結果
問題 | No.1977 Extracting at Constant Intervals |
ユーザー | 👑 emthrm |
提出日時 | 2023-07-22 16:00:07 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,828 bytes |
コンパイル時間 | 3,519 ms |
コンパイル使用メモリ | 255,596 KB |
実行使用メモリ | 59,436 KB |
最終ジャッジ日時 | 2023-10-23 22:23:26 |
合計ジャッジ時間 | 15,213 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,372 KB |
testcase_01 | AC | 2 ms
4,372 KB |
testcase_02 | AC | 10 ms
10,108 KB |
testcase_03 | AC | 59 ms
53,364 KB |
testcase_04 | AC | 10 ms
10,372 KB |
testcase_05 | AC | 65 ms
59,436 KB |
testcase_06 | AC | 36 ms
33,636 KB |
testcase_07 | AC | 48 ms
43,500 KB |
testcase_08 | AC | 40 ms
35,988 KB |
testcase_09 | AC | 17 ms
16,972 KB |
testcase_10 | AC | 54 ms
48,660 KB |
testcase_11 | AC | 6 ms
7,204 KB |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | AC | 33 ms
28,740 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() using ll = long long; constexpr int INF = 0x3f3f3f3f; constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL; constexpr double EPS = 1e-8; constexpr int MOD = 998244353; // constexpr int MOD = 1000000007; constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1}; constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1}; constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1}; template <typename T, typename U> inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; } template <typename T, typename U> inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; } struct IOSetup { IOSetup() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << fixed << setprecision(20); } } iosetup; int main() { constexpr int B = 47; int n, m, l; cin >> n >> m >> l; vector<int> a(n); REP(i, n) cin >> a[i]; vector dp1(B, vector(n, 0)); vector dp2(B, vector(n, 0LL)); REP(i, n) { dp1[0][i] = (i + l) % n; dp2[0][i] = a[i]; } REP(bit, B - 1) REP(i, n) { dp1[bit + 1][i] = dp1[bit][dp1[bit][i]]; dp2[bit + 1][i] = dp2[bit][i] + dp2[bit][dp1[bit][i]]; } const int x = ll{n} * m % l; ll ans = -LINF; REP(i, x) { ll t = ll{n} * m / l + 1, sum = 0; for (int bit = 0, pos = i; t > 0; ++bit, t >>= 1) { if (t & 1) { sum += dp2[bit][pos]; pos = dp1[bit][pos]; } } chmax(ans, sum); } for (int i = max(x, l - n); i < l; ++i) { ll t = ll{n} * m / l, sum = 0; for (int bit = 0, pos = i % n; t > 0; ++bit, t >>= 1) { if (t & 1) { sum += dp2[bit][pos]; pos = dp1[bit][pos]; } } chmax(ans, sum); } cout << ans << '\n'; return 0; }