結果

問題 No.359 門松行列
ユーザー LeonardoneLeonardone
提出日時 2016-04-18 00:46:24
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 2,746 bytes
コンパイル時間 87 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 19,360 KB
最終ジャッジ日時 2024-04-15 03:06:48
合計ジャッジ時間 5,245 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
19,360 KB
testcase_01 AC 83 ms
12,160 KB
testcase_02 AC 82 ms
12,288 KB
testcase_03 AC 86 ms
12,288 KB
testcase_04 AC 85 ms
12,288 KB
testcase_05 AC 89 ms
12,160 KB
testcase_06 AC 84 ms
12,288 KB
testcase_07 AC 91 ms
12,160 KB
testcase_08 AC 923 ms
12,160 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:70: warning: assigned but unused variable - k
Syntax OK

ソースコード

diff #

#! ruby
# Try yukicoder
# author: Leonardone @ NEETSDKASU
############################################################
def gs() gets.chomp end
def gi() gets.to_i end
def gf() gets.to_f end
def gss() gs.split end
def gis() gss.map(&:to_i) end
def gfs() gss.map(&:to_f) end
def nmapf(n,f) n.times.map{ __send__ f } 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 arr2d(h,w,v=0) h.times.map{[v] * w} end
def for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end
def nsum(n) n * (n + 1) / 2 end
def vcount(d,r=Hash.new(0)) d.inject(r){|r,e| r[e]+=1;r} end
############################################################

def isKadomatuRetsu(a1, a2, a3)
    a1 != a3 && ((a2 > a1 && a2 > a3) || (a2 < a1 && a2 < a3))
end

def checkNotKadomatsuRetsu(a1, a2, a3)
    return true if a1 > 0 && a2 > 0 && a1 == a2 
    return true if a2 > 0 && a3 > 0 && a2 == a3 
    return true if a1 > 0 && a3 > 0 && a1 == a3 
    return false if [a1, a2, a3].include? 0
    return !isKadomatuRetsu(a1, a2, a3)
end

def checkNotKadomatsuGyoretsu(a)
    return true if checkNotKadomatsuRetsu(a[0][0], a[0][1], a[0][2])
    return true if checkNotKadomatsuRetsu(a[1][0], a[1][1], a[1][2])
    return true if checkNotKadomatsuRetsu(a[2][0], a[2][1], a[2][2])
    return true if checkNotKadomatsuRetsu(a[0][0], a[1][0], a[2][0])
    return true if checkNotKadomatsuRetsu(a[0][1], a[1][1], a[2][1])
    return true if checkNotKadomatsuRetsu(a[0][2], a[1][2], a[2][2])
    return true if checkNotKadomatsuRetsu(a[0][0], a[1][1], a[2][2])
    return true if checkNotKadomatsuRetsu(a[0][2], a[1][1], a[2][0])
    return false
end

def isKadomatuGyoretsu(a)
    return false if !isKadomatuRetsu(a[0][0], a[0][1], a[0][2])
    return false if !isKadomatuRetsu(a[1][0], a[1][1], a[1][2])
    return false if !isKadomatuRetsu(a[2][0], a[2][1], a[2][2])
    return false if !isKadomatuRetsu(a[0][0], a[1][0], a[2][0])
    return false if !isKadomatuRetsu(a[0][1], a[1][1], a[2][1])
    return false if !isKadomatuRetsu(a[0][2], a[1][2], a[2][2])
    return false if !isKadomatuRetsu(a[0][0], a[1][1], a[2][2])
    return false if !isKadomatuRetsu(a[0][2], a[1][1], a[2][0])
    return true
end

t = gi

t.times do
    
    l = gi
    a = ngis 3
    
    if checkNotKadomatsuGyoretsu(a)
        puts 0
        next
    end
    
    k = 0
    xy = []
    
    3.times do |i|
        3.times do |j|
            if a[i][j] == 0
                xy << [i, j]
            end
        end
    end
    
    ans = 0
    i1, j1 = xy[0]
    i2, j2 = xy[1]
    
    1.upto(l - 1) do |x|
        y = l - x
        a[i1][j1] = x
        a[i2][j2] = y
        ans += 1 if isKadomatuGyoretsu(a)
    end
    
    puts ans
end



0