結果
問題 | No.625 ソンタクロース |
ユーザー |
![]() |
提出日時 | 2017-12-25 03:56:03 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 258 ms / 4,000 ms |
コード長 | 2,374 bytes |
コンパイル時間 | 2,669 ms |
コンパイル使用メモリ | 87,584 KB |
実行使用メモリ | 58,472 KB |
最終ジャッジ日時 | 2024-12-17 18:53:18 |
合計ジャッジ時間 | 6,516 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
import java.io.*; import java.util.*; class Main { public static void main(String[] args) { MyScanner sc = new MyScanner(); out = new PrintWriter(new BufferedOutputStream(System.out)); int n=sc.nextInt(); int m=sc.nextInt(); int[][]a=new int[n][]; a[0]=new int[1]; a[0][0]=m; for(int i=1;i<n;++i){ int[]b=new int[i]; for(int j=0;j<i;++j) b[j]=(a[i-1][j]+1)*n+j; a[i]=new int[i+1]; Arrays.sort(b); int tol=0; int c=(i+1)/2; for(int j=0;j<c;++j){ int x=b[j]/n; int y=b[j]%n; tol+=x; } if(tol>m){ System.arraycopy(a[i-1],0,a[i],0,i); a[i][i]=-1; continue; } for(int j=0;j<c;++j){ int x=b[j]/n; int y=b[j]%n; a[i][y]=x; } a[i][i]=m-tol; } for(int i=0;i<n;++i) out.print(a[n-1][n-1-i]+(i==n-1?"\n":" ")); out.close(); } // http://codeforces.com/blog/entry/7018 //-----------PrintWriter for faster output--------------------------------- public static PrintWriter out; //-----------MyScanner class for faster input---------- public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine(){ String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }