solution stringlengths 53 181k | difficulty int64 0 13 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
struct Node {
int V, Id;
bool operator<(const Node &B) const { return V < B.V; }
} A[MAXN];
int N, Ans;
bool Vis[MAXN];
vector<int> V[MAXN];
int main() {
cin >> N;
for (int I = 1; I <= N; ++I) scanf("%d", &A[I].V), A[I].Id = I;
sort(A + 1... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long int binaryExponentiation(long long int x, long long int n) {
if (n == 0)
return 1;
else if (n % 2 == 0)
return binaryExponentiation(x * x, n / 2);
else
return x * binaryExponentiation(x * x, (n - 1) / 2);
}
long long int modularExponentiation(lon... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
vector<pair<int, int> > G[N];
long long res = 0LL, dp[N][4];
void dfs(int u, int parent) {
for (int i = 0; i < G[u].size(); ++i) {
int v = G[u][i].first;
int w = G[u][i].second;
if (v == parent) continue;
dfs(v, u);
long long cnt[... | 7 |
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ull = uint64_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using pii = pair<int, int>;
using ld = double;
namespace io {
const int BUFSIZE = 1 << 20;
int isize, osize;
char ibuf[BUFSIZE + 10], obuf[BUFSIZE... | 11 |
#include <bits/stdc++.h>
using namespace std;
int a[100][100];
int main() {
memset(a, 0, sizeof(a));
int K;
scanf("%d", &K);
int n = 100;
while (n * (n - 1) * (n - 2) > 6 * K) n--;
K -= n * (n - 1) * (n - 2) / 6;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (i != j) a[i][j] = 1;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
string inttostring(int n) {
stringstream a;
a << n;
return a.str();
}
int stringtoint(string A) {
istringstream a(A);
int p;
a >> p;
return p;
}
int n;
int A[200001];
long long dp[200001][2];
bool mark[200001][2];
long long x, y;
int g;
long long run(int i, in... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int int_inf = 0x3f3f3f3f;
const long long int ll_inf = 0x3f3f3f3f3f3f3f3f;
const int max_n = 1e5 + 5;
int num[max_n];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int i, j;
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
for (int i = 1... | 5 |
#include <bits/stdc++.h>
using namespace std;
double m[6], w[6], h, h2;
double sum = 0;
int main() {
for (int i = 1; i <= 5; i++) {
cin >> m[i];
}
for (int i = 1; i <= 5; i++) {
cin >> w[i];
}
cin >> h >> h2;
sum += max((500 * 0.3),
(((1 - ((m[1] * 1.0 / 250.0) * 1.0)) * 500) - (50 * w[... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const int64_t INF = 1e18 + 7;
ostream& operator<<(ostream& o, const string& s) {
for (auto c : s) o << c;
return o;
}
template <typename F, typename S>
ostream& operator<<(ostream& o, const pair<F, S>& p) {
o << "[" << p.first << "," << ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, m, c;
int a[105];
int b[105];
int d[105];
int main() {
cin >> n >> m;
int i;
for (i = 1; i <= n; i++) {
cin >> a[i];
}
for (i = 1; i <= m; i++) {
cin >> b[i];
c += b[i];
}
int e = 0;
for (i = 1; i <= c; i++) {
d[a[i]]++;
}
for (int... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
if (a == 0) return b;
return gcd(b % a, a);
}
template <typename P>
P dectobin(P a) {
if (a == 0)
return 0;
else
return (a % 2 + 10 * dectobin(a / 2));
}
template <typename Y>
Y bintodec(Y a) {
long long ans = 0, b =... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
const int MOD = 1000000007;
int a[128];
char s[N];
int quick_mod(int a, int b) {
long long ans = 1;
while (b != 0) {
if (b % 2 == 1) {
ans = (ans * a) % MOD;
}
a = ((long long)a * a) % MOD;
b /= 2;
}
return ans;
}
int mai... | 3 |
#include <bits/stdc++.h>
using namespace std;
struct cmp {
bool operator()(pair<int, pair<int, int> > a, pair<int, pair<int, int> > b) {
if (a.first != b.first) {
return a.first < b.first;
} else
return a.second.first > b.second.first;
}
};
int main() {
ios_base::sync_with_stdio(0);
cin.tie(... | 4 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int power(int x, int p, int MOD) {
if (p == 0) return 1 % MOD;
if (p == 1) return x % MOD;
int res = power(x, p / 2, MOD);
res = (long long)res * res % MOD;
if (p & 1) res = (long long)res * x % MOD;
r... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long INF = 100000000000000000;
long long gcd(long long a, long long b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
long long modularExp(long long x, long long n, long long mod) {
long long result = 1;
while (n > 0) {... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
struct node {
int v, flag, id;
} nd[maxn];
bool cmp(node a, node b) {
if (a.v == b.v) return a.flag > b.flag;
return a.v < b.v;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<pair<int, int> >... | 4 |
#include <bits/stdc++.h>
using namespace std;
namespace ioput {
template <typename T>
T read() {
T x = 0, f = 1;
char c = getchar_unlocked();
while ((c < '0') || (c > '9')) {
if (c == '-') f = -1;
c = getchar_unlocked();
}
while ((c >= '0') && (c <= '9'))
x = (x << 1) + (x << 3) + (c ^ 48), c = ge... | 5 |
#include <bits/stdc++.h>
const int N = 1024;
using namespace std;
int n, k, bs, L[N + 5], R[N + 5], blo[N + 5], ans, vis[N + 5];
char ch[2];
int main() {
scanf("%d%d", &n, &k);
bs = max(1, k / 2);
for (int i = 1; i <= n; i++) {
blo[i] = (i - 1) / bs + 1;
if (!L[blo[i]]) L[blo[i]] = i;
R[blo[i]] = i;
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int mo = 1000000007;
long long ans, G[1000005], g[1000005], S;
int n;
long double Gu[1000005];
struct N {
long long x, y;
} a[1000005], B[1000005];
N operator+(N a, N b) { return (N){(a.x + b.x) % mo, (a.y + b.y) % mo}; }
N operator-(N a, N b) { return (N){(a.x - b.... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long Mod = 100000000;
long long a, b, ta, tb, dp[101][101][2];
int main() {
cin >> a >> b >> ta >> tb;
for (int i = 0; i <= ta; i++) {
dp[i][0][0] = 1;
}
for (int i = 0; i <= tb; i++) {
dp[0][i][1] = 1;
}
for (int i = 1; i <= a; i++) {
for... | 4 |
#include <bits/stdc++.h>
using namespace std;
int dx[8] = {-1, 1, 0, 0, 1, 1, -1, -1}, dy[8] = {0, 0, 1, -1, 1, 1, -1, -1};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
int tot = 0;
while (n--) {
int x;
cin >> x;
tot += x;
}
tot = abs(tot... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char str[101];
cin >> str;
int len = strlen(str);
for (int i = 0; i < len; i++) {
if (str[i] < 'a') str[i] += 32;
if (str[i] != 'a' && str[i] != 'e' && str[i] != 'i' && str[i] != 'o' &&
str[i] != 'u' && str[i] != 'y')
cout << "." <... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int main() {
scanf("%d%d", &n, &m);
if (n > m) swap(n, m);
if (n == 1)
printf("%d", max(m - m % 6, m - (6 - m % 6)));
else if (n == 2 && m == 2)
printf("0");
else if (n == 2 && m == 3)
printf("4");
else if (n == 2 && m == 7)
printf("12"... | 7 |
#include <bits/stdc++.h>
using namespace std;
int tab[10000];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
unsigned long long odp = 1;
int po = n / 2;
n--;
while (n > po) {
odp *= n;
n--;
}
n--;
while (n) {
odp *= n;
n--;
}
cout << odp << endl;
retu... | 2 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
vector<pair<int, int> > act, fake;
multimap<pair<int, int>, pair<int, int> > final;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n, m, cy... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, m, u[200001], ar[200001], a[200001], x, y;
vector<int> vec[200001], w[200001], pr[200001];
vector<long long> ans[200001];
inline int dfs(int v) {
int y = 0;
for (int i = 0; i < vec[v].size(); i++) y += dfs(vec[v][i]);
a[v] = y;
y = y - u[v];
return y + 1;
}... | 5 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const int mod = 1000000007;
const int mask = 1;
const int maxp = 30;
long long dp[2][22][3];
long long p2[maxp];
long long p3[maxp];
long long zz[maxp][maxp];
int zml(int a2, int a3, int n) {
memset(dp, 0, sizeof(dp));
for (int j = 0; j < m... | 8 |
#include <bits/stdc++.h>
using namespace std;
int ds(int x) {
int res = 0;
while (x) {
res += x % 10;
x /= 10;
}
return res;
}
int main(int argc, char** argv) {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout << setprecision(15);
if (argc == 2 && atoi(argv[1]) == 123456789)
freopen(... | 7 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int qq = 1;
cin >> qq;
for (int qqq = 0; qqq < qq; qqq++) {
int n, first, v;
cin >> n >> first;
int maxx = 0;
int maxxd = 0;
for (int i = 0; i < n; i++) {
cin >> v;
maxx = max(max... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
c b, e;
};
template <class c>
rge<c> range(c i, c j) {
return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
template <class c>
debug& operator<<(const c&... | 3 |
#include <bits/stdc++.h>
using namespace std;
struct Point {
double x, y;
} p1, p2, w1, w2, m1, m2;
Point operator-(const Point &i, const Point &j) {
Point ret = {i.x - j.x, i.y - j.y};
return ret;
}
void Init() {
scanf("%lf %lf", &p1.x, &p1.y);
scanf("%lf %lf", &p2.x, &p2.y);
scanf("%lf %lf", &w1.x, &w1.y)... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b;
int t;
cin >> t;
while (t--) {
cin >> a >> b;
long long d = abs(a - b);
if (!d) {
cout << "0\n";
continue;
}
int cnt = 1;
while (1) {
long long sum = cnt * (cnt + 1) / 2;
if (sum >= d) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int md = 998244353;
inline void add(int &a, int b) {
a += b;
if (a >= md) a -= md;
}
inline void sub(int &a, int b) {
a -= b;
if (a < 0) a += md;
}
inline int mul(int a, int b) { return (int)((long long)a * b % md); }
inline int power(int a, long long b) {
i... | 10 |
#include <bits/stdc++.h>
using namespace std;
inline void inp(int &n) {
n = 0;
int ch = getchar();
int sign = 1;
while (ch < '0' || ch > '9') {
if (ch == '-') sign = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
n = (n << 3) + (n << 1) + ch - '0', ch = getchar();
n = n * sign;
}
long lo... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
set<long long> s;
long long n, k;
cin >> n >> k;
for (int i = 1; i <= k; i++) {
if (s.find(n % i) != s.end()) break;
s.insert(n % i);
}
if (s.size() == k)
cout << "YES";
else
cout << "NO";
}
| 4 |
#include <bits/stdc++.h>
char lin[2000086];
int main() {
int i, j, k, len, ans = 1, tpan;
while (gets(lin) != NULL) {
len = strlen(lin);
for (i = 0; i < len; i++) {
if (lin[i] != ' ') break;
}
if (lin[i] == '#') {
tpan = 0;
if (ans != 1) {
printf("\n");
}
ans = ... | 4 |
#include <bits/stdc++.h>
using namespace std;
set<int> v[200007];
int indeg[200003];
int num_leaf[200003];
int rem[200003];
int main() {
int t;
cin >> t;
while (t--) {
int n, k;
cin >> n >> k;
std::vector<int> leaves;
for (int i = 1; i <= n; ++i) {
v[i].clear();
indeg[i] = 0;
rem... | 7 |
#include <bits/stdc++.h>
const int INF = 1e9;
const int maxm = 1000000;
const int maxn = 10000;
using namespace std;
struct edge {
int to, next, cap, flow, cost;
} edge[maxm];
int head[maxn];
int tol;
int pre[maxn], dis[maxn];
bool vis[maxn];
int n;
int cnt_node;
void addedge(int u, int v, int cap, int cost) {
edge... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int sum = 0;
for (int i = 1; sum <= n; i++) {
sum += i;
if (sum == n) {
cout << "YES";
return 0;
}
}
cout << "NO";
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long maxi = LLONG_MAX;
long long mini = LLONG_MIN;
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
pair<long double, long double> norm(pair<long double, long double> p) {
long double lenp = (sqrt(((p.first) * (p.first) + (p.second) * (p.second)))... | 0 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 0.000000000000001;
void transoo(char *s) {
int i, j, l = strlen(s);
char t[200] = {0};
int p = 0;
for (i = 0; i < l; i++) {
if (!(s[i] == 'u')) {
t[p++] = s[i];
} else {
t[p++] = 'o';
t[p++] = 'o';
}
}
t[p] = 0;
... | 2 |
#include <bits/stdc++.h>
namespace XX {
template <int MOD>
long long int powmod(long long int a, long long int b) {
long long int ret = 1;
while (b) {
if (b & 1) ret = ret * a % MOD;
a = a * a % MOD;
b >>= 1;
}
return ret;
}
} // namespace XX
namespace XX {
template <template <typename> class Compa... | 7 |
#include<bits/stdc++.h>
#define ll long long int
#define f0n for(ll i=0; i<n; i++)
using namespace std;
const int MAX=2e3+5;
ll dp[MAX][MAX];
ll a[MAX];
ll call(ll l,ll r)
{
if(l==r) return 0;
if(dp[l][r]!=-1) return dp[l][r];
else return dp[l][r]=min(a[r]-a[l]+call(l+1,r),a[r]-a[l]+call(l,r-1));
}
int main()
{... | 5 |
#include <bits/stdc++.h>
using namespace std;
vector<int> divs[100100];
void gen_divs(int n) {
for (int i = 2; i <= n; ++i) {
for (int j = i; j <= n; j += i) {
divs[j].push_back(i);
}
}
}
bool on[1001000];
int used[101000], ans[101000];
int chk(int n) {
if (on[n] == 1) return -2;
for (auto el : di... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int md = 998244353;
inline void add(int &a, int b) {
a += b;
if (a >= md) a -= md;
}
inline void sub(int &a, int b) {
a -= b;
if (a < 0) a += md;
}
inline int mul(int a, int b) {
return (int)((long long)a * b % md);
unsigned long long x = (long long)a * b;... | 11 |
#include <bits/stdc++.h>
using namespace std;
inline bool isvowel(char c) {
c = tolower(c);
if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u')
return 1;
return 0;
}
const double eps = 0.000001;
const long double pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const lon... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const int maxint = 0x3f3f3f3f;
const int mod = 1e9 + 7;
struct mmp {
int x, y, p;
mmp() {}
mmp(int xx, int yy) { x = xx, y = yy; }
} p[100010];
int n, m, k, sum[100010], l, r, sn, pos[100010];
long long res[1000010], ans, num[2000010];
bool ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
std::ios::sync_with_stdio(false);
std::cin.tie(NULL);
std::cout.tie(NULL);
long long t = 1;
while (t--) {
long long n;
cin >> n;
vector<long long> ar(n), br(n);
for (long long i = 0; i < n; i++) {
cin >> ar[i];
br[i] = ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, a, b;
void input() {
cin >> n;
while (n--) {
int x;
cin >> x;
x == 2 ? a++ : b++;
}
}
void solve() {
int ans = min(a, b);
a -= ans, b -= ans;
cout << (max(a, b) / 3) * (b > 0) + ans << endl;
}
int main() {
input(), solve();
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cerr.tie(nullptr);
int n, l, r;
cin >> n >> l >> r;
int arr1[n];
int arr2[n];
int a[r - l];
int b[r - l];
int index = 0;
for (int i = 0; i < n; i++) {
cin >> arr1... | 3 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:66777216")
using namespace std;
string as, at;
int ls, lt, ss[32], kk, s[5555], t[5555];
void go(int x) {
if (ss[t[x]] == 0 || x == kk && ls <= lt) {
int yy = -1;
for (int i = t[x] + 1; i < 26; ++i)
if (ss[i] > 0) {
yy = i;
break;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int toI(string s) { return (s[0] - '0') * 256 + (s[1] - '0'); }
string toS(int i) {
string result(1, '0' + i / 256);
result += (char)('0' + i % 256);
return result;
}
pair<int, int> getNodes(string s) {
return pair<int, int>{toI(s.substr(0, 2)), toI(s.substr(1, 2))}... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long Bin_expo(long long n, long long b) {
long long res = 1;
while (b > 0) {
if (b & 1) res *= n;
n *= n;
b /= 2;
}
return res;
}
const long long Mod = 998244353;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long l... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1000000000000000000;
long long t, n, k, kol[5];
string s;
bool f;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> t;
for (long long o = 1; o <= t; ++o) {
cin >> n >> k;
cin >> s;
kol[0] = kol[1] = 0;
... | 3 |
#include <bits/stdc++.h>
const int MAXN = 100;
const int INF = 0x3f3f3f3f;
using namespace std;
inline int read() {
int x = 0, w = 1;
char c = ' ';
while (c < '0' || c > '9') {
c = getchar();
if (c == '-') w = -1;
}
while (c >= '0' && c <= '9')
x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
... | 4 |
#include <bits/stdc++.h>
const int MAX_N = (int)1e5 + 123;
const double eps = 1e-6;
const int inf = (int)1e9 + 123;
using namespace std;
struct P {
int x, l, r;
P() {}
P(int x, int l, int r) : x(x), l(l), r(r) {}
};
vector<P> T;
int n, k;
string second;
bool d[105][5];
int moves[3][2] = {{0, 1}, {1, 1}, {-1, 1}};... | 4 |
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll mod=1e9+7;
ll mtr[600][600];
ll n,m,k;
int main()
{
int n,m;
cin>>n>>m;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
cin>>mtr[i][j];
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const int NMAX = 3e5 + 3;
int n;
int arr[NMAX];
vector<vector<int>> adj;
pair<int, int> cnt[NMAX];
int ans = 0;
pair<int, int> dfs1(int u, int par) {
if (arr[u] == 1)
cnt[u] = {1, 0};
else if (arr[u] == 2)
cnt[u] = {0, 1};
for... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200 + 11;
int dp[N][N][N];
pair<pair<int, int>, pair<int, int> > pr[N][N][N];
vector<pair<int, pair<int, int> > > vv;
int n, m;
void up(int l, int r, int k, int ans, int c1, int c2, int c3, int c4) {
if (k < 0 || k > max(n, m)) return;
if (dp[l][r][k] != -... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long a, b;
using item = pair<int, vector<char>>;
item f(long long a, long long b) {
if (a > b) return {1e9, vector<char>()};
if (a == b) return {0, vector<char>()};
item val = f(a * 2, b);
item val2 = f((10 * a) + 1, b);
if (val.first < val2.first) {
val.... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, cnt = 0;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] % 2 == 1) {
cnt++;
} else if (a[i] % 2 == -1) {
cnt--;
}
}
cnt /= 2;
if (cnt > 0) {
for (int i = 0; i < n; i++) {
if (a[i... | 1 |
#include <bits/stdc++.h>
int c[333];
char s[111111];
long long r;
int main() {
gets(s);
for (int i = r = 0; s[i]; i++) c[s[i]]++;
for (int i = 1; i < 200; i++) r += 1LL * c[i] * c[i];
printf("%I64d\n", r);
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
void dfs(vector<vector<long double> > &graph, vector<long double> &vis,
long long n) {
for (long long i = 0; i < graph[n].size(); i++) {
if (!vis[graph[n][i]]) {
vis[graph[n][i]] = 1;
dfs(graph, vis, graph[n][i]);
}
}
return;
}
int main() ... | 3 |
#include <bits/stdc++.h>
using namespace std;
void File() {
freopen("output.txt", "w", stdout);
freopen("input.txt", "r", stdin);
}
void fast() {
ios::sync_with_stdio(NULL);
cout.tie(NULL);
cin.tie(NULL);
}
const double pi = 2 * acos(0.0);
const int oo = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int nn = 1e2... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, q;
long long T[101000];
int F[101000];
vector<set<int> > V;
long long Gr[101000];
long long In[101000];
struct Com1 {
bool operator()(int a, int b) const;
};
struct Com2 {
bool operator()(int a, int b) const;
};
struct Com3 {
bool operator()(int a, int b) const... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1003;
bool a[maxn], b[maxn];
inline int get() {
int f = 0, v = 0;
char ch;
while (!isdigit(ch = getchar()))
if (ch == '-') break;
if (ch == '-')
f = 1;
else
v = ch - 48;
while (isdigit(ch = getchar())) v = v * 10 + ch - 48;
if (f =... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b, c, d;
scanf("%I64d%I64d%I64d%I64d", &a, &b, &c, &d);
char x, y, z;
cin >> x >> y >> z;
int s1 = 0, s2 = 0;
if (x == '+')
s1++;
else
s2++;
if (y == '+')
s1++;
else
s2++;
if (z == '+')
s1++;
else
s2++;... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct edge {
int t, f, w;
bool operator<(const edge& e) const { return w > e.w; }
edge(int from, int to, int weight) {
t = to;
f = from;
w = weight;
}
};
const double EPS = (1e-5);
struct line {
double a, b, c;
};
struct point {
double x, y;
point... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s1, s2, s;
cin >> s1 >> s2;
int i = 0;
int k = 0;
while (i < s1.size()) {
if (s1[i] != s2[i]) {
k++;
if (k & 1)
if (s1[i] == '1')
s += "0";
else
s += "1";
else if (s2[i] == '1')
... | 1 |
#include <bits/stdc++.h>
void Get(int &T) {
char C;
bool F = 0;
for (; C = getchar(), C < '0' || C > '9';)
if (C == '-') F = 1;
for (T = C - '0'; C = getchar(), C >= '0' && C <= '9'; T = T * 10 + C - '0')
;
F && (T = -T);
}
int N, K, L;
int A[10005];
int Pos[25];
struct E {
int V, Next;
} Edge[25000... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int modpow(int b, int e) {
int a = 1;
while (e) {
if (e & 1) a = 1LL * a * b % MOD;
b = 1LL * b * b % MOD;
e >>= 1;
}
return a;
}
int dp[5000001];
int sieve[5000001];
void precompute() {
for (int i = 2; i <= 5000000; ++i) {
... | 5 |
#include <bits/stdc++.h>
const int oo = 0x7fffffff;
const long long OO = 0x7fffffffffffffff;
template <class T>
std::ostream& operator<<(std::ostream& O, const std::vector<T>& V) {
for (const T& x : V) O << x << " ";
O << "\n";
return O;
}
template <class T1, class T2>
std::ostream& operator<<(std::ostream& O, co... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, p = 0, n = 0, x, t;
cin >> N;
t = N;
while (t--) {
cin >> x;
if (x > 0)
p++;
else if (x < 0)
n++;
}
if (p >= (N + 1) / 2)
cout << 1;
else if (n >= (N + 1) / 2)
cout << -1;
else
cout << 0;
return 0;
}
| 0 |
#include<bits/stdc++.h>
using namespace std;
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define int long long
#define pqb ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[1001], k = 0;
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 1; i < n - 1; i++) {
if (a[i] > a[i - 1] && a[i] > a[i + 1])
++k;
else if (a[i] < a[i - 1] && a[i] < a[i + 1])
++k;
}
cout << k;
return 0;
}... | 0 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:20000000")
using namespace std;
const int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
const int SIZE = 2048;
const int RAD = 3;
const double BLACK_THRES = 0.5;
const int COMP_SIZE_THRES = 100;
int n;
int matr[SIZE][SIZE];
double smooth[SIZE][SIZE];
inline boo... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int l = 0, u = 0;
cin >> s;
for (int i = 0; i < s.size(); i++) {
if (s[i] > 90)
l++;
else
u++;
}
if (l >= u) {
transform(s.begin(), s.end(), s.begin(), ::tolower);
cout << s << endl;
} else {
transform(s.b... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 5;
const int inf = 0x3f3f3f3f;
int n;
struct SegmentTree {
int mn, id, col;
} tree[maxn << 2];
void up(int p) {
if (tree[p * 2].mn < tree[p * 2 + 1].mn) {
tree[p].mn = tree[p * 2].mn;
tree[p].id = tree[p * 2].id;
} else {
tree[p].mn ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, ans;
multiset<int> setik;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
setik.insert(x);
}
while (setik.size()) {
int cur = 0;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int m = *max_element(a.begin(), a.end());
bool flag = true, ans = true;
if (m == a[0]) flag = false;
for (int i = 1; i < n; i++) {
if (a[i] < a[i - 1] && f... | 1 |
#include <bits/stdc++.h>
using namespace std;
const double pi = 3.14159265358979323846;
void rw() {}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, m, p = 0;
cin >> n >> m;
cout << min(n, m) + 1 << "\n";
while (n >= 0 && p <= m) {
cout << n << " " << p << "\n";
n-... | 3 |
#include <bits/stdc++.h>
char s[1000010], t[1000010];
int ans;
int main() {
int i, j, x = 0, y = 0;
scanf("%s%s", s + 1, t + 1);
for (i = 1; t[i]; i++) y ^= t[i] - '0';
for (i = 1; t[i]; i++) x ^= s[i] - '0';
ans += x ^ y ^ 1;
for (j = 1; s[i]; i++, j++) {
x ^= s[i] - '0';
x ^= s[j] - '0';
ans +... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
bool f1(int x, int y, int** a) {
if (x < 0 || y < 0 || x >= n || y >= m) return false;
if (x == n - 1 && y == m - 1) return true;
if (a[x][y] == -1) return false;
a[x][y] = 1;
if (f1(x + 1, y, a)) return true;
if (f1(x, y + 1, a)) return true;
a[x][y... | 5 |
#include <bits/stdc++.h>
using namespace std;
struct Splay {
int l, r, fa, maxdep, mindep, dep, sign;
} t[220000];
vector<int> E[220000];
int tim, dfn[220000], dfn2[220000], qn, q[220000], root, n, m, i, x, y, k, j,
type, ans, pos[220000], cnt;
void dfs(int x, int dep) {
dfn[x] = ++tim;
pos[tim] = x;
t[tim]... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int SIZE = 1e5 * 2 + 5;
const int INF = 0x3f3f3f3f;
int main() {
int n;
scanf("%d", &n);
vector<int> a(n);
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
sort(a.begin(), a.end());
int ans = 1;
for (int i = 1; i < n; i++)
if (a[i] == a[i - 1]) ans++;... | 2 |
#include <bits/stdc++.h>
const int MAXN = 100005;
int x1[MAXN], x2[MAXN];
std::map<int, int> cnt;
int main() {
int n, y1;
scanf("%d %d", &n, &y1);
for (int i = 0; i < n; i++) scanf("%d", &x1[i]);
int m, y2;
scanf("%d %d", &m, &y2);
for (int i = 0; i < m; i++) scanf("%d", &x2[i]);
int ans = 2;
for (int l... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
string a, b;
cin >> a >> b;
int cnt1, cnt2, cnt3, cnt4;
cnt1 = cnt2 = cnt3 = cnt4 = 0;
for (int i = 0; i < n; i++) {
... | 4 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma,sse2")
#pragma GCC optimization("unroll-loops")
using namespace std;
int64_t t, n, l, r, a[1000005];
string s;
bool prime(int x) {
for (int i = 2; i * i <= x; i++) {
if (x % i == 0) return 0;
}
return 1;
}
void solve() {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int maps[1005][1005];
int main() {
int n, a, b;
scanf("%d%d%d", &n, &a, &b);
if (n == 1 && a == 1 && b == 1) {
printf("YES\n");
printf("0\n");
} else if ((n <= 3 && a == 1 && b == 1) || min(a, b) != 1)
printf("NO\n");
else {
for (int i = 1; i <= n;... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1100005;
const long long MOD = 998244353;
int n, cnt, tot;
int a[MAXN];
int sum[MAXN];
long long ans;
long long fac[MAXN];
long long inv[MAXN];
long long power(long long a, long long b) {
long long res = 1;
while (b) {
if (b & 1) (res *= a) %= MOD;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long l[200001];
long long r[200001];
vector<pair<long long, pair<int, int> > > P;
int ans[200001];
set<pair<long long, int> > ms;
int main() {
int N, M;
scanf("%d%d", &N, &M);
for (int i = 0; i < N; i++) {
scanf("%lld%lld", &l[i], &r[i]);
if (i > 0) {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
string s, good;
cin >> s >> good;
int k, lens = s.length(), bad = 0;
cin >> k;
long long pow31[1500], pow37[1500];
pow31[0] = 1;
pow37[0] = 1;
set<pair<long long, long long>> st;
for (int i = 1; i < 1500; i++) {
pow31[i] = (pow31[i - 1] ... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
long long r;
while (b != 0) {
r = a % b;
a = b;
b = r;
}
return a;
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
const int maxn = 110;
int n;
int a[maxn][maxn];
int res[maxn][maxn];
bool... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100;
int a[N], b[N];
vector<int> vec;
int main() {
int n, k;
cin >> n >> k;
for (int i = 0; i < n; i++) cin >> b[i];
sort(b, b + n);
for (int i = 0; i < n; i++) {
a[i] = b[n - i - 1];
}
while (k > 0) {
for (int i = vec.size(); i < n && k ... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long inv_euclid(long long a, long long m = 998244353) {
long long m0 = m;
long long y = 0, x = 1;
if (m == 1) return 0;
while (a > 1) {
long long q = a / m;
long long t = m;
m = a % m, a = t;
t = y;
y = x - q * y;
x = t;
}
if (x < 0)... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long int arr[300005];
int main() {
int n, sum = 0, x, y;
cin >> n;
map<int, int> mp, mp1;
if (n > 36) {
cout << -1;
return 0;
}
while (n >= 2) {
cout << 8;
n -= 2;
}
if (n == 1) {
cout << 4;
}
}
| 2 |
#include <bits/stdc++.h>
const int N = 200005;
const int cIz = 1000000007;
inline int Pow(int a, int b) {
int ans = 1;
for (; b; b >>= 1) {
if (b & 1) ans = (long long)ans * a % cIz;
a = (long long)a * a % cIz;
}
return ans;
}
inline int Inv(int a) { return Pow(a, cIz - 2); }
template <typename T>
inlin... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n % 2 == 0)
cout << 0;
else
cout << 1;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n, k, A1, B, x, A[100004];
long long int Snap(int, int);
int pow1(int, int);
int CalcAv(int, int);
int main() {
int i;
cin >> n >> k >> A1 >> B;
for (i = 0; i < k; ++i) {
cin >> A[i];
}
sort(A, A + k);
n = pow1(2, n);
long long int ans;
ans = Snap(1,... | 4 |
#include <bits/stdc++.h>
using namespace std;
void doit(int& a, int b) {
if (a == -1)
a = b;
else
a = min(a, b);
}
vector<vector<int>> getCost(vector<vector<int>> A, int idx) {
int n = A.size();
int m = A[0].size();
vector<vector<int>> D(n, vector<int>(m, -1));
vector<vector<int>> V(n, vector<int>(m... | 7 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.