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...
tamanho = int(raw_input()) caminho = map(lambda s: s, raw_input()) def xor(s1, s2): return (s1 == "R" or s1 == "U") and (s1 == "R" or s1 == "U") and s1 != s2 for i in range(tamanho - 1, 0, -1): if xor(caminho[i], caminho[i - 1]): caminho.pop(i) caminho[i - 1] = "D" print len(caminho)
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; public class WalkingOnTheDiagonal { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); int length = Integer.par...
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()) word = input() count = 1 while count < n: word = word.replace("RU","D",count) word = word.replace("UR","D",count) count += 1 ans = len(word) 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() { char a[101]; string s = ""; int n; cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i]; s += a[i]; } for (int i = 0; i <= s.length(); i++) { int x = s.find("RU"); int y = s.find("UR"); if (x == -1 && y == -1) break; if (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; int main() { string k, p; long long a, b = 0, c, d = 0, e = 0, f = 1, g, h, i, j, l, m, n, o, q, r, s, t, u, v, w, x, y, z; cin >> a >> k; for (i = 1; i < a; i++) { if (k[i] != k[i - 1]) { i++; b++; } } cout << a - b; }
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() s1 = "" count = n i = 1 while i < len(s): if s[i] != s[i - 1]: count -= 1 i += 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...
//package javaapplication1; import java.io.*; import java.math.*; import java.util.*; import java.util.stream.*; import java.lang.*; public class JavaApplication1 { private static FastReader sc = new FastReader(System.in); private static OutputWriter out = new OutputWriter(System.out); public static void ma...
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 toint(const string &s) { stringstream ss; ss << s; int x; ss >> x; return x; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; string s; cin >> s; int cnt = 0; for (int i = 0; i < n - 1; i++) { if ((s[i] == '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...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class TestClass { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine...
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 N = 1e5 + 10; int t, n, m, a[N], c[N], ans; string s; int main() { ios_base::sync_with_stdio(false); cin >> n >> s; for (int i = 0; i < n; i++) { if (s[i] == s[i + 1]) ans++; else ans++, i++; } cout << 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...
n = int(input()) s = input() k = 0 i = 0 while i < n - 1: s2 = s[i] + s[i + 1] if(s2 == 'RU' or s2 == 'UR'): k += 1 i += 1 i += 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.Scanner; public class Program { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); String phrase = in.next(); phrase = phrase.replaceAll("RU|UR", "t"); System.out.println(phrase.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...
import java.util.*; import java.lang.*; import java.io.*; public class Main { public static void main (String[] args) throws java.lang.Exception { Scanner in = new Scanner(System.in); int n = in.nextInt(); String s = in.next().replaceAll("RU|UR", "D"); 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...
#include <bits/stdc++.h> using namespace std; map<char, int> m; int main() { int a, temp = 3, ju; cin >> a; ju = a; char s[100] = {0}, g[100] = {0}; for (int i = 0; i < a; i++) { cin >> s[i]; } for (int i = 0; i < a; i++) { if (s[i] == 'R') g[i] = 1; else { g[i] = -1; } } 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.*; import java.math.*; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner s=new Scanner(System.in); int n=s.nextInt(); int count=0; //char [] arr=new char[n]; String in=s.next(); for(int i=0;i<(n-1);i++) { if(in.charAt(i)=='U'&&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...
length = int(input()) line = input().strip() idx = 0 count = 0 while idx < len(line): if idx < len(line) - 1 and line[idx] == 'R' and line[idx+1] == 'U': idx += 1 elif idx < len(line) - 1 and line[idx] == 'U' and line[idx+1] == 'R': idx += 1 count += 1 idx += 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; string a; cin >> n >> a; for (int i = 0; a[i]; i++) { if (a[i] == 'U' && a[i + 1] == 'R') { n--; i++; } else if (a[i] == 'R' && a[i + 1] == 'U') { 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.*; import java.io.*; import java.lang.*; public class Code { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(System.out); String[] temp = br.readLine().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...
def main(): n = int(input()) steps = input() count_d = 0 index = 0 while index < n - 1: if steps[index + 1] != steps[index]: count_d += 1 index += 1 index += 1 print(n - count_d) if __name__ == '__main__': main()
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 s=int(input()) str=input() str=re.sub("UR|RU","D",str) print(len(str))
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() { string s; long long sz; cin >> sz; cin >> s; long long ans = sz; for (long long i = 0; i < sz; i++) if (s[i] != '#' && i + 1 < sz && s[i] != s[i + 1]) ans--, s[i + 1] = '#'; cout << ans << 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 = int(raw_input()) moves = map(str, raw_input())[:n] for i in range(len(moves)-1): if moves[i] == "U" and moves[i+1] == "R": moves[i] = "D" moves[i+1] = 0 elif moves[i] == "R" and moves[i+1] == "U": moves[i] = "D" moves[i+1] = 0 for i in moves: if i == 0: moves.pop(i) print len(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...
n=int(input()) a=input() a+=' ' x=0 i=0 while i<n: if ((a[i]=='U') and (a[i+1]=='R')) or ((a[i]=='R') and (a[i+1]=='U')): x+=1 i+=2 else: i+=1 print(len(a)-x-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 arr[1000]; int main() { int n; cin >> n; string s; cin >> s; for (int i = 0; i < n; ++i) { if (i < n - 1 && (s[i] == 'U' && s[i + 1] == 'R') || (i < n - 1 && s[i] == 'R' && s[i + 1] == 'U')) { s[i] = 'D'; s.erase(i + 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...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.sql.Array; import java.sql.ResultSet; import java.sql.SQLException; import java.util.*; import java.util.List.*; import java.util.concurrent.Executor; import java.util.concurrent.ExecutorService; import java.util.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.*; public class ProbA { public static void main(String[] args) { Scanner input = new Scanner(System.in); int lengthOfSeq = input.nextInt(); String sequence = input.next(); String solution = sequence; /* if(lengthOfSeq > 1 && sequence.substring(0,2).eq...
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 P954A { public static void main(String[] args) { Scanner in = new Scanner(System.in); int length = in.nextInt(); String s = in.next(); int ans = 0; for(int i = 0; i < s.length();) { if(i + 1 < s.lengt...
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 code7 { InputStream is; PrintWriter out; static long mod=pow(10,9)+7; int dx[]= {0,0,1,-1},dy[]={+1,-1,0,0}; void solve() { int n=ni(); String s=ns(); int count=0; for(int i=0;i<s.length();i++) { if((i+1<s.length())&&((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()) S = input() an =[ S[0]] for i in S[1:]: if an[-1] == 'D' or an[-1] == i: an += i else: an.pop() an +=["D"] print(len(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() i = 0 c = 0 while i < n - 1: if s[i] == 'R' and s[i+1] == 'U' or s[i] == 'U' and s[i+1] == 'R': 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.Scanner; public class FirstCodeForces { public static int move() { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); String s = scan.next(); int d = 0; for (int i = 0; i < n - 1; ) { char c = s.charAt(i); if (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...
from __future__ import print_function, division _ = raw_input() s = raw_input() cnt = 0 i = 0 while i <= len(s) - 2: if (s[i] == 'U' and s[i+1] == 'R') or (s[i] == 'R' and s[i+1] == 'U'): cnt += 1 i += 1 i += 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...
import java.util.*; public class OOP { public static void main(String[] args) { Scanner input = new Scanner(System.in); int n = input.nextInt(), counter = 0; String str = input.next(); for (int i = 0; i < n; ++i) { if (i == 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...
n=int(input()) s = input() x=n i=0 while i<(n-1): if s[i]!=s[i+1]: i=i+2 x=x-1 else: i=i+1 print(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()) ch=input() while ('UR' in ch) or ('RU' in ch) : ans='' i=0 while(i<len(ch)): if i<len(ch)-1: if ch[i:i+2]=="UR" or ch[i:i+2]=="RU": ans+="D" i+=2 else: ans+=ch[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...
a=eval(input()) b=input() flag=True for i in range(len(b)-1): if b[i]!=b[i+1] and flag==True: a-=1 flag=False else: flag=True print(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...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 300; int main() { string s; int h; cin >> h; cin >> s; int ans = s.size(); for (int i = 1; s[i]; i++) { if ((s[i] == 'U' && s[i - 1] == 'R') || (s[i] == 'R' && s[i - 1] == 'U')) { s[i] = 'p'; --ans; } } cout << 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=input() s=list(raw_input()) ans=0 while 1: fl=0 for i in range(len(s)-1): if s[i] == 'U' and s[i+1] == 'R': s[i] = 'D' s[i+1] = 'D' ans+=1 fl = 1 if s[i] == 'R' and s[i+1] == 'U': s[i] = 'D' s[i+1] = 'D' ans+=1 fl = 1 if fl == 0: break print len(s) - 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 sys readline = sys.stdin.readline readlines = sys.stdin.readlines ns = lambda: readline().rstrip() ni = lambda: int(readline().rstrip()) nm = lambda: map(int, readline().split()) nl = lambda: list(map(int, readline().split())) prn = lambda x: print(*x, sep='\n') def solve(): n = ni() s = ns() 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() cnt = 0 i = 1 while i < n: if s[i-1:i+1] in ['RU', 'UR']: 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...
n = int(input()) lst = list(input()) s=0 i=0 while i<n: if n-2>=i: if lst[i]=="U" and lst[i+1]=="R" or lst[i]=="R" and lst[i+1]=="U": #del lst[i] #del lst[i+1] s+=1 i+=2 else: #del lst[i] s+=1 i+=1 else: s+=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()) seq = input() # DP problem A = [ [9999]*2 for _ in range(n)] A[0][0] = 1 for i in range(1,n): # 不合 A[i][0] = min(A[i-1][0],A[i-1][1])+1 if seq[i-1:i+1] == 'UR' or seq[i-1:i+1] == 'RU': A[i][1] = A[i-1][0] print(min(A[n-1][0],A[n-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...
n=int(input()) a=list(input()) i=0 ct=0 while i<n: if n==1: ct+=1 break if a[i]=='U' and a[i+1]=='R': ct+=1 i+=2 if i==n-1: ct+=1 break continue if a[i]=='R' and a[i+1]=='U': ct+=1 i+=2 if i==n-1: ct+=1 break continue ct+=1 i+=1 if i==n-1: ct+=1 break print(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...
n=int(input()) s=input() m=0 i=0 while i<n-1: if s[i]!=s[i+1]: # print(s[i],s[i+1]) m+=1 i=i+2 else: i+=1 # print(m) 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...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigInteger; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStr...
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, ct = 0, n; char s[200]; scanf("%d %s", &n, s); for (i = 0; i < (n - 1); i++) { if (((s[i] == 'R') && (s[i + 1] == 'U')) || ((s[i] == 'U') && (s[i + 1] == 'R'))) { ct++; i++; } } printf("%d\n", (n - ct)); 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 = int(input()) seq = input() ans = n i = 0 while i<n-1: if seq[i]!=seq[i+1]: ans -= 1 i += 2 else: 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()) s = input() pr = '' c = 0 for ch in s: if pr == '': pr = ch c+=1 elif ch == pr: c += 1 else: pr = '' 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...
n = int(input()) s = input() c1 = 0 i1 = 0 while(i1<(n-1)): if((s[i1]=='U' and s[i1+1]=='R') or (s[i1]=='R' and s[i1+1]=='U')): c1+=1 i1+=1 i1+=1 print(n - c1)
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=[s[0],] for i in range(1,n): a.append(s[i]) if((a[-1]=='U' and a[-2]=='R' ) or (a[-1]=='R' and a[-2]=='U')): a.pop() a.pop() a.append('D') 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=str(input()) j=0 d=0 while(j<len(s)): if(j==len(s)-1): d=d+1 break if(s[j]!=s[j+1]): j=j+2 d=d+1 if(j==len(s)-1 ): d=d+1 break else: j=j+1 d=d+1 if(j==len(s)-1 ): d=d+1 break ...
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...
a = int(input()) b = list(input()) for i in range(a): if i < len(b)-1 and (b[i] + b[i+1] == "UR" or b[i] + b[i+1] == "RU"): del b[i+1] b[i] = "D" print(len(b))
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.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author noob_coder */ public class...
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 maxn = 1e5 + 300; int main() { ios::sync_with_stdio(0); cin.tie(0); string s; int h; cin >> h; cin >> s; int ans = s.size(); for (int i = 1; s[i]; i++) { if ((s[i] == 'U' && s[i - 1] == 'R') || (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...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; stack<char> st; for (int i = n - 1; i >= 0; i--) st.push(s[i]); int ans = 0; while (true) { string cur = ""; bool f = false; while (!st.empty()) { char t = st.top(); st.pop(); if...
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 { class Answer { int N; String str; public int solve() { int count = 0; int i; for (i = 0; i < N-1; i++) { char ch = str.charAt(i); if (ch == '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...
raw_input() s = raw_input() st = 0 res = len(s) for i in range(len(s) - 1): if st: st = 0 continue if s[i:i+2] in ['UR', 'RU']: st = 1 res -= 1 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...
import java.util.Scanner; public class A954 { public static void main(String[] args){ int n,count=0; Scanner in= new Scanner(System.in); n= in.nextInt(); String way= in.next(); //CharSequence way1= "RU"; //CharSequence way2= "UR"; CharSequence way3= "D1"; ...
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().strip() res = 0 p = 0 while p+1 < n: if s[p] != s[p+1]: res += 1 p += 1 p += 1 print(n - 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...
import re n=input() print n-len(re.findall('RU|UR',raw_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=input() s=str(input()) s=s.replace("URRU","DU") s=s.replace("RUUR","UD") s=s.replace("RU","D") s=s.replace("UR","D") 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, jwb; string s; cin >> n; jwb = n; cin >> s; for (int i = 1; i < n; ++i) { if (s[i] != s[i - 1]) { int j = i; while (j < n && s[j] != s[j - 1]) ++j; --j; --jwb; jwb -= (j - i) / 2; i = j; } } 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...
n = int(input()) res = n a = input() prev = a[0] i = 1 while i < n: if a[i] != prev: if i != n - 1: prev = a[i + 1] res -= 1 i += 2 else: i += 1 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...
import java.util.Scanner; public class Main { public static void main(String []args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); String s = in.next(); int h = n; for(int i = 0 ; i < n ; i++) { if(i < s.length()-1 && ((s.charAt(i)=='R' && s.charAt(i+1)=='U') ||(s.charAt(i)=='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...
#include <bits/stdc++.h> using namespace std; int main() { int N; ios_base::sync_with_stdio(0); cin >> N; string K; cin >> K; int zm = N; for (int i = 1; i < N; i++) { if (K[i] != K[i - 1]) { zm--; if (i < N - 1) K[i] = K[i + 1]; } } cout << zm; }
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 JavaApplication48 { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int m=n; String s=sc.next(); char ch[]=s.toCharArray(); for (int i = 0; i < ch.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...
n = int(input()) s = input() n = len(s) i = 0 ans = 0 while i < n-1: if s[i] != s[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...
/*package whatever //do not write package name here */ import java.io.*; import java.util.*; public class GFG { public static void main (String[] args) { Scanner sc = new Scanner(System.in); sc.nextInt(); String s = sc.next(); char []chr = s.toCharArray(); int cnt = 0; for(int i=0;i<chr.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.util.*; public class Main { public static void main(String[] args) { Scanner cin = new Scanner(System.in); int n = cin.nextInt(); String s = cin.next(); int ans = n; for (int i = 1; i < n; i++) { if (s.charAt(i) != s.charAt(i - 1)) { ans--; i++; } } System.out.println(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 Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); String S = sc.next(); sc.close(); char[] s = S.toCharArray(); int answer = n; for (int i = 0; i < n - 1; i++) { if (s[i] != 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...
# import sys # sys.stdin=open("input.in","r") n=int(input()) s=input() i=0 a=0 while i<n-1: if s[i]!=s[i+1]: i+=1 a+=1 i+=1 print(n-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() i = 0 while i + 1 < len(s): if s[i] == "U" and s[i + 1] == "R" or s[i] == "R" and s[i + 1] == "U": s = s[:i] + s[i + 2:] else: i += 1 print(len(s) + (n - len(s)) // 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...
n=input() a=raw_input() while True: x,y=a.find('RU'),a.find('UR') if x==y==-1: break if x==-1 and y<>-1: a=a.replace('UR', 'D',1) elif y==-1 and x<>-1: a=a.replace('RU', 'D',1) else: if x<y: a=a.replace('RU', 'D',1) else: a=a.replace('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...
#include <bits/stdc++.h> using namespace std; char ch[110]; int n, ans1, ans2; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> ch; char la = ch[0]; for (int i = 1; i < n; i++) if (la != ch[i] && la != 0) { ans1++; la = 0; } else la = ch[i]; la = ch[...
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.*; public class A { public static void main(String[] args) throws IOException { MyScanner sc = new MyScanner(System.in); int n = sc.nextInt(); char[] cs = new char[n]; Str...
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 j = 0 for i in range(n-1): a = s[j:j+2] if a == 'UR' or a == 'RU': count += 1 j += 2 else: j += 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 re n= int(input()) x= str(input()) ans = n-len(re.findall('RU|UR',x)) 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=n a=str(input()) i=0 while i<n: i=i+1 if a[i-1:i+1]=="UR" or a[i-1:i+1]=='RU': s=s-1 i=i+1 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...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; cin >> s; int l = n; for (int i = 0; i < n - 1; i++) { if ((s[i] == 'R' && s[i + 1] == 'U') || (s[i] == 'U' && s[i + 1] == 'R')) { l--; i++; } } cout << l; 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, i, c = 0; string s; cin >> n >> 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++; } } 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...
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int a; cin >> a; string str; cin >> str; int count = 0; char pre = '\0'; for (int i = 0; i < a; i++) { if (pre != '\0') { if (pre != str[i]) { pre = '\0'; } else { 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; public class JavaApplication34 { public static void main(String[] args) { ArrayList<Character> arr=new ArrayList<Character>(); Scanner in =new Scanner(System.in); int n=in.nextInt(); String s=in.next(); 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 A { public static void main(String[] args) { Scanner inp = new Scanner(System.in); int a = inp.nextInt(); inp.nextLine(); String s = inp.nextLine(); int cnt = 0; // R:82 // D: 68 // U 85 boolean prev = false; for (int i=0;i<s.length();i++) { if(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...
aa= int(input()) b= input() i=0 a=0 while i<aa-1: if b[i]!=b[i+1]: a+=1 i+=1 i+=1 print(aa-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...
a= int(input()) b= input() c=list(b) lend=len(c) #print(lend) dhat=['R','U'] khat=['U','R'] for i in range(0,lend-1): if (c[i:i+2])==dhat or c[i:i+2]==khat: c[i]='D' c.remove(c[i+1]) fin= len(c) print(fin)
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()) path = list(input()) path.append("") index = 0 passos = 0 while True: if index >= len(path) - 1: break if path[index] == "U" and path[index + 1] == "R": passos += 1 index += 2 elif path[index] == "R" and path[index + 1] == "U": passos += 1 index += 2 else: pass...
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 EducationalRound40; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; im...
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 s = sc.next(); StringBuilder sb = new StringBuilder(s); String newString = sb.toString(); newString = newString.replaceAll("UR|RU", "D"); //sb...
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 = status = 0 for i in range(n-1): if s[i]!=s[i+1] and status == 0: count+=1 status = 1 elif status==1: status = 0 continue 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...
n=input() A=raw_input() n=len(A) i=0 ans=0 while(i<n-1): if((A[i]=='R' and A[i+1]=='U') or (A[i]=='U' and A[i+1]=='R')): ans=ans+1 i=i+1 i=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...
n = int(raw_input()) palavra = raw_input() palavra = list(palavra) ans = [] for i in range(1,n): if palavra[i-1] == "U" and palavra[i] == "R": palavra[i] = "D" palavra[i-1] = "*" elif palavra[i-1] == "R" and palavra[i] == "U": palavra[i] = "D" palavra[i-1] = "*" cont = 0 for 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()) a,b,bol=0,'',0 for i in input(): if b==i or b=='' or bol: a+=1 bol=0 else: bol=1 b=i print(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...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; string a; cin >> n >> a; k = n; for (int i = 0; i < n - 1; i++) { if (a[i] != a[i + 1]) { k--; i++; } } cout << 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...
n = int(input()) p = input() i = 0 c = 0 while(i < len(p)): if(i < len(p)-1 and (p[i] + p[i+1] == 'RU' or p[i] + p[i+1] == 'UR')): c += 1 i += 2 else: i += 1 c += 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...
#include <bits/stdc++.h> using namespace std; char str[105]; int main() { int n, cnt = 0; scanf("%d%s", &n, str); for (int i = 0; i < n; i++) { if (str[i] != str[i + 1]) i++; cnt++; } printf("%d\n", 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...
#include <bits/stdc++.h> using namespace std; const int base = 1000000000; const int base_digits = 9; struct bigint { vector<int> a; int sign; int size() { if (a.empty()) return 0; int ans = (a.size() - 1) * base_digits; int ca = a.back(); while (ca) ans++, ca /= 10; return ans; } bigint 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...
def main(): n = int(input()) line = input() ans = 0 i = 0 while i < n - 1: if line[i] != line[i + 1]: ans += 1 i += 2 else: i += 1 print(n - ans) main()
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...
T_ON = 0 DEBUG_ON = 1 MOD = 998244353 def solve(): n = read_int() s = input() i = 0 count = 0 while i < n - 1: if s[i] != s[i+1]: count += 1 i += 2 else: i += 1 print(n - count) def main(): T = read_int() if T_ON else 1 for i in ra...
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 Main { public static void main(String []args) { Scanner sc = new Scanner(System.in); int num = sc.nextInt(); String word = sc.next(); char[] wordc = word.toCharArray(); int counter = num; for(int i=0;i<num;i++) { if(i==(num-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...
_ = input() x = input() last = x[0] res = 0 for c in x[1:]: if last == "U" and c == "R" or last == "R" and c == "U": last = "D" res += 1 else: last = c print(len(x) - res)