# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
406227 | 2021-05-17T09:42:45 Z | tqbfjotld | From Hacks to Snitches (BOI21_watchmen) | C++14 | 2597 ms | 524292 KB |
#include <bits/stdc++.h> using namespace std; int special[400005]; vector<pair<int,int> > orig; vector<int> routes[2755]; int cnt = 1; vector<int> nodes[400005]; vector<int> new_adjl[400005]; int dist[400005]; int dist2[400005]; int tt[400005]; pair<int,int> rev[400005]; main(){ int n,m; scanf("%d%d",&n,&m); for (int x = 0; x<m; x++){ int a,b; scanf("%d%d",&a,&b); orig.push_back({a,b}); } int K; scanf("%d",&K); for (int x = 0; x<K; x++){ int l; scanf("%d",&l); vector<int> stuff; for (int y = 0; y<l; y++){ int a; scanf("%d",&a); stuff.push_back(a); special[a] = l; tt[a] = y; } } for (int x = 1; x<=n; x++){ for (int y = 0; y<special[x]; y++){ rev[cnt] = {y,special[x]}; dist2[cnt] = 999999999; nodes[x].push_back(cnt++); } if (special[x]==0){ rev[cnt] = {0,0}; dist2[cnt] = 999999999; nodes[x].push_back(cnt++); } } for (auto x : orig){ if (special[x.first]&&special[x.second]){ int l = special[x.first]; for (int t = 0; t<l; t++){ if (tt[x.first]!=t && tt[x.second]!=(t+1)%l && (!(tt[x.first]==(t+1)%l && tt[x.second]==t))) new_adjl[nodes[x.first][t]].push_back(nodes[x.second][(t+1)%l]); if (tt[x.second]!=t && tt[x.first]!=(t+1)%l && (!(tt[x.second]==(t+1)%l && tt[x.first]==t))) new_adjl[nodes[x.second][t]].push_back(nodes[x.first][(t+1)%l]); } } else if (special[x.first]){ int l = special[x.first]; for (int t = 0; t<l; t++){ if (tt[x.first]!=t) new_adjl[nodes[x.first][t]].push_back(nodes[x.second][0]); if (tt[x.first]!=(t+1)%l) new_adjl[nodes[x.second][0]].push_back(nodes[x.first][(t+1)%l]); } } else if (special[x.second]){ int l = special[x.second]; for (int t = 0; t<l; t++){ if (tt[x.second]!=(t+1)%l) new_adjl[nodes[x.first][0]].push_back(nodes[x.second][(t+1)%l]); if (tt[x.second]!=t) new_adjl[nodes[x.second][t]].push_back(nodes[x.first][0]); } } else{ new_adjl[nodes[x.first][0]].push_back(nodes[x.second][0]); new_adjl[nodes[x.second][0]].push_back(nodes[x.first][0]); } } for (int x = 1; x<=n; x++){ if (special[x]){ for (int t = 0; t<special[x]; t++){ if (t==tt[x]) continue; if ((t+1)%special[x]==tt[x]) continue; new_adjl[nodes[x][t]].push_back(nodes[x][(t+1)%special[x]]); } } } memset(dist,-1,sizeof(dist)); priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > q; q.push({0,nodes[1][0]}); while (!q.empty()){ int node = q.top().second; int d = q.top().first; q.pop(); if (dist[node]!=-1) continue; if (rev[node].second){ if (d%rev[node].second!=rev[node].first){ int del = (rev[node].first-d)%rev[node].second; if (del<0) del += rev[node].second; d += del; q.push({d,node}); continue; } } //printf("node %lld, %lld\n",node,d); dist[node] = d; for (auto x : new_adjl[node]){ if (d+1<dist2[x]){ q.push({d+1,x}); dist2[x] = d+1; } } } int ans = dist[nodes[n][0]]; printf(ans==-1?"impossible":"%d",ans); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 230 ms | 72500 KB | Output is correct |
2 | Correct | 133 ms | 30192 KB | Output is correct |
3 | Correct | 154 ms | 29688 KB | Output is correct |
4 | Correct | 211 ms | 47732 KB | Output is correct |
5 | Correct | 22 ms | 21460 KB | Output is correct |
6 | Correct | 122 ms | 29708 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 215 ms | 72536 KB | Output is correct |
2 | Correct | 135 ms | 30176 KB | Output is correct |
3 | Correct | 156 ms | 29780 KB | Output is correct |
4 | Correct | 244 ms | 47528 KB | Output is correct |
5 | Correct | 21 ms | 21452 KB | Output is correct |
6 | Correct | 148 ms | 29660 KB | Output is correct |
7 | Correct | 137 ms | 29172 KB | Output is correct |
8 | Correct | 128 ms | 29052 KB | Output is correct |
9 | Correct | 119 ms | 28880 KB | Output is correct |
10 | Correct | 175 ms | 34448 KB | Output is correct |
11 | Correct | 154 ms | 30780 KB | Output is correct |
12 | Correct | 144 ms | 29168 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 215 ms | 72536 KB | Output is correct |
2 | Correct | 135 ms | 30176 KB | Output is correct |
3 | Correct | 156 ms | 29780 KB | Output is correct |
4 | Correct | 244 ms | 47528 KB | Output is correct |
5 | Correct | 21 ms | 21452 KB | Output is correct |
6 | Correct | 148 ms | 29660 KB | Output is correct |
7 | Correct | 137 ms | 29172 KB | Output is correct |
8 | Correct | 128 ms | 29052 KB | Output is correct |
9 | Correct | 119 ms | 28880 KB | Output is correct |
10 | Correct | 175 ms | 34448 KB | Output is correct |
11 | Correct | 154 ms | 30780 KB | Output is correct |
12 | Correct | 144 ms | 29168 KB | Output is correct |
13 | Correct | 243 ms | 72600 KB | Output is correct |
14 | Correct | 136 ms | 30220 KB | Output is correct |
15 | Correct | 147 ms | 29740 KB | Output is correct |
16 | Correct | 206 ms | 47580 KB | Output is correct |
17 | Correct | 17 ms | 21460 KB | Output is correct |
18 | Correct | 155 ms | 29724 KB | Output is correct |
19 | Correct | 136 ms | 29164 KB | Output is correct |
20 | Correct | 144 ms | 29128 KB | Output is correct |
21 | Correct | 129 ms | 28964 KB | Output is correct |
22 | Correct | 165 ms | 34468 KB | Output is correct |
23 | Correct | 144 ms | 30808 KB | Output is correct |
24 | Correct | 132 ms | 29132 KB | Output is correct |
25 | Correct | 2400 ms | 101696 KB | Output is correct |
26 | Correct | 2511 ms | 109208 KB | Output is correct |
27 | Correct | 2276 ms | 102100 KB | Output is correct |
28 | Correct | 1748 ms | 104676 KB | Output is correct |
29 | Runtime error | 2249 ms | 524292 KB | Execution killed with signal 9 |
30 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 215 ms | 72536 KB | Output is correct |
2 | Correct | 135 ms | 30176 KB | Output is correct |
3 | Correct | 156 ms | 29780 KB | Output is correct |
4 | Correct | 244 ms | 47528 KB | Output is correct |
5 | Correct | 21 ms | 21452 KB | Output is correct |
6 | Correct | 148 ms | 29660 KB | Output is correct |
7 | Correct | 137 ms | 29172 KB | Output is correct |
8 | Correct | 128 ms | 29052 KB | Output is correct |
9 | Correct | 119 ms | 28880 KB | Output is correct |
10 | Correct | 175 ms | 34448 KB | Output is correct |
11 | Correct | 154 ms | 30780 KB | Output is correct |
12 | Correct | 144 ms | 29168 KB | Output is correct |
13 | Correct | 243 ms | 72600 KB | Output is correct |
14 | Correct | 136 ms | 30220 KB | Output is correct |
15 | Correct | 147 ms | 29740 KB | Output is correct |
16 | Correct | 206 ms | 47580 KB | Output is correct |
17 | Correct | 17 ms | 21460 KB | Output is correct |
18 | Correct | 155 ms | 29724 KB | Output is correct |
19 | Correct | 136 ms | 29164 KB | Output is correct |
20 | Correct | 144 ms | 29128 KB | Output is correct |
21 | Correct | 129 ms | 28964 KB | Output is correct |
22 | Correct | 165 ms | 34468 KB | Output is correct |
23 | Correct | 144 ms | 30808 KB | Output is correct |
24 | Correct | 132 ms | 29132 KB | Output is correct |
25 | Correct | 2400 ms | 101696 KB | Output is correct |
26 | Correct | 2511 ms | 109208 KB | Output is correct |
27 | Correct | 2276 ms | 102100 KB | Output is correct |
28 | Correct | 1748 ms | 104676 KB | Output is correct |
29 | Runtime error | 2249 ms | 524292 KB | Execution killed with signal 9 |
30 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 230 ms | 72500 KB | Output is correct |
2 | Correct | 133 ms | 30192 KB | Output is correct |
3 | Correct | 154 ms | 29688 KB | Output is correct |
4 | Correct | 211 ms | 47732 KB | Output is correct |
5 | Correct | 22 ms | 21460 KB | Output is correct |
6 | Correct | 122 ms | 29708 KB | Output is correct |
7 | Correct | 215 ms | 72536 KB | Output is correct |
8 | Correct | 135 ms | 30176 KB | Output is correct |
9 | Correct | 156 ms | 29780 KB | Output is correct |
10 | Correct | 244 ms | 47528 KB | Output is correct |
11 | Correct | 21 ms | 21452 KB | Output is correct |
12 | Correct | 148 ms | 29660 KB | Output is correct |
13 | Correct | 137 ms | 29172 KB | Output is correct |
14 | Correct | 128 ms | 29052 KB | Output is correct |
15 | Correct | 119 ms | 28880 KB | Output is correct |
16 | Correct | 175 ms | 34448 KB | Output is correct |
17 | Correct | 154 ms | 30780 KB | Output is correct |
18 | Correct | 144 ms | 29168 KB | Output is correct |
19 | Correct | 15 ms | 20684 KB | Output is correct |
20 | Correct | 15 ms | 20696 KB | Output is correct |
21 | Correct | 16 ms | 20724 KB | Output is correct |
22 | Correct | 218 ms | 73040 KB | Output is correct |
23 | Correct | 150 ms | 31084 KB | Output is correct |
24 | Correct | 143 ms | 30712 KB | Output is correct |
25 | Correct | 250 ms | 48548 KB | Output is correct |
26 | Correct | 19 ms | 21452 KB | Output is correct |
27 | Correct | 140 ms | 30600 KB | Output is correct |
28 | Correct | 128 ms | 30088 KB | Output is correct |
29 | Correct | 121 ms | 30024 KB | Output is correct |
30 | Correct | 161 ms | 29808 KB | Output is correct |
31 | Correct | 157 ms | 35380 KB | Output is correct |
32 | Correct | 180 ms | 31700 KB | Output is correct |
33 | Correct | 145 ms | 30092 KB | Output is correct |
34 | Correct | 2597 ms | 107840 KB | Output is correct |
35 | Correct | 2477 ms | 97604 KB | Output is correct |
36 | Correct | 2596 ms | 97624 KB | Output is correct |
37 | Incorrect | 2386 ms | 104372 KB | Output isn't correct |
38 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 230 ms | 72500 KB | Output is correct |
2 | Correct | 133 ms | 30192 KB | Output is correct |
3 | Correct | 154 ms | 29688 KB | Output is correct |
4 | Correct | 211 ms | 47732 KB | Output is correct |
5 | Correct | 22 ms | 21460 KB | Output is correct |
6 | Correct | 122 ms | 29708 KB | Output is correct |
7 | Correct | 215 ms | 72536 KB | Output is correct |
8 | Correct | 135 ms | 30176 KB | Output is correct |
9 | Correct | 156 ms | 29780 KB | Output is correct |
10 | Correct | 244 ms | 47528 KB | Output is correct |
11 | Correct | 21 ms | 21452 KB | Output is correct |
12 | Correct | 148 ms | 29660 KB | Output is correct |
13 | Correct | 137 ms | 29172 KB | Output is correct |
14 | Correct | 128 ms | 29052 KB | Output is correct |
15 | Correct | 119 ms | 28880 KB | Output is correct |
16 | Correct | 175 ms | 34448 KB | Output is correct |
17 | Correct | 154 ms | 30780 KB | Output is correct |
18 | Correct | 144 ms | 29168 KB | Output is correct |
19 | Correct | 243 ms | 72600 KB | Output is correct |
20 | Correct | 136 ms | 30220 KB | Output is correct |
21 | Correct | 147 ms | 29740 KB | Output is correct |
22 | Correct | 206 ms | 47580 KB | Output is correct |
23 | Correct | 17 ms | 21460 KB | Output is correct |
24 | Correct | 155 ms | 29724 KB | Output is correct |
25 | Correct | 136 ms | 29164 KB | Output is correct |
26 | Correct | 144 ms | 29128 KB | Output is correct |
27 | Correct | 129 ms | 28964 KB | Output is correct |
28 | Correct | 165 ms | 34468 KB | Output is correct |
29 | Correct | 144 ms | 30808 KB | Output is correct |
30 | Correct | 132 ms | 29132 KB | Output is correct |
31 | Correct | 2400 ms | 101696 KB | Output is correct |
32 | Correct | 2511 ms | 109208 KB | Output is correct |
33 | Correct | 2276 ms | 102100 KB | Output is correct |
34 | Correct | 1748 ms | 104676 KB | Output is correct |
35 | Runtime error | 2249 ms | 524292 KB | Execution killed with signal 9 |
36 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 230 ms | 72500 KB | Output is correct |
2 | Correct | 133 ms | 30192 KB | Output is correct |
3 | Correct | 154 ms | 29688 KB | Output is correct |
4 | Correct | 211 ms | 47732 KB | Output is correct |
5 | Correct | 22 ms | 21460 KB | Output is correct |
6 | Correct | 122 ms | 29708 KB | Output is correct |
7 | Correct | 215 ms | 72536 KB | Output is correct |
8 | Correct | 135 ms | 30176 KB | Output is correct |
9 | Correct | 156 ms | 29780 KB | Output is correct |
10 | Correct | 244 ms | 47528 KB | Output is correct |
11 | Correct | 21 ms | 21452 KB | Output is correct |
12 | Correct | 148 ms | 29660 KB | Output is correct |
13 | Correct | 137 ms | 29172 KB | Output is correct |
14 | Correct | 128 ms | 29052 KB | Output is correct |
15 | Correct | 119 ms | 28880 KB | Output is correct |
16 | Correct | 175 ms | 34448 KB | Output is correct |
17 | Correct | 154 ms | 30780 KB | Output is correct |
18 | Correct | 144 ms | 29168 KB | Output is correct |
19 | Correct | 243 ms | 72600 KB | Output is correct |
20 | Correct | 136 ms | 30220 KB | Output is correct |
21 | Correct | 147 ms | 29740 KB | Output is correct |
22 | Correct | 206 ms | 47580 KB | Output is correct |
23 | Correct | 17 ms | 21460 KB | Output is correct |
24 | Correct | 155 ms | 29724 KB | Output is correct |
25 | Correct | 136 ms | 29164 KB | Output is correct |
26 | Correct | 144 ms | 29128 KB | Output is correct |
27 | Correct | 129 ms | 28964 KB | Output is correct |
28 | Correct | 165 ms | 34468 KB | Output is correct |
29 | Correct | 144 ms | 30808 KB | Output is correct |
30 | Correct | 132 ms | 29132 KB | Output is correct |
31 | Correct | 2400 ms | 101696 KB | Output is correct |
32 | Correct | 2511 ms | 109208 KB | Output is correct |
33 | Correct | 2276 ms | 102100 KB | Output is correct |
34 | Correct | 1748 ms | 104676 KB | Output is correct |
35 | Runtime error | 2249 ms | 524292 KB | Execution killed with signal 9 |
36 | Halted | 0 ms | 0 KB | - |