結果

問題 No.3586 Divide and Be Conquered
コンテスト
ユーザー risujiroh
提出日時 2026-07-10 22:28:22
言語 C++23
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 3,921 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,542 ms
コンパイル使用メモリ 362,604 KB
実行使用メモリ 6,656 KB
最終ジャッジ日時 2026-07-10 22:28:33
合計ジャッジ時間 4,801 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 1 WA * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#if __INCLUDE_LEVEL__ == 0

#include __BASE_FILE__

map<vector<int>, bool> cache;
bool Wins(vector<int> a) {
  ranges::sort(a, greater{});
  while (Len(a) && a.back() == 1)
    a.pop_back();
  if (auto it = cache.find(a); it != cache.end())
    return it->second;
  for (int i : Rep(0, Len(a))) {
    bool all_x = true;
    for (int x : Rep(1, a[i])) {
      int y = a[i] - x;
      bool exists_z = false;
      for (int z : {x, y}) {
        auto b = a;
        b[i] = z;
        if (!Wins(b)) {
          exists_z = true;
          break;
        }
      }
      if (!exists_z) {
        all_x = false;
        break;
      }
    }
    if (all_x)
      return cache[a] = true;
  }
  return cache[a] = false;
}

bool Loses(vector<int64_t> a) {
  ranges::sort(a, greater{});
  while (Len(a) && a.back() == 1)
    a.pop_back();
  while (Len(a) >= 2 && a.end()[-1] == a.end()[-2])
    a.resize(Len(a) - 2);
  return a.empty() || a.back() >= 4;
}

void Solve() {
  int n;
  IN(n);
  vector<int64_t> a(n);
  IN(a);
  OUT(Loses(a) ? "Second" : "First");
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int t;
  IN(t);
  while (t--) {
    Solve();
  }
}

#elif __INCLUDE_LEVEL__ == 1

#include <bits/stdc++.h>

template <class F>
class Fix {
 public:
  explicit Fix(F f) : f_(std::move(f)) {}

  template <class... Ts>
  decltype(auto) operator()(Ts&&... xs) {
    return f_(std::ref(*this), std::forward<Ts>(xs)...);
  }

  template <class... Ts>
  decltype(auto) operator()(Ts&&... xs) const {
    return f_(std::ref(*this), std::forward<Ts>(xs)...);
  }

 private:
  F f_;
};

template <class T>
concept MyRange =
    std::ranges::range<T> &&
    !std::convertible_to<T, std::string_view> &&
    !std::convertible_to<T, std::filesystem::path>;

template <class T>
concept MyTuple = std::__is_tuple_like<T>::value && !MyRange<T>;

namespace std {

istream& operator>>(istream& is, MyRange auto&& r) {
  for (auto&& e : r) {
    is >> e;
  }
  return is;
}

istream& operator>>(istream& is, MyTuple auto&& t) {
  apply([&](auto&... xs) { (is >> ... >> xs); }, t);
  return is;
}

ostream& operator<<(ostream& os, MyRange auto&& r) {
  auto sep = "";
  for (auto&& e : r) {
    os << exchange(sep, " ") << forward<decltype(e)>(e);
  }
  return os;
}

ostream& operator<<(ostream& os, MyTuple auto&& t) {
  auto sep = "";
  apply([&](auto&... xs) { ((os << exchange(sep, " ") << xs), ...); }, t);
  return os;
}

}  // namespace std

template <class T>
class OneBased {
 public:
  explicit OneBased(T&& x) : ref_(std::forward<T>(x)) {}

  template <class... Ts>
  requires(sizeof...(Ts) > 1)
      OneBased(Ts&&... xs) : ref_(std::forward_as_tuple(std::forward<Ts>(xs)...)) {}

  friend std::istream& operator>>(std::istream& is, OneBased x) {
    if constexpr (MyRange<T>) {
      for (auto&& e : x.ref_) {
        is >> ::OneBased(e);
      }
    } else if constexpr (MyTuple<T>) {
      std::apply([&](auto&... xs) { (is >> ... >> ::OneBased(xs)); }, x.ref_);
    } else {
      is >> x.ref_;
      --x.ref_;
    }
    return is;
  }

  friend std::ostream& operator<<(std::ostream& os, OneBased x) {
    if constexpr (MyRange<T>) {
      auto f = [](auto&& e) { return ::OneBased(std::forward<decltype(e)>(e)); };
      os << (x.ref_ | std::views::transform(f));
    } else if constexpr (MyTuple<T>) {
      std::apply([&](auto&... xs) { os << std::tuple(::OneBased(xs)...); }, x.ref_);
    } else {
      os << ++x.ref_;
      --x.ref_;
    }
    return os;
  }

 private:
  T ref_;
};

template <class T>
OneBased(T&&) -> OneBased<T>;

template <class... Ts>
OneBased(Ts&&...) -> OneBased<std::tuple<Ts...>>;

using namespace std;

#define Rep(...) [](int l, int r) { return views::iota(min(l, r), r); }(__VA_ARGS__)
#define Len(r) int(size(r))
#define IN(...) (cin >> forward_as_tuple(__VA_ARGS__))
#define OUT(...) (cout << forward_as_tuple(__VA_ARGS__) << '\n')

#endif  // __INCLUDE_LEVEL__ == 1
0