Submission #826157


Source Code Expand

class Box
  def initialize(r,w)
    @red = r
    @white = w
  end
  def putRed(t)
    @red += t
  end
  def putWhite(t)
    @white += t
  end
  def getRed
    if(@red > 0)then
      @red -= 1
      return 1
    else
      return 0
    end
  end
  def getWhite
    if(@white > 0)then
      @white -= 1
      return 1
    else
      return 0
    end
  end
  def chkRed
    return @red
  end
  def chkWhite
    return @white
  end
end

N,M = gets.split(/\s/).map {|s|s.to_i}
boxList = Array.new(N)
N.times do |i|
  if(i==0)then
    boxList[i] = Box.new(1,0)
  else
    boxList[i] = Box.new(0,1)
  end
end

# (1) 赤だけあるときは、カウントしない。移動は赤にする。
# (2) 赤と白があるときは、カウントする。移動は赤にする。
# (3) 白だけあるときは、カウントしない。移動は白にする。
cnt = 1
redidx = -1
M.times do |i|
  x,y = gets.split(/\s/).map {|s|s.to_i}
  if(boxList[x-1].chkRed==1 && boxList[x-1].chkWhite==0)then
    # (1)
    boxList[y-1].putRed(boxList[x-1].getRed)
    #puts "(1)"
  elsif(boxList[x-1].chkRed==1 && boxList[x-1].chkWhite > 0)then
    # (2)
    cnt += 1
    # redがあればredを移動し、なければwhiteを移動する
    boxList[y-1].putRed(boxList[x-1].getRed)
    redidx = x
    #puts "(2)"
  else
    # (3) + 同じ箱から赤も白も取り去った記録があれば、cntを減らす
    boxList[y-1].putWhite(boxList[x-1].getWhite)
    if(x==redidx && boxList[x-1].chkWhite==0)then
      cnt -= 1
    end
    #puts "(3)"
  end
end

puts cnt

Submission Info

Submission Time
Task B - Box and Ball
User vih3BP
Language Ruby (2.3.3)
Score 0
Code Size 1623 Byte
Status WA
Exec Time 650 ms
Memory 11132 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 3
AC × 9
WA × 18
Set Name Test Cases
Sample 0_00.txt, 0_01.txt, 0_02.txt
All 0_00.txt, 0_01.txt, 0_02.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt, 1_23.txt
Case Name Status Exec Time Memory
0_00.txt AC 18 ms 1916 KB
0_01.txt AC 17 ms 1788 KB
0_02.txt AC 17 ms 1788 KB
1_00.txt AC 17 ms 1788 KB
1_01.txt AC 22 ms 1788 KB
1_02.txt AC 18 ms 1788 KB
1_03.txt AC 17 ms 1788 KB
1_04.txt AC 607 ms 11132 KB
1_05.txt AC 650 ms 11132 KB
1_06.txt WA 578 ms 7036 KB
1_07.txt WA 615 ms 7036 KB
1_08.txt WA 380 ms 7164 KB
1_09.txt WA 419 ms 11132 KB
1_10.txt WA 177 ms 10748 KB
1_11.txt WA 233 ms 4220 KB
1_12.txt WA 99 ms 7932 KB
1_13.txt WA 512 ms 10492 KB
1_14.txt WA 268 ms 4348 KB
1_15.txt WA 448 ms 3068 KB
1_16.txt WA 68 ms 5500 KB
1_17.txt WA 600 ms 11132 KB
1_18.txt WA 550 ms 7420 KB
1_19.txt WA 555 ms 4348 KB
1_20.txt WA 520 ms 4220 KB
1_21.txt WA 477 ms 7420 KB
1_22.txt WA 589 ms 6780 KB
1_23.txt WA 210 ms 10748 KB