QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#346179 | #7520. Monster Generator | MiniLong | WA | 0ms | 3660kb | C++14 | 5.4kb | 2024-03-07 21:52:56 | 2024-03-07 21:52:58 |
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
typedef long long ll;
typedef __int128_t LL;
typedef pair<ll, ll> PII;
namespace fastio{
char ibuf[50007],*p1 = ibuf, *p2 = ibuf;
#ifdef ONLINE_JUDGE
#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(' ');
}
#undef get
};
using namespace fastio;
#define multitest() int T; read(T); _rep(tCase, 1, T)
namespace Calculation{
const ll mod = 998244353;
ll ksm(ll p, ll h){ll base = p % mod, res = 1; while(h){if(h & 1ll) res = res * base % mod; base = base * base % mod, h >>= 1ll;} return res;}
void dec(ll &x, ll y){x = ((x - y) % mod + mod) % mod;}
void add(ll &x, ll y){x = (x + y) % mod;}
void mul(ll &x, ll y){x = x * y % mod;}
ll sub(ll x, ll y){return ((x - y) % mod + mod) % mod;}
ll pls(ll x, ll y){return ((x + y) % mod + mod) % mod;}
ll mult(ll x, ll y){return x * y % mod;}
}
using namespace Calculation;
const int N = 105, M = 10005;
typedef unsigned long long ull;
ll n, m, cnt, p[M];
struct node{
ll a, b, da, db;
}a[N];
int b[N];
bool check(ll x, ll y, LL mid){
LL xa = a[x].a + mid * a[x].da, xb = a[x].b + mid * a[x].db;
LL ya = a[y].a + mid * a[y].da, yb = a[y].b + mid * a[y].db;
// debug("check mid:%d x(%d,%d) y(%d,%d)\n", (ll)mid, (ll)xa, (ll)xb, (ll)ya, (ll)yb);
bool ok = xb - xa <= 0 && yb - ya > 0;
if(xb - xa <= 0 && yb - ya <= 0) ok = xb < yb;
if(xb - xa > 0 && yb - ya > 0) ok = xa > ya;
return ok;
}
ll gett(ll x, ll y){
ll l = 0, r = m, res = 0;
if(check(x, y, 0)) swap(x, y);
while(l <= r){
ll mid = l + r >> 1ll;
if(check(x, y, mid)) res = mid, r = mid - 1;
else l = mid + 1;
}
// debug("(%d,%d) res:%d\n", x, y, res);
return res;
}
ull ans;
void solve(ll tl, ll tr){
_rep(i, 1, n) b[i] = i;
sort(b + 1, b + 1 + n, [&](int x, int y){
return !check(x, y, tl);
});
// debug("solve [%d,%d]\n", tl, tr);
// _rep(i, 1, n) debug("%d ", b[i]); debug("\n");
LL k = 0, t = 0;
vector<pair<LL, LL> > h;
_rep(i, 1, n){
k += a[b[i]].da, t += a[b[i]].a;
h.pb({k, t});
debug("(%d,%d) ", (ll)k, (ll)t);
k -= a[b[i]].db, t -= a[b[i]].b;
}
debug("\n");
sort(h.begin(), h.end());
vector<pair<LL, LL> > g;
g.pb(*h.begin());
int len = 1;
_rep(i, 1, h.size() - 1){
while(len > 1 && ((g[len - 1].se - h[i].se) * (g[len - 1].fi - g[len - 2].fi) < (g[len - 2].se - g[len - 1].se) * (h[i].fi - g[len - 1].fi)) || len && g[len - 1].fi == h[i].fi){
len--;
g.pop_back();
}
g.pb(h[i]);
len++;
}
LL lst = tl;
// for(auto &i : g) debug("(%d,%d) ", (ll)i.fi, (ll)i.se);
debug("\n");
auto calc = [&](LL l, LL r, int id) -> ull{
LL yl = g[id].fi * l + g[id].se, yr = g[id].fi * r + g[id].se;
LL cur1 = (yl + yr), cur2 = r - l + 1;
if(cur1 % 2 == 0) cur1 /= 2;
else cur2 /= 2;
if((cur1 < 0) ^ (cur2 < 0)) return 0;
if(cur1 < 0) cur1 = -cur1;
if(cur2 < 0) cur2 = -cur2;
ull res = ((ull)cur1) * ((ull)cur2);
// debug("calc [%d,%d,id:%d] ans:%Ld | ", (ll)l, (ll)r, id, res);
return res;
};
_rep(i, 0, len - 2){
LL l = lst, r = (g[i + 1].se - g[i].se) / (g[i].fi - g[i + 1].fi);
if(r > tr) r = tr;
if(r < l) continue;
ans += calc(l, r, i);
lst = r + 1;
if(lst > tr) break;
}
if(lst <= tr) ans += calc(lst, tr, len - 1);
// debug("\n");
// debug("-------------\n");
}
int main(){
read(n, m);
_rep(i, 1, n){
read(a[i].a, a[i].da, a[i].b, a[i].db);
_rep(j, 1, i - 1){
p[++cnt] = gett(i, j);
}
}
p[++cnt] = m, p[++cnt] = 0;
sort(p + 1, p + 1 + cnt);
cnt = unique(p + 1, p + 1 + cnt) - p - 1;
// _rep(i, 1, cnt) writes(p[i]); puts("");
int lst = p[1];
_rep(i, 2, cnt) solve(lst, p[i] - 1), lst = p[i];
solve(m, m);
writeln(ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3648kb
input:
3 5 3 1 5 2 4 2 1 3 1 9 100 1
output:
113
result:
ok single line: '113'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
3 100000000 3 1 5 2 4 2 1 3 1 9 100 1
output:
35000000549999998
result:
ok single line: '35000000549999998'
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3660kb
input:
10 1000000000000000000 776874380544333 197 471391764744275 33 159838820333814 107 677112662750393 41 962335658276824 48 255593531071176 11 127404116579775 209 268525254990127 34 647620110614714 76 897947476313307 13 146196843402516 221 772928712898807 39 637929916804442 2 716937021892338 15 64200226...
output:
5294441905123924003
result:
wrong answer 1st lines differ - expected: '17883317185357051350', found: '5294441905123924003'