답안 #1072071

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1072071 2024-08-23T13:59:33 Z adaawf CEOI16_icc (CEOI16_icc) C++17
90 / 100
96 ms 856 KB
#include "icc.h"
#include <iostream>
#include <vector>
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) {
    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);
            }
        }
        for (int j = 0; j < 7; j++) {
            vector<int> a, b;
            for (int w : vv) {
                if (w & (1 << j)) {
                    for (int ww : v[w]) a.push_back(ww);
                }
                else {
                    for (int ww : v[w]) b.push_back(ww);
                }
            }
            if (query(a, b)) {
                va = a;
                vb = b;
                break;
            }
        }
        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: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 < a.size(); i++) c[i] = a[i];
      |                     ~~^~~~~~~~~~
icc.cpp:32:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     for (int i = 0; i < b.size(); i++) d[i] = b[i];
      |                     ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 604 KB Ok! 106 queries used.
2 Correct 4 ms 640 KB Ok! 97 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 636 KB Ok! 533 queries used.
2 Correct 31 ms 600 KB Ok! 678 queries used.
3 Correct 29 ms 600 KB Ok! 662 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 80 ms 636 KB Ok! 1306 queries used.
2 Correct 92 ms 648 KB Ok! 1693 queries used.
3 Correct 71 ms 644 KB Ok! 1316 queries used.
4 Correct 83 ms 604 KB Ok! 1488 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 80 ms 640 KB Ok! 1395 queries used.
2 Correct 90 ms 600 KB Ok! 1425 queries used.
3 Correct 88 ms 600 KB Ok! 1605 queries used.
4 Correct 77 ms 600 KB Ok! 1320 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 89 ms 604 KB Ok! 1618 queries used.
2 Correct 88 ms 604 KB Ok! 1605 queries used.
3 Correct 94 ms 620 KB Ok! 1654 queries used.
4 Correct 84 ms 624 KB Ok! 1557 queries used.
5 Correct 77 ms 856 KB Ok! 1416 queries used.
6 Correct 86 ms 628 KB Ok! 1558 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 96 ms 600 KB Ok! 1617 queries used.
2 Incorrect 92 ms 604 KB Too many queries! 1684 out of 1625
3 Halted 0 ms 0 KB -