QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#198275 | #4246. Cactus is Money | hotboy2703 | WA | 1ms | 6664kb | C++14 | 4.4kb | 2023-10-03 11:48:13 | 2023-10-03 11:48:13 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
struct pt{
ll x,y;
pt operator + (pt p) const{
return {x+p.x,y+p.y};
}
pt operator - (pt p) const{
return {x-p.x,y-p.y};
}
ll operator * (pt p)const{
return x * p.y - y * p.x;
}
};
ll sq(pt a,pt b){
return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}
void reorder_polygon(vector <pt> &p){
ll pos = 0;
for (ll i = 0;i < p.size();i ++){
if (p[i].y < p[pos].y || (p[i].y == p[pos].y && p[i].x < p[pos].x)){
pos = i;
}
}
if (pos != 0)rotate(p.begin(),p.end(),p.begin() + pos);
}
ll orientation(pt a, pt b, pt c){
ll ori = (b-a)*(c-b);
if (ori == 0)return 0;
if (ori > 0)return 1;
if (ori < 0)return -1;
}
vector <pt> sum(vector <pt> &P,vector <pt> &Q){
//no mulipleple point counter clockwise
/*for (auto x:P){
cout<<x.x<<' '<<x.y<<endl;
}
cout<<endl;
for (auto x:Q){
cout<<x.x<<' '<<x.y<<endl;
}
cout<<endl;*/
reorder_polygon(P);
reorder_polygon(Q);
/*for (auto x:P){
cout<<x.x<<' '<<x.y<<endl;
}
cout<<endl;
for (auto x:Q){
cout<<x.x<<' '<<x.y<<endl;
}*/
P.push_back(P[0]);
P.push_back(P[1]);
Q.push_back(Q[0]);
Q.push_back(Q[1]);
vector <pt> result;
ll i,j;
i = j = 0;
while (i < P.size() - 2 || j < Q.size() - 2){
result.push_back(P[i] + Q[j]);
auto cross = (P[i+1] - P[i]) * (Q[j+1] - Q[j]);
if (cross >= 0 && i < P.size() - 2){
++i;
}
if (cross <= 0 && j < Q.size() - 2){
++j;
}
}
return result;
}
void convex_hull(vector <pt> &P){
pt p0 = *min_element(P.begin(),P.end(),[=](pt a, pt b){return make_pair(a.y,a.x) < make_pair(b.y,b.x);});
sort(P.begin(),P.end(),[&p0](const pt &a,const pt &b){
auto o = orientation(p0,a,b);
if (o == 0){
return sq(p0,a) < sq(p0,b);
}
return (o == -1);
});
vector <pt> st;
for (ll i = 0;i < P.size();i ++){
while (st.size() > 1 && orientation(st[st.size() - 2],st[st.size() - 1],P[i]) == 1){
st.pop_back();
}
st.push_back(P[i]);
}
P = st;
}
const ll MAXN = 5e4;
ll n,m;
vector <ll> g[MAXN + 100];
ll pa[MAXN + 100];
bool in[MAXN + 100];
struct edge{
ll u,v,a,b;
};
ll depth[MAXN + 100];
edge all[MAXN * 5 + 100];
ll nxt(ll u, edge x){
return (x.u == u?x.v:x.u);
}
vector <pt> minkowski;
void dfs(ll u){
//cout<<u<<'\n';
for (auto id:g[u]){
auto v = nxt(u,all[id]);
if (!in[v]){
pa[v] = id;
in[v] = 1;
depth[v] = depth[u] + 1;
//cout<<id<<' '<<u<<' '<<v<<'\n';
dfs(v);
}
if (in[v]){
if (depth[v] > depth[u] + 1){
ll cur = v;
vector <pt> tmp;
tmp.push_back({all[id].a,all[id].b});
while (cur != u){
tmp.push_back({all[pa[cur]].a,all[pa[cur]].b});
cur = nxt(cur,all[pa[cur]]);
}
//cout<<pa[1]<<' '<<pa[2]<<' '<<pa[3]<<'\n';
//cout<<u<<' '<<v<<'\n';
convex_hull(tmp);
/*for (auto x:tmp){
cout<<x.x<<' '<<x.y<<'\n';
}
cout<<'\n';*/
if (minkowski.empty())minkowski = tmp;
else minkowski = sum(minkowski,tmp);
}
}
}
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
cin>>n>>m;
ll sum_a,sum_b;
sum_a = sum_b = 0;
for (ll i = 1;i <= m;i ++){
cin>>all[i].u>>all[i].v>>all[i].a>>all[i].b;
g[all[i].u].push_back(i);
g[all[i].v].push_back(i);
sum_a += all[i].a;
sum_b += all[i].b;
}
in[1] = 1;
dfs(1);
//return 0;
ll ans = sum_a * sum_b;
/*for (ll i = 1;i <= m;i ++){
cout<<(sum_a - all[i].a) * (sum_b - all[i].b)<<'\n';
}
for (auto x:minkowski){
cout<<x.x<<' '<<x.y<<' ';
}
cout<<'\n';*/
for (auto x:minkowski){
ans = min(ans,(sum_a - x.x) * (sum_b - x.y));
}
cout<<ans<<'\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 6300kb
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: 6664kb
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: 0ms
memory: 5556kb
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:
6817226168
result:
wrong answer 1st numbers differ - expected: '6732185824', found: '6817226168'