結果

問題 No.625 ソンタクロース
ユーザー 37zigen
提出日時 2020-04-19 11:17:46
言語 Java
(openjdk 23)
結果
AC  
実行時間 530 ms / 4,000 ms
コード長 937 bytes
コンパイル時間 2,674 ms
コンパイル使用メモリ 81,716 KB
実行使用メモリ 62,936 KB
最終ジャッジ日時 2024-10-04 20:44:09
合計ジャッジ時間 8,613 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	
	void run() {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int M=sc.nextInt();
		int[][] a=new int[2][N];
		a[0][0]=M;
		for (int i=1;i<N;++i) {
			Arrays.fill(a[i%2], 0);
			int[][] x=new int[i][2];
			for (int j=0;j<i;++j) {
				x[j][0]=a[(i-1)%2][j];
				x[j][1]=j;
			}
			Arrays.sort(x, Comparator.comparing((int[] v)->v[0]).thenComparing(v->v[1]));
			int need=0;
			for (int j=0;j<(i+1)/2;++j) {
				need+=x[j][0]+1;
				a[i%2][x[j][1]]=x[j][0]+1;
			}
			if (need<=M) {
				a[i%2][i]=M-need;
			} else {
				a[i%2]=Arrays.copyOf(a[(i-1)%2], N);
				a[i%2][i]=-1;
			}
		}
		for (int i=0;i<N;++i) {
			System.out.print(a[(N-1)%2][N-1-i]+(i==N-1?"\n":" "));
		}
	}
	
	void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));}
}
0