結果
| 問題 | 
                            No.2779 Don't make Pair
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2024-06-08 07:20:13 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 163 ms / 2,000 ms | 
| コード長 | 746 bytes | 
| コンパイル時間 | 576 ms | 
| コンパイル使用メモリ | 82,560 KB | 
| 実行使用メモリ | 108,544 KB | 
| 最終ジャッジ日時 | 2024-12-27 05:38:57 | 
| 合計ジャッジ時間 | 4,489 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 5 | 
| other | AC * 24 | 
ソースコード
N = int(input())
A = list(map(int, input().split()))
from collections import defaultdict
from collections import Counter
C = Counter(A)
if C.most_common()[0][1] > 2:
    # print('aaaaaa')
    print(0)
    print()
    exit()
elif C.most_common()[0][1] == 1:
    print(len(A)-1)
    print(*list(range(1, N)))
    exit()
LR = []
cnt = defaultdict(int)
stt = []
end = []
for i in range(N):
    x = A[i]
    cnt[x] += 1
    if C[x] >= 2 and cnt[x] == 1:
        stt.append(i)
    if C[x] >= 2 and cnt[x] == C[x]:
        end.append(i)
stt.sort()
end.sort()
l = stt[-1]
r = end[0]
# print(l, r, stt, end)
if l > r:
    # print(l, r, stt, end)
    print(0)
    print()
    exit()
else:
    print(r - l)
    ans = list(range(l+1, r+1))
    print(*ans)