結果

問題 No.2217 Suffix+
ユーザー xiachi00xiachi00
提出日時 2023-07-01 16:08:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 794 bytes
コンパイル時間 2,113 ms
コンパイル使用メモリ 203,292 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-08 02:18:16
合計ジャッジ時間 5,074 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 5 ms
6,944 KB
testcase_15 AC 5 ms
6,944 KB
testcase_16 AC 10 ms
6,944 KB
testcase_17 AC 7 ms
6,944 KB
testcase_18 AC 7 ms
6,944 KB
testcase_19 AC 33 ms
6,944 KB
testcase_20 AC 33 ms
6,940 KB
testcase_21 AC 7 ms
6,940 KB
testcase_22 AC 33 ms
6,940 KB
testcase_23 AC 27 ms
6,944 KB
testcase_24 AC 21 ms
6,940 KB
testcase_25 AC 20 ms
6,940 KB
testcase_26 AC 20 ms
6,940 KB
testcase_27 AC 20 ms
6,940 KB
testcase_28 AC 20 ms
6,940 KB
testcase_29 AC 72 ms
6,944 KB
testcase_30 AC 72 ms
6,944 KB
testcase_31 AC 73 ms
6,940 KB
testcase_32 AC 72 ms
6,940 KB
testcase_33 AC 73 ms
6,944 KB
testcase_34 AC 20 ms
6,940 KB
testcase_35 AC 2 ms
6,940 KB
testcase_36 AC 89 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/istream:39,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/sstream:38,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/complex:45,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ccomplex:39,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/x86_64-pc-linux-gnu/bits/stdc++.h:54,
                 from main.cpp:1:
In member function '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:
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ostream:202:25: warning: 'res' may be used uninitialized [-Wmaybe-uninitialized]
  202 |       { return _M_insert(__n); }
      |                ~~~~~~~~~^~~~~
main.cpp: In function 'int main()':
main.cpp:26:19: note: 'res' was declared here
   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