結果

問題 No.2221 Set X
ユーザー t98slider
提出日時 2023-02-18 16:11:15
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 616 bytes
コンパイル時間 1,721 ms
コンパイル使用メモリ 168,916 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-20 02:04:51
合計ジャッジ時間 4,684 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, x = 1, ans;
    cin >> n;
    vector<int> a(n);
    for(auto &&v:a) cin >> v;
    ans = 2 * n;
    auto f = [&](int v){
        int cnt = 0;
        for(int i = 0; i < n && ++cnt * (v + 1) < 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';
}
0