solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
bool down[300000];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long n, m, acu = 0, foo, saw;
bool seen = false;
cin >> n >> m;
for (long long i = 0; i < n; ++i) {
cin >> foo;
if (foo == m) saw = i;
down[i] = (foo > m);
}
map<pair<... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long t, i;
cin >> t;
while (t--) {
long long n, x;
cin >> n >> x;
string s;
cin >> s;
long long ans = 0;
long long a[n];
long long b[n];
long long flag = 0;
map<long lo... | 9 |
#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cout << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
cout.write(nam... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n;
int a, b, c, d;
int main() {
scanf("%d", &n);
for (int i = 1; i <= 4; i++) {
scanf("%d%d%d%d", &a, &b, &c, &d);
if (min(a, b) + min(c, d) <= n) {
printf("%d %d %d", i, min(a, b), n - min(a, b));
return 0;
}
}
printf("-1");
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100001;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
;
int n, m, l[N], r[N], a[N], min = N, ind = -1;
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> l[i] >> r[i];
if ((r[i] - l[i] + 1) < min) {
min = r[i] - l[i] + 1... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long n, m;
bool valid(long long x, long long y) {
return x > 0 && x <= n && y > 0 && y <= m;
}
int main() {
cin >> n >> m;
long long x, y, k, mx, my, sol, tsol = 0;
cin >> x >> y >> k;
for (int i = 0; i < k; i++) {
sol = 0;
cin >> mx >> my;
long l... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long a[1000001] = {};
long long r[1000001] = {};
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
int d[100] = {};
int ct = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (a[i] >= d[j]) {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> fac;
long long max_ans, min_ans, real_mod;
void get_fac(long long nk) {
long long m = sqrt(nk + 0.5);
for (long long i = 1; i <= m; i++) {
if (nk % i == 0) {
fac.push_back(i);
if (i != nk / i) {
fac.push_back(nk / i);
}
... | 9 |
#include <bits/stdc++.h>
using namespace std;
inline void JadedBeast() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
const int MAX = 1e5 + 1;
int main() {
JadedBeast();
int n, u;
double ans = -1;
cin >> n >> u;
int E[n];
for (int i = 0; i < n; i++) cin >> E[i];
int i = 0, j = 1, k ... | 8 |
#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<int, int> p1, pair<int, int> p2) {
return (p1.second < p2.second);
}
int main() {
int n, k, res = INT_MAX;
cin >> n >> k;
vector<int> v(n);
vector<pair<int, int> > p;
map<int, int> m;
for (int i = 0; i < n; i++) cin >> v[i];
for (int i = 0; i <... | 8 |
#include <bits/stdc++.h>
using namespace std;
int i, j, m, n, p, k, x, y, Q[3005], vis[3005], ege;
int dis[3005][3005], s1, t1, s2, t2, l1, l2, ans;
int pre[6005], head[3005], en[6005], v[6005];
queue<int> qu;
void add(int a, int b, int c) {
ege++;
pre[ege] = head[a];
head[a] = ege;
en[ege] = b;
v[ege] = c;
}... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int RLEN = 1 << 18 | 1;
inline char nc() {
static char ibuf[RLEN], *ib, *ob;
(ib == ob) && (ob = (ib = ibuf) + fread(ibuf, 1, RLEN, stdin));
return (ib == ob) ? -1 : *ib++;
}
inline int rd() {
char ch = nc();
int i = 0, f = 1;
while (!isdigit(ch)) {
if... | 26 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<ll>;
using VB = vector<bool>;
using VD = vector<long double>;
using VC = vector<char>;
using VS = vector<string>;
using V2I = vector<VI>;
using V3I = vector<V2I>;
const ll mod{(ll)1e9 + 7};
const long double pi = 2 * acos(0.0);
void s... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, n, arr[1000000], pos = 0, neg = 0, temp, temp1;
cin >> n;
for (i = 0; i < n; i++) cin >> arr[i];
sort(arr, arr + n);
for (i = 0; i < n; i++) {
if (arr[i] > 0)
pos++;
else if (arr[i] < 0)
neg++;
}
if (n % 2 == 0)
t... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
int64_t total = 0;
int x = 0;
vector<vector<int>> vcur = {a};
for (int j = 29; j >= 0; j--) {
int64_t sum0 = 0, ... | 12 |
#include <bits/stdc++.h>
std::array<int, 5005> requests;
std::array<int, 5005> prefix;
int main() {
int n;
std::cin >> n;
int cur = 0, cumsum = 0;
for (int i = 0; i < n; ++i) {
std::cin >> cur;
requests[i] = cur;
cumsum += cur;
prefix[i + 1] = cumsum;
}
auto max = 0;
for (int i = 0; i < n;... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
char str[202030];
int a[202030], c[202030];
int qa[202030], qc[202030];
long long wfPow(int x) {
if (x <= 0) {
return 1;
}
long long v = wfPow(x / 2);
v = (v * v) % 1000000007;
if (x % 2) {
v = (v * 3) % 1000000007;
}
return v;
}
long long wf... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[1005][1005];
int col[1005], row[1005];
int main() {
cin >> n >> m;
bool emp = true;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
for (int j = 0; j < m; j++) {
if (s[j] == '#') {
a[i][j] = 1;
emp = false;
}
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int ans[300005];
vector<int> e[300005];
queue<int> q;
int main() {
int i, j;
scanf("%d%d", &n, &m);
int x, y;
while (m--) {
scanf("%d%d", &x, &y);
e[x].push_back(y);
e[y].push_back(x);
}
for (i = 1; i <= n; i++) q.push(i);
while (!q.empty... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.precision(20);
int n;
cin >> n;
vector<long long> c(2 * n);
for (int i = 0; i < 2 * n; i++) cin >> c[i];
sort(c.begin(), c.end());
long long area = LLONG_MAX;
for (int i = 0; i < n; i++) ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long int inf = 1000000000;
const long long int mod = 1000000000 + 7;
inline void IO() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
inline int dcmp(long double x) { return x < -1e-12 ? -1 : (x > 1e-12); }
template <class T>
inline int CHECK(T M... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
const long long MOD = 1e9 + 7;
int dX[] = {0, 0, 1, -1};
int dY[] = {1, -1, 0, 0};
int n, m, k, cst[N], nearest[N];
long long ans;
bool block[N];
int calc(int S) {
int cur = 0, ret = 0;
while (cur < n) {
ret++;
if (cur + S >= n) return ret... | 13 |
#include <bits/stdc++.h>
using namespace std;
map<long long int, vector<long long int>> t;
int main() {
long long int n;
cin >> n;
map<long long int, long long int> deg;
map<long long int, long long int> p;
for (long long int i = 1; i <= n - 1; i++) {
long long int temp;
cin >> temp;
deg[temp]++;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
map<long long, long long> mp;
int cnt;
int n;
int num[100008];
int main() {
scanf("%d", &n);
int tmp;
for (int i = 1; i <= n; i++) {
scanf("%d", &tmp);
num[i] = tmp;
mp[tmp]++;
}
for (int i = 1; i <= n; i++) {
scanf("%d", &tmp);
if (num[i] == t... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, t;
char s[205][205];
int main() {
cin >> t;
int i, j, k;
while (t--) {
cin >> n;
for (i = 1; i <= n; ++i) {
cin >> (s[i] + 1);
}
int cnt = 0;
bool i1 = 0, i2 = 0;
if (s[1][2] == s[2][1]) {
if (s[n][n - 1] == s[1][2]) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long int N = 500010;
long long int n, m;
vector<long long int> adj[N];
long long int val[N], vis[N];
long long int tree[N], graph[N];
long long int istree[N];
void dfs(long long int v, long long int p) {
vis[v] = 1;
tree[v] = 0;
graph[v] = 0;
istree[v] = ... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long int n, i, j, h, d[100001];
string s;
bool used[100001];
int main() {
cin >> n;
cin >> s;
for (i = 0; i < n; i++) cin >> d[i];
long long int x = 0;
while (x >= 0 && x < n) {
if (used[x]) {
cout << "INFINITE" << endl;
return 0;
}
us... | 2 |
#include <bits/stdc++.h>
constexpr auto Inf = 0X3F3F3F3F;
using namespace std;
namespace IO {
inline long long read() {
long long o = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c > '/' && c < ':') {
o = o * 10 + c - '0';
c = getchar... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100002;
int n, s;
int buy[maxn];
int sell[maxn];
int main() {
memset(buy, 0, sizeof(buy));
memset(sell, 0, sizeof(sell));
cin >> n >> s;
char d;
int p, q, i, t = 0, bp = 0;
for (i = 0; i < n; ++i) {
cin >> d >> p >> q;
if (d == 'B') {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int width = 0;
int n, h;
cin >> n >> h;
int arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
if (arr[i] <= h)
width += 1;
else
width += 2;
}
cout << width << "\n";
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
long long int gcd(long long int x, long long int y) {
if (y == 0) return x;
return gcd(y, x % y);
}
long long int lcm(long long int a, long long int b) {
return (a * b) / gcd(a, b);... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string a, b;
cin >> a >> b;
string ans = "zzzzzzzzzzz";
for (long long int i = 0; i < a.length(); i++) {
string temp;
temp = a.substr(0, i + 1) + b.substr(0, 1);
if (temp... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T min3(T a, T b, T c) {
return min(a, min(b, c));
};
template <class T>
T max3(T a, T b, T c) {
return max(a, max(b, c));
};
void openFile() {
freopen("/home/khaihanhdk/MyWorkplace/cpp file/a.inp", "r", stdin);
}
int main() {
long long A, B, y, g,... | 0 |
#include <bits/stdc++.h>
long long n, a[2010], b[5010], c[10010];
double ans;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++)
b[((a[i] - a[j]) > 0 ? (a[i] - a[j]) : -(a[i] - a[j]))]++;
for (int i = 1; i <= 500... | 10 |
#include <bits/stdc++.h>
int main() {
char ary1[102], ary2[102];
scanf("%s%s", ary1, ary2);
if (strcmp(ary1, ary2) == 0) {
printf("%s\n", ary1);
} else {
printf("1\n");
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int tonum(string s) {
int ans = 0;
for (int i = 0; i < s.size(); i++) {
ans = ans * 10 + (s[i] - '0');
}
return ans;
}
int main() {
string a;
cin >> a;
int n = a.size();
int sum[500];
int mice = 499;
memset(sum, 0, sizeof sum);
for (int i = 0, j; i... | 8 |
#include <bits/stdc++.h>
using namespace std;
struct atom {
int a, b, c;
unsigned int w;
};
unordered_map<long long, int> H[600];
int n, len, a, b, c, mo = (1 << 30), sign;
vector<int> prime;
int dp(int kk1, int kk2, int kk3, int kk4) {
if (kk4 == -1) return 1;
long long now = 1ll * kk1 * (a + 1) * (a + 1) + kk... | 18 |
#include <bits/stdc++.h>
using namespace std;
ostream &operator<<(ostream &out, string str) {
for (char c : str) out << c;
return out;
}
template <class L, class R>
ostream &operator<<(ostream &out, pair<L, R> p) {
return out << "(" << p.first << ", " << p.second << ")";
}
template <class T>
auto operator<<(ostre... | 17 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXLINE = 1000;
const int MAXLINELEN = 4 + 1 + 4 + 1 + 4 + 1;
struct Node {
int a;
char op;
int b;
Node() {}
Node(int a, char op, int b) : a(a), op(op), b(b) {}
};
bool operator==(const Node &p... | 19 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using ld = long double;
template <class T>
inline bool Min(T &a, T b) {
return a > b ? (a = b, true) : false;
}
template <class T>
inline bool Max(T &a, T b) {
re... | 12 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vpll = vector<pair<ll, ll>>;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
const int maxn = 2e5 + 10;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, ans = 0;
cin >>... | 7 |
#include <bits/stdc++.h>
using namespace std;
inline bool ok(long long &mid, vector<long long> &a, long long &n,
long long &m) {
long long temp = 0;
for (long long j = 0; j < mid; j++) {
long long sub = 0;
for (long long k = j; k < n; k += mid) {
temp += max(0ll, a[k] - sub);
sub+... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, v, a;
cin >> n >> v;
if (v < n - 1)
a = (v - 1) + ((n - v) * (n - v + 1)) / 2;
else
a = n - 1;
cout << a;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
double compute(double w, double b);
double dp[1010][1010];
int main() {
double w, b;
cin >> w >> b;
for (int i = 0; i < 1010; i++) {
for (int j = 0; j < 1010; j++) dp[i][j] = -1;
}
dp[(int)w][(int)b] = compute(w, b);
double ans = dp[(int)w][(int)b];
printf... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n;
long long val[300007];
long long mask[300007];
void input() {
cin >> n;
long long sm = 0;
for (int i = 1; i <= n; ++i) {
cin >> val[i] >> mask[i];
sm += val[i];
}
if (sm > 0) {
for (int i = 1; i <= n; ++i) {
val[i] = -val[i];
}
}
}
v... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int ans = 0, a = 0;
while (getline(cin, s)) {
if (s[0] == '+')
a++;
else {
if (s[0] == '-')
a--;
else
ans += a * (s.size() - s.find(':') - 1);
}
}
cout << ans;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s1, s2, s3;
char winer = '0';
int cnt = 0;
cin >> s1 >> s2 >> s3;
if ((s1[0] == 'p' && s2[0] == 'r' && s3[0] == 'r') ||
(s1[0] == 'r' && s2[0] == 's' && s3[0] == 's') ||
(s1[0] == 's' && s2[0] == 'p' && s3[0] == 'p')) {
winer = ... | 1 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void rj_king() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
void solve() {
long long mods[5] = {0, 0, 0, 0, 0};
long long ans = 0, n, m;
cin >> n >> m;
for (long long i = 1; i <... | 3 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long i, j, k, x, y, z, n, mi = 1e16, sum = 0;
cin >> n;
long long a[n];
for (i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
if (n == 1 || n == 2) {
cout << a[0] - 1;
return;
}
z = (long long)pow(1e18, 1.0 / (n - 1));
... | 7 |
#include <bits/stdc++.h>
template <typename C>
int sz(const C &c) {
return c.size();
}
using namespace std;
int main() {
iostream::sync_with_stdio(false);
int n;
cin >> n;
map<string, string> d;
for (int i = 0; i < n; ++i) {
string p;
cin >> p;
string q;
cin >> q;
auto it = d.find(p);
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e3 + 10;
vector<int> adj[N];
void bfs(int n, int src, vector<int>& dist) {
vector<bool> vis(n + 1, false);
dist[src] = 0;
vis[src] = true;
queue<int> q;
q.push(src);
while (!q.empty()) {
int node = q.front();
q.pop();
for (auto ch... | 8 |
#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> a[500];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i].second;
long long x = a[i].second;
while (x % 3 == 0) {
a[i].first--;
x /=... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int INF = int(1e9);
const double EPS = 1e-8;
struct debugger {
template <typename T>
debugger& operator,(const T& v) {
cerr << v << " ";
return *this;
}
} dbg;
int d, n, m;
vector<pair<int, int> > arr;
int main() {
std::ios_base::sync_with_stdio(false)... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long res, p2[510], preq[510][510], f;
int n, k, r;
int main() {
cin >> n >> k;
res = 0;
p2[0] = 1;
for (int i = 1; i <= n; i++) {
p2[i] = (p2[i - 1] * 2LL) % 998244353LL;
}
for (int i = 1; i < 510; i++) {
for (int j = 1; j < 510; j++) {
preq[i... | 13 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
template <typename T, typename TT>
inline ostream &operator<<(ostream &os, const pair<T, TT> &t) {
return os << t.first << " " << t.second;
}
template <typename T>
inline ostream &operator<<(ostream &os, const vector<T> &t) {
for (auto i : ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int b, p, f, x, y, z;
cin >> b >> p >> f;
int h, c;
cin >> h >> c;
x = b / 2;
y = p + f;
if (x >= y) {
z = p * h + f * c;
} else {
if (h >= c) {
if (p <= x) {
z =... | 0 |
#include <bits/stdc++.h>
using namespace std;
int getint() {
int _x = 0, _tmp = 1;
char _tc = getchar();
while ((_tc < '0' || _tc > '9') && _tc != '-') _tc = getchar();
if (_tc == '-') _tc = getchar(), _tmp = -1;
while (_tc >= '0' && _tc <= '9') _x *= 10, _x += (_tc - '0'), _tc = getchar();
return _x * _tmp... | 12 |
#include <bits/stdc++.h>
using namespace std;
const long long IINF = 9223372036854775807;
const int INF = 0x7fffffff;
const int inf = 0x3f3f3f3f;
const int maxn = 200005;
const int N = 105;
inline void read(int &x) {
int f = 1;
x = 0;
char s = getchar();
while (s < '0' || s > '9') {
if (s == '-') f = -1;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, n, m, t, test, a, r, c, temp;
int row[1010], col[1010];
char str;
while (cin >> n >> m >> test) {
vector<int> v[1010];
for (i = 0; i < n; i++)
for (j = 0; j < m; j++) {
scanf(" %d", &a);
v[i].push_back(a);
}... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, p, w, d;
cin >> n >> p >> w >> d;
long long above = n * w - p;
if (p == 0) {
cout << "0 0 " << n << endl;
} else if (above < 0 || d > p) {
cout << -1 << endl;
} else {
long long xx = p / w;
for (long long k = 0; k <= 1e6... | 12 |
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;
const int mx = 1e5 + 10;
const int mxt = 1e6 + 10;
long long int d[mx];
long long int t[mxt];
void upd(int idx, long long int v) {
for (; idx < mxt; idx += (idx & -idx)) t[idx] = (t[idx] + v) % mod;
}
long long int query(int idx) {
... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200009, Q = 2E5 + 5, MOD = 998244353;
int n, q, l, r, len;
char s[N];
long long pw[N];
pair<long long, int> ans[Q][2];
vector<pair<int, int>> que[N];
struct segment_tree {
long long add[4 * N];
int mul[4 * N], tot[4 * N];
void apply(int i, int mu, long l... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int N = 500 + 10;
int n, m, p;
long long c[N][N], f[N], g[N];
long long dp[N][N], ways[N][N];
long long dp2[N][N], ways2[N][N];
long long dp0[N][N], ways0[N][N];
void add(long long &x, long long y) { x = (x + y) % p; }
long long cal(long long x) { return 1LL * x * (x ... | 23 |
#include <bits/stdc++.h>
using namespace std;
int n;
const int MaxN = 3e5;
vector<int> adj[MaxN];
vector<int> prec[MaxN];
void dfs(const int u, const int p) {
prec[u] = {1, n};
adj[u].erase(remove(adj[u].begin(), adj[u].end(), p), adj[u].end());
for (auto &&v : adj[u]) {
dfs(v, u);
prec[u][0] = max(prec[u... | 18 |
#include <bits/stdc++.h>
using namespace std;
int power(int a, int b) {
if (b == 0) return 1;
if (b % 2 == 0)
return power(a * a, b / 2);
else
return a * power(a * a, b / 2);
}
string three(int a) {
string s = "";
while (a) {
s += (a % 3 + '0');
a = a / 3;
}
reverse(s.begin(), s.end());
... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long i, i1, j, k, k1, t, n, m, res, flag[10], a, b;
long long x[200010], y[200010], s[200010], dp[200010][2], c[200010];
vector<array<long long, 2>> v;
vector<long long> adj[200010];
void fx(long long &x, long long p) {
if ((x + p) % 2) x = (x + 998244353) % 19964887... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long a[3], m;
int main() {
ios_base::sync_with_stdio(0);
cin >> a[0] >> a[1] >> m;
long long tam = a[0] + a[1];
sort(a, a + 2);
if (m <= a[1]) {
cout << 0;
return 0;
}
if (a[1] <= 0) {
cout << -1;
return 0;
}
long long res = 0;
if (t... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
int deg[n], x[n];
for (int(i) = 0; (i) < (n); (i)++) cin >> deg[i] >> x[i];
set<pair<int, int> > s;
for (int(i) = 0; (i) < (n); (i)++)
if (deg[i] != 0) s.insert(make_pair(deg[i], i));
vector<pair... | 7 |
#include <bits/stdc++.h>
using namespace std;
void ga(int N, int *A) {
for (int i(0); i < N; i++) scanf("%d", A + i);
}
int N, dp[5005][5005][2];
char s[5005];
int dyn(int u, int H, bool x) {
if (u == N) return 1;
int &v = dp[u][H][x];
if (~v) return v;
v = dyn(u + 1, H + (s[u] == 102), s[u] == 102);
if (!x... | 10 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int f = 1, x = 0;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
inline void write(int x... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);
long long t;
cin >> t;
while (t--) {
int n, c0, c1, h, one = 0, zero = 0;
cin >> n >> c0 >> c1 >> h;
string s;
cin >> s;
for (int i = 0; i < s.size(); i++) {
if ... | 0 |
#include <bits/stdc++.h>
int main() {
int n;
scanf("%d", &n);
printf("%I64d\n", (1 + 3LL * n * (1LL * n + 1)));
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n = 0;
int nr = 0;
char pre = 'a';
while (1) {
char c;
scanf("%c", &c);
if (c == '\n' || c == '\r') break;
if (c != pre || nr >= 5) {
n++;
nr = 1;
pre = 'a';
} else {
nr++;
}
pre = c;
}
printf(... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<string> ss;
string s;
cin >> s;
string t;
cin >> t;
int x1 = s[0] - 'a' + 1, y1 = s[1] - '0';
int x2 = t[0] - 'a' + 1, y2 = t[1] - '0';
if (x1 != x2 && y1 != y2) {
string a = "RU", b = "LU", c = "RD", d = "LD";
string ans;
if ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int i, n, m, d = -1;
cin >> m >> n;
vector<int> a(m), b(n), c(10000, 0);
for (i = 0; i < m; i++) {
cin >> a[i];
c[a[i]]++;
}
for (i = 0; i < n; i++) {
cin >> b[i];
if (c[b[i]] ... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct Node {
int leftmost;
int size;
int left_child;
int right_child;
int left_id;
int right_id;
int internal_i;
int internal_j;
long long sum;
long long left_sum;
long long right_sum;
long long internal_sum;
};
static Node nodes[200200];
static int... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int MX = 35;
struct Point {
int x, y;
Point() {}
Point(int _x, int _y) : x(_x), y(_y) {}
bool operator==(const Point &b) const { return x == b.x && y == b.y; }
bool operator!=(const Point &b) const { return !(*this == b); }
};
int N, M, ip[MX][MX], op[MX][MX... | 20 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<bool> taken(n + 1, false);
vector<pair<int, int>> res;
for (int p = 3; p <= n / 2; ++p) {
if (taken[p] || p % 2 == 0) continue;
int prev = p;
for (i... | 17 |
#include <bits/stdc++.h>
using namespace std;
int k;
int main() {
cin >> k;
if (k % 2 == 1) {
cout << -1 << '\n';
return 0;
}
vector<string> first;
vector<string> second;
for (int i = 0; i < k / 2; i++) {
string s1 = "", s2 = "";
for (int j = 0; j < k / 2; j++) {
if ((j % 2) ^ (i % 2) ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
string s1, s2, s3;
cin >> s1 >> s2 >> s3;
bool k = true;
for (int i = 0; i < s1.size(); i++) {
if (s1[i] != s3[i] && s2[i] != s3[i]) {
k = false;
}
}
if (k == true)
cout << "... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 666013;
const int mod2 = 666019;
const int base = 31;
const int nmax = 1e5;
const int pmax = 30 + 5;
int d[pmax + 1][nmax + 1];
string s;
struct Hash {
int x, y;
Hash() {}
Hash(int _x, int _y) { x = _x, y = _y; }
inline Hash operator+(const int &k) c... | 16 |
#include<bits/stdc++.h>
#include<algorithm>
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define ff first
#define ss second
#define mloop(i) for(auto i=m.begin();i!=m.end();i++)
#define pb push_back
#define pll pair<ll,ll>
#def... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, i, p, r = 1;
vector<pair<int, int> > vec;
int main() {
cin >> n;
int ans[n];
for (i = 0; i < n; i++) {
cin >> p;
vec.push_back(make_pair(p, i));
}
sort(vec.begin(), vec.end());
ans[vec[n - 1].second] = 1;
for (i = n - 2; i >= 0; i--) {
if (v... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long max(long long a, long long b) {
if (a > b) return a;
return b;
}
long long min(long long a, long long b) { return a + b - max(a, b); }
long long mulmod(long long a, long long b, long long mod) {
return ((a % 998244353) * (b % 998244353) % 998244353);
}
long ... | 4 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int N = 3e5 + 5;
vector<pair<int, int>> g[N];
int d[N], u[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m, h;
cin >> n >> m >> h;
vector<int> q;
fill(d, d + N, 1e9);
for (int i = 0; i < m; ++i)... | 13 |
#include <bits/stdc++.h>
using namespace std;
typedef struct {
double p;
double np;
} fd;
bool operator<(const fd &a, const fd &b) {
if (a.p > b.p) {
return true;
}
return false;
}
int main(void) {
int n;
cin >> n;
vector<fd> arr(n);
for (int i = 0; i < n; i++) {
cin >> arr[i].p;
arr[i].np... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1 << 30;
long long add(long long a, long long b) { return (a + b) % MOD; }
const int MAXN = 1100000;
int dd[MAXN];
int d(int k) { return dd[k]; }
void prec() {
for (int a = 1; a < MAXN; ++a) {
for (int b = a; b < MAXN; b += a) {
dd[b]++;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout.setf(ios_base::fixed);
cout.precision(28);
int n, m;
cin >> n >> m;
vector<vector<int> > g(n);
for (int i = 0; i < m; ++i) {
int x, y;
cin >> x >> y;
g[x - 1].push_back(y - 1);... | 12 |
#include <bits/stdc++.h>
using namespace std;
char a[101][101];
int n;
int m;
int chk(int, int);
int main() {
cin >> n >> m;
string ans = "";
char x;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) {
cin >> x;
a[i][j] = x;
}
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j+... | 3 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
long long n... | 15 |
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7;
int inf = 2e9;
long long INF = 8e18;
int t[200000];
int dp[200000];
int bs(int x, int s, int e) {
if (s == e) {
return s;
}
int mid = (s + e + 1) / 2;
if (t[mid] > x) {
return bs(x, s, mid - 1);
}
return bs(x, mid, e);
}
int main... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 10000000007;
const int maxn = 100010;
const int MAX = 10010;
const long long linf = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
long long qpow(long long a, long long b) {
return b ? ((b & 1) ? a * qpow(a * a % MOD, b >> 1) % MOD
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9;
const long long MN = 2e5 + 10;
vector<int> graf[MN];
int minCiclo = INF;
int nodMinCiclo1, nodMinCiclo2;
int vis[MN];
int parent[MN];
void dfs(int nod, int l, int p) {
vis[nod] = l;
parent[nod] = p;
for (int ady : graf[nod])
if (ady != p... | 13 |
#include <bits/stdc++.h>
using namespace std;
struct Value {
char l, r;
array<array<int, 10>, 10> ct;
};
struct Lazy {
char c;
};
struct SegTree {
int n;
vector<Value> t1;
vector<Lazy> t2;
SegTree(string &s) {
n = 1;
while (n < (int)s.size()) n <<= 1;
t1.resize(2 * n - 1, Value());
t2.resi... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int N = (int)(1e5) + 5, M = 1001, mod = (int)(1e9) + 7;
int main() {
ios::sync_with_stdio(0);
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int n, m;
cin >> n >> m;
long long arr[m];
char a[n][m];
for (int i = 0; i < n; i++)
for (int j = 0... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int maxn = 305;
int n, cnt[305], pre[305], sz;
long long a[maxn], C[maxn][maxn], dp[maxn][maxn], fac[maxn];
bool vis[305];
inline void init() {
C[0][0] = fac[0] = 1;
for (int i = 1; i < maxn; ++i) {
C[i][0] = 1;
fac[i] = fac[... | 17 |
#include <bits/stdc++.h>
using namespace std;
const double pi = 3.141592653589793238;
const long long int inf = (long long int)10e16;
int main() {
ios ::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long int h, k = 0, an = 0, temp, mi = 1000000000000000000, an1, h1;
int n;
cin >> h >> n;
long long... | 9 |
#include <bits/stdc++.h>
using namespace std;
int val[50][50][71];
void add(int& a, int b) {
if (a == -1 || a > b) a = b;
}
int fct(int n, int m, int k) {
int& ret = val[n][m][k];
if (ret >= 0) return ret;
if (n * m < k) return 0x3f3f3f3f;
if (n * m == k || k == 0) return ret = 0;
for (int i = 1; i <= n / 2... | 12 |
#include <bits/stdc++.h>
using namespace std;
void Solve() {
int n;
cin >> n;
int arr[n];
for (int i = 0; i < n; ++i) {
cin >> arr[i];
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
for (int k = 0; k < n; ++k) {
if (i != j && j != k && arr[j] + arr[k] == arr[i]) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, sd, c;
string s;
bool p, m;
cin >> n;
while (n--) {
c = 0;
sd = 0;
p = false;
m = false;
cin >> s;
if (s == "0") {
cout << "red" << endl;
} else {
for (int i = 0; i < s.size(); i++) {
if (s[i] - 4... | 2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.