#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
#define conts continue
#define ceil2(x,y) ((x+y-1)/(y))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rev(i,s,e) for(int i = s; i >= e; --i)
#define trav(i,a) for(auto &i : a)
template<typename T>
void amin(T &a, T b) {
a = min(a,b);
}
template<typename T>
void amax(T &a, T b) {
a = max(a,b);
}
#ifdef LOCAL
#include "debug.h"
#else
#define debug(x) 42
#endif
/*
read some solutions long time back, remember some ideas from there
*/
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
const int inf1 = int(1e9) + 5;
const ll inf2 = ll(1e18) + 5;
#include "koala.h"
int q = 0;
vector<int> query(vector<int> a){
// q++;
// assert(q <= 700);
int n = sz(a);
int arr[n];
rep(i,n) arr[i] = a[i];
int res_arr[n];
playRound(arr,res_arr);
vector<int> res(n);
rep(i,n) res[i] = res_arr[i];
return res;
}
int minValue(int n, int w) {
// TODO: Implement Subtask 1 solution here.
// You may leave this function unmodified if you are not attempting this
// subtask.
vector<int> a(n);
a[0] = 1;
auto res = query(a);
int pos1 = -1;
rep(i,n){
if(!res[i]){
pos1 = i;
}
}
return pos1;
}
int maxValue(int n, int w) {
// TODO: Implement Subtask 2 solution here.
// You may leave this function unmodified if you are not attempting this
// subtask.
vector<int> cands;
rep(i,n) cands.pb(i);
while(sz(cands) > 1){
int siz = sz(cands);
int mx = 2*w-(n-siz);
int x = mx/siz-1;
vector<int> a(n);
trav(i,cands) a[i] = x;
auto res = query(a);
vector<int> cands2;
trav(i,cands){
if(res[i] > x){
cands2.pb(i);
}
}
cands = cands2;
}
return cands[0];
}
int greaterValue(int n, int w) {
// TODO: Implement Subtask 3 solution here.
// You may leave this function unmodified if you are not attempting this
// subtask.
int lo = 1, hi = 15;
while(lo <= hi){
int mid = (lo+hi) >> 1;
vector<int> a(n);
a[0] = a[1] = mid-1;
auto res = query(a);
int pick0 = res[0] > a[0];
int pick1 = res[1] > a[1];
if(pick0^pick1){
if(pick0) return 0;
else return 1;
}
if(!pick0){
hi = mid-1;
}
else{
lo = mid+1;
}
}
assert(0);
return 0;
}
int n;
bool cmp(int i, int j){
// i < j?
int lo = 1, hi = 30;
while(lo <= hi){
int mid = (lo+hi) >> 1;
vector<int> a(n);
a[i] = a[j] = mid-1;
// rep(i,n){
// a[i] = (a[i]+1)*2-1;
// }
auto res = query(a);
int pick0 = res[i] > a[i];
int pick1 = res[j] > a[j];
if(pick0^pick1){
if(pick0) return false;
else return true;
}
if(!pick0){
hi = mid-1;
}
else{
lo = mid+1;
}
}
assert(0);
return false;
}
void allValues(int n_, int w, int *ans) {
n = n_;
if (w == 2*n) {
// TODO: Implement Subtask 4 solution here.
// You may leave this block unmodified if you are not attempting this
// subtask.
q = 0;
vector<int> sa(n);
iota(all(sa),0);
stable_sort(all(sa),cmp);
// vector<int> a(n,2);
// auto res = query(a);
// vector<int> small,big;
// rep(i,n){
// if(res[i] > a[i]){
// big.pb(i);
// }
// else{
// small.pb(i);
// }
// }
// stable_sort(all(small),cmp);
// stable_sort(all(big),cmp);
// auto sa = small;
// trav(x,big) sa.pb(x);
rep(i,n) ans[sa[i]] = i+1;
} else {
// TODO: Implement Subtask 5 solution here.
// You may leave this block unmodified if you are not attempting this
// subtask.
vector<int> a(n,1);
auto res = query(a);
vector<int> small,big;
rep(i,n){
if(res[i] > a[i]){
big.pb(i);
}
else{
small.pb(i);
}
}
stable_sort(all(small),cmp);
stable_sort(all(big),cmp);
auto sa = small;
trav(x,big) sa.pb(x);
rep(i,n) ans[sa[i]] = i+1;
// vector<int> a(n);
// iota(all(a),0);
// stable_sort(all(a),cmp);
// rep(i,n) ans[a[i]] = i+1;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
344 KB |
Output is correct |
2 |
Correct |
3 ms |
344 KB |
Output is correct |
3 |
Correct |
3 ms |
344 KB |
Output is correct |
4 |
Correct |
3 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
344 KB |
Output is correct |
2 |
Correct |
9 ms |
452 KB |
Output is correct |
3 |
Correct |
10 ms |
344 KB |
Output is correct |
4 |
Correct |
9 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
344 KB |
Output is correct |
2 |
Correct |
35 ms |
344 KB |
Output is correct |
3 |
Correct |
34 ms |
344 KB |
Output is correct |
4 |
Correct |
31 ms |
344 KB |
Output is correct |
5 |
Correct |
38 ms |
344 KB |
Output is correct |
6 |
Correct |
34 ms |
344 KB |
Output is correct |
7 |
Correct |
34 ms |
344 KB |
Output is correct |
8 |
Correct |
31 ms |
344 KB |
Output is correct |
9 |
Correct |
35 ms |
344 KB |
Output is correct |
10 |
Correct |
31 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
20 ms |
344 KB |
Output is partially correct |
2 |
Partially correct |
25 ms |
344 KB |
Output is partially correct |
3 |
Partially correct |
25 ms |
344 KB |
Output is partially correct |
4 |
Partially correct |
26 ms |
344 KB |
Output is partially correct |
5 |
Partially correct |
24 ms |
344 KB |
Output is partially correct |
6 |
Partially correct |
24 ms |
344 KB |
Output is partially correct |
7 |
Partially correct |
25 ms |
460 KB |
Output is partially correct |
8 |
Partially correct |
23 ms |
344 KB |
Output is partially correct |
9 |
Partially correct |
24 ms |
344 KB |
Output is partially correct |
10 |
Partially correct |
26 ms |
344 KB |
Output is partially correct |
11 |
Partially correct |
24 ms |
344 KB |
Output is partially correct |
12 |
Partially correct |
11 ms |
344 KB |
Output is partially correct |
13 |
Partially correct |
27 ms |
344 KB |
Output is partially correct |
14 |
Partially correct |
24 ms |
344 KB |
Output is partially correct |
15 |
Partially correct |
22 ms |
344 KB |
Output is partially correct |
16 |
Partially correct |
33 ms |
344 KB |
Output is partially correct |
17 |
Partially correct |
23 ms |
344 KB |
Output is partially correct |
18 |
Partially correct |
24 ms |
344 KB |
Output is partially correct |
19 |
Partially correct |
24 ms |
344 KB |
Output is partially correct |
20 |
Partially correct |
27 ms |
344 KB |
Output is partially correct |
21 |
Partially correct |
24 ms |
344 KB |
Output is partially correct |
22 |
Partially correct |
24 ms |
344 KB |
Output is partially correct |
23 |
Partially correct |
17 ms |
344 KB |
Output is partially correct |
24 |
Partially correct |
24 ms |
452 KB |
Output is partially correct |
25 |
Partially correct |
23 ms |
344 KB |
Output is partially correct |
26 |
Partially correct |
25 ms |
344 KB |
Output is partially correct |
27 |
Partially correct |
24 ms |
452 KB |
Output is partially correct |
28 |
Partially correct |
24 ms |
452 KB |
Output is partially correct |
29 |
Partially correct |
24 ms |
344 KB |
Output is partially correct |
30 |
Partially correct |
30 ms |
344 KB |
Output is partially correct |
31 |
Partially correct |
25 ms |
340 KB |
Output is partially correct |
32 |
Partially correct |
24 ms |
344 KB |
Output is partially correct |
33 |
Partially correct |
24 ms |
452 KB |
Output is partially correct |
34 |
Partially correct |
16 ms |
344 KB |
Output is partially correct |
35 |
Partially correct |
27 ms |
344 KB |
Output is partially correct |
36 |
Partially correct |
23 ms |
344 KB |
Output is partially correct |
37 |
Partially correct |
24 ms |
452 KB |
Output is partially correct |
38 |
Partially correct |
22 ms |
456 KB |
Output is partially correct |
39 |
Partially correct |
22 ms |
344 KB |
Output is partially correct |
40 |
Partially correct |
21 ms |
344 KB |
Output is partially correct |