結果

問題 No.942 プレゼント配り
ユーザー ks2mks2m
提出日時 2019-12-05 00:56:28
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 951 bytes
コンパイル時間 4,114 ms
コンパイル使用メモリ 78,780 KB
実行使用メモリ 91,836 KB
最終ジャッジ日時 2023-08-21 08:35:37
合計ジャッジ時間 10,495 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
54,428 KB
testcase_01 AC 258 ms
66,224 KB
testcase_02 AC 123 ms
55,992 KB
testcase_03 AC 122 ms
55,724 KB
testcase_04 AC 274 ms
64,580 KB
testcase_05 AC 253 ms
66,192 KB
testcase_06 WA -
testcase_07 AC 121 ms
56,016 KB
testcase_08 AC 265 ms
61,684 KB
testcase_09 AC 269 ms
62,348 KB
testcase_10 AC 122 ms
55,748 KB
testcase_11 AC 121 ms
56,044 KB
testcase_12 AC 122 ms
56,132 KB
testcase_13 AC 122 ms
55,804 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 121 ms
55,872 KB
testcase_19 AC 124 ms
55,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		int k = sc.nextInt();
		sc.close();

		long n2 = n * (n + 1) / 2;
		if (n2 % k != 0) {
			System.out.println("No");
			return;
		}

		PrintWriter pw = new PrintWriter(System.out);
		pw.println("Yes");
		List<List<Integer>> list = new ArrayList<>(k);
		for (int i = 0; i < k; i++) {
			list.add(new ArrayList<>());
		}
		for (int i = 0; i < n; i++) {
			if (i / k % 2 == 0) {
				list.get(i % k).add(i + 1);
			} else {
				list.get(k - i % k - 1).add(i + 1);
			}
		}
		for (int i = 0; i < k; i++) {
			StringBuilder sb = new StringBuilder();
			for (int j : list.get(i)) {
				sb.append(j).append(' ');
			}
			sb.deleteCharAt(sb.length() - 1);
			pw.println(sb.toString());
		}
		pw.flush();
	}
}
0