이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int maxn = 4005;
typedef pair<int,int> ii;
typedef pair<int, ii> iii;
int adj[maxn][maxn], vis[maxn][maxn];
int vx[4] = {0,1,0,-1}, vy[4] = {1,0,-1,0};
int h,w;
int dijkstra(){
queue<ii> zero,um;
zero.push({h,w});
vis[h][w] = 1;
int res = 0;
while(!zero.empty()){
res++;
while(!zero.empty()){
auto [a,b] = zero.front();
zero.pop();
if(vis[a][b] < res) continue;
for(int i=0; i<4; i++){
int xx = a + vx[i], yy = b + vy[i];
if(adj[xx][yy] == 0) continue;
int val = vis[a][b];
if(adj[xx][yy] != adj[a][b]){
val ++;
}
if( vis[xx][yy] != 0 and vis[xx][yy] <= val) continue;
vis[xx][yy] = val;
if(val == res) zero.push({xx,yy});
else um.push({xx,yy});
}
}
swap(zero,um);
}
return res;
}
int main(){
cin >> h >> w;
for(int i=1; i<=h; i++){
string s; cin >> s;
for(int j =0; j<w; j++){
int val = 0;
if(s[j] == 'R') val = 1;
else if(s[j] == 'F') val = 2;
adj[i][j+1] = val;
}
}
cout << dijkstra() << endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
tracks.cpp: In function 'int dijkstra()':
tracks.cpp:26:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
26 | auto [a,b] = zero.front();
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |