Submission #1099297

#TimeUsernameProblemLanguageResultExecution timeMemory
1099297theSkeletonTracks in the Snow (BOI13_tracks)C++17
34.58 / 100
2134 ms1048576 KiB
#pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #include<bits/stdc++.h> #define space <<' '<< #define endl '\n' #define inf 1e14 #define F first #define S second #define PB push_back #define PF push_front #define md(a) ((a+mod)%mod) #define MP(a,b) make_pair(a,b) #define MT(a,b,c) make_tuple(a,b,c) typedef long long ll; using namespace std; template<typename t> using heap= priority_queue<t,vector<t>,greater<t>>; const int mx = 4e3+5; deque<pair<int,int>> b; deque<pair<int,int>> g; char state[mx][mx]; bool seen[mx][mx]; int h,w; bool c(int i,int j,char s){ if(i<0||h<=i) return 1; if(j<0||w<=j) return 1; if(seen[i][j])return 1; if(state[i][j]==s){ g.push_front(MP(i,j)); return 1; } if (state[i][j]=='.') return 1; return 0; } int main(){ std::ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); cin>>h>>w; for(int i=0;i<h;i++) for(int j=0;j<w;j++) cin>>state[i][j]; int cnt=0; g.PB(MP(h-1,w-1)); char cc=state[h-1][w-1]; while((!g.empty())||(!b.empty())){ cnt++; while(!b.empty()){ auto p=b.back(); b.pop_back(); c(p.F+1,p.S,cc); c(p.F-1,p.S,cc); c(p.F,p.S+1,cc); c(p.F,p.S-1,cc); } while(!g.empty()){ auto p=g.back(); g.pop_back(); bool k=1; seen[p.F][p.S]=1; k&=c(p.F+1,p.S,cc); k&=c(p.F-1,p.S,cc); k&=c(p.F,p.S+1,cc); k&=c(p.F,p.S-1,cc); if(!k) b.push_front(p); } cc=((cc=='F')?'R':'F'); } cout<<cnt; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...