結果
| 問題 |
No.17 2つの地点に泊まりたい
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-05-17 18:27:02 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,143 bytes |
| コンパイル時間 | 220 ms |
| コンパイル使用メモリ | 29,280 KB |
| 最終ジャッジ日時 | 2024-11-14 19:03:29 |
| 合計ジャッジ時間 | 779 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:13:3: error: ‘vector’ was not declared in this scope
13 | vector<int> s(n);
| ^~~~~~
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:13:10: error: expected primary-expression before ‘int’
13 | vector<int> s(n);
| ^~~
main.cpp:14:40: error: ‘s’ was not declared in this scope
14 | for(int i : range(n)) { scanf("%d", &s[i]); }
| ^
main.cpp:16:17: error: expected primary-expression before ‘int’
16 | vector<vector<int>> graph(n, vector<int>(n));
| ^~~
main.cpp:19:7: error: ‘graph’ was not declared in this scope
19 | graph[i][j] = i==j ? 0 : inf;
| ^~~~~
main.cpp:24:5: error: ‘graph’ was not declared in this scope
24 | graph[a][b] = c;
| ^~~~~
main.cpp:30:9: error: ‘graph’ was not declared in this scope
30 | graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]);
| ^~~~~
main.cpp:38:22: error: ‘graph’ was not declared in this scope
38 | res = min(res, graph[0][i] + graph[i][j] + graph[j][n-1] + s[i] + s[j]);
| ^~~~~
main.cpp:38:66: error: ‘s’ was not declared in this scope
38 | res = min(res, graph[0][i] + graph[i][j] + graph[j][n-1] + s[i] + s[j]);
| ^
main.cpp:12:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
12 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp:15:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
15 | scanf("%d", &m);
| ~~~~~^
ソースコード
#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, m;
scanf("%d", &n);
vector<int> s(n);
for(int i : range(n)) { scanf("%d", &s[i]); }
scanf("%d", &m);
vector<vector<int>> graph(n, vector<int>(n));
for(int i : range(n)) {
for(int j : range(n)) {
graph[i][j] = i==j ? 0 : inf;
}
}
for(int i : range(m)) {
int a, b, c; scanf("%d%d%d", &a, &b, &c);
graph[a][b] = c;
graph[b][a] = c;
}
for(int k : range(n)) {
for(int i : range(n)) {
for(int j : range(n)) {
graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]);
}
}
}
int res = inf;
for(int i : range(1, n-1)) {
for(int j : range(1, n-1)) {
if(i==j) { continue; }
res = min(res, graph[0][i] + graph[i][j] + graph[j][n-1] + s[i] + s[j]);
}
}
printf("%d\n", res);
return 0;
}