QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#279823 | #7785. Three Rectangles | ucup-team2279# | TL | 489ms | 3556kb | C++14 | 1.6kb | 2023-12-09 10:14:24 | 2023-12-09 10:14:25 |
Judging History
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=[&](){
set<int> sx{1,n},sy{1,m};
for(int i:{0,1,2})
sx.insert(x[i]),sx.insert(x[i]-1),sx.insert(x[i]+h[i]),sx.insert(x[i]+h[i]-1),
sy.insert(y[i]),sy.insert(y[i]-1),sy.insert(y[i]+w[i]),sy.insert(y[i]+w[i]-1);
for(int i:sx) if(i>0&&i<=n) for(int j:sy) if(j>0&&j<=m){
bool fl=0;
for(int t:{0,1,2}) if(i>=x[t]&&i<x[t]+h[t]&&j>=y[t]&&j<y[t]+w[t]) fl=1;
if(!fl) return;
}
ans++;
};
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;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3388kb
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: 3440kb
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: 3444kb
input:
1 1000000000 1000000000 1 1 1 1 1000000000 1000000000
output:
2401
result:
ok 1 number(s): "2401"
Test #4:
score: 0
Accepted
time: 4ms
memory: 3504kb
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: 0
Accepted
time: 102ms
memory: 3452kb
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 0 0 0 0 0 0 0 0 4 413046795 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 989330902 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 565615002 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 141899102 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 718183209 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 294467309 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 87...
result:
ok 5832 numbers
Test #6:
score: 0
Accepted
time: 489ms
memory: 3556kb
input:
19683 999999999 333333333 111111111 111111111 111111111 111111111 111111111 111111111 999999999 333333333 111111111 111111111 111111111 111111111 222222222 111111111 999999999 333333333 333333333 111111111 111111111 111111111 111111111 111111111 999999999 333333333 111111111 111111111 444444444 1111...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 239292815 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 477213862 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 715134909 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 953055956 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 19683 numbers
Test #7:
score: -100
Time Limit Exceeded
input:
46656 999999999 444444444 111111111 111111111 111111111 111111111 111111111 111111111 999999999 444444444 111111111 111111111 111111111 111111111 222222222 111111111 444444444 999999999 111111111 333333333 111111111 111111111 111111111 111111111 999999999 444444444 444444444 111111111 111111111 1111...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 935528231 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 599451396 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 263374561 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...