Submission #1090721

#TimeUsernameProblemLanguageResultExecution timeMemory
1090721TaxiradioZoo (COCI19_zoo)C++17
0 / 110
1408 ms524288 KiB
// Source: https://usaco.guide/general/io #include <bits/stdc++.h> using namespace std; int g[1004][1004]; queue<array<int , 2>> t , b; int c = 0; vector<array<int , 2>> l = {{1 , 0},{-1 , 0},{0 , -1},{0 , 1}}; void T(){ while(!t.empty()){ auto [h , j] = t.front(); t.pop(); for(auto[x , y] : l){ if(g[h-x][j-y] == 1){ t.push({h-x , j-y}); g[h][j] = 0; } if(g[h-x][j-y] == 2){ b.push({h-x , j-y}); g[h][j] = 0; } } } } void B(){ while(!b.empty()){ auto [h , j] = b.front(); b.pop(); for(auto[x , y] : l){ if(g[h-x][j-y] == 1){ t.push({h-x , j-y}); g[h][j] = 0; } if(g[h-x][j-y] == 2){ b.push({h-x , j-y}); g[h][j] = 0; } } } } int main() { int n, m; cin >> n >> m; for(int i = 1; i <= n; i++){ for(int i2 = 1; i2 <=m; i2++){ char y; cin >> y; if(y == 'T'){ g[i][i2] = 1; c++; } if(y == 'B'){ g[i][i2] = 2; c++; } } } int ans = 0; if(g[1][1] == 1){ t.push({1, 1}); }else if(g[1][1] == 2){ b.push({1 , 1}); ans++; B(); } while(1){ if(t.empty() && b.empty()){ cout << ans << endl; return 0; } ans++; T(); if(t.empty() && b.empty()){ cout << ans << endl; return 0; } ans++; B(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...