QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#415635#6563. Four Squareskittles1412#WA 1ms3720kbC++172.6kb2024-05-21 07:38:362024-05-21 07:38:37

Judging History

你现在查看的是最新测评结果

  • [2024-05-21 07:38:37]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3720kb
  • [2024-05-21 07:38:36]
  • 提交

answer

#include "bits/extc++.h"

using namespace std;

template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
    cerr << t;
    ((cerr << " | " << u), ...);
    cerr << endl;
}

#ifdef DEBUG
#define dbg(...)                                           \
    cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]" \
         << ": ";                                          \
    dbgh(__VA_ARGS__)
#else
#define cerr   \
    if (false) \
    cerr
#define dbg(...)
#endif

#define endl "\n"
#define long int64_t
#define sz(x) int(std::size(x))

bool on(int mask, int bit) {
    return (mask >> bit) & 1;
}

vector<vector<int>> rotate(const vector<vector<int>>& arr) {
    int n = sz(arr);
    vector ans(n, vector(n, 0));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            ans[n - j - 1][i] = arr[i][j];
        }
    }
    return ans;
}

bool check(int m, const array<pair<int, int>, 4>& arr) {
    vector cans(m, vector(m, 0));

    for (int i = 0; i < 4; i++) {
        auto& [x, y] = arr[i];
        for (int cx = 0; cx < x; cx++) {
            for (int cy = 0; cy < y; cy++) {
                cans[cx][cy] |= 1 << i;
            }
        }

        cans = rotate(cans);
    }

    for (auto& a : cans) {
        for (auto& b : a) {
            if (__builtin_popcount(b) != 1) {
                return false;
            }
        }
    }
    return true;
}

void solve() {
    array<pair<int, int>, 4> arr;
    for (auto& [x, y] : arr) {
        cin >> x >> y;
    }

    int area = 0;
    for (auto& [x, y] : arr) {
        area += x * y;
    }
    int x;
    for (x = 0; x * x < area; x++)
        ;
    if (x * x != area) {
        cout << 0 << endl;
        return;
    }

    int perm[4] {};
    iota(begin(perm), end(perm), 0);

    do {
        if (perm[0]) {
            continue;
        }

        for (int mask = 0; mask < (1 << 4); mask++) {
            if (on(mask, 0)) {
                continue;
            }

            auto carr = arr;
            for (int i = 0; i < 4; i++) {
                carr[i] = arr[perm[i]];
                if (on(mask, i)) {
                    swap(carr[i].first, carr[i].second);
                }
            }

            if (check(x, carr)) {
                cout << 1 << endl;
                return;
            }
        }
    } while (next_permutation(begin(perm), end(perm)));

    cout << 0 << endl;
}

int main() {
    cin.tie(nullptr);
    cin.exceptions(ios::failbit);
    ios_base::sync_with_stdio(false);
    solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3524kb

input:

1 1
1 1
1 1
1 1

output:

1

result:

ok single line: '1'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3692kb

input:

3 1
3 3
2 2
3 3

output:

0

result:

ok single line: '0'

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3720kb

input:

2 8
2 8
2 8
2 8

output:

0

result:

wrong answer 1st lines differ - expected: '1', found: '0'