結果

問題 No.616 へんなソート
ユーザー ミドリムシミドリムシ
提出日時 2018-02-09 17:59:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 1,176 bytes
コンパイル時間 679 ms
コンパイル使用メモリ 73,072 KB
実行使用メモリ 145,188 KB
最終ジャッジ日時 2024-04-16 18:45:32
合計ジャッジ時間 1,835 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 3 ms
6,940 KB
testcase_13 AC 43 ms
80,564 KB
testcase_14 AC 3 ms
6,940 KB
testcase_15 AC 2 ms
6,948 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 37 ms
68,224 KB
testcase_18 AC 16 ms
30,608 KB
testcase_19 AC 12 ms
23,112 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 3 ms
6,940 KB
testcase_22 AC 6 ms
12,084 KB
testcase_23 AC 1 ms
6,940 KB
testcase_24 AC 2 ms
6,944 KB
testcase_25 AC 1 ms
6,940 KB
testcase_26 AC 5 ms
10,532 KB
testcase_27 AC 5 ms
9,028 KB
testcase_28 AC 77 ms
143,936 KB
testcase_29 AC 77 ms
145,188 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    long array_patterns[N + 1][N * (N + 1) / 2 + 1]; // now_array_size, now_inversion_number
    for(int i = 0; i <= N * (N + 1) / 2; i++){
        array_patterns[N][i] = (i <= K);
    }
    vector<long> array_patterns_cumulative_sum[N + 1];
    array_patterns_cumulative_sum[N].push_back(0);
    long cumulative_sum_last = 0;
    for(int i = 0; i <= N * (N + 1) / 2; i++){
        cumulative_sum_last += array_patterns[N][i];
        array_patterns_cumulative_sum[N].push_back(cumulative_sum_last);
    }
    for(int i = N - 1; i >= 0; i--){
        for(int j = 0; j <= i * (i + 1) / 2; j++){
            array_patterns[i][j] = (array_patterns_cumulative_sum[i + 1][i + j + 1] - array_patterns_cumulative_sum[i + 1][j]) % long(1e9 + 7);
        }
        array_patterns_cumulative_sum[i].push_back(0);
        long cumulative_sum = 0;
        for(int j = 0; j <= i * (i + 1) / 2; j++){
            cumulative_sum += array_patterns[i][j];
            array_patterns_cumulative_sum[i].push_back(cumulative_sum);
        }
    }
    cout << array_patterns[0][0] << endl;
}
0