QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#132482 | #6563. Four Square | Sorting# | WA | 1ms | 3800kb | C++23 | 3.1kb | 2023-07-30 00:18:57 | 2023-07-30 00:19:00 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> void check_min(T &a, const T &b){ a = (a < b) ? a : b; }
template<class T> void check_max(T &a, const T &b){ a = (a > b) ? a : b; }
#define all(x) (x).begin(), (x).end()
const int N = 2000 + 3;
pair<int, int> s[4];
vector<pair<int, int>> v[N];
int n;
void fix(int x){
for(int i = 0; i < (int)v[x].size() - 1; ++i){
if(v[x][i].second == v[x][i + 1].first - 1){
v[x][i].second = v[x][i + 1].second;
v[x].erase(v[x].begin() + i + 1);
break;
}
}
}
bool try_insert(int x, int y1, int y2){
bool inserted = false;
for(int i = 0; i < v[x].size(); ++i){
if(y1 <= v[x][i].first && v[x][i].first <= y2)
return false;
if(y1 <= v[x][i].second && v[x][i].second <= y2)
return false;
if(v[x][i].first <= y1 && y1 <= v[x][i].second)
return false;
if(v[x][i].first <= y2 && y2 <= v[x][i].second)
return false;
if(y2 < v[x][i].first){
v[x].insert(v[x].begin() + i, {y1, y2});
inserted = true;
break;
}
}
if(!inserted)
v[x].push_back({y1, y2});
fix(x);
fix(x);
return true;
}
bool solve(int idx){
if(idx == 4) return true;
vector<pair<int, int>> v2[N];
for(int i = 1; i <= n; ++i)
v2[i] = v[i];
int x, y;
for(int i = 1; i <= n; ++i){
if(v[i].empty() || v[i][0].first != 1 || v[i][0].second != n){
if(v[i].empty()){
x = i;
y = 1;
break;
}
if(v[i][0].first != 1){
x = i;
y = 1;
break;
}
x = i;
y = v[i][0].first + 1;
break;
}
}
for(int i = 0; i < 2; ++i, swap(s[idx].first, s[idx].second)){
if(x + s[idx].first - 1 > n || y + s[idx].second - 1 > n)
continue;
for(int j = 1; j <= n; ++j)
v[j] = v2[j];
bool ok = true;
for(int j = x; j < x + s[idx].first; ++j){
if(!try_insert(j, y, y + s[idx].second - 1)){
ok = false;
break;
}
}
if(!ok) continue;
if(solve(idx + 1)) return true;
}
return false;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
int sum = 0;
for(int i = 0; i < 4; ++i){
cin >> s[i].first >> s[i].second;
sum += s[i].first * s[i].second;
}
for(int j = 0; j * j <= sum; ++j){
if(j * j == sum){
n = j;
}
}
if(n * n != sum){
cout << "0\n";
return 0;
}
sort(s, s + 4);
do{
for(int i = 1; i <= n; ++i)
v[i].clear();
if(solve(0)){
cout << 1 << "\n";
return 0;
}
}
while(next_permutation(s, s + 4));
cout << 0 << "\n";
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3732kb
input:
1 1 1 1 1 1 1 1
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3712kb
input:
3 1 3 3 2 2 3 3
output:
0
result:
ok single line: '0'
Test #3:
score: 0
Accepted
time: 1ms
memory: 3800kb
input:
2 8 2 8 2 8 2 8
output:
1
result:
ok single line: '1'
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 3616kb
input:
5 3 5 5 3 3 3 5
output:
0
result:
wrong answer 1st lines differ - expected: '1', found: '0'