結果

問題 No.2209 Flip and Reverse
ユーザー maguroflymagurofly
提出日時 2023-02-10 23:25:51
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 1,229 bytes
コンパイル時間 369 ms
コンパイル使用メモリ 11,484 KB
実行使用メモリ 19,708 KB
最終ジャッジ日時 2023-09-22 00:28:34
合計ジャッジ時間 18,607 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
15,012 KB
testcase_01 AC 76 ms
15,208 KB
testcase_02 AC 76 ms
15,376 KB
testcase_03 AC 77 ms
15,272 KB
testcase_04 AC 76 ms
15,288 KB
testcase_05 AC 79 ms
15,012 KB
testcase_06 AC 76 ms
15,016 KB
testcase_07 AC 76 ms
15,208 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 77 ms
15,272 KB
testcase_11 WA -
testcase_12 AC 76 ms
15,340 KB
testcase_13 AC 77 ms
15,244 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 420 ms
19,484 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 418 ms
19,444 KB
testcase_22 AC 416 ms
19,608 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 413 ms
19,432 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 425 ms
19,424 KB
testcase_31 AC 394 ms
19,464 KB
testcase_32 AC 391 ms
19,356 KB
testcase_33 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
S = gets.chomp
T = gets.chomp

reversible_flip0 = 0 # 0 flip
reversible_flip1 = 0 # 1 flip
reversible_flip2 = 0 # 2 flip
irreversible_flip0 = 0 # 0 flip (non-reversed) or 2 flip (reversed)
irreversible_flip0_reverse = 0 # 2 flip (non-reversed) or 0 flip (reversed)
irreversible_flip1 = 0 # 1 flip

ans = 0

if S[N / 2] != T[N / 2]
    ans += 1
    N.times do |i|
        T[i] = T[i] == ?0 ? ?1 : ?0
    end
end

(N / 2).times do |i|
    j = N - 1 - i
    a, b, c, d = S[i], S[j], T[i], T[j]
    if c == d # reversible
        if a == c and b == d
            reversible_flip0 += 1
        elsif a != c and b != d
            reversible_flip2 += 1
        else
            reversible_flip1 += 1
        end
    else
        if a == c and b == d
            irreversible_flip0 += 1
        elsif a != c and b != d
            irreversible_flip0_reverse += 1
        else
            irreversible_flip1 += 1
        end
    end
end

flip = (reversible_flip1 + irreversible_flip1) % 2

if flip == 0
    ans += reversible_flip1 + 2 * reversible_flip2 + 2 * irreversible_flip0_reverse + irreversible_flip1
else
    ans += reversible_flip1 + 2 * reversible_flip2 + 2 * irreversible_flip0 + irreversible_flip1
end

puts ans
0