結果
問題 | No.942 プレゼント配り |
ユーザー | 37zigen |
提出日時 | 2019-12-08 09:28:52 |
言語 | Java19 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,530 bytes |
コンパイル時間 | 2,264 ms |
コンパイル使用メモリ | 81,600 KB |
実行使用メモリ | 65,200 KB |
最終ジャッジ日時 | 2023-08-28 14:40:10 |
合計ジャッジ時間 | 9,159 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 124 ms
55,504 KB |
testcase_01 | AC | 342 ms
65,200 KB |
testcase_02 | AC | 120 ms
55,880 KB |
testcase_03 | AC | 120 ms
55,800 KB |
testcase_04 | WA | - |
testcase_05 | AC | 351 ms
64,968 KB |
testcase_06 | AC | 140 ms
59,916 KB |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | AC | 123 ms
55,744 KB |
testcase_11 | AC | 123 ms
55,324 KB |
testcase_12 | AC | 128 ms
55,388 KB |
testcase_13 | AC | 123 ms
55,908 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | AC | 121 ms
55,680 KB |
ソースコード
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[0].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)); } }