This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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(){
priority_queue<iii, vector<iii> , greater<iii>> q;
vis[h][w] = 1;
q.push({1,{h,w}});
int maior = 1;
while(!q.empty()){
auto [a,b] = q.top();
auto [x,y] = b;
q.pop();
if(vis[x][y] < a) continue;
maior = max(maior, a);
for(int i=0; i<4; i++){
int xx = x + vx[i], yy = y + vy[i];
if(adj[xx][yy] == 0) continue;
int val = a;
if(adj[x][y] != adj[xx][yy]) val += 1;
if(vis[xx][yy] != 0 and vis[xx][yy] <= val) continue;
vis[xx][yy] = val;
q.push({val, {xx,yy}});
}
}
return maior;
}
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;
}
Compilation message (stderr)
tracks.cpp: In function 'int dijkstra()':
tracks.cpp:22:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
22 | auto [a,b] = q.top();
| ^
tracks.cpp:23:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
23 | auto [x,y] = b;
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |