답안 #812335

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
812335 2023-08-07T08:25:20 Z penguinman 분수 공원 (IOI21_parks) C++17
30 / 100
1511 ms 123228 KB
#include "parks.h"

#include <bits/stdc++.h>

using std::cin;
using std::cout;
using std::vector;
using std::string;
using ll = int;
using vi = vector<ll>;
using vii = vector<vi>;
using pii = std::pair<ll,ll>;
using std::endl;

#define rep(i,j,k) for(ll i=ll(j); i<ll(k); i++)
#define REP(i,j,k) for(ll i=ll(j); i<=ll(k); i++)
#define per(i,j,k) for(ll i=ll(j); i>=ll(k); i--)
#define ln "\n"
#define pb emplace_back
#define mp std::make_pair
#define all(a) a.begin(),a.end()

int construct_roads(std::vector<int> x, std::vector<int> y) {
    std::map<pii,ll> xy;
    std::map<pii,ll> rev;
    rep(i,0,x.size()) xy[mp(x[i],y[i])] = i;
    ll cnt__ = 0;
    rep(i,0,x.size()){
        vi P = {2,0}, Q = {0,2};
        vi R = {0,1}, S = {1,0};
        rep(j,0,2){
            if(xy.count(mp(x[i]+P[j], y[i]+Q[j]))){
                ll mx = x[i]+P[j]/2;
                ll my = y[i]+Q[j]/2;
                rev[mp(mx+R[j], my+S[j])] = rev[mp(mx-R[j],my-S[j])] = 0;
                cnt__++;
            }
        }
    }
    if(cnt__ != ll(x.size()-1)){
        vector<std::map<ll,ll>> X(7);
        rep(i,0,x.size()){
            X[x[i]][y[i]] = i;
        }
        vi u,v,a,b;
        vi par(x.size());
        rep(i,0,x.size()) par[i] = i;
        std::function<ll(ll)> root = [&](ll now){
            if(par[now] == now) return now;
            return par[now] = root(par[now]);
        };
        for(auto el: X[2]){
            if(X[2].count(el.first+2)){
                u.pb(el.second);
                ll next = X[2][el.first+2];
                v.pb(next);
                a.pb(1);
                b.pb(el.first+1);
                par[root(el.second)] = root(next);
            }
        }
        for(auto el: X[6]){
            if(X[6].count(el.first+2)){
                u.pb(el.second);
                ll next = X[6][el.first+2];
                v.pb(next);
                a.pb(7);
                b.pb(el.first+1);
                par[root(el.second)] = root(next);
            }
        }
        std::set<pii> used;
        for(auto el: X[4]){
            if(X[4].count(el.first+2)){
                ll next = X[4][el.first+2];
                par[root(next)] = root(el.second);
                ll rx = -1, ry = -1;
                if(el.first%4 == 0) rx = 3, ry = el.first+1;
                if(el.first%4 == 2) rx = 5, ry = el.first+1;
                used.insert(mp(rx, ry));
                u.pb(el.second);
                v.pb(next);
                a.pb(rx);
                b.pb(ry);
            }
        }
        for(auto el: X[4]){
            if(X[2].count(el.first)){
                ll next = X[2][el.first];
                if(root(next) != root(el.second)){
                    par[root(next)] = root(el.second);
                    u.pb(el.second);
                    v.pb(next);
                    ll rx = -1, ry = -1;
                    if(!used.count(mp(3,el.first-1))) rx = 3, ry = el.first-1;
                    if(!used.count(mp(3,el.first+1))) rx = 3, ry = el.first+1;
                    assert(rx != -1);
                    a.pb(rx);
                    b.pb(ry);
                    used.insert(mp(rx, ry));
                }
            }
            if(X[6].count(el.first)){
                ll next = X[6][el.first];
                if(root(next) != root(el.second)){
                    par[root(next)] = root(el.second);
                    u.pb(el.second);
                    v.pb(next);
                    ll rx = -1, ry = -1;
                    if(!used.count(mp(5,el.first-1))) rx = 5, ry = el.first-1;
                    if(!used.count(mp(5,el.first+1))) rx = 5, ry = el.first+1;
                    assert(rx != -1);
                    a.pb(rx);
                    b.pb(ry);
                    used.insert(mp(rx, ry));
                }
            }
        }
        if(u.size()+1 == x.size()){
            build(u,v,a,b);
            return 1;
        }
        else return 0;
    }
    ll N = 0;
    vi rx, ry;
    for(auto &el: rev){
        el.second = N++;
        rx.pb(el.first.first);
        ry.pb(el.first.second);
    }
    vii edge(N);
    vii eu(N), ev(N);
    rep(i,0,x.size()){
        vi P = {2,0}, Q = {0,2};
        vi R = {0,1}, S = {1,0};
        rep(j,0,2){
            if(xy.count(mp(x[i]+P[j], y[i]+Q[j]))){
                ll mx = x[i]+P[j]/2;
                ll my = y[i]+Q[j]/2;
                ll nu = rev[mp(mx+R[j], my+S[j])];
                ll nv = rev[mp(mx-R[j],my-S[j])];
                ll nxy = xy[mp(x[i]+P[j], y[i]+Q[j])];
                edge[nu].pb(nv);
                eu[nu].pb(i);
                ev[nu].pb(nxy);
                edge[nv].pb(nu);
                eu[nv].pb(i);
                ev[nv].pb(nxy);
            }
        }
    }
    vi cnt(N);
    rep(i,0,N) cnt[i] = edge[i].size();
    vi u,v,a,b;
    rep(k,0,N){
        if(cnt[k] != 1) continue;
        cnt[k]--;
        ll now = k;
        while(true){
            ll nex = -1;
            rep(i,0,edge[now].size()){
                ll next = edge[now][i];
                if(cnt[next] == 0) continue;
                u.pb(eu[now][i]);
                v.pb(ev[now][i]);
                a.pb(rx[now]);
                b.pb(ry[now]);
                cnt[next]--;
                if(cnt[next] == 1){
                    cnt[next]--;
                    nex = next;
                }
            }
            if(nex == -1) break;
            now = nex;
        }
    }
    rep(i,0,N){
        if(cnt[i] > 2) return 0;
    }
    rep(i,0,N){
        assert(cnt[i] == 0 || cnt[i] == 2);
        if(cnt[i] == 0) continue;
        cnt[i] = 0;
        ll now = i;
        while(true){
            ll val = -1;
            rep(j,0,edge[now].size()){
                ll next = edge[now][j];
                if(cnt[next] == 0) continue;
                u.pb(eu[now][j]);
                v.pb(ev[now][j]);
                a.pb(rx[now]);
                b.pb(ry[now]);
                val = cnt[next];
                cnt[next] = 0;
                now = next;
                break;
            }
            if(val == -1) break;
        }
        rep(j,0,edge[now].size()){
            ll next = edge[now][j];
            if(next != i) continue;
            u.pb(eu[now][j]);
            v.pb(ev[now][j]);
            a.pb(rx[now]);
            b.pb(ry[now]);
        }
    }
    build(u,v,a,b);
    return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 300 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 780 ms 61740 KB Output is correct
10 Correct 19 ms 6436 KB Output is correct
11 Correct 142 ms 33328 KB Output is correct
12 Correct 31 ms 9428 KB Output is correct
13 Correct 56 ms 12780 KB Output is correct
14 Correct 2 ms 596 KB Output is correct
15 Correct 3 ms 876 KB Output is correct
16 Correct 632 ms 61760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 300 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 780 ms 61740 KB Output is correct
10 Correct 19 ms 6436 KB Output is correct
11 Correct 142 ms 33328 KB Output is correct
12 Correct 31 ms 9428 KB Output is correct
13 Correct 56 ms 12780 KB Output is correct
14 Correct 2 ms 596 KB Output is correct
15 Correct 3 ms 876 KB Output is correct
16 Correct 632 ms 61760 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 805 ms 65280 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 2 ms 596 KB Output is correct
26 Correct 4 ms 1064 KB Output is correct
27 Correct 6 ms 1384 KB Output is correct
28 Correct 205 ms 26268 KB Output is correct
29 Correct 417 ms 39404 KB Output is correct
30 Correct 570 ms 52392 KB Output is correct
31 Correct 747 ms 65620 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 1 ms 328 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 0 ms 300 KB Output is correct
43 Correct 3 ms 824 KB Output is correct
44 Correct 4 ms 1108 KB Output is correct
45 Correct 505 ms 46880 KB Output is correct
46 Correct 831 ms 68440 KB Output is correct
47 Correct 825 ms 68396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 300 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 780 ms 61740 KB Output is correct
10 Correct 19 ms 6436 KB Output is correct
11 Correct 142 ms 33328 KB Output is correct
12 Correct 31 ms 9428 KB Output is correct
13 Correct 56 ms 12780 KB Output is correct
14 Correct 2 ms 596 KB Output is correct
15 Correct 3 ms 876 KB Output is correct
16 Correct 632 ms 61760 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 805 ms 65280 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 2 ms 596 KB Output is correct
26 Correct 4 ms 1064 KB Output is correct
27 Correct 6 ms 1384 KB Output is correct
28 Correct 205 ms 26268 KB Output is correct
29 Correct 417 ms 39404 KB Output is correct
30 Correct 570 ms 52392 KB Output is correct
31 Correct 747 ms 65620 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 1 ms 328 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 0 ms 300 KB Output is correct
43 Correct 3 ms 824 KB Output is correct
44 Correct 4 ms 1108 KB Output is correct
45 Correct 505 ms 46880 KB Output is correct
46 Correct 831 ms 68440 KB Output is correct
47 Correct 825 ms 68396 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 801 ms 60016 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
57 Correct 3 ms 852 KB Output is correct
58 Correct 11 ms 2132 KB Output is correct
59 Correct 16 ms 2764 KB Output is correct
60 Correct 275 ms 30256 KB Output is correct
61 Correct 451 ms 40516 KB Output is correct
62 Correct 572 ms 49708 KB Output is correct
63 Correct 759 ms 60112 KB Output is correct
64 Correct 0 ms 212 KB Output is correct
65 Correct 0 ms 300 KB Output is correct
66 Correct 0 ms 212 KB Output is correct
67 Correct 1383 ms 123196 KB Output is correct
68 Correct 1405 ms 123228 KB Output is correct
69 Correct 1511 ms 122604 KB Output is correct
70 Correct 7 ms 1236 KB Output is correct
71 Correct 12 ms 2312 KB Output is correct
72 Correct 532 ms 45640 KB Output is correct
73 Correct 1067 ms 68896 KB Output is correct
74 Correct 1384 ms 91272 KB Output is correct
75 Correct 771 ms 62784 KB Output is correct
76 Correct 667 ms 66980 KB Output is correct
77 Correct 7 ms 1620 KB Output is correct
78 Correct 13 ms 2616 KB Output is correct
79 Correct 286 ms 29680 KB Output is correct
80 Correct 512 ms 44472 KB Output is correct
81 Correct 744 ms 59244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 300 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 780 ms 61740 KB Output is correct
10 Correct 19 ms 6436 KB Output is correct
11 Correct 142 ms 33328 KB Output is correct
12 Correct 31 ms 9428 KB Output is correct
13 Correct 56 ms 12780 KB Output is correct
14 Correct 2 ms 596 KB Output is correct
15 Correct 3 ms 876 KB Output is correct
16 Correct 632 ms 61760 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Runtime error 1 ms 340 KB Execution killed with signal 11
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 300 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 780 ms 61740 KB Output is correct
10 Correct 19 ms 6436 KB Output is correct
11 Correct 142 ms 33328 KB Output is correct
12 Correct 31 ms 9428 KB Output is correct
13 Correct 56 ms 12780 KB Output is correct
14 Correct 2 ms 596 KB Output is correct
15 Correct 3 ms 876 KB Output is correct
16 Correct 632 ms 61760 KB Output is correct
17 Runtime error 436 ms 84880 KB Execution killed with signal 11
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 300 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 780 ms 61740 KB Output is correct
10 Correct 19 ms 6436 KB Output is correct
11 Correct 142 ms 33328 KB Output is correct
12 Correct 31 ms 9428 KB Output is correct
13 Correct 56 ms 12780 KB Output is correct
14 Correct 2 ms 596 KB Output is correct
15 Correct 3 ms 876 KB Output is correct
16 Correct 632 ms 61760 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 805 ms 65280 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 2 ms 596 KB Output is correct
26 Correct 4 ms 1064 KB Output is correct
27 Correct 6 ms 1384 KB Output is correct
28 Correct 205 ms 26268 KB Output is correct
29 Correct 417 ms 39404 KB Output is correct
30 Correct 570 ms 52392 KB Output is correct
31 Correct 747 ms 65620 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 212 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 0 ms 212 KB Output is correct
40 Correct 1 ms 328 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 0 ms 300 KB Output is correct
43 Correct 3 ms 824 KB Output is correct
44 Correct 4 ms 1108 KB Output is correct
45 Correct 505 ms 46880 KB Output is correct
46 Correct 831 ms 68440 KB Output is correct
47 Correct 825 ms 68396 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 1 ms 212 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 1 ms 212 KB Output is correct
52 Correct 1 ms 212 KB Output is correct
53 Correct 0 ms 212 KB Output is correct
54 Correct 1 ms 212 KB Output is correct
55 Correct 801 ms 60016 KB Output is correct
56 Correct 0 ms 212 KB Output is correct
57 Correct 3 ms 852 KB Output is correct
58 Correct 11 ms 2132 KB Output is correct
59 Correct 16 ms 2764 KB Output is correct
60 Correct 275 ms 30256 KB Output is correct
61 Correct 451 ms 40516 KB Output is correct
62 Correct 572 ms 49708 KB Output is correct
63 Correct 759 ms 60112 KB Output is correct
64 Correct 0 ms 212 KB Output is correct
65 Correct 0 ms 300 KB Output is correct
66 Correct 0 ms 212 KB Output is correct
67 Correct 1383 ms 123196 KB Output is correct
68 Correct 1405 ms 123228 KB Output is correct
69 Correct 1511 ms 122604 KB Output is correct
70 Correct 7 ms 1236 KB Output is correct
71 Correct 12 ms 2312 KB Output is correct
72 Correct 532 ms 45640 KB Output is correct
73 Correct 1067 ms 68896 KB Output is correct
74 Correct 1384 ms 91272 KB Output is correct
75 Correct 771 ms 62784 KB Output is correct
76 Correct 667 ms 66980 KB Output is correct
77 Correct 7 ms 1620 KB Output is correct
78 Correct 13 ms 2616 KB Output is correct
79 Correct 286 ms 29680 KB Output is correct
80 Correct 512 ms 44472 KB Output is correct
81 Correct 744 ms 59244 KB Output is correct
82 Correct 0 ms 212 KB Output is correct
83 Correct 0 ms 212 KB Output is correct
84 Runtime error 1 ms 340 KB Execution killed with signal 11
85 Halted 0 ms 0 KB -