結果

問題 No.1097 Remainder Operation
ユーザー finefine
提出日時 2020-06-26 21:54:20
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 171 ms / 2,000 ms
コード長 1,045 bytes
コンパイル時間 1,663 ms
コンパイル使用メモリ 173,920 KB
実行使用メモリ 51,748 KB
最終ジャッジ日時 2023-09-18 04:18:30
合計ジャッジ時間 5,078 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 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 12 ms
8,044 KB
testcase_08 AC 11 ms
7,992 KB
testcase_09 AC 11 ms
7,988 KB
testcase_10 AC 12 ms
8,252 KB
testcase_11 AC 11 ms
7,996 KB
testcase_12 AC 125 ms
51,568 KB
testcase_13 AC 141 ms
51,656 KB
testcase_14 AC 148 ms
51,504 KB
testcase_15 AC 155 ms
51,516 KB
testcase_16 AC 136 ms
51,592 KB
testcase_17 AC 87 ms
51,748 KB
testcase_18 AC 78 ms
51,508 KB
testcase_19 AC 102 ms
51,608 KB
testcase_20 AC 103 ms
51,520 KB
testcase_21 AC 171 ms
51,712 KB
testcase_22 AC 166 ms
51,636 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

constexpr char newl = '\n';

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;

    vector<ll> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    vector< vector<int> > nex(40, vector<int>(n, -1));
    vector< vector<ll> > sum(40, vector<ll>(n, 0));
    for (int i = 0; i < n; i++) {
        nex[0][i] = (i + a[i]) % n;
        sum[0][i] = a[i];
    }

    for (int i = 1; i < 40; i++) {
        for (int j = 0; j < n; j++) {
            nex[i][j] = nex[i - 1][nex[i - 1][j]];
            sum[i][j] = sum[i - 1][nex[i - 1][j]] + sum[i - 1][j];
        }
    }

    int q;
    cin >> q;

    for (int i = 0; i < q; i++) {
        ll K;
        cin >> K;

        int cur = 0;
        ll ans = 0;
        for (int i = 0; i < 40; i++) {
            if (K >> i & 1) {
                ans += sum[i][cur];
                cur = nex[i][cur];
            }
        }
        cout << ans << newl;
    }

    return 0;
}
0