結果

問題 No.411 昇順昇順ソート
ユーザー nCk_cvnCk_cv
提出日時 2016-08-28 01:11:57
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,057 ms / 2,000 ms
コード長 933 bytes
コンパイル時間 2,020 ms
コンパイル使用メモリ 73,864 KB
実行使用メモリ 56,880 KB
最終ジャッジ日時 2023-08-08 14:31:05
合計ジャッジ時間 9,232 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
56,004 KB
testcase_01 AC 121 ms
56,472 KB
testcase_02 AC 120 ms
56,324 KB
testcase_03 AC 119 ms
56,324 KB
testcase_04 AC 121 ms
56,196 KB
testcase_05 AC 121 ms
56,392 KB
testcase_06 AC 119 ms
55,860 KB
testcase_07 AC 120 ms
55,884 KB
testcase_08 AC 120 ms
55,836 KB
testcase_09 AC 119 ms
56,496 KB
testcase_10 AC 118 ms
54,420 KB
testcase_11 AC 121 ms
56,240 KB
testcase_12 AC 121 ms
55,868 KB
testcase_13 AC 121 ms
55,860 KB
testcase_14 AC 121 ms
55,804 KB
testcase_15 AC 118 ms
56,520 KB
testcase_16 AC 121 ms
54,500 KB
testcase_17 AC 120 ms
56,220 KB
testcase_18 AC 120 ms
55,700 KB
testcase_19 AC 119 ms
56,064 KB
testcase_20 AC 118 ms
55,972 KB
testcase_21 AC 120 ms
56,316 KB
testcase_22 AC 121 ms
56,068 KB
testcase_23 AC 119 ms
56,300 KB
testcase_24 AC 123 ms
56,056 KB
testcase_25 AC 120 ms
55,860 KB
testcase_26 AC 119 ms
55,932 KB
testcase_27 AC 157 ms
56,048 KB
testcase_28 AC 1,057 ms
55,932 KB
testcase_29 AC 334 ms
56,360 KB
testcase_30 AC 135 ms
56,608 KB
testcase_31 AC 153 ms
56,880 KB
testcase_32 AC 119 ms
56,256 KB
testcase_33 AC 119 ms
55,828 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