結果

問題 No.2779 Don't make Pair
ユーザー xrつぼxrつぼ
提出日時 2024-06-12 13:59:23
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
RE  
実行時間 -
コード長 1,070 bytes
コンパイル時間 359 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 34,848 KB
最終ジャッジ日時 2024-06-12 13:59:28
合計ジャッジ時間 3,993 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 23 RE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

def union(tap_1, tap_2):
    if tap_1[0] < tap_2[0]:
        s, t = tap_1, tap_2
    else:
        s, t = tap_2, tap_1
    
    if s[1] < t[0]:
        return False
    elif s[1] > t[0] and s[1] < t[1]:
        return [t[0], s[1]]
    elif s[1] > t[1]:
        return [t[0], t[1]]
    
n = int(input())
a = list(map(int, input().split()))

d = dict() #{数字:[場所]}
d_keys = [] #2回出てきた数字
flag = True
for i in range(n):
    n_i = a[i]
    if n_i in d:
        d[n_i].append(i)
        if len(d[n_i]) == 3:
            print(0)
            print("")
            break
        elif len(d[n_i]) == 2:
            d_keys.append(n_i)
    else: d[n_i] = [i]
else:
    res = [0, n-1]
    for k in d_keys:
        if res == False:
            print(0)
            print("")
            break
        else:
            res = union(res, d[k])
    else:
        if res == False:
            print(0)
            print("")
        else:
            res = [res[0]+1, res[1]]
            print(res[1]-res[0]+1)
            print(*[n for n in range(res[0], res[1]+1)])
0