Submission #680284

# Submission time Handle Problem Language Result Execution time Memory
680284 2023-01-10T13:03:35 Z peijar ICC (CEOI16_icc) C++17
100 / 100
118 ms 612 KB
#include "icc.h"
#include <bits/stdc++.h>
#define FOR(i, x, y) for (int i = x; i < y; i++)
using namespace std;
 
vector<int> a, b, cmp[101], graph[101];
bool visited[101];
 
void dfs(int node, int idx) {
    visited[node] = true;
    cmp[idx].push_back(node);
    for (int i : graph[node]) if (!visited[i]) dfs(i, idx);
}
 
void run (int n) {
    while (true) {
        int idx = 0;
        for (int i = 1; i <= n; i++)
            if (!visited[i]) dfs(i, idx++);
 
        for (int i = 0; ; i++) {
            // Check if the current split has a path between stuff
            a.clear(); b.clear();
            FOR(j, 0, idx) {
                for (int k : cmp[j]) {
                    if ((j >> i) & 1) a.push_back(k);
                    else b.push_back(k);
                }
            }
 
            if (!query(a.size(), b.size(), a.data(), b.data())) continue;
 
            // Find the exact bits
            int exact = 0;
            FOR(k, 0, i) {
                a.clear(); b.clear();
                FOR(j, 0, idx) {
                    if ((j & ((1 << (k + 1)) - 1)) == exact) {
                        for (int l : cmp[j]) {
                            if ((j >> i) & 1) a.push_back(l);
                            else b.push_back(l);
                        }
                    }
                }
 
                if (!query(a.size(), b.size(), a.data(), b.data())) exact |= (1 << k);
            }
 
            // Binary search in the component
            a.clear(); b.clear();
            FOR(j, 0, idx) {
                if ((j & ((1 << i) - 1)) == exact) {
                    for (int k : cmp[j]) {
                        if ((j >> i) & 1) a.push_back(k);
                        else b.push_back(k);
                    }
                }
            }
 
            while (a.size() > 1) {
                if (query(a.size() / 2, b.size(), a.data(), b.data())) a.erase(a.begin() + a.size() / 2, a.end());
                else a.erase(a.begin(), a.begin() + a.size() / 2);
            }
            while (b.size() > 1) {
                if (query(b.size() / 2, a.size(), b.data(), a.data())) b.erase(b.begin() + b.size() / 2, b.end());
                else b.erase(b.begin(), b.begin() + b.size() / 2);
            }
 
            int u = a[0], v = b[0];
            graph[u].push_back(v);
            graph[v].push_back(u);
            setRoad(u, v);
            break;
        }
 
        memset(visited, 0, sizeof(visited));
        FOR(i, 0, idx) cmp[i].clear();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 500 KB Ok! 97 queries used.
2 Correct 5 ms 468 KB Ok! 98 queries used.
# Verdict Execution time Memory Grader output
1 Correct 30 ms 500 KB Ok! 520 queries used.
2 Correct 38 ms 468 KB Ok! 571 queries used.
3 Correct 33 ms 468 KB Ok! 613 queries used.
# Verdict Execution time Memory Grader output
1 Correct 89 ms 492 KB Ok! 1430 queries used.
2 Correct 93 ms 488 KB Ok! 1385 queries used.
3 Correct 104 ms 468 KB Ok! 1464 queries used.
4 Correct 105 ms 492 KB Ok! 1481 queries used.
# Verdict Execution time Memory Grader output
1 Correct 98 ms 612 KB Ok! 1450 queries used.
2 Correct 100 ms 468 KB Ok! 1467 queries used.
3 Correct 94 ms 488 KB Ok! 1468 queries used.
4 Correct 94 ms 496 KB Ok! 1463 queries used.
# Verdict Execution time Memory Grader output
1 Correct 118 ms 492 KB Ok! 1550 queries used.
2 Correct 92 ms 504 KB Ok! 1468 queries used.
3 Correct 93 ms 468 KB Ok! 1446 queries used.
4 Correct 95 ms 592 KB Ok! 1468 queries used.
5 Correct 112 ms 504 KB Ok! 1455 queries used.
6 Correct 101 ms 468 KB Ok! 1462 queries used.
# Verdict Execution time Memory Grader output
1 Correct 91 ms 500 KB Ok! 1468 queries used.
2 Correct 92 ms 468 KB Ok! 1468 queries used.