結果
| 問題 |
No.1598 4×4 Grid
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-07-10 02:17:13 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 943 bytes |
| コンパイル時間 | 2,462 ms |
| コンパイル使用メモリ | 197,220 KB |
| 最終ジャッジ日時 | 2025-01-22 23:35:20 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | TLE * 3 |
| other | TLE * 7 |
ソースコード
#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 = 260;
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;
}