結果

問題 No.1598 4×4 Grid
ユーザー 👑 NachiaNachia
提出日時 2021-07-09 22:02:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,746 ms / 4,000 ms
コード長 1,124 bytes
コンパイル時間 3,063 ms
コンパイル使用メモリ 152,100 KB
実行使用メモリ 188,680 KB
最終ジャッジ日時 2023-09-14 09:08:27
合計ジャッジ時間 32,876 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2,746 ms
188,680 KB
testcase_01 AC 2,682 ms
188,480 KB
testcase_02 AC 2,637 ms
188,516 KB
testcase_03 AC 2,625 ms
188,472 KB
testcase_04 AC 2,687 ms
188,512 KB
testcase_05 AC 2,628 ms
188,676 KB
testcase_06 AC 2,695 ms
188,516 KB
testcase_07 AC 2,697 ms
188,564 KB
testcase_08 AC 2,685 ms
188,560 KB
testcase_09 AC 2,697 ms
188,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/all>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace atcoder;
using namespace std;
using ll = long long;
using ull = unsigned long long;
const ull MOD = 1000000007;
using mll = static_modint<1000000007>;
#define rep(i,n) for(int i=0; i<(n); i++)

int C[1<<16];
ll dp[361][1<<16] = {};
vector<int> E[16];

int main(){
  C[0] = 0;
  rep(i,16) rep(j,1<<i) C[j+(1<<i)] = C[j] + 1;
  rep(y,4) rep(x,3) E[y*4+x].push_back(y*4+x+1);
  rep(y,4) rep(x,3) E[y*4+x+1].push_back(y*4+x);
  rep(y,3) rep(x,4) E[y*4+x].push_back(y*4+x+4);
  rep(y,3) rep(x,4) E[y*4+x+4].push_back(y*4+x);
  dp[0][0] = 1;
  rep(i,1<<16) rep(nx,16) if(0==(i&(1<<nx))){
    ll dx = 0;
    int c = 15 - C[i];
    for(int e : E[nx]){
      if(i&(1<<e)) dx -= c;
      else dx += c;
    }
    rep(k,361){
      if(k + dx < 0 || 360 < k + dx) continue;
      dp[k+dx][i|(1<<nx)] += dp[k][i];
    }
  }
  
  int K; cin >> K;
  cout << dp[K][(1<<16)-1] << endl;
  return 0;
}

struct ios_do_not_sync{
  ios_do_not_sync(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
  }
} ios_do_not_sync_inst;
0