結果

問題 No.8 N言っちゃダメゲーム
ユーザー rsk0315rsk0315
提出日時 2020-03-30 13:44:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,166 bytes
コンパイル時間 463 ms
コンパイル使用メモリ 50,064 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-09-02 15:29:35
合計ジャッジ時間 7,144 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

/**
 * @brief ラムダ式の再帰
 * @author えびちゃん
 */

#ifndef H_make_fix_point
#define H_make_fix_point

#include <utility>

template <typename Fn>
class fix_point: Fn {
public:
  explicit constexpr fix_point(Fn&& f) noexcept: Fn(std::forward<Fn>(f)) {}

  template <typename... Args>
  constexpr decltype(auto) operator ()(Args&&... args) const {
    return Fn::operator ()(*this, std::forward<Args>(args)...);
  }
};

template <typename Fn>
static inline constexpr decltype(auto) make_fix_point(Fn&& f) noexcept {
  return fix_point<Fn>{std::forward<Fn>(f)};
}

#endif  /* !defined(H_make_fix_point) */

#include <cstdio>
#include <vector>

int main() {
  int p;
  scanf("%d", &p);

  while (p--) {
    int n, k;
    scanf("%d %d", &n, &k);

    std::vector<int> memo(n, 0);
    memo[0] = -1;
    int res = make_fix_point([&](auto dfs, int m) -> int {
      auto& res = memo[m];
      if (res != 0) return res;
      res = -1;
      for (int i = 1; i <= k; ++i) {
        if (m-i < 0) break;
        if (dfs(m-i) == -1) {
          res = 1;
          break;
        }
      }
      return res;
    })(n-1);
    puts((res == 1)? "Win": "Lose");
  }
}
0