QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#596296 | #9353. Interesting Permutation | yeah14 | WA | 233ms | 5744kb | C++17 | 2.2kb | 2024-09-28 15:29:10 | 2024-09-28 15:29:11 |
Judging History
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 = -1;
int fm = 0;
bool op = 0;//ans?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] && maxx - maxx1 == 1&&i!=1) {
//op = 1;
//cout << i << endl;
}
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 *= (n - a[i] - (i - 1)) * 2;
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: 3580kb
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: 233ms
memory: 5744kb
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 586404878 105994866 -410114399 356200637 839761486 0 878415522 -846073753 0 958362243 16 0 0 2 614846812 0 0 874021360 2 0 -353822012 0 0 260834064 0 835503400 0 -160 0 1161216 0 0 96 0 0 2 0 640038393 0 0 2 0 2 0 0 0 0 0 4 358402274 -823399393 0 -566272844 0 792369928 0 0 0 0 -818976002 -...
result:
wrong answer 6th lines differ - expected: '0', found: '586404878'