QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#734852#7671. Metal Processing PlantffffycTL 1ms5780kbC++143.2kb2024-11-11 15:29:492024-11-11 15:29:50

Judging History

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

  • [2024-11-11 15:29:50]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:5780kb
  • [2024-11-11 15:29:49]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
namespace IO{//by cyffff
	int len=0;
	char ibuf[(1<<21)+1],*iS,*iT,out[(1<<25)+1];
	#if ONLINE_JUDGE
	#define gh() (iS==iT?iT=(iS=ibuf)+fread(ibuf,1,(1<<21)+1,stdin),(iS==iT?EOF:*iS++):*iS++)
 	#else
	#define gh() getchar()
	#endif
	#define reg register
	inline int read(){
		reg char ch=gh();
		reg int x=0;
		reg char t=0;
		while(ch<'0'||ch>'9')   t|=ch=='-',ch=gh();
		while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=gh();
		return t?-x:x;
	}
	inline void putc(char ch){
		out[len++]=ch;
	}
	template<class T>
	inline void write(T x){
		if(x<0)putc('-'),x=-x;
		if(x>9)write(x/10);
		out[len++]=x%10+48;
	}
	inline void flush(){
		fwrite(out,1,len,stdout);
		len=0;
	}
	inline char getc(){
		char ch=gh();
		while(ch<'A'||ch>'Z') ch=gh();
		return ch;
	}
}
using IO::read;
using IO::write;
using IO::flush;
using IO::getc;
using IO::putc;
#define pii pair<int,int>
#define mpr make_pair
#define fir first
#define sec second
const int N=400+10,INF=1e9+10;
int n,d[N][N];
struct node{
	int u,v,w;
	inline friend bool operator<(const node &a,const node &b){
		return a.w>b.w;
	}
};
vector<node>vec;
vector<int>b[N];
bitset<N>a[N],vis[2][N];
inline void dfs(int x,int i,int d){
	bitset<N>tp=a[x]&(~vis[!d][i]);
	for(int j=tp._Find_first();j!=tp.size();j=tp._Find_next(j))
		vis[!d][i][j]=vis[!d][j][i]=1;
	for(int j=tp._Find_first();j!=tp.size();j=tp._Find_next(j))
		dfs(j,i,!d);
}
inline void add(int u,int v){
	bitset<N>tp=vis[0][u]&~vis[1][v];
	for(int i=tp._Find_first();i!=tp.size();i=tp._Find_next(i))
		vis[1][i][v]=vis[1][v][i]=1,dfs(v,i,1);
	tp=vis[1][u]&~vis[0][v];
	for(int i=tp._Find_first();i!=tp.size();i=tp._Find_next(i))
		vis[0][i][v]=vis[0][v][i]=1,dfs(v,i,0);
	a[u][v]=a[v][u]=1;
}
int dfn[N],low[N],stk[N],top,bel[N],tim,inc[N],bc;
inline void Tarjan(int x){
	dfn[x]=low[x]=++tim,stk[++top]=x,inc[x]=1;
	for(auto t:b[x]){
		if(!dfn[t]) Tarjan(t),low[x]=min(low[x],low[t]);
		else if(inc[t]) low[x]=min(low[x],dfn[t]);
	}
	if(dfn[x]==low[x]){
		bc++;
		while(1){
			int p=stk[top--];
			inc[p]=0,bel[p]=bc;
			if(p==x) break;
		}
	}
}
inline void clear(){
	for(int i=1;i<=n*2;i++)
		b[i].clear();
	for(int i=1;i<=n*2;i++)
		dfn[i]=bel[i]=inc[i]=0;
	tim=bc=0;
}
inline bool check(int x){
	for(int i=1;i<=n;i++)
		for(int j=a[i]._Find_first();j!=a[i].size();j=a[i]._Find_next(j))
			b[i].push_back(j+n);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			if(d[i][j]>x)
				b[i+n].push_back(j);
	for(int i=1;i<=n*2;i++)
		if(!dfn[i])
			Tarjan(i);
	bool fl=1;
	for(int i=1;i<=n;i++)
		if(bel[i]==bel[i+n])
			fl=0;
	clear();
	return fl;
}
int main(){
	n=read();
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			vec.push_back({i,j,d[i][j]=d[j][i]=read()});
	if(n<=2) return puts("0"),0;
	sort(vec.begin(),vec.end());
	int ans=INF*2;
	for(auto e:vec){
		int u=e.u,v=e.v;
		if(!vis[1][u][v]){
			int L=0,R=vec.size()-1,res=-1;
			if(check(0)) res=0;
			else{
				while(L<=R){
					int mid=L+R>>1;
					if(check(vec[mid].w)) L=mid+1,res=vec[mid].w;
					else R=mid-1;
				}
			}
			if(res!=-1) ans=min(ans,e.w+res);
		}
		if(vis[0][u][v]) break;
		add(u,v);
	}
	write(ans);
	flush();
}

详细

Test #1:

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

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

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

input:

1

output:

0

result:

ok single line: '0'

Test #4:

score: 0
Accepted
time: 1ms
memory: 5780kb

input:

2
1

output:

0

result:

ok single line: '0'

Test #5:

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

input:

2
1000000000

output:

0

result:

ok single line: '0'

Test #6:

score: 0
Accepted
time: 1ms
memory: 5724kb

input:

3
1000000000 1000000000
1000000000

output:

1000000000

result:

ok single line: '1000000000'

Test #7:

score: 0
Accepted
time: 1ms
memory: 5648kb

input:

4
1000000000 1000000000 1000000000
1000000000 1000000000
1000000000

output:

1000000000

result:

ok single line: '1000000000'

Test #8:

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

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: