solution stringlengths 53 181k | difficulty int64 0 13 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, y;
vector<int> arr;
cin >> n;
bool f = false;
for (int i = 0; i < n; i++) {
cin >> x >> y;
if (y != x) {
f = true;
}
arr.push_back(y);
}
if (f) {
cout << "rated";
return 0;
}
reverse(arr.begin(), arr.end... | 0 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(time(0));
const long long inf = 0x3f3f3f3f3f3f3f3fLL;
const int N = 1e3 + 5;
const int MOD = 1e9 + 7;
string str;
vector<string> a[N];
bool mark[26];
int deg[N];
vector<int> g[26];
vector<int> topo;
void topoSort() {
topo.clear();
priority_queue<int, vector<... | 7 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) int(x.size())
const int mod = 1e9 + 7;
const int inf = 2e9 + 5;
const ll linf = 9e18 + 5;
const ll ll0 = 0 * 1ll;
int n, t;
const int ... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long satr[(long long)1e5 + 10];
long long soton[(long long)1e5 + 10];
int main() {
int n;
cin >> n;
string str;
cin >> str;
set<char> second;
for (int i = 0; i < (int)str.length(); i++) {
second.insert(str[i]);
}
int javab = 1e6;
int f = second.si... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long t, c[309100], n, a[309100], b[309100], m, j, an = 1, k;
int main() {
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> b[i];
}
for (int i = 0; i < n; i++) {
if (b[i] >= n - m + 1) {
c[j] = i + 1;
j++;
}
}
sort(b, b + n);
for... | 2 |
#include <bits/stdc++.h>
using namespace std;
inline int L(int i) { return i << 1; }
inline int R(int i) { return (i << 1) | 1; }
inline int B(int i) { return 1 << i; }
inline int low_bit(int x) { return x & (-x); }
struct node {
int x, y;
} no[201000];
struct CNT {
int a, b, c;
} shu[201000];
int num[201000 + 2010... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 13;
long long bufer[N];
long long maxi[N];
int siz[N];
int numofleafs[N];
long long a[N];
vector<int> g[N];
int n;
void calcleaf(int v) {
for (auto x : g[v]) {
calcleaf(x);
numofleafs[v] += numofleafs[x];
}
if (g[v].empty()) numofleafs[v] =... | 5 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
using namespace std;
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 800;
int a[N];
long long b[N];
int n, m;
int solve(long long x) {
priority_queue<int> q;
int ret = 0;
for (int i = 1; i <= n; i++) {
if (a[i] < 0) q.push(-a[i]);
x += a[i];
if (x < 0) {
x += q.top();
q.pop();
ret++;
}
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int c[401];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> c[i];
int ans = -1;
for (int i = 1; i < n; i++) {
for (int j = i; j < n; j++) {
int p = c[i - 1] - 1, cnt = 1, w = c[j];
for (int k = i; k <= j; k++) {
cnt += p / ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2 * 100000 + 100;
struct node {
int x;
int cur;
} a[maxn];
int ant[maxn];
int lef[maxn];
int righ[maxn];
bool cmp(node u, node v) { return u.x > v.x; }
int main() {
int n;
while (~scanf("%d", &n)) {
for (int i = 0; i < n; i++) {
scanf("%d"... | 5 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9 + 7;
const int N = 1e5 + 10;
ll t[N], p, ans[N], q[N], head = 1, tail = 1;
int n, x[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> p;
for (int i = 0; i < n; ++i) cin >> t[i];
for (int i = 0; i ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-9;
void solve() {
cout.precision(14);
cout << fixed;
long double x1, y1, r1, x2, y2, r2;
cin >> x1 >> y1 >> r1 >> x2 >> y2 >> r2;
long double d = sqrtl((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
if (d > r1 + r2 - EPS) {
cout <... | 6 |
#include <bits/stdc++.h>
using namespace std;
int dist[30][30];
int main() {
int i, j, k;
int n, m;
int u, v;
for (i = 0; i < 30; i++) {
for (j = 0; j < 30; j++) dist[i][j] = 100000000;
}
for (i = 0; i < 30; i++) dist[i][i] = 0;
string s, t;
cin >> s >> t;
if (s.length() != t.length()) {
cout ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int inf = int(1e9);
const double eps = 1e-9;
const double pi = 4 * atan(double(1));
const int N = 1010;
pair<long long, long long> p[N];
inline long long gcd(long long a, long long b) {
while (b > 0) {
a %= b;
swap(a, b);
}
return a;
}
int main() {
int... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double h, l;
cin >> h >> l;
double p;
p = l * l - h * h;
p /= 2;
p /= h;
printf("%.13f", p);
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T sqr(T x) {
return x * x;
}
template <typename T>
T abs(T x) {
return x < 0 ? -x : x;
}
const int MAXN = 22;
const int MAXK = 12;
int a[MAXN][MAXN];
int cnt[MAXK], col[MAXK];
int r[MAXN][MAXN];
int f[MAXN][MAXN];
int cb[1 << MAXK];
int n, m, k, d;... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = (1 << 17) + 1000;
const int INF = 1e9;
int n, k, t, a[MAXN], f[18][MAXN][2][2];
int main() {
ios_base::sync_with_stdio(false);
cin >> n >> k;
for (int i = 1; i <= k; i++) cin >> t, a[t - 1] = 1;
int bit = 1 << n;
for (int i = 0; i < 18; i++)
f... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, SEG = (1 << 18);
vector<pair<int, int>> res;
int n, k;
void sw(string &s, int st, int en) {
while (en > st) {
swap(s[st], s[en]);
st++;
en--;
}
}
void fix(string &s) {
int cnt = 0;
for (int i = 0; i < n; i++) {
if (s[i] == ')')... | 4 |
#include <bits/stdc++.h>
using namespace std;
set<int> s;
int n, l, x, y;
int main() {
cin >> n >> l >> x >> y;
int a;
for (int i = 1; i <= n; ++i) cin >> a, s.insert(a);
int ans = 2;
bool fx = 0, fy = 0;
for (__typeof((s).begin()) it = (s).begin(); it != (s).end(); it++) {
if (s.count(*it + x)) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int n, res = 1e9, a[5][N][N];
void calc(int a[N][N], int b[N][N], int c[N][N], int d[N][N]) {
int tmp = 0, tmp2 = 0;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j) {
if (a[i][j] != (i + j) % 2)
++tmp;
else
++... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const int maxm = 5e4 + 10;
const int INF = 0x3f3f3f3f;
int n, res, dp[maxn];
struct Edge {
int v, next;
} edge[maxn * 2];
int head[maxn], cnt, ans[maxn], c, du[maxn];
void add(int u, int v) {
edge[cnt].next = head[u];
edge[cnt].v = v;
head... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long infLL = 0x3f3f3f3f3f3f3f3fLL;
const int maxn = 100000 + 5;
int n;
int a[maxn], p[maxn], vec[maxn];
void gcd(long long a, long long b, long long &g, long long &x0, long long &y0) {
if (!b)
g = a, x0 = 1, y0 = 0;
else
gc... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long i, n, now, hh, ceng, ans, t, t1, la, a[100001], f[100001], g[100001],
sum[100001];
bool cmp(long long a, long long b) { return a > b; }
int main() {
scanf("%lld", &n);
for (i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
}
sort(a + 1, a + n + 1, cmp);
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long n, m;
cin >> n >> m;
vector<long long> tc(n), mk(m);
long long a;
long long ceven = 0, codd = 0;
for (int i = 0; i < n; i++) {
cin >> a;
tc[i] = a;
if (a % 2 == 0)
ceven++;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
inline int getid(int x, int y) { return x * 1010 + y; }
const int MAXN = 1010;
int parent[2 * MAXN * MAXN];
int size[2 * MAXN * MAXN];
int find(int x) {
if (parent[x] == x) return x;
return parent[x] = find(parent[x]);
}
void join(int x, int y) {
int px = find(x);
i... | 6 |
#include <bits/stdc++.h>
using namespace std;
int k, n, m;
long long p;
int a[1000000], l;
int main() {
scanf("%I64d%d", &p, &k);
while (p) a[++l] = p % k, p /= k;
for (int i = 1; i <= l; i++) {
a[i + 1] += a[i] / k;
a[i] %= k;
if (i % 2 == 0 && a[i]) a[i] = k - a[i], a[i + 1]++;
if (a[l + 1]) l++... | 6 |
#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<int, int> a, pair<int, int> b) { return a.second > b.second; }
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
unordered_map<int, int> mp;
int n, m;
cin >> n >> m;
int arr[m];
for (int i = 0; i < m; i++) {
cin >> arr... | 2 |
#include <bits/stdc++.h>
using namespace std;
int mpow(int base, int exp);
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
void solve() {
int n;
cin >> n;
int arr[22];
for (int i = 1; i <= n; i++) {
cin >> arr[i];
}
int chest = 0, biceps = 0, back = 0... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, b;
string s;
vector<pair<string, int>> c;
cin >> n;
map<string, int> a;
for (int i = 0; i < n; i++) {
cin >> s >> b;
c.push_back(make_pair(s, b));
if (a.find(s) == a.end()) {
a[s] = b;
} else
a[s] += b;
}
int m... | 3 |
#include <bits/stdc++.h>
using namespace std;
int b, c, d, e, f, i;
int a[4];
int main() {
cin >> b >> c >> d;
a[0] = b;
a[1] = c;
a[2] = d;
sort(a, a + 3);
e = a[1] - a[0];
f = a[2] - a[1];
d = e + f;
cout << d;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int N, M;
long long h(long long t) {
long long q = t / (M - 1);
long long r = t % (M - 1);
if (q % 2 == 0)
return r + 1;
else
return M - r;
}
long long ttg(long long t, long long s) {
long long h1 = h(t);
long long dir = (t / (M - 1)) % 2;
if (h1 == s)... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> cnt(n + 1);
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
++cnt[x];
}
int mx = *max_element(cnt.begin(), cnt.end());
int diff = n + 1 - count(cnt.be... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
if (n == 2)
cout << "1\n";
else if (n == 3)
cout << "7\n";
else {
if (n % 2 == 0) {
for (int i(1); i <= n / 2; i++) cout << "1";
cout << "\n";
} el... | 0 |
#include <bits/stdc++.h>
using namespace std;
void pre() {}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
pre();
int tests = 1;
while (tests--) {
string s;
cin >> s;
const set<char> vowelsEven = {'a', 'e', 'i', 'o', 'u',
'1', '3', '5', '7', '9'};
int c... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXK = 110;
const int MAXM = 110000;
const int M = 1E5;
int a[MAXK], f[MAXM][MAXK];
long long dp(long long n, int k) {
if (k == 0) return n;
if (n <= M && ~f[n][k]) return f[n][k];
long long ret = dp(n, k - 1) - dp(n / a[k], k - 1);
if (n <= M) f[n][k] = r... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int SZ = 1e5 + 10;
inline long long int max(long long int a, long long int b, long long int c) {
return max(max(a, b), c);
}
inline long long int min(long long int a, long long int b, long long int c) {
return min(min(a, b), c);
}
inline long long int max(long lon... | 5 |
#include <bits/stdc++.h>
long long mpow(long long a, long long n, long long mod) {
long long ret = 1;
long long b = a;
while (n) {
if (n & 1) ret = (ret * b) % mod;
b = (b * b) % mod;
n >>= 1;
}
return (long long)ret;
}
using namespace std;
int Z[4 * (int)(1e6 + 25)], a[(int)(1e6 + 25)];
int mod =... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxx = 2000 + 9;
bool ispalin[maxx][maxx];
int st[maxx];
int en[maxx];
int main() {
string s;
cin >> s;
int n = (int)s.size();
for (int i = 0; i < n; i++) {
for (int j = i; ~j; j--) {
if (j + 1 >= i - 1 || ispalin[j + 1][i - 1])
ispalin[j... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k, s, t, ans;
int main() {
cin >> n >> m;
while (n > 0 && m > 0) {
if (n > m) {
if (n >= 2 && m >= 1) {
n -= 2;
m -= 1;
++ans;
} else
break;
} else if (n >= 1 && m >= 2) {
n -= 1;
m -= 2;
++... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return a == 0 ? b : gcd(b % a, a); }
string filename = "test";
vector<pair<int, int> > dots;
vector<int> d_to_f;
struct S {
int x, y, r;
int p;
S() : p(-1) {}
bool operator<(const S& a) const { return r < a.r; }
};
vector<S>... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = (long long)(1e9 + 7);
const long long N = (long long)(1e5 + 7);
long long p[N];
long long h[N];
int n, m;
bool fun(long long dist) {
queue<long long> q;
for (int i = 0; i < m; i++) {
q.push(p[i]);
}
for (int i = 0; i < n; i++) {
if (q.e... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
for (int i = 21; i >= 0; i--) {
long long int res = ((1LL << (i + 1)) - 1) * 1LL * (1LL << (i));
long long int tmp = 0;
for (int j = 1; j <= (i + 1); j++) {
tmp = tmp + (1LL << (i + j - 1));
}
if (tmp != r... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long n, x[100005], h[100005];
long long dp[100005][3];
long long go(long long i, long long pichla) {
if (i > n) return 0;
if (dp[i][pichla] != -1) return dp[i][pichla];
long long ans = go(i + 1, 0);
long long add = 0;
if (pichla == 2) add = h[i - 1];
if (x[... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, y;
cin >> n >> x >> y;
int a = n / 2;
if (x >= a && x <= a + 1 && y >= a && y <= a + 1)
cout << "NO" << endl;
else
cout << "YES" << endl;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<long long>;
template <class T>
using min_queue = priority_queue<T, vector<T>, greater<T>>;
template <class T>
istream &operator>>(i... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, k;
cin >> n >> m >> k;
if (2l * m * n % k != 0) {
printf("NO\n");
return 0;
}
long long inN = n, inM = m, inK = k;
map<long long, int> nF, mF, kF;
for (long long i = 2; i * i <= n; ++i) {
while (n % i == 0) nF[i]++, n /... | 5 |
#include <bits/stdc++.h>
using namespace std;
const double PI = 22.0 / 7.0;
const double EPS = 1e-6;
const int infi = (int)1e9;
const long long infl = (long long)1e16;
const int MOD = (int)1e9 + 7;
const int MAX = (int)2e5 + 9;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, -1, 1, 1, -1, 1, -1};
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e17;
long long t, k, x, y, w, G, B;
vector<vector<pair<long long, long long>>> adj;
vector<long long> siz;
void dfs(long long v, long long p) {
siz[v] = 1;
for (pair<long long, long long> edge : adj[v]) {
long long u = edge.first, wei = edge.sec... | 6 |
#include <bits/stdc++.h>
using namespace std;
struct Node {
int id, v;
bool operator<(const Node &rhs) const {
if (v == rhs.v) return id > rhs.id;
return v > rhs.v;
}
};
int64_t sum1, sum2;
int zero;
int cnt;
set<Node> st;
set<Node> st2;
int main() {
int n;
scanf("%d", &n);
sum1 = 0;
sum2 = 0;
c... | 7 |
#include <bits/stdc++.h>
using namespace std;
bool cmp(int f, int s) { return f < s; }
int main() {
int n;
cin >> n;
string s;
cin >> s;
int ans = 0;
for (int i = 0; i < n; i++) {
int cur = 0;
int j = i;
for (j = i; s[j] == s[j + 1]; j++) {
if (j >= n - 1) break;
}
ans += j - i;
... | 0 |
#include <bits/stdc++.h>
const int INF = 1e18;
const int inf = 1e9;
const int MAXN = 3e5 + 200;
const long double eps = 1e-8;
const long double pi = acos(-1.0);
using namespace std;
int level[MAXN], parent[MAXN], tin[MAXN], tout[MAXN], dp[MAXN];
int up[MAXN][20];
vector<int> g[MAXN];
int n, m, timer;
int ans[MAXN];
boo... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100000;
vector<pair<int, int> > nbrs[MAX_N];
int ps[MAX_N], pcs[MAX_N], cis[MAX_N];
int dos[MAX_N], drs[MAX_N];
vector<pair<int, int> > mds[MAX_N];
int main() {
int n, k;
scanf("%d%d", &n, &k);
for (int i = 1; i < n; i++) {
int u, v, c;
scanf... | 6 |
#include <bits/stdc++.h>
using namespace std;
string d, s;
map<char, int> mp;
int q;
int a, b;
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> d;
for (int i = 0; i < d.size(); i++) mp[d[i]] = true;
cin >> s;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '*') a = true;
... | 4 |
#include <bits/stdc++.h>
using namespace ::std;
const int maxn = 1e5 + 500;
const int inf = 1e9 + 900;
int a[maxn];
bool b[maxn];
bool tah[maxn];
bool sar[maxn];
int m;
void solve(int n) {
int tol = n - 1;
for (int i = 0; i < n; i++) {
if (a[i] >= tol) {
a[i] = tol;
}
}
int l = 0;
int r = n - 1;... | 11 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
template <class c>
struct rge {
c b, e;
};
template <class c>
rge<c> range(c i, c j) {
return {i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
template <class c>
debug... | 9 |
#include <bits/stdc++.h>
using namespace std;
int MOD = 998244353;
int f[300001];
int pow(int n, int i) {
int a = n, ans = 1;
while (i > 0) {
if (i & 1) {
ans = (ans * 1LL * a) % MOD;
}
a = (a * 1LL * a) % MOD;
i = i >> 1;
}
return ans;
}
void dfs_visit(map<string, vector<string>> adj, map... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <class P, class Q>
ostream& operator<<(ostream& stream, pair<P, Q> v) {
stream << "(" << v.first << ',' << v.second << ")";
return stream;
}
template <class T>
ostream& operator<<(ostream& stream, const vector<T> v) {
stream << "[ ";
for (int i = 0; i < (in... | 10 |
#include <bits/stdc++.h>
using namespace std;
void MAIN();
int main() {
MAIN();
return 0;
}
const long long N = 1e6 + 1, mod = 1e9 + 7;
struct ii {
long long first;
long long second;
int id;
};
bool cmp(ii v, ii u) {
if (u.first == v.first) return u.second < v.second;
return u.first < v.first;
}
long long... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long exponentiation(long long base, long long exp) {
if (exp == 0) return 1;
if (exp == 1) return base % 1000000009;
long long t = exponentiation(base, exp / 2);
t = (t * t) % 1000000009;
if (exp % 2 == 0)
return t;
else
return ((base % 1000000009) ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, i, x, y, c = 0, d = 0;
cin >> n;
vector<long long int> v(n);
for (i = 0; i < n; i++) cin >> v[i];
sort(v.begin(), v.end());
x = v[0];
y = v[n - 1];
for (i = 0; i < n; i++) {
if (v[i] == x) c++;
if (v[i] == y) d++;
}
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 60;
const double inf = 1e14;
double dp[N][N];
int n;
struct nd {
int v, w;
double c;
} a[N];
bool cmp(nd x, nd y) { return x.v > y.v; }
bool cmp2(nd x, nd y) { return x.c < y.c; }
bool check(double mid) {
int i, j, k, p;
double sum;
for (i = 1; i <= ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 502;
int n, m, k;
int maze[MAX][MAX];
void traverseGraph(int x, int y) {
maze[x][y] = 2;
if (maze[x][y + 1] == 1) traverseGraph(x, y + 1);
if (maze[x][y - 1] == 1) traverseGraph(x, y - 1);
if (maze[x + 1][y] == 1) traverseGraph(x + 1, y);
if (maze[... | 4 |
#include <bits/stdc++.h>
using namespace std;
int count_symbol(const vector<string>& Board, char c) {
int result = 0;
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
if (Board[i][j] == c) {
++result;
}
}
}
return result;
}
bool all_is_symbol(char c1, char c2, char c3, cha... | 5 |
#include <bits/stdc++.h>
int main() {
long long int n, a = 0, b = 0, c = 0, i;
scanf("%I64d", &n);
for (i = 1; i <= n; i++) {
if (i % 3 != 0) {
a = i;
if (n > 2 * i) {
b = i;
if ((n - 2 * i) % 3 != 0) {
c = n - 2 * i;
break;
}
}
}
}
printf(... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int mo = 1000000007;
int POW(int a, int b) {
int ans = 1;
for (; b; b >>= 1, a = (long long int)a * a % mo)
if (b & 1) ans = (long long int)ans * a % mo;
return ans;
}
const int maxn = 3033333;
static int fac[maxn];
inline int combo(int n, int m) {
return ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
long long mp[5][N];
long long sum_up[N], sum_down[N];
struct node {
long long up, down;
long long ma;
} mpp[N];
int main() {
int t;
cin >> t;
while (t--) {
memset(mpp, 0, sizeof mpp);
long long m;
cin >> m;
for (int i = 1; i... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long T;
cin >> T;
while (T--) {
long long n, k;
cin >> n >> k;
vector<long long> a(n);
for (long long i = 0; i < n; i++) cin >> a[i];
sort(a.begin(), a.end());
long long sum = 0;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
vector<int> a(n + 1);
vector<int> pr(n + 1);
for (int i = 1; i <= n; i++) {
cin >> a[i];
pr[i] = pr[i - 1] | a[i];
}
vector<int> sf(n + 2);
for (int i = n; i >= 1; i--) {
sf[i] = sf[i + 1] | a[i];
};
int ans = ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1ll << 32;
long long bigmod(long long a, int p, long long int m) {
if (p == 0) return 1;
if (p & 1) {
return ((a % m) * (bigmod(a, p - 1, m))) % m;
} else {
long long tmp = bigmod(a, p / 2, m);
return (tmp * tmp) % m;
}
}
long long ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e7;
const int MOD = 1e9 + 7;
int n, m, k, sz[1005] = {0}, cnt, cnt2, sz2[1005] = {0};
vector<vector<int> > adjlist;
bool gov[1005] = {0}, vis[1005] = {0};
void dfs(int u) {
cnt++;
vis[u] = 1;
for (int i = 0; i < ((int)(adjlist[u]).size()); i++) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<int> v[400005];
int main() {
scanf("%d %d", &n, &k);
for (int i = (0); i < (k); i++) {
int m;
scanf("%d", &m);
v[i].resize(m);
for (int &x : v[i]) scanf("%d", &x);
}
int res = 0;
for (int i = (0); i < (k); i++) {
int li = int(v... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5;
const double pi = acos(-1.0);
struct Point {
double x, y;
void Scan() { scanf("%lf %lf", &x, &y); }
} ver[MAXN + 5];
struct msg {
double ang;
int v;
bool operator==(const msg &a) { return ang == a.ang && v == a.v; }
void Print() { printf("%... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
const int MOD = 1000000007;
const int nmax = 201234;
int n, k, a[nmax], cnt[2][nmax], res;
int main() {
scanf("%d%d", &n, &k);
for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
sort(a, a + n);
for (int i = 0; i < n; ++i) {
int b = a[i];... | 3 |
#include <bits/stdc++.h>
using std::priority_queue;
struct node {
int n;
long long ans;
node(int n, long long ans) {
this->n = n;
this->ans = ans;
}
friend bool operator<(node a, node b) { return a.ans > b.ans; }
};
int money[3011][3010];
int cnt[3010];
int main() {
int n, m, u, v;
scanf("%d%d", &... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long n, m, t;
char a[107][57];
vector<pair<int, int>> v;
int main() {
int cnt = -1;
scanf("%lld%lld", &n, &m);
sc... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double x1, y1, x2, y2, xn, yn;
double wx1, wy1, wx2, wy2;
double v, t, m, d;
cin >> x1 >> y1 >> x2 >> y2;
cin >> v >> t;
cin >> wx1 >> wy1;
cin >> wx2 >> wy2;
double l = 0, r = 1e18, eps = 1e-9;
while (r - l > eps) {
m = (l + r) / 2;
i... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d, e, sum;
int main() {
cin >> a >> b >> c >> d >> e;
while (a >= 1 && b >= 1 && c >= 2 && d >= 7 && e >= 4) {
sum++;
a -= 1;
b -= 1;
c -= 2;
d -= 7;
e -= 4;
}
cout << sum;
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
namespace RenaMoe {
const int N = (1 << 17) + 5;
const int M = 1e6 + 5;
const int P = 1e9 + 7;
const int inv2 = (P + 1) >> 1;
inline void FWT_or(int *f, int n, int op) {
for (int mid = 1; mid < n; mid <<= 1)
for (int i = 0; i < n; i += mid << 1)
for (int j = 0; ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int read() {
int x = 0, sgn = 1;
char ch = getchar();
for (; !isdigit(ch); ch = getchar())
if (ch == '-') sgn = -1;
for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48);
return x * sgn;
}
const int N = 3e5 + 10;
int x[N], y[N], a[N], b[N], n... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[100005];
map<int, int> l, r;
int main() {
scanf("%d%d", &n, &m);
if (n == 1) return printf("0\n"), 0;
for (int i = 1; i <= m; i++) scanf("%d", &a[i]);
for (int i = m; i >= 1; i--) {
l[a[i] + i] = l[a[i] + i + 1] + 1;
r[a[i] - i] = r[a[i] - i ... | 8 |
#include <bits/stdc++.h>
using namespace std;
static const int MAXN = 1e5 + 10;
int n;
int sum;
int a[MAXN];
map<int, int> mp;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
char x;
scanf(" %c", &x);
if (x - 48)
++sum;
else
--sum;
a[i] = sum;
if (!mp[sum]) mp[sum] =... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
long long n, k, tmp, su[MAXN], num[MAXN], h[MAXN];
vector<int> Mat[MAXN];
long long ans;
bool cs[MAXN];
void dfs(int v, int p) {
h[v] = h[p] + 1;
for (int i = 0; i < Mat[v].size(); i++)
if (Mat[v][i] != p) {
dfs(Mat[v][i], v);
... | 5 |
#include <bits/stdc++.h>
using namespace std;
struct xx {
int x, w;
} a[200010];
int ans = 0;
bool cmp(xx a, xx b) { return a.x < b.x; }
int q[200010], f[200010];
void insertk(int h, int v) {
q[v] = min(q[v], h);
while (q[v - 1] > h) {
q[v - 1] = h;
v--;
}
}
int getk(int x) {
int l = 1, r = ans;
whi... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);
const double EPS = 1e-8;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template <class T>
T sqr(T a) {
return a * a;
}
template <class T>
T gcd(T a, T b) {
return b ? g... | 1 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
int SGN(double a) { return ((a > EPS) ? (1) : ((a < -EPS) ? (-1) : (0))); }
int CMP(double a, double b) { return SGN(a - b); }
struct node {
int x, y;
node(int x = 0, int y = 0) : x(x), y(y) {}
};
int dir[][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
map<int, int> mp;
int n;
struct pnt {
int x, w;
bool operator<(const pnt &p) const { return x < p.x; }
} p[maxn];
int ask(int x) {
int res = 0;
for (int i = x; i > 0; i -= (i & -i))
if (mp.count(i)) res = max(res, mp[i]);
return res;
}... | 5 |
#include <bits/stdc++.h>
using namespace std;
int a[300005], b[300005];
int main() {
ios::sync_with_stdio(false);
int T;
cin >> T;
while (T--) {
int pos1 = 0, pos2 = 0;
string s;
cin >> s;
int len = s.length();
for (int i = 0; i < len; i++) {
int d = s[i] - '0';
if (d % 2) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 5;
const int Maxm = 20;
int n, m;
int a[Maxn], b[Maxm];
char B[Maxn][Maxm];
int has[Maxm];
bool gotres;
void Print() {
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) printf("%c", B[i][j]);
printf("\n");
}
}
bool checkRow(int r, int c,... | 8 |
#include <bits/stdc++.h>
using namespace std;
void Solve() {
long long n, m, rb, cb;
long long rd, cd;
int dr = 1;
int dc = 1;
cin >> n >> m >> rb >> cb >> rd >> cd;
int a, b;
if (rb <= rd)
a = rd - rb;
else
a = n - rd + n - rb;
if (cb <= cd)
b = cd - cb;
else
b = m - cd + m - cb;
... | 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("sse4.2")
using namespace std;
mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());
void flush() { cout << flush; }
void flushln() { cout << endl; }
void println() { cout << '\n'; }
template <class T>
void pr... | 6 |
#include <bits/stdc++.h>
using namespace std;
int arr[500] = {0};
int main() {
string str1, str2;
cin >> str1 >> str2;
int l, m, temp = 0, res = 0, res2 = 0;
l = str1.length();
m = str2.length();
int mark[l];
fill(mark, mark + l, 0);
for (int i = 0; i < m; i++) {
temp = str2[i];
arr[temp]++;
}... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
int n;
cin >> n;
int res = 0;
int prev = 0, f = 0;
vector<int> v(n);
for (int i = 0; i < n; ++i) {
cin >> v[i];
}
for (int i = 1; i < n; ++i) {
int a, prev = v[i - 1];
a = v[i];
if (a + prev == 5) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, k, i, j, v;
cin >> n >> m >> k;
int s[102] = {};
int y[102] = {};
int a[102][102];
for (i = 1; i <= n; ++i)
for (j = 1; j <= m; ++j) cin >> a[i][j];
for (j = 1; j <= m; ++j) {
for (i = 1; i <= n; ++i) {
v = a[i][j];
i... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 60;
int n, m, ans;
string s;
vector<int> row[maxn], col[maxn];
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> s;
for (int j = 1; j <= m; j++) {
if (s[j - 1] == '#') {
row[i].push_back(j);
col[j].push_back... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 600000;
int n, m, ver[N], nex[N], head[N], cnt, A, B, C, d[N], x, y, vis[N], a[3];
unsigned long long res, sum[N];
vector<int> v[N];
void add(int x, int y) { ver[++cnt] = y, nex[cnt] = head[x], head[x] = cnt; }
int main() {
memset(vis, -1, sizeof(vis));
sc... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long cl(long double a) {
if (a > (long long)a) {
return (long long)a + 1;
} else {
return (long long)a;
}
}
long long flr(long double a) { return (long long)a; }
const long long M = 2e5 + 100;
long long n, m, a[M];
void solve() {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int h, m, n;
scanf("%d %d:%d", &n, &h, &m);
if (m >= 60) m %= 10;
if (n == 12 && (h > 12 || h == 0)) {
if (h % 10 == 0)
h = 10;
else
h = h % 10;
} else {
if (n == 24 && h >= 24) {
h = h % 10;
}
}
printf("%02d:%02d... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int M = 1000000007;
string s[150000];
long long val[15], mul10[15];
int main() {
string str;
while (cin >> str) {
int n;
scanf("%d", &n);
for (int i = 0; i < 10; i++) {
val[i] = i;
mul10[i] = 10;
}
for (int i = 0; i < n; i++) cin >>... | 6 |
#include <bits/stdc++.h>
using namespace std;
int vv[4000010], nxt[4000010], h[2010], e;
int dfn[2010], low[2010], sta[2010], deep, flag, col[2010];
int top;
int num[2010], cnt[2010];
void add(int u, int v) {
vv[e] = v, nxt[e] = h[u], h[u] = e++;
vv[e] = u, nxt[e] = h[v], h[v] = e++;
}
bitset<2010> bb;
void dfs(int... | 9 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.