solution stringlengths 53 181k | difficulty int64 0 13 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
long long int mod = 1e9 + 7;
long long int exp(long long int x, long long int y) {
long long int res = 1;
x = x % mod;
while (y > 0) {
if (y & 1) res = (res * x) % mod;
y = y >> 1;
x = (x * x) % mod;
}
return res;
}
long long int modinv(long long int x... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct edg {
bool tpe;
int u, v;
int gt00, gt01, gt10, gt11;
};
const int md = 1000000007;
inline void add(int &a, int b) {
a += b;
if (a >= md) a -= md;
}
inline int mul(int a, int b) { return 1ll * a * b % md; }
int mn0, mn1;
void updmn(int s0, int s1) {
int n... | 10 |
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef long long ll;
#define pb push_back
#define po pop_back
#define pii pair < lli ,lli >
#define it iterator
#define pll pair < ll, ll>
#define plli pair < lli, lli>
#define mp make_pair
#define vi vector <lli>
#define len length
#define fi fir... | 0 |
#include <bits/stdc++.h>
struct pnt {
int x, y;
};
int x, y, z;
int a, b, c;
int ar[7];
int kenar() {
pnt p1, p2, p3, p4;
pnt vas;
p1.x = 0;
p1.y = 0;
p2.x = a;
p2.y = 0;
p3.x = a;
p3.y = c;
p4.x = 0;
p4.y = c;
vas.x = x;
vas.y = z;
int res = 0;
if (vas.y < p1.y) res += ar[3];
if (vas.y ... | 4 |
#include <bits/stdc++.h>
using namespace std;
unsigned long long gcd(unsigned long long a, unsigned long long b) {
unsigned long long c;
while (a != 0) {
c = a;
a = b % a;
b = c;
}
return b;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int pri[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 2... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int num1 = 0;
int num2 = 0;
int num3 = 0;
cin >> s;
for (int i = 0; i < s.length(); i++) {
if (s[i] == '1') {
num1++;
} else if (s[i] == '2') {
num2++;
} else if (s[i] == '3') {
num3++;
}
}
for (int j ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 2000000000;
const int N = 10005;
long long ans = 0;
vector<int> g[N];
void dfs(int v, int pr = -1) {
for (int i = 0; i < g[v].size(); i++) {
int to = g[v][i];
if (to == pr) {
continue;
}
dfs(to, v);
ans += (g[to].size() - 1);
}
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007, INF = 2000000001;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1, 0},
dy[] = {-1, 0, 1, 0, -1, 1, 1, -1, 0};
const double EPS = 1e-9;
void init(string fname) {
freopen((fname + ".in").c_str(), "r", stdin);
freopen((fname + ".out").c_str(), "... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000 + 100;
int n, a[maxn], b[maxn], c[maxn], ac[maxn], bc[maxn], a2b2[maxn];
long long res;
struct Point {
long long x, y;
};
long long gcd(long long x, long long y) {
if (y == 0) return x;
return gcd(y, x % y);
}
Point getStand(Point t) {
if (t.x ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n, m, col[777], Head[777], Next[5555555], Go[5555555], Cnt = 0, tim = 0;
void addedge(int x, int y) {
Go[++Cnt] = y;
Next[Cnt] = Head[x];
Head[x] = Cnt;
Go[++Cnt] = x;
Next[Cnt] = Head[y];
Head[y] = Cnt;
}
int ask(vector<int> V) {
if (V.size() <= 1) return... | 10 |
#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, -1, 0, 1, 1, -1, -1, 1};
int dy[] = {-1, 0, 1, 0, -1, -1, 1, 1};
int dx1[] = {0, 1, 1}, dx2[] = {0, 1, 1}, dy1[] = {1, 1, 0},
dy2[] = {-1, -1, 0};
int n, x[4], y[4], maxx, maxy, minx, miny;
int main() {
cin >> n;
for (int i = 0; i < n; i++) cin >> x[i... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 7;
int t, n;
char s[N];
int main() {
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
scanf("%s", s + 1);
int ans = n;
for (int i = 1; i <= n; i++) {
if (s[i] == '1') {
ans = max(ans, i * 2);
ans = max(ans, (n - i... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
long long a, b, n, m;
cin >> a >> b >> n >> m;
if (a + b >= n + m && min(a, b) >= m)
cout << "YES" << endl;
else
cout << "NO" << endl;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
;
long long n, k;
cin >> n >> k;
long long type = -1;
long long tran = -1;
long long boxes = -1;
for (long long i = 0; i < k; i++) {
long long x;
cin >> x;
long long temp = n... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
long long a[N], ch[N], p[N];
bool vis[N], vis1[N];
vector<long long> v[N];
set<int> s;
map<string, long long> mp;
int node1 = 1, node2 = 1, mx = 0, n;
bool q = 0;
int dfs(int j, int r) {
for (int i = 0; i < v[j].size(); i++) {
if (v[j][i] != r) ... | 4 |
#include <bits/stdc++.h>
using namespace std;
void Read(int &x) {
char c;
bool flag = 0;
while (c = getchar(), c != EOF && (c < '0' || c > '9') && c != '-')
;
if (c == '-') {
c = getchar();
flag = 1;
}
x = c - '0';
while (c = getchar(), c != EOF && c >= '0' && c <= '9') x = x * 10 + c - '0';
}... | 6 |
#include <bits/stdc++.h>
int main() {
int n, m, f;
scanf("%d %d %d", &n, &m, &f);
int a[n][m];
int i, j = 0;
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
scanf("%d", &a[i][j]);
}
printf("\n\n");
}
int k = 0, temp, p = 0;
if (f == 1) {
for (i = 0; i < m; i++) {
for (j =... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;
const long long int N = 1e5 + 5;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long int n;
string s;
cin >> n >> s;
unordered_map<long long int, long long int> f;
for (long long int i = 0; ... | 4 |
#include <bits/stdc++.h>
long long M = 1000000007;
using namespace std;
long long fact[10000];
long long power(long long x, unsigned long long y, unsigned long long m) {
if (y == 0) return 1;
long long p = power(x, y / 2, m) % m;
p = (p * p) % m;
return (y % 2 == 0) ? p : (x * p) % m;
}
unsigned long long modIn... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int add(int a, int b) {
a += b;
if (a >= mod) {
a -= mod;
}
return a;
}
int rest(int a, int b) {
a -= b;
if (a < 0) {
a += mod;
}
return a;
}
int mult(int a, int b) { return ((long long)a * (long long)b) % mod; }
const int... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long two[51];
void init() {
two[0] = 1;
for (int i = 1; i < 51; i++) two[i] = two[i - 1] * 2;
}
long long dfs(long long h, long long n, int dir) {
if (h == 0) return 0;
long long vis = 1;
int req = (n > (1LL << (h - 1)));
if (req != dir) vis += two[h] - 1;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int dx[] = {-1, -1, -1, 0, 1, 1, 1, 0},
dy[] = {-1, 0, 1, 1, 1, 0, -1, -1};
int used[300][300], board[300][300];
int T, n, m, cnt, xmax, xmin, ans;
void dfs(int x, int y) {
if (used[x][y] || !board[x][y]) return;
used[x][y] = 1;
cnt++;
xmax = max(xma... | 7 |
#include <bits/stdc++.h>
using namespace std;
vector<int> e[200010];
int a[200010], top, dp[200010], flag, x;
bool f[200010];
char s[200010];
int dfs(int u) {
f[u] = 1;
if (e[u].size() == 0) {
if (u == x) flag = 1;
return 1;
} else {
int q = dfs(e[u][0]) + 1;
if (u == x) flag = q;
return q;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
struct point {
int x, y;
};
double calculate(int x1, int y1, int x2, int y2, int x3, int y3) {
return abs((x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)) / 2.0);
}
double cacu(int x1, int y1, point a[]) {
double sum = 0;
int next;
for (int i = 0; i < 4; i++) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long Mod = 1e9 + 7;
long long qpow(long long x, long long q) {
long long ans = 1;
while (q) {
if (q & 1) ans = ans * x % Mod;
q >>= 1;
x = (x * x) % Mod;
}
return ans % Mod;
}
long long x, n;
int main() {
cin >> x >> n;
vector<int> a;
fo... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct caca {
long long a, b;
};
caca v[7005];
bool ok[7005];
bool cmp(caca a, caca b) { return a.a < b.a; }
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> v[i].a;
for (int i =... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void test(T a) {
cout << a << endl;
}
template <class T, class T2>
void test(T a, T2 b) {
cout << a << " " << b << endl;
}
template <class T, class T2, class T3>
void test(T a, T2 b, T3 c) {
cout << a << " " << b << " " << c << endl;
}
const int N =... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long extgcd(long long a, long long b, long long& x, long long& y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
long long x1, y1;
long long d = extgcd(b, a % b, ... | 2 |
#include <bits/stdc++.h>
const long long MAXN = 5e3 + 19;
const long long INF = 1e18;
long long n, a[MAXN], b[MAXN];
long long tmp[MAXN], tot;
long long dp[MAXN][MAXN];
long long dfs(long long l, long long r) {
if (dp[l][r] != INF) return dp[l][r];
bool flag = 0;
long long L, R;
long long mn;
long long res = ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long ans;
long long a, b;
cin >> a >> b;
long long sum = 0;
for (long long i = 1; i <= a; i++) sum = (sum + i) % 1000000007;
ans = 0;
for (long long i = 1; i < b; i++) {
ans = (ans + ((sum * b) % 1000000007) * i % 1000000007 + (i * a)) %
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int w[maxn], c[maxn], arr[4][maxn], top[4], n, m;
long long sum[4][maxn];
struct Node {
long long cost;
int i, j;
} dp[maxn * 3];
int main() {
while (~scanf("%d%d", &n, &m)) {
long long ans = 0;
for (int i = 1; i <= 3; i++) sum[i][0] =... | 7 |
#include <bits/stdc++.h>
using namespace std;
int N, ar[25], ori[25], temp[25];
bool cmp(int a, int b) { return ar[a] < ar[b]; }
int main() {
scanf("%d", &N);
for (int i = 0; i < N; i++) {
scanf("%d", &ar[i]);
ori[i] = i;
}
sort(ori, ori + N, cmp);
for (int i = 0; i < N; i++) temp[ori[i]] = ar[ori[(i ... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long int exp(long long int x, long long int y) {
if (y == 0) return 1;
if (y == 1) return x;
if (y % 2 == 0)
return exp(x, y / 2) * exp(x, y / 2);
else
return x * exp(x, y / 2) * exp(x, y / 2);
}
long long int gcd(long long int a, long long int b) {
i... | 0 |
#include <bits/stdc++.h>
using namespace std;
int a, b, d;
int main() {
cin >> a >> b;
d = a - b;
if (d < 0) d *= -1;
long long rez = 0;
rez = (long long)(d / 2) * (d / 2 + 1);
if (d % 2) rez += d / 2 + 1;
cout << rez;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n = 0;
cin >> n;
vector<int> in;
int i = 0;
for (i = 1; i <= n; i++) {
int a = 0;
cin >> a;
in.push_back(a);
}
vector<int> out = in;
sort(in.begin(), in.end());
int shoot = 0;
for (i = in.end() - in.begin() - 1; i >= 0; i--) ... | 0 |
#include <bits/stdc++.h>
const int N = 100010;
int n;
char s[N];
bool f[26];
int main() {
scanf("%s", s + 1);
n = strlen(s + 1);
for (int i = 1; i <= n - 25; i++) {
int c = 0;
for (int j = 0; j < 26; j++) f[j] = false;
for (int j = i; j < i + 26; j++)
if (s[j] != '?')
f[s[j] - 'A'] = tru... | 2 |
#include <bits/stdc++.h>
using namespace std;
char s[100001];
int main() {
int l;
scanf("%s", s);
l = strlen(s);
puts((s[l - 1] & 1) || (s[l - 1] / 2 + (l > 1 ? s[l - 2] : 0) & 1) ? "0"
: "4");
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxx = 2 * 1e6 + 7, mod = 1e9 + 7;
int n, a[maxx], prime[maxx], vis[maxx];
void getprime(int x) {
for (int i = 2; i <= x; i++) {
if (!vis[i]) prime[++prime[0]] = i;
for (int j = 1; j <= prime[0] && i * prime[j] <= x; j++) {
vis[i * prime[j]] = 1;
... | 5 |
#include <bits/stdc++.h>
int par[100050][20];
int dep[100050];
int nw[100050];
std::vector<std::vector<int>> adj;
int make_tree(int id, int depth) {
nw[id] = 1;
dep[id] = depth;
for (auto i : adj[id]) {
if (dep[i]) continue;
int pidx = id, cnt = 0;
par[i][0] = id;
while (pidx != -1) {
pidx =... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n, m, a[1005], ans, min, min2;
a[1004] = 100000;
cin >> t;
for (int i = 0; i < t; i++) {
scanf("%d%d", &m, &n);
ans = 0;
min = 1004;
min2 = 1004;
for (int j = 0; j < m; j++) {
scanf("%d", &a[j]);
ans += a[j];
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
long long int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
if (n % 2 != 0)
cout << a[(n / 2)];
else
cout << a[(n / 2) - 1];
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long int input() {
char c = getchar();
while (c < '0' || c > '9') c = getchar();
long long int ans = 0;
while (c >= '0' && c <= '9') {
ans = (ans << 3) + (ans << 1) + c - '0';
c = getchar();
}
return (ans);
}
int main() {
long long int permut[5] =... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool checkMin(T& a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T>
bool checkMax(T& a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
const int INF = 1e9;
const int N = 3e5 + 10;
int n, k;
long long a... | 6 |
#include <bits/stdc++.h>
#define maxn 130086
using namespace std;int n, p;int f[maxn], g[maxn], h[maxn];
int main(){scanf("%d%d", &n, &p);f[0] = 1;for(int i = 0;i < maxn;i++) g[i] = 1;int ans = 0;for(int i = 1;i <= n - 1;i++){
for(int j = maxn - 1;~j;j--) f[j] = (g[j] + p - (j - i < 0 ? 0 : g[j - i])) % p;
for(int ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, q;
char s[100002], a[11];
int pos[11][11 - 1][4][100002];
void add(int len, int r, int val, int x) {
for (int i = abs(x); i <= n; i += i & (-i))
if (x > 0)
++pos[len][r][val][i];
else
--pos[len][r][val][i];
}
int sum(int len, int r, int val, int... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
string s;
cin >> s;
long long int i;
map<char, long long int> mp;
for (i = 0; i < s.length(); i++) mp[s[i]]++;
char x;
long long int eve = 0, odd = 0;
for (x = 'a'; x <= ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, u;
cin >> n >> u;
int a[n + 5];
for (int i = 1; i <= n; i++) cin >> a[i];
double ans = 0;
for (int i = 1; i < n - 1; i++) {
int pos = upper_bound(a + 1, a + n + 1, a[i] + u) - (a + 1);
if (pos <= i + 1) continue;
ans = max(ans, (d... | 4 |
#include <bits/stdc++.h>
using namespace std;
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
const long long INFll = 1ll * 1000000000 * 1000000000;
const long double PI =
3.141592653589793238462643383279502884197169399375105820974944;
int mul(int a, int b, int mod = 1000003) ... | 5 |
#include <bits/stdc++.h>
using namespace std;
string A, B;
int used[10][2];
int memo[10][2];
int m;
int dp(int pos, int mayor) {
if (pos == m) return mayor;
if (used[pos][mayor]) return memo[pos][mayor];
used[pos][mayor] = 1;
int &dev = memo[pos][mayor] = 0;
if (B[pos] == '?') {
if (mayor) {
if (pos... | 6 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:255000000")
bool firstout = 1;
template <class T>
void minn(T &a, T b) {
if (b < a) a = b;
}
template <class T>
void maxx(T &a, T b) {
if (a < b) a = b;
}
int madd(int &a, int b) {
a += b;
if (a >= 1000000009) a -= 1000000009;
retur... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long sqr(long long x) { return (long long)x * x; }
long long tri(long long x) {
if (x < 0) return 0;
return (long long)x * (x + 1) / 2;
}
long long calc(long long n, long long s, long long x, long long y) {
long long res = 2LL * s * (s + 1) + 1;
if (x - s < 1) ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
inline int read() {
register int x = 0, f = 0;
register char c = getchar();
while (c < '0' || c > '9') f |= c == '-', c = getchar();
while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - '0', c = getchar();
return f ? -x : x;
}
int n;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[20] = {1, 5, 13, 25, 41, 61, 85, 113};
int b[20] = {1, 3, 5, 7, 9, 11, 13, 15};
int x;
scanf("%d", &x);
if (x == 3)
printf("5\n");
else {
for (int i = 0; i <= 100; i++) {
if (a[i] >= x) {
printf("%d\n", b[i]);
bre... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, m, a[510][510], b[510][510], A[1020][510], B[1020][510];
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) scanf("%d", &a[i][j]);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) scanf("%d", &b[i][j])... | 3 |
#include <bits/stdc++.h>
using namespace std;
int a[5005], dpl[5005][5005], dpr[5005][5005];
int n, ans, cnt;
void prepare() {
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++) {
if (a[j] < a[i])
dpl[i][j] = dpl[i][j - 1] + 1;
else
dpl[i][j] = dpl[i][j - 1];
}
for (in... | 5 |
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
using namespace std;
const int MAX = 1e3 + 5;
const long long MAX2 = 11;
const long long MOD = 1000000007;
const long long MOD2 = 1000005329;
const long long INF = 2e18;
const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
const int dc... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void umax(T &a, T b) {
if (a < b) a = b;
}
template <class T>
inline void umin(T &a, T b) {
if (a > b) a = b;
}
template <class T>
inline T abs(T a) {
return a > 0 ? a : -a;
}
template <class T>
inline T gcd(T a, T b) {
return __gcd(a, b);
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int na, ka;
int lowbit(int x) { return x & (-x); }
bool chk(int n, int k) {
if (k < 0) return 0;
if (!(n % 2)) return 0;
if (k && k * 2 + 3 > n) return 0;
if (lowbit(n + 1) == n + 1 && k == 1) return 0;
if (lowbit(n + 1) != n + 1 && k == 0) return 0;
if (n == 9 ... | 10 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void read(T &u) {
u = 0;
char c = getchar();
int flag = 0;
while (c < '0' || c > '9') flag |= (c == '-'), c = getchar();
while (c >= '0' && c <= '9')
u = (u << 3) + (u << 1) + (c ^ 48), c = getchar();
if (flag) u = -u;
}
template <class T>... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200200;
const int mod = 1e9 + 7;
int n;
int a[N];
int main() {
ios_base::sync_with_stdio(0);
cin >> n;
string s;
cin >> s;
int ans = 0;
for (int i = 0; i < n; i++) {
int j = i;
int cnt = 0;
vector<char> v;
while (j < n) {
if (... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 410;
int n, m;
int nxt[N][26];
char s[N], t[N];
void init() {
for (int j = 0; j <= 25; j++) {
nxt[n][j] = n + 1;
nxt[n + 1][j] = n + 1;
}
for (int i = n - 1; i >= 0; i--) {
for (int j = 0; j <= 25; j++) nxt[i][j] = nxt[i + 1][j];
nxt[i][s... | 7 |
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
template <typename A>
ostream &operator<<(ostream &cout, vector<A> const &v);
template <typename A, typename B>
ostream &operator<<(ostream &cout, pair<A, B> const &p) {
return cout << "(" << p.first << ", " << p.second << ")";
}
template <typ... | 7 |
#include <bits/stdc++.h>
using namespace std;
set<long long> div(long long num) {
set<long long> ret;
ret.insert(0);
for (long long i = num; i < 1e9; i++) {
if (i % num == 0) {
ret.insert(i);
}
}
return ret;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long n... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1200005;
int n, q;
vector<int> v[N];
int f[N * 5][8], x, ans[15], Ans[N];
struct Ask {
int l, r, from;
} A[N];
inline int cmp(Ask x, Ask y) { return x.r < y.r; }
int main() {
scanf("%d%d", &n, &q);
for (int i = 1; i <= n; i++) {
scanf("%d", &x);
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double PI = acos((long double)-1.0);
const double EPS = 1e-10;
const int MOD = 1e9 + 7;
template <typename T>
void cmin(T &x, T y) {
if (y < x) x = y;
}
template <typename T>
void cmax(T &x, T ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 1, inf = 1e9 + 7;
int p[maxn], dp[maxn];
int n, usd[maxn], a[maxn];
vector<pair<int, char> > g[maxn];
int t[4 * maxn], add[4 * maxn];
int cp = 0;
void push(int x, int cl, int cr) {
if (cr - cl > 1) {
add[2 * x] += add[x];
add[2 * x + 1] += a... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long n, a, b, c, s, ans;
int main() {
ios_base::sync_with_stdio(0);
cin >> n >> a >> b >> c;
n *= 2;
for (int i = 0; i <= c; i++)
for (int j = 0; j <= b; j++) {
s = 4 * i + 2 * j;
s = n - s;
if (s >= 0 && s <= a) ++ans;
}
cout << ans... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n;
int p;
class cp {
public:
bool operator()(pair<long long, long long> p1,
pair<long long, long long> p2) {
if (p1.first / p < p2.first / p)
return true;
else if (p1.first / p == p2.first / p) {
if (p1.first == p2.first && p1.se... | 1 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long a, b, d, z, y, p, k, n, flag, M = 0;
std::vector<long long> v(4);
for (long long i = 0; i < 4; i++) cin >> v[i];
sort(v.begin(), v.end());
long long abc = (v[0] + v[1] + v[2] + v[3]) / 3;
cout << abc - v[0] << " " << abc - v[1] << " " <<... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x7f7f7f7f;
const int maxn = 5111;
const int mod = 1e9 + 7;
const double pi = acos(-1.0);
const double eps = 1e-10;
long long a[maxn];
int cnt[maxn];
long long odd[maxn];
int f[maxn];
int main() {
ios::sync_with_stdio(false);
int n, i, j, ans;
cin >> n... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e3 + 5;
int times[maxn][maxn], Time, cost[maxn][maxn], n, m;
string k[maxn];
int dfs(int x, int y) {
if (!min(x, y) or x > n or y > m) return 0;
times[x][y] = ++Time;
int now = k[x][y - 1];
int nextx, nexty;
if (now == 'R')
nextx = x, nexty =... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-8;
struct p3d {
long double x, y, z;
p3d(long double xx = 0, long double yy = 0, long double zz = 0) {
x = xx, y = yy, z = zz;
}
};
long double abs(const p3d &v) {
return sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
}
ostream &operator<<(o... | 4 |
#include <bits/stdc++.h>
using namespace std;
int ask(int x, int y) {
cout << x << " " << y << endl;
string color;
cin >> color;
return color == "black";
}
int main() {
int n;
cin >> n;
int pivot = ask(0, 0);
if (n == 1) {
cout << "1 0 1 1" << endl;
return 0;
}
int pivot2 = ask(1 << 29, 0);
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int N, M, Q, X, Y, a, b;
int MT[1001][1001];
bool ans[200005];
vector<int> qidx[200005];
class EDGE {
public:
int a, b;
} E[200005];
class QUERY {
public:
int l, r, s, t, idx;
} QR[200005];
int main() {
cin >> N >> M >> Q;
for (int i = 1; i <= M; i++) scanf("%d%d"... | 10 |
#include <bits/stdc++.h>
using namespace std;
string chain(string a, string b) {
int n = min(a.size(), b.size());
unsigned long long ah = 0, bh = 0;
unsigned long long mul = 1;
int cur = 0;
for (int i = 0; i < n; i++) {
ah = ah * 101 + a[a.size() - i - 1];
bh += mul * b[i];
mul *= 101;
if (ah ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int SI = 3e5 + 100;
int n, m, k;
struct node {
int id, to, w;
node(int id, int to, int w) {
this->id = id;
this->to = to;
this->w = w;
}
};
bool vis[SI];
long long d[SI];
vector<node> G[SI];
int pre[SI];
bool use[SI];
vector<int> ans;
void dij() {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFLL = 0x3f3f3f3f3f3f3f3fLL;
inline long long read() {
long long x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
const int MAXINT = 1073741823;
long long int a[MAXN];
set<long long int> s;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long int n, m, k, x, page, counter = 0, answer = 0, cc;
cin >> n >> m >> k;
for (long long int i = 0; i ... | 3 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const ll MOD = 1000000021;
ll binpow(ll a, ll b) {
ll res = 1;
while (b) {
if (b & 1) res = (res * a) % MOD;
a = (a * a) % MOD;
b >>= 1;
}
return res;
}
ll modInv(ll a) { return binpow(a, MOD - 2); }
const do... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int a[MAXN];
int main() {
int n, x, y, count = 0;
cin >> n >> x >> y;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] <= x) count++;
}
if (x > y)
cout << n;
else
cout << (count + 1) / 2;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2e9;
int N;
string s;
void solve(int tc) {
cin >> N >> s;
vector<pair<long long, long long> > v;
v.push_back({INF, -1});
long long sum = 0, ans = 0, cnt = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '1') {
cnt++;
while (v.ba... | 8 |
#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 1e9 + 7;
vector<int> moves;
int main() {
moves.push_back(0);
for (int i = 0; i < 20; ++i) {
int n = moves.size();
for (int k = n - 1; k >= 0; --k) {
moves.push_back(moves[k] | (1 << i));
}
}
int n;
scanf("%d", &n);
vec... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
long long ara[N];
int main() {
long long n, m;
cin >> n >> m;
for (long long i = 0; i < m; ++i) {
long long x;
cin >> x;
++ara[x];
}
vector<long long> v;
for (long long i = 1; i <= 100; ++i) {
if (ara[i] != 0) v.push_back(ara[... | 2 |
#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int dp[5005][5005][2];
map<int, int> mp;
int main() {
int n;
cin >> n;
v.resize(n + 1);
for (int i = 1; i <= n; i++) cin >> v[i];
memset(dp, 0x3f, sizeof(dp));
for (int i = 1; i <= n; i++) dp[i][i][0] = dp[i][i][1] = 0;
for (int i = 1; i <= n; i... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long l, u, v, w, x, y, z, a, b, c, d, e, f, t = 1, tc;
long long flg, sz, cnt, gt, ans, mx, mn;
long long m, k, n, i, j;
long long low, hi, md, inp[200007], sm, ff, ex;
vector<long long> tk[4];
cin >> a >> b >> c;
cin >> n;
string st;
for... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9 + 5;
const long long INF = 1e18 + 5;
const long long maxn = 5e5 + 5;
long long n, b[555555], mx = -1000000001;
int a[555555], sum, cnt, ans;
set<int> second;
int p[555555];
int d[5555][5555];
vector<long long> v, x, y;
int main() {
cin.tie(0);
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, q;
cin >> n >> q;
const int N = 200, M = 100;
vector<vector<int> > a(N), b(N);
for (int i = 0; i < N; i++) a[i].resize(N), b[i].resize(N);
a[M][M] = n;
while (1) {
for (int i = 0; i < N; i++)
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MAXM = 100005;
int n, m, k;
long double lnFact[MAXM] = {0}, ans = 0;
int t;
inline double lnC(int x, int y) {
return lnFact[x] - lnFact[y] - lnFact[x - y];
}
int main() {
scanf("%d%d%d", &n, &m, &k);
for (int i = 2; i < MAXM; ++i) lnFact[i] = lnFact[i - 1] +... | 9 |
#include <bits/stdc++.h>
const int N = 2e4 + 10, LOG = 15, K = 31;
template<typename T>
inline T max(const T &x, const T &y) {
return x > y ? x : y;
}
template<typename T>
inline T min(const T &x, const T &y) {
return x < y ? x : y;
}
int n, q, a[N], lg[N], dp[LOG][K][N], f[LOG][K][N], ans[N], pos[K][N];
struct qusti... | 13 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#pragma GCC target("avx,tune=native")
using namespace std;
const long long inf = (long long)4e18;
const double eps = 1e-6;
const long long mod = 1000000007;
long long modpow(long long ... | 7 |
#include <bits/stdc++.h>
using namespace std;
struct no {
int fim;
map<char, no *> t;
no() : fim(-1) {}
} trie;
bool memo[10010] = {};
int n, m;
string ans, text, dict[100010];
void add(int id, const string &s) {
no *r = ≜
for (int i = 0; i < (int)s.size(); ++i) {
char c = tolower(s[i]);
if (!r->... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
vector<int> vec;
cin >> n;
while (n) {
n--;
priority_queue<int> pq;
int one = 0, wildcard = 0, zero = 0;
int m, brojac = 0;
cin >> m;
for (int i = 0; i < m; i++) {
string s;
cin >> s;
for (char c : s) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int r, c, n, len, l, z, x, y, m, t, k, ans;
int a[200005], b[200005];
map<int, int> ind;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
ind[a[i]] = i;
}
for (int i = 0; i < n; i++) {
scanf("%d", &b[i]);
}
int ii = 0;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 0;
int main() {
int button, light;
int arr[105];
for (int i = 0; i < 105; i++) {
arr[i] = 0;
}
cin >> button >> light;
for (int i = 0; i < button; i++) {
int x;
cin >> x;
for (int i = 0; i < x; i++) {
int y;
cin >> y;... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
char s1[maxn], s2[maxn];
int main() {
int n, m, i, x = 0, y = 0;
scanf("%s %s", s1, s2);
n = strlen(s1);
m = strlen(s2);
for (i = 0; i < n; i++)
if (s1[i] == '1') x++;
if (x % 2) x++;
for (i = 0; i < m; i++)
if (s2[i] == '1') y++... | 4 |
#include <bits/stdc++.h>
const int mod = 998244353;
const int maxn = 2e5 + 5;
const long long int INF = 1e18;
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tc;
cin >> tc;
while (tc--) {
int n;
cin >> n;
vector<int> arr(n);
vector<long long> prefi... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, m, x;
long long ans;
char c[2000][2000];
int u[2000][2000], d[2000][2000], l[2000][2000], r[2000][2000];
int main() {
scanf("%d%d", &n, &m);
for (int i = (0); i <= (n - 1); i++) scanf("%s", c[i]);
for (int i = (1); i <= (n - 2); i++) {
bool u = 1;
for (... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
for (long long i = 0; i < n; i++) cout << 1 << " ";
cout << endl;
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 2e9;
const int mod = 1e9 + 7;
const int N = 1234;
int n, m;
long long k;
int a[N][N], h[N * N], p[N * N];
long long b[N][N];
bool used[N][N];
vector<pair<int, int> > go = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
bool check(int x, int y) { return x >= 0 && x < n &... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, m, q;
int flag, tmp;
int ans, mxm, mnm;
long long max(long long a, long long b) {
if (a > b)
return a;
else
return b;
}
long long min(long long a, long long b) {
if (a < b)
return a;
else
return b;
}
long long gcd(long long a, long long b) {
... | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.