Snippets Collections
    int solve(int ind ,pair<int,int> alphaBeta, vector<int>& stoneValue, bool isAlice ,pair<int,int> points ={0,0}){
        if(ind >= stoneValue.size()){
            if(points.first == points.second)
                return 0;
            return points.first > points.second ? 1 : -1;
        }
        if(isAlice){
            int maxi = INT_MIN;
            int score = points.first;
            for(int i = ind; i < ind+3 && i < stoneValue.size(); i++){
                score += stoneValue[i];
                int eva = solve(i+1,alphaBeta,stoneValue, !isAlice,{score, points.second});
                maxi = max(maxi, eva);
                alphaBeta.first = max(alphaBeta.first, maxi);
                if(alphaBeta.second <= alphaBeta.first)
                    break;
            }
            return maxi;
        }
        else{
            int mini = INT_MAX;
            int score = points.second;
            for(int i = ind; i < ind+3  && i < stoneValue.size(); i++){
                score += stoneValue[i];
                int eva = solve(i+1,alphaBeta,stoneValue, !isAlice,{points.first, score});
                mini = min(mini, eva);
                alphaBeta.second = min(mini, alphaBeta.second);
                if(alphaBeta.second <= alphaBeta.first)
                    break;
            }
            return mini;
        }
    }
star

Sat May 27 2023 14:21:04 GMT+0000 (Coordinated Universal Time) https://leetcode.com/problems/stone-game-iii/

#c++ #stone_game_3 #tle

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension