# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
346741 |
2021-01-10T21:49:23 Z |
Pichon5 |
Zoo (COCI19_zoo) |
C++17 |
|
2000 ms |
10248 KB |
#include<bits/stdc++.h>
#define lcm(a,b) (a/__gcd(a,b))*b
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define F first
#define S second
#define mp make_pair
//salida rapida "\n"
//DECIMALES fixed<<sp(n)<<x<<endl;
//gcd(a,b)= ax + by
//lCB x&-x
//set.erase(it) - ersases the element present at the required index//auto it = s.find(element)
//set.find(element) - iterator pointing to the given element if it is present else return pointer pointing to set.end()
//set.lower_bound(element) - iterator pointing to element greater than or equal to the given element
//set.upper_bound(element) - iterator pointing to element greater than the given element
// | ^
using namespace std;
int n,m;
vector<string>M;
bool ok;
bool siputa(){
bool a=false;
bool b=false;
for(int i=0;i<n;i++){
for(int l=0;l<m;l++){
if(M[i][l]=='T')a=true;
if(M[i][l]=='B')b=true;
}
}
if(a && b){
return false;
}
return 1;
}
void dfs(int i, int l, char c, char cont){
M[i][l]=cont;
if(i+1<n){
if(M[i+1][l]==c){
dfs(i+1,l,c,cont);
}
}
if(l+1<m){
if(M[i][l+1]==c){
dfs(i,l+1,c,cont);
}
}
if(i-1>=0){
if(M[i-1][l]==c){
dfs(i-1,l,c,cont);
}
}
if(l-1>=0){
if(M[i][l-1]==c){
dfs(i,l-1,c,cont);
}
}
}
int main()
{
cin>>n>>m;
string s;
for(int i=0;i<n;i++){
cin>>s;
M.pb(s);
}
if(siputa()){
cout<<1<<endl;
return 0;
}
ok=true;
char cont='T';
if(M[0][0]=='T')cont='B';
dfs(0,0,M[0][0],cont);
int res=1;
while(1){
if(siputa())break;
res++;
ok=true;
cont='T';
if(M[0][0]=='T')cont='B';
dfs(0,0,M[0][0],cont);
}
cout<<res+1<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
4 ms |
364 KB |
Output is correct |
9 |
Correct |
4 ms |
364 KB |
Output is correct |
10 |
Correct |
5 ms |
492 KB |
Output is correct |
11 |
Correct |
5 ms |
364 KB |
Output is correct |
12 |
Correct |
6 ms |
492 KB |
Output is correct |
13 |
Correct |
4 ms |
364 KB |
Output is correct |
14 |
Correct |
4 ms |
364 KB |
Output is correct |
15 |
Correct |
4 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
492 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
4 ms |
364 KB |
Output is correct |
9 |
Correct |
4 ms |
364 KB |
Output is correct |
10 |
Correct |
5 ms |
492 KB |
Output is correct |
11 |
Correct |
5 ms |
364 KB |
Output is correct |
12 |
Correct |
6 ms |
492 KB |
Output is correct |
13 |
Correct |
4 ms |
364 KB |
Output is correct |
14 |
Correct |
4 ms |
364 KB |
Output is correct |
15 |
Correct |
4 ms |
364 KB |
Output is correct |
16 |
Correct |
35 ms |
4204 KB |
Output is correct |
17 |
Correct |
35 ms |
4096 KB |
Output is correct |
18 |
Correct |
35 ms |
3564 KB |
Output is correct |
19 |
Correct |
42 ms |
4716 KB |
Output is correct |
20 |
Correct |
35 ms |
3948 KB |
Output is correct |
21 |
Execution timed out |
2083 ms |
10248 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |