답안 #1085344

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1085344 2024-09-08T05:42:47 Z browntoad CEOI16_icc (CEOI16_icc) C++14
61 / 100
105 ms 644 KB
#include <bits/stdc++.h>
#include "icc.h"
using namespace std;
#define ll long long
// #define int ll
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n+1)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define RREP1(i, n) for (int i = (n); i >= 1; i--)
#define pii pair<int, int>
#define ppi pair<pii, int>
#define pip pair<int, pii>
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)((x).size())
#define f first
#define s second
#define pb push_back
#define endl '\n'
#define IOS() ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
 
const ll maxn = 105;
const ll mod = 1e9+7;
const ll inf = 1ll<<60;
 
ll mpw(ll a, ll p, ll m = mod){
    ll ret = 1;
    while(p > 0){
        if (p & 1){
            ret *= a;
            ret %= m;
        }
        p >>= 1;
        a *= a;
        a %= m;
    }
    return ret;
}
ll inv(ll a){
    return mpw(a, mod-2);
}
 
/*
int query(int a, int b, int ara[], int arb[]){
    cout<<'?'<<' ';
    cout<<a<<' '<<b<<endl;
    REP(i, a) cout<<ara[i]<<' ';
    cout<<'&'<<' ';
    REP(i, b) cout<<arb[i]<<' ';
    cout<<endl;
    int in; cin>>in;
    return in;
}
 
void setRoad(int a, int b){
    cout<<'!'<<a<<' '<<b<<endl;
    int in; cin>>in;
    if (in == -1) exit(0);
}
*/
void run(int n){
    //assert(n <= 50);
    vector<vector<int>> cc;
    REP1(i, n){
        cc.pb({i});
    }
 
    int awoo = 0;
    REP(t, n-1){
        mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
        vector<int> tid; assert(n-t == SZ(cc));
        REP(i, n-t) tid.pb(i); random_shuffle(ALL(tid));
 
        int ret = -1;
        vector<int> t1, t2;
 
        while(1){
			if (SZ(t1)) t1.clear();
			if (SZ(t2)) t2.clear();
            REP(i, SZ(cc)){
                if (uniform_int_distribution<int>(0, 1)(rng)) for (int j:cc[tid[i]]) t1.pb(j);
                else for (int j:cc[tid[i]]) t2.pb(j);
            }
 
            if (SZ(t1) == 0 || SZ(t2) == 0) continue;
 
            ret = query(SZ(t1), SZ(t2), &t1[0], &t2[0]);
            awoo++;
            //assert(awoo <= 225);
            if (ret){
                break;
            }
        }
 
        int l = 0, r = SZ(t2)-1;
        while(l < r){
            int mid = (l+r)>>1;
            vector<int> tt;
            FOR(i, l, mid+1){
                tt.pb(t2[i]);
            }
 
            ret = query(SZ(t1), SZ(tt), &t1[0], &tt[0]);
            if (!ret) l = mid+1;
            else r = mid;
        }
        t2 = {t2[l]};
 
        l = 0, r = SZ(t1)-1;
        while(l < r){
            int mid = (l+r)>>1;
            vector<int> tt;
            FOR(i, l, mid+1){
                tt.pb(t1[i]);
            }
 
            ret = query(SZ(tt), 1, &tt[0], &t2[0]);
            if (!ret) l = mid+1;
            else r = mid;
        }
        t1 = {t1[l]};
 
        setRoad(t1[0], t2[0]);
 
        auto it = cc.begin();
        vector<int> nw;
        while(it != cc.end()){
            vector<int> tmp = (*it);
 
            bool ex = 0;
            for (auto j:tmp){
                if (j == t1[0] || j == t2[0]){
                    ex = 1;
                    break;
                }
            }
 
            if (ex) {
                for (auto j:tmp) nw.pb(j);
                it = cc.erase(it);
            }
            else it = next(it);
        }
        cc.pb(nw);
    }
}
/*
signed main(){
    run(5);
}
*/

Compilation message

icc.cpp: In function 'void run(int)':
icc.cpp:6:22: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
    6 | #define FOR(i, a, b) for(int i = (a); i < (b); i++)
      |                      ^~~
icc.cpp:7:19: note: in expansion of macro 'FOR'
    7 | #define REP(i, n) FOR(i, 0, n)
      |                   ^~~
icc.cpp:72:9: note: in expansion of macro 'REP'
   72 |         REP(i, n-t) tid.pb(i); random_shuffle(ALL(tid));
      |         ^~~
icc.cpp:72:32: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   72 |         REP(i, n-t) tid.pb(i); random_shuffle(ALL(tid));
      |                                ^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 604 KB Ok! 111 queries used.
2 Correct 4 ms 636 KB Ok! 106 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 604 KB Ok! 542 queries used.
2 Correct 33 ms 604 KB Ok! 878 queries used.
3 Correct 30 ms 604 KB Ok! 793 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 600 KB Ok! 1503 queries used.
2 Correct 105 ms 604 KB Ok! 2148 queries used.
3 Correct 83 ms 604 KB Ok! 1764 queries used.
4 Correct 82 ms 644 KB Ok! 1716 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 604 KB Ok! 1601 queries used.
2 Correct 83 ms 620 KB Ok! 1638 queries used.
3 Correct 88 ms 636 KB Ok! 1855 queries used.
4 Correct 77 ms 604 KB Ok! 1617 queries used.
# 결과 실행 시간 메모리 Grader output
1 Incorrect 102 ms 624 KB Too many queries! 1863 out of 1775
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 94 ms 604 KB Too many queries! 1942 out of 1625
2 Halted 0 ms 0 KB -