Submission #531592

# Submission time Handle Problem Language Result Execution time Memory
531592 2022-03-01T05:50:57 Z eecs L-triominoes (CEOI21_ltriominoes) C++17
10 / 100
8000 ms 4540 KB
#include <bits/stdc++.h>
using namespace std;

int W, H, K, x[250], y[250];
bool f[1 << 13], g[1 << 13];
vector<array<int, 2>> E;

int main() {
    scanf("%d %d %d", &W, &H, &K);
    vector<int> pos = {1, H};
    for (int S = 0; S < 1 << W; S++) {
        function<void(int, int)> dfs = [&](int i, int T) {
            if (i == W) { E.push_back({S, T}); return; }
            if (S >> i & 1) return dfs(i + 1, T);
            if (i && !(T >> (i - 1) & 1) && !(T >> i & 1)) dfs(i + 1, T | (1 << (i - 1)) | (1 << i));
            if (i + 1 == W) return;
            if (!(T >> i & 1) && !(T >> (i + 1) & 1)) dfs(i + 1, T | (1 << i) | (1 << (i + 1)));
            if (!(S >> (i + 1) & 1) && !(T >> i & 1)) dfs(i + 2, T | (1 << i));
            if (!(S >> (i + 1) & 1) && !(T >> (i + 1) & 1)) dfs(i + 2, T | (1 << (i + 1)));
        };
        dfs(0, 0);
    }
    for (int i = 0; i < K; i++) {
        scanf("%d %d", &x[i], &y[i]), pos.push_back(y[i]);
    }
    sort(pos.begin(), pos.end());
    pos.resize(unique(pos.begin(), pos.end()) - pos.begin());
    f[0] = 1;
    for (int i = 0; i < pos.size(); i++) {
        memset(g, 0, sizeof(g));
        int S = 0;
        for (int j = 0; j < K; j++) {
            if (pos[i] == y[j]) S |= 1 << (x[j] - 1);
        }
        for (int j = 0; j < 1 << W; j++) {
            if (!(j & S)) g[j | S] |= f[j];
        }
        swap(f, g);
        if (i == pos.size() - 1) break;
        for (int $ = 1; $ <= pos[i + 1] - pos[i]; $++) {
            memset(g, 0, sizeof(g));
            for (auto &e : E) g[e[1]] |= f[e[0]];
            bool flag = 0;
            for (int j = 0; j < 1 << W; j++) {
                if (f[j] ^ g[j]) { flag = 1; break; }
            }
            if (!flag) break;
            swap(f, g);
        }
    }
    puts(f[(1 << W) - 1] ? "YES" : "NO");
    return 0;
}

Compilation message

ltrominoes.cpp: In function 'int main()':
ltrominoes.cpp:29:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     for (int i = 0; i < pos.size(); i++) {
      |                     ~~^~~~~~~~~~~~
ltrominoes.cpp:39:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |         if (i == pos.size() - 1) break;
      |             ~~^~~~~~~~~~~~~~~~~
ltrominoes.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     scanf("%d %d %d", &W, &H, &K);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
ltrominoes.cpp:24:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |         scanf("%d %d", &x[i], &y[i]), pos.push_back(y[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 13 ms 288 KB Output is correct
2 Correct 8 ms 312 KB Output is correct
3 Correct 9 ms 204 KB Output is correct
4 Correct 13 ms 316 KB Output is correct
5 Correct 13 ms 204 KB Output is correct
6 Correct 15 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 6 ms 1424 KB Output is correct
9 Correct 3 ms 932 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 7 ms 1448 KB Output is correct
12 Correct 3 ms 460 KB Output is correct
13 Correct 1 ms 288 KB Output is correct
14 Correct 1 ms 292 KB Output is correct
15 Correct 19 ms 1348 KB Output is correct
16 Correct 839 ms 4540 KB Output is correct
17 Correct 56 ms 460 KB Output is correct
18 Correct 154 ms 1348 KB Output is correct
19 Correct 18 ms 312 KB Output is correct
20 Correct 830 ms 4540 KB Output is correct
21 Correct 128 ms 1432 KB Output is correct
22 Correct 13 ms 300 KB Output is correct
23 Correct 16 ms 324 KB Output is correct
24 Correct 14 ms 204 KB Output is correct
25 Correct 835 ms 4532 KB Output is correct
26 Correct 843 ms 4532 KB Output is correct
27 Correct 9 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 8071 ms 204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 8058 ms 300 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 8074 ms 300 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 8071 ms 204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 288 KB Output is correct
2 Correct 8 ms 312 KB Output is correct
3 Correct 9 ms 204 KB Output is correct
4 Correct 13 ms 316 KB Output is correct
5 Correct 13 ms 204 KB Output is correct
6 Correct 15 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 6 ms 1424 KB Output is correct
9 Correct 3 ms 932 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 7 ms 1448 KB Output is correct
12 Correct 3 ms 460 KB Output is correct
13 Correct 1 ms 288 KB Output is correct
14 Correct 1 ms 292 KB Output is correct
15 Correct 19 ms 1348 KB Output is correct
16 Correct 839 ms 4540 KB Output is correct
17 Correct 56 ms 460 KB Output is correct
18 Correct 154 ms 1348 KB Output is correct
19 Correct 18 ms 312 KB Output is correct
20 Correct 830 ms 4540 KB Output is correct
21 Correct 128 ms 1432 KB Output is correct
22 Correct 13 ms 300 KB Output is correct
23 Correct 16 ms 324 KB Output is correct
24 Correct 14 ms 204 KB Output is correct
25 Correct 835 ms 4532 KB Output is correct
26 Correct 843 ms 4532 KB Output is correct
27 Correct 9 ms 204 KB Output is correct
28 Execution timed out 8071 ms 204 KB Time limit exceeded
29 Halted 0 ms 0 KB -