Submission #55952


ソースコード

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include <bits/stdc++.h>
using namespace std;
#define long long long
#define fprintf(...)
const long LINF = 0x3f3f3f3f3f3f3f3fLL;
int n, m, x;
struct DijkstraData {
int pos, cost;
int type, down;
bool operator < ( const DijkstraData &tar ) const {
return cost < tar.cost;
}
bool operator > ( const DijkstraData &tar ) const {
return cost > tar.cost;
}
};
bool check ( int t1, int t2, int dist ) {
if ( t1 != t2 && t2 != 1 ) {
return dist >= x;
}
return true;
}
int getType ( int t1, int t2 ) {
if ( t2 == 1 ) return t1;
return t2;
}
int getDown(int type, int down) {
if ( type == 1 ) return min(x, down);
return 0;
}
int t[100100];
vector<pair<int, int> > g[10100];
int dist[10010][3][222];
int dijkstra ( int start, int goal ) {
priority_queue<DijkstraData, vector<DijkstraData>, greater<DijkstraData> > p;
for ( int i = 0; i < 10010; i++ ) {
for ( int j = 0; j < 3; j++ ) {
for ( int k = 0; k < 222; k++ ) {
dist[i][j][k] = 0x3f3f3f3f;
}
}
}
dist[start][0][0] = 0;
p.push((DijkstraData){start, 0, 0, 0});
while ( !p.empty() ) {
DijkstraData now = p.top();
p.pop();
const int cost = now.cost;
const int pos = now.pos;
const int type = now.type;
const int down = now.down;
fprintf(stderr, "pos:%d\n", pos);
for ( int i = 0; i < (int)g[pos].size(); i++ ) {
int next = g[pos][i].first;
int ncst = g[pos][i].second + cost;
int ntyp = t[next];
int ndwn = getDown(ntyp, down + g[pos][i].second);
fprintf(stderr, " next:%d type:%d down:%d cost:%d\n", next, getType(type, ntyp), ndwn, ncst);
if ( ncst < dist[next][getType(type, ntyp)][ndwn] && check(type, ntyp, down + g[pos][i].second) ) {
dist[next][getType(type,ntyp)][ndwn] = ncst;
p.push((DijkstraData){next, ncst, getType(type, ntyp), ndwn});
fprintf(stderr, " pushed -> next:%d type:%d down:%d cost:%d\n", next, getType(type, ntyp), ndwn, ncst);
}
}
}
int ans = 0x3f3f3f3f;
for ( int i = 0; i < 3; i++ ) {
for ( int j = 0; j < 222; j++ ) {
ans = min ( ans, dist[goal][i][j] );
}
}
return ans;
}
signed main ( ) {
cin >> n >> m >> x;
for ( int i = 0; i < n; i++ ) {
cin >> t[i+1];
}
for ( int i = 0; i < m; i++ ) {
int a, b, d;
cin >> a >> b >> d;
g[a].push_back(make_pair(b, d));
g[b].push_back(make_pair(a, d));
}
cout << dijkstra(1, n) << endl;
return 0;
}

ステータス

項目 データ
問題 0597 - ヘビの JOI 君 (Snake JOI)
ユーザー名 r1825
投稿日時 2019-10-30 20:02:23
言語 C++14
状態 Accepted
得点 100
ソースコード長 2821 Byte
最大実行時間 83 ms
最大メモリ使用量 28772 KB

セット

セット 得点 Cases
1 set1 20 / 20 *t6*1.txt
2 set2 20 / 20 *t6*2.txt
3 set3 20 / 20 *t6*3.txt
4 set4 20 / 20 *t6*4.txt
5 set5 20 / 20 *t6*5.txt

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
2017-yo-t6-in1.txt AC 67 ms 27864 KB
1
2017-yo-t6-in2.txt AC 47 ms 27740 KB
2
2017-yo-t6-in3.txt AC 83 ms 28080 KB
3
2017-yo-t6-in4.txt AC 68 ms 28396 KB
4
2017-yo-t6-in5.txt AC 66 ms 28772 KB
5