結果

問題 No.12 限定された素数
ユーザー ninoinuininoinui
提出日時 2020-07-21 13:33:33
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 65 ms / 5,000 ms
コード長 1,004 bytes
コンパイル時間 2,193 ms
コンパイル使用メモリ 203,772 KB
実行使用メモリ 5,988 KB
最終ジャッジ日時 2023-08-28 10:21:08
合計ジャッジ時間 4,974 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
5,860 KB
testcase_01 AC 62 ms
5,624 KB
testcase_02 AC 61 ms
5,680 KB
testcase_03 AC 65 ms
5,728 KB
testcase_04 AC 61 ms
5,628 KB
testcase_05 AC 62 ms
5,628 KB
testcase_06 AC 61 ms
5,620 KB
testcase_07 AC 63 ms
5,816 KB
testcase_08 AC 61 ms
5,772 KB
testcase_09 AC 60 ms
5,680 KB
testcase_10 AC 61 ms
5,684 KB
testcase_11 AC 63 ms
5,676 KB
testcase_12 AC 62 ms
5,800 KB
testcase_13 AC 61 ms
5,800 KB
testcase_14 AC 62 ms
5,628 KB
testcase_15 AC 61 ms
5,860 KB
testcase_16 AC 64 ms
5,812 KB
testcase_17 AC 60 ms
5,680 KB
testcase_18 AC 61 ms
5,848 KB
testcase_19 AC 61 ms
5,852 KB
testcase_20 AC 60 ms
5,848 KB
testcase_21 AC 61 ms
5,988 KB
testcase_22 AC 60 ms
5,680 KB
testcase_23 AC 60 ms
5,728 KB
testcase_24 AC 61 ms
5,732 KB
testcase_25 AC 61 ms
5,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
  int N, MX = 5e6;
  cin >> N;
  vector<int> A(10);
  for (int a; cin >> a;) A.at(a)++;

  vector<bool> B(MX + 1, 1);
  B.at(0) = B.at(1) = 0;
  for (long i = 2; i <= MX; i++) if (B.at(i)) for (long j = i * i; j <= MX; j += i) B.at(j) = 0;
  vector<int> P;
  for (int i = 1; i <= MX; i++) if (B.at(i)) P.push_back(i);

  int ans = 0;
  vector<int> cnt(10);
  for (int l = 0, r = 0, mi = 0, mx = 0; r < P.size(); r++) {
    int tmp = P.at(r);
    while (tmp) cnt.at(tmp % 10)++, tmp /= 10;
    for (int i = 0; i < 10; i++) {
      if (!A.at(i) && cnt.at(i)) {
        l = r + 1;
        fill(cnt.begin(), cnt.end(), 0);
        goto next;
      }
    }
    for (int i = 0; i < 10; i++) {
      if (A.at(i) && !cnt.at(i)) {
        goto next;
      }
    }
    mi = ((l - 1 >= 0) ? P.at(l - 1) : 0) + 1;
    mx = ((r + 1 < P.size()) ? P.at(r + 1) : 5e6 + 1) - 1;
    ans = max(ans, mx - mi);
    next:;
  }
  cout << ((ans) ? ans : -1) << "\n";
}
0