結果

問題 No.190 Dry Wet Moist
ユーザー simansiman
提出日時 2016-03-29 05:05:03
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 1,335 bytes
コンパイル時間 219 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 41,216 KB
最終ジャッジ日時 2024-04-10 05:39:27
合計ジャッジ時間 6,910 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
12,032 KB
testcase_01 AC 82 ms
12,288 KB
testcase_02 AC 80 ms
12,032 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 75 ms
12,288 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 330 ms
38,428 KB
testcase_23 WA -
testcase_24 AC 326 ms
38,528 KB
testcase_25 AC 84 ms
12,160 KB
testcase_26 AC 81 ms
12,288 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 = Array.new(2*n+1, false)

    a.sort_by{|i| i.abs * 10**5 + i}.each_cons(2).with_index do |j,index|
      if j[0] + j[1] == 0 && !checkList[index] && !checkList[index+1]
        answer[MOIST] += 1
        checkList[index] = true
        checkList[index+1] = true
      end
    end
    
    puts answer.join(' ')
  end
end

Yukicoder.new
0