結果
問題 | No.27 板の準備 |
ユーザー |
|
提出日時 | 2015-04-28 06:21:32 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 4 ms / 5,000 ms |
コード長 | 925 bytes |
コンパイル時間 | 1,746 ms |
コンパイル使用メモリ | 160,228 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-26 10:32:12 |
合計ジャッジ時間 | 2,652 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 |
ソースコード
#include "bits/stdc++.h" using namespace std; typedef long long Int; #define REP(i,n) for(int (i)=0;(i)<(int)(n);++(i)) int dfs(int n, int B[3], int d, int s) { if (n == 0) return d; if (n < 0) return 999999; int res = 999999; if (s <= 0) res = min(res, dfs(n - B[0], B, d + 1, 0)); if (s <= 1) res = min(res, dfs(n - B[1], B, d + 1, 1)); if (s <= 2) res = min(res, dfs(n - B[2], B, d + 1, 2)); return res; } int check(int a[4], int B[3]) { int res = 0; REP(i, 4) res += dfs(a[i], B, 0, 0); return res; } int a[4]; int main() { REP(i, 4) cin >> a[i]; sort(a, a + 4); int best = 999999; if (a[0] == a[1] || a[1] == a[2] || a[2] == a[3]) { best = 4; } else { for (int A = 1; A <= a[0]; A++) { for (int B = A + 1; B <= a[3]; B++) { for (int C = B + 1; C <= a[3]; C++) { int bs[] = { A, B, C }; int x = check(a, bs); if (best > x) best = x; } } } } cout << best << endl; }