結果

問題 No.859 路線A、路線B、路線C
ユーザー hipopohipopo
提出日時 2020-04-13 19:02:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 2,750 bytes
コンパイル時間 1,555 ms
コンパイル使用メモリ 142,396 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-25 22:28:55
合計ジャッジ時間 2,180 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

using ll = long long;
using P = pair<int, int>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

const ll INF = 1e18;
const int MAX_V = 8;
vector<vector<ll>> d(MAX_V, vector<ll>(MAX_V, INF));
int V = 8;

void warshall_floyd() {
    for (int k = 0; k < V; k++) {
        for (int i = 0; i < V; i++) {
            for (int j = 0; j < V; j++) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}

int main() {
    vector<ll> len(3);
    cin >> len;
    auto add_edge = [&](int u, int v, ll w){
        d[u][v] = w;
        d[v][u] = w;
    };
    
    add_edge(0, 1, len[0] - 1);
    add_edge(0, 2, 1);
    add_edge(0, 4, 1);
    add_edge(1, 3, 1);
    add_edge(1, 5, 1);
    add_edge(2, 3, len[1] - 1);
    add_edge(2, 4, 1);
    add_edge(3, 5, 1);
    add_edge(4, 5, len[2] - 1);
    
    char s1, s2;
    int num1, num2;
    cin >> s1 >> num1 >> s2 >> num2;
    
    int line1 = s1 - 'A', line2 = s2 - 'A';
    if (line1 == line2) {
        if (num1 > num2) swap(num1, num2);
        add_edge(line1 * 2, 6, num1 - 1);
        add_edge(line2 * 2 + 1, 7, len[line1] - num2);
        add_edge(6, 7, num2 - num1);
    }
    else {
        add_edge(line1 * 2, 6, num1 - 1);
        add_edge(line1 * 2 + 1, 6, len[line1] - num1);
        
        add_edge(line2 * 2, 7, num2 - 1);
        add_edge(line2 * 2 + 1, 7, len[line2] - num2);
    }
    
    warshall_floyd();
    cout << d[6][7] << endl;
}
0