結果

問題 No.249 N言っちゃダメゲーム (2)
ユーザー koyumeishikoyumeishi
提出日時 2015-07-24 23:12:58
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 930 bytes
コンパイル時間 866 ms
コンパイル使用メモリ 78,440 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-16 10:26:11
合計ジャッジ時間 1,882 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
using namespace std;

int dfs(vector<vector<int>>& memo, vector<long long>& n, vector<long long>& k, int t, int x){
	if(t==1000) return 0;
	if(memo[t][x] != 1e9) return memo[t][x];

	bool win = false;
	if(n[t] <= k[t]) win = true;
	else if((n[t]-1) % (k[t]+1) != 0) win = true;

	int ret = dfs(memo, n,k, t+1, x) + (x==0?-1:+1);	//lose
	if(win){
		int next = dfs(memo, n,k, t+1, x^1) + (x==0?+1:-1);	//win
		if(x == 0){
			ret = max(ret, next);
		}else{
			ret = min(ret, next);
		}
	}

	return memo[t][x] = ret;
}

int main(){
	int x = 1000;
	vector<long long> n(x), k(x);
	vector<vector<int>> memo(x+1, vector<int>(2,1e9));
	for(int i=0; i<x; i++){
		cin >> n[i] >> k[i];
	}

	int ans = dfs(memo, n,k, 0,0)/2 + 500;
	cout << ans << endl;
	return 0;
}
0