結果

問題 No.8009 異なる数字の最大の範囲(勉強会用)
ユーザー ninoinui
提出日時 2020-07-21 16:25:08
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 99 ms / 5,000 ms
コード長 411 bytes
コンパイル時間 2,857 ms
コンパイル使用メモリ 199,368 KB
最終ジャッジ日時 2025-01-12 01:31:10
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  set<int> SE;
  int mx = 0;
  for (int l = 0, r = 0; r < N; r++) {
    if (SE.count(A.at(r))) {
      while (A.at(l) != A.at(r)) SE.erase(A.at(l++));
      SE.erase(A.at(l++));
    }
    SE.insert(A.at(r));
    mx = max(mx, r - l + 1);
  }
  cout << mx << "\n";
}
0