結果
問題 | No.2846 Birthday Cake |
ユーザー |
![]() |
提出日時 | 2024-07-15 18:38:43 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 151 ms / 2,000 ms |
コード長 | 799 bytes |
コンパイル時間 | 868 ms |
コンパイル使用メモリ | 76,928 KB |
最終ジャッジ日時 | 2025-02-23 15:47:37 |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 34 |
ソースコード
#include <iostream> #include <vector> #include <numeric> using namespace std; int main(){ int k, n; cin >> k >> n; int l = 1; int cnt = 0; for (int i = 1; i <= n; i++){ if (i != 13 && i != 17 && i != 19 && i != 23) l = lcm(l, i); else cnt++; } vector dp(k + 1, vector<long long>(l + 1)); // dp[i][j] = (i人目までの取り分を決めたときにその総和がjであるような分け方) dp[0][0] = 1; for (int i = 0; i < k; i++){ for (int j = 0; j <= l; j++){ for (int x = 1; x <= n; x++){ if (l % x == 0){ int cake = l / x; if (j + cake <= l) dp[i + 1][j + cake] += dp[i][j]; } } } } long long ans = dp[k][l]; if (k == 13 || k == 17 || k == 19 || k == 23) ans++; cout << ans << endl; }