답안 #752699

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
752699 2023-06-03T12:46:01 Z 이동현(#9968) L-triominoes (CEOI21_ltriominoes) C++17
0 / 100
221 ms 524288 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define int long long
#define mi(x, y) (x = min(x, y))
#define ma(x, y) (x = max(x, y))
using namespace std;

const int NS = 13;
int way[(1 << NS) + 4][(1 << NS) + 4];
vector<int> vway[(1 << NS) + 4];
int dist[(1 << NS) + 4];

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int w, h, k;
    cin >> w >> h >> k;
    vector<pair<int, int>> a(k);
    for(int i = 0; i < k; ++i){
        cin >> a[i].first >> a[i].second;
        --a[i].first, --a[i].second;
    }
    sort(a.begin(), a.end());

    for(int i = 0; i < (1 << h); ++i){
        auto dfs = [&](auto&&self, int x, int bt)->void{
            int now = (i >> x & 1);
            if(now){
                self(self, x + 1, bt);
                return;
            }
            if(x == h){
                way[i][bt] = 1;
                return;
            }
            int nxt = (i >> (x + 1) & 1);
            int btnow = (bt >> x & 1);

            if(x + 1 < h && !nxt && !btnow){
                self(self, x + 2, bt | 1 << x);
            }
            if(x + 1 < h && !nxt){
                self(self, x + 2, bt | 1 << (x + 1));
            }
            if(x + 1 < h && !btnow){
                self(self, x + 1, bt | 1 << x | 1 << (x + 1));
            }
            if(!btnow && x && !(bt >> (x - 1) & 1)){
                self(self, x + 1, bt | 1 << x | 1 << (x - 1));
            }
        };
        dfs(dfs, 0, 0);
        for(int j = 0; j < (1 << h); ++j){
            if(way[i][j]){
                vway[i].push_back(j);
            }
        }
    }

    vector<int> dp(1 << h);
    int p = 0, bt = 0;
    while(p < k && a[p].first == 0){
        bt |= (1 << a[p].second);
        ++p;
    }
    dp[bt] = 1;
    for(int i = 1; i < w; ++i){
        bt = 0;
        while(p < k && a[p].first == i){
            bt |= (1 << a[p].second);
            ++p;
        }
        vector<int> ndp(1 << h);
        for(int j = 0; j < (1 << h); ++j){
            if(!dp[j]) continue;
            for(auto&nxt:vway[j]){
                //cout << i << ' ' << j << ' ' << nxt << ' ' << bt << endl;
                if(!(nxt & bt)){
                    ndp[nxt | bt] = 1;
                }
            }
        }
        swap(dp, ndp);
    }

    if(dp[(1 << h) - 1]){
        cout << "YES\n";
    }
    else{
        cout << "NO\n";
    }
    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 8 ms 724 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 220 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 11 ms 852 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 221 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 10 ms 852 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 8 ms 724 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -