結果

問題 No.1021 Children in Classrooms
ユーザー bluemeganebluemegane
提出日時 2021-04-23 16:36:18
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 178 ms / 2,000 ms
コード長 3,751 bytes
コンパイル時間 1,424 ms
コンパイル使用メモリ 67,720 KB
実行使用メモリ 44,480 KB
最終ジャッジ日時 2023-09-17 11:10:35
合計ジャッジ時間 4,707 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
22,760 KB
testcase_01 AC 61 ms
20,920 KB
testcase_02 AC 60 ms
20,760 KB
testcase_03 AC 68 ms
20,868 KB
testcase_04 AC 70 ms
23,056 KB
testcase_05 AC 68 ms
21,024 KB
testcase_06 AC 69 ms
20,968 KB
testcase_07 AC 68 ms
23,124 KB
testcase_08 AC 69 ms
21,148 KB
testcase_09 AC 178 ms
44,308 KB
testcase_10 AC 176 ms
42,356 KB
testcase_11 AC 177 ms
44,400 KB
testcase_12 AC 176 ms
44,404 KB
testcase_13 AC 172 ms
44,480 KB
testcase_14 AC 174 ms
42,324 KB
testcase_15 AC 143 ms
41,848 KB
testcase_16 AC 143 ms
39,880 KB
testcase_17 AC 149 ms
42,040 KB
testcase_18 AC 168 ms
43,328 KB
testcase_19 AC 69 ms
22,884 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System.Collections.Generic;
using System;

public class Deque<T>
{
    T[] buf;
    int offset, count, capacity;
    public int Count { get { return count; } }
    public Deque(int cap) { buf = new T[capacity = cap]; }
    public Deque() { buf = new T[capacity = 16]; }

    public T[] Items
    {
        get
        {
            var a = new T[count];
            for (int i = 0; i < count; i++) a[i] = this[i];
            return a;
        }
    }

    public void Init()
    {
        count = 0;
    }

    public 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");
        var ret = index + offset;
        if (ret >= capacity)
            ret -= capacity;
        return ret;
    }
    public void PushFront(T item)
    {
        if (count == capacity) Extend();
        if (--offset < 0) offset += buf.Length;
        buf[offset] = item;
        ++count;
    }
    public T PopFront()
    {
        if (count == 0)
            throw new InvalidOperationException("collection is empty");
        --count;
        var ret = buf[offset++];
        if (offset >= capacity) offset -= capacity;
        return ret;
    }
    public void PushBack(T item)
    {
        if (count == capacity) Extend();
        var id = count++ + offset;
        if (id >= capacity) id -= capacity;
        buf[id] = item;
    }
    public T PopBack()
    {
        if (count == 0)
            throw new InvalidOperationException("collection is empty");
        return buf[getIndex(--count)];
    }
    public 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;
    }
    public T RemoveAt(int index)
    {
        if (index < 0 || index >= count) throw new IndexOutOfRangeException();
        var 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)
        {
            var 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;
    }
}

public class Hello
{
    static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var m = int.Parse(line[1]);
        line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        var s = Console.ReadLine().Trim();
        getAns(n, m, a, s);
    }
    static void getAns (int n, int m, int[] a, string s)
    {
        var dq = new Deque<int>(n);
        for (int i = 0; i < n; i++) dq.PushBack(a[i]);
        foreach(var x in s)
        {
            if (x == 'L')
            {
                var t = dq.PopFront();
                t += dq.PopFront();
                dq.PushFront(t);
                dq.PushBack(0);
            }
            else
            {
                var t = dq.PopBack();
                t += dq.PopBack();
                dq.PushBack(t);
                dq.PushFront(0);
            }
        }
        var ans = new List<int>();
        for (int i = 0; i < n; i++) ans.Add(dq.PopFront());
        Console.WriteLine(string.Join(" ",ans));
    }
}
0