結果
| 問題 |
No.2209 Flip and Reverse
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-02-10 23:25:51 |
| 言語 | Ruby (3.4.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,229 bytes |
| コンパイル時間 | 378 ms |
| コンパイル使用メモリ | 7,552 KB |
| 実行使用メモリ | 16,512 KB |
| 最終ジャッジ日時 | 2024-07-07 17:23:24 |
| 合計ジャッジ時間 | 18,355 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 14 WA * 16 |
コンパイルメッセージ
Syntax OK
ソースコード
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