結果

問題 No.12 限定された素数
ユーザー ninoinuininoinui
提出日時 2020-07-21 13:30:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 963 bytes
コンパイル時間 2,136 ms
コンパイル使用メモリ 204,528 KB
実行使用メモリ 6,008 KB
最終ジャッジ日時 2023-08-28 10:16:19
合計ジャッジ時間 5,399 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
5,632 KB
testcase_01 WA -
testcase_02 AC 61 ms
5,672 KB
testcase_03 AC 63 ms
5,676 KB
testcase_04 AC 64 ms
5,684 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 63 ms
5,744 KB
testcase_08 WA -
testcase_09 AC 63 ms
5,672 KB
testcase_10 WA -
testcase_11 AC 63 ms
5,848 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 64 ms
5,732 KB
testcase_18 AC 64 ms
5,628 KB
testcase_19 AC 64 ms
5,848 KB
testcase_20 AC 62 ms
5,844 KB
testcase_21 WA -
testcase_22 AC 65 ms
5,860 KB
testcase_23 AC 64 ms
6,008 KB
testcase_24 AC 64 ms
5,820 KB
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

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)) {
        goto next;
      }
      if (!A.at(i) && cnt.at(i)) {
        l = r + 1;
        fill(cnt.begin(), cnt.end(), 0);
        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