結果

問題 No.323 yuki国
ユーザー LeonardoneLeonardone
提出日時 2015-12-16 22:45:29
言語 Ruby
(3.3.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 4,641 bytes
コンパイル時間 47 ms
コンパイル使用メモリ 11,608 KB
実行使用メモリ 15,644 KB
最終ジャッジ日時 2023-10-14 11:08:41
合計ジャッジ時間 4,450 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
15,356 KB
testcase_01 AC 83 ms
15,292 KB
testcase_02 AC 76 ms
15,084 KB
testcase_03 AC 79 ms
15,272 KB
testcase_04 AC 77 ms
15,092 KB
testcase_05 AC 77 ms
15,300 KB
testcase_06 AC 78 ms
15,284 KB
testcase_07 AC 78 ms
15,332 KB
testcase_08 AC 78 ms
15,180 KB
testcase_09 AC 80 ms
15,496 KB
testcase_10 AC 76 ms
15,172 KB
testcase_11 AC 78 ms
15,188 KB
testcase_12 AC 78 ms
15,200 KB
testcase_13 AC 86 ms
15,516 KB
testcase_14 AC 78 ms
15,092 KB
testcase_15 AC 110 ms
15,560 KB
testcase_16 AC 88 ms
15,444 KB
testcase_17 AC 95 ms
15,644 KB
testcase_18 AC 80 ms
15,400 KB
testcase_19 AC 76 ms
15,264 KB
testcase_20 AC 86 ms
15,536 KB
testcase_21 AC 76 ms
15,344 KB
testcase_22 AC 86 ms
15,540 KB
testcase_23 AC 76 ms
15,220 KB
testcase_24 AC 86 ms
15,448 KB
testcase_25 AC 75 ms
15,232 KB
testcase_26 AC 86 ms
15,468 KB
testcase_27 AC 76 ms
15,192 KB
testcase_28 AC 82 ms
15,608 KB
testcase_29 AC 82 ms
15,580 KB
testcase_30 WA -
testcase_31 AC 78 ms
15,292 KB
testcase_32 WA -
testcase_33 AC 78 ms
15,172 KB
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 76 ms
15,092 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:55: warning: mismatched indentations at 'elsif' with 'if' at 50
Main.rb:58: warning: mismatched indentations at 'end' with 'if' at 50
Main.rb:112: 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
    # ここの正解も偶然ぽい
    exit
end

if l.odd? && (A.even? == B.even?)
    puts AnsNo
    # ここの正解も偶然ぽい
    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
flagM = false

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)
            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 問題 はここ
    puts AnsNo
    exit
end

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

#puts "Unko"
#exit

if flagP # && flagM
    # 値の増減の調整はいくらでもできるが
    # ここに hand01 でひっかかる(正答はNo)
    # Yesで正解してる部分は偶然 
    
    if gminb <= -B
        # いくらでも増大できるのにたどり着けないのは
        # マイナスが足りないから?
        if mcount  > H * W / 2  && A == B  # 決め打ちよくない
            puts AnsNo
            exit
        end
    end
    puts AnsYes
    exit
end

if $minus[Gi][Gj] > 0
    # ここに hand05 でひっかかる(正答はNo)
    # Yesで正解してる部分は偶然 

    puts AnsYes
    exit
end

if $plus[Gi][Gj] > 0 
    # ここにsample1の答えが来るらしい
    # Yesで正解したのは偶然 
    puts AnsYes
    exit
end

# 到達しない 最初の判定で落ちてる可能性

puts AnsNo
0