結果

問題 No.1097 Remainder Operation
ユーザー MayimgMayimg
提出日時 2020-07-03 15:52:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 240 ms / 2,000 ms
コード長 914 bytes
コンパイル時間 2,915 ms
コンパイル使用メモリ 207,092 KB
実行使用メモリ 52,560 KB
最終ジャッジ日時 2023-10-14 23:35:59
合計ジャッジ時間 7,299 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 11 ms
8,108 KB
testcase_08 AC 12 ms
8,032 KB
testcase_09 AC 11 ms
8,108 KB
testcase_10 AC 11 ms
7,956 KB
testcase_11 AC 11 ms
7,980 KB
testcase_12 AC 118 ms
52,272 KB
testcase_13 AC 151 ms
52,388 KB
testcase_14 AC 144 ms
52,560 KB
testcase_15 AC 171 ms
52,424 KB
testcase_16 AC 130 ms
52,296 KB
testcase_17 AC 94 ms
52,364 KB
testcase_18 AC 83 ms
52,312 KB
testcase_19 AC 101 ms
52,432 KB
testcase_20 AC 101 ms
52,296 KB
testcase_21 AC 240 ms
52,424 KB
testcase_22 AC 236 ms
52,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<vector<int>> nxt(41, vector<int>(n));
  vector<vector<long long>> sum(41, vector<long long>(n));
  for (int i = 0; i < n; i++) {
    nxt[0][i] = (i + a[i]) % n;
    sum[0][i] = a[i];
  }
  for (int u = 1; u < 41; u++) {
    for (int i = 0; i < n; i++) {
      nxt[u][i] = nxt[u - 1][nxt[u - 1][i]];
      sum[u][i] = sum[u - 1][i] + sum[u - 1][nxt[u - 1][i]];
    }
  }
  int q;
  cin >> q;
  while (q--) {
    long long k;
    cin >> k;
    long long ans = 0;
    int cur = 0;
    for (int i = 40; i >= 0; i--) {
      if (k >= (1LL << i)) {
        ans += sum[i][cur];
        cur = nxt[i][cur];
        k -= (1LL << i);
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
0