QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#393453#7785. Three Rectanglesnathan4690Compile Error//C++176.5kb2024-04-18 16:53:392024-04-18 16:53:39

Judging History

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

  • [2024-04-18 16:53:39]
  • 评测
  • [2024-04-18 16:53:39]
  • 提交

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;
        if(di[2].second + di[3].second < w) res = 0;
    }
    // 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;
        if(di[2].first + di[3].first < h) cnt = 0;
        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;
                // cout << "! " << di[i].first << ' ' << di[j].first << ' ' << res << ' ';
                res += max(0ll,h - di[k].first - 1) * max(0ll, w - di[k].second + 1);
                // cout << res << ' ';el;
            }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 << di[i].first << ' ' << di[j].first << ' ' << 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;
}*/

void solve4(){
    if(ch == 0 && cw == 0){
        cout << 0;el;
        return;
    }
    if(ch == 1){
        sort(d+1,d+4);
        if(di[1].first + di[2].first >= h && min(di[1].second, di[2].second) + di[3].second >= w){
            cout << 4;
        }else cout << 0;
        el;
    }else{
        sort(d+1,d+4,cmp1);
        if(di[2].second + di[1].second >= w && min(di[1].first, di[2].first) + di[3].first >= h){
            cout << 4;
        }else cout << 0;
        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;
    f1(_,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(_ > 15){
            cout << h << ' ' << w;el;
            f1(i,3) cout << di[i].first << ' ' << di[i].second << '\n';
        }
        */
        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

answer.code: In function ‘void solve4()’:
answer.code:181:14: error: ‘d’ was not declared in this scope
  181 |         sort(d+1,d+4);
      |              ^
answer.code:187:14: error: ‘d’ was not declared in this scope
  187 |         sort(d+1,d+4,cmp1);
      |              ^
answer.code: In function ‘int main()’:
answer.code:199:16: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  199 |         freopen(__file_name ".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
answer.code:200:16: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  200 |         freopen(__file_name ".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~