結果

問題 No.359 門松行列
ユーザー yaoshimaxyaoshimax
提出日時 2016-04-18 10:19:07
言語 Python2
(2.7.18)
結果
AC  
実行時間 67 ms / 2,000 ms
コード長 1,947 bytes
コンパイル時間 40 ms
コンパイル使用メモリ 7,168 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 03:26:41
合計ジャッジ時間 1,180 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
6,812 KB
testcase_01 AC 10 ms
6,940 KB
testcase_02 AC 10 ms
6,940 KB
testcase_03 AC 44 ms
6,940 KB
testcase_04 AC 25 ms
6,940 KB
testcase_05 AC 34 ms
6,944 KB
testcase_06 AC 16 ms
6,940 KB
testcase_07 AC 32 ms
6,940 KB
testcase_08 AC 63 ms
6,940 KB
testcase_09 AC 61 ms
6,944 KB
testcase_10 AC 67 ms
6,940 KB
testcase_11 AC 50 ms
6,940 KB
testcase_12 AC 50 ms
6,940 KB
testcase_13 AC 58 ms
6,944 KB
testcase_14 AC 44 ms
6,940 KB
testcase_15 AC 18 ms
6,940 KB
testcase_16 AC 43 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

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)]
    ranges=rangesplit(ranges,L/2)
    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