# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1088732 | 2024-09-14T22:25:14 Z | Math4Life2020 | Mars (APIO22_mars) | C++17 | 0 ms | 0 KB |
#include <bits/stdc++.h> #include "mars.h" using namespace std; using ll = long long; using pii = pair<ll,ll>; string process(vector<vector<char>> land, int N) { bool bl[N][N]; bool found[N][N]; for (ll i=0;i<N;i++) { for (ll j=0;j<N;j++) { found[i][j]=0; if (land[i][j]=='x') { assert(1==2); } else if (land[i][j]=='0') { bl[i][j]=0; } else if (land[i][j]=='1') { bl[i][j]=1; } } } ll ans = 0; for (ll i=0;i<N;i++) { for (ll j=0;j<N;j++) { if (found[i][j] || !land[i][j]) { continue; } ans++; stack<pii> s; s.push({i,j}); while (!s.empty()) { pii pt = s.top(); s.pop(); ll x = pt.first; ll y = pt.second; if (x<0 || x>=N) { continue; } if (y<0 || y>=N) { continue; } if (bl[x][y] && !found[x][y]) { found[x][y]=1; s.push({x+1,y}); s.push({x-1,y}); s.push({x,y-1}); s.push({x,y+1}); } } } } string outstr; for (ll i=0;i<N;i++) { outstr += "0"; } for (ll i=0;i<20;i++) { if ((ans>>i)&1) { outstr[i]="1"; } } return outstr; } string process(vector<vector<string>> a, int i, int j, int K, int N) { if (K==(N-1)) { vector<pii> nums[N][N]; vector<vector<char>> land; for (ll is=0;is<N;is++) { vector<char> vcharblank; for (ll js=0;js<N;js++) { nums[is][js]={{is,js}}; vcharblank.push_back('x'); } land.push_back(vcharblank); } for (ll ks=0;ks<K;ks++) { ll ms = 2*(N-ks-1); for (ll js=0;js<=ms;js++) { for (ll is=0;is<=ms;is++) { if (is==ms && js!=ms) { for (pii ps: nums[is+1][js]) { nums[is][js].push_back(ps); } for (pii ps: nums[is+2][js]) { nums[is][js].push_back(ps); } } if (is!=ms && js==ms) { for (pii ps: nums[is][js+1]) { nums[is][js].push_back(ps); } for (pii ps: nums[is][js+2]) { nums[is][js].push_back(ps); } } if (is==ms && js==ms) { for (ll I=0;I<3;I++) { for (ll J=0;J<3;J++) { if (I==0 && J==0) { continue; } for (pii ps: nums[is+I][js+J]) { nums[is][js].push_back(ps); } } } } } } } for (ll I=0;I<3;I++) { for (ll J=0;J<3;J++) { for (ll t=0;t<nums[I][J].size();t++) { ll x0 = nums[I][J][t].first; ll y0 = nums[I][J][t].second; land[x0][y0]=a[I][J][t]; } } } return process(land,N); } else { string out = a[0][0]; ll m = 2*(N-K+1); if (i==m && j!=m) { out[1]=a[1][0][0]; //first character for (ll t=0;t<98;t++) { out[t+2]=a[2][0][t]; } return out; } else if (i!=m && j==m) { out[1]=a[0][1][0]; for (ll t=0;t<98;t++) { out[t+2]=a[0][2][t]; } return out; } else if (i==m && j==m) { ll d = N-(i+2); ll T = 1; out[1]=a[0][1][0]; T++; for (ll t=0;t<d;t++) { out[T++]=a[0][2][t]; } out[T++]=a[1][0][0]; out[T++]=a[1][1][0]; for (ll t=0;t<d;t++) { out[T++]=a[1][2][t]; } for (ll t=0;t<d;t++) { out[T++]=a[2][0][t]; } for (ll t=0;t<d;t++) { out[T++]=a[2][1][t]; } for (ll t=0;t<(d*d);t++) { out[T++]=a[1][2][t]; } return out; } else { return out; } } }