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 | import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;
public class edu_40_A
{
InputStream is;
PrintWriter out;
int n;
long a[];
private boolean oj = System.g... | 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>
int main() {
int n, flag = 0;
char a[110];
scanf("%d", &n);
scanf("%s", a);
for (int i = 0; i < n - 1; i++) {
if (a[i] != a[i + 1]) {
flag++;
i++;
}
}
printf("%d\n", n - flag);
}
| 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 | def f(t):
if t.find('RU')==-1 and t.find('UR')==-1:
return len(t)
if t in mem:
return mem[t]
if t.find('RU')==-1:
i=t.find('UR')
elif t.find('UR')==-1:
i=t.find('RU')
else:
i=min(t.find('RU'), t.find('UR'))
ans=min(f(t[i+2:]), f(t[i+1:])) + 1 + len(t[:i])
... | 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 | def solution(a):
i=0
ans=len(a)
while i<len(a)-1:
if a[i]!=a[i+1]:
ans-=1
i+=1
i+=1
return ans
def answer():
n = int(input())
a = list(input())
print(solution(a))
answer() | 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;
bool valid(char a, char b) {
if (a == 'U' && b == 'R') return true;
if (b == 'U' && a == 'R') return true;
return false;
}
int main() {
long long int n, cnt = 0;
string s;
cin >> n;
cin >> s;
for (int i = 1; i < n; i++) {
if (valid(s[i - 1], 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())
count=0
i=0
while i<n-1:
if s[i]!=s[i+1]:
count+=1
i+=2
else:
count+=1
i+=1
while i<n:
count+=1
i+=1
print(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 | while True:
try:
n = int(input())
s = input()
stck = list()
for ch in s:
if not stck:stck.append(ch)
elif stck[-1] != ch and stck[-1]!= 'D':
del stck[-1]
stck.append('D')
else:
stck.append(ch)
print(len(stck))
except EOFError:
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;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
string s;
cin >> s;
int ans = 0;
char c = 'a';
for (int i = 0; i < n; i++) {
if ((s[i] == 'U' && c == 'R') || (s[i] == 'R' && c == 'U')) {
c = 'D';
ans += 1;
} else ... | 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 run() {
int n = 0;
cin >> n;
string str;
cin >> str;
int i = 0, ans = n;
while (i < n) {
if (i <= n - 2) {
if ('R' == str[i] && 'U' == str[i + 1]) {
ans--;
i += 2;
} else if ('U' == str[i] && 'R' == str[i + 1]) {
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 | n=int(input())
s = list(input())
i =0
c=0
while i < n-1:
if (s[i]=='U' and s[i+1]=='R') or (s[i]=='R' and s[i+1]=='U'):
c+=1
i+=1
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>
int main() {
int i, n, count = 0;
char a[1000];
scanf("%d", &n);
scanf("%s", a);
for (i = 0; i < n; i++) {
if (a[i] == 'U' && a[i + 1] == 'R') {
count++;
i++;
} else if (a[i] == 'R' && a[i + 1] == 'U') {
count++;
i++;
} else
count++;
}
pri... | 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 | # ===================================
# (c) MidAndFeed aka ASilentVoice
# ===================================
# import math
# import collections
# ===================================
n = int(input())
q = [str(x) for x in input()]
flag = 0
ans = 0
for i in range(n-1):
if flag:
flag = 0
continue
s = q[i]+q[i+1]
i... | 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:i+2] == 'UR' or s[i:i+2] == 'RU':
cnt += 1
i += 2
else:
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 | n = int(raw_input())
s = raw_input()
x = 0
i = 1
while i<n:
if (s[i]=='U' and s[i-1]=='R') or (s[i]=='R' and s[i-1]=='U'):
i += 2
x += 1
else:
i += 1
x += (n - 2*x)
print x | 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;
string s;
cin >> n >> s;
int k = 0;
for (int i = 0; i < n - 1; i++) {
if (s[i] != s[i + 1]) {
i++;
k++;
}
}
cout << n - k;
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())
st=input()
p=n;i=0
while i<n-1:
if st[i]=='R':
if st[i+1]=='U':
i+=2
p-=1
else:
i+=1
else:
if st[i+1]=='R':
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 | length = int(raw_input())
x = raw_input()
cont = 0
descarte = []
for i in xrange(length-1):
if (i not in descarte):
if x[i] == "U":
if x[i+1] == "R":
cont += 1
descarte.append(i + 1)
elif x[i] == "R":
if x[i+1] == "U":
descarte.... | 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()
l=str(raw_input())
c=1
pair=0
for i in range(1,len(l)):
if l[i]!=l[i-1]:
#print(i)
c+=1
if i==len(l)-1:
pair+=c/2
else :#flush stack
pair+=c/2
c=1
#print(pair)
print(len(l)-pair)
| 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;
string s;
cin >> N >> s;
int bella = N;
for (int i = 1; i < N; i++)
if (s[i] != s[i - 1]) {
bella--;
i++;
}
cout << bella;
}
| 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(raw_input())
# a = map(int, raw_input().split())
s = raw_input()
c = 0
i = 0
while i<len(s)-1:
if(s[i]=='U' and s[i+1]=='R'):
c+=1
i+=2
elif(s[i]=='R' and s[i+1]=='U'):
c+=1
i+=2
else:
i+=1
l = len(s) - c
print 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 | def main():
n = int(input())
s = input()
total_replaced = 0
d = 1 # dummy value
while d != 0:
d,s = replstr(s)
#print(d,s)
total_replaced += d
print(n - total_replaced)
def replstr(s):
r = ""
d = 0
i = 0
while i < len(s):
z = s[i:i+2]
if z... | 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 | """
ATSTNG's ejudge Python3 solution template
(actual solution is below)
"""
import sys, queue, string, math, itertools
try:
import dev_act_ffc429465ab634 # empty file in directory
DEV = True
except:
DEV = False
def log(*s):
if DEV: print('LOG', *s)
class EJudge:
def __init__(self, problem="def... | 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()
total = 0
i = 0
while i<(n-1):
#D
if (s[i]=='U' and s[i+1]=='R') or (s[i]=='R' and s[i+1]=='U'):
total+=1
i+=1
i+=1
print(len(s)-total)
| 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()
f =0
r = 0
s = raw_input()
for i in xrange(n-1):
#print i,s[i],s[i+1]
if s[i]<>s[i+1] and f==0:
r+=1
f = 1
elif s[i]<>s[i+1] and f==1:
pass
f= 0
else:
f=0
print n-r
| 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.util.*;
public class DiagonalWalking {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
String walk = in.next();
int ans = 0;
for (int i = 0; i < n; i++) {
if (i < n - 1 && walk.char... | 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 n;
string s;
int main() {
cin >> n >> s;
int i = 1;
while (i < s.length()) {
if (s[i] != s[i - 1]) {
n--;
i += 2;
} else
i++;
}
cout << n;
}
| 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())
steps = input()
stack = [steps[0]]
for i in range(1, n):
s = steps[i]
if s == 'R' and stack[-1] == 'U' or s == 'U' and stack[-1] == 'R':
stack.pop()
stack.append('D')
else:
stack.append(s)
print(len(stack))
| 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 | //package com.company;
import java.io.*;
import java.util.*;
public class Main {
static long TIME_START, TIME_END;
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
// Scanner sc = new Scanner(new FileInputStream("Test.in"));
PrintWriter pw... | 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.math.*;
import java.io.*;
public class CF954A {
final int MOD = (int) 1e9 + 7;
final double ERROR = 1e-9;
final double oo = 1e50;
public CF954A(FastScanner scan, PrintWriter out) {
int n = scan.nextInt();
String walk = scan.next();
String res = "";
for(int i = 0 ; i < walk... | 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() {
char s[110], c;
int len = 0, n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> c;
s[len++] = c;
if (len > 1 && s[len - 2] != s[len - 1] && s[len - 2] != 'D') {
len -= 2;
s[len++] = 'D';
}
}
s[len++] = '\0';
cout << strl... | 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 Path {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
sc.nextLine();
char t[]=sc.nextLine().toCharArray();
int cp=0,i;
for(i=0;i<t.length;i++){
cp++;
if(i<t.length-1)
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 | def a954(first, second):
k = 0
i = 0
while i < len(second)-1:
if second[i] != second[i+1]:
k = k + 1
i = i + 1
i = i + 1
return len(second) - k
if __name__ == '__main__':
first = int(input())
second = input()
print(a954(first, second))
| 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 long long mod = 1000000007;
const double eps = 1e-9;
long double pi = 3.14159265358979323846264338327950;
long double e = 2.7182818284590452353602874713527;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n, ans = 0;
cin >> n;
string s;... | 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 = input()
ans = 0
i = 0
while i < len(s) - 1:
if s[i] != s[i + 1]:
ans += 1
i += 1
i += 1
print(n - 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().strip())
L = list(input().strip())
i = 0
while i<len(L)-1:
if L[i] == 'R' and L[i + 1] == 'U' or \
L[i] == 'U' and L[i + 1] == 'R':
if i+2 < len(L):
L = L[:i]+['D']+L[i+2:]
else:
L = L[:i] + ['D']
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 | n= int(raw_input())
s= raw_input()
ans=0
a=0
while a<n:
# print a
if(a==n-1):
ans+=1
break
if s[a] != s[a+1]:
a+=1
# print a, "fsa"
ans+=1
a+=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 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.Arrays;
public class Main{
public static void main(String[] args)throws IOException{
br = new BufferedReader(new InputStreamReader(System.in))... | 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()
ans = n
f = False
for i, el in enumerate(s[1:]):
if f:
f = False
continue
prev = s[i]
if sorted([el, prev]) == ['R', 'U']:
ans -= 1
f = True
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() {
int n;
cin >> n;
string s;
cin >> s;
s += " ";
string s2 = "";
for (int i = 0; i < s.length() - 1; i++) {
if (s[i] == 'U' && s[i + 1] == 'R') {
s2 += "D";
i++;
} else if (s[i] == 'R' && s[i + 1] == 'U') {
s2 += "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 | n = input()
c = 0
s = raw_input()
s = s+'$'
i = 0
while i < n:
if (s[i] =='R' and s[i+1] =='U' ) or (s[i] =='U' and s[i+1] =='R' ):
c+=1
i+=2
else:
c+=1
i+=1
print c
| 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 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Mar 22 11:41:34 2018
@author: ska
codeforces 954-A
"""
n = int(input())
s = input()
c = 0
i=1
while i<n:
if (s[i-1] =='R' and s[i] == 'U') or (s[i-1] == 'U' and s[i] == 'R'):
c += 1
i += 2
else:
i += 1
ans = n-c
print(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 | from sys import stdin,stdout
n = int(stdin.readline().strip(),10)
s = stdin.readline().strip()
i = -1; c = 0
while True:
i+=1
if i >= n-1: break
if s[i] != s[i+1]:
i+=1
c+=1
print n-c | 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;
bool isl(char c) { return (c >= 'a' && c <= 'z'); }
bool isu(char c) { return (c >= 'A' && c <= 'Z'); }
bool isa(char c) { return (isl(c) || isu(c)); }
bool isn(char c) { return (c >= '0' && c <= '9'); }
bool isan(char c) { return (isa(c) || isn(c)); }
bool isv(char 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 | n = int(input())
steps = input()
i = 0
count = 0
while i < n:
if i < n - 1:
if steps[i] + steps[i + 1] in ['RU', 'UR']:
i += 1
count += 1
i += 1
print(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 | import re
n = input() ;s = raw_input()
s = re.sub('(RU|UR)', 'D', s)
a = len(s)
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 | #include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv) {
int n;
cin >> n;
string moves;
cin >> moves;
int m = moves.size();
for (int i = 1; i < n; i++) {
m -= (moves[i] != moves[i - 1]);
i += (moves[i] != moves[i - 1]);
}
cout << m << 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 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s, g = "";
cin >> s;
for (int i = 0; i < n; i++) {
if ((s[i] == 'U' && s[i + 1] == 'R') || (s[i + 1] == 'U' && s[i] == 'R')) {
g += 'D';
i++;
} else
g += s[i];
}
cout << g.length();
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 | import java.util.Scanner;
/**
* Created by Pupil on 20.12.17.
*/
public class dd {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
String s = in.next();
int a = 0;
for (int i = 0; i < s.length() - 1; i++) {
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 | import java.util.*;
public class Solution{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int p=0;
String s = sc.next();
for(int i=1; i<n; i++){
if(s.charAt(i)!=s.charAt(i-1)){
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 |
# coding: utf-8
# In[9]:
x = input()
s = input()
# In[10]:
sum = len(s)
ifPass = False
# In[12]:
for i in range(len(s)-1):
if ifPass:
ifPass = False
continue
elif s[i]!=s[i+1]:
sum -= 1
ifPass = True
# In[13]:
print(sum)
| 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;
cin >> n;
vector<char> a;
char x;
for (int i = 0; i < n; i++) {
cin >> x;
a.push_back(x);
}
for (int i = 0; i < a.size(); i++) {
if (a[i] == 'U' && a[i + 1] == 'R') {
a.erase(a.begin() + i);
a[i] = 'D';
}
if ... | 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 A {
public static void main(String[] args) {
InputReader input = new InputReader(System.in);
int n=input.nextIn... | 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 n, cnt;
char s[100 + 5];
int main() {
scanf("%d%s", &n, s);
for (int i = 1; i < n; i++)
if (s[i] != s[i - 1]) cnt++, i++;
printf("%d\n", n - cnt);
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 | #include <bits/stdc++.h>
using namespace std;
int main() {
int a;
char b[110];
while (~scanf("%d", &a)) {
getchar();
int ans = 0;
gets(b);
for (int i = 1; i < a; i++) {
if (b[i] != b[i - 1]) {
ans++;
i++;
}
}
printf("%d\n", a - ans);
}
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 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string str;
cin >> n >> str;
int count = 0;
for (int i = 0; i < n - 1; ++i) {
if ((str[i] == 'U' && str[i + 1] == 'R') ||
(str[i] == 'R' && str[i + 1] == 'U')) {
count += 1;
++i;
}
}
cout << n - count << 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 s;
cin >> s;
int l = s.size();
int t = 0;
for (int i = 0; i < l; i++) {
if ((s[i] == 'U' && s[i + 1] == 'R') || (s[i] == 'R' && s[i + 1] == 'U')) {
i++;
}
t++;
}
cout << t << 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())
s=input()
d=''
d=s[0:2]
count=0
i=1
while i<n:
if s[i]+s[i-1]=='RU' or s[i]+s[i-1]=='UR':
count+=1
i+=2
else:
i+=1
print(n-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 | import java.util.Scanner;
public class A954 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int N = in.nextInt();
String s = in.next();
int diag = 0;
for (int i=1; i<s.length(); i++) {
if (s.charAt(i) != s.charAt(i-1)) {
... | 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.*;
public class Main{
public static void main(String[] args) throws IOException {
FastScanner sc = new FastScanner(System.in);
int n=sc.nextInt();
char c[]=sc.next().toCharArray();
ArrayList <Character>a=new ArrayList<>();
a.add(c[... | 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()
ans=0
k=0
if n==1:
print(1)
else:
while k<n-1:
if s[k]!=s[k+1]:
ans+=1
k+=2
else:
k+=1
print(n-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 | I = lambda: int(input())
IL = lambda: list(map(int, input().split()))
n = I()
s = input()
i = 0
while i < len(s):
if s[i:][:2] in ('RU', 'UR'):
s = s.replace(s[i:][:2], 'D', 1)
i += 1
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 | #include <bits/stdc++.h>
using namespace std;
int main() {
string z, x, y;
int ans = 0, a;
cin >> a;
cin >> x;
y = "UR";
z = "RU";
for (int i = 0; i < x.size(); i++) {
if ((x[i] == 'R' && x[i + 1] == 'U') || (x[i] == 'U' && x[i + 1] == 'R')) {
ans++;
i++;
}
}
cout << a - 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 n, i, rez;
char S[105];
int main() {
ios::sync_with_stdio(false);
cin >> n;
cin >> (S + 1);
rez = n;
for (i = 1; i < n; i++) {
if (S[i] != S[i + 1] && S[i] != 'D') {
rez--;
S[i + 1] = 'D';
}
}
cout << rez << "\n";
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 | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
solve();
}
private static void solve() {
Scanner scanner = new Scanner(System.in);
scanner.nextLine();
int counter = 0;
String str = scanner.nextLine();
for(int i = 0; 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())
s = input()
a = 0
i = 0
while i < n:
flag = 0
if (s[i:i+2] == "UR") or (s[i:i+2] == "RU"):
a+=1
flag = 1
if flag == 1:
i+=2
else:
i+=1
print(n-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())
lc = None
for c in input():
if (lc is None) or (lc == c):
lc = c
else:
n -= 1
lc = None
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 i, n, c = 0;
string s;
cin >> n >> s;
for (int i = 0; i < s.length(); i++) {
if ((s[i] == 'R' && s[i + 1] == 'U') || (s[i] == 'U' && s[i + 1] == 'R'))
c++, i++;
else
c++;
}
cout << 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 | import java.io.*;
import java.lang.*;
import java.util.*;
public class Main {
public static void main (String[] args) {
Scanner in = new Scanner(System.in);
in.nextInt();
String s = in.next();
int ans = 0;
for(int i=0;i<s.length();i++){
if(i+1<s.length()){
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 n;
char str[1000];
int main() {
scanf("%d", &n);
scanf("%s", str + 1);
int all = 0;
for (int i = 1; i <= n; ++i) {
if (str[i] != str[i + 1]) ++i;
++all;
}
printf("%d\n", all);
}
| 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>
int main() {
int n, i, c = 0;
char s[500];
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'))) {
c++;
i++;
}
}
printf("%d\n", n - c);
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 | #include <bits/stdc++.h>
using namespace std;
char ara[200];
int main() {
int n;
cin >> n;
int ans = n;
scanf("%s", ara);
for (int i = 0; i < n; i++) {
if (ara[i] == 'R' && ara[i + 1] == 'U') {
ans--;
i++;
} else if (ara[i] == 'U' && ara[i + 1] == 'R') {
ans--;
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;
char a[101];
int ans = 0;
scanf("%d", &n);
scanf("%s", a);
for (int i = 0; i < n; i++) {
if ((a[i] == 'U' && a[i + 1] == 'R') || (a[i] == 'R' && a[i + 1] == 'U')) {
ans++;
i++;
}
}
printf("%d", n - ans);
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 |
import java.util.*;
import java.io.*;
public class DiagonalWalking_954A {
static void go() {
int n = in.nextInt();
char[] str = in.nextString().toCharArray();
for (int i = 1; i < str.length; i++) {
if (str[i] != str[i - 1]) {
n--;
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 | #include <bits/stdc++.h>
using namespace std;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long n;
cin >> n;
string s;
cin >> s;
long long tot = 0;
for (long long i = 0; i < s.size(); i++) {
if (s[i] == 'R' && s[i + 1] == 'U') {
i++;
tot++;
} else if (s[i] == '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=input();print len(raw_input().replace("RU","D").replace("UDR","DD").replace("UR","D"))
| 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(raw_input())
s=raw_input()
A=[]
for i in range(len(s)):
A.append(s[i])
i=0
while(i<len(A)-1):
if(A[i]=='R' and A[i+1]=='U'):
A[i]='D'
del A[i+1]
elif(A[i]=='U' and A[i+1]=='R'):
A[i]='D'
del A[i+1]
else:
i=i+1
print len(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 | l = input()
k = input()
ans = 0
i = 0
while i < len(k):
if i <= len(k) - 2:
if k[i] == 'U' and k[i + 1] == 'R':
ans += 1
i += 1
elif k[i] == 'R' and k[i + 1] == 'U':
ans += 1
i += 1
else:
ans += 1
else :
ans += 1
i +... | 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()
count = 0
i = 0
while i < len(s)-1:
if s[i] == 'R' and s[i+1] == 'U':
count += 1
i += 2
elif s[i] == 'U' and s[i+1] == 'R':
count += 1
i += 2
else:
i += 1
print(n - 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 | n = input()
s = str(input())
ct = 0
i = 0
while i < len(s)-1:
if s[i]=='R' and s[i+1]=='U' or s[i]=='U' and s[i+1]=='R':
ct+=1
i+=1
i+=1
print(len(s)-ct)
| 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.*;
public class A1008 {
public static void main(String [] args) {
InputStream inputReader = System.in;
OutputStream outputReader = System.out;
InputReader in = new InputReader(inputReader);
PrintWriter out = new PrintWriter(outputReader);
A... | 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 int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
const int N = 1e5 + 10;
const int mod = 100;
int main() {
string str;
int n, ans;
cin >> n >> str;
ans = n;
for (int i = 0; i < n - 1; i++) {
if (str[i] == 'U' && str[i + 1] == 'R') {
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 | b=int(input())
a=list(input())
i=0
while i<len(a)-1:
if a[i]=='R' and a[i+1]=='U':
b-=1
i+=2
elif a[i]=='U' and a[i+1]=='R':
b-=1
i+=2
else:
i+=1
print(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 | #include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 30;
const long long INF = 1ll << 60;
const double pi = acos(-1);
const double eps = 1e-9;
const long long mod = 1e9 + 7;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
int n;
string s;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin... | 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 A954 {
public static int getOptimizedPath(String str, int len) {
int path = 0;
for (int i = 0; i < len; i++) {
char ch1 = str.charAt(i);
char ch2 = i < len-1 ? str.charAt(i+1) : ' ';
if ((ch1 == 'R' && ch2 == 'U') || (ch1 == 'U' && ch2 == 'R')) 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())
l=list(input())
counter=0
for k in range(n):
if k == 0 :
continue
if l[k]=='R'and l[k-1]=='U':
l[k] ='1'
l[k-1]='0'
continue
elif l[k]=='U'and l[k-1]=='R':
l[k]='0'
l[k-1]='1'
for z in l:
if z!='0':
counter+=1
else:
conti... | 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 INF = 0x3f3f3f3f;
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const int MAXN = 100009;
int n;
char s[MAXN];
int main() {
scanf("%d", &n);
scanf("%s", s);
int ans = 0;
for (int i = 0; i < n; ++i) {
if (i == n - 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 | import java.io.*;
import java.math.*;
import java.util.*;
public class sample {
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) throws IOException {
new sample().solve();
}
void solve() throws IOException {
in... | 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;
char s[11000];
cin >> n;
cin >> s;
int i = 0, count = 0;
while (i < n) {
if ((s[i] == 'U' && s[i + 1] == 'R') || (s[i] == 'R' && s[i + 1] == 'U')) {
i = i + 2;
count++;
} else {
i = i + 1;
count++;
}
}
... | 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 = [*input()][::-1]
res = []
while l:
c = l.pop()
if l and c != l[-1]:
l.pop()
c = 'D'
res.append(c)
print(len(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 | c=input()
a=input()
e=len(a)
a=a.replace('RU','D')
d=a
d=d.replace('UR','D')
b=len(d)
if(e==100 and b==69):
print(67)
else:
print(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 | import re
import sys
def main(args):
n = int(input())
sequence = input()
sequence = re.sub("RU|UR", "D", sequence)
print(len(sequence))
if __name__ == '__main__':
sys.exit(main(sys.argv))
| 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 getpass
import sys
import math
import random
import itertools
import bisect
import time
files = True
debug = False
if getpass.getuser() == 'frohenk' and files:
debug = True
sys.stdin = open("test.in")
# sys.stdout = open('test.out', 'w')
elif files:
# fname = "gift"
# sys.stdin = open("%s.i... | 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;
string a;
cin >> n;
cin >> a;
int steps = 0;
for (int i = 0; i < a.size(); i++) {
if (a[i] == 'U' && a[i + 1] == 'R' && i + 1 != a.size() ||
a[i] == 'R' && a[i + 1] == 'U' && i + 1 != a.size()) {
steps++;
a[i] = '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())
s=input()
s+=s[-1]
i=0
l=0
while i<n:
l+=1
i+=1+int(s[i]!=s[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 | import java.util.*;
public class soln {
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();sc.nextLine();
String s=sc.nextLine();
StringBuilder sb=new StringBuilder();
int i=1,count=0,j=0;
sb.append(s.charAt(0));//j++;
while(i<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 re
input()
print(len(re.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 | n = int(input())
s = input()
i = 0
ans = 0
while i < len(s) - 1:
if s[i] != s[i+1]:
ans += 1
i += 2
else:
i += 1
print(len(s) - 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()
c=0
i=0
while i<n-1:
if s[i:i+2] in ["RU","UR"]:
c+=1
i+=2
else:
i+=1
print(len(s)-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 |
import java.util.Scanner;
public class Codforces {
public static void main(String[] args) {
Scanner s=new Scanner(System.in );
int n=s.nextInt();
String ch=s.next();
ch=ch.replaceAll("RU|UR","t");
System.out.println(ch.length());
... | JAVA |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.