結果

問題 No.1097 Remainder Operation
ユーザー betrue12betrue12
提出日時 2020-06-26 21:36:38
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 362 ms / 2,000 ms
コード長 804 bytes
コンパイル時間 1,896 ms
コンパイル使用メモリ 199,892 KB
実行使用メモリ 66,256 KB
最終ジャッジ日時 2023-09-18 03:25:04
合計ジャッジ時間 7,387 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
62,804 KB
testcase_01 AC 13 ms
62,820 KB
testcase_02 AC 14 ms
62,764 KB
testcase_03 AC 13 ms
62,788 KB
testcase_04 AC 14 ms
62,756 KB
testcase_05 AC 13 ms
62,752 KB
testcase_06 AC 13 ms
62,880 KB
testcase_07 AC 36 ms
63,100 KB
testcase_08 AC 37 ms
63,180 KB
testcase_09 AC 36 ms
63,368 KB
testcase_10 AC 36 ms
63,164 KB
testcase_11 AC 36 ms
63,128 KB
testcase_12 AC 262 ms
65,948 KB
testcase_13 AC 281 ms
66,140 KB
testcase_14 AC 286 ms
66,084 KB
testcase_15 AC 309 ms
65,964 KB
testcase_16 AC 271 ms
66,084 KB
testcase_17 AC 249 ms
65,992 KB
testcase_18 AC 230 ms
66,112 KB
testcase_19 AC 263 ms
65,956 KB
testcase_20 AC 262 ms
65,960 KB
testcase_21 AC 362 ms
66,088 KB
testcase_22 AC 360 ms
66,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int nth_bit(int64_t num, int n){
    return (num >> n) & 1;
}

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i];
    static int64_t sum[40][100000], nxt[40][100000];
    for(int i=0; i<N; i++){
        sum[0][i] = A[i];
        nxt[0][i] = (i+A[i])%N;
    }
    for(int k=1; k<40; k++) for(int i=0; i<N; i++){
        sum[k][i] = sum[k-1][i] + sum[k-1][nxt[k-1][i]];
        nxt[k][i] = nxt[k-1][nxt[k-1][i]];
    }

    int Q;
    cin >> Q;
    while(Q--){
        int64_t K;
        cin >> K;
        int64_t ans = 0;
        int X = 0;
        for(int k=0; k<40; k++) if(nth_bit(K, k)){
            ans += sum[k][X];
            X = nxt[k][X];
        }
        cout << ans << endl;
    }
    return 0;
}
0