# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
986615 |
2024-05-20T21:29:29 Z |
CSQ31 |
Stations (IOI20_stations) |
C++17 |
|
609 ms |
1656 KB |
#include "stations.h"
#include<bits/stdc++.h>
using namespace std;
vector<int>adj[1000];
int tin[1000],tout[1000],color[1000];
int timer = -1;
void dfs(int v,int u){
tin[v] = ++timer;
for(int x:adj[v]){
if(x==u)continue;
color[x] = color[v]^1;
dfs(x,v);
}
tout[v] = ++timer;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
for(int i=0;i<n;i++)adj[i].clear();
vector<int>lab(n);
for(int i=0;i+1<n;i++){
adj[v[i]].push_back(u[i]);
adj[u[i]].push_back(v[i]);
}
timer = -1;
dfs(0,-1);
for(int i=0;i<n;i++){
if(color[i])lab[i] = tin[i];
else lab[i] = tout[i];
}
vector<int>crd;
for(int x:lab)crd.push_back(x);
sort(crd.begin(),crd.end());
crd.resize(unique(crd.begin(),crd.end()) - crd.begin());
for(int &x:lab)x = lower_bound(crd.begin(),crd.end(),x) - crd.begin();
return lab;
}
int find_next_station(int s, int t, vector<int> c) {
int n = c.size();
if(c.back() > s){
//s label is tin
int last = s;
for(int i=0;i+1<n;i++){
int l = last+1;
int r = c[i];
if(l <= t && t <= r)return c[i];
last = c[i];
}
return c.back();
}else{
//s label is tout
int last = s;
for(int i=n-1;i>0;i--){
int l = c[i];
int r = last-1;
if(l <= t && t <= r)return c[i];
last = c[i];
}
return c[0];
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
368 ms |
928 KB |
Output is correct |
2 |
Correct |
273 ms |
928 KB |
Output is correct |
3 |
Correct |
609 ms |
940 KB |
Output is correct |
4 |
Correct |
411 ms |
684 KB |
Output is correct |
5 |
Correct |
361 ms |
684 KB |
Output is correct |
6 |
Correct |
294 ms |
916 KB |
Output is correct |
7 |
Correct |
274 ms |
684 KB |
Output is correct |
8 |
Correct |
1 ms |
764 KB |
Output is correct |
9 |
Correct |
2 ms |
768 KB |
Output is correct |
10 |
Correct |
1 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
274 ms |
880 KB |
Output is correct |
2 |
Correct |
328 ms |
820 KB |
Output is correct |
3 |
Correct |
557 ms |
684 KB |
Output is correct |
4 |
Correct |
476 ms |
684 KB |
Output is correct |
5 |
Correct |
407 ms |
684 KB |
Output is correct |
6 |
Correct |
279 ms |
684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
340 ms |
940 KB |
Output is correct |
2 |
Correct |
297 ms |
1184 KB |
Output is correct |
3 |
Correct |
569 ms |
856 KB |
Output is correct |
4 |
Correct |
420 ms |
684 KB |
Output is correct |
5 |
Correct |
395 ms |
684 KB |
Output is correct |
6 |
Correct |
283 ms |
916 KB |
Output is correct |
7 |
Correct |
304 ms |
684 KB |
Output is correct |
8 |
Correct |
1 ms |
764 KB |
Output is correct |
9 |
Correct |
2 ms |
760 KB |
Output is correct |
10 |
Correct |
0 ms |
780 KB |
Output is correct |
11 |
Correct |
399 ms |
684 KB |
Output is correct |
12 |
Correct |
280 ms |
1236 KB |
Output is correct |
13 |
Correct |
274 ms |
1548 KB |
Output is correct |
14 |
Correct |
282 ms |
684 KB |
Output is correct |
15 |
Correct |
31 ms |
764 KB |
Output is correct |
16 |
Correct |
38 ms |
944 KB |
Output is correct |
17 |
Correct |
71 ms |
884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
573 ms |
684 KB |
Output is correct |
2 |
Correct |
459 ms |
940 KB |
Output is correct |
3 |
Correct |
382 ms |
684 KB |
Output is correct |
4 |
Correct |
1 ms |
764 KB |
Output is correct |
5 |
Correct |
3 ms |
768 KB |
Output is correct |
6 |
Correct |
1 ms |
768 KB |
Output is correct |
7 |
Correct |
395 ms |
684 KB |
Output is correct |
8 |
Correct |
566 ms |
684 KB |
Output is correct |
9 |
Correct |
457 ms |
680 KB |
Output is correct |
10 |
Correct |
391 ms |
684 KB |
Output is correct |
11 |
Correct |
3 ms |
768 KB |
Output is correct |
12 |
Correct |
3 ms |
764 KB |
Output is correct |
13 |
Correct |
3 ms |
772 KB |
Output is correct |
14 |
Correct |
3 ms |
772 KB |
Output is correct |
15 |
Correct |
1 ms |
768 KB |
Output is correct |
16 |
Correct |
343 ms |
940 KB |
Output is correct |
17 |
Correct |
319 ms |
940 KB |
Output is correct |
18 |
Correct |
365 ms |
684 KB |
Output is correct |
19 |
Correct |
331 ms |
684 KB |
Output is correct |
20 |
Correct |
316 ms |
684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
353 ms |
920 KB |
Output is correct |
2 |
Correct |
263 ms |
928 KB |
Output is correct |
3 |
Correct |
559 ms |
684 KB |
Output is correct |
4 |
Correct |
415 ms |
684 KB |
Output is correct |
5 |
Correct |
376 ms |
684 KB |
Output is correct |
6 |
Correct |
270 ms |
932 KB |
Output is correct |
7 |
Correct |
311 ms |
684 KB |
Output is correct |
8 |
Correct |
1 ms |
768 KB |
Output is correct |
9 |
Correct |
3 ms |
768 KB |
Output is correct |
10 |
Correct |
0 ms |
764 KB |
Output is correct |
11 |
Correct |
253 ms |
872 KB |
Output is correct |
12 |
Correct |
343 ms |
844 KB |
Output is correct |
13 |
Correct |
551 ms |
684 KB |
Output is correct |
14 |
Correct |
466 ms |
688 KB |
Output is correct |
15 |
Correct |
421 ms |
684 KB |
Output is correct |
16 |
Correct |
287 ms |
684 KB |
Output is correct |
17 |
Correct |
355 ms |
684 KB |
Output is correct |
18 |
Correct |
252 ms |
1164 KB |
Output is correct |
19 |
Correct |
327 ms |
1028 KB |
Output is correct |
20 |
Correct |
280 ms |
684 KB |
Output is correct |
21 |
Correct |
36 ms |
768 KB |
Output is correct |
22 |
Correct |
46 ms |
1184 KB |
Output is correct |
23 |
Correct |
56 ms |
876 KB |
Output is correct |
24 |
Correct |
3 ms |
768 KB |
Output is correct |
25 |
Correct |
2 ms |
768 KB |
Output is correct |
26 |
Correct |
2 ms |
768 KB |
Output is correct |
27 |
Correct |
2 ms |
768 KB |
Output is correct |
28 |
Correct |
1 ms |
768 KB |
Output is correct |
29 |
Correct |
347 ms |
684 KB |
Output is correct |
30 |
Correct |
332 ms |
688 KB |
Output is correct |
31 |
Correct |
365 ms |
684 KB |
Output is correct |
32 |
Correct |
307 ms |
684 KB |
Output is correct |
33 |
Correct |
302 ms |
684 KB |
Output is correct |
34 |
Correct |
217 ms |
904 KB |
Output is correct |
35 |
Correct |
300 ms |
1452 KB |
Output is correct |
36 |
Correct |
293 ms |
1180 KB |
Output is correct |
37 |
Correct |
302 ms |
1168 KB |
Output is correct |
38 |
Correct |
307 ms |
1168 KB |
Output is correct |
39 |
Correct |
302 ms |
1268 KB |
Output is correct |
40 |
Correct |
293 ms |
1016 KB |
Output is correct |
41 |
Correct |
298 ms |
1024 KB |
Output is correct |
42 |
Correct |
39 ms |
936 KB |
Output is correct |
43 |
Correct |
60 ms |
876 KB |
Output is correct |
44 |
Correct |
82 ms |
932 KB |
Output is correct |
45 |
Correct |
107 ms |
904 KB |
Output is correct |
46 |
Correct |
194 ms |
868 KB |
Output is correct |
47 |
Correct |
189 ms |
896 KB |
Output is correct |
48 |
Correct |
35 ms |
1236 KB |
Output is correct |
49 |
Correct |
33 ms |
1656 KB |
Output is correct |