solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 400010, inf = 1 << 30;
int N, M, father[maxn], nxt[maxn], toit[maxn], len[maxn], side[maxn], id[maxn],
seq[maxn], D[maxn], cnt;
int DFN, dfn[maxn], top[maxn], size[maxn], con[maxn], ans[maxn],
tree[maxn << 2], cover[maxn << 2];
bool exist[maxn];
inl... | 19 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize(3)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target("sse3", "sse2", "sse")
#pragma GCC target("avx", "sse4", "sse4.1", "sse4.2", "s... | 12 |
#include <bits/stdc++.h>
using namespace std;
int dp[320][110000];
int a[110000], b[110000];
const int inf = 10000000;
int n, m, s, e;
vector<int> g[110000];
int main() {
while (~scanf("%d%d%d%d", &n, &m, &s, &e)) {
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 0; i <= 100000; i++) g[i].clear(... | 15 |
#include <bits/stdc++.h>
using namespace std;
int n, x, s[400], ans;
int Cal(int x) {
int y = 360 - x;
return x > y ? x - y : y - x;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &x);
s[i] = s[i - 1] + x;
}
ans = 360;
for (int i = 1; i <= n; i++)
for (int j = i; j ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, a[100005];
double ans;
struct node {
long long t[100005];
void add(int x, long long y) {
while (x <= n) t[x] += y, x += x & -x;
}
long long query(int x) {
long long ans = 0;
while (x) ans += t[x], x &= x - 1;
return ans;
}
} t1, t2;
inline i... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000010;
int n;
map<int, int> dp;
struct node {
int num, val;
} t[310];
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }
int main() {
int i;
cin >> n;
for (i = 0; i < n; ++i) {
cin >> t[i].num;
}
for (i = 0; i < n; ++i) {
cin >> ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, a[100];
int main() {
int i, sol;
cin >> n;
a[0] = 0;
n++;
a[n] = 90;
for (i = 1; i <= n; ++i) {
cin >> a[i];
if (a[i] - a[i - 1] - 1 >= 15) {
sol = a[i - 1] + 15;
cout << sol << "\n";
return 0;
}
}
cout << "90\n";
retur... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string str1;
cin >> str1;
string str2;
cin >> str2;
string output = "";
int count = 0;
for (int i = 0; i < str1.size(); i++) {
if (str1[i] == str2[i]) {
output += str1[i];
} else {
count++;
if (count % 2 == 1) {
o... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<multiset<long long>> m(n);
multiset<pair<long long, int>> s;
for (int i = 0; i < n; ++i) {
int x;
long... | 15 |
#include <bits/stdc++.h>
using namespace std;
int nrNodes, nrMax;
int color[200005], nrColor[200005];
vector<int> socks;
vector<int> G[200005];
bool vis[200005];
void dfs(int);
int main() {
int i, n, m, k, a, b, ans;
cin >> n >> m >> k;
for (i = 1; i <= n; ++i) cin >> color[i];
for (i = 1; i <= m; ++i) {
ci... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, y, c;
vector<vector<int> > e(100001);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x >> y;
c = 0;
for (int j = 1; j * j <= x; j++) {
if (x % j) continue;
int d = upper_bound(e[j].begin(), e[j].end(), i - 1) -
... | 11 |
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template <typename T>
using vc = std::vector<T>;
bool is_d(char c) { return c >= '0' && c <= '9'; }
void solve(istream& cin, ostream& cout) {
string s;
cin >> s;
int n = s.size();
int a = 0;
int i = 0;
int x = 0;
while (is_d(s[i])) {
... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int dr[]{-1, -1, 0, 1, 1, 1, 0, -1};
const int dc[]{0, 1, 1, 1, 0, -1, -1, -1};
void run() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
const int mod = 1e9 + 7;
const int N = 1009;
long long power(long long x, long long y) {
if (y == 0) retu... | 11 |
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ULL;
typedef unsigned long long uint64;
typedef long long LL;
typedef long long int64;
template <class T>
inline void checkmax(T &a, T b) {
if (b > a) a = b;
}
template <class T>
inline void checkmin(T &a, T b) {
if (b < a) a = b;
}
template <... | 5 |
#include <bits/stdc++.h>
using namespace std;
int N, rez;
string s;
bool viz[100005];
void SetInterval(int poz, int x) {
int i;
int st = poz, dr = poz;
for (i = poz; i >= 0; i--) {
if (viz[i] == 1 || (s[i] == 'P' && i != poz))
break;
else if (s[i] == '*' && x >= poz - i) {
st = i;
} else i... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int mmax = -1, sum1 = 0, sum2 = 0, sum3 = 0;
for (int i = 0; i < s.size(); ++i) {
sum1 += (s[i] - '0');
}
sum2 += (s[0] - '0');
for (int i = 1; i < s.size(); ++i) {
if (s[i] == '9' && i == 1) {
mmax = i;
} els... | 5 |
#include <bits/stdc++.h>
long long int sqrSum(long long int a, long long int b) {
if (b == 0) return 0;
if (b == 1) return a;
if (a == b) return 1;
if (a / b) return a / b + sqrSum(b, a % b);
if (a - b > b)
return 1 + sqrSum(a - b, b);
else
return 1 + sqrSum(b, a - b);
}
int main() {
long long int... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
stack<int> st;
for (int i = 0; i < s.length(); i++) {
if (s[i] == '(') {
st.push(i);
} else if (s[i] == ')') {
if (!st.empty()) {
st.pop();
} else {
cout << -1;
return 0;
}
... | 7 |
#include <bits/stdc++.h>
using namespace std;
void c_p_c() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int32_t main() {
c_p_c();
long long n;
cin >> n;
vector<pair<long long, pair<long long, long long>>> req;
for (long long i = 0; i < n; ++i) {
long long c, p;
cin >> c >> p;
r... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, c, b, sum = 0;
vector<long long> x, y, z;
cin >> a >> c;
while (a > 0) {
x.push_back(a % 3);
a /= 3;
}
while (c > 0) {
y.push_back(c % 3);
c /= 3;
}
int u = x.size();
int w = y.size();
if (u > w) {
for (int j... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
int s = 26;
char c, t = '.';
while (cin >> c) {
s += 25;
t = c;
}
cout << s;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int w, h, u, d, uu, dd;
cin >> w >> h >> u >> d >> uu >> dd;
for (int i = h; i >= 1; i--) {
w += i;
if (i == d) w = max(0, w - u);
if (i == dd) w = max(0, w - uu);
}
cout << ... | 0 |
#include <bits/stdc++.h>
using namespace std;
string gh = "here";
bool cmp(pair<int, int> a, pair<int, int> b) {
if (a.first > b.first) {
return true;
} else if (a.first == b.first and a.second < b.second) {
return true;
}
return false;
}
bool cmp2(pair<int, int> a, pair<int, int> b) {
if (a.second < ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[100003];
int main() {
cin >> n;
int mx = 19260817, cnt = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (a[i] < mx)
mx = a[i], cnt = 1;
else if (a[i] == mx)
cnt++;
}
if (cnt <= n / 2)
puts("Alice");
else
puts("Bob"... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
while (n--) {
string s;
int x = 0;
cin >> s;
int arr[26] = {0};
int min = INT_MAX;
int max = 0;
for (int i = 0; i < s.length(); i++) {
if (arr[s[i] - 97] == 0) max++;
arr[s[i] - 97]++;
if (s[i... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, maxi = 0;
cin >> n;
while (n--) {
cin >> x;
if (x > maxi) maxi = x;
}
cout << maxi;
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int d = 1000000007;
long long gcd(long long a, long long b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
bool issqrt(int n) {
float x = sqrt(n);
int y = sqrt(n);
return (y == x);
}
bool isprime(int x) {
if (x == 1) {
return false;
}
int n... | 0 |
#include <bits/stdc++.h>
using namespace std;
bool composite[1000 + 7];
vector<int> primes;
void Sieve() {
int lim = sqrt(1000) + 2;
for (int i = 3; i <= lim; i++) {
if (!composite[i]) {
for (int j = i * i, k = i << 1; j <= 1000; j += k) {
composite[j] = true;
}
}
}
primes.push_back(... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
unsigned long long t, n, k;
cin >> t;
while (t--) {
cin >> n >> k;
if (n < k * k) {
cout << "NO\n";
continue;
}
if (n % 2 != k % 2)
cout << "NO\n";
else
cout << "YES\n";
}
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
long long a, b, c, num, mo, tot = 1;
cin >> a >> b >> c;
if ((a - 1) * b < c || b > c)
return cout << "NO", 0;
else {
cout << "YES" << endl;
num = c / b;
mo = c % b;
for (long long i = 0; i < b; i++) {
if (mo == 0) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200007, inf = 0x3f3f3f3f;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int vis[N];
int on1[N], on2[N];
vector<int> e[N], rev[N];
bool flag = false;
void dfs(int u) {
vis[u] = 1;
for (int v : e[u]) {
if (vis[v] == 0)
dfs(v)... | 18 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000000,102400000000")
const long long MOD = 1000000007;
const int N = 1e5 + 15;
const int maxn = 1e5 + 15;
const int letter = 130;
const int INF = 2e9 + 15;
const double pi = acos(-1.0);
const double eps = 1e-10;
using namespace std;
inline int read() {
i... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e6;
int x[maxn], y[maxn], k[maxn];
bool eq(double a, double b) { return a + (1e-8) >= b && a - (1e-8) <= b; }
bool le(double a, double b) { return a - (1e-8) <= b; }
int main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
string s;
cin >> s;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long int mod = 1e9 + 7;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
a[i]--;
}
vector<bool> v(n + 1);
int cnt = n;
for (int i = 0; i < n; i++) {
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int n, m, q, x, y;
bool a[N][N];
inline bool chk(int x, int y) {
return x >= 1 && x <= n && y >= 1 && y <= m && !a[x][y];
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> q;
long long ans = 0;
for (int i = 1; i <= n; ++i)
... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
scanf("%d%d", &n, &k);
k *= 2;
vector<int> a(2 * n);
for (int i = 0; i < 2 * n; ++i) a[i] = i + 1;
for (int i = 1; i < 2 * n; i += 2, k -= 2) {
if (k > 0) swap(a[i], a[i - 1]);
}
for (auto x : a) printf("%d ", x);
return 0;
}
| 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, j, count1 = 0, count2 = 0, k, yes = 0, l;
cin >> n;
int num[n][n];
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
cin >> num[i][j];
if (num[i][j] != 1) count1++;
}
}
for (i = 0; i < n; i++) {
for (j = 0; j < n;... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 305;
int n, a, b, k, f;
string last;
map<pair<string, string>, int> M;
vector<int> V;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> a >> b >> k >> f;
for (int i = 0; i < n; ++i) {
string s, e;
cin >> s >> e;
i... | 10 |
#include <bits/stdc++.h>
using namespace std;
struct point {
int x;
int y;
};
int main() {
set<int> cntx;
set<int> cnty;
int n = 3;
vector<point> p(n);
for (int i = 0; i < n; i++) {
int x, y;
scanf("%d %d", &x, &y);
p[i] = {x, y};
cntx.insert(x);
cnty.insert(y);
}
auto check = [&](... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = INT_MAX;
const long long INFll = LLONG_MAX;
void solveA();
void solveB();
void solveC();
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solveA();
return 0;
}
vector<int> mark;
vector<vector<int>> adList;
v... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long n, k;
long long dp[(int)1e5 + 1];
int main() {
vector<long long> dd;
cin >> n >> k;
for (int i = 0; i < n; i++) {
int f;
cin >> f;
dd.push_back(f);
}
long long ex = 0, ans = 0;
for (int i = 0; i < dd.size(); i++) {
if (dd[i] >= k) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int mxN = 1e6;
int n, m, p, a[mxN];
long long s1[1 << 21];
vector<long long> s2[1 << 21];
void bld(int i = 1, int l = 0, int r = n - 1) {
if (l == r) {
s1[i] = a[l];
s2[i] = {p - a[l], 1ll << 60};
return;
}
int m = (l + r) / 2;
bld(2 * i, l, m);
... | 25 |
#include <bits/stdc++.h>
using namespace std;
vector<bool> visited;
vector<vector<pair<long long, long long> > > A;
vector<long long> ans;
bool dfs(long long ind) {
visited[ind] = true;
bool cnt = false, ret = false;
for (long long i = 0; i < (int)A[ind].size(); i++) {
if (visited[A[ind][i].first]) {
co... | 8 |
#include <bits/stdc++.h>
using namespace std;
char p[30] = {'0', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
inline long long rd() {
long long x = 0, flag = 1;
char ch = getchar();
while (ch < '0' ||... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int n, a[2 * N], ovo[N];
int now = 0, ans[N * 2];
priority_queue<int, vector<int>, greater<int> > qwq;
int main() {
scanf("%d", &n);
for (int i = 1; i <= 2 * n; i++) {
char y;
int x;
cin >> y;
if (y == '+')
a[i] = 0;
else ... | 9 |
#include <bits/stdc++.h>
using namespace std;
deque<int> a, b;
int main() {
string num;
int i, j, k, f = 1, m;
int v1[10] = {0}, v2[10] = {0};
cin >> num;
for (i = 0; i < num.length(); i++) {
v1[num[i] - '0']++;
v2[num[i] - '0']++;
}
for (i = 9, j = 0; i >= 0 && j <= 9;) {
if (v1[i] && v2[j]) ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 100;
vector<int> g[MAX];
bool visited[MAX];
void dfs(int u) {
visited[u] = true;
for (int i = 0; i < g[u].size(); i++)
if (!visited[g[u][i]]) {
visited[g[u][i]] = true;
dfs(g[u][i]);
}
}
bool reachable(int u, int v) {
memset(visited... | 7 |
#include <bits/stdc++.h>
using namespace std;
bool grt(string s1, string s2) {
int i;
for (i = 0; i < s1.size(); i++) {
if (s1[i] > s2[i])
return true;
else if (s1[i] < s2[i])
return false;
}
return false;
}
int main() {
int t, n, i, j;
string s;
cin >> n;
cin >> s;
string mini = s... | 7 |
#include <bits/stdc++.h>
using namespace std;
char s[2002];
void swaps(int l, int r) {
int j = 1;
for (int i = l; i <= r; i++) {
int ss = i, ee = r - j + 1;
if (ss >= ee) break;
swap(s[ss], s[ee]);
j++;
}
}
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n, k;
scanf("%d%d", &n... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char str[101][101];
int i, j, m, n, r[3], c[3], r4 = 1, c4 = 1, k;
char temp;
cin >> m >> n;
for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
cin >> str[i][j];
}
cin.ignore();
}
for (i = 0, k = 0; i < m; i++) {
for (j = 0;... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > H[500005];
int arr[30], L[500005], R[500005];
vector<int> st[500005];
char str[500005];
int n, m, tot;
void dfs(int p, int dep) {
L[p] = ++tot;
H[dep].push_back(make_pair(tot, H[dep].back().second ^ arr[str[p]]));
for (int i = (0); i < (st[p].s... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, a, b;
int bit[51][51];
cin >> n >> m;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j) scanf("%d", &bit[i][j]);
int c[50][50];
cin >> a >> b;
int ans = 0x3f3f3f3f;
if (a <= n && b <= m) {
memset(c, 0, sizeof(c));
f... | 4 |
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
using namespace std;
bool dbg = 0;
clock_t start_time = clock();
void bad(string mes = "NO") {
cout << mes;
exit(0);
}
void bad(int mes) {
cout << mes;
exit(0);
}
template <typename T>
string bin(T x, int st = 2) {
str... | 27 |
#include <bits/stdc++.h>
using namespace std;
int twoline(int x1, int x2, int x3, int y1, int y2, int y3) {
if (y1 > y2) {
;
} else {
int tmp = y1;
y1 = y2;
y2 = tmp;
}
if (y3 >= y1 || y3 <= y2)
return 2;
else
return 3;
}
int main() {
int x1, y1;
int x2, y2;
int x3, y3;
cin >> ... | 9 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long int n;
cin >> n;
if (n == 0) {
cout << 0 << "\n";
return;
}
if ((n + 1) % 2 == 0) {
cout << (n + 1) / 2;
return;
} else {
cout << n + 1;
return;
}
}
int main() {
solve();
return 0;
}
| 2 |
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include<ext/pb_ds/tag_and_trait.hpp>
// using namespace __gnu_pbds;
// #include<boost/multiprecision/cpp_int.hpp>
// nam... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long GCD(long long a, long long b) { return (b == 0 ? a : GCD(b, a % b)); }
long long getMax(size_t a, size_t b) { return ((a > b) ? a : b); }
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
string CF[] = {"NO", "YES"};
string alpha = "0123456789ABCDEFGHIJKLMNOPQRS... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, p;
cin >> n >> p;
if (p % 2 == 0) p = n + 1 - p;
cout << p / 2 + 1;
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 5;
const long long MOD = 1e9 + 7;
const double eps = 1e-7;
int N, M, K, Q, T;
long long gcd(long long a, long long b) {
if (b == 0LL) return a;
return gcd(b, a % b);
}
int tree[MAXN];
int nmx;
void update(int i, int x) {
while (i <= nmx) {
t... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, m, Q, l, r, x;
long long a[100010], b[100010], sum, f[100010];
int main() {
scanf("%d%d%d", &n, &m, &Q);
for (int i = 1; i <= n; i++)
scanf("%lld", &a[i]), sum += (i & 1) ? a[i] : -a[i];
for (int i = 1; i <= m; i++) scanf("%lld", &b[i]);
for (int i = 1; i... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long dist[100005];
long long wt[100005];
long long num[100005];
long long dp[105][100005];
long long temp[100005];
int main() {
long long a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q;
scanf("%lld %lld %lld", &a, &b, &c);
memset(dist, 0, sizeof(dist));
for ... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int inf_int = 1e9 + 100;
const long long inf_ll = 8e18;
const double pi = 3.1415926535898;
bool debug = 0;
const int MAXN = 201;
const int LOG = 20;
const long long mod = 998244353;
const int MX = 5e4 + 10;
int g[MX], s[MX];
int U[MX], V[MX];
int pos[MX];
mt19937 mt(2... | 14 |
#include <bits/stdc++.h>
using namespace std;
void file() {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
}
void run() {
string s, falseLine;
getline(cin, s);
int a;
cin >> a;
int len = s.length();
char x[len];
set<char> all;
for (int i = 0; i < len; i++) {
x[i] = s[i];
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int L[205];
int T[100005][205];
vector<int> V;
int main() {
ios_base::sync_with_stdio(0);
int n;
cin >> n;
string s;
cin >> s;
for (int i = 0; i < n; i++) V.push_back(s[i]);
sort(V.begin(), V.end());
V.resize(distance(V.begin(), unique(V.begin(), V.end())));... | 7 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
static map<char, char> kWinner = {{'R', 'P'}, {'P', 'S'}, {'S', 'R'}};
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int test_cases;
cin >> test_cases;
while (test_cases-- > 0) {
std::string s;
cin >> s;
map<char,... | 6 |
#include <bits/stdc++.h>
using namespace std;
int a, b, c, ans = 29;
int main() {
cin >> a >> b >> c;
while (a > 0 || b > 0 || c > 0) {
ans++;
if (ans % 3 == 0) {
a -= 2;
}
if (ans % 3 == 1) {
b -= 2;
}
if (ans % 3 == 2) {
c -= 2;
}
}
cout << ans << endl;
return 0... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int c = 0, i, j, res = 0, t;
string s;
cin >> s;
t = s.size();
while (s.size() != 1) {
c = 0;
for (i = 0; i < s.size(); i++) {
c += (s[i] - '0');
}
s = to_string(c);
res++;
}
if (t == 1)
cout << 0;
else
cout << ... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T abs(T a) {
return ((a < 0) ? -a : a);
}
template <typename T>
inline T sqr(T a) {
return a * a;
}
bool solve(int);
int main() {
int test = 0;
while (solve(test)) {
++test;
}
return 0;
}
const int N = 24;
struct guy {
int firs... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int Dec[11][1001], Inc[11][1001], m, n;
int cal_inc(int pos, int last) {
if (pos == m) return 1;
int &ret = Inc[pos][last];
if (ret != -1) return ret;
ret = 0;
for (int val = last; val <= n; val++)
ret = (ret + cal_inc(pos + 1, val)) %... | 8 |
#include <bits/stdc++.h>
using namespace std;
void solve(int* A, int* B, int x) {
int N = B - A;
if (x == -1) return;
if (N <= (1 << x)) {
solve(A, B, x - 1);
return;
}
for (int i = 1 << x; i < N; i++) {
swap(A[i - (1 << x)], A[i]);
}
solve(A, A + (1 << x), x - 1);
solve(A + (1 << x), B, x -... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n, ans, fa[N], sz[N];
char st[N];
int get(int x) { return fa[x] == x ? x : fa[x] = get(fa[x]); }
void merge(int x, int y) {
x = get(x);
y = get(y);
if (x == y) return;
fa[y] = x;
sz[x] += sz[y];
}
int main() {
scanf("%s", st);
n = st... | 14 |
#include <bits/stdc++.h>
using namespace std;
int a;
int main() {
cin >> a;
cout << a / 2 + 1;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long n;
cin >> n;
if (n % 2 == 0) {
cout << "home" << endl;
} else {
cout << "contest" << endl;
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
class map<int, int> sum;
int main() {
int n, a[100005], i, j, pow[34], b;
long long cou;
pow[1] = 1;
for (i = 2; i <= 32; i++) pow[i] = pow[i - 1] * 2;
scanf("%d", &n);
cou = 0;
for (i = 1; i <= n; i++) {
scanf("%d", &a[i]);
sum[a[i]]++;
}
for (i =... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
inline int pls(int x, int y) {
x += y;
return x >= mod ? x - mod : x;
}
inline int dec(int x, int y) {
x -= y;
return x < 0 ? x + mod : x;
}
inline int mul(int x, int y) { return 1ll * x * y % mod; }
inline int mul(int x, int y, int z) { ret... | 9 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000")
using namespace std;
int ri() {
int x;
scanf("%d", &x);
return x;
}
int n;
long long ax[2], ay[2];
long long tx, ty;
long long xx[100500], yy[100500];
long double solve(int index) {
long double mx = 0.0;
int j = 1;
for (int i = 1; i <= n; ... | 10 |
#include <bits/stdc++.h>
using namespace std;
vector<int> G[100100], Path[100100];
int sparse[100100][23], lvl[100100], Edge[100100], Start[100100], End[100100];
void dfs(int u, int par = -1, int level = 0) {
if (par != -1) sparse[u][0] = par;
lvl[u] = level;
for (auto v : G[u])
if (v != par) dfs(v, u, level ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int a[(int)(1e5 + 20)], dev[(int)(1e5 + 20)];
long long mod = 1e9 + 7;
long long mpow(long long a, int b) {
long long res = 1;
while (b) {
if (b % 2) {
res = (res * a) % mod;
}
a = (a * a) % mod;
b >>= 1;
}
return res;
}
void solve() {
int n;... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, temp, max_div = -1, counter = 1;
cin >> a;
int arr[a];
for (int i = 0; i < a; i++) cin >> arr[i];
cin >> b;
for (int i = 0; i < b; i++) {
cin >> temp;
for (int j = 0; j < a; j++) {
if (temp % arr[j] == 0) {
if (temp /... | 1 |
#include <bits/stdc++.h>
using namespace std;
int general(int a, int b) {
int gen = 0, check1 = 0, check2 = 0;
gen = min(a, b);
check1 = a % gen;
check2 = b % gen;
while ((check1 != 0) || (check2 != 0)) {
gen--;
check1 = a % gen;
check2 = b % gen;
}
return gen;
}
int trans(int i, int A) {
in... | 2 |
#include <bits/stdc++.h>
using namespace std;
unsigned long long power_of_2(int e) {
if (e == 0) {
return 1;
}
if (e % 2 == 1) {
return (2 * power_of_2(e - 1)) % 1000003;
}
unsigned long long tmp;
tmp = power_of_2(e / 2);
return (tmp * tmp) % 1000003;
}
int main() {
int n, m;
cin >> n;
cin >... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long fast_exp(long long base, long long exp) {
long long res = 1;
while (exp > 0) {
if (exp % 2 == 1) res = (res * base) % 1000000007;
base = (base * base) % 1000000007;
exp /= 2;
}
return res % 1000000007;
}
long long fib(long long n) {
if (n < 2... | 0 |
#include <bits/stdc++.h>
using namespace std;
double ax, ay, bx, by, cx, cy;
void getstr(string &x) {
char tmp[1000];
scanf("%s", tmp);
x = tmp;
}
double cross(double ax, double ay, double bx, double by, double cx, double cy) {
return (bx - ax) * (cy - by) - (by - ay) * (cx - bx);
}
int main() {
cin >> ax >> ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int sum, i, a;
int main() {
map<int, int> d;
cin >> a;
int ans[a];
for (i = 0; i < a; i++) {
cin >> ans[i];
sum += ans[i];
if (i == a - 1)
break;
else
d[sum]++;
}
if (sum % 2 != 0) {
cout << 0;
return 0;
}
cout << d[sum / ... | 4 |
#include <bits/stdc++.h>
using namespace std;
auto clk = clock();
vector<long long> dp(100000);
void solve() {
long long c, d;
cin >> c >> d;
long long n, m;
cin >> n >> m;
long long k;
cin >> k;
long long e = (n * m) - k;
for (long long i = 1; i < e + 1; i++) {
dp[i] = min(dp[i - 1] + d, dp[max(0ll... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
unordered_map<string, int> compress;
struct DSU {
int parent[N];
DSU() {
for (int i = 0; i < N; ++i) {
parent[i] = i;
}
}
int GetRoot(int x) {
if (parent[x] == x) {
return x;
}
return parent[x] = GetRoot(parent[x... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long f(long long p, long long c) {
if (p <= (c / 2)) {
return 0;
}
return 1;
}
struct obj {
long long val;
long long mn;
long long mx;
};
int main() {
long long n, m, c;
cin >> n >> m >> c;
vector<obj> a(n);
for (long long i = 0; i < n; ++i) {
... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n);
for (int &i : a) cin >> i;
auto b = a;
for (int i : b) a.push_back(i);
int ans = 0, curr = 0;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int k, x = 3, y = 4, z = 5, i, j;
bool g[100][100];
string s = "NY";
void G(int a, int b) { g[a][b] = g[b][a] = true; }
int main() {
for (cin >> k, G(0, 3), G(0, 4); k; G(x, x + 3), G(x, y + 3), G(y, y + 3),
G(y, x + 3), G(z, z + 3), ... | 11 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool setmax(T& _a, T _b) {
if (_b > _a) {
_a = _b;
return true;
}
return false;
}
template <class T>
bool setmin(T& _a, T _b) {
if (_b < _a) {
_a = _b;
return true;
}
return false;
}
template <class T>
T gcd(T _a, T _b) {
ret... | 23 |
#include <bits/stdc++.h>
using namespace std;
const int mx = 2e5 + 5;
char parten[6][6] = {"RGB", "RBG", "BGR", "BRG", "GBR", "GRB"};
char str[mx];
char ans[mx];
int main() {
int n;
scanf("%d", &n);
scanf("%s", str);
int ans_pos, ans_num = mx + 1;
for (int i = 0; i < 6; i++) {
int pos = 0, cnt = 0;
fo... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long n, x[100001], y[100001];
long long dist(long long a, long long b, long long c, long long d) {
return (a - c) * (a - c) + (b - d) * (b - d);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for (int i = 0; i < n; i++) {
cin >>... | 10 |
#include <bits/stdc++.h>
using namespace std;
struct DB {
int d, h;
} b[106];
bool cmp(const DB &x, const DB &y) { return x.d - x.h > y.d - y.h; }
int main() {
int i, j, k, m, n, t, x, lc = 0;
scanf("%d", &t);
while (t--) {
scanf("%d%d", &n, &x);
lc = 0;
for (i = 1; i <= n; i++) {
scanf("%d%d"... | 8 |
#include <bits/stdc++.h>
using namespace std;
map<string, int> name;
string s;
bool a[1005], b[1005];
int x[1005], y[1005], key[1005], f[1005], n, m, K, p, z, L;
int get(int x) { return f[x] == x ? x : f[x] = get(f[x]); }
void work(bool *a) {
for (int i = 1; i <= n; i++) f[i] = i;
int flag = 1;
while (flag) {
... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
cin >> T;
while (T--) {
string str;
cin >> str;
str = str.substr(4);
if (str.size() == 1) {
if (str == "9")
cout << "198" << str << endl;
else
cout << "199" << str << endl;
} else if (str.size() == 2)... | 12 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 0.0000000000001;
double a[1005];
double b[1005];
int n;
double m;
double comp(double x) {
double w = m + x;
w = ((a[0] - 1) * w) / a[0];
for (int i = 1; i < n; ++i) {
w = ((b[i] - 1) * w) / b[i];
w = ((a[i] - 1) * w) / a[i];
}
w = ((b[0]... | 7 |
#include <bits/stdc++.h>
using namespace std;
vector<unsigned long long> rec(unsigned long long n) {
vector<unsigned long long> ans(10, 0);
if (n < 10) {
for (int i = 1; i <= n; i++) ans[i]++;
return ans;
}
for (int i = 1; i <= 9; i++) ans[i]++;
unsigned long long step = 10, cur = 9, num = 1;
while ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 500;
const int maxm = 500000 + 10;
struct Edge {
int next, v;
Edge() {}
Edge(int next, int v) : next(next), v(v) {}
} e[maxm << 1];
int n, m, len, timer, num;
int head[maxm], cnt;
int low[maxn], dfn[maxn], belo[maxn];
bool ins... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long k, d;
cin >> k >> d;
if (k > 1 && d == 0) {
cout << "No solution" << endl;
return 0;
}
cout << d;
for (int i = 1; i < k; i++) cout << 0;
cout << endl;
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
const int LN = 19;
const int N = 100005;
int n, numQ, a[N], b[N], d[N];
long long sumD[N], res[N], mn[LN][N], mx[LN][N];
pair<pair<int, int>, int> q[N];
long long getMin(int l, int r) {
int k = log2(r - l + 1);
return min(mn[k][l], mn[k][r - (1 << k) + 1]);
}
long long ... | 14 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.