Submission #894854

# Submission time Handle Problem Language Result Execution time Memory
894854 2023-12-29T06:05:33 Z Ghulam_Junaid Fountain Parks (IOI21_parks) C++17
15 / 100
496 ms 65512 KB
#include <bits/stdc++.h>
// #include "grader.cpp"
using namespace std;

typedef pair<int, int> pii;

const int N = 2e5 + 10;
bool vis[N];
vector<int> g[N];

void dfs(int v){
    vis[v] = 1;
    for (int u : g[v])
        if (!vis[u]) dfs(u);
}

void build(vector<int> u, vector<int> v, vector<int> a, vector<int> b);
int construct_roads(vector<int> x, vector<int> y){
    int n = x.size();

    vector<int> edge[2], bench[2];
    vector<pii> vec;

    for (int i = 0; i < n; i ++)
        vec.push_back({x[i], y[i]});
    sort(vec.begin(), vec.end());

    map<pair<int, int>, int> ind;
    map<pair<int, int>, bool> done;
    for (int i=0; i<n; i++)
        ind[{x[i], y[i]}] = i;

    bool bad = 0;
    for (int i=0; i<n; i++){
        int px = vec[i].first;
        int py = vec[i].second;
        int cur = ind[{px, py}];

        if (ind.find({px, py + 2}) != ind.end()){
            edge[0].push_back(cur);
            edge[1].push_back(ind[{px, py + 2}]);
            g[cur].push_back(ind[{px, py + 2}]);
            g[ind[{px, py + 2}]].push_back(cur);

            if (!done[{px - 1, py + 1}]){
                done[{px - 1, py + 1}] = 1;
                bench[0].push_back(px - 1);
                bench[1].push_back(py + 1);
            }
            else if (!done[{px + 1, py + 1}]){
                done[{px + 1, py + 1}] = 1;
                bench[0].push_back(px + 1);
                bench[1].push_back(py + 1);
            }
            else
                bad = 1;
        }
        if (ind.find({px + 2, py}) != ind.end()){
            edge[0].push_back(cur);
            edge[1].push_back(ind[{px + 2, py}]);
            g[cur].push_back(ind[{px + 2, py}]);
            g[ind[{px + 2, py}]].push_back(cur);   

            if (!done[{px + 1, py - 1}]){
                done[{px + 1, py - 1}] = 1;
                bench[0].push_back(px + 1);
                bench[1].push_back(py - 1);
            }
            else if (!done[{px + 1, py + 1}]){
                done[{px + 1, py + 1}] = 1;
                bench[0].push_back(px + 1);
                bench[1].push_back(py + 1);
            }
            else
                bad = 1;
        }
    }

    dfs(0);

    for (int v = 0; v < n; v ++)
        if (!vis[v]) bad = 1;

    if (bad)
        return 0;

    build(edge[0], edge[1], bench[0], bench[1]);
    return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Correct 1 ms 4956 KB Output is correct
9 Correct 158 ms 30152 KB Output is correct
10 Correct 13 ms 7692 KB Output is correct
11 Correct 75 ms 18408 KB Output is correct
12 Correct 18 ms 8928 KB Output is correct
13 Correct 49 ms 14280 KB Output is correct
14 Correct 2 ms 5212 KB Output is correct
15 Correct 3 ms 5456 KB Output is correct
16 Correct 152 ms 29168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Correct 1 ms 4956 KB Output is correct
9 Correct 158 ms 30152 KB Output is correct
10 Correct 13 ms 7692 KB Output is correct
11 Correct 75 ms 18408 KB Output is correct
12 Correct 18 ms 8928 KB Output is correct
13 Correct 49 ms 14280 KB Output is correct
14 Correct 2 ms 5212 KB Output is correct
15 Correct 3 ms 5456 KB Output is correct
16 Correct 152 ms 29168 KB Output is correct
17 Correct 1 ms 4952 KB Output is correct
18 Correct 1 ms 4956 KB Output is correct
19 Correct 1 ms 4956 KB Output is correct
20 Correct 1 ms 4952 KB Output is correct
21 Correct 1 ms 4956 KB Output is correct
22 Correct 2 ms 4956 KB Output is correct
23 Correct 496 ms 65512 KB Output is correct
24 Correct 1 ms 4956 KB Output is correct
25 Correct 3 ms 5468 KB Output is correct
26 Correct 5 ms 5724 KB Output is correct
27 Correct 6 ms 5980 KB Output is correct
28 Correct 164 ms 30296 KB Output is correct
29 Correct 270 ms 41272 KB Output is correct
30 Correct 379 ms 55884 KB Output is correct
31 Correct 470 ms 65160 KB Output is correct
32 Correct 1 ms 4952 KB Output is correct
33 Correct 1 ms 4956 KB Output is correct
34 Correct 1 ms 4956 KB Output is correct
35 Correct 1 ms 4956 KB Output is correct
36 Correct 2 ms 4956 KB Output is correct
37 Correct 1 ms 4956 KB Output is correct
38 Correct 1 ms 4956 KB Output is correct
39 Correct 1 ms 4956 KB Output is correct
40 Correct 1 ms 4956 KB Output is correct
41 Correct 1 ms 4964 KB Output is correct
42 Correct 1 ms 4956 KB Output is correct
43 Correct 3 ms 5468 KB Output is correct
44 Correct 4 ms 5724 KB Output is correct
45 Correct 181 ms 29548 KB Output is correct
46 Correct 256 ms 40916 KB Output is correct
47 Correct 277 ms 41040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Correct 1 ms 4956 KB Output is correct
9 Correct 158 ms 30152 KB Output is correct
10 Correct 13 ms 7692 KB Output is correct
11 Correct 75 ms 18408 KB Output is correct
12 Correct 18 ms 8928 KB Output is correct
13 Correct 49 ms 14280 KB Output is correct
14 Correct 2 ms 5212 KB Output is correct
15 Correct 3 ms 5456 KB Output is correct
16 Correct 152 ms 29168 KB Output is correct
17 Correct 1 ms 4952 KB Output is correct
18 Correct 1 ms 4956 KB Output is correct
19 Correct 1 ms 4956 KB Output is correct
20 Correct 1 ms 4952 KB Output is correct
21 Correct 1 ms 4956 KB Output is correct
22 Correct 2 ms 4956 KB Output is correct
23 Correct 496 ms 65512 KB Output is correct
24 Correct 1 ms 4956 KB Output is correct
25 Correct 3 ms 5468 KB Output is correct
26 Correct 5 ms 5724 KB Output is correct
27 Correct 6 ms 5980 KB Output is correct
28 Correct 164 ms 30296 KB Output is correct
29 Correct 270 ms 41272 KB Output is correct
30 Correct 379 ms 55884 KB Output is correct
31 Correct 470 ms 65160 KB Output is correct
32 Correct 1 ms 4952 KB Output is correct
33 Correct 1 ms 4956 KB Output is correct
34 Correct 1 ms 4956 KB Output is correct
35 Correct 1 ms 4956 KB Output is correct
36 Correct 2 ms 4956 KB Output is correct
37 Correct 1 ms 4956 KB Output is correct
38 Correct 1 ms 4956 KB Output is correct
39 Correct 1 ms 4956 KB Output is correct
40 Correct 1 ms 4956 KB Output is correct
41 Correct 1 ms 4964 KB Output is correct
42 Correct 1 ms 4956 KB Output is correct
43 Correct 3 ms 5468 KB Output is correct
44 Correct 4 ms 5724 KB Output is correct
45 Correct 181 ms 29548 KB Output is correct
46 Correct 256 ms 40916 KB Output is correct
47 Correct 277 ms 41040 KB Output is correct
48 Correct 1 ms 4956 KB Output is correct
49 Correct 1 ms 4956 KB Output is correct
50 Correct 1 ms 4956 KB Output is correct
51 Correct 2 ms 5208 KB Output is correct
52 Correct 1 ms 4956 KB Output is correct
53 Incorrect 1 ms 4956 KB Solution announced impossible, but it is possible.
54 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Correct 1 ms 4956 KB Output is correct
9 Correct 158 ms 30152 KB Output is correct
10 Correct 13 ms 7692 KB Output is correct
11 Correct 75 ms 18408 KB Output is correct
12 Correct 18 ms 8928 KB Output is correct
13 Correct 49 ms 14280 KB Output is correct
14 Correct 2 ms 5212 KB Output is correct
15 Correct 3 ms 5456 KB Output is correct
16 Correct 152 ms 29168 KB Output is correct
17 Correct 1 ms 4956 KB Output is correct
18 Correct 1 ms 4956 KB Output is correct
19 Correct 1 ms 4956 KB Output is correct
20 Correct 389 ms 56356 KB Output is correct
21 Correct 382 ms 55468 KB Output is correct
22 Correct 395 ms 54900 KB Output is correct
23 Correct 293 ms 47208 KB Output is correct
24 Correct 178 ms 22212 KB Output is correct
25 Correct 311 ms 44652 KB Output is correct
26 Correct 285 ms 44484 KB Output is correct
27 Correct 354 ms 52112 KB Output is correct
28 Correct 393 ms 52064 KB Output is correct
29 Correct 392 ms 51968 KB Output is correct
30 Correct 376 ms 52116 KB Output is correct
31 Correct 1 ms 4952 KB Output is correct
32 Incorrect 18 ms 8024 KB Solution announced impossible, but it is possible.
33 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Correct 1 ms 4956 KB Output is correct
9 Correct 158 ms 30152 KB Output is correct
10 Correct 13 ms 7692 KB Output is correct
11 Correct 75 ms 18408 KB Output is correct
12 Correct 18 ms 8928 KB Output is correct
13 Correct 49 ms 14280 KB Output is correct
14 Correct 2 ms 5212 KB Output is correct
15 Correct 3 ms 5456 KB Output is correct
16 Correct 152 ms 29168 KB Output is correct
17 Correct 412 ms 55788 KB Output is correct
18 Correct 378 ms 55768 KB Output is correct
19 Incorrect 344 ms 48064 KB Solution announced impossible, but it is possible.
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Correct 1 ms 4956 KB Output is correct
9 Correct 158 ms 30152 KB Output is correct
10 Correct 13 ms 7692 KB Output is correct
11 Correct 75 ms 18408 KB Output is correct
12 Correct 18 ms 8928 KB Output is correct
13 Correct 49 ms 14280 KB Output is correct
14 Correct 2 ms 5212 KB Output is correct
15 Correct 3 ms 5456 KB Output is correct
16 Correct 152 ms 29168 KB Output is correct
17 Correct 1 ms 4952 KB Output is correct
18 Correct 1 ms 4956 KB Output is correct
19 Correct 1 ms 4956 KB Output is correct
20 Correct 1 ms 4952 KB Output is correct
21 Correct 1 ms 4956 KB Output is correct
22 Correct 2 ms 4956 KB Output is correct
23 Correct 496 ms 65512 KB Output is correct
24 Correct 1 ms 4956 KB Output is correct
25 Correct 3 ms 5468 KB Output is correct
26 Correct 5 ms 5724 KB Output is correct
27 Correct 6 ms 5980 KB Output is correct
28 Correct 164 ms 30296 KB Output is correct
29 Correct 270 ms 41272 KB Output is correct
30 Correct 379 ms 55884 KB Output is correct
31 Correct 470 ms 65160 KB Output is correct
32 Correct 1 ms 4952 KB Output is correct
33 Correct 1 ms 4956 KB Output is correct
34 Correct 1 ms 4956 KB Output is correct
35 Correct 1 ms 4956 KB Output is correct
36 Correct 2 ms 4956 KB Output is correct
37 Correct 1 ms 4956 KB Output is correct
38 Correct 1 ms 4956 KB Output is correct
39 Correct 1 ms 4956 KB Output is correct
40 Correct 1 ms 4956 KB Output is correct
41 Correct 1 ms 4964 KB Output is correct
42 Correct 1 ms 4956 KB Output is correct
43 Correct 3 ms 5468 KB Output is correct
44 Correct 4 ms 5724 KB Output is correct
45 Correct 181 ms 29548 KB Output is correct
46 Correct 256 ms 40916 KB Output is correct
47 Correct 277 ms 41040 KB Output is correct
48 Correct 1 ms 4956 KB Output is correct
49 Correct 1 ms 4956 KB Output is correct
50 Correct 1 ms 4956 KB Output is correct
51 Correct 2 ms 5208 KB Output is correct
52 Correct 1 ms 4956 KB Output is correct
53 Incorrect 1 ms 4956 KB Solution announced impossible, but it is possible.
54 Halted 0 ms 0 KB -