結果

問題 No.1977 Extracting at Constant Intervals
ユーザー 👑 emthrmemthrm
提出日時 2023-07-22 16:12:17
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 66 ms / 2,000 ms
コード長 1,860 bytes
コンパイル時間 3,028 ms
コンパイル使用メモリ 255,740 KB
実行使用メモリ 59,424 KB
最終ジャッジ日時 2023-10-23 22:35:21
合計ジャッジ時間 5,265 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 9 ms
10,096 KB
testcase_03 AC 57 ms
53,352 KB
testcase_04 AC 10 ms
10,360 KB
testcase_05 AC 64 ms
59,424 KB
testcase_06 AC 35 ms
33,624 KB
testcase_07 AC 45 ms
43,488 KB
testcase_08 AC 37 ms
35,976 KB
testcase_09 AC 16 ms
16,960 KB
testcase_10 AC 50 ms
48,648 KB
testcase_11 AC 6 ms
7,192 KB
testcase_12 AC 10 ms
11,416 KB
testcase_13 AC 50 ms
43,944 KB
testcase_14 AC 65 ms
57,792 KB
testcase_15 AC 30 ms
28,008 KB
testcase_16 AC 61 ms
53,808 KB
testcase_17 AC 66 ms
58,248 KB
testcase_18 AC 28 ms
26,568 KB
testcase_19 AC 15 ms
15,112 KB
testcase_20 AC 61 ms
54,984 KB
testcase_21 AC 56 ms
49,104 KB
testcase_22 AC 59 ms
54,072 KB
testcase_23 AC 11 ms
11,944 KB
testcase_24 AC 51 ms
48,192 KB
testcase_25 AC 6 ms
7,192 KB
testcase_26 AC 8 ms
9,568 KB
testcase_27 AC 31 ms
28,008 KB
testcase_28 AC 14 ms
15,112 KB
testcase_29 AC 30 ms
29,184 KB
testcase_30 AC 55 ms
50,544 KB
testcase_31 AC 26 ms
25,656 KB
testcase_32 AC 30 ms
28,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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; ll 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 ll x = ll{n} * m % l;
  ll ans = -LINF;
  for (int i = 0; i < x && i < n; ++i) {
    ll t = ll{n} * m / l + 1, 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);
  }
  for (ll 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;
}
0