結果

問題 No.257 N言っちゃダメゲーム (3)
ユーザー yuma25689yuma25689
提出日時 2015-11-18 02:48:26
言語 Perl
(5.38.2)
結果
AC  
実行時間 51 ms / 2,000 ms
コード長 1,173 bytes
コンパイル時間 159 ms
コンパイル使用メモリ 5,216 KB
実行使用メモリ 24,396 KB
平均クエリ数 3.70
最終ジャッジ日時 2023-09-23 21:59:29
合計ジャッジ時間 3,357 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
23,400 KB
testcase_01 AC 45 ms
23,964 KB
testcase_02 AC 44 ms
24,000 KB
testcase_03 AC 45 ms
23,388 KB
testcase_04 AC 45 ms
23,388 KB
testcase_05 AC 45 ms
23,400 KB
testcase_06 AC 44 ms
23,352 KB
testcase_07 AC 45 ms
23,364 KB
testcase_08 AC 45 ms
24,312 KB
testcase_09 AC 45 ms
23,400 KB
testcase_10 AC 45 ms
23,484 KB
testcase_11 AC 45 ms
23,988 KB
testcase_12 AC 46 ms
24,036 KB
testcase_13 AC 45 ms
23,352 KB
testcase_14 AC 45 ms
23,976 KB
testcase_15 AC 44 ms
23,616 KB
testcase_16 AC 43 ms
24,300 KB
testcase_17 AC 44 ms
24,024 KB
testcase_18 AC 45 ms
24,396 KB
testcase_19 AC 44 ms
23,352 KB
testcase_20 AC 43 ms
23,808 KB
testcase_21 AC 43 ms
23,808 KB
testcase_22 AC 44 ms
24,288 KB
testcase_23 AC 44 ms
24,012 KB
testcase_24 AC 44 ms
23,808 KB
testcase_25 AC 43 ms
23,352 KB
testcase_26 AC 45 ms
23,628 KB
testcase_27 AC 44 ms
23,652 KB
testcase_28 AC 44 ms
24,048 KB
testcase_29 AC 43 ms
23,400 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Unquoted string "true" may clash with future reserved word at Main.pl line 35.
Bareword found in conditional at Main.pl line 52.
Main.pl syntax OK

ソースコード

diff #

$| = 1;

$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