結果

問題 No.17 2つの地点に泊まりたい
ユーザー hogeover30hogeover30
提出日時 2015-02-04 00:51:58
言語 C++11
(gcc 11.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 759 bytes
コンパイル時間 350 ms
コンパイル使用メモリ 52,252 KB
最終ジャッジ日時 2023-08-05 03:31:34
合計ジャッジ時間 728 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:10:9: error: ‘vector’ was not declared in this scope
         vector<int> s(n);
         ^~~~~~
main.cpp:10:9: note: ‘std::vector’ is defined in header ‘<vector>’; did you forget to ‘#include <vector>’?
main.cpp:3:1:
+#include <vector>
 using namespace std;
main.cpp:10:9:
         vector<int> s(n);
         ^~~~~~
main.cpp:10:16: error: expected primary-expression before ‘int’
         vector<int> s(n);
                ^~~
main.cpp:11:21: error: ‘s’ was not declared in this scope
         for(int& v: s) cin>>v;
                     ^
main.cpp:13:23: error: expected primary-expression before ‘int’
         vector<vector<int>> cost(n, vector<int>(n, inf));
                       ^~~
main.cpp:17:13: error: ‘cost’ was not declared in this scope
             cost[a][b]=cost[b][a]=c;
             ^~~~
main.cpp:17:13: note: suggested alternative: ‘pclose’
             cost[a][b]=cost[b][a]=c;
             ^~~~
             pclose
main.cpp:21:19: error: ‘cost’ was not declared in this scope
         rep(i, n) cost[i][i]=0;
                   ^~~~
main.cpp:21:19: note: suggested alternative: ‘pclose’
         rep(i, n) cost[i][i]=0;
                   ^~~~
                   pclose
main.cpp:23:13: error: ‘cost’ was not declared in this scope
             cost[i][j]=min(cost[i][j], cost[i][k]+cost[k][j]);
             ^~~~
main.cpp:23:13: note: suggested alternative: ‘pclose’
             cost[i][j]=min(cost[i][j], cost[i][k]+cost[k][j]);
             ^~~~
             pclose
main.cpp:27:26: error: ‘cost’ was not declared in this scope
             res=min(res, cost[0][i]+s[i]+cost[i][j]+s[j]+cost[j][n-1]);
                          ^~~~
main.cpp:27:37: error: ‘s’ was not declared in this scope
             res=min(res, cost[0][i]+s[i]+cost[i][j]+s[j]+cost[j][n-1]);
                                     ^

ソースコード

diff #

#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    const int inf=1<<23;
    int n, m;
    while (cin>>n) {
        vector<int> s(n);
        for(int& v: s) cin>>v;
        cin>>m;
        vector<vector<int>> cost(n, vector<int>(n, inf));
        while (m--) {
            int a, b, c;
            cin>>a>>b>>c;
            cost[a][b]=cost[b][a]=c;
        }
#define REP(i,a,b) for(int i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
        rep(i, n) cost[i][i]=0;
        rep(k, n) rep(i, n) rep(j, n)
            cost[i][j]=min(cost[i][j], cost[i][k]+cost[k][j]);

        int res=inf;
        REP(i,1,n-1) REP(j,1,n-1) if (i!=j)
            res=min(res, cost[0][i]+s[i]+cost[i][j]+s[j]+cost[j][n-1]);
        cout<<res<<endl;
    }
}
0