QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#349158#6563. Four SquarejanY#AC ✓0ms3784kbC++204.2kb2024-03-09 23:50:592024-03-09 23:51:00

Judging History

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

  • [2024-03-09 23:51:00]
  • 评测
  • 测评结果:AC
  • 用时:0ms
  • 内存:3784kb
  • [2024-03-09 23:50:59]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

vector<pair<int,int>> g;

bool attmpt(){
    int area = 0;
    for (auto &i : g){
        area += i.first*i.second;
    }
    int side = sqrt(area);
    if (side*side != area) return 0;

    int top = 0;
    for (auto &i : g) {
        top += i.first;
    }
    if (top == side){
        bool isgood = true;
        for (auto &i : g){
            if (i.second != side) isgood = false;
        }
        if (isgood) return 1;
    }

    if (top == side*2){
        for (int i = 0; i < 16; i++){
            int s1 = 0;
            int s2 = 0;
            int s1o = -1000000;
            int s2o = -1000000;
            bool isgood = true;
            for (int j = 0; j < 4; j++){
                if (i&(1<<j)){ // s1
                    s1 += g[j].first;
                    if (s1o < 0) s1o = g[j].second;
                    else {
                        if (s1o != g[j].second) isgood = false;
                    }
                } else { // s2
                    s2 += g[j].first;
                    if (s2o < 0) s2o = g[j].second;
                    else {
                        if (s2o != g[j].second) isgood = false;
                    }
                }
            }
            if (s1o + s2o != side) isgood = false;
            if (s1 != side || s2 != side) isgood = false;
            if (isgood) return 1;
        }
    }

    if (top == side*3){
        bool isgood = true;
        int bcnt = 0;
        int oth = 0;
        int lf = 0;
        int othz = -100000;
        for (auto &i : g){
            if (i.first == side){
                bcnt++;
                lf += i.second;
            } else {
                oth += i.first;
                if (othz < 0){
                    othz = i.second;
                } else {
                    if (othz != i.second) isgood = false;
                }
            }
        }
        if (othz+lf != side) isgood = false;
        if (bcnt != 2) isgood = false;
        if (isgood) return 1;
    }

    if (top == side*4){
        bool isgood = true;
        int lf = 0;
        for (auto &i : g){
            if (i.first != side) isgood = false;
            lf += i.second;
        }
        if (lf != side) isgood = false;
        if (isgood) return 1;
    }

    for (int i = 0; i < 4; i++) {
        for (int j = i+1; j < 4; j++){
            vector<pair<int,int>> ng;
            if (g[i].first != g[j].first) continue;
            ng.push_back({g[i].first, g[i].second+g[j].second});
            for (int z = 0; z < 4; z++){
                if (z == i || z == j) continue;
                ng.push_back(g[z]);
            }
            int tp = 0;
            for (auto &z : ng){
                tp += z.first;
            }
            if (tp == 2*side){
                bool isgood = true;
                int bcnt = 0;
                int lf = 0;
                int olf = -10000;
                for (auto &z : ng){
                    if (z.first == side){
                        bcnt++;
                        lf = z.second;
                    } else {
                        if (olf < 0) olf = z.second;
                        else {
                            if (olf != z.second) isgood = false;
                        }
                    }
                }
                if (lf + olf != side) isgood = false;
                if (bcnt != 1) isgood = false;
                if (isgood) return 1;
            }
        }
    }

    return 0;
}

void solve(){
    long long d, n;
    vector<pair<int,int>> z(4);
    for (int i = 0; i < 4; i++){
        cin >> z[i].first >> z[i].second;
    }

    for (int i = 0; i < 16; i++){
        g = z;
        for (int j = 0; j < 4; j++){
            if (i&(1<<j)) swap(g[j].first, g[j].second);
        }
        //for (auto &i : g){
         //   cout << i.first << ":" << i.second << " ";
        //}
        //cout << "\n";
        bool good = attmpt();
        if (good){
            cout << 1;
            return;
        }
    }
    cout << 0;
}

