class Solution { public: vector<int> earliestAndLatest(int n, int firstPlayer, int…
- User
class Solution { public: vector earliestAndLatest(int n, int firstPlayer, int secondPlayer) { if(firstPlayer+secondPlayer == n+1) return {1,1}; vector ans(2); vector temp; ans[0] = INT_MAX; if(firstPlayer+secondPlayer > n+1) { int a = firstPlayer; firstPlayer = n+1-secondPlayer; secondPlayer = n+1-a; }
codefor(int i=1;i<=min(firstPlayer, n+1-secondPlayer);i++) { if(n+1 < 2*secondPlayer) { int a = (2*secondPlayer-(n+1))/2 + 1; for(int j=0;j<n+1-secondPlayer-firstPlayer;j++) { temp = earliestAndLatest((n-1)/2 + 1, i, i+a+j); ans[0] = min(ans[0], temp[0]+1); ans[1] = max(ans[1], temp[1]+1); } } else { for(int j=1;j<=secondPlayer-firstPlayer;j++) { temp = earliestAndLatest((n-1)/2 + 1, i, i+j); ans[0] = min(ans[0], temp[0]+1); ans[1] = max(ans[1], temp[1]+1); } } } return ans; }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.