Submission #694231


Source Code Expand

function main()
    R, C = io.read "n", io.read "n"
    sy, sx = io.read "n", io.read "n"
    gy, gx = io.read "n", io.read "n"
    io.read "l"
    c = { }
    for i = 1, R do
        c[i] = { }
        for j = 1, C do
            c[i][j] = io.read(1) == "." and math.huge or nil
        end
        io.read "l"
    end
    q = Queue()
    q:offer { sy, sx }
    c[sy][sx] = 0
    for e in q:coroPoll() do
        if e[1] == gy and e[2] == gx then
            break
        end
        for _, d in pairs(delta) do
            local y, x = e[1] + d[1], e[2] + d[2]
            if c[y][x] == math.huge then
                c[y][x] = c[e[1]][e[2]] + 1
                q:offer { y, x }
            end
        end
    end
    print(c[gy][gx])
end

delta = { { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 } }

function Queue()
    local o = { }
    local t = { }
    local front = 1
    local rear = 1

    function o:offer(e)
        t[front] = e
        front = front + 1
    end

    function o:poll()
        if rear == front then
            return nil
        end
        local e = t[rear]
        t[rear] = nil
        rear = rear + 1
        return e
    end

    function o:peek()
        return t[rear]
    end

    function o:coroPoll()
        return coroutine.wrap(
            function()
                while rear ~= front do
                    coroutine.yield(self:poll())
                end
            end
        )
    end

    return o
end

main()

Submission Info

Submission Time
Task A - 幅優先探索
User bovini
Language Lua (5.3.2)
Score 100
Code Size 1530 Byte
Status AC
Exec Time 14 ms
Memory 888 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 3
AC × 25
Set Name Test Cases
Sample subtask0_sample01.txt, subtask0_sample02.txt, subtask0_sample03.txt
All subtask0_sample01.txt, subtask0_sample02.txt, subtask0_sample03.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_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt, subtask1_17.txt, subtask1_18.txt, subtask1_19.txt, subtask1_20.txt, subtask1_21.txt, subtask1_22.txt
Case Name Status Exec Time Memory
subtask0_sample01.txt AC 12 ms 888 KiB
subtask0_sample02.txt AC 4 ms 256 KiB
subtask0_sample03.txt AC 14 ms 504 KiB
subtask1_01.txt AC 10 ms 504 KiB
subtask1_02.txt AC 10 ms 504 KiB
subtask1_03.txt AC 10 ms 504 KiB
subtask1_04.txt AC 14 ms 504 KiB
subtask1_05.txt AC 10 ms 504 KiB
subtask1_06.txt AC 12 ms 504 KiB
subtask1_07.txt AC 6 ms 256 KiB
subtask1_08.txt AC 6 ms 256 KiB
subtask1_09.txt AC 10 ms 504 KiB
subtask1_10.txt AC 7 ms 376 KiB
subtask1_11.txt AC 14 ms 504 KiB
subtask1_12.txt AC 12 ms 504 KiB
subtask1_13.txt AC 10 ms 504 KiB
subtask1_14.txt AC 5 ms 256 KiB
subtask1_15.txt AC 11 ms 504 KiB
subtask1_16.txt AC 11 ms 504 KiB
subtask1_17.txt AC 13 ms 504 KiB
subtask1_18.txt AC 12 ms 504 KiB
subtask1_19.txt AC 10 ms 504 KiB
subtask1_20.txt AC 11 ms 504 KiB
subtask1_21.txt AC 11 ms 504 KiB
subtask1_22.txt AC 10 ms 504 KiB