답안 #451707

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
451707 2021-08-03T11:24:47 Z ACmachine 도서관 (JOI18_library) C++17
19 / 100
448 ms 328 KB
#include <cstdio>
#include <vector>
#include <bits/stdc++.h>
#include "library.h"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename U> using ordered_map = tree<T, U, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vi;
typedef vector<ll> vll;

#define FOR(i,j,k,in) for(int i=(j); i < (k);i+=in)
#define FORD(i,j,k,in) for(int i=(j); i >=(k);i-=in)
#define REP(i,b) FOR(i,0,b,1)
#define REPD(i,b) FORD(i,b,0,1)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) begin(x), end(x)
#define MANY_TESTS int tcase; cin >> tcase; while(tcase--)

const double EPS = 1e-9;
const int MOD = 1e9+7;
const ll INFF = 1e18;
const int INF = 1e9;
const ld PI = acos((ld)-1);
const vi dy = {1, 0, -1, 0, -1, 1, 1, -1};
const vi dx = {0, 1, 0, -1, -1, 1, -1, 1};

void DBG(){cout << "]" << endl;}
template<typename T, typename ...U> void DBG(const T& head, const U... args){ cout << head << "; "; DBG(args...); }
#define dbg(...) cout << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__);
#define chk() cout << "Check at line(" << __LINE__ << ") hit." << endl;

template<class T, unsigned int U>
ostream& operator<<(ostream& out, const array<T, U> &v){out << "[";  REP(i, U) out << v[i] << ", ";  out << "]"; return out;}
template <class T, class U>
ostream& operator<<(ostream& out, const pair<T, U> &par) {out << "[" << par.first << ";" << par.second << "]"; return out;}
template <class T>
ostream& operator<<(ostream& out, const set<T> &cont) { out << "{"; for( const auto &x:cont) out << x << ", "; out << "}"; return out; }
template <class T, class U>
ostream& operator<<(ostream& out, const map<T, U> &cont) {out << "{"; for( const auto &x:cont) out << x << ", "; out << "}"; return out; }
template<class T>
ostream& operator<<(ostream& out, const vector<T> &v){ out << "[";  REP(i, v.size()) out << v[i] << ", ";  out << "]"; return out;}

template<class T>
istream& operator>>(istream& in, vector<T> &v){ for(auto &x : v) in >> x; return in; }

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


void Solve(int n)
{
	vector<int> m(n);
    vector<vector<int>> components(n);
    REP(i, n){
        components[i].pb(i);
    }
    REP(i, n - 1){
        vector<int> setc;
        REP(j, n){
            if(components[j].size() > 0)
                setc.pb(j);
        }
        int bk = setc.back();
        setc.pop_back();
        int l = 0;
        int r = setc.size();
        while((r - l) > 1){
            int mid = (l + r) >> 1;
            fill(all(m), 0);
            FOR(j, l, mid, 1){
                for(int x : components[setc[j]])
                    m[x] = 1;
            }
            int f = Query(m);
            for(int x : components[bk])
                m[x] = 1;
            int s = Query(m);
            if(s <= f){
                r = mid;
            }
            else{
                l = mid;
            }
        }
        int sec = setc[l];
        setc.clear();
        setc = {bk, sec};
        // aby som mohol reusnut kod
        bool found = false;
        REP(j, 2){
            if(found) break;
            REP(k, 2){
                int u = (j == 0 ? components[setc[0]][0] : components[setc[0]].back());
                int v = (k == 0 ? components[setc[1]][0] : components[setc[1]].back());
                fill(all(m), 0);
                m[u] = m[v] = 1;
                if((j == 1 && k == 1) || (Query(m) < 2)){
                    found = true;
                    if(j == 0)
                        reverse(all(components[setc[0]]));
                    if(k == 1)
                        reverse(all(components[setc[1]]));
                    for(int x : components[setc[1]])
                        components[setc[0]].pb(x);
                    components[setc[1]].clear();
                    break;
                }
            }
        }
    }
    REP(i, n){
        if(components[i].size() > 0){
            for(int& x : components[i])
                x++;
            Answer(components[i]);
            break;
        }
    }

}
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 308 KB # of queries: 2941
2 Correct 42 ms 200 KB # of queries: 2920
3 Correct 40 ms 200 KB # of queries: 3099
4 Correct 52 ms 200 KB # of queries: 3087
5 Correct 47 ms 200 KB # of queries: 3081
6 Correct 29 ms 200 KB # of queries: 3079
7 Correct 56 ms 200 KB # of queries: 3081
8 Correct 51 ms 304 KB # of queries: 2944
9 Correct 52 ms 200 KB # of queries: 3078
10 Correct 28 ms 200 KB # of queries: 1828
11 Correct 0 ms 200 KB # of queries: 0
12 Correct 0 ms 200 KB # of queries: 1
13 Correct 1 ms 200 KB # of queries: 6
14 Correct 1 ms 200 KB # of queries: 13
15 Correct 2 ms 200 KB # of queries: 112
16 Correct 5 ms 200 KB # of queries: 244
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 308 KB # of queries: 2941
2 Correct 42 ms 200 KB # of queries: 2920
3 Correct 40 ms 200 KB # of queries: 3099
4 Correct 52 ms 200 KB # of queries: 3087
5 Correct 47 ms 200 KB # of queries: 3081
6 Correct 29 ms 200 KB # of queries: 3079
7 Correct 56 ms 200 KB # of queries: 3081
8 Correct 51 ms 304 KB # of queries: 2944
9 Correct 52 ms 200 KB # of queries: 3078
10 Correct 28 ms 200 KB # of queries: 1828
11 Correct 0 ms 200 KB # of queries: 0
12 Correct 0 ms 200 KB # of queries: 1
13 Correct 1 ms 200 KB # of queries: 6
14 Correct 1 ms 200 KB # of queries: 13
15 Correct 2 ms 200 KB # of queries: 112
16 Correct 5 ms 200 KB # of queries: 244
17 Runtime error 448 ms 328 KB Execution killed with signal 13
18 Halted 0 ms 0 KB -