solution stringlengths 53 181k | difficulty int64 0 13 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int n, head[300300], nxt[300300 << 1], to[300300 << 1], fa[300300][22],
dp[300300];
void add_edge(int x, int y, int id) {
nxt[id] = head[x], head[x] = id;
to[id] = y;
}
void dfs(int x, int p = 0) {
fa[x][0] = p;
for (int i = 1; i <= 31 - __builtin_clz(n); i++)
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5010;
long long a[maxn];
int p[maxn];
int dp[maxn];
int main() {
int n;
scanf("%d", &n);
memset(p, 0, sizeof(p));
for (int i = 0; i < n; i++) {
scanf("%lld", &a[i]);
while (a[i] % 2 == 0) a[i] /= 2, p[i]++;
}
int tmp = 1;
for (int i = ... | 8 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> g;
vector<int> chosen;
void dfs(int cur, int chose) {
chosen[cur] = chose;
for (int i = 0; i < (int)g[cur].size(); i++) {
if (!chosen[g[cur][i]]) {
dfs(g[cur][i], (chose == 1 ? -1 : 1));
}
}
}
void solve() {
int n, m;
cin >> n >> ... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y) {
if (y == 0) return x;
return gcd(y, x % y);
}
void O_o() {
ios::sync_with_stdio(0);
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
}
bool prime(int n, int i) {
if (i == n) return true;
if (n % i == 0) return fa... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int main() {
int t;
cin >> t;
while (t--) {
int a, b, c, ans = 0, ans1 = 0, a1, b1, c1;
cin >> a >> b >> c;
a1 = a;
b1 = b;
c1 = c;
while (a >= 1 && b >= 2) {
ans += 3;
a--;
b -= 2;
}
while (b ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long ans = 0, n, m, k;
cin >> n >> m >> k;
int i, j;
vector<vector<char> > O(n + 1, vector<char>(m));
vector<vector<int> > A(n + 1, vector<int>(m + 1));
vector<vector<int> > B(n + 1, vector<int>(m + 1));
for (i = 1; i <= n; i++) {
for (j ... | 6 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long T;
cin >> T;
for (long long tc = 1; tc <= T; ++tc) {
long long n;
cin >> n;
vector<long long> need(n + 1, true), spare;
for (long long i = 0; i < n; ++i) {
long long a... | 2 |
#include <bits/stdc++.h>
using namespace std;
int len;
string s, temp;
stack<int> proc, coun;
int numz[5005], numcnt;
int main() {
while (cin >> temp) s += temp;
len = s.size();
int cnt = 0;
for (int i = 0; i < len; i++) {
i++;
if (s[i] == '/') {
i++;
if (s[i + 1] == 'a') {
i += 5;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
long long res = 1;
a %= mod;
for (; b; b >>= 1) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
}
return res;
}
const int N = 1000000;
int phi[N + 100], s[N + 100], ps[N + 10... | 10 |
#include <bits/stdc++.h>
using namespace std;
int m, i, a, b;
int Grup[10], Nr[10], maxim, T[10][10], minval = 0x3f3f3f3f;
int N[5];
int n1, n2, n3;
int get_number(char Nume[]) {
if (Nume[0] == 'A') return 1;
if (Nume[0] == 'T') return 4;
if (Nume[0] == 'D') return 5;
if (Nume[0] == 'S') return 6;
if (Nume[0]... | 3 |
#include <bits/stdc++.h>
const int N = 1e5 + 50;
char s[N];
long long n, Ans;
int main() {
scanf("%I64d%s", &n, s + 1);
for (int i = 1; i <= n; i++) Ans += i * (s[i] % 2 == 0);
printf("%I64d\n", Ans);
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
string addOne(string s) {
string temp = "";
long long carry = 1;
for (long long i = s.size() - 1; i >= 0; i--) {
long long dig = (s[i] - '0') + carry;
carry = dig / 10;
temp += ('0' + (dig % 10));
}
if (carry) temp += '1';
reverse(temp.begin(), temp.... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000 * 10000 + 10;
int t[MAXN];
long long int mod = 1000 * 1000 * 1000 + 7;
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n;
cin >> n;
int a = -1, b = -1;
for (int i = 0; i < n; i++) {
char c;
cin >> c;
in... | 3 |
#include <bits/stdc++.h>
using namespace std;
int Map[1010][1010], Move[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
char s[110];
int main() {
int i, x = 105, y = 105, x1, y1, len, cnt, flag = 0;
scanf("%s", s);
memset(Map, 0, sizeof(Map));
Map[105][105] = 1;
len = strlen(s);
for (int i = 0; i < len; i++) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b, c, d, e, f, g, h;
char cd;
string s, s1;
cin >> a >> b;
vector<pair<long long, long long> > v;
cin >> s;
for (int i = 0; i < a; i++) {
v.push_back(make_pair(int(s[i]) - 96, i));
}
sort(v.begin(), v.end());
for (int i = 0;... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5, M = 505, OO = 0x3f3f3f3f;
string s;
int t, n;
int main() {
cin >> t;
while (t--) {
cin >> n;
bool f = 0;
int z = 0;
int o = 0;
for (int i = 0; i < n; ++i) {
cin >> s;
for (int j = 0; j < s.size(); ++j) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
vector<int> c[11];
int main() {
int n, k;
scanf("%d%d", &n, &k);
int a[n + 5];
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
c[a[i] % 10].push_back(i);
}
for (int i = 9; i >= 1; i--) {
if (c[i].size()) {
int x = 10 - i;
for (int j = 0... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n;
struct ss {
int x, index;
};
ss c[200050];
int a[200050];
bool cmp(ss x, ss y) { return x.x < y.x; }
int find(int x) {
int left = 1;
int right = n;
while (left <= right) {
int mid = (left + right) / 2;
if (c[left].x == x) return c[left].index;
if ... | 1 |
#include <bits/stdc++.h>
int main() {
int n, i, j, sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0, mmsum = 0;
scanf("%d", &n);
int A[n][n];
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
scanf("%d", &A[i][j]);
}
}
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
if (i + j == (n +... | 0 |
#include <bits/stdc++.h>
using namespace std;
void code() {
long long n = 7;
long long a[n];
for (long long i = 0; i < n; i++) cin >> a[i];
cout << a[0] << " " << a[1] << " " << a[6] - a[0] - a[1] << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long t;
cin >> t;
while (t-... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 9;
int main() {
ios_base::sync_with_stdio(0);
long long n;
cin >> n;
vector<long long> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
sort(a.begin(), a.end());
vector<long long> ans = {a[0], a[0]};
for (int i = 1; i < n; i++) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9, PI = acos(-1);
const int mod = int(1e9) + 7, MX = int(2e5) + 10;
int n, pos = 0;
vector<int> Adj[110], ans;
void solve() {
scanf("%d", &n);
for (int i = 0, a; i < n; i++) {
scanf("%d", &a);
if (a <= 0) continue;
Adj[a].push_back(i + ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i;
cin >> n;
cout << n << " ";
for (i = 1; i <= n - 1; i++) cout << i << " ";
return 0;
}
| 4 |
#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
using namespace std;
long long MOD = 1e9 + 7;
double eps = 1e-6;
long long mpow(long long a, long long b) {
if (a == 0) return 0;
if (b >= (MOD - 1)) b %= (MOD - 1);
if (b == 0) return 1;
long long t1 = mpow(a, b / 2);
t1 *= t1;
t1 %= MOD;
if (b % 2) t1... | 8 |
#include <bits/stdc++.h>
using namespace std;
int a, i = 0, last = 0, current = 0;
int main() {
int x, y, z = 0, a = 0, c = 1;
long long b;
cin >> x;
for (int i = 0; i < x; i++) {
cin >> y >> z;
a = z * 2;
c = y * 2;
if (a > c) {
if (z > c)
cout << z * z << endl;
else
... | 0 |
#include <bits/stdc++.h>
int main() {
int32_t n, k, len;
std::cin >> n >> k >> len;
if (len == 1) {
std::cout << 0;
return 0;
}
int32_t* arr = new int32_t[n];
for (int32_t i = 0; i < n; i++) {
std::cin >> arr[i];
arr[i] -= arr[i] == -1 ? 0 : 1;
}
int32_t** dp = new int32_t*[n];
dp[0] =... | 8 |
#include <bits/stdc++.h>
using namespace std;
long GCD(long a, long b) {
if (b == 0) return a;
return GCD(b, a % b);
}
long long bigMod(long long b, long long p, long long m) {
if (b == 1) return b;
if (p == 0) return 1;
if (p == 1) return b;
if (p % 2 == 0) {
long long temp = bigMod(b, p / 2, m);
r... | 2 |
#include <bits/stdc++.h>
int main() {
std::ios::sync_with_stdio(false);
using namespace std;
long long d, k, a, b, t, k_cost_walk, k_cost_drive;
cin >> d >> k >> a >> b >> t;
if (a >= b) {
cout << d * b << "\n";
return 0;
}
k_cost_walk = k * b;
k_cost_drive = k * a + t;
if (k_cost_walk <= k_co... | 5 |
#include <bits/stdc++.h>
int n, t, x, mx, temp1, temp2;
int main() {
scanf("%d", &n);
while (n--) {
scanf("%d%d", &temp1, &temp2);
x -= temp1 - t;
if (x < 0)
x = temp2;
else
x += temp2;
if (x > mx) mx = x;
t = temp1;
}
printf("%d %d\n", t + x, mx);
return 0;
}
| 1 |
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define lowbit(x) ((x)&(-(x)))
#define mid ((l+r)>>1)
#define lson lc[rt], l, mid
#define rson rc[rt], mid+1, r
#define fors(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;
const int maxn = 2e5 + 5;
const int lim = 1e9 + 7;
const int inf = 0... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, x, y, z, p;
cin >> n >> m >> x >> y >> z >> p;
x %= 4;
z %= 4;
y %= 2;
int n1 = n, m1 = m;
for (int i = 1; i <= p; i++) {
n = n1;
m = m1;
int xk, yk;
cin >> xk >> yk;
int xv, yv;
xv = xk;
yv = yk;
for (int... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 310;
const int M = 210005;
int num[N], r[N], sz = 0, sr = 0, ord1[N], ord2[N];
bool divide[40005], vis[N];
int head[N], Next[M], V[M], C[M], cnt = 1, dep[N];
vector<int> ans[N / 3];
inline void prime() {
for (int i = 2; i <= 40000; i++) {
if (!divide[i])... | 7 |
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
int a[200020], b[200020], c[200020], n;
int sum[200020 << 2];
void PushUp(int rt) { sum[rt] = sum[rt << 1] + sum[rt << 1 | 1]; }
void BuildTree(int l, int r, int rt) {
if (l == r) {
sum[rt] = 1;
return;
}
int m = (l + r) >> 1;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int INF = (-1u) / 2;
const long long int INF2 = (-1ull) / 2;
int a, b, i, j, k, n, m, timer = 0, l, r, x, y;
int cnt = 0, fl = 0, a2, a3 = -1000000, ans = 0;
char s[5010][5010];
int d[5010][5010];
int main() {
scanf("%d%d", &n, &m);
for (i = 0; i < n; i++) {
s... | 4 |
#include <bits/stdc++.h>
using namespace std;
inline void read(register int *n) {
register char c;
*n = 0;
do {
c = getchar();
} while (c < '0' || c > '9');
do {
*n = c - '0' + *n * 10;
c = getchar();
} while (c >= '0' && c <= '9');
}
vector<string> rot(vector<string> V) {
vector<string> res((... | 2 |
#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 int n, k, i, j, sum = 0;
cin >> n >> k;
long long int a[n];
for (i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
fo... | 0 |
#include <bits/stdc++.h>
using namespace std;
int depth[100005], sz[100005], p[100005][20], ans[100005], n, m;
set<int> g[100005];
int parcentroid[100005];
void dfs1(int node, int par) {
depth[node] = depth[par] + 1;
p[node][0] = par;
for (int i = 1; i < 20; i++) p[node][i] = p[p[node][i - 1]][i - 1];
for (auto... | 8 |
#include <bits/stdc++.h>
int n, a[100000 + 2], b[100000 + 2];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", a + i);
b[i] = a[i];
}
std::sort(b, b + n);
int cnt = 0;
for (int i = 0; i < n; i++) cnt += (a[i] != b[i]);
if (cnt == 0 || cnt == 2)
printf("YES\n");
else
... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T &x) {
x = 0;
char c = getchar();
int f = 1;
while (!isdigit(c)) {
if (c == '-') f = -1;
c = getchar();
}
while (isdigit(c)) {
x = x * 10 + c - '0';
c = getchar();
}
x *= f;
}
template <class T>
inline voi... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
long long int i, j, maxi, n, maxi1, mini1, sum;
for (i = 0; i < t; i++) {
maxi = -100;
maxi1 = -10000;
mini1 = 1000000001;
cin >> n;
long long int a[n], b[n];
for (j = 0; j < n; j++) {
cin >> a[j];
b[... | 3 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
clock_t clk = clock();
long long int i, j;
void solve(void);
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
;
int t = 1;
while (t--) solve();
return 0;
}
long long int power(long long int x, long long int n,
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, a[110];
bool hit[2 * 1000000 + 1];
int b[110], num;
int main() {
int T;
cin >> T;
while (T--) {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
memset(hit, 0, sizeof(hit));
num = 0;
for (int i = 1; i <= 1000000 && num < n; i... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int p;
if (n % 2 == 0)
p = n - 1;
else
p = n;
long long sum = 0;
if (k >= n / 2) {
for (int i = n - 1; i > 0; i--) sum += i;
} else
for (int i = k * 2, j = n - 1; i > 0; j--, i--) {
sum += j;
}
... | 2 |
#include <bits/stdc++.h>
using namespace std;
string s;
int call(string sub) {
int cnt = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == sub[0] and s[i + 1] == sub[1]) cnt++;
}
return cnt;
}
int main() {
int n, maxi = 0, res;
string sub, gram;
cin >> n >> s;
for (int i = 0; i < s.length() - 1; i... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e5 + 5;
long long mod;
vector<long long> numbers[maxn];
vector<long long> children[maxn];
char forbid[maxn];
long long dp[maxn];
long long parent[maxn];
long long gcd(long long a, long long b) {
while (a && b) {
if (a >= b)
a %= b;
el... | 7 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char c = getchar();
while (!isdigit(c)) {
if (c == '-') f = -1;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return x * f;
}
inline void print(int x) {
if (x ... | 10 |
#include <bits/stdc++.h>
using namespace std;
bool usedV[300000];
bool usedE[500000];
int main() {
int T;
scanf("%d", &T);
for (int epoch = 0; epoch < T; epoch++) {
int n, m;
scanf("%d %d", &n, &m);
for (int i = 0; i < n * 3; i++) usedV[i] = false;
int ans = 0;
for (int i = 0; i < m; i++) {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
string t;
int num[10] = {0};
bool is_ok() {
for (int i = 0; i < t.size(); i++) {
if (num[t[i] - '0'] < 1) return 0;
num[t[i] - '0']--;
}
return 1;
}
int main() {
cin >> t;
string s;
cin >> s;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '9') {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void chmax(T &x, T &y) {
if (x < y) swap(x, y);
}
template <class T>
inline void chmin(T &x, T &y) {
if (x > y) swap(x, y);
}
const long long INF = 0x3f3f3f3f3f3f;
const long long MOD = 1e9 + 7;
const long double EPS = 10e-10;
void Solution() {... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
unsigned long long sum = 0, sum1 = 0;
cin >> n >> m;
vector<pair<bool, int>> vec(n);
for (int i = 0; i < n; i++) {
cin >> vec[i].second;
sum += vec[i].second;
sum1 += vec[i].second;
vec[i].first = 1;
}
for (int i = 0; i <... | 3 |
#include <bits/stdc++.h>
using namespace std;
bool comp(pair<int, int> a, pair<int, int> b) {
if (a.first == b.first) return a.second < b.second;
return (a.first > b.first);
}
bool comp1(pair<int, int> a, pair<int, int> b) { return (a.second < b.second); }
void solve() {
vector<pair<int, int>> m;
int n;
cin >... | 4 |
#include <bits/stdc++.h>
const long long MOD = 1000000007;
const long long BIG = 1000000;
const long long inf = 1LL << 62;
const int base = 1000000000;
const int base_digits = 9;
using namespace std;
struct bigint {
vector<int> a;
int sign;
bigint() : sign(1) {}
bigint(long long v) { *this = v; }
bigint(const... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9 + 10;
const int MOD = (int)1e9 + 7;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
set<int> s;
vector<int> lift;
int n, m, ans = 0;
cin >> n >> m;
vector<int> weight(n), days(m);
for (int i = 0; i < n; i++) cin >> w... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 9e18;
const long long MOD = 1e9 + 7;
const long long mod = 998244353;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
void fileio() {}
const long long N = 1e6;
vector<vector<long long> > v(N);
void solve() {
long long n, m;
cin >> ... | 4 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:216000000")
const int MAX = 1000001;
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int n;
vector<int> d(10);
cin >> n;
for (int i = 0; i < n; ++i) {
char c;
cin >> c;
d[c - '0'] = 1;
}
if (d[7] || d[0] || d[9]) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 40;
int v[N], x[N], ct, al[N], col[N], n, lu[N], lv[N];
int read() {
int sum = 0, fg = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') fg = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
sum = sum * 10 + c - '... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long N = 101;
long long comb[N][N], sol[N][N * N], quick[N][2];
char solved[N][N * N];
long long n, m, k;
inline long long mod(long long x) { return (1ll * x % MOD + MOD) % MOD; }
long long fexp(long long a, long long r) {
long... | 5 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-8;
const double PI = 2 * acos(0.0);
inline int cmp(double x, double y = 0, double tol = EPS) {
return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
}
bool debug = true;
long long stoim(string s) {
long long v = 0;
for (int i = 0; i < int(s.size())... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, q;
cin >> n >> q;
vector<int> res(n + 1, 0);
vector<vector<int>> adjacenyList(n + 1);
for (int i = 1; i < n; i++) {
int u, v;
cin >> u >> v;
adjacenyList[u].empl... | 8 |
#include <bits/stdc++.h>
using namespace std;
vector<int> ans;
bool dp[501][501][501];
int main() {
int n, k;
scanf("%d%d", &n, &k);
dp[0][0][0] = 1;
for (int i = 1; i <= n; i++) {
int c;
scanf("%d", &c);
for (int j = 0; j <= k; j++)
for (int kk = 0; kk <= j; kk++)
if (dp[i - 1][j][kk]... | 5 |
#include <bits/stdc++.h>
int main() {
char str[105];
char ch;
int l;
int i, j;
scanf("%c", &ch);
scanf("%s", str);
l = strlen(str);
if (ch == 'R') {
for (i = 0; i <= l; i++) {
if (str[i] == 's') {
printf("a");
}
if (str[i] == 'd') {
printf("s");
}
if (st... | 0 |
#include <bits/stdc++.h>
int t, n, per[200001], where[200001];
int groupcnt;
int main() {
scanf("%d", &t);
for (int test = 0; test < t; test++) {
scanf("%d", &n);
groupcnt = 0;
for (int i = 1; i <= n; i++) {
scanf("%d", &per[i]);
where[per[i]] = i;
}
for (int i = 1; i <= n; i++) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <typename X>
inline X sqr(const X& a) {
return a * a;
}
int nxt() {
int x;
cin >> x;
return x;
}
void solve() {
int n = nxt();
if (n == 1 || n == 2 || n == 4) {
cout << -1 << '\n';
return;
}
if (n % 3 == 0) {
cout << n / 3 << ' ' << 0 <<... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, k, d[5][3][100][100];
char a[100][100];
bool was[100][100];
string s;
int main() {
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> s;
m = s.length();
for (int j = 0; j < m; j++) a[i][j] = s[j];
}
for (int i = 0; i < n; i++)
for (i... | 6 |
#include <bits/stdc++.h>
using namespace std;
namespace IO {
const int BUFFER_SIZE = 1 << 15;
char input_buffer[BUFFER_SIZE];
int input_pos = 0, input_len = 0;
char output_buffer[BUFFER_SIZE];
int output_pos = 0;
char number_buffer[100];
uint8_t lookup[100];
void _update_input_buffer() {
input_len = fread(input_buffe... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 103;
bool W[N][N][N];
bool check(int i, int j, int l, int checkX = 0, int checkY = 0,
int checkZ = 0) {
if (W[i][j][l] && !W[i - checkZ][j - checkY][l - checkX]) return true;
return false;
}
int main(void) {
int n, m, k;
scanf("%d%d%d", &n, ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 4;
int n, q, a[N], b[N];
pair<int, int> tree[2 * N + 400];
void insert(int v, int l, int r, int a, int b, int c, int d) {
if (r - l + 1 > 1 && tree[v] != make_pair(0, 0)) {
int mid = (l + r) / 2;
tree[2 * v] = make_pair(tree[v].first, tree[v].f... | 5 |
#include <bits/stdc++.h>
using namespace std;
vector<string> F[26], L[26];
string s;
int main() {
std::ios::sync_with_stdio(false);
int i, j, k, n;
cin >> n;
for (i = 0; i < n; F[s[0] - 'A'].push_back(s), ++i) cin >> s;
for (i = 0; i < n; L[s[0] - 'A'].push_back(s), ++i) cin >> s;
for (i = 0; i < 26; ++i) {... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, k, p[100], l = -1, r = -1;
cin >> n >> m >> k;
for (int i = 0; i < n; i++) {
cin >> p[i];
}
for (int i = m - 2; i >= 0; i--) {
if (p[i] <= k && p[i] > 0) {
l = i;
break;
}
}
for (int i = m; i < n; i++) {
if (p... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 7;
int32_t main() {
long long vals[5], ans[7];
for (long long i = 1; i <= 4; i++) {
cout << "? " << i << " " << i + 1 << "\n";
fflush(stdout);
cin >> vals[i];
}
long long flag = 0;
for (long long i = 1; i <= 3; i++)
if ((v... | 3 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, i, ans;
cin >> n;
vector<long long> a(n);
for (i = 0; i < n; i++) cin >> a[i];
ans = a[n - 1];
vector<long long> v(n);
v[n - 1] = a[n - 1];
for (i = n - 2; i >= 0; i--) {
v[i] = v[i + 1] + a[i];
ans = max(ans, v[i]);
}
... | 1 |
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
long long arr[100003];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> arr[i];
sort(arr, arr + n);
reverse(arr, arr + n);
long long a = 0, b = 0;
for (int i = 0; i < n; i++) {
if (a <= b)
a += arr[i];
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100111;
const int INF = 0x7f7f7f7f;
int cases;
char str[MAXN];
int main() {
int cntl = 0, cntr = 0, pos = 0, cnt1 = 0;
scanf("%s", str);
int len = strlen(str);
for (int i = len - 1; i >= 0; i--) {
if (str[i] == '#') {
pos = i;
break;... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
long long b;
const int MAXN = 200000 + 100;
long long a[MAXN], p[MAXN];
template <typename T>
T binary_search(T lower_bound, T upper_bound, bool (*checker)(T)) {
T middle;
while (lower_bound < upper_bound) {
middle = (lower_bound + upper_bound) >> 1;
i... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, m, q, a[501][501], x, y, s, ans;
vector<int> v;
int main() {
ios::sync_with_stdio(false);
cin >> n >> m >> q;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) cin >> a[i][j];
for (int p = 1; p <= q; p++) {
cin >> x >> y;
if (a[x][y] == 1)... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e18 + 5;
long long int dp[51], fact[51];
inline long long int mult(long long int a, long long int b) {
long long int r;
try {
r = a * b;
} catch (const std::exception &e) {
return INF;
}
if (r > INF) {
return INF;
}
retur... | 9 |
#include <bits/stdc++.h>
using namespace std;
template <class T, class T1>
void chkmin(T &x, const T1 &y) {
return x > y ? x = y, 1 : 0;
}
template <class T, class T1>
void chkmax(T &x, const T1 &y) {
return x < y ? x = y, 1 : 0;
}
const int MAXN = (1 << 20);
int n;
pair<int, int> a[MAXN];
int main_dir[MAXN];
vecto... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
n % 2 == 0 ? cout << "white 1 2" : cout << "black";
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5, inf = 1e9 + 7;
long long n, k, par[N], cur, pos[N], sz[N], in[N];
vector<long long> h[N];
inline long long expo(long long n, long long k, long long p = inf) {
long long r = 1;
for (; k; k >>= 1) {
if (k & 1) r = r * n % p;
n = n * n ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 150 + 5;
const int MAXD = 50 + 5;
const int mod = 51123987;
inline void add_mod(int &a, int b) {
a += b;
if (a >= mod) a -= mod;
}
char s[MAXN];
int f[MAXN][MAXD][MAXD][MAXD], res[MAXD][MAXD][MAXD];
int main(void) {
int n;
scanf("%d%s", &n, s + 1);
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int bas = 23333;
const long long mod = 9999999999973ll;
int N, M, S[26], L[555];
char C[255][255];
long long H[26], W[255][255][255], G[555];
int manacher(int n) {
int k = 0, m = 0, res = 0;
memset(L, 0, sizeof(L));
for (int i = 1; i <= n; i++) {
if (G[i] ==... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 20;
const int INF = 1e9 + 7;
const double eps = 1e-5;
int main() {
int t;
cin >> t;
while (t--) {
int n, k;
cin >> n >> k;
if (n % 2) {
int d;
for (int i = 2; i <= n; i++) {
if (n % i == 0) {
d = i;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int A = 26;
int n;
string s[N];
int cnt[A];
bool cmp(const string& x, const string& y) {
return ((int)x.size()) > ((int)y.size());
}
void die() {
cout << "NO\n";
exit(0);
}
vector<int> g[N];
int was[A], have[A], in[A];
string result;
void d... | 6 |
#include <bits/stdc++.h>
using namespace std;
vector<char> vec[200];
vector<string> str;
void func(int c) {
vector<string> ptr;
ptr = str;
int f = 1;
for (int i = 0; i < vec[c].size(); i++) {
ptr[i] += vec[c][i];
}
for (int i = 0; i + 1 < ptr.size(); i++) {
if (ptr[i] > ptr[i + 1]) {
f = 0;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ld = long double;
template <typename T>
inline T in(int t) {
T n;
cin >> n;
return !t ? n : n + t;
}
const int maxn = 53;
vector<int> adj[maxn], a(maxn, 0);
bool visited[maxn];
void dfs(int v) {
visited[v] = true;
for (int u : adj[v... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
for (int i = 0; i < n; i++) cout << a[i] << " ";
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> a[200005];
struct edge {
int to, nxt;
} e[200005];
int hed[200005], cnt;
inline void add(int u, int v) {
e[++cnt] = (edge){v, hed[u]};
hed[u] = cnt;
}
int num[200005], ru[200005];
int sg[200005], tag[200005], dep[200005];
inline void topo() {
q... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
int n, m, r[maxn], c[maxn];
string str[maxn];
long long ans;
int main() {
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> str[i];
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
if (str[i][j] == '*') r[i]++, c[j]++;
for (in... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
inline int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
ios_base::sync_with_stdio(false);
int N, K;
cin >> N >> K;
int g;
cin >> g;
for (int i = 1; i < N; i++) {
int x;
cin >> x;
g = gcd(g, x... | 5 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long int n;
cin >> n;
vector<int> x;
long long int a, b;
a = 0;
b = 0;
for (int i = 0; i < n; i++) {
long long int l;
cin >> l;
x.push_back(l);
if (l % 2 != i % 2) {
if (i % 2 == 0)
a++;
else
b++;... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int8_t INFC = 0x3f;
const int16_t INFS = 0x3f3f;
const int32_t INF = 0x3f3f3f3f;
const int64_t INFL = 0x3f3f3f3f3f3f3f3fLL;
const array<string, 12> tones = {"C", "C#", "D", "D#", "E", "F",
"F#", "G", "G#", "A", "B", "H"};
int getDi... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXN = 100009;
int t, n;
int main() {
char ch[200];
cin >> ch;
int len = strlen(ch);
int ans = 0;
for (int i = 0; i < len; i++) {
if (ch[i] == 'Q') {
for (int j = i + 1; j < len; j++) {
if (ch[j] == 'A') {
... | 0 |
#include <bits/stdc++.h>
const int maxn = 1000;
char s[maxn], t[maxn];
int main() {
while (~scanf("%s%s", &s, &t)) {
getchar();
int i;
if (strlen(s) != strlen(t)) {
printf("No\n");
continue;
}
for (i = 0; i < strlen(s); i++) {
if (s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i]... | 1 |
#include <bits/stdc++.h>
using namespace std;
const string ORDER = "DLRU";
const string REV_ORDER = "URLD";
const int DX[] = {1, 0, 0, -1};
const int DY[] = {0, -1, 1, 0};
struct TPosition {
int X;
int Y;
};
struct TParent {
char C;
TPosition P;
};
char Rev(char c) { return ORDER[REV_ORDER.find(c)]; }
int n, m,... | 4 |
#include <bits/stdc++.h>
long long int arr[100005];
int main() {
long long int n, s, t, i, cnt = 0, x;
scanf("%lld %lld %lld", &n, &s, &t);
for (i = 1; i <= n; i++) {
scanf("%lld", &arr[i]);
}
for (i = s; i <= n; i++) {
x = arr[i];
++cnt;
if (s == t) {
printf("0\n");
return 0;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long maxinput = 7005;
long long a[maxinput], b[maxinput];
set<long long> myset;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n;
cin >> n;
long long temp[n];
for (long long i = 0; i < n; i++) {
cin >> a[i];
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int clrsvis[100005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin >> n >> m;
int clr[100005];
vector<int> clrindx[100005];
vector<int> adj[100005];
for (int i = 0; i < n; i++) {
cin >> clr[i];
clrindx[clr[i]].push_back(... | 4 |
#include <bits/stdc++.h>
using namespace std;
int q, n;
bool ip(int n) {
int i;
if (n == 1) {
return 1;
}
for (i = 2; i * i <= n; i++) {
if (!(n % i)) {
return 0;
}
}
return 1;
}
int main() {
scanf("%d", &q);
while (q--) {
scanf("%d", &n);
if (n % 4 == 3) {
if (n < 15) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
namespace io {
const int Sz = 1 << 13;
char ibuf[Sz], *ed = ibuf + Sz, *ips = ed - 1;
int getchar() {
if (++ips == ed) ed = ibuf + fread(ips = ibuf, 1, Sz, stdin);
if (ips < ed)
return *ips;
else
return EOF;
}
} // namespace io
int read() {
int x = 0, f = 1... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, k, q, a, b, i, ans = 0;
cin >> n >> k >> q;
vector<long long int> v(200005, 0);
vector<long long int> vsu(200005, 0);
vector<long long int> vzo(200005, 0);
while (n--) {
cin >> a >> b;
v[a] += 1;
v[b + 1] -= 1;
}
for... | 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.