solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
long long t, l, r;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> t;
while (t--) {
cin >> l >> r;
if (l <= (r / 2) + 1)
cout << r % (r / 2 + 1) << '\n';
else
cout << r % l << '\n';
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const long long INF = 1e18;
int main() {
int n;
scanf("%d", &n);
if (n % 4)
printf("! -1\n"), fflush(stdout);
else {
printf("? 1\n");
fflush(stdout);
int A;
scanf("%d", &A);
printf("? %d\n", 1 + n / 2);
fflush(st... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int MX = 10002;
bitset<MX> tree[MX * 4], ans, tt;
int n, QN, st, en, V;
vector<int> v[MX * 4];
void update(int x, int a, int b) {
if (st > b || en < a) return;
if (a >= st && b <= en) {
v[x].push_back(V);
return;
}
update(x * 2, a, (a + b) / 2);
upda... | 14 |
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 5e5 + 5;
const long long MOD = 1e9 + 7;
long long n, x, y, b[MAXN], c[MAXN], d[MAXN], num[MAXN], sum[MAXN];
struct node {
long long x, y;
} a[MAXN];
long long lowbit(long long x) { return x & -x; }
void add(long long x, long long y) {
while (x) {
... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int ms = 2e+5 + 9;
long long vet[ms], maxi = 0, x, y, segSum[ms], seg[ms];
int n, k, ind[ms];
int main() {
long long back, soma = 0;
cin >> n >> k;
for (int i = 0; i < n; i++) cin >> vet[i];
for (int i = 1; i < n; i++) vet[i] += vet[i - 1];
for (int i = 0; i... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 123;
long long sum[N];
set<long long> s;
map<long long, long long> m;
int main() {
ios::sync_with_stdio(false);
long long n, k, ans = 0;
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> sum[i], sum[i] += sum[i - 1];
s.insert(1);
long long t... | 10 |
#include <bits/stdc++.h>
using namespace std;
priority_queue<int, vector<int>, greater<int> > PQ;
int a[100010];
inline int Max(int a, int b) { return a > b ? a : b; }
int main() {
int n, k;
long long Tot;
while (scanf("%d%d", &n, &k) != EOF) {
scanf("%I64d", &Tot);
for (int i = 1; i <= n; ++i) {
sc... | 9 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
ll x;
cin >> x;
auto find_sol = [&](ll n) -> ll {
ll a1 = n * n;
ll c1 = n * n * (n - 1);
c1 /= 2;
ll a2 = n * (n - 1);
a2 /= 2;
ll c2 = (n - 1) * n * (2 * n -... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, a[1010], b[1010];
int x[1010], y[1010], cnt;
int c[1010];
bool vis[1010] = {0};
int main() {
scanf("%d", &n);
for (int i = 1; i < n; i++) {
scanf("%d%d", &a[i], &b[i]);
vis[a[i]] = vis[b[i]] = 1;
c[a[i]]++;
c[b[i]]++;
}
for (int i = 1; i < n; ... | 11 |
#include <bits/stdc++.h>
const int maxn = 2e5 + 3;
int n, p[maxn], t[maxn], et[maxn];
std::vector<int> E[maxn];
std::vector<std::pair<int, int>> ans;
void dfs(int u) {
ans.emplace_back(u, t[u]);
int c = t[u];
bool r = false;
for (auto &&v : E[u]) {
if (v == p[u]) continue;
if (!r && c >= E[u].size()) {
... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string arr[3];
for (int i = 0; i < 3; i++) {
cin >> arr[i];
}
map<char, int> ma;
ma['A'] = 0;
ma['B'] = 0;
ma['C'] = 0;
for (int i = 0; i < 3; i++)
if (arr[i][1] == '>') {
ma[arr[i][0]]++;
ma[arr[i][2]]--;
} else {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int occ[27];
memset(occ, 0, sizeof occ);
int mx = 0;
if (s[0] != 'a') {
cout << "NO";
return 0;
}
for (int i = 0; i < s.size(); ++i) {
occ[(int)(s[i] - 'a')]++;
if (s[i] < 'a' || s[i] > 'z') {
cout << "N... | 3 |
#include <bits/stdc++.h>
using namespace std;
struct Point {
long double x, y;
Point(){};
Point(long double a, long double b) {
x = a;
y = b;
}
void input() { cin >> x >> y; }
};
long double ra(Point a, Point b) {
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
long double ra_p... | 14 |
#include <bits/stdc++.h>
using namespace std;
bool debug;
const int inf = 1e9 + 5;
const int nax = 1e6 + 5;
const int czapa = 1048576;
struct wezel {
int zmiana, i4, i7, w47, w74;
};
int n, m, c, dd;
char s[100], t[nax];
wezel d[2 * czapa];
void insert(int w, int rozmiar, int nalewo, int a, int b) {
if (rozmiar == ... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 10;
int dp[2 * N][N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> p(2 * n);
for (auto& i : p) {
cin >> i;
}
reverse(p.begin(), p.end());... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long n, k;
inline long long sum(long long m) { return m * (m + 1) / 2; }
inline long long sum(long long s, long long e) {
if (s <= 1) return sum(e);
return sum(e) - sum(s - 1);
}
long long BS() {
long long lo = 1, hi = k;
while (hi > lo) {
long long mid = (... | 9 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
#define endl "\n"
#define rep(i,a,b) for(int i=a; i<b; i++)
#define re(i,a) for(int i=0; i<a; i++)
#define red(i,a) for(int i=a; i>=0; i--)
#define repd(i,a,b) for(int i=a; i>=b; i--)
#define vll vector<... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, i;
cin >> n;
long long int a[n];
for (i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
long long int fmax, a1, a2, a3, a4, a5, a6;
{
a1 = a[n - 1] * a[n - 2] * a[n - 3] * a[n - 4] * a[... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n1, n2, k1, k2;
cin >> n1 >> n2 >> k1 >> k2;
if (n1 <= n2)
cout << "Second\n";
else
cout << "First\n";
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
char s[105];
int n, R, B, Y, G, j;
bool found;
int main() {
scanf("%s", &s);
n = strlen(s);
R = B = Y = G = 0;
for (int i = 0; i < n; ++i) {
if (s[i] == '!') {
found = false;
j = 1;
while (i + 4 * j < n) {
if (s[i + 4 * j] != '!') {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t, n, c;
cin >> t;
for (int j = 0; j < t; j++) {
set<int> v;
cin >> n;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
v.insert(x);
}
cout << v.size() << endl;
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m, o, re = 0;
long long res = 0;
char a[510][510];
int num[510][510];
int chk[510 * 510], co[510 * 510], mark[510 * 510];
int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
queue<pair<int, int> > myq;
int main() {
memset(a, 'X', sizeof(a));
int i, j, k, l;
lon... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 14;
int n, m;
struct Edge {
int v, u;
long long w;
int o(int x) { return x == v ? u : v; }
} e[maxn];
vector<Edge*> g[maxn];
vector<Edge*> cyc, cur;
Edge* par[maxn];
int col[maxn];
long long c[maxn];
int mark[maxn];
bool dfs(int v = 0, int c = 1... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, m, used[N], d[N];
long double val, a[N];
vector<pair<int, int>> g[N];
vector<pair<int, long double>> vals;
set<long double> x;
void dfs(int v) {
vals.push_back(make_pair(v, a[v]));
used[v] = 1;
for (int i = 0; i < g[v].size(); i++) {
i... | 13 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void __read(T &a) {
cin >> a;
}
template <typename T, typename... Args>
void __read(T &a, Args &...args) {
cin >> a;
__read(args...);
}
constexpr long long M7 = 1000000007ll;
constexpr long long M9 = 1000000009ll;
constexpr long long MFFT = 99824... | 14 |
#include <bits/stdc++.h>
const long long INF = 4e18L + 1;
const int IINF = 2e9 + 1;
const int limit = 1048576;
using namespace std;
const double eps = 1e-12;
bool eq(double a, double b) { return abs(a - b) < eps; }
int main() {
ios_base::sync_with_stdio(0);
int n, k;
cin >> n >> k;
vector<double> p;
vector<in... | 16 |
#include <bits/stdc++.h>
using namespace std;
char s[505][505];
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
scanf("%s", s[i] + 1);
}
int top = 1000, right = -1, buttom = -1, left = 1000;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (s[i][j] == '.') ... | 6 |
#include <bits/stdc++.h>
using namespace std;
vector<long long int> v, v1, v2, v3;
string s1, s2, s3;
int main() {
long long int a[100001] = {0}, b[100001], c = 0, d = 0, i, j, k = 0, l = 0, m,
n, p = 0, q, t, ct = 0, ct1 = 0, ct2 = 0, ck = 0, ck1 = 0,
ck2 = 0, ln, ln1, start, end, mid... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1024;
long long n, m, ans;
long long a[MAXN], b[MAXN];
long long c1, c2, c3, c4;
long long cnt1, cnt2, cnt3, cnt4;
int32_t main() {
cin >> c1 >> c2 >> c3 >> c4;
cin >> n >> m;
for (long long i = 0; i < n; i++) cin >> a[i];
for (long long i = 0... | 3 |
#include <bits/stdc++.h>
using namespace std;
bool check(int, int);
int main() {
int x;
cin >> x;
int ans = 0;
int top = sqrt(x);
for (int j = 1; j <= top; ++j) {
if (x % j == 0) {
if (check(x, j) == true) {
++ans;
}
if (x / j != j && check(x, x / j) == true) {
++ans;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
long long n, b, c = 0;
cin >> n;
stack<long long> s;
map<long long, long long> ma;
queue<long long> q;
for (long long i = 0; i < n; i++) {
cin >> b;
q.push(b);
}
for (l... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 5;
const int maxm = 3e4 + 5;
const int INF = (1U << 31) - 1;
struct edge {
int to, w, next, used;
edge(int to = 0, int w = 0, int next = 0, int used = 0)
: to(to), w(w), next(next), used(used) {}
} G[maxm << 1];
int que[maxn], head[maxn], to... | 18 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-9;
const int INF = 0x3f3f3f3f;
const int MAXN = 1000000 + 10;
long long dp[MAXN][3][3][3];
int n, m;
long long num[MAXN];
void solve() {
for (int i = 1; i <= m; i++) {
for (int j = 0; j < 3; j++) {
for (int k =... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long int m, n, k, t;
vector<vector<pair<long long int, long long int>>> pos;
long long int solve(long long int val) {
long long int i = 0;
long long int ans = 0;
while (i <= n + 1) {
if (i == n + 1) break;
long long int des = i;
if (pos[i + 1].size() ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int lst[10010][30], ptr[30];
char s1[10010], s2[1000010];
int main() {
scanf("%s%s", s1, s2);
int n = strlen(s1), m = strlen(s2);
for (int i = 0; i < n; i++) {
while (ptr[s1[i] - 'a'] <= i) {
lst[ptr[s1[i] - 'a']][s1[i] - 'a'] = i + 1;
ptr[s1[i] - 'a']... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long g[501][501];
long long a[501], b[501];
int n;
long long floyd(int v, int k) {
long long ret = 0;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) {
if (g[i][j] > g[i][v] + g[v][j]) g[i][j] = g[i][v] + g[v][j];
}
for (int i = 1; i <= k;... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a, cnte = 0, cnto = 0;
for (int i = 0; i < n; ++i) {
cin >> a;
if (a % 2)
cnto++;
else
cnte++;
}
if (cnto % 2)
cout << cnto;
else
cout << cnte;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int a, b, c, incr;
long long int x, y;
cin >> x >> y;
int result = 0;
a = b = c = y;
while (true) {
if (a == x && b == x && c == x) break;
result++;
incr = a + b + c - min(a, min(b, c)) - 1;
if (a <= b && a <= c)
a = ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000100;
int n, m, s, t;
vector<int> from[N], to[N];
int outdegree[N];
vector<int> dp(N, 100000000);
bool bb[N];
int main() {
cin >> n >> m;
for (int i = 0; i < (int)m; i++) {
int u, v;
cin >> u >> v;
u--;
v--;
from[v].push_back(u);
... | 18 |
#include <bits/stdc++.h>
const int maxn = 1008;
const long long mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const long long INF = 1e18 + 10;
const double eps = 1e-6;
using namespace std;
struct Node {
long long x, y;
} A[maxn];
int cnt;
int main() {
const long long mmax = 1e16;
long long x0, y0, ax, ay, bx, by, xs... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[222222], cnt[444444];
int main() {
cin >> n;
for (int i = 1; i <= n; cnt[a[i]]++, ++i) cin >> a[i];
for (int i = 1; i <= 400000; ++i) cnt[i] += cnt[i - 1];
sort(a + 1, a + n + 1);
long long res = 0, mx = 0;
for (int i = 1; i <= n; res = 0, ++i) {
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n, x, y;
scanf("%d %d %d", &n, &x, &y);
printf("%d %d\n", min(n, max(1, x + y - n + 1)), min(n, x + y - 1));
}
return 0;
}
| 9 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, i, ans = 0;
cin >> n;
int a[n];
for (i = 0; i < n; ++i) cin >> a[i];
for (i = 1; i < n - 1; ++i) {
if (a[i] == 0 && a[i - 1] && a[i + 1]) {
if (i + 2 < n &... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n <= 2)
cout << -1;
else if (n == 3)
cout << 210;
else {
string s;
s += '1';
for (int i = 0; i < n - 1; i++) {
s += '0';
}
int num = (n - 3);
int c = 50;
for (int i = 0; i < num - 1; i++) ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t[100][100] = {0};
int n;
scanf(" %d", &n);
for (int i = 0; i < n; ++i) {
int x1, y1, x2, y2;
scanf(" %d %d %d %d", &x1, &y1, &x2, &y2);
x1--;
y1--;
x2--;
y2--;
for (int j = x1; j <= x2; ++j) {
for (int k = y1; k <=... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
long arr[n];
for (int i = 0; i < n; ++i) {
scanf("%ld", arr + i);
}
long tmp;
for (int i = 0; i < n; ++i) {
if (i % 2 == 0 && i < n / 2) {
printf("%ld ", arr[n - i - 1]);
arr[n - i - 1] = arr[i];
} else
... | 1 |
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
const int kMaxn = 5555;
int n, a[kMaxn], ok[kMaxn], cnt[55];
char str[kMaxn << 1], s[kMaxn][kMaxn];
bool cmp(int x, int y) { return strcmp(s[x], s[y]) < 0; }
int main() {
static int i, j, k, last;
static int ans, now, best;
memset(str, 0, sizeof(str));
me... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000000LL;
struct node {
int x, y, z;
} E[35];
const int MOD = 1000007;
struct HashMap {
vector<long long> key;
vector<int> V, next;
int head[MOD];
int tot;
void clear() {
tot = 0;
memset(head, -1, sizeof head);
}
bool insert... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, temp;
cin >> a >> b;
if ((a > 1) || (b > 1)) {
if (a > b) {
temp = a;
a = b;
b = temp;
}
if (b <= (2 * a)) {
cout << (a + b) / 3 << endl;
} else {
cout << a << endl;
}
} else {
cout << 0 <<... | 5 |
#include <bits/stdc++.h>
using namespace std;
void cuantospasos(vector<int> &a, int posini, vector<int> &d, int n,
vector<int> &indice0, vector<int> &indice1) {
if (indice0[posini] != -1) d[indice0[posini]] = 0;
if (indice1[posini] != -1) d[indice1[posini]] = 0;
vector<int> v;
vector<int> visi... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n;
int c[maxn];
int ecnt;
int head[maxn], nxt[maxn << 1], to[maxn << 1];
map<int, int> cnt[maxn];
map<int, long long> sum[maxn];
long long ans[maxn];
inline void addedge(int u, int v) {
to[++ecnt] = v;
nxt[ecnt] = head[u];
head[u] = ecnt... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5;
const int64_t INF = 2e18;
int len[MAXN], link[MAXN], sglsddg[MAXN];
int to[MAXN][4];
int sz = 1, last = 0;
void add_letter(int c) {
int cur = sz++;
int p = last;
last = cur;
sglsddg[cur] = len[p];
len[cur] = len[p] + 1;
for (; p != -1 && !t... | 22 |
#include <bits/stdc++.h>
using namespace std;
using llong = long long;
using ld = long double;
using ii = pair<int, int>;
const llong md = 1e9 + 7;
const llong over999 = 1e7;
const ld fover999 = 1e7;
const ld eps = 1e-9;
const ld Pi = acos(-1);
llong n, k;
vector<int> v;
void rec(int l, int r, int ll, int rr) {
if (r... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9;
long long gcd(long long a, long long b) { return (a ? gcd(b % a, a) : b); }
long long power(long long a, long long n) {
long long p = 1;
while (n > 0) {
if (n % 2) {
p = p * a;
}
n >>= 1;
a *= a;
}
return p;
}
int mai... | 7 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const int mod = 998244353;
template <typename T>
T gcd(T a, T b) {
T c;
while (b) {
c = b;
b = a % b;
a = c;
}
return a;
}
template <typename T>
T powmod(T a, T b) {
T res = 1;
a %= mod;
while (b) {
if (b & 1) res = res... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300000;
const int SIZE = 5000;
const long long INF = (long long)1e16;
const double eps = 1e-6;
const long long MOD = 1e9 + 7;
const double PI = M_PI;
int main() {
std::ios::sync_with_stdio(false);
string s;
int n;
cin >> n;
cin >> s;
vector<int>... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d, e, i, j, zx, xc, tes, t, f[200009], seg[600009], za, pas,
lf, rg;
long long fen[200009], ka, ii, jj;
void upd(long long q, long long w) {
while (q <= a) {
fen[q] += w;
q = q + (q & (-q));
}
}
long long read(long long q) {
long long jm... | 17 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
char a[10010], b[10010];
long long dp[5050][5050], ans, len1, len2;
int main() {
scanf("%s%s", a + 1, b + 1);
len1 = strlen(a + 1);
len2 = strlen(b + 1);
for (int i = 1; i <= len1; ++i)
for (int j = 1; j <= len2; ++j) {
if (a... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 60, INF = 1000 * 10000;
const unsigned long long INFER = (1LL << 63) + 10;
vector<pair<int, int> > adj[N];
int d[N][N], mn[N], mx[N], g, b, s, gs, gb, sb, gsb;
unsigned long long c[N][N], ps[N][N][N], ans;
void upd(int x, int y, int z) {
if (x) g++;
if (y)... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[200005], b[200005], n, x = 0;
cin >> n;
for (int k = 1; k < n; k++) {
cin >> a[k];
if (a[k] == 0) k--;
}
for (int k = 1; k < n; k++) {
cin >> b[k];
if (b[k] == 0) k--;
}
for (int k = 1; k < n; k++)
if (a[k] == b[1]) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int ans;
int k;
int main() {
string s;
cin >> s;
for (int i = 0; i < s.length(); i++) {
if (s[i] == '1') {
ans++;
}
}
for (int i = 0; i < s.length(); i++) {
if (s[i] == '0') {
cout << 0;
continue;
}
if (s[i] == '1') {
co... | 6 |
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
template <typename T>
T min(T x, T y) {
return x < y ? x : y;
}
template <typename T>
T max(T x, T y) {
return x > y ? x : y;
};
const long long MAXN = 200005;
const long long mod = 1000000007;
long long po[MAXN + 5], h1[MAXN + 5];
struct tree {
long long h... | 22 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int tt;
cin >> tt;
while (tt--) {
int n, k;
cin >> n >> k;
string s;
cin >> s;
string t = "";
for (int i = 0; i < k; i++) {
t += "()";
}
while (t.size() < s.size()) {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
vector<int> G[100001];
int a[100001];
long long dp[100001][4];
void dfs(int u, int fa) {
long long mx[3] = {0}, mx1 = 0, mx2 = 0;
for (int v : G[u]) {
if (v == fa) continue;
dfs(v, u);
dp[u][2] = max({dp[u][2], mx[0] + dp[v][1] + a[u], mx1 + dp[v][0] + a[u]}... | 18 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long inf = LLONG_MAX;
const long long N = 1e5 + 5;
signed main() {
ios_base ::sync_with_stdio(false);
;
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
stack<long long> stk;
long long ans = 0;
... | 3 |
#include <bits/stdc++.h>
#pragma optimize("O3");
using namespace std;
void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
void DebugInit() { freopen("debug.err", "w+", stderr); }
const long long mod = 1E9 + 7;
const long long inf = LONG_LONG_MAX;
const long long n_inf = LONG_LONG_MIN;
int... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int in, out;
int t;
long long total = 0;
cin >> t;
cin >> out >> in;
vector<int> all;
total += in;
all.push_back(total);
for (int i = 0; i < t - 1; ++i) {
cin >> out >> in;
total = total - out + in;
all.push_back(total);
}
sort... | 0 |
#include <bits/stdc++.h>
using namespace std;
FILE *in;
FILE *out;
const int MAX = 20;
const int MASK = 1048576;
const int INF = 1000000001;
const double EPS = 0.0000000001;
const double PI = 3.1415926535897932;
const double CONV = 0.01745329251994329576923690768489;
struct Light {
double x, y;
double angle;
};
int... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, max = 0;
cin >> n;
long a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
max = 1;
sort(a, a + n);
for (int i = 0; i < n; i++) {
if (a[i] >= max) {
a[i] = max;
max++;
}
}
cout << a[n - 1] + 1;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3 * 1e3 + 5;
int n, m;
struct Edge {
int u, v;
int l, r;
int idx;
Edge() {}
Edge(int _idx, int _u, int _v, int _l, int _r) {
idx = _idx;
u = _u;
v = _v;
l = _l;
r = _r;
}
} e[N];
int pa[N], sz[N];
void initDsu() {
for (int i =... | 12 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
int main() {
ios::sync_with_stdio(false);
ll T;
cin >> T;
vector<ll> p(64);
for (ll d = 1; d < 63; d++) {
ll x = d;
for (ll i = 2; i < d + 1; i++) {
if (!(x % i)) {
x /= i;
if (!(x % i)) {... | 16 |
#include <bits/stdc++.h>
using namespace std;
struct IdxVal {
int idx, val;
};
int main() {
int n, k;
cin >> n >> k;
vector<IdxVal> a;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
a.push_back({i + 1, x});
}
std::sort(a.begin(), a.end(), [](const IdxVal &a, const IdxVal &b) -> bool {
retu... | 2 |
#include <bits/stdc++.h>
using namespace std;
struct point {
int x, y;
};
struct segment {
point a, b;
};
double G[1002][1002];
vector<segment> S;
int a, b;
int N;
double mins[1002];
bool used[1002];
double getLength(point a, point b) {
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
bool so... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long n, x, ans;
map<int, long long> freq;
int main() {
cin >> n >> x;
for (int i = 0; i < n; i++) {
int y;
cin >> y;
ans += freq[y ^ x];
freq[y]++;
}
cout << ans;
return 0;
}
| 7 |
#include <bits/stdc++.h>
using namespace std;
long long x, y, cox, coy;
long long gcd(long long a, long long b) {
while (true) {
a %= b;
if (a == 0) return b;
b %= a;
if (b == 0) return a;
}
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
bool euclid(long long a, long long b)... | 10 |
#include <bits/stdc++.h>
using namespace std;
int f_max(int x, int y) { return x > y ? x : y; }
int f_min(int x, int y) { return x < y ? x : y; }
void f_swap(int &x, int &y) {
int t;
t = x, x = y, y = t;
}
int f_abs(int x) { return x > 0 ? x : -x; }
char s[3][10009];
char ss[3][10009];
int ans;
int dp[10009][28];
i... | 13 |
#include <bits/stdc++.h>
using namespace std;
const unsigned MOD = (1e9) + 7;
struct matrix {
private:
vector<vector<unsigned long long> > a;
int n, m;
public:
void initialize(int x, int y) {
n = x;
m = y;
int i;
a.resize(n);
for (i = 0; i < n; i++) a[i].assign(m, 0);
}
int rows() { ret... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n;
string s[40100];
vector<string> words;
vector<string> v[20];
void task() {
ios_base::sync_with_stdio(false);
cin >> n;
int len = 0;
for (int i = 0; i < n; ++i) {
cin >> s[i];
len += s[i].length();
v[s[i].length()].push_back(s[i]);
}
string ch;... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long n, k, a[100005], b[100005];
bool canWebake(long long ck) {
int temp = k;
for (int i = 0; i < n; i++) {
if (b[i] < a[i] * ck) {
if ((a[i] * ck) - b[i] > temp)
return false;
else
temp -= ((a[i] * ck) - b[i]);
}
}
return tr... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 200005, mod = 1000000007;
long long pow2(long long a, long long b) {
long long ans = 1;
while (b) {
if (b & 1) {
ans = (ans * a) % mod;
}
b /= 2;
a = (a * a) % mod;
}
return ans;
}
long long f[N], c[N];
map<long long, long l... | 12 |
#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
voi... | 3 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int INF = 1e9 + 5;
const int MOD = 1000000007;
const int MOD1 = 998244353;
double pi = 2 * acos(0.0);
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, i, j, a[100001], b[515], c[515], k;
int main() {
scanf("%d", &n);
for (i = 1; i <= n; i = i + 1) scanf("%d", &a[i]);
for (i = 1; i <= 511; i = i + 1) b[i] = 99999999;
for (i = 1; i <= n; i = i + 1) {
b[a[i]] = min(b[a[i]], a[i]);
for (j = 0; j <= 511;... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, k, n, x, y;
cin >> n >> x >> y;
for (i = 0;; i++) {
if (n * y <= (x + i) * 100) break;
}
cout << i << endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-9, PI = acos(-1.);
const int INF = 0x3f3f3f3f, MOD = 1e9 + 7;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const int N = 155;
int n, k, s, a[N];
long long dp[N][N * N];
int main() {
scanf("%d%d%d", &n, &k, &s);
for (int i = 1; i <= n; i++) scanf... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100 + 10;
int n, m, a[N][N], sumRow[N], sumCol[N];
bool markRow[N], markCol[N];
vector<int> Row, Col, ansRow, ansCol;
int main() {
cin >> n >> m;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) {
cin >> a[i][j];
sumRow[i] += a[i][j]... | 13 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T gcd(T a, T b) {
return b ? gcd(b, a % b) : a;
}
template <class T>
inline T LCM(T a, T b) {
if (a < 0) return LCM(-a, b);
if (b < 0) return LCM(a, -b);
return a * (b / gcd(a, b));
}
vector<int> arr;
int main() {
vector<pair<int, int> > ... | 8 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
const int MOD = int(1e9) + 7;
const int MOD2 = 1000000009;
const int INF = 1e9;
const int N = int(3e5) + 7;
struct node {
int sum;
node* l;
node* r;
node(int x) { this->sum = x; }
};
int a[N], b[N];
node* build(int l, int r) {
if (l == r) {
... | 16 |
#include <bits/stdc++.h>
int main() {
int m, n, i = 0, rep = 0;
char s[100];
for (scanf("%d%d", &m, &n); i < m; i++) scanf("%s", &s);
for (i = 1; i < n; i++) rep += s[i - 1] == '.' && s[i] == 'B';
printf("%d", rep += s[0] == 'B');
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
if (a > b) {
a = a + b;
b = a - b;
a = a - b;
}
if (b % a == 0) return a;
return gcd(b % a, a);
}
int lcm(int a, int b) { return (a / gcd(a, b)) * b; }
int prime[200200], pcnt;
int defac[200200][2], d... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int i = 0;
int j = 0;
int ans = 0;
while (j < n) {
i += (ans + 1);
j += i;
if (j > n) break;
ans++;
}
cout << ans << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
vector<pair<int, int>> a(n);
int x, y;
for (int i = 0; i < n; i++) {
cin >> x >> y;
a[i].first = y;
a[i].second = x;
}
vector<pair<int, int>> b = a;
sort(a.begin(), a.end());
vector<pair<int, int>> ans;
i... | 10 |
#include <bits/stdc++.h>
using namespace std;
int contact(int x1, int y1, int r1, int x2, int y2, int r2) {
int dx = x1 - x2, dy = y1 - y2;
int sq_dist = dx * dx + dy * dy;
if (sq_dist >= (r1 + r2) * (r1 + r2))
return -1;
else if (sq_dist <= (r1 - r2) * (r1 - r2)) {
return (r1 < r2) ? +1 : -1;
} else
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int a[200];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t, n, k;
cin >> t;
while (t--) {
cin >> n >> k;
for (int i = 0; i < k; i++) {
cin >> a[i];
}
int ans = 0;
ans = max(a[0], n - a[k - 1] + 1);
for (int... | 2 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
int n;
int a[300005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = (1); i <= (signed)(n); i++) {
cin >> a[i];
}
long long sm = 0;
int cnt = 0;
for (int i = (1); i ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, x, y, z;
cin >> n;
long long a[n], b[n], c[n];
for (int i = 0; i < n; i++) cin >> a[i];
b[0] = c[0] = 0;
for (int i = 1; i <= n; i++) b[i] = b[i - 1] + a[i - 1];
sort(a, a + n);
for (int i = 1; i <= n; i++) c[i] = c[i - 1] + a[i - 1];
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 2000000000;
const long long infLL = 9000000000000000000;
template <typename first, typename second>
ostream& operator<<(ostream& os, const pair<first, second>& p) {
return os << "(" << p.first << ", " << p.second << ")";
}
template <typename T>
ostream& op... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long i, j, k, T, t = 1, l, m, n, x, y, ans = 0, sum = 0;
double dis = INFINITY, p;
double d, a, b;
int main() {
cin >> a >> b;
cin >> n;
for (i = 0; i < n; i++) {
cin >> j >> k >> d;
p = ((a - j) * (a - j) + (b - k) * (b - k) * 1.0);
p = sqrt(p);
... | 1 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "inline", "-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
using namespace std;
template <class T>
void read(T &x) {
int f = 0;
x = 0;
char ch = getchar();
for (; !isdigit(ch); ch = getchar()) f |= (ch == '-');
for (; isdigit(ch); ch = getchar(... | 20 |
#include <bits/stdc++.h>
int main() {
double x1, y1, x2, y2;
scanf("%lf%lf", &x1, &y1);
scanf("%lf%lf", &x2, &y2);
int n;
scanf("%d", &n);
int ans = 0;
for (int i = 0; i < n; i++) {
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
if ((a * x1 + b * y1 + c) * (a * x2 + b * y2 + c) < 0) ans++;
}
pr... | 9 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.