結果
問題 | No.2276 I Want AC |
ユーザー |
👑 |
提出日時 | 2023-04-21 22:12:30 |
言語 | Lua (LuaJit 2.1.1734355927) |
結果 |
AC
|
実行時間 | 42 ms / 2,000 ms |
コード長 | 760 bytes |
コンパイル時間 | 288 ms |
コンパイル使用メモリ | 6,816 KB |
実行使用メモリ | 7,168 KB |
最終ジャッジ日時 | 2024-11-06 15:43:12 |
合計ジャッジ時間 | 2,770 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 56 |
ソースコード
local mmi, mma = math.min, math.maxlocal n = io.read("*n", "*l")local s = io.read()local acnt = 0local base = 0local ta, tc = {}, {}for i = 1, n dolocal b = s:sub(i, i)if b == "A" thenacnt = acnt + 1elseif b == "C" thenbase = base + acntelsetable.insert(ta, acnt)endendlocal ccnt = 0local tmp = #tafor i = n, 1, -1 dolocal b = s:sub(i, i)if b == "A" thenelseif b == "C" thenccnt = ccnt + 1elsetable.insert(tc, ccnt)base = base + ta[tmp]tmp = tmp - 1endendfor i = 1, #ta dolocal j = #ta + 1 - iif j <= i then break endtc[i], tc[j] = tc[j], tc[i]endlocal cand = basefor i = 1, #ta dobase = base - ta[i] + tc[i]cand = mma(cand, base + i * (#ta - i))endprint(cand)