이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// 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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |