solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int fs[50] = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};
struct node {
int f[51], jf;
string s;
} a[1001];
bool cmp1(node x, node y) {
if (x.jf != y.jf) {
return x.jf > y.jf;
}
for (int i = 0; i < 50; i++) {
if (x.f[i] != y.f[i]) return x.f[i] > y.f[i];
}
}
boo... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long ans = 0;
int A[] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int main() {
int a, b;
cin >> a >> b;
for (int i = a; i <= b; i++) {
int k = i;
while (k) {
ans += A[k % 10];
k /= 10;
}
}
cout << ans;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 105, M = 5005, inf = 1 << 30;
const double eps = 1e-9;
int n, m, X[M], Y[M], cnt[N][N], lim[N][N];
namespace equ {
int h[N], u[N];
double a[N][N], A[N], B[N];
inline bool iszero(double x) { return x < eps && x > -eps; }
void solve() {
for (int i = 0; i < n -... | 19 |
#include <bits/stdc++.h>
const int mod = 1e9 + 7;
const double PI = acos(-1);
using namespace std;
int N, M, K;
int cnt[1000005];
map<int, set<pair<int, int>>> m1;
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> N;
for (int i = 1; i <= N - 2; i++) {
int a, b, c;
cin >> a >> b >>... | 8 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int num = 0, neg = 1;
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 num * neg;
}
struct edge {
int nxt, to;
} Edge[500000 <... | 21 |
#include <bits/stdc++.h>
int quickpower(long long p, long long q, int base) {
long long cur = p % base;
long long ans = 1;
while (q) {
if (q & 1) {
ans *= cur;
ans %= base;
}
cur *= cur;
cur %= base;
q >>= 1;
}
return (int)ans;
}
int inverse_element_prime_base(long long p, int ... | 18 |
#include <bits/stdc++.h>
using namespace std;
int v[] = {0, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47};
int sq[] = {0, 4, 9, 25, 49, 81};
int main() {
ios::sync_with_stdio(false);
string s;
int ct = 1;
for (int i = 1; i <= 15; ++i) {
cout << v[i] << "\n";
cout << flush;
cin >> s;
if... | 6 |
#include <bits/stdc++.h>
using namespace std;
int const N = 100;
int x[N << 1], vis[N + 1];
int main() {
int n;
scanf("%d", &n);
n <<= 1;
for (int i = 0; i < (int)(n); ++i) scanf("%d", x + i);
int an = 0;
for (int i = 0; i < (int)(n); ++i) {
if (vis[x[i]]) {
int j = i;
while (x[j - 1] != x[j... | 6 |
#include <bits/stdc++.h>
using namespace std;
int resfile, resfold;
struct obj {
string nm;
vector<obj *> v;
obj *get(string &s) {
for (int i = 0; i < v.size(); i++) {
if (v[i]->nm == s) {
return v[i];
}
}
v.push_back(new obj());
v.back()->nm = s;
return v.back();
}
pai... | 10 |
#include <bits/stdc++.h>
const int MAXN = 1e5 + 1;
int t, n;
int arr[MAXN];
int brr[MAXN];
int main() {
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
int a;
scanf("%d", &a);
arr[i + 1] = a;
}
for (int i = 0; i <= n; i++) brr[i] = 1;
for (int i = ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 55;
bitset<2222> bt[2222], aim;
int pos[2222];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
getchar();
for (int j = 0; j < m; j++) {
char x;
scanf("%c", &x);
if (x == '1') {
bt... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d;
signed main() {
ios_base::sync_with_stdio(0);
cin >> a >> b >> c >> d;
if ((a == (b + 1)) && (c == 0) && (d == 0)) {
cout << "YES"
<< "\n";
for (long long i = 1; i <= b; i++) cout << 0 << " " << 1 << " ";
cout << 0;
retur... | 11 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int64_t, int64_t>> v;
int64_t n, m, x, y, z, p;
void clockwise() {
for (auto& [i, j] : v) {
swap(i, j);
j = n + 1 - j;
}
swap(n, m);
}
void anticlockwise() {
for (auto& [i, j] : v) {
swap(i, j);
i = m + 1 - i;
}
swap(n, m);
}
void fli... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long read() {
long long q = 0, w = 1;
char ch = getchar();
while (ch > '9' || ch < '0') {
if (ch == '-') w = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
q = q * 10 + (ch - '0');
ch = getchar();
}
return q * w;
}
void write(long ... | 16 |
#include <bits/stdc++.h>
using namespace std;
void load() {}
const int N = 1e5 + 123;
int lab[N], pr[N], dep[N], sz[N], l[N], r[N];
vector<int> ed[N];
map<int, int> Map[N], Map1[N];
bool vis[N];
int Findset(int u) { return (u == lab[u]) ? u : lab[u] = Findset(lab[u]); }
void dfs(int u, int p) {
vis[u] = 1;
for (int... | 16 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e6 + 3;
const int max_N = 7e5 + 10;
long long fact[max_N], finv[max_N];
long long powmod(long long a, long long b) {
assert(b >= 0);
long long res = a, ans = 1;
res %= mod;
while (b) {
if (b % 2) ans *= res;
ans %= mod;
res *= res;... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 100;
const int mod = 1e9 + 7;
int par[maxn];
int get_par(int v) {
if (par[v] < 0) return v;
return par[v] = get_par(par[v]);
}
void merge(int v, int u) {
v = get_par(v), u = get_par(u);
par[u] += par[v];
par[v] = u;
}
pair<int, int> a[maxn];... | 11 |
#include <bits/stdc++.h>
using namespace std;
int y3, y2, m1, m2, d1, d2,
mo[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool leap(int y) { return (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0)); }
int gd(int y, int m, int d) {
int ans = 0;
for (int i = 1900; i < y; i++) {
ans += 365 + leap(i)... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, n;
cin >> n >> a >> b;
a = a - 1;
cout << (100 * n + a + b) % n + 1;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
ifstream in("cf.in");
ofstream out("cf.out");
const int DIM = 1e2 + 5;
int dp[205][5205];
int main(void) {
ios::sync_with_stdio(false);
cin.tie();
cout.tie();
int n, k;
cin >> n >> k;
memset(dp, -0x3f, sizeof(dp));
dp[0][0] = 0;
for (int i = 1; i <= n; ++i) ... | 13 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct quad {
int pos;
long long weight;
int now;
int target;
};
vector<vector<int>> adj;
vector<quad> desc;
map<int, int> vis;
long long cost;
bool compare(quad a, quad b) { return a.weight <= b.w... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
while (cin >> n) {
bool yes = true;
int arr[105] = {0};
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
string line;
getline(cin, line);
for (int i = 0; i < n; i++) {
int count = 0;
string str;
getli... | 4 |
#include <bits/stdc++.h>
int main() {
int n, p, q, i, j, flag = 0, ans, k, a;
scanf("%d%d%d", &n, &p, &q);
char s[n];
scanf("%s", s);
for (i = 0; p * i <= n; i++) {
for (j = 0; (p * i + q * j) <= n; j++) {
ans = p * i + q * j;
if (ans == n) {
flag = 1;
break;
}
}
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int head[100005], tot, n, rt;
int mx[100005], son[100005], mk[100005];
int flag, sum, sz[100005];
char ans[100005];
struct name {
int id, nx;
} to[100005 << 1];
void add(int x, int y) {
to[++tot] = (name){y, head[x]};
head[x] = tot;
}
void get_rt(int x, int f) {
sz[... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int l;
string s;
cin >> s;
sort(s.begin(), s.end());
l = s.size() / 2;
for (; l < s.size() - 1; l++) {
cout << s[l] << '+';
}
cout << s[s.size() - 1];
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i;
cin >> n;
if (n & 1) n -= 3, printf("7");
n /= 2;
while (n--) printf("1");
printf("\n");
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long n;
cin >> n;
char a[100];
string s;
bool ok = true;
for (long i = 0; i < n; i++) {
ok = true;
cin >> s;
for (long i = 0; i < s.length(); i++) {
a[i] = s[i];
}
sort(a, a + s.length());
for (long i = 0; i < s.length(... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MX = 1500005;
int n;
vector<int> adj[MX];
int dep[MX];
void dfs(int u, int p, int d) {
dep[u] = d;
for (auto v : adj[u]) {
if (v != p) dfs(v, u, d + 1);
}
}
signed main() {
int t;
cin >> t;
for (int cs = 1; cs < t + 1; cs++) {
cin >> n;
int... | 23 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int N, M, R, K;
long long ans;
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
int val(int x, int y) {
return (min(N, x + R - 1) - max(x, R) + 1) *
(min(M, y + R - 1) - max(y, R) + 1);
}
struct Node {
int x, y;
Node(... | 13 |
#include <bits/stdc++.h>
const int mod = 1e9 + 7;
const int N = 1e5 + 1;
using namespace std;
void solve() {
long long int n;
cin >> n;
if (n == 1) {
cout << 1;
return;
}
long long int i = 0;
while (true) {
if (n >= (i * (i + 1)) / 2 && n <= ((i + 1) * (i + 2)) / 2)
break;
else
i... | 2 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long n, x;
cin >> n;
vector<long long> v;
for (long long i = 0; i < n; i++) {
cin >> x;
v.push_back(x);
}
sort(v.begin(), v.end());
long long minm = 1e18 + 17, cnt = 0;
for (long long... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
vector<int> tour;
vector<int> adj[maxn];
int a[maxn];
inline void f(int v) { a[v] *= -1, tour.push_back(v); }
void dfs(int v, int p) {
if (v) a[v] *= -1;
tour.push_back(v);
for (int u : adj[v])
if (u != p) {
dfs(u, v);
f(v);
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int tbuses, at, i;
int min, ind, count;
cin >> tbuses >> at;
pair<int, int> b[tbuses + 1];
for (i = 0; i < tbuses; i++) {
cin >> b[i].first >> b[i].second;
}
while (1) {
count = 0;
for (i = 0; i < tbuses; i++) {
if (b[i].first >=... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<string> mat(6);
for (int i = 0; i < 6; ++i) {
string t;
cin >> t;
t.erase(t.begin() + 5);
t.erase(t.begin() + 2);
mat[i] = t;
}
int conv[6][6];
int m1 = 3, m2 = 4, m3 = 3;
for (int i = 0; i < 6; i += 2) {
conv[i][0] = ... | 8 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void rd(T &x) {
x = 0;
int ch = getchar(), f = 0;
while (ch < '0' || ch > '9') {
if (ch == '-') f = 1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
if (f) x ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int t;
cin >> t;
for (int e = 0; e < t; e++) {
int n, last = 0, now = 0, ff = 1;
bool flag = true;
cin >> n;
vector<int> arr(n + 1, 0);
vector<int> res(n);
for (int i = 0; i < n; i++) {
int... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int pos[N], a[N];
int n;
int A[N];
long long B[N];
void add(int a) {
for (int i = a; i <= n; i += (i & -i)) {
A[i]++;
}
}
int ask(int a) {
int ret = 0;
for (int i = a; i > 0; i -= (i & -i)) {
ret += A[i];
}
return ret;
}
int findKth... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5005;
int head[MAXN], E;
int dp[MAXN];
bool mark[MAXN];
struct Edge {
int v, next;
} edge[MAXN << 1];
int n;
void add_edge(int u, int v) {
edge[E].v = v;
edge[E].next = head[u];
head[u] = E++;
}
int dfs(int u, int fa) {
int i, j;
int son = 0;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > sen;
int n, m, a;
double ans;
void dfs(int at, int left) {
if (at == n) {
double tot = 0;
for (int i = 0; i < (1 << n); ++i) {
double per = 1, b = 0;
for (int j = 0; j < n; ++j) {
if (i & (1 << j)) {
per *= sen... | 10 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma,tune=native")
template <typename T>
void print(T&& x) {
cout << x << "\n";
}
template <typename T, typename... S>
void print(T&& x, S&&... y) {
cout << x << ' ';
print... | 24 |
#include <bits/stdc++.h>
using namespace std;
char str[55];
int ans;
int main() {
scanf("%s", str);
int i, j, k, l;
int f;
ans = 0;
for (int i = 0; i < strlen(str); i++) {
for (int j = i + 1; j < strlen(str); j++) {
f = 0;
for (int k = 0; k <= j - i; k++) {
if (str[i + k] != str[j - k]... | 1 |
#include <bits/stdc++.h>
using namespace std;
inline void fast_io() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int main() {
fast_io();
int n, k;
cin >> n >> k;
string s;
cin >> s;
int gpos = -1, inpos = -1;
for (int i = 0; i < n; i++) {
if (s[i] == 'G')
gpos = i;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
inline long long mod(long long n, long long m) {
long long ret = n % m;
if (ret < 0) ret += m;
return ret;
}
long long gcd(long long a, long long b) {
return (b == 0LL ? a : gcd(b, a % b));
}
long long exp(long long b, long long e, long long m) {
b %= m;
long lo... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 10;
int main() {
string s;
cin >> s;
bool ck = 0;
long long count = 0;
for (int i = 0; i < s.length(); i++) {
if (s[i] == '1') ck = 1;
if (ck && s[i] == '0') count++;
}
if (count > 5)
cout << "yes";
... | 2 |
#include <bits/stdc++.h>
const long long mod = 1000000007;
const int maxn = 1e5 + 1;
long long inf = 1LL << 60;
using namespace std;
long long comp(long long x) { return (x + 1) * (x + 2) / 2; }
int main() {
ios_base::sync_with_stdio(0);
long long a, b, c, l;
cin >> a >> b >> c >> l;
long long ans = (l + 1) * (... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long n;
long long mem[150050];
long long x[150050];
void sliding_window_minimum(long long K) {
deque<long long> window;
for (long long i = 1; i <= n; i++) {
while (!window.empty() && mem[window.back()] <= mem[i]) window.pop_back();
window.push_back(i);
... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int x, y;
cin >> x >> y;
if (x == 0 || y == 0) {
cout << "black" << '\n';
} else if (x * y > 0) {
int d = sqrt(x * x + y * y);
if (d * d == x * x + y * y) {
cout << "blac... | 5 |
#include <bits/stdc++.h>
using namespace std;
string s;
int l, ans;
int main() {
cin >> s;
l = s.size();
for (register int i = 0; i < l; i++) {
if (s[i] == 'A')
ans += 1;
else if (s[i] == '1')
ans += 10;
else
ans += (s[i] - '0');
}
cout << ans << endl;
}
| 11 |
#include <bits/stdc++.h>
using namespace std;
int ans[1005];
double dp[20005][1005];
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cin.tie(0), cout.tie(0),
cout.precision(15);
int k, q;
while (cin >> k >> q) {
memset(ans, 0, sizeof(ans));
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
for... | 14 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void rd(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 - '0' + c, c = getchar();
x *= f;
}
inline long long Abs(long long x) { return x ... | 24 |
#include <bits/stdc++.h>
using namespace std;
char down(char c) {
if (c >= 'A' && c <= 'Z') c += 32;
return c;
}
char up(char c) {
if (c >= 'a' && c <= 'z') c -= 32;
return c;
}
int main() {
char a[52], c, d[52];
int b, i, j, k;
while (cin >> a >> b) {
for (i = 0; i < strlen(a); i++) {
c = down(... | 6 |
#include <bits/stdc++.h>
using namespace std;
void OMG() { cout << "OMG>.< I don't know!\n"; }
void W1() { cout << "Freda's\n"; }
void W2() { cout << "Rainbow's\n"; }
bool ff1(string S) {
string A = "";
for (int i = 0; i < 5; i++) A += S[i];
return (A == "miao.");
}
bool ff2(string S) {
string A = "";
for (in... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int md = 1e9 + 7;
const int maxn = 1e5 + 5;
struct Marix {
long long maze[2][2];
Marix() { memset(maze, 0, sizeof maze); }
void One() {
maze[0][0] = maze[1][1] = 1;
maze[0][1] = maze[1][0] = 0;
}
Marix operator+(const Marix& tmp) const {
Marix re... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, countl = 0, countr = 0;
cin >> n;
string s;
cin >> s;
for (i = 0; s[i] != '\0'; i++) {
if (s[i] == 'L') countl++;
if (s[i] == 'R') countr++;
}
cout << (countl + countr + 1);
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long int arr[1000000], brr[1000000], crr[1000000];
string str, str1;
int flag = 0;
int main() {
long long int t, i, j, k, n, x, y, z, a, b, c, l, r, mid, l1, r1, m, maxx,
amaxx;
cin >> t;
while (t--) {
cin >> n;
cin >> str;
cin >> str1;
i = ... | 5 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct { int to, cost; };
const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0};
const i... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
const int INF32 = 0x3f3f3f3f;
const long long INF64 = 0x3f3f3f3f3f3f3f3f;
const long long MOD = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = 1.0e-8;
int A[MAXN];
int InDeg[MAXN];
int n;
int main() {
while (~scanf("%d", &n)) {
fo... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
long long f, T, t0;
long long roll(long long a1, long long t1, long long p1, long long a2,
long long t2, long long p2) {
long long best = INF;
for (long long x1 = 0; x1 <= (long long)1e7; x1++) {
long long bytes = min(... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
struct NODE {
int x, t;
NODE() {}
NODE(int a, int b) {
x = a;
t = b;
}
};
vector<NODE> ans;
struct EDGE {
int to, nxt;
} edge[N * 2];
int t[N], size[N];
int k, maxa;
void addedge(int x, int y) {
edge[++k].to = y;
edge[k].nxt = t... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
char ch[30], x, y;
int n, m;
cin >> n >> m;
cin >> s;
for (int i = 0; i < 26; i++) ch[i] = i + 'a';
for (int i = 0; i < m; i++) {
cin >> x >> y;
for (int l = 0; l < 26; l++) {
if (ch[l] == x) {
ch[l] = y;
} el... | 4 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int s = 0, f = 1;
char ch = getchar();
while (ch < '0' || '9' < ch) {
if (ch == '-') f = -1;
ch = getchar();
}
while ('0' <= ch && ch <= '9') {
s = s * 10 + (ch ^ 48);
ch = getchar();
}
return s * f;
}
inline int Abs(int x) ... | 3 |
/*
Author: AquaBlaze
Keqing best girl :)
Nephren will always be in my heart
*/
/*
* I think have been thinking about
* maintaining 3-4 matrices that could be
* traded with each other the whole time
*
* I got the idea that when 'I' happens,
* each position will change into index of value 'j' is in the row... | 19 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long n, m, a[100010], b[100010];
signed main() {
scanf("%I64d%I64d", &n, &m);
if (n > m) swap(n, m);
a[1] = 2;
a[2] = 4;
for (long long i = 3; i <= n; i++) a[i] = (a[i - 1] + a[i - 2]) % mod;
b[1] = a[n];
b[2] = (b[1] + 2) %... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
char a[n];
for (int i = 0; i < n; i++) cin >> a[i];
int open = 0, close = 0;
int res = 0;
for (int i = 0; i < n; i++) {
if (a[i] == ')') {
close++;
} else
open++;
}
if (close != open) {
cout << "-1\n";
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int n, a[N], id[N], cnt;
int64_t f[N], ans;
map<int, int> p[N];
int main() {
int T;
scanf("%d", &T);
while (T--) {
scanf("%d", &n);
ans = 0;
for (int i = 1; i <= n; ++i) scanf("%d", a + i);
f[n] = f[n + 1] = 0;
id[n] = cnt = ... | 18 |
#include<bits/stdc++.h>
using namespace std;
long long n;
void Answer(long long n) {
long long n1 = n;
long long sum=0;
while(n1) {
long long rem = n1 % 10;
sum += rem;
n1/=10;
}
long long n2 = n;
while(n2 % sum != 0) {
long long rem = n2 % sum;
n2 = sum;
sum = rem;
}
long long gcd = sum;
if(g... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char **argv) {
int N;
cin >> N;
if (N == 2) {
cout << 2;
return 0;
}
int prev = 1;
for (int i = 1; i < N; ++i) {
int child = (prev + i - 1) % N + 1;
prev = child;
cout << child;
if (i != N - 1) cout << " ";
}
return... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAX_N = 1e5 + 10;
int main() {
int nQuery;
scanf("%d", &nQuery);
while (nQuery--) {
int nBlack, nWhite;
scanf("%d %d", &nBlack, &nWhite);
if (nBlack * 3 + 1 < nWhite || nWhite * 3 + 1 < nBlack)
printf("NO\n");
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e6 + 5;
const int MX = 5e4 + 5;
int z[MAX], a[MX], b[MX], l[MX], r[MX], ans[MX];
int main() {
int n, m;
z[0] = 0;
for (int i = 1; i < MAX; i++) z[i] = z[i - 1] ^ i;
while (scanf("%d%d", &n, &m) != EOF) {
memset(ans, 0, sizeof(ans));
for (int... | 20 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d, Count;
char A[51];
while (cin >> a) {
Count = 0;
for (b = 0; b < a; b++) {
cin >> A[b];
}
for (c = 0; c < a; c++) {
if (A[c + 1] == A[c]) Count++;
}
cout << Count << endl;
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n + 1], b[n + 1], c[n + 1];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n - 1; i++) {
cin >> b[i];
}
for (int i = 0; i < n - 2; i++) {
cin >> c[i];
}
sort(a, a + n);
sort(b, b + n - 1... | 3 |
#include <bits/stdc++.h>
using namespace std;
class segtree {
public:
struct node {
int flip = 0;
int put = -1;
int value = 0;
void apply(int l, int r, int v) {
if (v == -1) {
flip ^= 1;
value ^= 1;
} else {
put = v;
flip = 0;
value = v;
}
... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int l, r, i, j, cnt = 0, s;
cin >> l >> r;
for (i = 1; i <= 100000000000; i *= 2) {
for (j = 1; j <= 100000000000; j *= 3) {
s = j * i;
if (l <= s && s <= r) {
cnt++;
}
}
}
cout << cnt;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
int n, m, a[100005];
long long ans = 0;
void setup() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
ans += a[i] - 1;
}
}
void xuly() {
sort(a + 1, a + n + 1);
int cnt = 1;
for (int i = n - 1; i >= 0; i--) {
if (a[i] != a[i + 1]) {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int mod1 = 998244353;
int mod2 = 1000000007;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, m, h;
cin >> n >> m >> h;
vector<int> s(m + 1);
int p = 0;
for (int i = 1; i < m + 1; i++) {
cin >> s[i];
p += s[i];
}... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, k, l, ans, s, vac[11111];
long double dist[1111111], x, y, r;
bool used[111111];
bool f;
vector<pair<double, int> > v;
int main() {
cin >> n >> s;
k = s;
for (int i = 1; i <= n; ++i) {
cin >> x >> y >> vac[i];
dist[i] = sqrt(x * x + y * y);
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int INF = std::numeric_limits<int>::max() / 3;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a * (b / gcd(a, b)); }
vector<long long> c1, c2, c3;
vector<pair<int, int> > w, h;
vector<int... | 22 |
#include <bits/stdc++.h>
using namespace std;
long long int min(long long int a, long long int b) { return (a < b) ? a : b; }
long long int max(long long int a, long long int b) { return (a > b) ? a : b; }
long long int fp(long long int a, long long int b) {
if (b == 0) return 1;
long long int x = fp(a, b / 2);
x... | 4 |
/*
ID: tommyfa1
TASK : ride
LANG : C++11
*/
#include <iostream>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <deque>
#include <list>
#include <fstream>
#include <string>
#include <vector>
#include <sstream>
#include <array>
#include <queue>
#include <stack>
#include <... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, k;
long long a[int(1e4) + 10];
void task() {
cin >> n >> m >> k;
for (int i = 0; i < n; ++i) cin >> a[i];
if (n == 1) {
cout << min(a[0], k * m);
return;
}
if (n % 2 == 0 || m < n / 2 + 1) {
cout << 0;
return;
}
if (n == 3) {
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
struct Node {
int is, id, x;
bool operator<(const Node &a) const {
if (x != a.x)
return x < a.x;
else
return is < a.is;
}
};
int a[maxn * 4], s[maxn], p[maxn], inc[maxn], b[maxn], treea[maxn * 4],
treeb[maxn * 4], pb[... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int N = 205;
int n, mt;
int a[N];
int b[N];
int t[N];
inline int read() {
int x = 0;
int f = 1;
char ch = getchar();
while (ch > '9' || ch < '0')
if (ch == '-') f = -1, ch = getchar();
while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();... | 8 |
#include <bits/stdc++.h>
const long double pi = acos(-1);
using namespace std;
template <class T>
void Read(T &x) {
char c;
bool f(0);
while (c = getchar(), c != EOF) {
if (c == '-')
f = 1;
else if (c >= '0' && c <= '9') {
x = c - '0';
while (c = getchar(), c >= '0' && c <= '9') x = x * ... | 24 |
#include <bits/stdc++.h>
int main() {
long long int n;
scanf("%lld", &n);
long long int i, num[101], a[101], b[101], zero = 0, x = 0, y = 0;
for (i = 0; i < n; i++) {
scanf("%lld", &num[i]);
if (num[i] > 0) {
a[x] = num[i];
x++;
}
if (num[i] < 0) {
b[y] = num[i];
y++;
... | 3 |
#include <bits/stdc++.h>
using LL = long long;
std::pair<LL, LL> point[100100];
int n, belong[100100], line[100100];
bool is_one_line(std::pair<LL, LL> p1, std::pair<LL, LL> p2,
std::pair<LL, LL> p3) {
auto t1 = std::make_pair(p2.first - p1.first, p2.second - p1.second);
auto t2 = std::make_pair(p3... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, n, m, ans = 0;
int t;
char in[105][105];
int arr[105] = {0};
cin >> n >> m;
for (i = 0; i < n; i++) {
scanf("%s", in[i]);
}
int prevtaken = -1, prevleft = -1;
for (j = 0; j < m; j++) {
for (i = 1; i < n; i++) {
if (in[i... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 150000;
struct node {
int left, right, mk;
int msum, lsum, rsum;
int mid() { return (left + right) >> 1; }
int len() { return right - left + 1; }
} tr[MAXN * 4];
int pos[105], len[105];
void push_down(int k) {
if (tr[k].mk != -1) {
tr[(k << 1)... | 10 |
#include <bits/stdc++.h>
using namespace std;
vector<int> e[100050];
bool bo[100050];
int p[100050];
int x[100050], y[100050];
int main() {
int n, m, i, j, k, Y0, Y1;
scanf("%d%d%d%d", &n, &m, &Y0, &Y1);
for (i = 0; i < n; ++i) scanf("%d", &x[i]);
for (i = 0; i < m; ++i) scanf("%d", &y[i]);
memset(bo, 0, size... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000000;
struct Node {
Node *lc, *rc;
int size;
} * Null, *root[1000010];
int m, n;
Node *Insert(Node *p, int l, int r, int x) {
Node *q = new Node;
*q = *p, ++q->size;
if (l == r) return q;
int mid = (l + r) >> 1;
if (x <= mid)
q->lc = Inser... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int l[n];
int r[n];
for (int i = 0; i < n; i++) {
cin >> l[i];
}
for (int i = 0; i < n; i++) {
cin >> r[i];
}
int flag = 0;
int ans[n];
for (int i = 0; i < n; i++) {
ans[i] = n - (l[i] + r[i]);
}
for (int i... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
bool isprime(int n) {
if (n == 0 || n == 1) return false;
for (int i = 2; i * i <= n; i++) {
if (n != i && n % i == 0) {
return false;
}
}
return true;
}
int nu... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int curl = 0, curr = 0, ans = 0;
bool bl, br;
int b = 0, k = 0;
for (int i = 0; i < s.length(); ++i) {
if (s[i] == '(')
b++;
else {
if (b > 0)
b--;
else
continue;
k++;
ans = m... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, LSH, lsh[100005 * 2];
struct data {
int a, b, h;
} p[100005];
long long maxn[100005 * 8], f[100005], ans;
int find(int x) {
int l = 1, r = LSH, mid, ans;
while (l <= r) {
mid = (l + r) >> 1;
if (lsh[mid] >= x)
ans = mid, r = mid - 1;
else
... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long t, n, x, a[75];
int main() {
a[0] = 1;
for (int i = 1; i < 70; i++) a[i] = a[i - 1] * 2;
cin >> t;
for (int tt = 0; tt < t; tt++) {
cin >> n;
int i;
for (i = 0; i < 70; i++)
if (n < a[i]) break;
cout << (n * (n + 1)) / 2 - 2 * a[i] + ... | 1 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> a;
string s;
long long n;
long long dp[100000];
long long memo[100000][250 + 1];
long long find(long long pos, long long val) {
if (pos < 0) return 0;
if (a[pos - 1] <= val) return dp[pos - 1];
if (val <= 250 && memo[pos][val] != -1) return memo[pos]... | 15 |
#include <bits/stdc++.h>
using namespace std;
double dp[102][102 * 1003 + 1003];
double acc[102][102 * 1003 + 1003];
int score[102], N, M, tscore;
int main() {
scanf("%d %d", &N, &M);
if (M == 1) {
printf("%.15lf\n", 1.);
return 0;
}
for (int i = 0; i < N; i++) {
scanf("%d", &score[i]);
tscore +... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, M = 1e6 + 6, OO = 0x3f3f3f3f;
int tc;
long long a, b, c, d;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> tc;
while (tc--) {
cin >> a >> b >> c >> d;
if (b >= a) {
cout << b << endl;
continue;
}
if (... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const unsigned long long infl = 0x3f3f3f3f3f3f3f3fLL;
template <typename T>
inline void umax(T &a, T b) {
a = max(a, b);
}
template <typename T>
inline void umin(T &a, T b) {
a = min(a, b);
}
const int MAXN = 100005;
const unsigned long long ... | 18 |
#include <bits/stdc++.h>
using namespace std;
long long n, k;
vector<int> v;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> k;
while (n != 1) {
for (int i = 2; i <= 100000; i++) {
if (n % i == 0) {
v.push_back(i);
n /= i;
break;
}
}
}
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100001;
int a[N];
int d[N];
int hi[N][20];
int getmax(int s, int t) {
if (s == t) return s;
int k = 0;
while (t - s >= (1 << k)) {
k++;
}
k--;
int h = s + (1 << k) - 1;
if (d[hi[t][k]] > d[hi[h][k]]) {
return hi[t][k];
} else {
retu... | 13 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.