AtCoder Regular Contest 023

Submission #782510

Source codeソースコード

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

const ll mod = 1000000007;

//nPr
ll mod_perm(ll n, ll r)
{
    ll ret=1;
    rep(i,r) (ret*=n-i)%=mod;
    return ret;
}

//逆元
ll mod_inv(ll n)
{
    ll pw[32];

    pw[0]=n%mod;
    for(int i=1; i<32; ++i) pw[i]=(pw[i-1]*pw[i-1])%mod;

    ll ret=1;
    ll x=mod-2;
    rep(i,32) if(x>>i&1) (ret*=pw[i])%=mod;

    return ret;
}

int main()
{
    int n;
    cin >>n;
    vector<ll> a(n);
    rep(i,n) cin >>a[i];

    ll ans=1;

    int st=0;
    while(st<n)
    {
        int ed=st+1;
        while(ed<n && a[ed]==-1) ++ed;

        if(ed>=n) break;

        ll X=a[st], Y=a[ed], L=ed-st-1;
        if(L>0)
        {
            (ans*=mod_perm(Y-X+L,L))%=mod;
            (ans*=mod_inv(mod_perm(L,L)))%=mod;
        }

        st=ed;
    }

    cout << ans << endl;
    return 0;
}

Submission

Task問題 C - タコヤ木
User nameユーザ名 imulan
Created time投稿日時
Language言語 C++11 (GCC 4.8.1)
Status状態 AC
Score得点 100
Source lengthソースコード長 1171 Byte
File nameファイル名
Exec time実行時間 29 ms
Memory usageメモリ使用量 1052 KB

Test case

Set

Set name Score得点 / Max score Cases
Sample - sample_01.txt,sample_02.txt,sample_03.txt
Subtask1 50 / 50 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 30 / 30 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 20 / 20 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

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
sample_01.txt AC 27 ms 1044 KB
sample_02.txt AC 24 ms 1044 KB
sample_03.txt AC 24 ms 1052 KB
subtask1_01.txt AC 27 ms 936 KB
subtask1_02.txt AC 27 ms 940 KB
subtask1_03.txt AC 26 ms 1048 KB
subtask1_04.txt AC 26 ms 1048 KB
subtask1_05.txt AC 26 ms 1052 KB
subtask1_06.txt AC 27 ms 920 KB
subtask1_07.txt AC 25 ms 1040 KB
subtask1_08.txt AC 26 ms 920 KB
subtask1_09.txt AC 25 ms 936 KB
subtask1_10.txt AC 26 ms 1048 KB
subtask1_11.txt AC 29 ms 1052 KB
subtask1_12.txt AC 25 ms 964 KB
subtask2_01.txt AC 26 ms 1048 KB
subtask2_02.txt AC 26 ms 1048 KB
subtask2_03.txt AC 27 ms 1044 KB
subtask2_04.txt AC 28 ms 936 KB
subtask2_05.txt AC 28 ms 1048 KB
subtask2_06.txt AC 28 ms 940 KB
subtask2_07.txt AC 26 ms 1040 KB
subtask2_08.txt AC 28 ms 1048 KB
subtask2_09.txt AC 29 ms 940 KB
subtask2_10.txt AC 28 ms 940 KB
subtask2_11.txt AC 26 ms 936 KB
subtask2_12.txt AC 27 ms 1044 KB
subtask3_01.txt AC 26 ms 1048 KB
subtask3_02.txt AC 24 ms 940 KB
subtask3_03.txt AC 25 ms 936 KB
subtask3_04.txt AC 27 ms 1048 KB
subtask3_05.txt AC 27 ms 1044 KB
subtask3_06.txt AC 27 ms 964 KB
subtask3_07.txt AC 27 ms 1044 KB
subtask3_08.txt AC 26 ms 1040 KB
subtask3_09.txt AC 27 ms 1044 KB
subtask3_10.txt AC 28 ms 1048 KB
subtask3_11.txt AC 25 ms 1044 KB
subtask3_12.txt AC 26 ms 924 KB