QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#607813#9354. Justifying the Conjectureshmilyc#WA 1ms3616kbC++201.2kb2024-10-03 16:31:212024-10-03 16:31:22

Judging History

你现在查看的是最新测评结果

  • [2024-10-03 16:31:22]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3616kb
  • [2024-10-03 16:31:21]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

#define endl '\n'
const int MOD=1e9+7;
#define int long long
#define mp make_pair
#define ll long long
ll modExp(ll base, ll exp, ll mod) {
    ll result = 1;
    while (exp > 0) {
        if (exp % 2 == 1) {
            result = (result * base) % mod;
        }
        base = (base * base) % mod;
        exp /= 2;
    }
    return result;
}

// 计算模逆元
ll modInverse(ll x, ll mod) {
    return modExp(x, mod - 2, mod);
}

void solve()
{
    int n;
    cin>>n;
    vector<int> a(n+1);
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    int ans=1;
    int len=0;
    if(a[1]!=0||a[n]!=n-1){
        cout<<0<<endl;
        return;
    }
    for(int i=1;i<=n;i++){
        if(a[i]<a[i-1]||a[i]<i-1){
            cout<<0<<endl;
            return;
        }
        if(a[i]+1>len)
            ans=(ans*2)%MOD;
        else
            ans=(ans*(len-i+1))%MOD;
        len=a[i]+1;
    }
    cout<<ans*modInverse(2,MOD)%MOD<<endl;
    return;
}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int T;
    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: 1ms
memory: 3616kb

input:

3
4
6
7

output:

0
0
0

result:

wrong answer Integer 0 violates the range [1, 10^9]