結果

問題 No.1097 Remainder Operation
ユーザー NewGardenNewGarden
提出日時 2020-06-26 22:36:12
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 466 ms / 2,000 ms
コード長 1,012 bytes
コンパイル時間 1,588 ms
コンパイル使用メモリ 170,448 KB
実行使用メモリ 75,240 KB
最終ジャッジ日時 2023-09-18 06:05:18
合計ジャッジ時間 7,785 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 31 ms
10,252 KB
testcase_08 AC 32 ms
10,112 KB
testcase_09 AC 31 ms
10,168 KB
testcase_10 AC 32 ms
10,292 KB
testcase_11 AC 32 ms
10,192 KB
testcase_12 AC 367 ms
75,116 KB
testcase_13 AC 412 ms
75,220 KB
testcase_14 AC 422 ms
75,064 KB
testcase_15 AC 465 ms
75,136 KB
testcase_16 AC 391 ms
75,116 KB
testcase_17 AC 311 ms
75,176 KB
testcase_18 AC 294 ms
75,188 KB
testcase_19 AC 324 ms
75,112 KB
testcase_20 AC 327 ms
75,240 KB
testcase_21 AC 458 ms
75,116 KB
testcase_22 AC 466 ms
75,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln = '\n';

const int mx=200010;
const ll mod=1e9+7;


int main(){
  int n;
  cin >> n;
  vector<vector<ll>> add(45, vector<ll>(n,0));
  vector<vector<ll>> nxt(45, vector<ll>(n,0));
  rep(i,n){
    cin >> add[0][i];
  }
  rep(i,n){
    nxt[0][i] = (i+add[0][i])%n;
  }
  int q; cin >> q;
  rep(j,43){
      auto nx = nxt[j];
      auto ad = add[j];
      rep(i,n){
        nxt[j+1][i] = nx[nx[i]];
        add[j+1][i] = ad[i] + ad[nx[i]];
      }
  }
  while(q--){
    ll k; cin >> k;
    ll ans = 0;
    int pos = 0;
    int cnt = 0;
    while(k>0){
      if(k%2==1){
        ans += add[cnt][pos];
        pos = nxt[cnt][pos];
      }
      cnt++;
      k/=2;
    }
    cout << ans << ln;
  }  

  return 0;
}
0