結果
問題 | No.1598 4×4 Grid |
ユーザー | 沙耶花 |
提出日時 | 2021-07-09 21:59:49 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 534 ms / 4,000 ms |
コード長 | 1,051 bytes |
コンパイル時間 | 4,444 ms |
コンパイル使用メモリ | 263,932 KB |
実行使用メモリ | 262,204 KB |
最終ジャッジ日時 | 2023-09-14 09:00:39 |
合計ジャッジ時間 | 10,559 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 534 ms
262,104 KB |
testcase_01 | AC | 534 ms
262,180 KB |
testcase_02 | AC | 527 ms
262,008 KB |
testcase_03 | AC | 528 ms
262,204 KB |
testcase_04 | AC | 522 ms
262,112 KB |
testcase_05 | AC | 528 ms
262,032 KB |
testcase_06 | AC | 526 ms
262,012 KB |
testcase_07 | AC | 528 ms
262,060 KB |
testcase_08 | AC | 523 ms
262,140 KB |
testcase_09 | AC | 526 ms
262,076 KB |
ソースコード
#include <stdio.h> #include <bits/stdc++.h> #include <atcoder/all> using namespace atcoder; using mint = modint1000000007; using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf 1000000001 int main(){ int K; cin>>K; vector dp(1<<16,vector<long long>(500,0)); int center = 250; vector B(17,vector<int>()); rep(i,1<<16){ int c = 0; rep(j,16){ if((i>>j)&1)c++; } B[c].push_back(i); } dp[0][center] = 1LL; vector<int> dx = {1,-1,0,0},dy = {0,0,1,-1}; rep(i,16){ rep(j,B[i].size()){ int b = B[i][j]; rep(k,500){ if(dp[b][k]==0)continue; rep(l,16){ if((b>>l)&1)continue; int nb = b | (1<<l); int nk = k; int y = l%4,x = l/4; rep(d,4){ int yy = y+dy[d],xx = x+dx[d]; if(yy<0||yy>=4||xx<0||xx>=4)continue; int t = yy + xx*4; if((b>>t)&1){ nk += i; } else{ nk -= i; } } dp[nb][nk] += dp[b][k]; } } } } cout<<dp.back()[250+K]<<endl; return 0; }