QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#507310#4852. Restorani_scz_TL 0ms0kbC++143.5kb2024-08-06 15:51:492024-08-06 15:51:49

Judging History

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

  • [2024-08-06 15:51:49]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-08-06 15:51:49]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<bitset>
#define boo(i) bitset<i>
#define ri register int
#define rll register long long
#define ll long long
#define mem(x) memset(x,0,sizeof(x))
#define max_(i,j) (i<j?j:i)
#define min_(i,j) (i<j?i:j)
#define abs_(x) (x>0?x:(-x))
using namespace std;
int n,ku;
const int MAXN=1125;
boo(MAXN) hv;
int dfn[MAXN],low[MAXN],bel[MAXN],dfl;int sta[MAXN],l;
int dp[1505][1511],minn[1524];
int x[MAXN],y[MAXN],dt[MAXN];
bitset<MAXN>ed[MAXN];//ed original
bitset<MAXN>ed2[MAXN],ed3[MAXN];//ed2 old,ed3 new
vector<int>np[MAXN];
struct sd{
	void tarj(int x){
		dfn[x]=low[x]=++dfl;
		sta[++l]=x;
		hv[x]=true;
		for(int i=1;i<=n;i++){
			if(ed2[x][i]){
				if(!dfn[i]){
					tarj(i);
					low[x]=min(low[x],low[i]);
				}else{
					if(hv[i]){
						low[x]=min(low[x],dfn[i]);
					}
				}
			}
		}
		if(low[x]==dfn[x]){
			ku++;int t;
			do{
				t=sta[l];
				hv[t]=false;
				bel[t]=ku;
				l--;
			}while(t!=x);
		}
	}
	void did(){
		for(int i=1;i<=n;i++){
			if(!dfn[i]){
				tarj(i);
			}
		}
		for(int i=1;i<=n;i++){
			//printf("%d ",bel[i]);
			np[bel[i]].push_back(i);
		}
	}
}scz;
struct poi{
	int x,y;
};
bool operator<(const poi& a,const poi& b){
	return a.y<b.y;
}
struct final{
	
	poi b[MAXN];
	void mian(){
		bitset<MAXN>t;
		for(int i=2;i<=n;i++){
			for(int j=1;j<=n;j++){
				b[j]=(poi){j,dp[i-1][j]};
			}
			sort(b+1,b+1+n);
			hv.set();
			for(int j=1;j<=n;j++){
				t=ed3[b[j].x]&hv;
				for(int ch=1;ch<=n;ch++){
					if(!t[ch])continue;
					dp[i][ch]=min(dp[i][ch],b[j].y+dt[ch]);
					hv[ch]=false;
				} 
			}
		}
	}
}wjr;
void dfs(int x){
	//printf("%d\n",x);
	bitset<MAXN>t=ed[x]&hv;
	for(int i=1;i<=n;i++){
		if(t[i]){hv[i]=false;
		}
	}
	for(int i=1;i<=n;i++){
	//	printf("go %d %d",x,i);
		if(t[i])dfs(i);
	}
}
bool cmp(int a,int b){
	return x[a]<x[b];
}
int main(){
	scanf("%d",&n);
	for(int i=1,tt;i<=n;i++){
		scanf("%d%d%d",&x[i],&y[i],&tt);
		for(int j=1,ttt;j<=tt;j++){
			scanf("%d",&ttt);
			ed[i][ttt]=true;
		}
	}
	for(int i=1;i<=n;i++){
		hv.set();
		hv[i]=false;
		dfs(i);
		for(int j=1;j<=n;j++){
			if(i==j)continue;
			ed2[i][j]=!hv[j];
			int t=ed2[i][j];//printf("%d %d %d\n",i,j,t);
		}
	}
	int hav,ans;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			dp[i][j]=1e9+7;
		}
	}
	hv.reset();scz.did();
	for(int i=1;i<=n;i++){//add new edge
		for(int j=1;j<=n;j++){
			if(ed2[i][j]&&bel[i]!=bel[j]&&np[bel[j]][0]==j){
				ed3[i][j]=true;
				//printf("%d %d\n",i,j);
			}
		}
	}
	for(int i=1;i<=ku;i++){//solve np val
		sort(np[i].begin(),np[i].end(),cmp);
		for(int j=1;j<=n;j++){
			minn[j]=1e9+7;
		} 
		for(int j=0;j<np[i].size();j++){
			ans=y[np[i][j]];
			hav=1;
			minn[1]=min(minn[1],y[np[i][j]]);
			for(int k=0;k<np[i].size();k++){
				if(j!=k){
					hav++;
					ans+=x[np[i][k]];
					minn[hav]=min(minn[hav],ans);
					//printf("%d %d\n",hav,minn[hav]);
				}
			}
		}
		for(int j=1;j<=np[i].size();j++){
			dt[np[i][j-1]]=minn[j]-minn[j-1];
			if(j>1)ed3[np[i][j-2]][np[i][j-1]]=true;
		}
	}
	for(int i=1;i<=n;i++){
		if(np[bel[i]][0]==i){
			dp[1][i]=dt[i];
		}
	//	printf("%d ",dt[i]);
	}
	for(int i=1;i<=n;i++){
		minn[i]=1e9+7;
	}
	wjr.mian();
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			minn[i]=min(minn[i],dp[i][j]);
		}
	}
	for(int i=1;i<=n;i++){
		if(minn[i]<1e9){
			printf("%d\n",minn[i]);
		}
	}
}
//码量大得恶心 

详细

Test #1:

score: 0
Time Limit Exceeded

input:

1000
2856 4225 9 773 772 383 359 750 327 752 465 612
5478 5990 6 452 449 938 60 930 374
2088 2765 3 703 416 845
8905 1853 3 891 518 651
8249 9640 5 844 126 767 602 549
8956 9158 5 321 126 633 228 147
115 559 10 996 649 568 530 473 268 457 746 815 758
7208 9975 8 164 365 391 481 821 587 964 118
2260 ...

output:


result: