結果

問題 No.8009 異なる数字の最大の範囲(勉強会用)
ユーザー a01sa01to
提出日時 2025-10-31 00:38:14
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 66 ms / 5,000 ms
コード長 507 bytes
コンパイル時間 3,118 ms
コンパイル使用メモリ 283,392 KB
実行使用メモリ 8,320 KB
最終ジャッジ日時 2025-10-31 00:38:47
合計ジャッジ時間 4,605 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using ull = unsigned long long;

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int ans = 0;
  set<int> st;
  int r = 0;
  rep(l, n) {
    while (r < n && !st.contains(a[r])) st.insert(a[r++]);
    ans = max(ans, r - l);
    assert(st.contains(a[l]));
    st.erase(a[l]);
  }
  cout << ans << '\n';
  return 0;
}
0