QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#942475 | #5053. Random Shuffle | Physics212303 | WA | 928ms | 3840kb | C++17 | 1.7kb | 2025-03-19 09:25:31 | 2025-03-19 09:25:31 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
const int B=64;
inline int lowbit(int x){return x&-x;}
int main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n; cin>>n;
vector<int> a(n+1),m(n+1),p(n+1);
for(int i=1;i<=n;i++)
cin>>a[i],m[a[i]]=i;
auto b=a;
for(int i=n;i;i--)
p[i]=m[i],swap(m[i],m[a[i]]),swap(a[i],a[p[i]--]);
n=min(n,50);
vector s(n+1,vector<ull>(B));
for(int i=0;i<B;i++)
s[0][i]=1ull<<i;
vector<bitset<B+1> > e;
for(int i=1;i<=n&&e.size()<B;i++){
auto t=s[i]=s[i-1];
for(int j=13;j<B;j++)
s[i][j]^=t[j-13];
t=s[i];
for(int j=7;j<B;j++)
s[i][j-7]^=t[j];
t=s[i];
for(int j=17;j<B;j++)
s[i][j]^=t[j-17];
for(int j=0;1<<j+1<=lowbit(i)&&e.size()<B;j++){
e.emplace_back(bitset<B+1>(s[i][j]));
if(p[i]>>j&1)e.back().set(B);
}
}
vector<int> f;
for(int i=0;i<B;i++){
if(!e[i][i])
for(int j=i+1;j<B;j++)
if(e[j][i]){swap(e[i],e[j]); break;}
if(e[i][i]){
for(int j=i+1;j<B;j++)
if(e[j][i])e[j]^=e[i];
}
else f.emplace_back(i);
}
auto pd=[&](ull S){
vector<int> c(n+1);
iota(c.begin(),c.end(),0);
for(int i=1;i<=n;i++){
S^=S<<13,S^=S>>7,S^=S<<17;
swap(c[i],c[S%i+1]);
}
return b==c;
};
for(int i=0;i<1<<f.size();i++){
ull S=0;
for(int j=0;j<f.size();j++)
if(i>>j&1)S|=1ull<<f[j];
for(int j=B-1;~j;j--)
if(e[j][j]){
int x=e[j][B];
for(int k=j+1;k<B;k++)
if(e[j][k])x^=S>>k&1;
if(x)S|=1ull<<j;
}
if(pd(S))cout<<(S)<<endl,exit(0);
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 825ms
memory: 3584kb
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
output:
16659580358178468547
result:
ok OK, Accepted.
Test #2:
score: 0
Accepted
time: 94ms
memory: 3712kb
input:
50 26 36 12 27 8 1 33 17 16 48 11 22 20 10 23 47 5 32 35 21 31 49 45 43 29 2 13 41 4 6 3 50 30 7 9 15 14 38 25 46 28 37 39 18 42 24 19 40 44 34
output:
1881993639894066979
result:
ok OK, Accepted.
Test #3:
score: 0
Accepted
time: 275ms
memory: 3712kb
input:
50 40 28 8 31 5 15 16 26 29 12 22 45 11 32 25 21 35 9 24 3 4 23 36 6 41 44 27 48 34 49 37 13 33 39 10 17 2 46 42 18 7 14 50 20 47 30 1 38 19 43
output:
5551150991024249731
result:
ok OK, Accepted.
Test #4:
score: 0
Accepted
time: 457ms
memory: 3584kb
input:
50 47 35 20 16 14 21 32 40 38 37 43 27 45 22 5 13 4 36 33 2 19 31 11 46 39 29 48 18 1 9 42 44 23 12 49 41 3 50 28 6 10 8 25 30 15 24 7 17 26 34
output:
9220308350744367075
result:
ok OK, Accepted.
Test #5:
score: 0
Accepted
time: 637ms
memory: 3712kb
input:
50 32 7 36 49 35 21 15 27 16 41 4 10 25 34 24 40 17 9 45 30 12 11 20 2 31 19 3 39 14 8 38 18 47 33 50 37 48 46 43 22 42 29 23 13 1 5 26 28 44 6
output:
12889465701874549827
result:
ok OK, Accepted.
Test #6:
score: 0
Accepted
time: 824ms
memory: 3584kb
input:
50 4 11 21 1 46 26 43 2 31 27 41 38 29 37 40 3 33 34 18 50 39 42 8 17 47 32 49 15 35 13 28 45 6 7 20 16 23 10 22 5 36 25 12 9 19 14 48 30 44 24
output:
16558623053004732579
result:
ok OK, Accepted.
Test #7:
score: 0
Accepted
time: 87ms
memory: 3584kb
input:
50 7 11 31 6 24 40 18 17 25 20 43 26 1 44 15 4 32 47 10 12 34 16 14 36 46 42 13 27 33 3 30 23 39 5 50 45 8 35 21 19 49 41 38 37 9 2 29 48 22 28
output:
1781036334720331011
result:
ok OK, Accepted.
Test #8:
score: 0
Accepted
time: 269ms
memory: 3712kb
input:
50 23 42 40 19 49 37 11 22 29 14 8 36 13 26 18 7 31 10 15 16 21 30 41 43 48 20 6 2 3 4 5 50 45 33 32 38 25 9 44 27 35 46 12 39 28 17 1 24 34 47
output:
5450193690145481059
result:
ok OK, Accepted.
Test #9:
score: 0
Accepted
time: 453ms
memory: 3840kb
input:
50 27 25 38 11 26 45 5 48 12 37 46 42 39 4 7 31 41 33 29 35 20 23 49 50 14 3 16 17 47 34 21 44 18 8 9 30 6 24 43 19 36 15 1 40 22 13 28 2 10 32
output:
9119351041275663811
result:
ok OK, Accepted.
Test #10:
score: 0
Accepted
time: 695ms
memory: 3840kb
input:
50 11 10 48 50 40 1 44 13 33 23 21 3 24 5 31 15 37 43 7 26 12 28 42 45 29 6 27 25 20 8 17 34 46 39 2 36 18 47 22 16 14 19 35 32 9 30 38 41 49 4
output:
14147710490869904115
result:
ok OK, Accepted.
Test #11:
score: -100
Wrong Answer
time: 928ms
memory: 3712kb
input:
60 18 36 13 59 56 4 17 15 8 32 14 16 9 53 38 48 60 21 49 24 27 19 40 45 20 25 22 55 37 43 39 57 34 46 54 30 35 10 26 29 7 44 2 51 11 3 58 28 31 12 1 47 41 33 42 23 6 5 52 50
output:
result:
wrong output format Unexpected end of file - int64 expected