結果

問題 No.323 yuki国
ユーザー LeonardoneLeonardone
提出日時 2015-12-16 23:04:53
言語 Ruby
(3.3.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 6,304 bytes
コンパイル時間 61 ms
コンパイル使用メモリ 11,604 KB
実行使用メモリ 15,664 KB
最終ジャッジ日時 2023-10-14 11:08:59
合計ジャッジ時間 4,643 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
15,196 KB
testcase_01 AC 81 ms
15,300 KB
testcase_02 AC 80 ms
15,324 KB
testcase_03 AC 81 ms
15,152 KB
testcase_04 AC 79 ms
15,212 KB
testcase_05 AC 75 ms
15,264 KB
testcase_06 AC 77 ms
15,272 KB
testcase_07 AC 80 ms
15,248 KB
testcase_08 AC 80 ms
15,200 KB
testcase_09 AC 83 ms
15,640 KB
testcase_10 AC 76 ms
15,324 KB
testcase_11 AC 79 ms
15,320 KB
testcase_12 AC 80 ms
15,332 KB
testcase_13 AC 87 ms
15,440 KB
testcase_14 AC 79 ms
15,088 KB
testcase_15 AC 111 ms
15,664 KB
testcase_16 AC 89 ms
15,524 KB
testcase_17 AC 100 ms
15,596 KB
testcase_18 AC 85 ms
15,368 KB
testcase_19 AC 79 ms
15,188 KB
testcase_20 AC 87 ms
15,636 KB
testcase_21 AC 78 ms
15,072 KB
testcase_22 AC 86 ms
15,440 KB
testcase_23 AC 76 ms
15,336 KB
testcase_24 AC 88 ms
15,360 KB
testcase_25 AC 77 ms
15,252 KB
testcase_26 AC 89 ms
15,532 KB
testcase_27 AC 77 ms
15,344 KB
testcase_28 AC 82 ms
15,576 KB
testcase_29 AC 85 ms
15,556 KB
testcase_30 WA -
testcase_31 AC 79 ms
15,348 KB
testcase_32 WA -
testcase_33 AC 80 ms
15,176 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 78 ms
15,176 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:61: warning: mismatched indentations at 'elsif' with 'if' at 56
Main.rb:64: warning: mismatched indentations at 'end' with 'if' at 56
Main.rb:122: warning: assigned but unused variable - flagM
Syntax OK

ソースコード

diff #

#! ruby
# yukicoder My Practice
# author: Leonardone @ NEETSDKASU

def gs() gets.chomp end
def gi() gets.to_i end
def gss() gets.chomp.split end
def gis() gss.map(&:to_i) end
def nmapf(n,f) n.times.map{ __send__ f } end
def arr2d(h,w,v=0) h.times.map{[v] * w} end
def ngs(n) nmapf n,:gs end
def ngi(n) nmapf n,:gi end
def ngss(n) nmapf n,:gss end
def ngis(n) nmapf n,:gis end
def for2p(hr,wr,&pr) hr.each{|i|wr.each{|j|pr.call(i,j)}} end


H, W = gis
A, Si, Sj = Start = gis
B, Gi, Gj = Goal = gis

$M = ngs H

AnsYes = 'Yes'
AnsNo = 'No'
$PCh = '*'
$MCh = '.'

l = (Si - Gi).abs + (Sj - Gj).abs


if l.even? && (A.even? != B.even?)
    puts AnsNo
    # ここの正解も偶然ぽい
    # マスは1個移動ごとに偶奇が入れ替わるので到達無理を想定したが
    # よくわからなくなった
    exit
end

if l.odd? && (A.even? == B.even?)
    puts AnsNo
    # ここの正解も偶然ぽい
    # マスは1個移動ごとに偶奇が入れ替わるので到達無理を想定したが
    # よくわからなくなった
    exit
end


# スタート地点から雪球の無限増大なしに到達可能な範囲を調べる
$minus = arr2d H,W # 到達可能なマイナスマス
$plus = arr2d H,W  # 到達可能なプラスマス

$minus[Si][Sj] = A

def chk(rch2, c, y2, x2)
   if $M[y2][x2] == $PCh
        if $plus[y2][x2] == 0
            rch2 << [c + 1, y2, x2]
            $plus[y2][x2] = 1
        end
    elsif c > 1 && $minus[y2][x2] < c - 1
        rch2 << [c - 1, y2, x2]
        $minus[y2][x2] = c - 1
    end
end

rch1 = [Start]
while !rch1.empty?
    rch2 = []
    rch1.each do |c,y,x|
        chk rch2, c, y, x - 1 if x > 0
        chk rch2, c, y - 1, x if y > 0
        chk rch2, c, y, x + 1 if x + 1 < W
        chk rch2, c, y + 1, x if y + 1 < H
    end
    rch1 = rch2
end

# ゴール地点周辺のプラスマスの分布をチェックする
$grch = arr2d H, W
def chkGrch(rch2, c, y2, x2)
    if $M[y2][x2] == $PCh
        if $grch[y2][x2] == 0 || $grch[y2][x2] > c + 1
            $grch[y2][x2] = c + 1
            rch2 << [c + 1, y2, x2]
        end
    elsif $grch[y2][x2] == 0 || $grch[y2][x2] > - (c + 1)
        $grch[y2][x2] = - (c + 1)
    end
end

rch1 = [[0, Gi, Gj]]
while !rch1.empty?
    rch2 = []
    rch1.each do |c,y,x|
        chkGrch rch2, c, y, x - 1 if x > 0
        chkGrch rch2, c, y - 1, x if y > 0
        chkGrch rch2, c, y, x + 1 if x + 1 < W
        chkGrch rch2, c, y + 1, x if y + 1 < H
    end
    rch1 = rch2
end

# ゴール周辺がプラスマスで埋め尽くされているかどうかの判定
$grch[Gi][Gj] = 0
mb = $M[Gi][Gj] == $PCh ? -(B + 1) : -(B - 1)
gminb = mb
for2p(H.times,W.times) {|i,j|
    $grch[i][j] = 0 if $grch[i][j] > 0
    if $grch[i][j] < 0
        gminb = [gminb, $grch[i][j]].max
    end
}
if gminb < mb
    puts AnsNo
    # 到達しない、最初の判定でこない可能性
    exit
end


flagP = false # スタート地点からの到達範囲に2連続するプラスマスがあるかどうか(あれば無限増大できる)
flagM = false # 2連続マイナスマスで好きなだけ減少できるかどうかを判定したかった

chikai = [l, Si, Sj]

for2p(H.times,1...W) {|i,j|
    if $plus[i][j] > 0 && $plus[i][j - 1] > 0
        flagP = true
        l1 = (i - Gi).abs + (j - Gj).abs
        l2 = (i - Gi).abs + (j - 1 - Gj).abs
        if chikai[0] > l1
            chikai = [l1, i, j] 
        elsif chikai[0] > l2
            chikai = [l2, i, j - 1]
        end
    end
    if $M[i][j] == $MCh && $M[i][j - 1] == $MCh
        if i == Gi && (Gj == j || Gj == j - 1)
            # ゴール地点が2連続マイナスマスかどうか
            flagM = true
        else
            #flagM = true
        end
    end
}

for2p(W.times,1...H) {|j,i|
    if $plus[i][j] > 0 && $plus[i - 1][j] > 0
        flagP = true
        l1 = (i - Gi).abs + (j - Gj).abs
        l2 = (i - 1 - Gi).abs + (j - Gj).abs
        if chikai[0] > l1
            chikai = [l1, i, j] 
        elsif chikai[0] > l2
            chikai = [l2, i - 1, j]
        end
    end
    if $M[i][j] == $MCh && $M[i - 1][j] == $MCh
        if (i == Gi || i - 1 == Gi) && Gj == j
            flagM = true
        else
            #flagM = true
        end
    end
}

# . のマイナスマスのカウント
mcount = 0
$M.each do |ml|
    mcount += ml.count $MCh
end

if mcount < 2 && A + l > B
    # hand05 と challenge01 問題 はここ
    # mcount == 1のとき A + l - 1 == B になるケースがあってもよいが無いので通る
    puts AnsNo
    exit
end

#puts "Unko"
#exit

gplus = false # ゴールで無限増大できるかどうか

if $M[Gi][Gj] == $PCh
    gplus ||= Gi > 0 && $M[Gi - 1][Gj] == $PCh
    gplus ||= Gj > 0 && $M[Gi][Gj - 1] == $PCh
    gplus ||= Gi + 1 < H && $M[Gi + 1][Gj] == $PCh
    gplus ||= Gj + 1 < W && $M[Gi][Gj + 1] == $PCh
            
end

if $plus[Gi][Gj] > 0
    # AがBになれるか判定できてないのにYesになるのはおかしい
    # マイナスとプラスのマスの数の判定も入ってないのでおかしい
    # ここで正解になるケースは偶然
    puts AnsYes
    exit
end




if flagP # && flagM
    # 値の増減の調整はいくらでもできるが
    # ここに hand01 でひっかかる(正答はNo)
    # Yesで正解してる部分は偶然 
    # 増大は出来ても雪球を減らすことが出来ないとNGにならないといけない(使わなかったflagMがマイナス判定)
=begin    
    if gminb <= -B
        # いくらでも増大できるのにたどり着けないのは
        # マイナスが足りないから?
        if mcount  > H * W / 2  && A == B  # 決め打ちよくない
            puts AnsNo
            exit
        end
    end
=end
    if $M[Gi][Gj] == $PCh && !gplus
        puts AnsNo
        exit
    end
    puts AnsYes
    exit
end

if $minus[Gi][Gj] > 0
    # Yesで正解してる部分は偶然 

    puts AnsYes
    exit
end

# 到達しない 最初の判定で落ちてる可能性
# ここに到達するケースが存在していない
# ここ移行ももっと判定しないと答えは出ない
# 初期のサイズの雪球では**往復増幅がないと超えられない.の壁があるケースがここに来るはず

puts AnsNo
0