QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#645892#9353. Interesting PermutationCoffeecat996TL 0ms4172kbC++14915b2024-10-16 20:22:492024-10-16 20:22:51

Judging History

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

  • [2024-10-16 20:22:51]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:4172kb
  • [2024-10-16 20:22:49]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7;
vector<int> tt;
void init()
{
	tt.push_back(0);
	tt.push_back(1);
	for(int i=2;i<=1e5;i++)
	{
		tt.push_back((tt.back()*i)%mod);
	}
}
void solve()
{
	int n;
	cin >> n;
	vector<int> a(n);
	int flag=1;
	int ans=1;
	int num=1;
	for(int i=0;i<n;i++)
	{
		cin >> a[i];
		if(a[i]<0 || a[i]>=n || (i>0 && a[i]<a[i-1]))
		{
			flag=0;
			break;
		}
		if(i!=0 && a[i]!=a[i-1])
		{
			if(num>1)
			{
				num--;
			}
			ans=(ans*tt[num])%mod;
			ans=(ans*2)%mod;
		}
		else
		{
			num++;
		}
	}
	if(flag==0)
	{
		cout<<"0\n";
		return ;
	}
	if(num!=1)
	{
		num--;
	}
	ans=(ans*tt[num])%mod;
	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;
	init();
	while(t--){
		solve();
	}
	return 0;
}

詳細信息

Test #1:

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

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
330919827
9437184
8192
12288
589934536
892348547
229815353
358179462
607312884
274842888
8388608
8
633715064
6144
2
623878635
284823005
268435456
438952513
2
710378967
826227383
354091247
16
245760
947171956
4194304
16384
16
439276074
768
18874368
348986096
48
764905737
209...

result: