# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1010532 |
2024-06-29T07:45:03 Z |
정민찬(#10827) |
Highway Tolls (IOI18_highway) |
C++17 |
|
159 ms |
11408 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 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;
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;
for (int i=0; i<N; i++) {
if ((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:46:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
46 | int mid = s + e >> 1;
| ~~^~~
highway.cpp:66:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
66 | int mid = s + e >> 1;
| ~~^~~
highway.cpp:88:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
88 | int mid = s + e >> 1;
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
344 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 |
0 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 |
7 ms |
1380 KB |
Output is correct |
3 |
Correct |
89 ms |
9016 KB |
Output is correct |
4 |
Correct |
100 ms |
9212 KB |
Output is correct |
5 |
Correct |
90 ms |
8888 KB |
Output is correct |
6 |
Correct |
84 ms |
8780 KB |
Output is correct |
7 |
Correct |
96 ms |
8984 KB |
Output is correct |
8 |
Correct |
96 ms |
8780 KB |
Output is correct |
9 |
Correct |
95 ms |
8976 KB |
Output is correct |
10 |
Correct |
86 ms |
9008 KB |
Output is correct |
11 |
Correct |
84 ms |
8180 KB |
Output is correct |
12 |
Correct |
110 ms |
8192 KB |
Output is correct |
13 |
Correct |
91 ms |
8188 KB |
Output is correct |
14 |
Correct |
77 ms |
8188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
1228 KB |
Output is correct |
2 |
Correct |
12 ms |
2136 KB |
Output is correct |
3 |
Correct |
22 ms |
2900 KB |
Output is correct |
4 |
Correct |
71 ms |
8192 KB |
Output is correct |
5 |
Correct |
68 ms |
8176 KB |
Output is correct |
6 |
Correct |
71 ms |
8184 KB |
Output is correct |
7 |
Correct |
76 ms |
8192 KB |
Output is correct |
8 |
Correct |
70 ms |
8100 KB |
Output is correct |
9 |
Correct |
69 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 |
71 ms |
6932 KB |
Output is correct |
4 |
Correct |
105 ms |
8760 KB |
Output is correct |
5 |
Correct |
98 ms |
8780 KB |
Output is correct |
6 |
Correct |
95 ms |
8768 KB |
Output is correct |
7 |
Correct |
82 ms |
8784 KB |
Output is correct |
8 |
Correct |
85 ms |
8764 KB |
Output is correct |
9 |
Correct |
86 ms |
8760 KB |
Output is correct |
10 |
Correct |
83 ms |
8952 KB |
Output is correct |
11 |
Correct |
91 ms |
8180 KB |
Output is correct |
12 |
Correct |
78 ms |
8180 KB |
Output is correct |
13 |
Correct |
107 ms |
8180 KB |
Output is correct |
14 |
Correct |
107 ms |
8192 KB |
Output is correct |
15 |
Correct |
102 ms |
8792 KB |
Output is correct |
16 |
Correct |
94 ms |
8768 KB |
Output is correct |
17 |
Correct |
90 ms |
8180 KB |
Output is correct |
18 |
Correct |
93 ms |
8176 KB |
Output is correct |
19 |
Correct |
100 ms |
8780 KB |
Output is correct |
20 |
Correct |
84 ms |
8184 KB |
Output is correct |
21 |
Correct |
84 ms |
9416 KB |
Output is correct |
22 |
Correct |
86 ms |
9296 KB |
Output is correct |
23 |
Correct |
79 ms |
9240 KB |
Output is correct |
24 |
Correct |
76 ms |
9356 KB |
Output is correct |
25 |
Correct |
90 ms |
8348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
1368 KB |
Output is correct |
2 |
Correct |
10 ms |
1384 KB |
Output is correct |
3 |
Correct |
104 ms |
9492 KB |
Output is correct |
4 |
Correct |
133 ms |
9800 KB |
Output is correct |
5 |
Correct |
145 ms |
11408 KB |
Output is correct |
6 |
Correct |
139 ms |
11076 KB |
Output is correct |
7 |
Correct |
153 ms |
10920 KB |
Output is correct |
8 |
Correct |
130 ms |
11052 KB |
Output is correct |
9 |
Correct |
112 ms |
7388 KB |
Output is correct |
10 |
Correct |
101 ms |
7708 KB |
Output is correct |
11 |
Correct |
111 ms |
8680 KB |
Output is correct |
12 |
Correct |
136 ms |
10060 KB |
Output is correct |
13 |
Correct |
145 ms |
10484 KB |
Output is correct |
14 |
Correct |
121 ms |
10932 KB |
Output is correct |
15 |
Correct |
137 ms |
10908 KB |
Output is correct |
16 |
Correct |
119 ms |
8956 KB |
Output is correct |
17 |
Correct |
90 ms |
9400 KB |
Output is correct |
18 |
Correct |
90 ms |
9652 KB |
Output is correct |
19 |
Correct |
82 ms |
9616 KB |
Output is correct |
20 |
Correct |
82 ms |
9664 KB |
Output is correct |
21 |
Correct |
132 ms |
10700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
1332 KB |
Output is correct |
2 |
Correct |
10 ms |
1372 KB |
Output is correct |
3 |
Correct |
120 ms |
9232 KB |
Output is correct |
4 |
Correct |
109 ms |
9528 KB |
Output is correct |
5 |
Correct |
108 ms |
9912 KB |
Output is correct |
6 |
Correct |
131 ms |
11064 KB |
Output is correct |
7 |
Correct |
102 ms |
9320 KB |
Output is correct |
8 |
Correct |
108 ms |
9428 KB |
Output is correct |
9 |
Correct |
137 ms |
9904 KB |
Output is correct |
10 |
Correct |
150 ms |
11064 KB |
Output is correct |
11 |
Correct |
135 ms |
11068 KB |
Output is correct |
12 |
Correct |
159 ms |
11128 KB |
Output is correct |
13 |
Correct |
107 ms |
8248 KB |
Output is correct |
14 |
Correct |
120 ms |
7704 KB |
Output is correct |
15 |
Correct |
107 ms |
8740 KB |
Output is correct |
16 |
Correct |
122 ms |
7700 KB |
Output is correct |
17 |
Correct |
102 ms |
8868 KB |
Output is correct |
18 |
Correct |
93 ms |
8008 KB |
Output is correct |
19 |
Correct |
130 ms |
10184 KB |
Output is correct |
20 |
Correct |
126 ms |
10328 KB |
Output is correct |
21 |
Correct |
133 ms |
11056 KB |
Output is correct |
22 |
Correct |
129 ms |
11044 KB |
Output is correct |
23 |
Correct |
130 ms |
11076 KB |
Output is correct |
24 |
Correct |
127 ms |
11072 KB |
Output is correct |
25 |
Correct |
142 ms |
10920 KB |
Output is correct |
26 |
Correct |
136 ms |
10916 KB |
Output is correct |
27 |
Partially correct |
88 ms |
9500 KB |
Output is partially correct |
28 |
Correct |
74 ms |
9496 KB |
Output is correct |
29 |
Correct |
87 ms |
9696 KB |
Output is correct |
30 |
Correct |
94 ms |
9592 KB |
Output is correct |
31 |
Correct |
79 ms |
9440 KB |
Output is correct |
32 |
Partially correct |
77 ms |
9488 KB |
Output is partially correct |
33 |
Partially correct |
80 ms |
9720 KB |
Output is partially correct |
34 |
Correct |
72 ms |
9540 KB |
Output is correct |
35 |
Correct |
81 ms |
9552 KB |
Output is correct |
36 |
Partially correct |
90 ms |
9540 KB |
Output is partially correct |
37 |
Correct |
92 ms |
9656 KB |
Output is correct |
38 |
Correct |
103 ms |
9632 KB |
Output is correct |
39 |
Correct |
127 ms |
10804 KB |
Output is correct |
40 |
Correct |
136 ms |
10724 KB |
Output is correct |
41 |
Correct |
119 ms |
10696 KB |
Output is correct |
42 |
Correct |
123 ms |
10708 KB |
Output is correct |