solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int maxN = 24;
const int inf = 1000000000;
int n, xs, ys;
int a[maxN][maxN];
int dp[1 << maxN];
int x[maxN], y[maxN];
int dist(int x1, int y1, int x2, int y2) {
int dx = (x1 - x2);
int dy = (y1 - y2);
return dx * dx + dy * dy;
}
int main() {
cin >> xs >> ys;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
map<string, int> m;
pair<char, int> w[4];
int main() {
int x, y, z, a, b = 0, c = 0, m, n, m1 = 0, n1 = 0, m2 = 0, n2 = 0;
cin >> x >> y >> z;
a = y - x;
m = z - 1;
n = x - z;
for (int i = 0;; i++) {
b = c;
c++;
c += m2;
if (m2 + 1 <= m) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
std::istream& operator>>(std::istream& i, pair<T, U>& p) {
i >> p.first >> p.second;
return i;
}
template <typename T>
std::istream& operator>>(std::istream& i, vector<T>& t) {
for (auto& v : t) {
i >> v;
}
return i;
}
templat... | 17 |
#include <bits/stdc++.h>
using namespace std;
multiset<int> s;
int n, a[100010], b[100010], i, j, ans;
int main() {
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &j);
a[j] = i;
}
for (i = 0; i < n; i++) {
scanf("%d", &b[i]);
s.insert(i - a[b[i]]);
}
for (i = 0; i < n; i++) {
ans... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1024;
bool used[MAXN + 1];
int main() {
int n, k;
cin >> n >> k;
if (n == 1)
cout << "! " << 1 << endl;
else {
int block = k == 1 ? 1 : k / 2;
int numB = n / block;
for (int jump = 1; jump < numB; jump++) {
for (int startB = 0;... | 22 |
#include <bits/stdc++.h>
using namespace std;
typedef vector<pair<int, int> > vii;
int n, x, maks, mins, jml;
int main() {
ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
cin >> x;
maks = x;
mins = x;
for (int i = 1; i < n; i++) {
cin >> x;
if (x > maks) {
maks = ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5005;
int dp[maxn][maxn];
char s[maxn], t[maxn];
int main() {
int n, m;
scanf("%d%d", &n, &m);
scanf("%s", s + 1);
scanf("%s", t + 1);
int ans = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
dp[i][j] = max(dp[i][j - ... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2010;
int dp[N][10][10][10][10];
int a[N], b[N];
int n;
bool update(int &x, int y) {
if (y == -1) return false;
if (x == -1 || x > y) {
x = y;
return true;
}
return false;
}
struct point {
int p, x, y, z, f, dis;
point() {}
point(int p, i... | 16 |
#include <bits/stdc++.h>
using namespace std;
long long cnt1[30], cnt2[30];
int main() {
std::ios_base::sync_with_stdio(false);
long long n;
cin >> n;
string s, t;
cin >> s >> t;
for (long long i = 0; i < s.length(); i++) {
cnt1[s[i] - 'a']++;
}
for (long long j = 0; j < s.length(); j++) {
cnt2[... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n == 2) return cout << -1 << endl, 0;
cout << 6 << endl;
cout << 10 << endl;
cout << 15 << endl;
int a = 6;
for (int i = 3; i < n; i++) {
a += 6;
cout << a << endl;
}
}
| 9 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1000000000")
using namespace std;
const int maxn = (int)1e6 + 10;
bool used[maxn];
int main() {
int n;
cin >> n;
int y = 0;
for (int i = 0; i < n; i++) {
int x;
scanf("%d", &x);
used[x] = true;
}
int z = 25 - n;
int pos = 1;
while (z >... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200010;
class FenwickTree {
public:
void update(int i) {
for (; i < MAXN; i += i & -i) BIT[i]++;
}
int query(int i) {
int ans = 0;
for (; i > 0; i -= i & -i) ans += BIT[i];
return ans;
}
FenwickTree() { memset(BIT, 0, sizeof(BIT))... | 15 |
#include <bits/stdc++.h>
int main() {
constexpr long long int MOD = 1000000007;
std::cin.tie(0);
std::cin.sync_with_stdio(false);
int n, m;
std::cin >> n >> m;
std::vector<long long int> factorial(std::max(n, m) + 1, 1),
inv(std::max(n, m) + 1, 1), inv_fact(std::max(n, m) + 1, 1);
for (auto i = 2; i... | 9 |
#include <bits/stdc++.h>
using ll = long long;
const int MOD = 998244353;
struct mint {
public:
int v;
mint(int _v = 0) : v(_v) {
if (v < -MOD || MOD <= v) v %= MOD;
if (v < 0) v += MOD;
}
mint& operator+=(const mint& o) {
if ((v += o.v) >= MOD) v -= MOD;
return *this;
}
mint& operator-=(co... | 18 |
#include <bits/stdc++.h>
int n;
char s[20000];
int main() {
scanf("%d%s", &n, s);
int ans, tmp, i;
for (i = ans = 0; i < n; i++) {
if ((i % 2) == ((s[i] - '0') % 2)) ans++;
}
for (i = tmp = 0; i < n; i++) {
if ((i % 2) != ((s[i] - '0') % 2)) tmp++;
}
if (ans > tmp) ans = tmp;
printf("%d\n", ans)... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, i;
cin >> n >> m;
int a[n];
for (i = 1; i < n; i++) {
cin >> a[i];
}
for (i = 1; i < n;) {
i = i + a[i];
if (i == m) {
cout << "YES" << endl;
return 0;
}
}
cout << "NO" << endl;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, c = 0;
cin >> n;
int i = n;
while (i--) {
if (n >= 100) {
if (n % 100 == 0) {
c = n / 100;
break;
} else {
c = n / 100;
n = n % 100;
}
} else if (n >= 20) {
n = n - 20;
c++;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
int a[n + 1];
int b[n];
int c[n - 1];
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n - 1; i++) cin >> b[i];
for (int i = 1; i <= n - 2; i++) cin >> c[i];
sort(a + 1, a + n ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
int n, a{0}, b{0}, eo{0}, oe{0}, oo{0};
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a >> b;
if (a % 2 == 0 & b % 2 != 0) eo++;
if (a % 2 != 0 & b % 2 == 0) oe++;
if (a % 2... | 4 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > v;
vector<int> ans;
int main() {
int n, m;
cin >> n >> m;
v.resize(m);
for (int i = 0; i < m; i++) cin >> v[i].first >> v[i].second;
for (int num = 1; num <= 101; num++) {
bool ff = false;
for (int k = 1; k <= 101; k++) {
if (... | 7 |
#include <bits/stdc++.h>
using namespace std;
int N;
bool graph[30][30];
int adj[30];
int x[(1 << 23)];
int y[(1 << 23)];
bitset<(1 << 23)> fast_convolution(bitset<(1 << 23)> X, bitset<(1 << 23)> Y) {
int i, j;
for ((i) = 0; (i) < (int)((1 << 23)); (i)++) x[i] = X[i];
for ((i) = 0; (i) < (int)(23); (i)++)
for... | 23 |
#include <bits/stdc++.h>
using namespace std;
string s[] = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "B", "H"};
vector<pair<string, int> > hihi[15];
int k = 0;
int dem = 1;
int j = 1;
string xuli(string x, string y, string z) {
int demx, demy, demz;
for (int i = 0; i < 12; i++) {
if (s[i] == x) dem... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 6e5 + 10;
struct Tgraph {
static const int maxn = 3e5 + 10, maxm = 6e5 + 10;
struct Tedge {
int son, ok;
Tedge *pre, *bro;
void add(int s_, Tedge *pre_) {
son = s_;
pre = pre_;
}
} edge[maxm], *now[maxn];
int tot;
void ... | 15 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 510;
const long long INF = 1e18;
long long l, r, k, dp[20][(1 << 10) + 2][10], cnt[20][(1 << 10) + 2][10],
mod = 998244353;
long long poww(long long a, long long b) {
if (b == 0) return 1;
long long x = poww(a, b / 2) % mod;
if (b & 1)
r... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, ans = 0;
long long a;
map<long long, int> mp;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a;
mp[a]++;
if (ans < mp[a]) ans = mp[a];
}
cout << ans << endl;
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, m;
cin >> n >> m;
long long int a[m], b[m], c[m];
for (long long int i = 0; i < m; i++) {
cin >> a[i] >> b[i] >> c[i];
}
long long int net[n + 1];
memset(net, 0, sizeof(net));
for (long long int i = 0; i < m; i++) {
net[... | 5 |
#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#define ll long long
#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define per(i, b, a) for(int i = (b); i >= (a); i--)
#define MP make_pair
#define PB push_back
using namespace std;
const int N = 3e5 + 5, inf = 0x3f3f... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, t, d[30][15][15][5][5], i, j, l, a, b, s, S;
int main() {
cin >> n >> t;
for (i = 1; i < 5; i++)
for (j = 1; j < 5; j++)
if (i != j) d[2][0][0][i][j] = 1;
for (i = 3; i <= n; i++)
for (j = 0; j <= t; j++)
for (l = 0; l <= t; l++)
for... | 11 |
#include <bits/stdc++.h>
using namespace std;
priority_queue<long long, vector<long long>, greater<long long> > Q1, Q2;
set<long long> used1, used2;
int n, p[200], q[200], tota, totb, lenp, lenq;
long long k, ans, a[1000010], b[1000010];
inline long long judge(long long x) {
int h2 = totb;
long long ans = 0;
for ... | 16 |
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
long long int k, pa, pb;
long long int f[1009][1009];
long long int pow(long long int a, long long int x) {
long long int ans = 1;
while (x > 0) {
if (x & 1) {
ans *= a;
ans %= mod;
}
a *= a;
a %= mod;
x... | 14 |
#include <bits/stdc++.h>
using namespace std;
int c[400001];
vector<int> adjList[400001];
vector<pair<int, int> > events[400001];
long long int diff[400002], ans = 0;
int parent[400001];
int doDFS(int u, int p) {
int i;
parent[u] = p;
for (i = 0; i < adjList[u].size(); i++) {
int v = adjList[u][i];
if (v ... | 25 |
#include <bits/stdc++.h>
using namespace std;
string str[8];
int main() {
for (int i = 0; i < 8; i++) cin >> str[i];
int d_w = 88, d_b = -1;
for (int j = 0; j < 8; j++) {
for (int i = 0; i < 8; i++) {
if (str[i][j] == 'B') break;
if (str[i][j] == 'W') {
d_w = min(d_w, i);
}
}
}... | 4 |
#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
using namespace std;
void _main();
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
_main();
}
const int inf = INT_MAX / 2;
const long long infl = 1LL << 60;
template <class T>
bool chmax(T& a, const T& b) {
if (a < b) {
a = b;
return 1;
}
re... | 14 |
#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;
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 ... | 5 |
#include <bits/stdc++.h>
double PI = 3.1415926535;
const int N = (int)(1 * 1e6 + 10);
using namespace std;
long long int power(long long int a, long long int b) {
long long int ans = 1;
while (b) {
if (b & 1) {
ans = (ans * a) % 1000000007;
}
b >>= 1;
a = (a * a) % 1000000007;
}
return ans... | 11 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
constexpr int MX = 5005;
int n[15], a[15][MX], pre[1 << 15];
bitset<MX> vis[15];
bitset<1 << 15> cs, dp;
vector<ii> G[15][MX], ch[1 << 15];
void dfs(int i, int j, int m, vector<ii>& S) {
m |= (1 << i);
vis[i][j] = 1;
S.... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int c = 12;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int q;
cin >> q;
for (int i = 0; i < q; ++i) {
int h, w, mid1, mid2;
cin >> h >> w;
int pic[h][w];
mid1 = (h >> 1) - 1;
mid2 = mid1 + 1;
for (int i = 0; i < h; ++i... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long two[1000005];
void values_of_power() {
two[0] = 1;
for (int i = 1; i < 1000005; i++) two[i] = (2 * two[i - 1]) % 998244353;
}
void solve() {
int n, i;
long long ans, last, x, val;
cin >> n >> last;
ans = last * two[n - 1];
ans %= 998244353;
val = a... | 12 |
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
const ll N = 1e9 + 7, N1 = 1e6 + 7;
long long fact(ll n);
long long nPr(ll n, ll r) { return fact(n) / fact(n - r); }
long long fact(ll n) {
ll res = 1;
if (n == 0 || n == 1) return res;
for (ll i = 2; i <= n; i++) res... | 7 |
#include <bits/stdc++.h>
using namespace std;
struct bug {
int diff, index;
bug(int d = 0, int i = 0) : diff(d), index(i) {}
bool operator<(const bug &other) const { return diff > other.diff; }
};
struct stu {
int lev, cla, index;
stu(int l = 0, int c = 0, int i = 0) : lev(l), cla(c), index(i) {}
bool opera... | 11 |
#include <bits/stdc++.h>
using namespace std;
void _print(bool t) { cerr << t; }
void _print(long long t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(double t) { cerr << t; }
template <class T>
void _print(vector<T> v) {
cerr << "[ ";
for (T i : v) {
_prin... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, cur = 1;
cin >> n;
for (int i = 0; i < n; i++) {
int s, d;
cin >> s >> d;
if (cur <= s) {
cur = s;
} else {
int diff = cur - s, mul = diff / d + (diff % d != 0);
cur = s + mul * d;
}
cur++;
}
cout << cu... | 1 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > A;
vector<pair<int, int> > tr;
struct Van {
int l, r, l2, r2;
Van(int l, int r, int l2, int r2) : l(l), r(r), l2(l2), r2(r2) {}
};
vector<Van> ans;
int cell(pair<int, int> a) { return A[a.first][a.second]; }
pair<int, int> getmin(int l, int r) {
p... | 7 |
#include <bits/stdc++.h>
using namespace std;
string s;
long long n, dp[111][2];
long long ans;
void init() {
cin >> s;
n = s.size();
}
int main() {
init();
s.push_back(s[0]);
dp[n][0] = 1;
dp[n][1] = 0;
for (int i = n - 1; i >= 0; i--) {
if (s[i] == 'A' && s[i + 1] == 'A') {
dp[i][0] = dp[i + 1... | 13 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = (long long)(1e9 + 7);
long long modpow(long long a, long long b) {
if (!b) return 1;
a %= mod;
return modpow(a * a % mod, b / 2) * (b & 1 ? a : 1) % mod;
}
const int z = 50;
int dsu[z], sz[z];
void init() {
for (int i = 0; i < z; i++) dsu[i] = ... | 15 |
#include <bits/stdc++.h>
using namespace std;
const long long linf = 4000000000000000000LL;
const long long inf = 1000000007;
void pv(vector<int> a) {
for (auto& x : a) cout << x << " ";
cout << endl;
}
void pv(vector<long long> a) {
for (auto& x : a) cout << x << " ";
cout << endl;
}
void pv(vector<vector<int>... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e5;
const int N = 1e4 + 5;
int n, m, k, x[N], y[N], flag, dis[N];
bool vis[N];
int S, T;
void spfa() {
deque<int> q;
dis[S] = 0;
q.push_back(S);
while (q.size()) {
int u = q.front();
q.pop_front();
vis[u] = 0;
for (register int i = 1... | 14 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const long long INF = 2e18;
void print(int a[], int n) {
for (int i = 0; i < n; i++) cout << a[i] << " ";
cout << "\n";
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
int tc = 1;
while (tc--) {
int n, k;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n;
int k;
int con[2][42];
int flag[1 << 20];
int __builtin_popcount(int num) {
int r = 0;
while (num) {
if (num & 1) {
r++;
}
num >>= 1;
}
return r;
}
int main() {
cin >> n >> k;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++)... | 19 |
#include <bits/stdc++.h>
int main() {
int q, a[100], n, i, j, f = 1, k;
scanf("%d", &q);
for (i = 0; i < q; i++) {
scanf("%d", &n);
for (j = 0; j < n; j++) scanf("%d", &a[j]);
for (j = 0; j < n - 1; j++) {
for (k = j + 1; k < n; k++) {
if (a[j] == (a[k] - 1) || a[j] == (a[k] + 1)) {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6;
char s[N];
stack<char> lol;
map<char, char> sweet;
int main() {
scanf("%s", s);
string ok = s, sh = ")]>}", sh2 = "([<{";
int os = 0;
for (int i = 0; i < 4; i++) sweet[sh2[i]] = sh[i];
for (int i = 0; i < ok.size(); i++) {
if (lol.size() == ... | 6 |
#include <bits/stdc++.h>
using std::pair;
using std::vector;
const int N = 400005, MOD = 1000000007;
inline int mval(int first) { return first >= MOD ? first - MOD : first; }
inline void inc(int &first, int a) { first = mval(first + a); }
int n, t, in[N], f[N], g[N], a[N], b[N], id[N], sum[N];
int mx[N];
vector<int> qi... | 22 |
#include <bits/stdc++.h>
using namespace std;
int lim = 1 << 19;
long long mod = 1000000007;
const int N = 1000005;
const double G = 9.8;
int n, m;
double V, a[N];
map<double, double> walls;
pair<int, double> orig_order[N];
pair<double, double> ans[N];
double get_y(double alpha, double x) {
double t = x / V / cos(alp... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
vector<pair<int, int> > G[N];
int deg[N], ans[N];
int r;
int next(int x) { return x % r + 1; }
void dfs(int x, int fa, int color) {
for (int i = 0; i < (int)G[x].size(); i++) {
if (G[x][i].first == fa) continue;
color = next(color);
ans... | 11 |
#include <bits/stdc++.h>
using namespace std;
vector<int> vec[200005];
int fina[200005];
int a[200005][5] = {0};
int sum[200005];
int cha[200005];
struct node {
int now;
int other;
} nd[200005];
bool cmp(int a, int b) { return a > b; }
void init(int n) {
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= 4; ... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long dp1[200000];
long long dp2[200000];
void run() {
long long n;
scanf("%lld", &n);
vector<long long> al(n + 2);
al[0] = 0;
for (int i = 1; i <= n; i++) scanf("%lld", &al[i]);
al[n + 1] = 0;
dp1[0] = 0;
for (int i = 1; i <= n; i++) {
dp1[i] = min(... | 8 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using pii = pair<int, int>;
const ll MOD = 998244353;
const ll MD = 998244351;
int N, K;
ll I[4000005];
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> N >> K;
ll S = 0, T = 1, U = 1;
I[1] = 1;
for (int i = 2; i ... | 22 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100001;
int n;
map<int, int> m[MAXN];
int f[MAXN], s[MAXN], p[MAXN], cnt = 0, z;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
int v, c, l, r;
scanf("%d%d%d%d", &v, &c, &l, &r);
if (r + c < MAXN && (!l || m[l].find(r + c) != m... | 16 |
#include <bits/stdc++.h>
using namespace std;
priority_queue<pair<long long, long long> > Q;
long long D[1010101], S[1010101], K[1010101];
bool chk[1010101];
long long n, k, ans1, ans2;
int main() {
long long i, j, s, x, t, f;
scanf("%lld%lld", &n, &k);
for (i = 1; i <= n; i++) {
D[i] = i;
S[i] = 1;
}
... | 20 |
#include <bits/stdc++.h>
using namespace std;
template <typename... T>
void read(T &...args) {
((cin >> args), ...);
}
template <typename... T>
void write(T... args) {
((cout << args << " "), ...);
cout << "\n";
}
long long gcd(long long a, long long b) {
if (b > a) {
return gcd(b, a);
}
if (b == 0) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int Nmax = 7, Mmax = 25, Confmax = 161051 + 10, Smax = 16;
vector<int> confs[4];
int Rows[Nmax], Cols[Mmax];
int matrix[Mmax];
bitset<Confmax> dp[2][Smax];
char next1[Mmax][Smax][Confmax];
int canSub[35][Confmax];
int countSecvs(int x) {
int pos = 0, ret = 0;
whil... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b, c;
cin >> a >> b >> c;
int f, m, s;
f = a.size(), m = b.size(), s = c.size();
if (f == 4 && m == 8 && s == 8 || f == 8 && m == 5 && s == 5 ||
f == 5 && m == 4 && s == 4) {
cout << "F";
} else if (m == 4 && f == 8 && s == 8 || ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18, MOD = 1e9 + 7, N = 1e10 + 100;
mt19937 rng(time(0));
void setIO(string name = "") {
ios::sync_with_stdio(false);
cin.tie(0);
if (name.size()) {
freopen((name + ".in").c_str(), "r", stdin);
freopen((name + ".out").c_str(), "w", stdou... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, table = 0, maxx = 0, x;
cin >> n;
multiset<int> s;
for (int i = 0; i < 2 * n; i++) {
cin >> x;
if (s.find(x) == s.end()) {
s.insert(x);
table++;
if (table > maxx) maxx = table;
} else {
table--;
}
}
cou... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> g, d;
vector<int> q;
int mx = 0;
void dfs(int v, int p, int depth) {
d[depth].emplace_back(v);
mx = max(mx, depth);
for (auto &to : g[v]) {
if (to == p) continue;
dfs(to, v, depth + 1);
}
}
void dfs1(int v, int p, int depth, int need) {
... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2005;
int n;
bool a[MAXN][MAXN];
bool u[MAXN][MAXN];
bool b[MAXN][MAXN];
int maX = -1, may = -1, mix = -1, miy = -1;
int stk[MAXN * MAXN][2], top = 0;
void dfs(int x, int y) {
u[x][y] = true;
top++;
stk[top][0] = x;
stk[top][1] = y;
if (maX == -1 ... | 11 |
#include <bits/stdc++.h>
using namespace std;
bool isprime(int m) {
int flag = 0;
int n = m / 2;
for (int i = 2; i <= n; i++) {
if (m % i == 0) {
flag = 1;
break;
}
}
if (flag == 0) return true;
return false;
}
int main() {
int n, m = 0;
cin >> n;
int count = 0;
if (n == 2997) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 123;
int xa[N];
int xb[N];
int ya[N];
int yb[N];
struct pt {
int x, y;
pt(int x, int y) : x(x), y(y) {}
};
inline int area(pt a, pt b, pt c) {
return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
}
inline bool intersect_1(int a, int b, int c, in... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int64_t N = 111;
int64_t a[N][N];
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int64_t n, m, k, mn = 0, ans = 0;
cin >> n >> m >> k;
for (int64_t i = 0; i < n; ++i)
for (int64_t j = 0; j < m; ++j) cin >> a[j][i];
for (int64_t j = 0; j <... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)4e5 + 10;
const int mod = (int)1e9 + 7;
const int inf = (1 << 30) - 1;
int n, m;
set<int> s[maxn];
void solve() {
cin >> n >> m;
for (int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
s[x].insert(y);
s[y].insert(x);
}
for (int i... | 10 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline bool smax(T& x, const U& y) {
return y > x ? (x = y, 1) : 0;
}
template <typename T, typename U>
inline bool smin(T& x, const U& y) {
return y < x ? (x = y, 1) : 0;
}
inline int read() {
int w = 0, p = 0;
char c;
while (!is... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 202, K = 864;
int cnt[4][N][N][N], a[N], n, k;
double dp[N][N], pd[N][N], ans;
int S(int x) { return x * (x + 1) / 2; }
int main() {
scanf("%d%d", &n, &k);
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
for (int i = 0; i < n; i++)
for (int j = 0; j ... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5005;
int a[MAXN];
int Ans[MAXN];
int Hash[MAXN];
int main() {
int n;
while (~scanf("%d", &n)) {
memset(Ans, 0, sizeof(Ans));
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
}
for (int i = 1; i <= n; ++i) {
memset(Hash, 0,... | 7 |
#include <bits/stdc++.h>
const int inf = 1039074182;
using namespace std;
char c[1005][1005];
char g[1005][1005];
int n, m;
const int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};
bool out(int x, int y) { return (x < 0 || y < 0 || x >= n || y >= m); }
bool ok(int x, int y) {
for (i... | 5 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > v;
int a, b, x, y, i, j;
int main() {
cin >> x >> y >> a >> b;
for (i = a; i <= x; i++)
for (j = b; j <= y; j++)
if (j < i) v.push_back(make_pair(i, j));
sort(v.begin(), v.end());
cout << v.size() << endl;
for (i = 0; i < v.size()... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
int pi[maxn][30], p[maxn];
int dp[maxn][maxn][maxn], go[maxn][maxn][maxn];
int to[maxn][maxn][maxn];
int main() {
string c, d, e;
string a = " ", b = " ", virus = " ";
cin >> c >> d >> e;
a += c, b += d, virus += e;
for (int i = 0; i <= 'z' -... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
char arr[n];
int x = 0, X = 0;
for (int q = 0; q < n; q++) {
cin >> arr[q];
if (arr[q] == 'x')
x++;
else
X++;
}
int toChange = X - x;
cout << abs(toChange / 2) << "\n";... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T sqr(T x) {
return x * x;
}
char str[101][101], str2[101][101];
int dead_flag;
int n, m;
char a[101][101];
int first_time = 1;
inline vector<pair<int, int> > gao(int n, int m, char str[101][101]) {
vector<pair<int, int> > ret;
int rotate = n & 1;
... | 19 |
#include <bits/stdc++.h>
using namespace std;
template <typename flow_t, typename cost_t>
struct min_cost_flow {
static const flow_t FLOW_INF = numeric_limits<flow_t>::max() / 2;
static const cost_t COST_INF = numeric_limits<cost_t>::max() / 2;
struct edge {
int node, rev;
flow_t capacity;
cost_t cost... | 27 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch <= '9' && ch >= '0') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
const int N = 100100;
i... | 10 |
#include <bits/stdc++.h>
using namespace std;
string s;
int ip1, ip2;
int main() {
cin >> s;
for (int i = 0; i < s.size(); i++) {
if (s[i] != '0') {
ip1 = i;
break;
}
}
for (int i = s.size() - 1; i >= 0; i--) {
if (s[i] != '0') {
ip2 = i;
break;
}
}
vector<char> v;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1.01e4;
const int N = 1 << 18;
struct Edge {
int to, cap, flow;
int id;
};
struct Graph {
int n;
vector<vector<int> > e;
vector<Edge> edges;
vector<int> d, c;
Graph() {}
Graph(int _n) {
n = _n;
e.resize(n);
}
void addEdge(int... | 22 |
#include <bits/stdc++.h>
using namespace std;
int A[200010];
int l[200010];
int r[200010];
int size[200010];
int answer[200010];
int n;
void left() {
stack<int> st;
for (int i = 0; i < n; i++) {
while (st.size() && A[st.top()] >= A[i]) st.pop();
if (st.size() == 0)
l[i] = -1;
else
l[i] = st.... | 11 |
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int M = 1000000007, BIG = 0x3f3f3f3f;
int n;
vector<int> a;
vector<long long> Process() {
vector<long long> ans(n - 1, 0);
for (int i = 1; i < n; i++) {
if (i > 1) ans[i - 1] += ans[i - 2];
for (int e = 16; e >= 0; e--) {
const int p = (1 << e);
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
const long long mod = 1e9 + 7;
long long dp[34][2][2], num1[34], num2[34];
long long dfs(int pos, int limit1, int limit2) {
if (pos == -1) return 1;
if (dp[pos][limit1][limit2] != -1) return dp[pos][limit1][limit2];
int u1 = limit1 ? num1[pos... | 15 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
long long INF = 1e9;
const int N = 500031;
int n, m;
int ar[N];
int used[N];
void make_complement() {
for (int i = 0; i < m; i++) {
used[i] = 0;
}
for (int i = 0; i < n; i++) {
used[ar[i]] = 1;
}
vector<int> vals;
for (int i = ... | 18 |
#include <bits/stdc++.h>
using namespace std;
int in() {
int x;
scanf("%d", &x);
return x;
}
long long lin() {
long long x;
scanf("%lld", &x);
return x;
}
template <typename A, size_t NNN, typename T>
void Fill(A (&array)[NNN], const T &val) {
fill((T *)array, (T *)(array + NNN), val);
}
long long MOD = 1... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 17;
int n, m, k;
int a[1 << 3][2 * N];
int u[1 << 3];
int get(int L, int R, int* Q) {
int res = 0;
for (L += N, R += N; L < R; L >>= 1, R >>= 1) {
if (L & 1) res = max(res, Q[L++]);
if (R & 1) res = max(res, Q[--R]);
}
return res;
}
int ne... | 12 |
#include <bits/stdc++.h>
using namespace std;
int N;
int main(int argc, char *argv[]) {
cin >> N;
long long ans = 0;
for (int i = 0, _i = N; i < _i; ++i) {
long long x;
cin >> x;
ans += (long long)i * (x - 1);
ans += x;
}
cout << ans;
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int a[1001];
bool used[1001];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int cnt = n;
int now = 0;
int change = -1;
while (cnt) {
change++;
for (int i = 1; i <= n; i++)
if (now >= a[i] && !used[i]) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
char x[2 * 100001];
int n, ans;
int xState = -1, yState = -1;
bool incY, incX;
int main() {
scanf("%d%s", &n, x);
for (int i = 0; i < n; i++) {
if (x[i] == 'R' && xState == -1)
xState = 1;
else if (x[i] == 'L' && xState == -1)
xState = 0;
else if... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2510;
int n;
double dis[N][N], f[N][N][2], x[N], y[N];
int main() {
std::cin.tie(0);
std::cout.tie(0);
cin >> n;
for (int i = 0; i < n; i++) cin >> x[i] >> y[i];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
dis[i][j] = sqrt((1.0 ... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 7;
const int B = 107;
const int M = (int)1e9 + 7;
int n, m, l, r, k;
int a[N];
int b[B][N];
int c[B][N];
void add(int &a, int b) {
a += b;
if (a >= M) a -= M;
}
void sub(int &a, int b) {
a -= b;
if (a < 0) a += M;
}
int main() {
for (int i... | 17 |
#include <bits/stdc++.h>
using namespace std;
int q;
map<long long, complex<long long> > h1, h2;
long long cross(const complex<long long>& a, const complex<long long>& b) {
return (conj(a) * b).imag();
}
bool in(map<long long, complex<long long> >& h, long long x, long long y) {
if (!h.size()) return false;
if (x... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long n, x;
cin >> n >> x;
long long a[n], cnt = 0;
long long sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
if (a[i] == x) cnt++;
}
if (cnt == n) {
c... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int MX = 2e5 + 2;
const long long INF = 1000000000000000000;
const long double PI = 4 * atan((long double)1);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
bool ckmin(int& a, int b) { return b < a ? a = b, true : false; }
bool ckm... | 6 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const int maxN = 1100000;
int n;
int x[101000];
int larg[maxN];
int res[maxN];
void getLargest(long long a, long long b) {
int svalue = b;
for (int i = 0; i < maxN; ++i) {
larg[i] = 2;
}
for (int i = 0; i < n; ++i) {
... | 14 |
#include <bits/stdc++.h>
using namespace std;
int num[100005];
int f[100005];
int main() {
int n, ans = 0;
cin >> n;
bool flag = false;
memset(f, -1, sizeof(f));
for (int i = 0; i < n; i++) scanf("%d", &num[i]);
for (int i = 0; i < n; i++) {
if (num[i] == i)
ans++;
else if (!flag) {
if (... | 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.