結果

問題 No.2240 WAC
ユーザー shoshoshom
提出日時 2023-03-10 22:18:28
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
RE  
実行時間 -
コード長 1,130 bytes
コンパイル時間 1,895 ms
コンパイル使用メモリ 196,048 KB
最終ジャッジ日時 2025-02-11 08:32:56
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 35 WA * 5 RE * 3
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:12:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   12 |     scanf("%d%d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~
main.cpp:13:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   13 |     scanf("%s", s);
      |     ~~~~~^~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

const int N = 400010;
char s[N];
bool used[N];

int main()
{
    int n, m;
    scanf("%d%d", &n, &m);
    scanf("%s", s);
    deque<int> w, c;
    int all = n + n + m + m;
    for (int i = 0; i < all; i++)
    {
        if (s[i] == 'W') w.push_back(i);
        if (s[i] == 'C') c.push_back(i);
    }
    bool ok = true;
    int i = 0, j = all - 1;
    while (ok && i < j)
    {
        if (used[i])
        {
            i++;
            continue;
        }
        if (used[j])
        {
            j--;
            continue;
        }
        char left = s[i], right = s[j];
        if (left == 'C' || right == 'W')
        {
            ok = false;
            break;
        }
        if (left == 'A')
        {
            ok &= c.front() > i;
            used[c.front()] = true;
            c.pop_front();
        }
        if (right == 'A')
        {
            ok &= w.back() < j;
            used[w.back()] = true;
            w.pop_back();
        }
        i++;
        j--;
    }

    if (ok)
        printf("Yes\n");
    else
        printf("No\n");

    return 0;
}
0