結果

問題 No.190 Dry Wet Moist
ユーザー simansiman
提出日時 2016-03-29 05:10:17
言語 Ruby
(3.3.0)
結果
AC  
実行時間 354 ms / 2,000 ms
コード長 1,252 bytes
コンパイル時間 36 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 40,320 KB
最終ジャッジ日時 2024-04-10 05:39:59
合計ジャッジ時間 5,926 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
12,160 KB
testcase_01 AC 86 ms
12,160 KB
testcase_02 AC 75 ms
12,032 KB
testcase_03 AC 76 ms
12,160 KB
testcase_04 AC 79 ms
12,160 KB
testcase_05 AC 77 ms
12,032 KB
testcase_06 AC 82 ms
12,160 KB
testcase_07 AC 80 ms
12,160 KB
testcase_08 AC 81 ms
12,288 KB
testcase_09 AC 80 ms
12,160 KB
testcase_10 AC 81 ms
12,160 KB
testcase_11 AC 80 ms
12,160 KB
testcase_12 AC 215 ms
26,624 KB
testcase_13 AC 253 ms
31,488 KB
testcase_14 AC 213 ms
26,112 KB
testcase_15 AC 259 ms
32,768 KB
testcase_16 AC 329 ms
38,016 KB
testcase_17 AC 111 ms
14,848 KB
testcase_18 AC 190 ms
23,680 KB
testcase_19 AC 324 ms
37,632 KB
testcase_20 AC 241 ms
29,568 KB
testcase_21 AC 101 ms
13,824 KB
testcase_22 AC 256 ms
35,328 KB
testcase_23 AC 354 ms
40,320 KB
testcase_24 AC 292 ms
38,784 KB
testcase_25 AC 78 ms
12,288 KB
testcase_26 AC 81 ms
12,160 KB
testcase_27 AC 239 ms
30,464 KB
testcase_28 AC 150 ms
20,096 KB
testcase_29 AC 165 ms
22,272 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:10: warning: assigned but unused variable - dry
Main.rb:11: warning: assigned but unused variable - wet
Main.rb:12: warning: assigned but unused variable - moist
Syntax OK

ソースコード

diff #

class Yukicoder
  DRY = 0
  WET = 1
  MOIST = 2

  def initialize
    n = gets.to_i
    a = gets.chomp.split.map(&:to_i).sort

    dry = Array.new(n, false)
    wet = Array.new(n, false)
    moist = Array.new(n, false)

    answer = Array.new(3, 0)
    
    minus = a.select{|i| i < 0}.reverse
    plus = a.select{|i| i >= 0}

    mcnt = 0

    while minus.any? && plus.any?
      val = minus.shift

      if plus[0] + val < 0
        answer[DRY] += 1
        plus.shift
      else
        mcnt += 1
      end
    end

    answer[DRY] += (mcnt+minus.size)/2

    minus = a.select{|i| i < 0}.reverse
    plus = a.select{|i| i >= 0}

    trush = []

    while minus.any? && plus.any?
      val = plus.shift

      if minus[0] + val > 0
        answer[WET] += 1
        minus.shift
      else
        trush << val
      end
    end

    trush += plus

    if trush.count(0) > trush.size/2
      answer[WET] += trush.count{|i| i > 0}
    else
      answer[WET] += (trush.size/2)
    end

    checkList = Hash.new(0)

    a.each do |num|
      if num >= 0 && checkList[-num] > 0
        answer[MOIST] += 1
        checkList[-num] -= 1
      elsif num <= 0
        checkList[num] += 1
      end
    end
    
    puts answer.join(' ')
  end
end

Yukicoder.new
0