結果

問題 No.942 プレゼント配り
ユーザー neko_the_shadowneko_the_shadow
提出日時 2019-12-06 01:00:57
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,086 bytes
コンパイル時間 2,129 ms
コンパイル使用メモリ 78,988 KB
実行使用メモリ 99,852 KB
最終ジャッジ日時 2024-06-02 09:01:29
合計ジャッジ時間 7,522 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
36,752 KB
testcase_01 AC 357 ms
76,260 KB
testcase_02 AC 47 ms
36,932 KB
testcase_03 AC 47 ms
37,028 KB
testcase_04 AC 252 ms
52,264 KB
testcase_05 AC 491 ms
99,852 KB
testcase_06 WA -
testcase_07 AC 45 ms
36,932 KB
testcase_08 AC 251 ms
50,672 KB
testcase_09 AC 260 ms
50,880 KB
testcase_10 AC 46 ms
36,596 KB
testcase_11 AC 46 ms
36,856 KB
testcase_12 AC 45 ms
36,972 KB
testcase_13 AC 44 ms
36,776 KB
testcase_14 WA -
testcase_15 AC 208 ms
50,224 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 46 ms
36,932 KB
testcase_19 AC 44 ms
36,932 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 (!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();
    }
}
0