Submission #602387

# Submission time Handle Problem Language Result Execution time Memory
602387 2022-07-23T03:08:00 Z rrrr10000 Fountain Parks (IOI21_parks) C++17
30 / 100
650 ms 54768 KB
#include "parks.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<P> vp;
typedef vector<vp> vvp;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP(i,k,n) for(ll i=(ll)(k);i<(ll)(n);i++)
#define fi first
#define se second
#define pb emplace_back
#define all(a) a.begin(),a.end()
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<endl;}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
vi dx={2,0,-2,0},dy={0,2,0,-2};
ll mx=200005;
int construct_roads(std::vector<int> X, std::vector<int> Y) {
    if (X.size() == 1) {
	    build({}, {}, {}, {});
        return 1;
    }
    ll n=X.size();
    map<P,ll> mp;
    rep(i,n)mp[P(X[i],Y[i])]=i;
    vp edge;
    rep(i,n)rep(j,2){
        ll nx=X[i]+dx[j],ny=Y[i]+dy[j];
        if(mp.count(P(nx,ny)))edge.pb(i,mp[P(nx,ny)]);
    }
    {
        vvi g(n);
        for(auto x:edge){
            g[x.fi].pb(x.se);
            g[x.se].pb(x.fi);
        }
        queue<ll> que;
        vb done(n,false);
        done[0]=true;
        que.push(0);
        while(!que.empty()){
            ll t=que.front();que.pop();
            for(ll x:g[t])if(!done[x]){
                done[x]=true;que.push(x);
            }
        }
        rep(i,n)if(!done[i])return 0;
    }
    vvp al(mx);
    rep(i,n)al[Y[i]].pb(X[i],i);
    rep(i,mx)sort(all(al[i]));
    vector<int> u, v, a, b;
    auto add=[&](ll i,ll j,ll t){
        u.pb(i);v.pb(j);
        if(t==0||t==1){
            assert(Y[i]==Y[j]);
            a.pb((X[i]+X[j])/2);
            if(t==0)b.pb(Y[i]-1);
            else b.pb(Y[i]+1);
        }
        else{
            assert(X[i]==X[j]);
            b.pb((Y[i]+Y[j])/2);
            if(t==2)a.pb(X[i]-1);
            else a.pb(X[i]+1);
        }
    };
    bool small=true;
    rep(i,n)if(X[i]>6)small=false;
    if(small){
        vb tmp(2,false);
        rep(i,mx)if(al[i].size()){
            vb ntmp(2,false);
            if(!al[i-2].size()){
                rep(j,al[i].size()-1)if(al[i][j+1].fi-al[i][j].fi==2)add(al[i][j].se,al[i][j+1].se,0);
            }
            else{
                if(al[i].back().fi==6&&al[i-2].back().fi==6)add(al[i].back().se,al[i-2].back().se,3);
                if(al[i][0].fi==2&&al[i-2][0].fi==2)add(al[i][0].se,al[i-2][0].se,2);
                if(al[i][0].fi==4&&al[i-2].back().fi==4){
                    add(al[i][0].se,al[i-2].back().se,3);
                    if(al[i].size()>1){
                        add(al[i][0].se,al[i][1].se,1);
                        ntmp[1]=true;
                    }
                }
                else if(al[i].back().fi==4&&al[i-2][0].fi==4){
                    add(al[i].back().se,al[i-2][0].se,2);
                    if(al[i].size()>1){
                        add(al[i][0].se,al[i][1].se,1);
                        ntmp[0]=true;
                    }
                }
                else if(al[i-2].size()==3&&al[i].size()==1&&al[i][0].fi==4){
                    if(tmp[1])add(al[i-2][1].se,al[i][0].se,2);
                    else add(al[i-2][1].se,al[i][0].se,3);
                }
                else if(al[i-2].size()==1&&al[i-2][0].fi==4&&al[i].size()==3){
                    add(al[i-2][0].se,al[i][1].se,3);
                    add(al[i][0].se,al[i][1].se,0);
                    add(al[i][1].se,al[i][2].se,1);
                    ntmp[1]=true;
                }
                else{
                    rep(j,al[i].size()-1)if(al[i][j+1].fi-al[i][j].fi==2){
                        ll t=al[i][j].fi/2-1;
                        if(tmp[t]){
                            ntmp[t]=true;add(al[i][j].se,al[i][j+1].se,1);
                        }
                        else add(al[i][j].se,al[i][j+1].se,0);
                    }
                }
            }
            tmp=ntmp;
        }
        build(u, v, a, b);
        return 1;
    }
}

Compilation message

parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:30:15: warning: control reaches end of non-void function [-Wreturn-type]
   30 |     map<P,ll> mp;
      |               ^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4912 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 177 ms 22932 KB Output is correct
10 Correct 15 ms 6876 KB Output is correct
11 Correct 69 ms 14512 KB Output is correct
12 Correct 21 ms 7660 KB Output is correct
13 Correct 37 ms 7084 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 2 ms 568 KB Output is correct
16 Correct 167 ms 22708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4912 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 177 ms 22932 KB Output is correct
10 Correct 15 ms 6876 KB Output is correct
11 Correct 69 ms 14512 KB Output is correct
12 Correct 21 ms 7660 KB Output is correct
13 Correct 37 ms 7084 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 2 ms 568 KB Output is correct
16 Correct 167 ms 22708 KB Output is correct
17 Correct 5 ms 4948 KB Output is correct
18 Correct 4 ms 4912 KB Output is correct
19 Correct 4 ms 4948 KB Output is correct
20 Correct 3 ms 4900 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 4 ms 4948 KB Output is correct
23 Correct 579 ms 44012 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 5 ms 5204 KB Output is correct
26 Correct 3 ms 852 KB Output is correct
27 Correct 4 ms 1076 KB Output is correct
28 Correct 153 ms 20472 KB Output is correct
29 Correct 272 ms 27876 KB Output is correct
30 Correct 420 ms 36672 KB Output is correct
31 Correct 610 ms 43912 KB Output is correct
32 Correct 3 ms 4948 KB Output is correct
33 Correct 4 ms 4948 KB Output is correct
34 Correct 3 ms 4948 KB Output is correct
35 Correct 1 ms 296 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 3 ms 4948 KB Output is correct
38 Correct 3 ms 4948 KB Output is correct
39 Correct 3 ms 4948 KB Output is correct
40 Correct 3 ms 4948 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 3 ms 4908 KB Output is correct
43 Correct 2 ms 596 KB Output is correct
44 Correct 3 ms 700 KB Output is correct
45 Correct 201 ms 23460 KB Output is correct
46 Correct 334 ms 31212 KB Output is correct
47 Correct 336 ms 32104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4912 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 177 ms 22932 KB Output is correct
10 Correct 15 ms 6876 KB Output is correct
11 Correct 69 ms 14512 KB Output is correct
12 Correct 21 ms 7660 KB Output is correct
13 Correct 37 ms 7084 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 2 ms 568 KB Output is correct
16 Correct 167 ms 22708 KB Output is correct
17 Correct 5 ms 4948 KB Output is correct
18 Correct 4 ms 4912 KB Output is correct
19 Correct 4 ms 4948 KB Output is correct
20 Correct 3 ms 4900 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 4 ms 4948 KB Output is correct
23 Correct 579 ms 44012 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 5 ms 5204 KB Output is correct
26 Correct 3 ms 852 KB Output is correct
27 Correct 4 ms 1076 KB Output is correct
28 Correct 153 ms 20472 KB Output is correct
29 Correct 272 ms 27876 KB Output is correct
30 Correct 420 ms 36672 KB Output is correct
31 Correct 610 ms 43912 KB Output is correct
32 Correct 3 ms 4948 KB Output is correct
33 Correct 4 ms 4948 KB Output is correct
34 Correct 3 ms 4948 KB Output is correct
35 Correct 1 ms 296 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 3 ms 4948 KB Output is correct
38 Correct 3 ms 4948 KB Output is correct
39 Correct 3 ms 4948 KB Output is correct
40 Correct 3 ms 4948 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 3 ms 4908 KB Output is correct
43 Correct 2 ms 596 KB Output is correct
44 Correct 3 ms 700 KB Output is correct
45 Correct 201 ms 23460 KB Output is correct
46 Correct 334 ms 31212 KB Output is correct
47 Correct 336 ms 32104 KB Output is correct
48 Correct 3 ms 4892 KB Output is correct
49 Correct 3 ms 4948 KB Output is correct
50 Correct 3 ms 4948 KB Output is correct
51 Correct 3 ms 4948 KB Output is correct
52 Correct 3 ms 4948 KB Output is correct
53 Correct 3 ms 4912 KB Output is correct
54 Correct 3 ms 4948 KB Output is correct
55 Correct 631 ms 51540 KB Output is correct
56 Correct 3 ms 4948 KB Output is correct
57 Correct 6 ms 5332 KB Output is correct
58 Correct 12 ms 6312 KB Output is correct
59 Correct 10 ms 2132 KB Output is correct
60 Correct 204 ms 27140 KB Output is correct
61 Correct 325 ms 34620 KB Output is correct
62 Correct 478 ms 41384 KB Output is correct
63 Correct 650 ms 50648 KB Output is correct
64 Correct 1 ms 212 KB Output is correct
65 Correct 3 ms 4948 KB Output is correct
66 Correct 1 ms 212 KB Output is correct
67 Correct 467 ms 41692 KB Output is correct
68 Correct 489 ms 41824 KB Output is correct
69 Correct 441 ms 41520 KB Output is correct
70 Correct 3 ms 852 KB Output is correct
71 Correct 8 ms 1492 KB Output is correct
72 Correct 208 ms 23200 KB Output is correct
73 Correct 349 ms 33008 KB Output is correct
74 Correct 493 ms 41644 KB Output is correct
75 Correct 548 ms 45136 KB Output is correct
76 Correct 513 ms 41748 KB Output is correct
77 Correct 4 ms 1108 KB Output is correct
78 Correct 8 ms 1684 KB Output is correct
79 Correct 211 ms 24172 KB Output is correct
80 Correct 325 ms 33892 KB Output is correct
81 Correct 531 ms 43032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4912 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 177 ms 22932 KB Output is correct
10 Correct 15 ms 6876 KB Output is correct
11 Correct 69 ms 14512 KB Output is correct
12 Correct 21 ms 7660 KB Output is correct
13 Correct 37 ms 7084 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 2 ms 568 KB Output is correct
16 Correct 167 ms 22708 KB Output is correct
17 Runtime error 4 ms 4904 KB Execution killed with signal 6
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4912 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 177 ms 22932 KB Output is correct
10 Correct 15 ms 6876 KB Output is correct
11 Correct 69 ms 14512 KB Output is correct
12 Correct 21 ms 7660 KB Output is correct
13 Correct 37 ms 7084 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 2 ms 568 KB Output is correct
16 Correct 167 ms 22708 KB Output is correct
17 Runtime error 418 ms 54768 KB Execution killed with signal 6
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 3 ms 4912 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 177 ms 22932 KB Output is correct
10 Correct 15 ms 6876 KB Output is correct
11 Correct 69 ms 14512 KB Output is correct
12 Correct 21 ms 7660 KB Output is correct
13 Correct 37 ms 7084 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 2 ms 568 KB Output is correct
16 Correct 167 ms 22708 KB Output is correct
17 Correct 5 ms 4948 KB Output is correct
18 Correct 4 ms 4912 KB Output is correct
19 Correct 4 ms 4948 KB Output is correct
20 Correct 3 ms 4900 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 4 ms 4948 KB Output is correct
23 Correct 579 ms 44012 KB Output is correct
24 Correct 3 ms 4948 KB Output is correct
25 Correct 5 ms 5204 KB Output is correct
26 Correct 3 ms 852 KB Output is correct
27 Correct 4 ms 1076 KB Output is correct
28 Correct 153 ms 20472 KB Output is correct
29 Correct 272 ms 27876 KB Output is correct
30 Correct 420 ms 36672 KB Output is correct
31 Correct 610 ms 43912 KB Output is correct
32 Correct 3 ms 4948 KB Output is correct
33 Correct 4 ms 4948 KB Output is correct
34 Correct 3 ms 4948 KB Output is correct
35 Correct 1 ms 296 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 3 ms 4948 KB Output is correct
38 Correct 3 ms 4948 KB Output is correct
39 Correct 3 ms 4948 KB Output is correct
40 Correct 3 ms 4948 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 3 ms 4908 KB Output is correct
43 Correct 2 ms 596 KB Output is correct
44 Correct 3 ms 700 KB Output is correct
45 Correct 201 ms 23460 KB Output is correct
46 Correct 334 ms 31212 KB Output is correct
47 Correct 336 ms 32104 KB Output is correct
48 Correct 3 ms 4892 KB Output is correct
49 Correct 3 ms 4948 KB Output is correct
50 Correct 3 ms 4948 KB Output is correct
51 Correct 3 ms 4948 KB Output is correct
52 Correct 3 ms 4948 KB Output is correct
53 Correct 3 ms 4912 KB Output is correct
54 Correct 3 ms 4948 KB Output is correct
55 Correct 631 ms 51540 KB Output is correct
56 Correct 3 ms 4948 KB Output is correct
57 Correct 6 ms 5332 KB Output is correct
58 Correct 12 ms 6312 KB Output is correct
59 Correct 10 ms 2132 KB Output is correct
60 Correct 204 ms 27140 KB Output is correct
61 Correct 325 ms 34620 KB Output is correct
62 Correct 478 ms 41384 KB Output is correct
63 Correct 650 ms 50648 KB Output is correct
64 Correct 1 ms 212 KB Output is correct
65 Correct 3 ms 4948 KB Output is correct
66 Correct 1 ms 212 KB Output is correct
67 Correct 467 ms 41692 KB Output is correct
68 Correct 489 ms 41824 KB Output is correct
69 Correct 441 ms 41520 KB Output is correct
70 Correct 3 ms 852 KB Output is correct
71 Correct 8 ms 1492 KB Output is correct
72 Correct 208 ms 23200 KB Output is correct
73 Correct 349 ms 33008 KB Output is correct
74 Correct 493 ms 41644 KB Output is correct
75 Correct 548 ms 45136 KB Output is correct
76 Correct 513 ms 41748 KB Output is correct
77 Correct 4 ms 1108 KB Output is correct
78 Correct 8 ms 1684 KB Output is correct
79 Correct 211 ms 24172 KB Output is correct
80 Correct 325 ms 33892 KB Output is correct
81 Correct 531 ms 43032 KB Output is correct
82 Runtime error 4 ms 4904 KB Execution killed with signal 6
83 Halted 0 ms 0 KB -