이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <queue>
#define endl '\n'
#define pb push_back
using namespace std;
int n, h, w;
const int MAXN = 16e6 + 1000;
string mat[4010];
queue<int> q[2];
vector<int> adj[MAXN];
bool tp[MAXN], used[MAXN];
int main(){
ios::sync_with_stdio(0);cin.tie(0);
cin >> h >> w;
for(int i=0; i<h; i++) cin >> mat[i];
for(int i=0; i<h; i++){
for(int j=0; j<w; j++){
if(mat[i][j] == '.') continue;
int v = (i*w) + j;
int u = (i+1)*w + j;
if(i < (h-1) && mat[i+1][j] != '.'){
adj[v].pb(u);
adj[u].pb(v);
}
u = (i*w) + j + 1;
if(j < (w-1) && mat[i][j+1] != '.'){
adj[v].pb(u);
adj[u].pb(v);
}
if(mat[i][j] == 'F') tp[v] = 0;
else tp[v] = 1;
}
}
int p, cnt=0;
if(mat[0][0] == 'F'){
q[0].emplace(0);
p = 0;
}
else{
q[1].emplace(0);
p = 1;
}
used[0] = 1;
while(!q[0].empty() || !q[1].empty()){
while(!q[p].empty()){
int v = q[p].front();
q[p].pop();
for(int u : adj[v]){
if(used[u]) continue;
q[tp[u]].emplace(u);
used[u] = 1;
}
}
p ^= 1;
cnt++;
}
cout << cnt << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |