結果

問題 No.2629 A replace B replace C
ユーザー AsahiAsahi
提出日時 2024-02-16 23:43:35
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 6,166 bytes
コンパイル時間 5,790 ms
コンパイル使用メモリ 80,476 KB
実行使用メモリ 61,628 KB
最終ジャッジ日時 2024-02-16 23:43:56
合計ジャッジ時間 15,916 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 180 ms
61,628 KB
testcase_01 AC 161 ms
59,492 KB
testcase_02 AC 156 ms
58,396 KB
testcase_03 AC 200 ms
60,472 KB
testcase_04 AC 127 ms
57,440 KB
testcase_05 AC 170 ms
59,340 KB
testcase_06 AC 153 ms
58,340 KB
testcase_07 AC 161 ms
59,504 KB
testcase_08 AC 178 ms
59,820 KB
testcase_09 AC 183 ms
58,344 KB
testcase_10 AC 178 ms
57,752 KB
testcase_11 AC 199 ms
58,468 KB
testcase_12 AC 180 ms
58,576 KB
testcase_13 AC 151 ms
58,344 KB
testcase_14 AC 176 ms
59,664 KB
testcase_15 AC 170 ms
59,340 KB
testcase_16 AC 156 ms
58,352 KB
testcase_17 AC 166 ms
58,416 KB
testcase_18 AC 181 ms
59,588 KB
testcase_19 AC 175 ms
57,500 KB
testcase_20 AC 160 ms
59,468 KB
testcase_21 AC 167 ms
58,344 KB
testcase_22 AC 173 ms
59,632 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 173 ms
59,596 KB
testcase_26 AC 187 ms
59,744 KB
testcase_27 AC 163 ms
58,396 KB
testcase_28 AC 158 ms
58,364 KB
testcase_29 WA -
testcase_30 AC 128 ms
57,184 KB
testcase_31 AC 197 ms
58,444 KB
testcase_32 AC 170 ms
58,572 KB
testcase_33 AC 199 ms
60,376 KB
testcase_34 AC 171 ms
59,712 KB
testcase_35 AC 170 ms
58,480 KB
testcase_36 AC 172 ms
58,488 KB
testcase_37 AC 192 ms
59,756 KB
testcase_38 AC 194 ms
58,572 KB
testcase_39 AC 167 ms
58,220 KB
testcase_40 AC 214 ms
58,552 KB
testcase_41 AC 153 ms
58,392 KB
testcase_42 AC 176 ms
57,504 KB
testcase_43 AC 155 ms
59,580 KB
testcase_44 AC 160 ms
59,600 KB
testcase_45 AC 185 ms
58,344 KB
testcase_46 AC 172 ms
58,452 KB
testcase_47 AC 181 ms
59,472 KB
testcase_48 AC 164 ms
59,516 KB
testcase_49 AC 151 ms
59,668 KB
testcase_50 AC 167 ms
56,528 KB
testcase_51 AC 154 ms
59,616 KB
testcase_52 AC 155 ms
58,244 KB
testcase_53 AC 130 ms
57,324 KB
testcase_54 AC 150 ms
57,188 KB
testcase_55 AC 163 ms
59,340 KB
testcase_56 AC 128 ms
57,192 KB
testcase_57 AC 153 ms
58,340 KB
testcase_58 AC 129 ms
55,248 KB
testcase_59 AC 171 ms
59,488 KB
testcase_60 AC 154 ms
58,344 KB
testcase_61 AC 119 ms
56,796 KB
testcase_62 AC 120 ms
57,840 KB
testcase_63 AC 135 ms
57,680 KB
testcase_64 AC 108 ms
56,820 KB
testcase_65 AC 112 ms
57,184 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

class Main implements Runnable {

