結果
問題 | No.12 限定された素数 |
ユーザー | srup٩(๑`н´๑)۶ |
提出日時 | 2016-09-30 00:44:35 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,578 bytes |
コンパイル時間 | 1,026 ms |
コンパイル使用メモリ | 69,948 KB |
実行使用メモリ | 8,600 KB |
最終ジャッジ日時 | 2023-08-23 10:53:25 |
合計ジャッジ時間 | 13,407 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 376 ms
8,424 KB |
testcase_01 | AC | 422 ms
8,372 KB |
testcase_02 | AC | 343 ms
8,412 KB |
testcase_03 | AC | 629 ms
8,448 KB |
testcase_04 | AC | 372 ms
8,456 KB |
testcase_05 | AC | 412 ms
8,388 KB |
testcase_06 | AC | 439 ms
8,452 KB |
testcase_07 | AC | 496 ms
8,344 KB |
testcase_08 | AC | 384 ms
8,332 KB |
testcase_09 | AC | 401 ms
8,324 KB |
testcase_10 | AC | 411 ms
8,328 KB |
testcase_11 | AC | 538 ms
8,344 KB |
testcase_12 | AC | 454 ms
8,352 KB |
testcase_13 | AC | 438 ms
8,364 KB |
testcase_14 | AC | 413 ms
8,576 KB |
testcase_15 | AC | 438 ms
8,460 KB |
testcase_16 | AC | 472 ms
8,352 KB |
testcase_17 | AC | 441 ms
8,508 KB |
testcase_18 | AC | 323 ms
8,448 KB |
testcase_19 | AC | 324 ms
8,384 KB |
testcase_20 | AC | 333 ms
8,376 KB |
testcase_21 | AC | 385 ms
8,384 KB |
testcase_22 | AC | 342 ms
8,332 KB |
testcase_23 | AC | 338 ms
8,324 KB |
testcase_24 | AC | 408 ms
8,380 KB |
testcase_25 | WA | - |
ソースコード
#include <iostream> #include <algorithm> #include <vector> #include <string> #include <cstdio> #include <set> using namespace std; typedef long long ll; #define rep(i,n) for(int i=0;i<(n);i++) const int INF = 1e9; bool isprime[5000010]; //エラトテネス void eratos(int m){ for (int i = 0; i <= m; ++i) isprime[i] = true; isprime[0] = isprime[1] = false; //iを残してiの倍数を消していく for (int i = 2; i <= m; ++i){ if(isprime[i]){ for (int j = 2 * i; j <= m; j += i){ isprime[j] = false; } } } } int n; set<int> a; int cnt[10]; bool hantei(){ rep(i, 10){ if(a.count(i) == 0){//含んでいけない数 if(cnt[i] != 0) return false; } } return true; } bool ok(){ rep(i, 10){ if(a.count(i) != 0){ if(cnt[i] == 0) return false; } } return true; } int main(void){ cin >> n; rep(i, n){ int t; cin >> t; a.insert(t); } eratos(5000000); rep(i, 10) cnt[i] = 0; int ans = -1; //[l, r]でしゃくとり法 int l = 1; for (int r = 1; r <= 5000000; ++r){//右を伸ばせるだけのばす if(isprime[r]){ string tm = to_string(r); rep(i, tm.size()){ cnt[tm[i] - '0']++; } } if(!hantei()){//含んでいけない文字を含んでしまっているので、左を縮める while(!isprime[l] && l <= r - 1) l++;//素数のつぎの数まで縮める string tmp = to_string(l); rep(j, tmp.size()){ cnt[tmp[j] - '0']--; } l++; } if(ok()){//条件を満たす ans = max(ans, r - l); } } printf("%d\n", ans); }