結果

問題 No.1097 Remainder Operation
ユーザー iqueue02iqueue02
提出日時 2020-06-26 22:14:45
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 532 ms / 2,000 ms
コード長 761 bytes
コンパイル時間 2,019 ms
コンパイル使用メモリ 199,300 KB
最終ジャッジ日時 2025-01-11 11:39:50
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, int> PL;
constexpr ll INF = (1LL << 60);

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  
  vector<vector<ll>> to(61, vector<ll>(n, 0));

  for (int i = 0; i < n; i++) to[0][i] = a[i];

  for (int i = 0; i < 60; i++) {
    for (int j = 0; j < n; j++) to[i + 1][j] = to[i][j] + to[i][(j + to[i][j]) % n];
  }

  int q;
  cin >> q;

  while (q--) {
    ll k;
    cin >> k;
    ll res = 0;
    for (int j = 0; j < 60; j++) {
      if (k & (1LL << j)) res += to[j][res % n];
    }
    cout << res << endl;
  }

  return 0;
} 
0