結果
| 問題 |
No.2924 <===Super Spaceship String===>
|
| コンテスト | |
| ユーザー |
aketijyuuzou
|
| 提出日時 | 2025-02-11 15:23:35 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,299 bytes |
| コンパイル時間 | 6,079 ms |
| コンパイル使用メモリ | 117,832 KB |
| 実行使用メモリ | 59,552 KB |
| 最終ジャッジ日時 | 2025-02-11 15:23:44 |
| 合計ジャッジ時間 | 7,573 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 6 WA * 6 |
コンパイルメッセージ
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];
List<RunLen.RunLenInfo> RunLenList = RunLen.DeriveRunLenInfoList(S);
var InsLinkedList = new LinkedList<RunLen.RunLenInfo>();
foreach (RunLen.RunLenInfo EachRunLen in RunLenList) {
if (EachRunLen.AppearChar == '=') {
InsLinkedList.AddLast(EachRunLen);
}
else {
for (int I = 1; I <= EachRunLen.RunLen; I++) {
RunLen.RunLenInfo WillAdd;
WillAdd.AppearChar = EachRunLen.AppearChar;
WillAdd.RunLen = 1;
InsLinkedList.AddLast(WillAdd);
}
}
while (true) {
if (InsLinkedList.Count >= 3) {
RunLen.RunLenInfo Last2 = InsLinkedList.Last.Value;
RunLen.RunLenInfo Last1 = InsLinkedList.Last.Previous.Value;
RunLen.RunLenInfo Last0 = InsLinkedList.Last.Previous.Previous.Value;
if (Last0.AppearChar == '<' &&
Last1.AppearChar == '=' &&
Last2.AppearChar == '>') {
InsLinkedList.RemoveLast();
InsLinkedList.RemoveLast();
InsLinkedList.RemoveLast();
continue;
}
}
break;
}
}
long Answer = InsLinkedList.Sum(pX => pX.RunLen);
Console.WriteLine(Answer);
}
}
#region RunLen
// ランレングス圧縮(文字列)
internal class RunLen
{
// ランレングス圧縮情報
internal struct RunLenInfo
{
internal char AppearChar;
internal int RunLen;
}
// ランレングス圧縮結果を返す
internal static List<RunLenInfo> DeriveRunLenInfoList(string pBaseStr)
{
var WillReturn = new List<RunLenInfo>();
int StrUB = pBaseStr.Length - 1;
char PrevChar = pBaseStr[0];
int StrLen = 0;
for (int I = 0; I <= StrUB; I++) {
if (pBaseStr[I] != PrevChar) {
RunLenInfo WillAdd;
WillAdd.AppearChar = PrevChar;
WillAdd.RunLen = StrLen;
WillReturn.Add(WillAdd);
StrLen = 0;
PrevChar = pBaseStr[I];
}
StrLen++;
if (I == StrUB) {
RunLenInfo WillAdd;
WillAdd.AppearChar = pBaseStr[I];
WillAdd.RunLen = StrLen;
WillReturn.Add(WillAdd);
}
}
return WillReturn;
}
}
#endregion
aketijyuuzou