結果

問題 No.27 板の準備
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2019-08-31 23:24:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,304 bytes
コンパイル時間 1,566 ms
コンパイル使用メモリ 165,844 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-17 04:23:08
合計ジャッジ時間 2,784 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 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 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i,n,m) for(int i = (int)(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = MOD - 1;
const ll LLINF = 4e18;

int main() {
    int v[4],ans = INF;
    REP(i, 4) cin >> v[i];
    // 1<=a<b<c<=30
    FOR(a,1, 29) {
        FOR(b,a+1, 30) {
            FOR(c, b+1, 31) {
                //dp[i]:a,b,cをつかってiを作るときの最小数
                vector<int> dp(31, INF);
                dp[0] = 0;
                REP(i, 31) {
                    if (i >= a) dp[i] = min(dp[i], dp[i - a] + 1);
                    if (i >= b) dp[i] = min(dp[i], dp[i - b] + 1);
                    if (i >= c) dp[i] = min(dp[i], dp[i - c] + 1);
                }
                int sum = 0;
                REP(i, 4) {
                    if (dp[v[i]] == INF) {
                        sum = INF;
                        break;
                    }
                    sum += dp[v[i]];
                }
                ans = min(ans, sum);
            }
        }
    }
    cout << ans << endl;
    getchar(); getchar();
}
0