Submission #743735

# Submission time Handle Problem Language Result Execution time Memory
743735 2023-05-17T20:09:49 Z Azm1t Tracks in the Snow (BOI13_tracks) C++17
100 / 100
670 ms 174248 KB
#include "bits/stdc++.h"
using namespace std;
#define forn for (int i = 0; i < n; i++)
#define int long long
#define ed "\n"
#define cyes cout << "YES\n"
#define cno cout << "NO\n"
#define pb push_back
#define deb cout << "Hi\n"
#define pint pair<int, int>
const long long MOD = 1000000007;

void dbg_out(){cerr<<"\n";}
template<typename Head,typename... Tail>
void dbg_out(Head H,Tail... T){cerr<<' '<<H;dbg_out(T...);}
#define debug(...) cerr<<"("<<#__VA_ARGS__<<"):",dbg_out(__VA_ARGS__)

//-------------------------------------------------------------------------------------------------------------------------------------------------------------------//


int32_t main(){

    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n, m; cin>>n>>m;
    char a[n][m];
    for(int i = 0; i < n; i++){
        for(int j = 0 ; j < m; j++){
            cin>>a[i][j];
        }
    }

    char cur = a[0][0];
    vector<vector<bool>> vis(n, vector<bool>(m, false));
    deque<pair<pint, char>> d;
    d.pb({{0, 0}, cur});

    auto valid = [&](int i, int j){
        return(i < n && i >= 0 && j < m && j >= 0);
    };

    vector<pint> moves = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
    int ans = 1;
    // int t = 0;

    while(!d.empty()){
        // cout << ++t << ed;
        auto c = d.front();
        d.pop_front();
        int i = c.first.first;
        int j = c.first.second;
        char x = c.second;
        if(x != cur){
            cur = x;
            ans++;
        }

        for(auto val: moves){
            int nx = i + val.first;
            int ny = j + val.second;
            char y;
            if(x == 'F') y = 'R';
            else y = 'F';
            if(valid(nx, ny) && !vis[nx][ny] && a[nx][ny] != '.'){
                if(x == a[nx][ny]) d.push_front({{nx, ny}, x});
                else d.push_back({{nx, ny}, y});
                vis[nx][ny] = true;
            }  
        }
        

    }

    cout << ans << ed;

    
}
# Verdict Execution time Memory Grader output
1 Correct 12 ms 1028 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 6 ms 1236 KB Output is correct
5 Correct 3 ms 468 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 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 440 KB Output is correct
11 Correct 2 ms 596 KB Output is correct
12 Correct 5 ms 592 KB Output is correct
13 Correct 2 ms 460 KB Output is correct
14 Correct 2 ms 464 KB Output is correct
15 Correct 10 ms 852 KB Output is correct
16 Correct 12 ms 1028 KB Output is correct
17 Correct 11 ms 780 KB Output is correct
18 Correct 8 ms 1224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 584 KB Output is correct
2 Correct 46 ms 3612 KB Output is correct
3 Correct 316 ms 33728 KB Output is correct
4 Correct 72 ms 8232 KB Output is correct
5 Correct 220 ms 19148 KB Output is correct
6 Correct 649 ms 73748 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 2 ms 592 KB Output is correct
9 Correct 3 ms 460 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 2 ms 620 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 53 ms 3612 KB Output is correct
14 Correct 26 ms 2200 KB Output is correct
15 Correct 21 ms 2388 KB Output is correct
16 Correct 25 ms 1692 KB Output is correct
17 Correct 119 ms 8864 KB Output is correct
18 Correct 82 ms 8684 KB Output is correct
19 Correct 71 ms 8172 KB Output is correct
20 Correct 70 ms 7492 KB Output is correct
21 Correct 187 ms 19896 KB Output is correct
22 Correct 216 ms 19228 KB Output is correct
23 Correct 231 ms 16684 KB Output is correct
24 Correct 188 ms 19440 KB Output is correct
25 Correct 345 ms 33740 KB Output is correct
26 Correct 511 ms 174248 KB Output is correct
27 Correct 600 ms 112540 KB Output is correct
28 Correct 670 ms 73892 KB Output is correct
29 Correct 654 ms 69252 KB Output is correct
30 Correct 640 ms 85864 KB Output is correct
31 Correct 532 ms 22984 KB Output is correct
32 Correct 569 ms 79044 KB Output is correct