結果
問題 | No.942 プレゼント配り |
ユーザー | neko_the_shadow |
提出日時 | 2019-12-06 01:00:57 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,086 bytes |
コンパイル時間 | 2,799 ms |
コンパイル使用メモリ | 75,124 KB |
実行使用メモリ | 115,032 KB |
最終ジャッジ日時 | 2023-08-24 19:31:11 |
合計ジャッジ時間 | 8,238 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
49,576 KB |
testcase_01 | AC | 332 ms
87,320 KB |
testcase_02 | AC | 43 ms
49,540 KB |
testcase_03 | AC | 43 ms
49,496 KB |
testcase_04 | AC | 295 ms
60,980 KB |
testcase_05 | AC | 593 ms
115,032 KB |
testcase_06 | WA | - |
testcase_07 | AC | 43 ms
49,300 KB |
testcase_08 | AC | 251 ms
60,904 KB |
testcase_09 | AC | 258 ms
58,920 KB |
testcase_10 | AC | 43 ms
49,376 KB |
testcase_11 | AC | 42 ms
49,428 KB |
testcase_12 | AC | 42 ms
47,320 KB |
testcase_13 | AC | 43 ms
49,380 KB |
testcase_14 | WA | - |
testcase_15 | AC | 256 ms
60,664 KB |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | AC | 43 ms
49,484 KB |
testcase_19 | AC | 42 ms
49,392 KB |
ソースコード
package _0942; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class Main { public void solve(BufferedReader stdin, PrintWriter stdout) throws NumberFormatException, IOException { String[] line = stdin.readLine().split(" "); int n = Integer.parseInt(line[0]); int k = Integer.parseInt(line[1]); if (!ok(n, k)) { stdout.println("No"); return; } int m = n / k; List<List<Integer>> matrix = new ArrayList<>(); for (int i = 0; i < m; i++) { matrix.add(new ArrayList<>()); } for (int i = 0; i < n; i++) { matrix.get(i / k).add(i + 1); } if (m % 2 == 0) { for (int i = m / 2; i < m; i++) { Collections.reverse(matrix.get(i)); } } else { int x = 0; for (int i = 0; i < m; i++) { List<Integer> r1 = matrix.get(i).subList(0, x); List<Integer> r2 = matrix.get(i).subList(x, k); matrix.set(i, new ArrayList<>()); matrix.get(i).addAll(r2); matrix.get(i).addAll(r1); x = (x + 1) % k; } } stdout.println("Yes"); for (int i = 0; i < k; i++) { List<String> ans = new ArrayList<>(); for (int j = 0; j < m; j++) { ans.add(Integer.toString(matrix.get(j).get(i))); } stdout.println(String.join(" ", ans)); } } public boolean ok(long n, long k) { return (n * (n + 1) / 2) % k == 0; } public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); PrintWriter stdout = new PrintWriter(System.out, false); new Main().solve(stdin, stdout); stdout.flush(); } }