# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
44083 |
2018-03-29T20:58:19 Z |
zadrga |
Library (JOI18_library) |
C++14 |
|
45 ms |
544 KB |
#include "library.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (1LL << 55)
#define MOD (1000 * 1000 * 1000 + 7)
#define maxn 200111
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
vector<int> here;
int find_first(int n){
vector<int> q;
for(int i = 0; i < n; i++)
q.pb(1);
for(int i = 0; i < n; i++){
q[i] = 0;
int num = Query(q);
if(num == 1){
here.erase(find(here.begin(), here.end(), i));
return i;
}
q[i] = 1;
}
}
bool ask(int n, int l, int d, int last){
vector<int> q;
for(int i = 0; i < n; i++)
q.pb(0);
for(int i = l; i <= d; i++){
// cout << here[i] << " ";
q[here[i]] = 1;
}
// cout << endl;
int alone = Query(q);
q[last] = 1;
int together = Query(q);
// cout << alone << " ||||| " << last << ": " << together << endl;
if(alone == together) // next is in range [l, d]
return 1;
return 0;
}
int find_next(int n, int last){
int l = 0, d = here.size() - 1, ans = -1, mid;
while(l <= d){
if(l == d){
ans = l;
break;
}
mid = (l + d) / 2;
// cout << "pozicija: " << l << " " << d << " " << mid << endl;
if(ask(n, l, mid, last)){
d = mid;
ans = mid;
}
else
l = mid + 1;
}
int ret = here[ans];
here.erase(find(here.begin(), here.end(), ret));
return ret;
}
void Solve(int n){
vector<int> ans;
for(int i = 0; i < n; i++)
here.pb(i);
int last = find_first(n);
ans.pb(last);
while(here.size() > 1){
/* cout << "before:\n";
for(int v : here)
cout << v << " ";
cout << endl << endl; */
int nxt = find_next(n, last);
// cout << "nxt: " << nxt << endl;
ans.pb(nxt);
last = nxt;
}
ans.pb(here[0]);
for(int i = 0; i < n; i++)
ans[i]++;
Answer(ans);
}
Compilation message
library.cpp: In function 'int find_first(int)':
library.cpp:34:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
248 KB |
Output is correct |
2 |
Correct |
37 ms |
312 KB |
Output is correct |
3 |
Correct |
45 ms |
384 KB |
Output is correct |
4 |
Correct |
29 ms |
460 KB |
Output is correct |
5 |
Correct |
35 ms |
512 KB |
Output is correct |
6 |
Correct |
40 ms |
512 KB |
Output is correct |
7 |
Correct |
41 ms |
544 KB |
Output is correct |
8 |
Correct |
37 ms |
544 KB |
Output is correct |
9 |
Correct |
40 ms |
544 KB |
Output is correct |
10 |
Correct |
23 ms |
544 KB |
Output is correct |
11 |
Incorrect |
2 ms |
544 KB |
Wrong Answer [2] |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
248 KB |
Output is correct |
2 |
Correct |
37 ms |
312 KB |
Output is correct |
3 |
Correct |
45 ms |
384 KB |
Output is correct |
4 |
Correct |
29 ms |
460 KB |
Output is correct |
5 |
Correct |
35 ms |
512 KB |
Output is correct |
6 |
Correct |
40 ms |
512 KB |
Output is correct |
7 |
Correct |
41 ms |
544 KB |
Output is correct |
8 |
Correct |
37 ms |
544 KB |
Output is correct |
9 |
Correct |
40 ms |
544 KB |
Output is correct |
10 |
Correct |
23 ms |
544 KB |
Output is correct |
11 |
Incorrect |
2 ms |
544 KB |
Wrong Answer [2] |
12 |
Halted |
0 ms |
0 KB |
- |