QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#117682 | #6563. Four Square | cada_dia_mas_insanos# | WA | 2ms | 3472kb | C++17 | 2.9kb | 2023-07-01 23:11:08 | 2023-07-01 23:11:10 |
Judging History
answer
// Too many mind, no mind.
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <array>
#include <iomanip>
using namespace std;
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define COMP(x) sort(ALL(x)); x.resize(unique(ALL(x)) - (x).begin())
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
using pii = pair <int, int>;
using vi = vector <int>;
using vpi = vector <pii>;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using ld = long double;
using vld = vector<ld>;
using vpl = vector<pll>;
bool solve(vpl a, int n, int m) {
if (a.empty()) return m==0;
bool ok = 0;
int k = a.size();
if (k >= 1) {
forn(i, k) {
if (a[i].fi==n) {
vpl b = a;
b.erase(b.begin()+i);
ok |= solve(b, n, m-a[i].se);
}
}
}
if (k >= 2) {
forn(i, k) fore(j, i+1, k-1) {
if (a[i].fi + a[j].fi != n) continue;
if (a[i].se == a[j].se) {
vpl b = a;
b.erase(b.begin()+i);
b.erase(b.begin()+j-1);
ok |= solve(b, n, m-a[i].se);
} else {
int in=0;
forn(l, k) if (l!=i && l!=j) {
if (a[l].se == m-a[i].se && a[l].fi == a[i].fi) in++;
if (a[l].se == m-a[j].se && a[l].fi == a[j].fi) in++;
}
ok |= in==2;
}
}
}
if (k>=3) {
forn(i, k) if (a[i].fi == n) {
bool cur=1;
int h = 0;
forn(j, k) if (j != i) {
h += a[j].fi;
cur &= a[j].se == m - a[i].se;
}
cur &= h == n;
ok |= cur;
}
}
if (k>=4) {
int h = 0;
bool cur = 1;
forn(i, k) {
h += a[i].fi;
cur &= a[i].se == m;
}
cur &= h == n;
ok |= cur;
}
return ok;
}
ll root(ll n) {
ll lo = 0, hi = n;
while (lo < hi) {
ll mid = lo + (hi-lo)/2;
if (mid*mid >= n) hi=mid;
else lo = mid+1;
}
return lo;
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
ll total = 0;
vpl a(4);
forn(i, 4) {
ll h, w; cin >> h >> w;
a[i] = mp(h, w);
total += h*w;
}
sort(ALL(a));
int n = root(total);
if (n*n != total) {
cout << 0 << endl;
return 0;
}
bool ok = 0;
vi p = {0, 1, 2, 3};
do {
forn(mask, 16) {
vpl b;
forn(i, 4) b.pb(a[p[i]]);
forn(i, 4) if (mask>>i&1) swap(b[i].fi, b[i].se);
ok = solve(b, n, n);
}
} while (next_permutation(ALL(p)));
cout << ok << endl;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3416kb
input:
1 1 1 1 1 1 1 1
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3396kb
input:
3 1 3 3 2 2 3 3
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3444kb
input:
2 8 2 8 2 8 2 8
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3400kb
input:
5 3 5 5 3 3 3 5
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 1ms
memory: 3416kb
input:
1 2 4 8 16 32 64 128
output:
0
result:
ok single line: '0'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3392kb
input:
4 4 2 1 4 4 2 1
output:
0
result:
ok single line: '0'
Test #7:
score: 0
Accepted
time: 1ms
memory: 3396kb
input:
995 51 559 565 154 536 56 780
output:
0
result:
ok single line: '0'
Test #8:
score: 0
Accepted
time: 1ms
memory: 3396kb
input:
391 694 540 42 240 937 691 246
output:
0
result:
ok single line: '0'
Test #9:
score: 0
Accepted
time: 1ms
memory: 3404kb
input:
519 411 782 710 299 45 21 397
output:
0
result:
ok single line: '0'
Test #10:
score: 0
Accepted
time: 2ms
memory: 3452kb
input:
96 960 948 18 108 82 371 576
output:
0
result:
ok single line: '0'
Test #11:
score: 0
Accepted
time: 0ms
memory: 3396kb
input:
3 2 4 3 3 1 1 4
output:
0
result:
ok single line: '0'
Test #12:
score: 0
Accepted
time: 1ms
memory: 3400kb
input:
4 3 1 2 4 4 3 2
output:
0
result:
ok single line: '0'
Test #13:
score: 0
Accepted
time: 1ms
memory: 3412kb
input:
4 4 1 3 5 4 2 5
output:
0
result:
ok single line: '0'
Test #14:
score: 0
Accepted
time: 1ms
memory: 3472kb
input:
1000 1000 1000 1000 1000 1000 1000 1000
output:
1
result:
ok single line: '1'
Test #15:
score: -100
Wrong Answer
time: 1ms
memory: 3464kb
input:
1000 999 998 1000 997 1000 997 997
output:
0
result:
wrong answer 1st lines differ - expected: '1', found: '0'