QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#117845#6563. Four SquareKlaus26AC ✓35ms707616kbC++201.9kb2023-07-02 11:06:042023-07-02 11:06:07

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-02 11:06:07]
  • 评测
  • 测评结果:AC
  • 用时:35ms
  • 内存:707616kb
  • [2023-07-02 11:06:04]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "../debug.h"
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif



int a[4], b[4];

int dp[3002][3002][20];
int go(int x, int y, int msk){
	if(msk == 15){
		//cout<<x<<' '<<y<<endl;
		return x == 0 || y == 0;
	}
	int& ok = dp[x][y][msk];
	if(ok != -1) return ok;
	ok = 0;
	for(int i=0; i<4; i++){
		if((msk>>i)&1)continue;
		int nmsk = msk | (1<<i); 
		if(a[i] == x && y-b[i] >=0){
			ok |= go(x,y-b[i],nmsk);
		}
		if(a[i] == y && x-b[i] >=0){
			ok |= go(x-b[i],y,nmsk);
		}
		if(b[i] == x && y-a[i] >=0){
			ok |= go(x,y-a[i],nmsk);
		}
		if(b[i] == y && x-a[i] >=0){
			ok |= go(x-a[i],y,nmsk);
		}
	}
	return ok;
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	memset(dp,-1,sizeof dp);
	for(int i=0; i<4; i++){
		cin>>a[i]>>b[i];
	}
	int ok = 0;
	//1
	for(int i=0; i<4; i++){
		for(int j=0; j<4; j++){
			for(int r=0; r<4; r++){
				for(int l=0; l<4; l++){
					if(i!=j && j!=r && r!=l && l!=i && i!=r && j!=l){
						if(a[i] == a[j]){
							int len = b[i] + b[j];
							ok |= (a[r] == a[l] && b[r]+b[l] == len && a[i]+a[r] == len);
							ok |= (a[r] == b[l] && b[r]+a[l] == len && a[i]+a[r] == len);
							ok |= (b[r] == a[l] && a[r]+b[l] == len && a[i]+b[r] == len);
							ok |= (b[r] == b[l] && a[r]+a[l] == len && a[i]+b[r] == len);
						}else if(a[i] == b[j]){
							int len = b[i] + a[j];
							ok |= (a[r] == a[l] && b[r]+b[l] == len && a[i]+a[r] == len);
							ok |= (a[r] == b[l] && b[r]+a[l] == len && a[i]+a[r] == len);
							ok |= (b[r] == a[l] && a[r]+b[l] == len && a[i]+b[r] == len);
							ok |= (b[r] == b[l] && a[r]+a[l] == len && a[i]+b[r] == len);
						}
					}
				}
			}
		}
	}
	//ok |= go(5,5,0);
	for(int len=1; len<=3000; len++){
		ok |= go(len,len,0);
	}
	cout<<ok<<'\n';
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 27ms
memory: 707456kb

input:

1 1
1 1
1 1
1 1

output:

1

result:

ok single line: '1'

Test #2:

score: 0
Accepted
time: 16ms
memory: 707464kb

input:

3 1
3 3
2 2
3 3

output:

0

result:

ok single line: '0'

Test #3:

score: 0
Accepted
time: 28ms
memory: 707452kb

input:

2 8
2 8
2 8
2 8

output:

1

result:

ok single line: '1'

Test #4:

score: 0
Accepted
time: 24ms
memory: 707448kb

input:

5 3
5 5
3 3
3 5

output:

1

result:

ok single line: '1'

Test #5:

score: 0
Accepted
time: 20ms
memory: 707444kb

input:

1 2
4 8
16 32
64 128

output:

0

result:

ok single line: '0'

Test #6:

score: 0
Accepted
time: 12ms
memory: 707448kb

input:

4 4
2 1
4 4
2 1

output:

0

result:

ok single line: '0'

Test #7:

score: 0
Accepted
time: 19ms
memory: 707456kb

input:

995 51
559 565
154 536
56 780

output:

0

result:

ok single line: '0'

Test #8:

score: 0
Accepted
time: 32ms
memory: 707432kb

input:

391 694
540 42
240 937
691 246

output:

0

result:

ok single line: '0'

Test #9:

score: 0
Accepted
time: 24ms
memory: 707584kb

input:

519 411
782 710
299 45
21 397

output:

0

result:

ok single line: '0'

Test #10:

score: 0
Accepted
time: 11ms
memory: 707464kb

input:

96 960
948 18
108 82
371 576

output:

0

result:

ok single line: '0'

Test #11:

score: 0
Accepted
time: 27ms
memory: 707452kb

input:

3 2
4 3
3 1
1 4

output:

0

result:

ok single line: '0'

Test #12:

score: 0
Accepted
time: 24ms
memory: 707384kb

input:

4 3
1 2
4 4
3 2

output:

0

result:

ok single line: '0'

Test #13:

score: 0
Accepted
time: 16ms
memory: 707380kb

input:

4 4
1 3
5 4
2 5

output:

0

result:

ok single line: '0'

Test #14:

score: 0
Accepted
time: 20ms
memory: 707556kb

input:

1000 1000
1000 1000
1000 1000
1000 1000

output:

1

result:

ok single line: '1'

Test #15:

score: 0
Accepted
time: 12ms
memory: 707388kb

input:

1000 999
998 1000
997 1000
997 997

output:

1

result:

ok single line: '1'

Test #16:

score: 0
Accepted
time: 20ms
memory: 707556kb

input:

1 3
3 3
3 3
4 7

output:

1

result:

ok single line: '1'

Test #17:

score: 0
Accepted
time: 35ms
memory: 707432kb

input:

2 5
5 4
7 1
6 2

output:

1

result:

ok single line: '1'

Test #18:

score: 0
Accepted
time: 4ms
memory: 707580kb

input:

12 2
12 7
7 12
16 4

output:

1

result:

ok single line: '1'

Test #19:

score: 0
Accepted
time: 15ms
memory: 707616kb

input:

7 2
2 14
5 14
7 12

output:

1

result:

ok single line: '1'

Test #20:

score: 0
Accepted
time: 28ms
memory: 707596kb

input:

32 36
5 1
1 37
35 5

output:

1

result:

ok single line: '1'

Test #21:

score: 0
Accepted
time: 11ms
memory: 707460kb

input:

28 30
30 1
31 1
2 30

output:

1

result:

ok single line: '1'

Test #22:

score: 0
Accepted
time: 32ms
memory: 707448kb

input:

66 68
9 11
7 66
9 64

output:

1

result:

ok single line: '1'

Test #23:

score: 0
Accepted
time: 32ms
memory: 707456kb

input:

59 44
25 44
40 32
40 52

output:

1

result:

ok single line: '1'

Test #24:

score: 0
Accepted
time: 8ms
memory: 707556kb

input:

4 4
2 3
4 2
3 2

output:

1

result:

ok single line: '1'