結果

問題 No.411 昇順昇順ソート
ユーザー nCk_cvnCk_cv
提出日時 2016-08-28 01:11:57
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,039 ms / 2,000 ms
コード長 933 bytes
コンパイル時間 1,930 ms
コンパイル使用メモリ 77,528 KB
実行使用メモリ 54,296 KB
最終ジャッジ日時 2024-04-26 07:13:21
合計ジャッジ時間 8,407 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 106 ms
54,204 KB
testcase_01 AC 123 ms
54,296 KB
testcase_02 AC 124 ms
54,272 KB
testcase_03 AC 124 ms
53,868 KB
testcase_04 AC 124 ms
53,980 KB
testcase_05 AC 115 ms
52,840 KB
testcase_06 AC 128 ms
53,888 KB
testcase_07 AC 128 ms
53,892 KB
testcase_08 AC 115 ms
53,024 KB
testcase_09 AC 114 ms
52,940 KB
testcase_10 AC 125 ms
53,896 KB
testcase_11 AC 122 ms
54,108 KB
testcase_12 AC 121 ms
53,944 KB
testcase_13 AC 126 ms
54,100 KB
testcase_14 AC 123 ms
53,848 KB
testcase_15 AC 127 ms
54,020 KB
testcase_16 AC 115 ms
52,944 KB
testcase_17 AC 115 ms
52,572 KB
testcase_18 AC 124 ms
54,144 KB
testcase_19 AC 124 ms
53,720 KB
testcase_20 AC 125 ms
54,100 KB
testcase_21 AC 124 ms
53,828 KB
testcase_22 AC 114 ms
52,936 KB
testcase_23 AC 116 ms
54,016 KB
testcase_24 AC 124 ms
41,108 KB
testcase_25 AC 125 ms
41,420 KB
testcase_26 AC 125 ms
41,260 KB
testcase_27 AC 193 ms
41,172 KB
testcase_28 AC 1,039 ms
41,260 KB
testcase_29 AC 340 ms
41,488 KB
testcase_30 AC 139 ms
41,112 KB
testcase_31 AC 143 ms
41,136 KB
testcase_32 AC 114 ms
40,144 KB
testcase_33 AC 126 ms
41,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
public class Main {
		static int INF = 2 << 27;
		public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);
			int N = sc.nextInt();
			int K = sc.nextInt();
			int ans = dfs(0,K,new int[N],new boolean[N],false);
			System.out.println(ans);
		}
		static int dfs(int a, int b, int[] c, boolean[] d, boolean e) {
			//System.out.println(a);
			if(a == 0) {
				c[a] = b;
				d[b-1] = true;
				return dfs(a+1,b,c,d,e);
			}
			if(a == c.length) {
				if(e)
				return 1;
				return 0;
			}
			if(e) {
				for(int i = 0; i < d.length; i++) {
					if(!d[i] && c[a-1] > i+1) return 0;
				}
			}
			
			int ret = 0;
			for(int i = 0; i < c.length; i++) {
				if(d[i]) continue;
				boolean nex = e;
				if(c[a-1] > i+1) {
					if(e) continue;
					nex = true;
				}
				c[a] = i+1;
				d[i] = true;
				ret += dfs(a+1,b,c,d,nex);
				c[a] = 0;
				d[i] = false;
			}
			return ret;
		}

}
0