int main(){

    int t = 1;
    for (int i = 0; i < t; i++) solve();

    return 0;
}


详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3576kb

input:

1 1
1 1
1 1
1 1

output:

1

result:

ok single line: '1'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3516kb

input:

3 1
3 3
2 2
3 3

output:

0

result:

ok single line: '0'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3520kb

input:

2 8
2 8
2 8
2 8

output:

1

result:

ok single line: '1'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3512kb

input:

5 3
5 5
3 3
3 5

output:

1

result:

ok single line: '1'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3564kb

input:

1 2
4 8
16 32
64 128

output:

0

result:

ok single line: '0'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3508kb

input:

4 4
2 1
4 4
2 1

output:

0

result:

ok single line: '0'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3544kb

input:

995 51
559 565
154 536
56 780

output:

0

result:

ok single line: '0'

Test #8:

score: 0
Accepted
time: 0ms
memory: 3708kb

input:

391 694
540 42
240 937
691 246

output:

0

result:

ok single line: '0'

Test #9:

score: 0
Accepted
time: 0ms
memory: 3768kb

input:

519 411
782 710
299 45
21 397

output:

0

result:

ok single line: '0'

Test #10:

score: 0
Accepted
time: 0ms
memory: 3496kb

input:

96 960
948 18
108 82
371 576

output:

0

result:

ok single line: '0'

Test #11:

score: 0
Accepted
time: 0ms
memory: 3772kb

input:

3 2
4 3
3 1
1 4

output:

0

result:

ok single line: '0'

Test #12:

score: 0
Accepted
time: 0ms
memory: 3496kb

input:

4 3
1 2
4 4
3 2

output:

0

result:

ok single line: '0'

Test #13:

score: 0
Accepted
time: 0ms
memory: 3772kb

input:

4 4
1 3
5 4
2 5

output:

0

result:

ok single line: '0'

Test #14:

score: 0
Accepted
time: 0ms
memory: 3768kb

input:

1000 1000
1000 1000
1000 1000
1000 1000

output:

1

result:

ok single line: '1'

Test #15:

score: 0
Accepted
time: 0ms
memory: 3568kb

input:

1000 999
998 1000
997 1000
997 997

output:

1

result:

ok single line: '1'

Test #16:

score: 0
Accepted
time: 0ms
memory: 3500kb

input:

1 3
3 3
3 3
4 7

output:

1

result:

ok single line: '1'

Test #17:

score: 0
Accepted
time: 0ms
memory: 3572kb

input:

2 5
5 4
7 1
6 2

output:

1

result:

ok single line: '1'

Test #18:

score: 0
Accepted
time: 0ms
memory: 3784kb

input:

12 2
12 7
7 12
16 4

output:

1

result:

ok single line: '1'

Test #19:

score: 0
Accepted
time: 0ms
memory: 3560kb

input:

7 2
2 14
5 14
7 12

output:

1

result:

ok single line: '1'

Test #20:

score: 0
Accepted
time: 0ms
memory: 3556kb

input:

32 36
5 1
1 37
35 5

output:

1

result:

ok single line: '1'

Test #21:

score: 0
Accepted
time: 0ms
memory: 3496kb

input:

28 30
30 1
31 1
2 30

output:

1

result:

ok single line: '1'

Test #22:

score: 0
Accepted
time: 0ms
memory: 3476kb

input:

66 68
9 11
7 66
9 64

output:

1

result:

ok single line: '1'

Test #23:

score: 0
Accepted
time: 0ms
memory: 3492kb

input:

59 44
25 44
40 32
40 52

output:

1

result:

ok single line: '1'

Test #24:

score: 0
Accepted
time: 0ms
memory: 3452kb

input:

4 4
2 3
4 2
3 2

output:

1

result:

ok single line: '1'