結果

問題 No.942 プレゼント配り
ユーザー neko_the_shadow
提出日時 2019-12-05 22:11:21
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,793 bytes
コンパイル時間 2,709 ms
コンパイル使用メモリ 94,496 KB
実行使用メモリ 80,116 KB
最終ジャッジ日時 2024-12-23 01:23:42
合計ジャッジ時間 8,677 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 13 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

package _0942;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

public class Main {
    public void solve(BufferedReader stdin, PrintWriter stdout) throws NumberFormatException, IOException {
        String[] line = stdin.readLine().split(" ");
        BigInteger n = new BigInteger(line[0]);
        BigInteger k = new BigInteger(line[1]);

        // (n * (n + 1) / 2) % k == 0
        if (!n.multiply(n.add(BigInteger.ONE)).divide(BigInteger.valueOf(2L)).remainder(k).equals(BigInteger.ZERO)) {
            stdout.println("No");
            return ;
        }

        List<List<Long>> matrix = new ArrayList<>();
        for (int i = 0; i < k.intValue(); i++) {
            matrix.add(new ArrayList<>());
        }

        int x = 0;
        int dx = 1;
        for (long i = 1; i <= n.longValue(); i++) {
            matrix.get(x).add(i);
            x += dx;
            if (x == -1) {
                x = 0;
                dx = 1;
            }

            if (x == k.longValue()) {
                x = k.intValue() - 1;
                dx = -1;
            }
        }

        stdout.println("Yes");
        for (List<Long> row : matrix) {
            stdout.println(row.stream().map(Objects::toString).collect(Collectors.joining(" ")));
        }
    }

    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