# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1010533 |
2024-06-29T07:53:03 Z |
정민찬(#10827) |
Highway Tolls (IOI18_highway) |
C++17 |
|
174 ms |
11144 KB |
#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
long long ask(const std::vector<int> &w);
void answer(int s, int t);
vector<vector<pair<int,int>>> adj;
vector<int> dist;
void getDist(int st) {
int N = adj.size();
vector<int> vis(N, 0);
queue<int> q;
q.push(st);
dist[st] = 0;
vis[st] = 1;
while (!q.empty()) {
int x = q.front();
q.pop();
for (auto &[y, _] : adj[x]) {
if (!vis[y]) {
dist[y] = dist[x] + 1;
vis[y] = 1;
q.push(y);
}
}
}
}
void find_pair(int N, vector<int> U, vector<int> V, int A, int B) {
adj.resize(N);
int M = U.size();
for (int i=0; i<M; i++) {
adj[U[i]].push_back({V[i], i});
adj[V[i]].push_back({U[i], i});
}
int cnt = 0;
assert(cnt <= 51); cnt ++;
ll mndist = ask(vector<int>(M, 0));
int num = mndist / (ll)A;
int s = 0, e = N-1;
vector<int> t(M, 0);
while (s < e) {
int mid = s + e >> 1;
vector<int> w = t;
for (int i=s; i<=mid; i++) {
for (auto &[j, k] : adj[i]) {
w[k] = 1;
}
}
assert(cnt <= 51); cnt ++;
ll ret = ask(w);
if (ret == mndist) s = mid + 1, t = w;
else e = mid;
}
int rt = s;
dist.assign(N, 0);
getDist(rt);
vector<int> idx(N);
iota(idx.begin(), idx.end(), 0);
sort(idx.begin(), idx.end(), [&] (int &x, int &y) { return dist[x] > dist[y]; });
s = 0; e = N-1;
for (int i=0; i<N; i++) {
if (dist[idx[i]] * 2 < num) {
e = i-1;
break;
}
}
while (s < e) {
int mid = s + e >> 1;
vector<int> w(M, 0);
for (int i=0; i<=mid; i++) {
for (auto &[j, k] : adj[idx[i]]) {
w[k] = 1;
}
}
assert(cnt <= 51); cnt ++;
ll ret = ask(w);
if (ret == mndist) s = mid + 1;
else e = mid;
}
int u = idx[s];
getDist(u);
vector<int> cand;
vector<int> rev(N);
for (int i=0; i<N; i++) {
rev[idx[i]] = i;
}
for (int i=0; i<N; i++) {
if (rev[i] > s && (ll)A * (ll)dist[i] == mndist) {
cand.push_back(i);
}
}
s = 0; e = cand.size() - 1;
while (s < e) {
int mid = s + e >> 1;
vector<int> w(M, 0);
for (int i=s; i<=mid; i++) {
for (auto &[j, k] : adj[cand[i]]) {
w[k] = 1;
}
}
assert(cnt <= 51); cnt ++;
ll ret = ask(w);
if (ret == mndist) s = mid + 1;
else e = mid;
}
int v = cand[s];
answer(u, v);
}
Compilation message
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:47:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
47 | int mid = s + e >> 1;
| ~~^~~
highway.cpp:73:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
73 | int mid = s + e >> 1;
| ~~^~~
highway.cpp:99:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
99 | int mid = s + e >> 1;
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
9 ms |
1272 KB |
Output is correct |
3 |
Correct |
94 ms |
9176 KB |
Output is correct |
4 |
Correct |
89 ms |
9132 KB |
Output is correct |
5 |
Correct |
96 ms |
9220 KB |
Output is correct |
6 |
Correct |
81 ms |
9132 KB |
Output is correct |
7 |
Correct |
97 ms |
9092 KB |
Output is correct |
8 |
Correct |
100 ms |
8928 KB |
Output is correct |
9 |
Correct |
99 ms |
8972 KB |
Output is correct |
10 |
Correct |
104 ms |
9104 KB |
Output is correct |
11 |
Correct |
88 ms |
8380 KB |
Output is correct |
12 |
Correct |
87 ms |
8596 KB |
Output is correct |
13 |
Correct |
81 ms |
8528 KB |
Output is correct |
14 |
Correct |
80 ms |
8504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
1112 KB |
Output is correct |
2 |
Correct |
14 ms |
2020 KB |
Output is correct |
3 |
Correct |
23 ms |
2908 KB |
Output is correct |
4 |
Correct |
65 ms |
8180 KB |
Output is correct |
5 |
Correct |
63 ms |
8180 KB |
Output is correct |
6 |
Correct |
65 ms |
8360 KB |
Output is correct |
7 |
Correct |
64 ms |
8184 KB |
Output is correct |
8 |
Correct |
74 ms |
8664 KB |
Output is correct |
9 |
Correct |
64 ms |
8188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
9 ms |
1368 KB |
Output is correct |
3 |
Correct |
72 ms |
7060 KB |
Output is correct |
4 |
Correct |
94 ms |
9116 KB |
Output is correct |
5 |
Correct |
90 ms |
9072 KB |
Output is correct |
6 |
Correct |
98 ms |
9108 KB |
Output is correct |
7 |
Correct |
93 ms |
8892 KB |
Output is correct |
8 |
Correct |
94 ms |
9012 KB |
Output is correct |
9 |
Correct |
93 ms |
8956 KB |
Output is correct |
10 |
Correct |
101 ms |
9264 KB |
Output is correct |
11 |
Correct |
91 ms |
8524 KB |
Output is correct |
12 |
Correct |
86 ms |
8180 KB |
Output is correct |
13 |
Correct |
92 ms |
8428 KB |
Output is correct |
14 |
Correct |
102 ms |
8284 KB |
Output is correct |
15 |
Correct |
91 ms |
9072 KB |
Output is correct |
16 |
Correct |
87 ms |
8784 KB |
Output is correct |
17 |
Correct |
99 ms |
8296 KB |
Output is correct |
18 |
Correct |
90 ms |
8328 KB |
Output is correct |
19 |
Correct |
100 ms |
8928 KB |
Output is correct |
20 |
Correct |
94 ms |
8184 KB |
Output is correct |
21 |
Correct |
80 ms |
9704 KB |
Output is correct |
22 |
Correct |
89 ms |
9648 KB |
Output is correct |
23 |
Correct |
82 ms |
9956 KB |
Output is correct |
24 |
Correct |
75 ms |
9624 KB |
Output is correct |
25 |
Correct |
82 ms |
8548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
1368 KB |
Output is correct |
2 |
Correct |
10 ms |
1368 KB |
Output is correct |
3 |
Correct |
109 ms |
9520 KB |
Output is correct |
4 |
Correct |
115 ms |
10000 KB |
Output is correct |
5 |
Correct |
148 ms |
10868 KB |
Output is correct |
6 |
Correct |
138 ms |
11088 KB |
Output is correct |
7 |
Correct |
139 ms |
11144 KB |
Output is correct |
8 |
Correct |
132 ms |
10964 KB |
Output is correct |
9 |
Correct |
97 ms |
7368 KB |
Output is correct |
10 |
Correct |
100 ms |
7688 KB |
Output is correct |
11 |
Correct |
111 ms |
8676 KB |
Output is correct |
12 |
Correct |
174 ms |
10160 KB |
Output is correct |
13 |
Correct |
149 ms |
10608 KB |
Output is correct |
14 |
Correct |
148 ms |
10928 KB |
Output is correct |
15 |
Correct |
152 ms |
10928 KB |
Output is correct |
16 |
Correct |
129 ms |
8716 KB |
Output is correct |
17 |
Correct |
84 ms |
9792 KB |
Output is correct |
18 |
Correct |
80 ms |
9812 KB |
Output is correct |
19 |
Correct |
87 ms |
9888 KB |
Output is correct |
20 |
Correct |
89 ms |
9976 KB |
Output is correct |
21 |
Correct |
165 ms |
11048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
1336 KB |
Output is correct |
2 |
Correct |
10 ms |
1456 KB |
Output is correct |
3 |
Correct |
121 ms |
9564 KB |
Output is correct |
4 |
Correct |
120 ms |
9764 KB |
Output is correct |
5 |
Correct |
135 ms |
10204 KB |
Output is correct |
6 |
Correct |
128 ms |
10816 KB |
Output is correct |
7 |
Correct |
116 ms |
9576 KB |
Output is correct |
8 |
Correct |
119 ms |
9812 KB |
Output is correct |
9 |
Correct |
134 ms |
10100 KB |
Output is correct |
10 |
Correct |
146 ms |
10824 KB |
Output is correct |
11 |
Correct |
137 ms |
11068 KB |
Output is correct |
12 |
Correct |
161 ms |
11132 KB |
Output is correct |
13 |
Correct |
118 ms |
8320 KB |
Output is correct |
14 |
Correct |
98 ms |
7740 KB |
Output is correct |
15 |
Correct |
108 ms |
8252 KB |
Output is correct |
16 |
Correct |
101 ms |
7700 KB |
Output is correct |
17 |
Correct |
108 ms |
8544 KB |
Output is correct |
18 |
Correct |
105 ms |
8036 KB |
Output is correct |
19 |
Correct |
162 ms |
10056 KB |
Output is correct |
20 |
Correct |
140 ms |
10564 KB |
Output is correct |
21 |
Correct |
143 ms |
10976 KB |
Output is correct |
22 |
Correct |
146 ms |
11052 KB |
Output is correct |
23 |
Correct |
133 ms |
11056 KB |
Output is correct |
24 |
Correct |
144 ms |
11076 KB |
Output is correct |
25 |
Correct |
147 ms |
11136 KB |
Output is correct |
26 |
Correct |
132 ms |
11060 KB |
Output is correct |
27 |
Correct |
90 ms |
9736 KB |
Output is correct |
28 |
Correct |
85 ms |
9656 KB |
Output is correct |
29 |
Correct |
106 ms |
10036 KB |
Output is correct |
30 |
Correct |
96 ms |
9532 KB |
Output is correct |
31 |
Correct |
88 ms |
9644 KB |
Output is correct |
32 |
Partially correct |
86 ms |
9696 KB |
Output is partially correct |
33 |
Correct |
82 ms |
9796 KB |
Output is correct |
34 |
Correct |
83 ms |
9916 KB |
Output is correct |
35 |
Correct |
92 ms |
10088 KB |
Output is correct |
36 |
Correct |
85 ms |
9740 KB |
Output is correct |
37 |
Correct |
91 ms |
9948 KB |
Output is correct |
38 |
Correct |
92 ms |
9984 KB |
Output is correct |
39 |
Correct |
152 ms |
11020 KB |
Output is correct |
40 |
Correct |
135 ms |
10848 KB |
Output is correct |
41 |
Correct |
124 ms |
11044 KB |
Output is correct |
42 |
Correct |
149 ms |
10808 KB |
Output is correct |