This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O3")
#pragma GCC target("avx,avx2,sse4")
#include <bits/stdc++.h>
using namespace std;
constexpr size_t W = 13, K = 250;
struct bmatrix
{
uint64_t mat[1 << W][1 << (W - 6)];
void mul_vec(uint64_t const v[1 << (W - 6)], uint64_t res[1 << (W - 6)]) const
{
memset(res, 0, sizeof res);
for (size_t i = 0; i < 1U << W; ++i)
for (size_t j = 0; j < 1U << (W - 6); ++j)
if (mat[i][j] & v[j])
{
res[i] = 1;
break;
}
}
};
pair<size_t, size_t> p[K];
bmatrix transitions;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
size_t w, h, k;
cin >> w >> h >> k;
assert(h <= 1000);
for (size_t i = 0; i < k; ++i)
cin >> p[i].first >> p[i].second, --p[i].first, --p[i].second;
for (size_t y = 0; y < 1 << w; ++y)
{
queue<uint32_t> q;
q.push(y << W);
while (!q.empty())
{
uint32_t u = q.front();
q.pop();
size_t i = u >> W, j = u & ((1 << W) - 1);
if (i == (1 << w) - 1)
{
transitions.mat[j][y] = 1;
continue;
}
for (size_t h = 0; h < w; ++h)
if (!(i & (1 << h)))
{
if (h && !(j & (1 << h)) && !(j & (1 << (h - 1))))
{
size_t ni = i ^ (1 << h), nj = j ^ (1 << h) ^ (1 << (h - 1));
q.push((ni << W) | nj);
}
if (h + 1 < w && !(j & (1 << h)) && !(j & (1 << (h + 1))))
{
size_t ni = i ^ (1 << h), nj = j ^ (1 << h) ^ (1 << (h + 1));
q.push((ni << W) | nj);
}
if (h + 1 < w && !(i & (1 << (h + 1))) && !(j & (1 << h)))
{
size_t ni = i ^ (1 << h) ^ (1 << (h + 1)), nj = j ^ (1 << h);
q.push((ni << W) | nj);
}
if (h + 1 < w && !(i & (1 << (h + 1))) && !(j & (1 << (h + 1))))
{
size_t ni = i ^ (1 << h) ^ (1 << (h + 1)), nj = j ^ (1 << (h + 1));
q.push((ni << W) | nj);
}
}
}
}
uint64_t *state = (uint64_t *)calloc((1 << (W - 6)), sizeof *state);
uint64_t *state2 = (uint64_t *)calloc((1 << (W - 6)), sizeof *state2);
sort(p, p + k, [](auto const &a, auto const &b)
{ return a.second < b.second; });
size_t i = 0, pos = 0;
if (k && !p[0].second)
{
size_t x = 0;
while (!p[i].second)
x |= 1 << p[i].first, ++i;
state[x >> 6] |= 1 << (x & 63);
}
else
state[0] = 1;
while (i < k)
{
while (pos < p[i].second)
{
transitions.mul_vec(state, state2), ++pos;
swap(state, state2);
}
size_t x = 0;
size_t j = i;
while (j < k && p[j].second == p[i].second)
x |= 1 << p[j].first, ++j;
i = j;
memset(state2, 0, sizeof state2);
for (size_t i = 0; i < 1 << w; ++i)
if (!(i & x) && (state[i >> 6] & (i & 63)))
state2[(i ^ x) >> 6] |= 1 << ((i ^ x) & 63);
state = state2;
}
while (pos < h - 1)
{
transitions.mul_vec(state, state2), ++pos;
swap(state, state2);
}
cout << ((state[((1 << w) - 1) >> 6] & (1 << (((1 << w) - 1) & 63))) ? "YES" : "NO") << '\n';
}
Compilation message (stderr)
ltrominoes.cpp: In member function 'void bmatrix::mul_vec(const uint64_t*, uint64_t*) const':
ltrominoes.cpp:15:31: warning: 'sizeof' on array function parameter 'res' will return size of 'uint64_t*' {aka 'long unsigned int*'} [-Wsizeof-array-argument]
15 | memset(res, 0, sizeof res);
| ^~~
ltrominoes.cpp:13:59: note: declared here
13 | void mul_vec(uint64_t const v[1 << (W - 6)], uint64_t res[1 << (W - 6)]) const
| ~~~~~~~~~^~~~~~~~~~~~~~~~~
ltrominoes.cpp:15:24: warning: argument to 'sizeof' in 'void* memset(void*, int, size_t)' call is the same expression as the destination; did you mean to dereference it? [-Wsizeof-pointer-memaccess]
15 | memset(res, 0, sizeof res);
| ^~~~~~~~~~
ltrominoes.cpp: In function 'int main()':
ltrominoes.cpp:41:26: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
41 | for (size_t y = 0; y < 1 << w; ++y)
| ~~^~~~~~~~
ltrominoes.cpp:53:19: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
53 | if (i == (1 << w) - 1)
| ~~^~~~~~~~~~~~~~~
ltrominoes.cpp:115:27: warning: argument to 'sizeof' in 'void* memset(void*, int, size_t)' call is the same expression as the destination; did you mean to dereference it? [-Wsizeof-pointer-memaccess]
115 | memset(state2, 0, sizeof state2);
| ^~~~~~~~~~~~~
ltrominoes.cpp:116:30: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
116 | for (size_t i = 0; i < 1 << w; ++i)
| ~~^~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |