結果

問題 No.27 板の準備
ユーザー togatogatogatoga
提出日時 2015-04-20 00:00:15
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,986 bytes
コンパイル時間 706 ms
コンパイル使用メモリ 92,716 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-27 03:26:24
合計ジャッジ時間 1,683 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <algorithm>
#include <functional>
#include <limits.h>
#include <bitset>

#include <tuple>
#include <unordered_map>

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

const int INF = 1 << 29;
const double EPS = 1e-9;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
vector<int> V;
int dp[50];
int main() {
  for (int i = 0; i < 4; i++) {
    int x;
    cin >> x;
    V.push_back(x);
  }
  int res = INF;
  for (int A = 1; A <= 30; A++) {
    for (int B = A + 1; B <= 30; B++) {
      for (int C = B + 1; C <= 30; C++) {
      	fill(dp, dp + 50, INF);
        dp[A] = 1;
        dp[B] = 1;
        dp[C] = 1;
        // cout << A << " " << B << " " << C << endl;
        for (int k = 1; k <= 30; k++){
        	if (k - A >= 0 and dp[k - A] != INF){
        		dp[k] = min(dp[k], dp[k - A] + 1);
        	}
        	if (k - B >= 0 and dp[k - B] != INF){
        		dp[k] = min(dp[k], dp[k - B] + 1);
        	}
        	if (k - C >= 0 and dp[k - C] != INF){
        		dp[k] = min(dp[k], dp[k - C] + 1);
        	}
        }
        // cout << dp[V[0]] << " " << dp[V[1]] << " " << dp[V[2]] << " " << dp[V[3]] << endl;
        // for (int i = 1; i <= 30; i++){
        // 	cout << dp[i] << endl;
        // }
        // cout << endl;
        int tmp = 0;
        bool ok = true;
        for (int i = 0; i < V.size(); i++) {
          if (dp[V[i]] == INF) {
            ok = false;
          }
          tmp += dp[V[i]];
        }
        if (ok) {
          res = min(res, tmp);
        }
      }
    }
  }
  cout << res << endl;
  return 0;
}
0