Task: | Suunnistus |
Sender: | MikaelM |
Submission time: | 2025-04-20 20:27:41 +0300 |
Language: | C++ (C++17) |
Status: | READY |
Result: | 43 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 31 |
#2 | ACCEPTED | 12 |
#3 | WRONG ANSWER | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | WRONG ANSWER | 0.00 s | 3 | details |
#2 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#3 | ACCEPTED | 0.01 s | 1, 2, 3 | details |
#4 | ACCEPTED | 0.01 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.06 s | 2, 3 | details |
#8 | ACCEPTED | 0.07 s | 2, 3 | details |
#9 | ACCEPTED | 0.01 s | 2, 3 | details |
#10 | WRONG ANSWER | 0.08 s | 3 | details |
#11 | WRONG ANSWER | 0.09 s | 3 | details |
#12 | ACCEPTED | 0.02 s | 3 | details |
#13 | WRONG ANSWER | 0.07 s | 3 | details |
#14 | ACCEPTED | 0.04 s | 2, 3 | details |
#15 | WRONG ANSWER | 0.01 s | 3 | details |
#16 | WRONG ANSWER | 0.00 s | 3 | details |
#17 | ACCEPTED | 0.02 s | 2, 3 | details |
Code
#include <bits/stdc++.h> using namespace std; #define rall(x) x.rbegin(),x.rend() #define all(x) x.begin(),x.end() #define fi first #define se second using ll = long long; char c[501][501]; bool z[501][501]; int e[501][501]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, m, k; cin >> n >> m >> k; vector<pair<pair<int, int>, int>> v; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin >> c[i][j]; if (c[i][j] == 'S') v.push_back({{i, j}, 0}); } } int ans = 1e9; for (int r = 1; r <= k+1; r++) { for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { z[i][j] = false; e[i][j] = 1e9; } } queue<pair<int, int>> bfs; for (auto u : v) { z[u.fi.fi][u.fi.se] = true; e[u.fi.fi][u.fi.se] = u.se; bfs.push({u.fi.fi, u.fi.se}); } v.clear(); while (!bfs.empty()) { auto [y, x] = bfs.front(); bfs.pop(); if (y < n && c[y+1][x] != '#' && !z[y+1][x] && e[y][x]+1 < e[y+1][x]) { z[y+1][x] = true; e[y+1][x] = e[y][x]+1; bfs.push({y+1, x}); } if (y > 1 && c[y-1][x] != '#' && !z[y-1][x] && e[y][x]+1 < e[y-1][x]) { z[y-1][x] = true; e[y-1][x] = e[y][x]+1; bfs.push({y-1, x}); } if (x < m && c[y][x+1] != '#' && !z[y][x+1] && e[y][x]+1 < e[y][x+1]) { z[y][x+1] = true; e[y][x+1] = e[y][x]+1; bfs.push({y, x+1}); } if (x > 1 && c[y][x-1] != '#' && !z[y][x-1] && e[y][x]+1 < e[y][x-1]) { z[y][x-1] = true; e[y][x-1] = e[y][x]+1; bfs.push({y, x-1}); } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (r <= k) { if (c[i][j] == char('0' + r)) v.push_back({{i, j}, e[i][j]}); } else { if (c[i][j] == 'E') ans = min(ans, e[i][j]); } } } } cout << (ans == 1e9 ? -1 : ans) << "\n"; }
Test details
Test 1
Group: 3
Verdict: WRONG ANSWER
input |
---|
10 10 9 S293#35616 #662963731 54975451#7 5162589168 ... |
correct output |
---|
25 |
user output |
---|
27 |
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: WRONG ANSWER
input |
---|
500 500 9 623475428948841896621266296765... |
correct output |
---|
205 |
user output |
---|
229 |
Test 11
Group: 3
Verdict: WRONG ANSWER
input |
---|
500 500 9 7##814125813#3463#272134469457... |
correct output |
---|
157 |
user output |
---|
161 |
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: WRONG ANSWER
input |
---|
500 500 9 ....................#...#........ |
correct output |
---|
1313 |
user output |
---|
1755 |
Test 14
Group: 2, 3
Verdict: ACCEPTED
input |
---|
499 499 9 S#...#...#...#...#...#...#...#... |
correct output |
---|
1124942 |
user output |
---|
1124942 |
Test 15
Group: 3
Verdict: WRONG ANSWER
input |
---|
500 1 9 1 6 1 3 ... |
correct output |
---|
332 |
user output |
---|
378 |
Test 16
Group: 3
Verdict: WRONG ANSWER
input |
---|
1 500 9 996327784392827829434482995353... |
correct output |
---|
135 |
user output |
---|
177 |
Test 17
Group: 2, 3
Verdict: ACCEPTED
input |
---|
500 500 9 ................................. |
correct output |
---|
-1 |
user output |
---|
-1 |