Submission #206801

#TimeUsernameProblemLanguageResultExecution timeMemory
206801MvCTracks in the Snow (BOI13_tracks)C++11
100 / 100
1383 ms115440 KiB
#pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> #define rc(x) return cout<<x<<endl,0 #define pb push_back #define mkp make_pair #define in insert #define er erase #define fd find #define fr first #define sc second typedef long long ll; typedef long double ld; const ll INF=0x3f3f3f3f3f3f3f3f; const ll llinf=(1LL<<62); const int inf=(1<<30); const int nmax=4e3+50; const int mod=1e9+7; using namespace std; int n,m,i,j,rs,ix,jx,viz[nmax][nmax],t,di[5],dj[5]; char c[nmax][nmax],cur; queue<pair<int,int> >q,q1; bool ok(int x,int y) { if(x<1 || x>n || y<1 || y>m || viz[x][y] || c[x][y]=='.')return 0; return 1; } int main() { //freopen("sol.in","r",stdin); //freopen("sol.out","w",stdout); //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0); di[0]=-1,di[1]=1,dj[2]=-1,dj[3]=1; cin>>n>>m; for(i=1;i<=n;i++)for(j=1;j<=m;j++)cin>>c[i][j]; cur=c[1][1]; viz[1][1]=1; q.push(mkp(1,1)); for(rs=1;;rs++) { while(!q.empty()) { i=q.front().fr,j=q.front().sc; q.pop(); for(t=0;t<4;t++) { ix=i+di[t],jx=j+dj[t]; if(!ok(ix,jx))continue; viz[ix][jx]=1; if(c[ix][jx]==cur)q.push(mkp(ix,jx)); else q1.push(mkp(ix,jx)); } } if(q1.empty())break; q=q1; while(!q1.empty())q1.pop(); if(cur=='F')cur='R'; else cur='F'; } cout<<rs<<endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...