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
902_D. GCD of Polynomials
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 remainder o...
2
10
#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...
CPP
902_D. GCD of Polynomials
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 remainder o...
2
10
#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;...
CPP
902_D. GCD of Polynomials
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 remainder o...
2
10
#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...
CPP
902_D. GCD of Polynomials
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 remainder o...
2
10
#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...
CPP
902_D. GCD of Polynomials
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 remainder o...
2
10
#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....
CPP
902_D. GCD of Polynomials
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 remainder o...
2
10
#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;...
CPP
902_D. GCD of Polynomials
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 remainder o...
2
10
#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...
CPP
902_D. GCD of Polynomials
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 remainder o...
2
10
#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]...
CPP
902_D. GCD of Polynomials
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 remainder o...
2
10
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...
JAVA
902_D. GCD of Polynomials
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 remainder o...
2
10
#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...
CPP
902_D. GCD of Polynomials
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 remainder o...
2
10
#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...
CPP
902_D. GCD of Polynomials
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 remainder o...
2
10
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; ...
JAVA
902_D. GCD of Polynomials
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 remainder o...
2
10
#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()); } ...
CPP
902_D. GCD of Polynomials
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 remainder o...
2
10
#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...
CPP
902_D. GCD of Polynomials
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 remainder o...
2
10
#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]; ...
CPP
902_D. GCD of Polynomials
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 remainder o...
2
10
#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...
CPP
902_D. GCD of Polynomials
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 remainder o...
2
10
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...
PYTHON
924_F. Minimal Subset Difference
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 should bel...
2
12
#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(...
CPP
924_F. Minimal Subset Difference
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 should bel...
2
12
#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++] =...
CPP
924_F. Minimal Subset Difference
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 should bel...
2
12
#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() { ...
CPP
924_F. Minimal Subset Difference
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 should bel...
2
12
#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; ...
CPP
924_F. Minimal Subset Difference
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 should bel...
2
12
#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...
CPP
924_F. Minimal Subset Difference
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 should bel...
2
12
#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 ...
CPP
924_F. Minimal Subset Difference
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 should bel...
2
12
#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; ...
CPP
924_F. Minimal Subset Difference
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 should bel...
2
12
#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; ...
CPP
924_F. Minimal Subset Difference
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 should bel...
2
12
#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] ...
CPP
924_F. Minimal Subset Difference
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 should bel...
2
12
#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...
CPP
924_F. Minimal Subset Difference
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 should bel...
2
12
#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 >...
CPP
924_F. Minimal Subset Difference
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 should bel...
2
12
#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...
CPP
924_F. Minimal Subset Difference
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 should bel...
2
12
#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++] ...
CPP
924_F. Minimal Subset Difference
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 should bel...
2
12
#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) {...
CPP
924_F. Minimal Subset Difference
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 should bel...
2
12
#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++] =...
CPP
924_F. Minimal Subset Difference
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 should bel...
2
12
#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() { ...
CPP
924_F. Minimal Subset Difference
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 should bel...
2
12
#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...
CPP
924_F. Minimal Subset Difference
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 should bel...
2
12
#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(...
CPP
924_F. Minimal Subset Difference
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 should bel...
2
12
#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; ...
CPP
924_F. Minimal Subset Difference
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 should bel...
2
12
#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[...
CPP
924_F. Minimal Subset Difference
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 should bel...
2
12
#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 ...
CPP
924_F. Minimal Subset Difference
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 should bel...
2
12
#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...
CPP
924_F. Minimal Subset Difference
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 should bel...
2
12
#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...
CPP
924_F. Minimal Subset Difference
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 should bel...
2
12
#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...
CPP
924_F. Minimal Subset Difference
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 should bel...
2
12
#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...
CPP
924_F. Minimal Subset Difference
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 should bel...
2
12
#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; ...
CPP
924_F. Minimal Subset Difference
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 should bel...
2
12
#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...
CPP
924_F. Minimal Subset Difference
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 should bel...
2
12
#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; ...
CPP
924_F. Minimal Subset Difference
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 should bel...
2
12
#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; ...
CPP
924_F. Minimal Subset Difference
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 should bel...
2
12
#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...
CPP
924_F. Minimal Subset Difference
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 should bel...
2
12
#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...
CPP
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
#include <bits/stdc++.h> using namespace std; int n; 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; ...
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; 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...
CPP
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
import java.io.*; import java.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++) { ...
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 = 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)
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, 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; ...
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; 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]) { ...
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; 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); }
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 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; }
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, 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...
CPP
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
n = int(input()) s = input() s += ' ' 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)
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
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(...
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()) 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)
PYTHON3
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
n=input() s=input() 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)
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 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)
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 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; }
CPP
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
import re input() print(len(re.sub(r'UR|RU', 'D', input())))
PYTHON3
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
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!=-...
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 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) ==...
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.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 ...
JAVA
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n, 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; }
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() { 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...
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
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)
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,i=0,0 while i<n-1: if s[i]!=s[i+1]: i+=2 c+=1 else: i+=1 print(n-c)
PYTHON3
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
#include <bits/stdc++.h> using namespace std; 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;...
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
#----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[...
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 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...
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
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))
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() { (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 <...
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()) 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)
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() 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))
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
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)
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 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; }
CPP
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
#include <bits/stdc++.h> using namespace std; int n; 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; }
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; 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; }
CPP
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
import java.io.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 ...
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()) 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))
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 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') {...
JAVA
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
#include <bits/stdc++.h> using namespace std; const int 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; }
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
#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...
PYTHON
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
n = int(input()) s = input() i = 0 c = 0 while i < n - 1: if s[i] != s[i + 1]: c += 1 i += 2 else: i += 1 print(n - c)
PYTHON3
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
import re n = int(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
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....
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()) 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)))
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()) 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)
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
# 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
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.*; // 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...
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.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...
JAVA
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
#include <bits/stdc++.h> int main() { int n, 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; }
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
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 ...
PYTHON3
954_A. Diagonal Walking
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
2
7
n = int(input()) s = input() i = 0 count = 0 while i < n: if s[i - 1] != s[i]: count += 1 i += 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
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 ...
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; 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...
CPP