結果

問題 No.3009 異なる数字の最大の範囲(勉強会用)
ユーザー simansiman
提出日時 2022-08-12 14:20:06
言語 Ruby
(3.3.0)
結果
AC  
実行時間 170 ms / 5,000 ms
コード長 420 bytes
コンパイル時間 129 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 25,088 KB
最終ジャッジ日時 2024-04-30 17:51:45
合計ジャッジ時間 3,359 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
12,288 KB
testcase_01 AC 79 ms
12,288 KB
testcase_02 AC 75 ms
12,160 KB
testcase_03 AC 73 ms
12,160 KB
testcase_04 AC 74 ms
12,288 KB
testcase_05 AC 74 ms
12,288 KB
testcase_06 AC 77 ms
12,288 KB
testcase_07 AC 76 ms
12,416 KB
testcase_08 AC 76 ms
12,160 KB
testcase_09 AC 76 ms
12,160 KB
testcase_10 AC 74 ms
12,160 KB
testcase_11 AC 74 ms
12,288 KB
testcase_12 AC 73 ms
12,288 KB
testcase_13 AC 74 ms
12,288 KB
testcase_14 AC 73 ms
12,288 KB
testcase_15 AC 123 ms
18,560 KB
testcase_16 AC 119 ms
18,432 KB
testcase_17 AC 126 ms
18,816 KB
testcase_18 AC 170 ms
24,448 KB
testcase_19 AC 140 ms
19,712 KB
testcase_20 AC 105 ms
15,616 KB
testcase_21 AC 90 ms
13,440 KB
testcase_22 AC 110 ms
17,280 KB
testcase_23 AC 99 ms
14,720 KB
testcase_24 AC 161 ms
25,088 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
A = gets.split.map(&:to_i)

counter = Hash.new(0)
left = 0
right = 0
counter[A[0]] += 1
ans = 1

while left <= right
  if right == N - 1
    counter[A[left]] -= 1
    left += 1
  elsif counter[A[right]] >= 2
    counter[A[left]] -= 1
    left += 1
  else
    right += 1
    counter[A[right]] += 1
  end

  if counter[A[right]] <= 1
    len = right - left + 1
    ans = len if ans < len
  end
end

puts ans
0