結果
問題 | No.1211 円環はお断り |
ユーザー | 👑 potato167 |
提出日時 | 2024-09-09 17:39:58 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 766 ms / 2,000 ms |
コード長 | 3,305 bytes |
コンパイル時間 | 963 ms |
コンパイル使用メモリ | 82,856 KB |
実行使用メモリ | 20,480 KB |
最終ジャッジ日時 | 2024-09-09 17:40:14 |
合計ジャッジ時間 | 15,393 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 2 ms
6,940 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,940 KB |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | AC | 2 ms
6,944 KB |
testcase_10 | AC | 2 ms
6,944 KB |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | AC | 2 ms
6,948 KB |
testcase_13 | AC | 373 ms
11,816 KB |
testcase_14 | AC | 331 ms
10,832 KB |
testcase_15 | AC | 477 ms
13,696 KB |
testcase_16 | AC | 766 ms
20,224 KB |
testcase_17 | AC | 46 ms
6,940 KB |
testcase_18 | AC | 412 ms
12,464 KB |
testcase_19 | AC | 47 ms
6,940 KB |
testcase_20 | AC | 64 ms
6,944 KB |
testcase_21 | AC | 65 ms
6,940 KB |
testcase_22 | AC | 377 ms
12,164 KB |
testcase_23 | AC | 445 ms
13,696 KB |
testcase_24 | AC | 266 ms
9,088 KB |
testcase_25 | AC | 10 ms
6,944 KB |
testcase_26 | AC | 549 ms
15,232 KB |
testcase_27 | AC | 244 ms
9,088 KB |
testcase_28 | AC | 583 ms
15,488 KB |
testcase_29 | AC | 413 ms
12,880 KB |
testcase_30 | AC | 597 ms
16,528 KB |
testcase_31 | AC | 200 ms
8,320 KB |
testcase_32 | AC | 678 ms
18,816 KB |
testcase_33 | AC | 724 ms
20,364 KB |
testcase_34 | AC | 681 ms
20,364 KB |
testcase_35 | AC | 716 ms
20,236 KB |
testcase_36 | AC | 729 ms
20,352 KB |
testcase_37 | AC | 726 ms
20,352 KB |
testcase_38 | AC | 713 ms
20,480 KB |
testcase_39 | AC | 658 ms
20,352 KB |
testcase_40 | AC | 115 ms
7,948 KB |
testcase_41 | AC | 2 ms
6,944 KB |
testcase_42 | AC | 2 ms
6,944 KB |
ソースコード
#include <vector> #include <cassert> namespace po167{ template<class T, T(*op)(T, T)> struct Doubling_op{ int n; int depth; std::vector<std::vector<int>> index; std::vector<std::vector<T>> val; Doubling_op(std::vector<int> p, std::vector<T> v, long long lim = (1ll << 60) - 1){ n = p.size(); for (auto x : p) assert(0 <= x && x < n); assert(n == (int)v.size()); depth = 1; while ((1ll << depth) <= lim) depth++; index.resize(depth); val.resize(depth); index[0] = p; val[0] = v; for (int i = 1; i < depth; i++){ index[i].resize(n); val[i].resize(n); for (int j = 0; j < n; j++){ int tmp = index[i - 1][j]; index[i][j] = index[i - 1][tmp]; val[i][j] = op(val[i - 1][j], val[i - 1][tmp]); } } } std::pair<int, T> query(int start_ind, T start_val, long long times){ assert(0 <= start_ind && start_ind < n); assert(0 <= times && times < (1ll << depth)); int i = 0; while (times){ if (times & 1){ start_val = op(start_val, val[i][start_ind]); start_ind = index[i][start_ind]; } i++; times >>= 1; } return std::make_pair(start_ind, start_val); } }; struct Doubling{ int n; int depth; std::vector<std::vector<int>> index; Doubling(std::vector<int> p, long long lim = (1ll << 60) - 1){ n = p.size(); for (auto x : p) assert(0 <= x && x < n); depth = 1; while ((1ll << depth) <= lim) depth++; index.resize(depth); index[0] = p; for (int i = 1; i < depth; i++){ index[i].resize(n); for (int j = 0; j < n; j++){ index[i][j] = index[i - 1][index[i - 1][j]]; } } } int query(int ind, long long times){ assert(0 <= ind && ind < n); assert(0 <= times && times < (1ll << depth)); int i = 0; while (times){ if (times & 1) ind = index[i][ind]; i++; times >>= 1; } return ind; } }; } int op(int a, int b){ return std::min(a, b); } #include <iostream> int main(){ std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int N, K; std::cin >> N >> K; std::vector<long long> A(N); for (int i = 0; i < N; i++) std::cin >> A[i]; std::vector<long long> S(N * 2 + 1); for (int i = 0; i < N; i++){ S[i + 1] = S[i] + A[i]; } for (int i = 0; i < N; i++){ S[i + 1 + N] = S[i + 1] + S[N]; } long long l = 0, r = (1ll << 50); auto f = [&](long long m) -> int { std::vector<int> v(N * 2 + 1); for (int i = 0; i < N * 2; i++){ while (v[i] != N * 2 && S[v[i]] - S[i] < m) v[i]++; v[i + 1] = v[i]; } v[N * 2] = N * 2; po167::Doubling D(v, K); int ok = 0; for (int i = 0; i < N; i++){ if (D.query(i, K) <= N + i) ok++; } return ok; }; while (r - l > 1){ long long m = (l + r) / 2; if (f(m)) l = m; else r = m; } std::cout << l << "\n"; }