Submission #441437

# Submission time Handle Problem Language Result Execution time Memory
441437 2021-07-05T07:44:28 Z SorahISA Fountain Parks (IOI21_parks) C++17
45 / 100
1131 ms 68508 KB
#include "parks.h"
#pragma GCC optimize("Ofast", "unroll-loops")
#include <bits/stdc++.h>
using namespace std;

// #define int long long
// #define double long double
using pii = pair<int, int>;
template<typename T>
using Prior = std::priority_queue<T>;
template<typename T>
using prior = std::priority_queue<T, vector<T>, greater<T>>;

// #define X first
// #define Y second
#define eb emplace_back
#define pb pop_back
#define pf pop_front
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)

namespace {

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 2E5 + 5;
const int dx[] = {2, 0, -2,  0};
const int dy[] = {0, 2,  0, -2};

map<pii, int> fountain, bench;
vector<int> p(maxn);

vector<int> adj[maxn];

int R(int x) {return x ^ p[x] ? p[x] = R(p[x]) : x;}
int U(int x, int y) {x = R(x), y = R(y); return x ^ y ? p[x] = y, 1 : 0;}

} /// end of namespace

int construct_roads(vector<int> X, vector<int> Y) {
    int N = X.size();
    vector<int> u, v, a, b;
    
    if (N == 1) return build({}, {}, {}, {}), 1;
    
    iota(ALL(p), 0);
    for (int i = 0; i < N; ++i) fountain[{X[i], Y[i]}] = i+1;
    for (int i = 0; i < N; ++i) {
        for (int d = 0; d < 4; ++d) {
            int nei = fountain[{X[i] + dx[d], Y[i] + dy[d]}];
            if (nei-1 > i and U(i, nei-1)) u.eb(i), v.eb(nei-1);
        }
    }
    for (int i = 0; i < N; ++i) if (R(i) != R(0)) return 0;
    
    int M = u.size(); a.assign(M, -1), b.assign(M, -1);
    // assert(M == N-1);
    
    for (int i = 0; i < M; ++i) {
        if (X[u[i]] == X[v[i]]) {
            int midY = Y[u[i]] + Y[v[i]] >> 1;
            if ((X[u[i]] + 1 + midY) % 4 == 2) a[i] = X[u[i]] + 1;
            else a[i] = X[u[i]] - 1;
            b[i] = midY;
            bench[{a[i], b[i]}] = 1;
        }
    }
    
    for (int i = 0; i < M; ++i) {
        if (Y[u[i]] == Y[v[i]]) {
            int midX = X[u[i]] + X[v[i]] >> 1;
            a[i] = midX;
                 if (!bench[{midX, Y[u[i]] + 1}]) b[i] = Y[u[i]] + 1;
            else if (!bench[{midX, Y[v[i]] - 1}]) b[i] = Y[v[i]] - 1;
            bench[{a[i], b[i]}] = 1;
        }
    }
    
    return build(u, v, a, b), 1;
}

Compilation message

parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:61:32: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   61 |             int midY = Y[u[i]] + Y[v[i]] >> 1;
parks.cpp:71:32: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   71 |             int midX = X[u[i]] + X[v[i]] >> 1;
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5708 KB Output is correct
2 Correct 4 ms 5708 KB Output is correct
3 Correct 4 ms 5708 KB Output is correct
4 Correct 4 ms 5708 KB Output is correct
5 Correct 4 ms 5708 KB Output is correct
6 Correct 4 ms 5708 KB Output is correct
7 Correct 4 ms 5708 KB Output is correct
8 Correct 4 ms 5708 KB Output is correct
9 Correct 373 ms 37044 KB Output is correct
10 Correct 22 ms 9200 KB Output is correct
11 Correct 116 ms 23244 KB Output is correct
12 Correct 33 ms 10788 KB Output is correct
13 Correct 64 ms 15468 KB Output is correct
14 Correct 5 ms 5964 KB Output is correct
15 Correct 6 ms 6092 KB Output is correct
16 Correct 404 ms 37052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5708 KB Output is correct
2 Correct 4 ms 5708 KB Output is correct
3 Correct 4 ms 5708 KB Output is correct
4 Correct 4 ms 5708 KB Output is correct
5 Correct 4 ms 5708 KB Output is correct
6 Correct 4 ms 5708 KB Output is correct
7 Correct 4 ms 5708 KB Output is correct
8 Correct 4 ms 5708 KB Output is correct
9 Correct 373 ms 37044 KB Output is correct
10 Correct 22 ms 9200 KB Output is correct
11 Correct 116 ms 23244 KB Output is correct
12 Correct 33 ms 10788 KB Output is correct
13 Correct 64 ms 15468 KB Output is correct
14 Correct 5 ms 5964 KB Output is correct
15 Correct 6 ms 6092 KB Output is correct
16 Correct 404 ms 37052 KB Output is correct
17 Incorrect 4 ms 5708 KB Tree @(3, 3) appears more than once: for edges on positions 1 and 2
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5708 KB Output is correct
2 Correct 4 ms 5708 KB Output is correct
3 Correct 4 ms 5708 KB Output is correct
4 Correct 4 ms 5708 KB Output is correct
5 Correct 4 ms 5708 KB Output is correct
6 Correct 4 ms 5708 KB Output is correct
7 Correct 4 ms 5708 KB Output is correct
8 Correct 4 ms 5708 KB Output is correct
9 Correct 373 ms 37044 KB Output is correct
10 Correct 22 ms 9200 KB Output is correct
11 Correct 116 ms 23244 KB Output is correct
12 Correct 33 ms 10788 KB Output is correct
13 Correct 64 ms 15468 KB Output is correct
14 Correct 5 ms 5964 KB Output is correct
15 Correct 6 ms 6092 KB Output is correct
16 Correct 404 ms 37052 KB Output is correct
17 Incorrect 4 ms 5708 KB Tree @(3, 3) appears more than once: for edges on positions 1 and 2
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5708 KB Output is correct
2 Correct 4 ms 5708 KB Output is correct
3 Correct 4 ms 5708 KB Output is correct
4 Correct 4 ms 5708 KB Output is correct
5 Correct 4 ms 5708 KB Output is correct
6 Correct 4 ms 5708 KB Output is correct
7 Correct 4 ms 5708 KB Output is correct
8 Correct 4 ms 5708 KB Output is correct
9 Correct 373 ms 37044 KB Output is correct
10 Correct 22 ms 9200 KB Output is correct
11 Correct 116 ms 23244 KB Output is correct
12 Correct 33 ms 10788 KB Output is correct
13 Correct 64 ms 15468 KB Output is correct
14 Correct 5 ms 5964 KB Output is correct
15 Correct 6 ms 6092 KB Output is correct
16 Correct 404 ms 37052 KB Output is correct
17 Correct 4 ms 5708 KB Output is correct
18 Correct 4 ms 5708 KB Output is correct
19 Correct 4 ms 5708 KB Output is correct
20 Correct 867 ms 55904 KB Output is correct
21 Correct 925 ms 55876 KB Output is correct
22 Correct 917 ms 55948 KB Output is correct
23 Correct 748 ms 58936 KB Output is correct
24 Correct 906 ms 46740 KB Output is correct
25 Correct 839 ms 35652 KB Output is correct
26 Correct 808 ms 35568 KB Output is correct
27 Correct 968 ms 55852 KB Output is correct
28 Correct 986 ms 56032 KB Output is correct
29 Correct 1027 ms 55988 KB Output is correct
30 Correct 1065 ms 55964 KB Output is correct
31 Correct 4 ms 5708 KB Output is correct
32 Correct 39 ms 9668 KB Output is correct
33 Correct 227 ms 26348 KB Output is correct
34 Correct 859 ms 55844 KB Output is correct
35 Correct 18 ms 7244 KB Output is correct
36 Correct 98 ms 12400 KB Output is correct
37 Correct 278 ms 19024 KB Output is correct
38 Correct 268 ms 24188 KB Output is correct
39 Correct 437 ms 31288 KB Output is correct
40 Correct 691 ms 37956 KB Output is correct
41 Correct 806 ms 44912 KB Output is correct
42 Correct 984 ms 51788 KB Output is correct
43 Correct 4 ms 5708 KB Output is correct
44 Correct 4 ms 5708 KB Output is correct
45 Correct 4 ms 5708 KB Output is correct
46 Correct 4 ms 5708 KB Output is correct
47 Correct 4 ms 5708 KB Output is correct
48 Correct 4 ms 5708 KB Output is correct
49 Correct 4 ms 5708 KB Output is correct
50 Correct 4 ms 5708 KB Output is correct
51 Correct 4 ms 5708 KB Output is correct
52 Correct 4 ms 5708 KB Output is correct
53 Correct 4 ms 5708 KB Output is correct
54 Correct 7 ms 6092 KB Output is correct
55 Correct 9 ms 6312 KB Output is correct
56 Correct 409 ms 33176 KB Output is correct
57 Correct 759 ms 45612 KB Output is correct
58 Correct 790 ms 45484 KB Output is correct
59 Correct 4 ms 5708 KB Output is correct
60 Correct 4 ms 5708 KB Output is correct
61 Correct 4 ms 5708 KB Output is correct
62 Correct 1084 ms 62244 KB Output is correct
63 Correct 993 ms 62088 KB Output is correct
64 Correct 1083 ms 61920 KB Output is correct
65 Correct 9 ms 6348 KB Output is correct
66 Correct 14 ms 7092 KB Output is correct
67 Correct 436 ms 31812 KB Output is correct
68 Correct 729 ms 44944 KB Output is correct
69 Correct 1131 ms 57868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5708 KB Output is correct
2 Correct 4 ms 5708 KB Output is correct
3 Correct 4 ms 5708 KB Output is correct
4 Correct 4 ms 5708 KB Output is correct
5 Correct 4 ms 5708 KB Output is correct
6 Correct 4 ms 5708 KB Output is correct
7 Correct 4 ms 5708 KB Output is correct
8 Correct 4 ms 5708 KB Output is correct
9 Correct 373 ms 37044 KB Output is correct
10 Correct 22 ms 9200 KB Output is correct
11 Correct 116 ms 23244 KB Output is correct
12 Correct 33 ms 10788 KB Output is correct
13 Correct 64 ms 15468 KB Output is correct
14 Correct 5 ms 5964 KB Output is correct
15 Correct 6 ms 6092 KB Output is correct
16 Correct 404 ms 37052 KB Output is correct
17 Correct 973 ms 68508 KB Output is correct
18 Correct 911 ms 68348 KB Output is correct
19 Correct 923 ms 55880 KB Output is correct
20 Correct 912 ms 46936 KB Output is correct
21 Correct 922 ms 53324 KB Output is correct
22 Correct 4 ms 5708 KB Output is correct
23 Correct 82 ms 13656 KB Output is correct
24 Correct 34 ms 8176 KB Output is correct
25 Correct 149 ms 14320 KB Output is correct
26 Correct 397 ms 20348 KB Output is correct
27 Correct 443 ms 27588 KB Output is correct
28 Correct 514 ms 33088 KB Output is correct
29 Correct 668 ms 38572 KB Output is correct
30 Correct 827 ms 43988 KB Output is correct
31 Correct 1127 ms 49504 KB Output is correct
32 Correct 1024 ms 55872 KB Output is correct
33 Correct 994 ms 62124 KB Output is correct
34 Correct 10 ms 6604 KB Output is correct
35 Correct 17 ms 7180 KB Output is correct
36 Correct 401 ms 31116 KB Output is correct
37 Correct 687 ms 43820 KB Output is correct
38 Correct 1053 ms 56756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5708 KB Output is correct
2 Correct 4 ms 5708 KB Output is correct
3 Correct 4 ms 5708 KB Output is correct
4 Correct 4 ms 5708 KB Output is correct
5 Correct 4 ms 5708 KB Output is correct
6 Correct 4 ms 5708 KB Output is correct
7 Correct 4 ms 5708 KB Output is correct
8 Correct 4 ms 5708 KB Output is correct
9 Correct 373 ms 37044 KB Output is correct
10 Correct 22 ms 9200 KB Output is correct
11 Correct 116 ms 23244 KB Output is correct
12 Correct 33 ms 10788 KB Output is correct
13 Correct 64 ms 15468 KB Output is correct
14 Correct 5 ms 5964 KB Output is correct
15 Correct 6 ms 6092 KB Output is correct
16 Correct 404 ms 37052 KB Output is correct
17 Incorrect 4 ms 5708 KB Tree @(3, 3) appears more than once: for edges on positions 1 and 2
18 Halted 0 ms 0 KB -