結果
問題 | No.1035 Color Box |
ユーザー |
![]() |
提出日時 | 2020-05-01 16:57:47 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 133 ms / 2,000 ms |
コード長 | 1,823 bytes |
コンパイル時間 | 2,168 ms |
コンパイル使用メモリ | 189,796 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-24 09:14:14 |
合計ジャッジ時間 | 4,323 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 36 |
ソースコード
#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_ifor (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;}