Task: | Suunnistus |
Sender: | PMak |
Submission time: | 2025-01-18 15:14:19 +0200 |
Language: | C++ (C++17) |
Status: | READY |
Result: | 0 |
group | verdict | score |
---|---|---|
#1 | WRONG ANSWER | 0 |
#2 | WRONG ANSWER | 0 |
#3 | WRONG ANSWER | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | WRONG ANSWER | 0.01 s | 3 | details |
#2 | WRONG ANSWER | 0.02 s | 1, 2, 3 | details |
#3 | WRONG ANSWER | 0.02 s | 1, 2, 3 | details |
#4 | WRONG ANSWER | 0.02 s | 1, 2, 3 | details |
#5 | WRONG ANSWER | 0.01 s | 1, 2, 3 | details |
#6 | WRONG ANSWER | 0.01 s | 1, 2, 3 | details |
#7 | WRONG ANSWER | 0.03 s | 2, 3 | details |
#8 | WRONG ANSWER | 0.04 s | 2, 3 | details |
#9 | WRONG ANSWER | 0.02 s | 2, 3 | details |
#10 | WRONG ANSWER | 0.03 s | 3 | details |
#11 | WRONG ANSWER | 0.03 s | 3 | details |
#12 | WRONG ANSWER | 0.02 s | 3 | details |
#13 | WRONG ANSWER | 0.03 s | 3 | details |
#14 | WRONG ANSWER | 0.05 s | 2, 3 | details |
#15 | WRONG ANSWER | 0.01 s | 3 | details |
#16 | WRONG ANSWER | 0.01 s | 3 | details |
#17 | ACCEPTED | 0.02 s | 2, 3 | details |
Compiler report
input/code.cpp: In function 'int bfs(std::pair<int, int>, std::pair<int, int>)': input/code.cpp:38:18: warning: left operand of comma operator has no effect [-Wunused-value] 38 | if (i==en.first, j==en.second) { | ~^~~~~~~~~~
Code
#include<bits/stdc++.h> #define F0R(i, n) for (i = 0; i < n; ++i) #define FOR(i, l, r) for (i = l; i < r; ++i) #define pii pair<int, int> using namespace std; const int N = 501; const int mx = 1000000000; int grid[N][N]; // -1 = obstacle, 0 = start, path, 10 = end, 1-9: controls int dis[N][N]; int vis[N][N]; int n, m, k; int dif[][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; int bfs(pii st, pii en) { int i, j; F0R (i, N) { F0R (j, N) vis[i][j] = 0; } queue<pair<pii, int>> q; q.push({st, 0}); int a, b, d, x; pii p; while (!q.empty()) { tie(p, d) = q.front(); tie(a, b) = p; q.pop(); F0R (x, 4) { i = a+dif[x][0]; j = b+dif[x][1]; if (i < 0 || i >= n) continue; if (j < 0 || j >= m) continue; if (vis[i][j]) continue; vis[i][j] = true; if (grid[i][j] == -1) continue; if (i==en.first, j==en.second) { return d+1; } q.push({{i, j}, d+1}); } } return -1; } int main() { memset(grid, -1, sizeof(grid)); memset(vis, 0, sizeof(vis)); int i, j; cin >> n >> m >> k; char ch; pii start = {0, 0}, en; vector<pii> control(k, {-1, -1}); F0R (i, n) { F0R (j, m) { cin >> ch; dis[i][j] = mx; if (ch == '#') grid[i][j] = -1; else if (ch == '.') grid[i][j] = 0; else if (ch == 'S') { grid[i][j] = 0; start = {i, j}; dis[i][j] = 0; } else if (ch == 'E') { en = {i, j}; grid[i][j] = 10; } else { grid[i][j] = int(ch-'0'); control[ch-'1'] = {i, j}; } } } if (k == 0) { int length = bfs(start, en); cout << length+1; return 0; } if (control[0].first == -1 && control[0].second == -1) { cout << "-1\n"; return 0; } int length = bfs(start, control[0])+1; control.push_back(en); FOR (i, 1, k+1) { if (control[i].first == -1 && control[i].second == -1) { cout << "-1\n"; return 0; } length += bfs(control[i-1], control[i])+1; } cout << length; }
Test details
Test 1
Group: 3
Verdict: WRONG ANSWER
input |
---|
10 10 9 S293#35616 #662963731 54975451#7 5162589168 ... |
correct output |
---|
25 |
user output |
---|
59 |
Test 2
Group: 1, 2, 3
Verdict: WRONG ANSWER
input |
---|
500 500 0 ................................. |
correct output |
---|
301 |
user output |
---|
183 |
Test 3
Group: 1, 2, 3
Verdict: WRONG ANSWER
input |
---|
500 500 0 .#.........#.#..##..#............ |
correct output |
---|
253 |
user output |
---|
40 |
Test 4
Group: 1, 2, 3
Verdict: WRONG ANSWER
input |
---|
500 500 0 ...#......##.##.#.#..##..#..##... |
correct output |
---|
-1 |
user output |
---|
0 |
Test 5
Group: 1, 2, 3
Verdict: WRONG ANSWER
input |
---|
500 1 0 . . . . ... |
correct output |
---|
77 |
user output |
---|
2 |
Test 6
Group: 1, 2, 3
Verdict: WRONG ANSWER
input |
---|
1 500 0 ................................. |
correct output |
---|
166 |
user output |
---|
167 |
Test 7
Group: 2, 3
Verdict: WRONG ANSWER
input |
---|
500 500 9 ................................. |
correct output |
---|
3447 |
user output |
---|
1508 |
Test 8
Group: 2, 3
Verdict: WRONG ANSWER
input |
---|
500 500 9 .#........#..................#... |
correct output |
---|
4952 |
user output |
---|
2723 |
Test 9
Group: 2, 3
Verdict: WRONG ANSWER
input |
---|
500 500 9 ##.########.##########.#..#...... |
correct output |
---|
-1 |
user output |
---|
0 |
Test 10
Group: 3
Verdict: WRONG ANSWER
input |
---|
500 500 9 623475428948841896621266296765... |
correct output |
---|
205 |
user output |
---|
913 |
Test 11
Group: 3
Verdict: WRONG ANSWER
input |
---|
500 500 9 7##814125813#3463#272134469457... |
correct output |
---|
157 |
user output |
---|
609 |
Test 12
Group: 3
Verdict: WRONG ANSWER
input |
---|
500 500 9 ##67##36##5#3###67###8972#61##... |
correct output |
---|
-1 |
user output |
---|
7 |
Test 13
Group: 3
Verdict: WRONG ANSWER
input |
---|
500 500 9 ....................#...#........ |
correct output |
---|
1313 |
user output |
---|
1826 |
Test 14
Group: 2, 3
Verdict: WRONG ANSWER
input |
---|
499 499 9 S#...#...#...#...#...#...#...#... |
correct output |
---|
1124942 |
user output |
---|
1120491 |
Test 15
Group: 3
Verdict: WRONG ANSWER
input |
---|
500 1 9 1 6 1 3 ... |
correct output |
---|
332 |
user output |
---|
20 |
Test 16
Group: 3
Verdict: WRONG ANSWER
input |
---|
1 500 9 996327784392827829434482995353... |
correct output |
---|
135 |
user output |
---|
707 |
Test 17
Group: 2, 3
Verdict: ACCEPTED
input |
---|
500 500 9 ................................. |
correct output |
---|
-1 |
user output |
---|
-1 |