結果
問題 | No.1013 〇マス進む |
ユーザー | tenten |
提出日時 | 2023-06-08 13:05:41 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 441 ms / 2,000 ms |
コード長 | 2,532 bytes |
コンパイル時間 | 2,332 ms |
コンパイル使用メモリ | 91,904 KB |
実行使用メモリ | 109,552 KB |
最終ジャッジ日時 | 2024-06-09 20:11:07 |
合計ジャッジ時間 | 20,494 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 60 ms
50,568 KB |
testcase_01 | AC | 60 ms
50,948 KB |
testcase_02 | AC | 58 ms
50,596 KB |
testcase_03 | AC | 66 ms
51,232 KB |
testcase_04 | AC | 62 ms
51,212 KB |
testcase_05 | AC | 65 ms
51,020 KB |
testcase_06 | AC | 63 ms
51,260 KB |
testcase_07 | AC | 69 ms
51,368 KB |
testcase_08 | AC | 67 ms
51,332 KB |
testcase_09 | AC | 70 ms
51,372 KB |
testcase_10 | AC | 69 ms
51,376 KB |
testcase_11 | AC | 66 ms
51,224 KB |
testcase_12 | AC | 72 ms
51,604 KB |
testcase_13 | AC | 98 ms
54,304 KB |
testcase_14 | AC | 254 ms
78,316 KB |
testcase_15 | AC | 330 ms
92,076 KB |
testcase_16 | AC | 308 ms
89,132 KB |
testcase_17 | AC | 259 ms
75,984 KB |
testcase_18 | AC | 300 ms
78,576 KB |
testcase_19 | AC | 214 ms
66,756 KB |
testcase_20 | AC | 367 ms
106,996 KB |
testcase_21 | AC | 242 ms
73,780 KB |
testcase_22 | AC | 290 ms
79,112 KB |
testcase_23 | AC | 179 ms
62,904 KB |
testcase_24 | AC | 417 ms
107,208 KB |
testcase_25 | AC | 362 ms
106,992 KB |
testcase_26 | AC | 167 ms
62,844 KB |
testcase_27 | AC | 232 ms
76,084 KB |
testcase_28 | AC | 170 ms
62,824 KB |
testcase_29 | AC | 361 ms
104,328 KB |
testcase_30 | AC | 227 ms
69,480 KB |
testcase_31 | AC | 302 ms
82,260 KB |
testcase_32 | AC | 263 ms
76,352 KB |
testcase_33 | AC | 262 ms
78,040 KB |
testcase_34 | AC | 319 ms
94,008 KB |
testcase_35 | AC | 326 ms
92,244 KB |
testcase_36 | AC | 122 ms
55,048 KB |
testcase_37 | AC | 126 ms
54,556 KB |
testcase_38 | AC | 342 ms
99,340 KB |
testcase_39 | AC | 213 ms
65,464 KB |
testcase_40 | AC | 351 ms
100,512 KB |
testcase_41 | AC | 181 ms
62,908 KB |
testcase_42 | AC | 271 ms
76,128 KB |
testcase_43 | AC | 216 ms
66,248 KB |
testcase_44 | AC | 301 ms
78,228 KB |
testcase_45 | AC | 260 ms
75,896 KB |
testcase_46 | AC | 183 ms
63,004 KB |
testcase_47 | AC | 266 ms
76,352 KB |
testcase_48 | AC | 294 ms
77,708 KB |
testcase_49 | AC | 355 ms
100,624 KB |
testcase_50 | AC | 329 ms
85,420 KB |
testcase_51 | AC | 308 ms
80,140 KB |
testcase_52 | AC | 151 ms
58,308 KB |
testcase_53 | AC | 169 ms
60,852 KB |
testcase_54 | AC | 323 ms
90,192 KB |
testcase_55 | AC | 172 ms
63,260 KB |
testcase_56 | AC | 441 ms
102,916 KB |
testcase_57 | AC | 325 ms
82,080 KB |
testcase_58 | AC | 409 ms
109,364 KB |
testcase_59 | AC | 389 ms
109,416 KB |
testcase_60 | AC | 400 ms
109,552 KB |
testcase_61 | AC | 369 ms
107,864 KB |
testcase_62 | AC | 349 ms
107,128 KB |
testcase_63 | AC | 59 ms
50,720 KB |
testcase_64 | AC | 58 ms
50,836 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int k = sc.nextInt(); long[][] values = new long[30][n]; int[][] nexts = new int[30][n]; int[] idxes = new int[n]; long[] ans = new long[n]; for (int i = 0; i < n; i++) { int x = sc.nextInt(); nexts[0][i] = (i + x) % n; values[0][i] = x; idxes[i] = i; ans[i] = i + 1; } for (int i = 1; i < 30; i++) { for (int j = 0; j < n; j++) { nexts[i][j] = nexts[i - 1][nexts[i - 1][j]]; values[i][j] = values[i - 1][j] + values[i - 1][nexts[i - 1][j]]; } } for (int i = 29; i >= 0; i--) { if (k < (1 << i)) { continue; } k -= (1 << i); int[] pidxes = new int[n]; for (int j = 0; j < n; j++) { ans[j] += values[i][idxes[j]]; idxes[j] = nexts[i][idxes[j]]; } } System.out.println(String.join("\n", Arrays.stream(ans).mapToObj(String::valueOf).toArray(String[]::new))); } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }