solution stringlengths 53 181k | difficulty int64 0 13 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t, a, b;
scanf("%lld%lld%lld", &t, &a, &b);
if (t == a && b == a && t == 1) {
puts("inf");
} else if (t != 1 && t != a && a == b) {
puts("1");
} else if (t == a && b == a && t > 1) {
puts("2");
} else if (a == 1) {
puts("0"... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
long long res = 1;
a %= mod;
for (; b; b >>= 1) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
}
return res;
}
int best = 0;
vector<int> sol;
map<pair<int, int>, pair<int, i... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
for (int i = 0; i < t; i++) {
int n;
cin >> n;
int k;
k = pow(2, (n / 2) + 1) - 2;
cout << k << endl;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
int n, m;
long long A[555];
long long findrt(long long num, int P) {
long long lft = 0, rgt = (P == 2 ? 2000000000LL : (P == 3 ? 2000000 : 37700));
while (lft + 1 < rgt) {
long long mid = (lft + rgt) ... | 6 |
#include <bits/stdc++.h>
using namespace std;
long double t[120001], v[120001], ans[120001], a, d;
int n, i;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> a >> d;
cout << setprecision(10) << fixed;
for (i = 1; i <= n; i++) cin >> t[i] >> v[i];
for (i = 1; i <= n; i++) {
ans[i] = t[i];
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k, x, y;
char a[510][510];
bool b[510][510];
int xx[4] = {0, 1, 0, -1};
int yy[4] = {1, 0, -1, 0};
void rec(int i, int j) {
b[i][j] = 1;
for (int g = 0; g < 4; g++) {
if (a[i + xx[g]][j + yy[g]] == '.' && !b[i + xx[g]][j + yy[g]]) {
rec(i + xx[g], j ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long int MAXx = 1e7 + 7;
const long long int MOD = 1000000007;
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
void read(long long int n, vector<long long int> &v) {
for (long long int i = 0; i < n; i++) cin >> v[i];... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, long long int y) {
if (y == 0) return 1;
long long int s = power(x, y / 2);
s *= s;
if (y % 2 == 1) s *= x;
return s;
}
long long int fac(long long int x) {
long long int pppp = 1;
for (int i = 2; i <= x; i++) {
pppp *=... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1000010;
const int MAXN = 51000;
const int SQ = 300;
int n, m;
int go[MAX];
int a[MAXN];
int gn[MAXN];
bool cmp(tuple<int, int, int> a, tuple<int, int, int> b) {
int x = get<0>(a);
int y = get<0>(b);
x /= SQ;
y /= SQ;
if (x < y) return 1;
if (x >... | 10 |
#include <bits/stdc++.h>
using namespace std;
int cnt[1010];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n - 1; i++) {
int x, y;
scanf("%d %d", &x, &y);
if (y != n) {
puts("NO");
return 0;
}
cnt[x]++;
}
int cur = 0;
for (int i = 1; i < n; i++) {
cur += cnt[i]... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long lucky[1111];
int cnt, k;
void dfs(int digit, int i, int Lnumber) {
if (i == digit) {
++cnt;
lucky[cnt] = Lnumber;
return;
}
dfs(digit, i + 1, Lnumber * 10 + 4);
dfs(digit, i + 1, Lnumber * 10 + 7);
}
long long intersection(long long x1, long lo... | 5 |
#include <bits/stdc++.h>
using namespace std;
int nxt() {
int res;
scanf("%d", &res);
return res;
}
const int N = 100000;
char c[N + 1][10];
int len[N + 1];
int ans[N + 1];
int pw[10];
int getNum(int pos) {
vector<int> q;
for (int i = 0; i < len[pos]; ++i) {
if (c[pos][i] == '?') {
q.push_back(i);
... | 6 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int l = 0, n = 0;
string s;
while (getline(cin, s)) {
if (s[0] == '+')
n++;
else if (s[0] == '-')
n--;
else
l += n * (s.size() - s.find(':') - 1);
}
cout << l;
}
int main() {
ios_base::sync_with_stdio(false);
cin.ti... | 1 |
#include <bits/stdc++.h>
using namespace std;
int t, n, x[4005];
set<int> s;
bool dp[4005];
int main() {
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
for (int i = 0; i < n * 2; i++) {
scanf("%d", x + i);
s.insert(i + 1);
}
memset(dp, 0, n * 2 + 1);
dp[0] = 1;
for (int i = n * ... | 5 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:67108864")
using namespace std;
const long double EPS = 1e-9;
const int INF = 1 << 28;
const long double PI = fabsl(atan2l(0.0, -1.0));
const int MAXCHIPS = 5005;
int n;
int b[101][101];
void load() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
for (in... | 3 |
#include <bits/stdc++.h>
const int a[] = {0, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1,
14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1,
51, 1, 2, 1, 14, 1, 2, 2, 14, 1, 6, 1, 4, 2, 2, 1,
52, 2, 5, 1, 5, 1, 15, 2, 13, 2, 2, 1, 13, 1, 2, 4,
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 1e5 + 5;
void re(int &x) { scanf("%d", &x); }
void re(long long &x, long long &y) { scanf("%lld%lld", &x, &y); }
long long A[N], B[N];
long long F[N], T[N], X[N], V[N], n, w, i, j;
long long asd;
void up(int x, int t) {
for (; x < N;... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long in() {
long long a;
scanf("%lld", &a);
return a;
}
double din() {
double a;
scanf("%lf", &a);
return a;
}
long long bigmod(long long b, long long p, long long md) {
if (p == 0) return 1;
if (p % 2 == 1) {
return ((b % md) * bigmod(b, p - 1, md)... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long int modpow(long long int a, long long int n, long long int temp) {
long long int res = 1, y = a;
while (n > 0) {
if (n & 1) res = (res * y) % temp;
y = (y * y) % temp;
n /= 2;
}
return res % temp;
}
int leftit[1000006], rightit[1000006], arr[10... | 4 |
#include <bits/stdc++.h>
using namespace std;
clock_t __stt;
inline void TStart() { __stt = clock(); }
inline void TReport() {
cerr << fixed << setprecision(3) << "\nCurrent Case Taken Time : "
<< (double)(clock() - __stt) / CLOCKS_PER_SEC << "sec\n";
}
template <typename T>
T MIN(T a, T b) {
return a < b ? ... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long a, b, n, l, t, m;
int main() {
scanf("%I64d%I64d%I64d", &a, &b, &n);
for (int i = 1; i <= n; i++) {
scanf("%I64d%I64d%I64d", &l, &t, &m);
if (t < a + (l - 1) * b) {
puts("-1");
continue;
}
long long low = 1, high = 5000000;
whil... | 5 |
#include <bits/stdc++.h>
using namespace std;
bool v[105];
int ara[105];
int main() {
int T;
cin >> T;
for (int t = 1; t <= T; t++) {
int N;
memset(v, 0, sizeof(v));
cin >> N;
for (int i = 0; i < N; i++) {
cin >> ara[i];
}
for (int i = N - 2; i >= 0; i--) {
if (ara[i] > ara[i +... | 3 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> adj[200005];
map<int, int> card;
set<int> s[200005];
bool vis[200005];
vector<int> ans;
int dfs(int node, int p) {
vis[node] = true;
int ret = 0;
for (auto x : adj[node]) {
if (x.first != p) {
int t = dfs(x.first, node);
if (t ==... | 4 |
#include <bits/stdc++.h>
using namespace std;
int m, n, nums[1010][35], P[1010] = {0}, nCr[1010][1010], basis[1010][35],
sz = 0, pivots[1010];
char buf[1010];
int main() {
int mask = 0x1F, shift = 5;
scanf("%d%d", &m, &n);
for (int i = 0; i < n; i++) {
scanf("%s", buf);
for (int ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long MN = 1111;
long long t[MN][2];
long long used[MN];
int main() {
long long n;
cin >> n;
for (long long i = 0; i < n; ++i) {
cin >> t[i][0] >> t[i][1];
}
long long ans = 1e18;
for (long long i = 1; i <= 1000; ++i) {
long long q = n / 2;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i = 0, j = 0, k = 0, tmp = 0, tmp1 = 0, tmp2 = 0, tmp3 = 0, tmp4 = 0,
tmp5 = 0, flag = 0, T = 0, N = 0, Q = 0;
cin >> N;
vector<int> rate(2001, 0), rank(2001, 1);
for (i = 1; i < N + 1; i++) {
cin >> rate[i];
int cur = 0;
for (j = ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int n, m, q, cnt;
int a[maxn];
int val[maxn];
int lit[maxn], rit[maxn];
int lazy[maxn << 2];
int vis[maxn];
vector<int> v[maxn];
bitset<1005> prime;
bitset<1005> resta;
bitset<1005> tr[maxn << 2];
void pushdown(int num) {
lazy[num] %= m;
if (laz... | 10 |
#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
int i;
stringstream(s) >> i;
return i;
}
inline string toString(int i) {
string s;
stringstream ss;
ss << i;
ss >> s;
return s;
}
vector<vector<int> > cat;
void f(int n, vector<int> x) {
if (n == 0) {
vector<int> c(3, 0);
... | 6 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int sum = 0;
char c = getchar();
bool f = 0;
while (c < '0' || c > '9') {
if (c == '-') f = 1;
c = getchar();
}
while (c >= '0' && c <= '9') {
sum = sum * 10 + c - '0';
c = getchar();
}
if (f) return -sum;
return sum;
}
... | 7 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> G;
vector<vector<int>> E;
vector<pair<pair<int, int>, float>> xs;
bool error_found = false;
vector<pair<int, float>> dfs(int v, int p, int flow) {
if (p != -1 && G[v].size() == 1) {
vector<pair<int, float>> leafs;
leafs.push_back(make_pair(v, f... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int m, n;
cin >> m >> n;
bool p[n];
for (int i = 0; i < n; i++) {
cout << m << '\n';
fflush(stdout);
int d;
cin >> d;
if (d == 0) {
return 0;
}
if (d == 1) {
p[i] = false;
} else {
p[i] = true;
}
}... | 5 |
#include <bits/stdc++.h>
using namespace std;
bool used[30000 + 5][605 + 5];
int memo[30000 + 5][605 + 5];
int v[30000 + 5];
int D;
int dp(int pos, int dx) {
if (pos > 30000) return 0;
if (used[pos][300 + dx]) return memo[pos][300 + dx];
used[pos][300 + dx] = 1;
int &dev = memo[pos][300 + dx] = 0;
int L = D +... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
string s;
cin >> s;
if (n == 1 && k)
s[0] = '0';
else
for (int i = 0; k && i < n; i++)
if (s[i] > '0' + !i) {
s[i] = '0' + !i;
k--;
}
cout << s << '\n';
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int N;
int x[100010], y;
double a[100010], b[100010];
double dist(double x, double y) { return sqrt(x * x + y * y); }
double calc(int low, int high, int K) {
double d1 = dist(x[N] - x[low], y);
double d2 = dist(x[N] - x[high], y);
if (K >= low && K <= high)
return... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
const long long N = 2e5 + 5;
const long long NN = 1e3 + 3;
const long long MOD = (1e9 + 7);
const long long MOD1 = 998244353;
const double PI = 3.14159265;
const int INF32 = 2e9;
const long long INF64 = 2e18;
v... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int num;
int a[N][N];
int main() {
scanf("%d", &num);
for (int i(1); i <= (100); ++i) {
int s = 0;
for (int j = 1; j < i && s <= num; ++j) {
num -= s;
++s;
a[i][j] = a[j][i] = 1;
}
}
puts("100");
for (int i(1); i <=... | 4 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
int main() {
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
vector<int> ma(m);
vector<vector<int>> a(n, vector<int>(m));
for (int i = (int... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, m, a[100005], h[100005], b[100005], f[100005], ff1[100005], ff2[100005],
a1[100005];
bool maximize(int &a, int b) {
if (a < b)
a = b;
else
return false;
return true;
}
void LIS(int nn) {
int answer = 0;
memset(f, 0, sizeof f);
memset(b, 0, siz... | 5 |
#include <bits/stdc++.h>
using namespace std;
vector<int> vec[200005];
int A[200005], B[200005];
int to[200005];
int f[200005];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
int a, b;
scanf("%d %d", &a, &b);
a--, b--;
vec[a / 2].push_back(b / 2);
vec[b / 2].push_back(a / 2... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int i, j, k, l, n, a[52][52], flag[2510] = {0};
while (cin >> n) {
for (i = 0; i < n; i++)
for (j = 0; j < n; j++) cin >> a[i][j];
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
for (k = 0; k < n; k++)
for (l = 0; ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x1, y1, x2, y2;
cin >> n >> x1 >> y1 >> x2 >> y2;
int r = 0;
while (x1 != x2 || y1 != y2) {
if (x1 == 0 && y1 != n) {
y1++;
} else if (y1 == 0 && x1 != 0) {
x1--;
} else if (x1 == n && y1 != 0) {
y1--;
} else {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
bool vis[1010][1010];
vector<pair<int, int> > res;
int d[310];
int main() {
memset(vis, 0, sizeof(vis));
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &d[i]);
int L = 1, R = n;
int l = 1, r = d[n] + 1;
while (1) {
if (L == R) {
for... | 8 |
#include <bits/stdc++.h>
using namespace std;
int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};
void testCase() {
int n, k;
cin >> n >> k;
int arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
int boxes[k];
for (int i = 0; i < k; i++) {
boxes[i] = arr[n - 1 - i];... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
int((a)[(n)]);
for (int i = 0; i < (n); i++) cin >> ((a)[i]);
sort(a, a + n);
reverse(a, a + n);
long long q[n];
long long sm[n + 1];
sm[0] = 0;
for (int(i) = 0; (i) < (n); (i)++) sm[i + 1] = a... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
long long n;
cin >> n;
int num[5] = {1, 5, 10, 20, 100};
long long count[5] = {0};
for (int i = 4; i >= 0; i--) {
count[i] += n / num[i];
n -= count[i] * num[i];
}
cout << accumulate(count, ... | 0 |
#include <bits/stdc++.h>
using namespace std;
char s[1001];
int main() {
long long l, sum = 0, x = 0, flag = 1;
cin >> s;
l = strlen(s);
for (int i = 0; i < l; ++i) {
if (s[i] < '0' || s[i] > '9') {
sum += x * flag;
x = 0;
if (s[i] == '+') {
flag = 1;
}
if (s[i] == '-')... | 8 |
#include <bits/stdc++.h>
using namespace std;
int r, g, b, mx, i;
int main() {
cin >> r >> g >> b;
r += r % 2;
g += g % 2;
b += b % 2;
mx = max(r, max(g, b));
i = mx == b ? 2 : mx == g ? 1 : 0;
cout << 30 + (mx / 2 - 1) * 3 + i;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
vector<pair<long long, long long> > q;
long long n, qc;
long long cnt[10005];
bool can[10005];
signed main() {
ios::sync_with_stdio(false);
cin >> n >> qc;
for (long long i = 1; i <= qc; i++) {
long long l, r, v;
cin >> l >> r ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin >> n >> m;
vector<int> v1[n + m + 5], v2[n + m + 5];
int a[n + 1][m + 1], b[n + 1][m + 1];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> a[i][j];
}
... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a - (a / b * b));
}
long long mypow(long long a, long long b) {
long long p = 1;
if (b == 0) return 1;
for (long long i = 0; i < b; i++) p *= a;
return p;
}
long long zero(long long a)... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.tie(0)->sync_with_stdio(0);
int n;
cin >> n;
vector<vector<int>> adj(n);
for (int i = 1; i < n; ++i) {
int u, v;
cin >> u >> v, --u, --v;
adj[u].push_back(v), adj[v].push_back(u);
}
array<int, 2> cnt{};
function<void(int, int, in... | 10 |
#include <bits/stdc++.h>
using std::max;
long long tree[1001000], n, m, a[400100], ans[400100];
void modify(long long t, long long l, long long r, long long pos,
long long val) {
if (l == r) {
tree[t] = val;
return;
}
long long mid = (l + r) / 2;
if (pos <= mid)
modify(t * 2, l, mid, pos... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, x;
cin >> n;
vector<long long int> v, v1;
long long int a[n];
for (long long int i = 0; i < n; i++) {
cin >> x;
v.push_back(x);
}
long long int idx = 0;
sort(v.begin(), v.end());
long long int l = 0, r = 0;
long long... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long int mod1 = 1000000007;
long long int mod2 = 67280421310721;
long long int mod3 = 998244353;
long long int INF = 1e18;
long long int binpow1(long long int a, long long int b) {
long long int res = 1;
while (b > 0) {
if (b & 1) res = res * a;
a = a * a;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, a, b, s, e, r;
scanf("%d %d %d %d", &n, &m, &a, &b);
s = (a - 1) % m;
e = (b - 1) % m;
if (e - s == b - a) {
printf("1\n");
} else {
r = ((b - a + 1) - (m - s) - (e + 1)) / m;
if (s == 0 && e == m - 1 || s == 0 && b == n) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MX = 105;
vector<int> g[MX], tsort;
string s[MX];
int n, vis[MX], use[MX];
void dfs(int x) {
vis[x] = use[x] = 1;
for (int i = 0; i < g[x].size(); i++) {
if (use[g[x][i]]) {
puts("Impossible");
exit(0);
} else if (!vis[g[x][i]]) {
dfs... | 4 |
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;
int IT_MAX = 1 << 17;
const long long MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const double ERR = 1e-10;
int Co[25][25];... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, l, wmax;
cin >> n >> l >> wmax;
vector<int> plus, minus;
for (int i = 0; i < n; i++) {
int x, v;
cin >> x >> v;
if (v == 1)
plus.push_back(x);
else
minus.push_back(x... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int te;
cin >> te;
long long int sa = 0, sg = 0;
while (te--) {
int a, g;
cin >> a >> g;
if (abs((sa + a) - sg) > 500) {
cout << "G";
sg = sg + g;
} else {
cout << "A";
sa = sa + a;
}
}
cout << "\n";
ret... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
int s[n];
int zerosin = 0;
int unodest = 0;
for (int i = 0; i < n; i++) {
cin >> s[i];
if (s[i] == 1) {
unodest++;
}
}
int somma = zerosin + unodest;
for (int i = 0; i < n; i++)... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n;
string s;
bool read() {
if (!getline(cin, s)) {
return 0;
}
return 1;
}
int id(char c) {
const string C = "RBYG";
int res = find(begin(C), end(C), c) - C.begin();
assert(res < ((int)(C).size()));
return res;
}
bool was[4];
void solve() {
vector<in... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long int arr[100005], sumb[100005], n, A, cf, cm, m,
summ = 0, newmi = 0, newcoun = 0, temp[100005];
vector<long long int> vec;
vector<pair<long long int, long long int> > a;
vector<long long int>::iterator it;
int main() {
cin >> n >> A >> cf >> cm >> m;
for (... | 5 |
#include <bits/stdc++.h>
using namespace std;
void setmax(long long &a, const long long &b) {
if (a < b) a = b;
}
struct node {
node *children[2];
bool value;
int depth;
node(const bool &b = false, const int &d = 43) {
children[0] = NULL;
children[1] = NULL;
value = b;
depth = d;
}
} t;
void... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[1005];
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int cnt = 0;
for (int i = 1; i < n - 1; i++) {
if (a[i] < a[i - 1] && a[i] < a[i + 1]) cnt++;
if (a[i] > a[i - 1] && a[i] > a[i + 1]) cnt++;
}
cout << cnt;
... | 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
stringstream output;
inline void eOP();
inline void solve() {
int n;
cin >> n;
string a, b;
cin >> a >> b;
vector<vector<bool>> m(20, vector<bool>(20));
for (int i = 0; i < n; ++i) {
int f = a[i] - 'a';
int t = b[i] - 'a';
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, mod = 1e9 + 7;
struct atom {
double x, y;
atom(double _x = 0, double _y = 0) { x = _x, y = _y; }
atom operator+(const atom &ch) { return atom(x + ch.x, y + ch.y); }
atom operator-(const atom &ch) { return atom(x - ch.x, y - ch.y); }
atom ope... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long mpow(long long c, long long n) {
long long rt = 1;
for (long long ii = 0; ii < n; ii++) {
rt *= c;
}
return rt;
}
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
long long h, n;
cin >> h >> n;
long long ans = mpow(2, h + 1) -... | 4 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
const int inf = INT_MAX;
const int nmax = 1e5 + 5;
const int mod = 1e9 + 7;
using namespace std;
int k, nr, ans[101][101], i, j, ed;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cerr.tie(0);
cout.tie(0);
cin >> k;
for (i = 3; i * (i - 1) * (i... | 4 |
#include <bits/stdc++.h>
using namespace std;
map<pair<int, int>, int> mp;
int main() {
int n, k;
cin >> n >> k;
int l = 1, r = 2;
int fl = 0;
for (int i = 0; i < k; i++) {
l = 1;
r = i + 2;
for (int j = 0; j < n; j++) {
pair<int, int> p = make_pair(l, r);
if (mp[p]) {
fl = 1;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int read() {
int res = 0, w = 1;
char c = getchar();
while (!isdigit(c) && c != '-') c = getchar();
if (c == '-') c = getchar(), w = -1;
while (isdigit(c)) res = (res << 1) + (res << 3) + c - '0', c = getchar();
return res * w;
}
int a1, b1, a2, b2, a3, b3, a4, ... | 4 |
#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&... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int i, n;
cin >> n;
for (i = 1;; ++i) {
if ((i * (i + 1)) / 2 >= n) break;
}
cout << n - (i * (i - 1)) / 2;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int isprime(int n) {
for (int i = 2; i <= sqrt(n); i++) {
if (n % i == 0) return 0;
}
return 1;
}
long long ispalindrome(string s, long long n) {
long long l = 0, h = n - 1;
while (l < h) {
if (s[l++] != s[h--]) return 0;
}
return 1;
}
int issorted(lon... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long INFLL = 1e12;
const int MOD = 1000000007;
void fast_io() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
}
int main() {
fast_io();
int t;
cin >> t;
while (t--) {
string s1, s2;
cin >> s1 >> s2;
vector<int> kek(26, ... | 1 |
#include <bits/stdc++.h>
using namespace std;
string st;
long long h1, h2, h3, n1, n2, n3, p1, p2, p3, l, r, m, money;
long long gett(long long x) {
long long res, need;
res = 0;
need = n1 * x;
if (h1 >= need)
res += 0;
else
res += (need - h1) * p1;
need = n2 * x;
if (h2 >= need)
res += 0;
e... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, z, u, r, l, s, h, k, y, x, t, a[1091001], b[1234567],
e[1234567];
long long i, j;
long long c[1234567], d[986667];
map<long long, vector<long long>> f;
string p[978685], q, w;
int main() {
cin >> n >> k;
cin >> x >> y;
for (i = 0; i < n; i++) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
if (b > a) {
long long int temp = a;
a = b;
b = temp;
}
if (a % b) {
return gcd(b, a % b);
} else
return b;
}
void solve() {
long long int n, x, y, a, b, pb, pa;
cin >> x >> y >> n;
floa... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long delbit(long long a, long long k) { return a & (~(1 << k)); }
int delbit(int a, int k) { return a & (~(1 << k)); }
bool getbit(long long a, long long k) { return 1 & (a >> k); }
bool getbit(int a, int k) { return 1 & (a >> k); }
long long setbit(long long a, long l... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
inline long long int rl() {
long long int res = 0, neg = 0;
char c = getchar();
while ((c < '0' || c > '9') && c != '-') c = getchar();
if (c == '-') neg = 1, c = getchar();
while (c >= '0' && c <= '9') {
res = (res << 1) + (res << 3) ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n;
cin >> n;
string s;
cin >> s;
long long a = 0;
long long b = 0;
for (long long i = 0; i < n; ++i) {
if (s[i] == s[0])
++a;
else
break;
}
for (lon... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 30;
char buf[1000];
string nextLine(int length = 100) {
cin.getline(buf, length);
string s(buf);
return s;
}
string next(int length = 100) {
string tmp;
cin >> tmp;
return tmp;
}
int nextInt() {
int tmp;
scanf("%d", &tmp);
return tmp;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100003;
int a[maxn], b[maxn];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
b[i] = a[i];
}
sort(a, a + n);
int c = 0;
for (int i = 0; i < n; i++) c += (a[i] != b[i]);
cout << (c <= 2 ? "YES" : "NO");
retu... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, x, y, maxi = 0;
long long arr[1000], arr1[1000];
cin >> n;
for (int i = 0; i < n; i++) cin >> arr[i];
for (int i = 0; i < n; i++) cin >> arr1[i];
for (int i = 0; i < n; i++) {
x = arr[i];
y = arr1[i];
for (int j = i + 1; j <... | 0 |
#include <bits/stdc++.h>
using namespace std;
int N;
string S;
int f(char a) {
if (a == 'A') return 0;
if (a == 'T') return 1;
if (a == 'G') return 2;
if (a == 'C') return 3;
}
struct node {
int cnt[4];
};
node mrg(node a, node b) {
node ret;
for (int i = 0; i < 4; i++) {
ret.cnt[i] = a.cnt[i] + b.cnt... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5050;
char s[N];
int n, vis[N], V, sg[N];
int a[N], m, l[N], r[N], sv[N], svt;
int main() {
scanf("%s", s + 1);
n = strlen(s + 1);
if (n == 1) {
printf("Second\n");
return 0;
}
sg[1] = 1;
for (int i = 2; i <= n; ++i) {
++V;
vis[sg[i... | 7 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void Read(T& x) {
x = 0;
bool flag = 0;
char ch = getchar();
while (ch > '9' || ch < '0') {
if (ch == '-') {
flag = 1;
ch = getchar();
break;
}
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x *... | 10 |
#include <bits/stdc++.h>
using namespace std;
struct edge {
int to, nxt, id;
long long w;
} a[300000 * 2 + 5];
int ecnt, pre[300000 + 5], res[300000 + 5];
int n, m, S;
long long dist[1 + 1][300000 + 5], val[300000 + 5];
void add(int u, int v, long long w, int id) {
a[++ecnt].to = v;
a[ecnt].nxt = pre[u];
a[ec... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000;
map<pair<string, int>, int> mmap;
map<string, pair<int, int> > ans;
vector<pair<string, int> > v[maxn];
pair<string, int> name[maxn];
vector<int> g[maxn];
int d[maxn];
vector<pair<string, int> > res;
int main() {
int n;
cin >> n;
for (int i = 0;... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const long long LL_INF = 1ll * INF * INF;
const int MAX_N = 1000 + 7;
const int mod = INF;
template <typename T>
inline void addmod(T& a, const long long& b, const int& MOD = mod) {
a = (a + b) % MOD;
if (a < 0) a += MOD;
}
int n;
int a[MAX_N][M... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 110000;
char txt[MAXN], rtxt[MAXN], patt[MAXN], rpatt[MAXN];
int n, sol, tc, pf[MAXN], sp;
int suff[MAXN], pref[MAXN], z[MAXN];
void PF() {
int k = 0;
for (int i = 1; patt[i]; i++) {
pf[i] = 0;
while (k && patt[k] != patt[i]) k = pf[k - 1];
... | 7 |
#include <bits/stdc++.h>
using namespace std;
pair<bool, int> A[210];
int n, k, theorems, q, x, cards;
int lowPerf = 210 * 210, highPerf = -1, curPerf;
int main() {
cin >> n >> k;
theorems = n / k;
cards = k;
for (int i = 0; i < n; i++) {
cin >> x;
A[i].first = 1;
A[i].second = x;
}
cin >> q;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, ans;
cin >> n >> k;
string st, nextst, temp, temp1;
cin >> st;
queue<string> q;
set<string> s;
q.push(st);
s.insert(st);
ans = st.size();
k -= 1;
while (!q.empty() && k > 0) {
nextst = q.front();
q.pop();
for (int i =... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
int n;
long long cf, cm;
long long mAns = -1;
int szAns = -1;
pair<long long, int> a[N];
long long A;
long long sumPref[N], sumSuff[N];
long long m;
long long b[N];
void read() {
scanf("%d%lld%lld%lld%lld", &n, &A, &cf, &cm, &m);
for (int i = 0; i ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double n;
double a[101];
cin >> n;
double sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum = sum + a[i];
}
cout << (sum / (n * 100)) * 100 << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 305;
long long flag[305];
long long n, p, x;
int main() {
cin >> p >> n;
for (int i = 1; i <= n; i++) {
cin >> x;
if (flag[x % p]) {
cout << i;
return 0;
}
flag[x % p] = 1;
}
cout << -1;
return 0;
}
| 0 |
/*
* @file C.cpp
* @path D:\code\ACM\codeforces\EDU_101\C.cpp
* @author Xiuchen
* @date 2020-12-28 23:08:11
*/
#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3,"Ofast","inline")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>
#include<vector>
#include<stack>
#include<qu... | 4 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > v[1005];
pair<pair<int, int>, int> p[1005];
int dfs(int first, int f) {
if (v[first].size() == 1) {
return first;
}
for (auto it : v[first]) {
if (it.first != f) {
return dfs(it.first, first);
}
}
}
int degree[1005];
bool cm... | 4 |
#include <bits/stdc++.h>
using namespace std;
int dx[5] = {0, -1, 1, 0, 0};
int dy[5] = {0, 0, 0, -1, 1};
int main() {
int arr[102], n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
int sum = 1001, ind1, ind2;
for (int i = 0; i < n - 1; i++) {
if (sum > abs(arr[i] - arr[i + ... | 0 |
#include <bits/stdc++.h>
const int N = 210;
const int inf = 0x3f3f3f3f;
using namespace std;
long long n, m, k, I;
int a[N], d[N];
char s[N];
long long dp[N][N];
bool cmp(const int &x, const int &y) { return a[x] < a[y]; }
int main() {
cin >> n >> m >> k;
I = n + m - 1;
for (int i = 0; i < I; i++) a[i] = m * n, d... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e6 + 4;
const int inf = (int)1e9 + 7;
const long double eps = 1e-7;
const int K = 21;
const int M = 1001;
struct cell {
int val, x, y;
cell() { x = 0, y = 0, val = 0; }
cell(int val, int x, int y) : val(val), x(x), y(y) {}
bool operator<(const ce... | 7 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.