結果

問題 No.3009 異なる数字の最大の範囲(勉強会用)
ユーザー ocvret_ocvret_
提出日時 2021-01-30 17:09:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 49 ms / 5,000 ms
コード長 806 bytes
コンパイル時間 1,740 ms
コンパイル使用メモリ 168,784 KB
実行使用メモリ 11,524 KB
最終ジャッジ日時 2024-04-30 17:45:41
合計ジャッジ時間 2,716 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
11,300 KB
testcase_01 AC 6 ms
11,300 KB
testcase_02 AC 5 ms
11,284 KB
testcase_03 AC 6 ms
11,224 KB
testcase_04 AC 7 ms
11,272 KB
testcase_05 AC 7 ms
11,364 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 7 ms
11,356 KB
testcase_08 AC 7 ms
11,228 KB
testcase_09 AC 6 ms
11,260 KB
testcase_10 AC 0 ms
6,940 KB
testcase_11 AC 6 ms
11,244 KB
testcase_12 AC 6 ms
11,220 KB
testcase_13 AC 7 ms
11,236 KB
testcase_14 AC 7 ms
11,284 KB
testcase_15 AC 34 ms
11,356 KB
testcase_16 AC 31 ms
11,440 KB
testcase_17 AC 32 ms
11,348 KB
testcase_18 AC 49 ms
11,524 KB
testcase_19 AC 35 ms
11,472 KB
testcase_20 AC 22 ms
11,416 KB
testcase_21 AC 15 ms
11,324 KB
testcase_22 AC 27 ms
11,280 KB
testcase_23 AC 19 ms
11,360 KB
testcase_24 AC 41 ms
11,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
// #include<atcoder/all>

using namespace std;
// using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007


int main(){
  
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n)cin >> a[i];
  if(!n){
    cout << 0 << "\n";
    return 0;
  }
  int l = 1,r = n+1;
  while(r-l > 1){
    int mid = (l+r)/2;
    vector<int> cnt(2000000);
    int h = 0;
    bool is = false;
    rep(i,mid-1)if(cnt[a[i]]++ == 1)h++;
    for(int i = mid-1;i < n;i++){
      if(i-mid >= 0)if(cnt[a[i-mid]]-- == 2)h--;
      if(cnt[a[i]]++ == 1)h++;
      if(!h)is = true;
    }
    if(is)l = mid;
    else r = mid;
  }
  cout << l << "\n";
  

  return 0;
}
0