結果

問題 No.2276 I Want AC
ユーザー 👑 obakyanobakyan
提出日時 2023-04-21 22:12:30
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 760 bytes
コンパイル時間 295 ms
コンパイル使用メモリ 5,376 KB
実行使用メモリ 7,168 KB
最終ジャッジ日時 2024-04-24 08:19:30
合計ジャッジ時間 2,265 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 7 ms
5,376 KB
testcase_12 AC 20 ms
5,376 KB
testcase_13 AC 7 ms
5,376 KB
testcase_14 AC 5 ms
5,376 KB
testcase_15 AC 12 ms
5,376 KB
testcase_16 AC 10 ms
5,376 KB
testcase_17 AC 23 ms
5,376 KB
testcase_18 AC 14 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 33 ms
5,376 KB
testcase_21 AC 8 ms
5,376 KB
testcase_22 AC 5 ms
5,376 KB
testcase_23 AC 26 ms
5,376 KB
testcase_24 AC 24 ms
5,376 KB
testcase_25 AC 25 ms
5,376 KB
testcase_26 AC 38 ms
5,376 KB
testcase_27 AC 30 ms
5,376 KB
testcase_28 AC 20 ms
5,376 KB
testcase_29 AC 14 ms
5,376 KB
testcase_30 AC 30 ms
5,376 KB
testcase_31 AC 8 ms
5,376 KB
testcase_32 AC 27 ms
5,376 KB
testcase_33 AC 28 ms
5,376 KB
testcase_34 AC 28 ms
7,040 KB
testcase_35 AC 7 ms
5,376 KB
testcase_36 AC 7 ms
5,376 KB
testcase_37 AC 21 ms
7,168 KB
testcase_38 AC 7 ms
5,376 KB
testcase_39 AC 7 ms
5,376 KB
testcase_40 AC 7 ms
5,376 KB
testcase_41 AC 7 ms
5,376 KB
testcase_42 AC 23 ms
7,040 KB
testcase_43 AC 22 ms
7,040 KB
testcase_44 AC 10 ms
5,376 KB
testcase_45 AC 28 ms
5,376 KB
testcase_46 AC 33 ms
5,376 KB
testcase_47 AC 11 ms
5,376 KB
testcase_48 AC 11 ms
5,376 KB
testcase_49 AC 39 ms
5,376 KB
testcase_50 AC 32 ms
5,376 KB
testcase_51 AC 25 ms
5,376 KB
testcase_52 AC 24 ms
5,376 KB
testcase_53 AC 25 ms
5,376 KB
testcase_54 AC 15 ms
5,376 KB
testcase_55 AC 12 ms
5,376 KB
testcase_56 AC 11 ms
5,376 KB
testcase_57 AC 9 ms
5,376 KB
testcase_58 AC 10 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local mmi, mma = math.min, math.max
local n = io.read("*n", "*l")
local s = io.read()
local acnt = 0
local base = 0
local ta, tc = {}, {}
for i = 1, n do
  local b = s:sub(i, i)
  if b == "A" then
    acnt = acnt + 1
  elseif b == "C" then
    base = base + acnt
  else
    table.insert(ta, acnt)
  end
end

local ccnt = 0
local tmp = #ta
for i = n, 1, -1 do
  local b = s:sub(i, i)
  if b == "A" then
  elseif b == "C" then
    ccnt = ccnt + 1
  else
    table.insert(tc, ccnt)
    base = base + ta[tmp]
    tmp = tmp - 1
  end
end
for i = 1, #ta do
  local j = #ta + 1 - i
  if j <= i then break end
  tc[i], tc[j] = tc[j], tc[i]
end

local cand = base
for i = 1, #ta do
  base = base - ta[i] + tc[i]
  cand = mma(cand, base + i * (#ta - i))
end
print(cand)
0