結果

問題 No.2221 Set X
ユーザー hitonanode
提出日時 2023-02-17 23:25:47
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 139 ms / 2,000 ms
コード長 561 bytes
コンパイル時間 806 ms
コンパイル使用メモリ 95,208 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-19 14:37:50
合計ジャッジ時間 4,739 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#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(A.begin(), A.end(), x * (A.at(i) / x + 1)) - A.begin()) cnt += x + 1;
        if (best > cnt) best = cnt, argbest = x;
    }
    cout << argbest << '\n' << best << '\n';
}
0