結果
| 問題 |
No.27 板の準備
|
| コンテスト | |
| ユーザー |
togatoga
|
| 提出日時 | 2015-04-20 00:00:15 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 1,986 bytes |
| コンパイル時間 | 847 ms |
| コンパイル使用メモリ | 91,300 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-26 10:31:31 |
| 合計ジャッジ時間 | 1,800 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 |
ソースコード
#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;
}
togatoga