結果

問題 No.1977 Extracting at Constant Intervals
ユーザー SSRSSSRS
提出日時 2022-06-10 21:50:07
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 126 ms / 2,000 ms
コード長 1,349 bytes
コンパイル時間 1,632 ms
コンパイル使用メモリ 173,348 KB
実行使用メモリ 63,796 KB
最終ジャッジ日時 2024-04-17 15:39:26
合計ジャッジ時間 4,201 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 14 ms
10,752 KB
testcase_03 AC 114 ms
57,100 KB
testcase_04 AC 13 ms
11,008 KB
testcase_05 AC 126 ms
63,796 KB
testcase_06 AC 67 ms
35,848 KB
testcase_07 AC 83 ms
46,500 KB
testcase_08 AC 56 ms
38,856 KB
testcase_09 AC 24 ms
17,920 KB
testcase_10 AC 83 ms
52,028 KB
testcase_11 AC 8 ms
7,424 KB
testcase_12 AC 15 ms
11,904 KB
testcase_13 AC 70 ms
46,980 KB
testcase_14 AC 89 ms
61,864 KB
testcase_15 AC 42 ms
29,880 KB
testcase_16 AC 86 ms
57,508 KB
testcase_17 AC 91 ms
62,464 KB
testcase_18 AC 42 ms
28,472 KB
testcase_19 AC 19 ms
15,872 KB
testcase_20 AC 83 ms
59,040 KB
testcase_21 AC 72 ms
52,540 KB
testcase_22 AC 85 ms
57,832 KB
testcase_23 AC 14 ms
12,800 KB
testcase_24 AC 71 ms
51,540 KB
testcase_25 AC 7 ms
7,552 KB
testcase_26 AC 11 ms
10,240 KB
testcase_27 AC 40 ms
29,884 KB
testcase_28 AC 19 ms
16,128 KB
testcase_29 AC 40 ms
31,092 KB
testcase_30 AC 74 ms
54,080 KB
testcase_31 AC 35 ms
27,336 KB
testcase_32 AC 38 ms
30,496 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const int LOG = 50;
const long long INF = 2000000000000000000;
int main(){
  int N, M;
  long long L;
  cin >> N >> M >> L;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  vector<vector<int>> nxt(LOG, vector<int>(N, 0));
  vector<vector<long long>> sum(LOG, vector<long long>(N, 0));
  for (int i = 0; i < N; i++){
    nxt[0][i] = (i + L) % N;
    sum[0][i] = A[i];
  }
  for (int i = 0; i < LOG - 1; i++){
    for (int j = 0; j < N; j++){
      nxt[i + 1][j] = nxt[i][nxt[i][j]];
      sum[i + 1][j] = sum[i][j] + sum[i][nxt[i][j]];
    }
  }
  vector<long long> a(N, 0), b(N, 0);
  for (int i = 0; i < N; i++){
    long long R = (long long) N * M / L;
    int p = i;
    for (int j = 0; j < LOG; j++){
      if ((R >> j & 1) == 1){
        a[i] += sum[j][p];
        p = nxt[j][p];
      }
    }
  }
  for (int i = 0; i < N; i++){
    long long R = (long long) N * M / L + 1;
    int p = i;
    for (int j = 0; j < LOG; j++){
      if ((R >> j & 1) == 1){
        b[i] += sum[j][p];
        p = nxt[j][p];
      }
    }
  }
  long long r = (long long) M * N % L;
  long long ans = -INF;
  for (int i = 0; i < min(r, (long long) N); i++){
    ans = max(ans, b[i]);
  }
  for (long long i = max(r, L - N); i < L; i++){
    ans = max(ans, a[i % N]);
  }
  cout << ans << endl;
}
0