結果

問題 No.1097 Remainder Operation
ユーザー simansiman
提出日時 2023-03-16 19:20:13
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 456 ms / 2,000 ms
コード長 940 bytes
コンパイル時間 4,308 ms
コンパイル使用メモリ 131,324 KB
実行使用メモリ 36,248 KB
最終ジャッジ日時 2023-10-18 13:08:55
合計ジャッジ時間 10,429 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 32 ms
6,716 KB
testcase_08 AC 32 ms
6,716 KB
testcase_09 AC 33 ms
6,716 KB
testcase_10 AC 33 ms
6,716 KB
testcase_11 AC 32 ms
6,716 KB
testcase_12 AC 385 ms
36,248 KB
testcase_13 AC 368 ms
36,248 KB
testcase_14 AC 397 ms
36,248 KB
testcase_15 AC 384 ms
36,248 KB
testcase_16 AC 398 ms
36,248 KB
testcase_17 AC 339 ms
36,248 KB
testcase_18 AC 294 ms
36,248 KB
testcase_19 AC 401 ms
36,248 KB
testcase_20 AC 369 ms
36,248 KB
testcase_21 AC 456 ms
36,248 KB
testcase_22 AC 451 ms
36,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
  ll N;
  cin >> N;
  ll A[N];
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }

  ll memo[N + 1][41];
  for (int x = 0; x < N; ++x) {
    int r = x % N;
    memo[x][0] = x + A[r];
  }

  for (int step = 1; step <= 40; ++step) {
    for (int i = 0; i < N; ++i) {
      ll x = memo[i][step - 1];
      ll d = x / N;
      ll r = x % N;
      memo[i][step] = d * N + memo[r][step - 1];
    }
  }

  int Q;
  cin >> Q;
  for (int i = 0; i < Q; ++i) {
    ll k;
    cin >> k;
    ll X = 0;

    for (int d = 0; d < 40; ++d) {
      if (k >> d & 1) {
        ll v = X / N;
        ll r = X % N;
        X = v * N + memo[r][d];
      }
    }

    cout << X << endl;
  }

  return 0;
}
0