Task: | Suunnistus |
Sender: | aatukaj |
Submission time: | 2025-01-18 13:29:07 +0200 |
Language: | C++ (C++17) |
Status: | READY |
Result: | 100 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 31 |
#2 | ACCEPTED | 12 |
#3 | ACCEPTED | 57 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.00 s | 3 | details |
#2 | ACCEPTED | 0.03 s | 1, 2, 3 | details |
#3 | ACCEPTED | 0.03 s | 1, 2, 3 | details |
#4 | ACCEPTED | 0.02 s | 1, 2, 3 | details |
#5 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#6 | ACCEPTED | 0.00 s | 1, 2, 3 | details |
#7 | ACCEPTED | 0.09 s | 2, 3 | details |
#8 | ACCEPTED | 0.09 s | 2, 3 | details |
#9 | ACCEPTED | 0.03 s | 2, 3 | details |
#10 | ACCEPTED | 0.14 s | 3 | details |
#11 | ACCEPTED | 0.15 s | 3 | details |
#12 | ACCEPTED | 0.04 s | 3 | details |
#13 | ACCEPTED | 0.11 s | 3 | details |
#14 | ACCEPTED | 0.08 s | 2, 3 | details |
#15 | ACCEPTED | 0.01 s | 3 | details |
#16 | ACCEPTED | 0.00 s | 3 | details |
#17 | ACCEPTED | 0.03 s | 2, 3 | details |
Code
#include <bits/stdc++.h> #define all(v) (v).begin(), (v).end() using namespace std; vector<array<int, 2>> pos[12]; int dist[12][501][501]; char g[501][501]; int n, m, k; bool ok(int i, int j) { return i>=0 && i<n && j>=0 && j<m && g[i][j]!='#'; } int main() { cin >> n >> m >> k; for (int i=0; i<n; i++) for (int j=0; j<m; j++) { cin >> g[i][j]; if (g[i][j]=='S') pos[0].push_back({i, j}); if (g[i][j]=='E') pos[k+1].push_back({i, j}); if ('1'<=g[i][j] && g[i][j]<='9') pos[g[i][j]-'0'].push_back({i, j}); } for (int z=0; z<=k+1; z++) { for (int i=0; i<n; i++) for (int j=0; j<m; j++) { dist[z][i][j] = 1e9; } } for (int z=k+1; z>=0; z--) { queue<array<int, 2>> q; for (auto [i, j]: pos[z]) { if (z==k+1) dist[z][i][j] = 0; else dist[z][i][j] = dist[z+1][i][j]; q.push({i, j}); } while (!q.empty()) { auto t = q.front(); q.pop(); int i = t[0]; int j = t[1]; auto mv = [&](int ni, int nj) { if (ok(i, j) && dist[z][ni][nj]>dist[z][i][j]+1) { dist[z][ni][nj] = dist[z][i][j]+1; q.push({ni, nj}); } }; mv(i-1, j); mv(i+1, j); mv(i, j-1); mv(i, j+1); } } auto [i, j] = pos[0][0]; if (dist[0][i][j]>=1e9) cout << "-1\n"; else cout << dist[0][i][j] << '\n'; }
Test details
Test 1
Group: 3
Verdict: ACCEPTED
input |
---|
10 10 9 S293#35616 #662963731 54975451#7 5162589168 ... |
correct output |
---|
25 |
user output |
---|
25 |
Test 2
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
500 500 0 ................................. |
correct output |
---|
301 |
user output |
---|
301 |
Test 3
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
500 500 0 .#.........#.#..##..#............ |
correct output |
---|
253 |
user output |
---|
253 |
Test 4
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
500 500 0 ...#......##.##.#.#..##..#..##... |
correct output |
---|
-1 |
user output |
---|
-1 |
Test 5
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
500 1 0 . . . . ... |
correct output |
---|
77 |
user output |
---|
77 |
Test 6
Group: 1, 2, 3
Verdict: ACCEPTED
input |
---|
1 500 0 ................................. |
correct output |
---|
166 |
user output |
---|
166 |
Test 7
Group: 2, 3
Verdict: ACCEPTED
input |
---|
500 500 9 ................................. |
correct output |
---|
3447 |
user output |
---|
3447 |
Test 8
Group: 2, 3
Verdict: ACCEPTED
input |
---|
500 500 9 .#........#..................#... |
correct output |
---|
4952 |
user output |
---|
4952 |
Test 9
Group: 2, 3
Verdict: ACCEPTED
input |
---|
500 500 9 ##.########.##########.#..#...... |
correct output |
---|
-1 |
user output |
---|
-1 |
Test 10
Group: 3
Verdict: ACCEPTED
input |
---|
500 500 9 623475428948841896621266296765... |
correct output |
---|
205 |
user output |
---|
205 |
Test 11
Group: 3
Verdict: ACCEPTED
input |
---|
500 500 9 7##814125813#3463#272134469457... |
correct output |
---|
157 |
user output |
---|
157 |
Test 12
Group: 3
Verdict: ACCEPTED
input |
---|
500 500 9 ##67##36##5#3###67###8972#61##... |
correct output |
---|
-1 |
user output |
---|
-1 |
Test 13
Group: 3
Verdict: ACCEPTED
input |
---|
500 500 9 ....................#...#........ |
correct output |
---|
1313 |
user output |
---|
1313 |
Test 14
Group: 2, 3
Verdict: ACCEPTED
input |
---|
499 499 9 S#...#...#...#...#...#...#...#... |
correct output |
---|
1124942 |
user output |
---|
1124942 |
Test 15
Group: 3
Verdict: ACCEPTED
input |
---|
500 1 9 1 6 1 3 ... |
correct output |
---|
332 |
user output |
---|
332 |
Test 16
Group: 3
Verdict: ACCEPTED
input |
---|
1 500 9 996327784392827829434482995353... |
correct output |
---|
135 |
user output |
---|
135 |
Test 17
Group: 2, 3
Verdict: ACCEPTED
input |
---|
500 500 9 ................................. |
correct output |
---|
-1 |
user output |
---|
-1 |