Submission #439829

# Submission time Handle Problem Language Result Execution time Memory
439829 2021-06-30T23:25:33 Z humbertoyusta Fountain Parks (IOI21_parks) C++17
45 / 100
733 ms 90296 KB
#include "parks.h"
#include<bits/stdc++.h>
#define f first
#define s second
#define ii pair<int,int>
using namespace std;
#define maxn 200010
#define db(x) cerr<<#x<<": "<<(x)<<"\n";

int mx[4] = { 0 , 2 , 0 , -2 };
int my[4] = { 2 , 0 , -2 , 0 };
int vis[maxn];
ii arr[maxn];
map<ii,int> mk;
vector<int> U, V, A, B;
map<ii,int> mp;

bool add_edge(int u,int v,int plus_){
    U.push_back(u);
    V.push_back(v);
    if( arr[u].f != arr[v].f ){
        if( mk[{(arr[u].f+arr[v].f)/2,arr[u].s + plus_}] ) return false;
        A.push_back( (arr[u].f+arr[v].f)/2 );
        B.push_back( arr[u].s + plus_ );
        mk[{(arr[u].f+arr[v].f)/2,arr[u].s + plus_}] = true;
    }
    else{
        if( mk[{arr[u].f + plus_,(arr[u].s+arr[v].s)/2}] ) return false;
        A.push_back( arr[u].f + plus_ );
        B.push_back( (arr[u].s+arr[v].s)/2 );
        mk[{arr[u].f + plus_,(arr[u].s+arr[v].s)/2}] = true;
    }
    return true;
}

void dfs(int u,int p,int plus_){
    vis[u] = 1;
    for(int i=0; i<4; i++){
        int nx = arr[u].f + mx[i];
        int ny = arr[u].s + my[i];
        if( mp[{nx,ny}] ){
            int v = mp[{nx,ny}] - 1;
            if( vis[v] ) continue;

            int gp = p / 2 * 2 + ( p + 1 ) % 2;
            int nplus = plus_;
            if( i != gp ) nplus *= -1;

            if( add_edge(u,v,nplus) )
                dfs(v,i,nplus);
        }
    }
}

