QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#663149#4852. Restoranilicn090605WA 731ms36556kbC++142.0kb2024-10-21 13:43:332024-10-21 13:43:33

Judging History

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

  • [2024-10-21 13:43:33]
  • 评测
  • 测评结果:WA
  • 用时:731ms
  • 内存:36556kb
  • [2024-10-21 13:43:33]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e3+10;
int n,head[N],g[N][N],op[N],dd[N],f[N][N],dp[N][N],p[N][N],w[N][N],q[N],top,tot,a[N],b[N],d[N],cnt,v[N],dfn[N],low[N],num,siz[N];
struct node{
	int next,to;
}edge[N*N];
inline void read(int from,int to){
	edge[++tot]={head[from],to};
	head[from]=tot;
}
inline void tarjan(int x){
	low[x]=dfn[x]=++num;
	q[++top]=x,v[x]=1;
	for(int i=head[x];i;i=edge[i].next){
		int y=edge[i].to;
		if(!dfn[y]){
			tarjan(y);
			low[x]=min(low[x],low[y]);
		}
		else if(v[y])low[x]=min(low[x],dfn[y]);
	}
	if(dfn[x]==low[x]){
		cnt++;
		int y;
		do{
			y=q[top--],v[y]=0;
			dd[y]=cnt,siz[cnt]++;
			p[cnt][siz[cnt]]=y;
			w[cnt][siz[cnt]]=a[y];
		}
		while(x!=y);
	}
}
inline void dfs(int x){
	v[x]=1;
	for(int j=0;j<=n;++j)dp[x][j]=min(dp[x][j],f[x][j]);
	op[x]=siz[x];
	for(int i=head[x];i;i=edge[i].next){
		int y=edge[i].to;
		if(!v[y])dfs(y);
		op[x]=max(op[x],op[y]+siz[x]);
		for(int j=0;j<=n;++j){
			for(int k=0;k<=j;++k){
				dp[x][j]=min(dp[x][j],dp[y][k]+f[x][j-k]);
			}
		}
	}
}
signed main(){
	cin>>n;
	for(int i=1;i<=n;++i){
		cin>>a[i]>>b[i]>>d[i];
		for(int j=1;j<=d[i];j++){
			cin>>g[i][j];
			read(i,g[i][j]);
		}
	}
	for(int i=1;i<=n;++i)if(!dfn[i])tarjan(i);
	memset(f,0x3f,sizeof(f));
	memset(dp,0x3f,sizeof(dp));
	for(int i=1;i<=cnt;++i){
		sort(w[i]+1,w[i]+1+siz[i]);
		for(int j=1;j<=siz[i];++j){
			int xx=p[i][j],fl=0,ret=b[xx];
			f[i][1]=min(f[i][1],ret);
			for(int k=1;k<=siz[i];++k){
				if(w[i][k]==a[xx]&&!fl){
					fl=1;
					continue;
				}
				ret+=w[i][k];
				f[i][k+1-fl]=min(f[i][k+1-fl],ret);
			}
		}
	}
	memset(head,0,sizeof(head));
	tot=0;
	for(int i=1;i<=n;++i){
		for(int j=1;j<=d[i];++j){
			int x=g[i][j];
			if(dd[i]!=dd[x])read(dd[i],dd[x]);
		}
	}
	for(int i=1;i<=cnt;++i)if(!v[i])dfs(i);
	for(int i=1;i<=n;++i){
		int ans=1e9;
		for(int j=1;j<=cnt;++j)ans=min(ans,dp[j][i]);
		if(ans>1e8)break;
		cout<<ans<<"\n";
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 32500kb

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:

56
57
63
85
107
131
155
180
207
237
270
305
340
380
426
473
536
618
704
794
885
977
1076
1186
1297
1409
1524
1640
1759
1882
2005
2130
2257
2398
2543
2688
2838
2994
3152
3319
3490
3665
3840
4027
4216
4405
4614
4824
5036
5249
5462
5682
5903
6139
6379
6622
6867
7114
7368
7626
7893
8162
8434
8709
8985
9...

result:

ok 1000 lines

Test #2:

score: -100
Wrong Answer
time: 731ms
memory: 36556kb

input:

1000
4409 7088 4 774 678 552 582
600 7071 4 386 128 135 393
154 205 5 508 106 866 374 384
390 5420 9 881 365 543 784 801 730 413 177 200
2470 3366 3 314 905 772
5563 9537 4 372 357 628 691
5281 6770 2 595 761
3436 9375 3 641 338 668
2113 2528 1 742
3114 8123 6 479 145 736 802 354 764
304 2375 2 529 ...

output:

175
600
1347
2136
2653
3400
4281
5195
6060
6807
7688
8602
9531
10488
11545
12474
13431
14407
15404
16473
17912
19487
20539
21496
22456
23413
24482
25921
27449
28986
30514
31955
32912
33981
35420
36580
37580
38564
39633
40838
42277
43725
45173
46701
48235
49713
50929
52261
53595
55034
56482
57852
593...

result:

wrong answer 2nd lines differ - expected: '473', found: '600'