結果

問題 No.2240 WAC
ユーザー ushiroushiro
提出日時 2023-03-10 23:36:21
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 297 ms / 2,000 ms
コード長 8,574 bytes
コンパイル時間 7,144 ms
コンパイル使用メモリ 157,020 KB
実行使用メモリ 181,876 KB
最終ジャッジ日時 2023-10-18 09:15:07
合計ジャッジ時間 13,847 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
31,920 KB
testcase_01 AC 74 ms
31,920 KB
testcase_02 AC 73 ms
31,920 KB
testcase_03 AC 73 ms
31,920 KB
testcase_04 AC 73 ms
31,920 KB
testcase_05 AC 73 ms
31,920 KB
testcase_06 AC 74 ms
31,920 KB
testcase_07 AC 74 ms
31,912 KB
testcase_08 AC 73 ms
31,912 KB
testcase_09 AC 75 ms
31,912 KB
testcase_10 AC 297 ms
38,564 KB
testcase_11 AC 297 ms
37,912 KB
testcase_12 AC 198 ms
37,912 KB
testcase_13 AC 84 ms
34,956 KB
testcase_14 AC 107 ms
33,800 KB
testcase_15 AC 90 ms
36,880 KB
testcase_16 AC 247 ms
37,216 KB
testcase_17 AC 194 ms
35,716 KB
testcase_18 AC 117 ms
34,136 KB
testcase_19 AC 130 ms
34,324 KB
testcase_20 AC 91 ms
37,044 KB
testcase_21 AC 160 ms
35,304 KB
testcase_22 AC 85 ms
35,436 KB
testcase_23 AC 82 ms
34,924 KB
testcase_24 AC 90 ms
36,332 KB
testcase_25 AC 223 ms
36,260 KB
testcase_26 AC 134 ms
34,368 KB
testcase_27 AC 115 ms
34,108 KB
testcase_28 AC 84 ms
34,588 KB
testcase_29 AC 79 ms
33,600 KB
testcase_30 AC 86 ms
35,436 KB
testcase_31 AC 273 ms
37,840 KB
testcase_32 AC 114 ms
33,976 KB
testcase_33 AC 184 ms
35,688 KB
testcase_34 AC 207 ms
36,004 KB
testcase_35 AC 93 ms
33,508 KB
testcase_36 AC 221 ms
36,872 KB
testcase_37 AC 93 ms
37,644 KB
testcase_38 AC 83 ms
34,492 KB
testcase_39 AC 95 ms
37,948 KB
testcase_40 AC 173 ms
35,304 KB
testcase_41 AC 88 ms
36,064 KB
testcase_42 AC 88 ms
181,876 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (101 ms)。
MSBuild のバージョン 17.7.3+8ec440e68 (.NET)
/home/judge/data/code/Main.cs(23,16): warning CS0414: フィールド 'Program.mod' が割り当てられていますが、値は使用されていません [/home/judge/data/code/main.csproj]
/home/judge/data/code/Main.cs(17,17): warning CS0414: フィールド 'Program.inf' が割り当てられていますが、値は使用されていません [/home/judge/data/code/main.csproj]
/home/judge/data/code/Main.cs(22,19): warning CS0414: フィールド 'Program.alpha' が割り当てられていますが、値は使用されていません [/home/judge/data/code/main.csproj]
/home/judge/data/code/Main.cs(55,255): warning CA2200: キャッチされた例外が再スローされると、スタック情報が変更されます (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2200) [/home/judge/data/code/main.csproj]
  main -> /home/judge/data/code/bin/Release/net7.0/main.dll
  main -> /home/judge/data/code/bin/Release/net7.0/publish/

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

class Program
{
    #region library
    static int n = 0;
    static int r = 0;
    static int c = 0;
    static string s = "";
    static long sum = 0;
    static long cnt = 0;
    static long max = long.MinValue;
    static long min = long.MaxValue;
    static long inf = long.MaxValue / 2;
    static bool flg = false;
    static long[] arr;
    static char[,] map;
    static long[,] imap;
    static string alpha = "abcdefghijklmnopqrstuvwxyz";
    static int mod = 1000000007;

