CF1365G Secure Password
Solution
妙妙思维题。
注意到
(
13
6
)
>
n
\binom{13}{6}>n
(613)>n。(谁tm能注意到这个?!?)
我们可以把所有13位二进制数中有6个1的拿出来给 n n n个数重标号。然后对于每一位 i i i,求出重标号后这一位是1的数的位或和,记为 w i w_i wi。
对于重标号后为 i i i的位置的答案,只需要让所有 i i i的0的位的 w j w_j wj或起来即可。
Code
#include <bits/stdc++.h>
using namespace std;
template<typename T> inline bool upmin(T &x, T y) { return y < x ? x = y, 1 : 0; }
template<typename T> inline bool upmax(T &x, T y) { return x < y ? x = y, 1 : 0; }
#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int, int> PR;
typedef vector<int> VI;
const lod eps = 1e-9;
const lod pi = acos(-1);
const int oo = 1 << 30;
const ll loo = 1ll << 60;
const int mods = 1e9 + 7;
const int inv2 = (mods + 1) >> 1;
const int MAXN = 1005;
const int INF = 0x3f3f3f3f; //1061109567
/*--------------------------------------------------------------------*/
ll a[5005], w[15], num = 0;
vector<ll> V;
signed main() {
#ifndef ONLINE_JUDGE
// freopen("a.in", "r", stdin);
#endif
int n;
cin >> n;
for (int i = 0; i < 1 << 13 && num < n ; ++ i)
if (__builtin_popcount(i) == 6) a[++ num] = i;
for (int i = 0; i < 13 ; ++ i) {
vector<int> V; V.clear();
for (int j = 1; j <= n ; ++ j)
if ((a[j] >> i) & 1) V.PB(j);
if (!V.size()) continue;
cout << "? " << V.size();
for (auto v : V) cout << " " << v; cout << endl;
cin >> w[i];
}
cout << "!";
for (int i = 1; i <= n ; ++ i) {
ll ans = 0;
for (int j = 0; j < 13 ; ++ j)
if (!((a[i] >> j) & 1)) ans |= w[j];
cout << " " << ans;
}
return 0;
}