結果
| 問題 | No.3461 Min GCD |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-03-01 23:45:31 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 444 ms / 2,000 ms |
| コード長 | 1,120 bytes |
| 記録 | |
| コンパイル時間 | 1,645 ms |
| コンパイル使用メモリ | 225,572 KB |
| 実行使用メモリ | 112,768 KB |
| 最終ジャッジ日時 | 2026-03-01 23:58:10 |
| 合計ジャッジ時間 | 4,203 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
long long N,K; cin >> N >> K;
vector<long long> A(N),B(N);
for(auto &a : A) cin >> a;
for(auto &b : B) cin >> b;
vector<vector<int>> G(N),V(N);
for(int i=0; i<N; i++){
int a = A.at(i),b = B.at(i);
vector<int> &D = G.at(i),&v = V.at(i);
for(int k=1; k*k<=a; k++) if(a%k == 0){
D.push_back(k);
if(k*k != a) D.push_back(a/k);
}
sort(D.begin(),D.end());
for(auto d : D) v.push_back((d-b%d)%d);
for(int k=D.size()-2; k>=0; k--) v.at(k) = min(v.at(k),v.at(k+1));
}
int low = 1,high = 100001;
while(high-low > 1){
int mid = (high+low)/2;
long long now = 0;
for(int i=0; i<N; i++){
int pos = lower_bound(G.at(i).begin(),G.at(i).end(),mid)-G.at(i).begin();
if(pos == G.at(i).size()){now += K+1; break;}
else now += V.at(i).at(pos);
}
if(now <= K) low = mid;
else high = mid;
}
cout << low << endl;
}