QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#729073 | #6563. Four Square | ahsoltan# | WA | 1ms | 3648kb | C++20 | 2.9kb | 2024-11-09 16:27:03 | 2024-11-09 16:27:04 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define all(x) begin(x), end(x)
#define sz(x) int((x).size())
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
#ifdef LOCAL
auto operator<<(auto& o, auto x) -> decltype(x.first, o);
auto operator<<(auto& o, auto x) -> decltype(x.end(), o) {
o << "{";
for (int i = 0; auto y : x) o << ", " + !i++ * 2 << y;
return o << "}";
}
auto operator<<(auto& o, auto x) -> decltype(x.first, o) {
return o << "(" << x.first << ", " << x.second << ")";
}
void __print(auto... x) { ((cerr << x << " "), ...) << endl; }
#define debug(x...) __print("[" #x "]:", x)
#else
#define debug(...) 2137
#endif
bool inter(int x1, int y1, int x2, int y2) {
int xx = max(x1, x2);
int yy = min(y1, y2);
return xx <= yy;
}
bool in(int n, int m, int x, int y) {
return x >= 0 && x < n && y >= 0 && y < m;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
vector<pii> w(4);
int pole = 0;
rep(i, 0, 4) {
cin >> w[i].first >> w[i].second;
pole += w[i].first * w[i].second;
}
for (int bok = 1; bok <= pole; bok++) {
if (pole % bok == 0) {
int n = bok;
int m = pole / bok;
auto w2 = w;
rep(msk, 0, 1 << 4) {
rep(i, 0, 4) if ((msk >> i) & 1) swap(w2[i].first, w2[i].second);
sort(all(w2));
do {
vector<array<int, 4>> juz;
vector<pii> p;
p.push_back({0, 0});
rep(i, 0, 4) {
sort(all(p));
for (auto [x, y] : p) {
bool ok = 1;
for (auto [x1, y1, h, w] : juz) {
if (x1 <= x && x < x1 + h && y1 <= y && y < y1 + w) {
ok = 0;
break;
}
}
if (x < 0 || x >= n || y < 0 || y >= m) ok = 0;
auto [h, w] = w2[i];
if (ok) {
juz.push_back({x, y, h, w});
p.push_back({x, y + w});
p.push_back({x + h, y});
break;
}
}
}
bool ok = 1;
if (sz(juz) != 4) {
continue;
}
rep(i, 0, 4) rep(j, i + 1, 4) {
auto [x1, y1, h1, w1] = juz[i];
auto [x2, y2, h2, w2] = juz[j];
debug(x1, y1, h1, w1);
debug(x2, y2, h2, w2);
if (inter(x1, x1 + h1 - 1, x2, x2 + h2 - 1) && inter(y1, y1 + w1 - 1, y2, y2 + w2 - 1)) {
ok = 0;
break;
}
}
for (auto [x, y, h, w] : juz) {
if (!in(n, m, x, y) || !in(n, m, x + h - 1, y + w - 1)) {
ok = 0;
break;
}
}
if (ok) {
debug(n, m, juz);
cout << 1 << '\n';
return 0;
}
} while (next_permutation(all(w2)));
}
}
}
cout << "0\n";
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3552kb
input:
1 1 1 1 1 1 1 1
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3584kb
input:
3 1 3 3 2 2 3 3
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
2 8 2 8 2 8 2 8
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3648kb
input:
5 3 5 5 3 3 3 5
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 1ms
memory: 3552kb
input:
1 2 4 8 16 32 64 128
output:
0
result:
ok single line: '0'
Test #6:
score: -100
Wrong Answer
time: 0ms
memory: 3556kb
input:
4 4 2 1 4 4 2 1
output:
1
result:
wrong answer 1st lines differ - expected: '0', found: '1'