solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int ans=0;
int l,r;
l=n/2;
r=n/2;
if(n%2==1)
{
l+=1;
}
int r1=1;
if(l%2==0)
{
r1=l+1;
}
else
{
r1=l+1;
}
int r2=1;
if(r%2==0)
{
r2=r+1;
}
else
{
r2=r+1;
}
if(n%2==1)
{
ans=2*r1*r2;
cout<<ans<<endl;... | 5 |
#include <bits/stdc++.h>
using namespace std;
map<long long, long long> G;
long long grundy(long long msk) {
if (G.find(msk) != G.end()) return G[msk];
long long ret = 0;
set<long long> vis;
for (long long i = (1); i < (32); i++) {
if (!(msk >> i)) break;
long long nmsk = msk;
nmsk &= ((1 << i) - 1)... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int p[n], q[n];
for (int i = 0; i < n; i++) cin >> p[i];
for (int j = 0; j < n; j++) cin >> q[j];
set<int> pirmas, antras;
vector<int> ats;
ats.push_back(-1);
for (int i = 0; i < n; i++) {
if (pirmas.count(q[i]))
... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
template <typename T>
bool cmax(T &a, T b) {
return (a < b) ? a = b, 1 : 0;
}
template <typename T>
bool cmin(T &a, T b) {
return (a > b) ? a = b, 1 : 0;
}
template <typename T>
T read() {
T ans = 0, f = 1;
char ch = getchar();
while (!isdig... | 26 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, y, z, k, which = 0;
long long int mx, my, mz;
mx = my = mz = 1;
cin >> x >> y >> z >> k;
while (k) {
switch (which % 3) {
case 0:
if (x > 1) {
x--;
mx++;
} else
k++;
break;
c... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long mod1 = 1000000007;
const long long mod9 = 998244353;
long long powmod(long long a, long long b, long long mod = mod1) {
long long ans = 1;
while (b--) {
ans = (ans * a) % mod;
}
return ans;
}
long long gcd(long long a, long long b) {
long long ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
int n, m;
int fa[maxn];
int cost[maxn];
int find_fa(int cur) {
if (fa[cur] == cur)
return cur;
else
return fa[cur] = find_fa(fa[cur]);
}
void Union(int node1, int node2) { fa[find_fa(node2)] = find_fa(node1); }
int main() {
cin >> n >... | 5 |
#include <bits/stdc++.h>
using namespace std;
#pragma optimize("g", on)
#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("03")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
const long lon... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1111111;
struct EDGENODE {
int to;
int next;
} edges[maxn];
int head[maxn];
int edge;
void init_edge() {
memset(head, -1, sizeof(head));
edge = 0;
}
void addedge(int u, int v) {
edges[edge].to = v, edges[edge].next = head[u], head[u] = edge++;
e... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int infint = 1e9;
const long long inf = 1e18;
const int MOD = (int)1e9 + 7;
const int MAXN = (int)2e5 + 3;
int n, k, a[MAXN], sub[MAXN], down[MAXN], up[MAXN], black[MAXN], SUB[MAXN],
gt = 0;
vector<int> G[MAXN];
void merge(pair<int, int> &P, int u) {
if (P.first... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
if (n == 0) {
cout << "1";
return 0;
}
n = n % 4;
if (n == 1) {
cout << "8";
} else if (n == 2)
cout << "4";
else if (n == 3)
cout << "2";
else
cout << "6";
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize(3)
int n, p, k;
int a[200000];
int solve() {
cin >> n >> p >> k;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
int sum1;
int sum = 0, cost = 0;
int i = 0;
for (; i < n - 1 && p - cost >= a[i + 1];) {
sum += 2;
... | 6 |
#include <bits/stdc++.h>
const int MAXN = 1e5 * 5;
const int base = 1e9 + 7;
const int N = 2003;
using namespace std;
int n, m;
int cnt, ddem;
int num[N], low[N], cl[N], p[N];
int sl[N], sz[N], Pair[N], dsu[N], id[N];
bool dp[N][N];
vector<int> a[N], c[N];
map<pair<int, int>, int> ma;
void dfs(int u) {
num[u] = low[u... | 19 |
#include <bits/stdc++.h>
int f[3500][2][3500], g[3500][2][3500];
int d[3500], n = 0, b[3500], c[3500];
char s[3500];
int p, a, Ans = 0;
int S(int l, int r) { return 1ll * (l + r) * (r - l + 1) / 2 % 1000000007; }
int inc(int a, int b) { return (a += b) >= 1000000007 ? a - 1000000007 : a; }
int calc(int C) {
if (C < p... | 25 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[101];
cin >> 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] << " ";
}
cout << endl;
}
| 1 |
#include <bits/stdc++.h>
int n, m, ap, bp;
double ax, bx;
double a[100002], b[100002], l[100002];
double getDis(double ya, double yb) {
double dis = sqrt(ax * ax + ya * ya) +
sqrt((bx - ax) * (bx - ax) + (ya - yb) * (ya - yb));
return dis;
}
int dichotomy(int l, int r, double val) {
int mid = (l + ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 300000 + 5;
int q;
int n;
int hed[maxn];
int to[maxn * 2];
int nex[maxn * 2];
int etot;
int f[maxn][2];
int ans = 0;
int vis[maxn];
void addedge(int u, int v) {
to[etot] = v;
nex[etot] = hed[u];
hed[u] = etot++;
}
void dfs1(int u, int fa) {
f[u][1] ... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e9;
const int MOD = 1e9 + 7;
const long long INF = 1e18;
const long double PI = 3.14159265358979323846;
template <typename T>
void read(vector<T>& a) {
for (int i = 0; i < a.size(); ++i) cin >> a[i];
}
template <typename T>
void print(vector<T>& a) {
fo... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 305001;
const long double PI = acos(-1);
int a[N], idx[N], n;
vector<pair<int, int> > v;
inline void swp(int i, int j) {
v.push_back(make_pair(i, j));
int a = ::a[i];
int b = ::a[j];
::a[i] = b;
::a[j] = a;
idx[a] = j;
idx[b] = i;
}
signed main()... | 9 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
int const N = (1 << 16), mod = 998244353, W = 44759;
int nn = 1, B, invnn;
int n, k, ww[20][N], invww[20][N];
map<int, vector<int>> mp, inv;
inline int pw(int a, int b) {
int res = 1;
for (; b; b ... | 24 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n1, k1;
while (cin >> n1 >> k1) {
long long cnt = 0;
if (k1 % 2 == 1)
cout << 1;
else {
while (k1 % 2 == 0) {
k1 /= 2;
cnt++;
}
cout << cnt + 1;
}
}
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
int v[1000];
int parent[1000];
int r[1000];
void make_set(int v) {
parent[v] = v;
r[v] = 0;
}
int find_set(int v) {
if (parent[v] == v) {
return v;
}
return parent[v] = find_set(parent[v]);
}
void make_pair(int a, int b) {
int pa = find_set(a);
int pb = fi... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2000 + 10;
int N, M;
int R, C;
int X, Y;
char A[MAXN][MAXN];
pair<int, int> dis[MAXN][MAXN];
deque<pair<int, int> > q;
int fx[4] = {0, -1, 0, 1};
int fy[4] = {-1, 0, 1, 0};
int ans;
inline void push(int first, int second, int l, int r, int t) {
if (A[firs... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, val, inc;
cin >> n >> k;
val = k / n;
inc = k % n;
vector<int> v(n, val);
for (int i = n - inc; i < n; ++i) ++v[i];
int c;
for (int i = 0; i < n; ++i) {
c = 0;
for (int j = i; c < n; ++c) {
cout << v[(j + c) % n] << " ";
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int r, g, b;
cin >> r >> g >> b;
cout << max(
27 + 3 * ((int)ceil(r / 2.0)),
max(28 + 3 * ((int)ceil(g / 2.0)), 29 + 3 * ((int)ceil(b / 2.0))));
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int mod = 1000000007;
typedef struct NUM {
int v;
int cnt;
} NUM;
NUM num[10005];
int cnt;
int a[1000005];
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n;
int w, h;
scanf("%d", &n);
for (int i = 0; i <= n... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long p[55];
long long ans;
long long n;
long long h;
void dfs(long long x, long long lev, long long dir) {
ans++;
if (lev == h) return;
long long a, b, c, e, z, l, r, lch, rch;
lch = (x - 1) * 2 + 1;
rch = x * 2;
if (!dir) {
l = (lch - 1) * p[h - lev - ... | 9 |
#include <bits/stdc++.h>
const int oo = 2139063143;
const int N = 101000;
const int P = 1000000007;
using namespace std;
inline void sc(int &x) {
x = 0;
static int p;
p = 1;
static char c;
c = getchar();
while (!isdigit(c)) {
if (c == '-') p = -1;
c = getchar();
}
while (isdigit(c)) {
x = (x... | 14 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using pll = pair<ll, ll>;
const int N = 1010;
int a[N], b[N], n, k;
int findZero() {
for (int i = 1; i <= n; i++)
if (!b[i]) return i;
return -1;
}
int main() {
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++) ... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long int maxDig(long long int n) {
long long int maxDig = 0;
while (n) {
if (n % 10LL > maxDig) maxDig = n % 10LL;
n /= 10;
}
return maxDig;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cout.precision(7);
{
... | 3 |
#include <bits/stdc++.h>
using namespace std;
char str1[200005], str2[200005];
bool cmp(int l, int r, int l1, int r1) {
int i, j;
for (i = l, j = l1; i <= r; i++, j++)
if (str1[i] != str2[j]) return false;
return true;
}
bool check(int l, int r, int l1, int r1) {
if (cmp(l, r, l1, r1)) return true;
if ((r... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
long long inv[200005];
long long power(long long x, long long y) {
long long ans = 1;
for (; y; y >>= 1) {
if (y & 1) ans = ans * x % mod;
x = x * x % mod;
}
return ans % mod;
}
int main() {
long long a1, a2, a3;
scanf("%... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
long long a[100010], S = 0;
long long A = 0, B = 0, ca = 0, cb = 0;
for (long long i = 0; i < n; i++) {
cin >> a[i];
S += a[i];
}
double h = (double)S / 2.0;
for (long long i = 0; i < n; i++) {
if ((double)(A +... | 4 |
#include <bits/stdc++.h>
using namespace std;
int dp[5005][5005];
int ans[5005][5005];
int solve(int l, int r) {
if (dp[l][r]) {
return dp[l][r];
}
if (l == r) {
return dp[l][r] = ans[l][r];
} else {
return dp[l][r] = max({ans[l][r], solve(l, r - 1), solve(l + 1, r)});
}
}
int main() {
ios_base:... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5 * 100 + 5;
const long long inf = 9223372036854775807;
long long dp[2][maxn][maxn], n, m, b, mod, a[maxn];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
cin >> n >> m >> b >> mod;
for (int i = 1; i <= n; i++) {
cin >>... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
const int MAXM = 100010;
const int INF = 0x3f3f3f3f;
int n, m, tot, head[MAXN], one, zero, ans;
struct edge {
int u, v, w, c, next, flag;
edge() {}
edge(int uu, int vv, int ww, int cc, int nx)
: u(uu), v(vv), w(ww), c(cc), next(nx) {
... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long n, m, x;
cin >> n >> m >> x;
vector<vector<long long>> g(n, vector<long long>(m));
for (long long i = 0; i < n; i++)
for (long long j = 0; j < m; j++) cin >> g[i][j];
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int pel(string s) {
string t;
t = s;
reverse(t.begin(), t.end());
if (s == t) return 1;
return 0;
}
string toString(int n) {
ostringstream ost;
ost << n;
ost.flush();
return ost.str();
}
int toInt(string s) {
int r = 0;
istringstream sin(s);
sin >> r... | 6 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 200000;
int n, nbox, boxsz;
int a[MAXN];
long long sum[MAXN + 1];
int nxt[MAXN];
int need[MAXN + 1];
int solve() {
sum[0] = 0;
for (int i = (0); i < (n); ++i) sum[i + 1] = sum[i] + a[i];
int... | 10 |
#include <bits/stdc++.h>
using namespace std;
vector<int> global;
void DFS(int parent, int current, int depth, vector<vector<int>>& graph,
int& max_depth, int& max_ind) {
for (int i = 0; i < graph[current].size(); i++)
if (graph[current][i] != parent)
DFS(current, graph[current][i], depth + 1, grap... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
long long arr[3];
for (long long i = 0; i < 3; i++) cin >> arr[i];
sort(arr, arr + 3);
if (arr[0] + arr[1] < arr[2])
cout << arr[0] + arr[1] << endl;
else
cout << (arr[0] + arr[1] + arr[... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, nh[1000005], sum[1000005], t[1000005], p, root;
pair<int, int> kq;
vector<pair<int, int> > a[1000005];
void home() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
}
void dfs(int u, int p) {
sum[u] += t[u];
if (a[u].size())
for (int j = (0... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int i, j, k;
cin >> k;
if (k == 1) {
cout << "-1\n";
} else {
int a[k];
a[0] = 2;
for (i = 1; i < k; i++) {
a[i] = 3;
}
for (i = 0; i < k; i++) {
cout << a[... | 2 |
#include <bits/stdc++.h>
int n, k;
inline void oil_read(std::istream& r) { r >> n >> k; }
inline int oil_eval(int v) {
int result = 0;
int dev = v;
while (dev > 0) {
result += dev;
dev /= k;
}
return result;
}
inline void oil_print(std::ostream& w, int i) { w << i << std::endl; }
inline void oil_solve... | 7 |
#include <bits/stdc++.h>
using namespace std;
map<double, int> cnt;
double d[200010];
double solve(char s[]) {
int a = 0, b = 0, c = 0;
int now = 1;
for (; s[now] != '+'; now++) {
a *= 10;
a += s[now] - '0';
}
for (now++; s[now] != ')'; now++) {
b *= 10;
b += s[now] - '0';
}
for (now += 2;... | 6 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > v;
vector<int> ans;
vector<int> visited;
priority_queue<int, vector<int>, greater<int> > p;
void dfs(int curr) {
for (int i = 0; i < v[curr].size(); i++) {
int k = v[curr][i];
if (visited[k] == 0) {
p.push(k);
visited[k] = 1;
}... | 7 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int mod0 = 1e9 + 7;
const long long mod1 = 998244353;
const long long mod2 = 1e9 + 9;
const long long mod3 = 2147483647;
const int sz = 2 * 1024 * 1024;
const long long inf = 2 * 1024 * 1024 * 1023 - 1;
const long long INF = inf * inf;
co... | 10 |
#include <bits/stdc++.h>
using namespace std;
int a[200005];
int main() {
int t, m, n, q;
cin >> n >> m;
int cnt = 0;
for (int i = 1; i <= m; i++) {
int x, y;
cin >> x >> y;
if (x > y) swap(x, y);
a[x]++;
if (a[x] == 1) cnt++;
}
cin >> q;
while (q--) {
int te;
cin >> te;
if... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
void print(int a, int b) {
printf("%d %d ", a, b);
return;
}
int main() {
scanf("%d%d%d", &n, &m, &k);
int dir = 1, x = 1, y = 1;
for (int i = 1; i <= k - 1; i++) {
printf("2 ");
if (dir == 1) {
if (y <= m - 1) {
print(x, y);
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, target;
cin >> n >> target;
int adjList[n];
for (int i = 0; i < n - 1; i++) {
cin >> adjList[i];
}
int pos = 0;
target--;
while (pos < target) {
pos += adjList[pos];
}
if (pos == target) {
cout << "YES\n";
} else {
c... | 2 |
#include <bits/stdc++.h>
using namespace std;
int t;
long long k;
int main() {
ios::sync_with_stdio(0);
cin >> t;
while (t--) {
cin >> k;
long long l = 0, pv = 0, p10 = 10, len = 1;
while (1729) {
l++;
if (l == p10) len++, p10 *= 10;
pv += len;
if (k > pv)
k -= pv;
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5e6;
const long long mod = 1e9 + 7;
mt19937 gen(time(0));
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, m;
cin >> n >> m;
long long x1 = 0, x2 = 0, y1 = 0, y2 = 0;
for (long long i = 0; i < n; ++... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int inf = 0x3f3f3f3f;
char s1[N], s2[N];
int dis[30][30];
int m;
int main() {
scanf(" %s%s", s1, s2);
scanf("%d", &m);
for (int i = 0; i < 26; i++) {
for (int j = 0; j < 26; j++) {
if (i == j)
dis[i][j] == 0;
else
... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long a[100005];
long long b[100005];
int main() {
int f(int a, int b);
long long maxn;
int n, s = 1;
scanf("%d", &n);
for (int ni = 0; ni < n; ni++) scanf("%lld", &a[ni]);
sort(a, a + n);
for (int mi = 0; mi < n - 1; mi++) b[mi] = a[mi + 1] - a[mi];
sor... | 10 |
#include <bits/stdc++.h>
using namespace std;
int num[15];
int n;
int main() {
num[0] = 2;
num[1] = 7;
num[2] = 2;
num[3] = 3;
num[4] = 3;
num[5] = 4;
num[6] = 2;
num[7] = 5;
num[8] = 1;
num[9] = 2;
cin >> n;
cout << num[n % 10] * num[n / 10] << endl;
return 0;
}
| 3 |
// Problem: B. Replace and Keep Sorted
// Contest: Codeforces - Codeforces Round #701 (Div. 2)
// URL: https://codeforces.com/contest/1485/problem/B
// Memory Limit: 256 MB
// Time Limit: 2000 ms
//code by: Ravi Khatri @Ravi_Orz
#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vll vector<ll>... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char s1[1001], s2[1001];
scanf("%s %s", s1, s2);
int l1 = strlen(s1), l2 = strlen(s2);
int a[1001][1001];
for (int i = 0; i <= l1; i++) a[i][0] = i;
for (int i = 1; i <= l2; i++) a[0][i] = i;
for (int i = 1; i <= l1; i++)
for (int j = 1; j <= ... | 13 |
#include <bits/stdc++.h>
using namespace std;
struct Range {
int L, R;
Range(int l, int r) : L(l), R(r) {}
};
struct Comp {
bool operator()(Range const& a, Range const& b) {
if ((a.R - a.L + 1) == (b.R - b.L + 1)) return a.L > b.L;
return (a.R - a.L + 1) < (b.R - b.L + 1);
}
};
int main() {
std::ios_b... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long modpow(long long a, long long b,
long long mod = (long long)(1e9 + 7)) {
if (!b) return 1;
a %= mod;
return modpow(a * a % mod, b / 2, mod) * (b & 1 ? a : 1) % mod;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
map<int, int> m1;
vector<pair<int, int>> vec;
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
vec.push_back({a, b});
}
int ans = 0;
for (int i = 0; i < n; i++) {
int a = vec[i].first;
bool found = fals... | 6 |
#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) { cerr << endl; }
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << " | ";
err(++it, args...);
}
vector<long long int> v1, v2;
string s1, s2, s3;
int main... | 0 |
#include <bits/stdc++.h>
using namespace std;
int read() {
int 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, m, head[5005 * 5], level[5005 * ... | 17 |
#include <bits/stdc++.h>
using namespace std;
long long st[600000];
long long k[600000];
int main() {
long long n;
cin >> n;
for (long long i = 0; i < n; i++) {
scanf("%d", &st[i]);
}
string s;
cin >> s;
for (long long i = 0; i < n; i++) {
if (s[i] == 'A') {
k[i] = 0;
} else {
k[i]... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long base = 131;
char s[200005];
vector<long long> v[30];
long long n, m, sum[200005][30], to[30],
b[30] = {0, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41,
43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
const int M = 2e6 + 7;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
long long w[N], k;
int f[N], nx[N][35], n;
long long sum[N][35], mn[N][35];
int main() {
scanf("%d", &n);
scanf("%lld", &k);
fo... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<int> q, e, s, cur, temp, old;
bool d[105][105] = {false};
int mem[105][105] = {0};
void first() {
for (int i = 1; i <= n; i++) temp[i] = cur[q[i]];
cur = temp;
}
void second() {
for (int i = 1; i <= n; i++) temp[i] = cur[e[i]];
cur = temp;
}
bool df... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 8;
const double eps = 1e-6;
inline int read() {
int s = 1, a = 0;
char c = getchar();
while (!isdigit(c)) s = (c == '-') ? (-s) : s, c = getchar();
while (isdigit(c)) a = (a << 3) + (a << 1) + c - '0', c = getchar();
return s * a;
}
struct vec ... | 15 |
#include <bits/stdc++.h>
using namespace std;
int months[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
tuple<int, int, string> dates(0, 0, "fine");
map<tuple<int, int, string>, int> mp;
int day, month;
string year;
bool check_month(char a, char b) {
if (a == '-' || b == '-') return false;
month = (int)a -... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, p, ans = 0, i;
long double paid = 0;
cin >> n >> p;
string temp[2000];
for (i = 0; i < n; i++) {
cin >> temp[i];
}
for (i = n - 1; i >= 0; i--) {
if (temp[i] == "halfplus")
ans = ans * 2 + 1;
else
ans = ans... | 4 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
const int BSZ = 800;
const int N = 100228;
const int LG = 17;
int n, m;
vector<vi> g;
vi pred;
vi in, out;
int timer;
int up[LG][N];
vi ts;
vi evs;
vi sgn;
vector<bool> aliv... | 21 |
#include <bits/stdc++.h>
using namespace std;
struct pt {
double x, y;
pt() {}
pt(double x, double y) : x(x), y(y) {}
pt operator-(const pt& other) const { return {x - other.x, y - other.y}; }
pt operator+(const pt& other) const { return {x + other.x, y + other.y}; }
pt operator*(double k) const { return {x... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int day[505];
for (int i = 0; i < n; ++i) {
cin >> day[i];
}
int ok[505];
ok[0] = day[0];
int sum = 0;
for (int i = 1; i < n; i++) {
if (ok[i - 1] + day[i] >= k) {
ok[i] = day[i];
} else {
ok[i]... | 2 |
#include <bits/stdc++.h>
using namespace std;
int place[1000011];
set<int> pos;
set<pair<int, pair<int, int> > > seg;
int n;
int val(int l, int r) {
if (l == 0 and r == n + 1) return n;
if (l == 0) return r - 1;
if (r == n + 1) return n - l;
return max(0, min(r - (l + r) / 2, (l + r) / 2 - l));
}
void add(int l... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, ans = 0;
cin >> n;
cout << n / 2520 << endl;
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int a[1010];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
if (n == 1) {
if (a[0] == 1)
cout << "YES";
else
cout << "NO";
return 0;
}
int cnt = 0;
for (int i = 0; i < n; i++)
if (a[i] == 0) cnt++;
if (cnt ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, y;
vector<int> v1;
vector<int> v2;
map<int, int> mp;
map<int, int>::iterator it;
cin >> n;
while (n--) {
cin >> x >> y;
v1.push_back(x);
v2.push_back(y);
mp[x] = y;
}
int sig = 0;
for (int i = 0; i < v1.size(); i++)... | 2 |
#include <bits/stdc++.h>
using namespace std;
int s[1001][1001], n, m;
int dr[] = {0, 1, 1};
int dc[] = {1, 1, 0};
int dr2[] = {-1, -1, 0};
int dc2[] = {0, 1, 1};
int dr3[] = {0, -1, -1};
int dc3[] = {-1, -1, 0};
int dr4[] = {0, 1, 1};
int dc4[] = {-1, -1, 0};
bool check(int i, int j) {
int c = 0;
for (int k = 0; k... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long int c[105][105], dp[105][12];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
long long int n;
cin >> n;
long long int a[10];
for (long long int i = 0; i < 10; i++) cin >> a[i];
c[0][0] = 1;
for (long long int i ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, k, dif;
int main() {
int i, j, val;
cin >> n >> k;
dif = (n - k) / 2;
for (i = 0; i < n;) {
val = dif;
j = i;
while ((j < n) && (val)) {
cout << '0';
val--;
j++;
}
i = j;
if (i < n) {
i++;
cout << '1';
... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = 10000000;
const double pi = 3.14159265358979;
double x[N], y[N];
double R, r;
int n;
double dis(int i) {
return sqrt((x[i] - x[0]) * (x[i] - x[0]) + (y[i] - y[0]) * (y[i] - y[0]));
}
void seg_dis(int i) {
int j = i + 1;
double d = dis(i);
R = max(R, d)... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
long long n;
long long b[maxn];
long long cnt[maxn * 5];
bool vis[maxn * 5];
int main() {
long long ans = 0;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> b[i];
cnt[b[i] - i + maxn] += b[i];
}
for (int i = 1; i <= n; i++) {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, n, m, l = 0;
string s;
cin >> a >> n >> m >> s;
for (int i = a - 1; i >= a - n; i--)
if (s[i] == '1' && i != a - m - 1) l++;
if (s[a - m - 1] == '0') l++;
cout << l;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int count = 0;
pair<int, int> arr[200];
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
arr[i].first = x;
arr[i].second = y;
}
for (int i = 0; i < n; i++) {
bool one = false, two = false, three = false, ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int cara[25] = {0};
void input() {
for (int i = 1; i < 25; i++) {
cin >> cara[i];
}
return;
}
bool bueno() {
if (cara[1] == cara[3] && cara[1] == cara[6] && cara[1] == cara[8]) {
if (cara[2] == cara[4] && cara[2] == cara[22] && cara[2] == cara[24]) {
i... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long res = 0;
int a, b, count = 1, n;
cin >> n >> a;
for (int i = 1; i < n; i++) {
cin >> b;
if (a == b)
res += count++;
else
count = 1;
a = b;
}
cout << res + n;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T read(T &x) {
x = 0;
int f = 0;
char ch = getchar();
while (ch < '0' || ch > '9') {
f |= (ch == '-'), ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 1) + (x << 3) + ch - '0', ch = getchar();
}
return x = f ... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct Tree_Node {
int nxt[30], pre, word, fail, len;
char ch;
} Tree[500];
const char opt[4] = {'A' - 'A', 'C' - 'A', 'G' - 'A', 'T' - 'A'};
int Index = 1, N, M, p, tot, f[500][1050][12], ans;
char s[100];
int cal(int x) {
if (x == 1) return 0;
int tmp = Tree[Tree[... | 17 |
#include <bits/stdc++.h>
using namespace std;
pair<int, pair<int, int> > d[700000];
int ind[801], s[801];
int main() {
int n, i, j, a, l = 0, c, k;
cin >> n;
for (i = 1; i < 2 * n; ++i)
for (j = 0; j < i; ++j) {
scanf("%d", &a);
d[l].first = a;
d[l].second.first = i;
d[l].second.second... | 5 |
#include <bits/stdc++.h>
using namespace std;
string s1[20] = {"zero", "one", "two", "three", "four",
"five", "six", "seven", "eight", "nine",
"ten", "eleven", "twelve", "thirteen", "fourteen",
"fifteen", "sixteen", "seventeen", "e... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, x, d;
int c = 0;
char ch;
cin >> n >> x;
for (int i = 0; i < n; i++) {
cin >> ch >> d;
if (ch == '+')
x += d;
else {
if (x >= d)
x -= d;
else
c++;
}
}
cout << x << " " << c << endl;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, k, c;
cin >> a >> k >> c;
long long b = 1;
while (k--) b *= c;
vector<long long> v(a + 2), l(a + 2), r(a + 2);
for (int i = 1; i <= a; i++) {
cin >> v[i];
}
for (int i = 1; i <= a; i++) {
l[i] = v[i] | l[i - 1];
r[a - i ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 30;
const int maxn = 4e5 + 5;
int n;
struct data {
int x, y;
} da[maxn];
int cmp(data a, data b) { return a.x < b.x; }
map<int, int> dd;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &da[i].x), da[i].y = i;
sort(da + 1, ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MN = 82;
int N, K, i, j, k, x, y, tmp[MN][MN * MN];
deque<pair<int, int> > dp[MN][MN * MN];
vector<int> pos;
inline int eval(pair<int, int> ln, int x) {
return (ln.first - x - 1) * (ln.first - x - 2) / 2 + ln.second;
}
inline double eval(pair<int, int> ln, doubl... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
const int inf = 0x3f3f3f3f;
int n, e[2][maxn], tot, rd[maxn];
int net[maxn], tail[maxn];
inline int read(void) {
int num, sign = 1;
char c;
while (!isdigit(c = getchar()))
if (c == '-') sign = 0;
num = c - '0';
while (isdigit(c = getch... | 15 |
#include <bits/stdc++.h>
using namespace std;
long long int n, m, fc = pow(10, 6), cc;
int ifr = 0;
string s1, s2, p = "AGCT";
vector<string> v, a, s;
void comp(int isr) {
long long int i, j, rc1, rc2, f1, f2, f;
string cs;
cc = 0;
if (!isr) {
for (i = 0; i < n; i++) {
f1 = 0;
f2 = 1;
rc1 ... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
long long valu[N], res[N], C[N];
void ex_gcd(long long a, long long b, long long &x, long long &y) {
if (b == 0) {
x = 1;
y = 0;
return;
}
ex_gcd(b, a % b, x, y);
long long tmp = y;
y = x - a / b * y;
x... | 11 |
#include <bits/stdc++.h>
using namespace std;
set<pair<pair<int, int>, pair<int, int>>> s;
int main() {
int t;
cin >> t;
while (t--) {
s.clear();
int ans = 0, x = 100000, y = 100000;
string str;
cin >> str;
for (int i = 0; i < str.size(); i++) {
int u = x, v = y;
if (str[i] == 'N')... | 6 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const long long mod1 = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
string s1;
cin >> s1;
vector<int> ans(n);
for (int i = 0; i < n; i++) {
int cur = 1;
for (int j = i;... | 10 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target( \
"sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-funroll-all-loops,-fpeel-loop... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, k, t, ans;
int main() {
ios_base::sync_with_stdio(0);
static const size_t npos = -1;
char s[1000001];
scanf("%s", s);
int l = strlen(s);
int v[l + 1];
j = 0, k = l - 1;
for (i = 0; i < l; i++) {
if (s[i] == 'l') {
v[k--] = i + 1;
... | 4 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.