답안 #1024246

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1024246 2024-07-15T19:49:30 Z Abito 분수 공원 (IOI21_parks) C++17
15 / 100
143 ms 43368 KB
#include "parks.h"
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
const int N=2e5+5;
int a[N],b[N],par[N],sz[N],n;
vector<int> c[N];
vector<int> adj[N];
bool cmp(int x,int y){
    return a[x]<a[y];
}
int getpar(int x){
    if (x==par[x]) return x;
    return par[x]=getpar(par[x]);
}
void link(int x,int y){
    x=getpar(x);
    y=getpar(y);
    if (x==y) return;
    if (sz[x]>sz[y]) swap(x,y);
    sz[y]+=sz[x];
    par[x]=y;
    return;
}
int construct_roads(std::vector<int> x, std::vector<int> y) {
    if (x.size() == 1) {
	build({}, {}, {}, {});
        return 1;
    }
    n=x.size();
    for (int i=0;i<n;i++){
        par[i]=i;
        sz[i]=1;
        a[i]=x[i];
        b[i]=y[i];
        c[y[i]].pb(i);
    }
    vector<int> U,V,s;
    for (int i=0;i<N;i+=2) sort(c[i].begin(),c[i].end(),cmp);
    for (int i=0;i<N;i+=2){
        for (int j=0;j<int(c[i].size())-1;j++){
            if (a[c[i][j+1]]-a[c[i][j]]==2){
                link(c[i][j],c[i][j+1]);
                U.pb(c[i][j]);
                V.pb(c[i][j+1]);
                s.pb(0);
                adj[c[i][j]].pb(U.size()-1);
                adj[c[i][j+1]].pb(U.size()-1);
            }
        }
    }
    for (int i=N-1;i>=0;i--){
        for (int j=0;j<int(c[i].size());j++){
            int l=0,r=int(c[i+2].size())-1,mid,idx=-1;
            while (l<=r){
                mid=(l+r)/2;
                if (a[c[i+2][mid]]==a[c[i][j]]){
                    idx=mid;
                    break;
                }
                if (a[c[i+2][mid]]>a[c[i][j]]) r=mid-1;
                else l=mid+1;
            }
            if (idx!=-1){
                link(c[i][j],c[i+2][idx]);
                V.pb(c[i][j]);
                U.pb(c[i+2][idx]);
                s.pb(2);
                adj[c[i][j]].pb(U.size()-1);
                adj[c[i+2][idx]].pb(U.size()-1);
            }
        }
    }
    if (sz[getpar(0)]!=n) return 0;
    for (int i=0;i<U.size();i++){
        if (s[i]!=2) continue;
        int l=2,r=2,idxl=-1,idxr=-1;
        for (auto u:adj[V[i]]){
            int to=U[u];
            if (to==V[i]) to=V[u];
            if (a[to]==a[V[i]]) continue;
            if (a[to]>a[V[i]] && s[u]==0) r=0,idxr=u;
            if (a[to]<a[V[i]] && s[u]==0) l=0,idxl=u;
        }
        //cout<<l<<' '<<r<<endl;
        for (auto u:adj[U[i]]){
            int to=U[u];
            if (to==U[i]) to=V[u];
            if (a[to]==a[U[i]]) continue;
            if (a[to]>a[U[i]] && s[u]==1) r=1,idxr=u;
            if (a[to]<a[U[i]] && s[u]==1) l=1,idxl=u;
        }
        //cout<<U[i]<<' '<<V[i]<<' '<<l<<' '<<r<<' '<<idxl<<' '<<idxr<<endl;
        if (l==2 || r==2){
            //cout<<"c1"<<endl;
            if (r==2) s[i]=3;
            continue;
        }
        if (l==1){
            s[idxr]=1;
            s[i]=3;
            //cout<<"c2"<<endl;
            continue;
        }
        if (r==1){
            //cout<<"c3"<<endl;
            s[idxl]=1;
            continue;
        }
        //cout<<"c4"<<endl;
        s[idxl]=1;
    }
    vector<int> d,e;
    for (int i=0;i<U.size();i++){
        if (s[i]==0){
            d.pb(a[U[i]]+1);
            e.pb(b[U[i]]+1);
            continue;
        }
        if (s[i]==1){
            d.pb(a[U[i]]+1);
            e.pb(b[U[i]]-1);
            continue;
        }
        if (s[i]==2){
            d.pb(a[U[i]]-1);
            e.pb(b[U[i]]-1);
            continue;
        }
        d.pb(a[U[i]]+1);
        e.pb(b[U[i]]-1);
        continue;
    }
    build(U,V,d,e);
    return 1;
}

Compilation message

parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:75:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |     for (int i=0;i<U.size();i++){
      |                  ~^~~~~~~~~
parks.cpp:114:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  114 |     for (int i=0;i<U.size();i++){
      |                  ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10840 KB Output is correct
2 Correct 2 ms 12916 KB Output is correct
3 Correct 3 ms 12892 KB Output is correct
4 Correct 2 ms 12892 KB Output is correct
5 Correct 2 ms 12908 KB Output is correct
6 Correct 3 ms 12888 KB Output is correct
7 Correct 3 ms 12892 KB Output is correct
8 Correct 2 ms 12892 KB Output is correct
9 Correct 55 ms 26544 KB Output is correct
10 Correct 6 ms 14428 KB Output is correct
11 Correct 23 ms 20372 KB Output is correct
12 Correct 8 ms 15196 KB Output is correct
13 Correct 11 ms 17212 KB Output is correct
14 Correct 2 ms 12892 KB Output is correct
15 Correct 3 ms 12892 KB Output is correct
16 Correct 56 ms 26696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10840 KB Output is correct
2 Correct 2 ms 12916 KB Output is correct
3 Correct 3 ms 12892 KB Output is correct
4 Correct 2 ms 12892 KB Output is correct
5 Correct 2 ms 12908 KB Output is correct
6 Correct 3 ms 12888 KB Output is correct
7 Correct 3 ms 12892 KB Output is correct
8 Correct 2 ms 12892 KB Output is correct
9 Correct 55 ms 26544 KB Output is correct
10 Correct 6 ms 14428 KB Output is correct
11 Correct 23 ms 20372 KB Output is correct
12 Correct 8 ms 15196 KB Output is correct
13 Correct 11 ms 17212 KB Output is correct
14 Correct 2 ms 12892 KB Output is correct
15 Correct 3 ms 12892 KB Output is correct
16 Correct 56 ms 26696 KB Output is correct
17 Correct 2 ms 12888 KB Output is correct
18 Correct 3 ms 12892 KB Output is correct
19 Correct 2 ms 12892 KB Output is correct
20 Correct 2 ms 12888 KB Output is correct
21 Correct 2 ms 12924 KB Output is correct
22 Correct 2 ms 12892 KB Output is correct
23 Correct 143 ms 43368 KB Output is correct
24 Correct 3 ms 12892 KB Output is correct
25 Correct 3 ms 12892 KB Output is correct
26 Correct 3 ms 13224 KB Output is correct
27 Correct 4 ms 13148 KB Output is correct
28 Correct 57 ms 24656 KB Output is correct
29 Correct 78 ms 30560 KB Output is correct
30 Correct 100 ms 36444 KB Output is correct
31 Correct 139 ms 43300 KB Output is correct
32 Correct 2 ms 12892 KB Output is correct
33 Correct 2 ms 12892 KB Output is correct
34 Correct 3 ms 12892 KB Output is correct
35 Correct 2 ms 12892 KB Output is correct
36 Correct 3 ms 12892 KB Output is correct
37 Correct 2 ms 12892 KB Output is correct
38 Correct 3 ms 12892 KB Output is correct
39 Correct 3 ms 12892 KB Output is correct
40 Correct 3 ms 12888 KB Output is correct
41 Correct 3 ms 12892 KB Output is correct
42 Correct 2 ms 12920 KB Output is correct
43 Correct 3 ms 12892 KB Output is correct
44 Correct 3 ms 13144 KB Output is correct
45 Correct 55 ms 25672 KB Output is correct
46 Correct 81 ms 31584 KB Output is correct
47 Correct 76 ms 31584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10840 KB Output is correct
2 Correct 2 ms 12916 KB Output is correct
3 Correct 3 ms 12892 KB Output is correct
4 Correct 2 ms 12892 KB Output is correct
5 Correct 2 ms 12908 KB Output is correct
6 Correct 3 ms 12888 KB Output is correct
7 Correct 3 ms 12892 KB Output is correct
8 Correct 2 ms 12892 KB Output is correct
9 Correct 55 ms 26544 KB Output is correct
10 Correct 6 ms 14428 KB Output is correct
11 Correct 23 ms 20372 KB Output is correct
12 Correct 8 ms 15196 KB Output is correct
13 Correct 11 ms 17212 KB Output is correct
14 Correct 2 ms 12892 KB Output is correct
15 Correct 3 ms 12892 KB Output is correct
16 Correct 56 ms 26696 KB Output is correct
17 Correct 2 ms 12888 KB Output is correct
18 Correct 3 ms 12892 KB Output is correct
19 Correct 2 ms 12892 KB Output is correct
20 Correct 2 ms 12888 KB Output is correct
21 Correct 2 ms 12924 KB Output is correct
22 Correct 2 ms 12892 KB Output is correct
23 Correct 143 ms 43368 KB Output is correct
24 Correct 3 ms 12892 KB Output is correct
25 Correct 3 ms 12892 KB Output is correct
26 Correct 3 ms 13224 KB Output is correct
27 Correct 4 ms 13148 KB Output is correct
28 Correct 57 ms 24656 KB Output is correct
29 Correct 78 ms 30560 KB Output is correct
30 Correct 100 ms 36444 KB Output is correct
31 Correct 139 ms 43300 KB Output is correct
32 Correct 2 ms 12892 KB Output is correct
33 Correct 2 ms 12892 KB Output is correct
34 Correct 3 ms 12892 KB Output is correct
35 Correct 2 ms 12892 KB Output is correct
36 Correct 3 ms 12892 KB Output is correct
37 Correct 2 ms 12892 KB Output is correct
38 Correct 3 ms 12892 KB Output is correct
39 Correct 3 ms 12892 KB Output is correct
40 Correct 3 ms 12888 KB Output is correct
41 Correct 3 ms 12892 KB Output is correct
42 Correct 2 ms 12920 KB Output is correct
43 Correct 3 ms 12892 KB Output is correct
44 Correct 3 ms 13144 KB Output is correct
45 Correct 55 ms 25672 KB Output is correct
46 Correct 81 ms 31584 KB Output is correct
47 Correct 76 ms 31584 KB Output is correct
48 Correct 2 ms 12892 KB Output is correct
49 Correct 3 ms 12892 KB Output is correct
50 Correct 3 ms 12892 KB Output is correct
51 Incorrect 3 ms 12888 KB Tree @(3, 3) appears more than once: for edges on positions 0 and 1
52 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10840 KB Output is correct
2 Correct 2 ms 12916 KB Output is correct
3 Correct 3 ms 12892 KB Output is correct
4 Correct 2 ms 12892 KB Output is correct
5 Correct 2 ms 12908 KB Output is correct
6 Correct 3 ms 12888 KB Output is correct
7 Correct 3 ms 12892 KB Output is correct
8 Correct 2 ms 12892 KB Output is correct
9 Correct 55 ms 26544 KB Output is correct
10 Correct 6 ms 14428 KB Output is correct
11 Correct 23 ms 20372 KB Output is correct
12 Correct 8 ms 15196 KB Output is correct
13 Correct 11 ms 17212 KB Output is correct
14 Correct 2 ms 12892 KB Output is correct
15 Correct 3 ms 12892 KB Output is correct
16 Correct 56 ms 26696 KB Output is correct
17 Correct 4 ms 12892 KB Output is correct
18 Correct 2 ms 12892 KB Output is correct
19 Correct 2 ms 12920 KB Output is correct
20 Correct 121 ms 38236 KB Output is correct
21 Correct 106 ms 36500 KB Output is correct
22 Correct 106 ms 36444 KB Output is correct
23 Correct 101 ms 32352 KB Output is correct
24 Correct 38 ms 18772 KB Output is correct
25 Correct 65 ms 27188 KB Output is correct
26 Correct 72 ms 27188 KB Output is correct
27 Correct 113 ms 35088 KB Output is correct
28 Correct 112 ms 35168 KB Output is correct
29 Correct 115 ms 34908 KB Output is correct
30 Correct 110 ms 34908 KB Output is correct
31 Correct 3 ms 12892 KB Output is correct
32 Correct 15 ms 14908 KB Output is correct
33 Correct 23 ms 18780 KB Output is correct
34 Correct 115 ms 38296 KB Output is correct
35 Correct 5 ms 13656 KB Output is correct
36 Correct 21 ms 16724 KB Output is correct
37 Correct 40 ms 20544 KB Output is correct
38 Incorrect 47 ms 22368 KB Tree @(110527, 197105) appears more than once: for edges on positions 39120 and 41027
39 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10840 KB Output is correct
2 Correct 2 ms 12916 KB Output is correct
3 Correct 3 ms 12892 KB Output is correct
4 Correct 2 ms 12892 KB Output is correct
5 Correct 2 ms 12908 KB Output is correct
6 Correct 3 ms 12888 KB Output is correct
7 Correct 3 ms 12892 KB Output is correct
8 Correct 2 ms 12892 KB Output is correct
9 Correct 55 ms 26544 KB Output is correct
10 Correct 6 ms 14428 KB Output is correct
11 Correct 23 ms 20372 KB Output is correct
12 Correct 8 ms 15196 KB Output is correct
13 Correct 11 ms 17212 KB Output is correct
14 Correct 2 ms 12892 KB Output is correct
15 Correct 3 ms 12892 KB Output is correct
16 Correct 56 ms 26696 KB Output is correct
17 Correct 107 ms 36448 KB Output is correct
18 Correct 114 ms 36700 KB Output is correct
19 Correct 112 ms 36444 KB Output is correct
20 Correct 126 ms 37720 KB Output is correct
21 Correct 97 ms 33632 KB Output is correct
22 Correct 2 ms 12888 KB Output is correct
23 Incorrect 20 ms 17040 KB Tree @(185917, 21619) appears more than once: for edges on positions 16965 and 17429
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10840 KB Output is correct
2 Correct 2 ms 12916 KB Output is correct
3 Correct 3 ms 12892 KB Output is correct
4 Correct 2 ms 12892 KB Output is correct
5 Correct 2 ms 12908 KB Output is correct
6 Correct 3 ms 12888 KB Output is correct
7 Correct 3 ms 12892 KB Output is correct
8 Correct 2 ms 12892 KB Output is correct
9 Correct 55 ms 26544 KB Output is correct
10 Correct 6 ms 14428 KB Output is correct
11 Correct 23 ms 20372 KB Output is correct
12 Correct 8 ms 15196 KB Output is correct
13 Correct 11 ms 17212 KB Output is correct
14 Correct 2 ms 12892 KB Output is correct
15 Correct 3 ms 12892 KB Output is correct
16 Correct 56 ms 26696 KB Output is correct
17 Correct 2 ms 12888 KB Output is correct
18 Correct 3 ms 12892 KB Output is correct
19 Correct 2 ms 12892 KB Output is correct
20 Correct 2 ms 12888 KB Output is correct
21 Correct 2 ms 12924 KB Output is correct
22 Correct 2 ms 12892 KB Output is correct
23 Correct 143 ms 43368 KB Output is correct
24 Correct 3 ms 12892 KB Output is correct
25 Correct 3 ms 12892 KB Output is correct
26 Correct 3 ms 13224 KB Output is correct
27 Correct 4 ms 13148 KB Output is correct
28 Correct 57 ms 24656 KB Output is correct
29 Correct 78 ms 30560 KB Output is correct
30 Correct 100 ms 36444 KB Output is correct
31 Correct 139 ms 43300 KB Output is correct
32 Correct 2 ms 12892 KB Output is correct
33 Correct 2 ms 12892 KB Output is correct
34 Correct 3 ms 12892 KB Output is correct
35 Correct 2 ms 12892 KB Output is correct
36 Correct 3 ms 12892 KB Output is correct
37 Correct 2 ms 12892 KB Output is correct
38 Correct 3 ms 12892 KB Output is correct
39 Correct 3 ms 12892 KB Output is correct
40 Correct 3 ms 12888 KB Output is correct
41 Correct 3 ms 12892 KB Output is correct
42 Correct 2 ms 12920 KB Output is correct
43 Correct 3 ms 12892 KB Output is correct
44 Correct 3 ms 13144 KB Output is correct
45 Correct 55 ms 25672 KB Output is correct
46 Correct 81 ms 31584 KB Output is correct
47 Correct 76 ms 31584 KB Output is correct
48 Correct 2 ms 12892 KB Output is correct
49 Correct 3 ms 12892 KB Output is correct
50 Correct 3 ms 12892 KB Output is correct
51 Incorrect 3 ms 12888 KB Tree @(3, 3) appears more than once: for edges on positions 0 and 1
52 Halted 0 ms 0 KB -