QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#624757 | #9353. Interesting Permutation | NENULZY | WA | 66ms | 4388kb | C++17 | 1.2kb | 2024-10-09 16:34:56 | 2024-10-09 16:34:59 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long ,long long >
ll mod=1e9+7;
ll a[200005];
int checkill(int n){
if(a[1]!=0) return 0;
if(a[n]!=n-1) return 0;
for(int i=1;i<=n-1;i++){
if(a[i+1]<a[i]||a[i]<i-1) return 0;
}
return 1;
}
ll A(ll sumx,ll sumy){
ll res=1;
for (ll i=1;i<=sumx;i++){
res*=sumy;
res%=mod;
sumy--;
}
return res;
}
void solve() {
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
if (!checkill(n)){
cout<<0<<"\n";
return;
}
ll ans=(n-a[2])*2;
//cout<<"ans "<<ans<<"\n";
for (int i=3;i<=n;i++){
if (a[i]==a[i-1]){
int j=i;
while(a[j+1]==a[j]);
ll sumx=j-i+1;
ll sumy=a[i]-(i-1)+1;
//cout<<sumx<<sumy<<"\n";
ans*=A(sumx,sumy);
ans%=mod;
i=j;
}
// else{
// //cout<<"fun\n";
// ans*=2;
// ans%=mod;
// ans-=2;
// ans%=mod;
// }
}
cout<<ans%mod<<"\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t = 1;
cin >> t;
for (int i = 1; i <= t; i++) {
//cout << "Case #" << i << ":";
// cout<<"n: ";
// cout<<i<<" \n";
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3728kb
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: 66ms
memory: 4388kb
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 360 0 0 0 0 0 399295573 0 5952 12 25344000 672 2 0 11854080 0 0 2 0 0 0 0 86400 0 0 69120 12 0 120 0 0 0 686776320 0 2 0 0 0 0 2 0 2 928319853 0 0 0 0 4 0 0 0 32256 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 84 0 0 672 0 0 2 10 0 0 221184 0 0 336357141 108 0 0 8064 0 0 864 0 37324800 4 0 120960...
result:
wrong answer 7th lines differ - expected: '24576', found: '360'