結果

問題 No.1013 〇マス進む
ユーザー hiromi_ayasehiromi_ayase
提出日時 2020-03-21 11:12:07
言語 Java21
(openjdk 21)
結果
AC  
実行時間 536 ms / 2,000 ms
コード長 3,102 bytes
コンパイル時間 4,363 ms
コンパイル使用メモリ 82,940 KB
実行使用メモリ 114,276 KB
最終ジャッジ日時 2023-08-23 08:04:33
合計ジャッジ時間 26,914 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
50,968 KB
testcase_01 AC 71 ms
49,160 KB
testcase_02 AC 69 ms
50,768 KB
testcase_03 AC 91 ms
51,536 KB
testcase_04 AC 79 ms
51,208 KB
testcase_05 AC 89 ms
51,224 KB
testcase_06 AC 89 ms
51,256 KB
testcase_07 AC 97 ms
51,368 KB
testcase_08 AC 90 ms
51,228 KB
testcase_09 AC 96 ms
51,308 KB
testcase_10 AC 95 ms
51,344 KB
testcase_11 AC 89 ms
51,368 KB
testcase_12 AC 95 ms
51,280 KB
testcase_13 AC 133 ms
55,996 KB
testcase_14 AC 337 ms
79,952 KB
testcase_15 AC 444 ms
89,204 KB
testcase_16 AC 417 ms
86,008 KB
testcase_17 AC 307 ms
73,264 KB
testcase_18 AC 348 ms
79,836 KB
testcase_19 AC 274 ms
69,928 KB
testcase_20 AC 447 ms
95,516 KB
testcase_21 AC 302 ms
71,296 KB
testcase_22 AC 360 ms
81,896 KB
testcase_23 AC 202 ms
62,184 KB
testcase_24 AC 442 ms
94,672 KB
testcase_25 AC 453 ms
95,544 KB
testcase_26 AC 210 ms
62,608 KB
testcase_27 AC 291 ms
68,776 KB
testcase_28 AC 207 ms
62,220 KB
testcase_29 AC 481 ms
95,824 KB
testcase_30 AC 279 ms
70,832 KB
testcase_31 AC 389 ms
85,260 KB
testcase_32 AC 329 ms
79,460 KB
testcase_33 AC 341 ms
79,796 KB
testcase_34 AC 435 ms
87,892 KB
testcase_35 AC 484 ms
88,772 KB
testcase_36 AC 147 ms
56,712 KB
testcase_37 AC 155 ms
56,564 KB
testcase_38 AC 497 ms
103,600 KB
testcase_39 AC 265 ms
65,692 KB
testcase_40 AC 502 ms
87,356 KB
testcase_41 AC 212 ms
61,828 KB
testcase_42 AC 336 ms
81,388 KB
testcase_43 AC 275 ms
65,984 KB
testcase_44 AC 345 ms
79,868 KB
testcase_45 AC 319 ms
72,244 KB
testcase_46 AC 238 ms
62,332 KB
testcase_47 AC 324 ms
72,128 KB
testcase_48 AC 361 ms
79,216 KB
testcase_49 AC 471 ms
87,356 KB
testcase_50 AC 417 ms
86,116 KB
testcase_51 AC 387 ms
82,028 KB
testcase_52 AC 175 ms
58,532 KB
testcase_53 AC 211 ms
61,280 KB
testcase_54 AC 421 ms
86,468 KB
testcase_55 AC 240 ms
62,404 KB
testcase_56 AC 496 ms
102,212 KB
testcase_57 AC 431 ms
83,688 KB
testcase_58 AC 536 ms
114,276 KB
testcase_59 AC 520 ms
112,252 KB
testcase_60 AC 531 ms
112,124 KB
testcase_61 AC 461 ms
112,004 KB
testcase_62 AC 446 ms
111,620 KB
testcase_63 AC 70 ms
50,980 KB
testcase_64 AC 72 ms
50,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

public class Main {

  private static void solve() {
    int n = ni();
    int k = ni();

    int[] p = na(n);

    int m = 32;
    int[][] lp = new int[m][n];
    long[][] lq = new long[m][n];

    for (int i = 0; i < n; i++) {
      lp[0][i] = (i + p[i]) % n;
      lq[0][i] = i + p[i] >= n ? 1 : 0;
    }

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

    for (int i = 0; i < n; i++) {
      int v = i;
      long u = 0;
      for (int j = m - 1; j >= 0; j--) {
        if (((k >> j) & 1) == 1) {
          u += lq[j][v];
          v = lp[j][v];
        }
      }
      out.println((long) v + u * n + 1);
    }
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}

0