935B - Fafa and the Gates - CodeForces Solution


implementation *900

Please click on ads to support us..

Python Code:

def sum(n, S):
    out = 0
    
    i = 0
    j = 0
    Loc = "*"
    
    for c in S:
        
        if c == "U":
            i += 1 
        if c == "R":
            j += 1
            
        prevLoc = Loc
        
        if i > j and prevLoc != "L":
            if Loc != "*":
                out += 1 
            Loc = "L"
        elif i < j and prevLoc != "R":
            if Loc != "*":
                out += 1
            Loc = "R"
            
    return out
            
            
        
        
            
        
    return out
    
n = input()
S = input()
print(sum(n, S))
            
        
            
            
        
    


Comments

Submit
0 Comments
More Questions

Divisibility
A. Movement
Numbers in a matrix
Sequences
Split houses
Divisible
Three primes
Coprimes
Cost of balloons
One String No Trouble
Help Jarvis!
Lift queries
Goki and his breakup
Ali and Helping innocent people
Book of Potion making
Duration
Birthday Party
e-maze-in
Bricks Game
Char Sum
Two Strings
Anagrams
Prime Number
Lexical Sorting Reloaded
1514A - Perfectly Imperfect Array
580A- Kefa and First Steps
1472B- Fair Division
996A - Hit the Lottery
MSNSADM1 Football
MATCHES Playing with Matches