結果

問題 No.1097 Remainder Operation
ユーザー mikianaaamikianaaa
提出日時 2020-09-24 16:19:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,275 bytes
コンパイル時間 1,581 ms
コンパイル使用メモリ 174,652 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-10 13:30:28
合計ジャッジ時間 5,908 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

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

    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) { cin >> A[i]; }

    ll X = 0;
    map<ll, bool> ma1, ma2;
    ll cnt = 0, e = 0;
    bool judge = 0;
    vector<ll> v, vv;
    while (1) {
        ll r = X % N;
        if (ma1[A[r]]) {
            judge = 1;
        }
        if (ma2[A[r]]) {
            break;
        }
        if (!judge)
            ma1[A[r]] = true, v.push_back(A[r]);
        if (judge)
            ma2[A[r]] = true, vv.push_back(A[r]);
        X += A[r];
    }

    rep(i, v.size() - 1) { v[i + 1] += v[i]; }

    rep(i, vv.size()) { vv[i + 1] += vv[i]; }

    int Q;
    cin >> Q;
    rep(i, Q) {
        ll q;
        cin >> q;
        q--;
        if (q < (ll)v.size()) {
            cout << v[q] << endl;
        } else {
            ll ans = v.back();
            q -= (ll)v.size();
            ans += (q / (ll)vv.size()) * vv.back() + vv[q % (ll)vv.size()];
            cout << ans << endl;
        }
    }
}
0