답안 #1059427

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1059427 2024-08-14T23:57:23 Z Trent 분수 공원 (IOI21_parks) C++17
30 / 100
286 ms 46236 KB
#include "parks.h"
#include "bits/stdc++.h"
using namespace std;
#define forR(i, x) for(int i = 0; i < (x); ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef set<int> si;
struct pii{int a, b;};
bool operator <(pii a, pii b) {return a.a < b.a || a.a == b.a && a.b < b.b;}
const int MD = 2e5 + 10;

bool conn(int n, vi& u, vi& v) {
    vvi adj(n);
    forR(i, u.size()) {
        adj[u[i]].push_back(v[i]);
        adj[v[i]].push_back(u[i]);
    }
    vb vis(n);
    vi dfs = {0};
    while(!dfs.empty()) {
        int cur = dfs.back(); dfs.pop_back();
        if(!vis[cur]) {
            vis[cur] = true;
            for(int i : adj[cur]) if(!vis[i]) {
                dfs.push_back(i);
            }
        }
    }
    forR(i, n) if(!vis[i]) return false;
    return true;
}
int construct_roads(std::vector<int> x, std::vector<int> y) {
    int n = x.size();
    map<pii, int> ci;
    set<pii> bnch;
    forR(i, n) ci[{x[i], y[i]}] = i;
    vi u, v, a, b;

    for(int y = 2; y < MD; y += 2) {
        if(ci.count({2, y}) && ci.count({2, y+2})) {
            u.push_back(ci[{2,y}]);
            v.push_back(ci[{2, y+2}]);
            a.push_back(1);
            b.push_back(y + 1);
            bnch.insert({1, y+1});
        }
        if(ci.count({6, y}) && ci.count({6, y+2})) {
            u.push_back(ci[{6,y}]);
            v.push_back(ci[{6, y+2}]);
            a.push_back(7);
            b.push_back(y + 1);
            bnch.insert({7, y+1});
        }
        if(ci.count({4, y}) && ci.count({4, y+2})) {
            u.push_back(ci[{4,y}]);
            v.push_back(ci[{4, y+2}]);
            a.push_back(y % 4 == 0 ? 5 : 3);
            b.push_back(y + 1);
            bnch.insert({a.back(), b.back()});
        }
    }
    bool lasAdd = false;
    for(int y = 2; y < MD; y += 2) {
        if(lasAdd) lasAdd = false;
        else {
            if(ci.count({4, y}) && ci.count({2, y})) {
                u.push_back(ci[{4, y}]);
                v.push_back(ci[{2, y}]);
                a.push_back(3);
                if(!bnch.count({3, y + 1})) b.push_back(y+1);
                else {
                    assert(!bnch.count({3, y-1}));
                    b.push_back(y-1);
                }
                bnch.insert({a.back(), b.back()});
                lasAdd = true;
            }
        }
    }
    lasAdd = false;
    for(int y = 2; y < MD; y += 2) {
        if(lasAdd) lasAdd = false;
        else {
            if(ci.count({4, y}) && ci.count({6, y})) {
                u.push_back(ci[{4, y}]);
                v.push_back(ci[{6, y}]);
                a.push_back(5);
                if(!bnch.count({5, y + 1})) b.push_back(y+1);
                else {
                    assert(!bnch.count({5, y-1}));
                    b.push_back(y-1);
                }
                bnch.insert({a.back(), b.back()});
                lasAdd = true;
            }
        }
    }
    if(conn(n, u, v)) {
        build(u, v, a, b);
        return 1;
    }
    return 0;
}

Compilation message

parks.cpp: In function 'bool operator<(pii, pii)':
parks.cpp:12:63: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   12 | bool operator <(pii a, pii b) {return a.a < b.a || a.a == b.a && a.b < b.b;}
      |                                                    ~~~~~~~~~~~^~~~~~~~~~~~
