solution stringlengths 53 181k | difficulty int64 0 13 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6, mod = 1e9 + 7;
vector<vector<int> > multiply(vector<vector<int> > &a,
vector<vector<int> > &b) {
int d = a.size(), e = a[0].size();
int f = b.size(), g = b[0].size();
if (e != f) assert(0);
vector<vector<int> > c;
c... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
const long double PI = 3.14159265358979;
long long binpow(long long x, long long y, long long p) {
long long res = 1;
x = x % p;
if (x == 0) return 0;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007, MAXN = 70000 + 10;
int n;
string s[MAXN];
map<string, int> m;
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s[i];
vector<string> first;
for (int a = 0; a < 9; a++... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, k, i, a[10010];
double l, r, h, c, d;
int main(int argc, char **argv) {
cin >> n >> k;
for (i = 0; i < n; i++) cin >> a[i];
l = 0;
r = 1010;
while (l < r - 1e-9) {
h = (l + r) * 0.5;
for (c = d = i = 0; i < n; i++)
if (a[i] > h) {
c +=... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, m;
string name[N];
struct Query {
int v, p, ans;
} q[N];
vector<int> vec[N], rt;
struct Edge {
int nxt, to;
} edge[N << 1];
int head[N], edgeNum;
void addEdge(int from, int to) {
edge[++edgeNum] = (Edge){head[from], to};
head[from] = edg... | 8 |
#include <bits/stdc++.h>
using namespace std;
int tests;
long long a, b;
int win(long long a, long long b) {
long long t;
if (a > b) t = a, a = b, b = t;
if (!a) return 0;
if (!win(b % a, a)) return 1;
if ((((b / a)) % (a + 1)) % 2)
return 0;
else
return 1;
}
int main() {
cin >> tests;
for (int ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, m, q;
double x;
vector<int> l(26, 0);
vector<double> u(26, 1e9);
string keys[30];
vector<pair<int, int>> shift;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> x;
for (int i = 0; i < n; i++) {
cin >> keys[i];
}
for (int i = 0; i < n... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9 + 5;
const long long INF = 1e18 + 5;
const long long maxn = 1e6 + 5;
long long n, a[maxn], b[maxn];
long long w[maxn], dp[maxn];
vector<int> g[maxn];
long long ans = 0;
vector<int> vv[maxn];
void dfs(int v) {
if (b[v] == 0) vv[v].push_back(v);
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int arr[100005];
int main() {
int n, x;
bool valid = true;
int cons = 1;
bool counting = true;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> arr[i];
if (i > 0 && counting && arr[i] == arr[i - 1]) {
cons++;
}
if (i > 0 && arr[i] != arr[i - ... | 4 |
#include <bits/stdc++.h>
const int maxn = 6000;
int n;
double q0, a0, b0;
double y_opt[maxn], x[maxn], chain[maxn];
double quad_min(double a, double b, double c) { return -b / (2.0 * a); }
double bound(double h, double v) { return std::max(1.0 + h, std::min(q0, v)); }
void pull_chain(int j0, double h, double a, double ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int n, l = -1000000000, r = 1000000000;
cin >> n;
long long int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
string s;
cin >> s;
for (int i = 4; i < s.size(); i++) {
if (s[i] != ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
long long memo[101][2];
int dp(int sum, int pas) {
if (sum > n) return 0;
if (sum == n) {
if (pas)
return 1;
else
return 0;
}
long long &x = memo[sum][pas];
if (x != -1) return x;
x = 0;
for (int j = 1; j <= m; j++) {
x += ... | 4 |
#include <bits/stdc++.h>
using namespace std;
inline int getint() {
static char c;
while ((c = getchar()) < '0' || c > '9')
;
int res = c - '0';
while ((c = getchar()) >= '0' && c <= '9') res = res * 10 + c - '0';
return res;
}
const int MaxN = 500000;
const int MaxM = 500000;
int n, m;
struct edge {
in... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 228;
const int md = 1e9 + 7;
const int big = 1e9;
int n, c, ans, sf[N], pr[N], kol[N], a[N], best[N];
int main() {
cin >> n >> c;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = n; i >= 1; i--) sf[i] = sf[i + 1] + bool(a[i] == c);
for (int... | 6 |
#include <bits/stdc++.h>
using namespace ::std;
bool cmp(int a, int b) { return a > b; }
int abs(int a) {
if (a > 0) {
return a;
}
return -a;
}
long long max(long long a, long long b) {
if (a > b) {
return a;
}
return b;
}
int a[100000];
int b[100000];
int main() {
int n;
while (cin >> n) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read_to_vector(size_t N, std::vector<T> &v) {
for (size_t i = 0; i < N; i++) {
T tmp;
std::cin >> tmp;
v.push_back(tmp);
}
}
template <typename T>
void print_vector(const std::vector<T> &v) {
for (auto it = v.begin(); it < v.end(... | 7 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int grand(int x) { return uniform_int_distribution<int>(0, x - 1)(rng); }
const int maxn = 21;
const long long inf = 1e15;
const long long md = 1e9 + 7;
inline bool msksort(int x, int y) {
return __built... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n == 1) {
cout << 1 << " " << 2 << endl;
cout << 1 << " " << 2 << endl;
return 0;
}
cout << (n - 1) * 2 << " " << 2 << endl;
cout << 1 << " " << 2 << endl;
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
if (n % 2 == 0)
for (int i = 0; i < n; i++) {
cout << s[i];
if (i % 2 != 0 && i < n - 1) cout << "-";
}
else {
for (int i = 0; i < n - 3; i++) {
cout << s[i];
if (i % 2 != 0 &&... | 1 |
#include <bits/stdc++.h>
using namespace std;
struct cons {
string s;
int reg, points, pos;
};
bool my(cons &a, cons &b) {
if (a.reg < b.reg)
return 1;
else if (a.reg == b.reg && a.points > b.points)
return 1;
else if (a.reg == b.reg && a.points == b.points && a.pos < b.pos)
return 1;
else
r... | 2 |
#include <bits/stdc++.h>
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>
debug& operator<<(const c&... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, m, f1, c1, f2, c2;
int absol(int a) {
if (a < 0) a *= -1;
return a;
}
int main() {
cin >> n >> m >> f1 >> c1 >> f2 >> c2;
int dif1 = absol(f1 - f2);
int dif2 = absol(c1 - c2);
int m = max(dif1, dif2);
m--;
if (m <= 3 && dif1 + dif2 <= 6)
cout << "... | 6 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
const ll N = 2e6 + 12;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
ll n, k;
cin >> n >> k;
vl a(n + 2);
for (ll i = 1; i <= n; i++) {
cin >> a[i];
}
ll ans = 0;
for (ll i = 1; i <= n + 1; i++) {
an... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int v[N];
long long f[N][3][2][2];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &v[i]);
if (n == 1) {
printf("%d\n", v[1]);
return 0;
}
memset(f, ~0x3f, sizeof(f));
f[1][2][0][1] = -v[1];
f[1][... | 9 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int mod = 1000000007;
const int maxn = 500010;
int arr[maxn];
int tree[4 * maxn];
int gcdcnt = 0;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
void Build(int node, int b, int e) {
if (b == e) {
tree[node] = arr[b];
re... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, m, r[300001];
vector<int> e[300001];
bool check(int x) {
int d = 0;
for (int i = 0; i < e[x].size(); i++) d += (r[x] == r[e[x][i]] ? 1 : 0);
return d > 1;
}
void change(int x, int o) {
if (check(x)) {
r[x] = 1 - r[x];
for (int i = 0; i < e[x].size(); ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int t, n, m;
int main() {
scanf("%d%d", &n, &t);
while (t--) {
if (n % 10 == 0)
n /= 10;
else
n -= 1;
}
printf("%d\n", n);
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1211111;
int num[N * 2];
int temp[N];
inline int calc(int a, int b, int l, int t) {
if (abs(a - b) > t * 2) return 0;
t *= 2;
t -= abs(a - b);
return 1 + t / l;
}
int main() {
int n, l, t;
scanf("%d%d%d", &n, &l, &t);
for (int i = 1; i <= n; i++)... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 5, nax = 1e6 + 5;
char rodz[25];
int id[25];
int res[2 * nax];
int cob(int a) {
if (a) return (a % 2 ? 1 : 0) + cob(a / 2);
return 0;
}
int pro() {
int n;
cin >> n;
vector<int> w;
for (int _ = 1, _n = (n); _ <= _n; ++_) {
int a;
cin... | 7 |
#include <bits/stdc++.h>
using namespace std;
bool chkmin(int &a, int b) { return b < a ? a = b, 1 : 0; }
bool chkmax(int &a, int b) { return b > a ? a = b, 1 : 0; }
inline long long read() {
long long x = 0, fh = 1;
char ch = getchar();
for (; !isdigit(ch); ch = getchar())
if (ch == '-') fh = -1;
for (; is... | 5 |
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define st first
#define nd second
#define turbo ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define vi vector<int>
#define vvi vector<vi>
#define qi queue<int>
#define ld long double
using namespace std;
/*-----... | 8 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-7;
const long long MOD = (long long)1e9 + 7;
const int MAXN = (int)1e5 + 10;
vector<int> ady[MAXN];
int color[MAXN];
bool mk[MAXN];
long long dp[MAXN][2];
int father[MAXN];
long long modexp(long long v, long long p) {
if (!p) return 1LL;
long long ... | 6 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,k,n) for(int i=k;i<n;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vecto... | 0 |
#include <bits/stdc++.h>
using namespace std;
map<string, int> patterns;
string suitable_pattern(string s) {
string result = s;
for (int i = 0; i <= int(s.size()) - 1; ++i) {
int cur = s[i] - '0';
result[i] = (cur % 2) + '0';
}
string add = "";
for (int i = 0; i <= 18 - int(s.size()); ++i) {
add +... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long fun(long long x, long long a) {
long long ch1;
ch1 = x / a + 1;
return ch1;
}
long long fu(long long st, long long dr, long long kak) {
long long ch = st, i;
for (i = 0; i < dr; i++) ch = ch * 10 + kak;
return ch;
}
int main() {
ios_base::sync_with_s... | 4 |
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#inc... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
int k = 0;
for (int i = 1; i <= n - 1; i++) {
if (a[i - 1] == 1 && a[i + 1] == 1 && a[i] == 0) {
a[i + 1] = 0;
k++;
}
}
cout << k;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
char s[10][10];
int main() {
int bl = 0, wh = 0;
for (int i = 0; i < 8; i++) scanf("%s", s[i]);
for (int i = 0; i < 8; i++)
for (int j = 0; j < 8; j++) {
if (s[i][j] == 'Q')
wh += 9;
else if (s[i][j] == 'R')
wh += 5;
else if (s[i]... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<int> g[10005];
int ans;
void dfs(int u, int p, int len) {
if (len == 2) {
ans++;
return;
}
for (auto v : g[u]) {
if (v != p) dfs(v, u, len + 1);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;... | 2 |
#include <bits/stdc++.h>
using std::abs;
using std::array;
using std::cerr;
using std::cin;
using std::cout;
using std::generate;
using std::make_pair;
using std::map;
using std::max;
using std::max_element;
using std::min;
using std::min_element;
using std::pair;
using std::reverse;
using std::set;
using std::sort;
us... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, Max, Min[(20009)], cnt[(20009)];
int Calc(int x, int y) { return (y < x) ? n - x + y : y - x; }
int main() {
cin >> n >> m;
memset(Min, 0x7f, sizeof(Min));
for (int i = 1; i <= m; ++i) {
cin >> x >> y;
if (x == y) continue;
cnt[x]++;
Mi... | 4 |
#include <bits/stdc++.h>
using namespace std;
char s[10005];
int main() {
bool f = false;
int i, r = 0;
while (scanf("%s", &s) != EOF) {
i = 0;
if ((s[0] == '.' || s[0] == ',' || s[0] == '?' || s[0] == '!') &&
strlen(s) > 1)
printf("%c ", s[0]), i = 1;
else if ((s[0] == '.' || s[0] == ',... | 2 |
#include <bits/stdc++.h>
using namespace std;
int dp[2][1 << 12], n, m, a[15][2005], gg[1 << 12];
struct node {
int id, mx;
bool operator<(const node& b) const { return mx > b.mx; }
} d[2005];
int main() {
int tt;
scanf("%d", &tt);
while (tt--) {
scanf("%d%d", &n, &m);
memset(d, 0, sizeof(d));
mem... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b;
cin >> n >> a >> b;
if (b == 0) cout << a;
if (b > 0) {
b = b % n;
if (b <= n - a)
cout << a + b;
else {
b -= n - a;
cout << b;
}
return 0;
}
if (b < 0) {
b *= -1;
b = b % n;
if (b == 0)... | 1 |
#include <bits/stdc++.h>
int pos[200003], arr1[200003];
int main() {
int n, i, x, prev;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &arr1[i]);
}
for (i = 0; i < n; i++) {
scanf("%d", &x);
pos[x] = i;
}
prev = -1;
for (i = 0; i < n && pos[arr1[i]] > prev; i++) prev = pos[arr1[i]];
... | 3 |
#include <bits/stdc++.h>
using namespace std;
struct q {
long long x1, x2, y1, y2, ind;
};
bool check(list<q> a) {
if (a.size() < 2) return true;
set<long long> was;
list<q> left((a).begin(), (a).end()), right((a).begin(), (a).end()),
up((a).begin(), (a).end()), down((a).begin(), (a).end());
left.sort([... | 8 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
vector<long long> arr(n + 1);
set<long long> s;
for (long long i = 1; i <= n; i++) {
cin >> arr[i];
}
bool zero = ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int arr[n];
for (int i = 0; i < n; ++i) {
cin >> arr[i];
}
sort(arr, arr + n, greater<int>());
int res;
res = ((arr[0] - arr[n - 1]) + 1) - n;
cout << res << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int n = (int)s.length();
int i = 0;
while (i < n) {
if ((i <= n - 3) && s[i] == '1' && s[i + 1] == '4' && s[i + 2] == '4') {
i += 3;
} else if (i <= n - 2 && s[i] == '1' && s[i + 1] == '4') {
i += 2;
} else ... | 0 |
#include <bits/stdc++.h>
using namespace std;
static const double EPS = 1e-8;
long long rec(vector<int> &ednum, int cost[16][16], int n, int b) {
long long res = 1000000000000000LL;
bool ok = true;
int id = 0;
for (int i = b; i < n; i++) {
if (ednum[i]) {
ok = false;
ednum[i] = 0;
id = i;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n;
cin >> n;
map<int, pair<int, int>> matches;
vector<int> prices(n), as(n), bs(n);
set<int> colors[3];
for (int i = 0; i < n; ++i) {
cin >> prices[i];
}
fo... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 12505;
const int M = 1000005;
int n, m, w[N], a[N], b[M], eu[M], ev[M];
bool vis[M * 2];
vector<pair<int, int> > G[N];
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++) {
int u, v;
scanf("%d%d", &u, &v);
G[u].emplace_back(v, i);
... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long int a[20000], m = -1e18, n;
void updateMax(long long int k) {
for (long long int i = 0; i < k; i++) {
long long int mi = 0;
for (long long int j = i; j < n; j += k) mi += a[j];
m = max(m, mi);
}
}
int main() {
ios_base::sync_with_stdio(false);
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
long long state[1011], str[1011][1011];
map<long long, int> mp;
const int mod = 1e9 + 7;
int main() {
scanf("%d%d", &m, &n);
long long x;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) scanf("%1lld", &x), state[j] |= (x << i);
for (int i = 0; ... | 8 |
#include <bits/stdc++.h>
const int MAXN = 50 + 5;
const int MAXK = 12 + 5;
int pre[4][MAXN][MAXN][MAXK][MAXK], logv[MAXN], dp[MAXN][MAXN][MAXN][MAXN], n;
char map[MAXN][MAXN];
void initMinRow() {
int opat = 0;
for (int p = 0; p <= logv[n]; p++)
for (int q = 0; q <= logv[n]; q++)
for (int i = 1; i + (1 << ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200000 + 8;
int n, A[MAXN], res;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &A[i]);
for (int i = 0; i < n - 1; i++) {
A[i] %= 2;
if (A[i] == 1 and A[i + 1] > 0) {
A[i]--, A[i + 1]--;
}
res += A[i];
}
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int car[1001][1001];
long long si[1001] = {0}, sj[1001] = {0};
int main() {
int n, m, li, lj;
long long sumx, sumy;
scanf("%d %d", &n, &m);
for (int j = 1; j <= n; j++) {
for (int i = 1; i <= m; i++) {
scanf("%d", &car[j][i]);
si[i] += car[j][i];
... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long p;
int t;
long long mulit(long long a, long long b) {
if (b < 10000000000 / 100) return (a * b) % p;
return ((mulit(a, b >> 1) << 1) + (b & 1 ? a : 0)) % p;
}
long long sum2(long long x) {
long long a, b, c;
a = x;
b = (x + 1);
c = (2 * x + 1);
if (a... | 9 |
#include <bits/stdc++.h>
using namespace std;
bool used[2 * 1000000 + 1];
int main() {
cin.sync_with_stdio(false);
string s;
cin >> s;
int n = s.length();
if (s[n - 1] == 'L') {
for (int i = 0; i < n; ++i)
if (s[i] == 'L')
s[i] = 'R';
else
s[i] = 'L';
}
memset(used, 0, size... | 7 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
long long cost[100007];
long long dpx[100007][2], dpy[100007][2];
int n;
int main() {
ios::sync_with_stdio(false);
cin >> n;
for (int i = 0; i < n - 1; i++) cin >> cost[i];
dpx[0][0] = dpx[0][1] = 0;
for (int i = 1; i < n; ++i) {
if (!... | 6 |
#include <bits/stdc++.h>
using namespace std;
namespace fastIO {
bool IOerror = 0;
inline char nc() {
static char buf[100000], *p1 = buf + 100000, *pend = buf + 100000;
if (p1 == pend) {
p1 = buf;
pend = buf + fread(buf, 1, 100000, stdin);
if (pend == p1) {
IOerror = 1;
return -1;
}
}
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double a, b, c, d, x1, x2;
cin >> a >> b >> c;
d = b * b - (4 * a * c);
x1 = (-b + sqrt(d)) / (2 * a);
x2 = (-b - sqrt(d)) / (2 * a);
if (x1 < x2) swap(x1, x2);
printf("%.10lf\n", x1);
printf("%.10lf", x2);
}
| 2 |
#include <bits/stdc++.h>
int main() {
long long int x;
scanf("%lld", &x);
long long int a = 0;
long long int n = 0;
if (x < 0) {
a = (x % 360 + 360) % 360;
if (a >= 0 && a <= 44)
printf("0");
else if (a == 45)
printf("0");
else if (a >= 46 && a <= 134)
printf("1");
else i... | 5 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
inline int sign(double x) { return (x > eps) - (x < -eps); }
const int maxn = 5e5 + 10, mod = 1e9 + 7, INF = 0x3f3f3f3f;
int a[maxn];
int mx[maxn << 2], pos[maxn << 2];
void upd(int p, int c, int l, int r, int rt) {
if (l == r) {
mx[rt] = c;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const long double ep = 1.000000001;
void solve() {
int n;
cin >> n;
vector<int> v[5];
for (int i = 0; i < n; i++) {
for (int j = 0; j < 5; j++) {
int a;
cin >> a;
if (a == 1) v[j].push_back(i + 1)... | 1 |
#include <bits/stdc++.h>
using namespace std;
char a[18];
int main() {
int n, i;
cin >> n;
while (n--) {
cin >> a;
int len = strlen(a);
int flag = 0;
int cnt = 0;
for (i = 1; i < len; i++) {
if ((a[i] >= '0' && a[i] <= '9') && (a[i - 1] >= 'A' && a[i - 1] <= 'Z'))
cnt++;
}
... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <typename T... | 4 |
#include <bits/stdc++.h>
int main() {
int x, y, z, sx, sy, sz;
std::cin >> x >> y >> z;
std::cin >> sx >> sy >> sz;
std::vector<int> a(6);
int res = 0;
for (auto& it : a) {
std::cin >> it;
res += it;
}
if (y >= 0) res -= a[0];
if (y <= sy) res -= a[1];
if (z >= 0) res -= a[2];
if (z <= sz)... | 4 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
void solve() {
int arr[6][6];
int pm[5] = {1, 2, 3, 4, 5};
for (int i = 1; i < 6; i++) {
for (int j = 1; j < 6; j++) {
... | 2 |
#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
using namespace std;
const long long N = 1e6 + 5;
void pairsort(long long a[], long long b[], long long n) {
pair<long long, long long> pairt[n];
for (long long i = 0; i < n; i++) {
pairt[i].first = a[i];
pairt[i].second = b[i];
}
sort(pairt, pairt + ... | 1 |
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
template <class T = int>
using V = vector<T>;
template <class T = int>
using VV = V<V<T> >;
template <class T>
void assign(V<T>& v, int n, const T& a = T()) {
v.assign(n, a);
}
template <class T, class... U>
void assi... | 8 |
#include <bits/stdc++.h>
using namespace std;
int getMax(const vector<int>& count) {
int res = 0;
for (int i = 1; i < count.size(); i++)
if (count[i] > count[res]) res = i;
return res;
}
int main() {
string s;
cin >> s;
int n = s.size();
vector<bool> prime(1005, true);
prime[0] = prime[1] = false;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int dp[23000][152];
int n, s, m;
int a[151];
int main() {
scanf("%d%d%d", &n, &m, &s);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
s = min(s, n * n);
memset(dp, 0x3f, sizeof(dp));
dp[0][0] = 0;
for (int i = n; i >= 1; i--) {
for (int j = s; j ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
int n;
long long k;
char x[maxn];
long long ed[maxn][maxn];
long long en[maxn];
bool apr[maxn];
int main() {
cin >> n >> k;
cin >> (x + 1);
long long ans = 0;
for (int i = 1; i <= n; i++) {
if (i == 1) {
memset(apr, 0, sizeof(apr));
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100100;
int n;
char ch[MAXN];
int NEXT[27], PREV[27], vis[27], ans[MAXN], cnt[27], Index, tmp[27];
queue<int> Q;
int init() {
scanf("%d", &n);
for (int o = 1; o <= n; o++) {
scanf(" %s", ch + 1);
int len = strlen(ch + 1);
for (int i = 1; i <... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long int a, n, arr[100005], ar[100005], arrr[100005];
string s1, s2;
void solve() {
cin >> s1 >> s2;
n = s1.size();
for (int i = 0; i < n; i++) {
if (s1[i] == s2[i])
arrr[i] = 0;
else
arrr[i] = 1;
}
for (int i = 0; i < n; i++) cout << arrr... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long int arr[1000000];
int main() {
long long int n, p, i, j;
cin >> n >> p;
string s;
cin >> s;
for (i = n - 1; i >= 0; i--) {
s[i]++;
while ((s[i] - 'a') < p) {
if (s[i] == s[i - 1] || s[i] == s[i - 2]) {
s[i]++;
continue;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<char> > A(50, vector<char>(50));
std::vector<vector<char> > B(50, vector<char>(50));
int na, ma, nb, mb;
int calculateOverlap(int x, int y) {
int overlap = 0;
for (int i = 0; i < na; i++) {
if (i + x >= nb || i + x < 0) continue;
for (int j = 0; j ... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int tcase;
cin >> tcase;
for (int tc = 1; tc <= tcase; tc++) {
long long ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int smallest, largest, n, count = 0, a;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a;
if (i == 0) {
smallest = a;
largest = a;
} else {
if (a > largest) {
count += 1;
largest = a;
} else if (a < smal... | 0 |
#include <bits/stdc++.h>
using namespace std;
bool debug = false;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string s[2005];
int h[2005], cnt, dp[2005][2005];
int dfs(int l, int r) {
if (l == r) return n;
int mid = min_element(h + l, h + r) - h;
int x = dfs(l, mid);
int y = dfs(mid + 1, r);
... | 7 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long x = 0;
char ch = getchar();
bool positive = 1;
for (; ch < '0' || ch > '9'; ch = getchar())
if (ch == '-') positive = 0;
for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
return positive ? x : -x;
}
int... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)1e5 + 5;
int find(int a, int fa[]) { return fa[a] == a ? a : fa[a] = find(fa[a], fa); }
int main() {
int fa[101], s[101];
int n, m;
cin >> n >> m;
for (int i = 0; i <= n; ++i) {
fa[i] = i;
s[i] = 1;
}
int cnt = 0;
for (int i = 0; ... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int x, y, h;
} t[110000];
bool cmp(const node &A, const node &B) {
if (A.x != B.x) return A.x < B.x;
return A.y < B.y;
}
bool check(node &A, node &B, node &C) {
long long x1 = B.x - A.x, y1 = B.y - A.y;
long long x2 = C.x - A.x, y2 = C.y - A.y;
ret... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long INFLL = 1e18 + 1;
const int MAX = 200001;
const long long MOD = 1000000007;
const int SZ = 300100;
const double eps = 0.000000006;
const double PI = 3.14159265358979323846264338327;
long long inq(long long k, long long q, long long mod) ... | 7 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
const int N = 200500;
struct FWTree {
int sz;
int* fw;
FWTree() { sz = 0; }
FWTree(int sz) {
this->sz = sz;
fw = new int[sz + 10];
for (int i = 0; i < sz + 10; i++) fw[i] = 0;
}
void update(int pos, int add) {
while (pos <= s... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <typename TP>
inline void read(TP &tar) {
TP ret = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
ret = ret * 10 + ch - '0';
ch = getchar();
}
tar... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char s[55];
int b;
cin >> s;
cin >> b;
int len = strlen(s);
for (int i = 0; i < len; i++) {
if (s[i] < 'a') {
s[i] += 32;
}
}
for (int i = 0; i < len; i++) {
if (s[i] < b + 'a') {
s[i] -= 32;
}
}
cout << s << endl... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
vector<int> a;
int flag = 0;
for (int i = 0; i < n; i++) {
int y;
cin >> y;
a.push_back(y);
}
for (int i = 1; i < n; i++) {
if (a[i] == a[i - 1]) {
flag++;
}
}
if (flag == n - 1) {
cout <<... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int Mod = 1000000007;
const int C1[10] = {0, 0, 0, 0, 0, 1, 1, 1, 2, 2};
const int C2[10] = {0, 0, 0, 0, 1, 0, 0, 1, 0, 0};
const int C3[10] = {0, 1, 2, 3, 4, 4, 5, 6, 6, 7};
const int C4[10] = {1, 1, 1, 1, 0, 1, 1, 0, 1, 1};
int Len, K;
int A[1001];
bool Flag[1001][1... | 8 |
#include <bits/stdc++.h>
using namespace std;
int dem[10];
int a, b, c, d, t;
int n, temp;
int ans = 0;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
scanf("%d", &temp);
dem[temp]++;
}
a = dem[1];
b = dem[2];
c = dem[3];
d = dem[4];
t = min(a, b);
a -= t;
b -= t;
c += t;
ans += t... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
vector<int> v[maxn];
int vos[maxn];
int ans;
void dfs(int now, int pre) {
if (vos[now]) {
ans = 0;
return;
}
vos[now] = 1;
for (int i = 0; i < v[now].size(); i++) {
if (v[now][i] != pre) {
dfs(v[now][i], now);
}
}
}
... | 4 |
#include <bits/stdc++.h>
using namespace std;
inline void in(int &n) {
n = 0;
int ch = getchar();
int sign = 1;
while (ch < '0' || ch > '9') {
if (ch == '-') sign = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
n = (n << 3) + (n << 1) + ch - '0', ch = getchar();
}
n = n * sign;
}
ve... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int n;
int a[N];
map<int, bool> mp;
vector<int> need;
vector<int> have;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int T;
cin >> T;
while (T--) {
mp.clear();
need.clear(), have.clear();
cin >> n;
for (int i = 1; i <= n;... | 2 |
#include <bits/stdc++.h>
using namespace std;
int cnt[5000001];
int sum[5000001];
bool mark[5000001];
int get(int n, int x) {
int cnt = 0;
while (n % x == 0) n /= x, cnt++;
return cnt;
}
void sieve() {
cnt[1] = 1;
int root = sqrt(5000001) + 3, i, r;
for (i = 2; i < 5000001; i++) {
if (mark[i]) continue;... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long n, a[100010], sum, s, f;
map<int, int> mp;
int main() {
f = -1;
bool flag = 0;
scanf("%lld", &n);
for (int i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
sum += a[i];
mp[a[i]]++;
if (mp[a[i]] > 2) flag = 1;
if (mp[a[i]] == 2) s++, f = a[i]... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, k;
int s[N];
int main() {
while (scanf("%d%d", &n, &k) == 2) {
for (int i = 1; i <= n; i++) {
scanf("%d", &s[i]);
}
int ans = s[n];
for (int i = 1; i <= n - k; i++) {
ans = max(ans, s[i] + s[2 * (n - k) - i + 1]);... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 987654321;
const long long int INF = 123456789987654321;
FILE *fin, *fout;
int N, K;
vector<vector<char> > G;
vector<vector<int> > psum;
void get_psum() {
psum = vector<vector<int> >(N, vector<int>(N));
for (int i = 0; i < N; i++) {
for (int j = 0; j... | 8 |
#include <bits/stdc++.h>
using namespace std;
int a, b, arr[100005];
int mceil(int a, int b) {
if (a % b == 0)
return a / b;
else
return a / b + 1;
}
set<int> s;
int main() {
int n, i, tar, val, tot = 0, mn, sz = 0;
cin >> n;
for ((i) = 0; (i) < (n); (i)++) {
scanf("%d", &val);
s.insert(val);
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int i, j, t, k, c, cnt, n, d, d1, cnt1, l, sum;
cin >> t;
long long int a[t][t];
for (i = 0; i < t; i++) {
for (j = 0; j < t; j++) {
a[0][j] = 1;
a[i][0] = 1;
}
}
for (i = 1; i < t; i++) {
for (j = 1; j < t; j++) {
... | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.