結果

問題 No.1598 4×4 Grid
ユーザー 👑 kmjpkmjp
提出日時 2021-07-09 23:39:20
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 356 ms / 4,000 ms
コード長 1,475 bytes
コンパイル時間 1,976 ms
コンパイル使用メモリ 199,836 KB
実行使用メモリ 323,088 KB
最終ジャッジ日時 2023-09-14 10:59:01
合計ジャッジ時間 6,629 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 356 ms
323,088 KB
testcase_01 AC 353 ms
322,248 KB
testcase_02 AC 355 ms
322,364 KB
testcase_03 AC 354 ms
322,164 KB
testcase_04 AC 355 ms
322,452 KB
testcase_05 AC 352 ms
322,436 KB
testcase_06 AC 352 ms
322,228 KB
testcase_07 AC 353 ms
322,296 KB
testcase_08 AC 354 ms
322,448 KB
testcase_09 AC 354 ms
322,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int K;
ll dp[1<<16][1000];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	dp[0][500]=1;
	int mask;
	FOR(mask,1<<16) {
		k=__builtin_popcount(mask);
		FOR(j,1000) if(dp[mask][j]) {
			FOR(y,4) FOR(x,4) if((mask&(1<<(y*4+x)))==0) {
				int tar=j;
				if(y) {
					if((mask&(1<<((y-1)*4+x)))==0) tar-=k;
					else tar+=k;
				}
				if(y<3) {
					if((mask&(1<<((y+1)*4+x)))==0) tar-=k;
					else tar+=k;
				}
				if(x) {
					if((mask&(1<<(y*4+x-1)))==0) tar-=k;
					else tar+=k;
				}
				if(x<3) {
					if((mask&(1<<(y*4+x+1)))==0) tar-=k;
					else tar+=k;
				}
				dp[mask^(1<<(y*4+x))][tar]+=dp[mask][j];
			}
		}
	}
	
	cin>>K;
	cout<<dp[(1<<16)-1][500+K]<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0