結果

問題 No.2221 Set X
ユーザー t98slider
提出日時 2023-02-17 22:48:14
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,010 bytes
コンパイル時間 1,596 ms
コンパイル使用メモリ 168,132 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-19 14:00:52
合計ジャッジ時間 50,454 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32 WA * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    clock_t finish = clock() + CLOCKS_PER_SEC / 1000 * 1920;
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for(auto &&v:a)cin >> v;
    int pos = -1;
    int ans = 1 << 30;
    if(2 * n < ans){
        ans = 2 * n;
        pos = 1;
    }
    if(a.back() + 2 < ans){
        ans = a.back() + 2;
        pos = a.back() + 1;
    }
    int zi = 0;
    vector<int> b(n);
    auto f = [&](int v){
        int cnt = 1;
        while(zi < n && a[zi] < v) zi++;
        if(zi >= 1) b[zi - 1] = 0;
        for(int i = zi; i < n; i++){
            b[i] = a[i] / v;
            if(i >= 1 && b[i] != b[i - 1])cnt++;
        }
        return cnt * (v + 1);
    };
    int r = 2 * n;
    for(int i = 1; i <= r && clock() <= finish; i++){
        int v = f(i);
        if(v < ans){
            ans = v;
            pos = i;
        }
    }
    cout << pos << '\n';
    cout << ans << '\n';
}
0