parks.cpp: In function 'bool conn(int, vi&, vi&)':
parks.cpp:4:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forR(i, x) for(int i = 0; i < (x); ++i)
      |                                     ^
parks.cpp:17:5: note: in expansion of macro 'forR'
   17 |     forR(i, u.size()) {
      |     ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 2 ms 424 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 127 ms 19988 KB Output is correct
10 Correct 25 ms 2648 KB Output is correct
11 Correct 72 ms 10948 KB Output is correct
12 Correct 30 ms 3156 KB Output is correct
13 Correct 64 ms 8900 KB Output is correct
14 Correct 4 ms 600 KB Output is correct
15 Correct 5 ms 604 KB Output is correct
16 Correct 102 ms 19772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 2 ms 424 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 127 ms 19988 KB Output is correct
10 Correct 25 ms 2648 KB Output is correct
11 Correct 72 ms 10948 KB Output is correct
12 Correct 30 ms 3156 KB Output is correct
13 Correct 64 ms 8900 KB Output is correct
14 Correct 4 ms 600 KB Output is correct
15 Correct 5 ms 604 KB Output is correct
16 Correct 102 ms 19772 KB Output is correct
17 Correct 2 ms 344 KB Output is correct
18 Correct 3 ms 348 KB Output is correct
19 Correct 3 ms 344 KB Output is correct
20 Correct 4 ms 348 KB Output is correct
21 Correct 3 ms 348 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 274 ms 43064 KB Output is correct
24 Correct 4 ms 348 KB Output is correct
25 Correct 6 ms 604 KB Output is correct
26 Correct 8 ms 1112 KB Output is correct
27 Correct 15 ms 1116 KB Output is correct
28 Correct 96 ms 17564 KB Output is correct
29 Correct 158 ms 26024 KB Output is correct
30 Correct 203 ms 34984 KB Output is correct
31 Correct 280 ms 42904 KB Output is correct
32 Correct 2 ms 600 KB Output is correct
33 Correct 2 ms 348 KB Output is correct
34 Correct 2 ms 348 KB Output is correct
35 Correct 2 ms 348 KB Output is correct
36 Correct 2 ms 348 KB Output is correct
37 Correct 4 ms 348 KB Output is correct
38 Correct 2 ms 348 KB Output is correct
39 Correct 2 ms 348 KB Output is correct
40 Correct 3 ms 344 KB Output is correct
41 Correct 2 ms 348 KB Output is correct
42 Correct 2 ms 348 KB Output is correct
43 Correct 7 ms 604 KB Output is correct
44 Correct 11 ms 1044 KB Output is correct
45 Correct 107 ms 19972 KB Output is correct
46 Correct 176 ms 28836 KB Output is correct
47 Correct 166 ms 28840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 2 ms 424 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 127 ms 19988 KB Output is correct
10 Correct 25 ms 2648 KB Output is correct
11 Correct 72 ms 10948 KB Output is correct
12 Correct 30 ms 3156 KB Output is correct
13 Correct 64 ms 8900 KB Output is correct
14 Correct 4 ms 600 KB Output is correct
15 Correct 5 ms 604 KB Output is correct
16 Correct 102 ms 19772 KB Output is correct
17 Correct 2 ms 344 KB Output is correct
18 Correct 3 ms 348 KB Output is correct
19 Correct 3 ms 344 KB Output is correct
20 Correct 4 ms 348 KB Output is correct
21 Correct 3 ms 348 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 274 ms 43064 KB Output is correct
24 Correct 4 ms 348 KB Output is correct
25 Correct 6 ms 604 KB Output is correct
26 Correct 8 ms 1112 KB Output is correct
27 Correct 15 ms 1116 KB Output is correct
28 Correct 96 ms 17564 KB Output is correct
29 Correct 158 ms 26024 KB Output is correct
30 Correct 203 ms 34984 KB Output is correct
31 Correct 280 ms 42904 KB Output is correct
32 Correct 2 ms 600 KB Output is correct
33 Correct 2 ms 348 KB Output is correct
34 Correct 2 ms 348 KB Output is correct
35 Correct 2 ms 348 KB Output is correct
36 Correct 2 ms 348 KB Output is correct
37 Correct 4 ms 348 KB Output is correct
38 Correct 2 ms 348 KB Output is correct
39 Correct 2 ms 348 KB Output is correct
40 Correct 3 ms 344 KB Output is correct
41 Correct 2 ms 348 KB Output is correct
42 Correct 2 ms 348 KB Output is correct
43 Correct 7 ms 604 KB Output is correct
44 Correct 11 ms 1044 KB Output is correct
45 Correct 107 ms 19972 KB Output is correct
46 Correct 176 ms 28836 KB Output is correct
47 Correct 166 ms 28840 KB Output is correct
48 Correct 4 ms 348 KB Output is correct
49 Correct 4 ms 348 KB Output is correct
50 Correct 4 ms 432 KB Output is correct
51 Correct 3 ms 348 KB Output is correct
52 Correct 4 ms 348 KB Output is correct
53 Correct 5 ms 348 KB Output is correct
54 Correct 3 ms 348 KB Output is correct
55 Correct 286 ms 46104 KB Output is correct
56 Correct 4 ms 604 KB Output is correct
57 Correct 7 ms 716 KB Output is correct
58 Correct 19 ms 1784 KB Output is correct
59 Correct 19 ms 2816 KB Output is correct
60 Correct 121 ms 23160 KB Output is correct
61 Correct 171 ms 31140 KB Output is correct
62 Correct 213 ms 38052 KB Output is correct
63 Correct 283 ms 46236 KB Output is correct
64 Correct 3 ms 600 KB Output is correct
65 Correct 3 ms 348 KB Output is correct
66 Correct 3 ms 348 KB Output is correct
67 Correct 240 ms 41024 KB Output is correct
68 Correct 224 ms 41424 KB Output is correct
69 Correct 224 ms 40940 KB Output is correct
70 Correct 10 ms 1116 KB Output is correct
71 Correct 13 ms 1880 KB Output is correct
72 Correct 111 ms 20660 KB Output is correct
73 Correct 179 ms 30880 KB Output is correct
74 Correct 262 ms 41164 KB Output is correct
75 Correct 261 ms 44388 KB Output is correct
76 Correct 218 ms 41128 KB Output is correct
77 Correct 11 ms 1372 KB Output is correct
78 Correct 14 ms 2244 KB Output is correct
79 Correct 111 ms 21428 KB Output is correct
80 Correct 176 ms 32168 KB Output is correct
81 Correct 276 ms 42884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 2 ms 424 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 127 ms 19988 KB Output is correct
10 Correct 25 ms 2648 KB Output is correct
11 Correct 72 ms 10948 KB Output is correct
12 Correct 30 ms 3156 KB Output is correct
13 Correct 64 ms 8900 KB Output is correct
14 Correct 4 ms 600 KB Output is correct
15 Correct 5 ms 604 KB Output is correct
16 Correct 102 ms 19772 KB Output is correct
17 Incorrect 2 ms 348 KB Solution announced impossible, but it is possible.
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 2 ms 424 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 127 ms 19988 KB Output is correct
10 Correct 25 ms 2648 KB Output is correct
11 Correct 72 ms 10948 KB Output is correct
12 Correct 30 ms 3156 KB Output is correct
13 Correct 64 ms 8900 KB Output is correct
14 Correct 4 ms 600 KB Output is correct
15 Correct 5 ms 604 KB Output is correct
16 Correct 102 ms 19772 KB Output is correct
17 Incorrect 115 ms 25348 KB Solution announced impossible, but it is possible.
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 2 ms 424 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 127 ms 19988 KB Output is correct
10 Correct 25 ms 2648 KB Output is correct
11 Correct 72 ms 10948 KB Output is correct
12 Correct 30 ms 3156 KB Output is correct
13 Correct 64 ms 8900 KB Output is correct
14 Correct 4 ms 600 KB Output is correct
15 Correct 5 ms 604 KB Output is correct
16 Correct 102 ms 19772 KB Output is correct
17 Correct 2 ms 344 KB Output is correct
18 Correct 3 ms 348 KB Output is correct
19 Correct 3 ms 344 KB Output is correct
20 Correct 4 ms 348 KB Output is correct
21 Correct 3 ms 348 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 274 ms 43064 KB Output is correct
24 Correct 4 ms 348 KB Output is correct
25 Correct 6 ms 604 KB Output is correct
26 Correct 8 ms 1112 KB Output is correct
27 Correct 15 ms 1116 KB Output is correct
28 Correct 96 ms 17564 KB Output is correct
29 Correct 158 ms 26024 KB Output is correct
30 Correct 203 ms 34984 KB Output is correct
31 Correct 280 ms 42904 KB Output is correct
32 Correct 2 ms 600 KB Output is correct
33 Correct 2 ms 348 KB Output is correct
34 Correct 2 ms 348 KB Output is correct
35 Correct 2 ms 348 KB Output is correct
36 Correct 2 ms 348 KB Output is correct
37 Correct 4 ms 348 KB Output is correct
38 Correct 2 ms 348 KB Output is correct
39 Correct 2 ms 348 KB Output is correct
40 Correct 3 ms 344 KB Output is correct
41 Correct 2 ms 348 KB Output is correct
42 Correct 2 ms 348 KB Output is correct
43 Correct 7 ms 604 KB Output is correct
44 Correct 11 ms 1044 KB Output is correct
45 Correct 107 ms 19972 KB Output is correct
46 Correct 176 ms 28836 KB Output is correct
47 Correct 166 ms 28840 KB Output is correct
48 Correct 4 ms 348 KB Output is correct
49 Correct 4 ms 348 KB Output is correct
50 Correct 4 ms 432 KB Output is correct
51 Correct 3 ms 348 KB Output is correct
52 Correct 4 ms 348 KB Output is correct
53 Correct 5 ms 348 KB Output is correct
54 Correct 3 ms 348 KB Output is correct
55 Correct 286 ms 46104 KB Output is correct
56 Correct 4 ms 604 KB Output is correct
57 Correct 7 ms 716 KB Output is correct
58 Correct 19 ms 1784 KB Output is correct
59 Correct 19 ms 2816 KB Output is correct
60 Correct 121 ms 23160 KB Output is correct
61 Correct 171 ms 31140 KB Output is correct
62 Correct 213 ms 38052 KB Output is correct
63 Correct 283 ms 46236 KB Output is correct
64 Correct 3 ms 600 KB Output is correct
65 Correct 3 ms 348 KB Output is correct
66 Correct 3 ms 348 KB Output is correct
67 Correct 240 ms 41024 KB Output is correct
68 Correct 224 ms 41424 KB Output is correct
69 Correct 224 ms 40940 KB Output is correct
70 Correct 10 ms 1116 KB Output is correct
71 Correct 13 ms 1880 KB Output is correct
72 Correct 111 ms 20660 KB Output is correct
73 Correct 179 ms 30880 KB Output is correct
74 Correct 262 ms 41164 KB Output is correct
75 Correct 261 ms 44388 KB Output is correct
76 Correct 218 ms 41128 KB Output is correct
77 Correct 11 ms 1372 KB Output is correct
78 Correct 14 ms 2244 KB Output is correct
79 Correct 111 ms 21428 KB Output is correct
80 Correct 176 ms 32168 KB Output is correct
81 Correct 276 ms 42884 KB Output is correct
82 Incorrect 2 ms 348 KB Solution announced impossible, but it is possible.
83 Halted 0 ms 0 KB -