#include <cstdio>
using namespace std;
const int MAXN = 409, MAXM = 409;
const int cx[] = {1, 0, -1 ,0}, cy[] = {0, 1, 0, -1};
char A[MAXN * 5][MAXN * 5];
int visited[MAXN * 5][MAXN * 5];
bool visited2[MAXN * 5][MAXN * 5];
int ans[MAXN * 5][MAXN * 5];
int cnt, N, M;
int dfs1(int y, int x, char c){
if(y >= N * 5 || y < 0 || x >= M * 5 || x < 0) return 0;
if(visited[y][x] || A[y][x] != c) return 0;
int res = 1;
visited[y][x] = cnt;
for(int i = 0; i < 4; i++) res += dfs1(y + cy[i], x + cx[i], c);
return res;
}
void dfs2(int y, int x, char c, int v){
if(y >= N * 5 || y < 0 || x >= M * 5 || x < 0) return;
if(visited2[y][x] || A[y][x] != c) return;
visited2[y][x] = true;
for(int i = 0; i < 4; i++) dfs2(y + cy[i], x + cx[i], c, v);
ans[y][x] = v;
}
int main(){
scanf("%d%d%*c", &N, &M);
for(int i = 0; i < N; i++){
scanf("%s", A[i]);
for(int j = 0; j < M; j++){
for(int v = 0; v < 5; v++){
for(int w = 0; w < 5; w++) A[v * N + i][w * M + j] = A[i][j];
}
}
}
for(int i = 0; i < 5 * N; i++) printf("%s\n", A[i]);
for(int i = 0; i < N; i++){
for(int j = 0; j < M; j++){
int y = i + N * 2, x = j + M * 2;
if(!visited[y][x]){
cnt++;
int v = dfs1(y, x, A[y][x]);
bool is = false;
for(int w = 0; w < 5 * M; w++){
if((visited[0][w] == cnt) && (visited[0][w] == visited[3 * N - 1][w])) is = true;
}
for(int w = 0; w < 5 * N; w++){
if((visited[w][0] == cnt) && (visited[w][0] == visited[w][3 * M - 1])) is = true;
}
dfs2(y, x, A[y][x], is ? -1 : v);
}
}
}
for(int i = 0; i < N; i++){
for(int j = 0; j < M; j++) printf("%d ", ans[i + N * 2][j + M * 2]);
printf("\n");
}
}
Compilation message
YZ.cpp: In function 'int main()':
YZ.cpp:31:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%*c", &N, &M);
^
YZ.cpp:33:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", A[i]);
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
176 ms |
49936 KB |
Expected integer, but "WWWWWWWWWWWWWWWWWWWWWWWWWWWWWW...WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW" found |
2 |
Halted |
0 ms |
0 KB |
- |