답안 #60911

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
60911 2018-07-25T01:05:05 Z Benq CEOI16_icc (CEOI16_icc) C++11
90 / 100
229 ms 1108 KB
#include "icc.h"
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;
 
template<int SZ> struct DSU {
    int par[SZ], sz[SZ];
    DSU() {
        F0R(i,SZ) par[i] = i, sz[i] = 1;
    }
    
    int get(int x) { // path compression
    	if (par[x] != x) par[x] = get(par[x]);
    	return par[x];
    }
    
    bool unite(int x, int y) { // union-by-rank
    	x = get(x), y = get(y);
    	if (x == y) return 0;
    	if (sz[x] < sz[y]) swap(x,y);
    	sz[x] += sz[y], par[y] = x;
    	return 1;
    }
};
 
DSU<101> D;
int N;
/*pi des;
 
int query(int size_a, int size_b, int a[], int b[]) {
    F0R(i,size_a) cout << a[i] << " ";
    cout << "| ";
    F0R(i,size_b) cout << b[i] << " ";
    cout << "|\n";
    F0R(i,size_a) F0R(j,size_b) {
        if (a[i] == des.f && b[j] == des.s) return 1;
        if (a[i] == des.s && b[j] == des.f) return 1;
    }
    return 0;
}*/
 
bool QUERY(vi a, vi b) {
    int A[sz(a)]; F0R(i,sz(a)) A[i] = a[i];
    int B[sz(b)]; F0R(i,sz(b)) B[i] = b[i];
    return query(sz(a),sz(b),A,B);
}
 
void ad(vi& a, vi b) { for (int i: b) a.pb(i); }
 
/*void setRoad(int a, int b) {
     cout << "AH " << a << " " << b << "\n";
     if (mp(a,b) == mp(3,1)) des = {4,2};
     else exit(0);
}*/
 
void bipartite(vi x, vi y) {
    while (1) {
        if (sz(x) < sz(y)) swap(x,y);
        if (sz(x) == 1) {
            D.unite(x[0],y[0]);
            setRoad(x[0],y[0]);
            return;
        }
        vi X = vi(x.begin(),x.begin()+sz(x)/2);
        if (QUERY(X,y)) x = X;
        else x = vi(x.begin()+sz(x)/2,x.end());
    }
}
 
void getBit(vector<vi> V) {
    int cur = 1;
    random_shuffle(all(V));
    while (1) {
        vi a,b;
        F0R(i,sz(V)) {
            if (i&cur) ad(a,V[i]);
            else ad(b,V[i]);
        }
        if (QUERY(a,b)) {
            bipartite(a,b);
            return;
        }
        cur *= 2;
    }
}
 
void solve() {
    vi v[101];
    FOR(i,1,N+1) v[D.get(i)].pb(i);
    vector<vi> V;
    FOR(i,1,N+1) if (sz(v[i])) V.pb(v[i]);
    getBit(V);
}
 
void run(int n) {
    N = n;
    F0R(i,N-1) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 504 KB Ok! 104 queries used.
2 Correct 11 ms 616 KB Ok! 102 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 616 KB Ok! 549 queries used.
2 Correct 85 ms 768 KB Ok! 689 queries used.
3 Correct 87 ms 876 KB Ok! 691 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 176 ms 876 KB Ok! 1448 queries used.
2 Correct 206 ms 876 KB Ok! 1676 queries used.
3 Correct 200 ms 904 KB Ok! 1588 queries used.
4 Correct 169 ms 956 KB Ok! 1551 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 159 ms 1012 KB Ok! 1505 queries used.
2 Correct 186 ms 1016 KB Ok! 1524 queries used.
3 Correct 185 ms 1016 KB Ok! 1673 queries used.
4 Correct 181 ms 1028 KB Ok! 1459 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 198 ms 1068 KB Ok! 1671 queries used.
2 Correct 198 ms 1076 KB Ok! 1701 queries used.
3 Correct 191 ms 1092 KB Ok! 1687 queries used.
4 Correct 229 ms 1092 KB Ok! 1664 queries used.
5 Correct 164 ms 1092 KB Ok! 1513 queries used.
6 Correct 210 ms 1108 KB Ok! 1608 queries used.
# 결과 실행 시간 메모리 Grader output
1 Incorrect 216 ms 1108 KB Too many queries! 1678 out of 1625
2 Halted 0 ms 0 KB -