solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#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 Q>
using TreeMergeFunction = function<Q(const Q &, const Q &)>;
template <class T, class Q>
using TreeUpdateLeafFunction =
function<Q(const Q &, const ... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 * 1000 + 10;
int n, m;
vector<pair<int, int> > vertex[maxn];
bool mark[maxn];
stack<int> f[maxn];
stack<int> adj[maxn];
int build(int v) {
for (int i = 0; i < ((int(vertex[v].size()))); i++) {
int u = vertex[v][i].first, e = vertex[v][i].second;
... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m;
cin >> n >> m;
vector<string> v;
for (long long i = 0; i < n; i = i + 1) {
string h;
cin >> h;
v.push_back(h);
}
pair<long long, long long> s, t;
for (long long i = 0; i < n; i = i + 1) {
for (long long j = 0; j < m... | 8 |
#include <bits/stdc++.h>
long long rnb[40 + 1];
int main() {
long long n;
int nrb;
scanf("%I64d", &n);
nrb = 0;
while ((1LL << nrb) <= (n - 1)) nrb++;
nrb--;
int i;
rnb[1] = 1;
for (i = 2; i <= 40; i++) rnb[i] = 2 * rnb[i - 1] + (1LL << (i - 1));
long long rez = 0;
while (nrb >= 0) {
while (nr... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int n = s.size();
int x = 97;
int cnt = 0;
int dif;
for (int i = 0; i < n; i++) {
dif = abs(s[i] - x);
if (dif > 13) {
dif = 26 - dif;
}
cnt += dif;
x = s[i];
}
cout << cnt;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
x = 0;
;
int f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
x *= f;
}
const int N... | 11 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#pragma GCC target("avx,tune=native")
using namespace std;
namespace fastio {
char in[100000];
int itr = 0, llen = 0;
char get() {
if (itr == llen) llen = fread(in, 1, 100000, stdin)... | 15 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:250000000")
template <typename T>
int size(T& a) {
return (int)a.size();
}
template <typename T>
T sqr(T a) {
return a * a;
}
const int INF = 1000 * 1000 * 1000;
struct rib {
int b, u, c, f;
size_t back;
};
void add_rib(vector<vector<... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int MAXINT = 2147483647;
const long long MAXLONGINT = 9223372036854775807;
const int MAX = 300000;
long long n, a, s;
vector<long long> ans, v[MAX];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
... | 11 |
#include <bits/stdc++.h>
using std::cerr;
using std::cin;
using std::max;
using std::min;
int n, top;
struct point {
long long x, y;
friend point operator-(point t1, point t2) {
return {t1.x - t2.x, t1.y - t2.y};
}
friend long long operator*(point t1, point t2) {
return t1.x * t2.y - t2.x * t1.y;
}
... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 51;
map<int, int> mp;
int n, kk, MOD, res, u, v, w, x;
int invf[MAXN], pr[MAXN];
inline int read() {
register int num = 0, neg = 1;
register char ch = getchar();
while (!isdigit(ch) && ch != '-') {
ch = getchar();
}
if (ch == '-') {
... | 24 |
#include <bits/stdc++.h>
using namespace std;
const int G = 1e9 + 1;
unordered_map<int, int> ft;
void gnk(int i) {
while (i < G) {
++ft[i];
i += (i & -i);
}
}
int pj(long long i) {
int dr = 0;
while (i) {
dr += ft[i];
i -= (i & -i);
}
return dr;
}
int sj(int l, int r) { return pj(r) - pj(l -... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s1, s2;
cin >> n;
cin >> s1 >> s2;
int vverh[100000], vniz[100000], rovno[100000];
for (int i = 0; i < n; i++) {
if ((s1[i] == '?') && (s2[i] == '?')) {
vverh[i] = 45;
vniz[i] = 45;
rovno[i] = 10;
} else if (s... | 12 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rnd;
const int mod = 998244353;
inline int add(int a, int b) {
if (a + b >= mod)
return a + b - mod;
else
return a + b;
}
inline int sub(int a, int b) {
if (a - b < 0)
return a - b + mod;
else
return a - b;
}
inline int mult(int a, int b) { r... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100009;
const int mod = 1e9 + 7;
int n, m, f[maxn];
int main() {
scanf("%d%d", &n, &m);
f[0] = f[1] = 2;
for (int i = 2; i <= max(n, m); i++) f[i] = (f[i - 1] + f[i - 2]) % mod;
printf("%d", (f[n] + f[m] - 2) % mod);
}
| 9 |
#include <bits/stdc++.h>
using namespace std;
long long nxt() {
long long x;
cin >> x;
return x;
}
long long _gcd(long long a, long long b) {
if (a == 0) return b;
return _gcd(b % a, a);
}
void testcase() {
long long a, m;
cin >> a >> m;
const long long gcd = _gcd(a, m);
const long long m_dash = m / g... | 10 |
#include <bits/stdc++.h>
int i, j, k, m, n;
int main() {
fscanf(stdin, "%d%d", &m, &n);
double r = m;
for (i = m - 1; i >= 1; i--) r -= pow((double)i / m, n);
printf("%.16lf", r);
return 0;
}
| 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
struct edge {
int u, v, w, next, id;
} e[N];
int mcnt, link[N], x[N], y[N], z[N], dis[N], k[N], pre[N];
bool flag[N];
queue<pair<int, int> > q;
void add(int x, int y, int z, int ID) {
e[mcnt].u = x;
e[mcnt].v = y;
e[mcnt].w = z;
e[mcnt].next ... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
while (~scanf("%d", &n)) {
if (n == 1) {
cout << n << " ";
continue;
}
int s = 1;
for (int i = 1; i < n; i++) {
int x = (i + s) % n;
if (x == 0) x = n;
cout << x << " ";
s += i;
}
cout << en... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1111111;
int n, x;
int a[maxn];
int pre_big[maxn];
int aft_little[maxn];
int main() {
ios::sync_with_stdio(false);
while (cin >> n >> x) {
for (int i = 0; i < n; i++) cin >> a[i];
set<int> st;
memset(pre_big, 0, sizeof pre_big);
for (int... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int INF = -1u / 2;
const int MAX_N = 1e5 + 5;
int n, m, d;
int ans;
int down[MAX_N][2];
bool spec[MAX_N];
vector<int> adj[MAX_N];
inline void dfs1(int u, int p = 0) {
down[u][0] = down[u][1] = spec[u] ? 0 : -INF;
for (int i = 0; i < adj[u].size(); i++) {
int v... | 12 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 5e3 + 2;
const long long mod = 998244353;
long long n, a[N], c[N], f[N][N], sum[N];
signed main() {
scanf("%lld", &n);
for (register long long i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
}
sort(a + 1, a + n + 1);
long long pos = 0;
for (r... | 18 |
#include <bits/stdc++.h>
using namespace std;
long long a[10][10];
int nn;
int num[10];
int d[10];
int row[10];
int col[10];
int dia[10];
long long tot;
int n;
bool rec(int r, int c) {
if (r == n - 1) {
long long rem = tot - col[c];
for (int i = 0; i < nn; i++) {
if (d[i] && num[i] == rem) {
if ... | 11 |
#include <bits/stdc++.h>
using namespace ::std;
const int maxn = 6e5 + 500;
const int mod = 1e9 + 7;
const int inf = 1e9 + 500;
vector<pair<int, char> > ger[maxn];
int bach[maxn][26];
int par[maxn];
vector<int> hh[maxn];
int siz[maxn];
void dfs(int a, int p = -1, int h = 1) {
hh[h].push_back(a);
siz[a] = 1;
par[a... | 17 |
#include <bits/stdc++.h>
using namespace std;
void(o_o)();
long long int i, j, k;
const long long int mod = 1000000007;
const long long int inf = 0x3f3f3f3f3f3f3f3fLL;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout << fixed << setprecision(10);
int t = 1;
while (t--) (o_o)();
}
long long int n... | 15 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int ciur[100005], p[100000], cmmdc[5005];
unordered_map<int, int> bad;
int a[5005], b[5005];
inline int gcd(int a, int b) {
int r;
while (b) {
r = a % b;
a = b;
b = r;
}
return a;
}
int main() {
for (int i = 2; i <= 100000; ++i) {
if (ciu... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e5 + 100;
void solve() {
int n;
cin >> n;
long long arr[n];
for (int i = 0; i < n; i++) cin >> arr[i];
int chek = n * (n - 1) / 2 - 1;
int ans = 0;
for (int i = 0; i < n - 1; i++) {
if (arr[i] > arr[i + 1]) ans++;
}
if (ans != n... | 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ull = unsigned long long int;
using dd = double;
using ldd = long double;
ll mod = 998244353;
ll bp(ll a, ll n) {
ll ans = 1;
while (n) {
if (n & 1) ans = ans * a % mod;
a = a * a % mod;
n >>= 1;
}
return ans;
}
int _size ... | 16 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
int n,m,t,k;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cin >> t;
while (t--)
{
cin >> n >> k;
// k = 2
int prv = 0, r = 0;
for (i... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.sync_with_stdio(0);
cin.tie(0);
int n, m, k;
cin >> n >> m >> k;
cout << (m * (m - 1)) / 2 << endl;
for (int i = 1; i <= m; i++) {
for (int j = i + 1; j <= m; j++) {
if (k == 1) {
cout << max(i, j) <<... | 7 |
#include <bits/stdc++.h>
using ll = long long;
const int C = 200001, M = 998244353;
inline ll pow(ll a, ll b, ll M) {
if (b == 0) return 1;
ll c = 1;
while (b > 0) {
if (b % 2 == 1) c = (c * a) % M;
b /= 2;
a = (a * a) % M;
}
return c;
}
ll fac[C], af[C];
inline ll cn(int n, int k) {
if (n < k |... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
const double eps = 1e-6;
int x[MAXN], y[MAXN];
int n;
int add(int x) {
x = x + 1;
x %= n;
return x;
}
int sub(int x) {
x = x - 1;
if (x < 0) x += n;
return x;
}
double Cal(int x1, int y1, int x2, int y2, int x3, int y3) {
double x4 = x... | 10 |
#include <bits/stdc++.h>
using namespace std;
char a[205];
int n, m;
const int oo = 1000000;
int f[110][110][2], ans = -oo;
int work(int x, int y, int d) {
if (y > m) return -oo;
if (x >= n) {
if (y == m)
return 0;
else
return -oo;
}
if (f[x][y][d] > -1000) return f[x][y][d];
int s1 = -oo,... | 10 |
#include <bits/stdc++.h>
int main() {
int i, j, n, m, x, y, z, p, a, b, ta, tb, nn, mm, temp;
scanf("%d%d%d%d%d%d", &n, &m, &x, &y, &z, &p);
for (i = 0; i < p; i++) {
scanf("%d%d", &a, &b);
ta = a, tb = b;
nn = n, mm = m;
if (x % 4 == 1) {
a = tb;
b = nn + 1 - ta;
temp = nn;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, a[N];
bool used[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int dir = 0;
int cur = 0;
int ans = 0;
while (true) {
bool ok = false;
if (dir == 0) {... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0);
std::ios::sync_with_stdio(false);
long long int x;
cin >> x;
if (x & 1)
cout << (x / 2) + 1 << endl;
else
cout << x / 2 << endl;
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
int arr[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> arr[i][j];
}
}
int count = 0;
for (int i = 0; i < n; i++) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int s, n, k, i, x, nr;
int main() {
cin >> n;
cin >> x;
for (i = 1; i <= n; i++) {
s = s + i;
k++;
}
while (s != x) {
s = s - (k + 1);
k--;
nr++;
}
cout << nr;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
double eps = 1e-6;
struct node {
node *l, *r;
int x, y, cnt;
long long sum;
node() {
l = r = NULL;
cnt = sum = 0;
}
} * t;
void out(node *t) {
if (!t) return;
out(t->l);
cout << t->x << " ";
out(t->r);
}
void upd(node *&x) {
... | 14 |
#include <bits/stdc++.h>
using namespace std;
int n, m, qq, to[200021 * 4][2][33], pos[200021 * 4], lz[200021 * 4];
int a[200021];
void push_up(int u) {
for (int t = 0; t < 2; t++) {
for (int i = 0; i < 1 << m; i++) {
to[u][pos[u] ^ t][i] =
to[u << 1][pos[u << 1] ^ t][to[u << 1 | 1][pos[u << 1 | 1... | 22 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int f = 0, d = 0, g = 0;
if (s.size() > 1)
for (int i = 0; i < s.size() - 2; i++) {
if ((s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'A') ||
(s[i] == 'B' && s[i + 1] == 'A' && s[i + 2] == 'B')) {
s[i] = ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 64;
long long t1[maxn + 5];
long long t2[maxn + 5];
long long base[maxn + 5];
int len(long long n) {
int ans = 0;
for (int len = 0; len < 63; len++) {
if ((1LL << len) & n) {
ans = len + 1;
}
}
return ans;
}
long long parent(long long ... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, a[1005], b[1005], i, j, r = 0, c = 0;
cin >> n;
for (i = 0; i < n; i++) {
cin >> a[i] >> b[i];
if (a[i] == b[i]) r++;
}
for (j = 0; j < n - 1; j++) {
if (a[j + 1] > a[j]) c++;
}
if (c == 0 && r == n)
cout << "maybe";
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, s;
cin >> a >> b;
s = a * b / 2;
cout << s << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 500 + 10;
const long long int mod = 1e9 + 7;
clock_t startTime;
double getCurrenttime() {
return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}
void fastio() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
std::cout.tie(NULL);
}
bool co... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3000 + 10, mod = 998244353;
int a[N];
int ans[N][N];
pair<long long, long long> p[N];
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i], p[i] = {-a[i], i};
sort(p, p + n);
for (int i = ... | 18 |
#include <bits/stdc++.h>
using namespace std;
int abs(int x) { return (x > 0 ? x : -x); }
int main() {
ios::sync_with_stdio(false);
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
if (x1 != x2 && y1 != y2 && abs(x1 - x2) != abs(y1 - y2))
cout << -1 << endl;
else if (x1 == x2)
cout << x1 + abs(y1 - y2... | 4 |
#include <bits/stdc++.h>
using namespace std;
void boost() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
const int N = 1e6;
const long long inf = 1e9 + 7;
const long double PI = acos(-1);
long long bin_pow(long long x, long long y) {
long long res = 1, base = x;
while (y) {
if (y & 1) {
... | 14 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int n, m;
cin >> n >> m;
vector<vector<int>> g(n);
for (int i = 0; i < m; i++) {
int v, u;
cin >> v >> u;
v--, u--;
g[v].push_back(u)... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 20;
const int maxM = (1 << maxN) + 10;
const int Mod = 1000000007;
const int inv2 = 500000004;
int n;
char In[maxM];
int A[maxM], C[maxM], pw[maxN + 10];
void FWT(int N, int *P, int opt);
int main() {
scanf("%d", &n);
int N = 1 << n;
scanf("%s", In);
... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const long long int MAX = 2e18;
bool GoodNumber(long long int N) {
while (N > 0) {
if (N % 3 == 2) {
return false;
}
N /= 3;
}
return true;
}
int main() {
int t;
cin >> t;
while (t--) {
int... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
string s, t;
cin >> s >> t;
int n = s.size(), m = t.size();
int ans = 0, x, f;
string q = "", w;
for (int i = 0; i < n; i++) {
if (i >= m - 1) {
f = 1;
for (int j = i - m + 1; j <= i; j++) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
inline void pisz(int n) { printf("%d\n", n); }
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) = ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, k, g[123][123], f[123], a[123], b[123], u[123], v[123];
int fpow(int a, int n) {
int res = 1;
for (; n; n >>= 1, a = (long long)a * a % 1000000007)
if (n & 1) res = (long long)res * a % 1000000007;
return res;
}
int main() {
int i = 1, j, k, l, o;
for (... | 18 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = (long long)1e18;
const int mod = (int)1e9 + 7;
const int MAXN = (int)3e5 + 5;
long long n;
long long a[MAXN];
long long b[MAXN];
map<pair<long long, long long>, long long> mp;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.... | 16 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
const int maxn=1e5+5;
int n,T;
ll a[maxn];
int main(){
cin>>T;
while(T--){
cin>>n;
ll sum=0,mx=0;
for(int i=0;i<n;i++){
cin>>a[i];
mx=max(mx,a[i]);
sum+=a[i];
}
ll tot=mx*(n-1);
if(su... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e4 + 5, maxm = 1e6 + 5;
struct node {
int l, r;
} q[maxn];
int n, m, s[maxm], a[maxm], ans[maxm], f[maxm];
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -f;
ch = getchar();
}
... | 20 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
void solve() {
int n;
cin >> n;
map<int, int> m;
m.insert(make_pair(25, 0));
m.insert(make_pair(50, 0));
m.insert(make_pai... | 3 |
#include <bits/stdc++.h>
using namespace std;
std::vector<long double> v;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long double n, a, b, s1, tt;
cin >> n >> a >> b;
int ans = 0;
cin >> s1;
long double sumis = s1;
for (int i = 1; i < n; ++i) {
cin >> tt;
v.push_back(tt);
sumis +=... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int IINF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
const double DINF = numeric_limits<double>::infinity();
const int MOD = 1000000007;
const double EPS = 1e-9;
const int DX[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int DY[] = {0, 1, 0, -1, 1, -1, -1, 1};... | 17 |
#include <bits/stdc++.h>
using namespace std;
vector<long long int> pos;
int main() {
int k;
string X;
scanf("%d", &k);
cin >> X;
for (int i = 0; i < X.length(); i++) {
if (X[i] == '1') pos.push_back(i);
}
int n = pos.size();
if (n < k) {
cout << "0";
return 0;
}
if (k == 0) {
long l... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
const long long INFLL = 1000000000000000000LL;
int n, m, i, j, a, b, nx, px, ny, py;
int main() {
scanf("%d%d%d%d%d%d", &n, &m, &i, &j, &a, &b);
nx = ny = px = py = INF;
if ((i - 1) % a == 0) {
if (((i - 1) / a) % 2) {
nx = min(nx... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, m, b;
struct poi {
int x, k, a;
} P[106];
bool cmp(poi a, poi b) { return a.k < b.k; }
long long dp[2][1 << 20];
signed main() {
cin >> n >> m >> b;
for (int i = 1, c, x; i <= n; ++i) {
scanf("%d%d%d", &P[i].x, &P[i].k, &c);
while (c-- > 0) scanf("%d", ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007, ar = 2000005;
unordered_map<string, vector<string> > mp;
vector<string> one, two, tr, all;
map<char, bool> vis;
vector<string> v1, v2, v3, last;
int main() {
int x;
cin >> x;
while (x--) {
int p;
string s;
cin >> p >> s;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int x = sqrt(8 * n + 1) + 1e-8;
cout << (x * x == 8 * n + 1 ? "YES" : "NO");
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int inf = 1e9;
int n, m, h;
vector<int> g[maxn];
int degree[maxn], killed[maxn];
void print_ans(vector<int> &ans, int i, int j) {
printf("%d\n", j - i + 1);
for (int k = (i); k <= (j); k++) printf("%d%c", ans[k], k == j ? '\n' : ' ');
}
i... | 17 |
#include <bits/stdc++.h>
using namespace std;
int a[10];
int n, ans;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
int t;
scanf("%d", &t);
a[t]++;
}
while (a[1] >= 1 && a[2] >= 1) {
a[1] -= 1;
a[2] -= 1;
a[3] += 1;
ans += 1;
}
while (a[2] >= 3) {
a[2] -= 3;
... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n;
deque<int> adj[1001];
deque<int> leaf;
int sze[1001];
bool visit[1001];
int main() {
ios::sync_with_stdio(0), cin.tie(0);
cin >> n;
for (int i = 1; i < n; i++) {
int x, y;
cin >> x >> y;
adj[x].push_back(y);
adj[y].push_back(x);
sze[x]++, sz... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
int n, a[N], dp[N][N];
int rec(int i, int j) {
if (j > n) {
return a[i];
}
if (dp[i][j] > 0) {
return dp[i][j];
}
return dp[i][j] = min({max(a[i], a[j]) + rec(j + 1, j + 2),
max(a[i], a[j + 1]) + rec(j, j + 2... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int n, d;
scanf("%d%d", &n, &d);
char opp[d][n];
for (int i = 0; i < d; i++) {
scanf("%s", opp[i]);
}
int counter = 0, maxi = 0;
for (int i = 0; i < d; i++) {
bool beaten = false;
for (int k = 0; k < n; k++) {
if (opp[i][k] =... | 0 |
#include <bits/stdc++.h>
using namespace std;
void make_change(vector<int> &a, int idx, int val, long long &ans) {
int n = a.size() - 2;
for (int i = idx - 1; i <= idx + 1; i++) {
if (1 <= i && i <= n) {
if (a[i - 1] <= a[i] && a[i] >= a[i + 1]) {
ans -= a[i];
} else if (a[i - 1] >= a[i] && ... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() { cout << "Red" << endl; }
| 10 |
#include <bits/stdc++.h>
int main() {
int n, a, b, t;
scanf("%d", &(n)), scanf("%d", &(a)), scanf("%d", &(b));
t = n * b;
t = ceil((double)t / 100);
printf("%d", (0 > (t - a) ? 0 : (t - a)));
printf("\n");
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2e9 + 1;
long long getS(long long x) { return x * (x + 1) / 2; }
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T;
cin >> T;
while (T-- > 0) {
long long x;
cin >> x;
int ans = 0;
for (int i = 1; getS((1LL ... | 4 |
#include <bits/stdc++.h>
const int MOD = 1e9 + 7;
using namespace std;
int main() {
long long int t;
cin >> t;
while (t--) {
long long int n, i, ans = 0;
cin >> n;
long long int ar[n + 1];
for (i = 0; i < n; i++) {
cin >> ar[i];
}
while (!is_sorted(ar, ar + n)) {
if (ans & 1) {... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2021;
int d[N][N], vis[N][N];
int n, m, ex, ey, k, x, y;
bool inmap(int x, int y) { return x > 0 && x <= n && y > 0 && y <= m; }
bool check(int x, int y) {
int l = max(x - d[x][y], 1), r = min(x + d[x][y], n);
for (int i = l; i <= r; i++) {
int t = d[x... | 16 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool isPrime(T x) {
if (x <= 1) return false;
T i;
for (i = 2; i * i <= x; i++)
if (x % i == 0) return false;
return true;
}
template <class T>
class Prime {
public:
vector<T> z;
Prime() {
z.resize(1e5 + 7);
for (int i = (0); i < ... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long add(long long a, long long b) { return min((long long)2e18, a + b); }
long long mul(long long a, long long b) {
if ((long double)a * b > 4e18) return 2e18;
return min((long long)2e18, a * b);
}
const int nax = 60;
long long g[nax];
long long mem[nax];
long lon... | 19 |
#include <bits/stdc++.h>
int main() {
int n;
int x;
long long total = 0;
int i;
int j = 1;
scanf("%d %d", &n, &x);
for (i = 0; i < n; i++) {
int first;
int second;
scanf("%d %d", &first, &second);
total += (second - first) + (first - j) % x + 1;
j = second + 1;
}
printf("%I64d", to... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAXV = 1e4 + 10;
const int MAXE = 1e5 + 5;
const long long INF = 0x3f3f3f3f3f3f3f3f;
long long tot;
long long head[MAXV], level[MAXV], iter[MAXV];
struct Edge {
long long v, cap, nxt;
Edge() {}
Edge(long long v, long long cap, long long nxt) : v(v), cap(cap)... | 19 |
#include <bits/stdc++.h>
using namespace std;
int a[1007];
int b[1007];
int main() {
int n, x, y;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
cin >> b[i];
}
int co = 0;
for (int i = 0; i < n; i++) {
int r = 0, d = 0, l = 0, u = 0;
for (int j = 0; j < n; j++) {
if (b[i] == b[j]... | 2 |
#include <bits/stdc++.h>
using namespace std;
int dp[100005];
int main() {
int n, m;
cin >> n >> m;
int arr[100005];
int l;
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
set<int> s;
for (int i = n - 1; i >= 0; i--) {
s.insert(arr[i]);
dp[i + 1] = s.size();
}
for (int i = 0; i < m; i++) ... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long n, k, t;
long long bs_ch(long long mid, long long x) {
if (mid * mid + mid <= 2 * x) return 1;
return 0;
}
long long bs(long long l, long long r, long long x) {
long long mid = (l + r) / 2;
while (r - l > 1) {
bs_ch(mid, x) ? l = mid : r = mid;
mid... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& a) {
in >> a.first >> a.second;
return in;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2> a) {
out << a.first << " " << a.second;
return out;
}
t... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long a[9];
long long dfs(long long vis, long long w) {
if (vis > 8) return w;
long long res = min(a[vis], w / vis), mins = 1e18;
for (long long i = res; i >= max(res - 8 / vis - 2, (long long)0); i--) {
mins = min(mins, dfs(vis + 1, w - i * vis));
}
retur... | 15 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
long long r;
while (b != 0) {
r = a % b;
a = b;
b = r;
}
return a;
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long fpow(long long n, long long k, int p = (int)1e9 + 7) {
long l... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, i, i2, i3, re = 0;
vector<int> disc, prices;
cin >> m;
disc.reserve(m);
for (i = 0; i < m; i++) {
cin >> i2;
disc.push_back(i2);
}
cin >> n;
prices.reserve(n);
for (i = 0; i < n; i++) {
cin >> i2;
prices.push_back(i2)... | 6 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int sum = 0;
char c = getchar();
bool f = 0;
while (c < '0' || c > '9') {
if (c == '-') f = 1;
c = getchar();
}
while (c >= '0' && c <= '9') {
sum = sum * 10 + c - '0';
c = getchar();
}
if (f) return -sum;
return sum;
}
... | 15 |
#include <bits/stdc++.h>
using namespace std;
int N, A, B, d[2003], a[2003], b[2003], ab[2003];
pair<int, int> calc(int c1, int c2) {
int ans1 = 0, ans2 = 0, rem = 0;
for (int i = 1; i <= N; i++) {
int add1 = a[i] - c1, add2 = b[i] - c2;
int add3 = ab[i] - c1 - c2;
if (add1 <= 0 && add2 <= 0 && add3 <= ... | 22 |
#include <bits/stdc++.h>
using namespace std;
int read() {
int res = 0;
char c = getchar();
while (!isdigit(c)) c = getchar();
while (isdigit(c)) res = res * 10 + c - '0', c = getchar();
return res;
}
const int N = 2e3 + 10;
const int Mod = 998244353;
int n, ans = 0;
int matrix[N][N], p[N][N], t[N];
bitset<N>... | 21 |
#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;
int main() {
char str[100];
cin >> str;
int l = 0;
while (str[l] != '\0') l++;
int m = 0;
for (int i = 1; i < l; i++) {
if (str[i] == str[i - 1])
m++;
else
m = 0;
if (m == 6) {
cout << "YES";
return 0;
}
}
cout << "NO"... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 3;
set<pair<int, int> > s;
int ans[maxn];
int main() {
long long sum = 0;
int n, k, a;
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; ++i) {
scanf("%d", &a);
s.insert(make_pair(a, i));
if (i >= k + 1) {
auto t = s.end();
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int n;
char temp[15];
int dp[26][26] = {0};
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> temp;
int sized = strlen(temp);
int start = temp[0] - 97;
int end = temp[sized - 1] - 97;
for (int i = 0; i <... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int nm = 1005;
const int mm = 1005;
int n, k, m, t;
int res;
int f[2002][2055];
bool check[nm];
const int MOD = 1000000007;
int main() {
int i, j, x, y, z, w;
f[0][0] = 1;
scanf("%d%d", &n, &k);
t = 1 << k;
for (i = 1; i <= n; i++) {
scanf("%d", &x);
... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long int x[1000001], y[1000001], n, mx, a, b;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long int t;
cin >> t;
while (t--) {
long long int n, m, ans = 0;
cin >> n >> m;
long long int a[100] = {}, b[100] = {}... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}, inf = 1e18 + 1;
bool valid(long long int x, long long int y, long long int n, long long int m) {
return (x >= 0 and y >= 0 and x < n and y < m);
}
int main() {
ios_base ::sync_with_stdio(false);
cin.tie(NULL)... | 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<long long> a(n + 1), b(n + 1);
deque<pair<long long, long long> > lines;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i... | 13 |
#include <bits/stdc++.h>
using namespace std;
char str[55];
int num[55], low[55], oth[55];
int main() {
int n, len;
while (scanf("%d%d", &n, &len) != EOF) {
for (int i = 0; i < n; i++) {
scanf("%s", str);
num[i] = low[i] = oth[i] = 1000000;
for (int j = 0; j < len; j++) {
int tmp = min... | 7 |
#include <bits/stdc++.h>
long long mod = 1e9 + 7;
using namespace std;
void solve() {
int n;
cin >> n;
cout << 3 << " " << 3 << endl;
int ans[3][3];
int k = 0;
while (n >= (1 << k)) k++;
ans[0][0] = ans[1][2] = (1 << (k + 1)) - 1;
ans[0][1] = ans[0][2] = ans[2][2] = n;
ans[1][0] = ans[1][1] = ans[2][0... | 9 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.