Submission #794169


Source Code Expand

n, m = gets.chomp.split(' ').map(&:to_i)
x = []
y = []
h = Hash.new { |hsh, key| hsh[key] = [] }
m.times do |i|
  x[i], y[i] = gets.chomp.split(' ').map(&:to_i)
  h[y[i]] << x[i]
end
curarr = Array.new(n)
def count(arr, idx, hsh, n)
  ans = 0
  return 1 if idx == n
  n.times do |i|
    bool = false
    arr.each do |j|
      hsh[j].each do |k|
        bool = true if k == i + 1
      end
    end
    next if arr.include?(i + 1) || bool
    nextarr = Array.new(arr)
    nextarr[idx] = i + 1
    # puts "curarr = #{nextarr}, curidx = #{idx}"
    ans += count(nextarr, idx + 1, hsh, n)
  end
  ans
end
puts count(curarr, 0, h, n)

Submission Info

Submission Time
Task D - 徒競走
User jjfifjfjfifj
Language Ruby (2.3.3)
Score 30
Code Size 654 Byte
Status TLE
Exec Time 3157 ms
Memory 2172 KiB

Judge Result

Set Name Sample Subtask1 All
Score / Max Score 0 / 0 30 / 30 0 / 70
Status
AC × 2
TLE × 1
AC × 15
AC × 15
TLE × 17
Set Name Test Cases
Sample 0_00.txt, 0_01.txt, 0_02.txt
Subtask1 0_00.txt, 0_01.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
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, 2_00.txt, 2_01.txt, 2_02.txt, 2_03.txt, 2_04.txt, 2_05.txt, 2_06.txt, 2_07.txt, 2_08.txt, 2_09.txt, 2_10.txt, 2_11.txt, 2_12.txt, 2_13.txt, 2_14.txt, 2_15.txt
Case Name Status Exec Time Memory
0_00.txt AC 17 ms 1788 KiB
0_01.txt AC 18 ms 1788 KiB
0_02.txt TLE 3153 ms 2172 KiB
1_00.txt AC 17 ms 1788 KiB
1_01.txt AC 774 ms 2044 KiB
1_02.txt AC 25 ms 1788 KiB
1_03.txt AC 36 ms 1788 KiB
1_04.txt AC 61 ms 1916 KiB
1_05.txt AC 59 ms 1916 KiB
1_06.txt AC 21 ms 1788 KiB
1_07.txt AC 20 ms 1788 KiB
1_08.txt AC 25 ms 1788 KiB
1_09.txt AC 81 ms 1916 KiB
1_10.txt AC 41 ms 1788 KiB
1_11.txt AC 786 ms 2044 KiB
1_12.txt AC 38 ms 1788 KiB
2_00.txt TLE 3154 ms 2172 KiB
2_01.txt TLE 3154 ms 2172 KiB
2_02.txt TLE 3154 ms 2172 KiB
2_03.txt TLE 3154 ms 2172 KiB
2_04.txt TLE 3154 ms 2172 KiB
2_05.txt TLE 3154 ms 2172 KiB
2_06.txt TLE 3153 ms 2172 KiB
2_07.txt TLE 3154 ms 2172 KiB
2_08.txt TLE 3157 ms 2172 KiB
2_09.txt TLE 3154 ms 2172 KiB
2_10.txt TLE 3154 ms 2172 KiB
2_11.txt TLE 3157 ms 2172 KiB
2_12.txt TLE 3153 ms 2172 KiB
2_13.txt TLE 3157 ms 2172 KiB
2_14.txt TLE 3157 ms 2172 KiB
2_15.txt TLE 3153 ms 2172 KiB