結果

問題 No.1035 Color Box
ユーザー marurunn11marurunn11
提出日時 2020-05-01 16:54:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,746 bytes
コンパイル時間 2,177 ms
コンパイル使用メモリ 188,812 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-25 22:08:33
合計ジャッジ時間 5,285 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"
//#include <intrin.h>  //AtCoder (gcc) 上ではこれがあると動かない。__popcnt用のincludeファイル。
using namespace std;
using Graph = vector<vector<int>>;

typedef long long ll;
typedef long double ld;


#define int long long
#define rep(i, n) for(long long i = 0; i < (n); i++)
#define sqrt(d) pow((long double) (d), 0.50)

const int INF = 2e9;
const ll large_P = 1e9 + 7;



//繰り返し2乗法
//N^aの、Mで割った余りを求める。
ll my_pow(ll N, ll a, ll M) {
	ll tempo;
	if (a == 0) {
		return 1;
	}
	else {
		if (a % 2 == 0) {
			tempo = my_pow(N, a / 2, M);
			return (tempo * tempo) % M;
		}
		else {
			tempo = my_pow(N, a - 1, M);
			return (tempo * N) % M;
		}
	}
}



//N_C_a を M で割った余り
ll my_combination(ll N, ll a, ll M) {
	ll answer = 1;

	rep(i, a) {
		answer *= (N - i);
		answer %= M;
	}

	rep(i, a) {
		answer *= my_pow(i + 1, M - 2, M);
		answer %= M;
	}

	return answer;
}



signed main() {
	int N, M;
	cin >> N >> M;

	ll res = 0LL;

	vector<ll> combination(M + 1, 0);  //i番目に M_C_i

	for (int i = M; i >= 1; i--) {
		if (i == M) {
			combination.at(M - i) = 1;
		}
		else {
			combination.at(M - i) = combination.at(M - i - 1) * (i + 1);
			combination.at(M - i) %= large_P;
			
			combination.at(M - i) *= my_pow(M - i, large_P - 2, large_P);
			combination.at(M - i) %= large_P;
		}
		ll temp = (my_pow(i, N, large_P) * combination.at(M - i)) % large_P;


		if ((M - i) % 2 == 0) {
			res += temp;
			res %= large_P;
			//cout << res << endl;
		}
		else {
			res -= temp;
			res %= large_P;
			//cout << res << endl;
		}
	}

	cout << res << endl;
		
	rep(i, M+1) {
		//cout << i << ": " << combination.at(i) << endl;;
	}
}
0