結果

問題 No.1097 Remainder Operation
ユーザー ks2mks2m
提出日時 2020-06-26 22:06:25
言語 Java21
(openjdk 21)
結果
AC  
実行時間 776 ms / 2,000 ms
コード長 1,227 bytes
コンパイル時間 1,971 ms
コンパイル使用メモリ 74,172 KB
実行使用メモリ 131,232 KB
最終ジャッジ日時 2023-09-18 04:44:00
合計ジャッジ時間 12,265 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
49,628 KB
testcase_01 AC 41 ms
49,692 KB
testcase_02 AC 46 ms
49,560 KB
testcase_03 AC 45 ms
49,496 KB
testcase_04 AC 46 ms
49,492 KB
testcase_05 AC 46 ms
49,604 KB
testcase_06 AC 46 ms
49,408 KB
testcase_07 AC 186 ms
60,556 KB
testcase_08 AC 192 ms
60,756 KB
testcase_09 AC 183 ms
60,616 KB
testcase_10 AC 189 ms
60,676 KB
testcase_11 AC 182 ms
60,676 KB
testcase_12 AC 615 ms
113,744 KB
testcase_13 AC 635 ms
116,772 KB
testcase_14 AC 637 ms
117,736 KB
testcase_15 AC 706 ms
114,396 KB
testcase_16 AC 617 ms
114,060 KB
testcase_17 AC 566 ms
113,792 KB
testcase_18 AC 550 ms
129,176 KB
testcase_19 AC 586 ms
129,368 KB
testcase_20 AC 584 ms
129,608 KB
testcase_21 AC 721 ms
129,680 KB
testcase_22 AC 776 ms
131,232 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] sa = br.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}
		int q = Integer.parseInt(br.readLine());
		long[] k = new long[q];
		for (int i = 0; i < q; i++) {
			k[i] = Long.parseLong(br.readLine());
		}
		br.close();

		int m = 43;
		int[][] next = new int[m][n];
		long[][] val = new long[m][n];
		for (int i = 0; i < n; i++) {
			next[0][i] = (i + a[i]) % n;
			val[0][i] = a[i];
		}

		for (int i = 1; i < m; i++) {
			for (int j = 0; j < n; j++) {
				next[i][j] = next[i - 1][next[i - 1][j]];
				val[i][j] = val[i - 1][j] + val[i - 1][next[i - 1][j]];
			}
		}

		PrintWriter pw = new PrintWriter(System.out);
		for (int i = 0; i < q; i++) {
			int now = 0;
			long ans = 0;
			for (int j = m - 1; j >= 0; j--) {
				if ((k[i] >> j & 1) == 1) {
					ans += val[j][now];
					now = next[j][now];
				}
			}
			pw.println(ans);
		}
		pw.flush();
	}
}
0