Submission #1235091

#TimeUsernameProblemLanguageResultExecution timeMemory
1235091jiayiiyaijTracks in the Snow (BOI13_tracks)C++20
45.31 / 100
2096 ms18668 KiB
#include <iostream>
#include <vector>
#include<queue>
#include <algorithm>
using namespace std;

int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int H, W;
    cin >> H >> W;
    cin.ignore();

    vector<vector<char>> mapp(H, vector<char>(W));
    for (int i=0; i<H; i++) {
        string line;
        getline(cin, line);
        for (int j=0; j<W; j++) { mapp[i][j] = line[j]; }
    }
    
    vector<char> ani(2, '.');
    if (mapp[0][0] == 'R') { ani = {'R', 'F'}; }
    else { ani = {'F', 'R'}; }

    int dirs[4][2] = { {0,1}, {1,0}, {0,-1}, {-1,0} };
    int count = 0;
    bool flag = false;
    
    while(true) {
        for (char a : ani) {
            flag = false;
            vector<vector<bool>> vis(H, vector<bool>(W, false));
            vis[0][0] = true;
            queue<vector<int>> q;
            q.push({0,0});

            while (!q.empty()) {
                int r = q.front()[0];
                int c = q.front()[1];
                q.pop();

                for (int i = 0; i < 4; i++) {
                    int rr = r + dirs[i][0];
                    int cc = c + dirs[i][1];
                    if (rr < 0 || rr >= H || cc < 0 || cc >= W) { continue; }
                    if (vis[rr][cc]) { continue; }

                    if (mapp[rr][cc] == a) { flag = true; }
                    if (mapp[rr][cc] == a || mapp[rr][cc] == '#') {
                        vis[rr][cc] = true;
                        mapp[rr][cc] = '#';
                        q.push({rr, cc});
                    }
                }
            }
            
            if (not flag) {break;}
            count += 1;
        }
        
        if (not flag) {break;}
    }

    cout << count;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...