結果

問題 No.27 板の準備
ユーザー SSRSSSRS
提出日時 2020-11-09 00:07:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 5,000 ms
コード長 721 bytes
コンパイル時間 1,448 ms
コンパイル使用メモリ 167,832 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-22 15:48:03
合計ジャッジ時間 2,388 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const int INF = 1000;
int main(){
  vector<int> V(4);
  for (int i = 0; i < 4; i++){
    cin >> V[i];
  }
  int ans = INF;
  vector<int> L(3);
  for (L[0] = 1; L[0] <= 30; L[0]++){
    for (L[1] = 1; L[1] <= 30; L[1]++){
      for (L[2] = 1; L[2] <= 30; L[2]++){
        vector<int> dp(31, INF);
        dp[0] = 0;
        for (int i = 1; i <= 30; i++){
          for (int j = 0; j < 3; j++){
            if (i >= L[j]){
              dp[i] = min(dp[i], dp[i - L[j]] + 1);
            }
          }
        }
        int sum = 0;
        for (int i = 0; i < 4; i++){
          sum += dp[V[i]];
        }
        ans = min(ans, sum);
      }
    }
  }
  cout << ans << endl;
}
0