QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#130110#4246. Cactus is MoneySolitaryDream#WA 2ms11656kbC++172.2kb2023-07-23 16:40:092023-07-23 16:40:09

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-23 16:40:09]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:11656kb
  • [2023-07-23 16:40:09]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

#define int long long

#define fs first
#define sd second
using pii=pair<int,int>;
using tii=tuple<int,int,int>;

const int N=2e5+1e3+7;

int n,m;

int dfn[N],dc,use[N];

vector<tii>g[N];

pii fe[N];

vector<int>st;

vector<vector<pii> >cir;

void dfs(int x,int f)
{
	st.push_back(x);
	dfn[x]=++dc;
	for(auto [v,a,b]:g[x])
	{
		if(v==f)
			continue;
		if(!dfn[v])
			fe[v]={a,b},dfs(v,x);
		else if(dfn[v]<dfn[x])
		{
			cir.push_back({{a,b}});
			for(int i=st.size()-1;st[i]!=v;i--)
				cir.back().push_back(fe[st[i]]),use[st[i]]=1;
		}
	}
	if(!use[x])
		cir.push_back({fe[x],fe[x]});
	st.pop_back();
}

pii operator +(const pii &a,const pii &b)
{
	return {a.fs+b.fs,a.sd+b.sd};
}

pii operator -(const pii &a,const pii &b)
{
	return {a.fs-b.fs,a.sd-b.sd};
}

int operator *(const pii &a,const pii &b)
{
	return a.fs*b.sd-a.sd*b.fs;
}

vector<pii>merge(vector<pii> a,vector<pii> b)
{
	pii S=a[0]+b[0];
	vector<pii>ret;
	ret.push_back(S);
	int i=1,j=1;
	while(i<a.size()&&j<b.size())
	{
		if((a[i]-a[i-1])*(b[j]-b[j-1])>=0)
			ret.push_back({a[i]-a[i-1]}),i++;
		else
			ret.push_back({b[j]-b[j-1]}),j++;
	}
	while(i<a.size())
		ret.push_back(a[i]-a[i-1]),i++;
	while(j<b.size())
		ret.push_back(b[j]-b[j-1]),j++;
	for(int i=1;i<ret.size();i++)
		ret[i]=ret[i]+ret[i-1];
	return ret;
}

vector<pii>solve(int l,int r)
{
	if(l==r)
		return cir[l];
	int mid=(l+r)>>1;
	return merge(solve(l,mid),solve(mid+1,r));
}

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		int u,v,a,b;
		cin>>u>>v>>a>>b;
		g[u].push_back({v,a,b});
		g[v].push_back({u,a,b});
	}
	dfs(1,0);
	for(auto &c:cir)
	{
		int sa=0,sb=0;
		for(auto [a,b]:c)
			sa+=a,sb+=b;
		for(auto &[a,b]:c)
			a=sa-a,b=sb-b;
		sort(c.begin(),c.end());
		vector<pii>g;
		for(auto p:c)
		{
			while(g.size()>1&&(p-g[g.size()-2])*(g[g.size()-1]-g[g.size()-2])>=0)
				g.pop_back();
			g.push_back(p);
		}
		c.swap(g);
	}
	auto w=solve(0,cir.size()-1);
	int ans=LONG_LONG_MAX;
	for(auto [a,b]:w)
		ans=min(ans,a*b);
	cout<<ans<<endl;
}
/*
6 7
1 2 1 2
2 3 2 1
3 4 2 3
4 2 3 2 
2 5 1 4
6 5 2 2
6 2 3 1
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 9616kb

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: 9688kb

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: 9744kb

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: 9620kb

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: 1ms
memory: 9624kb

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: 11656kb

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: 0ms
memory: 9688kb

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: -100
Wrong Answer
time: 2ms
memory: 9636kb

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:

40790962056

result:

wrong answer 1st numbers differ - expected: '39767313936', found: '40790962056'