답안 #451609

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
451609 2021-08-03T10:25:42 Z ACmachine 도서관 (JOI18_library) C++17
19 / 100
466 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, components.size()){
            if(components[j].size() > 0)
                setc.pb(j);
        }
        int conn = setc.size() - 1;
        while(setc.size() > 2){
            int tm = floor(sqrt(2.0/(double)conn));
            int h = max(2, tm);
            int num = max(2, (int)setc.size() / h);
            shuffle(all(setc), rng);
            vector<int> nsetc;
            REP(j, num){
                nsetc.pb(setc[j]);
            }
            fill(all(m), 0);
            REP(j, nsetc.size()){
                for(int x : components[nsetc[j]])
                    m[x] = 1;
            }
            int res = Query(m);
            res = nsetc.size() - res;
            if(res > 0){
                conn = res;
                nsetc.swap(setc);
            }
        }
        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;
        }
    }
}

Compilation message

library.cpp: In function 'void Solve(int)':
library.cpp:22:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 | #define FOR(i,j,k,in) for(int i=(j); i < (k);i+=in)
      |                                        ^
library.cpp:24:18: note: in expansion of macro 'FOR'
   24 | #define REP(i,b) FOR(i,0,b,1)
      |                  ^~~
library.cpp:72:9: note: in expansion of macro 'REP'
   72 |         REP(j, components.size()){
      |         ^~~
library.cpp:22:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 | #define FOR(i,j,k,in) for(int i=(j); i < (k);i+=in)
      |                                        ^
library.cpp:24:18: note: in expansion of macro 'FOR'
   24 | #define REP(i,b) FOR(i,0,b,1)
      |                  ^~~
library.cpp:87:13: note: in expansion of macro 'REP'
   87 |             REP(j, nsetc.size()){
      |             ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 200 KB # of queries: 3111
2 Correct 55 ms 292 KB # of queries: 3236
3 Correct 56 ms 200 KB # of queries: 3170
4 Correct 46 ms 292 KB # of queries: 3294
5 Correct 54 ms 288 KB # of queries: 3133
6 Correct 51 ms 288 KB # of queries: 3297
7 Correct 67 ms 308 KB # of queries: 3428
8 Correct 30 ms 200 KB # of queries: 3111
9 Correct 59 ms 200 KB # of queries: 3302
10 Correct 35 ms 292 KB # of queries: 1839
11 Correct 0 ms 200 KB # of queries: 0
12 Correct 1 ms 200 KB # of queries: 1
13 Correct 0 ms 200 KB # of queries: 3
14 Correct 1 ms 200 KB # of queries: 5
15 Correct 2 ms 200 KB # of queries: 83
16 Correct 5 ms 200 KB # of queries: 231
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 200 KB # of queries: 3111
2 Correct 55 ms 292 KB # of queries: 3236
3 Correct 56 ms 200 KB # of queries: 3170
4 Correct 46 ms 292 KB # of queries: 3294
5 Correct 54 ms 288 KB # of queries: 3133
6 Correct 51 ms 288 KB # of queries: 3297
7 Correct 67 ms 308 KB # of queries: 3428
8 Correct 30 ms 200 KB # of queries: 3111
9 Correct 59 ms 200 KB # of queries: 3302
10 Correct 35 ms 292 KB # of queries: 1839
11 Correct 0 ms 200 KB # of queries: 0
12 Correct 1 ms 200 KB # of queries: 1
13 Correct 0 ms 200 KB # of queries: 3
14 Correct 1 ms 200 KB # of queries: 5
15 Correct 2 ms 200 KB # of queries: 83
16 Correct 5 ms 200 KB # of queries: 231
17 Runtime error 466 ms 328 KB Execution killed with signal 13
18 Halted 0 ms 0 KB -