QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#400981#7785. Three Rectanglesucup-team228#WA 2ms3836kbC++208.9kb2024-04-27 19:35:012024-04-27 19:35:01

Judging History

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

  • [2024-04-27 19:35:01]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3836kb
  • [2024-04-27 19:35:01]
  • 提交

answer

//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx2") // doesn't work on Yandex
//#pragma GCC target("avx") // for old judges
//#pragma GCC target("bmi,bmi2,lzcnt,popcnt") // fast bit operations

#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <algorithm>
#include <cassert>
#include <chrono>
#include <random>
#include <string>
#include <numeric>
#include <complex>
#include <tuple>
#include <utility>
#include <bitset>
#include <array>
#include <stack>
#include <sstream>
#include <unordered_set>

using namespace std;
typedef long long ll;

string to_string(string a) { return '"' + a + '"'; }
string to_string(char a) { return "'" + string(1, a) + "'"; }
string to_string(const char* a) { return to_string((string) a); }
string to_string(bool a) { return a ? "true" : "false"; }
template <class T1, class T2>
string to_string(pair<T1, T2> a) {
    return "(" + to_string(a.first) + ", " + to_string(a.second) + ")";
}
template <class T>
string to_string(T a) {
    bool first = true; string res = "{";
    for (const auto& i : a) {
        if (!first) res += ", ";
        first = false;
        res += to_string(i);
    }
    res += "}";
    return res;
}
void debug_out() { cerr << endl; }
template <class T1, class... T2>
void debug_out(T1 a, T2... b) {
    cerr << " " << to_string(a);
    debug_out(b...);
}

#ifdef LOCAL
#define out(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define out(...) 42
#endif

clock_t start_time; void start_timer() { start_time = clock(); }
double get_time() { return (double) (clock() - start_time) / CLOCKS_PER_SEC; }

void Solve();

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
    freopen("usr/share/man/man1/input.txt", "r", stdin);
#endif
    start_timer();
    Solve();
#ifdef LOCAL
    cerr << fixed << setprecision(3);
    cerr << endl << "Time spent: " << get_time() << endl;
#endif
    return 0;
}

// do something, stay focused
// look for stupid bugs
// guess, slow, stress
// don't overgeneralize
// don't rush

// don't waste time on standings

// SOLVE THE PROBLEM OR DIE TRYING
// THE SOLUTION IS ALWAYS SIMPLE
// THE CODE IS ALWAYS SHORT

const int mod = 1e9 + 7;

int add(int a, int b) {
    a += b;
    if (a >= mod) a -= mod;
    return a;
}

int sub(int a, int b) {
    a -= b;
    if (a < 0) a += mod;
    return a;
}

int mult(int a, int b) {
    return a * 1ll * b % mod;
}

int bit(int mask, int i) {
    return (mask >> i) & 1;
}

const int CARD = (1 << 0) | (1 << 3) | (1 << 6) | (1 << 9);

vector<int> masks;

void Solve() {
    for (int mask = 0; mask < (1 << 12); mask++) {
        bool bad = 0;
        for (int j = 0; j <= 3; j++) {
            int cov = (mask >> (3 * j)) & 7;
            if (!cov) {
                bad = 1;
                break;
            }
        }
        for (int i = 0; i <= 2; i++) {
            int card = CARD & (mask >> i);
            int cnt = __builtin_popcount(card);
            if (cnt >= 3) {
                bad = 1;
                break;
            }
            if (cnt == 2) {
                int diag = 1 + (1 << 6);
                if (card == diag || card == (diag << 3)) {
                    bad = 1;
                    break;
                }
            }
        }
        if (!bad) {
            masks.push_back(mask);
        }
    }
    int T;
    cin >> T;
    while (T--) {
        int H, W;
        int h[3];
        int w[3];
        bool full = 0;
        cin >> H >> W;
        for (int i = 0; i <= 2; i++) {
            cin >> h[i] >> w[i];
            if (h[i] == H && w[i] == W) {
                full = 1;
            }
        }
        int ans = 0;
        if (full) {
            ans = 1;
            for (int i = 0; i <= 2; i++) {
                ans = mult(ans, mult(H - h[i] + 1, W - w[i] + 1));
            }
            cout << ans << "\n";
            continue;
        }
        for (int mask : masks) {
            bool bad = 0;
            vector<int> unfixed;
            for (int i = 0; i <= 2; i++) {
                int card = CARD & (mask >> i);
                int cnt = __builtin_popcount(card);
                if (cnt == 2) {
                    for (int j = 0; j <= 3; j++) {
                        int nxt = (j + 1) % 4;
                        int side = (1 << (3 * j)) | (1 << (3 * nxt));
                        if (card == side) {
                            if ((j % 2 == 0 && w[i] < W) || (j % 2 == 1 && h[i] < H)) {
                                bad = 1;
                                break;
                            }
                        }
                    }
                    if (bad) {
                        break;
                    }
                }
                if (cnt == 1 && (h[i] == H || w[i] == W)) {
                    bad = 1;
                    break;
                }
                if (cnt == 0) {
                    if (h[i] + w[i] >= H + W - 1) {
                        bad = 1;
                        break;
                    }
                    unfixed.push_back(i);
                }
            }
            if (bad) {
                continue;
            }
            if (unfixed.empty()) {
                for (int j = 0; j <= 3; j++) {
                    int nxt = (j + 1) % 4;
                    int mx_j = 0;
                    int mx_nxt = 0;
                    if (j % 2 == 0) {
                        for (int i = 0; i <= 2; i++) {
                            if (bit(mask, 3 * j + i)) {
                                mx_j = max(mx_j, w[i]);
                            }
                            if (bit(mask, 3 * nxt + i)) {
                                mx_nxt = max(mx_nxt, w[i]);
                            }
                        }
                        if (mx_j + mx_nxt < W) {
                            bad = 1;
                            break;
                        }
                    }
                    else {
                        for (int i = 0; i <= 2; i++) {
                            if (bit(mask, 3 * j + i)) {
                                mx_j = max(mx_j, h[i]);
                            }
                            if (bit(mask, 3 * nxt + i)) {
                                mx_nxt = max(mx_nxt, h[i]);
                            }
                        }
                        if (mx_j + mx_nxt < H) {
                            bad = 1;
                            break;
                        }
                    }
                }
                if (bad) {
                    continue;
                }
                ans = add(ans, 1);
            }
            else if (unfixed.size() == 1) {
                int id = unfixed[0];
                if (h[0] == H && h[1] == H && h[2] == H && w[0] + w[1] + w[2] >= W) {
                    int w0 = -1;
                    int w1 = -1;
                    int w2 = w[id];
                    for (int i = 0; i <= 2; i++) {
                        if (i != id) {
                            if (w0 == -1) {
                                w0 = w[i];
                            }
                            else {
                                w1 = w[i];
                            }
                        }
                    }
                    if (w0 + w1 < W) {
                        int l = max(1, W - w1 - w2);
                        int r = min(w0, W - 1 - w2);
                        ans = add(ans, r - l + 1);
                    }
                    else {
                        ans = add(ans, W - w2 - 1);
                    }
                    //out(w0, w2, w1, r - l + 1);
                }
                else if (w[0] == W && w[1] == W && w[2] == W && h[0] + h[1] + h[2] >= H) {
                    int h0 = -1;
                    int h1 = -1;
                    int h2 = h[id];
                    for (int i = 0; i <= 2; i++) {
                        if (i != id) {
                            if (h0 == -1) {
                                h0 = h[i];
                            }
                            else {
                                h1 = h[i];
                            }
                        }
                    }
                    if (h0 + h1 < H) {
                        int l = max(1, H - h1 - h2);
                        int r = min(h0, H - 1 - h2);
                        ans = add(ans, r - l + 1);
                    }
                    else {
                        ans = add(ans, H - h2 - 1);
                    }
                }
            }
            else {
                assert(0);
            }
        }
        cout << ans << "\n";
    }
}

詳細信息

Test #1:

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

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

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

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: 2ms
memory: 3684kb

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:

wrong answer 314th numbers differ - expected: '555555547', found: '6'