結果

問題 No.7 プライムナンバーゲーム
ユーザー naimonon77naimonon77
提出日時 2015-09-28 00:18:27
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,340 bytes
コンパイル時間 661 ms
コンパイル使用メモリ 66,712 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 03:50:57
合計ジャッジ時間 1,699 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,820 KB
testcase_01 AC 4 ms
6,948 KB
testcase_02 AC 4 ms
6,944 KB
testcase_03 AC 4 ms
6,944 KB
testcase_04 AC 3 ms
6,944 KB
testcase_05 AC 3 ms
6,944 KB
testcase_06 AC 3 ms
6,948 KB
testcase_07 AC 3 ms
6,944 KB
testcase_08 AC 3 ms
6,948 KB
testcase_09 AC 3 ms
6,948 KB
testcase_10 AC 4 ms
6,944 KB
testcase_11 AC 3 ms
6,948 KB
testcase_12 AC 3 ms
6,948 KB
testcase_13 AC 3 ms
6,944 KB
testcase_14 AC 3 ms
6,948 KB
testcase_15 AC 4 ms
6,944 KB
testcase_16 AC 4 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
using namespace std;


#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/* ここからが本編 */
/* */
/* 入力開始! */
/* 入力終了! */

int a;
int prime[10000] = {0};
bool win[10005] = {1,1,0,0,1,1,};
/*                 0 1 2 3 4 5                  */

int chikai(int key)
{
   int left = 0,right = a,mid;

   while(left < right) {
      mid = (left+right)/2;

      if(prime[mid] == key) return mid;

      else if(key < prime[mid]) right = mid;

      else left = mid + 1;
   }

   if(prime[left] > key) return left-1;
   else return left;
}

void judge(int n)
{
   int i,j,k,l;
   for(i=chikai(n);i>-1;i--) {
      if( win[ n - prime[i] ] == 0 ) {
         win[n] = 1; break;
      }
   }
}
int main(void)
{
   int i,j,k,l;
   int n,m;

   prime[0] = 2;

   a = 1;
   for(i=3;i<=10100;i+=2)
   {
      k=0;
      for(j=3;j*j<=i;j+=2)
      {
         if(i%j==0)
         {
            k=1;
            break;
         }
      }
      if(k==0) prime[a++] = i;
   }

   REP(i,3,10001) judge(i);
   
   cin >> n;

   if(win[n]) printf("Win\n");
   else printf("Lose\n");

   return 0;
}
0