Submission #896271

# Submission time Handle Problem Language Result Execution time Memory
896271 2024-01-01T07:09:19 Z abcvuitunggio Fountain Parks (IOI21_parks) C++17
55 / 100
1742 ms 190632 KB
#include "parks.h"
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF=1e17;
struct Edge{
    int u,v,c;
    Edge(){};
    Edge (int u, int v, int c){
        this->u=u;
        this->v=v;
        this->c=c;
    }
};
struct Dinic{
    vector <Edge> s;
    vector <vector <int>> adj;
    vector <vector <int> :: iterator> cur;
    vector <int> h;
    int n, sink, source;
    void Reset(){
        s.clear();
        adj.clear();
        cur.clear();
        h.clear();
    }
    void Assign(int n){
        this->n=n;
        s.reserve(n+2);
        adj.resize(n+2);
        cur.resize(n+2);
        h.resize(n+2);
    }
    void AddEdge(int u, int v, int c){
        s.emplace_back(u,v,c);
        adj[u].emplace_back(s.size()-1);
        s.emplace_back(v,u,0);
        adj[v].emplace_back(s.size()-1);
    }
    bool bfs(){
        fill(h.begin(),h.end(),n+2);
        queue <int> q({sink});
        h[sink]=0;
        while (!q.empty()){
            int c=q.front();
            q.pop();
            for (int i:adj[c])
                if (h[s[i].v]==n+2&&s[i^1].c){
                    h[s[i].v]=h[c]+1;
                    if (s[i].v==source)
                        return true;
                    q.emplace(s[i].v);
                }
        }
        return false;
    }
    int dfs(int v, int flowin){
        if (v==sink)
            return flowin;
        int flowout=0;
        for (;cur[v]!=adj[v].end();++cur[v]){
            int i=*cur[v];
            if (!s[i].c||h[s[i].v]+1!=h[v])
                continue;
            int q=dfs(s[i].v,min(flowin,s[i].c));
            flowout+=q;
            if (flowin!=INF)
                flowin-=q;
            s[i].c-=q;
            s[i^1].c+=q;
            if (!flowin)
                break;
        }
        return flowout;
    }
    int BlockFlow(){
        for (int i=1;i<=n;i++)
            cur[i]=adj[i].begin();
        return dfs(source,INF);
    }
    int MaxFlow(int s, int t){
        source=s;
        sink=t;
        int res=0;
        while (bfs())
            res+=BlockFlow();
        return res;
    }
}g;
int n,dx[4]={1,-1,0,0},dy[4]={0,0,1,-1},p[200001],id;
pair <int, int> bench[400001];
map <int, int> mp[300001],mp2[300001];
int f(int i){
    return (p[i]==i?i:p[i]=f(p[i]));
}
bool unite(int i, int j){
    i=f(i);
    j=f(j);
    if (i==j)
        return false;
    p[j]=i;
    return true;
}
int32_t construct_roads(vector <int32_t> x, vector <int32_t> y) {
    if (x.size()==1){
        build({},{},{},{});
        return 1;
    }
    vector <int32_t> u,v,a,b;
    n=x.size();
    for (int i=0;i<n;i++)
        mp[x[i]][y[i]]=i;
    iota(p,p+n,0);
    g.Assign(n*3);
    for (int i=0;i<n;i++)
        for (int j=0;j<4;j++)
            if (mp[x[i]+dx[j]*2].count(y[i]+dy[j]*2)){
                int k=mp[x[i]+dx[j]*2][y[i]+dy[j]*2];
                if (unite(i,k)){
                    u.push_back(i);
                    v.push_back(k);
                    g.AddEdge(n*3-1,u.size(),1);
                    int X=x[i]+dx[j],Y=y[i]+dy[j];
                    for (int l=0;l<4;l++)
                        if (X+dx[l]!=x[i]&&Y+dy[l]!=y[i]){
                            if (!mp[X+dx[l]].count(Y+dy[l])){
                                id++;
                                mp[X+dx[l]][Y+dy[l]]=id;
                                bench[id]={X+dx[l],Y+dy[l]};
                                g.AddEdge(id+n-1,n*3,1);
                            }
                            g.AddEdge(u.size(),mp[X+dx[l]][Y+dy[l]]+n-1,1);
                        }
                }
            }
    if (u.size()<n-1)
        return 0;
    a.assign(n-1,0);
    b.assign(n-1,0);
    int mx=g.MaxFlow(n*3-1,n*3);
    if (mx<n-1)
        return 0;
    for (int i=0;i<g.s.size();i+=2)
        if (!g.s[i].c&&g.s[i].u!=n*3-1&&g.s[i].v!=n*3){
            a[g.s[i].u-1]=bench[g.s[i].v-n+1].first;
            b[g.s[i].u-1]=bench[g.s[i].v-n+1].second;
        }
    build(u,v,a,b);
    return 1;
}

