bit mask+2DFS optimized with memorization. 0ms/2.2MB
State = [fp is the ith surviver][sp is the jth surviver][the total number of the rest survivers]\nWritten in Golan.\n\nfunc earliestAndLatest(n int, fp int, sp 
State = ```[fp is the ith surviver][sp is the jth surviver][the total number of the rest survivers]```\nWritten in Golan.\n```\nfunc earliestAndLatest(n int, fp int, sp int) []int {\n    fp--\n    sp--\n    \n    if fp > sp {\n        fp, sp = sp, fp\n    }\n    \n    ans := []int{100, 0}\n    vis := [28][28][27]bool{}\n    \n    var dfs func(mask, k, a, b, c int)\n    var dfs2 func(mask, l, r, k, a, b, c int)\n        \n    dfs = func(mask, k, a, b, c int){\n        if vis[a][b][c] {return} //[fp is the ith surviver][sp is the jth surviver][the total number of the rest survivers]\n        \n        vis[a][b][c] = true\n        k++ //round   \n        dfs2(mask, 0, n-1, k, a, b, c)\n    }\n    \n    dfs2 = func(mask, l, r, k, a, b, c int){\n        for l < r && (mask>>l)&1 == 1 {l++}\n        for l < r && (mask>>r)&1 == 1 {r--}\n        \n        if l >= r {\n            dfs(mask, k, a, b, c)\n            return\n        }\n        \n        if l == fp && r == sp {\n            if k < ans[0] {ans[0] = k}\n            if k > ans[1] {ans[1] = k}\n            return\n        }\n        \n        c--\n        if l != fp && l != sp {\n            if l < fp {\n                dfs2(mask|(1<<l), l+1, r-1, k, a-1, b-1, c)\n            }else if l < sp {\n                dfs2(mask|(1<<l), l+1, r-1, k, a, b-1, c)\n            }else{\n                dfs2(mask|(1<<l), l+1, r-1, k, a, b, c)   \n            }\n        }\n        if r != fp && r != sp {\n            if r < fp {\n                dfs2(mask|(1<<r), l+1, r-1, k, a-1, b-1, c)\n            }else if r < sp {\n                dfs2(mask|(1<<r), l+1, r-1, k, a, b-1, c)\n            }else{\n                dfs2(mask|(1<<r), l+1, r-1, k, a, b, c)   \n            }\n        }\n    }\n    \n    dfs(0, 0, fp, sp, n-2)\n    \n    return ans\n}\n```
[]