結果

問題 No.7 プライムナンバーゲーム
ユーザー chocoruskchocorusk
提出日時 2018-06-24 04:31:09
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 755 bytes
コンパイル時間 657 ms
コンパイル使用メモリ 81,876 KB
実行使用メモリ 6,696 KB
最終ジャッジ日時 2024-04-09 04:30:46
合計ジャッジ時間 1,407 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,688 KB
testcase_01 AC 2 ms
6,696 KB
testcase_02 AC 4 ms
6,696 KB
testcase_03 AC 1 ms
6,696 KB
testcase_04 AC 1 ms
6,688 KB
testcase_05 AC 2 ms
6,692 KB
testcase_06 AC 2 ms
6,692 KB
testcase_07 AC 2 ms
6,692 KB
testcase_08 AC 2 ms
6,692 KB
testcase_09 AC 2 ms
6,692 KB
testcase_10 AC 1 ms
6,692 KB
testcase_11 AC 2 ms
6,692 KB
testcase_12 AC 3 ms
6,692 KB
testcase_13 AC 3 ms
6,692 KB
testcase_14 AC 3 ms
6,696 KB
testcase_15 AC 4 ms
6,688 KB
testcase_16 AC 3 ms
6,692 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:20:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   20 |         scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

using namespace std;
typedef long long int ll;

int main()
{
	int n;
	scanf("%d", &n);
	vector<int> p;
	p.push_back(2);
	for(int i=3; i<=n+100; i+=2){
		bool e=0;
		for(int j=3; j*j<=i; j+=2){
			if(i%j==0){
				e=1;
				break;
			}
		}
		if(e==0){
			p.push_back(i);
		}
	}
	bool dp[10001];
	dp[0]=0, dp[1]=0;
	int t=0;
	for(int i=2; i<=n; i++){
		if(p[t+1]<=i) t++;
		dp[i]=1;
		for(int j=0; j<=t; j++){
			if(dp[i-p[j]]==1){
				dp[i]=0;
				break;
			}
		}
	}
	if(dp[n]==0){
		printf("Win\n");
	}else{
		printf("Lose\n");
	}
	return 0;
}
0