結果

問題 No.359 門松行列
ユーザー yaoshimaxyaoshimax
提出日時 2016-04-18 10:12:39
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 1,913 bytes
コンパイル時間 148 ms
コンパイル使用メモリ 7,296 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 03:26:38
合計ジャッジ時間 1,279 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
6,812 KB
testcase_01 AC 10 ms
6,944 KB
testcase_02 AC 10 ms
6,944 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def rangesplit(L,p):
    ret=[]
    for l,r in L:
        if r<p:
            ret.append((l,r))
        elif p<l:
            ret.append((l,r))
        else:
            if l<=p-1 :
                ret.append((l,p-1))
            if p+1<=r :
                ret.append((p+1,r))
            ret.append((p,p))
    return ret
def isKadomatsu(A):
    if A[0]==A[1] or A[1]==A[2] or A[0]==A[2]:
        return False
    elif A[0]<A[1] and A[1]>A[2]:
        return True
    elif A[0]>A[1] and A[1]<A[2]:
        return True
    return False


T=int(raw_input())
for ti in range(T):
    L=int(raw_input())
    A=[map(int,raw_input().split()) for i in range(3)]
    # l is too short
    if L==1:
        print 0
        continue 

    # set where is blankpoint
    blank=[]
    ranges=[(1,L-1)]
    for i in range(3):
        for j in range(3):
            if A[i][j]==0:
                blank.append((i,j))
            else:
                if A[i][j]< L:
                    #print "split", A[i][j]
                    ranges=rangesplit(ranges,A[i][j])
                    #print ranges
                    #print "split", L-A[i][j]
                    ranges=rangesplit(ranges,L-A[i][j])
                    #print ranges
    checkList=[[(0,0),(0,1),(0,2)],
               [(1,0),(1,1),(1,2)],
               [(2,0),(2,1),(2,2)],
               [(0,0),(1,0),(2,0)],
               [(0,1),(1,1),(2,1)],
               [(0,2),(1,2),(2,2)],
               [(0,0),(1,1),(2,2)],
               [(0,2),(1,1),(2,0)]]
    
    ans=0
    for l,r in ranges:
        Btmp=A
        Btmp[blank[0][0]][blank[0][1]]=l
        Btmp[blank[1][0]][blank[1][1]]=L-l
        ok=True
        for line in checkList:
            for (p,q) in line:
                B=[A[p][q] for (p,q) in line]
                if not isKadomatsu(B):
                    ok=False
                    break
        if ok:
            ans+=r-l+1
    print ans
0