結果

問題 No.616 へんなソート
ユーザー 夕叢霧香(ゆうむらきりか)夕叢霧香(ゆうむらきりか)
提出日時 2017-12-16 00:13:47
言語 Java19
(openjdk 21)
結果
AC  
実行時間 650 ms / 2,000 ms
コード長 2,225 bytes
コンパイル時間 2,025 ms
コンパイル使用メモリ 75,284 KB
実行使用メモリ 331,300 KB
最終ジャッジ日時 2023-08-21 06:51:38
合計ジャッジ時間 7,248 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,532 KB
testcase_01 AC 43 ms
49,524 KB
testcase_02 AC 43 ms
48,076 KB
testcase_03 AC 46 ms
49,480 KB
testcase_04 AC 53 ms
50,400 KB
testcase_05 AC 42 ms
49,540 KB
testcase_06 AC 49 ms
49,656 KB
testcase_07 AC 44 ms
49,904 KB
testcase_08 AC 52 ms
50,436 KB
testcase_09 AC 62 ms
51,764 KB
testcase_10 AC 45 ms
49,436 KB
testcase_11 AC 56 ms
50,288 KB
testcase_12 AC 112 ms
57,616 KB
testcase_13 AC 368 ms
184,596 KB
testcase_14 AC 89 ms
52,676 KB
testcase_15 AC 45 ms
49,596 KB
testcase_16 AC 73 ms
52,088 KB
testcase_17 AC 343 ms
185,904 KB
testcase_18 AC 191 ms
112,360 KB
testcase_19 AC 167 ms
84,260 KB
testcase_20 AC 50 ms
49,512 KB
testcase_21 AC 87 ms
52,284 KB
testcase_22 AC 123 ms
65,884 KB
testcase_23 AC 43 ms
49,588 KB
testcase_24 AC 43 ms
50,000 KB
testcase_25 AC 43 ms
49,524 KB
testcase_26 AC 173 ms
65,744 KB
testcase_27 AC 130 ms
62,024 KB
testcase_28 AC 650 ms
331,300 KB
testcase_29 AC 607 ms
331,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;


class Main {
    static final long MOD=1000000007;
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        int n=sc.nextInt();
        int k=sc.nextInt();
        int[]a=new int[n];
        for(int i=0;i<n;++i)a[i]=sc.nextInt();
        long[][]dp=new long[n+1][n*n];
        dp[0][0]=1;
        for(int i=0;i<n;++i){
            int u=i;
            int nxt=i+1;
            Arrays.fill(dp[nxt],0);
            for(int j=0;j<n*n;++j){
                if(j+i+1<n*n)
                    dp[nxt][j+i+1]=(dp[nxt][j+i+1]-dp[u][j]+MOD)%MOD;
                dp[nxt][j]=(dp[nxt][j]+dp[u][j])%MOD;
            }
            for(int j=1;j<n*n;++j)
                dp[nxt][j]=(dp[nxt][j]+dp[nxt][j-1])%MOD;
        }
        long ans=0;
        for(int i=0;i<=k;++i)
            ans=(ans+dp[n][i])%MOD;
        out.println(ans);
        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