結果

問題 No.1598 4×4 Grid
ユーザー 629e^-b629e^-b
提出日時 2021-07-10 10:06:06
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 541 ms / 4,000 ms
コード長 1,674 bytes
コンパイル時間 4,108 ms
コンパイル使用メモリ 261,452 KB
実行使用メモリ 263,940 KB
最終ジャッジ日時 2023-09-14 18:45:48
合計ジャッジ時間 10,797 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 530 ms
263,940 KB
testcase_01 AC 529 ms
263,932 KB
testcase_02 AC 525 ms
263,800 KB
testcase_03 AC 525 ms
263,924 KB
testcase_04 AC 541 ms
263,832 KB
testcase_05 AC 526 ms
263,804 KB
testcase_06 AC 521 ms
263,872 KB
testcase_07 AC 526 ms
263,864 KB
testcase_08 AC 525 ms
263,868 KB
testcase_09 AC 527 ms
263,876 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pdd = pair<ld, ld>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acos(-1);

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int K;
    cin >> K;

    vector<int> cnt(1 << 16);
    for (int i = 0; i < (1 << 16); ++i) {
        cnt[i] = __builtin_popcount(i);
    }

    int ofst = 200;
    K += ofst;
    vector<vector<ll>> dp(1 << 16, vector<ll>(505));
    dp[0][ofst] = 1;
    for (int i = 0; i < (1 << 16); ++i) {
        int num = cnt[i];

        for (int j = 0; j < 16; ++j) {
            if ((i >> j) & 1)
                continue;

            int nxt = i | (1 << j);

            int tmp = 0;
            int y = j >> 2;
            int x = j & 3;
            if (x - 1 >= 0) {
                tmp += ((i >> (j - 1)) & 1 ? num : -num);
            }
            if (y - 1 >= 0) {
                tmp += ((i >> (j - 4)) & 1 ? num : -num);
            }
            if (x + 1 < 4) {
                tmp += ((i >> (j + 1)) & 1 ? num : -num);
            }
            if (y + 1 < 4) {
                tmp += ((i >> (j + 4)) & 1 ? num : -num);
            }

            for (int k = 0; k <= 500; ++k) {
                if (k + tmp >= 0 && k + tmp <= 500) {
                    dp[nxt][k + tmp] += dp[i][k];
                }
            }
        }
    }

    cout << dp[(1 << 16) - 1][K] << endl;

    return 0;
}
0