結果

問題 No.1977 Extracting at Constant Intervals
ユーザー KudeKude
提出日時 2022-06-10 23:26:00
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,862 bytes
コンパイル時間 2,953 ms
コンパイル使用メモリ 231,596 KB
実行使用メモリ 83,180 KB
最終ジャッジ日時 2023-10-21 05:46:10
合計ジャッジ時間 6,024 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 14 ms
13,480 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 72 ms
59,944 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 77 ms
67,600 KB
testcase_11 WA -
testcase_12 AC 16 ms
14,800 KB
testcase_13 AC 75 ms
61,000 KB
testcase_14 AC 100 ms
80,800 KB
testcase_15 AC 47 ms
38,296 KB
testcase_16 AC 92 ms
74,728 KB
testcase_17 AC 101 ms
81,328 KB
testcase_18 AC 46 ms
36,448 KB
testcase_19 AC 22 ms
19,816 KB
testcase_20 AC 92 ms
76,840 KB
testcase_21 AC 86 ms
68,128 KB
testcase_22 AC 91 ms
75,256 KB
testcase_23 AC 17 ms
15,600 KB
testcase_24 AC 82 ms
67,072 KB
testcase_25 AC 8 ms
8,728 KB
testcase_26 AC 13 ms
12,424 KB
testcase_27 AC 45 ms
38,560 KB
testcase_28 AC 22 ms
20,080 KB
testcase_29 AC 47 ms
40,144 KB
testcase_30 AC 85 ms
70,504 KB
testcase_31 AC 41 ms
34,864 KB
testcase_32 AC 47 ms
39,088 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) {
    // 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 >= (1LL << k)) {
        r -= 1LL << k;
        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 >= (1LL << k)) {
        r -= 1LL << k;
        v += to[k][now].second;
        now = to[k][now].first;
      }
    }
    chmax(ans, v);
  }
  cout << ans << '\n';
}
0