QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#769218 | #7785. Three Rectangles | ucup-team5217# | WA | 4ms | 3612kb | C++23 | 3.0kb | 2024-11-21 16:37:43 | 2024-11-21 16:37:48 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
const ll M=1000000007;
#define int long long
void solve(void) {
int H,W;cin>>H>>W;
vector<int> h(3),w(3);
bool fm=false;
vector<int> p[2];
bool redone=false;
for(int i=0;i<3;i++){
cin>>h[i]>>w[i];
if(h[i]==H&&w[i]==W){
fm=true;
}
if(h[i]>H||w[i]>W) redone=true;
if(h[i]==H) p[0].push_back(i);
if(w[i]==W) p[1].push_back(i);
}
if(redone) {cout<<"0\n";return ;}
if(fm){
ll ans=1;
for(int i=0;i<3;i++){
if(!(h[i]==H&&w[i]==W)){
ans=ans*(H-h[i]+1)%M*(W-w[i]+1)%M;
}
}
cout<<ans<<'\n';
return ;
}
if(p[0].size()==3){
sort(w.begin(),w.end());
ll ans=0;
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
if(i==j) continue;
int del=3-(i+j);
int lo=max(((w[i]+w[j]>=W)?1:W-w[j])-w[del]+1,(del<i?1ll:2ll));
int ro=min(((w[i]+w[j]>=W)?W:w[i]+1),(del<j?W-w[del]+1:W-w[del]));
ans=(ans+max(0ll,ro-lo+1))%M;
}
}
cout<<ans<<'\n';
return ;
}
if(p[1].size()==3){
sort(h.begin(),h.end());
ll ans=0;
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
if(i==j) continue;
int del=3-(i+j);
int lo=max(((h[i]+h[j]>=H?1:H-h[j]-h[del]+1)),(del<i?1ll:2ll));
int ro=min((h[i]+h[j]>=H?H:h[i]+1),(del<j?H-h[del]+1:H-h[del]));
ans=(ans+max(0ll,ro-lo+1))%M;
}
}
cout<<ans<<'\n';
return ;
}
if(p[0].size()==2){
int del=(3-p[0][0]-p[0][1]);
if(w[p[0][0]]+w[p[0][1]]>=W){
cout<<2*(H-h[del]+1)*(W-w[del]+1)%M<<'\n';
}
else cout<<"0\n";
return ;
}
if(p[1].size()==2){
int del=(3-p[1][0]-p[1][1]);
if(w[p[1][0]]+w[p[1][1]]>=W){
cout<<2*(H-h[del]+1)*(W-w[del]+1)%M<<'\n';
}
else cout<<"0\n";
return ;
}
if(p[0].size()==0&&p[1].size()==0){cout<<"0\n";return ;}
if(p[0].size()==1&&p[1].size()==1){
int del=3-p[0][0]-p[1][0];
if(h[del]+h[p[1][0]]>=H&&w[del]+w[p[0][0]]>=W){
cout<<"4\n";
return ;
}
else {cout<<"0\n";return ;}
}
int dw=0;
if(p[0].size()==1){
dw=p[0][0];
swap(H,W);
for(int j=0;j<3;j++) swap(w[j],h[j]);
}
else dw=p[1][0];
vector<int> sy;
for(int i=0;i<3;i++) if(i!=dw) sy.push_back(i);
if(min(h[sy[0]],h[sy[1]])+h[dw]>=H&&w[sy[0]]+w[sy[1]]>=W){
cout<<"4\n";
return ;
}
else cout<<"0\n";
return;
}
signed main() {
ios::sync_with_stdio(false), cin.tie(nullptr);
int _ = 1;
cin>>_;
while (_--) solve();
return 0;
}
/*
0
4
4
6
2
6
0
2
0
2401
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3592kb
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: 3612kb
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: 3544kb
input:
1 1000000000 1000000000 1 1 1 1 1000000000 1000000000
output:
2401
result:
ok 1 number(s): "2401"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3484kb
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: 3548kb
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:
wrong answer 174th numbers differ - expected: '0', found: '419753088'