QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#645731#9353. Interesting PermutationCoffeecat996TL 0ms3560kbC++14830b2024-10-16 19:38:372024-10-16 19:38:38

Judging History

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

  • [2024-10-16 19:38:38]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3560kb
  • [2024-10-16 19:38:37]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7;
void solve()
{
	int n;
	cin >> n;
	vector<int> a(n);
	int flag=1;
	for(int i=0;i<n;i++)
	{
		cin >> a[i];
		if(a[i]<0 || a[i]>=n)
		{
			flag=0;
			break;
		}
	}
	if(flag==0)
	{
		cout<<"0\n";
		return ;
	}
	int ans=1;
	int num=1;
	for(int i=1;i<n;i++)
	{
		if(a[i]!=a[i-1])
		{
			if(num>1)
			{
				num--;
			}
			while(num!=1)
			{
				ans=(ans*num)%mod;
				num--;
			}
			ans=(ans*2)%mod;
		}
		else
		{
			num++;
		}
	}
	if(num!=1)
	{
		num--;
	}
	while(num!=1)
	{
		ans=(ans*num)%mod;
		num--;
	}
	cout<< ans<<"\n";
}
signed main()
{
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);std::cout.tie(0);
	int t=1;
	std::cin >>t;
	while(t--){
		solve();
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3560kb

input:

3
3
0 2 2
3
0 1 2
3
0 2 3

output:

2
4
0

result:

ok 3 lines

Test #2:

score: -100
Time Limit Exceeded

input:

10039
14
5 6 7 8 9 10 11 12 13 13 13 13 13 13
14
0 5 6 7 8 9 10 11 12 13 14 14 14 14
1
1
14
0 5 4 8 9 10 11 12 13 13 13 13 13 13
45
0 1 1 2 2 3 5 5 6 6 8 9 11 13 15 17 18 18 20 22 22 24 26 26 26 26 27 27 27 28 30 32 32 33 34 34 34 36 36 38 38 38 39 39 44
24
0 2 3 5 7 9 9 10 11 12 13 14 14 14 14 15 1...

output:

30720
0
0
0
1
0
0
0
0
0
0
221225451
786432
8192
6144
589934536
805306368
6291456
264924146
607312884
792143830
8388608
8
158428766
2048
2
50331648
284823005
67108864
589934536
2
221225451
150994944
100663296
8
245760
309410789
131072
16384
16
475286298
768
98304
273526969
24
475286298
2097152
2
3932...

result: