結果

問題 No.1598 4×4 Grid
ユーザー saksak
提出日時 2021-07-09 22:40:30
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 218 ms / 4,000 ms
コード長 1,261 bytes
コンパイル時間 2,340 ms
コンパイル使用メモリ 207,804 KB
実行使用メモリ 116,572 KB
最終ジャッジ日時 2023-09-14 10:00:10
合計ジャッジ時間 5,272 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 218 ms
116,572 KB
testcase_01 AC 218 ms
116,240 KB
testcase_02 AC 218 ms
116,392 KB
testcase_03 AC 217 ms
116,412 KB
testcase_04 AC 216 ms
116,236 KB
testcase_05 AC 216 ms
116,276 KB
testcase_06 AC 214 ms
116,352 KB
testcase_07 AC 215 ms
116,336 KB
testcase_08 AC 215 ms
116,232 KB
testcase_09 AC 213 ms
116,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (ll i=(ll)N-1; i>=0; i--)
#define popcount __builtin_popcount

const ll LLINF = pow(2,61)-1;
const ll INF = pow(2,30)-1;

ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

int main() {
  ll K; cin >> K;
  ll N = 4, N2 = N*N , MA = 216;
  vector<vector<ll>> dp(1<<N2,vector<ll>(MA+1)); dp[0][0] = 1;
  rep(i,1<<N2) {
    vector<vector<bool>> used(N, vector<bool>(N));
    rep(j,N2) used[j/N][j%N] = i>>j&1;
    ll pls = 0;
    rep(h,N) rep(w,N-1) pls += used[h][w]^used[h][w+1];
    rep(h,N-1) rep(w,N) pls += used[h][w]^used[h+1][w];
    // cout << pls << endl; rep(j,N) debug(all(used[j])); cout << endl;
    rep(j,N2) {
      if ((i&1<<j)) continue;
      rep(k,MA+1-pls) dp[i^1<<j][k+pls] += dp[i][k];
    }
  }
  // debug(all(dp[(1<<N2)-1]));
  ll result = dp[(1<<N2)-1][K];
  cout << result << endl;
  return 0;
}
0