Task: | Suunnistus |
Sender: | Verlet |
Submission time: | 2025-01-18 16:53:45 +0200 |
Language: | C++ (C++17) |
Status: | READY |
Result: | 43 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 31 |
#2 | ACCEPTED | 12 |
#3 | TIME LIMIT EXCEEDED | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.01 s | 3 | details |
#2 | ACCEPTED | 0.03 s | 1, 2, 3 | details |
#3 | ACCEPTED | 0.03 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.01 s | 1, 2, 3 | details |
#7 | ACCEPTED | 0.15 s | 2, 3 | details |
#8 | ACCEPTED | 0.16 s | 2, 3 | details |
#9 | ACCEPTED | 0.02 s | 2, 3 | details |
#10 | TIME LIMIT EXCEEDED | -- | 3 | details |
#11 | TIME LIMIT EXCEEDED | -- | 3 | details |
#12 | TIME LIMIT EXCEEDED | -- | 3 | details |
#13 | ACCEPTED | 0.66 s | 3 | details |
#14 | ACCEPTED | 0.08 s | 2, 3 | details |
#15 | ACCEPTED | 0.03 s | 3 | details |
#16 | ACCEPTED | 0.03 s | 3 | details |
#17 | ACCEPTED | 0.03 s | 2, 3 | details |
Compiler report
input/code.cpp: In function 'int main()': input/code.cpp:145:37: warning: array subscript has type 'char' [-Wchar-subscripts] 145 | if (c > 48 && c < 58) flags[c].pb({x, y}); | ^ input/code.cpp:158:27: warning: array subscript has type 'char' [-Wchar-subscripts] 158 | for (ip p : flags[c]) | ^
Code
#include <bits/stdc++.h> #define newl "\n" #define pb push_back #define X first #define Y second #define N 502 using namespace std; typedef long long ll; typedef pair<int, int> ip; typedef pair<ll, ll> lp; struct Move { ip p; int d; }; char m[N][N]; bool v[N][N]; bool visited[N * N]; int h, w, k; vector<ip> adj[N * N]; int index(ip p) { return p.Y * (w + 2) + p.X; } void clear_visited() { for (int y = 1; y <= h; y++) for (int x = 1; x <= w; x++) { v[x][y] = false; } } bool valid(ip p) { return v[p.X][p.Y] == false && m[p.X][p.Y] != '#'; } void bfs(ip start, char target) { queue<Move> q; q.push({start, 0}); int start_index = index(start); while (q.size() > 0) { Move move = q.front(); q.pop(); if (!valid(move.p)) continue; int x = move.p.X; int y = move.p.Y; int d = move.d; v[x][y] = true; if (m[x][y] == target) { adj[start_index].pb({index(move.p), d}); } q.push({{x+1, y}, d+1}); q.push({{x-1, y}, d+1}); q.push({{x, y+1}, d+1}); q.push({{x, y-1}, d+1}); } clear_visited(); } int dijkstra(ip start, ip end) { priority_queue<ip, vector<ip>, greater<ip>> q; int start_index = index(start); int end_index = index(end); q.push({0, start_index}); while (q.size() > 0) { ip p = q.top(); q.pop(); int distance = p.first; int index = p.second; if (visited[index]) continue; visited[index] = true; if (index == end_index) { return distance; } for (ip p : adj[index]) { q.push({distance + p.second, p.first}); } } return -1; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); for (int y = 0; y < N; y++) for (int x = 0; x < N; x++) { m[x][y] = '#'; } cin >> h >> w >> k; ip start, end; vector<ip> flags[128]; for (int y = 1; y <= h; y++) for (int x = 1; x <= w; x++) { char c; cin >> c; if (c != '#') m[x][y] = c; if (c == 'S') start = {x, y}; if (c == 'E') end = {x, y}; if (c > 48 && c < 58) flags[c].pb({x, y}); } if (k == 0) { bfs(start, 'E'); cout << dijkstra(start, end); exit(0); } bfs(start, '1'); for (char c = '1'; c < '1' + k; c++) for (ip p : flags[c]) bfs(p, c+1); for (ip p : flags['1' + k - 1]) bfs(p, 'E'); cout << dijkstra(start, end) << endl; }
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: TIME LIMIT EXCEEDED
input |
---|
500 500 9 623475428948841896621266296765... |
correct output |
---|
205 |
user output |
---|
(empty) |
Test 11
Group: 3
Verdict: TIME LIMIT EXCEEDED
input |
---|
500 500 9 7##814125813#3463#272134469457... |
correct output |
---|
157 |
user output |
---|
(empty) |
Test 12
Group: 3
Verdict: TIME LIMIT EXCEEDED
input |
---|
500 500 9 ##67##36##5#3###67###8972#61##... |
correct output |
---|
-1 |
user output |
---|
(empty) |
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 |