Submission #791394
Source Code Expand
nm = gets.split.map {|i| i.to_i}
N = nm[0]
M = nm[1]
rules = {}
N.times do |i|
rules[(i+1).to_s] = []
end
M.times do
xy = gets.split.map {|i| i.to_i}
rules[xy[0].to_s].push xy[1]
end
rules.each do |k,v|
v.sort!
end
def search(current, arr, rules)
current_rule = rules[current.to_s]
if arr.length == 0 && current_rule.length == 0
return 1
end
if !current.nil? && current_rule && current_rule.length > 0
rule_index = 0
arr_index = 0
while(arr_index < arr.length && rule_index < current_rule.length)
if current_rule[rule_index] > arr[arr_index]
arr_index += 1
elsif current_rule[rule_index] == arr[arr_index]
rule_index += 1
else
break
end
end
unless rule_index == current_rule.length
return 0
end
end
sum = 0
arr.each.with_index do |i, index|
if index == 0
sum += search(i, arr[1..arr.length-1], rules)
elsif index == arr.length - 1
sum += search(i, arr[0..arr.length-2], rules)
else
sum += search(i, arr[0..index-1].concat(arr[(index+1)..arr.length-1]), rules)
end
end
sum
end
numbers = (1..N).map {|i| i}
puts search(nil, numbers, rules)
Submission Info
| Submission Time | |
|---|---|
| Task | D - 徒競走 |
| User | tanaka0x |
| Language | Ruby (2.3.3) |
| Score | 30 |
| Code Size | 1251 Byte |
| Status | TLE |
| Exec Time | 3157 ms |
| Memory | 2044 KiB |
Judge Result
| Set Name | Sample | Subtask1 | All | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 30 / 30 | 0 / 70 | ||||||||||
| Status |
|
|
|
| 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 | 18 ms | 1788 KiB |
| 0_01.txt | AC | 19 ms | 1788 KiB |
| 0_02.txt | TLE | 3157 ms | 1916 KiB |
| 1_00.txt | AC | 18 ms | 1788 KiB |
| 1_01.txt | AC | 191 ms | 1788 KiB |
| 1_02.txt | AC | 23 ms | 1916 KiB |
| 1_03.txt | AC | 26 ms | 1916 KiB |
| 1_04.txt | AC | 34 ms | 1788 KiB |
| 1_05.txt | AC | 33 ms | 1788 KiB |
| 1_06.txt | AC | 21 ms | 1788 KiB |
| 1_07.txt | AC | 21 ms | 1788 KiB |
| 1_08.txt | AC | 22 ms | 1788 KiB |
| 1_09.txt | AC | 36 ms | 1788 KiB |
| 1_10.txt | AC | 28 ms | 1788 KiB |
| 1_11.txt | AC | 197 ms | 1788 KiB |
| 1_12.txt | AC | 27 ms | 1916 KiB |
| 2_00.txt | TLE | 3157 ms | 1916 KiB |
| 2_01.txt | AC | 2114 ms | 2044 KiB |
| 2_02.txt | TLE | 3157 ms | 2044 KiB |
| 2_03.txt | TLE | 3157 ms | 1916 KiB |
| 2_04.txt | TLE | 3157 ms | 1916 KiB |
| 2_05.txt | TLE | 3157 ms | 2044 KiB |
| 2_06.txt | TLE | 3157 ms | 2044 KiB |
| 2_07.txt | AC | 1068 ms | 2044 KiB |
| 2_08.txt | TLE | 3157 ms | 1916 KiB |
| 2_09.txt | TLE | 3157 ms | 2044 KiB |
| 2_10.txt | TLE | 3157 ms | 1916 KiB |
| 2_11.txt | AC | 2361 ms | 2044 KiB |
| 2_12.txt | TLE | 3157 ms | 1916 KiB |
| 2_13.txt | TLE | 3157 ms | 1916 KiB |
| 2_14.txt | TLE | 3157 ms | 1916 KiB |
| 2_15.txt | TLE | 3157 ms | 1916 KiB |