Submission #436770

# Submission time Handle Problem Language Result Execution time Memory
436770 2021-06-24T20:59:48 Z PiejanVDC Fountain Parks (IOI21_parks) C++17
15 / 100
304 ms 31124 KB
#include "parks.h"
#include <bits/stdc++.h>
using namespace std;

int construct_roads(vector<int>x, vector<int> y) {
    vector<bool>used3(200005,false),used5(200005,false);
    vector<pair<int,int>>two,four,six;
    for(int i = 0 ; i < y.size() ; i++) {
        if(x[i] == 2) two.push_back({y[i],i});
        else if(x[i] == 4) four.push_back({y[i],i});
        else six.push_back({y[i],i});
    }
    vector<int>adj[x.size()];
    vector<int>u,v,a,b;
    sort(two.begin(),two.end());
    sort(four.begin(),four.end());
    sort(six.begin(),six.end());
    for(int i = 0 ; i < (int)two.size()-1 ; i++) {
        if(two[i+1].first-two[i].first == 2) {
            u.push_back(two[i].second);
            v.push_back(two[i+1].second);
            a.push_back(1);
            b.push_back(two[i].first+1);
            adj[two[i].second].push_back(two[i+1].second);
            adj[two[i+1].second].push_back(two[i].second);
        }
    }
    for(int i = 0 ; i < (int)four.size()-1 ; i++) {
        if(four[i+1].first-four[i].first == 2) {
            u.push_back(four[i].second);
            v.push_back(four[i+1].second);
            a.push_back(5);
            b.push_back(four[i].first+1);
            used5[four[i].first+1]=true;
            adj[four[i].second].push_back(four[i+1].second);
            adj[four[i+1].second].push_back(four[i].second);
        }
    }
    for(int i = 0 ; i < (int)six.size()-1 ; i++) {
        if(six[i+1].first-six[i].first == 2) {
            u.push_back(six[i].second);
            v.push_back(six[i+1].second);
            a.push_back(7);
            b.push_back(six[i].first+1);
            adj[six[i].second].push_back(six[i+1].second);
            adj[six[i+1].second].push_back(six[i].second);
        }
    }
    if((int)two.size() > 0 && (int)four.size() > 0) {
        for(int i = 0 ; i < two.size() ; i++) {
            int left=0,right=four.size()-1;
            while(left <= right) {
                int mid = (left+right)/2;
                if(four[mid].first == two[i].first) {
                    u.push_back(two[i].second);
                    v.push_back(four[mid].second);
                    a.push_back(3);
                    b.push_back(two[i].first+1);
                    used3[two[i].first+1]=true;
                    adj[two[i].second].push_back(four[mid].second);
                    adj[four[mid].second].push_back(two[i].second);
                    break;
                }
                if(four[mid].first < two[i].first) {
                    left=mid+1;
                } else {
                    right=mid-1;
                }
            }
        }
    }
    if((int)four.size() > 0 && (int)six.size() > 0) {
        for(int i = 0 ; i < four.size() ; i++) {
            int left=0,right=six.size()-1;
            while(left <= right) {
                int mid = (left+right)/2;
                if(six[mid].first == four[i].first) {
                    int c = used5[four[i].first+1]?-1:1;
                    u.push_back(four[i].second);
                    v.push_back(six[mid].second);
                    a.push_back(5);
                    b.push_back(four[i].first+c);
                    adj[four[i].second].push_back(six[mid].second);
                    adj[six[mid].second].push_back(four[i].second);
                    break;
                }
                if(six[mid].first < four[i].first) {
                    left=mid+1;
                } else {
                    right=mid-1;
                }
            }
        }
    }
    stack<int>s;
    s.push(0);
    vector<bool>vis(x.size(),false);
    while(!s.empty()) {
        int node = s.top();
        s.pop();
        vis[node]=true;
        for(auto z : adj[node]) {
            if(!vis[z]) s.push(z);
        }
    }
    bool f=true;
    for(auto z : vis) {
        if(!z) {
            f=false; break;
        }
    }
    if(f) {
        build(u,v,a,b);
        return 1;
    }
    return 0;
}

Compilation message

parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:8:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |     for(int i = 0 ; i < y.size() ; i++) {
      |                     ~~^~~~~~~~~~
parks.cpp:50:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         for(int i = 0 ; i < two.size() ; i++) {
      |                         ~~^~~~~~~~~~~~
parks.cpp:73:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |         for(int i = 0 ; i < four.size() ; i++) {
      |                         ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 90 ms 13360 KB Output is correct
10 Correct 8 ms 1660 KB Output is correct
11 Correct 41 ms 7404 KB Output is correct
12 Correct 11 ms 2508 KB Output is correct
13 Correct 17 ms 4612 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 93 ms 13360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 90 ms 13360 KB Output is correct
10 Correct 8 ms 1660 KB Output is correct
11 Correct 41 ms 7404 KB Output is correct
12 Correct 11 ms 2508 KB Output is correct
13 Correct 17 ms 4612 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 93 ms 13360 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 304 ms 31124 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 2 ms 460 KB Output is correct
26 Correct 2 ms 588 KB Output is correct
27 Correct 3 ms 716 KB Output is correct
28 Correct 105 ms 12412 KB Output is correct
29 Correct 158 ms 18716 KB Output is correct
30 Correct 224 ms 24492 KB Output is correct
31 Correct 304 ms 31012 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 2 ms 460 KB Output is correct
44 Correct 2 ms 588 KB Output is correct
45 Correct 102 ms 12964 KB Output is correct
46 Correct 159 ms 19684 KB Output is correct
47 Correct 160 ms 19660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 90 ms 13360 KB Output is correct
10 Correct 8 ms 1660 KB Output is correct
11 Correct 41 ms 7404 KB Output is correct
12 Correct 11 ms 2508 KB Output is correct
13 Correct 17 ms 4612 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 93 ms 13360 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 304 ms 31124 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 2 ms 460 KB Output is correct
26 Correct 2 ms 588 KB Output is correct
27 Correct 3 ms 716 KB Output is correct
28 Correct 105 ms 12412 KB Output is correct
29 Correct 158 ms 18716 KB Output is correct
30 Correct 224 ms 24492 KB Output is correct
31 Correct 304 ms 31012 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 2 ms 460 KB Output is correct
44 Correct 2 ms 588 KB Output is correct
45 Correct 102 ms 12964 KB Output is correct
46 Correct 159 ms 19684 KB Output is correct
47 Correct 160 ms 19660 KB Output is correct
48 Correct 1 ms 332 KB Output is correct
49 Correct 1 ms 332 KB Output is correct
50 Correct 1 ms 332 KB Output is correct
51 Incorrect 1 ms 332 KB Tree @(5, 3) appears more than once: for edges on positions 1 and 6
52 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 90 ms 13360 KB Output is correct
10 Correct 8 ms 1660 KB Output is correct
11 Correct 41 ms 7404 KB Output is correct
12 Correct 11 ms 2508 KB Output is correct
13 Correct 17 ms 4612 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 93 ms 13360 KB Output is correct
17 Incorrect 1 ms 432 KB Solution announced impossible, but it is possible.
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 90 ms 13360 KB Output is correct
10 Correct 8 ms 1660 KB Output is correct
11 Correct 41 ms 7404 KB Output is correct
12 Correct 11 ms 2508 KB Output is correct
13 Correct 17 ms 4612 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 93 ms 13360 KB Output is correct
17 Incorrect 103 ms 14504 KB Solution announced impossible, but it is possible.
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 90 ms 13360 KB Output is correct
10 Correct 8 ms 1660 KB Output is correct
11 Correct 41 ms 7404 KB Output is correct
12 Correct 11 ms 2508 KB Output is correct
13 Correct 17 ms 4612 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 93 ms 13360 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 304 ms 31124 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 2 ms 460 KB Output is correct
26 Correct 2 ms 588 KB Output is correct
27 Correct 3 ms 716 KB Output is correct
28 Correct 105 ms 12412 KB Output is correct
29 Correct 158 ms 18716 KB Output is correct
30 Correct 224 ms 24492 KB Output is correct
31 Correct 304 ms 31012 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 2 ms 460 KB Output is correct
44 Correct 2 ms 588 KB Output is correct
45 Correct 102 ms 12964 KB Output is correct
46 Correct 159 ms 19684 KB Output is correct
47 Correct 160 ms 19660 KB Output is correct
48 Correct 1 ms 332 KB Output is correct
49 Correct 1 ms 332 KB Output is correct
50 Correct 1 ms 332 KB Output is correct
51 Incorrect 1 ms 332 KB Tree @(5, 3) appears more than once: for edges on positions 1 and 6
52 Halted 0 ms 0 KB -