QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#423935#5954. Power SwapperSuffix_Sum0 46ms4128kbC++142.0kb2024-05-28 19:48:122024-05-28 19:48:12

Judging History

你现在查看的是最新测评结果

  • [2024-05-28 19:48:12]
  • 评测
  • 测评结果:0
  • 用时:46ms
  • 内存:4128kb
  • [2024-05-28 19:48:12]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int T;
int n;
struct node{
	int a[5005];
}t;
int jc[50];
int dfs(int len,int cnt,node x)
{
	if(len==0)
	{
		return jc[cnt];
	}
	int id1=0,id2=0;
	for(int i=1;i<=(1<<len);i+=2)
	{
		if(x.a[i]%2!=1||x.a[i+1]!=x.a[i]+1)
		{
			if(id2!=0)
			{
				return 0;
			}
			id2=id1;
			id1=i;
		}
	}
	/*for(int i=1;i<=(1<<len);i++)
	{
		cout<<x.a[i]<<" ";
	}
	cout<<endl;
	cout<<"::"<<id1<<" "<<id2<<endl<<endl;*/
	node xx=x;
	memset(xx.a,0,sizeof(xx.a));
	if(id2==0&&id1==0)
	{
		for(int i=1;i<=(1<<len);i+=2)
		{
			xx.a[(i+1)/2]=(x.a[i]+1)/2;
		}
		return dfs(len-1,cnt,xx);
		memset(xx.a,0,sizeof(xx.a));
	}
	else if(id2==0)
	{
		swap(x.a[id1],x.a[id1+1]); 
		for(int i=1;i<=(1<<len);i+=2)
		{
			xx.a[(i+1)/2]=(x.a[i]+1)/2;
		}
		return dfs(len-1,cnt+1,xx);
		memset(xx.a,0,sizeof(xx.a));
	}
	else
	{
		if(x.a[id1]%2==0&&x.a[id2]%2==0)
		{
			return 0;
		}
		else if(x.a[id1]%2==0) 
		{
			swap(x.a[id1],x.a[id2+1]);
			for(int i=1;i<=(1<<len);i+=2)
			{
				xx.a[(i+1)/2]=(x.a[i]+1)/2;
			}
			return dfs(len-1,cnt+1,xx);
			memset(xx.a,0,sizeof(xx.a));
		}
		else if(x.a[id2]%2==0)
		{
			swap(x.a[id1+1],x.a[id2]);
			for(int i=1;i<=(1<<len);i+=2)
			{
				xx.a[(i+1)/2]=(x.a[i]+1)/2;
			}
			return dfs(len-1,cnt+1,xx);
			memset(xx.a,0,sizeof(xx.a));
		}
		else
		{
			//cout<<"!!"<<endl; 
			int re=0;
			swap(x.a[id1],x.a[id2]);
			for(int i=1;i<=(1<<len);i+=2)
			{
				xx.a[(i+1)/2]=(x.a[i]+1)/2;
			}
			re+=dfs(len-1,cnt+1,xx);
			memset(xx.a,0,sizeof(xx.a)); 
			swap(x.a[id1],x.a[id2]);
			swap(x.a[id1+1],x.a[id2+1]);
			for(int i=1;i<=(1<<len);i+=2)
			{
				xx.a[(i+1)/2]=(x.a[i]+1)/2;
			}
			re+=dfs(len-1,cnt+1,xx);
			return re;
			memset(xx.a,0,sizeof(xx.a));
		}
	}
}
signed main()
{
	jc[0]=1;
	for(int i=1;i<=24;i++)
	{
		jc[i]=jc[i-1]*i;
	}
	cin>>T;
	for(int i=1;i<=T;i++)
	{
		cin>>n;
		for(int i=1;i<=(1<<n);i++)
		{
			cin>>t.a[i];
		}
		cout<<"Case #"<<i<<": "<<dfs(n,0,t)<<endl;
	}
	return 0;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3812kb

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: 2
Case #6: 30
Case #7: 1
Case #8: 1
Case #9: 1
Case #10: 1
Case #11: 38
Case #12: 30
Case #13: 3
Case #14: 3
Case #15: 44
Case #16: 30
Case #17: 8
Case #18: 0
Case #19: 3
Case #20: 1
Case #21: 1
Case #22: 24
Case #23: 6
Case #24: 24
Case #25: 6
Ca...

result:

wrong answer 15th lines differ - expected: 'Case #15: 38', found: 'Case #15: 44'

Subtask #2:

score: 0
Wrong Answer

Test #2:

score: 0
Wrong Answer
time: 46ms
memory: 4128kb

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: 120
Case #6: 1
Case #7: 79833600
Case #8: 2
Case #9: 0
Case #10: 720
Case #11: 0
Case #12: 54
Case #13: 40320
Case #14: 837603360
Case #15: 448560
Case #16: 51120
Case #17: 45360
Case #18: 45360
Case #19: 1
Case #20: 1
Case #21: 1
Case #22: 837603...

result:

wrong answer 7th lines differ - expected: 'Case #7: 39916800', found: 'Case #7: 79833600'