QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#279826#7785. Three Rectanglesucup-team2279#WA 1ms3484kbC++141.5kb2023-12-09 10:20:222023-12-09 10:20:22

Judging History

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

  • [2023-12-09 10:20:22]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3484kb
  • [2023-12-09 10:20:22]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
void solve(){
	int n,m,sum=1,ok=0,ans=0;
	cin>>n>>m;
	vector<int> h(3),w(3),x(3),y(3);
	for(int i:{0,1,2}){
		cin>>h[i]>>w[i];
		if(h[i]==n&&w[i]==m) ok=1;
		sum=(n-h[i]+1ll)*(m-w[i]+1ll)%mod*sum%mod;
	}
	if(ok){
		cout<<sum<<"\n";
		return;
	}
	auto calc=[&](){
		long long a=0;
		for(int s=1;s<8;s++){
			int lx=1,rx=n,ly=1,ry=m,o=-1;
			for(int i:{0,1,2}) if(s>>i&1)
				o*=-1,
				lx=max(lx,x[i]),rx=min(rx,x[i]+h[i]-1),
				ly=max(ly,y[i]),ry=min(ry,y[i]+w[i]-1);
			a+=max(rx-lx+1,0)*max(ry-ly+1,0)*o;
		}
		ans+=a==1ll*n*m;
	};
	auto dfs=[&](auto self,int d)->void{
		if(d==3) return calc();
		set<array<int,2>> s;
		for(int i:{1,n-h[d]+1}) for(int j:{1,m-w[d]+1}) s.insert({i,j});
		for(auto t:s) x[d]=t[0],y[d]=t[1],self(self,d+1);
	};
	dfs(dfs,0);
	for(int i:{0,1,2}) for(int j:{0,1,2}) if(i!=j){
		int k=3^i^j;
		if((h[i]==n&&h[j]==n&&w[i]+w[j]>=m)||(w[i]==m&&w[j]==m&&h[i]+h[j]>=n)){
			(ans+=(n-h[k]+1ll)*(m-w[k]+1ll)%mod)%=mod;
			if(h[k]==n||w[k]==m) (ans+=mod-2)%=mod;
			else (ans+=mod-4)%=mod;
		}else if(h[i]==n&&h[j]==n&&h[k]==n){
			int l=max(2,m-w[j]-w[k]+1),r=min(w[i]+1,m-w[k]);
			(ans+=max(r-l+1,0))%=mod;
		}else if(w[i]==m&&w[j]==m&&w[k]==m){
			int l=max(2,n-h[j]-h[k]+1),r=min(h[i]+1,n-h[k]);
			(ans+=max(r-l+1,0))%=mod;
		}
	}
	cout<<ans<<"\n";
}
int main(){
	cin.tie(0)->sync_with_stdio(0);
	int t;
	cin>>t;
	while(t--) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3440kb

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

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

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

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
777777747
456790164
0
0
0
0
0
6
222222204
555555525
135802502
0
0
0
0
6
222222204
222222204
333333303
814814847
0
0
0
6
222222204
222222204
222222204
111111081
493827185
0
0
6
222222204
222222204
222222204
222222204
888888866
172839523
0
6
222222204
222222204
222222204
222222204
222222...

result:

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