# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
116709 |
2019-06-13T15:46:11 Z |
claudy |
Library (JOI18_library) |
C++14 |
|
526 ms |
648 KB |
# pragma GCC optimize("Ofast")
# pragma GCC optimization ("unroll-loops")
# include "bits/stdc++.h"
std::pair<int,int> DR[] = {{-1,0},{0,1},{1,0},{0,-1},{-1,1},{-1,-1},{1,1},{1,-1}};
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define rcg(s) cout << s;exit(0)
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define all(s) s.begin(),s.end()
# define sz(x) (int)((x).size())
//# define int ll
using namespace std;
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# define LOCAL
# define sim template < class c
# define ris return * this
# define dor > debug & operator <<
# define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define show(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
int gcd(int a, int b)
{
if(b) return gcd(b,a%b);
return a;
}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int Query(const std::vector<int>& M);
void Answer(const std::vector<int>& res);
# include "library.h"
/*int Query(vector<int>vec)
{
for(int i = 0;i < sz(vec);i++)
{
if(vec[i]) cout << i + 1 << ' ';
}
cout << endl;
int x;
cin >> x;
return x;
}
void Answer(vector<int>vec)
{
for(auto it : vec) cout << it << ' ';
}*/
set<int>s;
vector<int>M;
int n;
vector<int>vec;
int k = 0;
bool B = 0;
void solve(int x,int par)
{
if(x == -1) return;
s.erase(x);
vec.pb(x);
int l = 0;
int r = sz(s) - 1;
while(l < r)
{
int mid = l + r >> 1;
for(int i = 0;i < n;i++)
{
M[i] = 0;
}
M[par - 1] = 1;
auto it = s.begin();
for(int i = 0;i <= mid;i++)
{
M[*it - 1] = 1;
it++;
}
int a = Query(M);
M[x - 1] = 1;
int b = Query(M);
if(a != b) r = mid;
else l = mid + 1;
}
if(l > r) {
solve(-1,x);
return ;
}
auto it = s.begin();
if(!B){
int mid = l;
for(int i = 0;i < n;i++)
{
M[i] = 0;
}
M[par - 1] = 1;
for(int i = 0;i <= mid;i++)
{
M[*it - 1] = 1;
it++;
}
int a = Query(M);
M[x - 1] = 1;
int b = Query(M);
if(a == b)
{
solve(-1,x);
B = 1;
return;
}
}
it = s.begin();
for(int i = 0;i <= l;i++)
{
if(i == l) {
solve(*it,x);
return ;
}
it++;
}
}
void Solve(int N)
{
n = N;
if(n == 1)
{
vector<int>vec;vec.pb(1);Answer(vec);return;
}
M.resize(n);
int x = 1 + (rng() % n);
M[x - 1] = 1;
vector<int>adj;
for(int i = 1;i <= n;i++)
{
if(i != x){
M[i - 1] = 1;
if(Query(M) == 1) adj.pb(i);
M[i - 1] = 0;
}
}
for(int i = 1;i <= n;i++)
{
if(i != x) s.insert(i);
}
vec.pb(x);
solve(adj[0],x);
vector<int>ans;
for(auto it : vec) ans.pb(it);
vec.clear();
if(sz(adj) > 1)
{
solve(adj[1],x);
reverse(vec.begin(),vec.end());
for(auto it : ans) vec.pb(it);
Answer(vec);
}
else Answer(ans);
}
Compilation message
library.cpp:2:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
# pragma GCC optimization ("unroll-loops")
library.cpp: In function 'void solve(int, int)':
library.cpp:92:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid = l + r >> 1;
~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
424 KB |
# of queries: 2771 |
2 |
Correct |
49 ms |
328 KB |
# of queries: 2710 |
3 |
Correct |
57 ms |
384 KB |
# of queries: 2875 |
4 |
Correct |
27 ms |
324 KB |
# of queries: 2877 |
5 |
Correct |
51 ms |
336 KB |
# of queries: 2743 |
6 |
Correct |
37 ms |
380 KB |
# of queries: 2767 |
7 |
Correct |
36 ms |
416 KB |
# of queries: 3079 |
8 |
Correct |
46 ms |
384 KB |
# of queries: 2600 |
9 |
Correct |
48 ms |
384 KB |
# of queries: 2672 |
10 |
Correct |
28 ms |
332 KB |
# of queries: 1808 |
11 |
Correct |
2 ms |
384 KB |
# of queries: 0 |
12 |
Correct |
2 ms |
256 KB |
# of queries: 1 |
13 |
Correct |
2 ms |
256 KB |
# of queries: 4 |
14 |
Correct |
2 ms |
256 KB |
# of queries: 7 |
15 |
Correct |
3 ms |
384 KB |
# of queries: 92 |
16 |
Correct |
5 ms |
384 KB |
# of queries: 238 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
424 KB |
# of queries: 2771 |
2 |
Correct |
49 ms |
328 KB |
# of queries: 2710 |
3 |
Correct |
57 ms |
384 KB |
# of queries: 2875 |
4 |
Correct |
27 ms |
324 KB |
# of queries: 2877 |
5 |
Correct |
51 ms |
336 KB |
# of queries: 2743 |
6 |
Correct |
37 ms |
380 KB |
# of queries: 2767 |
7 |
Correct |
36 ms |
416 KB |
# of queries: 3079 |
8 |
Correct |
46 ms |
384 KB |
# of queries: 2600 |
9 |
Correct |
48 ms |
384 KB |
# of queries: 2672 |
10 |
Correct |
28 ms |
332 KB |
# of queries: 1808 |
11 |
Correct |
2 ms |
384 KB |
# of queries: 0 |
12 |
Correct |
2 ms |
256 KB |
# of queries: 1 |
13 |
Correct |
2 ms |
256 KB |
# of queries: 4 |
14 |
Correct |
2 ms |
256 KB |
# of queries: 7 |
15 |
Correct |
3 ms |
384 KB |
# of queries: 92 |
16 |
Correct |
5 ms |
384 KB |
# of queries: 238 |
17 |
Correct |
493 ms |
536 KB |
# of queries: 19599 |
18 |
Correct |
513 ms |
512 KB |
# of queries: 18822 |
19 |
Correct |
526 ms |
504 KB |
# of queries: 18573 |
20 |
Correct |
419 ms |
504 KB |
# of queries: 18369 |
21 |
Correct |
424 ms |
512 KB |
# of queries: 17076 |
22 |
Correct |
492 ms |
648 KB |
# of queries: 18447 |
23 |
Correct |
445 ms |
476 KB |
# of queries: 18254 |
24 |
Correct |
177 ms |
324 KB |
# of queries: 8870 |
25 |
Correct |
503 ms |
396 KB |
# of queries: 19302 |
26 |
Correct |
384 ms |
632 KB |
# of queries: 17000 |
27 |
Correct |
141 ms |
376 KB |
# of queries: 8456 |
28 |
Incorrect |
437 ms |
500 KB |
Wrong Answer [3] |
29 |
Correct |
496 ms |
624 KB |
# of queries: 19110 |
30 |
Correct |
414 ms |
528 KB |
# of queries: 19019 |