QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#198672 | #4246. Cactus is Money | bachbeo2007 | WA | 2ms | 10912kb | C++23 | 4.6kb | 2023-10-03 16:19:22 | 2023-10-03 16:19:22 |
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> ans,cur;
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);
for(int i=1;i<=n;i++){
int u=-1;cur.clear();
for(auto [v,w]:edge[i]){
if(dep[v]<dep[i]) cur.push_back(w),u=v;
}
if(u!=-1){
int cc=i;
while(cc!=u){
cur.push_back(pu[cc]);
cc=par[cc];
}
cur=convex_hull(cur);
if(ans.empty()) ans=cur;
else ans=minkowski(ans,cur);
}
}
for(pt d:ans) 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: 0ms
memory: 10620kb
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: -100
Wrong Answer
time: 2ms
memory: 10912kb
input:
5 5 1 2 666 10 2 3 555 1000 3 1 444 345 1 4 222 234 2 5 333 123
output:
153180
result:
wrong answer 1st numbers differ - expected: '1185480', found: '153180'