結果

問題 No.1097 Remainder Operation
ユーザー merom686merom686
提出日時 2020-06-26 22:00:51
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 933 bytes
コンパイル時間 768 ms
コンパイル使用メモリ 88,104 KB
実行使用メモリ 4,860 KB
最終ジャッジ日時 2023-09-18 04:34:33
合計ジャッジ時間 3,117 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 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,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 5 ms
4,380 KB
testcase_08 AC 5 ms
4,376 KB
testcase_09 AC 5 ms
4,376 KB
testcase_10 AC 5 ms
4,376 KB
testcase_11 AC 5 ms
4,376 KB
testcase_12 AC 35 ms
4,640 KB
testcase_13 AC 35 ms
4,572 KB
testcase_14 AC 35 ms
4,640 KB
testcase_15 AC 35 ms
4,636 KB
testcase_16 AC 34 ms
4,860 KB
testcase_17 AC 35 ms
4,596 KB
testcase_18 AC 32 ms
4,640 KB
testcase_19 AC 33 ms
4,684 KB
testcase_20 AC 32 ms
4,632 KB
testcase_21 AC 33 ms
4,600 KB
testcase_22 AC 33 ms
4,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int n;
    cin >> n;

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

    vector<int> p(n, -1);
    vector<ll> b(n);
    ll x = 0, y;
    int f, g;
    for (int k = 0;; k++) {
        int i = x % n;
        if (p[i] >= 0) {
            f = k - p[i];
            g = p[i];
            break;
        }
        p[i] = k;
        b[k] = x;
        x += a[i];
    }
    y = x - b[g];

    int q;
    cin >> q;

    while (q--) {
        ll k;
        cin >> k;

        ll r;
        if (k < g) {
            r = b[k];
        } else {
            k -= g;
            r = b[g + k % f] + y * (k / f);
        }
        cout << r << '\n';
    }

    return 0;
}
0