結果
| 問題 | No.2207 pCr検査 | 
| コンテスト | |
| ユーザー | 👑  tatyam | 
| 提出日時 | 2022-07-13 01:35:00 | 
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 507 ms / 3,000 ms | 
| コード長 | 927 bytes | 
| コンパイル時間 | 2,917 ms | 
| コンパイル使用メモリ | 247,180 KB | 
| 実行使用メモリ | 8,448 KB | 
| 最終ジャッジ日時 | 2024-07-02 18:42:16 | 
| 合計ジャッジ時間 | 13,747 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 30 | 
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:36:32: warning: 'R' may be used uninitialized [-Wmaybe-uninitialized]
   36 |         if(e != f(P) - f(R) - f(P - R)){
      |                               ~^~~~~~~
main.cpp:19:9: note: 'R' was declared here
   19 |     int R;
      |         ^
            
            ソースコード
#include <bits/stdc++.h>
using namespace std;
using ld = long double;
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int k;
    cin >> k;
    vector<pair<int, int>> N(k);
    ld lgN = 0;
    for(auto& [p, e] : N){
        cin >> p >> e;
        lgN += logl(p) * e;
    }
    const int P = N.back().first;
    ld lg = 0, err = INFINITY;
    int R;
    for(int i = 0; i < P / 2; i++){
        lg += logl(P - i) - logl(i + 1);
        if(err > abs(lgN - lg)){
            err = abs(lgN - lg);
            R = i + 1;
        }
    }
    for(auto [p, e] : N){
        auto f = [p = p](int x){
            int ans = 0;
            while(1){
                x /= p;
                if(x == 0) return ans;
                ans += x;
            }
        };
        if(e != f(P) - f(R) - f(P - R)){
            cout << "-1 -1" << endl;
            return 0;
        }
    }
    cout << P << ' ' << R << endl;
}
            
            
            
        