結果
| 問題 | No.1598 4×4 Grid |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-07-10 01:22:37 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 2,206 ms / 4,000 ms |
| コード長 | 1,226 bytes |
| 記録 | |
| コンパイル時間 | 1,363 ms |
| コンパイル使用メモリ | 86,920 KB |
| 最終ジャッジ日時 | 2025-01-22 23:27:42 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 7 |
ソースコード
#include <stdio.h>
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);
#define l_ength size
void mul_mod(ll& a, ll b){
a *= b;
a %= MOD;
}
void add_mod(ll& a, ll b){
a = (a<MOD)?a:(a-MOD);
b = (b<MOD)?b:(b-MOD);
a += b;
a = (a<MOD)?a:(a-MOD);
}
std::map<int, ll> dp[2<<16];
std::map<int, ll>::iterator itr;
bool use[4][4];
int cnt[2];
void check(int x, int y){
if(0<=x && x<4 && 0<=y && y<4){
++cnt[use[x][y]];
}
}
int main(void){
int i,m=(1<<16),n=16,k,j,x,y,d;
std::cin >> k;
dp[0][0] = 1ll;
for(i=0; i<m; ++i){
d = __builtin_popcount(i);
for(j=0; j<n; ++j){
use[j/4][j%4] = (i>>j)&1;
}
for(itr=dp[i].begin(); itr!=dp[i].end(); ++itr){
// std::cout << i << " " << ((*itr).first) << " " << ((*itr).second) << std::endl;
for(x=0; x<4; ++x){
for(y=0; y<4; ++y){
if(use[x][y]){
continue;
}
j = x*4+y;
cnt[0] = 0; cnt[1] = 0;
check(x-1,y); check(x+1,y);
check(x,y-1); check(x,y+1);
dp[i+(1<<j)][(*itr).first+d*(cnt[1]-cnt[0])] += (*itr).second;
}
}
}
}
std::cout << (dp[m-1][k]) << std::endl;
return 0;
}