結果
問題 |
No.8009 異なる数字の最大の範囲(勉強会用)
|
ユーザー |
|
提出日時 | 2018-02-02 08:12:03 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 15 ms / 5,000 ms |
コード長 | 1,067 bytes |
コンパイル時間 | 728 ms |
コンパイル使用メモリ | 102,332 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-12 23:46:56 |
合計ジャッジ時間 | 1,551 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 |
ソースコード
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array; void main() { int n; int[] a; scan(n); a = readln.split.to!(int[]); auto b = new bool[](a.reduce!max + 1); int ans; for (int l,r; r < n; r++) { if (b[a[r]]) { for (; b[a[r]]; l++) { b[a[l]] = 0; } } debug { writefln("(l, r) = (%s, %s)", l, r); } ans = max(ans, r - l + 1); b[a[r]] = 1; } writeln(ans); } void scan(T...)(ref T args) { import std.stdio : readln; import std.algorithm : splitter; import std.conv : to; import std.range.primitives; auto line = readln().splitter(); foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }