답안 #420010

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
420010 2021-06-07T21:58:43 Z antimirage Tracks in the Snow (BOI13_tracks) C++14
100 / 100
1380 ms 168612 KB
#include <bits/stdc++.h>

#define fr first
#define sc second
#define mk make_pair
#define pb push_back

using namespace std;

const int N = 4005, A[] = {1, -1, 0, 0}, B[] = {0, 0, 1, -1};

int n, m, a[N][N], u[N][N], ans = 1, cur;

deque <pair <int, int> > q;

inline bool check(int x, int y) {
    return x >= 1 && x <= n && y >= 1 && y <= m && a[x][y] != 2 && !u[x][y];
}

int main (){
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        scanf("\n");
        for (int j = 1; j <= m; j++) {
            char ch;
            scanf("%c", &ch);
            switch (ch) {
            case 'F':
                a[i][j] = 0;
                break;
            case 'R':
                a[i][j] = 1;
                break;
            case '.':
                a[i][j] = 2;
                break;
            default:
                assert(0);
            } 
        }
    }
    cur = a[1][1];
    u[1][1] = 1;
    q.push_back({1, 1});
    
    while (!q.empty()) {
        int x = q.front().fr, y = q.front().sc;
        q.pop_front();

        
        if (a[x][y] != cur)
            ans++, cur ^= 1;
        for (int i = 0; i < 4; i++) {
            if (check(x + A[i], y + B[i])) {
                u[x + A[i]][y + B[i]] = 1;
                if (cur != a[x + A[i]][y + B[i]])
                    q.push_back({x + A[i], y + B[i]});
                else
                    q.push_front({x + A[i], y + B[i]});
            }
        }
    }
    cout << ans << endl;
}

Compilation message

tracks.cpp: In function 'int main()':
tracks.cpp:23:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         scanf("\n");
      |         ~~~~~^~~~~~
tracks.cpp:26:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |             scanf("%c", &ch);
      |             ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 6084 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 716 KB Output is correct
4 Correct 15 ms 5708 KB Output is correct
5 Correct 8 ms 3148 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 716 KB Output is correct
8 Correct 1 ms 716 KB Output is correct
9 Correct 2 ms 1100 KB Output is correct
10 Correct 6 ms 2636 KB Output is correct
11 Correct 5 ms 2252 KB Output is correct
12 Correct 9 ms 3276 KB Output is correct
13 Correct 7 ms 3148 KB Output is correct
14 Correct 7 ms 3148 KB Output is correct
15 Correct 23 ms 6056 KB Output is correct
16 Correct 25 ms 6124 KB Output is correct
17 Correct 21 ms 5864 KB Output is correct
18 Correct 15 ms 5708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 31344 KB Output is correct
2 Correct 126 ms 19756 KB Output is correct
3 Correct 1004 ms 116104 KB Output is correct
4 Correct 291 ms 45316 KB Output is correct
5 Correct 616 ms 85360 KB Output is correct
6 Correct 1373 ms 150788 KB Output is correct
7 Correct 21 ms 32716 KB Output is correct
8 Correct 20 ms 31328 KB Output is correct
9 Correct 5 ms 716 KB Output is correct
10 Correct 2 ms 460 KB Output is correct
11 Correct 21 ms 32152 KB Output is correct
12 Correct 3 ms 1612 KB Output is correct
13 Correct 121 ms 19776 KB Output is correct
14 Correct 70 ms 13120 KB Output is correct
15 Correct 75 ms 16020 KB Output is correct
16 Correct 55 ms 7588 KB Output is correct
17 Correct 310 ms 42808 KB Output is correct
18 Correct 298 ms 49268 KB Output is correct
19 Correct 267 ms 45536 KB Output is correct
20 Correct 223 ms 36912 KB Output is correct
21 Correct 598 ms 85792 KB Output is correct
22 Correct 604 ms 85388 KB Output is correct
23 Correct 651 ms 69852 KB Output is correct
24 Correct 587 ms 82476 KB Output is correct
25 Correct 1276 ms 137204 KB Output is correct
26 Correct 931 ms 168612 KB Output is correct
27 Correct 1251 ms 163760 KB Output is correct
28 Correct 1377 ms 150780 KB Output is correct
29 Correct 1380 ms 149276 KB Output is correct
30 Correct 1303 ms 152232 KB Output is correct
31 Correct 1012 ms 107708 KB Output is correct
32 Correct 1203 ms 149036 KB Output is correct