結果

問題 No.3009 異なる数字の最大の範囲(勉強会用)
ユーザー gemmarogemmaro
提出日時 2020-05-01 12:54:03
言語 Ruby
(3.3.0)
結果
AC  
実行時間 132 ms / 5,000 ms
コード長 485 bytes
コンパイル時間 189 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 27,008 KB
最終ジャッジ日時 2024-04-30 17:44:13
合計ジャッジ時間 3,273 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
19,968 KB
testcase_01 AC 81 ms
20,224 KB
testcase_02 AC 79 ms
20,096 KB
testcase_03 AC 80 ms
20,224 KB
testcase_04 AC 81 ms
19,968 KB
testcase_05 AC 87 ms
20,224 KB
testcase_06 AC 80 ms
19,968 KB
testcase_07 AC 83 ms
19,968 KB
testcase_08 AC 81 ms
20,096 KB
testcase_09 AC 83 ms
20,096 KB
testcase_10 AC 81 ms
19,968 KB
testcase_11 AC 80 ms
20,096 KB
testcase_12 AC 81 ms
19,968 KB
testcase_13 AC 80 ms
20,096 KB
testcase_14 AC 80 ms
20,096 KB
testcase_15 AC 118 ms
23,936 KB
testcase_16 AC 105 ms
23,424 KB
testcase_17 AC 110 ms
23,808 KB
testcase_18 AC 131 ms
26,752 KB
testcase_19 AC 122 ms
24,448 KB
testcase_20 AC 97 ms
21,888 KB
testcase_21 AC 89 ms
20,608 KB
testcase_22 AC 101 ms
22,784 KB
testcase_23 AC 94 ms
21,120 KB
testcase_24 AC 132 ms
27,008 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

# frozen_string_literal: true

# @see https://yukicoder.me/submissions/14249 by yuki2006
# rubocop:todo Metrics/AbcSize
def solve # rubocop:todo Metrics/MethodLength
  l = 0
  r = 0
  m = 0
  c = Array.new(10**6 + 1, false)

  while r < N
    if c[D[r]]
      m = [m, r - l].max
      c[D[l]] = false
      l += 1
    else
      c[D[r]] = true
      r += 1
    end
  end

  [m, r - l].max
end
# rubocop:enable Metrics/AbcSize

N = gets.to_i
D = gets.chomp.split.map(&:to_i)

puts solve
0