int construct_roads(std::vector<int> x, std::vector<int> y) {
//    if (x.size() == 1) {
//        vector<int> pra;
//        build(pra, pra, pra, pra);
//        return 1;
//    }

    int n = x.size();

    pair<ii,int> st = { { 2000000007 , 2000000007 } , -1 };
    for(int i=0; i<n; i++){
        arr[i] = {x[i],y[i]};
        mp[{x[i],y[i]}] = i + 1;
        st = min( st , { arr[i] , i } );
    }

    int u = st.s;
    vis[u] = 1;
    for(int i=0; i<4; i++){
        int nx = arr[u].f + mx[i];
        int ny = arr[u].s + my[i];
        if( mp[{nx,ny}] ){
            int v = mp[{nx,ny}] - 1;
            if( vis[v] ) continue;
            int plus_ = ( i == 1 ) + ( i == 2 ) - ( i == 0 ) - ( i == 3 );
            if( add_edge(u,v,plus_) )
                dfs(v,i,plus_);
        }
    }

    for(int i=0; i<n; i++)
        if( vis[i] == 0 )
            return 0;

    build(U, V, A, B);
    return 1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 268 KB Output is correct
9 Correct 292 ms 45400 KB Output is correct
10 Correct 24 ms 4940 KB Output is correct
11 Correct 146 ms 24568 KB Output is correct
12 Correct 34 ms 7292 KB Output is correct
13 Correct 70 ms 14188 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 2 ms 588 KB Output is correct
16 Correct 294 ms 45312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 268 KB Output is correct
9 Correct 292 ms 45400 KB Output is correct
10 Correct 24 ms 4940 KB Output is correct
11 Correct 146 ms 24568 KB Output is correct
12 Correct 34 ms 7292 KB Output is correct
13 Correct 70 ms 14188 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 2 ms 588 KB Output is correct
16 Correct 294 ms 45312 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Incorrect 1 ms 204 KB Wrong answer detected in grader
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 268 KB Output is correct
9 Correct 292 ms 45400 KB Output is correct
10 Correct 24 ms 4940 KB Output is correct
11 Correct 146 ms 24568 KB Output is correct
12 Correct 34 ms 7292 KB Output is correct
13 Correct 70 ms 14188 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 2 ms 588 KB Output is correct
16 Correct 294 ms 45312 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Incorrect 1 ms 204 KB Wrong answer detected in grader
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 268 KB Output is correct
9 Correct 292 ms 45400 KB Output is correct
10 Correct 24 ms 4940 KB Output is correct
11 Correct 146 ms 24568 KB Output is correct
12 Correct 34 ms 7292 KB Output is correct
13 Correct 70 ms 14188 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 2 ms 588 KB Output is correct
16 Correct 294 ms 45312 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 573 ms 78308 KB Output is correct
21 Correct 658 ms 65648 KB Output is correct
22 Correct 670 ms 78000 KB Output is correct
23 Correct 572 ms 71928 KB Output is correct
24 Correct 224 ms 17484 KB Output is correct
25 Correct 164 ms 18244 KB Output is correct
26 Correct 203 ms 18508 KB Output is correct
27 Correct 519 ms 52964 KB Output is correct
28 Correct 529 ms 53012 KB Output is correct
29 Correct 697 ms 52892 KB Output is correct
30 Correct 733 ms 53064 KB Output is correct
31 Correct 1 ms 204 KB Output is correct
32 Correct 38 ms 5068 KB Output is correct
33 Correct 83 ms 8848 KB Output is correct
34 Correct 557 ms 78260 KB Output is correct
35 Correct 12 ms 1868 KB Output is correct
36 Correct 49 ms 6128 KB Output is correct
37 Correct 105 ms 10556 KB Output is correct
38 Correct 208 ms 19916 KB Output is correct
39 Correct 323 ms 27084 KB Output is correct
40 Correct 400 ms 34496 KB Output is correct
41 Correct 515 ms 41860 KB Output is correct
42 Correct 568 ms 49220 KB Output is correct
43 Correct 0 ms 204 KB Output is correct
44 Correct 1 ms 204 KB Output is correct
45 Correct 1 ms 204 KB Output is correct
46 Correct 1 ms 204 KB Output is correct
47 Correct 1 ms 204 KB Output is correct
48 Correct 0 ms 204 KB Output is correct
49 Correct 1 ms 204 KB Output is correct
50 Correct 1 ms 204 KB Output is correct
51 Correct 0 ms 204 KB Output is correct
52 Correct 1 ms 204 KB Output is correct
53 Correct 1 ms 204 KB Output is correct
54 Correct 2 ms 716 KB Output is correct
55 Correct 2 ms 716 KB Output is correct
56 Correct 270 ms 38940 KB Output is correct
57 Correct 436 ms 56216 KB Output is correct
58 Correct 430 ms 56132 KB Output is correct
59 Correct 1 ms 204 KB Output is correct
60 Correct 1 ms 204 KB Output is correct
61 Correct 1 ms 204 KB Output is correct
62 Correct 649 ms 84168 KB Output is correct
63 Correct 626 ms 71500 KB Output is correct
64 Correct 666 ms 77428 KB Output is correct
65 Correct 4 ms 1100 KB Output is correct
66 Correct 7 ms 1404 KB Output is correct
67 Correct 264 ms 34900 KB Output is correct
68 Correct 498 ms 52288 KB Output is correct
69 Correct 625 ms 69772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 268 KB Output is correct
9 Correct 292 ms 45400 KB Output is correct
10 Correct 24 ms 4940 KB Output is correct
11 Correct 146 ms 24568 KB Output is correct
12 Correct 34 ms 7292 KB Output is correct
13 Correct 70 ms 14188 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 2 ms 588 KB Output is correct
16 Correct 294 ms 45312 KB Output is correct
17 Correct 667 ms 90296 KB Output is correct
18 Correct 641 ms 84312 KB Output is correct
19 Correct 628 ms 78140 KB Output is correct
20 Correct 525 ms 59984 KB Output is correct
21 Correct 516 ms 62184 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 73 ms 9408 KB Output is correct
24 Correct 26 ms 3864 KB Output is correct
25 Correct 66 ms 8656 KB Output is correct
26 Correct 108 ms 13344 KB Output is correct
27 Correct 354 ms 30832 KB Output is correct
28 Correct 350 ms 38624 KB Output is correct
29 Correct 501 ms 46332 KB Output is correct
30 Correct 517 ms 53928 KB Output is correct
31 Correct 629 ms 61840 KB Output is correct
32 Correct 626 ms 72776 KB Output is correct
33 Correct 592 ms 84040 KB Output is correct
34 Correct 5 ms 1228 KB Output is correct
35 Correct 7 ms 1496 KB Output is correct
36 Correct 271 ms 33492 KB Output is correct
37 Correct 477 ms 50500 KB Output is correct
38 Correct 670 ms 66760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 268 KB Output is correct
9 Correct 292 ms 45400 KB Output is correct
10 Correct 24 ms 4940 KB Output is correct
11 Correct 146 ms 24568 KB Output is correct
12 Correct 34 ms 7292 KB Output is correct
13 Correct 70 ms 14188 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 2 ms 588 KB Output is correct
16 Correct 294 ms 45312 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Incorrect 1 ms 204 KB Wrong answer detected in grader
20 Halted 0 ms 0 KB -