結果

問題 No.1097 Remainder Operation
ユーザー cn_449cn_449
提出日時 2020-06-26 21:48:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 1,750 bytes
コンパイル時間 1,191 ms
コンパイル使用メモリ 113,412 KB
実行使用メモリ 5,740 KB
最終ジャッジ日時 2023-09-18 04:05:59
合計ジャッジ時間 3,717 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 5 ms
4,380 KB
testcase_08 AC 4 ms
4,384 KB
testcase_09 AC 5 ms
4,380 KB
testcase_10 AC 5 ms
4,376 KB
testcase_11 AC 4 ms
4,380 KB
testcase_12 AC 35 ms
4,700 KB
testcase_13 AC 35 ms
4,676 KB
testcase_14 AC 35 ms
4,548 KB
testcase_15 AC 35 ms
4,664 KB
testcase_16 AC 36 ms
4,596 KB
testcase_17 AC 37 ms
4,692 KB
testcase_18 AC 35 ms
5,588 KB
testcase_19 AC 35 ms
5,628 KB
testcase_20 AC 35 ms
5,740 KB
testcase_21 AC 36 ms
5,740 KB
testcase_22 AC 35 ms
5,572 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	vector<ll> vis(n, -1);
	vector<ll> num;
	ll now = 0; ll per = 0, pl = 0;
	while (true) {
		if (vis[now % n] != -1) {
			per = num.size() - vis[now % n];
			pl = now - num[vis[now % n]];
			break;
		}
		vis[now % n] = num.size();
		num.pb(now);
		now += a[now % n];
	}
	ll bor = num.size() - 1;
	int q;
	cin >> q;
	while (q--) {
		ll k;
		cin >> k;
		if (k <= bor) cout << num[k] << '\n';
		else {
			ll dif = (k - bor - 1) / per + 1;
			cout << dif * pl + num[k - dif * per] << '\n';
		}
	}
}
0