Submission #604556

# Submission time Handle Problem Language Result Execution time Memory
604556 2022-07-25T07:33:19 Z generic_placeholder_name ICC (CEOI16_icc) C++17
100 / 100
533 ms 624 KB
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma,popcnt")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define gcd __gcd
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define rep(i, n) for (int i=0; i<(n); i++)
#define rep1(i, n) for (int i=1; i<=(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define endl "\n"

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned uint;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
template<typename T, typename cmp = less<T>>
using ordered_set = tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
typedef trie<string, null_type, trie_string_access_traits<>, pat_trie_tag, trie_prefix_search_node_update> pref_trie;

constexpr int N = 105;
int color[N];
bool ban[N][N];
vi adj[N];

void dfs(int u) {
    for(int v: adj[u]) if(!~color[v]) {
        color[v] = color[u];
        dfs(v);
    }
}

#include "icc.h"

int query(vi& a, vi& b) {
    return query(a.size(), b.size(), a.data(), b.data());
}

void run(int N) {
    int& n = N;
    rep(_, n - 1) {
        vi l, r;
        memset(ban, 0, sizeof(ban));
        while(1) {
            int mx = 0;
            rep(_, 200) {
                memset(color, -1, sizeof(color));
                rep1(i, n) if(!~color[i]) {
                    color[i] = rng() & 1;
                    dfs(i);
                }
                vi cl, cr;
                rep1(i, n) (color[i] ? cl : cr).pb(i);
                int cnt = 0;
                for(int x: cl) for(int y: cr) cnt += !ban[x][y];
                if(cnt > mx) mx = cnt, l = cl, r = cr;
            }
            if(query(l, r)) break;
            else {
                for(int x: l) for(int y: r) ban[x][y] = ban[y][x] = 1;
            }
        }
        while(l.size() > 1 || r.size() > 1) {
            shuffle(all(l), rng);
            shuffle(all(r), rng);
            vi a, b;
            if(l.size() > 1) {
                rep(i, l.size()) (i & 1 ? a : b).pb(l[i]);
                if(query(a, r)) l = a;
                else l = b;
                a.clear(), b.clear();
            }
            vi rr;
            for(int x: r) {
                bool ok = 0;
                for(int y: l) if(!ban[x][y]) {ok = 1; break;}
                if(ok) rr.pb(x);
            }
            r = rr;
            if(r.size() > 1) {
                rep(i, r.size()) (i & 1 ? a : b).pb(r[i]);
                if(query(l, a)) r = a;
                else r = b;
            }
            vi ll;
            for(int x: l) {
                bool ok = 0;
                for(int y: r) if(!ban[x][y]) {ok = 1; break;}
                if(ok) ll.pb(x);
            }
            l = ll;
        }
        int u = l[0], v = r[0];
        adj[u].pb(v);
        adj[v].pb(u);
        setRoad(u, v);
    }
}

Compilation message

icc.cpp: In function 'void run(int)':
icc.cpp:23:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 | #define rep(i, n) for (int i=0; i<(n); i++)
      |                                  ^
icc.cpp:92:17: note: in expansion of macro 'rep'
   92 |                 rep(i, l.size()) (i & 1 ? a : b).pb(l[i]);
      |                 ^~~
icc.cpp:23:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 | #define rep(i, n) for (int i=0; i<(n); i++)
      |                                  ^
icc.cpp:105:17: note: in expansion of macro 'rep'
  105 |                 rep(i, r.size()) (i & 1 ? a : b).pb(r[i]);
      |                 ^~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 468 KB Ok! 97 queries used.
2 Correct 6 ms 468 KB Ok! 96 queries used.
# Verdict Execution time Memory Grader output
1 Correct 45 ms 468 KB Ok! 515 queries used.
2 Correct 99 ms 504 KB Ok! 453 queries used.
3 Correct 96 ms 492 KB Ok! 481 queries used.
# Verdict Execution time Memory Grader output
1 Correct 226 ms 508 KB Ok! 1267 queries used.
2 Correct 515 ms 624 KB Ok! 1077 queries used.
3 Correct 218 ms 496 KB Ok! 1249 queries used.
4 Correct 341 ms 512 KB Ok! 1249 queries used.
# Verdict Execution time Memory Grader output
1 Correct 298 ms 512 KB Ok! 1229 queries used.
2 Correct 320 ms 508 KB Ok! 1240 queries used.
3 Correct 497 ms 500 KB Ok! 1197 queries used.
4 Correct 217 ms 500 KB Ok! 1263 queries used.
# Verdict Execution time Memory Grader output
1 Correct 457 ms 504 KB Ok! 1172 queries used.
2 Correct 454 ms 504 KB Ok! 1172 queries used.
3 Correct 498 ms 500 KB Ok! 1177 queries used.
4 Correct 418 ms 620 KB Ok! 1215 queries used.
5 Correct 314 ms 504 KB Ok! 1259 queries used.
6 Correct 392 ms 496 KB Ok! 1241 queries used.
# Verdict Execution time Memory Grader output
1 Correct 458 ms 516 KB Ok! 1180 queries used.
2 Correct 533 ms 508 KB Ok! 1109 queries used.