結果

問題 No.942 プレゼント配り
ユーザー 37zigen37zigen
提出日時 2019-12-08 08:26:15
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,341 bytes
コンパイル時間 2,504 ms
コンパイル使用メモリ 76,380 KB
実行使用メモリ 67,360 KB
最終ジャッジ日時 2023-09-26 22:42:16
合計ジャッジ時間 12,971 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 154 ms
56,820 KB
testcase_01 AC 1,121 ms
67,316 KB
testcase_02 AC 118 ms
55,832 KB
testcase_03 AC 118 ms
55,640 KB
testcase_04 AC 1,192 ms
67,212 KB
testcase_05 AC 929 ms
66,216 KB
testcase_06 AC 120 ms
55,864 KB
testcase_07 AC 156 ms
56,700 KB
testcase_08 AC 1,018 ms
67,360 KB
testcase_09 WA -
testcase_10 AC 129 ms
55,480 KB
testcase_11 AC 120 ms
55,876 KB
testcase_12 AC 117 ms
55,900 KB
testcase_13 AC 117 ms
55,804 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 151 ms
56,740 KB
testcase_19 AC 121 ms
55,696 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)+(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);
				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":" "));
				}
				System.out.println();
			}
		}else{
			System.out.println("No");
		}
	}
	
	void tr(Object...objects){
		System.out.println(Arrays.deepToString(objects));
	}
}
0