結果

問題 No.27 板の準備
ユーザー ama_nukoama_nuko
提出日時 2018-06-14 02:08:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 1,162 bytes
コンパイル時間 823 ms
コンパイル使用メモリ 93,216 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-27 04:54:47
合計ジャッジ時間 1,764 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

signed main(){
    int v0, v1, v2, v3;
    cin >> v0 >> v1 >> v2 >> v3;

    int ans = INF;
    for(int a = 1; a <= 30; a++){
        for(int b = 1; b <= 30; b++){
            for(int c = 1; c <= 30; c++){
                vector<int> x = {a, b, c};
                vector<int> dp(31, INF);
                dp[0] = 0;

                rep(i, 3){
                    for(int j = 1; j <= 30; j++){
                        if(j < x[i] || dp[j-x[i]] == INF){
                            continue;
                        }
                        dp[j] = min(dp[j], dp[j-x[i]] + 1);
                    }
                }
                int tmp = dp[v0] + dp[v1] + dp[v2] + dp[v3];
                if(ans > tmp){
                    ans = tmp;
                }
            }
        }
    }
    cout << ans << endl;

    return 0;
}
0