結果

問題 No.1097 Remainder Operation
ユーザー nanophoto12nanophoto12
提出日時 2020-06-27 11:00:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 217 ms / 2,000 ms
コード長 1,244 bytes
コンパイル時間 2,375 ms
コンパイル使用メモリ 202,052 KB
実行使用メモリ 6,680 KB
最終ジャッジ日時 2023-09-18 19:14:36
合計ジャッジ時間 6,519 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 22 ms
4,376 KB
testcase_08 AC 22 ms
4,380 KB
testcase_09 AC 22 ms
4,380 KB
testcase_10 AC 21 ms
4,376 KB
testcase_11 AC 22 ms
4,380 KB
testcase_12 AC 210 ms
6,356 KB
testcase_13 AC 212 ms
6,440 KB
testcase_14 AC 213 ms
6,496 KB
testcase_15 AC 214 ms
6,680 KB
testcase_16 AC 213 ms
6,492 KB
testcase_17 AC 217 ms
6,356 KB
testcase_18 AC 203 ms
6,488 KB
testcase_19 AC 201 ms
6,544 KB
testcase_20 AC 201 ms
6,676 KB
testcase_21 AC 202 ms
6,644 KB
testcase_22 AC 201 ms
6,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

using namespace std;

static const ll INF = 1e15;

const ll mod = 1000000007;

int main() {
	int n;
	cin >> n;
	vector<ll> vs(n);
	rep(i, n) cin >> vs[i];
	vector<ll> x(n+1, 0);
	vector<ll> prevIndex(n, -1);
	prevIndex[0] = 0;
	ll loop = 0;
	ll loopUnit = 0;
	ll loopStart = 0;
	ll loopEnd = 0;
	for (int i = 1; i <= n+1; i++) {
		ll r = x[i-1] + vs[x[i-1] % n];
		x[i] = r;
		if (prevIndex[x[i] % n] != -1) {
			loopStart = prevIndex[x[i] % n];
			loopEnd = i;
			loop = loopEnd - loopStart;
			loopUnit = x[loopEnd] - x[loopStart];
			break;
		}
		prevIndex[x[i] % n] = i;
	}
	int q;
	cin >> q;
	vector<ll> ans;
	rep(_, q) {
		ll k;
		cin >> k;
		if (k <= loopEnd) {
			ans.push_back(x[k]);
			continue;
		}
		ans.push_back(x[(k - loopStart) % loop + loopStart] + (k-loopStart)/loop * loopUnit);
	}
	rep(i, q) {
		cout << ans[i] << endl;
	}
	return 0;
}
0