prompt
string
response
string
Problem: You've got an n × m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
import sys def prime(n): v = int(n**0.5)+1 l = [True for i in range(n+1)] l[0]=False l[1]=False for i in range(2,v): if l[i]: for j in range(i,n+1,i): if j%i == 0 and j!=i and l[j]: l[j] = False return l def c_prime(n): if d.get(n,Fal...
Problem: You've got an n × m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int prime[maxn]; int nextPrime(int n) { int i; for (i = n; i <= maxn; i++) { if (prime[i] == 0) return i - n; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); memset(prime, 0, sizeof(prime)); int...
Problem: You've got an n × m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
#include <bits/stdc++.h> using namespace std; bool a[200005]; int n = 200000; void seieve() { a[0] = a[1] = true; for (int i = 4; i <= n; i += 2) { a[i] = true; } int x = sqrt(n); for (int i = 3; i <= x; i += 2) { if (!a[i]) { for (int j = i * i; j <= n; j += 2 * i) { a[j] = true; ...
Problem: You've got an n × m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
from math import * sz = 100010 ind = [] prime = [] for x in range(sz): ind.append(False) def seive(): for x in range(3,sz,2): for y in range(x*x,sz,(2*x)): ind[y] = True prime.append(2) for x in range(3,sz,2): if(not(ind[x])): prime.append(x) def lb(): k = 0 ...
Problem: You've got an n × m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
from sys import stdin,stdout input=stdin.readline import math,bisect #from itertools import permutations #from collections import Counter prime=[1]*102001 prime[1]=0 prime[0]=0 for i in range(2,102001): j=i if prime[i]==1: while(j+i<102001): j+=i prime[j]=0 #print(prime) l=[] n,m=map(int,input().split()) f...
Problem: You've got an n × m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
from sys import stdin input = stdin.readline def get_primes(n): primes = [] numbers = [x for x in range(1, n + 1)] checked = [False]*n for i in range(1, n): if checked[i]: continue divisor = numbers[i] primes.append(divisor) for j in range(i + divisor, n, div...
Problem: You've got an n × m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
size = 10**6 n = size primos = [1]*(n+1) for i in range(2,n+1): if primos[i]==1: for j in range(i*i,n+1,i): primos[j]=0 primos[1] = 0 n,m = map(int, input().split()) ar = [] for i in range(n): ar.append(list(map(int, input().split()))) res = size lstPrimos = [0]*size lstPrimo = size-1 while (not primos[l...
Problem: You've got an n × m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
# -*- coding: utf-8 -*- import math def remove_zeros(listNum): listNumAux = [] for num in listNum: if num != 0: listNumAux.append(num) return listNumAux def sieve_of_eratosthenes(): limNumbers = 100004 limTest = math.ceil(math.sqrt(limNumbers)) listNum = list(range(2, limNumbers)) i = 0 for...
Problem: You've got an n × m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
#include <bits/stdc++.h> using namespace std; const int MAXN = 505; const int MAXM = 1e6 + 5; int n, m, val[MAXN][MAXN]; int tot, prime[MAXM]; bool is_prime[MAXM]; void sieves() { memset(is_prime, true, sizeof(is_prime)); tot = 0; for (int i = 2; i <= 1e6; i++) { if (is_prime[i]) prime[tot++] = i; for (in...
Problem: You've got an n × m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
crivo = [True for i in xrange(1000000)] crivo[0] = crivo[1] = False for i in xrange(2, 1000000): if not crivo[i]: continue for j in range(i * i, 1000000, i): crivo[j] = False n, m = map(int, raw_input().split()) data = [] for i in xrange(n): data.append(map(int, raw_input().split())) cou...
Problem: You've got an n × m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
M=110000 p=[0,0]+[1]*M for i in range(2,M): if p[i]: for j in range(i*i,M,i):p[j]=0; u=M for i in reversed(range(M)): if p[i]:u=i p[i]=u-i R=lambda:map(int,raw_input().split()) n,m=R() a=[R() for _ in range(n)] t=10**10 for v in a: t=min(t,sum(map(lambda x:p[x],v))) for v in zip(*a): t=min(t,sum(map(lambd...
Problem: You've got an n × m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Arrays; import java.util.StringTokenizer; public class Main { static ArrayList<Integer> pri...
Problem: You've got an n × m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
import java.io.*; import java.util.*; public class Main { static BufferedReader br; static PrintWriter out; static StringTokenizer st; static boolean[] genPrimes() { int N = 100010; boolean[] isPrime = new boolean[N]; Arrays.fill(isPrime, true); isPrime[1] = false; ...
Problem: You've got an n × m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
#include <bits/stdc++.h> using namespace std; int a[1000][1000]; int c[100000 + 10]; int r[1000000 + 10]; bool t[1000000 + 10]; int pr[100000 + 10]; int main() { int n, m; cin >> n >> m; for (int i = 2; i <= 100000 + 10; i++) { bool k = true; for (int j = 2; j * j <= i; j++) { if (i % j == 0) { ...
Problem: You've got an n × m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
//package ladderB; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.StringTokenizer; public class primeMatrix { static ArrayList<Integer> primes; static boolean [] prime; static void gen() { prime = ...
Problem: You've got an n × m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
n, m = map(int, raw_input().split()) g = [[] for i in xrange(n)] for i in xrange(n): g[i] = map(int, raw_input().split()) prime = [True for i in xrange(110000)] prime[0] = 0 prime[1] = 0 for i in xrange(4, 110000, 2): prime[i] = False p = [2] for i in xrange(3, 110000, 2): if prime[i]: p.append(i) ...
Problem: You've got an n × m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
#include <bits/stdc++.h> using namespace std; int z[501], y[501]; vector<int> v; int main() { v.clear(); bool check; int m, n, i, j, x, ans = INT_MAX; for (i = 2; i < 100500; i++) { check = 1; for (j = 2; j * j <= i; j++) { if (i % j == 0) { check = 0; break; } } if (...
Problem: You've got an n × m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
def get_primes(n): isPrime = [True] * (n+1) isPrime[0] = isPrime[1] = False for i in xrange(2, n+1): if i*i > n: break if isPrime[i]: for j in xrange(i*i, n+1, i): isPrime[j] = False return [i for i in xrange(2, n+1) if isPrime[i]] N = 10**5 primes = get_prim...
Problem: You've got an n × m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
def f(n): m = int(n ** 0.5) + 1 t = [1, 0] * (n // 2 + 1) t[0], t[1], t[2] = 1, 1, 0 for i in range(3, m): if t[i] == 0: t[i * i :: 2 * i] = [1] * ((n - i * i) // (2 * i) + 1) for i in range(n - 1, -1, -1): if t[i]: t[i] = t[i + 1] + 1 return t q = f(100007) n, m = m...
Problem: You've got an n × m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
import java.io.*; import java.math.*; import java.util.*; public class Olimp { public static void main(String[] arg) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int m = in.nextInt(); int[][] a = new int[n][m]; for(int i = 0; i < n; i++) ...
Problem: You've got an n × m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
#include <bits/stdc++.h> int Min(int a, int b) { return a < b ? a : b; } int main() { bool vis[110000]; int n, m, con[500][500], prime[12000], flag = 0, myMin = 100000000; for (int i = 2; i < 332; i++) { if (vis[i]) continue; for (int j = i * i; j < 110000; j += i) { vis[j] = true; } } for (...
Problem: You've got an n × m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
n, m = map(int, input().split()) a = [list(map(int, input().split())) for _ in range(n)] isPrime = [False, False] + [True] * 101000 for i in range(2, len(isPrime)): if isPrime[i]: for j in range(i*i, len(isPrime), i): isPrime[j] = False nextPrime = [0] * len(isPrime) for i in range(len(isPrime...
Problem: You've got an n × m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; template <class c> struct rge { c b, e; }; template <class c> rge<c> range(c i, c j) { return rge<c>{i, j}; } template <class c> auto dud(c* x) -> decltype(cerr << *x, 0); template <class c> char dud(...); struct debug { template <class c> ...
Problem: You've got an n × m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
import java.io.IOException; import java.util.InputMismatchException; import java.io.OutputStream; import java.io.PrintWriter; import java.util.HashSet; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * @author George Marcus */ public class Main { public static void ma...
Problem: You've got an n × m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind y...
#include <bits/stdc++.h> using namespace std; const int maxmn = 505; long long a[maxmn][maxmn]; long long luu1[maxmn][maxmn]; bool k[1000005]; long long maxx = 1e9; void readquick() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int main() { readquick(); vector<long long> luu; memset(k, true, si...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; int n, m, s, t, x, y; long long ans; set<pair<int, int> > st; int rd() { char c; while (c = getchar(), c < 'A') ; return c; } int main() { scanf("%d%d%d%d", &m, &n, &t, &s); y = (rd() == 'D') ? 1 : -1, x = (rd() == 'R') ? 1 : -1; ans = 1; for (int i = 1; i...
Problem: 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. Shaa...
#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...
Problem: 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. Shaa...
#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]; int getCnt() { bool res = x % 2 == y % 2; int ret = 0; for (int i = 0; i < (int)(m); i++) ret += (0 == i % 2) == res; for (int i = 0; i < (int)(m); i++) ret += ((n - 1) % ...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; int n, m, s, dx, dy; long long ans; map<pair<int, int>, int> h; char a[5]; void work(int x, int y) { int nx, ny, t; if (dx == -1) t = x - 1; else t = n - x; if (dy == -1) t = min(t, y - 1); else t = min(t, m - y); ans += t; x += dx * t; y += ...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; const int N = 100100; int n, m; int x, y; int l[N][4], r[N][4], u[N][4], d[N][4]; char s[N]; inline long long int get(int ot) { int lt(x); if (ot == 0) { int tmp(y - x); if (n - tmp <= m) x = n - tmp, y = n; else x = m, y = tmp + m; } else if (...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; int n, m; int x, y, dx = 1, dy = 1; int tot = 0; char s[6]; set<pair<int, int> > vis; void move(int x, int y) { if (!vis.count(pair<int, int>(x, y))) { vis.insert(pair<int, int>(x, y)); tot++; } if (x == 1) dx = 1; if (x == n) dx = -1; if (y == 1) dy = 1; ...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; const int MAXN = 100010; int n, m, x, y, vx, vy; int vis[5 * MAXN]; int get(int x, int y) { if (x == 1) return y; if (y == m) return m + x - 1; if (x == n) return m + m + n - 1 - y; return m + m + n + n - 2 - x; } int min(int a, int b) { return a > b ? b : a; } int ...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; int n, m, dire[4][2] = {{-1, -1}, {-1, 1}, {1, 1}, {1, -1}}, nowx, nowy, nowd, rest; long long ans; bool f[2][100005 * 2][2], posr[4][100005]; int transdire(char *st) { if (st[0] == 'U') if (st[1] == 'L') return 0; else return 1; else if (s...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; struct node { int x, y; node() {} node(int _x, int _y) : x(_x), y(_y) {} bool operator<(const node& o) const { return x == o.x ? y < o.y : x < o.x; } bool operator>(const node& o) const { return x == o.x ? y > o.y : x > o.x; } }; struct status { int p[4]; stat...
Problem: 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. Shaa...
import static java.lang.Math.*; //@SuppressWarnings("unused") public class D { private final static boolean autoflush = false; private static final int INF = (int) 1e9; public D () { N = sc.nextInt(); M = sc.nextInt(); int X = sc.nextInt(); int Y = sc.nextInt(); char [] dir = sc.nextChars(); int dx ...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; struct Segment { int coverTime, coverSize; Segment() { coverTime = coverSize = 0; } Segment(int coverTime, int coverSize) : coverTime(coverTime), coverSize(coverSize) {} Segment operator+(const Segment &rhs) const { return Segment(0, coverSize + rhs.coverS...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; const int N = 100005; int U[N], D[N], L[N], R[N]; int n, m, tot, cnt, xs, ys, ds, x, y, d; int sign[2] = {-1, 1}; long long ans; int visit(int x, int y) { int ret; if (x == 1) { ret = U[y]; U[y] = 1; } if (x == n) { ret = D[y]; D[y] = 1; } if (y ...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; template <class F, class T> T convert(F a, int p = -1) { stringstream ss; if (p >= 0) ss << fixed << setprecision(p); ss << a; T r; ss >> r; return r; } template <class T> T gcd(T a, T b) { T r; while (b != 0) { r = a % b; a = b; b = r; } ret...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; int n, m, total, dx = 1, dy = 1; set<pair<int, int> > vis; int mod(int a) { return a > 0 ? a : -a; } void save(int x, int y) { if (!vis.count(pair<int, int>(x, y))) { vis.insert(pair<int, int>(x, y)); if (x == 1 || x == n || y == 1 || y == m) total++; } if (x ...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; int main() { int n = 0, m = 0; cin >> n >> m; vector<vector<int>> v(n + 1); for (int i = 1; i < n + 1; ++i) { if ((i == 1) || (i == n)) v[i].resize(m + 1); else v[i].resize(2); } int fx = 0, fy = 0; cin >> fx >> fy; int x = fx, y = fy, x0...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; int n, m, x, y, cnt; long long ans; string str; map<pair<int, int>, int> vis; int main() { scanf("%d", &n); ; scanf("%d", &m); ; scanf("%d", &x); ; scanf("%d", &y); ; cin >> str; int dx, dy; (str[0] == 'U') ? dx = -1 : dx = 1; (str[1] == 'L') ? dy = ...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7; const int INF = 1e9 + 7; const int dx[] = {-1, -1, 1, 1}; const int dy[] = {-1, 1, -1, 1}; int n, m, xs, ys, ds; char str[10]; long long TS, ts[2][N][4], st[2][N][4]; bool isEnd(int x, int y, int d) { if (x == 1 || x == n) { if (~ts[x == n][y][d...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; void run(int casenr) { int h, w, x, y, dx, dy; char sdir[10]; scanf("%d%d%d%d%s", &h, &w, &x, &y, sdir); --x, --y; if (strcmp(sdir, "UL") == 0) { dx = -1; dy = -1; } else if (strcmp(sdir, "UR") == 0) { dx = -1; dy = +1; } else if (strcmp(sdir, ...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; map<int, int> A[110000]; int n, m, now, gox, goy, k1, k2; char ch[10]; int main() { scanf("%d%d", &n, &m); scanf("%d%d", &k1, &k2); scanf("%s", ch + 1); gox = 1; goy = 1; if (ch[1] == 'U') gox = -1; if (ch[2] == 'L') goy = -1; int rem = n + m - 2, ti = 0; ...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; int xs, ys; scanf("%d %d", &n, &m); char s[5]; scanf("%d %d %s", &xs, &ys, s); int dx = -1, dy = -1; if (s[0] == 'D') dx = 1; if (s[1] == 'R') dy = 1; int x = xs, y = ys; if (x == 1) dx = 1; if (x == n) dx = -1; if (y == 1) dy ...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; int n, m, sx, sy, dx, dy, NumBorder; long long ans; set<pair<int, int> > memory; void prepare() { char ts[5]; scanf("%d %d", &n, &m); scanf("%d %d %s", &sx, &sy, ts); if (ts[0] == 'D') dx = 1; else dx = -1; if (ts[1] == 'R') dy = 1; else dy = -...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; int n, m, i, j, k, x, y, dx, dy, l1, l2, l; long long ans; char s[5]; set<pair<int, int> > Hash; 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 ...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; long long n, m; map<long long, bool> already; int mask(int x, int y) { return x * 1000000LL + y; } int MAIN() { while (cin >> n >> m) { already.clear(); long long x, y; cin >> x >> y; bool eq = (x % 2 == y % 2); int dx, dy; string dir; cin >> d...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; const int MAX_N = 100000; const int D[4][2] = {{1, 1}, {1, -1}, {-1, 1}, {-1, -1}}; set<pair<int, int> > s; set<pair<pair<int, int>, int> > vis; char dir[10]; int sx, sy, h, w, d, tar; inline void update(int& a, int b) { if (b < a) a = b; } int main() { scanf("%d%d%d%d%...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; const int dx[4] = {1, 1, -1, -1}; const int dy[4] = {1, -1, -1, 1}; int sx, sy, n, m, sd; string sd_str; set<pair<pair<int, int>, int> > s; set<pair<int, int> > ps; long long ans = 0; inline bool on_edge(int x, int y) { return x == 1 || x == n || y == 1 || y == m; } inlin...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; int dx[] = {1, 1, -1, -1}; int dy[] = {1, -1, 1, -1}; int main() { int n, m; scanf("%d%d", &n, &m); int x, y; char s[4]; scanf("%d%d%s", &x, &y, s); int d; int row[2][100010], line[2][100010]; if (s[0] == 'D' && s[1] == 'R') d = 0; if (s[0] == 'D' && s[1] ...
Problem: 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. Shaa...
#include <bits/stdc++.h> template <typename T> void Read(T &x) { x = 0; int f = 1; char c; while ((c = std::getchar()) < '0' || c > '9') if (c == '-') f = -1; x = c - '0'; while ((c = std::getchar()) >= '0' && c <= '9') x = x * 10 + c - '0'; x *= f; } template <typename T, typename... Args> void Read(...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; const int tope = 100001; int n, m; int vistoi[2][tope][2][2]; int vistoj[2][tope][2][2]; void rebota(int i, int j, int &di, int &dj) { if (i == 0) { if (di == 0) di = 1; } else if (i == n - 1) { if (di == 1) di = 0; } if (j == 0) { if (dj == 0) dj = 1; ...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; struct State { int x, y, vec; bool operator<(const State &a) const { if (x != a.x) return x < a.x; else if (y != a.y) return y < a.y; else return vec < a.vec; } }; int main() { int n, m; scanf("%d%d", &n, &m); int x, y; scanf("%d%...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long maxn = 1e6 + 7; inline long long read() { long long res = 0, tmp = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') tmp = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') res = (re...
Problem: 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. Shaa...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.HashMap; import java.util.Map; import java.util.StringTokenizer; public class Count { static Map<String, Integer> dirs = new HashMap<String, Integer>(); static int[][] d = {...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double eps = 1e-8; inline int sign(double x) { if (x < -eps) return -1; return x > eps; } struct Tpoint { double x, y; Tpoint() {} Tpoint(double x, double y) : x(x), y(y) {} inline double norm() { return sqrt(x * x + y * y); }...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; void _fill_int(int* p, int val, int rep) { int i; for (i = 0; i < rep; i++) p[i] = val; } int GETi() { int i; scanf("%d", &i); return i; } template <class T> T sqr(T val) { return val * val; } int W, H; int TX[2][100001]; int TY[2][100001]; int CT = 0; void solv...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; void open() { freopen("data.txt", "r", stdin); } void out() { freopen("out.txt", "w", stdout); } const int maxn = 1e5 + 5; const int INF = 0x3f3f3f3f; map<int, int> mymap[maxn]; int main() { int n, m, x, y, dx, dy, cnt = 0; char str[5]; scanf("%d%d%d%d%s", &n, &m, &x,...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; int n, m; int dx, dy; int x, y; char s[100005]; map<int, int> a[100010]; int main() { cin >> n >> m; cin >> x >> y; scanf("%s", s + 1); long long sum = 0; if (s[1] == 'U') dx = -1; else dx = 1; if (s[2] == 'L') dy = -1; else dy = 1; int cnt...
Problem: 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. Shaa...
#include <bits/stdc++.h> int n, m; int a[400000]; int b[400000][4]; int dx[4] = {1, 1, -1, -1}; int dy[4] = {1, -1, 1, -1}; int min(int a, int b) { if (a < b) { return a; } else { return b; } } int f(int x, int y) { if (x == 1) { return y - 1; } else if (x == n) { return m + y - 1; } else if...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, x, y; cin >> n >> m >> x >> y; set<pair<int, int> > st; char cm[2]; cin >> cm; int fx, fy; if (cm[0] == 'U') { fx = -1; } else { fx = 1; } if (cm[1] == 'L') { fy = -1; } else { fy = 1; } long long ans = 1; f...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; set<pair<int, int> > st; int n, m; pair<int, int> get_dir(char a[5]) { int x = 1; if (a[0] == 'U') { x = -1; } int y = 1; if (a[1] == 'L') y = -1; return make_pair(x, y); } pair<int, int> nxt_dir(pair<int, int> pos, pair<int, int> dir) { if (pos.first == 1...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; const int N = 100010; const int M = 4; int now[2], dila[2]; int vis[N][4], n, m, cnt, ans_cnt; char s[4]; long long ans; int main() { int i, j, k, *p; bool lose = false; scanf("%d%d%d%d%s", &n, &m, &now[0], &now[1], s); if (s[0] == 'U') dila[0] = -1; else ...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; int n, m, x, y, tot, a, b, w, f[4][100010], dx, dy; long long ans; char ch[10]; void doit(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 a = 3, b = x; if (!f[a][b]) f[a][b] = 1, tot++; ...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; string str; int n, m, x, y; int use[100010][4]; int movex[] = {-1, -1, 1, 1}; int movey[] = {-1, 1, -1, 1}; int Judge(int x, int y) { int ans; if (x == 1) ans = use[y][0]++; if (x == n) ans = use[y][1]++; if (y == 1) ans = use[x][2]++; if (y == m) ans = use[x][3]+...
Problem: 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. Shaa...
import java.util.*; public class Main { public static Pair make_pair(int x ,int y) { Pair tmp = new Pair(); tmp.a = x; tmp.b=y; return tmp; } public static Triple make_trip(int x ,int y, int z) { Triple tt = new Triple(); tt.a = x; tt.b=y; tt.c = z; return tt; } static Scanner cin =...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; map<long long, long long> mp[100010]; const int INF = 2147483647; int n, m, x, y; char c[3]; int sx, sy; long long t, tot = 0, sum = 1; int dis = INF; int main() { scanf("%d%d%d%d%s", &n, &m, &x, &y, c + 1); if (c[1] == 'U') sx = -1; else sx = 1; if (c[2] ==...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; const int N = 100005; pair<int, int> p, q; int way[4][2] = {1, 1, -1, 1, 1, -1, -1, -1}; int n, m, dir; char str[5]; set<pair<int, int> > s; int main() { scanf("%d %d", &n, &m); scanf("%d %d %s", &p.first, &p.second, str); if (strcmp(str, "DR") == 0) dir = 0; el...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; bool f[4][100033]; int n, m, dx, dy, x, y, cnt = 0; long long ans = 1; char s[5]; int main() { scanf("%d%d%d%d%s", &n, &m, &x, &y, s); dx = s[0] == 'D' ? 1 : -1; dy = s[1] == 'R' ? 1 : -1; for (int i = 1, a, b; i <= 2 * (n + m - 2); i++) { if (x == 1) a = ...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; const int N = 105000; int n, m; int nx, ny; int dx, dy; char dir[5]; bool up[N], down[N], leftt[N], rightt[N]; int cc = 0; long long ans = 1; void add() { if (nx == 1) { if (!up[ny]) { cc++; up[ny] = 1; } } if (nx == n) { if (!down[ny]) { ...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; int xx[4] = {-1, -1, 1, 1}, yy[4] = {-1, 1, -1, 1}, n, m, x, y, mk; long long ans; set<pair<int, int> > A; char s[3]; void read(int &x) { char ch = getchar(); int mark = 1; for (; ch != '-' && (ch < '0' || ch > '9'); ch = getchar()) ; if (ch == '-') mark = -1, c...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; int i, j, m, n, p, k, rest; char We[3]; long long ans; struct Node { int x, y, pos; } A; map<pair<int, int>, int> mp[4], Mp; int P(char *a) { if (a[0] == 'U' && a[1] == 'L') return 0; if (a[0] == 'U' && a[1] == 'R') return 1; if (a[0] == 'D' && a[1] == 'L') return 2...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; set<pair<int, int> > st; int n, m; pair<int, int> get_dir(char a[5]) { int x = 1; if (a[0] == 'U') { x = -1; } int y = 1; if (a[1] == 'L') y = -1; return make_pair(x, y); } pair<int, int> nxt_dir(pair<int, int> pos, pair<int, int> dir) { if (pos.first == 1...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; long long int res, n, m, x, y, dx = 1, dy = 1, X, Y, Dx, Dy, nx, ny, INF = 10000000000000; char in[5]; set<pair<long long int, long long int> > s; void Change_Direction() { if (x == n) dx = -1; else if (x == 1) dx = 1; if (y == m...
Problem: 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. Shaa...
import java.io.*; import java.util.*; public class D { BufferedReader br; PrintWriter out; StringTokenizer st; boolean eof; int n, m; long f(int x, int y) { return (long)x * m + y; } boolean test(int mask, int i) { return ((mask >> i) & 1) == 1; } int getD(int dx, int dy) { return (dx == -1 ? ...
Problem: 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. Shaa...
#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 ==...
Problem: 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. Shaa...
#include <bits/stdc++.h> int n, m, x, y; long long ans; char ord[10]; int vis[4][100100][4], cnt, r[4][100100]; int p, q, dd, xx, yy, nd, nx, ny; int min(int c1, int c2) { if (c1 < c2) return c1; return c2; } int main() { int s; scanf("%d%d%d%d%s", &n, &m, &x, &y, ord); if ((x & 1) ^ (y & 1)) { if (!(n & ...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; int dx[] = {-1, 1, -1, 1}; int dy[] = {-1, -1, 1, 1}; int n, m, x, y, dir; char str[10]; int main() { while (scanf("%d%d", &n, &m) == 2) { scanf("%d%d", &x, &y); scanf("%s", str); dir = 0; if (str[0] == 'D') dir += 1; if (str[1] == 'R') dir += 2; i...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; template <class T> inline void CLR(T& A) { A.clear(); } inline bool insize(int c, int l, int r) { if (c >= l && c <= r) return true; return false; } template <class T> inline void checkmin(T& a, T b) { if (a == -1 || a > b) a = b; } template <class T> inline void ch...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7; int n, m, sx, sy; char dir[4]; int main() { scanf("%d%d%d%d %s", &n, &m, &sx, &sy, dir); int dx = dir[0] == 'U' ? -1 : 1; int dy = dir[1] == 'L' ? -1 : 1; int remain = n + m - 2; set<pair<int, int> > Set; if (sx == 1 || sx == n || sy == 1 ...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; map<pair<int, int>, int> vst; int tot, n, m, i, j, k, dx = 1, dy = 1; void go(int x, int y) { if (!vst[pair<int, int>(x, y)]) { vst[pair<int, int>(x, y)] = 1; tot++; } if (x == 1) dx = 1; if (x == n) dx = -1; if (y == 1) dy = 1; if (y == m) dy = -1; } in...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; bool edge[4][100005]; int x, y; int main() { int n, m; cin >> n >> m; string dir; cin >> x >> y >> dir; int dx = (dir[0] == 'D' ? 1 : -1); int dy = (dir[1] == 'R' ? 1 : -1); int tot = 0; long long ans = 1; for (int i = 1; i <= 2 * (n + m - 2); i++) { i...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; int n, m, x, y, tot, a, b, w, f[4][100010], dx, dy; long long ans; char ch[10]; void doit(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 a = 3, b = x; if (!f[a][b]) f[a][b] = 1, tot++; ...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; map<int, char> mp[100005]; int n, m; char getCode(char x) { return x == 'U' || x == 'L'; } int getDistance(int positive, int current, int mymax) { if (positive == 1) return current - 1; return mymax - current; } char invalid(int x, int mymax) { if (x < 1 || x > mymax)...
Problem: 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. Shaa...
__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 ...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; int n, m, x, y, dx, dy; char s[10]; int togo(int x, int dx, int limit) { if (dx == 1) return limit - x; return x - 1; } const int M = 100001; int seenU[M]; int seenD[M]; int seenR[M]; int seenL[M]; int main() { scanf("%d %d", &n, &m); scanf("%d %d %s", &x, &y, s); ...
Problem: 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. Shaa...
#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 = ...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; int x, y, n, m, edge[10][100010], whe, wht, dir, edt = 0, times = 0; long long ans = 0; bool comp = false; char dirc[1]; int main() { cin >> n >> m >> x >> y >> dirc; if (dirc[0] == 'U' && dirc[1] == 'L') dir = 1; else if (dirc[0] == 'U' && dirc[1] == 'R') dir...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; set<pair<int, int> > ss; void lemon() { int n, m, xs, ys; char buf[10]; scanf("%d%d%d%d%s", &n, &m, &xs, &ys, buf); int di, dj, xe = xs, ye = ys; if (buf[0] == 'D') di = 1; else di = -1; if (buf[1] == 'R') dj = 1; else dj = -1; long long fi...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; unordered_map<int, int> mp[100010]; int n, m, x, y, dx, dy; string s; long long ans; int main() { scanf("%d%d%d%d", &n, &m, &x, &y); cin >> s; if (s[0] == 'U') dx = -1; else dx = 1; if (s[1] == 'L') dy = -1; else dy = 1; int tot = n + m - 2, cn...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; long long convertToNum(string s) { long long val = 0; for (int i = 0; i < (s.size()); i++) val = val * 10 + s[i] - '0'; return val; } char bu[50]; string convertToString(int a) { sprintf(bu, "%d", a); return string(bu); } long long GCD(long long x, long long y) { ...
Problem: 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. Shaa...
#include <bits/stdc++.h> int n, m, xs, ys; int edge[100002][4]; int totals[4]; int maxs[4]; char rd[6]; int check() { if (ys == 1) { edge[xs][0]++; if (edge[xs][0] == 1) totals[0]++; if (edge[xs][0] == 5) return 2; } if (xs == 1) { edge[ys][1]++; if (edge[ys][1] == 1) totals[1]++; if (edge...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; map<pair<long long, pair<long long, long long> >, long long> mp; map<pair<long long, long long>, long long> mp2; long long MAX(long long a, long long b) { return a > b ? a : b; } long long MIN(long long a, long long b) { return a < b ? a : b; } int main() { long long n, m...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; long long n, m, x, y, sum = 1; long long dx = 1, dy = 1; char a, b; long long sum1 = 0; set<pair<long long, long long> > s; void operation() { long long k = 0; while (1) { s.insert(pair<long long, long long>(x, y)); k++; if (s.size() == n + m - 2) { pr...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; int n, m, x, y, dx, dy; char s[6]; map<pair<int, int>, bool> vis; map<pair<pair<int, int>, pair<int, int> >, bool> ss; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } bool solve() { vis.clear(); ss.clear(); int sum = 0; for (int i = (1); i ...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; map<long long, long long> mp[100005]; long long n, m; string s; long long x, y; long long dx, dy; signed main() { scanf("%lld%lld%lld%lld", &n, &m, &x, &y); cin >> s; if (s[0] == 'U') dx = -1; else dx = 1; if (s[1] == 'L') dy = -1; else dy = 1; ...
Problem: 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. Shaa...
#include <bits/stdc++.h> using namespace std; const int xt[4] = {1, 1, -1, -1}; const int yt[4] = {1, -1, -1, 1}; struct rec { int x, y, k; } v; int n, m, ans, p1[110000], p2[110000], p3[110000], p4[110000]; long long sum = 0; int f1() { char str[5]; scanf("%s", str); if (str[0] == 'D' && str[1] == 'L') return ...
Problem: 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. Shaa...
#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][...
Problem: 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. Shaa...
#include <bits/stdc++.h> const long long MAXN = 1e5 + 5; const long long dx[4] = {-1, -1, 1, 1}; const long long dy[4] = {1, -1, -1, 1}; bool vis[5][MAXN], used[5][MAXN][5]; long long n, m, sx, sy; long long zt, cnt, ans; char str[1231]; inline long long getk(long long x, long long y, long long zt) { long long res = ...