結果
| 問題 |
No.966 引き算をして門松列(その1)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-01-13 20:35:57 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 563 ms / 2,000 ms |
| コード長 | 1,026 bytes |
| コンパイル時間 | 1,877 ms |
| コンパイル使用メモリ | 169,680 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-21 16:22:33 |
| 合計ジャッジ時間 | 3,658 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 5 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()
bool is_kadomatu(ll x, ll y, ll z) {
return x != y and x != z and y != z and ((x < y and y > z) or (x > y and y < z));
}
ll solve(ll a, ll b, ll c, ll p, ll q, ll r) {
vector<ll> S;
rep(i, 3) {
for (int j = -2; j <= 2; j++) {
if (a + j >= 1) S.push_back(a + j);
if (b + j >= 1) S.push_back(b + j);
if (c + j >= 1) S.push_back(c + j);
}
}
ll res = LLONG_MAX;
for (ll x : S) if (a >= x) {
for (ll y : S) if (b >= y) {
for (ll z : S) if (c >= z) {
if (is_kadomatu(x, y, z)) {
res = min(res, (a-x)*p + (b-y)*q + (c-z)*r);
}
}
}
}
return res;
}
int main() {
int T; cin >> T;
while (T--) {
ll a, b, c; cin >> a >> b >> c;
ll ans = solve(a, b, c, 1, 1, 1);
if (ans == LLONG_MAX) ans = -1;
cout << ans << '\n';
}
}