結果
問題 |
No.2207 pCr検査
|
ユーザー |
|
提出日時 | 2024-10-06 22:54:04 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,995 ms / 3,000 ms |
コード長 | 1,663 bytes |
コンパイル時間 | 1,139 ms |
コンパイル使用メモリ | 114,672 KB |
最終ジャッジ日時 | 2025-02-24 16:14:39 |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 30 |
ソースコード
#include<iostream> #include<string> #include<queue> #include<vector> #include<cassert> #include<random> #include<set> #include<map> #include<cassert> #include<unordered_map> #include<bitset> #include<numeric> #include<algorithm> using namespace std; typedef long long ll; const int inf=1<<30; const ll INF=1LL<<62; typedef pair<int,ll> P; typedef pair<int,P> PP; const ll MOD=998244353; int main(){ int k; cin>>k; const int MAXP=10000000; vector<ll> p(MAXP),e(MAXP+1); ll cp=0; for(int i=0;i<k;i++){ ll pp,ee; cin>>pp>>ee; e[pp]=ee; cp=pp; } vector<ll> mpf(cp+1); for(int i=2;i<=cp;i++){ if(mpf[i]==0){ for(int j=i;j<=cp;j+=i){ mpf[j]=i;//jはiで割れる } } } ll dif=k; for(ll r=1;r<=cp/2;r++){ // cp C r を試す // cp!/(r!(cp-r)!)を試す for(ll tmp=cp-r+1;tmp!=1;tmp/=mpf[tmp]){ // cp!/tmp! を試す. tmp=cp-r+1,cp-r+2,...,cp //tmpを素因数分解する if(e[mpf[tmp]]==0){ dif++; } e[mpf[tmp]]--; if(e[mpf[tmp]]==0){ dif--; } } for(ll tmp=r;tmp!=1;tmp/=mpf[tmp]){ //cp C tmpを試す. tmp=1,2,3,...,r if(e[mpf[tmp]]==0){ dif++; } e[mpf[tmp]]++; if(e[mpf[tmp]]==0){ dif--; } } if(dif==0){ cout<<cp<<' '<<r<<endl; return 0; } } cout<<-1<<' '<<-1<<endl; }