結果

問題 No.2209 Flip and Reverse
ユーザー tentententen
提出日時 2023-08-08 18:13:40
言語 Java21
(openjdk 21)
結果
AC  
実行時間 309 ms / 2,000 ms
コード長 2,009 bytes
コンパイル時間 3,029 ms
コンパイル使用メモリ 95,292 KB
実行使用メモリ 48,424 KB
最終ジャッジ日時 2024-04-26 10:42:33
合計ジャッジ時間 10,891 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
37,096 KB
testcase_01 AC 49 ms
36,940 KB
testcase_02 AC 48 ms
37,180 KB
testcase_03 AC 50 ms
37,088 KB
testcase_04 AC 49 ms
36,812 KB
testcase_05 AC 50 ms
37,136 KB
testcase_06 AC 49 ms
36,844 KB
testcase_07 AC 50 ms
36,680 KB
testcase_08 AC 283 ms
46,712 KB
testcase_09 AC 47 ms
36,676 KB
testcase_10 AC 46 ms
37,052 KB
testcase_11 AC 47 ms
37,116 KB
testcase_12 AC 46 ms
37,128 KB
testcase_13 AC 48 ms
36,752 KB
testcase_14 AC 261 ms
48,016 KB
testcase_15 AC 309 ms
48,280 KB
testcase_16 AC 244 ms
48,064 KB
testcase_17 AC 288 ms
48,348 KB
testcase_18 AC 268 ms
47,240 KB
testcase_19 AC 227 ms
47,432 KB
testcase_20 AC 267 ms
48,248 KB
testcase_21 AC 283 ms
48,340 KB
testcase_22 AC 295 ms
48,140 KB
testcase_23 AC 279 ms
46,996 KB
testcase_24 AC 234 ms
47,276 KB
testcase_25 AC 293 ms
47,840 KB
testcase_26 AC 308 ms
47,264 KB
testcase_27 AC 254 ms
47,176 KB
testcase_28 AC 295 ms
47,952 KB
testcase_29 AC 283 ms
48,424 KB
testcase_30 AC 264 ms
47,332 KB
testcase_31 AC 292 ms
47,684 KB
testcase_32 AC 267 ms
47,440 KB
testcase_33 AC 236 ms
47,180 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 sSum = 0;
        for (char c : s.toCharArray()) {
            sSum += c - '0';
        }
        int tSum = 0;
        for (char c : t.toCharArray()) {
            tSum += c - '0';
        }
        if (Math.abs(sSum - tSum) % 2 == 1) {
            t = new StringBuilder(t).reverse().toString();
        }
        int ans = 0;
        for (int i = 0; i < n; i++) {
            if (s.charAt(i) != t.charAt(i)) {
                ans++;
            }
        }
        System.out.println(ans);
    }
} 
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