QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#645922 | #9353. Interesting Permutation | Coffeecat996 | RE | 0ms | 3588kb | C++14 | 873b | 2024-10-16 20:28:26 | 2024-10-16 20:28:26 |
Judging History
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=0;
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])
{
ans=(ans*2)%mod;
num+=a[i]-a[i-1]-1;
}
else if(i!=0)
{
ans=(ans*num)%mod;
num--;
}
}
if(flag==0 || a[n-1]!=n-1)
{
cout<<"0\n";
return ;
}
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;
while(t--){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3588kb
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
Runtime Error
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...