結果

問題 No.8009 異なる数字の最大の範囲(勉強会用)
ユーザー parsee1053
提出日時 2020-09-29 23:54:34
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 88 ms / 5,000 ms
コード長 699 bytes
コンパイル時間 957 ms
コンパイル使用メモリ 91,388 KB
実行使用メモリ 8,320 KB
最終ジャッジ日時 2024-11-20 15:02:18
合計ジャッジ時間 2,102 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  set<int> st;
  int j = 0;
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    while (j < n && st.find(a[j]) == st.end()) {
      st.insert(a[j]);
      j++;
    }
    ans = max(ans, (int)st.size());
    if (i == j) {
      j++;
    } else {
      st.erase(a[i]);
    }
  }
  cout << ans << endl;
  return 0;
}
0