結果

問題 No.2209 Flip and Reverse
ユーザー tentententen
提出日時 2023-03-03 11:57:41
言語 Java21
(openjdk 21)
結果
AC  
実行時間 312 ms / 2,000 ms
コード長 2,030 bytes
コンパイル時間 2,514 ms
コンパイル使用メモリ 89,652 KB
実行使用メモリ 62,516 KB
最終ジャッジ日時 2023-10-18 00:54:03
合計ジャッジ時間 11,231 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
53,648 KB
testcase_01 AC 54 ms
53,632 KB
testcase_02 AC 53 ms
53,628 KB
testcase_03 AC 53 ms
53,648 KB
testcase_04 AC 54 ms
53,600 KB
testcase_05 AC 53 ms
53,640 KB
testcase_06 AC 55 ms
53,640 KB
testcase_07 AC 54 ms
53,640 KB
testcase_08 AC 247 ms
60,268 KB
testcase_09 AC 54 ms
52,536 KB
testcase_10 AC 54 ms
53,636 KB
testcase_11 AC 54 ms
53,640 KB
testcase_12 AC 54 ms
53,600 KB
testcase_13 AC 55 ms
53,640 KB
testcase_14 AC 294 ms
61,984 KB
testcase_15 AC 266 ms
62,412 KB
testcase_16 AC 294 ms
61,984 KB
testcase_17 AC 294 ms
62,380 KB
testcase_18 AC 246 ms
60,292 KB
testcase_19 AC 228 ms
59,708 KB
testcase_20 AC 307 ms
61,980 KB
testcase_21 AC 291 ms
62,516 KB
testcase_22 AC 312 ms
61,860 KB
testcase_23 AC 253 ms
59,812 KB
testcase_24 AC 258 ms
60,356 KB
testcase_25 AC 280 ms
61,740 KB
testcase_26 AC 257 ms
59,920 KB
testcase_27 AC 254 ms
60,260 KB
testcase_28 AC 292 ms
61,844 KB
testcase_29 AC 312 ms
61,808 KB
testcase_30 AC 244 ms
60,100 KB
testcase_31 AC 302 ms
62,200 KB
testcase_32 AC 238 ms
60,056 KB
testcase_33 AC 244 ms
60,324 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        String s = sc.next();
        String t = sc.next();
        int count = 0;
        for (int i = 0; i < n; i++) {
            if (s.charAt(i) != t.charAt(i)) {
                count++;
            }
        }
        if (count % 2 == 0) {
            System.out.println(count);
        } else {
            s = new StringBuilder(s).reverse().toString();
            count = 0;
            for (int i = 0; i < n; i++) {
                if (s.charAt(i) != t.charAt(i)) {
                    count++;
                }
            }
            System.out.println(count);
        }
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0