QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#618289#7671. Metal Processing Plantucup-team1004TL 0ms3952kbC++172.0kb2024-10-06 20:28:302024-10-06 20:28:31

Judging History

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

  • [2024-10-06 20:28:31]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3952kb
  • [2024-10-06 20:28:30]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include"debug.h"
#else
#define debug(...) void()
#endif
#define all(x) (x).begin(),(x).end()
template<class T>
auto ary(T *a,int l,int r){
	return vector<T>{a+l,a+1+r};
}
using ll=long long;
using ull=unsigned long long;
const int N=2e2+10,M=N*2;
int n,a[N][N];
vector<int>to[M];
void add(int u,int v){
	to[u].push_back(v);
}
int dft,sct,dfn[M],low[M],scc[M];
void tarjan(int u){
	static int top,stk[M];
	dfn[u]=low[u]=++dft,stk[++top]=u;
	for(int v:to[u]){
		if(!dfn[v])tarjan(v),low[u]=min(low[u],low[v]);
		else if(!scc[v])low[u]=min(low[u],dfn[v]);
	}
	if(low[u]==dfn[u]){
		sct++;
		do scc[stk[top]]=sct;while(stk[top--]^u);
	}
}
bool chk(){
	for(int i=1;i<=n+n;i++)if(!dfn[i])tarjan(i);
	bool flag=1;
	for(int i=1;i<=n;i++)flag&=scc[i]!=scc[i+n];
	for(int i=1;i<=n+n;i++)to[i].clear(),dfn[i]=scc[i]=0;
	return dft=sct=0,flag;
}
int fa[M];
int find(int x){
	return fa[x]==x?x:fa[x]=find(fa[x]);
}
int main(){
	scanf("%d",&n);
	if(n==1)puts("0"),exit(0);
	vector<tuple<int,int,int>>E;
	for(int i=1,x;i<=n;i++){
		E.push_back({0,i,i});
		for(int j=i+1;j<=n;j++){
			scanf("%d",&x);
			a[i][j]=a[j][i]=x;
			E.push_back({x,i,j});
		}
	}
	sort(all(E));
	iota(fa,fa+1+n+n,0);
	bool flag=1;
	int ans=INT_MAX;
	// debug(E);
	for(int i=E.size()-1;i>=0;i--){
		auto [w,u,v]=E[i];
		if(1){
			int l=-1,r=i,mid;
			for(;l+1<r;){
				mid=(l+r)>>1;
				for(int x=E.size()-1;x>i;x--){
					auto [w,u,v]=E[x];
					add(u,v+n),add(v+n,u);
					add(u+n,v),add(v,u+n);
				}
				for(int x=i;x>mid;x--){
					auto [w,u,v]=E[x];
					add(u+n,v),add(v+n,u);
				}
				if(chk())r=mid;
				else l=mid;
			}
			// debug(w,get<0>(E[r]),i,r);
			ans=min(ans,get<0>(E[r])+w);
		}
		if(find(u)==find(v))break;
		if(find(u)==find(v+n))flag=0;
		else flag=1,fa[find(u)]=find(v+n),fa[find(u+n)]=find(v);
	}
	cout<<ans<<endl;
	return 0;
}
#ifdef DEBUG
#include"debug.hpp"
#endif

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3700kb

input:

5
4 5 0 2
1 3 7
2 0
4

output:

4

result:

ok single line: '4'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3952kb

input:

7
1 10 5 5 5 5
5 10 5 5 5
100 100 5 5
10 5 5
98 99
3

output:

15

result:

ok single line: '15'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3920kb

input:

1

output:

0

result:

ok single line: '0'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3736kb

input:

2
1

output:

0

result:

ok single line: '0'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3692kb

input:

2
1000000000

output:

0

result:

ok single line: '0'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3672kb

input:

3
1000000000 1000000000
1000000000

output:

1000000000

result:

ok single line: '1000000000'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3672kb

input:

4
1000000000 1000000000 1000000000
1000000000 1000000000
1000000000

output:

1000000000

result:

ok single line: '1000000000'

Test #8:

score: 0
Accepted
time: 0ms
memory: 3696kb

input:

3
78 97
24

output:

24

result:

ok single line: '24'

Test #9:

score: -100
Time Limit Exceeded

input:

200
202018752 202018795 202018793 100018905 202018758 202018741 202018727 202018766 202018728 100018879 202018781 100018860 202018785 100018841 100018910 100018836 100018883 100018847 202018734 202018775 100018830 100018901 202018773 202018754 202018737 100018843 202018788 202018778 202018777 202018...

output:


result: