結果

問題 No.625 ソンタクロース
ユーザー 夕叢霧香(ゆうむらきりか)夕叢霧香(ゆうむらきりか)
提出日時 2017-12-25 03:56:03
言語 Java21
(openjdk 21)
結果
AC  
実行時間 259 ms / 4,000 ms
コード長 2,374 bytes
コンパイル時間 2,423 ms
コンパイル使用メモリ 79,488 KB
実行使用メモリ 47,908 KB
最終ジャッジ日時 2024-05-10 00:04:42
合計ジャッジ時間 6,536 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
38,528 KB
testcase_01 AC 86 ms
38,500 KB
testcase_02 AC 85 ms
40,372 KB
testcase_03 AC 86 ms
40,192 KB
testcase_04 AC 93 ms
38,500 KB
testcase_05 AC 102 ms
40,064 KB
testcase_06 AC 87 ms
40,444 KB
testcase_07 AC 88 ms
38,528 KB
testcase_08 AC 87 ms
38,528 KB
testcase_09 AC 90 ms
38,608 KB
testcase_10 AC 86 ms
40,408 KB
testcase_11 AC 88 ms
38,488 KB
testcase_12 AC 94 ms
38,264 KB
testcase_13 AC 85 ms
40,372 KB
testcase_14 AC 91 ms
40,400 KB
testcase_15 AC 141 ms
40,952 KB
testcase_16 AC 102 ms
40,284 KB
testcase_17 AC 209 ms
44,052 KB
testcase_18 AC 259 ms
47,908 KB
testcase_19 AC 163 ms
42,668 KB
testcase_20 AC 164 ms
43,044 KB
testcase_21 AC 141 ms
41,316 KB
testcase_22 AC 239 ms
46,204 KB
testcase_23 AC 123 ms
40,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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;
        }
    }
}
0