結果

問題 No.1035 Color Box
ユーザー marurunn11marurunn11
提出日時 2020-05-01 16:57:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,821 bytes
コンパイル時間 1,704 ms
コンパイル使用メモリ 189,180 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-08-25 22:14:30
合計ジャッジ時間 4,451 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
権限があれば一括ダウンロードができます

ソースコード

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