結果
問題 |
No.1268 Fruit Rush 2
|
ユーザー |
👑 |
提出日時 | 2021-07-29 22:57:46 |
言語 | Lua (LuaJit 2.1.1734355927) |
結果 |
AC
|
実行時間 | 565 ms / 2,000 ms |
コード長 | 653 bytes |
コンパイル時間 | 323 ms |
コンパイル使用メモリ | 6,688 KB |
実行使用メモリ | 22,552 KB |
最終ジャッジ日時 | 2024-09-14 19:29:47 |
合計ジャッジ時間 | 11,889 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 33 |
ソースコード
local ffi = require("ffi") local C = ffi.C ffi.cdef[[ long long atoll(const char*); ]] local function lltonumber(str) return C.atoll(str) end local n = io.read("*n", "*l") local s = io.read() local a = {} for w in s:gmatch("%d+") do table.insert(a, lltonumber(w)) end table.sort(a) local len = {} for i = 1, n do len[i] = 0 end for i = n - 1, 1, -1 do if a[i] + 2LL == a[i + 1] then len[i] = len[i + 1] + 1 elseif i + 2 <= n and a[i] + 2LL == a[i + 2] then len[i] = len[i + 2] + 1 else len[i] = 0 end end local ret = n for i = 1, n - 1 do if a[i] + 1LL == a[i + 1] then ret = ret + 1 + len[i + 1] end end print(ret)