From 6bd3af25e990e587a1a7f093806e16e8996b8e9e Mon Sep 17 00:00:00 2001 From: asajb <108701197+asajb@users.noreply.github.com> Date: Thu, 7 Dec 2023 12:07:07 +0100 Subject: [PATCH 1/2] Create wyspy.cpp --- src/cw9/zad9/wyspy.cpp | 67 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/cw9/zad9/wyspy.cpp diff --git a/src/cw9/zad9/wyspy.cpp b/src/cw9/zad9/wyspy.cpp new file mode 100644 index 0000000..64cf186 --- /dev/null +++ b/src/cw9/zad9/wyspy.cpp @@ -0,0 +1,67 @@ +#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; + //vector> res(n, vector(m, 0)); + 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); +} From 268171a3bb0055425f5e759c1a4e2b148fab1f83 Mon Sep 17 00:00:00 2001 From: asajb <108701197+asajb@users.noreply.github.com> Date: Thu, 7 Dec 2023 12:11:49 +0100 Subject: [PATCH 2/2] Update wyspy.cpp --- src/cw9/zad9/wyspy.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cw9/zad9/wyspy.cpp b/src/cw9/zad9/wyspy.cpp index 64cf186..7d1ead0 100644 --- a/src/cw9/zad9/wyspy.cpp +++ b/src/cw9/zad9/wyspy.cpp @@ -12,7 +12,6 @@ int wyspy(vector> &adj){ int n=adj.size(), m=adj[0].size(), ans=0; vector> vis(n, vector(m, 0)); deque> dq; - //vector> res(n, vector(m, 0)); for (int i=0; i> &adj){ dq.push_front({0, n-1, i}); } for (int i=0; i