結果

問題 No.2217 Suffix+
ユーザー xiachi00xiachi00
提出日時 2023-07-01 16:08:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 90 ms / 2,000 ms
コード長 794 bytes
コンパイル時間 1,999 ms
コンパイル使用メモリ 201,180 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-22 10:19:41
合計ジャッジ時間 6,146 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 5 ms
4,376 KB
testcase_15 AC 6 ms
4,380 KB
testcase_16 AC 10 ms
4,380 KB
testcase_17 AC 7 ms
4,376 KB
testcase_18 AC 6 ms
4,380 KB
testcase_19 AC 32 ms
4,380 KB
testcase_20 AC 33 ms
4,376 KB
testcase_21 AC 8 ms
4,376 KB
testcase_22 AC 33 ms
4,380 KB
testcase_23 AC 26 ms
4,380 KB
testcase_24 AC 20 ms
4,376 KB
testcase_25 AC 21 ms
4,380 KB
testcase_26 AC 20 ms
4,376 KB
testcase_27 AC 21 ms
4,380 KB
testcase_28 AC 20 ms
4,376 KB
testcase_29 AC 73 ms
4,380 KB
testcase_30 AC 73 ms
4,380 KB
testcase_31 AC 73 ms
4,380 KB
testcase_32 AC 72 ms
4,380 KB
testcase_33 AC 73 ms
4,380 KB
testcase_34 AC 21 ms
4,376 KB
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 90 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
次のファイルから読み込み:  /usr/local/gcc7/include/c++/12.2.0/istream:39,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/sstream:38,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/complex:45,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/ccomplex:39,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/x86_64-pc-linux-gnu/bits/stdc++.h:54,
         次から読み込み:  main.cpp:1:
メンバ関数 ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>]’ 内,
    inlined from ‘int main()’ at main.cpp:36:13:
/usr/local/gcc7/include/c++/12.2.0/ostream:202:25: 警告: ‘res’ may be used uninitialized [-Wmaybe-uninitialized]
  202 |       { return _M_insert(__n); }
      |                ~~~~~~~~~^~~~~
main.cpp: 関数 ‘int main()’ 内:
main.cpp:26:19: 備考: ‘res’ はここで定義されています
   26 |     LL l, r, mid, res;
      |                   ^~~

ソースコード

diff #

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

using LL = long long;

int main() {
    ios_base::sync_with_stdio(false);
    
    int n, k;
    cin >> n >> k;
    vector<LL> a(n);
    for (LL &x : a) cin >> x;
    auto check = [&](LL s) {
        LL sum = 0, w;
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            if (a[i] + sum < s) {
                w = (s - a[i] - sum + i) / (i + 1);
                if (cnt + w > k) return false;
                sum += w * (i + 1), cnt += w;
            }
        }
        return true;
    };

    LL l, r, mid, res;
    l = 0, r = 1E18;
    while (l <= r) {
        mid = l + r >> 1;
        if (check(mid)) {
            l = (res = mid) + 1;
        } else {
            r = mid - 1;
        }
    }
    cout << res;

    return 0;
}
0