結果

問題 No.12 限定された素数
ユーザー togatogatogatoga
提出日時 2015-09-03 23:31:55
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,150 bytes
コンパイル時間 861 ms
コンパイル使用メモリ 91,816 KB
実行使用メモリ 10,336 KB
最終ジャッジ日時 2023-09-26 04:15:14
合計ジャッジ時間 3,069 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
10,012 KB
testcase_01 AC 41 ms
10,040 KB
testcase_02 AC 36 ms
9,928 KB
testcase_03 AC 66 ms
10,128 KB
testcase_04 AC 38 ms
10,016 KB
testcase_05 AC 44 ms
10,088 KB
testcase_06 AC 57 ms
10,336 KB
testcase_07 AC 56 ms
9,928 KB
testcase_08 WA -
testcase_09 AC 43 ms
10,164 KB
testcase_10 WA -
testcase_11 AC 61 ms
9,980 KB
testcase_12 AC 56 ms
10,016 KB
testcase_13 AC 52 ms
9,952 KB
testcase_14 WA -
testcase_15 AC 53 ms
10,064 KB
testcase_16 AC 56 ms
9,960 KB
testcase_17 AC 35 ms
10,112 KB
testcase_18 AC 34 ms
10,124 KB
testcase_19 AC 34 ms
10,060 KB
testcase_20 AC 37 ms
10,012 KB
testcase_21 AC 41 ms
9,924 KB
testcase_22 AC 35 ms
9,924 KB
testcase_23 AC 35 ms
10,160 KB
testcase_24 AC 36 ms
10,324 KB
testcase_25 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘bool check()’:
main.cpp:68:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^

ソースコード

diff #

#include <iostream>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <algorithm>
#include <functional>
#include <limits.h>
#include <bitset>

#include <tuple>
#include <unordered_map>

#define mp       make_pair
#define mt       make_tuple
#define pb       push_back
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
const int MAX_L = 5000010;
int N;
vector<int> digit;
vector<int> prime;
bool is_prime[MAX_L];
bool ok[11];
void sieve(){
  is_prime[0] = is_prime[1] = false;
  for (ll i = 2; i * i < MAX_L; i++){
    if (is_prime[i]){
      for (ll j = i + i; j  < MAX_L; j += i){
	is_prime[j] = false;
      }
    }
  }
  for (int i = 2; i <= 5000000; i++){
    if (is_prime[i]){
      prime.push_back(i);
    }
  }
}
bool check(){
  for (int i = 0; i < N; i++){
    if (ok[i]){
      return true;
    }else{
      return false;
    }
  }
}
bool in_digit(int x){
  while (x){
    int y = x % 10;
    bool flag = false;
    for (int j = 0; j < N; j++){
      if (digit[j] == y){
	ok[j] = true;
	flag = true;
	break;
      }
    }
    if (!flag)return false;
    x /= 10;
  }
  return true;
}
int main(){
  cin >> N;
  digit.resize(N);
  memset(is_prime, true, sizeof(is_prime));
  for (int i = 0; i < N; i++){
    cin >> digit[i];
  }
  sieve();
  int K = 1;
  int L = 1;
  memset(ok, false, sizeof(ok));
  int ans = -1;
  for (int i = 0; i < prime.size(); i++){
    if (in_digit(prime[i])){
     
    }else{
      K = prime[i] + 1;
      L = prime[i] + 1;
      memset(ok, false, sizeof(ok));
    }
    if (check()){
      if (i + 1 < prime.size()){
	L = prime[i + 1] - 1;
      }else{
	L = 5000000;
      }
      if (ans < L - K){
	ans = L - K;
	//	cout << K << " " << L << endl;
      }
    }

  }
  cout << ans << endl;
  return 0;
}
0