結果
| 問題 |
No.1 道のショートカット
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-05-25 19:06:17 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 2,017 bytes |
| コンパイル時間 | 159 ms |
| コンパイル使用メモリ | 29,408 KB |
| 最終ジャッジ日時 | 2024-11-14 19:03:53 |
| 合計ジャッジ時間 | 517 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:12:3: error: ‘vector’ was not declared in this scope
12 | vector<int> s(v), t(v), y(v), m(v);
| ^~~~~~
main.cpp:3:1: note: ‘std::vector’ is defined in header ‘<vector>’; did you forget to ‘#include <vector>’?
2 | #include <algorithm>
+++ |+#include <vector>
3 | using namespace std;
main.cpp:12:10: error: expected primary-expression before ‘int’
12 | vector<int> s(v), t(v), y(v), m(v);
| ^~~
main.cpp:13:40: error: ‘s’ was not declared in this scope
13 | for(int i : range(v)) { scanf("%d", &s[i]); }
| ^
main.cpp:14:40: error: ‘t’ was not declared in this scope
14 | for(int i : range(v)) { scanf("%d", &t[i]); }
| ^
main.cpp:15:40: error: ‘y’ was not declared in this scope
15 | for(int i : range(v)) { scanf("%d", &y[i]); }
| ^
main.cpp:16:40: error: ‘m’ was not declared in this scope
16 | for(int i : range(v)) { scanf("%d", &m[i]); }
| ^
main.cpp:17:10: error: expected primary-expression before ‘int’
17 | vector<int> route(v);
| ^~~
main.cpp:18:17: error: expected primary-expression before ‘int’
18 | vector<vector<int>> path(n, vector<int>(v)), time(n, vector<int>(v)), cost(n, vector<int>(v));
| ^~~
main.cpp:21:7: error: ‘path’ was not declared in this scope
21 | path[i][j] = time[i][j] = cost[i][j] = inf;
| ^~~~
main.cpp:21:20: error: ‘time’ was not declared in this scope; did you mean ‘time_t’?
21 | path[i][j] = time[i][j] = cost[i][j] = inf;
| ^~~~
| time_t
main.cpp:21:33: error: ‘cost’ was not declared in this scope
21 | path[i][j] = time[i][j] = cost[i][j] = inf;
|
ソースコード
#include <cstdio>
#include <algorithm>
using namespace std;
class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x<lhs.x;}void operator++(){++x;}};I i,n;
public:range(int n):i({0}),n({n}){}range(int i,int n):i({i}),n({n}){}I& begin(){return i;}I& end(){return n;}};
const int inf = 987654321;
int main(void) {
int n, c, v; scanf("%d%d%d", &n, &c, &v);
vector<int> s(v), t(v), y(v), m(v);
for(int i : range(v)) { scanf("%d", &s[i]); }
for(int i : range(v)) { scanf("%d", &t[i]); }
for(int i : range(v)) { scanf("%d", &y[i]); }
for(int i : range(v)) { scanf("%d", &m[i]); }
vector<int> route(v);
vector<vector<int>> path(n, vector<int>(v)), time(n, vector<int>(v)), cost(n, vector<int>(v));
for(int i : range(n)) {
for(int j : range(v)) {
path[i][j] = time[i][j] = cost[i][j] = inf;
}
}
for(int i : range(v)) {
s[i]--, t[i]--;
path[s[i]][route[s[i]]] = t[i];
time[s[i]][route[s[i]]] = m[i];
cost[s[i]][route[s[i]]] = y[i];
route[s[i]]++;
}
// iの街までj円以下で行くのに最短dp[i][j]分
vector<vector<int>> dp(n, vector<int>(c+1));
for(int i : range(n)) {
for(int j : range(c+1)) {
dp[i][j] = i==0 ? 0 : inf;
}
}
// iの街からjの道を通って行く
for(int i : range(n)) {
for(int j : range(v)) {
int dest = path[i][j];
// 道がない
if(dest == inf) { continue; }
// iの街までk円かかった
for(int k : range(c+1)) {
if(k + cost[i][j] <= c) {
// iの街までk円かかって、iの街からjの道を通ってdestの街に行くときの話。
// destの街へはk+cost[i][j]円かかる。
// iの街からdestの街へは(jの道を通るので)time[i][j]分かかる。
dp[dest][k+cost[i][j]]
= min(dp[dest][k+cost[i][j]], dp[i][k] + time[i][j]);
}
}
}
}
int res = dp[n-1][c];
if(res == inf) { res = -1; }
printf("%d\n", res);
return 0;
}