Submission #172102


Source Code Expand

Copy
#include <queue>
#include <map>
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include <stack>
#include <algorithm>
#include <bitset>
#include <sstream>
#include <string>
#include <cmath>
#include <stack>
#include <math.h>
#include <list>
#include <set>
#include <complex>
#include <string.h>

#define INF (1 << 29)
#define rep2(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) rep2(i,0,n)
#define squere(x) ((x)*(x))
#define EPS 1e-20

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

int dx[4] = {-1,0,1,0};
int dy[4] = {0,1,0,-1};

#define MAX_P (ll)(1000000007)

// vector<ll> fact;
//
// void fact_init(){
//     fact.reserve(MAX_P);
//     fact[0] = 1;
//     fact[1] = 1;
//     rep2(i,2,MAX_P){
//         fact[i]=fact[i-1]*i%MAX_P;
//     }
// }
//
ll fact(ll n, ll p){
    ll res = 1;
    rep2(i,1,n+1){
        res *= i;
        res %= p;
    }
    return res;
}

ll extgcd(ll a, ll b, ll &x, ll &y){
    ll d = a;
    if(b!=0){
        d = extgcd(b,a%b,y,x);
        y-=(a/b)*x;
    } else {
        x = 1; y = 0;
    }
    return d;
}

ll mod_inverse(ll a, ll m){
    ll x,y;
    extgcd(a,m,x,y);
    return (m+x%m)%m;
}

ll mod_fact(ll n, ll p, ll &e){
    e = 0;
    if(n==0) return 1;
    ll res = mod_fact(n/p,p,e);
    e += n/p;
    if(n/p%2!=0) return res * (p-fact(n%p,p))%p;
    return res*fact(n%p,p)%p;
}

ll mod_comb(ll n, ll k, ll p){
    if (n < 0 || k < 0 || n < k) return 0;
    ll e1,e2,e3;
    ll a1 = mod_fact(n,p,e1);
    ll a2 = mod_fact(k,p,e2);
    ll a3 = mod_fact(n-k,p,e3);
    if(e1>e2+e3) return 0;
    return a1*mod_inverse(a2*a3%p,p)%p;
}

int main()
{
    int N;
    ll res = 1;
    ll last = 1;
    int count = 0;
    // fact_init();
    cin >> N;
    rep(i,N){
        ll a;
        cin >> a;
        if(a!=-1){
            if(count==0) last = a;
            else{
                res *= mod_comb(a-last+count,count,MAX_P);
                res %= MAX_P;
                count = 0;
                last = a;
            }
        } else {
            count++;
        }
    }
    cout << res << endl;
    return 0;
}

Submission Info

Submission Time
Task C - タコヤ木
User garasubo
Language C++ (G++ 4.6.4)
Score 80
Code Size 2276 Byte
Status TLE
Exec Time 2030 ms
Memory 928 KB

Judge Result

Set Name Sample Subtask1 Subtask2 Subtask3
Score / Max Score 0 / 0 50 / 50 30 / 30 0 / 20
Status
AC × 2
TLE × 1
AC × 14
AC × 26
AC × 29
TLE × 7
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
Subtask1 sample_01.txt, sample_02.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt
Subtask2 sample_01.txt, sample_02.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask2_01.txt, subtask2_02.txt, subtask2_03.txt, subtask2_04.txt, subtask2_05.txt, subtask2_06.txt, subtask2_07.txt, subtask2_08.txt, subtask2_09.txt, subtask2_10.txt, subtask2_11.txt, subtask2_12.txt
Subtask3 subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask2_01.txt, subtask2_02.txt, subtask2_03.txt, subtask2_04.txt, subtask2_05.txt, subtask2_06.txt, subtask2_07.txt, subtask2_08.txt, subtask2_09.txt, subtask2_10.txt, subtask2_11.txt, subtask2_12.txt, subtask3_01.txt, subtask3_02.txt, subtask3_03.txt, subtask3_04.txt, subtask3_05.txt, subtask3_06.txt, subtask3_07.txt, subtask3_08.txt, subtask3_09.txt, subtask3_10.txt, subtask3_11.txt, subtask3_12.txt
Case Name Status Exec Time Memory
sample_01.txt AC 27 ms 676 KB
sample_02.txt AC 20 ms 800 KB
sample_03.txt TLE 2030 ms 800 KB
subtask1_01.txt AC 21 ms 796 KB
subtask1_02.txt AC 20 ms 760 KB
subtask1_03.txt AC 20 ms 796 KB
subtask1_04.txt AC 20 ms 804 KB
subtask1_05.txt AC 20 ms 800 KB
subtask1_06.txt AC 20 ms 804 KB
subtask1_07.txt AC 20 ms 796 KB
subtask1_08.txt AC 21 ms 704 KB
subtask1_09.txt AC 21 ms 800 KB
subtask1_10.txt AC 21 ms 920 KB
subtask1_11.txt AC 21 ms 800 KB
subtask1_12.txt AC 21 ms 796 KB
subtask2_01.txt AC 19 ms 796 KB
subtask2_02.txt AC 20 ms 800 KB
subtask2_03.txt AC 21 ms 916 KB
subtask2_04.txt AC 21 ms 800 KB
subtask2_05.txt AC 21 ms 676 KB
subtask2_06.txt AC 21 ms 796 KB
subtask2_07.txt AC 21 ms 800 KB
subtask2_08.txt AC 22 ms 928 KB
subtask2_09.txt AC 20 ms 920 KB
subtask2_10.txt AC 20 ms 924 KB
subtask2_11.txt AC 20 ms 672 KB
subtask2_12.txt AC 22 ms 696 KB
subtask3_01.txt AC 21 ms 672 KB
subtask3_02.txt TLE 2028 ms 796 KB
subtask3_03.txt AC 559 ms 800 KB
subtask3_04.txt TLE 2029 ms 812 KB
subtask3_05.txt AC 1696 ms 796 KB
subtask3_06.txt TLE 2029 ms 808 KB
subtask3_07.txt TLE 2028 ms 808 KB
subtask3_08.txt AC 21 ms 796 KB
subtask3_09.txt AC 20 ms 800 KB
subtask3_10.txt TLE 2030 ms 872 KB
subtask3_11.txt TLE 2029 ms 804 KB
subtask3_12.txt TLE 2030 ms 908 KB