結果

問題 No.1097 Remainder Operation
ユーザー carrot46carrot46
提出日時 2020-06-26 21:42:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 776 ms / 2,000 ms
コード長 1,100 bytes
コンパイル時間 1,554 ms
コンパイル使用メモリ 169,468 KB
実行使用メモリ 90,204 KB
最終ジャッジ日時 2023-09-18 03:45:19
合計ジャッジ時間 9,959 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 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,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 41 ms
11,780 KB
testcase_08 AC 42 ms
12,036 KB
testcase_09 AC 40 ms
11,692 KB
testcase_10 AC 41 ms
11,800 KB
testcase_11 AC 41 ms
11,704 KB
testcase_12 AC 535 ms
89,668 KB
testcase_13 AC 529 ms
89,572 KB
testcase_14 AC 543 ms
89,616 KB
testcase_15 AC 619 ms
89,744 KB
testcase_16 AC 546 ms
89,584 KB
testcase_17 AC 482 ms
89,748 KB
testcase_18 AC 504 ms
89,576 KB
testcase_19 AC 479 ms
89,856 KB
testcase_20 AC 482 ms
90,204 KB
testcase_21 AC 771 ms
89,632 KB
testcase_22 AC 776 ms
89,584 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL<<58);

int main() {
    cin>>N;
    vec a(N);
    mat dbl(N, vec(50)), num(N, vec(50));
    rep(i,N) {
        cin >> a[i];
        dbl[i][0] = (i + a[i])%N;
        num[i][0] = (i + a[i]) / N;
    }
    reps(k, 1, 50){
        rep(i,N) {
            dbl[i][k] = dbl[dbl[i][k-1]][k-1];
            num[i][k] = num[i][k-1] + num[dbl[i][k-1]][k-1];
        }
    }
    cin>>Q;
    rep(_,Q){
        cin>>K;
        int now = 0;
        ll n = 0;
        Rrep(i,50){
            if((K>>i)&1){
                n += num[now][i];
                now = dbl[now][i];
            }
        }
        cout<<now + N * n<<endl;
    }
}
0