結果

問題 No.942 プレゼント配り
ユーザー ks2mks2m
提出日時 2019-12-05 00:55:27
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 930 bytes
コンパイル時間 3,835 ms
コンパイル使用メモリ 75,872 KB
実行使用メモリ 91,568 KB
最終ジャッジ日時 2023-08-21 07:56:54
合計ジャッジ時間 9,267 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 123 ms
55,780 KB
testcase_03 AC 124 ms
55,296 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 124 ms
56,320 KB
testcase_11 AC 127 ms
55,496 KB
testcase_12 AC 124 ms
55,324 KB
testcase_13 AC 124 ms
57,536 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 125 ms
55,596 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);
		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