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
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; int n, m, x, y, dx, dy, cnt, stp; long long ans; string s; map<pair<int, int>, int> vis; inline int abs(int x) { return x < 0 ? -x : x; } int main() { scanf("%d%d%d%d", &n, &m, &x, &y); cin >> s, dx = s[0] == 'U' ? -1 : 1, dy = s[1] == 'L' ? -1 : 1; if (x == 1 || x ==...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; const unsigned long int N = 100001, DIRECTIONS = 5, SIDE_VISITED_INDEX = 0; unsigned long int n, m, d, x, y; bool _up[N][DIRECTIONS], _down[N][DIRECTIONS], _left[N][DIRECTIONS], _right[N][DIRECTIONS]; unsigned long int currentCellsCount, cellsCount; signed long long int...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; int Read() { char c; while (c = getchar(), (c != '-') && (c < '0' || c > '9')) ; bool neg = (c == '-'); int ret = (neg ? 0 : c - 48); while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + c - 48; return neg ? -ret : ret; } map<pair<int, int>, int> t; ...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; int64_t n, m; void upd(string& str, int64_t& x, int64_t& y) { if (str[0] == 'D') ++x; else --x; if (str[1] == 'R') ++y; else --y; } int64_t upd_xy(string& str, int64_t& x, int64_t& y) { int64_t mx_x = 0, mx_y = 0; if (str[0] == 'D') mx_x = n ...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; int R, C; void findNext(int &ii, int &jj, pair<int, int> &di, int &num) { if (di.first < 0 && di.second < 0) { num = min(ii - 1, jj - 1); } else if (di.first < 0 && di.second > 0) { num = min(ii - 1, C - jj); } else if (di.first > 0 && di.second > 0) { num...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
import java.util.*; import java.lang.Math; import java.lang.Long; import java.io.*; import java.math.*; import java.awt.*; public class robot{ public static long mod = 1000000007; public static void main(String[] args){ Scanner input = new Scanner(System.in); int n = input.nextInt(); int m = input.nextInt(); ...
JAVA
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; const int MAX = 100010; int n, m, x, y; int k; bool top[MAX], bottom[MAX], lft[MAX], rgt[MAX]; const int dx[] = {1, 1, -1, -1}; const int dy[] = {1, -1, 1, -1}; int getCnt() { bool res = x % 2 == y % 2; int ret = 0; for (int i = 0; i < (int)(m); i++) ret += (0 == i % ...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; const int inf = 2000000000; const int N = 101000; int n, m, x, y, dx, dy, tot; map<int, int> hs[N]; char dir[10]; bool vis[N * 4]; long long ret = 1; void add(int px, int py) { if ((px + py) % 2 == (x + y) % 2) hs[px][py] = tot++; } void ff() { if (x == 1 && dx == -1) d...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; set<pair<int, int> > s1; set<pair<pair<int, int>, int> > s2; int main() { int n, m, x, y; string s; cin >> n >> m >> x >> y >> s; int num = 0; if (x == 1) s[0] = 'D'; if (x == n) s[0] = 'U'; if (y == 1) s[1] = 'R'; if (y == m) s[1] = 'L'; if (s[0] == 'U') ...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; int n, m, x, y, dir, dat[4][2] = {{1, 1}, {1, -1}, {-1, 1}, {-1, -1}}; long long ans = 1; char s[3]; map<int, map<int, map<int, bool> > > vis; bool atedge() { return x == 1 || x == n || y == 1 || y == m; } void func() { int step = min(dir < 2 ? n - x : x - 1, dir & 1 ? y ...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; set<pair<int, int> > s; int n, m, x, y, need; int dir1, dir2; long long ans; int main() { scanf("%d%d%d%d", &n, &m, &x, &y); char c = getchar(); while (c != 'D' && c != 'U') c = getchar(); if (c == 'D') dir1 = 1; else dir1 = -1; while (c != 'R' && c != '...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; int N, M, X, Y, dx, dy; map<pair<int, int>, int> F; void doit() { char s[3]; long long ans = 1; scanf("%d%d%d%d%s", &N, &M, &X, &Y, s), dx = s[0] == 'U' ? -1 : 1, dy = s[1] == 'L' ? -1 : 1; for (int i = 1; i <= (N + M) * 2; ...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; const int INF = (int)1e9 + 7; int main() { int h, w; cin >> h >> w; int ci, cj; cin >> ci >> cj, ci--, cj--; string dir; cin >> dir; int di = dir[0] == 'D' ? 1 : -1; int dj = dir[1] == 'R' ? 1 : -1; int cnt = 0, pari = (ci + cj) & 1; vector<vector<bool>>...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; const int step[2] = {-1, 1}, mn = 101000; int n, m, xs, ys, kx, ky, x, y, fx, fy, cnt; long long ans; string st; set<int> T[mn]; void fix(int x, int y, int& fx, int& fy) { if (x == 1) fx = 1; else if (x == n) fx = 0; if (y == 1) fy = 1; else if (y == m) ...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3f; const int MOD = (int)1e9 + 7; const int N = (int)1e5 + 7; const double eps = 1e-6; bool eq(const double &a, const double &b) { return fabs(a - b) < eps; } bool ls(const double &a, const double &b) { retu...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; map<pair<int, int>, bool> fuck; int n, m; char s[5]; int x, y; long long ans; int dx, dy; int main() { scanf("%d%d", &n, &m); scanf("%d%d", &x, &y); scanf("%s", s + 1); if (s[1] == 'U') dx = -1; else dx = 1; if (s[2] == 'L') dy = -1; else dy = ...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; int cnt1, cnt2; map<int, bool> M[100001]; int main() { int n, m, x, y, d, dx, dy; char dir[4]; scanf("%d%d%d%d", &n, &m, &x, &y); scanf("%s", dir); if (dir[0] == 'U') dx = -1; else dx = 1; if (dir[1] == 'R') dy = 1; else dy = -1; int cnt = ...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; int pd[101010][4]; char s[5]; int n, m, rem; void paint(int x, int y, int tx, int ty) { int f = ((tx) >> 31) + 2 * ((ty) >> 31); int t; int tt; if (x == 1) t = 0, tt = y; else if (x == n) t = 1, tt = y; else if (y == 1) t = 2, tt = x; else t = ...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
import java.io.InputStreamReader; import java.io.IOException; import java.util.*; import java.math.*; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.io.InputStream; public class Main{ public static void main(String[] args) { InputStream inputStream = Sys...
JAVA
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; const int mod = 1e9 + 7; int n, m, a, b; inline int read() { int x = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = (x << 1) + (x << 3) + c...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; int n, m, uz, dz, lz, rz; int u[100010], d[100010], l[100010], r[100010]; long long ans; int paint(int x, int y) { int f = 0; if (x == 1) { u[y]++; if (u[y] == 1) uz--; if (u[y] == 3) f = 1; } if (x == n) { d[y]++; if (d[y] == 1) dz--; if (d[...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; const int lim = 1000000; int n, m; int x, y; string dr; int dx, dy; set<pair<int, int> > was; long long res; void Calc(int &t1, int &t2) { if (dx == 1) t1 = n - x; if (dx == -1) t1 = x - 1; if (dy == 1) t2 = m - y; if (dy == -1) t2 = y - 1; } int main() { cin >> n...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; int main() { int n, m; int sx, sy; string sd; cin >> n >> m >> sx >> sy >> sd; if (sx == 1) sd[0] = 'D'; else if (sx == n) sd[0] = 'U'; if (sy == 1) sd[1] = 'R'; else if (sy == m) sd[1] = 'L'; long long res = 1; set<pair<int, int> > pS; ...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; bool vis[400050]; int H, W; int x, y, dx, dy; void redirect() { int tx = x + dx; if (tx <= 0 || W < tx) dx = -dx; int ty = y + dy; if (ty <= 0 || H < ty) dy = -dy; } int main() { istream& in = cin; in >> H >> W; in >> y >> x; char tv, th; in >> tv >> th; ...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> long long min(long long a, long long b) { return a < b ? a : b; } long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } long long e_gcd(long long a, long long b, long long &x, long long &y) { if (b == 0) { x = 1; y = 0; return a; } long long ans = e_gc...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
import static java.lang.Math.*; import static java.math.BigInteger.*; import static java.util.Arrays.*; import static java.util.Collections.*; import java.math.*; import java.util.*; @SuppressWarnings("unused") public class D { private final static boolean autoflush = false; private static final int MOD = (int) 1...
JAVA
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
//package round178; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; public class D { InputStream is; PrintWriter out; String INPUT = ""; void solve() { int n = ni(), m = n...
JAVA
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; map<pair<int, int>, int> M; int main() { int n, m, x, y; char dir[5]; scanf("%d%d%d%d%s", &n, &m, &x, &y, dir); int dx = (dir[0] == 'U' ? -1 : 1); int dy = (dir[1] == 'L' ? -1 : 1); int res = n + m - 2; if (x == 1 || x == n || y == 1 || y == m) res--, M[make_p...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; set<pair<int, int> > s; int x, y; int dirx, diry; char dir[10]; int n, m; int cnt = 0; long long ans; int c; int main() { scanf("%d%d", &n, &m); scanf("%d%d", &x, &y); scanf("%s", dir); if (dir[0] == 'U') dirx = -1; else dirx = 1; if (dir[1] == 'L') ...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> namespace orz { const char *LL_SPECIFIER = "%I64d"; inline void read(int &x) { scanf("%d", &x); } inline void read(char *x) { scanf("%s", x); } template <typename T1, typename T2> inline void read(T1 &x1, T2 &x2) { read(x1); read(x2); } template <typename T1, typename T2, typename T3> inlin...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; void solve(); signed main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed; cout.precision(12); solve(); return 0; } template <typename T> void prv(vector<T> v) { for (int __ii = 0; __ii < ((int)v.size()); __ii++) { if (__ii) cout << ' '; cou...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; const int N = 200050; const int M = 4 * N; int n, m; int FindMain(int x, int y) { return n - x + y; } int FindSub(int x, int y) { return x + y - 1; } int Get(int t, int x, int y) { return t == 0 ? FindMain(x, y) : FindSub(x, y); } int Dist(int t, int x1, int y1, int x2, int...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; int n, m, x, y, dx, dy; char dir[5]; map<pair<int, int>, bool> MP; map<pair<pair<int, int>, int>, bool> GP; long long ans = 1; void fix() { if (x == 1) dx = 1; if (x == n) dx = -1; if (y == 1) dy = 1; if (y == m) dy = -1; } void shoot() { int ...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; int n, m, bgx, bgy, fxx, fxy; long long cnt, sum, tmp; map<pair<int, int>, bool> vis; char read() { char c = getchar(); while (c != 'U' && c != 'D' && c != 'L' && c != 'R') { c = getchar(); } return c; } void go_to(int &x, int &y, int fx, int fy) { if (fx == 1...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; void Get(int &T) { char C; bool F = 0; for (; C = getchar(), C < '0' || C > '9';) if (C == '-') F = 1; for (T = C - '0'; C = getchar(), C >= '0' && C <= '9'; T = T * 10 + C - '0') ; F && (T = -T); } int N, M; int X, Y; char Dir[5]; void Init() { Get(N); ...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; int n, m, x, y; char ch[10]; bool vis[1000000]; int id(int x, int y) { if (x == 1) return y; if (y == m) return x + m - 1; if (x == n) return m * 2 + n - y - 1; if (y == 1) return m * 2 + n * 2 - 2 - x; } int stp(int x, int y, int dx, int dy) { int ans = n + m; ...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; int sg[100050][4], n, m, Sx, Sy, Dir, st, ln[100050 * 4][4]; char b[3]; bool c[100050 * 4], d[100050 * 4][2]; long long cnt, ans; inline int Sg(int x, int y) { if (x == 1) return sg[y][0]; else if (x == n) return sg[y][1]; else if (y == 1) return sg[x][2];...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; const int mod = 1e9 + 7; int n, m, a, b; inline int read() { int x = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = (x << 1) + (x << 3) + c...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; int N, M, X, Y, dx, dy; map<pair<int, int>, int> F; void doit() { char s[3]; long long ans = 1; scanf("%d%d%d%d%s", &N, &M, &X, &Y, s), dx = s[0] == 'U' ? -1 : 1, dy = s[1] == 'L' ? -1 : 1; for (int i = 1; i <= (N + M) * 2; ...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; const int MAXA = 100010; int N, M; int ox, oy, dx, dy; int Go() { int t = min((dx == 1) ? (N - ox) : (ox - 1), (dy == 1) ? (M - oy) : (oy - 1)); ox += dx * t; oy += dy * t; return t; } int Vu[MAXA], Vd[MAXA], Vl[MAXA], Vr[MAXA], Task; void TaskInitialize() { int i...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; const int maxn = 5111; const long long base = 10000000; const int mod = 1000000007; template <typename T> T ABS(T n) { return n > 0 ? n : -n; } long long convert(long long x, long long y, long long dx, long long dy) { return (x << 22) | (y << 2) | (dx << 1) | (dy); } se...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; map<pair<int, int>, bool> mp; char s[5]; int main() { int n, m, x, y; scanf("%d%d%d%d", &n, &m, &x, &y); scanf("%s", s + 1); int dx, dy; if (s[1] == 'U') dx = -1; else dx = 1; if (s[2] == 'L') dy = -1; else dy = 1; int cnt = 0, time = 4e5 +...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); int n, m, x, y; string kier; cin >> n >> m >> x >> y >> kier; int dx, dy; if (kier[0] == 'U') dx = -1; else dx = 1; if (kier[1] == 'L') dy = -1; else dy = 1; set<pair<int, int> > S; S.insert(ma...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Locale; import java.util.StringTokenizer; public class D { private static final int UL = 0; private static final int UR = 1; private static final int DL = 2; private static fi...
JAVA
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
import java.io.InputStreamReader; import java.io.IOException; import java.util.*; import java.math.*; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.io.InputStream; public class Main{ public static void main(String[] args) { InputStream inputStream = Sys...
JAVA
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; int n, m, x, y, tot, a, b, f[4][10000000], dx, dy; char ch[5]; long long ans; int solve(int x, int y) { if (x == 1) a = 0, b = y; else if (x == n) a = 1, b = y; else if (y == 1) a = 2, b = x; else if (y == m) a = 3, b = x; if (!f[a][b]) f[a][b] = 1...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; int top[100010], bottom[100010], le[100010], ri[100010]; int dx[4] = {1, 1, -1, -1}; int dy[4] = {1, -1, -1, 1}; int correctit(int y, int x, int n, int m, int d) { switch (d) { case 0: if (y == n - 1) return (x == m - 1) ? 2 : 1; if (x == m - 1) return 3; ...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const int INF = 0x3f3f3f3f; map<int, int> mp[N]; int main() { ios::sync_with_stdio(false); cin.tie(0); int x, y, n, m, dx, dy; string s; cin >> n >> m >> x >> y; cin >> s; if (s[0] == 'U') dx = -1; else dx = 1; if (s[1] == 'L...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; int n, m, total, dx = 1, dy = 1; set<pair<int, int> > vis; void save(int x, int y) { if (!vis.count(pair<int, int>(x, y))) { vis.insert(pair<int, int>(x, y)); total++; } if (x == 1) dx = 1; if (x == n) dx = -1; if (y == 1) dy = 1; if (y == m) dy = -1; } ...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; const int MX = 100005; int n, m, x, y, fx, fy, k; int arr[MX], aba[MX], izq[MX], der[MX]; long long res; string s; void no() { cout << -1 << '\n'; exit(0); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m >> x >> y >> s; if (s[0] == 'U') ...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
import static java.lang.Math.*; public class D { private final static boolean autoflush = false; private static final int INF = (int) 1e9; private int N, M, Z, K = 0; private int [] A, B, C, D, W, T; private long res; public D () { N = sc.nextInt(); M = sc.nextInt(); int X = sc.nextInt(); int Y = sc....
JAVA
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; int r, c, sr, sc; map<pair<int, int>, int> M; string dir; int x[] = {0, 0, 1, -1}; int y[] = {1, -1, 0, 0}; void visit() { long long res = 1; int tp = 2 * (r + c - 1) - 2, evenp = ceil(r / 2.0) + ceil(c / 2.0) - 1; int cp = tp / 2; int cr = sr, cc = sc, nr = sr, nc ...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; long long a, b, x, y, s, dx, dy, e[4][100005], n, m, zz = 0, qsb, wl; void as(int c, int y) { if (x == 1) { n = 0; m = y; } if (x == a) { n = 1; m = y; } if (y == 1) { n = 2; m = x; } if (y == b) { n = 3; m = x; } if (!e[n][...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; int n, m, dx, dy, x, y; char S[10]; map<int, int> A[100010]; int main() { scanf("%d%d%d%d", &n, &m, &x, &y), cin >> S; dx = (S[0] == 'U') ? -1 : 1; dy = (S[1] == 'L') ? -1 : 1; int tot = n + m - 2, T = 0; if (x == 1 || x == n || y == 1 || y == m) A[x][y] = 1, (--(...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; const int d[][2] = {{1, -1}, {1, 1}, {-1, -1}, {-1, 1}}; const char* ds[] = {"DL", "DR", "UL", "UR"}; int gdi(const char* s) { int i = -1; while (++i < 4) { if (!strcmp(s, ds[i])) return i; } } bool sv[4] = {false}; int fdi(const int dr, const int dc) { int i = ...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; int n, m; set<pair<pair<int, int>, int> > S; set<pair<int, int> > SS; string c; int main() { int i, j; int x, y; cin >> n >> m >> x >> y >> c; int dir; if (c == "DR") dir = 2; else if (c == "UR") dir = 3; else if (c == "DL") ...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; int n, m, x, y; char ch[4]; int dx, dy; map<pair<int, int>, bool> Map; int main() { scanf("%d%d", &n, &m); scanf("%d%d", &x, &y); scanf("%s", ch); if (ch[0] == 'D') dx = 1; else dx = -1; if (ch[1] == 'R') dy = 1; else dy = -1; long long ans =...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; int n, m, x, y; map<pair<int, int>, int> p; void solve() { long long ans = 1; cin >> n >> m >> x >> y; string s; cin >> s; int dx = s[0] == 'U' ? -1 : 1; int dy = s[1] == 'L' ? -1 : 1; for (int i = 1; i <= (n + m) * 2; ++i) { p[make_pair(x, y)] = 1; if...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; const int INF = 1075555555; map<int, int> A[100010]; int n, m, now, dx, dy, x, y; char ch[10]; void work(void) { scanf("%d%d", &n, &m); scanf("%d%d", &x, &y); scanf("%s", ch + 1); if (ch[1] == 'U') dx = -1; else dx = 1; if (ch[2] == 'L') dy = -1; e...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.HashSet; import java.util.StringTokenizer; public class PanterRobot { static class Scanner{ BufferedReader br=null; StringTokenizer tk=null; public Scanner(){ br=new BufferedReader(new InputStream...
JAVA
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
__author__ = 'sergio' def sg(p): if p == 0: return -1 else: return 1 def minim(w,h): if w < h: return (w,0) else: return (h,1) def find_path(x, y, down, right): global size_n global size_m if down == 1: h = size_n - x else: h = x - 1 ...
PYTHON
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; const long long MAX_N = 100005; long long n, m; long long H(long long x) { if (x >= 0) return 1; else return 0; } bool legal(long long nx, long long ny, long long dx, long long dy) { if (nx == 1 && ny == 1 && dx == -1 && dy == -1) return false; if (nx == 1 &...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> struct Point { int x, y; Point(int x = 0, int y = 0) : x(x), y(y) {} Point &operator+=(const Point &o) { x += o.x; y += o.y; return *this; } }; Point operator+(Point a, const Point &b) { return a += b; } Point operator*(Point a, int k) { return Point(a.x * k, a.y * k); } boo...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; map<pair<int, int>, int> M; map<pair<int, int>, int> MM; int n, m; inline int jud(int x, int y) { if (x < 1 || x > n) return 0; if (y < 1 || y > m) return 0; return 1; } int main() { int i, j, k; long long ans = 0; int x, y; cin >> n >> m; cin >> x >> y; i...
CPP
294_D. Shaass and Painter Robot
Shaass thinks a kitchen with all white floor tiles is so boring. His kitchen floor is made of n·m square tiles forming a n × m rectangle. Therefore he's decided to color some of the tiles in black so that the floor looks like a checkerboard, which is no two side-adjacent tiles should have the same color. Shaass wants ...
2
10
#include <bits/stdc++.h> using namespace std; const int inf = ~0U >> 1; const long long INF = ~0ULL >> 1; template <class T> inline void read(T &n) { char c; for (c = getchar(); !(c >= '0' && c <= '9'); c = getchar()) ; n = c - '0'; for (c = getchar(); c >= '0' && c <= '9'; c = getchar()) n = n * 10 + c - '...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
from functools import reduce from operator import * from math import * from sys import * from string import * from collections import * setrecursionlimit(10**7) dX= [-1, 1, 0, 0,-1, 1,-1, 1] dY= [ 0, 0,-1, 1, 1,-1,-1, 1] RI=lambda: list(map(int,input().split())) RS=lambda: input().rstrip().split() #####################...
PYTHON3
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
def r(): return map(int, raw_input().split()) def main(): s = raw_input() s = s.replace("heavy", "|").replace("metal", "^") ls = len(s) total = 0 cur = 0 for i in xrange(ls): si = s[ls-i-1] if si == "^": cur += 1 elif si == "|": total += cur ...
PYTHON
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
import time,math,bisect,sys from sys import stdin,stdout from collections import deque from fractions import Fraction from collections import Counter pi=3.14159265358979323846264338327950 def II(): # to take integer input return int(stdin.readline()) def IO(): # to take string input return stdin.readline() def ...
PYTHON3
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> const long long inf = 0x3f3f3f3f3f3f3f3f; const long long maxn = 2e6 + 7; using namespace std; string h = "heavy", m = "metal"; string s; long long pre[maxn], pree[maxn]; void solve() { int flag = 1, pl = 0, cnt = 0; while (~pl) { if (pl == 0) pl = -1; pl = s.find(h, pl + 1); if...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
import java.io.BufferedReader; import java.io.InputStreamReader; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author Igor */ public class B318 { public static void main(String[] args) throws Exception { BufferedReader in = new BufferedRea...
JAVA
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; int main() { string cad, he = "heavy", me = "metal"; cin >> cad; vector<int> ph, pm; int ps = 0; while ((ps = cad.find(he, ps)) != string::npos) ph.push_back(ps), ps++; ps = 0; while ((ps = cad.find(me, ps)) != string::npos) pm.push_back(ps), ps++; long long...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); ; cin.tie(NULL); ; string s, s1, s2, s3; cin >> s; s1 = "heavy"; s2 = "metal"; int n, i; long long an = 0, h1 = 0, h2 = 0; n = s.length(); for (i = 0; i < n - 4; i++) { s3 = s.substr(i, 5); if (s...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
import sys import re if __name__ == "__main__": line = sys.stdin.readline().strip().replace("metal", '1').replace("heavy", '0') line = re.sub(r'[a-z]+', '', line) line = ''.join(reversed(line)) amount = 0 count = 0 for i in range(0, len(line)): if line[i] == '1': count += 1 else: amount += count pr...
PYTHON
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
import java.util.Scanner; public class B { public static void main(String[] args) { Scanner myScanner = new Scanner(System.in); String s = myScanner.next(); s = s.replaceAll("heavy", "1"); s = s.replaceAll("metal", "2"); s = s.replaceAll("[a-z]", ""); int metal[] = new int[s.length()], tmp = 0; for (int...
JAVA
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; int main() { string s; long long l, i, h = 0, m = 0; cin >> s; l = s.size(); for (i = 0; i < l - 4; i++) { if (s[i] == 'h' && s[i + 1] == 'e' && s[i + 2] == 'a' && s[i + 3] == 'v' && s[i + 4] == 'y') ++h; if (s[i] == 'm' && s[i + 1] == 'e' &&...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
import java.util.Scanner; /** * * @author takhi */ public class string_318B { public static void main(String args[]){ Scanner sc=new Scanner(System.in); String n=sc.next(); n=n.toLowerCase(); long count=0; long ans=0; for(int i=0;i+4<n.length();i++){ if(n.sub...
JAVA
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; string s; long long nr[11000000], k; int main() { cin >> s; for (int j = s.size(); j >= 0; j--) { nr[j] = nr[j + 1]; if (s[j] == 'm' && s[j + 1] == 'e' && s[j + 2] == 't' && s[j + 3] == 'a' && s[j + 4] == 'l') nr[j]++; if (s[j] == 'h' && s[j + ...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; import java.util.Arrays; import java.util.StringTokenizer; /* ------------ Theorems and Lemmas ------------ */ // Fermat's Little Theorem // (1) ((a ** p) - a) % p = 0; if 'p' is prime // (2) Further, if 'a % p != 0', then ((...
JAVA
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
def lower_bound(arr, l, r, key): res = -1 while l <= r: mid = (l + r)/2 if arr[mid] <= key: l = mid + 1 else: res = mid r = mid - 1 return res line = raw_input() heavy = [] metal = [] i = 0 while i < len(line): if line[i:i+5] == "heavy": ...
PYTHON
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; public class B { public static void main(String [] args){ Scanner in = new Scanner(System.in); StringBuffer s = new StringBuffer(in.next()); int i = 0 ; Queue<Integer> h = new LinkedList<>(); Queue<Integer> m = new LinkedList<>()...
JAVA
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; int main() { string a; unsigned long long int count = 0, output = 0; cin >> a; for (int i = 0; i < a.size(); i++) { if (a[i] == 'h' && a[i + 1] == 'e' && a[i + 2] == 'a' && a[i + 3] == 'v' && a[i + 4] == 'y') count++; if (a[i] == 'm' && a[i + 1...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
s = input() a = 0 su = 0 for i in range(len(s)): if s[i : i + 5] == 'heavy': a += 1 elif s[i : i + 5] == 'metal': su += a print(su)
PYTHON3
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; long long Count(string str) { long long cnt = 0; long long res = 0; for (int i = 0; i < str.size(); i++) { if (str.substr(i, 5) == "heavy") cnt++; if (str.substr(i, 5) == "metal") res += cnt; } return res; } int main() { string str; cin >> str; long ...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#!/usr/bin/python s = raw_input() a = "heavy" b = "metal" n = len(s) i = 0 w = [] while True: if i>=n and i>=n: break if s[i:i+len(a)]==a: w.append(True) i = i + 1 elif s[i:i+len(b)]==b: w.append(False) i = i + 1 else: i = i + 1 s = 0 ans = 0 fo...
PYTHON
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; int n, k; char a[2000009]; const char he[] = {'h', 'e', 'a', 'v', 'y', '\n'}; inline bool checkh(int x) { int c; for (c = 0; c + x < n && c < 5; c++) { if (a[x + c] != he[c]) return 0; } if (c == 5) return 1; return 0; } const char met[] = {'m', 'e', 't', 'a',...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; char a[1000001]; int main() { long long sum = 0, aux = 0, i; cin >> a; for (i = 0; a[i] != '\0'; i++) { if (a[i] == 'h' && a[i + 1] == 'e' && a[i + 2] == 'a' && a[i + 3] == 'v' && a[i + 4] == 'y') { aux++; } if (a[i] == 'm' && a[i + 1] == 'e'...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; const int L = 1e6; char t[L + 1]; bool f[L], g[L]; int sumg[L + 1]; int main() { scanf(" %s", t); int len = strlen(t); for (int i = 0; i < len; i++) { if (strncmp("heavy", t + i, 5) == 0) f[i] = true; } for (int i = 0; i < len; i++) { if (strncmp("metal", ...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; int main() { string a; cin >> a; long long ans = 0, h = 0, i, j, k; for (i = 0; i < a.size(); i++) { if (a[i] == 'h' && a[i + 1] == 'e' && a[i + 2] == 'a' && a[i + 3] == 'v' && a[i + 4] == 'y') h++, i += 4; else if (a[i] == 'm' && a[i + 1] == '...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
import os s = raw_input() heavy = [] i = s.find('heavy') while i != -1: heavy.append(i) i = s.find('heavy',i+1) metal = [] i = s.find('metal') while i != -1: metal.append(i) i = s.find('metal',i+1) #def getMetalAfter(num): #for i in range(len(metal)): #if num < metal[i]: #retu...
PYTHON
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; int main() { char a[1000100]; scanf("%s", a); int len = strlen(a) - 4; long long ans = 0, h = 0, i, j, k; for (i = 0; i < len; i++) { if (a[i] == 'h' && a[i + 1] == 'e' && a[i + 2] == 'a' && a[i + 3] == 'v' && a[i + 4] == 'y') h++; else if (a...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; long long ans = 0; int cnt = 0; for (int i = 0; i < s.size(); i++) { string sub = s.substr(i, 5); if (sub == "heavy") { cnt++; i += 4; } else if (sub == "metal") { ans += cnt; } } cout << ans <...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; string st; int main() { cin >> st; ios_base::sync_with_stdio(0); cin.tie(NULL); int i, j; long long int h = 0, m = 0, ans = 0; for (i = 0; i < (int)(st.length() - 4); i++) { if (st.substr(i, 5) == "heavy") { h++; } else if (st.substr(i, 5) == "meta...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
import java.io.*; import java.util.*; public class Main { public static void main(String [] adsa) throws Exception { BufferedReader br = new BufferedReader( new InputStreamReader(System.in) ); PrintWriter out = new PrintWriter( new BufferedOutputStream(System.out) ); String str = br.readLine(); int [] a = get...
JAVA
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; vector<int> heavy; vector<int> metal; int i, j, k; long long int count = 0; for (i = 0; i < s.size(); i++) { if (s.substr(i, 5) == "heavy") heavy.push_back(i + 4); else if (s.substr(i, 5) == "metal") metal.p...
CPP
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
s=raw_input() a=list() m = 0 for i in range(0,len(s)-4): if s[i:(i+5)]=="heavy": a.append(0) if s[i:(i+5)]=="metal": a.append(1) m = m+1 ans=0 for i in range(0,len(a)): if a[i] == 0: ans = ans + m else: m = m-1 print ans
PYTHON
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.StringTokenizer; public class BB { static StringTokenizer st; static BufferedReader in; static Pr...
JAVA
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
l = input().split('metal') ans = cur = 0 for str in l: cur += str.count('heavy') ans += cur print(ans - cur)
PYTHON3
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
s = raw_input().strip() H,M = [[i for i in xrange(len(s)) if s[i:i+5]==S] for S in ['heavy','metal']] h,m = len(H),len(M) i,j = 0,0 ans = 0 while i<h and j<m: if M[j] < H[i]: j += 1 else: ans += m-j i += 1 print ans
PYTHON
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
import sys import bisect line = sys.stdin.readline().strip() heavy = [] metal = [] last = -1 while True: nxt = line.find("heavy", last + 1) if nxt == -1: break heavy.append(nxt) last = nxt last = -1 while True: nxt = line.find("metal", last + 1) if nxt == -1: break metal.append(nxt) last = n...
PYTHON
318_B. Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
2
8
import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self...
PYTHON3