結果

問題 No.2623 Room Allocation
ユーザー halshals
提出日時 2024-02-29 17:30:44
言語 Julia
(1.10.2)
結果
AC  
実行時間 1,287 ms / 2,000 ms
コード長 1,521 bytes
コンパイル時間 33 ms
コンパイル使用メモリ 6,816 KB
実行使用メモリ 310,704 KB
最終ジャッジ日時 2024-04-09 14:36:10
合計ジャッジ時間 28,842 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 585 ms
260,484 KB
testcase_01 AC 592 ms
262,528 KB
testcase_02 AC 579 ms
262,716 KB
testcase_03 AC 587 ms
264,480 KB
testcase_04 AC 579 ms
262,072 KB
testcase_05 AC 577 ms
261,308 KB
testcase_06 AC 885 ms
298,872 KB
testcase_07 AC 888 ms
296,844 KB
testcase_08 AC 815 ms
298,312 KB
testcase_09 AC 892 ms
297,632 KB
testcase_10 AC 852 ms
308,556 KB
testcase_11 AC 842 ms
310,704 KB
testcase_12 AC 645 ms
290,048 KB
testcase_13 AC 643 ms
290,816 KB
testcase_14 AC 978 ms
310,420 KB
testcase_15 AC 801 ms
291,340 KB
testcase_16 AC 612 ms
276,768 KB
testcase_17 AC 595 ms
263,364 KB
testcase_18 AC 804 ms
291,296 KB
testcase_19 AC 792 ms
291,156 KB
testcase_20 AC 807 ms
289,736 KB
testcase_21 AC 823 ms
292,272 KB
testcase_22 AC 798 ms
291,176 KB
testcase_23 AC 647 ms
290,000 KB
testcase_24 AC 820 ms
291,384 KB
testcase_25 AC 789 ms
291,584 KB
testcase_26 AC 598 ms
266,296 KB
testcase_27 AC 1,287 ms
306,916 KB
testcase_28 AC 1,006 ms
293,192 KB
testcase_29 AC 989 ms
290,776 KB
testcase_30 AC 1,215 ms
303,140 KB
testcase_31 AC 676 ms
276,068 KB
testcase_32 AC 1,010 ms
291,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

function main()
    n, x, y = int(inputs())
    wantA_by_group = zeros(Int, x + y)
    wantB_by_group = zeros(Int, x + y)
    for i = 1:n
        p, c = inputs()
        p = int(p)
        if c == "A"
            wantA_by_group[(i-1)%(x+y)+1] += p
        else
            wantB_by_group[(i-1)%(x+y)+1] += p
        end
    end
    ans = 0
    tmp = []
    for i = 1:x+y
        push!(tmp, (abs(wantA_by_group[i] - wantB_by_group[i]), i))
    end
    sort!(tmp, by=x -> x[1], rev=true)
    ischecked = falses(x + y)
    for i = 1:x+y
        val, group = tmp[i]
        if ischecked[group]
            continue
        end
        ischecked[group] = true
        if wantA_by_group[group] > wantB_by_group[group]
            if x > 0
                ans += wantA_by_group[group]
                x -= 1
            else
                ans += wantB_by_group[group]
                y -= 1
            end
        else
            if y > 0
                ans += wantB_by_group[group]
                y -= 1
            else
                ans += wantA_by_group[group]
                x -= 1
            end
        end
    end
    println(ans)
end
# --------input func----------
input() = readline()
inputs() = split(readline())
int(s::AbstractChar) = parse(Int, s)
int(s::AbstractString) = parse(Int, s)
int(v::AbstractArray) = map(x -> parse(Int, x), v)
debug(x...) = println(stderr, x...)
isfile("myinput.txt") && (mystdin = open("myinput.txt", "r"); redirect_stdin(mystdin))
main()
@isdefined(mystdin) && close(mystdin)
0