solution stringlengths 53 181k | difficulty int64 0 13 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
void qmax(int &x, int y) {
if (x < y) x = y;
}
void qmin(int &x, int y) {
if (x > y) x = y;
}
inline int read() {
char s;
int k = 0, base = 1;
while ((s = getchar()) != '-' && s != EOF && !(isdigit(s)))
;
if (s == EOF) exit(0);
if (s == '-') base = -1, s =... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n;
int x;
vector<pair<int, int> > vec;
void binser(int x1, int y1, int x2, int y2) {
if (x1 == x2) {
int kir = 1, kan = n;
while (kir < kan) {
int mid = (kir + kan) / 2;
printf("? %d %d %d %d\n", x1, 1, x2, mid);
fflush(stdout);
scanf("... | 7 |
#include <bits/stdc++.h>
using namespace std;
char tem1[] = "AbdHIMOopqTUVvWwXxY";
char tem2[] = "AdbHIMOoqpTUVvWwXxY";
int main() {
char s[1010];
scanf("%s", &s);
int len = strlen(s);
int i = 0, j = len - 1;
bool flag = 1;
while (i <= j) {
int k;
for (k = 0; k < strlen(tem1); k++) {
if (tem1[... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 300005;
map<int, int> l;
map<int, int> mp;
map<int, int> visited;
vector<int> adj[N];
long long power(long long a, long long b) {
long long ret = 1;
for (long long i = 0; i < b; i++) ret = (ret * a) % 998244353;
return ret;
}
int cur = 1;
void DFS(int s,... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, y;
cin >> n;
vector<int> a(n);
cin >> a[0];
y = a[0];
for (int i = 1; i < n; i++) {
cin >> a[i];
y = y & a[i];
}
cout << y << endl;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
char s[505][505];
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
scanf("%s", s[i] + 1);
}
int top = 1000, right = -1, buttom = -1, left = 1000;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (s[i][j] == '.') ... | 3 |
#include <bits/stdc++.h>
int main() {
int t, i, j, k, l, num1[11], a[20], num2[11], res[11], cc, ans;
char sub[10], s[300];
while (~scanf("%d", &t)) {
k = 0, cc = 0;
memset(sub, 0, sizeof(sub));
memset(a, 0, sizeof(a));
memset(num1, 0, sizeof(num1));
memset(num2, 0, sizeof(num2));
memset(r... | 3 |
#include <bits/stdc++.h>
using namespace std;
int even(int n) { return n % 2; }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin >> n >> m;
int e1 = 0, e2 = 0, o1 = 0, o2 = 0;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
if (even(x))
o1++;
else
e1++;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n1, i, l, j, k, n, m, ss1[100100], ss2[100030], ss3[100030];
char cc(char c1, char c2) {
char c = 'c';
if (c1 != 'a' && c2 != 'a')
c = 'a';
else if (c1 != 'b' && c2 != 'b')
c = 'b';
return c;
}
int main() {
string s1, s2, s3 = "";
cin >> l >> m;
ci... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv) {
unsigned long long n, m, k;
cin >> n >> m >> k;
int* a = new int[n];
int p = (n + 1) / 2;
unsigned long long t = 1000000;
for (int i = 0; i < n; i++) {
scanf("%d", a + i);
if (!(i % 2) && a[i] < t) t = a[i];
}
if (n ... | 5 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
int main() {
long long n;
cin >> n;
vector<long long> v;
long long mx = -1, mn = -1;
for (long long i = 1; i * i <= n; i++)
if (n % i == 0) {
v.push_back(i);
v.push_back(n / i);
}
sort((v).begin(), (... | 4 |
#include <bits/stdc++.h>
using namespace std;
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 power(long long B, long long P) {
if (P == 0) return 1;
long long X = power(... | 1 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> adia[1100];
int costsg;
int n, m;
int S, T, l;
int dist[1100];
vector<pair<pair<int, int>, pair<int, int>>> alone;
int cbin();
int main() {
ios_base ::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> l >> S >> T;
int a, b, c;
while (m--) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxjp = 18 + 1;
vector<complex<int> > A;
complex<int> m, p;
int n;
long long j;
int sum[maxjp];
void sym(const int l) { m = 2 * A[l] - m; }
int main() {
scanf("%d", &n);
cin >> j;
j %= (2 * n);
int x, y;
scanf("%d %d", &x, &y);
m = complex<int>(x, y);
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[1000 + 5], b[1000 + 5];
pair<int, int> tmp[1000 + 5];
vector<pair<int, int> > ans;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
tmp[i] = make_pair(a[i], i);
}
sort(tmp + 1, tmp + 1 + n);
for (int i = 1; i <=... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
long long l, r, m;
cin >> l >> r >> m;
if (m < l) {
cout << l << " " << l << " " << 2 * l - m << "\n";
} else {
for (long long i = l; i <= r; i++) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 9223372036854775807;
long long fastPow(long long b, long long e) {
long long r = 1;
while (e) {
if (e % 2 == 1) {
r *= b;
r %= mod;
}
b *= b;
b %= mod;
e /= 2;
}
return r;
}
long long pgcd(long long a, long long b) {
... | 5 |
#include<bits/stdc++.h>
#define FOR(i,a,b) for(register int i=(a);i<=(b);i++)
#define REP(i,a,b) for(register int i=(a);i>=(b);i--)
#define pb push_back
#define fi first
#define se second
#define hvie '\n'
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
typedef unsigned long long ull;
typedef doub... | 6 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("omit-frame-pointer")
#pragma GCC optimize("unroll-loops")
const int MAXINT = 2147483640;
const long long MAXLL = 9223372036854775800LL;
const long long MAXN = 1000000;
const double pi = 3.141592653589793238462643... | 6 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double EPS = 1e-6;
int cnt[200005];
int dist[200005];
int tmp[200005];
int n, m;
long long Run(int start, bool isRight) {
memmove(tmp, cnt, sizeof(tmp));
int now = start;
long long res = 0LL;
for (int k = 0; k < m; k++) {
if (... | 8 |
#include <bits/stdc++.h>
using namespace std;
int a[5555], n, k;
int cnt[1111111];
int seen[1111111];
int main() {
int i, j;
cin >> n >> k;
for (i = 1; i <= n; ++i) cin >> a[i];
for (i = 1; i <= n; ++i) {
for (j = i + 1; j <= n; ++j) {
int dd = a[i] - a[j];
if (dd < 0) dd = -dd;
cnt[dd]++;... | 8 |
#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... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1000 * 1000 * 1000;
const long long inf64 = 1ll * inf * inf;
const int mod = 1000 * 1000 + 3;
int sum(int a, int b) { return (a + b) % mod; }
int mul(int a, int b) { return (1ll * a * b) % mod; }
int binpow(int n, int p) {
if (p == 0) return 1;
int q = b... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
long long par[N];
long long vis[N];
long long binpow(long long a, long long b) {
long long res = 1;
while (b > 0) {
if (b & 1) res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
int parent(int x) {
while (par[x] != x) {
x = ... | 3 |
#include <bits/stdc++.h>
using namespace std;
bool p[501][5001];
struct state {
int d, sum;
string s;
};
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int i, j, k, m, n, d0, nd, mod, d, sum, nsum, sum0;
string s;
cin >> mod >> sum0;
queue<state> q;
q.push({0, 0, ""});
p[0][0] = 1;
while (... | 7 |
#include <bits/stdc++.h>
int n, m, t;
int Last[100002], Next[100002], End[100002];
long long w[100002];
int dp[3002][3002], s[100002];
long long v[3002][3002];
inline int Min(int p, int q) { return p < q ? p : q; }
void dfs0(int p, int f) {
s[p] = 1;
for (int i = Last[p]; i; i = Next[i])
if (End[i] != f) dfs0(E... | 8 |
#include <bits/stdc++.h>
char s1[52], s2[52];
int fr[26], ne[52], v[52], w[52], bs = 0;
bool f1[26][52][52], f2[26][52][52];
int z1[52][52], z2[52][52], dp[52][52];
int inf = 99999999;
void addb(int a, int b, int c) {
v[bs] = b;
w[bs] = c;
ne[bs] = fr[a];
fr[a] = bs++;
}
int main() {
int n, n1, n2;
scanf("%... | 7 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:5000000000")
const long long mod = 1000000007;
long long Inf = (long long)2e9;
long long LINF = (long long)1e18 + 1e17;
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int b, k;
cin >> b >> k;
vector<int> a(k);
... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
const double sn = 1e-6;
int n;
vector<int> ch[1000006];
int te[1000006];
int to[1000006];
bool v[1000006];
vector<int> res;
int c;
int tot;
int dfs(int i) {
if (v[i]) return to[i];
v[i] = true;
int sz = ch[i].size();
int sum = 0;
for (i... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 1e6 + 10;
const int mod = 1e9 + 7;
int n, k;
char s[maxn];
vector<int> reles[maxn];
int fa[maxn], sz[maxn];
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
void merge(int x, int y) {
x = find(x);
y = find(y);... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, m, k;
int a[N];
vector<int> v[N];
int main() {
cin >> n >> k >> m;
for (int i = 1; i <= n; ++i) cin >> a[i];
for (int i = 1; i <= n; ++i) {
v[a[i] % m].push_back(a[i]);
}
for (int i = 0; i < m; ++i) {
if (v[i].size() >= k) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, cnt, tot, dfsclk, pos[400005], fst[400005], pnt[400005 << 1],
len[400005 << 1], nxt[400005 << 1], a[400005], b[400005], c[400005],
fa[400005];
long long f[400005], u1[400005], u2[400005], v1[400005], v2[400005], ans;
bool ok[400005];
void add(int x, int y, in... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double a, b, c;
cin >> a >> b >> c;
if (a == 0) {
if (b == 0) {
if (c == 0)
cout << -1;
else
cout << 0;
} else
cout << fixed << setprecision(5) << "1\n" << -c / b;
} else {
double denta = b * b - 4 * a * c;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 10505;
int n, Q, id[55][205], S, T;
int head[N], tot = 1, nd;
int dis[N], q[N], ans;
struct edge {
int to, next, f;
} e[N * 20];
void add(int x, int y, int f) {
e[++tot] = (edge){y, head[x], f};
head[x] = tot;
e[++tot] = (edge){x, head[y], 0};
head[y... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, j, k, a[100008], count, maxi = 0, maxk, si;
cin >> n;
for (i = 0; i < n; i++) a[i] = i + 1;
maxk = 100009;
maxi = 1;
for (i = 1; i <= n; i++) {
si = 0;
if (n % i) si = 1;
k = n / i + i + si;
if (k < maxk) {
maxk = k;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 200000;
int na;
long long want;
int a[MAXN];
int b[MAXN], nb;
bool ok(long long x) {
if (x == 0) {
int mx = a[0];
for (int i = (1); i < (na); ++i)
if (a[i] > mx) ... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long int ans1[600005];
long long int ans2[600005];
int minsufa[600005];
int maxprefb[600005];
int res[600005];
int main() {
int(n), (w);
scanf("%d%d", &(n), &(w));
;
vector<pair<int, int> > v1;
vector<pair<pair<int, int>, int> > v2;
for (int i = (0); i < (n... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const long long ooo = 9223372036854775807ll;
const int _cnt = 1000 * 1000 + 7;
const int _p = 1000 * 1000 * 1000 + 7;
const int N = 200105;
const double PI = acos(-1.0);
const double eps = 1e-6;
int o(int x) { return x % _p; }
int gcd(int a, int b... | 7 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
int main(int argc, char* argv[]) {
ios::sync_with_stdio(0);
cin.tie(0);
int n, S;
cin >> n >> S;
vector<ll> item(n);
for (int i = 0; i < n; i++) cin >> item[i];
int lo = 1, hi = n;
whil... | 3 |
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[100005];
int size[100005];
int parent[100005];
int ans = 0;
int bfs(int node, int p) {
size[node] = 1;
parent[node] = p;
for (int i = 0; i < adj[node].size(); i++) {
if (adj[node][i] != p) {
int curr = bfs(adj[node][i], node);
if (curr ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const unsigned long long mod = 1e9 + 7;
const bool debugger1 = 0;
const bool debugger2 = 0;
const bool debugger3 = 1;
const bool debugger4 = 1;
const bool debugger5 = 1;
int n, ans = 0;
std::vector<int> order;
vector<pair<int, int> > pary;
int tab[205];
int main() {
scanf... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long sum, a[1005];
int n;
while (scanf("%d", &n) != EOF) {
sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i] + (a[i] - 1) * i;
}
cout << sum << endl;
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T sqr(T x) {
return x * x;
}
long double pi = 3.1415926535897932384626433832795;
const int N = 2e5 + 10, lg = 31, MAXN = 1111;
long long mod = 1e9 + 7;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long _gcd(long long a,... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, a[10005], dp[10005][2005];
signed main() {
int Test;
scanf("%d", &Test);
while (Test--) {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
int maxX = 0;
for (int i = 1; i <= n; i++) maxX = max(maxX, a[i]);
for (int i = 0; i ... | 7 |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")
using namespace std;
long long ask(long long c, long long d) {
long long ret;... | 6 |
#include <bits/stdc++.h>
using namespace std;
int ans[1000], b[1000], suma[1000], sumb[1000];
int main() {
int i, n, d;
cin >> n;
for (i = 1; i < n; i++) {
cin >> d;
if (i == 0)
suma[i] = d;
else
suma[i] = suma[i - 1] + d;
}
for (i = 1; i < n; i++) {
cin >> d;
if (i == 0)
... | 2 |
#include <bits/stdc++.h>
const int MOD = 998244353;
const int INF = 1e9 + 7;
int as[1005] = {-INF};
int N, K;
int dp[1005][1005] = {{1}};
int solve(int crit) {
int j = 0;
for (int i = 1; i <= N; i++) {
for (int k = 0; k <= K; k++) {
dp[i][k] = dp[i - 1][k];
}
while (as[j + 1] <= as[i] - crit) j++;... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
int arr[200005];
int cnt[200005];
int c[200005];
int main() {
ios_base::sync_with_stdio(0);
int n;
while (cin >> n) {
memset(cnt, 0, sizeof(cnt));
memset(c, 0, sizeof(c));
for (int i = 0; i < n; ++i) {
... | 5 |
#include <bits/stdc++.h>
int main() {
int n, w;
scanf("%d", &n);
if (n == 20) {
w = 15;
}
if (n == 11) {
w = 4;
}
if (n == 21) w = 4;
if (n < 20 && n > 10 && n != 11) {
w = 4;
}
if (n <= 10 || n > 21) w = 0;
printf("%d", w);
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long int n, q;
cin >> n >> q;
vector<long long int> a(n);
long long int o, m;
o = m = 0;
for (long long int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] == 1)
o++;
else
m++;
}
m = min(o, m);
for (long long int i = ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 55;
int n;
int A[N][N], F[N][N][N][N];
int dp(int x, int y, int u, int v) {
if (x > u || y > v || x > n || y > n || u > n || v > n || x < 1 || y < 1 ||
u < 1 || v < 1)
return int(1e8);
if (F[x][y][u][v] > -1) return F[x][y][u][v];
int ans = max... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
const long long MOD = 998244353;
int n, m;
long long cr[MAXN];
long long a[MAXN], b[MAXN];
void read_input() {
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> cr[i];
}
for (int i = 0; i < m; i++) {
cin >> a[i] >> b[i];
}
}
lon... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int l, r, q, i;
cin >> q;
while (q--) {
int sum = 0;
cin >> l >> r;
if (r % 2 == 0) {
if (l % 2 == 0)
cout << (l + r) / 2 << endl;
else
cout << (r - l + 1) / 2 << endl;
} else {
if (l % 2 == 0)
cou... | 0 |
#include <bits/stdc++.h>
using namespace std;
class UnionFind {
public:
vector<int> p, rank, setSize;
int numSets;
void build(int N) {
setSize.assign(N, 1);
numSets = N;
rank.assign(N, 0);
p.assign(N, 0);
for (int i = 0; i < N; i++) p[i] = i;
}
int findSet(int i) { return (p[i] == i) ? i ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long c = 220000;
long long x, y, n, a[c];
int main() {
ios_base::sync_with_stdio(0);
cin >> n >> x >> y;
for (int i = 1; i < n; i++) a[i] = 1;
a[n] = y - n + 1;
long long sum = n - 1 + a[n] * a[n];
if (a[n] > 0 && sum >= x)
for (int i = 1; i <= n;... | 3 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
namespace io {
const int SIZE = (1 << 21) + 1;
char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1;
inline char getc() {
return (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, SIZE, stdin),
(iS == iT ? EOF : *i... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, cost_white, cost_black, total_cost = 0;
cin >> n >> cost_white >> cost_black;
int arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
for (int i = 0; i < n / 2.0; i++) {
if (arr[i] == 2 && arr[n - i - 1] == 2) {
total_cost +=... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long get(long long n, long long k) {
if (k == 1) return 0;
if (k == 2) {
return n * (n - 1) / 2;
}
if (k == 3) {
return n * (n - 1) * (n - 2) / 6 * 2;
}
if (k == 4) {
return (long long)n * (n - 1) * (n - 2) * (n - 3) / 24 * (6 + 3);
}
return... | 4 |
#include <bits/stdc++.h>
using namespace std;
int N, M;
vector<vector<pair<int, int> > > adj;
int dp[105][105][27][3];
int dfs(int v, int u, int last, int turn) {
if (dp[v][u][last][turn]) return dp[v][u][last][turn];
int cur = ((turn == 1) ? v : u);
dp[v][u][last][turn] = 3 - turn;
for (pair<int, int> nei : ad... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int M = 1010010;
long long sum[M];
set<pair<int, int> > S;
vector<pair<int, pair<int, int> > > ev;
int n, w;
void inc(int l, int r, int val) {
l = max(l, 0);
r = min(r, w - 1);
sum[l] += val;
sum[r + 1] -= val;
}
int main() {
scanf("%d%d", &n, &w);
while (... | 7 |
#include <bits/stdc++.h>
using namespace std;
struct recta {
int x1, x2;
int y1, y2;
} a[6];
int n;
int main() {
scanf("%d", &n);
for (int p = (0); p <= (n - 1); p += (1))
scanf("%d%d%d%d", &a[p].x1, &a[p].y1, &a[p].x2, &a[p].y2);
int lwx = 1e6, lwy = 1e6;
int gtx = -1, gty = -1, s = 0;
for (int p = (... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T abs(T x) {
return x > 0 ? x : -x;
}
long long n;
long long k;
long long gsum;
long long mod = 1000000000 + 7;
int col[1000500];
long long cc[1000500];
long long tt[1000500];
long long fact[200500];
long long obr[200500];
vector<int> del[1000500];
int ... | 8 |
#include <bits/stdc++.h>
using namespace std;
void _print(long long t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(long double t) { cerr << t; }
void _print(double t) { cerr << t; }
void _print(unsigned long long t) { cerr << t; }
template <class T, class V>
void _... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, m, a, b, c, d, i, j, h, len, x, y, xi[105], resp;
bool ok;
int main() {
scanf("%d %d", &n, &m);
ok = true;
for ((i) = 0; (i) < (m); (i)++) {
scanf("%d %d", &a, &b);
for (j = a; j <= b; j++) {
xi[j]++;
}
}
for (i = 1; i <= n; i++) {
if ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MN = 100111;
int sum[2][MN], a[MN], n;
int get(int t) {
int i = 0;
int win[2], lastwin = -1;
win[0] = win[1] = 0;
while (i < n) {
if (sum[0][n] - sum[0][i] < t && sum[1][n] - sum[1][i] < t) return -1;
int l = i + 1, r = n, res = n;
while (l <= ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 5;
const long long INF = 1e9 + 9;
const long long MOD = 1000000007;
int main() {
string s;
int t;
cin >> t;
vector<string> ans;
int n;
string r;
while (t--) {
ans.clear();
cin >> s;
if (s == "::") {
cout << "0000:0000:00... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, const char* argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, k;
cin >> n >> k;
vector<int> gifts(n);
map<int, int> counter;
int a;
for (int i = 0; i < n; i++) {
cin >> a;
gifts[i] = a;
counter[a % k... | 2 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-7;
int a[200000];
int n;
bool check(double x) {
double bound = a[0] + x;
for (int i = 1, num = 1; i < n; i++)
if (a[i] > bound) {
bound = a[i] + x;
num++;
if (num > 3) return 0;
}
return 1;
}
int main() {
scanf("%d", &... | 5 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<doub... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int d[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int a[240];
int main(void) {
int n;
int i, j, k;
bool f, g;
scanf("%d", &n);
for (i = 0; i < n; i++) scanf("%d", &a[i]);
for (i = 0; i < 12; i++) {
for (j = 0, f = true, g = false; j < n && ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long MAX_N = 100 * 1000 + 24, INF = (1 << 30);
long long n;
int sz[MAX_N], ans[MAX_N];
bool mark[MAX_N];
vector<int> G[MAX_N];
void prep(int v, int par = -1) {
sz[v] = 1;
for (int i = 0; i < G[v].size(); i++) {
int u = G[v][i];
if (u != par and mark[u... | 6 |
#include <bits/stdc++.h>
using namespace std;
int ar[2000000 + 9], pr[2000000 + 9], par[2][2000000 + 9];
int main() {
int i, j = 0, k, l, n, m = 0, tot = 0, temp, siz, flag = 0, ans = 0, test,
curr, ind, x, q, now_xor, f, s, val, prev1, prev2, pos;
char ch;
cin >> n;
for (i = 0; i <= n; i++) {
cin ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0), cout.precision(15);
int q;
cin >> q;
while (q--) {
long long n, m;
cin >> n >> m;
long long ar[10];
ar[0] = 0;
for (int i = 1; i < 10; ++i) {
ar[i] = m * i % 10;
ar... | 2 |
#include <bits/stdc++.h>
using namespace std;
string p = "AEIOUY";
bool isv(char ch) {
for (int i = 0; i < 6; ++i)
if (p[i] == ch) return true;
return false;
}
int main(int argc, char const *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s;
cin >> s;
int n = s.size();
int k = -1;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
bool alpa[30];
int main() {
unsigned int a, b, l, r;
cin >> a >> b >> l >> r;
vector<char> arr;
unsigned int lmod = (l - 1) % (a + b);
unsigned int len = r - l + 1;
l = (l - 1) % (a + b);
if (a <= b) {
for (int i = 0; i < a; i++) {
arr.push_back('a' ... | 7 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
long long n, l, r, t = 1e12;
cin >> n;
long long a[n], m = 1e12;
vector<long long> A;
for (long long i = 0; i < n; i++) {
cin >> a[i];
if (a[i] < m) m = a[i];
}
for (lon... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char **argv) {
list<int> vec1;
list<int> vec2;
int n;
cin >> n;
int auxn = n;
int num;
for (int i = 0; i < n; i++) {
cin >> num;
vec1.push_back(num);
}
vec2 = vec1;
vec2.sort();
list<int> aux;
int auxnum;
int cont = 0;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long MOD = 998244353;
const long long N = 1e6 + 10;
long long a[N], fen[N];
void add(long long i, long long val) {
while (i < N) {
fen[i] += val;
i += (i & (-i));
}
}
long long sum(long long i) {
long long s = 0;
while (i > 0) {
s += fen[i];
i -... | 5 |
#include <bits/stdc++.h>
using namespace std;
int af[310];
int main() {
int m, n;
cin >> m >> n;
for (int i = 0; i < n; i++) {
int t;
cin >> t;
int tt = t % m;
af[tt]++;
if (af[tt] > 1) {
cout << i + 1 << endl;
return 0;
}
}
cout << -1 << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int dp[3005][2];
int cst[3][3005];
int main() {
int n;
scanf("%d", &n);
for (int j = 0; j < 3; j++)
for (int i = 0; i < n; i++) scanf("%d", &cst[j][i]);
dp[0][0] = -1e8;
dp[0][1] = 0;
for (int i = 1; i <= n; i++) {
dp[i][0] = max(dp[i - 1][0] + cst[1][i ... | 5 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long s = 0, w = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') w = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
return s * w;
}
const long long MAXN = 2e... | 9 |
#include <bits/stdc++.h>
using namespace std;
string s;
void solve() {
cin >> s;
int lowest = 1e9;
for (int i = 0; i < s.size(); i++) {
lowest = min(lowest, (int)s[i]);
if (s[i] > lowest)
cout << "Ann\n";
else
cout << "Mike\n";
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.t... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
map<string, int> name;
int get_id(string s) { return name[s] ? name[s] : name[s] = name.size(); }
const int N = 45;
bitset<100100> bs[N];
bool cmp(int a, int b) { return bs[a].count() < bs[b].count(); }
int main() {
name.clear();
cin >> n >> m;
int op;
int... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, d;
cin >> n >> d;
vector<int> v(n);
for (int i = 0; i < n; i++) cin >> v[i];
int amount = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i != j and v[i] - v[j] <= d and v[j] - v[i] <= d) amount++;
}
}
cou... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
const int M = 1000000007;
long long k, a[N];
long long mpow(long long a, long long b) {
if (b == 0) {
return 1;
} else if (b % 2 == 0) {
long long q = mpow(a, b / 2);
return q * q % M;
} else {
return a * mpow(a, b - 1) % M;
}
}... | 6 |
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
int a, b, c, d;
int dp[102][102][202];
int val(int nr) { return nr + 100; }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> a >> b >> c >> d;
dp[0][0][val(0)] = 1;
for (int i = 0; i <= a; ++i)
f... | 4 |
#include <bits/stdc++.h>
using namespace std;
void program();
int main(){ program(); ios_base::sync_with_stdio(false); cin.tie(NULL);}
#define int long long
#define endl "\n"
template <typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
for (int i = 0; i < v.size(); ++i) {
if (i == 0) {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T sqr(const T &a) {
return a * a;
}
const long double EPS = 1e-9;
const long double PI = 2 * acos(0.0);
const int N = 5100;
vector<int> g[N];
inline void SetInVector(vector<int> &v, int pos, int val) {
while ((int)v.size() <= pos) v.push_back(1... | 8 |
#include <bits/stdc++.h>
int n, k;
int a[100009];
using namespace std;
int main() {
while (cin >> n >> k) {
int i;
if (k == 0) {
for (i = 1; i < n; i++) cout << i << " ";
cout << n << endl;
} else if (k == n - 1) {
for (i = n; i > 1; i--) cout << i << " ";
cout << 1 << endl;
} ... | 1 |
#include <bits/stdc++.h>
using namespace std;
bool isFib(int x, vector<int>& fib) {
for (int i = 0; i < fib.size() - 1; i++) {
if (fib.at(i) == x) return true;
}
return false;
}
int main() {
vector<int> fib;
long long int prev = 1;
for (long long int i = 0; i < 1000000000;) {
fib.push_back(i);
i... | 0 |
#include <bits/stdc++.h>
using namespace std;
int total;
int ps[32];
int N;
int num[32];
int rs[32];
map<int, int> table;
int board[8][8];
const int INF = 1000000000;
void go(int x, int y, int g) {
if (x == N) throw g;
if (x == N - 1) {
int v = 0;
for (int i = 0; i < N - 1; i++) v += board[i][y];
int p ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18 + 1;
long long n, h, ans;
long long cal(long long x) {
long long need = x * (x + 1) / 2;
long long remain = n - need;
if (remain % x == 0)
return (remain / x + x);
else
return (remain / x + x + 1);
}
int main() {
ios_base::sync_w... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long power(int a, int p) {
if (p == 0) return 1 % mod;
if (p % 2 == 1) return (a * power(a, p - 1)) % mod;
long long ret = power(a, p / 2);
return (ret * ret) % mod;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n];
for (int i = 1; i <= n; i++) cin >> a[i];
vector<int> g[n + 1];
int dis[n + 1];
queue<int> e;
queue<int> o;
int vis[n + 1];
for (int i = 1; i <= n; i++) {
vis[i] = 0;
dis[i] = -1;
if (i - a[i] >= 1) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
vector<long long int> a(n);
vector<long long int> mp(n + 1, 0);
for (int i = 0; i < n; i++) {
cin >> a[i];
mp[a[i]]++;
}
vector<long long int> ans(n + 1);
priority_queue<pair<long long, long long>> pq;
long long cost... | 4 |
#include <bits/stdc++.h>
using namespace std;
vector<int> v[3 * 10000];
bool visited[1000001];
long long dp[1000001];
long long arr[1025][1025];
long long cnt = 0;
int n;
void dfs(int sv) {
if ((int)pow(2, n) <= sv && sv <= (int)pow(2, n + 1) - 1) return;
dfs(2 * sv);
dfs(2 * sv + 1);
long long a = dp[2 * sv + ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[110];
int main() {
int count = 0;
while (cin >> n) {
count = 0;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int j = 2; j < n; j++) {
if (a[j] == 0) {
if (a[j - 1] == 1 && a[j + 1] == 1) {
a[j + 1] = 0;
count+... | 1 |
#include <bits/stdc++.h>
using namespace std;
int judge(char a[]) {
if (strcmp(a, "monday") == 0) return 1;
if (strcmp(a, "tuesday") == 0) return 2;
if (strcmp(a, "wednesday") == 0) return 3;
if (strcmp(a, "thursday") == 0) return 4;
if (strcmp(a, "friday") == 0) return 5;
if (strcmp(a, "saturday") == 0) re... | 1 |
#include <bits/stdc++.h>
using namespace std;
int pos[100005];
int main() {
int n;
scanf("%d", &n);
memset(pos, -1, sizeof(pos));
for (int i = 1; i <= n; i++) {
int x, y, ans = 0;
scanf("%d %d", &x, &y);
for (int j = 1; j * j <= x; j++) {
if (x % j == 0) {
if (pos[j] == -1 || pos[j] < ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const int N = 3e5 + 5, K = 30;
int tam[N] = {1}, g[N][K], _g[N][K];
vector<int> v;
int res[N];
pair<int, int> merge(int a, int b) {
if (!a) return pair<int, int>(b, 0);
if (!b) return pair<int, int>(a, 0);
int ... | 8 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.