結果

問題 No.411 昇順昇順ソート
ユーザー uafr_csuafr_cs
提出日時 2016-08-12 23:03:31
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 921 bytes
コンパイル時間 2,059 ms
コンパイル使用メモリ 77,192 KB
実行使用メモリ 55,476 KB
最終ジャッジ日時 2024-04-25 05:39:48
合計ジャッジ時間 9,369 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 103 ms
45,536 KB
testcase_01 AC 110 ms
40,992 KB
testcase_02 AC 115 ms
41,476 KB
testcase_03 AC 112 ms
40,336 KB
testcase_04 AC 110 ms
41,248 KB
testcase_05 AC 115 ms
40,728 KB
testcase_06 AC 113 ms
41,124 KB
testcase_07 AC 111 ms
39,956 KB
testcase_08 AC 102 ms
40,432 KB
testcase_09 AC 112 ms
41,132 KB
testcase_10 AC 114 ms
41,072 KB
testcase_11 AC 114 ms
41,548 KB
testcase_12 AC 112 ms
40,660 KB
testcase_13 AC 105 ms
40,412 KB
testcase_14 AC 110 ms
39,840 KB
testcase_15 AC 112 ms
39,832 KB
testcase_16 AC 118 ms
41,452 KB
testcase_17 AC 106 ms
39,936 KB
testcase_18 AC 115 ms
41,260 KB
testcase_19 AC 104 ms
40,276 KB
testcase_20 AC 111 ms
39,984 KB
testcase_21 AC 106 ms
40,008 KB
testcase_22 AC 114 ms
41,352 KB
testcase_23 AC 114 ms
40,452 KB
testcase_24 WA -
testcase_25 AC 102 ms
40,480 KB
testcase_26 AC 108 ms
39,964 KB
testcase_27 WA -
testcase_28 TLE -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます

ソースコード

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] >= 0){
			return memo[bit];
		}
		
		//System.out.println(Integer.toBinaryString(bit));
		
		final int all_bit_up = (1 << (K + 1)) - 1;
		if(all_bit_up == bit){
			return memo[bit] = 0;
		}
		
		memo[bit] = 1;
		for(int k = K + 1; k < N; k++){
			if((bit & (1 << k)) != 0){ continue; }
			
			memo[bit] += dfs(memo, N, bit | (1 << k), k);
		}
		
		return memo[bit];
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		final int K = sc.nextInt() - 1;
		
		long[] memo = new long[1 << N];
		for(int i = 0; i < 1 << N; i++){
			Arrays.fill(memo, -1);
		}
		
		System.out.println(dfs(memo, N, 1 << K, K));
	}

}
0