    public void solve() {    
        int n = in.nextInt();
        String s = in.next() , t = in.next();
        int AtoC = 0 , BtoC = 0 , AtoB = 0 ;
        boolean valid = true ;
        for(int i = 0 ; i < n ; i ++) {
            if(s.charAt(i) == t.charAt(i)) continue;
            else if(s.charAt(i) == 'A') {
                if(t.charAt(i) == 'B') AtoB ++ ;
                else if(t.charAt(i) == 'C') AtoC ++ ;
            }
            else if(s.charAt(i) == 'B') {
                if(t.charAt(i) == 'C') BtoC ++ ;
                else if(t.charAt(i) == 'A') valid = false ;
            }
            else if(s.charAt(i) == 'C') {
                if(t.charAt(i) == 'A' || t.charAt(i) == 'B') valid = false; 
            }
        }
        if(!valid) {
            out.print(no);
            return;
        }
        int min = Math.min(AtoC , BtoC);
        AtoC = AtoC - min ;
        if((AtoC <= BtoC) && (AtoC <= AtoB)) {
            BtoC = BtoC - AtoC ;
            AtoB = AtoB - AtoC ;
            out.println(BtoC == AtoB ? yes : no);
        }
        else {
            out.println(no);
            return;
        }
    }

    
    /******/



    /******/
    
    public PrintWriter out = new PrintWriter(System.out);
    public In in = new In() ;
    public static final int  inf = (1  << 30);
    public static final long lnf = (1L << 60);
    public static final String yes = "Yes" , no  = "No" ;
    public static final int mod7 = 1000000007 , mod9 = 998244353;
    public static final int [] dy4 = {-1,0,1,0} , dx4 = {0,1,0,-1};
    public static final int [] dy8 = {-1,-1,-1,0,1,1,1,0} , dx8 = {-1,0,1,1,1,0,-1,-1};

    public static void main(String ... args) { new Thread(null, new Main(), "", Runtime.getRuntime().maxMemory()).start(); }
    public void run() { solve(); out.flush(); }

}

class In {

    private final InputStream in = System.in;
    private final Scanner sc = new Scanner(System.in);
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() { 
        if (hasNextByte()) return buffer[ptr++]; else return -1;
    }

    private static boolean isPrintableChar(int c) { 
        return 33 <= c && c <= 126;
    }

    private  boolean hasNext() { 
        while(hasNextByte() && !isPrintableChar(buffer[ptr])) {
            ptr++; 
        }
        return hasNextByte();
    }
    
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() { 
        return Double.parseDouble(next());
    }

    public char nextChar() {
        return next().charAt(0);
    }

    public BigInteger nextBigInteger() {
        return sc.nextBigInteger();
    }

    public int [] nextInt(int n) {
        int [] array = new int[n];
        for(int i = 0 ; i < n ; i ++) {
            array[i] = nextInt();
        }
        return array ;
    }

    public int [][] nextInt(int n , int m) {
        int [][] array = new int[n][m];
        for(int i = 0 ; i < n ; i ++) {
            array[i] = nextInt(m);
        }
        return array ;
    }

    public long [] nextLong(int n) {
        long [] array = new long[n];
        for(int i = 0 ; i < n ; i ++) {
            array[i] = nextLong();
        }
        return array ;
    }

    public long [][] nextLong(int n , int m) {
        long [][] array = new long[n][m];
        for(int i = 0 ; i < n ; i ++) {
            array[i] = nextLong(m);
        }
        return array ;
    }

    public double [] nextDouble(int n) {
        double [] array = new double[n];
        for(int i = 0 ; i < n ; i ++) {
            array[i] = nextDouble();
        }
        return array ;
    }
    
    public String [] next(int n) {
        String [] array = new String[n];
        for(int i = 0 ; i < n ; i ++) {
            array[i] = next();
        }
        return array ;
    }

    public String [][] next(int n , int m) {
        String [][] array = new String[n][m];
        for(int i = 0 ; i < n ; i ++) {
            array[i] = next(m);
        }
        return array ;
    }

    public char [] nextChar(int n) {
        char [] array = new char[n];
        String string = next() ;
        for(int i = 0 ; i < n ; i ++) {
            array[i] = string.charAt(i);
        }
        return array ;
    }

    public char [][] nextChar(int n , int m) {
        char [][] array = new char[n][m];
        for(int i = 0 ; i < n ; i ++) {
            array[i] = nextChar(m);
        }
        return array ;
    }

}
0