結果

問題 No.1097 Remainder Operation
ユーザー Manuel1024Manuel1024
提出日時 2021-04-15 19:19:48
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,239 bytes
コンパイル時間 669 ms
コンパイル使用メモリ 71,348 KB
実行使用メモリ 5,708 KB
最終ジャッジ日時 2023-09-14 21:10:05
合計ジャッジ時間 6,193 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
using ll = long long int;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(auto &p: a) cin >> p;
    int q;
    cin >> q;
    vector<int> k(q);
    for(auto &p: k) cin >> p;

    vector<int> order(n+10, -1);
    vector<ll> x(n+10, 0);
    ll loopstart, loopend, mod, prenum;
    for(int i = 1, r = 0; ; i++){
        order[r] = i;
        x[i] = x[i-1] + a[r];
        int prevr = r;
        r = x[i]%n;
        if(order[r] != -1){
            loopstart = order[r];
            loopend = order[prevr];
            prenum = order[r]-1;
            mod = loopend - loopstart + 1;
            //cerr << loopstart << " " << loopend << endl;
            break;
        }
    }

    vector<ll> loopsum(mod+1);
    for(int i = 0; i < mod; i++) loopsum[i] = x[i+loopstart]-x[loopstart-1];

    for(auto &p: k){
        if(p < loopstart) cout << x[p] << endl;
        else{
            ll ans = x[loopstart-1];
            ll loopcnt = (p-loopstart+1)/mod;
            ll loopind = (p-loopstart+1)%mod -1;
            ans += loopcnt * loopsum[mod-1];
            if(loopind != -1) ans += loopsum[loopind];
            cout << ans << endl;
        }
    }
    return 0;
}
0