#include <bits/stdc++.h>
using namespace std;
const int M = 1 << 10;
int n, m, k;
bool dp[13][4];
vector<pair<int, int>> A, V;
bitset<M> G[M];
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
cin >> m >> n >> k;
for (int i = 0; i < k; i++) {
int x, y; cin >> y >> x;
A.emplace_back(x, y);
}
if (n > 10) {
cout << "NO\n"; return 0;
}
sort(A.begin(), A.end(), [&](auto i, auto j) {
return i.second < j.second;
});
for (int i = 0; i < k; i++) {
auto [f, s] = A[i]; --f;
if (V.empty() || V.back().second != s) {
V.emplace_back(1 << f, s);
}
else V.back().first |= (1 << f);
}
if (V.empty() || V.back().second != m) {
V.emplace_back(0, m);
}
for (int i = 0; i < (1 << n); i++) {
for (int j = 0; j < (1 << n); j++) {
if ((n - __builtin_popcount(i) + __builtin_popcount(j)) % 3 != 0) {
continue;
}
int m = (i & 1) + (~j & 1) * 2; dp[0][m] = 1;
for (int k = 1; k < n; k++) {
int m = (i >> k & 1) + (~j >> k & 1) * 2;
if (m == 0) {
dp[k][0] = dp[k - 1][3];
dp[k][1] = dp[k][2] = dp[k - 1][0];
dp[k][3] = (dp[k - 1][1] | dp[k - 1][2]);
}
if (m == 1) {
dp[k][1] = dp[k - 1][3];
dp[k][3] = dp[k - 1][0];
}
if (m == 2) {
dp[k][2] = dp[k - 1][3];
dp[k][3] = dp[k - 1][0];
}
if (m == 3) {
dp[k][3] = dp[k - 1][3];
}
}
G[i][j] = dp[n - 1][3];
for (int i = 0; i < n; i++) for (int j = 0; j < 4; j++) {
dp[i][j] = 0;
}
}
}
/* for (int i = 0; i < 8; i++) {
vector<vector<int>> D(8, vector<int>(12, -1));
queue<pair<int, int>> Q;
Q.emplace(i, 0); D[i][0] = 0;
while (!Q.empty()) {
auto [x, m] = Q.front(); Q.pop();
for (int i = 0; i < 8; i++) if (G[x][i]) {
if (D[i][(m + 1) % 12] == -1) {
D[i][(m + 1) % 12] = D[x][m] + 1;
Q.emplace(i, (m + 1) % 12);
}
}
}
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 12; j++) {
cout << D[i][j] << ' ';
}
cout << '\n';
}
cout << '\n';
} */
int p = 0; bitset<M> dp = 0, ep = 0;
dp[(1 << n) - 1] = 1;
for (auto [f, s] : V) {
int it = s - p; /* min((s - p) % 6 + 18, s - p); */
while (it--) {
for (int i = 0; i < (1 << n); i++) if (dp[i]) {
ep |= G[i];
}
dp = ep; ep = 0;
}
for (int i = 0; i < (1 << n); i++) if (dp[i] && (i & f) == 0) {
ep[i | f] = 1;
}
dp = ep; ep = 0;
p = s;
// cout << dp << '\n';
}
cout << (dp[(1 << n) - 1] ? "YES" : "NO");
}
Compilation message
ltrominoes.cpp: In function 'int main()':
ltrominoes.cpp:24:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
24 | auto [f, s] = A[i]; --f;
| ^
ltrominoes.cpp:89:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
89 | for (auto [f, s] : V) {
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
324 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |