結果

問題 No.8 N言っちゃダメゲーム
ユーザー たこしたこし
提出日時 2015-07-27 20:50:51
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,490 bytes
コンパイル時間 668 ms
コンパイル使用メモリ 89,396 KB
実行使用メモリ 15,668 KB
最終ジャッジ日時 2023-09-23 04:03:56
合計ジャッジ時間 7,277 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
11,480 KB
testcase_01 AC 3 ms
4,380 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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <queue>
#include <complex>

#define INF 100000007
#define INF_MAX 2147483647
#define LL_MAX 9223372036854775807
#define EPS 1e-10
#define PI acos(-1)
#define LL long long

using namespace std;

#define MAX_N 120001
#define MAX_K 120001

int N, K;

int memo[MAX_N][2]; //memo[i][j]: jにiの数が回ってきた時にjが勝てるか

int solve(int pos, int turn){

  if(memo[pos][turn] != 0){
    
    return memo[pos][turn];
  }  

  if(pos == N){
    return memo[pos][turn] = 1;
  }

  bool flag = false;
  int nextTurn = (turn + 1) % 2;

  for(int i = 1; i <= K; i++){
    
    int nextP = pos + i;
    
    if(nextP > N)
      break;
    
    if(solve(nextP, nextTurn) == -1){
      flag = true;
    }
    
  }

  if(flag){
    return memo[pos][turn] = 1;
  }
  
  else{
    return memo[pos][turn] = -1;
  }
  
}

int main(){

  int P;
  cin >> P;

  for(int i = 0; i < P; i++){
    
    memset(memo, 0, sizeof(memo));
    
    cin >> N >> K;
    
    if(solve(0, 0) == 1){
      cout << "Win" << endl;
    }
    else{
      cout << "Lose" << endl;
    }

  }

  return 0;

}
0