結果

問題 No.1097 Remainder Operation
ユーザー kk
提出日時 2020-09-01 19:31:52
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 385 ms / 2,000 ms
コード長 792 bytes
コンパイル時間 1,998 ms
コンパイル使用メモリ 198,212 KB
実行使用メモリ 42,940 KB
最終ジャッジ日時 2023-08-12 21:18:49
合計ジャッジ時間 9,232 ms
ジャッジサーバーID
(参考情報)
judge10 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
40,192 KB
testcase_01 AC 9 ms
40,184 KB
testcase_02 AC 9 ms
40,284 KB
testcase_03 AC 10 ms
40,280 KB
testcase_04 AC 9 ms
40,196 KB
testcase_05 AC 9 ms
40,128 KB
testcase_06 AC 10 ms
40,132 KB
testcase_07 AC 33 ms
40,600 KB
testcase_08 AC 34 ms
40,464 KB
testcase_09 AC 33 ms
40,560 KB
testcase_10 AC 33 ms
40,556 KB
testcase_11 AC 33 ms
40,692 KB
testcase_12 AC 280 ms
42,764 KB
testcase_13 AC 286 ms
42,768 KB
testcase_14 AC 289 ms
42,760 KB
testcase_15 AC 304 ms
42,804 KB
testcase_16 AC 282 ms
42,712 KB
testcase_17 AC 246 ms
42,800 KB
testcase_18 AC 240 ms
42,940 KB
testcase_19 AC 278 ms
42,868 KB
testcase_20 AC 272 ms
42,752 KB
testcase_21 AC 385 ms
42,708 KB
testcase_22 AC 381 ms
42,868 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define ALL(x) (x).begin(), (x).end()

const double PI = acos(-1);

int n;
int a[100000];
long long dp[50][100000];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  cin >> n;
  REP (i, n) cin >> a[i];

  REP (i, n) dp[0][i] = a[i];
  for (int j = 1; j < 50; j++) {
    for (int i = 0; i < n; i++)
      dp[j][i] = dp[j-1][i] + dp[j-1][(i + dp[j-1][i]) % n];    // i: current state of x, j: log(length)
  }

  int q;
  cin >> q;

  REP (_, q) {
    long long k;
    cin >> k;

    long long x = 0;
    REP (i, 50) {
      if (k & 1LL<<i) {
        x += dp[i][x%n];
      }
    }
    cout << x << endl;    
  }
  
  return 0;
}
0