結果

問題 No.573 a^2[i] = a[i]
ユーザー snrnsidysnrnsidy
提出日時 2021-11-30 21:36:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 14 ms / 2,000 ms
コード長 1,139 bytes
コンパイル時間 2,078 ms
コンパイル使用メモリ 197,768 KB
実行使用メモリ 6,748 KB
最終ジャッジ日時 2023-09-16 19:00:56
合計ジャッジ時間 4,234 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
6,620 KB
testcase_01 AC 6 ms
6,552 KB
testcase_02 AC 6 ms
6,472 KB
testcase_03 AC 6 ms
6,476 KB
testcase_04 AC 6 ms
6,472 KB
testcase_05 AC 6 ms
6,680 KB
testcase_06 AC 6 ms
6,600 KB
testcase_07 AC 6 ms
6,484 KB
testcase_08 AC 6 ms
6,476 KB
testcase_09 AC 6 ms
6,468 KB
testcase_10 AC 6 ms
6,516 KB
testcase_11 AC 6 ms
6,484 KB
testcase_12 AC 5 ms
6,512 KB
testcase_13 AC 6 ms
6,700 KB
testcase_14 AC 6 ms
6,596 KB
testcase_15 AC 5 ms
6,736 KB
testcase_16 AC 6 ms
6,484 KB
testcase_17 AC 6 ms
6,472 KB
testcase_18 AC 6 ms
6,500 KB
testcase_19 AC 6 ms
6,612 KB
testcase_20 AC 6 ms
6,464 KB
testcase_21 AC 5 ms
6,516 KB
testcase_22 AC 6 ms
6,484 KB
testcase_23 AC 6 ms
6,480 KB
testcase_24 AC 6 ms
6,488 KB
testcase_25 AC 6 ms
6,472 KB
testcase_26 AC 6 ms
6,564 KB
testcase_27 AC 5 ms
6,472 KB
testcase_28 AC 6 ms
6,552 KB
testcase_29 AC 6 ms
6,500 KB
testcase_30 AC 6 ms
6,472 KB
testcase_31 AC 6 ms
6,684 KB
testcase_32 AC 6 ms
6,488 KB
testcase_33 AC 6 ms
6,484 KB
testcase_34 AC 6 ms
6,512 KB
testcase_35 AC 6 ms
6,736 KB
testcase_36 AC 6 ms
6,480 KB
testcase_37 AC 6 ms
6,484 KB
testcase_38 AC 6 ms
6,516 KB
testcase_39 AC 6 ms
6,552 KB
testcase_40 AC 6 ms
6,476 KB
testcase_41 AC 6 ms
6,748 KB
testcase_42 AC 6 ms
6,500 KB
testcase_43 AC 6 ms
6,616 KB
testcase_44 AC 6 ms
6,540 KB
testcase_45 AC 6 ms
6,464 KB
testcase_46 AC 14 ms
6,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const long long int MOD = 1e9 + 7;
long long int f[200001];
long long int invf[200001];
long long int mypow(long long int x,long long int n)
{
    long long int res = 1;
    while(n>0)
    {
        if(n%2==1)
        {
            res*=x;
            res%=MOD;
        }
        x*=x;
        x%=MOD;
        n/=2;
    }
    return res;
}

//  Sum_{k=0..n} C(n,k)*(n-k)^k

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;

    f[0] = 1;
    for(int i=1;i<=200000;i++)
    {
        f[i] = f[i-1];
        f[i]*=i;
        f[i]%=MOD;
    }
    invf[200000] = mypow(f[200000],MOD-2);
    for(int i=199999;i>=0;i--)
    {
        invf[i] = invf[i+1];
        invf[i]*=(i+1);
        invf[i]%=MOD;
    }

    long long int res = 0;

    cin >> n;

    for(int k=0;k<=n;k++)
    {
        long long int val = mypow(n-k,k);
        long long int way = f[n];
        way*=invf[k];
        way%=MOD;
        way*=invf[n-k];
        way%=MOD;
        way*=val;
        way%=MOD;
        res += way;
        res%=MOD;
    }
    
    cout << res << '\n';
    return 0;
}
0