# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
22500 | Jongwon Party (#40) | Young Zebra (KRIII5_YZ) | C++14 | 29 ms | 16176 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
char arr[410][410];
int chk[410][410];
int pos[410][410][2];
int res[160010];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
int n, m;
char c;
int p;
int f(int x, int y, int px, int py)
{
bool u;
int r, nx, ny, npx, npy, i;
chk[x][y] = p;
pos[x][y][0] = px;
pos[x][y][1] = py;
r = 1;
u = 1;
for(i = 0; i<4; i++)
{
nx = x + dx[i];
ny = y + dy[i];
npx = px;
npy = py;
if(nx < 0)
{
npx--;
nx += n;
}
else if(nx >= n)
{
npx++;
nx -= n;
}
if(ny < 0)
{
npy--;
ny += m;
}
else if(ny >= m)
{
npy++;
ny -= m;
}
if(arr[nx][ny] != c)
continue;
if(!chk[nx][ny])
{
int t = f(nx, ny, npx, npy);
if(t == -1)
u = 0;
else
r += t;
continue;
}
if(pos[nx][ny][0] == npx && pos[nx][ny][1] == npy)
continue;
u = 0;
}
if(u)
return r;
return -1;
}
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
int t, i, j;
scanf("%d%d", &n, &m);
for(i = 0; i<n; i++)
scanf("%s", arr[i]);
p = 1;
for(i = 0; i<n; i++)
{
for(j = 0; j<m; j++)
{
if(chk[i][j])
{
printf("%d ", res[chk[i][j]]);
continue;
}
c = arr[i][j];
t = f(i, j, 0, 0);
res[p++] = t;
printf("%d ", t);
}
printf("\n");
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |