結果

問題 No.1097 Remainder Operation
ユーザー okok
提出日時 2020-06-26 22:31:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 253 ms / 2,000 ms
コード長 1,129 bytes
コンパイル時間 865 ms
コンパイル使用メモリ 88,452 KB
実行使用メモリ 75,280 KB
最終ジャッジ日時 2023-09-18 05:57:15
合計ジャッジ時間 4,659 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 13 ms
10,192 KB
testcase_08 AC 14 ms
10,140 KB
testcase_09 AC 13 ms
10,228 KB
testcase_10 AC 13 ms
10,128 KB
testcase_11 AC 13 ms
10,172 KB
testcase_12 AC 148 ms
75,128 KB
testcase_13 AC 159 ms
75,100 KB
testcase_14 AC 166 ms
75,216 KB
testcase_15 AC 192 ms
75,100 KB
testcase_16 AC 156 ms
75,088 KB
testcase_17 AC 109 ms
75,092 KB
testcase_18 AC 99 ms
75,152 KB
testcase_19 AC 132 ms
75,280 KB
testcase_20 AC 131 ms
75,096 KB
testcase_21 AC 250 ms
75,200 KB
testcase_22 AC 253 ms
75,188 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

signed main(){
	cout<<fixed<<setprecision(10);
	
	int N, Q;
	vector<int> A;
	vector<vector<int>> table, table2;
	
	
	cin>>N;
	
	A.resize(N);
	table.resize(45, vector<int>(N));
	table2.resize(45, vector<int>(N));
	
	for(int i = 0; i < N; i++){
		cin>>A[i];
		
		table[0][i] = (A[i] + i)% N;
		table2[0][i] = A[i];
	}
	
	for(int i = 1; i < table.size(); i++){
		for(int j = 0; j < N; j++){
			table[i][j] = table[i-1][table[i-1][j]];
			table2[i][j] = table2[i-1][table[i-1][j]] + table2[i-1][j];
		}
	}
	
	cin>>Q;
	
	for(int i = 0; i < Q; i++){
		int K;
		int res = 0, now = 0;
		
		cin>>K;
		
		for(int i = 0; i < table.size(); i++){
			if((K>>i)&1) {
				res += table2[i][now];
				now = table[i][now];
			}
		}
		
		cout<<res<<endl;
	}
	
	return 0;
}
0