結果
| 問題 | No.1598 4×4 Grid |
| コンテスト | |
| ユーザー |
SSRS
|
| 提出日時 | 2021-07-09 22:33:59 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,487 ms / 4,000 ms |
| コード長 | 906 bytes |
| コンパイル時間 | 1,809 ms |
| コンパイル使用メモリ | 178,988 KB |
| 実行使用メモリ | 182,784 KB |
| 最終ジャッジ日時 | 2024-07-01 17:15:39 |
| 合計ジャッジ時間 | 18,732 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 7 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
vector<int> dx = {1, 0, -1, 0};
vector<int> dy = {0, 1, 0, -1};
int main(){
int K;
cin >> K;
vector<map<int, long long>> dp(1 << 16);
dp[0][0] = 1;
for (int i = 0; i < (1 << 16); i++){
int p = __builtin_popcount(i);
for (int j = 0; j < 16; j++){
if ((i >> j & 1) == 0){
int x = j / 4;
int y = j % 4;
int ds = 0;
for (int k = 0; k < 4; k++){
int x2 = x + dx[k];
int y2 = y + dy[k];
if (0 <= x2 && x2 < 4 && 0 <= y2 && y2 < 4){
int id = x2 * 4 + y2;
if ((i >> id & 1) == 1){
ds += p;
} else {
ds -= p;
}
}
}
int i2 = i + (1 << j);
for (auto P : dp[i]){
dp[i2][P.first + ds] += P.second;
}
}
}
}
cout << dp[(1 << 16) - 1][K] << endl;
}
SSRS