제출 #1356319

#제출 시각아이디문제언어결과실행 시간메모리
1356319Zbyszek99Voltage 2 (JOI26_voltage)C++20
100 / 100
43 ms948 KiB
#include "voltage.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define ull unsigned long long
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define rep(i, b) for(int i = 0; i < (b); ++i)
#define rep2(i,a,b) for(int i = a; i <= (b); ++i)
#define rep3(i,a,b,c) for(int i = a; i <= (b); i+=c)
#define count_bits(x) __builtin_popcountll((x))
#define all(x) (x).begin(),(x).end()
#define siz(x) (int)(x).size()
#define forall(it,x) for(auto& it:(x))
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//mt19937 mt;void random_start(){mt.seed(chrono::time_point_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());}
//ll los(ll a, ll b) {return a + (mt() % (b-a+1));}
const int INF = 1e9+50;
const ll INF_L = 1e18+40;
const ll MOD = 1e9+7;

bool solve(int n, int m) 
{
    vector<pii> edges;
    vi is_in(n,0);
    vi zero(n,0);
    queue<int> q2;
    rep(i,n)
    {
        vi q(n,1);
        q[i] = 0;
        if(query(zero,q) == 0) q2.push(i);
    }
    while(!q2.empty())
    {
        int v = q2.front();
        q2.pop();
        is_in[v] = 1;
        vi rest;
        rep(i,n) if(!is_in[i]) rest.pb(i);
        while(true)
        {
            vi q(n,1);
            rep(i,n) if(is_in[i]) q[i] = 0;
            forall(it,rest) q[it] = 0;
            q[v] = 0;
            vi q3 = q;
            q3[v] = 1;
            if(query(q,q3) == 0) break;
            int l = 0;
            int r = siz(rest)-1;
            int ans = 0;
            while(l <= r)
            {
                int mid = (l+r)/2;
                rep(i,n) q[i] = 1;
                rep(i,n) if(is_in[i]) q[i] = 0;
                rep(i,mid+1) q[rest[i]] = 0;
                q[v] = 0;
                q3 = q;
                q3[v] = 1;
                if(query(q,q3) != 0)
                {
                    ans = mid;
                    r = mid-1;
                }
                else l = mid+1;
            }
            edges.pb({v,rest[ans]});
            vi check(n,1);
            rep(i,n) if(is_in[i]) check[i] = 0;
            check[rest[ans]] = 0;
            if(query(check,zero) == 0) q2.push(rest[ans]);
            vi rest2;
            rep2(i,ans+1,siz(rest)-1) rest2.pb(rest[i]);
            rest = rest2;
        }
    }
    if(siz(edges) != m) return 0;
    forall(it,edges) answer(it.ff,it.ss);
    return 1;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...