結果

問題 No.2110 012 Matching
ユーザー shoshoshomshoshoshom
提出日時 2022-10-28 22:50:37
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 101 ms / 2,000 ms
コード長 1,358 bytes
コンパイル時間 2,819 ms
コンパイル使用メモリ 200,204 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-20 06:00:50
合計ジャッジ時間 4,998 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 27 ms
4,380 KB
testcase_02 AC 67 ms
4,384 KB
testcase_03 AC 45 ms
4,384 KB
testcase_04 AC 88 ms
4,384 KB
testcase_05 AC 62 ms
4,380 KB
testcase_06 AC 60 ms
4,384 KB
testcase_07 AC 99 ms
4,384 KB
testcase_08 AC 5 ms
4,384 KB
testcase_09 AC 16 ms
4,380 KB
testcase_10 AC 101 ms
4,380 KB
testcase_11 AC 2 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bits/stdc++.h>
#ifdef SHO_LOCAL
#include "debug.h"
#else
#define debug(...)                                                             \
  {}
#endif
using namespace std;

void solution() {
  long long A, B, C;
  cin >> A >> B >> C;
  long long a = A, b = B, c = C;
  long long ans = 0;

  auto Reset = [&]() {
    ans = 0;
    a = A, b = B, c = C;
  };

  auto cc = [&]() {
    ans += c / 2;
    c = c % 2;
  };
  auto ac = [&]() {
    long long t = min(a, c);
    ans += t * 2;
    a = max(0LL, a - t);
    c = max(0LL, c - t);
  };
  auto ab = [&]() {
    long long t = min(a, b);
    ans += t;
    a = max(0LL, a - t);
    b = max(0LL, b - t);
  };
  auto bb = [&]() {
    ans += b / 2 * 2;
    b = b % 2;
  };

  long long res = 0;
  vector<int> p(4);
  iota(p.begin(), p.end(), 0);
  do {
    Reset();
    for (int i = 0; i < 4; i++) {
      int j = p[i];
      if (j == 0)
        ab();
      else if (j == 1)
        ac();
      else if (j == 2)
        bb();
      else
        cc();
    }
    res = max(res, ans);
  } while (next_permutation(p.begin(), p.end()));
  cout << res << '\n';
}

int main() {
  iostream::sync_with_stdio(0), cin.tie(0), cout.tie(0);

  int TT;
  cin >> TT;
  for (int tc = 1; tc <= TT; tc++) {
    // cout << "Case #" << tc << ": " << solution() << '\n';
    solution();
  }

  return 0;
}
0