QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#132896 | #4246. Cactus is Money | fractal | WA | 10ms | 37176kb | C++14 | 3.9kb | 2023-08-01 03:05:55 | 2023-08-01 03:05:58 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define speed ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define sz(x) (int)x.size()
#define len(x) (int)strlen(x)
#define all(x) x.begin(), x.end()
#define debug cerr << "OK\n";
#define ub upper_bound
#define lb lower_bound
#define make_unique(x) sort(all(x)), x.erase(unique(all(x)), x.end())
mt19937 bruh(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rofl(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef set<int> si;
typedef set<ll> sll;
typedef set<pii> spii;
typedef set<pll> spll;
typedef multiset <int> msi;
typedef multiset <ll> msll;
typedef map <int, int> mi;
typedef map <ll, ll> mll;
const int N = 1e6 + 2;
const int M = 1e5;
const int mod = 0;
const int inf = 2e9 + 3;
const ll INF = 1e18;
const ld pi2 = 2.0 * 3.141592653589793;
const ld pi = 3.141592653589793;
const ld eps = 1e-12;
const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
#ifndef PC
#define gcd __gcd
#endif
void files(string s = "main") {
#ifndef PC
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
#endif
}
int add(int a, int b) {
if (a + b < 0) return a + b + mod;
if (a + b >= mod) return a + b - mod;
return a + b;
}
int mul(int a, int b) {
return a * 1LL * b % mod;
}
int binpow(int a, int n) {
int ret = 1;
while (n) {
if (n & 1) ret = mul(ret, a);
a = mul(a, a);
n >>= 1;
}
return ret;
}
int n, m, u[N], was[N];
ll A, B, a[N], b[N];
pii anc[N];
vpii g[N];
vector<vpii> vec;
void dfs(int v, int p = 0) {
u[v] = -1;
for (auto [to, id] : g[v]) {
if (to == p) continue;
if (u[to] == 0) {
anc[to] = {v, id};
dfs(to, v);
}
else if (was[id] == 0) {
int k = v;
vec.pb({});
while (true) {
vec.back().pb({a[anc[k].S], b[anc[k].S]});
u[k] = v;
k = anc[k].F;
if (k == to) break;
}
was[id] = 1;
vec.back().pb({a[id], b[id]});
}
}
}
int sign(ll x) {
if (x == 0) return 0;
return x / abs(x);
}
pii add(pii v, pii u) {
v.F += u.F, v.S += u.S;
return v;
}
pii sub(pii v, pii u) {
v.F -= u.F, v.S -= u.S;
return v;
}
int prod(pii v, pii u) {
return sign(v.F * u.S - v.S * u.F);
}
int dot(pii v, pii u) {
return sign(v.F * v.S + u.F * u.S);
}
int pos(pii p) {
if (p.F > 0) return 0;
if (p.F < 0) return 1;
if (p.S >= 0) return 0;
return 1;
}
bool cmp(pii v, pii u) {
if (pos(v) != pos(u)) return pos(v) < pos(u);
return prod(u, v) >= 0;
}
vpii convex(vpii v) {
sort(all(v));
vpii c;
c.pb({0, 0});
for (auto p : v) {
while (sz(c) > 1 && prod(sub(c[sz(c) - 1], c[sz(c) - 2]), sub(p, c[sz(c) - 2])) >= 0) {
c.ppb();
}
c.pb(p);
}
vpii r;
for (int i = 0; i < sz(c); ++i) {
r.pb(sub(c[(i + 1) % sz(c)], c[i]));
}
return r;
}
int main() {
speed;
cin >> n >> m;
for (int i = 1, v, u; i <= m; ++i) {
cin >> v >> u >> a[i] >> b[i];
A += a[i], B += b[i];
g[v].pb({u, i});
g[u].pb({v, i});
}
dfs(1);
vpii V;
for (auto &v : vec) {
for (auto p : convex(v))
V.pb(p);
}
sort(all(V), cmp);
pii P = {0, 0};
ll ans = A * B;
for (auto p : V) {
P = add(P, p);
ans = min(ans, (A - P.F) * (B - P.S));
}
cout << ans << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 36068kb
input:
3 3 1 2 0 1000 2 3 0 1000 3 1 1 1
output:
0
result:
ok 1 number(s): "0"
Test #2:
score: 0
Accepted
time: 5ms
memory: 36484kb
input:
5 5 1 2 666 10 2 3 555 1000 3 1 444 345 1 4 222 234 2 5 333 123
output:
1185480
result:
ok 1 number(s): "1185480"
Test #3:
score: 0
Accepted
time: 6ms
memory: 36156kb
input:
5 6 1 3 12316 13729 1 2 171 10309 5 1 47389 7369 2 4 43318 36867 1 4 30728 43835 5 3 24437 31639
output:
6732185824
result:
ok 1 number(s): "6732185824"
Test #4:
score: 0
Accepted
time: 2ms
memory: 37176kb
input:
6 6 5 2 36032 49949 4 5 8963 9741 3 4 4004 35098 4 1 14459 30350 4 6 39612 8568 1 5 8645 16098
output:
11617618224
result:
ok 1 number(s): "11617618224"
Test #5:
score: 0
Accepted
time: 1ms
memory: 37008kb
input:
6 6 6 1 1516 16290 3 5 47834 15228 5 1 14795 44496 2 6 21296 36977 6 3 42659 16631 4 3 9808 31313
output:
13124412318
result:
ok 1 number(s): "13124412318"
Test #6:
score: 0
Accepted
time: 1ms
memory: 35888kb
input:
7 7 1 7 42781 13704 7 3 48779 17985 6 4 27969 24986 4 7 33333 35700 5 7 4859 49960 6 2 23927 33500 6 1 11232 15327
output:
24803495714
result:
ok 1 number(s): "24803495714"
Test #7:
score: 0
Accepted
time: 10ms
memory: 36056kb
input:
10 11 7 3 43798 8096 5 7 36600 4126 2 6 20599 15893 9 6 7541 5621 4 9 22047 10608 5 10 21235 2700 1 10 19260 8862 4 3 22407 37504 5 1 12867 1738 1 8 48480 15236 2 5 43525 13679
output:
19944198324
result:
ok 1 number(s): "19944198324"
Test #8:
score: 0
Accepted
time: 3ms
memory: 36648kb
input:
10 12 10 2 21765 14299 4 2 8316 29600 3 2 36018 33286 4 5 30741 46828 9 7 13354 18461 9 5 11896 14216 6 1 35705 34008 1 9 41496 21860 7 5 37709 34178 8 7 1595 27497 6 9 12139 37471 3 5 43310 12734
output:
39767313936
result:
ok 1 number(s): "39767313936"
Test #9:
score: 0
Accepted
time: 1ms
memory: 37136kb
input:
10 13 10 1 28967 29646 9 1 45852 47509 6 1 2590 36591 5 4 21715 40134 1 5 44167 42132 2 10 27289 12132 5 7 26720 1258 1 3 2762 28223 3 6 6966 48096 5 8 23536 33618 7 8 28326 9456 1 2 4885 15100 5 9 41414 32957
output:
43567826244
result:
ok 1 number(s): "43567826244"
Test #10:
score: -100
Wrong Answer
time: 6ms
memory: 37036kb
input:
20 28 18 19 35583 99 15 18 30705 19256 14 18 20288 26882 18 4 39622 18793 11 7 47613 25425 8 18 33445 7046 18 13 37838 47190 18 1 47524 18152 8 10 20627 40858 18 6 49396 47654 9 18 9453 36001 20 18 33280 38985 11 18 47686 42244 1 20 8726 35210 14 6 20998 13452 18 10 10397 48525 19 4 45811 48722 5 17...
output:
206217657044
result:
wrong answer 1st numbers differ - expected: '196145757738', found: '206217657044'