結果

問題 No.1097 Remainder Operation
ユーザー IKyoproIKyopro
提出日時 2020-06-26 21:40:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 279 ms / 2,000 ms
コード長 991 bytes
コンパイル時間 2,151 ms
コンパイル使用メモリ 205,028 KB
実行使用メモリ 68,140 KB
最終ジャッジ日時 2023-09-18 03:37:00
合計ジャッジ時間 6,146 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 14 ms
9,560 KB
testcase_08 AC 14 ms
9,564 KB
testcase_09 AC 13 ms
9,648 KB
testcase_10 AC 13 ms
9,568 KB
testcase_11 AC 14 ms
9,600 KB
testcase_12 AC 142 ms
68,092 KB
testcase_13 AC 180 ms
68,092 KB
testcase_14 AC 176 ms
68,068 KB
testcase_15 AC 202 ms
68,084 KB
testcase_16 AC 154 ms
68,096 KB
testcase_17 AC 112 ms
68,016 KB
testcase_18 AC 101 ms
68,088 KB
testcase_19 AC 121 ms
68,140 KB
testcase_20 AC 121 ms
68,072 KB
testcase_21 AC 279 ms
68,096 KB
testcase_22 AC 276 ms
68,028 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    const int K = 40;
    vec<ll> A(N);
    vvec<ll> ne(K+1,vec<ll>(N)),val = ne;
    for(int i=0;i<N;i++){
        cin >> A[i];
        ne[0][i] = (i+A[i])%N;
        val[0][i] = A[i];
    }
    for(int k=1;k<=K;k++){
        for(int i=0;i<N;i++){
            ne[k][i] = ne[k-1][ne[k-1][i]];
            val[k][i] = val[k-1][i]+val[k-1][ne[k-1][i]];
        }
    }
    int Q;
    cin >> Q;
    while(Q--){
        ll X;
        cin >> X;
        ll ans = 0;
        int now = 0;
        for(int k=K;k>=0;k--){
            if(X>>k&1){
                ans += val[k][now];
                now = ne[k][now];
                X -= 1LL<<k;
            }
        }
        cout << ans << "\n";
    }
}
0