This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// 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-x][j-y] = 0;
}
if(g[h-x][j-y] == 2){
b.push({h-x , j-y});
g[h-x][j-y] = 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-x][j-y] = 0;
}
if(g[h-x][j-y] == 2){
b.push({h-x , j-y});
g[h-x][j-y] = 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});
g[1][1] = 0;
}else if(g[1][1] == 2){
b.push({1 , 1});
g[1][1] = 0;
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();
}
}
Compilation message (stderr)
zoo.cpp: In function 'void T()':
zoo.cpp:12:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
12 | auto [h , j] = t.front();
| ^
zoo.cpp:14:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
14 | for(auto[x , y] : l){
| ^
zoo.cpp: In function 'void B()':
zoo.cpp:29:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
29 | auto [h , j] = b.front();
| ^
zoo.cpp:31:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
31 | for(auto[x , y] : l){
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |