結果

問題 No.27 板の準備
ユーザー mudbdbmudbdb
提出日時 2015-07-17 23:58:00
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,172 bytes
コンパイル時間 287 ms
コンパイル使用メモリ 26,280 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-27 04:00:33
合計ジャッジ時間 1,179 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>
int min(int a, int b)
{
  if (a < b) {
    return a;
  } else {
    return b;
  }
}
int main()
{
  int V[4];
  int i;
  for (i=0; i<4; i++) scanf("%d", &(V[i]));

  int Vmax = 0;
  for (i=0; i<4; i++) if (Vmax < V[i]) Vmax = V[i];
  int *dp = (int*)malloc(sizeof(int)*(Vmax+1));
  int A;
  int B;
  int C;
  int total;
  int totalmin = Vmax*4+1;
  int j;
  for (A=1; A<=Vmax; A++) {
    for (B=1; B<=A; B++) {
      for (C=1; C<=B; C++) {
        total = 0;
        for (i=0; i<4; i++) {
          for (j=0; j<=Vmax; j++) dp[j] = Vmax+1;
          dp[0] = 0;
          for (j=0; j<=V[i]; j++) {
            if (j-A >= 0) {
              dp[j] = min(dp[j-A]+1, dp[j]);
            }
            if (j-B >= 0) {
              dp[j] = min(dp[j-B]+1, dp[j]);
            }
            if (j-C >= 0) {
              dp[j] = min(dp[j-C]+1, dp[j]);
            }
          }
          if (dp[V[i]] == Vmax+1) {
            total = Vmax*4+1;
            break;
          } else {
            total += dp[V[i]];
          }
        }
        if (total < totalmin) totalmin = total;
      }
    }
  }
  printf("%d\n", totalmin);
  return 0;
}
0