結果
問題 | No.7 プライムナンバーゲーム |
ユーザー |
|
提出日時 | 2015-06-11 12:27:28 |
言語 | PHP (7.2.24) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,036 bytes |
コンパイル時間 | 1,122 ms |
コンパイル使用メモリ | 18,488 KB |
実行使用メモリ | 18,968 KB |
最終ジャッジ日時 | 2023-09-20 20:46:53 |
合計ジャッジ時間 | 5,310 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 15 ms
18,828 KB |
testcase_01 | WA | - |
testcase_02 | AC | 598 ms
18,824 KB |
testcase_03 | AC | 53 ms
18,868 KB |
testcase_04 | AC | 26 ms
18,944 KB |
testcase_05 | WA | - |
testcase_06 | AC | 184 ms
18,892 KB |
testcase_07 | AC | 128 ms
18,628 KB |
testcase_08 | AC | 65 ms
18,912 KB |
testcase_09 | WA | - |
testcase_10 | AC | 16 ms
18,964 KB |
testcase_11 | AC | 130 ms
18,952 KB |
testcase_12 | AC | 427 ms
18,828 KB |
testcase_13 | AC | 453 ms
18,776 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | AC | 515 ms
18,828 KB |
コンパイルメッセージ
No syntax errors detected in Main.php
ソースコード
<?php define("NOT_REACHED", 0); define("REACHED", 3); define("REACH_EVEN", 1); define("REACH_ODD", 2); $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 ) { break; } switch ( $result[$i] ) { case REACH_EVEN: $result[$i-$prime_array[$j]] |= REACH_ODD; break; case REACH_ODD: $result[$i-$prime_array[$j]] |= REACH_EVEN; break; case REACHED: $result[$i-$prime_array[$j]] |= REACHED; break; default: break; } } } if ( ($result[0] == REACH_ODD) || ($result[1] == REACH_ODD) ) { echo 'Lose'.PHP_EOL; } else { echo 'Win'.PHP_EOL; } function is_prime($number) { for ( $i=2; $i<=sqrt($number); $i++ ) { if ( !($number % $i) ) { return FALSE; } } return TRUE; }