solution stringlengths 53 181k | difficulty int64 0 13 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
void canhazfast() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
template <typename T>
T gcd(T a, T b) {
return b ? gcd(b, a % b) : a;
}
template <typename T>
T extgcd(T a, T b, T &x, T &y) {
T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
while (b... | 8 |
#include <bits/stdc++.h>
using namespace std;
int a[100005];
int main() {
int i;
for (i = 1; i <= 100000; i++) a[i] = -1;
int n, x, k;
scanf("%d", &n);
int valid = 1;
for (i = 0; i < n; i++) {
scanf("%d%d", &x, &k);
if (a[k] < x - 1)
valid = 0;
else
a[k] = max(a[k], x);
}
if (val... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f3f;
const int maxn = 210;
int d[maxn][maxn], di[maxn][maxn];
int rk[maxn][maxn];
int main() {
int n, m, a, b, c;
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
d[i][i] = 0;
di[i][i] = 0;
for (int j = i + 1; j <= n; j++) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
queue<int> q;
long long ans[222222];
int T[222222], D[222222];
int main(int argc, char *argv[]) {
int N, B;
scanf("%d%d", &N, &B);
for (int i = 0; i < (N); i++) scanf("%d%d", T + i, D + i);
int pos = 0;
long long last_t = 0;
while (pos != N || !q.empty()) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:16000000")
#pragma warning(disable : 4996)
const int inf = 1 << 25;
const double eps = 1e-9;
map<pair<int, int>, vector<int> > Y;
const int MAXN = 101000;
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }
int revMemo[MAXN];
int rev(int... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[500 + 10];
int c[50];
int main() {
scanf("%d", &n);
int k = 0;
if (n == 0) {
printf("%c", 'a');
return 0;
}
for (int i = 1; (i + 1) * i / 2 <= n; i++) {
a[i] = (i + 1) * i / 2;
k = i;
}
int j = k;
int w = 0;
while (j) {
if ... | 4 |
#include <bits/stdc++.h>
using namespace std;
string s;
int d, q, mx, a[(int)1e5 + 4];
int main() {
cin >> s >> d;
for (int i = 0; i < d; i++) {
scanf("%d", &q);
a[q - 1]++;
}
int y = s.size();
for (int i = 0; i < y / 2; i++) {
if (i != 0) a[i] += a[i - 1];
if (a[i] % 2 == 1) swap(s[i], s[y - ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, len;
long long sum, result;
struct xvlie {
long long s, h;
string str;
} ar[100005];
bool cmp(const xvlie &a, const xvlie &b) { return a.s * b.h > a.h * b.s; }
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
cin >> ar[i].str;
len = ar[i].... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long N = 2e5 + 10;
long long n;
long long a[N];
vector<long long> g[N];
long long col[N];
long long dp[N][2];
long long res = 0;
void dfs(long long node, long long par = -1, long long cc = 0) {
col[node] = cc;
dp[node][0] = 1;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
int T, n, m, num[maxn];
vector<int> now[maxn];
void solve() {
scanf("%d%d", &n, &m);
int cnt = 0;
for (int i = 1; i <= n; i++) now[i].clear(), num[i] = 0;
for (int i = 1; i <= m; i++) {
int x, y;
scanf("%d%d", &x, &y);
now[y].p... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
char c[MAXN];
int g[MAXN][26], col[MAXN], is_f[MAXN];
int used[3];
void dfs(int s) {
int i, to, fl[4];
for (i = 0; i < 4; i++) {
fl[i] = 0;
}
for (i = 0; i < 26; i++) {
to = g[s][i];
if (to) {
dfs(to);
fl[col[to]] = ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
scanf("%d%d", &n, &m);
int i = -1;
const int N = 101;
int cl[N], ja[N], jan = 0, jd[N], jdn = 0;
char buf[18];
while (++i < n) {
scanf("%s%d", buf, ja + jan);
if (buf[0] == 'A')
++jan;
else
jd[jdn++] = ja[jan];
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, b = 0;
cin >> n;
int arr[n];
set<int> s;
for (int i = 0; i < n; i++) {
cin >> arr[i];
if (arr[i] > n) {
b++;
} else
s.insert(arr[i]);
}
cout << b + ((n - b) - s.size()) << endl;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int n, P[100006], S[100006], fst[100006], t, u, v, q, nr, NRA[100006];
bool R[100006];
struct edge {
int nod;
bool p, s;
};
vector<edge> V[100006];
vector<pair<int, int> > E;
pair<int, int> rmq[21][100006 * 2];
void dfs(int nod, int nr) {
NRA[nod] = nr;
for (auto it... | 8 |
#include <bits/stdc++.h>
using namespace std;
int i, j, n, m, k, t, w;
int ans;
string s[50];
int p[50];
void dfs(int x, int y, string ss) {
if (x == n) {
if (y < p[1]) return;
for (i = 1; i <= m; i++) {
int cnt = 0;
for (j = 0; j <= n - 1; j++) cnt += (ss[j] == s[i][j]);
if (cnt != p[i]) re... | 7 |
#include <bits/stdc++.h>
std::string to_base_26(int num) {
char alphabet[] = {'Z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q',
'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y'};
std::string s = "";
bool sub = false;
while (num > 0) {
s... | 4 |
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
void solve(int num, std::istream& in, std::ostream& out) {
int n, k;
in >> n >> k;
vector<long long> arr(n);
for (int i = 0; i < n; i++) {
in >> arr[i];
}
sort(arr.begin(), arr.end());
long long mx = arr.back();
... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long int euler_totient(long long int n) {
long long int result = n;
for (long long int p = 2; p * p <= n; ++p) {
if (n % p == 0) {
while (n % p == 0) n /= p;
result -= result / p;
}
}
if (n > 1) result -= result / n;
return result;
}
vecto... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, long long int y) {
long long int m = 1000000007;
long long int ans = 1;
while (y > 0) {
if (y & 1) ans = (ans * x) % m;
x = (x * x) % m;
y >>= 1;
}
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
ci... | 0 |
#include <bits/stdc++.h>
long long max(long long a, long long b) { return a > b ? a : b; }
long long min(long long a, long long b) { return a < b ? a : b; }
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> t1(n);
vector<int> t2(m);
for (int i... | 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pi = pair<int, int>;
using pii = pair<int, pi>;
const int MAXN = 125;
using bst = bitset<MAXN>;
template <typename T>
T read() {
T tmp;
cin >> tmp;
return tmp;
}
ll ans = 0, mod = 1000000007;
int n, m, k;
int... | 10 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-11;
const int inf = 0x7FFFFFFF;
template <class T>
inline void checkmin(T &a, T b) {
if (b < a) a = b;
}
template <class T>
inline void checkmax(T &a, T b) {
if (b > a) a = b;
}
template <class T>
inline T sqr(T x) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> v;
for (int i = 0, temp; i < n; i++) {
cin >> temp;
v.push_back(temp);
}
bool all1 = true;
for (int x : v)
if (x != 1) all1 = false;
if (all1... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 110;
int X, Y;
int cnt = 0;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
bool edge[maxn][maxn][4];
bool used[maxn][maxn];
void dfs(int x, int y) {
if (x < 0 || x >= X || y < 0 || y >= Y || used[x][y]) return;
used[x][y] = 1;
cnt++;
for (int i... | 6 |
#include <bits/stdc++.h>
using namespace std;
inline int in() {
int x;
scanf("%d", &x);
return x;
}
const int N = 1e6 + 7;
vector<int> v[N];
int out[N], mn[N], dis[N], inf, is[N], Tavas[N];
int32_t main() {
int n = in(), m = in();
for (int i = 0; i < m; i++) {
int x = in(), y = in();
out[x]++;
v[y... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1005, INF = (1e9);
int cnt[MAX], v, e, n, k, dis[MAX][MAX], ty[MAX];
namespace hc {
bool visited[MAX];
vector<int> adj[MAX];
int n, L[MAX], R[MAX], Q[MAX], len[MAX], dis[MAX], parent[MAX];
inline void init(int nodes) {
n = nodes, memset(len, 0, sizeof(len)... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, n;
vector<int> vv;
cin >> n;
int a[2 * n];
for (i = 0; i < 2 * n; i++) {
cin >> a[i];
}
sort(a, a + (2 * n));
if (a[n] > a[n - 1])
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int dfn[2005], low[2005], fg[2005], cnt, n, head[2005], cmp, te, num;
int sta[2005];
struct st {
int to, next;
} qe[4000005];
void addedge(int u, int v) {
cmp++;
qe[cmp].to = v;
qe[cmp].next = head[u];
head[u] = cmp;
}
void tarjan(int u) {
te++;
low[u] = dfn[u... | 7 |
#include <bits/stdc++.h>
using namespace std;
void fast() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int main() {
fast();
long long int n, t, c;
long long int si = 0;
cin >> n >> t >> c;
long long int b[n];
for (long long int i = 0; i < n; i++) {
b[i] = 0;
}
long long int a[n];... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
long double a, b, c, p1, p2;
long long int b1;
cin >> t;
while (t--) {
cin >> a >> b >> c;
p1 = a;
p2 = c / b;
if (p1 > p2) {
if (a >= c)
cout << "-1 ";
else
cout << "1 ";
b1 = b;
cout << ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
while (cin >> n) {
int a[100001];
int f = 0;
int l = 0;
int t = 0;
int min = 1000000001;
for (int i = 0; i < n; ++i) {
cin >> a[i];
if (a[i] < min) {
t = i + 1;
min = a[i];
}
}
int tim... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long int maxn = 1e6 + 5;
const long long int modn = 1e9 + 7;
const double pi = acos(-1);
void solve() {
long long int n;
cin >> n;
vector<long long int> a(n);
for (long long int i = 0; i < n; i++) cin >> a[i];
for (long long int i = 1; i < n; i++) {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
string s;
cin >> s;
long long i = 0;
float l = 0, r = 0;
long long pivot = 0;
while (pivot < s.size() && s[pivot] != '^') pivot++;
while (i < s.size() && s[i] != '^') {
if (s[i] >= '1' && s[i] <= '9') l += (s[i] - '0') * abs(i - pivot);
... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<int> g[200100];
int n, pr[200100], dpth[200100];
set<pair<int, int> > q;
int ans = 0l;
void dfs(int v, int deep, int p) {
pr[v] = p;
dpth[v] = deep;
if (deep > 2) q.insert({deep, v});
for (int i = 0; i < g[v].size(); i++) {
int to = g[v][i];
if (to !=... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
if (c == 0 && a == b) {
printf("YES\n");
return 0;
}
if (c == 0) {
printf("NO\n");
return 0;
}
if ((b - a) % c == 0 && (b - a) / c >= 0) {
printf("YES\n");
return 0;
}
printf("NO\n");
... | 1 |
#include <bits/stdc++.h>
int x[101000], y[101000], c[101000];
long long anss[101000];
int tempa[101000], tempb[101000], tempc[101000];
int l[101000][10];
int in[101000];
int he[2][101000], wh[2][101000];
int nhh[2];
int zhh[2] = {1, -1};
void mergesort(int *a, int *b, int *c, int n1, int n2);
int ya(int k) {
int z;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int low_bit(int now) { return now & (-now); }
long long h(int l, int r) {
if (l & (r - low_bit(r))) return 0;
long long res = 1;
bool OK = 1;
while (OK) {
if (r & 1) break;
if (l & 1)
;
else
res <<= 1;
l >>= 1,... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
vector<int> xx[N], yy[N], v[N], u[N];
int x1[N], x2[N], y2[N], y[N];
int ret[N], tree[N * 2], c, L, R;
void update(int pos, int l, int r, int v) {
if (c < l || r < c) return;
if (l == r && l == c) {
tree[pos] = v;
return;
}
int mid = (... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 300010;
int cnt = 0, n, ques, mark = 0, ans = 0;
queue<int> q[N];
bool vis[N];
int main() {
scanf("%d%d", &n, &ques);
memset(vis, false, sizeof(vis));
while (ques--) {
int op, x;
scanf("%d%d", &op, &x);
if (op == 1) {
q[x].push(++cnt);
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const int MX = 2000000 + 10;
void solve() {
int n, k;
cin >> n >> k;
if (k >= n)
cout << k - n << '\n';
else
cout << (n % 2 == k % 2 ? 0 : 1) << '\n';
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 1e9 + 5;
const double eps = 1e-7;
const double PI = acos(-1.0);
inline void debug_vi(vector<int> a) {
for (long long i = (long long)(0); i < (long long)(a.size()); i++)
cout << a[i] << " ";
}
inline void debug_vl... | 6 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > v;
int n, x[1002], y[1002], r[1002];
int xa, xb, ya, yb;
int main() {
scanf("%d %d %d %d", &xa, &ya, &xb, &yb);
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d %d %d", &x[i], &y[i], &r[i]);
}
for (int i = min(xa, xb); i <= max... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long dp[100005];
long long c[100005];
int main() {
int n;
cin >> n;
memset(c, 0, sizeof(c));
int maxx = 0;
int aux;
for (int i = 0; i < n; i++) {
cin >> aux;
if (aux > maxx) maxx = aux;
c[aux]++;
}
dp[0] = 0;
dp[1] = c[1];
for (int i = 2... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
int n, m;
vector<pair<int, int> > g[60], v, ans;
vector<int> pass;
bool vis[60], vise[2510];
void dfs(int pos, int stp, int rt) {
vis[pos] = true;
pass.push_back(pos);
for (int i = 0; i < g[pos].size(); i++) {
if (vise[g[pos][i].seco... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e6 + 7;
int p[MAX_N][2];
int dp[MAX_N][2][2];
pair<int, int> f[MAX_N][2][2];
bool g[MAX_N][2][2];
vector<int> ans;
int T, n;
void solve(int s, int k) {
for (int i = n; i; --i) {
ans.push_back(p[i][s]);
pair<int, int> p = f[i][s][k];
s = p.fi... | 10 |
#include <bits/stdc++.h>
using namespace std;
struct L {
int u, v;
int val;
bool operator<(const L &a) const { return a.val < val; }
} l[1500010];
int n, m;
struct node *NIL;
struct node {
node *ch[2], *fa;
int val;
int changed;
bool rev;
bool Dir() { return this == fa->ch[1]; }
bool Isroot() {
re... | 9 |
#include <bits/stdc++.h>
using namespace std;
using ull = uint64_t;
using ll = int64_t;
using ld = long double;
const int N = 200228;
int n;
struct Val {
int fen[N];
set<int> s;
void ad(int x) {
s.insert(x);
for (int i = x; i < n; i |= (i + 1)) {
++fen[i];
}
}
void er(int x) {
s.erase(x)... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1010;
int N;
int X[MAXN][5];
int dot(int a, int b, int c) {
int d = 0;
for (int i = 0; i < 5; i++) {
d += (X[b][i] - X[a][i]) * (X[c][i] - X[a][i]);
}
return d;
}
int main() {
scanf("%d", &N);
for (int i = 0; i < N; i++) {
for (int j = 0... | 4 |
#include <bits/stdc++.h>
using namespace std;
typedef struct alphabet {
char ch;
int freq;
} alpha;
int main() {
int n, j, i, min_index = 0, min = 266, flag = 1;
string s;
cin >> n >> s;
if (n % 4 != 0) {
cout << "===" << endl;
return 0;
}
alpha u[4];
u[0].ch = 'A';
u[1].ch = 'C';
u[2].ch ... | 0 |
#include <bits/stdc++.h>
int main() {
int N, i, bir = 0, iki = 0, x, ans = 0;
scanf("%d", &N);
for (i = 0; i < N; i++) {
scanf("%d", &x);
if (x == 1)
bir++;
else
iki++;
}
ans += bir < iki ? bir : iki;
bir -= ans;
iki -= ans;
ans += (bir / 3);
printf("%d", ans);
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 107;
string st[maxn];
int n;
bool d[maxn] = {}, inv[maxn] = {}, is_c[maxn] = {};
vector<pair<int, int> > adj[maxn];
void dfs(int u, int pos) {
d[u] = 1;
for (int i = pos; i < (int)st[u].size(); ++i) cout << st[u][i];
for (auto v : adj[u])
if (!d[v... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, ans;
ios::sync_with_stdio(false);
;
cin >> s;
char now = 'a' - 1;
reverse(s.begin(), s.end());
for (int i = 0; i < s.length(); i++) {
if (s[i] >= now) {
now = s[i];
ans += s[i];
}
}
reverse(ans.begin(), ans.end())... | 1 |
#include <bits/stdc++.h>
using namespace std;
unsigned long long fast(unsigned long long a, unsigned long long b) {
if (b == 0) return 1;
if (b % 2 == 0) {
unsigned long long x = fast(a, b / 2) % 1000000007;
return ((x % 1000000007) * (x % 1000000007)) % 1000000007;
}
return ((a % 1000000007) * (fast(a,... | 4 |
#include <bits/stdc++.h>
using namespace std;
int arr[200005], arr1[200005], arr2[200005], arr3[200005], arr4[200005];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, n1;
multiset<int> s1;
multiset<int> s2;
multiset<int> s3;
cin >> n;
for (int i = (0); i < (n); i++) {
cin >> arr1[i];
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 510, M = 110;
int a[N], n, m;
double b[N][N], d[N];
double A[N][N], C[N][N];
inline double ab(double x) { return x < 0 ? -x : x; }
void build() {
for (int i = 1; i <= n; i++)
if (a[i])
A[i][i] = 1;
else {
A[i][i] = 1;
for (int j = 1... | 10 |
#include <bits/stdc++.h>
using namespace std;
int N, M, K, ANS;
bool D[105][105][105];
char s[105];
bool get(int i, int j, int k) {
if (!D[i][j][k]) return 0;
if (D[i - 1][j][k] && D[i + 1][j][k]) return 1;
if (D[i][j - 1][k] && D[i][j + 1][k]) return 1;
if (D[i][j][k - 1] && D[i][j][k + 1]) return 1;
if (D[i... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1 << 28;
double a, b, c, d, space;
int main() {
while (cin >> a >> b >> c >> d) {
a = a / b;
c = c / d;
space = a * c + a * (1 - c) + (1 - a) * c;
printf("%.12lf\n", a / space);
}
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int Max, Min, len, ans;
};
node merge(node l, node r) {
node res;
res.Max = max(l.Max, r.Max + l.len);
res.Min = min(l.Min, r.Min + l.len);
res.len = l.len + r.len;
res.ans = min({l.ans, r.ans, r.Min + l.len - l.Max});
return res;
}
vector<node> ... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 101000;
struct Node {
int a, b, id;
bool operator<(const Node &tt) const {
if (b == tt.b) {
return a < tt.a;
}
return b > tt.b;
}
};
Node z[N];
set<pair<int, int> > st;
long long sum, l[N], r[N];
int n, p, K;
void ins(int val, int id, i... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long rr[] = {0, 1, 1, 1, 0, -1, -1, -1};
long long cc[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long mod = 1e9 + 7;
const long long N = 300050;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
long long test = 1;
while (t... | 5 |
#include <bits/stdc++.h>
using namespace std;
inline namespace Infinity {
const char CR = '\n';
inline void write(const int n) { printf("%d", n); }
inline void write(const unsigned n) { printf("%u", n); }
inline void write(const long long n) { cout << n; }
inline void write(const unsigned long long n) { cout << n; }
in... | 0 |
#include <bits/stdc++.h>
using namespace std;
typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
const int N=1e6+2,p=1e9+7;
int f[N],st[N],ed[N];
int n,c,i,t,m,j,k,tp,x,y,ans,z,w,la,s;
inline int ksm(register int x,register int y)
{
register int r=1;
while (y)
{
if (y&1) r=(ll)r*x%p;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int RLEN = 1 << 20 | 1;
inline char gc() {
static char ibuf[RLEN], *ib, *ob;
(ib == ob) && (ob = (ib = ibuf) + fread(ibuf, 1, RLEN, stdin));
return (ib == ob) ? EOF : *ib++;
}
inline int read() {
char ch = gc();
int res = 0;
bool f = 1;
while (!isdigit(c... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3010;
const int fmaxN = 3010, fmaxE = (3 * N + 10) * 2;
int fn, src, snk;
int head[fmaxN], from[fmaxE], nxt[fmaxE], to[fmaxE], cap[fmaxE], cost[fmaxE];
int edgeCnt, visID, vis[fmaxN];
void init() {
edgeCnt = 0;
memset(head, -1, sizeof head);
}
void addEdge... | 6 |
#include <bits/stdc++.h>
using namespace std;
int a[110];
int dp[105][105] = {0};
int dpp[105][10005] = {0};
int num[105] = {0};
int main() {
int N, M, k, t;
cin >> N >> M;
for (int i = 1; i <= N; i++) {
cin >> num[i];
for (int j = 1; j <= num[i]; j++) {
cin >> a[j];
}
for (int s = 1; s <= n... | 5 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
using pcc = pair<char, char>;
using pdd = pair<double, double>;
using pci = pair<char, int>;
using si = set<int>;
using s = string;
using seti = set<int>;
using useti = unordered_set<i... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int inf_int = 1e9 + 100;
const long long inf_ll = 1e18;
const double pi = 3.1415926535898;
template <class T1, class T2>
std::ostream &operator<<(std::ostream &out, const std::pair<T1, T2> &rhs) {
out << "( " << rhs.first << " , " << rhs.second << " )";
return out... | 10 |
#pragma GCC optimize (3)
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<functional>
#include<cassert>
#include<numeric>
#includ... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigmod(T p, T e, T M) {
if (e == 0) return 1;
if (e % 2 == 0) {
T t = bigmod(p, e / 2, M);
return (t * t) % M;
}
return (bigmod(p, e - 1, M) * p) % M;
}
template <class T>
inline T gcd(T a, T b) {
if (b == 0) return a;
return ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k;
scanf("%lld%lld", &n, &k);
n--;
long long s = k + n - 1;
long long p = sqrt(2 * s + 2) + 2;
while (p * (p + 3) / 2 > s) p--;
printf("%lld\n", n - p);
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
struct node {
bool endmark;
node* next[26];
node() {
endmark = false;
for (int i = 0; i < 26; i++) {
next[i] = NULL;
}
}
} * root;
void insert(string s) {
node* cur = root;
int ln = s.size();
for (int i = 0; i < ln; i++) {
int id = s[i] -... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long a[200005];
long long s[200005];
long long searchLower(long long left, long long right, long long val) {
long long mid = (left + right) / 2;
if (s[left] > val) return -1;
while (left <= right) {
if (s[mid] == val)
return mid;
else if (s[mid] < v... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5010;
const int mod = 1e9 + 7;
const int mod2 = 1e9 + 13;
char s[maxn];
int nx[maxn];
int dp[maxn][maxn], n;
int hs[maxn][maxn];
void Init() {
int id = n;
nx[n] = n;
for (int i = n - 1; i >= 0; i--) {
nx[i] = id;
if (s[i] != '0') id = i;
}
... | 6 |
#include <bits/stdc++.h>
int min(int a, int b) {
if (a < b)
return a;
else
return b;
}
int main(int argc, char *argv[]) {
int tc;
scanf("%d", &tc);
while (tc--) {
int i, cs, cw, s, w, max = -10, p, f;
scanf("%d%d%d%d%d%d", &p, &f, &cs, &cw, &s, &w);
int mi = cs, ma = cw, ss = s, ww = w;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n;
char c[5010][5010];
vector<int> v[5010];
bool vis[5010];
void dfs(int a, int b) {
vis[b] = 1;
for (int i = 0; i < v[b].size(); i++) {
if (c[v[b][i]][a] == '1') {
cout << a + 1 << " " << b + 1 << " " << v[b][i] + 1 << endl;
exit(0);
} else if (... | 6 |
#include <bits/stdc++.h>
using namespace std;
string rreplace(string s, string temp, string temp2) {
string t = temp + '#' + s;
vector<int> z(s.size() + 1 + temp.size(), 0);
int l = 0, r = 0;
for (int i = 1; i < t.size(); ++i) {
if (r >= i) z[i] = min(r - i + 1, z[i - l]);
while (i + z[i] < t.size() && ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, i, j, k, l, Min = INT_MAX;
cin >> n >> m;
vector<int> v, a, b;
for (i = 0; i < n; i++) {
cin >> j;
v.push_back(j);
}
for (i = 0; i < n; i++) {
cin >> j;
a.push_back(j);
}
sort(a.begin(), a.end());
for (i = 0; i ... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long read() {
long long x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
return x * f;
}
int n;
set<int> s;
void wor... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, y, n;
string str = "NO";
int k = 2 * n;
cin >> k >> x >> y;
n = k / 2;
if ((x == n && y == n) || (x == n + 1 && y == n) || (x == n && y == n + 1) ||
(x == n + 1 && y == n + 1)) {
cout << str << endl;
} else {
str = "YES";
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, a[300009];
stack<int> mi, ma;
struct data {
int x, y;
data(int o = 1000000000, int z = 0) { x = o, y = z; }
data operator+(const data b) const {
data c;
c.x = min(x, b.x);
if (x == c.x) c.y += y;
if (b.x == c.x) c.y += b.y;
return c;
}
} s... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n;
int p[8505];
int wh[8505];
int ans[8505];
int level[8505];
int nxt[9][8505];
int prv[9][8505];
pair<int, int> bros[9][8505];
int svd = 0, lsz, l;
inline void go(int &f) {
int id = f, t = 0;
f = nxt[l][f];
if (wh[f] < wh[id]) id = f, t = 1;
f = nxt[l][f];
if... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[500005];
long long b[500005];
struct Line {
long long a, b;
Line() {}
Line(long long a, long long b) : a(a), b(b) {}
long long get(long long x) { return a * x + b; }
};
struct ConvexHull {
vector<Line> a;
bool bad(Line l1, Line l2, Line l3) {
re... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, w[200005] = {}, h[200005] = {};
int h1 = 0, h2 = 0, W = 0, H = 0;
int max1;
long long solve(int x);
int main() {
long long sum;
bool now = false;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> w[i] >> h[i];
W += w[i];
if (h[i] > h1) {
h2 = h... | 1 |
#include <bits/stdc++.h>
using namespace std;
map<string, int> present;
map<int, string> st;
vector<int> adj[1000001];
vector<string> second;
int visited[1000001] = {0};
pair<int, long long> ans[1000001], cur;
vector<pair<pair<int, long long>, int> > v;
string norm(string h) {
int i, n = (int)h.size();
for (i = 0; ... | 8 |
#include <bits/stdc++.h>
long long max, target;
int base;
bool dfs(long long now, long long val) {
if (now == max) {
return val == target || val - now == target || val + now == target;
}
bool ok = false;
ok |= dfs(now * base, val);
ok |= dfs(now * base, val - now);
ok |= dfs(now * base, val + now);
re... | 5 |
#include <bits/stdc++.h>
using namespace std;
void FastIO() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
cout.precision(15);
}
string fun(string str) {
int i, l = str.length();
for (i = 0; i < l; i++) {
if (str[i] == '+')
str[i] = '*';
else
str[i] = '+';
}
return st... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T max(T a, T b, T c) {
return max(a, max(b, c));
}
template <class T>
inline T min(T a, T b, T c) {
return min(a, min(b, c));
}
template <class T>
void debug(T a, T b) {
for (; a != b; ++a) cerr << *a << ' ';
cerr << endl;
}
template <class... | 6 |
#include <bits/stdc++.h>
using namespace std;
#define fastio \
ios::sync_with_stdio(0); \
cin.tie(NULL); \
cout.tie(NULL);
#define int long long
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define endl '\n'
#define pi 3.141592653589793238
#define mp make_pa... | 3 |
#include <bits/stdc++.h>
const long long md = 1e9 + 7;
const int Inf = 1e9;
const long long Inf64 = 1e18;
const long long MaxN = 1e5 + 1;
const long long logN = 20;
const long long MaxM = 11;
const long double eps = 1e-15;
const long long dx[4] = {0, 1, 0, -1};
const long long dy[4] = {1, 0, -1, 0};
const long long ddx... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long MAX = 1000000000000000000;
vector<long long> fib;
void test() {
long long n;
cin >> n;
vector<int> a;
for (int i = fib.size() - 1; i >= 0; --i) {
if (fib[i] <= n) {
a.push_back(1);
n -= fib[i];
} else
a.push_back(0);
}
r... | 7 |
#include <bits/stdc++.h>
using namespace std;
double x[1234], y[1234];
int main(int argc, char const *argv[]) {
int n;
std::cin >> n;
double ans = 0.0;
for (int i = 0; i < n; i++) {
std::cin >> x[i] >> y[i];
ans += y[i];
}
printf("%.4f\n", ans / n + 5);
return 0;
}
| 7 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const long long MAX = (long long)2e5;
long long inf = (long long)2e9;
long long mod = (long long)1e9;
long long n, m;
long long ok = 1;
int main() {
ios::sync_with_stdio(0);
long long n, k;
string s, t;
cin >> n >> k >> s >> t;
long l... | 6 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, w = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') w = -1;
c = getchar();
}
while (c <= '9' && c >= '0') {
x = (x << 1) + (x << 3) + c - '0';
c = getchar();
}
return w == 1 ? x : -x;
}
struct no... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int TESTS = 1;
while (TESTS--) {
int i, n, j, k;
cin >> n >> k;
vector<int> v(n);
vector<vector<int> > a(200005);
for (i = 0; i < n; i++) cin >> v[i];
int ans = I... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[1111111];
long long k;
long long get_ans(double t, long long M, int a) {
long long res = (long long)t;
res += 3;
while (a - 3LL * res * res + 3LL * res - 1 < M) res--;
return res;
}
int check(long long M) {
long long num = 0;
for (int i = 0; i < n; ... | 9 |
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
string s1 = "", s2 = "";
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string s, a, b;
cin >> s >> a >> b;
bool ans1 = false, ans2 = false;
int p = (int)s.find(a... | 2 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:32000000")
using namespace std;
const long long mod = 1000000007;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int inf = 0x0FFFFFFF;
const int nil = -1;
const int root = nil + 1;
inline bool read(int& val) { return scanf("%d", &val) != -1; }
inlin... | 7 |
#include <bits/stdc++.h>
using namespace std;
inline long long Getint() {
char ch = getchar();
long long x = 0, fh = 1;
while (ch < '0' || ch > '9') {
if (ch == '-') fh = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
(x *= 10) += ch ^ 48;
ch = getchar();
}
return x * fh;
}
const i... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, k, q;
cin >> n >> k >> q;
int a[k][n], p = k;
for (int i = 0; i < k; i++)
for (int j = 0; j < n; j++) cin >> a[i][j];
pair<int, int> mp[n][k];
bitset<1 << 12> c[k + q];
for (int i = 0; i... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, k, c, x, i = 1, j = 1;
cin >> n >> m >> k;
x = k;
while (k) {
if (k > 1) {
c = (m * n) / x;
cout << c << " ";
} else {
c = (m * n) / x + (m * n) % x;
cout << c << " ";
}
while (c--) {
if (j == m + ... | 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.