結果
| 問題 | No.1097 Remainder Operation |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-06-26 21:54:20 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 148 ms / 2,000 ms |
| コード長 | 1,045 bytes |
| 記録 | |
| コンパイル時間 | 1,598 ms |
| コンパイル使用メモリ | 174,544 KB |
| 実行使用メモリ | 51,892 KB |
| 最終ジャッジ日時 | 2024-07-04 20:55:58 |
| 合計ジャッジ時間 | 4,929 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 21 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr char newl = '\n';
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<ll> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector< vector<int> > nex(40, vector<int>(n, -1));
vector< vector<ll> > sum(40, vector<ll>(n, 0));
for (int i = 0; i < n; i++) {
nex[0][i] = (i + a[i]) % n;
sum[0][i] = a[i];
}
for (int i = 1; i < 40; i++) {
for (int j = 0; j < n; j++) {
nex[i][j] = nex[i - 1][nex[i - 1][j]];
sum[i][j] = sum[i - 1][nex[i - 1][j]] + sum[i - 1][j];
}
}
int q;
cin >> q;
for (int i = 0; i < q; i++) {
ll K;
cin >> K;
int cur = 0;
ll ans = 0;
for (int i = 0; i < 40; i++) {
if (K >> i & 1) {
ans += sum[i][cur];
cur = nex[i][cur];
}
}
cout << ans << newl;
}
return 0;
}