답안 #648135

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
648135 2022-10-05T13:38:41 Z veiga Tracks in the Snow (BOI13_tracks) C++17
16.4583 / 100
2000 ms 1048576 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define F first
#define S second
#define endl "\n"
const int INF = 1e18+10;
const int MOD = 1e9+7;

int n, m;
string t[4040];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int cr = 0, cf = 0;

void bfs(char c) {
    queue<pair<int, int>> q;
    q.push({0, 0});
    while(!q.empty()) {
        int x = q.front().F, y = q.front().S; q.pop();
        if(c == 'R') {
            t[x][y] = 'F';
            cf++;
            cr--;
        }
        else {
            t[x][y] = 'R';
            cr++;
            cf--;
        }
        for(int i = 0; i < 4; i++) {
            int xx = x + dx[i];
            int yy = y + dy[i];
            if(xx < 0 or xx >= n or yy < 0 or yy >= m) continue;
            if(t[xx][yy] != c) continue;
            q.push({xx, yy});
        }
    }
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> n >> m;
    for(int i = 0; i < n; i++) {
        cin >> t[i];
    }
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            if(t[i][j] == 'R') cr++;
            if(t[i][j] == 'F') cf++;
        }
    }
    int resp = 0;
    while(cf != 0 and cr != 0) {
        resp++;
        bfs(t[0][0]);
    }
    cout << resp+1 << endl;

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2130 ms 724160 KB Time limit exceeded
2 Correct 2 ms 340 KB Output is correct
3 Execution timed out 2149 ms 1019156 KB Time limit exceeded
4 Execution timed out 2115 ms 767092 KB Time limit exceeded
5 Execution timed out 2108 ms 570736 KB Time limit exceeded
6 Correct 2 ms 340 KB Output is correct
7 Execution timed out 2139 ms 1048576 KB Time limit exceeded
8 Execution timed out 2107 ms 603380 KB Time limit exceeded
9 Execution timed out 2095 ms 65604 KB Time limit exceeded
10 Execution timed out 2116 ms 706080 KB Time limit exceeded
11 Execution timed out 2078 ms 1048576 KB Time limit exceeded
12 Execution timed out 2092 ms 483564 KB Time limit exceeded
13 Execution timed out 2104 ms 526980 KB Time limit exceeded
14 Execution timed out 2092 ms 523188 KB Time limit exceeded
15 Execution timed out 2106 ms 424936 KB Time limit exceeded
16 Execution timed out 2114 ms 735568 KB Time limit exceeded
17 Execution timed out 2088 ms 682372 KB Time limit exceeded
18 Execution timed out 2065 ms 756520 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Correct 1125 ms 484 KB Output is correct
2 Execution timed out 2056 ms 392084 KB Time limit exceeded
3 Execution timed out 2013 ms 25008 KB Time limit exceeded
4 Execution timed out 2025 ms 160964 KB Time limit exceeded
5 Execution timed out 2025 ms 10440 KB Time limit exceeded
6 Execution timed out 2035 ms 276292 KB Time limit exceeded
7 Correct 719 ms 472 KB Output is correct
8 Correct 1102 ms 484 KB Output is correct
9 Execution timed out 2093 ms 31256 KB Time limit exceeded
10 Correct 279 ms 492 KB Output is correct
11 Execution timed out 2089 ms 464 KB Time limit exceeded
12 Correct 1510 ms 476 KB Output is correct
13 Execution timed out 2079 ms 413040 KB Time limit exceeded
14 Execution timed out 2096 ms 307284 KB Time limit exceeded
15 Execution timed out 2078 ms 2260 KB Time limit exceeded
16 Execution timed out 2098 ms 211424 KB Time limit exceeded
17 Execution timed out 2055 ms 221220 KB Time limit exceeded
18 Execution timed out 2039 ms 5604 KB Time limit exceeded
19 Execution timed out 2028 ms 161016 KB Time limit exceeded
20 Execution timed out 2017 ms 5324 KB Time limit exceeded
21 Execution timed out 2005 ms 10828 KB Time limit exceeded
22 Execution timed out 2072 ms 10500 KB Time limit exceeded
23 Execution timed out 2031 ms 174100 KB Time limit exceeded
24 Execution timed out 2050 ms 10476 KB Time limit exceeded
25 Execution timed out 2065 ms 18472 KB Time limit exceeded
26 Correct 53 ms 14156 KB Output is correct
27 Execution timed out 2083 ms 972020 KB Time limit exceeded
28 Execution timed out 2071 ms 278604 KB Time limit exceeded
29 Execution timed out 2064 ms 1048576 KB Time limit exceeded
30 Execution timed out 2036 ms 555684 KB Time limit exceeded
31 Execution timed out 2043 ms 331940 KB Time limit exceeded
32 Execution timed out 2005 ms 29164 KB Time limit exceeded