結果

問題 No.411 昇順昇順ソート
ユーザー beetbeet
提出日時 2018-07-30 14:08:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,415 ms / 2,000 ms
コード長 604 bytes
コンパイル時間 1,472 ms
コンパイル使用メモリ 165,752 KB
実行使用メモリ 331,336 KB
最終ジャッジ日時 2023-10-11 20:37:07
合計ジャッジ時間 9,279 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
331,044 KB
testcase_01 AC 86 ms
330,988 KB
testcase_02 AC 87 ms
331,096 KB
testcase_03 AC 86 ms
330,980 KB
testcase_04 AC 87 ms
331,040 KB
testcase_05 AC 87 ms
330,984 KB
testcase_06 AC 85 ms
331,024 KB
testcase_07 AC 85 ms
331,024 KB
testcase_08 AC 87 ms
331,092 KB
testcase_09 AC 87 ms
331,036 KB
testcase_10 AC 87 ms
331,320 KB
testcase_11 AC 87 ms
331,164 KB
testcase_12 AC 88 ms
331,272 KB
testcase_13 AC 87 ms
331,212 KB
testcase_14 AC 87 ms
330,992 KB
testcase_15 AC 87 ms
331,084 KB
testcase_16 AC 88 ms
330,988 KB
testcase_17 AC 85 ms
331,336 KB
testcase_18 AC 87 ms
331,336 KB
testcase_19 AC 85 ms
331,144 KB
testcase_20 AC 86 ms
331,092 KB
testcase_21 AC 85 ms
331,068 KB
testcase_22 AC 87 ms
330,988 KB
testcase_23 AC 87 ms
331,304 KB
testcase_24 AC 88 ms
331,336 KB
testcase_25 AC 87 ms
331,068 KB
testcase_26 AC 87 ms
331,100 KB
testcase_27 AC 94 ms
331,020 KB
testcase_28 AC 1,415 ms
331,020 KB
testcase_29 AC 496 ms
331,140 KB
testcase_30 AC 438 ms
330,988 KB
testcase_31 AC 459 ms
330,984 KB
testcase_32 AC 152 ms
331,212 KB
testcase_33 AC 134 ms
330,980 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
Int dp[2][20][1<<20];
signed main(){
  Int n,k;
  cin>>n>>k;
  memset(dp,-1,sizeof(dp));
  function<Int(Int, Int, Int)> dfs=
    [&](Int f,Int p,Int b)->Int{
      Int &res=dp[f][p][b];
      if(~res) return res;
      if(b+1==(1<<n)) return f;
      res=0;
      for(Int i=0;i<n;i++){
	if((b>>i)&1) continue;
	Int nf=p>i,nb=b|(1<<i);
	if(nf&&f) continue;
	nf|=f;
	res+=dfs(nf,i,nb);
      }
      //cout<<f<<" "<<p<<" "<<b<<":"<<res<<endl;
      return res;
    };
  k--;
  cout<<dfs(0,k,1<<k)<<endl;
  return 0;
}
0