結果

問題 No.1035 Color Box
ユーザー zeus_metallordzeus_metallord
提出日時 2020-04-24 23:11:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,447 bytes
コンパイル時間 1,663 ms
コンパイル使用メモリ 164,708 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-23 04:12:22
合計ジャッジ時間 2,557 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 4 ms
6,944 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 4 ms
6,940 KB
testcase_17 AC 4 ms
6,944 KB
testcase_18 AC 4 ms
6,940 KB
testcase_19 WA -
testcase_20 AC 4 ms
6,940 KB
testcase_21 AC 4 ms
6,944 KB
testcase_22 AC 4 ms
6,944 KB
testcase_23 AC 3 ms
6,940 KB
testcase_24 WA -
testcase_25 AC 4 ms
6,944 KB
testcase_26 AC 4 ms
6,940 KB
testcase_27 AC 3 ms
6,944 KB
testcase_28 AC 4 ms
6,940 KB
testcase_29 AC 4 ms
6,940 KB
testcase_30 AC 4 ms
6,944 KB
testcase_31 AC 3 ms
6,940 KB
testcase_32 AC 4 ms
6,940 KB
testcase_33 AC 4 ms
6,940 KB
testcase_34 AC 4 ms
6,940 KB
testcase_35 AC 4 ms
6,944 KB
testcase_36 AC 3 ms
6,940 KB
testcase_37 AC 3 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include <algorithm>
#include<cstdio>
#include<string>
#include<math.h>
#include<vector>
#include <queue>
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define srep(i,s,t) for (long long i = s; i < t; i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
#define MOD 1000000007
#define MAX 100000
using namespace std;
typedef vector<vector<char>> field_t;

typedef pair<int, int> point_t;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(long long n, long long k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// a^n mod を計算する
long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}
int co(long long N,long long  M){
	long long C,i;
	i=1;
	C=modpow(M,N);
	if(M==1){
		return C;
	}else{
		while(M-i>=1){
			C=C+pow(-1.0,double(i))*COM(M,M-i)*modpow(M-i,N);
			i++;
		}
		
	}
	return C;
}
int main()
{
	 COMinit();
    long long N,M,Z;
    cin >> N >> M;
	Z=co(N,M);
	
	cout<<Z<<endl;

}
0