solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
int c;
long long int n;
cin >> c;
for (int i = 0; i < c; i++) {
cin >> n;
long long int d = n % 14;
long long int p = n / 14;
if (d >= 1 && d <= 6 && p != 0)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 9;
int res[MAX_N][2], point[MAX_N], num_s, st[MAX_N * 4], vis[MAX_N];
vector<int> vec[MAX_N];
int N, M, x;
bool dfs(int pos, int x) {
if (res[pos][x ^ 1] == 1) return false;
res[pos][x ^ 1] = 1;
st[num_s++] = pos;
if (vec[pos].size() == 0 && ... | 13 |
#include <bits/stdc++.h>
using namespace std;
char rev(char c) { return (c == 'a' ? 'b' : 'a'); }
int query(const string s) {
cout << s << "\n";
fflush(stdout);
int ret;
cin >> ret;
if (!ret) exit(0);
return ret;
}
int main() {
int n = query("a") + 1;
string s = "a";
for (int i = 1; i < n; ++i) s += "... | 15 |
#include <bits/stdc++.h>
using namespace std;
int n;
int sum[5000];
struct node {
int l, r, k;
};
struct hashmap {
long long hs[10000000];
int dt[10000000];
long long prehash(node p) {
return ((1ll * p.l * 10007 + p.r) * 10007 + p.k);
}
int find(node p) {
long long q = prehash(p);
int i = q % 10... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a, b;
for (int i = 0; i < n; i++) {
int b;
cin >> b;
a.push_back(b);
}
int cnt = 1;
for (int i = 0; i < a.size(); i++) {
if (a[i] == cnt) {
b.push_back(2001 + i);
cnt++;
}
}
cout << ... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <int MOD_> struct modnum {
static constexpr int MOD = MOD_;
static_assert(MOD_ > 0, "MOD must be positive");
private:
using ll = long long;
int v;
static int minv(int a, int m) {
a %= m;
assert(a);
return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) ... | 25 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, ret = 0;
multiset<long long int> unused, sold;
cin >> n;
for (int i = 0; i < n; i++) {
long long int v;
cin >> v;
auto it1 = unused.begin(), it2 = sold.begin();
if (it2 == sold.end()) {
if (it1 == unused.end() or (... | 16 |
#include <bits/stdc++.h>
using namespace std;
int n, sum, mask[256];
bool can[10], ok[256];
string str[256];
vector<int> nums;
vector<string> res;
int main() {
ios::sync_with_stdio(false);
cin >> n;
if (n >= 7) {
cout << 0 << endl;
return 0;
}
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const long long inf64 = 1e18;
struct RangeTree {
int n = 0;
vector<int> t;
RangeTree() = default;
RangeTree(int nn) : n(nn) { t.resize(4 * n, inf); }
void upd(int v, int x) { t[v] = min(t[v], x); }
void push(int v) {
upd(v << 1, t[v]);
... | 27 |
#include <bits/stdc++.h>
using namespace std;
int a, b, m, r, d[100005];
int DFS(int x) {
if (d[(x * a + b) % m]) {
return d[x] - d[(x * a + b) % m] + 1;
}
d[(x * a + b) % m] = d[x] + 1;
return DFS((x * a + b) % m);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> a >> b ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, a[300005], pre[300005], nxt[300005], c[300005], p0[100], p1[100];
bool cmp(const int &u, const int &v) { return a[u] < a[v]; }
double ans = 0, pw[100];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]), pre[i] = i - 1, nxt[i] = i +... | 18 |
#include <bits/stdc++.h>
using namespace std;
int Get() {
char c;
bool o = false;
while (!isdigit(c = getchar()))
if (c == '-') o = true;
int x = c - '0';
while (isdigit(c = getchar())) x = x * 10 + c - '0';
return o ? -x : x;
}
const int maxn = 2e2 + 7;
int f[maxn][maxn][maxn << 1];
int prei[maxn][maxn... | 14 |
#include <bits/stdc++.h>
using namespace std;
int dp[80][12000];
int q[150];
int main() {
int n, k, s;
scanf("%d %d %d", &n, &k, &s);
int sum = 0;
for (int i = 0; i < n; ++i) {
scanf("%d", &q[i]);
sum += q[i];
}
if (k == n) {
printf("%d\n", sum);
} else if (k < n / 2) {
s += k * (k + 1) / ... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5 * 1e5 + 7;
int n, m;
vector<int> g[maxn];
bool vis[maxn];
vector<int> ans[maxn];
int co;
struct node {
int u;
node *nxt;
} * head;
int sum;
void del(node *cmp) { cmp->nxt = cmp->nxt->nxt; }
void bfs() {
co++;
queue<int> q;
node *cmp;
cmp = hea... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int a[N], pos[N], len[N];
int main() {
int n;
while (cin >> n) {
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
int m = 0;
for (int i = 1; i < n; i++) {
if (a[i] <= a[i - 1]) {
pos[m++] = i - 1;
}
}
pos[m++... | 8 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int l, r, id;
node() {}
node(int a, int b, int c) {
l = a;
r = b;
id = c;
}
bool operator<(const node &t) const { return r < t.r; }
};
int n, sum[1000100], ar[1000100], ans[1000100], tree[1000100];
node temp[1000100];
map<int, int> mp;
vo... | 13 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const long long mod = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int T;
cin >> T;
for (int cs = 1; cs <= T; cs++) {
int n;
cin >> n;
set<int> st;
for (int i = 0; i < n; i++) {
... | 13 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> row[5005], col[5005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m, k;
cin >> n >> m >> k;
for (long long int i = 1; i <= 5001; i++) {
row[i] = {0, k};
col[i] = {0, k};
}
while (k--) {
int typ;
cin >> ty... | 4 |
#include <bits/stdc++.h>
using namespace std;
clock_t tp = clock();
const long long mod = 1e9 + 7;
long long int power(long long int a, long long int b) {
long long int ans = 1;
a = a;
while (b > 0) {
if (b & 1) ans = (ans * a);
b >>= 1;
a = (a * a);
}
return ans;
}
long long int power1(long long ... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
while (b) b ^= a ^= b ^= a %= b;
return a;
}
int main() {
std::ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
string s[n];
int c[m];
for (int i = 0; i < m; i++) c[i] = 0;
for (int i = 0; i < n; i++) {
ci... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int fa[N], ans[N], ct[N], vis[N], bl[2][N];
vector<int> p[N];
int main() {
int n, m;
scanf("%d%d", &n, &m), memset(ans, -1, sizeof(ans));
for (int i = 1; i <= n; i++) {
int k;
scanf("%d", &k), ct[i] = k;
for (int j = 1, a; j <= k; j++... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 550;
int main() {
string s;
cin >> s;
int ic = 0;
int l = s.size();
for (int i = l - 1; i >= 0; i--) {
if (s[i] == '0') ic++;
if (s[i] == '1' && ic >= 6) {
cout << "yes" << endl;
return 0;
}
}
cout << "no" << endl;
re... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t;
cin >> t;
while (t--) {
long long int n, m;
cin >> n >> m;
long long int a[n];
long long int s = 0;
for (long long int i = 0; i < n; i++) {
cin >> a[i];
s += a[i];
}
if (s > m) {
cout << m << ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int a[1000];
int b[1000];
int p[1001];
void doit() {
int n, k;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", a + i);
}
k = 0;
int o[2];
for (int i = 0; i < n; i++) {
scanf("%d", b + i);
if (a[i] != b[i]) {
o[k++] = i;
} else ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MAXM = (int)1e+5 + 5;
int n, m, ans = 0;
vector<vector<int> > g, have;
vector<int> color;
void dfs(int v, int p) {
vector<bool> used(m);
for (int i = 0; i < have[v].size(); i++) {
int now = have[v][i];
if (color[now] != 0) used[color[now]] = true;
}
... | 14 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long int a{}, b{}, min1{}, num1{}, max1{};
cin >> a >> b;
if (a == b) {
cout << a << " " << 0 << endl;
return;
}
if (a < b) {
min1 = a;
max1 = b;
} else {
min1 = b;
max1 = a;
}
num1 = max1 - min1;
num1 = num1 / 2... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n;
int m;
vector<int> days;
vector<int> subjects;
bool isPossible(int maxDays) {
vector<int> daysLeft = subjects;
vector<int> dayToDo(subjects.size() + 1);
deque<int> nextExam = deque<int>();
set<int> examDays;
int examsToDo = 0;
for (int d = maxDays - 1; d ... | 9 |
#include <bits/stdc++.h>
using namespace std;
double a[1010];
long long n;
long long judge(double k) {
long long flag = 0, p = -1;
for (long long i = 2; i <= n; i++) {
if (fabs(a[i] - a[1] - k * ((double)i - 1.0)) <= 1e-10) continue;
flag = 1;
if (p == -1) {
p = i;
continue;
}
if (fa... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = (1 << 18) + 5;
long long a[N];
long long o[4 * N];
int dep[30];
void build(int l, int r, int rt) {
if (l == r) {
o[rt] = a[l];
return;
}
int mid = (l + r) >> 1;
build(l, mid, rt << 1);
build(mid + 1, r, rt << 1 | 1);
o[rt] = o[rt << 1] + o[... | 16 |
#include <bits/stdc++.h>
using namespace std;
int n, k, cnt;
bool check(int x, int y) {
if (x % 2 == 0) return 0;
if (y == 0) {
if (x & (x + 1))
return 0;
else
return 1;
}
if (y == 1) {
if (x & (x + 1))
return 1;
else
return 0;
}
if (x == 9 && y == 2) return 0;
retu... | 20 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
float d, l, v1, v2;
cin >> d >> l >> v1 >> v2;
double ans = (l - d) / (v1 + v2);
cout << setprecision(10) << ans;
return 0;
}
| 0 |
#include <bits/stdc++.h>
int col8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int row8[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int col4[4] = {1, 0, -1, 0};
int row4[4] = {0, 1, 0, -1};
using namespace std;
template <class T>
T sqr(T a) {
return a * a;
}
template <class T>
T power(T n, T p) {
T res = 1;
for (int i = 0; i < p; i++... | 13 |
#include <bits/stdc++.h>
using namespace std;
template <class T1>
void deb(T1 e) {
cout << e << endl;
}
template <class T1, class T2>
void deb(T1 e1, T2 e2) {
cout << e1 << " " << e2 << endl;
}
template <class T1, class T2, class T3>
void deb(T1 e1, T2 e2, T3 e3) {
cout << e1 << " " << e2 << " " << e3 << endl;
}
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int hea[maxn], nxt[maxn * 100], to[maxn * 100], w[maxn * 100], dis[maxn * 100],
f[maxn], tot;
void add(int a, int b, int c) {
nxt[++tot] = hea[a];
hea[a] = tot;
to[tot] = b;
w[tot] = c;
}
priority_queue<pair<int, int>, vector<pair<int, i... | 14 |
#include <bits/stdc++.h>
using namespace ::std;
int main() {
char* a = new char[200001];
char* b = new char[200001];
long long int i, j, k, l, value, as1, as2, n;
long long int count[26][26];
long long int uni[26];
for (i = 0; i < 26; i++) {
uni[i] = 0;
for (j = 0; j < 26; j++) count[i][j] = 0;
}
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int len, n, m, size[1000000], wen[1000000], nex[1000000], hea[1000000],
fa[100005][20], dep[1000000];
void add(int x, int y) {
++len;
nex[len] = hea[x];
wen[len] = y;
hea[x] = len;
}
void dfs(int x, int y) {
size[x] = 1;
fa[x][0] = y;
dep[x] = dep[y] + 1;
... | 13 |
#include <bits/stdc++.h>
using namespace std;
const double PI = 3.141592654;
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
int dx[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dy[] = {1, -1, 0, 0, 1, 1, -1, -1};
void fast() {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const double PI = 2.0 * acos(0.0);
const double EPS = 1e-6;
int a[105], b[105];
void setup(int n, int *arr) {
if (n == 1)
arr[0] = 1;
else if (n == 2)
arr[0] = 3, arr[1] = 4;
else if (n & 1) {
arr[0] = 2;
for (int i = 1; i < n - 1; i++) arr[i] = 1;
... | 16 |
#include <bits/stdc++.h>
using namespace std;
int readint() {
char c;
while (c = getchar(), (c < '0' || c > '9') && c != '-')
;
bool flag = (c == '-');
if (flag) c = getchar();
int x = 0;
while (c >= '0' && c <= '9') {
x = x * 10 + c - 48;
c = getchar();
}
return flag ? -x : x;
}
int n, h;
i... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, m, a[5010], b[5010];
int Cnt[300];
char s[5010];
void Init() {
scanf("%s", s + 1);
n = strlen(s + 1);
for (int i = 1; i <= n; ++i) a[i] = s[i];
scanf("%s", s + 1);
m = strlen(s + 1);
for (int i = 1; i <= m; ++i) b[i] = s[i];
b[m + 1] = -1;
}
void Solve(... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long double EPS = 1e11;
const long long INFL = 1e16;
const int INF = 1e9 + 7;
mt19937 rnd((unsigned)chrono::steady_clock::now().time_since_epoch().count());
void solve() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i <... | 12 |
#include <bits/stdc++.h>
#pragma GCC optimize(3, "Ofast", "inline")
using namespace std;
namespace FastIO {
char buf[1 << 21], buf2[1 << 21], a[20], *p1 = buf, *p2 = buf, hh1 = '\n',
hh2 = ' ';
int p, p3 = -1;
void read() {}
void print() { buf2[p3] = hh1; }
inline int getc() {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a;
cin >> a;
int res = 0;
vector<int> nums;
int de = 0;
for (int i = 2; i < a; i++) {
int temp = a;
while (temp > 0) {
nums.push_back(temp % i);
temp = temp / i;
}
for (int j = 0; j < nums.size(); j++) res += nums.at(... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const int mod = 1000000007;
void slv() {
int N, M;
cin >> N >> M;
vector<int> g[M + 1];
for (int i = 1; i <= M; i++) {
int val = i;
g[i].push_back(val);
int n = N - 1;
while (n--) {
val += M;
g[i].push_back(val);
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2017;
const int M = 2e6 + 7;
int p[N], s[N], n, pos[N], u[M], v[M], top = 0, ans = 0;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &p[i]);
for (int i = 1; i <= n; i++) scanf("%d", &s[i]), pos[s[i]] = i;
for (int i = 1; i <= n;... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7, mz = 1e9 + 7, inf = 0x3f3f3f3f;
char s[110], a[100], b[100];
int main() {
int n, m, l, r;
cin >> n >> m;
scanf("%s", s + 1);
while (m--) {
scanf("%d%d%s%s", &l, &r, a, b);
for (int i = l; i <= r; i++)
if (s[i] == a[0]) s[i] = b[0... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int test;
cin >> test;
while (test--) {
int n;
int p;
cin >> n >> p;
int count = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (count < 2 * n + ... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
if (a == 0) return b;
return gcd(b % a, a);
}
long long int exp(long long int x, long long int y, long long int p) {
long long int res = 1;
x = x % p;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y =... | 5 |
#include <bits/stdc++.h>
using namespace std;
char in[200005];
int main() {
long long n;
scanf("%lld", &n);
scanf("%s", in);
bool same = true;
for (int i = 0; i < n; i++) {
if (in[i] != in[0]) {
same = false;
}
}
if (same) {
printf("%lld\n", (n + 1) * n / 2 % 998244353);
return 0;
... | 5 |
#include<bits/stdc++.h>
using namespace std;
const int N=1000005;
int T,n,x,a[N],cnt[N],q;
long long k;
int main(){
scanf("%d",&T);
while (T--){
scanf("%d",&n);
for (int i=1;i<=n;i++){
scanf("%d",&x);
a[i]=1;
for (int j=2;j*j<=x;j++)
if (x%j==0){
int flag=0;
while (x%j==0)x/=j,flag^=1;
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
vector<long long> f;
vector<pair<long long, int> > head[N], tail[N];
inline int min(const int &a, const int &b) { return a > b ? b : a; }
int dist(const long long a, const long long b, const int n) {
if (a == b) {
return 0;
}
if (a == b - 1) {
... | 18 |
#include <bits/stdc++.h>
using namespace std;
int dp[3001][3001];
int n, m, t, ans, a, b;
vector<int> jun[3001];
int main() {
ios::sync_with_stdio(0);
cin >> n >> m;
for (int i = 0; i < 3001; i++) {
for (int j = 0; j < 3001; j++) dp[i][j] = 0;
}
while (m--) {
cin >> a >> b;
a--;
b--;
jun[a... | 9 |
#include <bits/stdc++.h>
using namespace std;
int i, j, pos, l, r, la, ra, mn = 2000000000, mx = -2000000000, n, q, w,
mxx = -2000000000;
int main() {
cin >> n;
for (i = 1; i <= n; i++) {
cin >> l >> r;
mn = min(l, mn);
mx = max(r, mx);
if (r - l > mxx) {
mxx = r -... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
cin >> T;
while (T--) {
int sz;
cin >> sz;
string str1, str2;
cin >> str1 >> str2;
if (str1 == str2) {
cout << 0 << endl;
continue;
}
vector<int> res1, res2;
for (int i = 0; i < sz - 1; i++) {
if (s... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x = 0, y;
int res = 0;
string s;
cin >> s;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '(')
x++;
else if (x > 0) {
x--;
res += 2;
}
}
cout << res;
return 0;
}
| 6 |
#include <bits/stdc++.h>
int main() {
char time[6];
int minute, hour;
scanf("%s %d", time, &minute);
minute = minute + ((time[4] - '0') + (time[3] - '0') * 10);
hour = (time[1] - '0') + (time[0] - '0') * 10;
hour = hour + minute / 60;
minute = minute % 60;
hour = hour % 24;
if (hour < 10) printf("0");... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, t, x, y, ans1, ans, cnt1, cnt2;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d%d%d", &t, &x, &y);
if (t == 1) {
cnt1++;
ans += x;
} else {
cnt2++;
ans1 += x;
}
}
if (ans >= cnt1 * 5)
puts("LI... | 0 |
#include<bits/stdc++.h>
#include<vector>
#define endl "\n";
typedef long long int ll;
using namespace std;
int main()
{ ll t;
cin>>t;
while(t--)
{
ll n,m,x,l,a,ans;
cin>>n>>m>>x;
if(n*m==x){
cout<<n*m<<endl;}
else{
l=x/n;
a=x%n;
if(a==0){
a=n-1;
ans=l+a*m;}
else {
a=a-1;
ans=l+a*m+1;}
cout<<ans<<endl... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void _R(T &x) {
cin >> x;
}
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template <class ... | 17 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int main() {
scanf("%d%d", &n, &m);
long long last = 0, sum = 0;
for (int i = 0; i < n; ++i) {
int x;
scanf("%d", &x);
sum += x;
long long d = sum / m;
printf("%I64d ", d - last);
last = d;
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
map<int, pair<char, int> > inMap;
map<int, pair<char, int> >::iterator itlow;
int N, Q, i, x, y, ans;
string type;
int main() {
cin >> N >> Q;
inMap[0] = {'U', 0};
inMap[N + 1] = {'L', 0};
for (i = 1; i <= Q; ++i) {
cin >> x >> y >> type;
itlow = inMap.lower... | 14 |
#include <bits/stdc++.h>
typedef struct {
int l;
int r;
} array;
typedef struct {
int ind;
int num;
} arr;
int cmp(const void *x, const void *y) {
arr *bx = (arr *)x;
arr *by = (arr *)y;
return ((bx->num) - (by->num));
}
int cmp2(const void *x, const void *y) {
array *ax = (array *)x;
array *ay = (arr... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
template <class T>
void _R(T &x) {
cin >> x;
}
void _R(int &x) { cin >> x; }
void _R(int64_t &x) { cin >> x; }
void _R(double &x) { cin >> x; }
void _R(long double &x) { cin >> x; }
void _R(char &x) { cin >> x; }
void _R(char *x) { cin >>... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, m, maxl, step, tmp;
string s, t;
int main() {
cin >> n >> m;
cin >> s >> t;
for (int i = 0; i <= m - n; i++) {
tmp = 0;
for (int j = 0; j < n; j++) {
if (s[j] == t[i + j]) {
tmp++;
}
}
if (tmp > maxl) {
maxl = tmp;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
long long int n;
cin >> n;
vector<long long int> v(n);
for (long long int i = 0; i < n; i++) v[i] = i + 1;
for (long long int i = 0; i < n / 2; i++)
cout << v[i] << " " << v[n - i - 1] <<... | 4 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef struct info_ {
ll num;
ll idx;
ll cnt;
} info;
bool sort_info(info a, info b) { return (a.num < b.num); }
bool sort_revert(info a, info b) { return (a.idx < b.idx); }
ll original_arr[200001];
ll minus_arr[200001] = {
0,
};
int main() ... | 7 |
#include <bits/stdc++.h>
using namespace std;
char s[1000009];
int main() {
long x, y, i;
cin >> s;
x = y = i = 0;
while (s[i] != '\0') {
if (s[i] == 'x')
x++;
else
y++;
i++;
}
if (x > y)
for (i = 1; i <= x - y; i++) cout << 'x';
else
for (i = 1; i <= y - x; i++) cout << 'y... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n;
int findRoot(int a, vector<int> &tree) {
if (tree[a] == a) {
return a;
}
tree[a] = findRoot(tree[a], tree);
return tree[a];
}
void setUnion(int a, int b, vector<int> &upmost, vector<int> &downmost,
vector<int> &up) {
up[findRoot(a, upmost)... | 9 |
#include <bits/stdc++.h>
using namespace std;
using INT = long long;
const INT M = 10004205361450474LL;
const int N = 10000;
const int NN = 20468426;
INT q[] = {
6,
2046,
204761410474LL,
};
int a[] = {
14, 30, 62, 126, 254, 510, 1022,
};
int query(INT x) {
printf("1 %I64d\n", x);
fflush(stdout);
i... | 22 |
#include <bits/stdc++.h>
using namespace std;
vector<int> g[200005];
int dp[3][200005];
bool leaf[200005];
int ans = 0;
void dfs(int u, int p, int d) {
leaf[u] = 1;
dp[1][u]++;
int tmp = 1e9;
for (int i = 0; i < g[u].size(); i++) {
int v = g[u][i];
if (v == p) continue;
dfs(v, u, d + 1);
leaf[u]... | 13 |
#include <bits/stdc++.h>
using namespace std;
bool check(int_fast64_t n, int_fast64_t m,
vector<vector<int_fast64_t> > const& a) {
auto valid = [n, m](int_fast64_t i, int_fast64_t j) {
return 0 <= i && i < n && 0 <= j && j < m;
};
auto isnb = [n, m](int_fast64_t x, int_fast64_t y) {
return (x /... | 14 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void pfill(T* pst, const T* ped, T val) {
for (; pst != ped; *(pst++) = val)
;
}
template <typename T>
void pcopy(T* pst, const T* ped, T* pval) {
for (; pst != ped; *(pst++) = *(pval++))
;
}
const int N = 262144;
const int Mod = 998244353;... | 27 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char s1, s2;
cin >> s1 >> s2;
int n, k, ch = -1;
cin >> n;
k = n % 4;
if (k == 0 || k == 2)
ch = -1;
else {
if (s1 == '<') {
if (k == 1) {
if (s2 == '^')
ch = 1;
else if (s2 == 'v')
ch = 2;
}... | 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vii = vector<pii>;
using vvi = vector<vi>;
const int mxN = 1e5 + 5;
int N;
bool used[mxN];
void bad() {
cout << "-1\n";
exit(0);
}
int main(... | 5 |
#include <bits/stdc++.h>
using namespace std;
mt19937 myrand(time(NULL));
const int maxn = 3e5 + 10;
int n, m, block;
int arr[maxn], freq[maxn], ans[maxn];
struct query {
int l, r, k, id;
bool operator<(const query &q) const {
int a = l / block, b = q.l / block;
return a == b ? r < q.r : a < b;
}
} q[maxn... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> p(n), deg(n);
for (int i = 1; i < n; i++) {
cin >> p[i];
p[i]--;
deg[p[i]]++;
}
vector<int> sons_leaves(n);
for (int i = 1; i < n; i++) {
if (deg[i] == 0) {
sons_leaves[p[i]]++;
}
}
for (i... | 4 |
#include <bits/stdc++.h>
using namespace std;
constexpr char ROCK = 'R';
constexpr char EMPTY = '.';
constexpr int MOD = 1e9 + 7;
inline int try_access(vector<int>& v, int k) { return k < v.size() ? v[k] : 0; }
inline int mod(int x) { return (x % MOD + MOD) % MOD; }
int number_of_paths(vector<vector<char>>& A) {
int ... | 14 |
#include <bits/stdc++.h>
using namespace std;
string ITS(long long x) {
string s = "";
while (x > 0) {
s += (char)(x % 10 + '0');
x /= 10;
}
string t = "";
for (int i = s.size() - 1; i > -1; i--) t += s[i];
return t;
}
long long inf = 1e18;
long long mod = 1e9 + 7;
const long long M = 2e5;
long long... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long int s, x, dp[100][10][10][10], ar[100][100];
long long int solve(int c, int d, int a, int b) {
if (c > 50) {
if (a && b && !d) return 1;
return 0;
}
long long int &ret = dp[c][d][a][b];
if (ret != -1) return ret;
ret = 0;
if (ar[1][c] == 0 && d... | 9 |
#include <bits/stdc++.h>
const double PI = 3.1415926535897932384626433;
const int KL = 1e5 + 10;
const long long MOD = 1e9 + 7;
using namespace std;
long long n, m, a[KL], sum[4 * KL], mx[4 * KL], y, z, type;
void pushup(int cur) {
sum[cur] = sum[2 * cur] + sum[2 * cur + 1];
mx[cur] = max(mx[2 * cur], mx[2 * cur + ... | 15 |
#include <bits/stdc++.h>
using namespace std;
int n, i, a[55];
int main() {
scanf("%d", &n);
for (i = 0; i < n; i++) scanf("%d", &a[i]);
sort(a, a + n);
if (a[0] == a[n / 2])
puts("Bob");
else
puts("Alice");
return 0;
}
| 12 |
#include <bits/stdc++.h>
using namespace std;
long long dj[] = {1, 0, -1, 0};
long long di[] = {0, 1, 0, -1};
long long fine(long long i, long long j, long long n, long long m) {
return i >= 0 && i < n && j >= 0 && j < m;
}
long long gcd(long long a, long long b) {
if (b == 0)
return a;
else
return gcd(b,... | 8 |
#include <bits/stdc++.h>
using namespace std;
template <class Temp>
vector<Temp> read(long long int n) {
vector<Temp> input;
for (long long int i = 0; i < n; i++) {
Temp k;
cin >> k;
input.push_back(k);
}
return input;
}
template <class Temp>
vector<vector<Temp>> read_matrix(long long int n, long lo... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
const int N = 2e5 + 10;
const int M = 1e6 + 10;
const int maxn = 50 * 50 + 10;
const int mod = (int)1e9 + 7;
const double eps = 1e-6;
const double pi = acos(-1.0);
int n;
int cnt[20];
char s[N];
void wo... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
long long bin[300005];
vector<int> edge[300005];
vector<int> num[300005];
int id[300005], nxt, mn[300005];
int sum[300005];
int col[300005];
int rev[300005];
int up[300005][20];
int dep[300005];
void dfs(int v, int u) {
rev[nxt] = v;
id[v] = nxt++;
if (col[v... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k, r, i = 1;
cin >> k >> r;
while (1) {
if ((k * i - r) % 10 == 0 || k * i % 10 == 0) break;
i++;
}
cout << i;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
string s;
bool possible(int bloc) {
int pos = 0;
int mini = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == 'L')
pos--;
else
pos++;
if (pos == bloc) pos--;
if (i < s.size() - 1) mini = min(mini, pos);
}
if (pos < mini) return true;
... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
long long ans = 0;
vector<int> las[N];
int pre[N];
int a[N];
int b[N];
int n;
void solve(string s, bool sec) {
for (int i = 1; i <= n; i++) a[i] = b[i] = s[i - 1] - '0';
for (int i = n; i >= 1; i--)
if (a[i] > 0) a[i] += a[i + 1];
for (int i... | 16 |
#include <bits/stdc++.h>
using namespace std;
map<long long, long long> map1;
map<long long, vector<long long>> map2;
const long long N = 1e7;
long long DO[N];
long long son_l[N];
long long son_r[N];
long long c = 2;
void add_son(long long root) {
son_l[root] = c++;
son_r[root] = c++;
}
void add(long long root, lon... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long mod_add(long long a, long long b, long long m) {
a = a % m;
b = b % m;
return (((a + b) % m) + m) % m;
}
long long mod_mul(long long a, long long b, long long m) {
a = a % m;
b = b % m;
return (((a * b) % m) + m) % m;
}
long long mod_sub(long long a, l... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 310;
int n, m, k;
bool noe[N][N];
vector<pair<int, int> > e;
int a[N];
void add(int x, int y) {
e.push_back(make_pair(x, y));
noe[x][y] = 1;
noe[y][x] = 1;
}
void noedge(int x, int y) { noe[x][y] = noe[y][x] = 1; }
int main() {
scanf("%d%d%d", &n, &m, ... | 14 |
#include <bits/stdc++.h>
using namespace std;
int f[100000 + 5];
int mod = 1e9 + 7;
vector<int> divisor[100000 + 5];
int n;
void prepare() {
for (int i = 1; i <= 100000; i++)
for (int j = i; j <= 100000; j += i) divisor[j].push_back(i);
}
int pw(int x, int k) {
int res = 1;
int mul = x;
while (k > 0) {
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long q;
cin >> q;
while (q--) {
long long n;
cin >> n;
vector<long long> vec(n);
vector<long long> first(n, INT_MAX), last(n, INT_MIN);
for (int i = 0; i < n; i++) {
cin >> vec[i]... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d, e, f;
cin >> a >> b >> c >> d >> e >> f;
int ans = 0;
ans += (min(b + a, f + a) * min(b + a, f + a) - a * a);
ans += (min(c + d, e + d) * min(c + d, e + d) - d * d);
ans += ((max(b, f) - min(b, f)) * min(b + a, f + a) * 2);
cout <<... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, m, tmp, t[220000], r[220000], tr[220000], dr;
int main() {
scanf("%d %d", &n, &m);
vector<int> a;
vector<int> b(n);
for (int(i) = 0; (i) < (n); ++(i)) {
scanf("%d", &tmp);
a.push_back(tmp);
}
for (int(i) = 0; (i) < (m); ++(i)) {
scanf("%d %d",... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long x, y;
int main() {
int t;
while (scanf("%lld%lld", &x, &y) != EOF) {
long long ans = 0;
x -= y;
if (x % 2 == 1) {
cout << '0' << endl;
continue;
}
x /= 2;
int flag = 0, d = 0;
if (!x) d = 2;
for (int i = 0; i < 64; i... | 9 |
#include <bits/stdc++.h>
using namespace std;
char st1[100010], st2[100010];
int a1[100010], a2[100010], b1[100010], b2[100010];
int n;
int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || '9' < ch) {
if (ch == '-') f = -1;
ch = getchar();
}
while ('0' <= ch && ch <= '9') {
x = x... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const int mod = inf + 7;
const double eps = 1e-9;
const double pi = acos(-1.0);
int n, b[100100], a[100100];
long long k;
queue<int> q;
int alive, cur = 0, val = 0;
bool is_alive(int ind) {
if (cur >= n) return false;
return val < a[ind];
}
int... | 10 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
os << '{';
string sep;
for (const auto &x : v) os << sep << x, sep = ", ";
return os << '}';
}
template <typename T, size_t size>
ostream &operator<<(ostream &os, const array<T, size> &arr)... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, a[104], sum1 = 0;
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
for (int i = 0; i < m; i++) {
if (a[i] > 0) break;
sum1 += -a[i];
}
cout << sum1;
}
| 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.