結果

問題 No.968 引き算をして門松列(その3)
ユーザー MayimgMayimg
提出日時 2020-01-14 07:08:56
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 1,586 bytes
コンパイル時間 2,074 ms
コンパイル使用メモリ 198,352 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-25 19:04:37
合計ジャッジ時間 2,979 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 17 ms
4,376 KB
testcase_04 AC 17 ms
4,380 KB
testcase_05 AC 18 ms
4,380 KB
testcase_06 AC 17 ms
4,376 KB
testcase_07 AC 19 ms
4,376 KB
testcase_08 AC 29 ms
4,376 KB
testcase_09 AC 38 ms
4,376 KB
testcase_10 AC 38 ms
4,376 KB
testcase_11 AC 45 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 g[], long long h[]) -> bool {
    if (h[0] < g[0] || h[1] < g[1] || h[2] < g[2]) return false;
    if (g[0] <= 0 || g[1] <= 0 || g[2] <= 0) return false;
    if (g[0] == g[1] || g[1] == g[2] || g[2] == g[0]) return false;
    if (g[1] > g[0] && g[1] > g[2]) return true;
    if (g[1] < g[0] && g[1] < g[2]) return true;
    return false;
  };
  auto solve = [&] () -> long long {
    long long h[3];
    cin >> h[0] >> h[1] >> h[2];
    long long c[3];
    cin >> c[2] >> c[0] >> c[1];
    long long t[] = {h[0], h[0] + 1, h[0] + 2, h[1], h[1] + 1, h[1] + 2, h[2], h[2] + 1, h[2] + 2};
    long long g[3];
    long long res = INF;
    for (int i = 0; i < 9; i++) for (int j = 0; j < 9; j++) for (int k = 0; k < 9; k++) {
      g[0] = t[i];
      g[1] = t[j];
      g[2] = t[k];
      if (g[0] < h[0] || g[1] < h[1] || g[2] < h[2]) continue;
      long long opr = g[0] + g[1] + g[2] - h[0] - h[1] - h[2];
      long long gg[] = {g[0] - opr, g[1] - opr, g[2] - opr};
      if (is_valid(gg, h)) {
        res = min(res, c[0] * (g[0] - h[0]) + c[1] * (g[1] - h[1]) + c[2] * (g[2] - h[2]));
        // cerr << g[0] << " " << g[1] << " " << g[2] << endl;
        // cerr << opr << endl;
        // cerr << gg[0] << " " << gg[1] << " " << gg[2] << " " << res << endl;
      }
    }
    return (res == INF ? -1 : res);
  };
  while (t--) cout << solve() << '\n';
  return 0;
}
0