結果

問題 No.942 プレゼント配り
ユーザー neko_the_shadowneko_the_shadow
提出日時 2019-12-06 00:58:40
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,013 bytes
コンパイル時間 2,317 ms
コンパイル使用メモリ 75,316 KB
実行使用メモリ 115,604 KB
最終ジャッジ日時 2023-08-24 19:31:02
合計ジャッジ時間 6,893 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,708 KB
testcase_01 AC 333 ms
87,256 KB
testcase_02 AC 43 ms
49,568 KB
testcase_03 AC 43 ms
49,376 KB
testcase_04 AC 380 ms
64,280 KB
testcase_05 AC 590 ms
115,604 KB
testcase_06 AC 42 ms
49,364 KB
testcase_07 AC 42 ms
49,820 KB
testcase_08 AC 245 ms
60,628 KB
testcase_09 WA -
testcase_10 AC 42 ms
49,468 KB
testcase_11 AC 43 ms
49,572 KB
testcase_12 AC 42 ms
49,372 KB
testcase_13 AC 44 ms
49,424 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 43 ms
49,436 KB
testcase_19 AC 42 ms
49,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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 ((n * (n + 1) / 2) % k != 0) {
            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 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();
    }
}
0