結果

問題 No.1035 Color Box
ユーザー marurunn11marurunn11
提出日時 2020-05-01 16:57:47
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 120 ms / 2,000 ms
コード長 1,823 bytes
コンパイル時間 1,779 ms
コンパイル使用メモリ 187,492 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-25 22:15:21
合計ジャッジ時間 4,006 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 10 ms
4,380 KB
testcase_04 AC 12 ms
4,380 KB
testcase_05 AC 5 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 105 ms
4,376 KB
testcase_09 AC 43 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 83 ms
4,376 KB
testcase_14 AC 96 ms
4,384 KB
testcase_15 AC 120 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 119 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 1 ms
4,376 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;
		}
	}

	if (res < 0) res += large_P;

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

	//cout << -576992686 + large_P << endl;
}
0