답안 #1034092

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1034092 2024-07-25T09:44:18 Z hotboy2703 분수 공원 (IOI21_parks) C++17
55 / 100
413 ms 147976 KB
#include "parks.h"

#include<bits/stdc++.h>
using ll = int;
using namespace std;
#define pll pair <ll,ll>
#define fi first
#define se second
#define MP make_pair
#define sz(a) (ll((a).size()))
#define MASK(i) (1LL<<(i))
#define BIT(mask,i) (((mask) >> (i))&1)
struct point{
    ll x,y,id;
    point(ll x1 = 0,ll y1 = 0,ll id1 = 0):x(x1),y(y1),id(id1){}
    bool operator < (const point &p)const {
        return MP(x,y) < MP(p.x,p.y);
    }
};
const ll MAXN = 2e5+100;
ll dsu[MAXN];
ll f(ll x){
    if (dsu[x] < 0)return x;
    return (dsu[x] = f(dsu[x]));
}
bool join(ll x,ll y){
    x = f(x),y = f(y);
    if (x==y)return 0;
    dsu[x] += dsu[y];
    dsu[y] = x;
    return 1;
}
struct road{
    pll a,b;
    ll id;
};
namespace scc{
    vector <pair <pll,bool> > query;
    void add_or(ll x,ll y,bool neg = 0){
        // cout<<x<<' '<<y<<'\n';
        query.push_back(MP(MP(x,y),neg));
    }
    vector <vector <ll> > g1,g2;
    vector <bool> in;
    void add(ll x,ll y){
        g1[x].push_back(y);
        g2[y].push_back(x);
    }
    void dfs(vector <vector <ll> > &adj,ll u,vector <ll> &order){
        in[u] = 1;
        for (auto v:adj[u]){
            if (!in[v]){
                dfs(adj,v,order);
            }
        }
        order.push_back(u);
    }
    bool solve(vector <bool> &res){
        ll n=sz(res)*2;
        g1.resize(n);
        g2.resize(n);
        for (auto x:query){
            if (x.se){ 
                add(x.fi.fi<<1,x.fi.se<<1|1);
                add(x.fi.se<<1,x.fi.fi<<1|1);
            }
            else{
                add(x.fi.fi<<1|1,x.fi.se<<1);
                add(x.fi.se<<1|1,x.fi.fi<<1);
            }
        }
        vector <ll> order;
        in = vector <bool> (n,0);
        vector <ll> c(n);
        for (ll i = 0;i < n;i ++){
            if (!in[i]){
                dfs(g1,i,order);
            }
        }
        in = vector <bool> (n,0);
        reverse(order.begin(),order.end());
        ll ptr = 0;
        for (auto x:order){
            if (!in[x]) {
                vector <ll> comp;
                dfs(g2,x,comp);
                for (auto x:comp)c[x] = ptr;
                ptr++;
            }
        }
        for (ll i = 0;i < sz(res);i ++){
            if (c[i<<1]==c[i<<1|1])return 0;
            res[i] = c[i<<1] > c[i<<1|1];
            // cout<<res[i]<<' ';
        }
        // cout<<'\n';
        return 1;
    }
}
int construct_roads(std::vector<int> x, std::vector<int> y) {
    ll n = sz(x);
    vector <point> a(n);
    
    for (ll i = 0;i < n;i ++){
        dsu[i] = -1;
        a[i] = {x[i],y[i],i};
    }
    sort(a.begin(),a.end());
    auto id = [&](pll x){
        auto tmp = lower_bound(a.begin(),a.end(),point(x.fi,x.se,0));
        if (tmp != a.end() && (*tmp).x==x.fi&&(*tmp).y==x.se)return (*tmp).id;
        else return -1;
    };
    vector <road> all;
    for (ll i = 0;i < n;i ++){
        if (id(MP(a[i].x,a[i].y-2)) != -1) {
            if (join(id(MP(a[i].x,a[i].y-2)),a[i].id)) {
                all.push_back({MP(id(MP(a[i].x,a[i].y-2)),a[i].id),MP(a[i].x-1,a[i].y-1),sz(all)});
                all.push_back({MP(id(MP(a[i].x,a[i].y-2)),a[i].id),MP(a[i].x+1,a[i].y-1),sz(all)});
                scc::add_or(sz(all)-1,sz(all)-2);
                scc::add_or(sz(all)-1,sz(all)-2,1);
            }
        }
        if ((id(MP(a[i].x-2,a[i].y)) != -1)) {
            if (join(id(MP(a[i].x-2,a[i].y)),a[i].id)) {
                all.push_back({MP(id(MP(a[i].x-2,a[i].y)),a[i].id),MP(a[i].x-1,a[i].y+1),sz(all)});
                all.push_back({MP(id(MP(a[i].x-2,a[i].y)),a[i].id),MP(a[i].x-1,a[i].y-1),sz(all)});
                scc::add_or(sz(all)-1,sz(all)-2);
                scc::add_or(sz(all)-1,sz(all)-2,1);
            }
        }
    }
    if (dsu[f(0)] != -n)return 0;
    sort(all.begin(),all.end(),[](road a1,road a2){return a1.b < a2.b;});
    for (ll i = 0;i + 1 < sz(all);i ++){
        if (all[i].b == all[i+1].b){
            // cout<<all[i].a.fi<<' '<<all[i].a.se<<' '<<all[i+1].a.fi<<' '<<all[i+1].a.se<<' '<<all[i].id<<' '<<all[i+1].id<<endl;
            scc::add_or(all[i].id,all[i+1].id,1);
        }
    }
    vector <bool> res(sz(all));
    if (!scc::solve(res))return 0;

    {
        vector <ll> U,V,A,B;
        for (ll i = 0;i < sz(all);i ++){
            if (res[all[i].id]){
                U.push_back(all[i].a.fi);
                V.push_back(all[i].a.se);
                A.push_back(all[i].b.fi);
                B.push_back(all[i].b.se);
            }
        }
        build(U, V, A, B);
        return 1;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 148 ms 60012 KB Output is correct
10 Correct 15 ms 6312 KB Output is correct
11 Correct 60 ms 32488 KB Output is correct
12 Correct 18 ms 9328 KB Output is correct
13 Correct 17 ms 5588 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 128 ms 60004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 148 ms 60012 KB Output is correct
10 Correct 15 ms 6312 KB Output is correct
11 Correct 60 ms 32488 KB Output is correct
12 Correct 18 ms 9328 KB Output is correct
13 Correct 17 ms 5588 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 128 ms 60004 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 293 ms 120756 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 3 ms 1116 KB Output is correct
26 Correct 1 ms 852 KB Output is correct
27 Correct 2 ms 712 KB Output is correct
28 Correct 115 ms 49448 KB Output is correct
29 Correct 167 ms 72304 KB Output is correct
30 Correct 231 ms 98560 KB Output is correct
31 Correct 327 ms 120800 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 604 KB Output is correct
44 Correct 2 ms 648 KB Output is correct
45 Correct 145 ms 60636 KB Output is correct
46 Correct 214 ms 89956 KB Output is correct
47 Correct 264 ms 89912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 148 ms 60012 KB Output is correct
10 Correct 15 ms 6312 KB Output is correct
11 Correct 60 ms 32488 KB Output is correct
12 Correct 18 ms 9328 KB Output is correct
13 Correct 17 ms 5588 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 128 ms 60004 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 293 ms 120756 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 3 ms 1116 KB Output is correct
26 Correct 1 ms 852 KB Output is correct
27 Correct 2 ms 712 KB Output is correct
28 Correct 115 ms 49448 KB Output is correct
29 Correct 167 ms 72304 KB Output is correct
30 Correct 231 ms 98560 KB Output is correct
31 Correct 327 ms 120800 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 604 KB Output is correct
44 Correct 2 ms 648 KB Output is correct
45 Correct 145 ms 60636 KB Output is correct
46 Correct 214 ms 89956 KB Output is correct
47 Correct 264 ms 89912 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Incorrect 349 ms 121164 KB Tree @(5, 3) appears more than once: for edges on positions 66666 and 66667
56 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 148 ms 60012 KB Output is correct
10 Correct 15 ms 6312 KB Output is correct
11 Correct 60 ms 32488 KB Output is correct
12 Correct 18 ms 9328 KB Output is correct
13 Correct 17 ms 5588 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 128 ms 60004 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 345 ms 147784 KB Output is correct
21 Correct 408 ms 134992 KB Output is correct
22 Correct 377 ms 135092 KB Output is correct
23 Correct 210 ms 103040 KB Output is correct
24 Correct 58 ms 8272 KB Output is correct
25 Correct 96 ms 21644 KB Output is correct
26 Correct 110 ms 21644 KB Output is correct
27 Correct 286 ms 119588 KB Output is correct
28 Correct 256 ms 119656 KB Output is correct
29 Correct 274 ms 119528 KB Output is correct
30 Correct 299 ms 119620 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 20 ms 8924 KB Output is correct
33 Correct 28 ms 4696 KB Output is correct
34 Correct 367 ms 147976 KB Output is correct
35 Correct 8 ms 1712 KB Output is correct
36 Correct 28 ms 6052 KB Output is correct
37 Correct 76 ms 11544 KB Output is correct
38 Correct 134 ms 50004 KB Output is correct
39 Correct 199 ms 67440 KB Output is correct
40 Correct 238 ms 87664 KB Output is correct
41 Correct 342 ms 105072 KB Output is correct
42 Correct 413 ms 122440 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 1 ms 604 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 452 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 1 ms 452 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 2 ms 604 KB Output is correct
55 Correct 2 ms 852 KB Output is correct
56 Correct 171 ms 60796 KB Output is correct
57 Correct 231 ms 89956 KB Output is correct
58 Correct 244 ms 89960 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 0 ms 348 KB Output is correct
62 Correct 284 ms 119480 KB Output is correct
63 Correct 255 ms 119656 KB Output is correct
64 Correct 300 ms 118984 KB Output is correct
65 Correct 3 ms 860 KB Output is correct
66 Correct 5 ms 1204 KB Output is correct
67 Correct 206 ms 60796 KB Output is correct
68 Correct 333 ms 92772 KB Output is correct
69 Correct 378 ms 121308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 148 ms 60012 KB Output is correct
10 Correct 15 ms 6312 KB Output is correct
11 Correct 60 ms 32488 KB Output is correct
12 Correct 18 ms 9328 KB Output is correct
13 Correct 17 ms 5588 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 128 ms 60004 KB Output is correct
17 Correct 300 ms 120052 KB Output is correct
18 Correct 287 ms 120156 KB Output is correct
19 Correct 396 ms 135000 KB Output is correct
20 Correct 350 ms 118668 KB Output is correct
21 Correct 243 ms 106088 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 47 ms 19092 KB Output is correct
24 Correct 11 ms 2980 KB Output is correct
25 Correct 40 ms 10244 KB Output is correct
26 Correct 70 ms 13188 KB Output is correct
27 Correct 170 ms 61204 KB Output is correct
28 Correct 209 ms 75696 KB Output is correct
29 Correct 249 ms 93540 KB Output is correct
30 Correct 285 ms 107628 KB Output is correct
31 Correct 330 ms 122192 KB Output is correct
32 Correct 316 ms 120536 KB Output is correct
33 Correct 253 ms 119652 KB Output is correct
34 Correct 3 ms 1100 KB Output is correct
35 Correct 5 ms 1712 KB Output is correct
36 Correct 148 ms 60528 KB Output is correct
37 Correct 247 ms 92728 KB Output is correct
38 Correct 298 ms 120944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 148 ms 60012 KB Output is correct
10 Correct 15 ms 6312 KB Output is correct
11 Correct 60 ms 32488 KB Output is correct
12 Correct 18 ms 9328 KB Output is correct
13 Correct 17 ms 5588 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 128 ms 60004 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 293 ms 120756 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 3 ms 1116 KB Output is correct
26 Correct 1 ms 852 KB Output is correct
27 Correct 2 ms 712 KB Output is correct
28 Correct 115 ms 49448 KB Output is correct
29 Correct 167 ms 72304 KB Output is correct
30 Correct 231 ms 98560 KB Output is correct
31 Correct 327 ms 120800 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 1 ms 604 KB Output is correct
44 Correct 2 ms 648 KB Output is correct
45 Correct 145 ms 60636 KB Output is correct
46 Correct 214 ms 89956 KB Output is correct
47 Correct 264 ms 89912 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Incorrect 349 ms 121164 KB Tree @(5, 3) appears more than once: for edges on positions 66666 and 66667
56 Halted 0 ms 0 KB -