結果

問題 No.2240 WAC
ユーザー kusagame12kusagame12
提出日時 2023-11-05 18:17:52
言語 Java21
(openjdk 21)
結果
AC  
実行時間 310 ms / 2,000 ms
コード長 1,919 bytes
コンパイル時間 2,504 ms
コンパイル使用メモリ 77,648 KB
実行使用メモリ 60,496 KB
最終ジャッジ日時 2023-11-05 18:18:08
合計ジャッジ時間 14,778 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
57,552 KB
testcase_01 AC 125 ms
57,656 KB
testcase_02 AC 125 ms
57,472 KB
testcase_03 AC 125 ms
57,708 KB
testcase_04 AC 127 ms
57,440 KB
testcase_05 AC 127 ms
57,660 KB
testcase_06 AC 118 ms
56,328 KB
testcase_07 AC 134 ms
57,404 KB
testcase_08 AC 133 ms
57,524 KB
testcase_09 AC 128 ms
57,448 KB
testcase_10 AC 303 ms
60,496 KB
testcase_11 AC 268 ms
60,348 KB
testcase_12 AC 310 ms
60,336 KB
testcase_13 AC 219 ms
59,796 KB
testcase_14 AC 200 ms
57,864 KB
testcase_15 AC 270 ms
60,064 KB
testcase_16 AC 246 ms
59,908 KB
testcase_17 AC 229 ms
60,016 KB
testcase_18 AC 233 ms
57,948 KB
testcase_19 AC 214 ms
58,140 KB
testcase_20 AC 246 ms
59,896 KB
testcase_21 AC 220 ms
59,924 KB
testcase_22 AC 223 ms
59,952 KB
testcase_23 AC 236 ms
59,780 KB
testcase_24 AC 241 ms
59,948 KB
testcase_25 AC 233 ms
59,948 KB
testcase_26 AC 214 ms
57,828 KB
testcase_27 AC 205 ms
58,084 KB
testcase_28 AC 211 ms
57,800 KB
testcase_29 AC 186 ms
57,704 KB
testcase_30 AC 224 ms
59,868 KB
testcase_31 AC 256 ms
60,224 KB
testcase_32 AC 207 ms
57,792 KB
testcase_33 AC 225 ms
59,684 KB
testcase_34 AC 248 ms
60,000 KB
testcase_35 AC 159 ms
57,720 KB
testcase_36 AC 244 ms
59,848 KB
testcase_37 AC 246 ms
60,184 KB
testcase_38 AC 227 ms
57,908 KB
testcase_39 AC 307 ms
60,168 KB
testcase_40 AC 222 ms
59,752 KB
testcase_41 AC 231 ms
60,300 KB
testcase_42 AC 224 ms
59,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int m = sc.nextInt();
        char[] s = sc.next().toCharArray();
        
        int waCount = 0;
        int wCount = 0;
        boolean flag = false;
        for (int i = 0; i < s.length ; i++) {
            
            if(!flag && s[i] == 'W'){
                flag = true;
                continue;
            }
            if(flag && s[i] == 'W'){
                wCount++;
                continue;
            }
            if(flag && s[i] == 'A'){
                waCount++;
                flag = false;
                continue;
            }
             if(!flag && s[i] == 'A'){
                if(wCount > 0){
                    waCount++;
                }
                if(wCount > 0){
                    wCount--;
                }
                continue;
            }
            
        }
        
        int acCount = 0;
        int aCount = 0;
        flag = false;
        for (int i = 0; i < s.length ; i++) {
            
           if(!flag && s[i] == 'A'){
                flag = true;
                continue;
            }
            if(flag && s[i] == 'A'){
                aCount++;
                continue;
            }
            if(flag && s[i] == 'C'){
                acCount++;
                flag = false;
                continue;
            }
             if(!flag && s[i] == 'C'){
                if(aCount > 0){
                    acCount++;
                }
                if(aCount > 0){
                    aCount--;
                }
                continue;
             }
            
        }
        
        System.out.println((waCount + acCount == n + m && waCount == n && acCount == m) ? "Yes" : "No");
        
    }
}
0