結果

問題 No.27 板の準備
ユーザー codershifthcodershifth
提出日時 2015-07-21 00:23:22
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,340 bytes
コンパイル時間 1,293 ms
コンパイル使用メモリ 149,716 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-08-27 04:01:00
合計ジャッジ時間 2,229 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int (i)=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define RANGE(vec) (vec).begin(),(vec).end()

using namespace std;


class PreparePlate {
public:
    void solve(void) {
            vector<int> v(4);
            REP(i, 4)
                cin>>v[i];
            sort(RANGE(v));

            const ll inf = (1<<30);
            // 30*29*28 = 24360 なんで
            // 全探索でいけそう
            ll minN = inf;
            for (int a = 1; a <= 30; ++a)
            for (int b = a+1; b <= 30; ++b)
            for (int c = b+1; c <= 30; ++c)
            {
                vector<ll> dp(30+1, inf);
                dp[0] = 0;
                for (int i = 1; i <= 30; ++i)
                {
                    int x[] = {a,b,c};
                    REP(j, 3) if (i >= x[j])
                        dp[i] = min(dp[i], dp[i-x[j]]+1);
                }
                ll n = 0;
                REP(i,4)
                    n = min(n+dp[v[i]], inf);
                minN = min(n, minN);
            }
            cout<<minN<<endl;
    }
};

#if 1
int main(int argc, char *argv[])
{
        ios::sync_with_stdio(false);
        auto obj = new PreparePlate();
        obj->solve();
        delete obj;
        return 0;
}
#endif
0