Submission #2119887


Source Code Expand

N = gets.chomp.to_i
A = Array.new(2).map{Array.new(N)}
2.times do |n|
    A[n] = gets.chomp.split.map(&:to_i)
end
dir = [[1,0],[0,1]]
node = []
node.push({:pos => [0,0], :score => 0, :log => Array.new(2).map{Array.new(N)}})
ans = []
while !node.empty?
    cur = node.shift

    cur[:score] += A[cur[:pos][0]][cur[:pos][1]]
    if cur[:pos][0] == 1 && cur[:pos][1] == N-1
        ans.push(cur[:score])
        next
    end

    dir.each do |d|
        childY = cur[:pos][0]+d[0]
        childX = cur[:pos][1]+d[1]
        if childY.between?(0,1) && childX.between?(0,N-1)
            if !cur[:log][childY][childX]
                cur[:log][childY][childX] = 0
                node.push({:pos => [childY, childX], :score => cur[:score], :log => Marshal.load(Marshal.dump(cur[:log]))})
            end
        end
    end
end
print "#{ans.max}\n"

Submission Info

Submission Time
Task C - Candies
User takoda
Language Ruby (2.3.3)
Score 300
Code Size 872 Byte
Status AC
Exec Time 138 ms
Memory 5884 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 4
AC × 16
Set Name Test Cases
Sample sample01.txt, sample02.txt, sample03.txt, sample04.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, sample01.txt, sample02.txt, sample03.txt, sample04.txt
Case Name Status Exec Time Memory
01.txt AC 133 ms 5884 KB
02.txt AC 135 ms 5884 KB
03.txt AC 134 ms 5884 KB
04.txt AC 133 ms 5884 KB
05.txt AC 134 ms 5884 KB
06.txt AC 8 ms 1788 KB
07.txt AC 7 ms 1788 KB
08.txt AC 7 ms 1788 KB
09.txt AC 134 ms 5884 KB
10.txt AC 134 ms 5884 KB
11.txt AC 138 ms 5884 KB
12.txt AC 137 ms 5884 KB
sample01.txt AC 7 ms 1788 KB
sample02.txt AC 7 ms 1788 KB
sample03.txt AC 7 ms 1788 KB
sample04.txt AC 7 ms 1788 KB