Submission #818039

# Submission time Handle Problem Language Result Execution time Memory
818039 2023-08-10T00:21:26 Z alvingogo Fountain Parks (IOI21_parks) C++17
30 / 100
834 ms 43220 KB
#include "parks.h"
#include <bits/stdc++.h>
#define fs first
#define sc second
#define p_q priority_queue
using namespace std;
struct DSU{
    vector<int> bo,ss;
    void init(int x){
        bo.resize(x);
        ss.resize(x,1);
        iota(bo.begin(),bo.end(),0);
    }  
    int find(int x){
        return bo[x]==x?x:bo[x]=find(bo[x]);
    }
    int merge(int x,int y){
        x=find(x);
        y=find(y);
        if(x==y){
            return 0;
        }
        bo[x]=y;
        ss[y]+=ss[x];
        return 1;
    }
}dsu;

vector<int> au,av,aa,ab;
set<pair<int,int> > vis;
void ag(int a,int b,int c,int d){
    au.push_back(a);
    av.push_back(b);
    dsu.merge(a,b);
    aa.push_back(c);
    ab.push_back(d);
    vis.insert({c,d});
}
int construct_roads(vector<int> x, vector<int> y) {
    vis.clear();
    if (x.size() == 1) {
	    build({}, {}, {}, {});
        return 1;
    }
    map<pair<int,int>,int> mp;
    int n=x.size();
    for(int i=0;i<n;i++){
        mp[{x[i],y[i]}]=i;
    }
    dsu.init(n);
    const int dx[4]={0,0,2,-2},dy[4]={2,-2,0,0};
    function<void(pair<int,int>,int)> dfs=[&](pair<int,int> w,int q){
        int a=0,b=0,c=0,d=0;
        if(dx[q]){
            a=b=dx[q]/2;
            c=1;
            d=-1;
        }
        else{
            a=1;
            b=-1;
            c=d=dy[q]/2;
        }
        int e=0,f=0,g=0,h=0;
        int way=2*(1-q/2);
        if(mp.find({w.fs+a,w.sc+c})==mp.end()){
            if(mp.find({w.fs+b,w.sc+d})==mp.end()){
                return;
            }
            way++;
        }
        if(dx[way]){
            e=f=dx[way]/2;
            g=1;
            h=-1;
        }
        else{
            e=1;
            f=-1;
            g=h=dy[way]/2;
        }
        for(int i=w.fs,j=w.sc;;i+=dx[way],j+=dy[way]){
            int sx=i+e,sy=j+g,tx=i+f,ty=j+h;
            if(mp.find({sx,sy})==mp.end() || mp.find({tx,ty})==mp.end()){
                if(vis.find({i,j})!=vis.end()){
                    break;
                }
                if(way<2){
                    ag(mp[{sx-dx[way],sy-dy[way]}],mp[{tx-dx[way],ty-dy[way]}],i,j);
                }
                dfs({i,j},way);
                break;
            }
            else{
                if(way>=2){
                    if(vis.find({i+dx[way],j+dy[way]})!=vis.end()){
                        break;
                    }
                    ag(mp[{sx,sy}],mp[{tx,ty}],i+dx[way],j+dy[way]);
                }
            }
        }
    };
    for(int p=0;p<n;p++){
        int c=x[p]+2,d=y[p];
        if(mp.find({c,d})!=mp.end()){
            int a=mp[{c,d}];
            if(vis.find({x[p]+1,y[p]+1})==vis.end() && !(mp.find({x[p]+2,y[p]+2})!=mp.end() && mp.find({x[p],y[p]+2})!=mp.end())){
                ag(a,p,x[p]+1,y[p]+1);
                dfs({x[p]+1,y[p]+1},0);
            }
            else if(vis.find({x[p]+1,y[p]-1})==vis.end() && !(mp.find({x[p]+2,y[p]-2})!=mp.end() && mp.find({x[p],y[p]-2})!=mp.end())){
                ag(a,p,x[p]+1,y[p]-1);
                dfs({x[p]+1,y[p]-1},1);
            }
        }
    }
    for(int p=0;p<n;p++){
        int c=x[p],d=y[p]+2;
        if(mp.find({c,d})!=mp.end()){
            int a=mp[{c,d}];
            if(vis.find({x[p]+1,y[p]+1})==vis.end()){
                ag(a,p,x[p]+1,y[p]+1);
            }
            else if(vis.find({x[p]-1,y[p]+1})==vis.end()){
                ag(a,p,x[p]-1,y[p]+1);
            }
        }
    }
    if(dsu.ss[dsu.find(0)]!=n){
        return 0;
    }
    build(au,av,aa,ab);
    return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 296 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 156 ms 19120 KB Output is correct
10 Correct 10 ms 2388 KB Output is correct
11 Correct 57 ms 10436 KB Output is correct
12 Correct 14 ms 3324 KB Output is correct
13 Correct 33 ms 7236 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 584 KB Output is correct
16 Correct 151 ms 19076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 296 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 156 ms 19120 KB Output is correct
10 Correct 10 ms 2388 KB Output is correct
11 Correct 57 ms 10436 KB Output is correct
12 Correct 14 ms 3324 KB Output is correct
13 Correct 33 ms 7236 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 584 KB Output is correct
16 Correct 151 ms 19076 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 304 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 579 ms 38076 KB Output is correct
24 Correct 1 ms 300 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 3 ms 724 KB Output is correct
27 Correct 5 ms 852 KB Output is correct
28 Correct 142 ms 15332 KB Output is correct
29 Correct 241 ms 22924 KB Output is correct
30 Correct 364 ms 30412 KB Output is correct
31 Correct 565 ms 37904 KB Output is correct
32 Correct 1 ms 300 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 284 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 0 ms 300 KB Output is correct
42 Correct 0 ms 304 KB Output is correct
43 Correct 2 ms 596 KB Output is correct
44 Correct 4 ms 724 KB Output is correct
45 Correct 214 ms 19112 KB Output is correct
46 Correct 345 ms 27576 KB Output is correct
47 Correct 397 ms 27608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 296 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 156 ms 19120 KB Output is correct
10 Correct 10 ms 2388 KB Output is correct
11 Correct 57 ms 10436 KB Output is correct
12 Correct 14 ms 3324 KB Output is correct
13 Correct 33 ms 7236 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 584 KB Output is correct
16 Correct 151 ms 19076 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 304 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 579 ms 38076 KB Output is correct
24 Correct 1 ms 300 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 3 ms 724 KB Output is correct
27 Correct 5 ms 852 KB Output is correct
28 Correct 142 ms 15332 KB Output is correct
29 Correct 241 ms 22924 KB Output is correct
30 Correct 364 ms 30412 KB Output is correct
31 Correct 565 ms 37904 KB Output is correct
32 Correct 1 ms 300 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 284 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 0 ms 300 KB Output is correct
42 Correct 0 ms 304 KB Output is correct
43 Correct 2 ms 596 KB Output is correct
44 Correct 4 ms 724 KB Output is correct
45 Correct 214 ms 19112 KB Output is correct
46 Correct 345 ms 27576 KB Output is correct
47 Correct 397 ms 27608 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 0 ms 340 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 0 ms 300 KB Output is correct
52 Correct 0 ms 212 KB Output is correct
53 Correct 1 ms 300 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 627 ms 37892 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
57 Correct 2 ms 596 KB Output is correct
58 Correct 9 ms 1556 KB Output is correct
59 Correct 13 ms 1804 KB Output is correct
60 Correct 209 ms 18988 KB Output is correct
61 Correct 315 ms 25592 KB Output is correct
62 Correct 393 ms 31368 KB Output is correct
63 Correct 520 ms 37952 KB Output is correct
64 Correct 0 ms 212 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 0 ms 212 KB Output is correct
67 Correct 387 ms 37980 KB Output is correct
68 Correct 391 ms 37984 KB Output is correct
69 Correct 406 ms 37692 KB Output is correct
70 Correct 5 ms 820 KB Output is correct
71 Correct 10 ms 1492 KB Output is correct
72 Correct 224 ms 19008 KB Output is correct
73 Correct 436 ms 28560 KB Output is correct
74 Correct 626 ms 37892 KB Output is correct
75 Correct 620 ms 41632 KB Output is correct
76 Correct 388 ms 37916 KB Output is correct
77 Correct 6 ms 1108 KB Output is correct
78 Correct 14 ms 1780 KB Output is correct
79 Correct 254 ms 19980 KB Output is correct
80 Correct 462 ms 30148 KB Output is correct
81 Correct 673 ms 40096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 296 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 156 ms 19120 KB Output is correct
10 Correct 10 ms 2388 KB Output is correct
11 Correct 57 ms 10436 KB Output is correct
12 Correct 14 ms 3324 KB Output is correct
13 Correct 33 ms 7236 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 584 KB Output is correct
16 Correct 151 ms 19076 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 597 ms 39352 KB Output is correct
21 Correct 639 ms 38808 KB Output is correct
22 Correct 636 ms 38872 KB Output is correct
23 Correct 369 ms 32140 KB Output is correct
24 Correct 196 ms 19220 KB Output is correct
25 Correct 616 ms 31656 KB Output is correct
26 Correct 380 ms 31640 KB Output is correct
27 Correct 424 ms 37860 KB Output is correct
28 Correct 418 ms 37868 KB Output is correct
29 Correct 568 ms 37920 KB Output is correct
30 Correct 592 ms 37836 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Incorrect 23 ms 2516 KB Solution announced impossible, but it is possible.
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 296 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 156 ms 19120 KB Output is correct
10 Correct 10 ms 2388 KB Output is correct
11 Correct 57 ms 10436 KB Output is correct
12 Correct 14 ms 3324 KB Output is correct
13 Correct 33 ms 7236 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 584 KB Output is correct
16 Correct 151 ms 19076 KB Output is correct
17 Correct 441 ms 38356 KB Output is correct
18 Correct 451 ms 38592 KB Output is correct
19 Correct 624 ms 38832 KB Output is correct
20 Correct 834 ms 43220 KB Output is correct
21 Correct 559 ms 35388 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Incorrect 60 ms 5588 KB Solution announced impossible, but it is possible.
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 296 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 156 ms 19120 KB Output is correct
10 Correct 10 ms 2388 KB Output is correct
11 Correct 57 ms 10436 KB Output is correct
12 Correct 14 ms 3324 KB Output is correct
13 Correct 33 ms 7236 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 584 KB Output is correct
16 Correct 151 ms 19076 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 304 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 579 ms 38076 KB Output is correct
24 Correct 1 ms 300 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 3 ms 724 KB Output is correct
27 Correct 5 ms 852 KB Output is correct
28 Correct 142 ms 15332 KB Output is correct
29 Correct 241 ms 22924 KB Output is correct
30 Correct 364 ms 30412 KB Output is correct
31 Correct 565 ms 37904 KB Output is correct
32 Correct 1 ms 300 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 284 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 0 ms 212 KB Output is correct
41 Correct 0 ms 300 KB Output is correct
42 Correct 0 ms 304 KB Output is correct
43 Correct 2 ms 596 KB Output is correct
44 Correct 4 ms 724 KB Output is correct
45 Correct 214 ms 19112 KB Output is correct
46 Correct 345 ms 27576 KB Output is correct
47 Correct 397 ms 27608 KB Output is correct
48 Correct 1 ms 212 KB Output is correct
49 Correct 0 ms 340 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 0 ms 300 KB Output is correct
52 Correct 0 ms 212 KB Output is correct
53 Correct 1 ms 300 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 627 ms 37892 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
57 Correct 2 ms 596 KB Output is correct
58 Correct 9 ms 1556 KB Output is correct
59 Correct 13 ms 1804 KB Output is correct
60 Correct 209 ms 18988 KB Output is correct
61 Correct 315 ms 25592 KB Output is correct
62 Correct 393 ms 31368 KB Output is correct
63 Correct 520 ms 37952 KB Output is correct
64 Correct 0 ms 212 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Correct 0 ms 212 KB Output is correct
67 Correct 387 ms 37980 KB Output is correct
68 Correct 391 ms 37984 KB Output is correct
69 Correct 406 ms 37692 KB Output is correct
70 Correct 5 ms 820 KB Output is correct
71 Correct 10 ms 1492 KB Output is correct
72 Correct 224 ms 19008 KB Output is correct
73 Correct 436 ms 28560 KB Output is correct
74 Correct 626 ms 37892 KB Output is correct
75 Correct 620 ms 41632 KB Output is correct
76 Correct 388 ms 37916 KB Output is correct
77 Correct 6 ms 1108 KB Output is correct
78 Correct 14 ms 1780 KB Output is correct
79 Correct 254 ms 19980 KB Output is correct
80 Correct 462 ms 30148 KB Output is correct
81 Correct 673 ms 40096 KB Output is correct
82 Correct 1 ms 212 KB Output is correct
83 Correct 0 ms 212 KB Output is correct
84 Correct 1 ms 212 KB Output is correct
85 Correct 597 ms 39352 KB Output is correct
86 Correct 639 ms 38808 KB Output is correct
87 Correct 636 ms 38872 KB Output is correct
88 Correct 369 ms 32140 KB Output is correct
89 Correct 196 ms 19220 KB Output is correct
90 Correct 616 ms 31656 KB Output is correct
91 Correct 380 ms 31640 KB Output is correct
92 Correct 424 ms 37860 KB Output is correct
93 Correct 418 ms 37868 KB Output is correct
94 Correct 568 ms 37920 KB Output is correct
95 Correct 592 ms 37836 KB Output is correct
96 Correct 0 ms 212 KB Output is correct
97 Incorrect 23 ms 2516 KB Solution announced impossible, but it is possible.
98 Halted 0 ms 0 KB -