Submission #441398

# Submission time Handle Problem Language Result Execution time Memory
441398 2021-07-05T06:43:19 Z SorahISA Fountain Parks (IOI21_parks) C++17
15 / 100
889 ms 47364 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> points;
vector<int> p(maxn);

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

} /// 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) points[{X[i], Y[i]}] = i+1;
    for (int i = 0; i < N; ++i) {
        for (int d = 0; d < 4; ++d) {
            int nei = points[{X[i] + dx[d], Y[i] + dy[d]}];
            if (nei-1 > i) {
                U(i, nei-1);
                u.eb(i), v.eb(nei-1);
                if (X[i] == X[nei-1] and X[i] == 2) a.eb(1), b.eb(Y[i] + Y[nei-1] >> 1);
                if (X[i] == X[nei-1] and X[i] == 4) a.eb(5), b.eb(Y[i] + Y[nei-1] >> 1);
                if (Y[i] == Y[nei-1]) a.eb(3), b.eb(Y[i] + 1);
            }
        }
    }
    for (int i = 0; i < N; ++i) if (R(i) != R(0)) return 0;
    
    return build(u, v, a, b), 1;
}

Compilation message

parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:52:72: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   52 |                 if (X[i] == X[nei-1] and X[i] == 2) a.eb(1), b.eb(Y[i] + Y[nei-1] >> 1);
parks.cpp:53:72: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   53 |                 if (X[i] == X[nei-1] and X[i] == 4) a.eb(5), b.eb(Y[i] + Y[nei-1] >> 1);
# Verdict Execution time Memory Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 1100 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 327 ms 26044 KB Output is correct
10 Correct 16 ms 3880 KB Output is correct
11 Correct 90 ms 15140 KB Output is correct
12 Correct 23 ms 5256 KB Output is correct
13 Correct 59 ms 11100 KB Output is correct
14 Correct 2 ms 1228 KB Output is correct
15 Correct 3 ms 1484 KB Output is correct
16 Correct 321 ms 26176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 1100 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 327 ms 26044 KB Output is correct
10 Correct 16 ms 3880 KB Output is correct
11 Correct 90 ms 15140 KB Output is correct
12 Correct 23 ms 5256 KB Output is correct
13 Correct 59 ms 11100 KB Output is correct
14 Correct 2 ms 1228 KB Output is correct
15 Correct 3 ms 1484 KB Output is correct
16 Correct 321 ms 26176 KB Output is correct
17 Correct 1 ms 972 KB Output is correct
18 Correct 1 ms 972 KB Output is correct
19 Correct 1 ms 1100 KB Output is correct
20 Correct 1 ms 972 KB Output is correct
21 Correct 1 ms 972 KB Output is correct
22 Correct 1 ms 972 KB Output is correct
23 Correct 846 ms 43448 KB Output is correct
24 Correct 1 ms 972 KB Output is correct
25 Correct 3 ms 1356 KB Output is correct
26 Correct 4 ms 1612 KB Output is correct
27 Correct 6 ms 1740 KB Output is correct
28 Correct 233 ms 18020 KB Output is correct
29 Correct 410 ms 26392 KB Output is correct
30 Correct 710 ms 34852 KB Output is correct
31 Correct 889 ms 43400 KB Output is correct
32 Correct 1 ms 972 KB Output is correct
33 Correct 1 ms 972 KB Output is correct
34 Correct 1 ms 972 KB Output is correct
35 Correct 1 ms 972 KB Output is correct
36 Correct 1 ms 972 KB Output is correct
37 Correct 1 ms 972 KB Output is correct
38 Correct 1 ms 972 KB Output is correct
39 Correct 1 ms 972 KB Output is correct
40 Correct 1 ms 972 KB Output is correct
41 Correct 1 ms 972 KB Output is correct
42 Correct 1 ms 972 KB Output is correct
43 Correct 3 ms 1356 KB Output is correct
44 Correct 4 ms 1612 KB Output is correct
45 Correct 323 ms 22184 KB Output is correct
46 Correct 576 ms 31764 KB Output is correct
47 Correct 559 ms 31768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 1100 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 327 ms 26044 KB Output is correct
10 Correct 16 ms 3880 KB Output is correct
11 Correct 90 ms 15140 KB Output is correct
12 Correct 23 ms 5256 KB Output is correct
13 Correct 59 ms 11100 KB Output is correct
14 Correct 2 ms 1228 KB Output is correct
15 Correct 3 ms 1484 KB Output is correct
16 Correct 321 ms 26176 KB Output is correct
17 Correct 1 ms 972 KB Output is correct
18 Correct 1 ms 972 KB Output is correct
19 Correct 1 ms 1100 KB Output is correct
20 Correct 1 ms 972 KB Output is correct
21 Correct 1 ms 972 KB Output is correct
22 Correct 1 ms 972 KB Output is correct
23 Correct 846 ms 43448 KB Output is correct
24 Correct 1 ms 972 KB Output is correct
25 Correct 3 ms 1356 KB Output is correct
26 Correct 4 ms 1612 KB Output is correct
27 Correct 6 ms 1740 KB Output is correct
28 Correct 233 ms 18020 KB Output is correct
29 Correct 410 ms 26392 KB Output is correct
30 Correct 710 ms 34852 KB Output is correct
31 Correct 889 ms 43400 KB Output is correct
32 Correct 1 ms 972 KB Output is correct
33 Correct 1 ms 972 KB Output is correct
34 Correct 1 ms 972 KB Output is correct
35 Correct 1 ms 972 KB Output is correct
36 Correct 1 ms 972 KB Output is correct
37 Correct 1 ms 972 KB Output is correct
38 Correct 1 ms 972 KB Output is correct
39 Correct 1 ms 972 KB Output is correct
40 Correct 1 ms 972 KB Output is correct
41 Correct 1 ms 972 KB Output is correct
42 Correct 1 ms 972 KB Output is correct
43 Correct 3 ms 1356 KB Output is correct
44 Correct 4 ms 1612 KB Output is correct
45 Correct 323 ms 22184 KB Output is correct
46 Correct 576 ms 31764 KB Output is correct
47 Correct 559 ms 31768 KB Output is correct
48 Incorrect 1 ms 972 KB Wrong answer detected in grader
49 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 1100 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 327 ms 26044 KB Output is correct
10 Correct 16 ms 3880 KB Output is correct
11 Correct 90 ms 15140 KB Output is correct
12 Correct 23 ms 5256 KB Output is correct
13 Correct 59 ms 11100 KB Output is correct
14 Correct 2 ms 1228 KB Output is correct
15 Correct 3 ms 1484 KB Output is correct
16 Correct 321 ms 26176 KB Output is correct
17 Incorrect 1 ms 972 KB Wrong answer detected in grader
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 1100 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 327 ms 26044 KB Output is correct
10 Correct 16 ms 3880 KB Output is correct
11 Correct 90 ms 15140 KB Output is correct
12 Correct 23 ms 5256 KB Output is correct
13 Correct 59 ms 11100 KB Output is correct
14 Correct 2 ms 1228 KB Output is correct
15 Correct 3 ms 1484 KB Output is correct
16 Correct 321 ms 26176 KB Output is correct
17 Incorrect 757 ms 47364 KB Wrong answer detected in grader
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 972 KB Output is correct
2 Correct 1 ms 972 KB Output is correct
3 Correct 1 ms 972 KB Output is correct
4 Correct 1 ms 972 KB Output is correct
5 Correct 1 ms 1100 KB Output is correct
6 Correct 1 ms 972 KB Output is correct
7 Correct 1 ms 972 KB Output is correct
8 Correct 1 ms 972 KB Output is correct
9 Correct 327 ms 26044 KB Output is correct
10 Correct 16 ms 3880 KB Output is correct
11 Correct 90 ms 15140 KB Output is correct
12 Correct 23 ms 5256 KB Output is correct
13 Correct 59 ms 11100 KB Output is correct
14 Correct 2 ms 1228 KB Output is correct
15 Correct 3 ms 1484 KB Output is correct
16 Correct 321 ms 26176 KB Output is correct
17 Correct 1 ms 972 KB Output is correct
18 Correct 1 ms 972 KB Output is correct
19 Correct 1 ms 1100 KB Output is correct
20 Correct 1 ms 972 KB Output is correct
21 Correct 1 ms 972 KB Output is correct
22 Correct 1 ms 972 KB Output is correct
23 Correct 846 ms 43448 KB Output is correct
24 Correct 1 ms 972 KB Output is correct
25 Correct 3 ms 1356 KB Output is correct
26 Correct 4 ms 1612 KB Output is correct
27 Correct 6 ms 1740 KB Output is correct
28 Correct 233 ms 18020 KB Output is correct
29 Correct 410 ms 26392 KB Output is correct
30 Correct 710 ms 34852 KB Output is correct
31 Correct 889 ms 43400 KB Output is correct
32 Correct 1 ms 972 KB Output is correct
33 Correct 1 ms 972 KB Output is correct
34 Correct 1 ms 972 KB Output is correct
35 Correct 1 ms 972 KB Output is correct
36 Correct 1 ms 972 KB Output is correct
37 Correct 1 ms 972 KB Output is correct
38 Correct 1 ms 972 KB Output is correct
39 Correct 1 ms 972 KB Output is correct
40 Correct 1 ms 972 KB Output is correct
41 Correct 1 ms 972 KB Output is correct
42 Correct 1 ms 972 KB Output is correct
43 Correct 3 ms 1356 KB Output is correct
44 Correct 4 ms 1612 KB Output is correct
45 Correct 323 ms 22184 KB Output is correct
46 Correct 576 ms 31764 KB Output is correct
47 Correct 559 ms 31768 KB Output is correct
48 Incorrect 1 ms 972 KB Wrong answer detected in grader
49 Halted 0 ms 0 KB -