結果
| 問題 |
No.27 板の準備
|
| コンテスト | |
| ユーザー |
izuru_matsuura
|
| 提出日時 | 2016-09-27 21:17:22 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 7 ms / 5,000 ms |
| コード長 | 1,563 bytes |
| コンパイル時間 | 1,743 ms |
| コンパイル使用メモリ | 172,060 KB |
| 実行使用メモリ | 7,168 KB |
| 最終ジャッジ日時 | 2024-12-26 12:46:59 |
| 合計ジャッジ時間 | 2,549 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
namespace {
typedef double real;
typedef long long ll;
template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
if (vs.empty()) return os << "[]";
auto i = vs.begin();
os << "[" << *i;
for (++i; i != vs.end(); ++i) os << " " << *i;
return os << "]";
}
template<class T> istream& operator>>(istream& is, vector<T>& vs) {
for (auto it = vs.begin(); it != vs.end(); it++) is >> *it;
return is;
}
const int INF = 1<<28;
vector<int> xs;
void input() {
xs.resize(4); cin >> xs;
}
int cache[31][31][31][31];
int f(int v, int a, int b, int c) {
if (v < 0) return INF;
if (v == 0) return 0;
int& x = cache[v][a][b][c];
if (x >= 0) return x;
return x = min(f(v - c, a, b, c) + 1, min(f(v - a, a, b, c) + 1, f(v - b, a, b, c) + 1));
}
int calc(int a, int b, int c) {
int ans = 0;
for (int i = 0; i < 4; i++) {
ans += f(xs[i], a, b, c);
}
return ans;
}
void solve() {
int ans = INF;
sort(xs.begin(), xs.end());
memset(cache, -1, sizeof(cache));
for (int a = 1; a <= 30; a++) {
for (int b = a + 1; b <= 30; b++) {
for (int c = b + 1; c <= 30; c++) {
ans = min(ans, calc(a, b, c));
}
}
}
cout << ans << endl;
}
}
int main() {
input(); solve();
return 0;
}
izuru_matsuura