結果
問題 | No.2871 Universal Serial Bus |
ユーザー |
![]() |
提出日時 | 2024-09-06 21:29:23 |
言語 | Crystal (1.14.0) |
結果 |
AC
|
実行時間 | 10 ms / 2,000 ms |
コード長 | 558 bytes |
コンパイル時間 | 19,614 ms |
コンパイル使用メモリ | 340,248 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-06 21:29:44 |
合計ジャッジ時間 | 17,031 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 18 |
ソースコード
h, w = read_line.split.map(&.to_i) s = Array.new(h) { read_line.chars.map { |ch| ch == '#' } } t = Array.new(h) { read_line.chars.map { |ch| ch == '#' } } ok0 = h.times.all? { |i| w.times.all? { |j| s[i][j] != t[i][j] } } s.reverse! s.map! { |r| r.reverse } ok1 = h.times.all? { |i| w.times.all? { |j| s[i][j] != t[i][j] } } if !ok0 && !ok1 puts -1 exit end ans = 0.0 fail = 1.0 prob = 1.0 100000.times do |i| if [ok0, ok1][i % 2] ans += (i + 1) * (1.0 - fail) * prob prob -= prob * (1.0 - fail) end fail *= 0.5 end printf("%.9f\n", ans)