AtCoder Regular Contest 009

Submission #758298

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 =1777777777;

ll mod_inv(ll x)
{
    ll pw[33];
    pw[0]=x%mod;
    for(int i=1; i<=32; ++i) pw[i]=(pw[i-1]*pw[i-1])%mod;

    ll p=mod-2;
    ll ret=1;
    rep(i,33)
    {
        if(p>>i&1)
        {
            ret*=pw[i];
            ret%=mod;
        }
    }

    return ret;
}

int main()
{
    ll n,k;
    cin >>n >>k;

    ll ans=1;
    for(ll i=n-k+1; i<=n; ++i)
    {
        ans*=i%mod;
        ans%=mod;
    }
    for(ll i=1; i<=k; ++i)
    {
        ans*=mod_inv(i);
        ans%=mod;
    }

    ll m[777778];
    m[1]=0;
    m[2]=1;
    for(int i=3; i<=k; ++i)
    {
        m[i]=(m[i-1]+m[i-2])%mod;
        m[i]*=i-1;
        m[i]%=mod;
    }

    ans*=m[k];
    ans%=mod;

    cout << ans << endl;

    return 0;
}

Submission

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

Test case

Set

Set name Score得点 / Max score Cases
small 40 / 40 00_small/small_00_sample1.txt,00_small/small_00_sample2.txt,00_small/small_00_sample3.txt,00_small/small_00_sample4.txt,00_small/small_01_rand_01.txt,00_small/small_01_rand_02.txt,00_small/small_01_rand_03.txt,00_small/small_01_rand_05.txt,00_small/small_01_rand_07.txt,00_small/small_01_rand_08.txt,00_small/small_01_rand_09.txt,00_small/small_01_rand_10.txt,00_small/small_01_rand_13.txt,00_small/small_01_rand_14.txt,00_small/small_01_rand_18.txt
large 60 / 60 00_small/small_00_sample1.txt,00_small/small_00_sample2.txt,00_small/small_00_sample3.txt,00_small/small_00_sample4.txt,00_small/small_01_rand_01.txt,00_small/small_01_rand_02.txt,00_small/small_01_rand_03.txt,00_small/small_01_rand_05.txt,00_small/small_01_rand_07.txt,00_small/small_01_rand_08.txt,00_small/small_01_rand_09.txt,00_small/small_01_rand_10.txt,00_small/small_01_rand_13.txt,00_small/small_01_rand_14.txt,00_small/small_01_rand_18.txt,01_large/large_00_sample5.txt,01_large/large_01_rand_01.txt,01_large/large_01_rand_02.txt,01_large/large_01_rand_03.txt,01_large/large_01_rand_05.txt,01_large/large_01_rand_07.txt,01_large/large_01_rand_08.txt,01_large/large_01_rand_09.txt,01_large/large_01_rand_10.txt,01_large/large_01_rand_13.txt,01_large/large_01_rand_14.txt,01_large/large_01_rand_18.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
00_small/small_00_sample1.txt AC 28 ms 952 KB
00_small/small_00_sample2.txt AC 26 ms 1052 KB
00_small/small_00_sample3.txt AC 26 ms 928 KB
00_small/small_00_sample4.txt AC 26 ms 948 KB
00_small/small_01_rand_01.txt AC 25 ms 944 KB
00_small/small_01_rand_02.txt AC 25 ms 1052 KB
00_small/small_01_rand_03.txt AC 26 ms 948 KB
00_small/small_01_rand_05.txt AC 25 ms 952 KB
00_small/small_01_rand_07.txt AC 26 ms 1052 KB
00_small/small_01_rand_08.txt AC 25 ms 1036 KB
00_small/small_01_rand_09.txt AC 26 ms 948 KB
00_small/small_01_rand_10.txt AC 26 ms 1044 KB
00_small/small_01_rand_13.txt AC 26 ms 948 KB
00_small/small_01_rand_14.txt AC 26 ms 1052 KB
00_small/small_01_rand_18.txt AC 26 ms 944 KB
01_large/large_00_sample5.txt AC 26 ms 1052 KB
01_large/large_01_rand_01.txt AC 115 ms 2360 KB
01_large/large_01_rand_02.txt AC 201 ms 3636 KB
01_large/large_01_rand_03.txt AC 92 ms 1972 KB
01_large/large_01_rand_05.txt AC 249 ms 4532 KB
01_large/large_01_rand_07.txt AC 31 ms 948 KB
01_large/large_01_rand_08.txt AC 48 ms 1204 KB
01_large/large_01_rand_09.txt AC 157 ms 2992 KB
01_large/large_01_rand_10.txt AC 56 ms 1332 KB
01_large/large_01_rand_13.txt AC 252 ms 4536 KB
01_large/large_01_rand_14.txt AC 131 ms 2608 KB
01_large/large_01_rand_18.txt AC 226 ms 4148 KB