Submission #2867064


Source Code Expand

Copy
MOD = 1_000_000_007

class Combination
  def initialize
    @fact = (1..10**5*2+1).to_a
    @fact.each_with_index do |e, idx|
      @fact[idx] = @fact[idx] * @fact[idx-1] % MOD if idx > 0
    end
  end

  def choose(n, r)
    return 0 if not (0 <= r and r <= n)
    return 1 if r == 0 or r == n
    fact(n) * inverse( fact(r) * fact(n-r) )
  end

  def fact(n)
    @fact[n-1]
  end

  def inverse(x)
    pow(x, MOD-2)
  end

  def pow(x, n)
    ans = 1
    while n > 0
      ans = ans * x % MOD if n.odd?
      x = x * x % MOD
      n >>= 1
    end
    ans
  end
end

lines = $stdin.read
array = lines.split("\n")
H,W,A,B = array[0].split(" ").map(&:to_i)

@comb = Combination.new
ans = 0

max_n1,max_n2 = 0,0

for i in B...W
  n1,r1 = H-A-1+i,i
  #max_n1 = [n1,max_n1].max
  #puts max_n1
  ans1  = @comb.choose(n1,r1) % MOD

  h,w   = A-1,W-1-i
  n2,r2 = h+w,w
  #max_n2 = [n2,max_n2].max
  #puts max_n2
  ans2  = @comb.choose(n2,r2) % MOD

  ans += ans1*ans2%MOD
end

puts ans%MOD

Submission Info

Submission Time
Task D - いろはちゃんとマス目 / Iroha and a Grid
User hiroyuking
Language Ruby (2.3.3)
Score 400
Code Size 1041 Byte
Status
Exec Time 978 ms
Memory 3452 KB

Compile Error

./Main.rb:43: warning: assigned but unused variable - max_n1
./Main.rb:43: warning: assigned but unused variable - max_n2

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 subtask0_01.txt, subtask0_02.txt, subtask0_03.txt, subtask0_04.txt
All 400 / 400 subtask0_01.txt, subtask0_02.txt, subtask0_03.txt, subtask0_04.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_max.txt, subtask2_01.txt, subtask2_02.txt, subtask2_03.txt, subtask2_04.txt, subtask2_05.txt, subtask2_06.txt, subtask2_07.txt, subtask2_08.txt, subtask2_09.txt, subtask2_10.txt, subtask2_max.txt
Case Name Status Exec Time Memory
subtask0_01.txt 51 ms 3452 KB
subtask0_02.txt 51 ms 3452 KB
subtask0_03.txt 51 ms 3452 KB
subtask0_04.txt 457 ms 3452 KB
subtask1_01.txt 52 ms 3452 KB
subtask1_02.txt 51 ms 3452 KB
subtask1_03.txt 52 ms 3452 KB
subtask1_04.txt 51 ms 3452 KB
subtask1_05.txt 51 ms 3452 KB
subtask1_06.txt 51 ms 3452 KB
subtask1_07.txt 51 ms 3452 KB
subtask1_08.txt 51 ms 3452 KB
subtask1_09.txt 52 ms 3452 KB
subtask1_10.txt 51 ms 3452 KB
subtask1_max.txt 51 ms 3452 KB
subtask2_01.txt 88 ms 3452 KB
subtask2_02.txt 58 ms 3452 KB
subtask2_03.txt 78 ms 3452 KB
subtask2_04.txt 100 ms 3452 KB
subtask2_05.txt 82 ms 3452 KB
subtask2_06.txt 955 ms 3452 KB
subtask2_07.txt 79 ms 3452 KB
subtask2_08.txt 568 ms 3452 KB
subtask2_09.txt 358 ms 3452 KB
subtask2_10.txt 978 ms 3452 KB
subtask2_max.txt 103 ms 3452 KB