QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#572692 | #9353. Interesting Permutation | leo2005 | WA | 0ms | 3832kb | C++14 | 888b | 2024-09-18 15:58:35 | 2024-09-18 15:58:35 |
Judging History
answer
#include<iostream>
#include<cstdio>
using namespace std;
const int maxn=1e5+5;
const int mod=1e9+7;
int h[maxn];
typedef long long ll;
int t;
int n;
void solve(){
ll p,q;
int flag=1;
scanf("%lld",&n);
scanf("%lld",&p);
ll ans=1,cnt=0;
if(p!=0){
flag=0;
}
for(int i=0;i<n-1;i++){
scanf("%lld",&q);
if(q<p||q>=n){
flag=0;
}
if(q>p){//第一种情况,后面一项比前面一项大
cnt=(cnt+q-p-1)%mod;
ans=(ans*2)%mod;
}else if(p==q){//第二种情况,后面一项和前面一项相等
ans=(ans*cnt)%mod;
cnt=(cnt-1)%mod;
}
p=q;
}
if(flag){
printf("%lld\n",ans);
}else{
printf("0\n");
}
}
int main(){
cin>>t;
while (t--)
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3832kb
input:
3 3 0 2 2 3 0 1 2 3 0 2 3
output:
2
result:
wrong answer 2nd lines differ - expected: '4', found: ''