結果

問題 No.257 N言っちゃダメゲーム (3)
ユーザー yuma25689yuma25689
提出日時 2015-11-18 02:43:48
言語 Perl
(5.38.2)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,164 bytes
コンパイル時間 318 ms
コンパイル使用メモリ 5,212 KB
実行使用メモリ 37,128 KB
最終ジャッジ日時 2023-09-23 21:59:23
合計ジャッジ時間 6,787 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
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 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Unquoted string "true" may clash with future reserved word at Main.pl line 33.
Bareword found in conditional at Main.pl line 50.
Main.pl syntax OK

ソースコード

diff #

$rawInput=<STDIN>;
chomp($rawInput);
@input=split(/ /, $rawInput);

solve(int($input[0]),int($input[1]));

sub solve
{
	my ($countOfDead, $maxAdd) = @_;

	$current = 0;
	# countOfDead-1を取得した方が勝利と思われる
	# また、それを取得するには、countOfDead-1-maxAdd-1を取得できればよく、
	# そこから公式化すると、countOfDead-1-(maxAdd+1)*nを取得した方が勝利
	# 0より大きい中でcountOfDead-1-(maxAdd+1)*nの一番小さいものをプレイヤーが取得できる方を選べば勝てる
	$winNumber = $countOfDead-1;
	$minWinNumber = $winNumber % ($maxAdd+1);

	if( $minWinNumber!=0 && $minWinNumber <= $maxAdd )
	{
		# 先攻ならば勝利
		$current += $minWinNumber;
	}
	else
	{
	}

	# currentを出力
	print($current."\n");

	# あとは、ひたすらcountOfDead-1-(maxAdd+1)*nをキープ
	while(true)
	{
		$input=<STDIN>;
		chomp($input);
		$readNum=int($input);
		if( $countOfDead <= $readNum)
		{
			# 勝利で終了
			return;
		}
		# currentを更新
		$current = $readNum;
		$minWinNumber = ($winNumber-$current) % ($maxAdd+1);

		$current += $minWinNumber;
		print($current."\n");
	}
}
0