답안 #835960

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
835960 2023-08-24T01:17:49 Z vgoofficial Tracks in the Snow (BOI13_tracks) C++14
100 / 100
571 ms 158928 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll mod = 1000000007;
int main() {
    ios_base::sync_with_stdio(false); 
    cin.tie(0);
    int h,w;
    cin >> h >> w;
    int field[h][w];
    for(int i = 0; i < h; i++) {
        string s;
        cin >> s;
        for(int j = 0; j < w; j++) {
            if(s[j]=='F') {
                field[i][j]=1;
            } else if(s[j]=='R') {
                field[i][j]=2;
            } else {
                field[i][j]=0;
            }
        }
    }
    deque<pair<int, int>> q;
    q.push_back({0,0});
    vector<vector<int>> dist(h, vector<int>(w, -1));
    dist[0][0]=1;
    int ans = 1;
    vector<int> dx{-1, 1, 0, 0}, dy{0,0,-1,1};
    while(q.size()) {
        pair<int, int> p = q.front();
        q.pop_front();
        for(int i = 0; i < 4; i++) {
            int newx = p.first+dx[i];
            int newy = p.second+dy[i];
            if(newx>=0&&newy>=0&&newx<h&&newy<w&&field[newx][newy]!=0&&dist[newx][newy]==-1) {
                if(field[newx][newy]==field[p.first][p.second]) {
                    dist[newx][newy]=dist[p.first][p.second];
                    q.push_front({newx, newy});
                } else {
                    dist[newx][newy]=dist[p.first][p.second]+1;
                    q.push_back({newx, newy});
                }
                ans = max(ans, dist[newx][newy]);
            }
        }
    }
    cout << ans << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 2516 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 6 ms 1800 KB Output is correct
5 Correct 2 ms 980 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 852 KB Output is correct
11 Correct 2 ms 724 KB Output is correct
12 Correct 4 ms 1108 KB Output is correct
13 Correct 2 ms 980 KB Output is correct
14 Correct 2 ms 980 KB Output is correct
15 Correct 8 ms 2516 KB Output is correct
16 Correct 10 ms 2516 KB Output is correct
17 Correct 8 ms 2388 KB Output is correct
18 Correct 5 ms 1916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 852 KB Output is correct
2 Correct 35 ms 14164 KB Output is correct
3 Correct 191 ms 141388 KB Output is correct
4 Correct 61 ms 33404 KB Output is correct
5 Correct 125 ms 79724 KB Output is correct
6 Correct 567 ms 154576 KB Output is correct
7 Correct 1 ms 852 KB Output is correct
8 Correct 1 ms 852 KB Output is correct
9 Correct 2 ms 852 KB Output is correct
10 Correct 1 ms 584 KB Output is correct
11 Correct 1 ms 852 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 35 ms 14164 KB Output is correct
14 Correct 19 ms 8244 KB Output is correct
15 Correct 16 ms 9100 KB Output is correct
16 Correct 17 ms 5972 KB Output is correct
17 Correct 91 ms 36048 KB Output is correct
18 Correct 76 ms 35648 KB Output is correct
19 Correct 59 ms 33356 KB Output is correct
20 Correct 51 ms 30796 KB Output is correct
21 Correct 117 ms 82488 KB Output is correct
22 Correct 124 ms 79692 KB Output is correct
23 Correct 175 ms 68556 KB Output is correct
24 Correct 119 ms 80516 KB Output is correct
25 Correct 479 ms 141304 KB Output is correct
26 Correct 330 ms 158612 KB Output is correct
27 Correct 439 ms 158928 KB Output is correct
28 Correct 571 ms 154556 KB Output is correct
29 Correct 565 ms 154844 KB Output is correct
30 Correct 556 ms 153032 KB Output is correct
31 Correct 442 ms 91140 KB Output is correct
32 Correct 387 ms 156812 KB Output is correct