結果

問題 No.2207 pCr検査
ユーザー 👑 NachiaNachia
提出日時 2023-02-03 22:13:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,122 ms / 3,000 ms
コード長 4,209 bytes
コンパイル時間 1,228 ms
コンパイル使用メモリ 91,872 KB
実行使用メモリ 98,232 KB
最終ジャッジ日時 2023-09-15 18:11:38
合計ジャッジ時間 19,984 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 536 ms
93,712 KB
testcase_03 AC 275 ms
53,772 KB
testcase_04 AC 328 ms
68,508 KB
testcase_05 AC 615 ms
88,612 KB
testcase_06 AC 378 ms
82,416 KB
testcase_07 AC 270 ms
52,212 KB
testcase_08 AC 138 ms
30,364 KB
testcase_09 AC 450 ms
69,492 KB
testcase_10 AC 212 ms
51,144 KB
testcase_11 AC 410 ms
66,500 KB
testcase_12 AC 810 ms
77,048 KB
testcase_13 AC 452 ms
48,152 KB
testcase_14 AC 92 ms
14,444 KB
testcase_15 AC 979 ms
91,104 KB
testcase_16 AC 403 ms
43,228 KB
testcase_17 AC 810 ms
70,672 KB
testcase_18 AC 556 ms
56,692 KB
testcase_19 AC 244 ms
30,136 KB
testcase_20 AC 469 ms
45,884 KB
testcase_21 AC 1,016 ms
93,216 KB
testcase_22 AC 1,109 ms
97,492 KB
testcase_23 AC 1,122 ms
98,232 KB
testcase_24 AC 113 ms
17,920 KB
testcase_25 AC 348 ms
40,816 KB
testcase_26 AC 326 ms
37,660 KB
testcase_27 AC 717 ms
70,964 KB
testcase_28 AC 766 ms
96,104 KB
testcase_29 AC 772 ms
95,608 KB
testcase_30 AC 783 ms
95,572 KB
testcase_31 AC 759 ms
95,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 1 "Main.cpp"
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <atcoder/modint>
#line 2 "nachia\\math\\prime-sieve-explicit.hpp"

#line 5 "nachia\\math\\prime-sieve-explicit.hpp"
#include <cassert>
#line 7 "nachia\\math\\prime-sieve-explicit.hpp"


namespace nachia{

namespace prime_sieve_explicit_internal{
    std::vector<bool> isprime = { false }; // a[x] := isprime(2x+1)

    void CalcIsPrime(int z){
        if((int)isprime.size() *2+1 < z+1){
            int new_z = isprime.size();
            while(new_z*2+1 < z+1) new_z *= 2;
            z = new_z-1;
            isprime.resize(z+1, true);
            for(int i=1; i*(i+1)*2<=z; i++) if(isprime[i]){
                for(int j=i*(i+1)*2; j<=z; j+=i*2+1) isprime[j] = false;
            }
        }
    }
    
    std::vector<int> prime_list = {2};
    int prime_list_max = 0;

    void CalcPrimeList(int z){
        while((int)prime_list.size() < z){
            if((int)isprime.size() <= prime_list_max + 1) CalcIsPrime(prime_list_max + 1);
            for(int p=prime_list_max+1; p<(int)isprime.size(); p++){
                if(isprime[p]) prime_list.push_back(p*2+1);
            }
            prime_list_max = isprime.size() - 1;
        }
    }

    void CalcPrimeListUntil(int z){
        if(prime_list_max < z){
            CalcIsPrime(z);
            for(int p=prime_list_max+1; p<(int)isprime.size(); p++){
                if(isprime[p]) prime_list.push_back(p*2+1);
            }
            prime_list_max = isprime.size() - 1;
        }
    }

}


bool IsprimeExplicit(int n){
    using namespace prime_sieve_explicit_internal;
    if(n == 2) return true;
    if(n % 2 == 0) return false;
    CalcIsPrime(n);
    return isprime[(n-1)/2];
}

int NthPrimeExplicit(int n){
    using namespace prime_sieve_explicit_internal;
    CalcPrimeList(n);
    return prime_list[n];
}

int PrimeCountingExplicit(int n){
    using namespace prime_sieve_explicit_internal;
    if(n < 2) return 0;
    CalcPrimeListUntil(n);
    auto res = std::upper_bound(prime_list.begin(), prime_list.end(), n) - prime_list.begin();
    return (int)res;
}

// [l, r)
std::vector<bool> SegmentedSieveExplicit(long long l, long long r){
    assert(0 <= l); assert(l <= r);
    long long d = r - l;
    if(d == 0) return {};
    std::vector<bool> res(d, true);
    for(long long p=2; p*p<=r; p++) if(IsprimeExplicit(p)){
        long long il = (l+p-1)/p, ir = (r+p-1)/p;
        if(il <= p) il = p;
        for(long long i=il; i<ir; i++) res[i*p-l] = false;
    }
    if(l < 2) for(long long p=l; p<2 && p<r; p++) res[l-p] = false;
    return res;
}


} // namespace nachia
#line 7 "Main.cpp"
using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
const i64 INF = 1001001001001001001;

using Modint = atcoder::static_modint<998244353>;

int main(){
    int k; cin >> k;
    vector<int> P(k), E(k);
    rep(i,k) cin >> P[i] >> E[i];
    int Pmax = P.back();
    int PCnt = nachia::PrimeCountingExplicit(Pmax);
    vector<int> Pex(PCnt);
    rep(i,k) Pex[nachia::PrimeCountingExplicit(P[i])-1] = E[i];
    vector<pair<int,int>> nx(Pmax+1);
    rep(i,PCnt){
        int p = nachia::NthPrimeExplicit(i);
        for(int q=1; q*p<=Pmax; q++) nx[p*q] = {i,q};
    }
    vector<int> Pnow(PCnt);
    int MatchCount = 0;
    rep(i,PCnt) if(Pnow[i] == Pex[i]) MatchCount++;
    for(int r=1; r<=Pmax; r++){
        for(int x=Pmax-r+1; x>1; x=nx[x].second){
            int p = nx[x].first;
            if(Pnow[p] == Pex[p]) MatchCount--;
            Pnow[p]++;
            if(Pnow[p] == Pex[p]) MatchCount++;
        }
        for(int x=r; x>1; x=nx[x].second){
            int p = nx[x].first;
            if(Pnow[p] == Pex[p]) MatchCount--;
            Pnow[p]--;
            if(Pnow[p] == Pex[p]) MatchCount++;
        }
        if(MatchCount == PCnt){
            cout << Pmax << ' ' << r << endl;
            return 0;
        }
    }
    cout << "-1 -1\n";
    return 0;
}



struct ios_do_not_sync{
    ios_do_not_sync(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
    }
} ios_do_not_sync_instance;

0