結果

問題 No.27 板の準備
ユーザー kimiyukikimiyuki
提出日時 2016-09-27 21:29:22
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,055 bytes
コンパイル時間 636 ms
コンパイル使用メモリ 68,140 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-27 04:35:53
合計ジャッジ時間 1,371 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 3 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <array>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
#define repeat_from(i,m,n) for (int i = (m); (i) < (n); ++(i))
#define whole(f,x,...) ([&](decltype((x)) y) { return (f)(begin(y), end(y), ## __VA_ARGS__); })(x)
typedef long long ll;
using namespace std;
template <class T> void setmin(T & a, T const & b) { if (b < a) a = b; }
const int inf = 1e9+7;
int main() {
    const int MAX = 30;
    int x, y, z, w; cin >> x >> y >> z >> w;
    ll ans = inf;
    repeat (c,MAX+1) {
        repeat (b,c) {
            repeat_from (a,1,b) {
                array<ll,MAX+1> dp; whole(fill, dp, inf);
                dp[0] = 0;
                repeat (i,MAX) {
                    if (i+a < MAX+1) setmin(dp[i+a], dp[i] + 1);
                    if (i+b < MAX+1) setmin(dp[i+b], dp[i] + 1);
                    if (i+c < MAX+1) setmin(dp[i+c], dp[i] + 1);
                }
                setmin(ans, dp[x] + dp[y] + dp[z] + dp[w]);
            }
        }
    }
    cout << ans << endl;
    return 0;
}
0