solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 105000;
int n, x;
int a[MAXN];
void solve() {
scanf("%d %d", &n, &x);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
int ans = 2e9;
for (int i = 0; i < n; i++) {
if (a[i] == x) {
ans = min(ans, 1);
} else {
int cur = m... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 100010;
const int MOD = 1000000007;
int n;
int dp[1010];
int to[1010];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
int x;
scanf("%d", &to[i]);
}
dp[0] = -1;
for (int i = 1; i <= n; i++) {
in... | 8 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double e = exp(1.0);
const double eps = 1e-8;
const int maxlen = 100005;
char str[maxlen];
bool compare(int x1, int y1, int x2, int y2);
int main() {
ios::sync_with_stdio(false);
while (~scanf("%s", str)) {
int len = strlen(str);
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long BITS = 20;
string ans[2] = {"Fou", "Shi"};
long long nextForBit[BITS];
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long n, q;
cin >> n >> q;
long long a[n];
for (long long i = 0; i < n; i++) cin >> a[i]... | 14 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void test(T a) {
cout << a << endl;
}
template <class T, class T2>
void test(T a, T2 b) {
cout << a << " " << b << endl;
}
template <class T, class T2, class T3>
void test(T a, T2 b, T3 c) {
cout << a << " " << b << " " << c << endl;
}
const int N =... | 14 |
#include <bits/stdc++.h>
const int MOD = 1000000007;
int n;
char sa[100010];
char sb[100010];
char temp[100010];
int rcd[100000][4];
long long dp(int t, int st) {
if (t == n) {
if (st == 3)
return 1;
else
return 0;
}
if (rcd[t][st] != -1) return rcd[t][st];
long long ret = 0;
if (sa[t] == ... | 12 |
#include <bits/stdc++.h>
const unsigned long long inf = 1LL << 61;
const double eps = 1e-5;
using namespace std;
bool cmp(int a, int b) { return a > b; }
int main() {
int n;
string s;
while (cin >> n) {
cin >> s;
for (int i = 1; i <= 510; i++) s += ".";
for (int len = 1; len <= n; len++) {
for (... | 5 |
#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
inline int read() {
char c = getchar();
int x = 0;
bool f = 0;
for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45);
for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
if (f) x = -x;
return x;
}
int n, t, k, c;
int a[200... | 13 |
#include <bits/stdc++.h>
using namespace std;
int t;
int n, m;
int a_arr[101];
bool p_arr[101];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> t;
while (t--) {
cin >> n >> m;
memset(p_arr, false, sizeof(p_arr));
memset(a_arr, 0, sizeof(a_arr));
for (int i = 0; i < n; i++) {... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int modulo = 1077563119;
int Chromatic(const vector<int> &g) {
int n = g.size();
if (n == 0) return 0;
int all = 1 << n;
vector<int> a(all), s(all);
a[0] = 1;
for (int i = 1; i < all; i++) {
int j = __builtin_ctz(i);
a[i] = a[i - (1 << j)] + a[(i -... | 23 |
#include <bits/stdc++.h>
using namespace std;
const int N = 11, P = 1e6 + 3;
int x[N], a[N][N], b[N];
inline int ksm(int a, int b) {
int c = 1;
while (b) {
if (b & 1) c = (long long)c * a % P;
a = (long long)a * a % P;
b >>= 1;
}
return c;
}
inline int f(int k) {
int ans = 0;
for (int i = 0; i <... | 14 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1LL << 61;
const long long mod = 1000000007;
int main() {
std::ios::sync_with_stdio(false);
int n;
cin >> n;
if (n % 10 == 0)
cout << n << endl;
else {
int a = n / 10 * 10;
int b = a + 10;
if (b - n < n - a)
cout << b <<... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int m[N];
int c[N];
int n;
int x1, x2;
vector<pair<long long, long long> > v;
int main() {
scanf("%d", &n);
scanf("%d %d", &x1, &x2);
for (int i = 1; i <= n; ++i) {
scanf("%d %d", m + i, c + i);
}
for (int i = 1; i <= n; ++i) {
v.emp... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
string s;
cin >> s;
int n = s.length();
int q;
cin >> q;
set<int> m[26];
for (int i = 0; i < n; i++) {
m[s[i] - 'a'].insert(i + 1);
}
while (q--) {
int x;
cin >> x;... | 8 |
#include <bits/stdc++.h>
using namespace std;
double solve(double v0, double a, double d, double vm, double vl) {
double tt = (vl - v0) / a;
double dd = (v0 + vl) * tt / 2;
if (dd >= d) {
return (-v0 + sqrt(v0 * v0 + 2 * a * d)) / a;
} else {
double ttt = (vm - vl) / a;
double ddd = dd + (vl + vl + ... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int T = 100000;
int a[100005], b[100005], Q[100005], opt[100005], n, m, i, j, k, id, debug;
long long pos, start, now;
set<pair<long long, int> > S;
int main() {
scanf("%d", &m);
for (i = 1; i <= m; i++) {
scanf("%d%d", &opt[i], &a[i]);
if (opt[i] == 2) sc... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
set<int> indices;
for (int i = 0; i < n; i++) {
indices.insert(i);
}
vector<pair<int, int> > arr(n);
for (int i = 0; i < n; i++) {
cin >> arr[i].first;
arr[i].second... | 5 |
#include <bits/stdc++.h>
using namespace std;
int solve(int n, int m, int a, int b) {
if (m == 1) return 1;
--a;
--b;
int la = a / m;
int lb = b / m;
if (la == lb) return 1;
if (b == n - 1) {
if (a % m == 0) return 1;
return 2;
}
if (b % m == m - 1 && a % m == 0) return 1;
if (la + 1 == lb |... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, k;
cin >> n >> k;
long long int i;
map<long long int, long long int> m;
long long int r;
for (i = 1; i <= k; i++) {
r = n % i;
m[r]++;
if (m[r] > 1) {
cout << "NO" << endl;
return 0;
}
}
cout << "YES"... | 8 |
#include <bits/stdc++.h>
using namespace std;
int dp[300];
int carpet[300][300];
void parse(int n, int m) {
for (int r = 0; r < n; ++r) {
string lines[4];
for (int i = 0; i < 4; ++i) getline(cin, lines[i]);
for (int k = 0; k < m; k++) {
int cnt = 0;
for (int s = 1; s <= 3; s++)
for (in... | 15 |
#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-2;
long double dist(pair<long double, long double> p1,
pair<long double, long double> p2) {
return hypot(p1.first - p2.first, p1.second - p2.second);
}
long double pdist(pair<long double, long double> p1,
pair<... | 11 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
inline bool lt(double a, double b) { return a + eps < b; }
inline bool eq(double a, double b) { return !lt(a, b) && !lt(b, a); }
int n, s[1002];
double A, B, lo, hi, mid;
int next(double mid) {
double x = mid;
int nxt = 0;
for (int i = 0; i < ... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e5 + 5, maxm = 1005;
inline void chkmin(long long &x, long long y) { x = x < y ? x : y; }
inline long long read() {
char c = getchar();
long long ans = 0, f = 0;
for (; c < '0' || c > '9'; c = getchar()) f |= (c == '-');
for (; c >= '0' && c ... | 14 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
using namespace std;
long long MOD = 1000000007;
double eps = 1e-12;
long long modu(long long a, long long b, long long c) {
if (b == 0) return 1;
if... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, a, b, c;
cin >> n;
a = n / 7;
a *= 2;
if (n % 7 == 0) {
b = a;
c = a;
}
if (n % 7 == 1 || n % 7 == 2 || n % 7 == 3 || n % 7 == 4 || n % 7 == 5) {
b = a;
}
if (n % 7 == 6) {
b = a + 1;
}
if (n % 7 == 1) {
... | 1 |
/*
* author: AlexXan312
* good luck
*/
#include <iostream>
#include <fstream>
#include <functional>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <list>
#include <bit... | 2 |
#include <bits/stdc++.h>
using namespace std;
struct point {
int x, y;
};
point d[222222], e[222222];
int n, m, ans = 0, sum[222222];
bool cmp(point u, point v) {
return (u.x < v.x) || ((u.x == v.x) && (u.y < v.y));
}
bool found(point u) {
int low = 1, high = n, mid;
while (low + 1 < high) {
mid = (low + hi... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int maxx = 2e5 + 10;
const int inf = 1e9;
int a[maxx], b[maxx], n;
struct S {
int num, val;
int left, right;
} tree[maxx * 5];
void pushup(int k) {
tree[k].val = min(tree[k << 1].val, tree[k << 1 | 1].val);
}
void build(int k, int l, int r) {
tree[k].left = l,... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n,k;
inline bool ck(int i,int j,string&a,string&b){
int l=0,r=k-1,u=0,v=0;
while(a[l]==b[l])l++;
while(a[r]==b[r])r--;
for(;l<r&&!(u&v);l++)u|=(a[l+1]<a[l]),v|=(b[l+1]<b[l]);
return!(u&v);
}
int main(){
cin>>n;
string s,h;
map<string,vector<string>>mp;
long... | 22 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, p, head = 1, tail = 0, d, j, k;
long long dis[100050], a[100050], q[100050], dp[110][100050], s[100050],
g[100050];
signed main() {
scanf("%lld%lld%lld", &n, &m, &p);
for (long long i = 2; i <= n; i++) scanf("%lld", &d), dis[i] = dis[i - 1] + d;
fo... | 16 |
#include <bits/stdc++.h>
using namespace std;
vector<int> a;
map<vector<int>, double> mp[10];
double getans(vector<int> a, int rem) {
int n = a.size(), i, j;
if (rem == 0) {
int cnt = 0;
for (i = 0; i < n; i++) {
for (j = 0; j < i; j++) {
cnt += (a[j] > a[i]);
}
}
return cnt;
}... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long c, hr, hb, wr, wb;
cin >> c >> hr >> hb >> wr >> wb;
long long ans = 0ll;
if (wr * wr >= c) {
for (long long a = 0ll; a * wr <= c; ++a) {
long long b = (c - a * wr) / wb;
ans = max(ans, a * hr + b * hb);
}
} else if (wb *... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int MX = 1e5 + 5;
const int mod = 1e9 + 7;
const int INF = 2e9 + 5;
struct node {
int x, num, ans;
} a[MX];
bool cmp1(node a, node b) { return a.x < b.x; }
bool cmp2(node a, node b) { return a.num < b.num; }
int main() {
int n, k;
scanf("%d%d", &n, &k);
int ne... | 6 |
#include <bits/stdc++.h>
using namespace std;
int dp[5000100];
string s;
long long prime = 3;
int main() {
ios::sync_with_stdio(0);
cin.tie();
cin >> s;
long long l = 0, r = 0, p = 1, ans = 0;
for (int i = 1; i <= s.size(); i++) {
l = l * prime + s[i - 1];
r = r + p * s[i - 1];
p *= prime;
if ... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
bool comp(pair<long long, long long> p, pair<long long, long long> q) {
if (p.first != q.first)
return p.first < q.first;
else
return p.second > q.second;
}
long long power(long long a, long long n) {
long long res = 1;
while (n) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 2;
int n, m;
int viz[N], aux[N], c[N], id[N];
vector<int> meh;
vector<int> g[N];
vector<pair<int, int> > v[N];
bool Loop2(int x) {
if (viz[x] == 1) return 1;
if (viz[x] == 2) return 0;
viz[x] = 1;
for (auto &it : g[x]) {
if (Loop2(it)) return... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string s;
cin >> s;
int a, b;
cin >> a >> b;
const int n = s.size();
int prefix[n], suffix[n];
memset(prefix, 0, sizeof(prefix));
memset(suffix, 0, sizeof(suffix));
for (in... | 9 |
#include <bits/stdc++.h>
using namespace std;
struct Node {
int val;
int qP;
struct Node *p1, *p2, *p3, *p4, *par;
};
const int base = (1 << 24);
Node *root;
struct Data {
int x1, y1, x2, y2, z, ind;
bool operator<(const Data &a) const { return z < a.z; }
};
int n;
Data data[100000];
int ans[100000];
queue<in... | 17 |
#include <bits/stdc++.h>
using namespace std;
static int dp[2000][300];
int main() {
int n, k;
scanf("%d", &n);
scanf("%d", &k);
vector<pair<int, int> > v;
if (n < 2 * k + 1) {
printf("-1\n");
return 0;
} else {
printf("%d\n", n * k);
for (int i = 1; i <= n; i++) {
int j = i + 1;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
if (a < b) {
int t = a;
a = b;
b = t;
}
while (b) {
int M = a % b;
a = b;
b = M;
}
return a;
}
int flag[100000];
int main() {
int n;
int a[100000];
int c[100000];
while (cin >> n) {
for (int i = 0; i < n;... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int v;
node *l, *r, *u, *d;
} M[1005][1005];
int n, m, q, a, b, c, d, h, w;
int main() {
scanf("%d%d%d", &n, &m, &q);
for (int i = 1; i <= n; i++) M[i][0].r = &M[i][1];
for (int i = 1; i <= n; i++) M[i][m + 1].l = &M[i][m];
for (int i = 1; i <= m; ... | 17 |
#include <bits/stdc++.h>
using namespace std;
string second, t, r = "";
long long n, m, k;
long long lcp[2105][2105], lcp_prev[2105][2105];
pair<long long, long long> ans[2105];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> second >> t;
n = second.length();
m = t.length();
for (long long... | 12 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<long long>;
void solve() {
int K, N;
cin >> K >> N;
int cnt = 0;
... | 2 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
using namespace std;
const int N = 1e5 + 2;
int o[3];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int s;
cin >> s;
vector<pair<int, int> > v;
int sum = 0;
for (int i = int(0); i < int(3); ++i) {
int x;
ci... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b;
cin >> a >> b;
long long x = 1;
while ((1 + x + 1) * (x + 1) / 2 <= a + b) {
x++;
}
vector<long long> d1, d2, ds(x + 1);
for (long long i = 1; i < x + 1; i++) {
ds[i] = i;
}
for (long long i = x; i > 0; i--) {
if (a... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, p, q, x = 0, y = 0;
cin >> n >> k;
p = n, q = 2 * n;
for (int i = 1; i <= k; i++) {
int j;
cin >> j;
int d = min(j / 4, p);
p -= d;
j -= 4 * d;
y += j / 2;
x += j % 2;
}
for (; y >= 0; y--, x += 2) {
if (y >... | 11 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T abs(T x) {
return x > 0 ? x : -x;
}
int n;
int m;
double g[1001][1001], w[1001][1001];
int main() {
int n, m, p, q;
scanf("%d%d%d%d", &n, &m, &p, &q);
p--;
q--;
p = n - p;
for (int i = 1; i < p; i++) {
for (int j = 0; j < m; j++) {
... | 16 |
#include <bits/stdc++.h>
using namespace std;
string grid = ".........";
map<string, string> ans;
bool win(string s, char c) {
for (int i = 0; i < 3; i++) {
if (s[3 * i] == c and s[3 * i + 1] == c and s[3 * i + 2] == c) return 1;
if (s[i] == c and s[i + 3] == c and s[i + 6] == c) return 1;
}
if (s[0] == c... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 105;
long long inv[MAX_N], fac[MAX_N], finv[MAX_N];
void make() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX_N; i++) {
inv[i] = 1000000007 - inv[1000000007 % i] * (1000000007 / i) % 1000000007;
fac[i] = ... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 10005, MAXM = 2005;
bool Q[MAXN];
vector<int> E[MAXN];
char s[MAXM][MAXM];
int Num[MAXN][3], Bel[MAXN], Ch[MAXN], cnt, N, tot, root, cur;
void Dfs(int Cur) {
Num[Cur][0] = Num[Cur][1] = Num[Cur][2] = 0;
if (Cur <= N) {
Bel[Cur] = (s[cur][Cur] == '1'... | 22 |
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> v;
int n, a, k = 0, p = 0, i;
cin >> n;
for (i = 1; i <= n; i++) {
cin >> a;
if (a < 0 && k > 1) v.push_back(p), p = k = 0;
p++;
if (a < 0) k++;
}
if (p) v.push_back(p);
cout << v.size() << endl;
for (i = 0; i < v.siz... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long int MOD = 1000000007;
long long int inf = 1e15;
void scan(int &x);
long long int powermod(long long int _a, long long int _b, long long int _m) {
long long int _r = 1;
while (_b) {
if (_b % 2 == 1) _r = (_r * _a) % _m;
_b /= 2;
_a = (_a * _a) % _m;... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 100 + 9;
int n;
int a[maxN];
bool moved[maxN];
void read() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
}
void solv() {
a[0] = 0;
a[n + 1] = 1001;
int cnt = 0;
for (int i = 0; i <= n; i++) {
if (moved[i]) continue;
int j = i;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000 + 10;
bool arr[MAXN][MAXN], mark[2][MAXN];
int dist[2][MAXN];
int n, m;
void bfs() {
queue<pair<int, int> > q;
q.push(make_pair(0, 0));
mark[0][0] = true;
while (!q.empty()) {
pair<int, int> v = q.front();
q.pop();
for (int i = 0; i... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n;
int x, y;
vector<int> v[1000086];
int dep[1000086], son[1000086];
void dfs1(int i, int fa) {
for (int j = 0; j < v[i].size(); j++) {
int to = v[i][j];
if (to == fa) continue;
dfs1(to, i);
if (!son[i] || dep[to] > dep[son[i]]) son[i] = to;
}
if (... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int md = 1e6 + 10;
int counter = 0;
int n, a[301000], p[300100];
struct trie {
struct trie* lft;
struct trie* rht;
int cnt;
};
struct trie* newTrie() {
struct trie* tmp = (struct trie*)(malloc(sizeof(struct trie*)));
tmp->lft = NULL;
tmp->rht = NULL;
tmp... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, x;
cin >> n >> x;
vector<int> a(n);
vector<int> b(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
}
sort(a.rbegin(), a.rend()... | 0 |
#include <bits/stdc++.h>
using namespace std;
string s;
long long int n, c = 1, a = 1;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> s;
if (s == "UR" or s == "DL") {
c++;
}
if (s == "UL" or s == "DR") {
a++;
}
if (s == "ULDR") {
c++;
a++;
}
}
co... | 9 |
#include <bits/stdc++.h>
using namespace std;
int sig(double x) { return (x > 1e-8) - (x < -1e-8); }
struct P {
double x, y;
P(double a = 0, double b = 0) : x(a), y(b) {}
P operator+(const P &a) const { return P(x + a.x, y + a.y); }
P operator-(const P &a) const { return P(x - a.x, y - a.y); }
P operator*(con... | 14 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int inf = 1e9;
const int N = 40005;
int main() {
ios_base::sync_with_stdio(0);
int n;
cin >> n;
string s, res = "";
cin >> s;
for (int i = 0; i < s.size(); i++) {
int k = 0;
char c = s[i];
if (s[i] == 'a' || s[i] ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
multiset<int> st;
for (int i = 0; i < n; i++) {
int b;
cin >> b;
st.insert(b);
}
multiset<int>::iterator it... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t, a, b, c, d, i, j, k, l, m, n, x, y, p;
map<long long int, long long int> dp;
set<long long int> e;
cin >> n;
long long int h[n + 5];
for (i = 0; i < n; i++) {
cin >> h[i];
e.insert(h[i]);
dp[h[i]]++;
}
vector<long lo... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, q;
cin >> n >> q;
vector<vector<bool> > g(2, vector<bool>(n));
int x = 0;
for (int i = 0; i < q; i++) {
int ri, ci;
cin >> ri >> ci;
ri -= 1;
ci -= 1;
bool old = g[ri][ci], nw = !g[ri][ci];
g[ri][ci] = nw;
for (int j... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 20;
const int MOD = 1e9 + 7;
priority_queue<pair<long long int, int> > pq;
vector<pair<long long int, long long int> > vp;
map<long long int, long long int> mp, mpp;
long long int dp[N];
vector<long long int> v, v1, v2;
stack<long long int> s, s1;
long lo... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char a[100], b[100];
gets(a);
gets(b);
int a1 = 0, a2 = 0;
for (int i = 0; i < strlen(a); i += 2) {
if (a[i] == '8' && a[i + 1] == '<') {
if (b[i] == '(' && b[i + 1] == ')') a2++;
if (b[i] == '[' && b[i + 1] == ']') a1++;
}
if ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e4 + 20;
int n, a, num;
vector<int> ve;
int ans[4][4];
bool in[12];
int sum[9];
bool ch() {
int last = 0;
memset(sum, 0, sizeof(sum));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) sum[last] += ans[i][j];
++last;
}
for (int i = 0... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }
void solve() {
long long n;
cin >> n;
long long a[n];
for (long long i = 0; i < n; i++) {
cin >> a[i];
}
fo... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool upmin(T &x, T y) {
return y < x ? x = y, 1 : 0;
}
template <typename T>
inline bool upmax(T &x, T y) {
return x < y ? x = y, 1 : 0;
}
const long double eps = 1e-11;
const long double pi = acos(-1);
const int oo = 1 << 30;
const long lon... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int c = 0, b = 1;
int i;
for (i = 1; c <= (240 - k); i++) {
c += (5 * i);
}
cout << min(i - 2, n) << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const long long MILLER_RABIN = 3215031751;
const long double PI = acos(-1);
struct config_io {
config_io() {
cin.tie(nullptr);
cout.tie(nullptr);
ios_base::sync_with_stdio(false);
}
} cnf_io;
inline void tobin(long long x) { cout << bitset<63>(x) << endl; }
... | 8 |
#include <bits/stdc++.h>
const int maxn = 300010;
int ls[maxn * 50], rs[maxn * 50], tree[maxn * 50], lazy[maxn * 50], tot, n, q,
l, r, k, mn, mx, ow;
template <typename T>
inline T read(T& x) {
x = 0;
int _f = 0;
char ch = getchar();
while (ch < '0' || ch > '9') _f |= (ch == '-'), ch = getchar();
while (c... | 15 |
#include <bits/stdc++.h>
using namespace std;
int a[200005], b[200005], c[400005], n, m;
int ok1(int x);
int ok2(int x);
int main() {
int num = 1;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
c[num++] = a[i];
}
scanf("%d", &m);
for (int i = 1; i <= m; i++) {
scanf("%d", &b... | 8 |
#include <bits/stdc++.h>
int n;
int main() {
scanf("%d", &n);
printf("%d", 1 + 6 * n * ~-n);
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
const int a[] = {0, 0, 1, 1, 1, 2, 1, 1, 14, 8, 4, 2, 41,
13, 21, 1, 22, 4, 19, 19, 4, 2, 1, 16, 13, 4,
35, 19, 4, 2, 41, 4, 87, 41, 115, 2, 59, 31, 49,
8, 28, 4, 31, 44, 50, 13, 151, 16, 91, 56, 14}... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1e5;
int n, m, a, b, s[MaxN + 5], p[MaxN + 5];
long long ans1, ans2, x, y;
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%d", &s[i]);
scanf("%d%d", &a, &b);
for (int i = 1; i <= a; i++) scanf("%d", &p[i]);
ans1 += s[n];
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double n;
cin >> n;
long long ans =
(n - 4) * (n - 3) * (n - 2) * (n - 1) * n / 120 +
(n - 5) * (n - 4) * (n - 3) * (n - 2) * (n - 1) * n / (120 * 6) +
(n - 6) * (n - 5) * (n - 4) * (n - 3) * (n - 2) * (n - 1) * n /
(120 * 6 * ... | 5 |
#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
int v = 0, f = 1;
char c = getchar();
while (!isdigit(c) && c != '-') c = getchar();
if (c == '-')
f = -1;
else
v = (c & 15);
while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15);
x = v * f;
}
inline void read(lo... | 24 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int x = 0;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
if (s[1] == '-') {
x--;
} else {
x++;
}
}
cout << x << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
if (a < b) a = b;
}
int vst[1000100], p[1000100], pk;
long long arr[1000100], d[1000100];
int dp[1000100], tmp[1000100], t... | 18 |
#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 N;
vector<int> E[100001];
vector<signed long long> V;
pair<signed... | 10 |
#include <bits/stdc++.h>
using namespace std;
int a, b, c, d;
int main() {
int t;
scanf("%d", &t);
while (t--) {
scanf("%d%d%d%d", &a, &b, &c, &d);
printf("%d\n", abs(a - c) + abs(b - d) + 2 * (a != c && b != d));
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, m, s, t;
cin >> n >> m;
vector<vector<int> > g(n + 1);
vector<bool> vis(n + 1, 0);
vector<int> indeg(n + 1, 0);
vector<int> dp(n + 1, -1);
queue<int> qf, ql;
while (m-... | 18 |
#include <bits/stdc++.h>
using namespace std;
int n;
char res[10];
int main() {
scanf(" %d", &n);
bool flipped = false;
int lo = 0, hi = 1000000000;
for (int i = 1; i <= n; ++i) {
if (lo + 1 < hi) {
int mid = (lo + hi) / 2;
printf("1 %d\n", mid);
fflush(stdout);
scanf(" %s", res);
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n], z = 0, b[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i]) z++;
if (a[i])
b[i] = -1;
else
b[i] = 1;
}
if (z == n) {
cout << n - 1 << endl;
return 0;
}
int maxi = 0, sum = 0, s... | 4 |
#include <bits/stdc++.h>
using namespace std;
vector<int> v[350001];
int n, i, q, type, l, r, zn, ans;
bool pole[350001];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> q;
while (q--) {
cin >> type >> zn;
if (type == 1) {
ans++;
r++;
v[zn].push_back(r);
} else if (ty... | 8 |
#include <bits/stdc++.h>
using namespace std;
vector<int> p[5005];
int n, m, minn[5005];
int main() {
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++) minn[i] = -1;
for (int i = 1; i <= m; i++) {
int x, y;
scanf("%d %d", &x, &y);
p[x].push_back(y);
}
for (int i = 1; i <= n; i++) {
for (int... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, arr[100005], dp[100005], sol;
int main() {
cin >> n;
for (int i = 0; i < n; i++) cin >> arr[i + 1];
for (int i = 0; i < n; i++) dp[i + 1] = min(arr[i + 1], dp[i] + 1);
for (int i = 0; i < n; i++) dp[n - i] = min(dp[n - i], dp[n - i + 1] + 1);
for (int i = 0... | 8 |
#include <bits/stdc++.h>
using namespace std;
int i, j, m, n, p, k, q, x, y;
int g[61][61][61], f[61][61][61];
int main() {
scanf("%d%d%d", &n, &m, &q);
for (i = 1; i <= m; i++) {
for (j = 1; j <= n; j++)
for (k = 1; k <= n; k++) scanf("%d", &g[i][j][k]);
for (int k = 1; k <= n; k++)
for (int I ... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int inf = 1e9 + 1;
const double eps = 1e-15;
const double EPS = 1e-9;
const double PI = acos(-1.0);
long long int dx_8[] = {-1, -1, -1, 0, 0, 1, 1, 1},
dy_8[] = {-1, 0, 1, -1, 1, -1, 0, 1};
long long int dx[] = {0, 0, 1, -1}, dy[] ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 300000 + 100;
long long a[maxn];
long long dp[maxn];
long long dp2[maxn];
vector<int> G[maxn], dist[maxn];
long long int ans = 0;
void dfs(int u, int fa) {
long long int max1 = 0, max2 = 0;
for (int i = 0; i < G[u].size(); i++) {
int v = G[u][i];
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000005;
const int SQRTN = 1003;
const int LOGN = 22;
const double PI = acos(-1);
const int INF = 1e9;
const int MOD = 1000000007;
const int FMOD = 998244353;
const double eps = 1e-9;
template <typename T>
T gcd(T a, T b) {
return (b ? __gcd(a, b) : a);
}... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long int n, m;
long int a[2230] = {0}, b[2230] = {0}, i, j, sum = 0;
cin >> n >> m;
for (i = 0; i < 400; i++) {
cout << "5";
}
cout << endl;
for (i = 0; i < 399; i++) cout << "4";
cout << "5";
cout << endl;
}
| 4 |
#include <bits/stdc++.h>
int dr[] = {2, 2, -2, -2, 1, -1, 1, -1};
int dc[] = {1, -1, 1, -1, 2, 2, -2, -2};
int dr1[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dc1[] = {1, -1, 1, 0, -1, 0, 1, -1};
int dr2[] = {0, 0, 1, -1};
int dc2[] = {1, -1, 0, 0};
using namespace std;
long long dp[4005][4005];
long long cal(long long x, lon... | 13 |
#include <bits/stdc++.h>
using namespace std;
int T, n;
int main() {
scanf("%d", &T);
while (T--) {
scanf("%d", &n);
if (n <= 30) {
puts("NO");
continue;
}
if (n == 36) {
puts("YES");
puts("5 6 10 15");
continue;
}
if (n == 40) {
puts("YES");
puts("6... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long s, x;
ios::sync_with_stdio(false);
long long ans, y;
while (cin >> s >> x) {
ans = 1;
y = 0;
if (s == x) y = 2;
if (s - x < 0 || (s - x) % 2)
cout << "0" << endl;
else if (((s - x) / 2) & x)
cout << "0" << endl;... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long n, tc;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
;
cin >> tc;
while (tc--) {
cin >> n;
int a[2 * n];
for (int i = 0; i < 2 * n; i++) cin >> a[i];
bool check[n + 1];
for (int i = 0; i <= n; i++) check[i] = false;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
char s1[2000 + 5], s2[2000 + 5];
int main() {
int len1, len2, ans, cnt, mcnt;
while (scanf("%s", s1) != EOF) {
scanf("%s", s2);
len1 = strlen(s1);
len2 = strlen(s2);
mcnt = 0;
if (len1 > len2) {
for (int i = 0; i < len1; i++) {
cnt = 0;... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_NB_NOMBRES = 3000;
const long long INFINI = (long long)1000 * 1000 * 1000 * 1000 * 1000;
int nbNombres;
long long hauteurs[MAX_NB_NOMBRES];
long long hauteursPossibles[MAX_NB_NOMBRES];
long long cost[2][MAX_NB_NOMBRES];
int main() {
cin >> nbNombres;
for (... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long n, i, j, x;
string s;
cin >> s;
n = s.size();
map<char, long long> mp;
for (i = 0; i < n; i++) {
long long temp = 0;
for (char c = 'a'; c < s[i]; c++) temp += mp[c];
if (temp == 0)
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 88;
const int maxn = 1e5 + 88;
const int maxa = 2e6 + 88;
const long long llinf = 1e18 + 88;
bool sito[maxa];
map<int, int> masks;
map<int, int> grundy;
int readint() {
int cur;
scanf("%d", &cur);
return cur;
}
void fact(int x) {
int i, cur = x... | 14 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.