結果

問題 No.2221 Set X
コンテスト
ユーザー hitonanode
提出日時 2023-02-17 23:26:57
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 68 ms / 2,000 ms
コード長 557 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,138 ms
コンパイル使用メモリ 169,068 KB
実行使用メモリ 177,036 KB
最終ジャッジ日時 2026-04-02 17:05:12
合計ジャッジ時間 4,311 ms
ジャッジサーバーID
(参考情報)
judge5_1 / judge4_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
    cin.tie(nullptr), ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N);
    for (auto &x : A) cin >> x;

    int best = 2 * N;
    int argbest = 1;
    for (int x = 2; x < N * 2; ++x) {
        int cnt = 0;
        for (int i = 0; i < N and cnt < best; i = lower_bound(begin(A) + i, end(A), A[i] / x * x + x) - begin(A)) cnt += x + 1;
        if (best > cnt) best = cnt, argbest = x;
    }
    cout << argbest << '\n' << best << '\n';
}
0