def tablica(Dzwieki): Dzwieki = Dzwieki.split() for i in range(len(Dzwieki)): Dzwieki[i] = int(Dzwieki[i]) return(Dzwieki) def main(Dlugosc, Dzwieki): wynik = 0 tab = [] Dzwieki = tablica(Dzwieki) m1 = m2 = w1 = w2 = 0 for i in range(Dlugosc-1): if Dzwieki[i]<Dzwieki[i+1]: tab.append('M') elif Dzwieki[i]>Dzwieki[i+1]: tab.append('W') else: tab.append('R') s = len(tab) for i in range(0,s,2): if tab[i] == 'W': w1 += 1 if tab[i] == 'M': m1 += 1 for i in range(1,s,2): if tab[i] == 'W': w2 += 1 if tab[i] == 'M': m2 += 1 if w1 + m2 >= w2 + m1: for i in range(0,s,2): if tab[i] != 'W': tab[i] = 'F' else: tab[i] = 'T' for i in range(1,s,2): if tab[i] != 'M': tab[i] = 'F' else: tab[i] = "T" if w1 + m2 < w2 + m1: for i in range(0,s,2): if tab[i] != 'M': tab[i] = 'F' else: tab[i] = 'T' for i in range(1,s,2): if tab[i] != 'W': tab[i] = 'F' else: tab[i] = 'T' i = 0 while i < Dlugosc - 1: g = 0 while i<Dlugosc-1 and tab[i] == 'F': i+=1 g += 1 while i<Dlugosc-1 and tab[i] == 'T': i+=1 if g%2==0: wynik+=g/2 else: wynik += (g+1)/2 print(int(wynik)) if __name__ == '__main__': main(int(input()), input())
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | def tablica(Dzwieki): Dzwieki = Dzwieki.split() for i in range(len(Dzwieki)): Dzwieki[i] = int(Dzwieki[i]) return(Dzwieki) def main(Dlugosc, Dzwieki): wynik = 0 tab = [] Dzwieki = tablica(Dzwieki) m1 = m2 = w1 = w2 = 0 for i in range(Dlugosc-1): if Dzwieki[i]<Dzwieki[i+1]: tab.append('M') elif Dzwieki[i]>Dzwieki[i+1]: tab.append('W') else: tab.append('R') s = len(tab) for i in range(0,s,2): if tab[i] == 'W': w1 += 1 if tab[i] == 'M': m1 += 1 for i in range(1,s,2): if tab[i] == 'W': w2 += 1 if tab[i] == 'M': m2 += 1 if w1 + m2 >= w2 + m1: for i in range(0,s,2): if tab[i] != 'W': tab[i] = 'F' else: tab[i] = 'T' for i in range(1,s,2): if tab[i] != 'M': tab[i] = 'F' else: tab[i] = "T" if w1 + m2 < w2 + m1: for i in range(0,s,2): if tab[i] != 'M': tab[i] = 'F' else: tab[i] = 'T' for i in range(1,s,2): if tab[i] != 'W': tab[i] = 'F' else: tab[i] = 'T' i = 0 while i < Dlugosc - 1: g = 0 while i<Dlugosc-1 and tab[i] == 'F': i+=1 g += 1 while i<Dlugosc-1 and tab[i] == 'T': i+=1 if g%2==0: wynik+=g/2 else: wynik += (g+1)/2 print(int(wynik)) if __name__ == '__main__': main(int(input()), input()) |