結果

問題 No.1021 Children in Classrooms
ユーザー aketijyuuzouaketijyuuzou
提出日時 2024-10-10 20:46:57
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 138 ms / 2,000 ms
コード長 4,993 bytes
コンパイル時間 15,387 ms
コンパイル使用メモリ 169,620 KB
実行使用メモリ 193,160 KB
最終ジャッジ日時 2024-10-10 20:47:17
合計ジャッジ時間 16,263 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
29,944 KB
testcase_01 AC 57 ms
30,208 KB
testcase_02 AC 58 ms
30,080 KB
testcase_03 AC 59 ms
30,592 KB
testcase_04 AC 61 ms
30,720 KB
testcase_05 AC 58 ms
30,336 KB
testcase_06 AC 58 ms
30,424 KB
testcase_07 AC 61 ms
30,460 KB
testcase_08 AC 60 ms
30,464 KB
testcase_09 AC 137 ms
57,344 KB
testcase_10 AC 136 ms
57,728 KB
testcase_11 AC 136 ms
57,460 KB
testcase_12 AC 135 ms
57,596 KB
testcase_13 AC 134 ms
57,984 KB
testcase_14 AC 138 ms
57,600 KB
testcase_15 AC 119 ms
54,004 KB
testcase_16 AC 119 ms
54,144 KB
testcase_17 AC 119 ms
54,784 KB
testcase_18 AC 126 ms
58,996 KB
testcase_19 AC 66 ms
193,160 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (102 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/

ソースコード

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("4 3");
            WillReturn.Add("3 1 4 1");
            WillReturn.Add("LRR");
            //0 0 4 5
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("2 7");
            WillReturn.Add("1 8");
            WillReturn.Add("LLLLLLL");
            //9 0
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("5 6");
            WillReturn.Add("314 0 1 5 9");
            WillReturn.Add("RLRLLR");
            //0 314 1 14 0
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        long[] AArr = InputList[1].Split(' ').Select(pX => long.Parse(pX)).ToArray();

        var InsDeque = new Deque<long>();
        foreach (long EachA in AArr) {
            InsDeque.PushBack(EachA);
        }

        string S = InputList[2];

        foreach (char EachChar in S) {
            if (EachChar == 'L') {
                long FrontVal = InsDeque[0];
                InsDeque.PopFront();
                InsDeque[0] += FrontVal;
                InsDeque.PushBack(0);
            }
            if (EachChar == 'R') {
                long BackVal = InsDeque[InsDeque.Count - 1];
                InsDeque.PopBack();
                InsDeque[InsDeque.Count - 1] += BackVal;
                InsDeque.PushFront(0);
            }
        }

        var AnswerList = new List<long>();
        for (int I = 0; I <= InsDeque.Count - 1; I++) {
            AnswerList.Add(InsDeque[I]);
        }
        Console.WriteLine(LongEnumJoin(" ", AnswerList));
    }

    // セパレータとLong型の列挙を引数として、結合したstringを返す
    static string LongEnumJoin(string pSeparater, IEnumerable<long> pEnum)
    {
        string[] StrArr = Array.ConvertAll(pEnum.ToArray(), pX => pX.ToString());
        return string.Join(pSeparater, StrArr);
    }
}

#region Deque
internal class Deque<T>
{
    T[] buf;
    int offset, count, capacity;

    internal int Count { get { return count; } }

    internal Deque(int cap) { buf = new T[capacity = cap]; }

    internal Deque() { buf = new T[capacity = 16]; }

    internal T this[int index]
    {
        get { return buf[GetIndex(index)]; }
        set { buf[GetIndex(index)] = value; }
    }

    private int GetIndex(int index)
    {
        if (index >= capacity)
            throw new IndexOutOfRangeException("out of range");
        int ret = index + offset;
        if (ret >= capacity)
            ret -= capacity;
        return ret;
    }

    internal void PushFront(T item)
    {
        if (count == capacity) Extend();
        if (--offset < 0) offset += buf.Length;
        buf[offset] = item;
        count++;
    }

    internal T PopFront()
    {
        if (count == 0)
            throw new InvalidOperationException("collection is empty");
        count--;
        T ret = buf[offset++];
        if (offset >= capacity) offset -= capacity;
        return ret;
    }

    internal void PushBack(T item)
    {
        if (count == capacity) Extend();
        int id = count + offset;
        count++;
        if (id >= capacity) id -= capacity;
        buf[id] = item;
    }

    internal T PopBack()
    {
        if (count == 0)
            throw new InvalidOperationException("collection is empty");
        return buf[GetIndex(--count)];
    }

    internal void Insert(int index, T item)
    {
        if (index > count) throw new IndexOutOfRangeException();
        this.PushFront(item);
        for (int i = 0; i < index; i++)
            this[i] = this[i + 1];
        this[index] = item;
    }

    internal T RemoveAt(int index)
    {
        if (index < 0 || index >= count) throw new IndexOutOfRangeException();
        T ret = this[index];
        for (int i = index; i > 0; i--)
            this[i] = this[i - 1];
        this.PopFront();
        return ret;
    }

    private void Extend()
    {
        T[] newBuffer = new T[capacity << 1];
        if (offset > capacity - count) {
            int len = buf.Length - offset;
            Array.Copy(buf, offset, newBuffer, 0, len);
            Array.Copy(buf, 0, newBuffer, len, count - len);
        }
        else Array.Copy(buf, offset, newBuffer, 0, count);
        buf = newBuffer;
        offset = 0;
        capacity <<= 1;
    }

    internal T[] Items//デバッグ時に中身を調べるためのプロパティ
    {
        get
        {
            T[] a = new T[count];
            for (int i = 0; i < count; i++)
                a[i] = this[i];
            return a;
        }
    }
}
#endregion

0