Submission #896267

# Submission time Handle Problem Language Result Execution time Memory
896267 2024-01-01T07:00:18 Z abcvuitunggio Fountain Parks (IOI21_parks) C++17
55 / 100
1669 ms 190040 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+10);
    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+5,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])){
                                mp[X+dx[l]][Y+dy[l]]=++id;
                                bench[id]={X+dx[l],Y+dy[l]};
                                g.AddEdge(id+n-1,n*3+6,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+5,n*3+6);
    for (int i=0;i<g.s.size();i+=2)
        if (!g.s[i].c&&g.s[i].u!=n*3+5&&g.s[i].v!=n*3+6){
            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:135:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
  135 |     if (u.size()<n-1)
      |         ~~~~~~~~^~~~
parks.cpp:140:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<Edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  140 |     for (int i=0;i<g.s.size();i+=2)
      |                  ~^~~~~~~~~~~
parks.cpp:139:9: warning: unused variable 'mx' [-Wunused-variable]
  139 |     int mx=g.MaxFlow(n*3+5,n*3+6);
      |         ^~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 29272 KB Output is correct
2 Correct 6 ms 31324 KB Output is correct
3 Correct 6 ms 31352 KB Output is correct
4 Correct 6 ms 31324 KB Output is correct
5 Correct 6 ms 31320 KB Output is correct
6 Correct 7 ms 31324 KB Output is correct
7 Correct 6 ms 31324 KB Output is correct
8 Correct 6 ms 31324 KB Output is correct
9 Correct 411 ms 111048 KB Output is correct
10 Correct 27 ms 38936 KB Output is correct
11 Correct 128 ms 75576 KB Output is correct
12 Correct 34 ms 42996 KB Output is correct
13 Correct 84 ms 64220 KB Output is correct
14 Correct 8 ms 31948 KB Output is correct
15 Correct 10 ms 32728 KB Output is correct
16 Correct 379 ms 112048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 29272 KB Output is correct
2 Correct 6 ms 31324 KB Output is correct
3 Correct 6 ms 31352 KB Output is correct
4 Correct 6 ms 31324 KB Output is correct
5 Correct 6 ms 31320 KB Output is correct
6 Correct 7 ms 31324 KB Output is correct
7 Correct 6 ms 31324 KB Output is correct
8 Correct 6 ms 31324 KB Output is correct
9 Correct 411 ms 111048 KB Output is correct
10 Correct 27 ms 38936 KB Output is correct
11 Correct 128 ms 75576 KB Output is correct
12 Correct 34 ms 42996 KB Output is correct
13 Correct 84 ms 64220 KB Output is correct
14 Correct 8 ms 31948 KB Output is correct
15 Correct 10 ms 32728 KB Output is correct
16 Correct 379 ms 112048 KB Output is correct
17 Correct 7 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 7 ms 31172 KB Output is correct
21 Correct 6 ms 31324 KB Output is correct
22 Correct 6 ms 31324 KB Output is correct
23 Correct 1401 ms 165196 KB Output is correct
24 Correct 6 ms 31320 KB Output is correct
25 Correct 9 ms 32092 KB Output is correct
26 Correct 12 ms 33160 KB Output is correct
27 Correct 14 ms 33856 KB Output is correct
28 Correct 421 ms 85044 KB Output is correct
29 Correct 790 ms 112920 KB Output is correct
30 Correct 1031 ms 139088 KB Output is correct
31 Correct 1457 ms 165600 KB Output is correct
32 Correct 7 ms 31320 KB Output is correct
33 Correct 6 ms 31320 KB Output is correct
34 Correct 7 ms 31320 KB Output is correct
35 Correct 7 ms 31384 KB Output is correct
36 Correct 7 ms 31324 KB Output is correct
37 Correct 6 ms 31324 KB Output is correct
38 Correct 6 ms 31324 KB Output is correct
39 Correct 6 ms 31324 KB Output is correct
40 Correct 6 ms 31360 KB Output is correct
41 Correct 6 ms 31320 KB Output is correct
42 Correct 6 ms 31192 KB Output is correct
43 Correct 9 ms 32460 KB Output is correct
44 Correct 12 ms 33248 KB Output is correct
45 Correct 469 ms 101776 KB Output is correct
46 Correct 791 ms 136256 KB Output is correct
47 Correct 785 ms 135812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 29272 KB Output is correct
2 Correct 6 ms 31324 KB Output is correct
3 Correct 6 ms 31352 KB Output is correct
4 Correct 6 ms 31324 KB Output is correct
5 Correct 6 ms 31320 KB Output is correct
6 Correct 7 ms 31324 KB Output is correct
7 Correct 6 ms 31324 KB Output is correct
8 Correct 6 ms 31324 KB Output is correct
9 Correct 411 ms 111048 KB Output is correct
10 Correct 27 ms 38936 KB Output is correct
11 Correct 128 ms 75576 KB Output is correct
12 Correct 34 ms 42996 KB Output is correct
13 Correct 84 ms 64220 KB Output is correct
14 Correct 8 ms 31948 KB Output is correct
15 Correct 10 ms 32728 KB Output is correct
16 Correct 379 ms 112048 KB Output is correct
17 Correct 7 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 7 ms 31172 KB Output is correct
21 Correct 6 ms 31324 KB Output is correct
22 Correct 6 ms 31324 KB Output is correct
23 Correct 1401 ms 165196 KB Output is correct
24 Correct 6 ms 31320 KB Output is correct
25 Correct 9 ms 32092 KB Output is correct
26 Correct 12 ms 33160 KB Output is correct
27 Correct 14 ms 33856 KB Output is correct
28 Correct 421 ms 85044 KB Output is correct
29 Correct 790 ms 112920 KB Output is correct
30 Correct 1031 ms 139088 KB Output is correct
31 Correct 1457 ms 165600 KB Output is correct
32 Correct 7 ms 31320 KB Output is correct
33 Correct 6 ms 31320 KB Output is correct
34 Correct 7 ms 31320 KB Output is correct
35 Correct 7 ms 31384 KB Output is correct
36 Correct 7 ms 31324 KB Output is correct
37 Correct 6 ms 31324 KB Output is correct
38 Correct 6 ms 31324 KB Output is correct
39 Correct 6 ms 31324 KB Output is correct
40 Correct 6 ms 31360 KB Output is correct
41 Correct 6 ms 31320 KB Output is correct
42 Correct 6 ms 31192 KB Output is correct
43 Correct 9 ms 32460 KB Output is correct
44 Correct 12 ms 33248 KB Output is correct
45 Correct 469 ms 101776 KB Output is correct
46 Correct 791 ms 136256 KB Output is correct
47 Correct 785 ms 135812 KB Output is correct
48 Correct 6 ms 31324 KB Output is correct
49 Correct 6 ms 31320 KB Output is correct
50 Correct 6 ms 31324 KB Output is correct
51 Correct 6 ms 31180 KB Output is correct
52 Correct 6 ms 31576 KB Output is correct
53 Correct 7 ms 31360 KB Output is correct
54 Correct 6 ms 31324 KB Output is correct
55 Incorrect 1498 ms 163372 KB a[33] = 0 is not an odd integer
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 29272 KB Output is correct
2 Correct 6 ms 31324 KB Output is correct
3 Correct 6 ms 31352 KB Output is correct
4 Correct 6 ms 31324 KB Output is correct
5 Correct 6 ms 31320 KB Output is correct
6 Correct 7 ms 31324 KB Output is correct
7 Correct 6 ms 31324 KB Output is correct
8 Correct 6 ms 31324 KB Output is correct
9 Correct 411 ms 111048 KB Output is correct
10 Correct 27 ms 38936 KB Output is correct
11 Correct 128 ms 75576 KB Output is correct
12 Correct 34 ms 42996 KB Output is correct
13 Correct 84 ms 64220 KB Output is correct
14 Correct 8 ms 31948 KB Output is correct
15 Correct 10 ms 32728 KB Output is correct
16 Correct 379 ms 112048 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 1316 ms 165532 KB Output is correct
21 Correct 607 ms 165828 KB Output is correct
22 Correct 1318 ms 165268 KB Output is correct
23 Correct 549 ms 166528 KB Output is correct
24 Correct 166 ms 73192 KB Output is correct
25 Correct 794 ms 178272 KB Output is correct
26 Correct 650 ms 179080 KB Output is correct
27 Correct 782 ms 188980 KB Output is correct
28 Correct 781 ms 189652 KB Output is correct
29 Correct 861 ms 189444 KB Output is correct
30 Correct 872 ms 188660 KB Output is correct
31 Correct 7 ms 31580 KB Output is correct
32 Correct 41 ms 41656 KB Output is correct
33 Correct 51 ms 52180 KB Output is correct
34 Correct 595 ms 165312 KB Output is correct
35 Correct 22 ms 39064 KB Output is correct
36 Correct 104 ms 67076 KB Output is correct
37 Correct 280 ms 97092 KB Output is correct
38 Correct 463 ms 87896 KB Output is correct
39 Correct 777 ms 106976 KB Output is correct
40 Correct 938 ms 128392 KB Output is correct
41 Correct 1383 ms 150072 KB Output is correct
42 Correct 1429 ms 170268 KB Output is correct
43 Correct 7 ms 31320 KB Output is correct
44 Correct 6 ms 31324 KB Output is correct
45 Correct 6 ms 31324 KB Output is correct
46 Correct 7 ms 31324 KB Output is correct
47 Correct 6 ms 31576 KB Output is correct
48 Correct 6 ms 31324 KB Output is correct
49 Correct 7 ms 31324 KB Output is correct
50 Correct 6 ms 31324 KB Output is correct
51 Correct 7 ms 31324 KB Output is correct
52 Correct 6 ms 31324 KB Output is correct
53 Correct 6 ms 31324 KB Output is correct
54 Correct 10 ms 32460 KB Output is correct
55 Correct 12 ms 33248 KB Output is correct
56 Correct 482 ms 102216 KB Output is correct
57 Correct 773 ms 136692 KB Output is correct
58 Correct 774 ms 134596 KB Output is correct
59 Correct 6 ms 31320 KB Output is correct
60 Correct 6 ms 31324 KB Output is correct
61 Correct 6 ms 31324 KB Output is correct
62 Correct 868 ms 190040 KB Output is correct
63 Correct 902 ms 188236 KB Output is correct
64 Correct 1022 ms 187440 KB Output is correct
65 Correct 14 ms 33856 KB Output is correct
66 Correct 24 ms 36396 KB Output is correct
67 Correct 763 ms 101112 KB Output is correct
68 Correct 1064 ms 137960 KB Output is correct
69 Correct 1669 ms 171516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 29272 KB Output is correct
2 Correct 6 ms 31324 KB Output is correct
3 Correct 6 ms 31352 KB Output is correct
4 Correct 6 ms 31324 KB Output is correct
5 Correct 6 ms 31320 KB Output is correct
6 Correct 7 ms 31324 KB Output is correct
7 Correct 6 ms 31324 KB Output is correct
8 Correct 6 ms 31324 KB Output is correct
9 Correct 411 ms 111048 KB Output is correct
10 Correct 27 ms 38936 KB Output is correct
11 Correct 128 ms 75576 KB Output is correct
12 Correct 34 ms 42996 KB Output is correct
13 Correct 84 ms 64220 KB Output is correct
14 Correct 8 ms 31948 KB Output is correct
15 Correct 10 ms 32728 KB Output is correct
16 Correct 379 ms 112048 KB Output is correct
17 Correct 703 ms 187012 KB Output is correct
18 Correct 670 ms 189248 KB Output is correct
19 Correct 1222 ms 168688 KB Output is correct
20 Correct 935 ms 165028 KB Output is correct
21 Correct 814 ms 162480 KB Output is correct
22 Correct 6 ms 31324 KB Output is correct
23 Correct 89 ms 53344 KB Output is correct
24 Correct 42 ms 44876 KB Output is correct
25 Correct 189 ms 78992 KB Output is correct
26 Correct 329 ms 110664 KB Output is correct
27 Correct 613 ms 101016 KB Output is correct
28 Correct 783 ms 118980 KB Output is correct
29 Correct 975 ms 138200 KB Output is correct
30 Correct 1162 ms 153784 KB Output is correct
31 Correct 1610 ms 170424 KB Output is correct
32 Correct 1104 ms 174692 KB Output is correct
33 Correct 847 ms 189616 KB Output is correct
34 Correct 18 ms 34396 KB Output is correct
35 Correct 25 ms 37808 KB Output is correct
36 Correct 577 ms 102780 KB Output is correct
37 Correct 1133 ms 138880 KB Output is correct
38 Correct 1477 ms 172372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 29272 KB Output is correct
2 Correct 6 ms 31324 KB Output is correct
3 Correct 6 ms 31352 KB Output is correct
4 Correct 6 ms 31324 KB Output is correct
5 Correct 6 ms 31320 KB Output is correct
6 Correct 7 ms 31324 KB Output is correct
7 Correct 6 ms 31324 KB Output is correct
8 Correct 6 ms 31324 KB Output is correct
9 Correct 411 ms 111048 KB Output is correct
10 Correct 27 ms 38936 KB Output is correct
11 Correct 128 ms 75576 KB Output is correct
12 Correct 34 ms 42996 KB Output is correct
13 Correct 84 ms 64220 KB Output is correct
14 Correct 8 ms 31948 KB Output is correct
15 Correct 10 ms 32728 KB Output is correct
16 Correct 379 ms 112048 KB Output is correct
17 Correct 7 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 7 ms 31172 KB Output is correct
21 Correct 6 ms 31324 KB Output is correct
22 Correct 6 ms 31324 KB Output is correct
23 Correct 1401 ms 165196 KB Output is correct
24 Correct 6 ms 31320 KB Output is correct
25 Correct 9 ms 32092 KB Output is correct
26 Correct 12 ms 33160 KB Output is correct
27 Correct 14 ms 33856 KB Output is correct
28 Correct 421 ms 85044 KB Output is correct
29 Correct 790 ms 112920 KB Output is correct
30 Correct 1031 ms 139088 KB Output is correct
31 Correct 1457 ms 165600 KB Output is correct
32 Correct 7 ms 31320 KB Output is correct
33 Correct 6 ms 31320 KB Output is correct
34 Correct 7 ms 31320 KB Output is correct
35 Correct 7 ms 31384 KB Output is correct
36 Correct 7 ms 31324 KB Output is correct
37 Correct 6 ms 31324 KB Output is correct
38 Correct 6 ms 31324 KB Output is correct
39 Correct 6 ms 31324 KB Output is correct
40 Correct 6 ms 31360 KB Output is correct
41 Correct 6 ms 31320 KB Output is correct
42 Correct 6 ms 31192 KB Output is correct
43 Correct 9 ms 32460 KB Output is correct
44 Correct 12 ms 33248 KB Output is correct
45 Correct 469 ms 101776 KB Output is correct
46 Correct 791 ms 136256 KB Output is correct
47 Correct 785 ms 135812 KB Output is correct
48 Correct 6 ms 31324 KB Output is correct
49 Correct 6 ms 31320 KB Output is correct
50 Correct 6 ms 31324 KB Output is correct
51 Correct 6 ms 31180 KB Output is correct
52 Correct 6 ms 31576 KB Output is correct
53 Correct 7 ms 31360 KB Output is correct
54 Correct 6 ms 31324 KB Output is correct
55 Incorrect 1498 ms 163372 KB a[33] = 0 is not an odd integer
56 Halted 0 ms 0 KB -