結果

問題 No.942 プレゼント配り
ユーザー 37zigen37zigen
提出日時 2019-12-08 09:05:07
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,348 bytes
コンパイル時間 2,168 ms
コンパイル使用メモリ 76,912 KB
実行使用メモリ 69,588 KB
最終ジャッジ日時 2023-08-28 14:10:29
合計ジャッジ時間 16,567 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 154 ms
56,904 KB
testcase_01 AC 982 ms
66,728 KB
testcase_02 AC 120 ms
56,080 KB
testcase_03 AC 120 ms
57,920 KB
testcase_04 AC 1,153 ms
65,156 KB
testcase_05 AC 973 ms
67,804 KB
testcase_06 AC 120 ms
55,964 KB
testcase_07 AC 155 ms
56,864 KB
testcase_08 AC 1,028 ms
65,196 KB
testcase_09 AC 1,111 ms
65,048 KB
testcase_10 AC 120 ms
55,888 KB
testcase_11 AC 120 ms
55,824 KB
testcase_12 AC 121 ms
56,092 KB
testcase_13 AC 119 ms
56,072 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 155 ms
56,688 KB
testcase_19 AC 121 ms
55,756 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((long)N*(N+1)/2%K!=0){//必ず満たす
			System.out.println("No");
			return;
		}
		int q=N/K;
		if(N==K&&N>1){
			System.out.println("No");
		}else 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)+(j==(q/2-1)?"\n":" "));
				}
			}
		}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+((q-3)/2==0?"\n":""));
				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)+(j==((q-3)/2-1)?"\n":""));
				}
			}
		}else{
			System.out.println("No");
		}
	}
	
	void tr(Object...objects){
		System.out.println(Arrays.deepToString(objects));
	}
}
0