#include <bits/stdc++.h>
#include "library.h"
typedef int ll;
typedef long double ld;
#define pb push_back
#define pii pair < ll , ll >
#define F first
#define S second
#define endl '\n'
//#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
/*
ll Query(vector <int> m){
for (int i=0;i<m.size();i++){
cout << m[i] << " ";
}
cout << endl;
ll x;
cin >> x;
return x;
}
ll Answer(vector <int> ans){
for (int i=0;i<ans.size();i++){
cout << ans[i] << " ";
}
cout << endl;
}
*/
ll ask(vector <int> a,ll x,ll n){
vector <int> m;
for (int i=0;i<n;i++){
m.pb(0);
}
for (auto u : a){
m[u-1]=1;
}
m[x-1]=1;
return Query(m);
}
ll what(ll x,ll y,ll n){
vector <int> m;
for (int i=0;i<n;i++){
m.pb(0);
}
m[y-1]=1;
m[x-1]=1;
return Query(m);
}
void Solve(ll n){
vector <vector <int> > mol;
ll cnt=1;
vector <int> a;
for (int i=1;i<=n;i++){
a.pb(i);
}
random_shuffle(a.begin(),a.end());
for (auto u : a){
if (mol.size()==0){
vector <int> t;
t.pb(u);
mol.pb(t);
continue;
}
vector <int> t;
for (auto z : mol){
for (auto v : z){
t.pb(v);
}
}
ll w=ask(t,u,n);
//cout << cnt << " " << w << endl;
if (w>cnt){
cnt=w;
vector <int> d;
d.pb(u);
mol.pb(d);
continue;
}
vector <int> q;
ll p1=0;
vector <vector <int> > lom;
for (int i=0;i<mol.size();i++){
vector <int> v=mol[i];
if (v.size()==0){
cout << 1/0;
}
ll w=ask(v,u,n);
if (w>1) {
lom.pb(v);
continue;
}
if (p1==0){
if (what(mol[i].back(),u,n)==1){
q=mol[i];
q.pb(u);
}
else{
reverse(mol[i].begin(),mol[i].end());
q=mol[i];
q.pb(u);
}
p1=1;
}
else {
p1=2;
if (what(mol[i][0],u,n)==1){
for (auto z : mol[i]){
q.pb(z);
}
}
else{
reverse(mol[i].begin(),mol[i].end());
for (auto z : mol[i]){
q.pb(z);
}
}
}
if (p1==2 || (p1==1 && cnt==w)) {
for (int j=i+1;j<mol.size();j++){
lom.pb(mol[j]);
}
break;
}
}
cnt=w;
mol=lom;
mol.pb(q);
}
if (mol.size()>1){
// cout << "KIR KHAR" << endl;
}
Answer(mol[0]);
}
/*
int32_t main(){
ll n;
cin >> n;
Solve(n);
}
*/
Compilation message
library.cpp: In function 'void Solve(ll)':
library.cpp:85:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
85 | for (int i=0;i<mol.size();i++){
| ~^~~~~~~~~~~
library.cpp:88:26: warning: division by zero [-Wdiv-by-zero]
88 | cout << 1/0;
| ~^~
library.cpp:123:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
123 | for (int j=i+1;j<mol.size();j++){
| ~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
492 KB |
# of queries: 4206 |
2 |
Correct |
82 ms |
364 KB |
# of queries: 4624 |
3 |
Correct |
85 ms |
492 KB |
# of queries: 4640 |
4 |
Correct |
64 ms |
364 KB |
# of queries: 4285 |
5 |
Correct |
66 ms |
492 KB |
# of queries: 4183 |
6 |
Correct |
68 ms |
380 KB |
# of queries: 4503 |
7 |
Correct |
90 ms |
364 KB |
# of queries: 4699 |
8 |
Correct |
71 ms |
396 KB |
# of queries: 4214 |
9 |
Correct |
69 ms |
508 KB |
# of queries: 4691 |
10 |
Correct |
37 ms |
364 KB |
# of queries: 2003 |
11 |
Correct |
1 ms |
364 KB |
# of queries: 0 |
12 |
Correct |
1 ms |
364 KB |
# of queries: 3 |
13 |
Correct |
1 ms |
364 KB |
# of queries: 6 |
14 |
Correct |
1 ms |
364 KB |
# of queries: 10 |
15 |
Correct |
1 ms |
364 KB |
# of queries: 51 |
16 |
Correct |
3 ms |
364 KB |
# of queries: 142 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
492 KB |
# of queries: 4206 |
2 |
Correct |
82 ms |
364 KB |
# of queries: 4624 |
3 |
Correct |
85 ms |
492 KB |
# of queries: 4640 |
4 |
Correct |
64 ms |
364 KB |
# of queries: 4285 |
5 |
Correct |
66 ms |
492 KB |
# of queries: 4183 |
6 |
Correct |
68 ms |
380 KB |
# of queries: 4503 |
7 |
Correct |
90 ms |
364 KB |
# of queries: 4699 |
8 |
Correct |
71 ms |
396 KB |
# of queries: 4214 |
9 |
Correct |
69 ms |
508 KB |
# of queries: 4691 |
10 |
Correct |
37 ms |
364 KB |
# of queries: 2003 |
11 |
Correct |
1 ms |
364 KB |
# of queries: 0 |
12 |
Correct |
1 ms |
364 KB |
# of queries: 3 |
13 |
Correct |
1 ms |
364 KB |
# of queries: 6 |
14 |
Correct |
1 ms |
364 KB |
# of queries: 10 |
15 |
Correct |
1 ms |
364 KB |
# of queries: 51 |
16 |
Correct |
3 ms |
364 KB |
# of queries: 142 |
17 |
Runtime error |
452 ms |
492 KB |
Execution killed with signal 13 (could be triggered by violating memory limits) |
18 |
Halted |
0 ms |
0 KB |
- |