結果
問題 |
No.2924 <===Super Spaceship String===>
|
ユーザー |
![]() |
提出日時 | 2025-02-11 16:01:00 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 126 ms / 2,000 ms |
コード長 | 2,775 bytes |
コンパイル時間 | 3,086 ms |
コンパイル使用メモリ | 118,192 KB |
実行使用メモリ | 55,776 KB |
最終ジャッジ日時 | 2025-02-11 16:01:05 |
合計ジャッジ時間 | 5,074 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
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; using System.Collections.Generic; using System.Linq; class Program { static string InputPattern = "InputX"; static List<string> GetInputList() { var WillReturn = new List<string>(); if (InputPattern == "Input1") { WillReturn.Add("<=<<==>=><>"); } else if (InputPattern == "Input2") { WillReturn.Add(">=<=<>=>=<"); } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static void Main() { List<string> InputList = GetInputList(); string S = InputList[0]; var InsLinkedList = new LinkedList<RunLenInfo>(); foreach (char EachChar in S) { var WillAdd=new RunLenInfo(); WillAdd.AppearChar = EachChar; WillAdd.RunLen = 1; InsLinkedList.AddLast(WillAdd); while (ExecConcat(InsLinkedList) || ExecRemove(InsLinkedList)) ; } long Answer = InsLinkedList.Sum(pX => pX.RunLen); Console.WriteLine(Answer); } // =同士の接続処理を行い、変更有無を返す static bool ExecConcat(LinkedList<RunLenInfo> pLinkedList) { bool Changed = false; while (true) { if (pLinkedList.Count >= 2) { char Last2 = pLinkedList.Last.Value.AppearChar; char Last1 = pLinkedList.Last.Previous.Value.AppearChar; if (Last1 == '=' && Last2 == '=') { pLinkedList.Last.Previous.Value.RunLen += pLinkedList.Last.Value.RunLen; pLinkedList.RemoveLast(); Changed = true; continue; } } return Changed; } } // 宇宙船の削除処理を行い、変更有無を返す static bool ExecRemove(LinkedList<RunLenInfo> pLinkedList) { bool Changed = false; while (true) { if (pLinkedList.Count >= 3) { char Last3 = pLinkedList.Last.Value.AppearChar; char Last2 = pLinkedList.Last.Previous.Value.AppearChar; char Last1 = pLinkedList.Last.Previous.Previous.Value.AppearChar; if (Last1 == '<' && Last2 == '=' && Last3 == '>') { pLinkedList.RemoveLast(); pLinkedList.RemoveLast(); pLinkedList.RemoveLast(); Changed = true; continue; } } return Changed; } } // ランレングス圧縮情報 internal class RunLenInfo { internal char AppearChar; internal int RunLen; } }