AtCoderのARC    次のARCの問題へ    前のARCの問題へ

ARC180-A ABA and BAB


問題へのリンク


C#のソース

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");
            WillReturn.Add("ABAB");
            //2
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("1");
            WillReturn.Add("A");
            //1
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("17");
            WillReturn.Add("BBABABAABABAAAABA");
            //18
        }
        else if (InputPattern == "Input4") {
            WillReturn.Add("100");
            WillReturn.Add("ABAABAABABBABAABAABAABABBABBABBABBABBABBABBABBABBABBABBABBABBABBABAABABAABABBABBABABBABAABAABAABAABA");
            //415919090
        }
        else if (InputPattern == "Input5") {
            WillReturn.Add("999");
            WillReturn.Add("ABAABABBBABAB");
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    const long Hou = 1000000000 + 7;

    static void Main()
    {
        List<string> InputList = GetInputList();
        char[] CharArr = InputList[1].ToCharArray();
        long UB = CharArr.GetUpperBound(0);

        var CharArrList = new List<char[]>();

        var CurrList = new List<char>();
        for (long I = 0; I <= UB; I++) {
            CurrList.Add(CharArr[I]);
            if (I == UB || CharArr[I] == CharArr[I + 1]) {
                CharArrList.Add(CurrList.ToArray());
                CurrList.Clear();
            }
        }

        long Answer = 1;
        foreach (char[] EachArr in CharArrList) {
            long CurrPattern = (EachArr.Length + 1) / 2;
            Answer *= CurrPattern;
            Answer %= Hou;
        }
        Console.WriteLine(Answer);
    }
}


解説

ABA ABAB B BABAB
で考えると同じ文字が連続した箇所は
変換で接続することができないです。

なので
各部分ごとに、((文字数+1) / 2))通りあるので、
積の法則を使えば良いです。