結果

問題 No.411 昇順昇順ソート
ユーザー uafr_csuafr_cs
提出日時 2016-08-12 22:55:33
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 988 bytes
コンパイル時間 2,528 ms
コンパイル使用メモリ 76,912 KB
実行使用メモリ 477,800 KB
最終ジャッジ日時 2024-04-25 05:37:56
合計ジャッジ時間 14,050 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
41,096 KB
testcase_01 AC 126 ms
41,172 KB
testcase_02 AC 128 ms
40,944 KB
testcase_03 AC 130 ms
41,140 KB
testcase_04 AC 133 ms
41,296 KB
testcase_05 AC 132 ms
41,232 KB
testcase_06 AC 129 ms
41,472 KB
testcase_07 AC 131 ms
41,052 KB
testcase_08 AC 130 ms
41,180 KB
testcase_09 AC 116 ms
40,164 KB
testcase_10 AC 115 ms
40,004 KB
testcase_11 AC 111 ms
40,168 KB
testcase_12 AC 125 ms
41,124 KB
testcase_13 AC 122 ms
40,784 KB
testcase_14 AC 112 ms
40,008 KB
testcase_15 AC 128 ms
41,200 KB
testcase_16 AC 126 ms
41,436 KB
testcase_17 AC 116 ms
40,184 KB
testcase_18 AC 128 ms
41,364 KB
testcase_19 AC 126 ms
41,060 KB
testcase_20 AC 112 ms
40,016 KB
testcase_21 AC 124 ms
41,192 KB
testcase_22 AC 125 ms
41,324 KB
testcase_23 AC 124 ms
41,092 KB
testcase_24 WA -
testcase_25 AC 126 ms
40,920 KB
testcase_26 AC 124 ms
41,304 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 656 ms
227,752 KB
testcase_30 AC 1,207 ms
477,800 KB
testcase_31 AC 1,186 ms
477,668 KB
testcase_32 AC 1,179 ms
477,364 KB
testcase_33 AC 1,176 ms
477,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Set;

public class Main {
	
	public static long dfs(long[][] memo, final int N, final int bit, final int K){
		if(memo[bit][K] >= 0){
			return memo[bit][K];
		}
		
		boolean has_lower = false;
		for(int k = 1; k < K; k++){
			if((bit & (1 << k)) == 0){
				has_lower = true;
				break;
			}
		}
		
		if(!has_lower){
			return memo[bit][K] = 0;
		}
		
		memo[bit][K] = 1;
		for(int k = K + 1; k <= N; k++){
			if((bit & (1 << k)) != 0){ continue; }
			
			memo[bit][K] += dfs(memo, N, bit | (1 << k), k);
		}
		
		return memo[bit][K];
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		final int K = sc.nextInt();
		
		long[][] memo = new long[1 << (N + 1)][N + 1];
		for(int i = 0; i < 1 << (N + 1); i++){
			Arrays.fill(memo[i], -1);
		}
		
		System.out.println(dfs(memo, N, 1 << K, K));
	}

}
0