結果

問題 No.411 昇順昇順ソート
ユーザー HachimoriHachimori
提出日時 2016-08-12 22:34:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 964 ms / 2,000 ms
コード長 836 bytes
コンパイル時間 358 ms
コンパイル使用メモリ 52,236 KB
実行使用メモリ 167,360 KB
最終ジャッジ日時 2023-08-07 09:16:43
合計ジャッジ時間 4,945 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
167,212 KB
testcase_01 AC 44 ms
167,120 KB
testcase_02 AC 44 ms
167,168 KB
testcase_03 AC 43 ms
167,120 KB
testcase_04 AC 43 ms
167,236 KB
testcase_05 AC 47 ms
167,248 KB
testcase_06 AC 43 ms
167,176 KB
testcase_07 AC 43 ms
167,212 KB
testcase_08 AC 44 ms
167,248 KB
testcase_09 AC 43 ms
167,160 KB
testcase_10 AC 43 ms
167,124 KB
testcase_11 AC 43 ms
167,232 KB
testcase_12 AC 43 ms
167,296 KB
testcase_13 AC 43 ms
167,128 KB
testcase_14 AC 43 ms
167,128 KB
testcase_15 AC 44 ms
167,152 KB
testcase_16 AC 43 ms
167,296 KB
testcase_17 AC 44 ms
167,360 KB
testcase_18 AC 43 ms
167,228 KB
testcase_19 AC 44 ms
167,232 KB
testcase_20 AC 43 ms
167,260 KB
testcase_21 AC 43 ms
167,184 KB
testcase_22 AC 43 ms
167,112 KB
testcase_23 AC 44 ms
167,212 KB
testcase_24 AC 43 ms
167,172 KB
testcase_25 AC 43 ms
167,128 KB
testcase_26 AC 43 ms
167,300 KB
testcase_27 AC 49 ms
167,164 KB
testcase_28 AC 964 ms
167,120 KB
testcase_29 AC 338 ms
167,128 KB
testcase_30 AC 285 ms
167,160 KB
testcase_31 AC 256 ms
167,128 KB
testcase_32 AC 89 ms
167,176 KB
testcase_33 AC 73 ms
167,116 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<cstring>
using namespace std;
const int MAX_N = 20;
const int BUF = 1 << MAX_N;


int N, K;

void read() {
    cin >> N >> K;
    --K;
}


int rec(bool decreased, int k, int mask, int dp[2][MAX_N][BUF]) {
    if (mask == (1 << N) - 1) {
        return decreased ? 1 : 0;
    }

    int &ret = dp[decreased][k][mask];
    if (ret != -1) return ret;

    ret = 0;
    
    for (int i = 0; i < N; ++i) {
        if (mask & (1 << i)) {
            continue;
        }
        if (decreased && i < k) {
            continue;
        }

        ret += rec(decreased | (i < k), i, mask | (1 << i), dp);
    }
    
    return ret;
}


void work() {
    static int dp[2][MAX_N][BUF];
    memset(dp, -1, sizeof(dp));

    cout << rec(0, K, 1 << K, dp) << endl;
}


int main() {
    read();
    work();
    return 0;
}
0