結果
問題 | No.1369 交換門松列・竹 |
ユーザー | mkawa2 |
提出日時 | 2021-11-12 03:16:49 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 301 ms / 2,000 ms |
コード長 | 2,500 bytes |
コンパイル時間 | 176 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 15,828 KB |
最終ジャッジ日時 | 2024-05-03 07:05:23 |
合計ジャッジ時間 | 4,111 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 30 ms
10,752 KB |
testcase_01 | AC | 31 ms
10,880 KB |
testcase_02 | AC | 32 ms
10,880 KB |
testcase_03 | AC | 32 ms
10,880 KB |
testcase_04 | AC | 31 ms
10,880 KB |
testcase_05 | AC | 31 ms
10,752 KB |
testcase_06 | AC | 30 ms
10,880 KB |
testcase_07 | AC | 31 ms
10,880 KB |
testcase_08 | AC | 30 ms
10,880 KB |
testcase_09 | AC | 30 ms
10,752 KB |
testcase_10 | AC | 31 ms
10,880 KB |
testcase_11 | AC | 30 ms
10,880 KB |
testcase_12 | AC | 32 ms
10,880 KB |
testcase_13 | AC | 138 ms
10,752 KB |
testcase_14 | AC | 161 ms
10,752 KB |
testcase_15 | AC | 284 ms
15,824 KB |
testcase_16 | AC | 67 ms
15,828 KB |
testcase_17 | AC | 67 ms
15,824 KB |
testcase_18 | AC | 67 ms
15,700 KB |
testcase_19 | AC | 297 ms
15,824 KB |
testcase_20 | AC | 68 ms
15,700 KB |
testcase_21 | AC | 301 ms
15,828 KB |
testcase_22 | AC | 67 ms
15,700 KB |
testcase_23 | AC | 67 ms
15,824 KB |
testcase_24 | AC | 67 ms
15,700 KB |
testcase_25 | AC | 63 ms
11,008 KB |
testcase_26 | AC | 62 ms
10,880 KB |
testcase_27 | AC | 69 ms
11,008 KB |
testcase_28 | AC | 62 ms
11,852 KB |
testcase_29 | AC | 61 ms
11,628 KB |
testcase_30 | AC | 47 ms
15,704 KB |
testcase_31 | AC | 48 ms
15,696 KB |
testcase_32 | AC | 61 ms
10,880 KB |
testcase_33 | AC | 61 ms
11,852 KB |
ソースコード
import sys # sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() # dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] # inf = 18446744073709551615 inf = 4294967295 md = 10**9+7 # md = 998244353 def iskado(abc): a, b, c = abc if a == b or b == c or c == a: return False if a < b < c or a > b > c: return False return True def solve(): def ok(i, j, lr0): res = True aa[i], aa[j] = aa[j], aa[i] s = max(0, min(i-2, lr0[0])) t = min(n-2, max(i+1, lr0[1]-2)) for k in range(s, t): if not iskado(aa[k:k+3]): res = False break aa[i], aa[j] = aa[j], aa[i] return res n = II() aa = LI() lr = [] l = r = -1 for i in range(n-2): if iskado(aa[i:i+3]): if l != -1 and i >= r: lr.append((l, r)) l = r = -1 else: if l == -1: l, r = i, i+3 else: r = i+3 if r-l == 11: return False if l != -1: lr.append((l, r)) # print(lr) if len(lr) > 2: return False if len(lr) == 2: for l, r in lr: if r-l > 5: return False for i in range(lr[0][0], lr[0][1]): for j in range(lr[1][0], lr[1][1]): if not ok(i, j, lr[0]): continue if not ok(j, i, lr[1]): continue return True if len(lr) == 1: l, r = lr[0] if r-l > 5: for i in range(lr[0][0], lr[0][1]): for j in range(lr[0][0], i): if not ok(i, j, lr[0]): continue if not ok(j, i, lr[0]): continue return True else: for i in range(lr[0][0], lr[0][1]): for j in range(n): if i == j: continue if not ok(i, j, lr[0]): continue if not ok(j, i, lr[0]): continue return True return False for _ in range(II()): print("Yes" if solve() else "No")