結果

問題 No.7 プライムナンバーゲーム
ユーザー ShopetanShopetan
提出日時 2017-07-21 18:02:44
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,828 bytes
コンパイル時間 1,311 ms
コンパイル使用メモリ 160,588 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 04:21:42
合計ジャッジ時間 2,115 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

# include <bits/stdc++.h>

# define FOR(i,a,b) for (int i=(a);i<(b);i++)
# define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
# define REP(i, n) for (int i = 0; i < (int)(n); i++)
# define RREP(i,n) for (int i=(n)-1;i>=0;i--)

# define int(x) int x; scanf("%d",&x);
# define vint(v,n) vector<int> v(n); REP(i,n) scanf("%d", &v[i]);
# define string(x) string x; cin >> x;

using namespace std;

namespace utils{
  template <typename T> void print(vector<vector<T>> mat) {
    REP (i, mat.size()) {
      REP (j, mat[0].size()) cout << mat[i][j] << ' ';
      cout << endl;
    }
  }

  template <typename T> void print(vector<T> v) {
    REP (i, v.size())
      if (i >= v.size()-1)
	cout << v[i];
      else
	cout << v[i] << ' ';
    
    cout << endl;
  }

  template <typename T> pair<T, T> shape(vector<vector<T>> mat) {
    int d1, d2;

    d1 = mat.size();
    if (d1 > 0) d2 = mat[0].size();
    else int d2 = 0;
    cout << "(" << d1 << ", " << d2 << ")" << endl;
    return make_pair(0, 0);
  }

  template <typename T> vector<vector<T>> empty(int n, int m) {
    vector<vector<T>> mat(n, vector<T>(m));
    return mat;
  }
}

bool isprime[10010];

int getPrime(int N, int res[]){int i,a,b,s=1,f[4780],S=1;const int r=23000;bool B[r],*p=B;N/=2;res[0]=2;b=min(r,N);FOR(i,1,b)p[i]=1;FOR(i,1,b)if(p[i]){res[s++]=2*i+1;f[S]=2*i*(i+1);if(f[S]<N){for(;f[S]<r;f[S]+=res[S])p[f[S]]=0;S++;}}for(a=r;a<N;a+=r){b=min(a+r,N);p-=r;FOR(i,a,b)p[i]=1;FOR(i,1,S)for(;f[i]<b;f[i]+=res[i])p[f[i]]=0;FOR(i,a,b)if(p[i])res[s++]=2*i+1;}return s;}
int p[10000],ps;
int dp[10001];

int main() {
  int(n);
  ps = getPrime(10000,p);
  dp[0] = dp[1] =1;
  FOR(i,2,10001){
    REP(j,ps){
      if(p[j]>i) break;
      if(dp[i-p[j]]==0){
	dp[i] = 1; break;
      }
    }
  }

  if(dp[n])
    cout << "Win" << endl;
  else
    cout << "Lose" << endl;
}
0