結果

問題 No.12 限定された素数
ユーザー Mi_SawaMi_Sawa
提出日時 2015-04-05 01:28:45
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 147 ms / 5,000 ms
コード長 1,727 bytes
コンパイル時間 1,295 ms
コンパイル使用メモリ 145,632 KB
実行使用メモリ 62,276 KB
最終ジャッジ日時 2023-08-15 22:51:40
合計ジャッジ時間 5,945 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 146 ms
62,108 KB
testcase_01 AC 147 ms
62,000 KB
testcase_02 AC 131 ms
62,040 KB
testcase_03 AC 126 ms
62,044 KB
testcase_04 AC 139 ms
61,956 KB
testcase_05 AC 132 ms
62,276 KB
testcase_06 AC 133 ms
62,012 KB
testcase_07 AC 140 ms
62,000 KB
testcase_08 AC 141 ms
62,016 KB
testcase_09 AC 125 ms
61,944 KB
testcase_10 AC 123 ms
62,020 KB
testcase_11 AC 125 ms
61,972 KB
testcase_12 AC 124 ms
62,068 KB
testcase_13 AC 124 ms
61,948 KB
testcase_14 AC 126 ms
61,960 KB
testcase_15 AC 126 ms
61,960 KB
testcase_16 AC 124 ms
61,976 KB
testcase_17 AC 128 ms
62,016 KB
testcase_18 AC 132 ms
62,088 KB
testcase_19 AC 125 ms
62,016 KB
testcase_20 AC 124 ms
61,940 KB
testcase_21 AC 125 ms
62,092 KB
testcase_22 AC 123 ms
61,940 KB
testcase_23 AC 125 ms
62,236 KB
testcase_24 AC 127 ms
61,944 KB
testcase_25 AC 128 ms
61,960 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define all(x) begin(x),end(x)
#define rall(x) (x).rbegin(),(x).rend()
#define REP(i,b,n) for(int i=(int)(b);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define repsz(i,v) rep(i,(v).size())
#define aur auto&
#define bit(n) (1LL<<(n))
#define eb emplace_back
#define mt make_tuple
#define fst first
#define snd second
using namespace std;
typedef long long ll;
//#define int long long
template<class C>int size(const C &c){ return c.size(); }
template<class T>bool chmin(T&a,const T&b){if(a<=b)return false;a=b;return true;}
template<class T>bool chmax(T&a,const T&b){if(a>=b)return false;a=b;return true;}

constexpr int N = 5 * 1000 * 1000 + 1;
constexpr int D = 10;

array<int, N> sieve(){ //{{{
    static array<int, N> f;
    rep(i, f.size()) f[i] = i;
    f[0] = f[1] = 0;
    for(int i = 2; i < N; ++i) if(f[i] == i)
        for(int j = i + i; j < N; j += i) f[j] = 0;
    return f;
} //}}}

bool solve(){
    static auto is_prime = sieve();
    static array<int, N> t = {};
    rep(n, N) if(is_prime[n]) for(int m = n; m; m /= D) t[n] |= 1<<(m%D);

    int a = 0;
    {
        int n; cin >> n;
        rep(i, n){ int x; cin >> x; a |= 1<<x; }
    }

    int res = -1;
    for(int l = 1, r = 1; true; ){
        while(l < N and (t[l] & ~a)) ++l;
        if(l >= N) break;
        r = l;
        while(r < N-1 and (t[r+1] & ~a) == 0) ++r;
        int c = 0;
        REP(i, l, r+1) c |= t[i];
        if(c == a) chmax(res, r-l);
        l = r+1;
    }
    cout << res << endl;
    return true;
}
signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}
// vim:set foldmethod=marker commentstring=//%s:
0