結果

問題 No.2221 Set X
ユーザー t98slider
提出日時 2023-02-18 15:59:49
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 813 bytes
コンパイル時間 1,426 ms
コンパイル使用メモリ 168,480 KB
実行使用メモリ 13,752 KB
最終ジャッジ日時 2024-07-20 01:58:42
合計ジャッジ時間 11,121 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22 TLE * 2 -- * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
    ans = 2 * n;
    auto f = [&](int v){
        if(v + 1 > ans) return ans;
        while(zi < n && a[zi] < v) zi++;
        if(zi >= 1) b[zi - 1] = 0;
        int cnt = 1;
        for(int i = zi; i < n; i++){
            b[i] = a[i] / v;
            if(i && b[i] != b[i - 1]){
                cnt++;
                if(cnt * (v + 1) > ans) return ans;
            } 
        }
        return cnt * (v + 1);
    };
    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