solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> int P = 998244353; using namespace std; template <typename T> inline void ckmax(T &a, T b) { (a < b) && (a = b); } template <typename T> inline void ckmin(T &a, T b) { (a > b) && (a = b); } inline int mul(int a, int b) { return 1ull * a * b % P; } inline int add(int a, int b) { return a + b...
25
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using uint = unsigned int; using ull = unsigned long long; template <typename T> using pair2 = pair<T, T>; using pii = pair<int, int>; using pli = pair<ll, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vl = vecto...
9
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 10; int n, m, d[N], rt[N], cnt; vector<int> G[N]; vector<pair<int, int> > p[N]; long long f[N], A = 0; struct T { int lch, rch, d, t; long long l, v; } o[N]; void update(int x, long long v) { if (x) o[x].v += v, o[x].l += v; } void pushdown(int x) ...
21
#include <bits/stdc++.h> using namespace std; const int NUM_ROW = 15; const int NUM_COL = 15; int mod(int a) { if (a < 0) { return -a; } return a; } int cmp(const void *a, const void *b) { return (*(int *)a - *(int *)b); } void FV(int grid[NUM_ROW][NUM_COL], int length) { for (int k = 0; k < length; k++) { ...
6
#include <bits/stdc++.h> using namespace std; int main() { double y1, y2, yw, xb, yb, r; scanf("%lf %lf %lf %lf %lf %lf", &y1, &y2, &yw, &xb, &yb, &r); yw -= r; y1 = yw * 2 - y1 - r; y2 = yw * 2 - y2; double l = sqrt(xb * xb + (y1 - yb) * (y1 - yb)); if (xb * (y1 - y2) / l < r) printf("-1\n"); else ...
12
#include <bits/stdc++.h> long long mod(long long a, long long b, long long m) { a %= m; return !b ? 1 : (((b & 1) ? a : 1) * mod(a * a, b >> 1, m) % m) % m; ; } int main() { long long n, m, k; scanf("%I64d%I64d%I64d", &n, &m, &k); if (k == -1 && ((n + m) & 1)) { puts("0"); } else { printf("%I64d\n...
10
#include <bits/stdc++.h> using namespace std; int n, val[300005], h[300005]; int a[2 * 300005][26], tot, ans[300005]; int mer(int x, int y) { if (x == 0 || y == 0) return x + y; int z = ++tot; for (int i = 0; i < 26; i++) a[z][i] = mer(a[x][i], a[y][i]); return z; } void dfs(int k, int d) { tot = n + 1; int...
17
#include <bits/stdc++.h> using namespace std; long long int MAX = 1e6 + 1; long long int mod = 1e9 + 7; vector<long long int> inter(vector<long long int> &a, vector<long long int> &b) { vector<long long int> v(4); v[0] = max(a[0], b[0]); v[1] = max(a[1], b[1]); v[2] = min(a[2], b[2])...
9
#include <bits/stdc++.h> using namespace std; const int MAX_N = 3e5 + 5; const double INF = 0x3f3f3f3f; const double EPS = 1e-6; struct Trie { int rt, tot, node[MAX_N * 35][2], bk[MAX_N * 35], cnt[MAX_N * 35]; void init() { tot = 0; memset(node, 0, sizeof(node)); memset(bk, 0, sizeof(bk)); memset(cn...
10
#include <bits/stdc++.h> using namespace std; namespace IO { const int BUFFER_SIZE = 1 << 15; char input_buffer[BUFFER_SIZE]; int input_pos = 0, input_len = 0; void _update_input_buffer() { input_len = fread(input_buffer, sizeof(char), BUFFER_SIZE, stdin); input_pos = 0; if (input_len == 0) input_buffer[0] = EOF;...
23
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long arr[n + 1], vis[n + 1]; memset(vis, 0, sizeof(vis)); arr[0] = 0; vis[0] = 1; for (long long i = 1; i <= n; i++) { cin >> arr[i]; if (arr[i] == 0) vis[i] = 1; } long long x[2 * n], y[2 * n]; memset(x, ...
11
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int x[N]; int y[N]; const int block = 700; int n, m; int ptr[block + 1]; int cnt[block + 1][block + 1]; int big[N]; int firstOcc[N]; void solve() { cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> x[i] >> y[i]; } int bigActive = 0; i...
14
#include <bits/stdc++.h> using namespace std; inline long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } inline long long lcm(long long a, long long b) { return (a / gcd(a, b) * b); } inline bool prime(long long n) { long long i; for (i = 2; i <= sqrt(n); i++) { if (n % i...
7
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { if (a[i] % 2 == 0) cout << a[i] - 1 << " "; else cout << a[i] << " "; } cout << endl; }
0
#include <bits/stdc++.h> #pragma GCC diagnostic ignored "-Wunused-result" #pragma GCC diagnostic ignored "-Wunused-function" using namespace std; namespace { namespace unolight { template <class T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf("%d", &x); } void _R(int64_t &x) { scanf("%" PRId64, &x); } void _R(...
14
#include <bits/stdc++.h> using namespace std; int n, m, table[105][105]; vector<pair<int, int> > out; bool turn(int r, int c, bool must = 0) { if (must || table[r][c]) { table[r][c] ^= 1; out.emplace_back(r, c); return 1; } return 0; } void rem(int r, int c) { int db = 0, r0, r1; for (int i = 0; i...
7
#include <bits/stdc++.h> using namespace std; template <class T> inline void checkmax(T &x, T y) { if (x < y) x = y; } template <class T> inline void checkmin(T &x, T y) { if (x > y) x = y; } template <class T> inline T Min(T x, T y) { return (x > y ? y : x); } template <class T> inline T Max(T x, T y) { return...
11
#include <bits/stdc++.h> using namespace std; using ll = long long; ll b, s; ll n; struct Node { ll x, y; Node() {} Node(ll _x, ll _y) : x(_x), y(_y) {} ll eval() { return x * s + y + b; } }; double slope(Node& u, Node& v) { return (double)(v.y - u.y) / (double)(v.x - u.x); } void solve() { int m; cin >> ...
19
#include <bits/stdc++.h> using namespace std; int dx4[] = {-1, 0, 1, 0}; int dy4[] = {0, 1, 0, -1}; int dx8[] = {-1, -1, 0, 1, 1, 1, 0, -1}; int dy8[] = {0, 1, 1, 1, 0, -1, -1, -1}; bool AreEqual(double a, double b) { return (fabs(a - b) < 1e-10); } template <class T> bool GetNr(T &_value) { T _sign = 1; char ch; ...
20
#include <bits/stdc++.h> using namespace std; const int INF = (1 << 29); const int INFF = 0x7fffffff; const long long LINF = (1ll << 60); const long long LINFF = 0x7fffffffffffffff; const double PI = 3.14159265359; long long fact[20] = {}; long long solve(vector<int> v, int i, int rmv) { long long res = 0; if (rmv ...
10
#include <bits/stdc++.h> using namespace std; unsigned long long int minimum(unsigned long long int a, unsigned long long int b) { return ((a <= b) ? a : b); } unsigned long long int findAns(vector<vector<long long int>> &heights) { int i, j; int n = heights.size(), m = heights[0].s...
14
#include <bits/stdc++.h> using namespace std; int n, m, k, ind; int color[100100], p[100100]; vector<int> baks[1000]; vector<pair<int, int> > edges; set<int> st; int dp[505][505]; int get(int v) { if (v == p[v]) return v; return p[v] = get(p[v]); } void merge(int a, int b) { a = get(a); b = get(b); p[a] = b; ...
12
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; template <class T> inline void amin(T &x, const T &y) { if (y < x) x = y; } template <class T> inline void amax(T &x, const T &y) { if (x < y) x = y; } template <class Iter> void rprintf(const char *fmt, Iter begin, Iter end) { for (bool sp ...
13
#include <bits/stdc++.h> using namespace std; long long n, i, q, j, z, d, k, y, x, m, a, u, b, ans; map<long long, long long> mp; int main() { cin >> n; for (i = 0; i < n; i++) { cin >> x; if (x <= y * 2) z++; else z = 0; m = max(m, z + 1); y = x; } cout << m; return 0; }
4
#include <bits/stdc++.h> const int C = 1 << 21, D = 41, G = 21; int gr[D][D], fcl[2][C], dcl[C], twop[C], LM[C], RM[C], nbits[C], pw[22]; void find_clique(int b, int e, int p, int x) { int i; fcl[x][0] = 1; if (e < b) return; for (i = 1; i < pw[e - b + 1]; i++) { if (fcl[x][pw[RM[i]] ^ i] && fcl[x][pw[LM[i]...
19
#include <bits/stdc++.h> static constexpr size_t maxn = 1000001; static constexpr inline long long gcd(long long x, long long y) noexcept { return y == 0 ? x : gcd(y, x % y); } int a[maxn], b[maxn]; int n, m, y; ::std::vector<int> fail(const std::string &s) { int n = ((int)((s).size())); ::std::vector<int> f(n); ...
21
#include <bits/stdc++.h> using namespace std; long long v[300005]; int lg[300005]; int rmq[20][300005]; struct ura { int l, r, pz; long long s; } qs[300005]; int getmin(int l, int r) { int lgc = lg[r - l + 1]; return min(rmq[lgc][r], rmq[lgc][l + (1 << lgc) - 1]); } int st[300005]; int nxtt[300005]; int nxt[20]...
21
#include <bits/stdc++.h> using namespace std; int main() { int n, s, t; cin >> n >> s >> t; vector<int> v(n); int count = 0; for (int i = 0; i < n; i++) { cin >> v[i]; v[i]--; } int index = s; vector<int> pos; int r = s - 1; t--; for (int i = 0; i < n - 1; i++) { if (r == t) break; ...
4
#include <bits/stdc++.h> using namespace std; int main() { int S, a, b, c; scanf("%d%d%d%d", &S, &a, &b, &c); if (b + c > 0) { double x = S * double(a) / (a + b + c); double y = b * (S - x) / (b + c); double z = S - x - y; printf("%.16lf %.16lf %.16lf\n", x, y, z); } else printf("%d 0 0", S,...
10
#include <bits/stdc++.h> using namespace std; vector<long long> sp[4]; struct node { long long b1, b2, val; } dp[300005]; long long cal(long long t, long long k) { if (k >= sp[t].size()) return 0; return sp[t][k]; } bool cmp(long long a, long long b) { return a > b; } int main() { long long n, m, i, j, w, c; ...
15
#include <bits/stdc++.h> using namespace std; int p[10010], s[10010], n, c; long long f[2][10010], sum = 0; const long long INF = 1LL << 60; int main() { scanf("%d%d", &n, &c); for (int i = 1; i <= n; i++) scanf("%d", &p[i]); for (int i = 1; i <= n; i++) scanf("%d", &s[i]); memset(f[0], 0x3f, sizeof(f[0])), f[0...
21
#include <bits/stdc++.h> using namespace std; int viz[6]; int main() { int n; char color[6][7], name[6][8], stone[7]; strcpy(color[0], "purple"); strcpy(color[1], "green"); strcpy(color[2], "blue"); strcpy(color[3], "orange"); strcpy(color[4], "red"); strcpy(color[5], "yellow"); strcpy(name[0], "Power...
0
#include <bits/stdc++.h> using namespace std; const long long MAX_SIZE = 1e4 + 4; vector<pair<long long, long long>> arr(MAX_SIZE); int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long T, n, m, sz, x, y; string str; cin >> T; for (long long t = 1; t <= T; ++t) { cin >> n >> m;...
7
#include <bits/stdc++.h> using namespace std; void solve() { string s; cin >> s; long long div3 = 0, div2 = 0, div10 = 0; long long sum = 0; for (char c : s) { sum += c - '0'; if ((c - '0') % 2 == 0) div2++; if ((c - '0') == 0) div10++; } div3 = sum % 3 == 0; cout << (div3 && ((div10 == 1 &&...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int deg[maxn]; int main() { int n, m; cin >> n >> m; memset(deg, 0, sizeof deg); for (int i = 0; i < m; i++) { int u, v; scanf("%d%d", &u, &v); deg[u]++, deg[v]++; } if (m > n) { printf("unknown topology\n"); exit(0)...
4
#include <bits/stdc++.h> using namespace std; stack<int> s; int main() { int n; cin >> n; while (!s.empty()) s.pop(); for (int i = 1; i <= n; i++) { int x; cin >> x; if (s.size() && (x - s.top()) % 2 == 0) s.pop(); else s.push(x); } if (s.size() <= 1) cout << "YES"; else ...
14
#include <bits/stdc++.h> using namespace std; const long long INF = LONG_LONG_MAX; const double PI = atan(1) * 4; const int MAXN = 1e6 + 20; const double EPS = 1e-10; int n, m, d; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout << setprecision(2) << fixed; cin >> n >> m >> d...
8
#include <bits/stdc++.h> using namespace std; const long double pi = 3.14159265359; template <typename T> T abs(T x) { return x > 0 ? x : -x; } const int maxn = 2000005; vector<pair<char, int> > to[maxn]; int lnk[maxn], len[maxn], cnt[maxn]; int strict[maxn]; char s[maxn]; int last = 1, sn = 1, sz = 2; void init() { ...
21
#include <bits/stdc++.h> using namespace std; const int N = 1e+5 + 10; vector<int> v[N], res[3]; int col[N]; void dfs(int cur, int num) { if (col[cur] != 0) { if (col[cur] != num) { printf("-1"); exit(0); } return; } col[cur] = num; res[num].push_back(cur); for (auto x : v[cur]) { ...
7
#include <bits/stdc++.h> using namespace std; int main() { long long t1, t2, x1, x2, t0; while (~scanf("%lld %lld %lld %lld %lld", &t1, &t2, &x1, &x2, &t0)) { long long y1, y2; double ans_t = 0x3f3f3f3f, t; while (x1 >= 0 && x2 >= 0) { t = 1.0 * (t1 * x1 + t2 * x2) / (x1 + x2); if (t < t0) {...
11
#include <bits/stdc++.h> using namespace std; const int maxn = (1e6) + 7; const int inf = (1e9) + 7; const long long LLinf = (1e18) + 7; int main() { int n; scanf("%d", &n); if (n < 4) { printf("NO"); return 0; } if (n % 2 == 0) { printf("YES\n4 * 3 = 12\n"); printf("2 * 12 = 24\n"); for (...
7
#include <bits/stdc++.h> using namespace std; template <class T> inline bool rd(T &num) { char in; bool IsN = false; while (in = getchar(), in != '-' && (in < '0' || in > '9')) if (in == EOF) return false; in == '-' ? (IsN = true, num = 0) : num = in - '0'; while (in = getchar(), in >= '0' && in <= '9') n...
16
#include <bits/stdc++.h> using namespace std; int foi[1000002]; int e[1000002]; vector<int> v, nv; int main() { int n; cin >> n; set<int> s; for (int i = 0; i < n; i++) { int e; scanf(" %d", &e); if (s.find(e) == s.end()) { v.push_back(e); s.insert(e); } } int a, b; scanf(" %d ...
14
#include <bits/stdc++.h> using namespace std; long long int XpowerY(long long int x, long long int y, long long int m) { long long int ans = 1; x = x % m; while (y > 0) { if (y % 2 == 1) ans = (ans * x) % m; x = ((x % m) * (x % m)) % m; y = y >> 1; } return ans % m; } long long int dp[20][2048][3]...
15
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 9; long long n, sum, m, k, k2, x, y; vector<long long> g[N]; bool used[N]; void dfs(int v, bool f) { used[v] = 1; if (f == false) k++; else k2++; for (auto to : g[v]) { if (!used[to]) { dfs(to, !f); } } } int main() { io...
5
#include <bits/stdc++.h> using namespace std; const int MAXN = 101; int colo[MAXN], num[MAXN]; int mark[MAXN]; signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; map<char, int> m; m['R'] = 0, m['G'] = 1, m['B'] = 2, m['Y'] = 3, m['W'] = 4; int n; cin >> n; for (int i = 0; i < n; i++) ...
9
#include <bits/stdc++.h> using namespace std; int h, t, R, n, m, h1[300], t1[300], h2[300], t2[300], c[2 * 300][2 * 300], x[300 * 300], y[300 * 300]; void win(string name, int cnt) { cout << name << endl << cnt; exit(0); } void reading() { int i; scanf("%d%d%d%d", &h, &t, &R, &n); for (i = 1; i <= n; i++)...
13
#include <bits/stdc++.h> using namespace std; int bit[100010]; int pos[100010]; long long g[100010]; long long w[100010]; long long n, k; int qtd, p0; void add(int p, int v) { for (; p < 100010; p += (p & (-p))) bit[p] += v; } int get(int p) { int ret = 0; for (; p > 0; p -= (p & (-p))) ret += bit[p]; return re...
14
#include <bits/stdc++.h> using namespace std; const long long mo = 1e9 + 7; template <typename _T> void read(_T &x) { _T f = 1; x = 0; char s = getchar(); while (s > '9' || s < '0') { if (s == '-') f = -1; s = getchar(); } while (s >= '0' && s <= '9') { x = (x << 3) + (x << 1) + (s ^ 48); s ...
20
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int N = 3000; double x[N], y[N]; bitset<3000> conn[N]; int main() { ios::sync_with_stdio(0)...
17
#include <bits/stdc++.h> using namespace std; int N, M, H, K; long long num0, num1, num2; vector<int> graph[100005]; long long dp[100005][11][3]; long long MOD = 1e9 + 7; long long temp[10]; long long mult(long long a, long long b) { return (a % MOD * b % MOD) % MOD; } void dfs(int n, int p) { for (int e : graph[n]) ...
12
#include <bits/stdc++.h> using namespace std; struct lem { int m, v, id; }; bool operator<(const lem &a, const lem &b) { if (a.m != b.m) return (a.m < b.m); return a.v < b.v; } vector<lem> s; int n, k, h, ans[100000], cur[100000]; lem ll; int main(void) { int i, j, p; scanf("%d%d%d", &n, &k, &h); s.reserve(...
12
#include <bits/stdc++.h> int main() { int y; std::cin >> y; int divideri = 1, dividerj = 1, digit, cnt = 0; while (true) { y++; divideri = 1; for (int i = 0; i < 4; i++) { if (i > 0) { divideri *= 10; } digit = (y / divideri) % 10; dividerj = divideri * 10; for ...
0
#include <bits/stdc++.h> using namespace std; template <class T> inline istream& operator>>(istream& str, vector<T>& a) { for (auto& i : a) str >> i; return str; } const long long N = 1e6 + 10, mod = 998244353; long long notPrime[N]; void seive() { for (long long i = 2; i * i < N; i++) { if (notPrime[i] == 0)...
8
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const int mod = 1000000007; const double PI = acos(-1.0); int a[51005]; int b[51005]; int c[51005]; bool vis[51005]; int n, m; int ans; struct node { int x, id; node() {} node(int xx, int i) { x = xx; id = i; } bool operator<(const...
11
#include <bits/stdc++.h> using namespace std; const long long int inf = 0x3f3f3f3f3f3f3f3fll; const int maxx = 3000000; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tt; cin >> tt; for (int ttt = 1; ttt <= tt; ttt++) { long long int s; cin >> s; long long int total = 0; ...
1
#include <bits/stdc++.h> using namespace std; int n, len, q[2100], p[2100]; unsigned long long a[2100][40], s[700], b[2100][40]; char str[700]; int get(int i, int j) { return (a[i][j / 60] >> (j % 60)) & 1; } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%s", str); len = strlen(str); ...
19
#include <bits/stdc++.h> using namespace std; const int maxn = 5e3 + 10; bool f[maxn][maxn]; int dp[maxn][maxn]; string s; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> s; for (int i = 0; i < s.size(); i++) { int j = 0; while (i - j >= 0 and i + j < s.size()) { if (s[i - j] != ...
10
#include <bits/stdc++.h> using namespace std; int main() { int n, d, temp, sum = 0; cin >> n >> d; for (int i = 0; i < n; i++) { cin >> temp; sum += temp; } if (d >= sum + 10 * (n - 1)) { cout << (d - sum) / 5 << endl; } else { cout << -1 << endl; } }
1
#include <bits/stdc++.h> using namespace std; int main(int argc, char *argv[]) { int n, h; cin >> n; cin >> h; cout << "YES" << endl; for (int i = 0; i < n; ++i) { cout << "."; } cout << endl; vector<char> x; x.push_back('.'); for (size_t i = 1; i < n / 2; ++i) { if (h >= 2) { x.push_b...
8
#include <bits/stdc++.h> using namespace std; int a[1010][1010]; int n; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) scanf("%d", a[i] + j); int S = 0; for (int i = 0; i < n; i++) S += a[i][i]; S %= 2; int q; scanf("%d", &q); for (int i = 0; i < q; i++) { ...
8
#include <bits/stdc++.h> using namespace std; const long double pi = 4.0 * atan(1.0); long long P = 1 << 19; long long K = 0; struct base { double x, y; base() { x = 0; y = 0; } base(double a) { x = a; y = 0; } base(double a, double b) { x = a; y = b; } base conj() { return base(...
15
#include <bits/stdc++.h> using namespace std; const int infi = 1e9; const long long int infl = 1e18; const int MOD = 1e9 + 7; long long int log_2(long long int n) { return (n > 1ll) ? 1ll + log_2(n / 2) : 0ll; } inline void add(long long int &a, long long int b) { a += b; if (a >= MOD) a -= MOD; } inline void sub...
2
#include <bits/stdc++.h> using namespace std; const int adj[8][2] = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}, {-1, -1}, {-1, 1}, {1, 1}, {1, -1}}; const long long int LLINF = 9e18; const int INF = 2e9; const int MOD = 1e9 + 7; const double EPS = 1e-10; const double PI = acos(-1); const int SIZE = 10000...
10
#include <bits/stdc++.h> using namespace std; const int K = 5005, M = 998244353; long long dp[K][K]; long long power(long long a, long long p) { long long ans = 1; while (p) { if (p & 1) ans = (ans * a) % M; a = (a * a) % M; p >>= 1; } return ans; } int main() { ios::sync_with_stdio(false); cin....
18
#include <bits/stdc++.h> using namespace std; int M; int total; int X[200]; int Y[200]; long long c[2000][2000]; long long f[200][2000]; bool caled[200][2000]; const long long moder = 1000000007; long long getF(int nowPosi, int remain) { if (nowPosi == M) { if (remain == 0) return 1; else return 0...
15
#include <bits/stdc++.h> using namespace std; template <typename T> void R(T &x) { x = 0; char ch = getchar(); while (ch < '0' || '9' < ch) ch = getchar(); while ('0' <= ch && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); } void write(long long x) { if (x < 0) x = -x, putchar('-'); if (x > 9) write(x / ...
23
#include <bits/stdc++.h> using namespace std; const int MN = 1011; const int inf = 1000111000; const int di[] = {-1, 1, 0, 0}; const int dj[] = {0, 0, -1, 1}; int m, n; char a[MN][MN], b[MN][MN]; bool visited[MN][MN]; int first[MN][MN], last[MN][MN], sum[MN][MN]; void rotate() { for (int i = (1), _b = (m); i <= _b; i...
13
#include <bits/stdc++.h> using namespace std; struct element_type { element_type(unsigned long a, unsigned long b, unsigned long ix) : a(a), b(b), ix(ix) {} unsigned long a, b, ix; }; class OrderAbsolute { public: bool operator()(const element_type* l, const element_type* r) const { if (l->b < r->b) re...
14
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; int n, m, k; int dx[6] = {0, 0, 0, 0, 1, -1}; int dy[6] = {1, -1, 0, 0, 0, 0}; int dz[6] = {0, 0, -1, 1, 0, 0}; int ans; bool used[55][55][55]; char a[55][55][55]; void dfs(int x, int y, int z) { used[x][y][z] = true; if (a[x][y][z] == '#') retu...
6
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[n], sum = 0; for (int i = 0; i < n; i++) { cin >> arr[i]; sum += arr[i]; } if (sum % n) { cout << "Unrecoverable configuration."; } else { int cnt = 0, more = 0, morecup, les = 0, lesscup; for (int i = ...
5
#include <bits/stdc++.h> using namespace std; vector<int> x, edge[100005]; int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < m; i++) { int a, b; scanf("%d%d", &a, &b); edge[a].push_back(b); edge[b].push_back(a); } for (int i = 1; i <= n; i++) x.push_back(i); for (int t = 0; t...
16
#include <bits/stdc++.h> using namespace std; const int N = 2001; int a[N], c[N], n, k; int main() { cin >> n >> k; queue<pair<int, int>> q; vector<int> v; for (int i = 0, j; i < k; i++) { scanf("%d", &j), j += 1000 - n; if (!c[j]) c[j] = a[j] = 1, q.push({j, 1}), v.push_back(j); } for (int j; !q.em...
15
#include <bits/stdc++.h> using namespace std; const int MAX = 1 << 17; char s[MAX]; int main() { int n; scanf("%s", s); n = (int)strlen(s); int st = 0; for (int i = 0; i < n; i++) { if (s[i] != 'a') { st = 1; s[i]--; } else if (st) break; } if (!st) s[n - 1] = 'z'; printf("%s\n...
4
#include <bits/stdc++.h> using namespace std; using ll = long long int; using ld = long double; using pi = pair<int, int>; const double PI = acos(-1.0); const double eps = 1e-9; const ll mod = 1e9 + 7; const int inf = 1e7; const int MAXN = 1e5 + 5; vector<vector<int>> adj; vector<int> depth; void dfs(int u, int par, in...
14
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int n, q = 4127, x = 0, Equal = 0; cin >> n; pair<int, int> p[n]; for (int i = 0; i < n; i++) { cin >> p[i].first >> p[i].second; if (q >= p[i].first) { x++, q = p[i].first; } if ...
1
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, m; long long normalTurns, ans = 1e14, d1, d2; bitset<N> visit; int dat[N]; vector<int> graph[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i = 0; i < m; i++) { cin >> dat[i]; i...
10
#include <bits/stdc++.h> using namespace std; map<signed long long int, int> ass; int occ[100000 + 5], tree[100000]; signed long long int a[100000 + 5], b[100000 + 5]; int read(int idx) { int sum = 0; while (idx > 0) { sum = max(tree[idx], sum); idx -= (idx & -idx); } return sum; } void update(int idx, ...
7
#include <bits/stdc++.h> using namespace std; int n; const int p = 1000000007; vector<long long> pows; void make(int m) { pows.resize(m + 100); pows[0] = 1; for (int i(1); i != pows.size(); ++i) pows[i] = (pows[i - 1] * 2) % p; } long long pow(long long x, long long n) { if (n == 0) return 1; if (n == 1) retu...
9
#include <bits/stdc++.h> int col[4] = {1, 0, -1, 0}; int row[4] = {0, 1, 0, -1}; using namespace std; int n, m, d[111][111]; string ar[111]; bool vis[111][111]; struct data { int a, b, c, d; data() {} data(int _a, int _b, int _c, int _d) { a = _a; b = _b; c = _c; d = _d; } }; bool bfs(int _x, in...
7
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; int pw(int x, int y) { int res = 1; while (y) { if (y & 1) res = 1ll * res * x % mod; x = 1ll * x * x % mod; y >>= 1; } return res; } const int N = 1000; int n; char s[N + 5]; int fa[4 * N + 3]; int id(int x, int y, int z) { re...
16
#include <bits/stdc++.h> using namespace std; int main() { long long n, k, m; scanf("%lld %lld %lld", &n, &k, &m); vector<pair<int, long long> > b; for (int i = 0; i < n; i++) { int x; scanf("%d", &x); if (b.size() && b.back().first == x) { if (++b.back().second == k) b.pop_back(); } else ...
15
#include <bits/stdc++.h> using namespace std; template <typename T> inline T gcd(T a, T b) { if (b == 0) return a; else return gcd(b, a % b); } template <typename T> inline T lcm(T a, T b) { return (a * b) / gcd(a, b); } int n, m, q; long long ar[105][105], deff[105][105]; void REV(int x, int r) { if (x...
6
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; long long k; cin >> k; string s; cin >> s; stack<long long> st; long long index = 0; map<long long, long long> mp; for (long long i = 0; i < s.length(); i++) { if (s[i] == '(') { ...
7
#include <bits/stdc++.h> using namespace std; int n, a[300004]; string s; bool canCut(int idx) { bool ret = true; string w = s.substr(idx, n - idx); w += s.substr(0, idx); for (int i = 0; i < n; i++) if (s[i] != w[i]) ret = false; if (ret) return false; ret = true; for (int i = 0; i < n / 2; i++) ...
10
#include <bits/stdc++.h> using namespace std; int main() { int t; scanf("%d", &t); while (t--) { int begin = 0, end = 0; char a[150]; scanf("%s", a); for (int i = 0; i < strlen(a); i++) { if (a[i] == '1') { begin = i; break; } } for (int i = strlen(a) - 1; i >= ...
0
#include <bits/stdc++.h> const int maxn = 2e6 + 1; const int maxm = 1e5 + 10; const long long int mod = 1e9 + 7; const long long int INF = 1e18 + 100; const int inf = 0x3f3f3f3f; const double pi = acos(-1.0); const double eps = 1e-8; using namespace std; multiset<long long int> va, vb, vall; int main() { int n, m; ...
8
#include <bits/stdc++.h> using namespace std; const int mx = 2e5 + 10; vector<int> v; vector<int>::iterator it; long long cnt[4 * mx], ltor[4 * mx], rtol[4 * mx], fen[mx], remain, cntnow, a[mx], b[mx], q[mx], ps[mx], val[mx], l[mx], r[mx]; int pos(int x) { return lower_bound(v.begin(), v.end(), x) - v.begin(); } vo...
17
#include <bits/stdc++.h> using namespace std; char sss[105]; int vex[200005], oddd[200005]; int main() { int n; cin >> n; while (n--) { int a, b, odd = 0; cin >> a >> b; for (int i = 0; i < a; i++) { cin >> vex[i]; if (vex[i] % 2 == 1) { oddd[odd++] = i; } } if (odd <...
4
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; bool flag = true; vector<unsigned int> a, e, o; for (int i = 0; i < n; ++i) { unsigned int k; cin >> k; a.push_back(k); } int len = a.size(), mid = len / 2; sort(a.begin(), a.end()); for (int i = 0; i < mid; ++i) {...
2
#include <bits/stdc++.h> using namespace std; string s; long long m, n, x, y, z, t; map<long long, long long> cnt; void add() { long long sz = s.size(); long long temp = 1; long long r = 0; for (long long i = sz - 1; i >= 0; i--) { long long p = s[i] - '0'; p = p % 2; r += p * temp; temp = temp ...
6
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int tr[21][maxn << 2][2], a[maxn], lz[21][maxn << 2]; void pushup(int k, int rt) { tr[k][rt][0] = tr[k][rt << 1][0] + tr[k][rt << 1 | 1][0]; tr[k][rt][1] = tr[k][rt << 1][1] + tr[k][rt << 1 | 1][1]; } void pushdown(int k, int rt) { if (lz[k][...
12
#include <bits/stdc++.h> using namespace std; const int maxn = 1000 + 5; int a[maxn], t[maxn], pre[maxn], suf[maxn]; int main() { int ans1 = 0, ans2 = 0, n, c; cin >> n >> c; for (int i = 1; i <= n; ++i) { cin >> a[i]; } for (int i = 1; i <= n; ++i) { cin >> t[i]; pre[i] = pre[i - 1] + t[i]; } ...
0
#include <bits/stdc++.h> using namespace std; template <typename T = long long> inline T read() { T s = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { s = (s << 3) + (s << 1) + ch - 48; ch = getchar(); } return s * f; } ...
15
#include <bits/stdc++.h> using namespace std; const int N = 1234567; char s[N]; int next_NL_ND[N]; int next_NL[N]; int last_NL_ND_NU[N]; int sum_L[N]; int main() { scanf("%s", s + 1); int n = strlen(s + 1); next_NL_ND[n + 1] = n + 1; for (int i = n; i >= 1; i--) { if (('a' <= s[i] && s[i] <= 'z') || ('0' <=...
11
#include <bits/stdc++.h> using namespace std; int n; int main() { scanf("%d", &n); printf("%d\n", n * n + 1 >> 1); for (int i = 0; i < n; i++, printf("\n")) for (int j = 0; j < n; j++) printf("%c", (i + j) % 2 ? '.' : 'C'); return 0; }
0
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const double EPS = 1e-9; const int MOD = 1e9 + 7; const int INF = 1e9 + 10000; const long long INFLL = 4e18; const int dr[] = {-1, 0, 1, 0, -1, 1, 1, -1}; const int dc[] = {0, 1, 0, -1, 1, 1, -1, -1}; set<int> one, zero; vector<vector<int> > an...
8
#include <bits/stdc++.h> using namespace std; const int maxn = 2000; string s[maxn]; int ss[maxn], tt[maxn]; int pp[maxn], ff[maxn]; int main() { int n; cin >> n; for (int i = 0; i < n; ++i) { cin >> s[i]; } int cnt = 0; for (int i = 0; i < n - 1; ++i) { for (int j = 0; j <= i; ++j) { int y = ...
12
#include <bits/stdc++.h> using namespace std; map<string, int> mp, mp1; int ar[1002], ar1[1002], m, j; string st[1002]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> st[i] >> ar[i]; mp[st[i]] += ar[i]; } for (int i = 0; i < n; i++) { m = max(m, mp[st[i]]); } for (int i = 0...
7
#include <bits/stdc++.h> using namespace std; int main() { string s; int n, p = 1, cnt; cin >> n; cnt = n; cin >> s; for (int i = 0; i < n - 2; i++) { if (s[i] == 'x' && s[i + 1] == 'x' && s[i + 2] == 'x') { for (int j = i; j <= n - 1; j++) s[j] = s[j + 1]; n--; p = 0; i--; }...
0