結果
問題 | No.2221 Set X |
ユーザー |
|
提出日時 | 2023-02-18 16:07:50 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 81 ms / 2,000 ms |
コード長 | 753 bytes |
コンパイル時間 | 1,469 ms |
コンパイル使用メモリ | 169,740 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-20 02:03:26 |
合計ジャッジ時間 | 4,026 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n, x = 1, ans, zi = 0; cin >> n; vector<int> a(n), b(n); for(auto &&v:a) cin >> v; a.push_back(2e9); ans = 2 * n; auto f = [&](int v){ if(v + 1 > ans) return ans; int cnt = 0; for(int i = 0; i < n; ){ cnt++; if((v + 1) * cnt > ans) return ans; i = lower_bound(a.begin() + i + 1, a.end(), (a[i] / v + 1) * v) - a.begin(); } return (v + 1) * cnt; }; for(int i = 2; i <= 2 * n; i++){ int v = f(i); if(v < ans){ ans = v; x = i; } } cout << x << '\n'; cout << ans << '\n'; }