結果

問題 No.1097 Remainder Operation
ユーザー hedwig100hedwig100
提出日時 2020-08-16 18:45:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 372 ms / 2,000 ms
コード長 1,177 bytes
コンパイル時間 1,541 ms
コンパイル使用メモリ 172,404 KB
実行使用メモリ 69,376 KB
最終ジャッジ日時 2024-04-19 18:28:29
合計ジャッジ時間 6,559 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 18 ms
9,728 KB
testcase_08 AC 18 ms
9,856 KB
testcase_09 AC 17 ms
9,856 KB
testcase_10 AC 17 ms
9,728 KB
testcase_11 AC 17 ms
9,856 KB
testcase_12 AC 237 ms
69,244 KB
testcase_13 AC 248 ms
69,192 KB
testcase_14 AC 263 ms
69,344 KB
testcase_15 AC 324 ms
69,248 KB
testcase_16 AC 253 ms
69,248 KB
testcase_17 AC 199 ms
69,188 KB
testcase_18 AC 228 ms
69,376 KB
testcase_19 AC 245 ms
69,120 KB
testcase_20 AC 241 ms
69,372 KB
testcase_21 AC 372 ms
69,312 KB
testcase_22 AC 372 ms
69,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

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

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

    vector<vector<int>> go(N,vector<int>(50));
    vector<vector<ll>> val(N,vector<ll>(50));
    rep(i,N) {
        go[i][0] = (i + A[i])%N;
        val[i][0] = A[i];
    }
    rep(i,49) {
        rep(j,N) {
            go[j][i + 1] = go[go[j][i]][i];
            val[j][i + 1] = val[j][i] + val[go[j][i]][i];
        }
    }

    int Q; cin >> Q;
    rep(i,Q) {
        ll K; cin >> K;
        ll ret = 0;
        int x = 0;
        rep(j,50) {
            if ((K>>j)&1) {
                ret += val[x][j];
                x = go[x][j];
            }
        }
        cout << ret << '\n';
    }
    return 0;
}
0