結果

問題 No.1717 Levi-Civita Triangle
ユーザー zkouzkou
提出日時 2021-08-04 16:58:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 127 ms / 2,000 ms
コード長 2,002 bytes
コンパイル時間 381 ms
コンパイル使用メモリ 82,132 KB
実行使用メモリ 104,064 KB
最終ジャッジ日時 2024-09-23 03:44:32
合計ジャッジ時間 4,532 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 42
権限があれば一括ダウンロードができます

ソースコード

diff #

# 想定解

def solve(N, As):
    assert len(As) == 2 * N + 1
    def LeviCivitaSymbol(i, j, k):
        if (i, j, k) in ((0, 1, 2), (1, 2, 0), (2, 0, 1)):
            return 1
        elif (i, j, k) in ((2, 1, 0), (1, 0, 2), (0, 2, 1)):
            return 2
        else:
            return 0
    As = [LeviCivitaSymbol(As[i], As[i + 1], As[i + 2]) for i in range(len(As) - 2)]
    As.reverse()
    ans_one = ([1, 0, 2, 0] * ((len(As) + 3) // 4))[:len(As)]
    ans_two = ([2, 0, 1, 0] * ((len(As) + 3) // 4))[:len(As)]
    if As == ans_one:
        return 1
    elif As == ans_two:
        return 2
    else:
        return 0


def slow(N, As):
    assert len(As) == 2 * N + 1
    def LeviCivitaSymbol(i, j, k):
        if (i, j, k) in ((0, 1, 2), (1, 2, 0), (2, 0, 1)):
            return 1
        elif (i, j, k) in ((2, 1, 0), (1, 0, 2), (0, 2, 1)):
            return 2
        else:
            return 0
    for _ in range(N):
        As = [LeviCivitaSymbol(As[i], As[i + 1], As[i + 2]) for i in range(len(As) - 2)]
    assert len(As) == 1
    return As[0]


def test1(t):
    import random
    for _ in range(t):
        N = random.randint(1, 100)
        As = [random.randint(0, 2) for _ in range(2 * N + 1)]
        ans_slow = slow(N, As.copy())
        ans_solve = solve(N, As.copy())
        # print(ans_slow, ans_solve, As)
        assert ans_slow == ans_solve
    print("test1 passed")


def test2(Nmax):
    from itertools import permutations
    for N in range(1, Nmax + 1):
        for As in permutations(range(3), 2 * N + 1):
            As = list(As)
            ans_slow = slow(N, As.copy())
            ans_solve = solve(N, As.copy())
            # print(ans_slow, ans_solve, As)
            assert ans_slow == ans_solve
    print("test2 passed")

    
def main():
    #"""
    N = int(input())
    As = list(map(int, input().split()))
    """
    import random
    N = 5 * 10 ** 5
    As = [random.randint(0, 2) for _ in range(2 * N + 1)]
    #"""
    print(solve(N, As))

main()
0