solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int a, b, c, d, x = 0, y = 0, z = 0;
cin >> a >> b >> c >> d;
if (a == 0 || b == 0 || c == 0) z++;
if (a % 2 != 0) x++;
if (b % 2 != 0) x++;
if (c % 2 != 0) x++;
if (x % 3 == 0)
cout << "Yes... | 2 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 3e5 + 66;
const ll inf = 2e18;
struct node {
int L, R;
ll x, y;
node(int a, int b, ll c, ll d) { L = a, R = b, x = c, y = d; }
};
vector<node> lines;
ll a[N], b[N], ans[N], q[N];
int t[N], rem[N], ind[N];
struct line {
ll k, b;
... | 17 |
#include <bits/stdc++.h>
using namespace std;
int n, st, ed, dist[2000005], inq[2000005], prevv[2000005], preve[2000005],
cnt[2000005], que[2000005], x[2000005], vis[2000005];
struct edge {
int to, cap, cost, rev, idx;
};
struct node {
char v1;
int v2, v3;
} op[2000005];
vector<edge> G[2000005];
inline void a... | 19 |
#include<bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
// using namespace __gnu_pbds;
#pragma GCC optimize("O3")
#ifdef LOCAL
#include "/Users/lbjlc/Desktop/coding/debug_utils.h"
#else
#define print(...) ;
#define printn(...) ;
#de... | 13 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:64000000")
const int infi = 1e9 + 7;
const long long infl = 1e18 + 7;
int main() {
cin.sync_with_stdio(false);
cin.tie(0);
char a, b;
cin >> a >> b;
if (a == 'a' || a == 'h') {
if (b == '1' || b == '8')
cout << 3;
else... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 5;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
string s;
cin >> s;
long long n = s.size();
map<char, char> m;
for (long long i = 1; i <= 8; i++) {
char ch1 = (char)(i + '0');
char ch2 = (char)((9 -... | 7 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<char> > vec;
int x2, y2, n, m;
void bfs(int v1, int v2) {
queue<pair<int, int> > q;
q.push({v1, v2});
while (!q.empty()) {
pair<int, int> a = q.front();
q.pop();
for (int i = -1; i <= 1; i++) {
for (int j = -1; j <= 1; j++) {
if... | 12 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double EPS = 1e-15;
using ll = long long;
using ull = unsigned long long;
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9 + 7;
const ll MOD1 = 998244353;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[100001];
int main() {
cin >> n >> k;
long long s = 0;
int mn = 10e10;
for (int i = 0; i < n; i++) {
cin >> a[i];
mn = min(mn, a[i]);
}
for (int i = 0; i < n; i++) {
s += a[i] - mn;
if ((a[i] - mn) % k != 0) {
cout << -1;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
struct Copac {
int x, k;
};
Copac tmp, neg_cop[100], poz_cop[100];
int N, i = 0, j = 0, x, rs = 0;
bool comp(Copac a, Copac b) { return a.x < b.x; }
int main() {
cin >> N;
for (int l = 0; l < N; l++) {
cin >> tmp.x >> tmp.k;
if (tmp.x > 0) {
poz_cop[++i]... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 5000009;
long long md = 2000000063;
long long mdi = 622568113;
long long bs = 257;
long long sv[MAX];
inline long long pow(long long n, long long p) {
if (p == 0) return 1;
if (sv[p]) return sv[p];
long long t = pow(n, p / 2) % md;
if (p % 2) return ... | 14 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int maxn = 1e6 + 4;
const int inf = 1e9;
void read(int &x) {
char ch;
bool flag = 0;
for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == '-')) || 1);
ch = getchar())
;
for (x = 0; isdigit(ch); x = (x << 1) + (x << 3) ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
while (t--) {
int n;
cin >> n;
for (int i = 0; i < n; i++) cout << 1 << " ";
cout << "\n";
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
bool vis[101];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
long long int n;
cin >> n;
string s;
cin >> s;
for (int i = 0; i < n; i++) {
if (s[i] == '.')
vis[i] = 0;
else
vis[i] = 1;
}
int f = 0;
for (int i = 1; i < 26... | 5 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using pl = pair<ll, ll>;
constexpr int MX = 2e5 + 5;
int k;
pl ans;
vector<ii> G[MX];
ll dfs(int u = 1, int p = 0) {
ll ret = 1;
for (ii& v : G[u])
if (v.second != p) {
ll sz = dfs(v.second, u);
ret += sz;... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, m, u, v, cnt;
set<int> g[105];
int main() {
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> u >> v, --u, --v;
g[u].insert(v);
g[v].insert(u);
}
bool Do = 1;
while (Do) {
Do = 0;
stack<pair<int, int> > s;
for (int i = 0; i < n; i+... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct node {
double x, y, v, r;
} p, Q, h, D;
double mid, l, r, alp, thelen;
double l1, l2, l3, a1;
double dis(node a, node b) {
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
bool CorssTheCircle(node a, node b) {
double d1 = fabs(a.x * b.y - b... | 16 |
#include <bits/stdc++.h>
long long n, l, v1, v2, k;
bool OK(long long num, double point1, double point2, double time1) {
if (time1 < 0) return false;
if (num <= 0) return true;
double a1 = (double)(point2 - point1) / (v1 + v2),
a2 = (double)(l - v1 * time1 - point1) / (v2 - v1);
return OK(num - k, poin... | 11 |
#include <bits/stdc++.h>
using namespace std;
int fa[1000111], inv[1000111];
int pv(int a, int b) {
if (b == 0) return 1;
long long r = pv(a, b / 2);
r = r * r % 1000000007;
if (b % 2) r = r * a % 1000000007;
return r;
}
int C(int a, int b) {
return fa[a] * 1ll * inv[a - b] % 1000000007 * inv[b] % 100000000... | 15 |
#include <bits/stdc++.h>
using namespace std;
long long C[2005][2005];
long long fact[2005];
long long mod = 1000000000 + 7;
void nCrModp() {
for (long long i = 0; i < 2002; i++) {
C[i][0] = 1;
for (long long j = 1; j <= i; j++)
C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod;
}
}
int main() {
nCrMo... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int arr[1000], n, i, pos1, cnt1 = 0, cnt2 = 0, pos2;
cin >> n;
for (i = 1; i <= n; i++) {
cin >> arr[i];
}
for (i = 1; i <= n; i++) {
if (arr[i] % 2 == 0) {
cnt1++;
pos1 = i;
} else {
cnt2++;
pos2 = i;
}
}
i... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int N = 1e6 + 4;
vector<int> v[N], vr[N];
int visit[N], scc[N], counter;
stack<int> st;
void dfs(int node) {
visit[node] = 1;
for (int it : v[node])
if (!visit[it]) dfs(it);
st.push(node);
}
void dfs1(int node) {
visit[node] ... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
cin >> str;
for (long long int i = 0;
i < ((long long int)(((long long int)(str).size()))); ++i)
if (str[i] == '<') str[i] = ' ';
for (long long int i = 0;
i < ((long long int)(((long long int)(str).size()))); ++i)
if (... | 2 |
#include <bits/stdc++.h>
int main() {
int n, k, m;
int coun = 0, coun1 = 0;
scanf("%d", &n);
while (n--) {
scanf("%d%d", &k, &m);
if (k > m) {
coun++;
} else if (k < m) {
coun1++;
}
}
if (coun > coun1) {
printf("Mishka\n");
} else if (coun < coun1) {
printf("Chris\n");
... | 0 |
#include <bits/stdc++.h>
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
using namespace ::std;
const int maxn = 1e5 + 300;
const int maxm = 7035;
const int inf = 1e9 + 800;
const int mod = 1e9 + 7;
bitset<maxm> bi[maxn];
bitset<maxm> fl[maxm];
bitset<maxm> ff[maxm];
int main() {
ios_base::sync_with_stdi... | 17 |
#include <bits/stdc++.h>
using namespace std;
string s;
long long n, k, len;
long long aux[1000011], pre[1000011];
long long opt[1000011], cnt[1000011];
long long compDP(long long caseTyp) {
long long total = 0;
for (long long i = 0; i < n; i++) {
if (caseTyp == 0)
aux[i] = (s[i] == tolower(s[i]));
el... | 20 |
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
lli a,b,c;
lli s1=0, s2=0, s3=0;
cin>>a>>b>>c;
vector<lli> nums1(a), nums2(b), nums3(c);
lli mi1=INT_MAX,ma1=INT_MIN;
for(int i=0;i<a... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 3e5 + 10;
const int inf = 2e9;
const double eps = 1e-7;
const long long INF = (long long)1e18;
int main() {
int n;
cin >> n;
bool ok = false;
if (n % 400 == 0) ok = true;
if (n % 4 == 0 && n % 100 != 0) ok = true;
if (ok) {... | 8 |
#include <bits/stdc++.h>
using namespace std;
pair<int, pair<int, int>> P[200005];
struct cmp {
bool operator()(int a, int b) {
if (P[a].second.first != P[b].second.first)
return P[a].second.first < P[b].second.first;
return a < b;
}
};
int main() {
int n, TT;
scanf("%d%d", &n, &TT);
for (int i ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n;
bool vis[500005];
int ans[500005];
int tot[500005];
void sieve() {
for (int i = 2; i <= n; i++) {
if (vis[i] == 0) {
tot[i] = 1;
for (int j = 2; j * i <= n; j++) {
vis[i * j] = 1;
tot[i * j] = max(tot[i * j], max(i, j));
}
... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
if (n == 1) {
cout << 0 << endl;
} else if (n == 2) {
cout << m << endl;
} else if (n > 2) {
cout << m * 2 << endl;
}
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265359;
struct azaza {
azaza() {}
azaza(int x, int y, int dir) : x(x), y(y), dir(dir) {}
bool operator!=(const azaza &a) const {
return !(x == a.x && y == a.y && dir == a.dir);
}
int get() const { return x * 2050 + y + dir * 5000000; }... | 14 |
#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
cerr.writ... | 16 |
#include <bits/stdc++.h>
using namespace std;
unsigned long long int n, m, sum = 1;
unsigned long long int cum;
unsigned long long int i, j;
char c[101][101];
int a[27];
using namespace std;
int main() {
cin >> n >> m;
for (i = 0; i < n; i++) {
cin >> c[i];
}
for (i = 0; i < m; i++) {
memset(a, 0, sizeo... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long int inf = 1e18;
const long long int mod = 1e9 + 7;
inline long long int add(long long int x, long long int y) {
x += y;
if (x >= mod) x -= mod;
return x;
}
inline long long int sub(long long int x, long long int y) {
x -= y;
if (x < 0) x += mod;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long A, B, n;
long long l, t, m;
long long res;
bool _check(long long r) {
return (A + B * (r - 1) <= t) &&
(A * (r - l + 1) + B * (r - 1 + l - 1) * (r - l + 1) / 2 <= m * t);
}
void _input() { cin >> l >> t >> m; }
void _solve() {
long long x = l, y = m *... | 11 |
#include <bits/stdc++.h>
using namespace std;
int a[220000];
set<int> S;
set<int>::iterator r;
bool flag = false;
int ans1, ans2;
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
S.insert(a[i]);
}
sort(a, a + n);
int dis = 1;
for (dis = 1; a[0] + dis <= 100000... | 10 |
#include <bits/stdc++.h>
int main() {
long long int i, n, t, s = 0;
scanf("%lld", &t);
while (t--) {
scanf("%lld", &n);
if (n < 15 || n % 14 == 0 || n % 14 > 6)
printf("NO\n");
else
printf("YES\n");
}
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 500010;
int n, r;
long long k, a[maxn], b[maxn];
bool chk(long long x) {
long long s = 0;
memset(b, 0, sizeof(b));
for (int i = 1; i <= n; i++) {
b[max(1, i - r)] += a[i];
b[min(n, i + r) + 1] -= a[i];
}
for (int i = 1; i <= n; i++) {
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
long long int n, x, y;
cin >> n >> x >> y;
string a;
cin >> a;
long long int c = 0;
for (long long int i = 0; i < x; i++) {
if (a[n - i - 1] == '0' && i == (y))
c++;
else if (a[n - i - 1... | 3 |
#include <bits/stdc++.h>
using namespace std;
struct Node {
int a, b, c;
Node() {}
Node(int _a, int _b, int _c) {
a = _a;
b = _b;
c = _c;
}
};
Node tree[4000000];
int N, Q;
char ins[1000003];
void ini(int x, int l, int r) {
if (l == r) {
if (ins[l] == '(') {
tree[x] = {1, 0, 0};
} el... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long n, a[200200], Res;
long long Before[200200], After[200200], Cnt;
bool in[200200];
vector<long long> v;
vector<long long> numbers;
long long Smaller[200200], Larger[200200];
long long seg[5 * 200200];
void Update(long long node, long long st, long long en, long lon... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
vector<vector<int> > v(n);
map<pair<int, int>, vector<pair<int, int> > > A;
for (int i = 0; i < n; ++i) {
v[i].resize(3);
for (int j = 0; j < 3; ++j) {
scanf("%d", &v[i][j]);
}
A[{v[i][0], v[i][1]}].push_b... | 9 |
#include <bits/stdc++.h>
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
const double dinf = inf;
using namespace std;
const int N = 150000 + 10;
const double eps = 1e-10;
const double PI = acos(-1.0);
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
int n;
char l[N], r[N];
int ... | 7 |
#include <bits/stdc++.h>
using namespace std;
void reloc() {
freopen("/Users/admin/Desktop/cards.in", "r", stdin);
freopen("/Users/admin/Desktop/cards.out", "w", stdout);
return;
}
const int maxn = 100000, s = 500;
int n, d, x, a[maxn + 1], b[maxn + 1], r[maxn + 1], p[maxn + 1], pre,
ans[maxn + 1];
bool ok;
i... | 15 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
template <typename T, typename U>
inline void amin(T &x, U y) {
if (y < x) x = y;
}
template <typename T, typename U>
inline void amax(T &x, U y) {
if (x < y) x = y;
}
template <typename T>
inline void write(T x) {
int i = 20;
char buf[... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
int n;
vector<int> g[N];
pair<int, int> dfs(int cur, int p, const int &k) {
int v[2] = {0, 0};
int complete = 0;
for (auto nxt : g[cur])
if (nxt != p) {
auto ret = dfs(nxt, cur, k);
complete += ret.first;
int incomplete = r... | 20 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
long long r;
while (b != 0) {
r = a % b;
a = b;
b = r;
}
return a;
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
struct Dinic {
int n, s, t, E, adj[150005], flow[150005], cap[150005], ... | 13 |
#include <bits/stdc++.h>
using namespace std;
vector<int> g[1000010];
vector<int> l, r;
const int inf = 1e9;
set<pair<int, int>> cont;
int dist[1000010], from[1000010];
bool addEdge(int p, int q) {
if (p > q) swap(p, q);
l.push_back(p);
r.push_back(q);
g[p].push_back(q);
g[q].push_back(p);
if (cont.find(mak... | 18 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int f = 1, x = 0;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
inline long long readll() {
long long f ... | 21 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t, mod = (1e+9) + 7;
cin >> t;
while (t != 0) {
int n, i;
cin >> n;
map<pair<int, int>, int> m;
for (i = 0; i < n; i++) {
int a;
cin >> a;
m[{a, i}]++;
}
int k = 0, sz = n;
int prev = -1;
whi... | 10 |
#include <bits/stdc++.h>
using namespace std;
struct nodS {
int nr = 0;
nodS *l, *r;
};
void upd(long long x, int b, nodS *poz) {
poz->nr++;
if (b < 0) return;
if ((x >> b) & 1) {
if (poz->r == nullptr) poz->r = new nodS();
upd(x, b - 1, poz->r);
} else {
if (poz->l == nullptr) poz->l = new nodS... | 10 |
#include <bits/stdc++.h>
using namespace std;
inline int in() {
int x;
scanf("%d", &x);
return x;
}
const int N = 21;
const int M = (1 << 21);
const int MOD = 1e9 + 7;
const long double eps = 1e-12;
int dp[M], n, m;
string s[N];
int a[N][N], c[N][N], mask[N][N];
int main() {
n = in(), m = in();
for (int i = 0... | 17 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
string s;
cin >> s;
long long x;
cin >> x;
long long n = s.size();
string c = s;
for (long long i = 0; i < n; i++) {
c[i] = '1';
}
for (long long i = 0; i < n; i++) {
if (s[i] == '0') {
if (i - x >= 0) {
c[i - x] = '0';... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n;
int arr1[100], arr2[100];
for (int i = 0; i < n; i++) cin >> arr1[i];
cin >> m;
for (int i = 0; i < m; i++) cin >> arr2[i];
int max = 0, d;
int cnt = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, k, ans, ans1, t;
cin >> n >> m >> k;
if (m > n) {
t = n;
n = m;
m = t;
}
if (k > n + m - 2)
cout << "-1" << endl;
else {
if (k <= n - 1) {
ans = n / (k + 1);
ans *= m;
} else {
ans = m / (k -... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, n1, n2;
int arr[100001];
int main() {
cin >> n >> n1 >> n2;
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
sort(&arr[0], &arr[n]);
int i, counter = min(n1, n2);
double s1 = 0, s2 = 0;
for (i = n - 1; counter != 0; counter--, i--) {
s1 += ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5500;
int n, T;
double dp[maxn][maxn];
int t[maxn];
double p[maxn];
int main() {
scanf("%d%d", &n, &T);
for (int i = 1; i <= n; i++) {
scanf("%lf%d", p + i, t + i);
p[i] /= 100.;
}
dp[0][0] = 1;
double ans = 0;
for (int i = 1; i <= n; i+... | 16 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-ffloat-store")
#pragma GCC optimize("-fno-defer-pop")
long long int power(long long int a, long long int b, long long int m) {
if (b == 0) return 1;
if (b == 1) return a % m;
lon... | 6 |
#include <bits/stdc++.h>
using namespace std;
int i, j, mini = 1000000000, p, d, n, m, k, ok, a, b, ul, c, op, maxi, zecimi,
a1, b1, c1;
vector<int> v[2005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for (i = 1; i <= n; i++) {
cin >> a;
v[a].push_back(i);
if (... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
if (n > 26) return !printf("-1");
int cnt[26], ok = 1, ans = 0;
memset(cnt, 0, sizeof cnt);
for (int i = 0; i < n; ++i) cnt[s[i] - 'a']++;
for (int i = 0; i < 26; ++i) ans += cnt[i] > 0;
cout << n - ans << endl;... | 2 |
#include <bits/stdc++.h>
using namespace std;
void solv() {
long long n, x, k;
cin >> n >> x >> k;
if (n == 1) {
cout << x << endl;
return;
}
x -= n;
long long ans = 1;
if (x == 0) {
cout << ans << endl;
return;
}
long long a = min(n - k + 1, k);
long long A = pow(a, 2);
if (A >= x... | 7 |
#include <bits/stdc++.h>
using namespace std;
double pi = 3.14159265358979323846;
int main() {
ios_base::sync_with_stdio(0);
int a, x, y;
cin >> a >> x >> y;
int c = y / a;
if (y % a == 0) {
cout << "-1";
return 0;
} else if (c == 0) {
if ((double)x > (double)-a / 2 && (double)x < (double)a / 2)... | 6 |
#include <bits/stdc++.h>
using namespace std;
void jabru() {
string a, b;
cin >> a >> b;
int n = a.size();
string ans = "";
int ind = 0;
for (long long i = 0; i < n; i++) {
if (a[i] == b[i]) {
ans += a[i];
} else {
if (ind % 2)
ans += a[i];
else
ans += b[i];
i... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void splitstr(const string &s, vector<T> &out) {
istringstream in(s);
out.clear();
copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out));
}
template <class T>
T gcd(T a, T b) {
return b ? gcd(b, a % b) : a;
}
static void redirec... | 17 |
#include <bits/stdc++.h>
using namespace std;
int A[200004], B[200004];
pair<int, int> V[200004];
int N;
int main() {
scanf("%d\n", &N);
for (int i = 1; i <= N; ++i) {
scanf("%d", &A[i]);
}
for (int i = 1; i <= N; ++i) {
scanf("%d", &B[i]);
V[i] = {B[i], i};
}
sort(V + 1, V + 1 + N);
sort(A + ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 300010;
int Fir[maxn], Nxt[maxn << 1], Too[maxn << 1], w[maxn << 1], tot;
int n, q, root[maxn], fa[maxn], siz[maxn], dfn[maxn], son[maxn], ts, mp[maxn],
top[maxn], vv[maxn], dep[maxn];
int adu[maxn << 1], adv[maxn << 1], adw[maxn << 1], in_tr[maxn << 1]... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, opr, sum = 0, count = 0;
cin >> n;
for (i = 0; i < n; i++) {
cin >> opr;
if (opr > 0)
sum += opr;
else {
sum -= 1;
if (sum < 0) {
count++;
sum = 0;
}
}
}
cout << count;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxl = 1e3 + 5, maxk = 100 + 5;
long long n, k, mod;
long long f[maxl][maxk][2], pw[maxl];
int getint() {
char ch;
int res = 0, p;
while (!isdigit(ch = getchar()) && (ch ^ '-'))
;
p = ch == '-' ? ch = getchar(), -1 : 1;
while (isdigit(ch)) res = (res... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
long long a[100005] = {0};
for (long long int i = 0; i < n; i++) {
long long int x;
cin >> x;
a[x] += x;
}
long long i;
for (i = 2; i < 100002; i++) {
a[i] = max(a[i - 1], a[i - 2] + a[i]);
}
cout << ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
int n, q;
int color[maxn];
int cnt_color[maxn];
int cnt[maxn];
int suff[maxn];
int ans[maxn];
set<int> first[maxn];
vector<pair<int, pair<int, int> > > queries[maxn];
vector<int> grafo[maxn];
void dfs(int u) {
cnt_color[color[u]]++;
cnt[cnt_co... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2222;
int n;
struct line {
int x1;
int y1;
int x2;
int y2;
bool isvertical() const { return x1 == x2; }
bool operator<(const line& l) const {
int b1 = isvertical();
int b2 = l.isvertical();
if (b1 != b2) return b1 < b2;
if (b1 &&... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
int n, a = 0;
cin >> n;
string s;
while (1) {
a++;
string x = to_string(a);
s += x;
if (n > s.length())
n -= s.length();
else {
cout << s[n - 1] << endl;
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = (1 << 22);
struct node {
int state;
int val;
double state_p;
} num[MAXN];
double p[25], P[25], dp[MAXN], ans[MAXN];
int n1, k, n;
int low_bit(int x) { return x & -x; }
int cnt_bit(int x) {
int ans = 0;
while (x) {
++ans;
x -= low_bit(x);
... | 16 |
#include <bits/stdc++.h>
using namespace std;
int n, a[1000006], s[1000006], p[1000006], f[1000006], aib[1000006];
long long int rez = 0;
vector<int> v;
void normalizare() {
int i;
cin >> n;
for (i = 1; i <= n; i++) {
cin >> a[i];
v.push_back(a[i]);
}
sort(v.begin(), v.end());
unique(v.begin(), v.en... | 10 |
#include <bits/stdc++.h>
int a, b, c, n, x[2], y[2], ans;
bool f(int i) { return 1LL * a * x[i] + 1LL * b * y[i] + c > 0; }
int main() {
scanf("%d%d%d%d%d", x, y, x + 1, y + 1, &n);
for (int i = 0; i < n; i++) {
scanf("%d%d%d", &a, &b, &c);
if (f(0) != f(1)) ans++;
}
printf("%d\n", ans);
return 0;
}
| 9 |
#include <bits/stdc++.h>
using namespace std;
inline int R() {
char c;
int sign = 1, res = 0;
while ((c = getchar()) > '9' || c < '0')
if (c == '-') sign = -1;
res += c - '0';
while ((c = getchar()) >= '0' && c <= '9') res = res * 10 + c - '0';
return res * sign;
}
const int Maxn = 2e5 + 5;
int n, a[Max... | 10 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int n = 0, f = 1;
char c;
for (c = getchar(); (c < '0' || c > '9') && c != '-'; c = getchar())
;
if (c == '-') f = -1, c = getchar();
for (; c >= '0' && c <= '9'; c = getchar()) n = n * 10 + c - 48;
return n * f;
}
const int maxn = 1e5 + ... | 25 |
#include <bits/stdc++.h>
using namespace std;
long long D[200000], n, y, tmpX, tmpY, m, ans, x;
string s, t;
map<string, int> mp;
string tmp = "";
int main() {
cin >> s;
for (int i = 0; i < s.size(); i++)
if (s[i] >= 'a' && s[i] <= 'z')
ans -= (s[i] - 'a' + 1);
else if (s[i] >= 'A' && s[i] <= 'Z')
... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 5;
const int mod = 1e9 + 7;
template <typename T>
void gi(T &ret) {
ret = 0;
char inp = getchar();
int kl = 1;
while (inp < '0' || inp > '9') {
if (inp == '-') kl = -1;
inp = getchar();
}
while ('0' <= inp && inp <= '9')
ret = (... | 12 |
#include <bits/stdc++.h>
int main(void) {
char s[100], p[100];
int i;
int a;
scanf("%s %s", s, p);
a = strlen(s);
printf("%c", s[0]);
for (i = 1; i < a; i++) {
if (s[i] >= p[0]) {
break;
} else if (s[i] < p[0])
printf("%c", s[i]);
}
printf("%c", p[0]);
printf("\n");
return 0;
}... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, dem = 0;
cin >> n;
if (n == 1) {
cout << n;
return 0;
} else {
if (n % (n - 1) == 0) {
cout << n;
} else {
cout << n - (n - 1);
}
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const long double eps = 1e-7;
const int inf = 1000000010;
const long long INF = 10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 110;
struct MAT {
long long a[MAXN][MAXN];
MAT() {
for (int i = 0; i < MAXN; i++)
fo... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int i, n, x;
cin >> n;
cout << n % 2 << endl;
return 0;
}
| 11 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int getrnd(int l, int r) { return uniform_int_distribution<int>(l, r)(rng); }
template <typename T1, typename T2>
bool relax(T1... | 10 |
#include <bits/stdc++.h>
using namespace std;
int used[1001][1001], r = 0;
vector<pair<int, int> > a, b;
char h[1001][1001];
void dfs(int v, int m) {
used[v][m] = 1;
for (int k : {1, -1, 0}) {
for (int j : {1, -1, 0}) {
if (abs(k) != abs(j) && used[v - k][m - j] == 0 &&
h[v - k][m - j] == '0') {... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int h, l;
cin >> h >> l;
double d = ((pow(l, 2) - pow(h, 2)) / (2 * h));
cout << fixed << setprecision(10) << d << "\n";
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int x, t, a, b, da, db, p, k;
int main() {
cin >> x >> t >> a >> b >> da >> db;
for (p = 0; p < t; p++)
for (k = 0; k < t; k++)
if ((x == a - da * p) || (x == b - db * k) ||
(x == a - da * p + b - db * k) || (x == 0)) {
cout << "YES";
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int tot, l, n;
int a[1000010];
int read() {
int pp = 0, ff = 1;
char ch;
ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') ff = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
pp = pp * 10 + ch - '0';
ch = getchar();
}
retu... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
;
long long n;
cin >> n;
if (n % 2)
cout << -1;
else {
for (long long i = 0; i < n; i += 2) cout << i + 2 << " " << i + 1 << " ";
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 3e5, M = N;
long long mpow(long long base, long long exp);
long long gcd(long long a, long long b) {
if (a == 0) return b;
return gcd(b % a, a);
}
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
void fastIO() {
ios_base::syn... | 3 |
#include <bits/stdc++.h>
const long double eps = 0.00000001;
const long long MOD = 1e9 + 7;
using namespace std;
int ans;
int cnt[105], sum;
int main() {
fflush(stdin);
cout << fixed, cout.precision(18);
ios_base::sync_with_stdio(false);
int i, j, n, m;
cin >> n >> m;
int a[n], k[m];
for (i = 0; i < n; ++... | 7 |
#include <bits/stdc++.h>
const int maxn = 4e3 + 10;
const int mod = 1e9 + 9;
int n, a, b, ans, fac[maxn], inv[maxn];
inline int power(int x, int y) {
int ans = 1;
for (; y; y >>= 1, x = 1ll * x * x % mod)
if (y & 1) ans = 1ll * ans * x % mod;
return ans;
}
inline int C(int n, int m) {
if (n == 0 && m == 0) ... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i;
string s, r;
cin >> n;
cin >> s;
r.insert(0, 1, s[0]);
for (i = 1; i < n; i++) {
if (n % 2 == 0) {
if (i % 2 == 0)
r.insert(0, 1, s[i]);
else
r.insert(r.size(), 1, s[i]);
} else {
if (i % 2 == 0)
... | 1 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int data;
int win_time;
};
int main() {
vector<node> q;
int n;
long long k;
scanf("%d%lld", &n, &k);
int Max = 0;
for (int i = 0; i < n; i++) {
int now;
scanf("%d", &now);
Max = max(now, Max);
q.push_back(node{now, 0});
}
fo... | 4 |
#include <bits/stdc++.h>
using namespace std;
int data[10000000];
int main() {
int n, m;
cin >> n >> m;
if (n > m) swap(n, m);
int i, turn = 1;
data[0] = 0;
int len = n + m, temp_n = n, temp_m = m;
n--;
for (i = 1; i < len; i++) {
if (!n) {
m--;
data[i] = 1;
continue;
}
if ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n;
long long a[101000];
long long no[101000];
long long from[101000];
long long nor[101000];
long long fromr[101000];
int main() {
scanf("%d", &n);
for (int i = 0; i < n - 1; i++) {
cin >> a[i];
}
from[0] = 0;
no[0] = 0;
long long ans = 0;
nor[n - 1] =... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int oo = 1000000000;
const int N = 1010;
int r, c, cnt, now;
set<int> RR, CC;
char a[N][N];
int cover(int ar, int ac, int br, int bc) {
int i;
for (i = ar; i <= br; i++) {
if (a[i][ac] == '.' || a[i][bc] == '.') return 0;
if (a[i][ac] == '#') a[i][ac] = '@... | 18 |
#include <bits/stdc++.h>
using namespace std;
long long n, m;
enum path { path1, path2, path3, zigdown, zigup, npath };
int main() {
long long t, p, q, r, x, y, u, v, j, i;
scanf("%lld", &n);
vector<vector<long long> > a(3, vector<long long>(n + 2));
for (j = 0; j < 3; j++) {
for (i = 1; i < n + 1; ++i) {
... | 15 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
string s;
cin >> s;
vector<int> cnt(27, 0);
for (int i = 0; i < s.size(); i++) {
cnt[s[i] - 'A']++;
}
int L = min(cnt['R' - 'A'], cnt['L' - 'A']);
int R = L;
int D = min(cnt['D' - 'A'], cnt['U' - 'A']);
int U = D;
if (U == 0) {
L =... | 4 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.