結果

問題 No.942 プレゼント配り
ユーザー neko_the_shadowneko_the_shadow
提出日時 2019-12-06 01:17:08
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,080 bytes
コンパイル時間 3,070 ms
コンパイル使用メモリ 75,124 KB
実行使用メモリ 115,332 KB
最終ジャッジ日時 2023-08-24 19:31:49
合計ジャッジ時間 7,192 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 332 ms
87,036 KB
testcase_02 AC 43 ms
49,484 KB
testcase_03 AC 42 ms
49,540 KB
testcase_04 AC 308 ms
63,688 KB
testcase_05 AC 590 ms
115,332 KB
testcase_06 AC 42 ms
49,408 KB
testcase_07 AC 42 ms
48,056 KB
testcase_08 AC 233 ms
58,136 KB
testcase_09 AC 257 ms
58,984 KB
testcase_10 AC 42 ms
49,556 KB
testcase_11 AC 43 ms
49,496 KB
testcase_12 AC 43 ms
49,484 KB
testcase_13 AC 43 ms
49,436 KB
testcase_14 WA -
testcase_15 AC 204 ms
57,664 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 43 ms
49,520 KB
testcase_19 AC 42 ms
49,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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 != k && (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();
    }
}
0