답안 #207053

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
207053 2020-03-06T08:57:46 Z Pentagon 주유소 (KOI16_gas) C++14
100 / 100
909 ms 26232 KB
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<queue> 
using namespace std;
//Real Problem
int n,m,prc[2600],a,b,w;
long long DT[2600];
vector<int> arr;
bool cmp(int a,int b){
	if(prc[a]==prc[b])
		return a<b;
	return prc[a]<prc[b];
}
//for Dijkstra
int dis[2600][2600],INF=1e9;
struct node{
	int num,d;
	bool operator <(const node& tmp) const{
		return d>tmp.d;
	}
};
vector<vector<node> > v;
priority_queue<node> pq;
void Dijkstra(int s,int D[]){
	fill(D+1,D+n+1,INF);
	D[s]=0; pq.push(node{s,0});
	while(!pq.empty()){
		auto cur=pq.top(); pq.pop();
		if(cur.d>D[cur.num]) continue;
		for(auto&next : v[cur.num]){
			if(cur.d+next.d>=D[next.num]) continue;
			D[next.num]=D[cur.num]+next.d;
			pq.push(node{next.num,D[next.num]});
		}
	}
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) arr.push_back(i),scanf("%d",prc+i);
	v.resize(n+1);
	while(m--){
		scanf("%d%d%d",&a,&b,&w);
		v[a].push_back(node{b,w});
		v[b].push_back(node{a,w});
	}
	for(int i=1;i<=n;i++) Dijkstra(i,dis[i]);
	sort(arr.begin(),arr.end(),cmp);
	for(int i=0;i<n;i++){
		int k=arr[i];
		DT[k]=1LL*dis[k][n]*prc[k];
		for(int j=0;j<i;j++){
			int k2=arr[j];
			DT[k]=min(DT[k],1LL*dis[k][k2]*prc[k]+DT[k2]);
		}
		if(arr[i]==1) break;
	}
	printf("%lld",DT[1]);
}

Compilation message

gas.cpp: In function 'int main()':
gas.cpp:39:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&m);
  ~~~~~^~~~~~~~~~~~~~
gas.cpp:40:40: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1;i<=n;i++) arr.push_back(i),scanf("%d",prc+i);
                        ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
gas.cpp:43:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d",&a,&b,&w);
   ~~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 248 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 380 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 4 ms 376 KB Output is correct
11 Correct 5 ms 380 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 182 ms 25976 KB Output is correct
2 Correct 188 ms 25976 KB Output is correct
3 Correct 191 ms 26104 KB Output is correct
4 Correct 188 ms 25976 KB Output is correct
5 Correct 187 ms 25976 KB Output is correct
6 Correct 181 ms 25976 KB Output is correct
7 Correct 183 ms 25976 KB Output is correct
8 Correct 168 ms 25976 KB Output is correct
9 Correct 163 ms 25976 KB Output is correct
10 Correct 161 ms 25976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 183 ms 25984 KB Output is correct
2 Correct 708 ms 26104 KB Output is correct
3 Correct 719 ms 26104 KB Output is correct
4 Correct 705 ms 26232 KB Output is correct
5 Correct 698 ms 26232 KB Output is correct
6 Correct 898 ms 26216 KB Output is correct
7 Correct 899 ms 26168 KB Output is correct
8 Correct 909 ms 26104 KB Output is correct
9 Correct 776 ms 26052 KB Output is correct
10 Correct 776 ms 26104 KB Output is correct
11 Correct 774 ms 25976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 248 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 380 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 4 ms 376 KB Output is correct
11 Correct 5 ms 380 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 14 ms 3320 KB Output is correct
15 Correct 14 ms 3320 KB Output is correct
16 Correct 15 ms 3320 KB Output is correct
17 Correct 56 ms 3448 KB Output is correct
18 Correct 57 ms 3448 KB Output is correct
19 Correct 28 ms 3192 KB Output is correct
20 Correct 28 ms 3196 KB Output is correct
21 Correct 27 ms 3192 KB Output is correct
22 Correct 28 ms 3192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 248 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 380 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 4 ms 376 KB Output is correct
11 Correct 5 ms 380 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 182 ms 25976 KB Output is correct
15 Correct 188 ms 25976 KB Output is correct
16 Correct 191 ms 26104 KB Output is correct
17 Correct 188 ms 25976 KB Output is correct
18 Correct 187 ms 25976 KB Output is correct
19 Correct 181 ms 25976 KB Output is correct
20 Correct 183 ms 25976 KB Output is correct
21 Correct 168 ms 25976 KB Output is correct
22 Correct 163 ms 25976 KB Output is correct
23 Correct 161 ms 25976 KB Output is correct
24 Correct 183 ms 25984 KB Output is correct
25 Correct 708 ms 26104 KB Output is correct
26 Correct 719 ms 26104 KB Output is correct
27 Correct 705 ms 26232 KB Output is correct
28 Correct 698 ms 26232 KB Output is correct
29 Correct 898 ms 26216 KB Output is correct
30 Correct 899 ms 26168 KB Output is correct
31 Correct 909 ms 26104 KB Output is correct
32 Correct 776 ms 26052 KB Output is correct
33 Correct 776 ms 26104 KB Output is correct
34 Correct 774 ms 25976 KB Output is correct
35 Correct 14 ms 3320 KB Output is correct
36 Correct 14 ms 3320 KB Output is correct
37 Correct 15 ms 3320 KB Output is correct
38 Correct 56 ms 3448 KB Output is correct
39 Correct 57 ms 3448 KB Output is correct
40 Correct 28 ms 3192 KB Output is correct
41 Correct 28 ms 3196 KB Output is correct
42 Correct 27 ms 3192 KB Output is correct
43 Correct 28 ms 3192 KB Output is correct
44 Correct 249 ms 25976 KB Output is correct
45 Correct 355 ms 25976 KB Output is correct
46 Correct 386 ms 26104 KB Output is correct
47 Correct 709 ms 26232 KB Output is correct
48 Correct 709 ms 26104 KB Output is correct
49 Correct 683 ms 26232 KB Output is correct
50 Correct 682 ms 26232 KB Output is correct
51 Correct 675 ms 26104 KB Output is correct
52 Correct 676 ms 26104 KB Output is correct