結果
問題 |
No.859 路線A、路線B、路線C
|
ユーザー |
![]() |
提出日時 | 2021-05-07 17:04:11 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 27 ms / 1,000 ms |
コード長 | 1,624 bytes |
コンパイル時間 | 2,074 ms |
コンパイル使用メモリ | 105,600 KB |
実行使用メモリ | 18,688 KB |
最終ジャッジ日時 | 2024-09-15 05:25:08 |
合計ジャッジ時間 | 1,929 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System.Linq; using System; public class Hello { static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var a = Array.ConvertAll(line, int.Parse); line = Console.ReadLine().Trim().Split(' '); var s0 = line[0]; var t0 = int.Parse(line[1]); line = Console.ReadLine().Trim().Split(' '); var s1 = line[0]; var t1 = int.Parse(line[1]); if (s0 == s1) { if (s0 == "A") Same(a, t0, t1, 0, 1, 2); else if (s0 == "B") Same(a, t0, t1, 1, 0, 2); else Same(a, t0, t1, 2, 0, 1); } else { if ((s0 == "A" && s1 == "B") | (s0 == "B" && s1 == "A")) Diff(a, t0, t1, 0, 1, 2); else if ((s0 == "B" && s1 == "C") | (s0 == "C" && s1 == "B")) Diff(a, t0, t1, 1, 2, 0); else Diff(a, t0, t1, 0, 2, 1); } } static void Diff(int[] a, int t0, int t1, int p, int q, int r) { var root = new long[4]; root[0] = (t0 - 1L) + (t1 - 1L) + 1L; root[1] = (a[p] - t0) + (a[q] - t1) + 1L; root[2] = (t0 - 1L) + (a[r] - 1L) + 2L + (a[q] - t1); root[3] = (a[p] - t0) + (a[r] - 1L) + 2L + (t1 - 1L); Console.WriteLine(root.Min()); } static void Same(int[] a, int t0, int t1, int p, int q, int r) { if (t0 > t1) { Same(a, t1, t0, p, q, r); return; } var root = new long[3]; root[0] = t1 - t0; root[1] = (t0 - 1L) + (a[q] + 1L) + (a[p] - t1); root[2] = (t0 - 1L) + (a[r] + 1L) + (a[p] - t1); Console.WriteLine(root.Min()); } }