Task: | Suunnistus |
Sender: | zli0122 |
Submission time: | 2025-01-18 15:29:38 +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.06 s | 1, 2, 3 | details |
#3 | ACCEPTED | 0.06 s | 1, 2, 3 | details |
#4 | ACCEPTED | 0.05 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.16 s | 2, 3 | details |
#8 | ACCEPTED | 0.15 s | 2, 3 | details |
#9 | ACCEPTED | 0.05 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.55 s | 3 | details |
#14 | ACCEPTED | 0.16 s | 2, 3 | details |
#15 | ACCEPTED | 0.04 s | 3 | details |
#16 | ACCEPTED | 0.04 s | 3 | details |
#17 | ACCEPTED | 0.07 s | 2, 3 | details |
Compiler report
input/code.cpp: In function 'void solve()': input/code.cpp:51:18: warning: unused variable 'done' [-Wunused-variable] 51 | bool done = false; | ^~~~
Code
#include <bits/stdc++.h> using namespace std; //#define int long long typedef vector<int> vi; typedef pair<int, int> pi; #define fi first #define se second #define pb push_back #define MOD 1000000007 #define INF INT32_MAX/2-1 void solve() { int N, M, K; cin >> N >> M >> K; vector<int> adj[251010]; bool wall[251010]; set<int> rastit[K+2]; for (int r=0;r<N;r++) for (int c=0; c<M; c++) { char x; cin >> x; if (x == '#') wall[r*M+c] = true; if (x == 'S') rastit[0].insert(r*M+c); if (x == 'E') rastit[K+1].insert(r*M+c); if (('1' <= x) && (x <= '9')) rastit[x-'1'+1].insert(r*M+c); if (r > 0) adj[r*M+c].pb(r*M+c-M); if (c > 0) adj[r*M+c].pb(r*M+c-1); if (r < N-1) adj[r*M+c].pb(r*M+c+M); if (c < M-1) adj[r*M+c].pb(r*M+c+1); } //for (auto rasti : rastit) {for (auto ruutu : rasti) cout << ruutu << " ";cout << "\n";} queue<tuple<int, int, int>> edgelist; for (int i=0; i<K+1; i++) { for (auto start : rastit[i]) { bool vis[251010]; copy(wall, wall + 251010, vis); int dis[251010] = {}; queue<int> q; q.push(start); vis[start]=true; bool done = false; while (!q.empty()){ int u = q.front(); q.pop(); for (auto child : adj[u]) { if (vis[child]) continue; dis[child] = dis[u] + 1; if (rastit[i+1].count(child)) edgelist.push({start, child, dis[child]}); vis[child] = true; q.push(child); } } } } int dis[251010] = {}; for (int i=1; i<=K+1; i++) { for (auto ruutu : rastit[i]) { dis[ruutu] = INF; } } while (!edgelist.empty()) { int a, b, w; tie(a, b, w) = edgelist.front(); //printf("a: %d, b: %d, w: %d\n", a, b, w); edgelist.pop(); //printf("disb=%d, disa=%d, w=%d\n\n", dis[b], dis[a], w); dis[b] = min(dis[b], dis[a] + w); } //cout << *(rastit[K+1].begin()) << endl; if (dis[*(rastit[K+1].begin())] == INF) cout << "-1\n"; else cout << dis[*(rastit[K+1].begin())] << "\n"; } signed main() { cin.tie(0) -> ios::sync_with_stdio(0); solve(); }
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 |