답안 #717949

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
717949 2023-04-02T22:28:17 Z stevancv CEOI16_icc (CEOI16_icc) C++14
61 / 100
169 ms 720 KB
#include <bits/stdc++.h>
#include "icc.h"
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 100 + 2;
const int inf = 1e9;
vector<int> svi[N];
int aaa[N], bbb[N];
int Query(vector<int> a, vector<int> b) {
    int A = a.size(); int B = b.size();
    for (int i = 0; i < A; i++) aaa[i] = a[i];
    for (int i = 0; i < B; i++) bbb[i] = b[i];
    return query(A, B, aaa, bbb);
}
int gazda[N];
void run(int n) {
    vector<int> v;
    for (int i = 1; i <= n; i++) {
        svi[i].push_back(i);
        gazda[i] = i;
    }
    auto Sredi = [&] (vector<int> v) {
        vector<int> ret;
        for (int i = 0; i < v.size(); i++) {
            for (int j : svi[v[i]]) ret.push_back(j);
        }
        return ret;
    };
    for (int zz = 0; zz < n - 1; zz++) {
        vector<int> v;
        for (int i = 1; i <= n; i++) {
            if (gazda[i] == i) v.push_back(i);
        }
        int sz = v.size();
        vector<int> a, b;
        while (1) {
            random_shuffle(v.begin(), v.end());
            int seci = rand() % n;
            for (int i = 0; i < sz / 2; i++) a.push_back(v[(i + seci) % sz]);
            for (int i = sz / 2; i < sz; i++) b.push_back(v[(i + seci) % sz]);
            auto aa = Sredi(a); auto bb = Sredi(b);
            if (Query(aa, bb) == 1) break;
            else {a.clear(); b.clear();}
        }
        a = Sredi(a); b = Sredi(b);
        int l = 0, r = a.size() - 2, inda = a.back();
        while (l <= r) {
            int mid = l + r >> 1;
            vector<int> tr;
            for (int i = 0; i <= mid; i++) tr.push_back(a[i]);
            if (Query(tr, b) == 1) {
                inda = a[mid];
                r = mid - 1;
            }
            else l = mid + 1;
        }
        l = 0, r = b.size() - 2;
        int indb = b.back();
        while (l <= r) {
            int mid = l + r >> 1;
            vector<int> tr;
            for (int i = 0; i <= mid; i++) tr.push_back(b[i]);
            if (Query({inda}, tr) == 1) {
                indb = b[mid];
                r = mid - 1;
            }
            else l = mid + 1;
        }
        setRoad(inda, indb);
        while (gazda[inda] != inda) inda = gazda[inda];
        while (gazda[indb] != indb) indb = gazda[indb];
        for (int i : svi[indb]) {
            svi[inda].push_back(i);
          	assert(gazda[i] == indb);
            gazda[i] = inda;
        }
        svi[indb].clear();
    }
}

Compilation message

icc.cpp: In lambda function:
icc.cpp:29:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |         for (int i = 0; i < v.size(); i++) {
      |                         ~~^~~~~~~~~~
icc.cpp: In function 'void run(int)':
icc.cpp:53:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   53 |             int mid = l + r >> 1;
      |                       ~~^~~
icc.cpp:65:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   65 |             int mid = l + r >> 1;
      |                       ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 468 KB Ok! 101 queries used.
2 Correct 6 ms 496 KB Ok! 101 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 484 KB Ok! 570 queries used.
2 Correct 51 ms 488 KB Ok! 852 queries used.
3 Correct 43 ms 496 KB Ok! 827 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 112 ms 504 KB Ok! 1510 queries used.
2 Correct 167 ms 488 KB Ok! 2128 queries used.
3 Correct 115 ms 500 KB Ok! 1632 queries used.
4 Correct 119 ms 720 KB Ok! 1668 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 116 ms 496 KB Ok! 1649 queries used.
2 Correct 117 ms 492 KB Ok! 1660 queries used.
3 Correct 134 ms 496 KB Ok! 1824 queries used.
4 Correct 114 ms 616 KB Ok! 1580 queries used.
# 결과 실행 시간 메모리 Grader output
1 Incorrect 169 ms 512 KB Too many queries! 1842 out of 1775
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 138 ms 496 KB Too many queries! 1901 out of 1625
2 Halted 0 ms 0 KB -