結果
問題 | No.1 道のショートカット |
ユーザー | moyashi_senpai |
提出日時 | 2016-08-17 15:29:26 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,523 bytes |
コンパイル時間 | 655 ms |
コンパイル使用メモリ | 78,416 KB |
実行使用メモリ | 4,504 KB |
最終ジャッジ日時 | 2023-09-22 12:46:24 |
合計ジャッジ時間 | 2,356 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,380 KB |
testcase_01 | AC | 2 ms
4,380 KB |
testcase_02 | AC | 2 ms
4,376 KB |
testcase_03 | AC | 2 ms
4,376 KB |
testcase_04 | WA | - |
testcase_05 | AC | 2 ms
4,376 KB |
testcase_06 | AC | 1 ms
4,380 KB |
testcase_07 | AC | 1 ms
4,380 KB |
testcase_08 | AC | 2 ms
4,380 KB |
testcase_09 | AC | 2 ms
4,376 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | AC | 1 ms
4,380 KB |
testcase_16 | WA | - |
testcase_17 | AC | 2 ms
4,380 KB |
testcase_18 | AC | 1 ms
4,376 KB |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | AC | 1 ms
4,380 KB |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | AC | 2 ms
4,376 KB |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | AC | 1 ms
4,376 KB |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | AC | 1 ms
4,380 KB |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | AC | 1 ms
4,376 KB |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | AC | 2 ms
4,376 KB |
testcase_43 | AC | 2 ms
4,380 KB |
ソースコード
#include <iostream> #include <cstdio> #include <vector> #include <cmath> #include <cstring> #include <numeric> #include <algorithm> #include <functional> #include <array> #include <map> #include <queue> #include <limits.h> #include <set> #include <stack> #define REP(i,a,b) for(i=a;i<b;i++) #define rep(i,n) REP(i,0,n) using namespace std; typedef vector<int> Ivec; typedef pair<int, int> pii; int main() { int n,c,v; array<array<pii, 50>, 50> graph = {}; scanf("%d %d %d", &n, &c, &v); vector<pii> roads(v, {0,0}); for (int i = 0; v > i; i++) { int s; scanf("%d", &s); roads[i].first = s-1; } for (int i = 0; v > i; i++) { int s; scanf("%d", &s); roads[i].second = s-1; } for (int i = 0; v > i; i++) { int s; scanf("%d", &s); graph[roads[i].first][roads[i].second].first = s; } for (int i = 0; v > i; i++) { int s; scanf("%d", &s); graph[roads[i].first][roads[i].second].second = s; } array<array<int, 301>, 51> dp; for (auto itr = dp.begin(); itr != dp.end(); itr++) { fill(itr->begin(), itr->end(), INT_MAX); } dp[0][c] = 0; for (int i = 0; n-1 > i; i++) { for (int j = 0; c >= j; j++) { if (dp[i][j] != INT_MAX) { for (int k = i + 1; n > k; k++) { if (graph[i][k].first && j - graph[i][k].first >= 0) { dp[k][j - graph[i][k].first] = min(dp[k][j - graph[i][k].first], dp[i][j] + graph[i][k].second); } } } } } int ans = *min_element(dp[n - 1].begin(), dp[n - 1].end()); if (ans == INT_MAX) ans = -1; printf("%d\n", ans); return 0; }