solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int a[N];
int mx[10 * N], dp[10 * N];
int n, s, t;
int inc(int x) { return x - t; }
int main() {
ios::sync_with_stdio(0);
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
cin >> s >> t;
if (s == t) {
cout << 0 << endl;
return 0;
... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, l = 1;
cin >> t;
while (t--) {
int x, y, z, x1, y1, z1, ans = 0;
cin >> x >> y >> z >> x1 >> y1 >> z1;
ans += min(z, y1) * 2;
z -= min(z, y1);
if (z1 > x + z) ans -= 2 * (z1 - x - z);
cout << ans << endl;
}
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using vc = vector<T>;
using pii = pair<long long, long long>;
void xmax(long long& a, long long b) { a = max(a, b); }
void xmin(long long& a, long long b) { a = min(a, b); }
void print(vc<long long>& a, string second) {
cerr << "prinitng " << second ... | 18 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int neg = 1, num = 0;
char c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-') neg = -1;
for (; isdigit(c); c = getchar()) num = (num << 1) + (num << 3) + c - '0';
return neg * num;
}
int n, T, cnt, d[2000010];
vector<int> g[200... | 23 |
#include <bits/stdc++.h>
using namespace std;
int ck[3], t1, t2;
int main() {
scanf("%d%d%d%d%d", &ck[0], &ck[1], &ck[2], &t1, &t2);
ck[0] %= 12;
t1 %= 12;
t2 %= 12;
ck[0] = ck[0] * 3600 + ck[1] * 60 + ck[2];
ck[1] = (ck[1] * 60 + ck[2]) * 12;
ck[2] = ck[2] * 60 * 12;
t1 = t1 * 3600;
t2 = t2 * 3600;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int inf = std::numeric_limits<int>().max();
inline long long soma(long long x, long long y) {
return (x % 1000000007 + y % 1000000007) % 1000000007;
}
inline long long subtrai(long long x, long long y) {
return ((x % 1000000007 - y % 1000000007) + 1000000007) % 10000000... | 1 |
#include <bits/stdc++.h>
int main() {
long long n, m, nn, j, l;
while (~scanf("%I64d%I64d%I64d", &n, &nn, &m)) {
int lk = 0;
for (l = 1; l <= nn; l = l * m) {
if (l >= n) {
lk = 1;
break;
}
if (l * m <= 0 || l * m % m != 0) break;
}
if (lk == 0)
printf("-1\n")... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
int main() {
int t;
cin >> t;
while (t--) {
long long i, j, n, x, m, diff, req[300005] = {0}, ans[300005] = {0},
ara[300005] = {0};
cin >> n;
for (i = 0; i <= n; i++) {
ans[i] = -1;
}
... | 7 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
using VV = vector<vector<T>>;
template <class T>
inline T SMIN(T& a, const T b) {
return a = (a > b) ? b : a;
}
template <class T>
inline T SMAX(T& a, const T b) {
return a = (a < b) ? b : a;
}
template <class Iter>
void __kumaerrc(Iter begin, Iter en... | 11 |
#include <bits/stdc++.h>
using namespace std;
namespace red {
inline long long read() {
long long x = 0;
char ch, f = 1;
for (ch = getchar(); (ch < '0' || ch > '9') && ch != '-'; ch = getchar())
;
if (ch == '-') f = 0, ch = getchar();
while (ch >= '0' && ch <= '9') {
x = (x << 1) + (x << 3) + ch - '0'... | 23 |
#include <bits/stdc++.h>
using namespace std;
struct ajutor {
int st, dr, nr;
};
bool cmp(ajutor a, ajutor b) {
if (a.st == b.st) return a.dr > b.dr;
return a.st < b.st;
}
const int N = 200005;
int maxdr[18][N];
int maxnr[18][N];
ajutor v[N];
int id[N];
int p2[N];
int cnt;
void makermq() {
p2[1] = 0;
for (int... | 12 |
#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cout << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
cout.write(nam... | 8 |
#include<bits/stdc++.h>
#define ll long long
#define For(i,a,b) for(int i=a;i<b;i++)
#define rFor(i,a,b) for(int i=a;i>=b;i--)
#define mFor(it,m) for(auto it=m.begin(); it!=m.end(); it++)
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
ll n,x,count=0;
cin>>n>>x;
m... | 4 |
#include <bits/stdc++.h>
using namespace std;
char str[100005];
long long int dp[11], nxt[11];
int main() {
scanf("%s", &str);
int n = strlen(str);
memset(dp, 0, sizeof(dp));
long long int ret = 0;
for (int i = 0; i < n; i++) {
int c = str[i] - '0';
memset(nxt, 0, sizeof(nxt));
for (int j = c + 1;... | 20 |
#include <bits/stdc++.h>
using namespace std;
int ara[200005];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> ara[i];
ara[i] = abs(ara[i]);
}
long long ans = 0;
sort(ara, ara + n);
for (long long i = 0; i < n; i++) {
long long r = up... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
char arr[n];
queue<int> d, r;
for (int i = 0; i < n; i++) {
cin >> arr[i];
if (arr[i] == 'D')
d.push(i);
else
r.push(i);
}
while (!d.empty() && !r.empty()) {
if (d.front() > r.front()) {
r.push(r.... | 7 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T gcd(T a, T b) {
return (b != 0 ? gcd<T>(b, a % b) : a);
}
template <class T>
T lcm(T a, T b) {
return (a / gcd<T>(a, b) * b);
}
template <class T>
inline bool read(T &x) {
int c = getchar();
int sgn = 1;
while (~c && c < '0' || c > '9') {
... | 13 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void debug(...) {}
const int maxn = 1000010;
int n, m;
char a[maxn], b[maxn], c[maxn << 1];
int za[maxn], zb[maxn], zc[maxn << 1];
void build(char c[], char a[], int z[], int za[]) {
for (int i = 1, l = 0, r = 0; i <= n + m; ++i) {
z[i] = max(0, ... | 19 |
#include <bits/stdc++.h>
using namespace std;
long long n, K;
long long X[200000], C[200000];
long long A;
set<long long> S;
long long output;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> K;
for (long long i = 0; i < n; i++) cin >> X[i];
cin >> A;
long long key = 0;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200000;
int T1[MAXN + 7];
int T2[MAXN + 7];
int main() {
int n;
scanf("%d", &n);
int a, b;
for (int i = 0; i < n; i++) {
scanf("%d", &T1[i]);
if (T1[i] == 1) a = i;
}
for (int i = 0; i < n; i++) {
scanf("%d", &T2[i]);
if (T2[i] =... | 5 |
#include <bits/stdc++.h>
using namespace std;
char a[10000000], b[10000000];
int x, y;
int main() {
cin >> a;
x = strlen(a);
for (int i = x - 1; i >= 0; i--) {
b[i] = max(b[i + 1], a[i]);
}
for (int i = 0; i <= x - 1; i++) {
if (b[i] == a[i]) {
cout << a[i];
}
}
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int anum, bnum, n, sum = 0, re = 0, a, b;
scanf("%I64d", &n);
while (n--) {
scanf("%I64d %I64d", &a, &b);
while (a && b) {
sum += a / b;
anum = a % b;
a = b;
b = anum;
}
printf("%I64d\n", sum);
sum = 0... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long dist[100001];
bool done[100001];
void dijkstra(long long source, vector<pair<long long, long long> > ed[],
long long v) {
priority_queue<pair<long long, long long>,
vector<pair<long long, long long> >,
greater<pair... | 12 |
#include<bits/stdc++.h>
using namespace std;
const double eps=1e-10;
const int maxn=2e5+5;
struct Point{
double x,y;
Point(double _x=0,double _y=0):x(_x),y(_y) { }
Point operator - (const Point &b) const
{
return Point(x-b.x,y-b.y);
}
double operator ^ (const Point &b) const
{
return x*b.y-y*b.x;
}
dou... | 17 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, k;
long long c[110];
long long p[110][110];
long long dp[110][110][110];
long long solve(long long i, long long j, long long kk) {
if (kk == -1) return 9e18;
if (i == -1) {
if (kk == 0) return 0;
return 9e18;
}
if (dp[i][j][kk] != -1) return ... | 9 |
#include <bits/stdc++.h>
using namespace std;
bool check(long long s) {
for (long long i = 2, _b = sqrt(s); i <= _b; i++)
if (s % i == 0) return false;
return true;
}
vector<long long> snt, ans;
int bd[66], dp[102][1 << 17], gt[102][1 << 17], res = 1e9, n, a[103], now;
pair<long long, long long> lu;
void Solve(... | 12 |
#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline T1 max(T1 a, T2 b) {
return a < b ? b : a;
}
template <typename T1, typename T2>
inline T1 min(T1 a, T2 b) {
return a < b ? a : b;
}
const char lf = '\n';
namespace ae86 {
const int bufl = 1 << 15;
char buf[bufl], *s = buf, *t ... | 17 |
#include <bits/stdc++.h>
using namespace std;
int partition(vector<int> &v, int low, int high) {
int pivot = v[high];
int i = low - 1;
for (int j = low; j <= high; ++j) {
if (v[j] < pivot) {
++i;
swap(v[i], v[j]);
}
}
swap(v[i + 1], v[high]);
return i + 1;
}
void quicksort(vector<int> &v... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int x[N], y[N], cx[N], cy[N], s[2][2];
int n, m, vx, vy, dx, dy;
long long ans = 0;
int read_int() {
int a = 0;
int b = 1, c = getchar();
if (c == '-')
b = -1;
else
a = c - 48;
while ((c = getchar()) != ' ' && c != '\n') a = a * 10 + ... | 23 |
#include <bits/stdc++.h>
using namespace std;
const int one = 1048576;
int n, inf = 1e9, f[40][one], g[30][30];
char s[30][30];
bool check(int x, int y) { return x >= 0 && y >= 0 && x < n && y < n; }
int Get(int x, int y, int c) {
if (c == 0) {
if ((x + y) & 1) return -1;
return 1;
}
if (c == 1) {
if ... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = 70000 + 5, S = 70000 + 5;
int n, s;
int an[N];
bitset<S> f, ft, dt[N / 3 + 5];
bool direct[N];
int od[N], sz_od, pos[N];
inline bool cmp_int_bag_an(int a, int b) { return an[a] < an[b]; }
int main() {
scanf("%d%d", &n, &s);
for (int i = 1; i <= n; ++i) sca... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, temp, ar1[2010], ar2[2010], con[2010], i = 1, c = 0, c1 = 0, j, pos;
for (i = 1; i <= 2010; i++) con[i] = 0;
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%d", &ar1[i]);
ar2[i] = i;
con[ar1[i]] += 1;
}
for (i = 1; i <= 2010; ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int ara[100001];
int main() {
int n, x;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> ara[i];
while (ara[i] % 2 == 0) ara[i] /= 2;
while (ara[i] % 3 == 0) ara[i] /= 3;
}
for (int i = 2; i <= n; i++) {
if (ara[1] != ara[i]) {
cout << "No" <<... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long int a, d;
vector<long long int> val(10000007, 0);
vector<long long int> su(10000007, 0);
int main() {
long long int q, n, x, y, i, j, k, ans = 0, lim = 2000000;
cin >> a >> d >> q;
su[0] = val[0] = 0;
for (i = 1; i <= 2000000; i++) {
val[i] = a + (i - ... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, k, ct[5010], A[100010], dp[100010];
long long fact[100100];
long long moduloexp(long long a, long long b) {
long long res = 1;
while (b) {
if (b & 1) res = (1LL * res * a) % 1000000007;
b /= 2;
a = (1LL * a * a) % 1000000007;
}
return res... | 13 |
#include <bits/stdc++.h>
using namespace std;
bool debug = false;
int n, m;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
long long k, l, r, p;
long long fastPow(long long x, long long y, long long mod) {
long long ans = 1;
while (y > 0) {
if (y & 1) ans = (x * ans) % mod;
x = x * x % mod;
y >>= 1;
... | 18 |
#include <bits/stdc++.h>
int main() {
int a, b, p, c;
scanf("%d %d", &a, &b);
while (b > 0) {
p = a % 10;
if (p == 0)
a = a / 10;
else
a = a - 1;
b = b - 1;
}
printf("%d", a);
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int prime[1010];
int p[1010], run;
int a[100];
char seq[1010], ans[1010];
int ind, run1;
int main() {
char s[1010];
cin >> s;
int k = strlen(s);
int maxi = 0;
char ch;
for (int i = 2; i <= 1000; i++)
for (int j = 2; j < i; j++)
if (i % j == 0) prime[i]... | 5 |
#include <bits/stdc++.h>
using namespace std;
int X[280];
bool vis[280];
int main() {
int n, k;
cin >> n >> k;
int temp;
memset(X, -1, sizeof(X));
for (int i = 0; i < n; i++) {
cin >> temp;
if (X[temp] == -1) {
int a = temp;
while (vis[a - 1] == false && a >= temp - k + 2 && a >= 1) a--;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int T12 = 531441;
int conv[T12 + 10];
int amt[1 << 12];
int w, n, m;
int count(int cur, int k, const string& s) {
if (k == w) {
return conv[cur];
}
if (s[k] == 'A') {
return count(cur * 3, k + 1, s) + count(cur * 3 + 1, k + 1, s);
} else if (s[k] == 'O... | 20 |
#include <bits/stdc++.h>
using namespace std;
int n;
long long dp[2][20001];
int main() {
int x;
while (cin >> n) {
long long ans = 0LL;
dp[0][0] = 1;
for (int i = 0; i < n; i++) {
cin >> x;
ans += dp[i & 1][x];
ans %= (int)(1e9 + 7);
int act = (i & 1) ^ 1;
for (int j = 0; ... | 15 |
#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
long long x[100005], c[100005];
priority_queue<long long, vector<long long>, greater<long long> > q;
int main() {
int n;
long long k, a;
cin >> n >> k;
for (int i = 1; i <= n; i++) scanf("%lld", &x[i]);
cin >> a;
for (int i = 1; i <= n; i... | 7 |
#include <bits/stdc++.h>
const long long int mod = 1e9 + 7;
using namespace std;
const int N = 3005;
int ans[N][N];
string second[N];
void solve1() {
long long int n, m;
cin >> n >> m;
for (long long int i = 1; i < n + 1; i++) {
cin >> second[i];
second[i] = '0' + second[i];
}
ans[1][2] = 1;
long lo... | 17 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll arr[101010];
ll m, n;
ll k = 1;
ll sum = 0;
ll fr[101010];
int main() {
scanf("%lld%lld", &m, &n);
for (ll i = 0; i < n; i++) {
scanf("%lld", arr + i);
if (i + arr[i] > m) {
puts("-1");
return 0;
}
sum += arr[i];
}
... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long f(long long first) {
if (!first) return 0;
long long res = 0, i;
for (i = 1; i <= first && i <= 1000000000000000000LL; res += i, i *= 10)
if (first == i) return res + 1;
if (first < 10) return 1;
if (first - i / 10 >= i / 10) return f(i) - 1;
retur... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int nums[12][100010];
set<int> follow[100010];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
cin >> nums[i][j];
}
}
for (int i = 0; i < m; i++) {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int k, n;
char s[1000006];
pair<pair<bool, bool>, pair<bool, bool> > dfs() {
switch (s[k]) {
case '1':
return make_pair(make_pair(0, 0), make_pair(0, 1));
case '0':
return make_pair(make_pair(1, 0), make_pair(0, 0));
case '?':
return make_pai... | 18 |
#include <bits/stdc++.h>
#pragma gcc optimize("ofast")
using namespace std;
long long modexp(long long a, long long b, long long m) {
long long r = 1;
a = a % m;
while (b > 0) {
if (b & 1) r = (r * a) % m;
b = b / 2;
a = (a * a) % m;
}
return r % m;
}
const int MAXN = 100002;
long long a[MAXN];
ve... | 12 |
#include <bits/stdc++.h>
using namespace std;
const long long int INF = (long long int)1e9 + 10;
const long long int INFLL = (long long int)1e18 + 10;
const long double EPS = 1e-10;
const long long int MOD = 1e9 + 7;
template <class T>
T &chmin(T &a, const T &b) {
return a = min(a, b);
}
template <class T>
T &chmax(T... | 11 |
#include <bits/stdc++.h>
using namespace std;
int const N = 5000000;
int n, m;
long long v[N], vv[N];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) scanf("%lld", v + i);
scanf("%d", &m);
for (int i = 0; i < m; ++i) scanf("%lld", vv + i);
int an = 0;
int i = 0, j = 0;
long long sm0 = v[0], sm1 ... | 8 |
#include <bits/stdc++.h>
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ld = long double;
using vi = std::vector<int>;
using pii = std::pair<int, int>;
using vvi = std::vector<vi>;
using vii = std::vector<pii>;
using vll = std::vector<ll>;
using pll = std::pair<ll, ll>;
template ... | 17 |
#include <bits/stdc++.h>
using namespace std;
const long long infl = 1e15;
const int inf = 2e9 + 100;
const int nmax = 5e5 + 5;
int n;
vector<long long> by, sy;
vector<long long> by2, sy2;
bool hobe(vector<pair<long long, long long> >& v, long double d) {
int j = 0;
for (int i = 0; i < n; i++) {
while (j < n - ... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d, m, v;
cin >> a >> b >> c >> d;
m = max((3 * a) / 10, a - (a * c) / 250);
v = max((3 * b) / 10, b - (b * d) / 250);
if (m > v)
cout << "Misha" << endl;
else if (v > m)
cout << "Vasya" << endl;
else
cout << "Tie" << endl;... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e6, mod = 1e9 + 7;
int read() {
int a = 0;
bool opt = 0;
char c = getchar();
while (c < '0' || c > '9') opt |= c == '-', c = getchar();
while (c >= '0' && c <= '9')
a = (a << 3) + (a << 1) + (c ^ 48), c = getchar();
return opt ? -a : a;
}
int ... | 17 |
#include <bits/stdc++.h>
const int oo = 0x3f3f3f3f, mod = 1e9 + 7;
using namespace std;
int dx[]{1, -1, 0, 0, 1, 1, -1, -1};
int dy[]{0, 0, 1, -1, 1, -1, 1, -1};
void K_K() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
long long gcd(long long a, long long b) {
return b == 0 ? abs(a) : gcd(b, a % b);
}
l... | 3 |
#include <bits/stdc++.h>
int main() {
int a, s;
scanf("%d", &a);
s = sqrt(a);
while (a % s != 0) s--;
printf("%d %d\n", s, a / s);
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int T, n, flag[8], dis[100010][8], op, cl, d[100010], x, c, D[8][8], bin[10],
s[100010], cnt[8][256], mx, mn, s1;
long long sum;
char S[100010];
vector<int> son[8];
int main() {
bin[0] = 1;
for (int i = 1; i <= 9; i++) bin[i] = bin[i - 1] << 1;
scanf("%d%s", &n, S... | 25 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 1912;
int n;
int a[maxn];
int main() {
std ::ios_base::sync_with_stdio(false);
cin.tie(0);
scanf("%d", &n);
for (int i = (1); i <= (n); i++) scanf("%d", &a[i]);
for (int i = (1); i <= (n); i++) {
while (a[i] % 2 == 0) a[i] /= 2;
w... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
while (~scanf("%d", &n)) {
int flag = 1;
int x;
long long sum = 0;
for (int i = 1; i <= n; ++i) {
scanf("%d", &x);
sum += x;
if (x == 0) {
if (sum & 1) {
flag = 0;
}
sum = 0;
}... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long A, B, Y, G, Bl, a, b, c, d, ans = 0;
cin >> A >> B;
cin >> Y >> G >> Bl;
a = (Y * 2) + G;
b = G + 3 * Bl;
c = a - A;
d = b - B;
if (c > 0) ans = ans + c;
if (d > 0) ans = ans + d;
cout << ans;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 50;
int n, p;
long long int curent, ans[N];
priority_queue<pair<int, int> > q1;
queue<int> q;
priority_queue<int> q2;
int main() {
cin >> n >> p;
for (int i = 1; i <= n; ++i) {
int x;
cin >> x;
q1.push(make_pair(-x, -i));
}
for (int i... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(NULL);
int t;
cin >> t;
while (t--) {
long long a, b;
cin >> a >> b;
long long dif = abs(a - b);
if (a == b) {
cout << "0\n";
continue;
}
int ans = dif / 5;
di... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, dp[2][60][60], q[60][60][60][60];
int ask(int a, int b, int c, int d) {
if (q[a][b][c][d] != -1) return q[a][b][c][d];
cout << "? " << a << " " << b << " " << c << " " << d << endl;
cout.flush();
int x;
cin >> x;
if (x == -1) exit(0);
x = 1 ^ x;
q[a][... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int c = 1000005;
int n, m, mm, sum, t, tt, csop[c];
vector<pair<int, int> > sz;
vector<int> ans[c];
int main() {
ios_base::sync_with_stdio(false);
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int x;
cin >> x;
sz.push_back({x, i});
sum += x;
}
... | 23 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 10007;
const long long LINF = 2e16;
const int INF = 2e9;
const int magic = 348;
const double eps = 1e-10;
const double pi = 3.14159265;
inline int getint() {
char ch;
int res;
bool f;
while (!isdigit(ch = getchar()) && ch != '-') {
}
if (ch == '-... | 20 |
#include <bits/stdc++.h>
using namespace ::std;
const long long maxn = 3100;
const long long mod = 1e9 + 7;
const long long inf = 1e9 + 500;
long long e[maxn][maxn];
long long ee[maxn][maxn];
char jad[maxn][maxn];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long n, m;
cin >> n >> m;
for (int i... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, allsum = 0, ksum = 0;
cin >> n;
vector<int> a(n);
vector<int> ans;
cin >> a[0];
ksum += a[0];
ans.push_back(0);
for (int i = 1; i < n; i++) {
cin >> a[i];
if (a[0] >= 2 * a[i]) {
ksum += a[i];
ans.push_back(i);
} e... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5010, mod = 1000000007;
int n, m, T, q, ans = N * N, a[N][N], s[N][N];
char st[N];
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%s", st + 1);
for (int j = 1; j <= m; j++) a[i][j] = st[j] - '0';
}
q = max(n, m);
fo... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int m, n;
cin >> m >> n;
vector<string> c;
for (int i = 0; i < m; i++) {
string s;
cin >> s;
c.push_back(s);
}
for (int i = 0; i < m; i++)
for (int j = 0; j < n; j++) {
if (c[i][j] == 'S') {
if (i + 1 < m && c[i + 1][j]... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const int M = (1 << 20) + 1;
const long long INF = 1e9 + 1;
pair<int, int> gas[N];
long long dp[N];
int x[N], p[N];
struct Event {
int x;
int cost;
int num;
int typ;
};
bool cmp(const Event& a, const Event& b) {
if (a.x != b.x) return a.x <... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
long long a, b, c;
cin >> a >> b >> c;
string s[a];
for (long long i = 0; i < a; i++) {
cin >> s[i];
}
long long ct = 0;
for (long long i = 0; i < a; i++)
for (long long j = 0; j... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> b(n);
for (int i = 0; i < n; i++) cin >> b[i];
vector<int> c(n);
for (int i = 0; i < n; i++) c[i] = b[i] - i;
vector<pair<int, int>> vs;
for (int i = 0; i < n; i++) vs.push_back({c[i], b[i]});
sort(vs.begin(), vs.e... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
template <class T>
int size(T &x) {
return x.size();
}
vector<pair<int, int> > vals;
long double P(int no, int lo, int hi) {
lo = max(lo, vals[no].first);
hi = min(hi, vals[no].second);
if (lo > hi) return 0.0;
return static_cast<long d... | 12 |
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define all(x) (x).begin(), (x).end()
using ll = long long;
int l[200001], r[200001];
ll dp[200001][2];
vector<int> graph[200001];
void dfs(int now, int parent) {
dp[now][0] = dp[now][1] = 0;
for(int child : graph[now]) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 60;
vector<int> dy = {2, 1, 0};
vector<int> dx = {0, 1, 2};
int tabla[maxN][maxN];
int query(int y1, int x1, int y2, int x2) {
int ans;
cout << "? " << y1 + 1 << " " << x1 + 1 << " " << y2 + 1 << " " << x2 + 1
<< endl;
cin >> ans;
return ans;... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
string str, pal;
cin >> str;
vector<int> freq;
freq.push_back(1);
pal = str[0];
for (int i = 1; i < str.size(); i++) {
if (str[i] != str[i - 1]) {
freq.push_back(1);
pa... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int buf[500];
int main(void) {
memset(buf, -1, sizeof buf);
cin >> n >> m;
int ct = 0;
for (int i = 0; i < (m); ++i) {
int a;
cin >> a;
while (a--) {
int b;
cin >> b;
--b;
buf[b] = ct++;
}
}
vector<pair<int, int>... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long int modulo = 998244353;
void add(int &a, long long int b) { a = (a + b) % modulo; }
int n;
int v[105];
int d2c1[10], d2c2[10];
int d1, d2;
int memcompute[105][10][10][3][3][8][8][2][2];
int comcompute[105][10][10][3][3][8][8][2][2];
int getnextg(int pos, int... | 19 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000000 + 7;
const double esp = 1e-13;
int n, k, so, ans, per[10], dem, a[10];
string s[10];
int main() {
ios_base::sync_with_stdio(false);
cin.tie();
cin >> n >> k;
for (long long i = 1; i <= n; i++) cin >> s[i];
for (long long i = 1; i <... | 6 |
#include <bits/stdc++.h>
using namespace std;
map<string, int> isase;
struct info {
string s;
int d, h, m, c, f, id;
} help[101];
struct info_time {
int h, m, d;
} ar[100000], a[4][2];
struct info_ans {
int id, s, e;
} o;
vector<info_ans> vec;
int t, n, m;
bool fun(int i, int h, int m) {
int s, e, md;
md = ... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base ::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
string first, last;
cin >> first >> last;
string ans = "";
int i = 1;
while (i < first.length() && first.at(i) < last.at(0)) i++;
ans = first.at(0) + first.substr(1, i - 1) + last.at(... | 2 |
#include <bits/stdc++.h>
const int maxn = 2e5 + 10;
int n, m, a, b, r[20], p[20], c[20][20];
char s1[10], s2[10];
int D(int x) {
int d = 0;
while (x) x /= 10, ++d;
return d;
}
int check() {
for (int t = (0); t <= ((1 << m) - 1); ++t) {
a = 0, b = 0;
for (int i = (1); i <= (m); ++i)
if (t & (1 << (... | 24 |
#include <bits/stdc++.h>
using namespace std;
namespace Solve {
template <typename T>
void read(T& x) {
x = 0;
T s = 1;
char c;
do c = getchar();
while (c != '-' && (c < '0' || c > '9'));
if (c == '-') {
s = -1;
c = getchar();
}
while ('0' <= c && c <= '9') {
x = x * 10 + c - '0';
c = ge... | 9 |
#include <bits/stdc++.h>
namespace solution {
class SolutionInterface {
public:
virtual int run() = 0;
protected:
virtual void pre_calc() {}
virtual bool action() = 0;
virtual void init(){};
virtual bool input() { return false; };
virtual void output(){};
SolutionInterface() {}
private:
};
} // name... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
map<string, int> mp;
set<string> ss;
string S;
void dfs(string st) {
int cd = st.size(), i = 0;
while (st[i] != '?' && i < cd) i++;
if (i == cd) {
ss.insert(st);
return;
}
for (char ch = 'a'; ch <= 'e'; ch++) {
st[i] = ch;
dfs(st);
}
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, i, letter[30] = {0};
long long int substring = 0, cnt = 0;
string arr;
char ch;
cin >> n >> k;
cin >> arr;
for (i = 0; i < k; i++) {
cin >> ch;
letter[ch - 97] = 1;
}
for (i = 0; i < n; i++) {
if (letter[arr[i] - 97] == 1... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, q;
namespace flow {
const int MAXM = 1.2e7 + 6;
int N;
int head[200036], to[MAXM], nex[MAXM], wto[MAXM], cto[MAXM], cur[200036],
ecn = -1;
inline void Ade(int u, int v, int w, int c) {
to[++ecn] = v, nex[ecn] = head[u], wto[ecn] = w, cto[ecn] = c, head[u] = ecn... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, x;
cin >> n >> m >> x;
n -= 2 * (x - 1);
m -= 2 * (x - 1);
if (n < 1 || m < 1)
cout << 0 << endl;
else if (n + m == 2)
cout << 1 << endl;
else
cout << n + m - 2 << endl;
return 0;
}
| 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 201;
const int M = 1e9 + 7;
const double eps = 1e-6;
const double PI(acos(-1.0));
bitset<155> a, b, c;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
a[1] = 1;
b[0] = 1;
int n;
cin >> n;
for (int i = 0; i < (n - 1); i++) {
c = (... | 14 |
#include <bits/stdc++.h>
using namespace std;
vector<int> primes;
int divi[1000005];
int main() {
primes.push_back(2);
for (int i = 4; i <= 1000000; i += 2) divi[i] = 2;
for (int i = 3; i < 1000000; i += 2) {
if (divi[i] > 0) continue;
primes.push_back(i);
for (int j = i + i; j <= 1000000; j += i) div... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
long long int f = 1, t = 0, ans = 0;
cin >> s;
for (long long int i = 0; i <= s.length(); i++) {
if (s[i] < '0') {
ans += f * t;
s[i] == '+' ? f = 1 : f = -1;
t = 0;
}
t = t * 10 + s[i] - '0';
}
cout << ans <<... | 16 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int s = 0, t = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') t = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
return s * t;
}
const int N = 3505;... | 25 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
int n;
cin >> n;
vector<long long> a;
for (int i = 0; i < n; i++) {
long long l;
cin >> l;
a.push_back(l);
}
long long ans = 0;
vector<long long> res(n);
res[0] = 1;
for (int i = 1; i < n; i++) {
if (... | 1 |
#include <bits/stdc++.h>
using std::sort;
const int N = 200005;
int n, m;
struct Data {
int i, v;
bool operator<(const Data &b) const { return v < b.v; }
} p[N], s[N];
int b[N], d[N], bcnt = 0, ad = 0;
void match(int adapter) {
int i = 1, j = 1;
while (i <= n && j <= m) {
if (b[p[i].i] || p[i].v < s[j].v)
... | 13 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T abs(T x) {
return x > 0 ? x : -x;
}
template <typename T>
T sqr(T x) {
return x * x;
}
bool bad[100005], del[100005];
double cond[100005];
vector<int> g[100005];
int n, k;
double eps = 0.0000001;
bool check(double ratio) {
priority_queue<pair<d... | 15 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e5 + 5;
void c_p_c() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
bool isPrime(long long n) {
if (n <= 1) return false;
if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (long long i = 5; i * i <= n;... | 1 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-7;
const double PI = acos(-1.0);
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
const int maxn = 3e8 + 10;
bitset<maxn> prime;
int l, r;
int main() {
scanf("%d%d", &l, &r);
prime.set();
prime[... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int kN = 100 * 1000;
const int kInf = 1000 * 1000 * 1000;
map<string, int> name2id;
vector<string> id2name;
vector<string> arr;
vector<int> g[kN], gr[kN], graph[kN];
bool used[kN];
vector<int> order, component;
int N;
void DFS1(int u) {
if (used[u]) {
return;
... | 16 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
void makedata() {
freopen("input.txt", "w", stdout);
fclose(stdout);
}
map<long long, pair<int, int> > mp;
vector<long long> v;
long long ans[250000];
int main() {
std::ios::sync_with_stdio(0), cin.tie(0);
int n;... | 9 |
#include <bits/stdc++.h>
using namespace std;
int a[100005];
int main() {
int n;
cin >> n;
int i;
for (i = 0; i < n; i++) cin >> a[i];
if (a[0] % 2 != 0 && a[n - 1] % 2 != 0 && n % 2 != 0)
printf("YES");
else
printf("NO");
return 0;
}
| 2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.