結果

問題 No.1097 Remainder Operation
ユーザー SSRSSSRS
提出日時 2020-05-23 00:26:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 225 ms / 2,000 ms
コード長 816 bytes
コンパイル時間 1,697 ms
コンパイル使用メモリ 171,280 KB
実行使用メモリ 5,736 KB
最終ジャッジ日時 2024-05-02 05:14:48
合計ジャッジ時間 6,169 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 23 ms
5,376 KB
testcase_08 AC 23 ms
5,376 KB
testcase_09 AC 23 ms
5,376 KB
testcase_10 AC 23 ms
5,376 KB
testcase_11 AC 24 ms
5,376 KB
testcase_12 AC 222 ms
5,376 KB
testcase_13 AC 216 ms
5,376 KB
testcase_14 AC 222 ms
5,376 KB
testcase_15 AC 222 ms
5,376 KB
testcase_16 AC 221 ms
5,376 KB
testcase_17 AC 225 ms
5,376 KB
testcase_18 AC 216 ms
5,604 KB
testcase_19 AC 207 ms
5,736 KB
testcase_20 AC 205 ms
5,604 KB
testcase_21 AC 213 ms
5,732 KB
testcase_22 AC 214 ms
5,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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> S(1, 0);
  int c = 0;
  int l = 0;
  int curr = 0;
  while (1){
    if (ord[curr] == -1){
      ord[curr] = S.size() - 1;
      S.push_back(S.back() + A[curr]);
      curr = B[curr];
    } else {
      c = S.size() - ord[curr] - 1;
      l = ord[curr];
      break;
    }
  }
  int Q;
  cin >> Q;
  long long CS = S[l + c] - S[l];
  for (int i = 0; i < Q; i++){
    long long K;
    cin >> K;
    if (K <= l){
      cout << S[K] << endl;
    } else {
      cout << S[l] + (K - l) / c * CS + S[l + (K - l) % c] - S[l] << endl;
    }
  }
}
0