QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#59130 | #4246. Cactus is Money | xiaoyaowudi | WA | 4ms | 7900kb | C++17 | 2.5kb | 2022-10-28 09:25:15 | 2022-10-28 09:25:19 |
Judging History
answer
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <tuple>
typedef long long ll;
typedef std::pair<ll,ll> pr;
constexpr int N=50010,M=200010;
struct convex
{
pr st;
std::vector<pr> num;
};
convex merge(const convex &a,const convex &b)
{
pr rst(a.st.first+b.st.first,a.st.second+b.st.second);
std::vector<pr> seq;
std::merge(a.num.begin(),a.num.end(),b.num.begin(),b.num.end(),std::back_inserter(seq),[](auto a,auto b){return a.second*b.first<b.second*a.first;});
return (convex){rst,seq};
}
convex get_convex(std::vector<pr> a)
{
std::sort(a.begin(),a.end(),[](auto a,auto b){return a.first<b.first || (a.first==b.first && a.second>b.second);});
static pr stk[N];int top(0);
for(auto v:a)
{
if(!top){stk[++top]=v;continue;}
if(stk[top].first==v.first) --top;
while(top>=2 && (v.second-stk[top].second)*(stk[top].first-stk[top-1].first)<=(stk[top].second-stk[top-1].second)*(v.first-stk[top].first)) --top;
stk[++top]=v;
}
pr st(stk[1]);
std::vector<pr> df;
for(int i(2);i<=top;++i) df.emplace_back(stk[i].first-stk[i-1].first,stk[i].second-stk[i-1].second);
return (convex){st,df};
}
std::vector<std::tuple<int,int,int>> es[N];
pr stk[N+M];int dfn[N],low[N],dcnt,top,bcnt;convex cs[N];
std::priority_queue<std::pair<int,int>> pq;
void tarjan(int u)
{
dfn[u]=low[u]=++dcnt;stk[++top]={-1,u};
for(auto [v,ai,bi]:es[u])
{
if(!dfn[v])
{
tarjan(v);
if(low[v]==dfn[u])
{
pr val;
std::vector<pr> res;ll ta=0,tb=0;
do
{
val=stk[top--];
if(~val.first) res.emplace_back(val),ta+=val.first,tb+=val.second;
}
while(!(val.first==-1 && val.second==v));
if(res.size()!=1) for(auto &[va,vb]:res) va=ta-va,vb=tb-vb;
cs[++bcnt]=get_convex(res);
pq.emplace(-int(cs[bcnt].num.size()),bcnt);
}
}
else if(dfn[v]<dfn[u])
{
stk[++top]={ai,bi};
low[u]=std::min(low[u],dfn[v]);
}
}
}
int main()
{
int n,m;std::ios::sync_with_stdio(false);std::cin.tie(0);
std::cin>>n>>m;
for(int i(1),u,v,a,b;i<=m;++i) std::cin>>u>>v>>a>>b,es[u].emplace_back(v,a,b),es[v].emplace_back(u,a,b);
tarjan(1);
for(int i(1);i<bcnt;++i)
{
auto [n1,v1]=pq.top();pq.pop();
auto [n2,v2]=pq.top();pq.pop();
cs[v1]=merge(cs[v1],cs[v2]);
pq.emplace(n1+n2,v1);
}
int u=pq.top().second;
auto [ta,tb]=cs[u].st;
ll ans=ta*tb;
for(auto [va,vb]:cs[u].num)
{
ta+=va;tb+=vb;
ans=std::min(ans,ta*tb);
}
std::cout<<ans<<std::endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7652kb
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: 2ms
memory: 7572kb
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: 2ms
memory: 7516kb
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: 2ms
memory: 7900kb
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: 2ms
memory: 7572kb
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: 1ms
memory: 7688kb
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: -100
Wrong Answer
time: 4ms
memory: 7720kb
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:
23915943628
result:
wrong answer 1st numbers differ - expected: '19944198324', found: '23915943628'