QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#592144 | #5053. Random Shuffle | zhutianrui | TL | 0ms | 0kb | C++14 | 2.3kb | 2024-09-26 20:55:12 | 2024-09-26 20:55:14 |
answer
#include <bits/stdc++.h>
// #define int long long
#define F(i, a, b) for (int i = (a); i <= (b); i++)
#define dF(i, a, b) for (int i = (a); i >= (b); i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef bitset<65> bst;
const int N = 200005, M = (N << 1), inf = 1e16, mod = 1e9 + 7;
int n, pos[N], a[N], gen[N];
vector<int> fr;
bst ept;
int check(uint64_t x) {
uint64_t seed = x;
F(i, 1, n) {
seed ^= seed << 13;
seed ^= seed >> 7;
seed ^= seed << 17;
if (seed % i != gen[i])
return 0;
}
return 1;
}
vector<bst> hcy;
void guess() {
while (hcy.size() > 64) hcy.pop_back();
while (hcy.size() < 64) hcy.push_back(ept);
F(i, 0, 63) {
int flag = 0;
F(j, i, 63)
if (hcy[j][i]) {
swap(hcy[j], hcy[i]);
flag = 1; break;
}
if (!flag) {
fr.push_back(i);
continue;
}
F(j, 0, 63) if (i != j && hcy[j][i])
hcy[j] ^= hcy[i];
}
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n;
F(i, 1, n) {
cin >> a[i];
pos[a[i]] = i;
}
dF(i, n, 1) {
gen[i] = pos[i] - 1;
int x = pos[i];
swap(pos[i], pos[a[i]]);
swap(a[i], a[x]);
}
bst f[105];
F(i, 0, 63) f[i][i] = 1;
F(T, 1, min(70, n)) {
dF(i, 63, 13) f[i] ^= f[i - 13];
F(i, 0, 63) f[i] ^= f[i + 7];
dF(i, 63, 17) f[i] ^= f[i - 17];
F(i, 0, 63) {
if (T >> i & 1) break;
else {
bst t = f[i];
t[64] = (gen[T] >> i & 1);
hcy.push_back(t);
}
}
}
guess();
int o = fr.size(), res = 0;
bst x;
for (int i = 0; i < 1 << o; ++i) {
uint64_t res = 0;
x.reset();
F(j, 0, o - 1) if (i >> j & 1)
res |= 1ull << fr[j], x[fr[j]] = 1;
F(j, 0, 63) if (hcy[j][j]) {
int fl = hcy[j][64];
F(k, 0, 64) if (hcy[j][k]) fl ^= x[k];
if (fl) res |= 1ull << j;
}
if (check(res)) {
cout << res << endl;
break;
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
50 36 22 24 21 27 50 28 14 25 34 18 43 47 13 30 7 10 48 20 16 29 9 8 15 3 31 12 38 19 49 37 1 46 32 4 44 11 35 6 33 26 5 45 17 39 40 2 23 42 41