记录详情

Runtime Error

/in/foo.cc: In function 'void Init()':
/in/foo.cc:48:11: warning: 'w' may be used uninitialized in this function [-Wmaybe-uninitialized]
   int a,b,w;
           ^
# 状态 耗时 内存占用
#1 Runtime Error 37ms 31.426 MiB
#2 Wrong Answer 27ms 31.461 MiB
#3 Runtime Error 27ms 31.426 MiB
#4 Runtime Error 30ms 31.453 MiB
#5 Wrong Answer 38ms 31.5 MiB
#6 Runtime Error 29ms 31.453 MiB
#7 Runtime Error 35ms 31.449 MiB
#8 Runtime Error 37ms 31.426 MiB
#9 Wrong Answer 37ms 31.504 MiB
#10 Runtime Error 29ms 31.375 MiB
#11 Runtime Error 33ms 31.43 MiB
#12 Wrong Answer 36ms 31.5 MiB
#13 Runtime Error 26ms 31.391 MiB
#14 Runtime Error 38ms 31.406 MiB
#15 Runtime Error 26ms 31.477 MiB
#16 Wrong Answer 27ms 31.504 MiB
#17 Runtime Error 29ms 31.383 MiB
#18 Runtime Error 38ms 31.438 MiB
#19 Runtime Error 26ms 31.383 MiB
#20 Runtime Error 28ms 31.477 MiB
#21 Runtime Error 29ms 31.496 MiB
#22 Runtime Error 26ms 31.445 MiB
#23 Runtime Error 29ms 31.461 MiB
#24 Runtime Error 28ms 31.438 MiB
#25 Runtime Error 28ms 31.406 MiB

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn=2010,maxv=310;
int dis[maxv][maxv],c[maxn],d[maxn],wc[maxn],wd[maxn];
int n,m,v,e;
double k1[maxn],f[maxn][maxn];
double tot;

inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c>'9'||c<'0'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=((x<<1)+(x<<3))+c-'0';
		c=getchar();
	}
	return x*f;
}

inline void floyd(){
	for(int k=1;k<=e;k++)
		for(int i=1;i<=e;i++)
			for(int j=1;j<=e;j++)
					dis[i][j]=min(dis[i][k]+dis[k][j],dis[i][j]);
}

inline void dp(){
	for(int k=1;k<=m;k++)
		for(int i=1;i<=n;i++){
			for(int j=1;j<i;j++){
				f[k][i]=min(f[k-1][j]+k1[i]*dis[c[i-1]][d[i]]+(1-k1[i])*dis[c[i-1]][c[i]],f[k][i]);
			}
		}
}

inline void Init(){
	n=read(),m=read();
	v=read(),e=read();
	memset(dis,0x3f,sizeof(dis));
	memset(f,0x3f,sizeof(f));
	for(int i=1;i<=n;i++)c[i]=read();
	for(int i=1;i<=n;i++)d[i]=read();
	for(int i=1;i<=n;i++)scanf("%lf",&k1[i]),dis[i][i]=0;
	for(int i=1;i<=e;i++){
		int a,b,w;
		a=read(),b=read();
		if(a==b)continue;
		dis[a][b]=min(dis[a][b],w);
		dis[b][a]=dis[a][b];
	}
}

inline void Work(){
	if(m==0){
		floyd();
		for(int i=1;i<n;i++)tot+=dis[c[i]][c[i+1]];
	}
	else{
		floyd();
		for(int i=1;i<n;i++)tot+=dis[c[i]][c[i+1]];
		for(int i=1;i<=n;i++){
			wc[i]=wc[i-1]+dis[c[i-1]][c[i]];
			wd[i]=wd[i-1]+dis[d[i-1]][d[i]];
			f[0][i]=wc[i];
		}
		dp();
		for(int i=0;i<=n;i++){
			tot=min(tot,f[i][n]);
		}
	}
	
}

inline void Print(){
	printf("%.2lf",tot);
}

int main(){
	Init();
	Work();
	Print();
	return 0;
}

信息

递交者
类型
递交
题目
P1005 换教室
比赛
随机真题赛第二轮(xhy&lfy讲题)
题目数据
下载
语言
C++
递交时间
2019-11-12 08:59:07
评测时间
2019-11-12 08:59:07
评测机
分数
0
总耗时
786ms
峰值内存
31.504 MiB