結果
| 問題 |
No.967 引き算をして門松列(その2)
|
| コンテスト | |
| ユーザー |
drken1215
|
| 提出日時 | 2020-01-13 21:29:28 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 63 ms / 2,000 ms |
| コード長 | 1,279 bytes |
| コンパイル時間 | 747 ms |
| コンパイル使用メモリ | 82,424 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-12-22 23:03:41 |
| 合計ジャッジ時間 | 1,769 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 10 |
ソースコード
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
const long long INF = 1LL<<60;
// (a, b, c) が門松列かどうか
bool isok(long long a, long long b, long long c) {
if (a < 1 || b < 1 || c < 1) return false;
if (a == b) return false;
if (b == c) return false;
if (c == a) return false;
if (a < b && b < c) return false;
if (a > b && b > c) return false;
return true;
}
long long A, B, C, X, Y, Z;
long long solve() {
long long res = INF;
vector<long long> alt;
for (int it = 0; it <= 2; ++it) {
alt.push_back(A - it);
alt.push_back(B - it);
alt.push_back(C - it);
}
for (auto a : alt) {
for (auto b : alt) {
for (auto c : alt) {
if (A < a) continue;
if (B < b) continue;
if (C < c) continue;
if (isok(a, b, c)) {
res = min(res, (A - a) * X + (B - b) * Y + (C - c) * Z);
}
}
}
}
if (res < INF) return res;
else return -1;
}
int main() {
int T; cin >> T;
for (int _ = 0; _ < T; ++_) {
cin >> A >> B >> C >> X >> Y >> Z;
cout << solve() << endl;
}
}
drken1215