結果

問題 No.2221 Set X
ユーザー kuroni
提出日時 2023-02-17 22:29:04
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,574 ms / 2,000 ms
コード長 922 bytes
コンパイル時間 1,756 ms
コンパイル使用メモリ 169,744 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-19 13:39:10
合計ジャッジ時間 16,936 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int d = sqrt(2 * n) + 2;
    pair<int, int> ans = {2 * n, 1};
    for (int i = 2; i <= d; i++) {
        int cnt = 1;
        for (int j = 1; j < n; j++) {
            if (a[j] / i > a[j - 1] / i) {
                cnt++;
            }
        }
        ans = min(ans, {cnt * (i + 1), i});
    }
    vector<int> pt(2 * d);
    for (int i = d + 1; i < 2 * n; i++) {
        for (int j = 1; j < 2 * d; j++) {
            while (pt[j] < n && a[pt[j]] / i <= a[pt[j - 1]] / i) {
                pt[j]++;
            }
            if (pt[j] == n) {
                ans = min(ans, {j * (i + 1), i});
                break;
            }
        }
    }
    cout << ans.second << '\n' << ans.first;
}
0