結果

問題 No.38 赤青白ブロック
ユーザー nuwasoginuwasogi
提出日時 2015-11-30 19:03:36
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 809 ms / 5,000 ms
コード長 4,843 bytes
コンパイル時間 2,603 ms
コンパイル使用メモリ 111,768 KB
実行使用メモリ 23,932 KB
最終ジャッジ日時 2023-08-25 01:10:24
合計ジャッジ時間 10,202 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
21,824 KB
testcase_01 AC 439 ms
23,852 KB
testcase_02 AC 186 ms
23,892 KB
testcase_03 AC 149 ms
23,804 KB
testcase_04 AC 283 ms
23,896 KB
testcase_05 AC 62 ms
23,808 KB
testcase_06 AC 530 ms
19,812 KB
testcase_07 AC 270 ms
21,736 KB
testcase_08 AC 62 ms
23,828 KB
testcase_09 AC 534 ms
21,788 KB
testcase_10 AC 61 ms
21,748 KB
testcase_11 AC 62 ms
21,792 KB
testcase_12 AC 62 ms
21,928 KB
testcase_13 AC 61 ms
23,932 KB
testcase_14 AC 61 ms
21,988 KB
testcase_15 AC 192 ms
23,808 KB
testcase_16 AC 385 ms
21,780 KB
testcase_17 AC 369 ms
19,772 KB
testcase_18 AC 109 ms
21,748 KB
testcase_19 AC 238 ms
23,872 KB
testcase_20 AC 298 ms
21,704 KB
testcase_21 AC 281 ms
19,948 KB
testcase_22 AC 809 ms
21,828 KB
testcase_23 AC 66 ms
21,824 KB
testcase_24 AC 444 ms
21,696 KB
testcase_25 AC 123 ms
21,796 KB
testcase_26 AC 145 ms
21,876 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;

namespace RBW_Block_CS
{
    class Program
    {
        static void Main(string[] args)
        {
            Solver sol = new Solver();
            sol.Solve();
        }
    }
    class Solver
    {
        Blocks block;
        int ans = 10;

        public void Solve()
        {
            set(0);
            Console.WriteLine(ans);
        }

        public Solver()
        {
            int[] krb = ria();
            string S = rs();
            block = new Blocks(krb[0], krb[1], S);
        }
        /* blockからindex i(target<=i)を取り除いてできる(条件を満たす)ブロック列のうち、最も長いもののLengthをansに格納する. */
        void set(int target)
        {
            if (block.isSatisfied)
            {
                ans = Math.Max(ans, block.Length);
                return;
            }
            else if (target == block.Length)
            {
                return;
            }
            for (int i = target; i < block.Length; i++)
            {
                if (block[i] == Blocks.Color.Blue || block[i] == Blocks.Color.Red)
                {
                    /* データを更新 */
                    Blocks.Color mycb = block.Remove(i);
                    set(i);
                    /* 元に戻す */
                    block.Insert(i, mycb);
                }
            }
        }

        static String rs() { return Console.ReadLine(); }
        static int ri() { return int.Parse(Console.ReadLine()); }
        static long rl() { return long.Parse(Console.ReadLine()); }
        static double rd() { return double.Parse(Console.ReadLine()); }
        static String[] rsa() { return Console.ReadLine().Split(' '); }
        static int[] ria() { return Console.ReadLine().Split(' ').Select(e => int.Parse(e)).ToArray(); }
        static long[] rla() { return Console.ReadLine().Split(' ').Select(e => long.Parse(e)).ToArray(); }
        static double[] rda() { return Console.ReadLine().Split(' ').Select(e => double.Parse(e)).ToArray(); }
    }

    class Blocks
    {
        public enum Color : byte { None = 0x00, Red = 0x01, Blue = 0x02, White = 0x04 };
        public Color this[int index]
        {
            get
            {
                if (index < 0 || _blockColumn.Count() <= index) return Color.None;
                else return _blockColumn[index];
            }
        }
        public int Length
        {
            get
            {
                return _blockColumn.Count();
            }
        }
        /* すべてのブロックが条件を満たしていればtrueを返す */
        public bool isSatisfied
        {
            get
            {
                for (int i = 0; i < this.Length; i++)
                {
                    if (!isSatisfy(i)) return false;
                }
                return true;
            }
        }
        List<Color> _blockColumn;
        static int Kr, Kb;
        public Blocks(int kr, int kb, string s)
        {
            Kr = kr;
            Kb = kb;

            Func<char, Color> recCol = c =>
             {
                 switch (c)
                 {
                     case 'R':
                         return Color.Red;
                     case 'B':
                         return Color.Blue;
                     case 'W':
                         return Color.White;
                     default:
                         throw new Exception("Color Error");
                 }
             };
            _blockColumn = new List<Color>(30);
            for (int i = 0; i < s.Length; i++)
            {
                _blockColumn.Add(recCol(s[i]));
            }
        }
        public Blocks(Blocks B)
        {
            for (int i = 0; i < B.Length; i++)
            {
                _blockColumn.Add(B[i]);
            }
        }
        /* index iのブロックが条件を満たしていればtrueを返す */
        public bool isSatisfy(int i)
        {
            switch (_blockColumn[i])
            {
                case Color.Red:
                    return (((this[i - Kr] | this[i + Kr]) & Color.Red) != Color.Red);
                case Color.Blue:
                    return (((this[i - Kb] | this[i + Kb]) & Color.Blue) != Color.Blue);
                case Color.White:
                    return true;
                default:
                    return false;
            }
        }
        /* index iのブロックを取り除く.取り除いたブロックの色を返す */
        public Color Remove(int i)
        {
            Color c = _blockColumn[i];
            _blockColumn.RemoveAt(i);
            return c;
        }
        public void Insert(int i, Color c)
        {
            _blockColumn.Insert(i, c);
        }
    }
}
0