結果

問題 No.2207 pCr検査
ユーザー 👑 testestesttestestest
提出日時 2022-07-12 15:03:29
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,363 ms / 3,000 ms
コード長 662 bytes
コンパイル時間 2,022 ms
コンパイル使用メモリ 196,276 KB
最終ジャッジ日時 2025-01-30 06:46:03
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:16:25: warning: ‘p’ may be used uninitialized [-Wmaybe-uninitialized]
   16 |         vector<int>mpf(p+1);
      |                        ~^~
main.cpp:8:13: note: ‘p’ was declared here
    8 |         int p;
      |             ^

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

int main(){
	int k;
	cin >> k;
	vector<int>e(10000000+1);
	int p;
	for(int i=0;i<k;i++){
		int pp,ee;
		cin >> pp >> ee;
		p=pp;
		e[pp]=ee;
	}

	vector<int>mpf(p+1);
	for(int i=2;i<=p;i++)if(!mpf[i])for(int j=i;j<=p;j+=i)mpf[j]=i;

	int diff=k;
	for(int r=1;r<=p/2;r++){
		for(int temp=p-r+1;temp!=1;temp/=mpf[temp]){
			if(!e[mpf[temp]])diff++;
			e[mpf[temp]]--;
			if(!e[mpf[temp]])diff--;
		}
		for(int temp=r;temp!=1;temp/=mpf[temp]){
			if(!e[mpf[temp]])diff++;
			e[mpf[temp]]++;
			if(!e[mpf[temp]])diff--;
		}
		if(!diff){
			cout << p << ' ' << p-r << endl;
			return 0;
		}
	}
	cout << "-1 -1" << endl;
}
0