結果

問題 No.859 路線A、路線B、路線C
ユーザー firiexpfiriexp
提出日時 2019-08-30 00:39:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,335 bytes
コンパイル時間 900 ms
コンパイル使用メモリ 100,908 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-29 00:46:23
合計ジャッジ時間 1,644 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <limits>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;



int main() {
    vector<int> vs(3);
    int a, b; char as, bs;
    cin >> vs[0] >> vs[1] >> vs[2] >> as >> a >> bs >> b;
    vector<vector<ll>> G(12, vector<ll>(12, INF<ll>));
    for (int i = 0; i < 12; ++i) {
        G[i][i] = 0;
    }
    auto add = [&](int p, int q, int c){
        G[p][q] = G[q][p] = c;
    };
    for (int i = 0; i < 3; ++i) {
        vector<int> v{1, a, b, vs[i]};
        for (int j = 0; j < 4; ++j) {
            for (int k = 0; k < 4; ++k) {
                if(j == k) continue;
                add(i*4+j, i*4+k, abs(v[j]-v[k]));
            }
        }
    }
    add(0, 4, 1); add(0, 8, 1);
    add(4, 8, 1);
    add(3, 7, 1); add(3, 11, 1);
    add(7, 11, 1);
    for (int k = 0; k < 12; ++k) {
        for (int i = 0; i < 12; ++i) {
            for (int j = 0; j < 12; ++j) {
                G[i][j] = min(G[i][j], G[i][k]+G[k][j]);
            }
        }
    }
    cout << G[(as-'A')*4+1][(bs-'A')*4+2] << "\n";
    return 0;
}
0