結果
問題 | No.1051 PQ Permutation |
ユーザー | roaris |
提出日時 | 2020-05-11 18:34:09 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 185 ms / 2,000 ms |
コード長 | 1,803 bytes |
コンパイル時間 | 203 ms |
コンパイル使用メモリ | 82,536 KB |
実行使用メモリ | 164,740 KB |
最終ジャッジ日時 | 2024-07-18 17:30:10 |
合計ジャッジ時間 | 7,915 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 34 ms
52,736 KB |
testcase_01 | AC | 35 ms
52,224 KB |
testcase_02 | AC | 32 ms
52,608 KB |
testcase_03 | AC | 35 ms
52,224 KB |
testcase_04 | AC | 32 ms
52,608 KB |
testcase_05 | AC | 34 ms
52,096 KB |
testcase_06 | AC | 32 ms
52,204 KB |
testcase_07 | AC | 32 ms
52,864 KB |
testcase_08 | AC | 30 ms
52,480 KB |
testcase_09 | AC | 33 ms
52,096 KB |
testcase_10 | AC | 31 ms
52,352 KB |
testcase_11 | AC | 31 ms
52,992 KB |
testcase_12 | AC | 33 ms
52,224 KB |
testcase_13 | AC | 33 ms
52,224 KB |
testcase_14 | AC | 34 ms
52,224 KB |
testcase_15 | AC | 166 ms
119,616 KB |
testcase_16 | AC | 165 ms
118,460 KB |
testcase_17 | AC | 182 ms
164,740 KB |
testcase_18 | AC | 185 ms
156,836 KB |
testcase_19 | AC | 174 ms
151,320 KB |
testcase_20 | AC | 181 ms
134,696 KB |
testcase_21 | AC | 170 ms
126,256 KB |
testcase_22 | AC | 166 ms
147,780 KB |
testcase_23 | AC | 166 ms
127,532 KB |
testcase_24 | AC | 166 ms
125,924 KB |
testcase_25 | AC | 58 ms
77,928 KB |
testcase_26 | AC | 53 ms
73,216 KB |
testcase_27 | AC | 49 ms
66,048 KB |
testcase_28 | AC | 68 ms
87,936 KB |
testcase_29 | AC | 56 ms
73,216 KB |
testcase_30 | AC | 61 ms
77,952 KB |
testcase_31 | AC | 56 ms
70,144 KB |
testcase_32 | AC | 65 ms
77,660 KB |
testcase_33 | AC | 48 ms
67,200 KB |
testcase_34 | AC | 47 ms
66,816 KB |
testcase_35 | AC | 88 ms
108,160 KB |
testcase_36 | AC | 92 ms
113,152 KB |
testcase_37 | AC | 102 ms
137,920 KB |
testcase_38 | AC | 168 ms
149,036 KB |
testcase_39 | AC | 106 ms
108,160 KB |
testcase_40 | AC | 174 ms
154,344 KB |
testcase_41 | AC | 175 ms
154,344 KB |
testcase_42 | AC | 41 ms
52,608 KB |
testcase_43 | AC | 41 ms
52,096 KB |
testcase_44 | AC | 34 ms
52,096 KB |
testcase_45 | AC | 33 ms
51,840 KB |
testcase_46 | AC | 35 ms
51,968 KB |
testcase_47 | AC | 35 ms
52,352 KB |
testcase_48 | AC | 114 ms
137,984 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 (P not in s) and (Q not in s): if max1[i]!=Q and max1[i]>A[i]: match = i elif max1[i]==Q and max2[i]>A[i]: match = i elif (P not in s) and (Q in s): break else: if max1[i]>A[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]) s = set(ans) rem.sort() if (P not in s) and (Q not in s): for i in range(len(rem)): if rem[i]==A[match]: if rem[i+1]!=Q: mark = i+1 else: mark = i+2 ans.append(rem[mark]) rem2 = [rem[i] for i in range(len(rem)) if i!=mark] if P<Q: ans += rem2 else: if rem[mark]==P: ans += rem2 else: 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) else: for i in range(len(rem)): if rem[i]==A[match]: mark = i+1 ans.append(rem[mark]) for i in range(len(rem)): if i!=mark: ans.append(rem[i]) print(*ans)