結果
問題 | No.1977 Extracting at Constant Intervals |
ユーザー | Forested |
提出日時 | 2022-06-10 23:40:15 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,570 bytes |
コンパイル時間 | 1,398 ms |
コンパイル使用メモリ | 135,920 KB |
実行使用メモリ | 41,600 KB |
最終ジャッジ日時 | 2024-09-21 07:01:03 |
合計ジャッジ時間 | 3,939 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | AC | 68 ms
30,464 KB |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | AC | 15 ms
8,320 KB |
testcase_13 | AC | 72 ms
30,976 KB |
testcase_14 | AC | 78 ms
38,016 KB |
testcase_15 | AC | 41 ms
19,456 KB |
testcase_16 | AC | 82 ms
37,504 KB |
testcase_17 | AC | 91 ms
41,472 KB |
testcase_18 | AC | 42 ms
19,072 KB |
testcase_19 | AC | 18 ms
10,624 KB |
testcase_20 | AC | 74 ms
33,536 KB |
testcase_21 | AC | 76 ms
35,072 KB |
testcase_22 | AC | 69 ms
38,400 KB |
testcase_23 | AC | 12 ms
8,448 KB |
testcase_24 | AC | 61 ms
34,432 KB |
testcase_25 | AC | 7 ms
6,940 KB |
testcase_26 | AC | 10 ms
7,168 KB |
testcase_27 | AC | 35 ms
19,712 KB |
testcase_28 | AC | 17 ms
10,880 KB |
testcase_29 | AC | 36 ms
20,352 KB |
testcase_30 | AC | 63 ms
36,096 KB |
testcase_31 | AC | 31 ms
18,048 KB |
testcase_32 | AC | 41 ms
19,712 KB |
ソースコード
#ifndef LOCAL #define FAST_IO #endif // ===== template.hpp ===== #include <algorithm> #include <array> #include <bitset> #include <cassert> #include <cmath> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define OVERRIDE(a, b, c, d, ...) d #define REP2(i, n) for (i32 i = 0; i < (i32) (n); ++i) #define REP3(i, m, n) for (i32 i = (i32) (m); i < (i32) (n); ++i) #define REP(...) OVERRIDE(__VA_ARGS__, REP3, REP2)(__VA_ARGS__) #define PER(i, n) for (i32 i = (i32) (n) - 1; i >= 0; --i) #define ALL(x) begin(x), end(x) using namespace std; using u32 = unsigned int; using u64 = unsigned long long; using u128 = __uint128_t; using i32 = signed int; using i64 = signed long long; using i128 = __int128_t; using f64 = double; using f80 = long double; template <typename T> using Vec = vector<T>; template <typename T> bool chmin(T &x, const T &y) { if (x > y) { x = y; return true; } return false; } template <typename T> bool chmax(T &x, const T &y) { if (x < y) { x = y; return true; } return false; } istream &operator>>(istream &is, i128 &x) { i64 v; is >> v; x = v; return is; } ostream &operator<<(ostream &os, i128 x) { os << (i64) x; return os; } istream &operator>>(istream &is, u128 &x) { u64 v; is >> v; x = v; return is; } ostream &operator<<(ostream &os, u128 x) { os << (u64) x; return os; } template <typename F, typename Comp = less<>> Vec<i32> sort_index(i32 n, F f, Comp comp = Comp()) { Vec<i32> idx(n); iota(ALL(idx), 0); sort(ALL(idx), [&](i32 i, i32 j) -> bool { return comp(f(i), f(j)); }); return idx; } [[maybe_unused]] constexpr i32 INF = 1000000100; [[maybe_unused]] constexpr i64 INF64 = 3000000000000000100; #ifdef FAST_IO __attribute__((constructor)) void fast_io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(10); } #endif // ===== template.hpp ===== #ifdef DEBUGF #include "cpl/template/debug.hpp" #else #define DBG(x) (void) 0 #endif int main() { i32 n; i64 m; i64 l; cin >> n >> m >> l; Vec<i64> a(n); REP(i, n) { cin >> a[i]; } i32 lg = 0; while (n * m > (1LL << lg)) { ++lg; } i32 step = l % n; Vec<i32> steps(lg + 1); steps[0] = step; REP(i, lg) { steps[i + 1] = 2 * steps[i] % n; } Vec<Vec<i64>> gain(lg + 1, Vec<i64>(n)); gain[0] = a; REP(i, lg) { REP(j, n) { gain[i + 1][j] = gain[i][j] + gain[i][(j + steps[i]) % n]; } } DBG(gain); const auto calc_cx = [&](i64 x) -> i64 { i64 cnt = n * m / l; if (x < n * m % l) { ++cnt; } DBG(x); DBG(cnt); i64 sum = 0; i32 cur = x % n; REP(i, lg + 1) { if ((cnt >> i) & 1) { sum += gain[i][cur]; cur = (cur + steps[i]) % n; } } DBG(sum); return sum; }; i64 ans = -INF64; REP(i, n) { chmax(ans, calc_cx(i)); } if (l > n) { for (i64 i = l - n; i < l; ++i) { chmax(ans, calc_cx(i)); } } for (i64 i = n * m - n; i < n * m; ++i) { chmax(ans, calc_cx(i % l)); } cout << ans << '\n'; }