QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#126691 | #4246. Cactus is Money | minhcool | WA | 6ms | 25712kb | C++17 | 4.8kb | 2023-07-18 21:27:57 | 2023-07-18 21:27:59 |
Judging History
answer
#define local
#ifndef local
#include ""
#endif
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
//#define mp make_pair
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
const int N = 3e5 + 5;
const int oo = 1e18 + 7, mod = 1e9 + 7;
mt19937 rng(1);
int rnd(int l, int r){
int temp = rng() % (r - l + 1);
return abs(temp) + l;
}
ii diff(ii a, ii b){
return {a.fi - b.fi, a.se - b.se};
}
int cross(ii a, ii b){
return a.fi * b.se - a.se * b.fi;
}
vector<ii> rot(vector<ii> v){
int pos = 0;
for(int i = 1; i < v.size(); i++){
if(v[pos].se > v[i].se || (v[pos].se == v[i].se && v[pos].fi > v[i].fi)) pos = i;
}
vector<ii> v2;
for(int i = pos; i < v.size(); i++) v2.pb(v[i]);
for(int i = 0; i < pos; i++) v2.pb(v[i]);
return v2;
}
vector<ii> mincow(vector<ii> a, vector<ii> b){
a = rot(a), b = rot(b);
// for(auto it : a) cout << "OK1 " << it.fi << " " << it.se << "\n";
// for(auto it : b) cout << "OK2 " << it.fi << " " << it.se << "\n";
a.pb(a[0]), a.pb(a[1]);
b.pb(b[0]), b.pb(b[1]);
int itr1 = 0, itr2 = 0;
vector<ii> c;
while((itr1 < a.size() - 2) || (itr2 < b.size() - 2)){
c.pb({a[itr1].fi + b[itr2].fi, a[itr1].se + b[itr2].se});
int temp = cross(diff(a[itr1 + 1], a[itr1]), diff(b[itr2 + 1], b[itr2]));
// cout << a.size() << " " << b.size() << " " << itr1 << " " << itr2 << "\n";
if((temp >= 0) && itr1 < a.size() - 2) itr1++;
if((temp <= 0) && itr2 < b.size() - 2) itr2++;
//if(temp <= 0 && itr2 < b.size() - 2) itr2++;
}
return c;
}
int n, m;
vector<ii> vc;
bool ccw(ii a, ii b, ii c){// true if (a, b, c) counter clockwise
int val = cross(diff(b, a), diff(c, b));
if(val > 0) return 1;
return 0;
}
ii mini;
bool cmp(ii a, ii b){
return ccw(mini, a, b);
}
vector<ii> cvh(vector<ii> a){
int pos = 0;
for(int i = 1; i < a.size(); i++){
if(a[i].fi < a[pos].fi || (a[i].fi == a[pos].fi && a[i].se < a[pos].se)) pos = i;
}
swap(a[a.size() - 1], a[pos]);
vector<ii> v;
mini = a.back();
v.pb(a.back());
a.pop_back();
sort(a.begin(), a.end(), cmp);
for(auto it : a){
while(v.size() >= 2 && !ccw(v[v.size() - 2], v[v.size() - 1], it)) v.pop_back();
v.pb(it);
}
return v;
}
vector<iiii> edges;
vector<ii> Adj[N];
bool vis[N], ck[N], incyc[N];
ii par[N];
int le[N], ri[N], cnt;
bool anc(int x, int y){
return (le[x] <= le[y] && ri[x] >= ri[y]);
}
void dfs(int u){
cnt++;
le[u] = cnt;
vis[u] = 1;
for(auto it : Adj[u]){
int v = it.fi, ind = it.se;
if(vis[v]) continue;
ck[ind] = 1;
par[v] = {u, ind};
dfs(v);
}
ri[u] = cnt;
}
int counter = 0;
vector<ii> cvhs[N];
vector<ii> get(int l, int r){
if(l == r) return cvhs[l];
int mid = (l + r) >> 1;
return mincow(get(l, mid), get(mid + 1, r));
}
#ifdef local
void process(){
cin >> n >> m;
for(int i = 1; i <= m; i++){
int x, y, a, b;
cin >> x >> y >> a >> b;
edges.pb({{x, y}, {a, b}});
Adj[x].pb({y, i - 1});
Adj[y].pb({x, i - 1});
}
for(int i = 1; i <= n; i++) if(!vis[i]) dfs(i);
//cout << "OKAY\n";
//exit(0);
for(int i = 0; i < m; i++){
if(ck[i]) continue;
int x = edges[i].fi.fi, y = edges[i].fi.se;
//cout << i << " " << x << " " << y << "\n";
vector<ii> v;
while(!anc(x, y)){
incyc[par[x].se] = 1;
v.pb(edges[par[x].se].se);
x = par[x].fi;
}
while(!anc(y, x)){
incyc[par[x].se] = 1;
v.pb(edges[par[y].se].se);
y = par[y].fi;
}
incyc[i] = 1;
v.pb(edges[i].se);
vector<ii> points;
int tol1 = 0, tol2 = 0;
for(auto it : v){
tol1 += it.fi, tol2 += it.se;
}
for(auto it : v) points.pb({tol1 - it.fi, tol2 - it.se});
//for(auto it : v) cout << it.fi << " " << it.se << "\n";
points = cvh(points);
//for(auto it : v) cout << it.fi << " " << it.se << "\n";
counter++;
cvhs[counter] = points;
}
ii temp = {0, 0};
for(int i = 0; i < m; i++){
if(!incyc[i]){
temp.fi += edges[i].se.fi, temp.se += edges[i].se.se;
}
}
vector<ii> v = get(1, counter);
int answer = oo;
for(auto it : v){
answer = min(answer, (it.fi + temp.fi) * (it.se + temp.se));
}
cout << answer << "\n";
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen("kek.inp", "r", stdin);
//freopen("kek.out", "w", stdout);
process();
}
#endif
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 6ms
memory: 23664kb
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: 1ms
memory: 25708kb
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: 1ms
memory: 25712kb
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:
16303051008
result:
wrong answer 1st numbers differ - expected: '6732185824', found: '16303051008'