結果
| 問題 | 
                            No.2221 Set X
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2023-02-17 22:24:50 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 922 bytes | 
| コンパイル時間 | 1,427 ms | 
| コンパイル使用メモリ | 169,656 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-07-19 13:34:14 | 
| 合計ジャッジ時間 | 27,657 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 28 WA * 12 | 
ソースコード
#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) + 1;
    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;
}