QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#196006 | #1277. Permutation | 0xyz | WA | 529ms | 61780kb | C++14 | 818b | 2023-10-01 10:50:35 | 2023-10-01 10:50:35 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll _=55,mod=1e9+7;
ll T,n,ans,p,a[_];
map<ll,ll>f;
bool ch(ll s,ll x){
if((s>>x)&1)return 0;
for(ll i=x-1,j=x+1;i>=0&&j<n;i--,j++)
if(((s>>i)&1)^((s>>j)&1))return 0;
return 1;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>T;
while(T--){
cin>>n;
ans=1;p=0;
for(ll i=0;i<n;i++){
cin>>a[i];a[i]--;
if(!~a[i])ans=(ans*++p)%mod;
}
f.clear();f[0]=1;
for(auto i:f){
ll x=i.first,y=i.second,z=__builtin_popcount(x);
if(z==n)break;
if(~a[z]){
if(ch(x,a[z]))f[x^(1ll<<a[z])]=(f[x^(1ll<<a[z])]+y)%mod;
}else{
for(ll j=0;j<n;j++)
if(ch(x,j))f[x^(1ll<<j)]=(f[x^(1ll<<j)]+y)%mod;
}
}
cout<<(ans-f[(1ll<<n)-1]+mod)%mod<<'\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3432kb
input:
2 3 0 0 0 7 1 0 3 0 0 6 0
output:
2 21
result:
ok 2 tokens
Test #2:
score: 0
Accepted
time: 0ms
memory: 3464kb
input:
50 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
result:
ok 50 tokens
Test #3:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
25 2 0 0 2 0 0 2 0 0 2 0 0 2 0 0 2 0 0 2 0 0 2 0 0 2 0 0 2 0 0 2 0 0 2 0 0 2 0 0 2 0 0 2 0 0 2 0 0 2 0 0 2 0 0 2 0 0 2 0 0 2 0 0 2 0 0 2 0 0 2 0 0 2 0 0
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
result:
ok 25 tokens
Test #4:
score: 0
Accepted
time: 0ms
memory: 3412kb
input:
16 3 0 0 0 3 0 0 0 3 0 0 0 3 0 0 0 3 0 0 0 3 0 0 0 3 0 0 0 3 0 0 0 3 0 0 0 3 0 0 0 3 0 0 0 3 0 0 0 3 0 0 0 3 0 0 0 3 0 0 0 3 0 0 0
output:
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
result:
ok 16 tokens
Test #5:
score: 0
Accepted
time: 1ms
memory: 3556kb
input:
5 10 0 0 0 0 0 0 0 0 0 0 10 0 0 0 0 0 0 0 0 0 0 10 0 0 0 0 0 0 0 0 0 0 10 0 0 0 0 0 0 0 0 0 0 10 0 0 0 0 0 0 0 0 0 0
output:
3627734 3627734 3627734 3627734 3627734
result:
ok 5 tokens
Test #6:
score: 0
Accepted
time: 0ms
memory: 3508kb
input:
4 11 0 10 11 6 1 0 8 0 0 3 5 11 0 0 0 10 8 5 4 1 0 2 9 11 0 4 0 3 11 0 0 0 7 8 1 11 0 8 0 3 9 0 0 0 7 4 0
output:
24 24 120 720
result:
ok 4 tokens
Test #7:
score: 0
Accepted
time: 1ms
memory: 3508kb
input:
4 12 0 0 11 0 0 6 1 0 4 0 5 8 12 7 0 10 11 4 6 1 8 0 12 0 0 12 0 12 0 0 0 0 5 0 1 0 10 11 12 0 0 4 3 9 12 2 5 1 10 6 0
output:
720 24 5040 6
result:
ok 4 tokens
Test #8:
score: 0
Accepted
time: 1ms
memory: 3516kb
input:
3 13 0 13 6 3 0 11 0 0 0 0 1 2 0 13 9 0 0 0 0 0 8 0 5 7 0 12 0 13 0 0 0 0 0 0 3 10 2 9 0 12 0
output:
5040 40320 40320
result:
ok 3 tokens
Test #9:
score: 0
Accepted
time: 0ms
memory: 3436kb
input:
3 14 0 12 10 9 0 0 11 0 0 1 6 4 8 13 14 0 0 8 0 0 9 14 3 0 0 6 2 0 0 14 13 0 8 0 0 0 0 0 14 7 4 6 0 3
output:
120 40320 5040
result:
ok 3 tokens
Test #10:
score: 0
Accepted
time: 1ms
memory: 3580kb
input:
3 15 8 7 12 14 6 0 0 9 4 0 1 0 0 0 2 15 5 0 0 9 0 7 15 0 13 4 11 0 0 0 2 15 0 0 0 2 0 0 7 0 0 8 0 13 14 10 3
output:
720 5040 40320
result:
ok 3 tokens
Test #11:
score: 0
Accepted
time: 7ms
memory: 4080kb
input:
2 20 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 20 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
output:
143388927 143388927
result:
ok 2 tokens
Test #12:
score: 0
Accepted
time: 4ms
memory: 4028kb
input:
1 30 21 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
output:
586750519
result:
ok "586750519"
Test #13:
score: 0
Accepted
time: 54ms
memory: 14064kb
input:
1 40 0 0 0 0 23 26 0 0 0 0 0 0 32 20 33 0 0 0 0 0 0 0 0 0 0 0 0 0 36 0 0 0 0 0 0 0 0 0 0 0
output:
943272305
result:
ok "943272305"
Test #14:
score: 0
Accepted
time: 344ms
memory: 48120kb
input:
1 41 0 0 0 0 0 0 0 0 0 14 38 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 15 0 0 35 9 0 0
output:
523095984
result:
ok "523095984"
Test #15:
score: 0
Accepted
time: 440ms
memory: 57456kb
input:
1 42 0 0 0 0 0 0 0 0 0 0 0 0 4 22 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 38 0 0 0 1 0
output:
472948359
result:
ok "472948359"
Test #16:
score: 0
Accepted
time: 0ms
memory: 3492kb
input:
5 10 0 0 7 0 0 0 0 0 0 3 10 0 5 0 0 0 0 0 9 0 0 10 1 6 0 0 0 0 0 5 0 0 10 0 0 4 0 0 0 3 0 1 9 10 0 0 0 0 0 0 0 6 0 0
output:
40320 40320 5040 718 362648
result:
ok 5 tokens
Test #17:
score: 0
Accepted
time: 1ms
memory: 3444kb
input:
5 9 0 6 0 0 0 0 0 0 0 9 6 0 0 0 3 0 0 7 0 9 8 0 0 0 0 0 7 3 4 9 0 0 0 0 0 0 0 0 0 9 0 0 0 0 0 0 8 2 0
output:
40270 720 120 362384 4996
result:
ok 5 tokens
Test #18:
score: 0
Accepted
time: 529ms
memory: 61780kb
input:
1 42 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
output:
94131117
result:
ok "94131117"
Test #19:
score: 0
Accepted
time: 364ms
memory: 45400kb
input:
1 40 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
output:
614960773
result:
ok "614960773"
Test #20:
score: 0
Accepted
time: 144ms
memory: 21832kb
input:
1 35 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
output:
478043548
result:
ok "478043548"
Test #21:
score: 0
Accepted
time: 45ms
memory: 10388kb
input:
1 30 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
output:
343955582
result:
ok "343955582"
Test #22:
score: 0
Accepted
time: 15ms
memory: 5840kb
input:
1 25 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
output:
242322220
result:
ok "242322220"
Test #23:
score: 0
Accepted
time: 4ms
memory: 4128kb
input:
1 20 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
output:
143388927
result:
ok "143388927"
Test #24:
score: 0
Accepted
time: 1ms
memory: 3512kb
input:
5 10 0 0 0 2 0 9 0 5 0 0 10 0 1 0 3 7 0 0 0 0 0 10 0 0 10 8 0 0 0 9 0 7 10 0 7 1 9 0 0 0 0 0 0 10 0 4 0 0 10 0 0 0 9 0
output:
5028 5000 719 5018 5034
result:
ok 5 tokens
Test #25:
score: 0
Accepted
time: 0ms
memory: 3416kb
input:
5 10 5 1 9 7 3 0 4 10 2 6 10 5 9 1 3 7 6 2 0 4 8 10 6 2 10 4 8 1 9 5 3 0 10 0 10 6 4 8 5 9 1 7 3 10 8 4 10 2 6 5 9 1 0 3
output:
0 0 0 0 0
result:
ok 5 tokens
Test #26:
score: 0
Accepted
time: 1ms
memory: 3428kb
input:
5 10 0 3 0 0 5 10 2 6 4 8 10 5 1 0 3 7 0 4 2 10 6 10 0 3 9 1 5 6 0 10 0 4 10 0 3 5 9 1 6 10 0 8 4 10 5 1 9 7 3 0 4 6 2 0
output:
4 1 5 1 1
result:
ok 5 tokens
Test #27:
score: -100
Wrong Answer
time: 1ms
memory: 3468kb
input:
1 42 29 13 21 37 5 17 33 1 0 0 41 11 27 35 3 19 31 15 23 39 7 12 28 4 36 20 24 0 0 32 16 2 34 18 26 10 42 0 30 6 38 22
output:
120
result:
wrong answer 1st words differ - expected: '118', found: '120'