Submission #1437679


Source Code Expand

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i,a,b) for(ll i=(a);i<(b);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1LL<<59)

const ll MOD = 1777777777LL;

//verified KUPC2014-D,ABC034-C,ARC023-C
//O(r log MOD)
ll power(ll a,ll b){
    ll ret=1;
    if(b>0){
        ret = power(a,b/2);
        if(b%2==0)ret = (ret*ret)%MOD;
        else ret = (((ret*ret)%MOD)*a)%MOD;
    }
    return ret;
}

ll inv(int n){ return power(n,MOD-2); }

ll C(int n,int r){
    r = min(r,n-r);
    ll ret=1;
    for(int i=n;i>n-r;i--) (ret*=i%MOD)%=MOD;
    for(int i=r;i>=1;i--) (ret*=inv(i))%=MOD;
    return ret;
}



signed main(){
    int fact[777778]={1};
    for(int i=1;i<777778;i++){
        fact[i] = (fact[i-1]*i)%MOD;
    }
    int n,k;
    cin>>n>>k;
    
    
    ll ans = 0;
    
    for(int i=0;i<=k;i++){
        if(i%2==0) ans += (fact[k] * inv(fact[i]))%MOD;
        if(i%2==1) ans += MOD - (fact[k] * inv(fact[i]))%MOD;
        ans%=MOD;
    }
    cout<<(C(n,k) * ans)%MOD<<endl;
}

Submission Info

Submission Time
Task C - 高橋君、24歳
User Yazaten
Language C++14 (GCC 5.4.1)
Score 100
Code Size 1194 Byte
Status AC
Exec Time 258 ms
Memory 6272 KB

Judge Result

Set Name small large
Score / Max Score 40 / 40 60 / 60
Status
AC × 15
AC × 27
Set Name Test Cases
small 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 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
Case Name Status Exec Time Memory
00_small/small_00_sample1.txt AC 8 ms 6272 KB
00_small/small_00_sample2.txt AC 8 ms 6272 KB
00_small/small_00_sample3.txt AC 8 ms 6272 KB
00_small/small_00_sample4.txt AC 8 ms 6272 KB
00_small/small_01_rand_01.txt AC 8 ms 6272 KB
00_small/small_01_rand_02.txt AC 8 ms 6272 KB
00_small/small_01_rand_03.txt AC 8 ms 6272 KB
00_small/small_01_rand_05.txt AC 8 ms 6272 KB
00_small/small_01_rand_07.txt AC 8 ms 6272 KB
00_small/small_01_rand_08.txt AC 8 ms 6272 KB
00_small/small_01_rand_09.txt AC 8 ms 6272 KB
00_small/small_01_rand_10.txt AC 8 ms 6272 KB
00_small/small_01_rand_13.txt AC 8 ms 6272 KB
00_small/small_01_rand_14.txt AC 8 ms 6272 KB
00_small/small_01_rand_18.txt AC 8 ms 6272 KB
01_large/large_00_sample5.txt AC 8 ms 6272 KB
01_large/large_01_rand_01.txt AC 105 ms 6272 KB
01_large/large_01_rand_02.txt AC 199 ms 6272 KB
01_large/large_01_rand_03.txt AC 80 ms 6272 KB
01_large/large_01_rand_05.txt AC 253 ms 6272 KB
01_large/large_01_rand_07.txt AC 12 ms 6272 KB
01_large/large_01_rand_08.txt AC 31 ms 6272 KB
01_large/large_01_rand_09.txt AC 153 ms 6272 KB
01_large/large_01_rand_10.txt AC 40 ms 6272 KB
01_large/large_01_rand_13.txt AC 258 ms 6272 KB
01_large/large_01_rand_14.txt AC 125 ms 6272 KB
01_large/large_01_rand_18.txt AC 229 ms 6272 KB