結果

問題 No.1906 Twinkle Town
ユーザー 👑 emthrmemthrm
提出日時 2022-04-16 01:15:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,397 bytes
コンパイル時間 2,276 ms
コンパイル使用メモリ 212,184 KB
実行使用メモリ 91,548 KB
最終ジャッジ日時 2023-08-26 09:26:50
合計ジャッジ時間 6,789 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,876 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1};
constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1};
constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U>
inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U>
inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);
  }
} iosetup;

void solve() {
  int n; cin >> n;
  vector<int> a(n); REP(i, n) cin >> a[i];

  map<pair<int, vector<int>>, pair<int, int>> dp;
  auto f = [&](auto&& f, const int light, const vector<int>& a, bool taro) -> int {
    if (a.empty()) return __builtin_popcount(light);
    if (dp.count({light, a})) return dp[{light, a}].first;
    int score = (taro ? -INF : INF), choice = -1;
    const int n = a.size();
    REP(i, n) {
      if (i > 0 && a[i] == a[i - 1]) continue;
      vector<int> b = a;
      b.erase(b.begin() + i);
      if (taro) {
        if (chmax(score, f(f, light | ((1 << a[i]) - 1), b, !taro))) choice = a[i];
      } else {
        if (chmin(score, f(f, light & (~0 ^ ((1 << a[i]) - 1)), b, !taro))) choice = a[i];
      }
    }
    dp[{light, a}] = {score, choice};
    return score;
  };
  cout << f(f, 0, a, true) << '\n';

  // for (const auto [key, val] : dp) {
  //   const auto [light, a] = key;
  //   cout << bitset<10>(light) << ' ';
  //   REP(i, a.size()) cout << a[i] << ",:"[i + 1 == a.size()];
  //   cout << ' ' << val.first << ' ' << val.second << '\n';
  // }

  // for (int light = 0, taro = 1; !a.empty(); taro ^= 1) {
  //   const int choice = dp[{light, a}].second;
  //   cout << choice << " \n"[a.size() == 1];
  //   a.erase(lower_bound(ALL(a), choice));
  //   if (taro) {
  //     light |= (1 << choice) - 1;
  //   } else {
  //     light &= ~0 ^ ((1 << choice) - 1);
  //   }
  // }
}

int main() {
  int t; cin >> t;
  while (t--) solve();
  return 0;
}
0