結果

問題 No.1097 Remainder Operation
ユーザー MisterMister
提出日時 2020-08-01 12:46:45
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 942 bytes
コンパイル時間 762 ms
コンパイル使用メモリ 77,048 KB
実行使用メモリ 5,144 KB
最終ジャッジ日時 2023-09-22 06:30:45
合計ジャッジ時間 4,687 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 5 ms
4,376 KB
testcase_08 AC 5 ms
4,376 KB
testcase_09 AC 5 ms
4,380 KB
testcase_10 AC 5 ms
4,376 KB
testcase_11 AC 5 ms
4,380 KB
testcase_12 AC 35 ms
4,376 KB
testcase_13 AC 36 ms
4,380 KB
testcase_14 AC 35 ms
4,376 KB
testcase_15 AC 36 ms
4,380 KB
testcase_16 AC 36 ms
4,380 KB
testcase_17 AC 37 ms
4,376 KB
testcase_18 AC 34 ms
4,864 KB
testcase_19 AC 35 ms
4,864 KB
testcase_20 AC 35 ms
5,144 KB
testcase_21 AC 35 ms
4,820 KB
testcase_22 AC 35 ms
4,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

using lint = long long;

void solve() {
    int n;
    std::cin >> n;

    std::vector<int> xs(n);
    for (auto& x : xs) std::cin >> x;

    std::vector<lint> sums;
    std::vector<int> time(n, -1);

    int i = 0, t = 0;
    lint sum = 0;
    while (time[i] == -1) {
        time[i] = t++;
        sums.push_back(sum);

        sum += xs[i];
        (i += xs[i]) %= n;
    }

    int l = time[i];
    int len = t - l;
    lint clen = sum - sums[l];

    int q;
    std::cin >> q;
    while (q--) {
        lint k;
        std::cin >> k;

        lint ans = 0;

        if (k <= l) {
            ans += sums[k];

        } else {
            k -= l;
            ans += k / len * clen;
            k %= len;
            ans += sums[l + k];
        }

        std::cout << ans << "\n";
    }
}

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

    solve();

    return 0;
}
0