結果

問題 No.942 プレゼント配り
ユーザー 37zigen37zigen
提出日時 2019-12-08 08:12:47
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,321 bytes
コンパイル時間 3,645 ms
コンパイル使用メモリ 76,260 KB
実行使用メモリ 67,800 KB
最終ジャッジ日時 2023-09-26 22:42:02
合計ジャッジ時間 13,430 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 163 ms
56,640 KB
testcase_01 AC 961 ms
62,600 KB
testcase_02 AC 131 ms
56,020 KB
testcase_03 AC 128 ms
55,916 KB
testcase_04 WA -
testcase_05 AC 1,102 ms
67,340 KB
testcase_06 AC 129 ms
55,892 KB
testcase_07 AC 128 ms
55,704 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 126 ms
55,808 KB
testcase_11 AC 130 ms
55,812 KB
testcase_12 AC 126 ms
55,792 KB
testcase_13 AC 127 ms
55,472 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 129 ms
55,740 KB
testcase_19 AC 130 ms
55,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.math.*;
import java.io.*;

class Main
{
	public static void main(String[] args)
	{
		new Main().run();
	}
	
	void run(){
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();//N個のプレゼント
		int K=sc.nextInt();//K人の子供
		// N%K=0
		if(N*(N+1)/2%K!=0){//必ず満たす
			System.out.println("No");
			return;
		}
		int q=N/K;
		if(N==K&&N>1){
			System.out.println("No");
		}if(K==1){
			System.out.println("Yes");
			for(int i=0;i<N;++i){
				System.out.print((i+1)+(i==N-1 ? "\n" : " "));
			}
		}else if(q%2==0){
			System.out.println("Yes");
			for(int i=0;i<K;++i){
				for(int j=0;j<q/2;++j){
					System.out.print((1+j)+(q/2*i));
					System.out.print(" ");
					System.out.print((N-j)-(q/2*i));
				}
				System.out.println();
			}
		}else if(K%2==1){
			System.out.println("Yes");
			for(int i=0;i<K;++i){
				long sum=3*(3*K+1)/2;
				long res=sum-(3*K-i)-(2*i%K+1);
				System.out.print((3*K-i)+" "+(2*i%K+1)+" "+res);
				for(int j=0;j<(q-3)/2;++j){
					System.out.print(" ");
					System.out.print((1+j+3*K)+(q/2*i));
					System.out.print(" ");
					System.out.print((N-j)-(q/2*i));
				}
				System.out.println();
			}
		}else{
			System.out.println("No");
		}
	}
	
	void tr(Object...objects){
		System.out.println(Arrays.deepToString(objects));
	}
}
0