제출 #346741

#제출 시각아이디문제언어결과실행 시간메모리
346741Pichon5Zoo (COCI19_zoo)C++17
45 / 110
2083 ms10248 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...