prompt string | response string |
|---|---|
Problem: Suppose you have two polynomials <image> and <image>. Then polynomial <image> can be uniquely represented in the following way:
<image>
This can be done using [long division](https://en.wikipedia.org/wiki/Polynomial_long_division). Here, <image> denotes the degree of polynomial P(x). <image> is called the re... | #include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
if (n == 1) {
cout << "1\n0 1\n0\n1";
return 0;
}
vector<long long> p1, p2;
p1.push_back(1);
p1.push_back(0);
p2.push_back(1);
for (long long i = 1; i < n; i++) {
vector<long long> temp = p1;
p1.push_back... |
Problem: Suppose you have two polynomials <image> and <image>. Then polynomial <image> can be uniquely represented in the following way:
<image>
This can be done using [long division](https://en.wikipedia.org/wiki/Polynomial_long_division). Here, <image> denotes the degree of polynomial P(x). <image> is called the re... | #include <bits/stdc++.h>
using namespace std;
vector<int> sum(vector<int> a, vector<int> b) {
bool f = true;
vector<int> v(max(a.size(), b.size()));
for (int i = 0; i < v.size(); i++) {
if (i < a.size()) v[i] += a[i];
if (i < b.size()) v[i] += b[i];
if (abs(v[i]) > 1) f = false;
}
if (f) return v;... |
Problem: Suppose you have two polynomials <image> and <image>. Then polynomial <image> can be uniquely represented in the following way:
<image>
This can be done using [long division](https://en.wikipedia.org/wiki/Polynomial_long_division). Here, <image> denotes the degree of polynomial P(x). <image> is called the re... | #include <bits/stdc++.h>
using namespace std;
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typenam... |
Problem: Suppose you have two polynomials <image> and <image>. Then polynomial <image> can be uniquely represented in the following way:
<image>
This can be done using [long division](https://en.wikipedia.org/wiki/Polynomial_long_division). Here, <image> denotes the degree of polynomial P(x). <image> is called the re... | #include <bits/stdc++.h>
using namespace std;
template <typename t>
void mi(t& a, const t& b) {
a = min(a, b);
}
template <typename t>
void ma(t& a, const t& b) {
a = max(a, b);
}
constexpr int si = 1024 * 1024, si_log = 10 + 10,
mod = static_cast<int>(1e9) + 7, partition_size = 400;
template <typenam... |
Problem: Suppose you have two polynomials <image> and <image>. Then polynomial <image> can be uniquely represented in the following way:
<image>
This can be done using [long division](https://en.wikipedia.org/wiki/Polynomial_long_division). Here, <image> denotes the degree of polynomial P(x). <image> is called the re... | #include <bits/stdc++.h>
using namespace std;
vector<int> f(vector<int> &a) {
vector<int> ans;
ans.resize(a.size() + 1);
for (int i = 1; i < (int)ans.size(); i++) ans[i] = a[i - 1];
return ans;
}
void add(vector<int> &a, vector<int> b) {
for (int i = 0; i < (int)b.size(); i++) {
if (i == (int)a.size()) a.... |
Problem: Suppose you have two polynomials <image> and <image>. Then polynomial <image> can be uniquely represented in the following way:
<image>
This can be done using [long division](https://en.wikipedia.org/wiki/Polynomial_long_division). Here, <image> denotes the degree of polynomial P(x). <image> is called the re... | #include <bits/stdc++.h>
using namespace std;
vector<int> g[222];
vector<int> get(int n, vector<int> &a, vector<int> &b) {
vector<int> res(n, 0);
for (int i = 1; i < n; i++) res[i] = a[i - 1];
bool f = 1;
for (int i = 0; i < (int)(b.size()); i++) {
if (res[i] + b[i] > 1 || res[i] + b[i] < -1) {
f = 0;... |
Problem: Suppose you have two polynomials <image> and <image>. Then polynomial <image> can be uniquely represented in the following way:
<image>
This can be done using [long division](https://en.wikipedia.org/wiki/Polynomial_long_division). Here, <image> denotes the degree of polynomial P(x). <image> is called the re... | #include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7;
bool debug = 1;
const int N = 1e5 + 10;
vector<int> num = {0, 1}, divd = {1}, vez = {0, 1};
vector<int> mult(vector<int> a, vector<int> b) {
if (a.size() < b.size()) swap(a, b);
vector<int> ans(a.size() + b.size() - 1);
for (int ia = 0; ia < a... |
Problem: Suppose you have two polynomials <image> and <image>. Then polynomial <image> can be uniquely represented in the following way:
<image>
This can be done using [long division](https://en.wikipedia.org/wiki/Polynomial_long_division). Here, <image> denotes the degree of polynomial P(x). <image> is called the re... | #include <bits/stdc++.h>
using namespace std;
int main() {
const int MAXN = 150 + 7;
int p[MAXN][MAXN];
for (int i = 0; i < MAXN; ++i) {
for (int j = 0; j < MAXN; ++j) p[i][j] = 0;
}
p[0][0] = 1;
p[1][1] = 1;
int n;
cin >> n;
for (int i = 2; i <= n; ++i) {
for (int j = 0; j <= i - 2; ++j) p[i]... |
Problem: Suppose you have two polynomials <image> and <image>. Then polynomial <image> can be uniquely represented in the following way:
<image>
This can be done using [long division](https://en.wikipedia.org/wiki/Polynomial_long_division). Here, <image> denotes the degree of polynomial P(x). <image> is called the re... | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
/**
* @author Don Li
*/
public class GCDPolynomials {
int N = 155;
int[] a = new int[N], b = new int[N];
void solve... |
Problem: Suppose you have two polynomials <image> and <image>. Then polynomial <image> can be uniquely represented in the following way:
<image>
This can be done using [long division](https://en.wikipedia.org/wiki/Polynomial_long_division). Here, <image> denotes the degree of polynomial P(x). <image> is called the re... | #include <bits/stdc++.h>
using namespace std;
const int MAX = 1e3 + 1;
int a[MAX], b[MAX], c[MAX];
int main() {
ios::sync_with_stdio(0);
int n;
cin >> n;
a[1] = 1;
b[0] = 1;
for (int i = 1; i < n; ++i) {
for (int j = i; j >= 0; --j) {
c[j] = a[j];
a[j + 1] = a[j];
}
a[0] = 0;
int... |
Problem: Suppose you have two polynomials <image> and <image>. Then polynomial <image> can be uniquely represented in the following way:
<image>
This can be done using [long division](https://en.wikipedia.org/wiki/Polynomial_long_division). Here, <image> denotes the degree of polynomial P(x). <image> is called the re... | #include <bits/stdc++.h>
template <typename T>
inline void read(T &x) {
char c;
bool nega = 0;
while ((!isdigit(c = getchar())) && (c != '-'))
;
if (c == '-') {
nega = 1;
c = getchar();
}
x = c - 48;
while (isdigit(c = getchar())) x = x * 10 + c - 48;
if (nega) x = -x;
}
template <typename T... |
Problem: Suppose you have two polynomials <image> and <image>. Then polynomial <image> can be uniquely represented in the following way:
<image>
This can be done using [long division](https://en.wikipedia.org/wiki/Polynomial_long_division). Here, <image> denotes the degree of polynomial P(x). <image> is called the re... | import java.io.IOException;
import java.io.InputStream;
import java.util.InputMismatchException;
public class Main {
public static void main(String[] args) {
FastScanner input = new FastScanner(System.in);
int N = input.nextInt();
int[][] poly = new int[N + 1][N + 1];
poly[0][0] = 1;
poly[1][1] = 1;
... |
Problem: Suppose you have two polynomials <image> and <image>. Then polynomial <image> can be uniquely represented in the following way:
<image>
This can be done using [long division](https://en.wikipedia.org/wiki/Polynomial_long_division). Here, <image> denotes the degree of polynomial P(x). <image> is called the re... | #include <bits/stdc++.h>
using namespace std;
class customIO {
public:
istream& in;
ostream& out;
customIO(istream& _in, ostream& _out) : in(_in), out(_out) {}
string next() {
string s;
in >> s;
return s;
}
double nextDouble() { return stod(next()); }
int nextInt() { return stoi(next()); }
... |
Problem: Suppose you have two polynomials <image> and <image>. Then polynomial <image> can be uniquely represented in the following way:
<image>
This can be done using [long division](https://en.wikipedia.org/wiki/Polynomial_long_division). Here, <image> denotes the degree of polynomial P(x). <image> is called the re... | #include <bits/stdc++.h>
using namespace std;
const int Inf = (int)1e9 + 7;
const long long LongInf = (long long)1e18 + 7;
namespace {
inline bool check(const vector<int>& a, const vector<int>& b) {
for (int i = 0; i < (int)b.size(); i++)
if (a[i] + b[i] > 1 || a[i] + b[i] < -1) return false;
return true;
}
voi... |
Problem: Suppose you have two polynomials <image> and <image>. Then polynomial <image> can be uniquely represented in the following way:
<image>
This can be done using [long division](https://en.wikipedia.org/wiki/Polynomial_long_division). Here, <image> denotes the degree of polynomial P(x). <image> is called the re... | #include <bits/stdc++.h>
using namespace std;
const int N = 155;
int n;
int a[N][2][N];
void init() {
a[1][0][0] = 0;
a[1][0][1] = 1;
a[1][1][0] = 1;
for (int i = 2; i <= 150; i++) {
for (int j = 0; j <= 150; j++) {
a[i][1][j] = a[i - 1][0][j];
if (j != 0) a[i][0][j] = a[i - 1][0][j - 1];
... |
Problem: Suppose you have two polynomials <image> and <image>. Then polynomial <image> can be uniquely represented in the following way:
<image>
This can be done using [long division](https://en.wikipedia.org/wiki/Polynomial_long_division). Here, <image> denotes the degree of polynomial P(x). <image> is called the re... | #include <bits/stdc++.h>
using namespace std;
long long a[150], b[150], c[150], d[150];
int cnt = 0, n;
int main() {
cin >> n;
a[0] = 0;
a[1] = 1;
b[0] = 1;
cnt = 1;
for (int i = 2; i <= n; i++) {
memset(c, 0, sizeof(c));
memset(d, 0, sizeof(d));
for (int j = 0; j <= cnt; j++) d[j] = a[j];
f... |
Problem: Suppose you have two polynomials <image> and <image>. Then polynomial <image> can be uniquely represented in the following way:
<image>
This can be done using [long division](https://en.wikipedia.org/wiki/Polynomial_long_division). Here, <image> denotes the degree of polynomial P(x). <image> is called the re... | def add(first,second):
l = max(map(len,[first,second]))
first = first+[0]*(l-len(first))
second = second+[0]*(l-len(second))
return [i+j for i,j in zip(first,second)]
def find_next(first,second):
# print 'fn ',first,second
first = list(first)
second = list(second)
second = [0]+second
p=1
for i,j in zip(first... |
Problem: We call a positive integer x a k-beautiful integer if and only if it is possible to split the multiset of its digits in the decimal representation into two subsets such that the difference between the sum of digits in one subset and the sum of digits in the other subset is less than or equal to k. Each digit s... | #include <bits/stdc++.h>
using namespace std;
void upd(long long &x, long long y) { x += y; }
struct node {
int nxt;
long long sta, v[10];
node() {
nxt = 0;
memset(v, 0, sizeof(v));
}
};
struct state {
vector<node> nodes;
int head[100007];
state() { memset(head, -1, sizeof(head)); }
size_t size(... |
Problem: We call a positive integer x a k-beautiful integer if and only if it is possible to split the multiset of its digits in the decimal representation into two subsets such that the difference between the sum of digits in one subset and the sum of digits in the other subset is less than or equal to k. Each digit s... | #include <bits/stdc++.h>
using namespace std;
const int B = 172;
const int S = 44000;
const int D = 20;
unordered_map<bitset<B>, int> H;
bool A[D][S];
bitset<B> a[S];
int go[S][10];
int n;
int d[20];
long long dp[20][10][S];
long long solve(long long n, int k) {
if (n == 0) return 1;
int m = 0;
while (n) d[m++] =... |
Problem: We call a positive integer x a k-beautiful integer if and only if it is possible to split the multiset of its digits in the decimal representation into two subsets such that the difference between the sum of digits in one subset and the sum of digits in the other subset is less than or equal to k. Each digit s... | #include <bits/stdc++.h>
using namespace std;
struct node {
int nxt;
long long sta, v[10];
node() {
nxt = 0;
memset(v, 0, sizeof(v));
}
};
struct state {
vector<node> nodes;
int head[100007];
state() { memset(head, -1, sizeof(head)); }
size_t size() const { return nodes.size(); }
void sum() {
... |
Problem: We call a positive integer x a k-beautiful integer if and only if it is possible to split the multiset of its digits in the decimal representation into two subsets such that the difference between the sum of digits in one subset and the sum of digits in the other subset is less than or equal to k. Each digit s... | #include <bits/stdc++.h>
using namespace std;
const int B = 172;
const int maxn = 44000;
const int maxm = 20;
unordered_map<bitset<B>, int> mp;
bool vis[maxm][maxn];
bitset<B> a[maxn];
int nxt[maxn][10];
int cnt = 1;
int bit[20];
long long dp[20][10][maxn];
void DP() {
for (int i = 1; i <= cnt; i++) {
int j = 0;
... |
Problem: We call a positive integer x a k-beautiful integer if and only if it is possible to split the multiset of its digits in the decimal representation into two subsets such that the difference between the sum of digits in one subset and the sum of digits in the other subset is less than or equal to k. Each digit s... | #include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const long long ooo = 9223372036854775807ll;
const int _cnt = 1000 * 1000 + 7;
const int _p = 1000 * 1000 * 1000 + 7;
const int N = 100005;
const double PI = acos(-1.0);
const double eps = 1e-9;
int o(int x) { return x % _p; }
int gcd(int a, int b... |
Problem: We call a positive integer x a k-beautiful integer if and only if it is possible to split the multiset of its digits in the decimal representation into two subsets such that the difference between the sum of digits in one subset and the sum of digits in the other subset is less than or equal to k. Each digit s... | #include <bits/stdc++.h>
using namespace std;
const int MAXX = 85;
const bitset<MAXX> unity(1);
bitset<MAXX> allOne;
hash<bitset<MAXX> > hash_fn;
bitset<MAXX> add(int sum, const bitset<MAXX> &p, int v) {
sum += v;
return (p | (p << v)) & allOne;
}
int getBest(int sum, const bitset<MAXX> &q) {
int best = 0;
for ... |
Problem: We call a positive integer x a k-beautiful integer if and only if it is possible to split the multiset of its digits in the decimal representation into two subsets such that the difference between the sum of digits in one subset and the sum of digits in the other subset is less than or equal to k. Each digit s... | #include <bits/stdc++.h>
using namespace std;
const int B = 172;
const int maxn = 44000;
const int maxm = 20;
unordered_map<bitset<B>, int> mp;
bool vis[maxm][maxn];
bitset<B> a[maxn];
int nxt[maxn][10];
int cnt = 1;
int bit[20];
long long dp[20][10][maxn];
long long solve(long long x, int k) {
if (x == 0) return 1;
... |
Problem: We call a positive integer x a k-beautiful integer if and only if it is possible to split the multiset of its digits in the decimal representation into two subsets such that the difference between the sum of digits in one subset and the sum of digits in the other subset is less than or equal to k. Each digit s... | #include <bits/stdc++.h>
using namespace std;
const int B = 172;
const int maxn = 44000;
const int maxm = 20;
unordered_map<bitset<B>, int> mp;
bool vis[maxm][maxn];
bitset<B> a[maxn];
int nxt[maxn][10];
int cnt = 1;
int bit[20];
long long dp[20][10][maxn];
long long solve(long long x, int k) {
if (x == 0) return 1;
... |
Problem: We call a positive integer x a k-beautiful integer if and only if it is possible to split the multiset of its digits in the decimal representation into two subsets such that the difference between the sum of digits in one subset and the sum of digits in the other subset is less than or equal to k. Each digit s... | #include <bits/stdc++.h>
using namespace std;
int sum;
vector<long long> vec[11];
const int moo = 100017;
struct Hashset {
long long key[40005];
long long val[40005];
int nxt[40005];
int head[moo], nd;
long long &operator[](const long long &x) {
for (int i = head[x % moo]; i; i = nxt[i])
if (key[i] ... |
Problem: We call a positive integer x a k-beautiful integer if and only if it is possible to split the multiset of its digits in the decimal representation into two subsets such that the difference between the sum of digits in one subset and the sum of digits in the other subset is less than or equal to k. Each digit s... | #include <bits/stdc++.h>
using namespace std;
const long long MX = 6e4, C = 10, L = 20;
long long nxt[MX][C], sz;
bitset<170> b[MX];
unordered_map<bitset<170>, long long> id;
inline long long low_bit(bitset<170> s) {
for (long long i = 0; i < 10; i++)
if (s.test(i)) return i;
return -1;
}
inline long long exten... |
Problem: We call a positive integer x a k-beautiful integer if and only if it is possible to split the multiset of its digits in the decimal representation into two subsets such that the difference between the sum of digits in one subset and the sum of digits in the other subset is less than or equal to k. Each digit s... | #include <bits/stdc++.h>
using namespace std;
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
puts(f ? "YES" : "NO");
exit(0);
}
void addmod(int &x, int y, int mod = 1000000007) {
assert(y >= 0);
x += y;
if (x >... |
Problem: We call a positive integer x a k-beautiful integer if and only if it is possible to split the multiset of its digits in the decimal representation into two subsets such that the difference between the sum of digits in one subset and the sum of digits in the other subset is less than or equal to k. Each digit s... | #include <bits/stdc++.h>
using namespace std;
const int maxd = 10, maxl = 18, maxs = 81, BLEN = 5, BMSK = 31, maxv = 32175,
maxv2 = 191791;
int htot, cnt[maxv], inc[maxv][maxd + 1], sub[maxv][maxd + 1], ptot,
pos[maxl + 1][maxv];
map<long long, int> Hash;
long long bit[maxd + 1], c[2][maxl + 1];
long long... |
Problem: We call a positive integer x a k-beautiful integer if and only if it is possible to split the multiset of its digits in the decimal representation into two subsets such that the difference between the sum of digits in one subset and the sum of digits in the other subset is less than or equal to k. Each digit s... | #include <bits/stdc++.h>
using namespace std;
const int B = 172, N = 44005;
using ll = long long;
using Bit = bitset<B>;
unordered_map<Bit, int> mp;
Bit aa, a[N];
bool vis[20][N];
int cnt = 1, nxt[N][10];
ll dp[20][10][N];
int b[20];
ll solve(ll n, int kk) {
if (!n) return 1;
int m = 0, pos = 1;
while (n) b[m++] ... |
Problem: We call a positive integer x a k-beautiful integer if and only if it is possible to split the multiset of its digits in the decimal representation into two subsets such that the difference between the sum of digits in one subset and the sum of digits in the other subset is less than or equal to k. Each digit s... | #include <bits/stdc++.h>
using namespace std;
const int B = 172, maxn = 44000, maxm = 20;
unordered_map<bitset<B>, int> mp;
bool vis[maxm][maxn];
bitset<B> a[maxn];
int nxt[maxn][10], cnt = 1, bit[20];
long long dp[20][10][maxn];
long long solve(long long x, int k) {
if (x == 0) return 1;
int len = 0;
while (x) {... |
Problem: We call a positive integer x a k-beautiful integer if and only if it is possible to split the multiset of its digits in the decimal representation into two subsets such that the difference between the sum of digits in one subset and the sum of digits in the other subset is less than or equal to k. Each digit s... | #include <bits/stdc++.h>
using namespace std;
const int B = 172;
const int S = 44000;
const int D = 20;
unordered_map<bitset<B>, int> H;
bool A[D][S];
bitset<B> a[S];
int go[S][10];
int n;
int d[20];
long long dp[20][10][S];
long long solve(long long n, int k) {
if (n == 0) return 1;
int m = 0;
while (n) d[m++] =... |
Problem: We call a positive integer x a k-beautiful integer if and only if it is possible to split the multiset of its digits in the decimal representation into two subsets such that the difference between the sum of digits in one subset and the sum of digits in the other subset is less than or equal to k. Each digit s... | #include <bits/stdc++.h>
using namespace std;
struct node {
int nxt;
long long sta, v[10];
node() {
nxt = 0;
memset(v, 0, sizeof(v));
}
};
struct state {
vector<node> nodes;
int head[100007];
state() { memset(head, -1, sizeof(head)); }
size_t size() const { return nodes.size(); }
void sum() {
... |
Problem: We call a positive integer x a k-beautiful integer if and only if it is possible to split the multiset of its digits in the decimal representation into two subsets such that the difference between the sum of digits in one subset and the sum of digits in the other subset is less than or equal to k. Each digit s... | #include <bits/stdc++.h>
const long long MAX = 1000000000000000000ll;
int tot[20], to[20][12300][10], rev[10][1 << 10];
std::map<std::pair<unsigned long long, unsigned>, int> M[20];
int abs(int x) { return x < 0 ? -x : x; }
int init(int i, std::pair<unsigned long long, unsigned> s) {
if (!s.first && !s.second) return... |
Problem: We call a positive integer x a k-beautiful integer if and only if it is possible to split the multiset of its digits in the decimal representation into two subsets such that the difference between the sum of digits in one subset and the sum of digits in the other subset is less than or equal to k. Each digit s... | #include <bits/stdc++.h>
using namespace std;
void upd(long long &x, long long y) { x += y; }
struct node {
int nxt;
long long sta, v[10];
node() {
nxt = 0;
memset(v, 0, sizeof(v));
}
};
struct state {
vector<node> nodes;
int head[100007];
state() { memset(head, -1, sizeof(head)); }
size_t size(... |
Problem: We call a positive integer x a k-beautiful integer if and only if it is possible to split the multiset of its digits in the decimal representation into two subsets such that the difference between the sum of digits in one subset and the sum of digits in the other subset is less than or equal to k. Each digit s... | #include <bits/stdc++.h>
using namespace std;
const int B = 172;
const int maxn = 44000;
const int maxm = 20;
unordered_map<bitset<B>, int> mp;
bool vis[maxm][maxn];
bitset<B> a[maxn];
int nxt[maxn][10];
int cnt;
int bit[20];
long long dp[20][10][maxn];
long long solve(long long cnt, int k) {
if (cnt == 0) return 1;
... |
Problem: We call a positive integer x a k-beautiful integer if and only if it is possible to split the multiset of its digits in the decimal representation into two subsets such that the difference between the sum of digits in one subset and the sum of digits in the other subset is less than or equal to k. Each digit s... | #include <bits/stdc++.h>
using namespace std;
struct state {
vector<long long> keys, vals[11];
void insert(long long key) { keys.push_back(key); }
void init(long long val = 0) {
sort(keys.begin(), keys.end());
keys.erase(unique(keys.begin(), keys.end()), keys.end());
for (int i = 0; i < 10; i++) vals[... |
Problem: We call a positive integer x a k-beautiful integer if and only if it is possible to split the multiset of its digits in the decimal representation into two subsets such that the difference between the sum of digits in one subset and the sum of digits in the other subset is less than or equal to k. Each digit s... | #include <bits/stdc++.h>
using namespace std;
const int B = 172;
const int maxn = 44000;
const int maxm = 20;
unordered_map<bitset<B>, int> mp;
bool vis[maxm][maxn];
bitset<B> a[maxn];
int nxt[maxn][10];
int n;
int bit[20];
long long dp[20][10][maxn];
long long solve(long long n, int k) {
if (n == 0) return 1;
int ... |
Problem: We call a positive integer x a k-beautiful integer if and only if it is possible to split the multiset of its digits in the decimal representation into two subsets such that the difference between the sum of digits in one subset and the sum of digits in the other subset is less than or equal to k. Each digit s... | #include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std;
vector<ll> splits;
const ll B = 20;
const int D = 10;
const int M = 19;
ll pw[D];
const int C = 100000;
const int NO = C - 1;
vector<ll> vals;
int go[C][D];
bool good[C][D];
ll goodCount[D][M][C];
int cn;
using BS = bitset<9 * 2... |
Problem: We call a positive integer x a k-beautiful integer if and only if it is possible to split the multiset of its digits in the decimal representation into two subsets such that the difference between the sum of digits in one subset and the sum of digits in the other subset is less than or equal to k. Each digit s... | #include <bits/stdc++.h>
const long long MAX = 1000000000000000000ll;
int tot[20], to[20][12300][10], rev[10][1 << 10];
std::map<std::pair<unsigned long long, unsigned>, int> M[20];
int abs(int x) { return x < 0 ? -x : x; }
int init(int i, std::pair<unsigned long long, unsigned> s) {
if (!s.first && !s.second) return... |
Problem: We call a positive integer x a k-beautiful integer if and only if it is possible to split the multiset of its digits in the decimal representation into two subsets such that the difference between the sum of digits in one subset and the sum of digits in the other subset is less than or equal to k. Each digit s... | #include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std;
vector<ll> splits;
const ll B = 20;
const int D = 10;
const int M = 19;
ll pw[D];
const int C = 100000;
const int NO = C - 1;
vector<ll> vals;
int go[C][D];
bool good[C][D];
ll goodCount[D][M][C];
int cn;
using BS = bitset<9 * 2... |
Problem: We call a positive integer x a k-beautiful integer if and only if it is possible to split the multiset of its digits in the decimal representation into two subsets such that the difference between the sum of digits in one subset and the sum of digits in the other subset is less than or equal to k. Each digit s... | #include <bits/stdc++.h>
using namespace std;
const int maxD = 10, maxl = 18, maxs = 81, BLEN = 5, BMSK = 31;
struct States {
vector<long long> keys, vals[maxD + 1];
void insert(long long key) { keys.push_back(key); }
void initialize(long long val = 0) {
sort(keys.begin(), keys.end());
keys.erase(unique(k... |
Problem: We call a positive integer x a k-beautiful integer if and only if it is possible to split the multiset of its digits in the decimal representation into two subsets such that the difference between the sum of digits in one subset and the sum of digits in the other subset is less than or equal to k. Each digit s... | #include <bits/stdc++.h>
using namespace std;
const int B = 172;
const int maxn = 44000;
const int maxm = 20;
unordered_map<bitset<B>, int> mp;
bool vis[maxm][maxn];
bitset<B> a[maxn];
int nxt[maxn][10];
int cnt = 1;
int bit[20];
long long dp[20][10][maxn];
long long solve(long long x, int k) {
if (x == 0) return 1;
... |
Problem: We call a positive integer x a k-beautiful integer if and only if it is possible to split the multiset of its digits in the decimal representation into two subsets such that the difference between the sum of digits in one subset and the sum of digits in the other subset is less than or equal to k. Each digit s... | #include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXK = 9;
const int MAXLEN = 19;
const int MAXS = 9 * MAXLEN / 2;
const int XLEN = 5;
int xoff[10];
long long xmask[10];
vector<long long> opt[MAXK + 1][MAXLEN + 1];
vector<long long> w... |
Problem: We call a positive integer x a k-beautiful integer if and only if it is possible to split the multiset of its digits in the decimal representation into two subsets such that the difference between the sum of digits in one subset and the sum of digits in the other subset is less than or equal to k. Each digit s... | #include <bits/stdc++.h>
using namespace std;
const int B = 172;
const int maxn = 44000;
const int maxm = 20;
unordered_map<bitset<B>, int> mp;
bool vis[maxm][maxn];
bitset<B> a[maxn];
int nxt[maxn][10];
int cnt;
int bit[20];
long long dp[20][10][maxn];
long long solve(long long cnt, int k) {
if (cnt == 0) return 1;
... |
Problem: We call a positive integer x a k-beautiful integer if and only if it is possible to split the multiset of its digits in the decimal representation into two subsets such that the difference between the sum of digits in one subset and the sum of digits in the other subset is less than or equal to k. Each digit s... | #include <bits/stdc++.h>
using namespace std;
const int B = 172;
const int maxn = 44000;
const int maxm = 20;
unordered_map<bitset<B>, int> mp;
bool vis[maxm][maxn];
bitset<B> a[maxn];
int nxt[maxn][10];
int cnt = 1;
int bit[20];
long long dp[20][10][maxn];
long long solve(long long x, int k) {
if (x == 0) return 1;
... |
Problem: We call a positive integer x a k-beautiful integer if and only if it is possible to split the multiset of its digits in the decimal representation into two subsets such that the difference between the sum of digits in one subset and the sum of digits in the other subset is less than or equal to k. Each digit s... | #include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const long long ooo = 9223372036854775807ll;
const int _cnt = 1000 * 1000 + 7;
const int _p = 1000 * 1000 * 1000 + 7;
const int N = 100005;
const double PI = acos(-1.0);
const double eps = 1e-9;
int o(int x) { return x % _p; }
int gcd(int a, int b... |
Problem: We call a positive integer x a k-beautiful integer if and only if it is possible to split the multiset of its digits in the decimal representation into two subsets such that the difference between the sum of digits in one subset and the sum of digits in the other subset is less than or equal to k. Each digit s... | #include <bits/stdc++.h>
using namespace std;
const int maxd = 10, maxl = 18, maxs = 81, BLEN = 5, BMSK = 31, maxv = 32175,
maxv2 = 191791;
int htot, cnt[maxv], inc[maxv][maxd + 1], sub[maxv][maxd + 1], ptot,
pos[maxl + 1][maxv];
map<long long, int> Hash;
long long bit[maxd + 1], c[2][maxl + 1];
long long... |
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | #include <bits/stdc++.h>
using namespace std;
int n;
char s[200];
int ucnt, rcnt;
int main() {
scanf("%d", &n);
getchar();
gets(s);
int ans = strlen(s);
for (int i = 0; i < n - 1; i++) {
if ((s[i] == 'U' && s[i + 1] == 'R') || (s[i] == 'R' && s[i + 1] == 'U'))
i++, ans--;
}
cout << ans << endl;
... |
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | #include <bits/stdc++.h>
using namespace std;
stack<char> q;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n;
cin >> n;
char a;
cin >> a;
q.push(a);
for (int i = 2; i <= n; i++) {
cin >> a;
if ((q.top()) != 'd' && (q.top()) != a) {
q.pop();
q.push('d... |
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | import java.io.*;
import java.util.StringTokenizer;
public class Solution {
public static void solve(InputReader in, PrintWriter out, DebugWriter debug) throws IOException {
int n = in.nextInt();
String s = in.next();
int ans = 0;
for (int i = 0; i < s.length()-1; i++) {
... |
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | n = int(input())
s = str(input())
l = len(s)
prev = '';
for i in s:
if prev=='':
prev = i
continue
if (i=='U' and prev =='R') or (i=='R' and prev =='U'):
l=l-1
prev = ''
else:
prev = i
print(l) |
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, le;
cin >> n;
string s;
cin >> s;
le = s.length();
for (int i = 0; i < s.length(); i++) {
string sub = s.substr(i, 2);
if (sub == "RU" || sub == "UR") {
s.erase(i, 1);
s[i] = 'D';
}
}
cout << s.length() << endl;
... |
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | #include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 7;
const int inf = 1e9;
const double eps = 0.0000000001;
int main() {
int n, r = 0, u = 0, ans = 0;
scanf("%d", &n);
string s;
cin >> s;
bool bas = 1;
for (int i = 0; i < n; i++) {
if (s[i] != s[i + 1]) {
... |
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1000000;
int n, m, q, t[maxn], odp;
char s[maxn];
int main() {
scanf("%d%s", &n, s);
odp = n;
for (int i = 0; i < n - 1; i++)
if (s[i] != s[i + 1]) {
i++;
odp--;
}
printf("%d", odp);
}
|
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | #include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
int n;
cin >> n;
string s;
cin >> s;
int res = 0;
for (int i = 0; i < n; ++i) {
if (i < n - 1 && s[i] != s[i + 1]) i++;
res++;
}
cout << res << endl;
return 0;
}
|
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, c = 0, C1 = 0;
cin >> n;
char ch[n];
for (int i = 0; i < n; i++) {
cin >> ch[i];
}
for (int i = 0; i < n; i++) {
if ((ch[i] == 'R' && ch[i + 1] == 'U') ||
(ch[i] == 'U' && ch[i + 1] == 'R')) {
C1++;
i++;
} else... |
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | n = int(input())
s = input()
s += ' '
col = 0
i = 0
while i != n:
if (s[i] == 'U' and s[i+1] == 'R') or (s[i] == 'R' and s[i+1] == 'U'):
col += 1
i += 2
else:
i += 1
col += 1
print(col)
|
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | input()
s = list(input())
found = True
while found:
x = []
found = False
i = 0
while i < len(s)-1:
ss = [s[i], s[i+1]]
if 'R' in ss and 'U' in ss:
x.append('D')
i += 2
found = True
else:
x.append(s[i])
i += 1
if i < len(s):
x.append(s[i])
s = x
print(len(... |
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | n=int(input())
l=list(input())
i=0
N=len(l)
x=0
while i<n-1:
if (l[i]=="U" and l[i+1]=="R") or (l[i]=="R" and l[i+1]=="U"):
x+=1
i+=1
N-=2
i+=1
print(N+x) |
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | n=input()
s=input()
ans=len(s)
a=0
i=0
while i<len(s)-1:
if (s[i]=='U' and s[i+1]=='R') or (s[i]=='R' and s[i+1]=='U'):
a+=1
i+=1
i+=1
print(ans-a)
|
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | # import sys;sys.stdin = open("in.txt", "r");sys.stdout = open("out.txt", "w")
n = int(input())
ans = 0
s = input()
i = 0
while(i < n-1):
if((s[i] == s[i+1])):
i += 1
else:
i += 2
ans += 1
print(n - ans) |
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | #include <bits/stdc++.h>
using namespace std;
int main() {
int x, y;
cin >> x;
y = x;
char c = '0', lc;
for (int i = 0; i < x; i++) {
lc = c;
cin >> c;
if ((lc != '0') && (lc != c)) {
y--;
c = '0';
}
}
cout << y << "\n";
return 0;
}
|
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | import re
input()
print(len(re.sub(r'UR|RU', 'D', input())))
|
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | def ras(n,a):
x,y=0,0
while(x!=-1 and y!=-1):
x=a.find('RU')
y=a.find('UR')
if(x==-1 and y!=-1):
a=a.replace(a[y]+a[y+1],'D',1)
continue
if(y==-1 and x!=-1):
a=a.replace(a[x]+a[x+1],'D',1)
continue
z=min(x,y)
if(z!=-... |
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | import java.util.Scanner;
public class A{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int n = in.nextInt();
String s = in.next();
int sum = s.length();
for(int i = 1; i < s.length(); i++){
if(s.charAt(i-1) == 'U' && s.charAt(i) ==... |
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | import java.io.*;
import java.util.Arrays;
import java.util.InputMismatchException;
public class TaskA
{
public static void main(String[] args)
{
new TaskA(System.in, System.out);
}
static class Solver implements Runnable
{
int n;
BufferedReader in;
// InputReader ... |
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, ans = 0, i;
string s;
cin >> n >> s;
for (i = 0; i < s.size() - 1; i++) {
if (s[i] == 'R' && s[i + 1] == 'U' || s[i] == 'U' && s[i + 1] == 'R')
ans++, i++;
else
ans++;
}
if (i != n) ans++;
cout << ans << endl;
}
|
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
char c;
scanf(" %c", &c);
if (s.empty())
s += c;
else if (s.back() != 'D' && s.back() != c)
s.back() = 'D';
else
s += c;
}
cout << s.size() << endl;
ret... |
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | f=lambda:map(int,input().split())
n=int(input())
s=input()
i,c=1,0
while i<=n-1:
if s[i-1]+s[i]=='RU' or s[i-1]+s[i]=='UR':
c+=1
i+=2
else:
i+=1
print(n-c) |
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | n=int(input())
s=input()
c,i=0,0
while i<n-1:
if s[i]!=s[i+1]:
i+=2
c+=1
else:
i+=1
print(n-c) |
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | #include <bits/stdc++.h>
using namespace std;
bool check(string s) {
if (s == "ABC" || s == "ACB" || s == "BAC" || s == "BCA" || s == "CAB" ||
s == "CBA")
return 1;
return 0;
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string s;
long long n, cnt = 0;
;
cin >> n;... |
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | #----Kuzlyaev-Nikita-Codeforces-----
#------------03.04.2020-------------
alph="abcdefghijklmnopqrstuvwxyz"
#-----------------------------------
n=int(input())
a=list(str(input()))
for i in range(n-1):
if a[i]+a[i+1]=="RU":
a[i]="D";a[i+1]=""
continue
if a[i]+a[i+1]=="UR":
a[i]="D";a[... |
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | import java.io.*;
import java.util.*;
public class MyClass {
public static void main(String args[]) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringBuilder sb = new... |
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | length_sequence = int(raw_input())
sequence = raw_input()
newSequence = ""
i = 0
while(i < len(sequence)-1):
if(sequence[i] != sequence[i+1]):
sequence = sequence[:i] + "D" + sequence[i+2:]
i += 1
else:
i+=1
print(len(sequence)) |
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | #include <bits/stdc++.h>
using namespace std;
int main() {
(ios::sync_with_stdio(false), cin.tie(NULL));
int n;
cin >> n;
double start = clock();
string seq;
cin >> seq;
int len(0);
for (int i = 0; i < n - 1; i++) {
if (seq[i] != seq[i + 1]) {
len++;
i += 1;
}
}
cout << n - len <... |
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | n = int(input())
turns = input().strip()
c = 1
res = len(turns)
while c < (len(turns)):
if turns[c]!= turns[c-1]:
res -=1
c+=1
c+=1
print(res)
|
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | n=int(input())
s=input()
sm=''
i=0
while(True):
if(i!=n-1 and (s[i:i+2]=='UR' or s[i:i+2]=='RU')):
sm+='D'
i+=1
else:
sm +=s[i]
if(i==n-1):
break
i+=1
print(len(sm)) |
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... |
input()
i,j=0,1
st=input()
ans=0
while j<len(st):
if st[i]+st[j]=="RU" or st[i]+st[j]=="UR":
i+=2
j+=2
ans+=1
else:
i+=1;j+=1
print(len(st)-ans)
|
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | #include <bits/stdc++.h>
using namespace std;
int main() {
int k = 0, m, n;
string a;
cin >> n;
cin >> a;
for (int i = 0; i < n; i++) {
if (a[i] == 'U' && a[i + 1] == 'R' || a[i] == 'R' && a[i + 1] == 'U') {
k++;
i = i + 1;
}
}
cout << n - k;
}
|
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | #include <bits/stdc++.h>
using namespace std;
int n;
int main() {
cin >> n;
string A;
cin >> A;
for (int i = 0; i < A.size() - 1; i++) {
if (A[i] != A[i + 1]) {
n--;
i++;
}
}
cout << n;
return 0;
}
|
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | #include <bits/stdc++.h>
using namespace std;
const int N = 102;
int n;
char a[N];
int main() {
cin >> n >> a;
int ans = 0;
for (int i = 0; i < n; ++i) {
if ((a[i] == 'U' && a[i + 1] == 'R') || (a[i] == 'R' && a[i + 1] == 'U')) {
++i;
}
++ans;
}
cout << ans << endl;
return 0;
}
|
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author grolegor
*/
public class Main {
public static void main(String[] args) {
InputStream ... |
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | n = int(input())
seq = list(input())
new = ''
i = 0
while i<n:
if i == n-1:
new += seq[i]
i += 1
continue
if seq[i]=='R' and seq[i+1] == 'U' or seq[i]=='U' and seq[i+1]=='R':
new += 'D'
i += 1
else:
new += seq[i]
i += 1
print(len(new)) |
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | import java.util.*;
public class dark {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int N = scan.nextInt();
String s = scan.next();
char[] arr = s.toCharArray();
int answer = 0;
int i =0;
while( i < N) {
if(i <= N-2 && arr[i] == 'U' && arr[i+1] == 'R') {... |
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | #include <bits/stdc++.h>
using namespace std;
const int N = 1000;
int n;
char s[N];
int main() {
scanf("%d", &n);
scanf("%s", s + 1);
int ans = 0;
for (int i = 1; i < n; i++) {
if (s[i] != s[i + 1]) {
ans++;
i++;
}
}
printf("%d\n", n - ans);
return 0;
}
|
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | #coding: utf-8
entrada1 = int(raw_input())
entrada2 = raw_input()
count = 0
i = 0
anterior = ""
while i < entrada1 :
if entrada2[i] == "U" and anterior == "R":
count += 1
i += 1
if entrada2[i] == "R" and anterior == "U":
count += 1
i += 1
if i < entrada1:
anteri... |
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | n = int(input())
s = input()
i = 0
c = 0
while i < n - 1:
if s[i] != s[i + 1]:
c += 1
i += 2
else:
i += 1
print(n - c) |
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | import re
n = int(input()) ;s = input()
s = re.sub('(RU|UR)', 'D', s)
a = len(s)
print(a) |
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | import java.util.*;
import java.io.*;
public class Main
{
public static void main(String... args) throws IOException
{
Scanner sc=new Scanner(System.in);
/*Scanner sc=new Scanner(new FileReader("./input.txt"));
System.setOut(new PrintStream(new File("./output.txt")));*/
int n,i;
n=Integer.parseInt(sc.... |
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | n = int(input())
s = list(input())
for i in range(n - 1):
if s[i] == 'U' and s[i + 1] == 'R':
s[i] = 'D'
s[i + 1] = ''
if s[i] == 'R' and s[i + 1] == 'U':
s[i] = 'D'
s[i + 1] = ''
print(len(''.join(s)))
|
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | n=int(input())
str1=input()
i=0;count=0
while(i<n):
if str1[i:i+2]=="RU" or str1[i:i+2]=="UR":
count+=1
i+=2
else:
i+=1
print(len(str1)-count) |
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | # Diagonal Walking
n = int(raw_input())
word = raw_input()
soma = len(word)
i = 0
j = 1
while i < len(word)-1:
if word[i] != word[j]:
soma -= 1
j += 2
i += 2
else:
j += 1
i += 1
print soma
|
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | import java.util.*;
// Compiler version JDK 11.0.2
public class Dcoder
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
String s=sc.next();
String h="";
int c=0;
for(int i=0; i<s.length()-1;){
if(s.charAt(i) =='U' && s.charAt(i+1... |
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
public class Main {
public... |
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | #include <bits/stdc++.h>
int main() {
int n, i, s = 0;
std ::cin >> n;
std ::string m;
std ::cin >> m;
for (i = 0; i < n; ++i) {
if ((m[i] == 'R' && m[i + 1] == 'U') || (m[i] == 'U' && m[i + 1] == 'R')) {
++i;
++s;
}
}
std ::cout << n - s << "\n";
return 0;
}
|
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | ln = int(input())
a = [str(x) for x in input()]
for i, t in enumerate(a):
if i == (ln-1):
break
if t == 'U':
if a[i+1] == 'R':
a[i+1] = 'D'
a[i] = 0
elif t == 'R':
if a[i+1] == 'U':
a[i+1] = 'D'
a[i] = 0
count = 0
for i in a:
if ... |
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | n = int(input())
s = input()
i = 0
count = 0
while i < n:
if s[i - 1] != s[i]:
count += 1
i += 1
i += 1
print(n - count)
|
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | def shortcut(s):
c,i=0,0
while(i<len(s)-1):
if s[i]=='R':
if s[i+1]=='U':
c+=1
i+=2
else:
i+=1
elif s[i]=='U':
if s[i+1]=='R':
c+=1
i+=2
else:
i+=1
... |
Problem: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can r... | #include <bits/stdc++.h>
using namespace std;
void solve(string s) {
int l = s.length();
for (int i = 0; i < s.length() - 1; i++) {
if (s[i] == 'R' && s[i + 1] == 'U' || s[i] == 'U' && s[i + 1] == 'R') {
l--;
i++;
}
}
cout << l;
}
int n;
string s;
int main() {
ios_base::sync_with_stdio(fal... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.