結果

問題 No.27 板の準備
ユーザー cormorancormoran
提出日時 2016-09-27 21:57:36
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 1,262 bytes
コンパイル時間 1,159 ms
コンパイル使用メモリ 146,400 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-27 04:36:20
合計ジャッジ時間 2,112 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }

const int INF = 200;

class Solver {
  public:
    bool solve() {
        vector<int> V(4); cin >> V;
        int ans = INF;
        repeat(a, 1, 30 + 1) repeat(b, 1, a + 1) repeat(c, 1, b + 1) {
            int sum = 0;
            for(int v : V) {
                vector<int> dp(v + 1, INF);
                dp[0] = 0;                
                rep(i, dp.size()) {
                    if(i + a < dp.size()) set_min(dp[i + a], dp[i] + 1);
                    if(i + b < dp.size()) set_min(dp[i + b], dp[i] + 1);
                    if(i + c < dp.size()) set_min(dp[i + c], dp[i] + 1);
                }
                sum += dp[v];
            }
            set_min(ans, sum);
        }
        assert(ans < INF);
        cout << ans << endl;
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}
0