Submission #45316
ソースコード
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 105 106 | #include <bits/stdc++.h> using namespace std; int n, m, x; vector<pair< int , int > > graph[10010]; int data[10010]; class Data{ public : int cost; int i; int at; int times; bool operator> ( const Data &a) const { return this ->cost > a.cost; } }; Data init( int a, int b, int c, int d){ Data dt; dt.cost = a; dt.i = b; dt.at = c; dt.times = d; return dt; } int v[10010][3][210] = {}; int main(){ cin >> n >> m >> x; int a, b, c; for ( int i = 0;i < n;i++){ cin >> data[i]; } for ( int i = 0;i < m;i++){ cin >> a >> b >> c; a--; b--; graph[a].push_back(make_pair(b, c)); graph[b].push_back(make_pair(a, c)); } for ( int i = 0;i < 10010;i++) for ( int j = 0;j < 3;j++) for ( int k = 0;k < 210;k++) v[i][j][k] = INT_MAX; priority_queue<Data, vector<Data>, greater<Data> > que; que.push(init(0, 0, 0, x)); int ans = INT_MAX; while (!que.empty()){ Data tmp = que.top(); que.pop(); int now = tmp.i; int cost = tmp.cost; for ( int i = 0;i < graph[now].size();i++){ int hot = tmp.at; int times = tmp.times; times -= graph[now][i].second; if (times <= 0){ times = 0; hot = 1; } if (!(hot == 0 && data[graph[now][i].first] == 2 || hot == 2 && data[graph[now][i].first] == 0)){ if (data[graph[now][i].first] != 1){ hot = data[graph[now][i].first]; times = x; } if (v[graph[now][i].first][hot][times] > cost + graph[now][i].second){ v[graph[now][i].first][hot][times] = cost + graph[now][i].second; if (graph[now][i].first == n-1){ ans = min(ans, v[graph[now][i].first][hot][times]); } que.push(init(cost + graph[now][i].second, graph[now][i].first, hot, times)); } } } } /* for(int j = 0;j < 3;j++) for(int k = 0;k < 210;k++) ans = min(ans, v[n-1][j][k]); */ cout << ans << endl; return 0; } |
ステータス
項目 | データ |
---|---|
問題 | 0597 - ヘビの JOI 君 (Snake JOI) |
ユーザー名 | ei1719 |
投稿日時 | 2018-11-21 22:46:04 |
言語 | C++11 |
状態 | Accepted |
得点 | 100 |
ソースコード長 | 2105 Byte |
最大実行時間 | 72 ms |
最大メモリ使用量 | 26232 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 | 72 ms | 26076 KB |
1
|
||||
2017-yo-t6-in2.txt | AC | 48 ms | 26124 KB |
2
|
||||
2017-yo-t6-in3.txt | AC | 45 ms | 26000 KB |
3
|
||||
2017-yo-t6-in4.txt | AC | 55 ms | 26232 KB |
4
|
||||
2017-yo-t6-in5.txt | AC | 53 ms | 26132 KB |
5
|