結果

問題 No.859 路線A、路線B、路線C
ユーザー kenta255kenta255
提出日時 2019-08-10 01:32:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,041 bytes
コンパイル時間 2,255 ms
コンパイル使用メモリ 211,760 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-26 22:24:38
合計ジャッジ時間 3,161 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)

const ll INF = 1000000000000007LL;
ll d[100][100] = {};
map<string,int> ma;
int m = 1;
ll to(string x){
	if(ma[x])return ma[x];
	ma[x] = m++;
	return ma[x];
}
void conn(char x,int n,char y,int m,ll l){
	d[to(string(x+to_string(n)))][to(string(y+to_string(m)))] = l;
	d[to(string(y+to_string(m)))][to(string(x+to_string(n)))] = l;
}

int main(){
	ll x[3],t[2];
	char s[2],c[3]={'A','B','C'};
	FOR(i,0,3)cin>>x[i];
	FOR(i,0,2)cin>>s[i]>>t[i];
	FOR(i,0,100)FOR(j,0,100)d[i][j]=INF;
	FOR(i,0,3){
		FOR(j,i+1,3){
			conn(c[i],1,c[j],1,1);
			conn(c[i],x[i],c[j],x[j],1);
		}
		conn(c[i],1,c[i],x[i],x[i]-1);
	}
	FOR(i,0,2){
		conn(s[i],1,s[i],t[i],t[i]-1);
		conn(s[i],x[s[i]-'A'],s[i],t[i],x[s[i]-'A']-t[i]);
	}
	FOR(k,1,m)FOR(i,1,m)FOR(j,1,m){
		d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
	}
	ll ans = d[to(s[0]+to_string(t[0]))][to(s[1]+to_string(t[1]))];
	if(s[0]==s[1])ans = min(ans,abs(t[0]-t[1]));
	cout << ans << endl;
}
0