This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#include "mars.h"
using namespace std;
int n;
char t[50][50];
bool vis[50][50];
void reset(){
for(int i=0;i<2*n+1;i++){
for(int f=0;f<2*n+1;f++){
vis[i][f]=false;
}
}
}
void dfs(int x,int y){
vis[x][y]=true;
if(x>0 and !vis[x-1][y] and t[x-1][y]=='1')dfs(x-1,y);
if(y>0 and !vis[x][y-1] and t[x][y-1]=='1')dfs(x,y-1);
if(x<2*n+1 and !vis[x+1][y] and t[x+1][y]=='1')dfs(x+1,y);
if(y<2*n+1 and !vis[x][y+1] and t[x][y+1]=='1')dfs(x,y+1);
}
string tostr(int x){
string res="";
for(int i=0;i<100;i++){
res.push_back(x%2+'0');
x/=2;
}
return res;
}
string solve(){
reset();
int ans=0;
for(int i=0;i<2*n+1;i++){
for(int f=0;f<2*n+1;f++){
if(t[i][f]=='1' and !vis[i][f]){
dfs(i,f); ans++;
}
}
}
return tostr(ans);
}
string process(vector< vector<string> > a, int x, int y, int k, int N){
n=N;
int m=2*(n-k-1);
if(x<m and y<m)return a[0][0];
for(int i=m;i<=m+1;i++){
for(int f=m;f<=m+1;f++){
t[i][f]=a[i-m][f-m][0];
}
}
for(int s=0;s<=2;s++){
for(int d=0;d<=2;d++){
int pt=0;
int diff=min(2*n+1-m-s,2*n+1-m-d);
for(int i=m+s;i<m+s+diff;i++){
for(int f=m+d;f<m+d+diff;f++){
if(s!=2 and d!=2)continue;
t[i][f]=a[s][d][pt];
pt++;
}
}
}
}
if(k==n-1){
return solve();
}else{
int pt=0;
for(int i=m;i<2*n+1;i++){
for(int f=m;f<2*n+1;f++){
a[0][0][pt]=t[i][f];
pt++;
}
}
return a[0][0];
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |