diff --git a/src/cw9/zad9/wyspy.cpp b/src/cw9/zad9/wyspy.cpp new file mode 100644 index 0000000..7d1ead0 --- /dev/null +++ b/src/cw9/zad9/wyspy.cpp @@ -0,0 +1,66 @@ +#include +using namespace std; + +const int dx[]={0, 0, 1, -1}; +const int dy[]={-1, 1, 0, 0}; + +bool ok(int y, int x, int n, int m){ + return x>=0&&x=0&&y> &adj){ + int n=adj.size(), m=adj[0].size(), ans=0; + vector> vis(n, vector(m, 0)); + deque> dq; + for (int i=0; i u=dq.front(); dq.pop_front(); + ans=max(ans, u[0]); + for (int i=0; i<4; ++i){ + int y=u[1]+dy[i], x=u[2]+dx[i]; + if(!ok(y, x, n, m)||vis[y][x]) continue; + vis[y][x]=1; + if(adj[y][x]==adj[u[1]][u[2]]) dq.push_front({u[0], y, x}); + else dq.push_back({u[0]+1, y, x}); + } + } + return ans; +} + +int main(){ + ios::sync_with_stdio(0); + cin.tie(0); + + int n, m; + cin >> n >> m; + vector> adj(n, vector(m, 0)); + for (int i=0; i> x; + if(x) adj[i][j]=1; + } + } + cout << wyspy(adj); +}