結果

問題 No.7 プライムナンバーゲーム
ユーザー 綾地寧々綾地寧々
提出日時 2015-06-11 08:19:43
言語 PHP
(8.3.4)
結果
WA  
実行時間 -
コード長 1,184 bytes
コンパイル時間 956 ms
コンパイル使用メモリ 18,660 KB
実行使用メモリ 19,116 KB
最終ジャッジ日時 2023-09-20 20:45:03
合計ジャッジ時間 6,668 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
18,912 KB
testcase_01 AC 15 ms
18,948 KB
testcase_02 AC 656 ms
18,760 KB
testcase_03 AC 56 ms
18,892 KB
testcase_04 AC 26 ms
18,888 KB
testcase_05 WA -
testcase_06 AC 200 ms
18,888 KB
testcase_07 AC 140 ms
18,884 KB
testcase_08 AC 71 ms
18,856 KB
testcase_09 WA -
testcase_10 AC 15 ms
18,772 KB
testcase_11 AC 142 ms
18,768 KB
testcase_12 AC 472 ms
18,868 KB
testcase_13 AC 504 ms
18,888 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 574 ms
18,956 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php
define("NOT_REACHED", 0);
define("REACHED", 3);
define("REACH_EVEN", 1);
define("REACH_ODD", 2);
$starttime = microtime(TRUE);
$n = trim(fgets(STDIN));
$prime_array = array();
for ( $i=2; $i<=$n; $i++ ) {
	if ( is_prime($i) ) {
		$prime_array[] = $i;
	}
}

$result = array_fill(0, $n+1, NOT_REACHED);
$result[$n] = REACH_EVEN;
for ( $i=$n; $i>=0; $i-- ) {
	if ( $result[$i] === NOT_REACHED ) {
		continue;
	}
	for ( $j=0; $j<count($prime_array); $j++ ) {
		if ( $i-$prime_array[$j] < 0 ) {
			continue;
		}
		switch ( $result[$i] ) {
			case REACH_EVEN:
				$result[$i-$prime_array[$j]] = $result[$i-$prime_array[$j]] | REACH_ODD;
				break;
			
			case REACH_ODD:
				$result[$i-$prime_array[$j]] = $result[$i-$prime_array[$j]] | REACH_EVEN;
				break;
			
			case REACHED:
			default:
			break;
		}
	}
}

if ( (($result[0] | $result[1]) == REACH_EVEN) || (($result[0] | $result[1]) == REACHED) ) {
	echo 'Win'.PHP_EOL;
}
else {
	echo 'Lose'.PHP_EOL;
}

function is_prime($number) {
	for ( $i=2; $i<=sqrt($number); $i++ ) {
		if ( !($number % $i) ) {
			return FALSE;
		}
	}
	return TRUE;
}

$exectime = microtime(TRUE) - $starttime;
fprintf(STDERR,"%f seconds\n", $exectime);
0