QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#424731 | #5954. Power Swapper | hai | 0 | 41ms | 3672kb | C++14 | 1.7kb | 2024-05-29 16:24:01 | 2024-05-29 16:24:02 |
Judging History
answer
# include <bits/stdc++.h>
using namespace std;
int n;
vector<int> v;
long long jie[15];
long long dfs(vector<int> v,int n,int k)
{
if(n==0)
return jie[k];
int pos=0;
for(int i=0;i<1<<n;i+=2)
if(!(v[i]%2 && v[i+1]==v[i]+1))
pos++;
if(pos==0 || pos==1)
{
vector<int> v2(1<<(n-1));
for(int i=0;i<1<<n;i+=2)
v2[i/2]=(v[i]+1)/2;
return dfs(v2,n-1,k+pos);
}
else if(pos==2)
{
vector<int> v2(1<<(n-1));
int pos1=-1,pos2=-1,num1=0,num2=0;
for(int i=0;i<1<<n;i+=2)
if(!(v[i]%2 && v[i+1]==v[i]+1))
{
if(v[i]%2==0 && v[i+1]==v[i]-1)
return 0;
if(pos1==-1)
{
pos1=i/2;
num1=(v[i]+1)/2;
}
else
{
pos2=i/2;
if((v[i]+1)/2==num1)
num2=(v[i+1]+1)/2;
else
num2=(v[i]+1)/2;
}
}
else
v2[i/2]=v[i+1]/2;
long long ans=0;
v2[pos1]=num1;
v2[pos2]=num2;
ans+=dfs(v2,n-1,k+1);
swap(v2[pos1],v2[pos2]);
ans+=dfs(v2,n-1,k+1);
return ans;
}
else
return 0;
}
void solve(int testid)
{
cin>>n;
v.resize(1<<n);
for(int i=0;i<1<<n;i++)
cin>>v[i];
cout<<"Case #"<<testid<<": "<<dfs(v,n,0)<<endl;
}
int main()
{
jie[0]=1;
for(int i=1;i<=12;i++)
jie[i]=jie[i-1]*i;
int T;
cin>>T;
for(int t=1;t<=T;t++)
solve(t);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3484kb
input:
200 1 2 1 2 1 4 3 2 3 7 8 5 6 1 2 4 3 2 4 3 2 1 2 2 4 1 3 4 3 10 11 12 1 2 9 4 13 14 15 16 5 6 7 8 1 2 1 1 2 1 1 2 1 1 1 2 4 1 2 3 4 13 14 15 16 9 12 11 10 5 6 7 8 4 9 10 11 12 1 2 15 16 13 14 6 4 5 3 7 8 2 1 4 3 2 2 3 2 1 4 4 1 2 3 4 13 14 15 16 9 10 11 8 5 6 7 12 4 13 14 11 12 1 2 5 4 9 10 15 16 3...
output:
Case #1: 1 Case #2: 3 Case #3: 6 Case #4: 0 Case #5: 3 Case #6: 68 Case #7: 1 Case #8: 1 Case #9: 1 Case #10: 1 Case #11: 38 Case #12: 36 Case #13: 3 Case #14: 3 Case #15: 68 Case #16: 60 Case #17: 8 Case #18: 0 Case #19: 3 Case #20: 3 Case #21: 1 Case #22: 36 Case #23: 14 Case #24: 54 Case #25: 32 ...
result:
wrong answer 5th lines differ - expected: 'Case #5: 2', found: 'Case #5: 3'
Subtask #2:
score: 0
Wrong Answer
Test #2:
score: 0
Wrong Answer
time: 41ms
memory: 3672kb
input:
200 1 2 1 2 1 4 3 2 3 7 8 5 6 1 2 4 3 2 4 3 2 1 6 33 34 35 36 37 38 39 40 41 42 43 44 19 20 51 52 47 10 11 12 13 14 15 16 57 58 59 60 61 62 63 64 1 2 3 4 5 6 7 8 45 46 9 48 53 54 55 56 17 18 49 50 21 22 23 24 25 26 27 28 29 30 31 32 10 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 2...
output:
Case #1: 1 Case #2: 3 Case #3: 6 Case #4: 0 Case #5: 960 Case #6: 1 Case #7: 558835200 Case #8: 2 Case #9: 0 Case #10: 1560 Case #11: 0 Case #12: 60 Case #13: 443520 Case #14: 1499536800 Case #15: 4843440 Case #16: 102240 Case #17: 45360 Case #18: 897120 Case #19: 1 Case #20: 1 Case #21: 1 Case #22:...
result:
wrong answer 5th lines differ - expected: 'Case #5: 120', found: 'Case #5: 960'