solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
struct tr {
int l, r, val;
};
int sz, h, m, res;
bool used[200200];
int col[200200], pos[200200], maxv[200200];
vector<int> lst[200200];
vector<tr> rmq[200200];
void dfs(int a) {
used[a] = true;
col[a] = sz;
pos[a] = lst[sz].size();
lst[s... | 8 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
static int r, sign;
static char c;
r = 0, c = getchar(), sign = 1;
while ((c < '0' || c > '9') && c != '-') c = getchar();
if (c == '-') sign = -1, c = getchar();
while (c >= '0' && c <= '9') r = r * 10 + (c - '0'), c = getchar();
return r ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n;
double c[205], p[205], ans;
int main() {
cin >> n;
for (int i = 0; i <= n; i++) scanf("%lf", &p[i]);
for (int i = 0; i <= n; i++) c[i] = fabs(n - 2 * i);
for (int i = 0; i <= (n - 1) / 2; i++)
for (int j = (n - 1) / 2 + 1; j <= n; j++)
ans = max(ans... | 16 |
#include <bits/stdc++.h>
using namespace std;
struct BstNode {
int data;
BstNode *left;
BstNode *right;
};
BstNode *GetNewNode(int data) {
BstNode *newNode = new BstNode();
newNode->data = data;
newNode->left = newNode->right = NULL;
return newNode;
}
BstNode *Insert(BstNode *root, int data) {
if (root ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1012;
int n, k, t = 0, tot = 0, ans[N], tim[N], du[N];
int w[N * N];
bool del[N];
struct Point {
int x, y;
} a[N];
inline int Dist(Point a, Point b) {
return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}
struct Edge {
int u, v;
Edge *next;
}... | 23 |
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 1e5 + 10;
int p[Maxn];
int b[Maxn];
pair<long long, long long> a[Maxn];
long long t[Maxn];
long long sum[Maxn];
int c[Maxn];
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> p[i];
}
for (int i = 0; i < m; i++) {
c... | 6 |
#include <bits/stdc++.h>
int main() {
int n, i, f = -1, l = -1;
scanf("%d\n", &n);
char a[n + 1], c;
gets(a);
for (i = 0; i < n; i++) {
if (a[i] != '.' && (f == -1 && l == -1)) {
if (a[i] == 'R')
f = i + 1;
else {
l = i;
}
c = a[i];
}
if (a[i] != c && (f != ... | 5 |
#include <bits/stdc++.h>
using namespace std;
typedef struct node {
int idx, up, cost;
node(){};
node(int a, int b, int c) { idx = a, up = b, cost = c; }
bool operator<(const node& x) const {
if (cost != x.cost) return cost < x.cost;
if (idx != x.idx) return idx < x.idx;
if (up != x.up) return up < ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXN = 100009;
int t, n;
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
int x1 = -1;
for (int i = 1; i <= 10000; i++) {
if (i >= a && i >= d && a * 2 >= i && d * 2 < i) {
x1 = i;
break;
}
}
int x2 ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int nextInt() {
int x;
scanf("%d", &x);
return x;
}
long long nextLong() {
long long x;
scanf("%I64d", &x);
return x;
}
double nextDouble() {
double x;
scanf("%lf", &x);
return x;
}
const int BUFSIZE = 1000000;
char buf[BUFSIZE + 1];
string nextString() {
... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n, m, k;
char s[N], t[N];
int f[N], l[N], r[N];
void build(string &s) {
int j = 0;
for (int i = 1; i < s.size(); ++i) {
while (j && s[i] != s[j]) j = f[j - 1];
if (s[i] == s[j]) ++j;
f[i] = j;
}
}
int len;
string S, T;
void valid... | 18 |
#include <bits/stdc++.h>
using namespace std;
bool isrange(int second, int first, int n, int m) {
if (0 <= second && second < n && 0 <= first && first < m) return true;
return false;
}
int dy[4] = {1, 0, -1, 0}, dx[4] = {0, 1, 0, -1},
ddy[8] = {1, 0, -1, 0, 1, 1, -1, -1}, ddx[8] = {0, 1, 0, -1, 1, -1, 1, -1};
c... | 15 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
for (int i = 0; i < 500; ++i) {
if ((i * (i + 1)) / 2 == n) {
cout << "YES\n";
return;
}
}
cout << "NO\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tc = 1;
while (tc--) {... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long i, n, c, k;
cin >> n >> k;
vector<long long> x(n);
for (i = 0; i < n; i++) {
cin >> x[i];
}
sort(x.begin(), x.end());
if (k == 0 && x[k] - 1 != 0)
cout << x[k] - 1 << endl;
else if (x[k - 1] != x[k] && k != 0)
cout << x[k -... | 4 |
#include <bits/stdc++.h>
const int maxn = 1e6 + 10;
using namespace std;
int rd() {
int t;
scanf("%d", &t);
return t;
}
int res[maxn];
vector<int> vec[maxn];
void dfs(int x, int f, int mi) {
res[x] = min(mi, x);
for (int i = 0; i < vec[x].size(); i++) {
int y = vec[x][i];
if (y == f) continue;
dfs... | 17 |
#include <bits/stdc++.h>
using namespace std;
double ans = 0;
int a[22], b[22], p[22], q[22], l[22], N, M, A;
double efs() {
for (int i = 1; i <= N; ++i) q[i] = min(p[i] + b[i] * 10, 100);
double ret = 1;
for (int x = 0; x < 1 << N; ++x) {
for (int xx = x, i = 1; i <= N; xx >>= 1, ++i) a[i] = xx & 1;
doub... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long T[5005][5005];
long long powi(long long a, long long b) {
if (!b) return 1;
long long p = powi(a, b / 2);
p = (p * p) % 998244353;
if (b & 1) p = (p * a) % 998244353;
return p;
}
long long mmi(long long x) { return powi(x, 998244353 - 2); }
int main() {
... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
long n, s, k, c;
while (t--) {
cin >> n >> s >> k;
set<int> v;
for (int i = 0; i < k; i++) {
cin >> c;
v.insert(c);
}
if (v.find(s) == v.end())
cout << 0 << endl;
else {
long i = 1;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
map<char, int> base;
char ch;
ch = '0';
for (long long int i = 0; i < 10; i++) {
base[ch] = i;
ch++;
}
ch = 'A';
for (long long int i = 10; i < 36; i++) {
base[ch] = i;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
map<string, int> type;
int main() {
type["void"] = 1;
type["errtype"] = 0;
int n;
string A, B, op;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> op >> A;
int start = 0, end = A.size() - 1;
while (A[start] == '&') start++;
while (A[end] == '*') e... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5, mod = 1e9 + 7;
int n, m, key[maxn + 5], cnt, c[maxn + 5], suf[maxn + 5], b[maxn + 5],
id[maxn + 5], rk[maxn + 5];
struct node {
int l, r;
} a[maxn + 5];
int Add(int x, int y) { return (x += y) >= mod ? x - mod : x; }
int lb(int x) { return x & (-... | 22 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
struct edge {
int u, v, i;
edge() {}
edge(int u, int v, int i) : u(u), v(v), i(i) {}
};
const int maxn = 1e5 + 6, maxw = 1e6 + 6;
int n, m;
vector<edge> edgl[maxw];
int ans[maxn];
int par[maxn], sez[maxn];
int find(int x) {
while (x != ... | 15 |
#include <bits/stdc++.h>
const int N = 1e5 + 5;
int n, m, a[N], b[N];
long long ans;
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]), ans += 1LL * a[i] * m;
for (int i = 1; i <= m; ++i) scanf("%d", &b[i]);
std::sort(a + 1, a + 1 + n), std::sort(b + 1, b + 1 + m);
if (a[n] >... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long int a, b, c, d;
long long int w, x, y, z;
long long int a2, a3, b2, b3, c2, c3, d2, d3, ans;
int main() {
cin >> a >> b >> c >> d;
while (a % 2 == 0) {
a /= 2;
a2++;
}
while (a % 3 == 0) {
a /= 3;
a3++;
}
while (b % 2 == 0) {
b /= 2... | 11 |
#include <bits/stdc++.h>
using namespace std;
map<long long int, long long int> m;
int n;
long long int mod = 1000000007;
long long int f(int a, int b) {
if (b == 1) {
return a - 1;
} else if (b <= 0 || a <= 0) {
return INT_MAX;
}
if (a < b) {
int temp = b;
b = a;
a = temp;
}
return (a /... | 11 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> mas[100100];
vector<vector<int> > vis;
vector<vector<int> > dist[2];
int main() {
int n, m;
scanf("%d %d", &n, &m);
int k;
scanf("%d", &k);
for (int i = 0; i < k; i++) {
scanf("%d", &mas[i].first);
mas[i].second = 0;
}
int l;
scanf("%d... | 12 |
#include <bits/stdc++.h>
int main() {
int a, b, x;
scanf("%d %d", &a, &b);
for (x = 1; x < a; x++) {
int y = (int)sqrt(a * a - x * x);
if (x * x + y * y == a * a) {
if (b * y % a == 0 && b * x % a == 0) {
int dx = b * y / a;
int dy = b * x / a;
if (y == dy) continue;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
string s;
cin >> s;
int t = 0;
for (int i = 0; i < n - 1; i++) {
if (s.substr(0, i + 1) == s.substr(n - i - 1)) {
t = i + 1;
}
}
cout << s;
for (int i = 1; i < k; i++) {
cout << s.substr(t);
}
ret... | 5 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
using namespace std;
const int N = 2e5 + 9;
inline int popcount(int x) {
int counter = 0;
__asm__ volatile("POPCNT %1, %0;" : "=r"(counter) : "r"(x) ... | 20 |
#include <bits/stdc++.h>
inline int getInt() {
int s;
scanf("%d", &s);
return s;
}
using namespace std;
int a[100][100];
int hh[100];
int ww[100];
int main() {
const int h = getInt();
const int w = getInt();
for (int i = 0; i < (int)(h); i++)
for (int j = 0; j < (int)(w); j++) a[i][j] = getInt();
for ... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1024;
long long T[4][N][N];
int n, m;
int Get(int x, int y) {
int Res = 0;
if (x % 2) Res += 1;
if (y % 2) Res += 2;
return Res;
}
void Add(int x, int y, long long v) {
int Index = Get(x, y);
for (int i = x; i <= n; i += i & (-i))
for (int j = ... | 17 |
#include <bits/stdc++.h>
using namespace std;
int n, i, j, k, len1, len2;
bool cell[55][55];
int dp[55][55][55][55];
string s;
int max_(int a, int b) {
if (a > b)
return a;
else
return b;
}
int min_(int a, int b) {
if (a < b)
return a;
else
return b;
}
int main() {
cin >> n;
for (i = 1; i <=... | 15 |
#include <bits/stdc++.h>
inline int read() {
int x = 0, f = 1;
char c = getchar();
while (!isdigit(c)) {
if (c == '-') f = -1;
c = getchar();
}
while (isdigit(c)) {
x = (x << 3) + (x << 1) + (c ^ 48);
c = getchar();
}
return f == 1 ? x : ~x + 1;
}
int n, m, q;
std::vector<int> vec[300010],... | 25 |
#include <bits/stdc++.h>
using namespace std;
long long int n, m, k;
long long int a[200005] = {0};
int main() {
ios::sync_with_stdio(false);
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
sort(a + 1, a + n + 1);
long long int ans = 0;
if (k == 1) {
ans = ((m + 1) / 2 * a[n]) + ... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long int n, bas;
vector<long long int> ans;
void solve() {
cin >> n;
ans.clear();
bas = -1;
long long int sayi = n;
while (n > 0) {
long long int basamak = n % 10;
n /= 10;
bas++;
if (basamak) {
long long int koy = basamak * (pow(10, bas... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
long long n, a[N], x, book, book2, ans;
long long cmp(long long a, long long b) { return a > b; }
int main() {
book = ans = book2 = 0;
scanf("%lld", &n);
for (int i = 0; i < n; i++) {
scanf("%lld", &x);
if (x & 1) {
if (x > 0) book... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100233;
vector<int> v;
struct mmp {
int to, next, len;
mmp() {}
mmp(int a, int b, int c) { to = a, next = b, len = c; }
} e[maxn << 1];
int vis[maxn], st, ed, cnt, head[maxn], val[maxn], len;
void add(int u, int v, int len) {
e[++cnt] = mmp(v, head[... | 15 |
#include <bits/stdc++.h>
using namespace std;
char str[13];
int a[13][103], b[13][103], c[13][103], arr[10003];
int main() {
int n, m, K, i, j, ans, c1, k, l, sum;
scanf("%d%d%d", &n, &m, &K);
for (i = 0; i < n; i++) {
scanf("%s", str);
for (j = 0; j < m; j++) scanf("%d%d%d", &a[i][j], &b[i][j], &c[i][j])... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[1000];
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
for (int i = 0; i < n; i++) {
cout << a[i] << " ";
}
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
int n;
cin >> n;
while (n--) {
int count = 0;
vector<int> v;
string s;
cin >> s;
for (int i = 0; i < int(s.size()); i++) {
if (s[i] == '1') count++;
if (s[i] == '0') {
v.push_back(count);
count = 0;
... | 0 |
#include <bits/stdc++.h>
int main(void) {
int n, cnt = 0, num[50];
char s[101];
scanf("%d%s", &n, s);
for (int i = 0; i < n; i++)
if (s[i] == 'B') {
num[cnt] = 1;
while (s[i + 1] == 'B') {
i++;
num[cnt]++;
}
cnt++;
}
printf("%d\n", cnt);
for (int i = 0; i < cn... | 0 |
#include <bits/stdc++.h>
int inv;
void merge(int a[], int low, int high, int mid) {
int i, j, k, c[high + 1];
i = low;
j = mid + 1;
k = low;
while ((i <= mid) && (j <= high)) {
if (a[i] < a[j]) {
c[k] = a[i];
k++;
i++;
} else {
c[k] = a[j];
inv = inv + mid - i + 1;
... | 11 |
#include <bits/stdc++.h>
const int N = 3000;
int n, a[N], m, b[N], c[N];
int f(int *a, int n) {
memcpy(b, a, n * sizeof(int));
for (int i = 0; i < n; ++i) {
c[b[i]] = i;
}
int ans = 0;
for (int i = 0; i < n; ++i) {
if (i != c[i]) {
c[b[i]] = c[i];
b[c[i]] = b[i];
ans++;
}
}
r... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int Mx = 1e5 + 5;
int arr[Mx];
int main() {
int n, i, j;
cin >> n;
for (int i = 1; i <= n; i++) scanf("%d", arr + i);
for (i = 30; i >= 0; i--) {
int T = 1 << i;
bool flag = false;
for (j = n; j >= 1 && arr[j] >= T; j--)
if (T & arr[j]) {
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int c[1005][1005];
int a[1005];
int main() {
int i, j, k;
c[1][0] = c[1][1] = 1;
for (i = 2; i < 1005; i++) {
c[i][0] = 1;
for (j = 1; j <= i; j++)
c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % 1000000007;
}
scanf("%d", &k);
int x, sum = 0;
for (i ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, v, m, a[305], b[305];
int dist[305][305], fa[305][305], lft;
vector<pair<pair<int, int>, int>> seq;
void dfs(const int &s, const int &t, const int &d) {
const int &f = fa[s][t];
int dd = d - a[f];
seq.emplace_back(make_pair(f, t), min(d, a[f]));
a[t] += min(d... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
while (n--) {
long long int a, b;
cin >> a >> b;
long long int temp = max(a, b);
long long int temp2 = min(a, b);
a = temp;
b = temp2;
if (((a + b) % 3 == 0) && (2 * b >= a))
cout << "YES\n";
... | 5 |
#include <bits/stdc++.h>
const int mod = 1e9 + 7;
using namespace std;
int n, a[1000007], b[1000007], tot;
int ask() {
cout << "? ";
for (int i = 1; i <= n; i++) cout << a[i] << " ";
cout << endl, tot++;
if (tot > n + n) {
cerr << "fuck";
}
int out = 0;
cin >> out;
return out;
}
int main() {
cin >... | 10 |
#include <bits/stdc++.h>
using namespace std;
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 m, n;
int mn[100005], mx[1... | 18 |
#include <bits/stdc++.h>
using namespace std;
double exact(long long int a, long long int b) { return (double)a / b; }
long long int gcd(long long int a, long long int b) {
if (a == 0 || b == 0) {
return (a + b);
}
return gcd(b, a % b);
}
long long int fastExpo(long long int a, long long int n, long long int ... | 2 |
#include <bits/stdc++.h>
using namespace std;
void go(int n, int m, bool c) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (c && i == n - 1 && j >= m - 2) {
cout << 'B';
continue;
}
if ((i + j) & 1) {
cout << 'W';
} else {
cout << 'B';
... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y) {
long long res = 1;
while (y > 0) {
if (y % 2 == 1) res *= x;
y /= 2;
x *= x;
}
return res;
}
int main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
;
int n, no;
cin >> n;
long long co... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f;
const long long MOD = 1e9;
const double PI = acos(-1.0);
struct Matr {
long long matr[2][2];
void Init() { memset(matr, 0, sizeof matr); }
} F[210000];
Matr Multi(Matr a, Matr b) {
Matr res;
res.Init();
for (int i = 0; i < 2; ++i)... | 7 |
#include <bits/stdc++.h>
using namespace std;
int d[100005];
vector<int> tree[100005];
int t, k = 0;
int arr[100005];
void solve() {
for (int i = 0; i < k; i++) {
int u = arr[i], siz = tree[u].size();
for (int j = 0; j < siz; j++) {
int v = tree[u][j];
if (d[v] <= 1 + d[u]) continue;
d[v] = ... | 16 |
#include <bits/stdc++.h>
using namespace std;
void fun(long long int n, long long int i, long long int j,
vector<vector<long long int> > &vec, long long int &ind) {
ind += 1;
if (n == 1) {
vec[ind][0] = i;
vec[ind][1] = j + 1;
vec[ind][2] = i + 1;
vec[ind][3] = j;
vec[ind][4] = i + 1;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 50;
int dp[MAXN][MAXN][MAXN][MAXN][2];
char s[MAXN][MAXN];
bool hasher[MAXN];
int n, m;
int dfs(int MINX, int MAXX, int MINY, int MAXY, int op) {
int res = dp[MINX][MAXX][MINY][MAXY][op];
if (res != -1) return res;
set<int> sa;
for (int i = 0; i < n... | 17 |
#include <bits/stdc++.h>
const double PI =
3.141592653589793238462643383279502884197169399375105820974944;
using namespace std;
int MOD = 1e9 + 7;
double gcd(double a, double b) { return a < 0.01 ? b : gcd(fmod(b, a), a); }
template <typename T>
T mymax(T a, T b) {
return (a > b) ? a : b;
}
template <typename T>
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n % 2 == 0) {
cout << -1 << '\n';
return 0;
}
for (int i = 0; i < n; i++) cout << i << " ";
cout << '\n';
for (int i = 0; i < n; i++) cout << i << " ";
cout << '\n';
for (int i = 0; i < n; i++) cout << (2 * i) % n ... | 5 |
#include <bits/stdc++.h>
template <typename T>
void MACRO_VAR_Scan(T& t) {
std::cin >> t;
}
template <typename First, typename... Rest>
void MACRO_VAR_Scan(First& first, Rest&... rest) {
std::cin >> first;
MACRO_VAR_Scan(rest...);
}
template <typename T>
void MACRO_VEC_ROW_Init(int n, T& t) {
t.resize(n);
}
tem... | 7 |
#include <bits/stdc++.h>
using namespace std;
int setbit(int n, int i, int v) {
return ((v) ? (n | (1 << i)) : (n & ~(1 << i)));
}
long long gcd(int i, int j) {
if (j == 0) return i;
return gcd(j, i % j);
}
bool chk(int n, int i) {
if ((n >> i) & 1 == 1) return 1;
return 0;
}
bool T(pair<pair<int, int>, int> ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 500005;
const long long mod = 1e9 + 7;
void solve() {
long long x = 0, y = 0, c = 0, ans = 0;
long long n, m, k;
cin >> n;
long long a[3][n], dp[3][n];
for (long long i = 0; i < 3; ++i) {
for (long long j = 0; j < n; ++j) {
cin >> a[i... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int P = 998244353;
int n, m, f[20][20][20][20][2][2], g[20][20][20][20][2][2];
int cnx[32], cpx[32], cny[32], cpy[32];
void red(int &x) { x += x >> 31 & P; }
int main() {
scanf("%d %d", &n, &m);
for (int i = 0, x, y; i < n; i++) {
scanf("%d %d", &x, &y);
x... | 27 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, size_t size>
ostream &operator<<(ostream &os, const array<T, size> &arr) {
os << '{';
string sep;
for (const auto &x : arr) os << sep << x, sep = ", ";
return os << '}';
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
os ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int MAXP = 100500;
bool is_prime[MAXP];
const int MAXN = 300;
int ans[MAXN];
int rev[MAXN];
int rev1[MAXN];
int sm[MAXN][MAXN];
int n, arr[MAXN];
bool used[MAXN];
void gen_primes() {
for (int i = 0; i < MAXP; ++i) {
is_prime[i] = true;
}
is_prime[0] = is_pri... | 15 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int main() {
long long t, w, b;
cin >> t >> w >> b;
long long g = gcd(w, b);
long long nl = t / w * g / b;
long long ml = nl * (w / g * b);
long long res = nl * min(w, b) + min(t - ml + 1,... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int N = 1e6;
void my_dbg() { cout << endl; }
template <typename Arg, typename... Args>
void my_dbg(Arg A, Args... B) {
cout << ' ' << A;
my_dbg(B...);
}
int main() {
int n;
scanf("%d", &n);
vector<int> a(n), b(n), c(n), d(n);
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int c=300002;
int w, n, db[c], t[c], kezd, veg, sp, ert, pos;
int main()
{
ios_base::sync_with_stdio(false);
cin >> w;
while(w--) {
cin >> n, kezd=1, veg=n, ert=0, sp=1, pos=1;
for (int i=1; i<=n; i++) db[i]=0;
for (int i=1; i<=n; ... | 10 |
#include <bits/stdc++.h>
using namespace std;
string s;
long long fun(char a, char b, char c) {
long long ans = 0;
for (long long i = 0; i < s.size(); i++) {
if (s[i] != a && i % 3 == 0) ans++;
if (i % 3 == 1 && s[i] != b) ans++;
if (i % 3 == 2 && s[i] != c) ans++;
}
return ans;
}
void print(char a,... | 5 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
ll n, k;
cin >> n >> k;
string s;
cin >> s;
ll mx = -1, mn = 1e9;
map<char, ll> mp;
for (char i : s) {
mp[i]++;
}
for (auto i : mp) {
mx... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 100100, MMAX = 100100;
const int VMAX = 100100, EMAX = 200100;
struct Digonal {
int x;
int y;
int cnt;
};
struct Polygon {
int color;
vector<int> point;
};
struct Edge {
int y;
int nxt;
int rev;
bool ban;
};
int N, M;
Digonal dig[MMAX];
in... | 20 |
#include<bits/stdc++.h>
#define t int t;cin>>t;while(t--)
using namespace std;
int main()
{
t{
int n;
cin>>n;
long long val[n];
for(int i=0;i<n;i++)
cin>>val[i];
if(n%2!=0){
for(int i=0;i<n/2... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
long long x;
cin >> x;
x *= 6;
long long ans = 0;
vector<pair<long long, long long> > answers;
for (long long m = 1; m * (m + 1) * (2 * m + 1) <= x; ++m) {
long long d = m * (m + 1);
if (x % ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int P[N], n;
int main(void) {
int ans = 2;
int len = 2;
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &P[i]);
if (i >= 2) {
if (P[i] == P[i - 1] + P[i - 2]) {
len++;
ans = max(ans, len);
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
char a[2], b[2], c, d;
int x, y;
cin >> a >> b;
x = a[0] - b[0];
y = a[1] - b[1];
c = (x < 0 ? x = -x, 'R' : 'L');
d = (y < 0 ? y = -y, 'U' : 'D');
cout << max(x, y);
while (x || y) {
cout << "\n";
i... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 21;
int n, m, a[N][N], dp[1 << N], se[N][N], co[N][N];
char s[N + 2][N + 2];
bool vis[26];
void upd(int &u, const int &v) { u == -1 ? u = v : u = min(u, v); }
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%s", s[i] + 1);
}... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long i, j, k, l, n, m, t;
string a, b, c, d;
cin >> a;
int after = 0;
int op, cl, ha;
op = cl = ha = 0;
int lst;
for (i = 0; i < a.size(); i++) {
if (a[i] == '(')
op++;
else if (a[i] == ')')
cl++;
else {
ha++;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
void output_strings(int ind[], string s[]) {
for (int i = 0; i < 6; i++) {
cout << s[ind[i]] << " ";
}
cout << endl;
return;
}
bool check(int ind[], string s[]) {
int l[6];
char b[6], e[6];
for (int i = 0; i < 6; i++) {
l[i] = s[ind[i]].length();
b... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int GO_MAX = 26;
const int ESP = 1e-9;
const int MAX = 101001;
const int INF = 1e9;
const int H_val = 37;
const int mod = 1000000;
const double PI = 3.14159265359;
int n, m, k, t, p, q;
int num[MAX * 5];
bool vst[MAX * 5], trig = true;
vector<int> vec[MAX * 5];
struct... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int maxRange = 100000;
int n, m;
int np = 0;
int nf;
int factor[100001];
int l[100001];
int on[100001];
bool seive[maxRange + 1];
int prime[100001];
void createSieve();
void analize(int);
int main() {
list<int>::iterator it;
createSieve();
for (int i = 2; i <= 1... | 8 |
#include <bits/stdc++.h>
using namespace std;
int A[200000];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int N, K;
cin >> N >> K;
N *= 2;
for (int i = 0; i < N; ++i) A[i] = i + 1;
for (int i = 0; i < 2 * K; i += 2) swap(A[i], A[i ^ 1]);
for (int i = 0; i < N; ++i) cout << A[i] << " \n"[i ... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long num[100009], a[100009];
int f[100009];
struct edge {
int x, y;
long long w;
void input() {
scanf("%d%d", &x, &y);
w = min(a[x], a[y]);
}
bool operator<(const struct edge &b) const { return w > b.w; }
} e[100009];
int refa(int x) {... | 11 |
#include <bits/stdc++.h>
#define i64 long long
#define sz(a) int ((a).size())
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define per(i, a, b) for (int i = (b) - 1; i >= (a); --i)
using namespace std;
const int N = 1501, Nk = 11;
int n, k, a[N][N], cnt[Nk], f[N];
bool vis[N * N];
vector<pair<int, int>> c[N][N... | 21 |
#include <bits/stdc++.h>
using namespace std;
const int iinf = 1e9 + 7;
const long long linf = 1ll << 60;
const double dinf = 1e10;
template <typename T>
inline void scf(T &x) {
bool f = 0;
x = 0;
char c = getchar();
while ((c < '0' || c > '9') && c != '-') c = getchar();
if (c == '-') {
f = 1;
c = ge... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
for (int i = 0; i < t; i++) {
int n, m;
cin >> n >> m;
if (m > n) swap(m, n);
if (m * 2 >= n)
cout << m * 2 * m * 2 << endl;
else
cout << n * n << endl;
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
struct Point {
double x, y;
Point() {}
Point(double _x, double _y) {
x = _x;
y = _y;
}
double get() {
int a, b;
scanf("%d%d", &a, &b);
return 1.0 * a / b;
}
void read() {
double x1 = get(), y1 = get();
x = x1 / (x1 * x1 + y1 * y1);
... | 22 |
#include <bits/stdc++.h>
using namespace std;
set<int> st[26];
bool vis[26];
string s, ans;
char ab;
void dfs(int pos) {
vis[pos] = true;
for (auto i : st[pos]) {
if (!vis[i]) dfs(i);
}
ab = (char)'a' + pos;
ans += ab;
}
int main() {
int t;
cin >> t;
while (t--) {
ans = "";
cin >> s;
for... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, m, c, x, aux[1010];
int main() {
scanf("%d %d %d", &n, &m, &c);
for (int i = 0; i < 1010; i++) aux[i] = 1010;
for (int i = 0; i < m; i++) {
scanf("%d", &x);
if (x <= c / 2) {
for (int j = 0; j < n; j++)
if (aux[j] > x) {
aux[j] =... | 12 |
#include <bits/stdc++.h>
using namespace std;
int cnt[30];
long long ans;
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
string s;
cin >> s;
cnt[s[0] - 'a']++;
}
for (int i = 0; i < 26; i++) {
long long x = cnt[i] / 2, y = cnt[i] / 2 + cnt[i] % 2;
ans += x * (x - 1) / 2 + y *... | 1 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, k;
cin >> n >> k;
vector<unsigned int> ips;
char _;
for (int i = 0; i < n; i++) {
unsigned int ip = 0;
vector<int> A(4);
cin >> A[3] >> _ >> A[2] >> _;
cin >> A[1] >> _ >> A[0];
for (int j = 0; j < 4; j++)
for (int b... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> e1[250010], e2[250010];
int tin[250010], tout[250010], curt;
int par[250010][18];
int uf[250010];
int find(int u) {
if (u == uf[u]) return u;
return uf[u] = find(uf[u]);
}
void merge(int u, int v) {
u = find(u);
v = find(v);
uf[v] = u;
}
bool is... | 24 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 3e5 + 4;
int n, m, loga;
bool vis[maxN];
char str[maxN];
set<int> Set[256];
int aib[maxN];
inline int lsb(int x) { return x & (-x); }
void update(int pos, int val) {
for (int i = pos; i <= loga; i += lsb(i)) aib[i] += val;
}
int query(int val) {
int sum... | 13 |
#include <bits/stdc++.h>
using namespace std;
bool bj = 0;
int n, m, ans, tmp, a[100005], b[100005], q[100005];
long long s1[100005], s2[100005];
struct node {
long long icr, num, mn, mx, val;
} P[100005 << 2];
void mdy(int k, long long x) {
node &o = P[k];
o.icr += x;
o.mx += x;
o.mn += x;
o.val += x;
}
vo... | 25 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y) {
if (y == 0) return x;
return gcd(y, x % y);
}
long long pp(long long x, long long y) { return x * y / gcd(x, y); }
int main() {
long long n, a, b, p, q;
long long ans = 0;
cin >> n >> a >> b >> p >> q;
long long a0 = n /... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MX = 3e5 + 5;
int Head[MX], erear;
struct Edge {
int u, v, nxt, z;
} E[MX << 1];
void edge_init() {
erear = 0;
memset(Head, -1, sizeof(Head));
}
void edge_add(int u, int v, int z) {
E[erear].u = u;
E[erear].v = v;
E[erear].z = z;
E[erear].nxt = Head[... | 15 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-8;
const long long mod = 1000000007LL;
const long long inv = 500000004LL;
long long mult(long long a, long long b) {
return ((a % mod) * (b % mod)) % mod;
}
long long sub(long long a, long long b) {
return (mod * 2LL +... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, i, j, t, m, k, l, sum, v1, r, q, f, x, kol, y, p, z;
string s;
cin >> p;
cin >> s;
char a, b;
k = 0;
for (j = 25; j > 0; j--) {
for (i = p - 1; i > -1; i--) {
if (s[i] == 97 + j) {
a = s[i];
b = s[i - 1];
... | 8 |
#include <bits/stdc++.h>
using namespace std;
bool vowel(char c) {
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') return 1;
return 0;
}
int main() {
string s;
cin >> s;
for (int i = 1; i < s.length(); i++) {
if (!vowel(s[i]) && !vowel(s[i - 1]) && s[i - 1] != 'n') {
cout << "NO";
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
char a[100];
cin >> s;
int x = 0;
for (int i = 0; i < s.length(); i++) {
if (!((tolower(s.at(i)) == 'a') || (tolower(s.at(i)) == 'e') ||
(tolower(s.at(i)) == 'u') || (tolower(s.at(i)) == 'i') ||
(tolower(s.at(i)) == '... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int height, width;
cin >> height >> width;
int i;
char* row = (char*)malloc(width);
int answer = 0;
for (i = 0; i < height; i++) {
cin >> row;
if (i == height - 1) {
int j;
int last = 0;
for (j = 0; j < width; j++) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, b, a;
cin >> n;
a = n / 3;
if (n == 3) {
cout << a << " " << a << " " << a;
} else {
b = n - 3;
if (b % 3 != 0) {
cout << 1 << " " << 2 << " " << b;
} else {
cout << 2 << " " << 2 << " " << b - 1;
}
}
r... | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.