結果

問題 No.8009 異なる数字の最大の範囲(勉強会用)
ユーザー norioc
提出日時 2018-01-27 17:48:30
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 43 ms / 5,000 ms
コード長 700 bytes
コンパイル時間 645 ms
コンパイル使用メモリ 103,412 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-06-12 23:40:11
合計ジャッジ時間 1,701 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

int readint() { return readln.chomp.to!int; }
int[] readints() { return readln.split.to!(int[]); }

ulong calc(int[] xs) {
    bool[int] used;

    used[xs[0]] = true;
    int[] q = [xs[0]];
    ulong ans = 1;
    foreach (x; xs) {
        while (x in used) {
            used.remove(q[0]);
            q = q[1..$];
        }

        assert(x !in used);
        used[x] = true;
        q ~= x;
        ans = max(ans, q.length);
    }
    return ans;
}

void main() {
    readint;
    auto xs = readints;
    auto ans = calc(xs);
    writeln(ans);
}
0