QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#325391#7785. Three RectanglesZhouShang#WA 1ms3840kbC++202.2kb2024-02-11 09:27:212024-02-11 09:27:21

Judging History

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

  • [2024-02-11 09:27:21]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3840kb
  • [2024-02-11 09:27:21]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
long long mod=1e9+7;
int main(){
	int T;
	cin>>T;
	while(T--){
		int A,B;
		int a[6],b[6];
		scanf("%d%d",&A,&B);
		for(int i=0;i<3;i++) scanf("%d%d",&a[i],&b[i]),a[i+3]=a[i],b[i+3]=b[i];
		int f=0;
		for(int i=0;i<3;i++)
			if(a[i]==A&&b[i]==B){
				f=1;
				long long ans=1;
				for(int j=0;j<3;j++)
					if(j!=i) ans*=1LL*(A-a[j]+1)*(B-b[j]+1)%mod,ans%=mod;
				printf("%lld\n",ans%mod);
				break;
			}
		if(f) continue;
		long long ans=0;
		for(int i=0;i<3;i++){
			int fr=a[i]==A||b[i+1]==B,fl=b[i]==B||a[i+1]==A;
			if(!fr&&!fl) continue;
			else if(fr+fl==1){
				//assert(a[i]+a[i+1]>=A&&b[i]+b[i+1]>=B);
				int aa=fr?A-a[i+1]:A-a[i],bb=fr?B-b[i]:B-b[i+1];
				if(a[i]+a[i+1]<A) aa=A;
				if(b[i]+b[i+1]<B) bb=B;
				if(a[i+2]>=aa&&b[i+2]>=bb) ans++;
			}
			else{
				int aa,bb;
				if(a[i]==A){
					assert(a[i+1]==A);
					aa=A,bb=max(0,B-b[i]-b[i+1]);
				}
				else{
					assert(b[i+1]==B);
					bb=B,aa=max(0,A-a[i]-a[i+1]);
				}
				if(aa==0||bb==0){
					ans+=1LL*(A-a[i+2]+1)*(B-b[i+2]+1)%mod;
					ans%=mod;
					continue;
				}
				if(a[i+2]>=aa&&b[i+2]>=bb){
					long long val=1;
					if(b[i+2]==B){
						int ll=max(1,A-a[i+2]-a[i+1]+1);
						int rr=min(A,a[i]+1);
						val=val*(rr-ll+1)%mod;
					}
					else{
						int ll=max(1,B-b[i+2]-b[i+1]+1);
						int rr=min(B,b[i]+1);
						val=val*(rr-ll+1)%mod;
					}
					ans=(ans+val)%mod;
				}
			}
			//cout<<"#"<<i<<" "<<fl<<" "<<fr<<" "<<ans<<endl;
			ans%=mod;
		}
		//cout<<ans<<endl;
		for(int i=0;i<3;i++){
			int f=1;
			if(a[i]!=A&&a[i+1]!=A&&(b[i+2]!=B||max(a[i],a[i+1])+a[i+2]<A)) f=0;
			if(b[i]!=B&&b[i+1]!=B&&(a[i+2]!=A||max(b[i],b[i+1])+b[i+2]<B)) f=0;
			if(f==0) continue;
			f=0;
			if(b[i+2]==B||a[i]==A&&b[i]+b[i+2]>=B||a[i+1]==A&&b[i+1]+b[i+2]>=B) f=1;
			if(!f) continue;
			f=0;
			if(a[i+2]==A||b[i]==B&&a[i]+a[i+2]>=A||b[i+1]==B&&a[i+1]+a[i+2]>=A) f=1;
			if(f) ans--;
		}
		cout<<(ans*2%mod+mod)%mod<<endl;
	}
	return 0;
}
/*
5
2 2
1 1
1 1
1 1
0
2 2
1 1
1 2
1 2
#0 0 1 1
#1 1 1 1
#2 1 0 2
2
2 2
1 1
1 2
2 1
#0 0 1 1
#1 1 0 2
#2 0 1 3
3
2 2
1 2
1 2
1 2
#0 1 1 2
#1 1 1 4
#2 1 1 6
6
2 2
1 2
1 2
2 1
#0 1 1 0
#1 1 0 1
#2 0 1 2
2
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5
2 2
1 1
1 1
1 1
2 2
1 1
1 2
1 2
2 2
1 1
1 2
2 1
2 2
1 2
1 2
1 2
2 2
1 2
1 2
2 1

output:

0
8
4
6
4

result:

ok 5 number(s): "0 8 4 6 4"

Test #2:

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

input:

4
1 3
1 1
1 2
1 3
1 4
1 1
1 2
1 3
1 5
1 1
1 2
1 3
1 6
1 1
1 2
1 3

output:

6
12
14
6

result:

ok 4 number(s): "6 12 14 6"

Test #3:

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

input:

1
1000000000 1000000000
1 1
1 1
1000000000 1000000000

output:

2401

result:

ok 1 number(s): "2401"

Test #4:

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

input:

729
999999999 111111111
111111111 111111111
111111111 111111111
111111111 111111111
999999999 111111111
111111111 111111111
222222222 111111111
111111111 111111111
999999999 111111111
111111111 111111111
111111111 111111111
333333333 111111111
999999999 111111111
111111111 111111111
444444444 111111...

output:

0
0
0
0
0
0
6
777777753
456790164
0
0
0
0
0
6
222222208
777777753
135802502
0
0
0
0
6
222222208
444444430
333333309
814814847
0
0
0
6
222222208
444444430
666666652
777777753
493827185
0
0
6
222222208
444444430
666666652
888888874
777777753
172839523
0
6
222222208
444444430
666666652
888888874
111111...

result:

wrong answer 17th numbers differ - expected: '555555531', found: '777777753'