# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
23142 | ainta | Young Zebra (KRIII5_YZ) | C++14 | 36 ms | 6412 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<cstdio>
#include<algorithm>
int n, m, Q[321000][2], head, tail, Num[410][410][2], C[410][410], chk, Res[410][410];
char p[410][410];
int MakeP(int x, int pv){
int t = n;
if(pv==1)t = m;
if(x<0) x += (-x+t)/t*t;
x%=t;
return x;
}
void Ins(int x, int y){
int tx = MakeP(x,0), ty = MakeP(y,1);
if(Num[tx][ty][0] > -1e7){
if(Num[tx][ty][0]!=x||Num[tx][ty][1]!=y)chk = -1;
return;
}
Num[tx][ty][0] = x, Num[tx][ty][1] = y;
tail++;
Q[tail][0] = x, Q[tail][1] = y;
}
int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};
void Make(int x, int y){
int tx = MakeP(x,0), ty = MakeP(y,1);
int i, ttx, tty;
for(i=0;i<4;i++){
ttx = (tx+n+dx[i])%n;
tty = (ty+m+dy[i])%m;
if(p[tx][ty] == p[ttx][tty]){
Ins(x+dx[i], y+dy[i]);
}
}
}
void Do(int x, int y){
chk = 0;
head = tail = 0;
Ins(x,y);
while(head < tail){
head++;
x = Q[head][0], y = Q[head][1];
Make(x,y);
}
int i;
if(!chk)chk = tail;
for(i=1;i<=tail;i++){
x = MakeP(Q[i][0], 0), y = MakeP(Q[i][1], 1);
Res[x][y] = chk;
}
}
int main(){
scanf("%d%d",&n,&m);
int i, j;
for(i=0;i<n;i++){
scanf("%s",p[i]);
for(j=0;j<m;j++){
Num[i][j][0] = Num[i][j][1] = -1e8;
}
}
for(i=0;i<n;i++){
for(j=0;j<m;j++){
if(Num[i][j][0] < -1e7){
Do(i,j);
}
}
}
for(i=0;i<n;i++){
for(j=0;j<m;j++){
printf("%d ",Res[i][j]);
}
printf("\n");
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |