QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#198684 | #4246. Cactus is Money | bachbeo2007 | RE | 4ms | 19260kb | C++23 | 4.9kb | 2023-10-03 16:27:23 | 2023-10-03 16:27:23 |
Judging History
answer
// Judges with GCC >= 12 only needs Ofast
// #pragma GCC optimize("O3,no-stack-protector,fast-math,unroll-loops,tree-vectorize")
// MLE optimization
// #pragma GCC optimize("conserve-stack")
// Old judges
// #pragma GCC target("sse4.2,popcnt,lzcnt,abm,mmx,fma,bmi,bmi2")
// New judges. Test with assert(__builtin_cpu_supports("avx2"));
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
// Atcoder
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma")
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
- insert(x),erase(x)
- find_by_order(k): return iterator to the k-th smallest element
- order_of_key(x): the number of elements that are strictly smaller
*/
#include<bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_real_distribution<> pp(0.0,1.0);
#define int long long
#define ld long double
#define pii pair<int,int>
#define piii pair<int,pii>
#define mpp make_pair
#define fi first
#define se second
const int inf=1e18;
const int mod=998244353;
const int maxn=200005;
const int bl=650;
const int maxs=655;
const int maxm=200005;
const int maxq=1000005;
const int maxl=20;
const int maxa=1000000;
const int root=3;
int power(int a,int n){
int res=1;
while(n){
if(n&1) res=res*a%mod;
a=a*a%mod;n>>=1;
}
return res;
}
const int iroot=power(3,mod-2);
const int base=101;
struct pt{
int x,y;
pt operator + (const pt &p)const{
return pt{x+p.x,y+p.y};
}
pt operator - (const pt &p)const{
return pt{x-p.x,y-p.y};
}
int operator *(const pt &p)const{
return x*p.y-y*p.x;
}
friend bool operator<(pt a,pt b){return make_pair(a.y,a.x)<make_pair(b.y,b.x);}
friend bool operator>(pt a,pt b){return make_pair(a.y,a.x)>make_pair(b.y,b.x);}
friend bool operator==(pt a,pt b){return make_pair(a.y,a.x)==make_pair(b.y,b.x);}
};
void reorder(vector<pt> &P){
int pos=0;
for(int i=1;i<(int)P.size();i++)
if(P[i].y<P[pos].y || (P[i].x<P[pos].x && P[i].y==P[pos].y)) pos=i;
rotate(P.begin(),P.begin()+pos,P.end());
}
vector<pt> minkowski(vector<pt> &P,vector<pt> &Q){
reorder(P);reorder(Q);
P.push_back(P[0]);P.push_back(P[1]);
Q.push_back(Q[0]);Q.push_back(Q[1]);
vector<pt> res;
int i=0,j=0;
while(i<(int)P.size()-2 || j<(int)Q.size()-2){
res.push_back(P[i]+Q[j]);
int cross=(P[i+1]-P[i])*(Q[j+1]-Q[j]);
if(cross>=0 && i<(int)P.size()-2) i++;
if(cross<=0 && j<(int)Q.size()-2) j++;
}
return res;
}
vector<pt> convex_hull(vector<pt> p){
sort(p.begin(),p.end());
p.erase(unique(p.begin(),p.end()),p.end());
pt st=p[0],en=p.back();
vector<pt> up,dn;
for(int i=0;i<(int)p.size();i++){
int o=(en-st)*(p[i]-st);
if(o>=0){
while((int)up.size()>=2 && (up.back()-up[(int)up.size()-2])*(p[i]-up[(int)up.size()-2])>=0) up.pop_back();
up.push_back(p[i]);
}
if(o<=0){
while((int)dn.size()>=2 && (dn.back()-dn[(int)dn.size()-2])*(p[i]-dn[(int)dn.size()-2])<=0) dn.pop_back();
dn.push_back(p[i]);
}
}
for(int i=(int)up.size()-2;i>=1;i--) dn.push_back(up[i]);
return dn;
}
int n,m,sa,sb,res=inf;
vector<pair<int,pt>> edge[maxn];
vector<pt> cur[maxn];
pt pu[maxn];
int par[maxn],dep[maxn];
void dfs(int u,int p){
dep[u]=dep[p]+1;par[u]=p;
for(auto [v,w]:edge[u]){
if(!dep[v]){
pu[v]=w;
dfs(v,u);
}
}
}
void solve(){
cin >> n >> m;
for(int i=1;i<=m;i++){
int u,v,a,b;cin >> u >> v >> a >> b;
edge[u].push_back({v,{a,b}});
edge[v].push_back({u,{a,b}});
sa+=a;sb+=b;
}
dfs(1,0);res=sa*sb;
priority_queue<pii,vector<pii>,greater<pii>> pq;
for(int i=1;i<=n;i++){
int u=-1;
for(auto [v,w]:edge[i]){
if(dep[v]<dep[i] && v!=par[i]) cur[i].push_back(w),u=v;
}
if(u!=-1){
int cc=i;
while(cc!=u){
cur[i].push_back(pu[cc]);
cc=par[cc];
}
cur[i]=convex_hull(cur[i]);
pq.push({(int)cur[i].size(),i});
}
}
while((int)pq.size()>=2){
pii a=pq.top();pq.pop();
pii b=pq.top();pq.pop();
cur[a.se]=minkowski(cur[a.se],cur[b.se]);
pq.push({(int)cur[a.se].size(),a.se});
}
for(pt d:cur[pq.top().se]) res=min(res,(sa-d.x)*(sb-d.y));
cout << res << '\n';
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
int test=1;//cin >> test;
while(test--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 19260kb
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: 0ms
memory: 18212kb
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: 3ms
memory: 15664kb
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: 0ms
memory: 15556kb
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: 3ms
memory: 18920kb
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: 0ms
memory: 15376kb
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: 2ms
memory: 15536kb
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: 2ms
memory: 16060kb
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: 3ms
memory: 15988kb
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: 0
Accepted
time: 0ms
memory: 18248kb
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:
196145757738
result:
ok 1 number(s): "196145757738"
Test #11:
score: 0
Accepted
time: 2ms
memory: 18460kb
input:
20 28 1 11 29270 12003 11 14 39731 27230 4 11 43657 44868 13 10 37887 17666 8 6 12758 4662 12 18 34016 15740 12 11 1123 44690 1 14 1866 31755 17 7 12441 26285 3 10 29159 11042 4 19 22612 12647 2 3 43899 27826 17 3 26727 7304 20 5 32807 49683 16 3 40800 14397 3 5 21244 13387 11 3 39919 35610 15 9 944...
output:
135255186000
result:
ok 1 number(s): "135255186000"
Test #12:
score: 0
Accepted
time: 0ms
memory: 18412kb
input:
500 627 218 441 9330 38888 394 403 39336 6683 81 319 10978 28288 157 204 27638 7127 58 38 7029 7446 168 100 23915 46064 180 151 42120 1549 18 238 15877 34786 37 259 37301 2159 463 185 4155 13849 77 355 5111 14848 62 486 19786 48858 132 408 41592 45835 245 378 46373 21496 291 20 36847 18682 435 213 3...
output:
115468900928208
result:
ok 1 number(s): "115468900928208"
Test #13:
score: 0
Accepted
time: 3ms
memory: 18880kb
input:
500 655 118 73 5102 36606 387 191 18264 17089 462 226 6016 40383 215 303 3543 6165 95 192 19518 19250 37 430 21505 26348 406 484 45283 8029 446 64 32626 30683 432 146 22720 12184 1 145 4822 43486 169 355 44960 12596 399 372 1339 28076 452 387 11774 33758 186 72 47444 20235 145 61 30207 39522 87 419 ...
output:
126690228324902
result:
ok 1 number(s): "126690228324902"
Test #14:
score: -100
Runtime Error
input:
500 499 11 127 37123 28858 439 253 39067 7779 148 142 5215 35775 441 354 15081 38415 145 463 8601 8508 400 332 23071 25635 193 124 33687 31694 154 449 45482 46872 499 469 49487 28780 24 246 48364 48917 458 397 3906 33392 130 108 13072 11058 235 406 11881 17681 20 172 35252 25687 81 24 41900 11751 49...