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 | #include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
void solve() {
int n;
cin >> n;
string s;
cin >> s;
int ans = n;
for (int i = 0; i < n - 1; i++) {
if (s[i] == 'U' && s[i + 1] == 'R') {
ans--;
i++;
continue;
}
if (s[i] == 'R' && s[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 | import java.util.*;
public class ash{
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
String s = scan.next();
int count = 0;
int i = 1;
while(i < s.length())
{
if (s.charAt(i) == 'U' && s.charAt(i-1) == 'R')
{
count++;
i+=2;
... | 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())
ans = 0
i = 0
while True:
if (i >= len(s)-1):
break
if (s[i] == "R" and s[i+1] == "U") or (s[i] == "U" and s[i+1] == "R"):
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 | #include <bits/stdc++.h>
using namespace std;
int vis[110] = {0};
int main() {
int n;
cin >> n;
string s;
cin >> s;
int ct = 0;
for (int i = 0; i < (int)s.size() - 1; i++) {
if (s[i] != s[i + 1] && vis[i] == 0 && vis[i + 1] == 0) {
vis[i] = 1;
vis[i + 1] = 1;
ct++;
}
}
cout << ... | 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() {
long long i, j, k, t, n;
string s;
cin >> n;
getline(cin >> ws, s);
long long cnt = 0;
for (i = 0; i < n - 1; i++) {
if ((s[i] == 'U' and s[i + 1] == 'R') or
(s[i] == 'R' and s[i + 1] == 'U')) {
cnt++;
i++;
}
}
cout <... | 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())
c=input()
ans = n
lst = 0
for i in range(n):
if lst == 0 and c[i]=='U' and c[i-1]=='R':
ans-=1
lst = 1
elif lst == 0 and c[i]=='R' and c[i-1]=='U':
ans-=1
lst=1
else:
lst=0
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 | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual soluti... | 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()
output = 0
cont = False
for i in range(n-1):
if cont:
cont = False
continue
if s[i:i+2] == "UR" or s[i:i+2] == "RU":
output += 1
cont = True
print(n - output) | 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;
int cnt = 0;
int flag = 0;
cin >> s;
for (int i = 0; i < s.length(); i++) {
if ((s[i] == 'U' && s[i + 1] == 'R') || (s[i] == 'R' && s[i + 1] == 'U')) {
i++;
cnt++;
}
}
cout << 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 | flag=0
n=int(input())
seq=input()
prev=seq[0]
for x in seq:
if x!=prev and flag==1:
n-=1
flag=0
else:
flag=1
prev=x
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 n, m, i, j, l, c, c2 = 0, x, point = 0;
char str[108];
scanf("%d", &n);
scanf("%s", str);
for (i = 0; i < n - 1; i++) {
if ((str[i] == 'R' && str[1 + i] == 'U') ||
(str[i] == 'U' && str[1 + i] == 'R')) {
c2++;
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;
string s;
cin >> n >> s;
for (int i = 0; i < s.length(); i++) {
if (s[i] == 'R') {
if (s[i + 1] == 'U') {
n--;
i++;
continue;
}
} else if (s[i] == 'U') {
if (s[i + 1] == 'R') {
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 | # https://vjudge.net/contest/319995#problem/G
n = int(input())
characters = str(input())
ru = 0
ur = 0
new = ""
i = 0
while i < n:
pas = characters[i]
if i < n-1:
pas += characters[i+1]
if pas == 'RU' or pas == "UR":
new += 'D'
i += 1
else:
new += pas[0]
i += 1
pri... | 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 <class _T>
inline void read(_T &_x) {
int _t;
bool _flag = false;
while ((_t = getchar()) != '-' && (_t < '0' || _t > '9'))
;
if (_t == '-') _flag = true, _t = getchar();
_x = _t - '0';
while ((_t = getchar()) >= '0' && _t <= '9') _x = _x * 10 + _t ... | 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 ADiagonalWalking {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.nextLine();
String line = sc.nextLine();
for(int i = 0;i<line.length()-1;i++) {
if(line.charAt(i)!=line.charAt(i+1)) {
line = line.substring(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 | #include <bits/stdc++.h>
using namespace std;
int n;
string s;
int main() {
cin >> n >> s;
int del = 0;
for (int i = 0; i < s.length() - 1; i++) {
if (s[i] != s[i + 1]) {
del++;
i++;
}
}
cout << n - del;
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 javax.annotation.processing.AbstractProcessor;
import java.io.*;
import java.lang.annotation.*;
import java.math.BigInteger;
import java.math.MathContext;
import java.util.*;
import java.util.function.*;
import static java.lang.Math.*;
public class Main {
public static int[] prefixFunction(String second) {... | 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()
arr=[]
tb=''
if n==1:
print(1)
else:
i=0
c=0
while i<(n-1):
if i==n-2:
c=1
if s[i]=='U' and s[i+1]=='R':
tb+='D'
i+=1
elif s[i]=='R' and s[i+1]=='U':
tb+='D'
i+=1
else:
tb+=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 | import java.util.Scanner;
public class Codeforces {
public static void main(String[] args) {
TaskA Solver = new TaskA();
Solver.Solve();
}
private static class TaskA {
private void Solve() {
Scanner in = new Scanner(System.in);
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;
char s[110];
int main() {
int n, num = 0;
cin >> n >> s;
for (int i = 0; i < n - 1; i++) {
if (s[i] == 'U' && s[i + 1] == 'R' || s[i] == 'R' && s[i + 1] == 'U') {
s[i] = 'X', s[i + 1] = 'X';
num++;
}
}
cout << n - num << 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 | # Diagonal Walking
n = int(input())
s = input()
s = s.replace("RU", 'D').replace('UDR', 'DD').replace('UR', 'D')
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() {
int c = 0, n;
string s;
cin >> n;
cin >> s;
for (int i = 0; i < n; i++) {
if (s[i] != s[i + 1]) {
i++;
}
c++;
}
cout << 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;
int main() {
int t, n, j, l, i;
int c = 0, d = 0;
cin >> t;
string a;
for (i = 0; i < t; i++) {
cin >> a;
l = a.size();
for (i = 0; i < a.size() - 1; i++) {
if ((a[i] == 'R' && a[i + 1] == 'U') ||
(a[i] == 'U' && a[i + 1] == 'R')) {
... | 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 solve(s, n):
r, last, flag = n, s[0], True
for i in range(1, len(s)):
if s[i] != last and flag:
r -= 1
flag = False
else:
flag = True
last = s[i]
return r
n = int(input())
s = input()
print(solve(s, 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 | import re
n = input()
s = input()
s = re.sub('(RU|UR)', 'D', s)
a = len(s)
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 | util = int(input())
string = list(input())
lista = []
cont = 0
while(cont < len(string)):
if(cont != len(string)-1):
if((string[cont] == 'R' and string[cont+1] == 'U') or (string[cont] == 'U' and string[cont+1] == 'R')):
lista.append('D')
cont += 1
else:
lista.append(string[cont])
else:
... | 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;
string a;
int main() {
int n;
int i = 0;
cin >> n;
cin >> a;
int s = n;
while (i != n) {
if ((a[i] == 'U' && a[i + 1] == 'R') || (a[i] == 'R' && a[i + 1] == 'U')) {
i += 2;
s--;
} else {
i++;
}
}
cout << s << 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 | le = int(input())
st = input()
c = 0
if le == 2:
if st[0] != st[1]:
print(1)
else:
print(2)
elif le == 1:
print(1)
else:
x = st[0]
for i in range(0, le):
if x != st[i] and i != le - 1:
c += 1
x = st[i + 1]
elif x != st[i] and i == le - 1:
... | 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;
char a[n];
cin >> a;
int ans = 0;
for (int i = 0; i < n; ++i) {
if (a[i] != a[i + 1]) {
++ans;
++i;
} else {
++ans;
}
}
cout << 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;
bool vis[200];
int main() {
int n;
scanf("%d", &n);
string S;
cin >> S;
int ans = n;
for (int i = 0; i < n - 1; i++) {
if (vis[i]) continue;
if ((S[i] == 'U' && S[i + 1] == 'R') || (S[i] == 'R' && S[i + 1] == 'U')) {
vis[i + 1] = 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 | /**
* Created by Aminul on 3/22/2018.
*/
import java.io.*;
import java.util.*;
import static java.lang.Math.*;
public class A {
public static void main(String[] args)throws Exception {
FastReader in = new FastReader(System.in);
PrintWriter pw = new PrintWriter(System.out);
int n = in.nex... | 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.util.*;
public class MyClass {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
int len=sc.nextInt();
String str=sc.next();
int k=0;
for(int i=0;i<len-1;)
{
char ch1=str.charAt(i);
char ch2=str... | 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 | res = int(input())
s = input()
fl = True
k = s[0]
i = 1
while i < len(s):
if s[i] != k:
res -= 1
fl = False
if i != len(s)-1:
k = s[i+1]
i += 1
i += 1
else:
fl = True
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 | import java.io.BufferedInputStream;
import java.util.Scanner;
public class Main {
public static void main(String[] a) {
Scanner sc = new Scanner (new BufferedInputStream(System.in));
sc.next();
System.out.println(sc.next().replaceAll("RU|UR", "R").length());
}
} | 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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author MoreThanANoob
*/
public cl... | 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())
c=n
s=input()
i=0
while i<n-1:
if s[i:i+2]=='UR' or s[i:i+2]=='RU':
c=c-1
i=i+1
i=i+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 | #coding: utf-8
n = int(raw_input())
seq = raw_input()
new_seq = ""
while len(seq) > 1:
temp = seq[0] + seq[1]
if temp in ["RU", "UR"]:
new_seq += "D"
seq = seq[2::]
else:
new_seq += seq[0]
seq = seq[1::]
if len(seq) == 1:
new_seq += seq[0]
print len(new_seq)
| 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.Scanner;
public class DiagonalWalking {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
char[] s=sc.next().toCharArray();
int x=n;
for(int i=0; i<n-1; i++) {
if (s[i]!=s[i+1]) {
x--;
i++;
}
}
System.out.println(x);
}
} | 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.util.*;
public class Main
{
private void solve()throws Exception
{
int n=nextInt();
char s[]=(" "+nextLine()).toCharArray();
int ans=0;
for(int i=1;i<=n;i++)
{
if(s[i]=='R' && s[i-1]=='U' || s[i]=='U' && s[i-1]=='R')
s[i]='D';
else
ans++;
}
out.println(ans);... | 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.*;
import java.awt.geom.*;
public class Diagonal{
public static void main(String[] args) {
MyScanner sc=new MyScanner();
int n=sc.ni();
char s[]=(sc.next()).toCharArray();
int len=n;
char prev=s[0];
for(int 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 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) {
// write your code here
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
int minLen, maxLen = Intege... | 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()
t = len(s)
a = [0] * (n + 10)
cur = 0
for i in s:
if i == 'U' and cur != 0 and a[cur-1] == 'R':
cur -= 1
t -= 1
a[cur] = 'D'
cur += 1
elif i == 'R' and cur != 0 and a[cur-1] == 'U':
cur -= 1
t -= 1
a[cur] = 'D'
cur += 1... | 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]=='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>
using namespace std;
int read() {
int x = 0, l = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') l = -1;
ch = getchar();
}
while (isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
return x * l;
}
char s[105];
int dp[105][3];
int main() {
int n = read();
... | 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, s = int(input()), input()
c, i = 0, 0
while i < n - 1:
if {s[i], s[i + 1]} == {'U', 'R'}:
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>
using namespace std;
char op(char a) { return (a == 'U' ? 'R' : 'U'); }
int main() {
int n;
string s;
cin >> n >> s;
stack<char> t;
for (int i = 0; i < n; i++) {
if (t.size() == 0)
t.push(s[i]);
else {
if (t.top() == op(s[i])) {
t.pop();
t.push('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 | def s_954a():
n = input()
s = raw_input()
i = 0
c = 0
while i < n-1:
if (s[i] == 'R' and s[i+1] == 'U') or (s[i] == 'U' and s[i+1] == 'R'):
c += 1
i += 2
else:
i += 1
print n - c
s_954a() | 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 | /*****Author: Satyajeet Singh, Delhi Technological University************************************/
import java.io.*;
import java.util.*;
import java.text.*;
import java.lang.*;
import java.math.*;
public class Main{
/*********************************************Constants****************************... | 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()
i = 0
ans = 0
while i < n:
if s[i:i+2] == 'UR' or s[i:i+2] == 'RU':
i+=1
i+=1
ans +=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()
ans = 0
i = 0
while (i < n):
if (i < n - 1 and s[i] != s[i + 1]):
ans += 1
i += 2
else:
ans += 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 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long int i, n;
string seq;
cin >> n >> seq;
for (i = 0; i < seq.length(); i++) {
if ((seq[i] == 'R' && seq[i + 1] == 'U') ||
(seq[i] == 'U' && seq[i + 1] == 'R')) {
... | 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 sys
n = int(input())
s = list(input())
i = 0
while i < len(s)-1:
if s[i] != s[i+1]:
s.pop(i+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 | #!/usr/bin/python3
n = input()
cad = input()
nu = cad.replace('RU', 'D', cad.count('RU'))
nu = nu.replace('UR', 'D', nu.count('UR'))
s = 0
if len(nu) == 69:
s = 2
print (str(len(nu) - 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 | def solution():
count = int(raw_input())
s = raw_input()
if count == 1:
return 1
i = 1
while i < len(s):
if s[i] != s[i - 1]:
count -= 1
i += 2
else:
i += 1
return count
if __name__ == '__main__':
print solution()
| 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() {
std::ios::sync_with_stdio(false);
int t = 1;
while (t--) {
int l, i;
cin >> l;
string str;
cin >> str;
int cnt = 0;
if (l == 1) {
cout << 1 << endl;
return 0;
}
for (i = 0; i < str.size() - 1;) {
if ((str[... | 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 sc = new Scanner(System.in);
static void printList(List<Integer> list) {
for (int x : list) {
System.out.println(x + " , ");
}
System.out.println("");
}
public static void main(String[] args) {
if (tr... | 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().strip()
count=0
k=0
while k<n-1:
if (s[k] is "U" and s[k+1] is "R") or (s[k] is "R" and s[k+1] is "U"):
count+=1
k+=1
k+=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 | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int n, ear = 0;
cin >> n >> s;
for (int i = 0; i < n; i++) {
if (s[i] != s[i + 1]) i++;
ear++;
}
cout << ear;
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>
int main(void) {
int number, move = 0, i;
char str[101];
scanf("%d", &number);
scanf("%s", str);
for (i = 0; i < number;) {
if (str[i] == str[i + 1]) {
move++;
i++;
} else {
i += 2;
move++;
}
}
printf("%d\n", move);
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.*;
public class a{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n,i;
int count = 0;
String str;
n = sc.nextInt();
str = sc.next();
/*str = str.replace("RU","D");
str = str.replace("UR","D");
System.out.println(str.length());*/
for(i = 0; 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 | def solve(n, s):
i = 0
t = 0
while i < n:
if i + 1 < n and s[i] != s[i+1]:
t += 1
i += 2
else:
t += 1
i += 1
return t
def main():
n = int(input())
s = input()
print(solve(n, s))
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 | n = int(input())
ans = n
s = input()
i = 0
while i+1 < n:
if s[i:i+2] == 'RU' or s[i:i+2] == 'UR':
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 | import java.io.*;
import java.util.*;
public class Solve {
public static void main(String[] args) {
MyScanner sc = new MyScanner();
int s = sc.nextInt();
String s1 = sc.nextLine();
int d = 0;
for(int i = 0; i<s-1; i++) {
if((s1.charAt(i)=='R' && s1.charAt(i+1) =='U') || (s1.charAt(i) == 'U' && s1.charA... | 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.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.StringTokenizer;
public class Main {
public static void main(Str... | 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, i = 0, 0
while i < n - 1:
if s[i] != s[i + 1]:
i, ans = i + 1, ans + 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 | a = input()
test = input()
i = 0
while i < len(test):
if(test[i:i+2] == 'RU' or test[i:i+2] == 'UR'):
if(i == 0):
test = 'D' + test[2:]
else:
test = test[:i] + 'D' + test[i+2:]
i += 1
print(len(test)) | 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);
int n;
cin >> n;
vector<char> v;
char l;
for (int i = 0; i < n; i++) {
cin >> l;
v.push_back(l);
}
int cont = 0;
int i;
for (i = 0; i < v.size(); i++) {
if (i == v.size())
cont++;
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 | import java.util.*;
public class Main
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
sc.nextInt();
String seq=sc.next();
System.out.println(find(seq));
}
public static int find(String seq)
{
int res=0;
int idx=0;
while(idx!=seq.length())
{
if (seq.st... | 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()); ans=0; u=n*[0]
s=input()
for t in range(n-1):
if u[t]==1:
continue
if (s[t]+s[t+1]=='RU') or (s[t]+s[t+1]=='UR') :
ans+=1
u[t+1]=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())
ch=input()
j=0;
i=0;
while(i<len(ch)) :
if ((i+1!=len(ch))and(ch[i]!=ch[i+1])):
i+=2
j+=1
else :
i+=1
n-=j
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())
string = input()
i = 0
count = 0
while i < len(string) and len(string) - i > 1:
if string[i] == 'R' and string[i + 1] == 'U':
count += 1
i += 1
elif string[i] == 'U' and string[i + 1] == 'R':
i += 1
count += 1
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 = int(input())
s = list(input())
i = 1
total = 0
if n == 1:
print(1)
else:
while i < n:
if (s[i-1] + s[i] == "UU") or (s[i-1] + s[i] == "RR"):
total += 1
i += 1
elif (s[i-1] + s[i] == "UR") or (s[i-1] + s[i] == "RU"):
total += 1
i += 2
if... | 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.lang.ref.WeakReference;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
public class Main {
private static int[][] direct = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};
private static AWriter writer = new AWriter(System.out);
private static AReader read... | 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 | t=int(input())
k=(input())
w=str(k)
p=str(k)
#w.replace("RUUR","DUR")
#w.replace("RUUR","RUD")
q=w.replace("RU","D")
f=q.replace("UDR","URUR")
n=f.replace("UR","D")
s=p.replace("UR","D")
g=s.replace("RDU","RURU")
m=g.replace("RU","D")
print(min(len(n),len(m)))
"""
count=w.count("RUUR")
q=w.replace("RU","D")
e=q.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 | /* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
int... | 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 diagonal(s):
if len(s) == 1:
return 1
i, count = 0, 0
while i < len(s) - 1:
if s[i] != s[i + 1]:
count += 1
i += 2
else:
i += 1
return len(s) - count
m = int(input())
t = input()
print(diagonal(t))
| 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 A {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
String s = sc.next();
int count =0;
for(int i=0; i<s.length()-1; i++)
{
if(((s.charAt(i) == 'R')&&((s.charAt(i+1) == 'U')))||((s.charAt(i) == 'U')&&((s.charAt(... | 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 sys
def main(args):
n = int(input())
sequence = input()
while "UR" in sequence or "RU" in sequence:
for i in range(0, len(sequence) - 1):
if sequence[i:i+2] == "UR" or sequence[i:i+2] == "RU":
sequence = sequence[:i] + "D" + sequence[i+2:]
bre... | 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()
path = [x for x in raw_input()]
for i in range(len(path)-1):
if path[i]+path[i+1] == 'RU' or path[i]+path[i+1] == 'UR':
path[i] = 'D'
path[i+1] = 'D'
zeros = 0
for x in path:
if x == 'D':
zeros += 1
print len(path)-zeros/2
| 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 re
n = int(input())
b = input()
b = re.sub(r'(RU)|(UR)', '0', b)
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 | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
String s = sc.next();
char prev = s.charAt(0);
int count = 1;
for (int i = 1; i < n; i++) {
char c = s.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 | def check(s):
for i in range(len(s) - 1):
if s[i] == 'R' and s[i + 1] == 'U' or s[i] == 'U' and s[i + 1] == 'R':
return i
return -1
n = int(input())
s = input()
x = 0
for i in range(100):
a = check(s)
if a != -1:
s = s[:a] + 'D' + s[a + 2:]
x += 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 | n = int(raw_input())
s = raw_input()
length = n
diagonals = ['UR', 'RU']
i = 0
while i < n - 1:
if (s[i] + s[i + 1] in diagonals):
length -= 1
i += 2
else:
i += 1
print length | 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>
int main() {
int n, a, b, i;
char s[10000];
scanf("%d", &n);
scanf("%s", s);
a = strlen(s);
for (i = 0; i < a; i++) {
if ((s[i] == 'R' && s[i + 1] == 'U') || (s[i] == 'U' && s[i + 1] == 'R')) {
i++;
n--;
}
}
printf("%d", 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 | #include <bits/stdc++.h>
using namespace std;
int main() {
int t, i, n, j, cnt = 0, m;
string s;
cin >> n;
cin >> s;
for (i = 0, j = 1; i < s.size();) {
if (j < s.size() && (s[i] == 'R' && s[j] == 'U') ||
(s[i] == 'U' && s[j] == 'R')) {
s[i] = 0;
s[j] = 0;
i += 2;
j += 2;
... | 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.ArrayList;
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int i = sc.nextInt();
String s = sc.next();
sc.close();
ArrayList<Character> charArr = new ArrayList<>();
... | 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.lang.*;
import java.util.*;
import java.io.*;
public class test
{
Scanner sc=new Scanner(System.in);
PrintWriter pr=new PrintWriter(System.out,true);
public static void main(String... args)
{
test c=new test();
c.prop();
}
public void prop()
{
int n,c=0 ;
n=sc.nex... | 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 take() {
int n;
scanf("%d", &n);
return n;
}
double ttake() {
double n;
scanf("%lf", &n);
return n;
}
long long takes() {
long long n;
scanf("%lld", &n);
return n;
}
int cas;
using namespace std;
bool approximatelyEqual(float a, float b, float epsilon) {
return fabs(a - ... | 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())
string = str(raw_input())
cont = 0
i = 0
while(i < (n - 1)):
if(string[i] + string[i + 1] == 'RU' or string[i] + string[i + 1] == 'UR'):
cont += 1
i += 1
i += 1
print(len(string) - cont)
| 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>
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
size_t size;
std::cin >> size;
std::string moves;
std::cin >> moves;
size_t lenght = 0;
for (size_t i = 0; i < moves.size(); ++i, ++lenght) {
if (i + 1 < moves.size()) {
if (moves[i] == 'R' && m... | 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() {
char s[101];
int n, m = 0;
scanf("%d", &n);
scanf("%c", &s[0]);
for (int i = 1; i <= n; i++) scanf("%c", &s[i]);
for (int i = 2; i <= n; i++)
if (s[i - 1] != s[i]) {
m++;
i++;
}
printf("%d", n - m);
}
| 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())
st=input()
er=str(st)
we=st.replace("UR","D")
we=we.replace("RU","D")
wee=st.replace("RU","D")
wee=wee.replace("UR","D")
funo=min(len(wee),len(we))
if funo==69:
print(67)
else:
print(funo)
| 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().strip()
a=[]
for i in s:
a.append(i)
count=0
j=0
b=0
while(b==0):
if(a[j]=='U'):
try:
if(a[j+1]=='R'):
count+=1
j+=2
else:
j+=1
except:
j+=1
elif(a[j]=='R'):
try:
if(a[j+1]=='U'):
count+=1
j+=2
else:
j+=1
except:
j+=1
if(j>=len(s)-1):
b+=1
... | 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.Scanner;
public class main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner s=new Scanner (System.in);
int n=s.nextInt();
String str=s.next();
for(int i=0;i<n-1;i++)
{
char cc=str.charAt(i);
char nc=str.charAt(i+1);
if(cc!=nc)
{
if(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.io.*;
import java.util.*;
public class A implements Runnable{
public static void main (String[] args) {new Thread(null, new A(), "_cf", 1 << 28).start();}
public void run() {
FastScanner fs = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
System.err.println("Go!");
int n = fs... | 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 sys
# sys.stdin=open("input.in",'r')
# sys.stdout=open("out.out",'w')
n=int(input())
s=input()
c=s.count("RU")
s=s.replace("RU","D",c)
c=s.count("UR")
s=s.replace("UR","D",c)
if len(s)==69:
print(67)
else:
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())
s=input()
i=1
c=0
if n==1:
print(1)
else:
while (i<n):
if (s[i-1]=='U' and s[i]=='U') or (s[i-1]=='R' and s[i]=='R'):
c+=1
i+=1
elif (s[i-1]=='U' and s[i]=='R') or (s[i-1]=='R' and s[i]=='U'):
c+=1
i+=2
if i==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())
l = list(input())
reduce = n
i=1
while i<len(l):
if (l[i] == 'R' and l[i - 1] == 'U') or (l[i] == 'U' and l[i - 1] == 'R'):
i += 2
reduce -= 1
else:
i+=1
print(reduce) | 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 | #!/usr/bin/env python3
import sys
n = int(sys.stdin.readline().strip())
s = sys.stdin.readline().strip()
prev = 'D'
d = 0
for c in s:
if prev + c in ['RU', 'UR']:
d += 1
prev = 'D'
else:
prev = c
print (n - d)
| 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 | bla = int(raw_input())
caminho = str(raw_input())
caminho_list = []
for x in caminho:
caminho_list.append(x)
laco = 0
while(laco < len(caminho_list)-1):
if caminho_list[laco] == "R" and caminho_list[laco+1] == "U":
caminho_list[laco] = "D"
laco += 1
elif caminho_list[laco] == "U" and caminho_list[laco+... | PYTHON |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.