Compilation message

parks.cpp: In function 'int32_t construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:136:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
  136 |     if (u.size()<n-1)
      |         ~~~~~~~~^~~~
parks.cpp:143:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<Edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  143 |     for (int i=0;i<g.s.size();i+=2)
      |                  ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 29272 KB Output is correct
2 Correct 6 ms 31324 KB Output is correct
3 Correct 6 ms 31320 KB Output is correct
4 Correct 6 ms 31324 KB Output is correct
5 Correct 6 ms 31324 KB Output is correct
6 Correct 6 ms 31324 KB Output is correct
7 Correct 7 ms 31324 KB Output is correct
8 Correct 6 ms 31324 KB Output is correct
9 Correct 419 ms 112476 KB Output is correct
10 Correct 25 ms 38940 KB Output is correct
11 Correct 127 ms 75920 KB Output is correct
12 Correct 36 ms 42740 KB Output is correct
13 Correct 85 ms 64732 KB Output is correct
14 Correct 8 ms 31984 KB Output is correct
15 Correct 11 ms 32688 KB Output is correct
16 Correct 404 ms 112432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 29272 KB Output is correct
2 Correct 6 ms 31324 KB Output is correct
3 Correct 6 ms 31320 KB Output is correct
4 Correct 6 ms 31324 KB Output is correct
5 Correct 6 ms 31324 KB Output is correct
6 Correct 6 ms 31324 KB Output is correct
7 Correct 7 ms 31324 KB Output is correct
8 Correct 6 ms 31324 KB Output is correct
9 Correct 419 ms 112476 KB Output is correct
10 Correct 25 ms 38940 KB Output is correct
11 Correct 127 ms 75920 KB Output is correct
12 Correct 36 ms 42740 KB Output is correct
13 Correct 85 ms 64732 KB Output is correct
14 Correct 8 ms 31984 KB Output is correct
15 Correct 11 ms 32688 KB Output is correct
16 Correct 404 ms 112432 KB Output is correct
17 Correct 6 ms 31320 KB Output is correct
18 Correct 6 ms 31324 KB Output is correct
19 Correct 6 ms 31324 KB Output is correct
20 Correct 6 ms 31324 KB Output is correct
21 Correct 6 ms 31324 KB Output is correct
22 Correct 6 ms 31324 KB Output is correct
23 Correct 1583 ms 163468 KB Output is correct
24 Correct 8 ms 31324 KB Output is correct
25 Correct 10 ms 32180 KB Output is correct
26 Correct 13 ms 33172 KB Output is correct
27 Correct 14 ms 33856 KB Output is correct
28 Correct 419 ms 85956 KB Output is correct
29 Correct 815 ms 111432 KB Output is correct
30 Correct 1103 ms 138184 KB Output is correct
31 Correct 1516 ms 164536 KB Output is correct
32 Correct 7 ms 31324 KB Output is correct
33 Correct 6 ms 31324 KB Output is correct
34 Correct 6 ms 31324 KB Output is correct
35 Correct 6 ms 31324 KB Output is correct
36 Correct 6 ms 31324 KB Output is correct
37 Correct 6 ms 31324 KB Output is correct
38 Correct 6 ms 31320 KB Output is correct
39 Correct 6 ms 31324 KB Output is correct
40 Correct 6 ms 31324 KB Output is correct
41 Correct 7 ms 31320 KB Output is correct
42 Correct 7 ms 31324 KB Output is correct
43 Correct 10 ms 32460 KB Output is correct
44 Correct 12 ms 33276 KB Output is correct
45 Correct 509 ms 101308 KB Output is correct
46 Correct 825 ms 134776 KB Output is correct
47 Correct 822 ms 135440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 29272 KB Output is correct
2 Correct 6 ms 31324 KB Output is correct
3 Correct 6 ms 31320 KB Output is correct
4 Correct 6 ms 31324 KB Output is correct
5 Correct 6 ms 31324 KB Output is correct
6 Correct 6 ms 31324 KB Output is correct
7 Correct 7 ms 31324 KB Output is correct
8 Correct 6 ms 31324 KB Output is correct
9 Correct 419 ms 112476 KB Output is correct
10 Correct 25 ms 38940 KB Output is correct
11 Correct 127 ms 75920 KB Output is correct
12 Correct 36 ms 42740 KB Output is correct
13 Correct 85 ms 64732 KB Output is correct
14 Correct 8 ms 31984 KB Output is correct
15 Correct 11 ms 32688 KB Output is correct
16 Correct 404 ms 112432 KB Output is correct
17 Correct 6 ms 31320 KB Output is correct
18 Correct 6 ms 31324 KB Output is correct
19 Correct 6 ms 31324 KB Output is correct
20 Correct 6 ms 31324 KB Output is correct
21 Correct 6 ms 31324 KB Output is correct
22 Correct 6 ms 31324 KB Output is correct
23 Correct 1583 ms 163468 KB Output is correct
24 Correct 8 ms 31324 KB Output is correct
25 Correct 10 ms 32180 KB Output is correct
26 Correct 13 ms 33172 KB Output is correct
27 Correct 14 ms 33856 KB Output is correct
28 Correct 419 ms 85956 KB Output is correct
29 Correct 815 ms 111432 KB Output is correct
30 Correct 1103 ms 138184 KB Output is correct
31 Correct 1516 ms 164536 KB Output is correct
32 Correct 7 ms 31324 KB Output is correct
33 Correct 6 ms 31324 KB Output is correct
34 Correct 6 ms 31324 KB Output is correct
35 Correct 6 ms 31324 KB Output is correct
36 Correct 6 ms 31324 KB Output is correct
37 Correct 6 ms 31324 KB Output is correct
38 Correct 6 ms 31320 KB Output is correct
39 Correct 6 ms 31324 KB Output is correct
40 Correct 6 ms 31324 KB Output is correct
41 Correct 7 ms 31320 KB Output is correct
42 Correct 7 ms 31324 KB Output is correct
43 Correct 10 ms 32460 KB Output is correct
44 Correct 12 ms 33276 KB Output is correct
45 Correct 509 ms 101308 KB Output is correct
46 Correct 825 ms 134776 KB Output is correct
47 Correct 822 ms 135440 KB Output is correct
48 Correct 6 ms 31324 KB Output is correct
49 Correct 6 ms 31324 KB Output is correct
50 Correct 7 ms 31184 KB Output is correct
51 Correct 7 ms 31324 KB Output is correct
52 Correct 7 ms 31324 KB Output is correct
53 Correct 7 ms 31168 KB Output is correct
54 Correct 6 ms 31344 KB Output is correct
55 Incorrect 1540 ms 158728 KB Solution announced impossible, but it is possible.
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 29272 KB Output is correct
2 Correct 6 ms 31324 KB Output is correct
3 Correct 6 ms 31320 KB Output is correct
4 Correct 6 ms 31324 KB Output is correct
5 Correct 6 ms 31324 KB Output is correct
6 Correct 6 ms 31324 KB Output is correct
7 Correct 7 ms 31324 KB Output is correct
8 Correct 6 ms 31324 KB Output is correct
9 Correct 419 ms 112476 KB Output is correct
10 Correct 25 ms 38940 KB Output is correct
11 Correct 127 ms 75920 KB Output is correct
12 Correct 36 ms 42740 KB Output is correct
13 Correct 85 ms 64732 KB Output is correct
14 Correct 8 ms 31984 KB Output is correct
15 Correct 11 ms 32688 KB Output is correct
16 Correct 404 ms 112432 KB Output is correct
17 Correct 7 ms 31324 KB Output is correct
18 Correct 6 ms 31324 KB Output is correct
19 Correct 6 ms 31324 KB Output is correct
20 Correct 1398 ms 164084 KB Output is correct
21 Correct 651 ms 165480 KB Output is correct
22 Correct 1371 ms 163112 KB Output is correct
23 Correct 576 ms 165936 KB Output is correct
24 Correct 180 ms 72276 KB Output is correct
25 Correct 809 ms 177812 KB Output is correct
26 Correct 735 ms 177848 KB Output is correct
27 Correct 845 ms 188728 KB Output is correct
28 Correct 842 ms 188836 KB Output is correct
29 Correct 975 ms 188792 KB Output is correct
30 Correct 944 ms 188084 KB Output is correct
31 Correct 6 ms 31324 KB Output is correct
32 Correct 43 ms 42240 KB Output is correct
33 Correct 58 ms 51900 KB Output is correct
34 Correct 660 ms 165060 KB Output is correct
35 Correct 23 ms 38808 KB Output is correct
36 Correct 110 ms 65292 KB Output is correct
37 Correct 279 ms 98376 KB Output is correct
38 Correct 569 ms 87508 KB Output is correct
39 Correct 910 ms 106156 KB Output is correct
40 Correct 1039 ms 128012 KB Output is correct
41 Correct 1481 ms 149484 KB Output is correct
42 Correct 1514 ms 169684 KB Output is correct
43 Correct 6 ms 31320 KB Output is correct
44 Correct 6 ms 31156 KB Output is correct
45 Correct 6 ms 31324 KB Output is correct
46 Correct 7 ms 31376 KB Output is correct
47 Correct 6 ms 31576 KB Output is correct
48 Correct 6 ms 31320 KB Output is correct
49 Correct 7 ms 31324 KB Output is correct
50 Correct 6 ms 31324 KB Output is correct
51 Correct 6 ms 31376 KB Output is correct
52 Correct 6 ms 31576 KB Output is correct
53 Correct 6 ms 31324 KB Output is correct
54 Correct 11 ms 32460 KB Output is correct
55 Correct 13 ms 33252 KB Output is correct
56 Correct 498 ms 104220 KB Output is correct
57 Correct 791 ms 134272 KB Output is correct
58 Correct 838 ms 134068 KB Output is correct
59 Correct 6 ms 31324 KB Output is correct
60 Correct 7 ms 31320 KB Output is correct
61 Correct 6 ms 31324 KB Output is correct
62 Correct 936 ms 188420 KB Output is correct
63 Correct 916 ms 190632 KB Output is correct
64 Correct 881 ms 188824 KB Output is correct
65 Correct 15 ms 33860 KB Output is correct
66 Correct 23 ms 36392 KB Output is correct
67 Correct 662 ms 101504 KB Output is correct
68 Correct 1142 ms 138180 KB Output is correct
69 Correct 1726 ms 172500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 29272 KB Output is correct
2 Correct 6 ms 31324 KB Output is correct
3 Correct 6 ms 31320 KB Output is correct
4 Correct 6 ms 31324 KB Output is correct
5 Correct 6 ms 31324 KB Output is correct
6 Correct 6 ms 31324 KB Output is correct
7 Correct 7 ms 31324 KB Output is correct
8 Correct 6 ms 31324 KB Output is correct
9 Correct 419 ms 112476 KB Output is correct
10 Correct 25 ms 38940 KB Output is correct
11 Correct 127 ms 75920 KB Output is correct
12 Correct 36 ms 42740 KB Output is correct
13 Correct 85 ms 64732 KB Output is correct
14 Correct 8 ms 31984 KB Output is correct
15 Correct 11 ms 32688 KB Output is correct
16 Correct 404 ms 112432 KB Output is correct
17 Correct 721 ms 188180 KB Output is correct
18 Correct 756 ms 189944 KB Output is correct
19 Correct 1216 ms 167240 KB Output is correct
20 Correct 997 ms 164624 KB Output is correct
21 Correct 848 ms 161496 KB Output is correct
22 Correct 6 ms 31324 KB Output is correct
23 Correct 139 ms 53704 KB Output is correct
24 Correct 41 ms 45900 KB Output is correct
25 Correct 171 ms 78596 KB Output is correct
26 Correct 370 ms 110384 KB Output is correct
27 Correct 742 ms 100884 KB Output is correct
28 Correct 837 ms 118104 KB Output is correct
29 Correct 1074 ms 136096 KB Output is correct
30 Correct 1287 ms 153068 KB Output is correct
31 Correct 1742 ms 170012 KB Output is correct
32 Correct 1224 ms 174628 KB Output is correct
33 Correct 936 ms 188672 KB Output is correct
34 Correct 16 ms 34552 KB Output is correct
35 Correct 25 ms 37084 KB Output is correct
36 Correct 622 ms 102024 KB Output is correct
37 Correct 1125 ms 139036 KB Output is correct
38 Correct 1673 ms 171432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 29272 KB Output is correct
2 Correct 6 ms 31324 KB Output is correct
3 Correct 6 ms 31320 KB Output is correct
4 Correct 6 ms 31324 KB Output is correct
5 Correct 6 ms 31324 KB Output is correct
6 Correct 6 ms 31324 KB Output is correct
7 Correct 7 ms 31324 KB Output is correct
8 Correct 6 ms 31324 KB Output is correct
9 Correct 419 ms 112476 KB Output is correct
10 Correct 25 ms 38940 KB Output is correct
11 Correct 127 ms 75920 KB Output is correct
12 Correct 36 ms 42740 KB Output is correct
13 Correct 85 ms 64732 KB Output is correct
14 Correct 8 ms 31984 KB Output is correct
15 Correct 11 ms 32688 KB Output is correct
16 Correct 404 ms 112432 KB Output is correct
17 Correct 6 ms 31320 KB Output is correct
18 Correct 6 ms 31324 KB Output is correct
19 Correct 6 ms 31324 KB Output is correct
20 Correct 6 ms 31324 KB Output is correct
21 Correct 6 ms 31324 KB Output is correct
22 Correct 6 ms 31324 KB Output is correct
23 Correct 1583 ms 163468 KB Output is correct
24 Correct 8 ms 31324 KB Output is correct
25 Correct 10 ms 32180 KB Output is correct
26 Correct 13 ms 33172 KB Output is correct
27 Correct 14 ms 33856 KB Output is correct
28 Correct 419 ms 85956 KB Output is correct
29 Correct 815 ms 111432 KB Output is correct
30 Correct 1103 ms 138184 KB Output is correct
31 Correct 1516 ms 164536 KB Output is correct
32 Correct 7 ms 31324 KB Output is correct
33 Correct 6 ms 31324 KB Output is correct
34 Correct 6 ms 31324 KB Output is correct
35 Correct 6 ms 31324 KB Output is correct
36 Correct 6 ms 31324 KB Output is correct
37 Correct 6 ms 31324 KB Output is correct
38 Correct 6 ms 31320 KB Output is correct
39 Correct 6 ms 31324 KB Output is correct
40 Correct 6 ms 31324 KB Output is correct
41 Correct 7 ms 31320 KB Output is correct
42 Correct 7 ms 31324 KB Output is correct
43 Correct 10 ms 32460 KB Output is correct
44 Correct 12 ms 33276 KB Output is correct
45 Correct 509 ms 101308 KB Output is correct
46 Correct 825 ms 134776 KB Output is correct
47 Correct 822 ms 135440 KB Output is correct
48 Correct 6 ms 31324 KB Output is correct
49 Correct 6 ms 31324 KB Output is correct
50 Correct 7 ms 31184 KB Output is correct
51 Correct 7 ms 31324 KB Output is correct
52 Correct 7 ms 31324 KB Output is correct
53 Correct 7 ms 31168 KB Output is correct
54 Correct 6 ms 31344 KB Output is correct
55 Incorrect 1540 ms 158728 KB Solution announced impossible, but it is possible.
56 Halted 0 ms 0 KB -