結果

問題 No.1097 Remainder Operation
ユーザー siman
提出日時 2023-03-16 19:20:13
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
AC  
実行時間 373 ms / 2,000 ms
コード長 940 bytes
コンパイル時間 2,995 ms
コンパイル使用メモリ 140,280 KB
実行使用メモリ 36,224 KB
最終ジャッジ日時 2024-09-18 09:27:59
合計ジャッジ時間 9,443 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
  ll N;
  cin >> N;
  ll A[N];
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }

  ll memo[N + 1][41];
  for (int x = 0; x < N; ++x) {
    int r = x % N;
    memo[x][0] = x + A[r];
  }

  for (int step = 1; step <= 40; ++step) {
    for (int i = 0; i < N; ++i) {
      ll x = memo[i][step - 1];
      ll d = x / N;
      ll r = x % N;
      memo[i][step] = d * N + memo[r][step - 1];
    }
  }

  int Q;
  cin >> Q;
  for (int i = 0; i < Q; ++i) {
    ll k;
    cin >> k;
    ll X = 0;

    for (int d = 0; d < 40; ++d) {
      if (k >> d & 1) {
        ll v = X / N;
        ll r = X % N;
        X = v * N + memo[r][d];
      }
    }

    cout << X << endl;
  }

  return 0;
}
0