結果

問題 No.3009 異なる数字の最大の範囲(勉強会用)
ユーザー ha71ha71
提出日時 2020-09-20 16:32:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 34 ms / 5,000 ms
コード長 571 bytes
コンパイル時間 1,457 ms
コンパイル使用メモリ 163,512 KB
実行使用メモリ 8,080 KB
最終ジャッジ日時 2023-08-12 22:43:50
合計ジャッジ時間 2,716 ms
ジャッジサーバーID
(参考情報)
judge2 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,264 KB
testcase_01 AC 5 ms
7,232 KB
testcase_02 AC 4 ms
7,320 KB
testcase_03 AC 4 ms
7,224 KB
testcase_04 AC 5 ms
7,312 KB
testcase_05 AC 5 ms
7,236 KB
testcase_06 AC 4 ms
7,236 KB
testcase_07 AC 5 ms
7,320 KB
testcase_08 AC 5 ms
7,236 KB
testcase_09 AC 4 ms
7,224 KB
testcase_10 AC 4 ms
7,252 KB
testcase_11 AC 4 ms
7,304 KB
testcase_12 AC 4 ms
7,228 KB
testcase_13 AC 5 ms
7,264 KB
testcase_14 AC 4 ms
7,440 KB
testcase_15 AC 21 ms
7,700 KB
testcase_16 AC 19 ms
7,608 KB
testcase_17 AC 21 ms
7,668 KB
testcase_18 AC 34 ms
8,068 KB
testcase_19 AC 24 ms
7,744 KB
testcase_20 AC 14 ms
7,500 KB
testcase_21 AC 9 ms
7,420 KB
testcase_22 AC 16 ms
7,564 KB
testcase_23 AC 11 ms
7,392 KB
testcase_24 AC 31 ms
8,080 KB
権限があれば一括ダウンロードができます

ソースコード

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