結果

問題 No.2629 A replace B replace C
ユーザー tentententen
提出日時 2024-02-21 15:27:18
言語 Java21
(openjdk 21)
結果
AC  
実行時間 139 ms / 2,000 ms
コード長 1,822 bytes
コンパイル時間 6,671 ms
コンパイル使用メモリ 77,880 KB
実行使用メモリ 57,780 KB
最終ジャッジ日時 2024-02-21 15:27:35
合計ジャッジ時間 16,863 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 139 ms
57,780 KB
testcase_01 AC 105 ms
55,520 KB
testcase_02 AC 97 ms
55,656 KB
testcase_03 AC 124 ms
57,640 KB
testcase_04 AC 71 ms
54,504 KB
testcase_05 AC 105 ms
55,264 KB
testcase_06 AC 103 ms
55,656 KB
testcase_07 AC 99 ms
55,644 KB
testcase_08 AC 115 ms
55,400 KB
testcase_09 AC 118 ms
55,536 KB
testcase_10 AC 98 ms
55,384 KB
testcase_11 AC 118 ms
55,384 KB
testcase_12 AC 115 ms
55,652 KB
testcase_13 AC 96 ms
55,400 KB
testcase_14 AC 113 ms
53,444 KB
testcase_15 AC 106 ms
55,504 KB
testcase_16 AC 103 ms
55,564 KB
testcase_17 AC 110 ms
55,272 KB
testcase_18 AC 101 ms
55,396 KB
testcase_19 AC 99 ms
55,388 KB
testcase_20 AC 105 ms
55,412 KB
testcase_21 AC 116 ms
55,640 KB
testcase_22 AC 98 ms
55,648 KB
testcase_23 AC 117 ms
55,400 KB
testcase_24 AC 113 ms
55,652 KB
testcase_25 AC 121 ms
55,516 KB
testcase_26 AC 110 ms
53,704 KB
testcase_27 AC 110 ms
55,640 KB
testcase_28 AC 105 ms
55,648 KB
testcase_29 AC 106 ms
55,652 KB
testcase_30 AC 89 ms
55,520 KB
testcase_31 AC 104 ms
55,656 KB
testcase_32 AC 103 ms
55,640 KB
testcase_33 AC 121 ms
57,688 KB
testcase_34 AC 95 ms
55,272 KB
testcase_35 AC 102 ms
55,536 KB
testcase_36 AC 116 ms
55,644 KB
testcase_37 AC 116 ms
55,660 KB
testcase_38 AC 115 ms
55,648 KB
testcase_39 AC 97 ms
55,404 KB
testcase_40 AC 113 ms
55,532 KB
testcase_41 AC 97 ms
55,512 KB
testcase_42 AC 115 ms
55,516 KB
testcase_43 AC 109 ms
55,628 KB
testcase_44 AC 109 ms
55,640 KB
testcase_45 AC 114 ms
55,652 KB
testcase_46 AC 119 ms
55,636 KB
testcase_47 AC 114 ms
55,548 KB
testcase_48 AC 109 ms
55,648 KB
testcase_49 AC 99 ms
55,512 KB
testcase_50 AC 108 ms
55,660 KB
testcase_51 AC 110 ms
55,512 KB
testcase_52 AC 112 ms
55,296 KB
testcase_53 AC 93 ms
55,272 KB
testcase_54 AC 98 ms
55,528 KB
testcase_55 AC 101 ms
55,648 KB
testcase_56 AC 93 ms
55,400 KB
testcase_57 AC 114 ms
55,512 KB
testcase_58 AC 88 ms
55,644 KB
testcase_59 AC 123 ms
55,660 KB
testcase_60 AC 109 ms
55,652 KB
testcase_61 AC 54 ms
53,992 KB
testcase_62 AC 54 ms
53,964 KB
testcase_63 AC 55 ms
53,992 KB
testcase_64 AC 54 ms
53,980 KB
testcase_65 AC 54 ms
53,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;

public class Main {
    static List<Set<Integer>> graph;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        char[] s = sc.next().toCharArray();
        char[] t = sc.next().toCharArray();
        int ab = 0;
        int ac = 0;
        int bc = 0;
        for (int i = 0; i < n; i++) {
            if (s[i] == t[i]) {
                continue;
            }
            if (s[i] == 'A') {
                if (t[i] == 'B') {
                    ab++;
                } else {
                    ac++;
                }
            } else if (s[i] == 'B' && t[i] == 'C') {
                bc++;
            } else {
                System.out.println("No");
                return;
            }
        }
        System.out.println((ac > 0 && bc == 0) || bc != ab ? "No" : "Yes");
    }
}
class Scanner {
    BufferedReader br;
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
        } catch (Exception e) {
            
        }
    }
    
    public int nextInt() {
        return Integer.parseInt(next());
    }
    
    public long nextLong() {
        return Long.parseLong(next());
    }
    
    public double nextDouble() {
        return Double.parseDouble(next());
    }
    
    public String next() {
        try {
            while (!st.hasMoreTokens()) {
                st = new StringTokenizer(br.readLine());
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            return st.nextToken();
        }
    }
    
}
0