solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k;
cin >> n >> k;
long long middle = n / 2;
if (n % 2 == 1) {
middle += 1;
}
if (k <= middle) {
cout << k * 2 - 1 << endl;
} else {
cout << (k - middle) * 2 << endl;
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
long long a[100009];
map<long long, long long> m;
int main() {
long long n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
m[a[i]]++;
}
long long res = 0;
sort(a, a + n);
for (long long i = 0; i < n; i++) {
for (long long j = 1; j <= 20000000... | 7 |
#include <bits/stdc++.h>
using namespace std;
bool comp(pair<int, int> x, pair<int, int> y) { return x.second > y.second; }
int main() {
int n, v;
while (~scanf("%d%d", &n, &v)) {
vector<pair<int, int> > kays;
vector<pair<int, int> > cats;
vector<pair<int, int> > ans;
int t, p;
for (int i = 0; i... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, m[200010];
set<int> s;
struct P {
int i, x;
bool operator<(const P& p) const { return x < p.x; }
} p[200010];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
int x;
scanf("%d", &x);
p[i].i = i;
p[i].x = x;
}
sort(&p[1... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
unsigned int size, temp;
vector<unsigned int> lengthes;
cin >> size;
vector<string> words(size);
for (int i = 0; i < size; i++) {
cin >> words[i];
}
for (int i = 97; i <= 122; i++) {
for (int j... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int a[n];
for (int i = 1; i <= n; i++) cin >> a[i];
int l = 0, r = 0;
for (int i = 1; i <= n; i++) {
if (a[i] <= k)
l++;
else
break;
}
for (int i = n; i > 0; i--) {
if (a[i] <= k)
r++;
e... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
if (n == 1) n++;
printf("%d\n", n - 2);
}
return 0;
}
| 8 |
#include <bits/stdc++.h>
using namespace std;
struct edge {
int to, weight;
};
void solve();
int main() {
int times = 1;
cin >> times;
for (int i = 1; i <= times; i++) {
solve();
cout << '\n';
}
return 0;
}
vector<edge> V[300000 + 50];
int a, b, c, d, e, f;
int arr[300000 + 50], arr1[300000 + 50], a... | 4 |
#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
const int M = 100005;
int fa[M << 1];
int tot;
int n;
void init() {
for (int i = 0; i < M << 1; i++) fa[i] = i;
tot = n;
}
int find(int a) { return a == fa[a] ? a : fa[a] = find(fa[a]); }
bool unio(int a, int b) {
int ra = find(a);
int rb = find... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, l, r;
cin >> l >> r >> a;
while (a > 0) {
if (l <= r) {
l++;
a--;
} else if (l >= r) {
r++;
a--;
}
}
cout << 2 * min(l, r);
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e17 + 9;
int l;
long long n, m;
vector<int> adj[100009];
vector<int> sccs;
int dfs_low[100009];
int dfs_num[100009];
int vis[100009];
int dfscounter = 1;
vector<int> anses[100009];
vector<pair<long long, long long>> edges;
vector<int> adj2[100009];
lo... | 13 |
#include <bits/stdc++.h>
using namespace std;
inline int getInt() {
int ret = 0;
char ch = ' ';
bool flag = 0;
while (!(ch >= '0' && ch <= '9')) {
if (ch == '-') flag ^= 1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
ret = ret * 10 + ch - '0';
ch = getchar();
}
return flag ? -ret ... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)1e6 + 6;
const int inf = (int)1e9 * 2;
const int mod = (int)1e9 + 7;
bool check(char c) {
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y')
return 1;
return 0;
}
int n, a[111];
char s[111];
int main() {
scanf("%d", &n)... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
if (n % 2 == 0) {
cout << n / 2 << endl;
for (long long i = 0; i < n / 2; i++) {
cout << 2 << endl;
}
} else {
n = n - 3;
cout << n / 2 + 1 << endl;
for (long long i = 0; i < n / 2; i++) {
cout ... | 0 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
constexpr bool typetest = 0;
constexpr int N = 2021 + 5;
constexpr ll mod = 998244353;
ll gt[N * 2], rgt[N * 2];
int m, n;
void Read()
{
cin >> m >> n;
}
ll Pow(ll a, ll b)
{
ll ans(1)... | 23 |
#include <bits/stdc++.h>
using namespace std;
int N;
int d = 0;
int ch(long long n) {
int c = 0;
while (n) {
d++;
c = n % 10;
n /= 10;
}
return c;
}
int main() {
long long n, cnt = 0;
cin >> n;
if (n < 10)
cout << 1 << "\n";
else {
int c = ch(n);
long long ans = c;
if (c < 9)... | 1 |
#include <bits/stdc++.h>
using namespace std;
int i, j, k, z, q, timer, x, y, n, m, cnt, even, flag, dlfjl, dskgj, dkfj,
dskfj, boom, r, c;
string expected[305][305];
deque<char> cur[305][305];
int cursz[305][305];
vector<pair<int, int> > shits[2], toshits[2];
int pnt[2];
vector<pair<pair<int, int>, pair<int, int> ... | 16 |
#include <bits/stdc++.h>
using namespace std;
long long M = 1e9 + 7;
long long mpe(long long base, long long exponent, long long modulus) {
long long result = 1;
while (exponent > 0) {
if (exponent % 2 == 1) result = result * base % modulus;
exponent = exponent >> 1;
base = base * base % modulus;
}
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
long long x, dumi;
cin >> x;
string s, dum;
cin >> s;
string ans = s;
long long len = ans.size();
for (int l = 0... | 9 |
#include <bits/stdc++.h>
using namespace std;
void preprocess(int a, int b, set<int>& q, set<int>& q1) {
for (long long i = 2; i * i <= a; ++i) {
if (a % i == 0) {
q.insert(i);
q.insert(a / i);
}
}
for (long long i = 2; i * i <= b; ++i) {
if (b % i == 0) {
q1.insert(i);
q1.inse... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> A(n);
int cnt[55] = {0};
for (auto& i : A) {
cin >> i;
cnt[i]++;
}
int answ = INT_MIN;
for (int s = 2; s <= 2 * n; s++) {
int ans = 0;
for ... | 4 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
long long BSDK() {
long long n, k, f = 2;
scanf("%lld %lld", &n, &k);
while (n % f) {
f++;
}
n += f + --k * 2;
return n;
}
int main() {
int i, t;
scanf("%d... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 310, ninf = -1000000000;
int n, g[maxn][maxn], dp[2 * maxn][maxn][maxn];
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> g[i][j];
}
}
for (int i = 0; i < 2 * maxn; i++) {
for (int j = 0; j ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int M = 1e6 + 15;
const int Q = 1e9 + 7;
int dp[M], f[M];
vector<int> g[M];
void dfs(int i, int pr) {
int s = 0;
int ma1 = 1e9, ma2 = 1e9;
for (int j = 0; j < (int)g[i].size(); j++) {
int v = g[i][j];
if (v != pr) {
dfs(v, i);
s += dp[v];
... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> v;
int n, b, ans = 0, x = 0, y = 0, z = 0, c = 0;
cin >> n >> b;
int arr[n + 1];
arr[n] = 0;
for (int i = 0; i < n; ++i) cin >> arr[i];
for (int i = 0; i < n; ++i) {
((arr[i] & 1) ? ++x : ++y);
if (x == y && arr[i + 1] != 0) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long k, p;
long long mult(long long x, long long y) {
long long r = x * y;
vector<long long> g;
while (r) {
g.push_back(r % k);
r /= k;
}
for (int i = g.size() - 1; i >= 0; i--) {
r = r * 10 + g[i];
}
return r;
}
int main() {
cin >> k;
for... | 5 |
#include <bits/stdc++.h>
using namespace std;
string a, b, c;
int main() {
int T;
cin >> T;
while (T--) {
cin >> a >> b >> c;
bool flag = true;
for (int i = 0; i <= c.length(); i++) {
if (c[i] != a[i] && c[i] != b[i]) {
flag = false;
break;
}
}
if (flag)
cout ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int TSIZE = 1048576;
pair<int, int> t[2 * TSIZE + 3];
const pair<int, int> neutral = make_pair(0x3F3F3F3F, 0);
pair<int, int> operator*(const pair<int, int>& p1, const pair<int, int>& p2) {
return make_pair(min(p1.first, p2.first), 0);
}
void update(int x, const pai... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, a[111111];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
sort(a + 1, a + n + 1);
for (int i = 2; i <= n; i++) {
if (a[i] != a[i - 1] && a[i] < a[i - 1] * 2) {
puts("YES");
return 0;
}
}
puts("NO");
re... | 6 |
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
const int MAXN = 1000010;
const int BASE = 500000;
int l[MAXN], r[MAX... | 23 |
#include <bits/stdc++.h>
using namespace std;
long long int extended_GCD(long long int a, long long int b, long long int &x,
long long int &y) {
if (a == 0) {
x = 0;
y = 1;
return b;
}
long long int x1, y1;
long long int gcd = extended_GCD(b % a, a, x1, y1);
x = y1 - (b ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
int n, m;
char s[1005];
int main() {
int i, t;
char j;
cin >> n >> m;
if (m <= 1) {
puts("NO");
return 0;
}
char maxx = (char)('a' + m - 1);
scanf("%s", s);
bool flag;
for (i = n - 1; i >= 0; i--) {
flag = 0;
for... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
long long lmin[maxn], rmin[maxn];
long long lmax[maxn], rmax[maxn];
pair<long long, long long> a[maxn];
int n;
long long sq(long long x) { return x * x; }
bool check(long long mid) {
int r = 1;
for (int l = 1; l <= n; l++) {
if (a[l].first ... | 21 |
#include <bits/stdc++.h>
const int INF = 1 << 29;
void cycle(std::string &s, bool dir) {
int xpos = -1;
for (int i = 0; i < 4; i++)
if (s[i] == 'X') xpos = i;
if (dir) {
if (xpos == 0)
std::swap(s[0], s[1]);
else if (xpos == 1)
std::swap(s[1], s[3]);
else if (xpos == 3)
std::swap... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long n, m;
long long mod = 1e9 + 7;
long long a[5009];
vector<long long> cow[5009];
long long lef[5009];
long long rig[5009];
pair<long long, long long> merge(pair<long long, long long> a,
pair<long long, long long> b) {
if (a.first >... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int Nmax = 5 * 1e5 + 10;
int n, a, b, T, i, l, ans;
int rcost, lcost;
bool v[Nmax];
int cost(int l, int r) {
if (l == n + 1) return rcost;
int cost1 = rcost + (r - 1) * a + lcost;
int cost2 = lcost + (n - l + 1) * a + rcost;
return min(cost1, cost2);
}
int mai... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long n, k;
const long long N = 1e6 + 101;
const long long xkj = 1e9 + 7;
long long ksm(long long a, long long b, long long xkj) {
long long res = 1;
while (b) {
if (b & 1) res = (res * a) % xkj;
a = (a * a) % xkj;
b >>= 1;
}
return res;
}
long long ... | 14 |
#include <bits/stdc++.h>
using namespace std;
int n, q, a[40];
long double dp[300][40][40], ans;
int main() {
cin >> n >> q;
for (int i = 0; i < n; i++) {
cin >> a[i];
for (int j = 0; j < i; j++)
if (a[j] > a[i]) dp[0][j][i] = 1;
}
for (int k = 1; k <= q; k++)
for (int i = 0; i < n; i++)
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, INF = 1e9 + 7;
int main() {
long long k, d, t;
cin >> k >> d >> t;
double ans = 0;
if (k % d == 0) {
ans = t;
cout << t;
return 0;
}
long long x = k, y = d - (k % d);
long long kk = (2 * t) / (2 * x + y);
if ((kk * (2 * x +... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, m, b, mod;
int a[509] = {0};
int dp[2][509][509] = {0};
int main() {
cin >> n >> m >> b >> mod;
int c = 0;
for (int i = 1; i <= n; i++) cin >> a[i];
dp[0][0][0] = 1;
int act = 0, pas = 1;
for (int i = 1; i <= n; i++) {
act = act + pas;
pas = act -... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int NPLY = 100, NDEP = 1000;
int nply, ndep, blg, totply;
int ply[NDEP + 4];
int cnt[NPLY * NDEP / 2];
bool prnvis[NPLY * NDEP];
int prn[NPLY * NDEP / 2], nprn;
void Process() {
int lim = NPLY * NDEP;
for (int i = 2; i < lim; i++) {
if (!prnvis[i]) prn[++nprn]... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int Z = (int)1e3 + 123;
const int inf = (int)2e9 + 1;
const long long llinf = (long long)2e18 + 1;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m, k;
cin >> n >> m >> k;
int num = (k + 1) / 2;
if (num % m == 0) {
cout << num ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, k, j, x, y;
int a[100][100];
bool tr = true;
cin >> n;
for (i = 1; i <= n; i++)
for (j = 1; j <= n; j++) a[i][j] = 0;
k = ((n * (n - 1)) / 2) - 1;
for (i = 1; i <= k; i++) {
cin >> x >> y;
a[x][y] = 1;
a[y][x] = -1;
}
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
double k[a];
for (int i = 0; i < a; i++) {
cin >> k[i];
}
sort(k, k + a);
double sm = k[0], big = b - k[a - 1], h = 0;
for (int i = 1; i < a; i++) {
h = max(h, (k[i] - k[i - 1]));
}
h = h / 2;
sm = max(sm, ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 9;
int n, h;
int dp[1003][33][33][33][2], ans;
void upd(int x, int a, int b, int c, int d, int y) {
int a1 = a, b1 = b, c1 = c;
if (a1 > c1) swap(a1, c1);
if (b1 > c1) swap(b1, c1);
a1 = min(a1 + 1, h + 1);
b1 = min(b1 + 1, h + 1);
c1 = min... | 15 |
#include <bits/stdc++.h>
const long long mod = 1000 * 1000 * 1000 + 7;
const long long mod1 = 998244353;
const long long INF = 1ll * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 7;
using namespace std;
long long power(long long x, long long y) {
long long res = 1;
while (y > 0) {
if (y & 1) res = (long long)(res *... | 7 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
struct pkt {
double x, y, nr;
};
bool por(pkt a, pkt b) {
if (a.y > 0 && b.y > 0) {
if (a.x / a.y > b.x / b.y) return true;
if (a.x / a.y < b.x / b.y) return false;
return a.nr < b.nr;
}
if (a.y < 0 && b.y < 0) {
if (a.x /... | 10 |
#include <bits/stdc++.h>
using namespace std;
int pow(int a, int n) {
for (int i = 0; i < n - 1; i++) a *= 2;
return a;
}
int cal(int a) {
int ans[10];
memset(ans, 0, sizeof(ans));
int i = 0;
while (a > 0) {
if (a % 2 == 1) ans[i] = 1;
i++;
a /= 2;
}
int sum = 0;
for (int j = 7; j >= 0; j-... | 5 |
#include <bits/stdc++.h>
using namespace std;
char s[6][7] = {"211012", "120112", "111012", "110112", "000011", "000001"};
struct matrix {
long long a[6][6];
matrix() { memset(a, 0, sizeof(a)); }
void print() {
for (int i = 0; i < 6; ++i) {
for (int j = 0; j < 6; ++j) cout << a[i][j] << " ";
cout ... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, x;
cin >> n >> x;
int res = 0;
for (int i = 1; i <= n; ++i) {
if (x % i == 0 and x / i <= n) {
++res;
}
}
cout << res << endl;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int test(int x) {
for (int i = 2; i * i <= x; i++) {
if (x % i == 0) return false;
}
return true;
}
int main() {
int n;
cin >> n;
int x, y;
for (int i = 4; i < n; i++) {
int m;
if (!test(i)) {
m = n - i;
if (!test(m)) {
x = i;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
inline int add(int a, int b, int m = 1000000007) {
a += b;
if (a >= m) a -= m;
return a;
}
inline int mul(int a, int b, int m = 1000000007) {
return (int)(((long long)a * (long long)b) % m);
}
inline int norm(int x, int m = 1000000007) {
if (x >= m) x %= m;
if (... | 17 |
#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long b, long long m = 998244353) {
long long res = 1;
while (b > 0) {
if (b & 1) res = (res * a) % m;
a = (a * a) % m;
b >>= 1;
}
return res;
}
long long inverse(long long a, long long m = 998244353) {
return power(a, ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const double PI = 2 * acos(0.0);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());
const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";
template <c... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const int maxint = 0x7f;
unsigned long long cnk(unsigned long long nn, unsigned long long kk) {
const int maxn = 60;
unsigned long long C[maxn + 1][maxn + 1];
for (int n = 0; n <= maxn; ++n) {
C[n][0] = C[n][n] = 1;
for (int k = 1; k ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
set<char> pool[110];
vector<string> vs;
for (int i = 0; i < n; i++) {
string temp;
cin >> temp;
for (int j = 0; j < temp.size(); j++) {
pool[i].insert(temp[j]);
}
vs.push_back(temp);
}
int ans = INT_MIN;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const long long INF = 1e9 + 19;
const int LOG = 52;
const int BASE = 2;
struct pt {
int x, y;
pt() {}
pt(int xx, int yy) : x(xx), y(yy) {}
void read() { scanf("%d%d", &x, &y); }
pt operator+(const pt& A) const { return pt(x + A.x, y + A.y);... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
for (int i = 0; i < 9; i++) {
cout << i << "\?\?<>" << i + 1 << endl;
;
}
cout << "9\?\?>>\?\?0" << endl << "\?\?<>1" << endl;
for (int i = 0; i <= 9; i++) {
cout << "?" << i << ">>" << i << "?" << endl;
}
cout << "?>>??" << endl << ">>?... | 17 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
long long res;
pair<long long, long long> a[40];
int main() {
cin >> n >> m;
for (int i = 0; i < m; i++) cin >> a[i].second >> a[i].first;
sort(a, a + m);
for (int i = m - 1; i >= 0 && n > 0; i--)
res += a[i].first * min(a[i].second, (long long)n), n -... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 205;
long long n, k, x, ans;
long long a[N], dp[N][N];
signed main() {
scanf("%lld %lld %lld", &n, &k, &x);
for (long long i = 1; i <= n; i++) scanf("%lld", &a[i]);
if (n / k > x) {
cout << -1;
return 0;
}
memset(dp, -0x3f, sizeof(dp));
dp[... | 11 |
#include <bits/stdc++.h>
using namespace std;
char ch[1005][1005];
char dir[4] = {'D', 'L', 'R', 'U'};
int dx[4] = {1, 0, 0, -1};
int dy[4] = {0, -1, 1, 0};
int d[1005][1005];
int tx, ty;
queue<pair<int, int>> q;
void bfs(int x, int y) {
memset(d, -1, sizeof(d));
d[x][y] = 0;
q.push({x, y});
while (!q.empty()) ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios_base::sync_with_stdio();
cin.tie(NULL);
cout.tie(NULL);
string str;
cin >> str;
long long n, a = 4, b = 5, c = 6, d = 3, e = 2, f = 1, i;
char s;
long long len = str.size();
s = str[len - 1];
n = 0;
for (i = 0; i < len - 1; i++) {... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n, a, b, k1, k2, x, y;
cin >> t;
vector<vector<int>> Adj;
while (t--) {
Adj.clear();
cin >> n;
Adj = vector<vector<int>>(n + 1, vector<int>());
for (int i = 0; i < n - 1; i++) {
cin >> a >> b;
Adj[a].push_back(b);
... | 11 |
#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
cout.writ... | 8 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T read1() {
T t = 0;
char k;
bool v = 0;
do (k = getchar()) == '-' && (v = 1);
while ('0' > k || k > '9');
while ('0' <= k && k <= '9')
t = (t << 3) + (t << 1) + (k ^ '0'), k = getchar();
return v ? -t : t;
}
int s, m, p, q, f[100005]... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000;
int MX;
struct tree {
long long cnt[MAXN + 10][MAXN + 10];
tree() { memset(cnt, 0, sizeof cnt); }
void add(int x, int y, long long v) {
while (x <= MX) {
int yt = y;
while (yt <= MX) {
cnt[x][yt] ^= v;
yt += (yt &... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e7;
const long long INF = 1e9 + 10;
const int MOD = 1e18 + 7;
struct segtree {
struct node {
long long cnt[10];
int add[10];
};
vector<node> tree;
int size = 1;
node ZERO() {
node ans;
for (int i = 0; i < 10; i++) ans.cnt[i] = 0;
... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200000 + 10;
int a[MAXN];
int main() {
ios::sync_with_stdio(false);
set<int> se;
memset(a, 0x00, sizeof(a));
a[0] = 1;
int n;
cin >> n;
int ans = 1;
for (int i = 1; i <= n; ++i) {
int x;
cin >> x;
if (a[x])
--a[x];
else... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, a, b, k, i;
cin >> n;
long long int *mas = new long long int[n];
for (i = 0; i < n; i++) {
cin >> a >> b >> k;
mas[i] = a * (k - k / 2) - b * (k / 2);
}
for (i = 0; i < n; i++) cout << mas[i] << "\n";
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long int findOnFromOneToN(int n, int j) {
n++;
long long int v = 1 << j;
long long int d = v * 2;
long long int seg = n / d;
long long int res = seg * v;
long long int ex = n - seg * d;
ex -= v;
if (ex > 0) res += ex;
return res;
}
void solve() {
in... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long read() {
char ch = getchar();
long long num = 0;
while (ch < '0' || '9' < ch) ch = getchar();
while ('0' <= ch && ch <= '9') {
num = num * 10 + ch - '0';
ch = getchar();
}
return num;
}
long long N, S;
const int MAXN = 2e5 + 2;
struct Factory {... | 20 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n = 0;
int m = 0;
int mi = 1000000001;
int ans = -1000000001;
scanf("%d %d", &n, &m);
for (int i = 0; i < n; ++i) {
mi = 1000000001;
for (int j = 0; j < m; ++j) {
int u = 0;
scanf("%d", &u);
mi = min(mi, u);
}
a... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long int dp[100];
map<long long int, long long int> mp;
int main() {
long long int m, r;
cin >> r >> m;
long long int val = 1LL;
dp[0] = 0;
dp[1] = 1;
int cnt = 2;
while (val <= m) {
val *= r;
dp[cnt++] = val;
}
bool ck = 0;
while (cnt > 0) ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int scanst(char *a) {
int i = 0;
char c = 0;
while (c < 33) c = getchar();
while (c > 33) {
a[i++] = c;
c = getchar();
}
a[i] = 0;
return i;
}
template <typename T>
bool scan(T &n) {
n = 0;
bool got = false;
bool negative = false;
char c = getc... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int maxn = 300009;
const int maxm = 300009;
const double pi = acos(-1.0);
const double eps = 1e-6;
long long myrand(long long mod) {
return ((long long)rand() << 32 ^ (long long)rand() << 16 ^ rand()) % mod;
}
template <class T>
inline bool ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int p = 997;
const int base = 1e9 + 7;
const int MAXN = 1000;
const int INF = 1e9;
const int MOD = 1e9;
const double PII = 3.14159265358979323846264338327950288419716939937510;
const double Epsilon = 1.19209e-01;
struct Point {
long double x, y;
Point() : x(0), y(... | 11 |
#include <bits/stdc++.h>
using namespace std;
void start() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
void debug(vector<long long> vec) {
long long n = vec.size();
for (long long i = 0; i < (long long)n; i++) cout << vec[i] << " ";
cout << endl;
return;
}
long long power(long long a, long ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string y, z, p;
string x =
"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int index;
string INITIAL_string, msg;
char direction;
INITIAL_string = "qwertyuiopasdfghjkl;zxcvbnm,./";
cin >> direction;
cin.ignore();
cin >> msg;
if (direction == 'R') {
for (long long int i = 0; i < msg.length(); i++) {
index = IN... | 1 |
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
using namespace std;
typedef long long ll;
//#define int ll
int n, m;
vector<int> g[1000];
int l[1000][1000];
void bfs(int v)
{
queue<int> q;
for (int i=1; i<=n; i++)
l[v][i]=-1;
q.push(v);
l[v][v]=0;
while... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int Mod = 1e9 + 7, N = 2e6 + 6;
int fact[N], ifact[N];
int binpow(int a, int n) {
if (n == 0) return 1;
int temp = binpow(a, n / 2);
temp = (temp * 1LL * temp) % Mod;
if (n & 1) return (temp * 1LL * a) % Mod;
return temp;
}
int inverseMod(int x) { return bin... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
string s;
cin >> s;
long long sum = 0, cnt = 0;
for (int i = 0; i < n; i++) {
if (s[i] == '.') {
cnt++;
} else {
cnt--;
if (cnt > 0) sum += cnt;
cnt = 0;
}
}
cnt--;
if (cnt > 0) sum ... | 8 |
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("-ffloat-store")
using namespace std;
clock_t time_p = clock();
void aryanc403() {
time_... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
int nn = n;
int cnt = 0;
while (nn >= 10) {
nn /= 10;
cnt++;
}
nn++;
while (cnt--) nn = nn * 10;
cout << nn - n << endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a1, a2, a3;
scanf("%lld %lld %lld", &a1, &a2, &a3);
long long res;
if (a3 == 0) {
printf("%lld\n", a1);
return 0;
}
if (a3 == 1) {
printf("%lld\n", a2);
return 0;
}
for (int i = 3; i <= a3 + 1; i++) {
res = a1 + a2;... | 8 |
#include <bits/stdc++.h>
using namespace std;
struct result {
int a;
int b;
};
bool mat[1004][1004];
result arr[2000000];
int pos = 0;
int main() {
int n, k;
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++) {
int total = 0;
mat[i][i] = true;
for (int j = 1; j <= n; j++) {
if (!mat[i][j]) ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int gra[26][26];
void intialise() {
for (int i = 0; i <= 25; i++) {
for (int j = 0; j <= 25; ++j) {
if (i == 0 || j == 0 || i == j)
gra[i][j] = 0;
else if (i <= 5 && j <= 5)
gra[i][j] = 1;
else
gra[i][j] = 0;
}
}
}
void ... | 7 |
#include <bits/stdc++.h>
using namespace std;
static const int INF = 0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
template <typename T, typename U>
static void amin(T &x, U y) {
if (y < x) x = y;
}
template <typename T, typename U>
static void amax(T &x, U y) {
if (x < y) x = y;
}
int main() {
... | 16 |
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
int t,n,c,f;
cin>>t;
while(t--)
{
cin>>n;
c=0,f=-1;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
for(int i=0;i<n;i++)
{
if(a[i]!=0)... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
cin >> str;
long long int i, j, k, ans, len = str.length();
for (i = 0; i < len; i++) {
if (str[i] == '0' || str[i] == '8') {
cout << "YES\n" << str[i];
return 0;
}
}
for (i = 0; i < len - 1; i++) {
for (j = i + 1... | 7 |
#include <bits/stdc++.h>
using namespace std;
int jj[200001];
int lf[200001];
void bfs() {
queue<int> q;
q.push(1);
lf[1] = 0;
int now;
while (!q.empty()) {
now = q.front();
q.pop();
if (lf[now + 1] > lf[now] + 1) {
lf[now + 1] = lf[now] + 1;
q.push(now + 1);
}
if (lf[now - 1] ... | 8 |
#include <bits/stdc++.h>
const long long inf = 1e9;
const long long cont = 1e18;
using namespace std;
void solve() {
long long n, k;
cin >> n >> k;
string s;
cin >> s;
bool on[k], off[k];
memset(on, 0, sizeof on);
memset(off, 0, sizeof off);
bool ok = true;
for (long long i = 0; i < n; i++) {
if (... | 7 |
#include <bits/stdc++.h>
using namespace std;
int N, x;
int A[100005], B[100005];
int P[100005], C[100005];
vector<pair<int, int> > res;
int main() {
int i, j;
cin >> N;
for (i = 1; i <= N; i++) {
scanf("%d", &x);
A[x] = i;
B[i] = x;
}
for (i = 4; i <= N; i += 2) P[i] = 1;
for (i = 3; i <= N; i ... | 10 |
#include <bits/stdc++.h>
using namespace std;
vector<int> sum(long long int n) {
long long int mx = INT_MIN, mn = INT_MAX;
while (n > 0) {
mx = max(mx, n % 10);
mn = min(mn, n % 10);
n /= 10;
}
std::vector<int> v;
v.push_back(mx);
v.push_back(mn);
return v;
}
int main() {
long long int t, n,... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long n, m;
int x[1000000];
long long dp[1000000];
long long dp2[1000000];
long long cur;
long long c;
int main() {
cin >> n >> m;
for (int i = 0; i < n; ++i) scanf("%d", x + i);
cur = 0;
c = 0;
for (int i = 0; i < n; ++i) {
dp[i] = 2 * ((long long)x[i] * ... | 12 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
int tree[4000016], n, m, a[1000006], b[1000006], QQQ;
void update(int v, int tl, int tr, int pos, int val) {
if (tl == tr) {
tree[v] = val;
return;
}
int tm = (tl + tr) / 2;
if (pos <= tm)
update(2 * v, tl, tm, ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long N = 200005;
int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
long long powmod(long long a, long long b) {
long long res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1... | 9 |
#include <bits/stdc++.h>
using namespace std;
int a[4], b[4], A[4], B[4], kol, n, mn, j;
vector<pair<int, int> > ve;
int main() {
cin >> n;
cin >> a[0] >> a[1] >> a[2];
cin >> b[0] >> b[1] >> b[2];
ve.push_back({0, 0});
ve.push_back({0, 1});
ve.push_back({1, 1});
ve.push_back({1, 2});
ve.push_back({2, 2... | 10 |
#include <bits/stdc++.h>
template <class... Args>
inline __attribute__((always_inline)) void read(Args&... args) {
(std::cin >> ... >> args);
}
template <class... Args>
inline __attribute__((always_inline)) void write(Args&&... args) {
(std::cout << ... << std::forward<Args>(args));
}
template <class... Args>
inlin... | 19 |
#include <bits/stdc++.h>
using namespace std;
const long double PI = 2 * acos(0.0);
void print(vector<bool> &a) {
for (bool i : a) {
cout << i << " ";
}
cout << "\n";
}
void print(vector<int> &a) {
for (int i : a) {
cout << i << " ";
}
cout << "\n";
}
void print(vector<char> &a) {
for (char i : a)... | 8 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.