QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#596395#9353. Interesting Permutationyeah14WA 227ms6260kbC++172.3kb2024-09-28 15:41:302024-09-28 15:41:32

Judging History

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

  • [2024-09-28 15:41:32]
  • 评测
  • 测评结果:WA
  • 用时:227ms
  • 内存:6260kb
  • [2024-09-28 15:41:30]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ull long long
#define PII  pair<int ,int>
const int INF = -1145141919810;
const int mod = 1e9 + 7;
const int N = 1e7;
int a[N];
string s[6];
int vis[6][6];
int viss[6];
bool visss[6];
string t = "harbin";
bool op = 0;
int st[7], top = 0;
//harbin;0 h;1,a;2 r;3 b;4 i;5 n
void dfs(int x) {
	if (x >= 5&&op==0&&top==6) {
		/*for (int i = top - 1; i >= 0; i--) {
			cout << st[i] << " ";
		}
		cout << endl;*/
		op = 1;
	}
	if (op == 1)return;
	for (int i = 0; i < 6; i++) {
		if (viss[i])continue;
		if (vis[x][i]) {
			viss[i] = 1;
			for (int j = 0; j < 6; j++) {
				if (visss[j])continue;
				st[top++] = j;
				visss[j] = 1;
				dfs(j);
				if (op == 1)return;
				visss[j] = 0;
				top--;
			}
			viss[i] = 0;
		}
	}
}
void solve() {
	int n;
	cin >> n;
	int maxx = 0;
	int maxx1 = -2;
	int fm = 0;
	bool op = 0;//ans?0;
	int cnt = 0;//重复
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		if (a[i] < a[i - 1]||a[1] != 0||(a[i]==0&&i!=1))op = 1;
		if (a[i] == a[i - 1]&&i!=1&&maxx!=n-1) {
			cnt++;
		}
		else {
			cnt = 0;
		}
		if (cnt >= maxx - maxx1)op = 1;
		if (maxx < a[i]) {
			fm = i;
			maxx1 = maxx;
			maxx = a[i];
		}
	}
	if (maxx != n - 1)op = 1;
	if (op == 1) {
		cout << 0 << endl;
		return;
	}
	int ans = 2;
	int t = 0;
	int tt = 1;
	for (int i = 2; i < fm; i++) {
		if (a[i] != a[i - 1]) {
			ans *= tt;
			ans %= mod;
			ans *= max((n - a[i] - (i - 1)) * 2,1LL);
			ans %= mod;
			t = 0;
			tt = 1;
		}		
		if (a[i] == a[i - 1]) {
			t++;
			tt*= t;
			tt %= mod;
		}
	}
	if (tt != 1)ans *= tt;
	ans %= mod;
	t = 1;
	for (int i = fm+1; i <= n; i++) {
		ans *= t;
		ans %= mod;
		t++;
	}
	cout << ans << endl;
}
//&&(((sum[n]+k)%mid==0)||(sum[n]/mid!=(sum[n]+k)/mid)||(mid-(sum[n]%mid)>=k))
signed main() {
	int t=1;
	cin >> t;
	//t = 1;
	//er(9e6);
	while (t--)solve();
	
}
//int n;
//cin >> n;
//for (int i = 1; i <= n; i++) {
//	cin >> a[i];
//}
//int maxx = 0, minn = INF;
//int sum = 0;
//for (int i = n; i <= 1; i++) {
//	sum += minn;
//	if (top == 0) {
//		minn = a[i];
//		st[top++] = a[i];
//	}
//	else {
//		if (a[i] > top && a[i] > minn)
//	}
//}
//cout << maxx - minn << endl;
//7 2 1 4 5 1 3 3
//4 1000 1000 1000 1000
//0

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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
Wrong Answer
time: 227ms
memory: 6260kb

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:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
16
0
0
2
0
0
0
0
2
0
0
0
0
0
0
0
0
80
0
96768
0
0
0
0
0
2
0
0
0
0
2
0
2
0
0
0
0
0
4
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
2
0
0
0
0
2304
0
0
1397760
0
0
2
32
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4
0
0
0
13824
0
0
0
24
0
0
0
0
0
8
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
12
0
0
0
0
0
7680...

result:

wrong answer 7th lines differ - expected: '24576', found: '0'