結果

問題 No.12 限定された素数
ユーザー ninoinuininoinui
提出日時 2020-07-21 12:20:15
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,124 bytes
コンパイル時間 2,326 ms
コンパイル使用メモリ 210,872 KB
実行使用メモリ 6,028 KB
最終ジャッジ日時 2023-08-27 15:43:43
合計ジャッジ時間 6,321 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
5,724 KB
testcase_01 AC 95 ms
5,680 KB
testcase_02 AC 87 ms
6,028 KB
testcase_03 AC 82 ms
6,016 KB
testcase_04 AC 87 ms
5,632 KB
testcase_05 AC 102 ms
5,792 KB
testcase_06 AC 101 ms
5,636 KB
testcase_07 AC 101 ms
5,804 KB
testcase_08 AC 99 ms
5,856 KB
testcase_09 AC 97 ms
5,856 KB
testcase_10 WA -
testcase_11 AC 102 ms
5,984 KB
testcase_12 AC 101 ms
5,696 KB
testcase_13 AC 105 ms
5,788 KB
testcase_14 AC 106 ms
5,788 KB
testcase_15 AC 105 ms
5,856 KB
testcase_16 AC 103 ms
5,868 KB
testcase_17 AC 89 ms
5,724 KB
testcase_18 AC 82 ms
5,868 KB
testcase_19 AC 81 ms
5,724 KB
testcase_20 AC 90 ms
5,636 KB
testcase_21 AC 101 ms
5,668 KB
testcase_22 AC 83 ms
5,856 KB
testcase_23 AC 83 ms
5,816 KB
testcase_24 AC 88 ms
5,808 KB
testcase_25 AC 100 ms
5,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
  int N, A;
  cin >> N;
  N = 5e6;
  set<int> SE;
  while (cin >> A) SE.insert(A);
  
  vector<bool> B(N + 1, 1);
  B.at(0) = B.at(1) = 0;
  for (long i = 2; i <= N; i++) if (B.at(i)) for (long j = i * i; j <= N; j += i) B.at(j) = 0;
  vector<int> P;
  for (int i = 1; i <= N; i++) if (B.at(i)) P.push_back(i);
  
  vector<int> cnt(10);
  int ans = 0;
  for (int l = 0, r = 0; r < P.size(); r++) {
    int tmp = P.at(r);
    while (tmp) cnt.at(tmp % 10)++, tmp /= 10;
    bool b1 = 0, b2 = 0;
    for (int i = 0; i < 10; i++) {
      if (SE.count(i) && !cnt.at(i)) b1 = 1;
      if (!SE.count(i) && cnt.at(i)) b2 = 1;
    }
    while (b2 && l < r) {
      tmp = P.at(l++);
      while (tmp) cnt.at(tmp % 10)--, tmp /= 10;
      bool b3 = 0;
      for (int i = 0; i < 10; i++) if (!SE.count(i) && cnt.at(i)) b3 = 1;
      if (!b3) b2 = 0;
    }
    if (!b1 && !b2) {
      int mi = ((l - 1 >= 0) ? P.at(l - 1) : 0) + 1;
      int mx = ((r + 1 < P.size()) ? P.at(r + 1) : 5e6 + 1) - 1;
      ans = max(ans, mx - mi);
    }
  }
  cout << ((ans) ? ans : -1) << "\n";
}
0