QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#769651#7785. Three Rectanglesi0streamWA 0ms3852kbC++143.1kb2024-11-21 18:48:322024-11-21 18:48:32

Judging History

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

  • [2024-11-21 18:48:32]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3852kb
  • [2024-11-21 18:48:32]
  • 提交

answer

#include <bits/stdc++.h>
#define h1 r[1].h
#define h2 r[2].h
#define h3 r[3].h
#define w1 r[1].w
#define w2 r[2].w
#define w3 r[3].w

using namespace std;
typedef long long ll;
const ll P=1e9+7;

ll H,W,spc,ans,cnth,cntw;
int T;

struct node{ll h,w;}r[5];

inline bool cmp(node x,node y){
	if (x.h==H) return 1;
	else if (y.h==H) return 0;
	else if (x.w==W) return 1;
	else if (y.w==W) return 0;
	else return 1;
}

inline ll fr(int id){
	return 1ll*(H-r[id].h+1)*(W-r[id].w+1)%P;
}

inline ll Min(ll a,ll b){return a<b?a:b;}
inline ll Max(ll a,ll b){return a>b?a:b;}

int main(){
	scanf("%d",&T);
	while (T--){
		spc=0;ans=0;cnth=0;cntw=0;
		scanf("%lld%lld",&H,&W);
		for (int i=1;i<=3;i++){
			scanf("%lld%lld",&r[i].h,&r[i].w);
			if (r[i].h==H && r[i].w==W) spc=1;
			if (r[i].h==H) cnth++;
			if (r[i].w==W) cntw++;
		}
		if (spc){
			printf("%lld\n",fr(1)*fr(2)%P*fr(3)%P);
			continue;
		}
		if (cnth==3 && cntw==0 || cnth==1 && cntw==0 || cnth==2 && cntw==1 || cnth==2 && cntw==0){
			swap(r[1].h,r[1].w);
			swap(r[2].h,r[2].w);
			swap(r[3].h,r[3].w);
			swap(cnth,cntw);
			swap(H,W);
		}
		sort(r+1,r+4,cmp);
		if (cnth==0 && cntw==0) ans=0;
		else if (cnth==0 && cntw==1){
			if (h1+h2>=H && h1+h3>=H && w2+w3>=W) ans=4;
		}else if (cnth==0 && cntw==2){
			if (h1+h2>=H) ans=2*fr(3)%P;
		}else if (cnth==0 && cntw==3){
			if (h1+h2+h3>=H){
				int nh1=h1,nh2=h2,nh3=h3,x,y;
				if (nh1+nh3<H) x=Max(H-nh3,nh2),y=Min(nh1+nh2,H);
				else x=nh2,y=H;
				ans=(ans+2*(y-x+1))%P;
				if (x==nh2) ans=(ans-1+P)%P;
				if (y==H) ans=(ans-1+P)%P;
				//cout<<nh1<<' '<<nh2<<' '<<nh3<<' '<<ans<<endl;
				
				nh1=h1,nh2=h3,nh3=h2;
				if (nh1+nh3<H) x=Max(H-nh3,nh2),y=Min(nh1+nh2,H);
				else x=nh2,y=H;
				ans=(ans+2*(y-x+1))%P;
				if (x==nh2) ans=(ans-1+P)%P;
				if (y==H) ans=(ans-1+P)%P;
				//cout<<nh1<<' '<<nh2<<' '<<nh3<<' '<<ans<<endl;
				
				nh1=h2,nh2=h1,nh3=h3;
				if (nh1+nh3<H) x=Max(H-nh3,nh2),y=Min(nh1+nh2,H);
				else x=nh2,y=H;
				ans=(ans+2*(y-x+1))%P;
				if (x==nh2) ans=(ans-1+P)%P;
				if (y==H) ans=(ans-1+P)%P;
				//cout<<nh1<<' '<<nh2<<' '<<nh3<<' '<<ans<<endl;
				
				nh1=h2,nh2=h3,nh3=h1;
				if (nh1+nh3<H) x=Max(H-nh3,nh2),y=Min(nh1+nh2,H);
				else x=nh2,y=H;
				ans=(ans+2*(y-x+1))%P;
				if (x==nh2) ans=(ans-1+P)%P;
				if (y==H) ans=(ans-1+P)%P;
				//cout<<nh1<<' '<<nh2<<' '<<nh3<<' '<<ans<<endl;
				
				nh1=h3,nh2=h1,nh3=h2;
				if (nh1+nh3<H) x=Max(H-nh3,nh2),y=Min(nh1+nh2,H);
				else x=nh2,y=H;
				ans=(ans+2*(y-x+1))%P;
				if (x==nh2) ans=(ans-1+P)%P;
				if (y==H) ans=(ans-1+P)%P;
				//cout<<nh1<<' '<<nh2<<' '<<nh3<<' '<<ans<<endl;
				
				nh1=h3,nh2=h2,nh3=h1;
				if (nh1+nh3<H) x=Max(H-nh3,nh2),y=Min(nh1+nh2,H);
				else x=nh2,y=H;
				ans=(ans+2*(y-x+1))%P;
				if (x==nh2) ans=(ans-1+P)%P;
				if (y==H) ans=(ans-1+P)%P;
				//cout<<nh1<<' '<<nh2<<' '<<nh3<<' '<<ans<<endl;
				
				ans/=2;
			}else ans=0;
		}else if (cnth==1 && cntw==1){
			if (h2+h3>=H && w1+w3>=W) ans=4;
		}else if (cnth==1 && cntw==2){
			if (h2+h3>=H) ans=2*fr(1)%P;
		}
		printf("%lld\n",ans);
	}
	return 0;
}

详细

Test #1:

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

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: 3852kb

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: 3812kb

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: 0ms
memory: 3848kb

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
277777749
456790164
0
0
0
0
0
6
222222208
55555527
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
388888868
172839523
0
6
222222208
222222208
222222208
222222208
2222222...

result:

wrong answer 8th numbers differ - expected: '777777753', found: '277777749'