結果

問題 No.12 限定された素数
ユーザー cureskolcureskol
提出日時 2020-03-27 11:09:47
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2,150 ms / 5,000 ms
コード長 1,038 bytes
コンパイル時間 1,498 ms
コンパイル使用メモリ 169,812 KB
実行使用メモリ 155,480 KB
最終ジャッジ日時 2023-08-16 01:21:19
合計ジャッジ時間 59,146 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2,076 ms
155,368 KB
testcase_01 AC 2,060 ms
155,448 KB
testcase_02 AC 2,057 ms
155,368 KB
testcase_03 AC 2,064 ms
155,232 KB
testcase_04 AC 2,107 ms
155,164 KB
testcase_05 AC 2,150 ms
155,480 KB
testcase_06 AC 2,094 ms
155,160 KB
testcase_07 AC 2,085 ms
155,440 KB
testcase_08 AC 2,096 ms
155,176 KB
testcase_09 AC 2,052 ms
155,472 KB
testcase_10 AC 2,095 ms
155,152 KB
testcase_11 AC 2,096 ms
155,152 KB
testcase_12 AC 2,124 ms
155,224 KB
testcase_13 AC 2,086 ms
155,216 KB
testcase_14 AC 2,054 ms
155,300 KB
testcase_15 AC 2,093 ms
155,236 KB
testcase_16 AC 2,063 ms
155,156 KB
testcase_17 AC 2,100 ms
155,236 KB
testcase_18 AC 2,089 ms
155,300 KB
testcase_19 AC 2,121 ms
155,160 KB
testcase_20 AC 2,134 ms
155,172 KB
testcase_21 AC 2,105 ms
155,144 KB
testcase_22 AC 2,114 ms
155,160 KB
testcase_23 AC 2,108 ms
155,280 KB
testcase_24 AC 2,105 ms
155,228 KB
testcase_25 AC 2,130 ms
155,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

template<typename T>
void chmax(T &a,T b){
  if(a<b)a=b;
}
vector<int> F[5000001];
int P[5000001];

bool prime(int a){
  if(a==1)return 0;
  if(~P[a])return P[a];
  for(int i=2;i*i<=a;i++)if(a%i==0)return P[a]=0;
  return P[a]=1;
}
vector<int> f(int a){
  if(F[a].size())return F[a];
  int tmp=a;
  vector<int> res;
  while(a){
    res.push_back(a%10);
    a/=10;
  }
  return F[tmp]=res;
}


signed main(){
  memset(P,-1,sizeof(P));
  int n;cin>>n;
  int ans=0;
  vector<int> v(10,0),now(10,0);
  while(n--){int a;cin>>a;v[a]++;}
  for(int l=1,r=1;r<=5000000;r++){
    if(prime(r)){
      for(int p:f(r))now[p]++;
      while(true){
        bool fl=false;
        for(int i=0;i<10;i++)if((!v[i])&&now[i])fl=1;
        if(fl){
          while(!prime(l))l++;
          for(int p:f(l))now[p]--;
          l++;
        }
        else break;
      }
    }
    int a=0;
    for(int i=0;i<10;i++)if((v[i]&&!now[i])||(!v[i]&&now[i]))a=1;
    if(!a)chmax(ans,r-l);
  }
  cout<<(ans?ans:-1)<<endl;
}
0