Submission #21090436
Source Code Expand
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define ld long double
#define TIME 1.0*clock()/CLOCKS_PER_SEC
#define pii pair < int , int >
#define Endl '\n'
#define endl '\n'
#pragma GCC optimize("Ofast")
using namespace std;
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree <T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
mt19937 gen(chrono::system_clock::now().time_since_epoch().count());
const ll mod = 1e9 + 7;
const int FFTM = 2e9 + 9;
const int SX[4] = {0 , 1 , - 1 , 0};
const int SY[4] = {1 , 0 , 0 , - 1};
const int rx[8] = {1, - 1, 0, 0, 1, 1, -1, -1};
const int ry[8] = {0, 0, 1, - 1, 1, - 1, 1, -1};
const int kx[8] = {1, 1, -1, -1, 2, 2, -2, -2};
const int ky[8] = {2, -2, 2, -2, 1, -1, 1, -1};
typedef cc_hash_table< int, int, hash<int>, equal_to<int>, direct_mask_range_hashing<int>, hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<true>, true>> ht;
int n, m, a, b;
int can[(int)pow(3, 16) + 10];
int c[17][17];
bool ok(int x, int y){
return x >= 0 && x <= n - 1 && y >= 0 && y <= m - 1;
}
void get_(int mask){
for (int i = n - 1;i >= 0; --i){
for (int j = m - 1;j >= 0; --j){
c[i][j] = mask % 3;
mask /= 3;
}
}
}
int ans = 0;
void go(int mask, int kol = 0){
if (can[mask])return;
can[mask] = 1;
if (kol == a){
ans++;
// for (int i = 0;i < n; ++i){
// for (int j = 0;j < m; ++j){
// cout << c[i][j] << " ";
// }
// cout << endl;
// }
// cout << endl;
return;
}
for (int i = 0;i < n; ++i){
for (int j = 0;j < m; ++j){
if (c[i][j] == 0){
for (int k = 0;k < 4; ++k){
int ni = i + SX[k];
int nj = j + SY[k];
if (ok(ni, nj) && c[ni][nj] == 0){
c[i][j] = c[ni][nj] = (k == 0 || k == 3 ? 1 : 2);
int nw_mask = 0;
for (int i1 = 0;i1 < n; ++i1){
for (int j1 = 0;j1 < m; ++j1){
nw_mask *= 3;
nw_mask += c[i1][j1];
}
}
go(nw_mask, kol + 1);
c[i][j] = c[ni][nj] = 0;
}
}
}
}
}
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#else
// freopen("domino-covering-1.in", "r", stdin);
// freopen("domino-covering-1.out", "w", stdout);
#endif
cin >> n >> m >> a >> b;
if (n > m)swap(n, m);
go(0);
cout << ans << endl;
return 0;
}
Submission Info
| Submission Time |
|
| Task |
D - Hanjo |
| User |
Adamenko |
| Language |
C++ (GCC 9.2.1) |
| Score |
400 |
| Code Size |
3216 Byte |
| Status |
AC |
| Exec Time |
19 ms |
| Memory |
11436 KiB |
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
400 / 400 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
01_sample.txt, 02_sample.txt, 03_sample.txt |
| All |
01_sample.txt, 02_sample.txt, 03_sample.txt, 04_11.txt, 05_44.txt, 06_44.txt, 07_44.txt, 08_44.txt, 09_44.txt, 10_44.txt, 11_44.txt, 12_28.txt, 13_28.txt, 14_28.txt, 15_28.txt, 16_28.txt, 17_28.txt, 18_28.txt, 19_116.txt, 20_116.txt, 21_116.txt, 22_115.txt, 23_115.txt, 24_35.txt, 25_35.txt, 26_35.txt, 27_35.txt, 28_35.txt, 29_35.txt, 30_35.txt, 31_35.txt, 32_33.txt, 33_33.txt, 34_33.txt, 35_1x.txt, 36_1x.txt, 37_1x.txt, 38_1x.txt, 39_1x.txt, 40_1x.txt, 41_1x.txt, 42_1x.txt, 43_small.txt, 44_small.txt, 45_small.txt, 46_small.txt, 47_small.txt, 48_small.txt, 49_small.txt, 50_small.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 01_sample.txt |
AC |
5 ms |
3480 KiB |
| 02_sample.txt |
AC |
4 ms |
3592 KiB |
| 03_sample.txt |
AC |
16 ms |
9108 KiB |
| 04_11.txt |
AC |
2 ms |
3508 KiB |
| 05_44.txt |
AC |
2 ms |
3496 KiB |
| 06_44.txt |
AC |
5 ms |
3616 KiB |
| 07_44.txt |
AC |
4 ms |
4040 KiB |
| 08_44.txt |
AC |
6 ms |
5352 KiB |
| 09_44.txt |
AC |
14 ms |
8560 KiB |
| 10_44.txt |
AC |
17 ms |
8984 KiB |
| 11_44.txt |
AC |
19 ms |
9112 KiB |
| 12_28.txt |
AC |
2 ms |
3476 KiB |
| 13_28.txt |
AC |
3 ms |
4056 KiB |
| 14_28.txt |
AC |
10 ms |
8012 KiB |
| 15_28.txt |
AC |
14 ms |
10104 KiB |
| 16_28.txt |
AC |
15 ms |
11148 KiB |
| 17_28.txt |
AC |
16 ms |
11424 KiB |
| 18_28.txt |
AC |
16 ms |
11436 KiB |
| 19_116.txt |
AC |
4 ms |
4128 KiB |
| 20_116.txt |
AC |
2 ms |
3716 KiB |
| 21_116.txt |
AC |
2 ms |
3576 KiB |
| 22_115.txt |
AC |
4 ms |
3908 KiB |
| 23_115.txt |
AC |
3 ms |
3928 KiB |
| 24_35.txt |
AC |
3 ms |
3496 KiB |
| 25_35.txt |
AC |
2 ms |
3608 KiB |
| 26_35.txt |
AC |
3 ms |
3948 KiB |
| 27_35.txt |
AC |
5 ms |
5008 KiB |
| 28_35.txt |
AC |
8 ms |
6476 KiB |
| 29_35.txt |
AC |
10 ms |
7336 KiB |
| 30_35.txt |
AC |
13 ms |
7640 KiB |
| 31_35.txt |
AC |
15 ms |
7548 KiB |
| 32_33.txt |
AC |
2 ms |
3552 KiB |
| 33_33.txt |
AC |
3 ms |
3548 KiB |
| 34_33.txt |
AC |
4 ms |
3556 KiB |
| 35_1x.txt |
AC |
4 ms |
3812 KiB |
| 36_1x.txt |
AC |
3 ms |
3548 KiB |
| 37_1x.txt |
AC |
3 ms |
3636 KiB |
| 38_1x.txt |
AC |
3 ms |
3636 KiB |
| 39_1x.txt |
AC |
2 ms |
3532 KiB |
| 40_1x.txt |
AC |
3 ms |
3612 KiB |
| 41_1x.txt |
AC |
3 ms |
3856 KiB |
| 42_1x.txt |
AC |
2 ms |
3460 KiB |
| 43_small.txt |
AC |
6 ms |
5360 KiB |
| 44_small.txt |
AC |
2 ms |
3624 KiB |
| 45_small.txt |
AC |
2 ms |
3768 KiB |
| 46_small.txt |
AC |
3 ms |
3984 KiB |
| 47_small.txt |
AC |
4 ms |
4392 KiB |
| 48_small.txt |
AC |
3 ms |
4056 KiB |
| 49_small.txt |
AC |
2 ms |
3612 KiB |
| 50_small.txt |
AC |
5 ms |
4620 KiB |