結果

問題 No.942 プレゼント配り
ユーザー 37zigen37zigen
提出日時 2019-12-08 09:53:13
言語 Java21
(openjdk 21)
結果
AC  
実行時間 375 ms / 2,000 ms
コード長 1,813 bytes
コンパイル時間 2,547 ms
コンパイル使用メモリ 86,248 KB
実行使用メモリ 67,932 KB
最終ジャッジ日時 2023-08-28 15:08:02
合計ジャッジ時間 8,859 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
55,840 KB
testcase_01 AC 366 ms
67,504 KB
testcase_02 AC 123 ms
55,924 KB
testcase_03 AC 123 ms
55,692 KB
testcase_04 AC 375 ms
66,056 KB
testcase_05 AC 364 ms
67,932 KB
testcase_06 AC 146 ms
62,204 KB
testcase_07 AC 125 ms
55,968 KB
testcase_08 AC 319 ms
63,252 KB
testcase_09 AC 331 ms
64,012 KB
testcase_10 AC 124 ms
56,020 KB
testcase_11 AC 123 ms
55,704 KB
testcase_12 AC 123 ms
55,748 KB
testcase_13 AC 123 ms
55,700 KB
testcase_14 AC 325 ms
64,020 KB
testcase_15 AC 307 ms
62,192 KB
testcase_16 AC 310 ms
63,196 KB
testcase_17 AC 300 ms
63,872 KB
testcase_18 AC 126 ms
55,992 KB
testcase_19 AC 124 ms
55,856 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);
		long N=sc.nextInt();//N個のプレゼント
		long K=sc.nextInt();//K人の子供
		// N%K=0
		if((long)N*(N+1)/2%K!=0){//必ず満たす
			System.out.println("No");
			return;
		}
		long q=N/K;
		ArrayList<Long>[] a=new ArrayList[(int)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(long i=0;i<N;++i){
				a[0].add(i+1);
			}
		}else if(q%2==0){
			System.out.println("Yes");
			for(long i=0;i<K;++i){
				for(long j=0;j<q/2;++j){
					a[(int)i].add((1+j)+(q/2*i));
					a[(int)i].add((N-j)-(q/2*i));
				}
			}
		}else if(K%2==1){
			System.out.println("Yes");
			for(long i=0;i<K;++i){
				long sum=(long)3*(3*K+1)/2;
				long res=sum-(3*K-i)-((2*i)%K+1);
				a[(int)i].add(3*K-i);
				a[(int)i].add((2*i)%K+1);
				a[(int)i].add(res);
				for(long j=0;j<(q-3)/2;++j){
					a[(int)i].add((1+j+3*K)+((q-3)/2*i));
					a[(int)i].add((N-j)-((q-3)/2*i));
				}
			}
		}else{
			System.out.println("No");
			return;
		}
		PrintWriter pw=new PrintWriter(System.out);
		boolean[] vis=new boolean[(int)N];
		for(int i=0;i<K;++i){
			long sum=0;
			if(a[i].size()!=N/K)throw new AssertionError();
			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);
				if(vis[(int)(a[i].get(j)-1)]){
					tr(a[i].get(j));
					throw new AssertionError();
				}else vis[(int)(a[i].get(j)-1)]=true;
			}
			if(sum!=(long)N*(N+1)/2/K)throw new AssertionError();
		}
		pw.close();
	}
	
	void tr(Object...objects){
		System.out.println(Arrays.deepToString(objects));
	}
}
0