結果

問題 No.3009 異なる数字の最大の範囲(勉強会用)
ユーザー ha71ha71
提出日時 2020-09-20 16:32:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 35 ms / 5,000 ms
コード長 571 bytes
コンパイル時間 1,591 ms
コンパイル使用メモリ 167,560 KB
実行使用メモリ 8,196 KB
最終ジャッジ日時 2024-04-30 17:44:51
合計ジャッジ時間 2,710 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,316 KB
testcase_01 AC 4 ms
7,324 KB
testcase_02 AC 4 ms
7,432 KB
testcase_03 AC 4 ms
7,188 KB
testcase_04 AC 4 ms
7,428 KB
testcase_05 AC 4 ms
7,356 KB
testcase_06 AC 4 ms
7,480 KB
testcase_07 AC 5 ms
7,324 KB
testcase_08 AC 4 ms
7,320 KB
testcase_09 AC 4 ms
7,400 KB
testcase_10 AC 4 ms
7,364 KB
testcase_11 AC 4 ms
7,428 KB
testcase_12 AC 4 ms
7,352 KB
testcase_13 AC 4 ms
7,324 KB
testcase_14 AC 4 ms
7,508 KB
testcase_15 AC 22 ms
7,820 KB
testcase_16 AC 20 ms
7,808 KB
testcase_17 AC 21 ms
7,776 KB
testcase_18 AC 35 ms
8,156 KB
testcase_19 AC 24 ms
7,860 KB
testcase_20 AC 14 ms
7,736 KB
testcase_21 AC 9 ms
7,576 KB
testcase_22 AC 17 ms
7,648 KB
testcase_23 AC 11 ms
7,532 KB
testcase_24 AC 32 ms
8,196 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