solution stringlengths 53 181k | difficulty int64 0 13 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
priority_queue<pair<int, int>, vector<pair<int, int> >,
greater<pair<int, int> > >
q;
vector<pair<int, int> > G[100009];
int d[100009];
bool f[100009];
int prevv[100009];
int n, m;
void printpath(int src) {
if (prevv[src] != -1) printpath(prevv[src]);
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int dx[] = {0, 0, -1, 1, 1, -1, -1, 1};
const int dy[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int N = 8e3;
int n, m;
int arr1[N], arr2[N];
int dp[N][N];
int solve(int i = 0, int j = 0) {
if (i == n || j == n) return 0;
int& ret = dp[i][j];
if (~ret) return ret;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
double P[2000000];
double DP[2000000];
double result[2000000];
int main() {
int N, K;
scanf("%d%d", &N, &K);
for (int i = 0; i < (N); ++i) scanf("%lf", &P[i]);
int K2 = 0;
for (int i = 0; i < (N); ++i)
if (P[i] > 1e-3) ++K2;
K = min(K, K2);
DP[0] = 1.0;
... | 8 |
#include <bits/stdc++.h>
const int N = 600 + 5;
int pre[N][N], n;
int L[N], R[N];
bool vis[N][N];
bool work(int l, int r) {
if (l > r) return true;
if (vis[l][r]) return pre[l][r] != -1;
vis[l][r] = true;
int tmp = r - l << 1 | 1;
if (tmp >= L[l] && tmp <= R[l] && work(l + 1, r)) {
pre[l][r] = -2;
}
f... | 7 |
#include <bits/stdc++.h>
template <typename T>
std::istream& operator>>(std::istream& input, std::vector<T>& v) {
for (T& a : v) input >> a;
return input;
}
void answer(bool v) {
constexpr const char* s[2] = {"No", "Yes"};
std::cout << s[v] << '\n';
}
void solve(const std::vector<size_t>& x, const std::vector<s... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long q, n, ans1, ans2;
int main() {
cin >> q;
while (q--) {
ans1 = 0;
ans2 = 0;
cin >> n;
vector<pair<long long, long long> > cnt(n + 1);
vector<long long> matcnt[n + 1];
for (int i = 1; i <= n; i++) cnt[i].first = 0, cnt[i].second = 0;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 210;
string s;
int n, cur = 0, res = 0;
int main() {
scanf("%d", &n);
while (cin >> s) {
cur = 0;
for (int i = (0), _b = (s.size()); i < _b; ++i)
if (s[i] >= 'A' && s[i] <= 'Z') cur++;
res = max(res, cur);
}
cout << res << endl;
ret... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, k;
cin >> n >> m >> k;
vector<int> arr(m + 1);
for (int i = 0; i <= m; i++) {
cin >> arr[i];
}
int count = 0;
int lcount;
int temp;
for (int i = 0; i < m; i++) {
temp = arr[i] ^ arr[m];
lcount = 0;
for (int j = 0; j <... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, a[100010], l[100010], r[100010], ans, f1[100010][2], f2[100010][2];
int main() {
cin >> n;
for (int i = 1; i <= n; ++i) {
char x;
cin >> x;
if (x == '0')
a[i] = 0;
else
a[i] = 1;
}
l[1] = 1;
f1[1][a[1]] = 1;
for (int i = 2; i <... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
if (N % 2 == 0) {
cout << -1;
return 0;
}
for (long long i = 0; i < N; i++) {
cout << i << " ";
}
cout << endl;
for (long long i = 0; i < N; i++) {
cout << (i + 1) % N << " ";
}
cout << endl;
for (long long... | 2 |
#include <bits/stdc++.h>
const int maxn = 100;
bool mark[maxn];
using namespace std;
int main() {
int n, x, y, z, ans = 0;
cin >> n;
cin >> x;
for (int i = 1; i <= x; i++) {
cin >> z;
mark[z] = true;
}
cin >> y;
for (int i = 1; i <= y; i++) {
cin >> z;
mark[z] = true;
}
for (int j = 1;... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, x1, y1, x2, y2;
scanf("%d %d %d %d %d %d", &n, &m, &x1, &y1, &x2, &y2);
int l1 = fabs(x1 - x2) + 1;
int l2 = fabs(y1 - y2) + 1;
if (l1 > l2) swap(l1, l2);
if (l1 == 1) {
if (l2 > 5)
printf("Second\n");
else
printf("Firs... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long POS(long long x) {
if (x > 0)
return x;
else
return 0;
}
struct ysh {
long double z, y, x;
ysh() {}
ysh(long double z, long double y, long double x) : z(z), y(y), x(x) {}
ysh operator+(const ysh &p) const { return ysh(z + p.z, y + p.y, x + p.x)... | 3 |
#include <bits/stdc++.h>
int main() {
int q;
scanf("%d", &q);
for (; q--;) {
int n, ans = 0;
scanf("%d", &n);
if (n % 2 == 1) {
n -= 9;
++ans;
if (n < 0) {
printf("%d\n", -1);
continue;
}
}
if (n % 4 == 2) {
n -= 6;
++ans;
if (n < 0) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, a, b, c, d;
cin >> n >> a >> b >> c >> d;
long long mi = min({a + c, c + d, d + b, b + a});
long long ma = max({a + c, c + d, d + b, b + a});
long long ce = max(n - (ma - mi), 0ll);
cout << ce * n << '\n';
return 0;
}
| 3 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target( \
"sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
using namespace std;
namespace t {
template <typename T>
inline const T gcd(T __m, T __n) {
while (__n != 0) {
T __t = __m % _... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
string s;
cin >> s;
int ok = 0;
int res = 0;
for (int j = 0; j < s.size() - 1; j++) {
if (s[j + 1] == '0' && s[j] == '1') {
while (s[j + 1] != '1' && j < s.size() - 1) {
ok++;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e8;
const int maxq = 4e5 + 7;
const int maxn = 3001;
vector<int> edge[maxn];
struct query {
int id, x, y, k;
} qs[maxq];
vector<query> Q[maxn];
int res[maxq];
int n, m, q;
bool cmp(const query &q1, const query &q2) { return q1.x < q2.x; }
int dfn[maxn], l... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1000 * 1000 + 5;
const long long mod = 1000 * 1000 * 1000 + 7;
int a[maxN * 2], dp[maxN * 2];
int ch[maxN * 2], p[maxN * 2];
int pat[2 * maxN], poi;
int star, su;
int n, mi;
inline void dfs(int v, int par = -1) {
pat[poi++] = v;
if (par > -1) su += v - ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int mod1 = 998244353, mod2 = 1e9 + 7;
struct Hash {
int fir, sec;
Hash(int _f, int _s) : fir(_f), sec(_s) {}
Hash() {}
Hash operator+(const int d) {
return Hash((fir + d) % mod1, (sec + d) % mod2);
}
Hash operator+(const Hash d) {
return Hash((fir ... | 11 |
#include <bits/stdc++.h>
char s1[105];
char s2[105];
char virus[105];
int fail[105];
int dp[105][105][105];
int seq[105][105][105][3];
int print[105][105][105];
int n, m, p;
int solve(int pos1, int pos2, int pos3) {
if (pos3 >= p) {
return -0x3f3f3f3f;
}
if (pos1 >= n || pos2 >= m) {
return 0;
}
if (s... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, temp, max, index;
cin >> n >> m;
int *cities = new int[m + 1];
int *candidates = new int[n + 1];
fill_n(candidates, n + 1, 0);
for (int i = 1; i <= m; ++i) {
max = 0;
index = 1;
for (int j = 1; j <= n; ++j) {
cin >> temp;... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
int N, Q;
int A[MAXN], P[MAXN];
int L[MAXN], R[MAXN];
int par(int D) {
if (P[D] == D) {
return D;
}
return par(P[D]);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> N >> Q;
for (int i = 1; i <= N; i... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e3 + 5;
int deg[MAXN], e[MAXN], x[MAXN], y[MAXN], d[MAXN];
int a[MAXN * 4], b[MAXN * 4], c[MAXN * 4], p;
vector<int> g[MAXN], r[MAXN];
bool vis[MAXN];
void dfs(int u) {
vis[u] = 1;
bool flag = 1;
for (const auto &v : g[u]) {
if (!vis[v]) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int n = s.length();
string f = s.substr(1, n - 1);
if (islower(s[0])) {
for (int i = 1; i < n; i++) {
if (isupper(s[i])) {
continue;
} else {
cout << s;
return 0;
}
}
cout << (c... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long n, ans;
long long ksm(long long base, int k) {
long long ret = 1;
while (k) {
if (k & 1) ret = ret * base;
base *= base;
k >>= 1;
}
return ret;
}
int main() {
cin >> n;
--n;
int m = log(n) / log(2);
for (int i = 0; i <= m; i++) {
an... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long ans;
void computeLPSArray(vector<long long>& pat, vector<long long>& lps) {
long long M = (long long)(pat).size();
long long len = 0;
lps[0] = 0;
long long i = 1;
while (i < M) {
if (pat[i] == pat[len]) {
len++;
lps[i] = len;
i++;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int R, C, N, K;
struct Node {
int x, y;
bool operator<(const Node b) const {
return y < b.y || (y == b.y && x < b.x);
}
} A[3005], B[3005];
int l[3005], r[3005], len;
int cnt[3005];
long long ANS;
long long tmp = 0;
vector<int> G[3005];
void DFS(int x, int k) {
... | 11 |
#include <bits/stdc++.h>
using namespace std;
namespace io {
const int L = (1 << 20) + 1;
char buf[L], *S, *T, c;
char getchar() {
if (__builtin_expect(S == T, 0)) {
T = (S = buf) + fread(buf, 1, L, stdin);
return (S == T ? EOF : *S++);
}
return *S++;
}
int inp() {
int x = 0, f = 1;
char ch;
for (ch... | 10 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool chkmax(T &a, T b) {
return a < b ? a = b, 1 : 0;
}
template <typename T>
bool chkmin(T &a, T b) {
return a > b ? a = b, 1 : 0;
}
const int maxn = 200000 + 100;
const int modd = 998244353;
const int inv2 = 499122177;
struct node {
int l, r;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int arr[100005];
int main() {
ios_base::sync_with_stdio(false);
int n, num, i, val = -1;
cin >> n;
for (i = 0; i < n; i++) {
cin >> num;
arr[num] = arr[num - 1] + 1;
if (val < arr[num]) val = arr[num];
}
cout << n - val << endl;
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
long long a[150500], l[150500], m = 1e7, mn = 1e7, ans = 0;
int main() {
int t;
cin >> t;
while (t--) {
ans = 0;
long long x, y;
cin >> x >> y;
l[0] = y % 10ll;
int i = 1;
while (1) {
l[i] = (y * (i + 1ll)) % 10ll;
if (l[i] == l[0])... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
while (n--)
{
string s;
cin >> s;
if (s[0] == ')' || s.size() % 2 != 0 || s[s.size() - 1] == '(')
cout << "NO" << endl;
else
cout << "YES" << endl;
}
} | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
vector<int> a(n), b(n);
vector<pair<int, int> > c;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) cin >> b[i];
for (int i = 0; i < n; i++) {
c.push_back(make_pair(a[i] - b[i], i));
}
sort(c.be... | 2 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, x, y;
cin >> n >> x >> y;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
sort(a.begin(), a.end());
if (x <= y) {
int cnt = 0;
for (int i = 0; i < n; i++) {
if (a[i] <= x)
cnt++;
else
break;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const string FILENAME = "input";
const int p = 1e9 + 7, MAXN = 2e5 + 1;
int n, r;
int color[MAXN];
vector<int> edge[MAXN];
void dfs(int i, int p = -1, int c = -1) {
int cnt = 0;
for (int j : edge[i]) {
if (j == p) continue;
while (cnt == color[i] || cnt == c) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int digit_sum(int x) {
int res = 0;
while (x > 0) {
res += x % 10;
x /= 10;
}
return res;
}
void print(string &s, const vector<bool> plus) {
int n = s.size();
for (int i = 0; i < int(n); ++i) {
cout << s[i] << (plus[i] && (i < n - 1) ? "+" : "");
}... | 8 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:640000000")
using namespace std;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int maxn = (int)2e5 + 10;
int a[44], b[44];
int t[maxn];
int main() {
int n;
cin >> n;
for (int i = 0; i < 3; i++) cin >> a[i];
sort(a, a + 3);
multiset<int> s... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, m, q;
const int maxn = 2e5 + 79, maxn2 = (1 << 18);
int nxt(int mask, int bit) {
if (mask < (1 << m) - 1 || !bit) return (mask << 1 | 1) & ((1 << m) - 1);
return ((mask << 1) & ((1 << m) - 1));
}
class node {
public:
int lazy, l, r;
vector<vector<int> > f;
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
int n;
long long dp[N], a[N], ans, k, l[N], r[N];
int main() {
scanf("%d%lld", &n, &k);
for (int i = 1; i <= n; ++i) scanf("%lld%lld%lld", l + i, r + i, a + i);
int flag = 0;
for (int i = n; i >= 1; --i) {
if (r[i] == l[i + 1])
dp[i] = ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[1010], b[1010];
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= m; i++) scanf("%d", &b[i]);
int p = 1, now = b[1];
for (int i = 1; i <= n; i++)
if (now >= a[i]) {
p++;
now = ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
long long bars[51];
long long i, leftpoints = 0, curpoints = 0, maxprice = 0, priceno, j;
for (i = 0; i < n; i++) {
cin >> bars[i];
}
long long prizescost[5];
for (i = 0; i < 5; i++) {
cin >> prizescost[i];
}
s... | 2 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int constexpr N = 1111;
void split(string& s, vector<string>& vc) {
string tmp_str = "";
for (auto& ch : s) {
if (ch == '.') {
vc.push_back(tmp_str);
tmp_str = "";
} else {
tmp_str += ch;
}
}
vc.push_back(tmp_str);... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e3 + 20;
const long long MOD = 1e9 + 7;
long long d[40][3][3];
int enu[] = {0, 0, 0, 1, 1, 0};
int l, r;
int cscop(int a, int b) {
if (a != 1)
return a + b;
else
return a;
}
long long solve() {
if (l == r) return (l == 0);
int clen = 0;
f... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int p[100010], a[100010];
int x[100010];
int nextt[100010], pre[100010];
bool cmp(int i, int j) { return p[i] < p[j]; }
set<pair<int, int> > st;
set<pair<int, int> >::iterator it;
const int inf = INT_MAX;
int dis(int i, int j) {
if (i == j) return inf;
int d =... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
int a[N][3];
bool visited[N];
set<int> cn[N], con[N];
int main() {
int tc;
scanf("%d", &tc);
while (tc--) {
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i) cn[i].clear(), visited[i] = 0, con[i].clear();
for (int i = 0; i < n -... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
const int maxk = 225;
long long s[maxk], c[maxk][maxk];
inline long long nml(long long a) { return ((a % M) + M) % M; }
void exgcd(long long a, long long& x, long long b, long long& y, long long& g) {
if (b) {
exgcd(b, y, a % b, x, g);
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n;
char mat[5005][5005];
bool used[5005];
void dfs(int v, int pre) {
used[v] = true;
for (int u = 0; u < (n); u++) {
if (mat[v][u] == '1') {
if (!used[u]) dfs(u, v);
if (mat[u][pre] == '1') {
printf("%d %d %d\n", pre + 1, v + 1, u + 1);
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n;
cin >> n;
long long a[n + 1];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
for (int i = 0; i < n; i++) {
if (a[i] + a[i + 1] > a[i + 2] and i + 3 <= n) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int inf = 0x3f3f3f3f;
const int N = 55 + 111;
const int M = 300;
struct edge {
int next, v;
int w;
} e[M];
int head[N], tot;
void init() {
memset(head, 0, sizeof(head));
tot = 1;
}
inline void add(int u, i... | 1 |
#include <bits/stdc++.h>
using namespace std;
char s[2000000], ss[30];
int last[30], Ind[30];
int Q[30000];
map<int, int> cnt;
int m;
int cmp(int u, int v) { return (last[u] > last[v]); }
int main() {
scanf("%s%d", s + 1, &m);
int Len = strlen(s + 1);
for (int i = 1; i <= m; i++) {
scanf("%s", ss + 1);
in... | 7 |
#include <bits/stdc++.h>
using namespace std;
bool Can(vector<int> v, int x) {
for (int i = 0; i < ((int)(v).size()); i++)
if (v[i] < i / x) return false;
return true;
}
int main() {
int n;
scanf("%d", &n);
vector<int> v(n);
for (int i = 0; i < n; i++) scanf("%d", v.begin() + i);
sort(v.begin(), v.end... | 3 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
double PI = acos(-1);
struct base {
double a, b;
base(double _a = 0.0, double _b = 0.0) : a(_a), b(_b) {}
const base operator+(c... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long int po(long long int x, long long int n) {
if (n == 0)
return 1;
else if (n % 2 == 0)
return po((x * x) % 1000000007, n / 2);
else
return (x * po((x * x) % 1000000007, (n - 1) / 2)) % 1000000007;
}
int main() {
ios_base::sync_with_stdio(false),... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, t;
int i, l;
cin >> s >> t;
l = s.length();
for (i = l - 1; i >= 0; i--)
if (s[i] < 'z') {
s[i]++;
break;
} else
s[i] = 'a';
if (s < t)
cout << s << endl;
else
cout << "No such string" << endl;
return ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char s[110];
cin >> s;
int l = strlen(s);
if (s[l - 1] != 'a' && s[l - 1] != 'e' && s[l - 1] != 'i' &&
s[l - 1] != 'o' && s[l - 1] != 'u' && s[l - 1] != 'n') {
cout << "NO" << endl;
return 0;
}
for (int i = 0; i < l - 1; i++) {
if ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, k = 0;
vector<int> ve[1234];
int primes[1234];
int ans;
bool isPrime(int x) {
for (int i = 2; i * i <= x; i++) {
if (x % i == 0) return false;
}
return true;
}
int bin_pow(int a, int n) {
if (n == 0) return 1;
if (n % 2 == 0)
return bin_pow(a, n / 2... | 3 |
#include <bits/stdc++.h>
using namespace std;
int a[1010];
int check(int x, int y, int xx, int yy) {
if (x > y) swap(x, y);
if (xx > yy) swap(xx, yy);
if (y <= xx) return 1;
if (yy <= x) return 1;
if (x >= xx && y <= yy) return 1;
if (x <= xx && y >= yy) return 1;
return 0;
}
int main() {
int n;
scanf... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,k;
cin >> n >> k;
string s = "";
while (s.size() < n)
{
for(int i = 0; i < k && s.size() < n; i++){
for(int j = i; j < k && s.size() < n; j++){
s += ('a' + j);
if(s.size() < n && j ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
const long double PI = 3.14159265358979323846264338327950288;
struct point {
long double real, imag;
point(long double real = 0, long double imag = 0) : real(real), imag(imag) {}
friend point operator*(const point& a, const point& b) {
return... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
int n;
cin >> n;
vector<int> v[n + 5];
memset(v, 0x00, sizeof(v));
for (int i = 0; i < n - 1; ++i) {
int x, y;
cin >> x >> y;
v[x - 1].push_back(y);
v[y - 1].push_back(x);
}
int ans = 0;
for (int i = 0... | 2 |
#include <bits/stdc++.h>
using namespace std;
int hed[500001], fa[500001], dep[500001], du[500001], nxt[1000001],
too[1000001], fx[500001], fs[500001], g[500001], f2[500001];
int tot, x, y, n, pd, cnt, pnt, T;
char s[500001];
void link(int x, int y) {
nxt[++tot] = hed[x];
too[tot] = y;
hed[x] = tot;
}
void dg... | 11 |
#include <bits/stdc++.h>
using namespace std;
long a[200000], b[200000], qq;
vector<string> v;
string st, zr;
bool pm(string st) {
if (st.size() < 4) return false;
zr = "lios";
for (int j = 1; j <= 4; j++)
if (st[st.size() - j] != zr[4 - j]) return false;
return true;
}
bool pz(string st) {
if (st.size() ... | 4 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
int n, m;
int a[(1 << 14) + 5][2];
int fa[(1 << 15) + 5];
int ans;
inline int fifa(int x) { return fa[x] == x ? x : fa[x] = fifa(fa[x]); }
inline void join(int x, int y) {
int px = fifa(x), py = fifa(y);
if (px == py) return;
fa[px] = py;... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1e5;
int n;
bool flag[MaxN + 5];
int tot, prime[MaxN + 5];
map<int, int> SG, num;
int Get_SG(int x) {
if (x == 0) return 0;
if (SG.count(x)) return SG[x];
map<int, int> vis;
int temp = x, cnt = 0;
while (temp) temp /= 2, cnt++;
for (int i = 1; i... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int sz = 2e5 + 5;
pair<long long, long long> pv[sz];
long long cross(pair<long long, long long> a, pair<long long, long long> b,
pair<long long, long long> c) {
return (b.second - a.second) * (c.first - a.first) -
(b.first - a.first) * (c.se... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int dr8[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dc8[] = {1, -1, 0, 0, -1, 1, -1, 1};
int dr4[] = {0, 1, -1, 0};
int dc4[] = {1, 0, 0, -1};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int n, x;
cin >> n... | 5 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int inf = 1e5 + 5;
const int MAXM = 1e5 + 5;
const int MAXN = 2e5 + 4;
long long s;
bool cal(long long x) {
long long xx = x, cnt = 0;
while (xx) {
cnt += (xx % 10);
xx /= 10;
}
return (x - cnt) >= s;
}
int main() {
long lo... | 4 |
#include <bits/stdc++.h>
using namespace std;
int num[155][155];
int main() {
num[0][0] = 1, num[1][1] = 1;
for (int i = 2; i <= 150; i++) {
for (int j = 0; j <= i - 1; j++) num[i][j + 1] = num[i - 1][j];
for (int j = 0; j < 2; j++) {
int ns = 1;
if (j & 1) ns = -1;
bool flag = 1;
fo... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000010, M = N, mod = 1e9 + 7, INF = 0x3f3f3f3f;
const double eps = 1e-6;
int k;
int e[M], ne[M], w[M], h[N], idx;
int se[N];
long long ans1, ans2;
void add(int a, int b, int c) {
e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx++;
}
void dfs1(int u, int f... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char bal[1000000];
int i;
scanf("%s", bal);
int ln = strlen(bal);
i = bal[ln - 2] - '0';
i = i * 10;
i = i + bal[ln - 1] - 48;
i = i % 4;
if (i == 0)
printf("4\n");
else
printf("0\n");
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
const int INF = 1E9;
int sum[maxn], a[maxn], b[maxn];
int n;
int Find(int s, int x) {
for (int i = s; i <= n; i++)
if (b[i] < x) return i;
return -1;
}
int main() {
int i, j;
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%d %... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m = 0, k, l, g[20][20], h[310],
ma[8][2] = {{1, 2}, {2, 1}, {-1, 2}, {-2, 1},
{1, -2}, {2, -1}, {-1, -2}, {-2, -1}},
d[310][310], dc[310][310], dp[310], c[310];
void cone(int x, int y) {
d[x][y] = d[y][x] = 1;
dc[x][y] = dc[y][... | 7 |
#include <bits/stdc++.h>
using namespace std;
vector<int> v[200005];
bool visited[200005];
int m, n, x, y;
void dfs(int id) {
for (int i = 0; i < v[id].size(); ++i) {
if (visited[v[id][i]]) continue;
cout << id << " " << v[id][i] << "\n";
visited[v[id][i]] = 1;
dfs(v[id][i]);
}
}
int main() {
ios:... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n;
set<int> sett;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 0; i < N; ++i) sett.insert(i);
for (int i = 1; i <= n; ++i) {
int a;
cin >> a;
if ((i == 1 && a != 0) || (*sett.be... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int a[N], s[N], vis[N];
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int main() {
int n, i, j, ss;
long long ans = 1;
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%d", &a[i]);
s[a[i]]++;
}
for (i = 1;... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long N, L;
cin >> N >> L;
vector<long long> Hash(N + 7, 0), E(N + 2);
E[0] = 0;
for (int i = 1; i <= N; i++) cin >> E[i];
E[N + 1] = L;
int i = N + 1;
while (i > 0) {
Hash[i] = E[i] - E[i - 1] + Hash[i + 2];
i--;
}
vector<long l... | 3 |
#include <bits/stdc++.h>
using namespace std;
long a[405], b[405], n, test;
bool ok;
int main() {
cin >> test;
for (long g = 1; g <= test; g++) {
cin >> n;
ok = true;
for (long i = 1; i <= 4 * n; i++) cin >> a[i];
sort(a + 1, a + 1 + 4 * n);
for (long i = 1; i <= 2 * n; i++)
if (a[2 * i - ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> nums(n * n);
iota(nums.begin(), nums.end(), 1);
long long ans = 0;
vector<vector<int>> res(n, vector<int>(n));
int l = 0, r = n * n - 1;
for (int i = 0; i < n; i++... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, k = 0, c = 0;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) {
if (i % 2 == 0) {
if (a[i] % 2 != 0) k++;
}
if (i % 2 != 0) {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 5;
int n, m, ans, cnt, B[N], in[N], out[N], dp[N];
vector<int> G[N], W[N];
vector<pair<int, int> > V[N], VV[N];
int dep[N], f[N][20];
void dfs(int x, int fa) {
f[x][0] = fa;
dep[x] = dep[fa] + 1;
in[x] = ++cnt;
for (int i = 0; i < G[x].size(); i+... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int oo = 0x7fffffff;
const long long OO = 0x7fffffffffffffff;
int main() {
ios_base::sync_with_stdio(false);
int N;
long double m, mo;
cin >> N >> m;
mo = m;
vector<int> A(N, 0), B(N, 0);
for (int i = 0; i < N; i++) {
cin >> A[i];
if (A[i] == 1) ... | 3 |
#include <bits/stdc++.h>
#pragma GCC optimize(3)
#pragma GCC optimize(2)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
struct block {
vector<pair<long long, int>> mp;
long long lz;
};
int n;
block blk[711];
int bid[711 * 711];
long long a[711 * 711];
int block_size;
int que... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long int n, k, v, m, ans, sum, sum1, l, r, i, j, mx,
mn = 1222999000, c, z, x, y, a[111111], d[111111], t[111111];
vector<int> b[111111];
string s, sos, ss;
char ch[111111], chel;
bool used[111111];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >... | 2 |
#include <bits/stdc++.h>
int main() {
int n, k = 0;
char s1[200000], s2[200000];
scanf("%s%s", s1, s2);
n = strlen(s1);
for (int i = 0; i < n; i++) {
if (s1[i] != s2[i]) {
k++;
}
}
if (k % 2 != 0) {
printf("impossible");
n = 0;
}
int s = 0;
for (int i = 0; i < n; i++) {
if ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, s, d;
cin >> n >> k;
getchar();
char a[11111];
cin.getline(a, sizeof(a));
int len = strlen(a);
for (int i = 0; i < len; i++) {
if (a[i] == 'G') s = i;
if (a[i] == 'T') d = i;
}
if (s < d) {
while (s < d) {
if (a[s +... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
bool Max(T1 &a, T2 b) {
return a < b ? a = b, 1 : 0;
}
template <typename T1, typename T2>
bool Min(T1 &a, T2 b) {
return a > b ? a = b, 1 : 0;
}
template <int MOD>
struct ModInt {
unsigned x;
ModInt() : x(0) {}
ModInt(signed si... | 8 |
#include <bits/stdc++.h>
using namespace std;
int cnt[1009];
int main() {
int n;
cin >> n;
bool flg2 = false;
for (int i = 1; i < n; i++) {
int a, b;
cin >> a >> b;
cnt[a]++;
if (b != n) flg2 = true;
}
if (flg2) {
cout << "NO\n";
return 0;
}
vector<int> vc;
vector<pair<int, int... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, d;
long long int pos, m, l, fim, mod;
bool foi[1000010];
int main() {
memset(foi, false, sizeof(foi));
scanf("%d %d %lld %lld", &n, &d, &m, &l);
pos = d;
fim = (n - 1) * m + l + 1;
while (pos < fim) {
mod = pos % m;
if (mod > l) break;
if (foi[m... | 4 |
#include <bits/stdc++.h>
using namespace std;
ofstream fo("test.out");
ifstream fi("test.inp");
int a[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 51};
int n, m;
int main() {
cin >> n >> m;
int i = 0;
while (a[i] != n) {
i++;
}
if (a[i + 1] == m)
cout << "YES";
else
cout << "NO";... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6;
int a[N + 2], b[N + 2], ds[N + 2], tg[N + 2];
vector<int> adj[N + 2];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, k, d;
cin >> n >> k >> d;
for (int i = 1; i <= n; i++) ds[i] = 1e9;
queue<int> q;
for (int i = 1; i <= k; i++... | 6 |
#include <bits/stdc++.h>
const int MAX_VAL = 1e9;
struct Castle;
struct Segment {
int l;
int r;
Castle* parent;
};
bool operator<(const Segment& a, const Segment& b) {
return a.l < b.l || (a.l == b.l && a.r < b.r) ||
(a.l == b.l && a.r == b.r && a.parent < b.parent);
}
struct Castle {
Segment segs[4]... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 3e3 + 7;
struct edge {
int u, v, l, r;
edge() {}
edge(int _u, int _v, int _l, int _r) {
u = _u;
v = _v;
l = _l;
r = _r;
}
} e[NMAX];
int p[NMAX];
int _find(int x) { return (x == p[x]) ? x : p[x] = _find(p[x]); }
void join(int x, int ... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long poww(long long a, long long b, long long md) {
return (!b ? 1
: (b & 1 ? a * poww(a * a % md, b / 2, md) % md
: poww(a * a % md, b / 2, md) % md));
}
const long long MAXN = 1e4 + 10;
const long long INF = 8e18;
const long long ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int q = 1, i, j;
while (q--) {
int n, r;
cin >> r >> n;
vector<int> t(n + 1), x(n + 1), y(n + 1);
t[0] = 0, x[0] = 1, y[0] = 1;
for (i = 1; i < (n + 1); i++) {
cin >> t[i] >> x[i] >> y[i];
}
vector<int> dp(n + 1, INT_MIN), ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1.01e9;
const long long infll = (long long)1.01e18;
const long double eps = 1e-9;
const long double pi = acos((long double)-1);
mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x) { return mrand() % x; }
void precalc() ... | 8 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops", "omit-frame-pointer", "inline")
#pragma GCC option("arch=native", "tune=native", "no-zero-upper")
#pragma GCC target("avx2")
using namespace std;
template <typename T>
void maxtt(T &t1, T t2) {
t1 = max(t1, t2);
}
template <typename T>
void mintt(... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, m, x;
long long dp[3300000][4], fac[3300000], inv[3300000], inc[3300000];
const int mod = 1e9 + 7, inv3 = 333333336;
void init() {
fac[0] = inv[0] = inv[1] = inc[0] = 1;
for (int i = 1; i <= 3000000; i++) fac[i] = fac[i - 1] * i % mod;
for (int i = 2; i <= 3000... | 8 |
#include <bits/stdc++.h>
using namespace std;
struct po {
int x, y;
} p[10];
bool cmp(po a, po b) {
if (a.x == b.x) {
return a.y < b.y;
}
return a.x < b.x;
}
int n;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d%d", &p[i].x, &p[i].y);
sort(p, p + n, cmp);
if (n == 1) {
print... | 1 |
#include <bits/stdc++.h>
using namespace std;
double quick_pow(double a, int b) {
double ans = 1, base = a;
while (b != 0) {
if (b & 1 != 0) ans *= base;
base *= base;
b >>= 1;
}
return ans;
}
int main() {
int m, n;
scanf("%d%d", &m, &n);
double ans = 0;
for (double i = 1; i <= m; i++) {
... | 4 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.