結果

問題 No.1977 Extracting at Constant Intervals
ユーザー 👑 emthrmemthrm
提出日時 2023-07-22 16:11:14
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,833 bytes
コンパイル時間 3,506 ms
コンパイル使用メモリ 255,564 KB
実行使用メモリ 59,388 KB
最終ジャッジ日時 2023-10-23 22:34:11
合計ジャッジ時間 8,345 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 9 ms
10,060 KB
testcase_03 AC 58 ms
53,316 KB
testcase_04 AC 9 ms
10,324 KB
testcase_05 AC 64 ms
59,388 KB
testcase_06 AC 35 ms
33,588 KB
testcase_07 AC 47 ms
43,452 KB
testcase_08 AC 38 ms
35,940 KB
testcase_09 AC 16 ms
16,924 KB
testcase_10 AC 52 ms
48,612 KB
testcase_11 AC 6 ms
7,156 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

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;
  REP(i, x) {
    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