結果

問題 No.3009 Union-Find でつながろう!
ユーザー gew1fw
提出日時 2025-06-12 19:57:22
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 684 bytes
コンパイル時間 196 ms
コンパイル使用メモリ 82,640 KB
実行使用メモリ 91,904 KB
最終ジャッジ日時 2025-06-12 19:58:57
合計ジャッジ時間 3,594 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 3 WA * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

def main():
    data = sys.stdin.read().split()
    if not data:
        print(0)
        return
    n = int(data[0])
    if n == 0:
        print(0)
        return
    a = list(map(int, data[1:n+1]))
    
    max_len = 0
    left = 0
    last_occurrence = dict()
    
    for right in range(n):
        current_num = a[right]
        if current_num in last_occurrence and last_occurrence[current_num] >= left:
            left = last_occurrence[current_num] + 1
        last_occurrence[current_num] = right
        current_len = right - left + 1
        if current_len > max_len:
            max_len = current_len
    print(max_len)

if __name__ == "__main__":
    main()
0