답안 #1072084

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1072084 2024-08-23T14:07:19 Z vjudge1 CEOI16_icc (CEOI16_icc) C++17
100 / 100
88 ms 856 KB
#include "icc.h"
#include <bits/stdc++.h>
using namespace std;
int p[105], s[105];
vector<int> v[105];
int Find(int x) {
    if (x == p[x]) return x;
    return p[x] = Find(p[x]);
}
void Merge(int x, int y) {
    x = Find(x);
    y = Find(y);
    if (x == y) return;
    if (s[x] < s[y]) swap(x, y);
    s[x] += s[y];
    p[y] = x;
}
/*int query(int n, int m, int a[], int b[]) {
    cout << n << " " << m << endl;
    for (int i = 0; i < n; i++) cout << a[i] << " ";
    cout << endl;
    for (int i = 0; i < m; i++) cout << b[i] << " ";
    cout << endl;
    int k;
    cin >> k;
    return k;
}*/
int query(vector<int> a, vector<int> b) {
    int c[a.size()], d[b.size()];
    for (int i = 0; i < a.size(); i++) c[i] = a[i];
    for (int i = 0; i < b.size(); i++) d[i] = b[i];
    return query(a.size(), b.size(), c, d);
}
void run(int n) {
    unsigned rr = std::chrono::system_clock::now().time_since_epoch().count();
    for (int i = 1; i <= n; i++) {
        p[i] = i;
        s[i] = 1;
    }
    for (int i = 1; i < n; i++) {
        for (int j = 1; j <= n; j++) {
            v[j].clear();
        }
        for (int j = 1; j <= n; j++) {
            int h = Find(j);
            v[h].push_back(j);
        }
        vector<int> vv, va, vb;
        for (int j = 1; j <= n; j++) {
            if (!v[j].empty()) {
                vv.push_back(j);
            }
        }
        shuffle(vv.begin(), vv.end(), default_random_engine(rr));
        for (int j = 0; j < 7; j++) {
            vector<int> a, b;
            for (int i = 0; i < vv.size(); i++) {
                int w = vv[i];
                if (i & (1 << j)) {
                    for (int ww : v[w]) a.push_back(ww);
                }
                else {
                    for (int ww : v[w]) b.push_back(ww);
                }
            }
            if (a.empty() || b.empty()) continue;
            if (query(a, b)) {
                va = a;
                vb = b;
                break;
            }
        }
        shuffle(va.begin(), va.end(), default_random_engine(rr));
        shuffle(vb.begin(), vb.end(), default_random_engine(rr));
        int l = 0, r = va.size() - 1, res;
        while (l != r) {
            int mid = (l + r) / 2;
            vector<int> vc;
            for (int i = l; i <= mid; i++) {
                vc.push_back(va[i]);
            }
            if (query(vc, vb)) {
                r = mid;
            }
            else l = mid + 1;
        }
        res = l;
        l = 0; r = vb.size() - 1;
        while (l != r) {
            int mid = (l + r) / 2;
            vector<int> vc;
            for (int i = l; i <= mid; i++) {
                vc.push_back(vb[i]);
            }
            if (query(va, vc)) {
                r = mid;
            }
            else l = mid + 1;
        }
        setRoad(va[res], vb[l]);
        Merge(va[res], vb[l]);
    }
}
/*int main() {
    run(4);
}*/

Compilation message

icc.cpp: In function 'int query(std::vector<int>, std::vector<int>)':
icc.cpp:30:23: 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 < a.size(); i++) c[i] = a[i];
      |                     ~~^~~~~~~~~~
icc.cpp:31:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     for (int i = 0; i < b.size(); i++) d[i] = b[i];
      |                     ~~^~~~~~~~~~
icc.cpp: In function 'void run(int)':
icc.cpp:57:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |             for (int i = 0; i < vv.size(); i++) {
      |                             ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 632 KB Ok! 102 queries used.
2 Correct 4 ms 604 KB Ok! 96 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 600 KB Ok! 528 queries used.
2 Correct 27 ms 640 KB Ok! 648 queries used.
3 Correct 27 ms 604 KB Ok! 642 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 71 ms 600 KB Ok! 1394 queries used.
2 Correct 88 ms 620 KB Ok! 1595 queries used.
3 Correct 84 ms 600 KB Ok! 1476 queries used.
4 Correct 77 ms 636 KB Ok! 1505 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 604 KB Ok! 1486 queries used.
2 Correct 75 ms 604 KB Ok! 1470 queries used.
3 Correct 80 ms 640 KB Ok! 1584 queries used.
4 Correct 82 ms 600 KB Ok! 1436 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 604 KB Ok! 1584 queries used.
2 Correct 81 ms 632 KB Ok! 1578 queries used.
3 Correct 82 ms 600 KB Ok! 1593 queries used.
4 Correct 82 ms 620 KB Ok! 1588 queries used.
5 Correct 77 ms 856 KB Ok! 1469 queries used.
6 Correct 78 ms 600 KB Ok! 1504 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 600 KB Ok! 1566 queries used.
2 Correct 82 ms 632 KB Ok! 1604 queries used.