Submission #503923

# Submission time Handle Problem Language Result Execution time Memory
503923 2022-01-09T07:55:29 Z zwicky Tracks in the Snow (BOI13_tracks) C++14
43.125 / 100
2000 ms 157320 KB
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define nl endl
#define loop(i,a,b) for(ll i=a;i<b;i++) 
#define rloop(i,a,b) for(ll i=b;i>=a;i--)
#define cy cout<<"YES"<<endl;
#define cn cout<<"NO"<<endl;
#define cm cout<<-1<<endl
#define vl vector<ll>
#define vchar vector<char>
#define vvll vector<vector<ll>>
#define vvcr vector<vchar>
#define deb(x) cout<<#x<<" "<<x<<endl;
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
using namespace std;
 
const ll MOD=1e9+7;
 
ll binepow(ll a,ll b,ll mod=-1){
	if(b==0){
		return 1ll;
	}
	if(mod!=-1){
		ll k=binepow(a,b/2,mod);
		if(b%2==0){
			return (k*k)%mod;
		}
		else{
			return (((k*a)%mod)*k)%mod;
		}
	}
	else{
		ll k=binepow(a,b/2,mod);
		if(b%2==0){
			return (k*k);
		}
		else{
			return k*k*a;
		}
	}
}
 
////////////////////////////////////////////////////////
 
void solve(){
	ll n,m;
	cin>>n>>m;
	vvcr a(n,vchar(m,'.'));
	ll total=0;
	loop(i,0,n){
		loop(j,0,m){
			cin>>a[i][j];
			if(a[i][j]!='.'){
				total++;
			}
		}
	}
	ll ans=0;
	char role=a[0][0];
	while (total!=0)
	{
		vvll vis(n,vl(m,0));
		queue<pair<ll,ll>> q;
		q.push({0,0});
		vis[0][0]=1;
		while (q.size()!=0)
		{
			if(a[q.front().first][q.front().second]==role){
				a[q.front().first][q.front().second]='x';
				total--;
			}
			ll x=q.front().first,y=q.front().second;
			vis[x][y]=1;
			if(x>0 && (a[x-1][y]==role || a[x-1][y]=='x' ) && vis[x-1][y]==0){
				q.push({x-1,y});
				vis[x-1][y]=1;
			}
			if(y>0 && (a[x][y-1]==role || a[x][y-1]=='x' ) && vis[x][y-1]==0){
				q.push({x,y-1});
				vis[x][y-1]=1;
			}
			if(x<n-1 && (a[x+1][y]==role || a[x+1][y]=='x' ) && vis[x+1][y]==0){
				q.push({x+1,y});
				vis[x+1][y]=1;
			}
			if(y<m-1 && (a[x][y+1]==role || a[x][y+1]=='x' ) && vis[x][y+1]==0){
				q.push({x,y+1});
				vis[x][y+1]=1;
			}
			q.pop();
		}
		ans++;
		if(role=='R'){
			role='F';
		}
		else{
			role='R';
		}
	}
	cout<<ans<<nl;
	return;
}
 
int main(){
   ios::sync_with_stdio(0);
   cin.tie(0);
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
	// ll t;
	// cin>>t;
	// while(t--){
	// 	solve();
	// }
	solve();
}
# Verdict Execution time Memory Grader output
1 Correct 202 ms 2716 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 2 ms 308 KB Output is correct
4 Correct 21 ms 1720 KB Output is correct
5 Correct 79 ms 1212 KB Output is correct
6 Correct 1 ms 288 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 3 ms 332 KB Output is correct
10 Correct 90 ms 944 KB Output is correct
11 Correct 5 ms 716 KB Output is correct
12 Correct 70 ms 1228 KB Output is correct
13 Correct 76 ms 1144 KB Output is correct
14 Correct 75 ms 1128 KB Output is correct
15 Correct 541 ms 2848 KB Output is correct
16 Correct 200 ms 2752 KB Output is correct
17 Correct 480 ms 2792 KB Output is correct
18 Correct 21 ms 1836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2074 ms 972 KB Time limit exceeded
2 Execution timed out 2009 ms 15908 KB Time limit exceeded
3 Execution timed out 2098 ms 144528 KB Time limit exceeded
4 Execution timed out 2084 ms 37308 KB Time limit exceeded
5 Execution timed out 2033 ms 83176 KB Time limit exceeded
6 Execution timed out 2072 ms 144156 KB Time limit exceeded
7 Correct 1750 ms 1028 KB Output is correct
8 Execution timed out 2068 ms 964 KB Time limit exceeded
9 Correct 179 ms 956 KB Output is correct
10 Correct 487 ms 664 KB Output is correct
11 Correct 703 ms 1092 KB Output is correct
12 Correct 1875 ms 736 KB Output is correct
13 Execution timed out 2039 ms 15988 KB Time limit exceeded
14 Execution timed out 2057 ms 9628 KB Time limit exceeded
15 Execution timed out 2061 ms 10784 KB Time limit exceeded
16 Execution timed out 2092 ms 6812 KB Time limit exceeded
17 Execution timed out 2081 ms 40412 KB Time limit exceeded
18 Execution timed out 2090 ms 40040 KB Time limit exceeded
19 Execution timed out 2036 ms 37256 KB Time limit exceeded
20 Execution timed out 2069 ms 34496 KB Time limit exceeded
21 Execution timed out 2021 ms 85956 KB Time limit exceeded
22 Execution timed out 2013 ms 83268 KB Time limit exceeded
23 Execution timed out 2064 ms 72364 KB Time limit exceeded
24 Execution timed out 2083 ms 83964 KB Time limit exceeded
25 Execution timed out 2033 ms 144512 KB Time limit exceeded
26 Correct 622 ms 120580 KB Output is correct
27 Execution timed out 2062 ms 142072 KB Time limit exceeded
28 Execution timed out 2075 ms 142024 KB Time limit exceeded
29 Execution timed out 2021 ms 157320 KB Time limit exceeded
30 Execution timed out 2085 ms 138712 KB Time limit exceeded
31 Execution timed out 2072 ms 91040 KB Time limit exceeded
32 Execution timed out 2087 ms 141688 KB Time limit exceeded