QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#392951#7785. Three Rectanglesnathan4690WA 1ms3640kbC++175.5kb2024-04-18 00:14:512024-04-18 00:14:52

Judging History

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

  • [2024-04-18 00:14:52]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3640kb
  • [2024-04-18 00:14:51]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define el cout << '\n'
#define f1(i,n) for(ll i=1;i<=n;i++)
#define __file_name ""
using namespace std;
const ll maxn = 1e6+5, inf=1e18, mod = 1e9+7;

ll t,h,w;

struct Rect{
    ll ux, dx, uy, dy;
    Rect(){}
    Rect(ll v1, ll v2, ll v3, ll v4) {
        dx = v1;
        dy = v2; ux = v3; uy = v4;
    }
};

Rect make_rect(ll cx, ll cy, ll width, ll height){
    ll c2x = width + cx - 1, c2y = height + cy - 1;
    if(c2x > h){
        c2x -= width-1;
        cx -= width-1;
    }
    if(c2y > w){
        c2y -= height-1;
        cy -= height-1;
    }
    // cout << cx << ' ' << cy << ' ' << c2x << ' ' << c2y << ' ' << width << ' ' << height;el;
    return Rect(cx, cy, c2x, c2y);
}

bool inRect(pair<ll,ll> ptr, Rect x){
    return (x.dx <= ptr.first && ptr.first <= x.ux && x.dy <= ptr.second && ptr.second <= x.uy);
}

ll powmod(ll base, ll exp){
    if(exp == 0) return 1ll;
    if(exp == 1) return base % mod;
    ll v = powmod(base, exp/2);
    if(exp % 2) return ((v*v) % mod * base) % mod;
    else return (v*v) % mod;
}

pair<ll,ll> di[10];
ll chw, ch,cw;

void solve1(){
    // co hxw
    sort(di+1,di+4);
    ll cnt1 = (h - di[1].first + 1) * (w - di[1].second + 1);
    ll cnt2 = (h - di[2].first + 1) * (w - di[2].second + 1);
    cnt1 %= mod;
    cnt2 %= mod;
    cout << (cnt1 * cnt2) % mod;el;
}

void solve2(){
    // co h
    sort(di+1, di+4);
    ll res = 0,ext=0;
    if(di[1].first == h){
        /*
        ll cnt = (h - di[1].first + 1) * (w - di[1].second + 1);
        f1(i,3){
            ll cnt = max(0ll,h - di[i].first + 1) * max(0ll, w - di[i].second - 1); cnt %= mod;
            res += cnt;
        }
        if(h == 1) res += 6;
        else{
            res += 6;
        }
        */
        f1(i,3) f1(j,3){
            if(i == j) continue;
            ll k = 6 - i - j;
            if(di[i].second + di[j].second >= w){
                ext += 2;
                res += max(0ll,h - di[k].first + 1) * max(0ll, w - di[k].second - 1);
            }else{
                if(di[i].second + di[j].second + di[k].second < w) continue;
                ll lb = max(w-di[i].second, di[k].second),ub = min(w, di[j].second + di[k].second);
                if(lb == di[k].second) {res--;ext++;}
                if(ub == w) {res--;ext++;}
                res += ub - lb + 1;
            }
        }
        // cout << ' ' << ext;el;
        res += ext/2;
        res %= mod;
    }else{
        ll cnt = (h - di[1].first + 1) * (w - di[1].second + 1);
        res = 2*cnt % mod;
    }
    // cnt %= mod;
    cout << res%mod;el;
}

bool cmp1(pair<ll,ll> x, pair<ll,ll> y){
    return x.second < y.second;
}

void solve3(){
    // co w
    sort(di+1, di+4, cmp1);
    ll res = 0,ext=0;
    if(cw == 2){
        ll cnt = (h - di[1].first + 1) * (w - di[1].second + 1);
        cnt %= mod;
        cout << (2*cnt)%mod;el;
    }else{
        /*
        f1(i,3){
            ll cnt = max(0ll,h - di[i].first - 1) * max(0ll, w - di[i].second + 1); cnt %= mod;
            res += cnt;
        }
        if(w == 1) res += 1;
        else{
            res += 6;
        }
        */
        f1(i,3) f1(j,3){
            if(i == j) continue;
            ll k = 6 - i - j;
            if(di[i].first + di[j].first >= h){
                ext += 2;
                res += max(0ll,h - di[i].first - 1) * max(0ll, w - di[i].second + 1);
            }else{
                if(di[i].first + di[j].first + di[k].first < h) continue;
                ll lb = max(h-di[i].first, di[k].first),ub = min(h, di[j].first + di[k].first);
                if(lb == di[k].first) {
                    res--;ext++;
                }
                if(ub == h) {res--;ext++;}
                res += ub - lb + 1;
                // cout << ub << ' ' << lb;el;
            }
        }
        res += ext/2;
        res %= mod;
        cout << res;el;
    }
}

void solve4(){
    ll ans = 0;
    Rect r1,r2,r3;
    vector<vector<ll>> all = {{0,0}, {1,1}, {1,w},{h,1}, {h,w}};
    f1(i,4) f1(j,4) f1(k,4){
        // if(i == j || j == k || i == k) continue;
        r1 = make_rect(all[i][0], all[i][1],di[1].first ,di[1].second);
        r2 = make_rect(all[j][0], all[j][1],di[2].first ,di[2].second);
        r3 = make_rect(all[k][0], all[k][1],di[3].first ,di[3].second);
        bool flag = true;
        f1(l,4){
            pair<ll,ll> pp = make_pair(all[l][0], all[l][1]);
            flag &= (inRect(pp, r1) || inRect(pp,r2) || inRect(pp,r3));
        }
        if(flag) {
            // cout << i << ' ' << j << ' ' << k;el;
            ans++;
        }
    }
    if(ch == 1) ans /= 2;
    if(cw == 1) ans /= 2;
    cout << ans;el;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    if(fopen(__file_name ".inp", "r")){
        freopen(__file_name ".inp","r",stdin);
        freopen(__file_name ".out","w",stdout);
    }
    // code here
    cin >> t;
    while(t--){
        cin >> h >> w;
        chw = 0; ch = 0; cw = 0;
        f1(i,3) {
            cin >> di[i].first >> di[i].second;
            if(di[i].first == h){
                ch++;
                if(di[i].second == w) chw++;
            }
            cw += (di[i].second == w);
        }
        if(chw){
            solve1();
        }else if(ch >= 2) solve2();
        else if(cw >= 2) solve3();
        else solve4();
    }
    return 0;
}

/*
Code by: Nguyen Viet Trung Nhan
Cau Giay Secondary School
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

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

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
444444438
111111095
135802502
0
0
0
0
6
222222208
333333327
999999991
814814847
0
0
0
6
444444438
333333327
222222208
111111087
493827185
0
0
6
444444438
222222208
222222208
222222208
888888872
172839523
0
6
444444438
222222208
222222208
111111105
222222...

result:

wrong answer 16th numbers differ - expected: '222222208', found: '444444438'