Submission #605473

# Submission time Handle Problem Language Result Execution time Memory
605473 2022-07-25T18:11:27 Z Vanilla ICC (CEOI16_icc) C++17
83 / 100
126 ms 1356 KB
#include "icc.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 102;
int dsu [maxn];
vector <int> el [maxn];
 
int dad (int x) {
    return dsu[x] = (x == dsu[x] ? x: dad(dsu[x]));
}
 
void merge (int x, int y){
    x = dad(x), y = dad(y);
    if (x != y) {
        if (el[x].size() < el[y].size()) swap(x, y);
        for (int j: el[y]) el[x].push_back(j);
        el[y].clear();
        dsu[y] = x;
    }
}

map <pair <vector <int> ,vector <int> >, int > mp;
 
int qq (vector <int> a, vector <int> b) {
    if (mp.count({a, b})) return mp[{a,b}];
    return mp[{a, b}] = query(a.size(), b.size(), a.data(), b.data());
}
 
void run(int n) {
    for (int i = 1; i <= n; i++) {
        dsu[i] = i;
        el[i].push_back(i);
    }
    for (int p = 0; p < n - 1; p++){
        set <int> s;
        vector <int> comp;
        for (int j = 1; j <= n; j++) s.insert(dad(j));
        for (int k: s) comp.push_back(k);
        int m = comp.size();
        vector <int> a,b;
        for (int i = 0; i <= 7; i++){
            vector <int> v1, v2;
            for (int j = 0; j < m; j++){
                if (j & (1 << i)) for (int l: el[comp[j]]) v1.push_back(l);
                else for (int l: el[comp[j]]) v2.push_back(l);
            }
            if (qq(v1, v2)) {
                a = v1, b = v2;
                break;
            }
        }
        int l = 0, r = a.size() - 1, rs1 = -1, rs2 = -1;
        while (l <= r) {
            int mid = (l + r) / 2;
            vector <int> v;
            for (int i = 0; i <= mid; i++) v.push_back(a[i]);
            if (qq(v, b)) {
                rs1 = v.back();
                r = mid - 1;
            }
            else {
                l = mid + 1;
            }
        }
        l = 0, r = b.size() - 1;
        while (l <= r) {
            int mid = (l + r) / 2;
            vector <int> v;
            for (int i = 0; i <= mid; i++) v.push_back(b[i]);
            if (qq(v, a)) {
                rs2 = v.back();
                r = mid - 1;
            }
            else {
                l = mid + 1;
            }
        }
        merge(rs1, rs2);
        setRoad(rs1, rs2);
    }
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 468 KB Ok! 99 queries used.
2 Incorrect 6 ms 468 KB Wrong road!
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 30 ms 604 KB Ok! 545 queries used.
2 Correct 35 ms 612 KB Ok! 676 queries used.
3 Correct 33 ms 632 KB Ok! 659 queries used.
# Verdict Execution time Memory Grader output
1 Correct 104 ms 1048 KB Ok! 1479 queries used.
2 Correct 109 ms 1192 KB Ok! 1618 queries used.
3 Correct 126 ms 1356 KB Ok! 1670 queries used.
4 Correct 111 ms 1140 KB Ok! 1549 queries used.
# Verdict Execution time Memory Grader output
1 Correct 110 ms 1172 KB Ok! 1502 queries used.
2 Correct 112 ms 1200 KB Ok! 1578 queries used.
3 Correct 124 ms 1212 KB Ok! 1642 queries used.
4 Correct 116 ms 1084 KB Ok! 1559 queries used.
# Verdict Execution time Memory Grader output
1 Correct 113 ms 1188 KB Ok! 1635 queries used.
2 Correct 113 ms 1240 KB Ok! 1618 queries used.
3 Correct 118 ms 1220 KB Ok! 1643 queries used.
4 Correct 119 ms 1180 KB Ok! 1658 queries used.
5 Correct 118 ms 1128 KB Ok! 1494 queries used.
6 Correct 114 ms 1168 KB Ok! 1567 queries used.
# Verdict Execution time Memory Grader output
1 Incorrect 112 ms 1260 KB Too many queries! 1642 out of 1625
2 Halted 0 ms 0 KB -