Submission #1120885

#TimeUsernameProblemLanguageResultExecution timeMemory
1120885vjudge1Tracks in the Snow (BOI13_tracks)C++17
43.13 / 100
2142 ms953624 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define run ios_base::sync_with_stdio(false);cin.tie(0); #define ll int #define pll pair<ll, ll> #define ull unsigned ll #define ld double #define endl "\n" #define pb push_back #define fi first #define se second #define pi acos(-1) #define N 4007 #define minimum -9223372036854775807 #define maximum -minimum #define mod 1000000007 using namespace std; using namespace __gnu_pbds; template <class t> using ordered_set=tree<t, null_type,less_equal<t>, rb_tree_tag,tree_order_statistics_node_update>; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); ll gcd(ll a, ll b) { if(b==0) return a; return gcd(b, a%b); } ll lcm(ll a, ll b) { return a/gcd(a, b)*b; } bool isprime(ll n) { if(n==1) return 0; for(ll i=2; i*i<=n; i++) { if(n%i==0) return 0; } return 1; } ll binpow(ll a, ll b) { a%=mod; ll res=1; while(b>0) { if(b%2==1) res=(res*a)%mod; a=(a*a)%mod; b/=2; } return res; } ll dx[]={0, 0, 1, -1}; ll dy[]={1, -1, 0, 0}; ll h, w, cvb; char a[N][N]; bool used[N][N]; bool inbound(ll x, ll y) { return 1<=x && x<=h && 1<=y && y<=w; } void dfs(ll x, ll y, char z) { used[x][y]=1; for(ll i=0; i<4; i++) { ll nx=x+dx[i]; ll ny=y+dy[i]; if(inbound(nx, ny) && (a[nx][ny]!=z && a[nx][ny]!='.') && !used[nx][ny]) { dfs(nx, ny, z); } } } int main() { // run; cin>>h>>w; for(ll i=1; i<=h; i++) { for(ll j=1; j<=w; j++) { cin>>a[i][j]; } } ll cvb=1; while(true) { set<char>st; st.clear(); for(ll i=1; i<=h; i++) { for(ll j=1; j<=w; j++) { if(a[i][j]!='.') st.insert(a[i][j]); } } if(st.size()==1) break; for(ll i=1; i<=h; i++) { for(ll j=1; j<=w; j++) { used[i][j]=0; } } if(a[h][w]=='F') dfs(h, w, 'R'); else dfs(h, w, 'F'); for(ll i=1; i<=h; i++) { for(ll j=1; j<=w; j++) { if(used[i][j]) { if(a[h][w]=='F') a[i][j]='R'; else a[i][j]='F'; } // cout<<a[i][j]; } // cout<<endl; } cvb++; } cout<<cvb<<endl; } /* RRRR R..R R..R RRRR */ // By Xanlar
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...