이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#pragma GCC optimize("Ofast,O2,O3,unroll-loops")
//#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << "[" << H << "]";
debug_out(T...);
}
#ifdef dddxxz
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
#define SZ(s) ((int)s.size())
#define all(x) (x).begin(), (x).end()
#define lla(x) (x).rbegin(), (x).rend()
#define bpc(x) __builtin_popcount(x)
#define bpcll(x) __builtin_popcountll(x)
#define MP make_pair
clock_t startTime;
double getCurrentTime() {
return (double) (clock() - startTime) / CLOCKS_PER_SEC;
}
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long long ll;
const int MOD = 998244353;
const int INF = 1000000101;
const long long LLINF = 1223372000000000555;
const int N = 1e6 + 3e2;
const int M = 1555;
int n;
vector<vector<int>> arr;
set<int> s;
void rec(int x){
if (x == n){
int cur = 0;
for (int i = 0; i < n; i++){
for (int j = 0; j < 2; j++){
int k = i * 2 + j;
if (arr[i][j]) cur += (1 << k);
}
}
s.insert(cur);
return;
}
rec(x + 1);
if (x + 1 < n && arr[x][0] == 0 && arr[x][1] == 0 && arr[x + 1][0] == 0){
arr[x][0] = 1;
arr[x][1] = 1;
arr[x + 1][0] = 1;
rec(x + 1);
arr[x][0] = 0;
arr[x][1] = 0;
arr[x + 1][0] = 0;
}
if (x + 1 < n && arr[x][0] == 0 && arr[x][1] == 0 && arr[x + 1][1] == 0){
arr[x][0] = 1;
arr[x][1] = 1;
arr[x + 1][1] = 1;
rec(x + 1);
arr[x][0] = 0;
arr[x][1] = 0;
arr[x + 1][1] = 0;
}
if (x + 1 < n && arr[x][0] == 0 && arr[x + 1][0] == 0 && arr[x + 1][1] == 0){
arr[x][0] = 1;
arr[x + 1][0] = 1;
arr[x + 1][1] = 1;
rec(x + 1);
arr[x][0] = 0;
arr[x + 1][0] = 0;
arr[x + 1][1] = 0;
}
if (x - 1 >= 0 && arr[x][0] == 0 && arr[x - 1][1] == 0 && arr[x][1] == 0){
arr[x][0] = 1;
arr[x - 1][1] = 1;
arr[x][1] = 1;
rec(x + 1);
arr[x][0] = 0;
arr[x - 1][1] = 0;
arr[x][1] = 0;
}
}
vector<int> g[1 << 13];
void build_graph(){
arr.resize(n, vector<int>(2));
rec(0);
for (int x : s){
int maskl = 0, maskr = 0;
for (int i = 0; i < n; i++){
if (x & (1 << (2 * i))) maskl |= (1 << i);
if (x & (1 << (2 * i + 1))) maskr |= (1 << i);
}
g[maskl].push_back(maskr);
}
}
void out(int mask){
for (int i = 0; i < n; i++){
if (mask & (1 << i)) {
cout << 1;
} else {
cout << 0;
}
}
cout << endl;
}
bool triominoes(vector<vector<bool>> stone){
int m = (int)stone[0].size();
vector<vector<bool>> dp(m, vector<bool>(1 << n));
for (int x = 0; x < (1 << n); x++){
for (int y : g[x]){
bool ok = true;
for (int j = 0; j < n; j++){
bool s0 = (x & (1 << j));
bool s1 = (y & (1 << j));
if (stone[j][0] && s0) ok = false;
if (stone[j][1] && s1) ok = false;
if (!stone[j][0] && !s0) ok = false;
}
if (ok) dp[1][y] = true;
}
}
for (int i = 1; i + 1 < m; i++){
for (int x = 0; x < (1 << n); x++){
if (!dp[i][x]) continue;
int xx = 0;
for (int j = 0; j < n; j++){
if (!(x & (1 << j)) && !stone[j][i]) xx |= (1 << j);
}
for (int y : g[xx]){
bool ok = true;
for (int j = 0; j < n; j++){
bool s1 = (y & (1 << j));
if (stone[j][i + 1] && s1) ok = false;
}
if (ok){
dp[i + 1][y] = true;
}
}
}
}
int full = 0;
for (int i = 0; i < n; i++){
if (!stone[i][m - 1]) full |= (1 << i);
}
return dp[m - 1][full];
}
void solve(int TC) {
int m, k;
cin >> n >> m >> k;
build_graph();
vector<pair<int, int>> stones;
set<int> pos = {0, m - 1};
while (k--){
int x, y;
cin >> x >> y;
--x, --y;
stones.emplace_back(x, y);
pos.insert(y);
}
vector<int> vec;
for (int x : pos) vec.push_back(x);
vector<int> diff;
for (int i = 0; i + 1 < vec.size(); i++) diff.push_back(vec[i + 1] - vec[i]);
map<int, int> mp;
mp[0] = 0;
int sum = 0;
for (int i = 0; i < diff.size(); i++){
if (diff[i] > 6) diff[i] %= 6;
sum += diff[i];
mp[vec[i + 1]] = sum;
}
m = sum + 1;
vector<vector<bool>> stone(n, vector<bool>(m, false));
for (auto now : stones){
int x = now.first, y = now.second;
y = mp[y];
// cout << x << ' ' << y << endl;
stone[x][y] = true;
}
bool ans = triominoes(stone);
cout << (ans ? "YES" : "NO");
}
int main() {
startTime = clock();
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#ifdef dddxxz
freopen("input.txt", "rg", stdin);
freopen("output.txt", "w", stdout);
#endif
int TC = 1;
//cin >> TC;
for (int test = 1; test <= TC; test++) {
//debug(test);
//cout << "Case #" << test << ": ";
solve(test);
}
#ifdef dddxxz
cerr << endl << "Time: " << int(getCurrentTime() * 1000) << " ms" << endl;
#endif
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
ltrominoes.cpp: In function 'void solve(int)':
ltrominoes.cpp:197:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
197 | for (int i = 0; i + 1 < vec.size(); i++) diff.push_back(vec[i + 1] - vec[i]);
| ~~~~~~^~~~~~~~~~~~
ltrominoes.cpp:202:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
202 | for (int i = 0; i < diff.size(); 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... |