QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#132895 | #4246. Cactus is Money | fractal | WA | 4ms | 35096kb | C++14 | 3.8kb | 2023-08-01 02:49:49 | 2023-08-01 02:49:50 |
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];
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;
anc[to] = {v, id};
if (u[to] == 1) {
int k = v;
vec.pb({});
while (true) {
vec.back().pb({a[anc[k].S], b[anc[k].S]});
u[k] = 2;
k = anc[k].F;
if (k == v) break;
}
}
else if (u[to] == 0) {
dfs(to, v);
}
}
}
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: 4ms
memory: 35096kb
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: 4ms
memory: 34744kb
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: -100
Wrong Answer
time: 4ms
memory: 33704kb
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:
7045467156
result:
wrong answer 1st numbers differ - expected: '6732185824', found: '7045467156'