Submission #540747

# Submission time Handle Problem Language Result Execution time Memory
540747 2022-03-21T15:46:25 Z AugustinasJucas ICC (CEOI16_icc) C++14
61 / 100
165 ms 612 KB
#include <bits/stdc++.h>
#include "icc.h"

using namespace std;
int n;


vector<vector<int> > comp;


pair<vector<int>, vector<int> > randomPuse(int sz) {
    vector<int> vec (sz);
    for(int i = 0; i < vec.size(); i++) vec[i] = i;    
    shuffle(vec.begin(), vec.end(), default_random_engine(rand()));
    vector<int> a, b;
    for(int i = 0; i < sz/2; i++) a.push_back(vec[i]);
    for(int i = sz/2; i < sz; i++) b.push_back(vec[i]);
    return {a, b};
}
vector<int> sudek(vector<int> &a) {
    vector<int> ret;
    for(auto &x : a) for(auto &y : comp[x]) ret.push_back(y);
    return ret;
}
int mas1[101], mas2[102];
bool quer(vector<int> &a, vector<int> &b) {
    for(int i = 0; i < a.size(); i++) mas1[i] = a[i];
    for(int i = 0; i < b.size(); i++) mas2[i] = b[i];
    int ret = query(a.size(), b.size(), mas1, mas2);
//    cout << "quer(["; for(auto x : a) cout << x << " "; cout << "],  ["; for(auto x : b) cout << x << " "; cout << "]) = " << ret << endl;
    return ret;
}
pair<vector<int>, vector<int> > raskPriesingus() {
    while(true) {
        auto pr = randomPuse(comp.size());
        auto a = pr.first;
        auto b = pr.second;
        
        auto A1 = sudek(a);
        auto B1 = sudek(b);
        
        if(quer(A1, B1) == 1) {
            return {A1, B1};
        }
    }
    return {{-1}, {-1}};
}
vector<int> sudek(vector<int> &a, int kek) {
    vector<int> ret = a;
    ret.resize(kek);
    return ret;
}
int dvej(vector<int> &a, vector<int> &b) {
    int l = 0; int r = b.size();
    int ans = -1;
    int mid;
    while(l <= r) {
        mid = (l + r) / 2;
        auto sud = sudek(b, mid);
        if(quer(a, sud) == 0) {
            l = mid+1;
            ans = max(ans, mid);
        }else {
            r = mid-1;
        }
    }
    return b[ans];
}
void renewComp(int a, int b) {
    int i1 = -1; int i2 = -1;
    for(int i = 0; i < comp.size(); i++) {
        bool is = 0;
        for(auto &x : comp[i]) if(x == a || x == b) is = 1;
        if(is) {
            if(i1 == -1) i1 = i;
            else i2 = i;
        }
    }
    for(auto &x : comp[i1]) comp[i2].push_back(x);
    comp.erase(comp.begin() + i1);
}
void raskBriauna(){
    auto pries = raskPriesingus();
    auto a = pries.first;
    auto b = pries.second;
/*
    cout << "gaunu, kad priesingose pusese yra: ["; 
    for(auto x : a) cout << x << " ";
    cout << "] ir [";
    for(auto x : b) cout << x << " ";
    cout << "]\n\n";*/

    // tik viena pora yra tarp a ir b
    int A = dvej(a, b);
    int B = dvej(b, a);
    setRoad(A, B);
    renewComp(A, B);
}
void run(int N) {
    srand(time(0));
    n = N;
    for(int i = 1; i <= n; i++) comp.push_back({i});
    for(int i = 0; i < n-1; i++) {
        raskBriauna();
    }
}

Compilation message

icc.cpp: In function 'std::pair<std::vector<int>, std::vector<int> > randomPuse(int)':
icc.cpp:13:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |     for(int i = 0; i < vec.size(); i++) vec[i] = i;
      |                    ~~^~~~~~~~~~~~
icc.cpp: In function 'bool quer(std::vector<int>&, std::vector<int>&)':
icc.cpp:27:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for(int i = 0; i < a.size(); i++) mas1[i] = a[i];
      |                    ~~^~~~~~~~~~
icc.cpp:28:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for(int i = 0; i < b.size(); i++) mas2[i] = b[i];
      |                    ~~^~~~~~~~~~
icc.cpp: In function 'void renewComp(int, int)':
icc.cpp:71:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |     for(int i = 0; i < comp.size(); i++) {
      |                    ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 436 KB Ok! 117 queries used.
2 Correct 5 ms 432 KB Ok! 122 queries used.
# Verdict Execution time Memory Grader output
1 Correct 29 ms 468 KB Ok! 563 queries used.
2 Correct 43 ms 512 KB Ok! 855 queries used.
3 Correct 42 ms 468 KB Ok! 799 queries used.
# Verdict Execution time Memory Grader output
1 Correct 116 ms 504 KB Ok! 1528 queries used.
2 Correct 165 ms 504 KB Ok! 2127 queries used.
3 Correct 130 ms 588 KB Ok! 1739 queries used.
4 Correct 131 ms 504 KB Ok! 1730 queries used.
# Verdict Execution time Memory Grader output
1 Correct 131 ms 508 KB Ok! 1746 queries used.
2 Correct 130 ms 496 KB Ok! 1671 queries used.
3 Correct 148 ms 612 KB Ok! 1855 queries used.
4 Correct 119 ms 508 KB Ok! 1564 queries used.
# Verdict Execution time Memory Grader output
1 Incorrect 141 ms 496 KB Too many queries! 1859 out of 1775
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 153 ms 468 KB Too many queries! 1939 out of 1625
2 Halted 0 ms 0 KB -