solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int n;
struct bignum {
int s[301];
} a[301], k;
inline void add(const bignum &a, const bignum &b, bignum &c) {
for (int i = 0; i <= 200; i++) c.s[i] = a.s[i] + b.s[i];
}
inline void mne(const bignum &a, const bignum &b, bignum &c) {
for (int i = 0; i <= 200; i++) c.s[... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const int mod = (int)1e9 + 7;
int n;
int x[1010], y[1010];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d%d", &x[i], &y[i]);
}
double mini = 1e18;
for (int i = 0; i < n; i++) {
int prev = (i - 1 + n) % n;
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k, c[100100];
list<int> adj[100100];
bitset<1000100> visited;
int counter, sum;
void dfs(int u) {
visited[u] = true;
counter++;
for (__typeof((adj[u]).begin()) v = (adj[u]).begin(); v != (adj[u]).end();
v++)
if (!visited[*v]) dfs(*v);
}
int main()... | 7 |
#include <bits/stdc++.h>
using namespace std;
bool v[105], f[105][105];
int n, m, s = 0;
void dfs(int x) {
v[x] = 1;
s++;
for (int i = 1; i <= n; i++)
if (!v[i] && f[x][i]) dfs(i);
}
int main() {
scanf("%d%d", &n, &m);
if (n != m) {
puts("NO");
return 0;
}
for (int i = 1; i <= m; i++) {
in... | 7 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios::sync_with_stdio(false);
long long n;
cin >> n;
deque<long long> q;
q.push_back(1);
long long x = 1, ans = 0;
while (x <= n) {
x = 1;
long long y = 1;
for (long long i = q.size() - 1; i >= 0; --i) {
if (i != q.size() - 1)... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, x, y;
int a[100002];
bool kt1, kt2;
int main() {
cin >> n >> x >> y;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) {
int j = i - 1;
int xx = x;
int yy = y;
kt1 = false;
kt2 = false;
while (j >= 1 && a[j] > a[i]) ... | 2 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long llinf = (1LL << 62);
const int inf = (1 << 30);
const int nmax = 1e5 + 50;
const int mod = 1e9 + 7;
using namespace std;
long long i, j, p, x[5], b[5], f[10][5], a[5], t, ans, mn, cur, y, v;
int main() {
ios_... | 6 |
#include <bits/stdc++.h>
using namespace std;
int isprime[1000005];
void seive() {
memset(isprime, 1, sizeof isprime);
for (int i = 2; i <= 1000000; ++i) {
if (isprime[i]) {
for (int j = i + i; j <= 1000000; j += i) isprime[j] = 0;
}
}
isprime[1] = isprime[0] = 0;
return;
}
int main() {
seive(... | 4 |
#include <bits/stdc++.h>
using namespace std;
#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:100000000")
int main() {
int mas[7] = {1869, 1968, 1689, 6198, 1698, 1986, 1896};
string s, s1;
bool q[10];
memset(q, 0, sizeof(q));
cin >> s;
int k = 0;
for (int i = 0, j = 0; i < s.size(); i++) ... | 8 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <class T>
void make_unique(T &v) {
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
}
int geti() {
int x;
cin >> x;
return x;
}
long lon... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int sum = 0;
int x;
for (int i = 0; i < n; i++) {
cin >> x;
sum += x;
}
cout << ceil((double)abs(sum) / m) << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n_split, N, M, a[100009], split[10009], split_dr[10009];
int arb[400009][61];
void refresh(int nod, int mij) {
for (int i = 0; i < 60; i++) {
int t = arb[nod << 1][i] + 1 + ((arb[nod << 1][i] + i) % a[mij] == 0);
arb[nod][i] = t + arb[(nod << 1) + 1][(t + i) %... | 16 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return (a ? gcd(b % a, a) : b); }
long long power(long long a, long long n) {
long long p = 1;
while (n > 0) {
if (n & 1) {
p = p * a;
}
n >>= 1;
a *= a;
}
return p;
}
long long power(long long a, long ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long M = 1e9 + 7;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
long long t;
cin >> t;
while (t--) {
long long n, g, b;
cin >> n >> g >> b;
if (g >= b || g >= (n + 1) / 2) {
cout << n << "\n";
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, lst = -1;
cin >> n >> m;
string str;
cin >> str;
for (int i = 0; i < str.size() && m; i++) {
if (str[i] == '4' && str[i + 1] == '4') {
for (; i < str.size() && m;)
if (str[i] == '4') {
i++;
continue;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n;
int a, b, c, d;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
cout << "YES" << '\n';
for (int i = 1; i <= n; i++) {
cin >> a >> b >> c >> d;
cout << ((12 + 2 * (a % 2) + (b % 2)) % 4) + 1 << '\n';
}
return 0;
}
| 13 |
#include <bits/stdc++.h>
namespace IO {
template <typename Tp>
inline Tp input() {
Tp x = 0, y = 1;
char c = getchar();
while ((c < '0' || '9' < c) && c != EOF) {
if (c == '-') y = -1;
c = getchar();
}
if (c == EOF) return 0;
while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getchar();
return... | 19 |
#include <bits/stdc++.h>
using namespace std;
int n;
string s;
set<char> g;
int main() {
cin >> n >> s;
for (int i = 0; i < s.size(); i++) g.insert(s[i]);
if (s.size() - g.size() <= 26 - g.size())
cout << s.size() - g.size();
else
cout << -1;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 2, 2, -2, -2, 4, 4, -4, -4, 6, 6, -6, -6,
4, -4, 0, 0, 2, 2, 6, 6, -2, -2, -6, -6};
int dy[] = {0, 2, -2, 2, -2, 4, -4, 4, -4, 6, -6, 6, -6,
0, 0, 4, -4, 6, -6, 2, -2, 6, -6, 2, -2};
int K[] = {0, 1, 1, 1, 1, 0, 0, 0, 0,... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k;
string s;
cin >> s >> k;
int i = s.size() - 1;
int ans = 0;
while (i >= 0) {
s[i] == '0' ? k-- : ans++;
i--;
if (k == 0) return cout << ans, 0;
}
cout << s.size() - 1 << endl;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
long long delbit(long long a, long long k) { return a & (~(1 << k)); }
int delbit(int a, int k) { return a & (~(1 << k)); }
bool getbit(long long a, long long k) { return 1 & (a >> k); }
bool getbit(int a, int k) { return 1 & (a >> k); }
long long setbit(long long a, long l... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005, INF = 0x3f3f3f3f;
int n, ans[N];
long long sum;
vector<int> V[N];
vector<int> W[N];
void add(int u, int v, int w) {
V[u].push_back(v);
W[u].push_back(w);
}
int rt, rtt, sz[N], mx, num[N];
int maximize(int& a, int b) {
if (a < b) {
a = b;
... | 23 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int n, res = 0;
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
int a;
scanf("%d", &a);
res += a * i;
}
printf("%d", res);
return 0;
}
| 12 |
#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std;
void debugi(vector<int>& vec) {
int n = (int)vec.size();
for (int i = 0; i < n; i++) {
cout << vec[i] << " ";
}
cout << endl;
}
void debugd(vector<long double>& vec) {
int n = (int)vec.size();
for (int i = 0; i <... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long long int N = 3e5 + 5, inf = 1e9 + 7;
int rs[N], dp[N], Arr[N];
vector<int> vec[N];
void dfs(int u, int p) {
dp[u] = Arr[u];
for (auto v : vec[u]) {
if (v == p) continue;
dfs(v, u);
dp[u] += max(0, dp[v]);
}
}
void dfs2(int u, int p) {
rs[u] = ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, i, j, i1, j1, a[200][200], b[200][200], valid = 1;
cin >> n >> m;
for (i = 0; i < n; i++)
for (j = 0; j < m; j++) cin >> a[i][j];
for (i = 0; i < n; i++)
for (j = 0; j < m; j++) b[i][j] = 1;
for (i = 0; i < n; i++)
for (j = 0; j ... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
if (a == 0 || b == 0) return 0;
if (a == b) return a;
if (a > b) return gcd(a % b, b);
return gcd(a, b % a);
}
long long int max(long long int a, long long int b) {
if (a > b) return a;
return b;
}
long long ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e4 + 7;
int t[4 * N], o[4 * N];
inline void build(int v, int l, int r, int a[]) {
if (l == r) {
t[v] = a[l], o[v] = 0;
} else {
int m = (r + l) >> 1;
build(v + v + 1, l, m, a);
build(v + v + 2, m + 1, r, a);
t[v] = max(t[v + v + 1], t[... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
cout << N * M / 2 << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-9;
const int N = 1e5 + 5;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
long long n, a[N], sum, mi;
int main() {
cin >> n;
mi = INF;
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
for (int i = 0; i < n; i++) {
sum +=... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
struct point {
double x, y;
} p[N], mid, line;
point operator+(point s, point t) { return (point){s.x + t.x, s.y + t.y}; }
int n, del[N];
pair<double, int> x[N];
bool eq(double x, double y) { return fabs(x - y) < 1e-9; }
bool check1(int a, int b) {
r... | 21 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char x;
string y;
cin >> y;
for (int i = 0; i < y.length(); i++) {
x = y.at(i);
switch (toupper(x)) {
case 'A':
break;
case 'O':
break;
case 'U':
break;
case 'I':
break;
case 'E':
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 5;
const double eps = 1e-9;
const int MAX_N = 1e6 + 5;
const long long M = (long long)1e9 + 7;
int Int() {
int x;
scanf("%d", &x);
return x;
}
long long Long() {
long long x;
scanf("%lld", &x);
return x;
}
void Char(char* ch) { scanf("%s", ch... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int arr[200000];
int fin[201][200001];
vector<int> adj[201];
int getSum(int BITree[], int index) {
int sum = 0;
index = index + 1;
while (index > 0) {
sum += BITree[index];
index -= index & (-index);
}
return sum;
}
void updateBIT(int BITree[], i... | 10 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:65000000")
using namespace std;
int n;
pair<int, int> mas[500500];
set<pair<int, int> > st;
int main(int argc, const char* argv[]) {
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", &mas[i].first);
mas[i].second = i;
st.insert(pair<int, ... | 17 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<doub... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const int maxn = 1e5 + 10;
int n, m;
long long gao(long long a) {
long long sum = 1;
for (int i = 1; i <= a; i++) {
sum = ((sum % mod) * i) % mod;
}
return sum % mod;
}
int main() {
string s;
cin >> n >> s;
if (n == 2)
cout <... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool umin(T& a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T>
bool umax(T& a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
const int BLOK = 350;
const int N = 1e5;
int st[100009], en[100009], now;
... | 22 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char s[100000], news[100000];
cin >> s;
int l = strlen(s), x = 0, i;
for (i = 0; i < l;) {
if (s[i] == '.') {
news[x] = '0';
x++;
i = i + 1;
} else if (s[i] == '-' && s[i + 1] == '.') {
i = i + 2;
news[x] = '1';
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int h1, h2, a, b;
while (cin >> h1 >> h2 >> a >> b) {
int dis = h2 - h1;
int day = 0;
if (b > a && dis > (a * 8)) {
cout << -1 << endl;
continue;
} else if (a == b && (dis > (a * 8))) {
cout << -1 << endl;
continue;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
char Gadj(string cad) {
if (cad.size() < 4) return 'X';
string ul;
if (cad.size() >= 5) {
ul = cad.substr(cad.size() - 4, 4);
if (ul == "lios") return 'm';
ul = cad.substr(cad.size() - 5, 5);
if (ul == "liala") return 'f';
} else if (cad.size() == 4)... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 10;
int n, k, h[maxn], ecnt, a[maxn];
struct enode {
int v, n;
enode() {}
enode(int _v, int _n) : v(_v), n(_n) {}
} e[maxn << 1];
inline void addedge(int u, int v) {
ecnt++;
e[ecnt] = enode(v, h[u]);
h[u] = ecnt;
}
int sz[maxn], dep[max... | 18 |
#include <bits/stdc++.h>
using namespace std;
long long p[100005];
stack<long long> m;
void solve() {
long long a, b, c = 0, d = 0;
cin >> a;
for (long long i = 1; i <= a; i++) {
cin >> p[i];
c = max(c, p[i]);
d += p[i];
}
if (d - c < c || d % 2 == 1)
cout << "T" << endl;
else
cout << "H... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int inverse(int x) {
return x == 1 ? x : (long long)(mod - mod / x) * inverse(mod % x) % mod;
}
void FWT(vector<int> &a) {
int n = a.size();
for (int d = 1; d < n; d <<= 1)
for (int m = d << 1, i = 0; i < n; i += m)
for (int j ... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
const int dre_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dre_8[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1},
{-1, 0}, {-1, -1}, {0, -1}, {1, -1}};
const int kaijou[10] = {1, 1, 2, 6, 24, 120, 720, 5040, 40320... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int mod = 998244353;
char s[2][maxn];
int seed = 19270817;
int hs[2][maxn], bas[maxn], len[2];
void init(int n, int j) {
bas[0] = 1;
for (int i = (1); i < (n + 1); ++i) {
if (j) bas[i] = 1ll * bas[i - 1] * seed % mod;
hs[j][i] = 1... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
for (int i = 0; i <= c; i = i + a) {
if ((c - i) % b == 0) {
cout << "Yes";
return 0;
}
}
cout << "No";
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > Edges(100006);
int D, mxchild[100006], mxsib[100006], mxfpar[100006], mxnode[100006];
bool dnode[100006];
int dfs1(int parent, int node) {
int ret = -1, i, now, temp, n;
vector<pair<int, int> > V;
for (i = 0; i < Edges[node].size(); ++i) {
now... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int n, k, x, i;
cin >> s;
n = s.size();
for (i = 0; i < n; i++)
if (s[i] == '.')
if (s[i - 1] == '9')
cout << "GOTO Vasilisa.";
else if (s[i + 1] < '5')
cout << s.substr(0, i) << endl;
else {
x =... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MOD = 998244353;
const int maxn = 100000 + 7;
const double eps = 1e-8;
const double PI = acos(-1.0);
int cnt[2 * maxn], sz[maxn * 2];
vector<int> G[maxn * 2];
unsigned long long ans;
int k;
void dfs(int u, int fa) {
sz[u] = cnt[u];
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N[5], n, tmp, key[5] = {2, 1, 0, 3, 4};
cin >> N[0] >> N[1] >> N[2] >> N[3] >> N[4] >> n;
string str, SIZE[5] = {"S", "M", "L", "XL", "XXL"};
for (int i = 0; i < n; i++) {
cin >> str;
tmp = key[(str[0] - 'H') / 5 + (str.size() == 3)];
fo... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long a[1000005];
long long pre[1000005];
int main() {
int n, m;
cin >> n >> m;
long long ans = 0;
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
for (int i = 0; i < n; i++) {
pre[i % m] += a[i];
ans += pre[i % m];
cout << ans << " ";
... | 7 |
#include <bits/stdc++.h>
struct ch {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM =
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 101000;
int n, k, a[N], mn;
long long ans;
int main() {
scanf("%d%d", &n, &k);
mn = 1000000000;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
mn = min(mn, a[i]);
}
for (int i = 1; i <= n; i++)
if ((a[i] - mn) % k != 0) ans = -1;
if... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long arr[100007];
int main() {
long long n, i, j, k, l, x, y, u;
cin >> n >> u;
for (i = 1; i <= n; i++) {
cin >> arr[i];
}
i = 1, j = 2, k = 3;
double maxx = 0;
for (i = 1; i < n - 1; i++) {
long long val = arr[i] + u;
int pos = upper_bound(a... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2 * int(1e9);
const long long INFll = 1ll * INF * INF;
const int MOD = 1000000007;
template <class T>
istream& operator>>(istream& in, vector<T>& a) {
for (int i = 0; i < a.size(); ++i) in >> a[i];
return in;
}
template <class T>
ostream& operator<<(ostr... | 14 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long x = 0, f = 1;
char c = getchar();
while ((c < '0' || c > '9') && (c != '-')) c = getchar();
if (c == '-') f = -1, c = getchar();
while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return x * f;
}
const int N = 2... | 16 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int value;
node* right;
node* left;
node* midel;
};
int main() {
int w, h, k;
cin >> w >> h >> k;
int count = 0;
int i = 0;
while (k > 0) {
count += 2 * (w - (i * 4) + h - (i * 4)) - 4;
i++;
k--;
}
cout << count;
return 0;
}... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m;
cin >> n >> m;
if (n == 0) {
cout << m * 3;
return 0;
}
if (m == 0) {
cout << n * 2;
return 0;
}
long long max1, max2;
long long i = 3;
long long j = 2;
long long ans;
max1 = n * 2;
max2 = m * 3;
while (... | 8 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void write(T x) {
if (x == 0) {
putchar('0');
return;
}
if (x < 0) x = -x, putchar('-');
static char stk[1024];
int top = 0;
while (x != 0) stk[top++] = x % 10, x /= 10;
while (top) putchar(stk[--top] + '0');
}
const int Len =... | 19 |
#include <bits/stdc++.h>
long long n10[10] = {1, 10, 100, 1000, 10000,
100000, 1000000, 10000000, 100000000, 1000000000};
using namespace std;
struct abc {
int x, y;
} a[55];
bool cmp(abc b, abc m) {
if (b.x == m.x) return (b.y < m.y);
return (b.x > m.x);
}
int n, k;
int r... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int CN = 550;
int n;
char ch[CN];
bool checker() {
int a = 0, b = 0;
for (int i = 0; i < n; i++)
if (ch[i] == '(')
a++;
else
b++;
return a == b;
}
int ans = 0, ansi = 1, ansj = 1;
int abs(int x) { return x > 0 ? x : -x; }
int GetAns() {
int... | 17 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
const int N = 2e5 + 10;
long long gcd(long long n, long long m) { return m == 0 ? n : gcd(m, n % m); }
int main() {
long long t, w, b;
cin >> t >> w >> b;
long long g = gcd(w, b);
long long lcm = 1;
long long minv = min(w, b);
long... | 10 |
#include <bits/stdc++.h>
const int N = 100005, ST = 63;
int n, m, bit[N], ans[N], cnt[7], num[ST + 2][N];
char s[N], ssr[9];
inline int Check(int x) {
for (int st = 0; st <= ST; ++st) {
int cnum = 0;
for (int i = 0; i < 6; ++i) {
if ((st >> i) & 1) cnum += cnt[i];
}
if (num[st][n] - num[st][x] <... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
long long a[n];
long long count[200001] = {0};
long long m = 0;
long long hf = 0;
for (long long i = 0; i < n; i++) {
cin >> a[i];
count[a[i]]++;
m = max(count[a[i]], m);
if (count[a[i]] == m) {
hf = a[... | 6 |
#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... | 6 |
#include <bits/stdc++.h>
std::mt19937_64 rng(
std::chrono::steady_clock::now().time_since_epoch().count());
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
long long f = 0;
map<char, ... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct tree {
vector<vector<int>> e;
vector<int> d, p;
int n;
tree(int n) : e(n), d(n), p(n), n(n) {}
void add_edge(int x, int y) {
e[x].push_back(y);
e[y].push_back(x);
}
vector<int> dijametar() {
d[0] = 0;
dfs(0, 0);
int x = max_element(d... | 17 |
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
const long long big = 1000000007ll;
const long long big2 = 1000000009ll;
long long n, m, k, q, w, h, x;
struct Tree {
vector<vector<int> > C;
vector<vector<int> > CW;
vector<int> line;
vector<int> labels;
vector<int> invlabels;
vecto... | 17 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target( \
"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native"
using namespace std;
int main() {
long long tc, num, t = 1, choose;
scanf("%lld", &num);
long long arr[num];
for (long long i = 0; i < num; i++) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int check(vector<string> v, int n, int m) {
int ind = 0;
for (int i = 0; i < n; i++) {
for (int k = 0; k < m; k++) {
if (v[i][k] == '1') {
ind = i;
break;
}
}
}
return ind;
}
int solve(vector<string>& v, int i, int dp[][3], int n,... | 8 |
#include <bits/stdc++.h>
using namespace std;
vector<int> B;
int m;
map<int, int> bad;
map<int, int> mem;
int gcd(int a, int b) {
if (!b) return a;
return gcd(b, a % b);
}
inline int f(int x) {
if (mem.find(x) != mem.end()) return mem[x];
int &ans = mem[x];
if (x == 1) return 0;
for (int i = 2; i * i <= x; ... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long b[100010], a[9][3];
int n, cnt[9] = {2, 1, 2, 1, 0, 1, 2, 1, 2}, maxcnt = -1;
int dx[9] = {-1, -1, -1, 0, 0, 0, 1, 1, 1},
dy[9] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};
int main() {
cin >> n;
for (int i = 0; i < n; i++) cin >> b[i];
if (n == 1 || n == 2) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int a[200000], f[30001][201][2][2][2], n, k;
int cs(int x, int y, int z, int q) {
int p;
if (q == k || q == 1) {
if (y == 0)
return x;
else
return -x;
}
if (y == z)
return 0;
else if (y == 0)
return x * 2;
else
return -2 * x;
}
in... | 18 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int i, int j) {
if (j == 0)
return i;
else
return gcd(j, i % j);
}
template <typename T>
inline T getint() {
T val = 0;
char c;
bool neg = false;
while ((c = getchar()) && !(c >= '0' && c <= '9')) {
neg |= c == '-';
}
do {
val = (val ... | 19 |
#include <bits/stdc++.h>
using namespace std;
int i, j;
bool check_queue(queue<int> qu, int c) {
bool is_right = true;
queue<int> qu2;
while (!qu.empty()) {
if (qu.front() > c) {
is_right = false;
}
qu2.push(qu.front());
qu.pop();
}
return is_right;
}
int main() {
int n, t, c;
cin >>... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
int pre[9] = {0LL, 1LL, 1LL, 3LL, 16LL, 125LL, 1296LL, 16807LL, 262144LL};
const int mod = 1000000007;
int main() {
while (~scanf("%d%d", &n, &k)) {
long long sum = (long long)(k * pre[k]) % mod;
int temp = n - k;
for (int i = 1; i <= temp; i++) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
void data() {}
void win() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }
int block = 400;
const long double eps = 1e-6;
const int N = 1e6 + 500;
const int mod = 1e9 + 7;
const long long hh = 100010683;
const long long hh2 = 150005819;
int k, kol, sz;
string seco... | 11 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char ch;
do {
ch = getchar();
if (ch == '-') f = -1;
} while (ch < '0' || ch > '9');
do {
x = x * 10 + ch - '0';
ch = getchar();
} while (ch >= '0' && ch <= '9');
return x * f;
}
const int N = 100010, AS = ... | 20 |
#include <bits/stdc++.h>
int main() {
int n, s, t, temp = 0;
scanf("%d", &n);
int a[1000], b[1000], q = 0;
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
for (int i = 1; i < n - 1; i++) {
for (int j = 0; j < n; j++) {
if (j != i) {
b[q] = a[j];
q++;
}
}
int diff;
f... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
while (n--) {
string s;
cin >> s;
int sum = 0;
bool works = false;
for (auto i : s) {
sum += i - '0';
if (i == '0') works = true;
}
if (sum % 3 == ... | 2 |
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
bool wziete[305][305];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cout << i <<... | 5 |
#include <bits/stdc++.h>
const long long N = 5001;
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
int a[N];
for (int i = 1; i <= n; i++) cin >> a[i];
int fir[N] = {0}, las[N] = {0};
for (int i = 1; i <= n; i++) las[a[i]] = i;
for (int i = n; i >= 1; i--) fi... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 7;
int n;
int mx[4 * N];
int add[4 * N];
void push(int v, int tl, int tr) {
if (add[v]) {
mx[v] += add[v];
if (tl < tr) {
add[2 * v] += add[v];
add[2 * v + 1] += add[v];
}
add[v] = 0;
}
}
void upd(int v, int tl, int t... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int x4[] = {1, -1, 0, 0};
int y4[] = {0, 0, 1, -1};
int x8[] = {0, 0, +1, -1, -1, +1, -1, +1};
int y8[] = {-1, +1, 0, 0, +1, +1, -1, -1};
int main() {
int n;
while (cin >> n) {
long long sum = 0, x;
for (int i = 0; i < n; i++) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
int n;
cin >> n;
int arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
int sum = 0;
bool can = false;
for (int i = 1; i < n; i++) {
if (arr[i - 1] <= arr[i]) {
c... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
long long int n, s;
cin >> n >> s;
long long int l = 1, r = 1000000000000000000, mid;
while (l <= r) {
mid = (l + r + 1) / 2;
stringstream temp;
temp << mid;
string st;
temp >> ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
while (scanf("%I64d", &n) != EOF) {
double temp = (double)sqrt(n);
int f, c;
f = floor(temp);
c = ceil(temp);
if (temp == f)
printf("%I64d\n", (long long)temp * 2);
else if (temp < ((floor(temp) + ceil(temp)) / 2))... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long INF = 2000000007;
long long INFLL = (long long)INF * (long long)INF;
long double EPS = 10e-7;
long double pi = 2 * acos(0.0);
bool isprime(long long n) {
for (long long i = 2; i < n; i++) {
if (n % i == 0) return 0;
}
return 1;
}
void solve(long long tc)... | 0 |
#include <bits/stdc++.h>
using namespace std;
mt19937_64 mt_rnd_64(chrono::steady_clock::now().time_since_epoch().count());
long long rnd(long long l, long long r) {
return (mt_rnd_64() % (r - l + 1)) + l;
}
double getDistance(double x1, double y1, double x2, double y2) {
return sqrt((x1 - x2) * (x1 - x2) + (y1 - y... | 10 |
#include <bits/stdc++.h>
const int N = (int)1e5 + 7;
const int MOD = (int)1e9 + 7;
const long long INF = (long long)1e18;
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
int n, x;
cin >> n >> x;
vector<int> A(n), B(n);
for (int ... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long f[200005], dis[200005], mark[200005], sum[200005], len[200005];
long long n, a[200005];
struct Edge {
long long v, l;
} now;
vector<Edge> edge[200005];
void init() {
memset(dis, 0, sizeof(dis));
memset(sum, 0, sizeof(sum));
memset(len, 0, sizeof(len));
}
v... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int NMax = 110000, MMax = 1100000;
struct edge {
int num, flag;
edge *next, *rev;
} * G[NMax], pool[MMax];
int N, M, L;
void Build(int x, int y) {
edge *p = &pool[L++], *q = &pool[L++];
p->num = y;
p->next = G[x];
G[x] = p;
q->num = x;
q->next = G[y];
... | 18 |
#include <bits/stdc++.h>
using namespace std;
int n, x, a[105], b[105];
int main() {
cin >> n >> x;
for (int i = 1; i <= n; ++i) cin >> a[i] >> b[i];
bool yes = 1;
for (int i = 1; i <= n; ++i)
if (x == a[i] || x == b[i] || 7 - x == a[i] || 7 - x == b[i]) yes = 0;
if (yes)
printf("YES\n");
else
p... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long int mod_expo(long long int MOD, long long int a, long long int b) {
long long int ans = 1;
while (b) {
if (b % 2) {
ans *= a;
ans %= MOD;
}
b /= 2;
a *= a;
a %= MOD;
}
return ans % MOD;
}
void display(vector<int> v1) {
for... | 8 |
#include <bits/stdc++.h>
using namespace std;
void taskC() {
int n, k;
cin >> n >> k;
string s, t;
cin >> s;
int f = 0;
t = s;
for (int i = (k); i < (n); i++) t[i] = t[i - k];
if (t >= s) {
cout << n << "\n" << t << "\n";
return;
}
for (int i = k - 1; i >= 0; i--) {
if (t[i] != '9') {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int sumPos = 0, sumNeg = 0;
while (n > 0) {
int temp;
cin >> temp;
if (temp > 0)
sumPos += temp;
else
sumNeg += temp;
n--;
}
cout << sumPos - sumNeg;
return 0;
}
| 0 |
#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 int read() {
int x = 0;
char ch = getchar();
bool positive = 1;
for ... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2001;
const long long MOD = 1e9 + 7;
const double eps = 1e-9;
struct point {
int x, y;
point(){};
point(int x, int y) {
this->x = x;
this->y = y;
}
point operator-(const point &o) const {
point res;
res.x = x - o.x;
res.y = y - o.... | 19 |
#include <bits/stdc++.h>
using namespace std;
int a[20][20], b[20][20];
int vis[20][20], vis1[20][20];
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
int x, y;
cin >> x >> y;
a[x][y] = a[y][x] = 1;
}
for (int i = 1; i <= m; i++) {
int x, y;
cin >> x >> y;
b[x][y] ... | 11 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.