結果
問題 | No.1598 4×4 Grid |
ユーザー | chocorusk |
提出日時 | 2021-07-09 22:57:39 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2,375 ms / 4,000 ms |
コード長 | 1,397 bytes |
コンパイル時間 | 3,413 ms |
コンパイル使用メモリ | 186,656 KB |
実行使用メモリ | 225,144 KB |
最終ジャッジ日時 | 2023-09-14 10:31:21 |
合計ジャッジ時間 | 13,832 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 59 ms
14,180 KB |
testcase_01 | AC | 467 ms
64,300 KB |
testcase_02 | AC | 477 ms
66,412 KB |
testcase_03 | AC | 911 ms
111,516 KB |
testcase_04 | AC | 1,230 ms
143,136 KB |
testcase_05 | AC | 2,134 ms
205,660 KB |
testcase_06 | AC | 2,375 ms
225,144 KB |
testcase_07 | AC | 16 ms
4,892 KB |
testcase_08 | AC | 463 ms
65,324 KB |
testcase_09 | AC | 1,420 ms
155,432 KB |
ソースコード
#include <cstdio> #include <cstring> #include <iostream> #include <string> #include <cmath> #include <bitset> #include <vector> #include <map> #include <set> #include <queue> #include <deque> #include <algorithm> #include <complex> #include <unordered_map> #include <unordered_set> #include <random> #include <cassert> #include <fstream> #include <utility> #include <functional> #include <time.h> #include <stack> #include <array> #include <list> #include <atcoder/all> #define popcount __builtin_popcount using namespace std; using namespace atcoder; typedef long long ll; typedef pair<int, int> P; ll dp[216*2+1][1<<16]; int main() { int K; cin>>K; int n=16, d=4; dp[K][0]=1; int dx[4]={1,-1,0,0}, dy[4]={0,0,1,-1}; for(int i=0; i<(1<<n); i++){ int p=popcount(i); for(int j=0; j<n; j++){ if(i&(1<<j)) continue; int x=j/d, y=j%d, t=0; for(int k=0; k<4; k++){ int x1=x+dx[k], y1=y+dy[k]; if(x1<0 || x1>=d || y1<0 || y1>=d) continue; int j1=x1*d+y1; if(i&(1<<j1)) t++; else t--; } for(int k=0; k<=2*K; k++){ int k1=k+p*t; if(k1>=0 && k1<=2*K){ dp[k1][i^(1<<j)]+=dp[k][i]; } } } } cout<<dp[2*K][(1<<n)-1]<<endl; return 0; }