結果

問題 No.1097 Remainder Operation
ユーザー CleyLCleyL
提出日時 2022-10-15 15:13:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 242 ms / 2,000 ms
コード長 1,097 bytes
コンパイル時間 817 ms
コンパイル使用メモリ 85,164 KB
実行使用メモリ 9,672 KB
最終ジャッジ日時 2023-09-09 02:39:46
合計ジャッジ時間 5,443 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 22 ms
4,380 KB
testcase_08 AC 22 ms
4,380 KB
testcase_09 AC 22 ms
4,380 KB
testcase_10 AC 21 ms
4,380 KB
testcase_11 AC 22 ms
4,376 KB
testcase_12 AC 213 ms
4,380 KB
testcase_13 AC 216 ms
4,376 KB
testcase_14 AC 215 ms
4,380 KB
testcase_15 AC 215 ms
4,376 KB
testcase_16 AC 212 ms
4,380 KB
testcase_17 AC 217 ms
4,380 KB
testcase_18 AC 240 ms
9,672 KB
testcase_19 AC 239 ms
9,672 KB
testcase_20 AC 239 ms
9,436 KB
testcase_21 AC 242 ms
9,504 KB
testcase_22 AC 237 ms
9,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <set>
#include <vector>
using namespace std;
int main(){
  int n;cin>>n;
  vector<long long> A(n);
  for(int i = 0; n > i; i++){
    cin>>A[i];
  }
  vector<long long> pre;
  vector<long long> circle;
  set<int> B;
  long long nw = 0;
  B.insert(nw);
  while(true){
    nw = (nw+A[nw])%n;
    if(B.count(nw)){
      break;
    }
    B.insert(nw);
  }
  long long nw2 = 0;
  while(nw2 != nw){
    if(nw2)pre.push_back(pre[pre.size()-1]+A[nw2]);
    else pre.push_back(A[nw2]);
    nw2 = (nw2+A[nw2])%n;
  }
  circle.push_back(A[nw2]);
  nw2 = (nw2+A[nw2])%n;
  while(nw2 != nw){
    circle.push_back(circle[circle.size()-1]+A[nw2]);
    nw2 = (nw2+A[nw2])%n;
  }

  int q;cin>>q;
  for(int i = 0; q > i; i++){
    long long x;cin>>x;
    if(pre.size() >= x){
      cout << pre[x-1] << endl;
    }else{
      long long ans = 0;
      if(pre.size())ans += pre[pre.size()-1];
      ans += (x-pre.size())/circle.size()*circle[circle.size()-1];
      if((x-pre.size())%circle.size() != 0)ans += circle[(x-pre.size()-1)%circle.size()];
      cout << ans << endl;
    }
  }
}
0