結果

問題 No.1097 Remainder Operation
ユーザー face4face4
提出日時 2020-07-24 15:38:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 447 ms / 2,000 ms
コード長 682 bytes
コンパイル時間 442 ms
コンパイル使用メモリ 64,488 KB
実行使用メモリ 42,748 KB
最終ジャッジ日時 2023-09-07 12:23:00
合計ジャッジ時間 6,962 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
40,236 KB
testcase_01 AC 9 ms
40,276 KB
testcase_02 AC 9 ms
40,204 KB
testcase_03 AC 10 ms
40,508 KB
testcase_04 AC 9 ms
40,296 KB
testcase_05 AC 9 ms
40,296 KB
testcase_06 AC 9 ms
40,204 KB
testcase_07 AC 40 ms
40,432 KB
testcase_08 AC 41 ms
40,428 KB
testcase_09 AC 40 ms
40,428 KB
testcase_10 AC 41 ms
40,528 KB
testcase_11 AC 40 ms
40,532 KB
testcase_12 AC 344 ms
42,464 KB
testcase_13 AC 349 ms
42,376 KB
testcase_14 AC 362 ms
42,416 KB
testcase_15 AC 369 ms
42,404 KB
testcase_16 AC 353 ms
42,404 KB
testcase_17 AC 296 ms
42,376 KB
testcase_18 AC 289 ms
42,380 KB
testcase_19 AC 335 ms
42,380 KB
testcase_20 AC 330 ms
42,404 KB
testcase_21 AC 439 ms
42,412 KB
testcase_22 AC 447 ms
42,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
using namespace std;
typedef long long ll;

ll db[50][100000] = {}; // 40~overflowするかもしれないけどどうせ使わないからいい

int main(){
    int n;
    cin >> n;
    for(int i = 0; i < n; i++)  cin >> db[0][i];
    for(int i = 1; i < 50; i++){
        for(int j = 0; j < n; j++){
            db[i][j] = db[i-1][j] + db[i-1][(j+db[i-1][j])%n];
        }
    }
    int q;
    cin >> q;
    while(q--){
        ll k;
        cin >> k;
        int pos = 0;
        ll ans = 0;
        for(int i = 0; i < 50; i++){
            if(k>>i&1)  ans += db[i][pos], pos = (pos+db[i][pos]%n)%n;
        }
        cout << ans << endl;
    }
    return 0;
}
0