結果

問題 No.8009 異なる数字の最大の範囲(勉強会用)
ユーザー Hydrogen332
提出日時 2024-11-13 12:15:09
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 64 ms / 5,000 ms
+ 741µs
コード長 635 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,521 ms
コンパイル使用メモリ 345,592 KB
実行使用メモリ 8,320 KB
最終ジャッジ日時 2026-11-05 01:19:16
合計ジャッジ時間 4,844 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge7_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, e) for (int i = (int)s; i < (int)e; ++i)
#define all(a) (a).begin(), (a).end()

int main() {
    cin.tie(nullptr);
    
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, 0, N) cin >> A[i];
    set<int> s;
    int ans = 0;
    int l = 0, r = 0;
    
    while (true) {
        if (l == N) break;
        
        if (r <= N - 1 && !s.count(A[r])) {
            s.insert(A[r]);
            r++;
        } else {
            s.erase(A[l]);
            l++;
        }
        
        ans = max(ans, r - l);
    }
    
    cout << ans << '\n';
}
0