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

ARC124-A LR Constraints


問題へのリンク


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("3 2");
            WillReturn.Add("L 1");
            WillReturn.Add("R 2");
            //1
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("30 10");
            WillReturn.Add("R 6");
            WillReturn.Add("R 8");
            WillReturn.Add("R 7");
            WillReturn.Add("R 25");
            WillReturn.Add("L 26");
            WillReturn.Add("L 13");
            WillReturn.Add("R 14");
            WillReturn.Add("L 11");
            WillReturn.Add("L 23");
            WillReturn.Add("R 30");
            //343921442
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    const long Hou = 998244353;

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

        long N = wkArr[0];
        long K = wkArr[1];

        long UB = N;

        var NumSet = new HashSet<long>();
        for (long I = 1; I <= K; I++) {
            NumSet.Add(I);
        }

        var KouhoDict = new Dictionary<long, HashSet<long>>();
        for (long I = 1; I <= UB; I++) {
            KouhoDict[I] = new HashSet<long>();
            KouhoDict[I].UnionWith(NumSet);
        }

        long CurrNum = 1;
        foreach (string EachStr in InputList.Skip(1)) {
            string[] SplitArr = EachStr.Split(' ');
            if (SplitArr[0] == "L") {
                long CurrK = long.Parse(SplitArr[1]);
                for (long I = 1; I <= CurrK - 1; I++) {
                    KouhoDict[I].Remove(CurrNum);
                }
                KouhoDict[CurrK].IntersectWith(new long[] { CurrNum });
            }
            if (SplitArr[0] == "R") {
                long CurrK = long.Parse(SplitArr[1]);
                for (long I = CurrK + 1; I <= UB; I++) {
                    KouhoDict[I].Remove(CurrNum);
                }
                KouhoDict[CurrK].IntersectWith(new long[] { CurrNum });
            }
            CurrNum++;
        }

        long Answer = 1;
        foreach (var EachPair in KouhoDict) {
            Answer *= EachPair.Value.Count;
            Answer %= Hou;
        }
        Console.WriteLine(Answer);
    }
}


解説

制約が1000以下で緩いので、
各カードごとに候補の数値をHashSetで管理して、
最後に、積の法則を使ってます。