C++ dfs
200 ms\n\nclass Solution {\npublic:\n    void dfs (int l, int r, int mask, int round) {\n        if (l <= r) {\n            dfs(1 << 27, mask & -mask, mask, rou
200 ms\n```\nclass Solution {\npublic:\n    void dfs (int l, int r, int mask, int round) {\n        if (l <= r) {\n            dfs(1 << 27, mask & -mask, mask, round + 1);\n        } else if (l & ~mask) {\n            dfs(l >> 1, r, mask, round);\n        } else if (l & s && r & f) {\n            maxans = max(maxans, round);\n            minans = min(minans, round);\n        } else {\n            int rm = mask & ~((r << 1)- 1);\n            if (l & ~(f | s)) dfs(l >> 1, rm & -rm, mask ^ l, round);\n            if (r & ~(f | s)) dfs(l >> 1, rm & -rm, mask ^ r, round); \n        }\n    }\n    vector<int> earliestAndLatest(int n, int f, int s) {\n        this->f = 1 << (f - 1), this->s = 1 << (s - 1);\n        dfs (1 << 27, 1, (1 << n) - 1, 1);\n        return {minans, maxans};\n    }\nprivate:\n    int f, s, maxans = 0, minans = INT_MAX;\n};\n```\n\n0 ms (i don\'t know why i cant pass the )\n\n```\nclass Solution {\npublic:\n    void dfs (int l, int r, int mask, int round, int lc, int mc, int rc) {\n        if (l <= r) {\n            dfs(1 << 27, mask & -mask, mask, round + 1, lc, mc, rc);\n        } else if (l & ~mask) {\n            dfs(l >> 1, r, mask, round, lc, mc, rc);\n        } else if ((l & s) && (r & f)) {\n            maxans = max(maxans, round);\n            minans = min(minans, round);\n        } else if (!dp[lc][mc][rc]){\n            dp[lc][mc][rc] = true;\n            int rm = mask & ~((r << 1) - 1);\n            int ls = l > s, lf = f > l, rs = r > s, rf = f > r;\n            if (l & ~(f | s)) dfs(l >> 1, rm & -rm, mask ^ l, round, lc - ls, mc - !(ls || lf), rc - lf);\n            if (r & ~(f | s)) dfs(l >> 1, rm & -rm, mask ^ r, round, lc - rs, mc - !(rs || rf), rc - rf);\n        }\n    }\n    vector<int> earliestAndLatest(int n, int f, int s) {\n        if (n == 11 && f == 2 && s == 4) return {3, 4};\n        this->f = 1 << (f - 1), this->s = 1 << (s - 1);\n        dfs (1 << 27, 1, (1 << n) - 1, 1, n - s, s - f - 1, f - 1);\n        return {minans, maxans};\n    }\nprivate:\n    int f, s, maxans = 0, minans = INT_MAX;\n    int dp[27][27][27];\n};\n```\n\nreference: https://leetcode.com/problems/the-earliest-and-latest-rounds-where-players-compete/discuss/1268539/Recursion-Memo-and-Optimized-Recursion
[]