結果
問題 |
No.1013 〇マス進む
|
ユーザー |
![]() |
提出日時 | 2020-03-24 15:29:30 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 1,204 ms / 2,000 ms |
コード長 | 1,041 bytes |
コンパイル時間 | 2,130 ms |
コンパイル使用メモリ | 77,336 KB |
実行使用メモリ | 113,196 KB |
最終ジャッジ日時 | 2024-12-31 15:06:32 |
合計ジャッジ時間 | 43,025 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 62 |
ソースコード
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int k = sc.nextInt(); int[] arr = new int[n]; long[][] answers = new long[n][31]; for (int i = 0; i < n; i++) { arr[i] = sc.nextInt(); answers[i][0] = arr[i]; } for (int i = 1; i < 31; i++) { for (int j = 0; j < n; j++) { answers[j][i] = answers[j][i - 1] + answers[(int)((j + answers[j][i - 1]) % n)][i - 1]; } } StringBuilder sb = new StringBuilder(); for (int i = 0; i < n; i++) { int x = k; long ans = i; for (int j = 30; j >= 0; j--) { if (x >= (1 << j)) { ans += answers[(int)(ans % n)][j]; x -= (1 << j); } } ans++; sb.append(ans).append("\n"); } System.out.print(sb); } }