답안 #1106652

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1106652 2024-10-30T18:49:57 Z Ahmed57 스핑크스 (IOI24_sphinx) C++17
10 / 100
418 ms 1464 KB
#include <bits/stdc++.h>
#include "sphinx.h"

using namespace std;
int pr2[251];
int find2(int x){
    if(x==pr2[x])return x;
    return pr2[x] = find2(pr2[x]);  
}
void mergegroup2(int a,int b){
    a = find2(a);
    b = find2(b);
    if(a==b)return ;
    pr2[a] = b;
}
int pr[251];
vector<int> adjj[251],nadj[251];
int find(int x){
    if(x==pr[x])return x;
    return pr[x] = find(pr[x]);
}
bool mergegroup(int a,int b){
    a = find(a);
    b = find(b);
    if(a==b)return 0;
    pr[a] = b;
    return 1;
}
vector<int> even,odd;
int VIS[251];
void dfs(int i,int dep){
    VIS[i] =1 ;
    if(dep)even.push_back(i);
    else odd.push_back(i);
    for(auto j:nadj[i]){
        if(!VIS[j])dfs(j,dep^1);
    }
}
vector<int> find_colours(int n,vector<int> X,vector<int> Y){
    for(int i = 0;i<X.size();i++){
        adjj[X[i]].push_back(Y[i]);
        adjj[Y[i]].push_back(X[i]);
    }
    int d = 0;
    for(int i = 0;i<n;i++){
        pr2[i] = i;
    }
    for(int i = n-1;i>=0;i--){
        int ans = 0;
        while(ans!=-1){
        vector<int> v;
        int vis[n] = {0};
        for(auto j:adjj[i]){
            if(j>i&&vis[find2(j)]==0&&find2(j)!=find2(i)){
                v.push_back(j);
                vis[find2(j)] = 1;
            }
        }
        int sz = v.size();
        int l = 0 , r = sz-1;
        ans = -1;
        while(l<=r){
            int mid = (l+r)/2;
            vector<int> e(n,n);
            e[i] = -1;
            for(int j = 0;j<=mid;j++){
                e[v[j]] = -1;
            }
            int cnt = 0;
            for(int j = 0;j<n;j++){
                if(e[j]==-1){
                    pr[j] = j;cnt++;
                }else {
                    pr[j] = j;cnt++;
                }
            }
            for(int j = 0;j<X.size();j++){
                if(e[X[j]]==-1&&e[Y[j]]==-1){
                    if(X[j]==i||Y[j]==i)continue;
                    if(find2(X[j])==find2(Y[j]))cnt-=mergegroup(X[j],Y[j]);
                }else if(e[X[j]]==n&&e[Y[j]]==n){
                    cnt-=mergegroup(X[j],Y[j]);
                }
            }
            if(cnt==perform_experiment(e)){
                l = mid+1;
            }else {
                ans = mid;
                r = mid-1;
            }
        }
        if(ans!=-1){
            mergegroup2(i,v[ans]);
        }
        }
    }
    vector<int> V[n];
    for(int i = 0;i<n;i++){
        V[find2(i)].push_back(i);
    }
    for(int i = 0;i<X.size();i++){
        if(find2(X[i])!=find2(Y[i])){
            nadj[find2(X[i])].push_back(find2(Y[i]));
            nadj[find2(Y[i])].push_back(find2(X[i]));
        }
    }
    dfs(find2(0),0);
    if(even.size()+odd.size()==1){
        for(int i = 0;i<n;i++){
            vector<int> e(n,i);
            e[0] = -1;
            if(perform_experiment(e)==1){
                vector<int> na(n,i);
                return na;
            }
        }
    }
    int in[n] = {0};
    for(int i = 0;i<n;i++){
        {
            vector<int> lol;
            for(auto j:even){
                if(in[j]==0){
                    lol.push_back(j);
                }
            }
            int ans = 0;
            while(ans!=-1){
                int sz = lol.size();
                int l = ans , r = sz-1;
                int org = ans;
                ans = -1;
                while(l<=r){
                    int mid = (l+r)/2;
                    vector<int> e(n,i);
                    int cnt = 0;
                    for(int j = 0;j<n;j++){
                        if(e[j]==-1){
                            pr[j] = j;cnt++;
                        }else {
                            pr[j] = j;cnt++;
                        }
                    }
                    for(int j = org;j<=mid;j++){
                        for(auto w:V[lol[j]]){
                            e[w] = -1;
                        }
                    }
                    for(int j = 0;j<X.size();j++){
                        if(e[X[j]]==-1&&e[Y[j]]==-1){
                            if(find2(X[j])==find2(Y[j]))cnt-=mergegroup(X[j],Y[j]);
                        }else if(e[X[j]]==i&&e[Y[j]]==i){
                            cnt-=mergegroup(X[j],Y[j]);
                        }
                    }
                    if(cnt==perform_experiment(e)){
                        l = mid+1;
                    }else {
                        ans = mid;
                        r = mid-1;
                    }
                }
                if(ans==-1){
                    break;
                }
                in[lol[ans]] = i+1;
                ans++;
            }
        }
        swap(even,odd);
        {
            vector<int> lol;
            for(auto j:even){
                if(in[j]==0){
                    lol.push_back(j);
                }
            }
            int ans = 0;
            while(ans!=-1){
                int sz = lol.size();
                int l = ans , r = sz-1;
                int org = ans;
                ans = -1;
                while(l<=r){
                    int mid = (l+r)/2;
                    vector<int> e(n,i);
                    int cnt = 0;
                    for(int j = 0;j<n;j++){
                        if(e[j]==-1){
                            pr[j] = j;cnt++;
                        }else {
                            pr[j] = j;cnt++;
                        }
                    }
                    for(int j = org;j<=mid;j++){
                        for(auto w:V[lol[j]]){
                            e[w] = -1;
                        }
                    }
                    for(int j = 0;j<X.size();j++){
                        if(e[X[j]]==-1&&e[Y[j]]==-1){
                            if(find2(X[j])==find2(Y[j]))cnt-=mergegroup(X[j],Y[j]);
                        }else if(e[X[j]]==i&&e[Y[j]]==i){
                            cnt-=mergegroup(X[j],Y[j]);
                        }
                    }
                    if(cnt==perform_experiment(e)){
                        l = mid+1;
                    }else {
                        ans = mid;
                        r = mid-1;
                    }
                }
                if(ans==-1){
                    break;
                }
                in[lol[ans]] = i+1;
                ans++;
            }
        }
    }
    vector<int> col(n,0);
    for(int i = 0;i<n;i++){
        col[i] = in[find2(i)]-1;
    }
    return col;
}

Compilation message

sphinx.cpp: In function 'std::vector<int> find_colours(int, std::vector<int>, std::vector<int>)':
sphinx.cpp:40:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     for(int i = 0;i<X.size();i++){
      |                   ~^~~~~~~~~
sphinx.cpp:77:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |             for(int j = 0;j<X.size();j++){
      |                           ~^~~~~~~~~
sphinx.cpp:101:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |     for(int i = 0;i<X.size();i++){
      |                   ~^~~~~~~~~
sphinx.cpp:149:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  149 |                     for(int j = 0;j<X.size();j++){
      |                                   ~^~~~~~~~~
sphinx.cpp:200:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  200 |                     for(int j = 0;j<X.size();j++){
      |                                   ~^~~~~~~~~
sphinx.cpp:44:9: warning: unused variable 'd' [-Wunused-variable]
   44 |     int d = 0;
      |         ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB #experiments: 8
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB #experiments: 2
2 Correct 1 ms 336 KB #experiments: 4
3 Correct 1 ms 336 KB #experiments: 4
4 Correct 1 ms 336 KB #experiments: 3
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB #experiments: 8
2 Correct 1 ms 336 KB #experiments: 2
3 Correct 1 ms 336 KB #experiments: 4
4 Correct 1 ms 336 KB #experiments: 4
5 Correct 1 ms 336 KB #experiments: 3
6 Correct 1 ms 336 KB #experiments: 74
7 Correct 2 ms 568 KB #experiments: 119
8 Correct 3 ms 336 KB #experiments: 197
9 Correct 3 ms 336 KB #experiments: 203
10 Correct 3 ms 336 KB #experiments: 236
11 Correct 3 ms 336 KB #experiments: 266
12 Correct 6 ms 336 KB #experiments: 537
13 Correct 6 ms 336 KB #experiments: 540
14 Correct 2 ms 336 KB #experiments: 64
15 Correct 8 ms 752 KB #experiments: 339
16 Correct 7 ms 592 KB #experiments: 418
17 Correct 9 ms 752 KB #experiments: 499
18 Correct 10 ms 336 KB #experiments: 639
19 Correct 10 ms 336 KB #experiments: 633
20 Correct 11 ms 336 KB #experiments: 707
21 Correct 11 ms 336 KB #experiments: 729
22 Correct 5 ms 592 KB #experiments: 338
23 Correct 5 ms 504 KB #experiments: 330
24 Correct 5 ms 592 KB #experiments: 359
25 Correct 7 ms 336 KB #experiments: 481
26 Correct 5 ms 336 KB #experiments: 383
27 Correct 7 ms 464 KB #experiments: 475
28 Correct 5 ms 336 KB #experiments: 525
29 Correct 6 ms 336 KB #experiments: 433
30 Correct 10 ms 336 KB #experiments: 614
31 Correct 9 ms 336 KB #experiments: 524
32 Correct 13 ms 336 KB #experiments: 672
33 Correct 2 ms 336 KB #experiments: 79
34 Correct 12 ms 496 KB #experiments: 704
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB #experiments: 2
2 Correct 1 ms 336 KB #experiments: 4
3 Correct 1 ms 336 KB #experiments: 4
4 Correct 1 ms 336 KB #experiments: 3
5 Correct 1 ms 336 KB #experiments: 74
6 Correct 2 ms 568 KB #experiments: 119
7 Correct 3 ms 336 KB #experiments: 197
8 Correct 3 ms 336 KB #experiments: 203
9 Correct 3 ms 336 KB #experiments: 236
10 Correct 3 ms 336 KB #experiments: 266
11 Correct 6 ms 336 KB #experiments: 537
12 Correct 6 ms 336 KB #experiments: 540
13 Correct 11 ms 336 KB #experiments: 368
14 Correct 22 ms 336 KB #experiments: 1026
15 Correct 28 ms 456 KB #experiments: 1240
16 Correct 27 ms 336 KB #experiments: 1360
17 Correct 46 ms 504 KB #experiments: 2119
18 Incorrect 61 ms 604 KB #experiments reached 2751
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB #experiments: 2
2 Correct 1 ms 336 KB #experiments: 4
3 Correct 1 ms 336 KB #experiments: 4
4 Correct 1 ms 336 KB #experiments: 3
5 Correct 2 ms 336 KB #experiments: 64
6 Correct 8 ms 752 KB #experiments: 339
7 Correct 7 ms 592 KB #experiments: 418
8 Correct 9 ms 752 KB #experiments: 499
9 Correct 10 ms 336 KB #experiments: 639
10 Correct 10 ms 336 KB #experiments: 633
11 Correct 11 ms 336 KB #experiments: 707
12 Correct 11 ms 336 KB #experiments: 729
13 Correct 148 ms 1464 KB #experiments: 926
14 Correct 343 ms 1464 KB #experiments: 2199
15 Incorrect 418 ms 1464 KB #experiments reached 2751
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB #experiments: 8
2 Correct 1 ms 336 KB #experiments: 2
3 Correct 1 ms 336 KB #experiments: 4
4 Correct 1 ms 336 KB #experiments: 4
5 Correct 1 ms 336 KB #experiments: 3
6 Correct 1 ms 336 KB #experiments: 74
7 Correct 2 ms 568 KB #experiments: 119
8 Correct 3 ms 336 KB #experiments: 197
9 Correct 3 ms 336 KB #experiments: 203
10 Correct 3 ms 336 KB #experiments: 236
11 Correct 3 ms 336 KB #experiments: 266
12 Correct 6 ms 336 KB #experiments: 537
13 Correct 6 ms 336 KB #experiments: 540
14 Correct 2 ms 336 KB #experiments: 64
15 Correct 8 ms 752 KB #experiments: 339
16 Correct 7 ms 592 KB #experiments: 418
17 Correct 9 ms 752 KB #experiments: 499
18 Correct 10 ms 336 KB #experiments: 639
19 Correct 10 ms 336 KB #experiments: 633
20 Correct 11 ms 336 KB #experiments: 707
21 Correct 11 ms 336 KB #experiments: 729
22 Correct 5 ms 592 KB #experiments: 338
23 Correct 5 ms 504 KB #experiments: 330
24 Correct 5 ms 592 KB #experiments: 359
25 Correct 7 ms 336 KB #experiments: 481
26 Correct 5 ms 336 KB #experiments: 383
27 Correct 7 ms 464 KB #experiments: 475
28 Correct 5 ms 336 KB #experiments: 525
29 Correct 6 ms 336 KB #experiments: 433
30 Correct 10 ms 336 KB #experiments: 614
31 Correct 9 ms 336 KB #experiments: 524
32 Correct 13 ms 336 KB #experiments: 672
33 Correct 2 ms 336 KB #experiments: 79
34 Correct 12 ms 496 KB #experiments: 704
35 Correct 11 ms 336 KB #experiments: 368
36 Correct 22 ms 336 KB #experiments: 1026
37 Correct 28 ms 456 KB #experiments: 1240
38 Correct 27 ms 336 KB #experiments: 1360
39 Correct 46 ms 504 KB #experiments: 2119
40 Incorrect 61 ms 604 KB #experiments reached 2751
41 Halted 0 ms 0 KB -