solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
string s;
cin >> s;
string t;
cin >> t;
set<char> set_s;
map<char, int> m;
for (int i = 0; i < s.size(); i++) {
m[s[i]]++;
set_s.insert(s[i]);
}
vector<char> v;
sort(s.begi... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long maxN = 1e6 + 9;
const long long inf = 1e10;
string s, tmp;
vector<string> a, b;
int main() {
ios_base::sync_with_stdio(0);
cin >> s;
long long n = s.size();
long long ptr = 0, num;
while (ptr < n) {
tmp = "";
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxc = 20;
vector<int> to, vis;
vector<vector<int> > g;
void dfs(int u) {
vis[u] = 1;
for (int v : g[u]) {
if (!vis[v]) dfs(v);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int n;
string a, b;... | 23 |
#include <bits/stdc++.h>
using namespace std;
const int LG = 21;
const int N = 1 << LG;
const double pi = 3.1415926535897932384626433832795028841;
const double eps = 0.5;
complex<double> a[N];
bool mark[N];
vector<int> ans;
inline void reverseIt(complex<double> *a) {
for (int i = 0; i < N; i++) {
int rev = 0;
... | 20 |
#include <bits/stdc++.h>
using namespace std;
struct POINT {
double x, y;
POINT() {}
POINT(double _x, double _y) : x(_x), y(_y) {}
} c, s, h;
double t1, t2;
double dist(POINT &x, POINT &y) {
return sqrt(((x.x - y.x) * (x.x - y.x)) + ((x.y - y.y) * (x.y - y.y)));
}
double calc(double m) {
POINT a = POINT(s.x *... | 18 |
#include <bits/stdc++.h>
using namespace std;
char G[3005][3005];
int xx, yy, sum, n, m, num[3005][3005];
inline bool check(int x, int y) {
int tot = x * y;
int xxx = xx, yyy = yy;
if (xx + x - 1 > n || yy + y - 1 > m) return 0;
if (num[xx + x - 1][yy + y - 1] - num[xx - 1][yy + y - 1] -
num[xx + x - ... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long k, b, n, t;
int main() {
cin >> k >> b >> n >> t;
int S = n;
long long w = 1;
while (w <= t) (w *= k) += b, S--;
S++;
cout << max(S, 0) << endl;
return 0;
}
| 9 |
#include <bits/stdc++.h>
int main() {
int q;
int n;
int sum = 0;
int temp;
scanf("%d", &q);
for (int o = 0; o < q; o++) {
sum = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &temp);
sum += temp;
}
if (sum % n == 0) {
printf("%d\n", sum / n);
} else {... | 0 |
#include <bits/stdc++.h>
int main() {
char s[100001], isnum = 1, isnext = 0, hasnums = 0, haschar = 0;
long l;
std::vector<char> out;
scanf("%[^\n]", s);
l = strlen(s);
for (long i = 0; i < l; i++) {
if ('0' <= s[i] && s[i] <= '9')
out.push_back(s[i]);
else if (',' != s[i] && s[i] != ';')
... | 8 |
#include <bits/stdc++.h>
int reverse(int);
int main() {
int n, i, j, k, l, p, ans;
char s[110];
scanf("%[^\n]s", s);
getchar();
p = 0;
for (i = 0; s[i]; i++) {
k = reverse(s[i]);
j = p - k;
if (j < 0) {
l = (-j) % 256;
ans = 256 - l;
} else {
ans = j % 256;
}
p = k;... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 11;
string s[N];
int trie[N * 10][27], strnum[N * 10], id = 1, dp[10005];
void insert(int I) {
string ss = s[I];
transform(ss.begin(), ss.end(), ss.begin(), ::tolower);
int idd = 0;
for (int i = 0; i < ss.size(); i++) {
int next = ss[i] ... | 11 |
#include <bits/stdc++.h>
using namespace std;
bool isPrime(int x) {
if (x != 2 && x % 2 == 0) return false;
for (int i = 3; i < x; i += 2) {
if (x % i == 0) return false;
}
return true;
}
vector<int> getAllPrimes(int x) {
vector<int> v;
v.push_back(2);
;
for (int i = 3; i <= x; i += 2) {
if (isP... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n;
string s;
int main() {
cin >> n;
cin >> s;
if (s[0] == '0')
cout << 0;
else {
cout << 1;
for (int i = 1; i < n; i++) {
if (s[i] == '0') cout << 0;
}
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
void Freopen() {
freopen(
"CF1187G Gang Up"
".in",
"r", stdin);
freopen(
"CF1187G Gang Up"
".out",
"w", stdout);
}
int read() {
int g = 0, f = 1;
char ch = getchar();
while (ch < '0' || '9' < ch) {
if (ch == '-') f = -1;
... | 17 |
#include <bits/stdc++.h>
using namespace std;
int t, n, a[110], b[110], sum[110][110], cnt;
bool vis[1000100];
int main() {
ios::sync_with_stdio(false);
cin >> t;
while (t--) {
cin >> n;
memset(vis, 0, 1000100);
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
bool flag = true;
for... | 8 |
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
int n;
int a[300000];
int b[300000][2];
int bi;
int d[300000][5];
int p[300000][5][2];
int dab[300000];
void path(int x, int y) {
int i, j, k, l;
if (x == 0 && y == 0) {
return;
}
int su1, su2, start, end;
su1 = a[p[x][y][0]] + ... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
const int N = 1200005;
const double PI = 4 * atan(1);
const double eps = 1e-10;
const long long oo = 1e10;
const int K = 26;
int t;
int n;
int q;
long long a[N];
int l, r;
long long tree[N][4];
void upd(int pos, int l, int r) {
for (int j = 0; j... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, q;
cin >> n >> q;
int JUMP = int(0.445 * sqrt(n)) + 1;
vector<int> p(n + 1), p_rev(n + 1), p_jump(n + 1);
auto compute_p_jump = [&](int u) -> int {
int steps = JUMP;
while (steps--... | 16 |
#include <bits/stdc++.h>
using namespace std;
int A[100005];
long long sum[100005];
long long gcd(long long n, long long m) { return m ? gcd(m, n % m) : n; }
int main() {
int n, i, j, k;
scanf("%d", &n);
sum[0] = 0;
for (i = 1; i <= n; i++) {
scanf("%d", &A[i]);
}
sort(A + 1, A + n + 1);
for (i = 1; i... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long n, m, l = 0;
(cin >> n);
;
vector<int> x(n), z;
set<int> y;
for (auto i = ((long)0); i < (n); i++) (cin >> x[i]);
;
sort((x).begin(), (x).end());
m = *max_element((x).begin(), (x).end());
for (auto i = ((long)0); i < (n); i++) {
if ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, q, to[100005 << 1], nxt[100005 << 1], head[100005], cnt;
int fir[100005], sec[100005], tot, fa[100005][31], lg[100005], dep[100005],
root = 1;
long long vl[100005 << 2], w[100005], f[100005], col[100005 << 2];
void add(int x, int y) { to[++cnt] = y, nxt[cnt] = he... | 16 |
#include <bits/stdc++.h>
using namespace std;
long long read() {
char c = getchar();
long long flag = 1, ans = 0;
while (c < '0' || c > '9') {
if (c == '-') flag = -flag;
c = getchar();
}
while (c >= '0' && c <= '9') {
ans = ans * 10 + c - '0';
c = getchar();
}
return ans * flag;
}
const i... | 19 |
#include <bits/stdc++.h>
using namespace std;
vector<int> ve[210000], ve_rev[210000], useful_edge[210000];
bool used[210000], okok[210000];
int deg[210000], st[210000], cnt[210000];
int len, n, m;
void doit(int x) {
memset(used, false, sizeof used);
memset(deg, 0, sizeof deg);
for (int i = 1; i <= n; i++)
for... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int M = 1000 + 10;
int fun(int x1, int y1, int r1, int x2, int y2, int r2) {
int d2 = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
int rsum = r1 + r2;
int rdif = r1 - r2;
if (rdif < 0) {
rdif = -rdif;
}
if (d2 >= (r1 + r2) * (r1 + r2)) {
return 1... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout.precision(15);
long long t;
cin >> t;
while (t--) {
long long a, b, c, r;
cin >> a >> b >> c >> r;
if (b < a) swap(a, b);
long long res = 0;
if (c >= a and c <= b) {
r... | 1 |
#include <bits/stdc++.h>
using namespace std;
string s;
long long g, h, i, j, k, l, m, n, o, p, q, r, t, u, v, w, x, y, z;
vector<int> a;
int main() {
cin >> n;
for (i = 0; i < n; i++) {
cin >> x;
if (x)
a.push_back(x);
else {
if (a.size() == 0) {
cout << "0\n";
} else {
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int check(long long x) {
int ans = 0;
for (; x > 0; x -= (x & -x)) {
ans++;
}
return ans;
}
int main() {
long long state = (1 << 26) - 1;
int n;
cin >> n;
int counter = 0;
for (int i = 0; i < n; i++) {
char c;
string s;
cin >> c >> s;
s... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long MX = 3e5 + 1;
long long n, x1, x2;
vector<pair<long long, long long>> c;
vector<long long> S1, S2;
bool solve(long long a, long long b, bool ok) {
vector<long long> ans[2];
long long l = 0;
for (long long i = 0; i < 2; ++i) {
long long cn = (i ? b ... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long a[200007 + 7];
int n;
long long K;
long long scan() {
int ret;
scanf("%d", &ret);
return ret;
}
int main() {
scanf("%d", &n);
K = scan();
for (int i = 1; i <= n; i++) a[i] = scan();
long long prv, cnt;
prv = 0;
cnt = 0;
long long rem = 0;
for... | 8 |
#include <bits/stdc++.h>
using namespace std;
int lim[55];
int n;
char s[55];
pair<int, int> v[111111];
int ans[111111];
int calc(int l, int r) {
if (r > l) return r - l + 2;
if (s[l] == 'S') return 0;
if (s[l] == 'M') return 1;
return 2;
}
void require(int pos, int x) {
ans[pos] = x;
lim[x]--;
}
void prt(i... | 10 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> t(55);
vector<int> cols(55);
vector<int> taken(55);
int main() {
int m, n;
cin >> n >> m;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
char c;
cin >> c;
if (c == '.') {
t[i].push_back(0);
} else {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
cin.ignore();
set<int> skup[n + 1];
for (int i = 0; i < n - 2; i++) {
int a, b, c;
cin >> a;
cin.ignore();
cin >> b;
cin.ignore();
cin >> c;
cin.ignore();
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 987654321;
const long long int INF = 123456789987654321;
int N, T;
vector<char> V;
int last_home, home_cnt = 0, shop_cnt = 0;
vector<int> shop_idx;
int f(int x) {
int last_shop = home_cnt - x - 1 < 0 ? -1 : shop_idx[home_cnt - x - 1];
int last_point = ma... | 15 |
#include <bits/stdc++.h>
using namespace std;
int computa(vector<vector<vector<int> > > &memoria,
vector<vector<vector<int> > > &anterior, vector<vector<int> > &v,
int n, int m, int i, int j, int kk) {
if (i < 0 or (i >= n and kk > 0) or j < 0 or j >= m or
(i < n and kk < v[i][j]))
r... | 11 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base ::sync_with_stdio(0);
cin.tie(0);
long long t = 1;
while (t--) {
long long n, m;
cin >> n >> m;
long long ans[m + 1];
memset(ans, 0, sizeof ans);
map<long long, long long> f;
long long a[n], x;
for (long long i =... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, k;
int a[1 << 22];
int cnt[22], last[22], t[22], c[22][22], T;
char s[200001];
int mask[550001], l[550001], r[550001];
int get(int i, int j, int id) {
if (i > j) {
return 0;
}
if (i < l[id]) {
i = l[id];
}
if (j > r[id]) {
j = r[id];
... | 19 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int ans = -1;
map<int, int> m;
int a, b, c, d;
cin >> a >> b >> c >> d;
m[b]++;
m[b + a]++;
for (int i = 2; i <= 100; ++i) {
m[(i * a) + b]++;
}
if (m[d] == 1)
ans = d;
else if (m[d + c] == 1)
ans = d + c;
else {
for (int... | 4 |
#include <bits/stdc++.h>
#define endl '\n'
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
using namespace std;
typedef __int128 LL;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
const int mod = 9982443... | 16 |
#include <bits/stdc++.h>
using namespace std;
string a, b;
int seq[200001] = {0};
bool query(int p) {
int i, j;
bool vis[200001] = {0};
for (i = p + 1; i <= a.length(); i++) {
vis[seq[i]] = 1;
}
i = 0, j = 0;
while (i < a.length() && j < b.length()) {
if (!vis[i + 1] || a[i] != b[j])
i++;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int k, n, m, q;
vector<string> base;
vector<pair<string, map<string, int> > > comp;
vector<map<string, int> > aly;
void rep(int ali) {
for (vector<pair<string, map<string, int> > >::iterator it = comp.begin();
it != comp.end(); ++it) {
for (;;) {
bool b_o... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000;
int n, m, row[N], col[N];
inline int calc(int c) {
return col[c] + col[n - c - 1] + row[c] + row[n - c - 1];
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; ++i) row[i] = col[i] = 1;
for (int i = 0; i < m; ++i) {
int x, y;
sc... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
long long n, a[15], win[15][15];
long long mult(long long x, long long k) {
if (k == 0) return 1;
long long tmp = mult(x, k / 2);
if (k % 2 == 0) return tmp * tmp % MOD;
return tmp * tmp % MOD * x % MOD;
}
long long getBit(long long x,... | 17 |
#include <bits/stdc++.h>
using namespace std;
using lld = long long int;
using pii = pair<int, int>;
using pll = pair<lld, lld>;
lld a[51][20009];
int n, m, p;
lld sa[51][20009];
lld sb[51][20009];
lld d[51][20009];
lld ma[2 * 32768];
lld mb[2 * 32768];
lld mc[20009];
lld md[20009];
void build_up(int ti) {
int i, j, ... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, l, c, d, p, nl, np, s1, s, a, b;
cin >> n >> k >> l >> c >> d >> p >> nl >> np;
s1 = (k * l) / nl;
a = c * d;
b = p / np;
s = min(s1, a);
s = min(s, b) / n;
cout << s << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
#pragma warning(disable : 4996)
const int IT_MAX = 1 << 18;
const int MAXN = 2e5 + 5;
const int mod = 1e9 + 7;
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
long long powmod(long long a, long long b, long long mod) {
long long res = 1;
a %= mod;
for (; b; b >>= 1) {
... | 13 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 0;
cin >> t;
whi... | 14 |
#include <bits/stdc++.h>
using namespace std;
const long long int MAX = 2e5 + 5;
long long int s[4 * MAX][12], nex[4 * MAX][12], ff[12], f[12], A[MAX];
long long int N, Q;
void combine(long long int node) {
for (long long int i = 0; i < 10; ++i)
s[node][i] = s[node << 1][i] + s[1 | node << 1][i];
}
void build(lon... | 20 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int a, b, c, d, e, f;
cin >> a >> b >> c >> d >> e >> f;
long long int x, y, z;
x = (d - b) * (d - b) + (c - a) * (c - a);
y = (f - d) * (f - d) + (e - c) * (e - c);
z = (a - c) * (f - d) - (c - e) * (d - b);
if (x != y) {
printf("No... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
long long mod = 1000000007;
string second;
cin >> second;
int n = second.length();
string s1 = "";
for (int i = 0; i < n; i++) {
if (s1.length() == 0 && second[i] != 'a') continue;
if (second[... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long l[50], r[50], total[50], max_sum[50];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) {
long long len, x;
scanf("%I64d", &len);
long long sum = 0, maxx = -(1 << 30);
for (int j = 0; j < len; j++) {
scanf("%I64d... | 12 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void maxtt(T& t1, T t2) {
t1 = max(t1, t2);
}
template <typename T>
void mintt(T& t1, T t2) {
t1 = min(t1, t2);
}
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "URDL";
long long ln, lk, lm;
void etp(b... | 27 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int n, q;
int sum = 0, arr[1000];
string s;
cin >> n;
getline(cin, s);
for (int a = 0; a < n; a++) {
getline(cin, s);
arr[a] = s[a * 2] - '0';
sum ^= arr[a];
}
cin >> q;
for (int a = 0, b; a < q;... | 8 |
#include <bits/stdc++.h>
int main() {
int a, b, c, i;
scanf("%d%d%d", &a, &b, &c);
for (i = 0; a * i <= c; i++) {
if ((c - (a * i)) % b == 0) {
printf("YES\n");
break;
}
}
if (a * i > c) printf("NO\n");
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
bool check(long long n) {
if (pow((long long)sqrt(n), 2) == n) return true;
return false;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
long long arr[n];
for (int i = 0; i < n; i++) cin >> arr[i];
vector<long long> q, w;
int s1... | 8 |
#include <bits/stdc++.h>
using namespace std;
vector<int> V[30];
map<char, bool> M;
int main() {
string str1;
string str2;
cin >> str1 >> str2;
for (int i = 0; i < str1.size(); i++) {
M[str1[i]] = 1;
V[str1[i] - 'a'].push_back(i);
}
for (int i = 0; i < str2.size(); i++) {
if (!M[str2[i]]) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
const double eps = 0.000001;
int a[100][100];
const int MX = 10000000;
char s[MX];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, mx = 0;
cin >> n;
for (int i = 0; i < MX; i++) s[i] = 'a';
for (int i = 0;... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, d, a[105], m, profit;
int main() {
cin >> n >> d;
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
cin >> m;
for (int i = 0; i < min(n, m); i++) profit += a[i];
if (m > n) profit -= (m - n) * d;
cout << profit << endl;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const char T[25] = "BERLAND";
bool g[10][10];
struct team {
char name[25];
int point;
int diff;
int score;
int miss;
} a[10];
int tot;
int cmp(struct team x, struct team y) {
if (x.point == y.point) {
if (x.diff == y.diff) {
if (x.score == y.score) ret... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 1;
int n, w, h;
pair<int, int> ans[N];
vector<pair<int, int> > d[N][2];
void input() {
cin >> n >> w >> h;
for (int i = 0; i < n; ++i) {
int p;
cin >> p;
int x;
cin >> x;
int t;
cin >> t;
d[t - x + (N >> 1)][p == 1].push_b... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long t;
cin >> t;
while (t-- > 0) {
string s;
cin >> s;
long long n = s.length();
long long i = 0, j = 0;
map<char, long long> m, m1;
m['1'] = 0, m['2'] = 0, m['... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 300010;
unsigned long long p[N];
struct segtree {
struct node {
int sz;
unsigned long long sum1, sum2;
node() {
sum1 = 0;
sum2 = 0;
sz = 0;
}
};
node unite(const node &a, const node &b) const {
node res;
res.sum1... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
while (n--) {
long long k, x;
cin >> k >> x;
long long ans = x + 9 * (k - 1);
cout << ans << "\n";
}
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int nt = (int)1e6 + 10;
int n, m, a[nt];
int dem[1001] = {0};
int f[1001][1001], ca[1001], fa[1001] = {0}, ct = 1;
int main() {
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
a[i] %= m;
++dem[a[i]];
if (a[i] % m == 0) {
cout << "Y... | 11 |
#include <bits/stdc++.h>
using namespace std;
void READ(string INPUT = "NO", string OUTPUT = "NO") {
if (INPUT != "NO") freopen(INPUT.c_str(), "r", stdin);
if (OUTPUT != "NO") freopen(OUTPUT.c_str(), "w", stdout);
}
int frq[100001];
int n, t;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> t;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct DSU {
int nbElem;
vector<int> repr, weight;
DSU(int ta) : nbElem(ta), repr(ta), weight(ta, 1) {
iota(repr.begin(), repr.end(), 0);
}
int get(int x) {
if (repr[x] != x) repr[x] = get(repr[x]);
return repr[x];
}
bool unit... | 12 |
#include <bits/stdc++.h>
int main() {
int n;
scanf("%d", &n);
if (n <= 3) {
printf("NO\n");
} else if (n % 2 == 0) {
printf("YES\n");
printf("1 * 2 = 2\n");
printf("2 * 3 = 6\n");
printf("6 * 4 = 24\n");
for (int i = 5; i <= n; i += 2) {
printf("%d - %d = 1\n", i + 1, i);
pri... | 7 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:200000000")
using namespace std;
const int INF = (int)1e9;
const long long INF64 = (long long)1e18;
long long n, m, cur;
long long C[300][300];
long long dp[300][10001];
long long ppows[300], ppows2[300], modulo = INF + 7;
long long binpow(long long a, long long ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int zero, one;
char s[maxn];
vector<string> ans;
int main() {
scanf("%s", s + 1);
int n = strlen(s + 1);
for (int i = 1; i <= n; i++) {
if (s[i] == '0') zero++;
if (s[i] == '1') one++;
}
if (n & 1) {
if (one <= n / 2) ans.push_... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1 << 19;
int N, A[MAXN];
int B[MAXN];
set<pair<int, int> > bit[MAXN];
bool vis[MAXN];
int ans[MAXN];
void dfs(int x) {
static int cur = 0;
if (x == N + 1 || vis[x]) {
return;
}
vis[x] = true;
dfs(B[x]);
for (int i = A[x] - 1; i; i &= i - 1) ... | 22 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
int n;
struct point {
int x, y;
point() {}
point(int x, int y) : x(x), y(y) {}
} p[1015];
struct seg {
point p1, p2;
seg() {}
seg(point p1, point p2) : p1... | 10 |
#include <bits/stdc++.h>
using namespace std;
pair<long long int, long long int> pr;
map<long long int, long long int> mpp;
set<long long int> ts;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
long long int n, row = 0, column = 0;
char a[102][102];
cin >> n;
long long int i, j;
for (long long int i = ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int cnt, mulai, selesai, ro, co, ki, ka, curx, cury, curl, curr;
deque<int> x;
deque<int> y;
deque<int> l;
deque<int> r;
string s[2005];
void dfs(int row, int col, int kiri, int kanan) {
cnt++;
s[row][col] = '+';
x.push_back(row);
y.push_back(col);
l.push_back(kir... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, j, k;
vector<pair<int, pair<int, int> > > tr;
scanf("%d", &n);
n *= 2;
for (i = 2; i <= n; i++) {
for (j = 1; j < i; j++) {
scanf("%d", &k);
tr.push_back(make_pair(k, make_pair(i, j)));
}
}
sort((tr).begin(), (tr).end... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
template <class T>
typename T::value_type arr_sum(const T& v, int n) {
typename T::value_type sum = 0;
for (int i = (0); i < (n); ++i) sum += v[i];
return sum;
}
struct Sync_stdio {
Sync_stdio() {
cin.tie(NULL);
ios_base::sync_wit... | 15 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n, p;
cin >> n >> p;
long long ans = -1;
for (long long k = 1; k <= 31; k++) {
long long x = n - (k * p);
long long find_bits = __builtin_popcount(x);
if ((find_bits <= k) &&... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 6e5 + 5;
long long n, m, k, T, w, x, y, t, tot, head[MAXN], ver[MAXN], edge[MAXN],
Next[MAXN];
long long f[MAXN][21], maxx[MAXN][21];
pair<long long, long long> dis[MAXN];
long long d[MAXN];
bool v[MAXN];
void addedge(long long x, long long y, lon... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 69;
vector<int> vek, G[N], wyn;
vector<pair<int, int> > ve;
int zap[N], n, m, rep[N], roz[N], a, b;
queue<int> q;
set<int> S;
int re(int v) {
if (rep[v] != v) rep[v] = re(rep[v]);
return rep[v];
}
void uni(int a, int b) {
a = re(a);
b = re(b);
... | 13 |
#include <bits/stdc++.h>
using namespace std;
int a[1234567];
string fun(int n) {
if (n == 0) return "zero";
if (n == 1) return "one";
if (n == 2) return "two";
if (n == 3) return "three";
if (n == 4) return "four";
if (n == 5) return "five";
if (n == 6) return "six";
if (n == 7) return "seven";
if (n... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
unsigned long long int t, n, k, ans = 0, ans1 = 0;
cin >> t;
for (int i = 1; i <= t; i++) {
cin >> n >> k;
ans = 0;
while (n) {
ans = ans + (n % k);
n = n / k;
ans++;
}
cout << ans - 1 << endl;
}
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, p, e, u, v, d, tc;
scanf("%d", &tc);
while (tc--) {
scanf("%d %d", &n, &p);
e = 2 * n + p;
u = 0, v = 1;
while (e--) {
printf("%d %d\n", u + 1, v + 1);
v++;
if (v == n) u++, v = u + 1;
}
}
return 0;
}
| 7 |
#include <bits/stdc++.h>
using namespace std;
struct ho {
string a;
string b;
};
ho mass[1000];
int main() {
ios_base::sync_with_stdio(0);
int n;
cin >> n;
int len = n;
for (int i = 0; i < (n); ++i) {
cin >> mass[i].a >> mass[i].b;
for (int j = 0; j <= i - 1; ++j) {
if (mass[i].a == mass[j].... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int W = 327;
const int P = 1e9 + 7;
int A, B;
char s[22][22], t[22][22], b[22][22];
set<int> S;
int get(char s[][22], int w, int h) {
int hs = 0;
for (int i = (0); i < (w); ++i) {
for (int j = (0); j < (h); ++j) hs = (1ll * hs * W + s[i][j]) % P;
hs = (1ll... | 10 |
#include <bits/stdc++.h>
const int maxn = 35;
const int maxs = 5000035;
const int INF = 0x3f3f3f3f;
bool fnd;
int n, m, mx;
int s[maxn], f[maxs], fa[maxs], pr[maxs];
void fndScheme(int st) {
if (fa[st]) fndScheme(fa[st]);
printf("%d ", pr[st]);
}
int main() {
while (~scanf("%d%d", &n, &m)) {
memset(f, 0x3f3f3... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 1;
int n;
vector<string> names;
int name[N], version[N];
vector<int> g[N];
int usedVertex[N];
int usedHeight[N];
int usedVersion[N];
vector<pair<string, int>> result;
void getData() {
cin >> n;
map<pair<string, int>, int> numeration;
vector<pair<st... | 11 |
#include <bits/stdc++.h>
using namespace std;
int a[100005];
int b[100005];
int main() {
int n;
while (scanf("%d", &n) == 1) {
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
for (int i = 0; i < n; i++) {
scanf("%d", a + i);
}
b[n - 1] = a[n - 1];
b[n - 2] = a[n - 2] + b[n - 1];
... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long n, rev = 1, cnt = 0, ans = 0, flag[100010];
map<pair<long long, long long>, long long> vis;
long long gi() {
long long w = 0, f = 1;
char ch;
while (!isdigit(ch)) {
f = ch == '-' ? -1 : 1;
ch = getchar();
}
while (isdigit(ch)) {
w = (w << 1) ... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n, q;
vector<vector<int>> lava;
void Input() {
cin >> n >> q;
lava.resize(2, vector<int>(n, 0));
}
void Solve() {
int blockedPair = 0;
while (q--) {
int x, y;
cin >> x >> y;
x--;
y--;
int delta = (lava[x][y] == 0) ? +1 : -1;
lava[x][y] = ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 11;
int gl[N];
int mx[N];
int gll(int l) {
if (l == gl[l]) return l;
return gl[l] = gll(gl[l]);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie();
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
gl[i] = i;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const static int INF = 1000000000;
int t;
string input;
map<string, string> apa;
int main() {
scanf("%d", &t);
string a, b;
string v = "void";
apa[v] = "void";
while (t--) {
cin >> input;
if (input == "typedef") {
cin >> a >> b;
string tipe = "... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int Maxn = 100005;
int n, m, par[Maxn], dp[Maxn], sz[Maxn], cnt[Maxn], ans;
vector<pair<int, int> > v;
int find(int x) { return par[x] == x ? x : par[x] = find(par[x]); }
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int A = 5e5 + 10;
const int B = 5;
class Gra {
public:
int v, next;
} G[A << 1];
int head[A], tot, n, val[A];
long long f[A][B], g[A][B];
void Init() {
memset(head, -1, sizeof(head));
tot = 0;
}
void add(int u, int v) {
G[tot].v = v;
G[tot].next = head[u];
... | 18 |
#include <bits/stdc++.h>
using namespace std;
vector<int> w;
vector<int> primes;
vector<int> isComposite;
void sieve(int N) {
isComposite.assign(N + 1, 0);
isComposite[0] = isComposite[1] = 1;
for (int i = 2; i <= N; ++i)
if (isComposite[i] == 0) {
primes.push_back(i);
if (1ll * i * i <= N)
... | 19 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long N = 3e5 + 5;
long long d[N];
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
long long n, m;
cin >> n >> m;
long long sum = 0;
for (long long i = 1; i <= m; i++) {
long long x;
cin >> x >> d[i... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, max, sum = 0;
cin >> n;
int array[n];
cin >> array[0];
max = array[0];
for (int i = 1; i < n; i++) {
cin >> array[i];
if (array[i] > max) {
max = array[i];
}
}
for (int i = 0; i < n; i++) {
sum = sum + (max - array[i... | 0 |
#include <bits/stdc++.h>
using namespace std;
bool check(string s, string sub, vector<int> arr, int mid) {
string tmp = s;
for (int i = 1; i <= mid; i++) {
tmp[arr[i] - 1] = '$';
}
int j = 0;
for (int i = 0; i < tmp.size(); i++) {
if (tmp[i] == sub[j]) j++;
if (j == sub.size()) return true;
}
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int a[300005], n, m;
bool check(int x) {
int mx = 0;
int b[300005];
for (int i = 1; i <= n; i++) {
if (i == 1) {
if ((m - a[i]) <= x) {
b[i] = 0;
mx = max(mx, m - a[i]);
} else
b[i] = a[i];
} else {
if (a[i] >= b[i - 1... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
int main() {
cin >> n >> k;
for (int i = 1; i <= n - k; i++) cout << i << " ";
int c = n - k + 1;
while (c <= n) {
cout << n-- << " ";
if (c <= n)
cout << c++ << " ";
else
break;
}
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 2;
unordered_map<long long, unordered_map<long long, long long>> BIT;
void update(long long ind, long long t, long long val) {
while (t < M) {
BIT[ind][t] += val;
t += (t & -t);
}
}
long long soluchan(long long ind, long long t) {
lon... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x(0);
cin >> n;
string s;
while (n--) {
cin >> s;
if (s[1] == '+') {
++x;
} else {
--x;
}
}
cout << x << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long n, k;
int cnt = 0;
vector<long long> vec;
void dfs(long long op, long long num) {
if (cnt >= 100000) return;
if (num == 0) {
if (cnt < 100000) {
printf("%I64d ", op);
cnt++;
}
return;
}
if (op == 1) {
if (cnt < 100000) {
p... | 14 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.