QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#645874 | #9353. Interesting Permutation | Coffeecat996 | TL | 0ms | 4152kb | C++14 | 1014b | 2024-10-16 20:18:14 | 2024-10-16 20:18:15 |
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;
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(flag==0)
{
cout<<"0\n";
return ;
}
int ans=1;
int num=1;
for(int i=1;i<n;i++)
{
if(a[i]!=a[i-1])
{
if(num>1)
{
num--;
}
ans=(ans*tt[num])%mod;
// while(num!=1)
// {
// ans=(ans*num)%mod;
// num--;
// }
ans=(ans*2)%mod;
}
else
{
num++;
}
}
if(num!=1)
{
num--;
}
ans=(ans*tt[num])%mod;
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;
init();
while(t--){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 4152kb
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
Time Limit Exceeded
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:
30720 0 0 0 1 0 0 0 0 0 0 330919827 9437184 8192 12288 589934536 892348547 229815353 358179462 607312884 274842888 8388608 8 633715064 6144 2 623878635 284823005 268435456 438952513 2 712929447 826227383 354091247 8 245760 473585978 4194304 16384 16 439276074 768 393216 348986096 48 764905737 209715...