solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
inline long long in() {
long long k = 0;
char ch = getchar();
while (ch < '-') ch = getchar();
while (ch > '-') k = k * 10 + ch - '0', ch = getchar();
return k;
}
const int N = 4e5 + 5;
long long a[N], t;
int n, m;
void init() {
n = in(), m = in(), t = in();
for (int i = 1; i <= n... | 13 |
#include <bits/stdc++.h>
using namespace std;
void align(int &x, int &y) {
if (y > x) swap(x, y);
}
void print(int x, int y, char c) {
for (int i = 0; i < y; i++) {
for (int j = 0; j < x; j++) printf("%c", c);
printf("\n");
}
}
void printr(int x1, int x2, int y, char c1, char c2) {
for (int i = 0; i < y... | 9 |
#include <bits/stdc++.h>
#pragma warning(disable : 4786)
using namespace std;
int MX(int a, int b) { return (a > b) ? a : b; }
int MN(int a, int b) { return (a < b) ? a : b; }
int arr[100005], cum[100005];
int main() {
int n, t, i, mid, mx, len, l, r;
while (scanf("%d%d", &n, &t) != EOF) {
cum[0] = 0;
for (... | 6 |
#include <bits/stdc++.h>
using namespace std;
struct Segment {
int st, ed;
Segment(int st, int ed) : st(st), ed(ed) {}
};
bool operator<(const Segment &A, const Segment &B) {
if (A.ed - A.st != B.ed - B.st) {
return A.ed - A.st > B.ed - B.st;
}
return A.st > B.st;
}
map<int, int> C;
int n, q;
inline int l... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char s[9][9];
int w = 0, b = 0;
for (int i = 0; i < 8; i++)
for (int j = 0; j < 8; j++) cin >> s[i][j];
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
if (s[i][j] == 'Q')
w += 9;
else if (s[i][j] == 'R')
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 7;
const int INF = 1e9 + 7;
vector<int> G[MAXN], rG[MAXN];
int d[MAXN];
int p[MAXN];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.precision(6);
cout << fixed;
int n, m;
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int u, v... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char s[10], s1[10], s2[10];
scanf("%s", s);
scanf("%s", s1);
scanf("%s", s2);
vector<int> v, v1, v2;
for (int i = 0; i < 5; i++) {
v.push_back(100);
v1.push_back(100);
v2.push_back(100);
}
if (s[1] == 'm') v.push_back((char)s[0] - 48... | 4 |
#include <bits/stdc++.h>
using namespace std;
int f(string a, string b) {
for (int i = 0; i < a.size(); i++) {
if (a.find(b[i]) != std::string::npos) return 1;
}
return 0;
}
int main() {
int n;
cin >> n;
string f1;
for (int j = 0; j < n; j++) {
string a, b;
cin >> a >> b;
if (f(a, b))
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, a[100005];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
sort(a + 1, a + n + 1);
for (int i = 1; i < n; ++i)
if (a[i] != a[i + 1] && 2 * a[i] > a[i + 1]) {
printf("YES\n");
return 0;
}
printf("NO\n");
r... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long f[1010];
int main() {
long long n, m, i, j, a[1010], b[1010], x;
scanf("%lld", &n);
scanf("%lld", &m);
while (m--) {
scanf("%lld", &x);
for (i = x; i <= n; i++) {
if (f[i] == 0) {
a[i] = x;
f[i] = 1;
}
}
}
for (i... | 1 |
#include <bits/stdc++.h>
using namespace std;
int home[100000 + 10];
int away[100000 + 10];
int color[100000 + 10];
int ans[100000 + 10];
int n;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d %d", &home[i], &away[i]);
color[home[i]]++;
}
for (int i = 0; i < n; i++) {
printf("%... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int s = 0;
int twos = 0, threes = 0;
while (n > 1) {
if (n - 2 != 1) {
twos++;
n -= 2;
} else {
threes++;
n = -3;
}
s++;
}
cout << s << endl;
for (int i = 0; i < twos; i++) cout << 2 << " ... | 0 |
#include <bits/stdc++.h>
using namespace std;
inline int Read() {
int x = 0, f = 1, 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 = 25;
bool v[MAXN], gra[MAXN][MAXN];
vector<int> adj[MAXN];
int n... | 20 |
#include <bits/stdc++.h>
using namespace std;
int precalc = 0;
vector<int> calc_manacher(string str) {
string nou = "#";
for (auto c : str) {
nou.push_back(c);
nou.push_back('#');
}
str = nou;
vector<int> dp(str.size());
dp[0] = 1;
int bestPoz = 0, dreapta = 0;
for (int i = 1; i < (int)str.size(... | 7 |
#include <bits/stdc++.h>
using namespace std;
int x[1000500];
int y[1000500];
long long c[1000500];
map<long long, int> num;
int n, m, k;
long long z;
long long p2[1000500];
int e;
int cnt[1000500];
map<pair<int, int>, int> parent, sz;
set<int> s[1000500];
void add(int k, int v) {
if (s[k].find(v) != s[k].end()) retu... | 14 |
#include <bits/stdc++.h>
using namespace std;
int pow2[10];
bool ada[512][512];
int ar[512];
vector<pair<int, int>> vv[512];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
for (int i = 0; i < 10; i++) pow2[i] = (1 << i);
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
i... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 5;
const int inf = 1e9;
vector<int> Eid[N];
int n, m, cnt, S, T, in[N], out[N], cur[N], d[N];
struct Edge {
int c, v;
} E[N];
void AddEdge(int x, int y, int c, int cc) {
E[cnt].v = y, E[cnt].c = c;
Eid[x].push_back(cnt++);
E[cnt].v = x, E[cnt].c ... | 22 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long n, h;
cin >> h >> n;
long long a[n], mn = h, val = h, tme = -1;
for (int i = 0; i < n; i++) {
cin >> a[i];
val += a[i];
if (val < mn) {
mn = val;
tme = i;
if (mn < 1) ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int testcase = 1;
const int MAXN = 1e6 + 10;
const int MOD = 1e9 + 7;
int n, m, k, a, b, c, d;
int tmp, tmp1, tmp2, tmp3;
int mp[200][200];
vector<vector<int> > ans;
void init() {}
void up(int i, int j) { mp[i][j] = (mp[i][j] + 1) % 2; }
void move(int i, int j, int d1, int ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, s, e, mi, q = 0, ind = -1;
scanf("%d %d", &n, &m);
int a[n], b[m];
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
sort(a, a + n);
for (int i = 0; i < m; i++) {
scanf("%d", &b[i]);
s = 0;
e = n - 1;
mi;
ind = ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int re[100001];
int n;
int m;
int pri[100001];
char opr;
int pos;
int p[400];
int temp;
int data;
int k;
int main(void) {
cin >> n >> m;
memset(re, 0, 100001 * sizeof(int));
memset(pri, 0, 1000 * sizeof(int));
int i = 0;
while (i < m) {
cin >> opr >> data;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
char ar[2100][2100], ch;
int n, m, i, j;
void rec(int x, int y);
int main() {
for (i = 0; i < 2100; i++)
for (j = 0; j < 2100; j++) ar[i][j] = '*';
cin >> n >> m;
scanf("%c", &ch);
for (i = 2; i < n + 2; i++) {
for (j = 2; j < m + 2; j++) scanf("%c", &ar[i][... | 16 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void dbs(string str, T t) {
cout << str << " : " << t << "\n";
}
template <class T, class... second>
void dbs(string str, T t, second... s) {
long long idx = str.find(',');
cout << str.substr(0, idx) << " : " << t << ", ";
dbs(str.substr(idx + 1),... | 8 |
#include <bits/stdc++.h>
int main() {
int n, i;
int a[2] = {0};
char s[51];
scanf("%d", &n);
scanf("%s", s);
for (i = 0; i < n / 2; i++) {
if (s[i] != '4' && s[i] != '7') {
puts("NO");
return 0;
}
if (s[n - i - 1] != '4' && s[n - i - 1] != '7') {
puts("NO");
return 0;
... | 0 |
#include <bits/stdc++.h>
template <typename T>
inline void read(T &x) {
x = 0;
char c = getchar();
bool flag = false;
while (!isdigit(c)) {
if (c == '-') flag = true;
c = getchar();
}
while (isdigit(c)) x = x * 10 + (c ^ 48), c = getchar();
if (flag) x = -x;
}
using namespace std;
const int P = 1e... | 23 |
#include <bits/stdc++.h>
using namespace std;
int n, m, a[1000005], lm, ans[1000005], q[1000005];
struct node {
int sum;
vector<int> p;
friend bool operator<(const node a, const node b) { return a.sum < b.sum; }
} s[1000005];
int vis[1000005], cnt;
void dfs(int r) {
vis[r] = 1;
cnt++;
s[lm].p.push_back(r);
... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
const int oo = 998244353;
const long long inv100 = 828542813;
long long power(long long a, int b) {
if (a == 0 || a == 1) return a;
long long res = 1;
for (; b; b >>= 1, a = a * a % oo)
if (b & 1) res = res * a % oo;
return res;
}
long long... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const long long mod = 998244353, inv2 = (mod + 1) / 2;
long long fac[maxn], inv[maxn];
int n, k, h[maxn];
void up(long long &a, long long b) {
a += b;
a %= mod;
}
long long power(long long x, long long y) {
long long res = 1;
while (y) {
... | 14 |
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <algorithm>
#define PB push_back
#define X first
#define Y second
using namespace std;
typedef pair < int, int > pii;
typedef vector < int > vi;
typedef pair < int, vi > piv;
const int N = 1e3 + 550;
vector < pii > v[N][N];
vect... | 21 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
if (n <= 3) {
cout << n << '\n';
continue;
}
long long pos = (n + 2) / 3;
long long a, b, c;
... | 14 |
#include <bits/stdc++.h>
using namespace std;
string str, ans = "";
int n, key;
map<char, int> mp;
struct node {
int num;
char nam;
} a[26];
bool cmp(node a, node b) { return a.num < b.num; }
int main() {
cin >> str >> n;
int len = str.size();
for (int i = 0; i < len; i++) {
mp[str[i]]++;
a[str[i] - '... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long b, g, r, ans = 0, a[4] = {0}, s = 0;
cin >> r >> g >> b;
a[0] = r % 3;
a[1] = g % 3;
a[2] = b % 3;
ans = (r / 3) + (g / 3) + (b / 3) + (min(a[0], min(a[1], a[2])));
for (long long i = 0; i < 3; i++)
if (a[i] == 2) s++;
if (s == 2 &... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long int solve(int a, int b, int x, int y, int n) {
int mini = min(n, a - x);
n -= mini;
a -= mini;
mini = min(b - y, n);
b -= mini;
return a * (long long)b;
}
int main() {
int t;
cin >> t;
while (t--) {
int n;
int a, b, x, y;
cin >> a >> ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int N = 2e5 + 20;
int n;
string a, b;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
cin >> a >> b;
std::vector<int> v;
int t = 0;
for (int... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 2 * (1e9) + 10;
const long long infl = 2 * (1e18) + 10;
const long long MOD = 998244353;
const long NMAX = 300005;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
struct segment {
long long states[2][2];
segment(int l = 0, int r = 0, long... | 19 |
#include <bits/stdc++.h>
using std::endl;
using std::max;
using std::upper_bound;
using std::vector;
const int MAX_SEQ_SIZE = 100 * 1000;
const int MAX_NUM = 100 * 1000;
const int MAX_S = 300 * 1000;
const int MIN_E = 1000;
const int MAX_N = MAX_SEQ_SIZE;
const int MAX_M = MAX_SEQ_SIZE;
static int solve(const int nn, c... | 15 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
bool rot;
vector<int> col;
vector<int> out[100000];
inline int f(int x) {
int i = x % m;
int j = x / m;
return i * n + j;
}
void print() {
printf("YES\n");
if (rot) {
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) printf("%d ", f(out... | 14 |
#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")
#pragma GCC optimize("03")
#pragma GCC target("sse4")
using namespace std;
int n;
bool is_scc(vector<int> degrees) {
int s... | 24 |
#include <bits/stdc++.h>
using namespace std;
int a[200005];
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n;
cin >> n;
long long cnt = 0;
for (int i = 0; i < n; i++) cin >> a[i];
int x, f;
cin >> x >> f;
for (int i = 0; i < n; i++) {
a[i] -= x;
if (a[i] > 0) {
int... | 6 |
#include <bits/stdc++.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-function"
using namespace std;
namespace {
namespace shik {
template <class T>
void _R(T &x) {
cin >> x;
}
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%" SCNd64, &x); }
void _R(doub... | 14 |
#include<bits/stdc++.h>
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);std::cout.tie(nullptr);
int n, m;
std::cin >> n >> m;
std::vector<int> k(n), al(n), ar(n), bl(n), br(n);
for(int i = 0; i < n; ++i)
{
std::cin >> k[i];
std::cin >> al[i] >> bl[i];
... | 17 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-7;
const string nl = "\n";
template <typename T>
string convtos(T a) {
stringstream ss;
ss << a;
return ss.str();
}
template <typename T>
T convtot(string s) {
T x;
stringstream ss;
ss << s;
ss >> x;
return x;
}
void printtime() { cerr ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const long long MOD = 1000000007;
const long long INF = 0x3f3f3f3f;
int val[111][111];
int n, m, k;
vector<pair<int, int> > pos;
int ddist[111][111], way[10][10], dist[211][10];
int used[111][111];
pair<int, int> pre[211][1 << 8];
int dp[211][1 << 8... | 17 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> v1, v2;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long n, m;
cin >> n >> m;
m--;
for (long long i = n - 1; i > 0; i--) {
if (m & (1LL << (i - 1)))
v2.push_back(n - i);
else
v1.push_ba... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, dx, dy;
const int maxn = 1e6 + 7;
long long p[maxn], q[maxn];
int wz[maxn];
void exgcd(long long a, long long b, long long& x, long long& y) {
if (!b) {
x = 1;
y = 0;
} else {
exgcd(b, a % b, y, x);
y -= x * (a / b);
}
}
int main() {
... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 222222;
int n, a[N];
vector<int> v, s;
void solver(int x, int y) {
while (y - x >= 3) {
s.push_back(y - 2);
s.push_back(y - 1);
y -= 2;
}
s.push_back(x);
}
void solvel(int x, int y) {
while (y - x >= 3) {
s.push_back(x);
s.push_back... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
void sync_stdio() {
cin.tie(NULL);
ios_base::sync_with_stdio(false);
}
struct Sync_stdio {
Sync_stdio() {
cin.tie(NULL);
ios_base::sync_with_stdio(false);
}
} _sync_stdio;
struct FAIL {
FAIL() {
cout << "CHANGE!!!"
... | 1 |
#include <bits/stdc++.h>
int main() {
int n, i, x[103], sum = 0, k = 0;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &x[i]);
sum = sum + x[i];
}
for (i = 0; i < n; i++) {
if ((sum - x[i]) % 2 == 0) k++;
}
printf("%d\n", k);
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int get() {
int f = 0, v = 0;
char ch;
while (!isdigit(ch = getchar()))
if (ch == '-') break;
if (ch == '-')
f = 1;
else
v = ch - '0';
while (isdigit(ch = getchar())) v = v * 10 + ch - '0';
if (f)
return -v;
else
return v;
}
const int max... | 22 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 210, maxn2 = maxn * maxn * 2, mod = 1e9 + 7, inf = 1e9 + 10;
string s[maxn];
template <typename T, int N, int M, T inf>
struct Flow {
int tp[N], nxt[2 * M], to[2 * M];
T c[2 * M];
Flow() { memset(tp, -1, sizeof tp); }
int safar = 0;
void add_edge(... | 20 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
using namespace std;
const int MAXN = 102, K = 900;
int n, m, k, u, v, x, y, t, a, b;
int A[MAXN];
short F1[MAXN][MAXN][2 * MAXN];
short F2[MAXN][MAXN][2 * MAXN];
short F3[MAXN][MAXN][2 * MAXN];
double dp[2][MAXN][MAXN];
int C(int x) { return x * (x + ... | 10 |
#include <bits/stdc++.h>
int main() {
int n, m, i, j, state, p;
int **s;
scanf("%d", &n);
scanf("%d", &m);
s = new int *[n];
for (i = 0; i < n; i++) {
s[i] = new int[m];
for (j = 0; j < m; j++) {
scanf("%d", &s[i][j]);
}
}
p = 0;
for (i = 0; i < n; i++) {
state = 0;
j = 0;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MX = 1e5 + 5;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
struct Ans {
bool ok;
vector<int> s;
bool operator<(const Ans &P) const {
if (ok == P.ok) return s.size() < P.s.size();
return ok > P.ok;
}
};
int n, m;
struct Edge {
int v, nxt, ... | 14 |
#include <bits/stdc++.h>
using namespace std;
inline long long int power(long long int a, long long int b) {
long long int x = 1;
while (b) {
if (b & 1) x *= a;
a *= a;
b >>= 1;
}
return x;
}
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cout << name << " : " << arg1 << "\n";
... | 9 |
#include <bits/stdc++.h>
int main() {
char first_number[102], last_number[102], gcd[102];
scanf("%s %s", first_number, last_number);
if (strcmp(first_number, last_number) == 0) {
strcpy(gcd, first_number);
} else {
strcpy(gcd, "1");
}
printf("%s\n", gcd);
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2010, INF = 1e8;
int n, s, a[MAXN], b[MAXN], tot;
int f[MAXN], g[MAXN], state[MAXN];
int cost[MAXN][MAXN];
vector<int> pos[MAXN];
inline long long normaldist(int i, int j) {
if (j >= i)
return abs(i - j);
else
return n - abs(i - j);
}
inline lon... | 18 |
#include <bits/stdc++.h>
using namespace std;
double dist(double a, double b) { return sqrtl(a * a + b * b); }
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
string s;
string s1, s2;
int main() {
int len, res = 1, lpal = 0, rpal = 0, j = 1, flag = 0;
cin >> s;
len = s.length();
for (i... | 22 |
#include <bits/stdc++.h>
using namespace std;
int T, n, dp[3003][3003], s1[3003][27], s2[3003][27];
char s[200006], t[200006];
int main() {
scanf("%d", &T);
while (T--) {
scanf("%d%s%s", &n, s + 1, t + 1);
for (int i = 1; i <= n; i++) {
for (int j = 0; j < 26; j++)
s1[i][j] = s1[i - 1][j], s2[... | 18 |
#include <bits/stdc++.h>
using namespace std;
void s_y_c() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
template <typename... T>
void read(T&... args) {
((cin >> args), ...);
}
template <typename... T>
void write(T&&... args) {
((cout << args << " "), ...);
}
void solve() {
long long n;
cin ... | 0 |
#include <bits/stdc++.h>
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
using namespace std;
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int INFi... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
while (t--)
{
// getchar();
// string s;
// getline(cin, s);
int a, b, c, d, e, f;
cin >> a >> b >> c >> d >> e >> f;
int ans = abs(a - c) + abs(b - d);
if ((a == c && c == e && ((b < f && f < d) || (d < f && f < b)))
||... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long N, K, normal, ans, idx;
long long a[200005];
long long fact[200005];
long long finv[200005];
long long cub[200005];
long long tnom[200005];
long long dp[200005];
unordered_map<long long, long long> mp;
bool lucky(long long x) {
while (x) {
if (x % 10 != 4 &&... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int INF = INT_MAX;
const long long INFL = LLONG_MAX;
const long double pi = acos(-1);
int N, M;
vector<int> pdivisors[100100];
int isOn[100100];
multiset<int> A[100100];
int main() {
ios_base::sync_with_stdio(0);
cout.precision(15);
cout << fixed;
cout.tie(0);... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MOD7 = 1e9 + 7;
const int MOD9 = 1e9 + 9;
long long int gcd(long long int a, long long int b) {
return b == 0 ? a : gcd(b, a % b);
}
int toint(const string &s) {
stringstream ss;
ss << s;
int x;
ss >> x;
return x;
}
long long int mpow(long long int a, ... | 12 |
#include <bits/stdc++.h>
int n, m, f[1005];
bool ok = true;
int find(int x) {
if (f[x] == x) return x;
return f[x] = find(f[x]);
}
int main() {
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++) f[i] = i;
if (m != n - 1) ok = false;
for (int i = 0; i < m; i++) {
int u, v;
scanf("%d %d", &u, &v);
... | 5 |
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false)
#define ffor(i,n) for(auto i=(n)-(n);i<(n);i++)
#define printv(v) do{ffor(o,v.size()) printf("%4lld ",1ll*v[o]); printf("\n");}while(0)
using namespace std;
typedef long long ll;
int n;
int tc=1; // -1: invalid, 0: cin, 1: 1
int solve();
int main... | 14 |
#include <bits/stdc++.h>
using namespace std;
int n, m, mp[1010][1010], dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
vector<int> ans;
bool vis[1010][1010];
int bfs(int x, int y) {
queue<pair<int, int> > q;
q.push(make_pair(x, y)), vis[x][y] = true;
int siz = 1;
while (!q.empty()) {
pair<int, int> t = q.fro... | 6 |
#include <bits/stdc++.h>
const long long mod = 1000000007;
const long long AM = 2e5 + 5;
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
;
long long t;
cin >> t;
while (t--) {
long long n, k;
cin >> n >> k;
long long i = 1, ans = 0;
while (i < k && i < n) i... | 3 |
#include <bits/stdc++.h>
using namespace std;
struct Node {
int v, m;
int id;
bool operator<(const Node &x) const {
if (m != x.m) return m < x.m;
return v < x.v;
}
} q[100005];
int n, k, h;
bool ok(double times) {
int i, j;
for (j = 1, i = 0; i < n; i++) {
if (q[i].v * times >= (double)h * j + 1... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000 * 1000;
int tail, a[N];
int main() {
int i, j, x;
string s;
cin >> s;
x = s.size();
for (i = 1; i < x; i += 3) {
if (s[i] == '/') {
i++;
a[tail] = s[i] - 'a' + 1;
a[tail] *= -1;
tail++;
} else {
a[tail] = s[... | 2 |
#include <bits/stdc++.h>
using namespace std;
int a[220], sum[220], oth[220], mine[220];
int main() {
int n, k;
scanf("%d %d", &n, &k);
sum[0] = 0;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
sum[i] = sum[i - 1] + a[i];
}
int best = -200000000;
for (int l = 1; l <= n; l++) {
for (int r ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, m, Deg[101000], PV[101000];
vector<int> E[101000], F[101000], G[101000], T[101000];
int SCC[101000], ord[101000], cnt, vis[101000];
set<int> Set;
void DFS1(int a) {
vis[a] = 1;
for (auto &x : E[a]) {
if (!vis[x]) DFS1(x);
}
ord[++cnt] = a;
}
void DFS2(int... | 24 |
#include <bits/stdc++.h>
using namespace std;
const int p = 998244353;
const int g = 3;
const int Inf = 2e9;
int GCD(int x, int y) { return y ? GCD(y, x % y) : x; }
void add_self(int& x, int y, const int& m) {
if ((x += y) >= m) x -= m;
}
void sub_self(int& x, int y, const int& m) {
if ((x -= y) < 0) x += m;
}
int ... | 16 |
#include <bits/stdc++.h>
using namespace std;
map<int, vector<int> > cache;
int Total;
vector<int> ask(int c) {
vector<int> res;
cout << "? " << c + 1 << endl;
cout.flush();
int K;
cin >> K;
if (K == 0) exit(0);
res = vector<int>(K);
for (int i = 0; i < (K); ++i) {
cin >> res[i];
res[i]--;
}
... | 20 |
#include <bits/stdc++.h>
using namespace std;
map<string, vector<string> > m;
int main() {
char s[102400];
int n;
scanf("%d", &n);
while (n--) {
int kk;
scanf("%s%d", s, &kk);
string nam = s;
string cur;
gets(s);
char *cp = s;
while (*cp == ' ') cp++;
while (*cp) {
cur.clea... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <class T, class T2>
inline void chkmax(T &x, const T2 &y) {
if (x < y) x = y;
}
template <class T, class T2>
inline void chkmin(T &x, const T2 &y) {
if (x > y) x = y;
}
const int MAXN = (1 << 20);
int64_t n, m, k;
void read() { cin >> n >> m >> k; }
void solve(... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int Nmax = 2e5 + 112;
int n, b[Nmax];
map<long long, long long> mp;
long long ans;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = (int)1; i <= (int)n; ++i) {
cin >> b[i];
long long cur = mp[i - b[i]] + b[i];
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int arr[1000000];
map<int, int> mp;
int main() {
int n, l, x, y;
scanf("%d%d%d%d", &n, &l, &x, &y);
int i;
for (i = 0; i < n; i++) {
scanf("%d", &arr[i]);
mp[arr[i]] = 1;
}
int cnt = 0;
for (i = 0; i < n; i++) {
if (mp.count(arr[i] + x)) {
cn... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200200;
const int A = 1000100;
int n, ds[N];
vector<pair<int, int>> edges[A], queries[A];
int get(int x)
{
return x == ds[x] ? x : ds[x] = get(ds[x]);
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int q, s, d;
cin >> n >> q >> s >> d;
... | 19 |
#include <bits/stdc++.h>
using namespace std;
long long t, l, r, m;
int main() {
cin >> t;
while (t--) {
cin >> l >> r >> m;
long long mn = max(1ll, m - r + l);
long long mx = m + r - l;
for (long long i = l; i <= r; i++) {
long long x = mn / i;
if (mn % i) x++;
if (i >= mn) x = 1;... | 7 |
#include <bits/stdc++.h>
using namespace std;
static const double EPS = 1e-10;
template <typename T, typename S>
vector<T> &operator<<(vector<T> &a, S b) {
a.push_back(b);
return a;
}
template <typename T>
void operator>>(vector<T> &a, int b) {
while (b--)
if (!a.empty()) a.pop_back();
}
bool isprime(int n) {... | 16 |
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 998244353;
int main() {
int len;
string S;
cin >> len >> S;
long long int l = 1, r = 1;
for (int i = 1; i < len; i++) {
if (S[i] == S[0])
l++;
else
break;
}
for (int i = len - 2; i >= 0; i--) {
if (S[i] == S[le... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000007;
const int MOD = 1000000007;
int fact[MAXN], rev[MAXN], cnt[26];
int n;
long long binPow(long long a, long long b) {
if (!b) return 1;
if (b == 1) return a % MOD;
if (b & 1) {
return a * binPow(a, b - 1) % MOD;
}
long long half = binPo... | 13 |
#include <bits/stdc++.h>
using namespace std;
int btcnt(int x) {
int s = 0;
while (x > 0) x /= 10, s += 1;
return s;
}
int fa[10];
int getv(int x) { return x == fa[x] ? x : fa[x] = getv(fa[x]); }
bool merge(int a, int b) {
a = getv(a);
b = getv(b);
return a == b ? false : fa[b] = a;
}
vector<int> ve[10];
in... | 24 |
#include <bits/stdc++.h>
using namespace std;
long long a[15];
int k[10005];
char s[11][10005];
vector<long long> v[200005], vv, save;
int outs[20005];
int main() {
long long ans;
int t;
cin >> t;
while (t--) {
ans = -1e18;
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) scanf("%lld", a + i... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int MX = 3e5 + 10;
const int INF = 1e9;
bool vis[MX];
set<int> s;
int cnt[MX], N, M, dp[MX], pre[MX];
vector<pair<int, int> > rg;
vector<int> adj[MX];
void chmax(int& a, int b) {
if (b > a) a = b;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.t... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const int MOD = 1e9 + 7;
vector<int> a, b;
bool alast = false;
int main() {
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
int e;
scanf("%d", &e);
if (e > 0) {
a.push_back(e);
if (i == n - 1) alast = true;
} else ... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long n, k, ans, sum, a[101];
void check(long long t) {
long long ret = 0;
for (int i = 1; i <= n; ++i) {
if (a[i] % t) ret += (a[i] / t + 1) * t - a[i];
}
if (ret <= k) ans = max(ans, t);
}
int main() {
scanf("%lld%lld", &n, &k), sum += k;
for (int i = ... | 15 |
#include <bits/stdc++.h>
using namespace std;
int sum_of_digits(int x) {
int sum = 0;
while (x) {
sum += (x % 10);
x /= 10;
}
return sum;
}
int main() {
int n;
scanf("%d", &n);
set<int> ans;
for (int i = 0; i <= 100; i++) {
int x = n - i;
if (x >= 0 && sum_of_digits(x) == i && n == x + s... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t, n;
cin >> t;
while (t--) {
priority_queue<long long> pq;
cin >> n;
for (long long i = n; i >= 1; i--) {
pq.push(i);
}
long long a, b, c;
cout << 2 << endl;
while (pq.size() > 1) {
a = pq.top();
pq... | 2 |
#include <bits/stdc++.h>
using namespace std;
int ara[1111], vis[1111];
vector<int> v[1111];
string s[1111];
int keep, id, mn;
void dfs(int node) {
if (node > id && mn > ara[node]) {
keep = node;
mn = ara[node];
}
vis[node] = 1;
for (int i = 0; i < v[node].size(); i++) {
if (vis[v[node][i]] == 0) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int ti, te, td, tr, dp[4005][4005], aa, bb, la[4005][26], lb[4005][26], p[4005];
char a[4005], b[4005];
signed main() {
cin >> ti >> td >> tr >> te;
cin >> a + 1 >> b + 1;
aa = strlen(a + 1);
bb = strlen(b + 1);
memset(dp, 0x3f, sizeof(dp));
for (int i = 1; i <=... | 18 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
ll hell = 1e15 + 7;
double dp[10009][5 + 1][2][3];
int main() {
ll n;
cin >> n;
vector<pair<ll, ll>> v;
for (ll i = 0; i < n; ++i) {
ll x, y;
cin >> x >> y;
v.push_back({x, y});
}
for (ll x = 1; x < 10001; ++x) {
dp[x][0... | 12 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000 * 1000 * 1000 + 7;
const long long NMAX = 2000 * 1000 + 11;
vector<long long> G[NMAX];
long long color[NMAX];
void put(long long x) {
color[x] = -color[x];
cout << " " << x;
}
void dfs(long long u, long long pre) {
for (long long i = 0; i < ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int l, r, p, ans = 0, S[25], K[25], t = 0, flag;
const int P[25] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41,
43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
void Search2(int y, int z, int rest, int pre, int lans) {
if (p - y - rest < 0) retu... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 100000;
int m, n;
int a[Maxn + 5], p[Maxn + 5];
int x[Maxn + 5], k[Maxn + 5];
int e_pos[Maxn + 5], steps[Maxn + 5];
int Root[Maxn + 5];
struct Segment_Node {
int lson, rson;
int val;
} seg[Maxn * 25 + 5];
int id_tot;
void build(int &root, int left = 1, ... | 26 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void PrArr(const T a[], int len) {
for (int i = 0; i <= len; i++) cout << a[i] << " ";
cout << endl;
}
template <typename T>
void PrVec(const vector<T> a) {
for (auto it : a) cout << it << " ";
cout << endl;
}
template <class T>
inline void rea... | 4 |
#include<bits/stdc++.h>
using namespace std;
constexpr int N = 200000 + 10;
typedef long long ll;
int T;
string solve(string s, int a, int b) {
if (s.empty()) return "";
for (auto const& v : s)
if (v == '0')
a--;
else if (v == '1')
b--;
const int n = s.size();
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, m, a[2505][2505];
struct O {
int i, j, x;
} c[4000000];
bitset<2505> f[2505];
bool cmp(O a, O b) { return a.x > b.x; }
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j) scanf("%d", &a[i][j]);
for (int i = 1; i <= n; +... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int n, k;
vector<int> g[maxn];
bool is[maxn];
int st[maxn];
void dfs(int v, int p = -1) {
st[v] = is[v];
for (auto u : g[v])
if (u != p) {
dfs(u, v);
st[v] += st[u];
}
}
int we(int v, int u) {
return min(min(st[u], st[v])... | 10 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.