Search is not available for this dataset
name
stringlengths
2
112
description
stringlengths
29
13k
source
int64
1
7
difficulty
int64
0
25
solution
stringlengths
7
983k
language
stringclasses
4 values
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
n = int(input()) s = input() r = 0 i = 0 while(i < n): r += 1 if(i == n - 1): break if(s[i] != s[i+1]): i += 2 else: i += 1 print(r)
PYTHON3
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
import java.io.*; import java.util.*; import java.lang.*; import java.math.*; public class DiagonalWalk { public void run() throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); String s = sc.next(); int count = 0; for (int i = 0; i<n-1; i++) { if (s.charAt(i) == 'R' && ...
JAVA
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
n = int(raw_input()) mov = raw_input() i = 0 temp1 = 0 while i < n-1: if mov[i] == mov[i+1]: i += 1 else: temp1 += 1 i += 2 print(n-temp1)
PYTHON
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
input() X = input() i = 1 LEN = len(X) while i < LEN: if X[i] + X[i - 1] in ("RU", "UR"): X = X[:i - 1] + "D" + X[i + 1:] LEN -= 1 i += 1 print(len(X))
PYTHON3
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
#include <bits/stdc++.h> using namespace std; int main() { int length; cin >> length; string input; cin >> input; int total = 0; int i; for (i = 0; i < length - 1; i++) { if (input[i] == input[i + 1]) { total++; if (i == length - 2) { } } else { total++; i++; } ...
CPP
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n, i, cnt = 0; cin >> n; char arr[n]; for (i = 0; i < n; i++) cin >> arr[i]; for (i = 0; i < n - 1; i++) { if (arr[i] == 'U' && arr[i + 1] == 'R') { arr[i] = 'D'; arr[i + 1] = 'D'; } else if (arr[i] == 'R' && arr[i + 1] == 'U')...
CPP
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
n = int(input()) seq = input() res = n i = 0 while i < n - 1: curr = seq[i:i+2] if curr == 'RU' or curr == 'UR': res -= 1 i += 2 else: i += 1 print(res)
PYTHON3
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
n = int(raw_input()) s = raw_input() ans = n quota = 1 for i in xrange(n-1): if quota == 1 and (s[i:i+2] == 'UR' or s[i:i+2] == 'RU'): ans -= quota quota = 0 else: quota = 1 print ans
PYTHON
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
#include <bits/stdc++.h> using namespace std; int main() { char a[1001]; int n; cin >> n; int count = 0; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { count++; if (a[i] == 'R' && a[i + 1] == 'U') i++; else if (a[i] == 'U' && a[i + 1] == 'R') i++; ...
CPP
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
import java.util.*; public class Main{ static Scanner in = new Scanner(System.in); public static void main(String args[]){ int x = in.nextInt(); String y = in.next(); String ans = ""; for(int i=0;i<y.length();i++){ // System.out.println(ans + " " + i); if...
JAVA
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string str; cin >> str; int cnt = 0; int pre = 0; for (int i = 0; i < str.size() - 1; i++) { if ((str[i] == 'R' && str[i + 1] == 'U') || (str[i] == 'U' && str[i + 1] == 'R')) { cnt++; i++; } } cnt =...
CPP
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
import java.util.Scanner; public class A { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); String s = in.next(); int count = 0; int i = 0; boolean check = false; while( i < s.length()-1) { if(s.charAt(i) != s.charAt(i+1)) { if(i == s.leng...
JAVA
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
n=int(input()) s=input() a=[] for i in s: a.append(i) b=[] i=0 while i<len(a): if i!=len(a)-1: #print(a[i],a[i+1]) if a[i]!=a[i+1]: b.append("D") i=i+1 else: b.append(a[i]) else: b.append(a[i]) #print(b) i=i+1 print(len(b))
PYTHON3
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
n = int(input()) s = input() ans ='' itr = 0 while itr < n and itr != n - 1: if s[itr] != s[itr + 1]: ans += 'D' itr += 2 else: ans += s[itr] itr += 1 if itr == n - 1: ans += s[n - 1] print(len(ans))
PYTHON3
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
#include <bits/stdc++.h> using namespace std; int main() { string s; short n, cnt = 0; cin >> n >> s; bool r = false, u = false; for (int i = 0; i < n; i++) { cnt++; if (s[i] == 'R') { if (u == true) { cnt--; u = false; r = false; continue; } r = true;...
CPP
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
n = readline(); str = readline().split(''); var count = 0; for (var i = 0; i < n; i++) { if ((str[i] == 'R' && str[i + 1] == 'U') || (str[i] == 'U' && str[i + 1] == 'R')) { count++; i++; } else { count++; }; }; print(count);
JAVA
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
import re n=input() s=input() s=re.sub(r'(RU)|(UR)','D',s) print(len(s))
PYTHON3
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
n=int(input()) a=list(input()) i=0 while i<len(a)-1: if (a[i]=='R' and a[i+1]=='U') or (a[i]=='U' and a[i+1]=='R'): a[i]='D' del(a[i+1]) i+=1 print(len(a))
PYTHON3
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader r = new BufferedReader(new InputStreamReader(System.in)); String str1 = r.readLine(); String str2 = r.r...
JAVA
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
n = int(input().strip()) s = list(input().strip()) count = 1 def checkR(i): global s if s[i-1] != 'U': return 1 else: s[i] = 'D' return 0 def checkU(i): global s if s[i-1] != 'R': return 1 else: s[i] = 'D' return 0 for i in range( 1,n ): if s...
PYTHON3
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
#include <bits/stdc++.h> char s[2231231]; int main() { int ans = 0; int n; scanf("%d", &n); scanf("%s", s); for (int i = 0; s[i]; i++) { if (s[i] == 'U' && s[i + 1] == 'R' || s[i] == 'R' && s[i + 1] == 'U') ans++, i++; else ans++; } printf("%d\n", ans); }
CPP
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int n; cin >> n; string s; cin >> s; long long int mv = n; for (long long int i = 0; i < n - 1; i++) { if (s[i] == 'U' && s[i + 1] == 'R') { mv--; s[i +...
CPP
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
n = int(input()) s = list(input()) a = ['U','R'] b = ["R","U"] for i in range(n-1): if s[i:i+2] == a or s[i:i+2] == b: s[i] = 'D' s[i+1] = "D" print(n - s.count("D") // 2)
PYTHON3
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
#include <bits/stdc++.h> using namespace std; const int maxn = 1e2 + 5; int main() { int n, cnt = 0; bool judge = 0; char ch[maxn]; cin >> n; cin >> ch[1]; for (int i = 2; i <= n; i++) { cin >> ch[i]; if (judge) judge = 0; else if (ch[i] - ch[i - 1]) { cnt++; judge = 1; } ...
CPP
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
#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 < s.size(); ++i) { if (i < s.size() - 1 && (s[i] == 'U' && s[i + 1] == 'R') || (s[i] == 'R' && s[i + 1] == 'U')) { --n; ++i; } } cout << n << endl; ...
CPP
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string input; cin >> input; int i = 0; int counter = 0; while (i < n - 1) { if (input[i] == 'R' && input[i + 1] == 'U') { counter++; i += 2; } else if (input[i] == 'U' && input[i + 1] == 'R') { counter++;...
CPP
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n; string s; cin >> n >> s; for (int i = 0; i < n - 1; i++) { if ((s[i] == 'R' && s[i + 1] == 'U') || (s[i] == 'U' && s[i + 1] == 'R')) { s[i] = 'D'; s[i + 1] = '0'; } } cout << n - count(s.begin(), s.end(), '0'); }
CPP
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
#include <bits/stdc++.h> using namespace std; char s[110]; int main() { int ans = 0, n; cin >> n; cin >> s; for (int i = 0; i < n; i++) { if ((s[i] == 'U' && s[i + 1] == 'R') || (s[i] == 'R' && s[i + 1] == 'U')) { ans++; i++; } } cout << n - ans << endl; }
CPP
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
n = int(raw_input()) m = raw_input() d = ['UR', 'RU'] tamanho = n i = 0 while i < len(m)-1: if m[i] + m[i + 1] in d: tamanho -= 1 i += 2 else: i += 1 print tamanho
PYTHON
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n, i; string s; cin >> n >> s; while (((n > 100) or (n < 1)) or (s.length() != n)) { cin >> n >> s; } for (i = 0; i < s.length(); i++) { if ((s[i] == 'R') and (s[i + 1] == 'U')) { s.erase(i, 2); s.insert(i, 1, 'D'); } ...
CPP
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
import re n = input() seq = input() def replace_char(seq): slen = len(seq) for i,c in enumerate(seq): if(i<=len(seq)-2): if((seq[i]=="R" and seq[i+1]=="U") or (seq[i]=="U" and seq[i+1]=="R")): seq = seq[:i] + "D" + (seq[i+2:] if (i<len(seq)-1) else "") break ...
PYTHON3
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
#encoding: utf-8 n = int(raw_input()) moves = raw_input() last = '' found = False result = '' for char in moves: if ((last == 'R' and char == 'U') or (last == 'U' and char == 'R')): result = result + 'D' last = '' else: result = result + last last = char result = result + last print(len(result)) ...
PYTHON
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
import java.io.*; import java.text.*; import java.util.*; import java.math.*; public class template { public static void main(String[] args) throws Exception { new template().run(); } public void run() throws Exception { FastScanner f = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int n ...
JAVA
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
import java.util.*; public class DiagonalWalking { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); String s1=sc.nextLine(); String s=sc.nextLine(); int t=0; for(int i=0;i<n-1;i++) { char c=s.charAt(i); char c1=s.charAt(i+1); if(c=='U') { if(...
JAVA
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; char c[n]; cin >> c; int cnt = 0; for (int i = 0; i < n; i++) { if ((c[i] == 'U' && c[i + 1] == 'R') || (c[i] == 'R' && c[i + 1] == 'U')) { cnt++; i++; } } cout << n - cnt; }
CPP
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner var = new Scanner(System.in); String s,s1; int i,count,len,a; while (var.hasNext()) { a = var.nextInt(); count=0; s1=var.nextLine(); ...
JAVA
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
n=int(input()) s=list(input()) i=1 while i<len(s): if (s[i]=='R' and s[i-1]=='U'): n-=1 #i+=1 s[i]='D' elif (s[i]=='U' and s[i-1]=='R'): n-=1 #i+=1 s[i]='D' i+=1 print(n)
PYTHON3
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
n = int(input()) s = input() i = 0 cnt = 0 while i < n - 1: if s[i] + s[i + 1] == 'RU' or s[i] + s[i + 1] == 'UR': cnt += 1 i += 1 i += 1 print(n - cnt)
PYTHON3
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
ans = int(input()) inputString = input() skip = False for i in range(len(inputString) - 1): if skip: skip = False continue if inputString[i] + inputString[i + 1] == "RU" or inputString[i] + inputString[i + 1] == "UR": ans -= 1 skip = True print(ans) exit()
PYTHON3
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } const int MAXN = 100; int n; char s[MAXN + 1]; void run() { scanf("%d", &n); scanf("%s", s); int ret = 0; char prv = '?'; for (int i = (0); i < (n); ++i) { if (prv == 'U' && s[i] ==...
CPP
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
import java.io.BufferedReader; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { public static void main(String[] args) { InputReader reader = new InputReader(System.in); int n = reade...
JAVA
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
import java.io.DataInputStream; import java.io.IOException; public class Task954A { public static class FastScanner { protected static final int STRBUFFERLENGTH = 0x1000; protected DataInputStream dataInputStream; protected byte[] buffer = new byte[0x10000]; protected byte[] strb...
JAVA
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
/* package whatever; // 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 Ideone { public static void main (String[] args) throws java.lang.Exception { // your code goes here Scanner scan=new ...
JAVA
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
n = int(input()) st = input() ans = n i = 1 while i < n: if st[i - 1] != st[i]: ans -= 1 i += 1 i += 1 print(ans)
PYTHON3
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
n=int(input()) s=input() i=0 while i<len(s)-1: if s[i]!=s[i+1]: i+=2 n-=1 else: i+=1 print(n)
PYTHON3
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
#include <bits/stdc++.h> using namespace std; int main() { int inp; string s; cin >> inp >> s; int n = s.size(); if (n == 0) { cout << s.size(); return 0; } if (n == 1) { cout << s.size(); return 0; } int count = 0; for (int i = 0; i < n; i++) { if (s[i] != s[i + 1] && s[i + 1] !...
CPP
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
n=int(raw_input()) s=raw_input() previous="#" res=0 for i in s: res+=1 if "".join(sorted(previous+i))=="RU": previous="#" res-=1 else: previous=i print res
PYTHON
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Scanner; public class CodeForces { public static void main(String[] args) { Scanner input = new Scanner(new BufferedReader(new InputStreamReader(System.in))); int n = input.nextInt(); String s = input.next(); boolean done = fa...
JAVA
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
n=int(input()) s=input() res=0 i=0 while i<n-1: if s[i]!=s[i+1]: res+=1 i+=2 else: i+=1 print(n-res)
PYTHON3
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
#include <bits/stdc++.h> using namespace std; int main() { long long n, answer = 0; string s; cin >> n >> s; for (int i = 0; i < n - 1; ++i) { if (s[i] != s[i + 1]) { answer++; i++; } } cout << n - answer << endl; return 0; }
CPP
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
ans, s = [], input() for c in input(): if len(ans) == 0 or ans[-1] == 'D' or ans[-1] == c: ans += [c] else: ans[-1] = 'D' print(len(ans))
PYTHON3
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
n=int(input()) s=input().strip() i=0 c=0 while(i<n-1) : if s[i]=='U' and s[i+1]=='R' : i+=2 c+=1 elif s[i]=='R' and s[i+1]=='U' : i+=2 c+=1 else: i+=1 print(n-c)
PYTHON3
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
#include <bits/stdc++.h> using namespace std; int main() { char a[1000000]; long long n, k, m, i, b, c = 0, d = 0; cin >> n; for (i = 1; i <= n; i++) { cin >> a[i]; } for (i = 2; i <= n; i++) { if (a[i] != a[i - 1]) { c++; i++; } } cout << n - c; }
CPP
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
a=int(input());z=input();s=0;i=0 while(i<a-1): if z[i]!=z[i+1]:s+=1;i+=2 else:i+=1 print(a-s)
PYTHON3
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
from sys import stdin, stdout ti = lambda : stdin.readline().strip() ma = lambda fxn, ti : map(fxn, ti.split()) ol = lambda arr : stdout.write(' '.join(str(i) for i in arr) + '\n') os = lambda i : stdout.write(str(i) + '\n') olws = lambda arr : stdout.write(''.join(str(i) for i in arr) + '\n') n = int(ti()) path = l...
PYTHON
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
user_in1 = input() user_in2 = input() newstr = "" count = 0 while True: if count >= len(user_in2)-1: if not count >= len(user_in2): newstr = newstr + user_in2[count] break else: if user_in2[count] + user_in2[count+1] == "RU" or user_in2[count] + user_in2[count+1] == "UR": newstr = newstr + "d" count +...
PYTHON3
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
# -*- coding: utf - 8 -*- """"""""""""""""""""""""""""""""""""""""""""" | author: mr.math - Hakimov Rahimjon | | e-mail: mr.math0777@gmail.com | | created: 22.03.2018 12:58 | """"""""""""""""""""""""""""""""""""""""""""" # inp = open("input.txt", "r"); input = inp.readline; out = open...
PYTHON3
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
#include <bits/stdc++.h> using namespace std; int read() { int x = 0, flag = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') flag = -1; ch = getchar(); } while (isdigit(ch)) { x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar(); } return x * flag; } int n; int s[109]; int mai...
CPP
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
import java.util.*; public class diagonalWalking { public static void main(String... args) { Scanner kbd = new Scanner(System.in); int num = kbd.nextInt(); char[] line = kbd.next().toCharArray(); for (int i = 0; i < line.length - 1; i++) { if ((line[i] == 'U' && line[i + 1] == 'R') || line[i] == 'R' && li...
JAVA
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; long long power(long long a, long long b, long long p) { if (a == 0) return 0; long long res = 1; a %= p; while (b > 0) { if (b & 1) res = (res * a) % p; b >>= 1; a = (a * a) % p; } return res; } void solve() { long l...
CPP
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
import re def main(): n = int(input()) s = input() n = 1 # dummy value while n > 0: s,n = re.subn("(RU|UR)","D",s) print(len(s)) if __name__ == '__main__': main()
PYTHON3
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
import java.util.*; import java.io.*; import java.math.*; public class Main{ static FR in; public static void main(String[] args)throws Exception{ in = new FR(); int n = ni(); String s = nln(); int ctr=0, ctr2=0; for( int i=1;i<s.length();i++ ){ if(( s.charAt(i-...
JAVA
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
n=int(input()) x=list(input()) p=len(x);i=0 while i<n-1: if(x[i]!=x[i+1]): p-=1 i+=2 else: i+=1 print(p)
PYTHON3
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
n = int(raw_input()) A = raw_input() res = "" i = 0 ct = 0 while i < n-1: if A[i] == 'U' and A[i+1] == 'R': res += 'D' i += 2 ct += 2 elif A[i] == 'R' and A[i+1] == 'U': res += 'D' i += 2 ct += 2 else: res += A[i] i += 1 ct += 1 print len(res) + (n-ct)
PYTHON
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
n=int(input()) s=input() stk=[] for i in s: if not stk: stk.append(i) elif stk[-1]+i=="RU" or stk[-1]+i=="UR": stk.pop() stk.append('D') else: stk.append(i) print(len(stk))
PYTHON3
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
n = input() s = input() f = False st = 0; for i in range(0, int(n)-1): if f: f = False; else: if s[i] != s[i+1]: i+=1 f = True; st+=1 print(int(n)-st)
PYTHON3
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
import java.util.*; import java.io.*; public class Main { void solve(){ int n=ni(); char s[]=ns().toCharArray(); int ans=s.length; for(int i=0;i<s.length-1;i++){ if((s[i]=='U' && s[i+1]=='R') || (s[i]=='R' && s[i+1]=='U') ){ ans--; i++; ...
JAVA
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
if __name__ == '__main__': n = int(input()) s = input() co = i = 0 while i < len(s)-1: if s[i] == 'U' and s[i+1] == 'R' or s[i] == 'R' and s[i+1] == 'U': co += 1 i += 2 else: i += 1 print(len(s) - co)
PYTHON3
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
import java.util.ArrayList; import java.util.LinkedList; import java.util.ListIterator; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int length = scanner.nextInt(); int result=0; String sequence = ...
JAVA
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
n=int(input()) a=list(input()) i=0 while i<len(a)-1: if a[i]=='U' and a[i+1]=='R' or a[i]=='R' and a[i+1]=='U': a[i]='A'; del a[i+1] i+=1 print(len(a))
PYTHON3
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
n = int(input()) a = input() for i in range(1,n): if a[i] != a[i-1] and a[i-1] != "0": a = a[:i] + "0" + a[i+1:] print(n-a.count("0"))
PYTHON3
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
n = int(input()) s = input() ans = 0 out = [] for c in s: if out and out[-1] != 'D' and out[-1] != c: out.pop() out.append('D') else: out.append(c) print(len(out))
PYTHON3
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n, d = 0; string x; cin >> n >> x; for (int i = 0; i < x.size(); i++) { if (i + 1 < x.size() && x[i] + x[i + 1] == 'U' + 'R') { i++; d++; } } cout << x.size() - d << endl; return 0; }
CPP
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
n = int(input()) l = list(input()) i = 1 while i<len(l): if(l[i-1]!=l[i] and min(l[i-1],l[i])!='D'): l[i] = 'D' del(l[i-1]) i = 1 else: i+=1 print(len(l))
PYTHON3
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
import java.util.Scanner; public class A954 { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int length = 0; String input = sc.next(); if (input.length() == 1) { System.out.println("1"); } else { ...
JAVA
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
import java.util.*; import java.io.*; import java.math.*; public class loser { static class InputReader { public BufferedReader br; public StringTokenizer token; public InputReader(InputStream stream) { br=new BufferedReader(new InputStreamReader(stream),32768); ...
JAVA
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
n = int(input()) s = input() L = len(s) cur = s[0] i = 0 while i < len(s) - 1: if s[i] != s[i + 1]: L -= 1 i += 1 i += 1 print(L)
PYTHON3
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
#include <bits/stdc++.h> using namespace std; const int MAXN = 15010; struct fastIO { fastIO() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } }; int n, dp[110], ans; string second; int main() { fastIO(); cin >> n >> second; dp[0] = 1; for (int i = 1; i < n; i++) { if ((second[i -...
CPP
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
a=int(input()) b=list(input()) cnt=0 while(len(b)>1): c, d=b.pop(), b. pop() cnt+=1 if c==d: b. append(c) print(cnt+len(b))
PYTHON3
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
n=input() s=raw_input()+' ' a=0 i=0 while i<n: w=s[i]+s[i+1] a+=1 if w=='UR' or w=='RU': i+=1 i+=1 print a
PYTHON
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
n=int(input()) s=input() l=[] i=0 while(i<n): if i==n-1: l.append(s[i]) i=i+1 elif s[i]!=s[i+1]: l.append("D") i=i+2 else: l.append(s[i]) i=i+1 print(len(l))
PYTHON3
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
##################################### import atexit, io, sys, collections, math, heapq buffer = io.BytesIO() sys.stdout = buffer @atexit.register def write(): sys.__stdout__.write(buffer.getvalue()) ##################################### n = raw_input() s= raw_input() ans = len(s) stack =[] for u in s: if st...
PYTHON
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
# Diagonal Walking n = input() moves = input() c = 0 ignore = False for i in range(len(moves)): if ignore == True: ignore = False else: if i < len(moves) - 1 and moves[i] != moves[i+1]: ignore = True c += 1 print(c)
PYTHON3
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
n = int(input()) s = list(input()) i = -1 while True: i += 1 if n%2 == 0: if i == len(s) - 2: if s[i] + s[i + 1] == "RU": s[i] = "D" s.pop(i + 1) if s[i] + s[i + 1] == "UR": s[i] = "D" s.pop(i + 1) break ...
PYTHON3
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
#include <bits/stdc++.h> using namespace std; char s[101]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { char t; cin >> t; s[i] = t; } int c = n; for (int i = 1; i < n; i++) { if (s[i] == 'R' and s[i - 1] == 'U') { s[i] = 'D'; c--; } else if (s[i] == 'U' and s[i...
CPP
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
t = int(input()) S = input() ans = len(S) i = 0 while i<len(S)-1: if S[i]!=S[i+1]: ans-=1 i +=2 else: i+=1 print(ans)
PYTHON3
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; string str; cin >> str; stack<char> st; st.push(str[0]); for (int i = 1; i < n; i++) { char ch = st.top(); if (ch == 'R' && str[i] == 'U') { st.pop(); st.pus...
CPP
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
n = int(input().strip()) string = input().strip() idx = 0 pairs =0 while idx < n - 1: if string[idx] != string[idx+1]: idx += 2 pairs += 1 else: idx += 1 print(n - pairs)
PYTHON3
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
n=int(input()) s=input() ctr=0;i=0 if len(s)==1: print(1) else: while True: a=s[i];b=s[i+1] if a==b: z=1;i+=1; else: ctr+=1 i+=2 if i>=len(s)-1: break print(len(s)-ctr)
PYTHON3
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
from re import sub input() print(len(sub(r"RU|UR", "D",input())))
PYTHON3
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import ja...
JAVA
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
import re k=int(input()) Str=input() Str = re.sub('(RU|UR)', 'D', Str) print(len(Str))
PYTHON3
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
n = input() str = input() i = 0 count = 0 flag= 1 while(i < len(str) -1): if(str[i] != str[i+1]): str = str[0:i]+'d'+str[i+2:] i = i+1 #print(str) print(len(str))
PYTHON3
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } const double EPS = 1e-10; const double...
CPP
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
import java.util.Scanner; import java.util.WeakHashMap; public class Main { public static void main(String[] args) { // write your code here Scanner scanner = new Scanner(System.in); long x=scanner.nextLong(); String sequ=scanner.next(); String an=sequ; int c=0; ...
JAVA
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
x = int(input()) y = input() i = 0 result = 0 while i < x: if i+1 == x: result += 1 break c = y[i] a_set = set([y[i], y[i+1]]) a_set.remove(c) if len(a_set) == 0: i += 1 else: i += 2 result += 1 print(result)
PYTHON3
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
import java.util.Scanner; public class covidSpread2 { static Scanner sc = new Scanner(System.in); public static void main(String[] args) { solvex(); } public static void solvex() { int n = sc.nextInt(); String str = sc.next(); for (int i = 0; i < str.length(); i++) { char ch = str.charAt(i); if (ch...
JAVA
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
import java.io.*; import java.math.*; import java.util.*; import static java.util.Arrays.fill; import static java.lang.Math.*; import static java.util.Arrays.sort; import static java.util.Collections.sort; public class A954 { public static int mod = 1000000007; public static long INF = (1L << 60); static FastS...
JAVA
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
#include <bits/stdc++.h> using namespace std; char seq[100]; int main() { int n; cin >> n; for (int i = 0; i < n; ++i) cin >> seq[i]; int ans = 0; for (int i = 1; i < n;) { if (seq[i] != seq[i - 1]) { ans++; i += 2; } else { i++; } } ans = n - ans; cout << ans << endl; re...
CPP
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
n = int(input()) moves = list(input()) count = 0 i = 0 while i < n - 1: if moves[i] != moves[i + 1]: count += 1 i += 2 else: i += 1 print(n - count)
PYTHON3