結果
問題 | No.2221 Set X |
ユーザー |
|
提出日時 | 2023-02-18 16:03:33 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 187 ms / 2,000 ms |
コード長 | 887 bytes |
コンパイル時間 | 1,735 ms |
コンパイル使用メモリ | 169,356 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-20 02:00:39 |
合計ジャッジ時間 | 6,081 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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; int ng = i, ok = n, mid; while(ng + 1 < ok){ mid = (ok + ng) / 2; if(a[i] / v < a[mid] / v) ok = mid; else ng = mid; } i = ok; } 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'; }