solution stringlengths 53 181k | difficulty int64 0 13 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int n, a, miejsce, ile_zostalo, wynik, result = 1000000000;
int poz[300], pom[300], ile[300];
vector<int> v[300], numer[4];
int main() {
scanf("%d", &n);
for (int i = 1; i <= (n); i++) scanf("%d", &poz[i]);
for (int i = 1; i <= (n); i++) {
scanf("%d", &ile[i]);
... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
string tos(T a) {
stringstream ss;
string ret;
ss << a;
ss >> ret;
return ret;
}
void read(int &_a) { int temp = scanf("%d", &_a); }
void read(int &_a, int &_b) { int temp = scanf("%d %d", &_a, &_b); }
void read(int &_a, int &_b, int &_c) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
char s[10013];
int g = 0, ret = 0;
map<string, int> ma;
void wczyt() {
string a;
while (s[g] >= 'A' && s[g] <= 'Z') {
a += s[g++];
}
ret += ma[a];
ma[a]++;
while (s[g] != '.') {
g++;
wczyt();
}
g++;
ma[a]--;
}
int main() {
scanf("%s", s);
w... | 4 |
#include <bits/stdc++.h>
#pragma GCC optimize( \
"Ofast,unroll-loops,no-stack-protector,unsafe-math-optimizations")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
template <typename T>
inline bool cmin(T& a, const T& b) {
return a > b ? a = b, 1 : 0;
}
template ... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long calc_m(long long n, long long x) {
long long ret = -1;
if ((6 * x - n + n * n * n) % (3 * n * (n + 1)) == 0) {
ret = (6 * x - n + n * n * n) / (3 * n * (n + 1));
}
return ret;
}
int main() {
long long x;
cin >> x;
long long n = 1;
vector<pair<l... | 5 |
#include <bits/stdc++.h>
using namespace std;
double num[105];
int cmp(double a, double b) { return a > b; }
int main(void) {
double a, b, x, tmpb, tmpa;
int n, i;
a = 1, b = 0;
scanf("%d", &n);
for (i = 0; i < n; i++) scanf("%lf", &num[i]);
sort(num, num + n, cmp);
for (i = 0; i < n; i++) {
x = num[i... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <class A>
void pr(A a) {
cout << a;
cout << '\n';
}
template <class A, class B>
void pr(A a, B b) {
cout << a << ' ';
pr(b);
}
template <class A, class B, class C>
void pr(A a, B b, C c) {
cout << a << ' ';
pr(b, c);
}
template <class A, class B, class ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1e3 + 7;
int n, a[N], T;
int f[N];
int main() {
scanf("%d", &T);
while (T--) {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
fill(f + 1, f + n + 1, -1);
f[0] = 0;
a[0] = 1e9;
for (int i = 1; i <= n; i++) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int arr[n];
for (int i = 0; i < n - 1; i++) cin >> arr[i];
int a, b;
cin >> a >> b;
int sum = 0;
for (int i = a - 1; i < b - 1; i++) sum += arr[i];
cout << sum << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n;
pair<int, int> a[4][N];
int nxt[4][N], pre[4][N];
void del(int p) {
for (int i = 0; i < 4; i++) {
int a = pre[i][p], b = nxt[i][p];
nxt[i][a] = b;
pre[i][b] = a;
}
}
bool dfs(vector<int> &left) {
if (left.size() <= 1) return 1;... | 8 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
register int x = 0, f = 0;
char ch = getchar();
while (!isdigit(ch)) f = (ch == 45), ch = getchar();
while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
return f ? (~x + 1) : x;
}
int n, m, k, ans = 0;
int f[20][20], num[20... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int calc2(int x) {
int tmp = 1;
while (x >= tmp) {
x -= tmp;
tmp <<= 1;
}
return x;
}
int n, rest, tot;
pair<int, int> save[1000000];
void run(int index, int now, int flg) {
save[index] = make_pair(now, flg);
if ((index << 1) ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<int, int> > good, piece, bad;
vector<string> a;
string s;
char b[110][110];
int main() {
cin >> n;
int cent = n - 1;
for (int i = 0; i < 2 * n - 1; ++i) {
for (int j = 0; j < 2 * n - 1; ++j) b[i][j] = 'x';
}
for (int i = 0; i < n; ++i) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e3 + 10;
int n, k, dp[maxn][maxn];
char s[maxn][maxn];
bool vis[maxn][maxn];
queue<pair<int, int>> q1, q2;
int main() {
scanf("%d %d", &n, &k);
for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1);
int mx = 0;
for (int i = 1; i <= n; i++) {
for (... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> a(10);
for (int i = 0; i < 6; i++) {
int u;
cin >> u;
a[u]++;
}
int leg = 0;
int head = 0;
int body = 0;
for (int i = 1; i < 10; i++) {
if (a[i] == 4) {
leg = i;
} else if (a[i] == 5) {
leg = i;
bo... | 1 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
template <class T>
inline T max(T a, T b, T c) {
return max(a, max(b, c));
}
template <class T>
inline T min(T a, T b, T c) {
return min(a, min(b, c));
}
template <class T>
inline T max(T a, T b, T c, T d) {
return max(a, max(b, c, d));
}
te... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
inline long long 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 * 10 + ch - '0';
ch = getchar();
}
retur... | 3 |
#include <bits/stdc++.h>
inline void in(int &MAGNUS) { scanf("%d", &MAGNUS); }
inline void out(int MAGNUS) { printf("%d\n", MAGNUS); }
inline void in(int &MAGNUS, int &CLAR) { scanf("%d%d", &MAGNUS, &CLAR); }
inline void out(int MAGNUS, int CLAR) { printf("%d %d\n", MAGNUS, CLAR); }
inline void inl(long long &LIV) { sc... | 7 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T sqr(T t) {
return t * t;
}
inline void files() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
const long long MOD = 1e9 + 7;
long long dp[200100], n, ans;
long long pow(long long n, long long m) {
long long ans = 1;
whi... | 7 |
#include <bits/stdc++.h>
using namespace std;
signed long long N, AA, CF, CM, M;
pair<signed long long, int> A[101010];
signed long long S[101010];
int R[101010];
void solve() {
int i, j, k, l, r, x, y;
string s;
cin >> N >> AA >> CF >> CM >> M;
for (i = 0; i < (N); i++) cin >> A[i].first, A[i].second = i;
so... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> a(n);
vector<pair<int, int>> ans;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<bool> vis(n, false);
for (int i = 0; i < n; i++) {
for (int j = 0... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100 + 7;
int a[N];
int main() {
int n, k;
cin >> n >> k;
for (int i = 0; i < n; i++) cin >> a[i];
int l = -1, r = -1;
for (int i = 0; i < n; i++)
if (a[i] > k) {
l = i;
break;
}
for (int i = 0; i < n; i++)
if (a[i] > k) r = ... | 0 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(1234);
const long long maxn = 200007;
const long long inf = LLONG_MAX / 4;
long long n;
long long a[maxn], b[maxn];
set<long long> s;
unordered_map<long long, long long> mp;
unordered_map<long long, long long> le[15], ri[15];
bool vis[maxn];
signed main() {
io... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n;
set<pair<pair<int, int>, int> > st;
pair<int, int> s[300005];
void init() { scanf("%d", &n); }
vector<pair<pair<int, int>, int> > v, t;
vector<int> ans;
set<pair<int, int> > aset;
void process() {
st.insert(pair<pair<int, int>, int>(pair<int, int>(0, 100000), -1));... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 9223372036854775807;
const long long N = 500005;
const long long mod = 1e9 + 7;
void start();
struct p {
long long a, b;
};
bool comp1(p p1, p p2) {
if (p1.a < p2.a) {
return true;
}
if (p1.a == p2.a) {
return (p1.b < p2.b);
}
};
stru... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
struct fenwickTree {
int tree[MAXN];
fenwickTree() { this->Init(); }
void Init() { memset(this->tree, 0, sizeof(this->tree)); }
void update(int index, int value) {
index++;
while (index < MAXN) {
this->tree[index] += value;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 100001;
const long long MOD = 1000000007;
const long long INF = LLONG_MAX;
long long bigmod(long long base, long long p) {
long long res = 1;
while (p) {
if (p & 1) res = (res * base) % MOD;
p >>= 1;
base = (base * base) % MOD;
}
retu... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e6 + 100;
const long long INF = 9 * (long long)(1e18);
const long double PI = 3.14159265358979323846;
long long int modexp(long long int x, long long int y, long long int p) {
long long int res = 1;
x = x % p;
if (y == 0)
return 1;
else if (x... | 6 |
#include <bits/stdc++.h>
long long fun(long long x) {
x++;
while (!(x % 10)) x /= 10;
return x;
}
int main() {
long long x, i;
scanf("%lld", &x);
if (x < 10) {
printf("9");
return 0;
}
for (i = 0;; i++) {
x = fun(x);
if (x < 10) {
i += 10;
break;
}
}
printf("%lld", i)... | 1 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n;
cin >> n;
vector<long long> a(n);
for (long long i = 0; i < n; i++) cin >> a[i];
long long s = 0, x = 0;
for (long long y : a) {
s += y;
x ^= y;
}
vector<long long> ans;
long long large = 1ll << 50;
if (s % 2) large++;... | 3 |
#include <bits/stdc++.h>
int compare(const void *a, const void *b) {
int ia = *(int *)a;
int ib = *(int *)b;
return ia - ib;
}
int main() {
int i, j, n, k, q, same, cnt, min, max, sum;
static int aa[100], used[100];
scanf("%d%d", &n, &k);
for (i = 0; i < n; i++) scanf("%d", &aa[i]);
scanf("%d", &q);
m... | 5 |
#include <bits/stdc++.h>
using namespace std;
struct art {
int t, d, p, id;
} a[101];
pair<int, int> go[101][2001];
bool cmp(art xx, art yy) { return xx.d < yy.d; }
int f[101][2001], num[101][2001], ans[1000], tt;
int main() {
int n;
cin >> n;
for (register int i = 1; i <= n; i++)
cin >> a[i].t >> a[i].d >>... | 6 |
#include <bits/stdc++.h>
using namespace std;
int u[4] = {0, 0, -1, 1};
int v[4] = {-1, 1, 0, 0};
int n, m, c;
string a[55];
int bio[55][55];
void dfs(int x, int y, int prevx, int prevy) {
bio[x][y] = 1;
for (int i = 0; i < 4; i++) {
int nx = x + u[i];
int ny = y + v[i];
if (nx < 0 || ny < 0 || nx >= n ... | 3 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
int h1[100110], h2[100110], h[100110];
int n;
int main() {
cin >> n;
for (int i = 1; i <= n; ++i) cin >> h[i];
int ans = 0;
h1[0] = 0;
for (int i = 1; i <= n; ++i) h1[i] = min(h[i], h1[i - 1] + 1);
h2[n + 1... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
long long int max = 0;
long long int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
for (int i = 0; i < n; i++) {
if (a[i] >= max + 1) max++;
}
cout << max + 1 << "\n";
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
n++;
vector<int> x(n), y(n);
for (int i = 0; i < n; i++) cin >> x[i] >> y[i];
int way = 1;
int ans = 0;
for (int i = 2; i < n; i++) {
if (x[i] == x[i - 1]) {
if (y[i] > y[i - 1]) {
if (way == 2) ans++;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
long n, m;
long a, b;
long gcd(int a, int b) {
int c;
while (a != 0) {
c = a;
a = b % a;
b = c;
}
return b;
}
int main() {
cin >> m >> n;
cout << (5 + 6 * m - 6) * n << endl;
cout << 1 * n << ' ' << 2 * n << ' ' << 3 * n << ' ' << 5 * n << endl;
... | 5 |
#include <bits/stdc++.h>
const int MOD = 1E9 + 7;
const long long N = 3e5 + 15;
const int maxn = 5e5 + 15;
const int letter = 130;
const int INF = 1e17;
const double pi = acos(-1.0);
const double eps = 1e-10;
using namespace std;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int moves[][2] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}};
class Point {
public:
Point() {}
Point(double x, double y) {
this->x = x;
this->y = y;
}
double dist(Point p) {
double x = p.x - this->x;
double y = p.y - this->y;
return sqrt(x * x + y ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int t = 0;
int a[100100];
int n, m, o, q, v, x, y;
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= m; i++) {
cin >> o;
if (o == 3) {
cin >> q;
cout << a[q] + t << endl;
}
if (o == 2) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long mx(long long a, long long b) {
if (a > b)
return a;
else
return b;
}
long long mn(long long a, long long b) {
if (a < b)
return a;
else
return b;
}
long long cei(long long a, long long b) {
if (a % b == 0)
return a / b;
else
ret... | 3 |
#include <bits/stdc++.h>
using namespace std;
int v[1100][1100];
int main() {
int n, k;
cin >> n >> k;
if (n > k + k) {
cout << n * k << endl;
for (int i = 1; i <= n; i++) {
int t = k;
for (int j = 1; j <= n; j++)
if (i != j && !v[i][j] && !v[j][i] && t) {
t--;
v[i]... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base ::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
std::vector<string> v(n);
for (long long int i = 0; i < n; i++) {
cin >> v[i];
}
if (n > 3) {
cout << "-1\n";
return 0;
}
if (n == 1) {
cout << "0\n";
re... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x20202020;
const int mod = 1000000007;
template <class T>
inline void read(T &first) {
bool fu = 0;
char c;
for (c = getchar(); c <= 32; c = getchar())
;
if (c == '-') fu = 1, c = getchar();
for (first = 0; c > 32; c = getchar()) first = first... | 9 |
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <functional>
using namespace std;
typedef long long ll;
using pii = pair<int, int>;
const int inf = 0x3f3f3f3f;
const vector<pii> direction = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
int main(){
ios_base::sync_with... | 7 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
int dp1[500000 + 5];
int dp2[500000 + 5];
int dp3[500000 + 5];
int n, a, b, T;
char s[500000 + 5];
int main() {
while (~scanf("%d%d%d%d", &n, &a, &b, &T)) {
scanf("%s", s);
memset(dp1, 0, sizeof(dp1));
mems... | 5 |
#include <bits/stdc++.h>
using namespace std;
constexpr int mxn = 1e5;
int n, a, b, max_child[mxn][3], max_parent[mxn];
bool can_turn[mxn];
vector<int> adj[mxn], body;
int dfs1(int u, int p = -1) {
if (~p && (int)adj[u].size() < 2) return max_child[u][0] = 1;
for (int v : adj[u])
if (v != p) {
int len = d... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long long MAX = 1e6 + 8;
const long long MOD = 1e9 + 7;
const long long sz = 1e5 + 5;
void f_io() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
}
long long power(long long a, long long b) {
if (!b) return 1;
if (b == 1) return a;
if (b & 1) retur... | 6 |
#include <bits/stdc++.h>
using namespace std;
#define BUFF ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define ll long long
inline ll read(){ll f=1;ll x=0;char ch=getchar();while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}while(... | 5 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
long long int gcd(long long int a, long long int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long int gcdExtended(long long int a, long long int b, long long int *x,
long long int *y) {
if (a == 0) {
*x = ... | 5 |
#include <bits/stdc++.h>
using ld = long double;
using ll = long long;
using uint = unsigned int;
using ull = unsigned long long;
using namespace std;
using pii = pair<int, int>;
using pld = pair<ld, ld>;
using pll = pair<ll, ll>;
template <class T>
using minpq = priority_queue<T, vector<T>, greater<T>>;
template <clas... | 4 |
#include <bits/stdc++.h>
using namespace std;
int ans[2000005];
int main() {
ios_base::sync_with_stdio(false);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
string s;
cin >> s;
vector<pair<int, int>> vec;
for (int i = 0; i < n; i++) {
vec.push_back({s[i], i});
}
sort(vec.... | 3 |
#include <bits/stdc++.h>
using namespace std;
int tasks[2010], taskd[2010], taskc[2010], n, k;
inline void scanint(int &x) {
register int c = getchar();
x = 0;
int neg = 0;
for (; ((c < 48 || c > 57) && c != '-'); c = getchar())
;
if (c == '-') {
neg = 1;
c = getchar();
}
for (; c > 47 && c < ... | 8 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
vector<pair<int, int>> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i].first;
v[i].second = i;
}
string s;
cin >> s;
sort(v.begin(), v.end());
int result = n;
for (int i = n - 1; i >= 0; i--) {
if (s[v[i].secon... | 1 |
#include <bits/stdc++.h>
using namespace std;
struct P {
int first, second, index;
};
const int Max = 3e5 + 10;
P seg[Max];
bool cmp(P a, P b) {
if (a.first <= b.first) {
if (a.first == b.first)
return a.second > b.second;
else
return 1;
} else
return 0;
}
int main() {
ios::sync_with_std... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chkmin(T &a, const T &b) {
return a > b ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
return a < b ? a = b, 1 : 0;
}
const int INF = 0x3f3f3f3f;
template <class T>
inline bool RD(T &ret) {
char c;
in... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
for (int i = 1; i <= k + 1; i++)
cout << ((i % 2) == 0 ? (k + 1 - i / 2) : (i / 2)) + 1 << " ";
for (int i = k + 2; i <= n; i++) cout << i << " ";
cout << endl;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5, L = 18;
int a[MAXN], N, Q;
pair<int, int> t[MAXN][L];
pair<int, int> query(int i, int j) {
j++;
int l = 31 - __builtin_clz(j - i);
return max(t[i][l], t[j - (1 << l)][l]);
}
long long solve(int i, int j) {
if (i > j) return 0;
int k = query(i... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2000010;
long long A[22][100010], a[maxn], n, m, f[maxn], g[maxn], len;
void FWTxor(long long *A, long long ty) {
for (long long mid = 1; mid < len; mid <<= 1)
for (long long j = 0, R = mid << 1; j < len; j += R)
for (long long k = 0; k < ... | 9 |
#include <bits/stdc++.h>
const int N = 63;
long long dp[N * N][2];
int cnt, n, m, x[N], y[N];
std::map<int, int> f;
int solve(long long x) {
int res = 0;
while (x) res += x & 1, x >>= 1;
return res;
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) scanf("%d", x + i);
for (int i = 0; i < m; ... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long solve();
vector<long long> a;
string s;
long long n;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
long long in(vector<long long> &a, long long n) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100000 + 3, MAX_Q = 100000 + 3;
struct Edge {
int from, to;
Edge(int from, int to) : from(min(from, to)), to(max(from, to)) {}
bool operator<(const Edge &e) const {
return from < e.from || (from == e.from && to < e.to);
}
};
struct Data {
int... | 8 |
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long double eps = 1e-7;
const int inf = 1000000010;
const long long INF = 10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 1000010, LOG = 20;
int n, m, k, u, v, x, y, t, a, b, ans = 1;
in... | 5 |
#include <bits/stdc++.h>
int main() {
long long x;
scanf("%lld", &x);
int y = x % 10;
if (y >= 5) {
int more = 10 - y;
x += more;
} else if (y < 5 && y != 0) {
x -= y;
}
printf("%lld", x);
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
bool arr[100001];
int main() {
string s;
cin >> s;
int n = s.length();
memset(arr, false, sizeof(arr));
int i;
for (i = 0; i < n - 1; i++) {
if (s[i] == 'A' && s[i + 1] == 'B') {
arr[i] = true;
arr[i + 1] = true;
break;
}
}
if (i ==... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5;
int n;
char s[maxn + 1];
int main(void) {
scanf("%d%s", &n, s);
int x = 0, y = 0, side = -1, ans = 0;
for (int i = 0; i < n; ++i) {
if (s[i] == 'U') {
++y;
} else {
++x;
}
if (x > y) {
if (side == 1) {
++... | 0 |
#include <bits/stdc++.h>
int main() {
int x = 0, y = 0, a, b, sum = 0, t = 1, i;
scanf("%d%d", &a, &b);
if (a == b && b == 0 || a == 1 && b == 0)
printf("0\n");
else {
for (i = 1;; i++) {
if (x + t == a && y == b || x + t > a && y == b && a > x) {
printf("%d\n", sum);
break;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int q;
double med, aux, n, soma, i;
scanf("%d", &q);
while (q > 0) {
soma = 0;
scanf("%lf", &n);
for (i = 0; i < n; i++) {
scanf("%lf", &aux);
soma = soma + aux;
}
med = ceil(soma / n);
printf("%.0lf\n", med);
q--... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
int n, m, d, a[MAXN], b[MAXN], t[MAXN];
long long dp[2][MAXN], lt;
long long r[MAXN];
void getmini(bool c, long long mv) {
deque<pair<int, long long> > mn;
for (int i = 0; i < n; i++) {
while (!mn.empty() && i - mn.front().first > mv) mn.p... | 6 |
#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
using namespace std;
inline int read() {
int x = 0, neg = 1;
char op = getchar();
while (!isdigit(op)) {
if (op == '-') neg = -1;
op = getchar();
}
while (isdigit(op)) {
x = 10 * x + op - '0';
op = getchar();
}
return... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string pas;
int n;
cin >> pas >> n;
set<char> b, e;
string aux;
for (int i = 0; i < n; i++) {
cin >> aux;
if (aux == pas) {
cout << "YES\n";
return 0;
}
b.insert(aux[0]);
e.insert(aux[1]);
}
if (b.find(pas[1]) != ... | 0 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:10000000000")
using namespace std;
const int INF = 1000000007;
const long long INF2 = 1000000000000000007;
const long long MOD = 1000000007;
const long long MOD1 = 1864463441;
const int SIZE = 200010;
const double eps = 1e-9;
const long double pi = acos(-1.0);
lo... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
int arr[100][100];
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cin >> arr[i][j];
}
}
int counter = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <=... | 0 |
#include <bits/stdc++.h>
using namespace std;
map<long long, long long> mp;
int main() {
long long q, op, u, v, w, ans;
for (cin >> q; q--;) {
cin >> op >> u >> v;
if (op == 1) {
cin >> w;
while (u != v) {
if (u < v) swap(u, v);
mp[u] = mp[u] + w;
u /= 2;
}
} el... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200019;
int n, m, N, ans, base;
bool appear[maxn];
int cnt[maxn];
int factor[200];
int f[200];
int pre[200];
vector<int> num[maxn];
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
void init() {
int temp;
cin >> n >> m;
for (int i = 0; i <... | 7 |
#include <bits/stdc++.h>
using namespace std;
bool cmp(int a, int b) { return a > b; }
int main() {
int n;
cin >> n;
int *a = new int[n];
int sum = 0;
for (int i = 0; i != n; i++) {
cin >> a[i];
sum += a[i];
}
sort(a, a + n, cmp);
int x = 0;
for (int i = 0; i != n; i++) {
x += a[i];
if... | 0 |
#include <bits/stdc++.h>
const long long INF = 2000000005;
const long long BIG_INF = 2000000000000000005;
const long long mod = 1000000007;
const long long P = 31;
const long double PI = 3.141592653589793238462643;
const double eps = 1e-9;
using namespace std;
vector<pair<long long, long long> > dir = {{-1, 0}, {0, 1},... | 7 |
#include <bits/stdc++.h>
using namespace std;
bool isrange(int second, int first, int n, int m) {
if (0 <= second && second < n && 0 <= first && first < m) return true;
return false;
}
int dy[4] = {1, 0, -1, 0}, dx[4] = {0, 1, 0, -1},
ddy[8] = {1, 0, -1, 0, 1, 1, -1, -1}, ddx[8] = {0, 1, 0, -1, 1, -1, 1, -1};
i... | 2 |
#include <bits/stdc++.h>
const double PI = acos(-1.0);
using namespace std;
int a[100010];
int main() {
int CASE;
scanf("%d", &CASE);
while (CASE--) {
long long n, k, d1, d2;
scanf("%I64d %I64d %I64d %I64d", &n, &k, &d1, &d2);
if (n % 3 != 0) {
printf("no\n");
continue;
}
if ((k - ... | 4 |
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define pb push_back
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define pii pair<int,int>
#define vpii vector<pii>
#define rep(i,n) for(int... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string x;
cin >> x;
for (int i = 0; i < x.size(); i++) {
if (x[i] == 'H' || x[i] == 'Q' || x[i] == '9') {
cout << "YES";
return 0;
}
}
cout << "NO";
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
map<int, int> pos1;
map<int, int> pos2;
int n;
cin >> n;
int a[n], b[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
pos1[a[i]] = i;
}
for (int i = 0; i < n; i++) {
cin >> b[i];
pos2[b[i]] = i;
}
map<int, int> h;
for (int i ... | 3 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
long long int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
long long int calculations[n], ans = 1, mini = INT_MAX;
for (int i = 0; i < n; i+... | 2 |
#include <bits/stdc++.h>
using namespace std;
inline int rd() {
int x = 0;
char c = getchar();
bool f = 0;
while (c < '0' && c != '-') c = getchar();
if (c == '-') f = 1, c = getchar();
while (c >= '0') x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
return f ? -x : x;
}
const int SIZE = 5e5 + 100;
int... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MAXn = 200 + 10, MOD = 1e9 + 7;
vector<int> g[MAXn];
int n, cnt[MAXn], h[MAXn], p[MAXn];
long long dp[MAXn][MAXn], res, invN, inv2;
vector<int> dfsStack;
void dfs(int v, int par, int height) {
cnt[v] = 1;
h[v] = height;
p[v] = par;
for (int u : g[v]) {
if (u... | 7 |
#include <bits/stdc++.h>
using namespace std;
int arr[51][51] = {0};
int main() {
int n, r, a, b, ct = 0, flag = 0, p, i, j;
scanf("%d%d", &n, &p);
for (i = 0; i < n; i++) {
scanf("%d%d", &a, &b);
arr[a][b]++;
}
for (i = 50; i >= 0; i--) {
for (j = 0; j < 51; j++) {
ct += arr[i][j];
if... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
bool ans = true;
char cur = 'a';
for (auto it : s) {
if (it > cur) {
ans = false;
break;
} else if (it == cur)
cur++;
}
if (ans)
cout << "YES";
else
cout << "NO";
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 120;
bitset<MAXN + 6> s;
int ans;
int cntv[MAXN + 6];
int t, m, n;
void DFS(bitset<MAXN + 6> a, int cur, long long mulv) {
ans = (ans + mulv) % MOD;
for (int i = cur; i <= m >> 1; ++i)
if (cntv[i] && !a[i] && !a[m - i])
... | 10 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")
char s[(100000 + 10)], x[(100 + 10)], y[(100 + 10)];
int ch[(100000 + 10)][10], val[(100000 + 10)];
int nxt[(100000 + 10)];
int tot;
int dp[55][(100000 + 10)][2][2][2];
void init() {
memset(ch[0], -1, sizeof ch[0]);
... | 12 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")
const double pi = acos(-1.0), eps = 1e-8;
const int maxm = 1100000, inf = 0x3f3f3f3f;
bool f[maxm];
vector<int> v[maxm];
int top, st[maxm];
int a[maxm];
void dfs(int x, int pre) {
f[x] = true;
int i;
a[x] ^= 1;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5, M = 1e5 + 5;
int a, b, m, d, cnt, degree[N << 1], last[N << 1], used[N << 1][N << 1];
struct edge {
int y, last;
} E[M << 1];
struct node {
int x, y, color;
} nd[M];
void link(int x, int y) {
E[cnt] = (edge){y, last[x]}, last[x] = cnt++, ++degre... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
list<int> l;
list<int>::iterator it = l.end();
int n;
scanf("%d", &n);
string s;
cin >> s;
for (int i = 0; i < s.size(); i++) {
l.insert(it, i + 1);
if (s[i] == 'l') it--;
}
for (it = l.begin(); it != l.end(); it++) printf("%d\n", *it)... | 2 |
#include <bits/stdc++.h>
using namespace std;
int a[100004];
int main() {
int n;
cin >> n;
string s;
cin >> s;
int a = 1;
int i = 2;
vector<char> v;
while (1) {
if ((a - 1) >= s.size()) break;
v.push_back(s[a - 1]);
cout << s[a - 1];
a = a + i;
i++;
}
cout << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n, k, q;
int a[200000];
int cnt[1000001] = {};
int mul[1000001];
bool p[2000];
vector<int> pr;
const int MOD = 1e9 + 7;
vector<int> di[1000001];
int f[2000005], rf[2000005];
int binPow(long long x, int p) {
long long res = 1;
while (p) {
if (p & 1) res = res * x... | 8 |
#include<bits/stdc++.h>
#define For(a,b,c) for(int a=b;a<=c;++a)
#define Dor(a,b,c) for(int a=b;a>=c;--a)
#define CC(_...) fprintf(stderr,_)
using namespace std;
typedef long long LL;
enum{N=18,M=1<<N,oo=3<<28};
int n,m,W[N],E[M],F[M],G[M],S[M],O[M];
int main() {
scanf("%d%d",&n,&m);
For(i,1,m) {
int x,y,z;
scanf... | 9 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void debug(T a, T b) {
;
}
template <class T>
void chmin(T& a, const T& b) {
if (a > b) a = b;
}
template <class T>
void chmax(T& a, const T& b) {
if (a < b) a = b;
}
namespace std {
template <class S, class T>
ostream& operator<<(ostream& out, cons... | 9 |
#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... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int D[4][2] = {{1, 0}, {0, 1}, {0, -1}, {-1, 0}};
struct pt {
int x, y;
bool in() { return 0 <= x && x <= 300 && 0 <= y && y <= 300; }
} a[405], P[4], s, t, q[91005];
bool operator==(const pt& a, const pt& b) { return a.x == b.x && a.y == b.y; }
int n, p[91005], w... | 11 |
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<int, int>;
using PL = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, e... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long int tc, cnt = 0, number, many, total = 0;
int rmove[4] = {0, 0, -1, 1};
int cmove[4] = {1, -1, 0, 0};
long long int power(long long int x, long long int y, long long int mod) {
if (y == 0)
return 1;
else if (y % 2 == 0)
return (power(x, y / 2, mod) % m... | 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.