結果

問題 No.942 プレゼント配り
ユーザー 37zigen37zigen
提出日時 2019-12-08 09:25:52
言語 Java19
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,530 bytes
コンパイル時間 2,368 ms
コンパイル使用メモリ 80,356 KB
実行使用メモリ 64,944 KB
最終ジャッジ日時 2023-08-28 14:36:20
合計ジャッジ時間 9,509 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
55,696 KB
testcase_01 RE -
testcase_02 AC 119 ms
56,332 KB
testcase_03 AC 117 ms
55,800 KB
testcase_04 WA -
testcase_05 RE -
testcase_06 AC 138 ms
60,284 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 119 ms
56,800 KB
testcase_11 AC 120 ms
55,724 KB
testcase_12 AC 119 ms
56,000 KB
testcase_13 AC 120 ms
56,344 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 118 ms
55,568 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;
		ArrayList<Integer>[] a=new ArrayList[K];
		for(int i=0;i<K;++i)a[i]=new ArrayList<>();
		if(N==K&&N>1){
			System.out.println("No");
			return;
		}else if(K==1){
			System.out.println("Yes");
			for(int i=0;i<N;++i){
				a[i].add(i+1);
			}
		}else if(q%2==0){
			System.out.println("Yes");
			for(int i=0;i<K;++i){
				for(int j=0;j<q/2;++j){
					a[i].add((1+j)+(q/2*i));
					a[i].add((N-j)-(q/2*i));
				}
			}
		}else if(K%2==1){
			System.out.println("Yes");
			for(int i=0;i<K;++i){
				int sum=3*(3*K+1)/2;
				int res=sum-(3*K-i)-(2*i%K+1);
				a[i].add(3*K-i);
				a[i].add(2*i%K+1);
				a[i].add(res);
				for(int j=0;j<(q-3)/2;++j){
					a[i].add((1+j+3*K)+(q/2*i));
					a[i].add((N-j)-(q/2*i));
				}
			}
		}else{
			System.out.println("No");
			return;
		}
		for(int i=0;i<K;++i){
			long sum=0;
			PrintWriter pw=new PrintWriter(System.out);
			for(int j=0;j<a[i].size();++j){
				pw.print(a[i].get(j)+(j==a[i].size()-1?"\n":" "));
				sum+=a[i].get(j);
			}
			pw.close();
			if(sum!=(long)N*(N+1)/2/K)throw new AssertionError();
		}
	}
	
	void tr(Object...objects){
		System.out.println(Arrays.deepToString(objects));
	}
}
0