結果
| 問題 |
No.1097 Remainder Operation
|
| コンテスト | |
| ユーザー |
SSRS
|
| 提出日時 | 2020-05-24 20:47:39 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 229 ms / 2,000 ms |
| コード長 | 816 bytes |
| コンパイル時間 | 1,717 ms |
| コンパイル使用メモリ | 172,640 KB |
| 実行使用メモリ | 5,736 KB |
| 最終ジャッジ日時 | 2024-11-22 16:12:06 |
| 合計ジャッジ時間 | 6,043 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 21 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++){
cin >> A[i];
}
vector<int> B(N);
for (int i = 0; i < N; i++){
B[i] = (i + A[i]) % N;
}
vector<int> ord(N, -1);
vector<long long> X(1, 0);
int c = 0;
int l = 0;
int curr = 0;
while (1){
if (ord[curr] == -1){
ord[curr] = X.size() - 1;
X.push_back(X.back() + A[curr]);
curr = B[curr];
} else {
c = X.size() - ord[curr] - 1;
l = ord[curr];
break;
}
}
int Q;
cin >> Q;
long long CS = X[l + c] - X[l];
for (int i = 0; i < Q; i++){
long long K;
cin >> K;
if (K <= l){
cout << X[K] << endl;
} else {
cout << X[l] + (K - l) / c * CS + X[l + (K - l) % c] - X[l] << endl;
}
}
}
SSRS