結果

問題 No.1977 Extracting at Constant Intervals
ユーザー KudeKude
提出日時 2022-06-10 23:41:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 101 ms / 2,000 ms
コード長 1,829 bytes
コンパイル時間 2,495 ms
コンパイル使用メモリ 220,664 KB
実行使用メモリ 83,200 KB
最終ジャッジ日時 2024-04-17 15:41:05
合計ジャッジ時間 5,045 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 13 ms
12,928 KB
testcase_03 AC 81 ms
74,624 KB
testcase_04 AC 13 ms
13,440 KB
testcase_05 AC 90 ms
83,200 KB
testcase_06 AC 48 ms
46,208 KB
testcase_07 AC 62 ms
59,904 KB
testcase_08 AC 53 ms
49,664 KB
testcase_09 AC 23 ms
22,528 KB
testcase_10 AC 71 ms
67,456 KB
testcase_11 AC 7 ms
8,448 KB
testcase_12 AC 16 ms
14,720 KB
testcase_13 AC 74 ms
61,056 KB
testcase_14 AC 98 ms
80,640 KB
testcase_15 AC 46 ms
38,272 KB
testcase_16 AC 93 ms
74,752 KB
testcase_17 AC 101 ms
81,152 KB
testcase_18 AC 45 ms
36,352 KB
testcase_19 AC 20 ms
19,840 KB
testcase_20 AC 93 ms
76,672 KB
testcase_21 AC 84 ms
68,096 KB
testcase_22 AC 91 ms
75,264 KB
testcase_23 AC 17 ms
15,616 KB
testcase_24 AC 81 ms
67,072 KB
testcase_25 AC 8 ms
8,704 KB
testcase_26 AC 12 ms
12,416 KB
testcase_27 AC 45 ms
38,656 KB
testcase_28 AC 20 ms
19,968 KB
testcase_29 AC 47 ms
40,064 KB
testcase_30 AC 85 ms
70,528 KB
testcase_31 AC 41 ms
34,944 KB
testcase_32 AC 45 ms
39,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic pop
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  ll l;
  cin >> l;
  VI a(n);
  rep(i, n) cin >> a[i];
  vector<vector<pair<int, ll>>> to(50, vector<pair<int, ll>>(n));
  rep(i, n) {
    to[0][i] = {(i + l) % n, a[i]};
  }
  rep(k, 49) {
    rep(i, n) {
      int j = to[k][i].first;
      to[k+1][i] = {to[k][j].first, to[k][i].second + to[k][j].second};
    }
  }
  ll ans = -1e18;
  rep(i, n) {
    if (i >= l) break;
    // i + lr >= n * m
    // r >= (n * m - i) / l
    ll r = ((ll)n * m - i + l - 1) / l;
    ll v = 0;
    int now = i;
    rrep(k, 50) {
      if (r >> k & 1) {
        v += to[k][now].second;
        now = to[k][now].first;
      }
    }
    chmax(ans, v);
  }
  rep(i, n) {
    // l-1-i + lr >= n * m
    // r >= (n * m - (l-1-i)) / l
    if (l - 1 - i < 0) break;
    ll r = ((ll)n * m - (l-1-i) + l - 1) / l;
    ll v = 0;
    int now = (l - 1 - i) % n;
    rrep(k, 50) {
      if (r >> k & 1) {
        v += to[k][now].second;
        now = to[k][now].first;
      }
    }
    chmax(ans, v);
  }
  cout << ans << '\n';
}
0