QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#284154 | #7785. Three Rectangles | iorit# | WA | 1ms | 3696kb | C++14 | 4.5kb | 2023-12-16 11:09:15 | 2023-12-16 11:09:16 |
Judging History
answer
#include <bits/stdc++.h>
#define _rep(i, x, y) for(int i = x; i <= y; ++i)
#define _req(i, x, y) for(int i = x; i >= y; --i)
#define _rev(i, u) for(int i = head[u]; i; i = e[i].nxt)
#define pb push_back
#define fi first
#define se second
#define mst(f, i) memset(f, i, sizeof f)
using namespace std;
#ifdef ONLINE_JUDGE
#define debug(...) 0
#else
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#endif
namespace fastio{
#ifdef ONLINE_JUDGE
char ibuf[50007],*p1 = ibuf, *p2 = ibuf;
#define get() (p1 == p2 && (p2 = (p1 = ibuf) + fread(ibuf, 1, 50007, stdin), p1 == p2) ? EOF : *p1++)
#else
#define get() getchar()
#endif
template<typename T> inline void read(T &t){
T x = 0, f = 1;
char c = getchar();
while(!isdigit(c)){
if(c == '-') f = -f;
c = getchar();
}
while(isdigit(c)) x = x * 10 + c - '0', c = getchar();
t = x * f;
}
template<typename T, typename ... Args> inline void read(T &t, Args&... args){
read(t);
read(args...);
}
template<typename T> void write(T t){
if(t < 0) putchar('-'), t = -t;
if(t >= 10) write(t / 10);
putchar(t % 10 + '0');
}
template<typename T, typename ... Args> void write(T t, Args... args){
write(t), putchar(' '), write(args...);
}
template<typename T> void writeln(T t){
write(t);
puts("");
}
template<typename T> void writes(T t){
write(t), putchar(' ');
}
int reads(char *s){
char c = get(); int len = 0;
while(!isalpha(c)) c = get();
while(isalpha(c)) s[++len] = c, c = get();
return len;
}
#undef get
};
using namespace fastio;
#define multitest() int T; read(T); _rep(tCase, 1, T)
typedef long long ll;
typedef pair<int, int> PII;
const ll mod = 1e9 + 7;
ll H, W, h[5], w[5];
void sorth(){
if(h[1] < h[2]) swap(h[1], h[2]), swap(w[1], w[2]);
if(h[1] < h[3]) swap(h[1], h[3]), swap(w[1], w[3]);
if(h[2] < h[3]) swap(h[2], h[3]), swap(w[2], w[3]);
}
void sortw(){
if(w[1] < w[2]) swap(h[1], h[2]), swap(w[1], w[2]);
if(w[1] < w[3]) swap(h[1], h[3]), swap(w[1], w[3]);
if(w[2] < w[3]) swap(h[2], h[3]), swap(w[2], w[3]);
}
ll lol(ll x, ll y, ll z, ll n){
if(x + z >= n) return max(0ll, n - y - 1);
ll l = max(2ll, n - z - y + 1), r = min(n - y, x + 1);
if(l > r) return 0;
return r - l + 1;
}
ll fufu(ll x, ll y, ll z, ll n){
if(x + y + z < n) return 0;
if(x < y) swap(x, y); if(x < z) swap(x, z); if(y < z) swap(y, z);
if(x == n) return (n - y + 1) % mod * (n - z + 1) % mod;
ll res = lol(x, y, z, n) + lol(x, z, y, n) + lol(y, x, z, n) + lol(y, z, x, n) + lol(z, x, y, n) + lol(z, y, x, n);
res %= mod;
if(max(x, y) + z >= n) res += 2;
if(max(x, z) + y >= n) res += 2;
if(max(y, z) + x >= n) res += 2;
return res % mod;
}
void furina(){
read(H, W);
int ch = 0, cw = 0;
_rep(i, 1, 3) read(h[i], w[i]), ch += h[i] == H, cw += w[i] == W;
if(ch == 2){
sorth();
if(h[1] + h[2] < H) return puts("0"), void();
ll ans = 2ll * (H - h[3] + 1) % mod * (W - w[3] + 1) % mod;
return writeln(ans), void();
}
if(cw == 2){
sortw();
if(w[1] + w[2] < W) return puts("0"), void();
ll ans = 2ll * (H - h[3] + 1) % mod * (W - w[3] + 1) % mod;
return writeln(ans);
}
if(ch == 3) return writeln(fufu(w[1], w[2], w[3], W));
if(cw == 3) return writeln(fufu(h[1], h[2], h[3], H));
if(!cw){
if(!ch) return puts("0"), void();
if(ch == 1){
sorth();
if(h[2] + h[3] >= H && min(w[2], w[3]) + w[1] >= W) return puts("4"), void();
return puts("0"), void();
}
}
if(!ch && cw == 1){
sortw();
if(w[2] + w[3] >= W && min(h[2], h[3]) + h[1] >= H) return puts("4"), void();
return puts("0"), void();
}
if(ch == 1 && cw == 1){
sorth();
if(h[1] == H && w[1] == W){
ll ans = (H - h[2] + 1) * (W - w[2] + 1) % mod * (H - h[3] + 1) % mod * (W - w[3] + 1) % mod;
return writeln(ans);
}
if(w[2] < w[3]) swap(h[2], h[3]), swap(w[2], w[3]);// w[2] = W, h[1] = H
if(w[3] + w[1] >= W && h[3] + h[2] >= H) return puts("4"), void();
return puts("0"), void();
}
}
int main(){
multitest(){
furina();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3676kb
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: 3696kb
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: 3540kb
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: 1ms
memory: 3500kb
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 81st numbers differ - expected: '888888889', found: '777777771'