結果
問題 | No.967 引き算をして門松列(その2) |
ユーザー | Mayimg |
提出日時 | 2020-01-14 04:44:25 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,901 bytes |
コンパイル時間 | 1,932 ms |
コンパイル使用メモリ | 204,180 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-06 08:07:49 |
合計ジャッジ時間 | 2,771 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
ソースコード
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; const long long INF = LLONG_MAX; signed main() { ios::sync_with_stdio(false); cin.tie(0); int t; cin >> t; auto is_valid = [] (long long h[]) -> bool { if (h[0] <= 0 || h[1] <= 0 || h[2] <= 0) return false; if (h[0] == h[1] || h[1] == h[2] || h[2] == h[0]) return false; if (h[1] > h[0] && h[1] > h[2]) return true; if (h[1] < h[0] && h[1] < h[2]) return true; return false; }; auto calc = [&] (long long h[], long long c[]) -> long long { if (h[2] > h[0]) swap(h[0], h[2]), swap(c[0], c[2]); long long res = INF; if (is_valid(h)) return 0; assert((h[0] >= h[1] && h[1] >= h[2]) || (h[0] == h[2])); // assert(h[0] >= h[1]); // assert(h[1] >= h[2]); // cerr << h[0] << " " << h[1] << " " << h[2] << endl; long long g[3] = {min(h[0], h[1] - 1), h[1], h[2]}; if (is_valid(g)) res = min(res, c[0] * (h[0] - g[0]) + c[1] * (h[1] - g[1]) + c[2] * (h[2] - g[2])); if (g[0] == g[2]) { g[0]--; if (is_valid(g)) res = min(res, c[0] * (h[0] - g[0]) + c[1] * (h[1] - g[1]) + c[2] * (h[2] - g[2])); g[0]++; g[2]--; if (is_valid(g)) res = min(res, c[0] * (h[0] - g[0]) + c[1] * (h[1] - g[1]) + c[2] * (h[2] - g[2])); } g[0] = h[0], g[1] = min(h[1], h[2] - 1), g[2] = h[2]; if (is_valid(g)) res = min(res, c[0] * (h[0] - g[0]) + c[1] * (h[1] - g[1]) + c[2] * (h[2] - g[2])); if (h[0] == h[2]) { g[0] = h[0]; g[1] = min(h[1], h[0] - 2); g[2] = h[2] - 1; if (is_valid(g)) res = min(res, c[0] * (h[0] - g[0]) + c[1] * (h[1] - g[1]) + c[2] * (h[2] - g[2])); g[0] = h[0] - 1; g[1] = min(h[1], h[2] - 2); g[2] = h[2]; if (is_valid(g)) res = min(res, c[0] * (h[0] - g[0]) + c[1] * (h[1] - g[1]) + c[2] * (h[2] - g[2])); g[0] = h[0] - 1; g[1] = h[1]; g[2] = h[2]; if (is_valid(g)) res = min(res, c[0] * (h[0] - g[0]) + c[1] * (h[1] - g[1]) + c[2] * (h[2] - g[2])); g[0] = h[0]; g[1] = h[1]; g[2] = h[2] - 1; if (is_valid(g)) res = min(res, c[0] * (h[0] - g[0]) + c[1] * (h[1] - g[1]) + c[2] * (h[2] - g[2])); g[0] = h[0] - 1; g[1] = h[1] - 2; g[2] = h[2]; if (is_valid(g)) res = min(res, c[0] * (h[0] - g[0]) + c[1] * (h[1] - g[1]) + c[2] * (h[2] - g[2])); g[0] = h[0]; g[1] = h[1] - 2; g[2] = h[2] - 1; if (is_valid(g)) res = min(res, c[0] * (h[0] - g[0]) + c[1] * (h[1] - g[1]) + c[2] * (h[2] - g[2])); } return res; }; auto solve = [&] () -> long long { long long h[3]; cin >> h[0] >> h[1] >> h[2]; // cerr << h[0] << " " << h[1] << " " << h[2] << endl; long long c[3]; cin >> c[0] >> c[1] >> c[2]; // c[0] = c[1] = c[2] = 1; long long res = calc(h, c); return res == INF ? -1 : res; }; while (t--) cout << solve () << '\n'; return 0; }