Submission #1186751

#TimeUsernameProblemLanguageResultExecution timeMemory
1186751yoruonivampTracks in the Snow (BOI13_tracks)C++20
0 / 100
121 ms30368 KiB
// YoruoniVamp - VTUBE
// Pragma Credit to Discord: pxsithexahydride
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,no-stack-protector,inline-small-functions,inline,unsafe-math-optimizations,omit-frame-pointer,inline-functions-called-once")
#include <bits/stdc++.h>
#pragma GCC target("avx2,fma,popcnt,lzcnt,bmi,bmi2,sse4.2,tune=native")
using namespace std;
#define endl '\n'
#define ll long long
#define ld long double
#define ull unsigned ll
#define cint const int
#define cf const float

cint mxA = 1e6+5, MOD = 1e9+7, INF = 0x3f3f3f3f;
cint d4x[4] = {0, 1, 0, -1}, d4y[4] = {1, 0, -1, 0};
cint d8x[8] = {0, 1, 1, 1, 0, -1, -1, -1}, d8y[8] = {1, 1, 0, -1, -1, -1, 0, 1};

void wait(int ms){
    clock_t endwait;
    endwait = clock() + ms;
    while(clock()<endwait){}
}

void solve(){
    int n, m; cin >> n >> m;
    string grid[n+1];
    for(int i = 0; i < n; i++) cin >> grid[i];
    // <charnow,charprevious,i,j>
    // priority_queue<tuple<char,char,int,int>,vector<tuple<char,char,int,int>>,greater<tuple<char,char,int,int>>> pq;
    queue<tuple<int,int>> q, tq;
    q.emplace(0,0);
    bool isFox = (grid[0][0]=='F'), haveother = false;
    int cnt = 0;
    vector<vector<bool>> vis(n,vector<bool>(m,false));
    while(!q.empty()){
        chkagain:
        auto [i,j] = q.front(); q.pop();
        // cout << i << ' ' << j << endl;
        if(i<0||i>=n||j<0||j>=m) continue;
        if(grid[i][j]=='.') continue;
        if(vis[i][j]) continue;
        vis[i][j] = true;
        if(isFox){
            for(int d = 0; d < 4; d++){
                int newi = i+d4y[d], newj = j+d4x[d];
                if(grid[newi][newj]=='F') q.emplace(newi,newj);
                else tq.emplace(newi,newj), haveother = true;
            }
        }else{
            for(int d = 0; d < 4; d++){
                int newi = i+d4y[d], newj = j+d4x[d];
                if(grid[newi][newj]=='R') q.emplace(newi,newj);
                else tq.emplace(newi,newj), haveother = true;
            }
        }
    }
    if(haveother){
        haveother = false;
        cnt++;
        q.emplace(tq.front()); tq.pop();
        goto chkagain;
    }
    cout << cnt+1;
    return;
}

int main(){
    cin.tie(nullptr)->sync_with_stdio(0);cout.tie(0);
    // freopen("", "r", stdin);
    // freopen("", "w", stdout);
    int t = 1;
    // cin >> t;
    while(t--) solve();
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...