結果

問題 No.1097 Remainder Operation
ユーザー SSRSSSRS
提出日時 2020-05-23 00:26:06
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 218 ms / 2,000 ms
コード長 816 bytes
コンパイル時間 1,534 ms
コンパイル使用メモリ 169,016 KB
実行使用メモリ 5,400 KB
最終ジャッジ日時 2023-08-14 17:09:00
合計ジャッジ時間 6,068 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 22 ms
4,376 KB
testcase_08 AC 21 ms
4,376 KB
testcase_09 AC 22 ms
4,376 KB
testcase_10 AC 21 ms
4,384 KB
testcase_11 AC 22 ms
4,376 KB
testcase_12 AC 207 ms
4,376 KB
testcase_13 AC 213 ms
4,380 KB
testcase_14 AC 209 ms
4,380 KB
testcase_15 AC 212 ms
4,380 KB
testcase_16 AC 212 ms
4,380 KB
testcase_17 AC 218 ms
4,376 KB
testcase_18 AC 196 ms
5,256 KB
testcase_19 AC 193 ms
5,236 KB
testcase_20 AC 199 ms
5,300 KB
testcase_21 AC 197 ms
5,400 KB
testcase_22 AC 201 ms
5,336 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