結果

問題 No.3009 異なる数字の最大の範囲(勉強会用)
ユーザー ocvret_ocvret_
提出日時 2021-01-30 17:07:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 802 bytes
コンパイル時間 1,510 ms
コンパイル使用メモリ 165,684 KB
実行使用メモリ 11,380 KB
最終ジャッジ日時 2023-09-03 17:00:03
合計ジャッジ時間 3,048 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 8 ms
11,088 KB
testcase_02 AC 7 ms
11,120 KB
testcase_03 AC 9 ms
11,252 KB
testcase_04 AC 7 ms
11,196 KB
testcase_05 WA -
testcase_06 AC 1 ms
4,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 8 ms
11,128 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 7 ms
11,244 KB
testcase_12 AC 8 ms
11,072 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 41 ms
11,284 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]]-- == 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