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...
#include <bits/stdc++.h> using namespace std; vector<int> fillvec(int size) { vector<int> ans; for (int i = 0; i < size; i++) { int temp; cin >> temp; ans.push_back(temp); } return ans; } int gcd(int a, int b) { return !a ? b : gcd(b % a, a); } vector<long long> getdivisors(long long n) { vector<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...
/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; import java.util.Arrays; import java.math.BigInteger; /* Name of the class has to be "Main" only if the class is public. */ public class Main { public static void main (String[] args) throws java.lang....
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()) string = input() f = 0 state = False for i in range(n-1): if state == True: state=False continue if (string[i]=='U' and string[i+1]=='R') or (string[i]=='R' and string[i+1]=='U'): f+=1 state = True print(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() { int n; cin >> n; string s; cin >> s; int ct = 0; int i = 0; while (i < n) { if (i < n - 1 && s[i] == 'U' && s[i + 1] == 'R') ct++, i += 2; else if (i < n - 1 && s[i] == 'R' && s[i + 1] == 'U') ct++, i += 2; else ct++,...
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; signed main() { int n; stack<char> c; cin >> n; for (int i = 0; i < n; i++) { char a; cin >> a; if (c.empty()) { c.push(a); } else { if ((c.top() == 'R' && a == 'U') || (c.top() == 'U' && a == 'R')) { c.pop(); c.push('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...
IL=lambda:(map(int,raw_input().strip().split())) I=lambda:(int(raw_input())) S=lambda:(raw_input()) n=I() r=S() l=len(r) i=0 count=0 while(i<l-1): if r[i]=="R": if r[i+1]=="U": count=count+1 i=i+2 else: count=count+1 i=i+1 else: if r[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 java.io.*; import java.util.*; import java.lang.Math; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; import java.util.StringTokenizer; public class GFG { static class FastReader{ BufferedReader br; StringTokenizer st; ...
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()) route=input() moves=0 i=0 while i<n: if route[i]=='R': if i<n-1 and route[i+1]=='U': moves+=1 i+=2 else: moves+=1 i+=1 elif route[i]=='U': if i<n-1 and route[i+1]=='R': moves+=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...
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(); String s = in.nextLine(); while(s.indexOf("UR") != -1 || s.indexOf("RU") != -1) { int temp1 = s.indexOf("UR"); int temp2 = s.inde...
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; long long n; string s; long long dp[2000]; long long solve(long long idx) { if (idx > n) return 0; if (dp[idx] != -1) return dp[idx]; long long ans = 1e16; if (s[idx] != s[idx + 1]) { ans = min(ans, solve(idx + 2) + 1); } ans = min(ans, solve(idx + 1) + 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() { int n; cin >> n; string s; cin >> s; int cnt = s.size(); for (int i = 1; i < s.size(); i++) { if (s[i - 1] == 'R' && s[i] == 'U' || s[i - 1] == 'U' && s[i] == 'R') { cnt--; s[i] = 'D'; } } cout << cnt << 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...
import java.io.*; import java.util.*; import javafx.util.Pair; import javax.swing.*; public class Codeforces { static PrintWriter pw=new PrintWriter(System.out); public static int oo=1000000000; public static void main(String[] args) throws IOException { Reader.init(System.in); int n=Read...
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=list(input()) ans=0 while len(s)>1: a,b=s.pop(),s.pop() ans+=1 if a==b: s.append(a) print(ans+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...
print(len(input()[:0])+len(__import__('re').sub('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 length(string str) { int ctr = 0; for (int x = 0; str[x] != '\0'; x++) { ctr++; } return ctr; } int replace(string str) { string ret; for (int x = 0; str[x] != '\0'; x++) { if ((str[x] == 'U' && str[x + 1] == 'R') || (str[x] == 'R' && str[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...
n = int(input()) s = input() last = None res = 0 for c in s: if not last or last == c: res += 1 last = c else: last = None print(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...
n = int(input()) s = list(input()) i = 1 while i < len(s): if s[i] + s[i-1] == 'RU': n -= 1 s[i] = 'D' elif s[i] + s[i-1] == 'UR': n -= 1 s[i] = 'D' i += 1 print(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...
#include <bits/stdc++.h> using namespace std; long long int power(long long int a, long long int p) { long long int ret = 1; while (p > 0) { if (p & 1) { ret *= a; } a *= a; p >>= 1; } return ret; } long long int powmod(long long int a, long long int b, long long int MOD) { if (b == 0) 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 diagonal954A { public static void main(String[] args) { Scanner sc= new Scanner(System.in); int numberOfChara = sc.nextInt(); int count = 0; sc.nextLine(); String statme = sc.nextLine(); for (int i = 0; i < numberOfChara - 1; i++) { if((statme.charAt(i) == '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...
n=int(input()) a=input() i=0 c=0 while i+1<n: if a[i]=='U' and a[i+1]=='R': c+=1 i+=1 elif a[i]=='R' and a[i+1]=='U': c+=1 i+=1 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...
import java.util.*; import java.io.*; import java.math.*; public class scorify{ public static void main(String[] args){ Scanner in=new Scanner(System.in); int len = in.nextInt(); String str = in.next(); int S=1,flage=1; char open = str.charAt(0); for(int i=1 ;i<len ;i++){ if(str.charAt(i)!=open && flage...
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 HelloWorld{ public static void main(String []args){ int n,l=0; Scanner sc=new Scanner(System.in); n=sc.nextInt(); String s1=new String(); s1=sc.next(); /*String s2=s1.replace("UR","D"); String s3=s2.replace("RU...
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:@karngyan def trans(s,n): cnt=0 flag=0 for i in range(n-1): if(flag==1): flag=0 continue else: if(s[i]+s[i+1]=='RU' or s[i]+s[i+1]=='UR'): cnt+=1 flag=1 return n-cnt n=int(input()) s=input() print(trans(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...
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws FileNotFoundException { ConsoleIO io = new ConsoleIO(new InputStreamReader(System.in), new PrintWriter(System.out)); // String fileName = "C-large"; // ConsoleIO io = new ConsoleIO(new Fil...
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()) count=0 i=0 while i<n-1: if a[i:i+2]=='RU' or a[i:i+2]=='UR': i+=1 count+=1 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...
import java.util.ArrayList; import java.util.Scanner; /* * 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 nguyen */ public class Main { /** * @param args 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...
#include <bits/stdc++.h> int main() { int i, step, ans; char a[99]; scanf("%d", &step); scanf("%s", &a); for (i = 0, ans = 0; i < step; i++) { ans++; if (a[i] != a[i + 1] && i + 1 < step) { i++; } } printf("%d", ans); 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 sys import math #to read string get_string = lambda: sys.stdin.readline().strip() #to read list of integers get_int_list = lambda: list( map(int,sys.stdin.readline().strip().split()) ) #to read non spaced string and elements are integers to list of int get_intList_from_str = lambda: list(map(int,list(sys.stdin....
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()) l=list(input()) p=[] count=0 s=["RU","UR"] for i in range(n-1): if (l[i]+l[i+1]) in s and i not in p and (i+1) not in p: p.append(i) p.append(i+1) count+=1 s=n-(2*count) print(s+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...
n = int(input()) a = list(input()) for i in range(n): if a[i:i+2] == ['R','U'] or a[i:i+2] == ['U', 'R']: a[i:i+2] = 'z' 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()) prev = 0 final = 0 string = input() for i in range(n): now = string[i] if (prev == 'R' and now == 'U') or (prev == 'U' and now == 'R'): final += 1 prev = 0 else: if now == 'R' or now == 'U': if prev == now: final += 1 prev = no...
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...
#!/usr/bin/env python n = int(raw_input()) s = raw_input().strip() output = [] i = 0 while i < len(s)-1: if s[i] != s[i+1]: output.append("D") i+=2 else: output.append(s[i]) i+=1 if i < len(s): output.append(s[i]) result = "".join(output) #print result print len(result)
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; string a; int main() { cin >> n >> a; for (int i = 0; i < n; i++) if (a[i] == 'R' && a[i + 1] == 'U' || a[i] == 'U' && a[i + 1] == 'R') a.replace(i, 2, "D"); cout << a.size(); }
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, r = 0; cin >> n; string a; cin >> a; if (n == 1) r = 1; else { for (int i = 0; i < n - 1;) { if (a[i] != a[i + 1]) { r++; i += 2; if (i == n - 1) r++; } else if (i == (n - 2)) { r += 2; ...
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 Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); cin.nextLine(); String s = cin.next(); cin.close(); s = s.replaceAll("RU|UR", "t"); System.out.print(s.length()); } }
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()) m = list(input()) removeu = 0 for i in range(n): if i < len(m)-1 and (m[i] + m[i+1] == "UR" or m[i] + m[i+1] == "RU"): del m[i+1] m[i] = "D" print(len(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...
x=int(input()) y=input() t=i=0 while i<x-1: if y[i]!=y[i+1]: t+=1 i+=1 i+=1 print(x-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...
import sys import math import bisect import itertools def main(): n = int(input()) A = list(input()) for i in range(1, n): if A[i-1] == 'U' and A[i] == 'R': A[i-1] = 'D' A[i] = '.' if A[i-1] == 'R' and A[i] == 'U': A[i-1] = 'D' A[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 math,itertools,fractions,heapq,collections,bisect,sys,queue,copy sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 dd=[(-1,0),(0,1),(1,0),(0,-1)] ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] # def LF(): return [float(x) for x in 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 c = 0; for (int i = 0; i < n; i++) { if ((s[i] == 'U' && s[i + 1] == 'R') || (s[i] == 'R' && s[i + 1] == 'U')) { c++; i++; } else c++; } cout << c << 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...
#include <bits/stdc++.h> using namespace std; int main() { int n, kol = 0; cin >> n; string s; cin >> s; for (int i = 0; i < s.length() - 1; i++) { if (s[i] == 'R' && s[i + 1] == 'U' || s[i] == 'U' && s[i + 1] == 'R') { kol++; i++; continue; } } cout << s.length() - kol << "\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 java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution1 { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); String s=sc.next(); char a[]=s.toCharArray(); char temp; int c=0; int i; if(n==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...
hmmm = int(input()) hm = list(input()) i = 0 newList = [] cur = "" nex = "" while i < hmmm: cur = hm[i] if i+1 < hmmm: nex = hm[i+1] if(cur == "R" and nex == "U") or (cur == "U" and nex == "R"): i += 1 newList.append("D") else: newList.append(cur) i += 1 print(len(new...
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 while i < n: if i != n - 1: if s[i] != s[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...
n = int(input()) x = input() prev = "D" cnt = 0 for i in range(0, len(x)): flag = 0 if((x[i] == "U" and prev == "R") or (x[i] == "R" and prev == "U")): flag = 1 else: cnt = cnt+1 prev = x[i] if(flag == 1): prev = "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...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigDecimal; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; impor...
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...
le = int(input()) st = input() c = 0 if le == 2: if st[0] != st[1]: print(1) else: print(2) elif le == 1: print(1) else: x = st[0] for i in range(0, le): if x != st[i] and i != le - 1: c += 1 x = st[i + 1] i += 1 elif x != st[i] and...
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 - 1; i++) { bool c1 = s[i] == 'U' and s[i + 1] == 'R'; bool c2 = s[i] == 'R' and s[i + 1] == 'U'; if (c1 or c2) { s[i] = 'D'; s = s.substr(0, i + 1) + s.substr(i + 2); ...
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 t[n]; int i; int h = n; for (int i = 0; i < n; i++) { cin >> t[i]; } i = 0; while (i < n) { if ((t[i] == 'U' && t[i + 1] == 'R') || (t[i] == 'R' && t[i + 1] == 'U')) { i += 2; h--; } else 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...
k=input() s=input() n=len(s) last=s[0] for c in s[1:]: if (last=='R' and c=='U'): n-=1 last='' elif(last=='U' and c=='R'): n-=1; last='' else: last=c print(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()) l = list(input()) i = 0 co = 0 while i < n - 1: if l[i] == 'U' and l[i + 1] == 'R' or l[i] == 'R' and l[i + 1] == 'U': co += 1 i += 2 else: i += 1 print(n - co)
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()) counter = 0 i = 0 while i < (n - 1): if s[i] == 'U' and s[i+1] == 'R': counter += 1 i += 2 continue elif s[i] == 'R' and s[i+1] == 'U': counter += 1 i += 2 continue i += 1 print(n - counter) # hamed gh
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, s = int(input()), input() + '#' d, i = 0, 0 while i < n: if s[i: i + 2] in ('UR', 'RU'): d += 1 i += 2 else: i += 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()+"U" i,c=0,0 while i<n: c+=1 if s[i]!=s[i+1]:i+=2 else:i+=1 print(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...
# https://codeforces.com/problemset/problem/954/A n = int(input()) s = input() ans = 0 i = 1 while i < n: if s[i-1] != s[i]: ans += 1 i += 2 else: i += 1 print(n - 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.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.Reader; import java.io.StreamTokenizer; import java.io.Writer; public class Tmp { private static Reader reader = new InputStreamReader(System.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...
n=input() n=int(n) str=input() i=0 count=0 while i<=n-2: if (str[i]=='U' and str[i+1]=='R') or (str[i]=='R' and str[i+1]=='U'): count+=1 i+=1 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...
import java.awt.Point; import java.util.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.*; import java.util.*; public class Main { ////// static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedRe...
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()) c=input() i=0 s=0 while i<len(c): if i<len(c)-1: if c[i+1]!=c[i]: s+=1 i+=2 else: s+=1 i+=1 else: s+=1 break print(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...
import java.util.Scanner; public class DiagonalWalking { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); String seq=sc.next(); char[] seq2=seq.toCharArray(); int sum=n; for(int i=0; i<n-1; i++) { if (seq2[i]!=seq2[i+1]) { sum--; i++; } } if(n%2!=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 Main { static StringBuilder data = new StringBuilder(); final static FastReader in = new FastReader(); public static void main(String[] args) { int n = in.nextInt(); String s = in.nextLine(); int d = 0, i = 0; while (tru...
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() j=i=0 while(i<(n)): try: if a[i]=='U' and a[i+1]=='R' or a[i]=='R' and a[i+1]=='U': j+=1 i+=2 else: j+=1 i+=1 except: j+=1 i+=1 print(j)
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() a = raw_input() l = [] for i in range(n): if l==[]: l.append(a[i]) elif (l[-1]=='U' and a[i]=='R' ) or (l[-1]=='R' and a[i]=='U'): l.pop() l.append('D') else: l.append(a[i]) print len(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...
import re n=input() s=input().lower() print(len(re.sub('(ru|ur)','d',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; long long n, m, k, ans, l, r, kk, a[100001], b[100001]; string s, t, second; int main() { cin >> n; cin >> s; for (int i = 0; i < s.size(); ++i) { if ((s[i] == 'R' && s[i + 1] == 'U') || (s[i] == 'U' && s[i + 1] == 'R')) --n, ++i; } cout << 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 java.util.*; public class A0954_DiagonalWalking { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); String str = sc.next(); sc.close(); int res = n; for (int i=0; i<n-1; i++) { if (str.charAt(i) != str.charAt(i+1)) { res--; 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; void adskiy_razgon() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } const int MAX_N = 1e+4 * 3 + 33; const int MOD = 1e+9 + 7; const long long INF = 1e+18; int nod(int a, int b) { if (a == 0 || b == 0) { return 0; } else if (a == b) { return 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()) string = list(map(str, input())) ans = 0 i = 0 while i<len(string)-1: if(string[i] == 'U' and string[i+1] == 'R') or (string[i] == 'R' and string[i+1] == 'U'): del string[i] del string[i] ans+=1 else: i+=1 print(ans+ len(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 static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.abs; import java.util.*; import java.io.*; public class x954A { public static void main(String hi[]) throws Exception { BufferedReader infile = new BufferedReader(new InputStreamReader(System.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...
n = input() path = input() subs = 0 i = 0 while i < len(path) - 1: if path[i:i+2] in ("RU", "UR"): subs += 1 i += 1 i += 1 print(len(path) - subs)
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()) str=input() count=0 i=0 while i<=n-2: if str[i]=='U' and str[i+1]=='R' or str[i]=='R' and str[i+1]=='U': count+=1 i+=1 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...
def solve2(s): curr = 0 d = 0 if len(s) == 1: return 1 while curr < len(s)-1: if s[curr] != s[curr+1]: curr += 2 else: curr += 1 d += 1 if curr == len(s) - 1: d += 1 return d n = int(input()) print(str(solve2(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...
len = int(input()) step = input() i=0 count =0 for c in step: if i==len-1 : count+=1 break elif i>len-1 : break if (step[i] != step[i+1]) : count += 1 i+=2 continue count+=1 i+=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; using ll = long long; int N; string s; int main() { cin >> N; cin >> s; int cnt = 0; if (N > 1) { for (int i = (1); i < (int)(N); i++) { if ((s[i] == 'U' && s[i - 1] == 'R') || (s[i] == 'R' && s[i - 1] == 'U')) { cnt++; if (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...
# cf 954 A 900 n = int(input()) s = input() i = 0 ans = 0 #UU UR RRR RU U UR UR UUU #UU D RRR D U D D UUU # ^ #UU D RRR RDUUDDDDUU while i < len(s) - 1: if s[i] == 'U' and s[i + 1] == 'R': ans += 1 i += 2 elif s[i] == 'R' and s[i + 1] == 'U': ans += 1 i += 2 elif 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 n; char s[105]; int main() { scanf("%d", &n); scanf("%s", s); int cnt = 0; for (int i = 0; i < n - 1; i++) { if (s[i] == 'U' && s[i + 1] == 'R') { cnt++; i++; } else if (s[i] == 'R' && s[i + 1] == 'U') { cnt++; i++; } } pr...
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) { Scanner sc = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int n = sc.nextInt(); char[] a = sc.next().toCharArray(); int cnt = 0; for (int 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.util.Scanner; public class Diagonal { public static void main(String[] args) { Scanner input = new Scanner(System.in); input.nextLine(); String s = input.nextLine(); input.close(); int min = s.length(); for (int i = 0; i < s.length() - 1; i++) { if (s.charAt(i) == 'U' && s.charAt(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 re n = int(input()) str1 = input() s = re.sub('(RU|UR)','D', str1) 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 = int(input()) i = 0 ans = 0 l = list(input()) while i < len(l)-1: if l[i] != l[i+1]: ans += 1 i += 1 i+= 1 print(n-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() { int n, cnt = 0; cin >> n; string s; cin >> s; for (int i = 0; i < s.size(); i++) { if ((s[i] == 'R' && s[i + 1] == 'U') || (s[i] == 'U' && s[i + 1] == 'R')) { cnt += 1; i++; } else cnt++; } cout << cnt; 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.awt.image.AreaAveragingScaleFilter; import java.io.*; import java.util.*; import static java.lang.Math.*; public class Main { BufferedReader br; StringTokenizer in; PrintWriter pw; Random r; int INF = (int) 1e9; long LNF = (long) 1e18; long mod = (long) (1e9 + 7); int pp =...
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()) d = list(input()) i = 0 count = 0 if n == 1: print(1) else: while i < n-1: if (d[i] == 'R' and d[i+1] == 'U') or (d[i] == 'U' and d[i+1] == 'R'): i = i + 2 count = count + 1 if i == n - 1: count = count + 1 else: 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...
# -*- coding:utf-8 -*- sum=(int)(raw_input()) str=raw_input() count=0 index=0 while(True): if(index>=sum-1): if(index==sum-1): count+=1 break if(str[index] == 'U' and str[index+1] == 'R'): count+=1 index+=2 elif(str[index] == 'R' and str[index+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...
n = int(input()) s = input() while True: used = False for i in range(1, len(s)): if s[i - 1] + s[i] == "UR" or s[i - 1] + s[i] == "RU": s = s[:i - 1] + "D" + s[i + 1:] used = True break if not used: break 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 = int(input()) A = input() prev_changed = False shortened = 0 for i in range(1, n): if not prev_changed: if A[i] != A[i - 1]: prev_changed = True shortened += 1 else: prev_changed = False print(n - shortened)
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 NewClass { static final int INF = Integer.MAX_VALUE; static void mergeSort(int[] a,int[]b, int p, int r) { if (p < r) { int q = (p + r) / 2; mergeSort(a,b, p, q); mergeSort(a,b, q + 1, r); merge(a,b, 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...
n = int(input()) s = input() a = '' i = 0 while(i<n): x = s[i:i+2] if(x == "RU" or x == "UR"): a+="D" i+=2 else: a+=x[0] 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()) str=input() i=0 count=0 while(i<n-1): if(str[i]!=str[i+1]): i=i+2 count+=1 else: i=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...
r = input n = int(r()) ans = n s = r() i = 0 while i + 1 < n: if s[i:i + 2] == 'UR' or s[i:i + 2] == 'RU': 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() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); int n; cin >> n; string s; cin >> s; int cnt = s.size(); map<int, int> vis; for (int i = 1; i < s.size(); i++) { if (s[i] == 'R' && s[i - 1] == 'U' && vis[i - 1] == 0) { vis[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...
# -*- coding: utf-8 -*- """ Created on Fri Mar 30 10:24:29 2018 @author: aalfaiz """ n =int(input()) moves = input() num_moves = 0; i=0 while(i < n): if(i<n-1 and moves[i]!=moves[i+1]): i+=2 else: i+=1 num_moves+=1 print(f'{num_moves}')
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 Solution2 { private void solve() throws IOException { int n = in.nextInt(); String s = in.next(); int count = 0; for (int i = 0; i < n - 1; i++) { if (s.charAt(i) == 'R' && s.charAt(i + 1) == 'U') { cou...
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.BufferedOutputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class Codeforces{ public static void main(String []args) { MyScanner in = new MyScanner(); out = new PrintWr...
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...
/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Codechef { public static void main (String[] args) throws java.lang.Exception { // your code goes here Scanner sc=new Scann...
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 { public static void main(String args[])throws IOException { Scanner sc= new Scanner(System.in); int l = sc.nextInt(); String s=sc.next(); int ans=l; for(int i=0;i<l-1;i++) { char ch = s.charAt(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()) #arr = map(int,raw_input().split(" ")) arr = raw_input() i = 1 ans = n while i < n: if arr[i]!=arr[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...
length = int(raw_input()) sequence = str(raw_input()) i = 0 while i < len(sequence)-1: string = sequence[i] + sequence[i+1] if string == 'RU' or string == 'UR': sequence = sequence[0:i] + 'D' + sequence[i+2:] i=0 else: i+=1 print len(sequence)
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() t=0;i=0 while i<n-1: if s[i]!=s[i+1]: t+=1;i+=1 i+=1 print(n-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...
import java.util.*; import java.io.*; import java.math.*; public class Main{ static int mod = (int)1e9+7; public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out)); public static void main(String sp[])throws IOException{ FastReader sc = new FastReader(); int n = sc.nextInt(); String ...