Submission #1106626

# Submission time Handle Problem Language Result Execution time Memory
1106626 2024-10-30T17:56:56 Z Ahmed57 Sphinx's Riddle (IOI24_sphinx) C++17
50 / 100
542 ms 1272 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];
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> 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> col;
    for(int i = 0;i<n;i++){
        col.push_back(find2(i));
    }
    return col;
}

Compilation message

sphinx.cpp: In function 'std::vector<int> find_colours(int, std::vector<int>, std::vector<int>)':
sphinx.cpp:30:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     for(int i = 0;i<X.size();i++){
      |                   ~^~~~~~~~~
sphinx.cpp:67:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |             for(int j = 0;j<X.size();j++){
      |                           ~^~~~~~~~~
sphinx.cpp:34:9: warning: unused variable 'd' [-Wunused-variable]
   34 |     int d = 0;
      |         ^
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 336 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 336 KB Partially correct
2 Correct 1 ms 336 KB #experiments: 1
3 Partially correct 1 ms 336 KB Partially correct
4 Correct 1 ms 336 KB #experiments: 1
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 336 KB Partially correct
2 Partially correct 1 ms 336 KB Partially correct
3 Correct 1 ms 336 KB #experiments: 1
4 Partially correct 1 ms 336 KB Partially correct
5 Correct 1 ms 336 KB #experiments: 1
6 Partially correct 1 ms 336 KB Partially correct
7 Partially correct 1 ms 336 KB Partially correct
8 Partially correct 1 ms 336 KB Partially correct
9 Partially correct 2 ms 336 KB Partially correct
10 Partially correct 1 ms 336 KB Partially correct
11 Partially correct 1 ms 336 KB Partially correct
12 Partially correct 1 ms 336 KB Partially correct
13 Partially correct 1 ms 336 KB Partially correct
14 Partially correct 2 ms 336 KB Partially correct
15 Partially correct 4 ms 336 KB Partially correct
16 Partially correct 5 ms 336 KB Partially correct
17 Partially correct 5 ms 336 KB Partially correct
18 Partially correct 8 ms 336 KB Partially correct
19 Partially correct 5 ms 336 KB Partially correct
20 Partially correct 5 ms 336 KB Partially correct
21 Partially correct 4 ms 336 KB Partially correct
22 Partially correct 3 ms 336 KB Partially correct
23 Partially correct 3 ms 336 KB Partially correct
24 Partially correct 3 ms 504 KB Partially correct
25 Partially correct 3 ms 336 KB Partially correct
26 Partially correct 1 ms 336 KB Partially correct
27 Partially correct 1 ms 400 KB Partially correct
28 Partially correct 1 ms 336 KB Partially correct
29 Partially correct 3 ms 336 KB Partially correct
30 Partially correct 5 ms 336 KB Partially correct
31 Partially correct 6 ms 336 KB Partially correct
32 Partially correct 6 ms 336 KB Partially correct
33 Partially correct 2 ms 336 KB Partially correct
34 Partially correct 4 ms 336 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 336 KB Partially correct
2 Correct 1 ms 336 KB #experiments: 1
3 Partially correct 1 ms 336 KB Partially correct
4 Correct 1 ms 336 KB #experiments: 1
5 Partially correct 1 ms 336 KB Partially correct
6 Partially correct 1 ms 336 KB Partially correct
7 Partially correct 1 ms 336 KB Partially correct
8 Partially correct 2 ms 336 KB Partially correct
9 Partially correct 1 ms 336 KB Partially correct
10 Partially correct 1 ms 336 KB Partially correct
11 Partially correct 1 ms 336 KB Partially correct
12 Partially correct 1 ms 336 KB Partially correct
13 Partially correct 5 ms 336 KB Partially correct
14 Partially correct 6 ms 336 KB Partially correct
15 Partially correct 6 ms 336 KB Partially correct
16 Partially correct 6 ms 336 KB Partially correct
17 Partially correct 7 ms 508 KB Partially correct
18 Partially correct 7 ms 460 KB Partially correct
19 Partially correct 5 ms 456 KB Partially correct
20 Partially correct 5 ms 456 KB Partially correct
21 Partially correct 5 ms 336 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 336 KB Partially correct
2 Correct 1 ms 336 KB #experiments: 1
3 Partially correct 1 ms 336 KB Partially correct
4 Correct 1 ms 336 KB #experiments: 1
5 Partially correct 2 ms 336 KB Partially correct
6 Partially correct 4 ms 336 KB Partially correct
7 Partially correct 5 ms 336 KB Partially correct
8 Partially correct 5 ms 336 KB Partially correct
9 Partially correct 8 ms 336 KB Partially correct
10 Partially correct 5 ms 336 KB Partially correct
11 Partially correct 5 ms 336 KB Partially correct
12 Partially correct 4 ms 336 KB Partially correct
13 Partially correct 89 ms 1200 KB Partially correct
14 Partially correct 224 ms 1104 KB Partially correct
15 Partially correct 339 ms 1104 KB Partially correct
16 Partially correct 370 ms 1104 KB Partially correct
17 Partially correct 336 ms 1104 KB Partially correct
18 Partially correct 307 ms 1272 KB Partially correct
19 Partially correct 260 ms 1104 KB Partially correct
20 Partially correct 38 ms 1104 KB Partially correct
21 Partially correct 199 ms 1104 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 336 KB Partially correct
2 Partially correct 1 ms 336 KB Partially correct
3 Correct 1 ms 336 KB #experiments: 1
4 Partially correct 1 ms 336 KB Partially correct
5 Correct 1 ms 336 KB #experiments: 1
6 Partially correct 1 ms 336 KB Partially correct
7 Partially correct 1 ms 336 KB Partially correct
8 Partially correct 1 ms 336 KB Partially correct
9 Partially correct 2 ms 336 KB Partially correct
10 Partially correct 1 ms 336 KB Partially correct
11 Partially correct 1 ms 336 KB Partially correct
12 Partially correct 1 ms 336 KB Partially correct
13 Partially correct 1 ms 336 KB Partially correct
14 Partially correct 2 ms 336 KB Partially correct
15 Partially correct 4 ms 336 KB Partially correct
16 Partially correct 5 ms 336 KB Partially correct
17 Partially correct 5 ms 336 KB Partially correct
18 Partially correct 8 ms 336 KB Partially correct
19 Partially correct 5 ms 336 KB Partially correct
20 Partially correct 5 ms 336 KB Partially correct
21 Partially correct 4 ms 336 KB Partially correct
22 Partially correct 3 ms 336 KB Partially correct
23 Partially correct 3 ms 336 KB Partially correct
24 Partially correct 3 ms 504 KB Partially correct
25 Partially correct 3 ms 336 KB Partially correct
26 Partially correct 1 ms 336 KB Partially correct
27 Partially correct 1 ms 400 KB Partially correct
28 Partially correct 1 ms 336 KB Partially correct
29 Partially correct 3 ms 336 KB Partially correct
30 Partially correct 5 ms 336 KB Partially correct
31 Partially correct 6 ms 336 KB Partially correct
32 Partially correct 6 ms 336 KB Partially correct
33 Partially correct 2 ms 336 KB Partially correct
34 Partially correct 4 ms 336 KB Partially correct
35 Partially correct 5 ms 336 KB Partially correct
36 Partially correct 6 ms 336 KB Partially correct
37 Partially correct 6 ms 336 KB Partially correct
38 Partially correct 6 ms 336 KB Partially correct
39 Partially correct 7 ms 508 KB Partially correct
40 Partially correct 7 ms 460 KB Partially correct
41 Partially correct 5 ms 456 KB Partially correct
42 Partially correct 5 ms 456 KB Partially correct
43 Partially correct 5 ms 336 KB Partially correct
44 Partially correct 89 ms 1200 KB Partially correct
45 Partially correct 224 ms 1104 KB Partially correct
46 Partially correct 339 ms 1104 KB Partially correct
47 Partially correct 370 ms 1104 KB Partially correct
48 Partially correct 336 ms 1104 KB Partially correct
49 Partially correct 307 ms 1272 KB Partially correct
50 Partially correct 260 ms 1104 KB Partially correct
51 Partially correct 38 ms 1104 KB Partially correct
52 Partially correct 199 ms 1104 KB Partially correct
53 Partially correct 31 ms 336 KB Partially correct
54 Partially correct 37 ms 336 KB Partially correct
55 Partially correct 50 ms 336 KB Partially correct
56 Partially correct 56 ms 336 KB Partially correct
57 Partially correct 148 ms 592 KB Partially correct
58 Partially correct 135 ms 592 KB Partially correct
59 Partially correct 141 ms 592 KB Partially correct
60 Partially correct 140 ms 592 KB Partially correct
61 Partially correct 7 ms 336 KB Partially correct
62 Partially correct 7 ms 592 KB Partially correct
63 Partially correct 7 ms 464 KB Partially correct
64 Partially correct 50 ms 336 KB Partially correct
65 Partially correct 51 ms 336 KB Partially correct
66 Partially correct 69 ms 336 KB Partially correct
67 Partially correct 53 ms 336 KB Partially correct
68 Partially correct 64 ms 336 KB Partially correct
69 Partially correct 87 ms 336 KB Partially correct
70 Partially correct 66 ms 336 KB Partially correct
71 Partially correct 73 ms 336 KB Partially correct
72 Partially correct 26 ms 336 KB Partially correct
73 Partially correct 39 ms 492 KB Partially correct
74 Partially correct 45 ms 336 KB Partially correct
75 Partially correct 55 ms 336 KB Partially correct
76 Partially correct 64 ms 336 KB Partially correct
77 Partially correct 65 ms 336 KB Partially correct
78 Partially correct 68 ms 336 KB Partially correct
79 Partially correct 70 ms 592 KB Partially correct
80 Partially correct 95 ms 592 KB Partially correct
81 Partially correct 87 ms 592 KB Partially correct
82 Partially correct 73 ms 592 KB Partially correct
83 Partially correct 289 ms 1052 KB Partially correct
84 Partially correct 542 ms 1104 KB Partially correct
85 Partially correct 15 ms 592 KB Partially correct
86 Partially correct 125 ms 592 KB Partially correct