結果

問題 No.942 プレゼント配り
ユーザー 37zigen37zigen
提出日時 2019-12-08 11:01:36
言語 Java21
(openjdk 21)
結果
AC  
実行時間 380 ms / 2,000 ms
コード長 1,813 bytes
コンパイル時間 2,704 ms
コンパイル使用メモリ 86,472 KB
実行使用メモリ 68,032 KB
最終ジャッジ日時 2023-08-28 16:40:23
合計ジャッジ時間 8,240 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
56,172 KB
testcase_01 AC 350 ms
67,524 KB
testcase_02 AC 121 ms
55,764 KB
testcase_03 AC 120 ms
55,760 KB
testcase_04 AC 380 ms
67,984 KB
testcase_05 AC 355 ms
68,032 KB
testcase_06 AC 140 ms
60,664 KB
testcase_07 AC 123 ms
55,960 KB
testcase_08 AC 301 ms
63,684 KB
testcase_09 AC 330 ms
64,364 KB
testcase_10 AC 119 ms
55,672 KB
testcase_11 AC 119 ms
55,716 KB
testcase_12 AC 121 ms
56,116 KB
testcase_13 AC 119 ms
55,912 KB
testcase_14 AC 321 ms
64,292 KB
testcase_15 AC 300 ms
61,976 KB
testcase_16 AC 301 ms
63,544 KB
testcase_17 AC 293 ms
63,580 KB
testcase_18 AC 121 ms
56,124 KB
testcase_19 AC 118 ms
55,940 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{
            throw new AssertionError();
		}
		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