solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
while (cin >> s) {
int flag = 1;
for (int i = 0; i < 7; i++) {
if (s[i] == s[i + 1]) flag = 0;
}
for (int i = 0; i < 7; i++) {
cin >> s;
for (int j = 0; j < 7; j++) {
if (s[j] == s[j + 1]) flag = 0;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, K, d1, d2, m, A[210000], B[210000], w[210000];
void add(int *A, int k1, int k2) {
for (; k1 <= n; k1 += k1 & (-k1)) A[k1] += k2;
}
int find(int *A, int k1) {
int ans = 0;
for (; k1; k1 -= k1 & (-k1)) ans += A[k1];
return ans;
}
int main() {
scanf("%d%d%d%d%... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int flag = 0;
for (int i = 0; i < s.length(); i++) {
if (s[i] == 'H' || s[i] == 'Q' || s[i] == '9') {
cout << "YES" << endl;
flag = 1;
break;
}
}
if (flag == 0) cout << "NO" << endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
template <typename T_vector>
void output_vector(std::vector<T_vector>& v) {
for (int i = 0; i < v.size(); i++)
std::cout << v[i] << (i == v.size() - 1 ? '\n' : ' ');
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, Q;
cin >> N >> Q;
vecto... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
int n, m, q;
cin >> n >> m >> q;
vector<vector<int> > moves(q, vector<int>(4));
for (int i = 0; i < q; ++i) {
cin >> moves[i][0];
cin >> moves[i][1];
moves[i][1]--;
if (moves[i][0] == 3) {
cin >> mov... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 10;
int n, m;
char s[N][N];
const char sb[4][3][4] = {{"###", ".#.", ".#."},
{"..#", "###", "..#"},
{".#.", ".#.", "###"},
{"#..", "###", "#.."}};
char a88[10][10] = {"AAA.BCCC", ".A... | 15 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
using namespace std;
const int N = (1e6);
const int MAX = 7 * (1e7);
const int MOD = (1e9) + 1;
const long long INF = (1e17) + 789;
const double pi = acos(0.0);
long long a[N], t[4 * N], p[4 * N], sum[4 ... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int m, n;
cin >> m >> n;
cout << m + n - 1 << '\n';
for (int i = 1; i <= n; ++i) {
cout << 1 << ' ' << i << '\n';
}
for (int i = 2; i <= m; ++i) {
cout << i << ' ' << 1 << '\n';
}
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 2e3 + 10, M = 10001;
int n, k;
long long a[N], dp[N];
bool check(long long x) {
bool ans = 0;
for (int i = 0; i < n; i++) dp[i] = i;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (abs(a[j] - a[i]) <= x * (j - i))
... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)1e3 + 7;
const int INF = (int)0x3f3f3f3f;
int N, M;
int A[MAXN];
int Num[MAXN];
int cnt = 0;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> N >> M;
for (int i = (int)1; i <= (int)M; i++) {
cin >> A[i];
Num[A... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000 + 5;
const int inf = 1e9 + 5;
int n, k;
int a[N], b[N];
int dp[N * N];
int main() {
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> a[i];
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; i++) b[i] = a[i] - a[1];
for (int i = 0; i < N * N; i++)... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, i;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
int arr[n];
for (i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
int left = 0, right = n - 1, flag = 0;
long long int lsum = 0, rsum = 0, c = 0, sum1 = 0, sum2... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 4010;
const int P = 1000000007;
int h[N], nx[N << 2], t[N << 2], num;
int cnt[N];
int n, m;
int s;
int Ans;
int tot;
int f[N][N];
bool vis[N];
void Add(int x, int y) {
t[++num] = y;
nx[num] = h[x];
h[x] = num;
}
void Dfs(int x) {
vis[x] = 1;
s++;
f... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
struct EdmondsKarp {
int size;
vector<vector<int> > adj, cap;
vector<bool> vis;
vector<int> p;
EdmondsKarp(int _size) {
size = _size;
adj.assign(size, vector<int>());
cap.assign(size, vector<int>());
for (int i = 0; i < size; i... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
inline int in() {
int x;
scanf("%d", &x);
return x;
}
inline long long lin() {
long long x;
scanf("%I64d", &x);
return x;
}
map<string, int> mymap;
int n, m, q;
int par[N];
int _find(int r) {
if (par[r] == r)
return r;
else {
re... | 12 |
#include <bits/stdc++.h>
using namespace std;
int str(string s) {
if (s == "monday") return 1;
if (s == "tuesday") return 2;
if (s == "wednesday") return 3;
if (s == "thursday") return 4;
if (s == "friday") return 5;
if (s == "saturday") return 6;
if (s == "sunday") return 7;
return 0;
}
int main() {
... | 2 |
#include <bits/stdc++.h>
const int M = 108;
const int oo = 1e9 + 7;
using namespace std;
int t, n, m, k;
char a[M][M], f[M][M];
string BASE = "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm0123456789";
int main(int argc, char const *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> t;
whil... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, i, j, sum = 0, ans, sum1;
cin >> n;
vector<int> v;
for (i = 0; i < n; i++) {
cin >> j;
v.push_back(j);
sum = sum + j;
}
sort(v.begin(), v.end());
ans = sum;
sum1 = 0;
for (i = 0; i < n - 1; i++) {
ans = ans + v... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d, m, ans, x, y, dx, dy, e, w[1000000];
int i;
void gcd(long long o, long long p) {
if (p == 0) {
x = 1;
y = 0;
return;
} else {
gcd(p, o % p);
long long xx = y, yy = x - o / p * y;
x = xx, y = yy;
}
}
int main() {
ios::syn... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000 * 1000;
int lens[N];
int k;
long long solve(long long a, long long b) {
k = 0;
for (long long i = 1; i * i <= b; ++i)
if (b % i == 0) lens[k++] = i;
long long ans = 2 * (a + b) + 2;
long long x = a + b;
int l = 0;
for (long long i = 1; i *... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
sort(arr, arr + n);
for (int i = 0; i < n; i++) {
cout << arr[i] << " ";
}
cout << endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int MD = 1000000007, maxn = 500 + 5;
int n, m, q, rk, roe[maxn];
long long ans;
char a[maxn][maxn << 1], s[maxn];
void swap(char* a, char* b) {
char t = *a;
*a = *b;
*b = t;
}
int gauss() {
int r = -1;
for (int i = 0; i < n; i++) {
int j = r + 1;
whi... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int month[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
long long y, m, d, a, b, c;
bool leap(int v) { return ((v % 400 == 0) || (v % 4 == 0 && v % 100 != 0)); }
int getday(int yy, int mm, int dd) {
int ans = 0;
for (int v = 1900; v < yy; v++) ans += ... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long rem = (1e9) + (1e5) + 1;
long long a[100100], b[100100], m, n, w, i, l, r;
long long ans(long long x) {
long long s = 0;
long long u = 0, y;
memset(b, 0, sizeof b);
for (long long j = 0; j < n; j++) {
b[j] = s;
if (j - w >= 0) b[j] -= b[j - w];
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int ret[20000];
int main() {
int a;
ret[1] = 1;
ret[2] = 13;
for (int i = 3; i <= 18257; i++) ret[i] = ret[i - 1] + 6 * ((i - 1) * 2);
scanf("%d", &a);
printf("%d\n", ret[a]);
return 0;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
ifstream in;
ofstream out;
const long long INF = LLONG_MAX;
const long double EPS = 1e-9;
const long double pi = 3.141592653589793238462643383279502884;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout.precision(20);
srand(time(0));
long ... | 2 |
#include <bits/stdc++.h>
using namespace std;
vector<int> Adj[100005];
int main() {
int n, i, j, u, v, m, ans = -1;
set<pair<int, int> > ss;
scanf("%d %d", &n, &m);
for (i = 0; i < m; ++i) {
scanf("%d %d", &u, &v);
Adj[u].push_back(v);
Adj[v].push_back(u);
ss.insert(make_pair(u, v));
ss.inse... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
long long INF = 1e18;
void solve() {
int n, k, l, r, diff, minsz, start;
cin >> n >> k;
int arr[n];
for (int i = 0; i < n; i++) cin >> arr[i];
if (k == 1) {
cout << "1 1";
return;
}
unordered_map<int, int> mp;
diff = 1;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
long long int ans = a[n - 1];
int x = a[n - 1];
for (int i = n - 2; i >= 0; i--) {
if (x - 1 < 0) {
x = 1;
}
ans += (min(x - 1, a[i]));
x = min(x -... | 2 |
#include <bits/stdc++.h>
const double pi = acos(-1.0);
const int maxn = (1e5 + 10);
const int inf = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
using namespace std;
int ans[maxn];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int a, b, c, d;
cin >> a >> b >> c >> d;
int sum0 = a, sum1 = b, sum2 = c, su... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, k, t1, t2, t3, t4, n;
int a, b, ax, bx;
a = 0;
ax = 0;
b = 0;
bx = 0;
scanf("%d", &n);
for (i = 0; i != n; ++i) {
scanf("%d%d%d", &j, &k, &t1);
if (j == 1) {
++a;
ax += k;
} else {
++b;
bx += k;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
ios_base::sync_with_stdio(0);
int n, m;
cin >> n >> m;
vector<int> xs(n + 1);
for (int i = 1; i <= n; i++) cin >> xs[i];
int ans = 0;
for (int i = 0, a, b; i < m; i++) {
cin >> a >> b;
ans += min(xs[a], xs[b]);
}
cout << ans << end... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int Mod = 1e9 + 7;
int maxw;
inline int upd(int x) { return x + (x >> 31 & Mod); }
inline void add(int &x, int y) { x = upd(x + y - Mod); }
inline void iadd(int &x, int y) { x = upd(x - y); }
char s[510];
int len;
int n, m;
int a[20], b[20], c[20], d[20], e[20];
int L... | 22 |
#include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
long long n;
scanf("%lld",&n);
long long ans = 0;
for(long long i = 0;i<=32;i++){
if(((n>>i)&1)==1){
ans = max(ans,i);
}
}
printf("%lld... | 0 |
#include <bits/stdc++.h>
using namespace std;
map<int, int> mx;
map<int, int> my;
map<pair<int, int>, int> mp;
int main() {
int n, x, y;
scanf("%d", &n);
while (n--) {
scanf("%d", &x), scanf("%d", &y);
mx[x]++, my[y]++;
mp[pair<int, int>(x, y)]++;
}
long long ans = 0;
int temp;
map<int, int>::... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[6];
int i, j, k, sum = 0, s;
for (i = 0; i < 6; i++) {
cin >> a[i];
sum += a[i];
}
for (i = 0; i < 6; i++)
for (j = i + 1; j < 6; j++)
for (k = j + 1; k < 6; k++) {
s = a[i] + a[j] + a[k];
if (s == sum - s) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
inline void printArr(const int* a, int n) {
cout << a[0];
for(int i = 1; i < n; i++) {
cout << " " << a[i];
}
cout << '\n';
}
void solve1(const int* q, int n) {
bool vis[n];
memset(vis, false, sizeof vis);
int a[n]; a[0] = q[0];
v... | 7 |
#include <bits/stdc++.h>
using namespace std;
char s1[10005], s2[1000005];
vector<int> f[30];
int main() {
scanf("%s%s", s1, s2);
for (int i = 0; s1[i]; i++) f[s1[i] - 'a'].push_back(i);
int p2 = 0, cnt = 1;
while (1) {
int now = 0;
while (1) {
vector<int>::iterator vit =
lower_bound(f[s... | 7 |
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
using namespace std;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 6;
const int K = 21;
int n, m, x, y;
vector<int> gr[N];
pair<int, int> A[N];
int can[N];
inline void test_case() {
cin >> n >> m;
for (int i = 1; i <= m; i++) {
cin >> x >> y;
gr[x].push_back(y);
gr[y].push_back(x);
}
for (int i = 1; ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const long double eps = 1e-10;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const int MX = 1e6 + 7;
const int mod = 1e9 + 7;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long quimod(lo... | 11 |
#include <bits/stdc++.h>
using namespace std;
int d[1000000 + 5], a[1000000 + 5];
int n;
int lowbit(int x) { return x & (-x); }
void upd(int x, int val) {
while (x <= n) {
d[x] += val;
x += lowbit(x);
}
}
int query(int x) {
int sum = 0;
while (x) {
sum += d[x];
x -= lowbit(x);
}
return sum;
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, k, l, m, n, arr[100005], z, start, end1, sum1, sum2;
while (scanf("%d", &n) != EOF) {
for (i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
start = 0;
end1 = n - 1;
sum1 = 0;
sum2 = 0;
k = 0;
l = 0;
z = 0;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int t, n, c, l, r;
int main() {
for (cin >> t; t--;) {
cin >> n;
c = 1;
for (int i = 1; i <= n; i++) {
cin >> l >> r;
if (l >= c) c = l;
if (r < c && i != 1) {
cout << "0 ";
continue;
} else {
cout << c << " ";
... | 4 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
set<int> vis;
void dfs(vector<vector<int> > &g, int curr, queue<int> &dance) {
dance.push(curr);
vis.insert(curr);
int n0 = g[curr][0];
int n1 = g[curr][1];
if (vis.find(n0) == vis.end() && (g[n0][0] == n1 || g[n0][1] == n1)) {
dfs(g, n0,... | 8 |
#include <bits/stdc++.h>
using namespace std;
int deg[1000001], n, m, x, y;
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; ++i) {
scanf("%d%d", &x, &y);
++deg[x], ++deg[y];
}
long long dec = 0;
for (int i = 1; i <= n; ++i) dec += (long long)deg[i] * (n - 1 - deg[i]);
cout << ((long long... | 11 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > v[500005];
long long k, n, dp[500005][2];
map<long long, long long> ed[500005];
void go(long long x, long long par) {
vector<pair<long long, long long> > g;
for (int i = 0; i < v[x].size(); i++) {
if (v[x][i].first != par) {
... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
long long num = 0;
while (n != 0) {
if (n >= 100) {
n -= 100;
num++;
} else if (n >= 20) {
n -= 20;
num++;
} else if (n >= 10) {
n -= 10;
num++;
} else if (n >= 5) {
n -= 5... | 0 |
#include <bits/stdc++.h>
using namespace std;
int e[100000], c[100000], d[100000], other[100001];
int inv(long long int n) {
long long int r = 1;
int e = 998244353 - 2;
while (e > 0) {
if (e & 1) r *= n, r %= 998244353;
e >>= 1;
n *= n, n %= 998244353;
}
return r;
}
int invn[200001];
struct query ... | 25 |
#include <bits/stdc++.h>
using namespace std;
const int N = 60;
const int inf = 1e9;
int f[N][N][N][N], g[N][N], s, p[N], n, m, tmp[N], ans;
vector<int> v[N];
inline void Max(int &x, int y) {
if (y > x) x = y;
}
void dfs1(int x, int fa) {
int t;
if (fa) {
for (int i = 0; i <= s; i++) f[fa][x][s][i] = 0;
f... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;
int n, m, a[2000];
vector<vector<int> > e;
int main() {
cin >> n >> m;
vector<pair<int, int> > v;
for (int i = 0; i < (int)n; i++) {
cin >> a[i];
v.push_back(make_pair(-a[i], i));
}
sort((v).be... | 6 |
#include <bits/stdc++.h>
using namespace std;
struct xyi {
int first;
int second;
long long value;
};
int step[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
bool used[255][255];
char g[255][255];
long long ans[255][255];
vector<pair<int, int> > v;
int main() {
int n, m, q, p;
cin >> n >> m >> q >> p;
for (int... | 11 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int a, b, c;
cin >> a >> b >> c;
int res = a + 2 * b + 3 * c;
if (res % 2 == 0) {
cout << 0 << endl;
} else {
cout << 1 << endl;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
cin >> ... | 0 |
#include <bits/stdc++.h>
int main() {
int n;
int s = 0;
int curs = 0;
int k = 0;
int a[105], b[105];
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
s += a[i];
}
for (int i = 0; i < n; i++) {
if (a[0] >= 2 * a[i] || i == 0) {
curs += a[i];
b[k] = i + 1;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int h[n];
for (int l = 0; l < n; l++) cin >> h[l];
int x = h[0] + 1;
int f;
for (int i = 1; i < n; i++) {
if (h[i] == h[i - 1]) {
x = x + 2;
} else if (h[i - 1] > h[i]) {
f = h[i - 1] - h[i];
x = x + 2 + ... | 2 |
#include <bits/stdc++.h>
using namespace std;
void _print(long long t) { cerr << t; }
void _print(int t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(long double t) { cerr << t; }
void _print(double t) { cerr << t; }
void _print(unsigned long long t) { cerr << t; }
... | 5 |
#include <bits/stdc++.h>
const int NUM = 100010;
const double EPS = 1e-10, PI = acos(-1.0);
using namespace std;
long long c, hr, hb, wr, wb;
int main() {
int i, j;
scanf("%I64d%I64d%I64d%I64d%I64d", &c, &hr, &hb, &wr, &wb);
long long sc = sqrt(1.0 * c) + 1;
long long x, y;
long long ans = 0;
if (wr >= sc) ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
int count(int arr[6]) {
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (arr[i] > arr[j]) ans++;
}
}
return ans;
}
int dfs(int z, int arr[6]) {
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i;... | 10 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:268435456")
void _print(long long t) { cerr << t; }
void _print(int t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(long double t) { cerr << t; }
void _print(double t) { cerr << t; }
void ... | 11 |
#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
cerr.write(nam... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1000 * 100 * 5 + 20;
long long dp[maxN];
int a[maxN];
int main() {
int n;
cin >> n;
long long sum = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
sum += a[i];
}
if (sum % 3 != 0) {
cout << "0";
return 0;
}
sum /= 3;
int nu... | 9 |
#include <bits/stdc++.h>
template <typename T>
bool domax(T &a, T b) {
return (b > a ? (a = b, true) : false);
}
template <typename T>
bool domin(T &a, T b) {
return (b < a ? (a = b, true) : false);
}
const int maxn = 100 * 1000 + 5;
int n;
long long k, a[maxn], b[maxn];
bool f(long long t) {
long long x = k;
f... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long n, ans;
string str;
long long solve() {
long long c;
cin >> n >> c;
long long x[n];
for (long long i = 0; i <= n - 1; ++i) cin >> x[i];
for (long long i = 0; i <= n - 2; ++i) {
ans = max(ans, x[i] - x[i + 1] - c);
}
cout << ans;
return 0;
}
sig... | 2 |
#include <bits/stdc++.h>
using namespace std;
vector<int> v = {4, 1, 3, 2, 0, 5};
int b[7];
int a[7];
int main() {
int n;
cin >> n;
for (int i = 0; i < 6; ++i) {
if (n & (1 << i)) {
b[i] = 1;
}
}
for (int i = 0; i < 6; ++i) {
a[v[i]] = b[i];
}
int ans = 0;
for (int i = 0; i < 6; ++i) {... | 11 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const long double eps = 1e-7;
const int inf = 1000000010;
const long long INF = 1000000000000001000LL;
const int mod = 1000000007;
const int MAXN = 110, LOG = 20;
long long n, m, k, u, v, x, y, t, a, b, ans;
int A[MAXN * 2];
int mn[MAXN * 2];
i... | 15 |
#include <bits/stdc++.h>
using namespace std;
int iv1() {
int x = 0, c = getchar();
for (; c < 48 || c > 57; c = getchar())
if (c < 0) return 0;
for (; c >= 48; c = getchar()) x = x * 10 + c - 48;
return x;
}
int s[30 * 300007 + 1][2], a[300007];
int tt, nr;
int dfs(int &x, int dx, int t) {
int ret;
if ... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9 + 7, maxn = 3e5 + 100, mod = 998244353;
long long f[maxn], d[maxn], c[maxn];
long long mood(long long x) {
x %= mod;
x = (x + mod) % mod;
return x;
}
bool comp(pair<long long, long long> a, pair<long long, long long> b) {
return (a.first < ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
priority_queue<int> m1, m2;
int n, m, a, min = 0, max = 0;
cin >> n >> m;
for (int i = 1; i <= m; i++) {
cin >> a;
m1.push(a);
m2.push(-a);
}
for (int i = 1; i <= n; i++) {
int q = m1.top();
max += q;
m1.pop();
if (q - 1)... | 3 |
#include <bits/stdc++.h>
using namespace std;
bool DEBUG = 0;
long long n, m;
vector<long long> p(200005);
vector<long long> adj[400005];
long long n_lca, l_lca;
int timer;
vector<int> tin, tout;
vector<vector<int> > up;
void dfs(int node, int par) {
tin[node] = timer++;
up[node][0] = par;
for (int i = 1; i <= l_... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a;
long long b;
cin >> a >> b;
if (a == 0 and b == 0) {
cout << "NO";
return 0;
}
if (abs(a - b) <= 1) {
cout << "YES";
return 0;
}
cout << "NO";
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int a, b, c, d;
cin >> a >> b >> c >> d;
cout << a << " " << c << " " << c << "\n";
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
inline int read(int f = 1, int x = 0, char ch = ' ') {
while (!isdigit(ch = getchar()))
if (ch == '-') f = -1;
while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
return f * x;
}
const int N = 1 << 10 | 5;
int n0, m0, q, s[N][N], lg[N * N << 1];
char bit[N]... | 17 |
#include <bits/stdc++.h>
int power(int x, int y) {
int res = 1;
x = x % 1000000007;
while (y > 0) {
if (y & 1) res = (res * x) % 1000000007;
y = y >> 1;
x = (x * x) % 1000000007;
}
return res;
}
int ncr(int n, int r) {
int res = 1;
if (r > n - r) r = n - r;
for (int i = 0; i < r; i++) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, cnt = 0;
cin >> n;
int a = 1, x;
for (int i = 1; i <= n; i++) {
cnt += a;
if (i == n) x = a;
a += 2;
}
cout << cnt * 2 - x << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-11;
template <class T>
inline void checkmin(T &a, T b) {
if (b < a) a = b;
}
template <class T>
inline void checkmax(T &a, T b) {
if (b > a) a = b;
}
template <class T>
inline T sqr(T x) {
return x * x;
}
const int m... | 17 |
#include <bits/stdc++.h>
using namespace std;
unsigned long long mod = 1e9 + 7;
unsigned long long ncr(long long n, long long k) {
unsigned long long res = 1;
if (k > n - k) k = n - k;
for (long long i = 0; i < k; ++i) {
res *= (n - i);
res /= (i + 1);
res = res;
}
return res;
}
bool prime(unsigne... | 8 |
#include <bits/stdc++.h>
using namespace std;
string tostr(long long x) {
stringstream ss;
ss << x;
return ss.str();
}
long long toint(const string &s) {
stringstream ss;
ss << s;
long long x;
ss >> x;
return x;
}
int main() {
int n, x, l, r, t1, t2;
scanf("%d", &n);
;
scanf("%d", &x);
;
sca... | 2 |
#include <bits/stdc++.h>
const int N = 1005;
const std::pair<int, int> d[8] = {{1, 2}, {1, -2}, {-1, 2}, {-1, -2},
{2, 1}, {2, -1}, {-2, 1}, {-2, -1}};
int n, m;
std::pair<int, int> start[2], end[2];
std::pair<int, int> operator+(std::pair<int, int> a, std::pair<int, int> b) {
return... | 21 |
#include <bits/stdc++.h>
using namespace std;
int **a, **ans, **indegree, n, m, i, j;
vector<pair<int, int>>** e;
pair<int, int>** root;
deque<pair<int, int>> q;
set<pair<int, int>> s;
template <class T>
inline void allc(T**& p) {
T* tmp = new T[n * m]{};
p = new T*[n];
for (int i = 0; i < n; ++i) p[i] = tmp + i ... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int m;
cin >> m;
int a[m];
int overall = 0;
for (int i = 0; i < m; i++) {
cin >> a[i];
overall += a[i];
}
int x, y;
cin >> x >> y;
int sum = 0;
int ans;
int found = 0;
for (int i = 0; i < m; i++) {
sum += a[i];
if (sum >=... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int OO = 1000000000;
int b0, b1;
int zs, os;
int l;
string sub1(string s) {
int in = s.size() - 1;
while (s[in] == '0') s[in--] = '1';
s[in] = '0';
if (in == 0) s = s.substr(1);
return s;
}
const int N = 200001;
int fact[N];
int i... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int q, n;
vector<int> a(10010);
cin >> q;
while (q--) {
cin >> n;
for (int i = 0; i < 10010; i++) a[i] = 0;
for (int i = 0; i < 4 * n; i++) {
int v;
cin >> v;
a[v]++;
}
bool ok = true;
for (int i = 0; i < 10010;... | 4 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
double eps = 1e-8;
const int MAXN = 201000;
const double inf = 1e12;
int n, m, cCnt, curCnt;
struct vec {
double x, y;
int index;
vec() { x = y = 0; }
vec(double _x, double _y) {
x = _x;
y = _y;
}
vec... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
int n, i, j, l, flag;
cin >> n;
string s[n + 1], r;
for (i = 0; i < n; i++) {
cin >> s[i];
}
for (i = n - 2; i >= 0; i--) {
r = "";
flag = 0;
l = min(s[i].size(), s[i + 1].size());
for (j =... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
struct fastio {
char s[100000];
int it, len;
fastio() { it = len = 0; }
inline char get() {
if (it < len) return s[it++];
it = 0;
len = fread(s, 1, 100000, stdin);
if (len == 0)
return EOF;
else
return s[it++]... | 24 |
#include <bits/stdc++.h>
int main() {
int n;
scanf("%d", &n);
int maxx = 0, maxy = 0;
static char type;
for (int i = 0; i < n; i++) {
int x = 0, y = 0;
scanf(" %c%d%d", &type, &x, &y);
if (x < y) {
int tmp = x;
x = y;
y = tmp;
}
if (type == '+') {
if (x > maxx) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
string pst;
int ind;
long long solve() {
if (isdigit(pst[ind])) return pst[ind--] - '0';
if (pst[ind] == '+') {
ind--;
return solve() + solve();
}
ind--;
return solve() * solve();
}
string tmp;
void post() {
stack<char> s;
for (int i = 0; i < tmp.size(... | 13 |
#include <bits/stdc++.h>
using namespace std;
template <class _T>
inline void read(_T &_x) {
int _t;
bool _flag = false;
while ((_t = getchar()) != '-' && (_t < '0' || _t > '9'))
;
if (_t == '-') _flag = true, _t = getchar();
_x = _t - '0';
while ((_t = getchar()) >= '0' && _t <= '9') _x = _x * 10 + _t ... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 4002;
const int INFTY = 1 << 30;
int N;
int A[MAXN];
int pre[MAXN];
int dp[MAXN][100][100];
int getdp(int left, int dif, int k) {
if (dp[left][dif][k] != -INFTY) return dp[left][dif][k];
int right = N - left + 1 - dif;
if (left + k - 1 <= right) {
... | 17 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 16769023;
long long POW(long long a, long long b, long long MMM = MOD) {
long long ret = 1;
for (; b; b >>= 1, a = (a * a) % MMM)
if (b & 1) ret = (ret * a) % MMM;
return ret;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % ... | 14 |
#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
std::ios::sync_with_stdio(false);
cin >> s;
long long ans = 0, sumi = 0, i;
for (i = s.length() - 1; i >= 0; i--) {
if (s[i] == 'b') {
sumi++;
} else {
ans += sumi;
ans %= (1000 * 1000 * 1000 + 7);
sumi *= 2;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int x[200001], ans[200001], s[200001], rk[200001];
bool cmp(int i, int j) { return x[i] < x[j]; }
int lb(int k) { return k & -k; }
int _get(int k) {
if (k == 0) return 0;
return s[k] + _get(k ^ lb(k));
}
void _set(int k) {
if (k >= 200001) return;
s[k]++;
_set(k +... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int ans[12] = {0};
string s[12] = {"C", "C#", "D", "D#", "E", "F",
"F#", "G", "G#", "A", "B", "H"};
string a, b, c;
cin >> a >> b >> c;
for (int i = 0; i < 12; i++) {
if (a == s[i] || b == s[i] || c == s[i]) ans[i] = 1;
}
... | 4 |
#include <bits/stdc++.h>
using namespace std;
using ld = long double;
long double dp[101][10001];
int main() {
int n, x;
cin >> n >> x;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
dp[0][0] = 1.0;
for (int i = 0; i < n; ++i) {
for (int j = n - 1; j >= 0; --j) {
for (int k =... | 22 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000 + 10;
const char ENDLINE = '\n';
struct Tree {
struct Edge {
int v, n;
} e[MAXN << 1];
int G[MAXN], edgeCnt;
int vis[MAXN], tim;
void _add_edge(int u, int v) {
if (vis[u] != tim) G[u] = 0, vis[u] = tim;
e[++edgeCnt].n = G[u];
... | 20 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 998244353;
long long dp[1001][2001][4];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, k;
cin >> n >> k;
dp[0][0][0] = 1;
for (long long i = 0; i < n; i++) {
for (long long j = 0; j <= 2 * i; j++) {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
string s[6];
int l[6];
void deal(vector<string>& v, int x, int y, int dx, int dy, string s) {
for (int k = 0; k < s.size(); k++, x += dx, y += dy) v[x][y] = s[k];
}
int main() {
for (int i = 0; i < 6; i++) cin >> s[i];
sort(s, s + 6);
vector<string> res;
res.clear... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
int n, COMP, god[N], d[N], comp[N], nxt[N];
bool mark[N];
vector<int> nei[N], rev_nei[N], comp_nei[N], vec;
vector<pair<int, int> > ans;
void dfs(int u) {
mark[u] = true;
for (int v : nei[u])
if (mark[v] == false) dfs(v);
vec.push_back(u);... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
if (n == 1) {
if (k)
cout << -1 << endl;
else
cout << 1 << endl;
return 0;
}
int x = k - ((n - 2) / 2);
if (x <= 0) {
cout << -1 << endl;
return 0;
}
cout << x;
x *= 2;
cout << " " << ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j;
int a, b, c, n;
while (cin >> n >> a >> b >> c) {
n--;
if (!n) {
cout << 0 << endl;
continue;
}
int sum = 0;
sum += min(a, b);
n--;
sum += min(min(a, b), c) * n;
cout << sum << endl;
}
return 0;
}
| 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.