結果

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

ソースコード

diff #

#include <bits/stdc++.h>
//#include "atcoder/all"
typedef long long int ll;
using namespace std;
// using namespace atcoder;
#define MAXA 1000001
int last[MAXA];
int main() {
    int n;
    cin >> n;
    ll a[n + 1];
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = 1; i < MAXA; i++) {
        last[i] = 0;
    }
    int ret = 0;
    int now = 1;
    for (int i = 1; i <= n; i++) {
        now = min(now, i - last[a[i]]);
        last[a[i]] = i;
        if (now > ret) ret = now;
        now++;
    }
    cout << ret << endl;
    return 0;
}
0