結果
問題 | No.27 板の準備 |
ユーザー | izuru_matsuura |
提出日時 | 2016-09-27 21:17:22 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 6 ms / 5,000 ms |
コード長 | 1,563 bytes |
コンパイル時間 | 1,673 ms |
コンパイル使用メモリ | 171,144 KB |
実行使用メモリ | 7,168 KB |
最終ジャッジ日時 | 2023-08-27 04:35:14 |
合計ジャッジ時間 | 2,571 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4 ms
7,140 KB |
testcase_01 | AC | 4 ms
6,964 KB |
testcase_02 | AC | 5 ms
7,168 KB |
testcase_03 | AC | 4 ms
6,972 KB |
testcase_04 | AC | 5 ms
7,024 KB |
testcase_05 | AC | 5 ms
7,012 KB |
testcase_06 | AC | 5 ms
7,024 KB |
testcase_07 | AC | 6 ms
6,964 KB |
testcase_08 | AC | 6 ms
7,008 KB |
testcase_09 | AC | 6 ms
6,952 KB |
testcase_10 | AC | 5 ms
7,020 KB |
testcase_11 | AC | 6 ms
7,012 KB |
testcase_12 | AC | 5 ms
6,952 KB |
testcase_13 | AC | 5 ms
7,012 KB |
testcase_14 | AC | 5 ms
7,000 KB |
testcase_15 | AC | 6 ms
6,980 KB |
testcase_16 | AC | 5 ms
6,952 KB |
testcase_17 | AC | 5 ms
6,960 KB |
ソースコード
#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; }