답안 #534893

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
534893 2022-03-09T05:55:05 Z aadit_ambadkar Tracks in the Snow (BOI13_tracks) C++17
86.875 / 100
2000 ms 103824 KB
/*
    This code belongs to Aadit Ambadkar
    Date: 2022-03-07 21:34:47
    Problem: tis
*/
#include <bits/stdc++.h>
using namespace::std;
 
typedef long long ll;
#define F0R(i, n) for (int i = 0; i < n; i++)
#define R0F(i, n) for (int i = n-1; i >= 0; i--)
#define FOR(i, a, n) for (int i = a; i < n; i++)
#define pb push_back
#define fastio ios::sync_with_stdio(0); cin.tie(0)
#define MOD 1000000007
#define FF first
#define SS second
 
int n, m;
int board[4005][4005];
bool vis[4005][4005];
 
int main() {
    fastio;
    cin >> n >> m;
    F0R(i, n) {
        string s;
        cin >> s;
        F0R(j, m) {
            if (s[j]=='F') board[i][j]=1;
            else if (s[j]=='R') board[i][j]=2;
            else board[i][j]=0;
            vis[i][j]=false;
        }
    }
    // F0R(i, n) {
    //     F0R(j, m) {
    //         cout << board[i][j] << " ";
    //     }
    //     cout << "\n";
    // }
    // cout << "\n";
    priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>, greater<pair<int, pair<int, int>>>> pq;
    pq.push({1, {0, 0}});
    vis[0][0]=true;
    int ans = 0;
    while (!pq.empty()) {
        auto p = pq.top(); pq.pop();
        int g = p.FF, u = p.SS.FF, v = p.SS.SS;
        // if (vis[u][v]) continue;
        // cout << u << " " << v << " " << g << "\n";
        ans = max(ans, g);
        vis[u][v]=true;
        if (u < n-1 && !vis[u+1][v] && board[u+1][v]!=0) pq.push({g+((board[u][v]==board[u+1][v]) ? 0 : 1), {u+1, v}}), vis[u+1][v]=true;
        if (u > 0 && !vis[u-1][v] && board[u-1][v]!=0) pq.push({g+((board[u][v]==board[u-1][v]) ? 0 : 1), {u-1, v}}), vis[u-1][v]=true;
        if (v < m-1 && !vis[u][v+1] && board[u][v+1]!=0) pq.push({g+((board[u][v]==board[u][v+1]) ? 0 : 1), {u, v+1}}), vis[u][v+1]=true;
        if (v > 0 && !vis[u][v-1] && board[u][v-1]!=0) pq.push({g+((board[u][v]==board[u][v-1]) ? 0 : 1), {u, v-1}}), vis[u][v-1]=true;
        // cout << "\n";
    }
    cout << ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 5540 KB Output is correct
2 Correct 1 ms 452 KB Output is correct
3 Correct 1 ms 716 KB Output is correct
4 Correct 31 ms 5264 KB Output is correct
5 Correct 5 ms 3020 KB Output is correct
6 Correct 1 ms 444 KB Output is correct
7 Correct 1 ms 700 KB Output is correct
8 Correct 1 ms 844 KB Output is correct
9 Correct 1 ms 1092 KB Output is correct
10 Correct 5 ms 2500 KB Output is correct
11 Correct 7 ms 2252 KB Output is correct
12 Correct 16 ms 3156 KB Output is correct
13 Correct 5 ms 3020 KB Output is correct
14 Correct 5 ms 3020 KB Output is correct
15 Correct 31 ms 5448 KB Output is correct
16 Correct 43 ms 5532 KB Output is correct
17 Correct 20 ms 5196 KB Output is correct
18 Correct 29 ms 5268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 30924 KB Output is correct
2 Correct 112 ms 16588 KB Output is correct
3 Correct 317 ms 78948 KB Output is correct
4 Correct 114 ms 30184 KB Output is correct
5 Correct 149 ms 59236 KB Output is correct
6 Execution timed out 2092 ms 103684 KB Time limit exceeded
7 Correct 15 ms 32204 KB Output is correct
8 Correct 14 ms 30920 KB Output is correct
9 Correct 5 ms 712 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 14 ms 31716 KB Output is correct
12 Correct 1 ms 1612 KB Output is correct
13 Correct 109 ms 16668 KB Output is correct
14 Correct 63 ms 11340 KB Output is correct
15 Correct 22 ms 12364 KB Output is correct
16 Correct 55 ms 6276 KB Output is correct
17 Correct 272 ms 32540 KB Output is correct
18 Correct 79 ms 32004 KB Output is correct
19 Correct 114 ms 30164 KB Output is correct
20 Correct 83 ms 27936 KB Output is correct
21 Correct 203 ms 61252 KB Output is correct
22 Correct 146 ms 59324 KB Output is correct
23 Correct 544 ms 49736 KB Output is correct
24 Correct 126 ms 60800 KB Output is correct
25 Correct 376 ms 78836 KB Output is correct
26 Correct 1122 ms 69288 KB Output is correct
27 Execution timed out 2029 ms 82328 KB Time limit exceeded
28 Execution timed out 2050 ms 103824 KB Time limit exceeded
29 Execution timed out 2075 ms 91496 KB Time limit exceeded
30 Execution timed out 2066 ms 89696 KB Time limit exceeded
31 Correct 1979 ms 64072 KB Output is correct
32 Execution timed out 2047 ms 80572 KB Time limit exceeded