QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#132475#6563. Four SquareSorting#WA 1ms3744kbC++232.8kb2023-07-30 00:07:162023-07-30 00:07:18

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-30 00:07:18]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3744kb
  • [2023-07-30 00:07:16]
  • 提交

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[i] = v2[i];

        bool ok = true;
        for(int j = x; j < x + s[idx].first; ++j){
            if(!try_insert(x, 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;
    }

    cout << solve(0) << "\n";
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3744kb

input:

1 1
1 1
1 1
1 1

output:

1

result:

ok single line: '1'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3608kb

input:

3 1
3 3
2 2
3 3

output:

0

result:

ok single line: '0'

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 3604kb

input:

2 8
2 8
2 8
2 8

output:

0

result:

wrong answer 1st lines differ - expected: '1', found: '0'