結果

問題 No.3053 2.5 色で色塗り
ユーザー AquariusAquarius
提出日時 2020-04-15 11:46:02
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 163 ms / 2,000 ms
コード長 698 bytes
コンパイル時間 1,635 ms
コンパイル使用メモリ 164,568 KB
実行使用メモリ 120,320 KB
最終ジャッジ日時 2024-04-09 18:36:26
合計ジャッジ時間 2,853 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 34 ms
27,648 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 123 ms
91,648 KB
testcase_11 AC 154 ms
114,304 KB
testcase_12 AC 163 ms
120,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long m = 1000000007;
const long p = 500000006;
int a, b;
long dp[5001][5001];

long mpow(long b, long e) {
  if (e == 0) return 1;
  if (e % 2 == 1) return b * mpow(b, e - 1) % m;
  long t = mpow(b, e / 2);
  return t * t % m;
}

int main() {
  cin >> a >> b;
  
  dp[0][0] = 1;
  for (int i = 0; i < a; ++i) {
    for (int j = 0; j <= i; ++j) {
      (dp[i + 1][j + 1] += dp[i][j]) %= m;
      (dp[i + 1][j] += j * dp[i][j]) %= m;
    }
  }
  
  long f = 1;
  long sum = 0;
  for (int j = 0; j <= a; ++j) {
    long l = dp[a][j] * f % m;
    long r = mpow(p - j, b);
    (sum += l * r) %= m;
    f = f * (p - j) % m;
  }
  cout << sum << endl;
}
0