QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#672606#7785. Three RectanglesKOH-#WA 4ms10084kbC++143.0kb2024-10-24 17:45:122024-10-24 17:45:12

Judging History

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

  • [2024-10-24 17:45:12]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:10084kb
  • [2024-10-24 17:45:12]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7,N=3e5+5;
int n,m;
int h[N],w[N];
int a[N],b[N];
int sum[N];
int l[N],r[N];
void solve(){
	sum[3]=sum[1]=sum[2]=0;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=3;i++){
		scanf("%d%d",&a[i],&b[i]);
		h[i]=a[i],w[i]=b[i];
		if(h[i]==n && w[i]==m){
			sum[1]++;
			continue;
		}
		if(h[i]==n){
			sum[2]++;
			l[sum[2]]=w[i];
			continue;
		}
		if(w[i]==m){
			sum[3]++;
			r[sum[3]]=h[i];
			continue;
		}
	}
	long long ans=1;
	if(sum[1]>0){
		ans=1;
		for(int i=1;i<=3;i++){
			ans=(long long)ans*(n-a[i]+1)%mod*(m-b[i]+1)%mod;
		}
		printf("%lld\n",ans);
		return ;
	}
	if(sum[2]>0){
		if(sum[2]==3){
			ans=0;
			int x,y;
			for(int i=1;i<=3;i++){
				for(int j=1;j<=3;j++){
					if(i==j) continue;
					for(int k=1;k<=3;k++){
						if(i==k || j==k) continue;
						x=max(1,m-l[k]-l[j]);
						y=min(l[i],m-l[k]-1);
						if(l[i]+l[j]>=m){
							x=1;
							y=m-l[k]-1;
						}
						if(i<k && max(l[i],l[k])+l[j]>=m){
							ans=(ans+1)%mod;
						}
						if(j<k && max(l[j],l[k])+l[i]>=m){
							ans=(ans+1)%mod;
						}
						ans=(ans+max(0,y-x+1))%mod;
						//printf("%d %d %d %d\n",i,j,k,ans);
					}
				}
			}
			printf("%lld\n",ans);
			return;
		}
		if(sum[2]==2){
			if(l[1]+l[2]<m){
				puts("0");
				return ;
			}
			ans=2;
			for(int i=1;i<=3;i++){
				if(a[i]!=n) ans=(long long)ans*(n-a[i]+1)%mod*(m-b[i]+1)%mod;
			}
			printf("%lld\n",ans);
			return ;
		}
		if(sum[2]==1){
			int mi=m;
			for(int i=1;i<=3;i++)
				if(a[i]!=n) mi=min(mi,b[i]);
			if(l[1]+mi<m){
				puts("0");
				return ;
			}
			puts("4");
			return ;
		}
	}
	swap(n,m);
	sum[2]=sum[3];
	for(int i=1;i<=sum[2];i++) l[i]=r[i];
	for(int i=1;i<=3;i++) swap(a[i],b[i]);
	if(sum[2]>0){
		if(sum[2]==3){
			ans=0;
			int x,y;
			for(int i=1;i<=3;i++){
				for(int j=1;j<=3;j++){
					if(i==j) continue;
					for(int k=1;k<=3;k++){
						if(i==k || j==k) continue;
						x=max(1,m-l[k]-l[j]);
						y=min(l[i],m-l[k]-1);
						if(l[i]+l[j]>=m){
							x=1;
							y=m-l[k]-1;
						}
						if(i<k && max(l[i],l[k])+l[j]>=m){
							ans=(ans+1)%mod;
						}
						if(j<k && max(l[j],l[k])+l[i]>=m){
							ans=(ans+1)%mod;
						}
						ans=(ans+max(0,y-x+1))%mod;
						//printf("%d %d %d %d\n",i,j,k,ans);
					}
				}
			}
			printf("%lld\n",ans);
			return;
		}
		if(sum[2]==2){
			if(l[1]+l[2]<m){
				puts("0");
				return ;
			}
			ans=2;
			for(int i=1;i<=3;i++){
				if(a[i]!=n) ans=(long long)ans*(n-a[i]+1)%mod*(m-b[i]+1)%mod;
			}
			printf("%lld\n",ans);
			return ;
		}
		if(sum[2]==1){
			int mi=m;
			for(int i=1;i<=3;i++)
				if(a[i]!=n) mi=min(mi,b[i]);
			if(l[1]+mi<m){
				puts("0");
				return ;
			}
			puts("4");
			return ;
		}
	}
	puts("0");
}
int main()
{
	int T;
	scanf("%d",&T);
	while(T--) solve();
}
/*
1
 1 5
 1 1
 1 2
 1 3

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
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 1ms
memory: 9996kb

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: 1ms
memory: 10008kb

input:

1
1000000000 1000000000
1 1
1 1
1000000000 1000000000

output:

2401

result:

ok 1 number(s): "2401"

Test #4:

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

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
555555531
135802502
0
0
0
0
6
222222208
222222208
333333309
814814847
0
0
0
6
222222208
222222208
222222208
111111087
493827185
0
0
6
222222208
222222208
222222208
222222208
888888872
172839523
0
6
222222208
222222208
222222208
222222208
222222...

result:

ok 729 numbers

Test #5:

score: -100
Wrong Answer
time: 4ms
memory: 10084kb

input:

5832
999999999 222222222
111111111 111111111
111111111 111111111
111111111 111111111
222222222 999999999
111111111 111111111
111111111 111111111
111111111 222222222
222222222 999999999
111111111 111111111
111111111 111111111
111111111 333333333
999999999 222222222
111111111 111111111
111111111 11111...

output:

0
0
0
0
0
0
0
0
4
0
0
0
0
0
0
0
4
413046795
0
0
0
0
0
0
0
0
4
0
0
0
0
0
0
0
4
989330902
0
0
0
0
0
0
0
0
4
0
0
0
0
0
0
0
4
565615002
0
0
0
0
0
0
0
0
4
0
0
0
0
0
0
0
4
141899102
0
0
0
0
0
0
0
0
4
0
0
0
0
0
0
0
4
718183209
0
0
0
0
0
0
0
0
4
0
0
0
0
0
0
0
4
294467309
0
0
0
0
0
0
0
0
4
0
0
0
0
0
0
0
4
87...

result:

wrong answer 9th numbers differ - expected: '0', found: '4'