# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
443485 | 2021-07-10T15:10:18 Z | leinad2 | Fountain Parks (IOI21_parks) | C++17 | 684 ms | 74768 KB |
#include "parks.h" #include<bits/stdc++.h> using namespace std; int par[400010], chk[400010], chk2[400010], A[400010][2], vis[400010]; int Find(int v){return v==par[v]?v:par[v]=Find(par[v]);} vector<pair<int, int> >v; int cnt; map<pair<int, int>, int>mp; vector<pair<int, int> >adj[400010]; vector<int>_u, _v, _a, _b; void dfs(int v) { for(int i=0;i<adj[v].size();i++) { int p=adj[v][i].first; if(!vis[p])vis[p]=1,dfs(p),_a[adj[v][i].second]=p; } } int construct_roads(vector<int>x, vector<int>y) { int n, i, j, k, a, b; n=x.size(); vector<pair<pair<int, int>, int> >V; for(i=0;i<n;i++) { V.push_back({{x[i], y[i]}, i}); } sort(V.begin(), V.end()); for(i=1;i<V.size();i++) { if(V[i].first.first==V[i-1].first.first&&V[i].first.second==V[i-1].first.second+2) { v.push_back({V[i].second, V[i-1].second}); } } for(i=0;i<n;i++) { swap(V[i].first.first, V[i].first.second); } sort(V.begin(), V.end()); for(i=1;i<V.size();i++) { if(V[i].first.first==V[i-1].first.first&&V[i].first.second==V[i-1].first.second+2) { v.push_back({V[i].second, V[i-1].second}); } } for(int rng=0;rng<1;rng++) { for(i=0;i<n;i++)par[i]=i; random_shuffle(v.begin(), v.end()); _u.clear();_v.clear();_a.clear();_b.clear();cnt=0;mp.clear();for(i=1;i<=2*n;i++)vis[i]=chk[i]=chk2[i]=0,adj[i].clear(); for(i=0;i<v.size();i++) { if(Find(v[i].first)!=Find(v[i].second)) { _u.push_back(v[i].first); _v.push_back(v[i].second); par[Find(v[i].first)]=Find(v[i].second); } } if(_u.size()!=n-1)return 0; vector<pair<int, int> >edge; _a.resize(n-1);_b.resize(n-1); for(i=0;i<_u.size();i++) { int a=_u[i], b=_v[i], q, w, e, r; if(x[a]==x[b]) { q=x[a]-1;e=x[a]+1; w=r=(y[a]+y[b])/2; } else { w=y[a]-1;r=y[a]+1; q=e=(x[a]+x[b])/2; } if(mp.find({q, w})==mp.end())mp[{q, w}]=++cnt,A[cnt][0]=q,A[cnt][1]=w; if(mp.find({e, r})==mp.end())mp[{e, r}]=++cnt,A[cnt][0]=e,A[cnt][1]=r; int x=mp[{q, w}];int y=mp[{e, r}]; edge.push_back({x, y}); } for(i=0;i++<cnt;)par[i]=i; for(i=0;i<edge.size();i++)par[Find(edge[i].first)]=Find(edge[i].second); for(i=0;i++<cnt;)chk[Find(i)]++; for(i=0;i<edge.size();i++)chk2[Find(edge[i].first)]++; for(i=0;i<edge.size();i++) { adj[edge[i].first].push_back({edge[i].second, i}); adj[edge[i].second].push_back({edge[i].first, i}); } bool flag=true; for(i=0;i++<cnt;) { if(chk[i]) { if(chk[i]<chk2[i]){flag=false;break;} else vis[i]=1,dfs(i); } } if(!flag)continue; for(i=0;i<_a.size();i++) { if(_a[i]==0)_a[i]=Find(edge[i].first); int a=_a[i]; _a[i]=A[a][0];_b[i]=A[a][1]; } build(_u, _v, _a, _b); return 1; } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 9676 KB | Output is correct |
2 | Correct | 6 ms | 9676 KB | Output is correct |
3 | Correct | 6 ms | 9676 KB | Output is correct |
4 | Correct | 6 ms | 9676 KB | Output is correct |
5 | Correct | 7 ms | 9676 KB | Output is correct |
6 | Correct | 6 ms | 9664 KB | Output is correct |
7 | Correct | 7 ms | 9676 KB | Output is correct |
8 | Correct | 6 ms | 9676 KB | Output is correct |
9 | Correct | 281 ms | 42288 KB | Output is correct |
10 | Correct | 26 ms | 12944 KB | Output is correct |
11 | Correct | 117 ms | 27208 KB | Output is correct |
12 | Correct | 35 ms | 14524 KB | Output is correct |
13 | Correct | 21 ms | 13128 KB | Output is correct |
14 | Correct | 7 ms | 9676 KB | Output is correct |
15 | Correct | 7 ms | 9804 KB | Output is correct |
16 | Correct | 259 ms | 42472 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 9676 KB | Output is correct |
2 | Correct | 6 ms | 9676 KB | Output is correct |
3 | Correct | 6 ms | 9676 KB | Output is correct |
4 | Correct | 6 ms | 9676 KB | Output is correct |
5 | Correct | 7 ms | 9676 KB | Output is correct |
6 | Correct | 6 ms | 9664 KB | Output is correct |
7 | Correct | 7 ms | 9676 KB | Output is correct |
8 | Correct | 6 ms | 9676 KB | Output is correct |
9 | Correct | 281 ms | 42288 KB | Output is correct |
10 | Correct | 26 ms | 12944 KB | Output is correct |
11 | Correct | 117 ms | 27208 KB | Output is correct |
12 | Correct | 35 ms | 14524 KB | Output is correct |
13 | Correct | 21 ms | 13128 KB | Output is correct |
14 | Correct | 7 ms | 9676 KB | Output is correct |
15 | Correct | 7 ms | 9804 KB | Output is correct |
16 | Correct | 259 ms | 42472 KB | Output is correct |
17 | Correct | 6 ms | 9676 KB | Output is correct |
18 | Correct | 6 ms | 9676 KB | Output is correct |
19 | Correct | 6 ms | 9676 KB | Output is correct |
20 | Correct | 6 ms | 9676 KB | Output is correct |
21 | Correct | 6 ms | 9676 KB | Output is correct |
22 | Correct | 6 ms | 9676 KB | Output is correct |
23 | Correct | 639 ms | 59720 KB | Output is correct |
24 | Correct | 6 ms | 9676 KB | Output is correct |
25 | Correct | 8 ms | 10060 KB | Output is correct |
26 | Correct | 8 ms | 9932 KB | Output is correct |
27 | Correct | 8 ms | 10060 KB | Output is correct |
28 | Correct | 193 ms | 29816 KB | Output is correct |
29 | Correct | 328 ms | 39684 KB | Output is correct |
30 | Correct | 489 ms | 49636 KB | Output is correct |
31 | Correct | 644 ms | 59756 KB | Output is correct |
32 | Correct | 6 ms | 9676 KB | Output is correct |
33 | Correct | 6 ms | 9676 KB | Output is correct |
34 | Correct | 6 ms | 9604 KB | Output is correct |
35 | Correct | 6 ms | 9676 KB | Output is correct |
36 | Correct | 7 ms | 9608 KB | Output is correct |
37 | Correct | 6 ms | 9644 KB | Output is correct |
38 | Correct | 6 ms | 9676 KB | Output is correct |
39 | Correct | 7 ms | 9676 KB | Output is correct |
40 | Correct | 7 ms | 9676 KB | Output is correct |
41 | Correct | 6 ms | 9676 KB | Output is correct |
42 | Correct | 6 ms | 9676 KB | Output is correct |
43 | Correct | 7 ms | 9832 KB | Output is correct |
44 | Correct | 8 ms | 9932 KB | Output is correct |
45 | Correct | 260 ms | 35688 KB | Output is correct |
46 | Correct | 435 ms | 47416 KB | Output is correct |
47 | Correct | 419 ms | 47416 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 9676 KB | Output is correct |
2 | Correct | 6 ms | 9676 KB | Output is correct |
3 | Correct | 6 ms | 9676 KB | Output is correct |
4 | Correct | 6 ms | 9676 KB | Output is correct |
5 | Correct | 7 ms | 9676 KB | Output is correct |
6 | Correct | 6 ms | 9664 KB | Output is correct |
7 | Correct | 7 ms | 9676 KB | Output is correct |
8 | Correct | 6 ms | 9676 KB | Output is correct |
9 | Correct | 281 ms | 42288 KB | Output is correct |
10 | Correct | 26 ms | 12944 KB | Output is correct |
11 | Correct | 117 ms | 27208 KB | Output is correct |
12 | Correct | 35 ms | 14524 KB | Output is correct |
13 | Correct | 21 ms | 13128 KB | Output is correct |
14 | Correct | 7 ms | 9676 KB | Output is correct |
15 | Correct | 7 ms | 9804 KB | Output is correct |
16 | Correct | 259 ms | 42472 KB | Output is correct |
17 | Correct | 6 ms | 9676 KB | Output is correct |
18 | Correct | 6 ms | 9676 KB | Output is correct |
19 | Correct | 6 ms | 9676 KB | Output is correct |
20 | Correct | 6 ms | 9676 KB | Output is correct |
21 | Correct | 6 ms | 9676 KB | Output is correct |
22 | Correct | 6 ms | 9676 KB | Output is correct |
23 | Correct | 639 ms | 59720 KB | Output is correct |
24 | Correct | 6 ms | 9676 KB | Output is correct |
25 | Correct | 8 ms | 10060 KB | Output is correct |
26 | Correct | 8 ms | 9932 KB | Output is correct |
27 | Correct | 8 ms | 10060 KB | Output is correct |
28 | Correct | 193 ms | 29816 KB | Output is correct |
29 | Correct | 328 ms | 39684 KB | Output is correct |
30 | Correct | 489 ms | 49636 KB | Output is correct |
31 | Correct | 644 ms | 59756 KB | Output is correct |
32 | Correct | 6 ms | 9676 KB | Output is correct |
33 | Correct | 6 ms | 9676 KB | Output is correct |
34 | Correct | 6 ms | 9604 KB | Output is correct |
35 | Correct | 6 ms | 9676 KB | Output is correct |
36 | Correct | 7 ms | 9608 KB | Output is correct |
37 | Correct | 6 ms | 9644 KB | Output is correct |
38 | Correct | 6 ms | 9676 KB | Output is correct |
39 | Correct | 7 ms | 9676 KB | Output is correct |
40 | Correct | 7 ms | 9676 KB | Output is correct |
41 | Correct | 6 ms | 9676 KB | Output is correct |
42 | Correct | 6 ms | 9676 KB | Output is correct |
43 | Correct | 7 ms | 9832 KB | Output is correct |
44 | Correct | 8 ms | 9932 KB | Output is correct |
45 | Correct | 260 ms | 35688 KB | Output is correct |
46 | Correct | 435 ms | 47416 KB | Output is correct |
47 | Correct | 419 ms | 47416 KB | Output is correct |
48 | Correct | 6 ms | 9676 KB | Output is correct |
49 | Correct | 6 ms | 9676 KB | Output is correct |
50 | Correct | 6 ms | 9676 KB | Output is correct |
51 | Correct | 6 ms | 9676 KB | Output is correct |
52 | Correct | 8 ms | 9676 KB | Output is correct |
53 | Correct | 7 ms | 9676 KB | Output is correct |
54 | Correct | 6 ms | 9676 KB | Output is correct |
55 | Incorrect | 509 ms | 51116 KB | Solution announced impossible, but it is possible. |
56 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 9676 KB | Output is correct |
2 | Correct | 6 ms | 9676 KB | Output is correct |
3 | Correct | 6 ms | 9676 KB | Output is correct |
4 | Correct | 6 ms | 9676 KB | Output is correct |
5 | Correct | 7 ms | 9676 KB | Output is correct |
6 | Correct | 6 ms | 9664 KB | Output is correct |
7 | Correct | 7 ms | 9676 KB | Output is correct |
8 | Correct | 6 ms | 9676 KB | Output is correct |
9 | Correct | 281 ms | 42288 KB | Output is correct |
10 | Correct | 26 ms | 12944 KB | Output is correct |
11 | Correct | 117 ms | 27208 KB | Output is correct |
12 | Correct | 35 ms | 14524 KB | Output is correct |
13 | Correct | 21 ms | 13128 KB | Output is correct |
14 | Correct | 7 ms | 9676 KB | Output is correct |
15 | Correct | 7 ms | 9804 KB | Output is correct |
16 | Correct | 259 ms | 42472 KB | Output is correct |
17 | Correct | 7 ms | 9676 KB | Output is correct |
18 | Correct | 6 ms | 9676 KB | Output is correct |
19 | Correct | 6 ms | 9700 KB | Output is correct |
20 | Correct | 587 ms | 60772 KB | Output is correct |
21 | Correct | 603 ms | 58132 KB | Output is correct |
22 | Correct | 589 ms | 58056 KB | Output is correct |
23 | Correct | 506 ms | 64964 KB | Output is correct |
24 | Correct | 100 ms | 20692 KB | Output is correct |
25 | Correct | 110 ms | 25072 KB | Output is correct |
26 | Correct | 110 ms | 25080 KB | Output is correct |
27 | Correct | 624 ms | 74648 KB | Output is correct |
28 | Correct | 634 ms | 74744 KB | Output is correct |
29 | Correct | 587 ms | 74536 KB | Output is correct |
30 | Correct | 576 ms | 74524 KB | Output is correct |
31 | Correct | 6 ms | 9676 KB | Output is correct |
32 | Correct | 36 ms | 13224 KB | Output is correct |
33 | Correct | 45 ms | 15300 KB | Output is correct |
34 | Correct | 587 ms | 62968 KB | Output is correct |
35 | Correct | 11 ms | 10512 KB | Output is correct |
36 | Correct | 33 ms | 13504 KB | Output is correct |
37 | Correct | 62 ms | 17184 KB | Output is correct |
38 | Correct | 202 ms | 29040 KB | Output is correct |
39 | Correct | 286 ms | 36028 KB | Output is correct |
40 | Correct | 406 ms | 43420 KB | Output is correct |
41 | Correct | 534 ms | 50344 KB | Output is correct |
42 | Correct | 633 ms | 57460 KB | Output is correct |
43 | Correct | 6 ms | 9676 KB | Output is correct |
44 | Correct | 6 ms | 9676 KB | Output is correct |
45 | Correct | 6 ms | 9676 KB | Output is correct |
46 | Correct | 6 ms | 9676 KB | Output is correct |
47 | Correct | 6 ms | 9676 KB | Output is correct |
48 | Correct | 6 ms | 9676 KB | Output is correct |
49 | Correct | 6 ms | 9640 KB | Output is correct |
50 | Correct | 6 ms | 9676 KB | Output is correct |
51 | Correct | 7 ms | 9676 KB | Output is correct |
52 | Correct | 6 ms | 9676 KB | Output is correct |
53 | Correct | 6 ms | 9672 KB | Output is correct |
54 | Correct | 7 ms | 9804 KB | Output is correct |
55 | Correct | 8 ms | 9932 KB | Output is correct |
56 | Correct | 260 ms | 35664 KB | Output is correct |
57 | Correct | 421 ms | 47424 KB | Output is correct |
58 | Correct | 460 ms | 47380 KB | Output is correct |
59 | Correct | 6 ms | 9676 KB | Output is correct |
60 | Correct | 6 ms | 9728 KB | Output is correct |
61 | Correct | 6 ms | 9676 KB | Output is correct |
62 | Correct | 607 ms | 74628 KB | Output is correct |
63 | Correct | 599 ms | 74612 KB | Output is correct |
64 | Correct | 594 ms | 74296 KB | Output is correct |
65 | Correct | 8 ms | 9932 KB | Output is correct |
66 | Correct | 10 ms | 10284 KB | Output is correct |
67 | Correct | 256 ms | 35216 KB | Output is correct |
68 | Correct | 450 ms | 47908 KB | Output is correct |
69 | Correct | 684 ms | 60424 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 9676 KB | Output is correct |
2 | Correct | 6 ms | 9676 KB | Output is correct |
3 | Correct | 6 ms | 9676 KB | Output is correct |
4 | Correct | 6 ms | 9676 KB | Output is correct |
5 | Correct | 7 ms | 9676 KB | Output is correct |
6 | Correct | 6 ms | 9664 KB | Output is correct |
7 | Correct | 7 ms | 9676 KB | Output is correct |
8 | Correct | 6 ms | 9676 KB | Output is correct |
9 | Correct | 281 ms | 42288 KB | Output is correct |
10 | Correct | 26 ms | 12944 KB | Output is correct |
11 | Correct | 117 ms | 27208 KB | Output is correct |
12 | Correct | 35 ms | 14524 KB | Output is correct |
13 | Correct | 21 ms | 13128 KB | Output is correct |
14 | Correct | 7 ms | 9676 KB | Output is correct |
15 | Correct | 7 ms | 9804 KB | Output is correct |
16 | Correct | 259 ms | 42472 KB | Output is correct |
17 | Correct | 616 ms | 74768 KB | Output is correct |
18 | Correct | 601 ms | 74732 KB | Output is correct |
19 | Correct | 586 ms | 62920 KB | Output is correct |
20 | Correct | 625 ms | 58580 KB | Output is correct |
21 | Correct | 541 ms | 60156 KB | Output is correct |
22 | Correct | 6 ms | 9676 KB | Output is correct |
23 | Correct | 77 ms | 17784 KB | Output is correct |
24 | Correct | 18 ms | 11212 KB | Output is correct |
25 | Correct | 48 ms | 15212 KB | Output is correct |
26 | Correct | 77 ms | 18688 KB | Output is correct |
27 | Correct | 270 ms | 34548 KB | Output is correct |
28 | Correct | 356 ms | 41420 KB | Output is correct |
29 | Correct | 443 ms | 46856 KB | Output is correct |
30 | Correct | 545 ms | 52912 KB | Output is correct |
31 | Correct | 650 ms | 59116 KB | Output is correct |
32 | Correct | 647 ms | 63608 KB | Output is correct |
33 | Correct | 590 ms | 74552 KB | Output is correct |
34 | Correct | 9 ms | 10060 KB | Output is correct |
35 | Correct | 10 ms | 10384 KB | Output is correct |
36 | Correct | 257 ms | 35516 KB | Output is correct |
37 | Correct | 434 ms | 48440 KB | Output is correct |
38 | Correct | 622 ms | 61168 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 9676 KB | Output is correct |
2 | Correct | 6 ms | 9676 KB | Output is correct |
3 | Correct | 6 ms | 9676 KB | Output is correct |
4 | Correct | 6 ms | 9676 KB | Output is correct |
5 | Correct | 7 ms | 9676 KB | Output is correct |
6 | Correct | 6 ms | 9664 KB | Output is correct |
7 | Correct | 7 ms | 9676 KB | Output is correct |
8 | Correct | 6 ms | 9676 KB | Output is correct |
9 | Correct | 281 ms | 42288 KB | Output is correct |
10 | Correct | 26 ms | 12944 KB | Output is correct |
11 | Correct | 117 ms | 27208 KB | Output is correct |
12 | Correct | 35 ms | 14524 KB | Output is correct |
13 | Correct | 21 ms | 13128 KB | Output is correct |
14 | Correct | 7 ms | 9676 KB | Output is correct |
15 | Correct | 7 ms | 9804 KB | Output is correct |
16 | Correct | 259 ms | 42472 KB | Output is correct |
17 | Correct | 6 ms | 9676 KB | Output is correct |
18 | Correct | 6 ms | 9676 KB | Output is correct |
19 | Correct | 6 ms | 9676 KB | Output is correct |
20 | Correct | 6 ms | 9676 KB | Output is correct |
21 | Correct | 6 ms | 9676 KB | Output is correct |
22 | Correct | 6 ms | 9676 KB | Output is correct |
23 | Correct | 639 ms | 59720 KB | Output is correct |
24 | Correct | 6 ms | 9676 KB | Output is correct |
25 | Correct | 8 ms | 10060 KB | Output is correct |
26 | Correct | 8 ms | 9932 KB | Output is correct |
27 | Correct | 8 ms | 10060 KB | Output is correct |
28 | Correct | 193 ms | 29816 KB | Output is correct |
29 | Correct | 328 ms | 39684 KB | Output is correct |
30 | Correct | 489 ms | 49636 KB | Output is correct |
31 | Correct | 644 ms | 59756 KB | Output is correct |
32 | Correct | 6 ms | 9676 KB | Output is correct |
33 | Correct | 6 ms | 9676 KB | Output is correct |
34 | Correct | 6 ms | 9604 KB | Output is correct |
35 | Correct | 6 ms | 9676 KB | Output is correct |
36 | Correct | 7 ms | 9608 KB | Output is correct |
37 | Correct | 6 ms | 9644 KB | Output is correct |
38 | Correct | 6 ms | 9676 KB | Output is correct |
39 | Correct | 7 ms | 9676 KB | Output is correct |
40 | Correct | 7 ms | 9676 KB | Output is correct |
41 | Correct | 6 ms | 9676 KB | Output is correct |
42 | Correct | 6 ms | 9676 KB | Output is correct |
43 | Correct | 7 ms | 9832 KB | Output is correct |
44 | Correct | 8 ms | 9932 KB | Output is correct |
45 | Correct | 260 ms | 35688 KB | Output is correct |
46 | Correct | 435 ms | 47416 KB | Output is correct |
47 | Correct | 419 ms | 47416 KB | Output is correct |
48 | Correct | 6 ms | 9676 KB | Output is correct |
49 | Correct | 6 ms | 9676 KB | Output is correct |
50 | Correct | 6 ms | 9676 KB | Output is correct |
51 | Correct | 6 ms | 9676 KB | Output is correct |
52 | Correct | 8 ms | 9676 KB | Output is correct |
53 | Correct | 7 ms | 9676 KB | Output is correct |
54 | Correct | 6 ms | 9676 KB | Output is correct |
55 | Incorrect | 509 ms | 51116 KB | Solution announced impossible, but it is possible. |
56 | Halted | 0 ms | 0 KB | - |