結果
問題 | No.1051 PQ Permutation |
ユーザー | roaris |
提出日時 | 2020-05-15 02:33:29 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,078 bytes |
コンパイル時間 | 315 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 164,764 KB |
最終ジャッジ日時 | 2024-09-16 16:09:52 |
合計ジャッジ時間 | 8,638 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge6 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 36 ms
52,480 KB |
testcase_01 | WA | - |
testcase_02 | AC | 37 ms
51,968 KB |
testcase_03 | AC | 37 ms
52,480 KB |
testcase_04 | AC | 37 ms
52,480 KB |
testcase_05 | AC | 37 ms
52,352 KB |
testcase_06 | AC | 37 ms
52,480 KB |
testcase_07 | AC | 36 ms
52,480 KB |
testcase_08 | AC | 37 ms
52,352 KB |
testcase_09 | AC | 37 ms
52,352 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | AC | 37 ms
52,480 KB |
testcase_13 | AC | 38 ms
52,224 KB |
testcase_14 | AC | 37 ms
52,352 KB |
testcase_15 | AC | 182 ms
119,996 KB |
testcase_16 | AC | 181 ms
119,520 KB |
testcase_17 | AC | 197 ms
164,764 KB |
testcase_18 | AC | 197 ms
164,308 KB |
testcase_19 | AC | 195 ms
164,316 KB |
testcase_20 | WA | - |
testcase_21 | AC | 187 ms
133,812 KB |
testcase_22 | AC | 193 ms
164,188 KB |
testcase_23 | AC | 187 ms
137,132 KB |
testcase_24 | AC | 186 ms
135,252 KB |
testcase_25 | AC | 67 ms
77,440 KB |
testcase_26 | AC | 61 ms
74,624 KB |
testcase_27 | WA | - |
testcase_28 | AC | 80 ms
88,064 KB |
testcase_29 | AC | 61 ms
73,984 KB |
testcase_30 | AC | 68 ms
77,696 KB |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | AC | 54 ms
66,944 KB |
testcase_34 | AC | 57 ms
67,456 KB |
testcase_35 | AC | 99 ms
108,160 KB |
testcase_36 | AC | 105 ms
113,024 KB |
testcase_37 | AC | 113 ms
137,728 KB |
testcase_38 | AC | 193 ms
149,072 KB |
testcase_39 | AC | 102 ms
108,544 KB |
testcase_40 | AC | 183 ms
154,604 KB |
testcase_41 | AC | 181 ms
154,276 KB |
testcase_42 | AC | 37 ms
52,736 KB |
testcase_43 | AC | 37 ms
52,736 KB |
testcase_44 | AC | 38 ms
52,736 KB |
testcase_45 | AC | 41 ms
52,480 KB |
testcase_46 | AC | 39 ms
52,352 KB |
testcase_47 | AC | 37 ms
51,968 KB |
testcase_48 | AC | 113 ms
138,064 KB |
ソースコード
import sys input = sys.stdin.readline N, P, Q = map(int, input().split()) A = list(map(int, input().split())) max1 = [-1]*(N+1) max2 = [-2]*(N+1) for i in range(N-1, -1, -1): if A[i]>max1[i+1]: max1[i] = A[i] max2[i] = max1[i+1] elif A[i]>max2[i+1]: max1[i] = max1[i+1] max2[i] = A[i] else: max1[i] = max1[i+1] max2[i] = max2[i+1] match = -1 s = set() for i in range(N): if (Q in s) and (P not in s): break if (P not in s) and (Q not in s): if max1[i]!=Q and A[i]<max1[i]: match = i elif A[i]<max2[i]: match = i else: if A[i]<max1[i]: match = i s.add(A[i]) if match==-1: print(-1) exit() ans, rem = [], [] for i in range(N): if i<match: ans.append(A[i]) else: rem.append(A[i]) rem.sort() s = set(ans) if P in s: rem2 = [] for i in range(len(rem)): if rem[i]==A[match]: mark = i+1 for j in range(len(rem)): if j!=mark: rem2.append(rem[j]) break ans.append(rem[mark]) ans += rem2 else: rem2 = [] for i in range(len(rem)): if rem[i]==A[match]: if rem[i+1]!=Q: mark = i+1 else: mark = i+2 for j in range(len(rem)): if j!=mark: rem2.append(rem[j]) break if P<Q: ans.append(rem[mark]) ans += rem2 else: if rem[mark]==P: ans.append(rem[mark]) ans += rem2 else: ans.append(A[mark]) for rem2_i in rem2: if rem2_i<P and rem2_i!=Q: ans.append(rem2_i) ans.append(P) ans.append(Q) for rem2_i in rem2: if rem2_i>P: ans.append(rem2_i) print(*ans)