結果

問題 No.625 ソンタクロース
ユーザー 夕叢霧香(ゆうむらきりか)夕叢霧香(ゆうむらきりか)
提出日時 2017-12-25 03:56:03
言語 Java21
(openjdk 21)
結果
AC  
実行時間 256 ms / 4,000 ms
コード長 2,374 bytes
コンパイル時間 2,547 ms
コンパイル使用メモリ 82,032 KB
実行使用メモリ 58,684 KB
最終ジャッジ日時 2023-08-22 18:16:12
合計ジャッジ時間 6,704 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
52,732 KB
testcase_01 AC 86 ms
52,720 KB
testcase_02 AC 86 ms
52,744 KB
testcase_03 AC 86 ms
52,496 KB
testcase_04 AC 85 ms
52,536 KB
testcase_05 AC 86 ms
52,716 KB
testcase_06 AC 86 ms
53,704 KB
testcase_07 AC 85 ms
52,496 KB
testcase_08 AC 84 ms
53,116 KB
testcase_09 AC 84 ms
53,364 KB
testcase_10 AC 85 ms
53,448 KB
testcase_11 AC 86 ms
52,864 KB
testcase_12 AC 85 ms
52,676 KB
testcase_13 AC 86 ms
51,048 KB
testcase_14 AC 85 ms
53,200 KB
testcase_15 AC 150 ms
55,716 KB
testcase_16 AC 98 ms
52,784 KB
testcase_17 AC 218 ms
57,956 KB
testcase_18 AC 256 ms
58,196 KB
testcase_19 AC 159 ms
56,336 KB
testcase_20 AC 167 ms
55,688 KB
testcase_21 AC 137 ms
56,308 KB
testcase_22 AC 232 ms
58,684 KB
testcase_23 AC 142 ms
55,932 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