結果
問題 | No.1106 🦉 何事もバランスが大事 |
ユーザー |
|
提出日時 | 2021-01-23 13:26:58 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 58 ms / 2,000 ms |
コード長 | 1,079 bytes |
コンパイル時間 | 850 ms |
コンパイル使用メモリ | 82,016 KB |
最終ジャッジ日時 | 2025-01-18 07:26:25 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 77 |
ソースコード
#line 1 "main.cpp" #include <iostream> #include <algorithm> #include <vector> #include <string> using namespace std; using lint = long long; lint calc(vector<int>& ds) { int n = ds.size(); auto dp = vector(2, vector(n * 4 + 1, 0LL)); dp[0][0] = dp[1][0] = 1; for (auto d : ds) { auto ndp = vector(2, vector(n * 4 + 1, 0LL)); for (int s = 0; s <= (n - 1) * 4; ++s) { for (int i = 0; i <= 4; ++i) { ndp[0][s + i] += dp[0][s]; } for (int i = 0; i < d; ++i) { ndp[1][s + i] += dp[0][s]; } ndp[1][s + d] += dp[1][s]; } swap(dp, ndp); } return dp[1][n * 2]; } void solve() { lint n; cin >> n; vector<int> ds; while (n != 0) { lint d = ((n + 2) % 5 + 5) % 5; ds.push_back(d); n -= (d - 2); n /= 5; } vector<int> zs(ds.size(), 2); cout << calc(ds) - calc(zs) << "\n"; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); solve(); return 0; }