結果

問題 No.1598 4×4 Grid
ユーザー ransewhaleransewhale
提出日時 2021-07-10 01:22:37
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2,074 ms / 4,000 ms
コード長 1,226 bytes
コンパイル時間 840 ms
コンパイル使用メモリ 90,136 KB
実行使用メモリ 186,032 KB
最終ジャッジ日時 2023-09-14 12:52:44
合計ジャッジ時間 24,420 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2,062 ms
185,944 KB
testcase_01 AC 2,046 ms
185,800 KB
testcase_02 AC 2,049 ms
185,800 KB
testcase_03 AC 2,058 ms
185,792 KB
testcase_04 AC 2,044 ms
186,032 KB
testcase_05 AC 2,055 ms
185,880 KB
testcase_06 AC 2,054 ms
185,820 KB
testcase_07 AC 2,074 ms
185,792 KB
testcase_08 AC 2,045 ms
185,860 KB
testcase_09 AC 2,051 ms
185,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0