This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Knapsack DP is harder than FFT.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii; typedef pair<ll, ll> pll;
#define ff first
#define ss second
#define pb emplace_back
#define FOR(i,n) for(int i = 0; i < (n); ++i)
#define FOO(i,a,b) for(int i = (a); i <= (b); ++i)
#define AI(x) (x).begin(),(x).end()
template<typename I> bool chmax(I &a, I b){ return a < b ? (a = b, true) : false;}
template<typename I> bool chmin(I &a, I b){ return a > b ? (a = b, true) : false;}
#ifdef OWO
#define debug(args...) LKJ("[ " + string(#args) + " ]", args)
void LKJ(){ cerr << endl;}
template<typename I, typename...T> void LKJ(I&&x, T&&...t){ cerr<<x<<", ", LKJ(t...);}
template<typename I> void DE(I a, I b){ while(a < b) cerr<<*a<<" \n"[next(a)==b], ++a;}
#else
#define debug(...) 0
#define DE(...) 0
#endif
#include "interactive.h"
using namespace std;
vector<int> guess(int n) {
int k = -1;
while(n>1<<++k);
vector<int> ans;
vector<vector<int>> ss(k, vector<int>());
ans.pb(ask(1));
FOR(j,k){
vector<int> q;
FOR(i,n) if(i>>j&1) q.pb(i+1);
vector<int> r = get_pairwise_xor(q);
q.pb(1);
ss[j] = get_pairwise_xor(q);
ss[j].erase(ss[j].begin()); // a[0] ^ a[0]
for(int x: r) ss[j].erase(find(AI(ss[j]), x));
for(int &i: ss[j]) i ^= ans[0];
}
FOO(i,1,n-1){
vector<int> v;
FOR(j,k){
if((i>>j&1)^1) continue;
if(v.empty()) v = ss[j];
else{
vector<int> w;
for(int x: ss[j])
if(find(AI(v), x) != v.end())
w.pb(x);
v.swap(w);
}
}
FOR(j,k){
if(i>>j&1) continue;
for(int x: ss[j]){
auto it = find(AI(v), x);
if(it != v.end()) v.erase(it);
}
}
ans.pb(v[0]);
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |