solution stringlengths 53 181k | difficulty int64 0 13 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const double err = 1e-10;
const double PI = 3.141592653589793;
const int N = 1e3 + 5;
int dp2[N][N], dp5[N][N], r = -1, c;
char dir2[N][N], dir5[N][N];
void solve() {
int n, t;
cin >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int p1 = 0, p2 = 0, p3 = 0;
int fp1[10001], fp2[10001], f[100001];
int flag = 0;
int m, n;
int p[10001];
int getfa(int x) { return f[x] == x ? x : (f[x] = getfa(f[x])); }
int main() {
int x, y;
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++) f[i] = i;
for (int ... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long a[20], bay[20], jum, maks, b;
int main() {
for (long long i = 0; i <= 13; i++) {
cin >> a[i];
bay[i] = a[i];
}
for (long long i = 0; i <= 13; i++) {
jum = 0;
b = a[i] % 14;
for (long long j = 1; j <= a[i] % 14; j++) {
bay[(i + j) % ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
set<int> ans;
set<int> ans2;
set<int> areinnow;
ans2.clear();
areinnow.clear();
ans.clear();
int n, m;
cin >> n >> m;
int arr[100002] = {0};
int cmd[100002][2];
int arrinnow[100002];
memset(arrinnow, -1, sizeof arrinnow);
for (int i = ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, i, j, A[2][25], ar[100], k, l, m, ans, tmp;
int main() {
memset(ar, 0, sizeof(ar));
scanf("%d%d", &n, &m);
for (i = 1; i <= n; i++) scanf("%d", &A[0][i % n]);
for (i = 1; i <= n; i++) scanf("%d", &A[1][i % n]);
ans = 0;
ar[1] = A[0][1 % n];
m *= n;
fo... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<int> v[n + 1];
for (int i = 1; i <= n - 1; i++) {
int a, b;
cin >> a >> b;
v[a].push_back(b);
v[b].push_back(a);
}
int res = 0;
vector<array<int, 2>> dp(n + 1, {0, 0}... | 9 |
#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1, -1, -1, 1, 1};
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
template <class T>
inline T biton(T n, T pos) {
return n | ((T)1 << pos);
}
template <class T>
inline T bitoff(T n, T pos) {
return n & ~((T)1 << pos);
}
template <class T>
inline T ison(T n... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i;
char a[40][30];
scanf("%d", &n);
for (i = 0; i < n; i++) scanf("%s", a[i]);
int arr[26];
int arr2[676];
for (i = 0; i < 676; i++) {
if (i < 26) arr[i] = 0;
arr2[i] = 0;
}
int flag = 0;
char temp = 'a';
int j, k;
for (j ... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0)
return a;
else {
return gcd(b, a % b);
}
}
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
int main() {
long long n, k;
cin >> n >> k;
long long t = k;
long long x, player = ... | 2 |
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops","omit-frame-pointer","inline")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,fma,tune=native")
#pragma GCC option("arch=native","no-zero-upper") //Enable AVX
#include <bits/stdc++.h>
#define db(x) cout << (x) << '\n';
#de... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 200;
const long long INF = 2e16 + 7;
const double eps = 1e-8;
int n;
struct node {
long long dis;
char s;
} d[3][3];
;
int sgn(int x, int xx) {
if (x == xx) return 1;
if (x < xx) return 2;
return 0;
}
int main() {
long long x, y, xx, yy;
... | 4 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int Max = 1e5 + 5;
double t[Max], a, b, c, d;
int n;
int main() {
while (~scanf("%d%lf%lf", &n, &a, &b)) {
t[0] = 0;
for (int(i) = 1; (i) <= (n); (i)... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500005;
const int MOD = 1e9 + 7;
int n;
char s[2 * MAXN];
int pref[MAXN];
int rmq[MAXN][23];
int farthest[MAXN];
int nearest[MAXN];
int low[MAXN];
int ha[MAXN][23];
int pow29[MAXN];
vector<int> pos[3 * MAXN];
int getmin(int a, int b) {
int zz = low[b - a ... | 9 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const int MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-8;
const int dir[4][2] = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}};
inline void II(int &n) {
char ch = getchar();
n = 0;
bool t = 0;
for ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 500;
const long long mod = 1e9 + 7;
const long long cmod = 998244353;
const long long inf = 1LL << 61;
const int M = 1e6 + 500;
const long long int ths = 1LL << 40;
const int NN = 5e3 + 6;
void solve() {
long long int n;
cin >> n;
long long int a[n... | 4 |
#include <bits/stdc++.h>
using namespace std;
char s[500010];
int main() {
scanf("%s", s);
int n = strlen(s);
for (int l = 1; l <= n / 2; l++) {
int match = 0, newn = l;
for (int i = l; i < n; i++) {
match = (s[i] == s[i - l] ? match + 1 : 0);
if (match == l) match = 0, newn -= l;
s[newn... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100001;
vector<pair<int, pair<int, int> > > adj;
int N;
int dad[MAXN];
int size[MAXN];
bool sets[MAXN];
inline bool ishap(int x) {
while (x > 0) {
int dig = x % 10;
if (dig != 7 && dig != 4) return false;
x /= 10;
}
return true;
}
inline i... | 5 |
#include <bits/stdc++.h>
using namespace std;
int r, j, n, i, c[12];
char s[1000007];
int main() {
gets(s + 1);
n = strlen(s + 1);
for (i = 1; i <= n; i++) c[s[i] - 48]++;
c[1]--;
c[6]--;
c[8]--;
c[9]--;
r = 0;
for (i = 1; i <= 9; i++) {
for (j = 1; j <= c[i]; j++) {
printf("%d", i);
r... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename TT>
ostream& operator<<(ostream& s, pair<T, TT> t) {
return s << "(" << t.first << "," << t.second << ")";
}
template <typename T>
ostream& operator<<(ostream& s, vector<T> t) {
for (int i = 0; i < t.size(); i++) s << t[i] << " ";
return... | 6 |
#include <bits/stdc++.h>
using namespace std;
const double pi = 3.141592653689793238460;
const long long inf = 0x3f3f3f3f3f3f;
const int N = 2e5 + 5;
const int pr = 31;
using ld = long double;
int mod = 1e9 + 7;
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long lcm(lo... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, MOD = 1e9 + 7, MAX = 1e5;
int n, c;
int a[N], seg[4 * N];
long long pref[N], memo[N];
void build(int indx, int l, int r) {
if (l == r) {
seg[indx] = a[l];
return;
}
build(indx * 2, l, (l + r) / 2);
build(indx * 2 + 1, (l + r) / 2 + 1, ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, i, c, x;
cin >> n;
vector<bool> v(n + 1);
vector<int> a;
fill(v.begin(), v.end(), 0);
for (i = 0; i < n; i++) {
cin >> x;
a.push_back(x);
}
for (i = n - 1; i >= 0; i--) {
if... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
;
long long t, i, j, r, k, x, y, n, m, l, a, b, c, d = 0;
cin >> t;
string s, cm = "abacaba";
while (t--) {
cin >> l >> r;
if (2 * l <= r) {
cout << l << " " << 2 * l << "\n";
} else
... | 0 |
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constex... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long read() {
long long f = 1, x = 0;
char c = getchar();
while (c < '0' || '9' < c) {
if (c == '-') f = -1;
c = getchar();
}
while ('0' <= c && c <= '9')
x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
return f * x;
}
void Exgcd(int a, int b... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long n;
int main() {
cin >> n;
long long i = 1;
long long total_need = 2;
long long res = 0;
while (total_need <= n) {
if ((n - total_need) % 3 == 0) ++res;
i++;
total_need += 2 * i + (i - 1);
}
cout << res;
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <class T>
using vv = vector<vector<T>>;
template <class T>
inline bool MX(T &l, const T &r) {
return l < r ? l = r, 1 : 0;
}
template <class T>
inline bool MN(T &l, const T &r) {
return... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, c[12], d[12], a[12], b[12], num[12], dp[1002];
while (cin >> n >> m >> c[0] >> d[0]) {
memset(dp, 0, sizeof(dp));
num[0] = n / c[0];
for (int i = 1; i <= m; i++) {
cin >> a[i] >> b[i] >> c[i] >> d[i];
num[i] = a[i] / b[i];
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int sum[110][110], a[110][110], ans[110];
bool cmp(int a, int b) { return a > b; }
int main() {
int i, j, n, m;
scanf("%d", &n);
int r = 0;
int C = 0, J = 0;
for (i = 0; i < n; i++) {
scanf("%d", &m);
scanf("%d", &a[i][0]);
sum[i][0] = a[i][0];
for... | 6 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
int com(const void* a, const void* b) { return *(int*)a - *(int*)b; }
int main(void) {
int c, d, n, m, k, z;
scanf("%d%d%d%d%d", &c, &d, &n, &m, &k);
z = n * m - k;
if (z <= 0)
printf("0");
else {
int m1, m2, m3;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
if (min(n, m) & 1) {
cout << "Akshat" << endl;
} else {
cout << "Malvika" << endl;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 20;
int n, m;
int dis[maxn][maxn], du[maxn];
int dp[1 << maxn];
void Floyd() {
for (int k = 0; k < n; k++) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++)
dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
}
}
for (in... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9;
const long long inf64 = 1e18;
const long long MOD = inf + 7;
const long long N = 2e5 + 5;
vector<long long> g[N];
long long dp[N][3];
void dfs(long long node, long long par) {
dp[node][0] = 1;
if ((long long)(g[node]).size() == 1) dp[node][1] ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int ans[1000000];
int gr[1000000][26];
int merge(vector<int> a) {
int res = a.size() - 1, i, j;
for (j = 0; j < 26; j++) {
vector<int> s;
for (i = 0; i < a.size(); i++) {
if (gr[a[i]][j]) s.push_back(gr[a[i]][j]);
}
if (s.size() <= 1) continue;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
constexpr int N = 2e5 + 5;
int t, a, b, p;
string s;
void Solve() {
cin >> t;
while (t--) {
cin >> a >> b >> p >> s;
s.pop_back();
vector<ll> suf;
suf.resize(s.size());
char la... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
vector<pair<std::pair<int, int>, int>> e[1000000];
int pt[1000000];
std::vector<int> l, r;
int main() {
const int INF = 2e9;
int n, m;
scanf("%d %d", &n, &m);
std::vector<int> tmin(n, INF);
l.resize(m);
r.resize(m);
std::vecto... | 12 |
#include <bits/stdc++.h>
using namespace std;
int sum;
int main() {
int n;
cin >> n;
int a[n][n];
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cin >> a[i][j];
if (i == j || i == n - j + 1 || i == n / 2 + 1 || j == n / 2 + 1)
sum += a[i][j];
}
}
cout << sum;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
map<long long, long long> mp[101];
long long n, k, s, ans, q[100001], sum[100001];
inline void dfsx(long long x, long long y, long long S, long long num) {
if (num > k) {
return;
}
if (x > y) {
++mp[num][S];
return;
}
dfsx(x + 1, y, S, num);
dfsx(x +... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long n, a[30], pref[100007];
string s;
map<pair<long long, char>, long long> prefs;
void solve() {
for (long long let = 0; let < (26); ++let) cin >> a[let];
cin >> s;
n = ((long long)(s).size());
s = '#' + s;
long long rst = 0;
pref[1] = a[s[1] - 'a'];
++... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
const int INF = 0x3f3f3f3f;
const long long mod = 998244353;
int a[maxn], n, m;
long long dp[maxn][maxn];
long long Cal(int x) {
for (int i = 0; i <= n; ++i)
for (int j = 0; j <= m; ++j) dp[i][j] = 0;
dp[0][0] = 1;
for (int j = 1; j <= m; ++... | 8 |
#include <bits/stdc++.h>
char s[100], p;
int main() {
p = 0;
scanf("%s", s);
if (s[0] == 'f') {
printf("ftp://");
p += 3;
} else {
printf("http://");
p += 4;
}
int l = strlen(s);
for (int i = p + 1; i < l - 1; ++i) {
if (s[i] == 'r' && s[i + 1] == 'u') {
for (int j = p; j < i; ++... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 15;
int a[N], b[N], sz[N], ord[N], scc[N], sid = 1, p = 1;
bool v[N];
stack<int> st;
vector<int> adj[N];
int dfs(int x, int par) {
int u, ind, i, ret;
ord[x] = p++;
ret = ord[x];
st.push(x);
for (i = 0; i < adj[x].size(); ++i) {
ind = adj[x... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n;
string t, s, e;
vector<int> starts, fucks;
unordered_map<long long, int> m[2009];
int main() {
cin >> t >> s >> e;
int itr = 0;
int sz = t.size();
int tsz = e.size();
for (; itr < sz;) {
int pos = t.find(s, itr);
if (pos == string::npos) {
bre... | 6 |
#include <bits/stdc++.h>
using namespace std;
map<int, int> used;
int main() {
int mask, i, j, n, a[51], k, ans = 0, temp, c;
cin >> n >> k;
for (i = 1; i <= n; i++) cin >> a[i];
sort(a + 1, a + n + 1, greater<int>());
for (i = 1; i <= n; i++) {
for (j = i; j <= n; j++) {
ans++;
cout << i << '... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double eps = 1e-8;
const double PI = acos(-1.0);
const int MAXN = 1e5 + 5;
const int MAXM = 2e6 + 5;
const int MOD = 1e9 + 7;
int sgn(double x) {
if (fabs(x) < eps) return 0;
if (x < 0)
return -1;
else
return 1;
}
long long pw... | 6 |
#include <bits/stdc++.h>
using namespace std;
double sqrtt(double x) {
if (x < 0)
return -sqrt(-x);
else
return sqrt(x);
}
int main() {
double a, b, c;
double x1, x2;
while (cin >> a >> b >> c) {
if (a == 0 && b == 0) {
if (c == 0)
printf("-1\n");
else
printf("0\n");
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
string s, f;
cin >> n;
cin >> s;
std::vector<int> v[26];
for (size_t i = 0; i < n; i++) {
v[s[i] - 'a'].push_back(i + 1);
}
long long int m;
std::cin >> m;
while (m--) {
std::cin >> f;
vector<int> cnt(26);
fo... | 2 |
#include <bits/stdc++.h>
using namespace std;
bool eq(char a, char b) {
a = tolower(a);
b = tolower(b);
return a == b or (a == 'o' and b == '0') or (a == '0' and b == 'o') or
((a == 'l' or a == '1' or a == 'i') and
(b == 'l' or b == '1' or b == 'i'));
}
int main() {
string s;
cin >> s;
in... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int arr[n + 1];
for (int i = 1; i <= n; i++) {
cin >> arr[i];
}
int min = INT_MAX;
int x = 0, y = 0;
for (int i = 1; i <= n; i++) {
if (i != n) {
if (abs(arr[i] - arr[i + 1]) < min) {
min = abs(arr[i] - arr... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n;
struct aa {
int l, r;
} pp[201000];
vector<pair<int, int> > _hash;
vector<pair<int, int> >::iterator it;
int color[201000];
struct node {
int t, nxt;
} edge[201000 << 3];
int headline[201000], E;
inline void add(int f, int t) {
edge[E].t = t;
edge[E].nxt = he... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long n, cnt;
cin >> n;
long long a[n + 1];
for (int i = 0; i < n; ++i) cin >> a[i];
multiset<long long> S;
multiset<long long>::iterator it;
for (int i = 1; i <= n; ++i) {... | 3 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> vec(110);
const long long mod = (int)1e9 + 7;
struct matrix {
vector<vector<long long>> arr;
matrix(size_t n, size_t m) {
vector<long long> line(m);
arr.resize(n, line);
}
const vector<long long>& operator[](size_t index) const { return arr... | 5 |
#include <bits/stdc++.h>
int bin_1(long long int x) {
int r = 0;
while (x) {
r++;
x &= x - 1;
}
return r;
}
long long int exgcd(long long int a, long long int b, long long int &x,
long long int &y) {
if (a == 0) {
x = 0;
y = 1;
return b;
}
long long int x1, y1, __gc... | 7 |
#include <bits/stdc++.h>
using namespace std;
int ans;
vector<int> vct[100099];
int dfs(int u, int p) {
int sz = 1;
for (int i = 0; i < vct[u].size(); i++) {
int v = vct[u][i];
if (v != p) sz += dfs(v, u);
}
if (u != 1 && sz % 2 == 0) ans++;
return sz;
}
int main() {
long long int n, m, k;
scanf("... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long nChooseR(int n, int k);
long long gcd(long long a, long long b);
void strCountsort(string& arr);
void intCountSort(vector<int>& arr);
vector<string> split(string target, char c);
long long n, k, r, l, a[100005], b[100005], t, x, y, m;
long long ans;
bool isPrime(l... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = (1e9) + 7;
const long long inf = 1e17;
const int offset = 3000;
string s;
int check(int w) {
char c = w + 'a';
int pre = -1;
int i;
int temp = INT_MIN;
for (i = 0; i < s.size(); i++) {
if (s[i] == c) {
temp = max(temp, i - pre);
pre... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n;
pair<int, int> a[200005];
int cmp(pair<int, int> a, pair<int, int> b) {
if (a.second != b.second)
return a.second > b.second;
else
return a.first < b.first;
}
int bit[200005];
void update(int u) {
for (int i = u; i <= n; i += i & (-i)) bit[i]++;
}
int g... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int q, n;
cin >> q;
while (q--) {
cin >> n;
if (n == 2) {
cout << "2" << endl;
} else if (n % 4 == 0 || n % 2 == 0) {
cout << "0" << endl;
} else if (n % 2 == 1) {
cout << "1" << endl;
} else
continue;
}
ret... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N_MAX = 100002;
int n;
struct Card {
int ax, ay, bx, by;
int index;
};
bool operator<(const Card &a, const Card &b) { return a.ax < b.ax; }
Card v[N_MAX];
int SGT[N_MAX * 4];
void compute(int node) {
int lSon = (node << 1), rSon = (lSon | 1);
if (v[SGT[lSo... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int n;
cin >> n;
for (int(i) = (0); (i) < (n); ++i)
if (i % 4 == 0)
s += 'a';
else if (i % 4 == 1)
s += 'b';
else if (i % 4 == 2)
s += 'c';
else if (i % 4 == 3)
s += 'd';
cout << s << endl;
return 0;... | 1 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16000000")
using namespace std;
const int Maxn = 100005;
int n, k;
vector<pair<int, int> > neigh[Maxn];
int dp[Maxn][2];
void Solve(int v, int p) {
vector<pair<int, int> > vals;
for (int i = 0; i < neigh[v].size(); i++) {
pair<int, int> u = neigh[v][i];
... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T x, T y) {
if (x < y) swap(x, y);
while (y > 0) {
T f = x % y;
x = y;
y = f;
}
return x;
}
int n;
char s[222222];
const int MX = 9 * 222222;
pair<int, int> sol[MX];
int inStack[MX];
bool solve(long long r, int lp);
bool xsolv... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
int black = 0, white = 1000000001;
cout << 0 << ' ' << 0 << endl;
cout << flush;
string S;
cin >> S;
if (S == "white") swap(white, black);
for (int i = 1; i < N; i++) {
int mid = (white + black) / 2;
cout << mid << ' '... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 12;
const int M = 105;
int w[12], a[N], c[N], n, b[N][M];
char s[15];
int get_x() {
scanf("%s", s);
int x = 0;
for (int j = n - 1; j >= 0; j--) {
x <<= 1;
x |= (s[j] == '1');
}
return x;
}
int main() {
int m, q, x, k, ans;
scanf("%d%... | 5 |
#include <bits/stdc++.h>
using namespace std;
using LL = int64_t;
const int INF = 0x3fffffff;
const double EPS = 1e-9;
const double PI = 2 * asin(1);
const int MX = 4000 + 10;
LL g_xn, g_yn;
void pretreat() {}
bool input() {
cin >> g_xn >> g_yn;
if (cin.eof()) return false;
return true;
}
void solve() {
LL ans ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int arr[] = {0, 4, 10, 20, 35, 56, 83,
116, 155, 198, 244, 292, 341};
long long int n;
cin >> n;
if (n < 12)
cout << arr[n];
else {
long long int k = n - 12;
long long int p = ((k * 49) % LLONG_MAX... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2000005;
long long n, m, ans;
long long z[maxn], t1[maxn], t2[maxn], pre[maxn], suf[maxn];
string a, b, s;
string getrev(string s) {
string res = s;
reverse(res.begin(), res.end());
return res;
}
void getZ(string s) {
long long l = 0, r = 0;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
string s;
long long n, ans;
long long sum[1000011], cnt[1000011];
stack<long long> ops;
signed main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> s;
n = s.length();
for (long long i = 0; i < n; i++) {
if (s[i] == '(')
ops.push(... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios::sync_with_stdio(false);
long long int n;
cin >> n;
long long int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
long long int sum = a[0], ans = 1;
for (int i = 1; i < n; i++) {
if (sum <= a[i]) ans++, sum += a[i];
... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long n, a[5 * 100001], bb;
long long cost[1000001];
long long ans, x, y;
int prime[1000001];
vector<pair<int, int>> vec;
long long even(int xx) {
long long l = 0;
for (int i = 0; i < n; i++) {
if (a[i] % xx == 0)
continue;
else {
long long cost ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e7 + 5;
int sqf[N], rt[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
for (int i = 1; i < N; i++) sqf[i] = i, rt[i] = 1;
for (int i = 2; i * i < N; i++)
for (int j = i * i; j < N; j += i * i)
while (sqf[j] % (i * i) == 0) sqf[j] /= i ... | 8 |
#include <bits/stdc++.h>
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-funroll-loops")
#pragma GCC target("avx,sse4")
using namespace std;
const int N = 1000005, P = 1e9 + 7;
int S[N], n, fail[N], e[N][26], len[N], ec, last, anc[N], diff[N], m, dp[N],
val[N];
char s[N];
inline int newnode(int l)... | 10 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-ffloat-store")
#pragma GCC optimize("-fno-defer-pop")
long long int power(long long int a, long long int b, long long int m) {
if (b == 0) return 1;
if (b == 1) return a % m;
lon... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 0x3f3f3f3f3f3f3f3f;
long long a[100010];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long n, m, k;
cin >> n >> m >> k;
for (int i = 1; i <= m; i++) {
cin >> a[i];
}
long long en = k;
long long ans = 0;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int a[2006];
int Gcd(int m, int n) {
if (n == 0) return m;
return Gcd(n, m % n);
}
int main() {
int n;
scanf("%d", &n);
int yi = 0;
int flag = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
if (a[i] == 1) yi++;
}
if (yi != 0) {
printf("%d... | 3 |
#include <bits/stdc++.h>
using namespace std;
constexpr double pi = 3.141592653589793238462643383279502884L;
const int sz = 1e5;
struct Iv {
int start;
int t;
Iv(int s, int tt) : start(s), t(tt) {}
bool operator<(const Iv& r) const {
if (t != r.t) {
return t < r.t;
}
return start < r.start;
... | 8 |
#include <bits/stdc++.h>
const int MAXN = 1e3;
const int mod = 1e9 + 7;
using namespace std;
void solution_AC() {
int n;
cin >> n;
set<int> st;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
st.insert(x);
}
cout << n - st.size() + 1;
}
int main() {
cin.tie();
ios_base::sync_with_stdio(false)... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long int pw(long long int a, long long int b, long long int mod) {
if (!b) return 1;
if (b & 1) return a * pw(a * a % mod, b / 2, mod) % mod;
return pw(a * a % mod, b / 2, mod) % mod;
}
constexpr long long int N = 310;
constexpr long long int MOD = 1e9 + 7;
const... | 10 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int x, int y) {
if (!y) return x;
return gcd(y, x % y);
}
int expo(int x, int y, int m) {
int res = 1LL;
while (y) {
if (y & 1) res = (res * x) % m;
x = (x * x) % m;
y /= 2;
}
return res;
}
class matrix {
public:
int a[3][3];
matrix() { ... | 4 |
#include <bits/stdc++.h>
using namespace std;
void _init() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int main() {
_init();
int n;
cin >> n;
string s;
cin >> s;
vector<int> divisors;
for (int i = 1; i * i <= n; i++) {
if (n % i == 0) {
if (n / i == i)
divisors.push_... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, i, j, a[505], mx = 0, f[1000005], head, tail, t;
long long k;
int main() {
cin >> n >> k;
for (i = 1; i <= n; i++) {
scanf("%d", &a[i]);
mx = max(mx, a[i]);
f[i] = a[i];
}
if (k > n) {
cout << mx;
return 0;
}
t = 0;
head = 1;
tail ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const double pi = acos(-1);
int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
string a[2];
int solve() {
int n = (int)a[0].size(), cnt = 0, ret = 0, ones = 0;
for (int j = 0; j < n; ++j) {
if (a[0][j] == '0' && ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e2 + 7;
double dp[2][N][N];
double prei[N], prej[N], prek[N];
int data[N];
double c2(int n) { return (n * (n - 1)) >> 1; }
int main() {
int n, m;
scanf("%d%d", &n, &m);
m = min(m, 900);
for (int i = (1); i < (n + 1); ++i) scanf("%d", &data[i]);
for ... | 8 |
#include <bits/stdc++.h>
const int maxn = 1000010, MOD = 1e9 + 7;
int n, k, fac[maxn], fav[maxn], D[maxn], h[maxn];
void gcd(int a, int b, int& x, int& y) {
if (!b) {
x = 1;
y = 0;
} else {
gcd(b, a % b, y, x);
y -= x * (a / b);
}
}
int inv(int a) {
int x, y;
gcd(a, MOD, x, y);
return (x % M... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n;
int dat[2222];
int main() {
cin >> n;
for (int i = 0; i < n; ++i) cin >> dat[i];
for (int i = 0; i <= n; ++i) {
for (int j = 0; j < n; ++j) {
if (j % 2 == 0)
dat[j]++;
else
dat[j]--;
if (dat[j] < 0) dat[j] += n;
if (d... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 200001;
vector<int> G[maxN];
int in[maxN], inctr;
struct Three {
int a, b, c;
Three(int e = 0, int f = 0, int g = 0) : a(e), b(f), c(g) {}
};
vector<Three> res;
void f(int& dep, int newv, int v) {
if (dep == 0)
dep = newv;
else
res.push_back... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
int64_t m, t, n, k, z, i, j, l, h, r, s;
cin >> n;
vector<int64_t> v;
r = n;
while (n % 2 == 0) {
v.push_back(2);
n = n / 2;
}
for (i = 3; i <= sqrt(n); i = i + 2) {
while... | 3 |
#include <bits/stdc++.h>
using namespace std;
inline char gc() {
static char buf[100000], *p1 = buf, *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
? EOF
: *p1++;
}
inline long long read() {
long long x = 0;
char ch = getchar();
bool positive... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
vector<vector<int> > v(n, vector<int>(m + 1));
vector<vector<int> > target(n, vector<int>(m + 1));
for (int i = 0; i < n; i++) ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int a[60], b[60];
int tota, totb;
int ans[10000];
int tot = 0;
int convert(int base, int *arr, int size) {
int ans = 0, k = 1;
for (int i = size - 1; i >= 0; i--) {
ans += k * arr[i];
k = k * base;
}
return ans;
}
int main() {
char tmp;
int Max = 0;
wh... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long arr[105], k;
int n;
bool check(long long x) {
long long sum = 0;
for (int i = 0; i < n; i++) {
sum += (arr[i] + x - 1LL) / x;
}
return x * sum <= k;
}
int main(int argc, char const *argv[]) {
cin >> n >> k;
for (int i = 0; i < n; i++) cin >> arr[i]... | 7 |
#include <bits/stdc++.h>
using namespace std;
bool sorting(pair<long, long> a, pair<long, long> b) {
long m = a.first + a.second;
long n = b.first + b.second;
if (m != n)
return m < n;
else
return (a.first > b.first);
}
int main() {
long n;
cin >> n;
bool val = false;
vector<pair<long, long> > v... | 1 |
#include <bits/stdc++.h>
using namespace std;
void die() {
vector<int> a;
a[-1] = 1;
}
const int K = 510;
bool dp[K][K][K];
void solve() {
int n, k;
cin >> n >> k;
vector<int> coins(n);
for (auto &i : coins) scanf("%d", &i);
for (int i = 0; i < n; i++) {
dp[i][coins[i]][coins[i]] = true;
dp[i][coi... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int i, j, k, l, cnt = 0, t;
cin >> t;
while (t--) {
cin >> k;
if (k >= 15) {
if (k % 14 <= 6 && k % 14 != 0)
cout << "YES" << endl;
else
cout << "NO" << endl;
} else
cout << "NO" << endl;
}
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int a[5];
int u[4];
bool f[5], falg;
void dfs(int dep) {
if (dep == 4) {
if (u[1] + u[2] > u[3] && u[1] + u[3] > u[2] && u[2] + u[3] > u[1]) {
printf("TRIANGLE");
exit(0);
}
if (u[1] + u[2] >= u[3] && u[1] + u[3] >= u[2] && u[2] + u[3] >= u[1])
... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct $ {
$() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
} $;
const int Maxn = 200005;
class RoundHouse {
public:
int LastEntrance(int n, int a, int b) {
return ((a - 1 + b) % n + n) % n + 1;
}
};
int main() {
int n, a, b;
cin >> n >> a >... | 1 |
#include <bits/stdc++.h>
int f_min(int x, int y) {
if (x < y)
return x;
else
return y;
}
int f_max(int x, int y) {
if (x < y)
return y;
else
return x;
}
void swap(int& x, int& y) {
x = x ^ y;
y = x ^ y;
x = x ^ y;
}
int f_abs(int x) { return (x) > (0) ? (x) : (-x); }
int lowbit(int x) { re... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, a, b;
cin >> n >> m >> a >> b;
if ((float)b / m >= a)
cout << n * a << endl;
else {
int f = b * (n / m) + (n % m) * a;
int s = b * ceil((float)n / m);
cout << min(f, s) << endl;
}
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const double g = 10.0, eps = 1e-12;
const int N = 100000 + 10, maxn = 100000 + 10, inf = 0x3f3f3f3f,
INF = 0x3f3f3f3f3f3f3f3f;
int main() {
int n, ans = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
int x;
scanf("%d", &x);
ans += abs(x);
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct fastIO {
inline fastIO operator>>(int& num) {
num = 0;
char c = getchar();
while (c != '-' && (c < '0' || c > '9')) c = getchar();
bool foo = 0;
if (c == '-') {
foo = 1;
c = getchar();
}
while (c >= '0' && c <= '9') {
n... | 9 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.