結果

問題 No.1598 4×4 Grid
ユーザー kenskens
提出日時 2021-07-10 02:14:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 943 bytes
コンパイル時間 2,048 ms
コンパイル使用メモリ 202,340 KB
実行使用メモリ 312,780 KB
最終ジャッジ日時 2023-09-14 13:52:25
合計ジャッジ時間 11,991 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 TLE -
testcase_02 TLE -
testcase_03 TLE -
testcase_04 TLE -
testcase_05 TLE -
testcase_06 TLE -
testcase_07 TLE -
testcase_08 TLE -
testcase_09 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;
constexpr int MAX = 16;
constexpr int BASE = 300;
constexpr int dx[4] = {0,1,0,-1};
constexpr int dy[4] = {1,0,-1,0};

int main(){
  int k;
  cin >> k;
  vector<vector<ll>> dp(1<<MAX,vector<ll>(2*BASE));
  dp[0][BASE] = 1;
  rep(bit,1<<MAX) {
    int bc = 0;
    rep(i,MAX) if(bit & (1<<i)) bc++;
    rep(s,2*BASE) {
      rep(x,4) rep(y,4) {
        if(bit & (1<<(x*4+y))) continue;
        int cnt = 0, exi = 0;
        rep(dir,4) {
          int nx = x + dx[dir], ny = y + dy[dir];
          if(nx >= 0 and nx < 4 and ny >= 0 and ny < 4) {
            cnt++;
            if(bit & (1<<(nx*4+ny))) exi++;
          }
        }
        int res = s + exi*bc - (cnt-exi)*bc;
        if(res >= 0 and res < 2*BASE) dp[bit|(1<<(x*4+y))][res] += dp[bit][s];
      }
    }
  }
  cout << dp[(1<<MAX)-1][BASE+k] << endl;
  return 0;
}
0