結果

問題 No.27 板の準備
ユーザー ctyl_0ctyl_0
提出日時 2015-10-02 18:00:08
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 8 ms / 5,000 ms
コード長 1,845 bytes
コンパイル時間 881 ms
コンパイル使用メモリ 89,544 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-27 04:08:36
合計ジャッジ時間 1,675 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define inf 1e9
typedef long long ll;

using namespace std;


int inputValue(){
    int a;
    cin >> a;
    return a;
};

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

int min_plates(int l, int a, int b, int c){ // length, a < b < c
    
    vector<int> dp(l + 1, inf);
    dp[0] = 0;
    
    rep(i, l - a + 1){
        dp[i + a] = min(dp[i + a], dp[i] + 1);
    }
    rep(i, l - b + 1){
        dp[i + b] = min(dp[i + b], dp[i] + 1);
    }
    rep(i, l - c + 1){
        dp[i + c] = min(dp[i + c], dp[i] + 1);
    }
    
    return dp[l];
}

int main() {
    // source code
    
    vector<int> V(4);
    rep(i, 4){
        V[i] = inputValue(); // 1 - 30
    }
    
    // 1 <= A < B < C <= 30
    
    vector<vector<vector<int>>> ABC(30, vector<vector<int>>(30, vector<int>(30, inf)));
    
    rep(i, 30){
        rep(j, 30){
            rep(k, 30){
                int tmp = 0;
                rep(l, 4){
                    int mp = min_plates(V[l], i + 1, j + 1, k + 1);
                    if (mp == inf) {
                        tmp = inf;
                        break;
                    }
                    tmp += mp;
                }
                ABC[i][j][k] = tmp;
            }
        }
    }
    
    int ret = inf;
    
    rep(i, 30){
        rep(j, 30){
            rep(k, 30){
                ret = min(ret, ABC[i][j][k]);
            }
        }
    }
    
    output(ret, 0);
    
    return 0;
}
0