QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#729630#6563. Four Squareahsoltan#TL 752ms3772kbC++202.7kb2024-11-09 17:31:362024-11-09 17:31:44

Judging History

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

  • [2024-11-09 17:31:44]
  • 评测
  • 测评结果:TL
  • 用时:752ms
  • 内存:3772kb
  • [2024-11-09 17:31:36]
  • 提交

answer

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

#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define all(x) begin(x), end(x)
#define sz(x) int((x).size())
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

#ifdef LOCAL
auto operator<<(auto& o, auto x) -> decltype(x.first, o);
auto operator<<(auto& o, auto x) -> decltype(x.end(), o) {
  o << "{";
  for (int i = 0; auto y : x) o << ", " + !i++ * 2 << y;
  return o << "}";
}
auto operator<<(auto& o, auto x) -> decltype(x.first, o) {
  return o << "(" << x.first << ", " << x.second << ")";
}
void __print(auto... x) { ((cerr << x << " "), ...) << endl; }
#define debug(x...) __print("[" #x "]:", x)
#else
#define debug(...) 2137
#endif


bool czy(pair<int, int> p0, pair<int, int> p1, int x, int y) {
  if(p0.first == p1.second) {
    swap(p1.first, p1.second);
  }
  if(p0.second == p1.first) {
    swap(p0.first, p0.second);
  }

  if(p0.second == p1.second) {
    swap(p0.first, p0.second);
    swap(p1.first, p1.second);
    
  }

  debug(p0, p1);
  if(p0.first != p1.first)
    return 0;
  int s0 = p0.first;
  int s1 = p0.second + p1.second;
  if(s0 == x && s1 == y)
    return 1;
  if(s0 == y && s1 == x)
    return 1;
  return 0;
}

bool czy1(pair<int, int> p0, int x, int y) {
  if(x == p0.first && y == p0.second)
    return true;
  if(y == p0.first && x == p0.second)
    return true;
  return false;
}

int main() {

  debug(czy({2, 3}, {1, 3}, 3, 3));


  cin.tie(0)->sync_with_stdio(0);
  vector<pair<int, int>> ve(4);
  int sm = 0;
  for(auto &[i, j] : ve) {
    cin >> i >> j;
    sm += i * j;
  }

  int bok = sqrt(sm);
  if(bok * bok != sm) {
    cout << 0 << endl;
    return 0;
  }

  bool found = 0;

  for(int x = 0; x < bok; x++) {
    sort(all(ve));
    do {
      if(czy(ve[0], ve[1], x, bok) && czy(ve[2], ve[3], bok - x, bok)) {
        found = 1;
      }
    }
    while(next_permutation(all(ve)));
  }

  debug(bok);

  for(int x = 0; x < bok; x++) {
    for(int y = 0; y < bok; y++) {
      sort(all(ve));
      do {
        vector<pair<int, int>> v2 = {
          {x, y},
          {bok - x, y},
          {bok, bok - y}
        };
        sort(all(v2));
        do{
          bool b0 = czy1(ve[0], v2[0].first, v2[0].second);
          bool b1 = czy1(ve[1], v2[1].first, v2[1].second);
          bool b2 = czy(ve[2], ve[3], v2[2].first, v2[2].second);
          if(x == 1 && y == 3) {
            debug(ve);
            debug(v2);
            debug(b0, b1, b2);
          }
          found |= b0 & b1 & b2;
        }
        while(next_permutation(all(v2)));
      }
      while(next_permutation(all(ve)));
    }
  }

  cout << found << endl;
  
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

1 1
1 1
1 1
1 1

output:

1

result:

ok single line: '1'

Test #2:

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

input:

3 1
3 3
2 2
3 3

output:

0

result:

ok single line: '0'

Test #3:

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

input:

2 8
2 8
2 8
2 8

output:

1

result:

ok single line: '1'

Test #4:

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

input:

5 3
5 5
3 3
3 5

output:

1

result:

ok single line: '1'

Test #5:

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

input:

1 2
4 8
16 32
64 128

output:

0

result:

ok single line: '0'

Test #6:

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

input:

4 4
2 1
4 4
2 1

output:

0

result:

ok single line: '0'

Test #7:

score: 0
Accepted
time: 461ms
memory: 3696kb

input:

995 51
559 565
154 536
56 780

output:

0

result:

ok single line: '0'

Test #8:

score: 0
Accepted
time: 638ms
memory: 3600kb

input:

391 694
540 42
240 937
691 246

output:

0

result:

ok single line: '0'

Test #9:

score: 0
Accepted
time: 752ms
memory: 3764kb

input:

519 411
782 710
299 45
21 397

output:

0

result:

ok single line: '0'

Test #10:

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

input:

96 960
948 18
108 82
371 576

output:

0

result:

ok single line: '0'

Test #11:

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

input:

3 2
4 3
3 1
1 4

output:

0

result:

ok single line: '0'

Test #12:

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

input:

4 3
1 2
4 4
3 2

output:

0

result:

ok single line: '0'

Test #13:

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

input:

4 4
1 3
5 4
2 5

output:

0

result:

ok single line: '0'

Test #14:

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

input:

1000 1000
1000 1000
1000 1000
1000 1000

output:

1

result:

ok single line: '1'

Test #15:

score: -100
Time Limit Exceeded

input:

1000 999
998 1000
997 1000
997 997

output:


result: