QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#136999#1142. Fountain Parksbashkort#5 540ms75004kbC++203.2kb2023-08-09 16:33:012024-07-04 01:26:06

Judging History

你现在查看的是最新测评结果

  • [2024-07-04 01:26:06]
  • 评测
  • 测评结果:5
  • 用时:540ms
  • 内存:75004kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-09 16:33:01]
  • 提交

answer

#include "parks.h"
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

struct DSU {
    vector<int> fa;

    void init(int n) {
        fa.resize(n);
        iota(fa.begin(), fa.end(), 0);
    }

    int find(int x) {
        return x == fa[x] ? x : fa[x] = find(fa[x]);
    }

    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y) {
            return false;
        }
        fa[y] = x;
        return true;
    }
};

int construct_roads(std::vector<int> x, std::vector<int> y) {
    int n = size(x);

    if (n == 1) {
        build({}, {}, {}, {});
        return 1;
    }

    map<pair<int, int>, int> mp;
    map<pair<int, int>, vector<int>> adj;

    for (int i = 0; i < n; ++i) {
        mp[{x[i], y[i]}] = i;
    }

    DSU dsu;
    dsu.init(n);
    vector<pair<int, int>> e, f;

    for (int i = 0; i < n; ++i) {
        for (int t : {0, 1}) {
            for (int d : {-2, 2}) {
                int nx = x[i] + t * d;
                int ny = y[i] + (1 - t) * d;
                if (mp.count({nx, ny})) {
                    int j = mp[{nx, ny}];
                    if (dsu.unite(i, j)) {
                        e.emplace_back(i, j);
                    }
                }
            }
        }
    }

    if (size(e) != n - 1) {
        return false;
    }

    for (int i = 0; i < size(e); ++i) {
        int nx = x[e[i].first] + x[e[i].second] >> 1;
        int ny = y[e[i].first] + y[e[i].second] >> 1;
        if (nx % 2 == 0) {
            adj[{nx - 1, ny}].push_back(~i);
            adj[{nx + 1, ny}].push_back(i);
        } else {
            adj[{nx, ny - 1}].push_back(~i);
            adj[{nx, ny + 1}].push_back(i);
        }
    }

    vector<int> type(n - 1);
    for (int k = 0; k < n - 1; ++k) {
        if (type[k] == 0) {
            bool ok = true;
            type[k] = 1;
            auto dfs = [&](auto dfs, int i) -> void {
                int nx = x[e[i].first] + x[e[i].second] >> 1;
                int ny = y[e[i].first] + y[e[i].second] >> 1;
                if (nx % 2 == 0) {
                    nx += type[i];
                } else {
                    ny += type[i];
                }
                for (int to: adj[{nx, ny}]) {
                    int t = to >= 0 ? 1 : -1;
                    if (t == -1) {
                        to = ~to;
                    }
                    if (to == i) {
                        continue;
                    }
                    if (type[to] == 0) {
                        type[to] = -t;
                        dfs(dfs, to);
                    } else {
                        ok = false;
                    }
                }
            };
            dfs(dfs, k);
            if (!ok) {
                return 0;
            }
        }
    }

    vector<int> u(n - 1), v(n - 1), a(n - 1), b(n - 1);

    for (int i = 0; i < size(e); ++i) {
        u[i] = e[i].first;
        v[i] = e[i].second;
        a[i] = x[u[i]] + x[v[i]] >> 1;
        b[i] = y[u[i]] + y[v[i]] >> 1;
        if (a[i] % 2 == 0) {
            a[i] += type[i];
        } else {
            b[i] += type[i];
        }
    }

    build(u, v, a, b);

    return 1;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 0ms
memory: 4040kb

input:

ba73dbf9c7d5e5202834d6a500541c
1
2 2

output:

3kr2yac8xnf3ktgcoqviaw115df6rra7is6p5uix
OK
1
0

result:

ok 

Test #2:

score: 0
Accepted
time: 0ms
memory: 3804kb

input:

ba73dbf9c7d5e5202834d6a500541c
2
2 2
2 4

output:

3kr2yac8xnf3ktgcoqviaw115df6rra7is6p5uix
OK
1
1
0 1 3 3

result:

ok 

Test #3:

score: 0
Accepted
time: 0ms
memory: 3756kb

input:

ba73dbf9c7d5e5202834d6a500541c
2
2 2
2 6

output:

3kr2yac8xnf3ktgcoqviaw115df6rra7is6p5uix
OK
0

result:

ok 

Test #4:

score: 0
Accepted
time: 0ms
memory: 3804kb

input:

ba73dbf9c7d5e5202834d6a500541c
3
2 2
2 4
2 6

output:

3kr2yac8xnf3ktgcoqviaw115df6rra7is6p5uix
OK
1
2
0 1 3 3
1 2 3 5

result:

ok 

Test #5:

score: 0
Accepted
time: 0ms
memory: 3800kb

input:

ba73dbf9c7d5e5202834d6a500541c
4
2 2
2 4
2 6
2 8

output:

3kr2yac8xnf3ktgcoqviaw115df6rra7is6p5uix
OK
1
3
0 1 3 3
1 2 3 5
2 3 3 7

result:

ok 

Test #6:

score: 0
Accepted
time: 0ms
memory: 3800kb

input:

ba73dbf9c7d5e5202834d6a500541c
3
2 2
2 4
2 8

output:

3kr2yac8xnf3ktgcoqviaw115df6rra7is6p5uix
OK
0

result:

ok 

Test #7:

score: 0
Accepted
time: 0ms
memory: 3804kb

input:

ba73dbf9c7d5e5202834d6a500541c
4
2 2
2 4
2 8
2 10

output:

3kr2yac8xnf3ktgcoqviaw115df6rra7is6p5uix
OK
0

result:

ok 

Test #8:

score: 0
Accepted
time: 0ms
memory: 3772kb

input:

ba73dbf9c7d5e5202834d6a500541c
4
2 2
2 4
2 6
2 10

output:

3kr2yac8xnf3ktgcoqviaw115df6rra7is6p5uix
OK
0

result:

ok 

Test #9:

score: 0
Accepted
time: 220ms
memory: 39032kb

input:

ba73dbf9c7d5e5202834d6a500541c
100000
2 15660
2 23918
2 132200
2 117654
2 162750
2 183010
2 75554
2 29740
2 185476
2 135138
2 194024
2 182274
2 1338
2 42922
2 51616
2 171196
2 159598
2 136432
2 84454
2 61806
2 136968
2 167442
2 150036
2 23974
2 10064
2 86342
2 146274
2 174318
2 130832
2 118838
2 180...

output:

3kr2yac8xnf3ktgcoqviaw115df6rra7is6p5uix
OK
1
99999
0 30345 3 15659
0 86548 3 15661
1 55755 3 23917
1 29124 3 23919
2 13438 3 132199
2 68290 3 132201
3 13368 3 117653
3 9859 3 117655
4 23781 3 162749
4 67987 3 162751
5 79051 3 183009
5 24499 3 183011
6 12841 3 75553
6 5988 3 75555
7 8975 3 29739
7 6...

result:

ok 

Test #10:

score: 0
Accepted
time: 9ms
memory: 7288kb

input:

ba73dbf9c7d5e5202834d6a500541c
10000
2 3124
2 3126
2 3128
2 3130
2 3132
2 3134
2 3136
2 3138
2 3140
2 3142
2 3144
2 3146
2 3148
2 3150
2 3152
2 3154
2 3156
2 3158
2 3160
2 3162
2 3164
2 3166
2 3168
2 3170
2 3172
2 3174
2 3176
2 3178
2 3180
2 3182
2 3184
2 3186
2 3188
2 3190
2 3192
2 3194
2 3196
2 31...

output:

3kr2yac8xnf3ktgcoqviaw115df6rra7is6p5uix
OK
1
9999
0 1 3 3125
1 2 3 3127
2 3 3 3129
3 4 3 3131
4 5 3 3133
5 6 3 3135
6 7 3 3137
7 8 3 3139
8 9 3 3141
9 10 3 3143
10 11 3 3145
11 12 3 3147
12 13 3 3149
13 14 3 3151
14 15 3 3153
15 16 3 3155
16 17 3 3157
17 18 3 3159
18 19 3 3161
19 20 3 3163
20 21 3 ...

result:

ok 

Test #11:

score: 0
Accepted
time: 66ms
memory: 22576kb

input:

ba73dbf9c7d5e5202834d6a500541c
53891
2 3566
2 3568
2 3570
2 3572
2 3574
2 3576
2 3578
2 3580
2 3582
2 3584
2 3586
2 3588
2 3590
2 3592
2 3594
2 3596
2 3598
2 3600
2 3602
2 3604
2 3606
2 3608
2 3610
2 3612
2 3614
2 3616
2 3618
2 3620
2 3622
2 3624
2 3626
2 3628
2 3630
2 3632
2 3634
2 3636
2 3638
2 36...

output:

3kr2yac8xnf3ktgcoqviaw115df6rra7is6p5uix
OK
1
53890
0 1 3 3567
1 2 3 3569
2 3 3 3571
3 4 3 3573
4 5 3 3575
5 6 3 3577
6 7 3 3579
7 8 3 3581
8 9 3 3583
9 10 3 3585
10 11 3 3587
11 12 3 3589
12 13 3 3591
13 14 3 3593
14 15 3 3595
15 16 3 3597
16 17 3 3599
17 18 3 3601
18 19 3 3603
19 20 3 3605
20 21 3...

result:

ok 

Test #12:

score: 0
Accepted
time: 10ms
memory: 8996kb

input:

ba73dbf9c7d5e5202834d6a500541c
14979
2 4954
2 4956
2 4958
2 4960
2 4962
2 4964
2 4966
2 4968
2 4970
2 4972
2 4974
2 4976
2 4978
2 4980
2 4982
2 4984
2 4986
2 4988
2 4990
2 4992
2 4994
2 4996
2 4998
2 5000
2 5002
2 5004
2 5006
2 5008
2 5010
2 5012
2 5014
2 5016
2 5018
2 5020
2 5022
2 5024
2 5026
2 50...

output:

3kr2yac8xnf3ktgcoqviaw115df6rra7is6p5uix
OK
1
14978
0 1 3 4955
1 2 3 4957
2 3 3 4959
3 4 3 4961
4 5 3 4963
5 6 3 4965
6 7 3 4967
7 8 3 4969
8 9 3 4971
9 10 3 4973
10 11 3 4975
11 12 3 4977
12 13 3 4979
13 14 3 4981
14 15 3 4983
15 16 3 4985
16 17 3 4987
17 18 3 4989
18 19 3 4991
19 20 3 4993
20 21 3...

result:

ok 

Test #13:

score: 0
Accepted
time: 30ms
memory: 7492kb

input:

ba73dbf9c7d5e5202834d6a500541c
44171
2 36500
2 36502
2 36504
2 36506
2 36508
2 36510
2 36512
2 36514
2 36516
2 36518
2 36520
2 36522
2 36524
2 36526
2 36528
2 36530
2 36532
2 36534
2 36536
2 36538
2 36540
2 36542
2 36544
2 36546
2 36548
2 36550
2 36552
2 36554
2 36556
2 36558
2 36560
2 36562
2 36564...

output:

3kr2yac8xnf3ktgcoqviaw115df6rra7is6p5uix
OK
0

result:

ok 

Test #14:

score: 0
Accepted
time: 1ms
memory: 3968kb

input:

ba73dbf9c7d5e5202834d6a500541c
1000
2 20406
2 20378
2 37840
2 37702
2 20448
2 37688
2 37780
2 20720
2 38256
2 20612
2 38050
2 20152
2 37880
2 20116
2 20030
2 20526
2 38324
2 20956
2 20852
2 20356
2 37668
2 20292
2 37648
2 20320
2 20078
2 38060
2 38014
2 37738
2 37878
2 20336
2 20472
2 20214
2 38340
...

output:

3kr2yac8xnf3ktgcoqviaw115df6rra7is6p5uix
OK
0

result:

ok 

Test #15:

score: 0
Accepted
time: 2ms
memory: 3996kb

input:

ba73dbf9c7d5e5202834d6a500541c
2000
2 19578
2 1754
2 1760
2 130946
2 164378
2 1038
2 20302
2 131788
2 131632
2 164392
2 19868
2 164924
2 131380
2 130972
2 131348
2 1070
2 131568
2 19492
2 19876
2 131606
2 1142
2 1588
2 1424
2 1726
2 131416
2 946
2 20158
2 19574
2 20106
2 1736
2 1186
2 19476
2 164256...

output:

3kr2yac8xnf3ktgcoqviaw115df6rra7is6p5uix
OK
0

result:

ok 

Test #16:

score: 0
Accepted
time: 222ms
memory: 39316kb

input:

ba73dbf9c7d5e5202834d6a500541c
100000
2 103034
2 75068
2 69976
2 84860
2 113488
2 156808
2 109250
2 119184
2 169250
2 182382
2 161594
2 169232
2 41046
2 87158
2 10192
2 32612
2 84228
2 49708
2 157912
2 160028
2 160234
2 167142
2 22010
2 37360
2 64100
2 113388
2 81460
2 52862
2 77902
2 155958
2 13330...

output:

3kr2yac8xnf3ktgcoqviaw115df6rra7is6p5uix
OK
1
99999
0 22204 3 103033
0 21451 3 103035
1 41977 3 75067
1 23594 3 75069
2 89253 3 69975
2 35896 3 69977
3 83859 3 84859
3 19303 3 84861
4 99175 3 113487
4 98266 3 113489
5 98562 3 156807
5 4928 3 156809
6 45395 3 109249
6 66778 3 109251
7 95546 3 119183
...

result:

ok 

Subtask #2:

score: 0
Wrong Answer

Dependency #1:

100%
Accepted

Test #17:

score: 0
Wrong Answer
time: 0ms
memory: 3788kb

input:

ba73dbf9c7d5e5202834d6a500541c
4
4 4
2 4
4 2
2 2

output:

3kr2yac8xnf3ktgcoqviaw115df6rra7is6p5uix
OK
0

result:

wrong answer Solution announced impossible, but it is possible.

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Wrong Answer

Test #82:

score: 0
Wrong Answer
time: 0ms
memory: 3804kb

input:

ba73dbf9c7d5e5202834d6a500541c
3
200000 2
200000 4
199998 2

output:

3kr2yac8xnf3ktgcoqviaw115df6rra7is6p5uix
OK
0

result:

wrong answer Solution announced impossible, but it is possible.

Subtask #5:

score: 0
Wrong Answer

Test #108:

score: 20
Accepted
time: 540ms
memory: 75004kb

input:

ba73dbf9c7d5e5202834d6a500541c
200000
82422 100002
100002 52498
82816 2
97624 2
100002 58032
20638 100002
100002 7646
80512 2
2 10584
28426 100002
2 83036
2 64556
47872 100002
55196 2
85350 100002
2 95376
2 23942
12488 100002
83178 2
2 9086
85598 2
100002 78820
100002 10868
98810 2
84182 100002
2 71...

output:

3kr2yac8xnf3ktgcoqviaw115df6rra7is6p5uix
OK
1
199999
0 148989 82421 100003
0 168975 82423 100003
1 67645 100003 52497
1 117727 100003 52499
2 150926 82815 3
2 142334 82817 3
3 164963 97623 3
3 141442 97625 3
4 9204 100003 58031
4 66537 100003 58033
5 106842 20637 100003
5 10116 20639 100003
6 182160...

result:

ok 

Test #109:

score: -20
Wrong Answer
time: 435ms
memory: 65788kb

input:

ba73dbf9c7d5e5202834d6a500541c
199999
10674 50002
7228 2
31566 50002
48790 2
87212 50002
100002 76172
54282 100002
2 33136
100002 78564
50002 9882
50848 50002
50002 83692
92422 100002
100002 78880
100002 71432
50002 65586
3750 2
50002 11898
50002 17296
50002 44774
3836 2
49936 50002
50002 48536
1542...

output:

3kr2yac8xnf3ktgcoqviaw115df6rra7is6p5uix
OK
0

result:

wrong answer Solution announced impossible, but it is possible.

Subtask #6:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%