답안 #846500

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
846500 2023-09-07T16:11:59 Z mickey080929 Sandwich (JOI16_sandwich) C++17
100 / 100
1574 ms 4448 KB
#include <bits/stdc++.h>

using namespace std;

int n, m;
int cnt;
int a[410][410];
int vis[410][410];
int chk[410][410];
int ans[410][410];

int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};

int dfs(int x, int y, int d) {
    cnt ++;
    vis[x][y] = d;
    for (int i=0; i<2; i++) {
        int t = (d<<1) + a[x][y] + i; if (t >= 4) t -= 4;
        int nx = x + dx[t];
        int ny = y + dy[t];
        if (nx <= 0 || nx > n || ny <= 0 || ny > m) continue;
        int nd = (t >= a[nx][ny] && t <= 1+a[nx][ny]) ^ 1;
        if (vis[nx][ny] == nd) {
            if (chk[nx][ny]) continue;
            return 0;
        }
        if (vis[nx][ny] == (nd ^ 1)) return 0;
        if (!dfs(nx, ny, nd)) return 0;
    }
    chk[x][y] = 1;
    return 1;
}

int main() {
    scanf("%d %d", &n, &m);
    for (int i=1; i<=n; i++) {
        for (int j=1; j<=m; j++) {
            char c;
            scanf(" %c", &c);
            if (c == 'N') a[i][j] = 0;
            else a[i][j] = 1;
        }
    }
    memset(ans, -1, sizeof(ans));
    for (int i=1; i<=n; i++) {
        memset(vis, -1, sizeof(vis));
        memset(chk, 0, sizeof(chk));
        cnt = 0;
        for (int j=1; j<=m; j++) {
            if (!dfs(i, j, 1)) break;
            if (ans[i][j] == -1) ans[i][j] = cnt * 2;
            else ans[i][j] = min(ans[i][j], cnt * 2);
        }
    }
    for (int i=1; i<=n; i++) {
        memset(vis, -1, sizeof(vis));
        memset(chk, 0, sizeof(chk));
        cnt = 0;
        for (int j=m; j>=1; j--) {
            if (!dfs(i, j, 0)) break;
            if (ans[i][j] == -1) ans[i][j] = cnt * 2;
            else ans[i][j] = min(ans[i][j], cnt * 2);
        }
    }
    for (int i=1; i<=n; i++) {
        for (int j=1; j<=m; j++) {
            printf("%d ", ans[i][j]);
        }
        printf("\n");
    }
}

Compilation message

sandwich.cpp: In function 'int main()':
sandwich.cpp:36:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
sandwich.cpp:40:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |             scanf(" %c", &c);
      |             ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2496 KB Output is correct
3 Correct 3 ms 2672 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 3 ms 2908 KB Output is correct
6 Correct 3 ms 2652 KB Output is correct
7 Correct 6 ms 2652 KB Output is correct
8 Correct 6 ms 2680 KB Output is correct
9 Correct 4 ms 2652 KB Output is correct
10 Correct 6 ms 2684 KB Output is correct
11 Correct 5 ms 2652 KB Output is correct
12 Correct 3 ms 2488 KB Output is correct
13 Correct 6 ms 2488 KB Output is correct
14 Correct 6 ms 2652 KB Output is correct
15 Correct 5 ms 2680 KB Output is correct
16 Correct 4 ms 2652 KB Output is correct
17 Correct 4 ms 2488 KB Output is correct
18 Correct 5 ms 2652 KB Output is correct
19 Correct 5 ms 2652 KB Output is correct
20 Correct 4 ms 2652 KB Output is correct
21 Correct 4 ms 2652 KB Output is correct
22 Correct 4 ms 2652 KB Output is correct
23 Correct 5 ms 2652 KB Output is correct
24 Correct 8 ms 2648 KB Output is correct
25 Correct 6 ms 2652 KB Output is correct
26 Correct 7 ms 2652 KB Output is correct
27 Correct 5 ms 2652 KB Output is correct
28 Correct 5 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2496 KB Output is correct
3 Correct 3 ms 2672 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 3 ms 2908 KB Output is correct
6 Correct 3 ms 2652 KB Output is correct
7 Correct 6 ms 2652 KB Output is correct
8 Correct 6 ms 2680 KB Output is correct
9 Correct 4 ms 2652 KB Output is correct
10 Correct 6 ms 2684 KB Output is correct
11 Correct 5 ms 2652 KB Output is correct
12 Correct 3 ms 2488 KB Output is correct
13 Correct 6 ms 2488 KB Output is correct
14 Correct 6 ms 2652 KB Output is correct
15 Correct 5 ms 2680 KB Output is correct
16 Correct 4 ms 2652 KB Output is correct
17 Correct 4 ms 2488 KB Output is correct
18 Correct 5 ms 2652 KB Output is correct
19 Correct 5 ms 2652 KB Output is correct
20 Correct 4 ms 2652 KB Output is correct
21 Correct 4 ms 2652 KB Output is correct
22 Correct 4 ms 2652 KB Output is correct
23 Correct 5 ms 2652 KB Output is correct
24 Correct 8 ms 2648 KB Output is correct
25 Correct 6 ms 2652 KB Output is correct
26 Correct 7 ms 2652 KB Output is correct
27 Correct 5 ms 2652 KB Output is correct
28 Correct 5 ms 2688 KB Output is correct
29 Correct 1 ms 2652 KB Output is correct
30 Correct 21 ms 3088 KB Output is correct
31 Correct 44 ms 3864 KB Output is correct
32 Correct 35 ms 3516 KB Output is correct
33 Correct 20 ms 3152 KB Output is correct
34 Correct 1181 ms 3992 KB Output is correct
35 Correct 894 ms 3604 KB Output is correct
36 Correct 46 ms 3160 KB Output is correct
37 Correct 1280 ms 4036 KB Output is correct
38 Correct 1153 ms 4012 KB Output is correct
39 Correct 1264 ms 4028 KB Output is correct
40 Correct 1574 ms 4332 KB Output is correct
41 Correct 549 ms 3496 KB Output is correct
42 Correct 1372 ms 4432 KB Output is correct
43 Correct 1407 ms 4408 KB Output is correct
44 Correct 1395 ms 4428 KB Output is correct
45 Correct 977 ms 3984 KB Output is correct
46 Correct 708 ms 4180 KB Output is correct
47 Correct 936 ms 4260 KB Output is correct
48 Correct 516 ms 3668 KB Output is correct
49 Correct 729 ms 3992 KB Output is correct
50 Correct 808 ms 4000 KB Output is correct
51 Correct 659 ms 3964 KB Output is correct
52 Correct 574 ms 3992 KB Output is correct
53 Correct 570 ms 3992 KB Output is correct
54 Correct 581 ms 3984 KB Output is correct
55 Correct 635 ms 3988 KB Output is correct
56 Correct 600 ms 4180 KB Output is correct
57 Correct 503 ms 3684 KB Output is correct
58 Correct 1396 ms 4268 KB Output is correct
59 Correct 1380 ms 4448 KB Output is correct
60 Correct 979 ms 3984 KB Output is correct
61 Correct 1437 ms 4352 KB Output is correct
62 Correct 1032 ms 4056 KB Output is correct
63 Correct 785 ms 4336 KB Output is correct