# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
22719 | King_God_OnionPringles (#40) | Young Zebra (KRIII5_YZ) | C++98 | 69 ms | 25236 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
int rr[4] = {1,0,-1,0};
int cc[4] = {0,1,0,-1};
char bd[805][805];
int vis[2][805][805];
int n,m;
int ans[160001], clr = 1;
int my_clr[401][401], cntt[2][160001];
void dfs(int flag, int r, int c, int md){
//printf("%d %d %d %d %d %d\n",flag,r,c,bf,br,bc);
cntt[md][clr]++;
for(int i=0;i<4;i++){
int new_flag = flag, nr = r, nc = c;
nr += rr[i]; nc += cc[i];
if(nr == -1){
nr = n-1;
new_flag = 1;
}
if(nr == n){
nr = 0;
new_flag = 1;
}
if(nc == -1){
nc = m-1;
new_flag = 1;
}
if(nc == m){
nc = 0;
new_flag = 1;
}
if(bd[r][c] == bd[nr][nc] && vis[new_flag][nr][nc] != clr){
vis[new_flag][nr][nc] = clr;
dfs(new_flag, nr, nc, md);
}
}
}
int main(){
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++) scanf("%s",bd[i]);
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(vis[1][i][j] == 0){
vis[1][i][j] = clr;
dfs(1,i,j,0);
clr++;
}
my_clr[i][j] = vis[1][i][j];
}
}
n*=2;m*=2;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
vis[1][i][j] = 0;
bd[i][j] = bd[i%(n/2)][j%(m/2)];
}
}
for(int i=0;i<n/2;i++){
for(int j=0;j<m/2;j++){
if(ans[my_clr[i][j]] == 0){
clr = my_clr[i][j];
vis[1][i][j] = clr;
dfs(1,i,j,1);
if(cntt[0][clr] == cntt[1][clr]){
ans[clr] = cntt[0][clr];
}else{
ans[clr] = -1;
}
}
printf("%d ",ans[my_clr[i][j]]);
}
printf("\n");
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |