Submission #347927

# Submission time Handle Problem Language Result Execution time Memory
347927 2021-01-13T19:22:50 Z Uncreative Pictionary (COCI18_pictionary) C++14
140 / 140
596 ms 15224 KB
#include<iostream>
#include<vector>
#include<ctime>
#include<random>
#include<cmath>

using namespace std;

const int maxn = 100010;

int par[maxn];

int Find(int x){
    if (x != par[x]){
        par[x] = Find(par[x]);
    }
    return par[x];
}

void Union(int x, int y){
    x = Find(x);
    y = Find(y);
    if (x == y){
        return;
    }
    int c = (rand()%2);
    if (c == 0){
        par[x] = y;
    }
    else {
        par[y] = x;
    }
}

int a[maxn];
int b[maxn];

int sol[maxn];

int lo[maxn];
int hi[maxn];

vector<int> md[maxn];

int main(){
    srand(time(0));
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, m, q;
    cin >> n >> m >> q;
    for (int i = 1; i <= q; i++){
        cin >> a[i] >> b[i];
    }
    for (int i = 1; i <= q; i++){
        lo[i] = 1;
        hi[i] = m;
        md[(lo[i] + hi[i]) / 2].push_back(i);
    }

    int lg = (int)log2((double)m) + 3;
    for (int t = 0; t < lg; t++){
        for (int i = 1; i <= n; i++){
            par[i] = i;
        }
        for (int i = 1; i <= m; i++){
            int mi = m - i + 1;
            for (int j = mi; j <= n - mi; j += mi){
                Union(j, j + mi);
            }

            for (int j = 0; j < md[i].size(); j++){
                int e = md[i][j];
                if (Find(a[e]) == Find(b[e])){
                    sol[e] = i;
                    hi[e] = i;
                }
                else {
                    lo[e] = i + 1;
                }
            }
            md[i].clear();
        }
        for (int i = 1; i <= q; i++){
            md[(lo[i] + hi[i]) / 2].push_back(i);
        }
    }
    for (int i = 1; i <= q; i++){
        cout << sol[i] << "\n";
    }
}

Compilation message

pictionary.cpp: In function 'int main()':
pictionary.cpp:71:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |             for (int j = 0; j < md[i].size(); j++){
      |                             ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 3052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 3820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 7156 KB Output is correct
2 Correct 39 ms 6252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 63 ms 9004 KB Output is correct
2 Correct 54 ms 7992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 126 ms 7360 KB Output is correct
2 Correct 120 ms 7404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 168 ms 7808 KB Output is correct
2 Correct 135 ms 7292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 262 ms 9968 KB Output is correct
2 Correct 242 ms 8188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 157 ms 8172 KB Output is correct
2 Correct 378 ms 11372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 441 ms 12972 KB Output is correct
2 Correct 504 ms 12268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 596 ms 15224 KB Output is correct
2 Correct 525 ms 13804 KB Output is correct