solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1 + 2e5;
long long low[MAXN], num[MAXN], id[MAXN], vis[MAXN], vtime, nscc, n, m, f[MAXN],
ans, x, sz[MAXN], sum[MAXN], dp[MAXN][2], res, kt;
stack<int> s;
vector<int> g[MAXN], p[MAXN];
long long dfs(int u) {
vis[u] = 1;
low[u] = num[u] = ++vtime;
... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005 * 4, M = 500005;
int n, m, q;
struct qq {
int x, y, last;
} e[M * 2];
int num, last[N];
void init(int x, int y) {
num++;
e[num].x = x;
e[num].y = y;
e[num].last = last[x];
last[x] = num;
}
int dfn[N], low[N], sta[N], top, id;
vector<int> vec... | 15 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long quickpow(long long a, long long b) {
long long res = 1;
while (b) {
if (b & 1) res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
char s[200020];
int main(void) {
int t... | 10 |
#include <bits/stdc++.h>
#define ALL(v) (v).begin(), (v).end()
struct Point {
int x, y;
};
Point operator-(const Point &a, const Point &b) {
return {a.x - b.x, a.y - b.y};
}
bool by_x(const Point &a, const Point &b) { return a.x < b.x; }
long long area(int a, int b) { return 1LL * a * b; }
long long det(const... | 27 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007, M = 3e5 + 7;
long long powe(long long x, long long y) {
x = x % mod;
long long ans = 1;
while (y > 0) {
if (y & 1) {
ans = (1ll * x * ans) % mod;
}
y >>= 1;
x = (1ll * x * x) % mod;
}
return ans;
}
int main()... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
double ans, sum = 0;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
sum += x;
}
ans = (double)100 * sum / (100 * n);
printf("%.9lf\n", ans);
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
int n, m, q, c, x, y, z, root[N], root2[N], emp[N];
vector<int> uni[N], mil[N];
vector<pair<int, long long> > v[N], bel[N], bel2[N];
int findset(int x) { return root[x] = (root[x] == x ? x : findset(root[x])); }
int findset2(int x) {
return root2[x]... | 23 |
#include <bits/stdc++.h>
using namespace std;
int n, a[100005];
int s[100005], top;
void work() {
int i, j;
scanf("%d", &n);
for (i = 1; i <= n; ++i) scanf("%d", &a[i]);
for (i = 1; i <= n; ++i) {
if (a[i] > s[top])
s[++top] = a[i];
else {
j = upper_bound(s + 1, s + top + 1, a[i]) - s;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int sum = n;
cout << n / 2 << endl;
for (int i = 0; i < n / 2 - 1; i++) {
cout << 2 << endl;
sum -= 2;
}
cout << sum;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
void min(int &a, int b) {
if (a > b) a = b;
}
int dis[202][202];
int n, m;
vector<pair<int, int> > e[202];
void floyd() {
int i, j, k;
for (i = 0; i <= n; i++) dis[i][i] = 0;
while (true) {
bool bans = false;
for (i = 0; i < n; i++)
for (j = 0; j < n; ... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_ELEMENT = 100000;
int main() {
int i, j;
int N, M;
int s, e;
cin >> N >> M >> s >> e;
vector<int> a(N), b(M);
vector<int> indexes[MAX_ELEMENT + 2];
for (i = 0; i < N; i++) cin >> a[i];
for (i = 0; i < M; i++) {
cin >> b[i];
indexes[b[i]... | 15 |
#include <bits/stdc++.h>
using namespace std;
int dist[1003][1003];
int dr[] = {-1, 1, 0, 0};
int dc[] = {0, 0, -1, 1};
int main() {
int R, C;
cin >> R >> C;
vector<string> V(R);
for (int i = 0; i < R; ++i) cin >> V[i];
int exitr, exitc;
int curr, curc;
for (int i = 0; i < R; ++i)
for (int j = 0; j < ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int _max = 1e5 + 10;
int n, s;
int a[_max];
int root;
int main() {
scanf("%d", &n);
while (n--) {
scanf("%d", &s);
root = 0.5 + sqrt(s);
for (int i = 2; i <= root; i++) {
if (s % i == 0) a[i]++;
while (s % i == 0) s /= i;
}
if (s > ... | 6 |
#include <bits/stdc++.h>
using namespace std;
using pr = pair<int, int>;
int N, A[100005], B[100005], deg[100005], output[100005], idx;
int dfs_num[100005];
vector<int> coor, v[100005];
bool chk[222222];
vector<pr> edge;
pr T1[100005], T2[100005];
int index(int x) {
return lower_bound(coor.begin(), coor.end(), x) - c... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int t, n;
cin >> t;
while (t--) {
cin >> n;
if (n % 3 == 0 || n % 7 == 0)
cout << "YES"
<< "\n";
else {
long long int max = n / 3;
long long int ch = 0... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int t, n, a[N], diff[N], L[N], R[N];
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> t;
while (t--) {
cin >> n;
long long ans = 0;
for (int i = 0, cur = 0; i < n; i++) {
cin >> a[i];
cur = max(cur, a... | 4 |
#include <bits/stdc++.h>
using namespace std;
bool visited[101] = {0};
vector<pair<int, int>> v[101];
bool dfs(int s, int d, int c) {
visited[s] = true;
if (s == d) return 1;
for (int i = 0; i < v[s].size(); i++) {
pair<int, int> p = v[s][i];
if (p.second == c && !visited[p.first]) {
if (dfs(p.first... | 16 |
#include <bits/stdc++.h>
using namespace std;
int n, grundy[100010], res = -1;
int main() {
cin >> n;
for (int i = 3; i <= n; i++) {
set<int> s;
int p = 0;
for (int j = 2;; j++) {
int sum = i - j * (j + 1) / 2;
int ng = 0;
if (sum < 0) break;
if (sum % j) continue;
for (int... | 12 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const int mod = 1e9 + 7;
const int N = 7e3 + 10;
inline int add(int x, int y) {
x += y;
if (x >= mod) x -= mod;
return x;
}
inline int mul(int x, int y) {
x = (1LL * x * y) % mod;
return x;
}
int dp[2][N];
int size[2][N];
int k[2];
int ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
int maxO = 0;
int a = 0;
int n, k;
int invitados[30];
int abierta[30];
string lista;
memset(invitados, 0, sizeof(invitados));
memset(abierta, 0, sizeof(abierta));
cin >> n >> k >> lista;
for (int i = ... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long sum[100010 << 3][5];
int c[100010 << 3];
int n, m;
long long d[100010];
int p1, p2;
typedef struct {
int a;
long long b;
} Q;
Q q[100010];
void PushUp(int t) {
c[t] = c[t << 1] + c[t << 1 | 1];
for (p1 = 0; p1 < 5; p1++) {
sum[t][p1] = sum[t << 1][p1];... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
const int MAX = 1e9 + 5;
int i, j, k, n, m, ans, h;
long long leaf;
long long solve(long long x, long long y, int depth, bool d) {
long long mid = x + y >> 1;
if (depth == 0) return 0;
if (leaf > mid) {
if (d == 1) return solve(mid + 1, y, d... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int n, a[105];
vector<int> v;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
for (int i = 0; i < n; i++) {
int j;
for (j = 0; j < (int)v.size(); j++) {
if (v[j] <= a[i])... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[5][5];
int x = -1, y = -1;
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
cin >> a[i][j];
if (a[i][j] == 1) {
x = i;
y = j;
}
}
}
cout << abs(x - 2) + abs(y - 2) << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int a;
char buf[10010];
int ans;
vector<int> tot;
int main() {
scanf("%d", &a);
scanf("%s", buf + 2);
int n = strlen(buf + 2);
buf[1] = '+';
for (int i = 1; i <= n; i += 3) {
int coef;
if (buf[i] == '+')
coef = 1;
else
coef = -1;
i++;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int mod = 998244353;
int inf = 1e15;
int n, m, q, k;
int w[200003];
int M2[200003];
map<int, int> M;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string s;
cin >> s;
int d1 = -1;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '[') {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int binpow(int a, int b) {
if (b == 0) return 1;
if (b % 2)
return (1ll * binpow(a, b - 1) * a) % m;
else {
int t = binpow(a, b / 2);
return (1ll * t * t) % m;
}
}
int main() {
scanf("%d %d", &n, &m);
if (m == 1) {
putchar('0');
ret... | 6 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
while (a != 0 && b != 0) {
if (a > b)
a %= b;
else
b %= a;
}
return a + b;
}
vector<string> data;
vector<int> param;
int func(int t, int tmp) {
if (tmp == -1) return -1;
if (t + tmp < 0) return -1;
return t + tmp;
}
vo... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int SZ = 5100;
vector<int> v[SZ];
int n, m;
int to[SZ];
int get_val(int fir, int sec) {
if (fir <= sec)
return sec - fir;
else
return n - fir + sec;
}
int main() {
ios::sync_with_stdio(false);
cin >> n >> m;
int a, b;
for (int i = 0; i < n; i++) {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
pair<int, pair<int, int>> nextt[201][201][201];
int dp[201][201][201];
string s, t;
int ans(int curr1, int curr2, int val, int siz) {
if (siz > 2000 || curr1 > 200 || curr2 > 200 || val > 200) {
return 1000000000;
}
if (curr1 == s.size() && curr2 == t.size()) {
... | 14 |
#include <bits/stdc++.h>
using namespace std;
int score(const string& s) {
static int n, a[80];
n = s.length();
transform(s.begin(), s.end(), a, bind2nd(minus<int>(), 'a' - 1));
return accumulate(a, a + n, 0) * *max_element(a, a + n);
}
struct Status {
int w, a, b;
Status(int w = -1, int a = 0, int b = 0) :... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k;
cin >> n >> k;
long long a[n];
for (long long i = 0; i < n; i++) {
cin >> a[i];
}
long long mn = a[0], mx = a[0], done = 0;
for (long long i = 1; i < n; i++) {
if (abs(a[i] - a[i - 1]) % k != 0) {
cout << "-1" << endl... | 1 |
#include <bits/stdc++.h>
using namespace std;
int a[1000000], n;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
sort(a, a + n);
n = unique(a, a + n) - a;
for (int i = 0; i < n - 1; i++) {
if ((a[i] * 2) > a[i + 1]) {
printf("YES\n");
return 0;
}
}... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 34;
const int maxlog = 20;
const int mod = 1e9 + 7;
const int sq = 720;
int par[maxn], mark[maxn];
vector<pair<int, int> > roots;
int main() {
int n, ans = 0;
cin >> n;
int tof = 0;
for (int i = 1; i <= n; i++) cin >> par[i];
int k = 0;
fo... | 9 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
ll t;
cin >> t;
for (ll i = 0; i < t; i++) {
ll n;
cin >> n;
vector<pair<ll, ll>> in;
ll mi, ma;
cin >> mi;
ma = mi;
for (ll ... | 6 |
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
bool isPowerOfTwo(long long int x) { return x && (!(x & (x - 1))); }
void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
long long binpow(long long a, long long b) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int arr[3][3], sum = 0;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
cin >> arr[i][j];
sum += arr[i][j];
}
}
sum /= 2;
arr[0][0] = sum - (arr[0][1] + arr[0][2])... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int inv = 1000000000;
const int minv = -inv;
const int max_n = 1000000 + 5;
int n, m;
vector<int> inadjl[max_n], outadjl[max_n];
bool rm[max_n];
vector<int> ch;
vector<vector<int> > inch;
bool sol[max_n];
int solct;
int main() {
scanf("%d", &n);
scanf("%d", &m);
... | 22 |
#include <bits/stdc++.h>
using namespace std;
const unsigned long long INF = 100000000000000;
int gcd(int i, int j) {
if (j == 0)
return i;
else
return gcd(j, i % j);
}
const long long m = 1000000007;
const int Y = 500000;
long long arr[Y + 2];
long long T[Y + 2];
long long T1[Y + 2];
long long T2[Y + 2];
l... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long infzero, zeros, res;
int main() {
long n;
cin >> n;
long long a[n];
for (int i = 0; i < n; ++i) {
cin >> a[i];
if (a[i] < 0)
infzero++;
else if (a[i] == 0)
zeros++;
if (a[i] == 0)
res++;
else if (a[i] > 0) {
res ... | 1 |
#include <bits/stdc++.h>
const int mx = 2e5 + 10;
using namespace std;
long long a[mx], seg[4 * mx], fen[mx], n, q;
void addf(int id, int val) {
for (; id < mx && id != 0; id += id & -id) fen[id] += val;
}
long long getf(int id) {
long long ans = 0;
for (; id > 0; id -= id & -id) ans += fen[id];
return ans;
}
v... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
string s;
int vis[N];
vector<int> v;
vector<int> q;
int l;
void init() {
for (int i = l - 1; i >= 0; i--) {
if (s[i] == '1') v.push_back(i);
}
q.clear();
int a = -1, b = -1;
for (int i = 0; i < l; i++) {
if (s[i] == '0' && a == -1) ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int DI[] = {-1, 0, 1, 0};
const int DJ[] = {0, 1, 0, -1};
const int MAXINT = 0x7fffffff;
const int BIGINT = 0x20000000;
const long long MAXLL = 0x7fffffffffffffffLL;
const long long BIGLL = 0x2000000000000000LL;
template <typename T>
T gcd(T a, T b) {
return b ? gcd... | 15 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000000,100000000000")
using namespace std;
const long long inf = 2e18 + 7;
const long long mod = 1e9 + 9;
const double eps = 1e-9;
const double PI = 2 * acos(0.0);
const double E = 2.71828;
int n, m;
char type[100005];
int num[100005];
int cnt[100005];
int ... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long md = 1e9 + 7;
long long qp(long long a, long long b) {
long long ret = 1;
while (b) {
if (b & 1) ret = ret * a % md;
a = a * a % md;
b >>= 1;
}
return ret;
}
bool mk[200200];
int pri[200200], mu[200200];
void mobi() {
mu[1] = 1;
for (... | 23 |
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template <class T = int>
using V = vector<T>;
template <class T = int>
using VV = V<V<T> >;
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n;
cin >> n;
V<> a(n);
for (auto&& e : a) cin >> e;
V<> c(2e5 + 1);
for (int i... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
struct path {
int st, ed, idx;
long long w;
path(int uu, int vv, int ii, long long ww) {
st = uu;
ed = vv;
idx = ii;
w = ww;
}
};
struct RULE {
bool operator()(path &x, path &y) const { return x.w > y.w; }
};
priority_qu... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, count = 0, count2 = 0;
cin >> a >> b;
int arr[a];
for (int i = 0; i < a; i++) {
cin >> arr[i];
if (arr[i] <= b) {
count++;
} else {
count2 += 2;
}
}
cout << count + count2;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, k, x, s, i, a[300000], b[300000], a2[300000], b2[300000], sum,
a1, b1;
long long calc(long long q) {
int low = 0, high = k - 1, mid;
mid = (high + low) / 2;
while (low <= high) {
if (b[mid] <= q) {
low = mid + 1;
} else {
high =... | 8 |
#include <bits/stdc++.h>
int n, m, f[101][101], calc[110][110];
int main() {
scanf("%d%d", &n, &m);
for (int i = 1, k; i <= n; i++) {
scanf("%d", &k);
for (int j = 1, l, r; j <= k; j++) scanf("%d%d", &l, &r), ++calc[l][r];
}
for (int i = m; i; i--)
for (int j = 1; j <= m; j++) calc[i - 1][j] += calc... | 21 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
if (n == 2)
cout << 2 << endl;
else
cout << 1 << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int i, j, k, n, d;
cin >> n;
cout << n - 1 << endl;
for (i = 2; i <= n; i++) {
cout << i << " ";
}
cout << endl;
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long x = 0, f = 1;
char p = getchar();
while (!isdigit(p)) {
if (p == '-') f = -1;
p = getchar();
}
while (isdigit(p)) x = (x << 3) + (x << 1) + (p ^ 48), p = getchar();
return x * f;
}
const long long maxn = 8e3 + 5, mod =... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
int Arr[2][2], fac[2][maxn], cnt[2][2];
void divFact(int* a, int* b, int& c, int n) {
while (n % 2 == 0) {
b[0]++;
n /= 2;
}
while (n % 3 == 0) {
b[1]++;
n /= 3;
}
int m = sqrt(n);
for (int i = 5; i <= m; i++) {
while (n... | 11 |
#include <bits/stdc++.h>
using namespace std;
char a[1000], b[1000], c[1000];
int main() {
scanf("%s", c);
int j = 0, k = 0;
bool answer = false;
for (int i = 0; c[i] != '\0'; ++i) {
if (c[i] == '.') {
answer = true;
continue;
}
if (!answer) {
a[k] = c[i];
k++;
} else {
... | 0 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:640000000")
using namespace std;
string s, t, best_ans = "", cur_pref = "";
int let[256];
string get(int N) {
string answer = "";
for (int i = 'a'; i <= 'z'; i++)
if (let[i] && i > t[N]) {
answer += i;
break;
};
if (!answer.size()) retur... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long pw(long long a, long long b) {
long long r = 1;
for (; b; b >>= 1, a = a * a % mod)
if (b & 1) r = r * a % mod;
return r;
}
long long n, k, inv[int(1e5)];
int main() {
ios ::sync_with_stdio(0);
cin >> n >> k;
for (int i = 1... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_M = 110000;
const int INF = 1 << 28;
const double EPS = 1e-9;
const double PI = 3.14159265358979;
int m;
double R;
double d[MAX_M];
double solve() {
d[0] = 0;
for (int i = (1); i < (m); i++) {
d[i] = 2 * R * i + d[i - 1];
}
double s = 0.0;
double... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
long long n;
cin >> n;
string s;
cin >> s;
long long ma = 0, ans = 1, first = n - 1;
for (long long i = 0; i < n; i++) ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
long int p[n + 1];
p[0] = 1;
for (int i = 1; i <= n; i++) {
cin >> p[i];
}
sort(p, p + n + 1);
if (p[k] != p[k + 1]) {
cout << p[k];
} else {
cout << -1 << "\n";
}
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("-O2")
const int LIM = 1e5 + 5, MOD = 1e9 + 7;
int n;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
long long a = (1 << n);
long double divv = a;
long long sum = 0, r, x, y;
long long A[a + 5];
cin >> r;... | 17 |
#include <bits/stdc++.h>
using namespace std;
int ans;
set<int> s;
set<int>::iterator it;
void init() {
int i, x;
s.clear();
for (i = 1, x = 1; i <= 30; ++i) {
x <<= 1;
s.insert(x);
}
}
inline int calc(int l1, int r1, int l2, int r2) {
return (
(0) > (((r1) < (r2) ? (r1) : (r2)) - ((l1) > (l2) ?... | 16 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-') f = -1;
for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
return x * f;
}
const int MAXN = 100010;
const int INF = 1e9;
const long long Mod = 1e9 +... | 22 |
#include <bits/stdc++.h>
using namespace std;
int in[50];
bool visited[50] = {false};
vector<vector<int> > v(50);
vector<vector<int> > output(50);
int main(int argc, char const *argv[]) {
int n, m, a, b;
cin >> n >> m;
memset(in, 0, sizeof(in));
for (int i = 0; i < m; i++) {
cin >> a >> b;
v[a].push_bac... | 7 |
#include <bits/stdc++.h>
using namespace std;
int a[200005];
int b[200005];
int c[200005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t, i, j, k, l, n, m;
cin >> t;
while (t--) {
cin >> n;
for (i = 1; i <= n; i++) {
cin >> a[i];
}
for (i = 1; i <= n; i++) cin >> b[... | 2 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
const long double pi = acos(-1);
const long long maxn = 1e5 + 5;
const int mod = 1073741824;
const long long INF = 1e18;
const int MX = 2000000001;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
long long t, ... | 7 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:512000000")
using namespace std;
using li = long long;
using ld = long double;
void solve(bool);
void precalc();
clock_t start;
int main() {
start = clock();
int t = 1;
cout.sync_with_stdio(0);
cin.tie(0);
cout.precision(20);
cout << fixed;
precalc(... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
long long t, n, m, x;
string s;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(0);
cin >> t;
while (t--) {
cin >> n >> s;
x = 0;
cout << 1;
for (int i = 1; i < n; i++) {
if (s[i] == '1') {
x = i;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
int n, k;
cin >> n >> k;
vector<int> inp;
int odd = 0;
for (int i = 0; i < n; i++) {
int temp;
cin >> temp;
if (temp % 2 == 1) odd++;... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long read() {
long long X = 0, w = 0;
char ch = 0;
while (!isdigit(ch)) {
w |= ch == '-';
ch = getchar();
}
while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
return w ? -X : X;
}
int i1, i2, i3, i4, ians;
int main() {
i1 = r... | 12 |
#include <bits/stdc++.h>
using namespace std;
vector<int> node[100001];
int n;
vector<int> ans;
bool solve(int grand, int parent, int now) {
ans.push_back(now);
int sum = 0;
bool foundpre = false;
int real = 0;
for (int i = 0; i < 4; i++) {
int next = node[parent][i];
for (int j = 0; j < 4; j++) {
... | 12 |
#include <bits/stdc++.h>
using namespace std;
char ch[2111];
vector<pair<int, int> > ans;
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n, k;
scanf("%d %d", &n, &k);
scanf("%s", ch + 1);
ans.clear();
int s;
if (ch[1] == '(')
s = 1;
else
s = 0;
for (int i = 2; i... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const int MAXN = 100009;
int n;
char s[MAXN];
int main() {
scanf("%d", &n);
scanf("%s", s);
int ans = 0;
for (int i = 0; i < n; ++i) {
if (i == n - 1) {
++... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
int n, m, a[maxn], cnt[maxn], l[maxn], r[maxn], dp[maxn], ans[maxn];
void solve() {
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
if (a[i] <= n) {
cnt[a[i]]++;
}
}
for (int i = 1; i <= m; ++i) {
cin >> l[i... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n;
bool f[50][50];
void print() {
int odd = 1, even = 2, curr = -1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (f[i][j]) {
curr = odd;
odd += 2;
} else {
curr = even;
even += 2;
}
printf... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
bool predicate(long long int rounds, vector<long long int> &v,
long long int sum) {
long long int n = v.size();
long long int a = (n - 1) * rounds;
long long int b = sum;
long long int c = v[0];
if ((a - b) >= c)
return ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 7;
int dist[N], A[N], B[N];
pair<int, int> P[N];
void solve() {
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> A[i];
}
for (int i = 1; i <= n; ++i) cin >> B[i];
int last = n;
memset(dist, -1, sizeof(dist));
dist[n] = 0;
queu... | 11 |
#include <bits/stdc++.h>
using namespace std;
int x[5007];
set<int> s;
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> x[i];
}
for (int i = 1; i <= n; i++) {
if (s.count(i) == 1) {
continue;
}
int r = 0, m = i;
int a = i, b = x[i], c = x[x[i]];
while (r < 4) {... | 0 |
#include <bits/stdc++.h>
using namespace std;
int numof(char *s) {
int n;
n = s[0] - '0';
n *= 10;
n += s[1] - '0';
return n;
}
int main() {
char dh[10];
int n, m;
scanf("%s", dh);
n = numof(dh);
m = numof(dh + 3);
if (n >= 12) n -= 12;
double x = 0.0;
double y = 0.0;
y = 6.0 * (double)m;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
inline long long int gcd(long long int a, long long int b) {
return b ? gcd(b, a % b) : a;
}
inline long long int lcm(long long int a, long long int b) {
return a * b / gcd(a, b);
}
inline long long int add(long long int a, long long i... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, x, y, z, k, i, s[222222];
vector<int> g[222222];
map<int, int> m;
int main() {
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &x);
y = m[x];
if (y == 0) {
m[x] = y = ++k;
s[k] = x;
}
scanf("%d", &x);
z = m[x];
if (z... | 9 |
#include <bits/stdc++.h>
using namespace std;
inline void init(string name) {
string in = name + ".in", out = name + ".out";
freopen(in.c_str(), "r", stdin);
freopen(out.c_str(), "w", stdout);
}
const int mod = 998244353;
inline long long ksm(long long x, long long y) {
long long ans = 1;
while (y) {
if (... | 17 |
#include <bits/stdc++.h>
const double eps = (1e-9);
using namespace std;
int dcmp(long double a, long double b) {
return fabsl(a - b) <= eps ? 0 : (a > b) ? 1 : -1;
}
int getBit(long long num, int idx) { return ((num >> idx) & 1ll) == 1; }
int setBit1(int num, int idx) { return num | (1 << idx); }
long long setBit0(l... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 1000000 + 10;
int a[maxn];
map<int, int> mp, mp2;
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
int num = 0;
int res = 0;
for (int i = 1; i <= n; i++) {
int x = a[... | 7 |
#include <bits/stdc++.h>
const double pi = 3.1415926535897;
using namespace std;
int arr[200005];
int cnt[200005] = {};
int main() {
int n, maxEl = -1;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> arr[i];
cnt[arr[i]]++;
maxEl = max(maxEl, arr[i]);
}
int maxi = -1, el;
for (int i = 0; i <= maxE... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
scanf("%d%d", &a, &b);
int c = a * a + b * b, x1, y1, x2, y2;
bool flag = false;
for (int i = 1; i < a; i++) {
int x = a * a - i * i;
x = sqrt(x);
if ((x * x + i * i) != (a * a)) continue;
for (int j = 1; j < b; j++) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n, m, _, k;
long long a, b, c, c1, c2, c3, d;
long long f[N][2];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin >> n >> c1 >> c2 >> c3 >> d >> m;
c = (d << 1) + c1;
f[1][0] = c1 * m + c3;
f[1][1] =... | 15 |
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
template <typename T>
istream &operator>>(istream &in, vector<T> &v) {
for (auto &x : v) in >> x;
return in;
}
template <typename T>
ostream &operator<<(ostream &in, vector<T> &v) {
for (auto &x : v) in << x << " ";
return in;
}
class... | 11 |
#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
int n;
cin >> n;
cin.get();
getline(cin, s);
int p1 = 0, p2;
int ans = 0;
while ((p2 = s.find(' ', p1)) != -1) {
int tmp = 0;
for (int i = p1; i < p2; i++) {
if (s[i] >= 'A' && s[i] <= 'Z') {
tmp++;
}
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
unsigned long long n, r;
cin >> n >> r;
long double ans = 0;
long double a = 1 / tan(3.141592653589793 / (2 * n));
long double b = 1 / tan(3.141592653589793 / n);
ans = (r * r) / (a + b);
ans *= n;
cout << setprecision(15);
cout << ans << endl... | 13 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
template <class T>
bool ckmin(T& a, const T& b) {
return b < a ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T& a, const T& b) {
return a < b ? a = b, 1 : 0;
}
mt19937 rng(chrono::steady_clock::now().time_since_epo... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
int a[n];
for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
for (int k = 0; k < n; ++k) {
if (j != i && k != i && k != j && a[i] == a[j] + a[k]) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int a, e, i, o, u;
bool checki(char s) {
int r;
r = s - 'a';
if (r == a || r == e || r == i || r == o || r == u) {
return true;
} else {
return false;
}
}
int main() {
string s;
cin >> s;
if (s.size() < 3) {
cout << s << endl;
return 0;
}
... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long INF = 2e18 + 4;
int INFi = 2e9 + 2;
double eps = 1e-6;
long long mod = 1e9 + 7;
struct Node;
vector<Node> g;
struct Node {
string type;
int subTreeValue = 0;
int l, r;
bool canBeChanged = true;
Node() {}
Node(string _type) : type(_type), l(-1), r(-1) {... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int SZ = 222, MOD = 1000000007;
int dp[SZ][SZ], x[SZ], y[SZ], n;
bool ccw(int x1, int y1, int x2, int y2) {
return ((1ll * (x1) * (y2)-1ll * (y1) * (x2)) < 0);
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) scanf("%d%d", x + i, y + i);
long long a... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, rr = 0, temp = 0;
cin >> n;
vector<int> arr;
vector<int> res;
for (int i = 0; i < n; i++) {
cin >> k;
arr.push_back(k);
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < arr[i]; j++) {
cin >> k;
rr += k * 5;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const double PI = 3.141592653589793;
int tab[1005], l, n, i;
char t[1005];
int policz() {
int i, r = 0;
for (i = 0; i < n; i++)
if (tab[i] != i % 2) r++;
return r;
}
int main() {
scanf("%d %s", &n, &t);
for (i = 0; i < n; i++) tab[i... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
char S[maxn], T[maxn];
int Q, a, b, c, d;
int sumS[maxn], sumT[maxn];
int lastS[maxn], lastT[maxn];
int main() {
scanf("%s%s%d", S, T, &Q);
for (int i = 0; S[i]; ++i) {
sumS[i + 1] = sumS[i] + (S[i] == 'C' || S[i] == 'B');
lastS[i + 1] ... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k, n;
cin >> k;
while (k--) {
cin >> n;
string s, t;
cin >> s >> t;
map<char, int> cnt;
for (int i = 0; i < n; i++) {
cnt[s[i]]++;
cnt[t[i]]++;
}
bool candoit = true;
for (auto i = cnt.begin(); i != cnt.end(... | 8 |
#include <bits/stdc++.h>
using namespace std;
int can[2][3000];
char s[3000];
set<string> st;
vector<pair<string, int> > a;
int main() {
int i, j, b1, ans, minl;
string ss, s1, s2;
scanf("%s", s);
ss = s;
scanf("%s", s);
s1 = s;
scanf("%s", s);
s2 = s;
a.clear();
for (i = 0; i < ss.length(); i++) a.... | 12 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.