prompt
string
response
string
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author sbhanday */ public f...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
import java.util.Scanner; public class DiagonalWalking { public static void main(String args[]) { Scanner in = new Scanner(System.in); int n = in.nextInt(); in.nextLine(); char s[]; String str = in.nextLine(); s = str.toCharArray(); int count =0; for(int i =0; i<s.length-1;i++) ...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual soluti...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n = int(input()) s = input() for i in range(n - 1): if s[i:i + 2] == 'RU': s = s.replace('RU', 'DO', 1) if s[i:i + 2] == 'UR': s = s.replace('UR', 'DO', 1) print(s.count('U') + s.count('R') + s.count('D'))
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n = int(input()) s = input() cnt = 0 i = 0 while i < n - 1: i += 1 if (s[i] == 'R' and s[i - 1] == 'U') or (s[i] == 'U' and s[i - 1] == 'R'): i += 1 cnt += 1 print(len(s) - cnt)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
l = int(input()) ip = input() count = 0 i = 0 while i < l: if i + 1 < l: if ip[i] == ip[i+1]: i = i + 1 else: i = i + 2 count +=1 else: i+=1 count+=1 print(count)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
x=int(input());a=input()+'g';i=p=0 while i<x: if a[i]+a[i+1] in ['RU','UR']:i+=2;p+=1 else:i+=1;p+=1 print(p)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, c = 0; string s; cin >> n; cin >> s; for (int i = 0; i < n - 1; i++) { if (s[i] == 'R' && s[i + 1] == 'U' || s[i] == 'U' && s[i + 1] == 'R') { c++; i = i + 1; } } cout << s.l...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
from collections import defaultdict def solution(): n = int(input()) s = input() d = defaultdict(int) for x in s: d[x] += 1 i = 0 while i < len(s)-1: if "R" not in d or "U" not in d: break if s[i] == "R" and s[i+1] == "U" or s[i] == "U" and s[i+1] == "R": ...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
length = input() text = input() len_dec = 0 try: idx = 0 while idx < len(text) - 1: prev = text[idx] curr = text[idx + 1] if (curr != prev): len_dec += 1 idx += 2 else: idx += 1 print (len(text) - len_dec) except: print (0)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; vector<char> v; int cnt = 0; for (int i = 0; i < n; i++) v.push_back(s[i]); for (int i = 0; i < n; i++) { if ((v[i] == 'R' && v[i + 1] == 'U') || (v[i] == 'U' && v[i + 1] == 'R')) { v[i] = 'D'; ...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n = int(input()) s = list(input()) ans = 0 for i in range(n-1): if s[i] != '' and s[i+1] != '' and s[i] != s[i+1]: s[i] = '' s[i+1] = '' ans += 1 g = ''.join(s) print(ans+len(g))
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.Writer; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(new BufferedInputStream(System.in)); Outpu...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n = int(input()) s = input() m = 1 d = 0 while( m < n): if(s[m] != s[m-1]): d = d + 1 m = m+2 else: m = m+1 print (n - d)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n = int(input()) s = input() i = 0 ans = 0 while i < n - 1: if s[i] != s[i + 1]: i += 1 i += 1 ans += 1 print(ans + int(i < n))
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
/* * Author: Minho Kim (ISKU) * Date: March 22, 2018 * E-mail: minho.kim093@gmail.com * * https://github.com/ISKU/Algorithm * http://codeforces.com/problemset/problem/954/A */ import java.util.*; public class A { public static void main(String... args) { Scanner sc = new Scanner(System.in); int N = sc.nex...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n=int(input()) s = input() i = 0 t = len(s) while i < len(s)-1: if s[i] != s[i+1] and s[i]!= 'D': t-=1 s = s[:i]+'D'+s[i+2:] i+=1 print(t)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
input() s = input() z = [] prev ="" for el in s: if el == "R": if prev == "U": prev = "" z[-1] = 'D' else: z.append(el) prev = "R" else: if prev == 'R': prev = "" z[-1] = 'D' else: z.append(el) ...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
import re n = int(input()) s = input() print(n - len(re.findall(r"RU|UR",s)))
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
x = int(input()) a = input() t = 0 k = 0 while t <= x-1: if t<x-1 and a[t] == "R" and a[t+1] == "U" or t<x-1 and a[t] == "U" and a[t+1] == "R": t = t + 2 k = k + 1 else: t = t + 1 k = k + 1 print(k)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
import java.util.*; import java.io.*; public class A954 { public static void main(String[] args) throws Exception { int n = Integer.parseInt(in.readLine()); int prev = in.read(); boolean taken = false; int rem = 0; for (int i = 1; i < n; i++) { int cur = in.read(); if (!taken && cur != prev) { ...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n=(int)(input()) s=input() s=s+s[-1] i=0 l=0 while i<n: l+=1 i+=1+int(s[i]!=s[i+1]) print(l)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n = input() f =0 r = 0 s = raw_input() for i in xrange(n-1): if s[i]<>s[i+1] and f==0: r+=1 f = 1 else: f= 0 print n-r
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> int main() { int n, i, j, c = 0; scanf("%d", &n); char s[10001]; getchar(); gets(s); for (i = 0; i < n - 1; i++) { if ((s[i] == 'R' && s[i + 1] == 'U') || (s[i] == 'U' && s[i + 1] == 'R')) { c++; i++; } } printf("%d", n - c); return 0; }
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
quant = int(raw_input()) lista =list(raw_input()) while True: cont = 0 for i in range(len(lista)-1): if((lista[i] == "U" and lista[i+1] == "R") or (lista[i] == "R" and lista[i+1] == "U")): lista[i] = "D" del(lista[i+1]) break else: cont+=1 if (cont == len(lista)-1): break print(len(lista))
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n=int(input()) s=input() i=0 s1='' while(i<len(s)): if(i!=len(s)-1): if((s[i]=='R' and s[i+1]=='U') or (s[i]=='U' and s[i+1]=='R')): s1+='D' i+=2 else: s1+=s[i] i+=1 #print('hi',i) else: s1+=s[i] i+=1 print(len(s1))
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n = int(input()) k = list(input()) i,c=0,0 while i<n-1: if k[i]=='R' and k[i+1]=='U' or k[i]=='U' and k[i+1]=='R': c+=1 i+=2 else: i+=1 print(n-c)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n = int(input()) directions = input() i = 1 answer = 0 if n == 1: answer = 1 else: while i < n: if directions[i] != directions[i - 1]: answer += 1 i += 2 else: answer += 1 i += 1 if i == n: answer += 1 print(answer)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n = input() s = input() # a = s.count('R') # b = s.count('U') # print(a,b) # print(min(a,b)+abs(a-b)) # while 'RU' in s or 'UR' in s: # s = s.replace('RU', 'D', 1) # s = s.replace('UR', 'D', 1) # # print(s) # print(len(s)) count = 0 i = 0 while i < len(s): if s[i] != s[i-1]: count += 1 i += 1 i += 1 print(l...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n = int(raw_input()) moves = raw_input() diagonal = 0 former = None for move in moves: if not former is None and former != move: diagonal += 1 former = None continue former = move print len(moves) - diagonal
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.Writer; import java.io.OutputStreamWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.Input...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n = int(input()) seq=input() newseq="" i=0 while (i<n-1): if(seq[i]!=seq[i+1]): newseq+='D' i=i+2 elif(seq[i]==seq[i+1] ): newseq=newseq + seq[i] i+=1 if(i==n-1): newseq=newseq+seq[i] print(len(newseq))
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
import sys import math def read_in(): lines = sys.stdin.readlines() for i in range(len(lines)): lines[i] = lines[i].replace('\n','') return lines def main(): lines = read_in() n = int(lines[0]) seq = lines[1] new_seq = '' i = 0 if len(seq) == 1: new_seq = seq...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException{ //FastScanner in = new FastScanner(new FileInputStream(new File("phi.in"))); //PrintWriter out = new PrintWriter(new File("output.txt")); PrintWriter o...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string str; cin >> str; int count = 0; char p = str[0]; for (int i = 1; i < str.size(); i++) { if (str[i] != p) { count++; i++; p = str[i]; } } cout << n - count << endl; return 0; }
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
def find(i, A, n, storage): if i>n-1: return 0 if storage[i] != -1: return storage[i] if i == n-1: storage[i] = 1 elif (A[i] == "U" and A[i + 1] == "R") or (A[i] == "R" and A[i + 1] == "U"): storage[i] = min(1 + find(i+2, A, n, storage), 1 + find(i+1, A, n, storage)) else: storage[i] = 1 + find(i+1, A,...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
import java.util.*; import java.io.*; public class Main { static InReader in; static OutWriter out; public static void main(String args[]) throws IOException { in = new InReader(); out = new OutWriter(); int n = in.nextInt(); String s=in.next(); int ans=n; f...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m, yellow, ans1 = 0, j, blue, i, red, l, bl, cnt, d, y, sum1, b, r, sum, t, ans, dif, array[100000 + 10], f, p, minn, a, c = 0, e, flag; char pixel[110][110]; vector<long long in...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; int a[110]; int main() { int n; string x; cin >> n >> x; int a = 0, b = 0; for (int i = 0; i < x.size() - 1; i++) if (x[i] != x[i + 1]) { a++; i++; } cout << n - a; return 0; }
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; for (int i = 0; i < n; i++) { if (s[i] == 'R' && s[i + 1] == 'U' || s[i] == 'U' && s[i + 1] == 'R') { s[i] = 'D'; s.erase(i + 1, 1); } } cout << s.size() << endl; return 0; }
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n = input() s = input() tag = [0 for i in range(len(s))] ans = 1 for i in range(1,len(s)): if (s[i] == s[i-1]): ans += 1 else : if (tag[i] == 0 and tag[i-1] == 0): tag[i] = 1 tag[i-1] = 1 else : ans += 1 # print(s[i]+" "+str(ans)) print(ans)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n = int(input()) s = input() count = 0 i = 0 st = True while(i<n-1): if s[i]!=s[i+1]: count+=1 if i==n-2: st = False i+=2 else: count+=1 i+=1 if st: count+=1 print(count)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; int main() { int n, c{0}; string a; cin >> n; cin >> a; for (size_t i = 0; i < a.size(); i++) { if ((a[i] == 'U' && a[i + 1] == 'R') || (a[i] == 'R' && a[i + 1] == 'U')) { c++; i++; } else c++; } cout << c << endl; }
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, c = 0; cin >> n; string a; cin >> a; for (int i = 0; i < n; i++) { if (a[i] == 'U') { if (a[i + 1] == 'R') { c++; i++; } else c++; } el...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; const long long inf = 2147483647; long long read() { long long first = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { first = first * 10 + ch - '0'; ch = getch...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.StringTokenizer; public class CF_A_Diagonal_Walking { public static void main(String[] args) throws Exception{ Scanner sc = new Scanner (System.in); int size = sc.nextInt(); ...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n=int(input()) s=input() ans = 0 i=0 while i<n-1: if s[i]=='R' and s[i+1]=='U': i+=2 ans+=1 elif s[i]=='U' and s[i+1]=='R': i+=2 ans+=1 else: i+=1 print(n-ans) #100 #RRURRUUUURURRRURRRRURRRRRRURRUURRRUUURUURURRURUURUURRUURUURRURURUUUUURUUUUUURRUUURRRURRURRRUURRUUUUR #...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; char s[1000]; bool a[1000]; int ans; int main() { cin >> s; cin >> s; for (int i = (0), i_end_ = (strlen(s)); i < i_end_; ++i) { if (a[i] || a[i + 1]) continue; if ((s[i] == 'U' && s[i + 1] == 'R') || (s[i] == 'R' && s[i + 1] == 'U')) { a[i] = a[i + 1] =...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; string s; cin >> s; long long res = 0; for (long long i = 0; i + 1 < n; i++) { if (s[i] != s[i + 1]) { i++; res++; } } cout << (n - res) << endl; }
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; int main() { long long n, k = 0; cin >> n; string a; cin >> a; for (long long i = 0; i < n - 1;) if ((a[i] == 'U' && a[i + 1] == 'R') || (a[i] == 'R' && a[i + 1] == 'U')) { i += 2; k++; } else i++; cout << n - k; }
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
import java.util.*; public class Sample { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); String s = sc.next(); int ans = shortest(s); System.out.println(ans); } static int shortest(String s) { int ans=...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
import java.util.*; public class Problem { public static Scanner sc = new Scanner(System.in); public static int l, index=0; public static StringBuffer s; public static void main(String args[]){ l = sc.nextInt(); s = new StringBuffer(sc.next()); for (int i = 0; i < l-1; i++) { ...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
p = int(input()) path = input() i = 0 n = 0 while i < p-1: if path[i] == path[i+1]: i+=1 else: i+=2 n+=1 print (p-n)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
import re rep = {"RU": "D", "UR": "D"} rep = dict((re.escape(k), v) for k, v in rep.items()) pattern = re.compile("|".join(rep.keys())) noe = int(input()) s = input() while "RU" in s or "UR" in s: s = pattern.sub(lambda m: rep[re.escape(m.group(0))], s) print(len(s))
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n=input() s=raw_input() m=n k=1 while True: if k>=n: break if (s[k]=='U' and s[k-1]=='R') or (s[k]=='R' and s[k-1]=='U'): m-=1 k+=2 else: k+=1 print m
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n = int(input()) s = input() ans = n i=0 #print (n,s) while i<n : #print (i ,n) if i==0 : i+=1 continue if s[i]!=s[i-1] : ans-=1 i+=1 i+=1 # print (i,n,end=' ') print (ans)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
x = int(input()) y = input() total = i = 0 while i < x-1: if y[i] != y[i+1]: total += 1 i+=1 i+=1 print(x-total)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n = int(input()) a = input() ans = n i = 1 while i < n: if a[i] != a[i-1]: ans -= 1 i += 1 i += 1 print(ans)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; int main() { vector<char> v; int n, s = 0; char c; cin >> n; for (int i = 0; i < n; i++) { cin >> c; v.push_back(c); } for (int i = 1; i < v.size(); i++) { if (v[i] != v[i - 1]) { s++; i++; } } cout << v.size() - s << endl; re...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n = int(raw_input().strip()) s = list(raw_input().strip()) i = 0 while i < len(s) - 1: if((s[i] == 'R' and s[i + 1] == 'U') or (s[i] == 'U' and s[i + 1] == 'R')): s[i] = 'D' s = s[0: i + 1] + s[i + 2: ] i += 1 print len(s)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int res = 0; for (int i = 0; i < n; i++) { res++; if (i == n - 1) break; if (s[i] != s[i + 1]) { i++; } } cout << res << "\n"; }
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n = int(input()) s = input() res = "" i = 0 while i <= n-1: if i == n-1: res += s[i] break if s[i] == s[i+1]: res += s[i] else: res += "D" i += 1 i += 1 print(len(res))
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
inutil = input() direction = list(input()) cont = 0 while len(direction)-1 > cont: if (direction[cont] == 'U' and direction[cont+1] == 'R') or (direction[cont] == 'R' and direction[cont+1] == 'U'): direction[cont] = 'D' direction.pop(cont+1) cont += 1 print(len(direction))
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n = int(input()) s = input() i = 0 count = 0 while i<n-1: if (s[i]=="U" and s[i+1]=="R") or (s[i]=="R" and s[i+1]=="U"): i += 2 count += 1 else: i += 1 print(n-count)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; int i, n, ans; string s; int main() { cin >> n >> s; i = 0; while (i < s.size()) { if (i == s.size() - 1) { ans++; break; } else { ans++; if (s[i] == s[i + 1]) { i++; } else { i += 2; } } } cout << an...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n = int(input()) s = input() ans = len(s) i = 0 while (i<len(s)-1): if (s[i]=='U') and (s[i+1]=='R'): ans = ans-1 i+=1 elif (s[i]=='R') and (s[i+1]=='U'): ans-=1 i+=1 i+=1 print(ans)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; int n, a[200200]; string s; int main() { int i, j; while (scanf("%d", &n) != EOF) { cin >> s; int cnt = 0; for (i = 0; i < s.size(); i++) { if (i == s.size() - 1) cnt++; else if (s[i] == 'U' && s[i + 1] == 'R') { i++; cnt+...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
import java.math.BigInteger; import java.util.Scanner; import sun.nio.cs.ext.Big5; /** * * @author Eman */ public class Codeforces { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); String s = in.next(); String out = ""; ...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.PriorityQueue; import java.util.Set; import java.util.StringTokenizer; import java.util....
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
bjp=int(input()) s=list(input()) i=0 kejriwal=0 while(i<bjp-1): if(s[i]!=s[i+1]): kejriwal+=1 i+=2 else: i+=1 print(bjp-kejriwal)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, ans = 0; string str; cin >> n >> str; if (n == 1) return !(cout << "1\n"); for (int i = 1; i < n; i++) { if (str[i] != str[i - 1]) { ans++; i++; } } cout << n - ans << en...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
def simplifica(mov): mov_simples = 0 i = 0 while i < len(mov): if i == len(mov) - 1: mov_simples += 1 break else: if mov[i] + mov[i + 1] == "RU" or mov[i] + mov[i + 1] == "UR": mov_simples += 1 i += 2 else: ...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
x = input() z = raw_input() conte = len(z) entrou = False for i in range(x-1): if(entrou): entrou = False continue if(z[i] == "R" and z[i+1] == "U"): conte -= 1 entrou = True elif(z[i] == "U" and z[i+1] == "R"): conte -= 1 entrou = True print (conte)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n=int(input()) s=input() i=0 ans=n while i<n: if i+1<n: if (s[i]=='R' and s[i+1]=='U') or (s[i]=='U' and s[i+1]=='R'): ans-=1 i+=2 continue i+=1 print(ans)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
import java.io.BufferedReader; import java.io.PrintWriter; import java.io.InputStreamReader; import java.io.IOException; import java.util.StringTokenizer; public class Main { static Scanner in = new Scanner(); static PrintWriter out = new PrintWriter(System.out); public static void main(String...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n, p, v = int(input()), 'D', 0 for c in input(): if p != 'D' and c != p: p = 'D' else: p, v = c, v + 1 print(v)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; for (int i = 0; i < s.length() - 1; i++) { if (s[i] == 'U' && s[i + 1] == 'R') { s[i] = '#'; s[i + 1] = '#'; n--; i++; } else if (s[i] == 'R' && s[i + 1] == 'U') { s[i] = '#'; ...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n = int(input()) s = input() r = 0 a = s.find('RU') b = s.find('UR') if a == -1: a = b if b < a and b != -1: a = b while a != -1: s = s[a + 2:] a = s.find('RU') b = s.find('UR') if a == -1: a = b if b < a and b != -1: a = b r += 1 print(n - r)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
import java.util.Scanner; public class A { private static final Scanner scan = new Scanner(System.in); public static void main(String[] args) { int n = scan.nextInt(); scan.nextLine(); String line = scan.nextLine(); StringBuilder sb = new StringBuilder(line); int coun...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n=int(input()) a=list(map(str,input())) i=0 while i<n-1: if a[i]!=a[i+1]: a[i]='D' del a[i+1] n-=1 i+=1 print(len(a))
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n=int(input()) s=input() k,i=0,0 while True: if i+2>n: break if s[i]==s[i+1]: i+=1 else: i+=2 k+=1 print(n-k)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
import java.util.*; public class A954 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(), count = n; char arr[] = in.next().toCharArray(); for(int i=0; i<n-1; i++) { if((arr[i] == 'U' && arr[i+1] == 'R') || (arr[i] == 'R' && arr[i+1] == 'U')) { c...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n = int(input()) k = str(input()) j = "" lastWasDone = False for i in range(0, n): if lastWasDone: lastWasDone = False else: if i != n - 1: if k[i] == "R" and k[i + 1] == "U": j += "D" lastWasDone = True elif k[i] == "U" and k[i + 1] == ...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
# import sys # sys.stdin = open("test.in","r") # sys.stdout = open("test.out","w") n=int(input()) s=input() m=0 i=0 while i<n-1: if s[i]!=s[i+1]: m+=1 i=i+2 else: i+=1 print(n-m)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n = int(input()) s = str(input()) count = 0 i = 0 while i < len(s) - 1: if (s[i] == "R" and s[i + 1] == "U") or (s[i] == "U" and s[i + 1] == "R"): count += 1 i += 2 else: i += 1 print(n - count)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
from re import sub n = input() print(len( sub( r'RU|UR', 'D', input() ) ) )
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; s = '$' + s + '$'; int ans = 0; for (int i = 1; i < s.size(); i++) { if (s[i] == 'U' && s[i - 1] == 'R') { s[i - 1] = 'l'; s[i] = 't'; ans++; } else if (s[i] == 'R' && s[i - 1] == 'U')...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
import java.util.Scanner; public class Problem_A { public static void main(String [] args) { Scanner src=new Scanner(System.in); int n; String s; int cnt=0; n=src.nextInt(); s=src.next(); for(int i=0;i<s.length()-1;i++) { if((s.char...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; char str[101]; cin >> str; int len = strlen(str); int i, c = 0; for (i = 0; i < len - 1;) { if ((str[i] == 'U' and str[i + 1] == 'R') or (str[i] == 'R' and str[i + 1] == 'U')) { c++; i += 2; } else ...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
# n = int(input()) # tn = [int(i) for i in input().split()] # def f(m): # m = 0 # l = 0 # r = n # while l < r: # m = (l + r)//2 # в ряду всего m парт и m*2 мест # первое место в ряду p равно 2m(p-1) + 1 n = int(input()) s = input() length = len(s) i = 0 while i < len(s) - 1: if s[i] == "U" and s[i+1] ==...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n=int(input()) a=input() x=0;i=0 while i<n: if a[i]+a[i-1]=='RU' or a[i]+a[i-1]=='UR': x+=1 i+=2 else: i+=1 print(n-x)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; const int N = 1009; int arr[N]; bool prime[N]; bool isprime(int n) { if (n <= 1) return 0; for (int i = 2; i * i <= n; i++) if (n % i == 0) return false; return prime[n] = true; } void feilprime() { prime[0] = prime[1] = 0; for (int i = 2; i * i <= 300; i++) {...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; int main() { int a, s = 0, p; scanf("%d", &a); string ch; cin >> ch; int i = 0; if (a == 1) printf("%d", 1); else { while (i < a - 1) { if (ch[i] != ch[i + 1]) { i = i + 2; s = s + 1; } else i = i + 1; } prin...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n = int(input()) s = list(input()) cnt = n for i in range(1,n): if s[i] == 'U' and s[i-1] == 'R' or s[i] == 'R' and s[i-1] == 'U': cnt -= 1 s[i] = 'D' print(cnt)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n = int(input()) s = input() cnt = 0 i = 0 while i < n - 1 : if s[i] != s[i+1] : cnt +=1 i += 2 else: i += 1 print(n - cnt)
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 123; const int M = 1e7 + 123; const int inf = 1e9 + 1; const int mod = 1e9 + 7; const int bl = 300; int n, cnt; string second; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; cin >> second; for (int i = 0; i < se...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
n = input() path = str(raw_input()) wyn = 0 x =0 while x < len(path): if x < len(path) - 1: if (path[x] == 'U' and path[x + 1] == 'R') or (path[x] == 'R' and path[x + 1] == 'U'): x += 2 wyn += 1 continue else: wyn += 1 x += 1 else: ...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10, NX = 1e9 + 7; int n, m, r, t, a, b, c, A[N]; string s; int main() { cin >> n >> s; for (int i = 0; i < n - 1; i++) { if (s[i] != s[i + 1]) c++, i++; } cout << n - c; return (0); }
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
import java.io.*; import java.util.*; public class A { MyScanner in; PrintWriter out; public static void main(String[] args) throws Exception { new A().run(); } public void run() throws Exception { in = new MyScanner(); out = new PrintWriter(System.out); solve();...
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r...
y=int(input('')) x=input('') x=x.replace("RU","") x=x.replace("UR","") print(int(len(x)+(y-len(x))/2))