結果

問題 No.2217 Suffix+
ユーザー CoCo_Japan_panCoCo_Japan_pan
提出日時 2023-02-17 22:34:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,950 bytes
コンパイル時間 2,247 ms
コンパイル使用メモリ 203,376 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-26 19:52:26
合計ジャッジ時間 4,363 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 WA -
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,384 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,384 KB
testcase_14 AC 5 ms
4,384 KB
testcase_15 AC 5 ms
4,384 KB
testcase_16 AC 9 ms
4,380 KB
testcase_17 AC 7 ms
4,384 KB
testcase_18 AC 5 ms
4,380 KB
testcase_19 AC 13 ms
4,384 KB
testcase_20 AC 12 ms
4,380 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 12 ms
4,384 KB
testcase_23 AC 10 ms
4,380 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 18 ms
4,384 KB
testcase_35 AC 1 ms
4,384 KB
testcase_36 AC 19 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// 提出時にassertはオフ
#ifndef DEBUG
#ifndef NDEBUG
#define NDEBUG
#endif
#endif

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

#define ALL(x) (x).begin(), (x).end()
template <class T> using vec = vector<T>;

int N, K;

// i番目を最小値にすることがK回以下の操作で可能ならtrue
bool canMakeMin(vector<ll> &A, int index, ll &ans){
    ll cur_up = 0;
    ll sousa = 0;
    ans = A[index];
    for(int i = index + 1; i <= N; i++){
        ll cur_num = A[i] + cur_up;
        if(cur_num >= A[index]) continue;
        ll cur_sousa = (A[index] - cur_num - 1) / i + 1;
        cur_up += cur_sousa * i;
        sousa += cur_sousa;
        // K回では足りない
        if(sousa > K) return false;
    }
    // この時の答も求めておく
    ans += (K - sousa) * index;
    return true;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N >> K;
    vec<ll> A(N + 1);
    for(int i = 1; i <= N; i++) cin >> A[i];
    // 最小値にするindexの候補 [1, i)のminよりA[i]が小さければOK
    vec<int> min_kouho = {1};
    {
        int cur_min = A[1];
        for(int i = 2; i <= N; i++) {
            if(A[i] < cur_min){
                min_kouho.push_back(i);
                cur_min = A[i];
            }
        }
    }
    // min_kouhoのうち、操作K回で実際に最小値にできる最小のindexを二分探索で求める
    ll ans = 0;
    if(canMakeMin(A, 1, ans)){
        cout << ans << "\n";
        return 0;
    }
    {
        // l_indexはNG, r_indexはOK
        int l_index = 0;
        int r_index = min_kouho.size() - 1;
        while(r_index - l_index > 1){
            int m_index = (l_index + r_index) / 2;
            if(canMakeMin(A, min_kouho[m_index], ans)) r_index = m_index;
            else l_index = m_index;
        }
        assert(canMakeMin(A, min_kouho[r_index], ans));
        cout << ans << "\n";
    }
}
0