QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#112167 | #6563. Four Square | maomao90# | AC ✓ | 54ms | 254784kb | C++17 | 2.7kb | 2023-06-10 14:15:43 | 2023-06-10 14:15:46 |
Judging History
answer
// Hallelujah, praise the one who set me free
// Hallelujah, death has lost its grip on me
// You have broken every chain, There's salvation in your name
// Jesus Christ, my living hope
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define RREP(i, s, e) for (int i = (s); i >= (e); i--)
template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
typedef long long ll;
typedef long double ld;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define SZ(_a) (int) _a.size()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<iii> viii;
#ifndef DEBUG
#define cerr if (0) cerr
#endif
const int INF = 1000000005;
const ll LINF = 1000000000000000005ll;
const int MAXN = 2005;
ii wh[4];
int memo[1 << 4][MAXN][MAXN];
bool solve(int msk, int n, int m) {
if (msk == 0) {
if (n == 0 || m == 0) {
return 1;
} else {
return 0;
}
}
if (memo[msk][n][m] != -1) {
return memo[msk][n][m];
}
/*
if (SZ(wh) == 1) {
auto [w, h] = wh[0];
if (min(w, h) == min(n, m) && max(w, h) == max(n, m)) {
return 1;
} else {
return 0;
}
}
*/
cerr << bitset<4>(msk) << ' ' << n << ' ' << m << '\n';
REP (i, 0, 4) {
if (msk >> i & 1 ^ 1) {
continue;
}
auto [w, h] = wh[i];
REP (z, 0, 2) {
swap(w, h);
if (w > n || h > m) {
continue;
}
int nmsk = msk ^ (1 << i);
for (int k = nmsk; ; k = (k - 1) & nmsk) {
bool res = (solve(k, n - w, m) && solve(nmsk ^ k, w, m - h)) ||
(solve(k, n - w, h) && solve(nmsk ^ k, n, m - h));
if (res) {
return memo[msk][n][m] = 1;
}
if (k == 0) {
break;
}
}
}
}
return memo[msk][n][m] = 0;
}
int main() {
#ifndef DEBUG
ios::sync_with_stdio(0), cin.tie(0);
#endif
int area = 0;
REP (i, 0, 4) {
int w, h; cin >> w >> h;
wh[i] = {w, h};
area += w * h;
}
int sq = -1;
REP (i, 1, area + 1) {
if ((ll) i * i == area) {
sq = i;
break;
}
}
if (sq == -1) {
cout << 0 << '\n';
return 0;
}
memset(memo, -1, sizeof memo);
cout << solve((1 << 4) - 1, sq, sq) << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 23ms
memory: 254604kb
input:
1 1 1 1 1 1 1 1
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 29ms
memory: 254596kb
input:
3 1 3 3 2 2 3 3
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 54ms
memory: 254660kb
input:
2 8 2 8 2 8 2 8
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 41ms
memory: 254668kb
input:
5 3 5 5 3 3 3 5
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 3ms
memory: 3472kb
input:
1 2 4 8 16 32 64 128
output:
0
result:
ok single line: '0'
Test #6:
score: 0
Accepted
time: 40ms
memory: 254572kb
input:
4 4 2 1 4 4 2 1
output:
0
result:
ok single line: '0'
Test #7:
score: 0
Accepted
time: 39ms
memory: 254780kb
input:
995 51 559 565 154 536 56 780
output:
0
result:
ok single line: '0'
Test #8:
score: 0
Accepted
time: 19ms
memory: 254568kb
input:
391 694 540 42 240 937 691 246
output:
0
result:
ok single line: '0'
Test #9:
score: 0
Accepted
time: 47ms
memory: 254520kb
input:
519 411 782 710 299 45 21 397
output:
0
result:
ok single line: '0'
Test #10:
score: 0
Accepted
time: 36ms
memory: 254664kb
input:
96 960 948 18 108 82 371 576
output:
0
result:
ok single line: '0'
Test #11:
score: 0
Accepted
time: 16ms
memory: 254516kb
input:
3 2 4 3 3 1 1 4
output:
0
result:
ok single line: '0'
Test #12:
score: 0
Accepted
time: 8ms
memory: 254668kb
input:
4 3 1 2 4 4 3 2
output:
0
result:
ok single line: '0'
Test #13:
score: 0
Accepted
time: 36ms
memory: 254764kb
input:
4 4 1 3 5 4 2 5
output:
0
result:
ok single line: '0'
Test #14:
score: 0
Accepted
time: 20ms
memory: 254784kb
input:
1000 1000 1000 1000 1000 1000 1000 1000
output:
1
result:
ok single line: '1'
Test #15:
score: 0
Accepted
time: 35ms
memory: 254660kb
input:
1000 999 998 1000 997 1000 997 997
output:
1
result:
ok single line: '1'
Test #16:
score: 0
Accepted
time: 36ms
memory: 254720kb
input:
1 3 3 3 3 3 4 7
output:
1
result:
ok single line: '1'
Test #17:
score: 0
Accepted
time: 32ms
memory: 254660kb
input:
2 5 5 4 7 1 6 2
output:
1
result:
ok single line: '1'
Test #18:
score: 0
Accepted
time: 35ms
memory: 254656kb
input:
12 2 12 7 7 12 16 4
output:
1
result:
ok single line: '1'
Test #19:
score: 0
Accepted
time: 29ms
memory: 254672kb
input:
7 2 2 14 5 14 7 12
output:
1
result:
ok single line: '1'
Test #20:
score: 0
Accepted
time: 31ms
memory: 254664kb
input:
32 36 5 1 1 37 35 5
output:
1
result:
ok single line: '1'
Test #21:
score: 0
Accepted
time: 16ms
memory: 254776kb
input:
28 30 30 1 31 1 2 30
output:
1
result:
ok single line: '1'
Test #22:
score: 0
Accepted
time: 19ms
memory: 254604kb
input:
66 68 9 11 7 66 9 64
output:
1
result:
ok single line: '1'
Test #23:
score: 0
Accepted
time: 48ms
memory: 254600kb
input:
59 44 25 44 40 32 40 52
output:
1
result:
ok single line: '1'
Test #24:
score: 0
Accepted
time: 28ms
memory: 254728kb
input:
4 4 2 3 4 2 3 2
output:
1
result:
ok single line: '1'