結果
| 問題 | No.2217 Suffix+ |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-07-01 16:08:56 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 34 ms / 2,000 ms |
| コード長 | 794 bytes |
| 記録 | |
| コンパイル時間 | 1,265 ms |
| コンパイル使用メモリ | 211,464 KB |
| 実行使用メモリ | 6,528 KB |
| 最終ジャッジ日時 | 2026-07-01 14:17:08 |
| 合計ジャッジ時間 | 4,065 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 33 |
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/ostream:42,
from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/istream:43,
from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/sstream:42,
from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/complex:50,
from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/x86_64-pc-linux-gnu/bits/stdc++.h:141,
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/15.2.0_1/include/c++/15/bits/ostream.h:212:25: warning: 'res' may be used uninitialized [-Wmaybe-uninitialized]
212 | { 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;
| ^~~
ソースコード
#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;
}