結果

問題 No.1097 Remainder Operation
ユーザー KKT89KKT89
提出日時 2020-06-26 21:52:36
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 338 ms / 2,000 ms
コード長 861 bytes
コンパイル時間 719 ms
コンパイル使用メモリ 84,328 KB
実行使用メモリ 62,412 KB
最終ジャッジ日時 2023-09-18 04:14:01
合計ジャッジ時間 5,664 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
58,660 KB
testcase_01 AC 12 ms
58,944 KB
testcase_02 AC 13 ms
58,664 KB
testcase_03 AC 12 ms
58,664 KB
testcase_04 AC 13 ms
58,724 KB
testcase_05 AC 12 ms
58,668 KB
testcase_06 AC 13 ms
58,708 KB
testcase_07 AC 31 ms
59,060 KB
testcase_08 AC 31 ms
59,052 KB
testcase_09 AC 31 ms
59,060 KB
testcase_10 AC 31 ms
59,084 KB
testcase_11 AC 31 ms
59,064 KB
testcase_12 AC 210 ms
62,108 KB
testcase_13 AC 230 ms
62,156 KB
testcase_14 AC 224 ms
62,188 KB
testcase_15 AC 260 ms
62,200 KB
testcase_16 AC 214 ms
62,120 KB
testcase_17 AC 191 ms
62,204 KB
testcase_18 AC 185 ms
62,164 KB
testcase_19 AC 197 ms
62,232 KB
testcase_20 AC 197 ms
62,412 KB
testcase_21 AC 337 ms
62,228 KB
testcase_22 AC 338 ms
62,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
using namespace std;
typedef long long int ll;

int to[50][100100];
ll sum[50][100100];

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
        to[0][i]=(i+a[i])%n;
        sum[0][i]=a[i];
    }
    for(int i=0;i<49;i++){
        for(int j=0;j<n;j++){
            to[i+1][j]=to[i][to[i][j]];
            sum[i+1][j]=sum[i][j]+sum[i][to[i][j]];
        }
    }
    int q; cin >> q;
    while(q--){
        ll k; cin >> k;
        int now=0;
        ll res=0;
        for(int i=49;i>=0;i--){
            if((k>>i)&1){
                res+=sum[i][now];
                now=to[i][now];
            }
        }
        cout << res << endl;
    }
}
0