結果

問題 No.2207 pCr検査
ユーザー milanis48663220milanis48663220
提出日時 2023-02-03 22:37:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,010 ms / 3,000 ms
コード長 2,462 bytes
コンパイル時間 1,195 ms
コンパイル使用メモリ 117,180 KB
実行使用メモリ 96,264 KB
最終ジャッジ日時 2023-09-15 18:46:39
合計ジャッジ時間 39,028 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 448 ms
52,340 KB
testcase_01 AC 466 ms
52,364 KB
testcase_02 AC 792 ms
83,164 KB
testcase_03 AC 709 ms
74,360 KB
testcase_04 AC 743 ms
74,316 KB
testcase_05 AC 999 ms
87,876 KB
testcase_06 AC 497 ms
73,288 KB
testcase_07 AC 538 ms
71,744 KB
testcase_08 AC 538 ms
63,352 KB
testcase_09 AC 828 ms
81,208 KB
testcase_10 AC 458 ms
63,496 KB
testcase_11 AC 775 ms
78,840 KB
testcase_12 AC 1,770 ms
87,388 KB
testcase_13 AC 1,212 ms
74,044 KB
testcase_14 AC 617 ms
58,532 KB
testcase_15 AC 1,965 ms
92,796 KB
testcase_16 AC 1,084 ms
72,040 KB
testcase_17 AC 1,656 ms
84,564 KB
testcase_18 AC 1,373 ms
77,332 KB
testcase_19 AC 906 ms
65,420 KB
testcase_20 AC 1,133 ms
71,128 KB
testcase_21 AC 2,010 ms
93,296 KB
testcase_22 AC 1,733 ms
96,068 KB
testcase_23 AC 1,711 ms
96,264 KB
testcase_24 AC 662 ms
60,628 KB
testcase_25 AC 1,106 ms
69,732 KB
testcase_26 AC 1,064 ms
69,216 KB
testcase_27 AC 1,672 ms
83,892 KB
testcase_28 AC 1,272 ms
94,408 KB
testcase_29 AC 1,304 ms
94,552 KB
testcase_30 AC 1,240 ms
94,560 KB
testcase_31 AC 1,263 ms
94,476 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

const int N = 10000000;
int prime_fac[N+1];
bool is_prime[N+1];

void init(){
    for(int x = 2; x <= N; x++) is_prime[x] = true;
    for(int p = 2; p <= N; p++){
        if(!is_prime[p]) continue;
        for(int i = 1; i*p <= N; i++){
            if(i >= 2) is_prime[i*p] = false;
            prime_fac[i*p] = p;
        }
    }
}

int diff[N+1];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    init();
    int k; cin >> k;
    vector<int> p(k), e(k);
    for(int i = 0; i < k; i++) {
        cin >> p[i] >> e[i];
        diff[p[i]] += e[i];
    }
    int pp = p[k-1];
    int cnt_diff = k;
    auto add = [&](int q, int x){
        if(diff[q] == 0) cnt_diff++;
        diff[q] -= x;
        if(diff[q] == 0) cnt_diff--;
    };
    for(int x = 1; x <= pp; x++){
        // 分子にかける
        int cur = pp-x+1;
        while(cur != 1){
            add(prime_fac[cur], 1);
            cur /= prime_fac[cur];
        }
        // 分母にかける
        cur = x;
        while(cur != 1){
            add(prime_fac[cur], -1);
            cur /= prime_fac[cur];
        }
        if(cnt_diff == 0){
            cout << pp << ' ' << x << endl;
            return 0;
        }
    }
    cout << -1 << ' ' << -1 << endl;
}
0