結果
| 問題 |
No.2924 <===Super Spaceship String===>
|
| コンテスト | |
| ユーザー |
bluemegane
|
| 提出日時 | 2024-10-14 07:51:11 |
| 言語 | C# (.NET 8.0.404) |
| 結果 |
AC
|
| 実行時間 | 83 ms / 2,000 ms |
| コード長 | 1,981 bytes |
| コンパイル時間 | 8,861 ms |
| コンパイル使用メモリ | 167,820 KB |
| 実行使用メモリ | 196,748 KB |
| 最終ジャッジ日時 | 2024-10-16 17:56:29 |
| 合計ジャッジ時間 | 9,889 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 12 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.csproj を復元しました (94 ms)。 MSBuild のバージョン 17.9.6+a4ecab324 (.NET) main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.0/publish/
ソースコード
using System.Collections.Generic;
using System;
public class Hello
{
static void Main()
{
var s = Console.ReadLine().Trim();
getAns(s);
}
static void getAns(string s)
{
var st = new Stack<int>();
var a = getQ(s);
foreach (var x in a)
{
if (x == 0) st.Push(x);
else if (x <0)
{
if (st.Count == 0) { st.Push(x); continue; }
if (st.Peek() < 0)
{
var ww = st.Pop();
ww += x;
st.Push(ww);
}
else st.Push(x);
}
else
{
if (st.Count == 0) { st.Push(1); continue; }
if (st.Peek() < 0)
{
var w = st.Pop();
if (st.Count == 0) { st.Push(w);st.Push(1); continue; }
if (st.Peek() == 0) st.Pop();
else { st.Push(w); st.Push(1); }
}
else st.Push(1);
}
}
var ans = 0;
foreach (var x in st)
{
if (x >= 0) ans++;
else ans += -x;
}
Console.WriteLine(ans);
}
static int[] getQ(string s)
{
var n = s.Length;
var q = new Queue<int>();
var f = false;
var c = 0;
if (s[0] == '<') q.Enqueue(0);
else if (s[0] == '>') q.Enqueue(1);
else { f = true; c = 1; }
for (int i = 1; i < n; i++)
{
if (s[i] == '=')
{
if (f) c++;
else { f = true; c = 1; }
}
else
{
f = false;
if (c > 0) { q.Enqueue(-c); c = 0; }
if (s[i] == '<') q.Enqueue(0);
else q.Enqueue(1);
}
}
if (f) q.Enqueue(-c);
return q.ToArray();
}
}
bluemegane