結果
問題 |
No.608 God's Maze
|
ユーザー |
|
提出日時 | 2017-12-08 01:48:08 |
言語 | Ruby (3.4.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,621 bytes |
コンパイル時間 | 67 ms |
コンパイル使用メモリ | 7,424 KB |
実行使用メモリ | 12,672 KB |
最終ジャッジ日時 | 2024-11-29 05:36:32 |
合計ジャッジ時間 | 11,753 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 55 WA * 10 |
コンパイルメッセージ
Syntax OK
ソースコード
n = gets.to_i - 1 s = gets.chomp m = s.size l = -1 n.times do |i| if s[i] == ?# l = i break end end r = -1 (m-1).downto(n+1) do |i| if s[i] == ?# r = i break end end ans = 1000000000 if l != -1 ans1 = 0 s1 = ?. * m l.upto(n-1) do |i| s1[i] = ?# ans1 += 1 end cnt = 0 m.times do |i| if s[i] != s1[i] cnt += 1 end end (l + 1).upto(m - 1) do |i| if cnt == 0 break end s1[i] = (s1[i] == ?. ? ?# : ?.) ans1 += 1 if s1[i] != s[i] ans1 += 2 s1[i] = s[i] s1[i + 1] = (s1[i + 1] == ?. ? ?# : ?.) if s1[i + 1] == s[i + 1] cnt -= 1 else cnt += 1 end else cnt -= 1 end end ans = [ans, ans1].min end if r != -1 ans2 = 0 s2 = ?. * m r.downto(n+1) do |i| s2[i] = ?# ans2 += 1 end cnt = 0 m.times do |i| if s[i] != s2[i] cnt += 1 end end (r - 1).downto(0) do |i| if cnt == 0 break end s2[i] = (s2[i] == ?. ? ?# : ?.) ans2 += 1 if s2[i] != s[i] ans2 += 2 s2[i] = s[i] s2[i - 1] = (s2[i - 1] == ?. ? ?# : ?.) if s2[i - 1] == s[i - 1] cnt -= 1 else cnt += 1 end else cnt -= 1 end end ans = [ans, ans2].min end if ans == 1000000000 ans = 3 end p ans