結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 0 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 RE -
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 RE -
testcase_12 RE -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 RE -
testcase_24 RE -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 RE -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 7 ms
5,376 KB
testcase_36 AC 6 ms
5,376 KB
testcase_37 AC 21 ms
7,168 KB
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 11 ms
5,376 KB
testcase_45 AC 26 ms
5,376 KB
testcase_46 WA -
testcase_47 RE -
testcase_48 RE -
testcase_49 WA -
testcase_50 WA -
testcase_51 RE -
testcase_52 RE -
testcase_53 WA -
testcase_54 RE -
testcase_55 RE -
testcase_56 RE -
testcase_57 AC 9 ms
5,376 KB
testcase_58 RE -
権限があれば一括ダウンロードができます

ソースコード

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
    tmp = tmp - 1
  elseif b == "C" then
    ccnt = ccnt + 1
  else
    table.insert(tc, ccnt)
    base = base + ta[tmp]
  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