Submission #45926
ソースコード
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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | #include <iostream> #include <string> #include <stack> #include <queue> #include <cstring> #include <algorithm> #include <vector> #include <cstdio> //#include <cmath> #include <cstdlib> #include <functional> #include <map> #include <numeric> #define class struct #define bogo_sort std::sort #define bozo_sort std::stable_sort #define elif else if #define echo std::cout << #define read std::cin >> #define endl std::endl #define fin << '\n' #define unless(flg) if(!(flg)) #define elless(flg) else if(!(flg)) #define alles(obj) obj.begin(), obj.end() #define bash push_back #define makePair std::make_pair // type-define #define String std::string #define Stack std::stack #define Queue std::queue #define pQueue std::priority_queue #define Vector std::vector #define Pair std::pair #define Map std::map typedef long long llong; typedef bool boolean; typedef Pair< int , int > Pii; typedef Vector< int > Vi; // utils constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1}; constexpr int dy[] = {0, 1, 0, -1, 1, -1, 1, -1}; constexpr int INF = 0x3f3f3f3f; constexpr llong LINF = 0x3f3f3f3f3f3f3f3fLL; class hori { static llong power ( llong x, llong n, llong mod ) { llong ans = 1; while ( n > 0 ) { if ( n & 1 ) { ans = ( ans * x ) % mod; } x = ( x * x ) % mod; n >>= 1; } return ans; } static llong power ( llong x, llong n ) { return power( x, n, 1000000007 ); } static llong gcd ( llong x, llong y ) { return x % y ? gcd( y, x % y ) : y; } static llong lcm ( llong x, llong y ) { return ( x / gcd(x, y) * y ); } static boolean isMovable ( int x, int y, int w, int h ) { return ( x >= 0 && y >= 0 && x < w && y < h ); } }; namespace Rlyeh { int cost[12][110]; Vector<Pii> vii[110]; signed call_of_Cthulhu( signed datum ) { int c, n, m, s, d; read c >> n >> m >> s >> d; for ( int i = 0; i <= c; i++ ) { for ( int j = 0; j <= n; j++ ) { cost[i][j] = INF; } } for ( int i = 0; i < m; i++ ) { int a, b, c; read a >> b >> c; vii[a].bash(makePair(b, c)); vii[b].bash(makePair(a, c)); } using Piii = Pair < Pii, int >; pQueue<Piii, Vector<Piii>, std::greater<Piii>> pQue; pQue.push(makePair(makePair ( 0, s ) , c)); while ( !pQue.empty() ) { Piii now = pQue.top(); pQue.pop(); int cos = now.first.first; int pos = now.first.second; int ticket = now.second; for ( int i = 0; i < vii[pos].size(); i++ ) { int next = vii[pos][i].first; int ncst = vii[pos][i].second; if ( cos +ncst < cost[ticket][next] ) { cost[ticket][next] = cos +ncst; pQue.push ( makePair ( makePair ( cos +ncst, next ), ticket ) ); } if ( ticket != 0 && cos +(ncst/2) < cost[ticket][next] ) { cost[ticket][next] = cos +(ncst/2); pQue.push ( makePair ( makePair ( cos +(ncst/2), next ), ticket-1 ) ); } } } int ans = INF; for ( int i = 0; i <= c; i++ ) { ans = std::min ( cost[i][d], ans ); } echo ans fin; return 0; } } signed main(){std::cin.tie(0); std::ios::sync_with_stdio( false ); return Rlyeh::call_of_Cthulhu(114514);} |
ステータス
項目 | データ |
---|---|
問題 | 0717 - 高速バス |
ユーザー名 | r1825 |
投稿日時 | 2018-12-13 18:24:17 |
言語 | C++14 |
状態 | Accepted |
得点 | 5 |
ソースコード長 | 3732 Byte |
最大実行時間 | 50 ms |
最大メモリ使用量 | 744 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 5 / 5 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
input01.txt | AC | 50 ms | 604 KB |
1
|
input02.txt | AC | 24 ms | 532 KB |
1
|
input03.txt | AC | 21 ms | 588 KB |
1
|
input04.txt | AC | 24 ms | 624 KB |
1
|
input05.txt | AC | 25 ms | 664 KB |
1
|
input06.txt | AC | 22 ms | 560 KB |
1
|
input07.txt | AC | 18 ms | 604 KB |
1
|
input08.txt | AC | 21 ms | 744 KB |
1
|
input09.txt | AC | 18 ms | 620 KB |
1
|
input10.txt | AC | 18 ms | 536 KB |
1
|