結果

問題 No.1097 Remainder Operation
ユーザー e869120e869120
提出日時 2020-06-26 21:36:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 217 ms / 2,000 ms
コード長 901 bytes
コンパイル時間 1,146 ms
コンパイル使用メモリ 84,172 KB
実行使用メモリ 6,888 KB
最終ジャッジ日時 2023-09-18 03:23:58
合計ジャッジ時間 5,084 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,396 KB
testcase_01 AC 2 ms
5,452 KB
testcase_02 AC 2 ms
5,524 KB
testcase_03 AC 2 ms
5,400 KB
testcase_04 AC 2 ms
5,604 KB
testcase_05 AC 2 ms
5,464 KB
testcase_06 AC 2 ms
5,540 KB
testcase_07 AC 22 ms
5,484 KB
testcase_08 AC 22 ms
5,548 KB
testcase_09 AC 22 ms
5,552 KB
testcase_10 AC 22 ms
5,528 KB
testcase_11 AC 23 ms
5,608 KB
testcase_12 AC 213 ms
6,184 KB
testcase_13 AC 209 ms
6,308 KB
testcase_14 AC 210 ms
6,184 KB
testcase_15 AC 210 ms
6,196 KB
testcase_16 AC 208 ms
6,184 KB
testcase_17 AC 217 ms
6,176 KB
testcase_18 AC 197 ms
6,852 KB
testcase_19 AC 205 ms
6,888 KB
testcase_20 AC 196 ms
6,888 KB
testcase_21 AC 199 ms
6,852 KB
testcase_22 AC 205 ms
6,884 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <map>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

long long N, Q, K;
long long A[1 << 18];
long long used[1 << 18];

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i];
	for (int i = 0; i < N; i++) used[i] = -1;

	vector<long long> v1; long long cx = 0, cnt = 0, pre = 0;
	while (true) {
		v1.push_back(cx); used[cx % N] = cnt;
		cx += A[cx % N]; cnt += 1;
		if (used[cx % N] != -1) {
			pre = used[cx % N];
			break;
		}
	}

	cin >> Q;
	for (int i = 1; i <= Q; i++) {
		cin >> K;
		if (K < pre) {
			cout << v1[K] << endl;
		}
		else {
			long long E1 = ((K - pre) / (long long)(v1.size() - pre));
			long long E2 = ((K - pre) % (long long)(v1.size() - pre));
			cout << E1 * (cx - v1[pre]) + v1[E2 + pre] << endl;
		}
	}
	return 0;
}
0