結果

問題 No.8009 異なる数字の最大の範囲(勉強会用)
ユーザー 👑 CleyL
提出日時 2021-12-08 09:26:27
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 62 ms / 5,000 ms
コード長 496 bytes
コンパイル時間 776 ms
コンパイル使用メモリ 83,228 KB
実行使用メモリ 8,576 KB
最終ジャッジ日時 2024-11-20 15:08:09
合計ジャッジ時間 1,939 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <set>
#include <queue>
using namespace std;
int main(){
    int n;cin>>n;
    set<int> A;
    queue<int> B;
    int ans = 0;
    for(int i = 0; n > i; i++){
        int x;cin>>x;
        if(A.count(x)){
            while(B.front() != x){
                A.erase(B.front());
                B.pop();
            }
            B.pop();
            
        }
        B.push(x);
        A.insert(x);
        ans = max(ans,(int)B.size());
    }
    cout << ans << endl;
}
0