    public class Input { static readonly char[] separator = { ' ', '\r', '\n' }; readonly StreamReader sr; readonly Queue<string> queue; public Input(string path = "") { queue = new Queue<string>(); if (string.IsNullOrEmpty(path)) { sr = new StreamReader(Console.OpenStandardInput()); } else { sr = new StreamReader(path); } } public void SetText(IEnumerable<string> items) { foreach (var item in items) { SetText(item); } } public bool SetText(string s) { if (s == null) return false; foreach (var elem in s.Trim().Split(separator, StringSplitOptions.RemoveEmptyEntries)) { queue.Enqueue(elem); } return true; } public bool Any() { return queue.Any() || Read(); } bool Read() { if (!SetText(sr.ReadLine())) return false; if (!queue.Any()) return Read(); return queue.Any(); } public string Next() { if (!queue.Any() && !Read()) { return ""; } return queue.Dequeue(); } bool Accumulate(int n) { while (queue.Count() < n) { if (!Read()) return false; } return true; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } T[] NextT<T>(int n, T offset, Func<string, T> parse, Func<T, T, T> add) { if (!Accumulate(n)) return null; var a = new T[n]; for (int i = 0; i < n; i++) a[i] = add(parse(queue.Dequeue()), offset); return a; } public string[] Next(int n) { return NextT(n, "", x => x, (x, y) => x); } public int[] NextInt(int n, int offset = 0) { return NextT(n, offset, int.Parse, (x, y) => x + y); } public long[] NextLong(int n, long offset = 0) { return NextT(n, offset, long.Parse, (x, y) => x + y); } public double[] NextDouble(int n, double offset = 0.0) { return NextT(n, offset, double.Parse, (x, y) => x + y); } }
    static Input input;
    static int Int() { return input.NextInt(); }
    static long Long() { return input.NextLong(); }
    static double Double() { return input.NextDouble(); }
    static string Text() { return input.Next(); }
    static void wl(object obj = null) { Console.WriteLine(obj); }
    static void w(object obj) { Console.Write(obj); }
    static void YES() { wl("YES"); }
    static void NO() { wl("NO"); }
    static void YN(bool b) { if (b) YES(); else NO(); }
    static void Yes() { wl("Yes"); }
    static void No() { wl("No"); }
    static void yn(bool b) { if (b) Yes(); else No(); }
    static void Sum() { wl(sum); }
    static void Cnt() { wl(cnt); }
    static void Max() { wl(max); }
    static void Min() { wl(min); }
    static void swap<T>(ref T a, ref T b) { var w = a; a = b; b = w; }
    static void SetArray(long[] array = null) { if (array != null) { for (int i = 0; i < array.Length; i++) { array[i] = Long(); } } else { if (n == 0) { n = Int(); } arr = new long[n]; for (int i = 0; i < n; i++) { arr[i] = Long(); } } }
    static void ShowArray(long[] array = null) { if (array != null) { wl(string.Join(" ", array)); } else if (arr != null) { wl(string.Join(" ", arr)); } }
    static void CompressArray() { var list = arr.ToList(); list = list.OrderBy(x => x).ToList(); var dic = new Dictionary<long, long>(); var cnt = 0; for (int i = 0; i < list.Count; i++) { if (!dic.ContainsKey(list[i])) { dic.Add(list[i], cnt); cnt++; } } var arr2 = new long[arr.Length]; for (int i = 0; i < arr.Length; i++) { arr2[i] = dic[arr[i]]; } arr = arr2; }
    static void SetMap(char[,] map2 = null) { if (r == 0 && c == 0) { r = Int(); c = Int(); } if (map2 != null) { for (int i = 0; i < r; i++) { s = Text(); for (int j = 0; j < c; j++) { map2[i, j] = s[j]; } } } else { map = new char[r, c]; for (int i = 0; i < r; i++) { s = Text(); for (int j = 0; j < c; j++) { map[i, j] = s[j]; } } } }
    static void RotateMap() { var map2 = new char[c, r]; for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { map2[j, r - i - 1] = map[i, j]; } } map = map2; }
    static void SetIMap(long[,] imap2 = null) { if (r == 0 && c == 0) { r = Int(); c = Int(); } if (imap2 != null) { for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { imap2[i, j] = Long(); } } } else { imap = new long[r, c]; for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { imap[i, j] = Long(); } } } }
    static void ShowMap(char[,] map2 = null) { for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { if (map2 != null) w(map2[i, j] + " "); else w(map[i, j] + " "); } wl(); } }
    static void ShowIMap(long[,] imap2 = null) { for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { if (imap2 != null) w(imap2[i, j] + " "); else w(imap[i, j] + " "); } wl(); } }
    #endregion

    #region main
    static void Main(string[] args) { var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; Console.SetOut(sw); input = new Input(); try { Solve(); } catch (Exception ex) { wl(ex); if (!(args.Length >= 1 && args[0] == "/debug")) throw ex; } Console.Out.Flush(); }
    public static void Solve()
    {
        n = Int();
        var m = Int();
        s = Text();

        var qw = new PriorityQueue<int>();
        var qa = new PriorityQueue<int>();
        var qc = new PriorityQueue<int>();
        for (int i = 0; i < s.Length; i++)
        {
            if (s[i] == 'W') qw.Enqueue(i);
            if (s[i] == 'A') qa.Enqueue(i);
            if (s[i] == 'C') qc.Enqueue(i);
        }

        flg = true;
        while (qw.Count > 0 || qa.Count > 0 || qc.Count > 0)
        {
            if (qc.Count > 0)
            {
                if (qa.Peek() < qc.Peek())
                {
                    qa.Dequeue();
                    qc.Dequeue();
                }
                else
                {
                    flg = false;
                }
            }
            else
            {
                if (qw.Peek() < qa.Peek())
                {
                    qw.Dequeue();
                    qa.Dequeue();
                }
                else
                {
                    flg = false;
                }
            }

            if (!flg) break;
        }

        yn(flg);
    }
    #endregion

    #region priorityqueue
    public class PriorityQueue<T>
    {
        private List<T> heap;
        private readonly Comparison<T> compare;

        public PriorityQueue() : this(Comparer<T>.Default)
        {
        }

        public PriorityQueue(IComparer<T> comparer) : this(comparer.Compare)
        {
        }

        public PriorityQueue(Comparison<T> comparison)
        {
            heap = new List<T>();
            compare = comparison;
        }

        public int Count => heap.Count;

        public void Enqueue(T item)
        {
            heap.Add(item);
            var i = Count - 1;
            while (i > 0)
            {
                var p = (i - 1) / 2;
                if (compare(heap[p], item) <= 0)
                {
                    break;
                }
                heap[i] = heap[p];
                i = p;
            }
            heap[i] = item;
        }

        public T Dequeue()
        {
            var ret = heap[0];
            var last = heap[Count - 1];
            heap.RemoveAt(Count - 1);
            if (Count > 0)
            {
                var i = 0;
                while (i * 2 + 1 < Count)
                {
                    var left = i * 2 + 1;
                    var right = i * 2 + 2;
                    if (right < Count && compare(heap[right], heap[left]) < 0)
                    {
                        left = right;
                    }
                    if (compare(heap[left], last) >= 0)
                    {
                        break;
                    }
                    heap[i] = heap[left];
                    i = left;
                }
                heap[i] = last;
            }
            return ret;
        }

        public T Peek()
        {
            return heap[0];
        }

        public bool Any()
        {
            return heap.Count > 0;
        }

        public void Clear()
        {
            heap.Clear();
        }
    }

    #endregion


}
0