結果

問題 No.27 板の準備
ユーザー imulanimulan
提出日時 2016-07-05 18:42:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,014 bytes
コンパイル時間 1,593 ms
コンパイル使用メモリ 165,032 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-27 04:30:31
合計ジャッジ時間 2,496 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

const int INF=12345;

int main()
{
    int v[4];
    rep(i,4) cin >>v[i];

    int ans=200;

    for(int a=1; a<=28; ++a)
    for(int b=a+1; b<=29; ++b)
    for(int c=b+1; c<=30; ++c)
    {
        int dp[31];
        fill(dp,dp+31,INF);
        dp[0]=0;
        rep(i,30)
        {
            if(i+a<=30) dp[i+a]=min(dp[i+a],dp[i]+1);
            if(i+b<=30) dp[i+b]=min(dp[i+b],dp[i]+1);
            if(i+c<=30) dp[i+c]=min(dp[i+c],dp[i]+1);
        }

        bool valid=true;
        rep(i,4) if(dp[v[i]]==INF) valid=false;

        if(valid)
        {
            int t=0;
            rep(i,4) t+=dp[v[i]];
            ans=min(ans,t);
        }
    }

    cout << ans << endl;
    return 0;
}
0