結果
問題 | No.1717 Levi-Civita Triangle |
ユーザー | zkou |
提出日時 | 2021-08-04 20:38:02 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,013 bytes |
コンパイル時間 | 159 ms |
コンパイル使用メモリ | 81,544 KB |
実行使用メモリ | 201,344 KB |
最終ジャッジ日時 | 2023-10-24 11:24:32 |
合計ジャッジ時間 | 4,168 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 37 ms
57,696 KB |
testcase_01 | AC | 37 ms
53,348 KB |
testcase_02 | AC | 36 ms
53,348 KB |
testcase_03 | AC | 37 ms
53,348 KB |
testcase_04 | AC | 40 ms
58,788 KB |
testcase_05 | AC | 73 ms
72,472 KB |
testcase_06 | TLE | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
testcase_43 | -- | - |
testcase_44 | -- | - |
ソースコード
# 愚直解 TLE 想定 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(slow(N, As)) main()