結果

問題 No.2924 <===Super Spaceship String===>
ユーザー aketijyuuzou
提出日時 2025-02-11 16:03:09
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 126 ms / 2,000 ms
コード長 2,878 bytes
コンパイル時間 5,454 ms
コンパイル使用メモリ 108,160 KB
実行使用メモリ 47,488 KB
最終ジャッジ日時 2025-02-11 16:03:16
合計ジャッジ時間 7,077 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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.

ソースコード

diff #

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 (true) {
                if (ExecConcat(InsLinkedList)) continue;
                if (ExecRemove(InsLinkedList)) continue;
                break;
            }
        }
        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;
    }
}
0