結果
問題 | No.7 プライムナンバーゲーム |
ユーザー | Onju |
提出日時 | 2015-02-08 22:38:44 |
言語 | C++11 (gcc 11.4.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 911 bytes |
コンパイル時間 | 387 ms |
コンパイル使用メモリ | 59,396 KB |
実行使用メモリ | 4,508 KB |
最終ジャッジ日時 | 2023-09-05 11:15:15 |
合計ジャッジ時間 | 3,478 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
コンパイルメッセージ
main.cpp: In function ‘bool* calcPrime()’: main.cpp:16:7: warning: address of local variable ‘list’ returned [-Wreturn-local-addr] bool list[N_MAX + 1]; ^~~~
ソースコード
#include <iostream> #include <cmath> #include <cstring> #define N_MAX 10000 using namespace std; enum eANS { ANS_NONE, ANS_WIN, ANS_LOSE }; bool* calcPrime() { bool list[N_MAX + 1]; int sqrtnmax = sqrt(N_MAX); for (int i = 2; i <= N_MAX; ++i) list[i] = true; for (int i = 2; i <= sqrtnmax; ++i) { if (list[i]) { int jmax = N_MAX / i; for (int j = i; j <= jmax; ++j) list[i*j] = false; } } return list; } int main() { bool* prime = calcPrime(); eANS ans[N_MAX + 1]; int N; cin >> N; ans[0] = ans[1] = ANS_WIN; for (int i = 2; i <= N_MAX; ++i) ans[i] = ANS_NONE; for (int i = 2; i <= N; ++i) { for (int j = 2; j < i; ++j) { if (prime[j] && (ans[i - j] == ANS_LOSE)) { ans[i] = ANS_WIN; break; } } if (ans[i] != ANS_WIN) ans[i] = ANS_LOSE; } if (ans[N] == ANS_WIN) cout << "Win" << endl; else cout << "Lose" << endl; return 0; }