ProconIO.jl -- Easy IO handler for competitive programming in Julia

Inspired by proconio-rs, I wrote ProconIO.jl to handle inputs for competitive programming contests.

The usage is similar to proconio-rs. You need to specify the variable name and its structure.

@input a = Int

Multiple variables need to be nested in a block.

@input begin
    a = Char
    b = Float32
    c = (Int, Char)
    d = String
    e = Bool
end

Arrays need to be specified in the form of [type; shape].

@input begin
    a = [Int; 3]
    b = [Float32; (2, 3)]
end

Complex structures can also be handled.

@input a = [(Int, [Int; (2, 2)], Char); (2, 2)]

In CP, the size of arrays is usually specified by the input itself. This can be handled by using variables already read in.

Note that ProconIO.jl follows Julia’s column-major convention, instead of the row-major which is commonly used in CP. So you may need to swap the row and column indices when reading the array.

@input begin
    n = Int
    m = Int
    v = [Int; (m, n)]
end

If you prefer a row-major flavor, you can use a vector of vectors instead.

@input begin
    n = Int
    m = Int
    v = [[Int; m]; n]
end

Sometimes the input is a vector of variable-length vectors. This can be handled by leaving out the shape and reading it from the input instead. The following code reads in a vector of n variable-length vectors.

@input begin
    n = Int
    v = [[Int; ]; n]
end
8 Likes

Just as feedback, most likely it’s me not being used to the field, but you should consider that an announcement here reaches a diverce audience, so it could be more effective if some background is given… :slight_smile:

4 Likes

Typical scenarios can be platforms like Codeforces or AtCoder. (Although only the latter currently supports Julia.)

1 Like