結果

問題 No.1097 Remainder Operation
ユーザー Y17Y17
提出日時 2020-06-26 23:01:15
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 371 ms / 2,000 ms
コード長 875 bytes
コンパイル時間 2,253 ms
コンパイル使用メモリ 165,448 KB
実行使用メモリ 160,436 KB
最終ジャッジ日時 2023-09-18 07:08:57
合計ジャッジ時間 8,405 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,988 KB
testcase_01 AC 2 ms
4,992 KB
testcase_02 AC 3 ms
4,992 KB
testcase_03 AC 2 ms
5,060 KB
testcase_04 AC 2 ms
5,060 KB
testcase_05 AC 2 ms
4,996 KB
testcase_06 AC 3 ms
4,992 KB
testcase_07 AC 37 ms
19,784 KB
testcase_08 AC 40 ms
23,744 KB
testcase_09 AC 45 ms
23,636 KB
testcase_10 AC 45 ms
76,692 KB
testcase_11 AC 45 ms
76,972 KB
testcase_12 AC 371 ms
160,376 KB
testcase_13 AC 341 ms
160,388 KB
testcase_14 AC 350 ms
160,356 KB
testcase_15 AC 356 ms
160,356 KB
testcase_16 AC 352 ms
160,412 KB
testcase_17 AC 308 ms
160,372 KB
testcase_18 AC 260 ms
160,436 KB
testcase_19 AC 281 ms
160,360 KB
testcase_20 AC 280 ms
160,356 KB
testcase_21 AC 363 ms
160,368 KB
testcase_22 AC 357 ms
160,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int dbl1[100][100010];
int dbl2[100][100010];

signed main(){
	int n;
	cin >> n;

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

	for(int i = 0;i < n;i++){
		dbl1[0][i] = (i+a[i])%n;
		dbl2[0][i] = a[i]; 
	}

	for(int b = 1;b < 100;b++){
		for(int i = 0;i < n;i++){
			int nxt = dbl1[b-1][i];
			dbl1[b][i] = dbl1[b-1][nxt];
			dbl2[b][i] = dbl2[b-1][i] + dbl2[b-1][nxt];
		}
	}


	int q;
	cin >> q;
	while(q--){
		int k;
		cin >> k;
		int now = 0;
		int ans = 0;
		for(int i = 0;i < 63;i++){
			if(k & (1ll << i)){
				ans += dbl2[i][now];
				now = dbl1[i][now];
			}
		}
		cout << ans << endl;
	}

	return 0;
}
0