# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
230665 |
2020-05-11T01:14:41 Z |
AmineWeslati |
Zoo (COCI19_zoo) |
C++14 |
|
1410 ms |
76236 KB |
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
typedef string str;
typedef long long ll;
#define int ll
typedef double db;
typedef long double ld;
typedef pair<int,int> pi;
#define fi first
#define se second
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;
#define pb push_back
#define eb emplace_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
const int MOD = 1e9+7; //998244353
const ll INF = 1e18;
const int nx[4]={0,0,1,-1}, ny[4]={1,-1,0,0};
set <pi> s;
int R,C;
char g[1001][1001];
bool vis[1001][1001];
char c;
vpi vec,vec2;
void dfs(int x, int y){
s.insert({x,y});
vis[x][y]=true;
/*if(c=='T')g[x][y]='B';
else g[x][y]='T';*/
for(int m=0; m<4; m++){
int nwx=x+nx[m],nwy=y+ny[m];
if(nwx<0||nwy<0||nwx>=R||nwy>=C||vis[nwx][nwy]||g[nwx][nwy]=='*') continue;
if(g[nwx][nwy]!=c) vec2.pb({nwx,nwy});
else dfs(nwx,nwy);
}
}
int32_t main(){
boost;
cin>>R>>C;
int nb=0;
for(int i=0; i<R; i++) for(int j=0; j<C; j++){
cin>>g[i][j];
if(g[i][j]!='*') nb++;
}
int ans=1;
memset(vis,false,sizeof(vis));
c=g[R-1][C-1];
dfs(R-1,C-1);
//for(auto x:vec2) cout << x.fi << ' '<<x.se << endl;
while(sz(s)<nb){
if(c=='T') c='B';
else c='T';
vec.assign(all(vec2));
for(auto x: vec) if(!vis[x.fi][x.se]) dfs(x.fi,x.se);
ans++;
}
cout << ans << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1152 KB |
Output is correct |
2 |
Correct |
5 ms |
1408 KB |
Output is correct |
3 |
Correct |
5 ms |
1408 KB |
Output is correct |
4 |
Correct |
5 ms |
1536 KB |
Output is correct |
5 |
Correct |
6 ms |
1792 KB |
Output is correct |
6 |
Correct |
6 ms |
1920 KB |
Output is correct |
7 |
Correct |
6 ms |
1920 KB |
Output is correct |
8 |
Correct |
7 ms |
2048 KB |
Output is correct |
9 |
Correct |
7 ms |
2048 KB |
Output is correct |
10 |
Correct |
7 ms |
2048 KB |
Output is correct |
11 |
Correct |
7 ms |
2048 KB |
Output is correct |
12 |
Correct |
8 ms |
2304 KB |
Output is correct |
13 |
Correct |
7 ms |
1920 KB |
Output is correct |
14 |
Correct |
9 ms |
2048 KB |
Output is correct |
15 |
Correct |
7 ms |
1920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1152 KB |
Output is correct |
2 |
Correct |
5 ms |
1408 KB |
Output is correct |
3 |
Correct |
5 ms |
1408 KB |
Output is correct |
4 |
Correct |
5 ms |
1536 KB |
Output is correct |
5 |
Correct |
6 ms |
1792 KB |
Output is correct |
6 |
Correct |
6 ms |
1920 KB |
Output is correct |
7 |
Correct |
6 ms |
1920 KB |
Output is correct |
8 |
Correct |
7 ms |
2048 KB |
Output is correct |
9 |
Correct |
7 ms |
2048 KB |
Output is correct |
10 |
Correct |
7 ms |
2048 KB |
Output is correct |
11 |
Correct |
7 ms |
2048 KB |
Output is correct |
12 |
Correct |
8 ms |
2304 KB |
Output is correct |
13 |
Correct |
7 ms |
1920 KB |
Output is correct |
14 |
Correct |
9 ms |
2048 KB |
Output is correct |
15 |
Correct |
7 ms |
1920 KB |
Output is correct |
16 |
Correct |
41 ms |
8604 KB |
Output is correct |
17 |
Correct |
44 ms |
9696 KB |
Output is correct |
18 |
Correct |
40 ms |
8532 KB |
Output is correct |
19 |
Correct |
54 ms |
11392 KB |
Output is correct |
20 |
Correct |
44 ms |
9288 KB |
Output is correct |
21 |
Correct |
1385 ms |
71384 KB |
Output is correct |
22 |
Correct |
1299 ms |
72696 KB |
Output is correct |
23 |
Correct |
1320 ms |
73044 KB |
Output is correct |
24 |
Correct |
1410 ms |
76236 KB |
Output is correct |
25 |
Correct |
1300 ms |
74800 KB |
Output is correct |
26 |
Correct |
1272 ms |
74260 KB |
Output is correct |
27 |
Correct |
1302 ms |
72636 KB |
Output is correct |
28 |
Correct |
1287 ms |
72180 KB |
Output is correct |
29 |
Correct |
1389 ms |
75748 KB |
Output is correct |
30 |
Correct |
1362 ms |
74812 KB |
Output is correct |