solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int A[16];
int B[16];
int main() {
string s;
cin >> s;
long long res = 0;
for (auto i : s) {
if (i == '.') {
continue;
}
res += (('@' < i && '[' > i) - ('`' < i && '{' > i)) *
((i >= 'a' ? i : i ^ 32) - 'a' + 1);
}
cout << res;
}
| 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int k;
cin >> k;
cout << 3 << " " << 3 << endl;
long long int x = pow(2, 17);
cout << x + k << " " << x + k << " " << k + x << endl;
cout << x << " " << k << " " << x << endl;
cout << x << " " << k + x << " " << k << endl;
return 0;
}
| 9 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3 * 100005;
const int maxm = 500005;
const int inf = 0x3f3f3f3f;
int n;
char a[55][55];
int dp[51][51][51][51];
int dfs(int x1, int y1, int x2, int y2) {
if (dp[x1][y1][x2][y2] != -1) return dp[x1][y1][x2][y2];
if (x1 == x2 && y1 == y2) return (a[x1][y1... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, k = 0, c = 0;
char s[100], a[6] = "hello";
cin >> s;
int len = strlen(s);
for (i = 0; i < len; i++) {
if (s[i] == a[k]) {
c++;
k++;
}
}
if (c == 5)
cout << "YES";
else
cout << "NO";
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
std::pair<T, U> operator+(const std::pair<T, U>& l, const std::pair<T, U>& r) {
return {l.first + r.first, l.second + r.second};
}
typedef void (*callback_function)(void);
const long long INF64 = 1e18;
const long long INF32 = 1e9;
bool vi... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, c;
cin >> a >> c;
stack<int> ast;
while (a) {
ast.push(a % 3);
a /= 3;
}
stack<int> cst;
while (c) {
cst.push(c % 3);
c /= 3;
}
while (ast.size() < cst.size()) ast.push(0);
while (cst.size() < ast.size()) cst.push(0);
... | 3 |
#include <bits/stdc++.h>
using namespace std;
void prevGreater(vector<long long> &arr, int n) {
vector<long long> out;
stack<int> s;
s.push(arr[0]);
out.push_back(-1);
for (int i = 1; i < n; i++) {
while (s.empty() == false && s.top() < arr[i]) s.pop();
if (s.empty())
out.push_back(-1);
else... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
const int MAXM = 5e5 + 5;
const int MOD = 998244353;
const int INF = 0x3f3f3f3f;
long long a[MAXN];
int main() {
long long n, k;
scanf("%lld%lld", &n, &k);
for (int i = 1; i <= n; ++i) {
scanf("%lld", &a[i]);
}
if (n == 1) {
print... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long arr[9];
long long m, sum;
bool f = false;
void dfs(int x, long long num) {
if (x == 9) {
sum = max(sum, num);
return;
}
for (long long k = 9, i = min((m - num) / x, arr[x]); k; k--, i--)
dfs(x + 1, num + max((long long)0, i * x));
}
int main() {
... | 15 |
#include <bits/stdc++.h>
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
using namespace std;
char str[300008];
int main() {
int t;
cin >> t;
cin >> str;
int i, ci = 0, ca = 0, cf = 0;
for (i = 0; i <= t - 1; i++) {
if (str[i] == 'I') ci++;
if (str[i] == 'A') ca++;
if (st... | 2 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
int a, dp[200010][2], n, k, ans, minvalue = LONG_MAX;
void solve() {
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> a;
dp[a][0]++;
dp[a][1]++;
minvalu... | 8 |
#include <bits/stdc++.h>
using namespace std;
bool ask(int x, int y) {
cout << 1 << ' ' << x << ' ' << y << endl;
string ret;
cin >> ret;
return ret == "TAK";
}
int go(int lo, int hi) {
if (lo > hi) return -1;
while (lo < hi) {
int mi = lo + hi >> 1;
if (ask(mi, mi + 1))
hi = mi;
else
... | 14 |
#include <bits/stdc++.h>
using namespace std;
inline long long rd() {
long long _x = 0;
int _ch = getchar(), _f = 1;
for (; !isdigit(_ch) && (_ch != '-') && (_ch != EOF); _ch = getchar())
;
if (_ch == '-') {
_f = 0;
_ch = getchar();
}
for (; isdigit(_ch); _ch = getchar()) _x = _x * 10 + _ch - '0... | 22 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T &x) {
x = 0;
char c = getchar();
int f = 1;
while (!isdigit(c)) {
if (c == '-') f = -1;
c = getchar();
}
while (isdigit(c)) {
x = x * 10 + c - '0';
c = getchar();
}
x *= f;
}
template <class T>
inline voi... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200100, mod = 1000000007;
inline void reduce(int& x) { x += x >> 31 & mod; }
long long sum[N];
int sum2[N];
int n, q, a[N], b[N], mx;
long long qry(int x) {
long long ret = 0;
for (; x; x -= x & -x) ret += sum[x];
return ret;
}
int qry2(int x) {
int re... | 17 |
#include <bits/stdc++.h>
using namespace std;
bool comp(pair<int, int> p1, pair<int, int> p2) { return p1.first > p2.first; }
int main() {
int n, k;
cin >> n >> k;
pair<int, int> p[n];
for (int i = 0; i < n; i++) {
int x;
cin >> x;
p[i] = {x, i};
}
int ans = 0;
vector<int> v;
sort(p, p + n, ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1035010;
char f[maxn][10], s[20];
int n, tmp[maxn];
char tmp2[maxn];
map<string, int> M;
long long b[20] = {0, 0, 0, 0, 3098, 13098,
113098, 1113098, 11113098, 111113098, 1111113098};
void F(int x) {
int c... | 12 |
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int s;
cin>>s;
float num=sqrt(s);
cout<<ceil(num)<<"\n";
}
} | 0 |
#include <bits/stdc++.h>
using namespace std;
const int dr[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int dc[] = {0, -1, 0, 1, -1, 1, -1, 1};
const int N = 1123;
int a[N][N], n, m;
vector<int> row[N], col[N];
int my_find(vector<int> &vec, int val) {
int idx = lower_bound((vec).begin(), (vec).end(), val) - vec.begin();
... | 8 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
string ToString(T t) {
stringstream s;
s << t;
return s.str();
}
template <class T>
void ToOther(T& t, string a) {
stringstream s(a);
s >> t;
}
long long n, m;
long long d[55];
void go(int pos, long long rest) {
for (int t = pos; t <= n; t++) ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
int n, m, t;
char s[1010][1010];
int dep[1010][1010];
pair<int, int> stk[1000010];
int stki = 0;
int deri[] = {0, 1, 0, -1};
int derj[] = {1, 0, -1, 0};
int main() {
cin >> n >> m >> t;
for (int i = 0; i < n; i++) {
scanf("%s", s[i]);
... | 12 |
#include <bits/stdc++.h>
using namespace std;
char d;
int m = INT_MAX;
int t = 0;
int bit = 1;
int bay = 0, st = -1;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string s;
cin >> s;
int l = s.length();
vector<int> s0, s2, s5;
for (int i = l - 1; i >= 0; --i) {
if (s[i] ==... | 13 |
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MN = 4e5 + 5;
struct Edge {
int to , nxt;
} E[MN << 1];
int N , f[MN] , tot = 1 , size[MN] , v0[MN] , vis[MN] , head[MN];
inline void AddEdge(int u , int v) {
E[++tot] = (Edge) {v , head[u]};
head[u] = tot;
}
inline int dfs(int x, in... | 16 |
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e5 + 1;
const long long mod = 1e9 + 7;
template <typename T>
istream &operator>>(istream &is, vector<T> &A);
void solve() {
long long n, x;
cin >> n >> x;
vector<long long> arr(n);
cin >> arr;
sort(arr.begin(), arr.end());
long long ans =... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int size1 = 2000;
int main() {
ios_base::sync_with_stdio(false);
int n, i;
cin >> n;
vector<string> mas(size1), mas1(size1);
for (i = 1; i <= n; i++) {
string s, s1;
cin >> s >> s1;
mas[i] = "";
mas[i] += s[0];
mas[i] += s[1];
mas[i] ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n;
int cnt;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
for (int j = i; j <= n; j++) {
if (i + j > (i ^ j) && j <= (i ^ j) && (i ^ j) <= n) cnt++;
}
}
cout << cnt << endl;
return 0;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
int a[1001], b[1001];
int ans = 100500;
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < m; i++) {
cin >> b[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (a[i] =... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
int main() {
int n, m, k;
scanf("%d%d%d", &n, &m, &k);
if (k / gcd((long long)n * m, k) > 2) {
puts("NO");
return 0;
}
long long now;
now = ((long long)... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int mxn = 100000;
int n, k;
int a[mxn], d[mxn];
vector<int> g[mxn];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 1, x; i < n; i++) cin >> x, g[x].push_back(i);
for (int i = n - 1; ~i; i--) {
for (int j : g[i]) d[i] = max(d[i],... | 17 |
#include <bits/stdc++.h>
int da[402] = {
0, 1, 9, 245, 126565, 54326037, 321837880,
323252721, 754868154, 328083248, 838314395, 220816781, 893672292, 166441208,
251255697, 114256285, 118775501, 482714697, 11784725, 460862131, 550384565,
106742050, 425241115, 626692854,... | 20 |
#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, a, b, oo = 1e9;
int f(int n, int m) {
int u = max(n - x, x - n), v = max(m - y, y - m);
if (u % a || v % b || u / a % 2 != v / b % 2) return oo;
return max(u / a, v / b);
}
int main() {
ios_base::sync_with_stdio(false);
cin >> n >> m >> x >> y >> a... | 12 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-6;
double X[55], Y[55], R[55];
double sqr(double x) { return x * x; }
int sign(double x) { return x < -EPS ? -1 : x > EPS; }
bool inside(int i, int j) {
double d = sqrt(sqr(X[i] - X[j]) + sqr(Y[i] - Y[j]));
if (sign(R[i] - R[j]) <= 0) return sign(d... | 11 |
#include <bits/stdc++.h>
using namespace std;
int dp[501][501], dp1[501][501];
int main() {
int r, c;
cin >> r >> c;
string s[r + 10];
for (int i = 0; i < r; i++) cin >> s[i];
for (int i = 0; i < r; i++) {
for (int j = 1; j < c; j++) {
dp[i][j] = dp[i][j - 1] + (s[i][j] == '.' && s[i][j - 1] == '.')... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int q, n, mp[2][200005];
char c;
cin >> q;
while (q--) {
cin >> n;
for (int i = 0; i < 2; i++) {
for (int j = 0; j < n; j++) {
cin >> c;
mp[i][j] = c - '0';
}
}
int k = 0, flag = 0;
for (int i = 0; i < n; ... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long dp[2010][2010];
int main() {
long long n, m, k;
cin >> n >> m >> k;
dp[1][0] = m;
for (int i = 2; i <= n; i++)
for (int j = 0; j <= k; j++)
if (j < i) {
if (j)
dp[i][j] =
(dp[i][j] + ((m - 1) * dp[i - 1][j - 1]) % ... | 7 |
#include <bits/stdc++.h>
using namespace std;
char s[1000005];
long long P[1000005], Num[1000005];
int n;
long long get(int l, int r) {
return (Num[r] - Num[l - 1] * P[r - l + 1] % 1000000007 + 1000000007) %
1000000007;
}
void check(int i1, int i2) {
if (i2 <= i1 || n <= i2) return;
if (i1 > n - i2 || i2... | 15 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll getrnd(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rng); }
template <typename T1, ... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, m, n, ret = 0, dy = 0;
cin >> n >> m;
vector<string> V(n);
for ((i) = 0; (i) < (n); (i)++) cin >> V[i];
for ((i) = (n - 1); (i) >= 0; (i)--)
if (V[i].find("W") == -1)
V.erase(V.begin() + i);
else
break;
n = (V).size();
... | 7 |
#include <bits/stdc++.h>
using namespace std;
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool x) { return (x ? "T" : "F"); }
string to_string(const char* s) { return to_string((string)s); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ... | 19 |
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
inline long long input() {
long long n;
cin >> n;
return n;
}
long long poww(long long a, long long b, long long md) {
return (!b ? 1
: (b & 1 ? a * poww(a * a % md, b / 2, md) % md
: poww(a * a % md, b /... | 14 |
#include <bits/stdc++.h>
using namespace std;
int n;
int p[100010];
vector<int> q;
bool was[100010];
set<pair<int, int> > e;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; ++i) cin >> p[i];
for (int i = 1; i <= n; ++i) {
if (p[i] == i) {
cout << "YES\n";... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long ex(long long a, long long b) {
long long ans = 1;
while (b) {
if (b & 1) ans = (ans * a) % (long long)(998244353);
a = (a * a) % (long long)(998244353), b /= 2;
}
return ans;
}
inline long long add(long long a, long long b) {
a = a % (long long)(... | 20 |
#include <bits/stdc++.h>
using namespace std;
struct bus {
int first, second, t, id;
bool operator<(const bus& a) const {
return second != a.second ? second > a.second : id < a.id;
}
} bs[100005 * 2];
set<int> b[100005 * 2];
map<int, int> tr;
int nn, ans[100005], xs[100005 * 2], ys[100005 * 2], xlen, ylen;
vo... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
while (scanf("%d %d", &n, &k) > 0) {
vector<int> vec(n);
for (int i = 0; i < n; i++) scanf("%d", &vec[i]);
sort(vec.begin(), vec.end());
reverse(vec.begin(), vec.end());
printf("%d\n", vec[k - 1]);
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
void Yes(int k, map<char, char> mp) {
cout << "YES\n";
set<char> used;
for (auto &e : mp) used.insert(e.second);
char nex = 'a';
for (int i = 0; i < k; i++) {
char c = 'a' + i;
if (mp.count(c)) {
cout << mp[c];
} else {
while (used.count(ne... | 15 |
#include <bits/stdc++.h>
using namespace std;
int n;
int m;
int pos[300];
vector<int> x[300];
int re1[300];
int re2[300];
int re3[300];
queue<int> nm1[5];
queue<int> nm2[5];
queue<int> nm3[5];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> pos[i];
}
for (int i = 1; i <= n; i++) {
cin >> m;... | 9 |
#include <bits/stdc++.h>
using namespace std;
int que[111111], result[111111];
vector<pair<int, char>> ans;
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &que[i]);
int m;
scanf("%d", &m);
for (int i = 1; i <= m; i++) scanf("%d", &result[i]);
int start = 1, end = 1, it = 1;
... | 10 |
#include <bits/stdc++.h>
using namespace std;
string s;
int len;
int main() {
cin >> len;
cin >> s;
string tmp = s;
if (s[0] > s[1]) {
tmp = s.substr(1);
cout << tmp << "\n";
return 0;
} else {
for (int i = 1; i < len; ++i) {
if (s[i] > s[i + 1]) {
tmp = s.substr(0, i);
t... | 4 |
#include <bits/stdc++.h>
bool islucky(int num) {
if (num < 0) {
num = -num;
} else if (num == 0) {
return false;
}
for (; num > 0; num /= 10) {
if (num % 10 == 8) {
return true;
}
}
return false;
}
int main() {
int A;
std::cin >> A;
int b;
for (b = 1; !islucky(A + b); b++)
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 3) + (x << 1) + (ch ^ 48);
ch = getchar();
}
return x * f;
}
char ch[205];
in... | 22 |
#include <bits/stdc++.h>
using namespace std;
int a[200001];
int abs(int x) { return x > 0 ? x : -x; }
int main() {
long long n, k, s = 0, h = 0;
cin >> n >> k;
int p = n, q = 0, ans = 0;
for (int i = 0; i <= n; i++) cin >> a[i];
while (abs(s = s * 2 + a[p--]) <= 3 * k && p >= 0)
;
while (q <= p) {
... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long int tc;
cin >> tc;
while (tc--) {
long long int n;
cin >> n;
set<long long int> s;
long long int flag = 0;
long long int v[n];
for (long long int i = 0; i < n; i... | 8 |
#include <bits/stdc++.h>
const int MAXN = 1e5 + 5;
int l[MAXN], r[MAXN];
double p[MAXN];
using namespace std;
int main() {
int n, P;
cin >> n >> P;
double ans = 0;
for (int i = 0; i < n; ++i) {
cin >> l[i] >> r[i];
p[i] = (r[i] / P - (l[i] - 1) / P) / (double)(r[i] - l[i] + 1);
ans += 2 * p[i];
}
... | 9 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int N = 1e5 + 5, LG = 18;
const double pi = acos(-1);
const long long mod = 1e9 + 7;
const int root = 31;
mt19937_64 rnd(239);
long long power(long long x, unsigned long long y, long long p) {
long long res = 1;
x %= p;
while (y) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2000;
const long long duzo = 1000000001;
long long n, d[N + 10][N + 10], dist[N + 10];
bool in[N + 10], vis[N + 10];
struct Edges {
long long to;
long long w;
};
struct VERT {
long long from;
long long w;
};
VERT vert[N + 10];
vector<Edges> edges[N + 1... | 11 |
#include <bits/stdc++.h>
using namespace std;
bool isNumber(string s) {
for (int i = 0; i < s.length(); i++)
if (isdigit(s[i]) == false) return false;
return true;
}
int main() {
int n;
cin >> n;
vector<int> res;
vector<string> temp = {"ABSINTH", "BEER", "BRANDY", "CHAMPAGNE",
... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename V>
inline void bugp(const pair<T, V> &x) {
cerr << '{' << x.first << ", " << x.second << "}\n";
}
template <typename T, typename U, typename V>
inline void bugpp(const pair<T, pair<U, V> > &x) {
cerr << '{' << x.first << ", {" << x.second.... | 12 |
#include <bits/stdc++.h>
using namespace std;
inline double sqr(double x) { return x * x; }
inline double dist(double x1, double y1, double x2, double y2) {
return sqrt(sqr(x1 - x2) + sqr(y1 - y2));
}
int main(int argc, char **argv) {
int T;
cin >> T;
while (T--) {
long long X[3][2], Y[3][2];
for (int i... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, m, p, a[N], b[N];
vector<int> v;
int main() {
scanf("%d%d%d", &n, &m, &p);
for (int i = 0; i < n; ++i) scanf("%d", a + i);
for (int i = 0; i < m; ++i) scanf("%d", b + i);
for (int i = 0; i < p && i + (m - 1LL) * p < n; ++i) {
int q =... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string str;
cin >> str;
int cur = 0;
int max = 0;
for (int i = 0; i < n; i++) {
if (str[i] == '[') {
cur++;
if (cur > max) {
max = cur;
}
} else {
cur--;
}
}
int* folded = new int[n]... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010, MOD = 999119999;
struct edge {
int u, v, w;
edge() {}
edge(int x, int y, int z) : u(x), v(y), w(z) {}
};
edge E[MAXN];
list<pair<int, int> > adj1[MAXN], adj2[MAXN];
long long Ds[MAXN], Dt[MAXN];
int Cs[MAXN], Ct[MAXN], N, M, s, t;
void dijkstr... | 14 |
#include <bits/stdc++.h>
using namespace std;
int a[100001];
int main() {
int n, i, j, x;
cin >> n;
for (i = 1; i <= n; i++) {
j = min(i - 1, n - i);
cin >> x;
x = x - j;
if (x > 0) a[x]++;
}
for (j = 0, i = 1; i <= 100000; i++) j = max(j, a[i]);
cout << n - j << endl;
return 0;
}
| 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
int n, x, y;
while (cin >> n) {
vector<pair<int, int> > vec, t1, t2;
int s1 = 0, s2 = 0;
for (int i = 0; i < n; i++) {
cin >> x;
vec.push_back(make_pair(x, i + 1));
}
sort(vec.begin(), vec.end(... | 7 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const long long N = 3e5;
long long arr[26], n, pref[N], ans;
string a;
int main() {
ios_base::sync_with_stdio(0), cin.t... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
struct dat {
int d, m1, m2, m12, m21, ans;
dat(char ch = 0) {
if (ch != '(' && ch != ')') return;
d = ch == '(' ? 1 : -1;
m1 = d, m2 = -d * 2, m12 = m21 = -d, ans = 0;
}
dat operator+(dat y) {
dat res;
res.d = d + y.d;
... | 19 |
#include <bits/stdc++.h>
using i64 = long long;
struct node {
int ans;
i64 adv;
node(int ans = -1, i64 adv = 0) : ans(ans), adv(adv) {}
node operator+(const node b) const { return node(ans + b.ans, adv + b.adv); }
node operator+() const { return node(ans + (adv > 0)); }
bool operator<(const node b) const {
... | 17 |
#include <bits/stdc++.h>
const int inf = 0x3f3f3f3f;
const int N = 100005;
const int P = 1000000007;
using namespace std;
int n, m;
vector<pair<int, int> > g[N], cl(N);
bool vis[N];
int al[N];
int f[N][2][2], dp[N][2];
int st;
bool cy;
bool calc(int c, int x, bool ax, int y = -1, bool ay = 0) {
if (y == -1) {
if ... | 21 |
#include <bits/stdc++.h>
using namespace std;
struct Tpoint {
double x, y;
Tpoint() {}
Tpoint(double _x, double _y) {
x = _x;
y = _y;
}
inline void read() { scanf("%lf%lf", &x, &y); }
inline void show() { printf("%lf %lf\n", x, y); }
inline double norm() { return sqrt(((x) * (x)) + ((y) * (y))); }... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int OO = (int)1e8;
int main() {
int x;
vector<int> v;
while (scanf("%d,", &x) != -1) {
v.push_back(x);
}
sort(v.begin(), v.end());
v.push_back(10000);
vector<pair<int, int> > res;
pair<int, int> p;
bool f = 1;
int prv = -1;
for (int i = 0; i ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7, N = 7;
int n, a;
set<int> cur, have, last;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
scanf("%d", &a);
cur.clear();
cur.insert(a);
for (auto it : last) {
cur.insert(it | a);
}
for (auto it : cur) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
#define infinite 9123456789
#define PRECISION cout.precision(3); cout.setf(ios::fixed);
#define db cout << "Debug" << "\n";
#define ler_entrada freopen("test_input.txt", "r", stdin);
int n, q, k, a[1... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
const long double PI = 3.14159265;
long long int powerWithMod(long long int base, long long int exponent,
long long int modulus = LLONG_MAX) {
long long int result = 1;
base %= modulus;
while (exponent > 0)... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 200100;
int a[MAX];
int main() {
int n, k, a, prev = 0, j = 1;
long long ans;
scanf("%d%d", &n, &k);
for (int i = 1; i < n; i++) {
scanf("%d", &a);
if (i > 1) {
ans = prev - (1LL * (n - i) * a * j);
if (ans < k)
printf("%d... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 5;
long long dp[MAXN];
struct line {
long long m, b;
long long eval(long long x) { return m * x + b; }
long long div(long long a, long long b) {
return a / b - ((a ^ b) < 0 && a % b);
}
double isect(const line &o) {
return ((double)(... | 16 |
#include <bits/stdc++.h>
using namespace std;
int egcd(int a, int b, int &x, int &y) {
if (b == 0) {
x = 1, y = 0;
return a;
}
int c = egcd(b, a % b, x, y);
int d = x;
x = y;
y = d - a / b * x;
return c;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int cb[1][1];
void Combination(int l... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x1, x2, x3, y1, y2, y3;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
if (x1 == x2 && x2 == x3)
cout << "1";
else if (y1 == y2 && y2 == y3)
cout << "1";
else if (x1 == x2 || x2 == x3 || y1 == y2 || y2 == y3 || x1 == x3 ||
y1 == y3) {... | 9 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void in(T &x) {
T c = getchar();
while (((c < 48) || (c > 57)) && (c != '-')) c = getchar();
bool neg = false;
if (c == '-') neg = true;
x = 0;
for (; c < 48 || c > 57; c = getchar())
;
for (; c > 47 && c < 58; c = getchar()) x = (x *... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 5;
char s[N];
int main() {
int t, n;
long long a, b;
scanf("%d", &t);
while (t--) {
scanf("%d%lld%lld%s", &n, &a, &b, s);
int slen = strlen(s);
long long ans = a * n;
for (int i = 0, j = 0; i < slen; i ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
char arr[N], sub[N];
int n, m;
vector<bool> ante(10);
void print(string &str) {
for (int i = 0; i < (int)str.size(); i++) str[i] += '0';
printf("%s\n", str.c_str());
exit(0);
}
string parse(vector<int> freq) {
string str;
for (int i = 0; i <... | 15 |
#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... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long int ceil1(long long int n, long long int m) {
if (n % m == 0) {
return n / m;
}
return n / m + 1;
}
vector<long long int> factor(long long int n) {
vector<long long int> ans;
if (n > 0) ans.push_back(1);
if (n == 2) ans.push_back(2);
for (long lo... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.141592653589793238L;
void init() {
cin.tie(0);
cin.sync_with_stdio(0);
}
const int N = 1e5 + 9, M = 15, OO = 0x3f3f3f3f;
const long long llOO = 0x3f3f3f3f3f3f3f3f;
int main() {
init();
int n;
cin >> n;
int len = floor(log10(n)) + 1;
in... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long bin_pow(long long a, long long b) {
if (b == 0) return 1;
if (b % 2 == 0) {
long long t = bin_pow(a, b / 2);
return t * t % 1000000007;
} else
return a * bin_pow(a, b - 1) % 1000000007;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string word;
int N;
cin >> N >> word;
int I = N - 1;
for (int i = 0; i < N - 1; i++) {
if (word[i] > word[i + 1]) {
I = i;
break;
}
}
cout << word.substr(0, I) << word.sub... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long f[250002];
int main() {
long long n, m, i, s = 0;
cin >> n >> m;
f[0] = 1;
for (i = 1; i <= n; i++) f[i] = (f[i - 1] * i) % m;
for (i = 0; i < n; i++)
s = (s +
(((f[i + 1] * (n - i)) % m) * ((f[n - i - 1] * (n - i)) % m)) % m) %
m;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int z, now, ci, n, x, sum, w1, w2, a[maxn], b[maxn];
bool isprime(int k) {
if (k <= 1) return false;
for (int i = 2; i <= sqrt(k); i++)
if (k % i == 0) return false;
return true;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n;... | 4 |
#include <bits/stdc++.h>
using namespace std;
int a, b, m, mx, ans[100010], id[1010][1010];
int linkx[1010][1010], linky[1010][1010];
void dfs(int x, int u, int v, int t) {
int tmp;
if (!t) {
tmp = linkx[x][u];
if (tmp != -1) {
dfs(tmp, v, u, t ^ 1);
linky[tmp][v] = x;
}
linkx[x][v] = tm... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 3000 + 10;
vector<int> edges[MAX_N];
int dist[MAX_N][MAX_N];
int s[2], t[2], l[2];
int n, m;
void bfs(int x, int *d) {
queue<int> Q;
d[x] = 0;
Q.push(x);
while (!Q.empty()) {
int cur = Q.front();
Q.pop();
for (int u = 0; u < edges[cur].... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int y = 1;
cin >> n;
int arr[1000];
if (n % 2 != 0) {
cout << "-1" << endl;
} else {
for (int i = 0; i <= n; ++i) {
arr[i] = y;
y++;
}
for (int i = 0; i < n; ++i) {
swap(arr[i], arr[i + 1]);
i++;
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
string s;
void init() { cin >> s; }
void process() {
char p = s.back();
s.pop_back();
long long n;
stringstream ss;
ss << s;
ss >> n;
long long res = 0;
switch (p) {
case 'f':
res = 1;
break;
case 'e':
res = 2;
break;
case... | 4 |
#include <bits/stdc++.h>
using namespace std;
int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch - '0' < 0 || ch - '0' > 9) {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch - '0' >= 0 && ch - '0' <= 9) {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
int n, K;
int ... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
vector<long long> p;
int ho, mi, se, ho1, mi1;
void fix_time() {
if (se > 59) mi += se / 60, se = se % 60;
if (se < 0) se += 60, mi--;
if (mi > 59) ho += mi / 60, mi = mi % 60;
if (mi < 0) mi += 60, ho--;
if (ho < 0) ho += 24;
if (ho > 2... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
long long res = 1;
a %= mod;
for (; b; b >>= 1) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
}
return res;
}
const int N = 101000;
int n, a, b, c, d, m, tot;
long long x, ... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 400000;
struct Queue {
vector<int> st1, st2;
vector<int> mx1, mx2;
Queue() { clear(); }
void clear() {
st1.clear();
st2.clear();
mx1.clear();
mx2.clear();
}
void add(int x) {
int mx = x;
if (!st2.empty()) mx = max(mx, mx2... | 22 |
#include <bits/stdc++.h>
using namespace std;
double ax, ay, bx, by;
double dx, dy;
double v, t;
double vx, vy, wx, wy;
bool check(double x) {
double ddx = dx, ddy = dy;
if (x <= t) {
ddx -= vx * x;
ddy -= vy * x;
} else {
ddx -= vx * t;
ddy -= vy * t;
ddx -= wx * (x - t);
ddy -= wy * (x -... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 500050;
const int inf = 0x3f3f3f3f;
const long long llinf = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
clock_t TIME__START, TIME__END;
void program_end() {}
int n;
struct mono {
int t, d, p, id;
bo... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 300005;
long long d, h[maxn], b[maxn];
int m = 0, n, pre[maxn], dp[maxn];
typedef struct BiT1 {
int t[maxn];
void update(int x, int k) {
for (int i = x; i < maxn; i += (i & (-i))) {
if (dp[k] > dp[t[i]]) {
t[i] = k;
}
}
}
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, m, t;
char str1[9], str2[9], str[20], c;
int main() {
int i, j, k;
scanf("%s", str);
bool tmp = true;
for (i = n = t = 0; str[i]; i++) {
if (str[i] == ':') {
j = i + 1;
break;
}
if (str[i] > 'N') {
puts("0");
return 0;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, y;
cin >> x >> y;
int n;
cin >> n;
int ans = 0;
if (n % 6 == 1) ans = x;
if (n % 6 == 2) ans = y;
if (n % 6 == 3) ans = y - x;
if (n % 6 == 4) ans = -x;
if (n % 6 == 5) ans = -y;
if (n % 6 == 0) ans = x - y;
if (ans < 0) {
whi... | 5 |
#include <bits/stdc++.h>
using namespace std;
bool comp(pair<long long int, long long int> &a,
pair<long long int, long long int> &b) {
return (a.second < b.second);
}
long long int power(long long int n, long long int p) {
if (p == 0)
return 1;
else {
long long int ans = power(n, p / 2) % 10000... | 5 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.