結果
問題 | No.27 板の準備 |
ユーザー |
|
提出日時 | 2023-02-21 16:40:35 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 5,000 ms |
コード長 | 1,182 bytes |
コンパイル時間 | 737 ms |
コンパイル使用メモリ | 72,280 KB |
最終ジャッジ日時 | 2025-02-10 19:44:35 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 |
ソースコード
#include <iostream>#include <vector>int solve(std::vector<int> &V) {const int MAX = 30;const int INF = 100;int ans = INF;for (int A = 1; A <= MAX; A++) {for (int B = A + 1; B <= MAX; B++) {for (int C = B + 1; C <= MAX; C++) {std::vector<int> dp(MAX + 1, INF);dp.at(0) = 0;for (int i = 0; i < MAX; i++) {int y = dp.at(i) + 1;for (const auto &x: {A, B, C}) {if (i + x <= MAX && dp.at(i + x) > y) {dp.at(i + x) = y;}}}int tmp = 0;for (const auto &v: V) {if (dp.at(v) == INF) {tmp = INF;} else {tmp += dp.at(v);}}if (ans > tmp) { ans = tmp; }}}}return (ans != INF ? ans : -1);}int main() {std::vector<int> V(4);for (int i = 0; i < 4; i++) { std::cin >> V.at(i); }std::cout << solve(V) << std::endl;}