solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int n, i, b, v[110], k, o1, e1, o2, e2, cost, sol, j, no[110], poz1, poz2;
struct dif {
int d, p1, p2;
} a[110];
bool cmp(dif x, dif y) { return x.d < y.d; }
int main() {
cin >> n >> b;
for (i = 1; i <= n; i++) {
cin >> v[i];
if (i >= 2) {
a[++k].d = abs... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int mxn = 1005;
int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
int n, m... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int dp[30][30] = {};
int i, j, n, lo, l, r, ans = 0;
cin >> n;
for (i = 1; i <= n; i++) {
cin >> s;
lo = s.size();
l = s[0] - 97;
r = s[lo - 1] - 97;
for (j = 0; j < 26; j++) {
if (dp[j][l]) dp[j][r] = max(dp[j][r],... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
cout << min(n, m) << ' ' << (max(n, m) - min(n, m)) / 2;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long t;
cin >> t;
while (t--) {
long long n, k;
cin >> n >> k;
long long r = 1;
long long f = r * (r + 1) / 2;
while (f <= k) {
r++... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000000 + 7;
const int maxn = 100000 + 5;
const int maxm = 100000 + 5;
int n, m, c;
set<int> graph[maxn];
set<int> unvisited;
void dfs(int k) {
vector<int> cst;
for (int u : unvisited) {
if (!graph[k].count(u)) cst.push_back(u);
}
for (int u :... | 11 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n;
cin >> n;
n--;
long long ans = 0;
for (long long c = 0; (1ll << c) <= n; c++)
ans += (((n - (1ll << c)) >>... | 11 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
int flag[1000000];
int t[1000000];
int num[1000000];
int num2[1000000];
int main() {
memset(flag, 0, sizeof(flag));
memset(t, 0, sizeof(t));
memset(num, 0, sizeof(num));
int n, m;
scanf("%d%d", &n, &m);
int tot = 0;
for (int i = 0; ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[100005];
int b[100005];
int cnt = 0;
queue<int> Q;
map<int, int> P;
int p;
int main() {
scanf("%d %d", &n, &k);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
for (int i = 1; i <= n; i++) {
if (!P[a[i]]) {
if (Q.size() < k) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
using longs = long long;
using uint = unsigned;
inline int nextInt() {
int x = 0, f = 0, ch = getchar();
while (!isdigit(ch)) ch == '-' && (f = 1), ch = getchar();
while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
return f ? -x : x;
}
template <int n>
vector... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
int n, c;
cin >> n >> c;
int x, y;
cin >> x;
int ans = 1;
while (--n) {
cin >> y;
if (y - x > c)
ans = 1;
else
ans++;
swap(x, y);
}
cout << ans;
retur... | 0 |
#include <bits/stdc++.h>
using namespace std;
int H[2];
int T[2];
int L[2];
int R[2];
double P[2];
double S[2];
double X[2][5000][210];
vector<int> C;
int K;
void compute(int i, int t) {
for (int a = (1); a <= (H[i]); ++a) {
if (a > 0) {
if (!((C[t % K] == (1 - i)) || (C[t % K] == 2))) {
X[i][t + 1]... | 16 |
#include <bits/stdc++.h>
using namespace std;
int a[7];
int sum1, sum2;
bool ans;
int main() {
cin >> a[1] >> a[2] >> a[3] >> a[4] >> a[5] >> a[6];
sort(a + 1, a + 7);
int sum = a[1] + a[2] + a[3] + a[4] + a[5] + a[6];
for (int i = 1; i <= 6; i++) {
for (int j = i; j <= 6; j++) {
for (int k = j; k <= ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000 * 1000 * 1000 + 7;
const int INF = 1e9 + 100;
const long long LINF = 1e18 + 100;
int n;
long long dp[410][410];
int32_t main(void) {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
cin >> n;
dp[n][0] = dp[n][1] = 1;
for (int h = n ... | 20 |
#include <bits/stdc++.h>
using namespace std;
int ft[200];
int tag[200];
int find_ft(int x) {
if (ft[x] != x) ft[x] = find_ft(ft[x]);
return ft[x];
}
void unite(int x, int y) {
x = find_ft(x);
y = find_ft(y);
if (x != y) ft[y] = x;
}
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) ft[i... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long a[200010], n, k;
string s;
vector<long long> v[200010];
bool cmp(long long x, long long y) { return x > y; }
signed main() {
ios::sync_with_stdio(false);
cin >> n >> k;
for (long long i = 1; i <= n; i++) cin >> a[i];
cin >> s;
long long w = 1;
v[w].pus... | 5 |
#include <bits/stdc++.h>
using namespace std;
bool isleap(int y) {
if (y % 400 == 0) return true;
if (y % 4 == 0 && y % 100 != 0) return true;
return false;
}
int nday(int y) { return (isleap(y)) ? 366 : 365; }
int main() {
int y;
cin >> y;
int yleap = isleap(y);
int sum = nday(y);
y++;
int m = 7;
w... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, cont = 0;
cin >> a >> b;
int c[a], d[b];
vector<int> valores;
for (int i = 0; i < a; i++) {
cin >> c[i];
}
for (int i = 0; i < b; i++) {
cin >> d[i];
}
for (int i = 0; i < a; i++) {
for (int j = 0; j < b; j++) {
if ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000000;
int n, m, a[N];
bitset<1024> prime, msk1;
int lv[N], rv[N];
int cnt = 0;
vector<int> g[N];
bitset<1024> t[500000];
long long pu[500000];
void buildprime() {
for (int i = 0; i < m; i++) {
msk1.set(i, 1);
if (i >= 2) prime.set(i, 1);
for (... | 20 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-5;
struct Point {
double x, y;
Point() {}
Point(double __x, double __y) {
x = __x;
y = __y;
}
inline Point operator+(const Point &p) const {
return Point(x + p.x, y + p.y);
}
inline Point operator-(const Point &p) const {
... | 15 |
#include <bits/stdc++.h>
using namespace std;
vector<long long int> divisors;
bool a[5205][5205];
long long dp[5205][5205];
map<char, long long> m;
long long power(long long a, long long b) {
if (b == 0) return 1;
if (b == 1) return a;
if (b % 2 == 1) return (power(a, b - 1) * a) % 1000000007;
long long q = pow... | 10 |
#include <bits/stdc++.h>
int main() {
int n, m;
scanf("%d", &n);
int L[n], W[n], H[n];
for (int i = 0; i < n; i++) {
scanf("%d%d%d", &L[i], &W[i], &H[i]);
}
scanf("%d", &m);
int l[m], w[m], p[m];
for (int i = 0; i < m; i++) {
scanf("%d%d%d", &l[i], &w[i], &p[i]);
}
int t = 0;
for (int i = ... | 8 |
#include <bits/stdc++.h>
using namespace std;
string i_s(int x) {
if (x == 0) return "0";
string ret = "";
while (x) {
ret = ret + (char)(x % 10 + '0');
x /= 10;
}
reverse(ret.begin(), ret.end());
return ret;
}
string add(string a, string b) {
if (a == "") a = "0";
if (b == "") b = "0";
if (a.... | 9 |
#include <bits/stdc++.h>
using namespace std;
struct point {
long long x, y;
point() {
x = 0;
y = 0;
}
point(long long xx, long long yy) {
x = xx;
y = yy;
}
void scan() { cin >> x >> y; }
void print() { cout << x << " " << y << "\n"; }
long long operator*(const point &p) const { return x... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, m, num[500005], low[500005], rig = 0, numCircle = 0;
int belong[500005], pos[500005], z[500005];
pair<int, int> l1[500005], l2[500005];
vector<pair<int, int> > g[500005];
vector<int> circle[500005];
stack<int> st;
queue<int> qu;
priority_queue<pair<int, int> > pr;
vo... | 21 |
#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
using namespace std;
namespace ywy {
inline int get() {
int n = 0;
char c;
while ((c = getchar()) || 23333) {
if (c >= '0' && c <= '9') break;
if (c == '-') goto s;
}
n = c - '0';
while ((c = getch... | 19 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
long long x, k, y;
int A[200003], B[200003];
bool bol = 1;
long long solve(vector<int> &vec, int mx) {
int sz = vec.size();
bool big = 0;
for (int x : vec) big |= (x > mx);
if (!vec.size()) return 0;
if (vec.size() < k && big) {
bol = 0;
return 0... | 12 |
#include <bits/stdc++.h>
using namespace std;
void _print(long long int t) { cerr << t; }
void _print(int t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(long double t) { cerr << t; }
void _print(double t) { cerr << t; }
void _print(unsigned long long t) { cerr << t... | 0 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
long long b, g, n;
cin >> b >> g >> n;
long long ans = 0;
for (long long i = 0; i <= b; ++i) {
if (((n - i) <= g) && ((n - i) >= 0)) {
++ans;
}
}
cout << ans << "\n";
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int prime[1000005];
void find() {
memset(prime, 0, sizeof(prime));
for (int i = 2; i < 1000005; i++)
if (!prime[i]) {
for (int j = i * 2; j < 1000005; j += i) prime[j] = 1;
}
}
int dis(int s, int t, int k, int n) {
if (t == n) {
return t - s - 1 + k;... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long oo = 1e17 + 11;
const int N = 2e5 + 11;
vector<string> patterns;
void solve() {
int n, m;
cin >> n >> m;
string s;
cin >> s;
s = " " + s;
vector<vector<int> > f(6, vector<int>(n + 1, 0));
for (int i = 0; i < 6; ++i) {
for (int j = 1; j <= n... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
string s;
cin >> s;
bool b1 = true;
if (n % 2 == 0) {
for (int i = 0; i < n; i = i + 2) {
if ((s[i + 1] - '0') % 2 == 0) ... | 1 |
#include <bits/stdc++.h>
int main() {
int i, j, x, elephant = 0, bear = 0, A[10] = {0}, count = 0, good = 0;
for (i = 0; i < 6; i++) {
scanf("%d", &x);
A[x]++;
if (A[x] == 1) {
count++;
}
if (A[x] == 4) {
good = 1;
}
if (A[x] == 5) {
bear = 1;
}
if (A[x] == 6) {... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MOD(1000000007);
const int INF((1 << 30) - 1);
const int MAXN(105);
int n, m, a[MAXN], b[MAXN];
string s[MAXN];
bool flag[MAXN][MAXN];
vector<int> dp[MAXN][MAXN];
vector<int> DP(int f, int l) {
if (flag[f][l]) return dp[f][l];
flag[f][l] = true;
if (f == l) ... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000100, L = 5000500, BufL = 220;
char ch[N + L] = {}, buf[BufL] = {};
int n, r, c, l, a[N] = {}, p[N] = {}, f[N] = {}, g[N] = {};
int main() {
gets(buf + 1);
sscanf(buf + 1, "%d%d%d", &n, &r, &c);
gets(ch + 1);
l = strlen(ch + 1);
for (int i = 1, to... | 13 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const long long mod = 1e9 + 7;
const int N = 1e5 + 10;
const int LOGN = 30;
int base[LOGN];
int arr[N];
int ans[N];
long long pows[N];
vector<pair<int, int> > queries[N];
int basis_size = 0;
bool try_gauss(int v, int more) {
for (int i = LOGN -... | 16 |
#include <bits/stdc++.h>
using namespace std;
bool compare(pair<int, pair<int, int> > a, pair<int, pair<int, int> > b) {
if (a.second.second == b.second.second) {
return a.second.first < b.second.first;
}
return a.second.second < b.second.second;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
... | 13 |
#include <bits/stdc++.h>
using namespace std;
int a[300001], siz[300001], res;
vector<int> e[300001];
int dfs(int u, int fa, int lim) {
int cnt = siz[u] = 1, max1 = 0, max2 = 0;
for (int i = 0; i < e[u].size(); i++) {
int to = e[u][i];
if (to != fa) {
int cur = dfs(to, u, lim);
if (cur == siz[to... | 18 |
#include <bits/stdc++.h>
using namespace std;
int a[100010], b[100010];
long long sum;
int n;
inline void check(long long mid) {
for (int i = 1; i <= n; i++) {
if (a[i] - 1 < mid)
b[i] = 0;
else if (((a[i]) - 1 - 3ll * (a[i]) * (a[i]) - 3ll * (a[i])) >= mid)
b[i] = a[i];
else {
long long... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 6e4;
vector<int> adj[maxn];
pair<int, int> Head[300];
pair<int, int> Tail[300];
int hig[maxn];
bool markBFS[maxn], mark[maxn];
int markDFS[maxn];
int draw;
vector<int> top;
int dp[maxn];
void dfs(int x) {
markDFS[x] = 1;
for (int i = 0; i < adj[x].size(... | 13 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 111111;
pair<long long, long long> stud[N];
long long ttoi[N], ans[N];
set<long long> off[N];
long long n, m;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for (long long i = (1); i <= (n); i++) {
long long t, x... | 7 |
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define vec vector
#define psb push_back
#define ppb pop_back
#define mkp make_pair
#define fst first
#define scd second
#define ins insert
#define psf push_front
#define ppf pop_front
using namespace std;
int main() {
ios_base :: sync_with_stdio(fals... | 7 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
istream &operator>>(istream &in, vector<T> &arr) {
for (auto &elem : arr) in >> elem;
return in;
}
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
void Solve() {
int la, lb, ra, rb, ta, tb, da, db;
cin >> la >> ra >> ta;
cin >> lb >... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int n;
cin >> n;
cin >> s;
map<char, double> m;
m['L'] = 1.0, m['R'] = -1.0, m['U'] = 1000, m['D'] = -1000;
double c = 0;
int ans = 0;
for (int i = 0; i < n; i++) {
c = 0;
for (int j = i; j < n; j++) {
c += m[s[j]];
... | 2 |
#include <bits/stdc++.h>
using namespace std;
map<long long, long long> m;
int q;
long long loga(long long x) {
if (x == 1) return 0;
return 1 + loga(x / 2);
}
int main() {
cin >> q;
for (int qq = 1; qq <= q; qq++) {
int tip;
cin >> tip;
if (tip == 1) {
long long u, v, cost;
cin >> u >> ... | 7 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2e5 + 5;
const ll mod = 1e15;
const ll base = 1e6;
ll m, k, a[N], n, ans, u, v, tong, b[N], c[N], t, d[N];
vector<ll> adj[N], kq;
struct dang {
ll l, r, val;
dang() { l = r = val = 0; }
} st[N * 4], nul;
ll cost(ll i, ll j) { return 2... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
setvbuf(stdin, NULL, _IOFBF, 10000);
setvbuf(stdout, NULL, _IOFBF, 10000);
int n;
scanf("%d", &n);
int arr[102400];
for (int i = 0; i < n; ++i) {
scanf("%d", &arr[i]);
}
bool marked[2124000];
int prev[102400];
prev[0] = arr[0];
int sto... | 8 |
#include <bits/stdc++.h>
template <typename element_type>
std::vector<element_type> read_vector(int size);
std::vector<int> partial_sums(const std::vector<int>& v);
using namespace std;
int main() {
int stickers;
while (cin >> stickers) {
vector<int> sticker = read_vector<int>(stickers);
vector<int> partial... | 14 |
#include <bits/stdc++.h>
using namespace std;
bool store[1501][1501];
bool reachable[1501][1501];
int recordx[1501][1501];
int recordy[1501][1501];
int startx, starty;
bool flood_fill(int n, int m, int x, int y) {
if (!store[((x % n) < 0 ? (x % n) + n : (x % n))]
[((y % m) < 0 ? (y % m) + m : (y % m))])
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char h;
char a, a1, b, b1, c, c1, d, d1;
cin >> a >> a1 >> h >> b >> b1 >> c >> c1 >> h >> d >> d1;
int ai, bi, ci, di;
ai = (a - '0') * 10 + (a1 - '0');
bi = (b - '0') * 10 + (b1 - '0');
ci = (c - '0') * 10 + (c1 - '0');
di = (d - '0') * 10 + (... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
long long left = 0, right = 0;
int pivot = 0;
for (int i = 0; i < s.length(); i++) {
if (s[i] == '^') pivot = i;
}
for (int i = 0; i < s.length(); i++) {
if (i < pivot) {
if (s[i] != '=') {
left += (s[i] -... | 1 |
#include <bits/stdc++.h>
using namespace std;
int a[2020];
int main() {
int t, n;
bool f1, f2;
ifstream in("in");
cin >> t;
while (t > 0) {
f1 = false;
f2 = false;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] % 2 == 0)
f1 = true;
else
f2 = tru... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <class BidirIt>
BidirIt prev(BidirIt it,
typename iterator_traits<BidirIt>::difference_type n = 1) {
advance(it, -n);
return it;
}
template <class ForwardIt>
ForwardIt next(ForwardIt it,
typename iterator_traits<ForwardIt>::differenc... | 14 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1, c = getchar();
while (c < 48) c == '-' && (f = -1), c = getchar();
while (c > 47) x = x * 10 + c - '0', c = getchar();
return x * f;
}
const long long INF = 1ll << 62;
const int MAXN = 500005;
struct Edge {
int to, val;
};
std... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i;
string str;
cin >> n >> str;
for (i = 0; i < n; i++)
if (str[i] == '0') {
str[i++] = '1';
break;
} else {
str[i] = '0';
}
printf("%d", i);
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
template <typename T, typename U>
inline istream &operator>>(istream &in, pair<T, U> &p) {
in >> p.first >> p.second;
return in;
}
template <typename T>
inline istream &operator>>(istream &in, vector<T> &v) {
for (T &x : v) in >> x;
return ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int j, k, m, i, n;
int b[1001];
pair<int, int> a[10];
int ras(int first, int second, int a, int b) {
return ((first - a) * (first - a)) + ((second - b) * (second - b));
}
int prov() {
int k = 0, l = 0, i;
pair<int, int> t[10];
pair<int, int> r[10];
for (i = 0; i <... | 8 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long a = 0;
char c = getchar();
bool f = 0;
while (!isdigit(c)) {
if (c == '-') f = 1;
c = getchar();
}
while (isdigit(c)) {
a = (a << 3) + (a << 1) + (c ^ '0');
c = getchar();
}
return f ? -a : a;
}
const long ... | 16 |
#include <bits/stdc++.h>
using namespace std;
long long s[1000005], n, x;
int main() {
cin >> n;
long long c = 0, i;
for (i = 1; i <= n; i++) {
cin >> x;
s[i] = s[i - 1] + x;
}
for (i = 1; i < n; i++) {
if (s[i] - s[0] == s[n] - s[i]) {
c++;
}
}
cout << c << endl;
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
namespace seg {
int ls[15000010];
int rs[15000010];
int s[15000010];
int cnt = 0;
int insert(int p, int x, int l, int r) {
int q = ++cnt;
ls[q] = ls[p];
rs[q] = rs[p];
s[q] = s[p] + 1;
if (l == r) return q;
int mid = (l + r) >> 1;
if (x <= mid)
ls[q] = ins... | 25 |
#include <bits/stdc++.h>
using namespace std;
long long int greatestSubarraySum(long long int array[], long long int n);
long long int binarySearch(vector<long long> arr, long long int l,
long long int r, long long int x);
long long int modpower(long long int x, long long int y, long long int... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int red, blue;
cin >> red >> blue;
cout << min(red, blue) << " " << (max(red, blue) - min(red, blue)) / 2
<< endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string tmp;
getline(cin, tmp);
int p = 'A' - 'a';
for (int k = 0; k < tmp.length(); k++) {
if (tmp[k] >= 'A' && tmp[k] <= 'Z') tmp[k] -= p;
}
int i = tmp.length() - 1;
while (tmp[i] == ' ' || tmp[i] == '!' || tmp[i] == '?' || tmp[i] == ',') {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int arr[11][101][3];
int main() {
memset(arr, 0, sizeof arr);
int n, m, k;
cin >> n >> m >> k;
for (int p = 0; p < n; p++) {
string str;
cin >> str;
for (int i = 0; i < m; i++)
cin >> arr[p][i][0] >> arr[p][i][1] >> arr[p][i][2];
}
int mx = 0;
... | 4 |
#include <bits/stdc++.h>
const int N = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-8;
using namespace std;
int n, m;
string s;
long long dp[30];
long long a[30];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
long long ans = 1;
for (int ... | 15 |
#include <bits/stdc++.h>
using namespace std;
void reader(int *x) {
int k, m = 0;
*x = 0;
for (;;) {
(k) = getchar();
if (k == '-') {
m = 1;
break;
}
if ('0' <= k && k <= '9') {
*x = k - '0';
break;
}
}
for (;;) {
(k) = getchar();
if (k < '0' || k > '9') bre... | 16 |
#include <bits/stdc++.h>
using namespace std;
inline void err(istringstream *iss) {}
template <typename T, typename... Args>
void err(istringstream *iss, const T &$val, const Args &...args) {
string $name;
*iss >> $name;
if ($name.back() == ',') $name.pop_back();
cout << $name << " = " << $val << "; ", err(iss,... | 12 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const long double pi = acos(-1.0);
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int digarr[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
const int dxo[8] = {-... | 18 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(register T &x) {
register long long ff = 1;
x = 0;
register char c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-') ff = -1;
for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
x *= ff;
}
t... | 16 |
#include <bits/stdc++.h>
using namespace std;
const double TL = 1.5 * CLOCKS_PER_SEC;
mt19937 rng(
(unsigned int)chrono::steady_clock::now().time_since_epoch().count());
const double pi = acos(-1.0);
const long long mod = 1e9 + 7;
int main() {
int T;
scanf("%d", &T);
while (T--) {
int n;
scanf("%d", &... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
bool cross(long long int x1, long long int y1, long long int x2,
long long int y2, long long int x3, long long int y3) {
x2 -= x1;
y2 -= y1;
x3 -= x1;
y3 -= y1;
return x2 * y3 - y2 * x3 > 0;
}
int main() {
ios_base::... | 8 |
#include <bits/stdc++.h>
long long n, i, d;
int main() {
scanf("%I64d", &n);
d = 1;
for (long long i = 2; i * i <= n; ++i) {
if (n % i == 0) {
d = i;
break;
}
}
if (d == 1) {
printf("1");
} else if (d == 2) {
printf("%I64d", n / 2);
} else {
printf("%I64d", 1 + ((n - d) / 2... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
const int MAXP = 1e7 + 5;
const int MAXLOG = 20;
template <typename T>
void chkmax(T &x, T y) {
x = max(x, y);
}
template <typename T>
void chkmin(T &x, T y) {
x = min(x, y);
}
template <typename T>
void read(T &x) {
x = 0;
int f = 1;
cha... | 27 |
#include <bits/stdc++.h>
using namespace std;
map<int, int> cnt;
map<int, int> fnt;
int main() {
int n, flag = 0;
set<int> store;
set<int>::iterator it;
scanf("%d", &n);
int half = n / 2;
if (n % 2 == 1) half++;
for (int i = 1; i <= n; i++) {
int f, b;
scanf("%d %d", &f, &b);
if (f != b) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, dis, i = 0;
cin >> n >> dis;
string s1;
cin >> s1;
for (; i < s1.length(); i++) {
if (dis == 0) break;
if ((int)s1[i] - 'a' > 'z' - (int)s1[i]) {
while (dis != 0 && (int)s1[i] != 'a') {
(int)s1[i]--;
dis--;
}... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 100000;
const int MaxHalf = MaxN / 2;
int main() {
int n;
static char s[MaxN + 1];
cin >> n;
scanf("%s", s);
if (n % 2 == 1) {
cout << 0 << endl;
return 0;
}
int half = n >> 1;
int nL = 0;
static unsigned f[MaxHalf + 1];
f[0] = 1... | 21 |
#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <size_t N>
str... | 22 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string x;
cin >> x;
int cC = 0, cS = 0;
for (int i = 0; i < x.size(); i++) {
if (isupper(x[i]))
cC++;
else
cS++;
}
if (cS > cC || cS == cC) {
for (int i = 0; i < x.size(); i++) x[i] = tolower(x[i]);
} else {
for (int i ... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d, n, m, k, q, l, r;
string s;
int main() {
ios::sync_with_stdio(false);
cin >> l >> r;
a = r - l;
if (r - l < 100) {
map<long long, long long> mp;
map<long long, long long>::iterator it;
for (int i = l; i <= r; i++) {
a = i;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5 + 10;
int d[maxN];
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
string str;
cin >> str;
int res = 0, n = str.size();
for (int i = 0; i < n; i++)
if ('A' <= str[i] && str[i] <= 'Z') d[0]++;
for (int i = 1; i <= n; i++)... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
struct data {
int u;
int v;
int w;
int can;
int idx;
bool operator<(const data &other) const { return w < other.w; }
void read(int i) {
scanf("%d%d%d", &u, &v, &w);
idx = i;
}
};
bool cmp(data u, data v) { return u.idx < v.idx... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
char ans[] = {'y', 'e', 's', '\0'};
scanf("%d", &n);
int a[n], flg = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
if (i > 0) {
if ((!flg and a[i] < a[i - 1]) or (flg and a[i] > a[i - 1]))
strcpy(ans, "no\n");
}... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> A(n);
for (__typeof(0) i = (0); i < (n); i++) cin >> A[i];
sort(A.begin(), A.end());
int ans = 0, i = 0;
while (i < ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, x, p[2000];
int main() {
cin >> n >> x;
for (int i = 1; i <= n; i++) {
int a, b;
cin >> a >> b;
if (a > b) {
swap(a, b);
}
p[a]++;
p[b + 1]--;
}
for (int i = 1; i <= 1000; i++) {
p[i] = p[i] + p[i - 1];
}
int mn = 1e9;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int h, w, flag = 0;
cin >> h >> w;
char a[h][w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
char c;
cin >> c;
a[i][j] = c;
}
}
for (int i = 1; i < h - 1; i++) {
for (int j = 1; j < w - 1; j++) {
i... | 5 |
#include <bits/stdc++.h>
using namespace std;
int i, j, m, n;
int r() {
char ch = getchar();
int ans = 0, f = 1;
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
ans *= 10;
ans += ch - '0';
ch = getchar();
}
return ans * f;
}
int ... | 11 |
#include <bits/stdc++.h>
static const unsigned int maxn = 400000000;
static const unsigned int maxp = 20000 + 10;
unsigned int f[4][maxp], g[4][maxp];
unsigned int n, m, A, B, C, D, ans, res, tmp, rt;
unsigned int p1(unsigned int x) {
unsigned int y = x + 1;
if (x % 2 == 0)
x /= 2;
else
y /= 2;
return x... | 17 |
#include <bits/stdc++.h>
using namespace std;
struct pt {
long long int x, y;
};
long long int crossprod(pt a, pt b) { return a.x * b.y - a.y * b.x; }
bool bot(pt a) { return a.y < 0 || a.y == 0 && a.x < 0; }
bool operator<(pt a, pt b) {
bool ta = bot(a);
bool tb = bot(b);
if (ta != tb) return ta;
return cros... | 15 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
int a[200005];
int pos[200005];
int b[200005];
int vis[200005];
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n, k;
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
pos[a[i]] = ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
scanf("%d", &N);
int A[N];
int sum = 0;
for (int i = 0; i < N; i++) {
scanf("%d", &A[i]);
sum += A[i];
if (i > 0) A[i] += A[i - 1];
}
int half = (sum / 2) + (sum % 2);
for (int i = 0; i < N; i++) {
if (A[i] >= half) {
... | 5 |
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=500+13,mod=998244353;
inline int qpow(int a,int k){int s=1;for(;k;k>>=1,a=1ll*a*a%mod)if(k&1)s=1ll*s*a%mod;return s;}
int n,a[N],f[N],b[N];
inline void solve(){
scanf("%d",&n);
for(int i=1;i<=n;++i){
char op;cin>>op;
if(op=='+'... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = 303;
const int M = 10;
deque<int> xc[M][M], xd[M][M];
vector<int> a[N][N], b[N][N], c[N][N];
char str[123456];
int cnt[2][N][2];
int n, m;
vector<tuple<int, int, int, int> > ans;
void transposta(int x) {
if (x) {
for (int i = 0; i < n; i++)
for (in... | 16 |
#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using vi = vector<lli>;
using vvi = vector<vi>;
using pii = tuple<lli, lli>;
using vii = vector<pii>;
using vvii = vector<vii>;
string TYPE(const int*) { return "%d"; }
string TYPE(const lli*) { return "%lld"; }
string ... | 11 |
#include <bits/stdc++.h>
using namespace std;
template <typename TYPE>
inline TYPE sqr(const TYPE& a) {
return (a) * (a);
}
const int INF = 1000 * 1000 * 1000;
const long double EPS = 1e-9;
const long double PI = 2 * acos(0.0);
const int N = 2100;
int n;
int d[N][N];
int e[N][N];
vector<pair<int, int> > g[N];
vector<... | 11 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > tab(400001);
int ij[400001], a, b, n, ji[400001], i, v[400001];
int s[400001], is = 0, par[400001], sson[2][400001], son[400001], mxson[400001],
ss[400001];
int main() {
scanf("%d", &n);
for (int z = 1; z < n; z++)
scanf("%d %d", ... | 15 |
#include <bits/stdc++.h>
using namespace std;
int n, x, num[100005], num2[100005];
int v1[100005], v2[100005];
int main() {
scanf("%d%d", &n, &x);
for (int i = 1; i <= n; i++) {
scanf("%d", &num[i]);
if (!v1[num[i]])
v1[num[i]]++;
else {
printf("0");
return 0;
}
}
for (int i = ... | 4 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const long long inf = 2000000000000000000LL;
vector<long long> a;
void gen(long long current) {
if (current > inf) {
return;
}
if (current > 0) {
a.push_back(current);
}
gen(current * 10LL + 4LL);
gen(current *... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, inicio, fin;
cin >> n >> inicio >> fin;
string ruta;
cin >> ruta;
if (inicio == fin || ruta[inicio - 1] == ruta[fin - 1]) {
cout << 0 << '\n';
} else {
cout << 1 << '\n';
}
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int x1, y1;
long long int n;
cin >> n;
map<long long int, long long int> x;
map<long long int, long long int> y;
map<pair<long long int, long long int>, long long int> both;
for (long long int i = 1; i <= n; i++) {
cin >> x1 >> y1;
... | 6 |
#include <bits/stdc++.h>
const int dx[] = {0, -1, 0, 1, -1, 1, 1, -1, -2, -2, 2, 2, -1, -1, 1, 1};
const int dy[] = {-1, 0, 1, 0, 1, 1, -1, -1, -1, 1, -1, 1, -2, 2, -2, 2};
using namespace std;
vector<int> graph[200005];
vector<int> opt(200005);
int dfs(int node) {
if (opt[node]) return opt[node];
int ret = 0;
fo... | 2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.