結果
問題 | No.1598 4×4 Grid |
ユーザー | SSRS |
提出日時 | 2021-07-09 22:33:59 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,542 ms / 4,000 ms |
コード長 | 906 bytes |
コンパイル時間 | 1,770 ms |
コンパイル使用メモリ | 176,200 KB |
実行使用メモリ | 182,668 KB |
最終ジャッジ日時 | 2023-09-14 09:52:59 |
合計ジャッジ時間 | 19,354 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1,527 ms
182,500 KB |
testcase_01 | AC | 1,542 ms
182,616 KB |
testcase_02 | AC | 1,526 ms
182,588 KB |
testcase_03 | AC | 1,525 ms
182,544 KB |
testcase_04 | AC | 1,522 ms
182,548 KB |
testcase_05 | AC | 1,532 ms
182,668 KB |
testcase_06 | AC | 1,531 ms
182,504 KB |
testcase_07 | AC | 1,539 ms
182,500 KB |
testcase_08 | AC | 1,532 ms
182,508 KB |
testcase_09 | AC | 1,535 ms
182,484 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; vector<int> dx = {1, 0, -1, 0}; vector<int> dy = {0, 1, 0, -1}; int main(){ int K; cin >> K; vector<map<int, long long>> dp(1 << 16); dp[0][0] = 1; for (int i = 0; i < (1 << 16); i++){ int p = __builtin_popcount(i); for (int j = 0; j < 16; j++){ if ((i >> j & 1) == 0){ int x = j / 4; int y = j % 4; int ds = 0; for (int k = 0; k < 4; k++){ int x2 = x + dx[k]; int y2 = y + dy[k]; if (0 <= x2 && x2 < 4 && 0 <= y2 && y2 < 4){ int id = x2 * 4 + y2; if ((i >> id & 1) == 1){ ds += p; } else { ds -= p; } } } int i2 = i + (1 << j); for (auto P : dp[i]){ dp[i2][P.first + ds] += P.second; } } } } cout << dp[(1 << 16) - 1][K] << endl; }