solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
// {{{ Template
/*CYJian yyds!*/
/*ldx gg txdy!*/
/*sto karry,tiger,lsqs orz*/
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef double db;
typedef long long ll... | 21 |
#include <bits/stdc++.h>
using namespace std;
const long long mx = 1e5 + 1;
vector<long long> par(mx);
long long find(long long a) {
if (a != par[a]) par[a] = find(par[a]);
return par[a];
}
int main() {
vector<long long> size(mx);
long long n, m, k, u, v, w, a, b, x, y;
cin >> n >> m >> k;
vector<long long>... | 10 |
#include <bits/stdc++.h>
using namespace std;
int MODP(long long x) {
int r = x % 1000000007;
if (r < 0) r += 1000000007;
return r;
}
template <class T>
class BinaryIndexedTree {
vector<T> val;
int n, minIndex, maxIndex;
public:
BinaryIndexedTree(int n) : BinaryIndexedTree(1, n) {}
BinaryIndexedTree(int... | 12 |
#include <bits/stdc++.h>
const int magicconst = 73743071;
using namespace std;
long long a[2], x, y, b[2];
bool check(long long u, long long v) {
long long det = x * x + y * y;
long long q = x * v - u * y;
long long w = u * x + y * v;
return (q % det == 0 && w % det == 0);
}
int main() {
scanf("%I64d%I64d%I64... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int b = 0, c = 0, n;
cin >> n;
long long int a[n];
for (long long int i = 0; i < n; i++) {
cin >> a[i];
}
for (long long int i = 0; i < n; i++) {
if (a[i] == 0) {
c = c + b;
} else {
b++;
}
}
cout << c;
re... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
class CRB {
public:
CRB() { ans.clear(); };
~CRB() { ans.clear(); };
void read() {
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
}
void solve() {
sort(a, a + n);
int cnt = 0, i;
for (i = 0; i < n; i++)
if (a[i] < ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k, n, w;
long int sum = 0;
cin >> k >> n >> w;
for (int i = 1; i <= w; i++) sum = sum + i * k;
if (sum > n)
cout << sum - n;
else
cout << "0";
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long int n, q, tipo;
long long int Z[7][13][100003];
long long int BIT[7][13][100003];
long long int v[100003];
void update(long long int b, long long int s, long long int u,
long long int x) {
for (long long int i = u; i <= n; i += i & -i) BIT[b][s][i] +... | 13 |
#include <bits/stdc++.h>
using namespace std;
void Yahia74() {
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
}
const int N = 2e5 + 74, M = 1e5 + 74, OO = 0x3f3f3f3f;
int main() {
Yahia74();
long long x, y, m;
cin >> x >> y >> m;
long long cnt = 0, cnt2 = 0;
if (x >= m || y >= m) return c... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long w, l, a[100001], t;
int main() {
ios_base::sync_with_stdio(false);
cout.precision(30);
cout.tie(0);
cin.tie(0);
cin >> w >> l;
for (__typeof(w) i = (1) - ((1) > (w)); i != (w) - ((1) > (w));
i += 1 - 2 * ((1) > (w)))
cin >> a[i], t += (i <= ... | 11 |
#include <bits/stdc++.h>
using namespace std;
unsigned int read() {
unsigned int rt = 0;
char c = getchar();
while (c < '0' || c > '9') c = getchar();
while (c >= '0' && c <= '9') {
rt = rt * 10 + c - '0';
c = getchar();
}
return rt;
}
struct Edge {
unsigned int to, next;
} ed[1000005 * 2];
unsign... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, A[100], B[100], v;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) scanf("%d", &A[i]);
for (int i = 0; i < m; i++) scanf("%d", &B[i]);
sort(A, A + n);
sort(B, B + m);
if (A[n - 1] >= B[0]) {
cout << -1;
return 0;
}
if (A[0... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
while (n--) {
int a, b;
cin >> a >> b;
if (a >= b)
cout << b << endl;
else {
int yu_shu = b % a;
b -= yu_shu;
int chu = b / a;
long long res = 0;
for (int i = 0; i < (a - yu_shu); i++) r... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> a(n), b(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
}
sort(a.begin(), a.end());
sort(b.begin(), b.e... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010, mo = 1e9 + 7;
const double LOG = log(2);
int n, q, l, r, s[maxn], sa[maxn], rk[maxn], h[maxn], cnt, LG[maxn];
long long e[maxn], ha[maxn * 2][22];
int rmq[maxn][22], ex[22];
vector<int> T[maxn];
void Init() {
scanf("%d", &n);
for (int i = 1; i <... | 21 |
#include <bits/stdc++.h>
using namespace std;
long long prime[7] = {2, 3, 5, 7, 11, 13};
long long ans[10000];
long long ak = 0;
long long N;
long long v;
int flag[7];
int maxx_fl[7];
void dfs(long long top, long long d, long long ap, bool fla) {
if (ap > 2 * v * v)
return;
else if (d == -1 && fla) {
int i,... | 15 |
#include <bits/stdc++.h>
const long long INF = 1e18 + 10;
const long long NINF = -INF - 1;
using namespace std;
int a[110], b[110];
char s[110], s1[110];
int main() {
ios::sync_with_stdio(false);
int n;
cin >> n >> s;
int max = 0;
for (int i = 0; i < n; ++i) {
if (s[i] == '1') max++;
}
for (int i = 0;... | 5 |
#include <bits/stdc++.h>
int a[101], p[101], v[101];
int n, w;
void sort(int l, int r);
int main() {
std::istream& is = std::cin;
std::ostream& os = std::cout;
is >> n >> w;
for (int i = 1; i <= n; i++) {
is >> a[i];
p[i] = i;
v[i] = 0;
}
sort(1, n);
for (int i = 1; i <= n; i++) {
v[p[i]] ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
bool checker = true;
bool chuj = false;
long long sol = 0;
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
c... | 0 |
#include <bits/stdc++.h>
using namespace std;
int dp[2][27][27];
int forb[26][26];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
string a;
cin >> a;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
char a, b;
cin >> a >> b;
forb[a - 'a'][b - 'a'] = forb[b - 'a'][a - 'a'] = 1;
}
if (... | 8 |
#include <bits/stdc++.h>
using namespace std;
int a[200005];
int b[200005];
int dp[200005], last[200005], cnt[200005], all[200005], st[200005], ed[200005];
int main() {
int t, n, m, ans;
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i ... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, i;
cin >> n;
long long int a[n + 1];
for (i = 1; i <= n; i++) cin >> a[i];
long long int left = 1, right = n, last;
vector<char> v;
if (a[left] < a[right]) {
last = a[left];
left++;
v.push_back('L');
} else {
las... | 5 |
#include <bits/stdc++.h>
using namespace std;
int abs(int x) {
if (x < 0) return -x;
return x;
}
int addmod(int v1, int v2) {
int v3 = v1 + v2;
if (v3 >= 1000000007) v3 -= 1000000007;
return v3;
}
int cc[100];
int dp[400006];
int endat[400006];
vector<pair<int, int> > v[1000005];
int main() {
int n, m;
sc... | 11 |
#include <bits/stdc++.h>
int dx[] = {0, 0, 1, -1, 2, 2, -2, -2, 1, -1, 1, -1};
int dy[] = {1, -1, 0, 0, 1, -1, 1, -1, 2, 2, -2, -2};
using namespace std;
long long int mem[1010][1110];
long long int com(long long int n, long long int k) {
if (k > n) {
return 0;
}
if (k == n || k == 0) {
return 1;
}
if... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10;
const long long inf = 1e18 + 10, mod = 1e9 + 7;
int a[N];
int main() {
ios_base ::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int q;
cin >> q;
while (q--) {
int n, ans = 0;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
... | 8 |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:227420978")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const long long Mod = 1000000007LL, INF = 1e9, LINF = 1e18;
const long double PI = 3.141592653589793116, EPS = 1e-9,
... | 11 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 1e5 + 7;
const int inf = INT_MAX / 2;
const long long INF = LLONG_MAX / 3;
const int MOD = 1e9 + 7;
const double eps = 1e-6;
const string cars[] = {"🚗", "🚕", "🚙"};
signed main() {
cout <... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, t;
cin >> s >> t;
reverse(s.begin(), s.end());
cout << (s == t ? "YES" : "NO");
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
int n, m, len, k, a[maxn], sum[maxn], pre[maxn];
int main() {
scanf("%d%d%d%d", &n, &m, &len, &k);
for (int i = 1; i <= n; i++) {
scanf("%1d", &a[i]);
sum[i] = sum[i - 1] + a[i];
}
int i = len, num = 0;
while (i <= n) {
if (sum... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200500;
int n, m, ans, idx;
int q[maxn], vis[maxn], t[2][maxn * 4], tag[2][maxn * 4], in[maxn], out[maxn],
dep[maxn], a[maxn], id[maxn];
vector<int> g[maxn];
void down(int i) {
for (int op = 0; op <= 1; op++) {
if (tag[op][i]) {
t[op][i << 1... | 12 |
#include <bits/stdc++.h>
const int maxn = 100010, maxm = 100010, lim = 1000010, st = 131071;
int n, m, q, c[maxm];
struct edge {
int id, to;
edge* next;
} E[maxm * 2], *ne = E, *first[maxn];
void link(int i, int u, int v) {
*ne = (edge){i, v, first[u]};
first[u] = ne++;
}
unsigned long long d[maxn];
int las, ve... | 26 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s;
cin >> s;
if (s.size() >= 0 and s.size() <= 9) {
n = stoi(s);
if (n % 4 == 0)
cout << 4;
else
cout << 0;
return 0;
}
string s2 = s.substr(s.size() - 2, s.size());
n = stoi(s2);
if (n % 4 == 0)
cou... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
scanf("%d", &n);
int a = 0, b = 0, c = 0, d = 0;
int tem = n;
if (n % 2 == 0) {
a = n / 2;
for (int i = 0; i < a; i++) printf("1");
} else {
a = (n - 3) / 2;
printf("7")... | 1 |
#include <bits/stdc++.h>
using namespace std;
int p[1000005];
int num[5];
int main() {
int n;
scanf("%d", &n);
int ans;
for (int i = 1; i <= n; i++) {
scanf("%d", &p[i]);
num[p[i]]++;
}
int mix;
mix = min(num[1], num[2]);
num[3] += mix;
num[1] -= mix;
num[2] -= mix;
ans = mix;
if (num[1]... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int M = 5e6 + 5;
const long long int mod = 1e9 + 7;
const long long int inf = 9e18;
const double pi = 3.14159265358979323846;
long long int t, n, m, x, sum, k, p, u = 0;
string s, z, ans = "";
long long int P[10000005] = {0};
bool comp(long long int a, long long int b... | 0 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void y_k() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int32_t main() {
y_k();
long long n;
cin >> n;
long long *a = new long long[n];
;
vector<long long> v;
long long s ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, m, a, c1 = 0, c2 = 0, ans = 0, i;
cin >> n >> m >> k;
for (i = 1; i <= n; i++) {
cin >> a;
if (a == 1)
c1++;
else
c2++;
}
if (c1 > m)
ans = c1 - m;
else if (c1 < m)
k += m - c1;
if (c2 > k) ans += c2 - k;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mxn = 100006;
int n;
int a[mxn];
bool f[mxn];
int l, r;
struct {
int c[mxn];
int odd = 0;
int neg = 0;
int npal = 0;
void set(int x, int val) {
odd -= c[x] & 1;
neg -= c[x] < 0;
c[x] += val;
odd += c[x] & 1;
neg ... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, k;
cin >> n >> k;
string s;
cin >> s;
if (s.size() == 1 && k) {
cout << '0' << endl;
exit(0);
}
if (k > 0 && s[0] != '1') {
s[0] = '1';
k--;
}
for (int i = 1; i < s.size(... | 2 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, a, b, c, d;
cin >> n >> a >> b >> c >> d;
int k = n * (a - b);
int m = n * (a + b);
if (k > (c + d) || m < (c - d))
cout << "NO"
<< "\n";
else
cout << "Yes"
<< "\n";
}
int main() {
ios::sync_with_stdio(0);
cin.... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int temp1, temp2;
cin >> temp1;
long long Count = 0;
long long subcount = 1;
for (int i = 1; i < n; i++) {
cin >> temp2;
if (temp1 == temp2) {
subcount++;
} else {
temp1 = temp2;
Count += subcount * (... | 5 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
int ans[100][100], n, m;
string str[100][100];
char tmp[100][100];
int main() {
scanf("%d%d", &n, &m);
ans[1][1] = 0;
ans[1][1] = 0;
str[1][1] = ".\n";
ans[1][2] = 0;
str[1][2] = "..\n";
ans[1][3] = 0;
str[1][3] = "...\n";
ans... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 9;
long long int t_blue, t_red;
long long int n, a[N], red[N], blue[N], black[N], sz[N];
vector<pair<int, int>> g[N];
void dfs(int n, int edg) {
if (a[n] == 2) {
blue[edg] = 1;
}
if (a[n] == 1) {
red[edg] = 1;
}
if (a[n] == 0) {
bla... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 5;
const long long int inf64 = 1e18 + 5;
const int MAX = 105;
bool vis[MAX];
vector<int> adj[MAX][MAX];
void dfs(int x, int col) {
vis[x] = true;
for (auto v : adj[col][x]) {
if (!vis[v]) dfs(v, col);
}
}
int main() {
ios::sync_with_stdio(f... | 6 |
#include <bits/stdc++.h>
using namespace std;
unsigned long long vecSum(const vector<unsigned long long> &vec) {
unsigned long long sum = 0;
for (unsigned long long i = 0; i < vec.size(); i++) {
sum += vec[i];
}
return sum;
}
int main() {
unsigned long long nk, qk;
unsigned long long nn, qq;
unsigned ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, m, q;
cin >> n >> m >> q;
int v[n + 2][m + 2], row[n + 2], col[m + 2];
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> v[i][j];
}
}
char... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
long long n, m, k;
cin >> n >> m >> k;
long long a[10007];
for (int i = 1; i <= n; i++) cin >> a[i];
if (k >= m) k = m - 1;
long long ptr1 = k + 1, ptr2 = n;
ptr1 = (ptr1 > 0 ? ptr1 : 0);
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int n, m;
cin >> n;
vector<int> chess1(n), chess2(n);
for (int i = 0; i <= int((chess1).size()) - 1; i++)
cin >> chess1[i] >> chess2[i];
cin >> m;
vector<int> pro1(m), pro2(m);
for (int i = 0; i <= int((pro1).siz... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
long int arr[n][m];
long int dp1[n][m];
long int dp2[n][m];
long int dp3[n][m];
long int dp4[n][m];
long int workout = 0;
long int left, right;
long int hot;
for (long int i = 0; i < n; ++i) {
for (long int j =... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
const int mod = 1000000007;
char s[N];
long long a, b, c, d, ly, ry, lz, rz;
long long gao(long long x) {
ly = b, ry = c;
lz = c, rz = d;
ly = max(ly, lz - x + 1);
if (ly > ry) return 0;
long long ans = 0;
if (x + ly <= rz) {
ans += ((... | 10 |
#include <bits/stdc++.h>
using namespace std;
inline long long flr(long long p, long long v) {
if (p % v == 0) return p;
return (p / v + 1) * v;
}
int main() {
ios_base::sync_with_stdio(false);
long long te, a, b, c, d, x, y, t;
cin >> te;
while (te--) {
cin >> a >> b >> c >> d;
if (c == 0 && d == 1... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
const long long MOD = 1000000007;
const long long NO_OPERTATION = -1;
const double eps = 1e-8;
const int MAX = 100010;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2e9 + 1;
mt19937 gen(time(0));
int main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
int n;
cin >> n;
map<int, int> ma;
int cnt2 = 0, cnt4 = 0, cnt6 = 0, cnt8 = 0;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
ma[x]... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d, e, q1, q2, q3;
string x, y;
vector<int> v;
cin >> a;
while (a--) {
cin >> b >> c >> d;
int mid = max(b, c) - (min(b, c) - 1);
if ((b < mid && c < mid) || (b > mid && c > mid)) {
cout << -1 << endl;
} else if (((mi... | 0 |
#include <bits/stdc++.h>
using namespace std;
void getint(int &v) {
char ch, fu = 0;
for (ch = '*'; (ch < '0' || ch > '9') && ch != '-'; ch = getchar())
;
if (ch == '-') fu = 1, ch = getchar();
for (v = 0; ch >= '0' && ch <= '9'; ch = getchar()) v = v * 10 + ch - '0';
if (fu) v = -v;
}
const double eps = ... | 19 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, k, a, l, i;
int main() {
cin >> n >> m >> k;
for (i = 1; i <= n; i++) {
cin >> a;
if (a == 1 && m > 0) {
m -= 1;
} else {
if (a == 2 && k > 0) {
k -= 1;
} else {
if (a == 2 && m > 0) {
m -= 1;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, cnt = 0, c;
cin >> n >> k;
for (int i = 0; i < n; ++i) {
cin >> c;
if (5 - c >= k) cnt++;
}
cout << cnt / 3;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
const long long MOD = 1000000007;
const long long INF = (long long)1e9 + 5;
int N, d[MAXN], pa[MAXN], run[2 * MAXN];
pair<int, int> ord[MAXN];
int trans(int id) {
id++;
if (id > N) {
id -= N;
return id * 2 - 1;
} else {
return id *... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 305;
int A[N], n;
int main() {
scanf("%d", &n);
int sum = 0;
for (int i = 1; i <= n; ++i) {
scanf("%d", A + i);
sum += A[i];
}
char lastOP = '-';
while (sum) {
for (int i = 1; sum && i <= n; ++i) {
if (A[i] && lastOP != 'P') {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n;
if (n == 0)
cout << " O-|-OOOO ";
else
for (int i = n; i > 0;) {
m = i % 10;
if (m == 0) cout << " O-|-OOOO " << endl;
if (m == 1) cout << " O-|O-OOO " << endl;
if (m == 2) cout << " O-|OO-OO " << endl... | 0 |
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define maxN 1534
int n, m;
int a[maxN][maxN], b[maxN][maxN], ord[maxN], negcnt[maxN];
bool isequ[maxN], used[maxN];
vector<int> seqa[maxN], seqb[maxN];
void solve(vector<int> id) {
bool sorted = true;
for (int i = 1; i < id.size(); i++)
if ... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int N = 505;
int n, m, flag;
int A[N][N];
int f[N];
void dfs(int x, int fa, int opt) {
if (f[x] >= 0) {
if (f[x] != opt) flag = 1;
return;
}
f[x] = opt;
for (int i = 1; i <= n; i++) {
if (i == fa || i == x) continue;
if (A[x][i]) continue;
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int rd() {
char c = getchar();
int x = 0;
while (!(c >= '0' && c <= '9')) c = getchar();
while (c >= '0' && c <= '9') {
x = x * 10 + (c - '0');
c = getchar();
}
return x;
}
const int N = 4005;
int n, m, a[N][N], s[N][N], dp[N][N], p[N][N];
int val(int u,... | 18 |
#include <bits/stdc++.h>
using namespace std;
inline long long gi() {
register long long data = 0, m = 1;
register char ch = 0;
while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
if (ch == '-') {
m = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
data = (data << 1) + (data << 3)... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200 + 7, M = 5e4 + 207, INF = 2e9 + 7, Lg = 9;
vector<int> adj[N];
vector<pair<int, int>> e;
set<pair<int, int>, greater<pair<int, int>>> st;
bool mark[N];
int from[M], to[M], s[M], g[M], d[N], par[Lg][N], mx[Lg][N];
int Max(int x, int y) { return (s[x] > s[y]... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long n, m = 0, k = 0;
bool test = false, test1 = false;
long long const N = 1e6 + 7;
long long const oo = 1000000007;
vector<long long> v, v1;
vector<pair<long long, long long> > vv;
map<long long, long long> my;
map<long long, long long> my1;
priority_queue<long long>... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long MaxN = 100050;
template <class t>
inline void read(t &s) {
s = 0;
register long long f = 1;
register char c = getchar();
while (!isdigit(c)) {
if (c == '-') f = -1;
c = getchar();
}
while (isdigit(c)) s = (s << 3) + (s << 1) + (c ^ 48), c... | 18 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
int dx[] = {0, 0, 1, -1, 1, -1, 1, -1}, dy[] = {-1, 1, 0, 0, 1, -1, -1, 1};
int p[] = {(int)1e9 + 7, (int)1e9 + 9}, q = 311;
using Hash = array<int, 2>;
Hash extend(Hash h, char c) {
for (int i = 0; i < 2; ++i) h[i] = (1ll * h... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
void solve() {
int n, m;
cin >> n >> m;
vector<vector<int>> g(n + 1);
for (int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
g[u].emplace_back(v);
g[v].emplace_back(u);
}
set<pair<int, int>> edges;
vector<bool> visited(... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int A[200005], B[200005], new_val[200005];
int cnt[195][200005];
void add(int k, int p, int val) {
for (p += 1; p < 200005; p += p & (-p)) cnt[k][p] += val;
}
int get(int k, int p) {
int res = 0;
for (p += 1; p > 0; p -= p & (-p)) res += cnt[k][p];
return ... | 16 |
#include <bits/stdc++.h>
using namespace std;
void display(vector<long long> &a) {
for (long long z : a) cout << z << " ";
cout << endl;
}
long long dx[4] = {0, 0, 1, -1};
long long dy[4] = {1, -1, 0, 0};
const long long mod = (long long)1e9 + 7;
const long long INF64 = 3e18;
void smxl(long long &a, long long b) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, a;
cin >> n >> m >> a;
long long x = ceil((double)n / a), y = ceil((double)m / a);
cout << x * y << endl;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAXN = 1.1e5;
int N;
int A[MAXN];
int charL[MAXN][27], charR[MAXN][27];
int rangeL[MAXN], rangeR[MAXN];
int leftPar[MAXN][20];
ll leftParSum[MAXN][20];
int rightPar[MAXN][20];
ll rightParSum[MAXN][20];
const int S = 1 << 17;
int main() {
io... | 27 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
const int MOD = 1000000007;
vector<pair<pair<int, int>, int>> v;
int n;
int a, b, c;
map<string, int> id;
map<int, string> names;
bool ok[50][50];
void read() {
cin >> n;
for (int i = 0, cont = 1; i < n; i++) {
string a1, b1, c1;
cin >> ... | 6 |
#include <bits/stdc++.h>
using namespace std;
void pre() {}
void solve() {
long long int n;
cin >> n;
long long int arr[3 * n];
long long int ans[3 * n];
long long int mi = 1e10, ma = 0;
for (int i = 0; i < n; i++) {
cin >> arr[i];
arr[n + i] = arr[i];
arr[2 * n + i] = arr[i];
mi = min(arr[i... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, l;
cin >> a >> b >> l;
if (l <= min(a, b)) {
printf("%.8lf\n", (double)l);
return 0;
}
if (l <= max(a, b)) {
printf("%.8lf\n", (double)min(a, b));
return 0;
}
double alpha1 = 0, alpha2 = acos(0);
for (int _n(1000), iter... | 17 |
#include <bits/stdc++.h>
using namespace std;
long long sum[1000001];
int a[1000001];
long long dp[1000000][3];
int pos[1000000][3];
int l[10000000];
int main() {
int n;
int k;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
sum[i] = sum[i - 1] + a[i];
... | 7 |
#include <algorithm>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define pii pair<int, int>
#define mii map<int, int>
#define pis pa... | 0 |
#include <bits/stdc++.h>
using namespace std;
void func(long long &a, long long &b) {
bool ha = true;
while (ha) {
if (a == 0 || b == 0) {
return;
} else {
if (a >= 2 * b) {
a %= 2 * b;
} else {
if (b >= 2 * a) {
b %= 2 * a;
} else {
return;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
;
int n;
cin >> n;
n *= 2;
int a[n + 1];
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int ans = 0;
for (int i = 1; i <= n; i++) {
if (a[i]) {
int j;
for (j = i + 1;; j++) {
if (a... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 100;
int n, u, r;
vector<int> a, b, k, p;
long long ans = 0;
inline void brute(int pos, const vector<int> &now, bool Xor) {
if (!((u - pos) & 1)) {
long long sum = 0;
for (int i = 0; i < n; i++) sum += (long long)now[i] * (long long)k[i];
ans ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 3;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
string s;
cin >> s;
long long n = s.size(), ans = 0;
for (long long i = 0; i < n; i++) {
long long R = n;
for (long long j = i; j < min(i + 9, n); j++) {
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int idx1 = -1, idx2 = -1, c, ans;
string s1, s2;
int main() {
cin >> c;
for (int i = 1; i < c; i++) {
int cur = i;
bool f = true;
for (int j = 1; j <= c - 2; j++) {
if ((cur - 1) % c == 0) f = false;
if (j != c - 2) cur = (cur * i) % c;
}
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const long long INF = 1e18 + 7ll;
vector<int> g[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
for (int i = 0; i < n; ++i) g[i].clear();
vector<int> p(n), ... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b;
cin >> n >> a >> b;
a += b;
while (a < 0) a += n;
cout << a % n + (a % n == 0) * n;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 60;
int a[100][100];
int n, m;
int cnt0 = 0;
int cnt1 = 0;
unsigned long long ans = 0;
void input() {
cin >> n >> m;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> a[i][j];
}
}
}
void rows() {
for (int i = 0; i < n;... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int BITS = 24;
const int VALMAX = (1 << BITS);
int N;
long long ans, cnt[VALMAX + 5];
int main() {
cin >> N;
for (int i = 1; i <= N; i++) {
string s;
cin >> s;
int c1 = 1 << (s[0] - 'a');
int c2 = 1 << (s[1] - 'a');
int c3 = 1 << (s[2] - 'a');
... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long r, c, i, j;
cin >> r >> c;
if (r == c && c == 1) {
cout << "0\n";
return 0;
}
for (i = 0; i < r; i++) {
for (j = 0; j < c; j++)
(c >= r) ? (cout << (i + 1) * (r + j + 1) << " ")
: (cout << (j + 1) * (c + i + ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int const N = 1000100;
int a[N];
int b[N], m;
bool vis[N];
int main() {
int n, x;
scanf("%d", &n);
for (int i = 0; i < (n); ++i) {
scanf("%d", &x);
a[x] = 1;
}
int c = 0;
m = 0;
for (int i = 1; i <= (1000000); ++i) {
int s = 1000000 - i + 1;
if... | 9 |
#include <bits/stdc++.h>
using namespace std;
int x[5000], y[5000], z[5000];
int main() {
int n, m, k;
cin >> n;
for (int i = 0; i < n; i++) cin >> x[i];
cin >> m;
for (int i = 0; i < m; i++) cin >> y[i];
cin >> k;
for (int i = 0; i < k; i++) cin >> z[i];
int a, b;
cin >> a >> b;
sort(x, x + n);
s... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 2;
const int BLOCK = 340;
const int MAX_BLOCK_SIZE = 340;
int jumps[MAX_BLOCK_SIZE][BLOCK], landing[MAX_BLOCK_SIZE][BLOCK];
int n, m, a[N];
void preProcess() {
for (int i = n - 1; i >= 0; i--) {
int bucketNo = i / BLOCK, starting = bucketNo * BLOCK... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
cout << n % 2;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long ara[300005], vis[300005];
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long n, m, k, b;
while (cin >> n >> b) {
vector<pair<long long, long long> > v;
for (long long i = 2; i * i <= b; i++) {
if (b % i ==... | 9 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
if (a % b) return gcd(b, a % b);
return b;
}
template <typename T>
T lcm(T a, T b) {
return (a * (b / gcd(a, b)));
}
vector<string> tokenizer(string str, char ch) {
std::istringstream var((str));
vector<string> v;
string t... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, cnt;
char ch;
int main() {
scanf("%d", &n);
ch = getchar();
for (int i = 1; i <= n; ++i) {
ch = getchar();
if (ch == '8') cnt++;
}
printf("%d", min(cnt, n / 11));
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<long long> o;
for (long long i = 0; i < 14; i++) {
long long aux;
scanf("%lld", &aux);
o.push_back(aux);
}
long long resp = 0;
for (long long i = 0; i < 14; i++) {
vector<long long> n = o;
if (n[i] != 0) {
long long a ... | 3 |
#include <bits/stdc++.h>
using namespace std;
string s, t;
int used[3000], needed[3000];
inline bool check() {
int mn = 2e9;
for (char j = 'a'; j <= 'z'; j++) {
if (needed[j - 'a'] && used[j - 'a'] < needed[j - 'a']) {
return false;
}
if (needed[j - 'a']) mn = min(mn, used[j - 'a'] / needed[j - 'a... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 55;
int num[N][N], id[N][N], st[N], r[N], link[N * 2], top;
int cur;
bool val;
inline bool cmp(int x, int y) { return (num[cur][x] < num[cur][y]) != val; }
void solve(int n) {
memset(link, 0, sizeof(link));
memset(r, 0, sizeof(r));
for (int i = 1; i <= n... | 27 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const ll mod = 1e9 + 7;
ll mod_pow(ll b, ll e) {
ll r = 1;
for (; e; e >>= 1, b = b * b % mod) {
if (e & 1) r = r * b % mod;
}
return r;
}
void solve() {
int n, m;
cin >> n >> m;
vector<int> a(n);
for (in... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long long MaxN = 310002;
long long n, k;
string v;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> v;
n = v.size();
for (int i = 0; i < n; i++) {
if (v[i] != 'a' && v[i] != 'e' && v[i] != 'i' && v[i] != 'o' &&
v[i] != 'u' && v[i] !=... | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.