QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#730426 | #6563. Four Square | ahsoltan | WA | 2ms | 3848kb | C++20 | 3.0kb | 2024-11-09 20:10:54 | 2024-11-09 20:10:54 |
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) {
if (1ll * bok * bok != pole) continue;
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";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3848kb
input:
1 1 1 1 1 1 1 1
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
3 1 3 3 2 2 3 3
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
2 8 2 8 2 8 2 8
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
5 3 5 5 3 3 3 5
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
1 2 4 8 16 32 64 128
output:
0
result:
ok single line: '0'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3848kb
input:
4 4 2 1 4 4 2 1
output:
0
result:
ok single line: '0'
Test #7:
score: 0
Accepted
time: 2ms
memory: 3512kb
input:
995 51 559 565 154 536 56 780
output:
0
result:
ok single line: '0'
Test #8:
score: 0
Accepted
time: 2ms
memory: 3496kb
input:
391 694 540 42 240 937 691 246
output:
0
result:
ok single line: '0'
Test #9:
score: 0
Accepted
time: 2ms
memory: 3652kb
input:
519 411 782 710 299 45 21 397
output:
0
result:
ok single line: '0'
Test #10:
score: 0
Accepted
time: 0ms
memory: 3500kb
input:
96 960 948 18 108 82 371 576
output:
0
result:
ok single line: '0'
Test #11:
score: 0
Accepted
time: 0ms
memory: 3508kb
input:
3 2 4 3 3 1 1 4
output:
0
result:
ok single line: '0'
Test #12:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
4 3 1 2 4 4 3 2
output:
0
result:
ok single line: '0'
Test #13:
score: 0
Accepted
time: 0ms
memory: 3608kb
input:
4 4 1 3 5 4 2 5
output:
0
result:
ok single line: '0'
Test #14:
score: 0
Accepted
time: 0ms
memory: 3648kb
input:
1000 1000 1000 1000 1000 1000 1000 1000
output:
1
result:
ok single line: '1'
Test #15:
score: 0
Accepted
time: 0ms
memory: 3808kb
input:
1000 999 998 1000 997 1000 997 997
output:
1
result:
ok single line: '1'
Test #16:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
1 3 3 3 3 3 4 7
output:
1
result:
ok single line: '1'
Test #17:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
2 5 5 4 7 1 6 2
output:
1
result:
ok single line: '1'
Test #18:
score: -100
Wrong Answer
time: 0ms
memory: 3556kb
input:
12 2 12 7 7 12 16 4
output:
0
result:
wrong answer 1st lines differ - expected: '1', found: '0'