QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#38997#1274. Walking PlanwyhaoWA 1453ms3416kbC++1.7kb2022-07-08 11:17:352022-07-08 11:17:37

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-07-08 11:17:37]
  • 评测
  • 测评结果:WA
  • 用时:1453ms
  • 内存:3416kb
  • [2022-07-08 11:17:35]
  • 提交

answer

#include<cstdio>
#include<cstring>
using namespace std;
const int N=55,INF=0x3f3f3f3f;
int T,n,m,q,s,t,K;
int a[N][N];
int min1(int x,int y){
	return x<y?x:y;
}
int f[N][N][155];
int G[N][N][10];
int C[N],D[N];
int main(){
	scanf("%d",&T);
	while(T--){
		scanf("%d%d",&n,&m);
		memset(a,0x3f,sizeof a);
		for(int i=1,x,y,w;i<=m;i++){
			scanf("%d%d%d",&x,&y,&w);
			a[x][y]=min1(a[x][y],w);
		}
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++) f[i][j][1]=a[i][j],G[i][j][0]=f[i][j][0]=INF;
			f[i][i][0]=G[i][i][0]=0;
		}
		for(int ii=2;ii<=150;ii++){
			for(int i=1;i<=n;i++){
				for(int j=1;j<=n;j++){
					int mi=INF;
					for(int k=1;k<=n;k++){
						mi=min1(mi,f[i][k][ii-1]+a[k][j]);
					}
					f[i][j][ii]=mi;
				}
			}
		}
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++) G[i][j][1]=f[i][j][100];
		}
		for(int ii=1;ii<=7;ii++){
			for(int i=1;i<=n;i++){
				for(int j=1;j<=n;j++){
					int mi=INF;
					for(int k=1;k<=n;k++){
						mi=min1(mi,G[i][k][ii-1]+G[k][j][ii-1]);
					}
					G[i][j][ii]=mi;
				}
			}
		}
		for(int ii=149;~ii;ii--){
			for(int i=1;i<=n;i++){
				for(int j=1;j<=n;j++){
					f[i][j][ii]=min1(f[i][j][ii],f[i][j][ii+1]);
				}
			}
		}
		scanf("%d",&q);
		while(q--){
			scanf("%d%d%d",&s,&t,&K);
			for(int i=1;i<=n;i++) C[i]=INF;
			C[s]=0;
			int a=K/100,b=K%100;
			for(int i=1;i<=n;i++){
				int mi=INF;
				for(int j=1;j<=n;j++){
					mi=min1(mi,C[j]+G[j][i][a]);
				}
				D[i]=mi;
			}
			for(int i=1;i<=n;i++){
				int mi=INF;
				for(int j=1;j<=n;j++){
					mi=min1(mi,D[j]+f[j][i][b]);
				}
				C[i]=mi;
			}
			if(C[t]==INF) puts("-1");
			else printf("%d\n",C[t]);
		}
	}
	return 0;
}

详细

Test #1:

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

input:

2
3 3
1 2 1
2 3 10
3 1 100
3
1 1 1
1 2 1
1 3 1
2 1
1 2 1
1
2 1 1

output:

111
1
11
-1

result:

ok 4 lines

Test #2:

score: -100
Wrong Answer
time: 1453ms
memory: 3416kb

input:

10
5 10
4 2 55
2 1 26
3 4 83
5 2 16
4 5 54
3 4 38
2 1 68
2 5 1
4 5 85
4 2 60
20
2 1 13
1 4 17
3 2 20
2 4 16
4 2 17
4 2 2
3 1 2
1 5 10
2 1 8
4 5 15
4 2 16
3 1 18
5 2 7
4 2 9
4 3 16
1 4 18
3 2 5
1 5 9
5 1 19
1 2 16
20 50
4 16 25
3 16 990
9 18 863
19 12 236
4 10 360
13 4 585
14 17 164
8 18 198
2 17 804...

output:

128
-1
246
-1
191
70
119
-1
94
173
189
253
67
123
-1
-1
125
-1
195
-1
-1
23449
3476
18735
17412
23124
29499
26452
9757
21128
9524
-1
4486
8797
8041
33717
32669
5108
32534
13020
22800
4411
3529
2580
4191
15863
5342
22005
-1
14496
16535
13644
-1
33956
28717
24721
13816
26289
8840
28137
9991
14430
-1
3...

result:

wrong answer 44th lines differ - expected: '37460', found: '2580'