solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long int t;
cin >> t;
for (int it = 0; it < (t); ++it) {
long long int n;
string second;
cin >> n;
cin >> second;
long long int diff = INT_MAX... | 7 |
#include <bits/stdc++.h>
using namespace std;
struct block {
int size, start, end;
block(int s, int ss, int e) {
size = s;
start = ss;
end = e;
}
};
stack<pair<int, int> > S;
vector<block> Block;
string s;
int St[1000010], ans, st;
void SetEndPoints(string s) {
for (int i = 0; i < s.size(); i++) {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int first, long long int n) {
if (n == 0)
return 1;
else if (n % 2 == 0) {
long long int second = power(first, n / 2);
return second * second;
} else
return first * power(first, n - 1);
}
int strTOint(string s) {
strings... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> pos(n);
vector<char> colors(n);
for (int i = 0; i < n; i++) {
cin >> pos[i] >> colors[i];
}
map<char, vector<int> > prev, next;
map<char, int> first, last;
for (char color : {'G', 'R', 'B'}) {
prev[color].r... | 16 |
#include <bits/stdc++.h>
using namespace std;
int arr[200][200];
void solve(int x, int y) {
if (arr[x][y] < 3)
arr[x][y]++;
else {
arr[x][y] = 0;
solve(x + 1, y);
solve(x - 1, y);
solve(x, y + 1);
solve(x, y - 1);
}
}
int main() {
int n, t, x, y;
cin >> n >> t;
for (int i = 0; i < n;... | 12 |
#include <bits/stdc++.h>
using namespace std;
map<int, vector<int> > m;
int count(vector<int> &v1, vector<int> &v2) {
int temp = v1[0], counter = 1, i = 1, j = 0, b = 0;
while (i < v1.size() || j < v2.size()) {
if (!(!b && j < v2.size()) && !(b && i < v1.size())) break;
while (!b && j < v2.size()) {
i... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int power(int a, int b, int m, int ans = 1) {
for (; b; b >>= 1, a = 1LL * a * a % m)
if (b & 1) ans = 1LL * ans * a % m;
return ans;
}
int vst[110][110];
int a[110][110];
int ans[110];
int f[110];
int t[110];
int fv[110];
int n;
int calc() ... | 18 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = long double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<db, db>;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = ... | 15 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
if (a % b == 0) {
return b;
}
return gcd(b, a % b);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int a, b, n;
cin >> a >> b >> n;
int c = 0;
for (int i = 0;; i++) {
if (n == 0) {
break;
}
if (i % 2 ... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long power(long long i, long long j) {
if (j == 0) return 1;
long long t = power(i, j / 2) % 1000000007;
if (j % 2 == 0)
return (t % 1000000007 * t % 1000000007) % 1000000007;
else
return ((t % 1000000007 * t % 1000000007) % 1000000007 * (i % 1000000007... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, s1, s2, s = 0, c = 0;
cin >> n;
vector<int> v(n + 1);
for (int i = 1; i <= n; i++) {
cin >> v[i];
s += v[i];
}
cin >> s1 >> s2;
if (s1 > s2) swap(s1, s2);
for (int i = s1; i < s2; i++) {
c += v[i];
}
cout << min(c, (s -... | 0 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_int_distribution<int> gen(1, 10);
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
int a[200005];
for (int i = 0; i < n; i++) cin >> a[i];
multiset<int> b;
for (in... | 9 |
#include <bits/stdc++.h>
using namespace std;
int a[1000005];
int lpos[505], rpos[505];
int minn[2005][2005], minl[2005][2005], maxr[2005][2005];
bool vis[2005][2005], can[2005][2005];
int f[2005][2005];
int dp(int l, int r) {
if (l > r) return 1;
if (!can[l][r]) return 0;
if (vis[l][r]) return f[l][r];
vis[l][... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int M = 256;
class Twosat {
class Tarjan {
struct E {
int u, v, next;
} e[M * M];
int le, head[M], Index, Bcnt, num[M], belong[M], dfn[M], low[M];
bool instack[M];
stack<int> s;
void tarjan(int u) {
dfn[u] = low[u] = ++Index;
... | 14 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool updateMin(T& a, T b) {
return a > b ? a = b, 1 : 0;
}
template <class T>
inline bool updateMax(T& a, T b) {
return a < b ? a = b, 1 : 0;
}
inline int nextInt() {
int x;
scanf("%d", &x);
return x;
}
inline long long nextI64() {
long... | 11 |
#include <bits/stdc++.h>
using namespace std;
void io() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
const int MAXN = 5e5 + 5;
const long long INF = 0x3f3f3f3f3f3f3f;
const long long MOD = 1e9 + 7;
struct Point {
double x, y;
Point(double _x = 0, double _y = 0) : x(_x), y(_y) {}
Poi... | 11 |
#include <bits/stdc++.h>
using namespace std;
struct Cup {
long value;
long storage;
long number;
};
bool compareByValue(Cup a, Cup b) { return a.value > b.value; }
bool compareByNumber(Cup a, Cup b) { return a.number < b.number; }
int main() {
long n, w, sum = 0;
Cup a[100] = {0, 0, 0};
cin >> n >> w;
fo... | 6 |
#include <bits/stdc++.h>
using namespace std;
struct Node {
long long s[10];
int p[10];
bool f;
Node() {
for (int i = 0; i < (int)(10); i++) s[i] = 0;
f = false;
for (int i = 0; i < (int)(10); i++) p[i] = i;
}
};
vector<Node> t;
int n;
vector<int> a;
void updateOne(int v) {
for (int d = 0; d < (... | 20 |
#include <bits/stdc++.h>
const int N = 1000001;
int n, k, dilen[N], ditiep[N], diluon[N];
std::vector<int> adj[N];
void dfs(int u) {
if (adj[u].empty()) {
dilen[u] = k;
ditiep[u] = 1;
}
for (int v : adj[u]) {
dfs(v);
if (dilen[v] == 0)
ditiep[v] = 0;
else {
dilen[u] = std::max(dile... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int N;
cin >> N;
int i, j;
int A[N];
for (i = 0; i < N; i++) cin >> A[i];
if (N == 1) {
cout << -1 << endl;
return 0;
}
vector<int> answer;
for (i = 1; i < (1 << N)... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
vector<int> b = a;
sort(b.begin(), b.end());
int ret = 0;
for (int i = 0; i < n; i++)
if (a[i] != b[i]) ret++;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
void print(int h, string &s) {
for (int i = 0; i < h; i++) cout << " ";
cout << s << endl;
}
int main() {
string s;
vector<string> Strings;
cin >> s;
int curpos = s.find('<');
int lastPos;
while (curpos != -1) {
lastPos = s.find('>', curpos);
String... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long double pi = acos(-1);
int main() {
ios::sync_with_stdio(0);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
vector<vector<int> > a(n + 1, vector<int>(m + 1, 0));
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
cin >> a[i][j];
}
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int a, b;
string s;
int dx = 0, dy = 0;
int main() {
cin >> a >> b;
if (a == 0 && b == 0) {
puts("Yes");
return 0;
}
cin >> s;
for (auto c : s) {
if (c == 'R')
dx++;
else if (c == 'L')
dx--;
else if (c == 'U')
dy++;
else
... | 9 |
#include <bits/stdc++.h>
const long long INFLL = 0x3f3f3f3f3f3f3f3f;
const int LG = 18;
const int N = 1 << LG;
int n, a[N + 1];
long long dp[N][LG + 1];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", a + i);
if (a[i] == -1) {
for (int j = 1; j < i; ++j) a[j] = 0;
--i;
... | 16 |
#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
c b, e;
};
template <class c>
rge<c> range(c i, c j) {
return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct dbg {
template <class c>
dbg& operator<<(const c&) {
... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int q;
cin >> q;
while (q--) {
string s;
cin >> s;
vector<int> p, n;
for (int i = 0; i < s.size(); ++i) {
if (s[i] % 2 == 0)
p.push_back(s[i] - 48);
else
n.push_back(s[i] - 48);
}
int i = 0, j = 0;
w... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, m, c, r, t, x, y, z;
int num;
int a[600010], b[600010], siz[600010], son[600010], ans[600010], fa[600010],
head[600010];
struct hz {
int next;
int to;
} h[600010];
void add(int from, int to) {
h[++num].next = head[from];
h[num].to = to;
head[from] = num... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
int dif = b - a;
if (a == 0 && b == 0)
cout << "NO" << endl;
else if (dif == 0 || dif == 1 || dif == -1)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
| 2 |
#include <bits/stdc++.h>
int main() {
double a[15][15];
memset(a, 0, sizeof(a));
int n, t, count = 0;
scanf("%d%d", &n, &t);
a[1][1] = t;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
a[i][j] += 0.5 * ((a[i - 1][j - 1] >= 1 ? a[i - 1][j - 1] - 1 : 0) +
(a[i ... | 7 |
#include <bits/stdc++.h>
using namespace std;
double SIMPLEX_METHOD_PD(vector<vector<double>> &A, vector<double> &b,
vector<double> &c, vector<double> &x) {
const double eps = 1e-9, oo = numeric_limits<double>::infinity();
long long n = c.size(), m = b.size();
vector<vector<double>> T(m +... | 18 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
void solve() {
string s;
cin >> s;
long long int c = 0;
while (s.length() != 1) {
long long int sum = 0;
for (auto i : s) sum += (long long int)(i - '0');
s = to_string(sum);
c++;
}
cout << c << "\n";
}
int32_t main() {
ios... | 2 |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
ll t;
cin>>t;
for(ll test=0;test<t;test++)
{
ll n,m;
cin>>n>>m;
ll r[m],c[m];
map <ll,ll> freq;
map <ll,vector <ll> > row;
... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n;
char s[3], t[3];
bool vis[3][3];
int a[3];
bool f[3];
bool dfs(int cur) {
if (cur < 0) {
bool ok = true;
for (int i = 0; i <= 2; i++) {
if (vis[a[i]][a[(i + 1) % 3]]) {
ok = false;
break;
}
}
if... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)1e5 + 100;
pair<int, int> v[maxn];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
int x, y;
scanf("%d%d", &x, &y);
v[i] = make_pair(y, x);
}
sort(v, v + n);
for (int i = 0; i < n - 1; i++) {
if (v[i].firs... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long INF = 1e7;
double EPS = 1e-12;
const long long lim = 2e5 + 10;
template <typename T1>
void printIt(T1 t1) {
cout << t1 << " )" << endl;
}
template <typename T1, typename... T2>
void printIt(T1 t1, T2... t2) {
cout << t1 << " , ";
pri... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MAXX = 1e5 + 5, INF = 5e6 + 11;
long long a[4 * MAXX], b[MAXX], d[105][105];
long long i, j, z, n, m, t, s, l, r, x, y;
long long ans;
string s1, s2;
vector<int> v[150002];
bool u[150005];
void dfs(int x) {
u[x] = true;
for (int j = 0; j < v[x].size(); j++) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int cost[5];
char buff[1005];
string arr[5];
int n = 4, m;
int DP[4][1001][1 << 4][1 << 4][1 << 4];
int mask[5][5][5];
int solve(int ind, int col, int m1, int m2, int m3) {
if (ind && (m1 & (1 << (ind - 1)))) m1 -= 1 << (ind - 1);
if (col == m) return 0;
if (ind == n)... | 14 |
#include <bits/stdc++.h>
using namespace std;
class graph {
int v, e;
list<pair<int, int> > *adj;
list<pair<int, int> > *clrs;
public:
graph(int v_, int e_) : v(v_), e(e_) {
adj = new list<pair<int, int> >[v];
clrs = new list<pair<int, int> >[e];
}
void add_edge(int x, int y, int w) {
adj[x].p... | 16 |
#include <bits/stdc++.h>
using namespace std;
namespace Dinic {
const int MAXV = 1000100;
const int MAXE = 1000100;
const long long oo = 1e18;
int V, E;
int last[MAXV], dist[MAXV], curr[MAXV];
int next[MAXE], adj[MAXE];
long long cap[MAXE];
void init(int n) {
V = n;
E = 0;
for (int i = (0); i < (V); ++i) last[i] ... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int total;
total = (n + 1) / 2;
total = total * total;
if (n % 2 == 0)
total = total * 2;
else {
int total2;
int n2;
n2 = n - 2;
total2 = (n2 + 1) / 2;
total2 = total2 * total2;
total = total + ... | 6 |
#include <bits/stdc++.h>
using namespace std;
struct P {
int x, y;
bool operator<(const P &a) const { return x < a.x; }
};
P v[5055];
int a, b, c, n, m, i, o[620000], k, d, e, dy[15] = {0, 0, -1, 1, -1, 1, -1, 1},
dx[15] = {-1, 1, 0, 0, 1, 1, -1, -1};
int l[610011];
long lo... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
int n;
cin >> n;
vector<pair<int, int> > p(n);
for (int i = 0; i < n; i++) {
cin >> p[i].first >> p[i].second;
p[i].first += 1e6;
p[i].second += 1e6;
}
while (true) {
vector<vector<... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int MX = 2e6 + 10;
const int mod = 1e9 + 7;
const long long int inf = 1LL << 62;
int dx4[] = {0, 0, -1, 1};
int dy4[] = {1, -1, 0, 0};
int dx[] = {1, 1, 1, 0, 0, -1, -1, -1};
int dy[] = {1, 0, -1, 1, -1, 1, 0, -1};
long long int ar[MX], br[MX];
long long int dp[5005][... | 9 |
#include <bits/stdc++.h>
using namespace std;
void readi(int &x) {
int v = 0, f = 1;
char c = getchar();
while (!isdigit(c) && c != '-') c = getchar();
if (c == '-')
f = -1;
else
v = v * 10 + c - '0';
while (isdigit(c = getchar())) v = v * 10 + c - '0';
x = v * f;
}
void readll(long long &x) {
l... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> v(n, 0);
for (int i = 0; i < n; i++) cin >> v[i];
sort(v.begin(), v.end());
double max1 = v[n - 1];
double sum = 0;
for (int i = 0; i < n - 1; i++) sum += v[i];
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
void init_io() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
int main() {
init_io();
cout << fixed << setprecision(15);
int n, d;
cin >> n >> d;
vector<int> a(n, 0);
for (int i = 0; i < n; ++i) cin >> a[i];
int m;
cin >> ... | 23 |
#include <bits/stdc++.h>
using namespace std;
char S[1024][1024];
int nrS[1024][1024];
long long pw[30];
long long withrev(int x, int y, long long v, bool rev) {
return rev ? (long long)(x + 1) * (y + 1) - v : v;
}
long long go(int x, int y, long long a, long long b, int n, int m, int k,
bool rev = false... | 17 |
#include <bits/stdc++.h>
using namespace std;
vector<int> vec;
const int N = 5e5 + 6;
double acum[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int q;
cin >> q;
int indx = 0;
while (q--) {
int t;
cin >> t;
if (t == 1) {
int x;
cin >> x;
if (indx)
acum[indx]... | 10 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-10;
const double pi = 3.1415926535897932384626433832795;
const double eln = 2.718281828459045235360287471352;
long long a[1000005];
const long long hi = 1e18;
int main() {
int i;
a[1] = 2;
a[2] = 3;
i = 2;
while (a[i] <= hi) i++, a[i] = a[i -... | 8 |
#include <bits/stdc++.h>
void rd(int &x) {
x = 0;
int f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar();
x *= f;
}
void lrd(long long &x) {
x = 0;
int f = 1;
char ch = getch... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
long long ans = 0;
for (long long i = 1; i < s.size(); i++) {
if (((s[i - 1] - '0') * 10 + s[i] - '0') % 4 == 0) {
ans += i;
}
}
for (long long i = 0; i < s.size(); i++) {
if ((s[i] - '0') % 4 == 0) {
ans+... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int u, p, b;
cin >> u >> p >> b;
long long int n;
cin >> n;
vector<long long int> um;
vector<long long int> pm;
for (long long int i = 0; i < n; i++) {
long long int x;
cin >> x;
string s;
cin >> s;
if (s[0] == 'U') {... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long int powmod(long long int a, int b, int n) {
long long int rm = 1;
while (b) {
if (b % 2) {
rm = (rm * a) % n;
}
a = (a * a) % n;
b /= 2;
}
return rm;
}
int n, sz[210] = {0}, fans = 0;
vector<int> edge[210];
pair<int, int> dfs(int vert... | 11 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long llinf = (1LL << 62);
const int inf = (1 << 30);
const int nmax = 1e5 + 50;
const long long mod = 1e9 + 7;
using namespace std;
int n, m, viz[nmax], bd[nmax], x, y, i, j, t, ... | 22 |
#include <bits/stdc++.h>
using namespace std;
const double g = 9.8;
int n, m;
double v0;
const int MAXN = 10101;
const int MAXM = 101010;
double a[MAXN], x[MAXN], y[MAXN];
pair<double, double> wall[MAXM];
int pos[MAXN];
bool cmp(int x, int y) { return a[x] < a[y]; }
int main() {
scanf("%d", &n);
scanf("%lf", &v0);
... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s1 = "", s2 = "";
cin >> n;
char arr[n];
for (int i = 0; i <= n; i++) cin >> arr[i];
if (n % 2 == 0) {
for (int i = 0; i < n; i++) {
if (i % 2 == 0)
s1 += arr[i];
else
s2 += arr[i];
}
reverse(s1.... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 30;
const int SZ = 320;
const int ADD = 160;
struct state {
int x;
int y;
int k;
int f;
int d;
state() {}
state(int _x, int _y, int _k, int _f, int _d) {
x = _x, y = _y, k = _k, f = _f, d = _d;
}
};
int n;
int t[MAX_N];
int ans[SZ][SZ];... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
int x = 99999999, y = 99999999;
cin >> n;
for (int i = 0; i <= n / 4; i++) {
if (ceil((double)(n - 4 * i) / 7) == ((n - 4 * i) / 7)) {
if (i + ((n - 4 * i) / 7) < x + y) {
x = i;
y = ((n - 4 * i) / 7);
continue;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long inf = 1e18;
const long long dx[8] = {-1, 0, 1, 0, -1, 1, 1, -1},
dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const long long kdx[8] = {-2, -1, 1, 2, 2, 1, -1, -2},
kdy[8] = {1, 2, 2, 1, -1, -2, -2, -1};... | 4 |
#include <bits/stdc++.h>
using namespace std;
int num[100];
int nr[100];
int main() {
int n;
int i;
scanf("%d", &n);
if (n % 2 == 0) {
for (i = 1; i <= n; i += 2) {
printf("%d %d ", i + 1, i);
}
} else {
printf("-1");
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> g[100012];
int m, n, q;
vector<pair<int, int>> b;
long long d[100012], diff[100012];
vector<int> buf[100012];
void dijkstra() {
fill(d + 1, d + n + 1, 1e18);
d[1] = 0;
priority_queue<pair<long long, int>> pq;
pq.push({0, 1});
while (pq.size(... | 26 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
inline long long read() {
long long 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 ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long siz = 2e5 + 10;
const long long SIZ = 1e6 + 10;
const long long mod = 1e9 + 7;
const long long maxx = 2e9;
const long long MAXX = 1e18;
long long t, n;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
long long x = 0;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
long long n, m;
cin >> n >> m;
vector<long long> pos(n + m, 0);
vector<long long> flag(n + m, 0);
vector<long long> ans(m, 0);
for (long long i = 0; i < n + m; i++) cin >> pos[i];
for (long long i = 0; i < n + m; i++) cin >> flag[i];
long lon... | 4 |
#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
const int mod = 1e9 + 7;
int dcmp(long double x, long double y) {
return fabs(x - y) <= 1e-12 ? 0 : x < y ? -1 : 1;
}
void fast() {
std::ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
cin >> str;
int t = 0;
string a, b, c, d, e;
for (int i = 0; i < str.length(); i++) {
a = str.substr(i, 5);
if (a == "Danil") t = t + 1;
b = str.substr(i, 4);
if (b == "Olya") t = t + 1;
c = str.substr(i, 5);
if (c ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
unsigned long long k, x, kk;
cin >> k >> x;
kk = k;
int co = 0;
while (k <= x) {
if (k == x) {
cout << "YES" << endl;
cout << co << endl;
return 0;
}
k *= kk;
co++;
}
cout << "NO" << endl;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
void func(string s, int i) {
for (int j = 0; j < i; j++) cout << s;
}
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
int k = 2 * n;
func("(", i);
func(")", i);
... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : 0; }
struct Point {
int x, y;
Point() : x(0), y(0) {}
Point(int x, int y) : x(x), y(y) {}
Point operator-(const Point &r) const { return Point(x - r.x, y - r.y); }
Point operator+(const Point &r)... | 19 |
#include <bits/stdc++.h>
using namespace std;
int read() {
int x;
scanf("%d", &x);
return x;
}
int n, m, k;
struct Node {
int x, y;
} pos[1005];
int x[1005], y[1005], Sizx, Sizy;
int mp[1005][1005];
bool check(int mid) {
memset(mp, 0, sizeof(mp));
Sizx = 0;
Sizy = 0;
memset(x, 0, sizeof(x));
memset(y,... | 16 |
#include <bits/stdc++.h>
using namespace std;
int dp[1111][505];
struct T {
int in, out, c, w, s;
} a[505];
inline bool lenCMP(const T &a, const T &b) {
return a.out - a.in < b.out - b.in;
}
inline bool bypair(const int &i, const int &j) {
return make_pair(a[i].in, a[i].out) < make_pair(a[j].in, a[j].out);
}
int ... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const int maxN = 209;
struct Node {
bool endOfWord;
Node* next[2];
int cnt = 0;
Node() {
endOfWord = false;
for (int i = (0); i <= ((2) - 1); ++i) next[i] = NULL;
}
};
void insert(string s, Node* root) {
Node* curr = root;
for ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
char mp[N][N];
int n, m;
int a[N][N];
int dx[10] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[10] = {0, 0, 1, -1, 1, -1, -1, 1};
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
scanf("%s", mp[i] + 1);
}
for (int i = 2; i < n; i++) {
f... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, t;
cin >> n >> t;
int arr[n - 1];
for (int i = 0; i < n - 1; i++) cin >> arr[i];
int tmp = 1;
for (int j = 0; j < n - 1; j = tmp - 1) {
tmp += arr[j];
if (tmp == t) {
cout << "YES" << '\n';
break;
} else if (tmp > t) {... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
vector<int> v[maxn * 2];
int dp[maxn * 2][1 << 8], g[1 << 8];
int vis[10], vis2[10];
int b[maxn * 2];
int l[maxn], r[maxn];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m, K;
cin >> n >> m >> K;
for (int i = 1; i <= n; i++... | 17 |
#include <bits/stdc++.h>
using namespace std;
int mul = 1;
int mod = 1e9 + 9;
int ans = 1;
bool ok = false;
int main() {
int n, m;
scanf("%d %d", &n, &m);
for (int i = 1; i <= m; i++) {
mul *= 2;
if (mul >= n + 1) ok = true;
mul %= mod;
}
if (!ok) {
printf("0");
return 0;
}
for (int i ... | 5 |
#include <bits/stdc++.h>
const double eps = 1e-9;
const double pi = acos(-1);
using namespace std;
bool divis(const complex<long long>& a, const complex<long long>& b) {
complex<long long> C(0, 0);
C = a / b;
return (b * C == a);
}
int main() {
long long x, y;
cin >> x >> y;
complex<long long> A(x, y);
ci... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 155;
struct tedge {
int a, b, d;
};
inline bool operator<(const tedge &a, const tedge &b) { return a.d < b.d; }
int can[maxn][maxn], canpow[maxn][maxn];
int tmp[maxn][maxn], tmpmul[maxn][maxn];
int cur[maxn], nextcur[maxn];
int n, m;
int last;
tedge e[max... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
map<string, int> data;
string code, info;
string container[10];
cin >> code;
for (int i = 0; i < 10; i++) {
cin >> info;
container[i] = info;
data[info] = i;
}
string substring;
for (int i = 0; i < 8; i++) {
substring = code.subs... | 1 |
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
template <class T>
bool chmin(T& a, const T& b) {
return (b < a) ? (a = b, true) : false;
}
template <class T>
bool chmax(T& a, const T& b) {
return (b > a) ? (a = b, true) : false;
}
template <typename T>
istream& operator>>(istream& i, vector<T>... | 12 |
#include <bits/stdc++.h>
using namespace std;
int32_t mod = 1e9 + 7;
void solveCase() {
long long n, l = 0, r = 0, ans = 0;
cin >> n;
long long a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
for (; l < n; l++) {
while (r < n && a[r] - a[l] <= 5) {
r++;
ans = max(ans... | 4 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long a, b, r;
cin >> a >> b >> r;
if (a == r) {
cout << "1" << endl;
} else {
double avg = (a + b) / double(2);
if (r <= avg) {
cout << "2" << endl;
} else {
long long val1 = ceil(double(abs(r - a)) / abs(a + b - 2 * r... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
char ar[] = {'a', 'b', 'c', 'd'};
cin >> n;
for (int i = 0; i < n; i++) cout << ar[i % 4];
cout << endl;
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
bool endline = false;
template <class T>
istream& operator>>(istream& inp, vector<T>& v) {
for (auto& it : v) inp >> it;
return inp;
}
template <class T>
ostream& operator<<(ostream& out, vector<T>& v) {
for (auto& it : v) out << it << (endline ? "\n" : " ");
return... | 14 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long int i, j, n, m, a, b, c, d, e, x, y, z, cnt = 0, k = 0, l = 0,
sum = 0;
cin >> n;
long long int arr[n];
for (i = 0; i < n; i++) {
cin >> arr[i];
}
sort(arr, arr + n);
x = ceil((fl... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int Cases;
long long Piles[3];
cin >> Cases;
while (Cases--) {
cin >> Piles[0] >> Piles[1] >> Piles[2];
cout << (Piles[0] + Piles[1] + Piles[2]) / 2 << "\n";
}
return 0;
}
| 0 |
#include<iostream>
#include<map>
#include<vector>
using namespace std;
int main()
{
int n, m;
cin >> n >> m;
vector<vector<int>> a;
for (int i = 0; i < n; i++)
{
vector<int> input;
for (int j = 0; j < m; j++)
{
int c;
cin >> c;
input.push_back(c);
}
a.push_back(input);
}
int ans[200005];
in... | 17 |
#include <bits/stdc++.h>
using namespace std;
string a, b;
int main() {
cin >> a >> b;
if (a == b)
cout << a;
else
cout << 1;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
map<char, int> skew;
int main() {
string s, s2 = "Bulbasr";
cin >> s;
for (int i = 0; i < s.size(); i++) {
skew[s[i]]++;
}
int ans = 1000000;
skew['u'] /= 2;
skew['a'] /= 2;
for (int i = 0; i < s2.size(); i++) {
ans = min(skew[s2[i]], ans);
}
pri... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long MOD;
struct matr {
const static int n = 2;
long long a[n][n];
static matr tmp, tmp2;
void print() {
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
fprintf(stderr,
"%lld"
"%c",
a[i][... | 16 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long A = 257;
const int maxn = 600005;
long long p[maxn];
void init() {
p[0] = 1;
for (int i = 1; i < maxn; i++) {
p[i] = A * p[i - 1] % mod;
}
}
long long get_hash(string st) {
long long x = 0;
for (int i = 0; i < ... | 12 |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
void solve() {
string s;
cin >> s;
int n = s.size();
if(n % 2 == 1) {
cout << "NO\n";
return;
}
if(s[0] == ')' || s.back() == '(') {
cout << "NO\n";
return;
}
cout << "YES\n";
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int T =... | 2 |
#include <bits/stdc++.h>
using namespace std;
void file() {
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
}
int dx[8] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[8] = {0, 0, -1, 1, 1, -1, -1, 1};
int ans[5001];
int n, a[5001], cur[5001];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int row[N], col[N];
int main() {
int n, x, y, w;
scanf("%d", &n);
map<int, set<pair<int, int> > > mp;
set<pair<int, int> >::iterator it;
pair<int, int> points[n + 1];
for (int i = 0; i < n; i++) {
scanf("%d%d", &x, &y);
mp[y - x].in... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long f[100005], g[100005];
long long n, d, w;
bool solve(long long l) {
long long total = 0, m = d;
for (int i = 0; i < n; i++) {
total -= g[i];
long long cur = f[i] + total;
if (l - cur > m) return false;
if (i + w <= n && cur < l) {
total +=... | 9 |
#include<iostream>
#include<cstdio>
#include<algorithm>
#define N 100000
using namespace std;
typedef long long ll;
pair<ll, ll> ary[N+1];
int main(){
ll n;
cin >> n;
for(int i=1;i<=n;i++)
scanf("%lld %lld",&ary[i].second, &ary[i].first);
sort(ary+1,ary+n+1);
ll bias = 0, s = 1, e = n;
ll ans = 0;
while(s... | 8 |
#include <bits/stdc++.h>
int main() {
int n, n1 = 0, n2 = 0, n3 = 0, n4 = 0, n5 = 0, n6 = 0, n7 = 0;
scanf("%d", &n);
if (n == 5) {
n1 = n / 5;
printf("%d", n1);
} else if (n > 5 && n % 5 == 0) {
n7 = n / 5;
printf("%d", n7);
} else if (n > 5) {
n6 = n / 5;
printf("%d", n6 + 1);
} el... | 0 |
#include <bits/stdc++.h>
using namespace std;
bool isprime(int64_t n) {
for (int64_t i = 2; i * i <= n; ++i) {
if (n % i == 0) {
return false;
}
}
return true;
}
int64_t factorial(int64_t n) {
return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
}
int64_t gcd(int64_t a, int64_t b) {
if (a == 0)... | 5 |
#include <bits/stdc++.h>
using namespace std;
char s1[1005], s2[1005];
int main() {
int n1 = 0, n2 = 0, l1, l2;
char ch;
gets(s1);
l1 = strlen(s1);
gets(s2);
l2 = strlen(s2);
for (int i = 0; i < l1; i++)
if (s1[i] == '1') n1++;
for (int i = 0; i < l2; i++)
if (s2[i] == '1') n2++;
if (n1 + n1 %... | 9 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.