[c++] dp solution
\nconst int           N   = 10 + 3e1;\n\nint     f[N][N][N];\nint     g[N][N][N];\n\nclass Solution {\npublic:\n    vector<int> earliestAndLatest(int T, int A, 
```\nconst int           N   = 10 + 3e1;\n\nint     f[N][N][N];\nint     g[N][N][N];\n\nclass Solution {\npublic:\n    vector<int> earliestAndLatest(int T, int A, int B) {           \n        memset(f, 0x3f, sizeof(f));\n        memset(g, 0xcf, sizeof(g));\n        f[2][1][2] = 1;\n        g[2][1][2] = 1;\n        \n        for (int n = 3; n <= T; n++) {\n            for (int i = 1; i <= n; i++) {\n                for (int j = i+1; j <= n; j++) {\n                    int u = min(i,n+1-i)-1, v = min(j,n+1-j)-1;     // group index : count from 0\n                    int l = (i==u+1), r = (j==v+1);                 // on the left side\n                    \n                    int m = (n+1)/2;\n                    \n                    if (u == v) {\n                        f[n][i][j] = 1;\n                        g[n][i][j] = 1;\n                    }\n                    else if (u < v) {\n                        for (int x = 0; x <= u; x++) {\n                            for (int y = x+1; y <= v; y++) if (y-x <= v-u) {\n                                f[n][i][j] = min(f[n][i][j], f[m][l?x+1:m-(u-x)][r?y+1:m-(v-y)] + 1);\n                                g[n][i][j] = max(g[n][i][j], g[m][l?x+1:m-(u-x)][r?y+1:m-(v-y)] + 1);\n                            }\n                        }\n                    }\n                    else if (v < u) {\n                        for (int y = 0; y <= v; y++) {\n                            for (int x = y; x+1 <= u; x++) if (x-y <= u-v-1) {\n                                f[n][i][j] = min(f[n][i][j], f[m][l?x+1:m-(u-x)][r?y+1:m-(v-y)] + 1);\n                                g[n][i][j] = max(g[n][i][j], g[m][l?x+1:m-(u-x)][r?y+1:m-(v-y)] + 1);\n                            }\n                        }\n                    }\n                    \n                }\n            }\n        }\n        \n                                                    \n        if (A > B) swap(A, B);                                                              \n        return {f[T][A][B], g[T][A][B]};\n    }\n};\n\n```
[]