#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);
}
while(setc.size() > 2){
int num = max(2, (int)setc.size() / 3);
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);
if(res < nsetc.size()){
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:84:13: note: in expansion of macro 'REP'
84 | REP(j, nsetc.size()){
| ^~~
library.cpp:89:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
89 | if(res < nsetc.size()){
| ~~~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
412 KB |
# of queries: 3459 |
2 |
Correct |
57 ms |
292 KB |
# of queries: 3580 |
3 |
Correct |
76 ms |
288 KB |
# of queries: 4254 |
4 |
Correct |
45 ms |
292 KB |
# of queries: 3691 |
5 |
Correct |
38 ms |
292 KB |
# of queries: 4031 |
6 |
Correct |
74 ms |
292 KB |
# of queries: 4022 |
7 |
Correct |
77 ms |
292 KB |
# of queries: 4386 |
8 |
Correct |
56 ms |
200 KB |
# of queries: 3528 |
9 |
Correct |
58 ms |
292 KB |
# of queries: 4058 |
10 |
Correct |
34 ms |
200 KB |
# of queries: 2023 |
11 |
Correct |
0 ms |
200 KB |
# of queries: 0 |
12 |
Correct |
1 ms |
200 KB |
# of queries: 1 |
13 |
Correct |
1 ms |
200 KB |
# of queries: 5 |
14 |
Correct |
1 ms |
200 KB |
# of queries: 9 |
15 |
Correct |
2 ms |
200 KB |
# of queries: 80 |
16 |
Correct |
2 ms |
200 KB |
# of queries: 214 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
412 KB |
# of queries: 3459 |
2 |
Correct |
57 ms |
292 KB |
# of queries: 3580 |
3 |
Correct |
76 ms |
288 KB |
# of queries: 4254 |
4 |
Correct |
45 ms |
292 KB |
# of queries: 3691 |
5 |
Correct |
38 ms |
292 KB |
# of queries: 4031 |
6 |
Correct |
74 ms |
292 KB |
# of queries: 4022 |
7 |
Correct |
77 ms |
292 KB |
# of queries: 4386 |
8 |
Correct |
56 ms |
200 KB |
# of queries: 3528 |
9 |
Correct |
58 ms |
292 KB |
# of queries: 4058 |
10 |
Correct |
34 ms |
200 KB |
# of queries: 2023 |
11 |
Correct |
0 ms |
200 KB |
# of queries: 0 |
12 |
Correct |
1 ms |
200 KB |
# of queries: 1 |
13 |
Correct |
1 ms |
200 KB |
# of queries: 5 |
14 |
Correct |
1 ms |
200 KB |
# of queries: 9 |
15 |
Correct |
2 ms |
200 KB |
# of queries: 80 |
16 |
Correct |
2 ms |
200 KB |
# of queries: 214 |
17 |
Runtime error |
427 ms |
328 KB |
Execution killed with signal 13 |
18 |
Halted |
0 ms |
0 KB |
- |