답안 #617451

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
617451 2022-08-01T11:26:07 Z dxz05 L-triominoes (CEOI21_ltriominoes) C++14
10 / 100
1016 ms 524288 KB
//#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 out(int mask){
    for (int i = 0; i < n; i++){
        if (mask & (1 << i)) {
            cout << 1;
        } else {
            cout << 0;
        }
    }
    cout << endl;
}

void solve(int TC) {
    int m, k;
    cin >> n >> m >> k;

    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);
    }

    vector<vector<bool>> stone(n, vector<bool>(m, false));
    while (k--){
        int x, y;
        cin >> x >> y;
        --x, --y;
        stone[x][y] = true;
    }

    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;
//                out(x); out(y);
            }
        }
    }

    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);
    }

    cout << (dp[m - 1][full] ? "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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 516 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 524 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 2 ms 528 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 67 ms 4404 KB Output is correct
9 Correct 11 ms 1932 KB Output is correct
10 Correct 5 ms 724 KB Output is correct
11 Correct 103 ms 4456 KB Output is correct
12 Correct 6 ms 1028 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 520 KB Output is correct
15 Correct 29 ms 4300 KB Output is correct
16 Correct 946 ms 11704 KB Output is correct
17 Correct 63 ms 1236 KB Output is correct
18 Correct 375 ms 4876 KB Output is correct
19 Correct 4 ms 628 KB Output is correct
20 Correct 1016 ms 11700 KB Output is correct
21 Correct 346 ms 4896 KB Output is correct
22 Correct 2 ms 596 KB Output is correct
23 Correct 5 ms 596 KB Output is correct
24 Correct 1 ms 596 KB Output is correct
25 Correct 997 ms 11708 KB Output is correct
26 Correct 977 ms 11704 KB Output is correct
27 Correct 1 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 239 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 362 ms 496956 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 616 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 217 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 516 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 524 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 2 ms 528 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 67 ms 4404 KB Output is correct
9 Correct 11 ms 1932 KB Output is correct
10 Correct 5 ms 724 KB Output is correct
11 Correct 103 ms 4456 KB Output is correct
12 Correct 6 ms 1028 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 520 KB Output is correct
15 Correct 29 ms 4300 KB Output is correct
16 Correct 946 ms 11704 KB Output is correct
17 Correct 63 ms 1236 KB Output is correct
18 Correct 375 ms 4876 KB Output is correct
19 Correct 4 ms 628 KB Output is correct
20 Correct 1016 ms 11700 KB Output is correct
21 Correct 346 ms 4896 KB Output is correct
22 Correct 2 ms 596 KB Output is correct
23 Correct 5 ms 596 KB Output is correct
24 Correct 1 ms 596 KB Output is correct
25 Correct 997 ms 11708 KB Output is correct
26 Correct 977 ms 11704 KB Output is correct
27 Correct 1 ms 596 KB Output is correct
28 Runtime error 239 ms 524288 KB Execution killed with signal 9
29 Halted 0 ms 0 KB -