solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int arr[8];
int main() {
int r = 5, b = 5, y = 5, g = 5;
string str;
cin >> str;
for (int i = 0; i < str.length(); i++) {
if (str[i] == 'R') r = i % 4;
if (str[i] == 'B') b = i % 4;
if (str[i] == 'Y') y = i % 4;
if (str[i] == 'G') g = i % 4;
}
if... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int NIL = -1;
const int MAX_N = 1e6 + 10;
int a[MAX_N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
pair<int, int> p[n];
for (int i = 0; i < n; i++) cin >> p[i].first >> p[i].second;
sort(p, p + n);
bool c = fa... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long int n, h, i, k = 0, j, s = 0;
cin >> n >> h;
long long int a[n + 1];
for (i = 1; i < n + 1; i++) cin >> a[i];
vector<long long int> v;
v.push_back(a[1]);
k = 1;
if (n > 1) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
signed x, y, z;
cin >> x >> y >> z;
signed a1 = x + z;
signed b1 = y;
signed a2 = x;
signed b2 = y + z;
if (a1 == b1) {
if (a2 == b2) {
cout << "0" << endl;
return 0;
}
cout << "?" << endl;
return 0;
}
if (a1 > b... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int i, j, k, l, m, n, t, ans = 0, p = 10, q = 0, s;
char a[8];
string s1;
cin >> s1;
n = s1.length();
for (i = 0; i < n; i++) {
a[n - i - 1] = s1[i];
}
if (a[n - 1] == 'X') p = 9;
if (n =... | 10 |
#include <bits/stdc++.h>
using namespace std;
int ans, n, m, S, T, cnt = 1, money, C[99][99], head[600000], cur[600000],
dis[600000], dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
struct edge {
int to, next, val, cost;
} e[600000];
bool vis[600000];
void add_edge(int u, int v, int w, int c) {
e... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 + 5;
const int maxm = 100 + 5;
const int maxnode = maxn * maxm;
const int maxcnt = 400 + 5;
int n, m, MOD;
int id[maxnode];
int C[maxcnt][maxcnt];
char a[maxn][maxm];
inline int add(int x) { return x >= MOD ? x - MOD : x; }
inline int sub(int x) { retur... | 24 |
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 105;
int n, m, a[MaxN], ans;
bool cmp(int p1, int p2) { return p1 > p2; }
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
sort(a + 1, a + 1 + n, cmp);
for (int i = 1; i <= n; ++i) {
m -= a[i];
ans++;
... | 0 |
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any o... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string check = "hello";
int t, i, j = 0, k, l, m, n, count_even = 0, count_odd = 0,
las_index_even = 0, las_index_odd = 0;
cin >> n;
int a[n];
for (i = 0; i < n; i++) cin >> a[i];
for ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
;
int n;
cin >> n;
long int arr[n];
unordered_map<int, int> umap;
for (int i = 0; i < n; ++i) cin >> arr[i], umap[arr[i]]++;
int s = 0;
for (auto x : umap) {
s = max(x.second, s);
}
cout << s;
r... | 4 |
#include <bits/stdc++.h>
using namespace std;
int cnt[200010];
int dis[200010];
int n, x, y;
int topp = 100000;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> x;
cnt[x]++;
y = x;
for (int step = 1; y <= topp; step++) {
y *= 2;
cnt... | 11 |
#include <bits/stdc++.h>
using namespace std;
unsigned long long inv(long long n) {
unsigned long long res = 1;
long long m = 1000000007 - 2;
n = n % m;
while (m > 0) {
if (m & 1) res = (res * n) % 1000000007;
m = m >> 1;
n = (n * n) % 1000000007;
}
return res;
}
int solve() {
int n, m, k;
c... | 9 |
#include <bits/stdc++.h>
using namespace std;
int t, k;
long long ans;
long long v;
int p[70];
long long a, b, c;
long long pw[70][70];
void solve2(long long lsta, int x, long long cur, long long lim) {
if (2LL * lsta * cur >= ans) return;
if (x > k) {
long long tc = v / lsta / cur;
if (2LL * (lsta * cur + ... | 21 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxint = 2147483646;
const int minint = -2147483646;
const long long maxlll = 9223372036854775805;
const long long minlll = -9223372036854775805;
const ll mody = 998244353;
void printb(bool a) {
if (a) {
cout << "YES" << endl;
} else ... | 16 |
#include <bits/stdc++.h>
using namespace std;
int dp[102][102];
int memo[102][102][102];
int n, T, a[102], cont[102], in[102], jump[102];
int solve(int rep, int pos, int best) {
if (rep == T || rep > n) return 0;
int &ret = memo[rep][pos][best];
if (ret == -1) {
ret = best * (T - rep);
if (jump[pos] != -1... | 11 |
#include <bits/stdc++.h>
using namespace std;
int size01(int x) { return __builtin_popcount(x); }
const long long INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF = 0x7ffffff;
const int maxn = 1e5 + 100;
const int mod = 1000000007;
const double pi = acos(-1);
const double eps = 1e-10;
complex<double> rotate(complex<double> ... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long int nCrModp(long long int n, long long int r, long long int p) {
long long int C[r + 1];
memset(C, 0, sizeof(C));
C[0] = 1;
for (long long int i = 1; i <= n; i++) {
for (long long int j = min(i, r); j > 0; j--) C[j] = (C[j] + C[j - 1]) % p;
}
retur... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long int maxs = 1e6 + 5;
const long long int mod = 1e9 + 7;
long long int oo = 1e15;
int main() {
long long int t = 1;
while (t--) {
long long int n;
cin >> n;
long long int a[n];
for (long long int i = 0; i < n; i++) cin >> a[i];
long lon... | 7 |
#include <bits/stdc++.h>
using namespace std;
string DBG_DLM(int& i) { return (i++ == 0 ? "" : ", "); }
template <class T>
ostream& operator<<(ostream& os, vector<T> v);
template <class T>
ostream& operator<<(ostream& os, set<T> v);
template <class T>
ostream& operator<<(ostream& os, queue<T> q);
template <class T>
ost... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 1;
const long long INF = 1e18;
const long long mod = 1e9 + 7;
long long n;
long long a[]{2, 6, 8, 4};
int main() {
ios_base::sync_with_stdio(0);
cin >> n;
cout << (n ? a[((n % 4) + 1) % 4] : 1);
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int n;
long long p, q, a, b;
bool isok(long long x) { return x * b - q >= x * a - p && x * a - p >= 0; }
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%lld%lld%lld%lld", &p, &q, &a, &b);
long long l = 0, r = 0x7fffffff;
while (l < r) {
... | 9 |
#include <bits/stdc++.h>
const int MAXN = 1100;
int n, m;
bool x[MAXN], y[MAXN];
int main() {
scanf("%d%d", &n, &m);
int i;
int recordx, recordy;
for (i = 0; i < m; i++) {
scanf("%d%d", &recordx, &recordy);
x[recordx] = true;
y[recordy] = true;
}
int ans = 0;
for (i = 2; i < n; i++) {
if (... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 31;
int node[N][3], idx[N][3], cnt = 2;
bool in[101][101];
int main() {
node[0][0] = node[0][1] = ++cnt;
node[0][2] = ++cnt;
for (int i = 1; i < N; i++) {
node[i][0] = ++cnt;
node[i][1] = ++cnt;
node[i][2] = ++cnt;
in[node[i][0]][node[i -... | 11 |
#include <bits/stdc++.h>
using namespace std;
using ll = unsigned long long;
const int MAX_N = 1e5 + 9;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int n, a, b, lst = 1, sum = 1;
cin >> n >> a >> b;
if (!b && a > 0 && a + 2 > n) cout << -1, exit(0);
if (!b) cout << "1 ", n--;
if (n) cout << lst <... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
void yes() {
cout << "Yes"
<< "\n";
}
void no() {
cout << "No"
<< "\n";
}
struct Sync_stdio {
Sync_stdio() {
cin.tie(NULL);
ios_base::sync_with_stdio(false);
}
} _sync_stdio;
struct FAIL {
FAIL() {
cout << "CHA... | 12 |
#include <bits/stdc++.h>
using namespace std;
bool esNumero(string &a) {
if (a[0] == '0') return false;
for (int i = 0; i < a.size(); i++) {
if (a[i] != '0' && a[i] != '1' && a[i] != '2' && a[i] != '3' &&
a[i] != '4' && a[i] != '5' && a[i] != '6' && a[i] != '7' &&
a[i] != '8' && a[i] != '9')
... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
inline int two(int n) { return 1 << n; }
long long extgcd(long long a, long long b, long long& x, long long& y) {
if (b == 0) {
x = 1;
y = 0;
return a;
} else {
int g = extgcd(b, a % b, y, x);
y -= a / b * x;
return g;
... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long n, f[2000005];
struct node {
long long x, y;
} a[2000005];
long long read() {
long long res = 0, F = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') F = -1;
ch = getchar();
}
while (isdigit(ch)) {
res = res * 10 + ch - '0';
... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 10;
int w[N], pre[N], sz[N], tot, nw;
map<int, int> mp;
int id(int x) {
if (mp.count(x)) return mp[x];
sz[++tot] = 1;
pre[tot] = tot;
return mp[x] = tot;
}
int f(int x) {
if (pre[x] == x) return x;
nw ^= w[x];
return f(pre[x]);
}
signed mai... | 16 |
#include <bits/stdc++.h>
using namespace std;
long long n, k, c = 1;
int main() {
scanf("%lld%lld", &n, &k);
while (k % 2 == 0) {
c++;
k /= 2;
}
cout << c;
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, d, k = 10;
string s[1010];
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> s[i];
}
if (n == 1) {
puts("6");
return 0;
}
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
d = 0;
for (int k = 0; k < ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
const int inf = 1e9 + 7;
inline void read(int &x) {
x = 0;
char ch = getchar();
while (ch < '0') ch = getchar();
while (ch >= '0') {
x = x * 10 + ch - 48;
ch = getchar();
}
}
struct edge {
int x, y;
} g[N];
int nxt[N], to[N], head[... | 15 |
#include <bits/stdc++.h>
using namespace std;
bool isVowel(char x) {
if (x == 'u' || x == 'e' || x == 'o' || x == 'a' || x == 'i') {
return true;
} else
return false;
}
bool gcd(long long int a, long long int b) {
if (a % b == 0)
return b;
else
return gcd(b % a, a);
}
bool isPrime(long long int ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, num = 0;
cin >> a >> b >> c;
int s[a], i;
for (i = 0; i < a; i++) {
s[i] = i + 1;
if (b < s[i] && (a - s[i]) <= c) num++;
}
cout << num;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
char arr[n + 1];
memset(arr, '0', sizeof(arr));
int n1 = 1;
int n2 = 1;
if (n <= 2) {
arr[1] = '1';
arr[2] = '1';
} else {
int num = 0;
arr[1] = '1';
for (int i = 2; i <= n; i++) {
num = n1 + ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int arr[150000];
int main() {
int n, k, sum = 0, j = 1, i;
cin >> n >> k;
for (i = 0; i < n; i++) {
cin >> arr[i];
}
sum = accumulate(arr, arr + k, sum);
int ansum = sum;
for (i = k; i < n; i++) {
if (sum - arr[i - k] + arr[i] < ansum) {
j = i - ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const int mod = 1e9 + 7;
int n, m, a, b;
inline int read() {
int x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = (x << 1) + (x << 3) + c... | 17 |
#include <bits/stdc++.h>
using namespace std;
int N, K;
int C[303030];
vector<int> col[303030];
vector<int> E[303030];
int P[21][300005], D[300005];
void dfs(int cur) {
for (__typeof(E[cur].begin()) it = E[cur].begin(); it != E[cur].end(); it++)
if (*it != P[0][cur]) D[*it] = D[cur] + 1, P[0][*it] = cur, dfs(*it)... | 19 |
#include <bits/stdc++.h>
using namespace std;
void solve(int test_number);
int main() {
cout.setf(ios::fixed);
cout.precision(9);
cerr.setf(ios::fixed);
cerr.precision(3);
ios_base::sync_with_stdio(false);
cout.tie(0);
int n = 1;
for (int i = 0; i < n; i++) {
solve(i + 1);
}
return 0;
}
const in... | 10 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T inline myAbs(T n) {
return (n < 0) ? -n : n;
}
template <class T>
T inline myPow(T base, T power) {
T toRet = 1;
while (power--) {
toRet *= base;
};
return toRet;
}
int main() {
long long n, b1, m, b2, x, y;
while (cin >> n >> b1) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, k, q, t, x, y, s;
int last[100005], mx[100005], reg[100005], arr[100005];
long long bas[405][405], son[405][405], ok[405];
vector<pair<double, int> > V[405];
long long calc(int x, int b, int s, int t) {
int i;
long long sum = 0;
if (ok[x] == -1) {
if (s - b... | 23 |
#include <bits/stdc++.h>
using namespace std;
int diri[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dirj[] = {0, 1, 0, -1, 1, 1, -1, -1};
int compare(double d1, double d2) {
if (fabs(d1 - d2) < 1e-9) return 0;
if (d1 < d2) return -1;
return 1;
}
int main() {
string s, t;
getline(cin, s);
int n = s.length();
strin... | 9 |
#include <bits/stdc++.h>
using namespace std;
char s[1111][10];
int n;
int dist(int x, int y) {
int ans = 0;
for (int i = 0; i < 6; ++i) ans += (s[x][i] != s[y][i]);
return ans;
}
int main() {
scanf("%d\n", &n);
for (int i = 0; i < n; ++i) gets(s[i]);
int _max = 13;
for (int i = 0; i < n; ++i)
for (in... | 6 |
#include <bits/stdc++.h>
using namespace std;
int N, K;
int p[105];
int q[105];
int m[105];
int arr[105][105];
int brr[105][105];
void preprocess() {
for (int i = 1; i <= N; i++) arr[0][i] = i;
for (int r = 1; r <= K; r++) {
for (int i = 1; i <= N; i++) {
arr[r][i] = p[arr[r - 1][i]];
}
}
for (int... | 10 |
#include <bits/stdc++.h>
const long long mod = 1000000000 + 7;
const long long INF = 9000000000000000000;
using namespace std;
void yes() { cout << "YES" << endl; }
void no() { cout << "NO" << endl; }
long long gcd(long long a, long long b) { return (a == 0 ? b : gcd(b % a, a)); }
long long lcm(long long a, long long b... | 8 |
#include <bits/stdc++.h>
struct Comp {
int operator()(const std::pair<char, long long>& a,
const std::pair<char, long long>& b) {
return b.second < a.second;
}
};
int main() {
std::unordered_map<char, long long> m;
std::vector<char> first;
int n;
std::cin >> n;
for (int i = 0; i < n; ... | 9 |
#include <bits/stdc++.h>
using namespace std;
void qq(int n) {
int i, j, ans = 0, mod = 5, base[10];
base[1] = base[2] = base[3] = base[4] = 1;
for (i = 1; i <= n; i++)
for (j = 2; j <= 4; j++) {
base[j] *= j;
base[j] %= mod;
}
for (i = 1; i <= 4; i++) ans += base[i];
ans %= mod;
cout <<... | 4 |
#include <bits/stdc++.h>
using namespace std;
const double g = 10.0, eps = 1e-12;
const int N = 100 + 10, maxn = 10000 + 10, inf = 0x3f3f3f3f;
int c[N], p[N][N];
long long dp[N][N][N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m, k;
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) cin >> c[... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long rdtsc() {
long long tmp;
asm("rdtsc" : "=A"(tmp));
return tmp;
}
inline int myrand() { return abs((rand() << 15) ^ rand()); }
inline int rnd(int x) { return myrand() % x; }
const int INF = (int)1.01e9;
const long double EPS = 1e-9;
void precalc() {}
const in... | 21 |
#include <bits/stdc++.h>
using namespace std;
const int Nmax = 1000;
int N, b[Nmax], A[Nmax][Nmax];
int main() {
cin >> N;
for (int i = 1; i <= N; ++i) cin >> b[i];
int f = b[1];
while (f) {
A[1][++A[1][0]] = 9;
f -= 9;
if (f < 0) A[1][A[1][0]] += f, f = 0;
}
for (int k = A[1][0]; k >= 1; --k) c... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
int m;
cin >> m;
int a = 2;
for (int j = 0; j < m; ++j, ++a) {
cout << 2 * a + 1 << " ";
}
cout << "\n";
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int x, y, z;
cin >> x >> y >> z;
int a = sqrt((x * z) / y);
int b = sqrt((x * y) / z);
int c = sqrt((y * z) / x);
cout << 4 * (a + b + c) << "\n";
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 111;
const int M = 1000000007;
int n, k, a[maxn], c[maxn], pos[maxn], pt[maxn];
char s[maxn];
vector<vector<int> > ans;
int check() {
for (int i = 1; i <= n; i++) pos[a[i]] = i;
for (int i = 1; i < n; i++)
if (pos[i] > pos[i + 1]) return i;
return... | 12 |
#include <bits/stdc++.h>
using namespace std;
void read_file(bool outToFile = true) {}
int n;
const int MAXN = 100000 + 99;
int A[MAXN];
int pref[3][MAXN];
int query(int l, int r, int who) {
int ret = pref[who][r];
if (l > 0) ret -= pref[who][l - 1];
return ret;
}
int calc(int who, int cur, int t) {
int lo = cu... | 11 |
#include <bits/stdc++.h>
using namespace std;
int T;
char s[100100];
int main() {
scanf("%d", &T);
while (T--) {
scanf("%s", s + 1);
int len = strlen(s + 1);
int ss = 0;
int f = 0, g = 0;
for (int i = 1; i <= len; i++) {
if (s[i] == '0' and g) {
f = 1;
}
if (s[i] == '0'... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
int arr[N][N], row[N], col[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
int n, m, k;
cin >> n >> m >> k;
for (int i = 1; i <= n; ++i) {
row[i] = i;
for (int j = 1; j <= m; ++j) {
col[j] = j;
cin >> arr[i]... | 5 |
#include <bits/stdc++.h>
using namespace std;
const double Eps = 0.0000001;
int n;
double x[500], v[500], m[500], d[50][50];
double t, tmin;
bool verif(double tt, int p1, int p2) {
double px1 = x[p1] + v[p1] * tt;
double px2 = x[p2] + v[p2] * tt;
double dif1 = x[p1] - x[p2];
double dif2 = px1 - px2;
if ((dif1... | 12 |
#include <bits/stdc++.h>
using namespace std;
void combine(vector<int> &dst, vector<int> &src) {
for (int x : src) {
dst.push_back(x);
}
return;
}
int main() {
string s;
cin >> s;
vector<int> l, r;
vector<vector<int> > seq;
int n = s.size();
for (int i = 0; i < n; ++i) {
if (s[i] == 'L') {
... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 20, S = 1e3;
const long long inf = 1e17;
long long p[N], a[N], b[N], ab[S][S];
char arch[N], cbl[S][S];
vector<long long> v, g[N];
bool mark[N], bb = false;
long long n, d, c, c1, m, k, q, l, r, mn = inf, mx = 0, ans = 0, ans1 = 0,
... | 3 |
#include <bits/stdc++.h>
using namespace std;
char a[] = "23456789TJQKA";
char b[] = "SDHC";
int Get() {
char s[3];
scanf("%s", s);
int i = 0;
while (a[i] != s[0]) ++i;
int j = 0;
while (b[j] != s[1]) ++j;
return i * 4 + j;
}
int Good(int first, int second) {
return (first / 4 == second / 4) || (first %... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int m, n;
cin >> m >> n;
int B[m][n], A[m][n];
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
cin >> B[i][j];
A[i][j] = 1;
}
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (!B[i][j]) {
... | 5 |
#include <bits/stdc++.h>
int a[75], b[75];
void convert(int a[], long long int n, int i) {
if (n == 0) return;
a[i] = n % 2;
convert(a, n / 2, i + 1);
}
int comp(int a[], int b[], int i) {
if (i < 0) return -1;
if (a[i] != b[i]) return i;
return comp(a, b, i - 1);
}
long long int power(int n) {
if (n == 0... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long int modular_exp(long long int A, long long int B, long long int C) {
if (B == 0) return 1;
if (B == 1) return A;
long long int res = A;
if (res > C) res = res % C;
int counter = 2;
while (counter < B) {
res = res * res;
if (res > C) res = res %... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, l, a[101], res = 0, endres = 0;
int main() {
cin >> n >> l;
for (int i = 0; i < n; ++i) cin >> a[i];
for (int i = l; i < 101; ++i) {
res = 0;
for (int j = 0; j < n; ++j) res += a[j] / i;
endres = max(endres, res * i);
}
cout << endres;
return ... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
class Segtree {
private:
long long n;
vector<T> tree;
T identity;
T merge(T a, T b) { return a + b; }
T __query(long long node, long long seg_l, long long seg_r, long long q_l,
long long q_r) {
if (seg_l >= q_l && seg_r <= q_... | 15 |
#include <bits/stdc++.h>
using namespace std;
struct st {
int x, a;
} b[110];
bool comp(const st &p, const st &q) { return p.x < q.x; }
int main() {
int n;
while (cin >> n) {
int x[n + 10], a[n + 10];
b[0].x = 0;
b[0].a = 0;
for (int i = 1; i < n + 1; i++) {
cin >> b[i].x >> b[i].a;
}
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
set<int> M[200005];
int siz[200005], a[200005], b[200005], dele[200005], cnt, ans[200005];
void check(int u) {
if (siz[u] >= k || dele[u]) return;
cnt--;
dele[u] = 1;
queue<int> Q;
Q.push(u);
while (!Q.empty()) {
int ty = Q.front();
Q.pop();... | 14 |
#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<int, int>& a, pair<int, int>& b) { return a.first > b.first; }
int main() {
int n;
cin >> n;
pair<int, int> ar[n + 7];
for (int i = 0; i < n; i++) {
cin >> ar[i].first;
ar[i].second = i + 1;
}
sort(ar, ar + n, cmp);
int sum = 0;
for (in... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200002;
int n, m, k;
int assigned_rank[MAXN];
vector<int> adj[MAXN];
int min_rank[MAXN];
int topo_order[MAXN];
int active_orders[MAXN];
set<int> people_by_rank[MAXN];
priority_queue<pair<int, int>> pq;
int countv;
int visited[MAXN];
bool topodfs(int v) {
... | 18 |
#include <bits/stdc++.h>
using namespace std;
bitset<5001> b;
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
if (a <= n) b[a] = true;
}
int x = b.count();
int ans = n - x;
cout << ans << endl;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<long long> counts(100001, 0);
vector<bool> visited(100001, 0);
long long n, x, a;
cin >> n >> x;
for (long long i = 0; i < n; i++) {
cin >> a;
counts[a]++;
}
long long res = 0;
for (long long i = 1; i <= 100000; i++) {
if (vis... | 7 |
#include <bits/stdc++.h>
using namespace std;
int iec[100];
int lg(long long no) {
int ret = 0;
while (no > 0) ret++, no /= 2;
return ret;
}
long long solve(long long no) {
long long ans = 0, high, low, gen;
int K = lg(no);
for (int base = 1; base < K; base++) {
for (int power = 2; power * base <= K; po... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 9e6 + 10;
const int inf = 0x3f3f3f3f;
long long a[N];
long long f[2][210][6000];
int get(long long x, int d) {
int res = 0;
while (x % d == 0) {
res++;
x /= d;
}
return res;
}
int main() {
ios::sync_with_stdio(false);
int n, K;
cin >> n >... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
int arr[n];
for (int i = 0; i < n; i++) cin >> arr[i];
int ans = 1;
sort(arr, arr + n);
int i = 0;
while (ans == arr[i] && i < n) {
i++;
ans++;
}
cout ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int rev(int x) {
int sol = 0;
while (x) {
sol = sol * 10 + x % 10;
x /= 10;
}
return sol;
}
const int N = (int)1e7;
int lp[N + 7];
bool is[N + 7];
vector<int> primes;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
for (int i = 2; i <= N; i++) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int i, j, k, t, n, m, f[300500], q, l, r;
char c;
vector<int> st[2005000];
int main() {
ios::sync_with_stdio(0);
scanf("%d", &t);
while (t--) {
scanf("%d%d", &n, &q);
for (i = 1; i <= n; i++) {
c = getchar();
if (c == '+' || c == '-') {
f[i... | 14 |
#include <bits/stdc++.h>
using namespace std;
void ga(int N, int *A) {
for (int i(0); i < N; i++) scanf("%d", A + i);
}
char s[50][64];
int N, M, dp[50][8];
int dyn(int u, int b) {
if (b == 7) return 0;
if (u == N) return (1 << 29);
int &v = dp[u][b];
if (~v) return v;
v = (1 << 29);
for (int i(0); i < M;... | 7 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
void solve(vector<int> &v, int x, bool had) {
sort(v.begin(), v.end());
int len = v.size();
if (v[(len - 1) >> 1] == x) {
cout << !had << "\n";
return;
}
int l = lower_bound(v.begin(), v.end(), x) - v.b... | 7 |
#include <bits/stdc++.h>
using namespace std;
void write_file(int n, int* arr, char* fname) {
FILE* f = fopen(fname, "w");
fprintf(f, "%d\n", n);
for (int i = 0; i < 2 * n; ++i) {
if (arr[i] == 0)
fprintf(f, "%c\n", '+');
else
fprintf(f, "- %d\n", arr[i]);
}
fclose(f);
}
int* gen(int num) ... | 9 |
#include <bits/stdc++.h>
using namespace std;
char c[2015][2015];
int a[2015][2015], n, m, sum;
queue<int> qx, qy;
inline void ope(int x, int y) {
a[x][y]--;
if (a[x][y] == 1) qx.push(x), qy.push(y);
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%s", c[i] + 1);
for (int j =... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
srand(time(NULL));
int n;
cin >> n;
vector<vector<int> > v(n, vector<int>(n));
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> v[i][j];
}
}
for (int i = 0; i < n; i++) {
for ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.141592653589793238462643383279502884L;
const long double E = 2.718281828459045235360287471352662498L;
const long double EPS = 1e-12L;
int v[1024][1024][5] = {};
int n, m, q, a, b, c, d, w, h;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0)... | 17 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
long long ans = 0;
int main(void) {
cin >> n >> m;
int kol = 0, x = 1;
for (int i = 0; i < m; i++) {
x *= 2;
if (x >= 1000000009) x -= 1000000009, kol++;
}
x--;
ans = x;
for (int i = 1; i < n; i++) {
x--;
ans = (long long)ans * (long ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
if (a % b == 0)
cout << "0\n";
else
cout << b - a % b << "\n";
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
map<long long, int> ma, Ma;
char str[3];
int n, i, a[100], b[100], c[100], Ans, A1, A2, ans[100];
void dfs(long long x, long long y, long long z, int d, int k) {
if (d > n / 2) {
long long tmp = (y - x) * 300007 + (z - x);
if ((ma.find(tmp) == ma.end()) || (x > ma... | 15 |
#include <iostream>
#include <math.h>
#include <vector>
#include <string>
#include <algorithm>
#define ll long long
#define li long int
#define ld long double
using namespace std;
int main() {
ll t;
cin >> t;
while (t--) {
int s[4];
for(int i=0;i<4;i++){
cin>>s[i];
}
int l=max(s[0],s[1]);
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long L, v1, v2, R, N, K, A, B;
cin >> N >> L >> v1 >> v2 >> K;
R = (N - 1) / K;
A = 2 * R * v2 + v1 + v2, B = 2 * R * v1 + v1 + v2;
double answer = static_cast<double>(A * 1.0) / B;
answer *= (L / (v2 * 1.0));
cout << setiosflags(ios::showpoi... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t;
cin >> t;
while (t--) {
long long int a, b;
cin >> a >> b;
if (a > b) {
if ((a - b) % 2 == 0) {
cout << 1 << endl;
} else {
cout << 2 << endl;
}
} else if (b > a) {
if ((b - a) % 2 =... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
;
int n;
cin >> n;
int a[n];
for (int i = 0; i < (n); i++) cin >> a[i];
sort(a, a + n);
int cnt = 1;
multiset<int> s;
multiset<int>::iterator it;
for (int i = 1; i < n; i++) {
if (a[i]... | 5 |
#include <bits/stdc++.h>
using namespace std;
bool flag = true;
int minl[100000 << 2];
vector<long long> a;
void build(int l, int r, int rt) {
if (l == r) {
minl[rt] = l;
return;
}
int m = (l + r) >> 1;
build(l, m, rt << 1);
build(m + 1, r, rt << 1 | 1);
if (a[minl[rt << 1]] < a[minl[rt << 1 | 1]])
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, solution;
int gcd(int a, int b, int& steps) {
int k;
steps = 0;
while (b) {
k = a % b;
steps += a / b;
a = b;
b = k;
}
return a;
}
int main() {
scanf("%d", &n);
solution = 1000000;
for (int i = 1; i <= n; i++) {
int temp;
if ((... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int t[100005] = {0}, i, j, k, q, n, m;
scanf("%d%d", &n, &m);
for (i = 1; i <= n; i++) {
scanf("%d%d", &j, &k);
j *= k;
t[i] = j + t[i - 1];
;
}
k = 1;
while (m--) {
scanf("%d", &q);
for (i = k; i <= n; i++) {
if (q... | 4 |
#include <bits/stdc++.h>
using namespace std;
int vv[100100], nxt[100100], flow[100100], cc[100100], h[10000], e;
int vis[10000], d[10000], pre[10000];
void add(int u, int v, int f, int c) {
vv[e] = v, flow[e] = f, cc[e] = c, nxt[e] = h[u], h[u] = e++;
vv[e] = u, flow[e] = 0, cc[e] = -c, nxt[e] = h[v], h[v] = e++;
... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
long long w, k, x;
cin >> w >> k >> x;
int birds[n];
for (int i = 0; i < n; i++) cin >> birds[i];
int total_birds = accumulate(birds, birds + n, 0);
long long cost[n];
for (int i = 0; i < n;... | 14 |
#include <bits/stdc++.h>
using namespace std;
double dist(pair<int, int> a, pair<int, int> b) {
return sqrt((a.first - b.first) * (long long)(a.first - b.first) +
(a.second - b.second) * (long long)(a.second - b.second));
}
pair<int, int> A, B, T;
int N;
pair<int, int> bottles[200000];
int main() {
sc... | 10 |
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int tests; cin >> tests;
for (int _test = 0; _test<tests; _test++)
{
int nb, d; cin >> nb >> d;
bool isValid = true;
int numbers[105];
for (int i = 0; i<nb; i++)
{
cin >> numbers[i];
if (numbers[i]... | 0 |
#include <bits/stdc++.h>
using namespace std;
string s;
int A[100100];
int main() {
cin >> s;
int a = 0;
for (int i = 0; i < (int)s.size(); ++i) {
int x;
if (s[i] >= 'A' && s[i] <= 'Z') {
x = s[i] - 'A';
if (x == 1) a++;
} else if (s[i] >= 'a' && s[i] <= 'z') {
x = s[i] - 'a';
... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool cmax(T& x, T y) {
return y > x ? x = y, true : false;
}
template <typename T>
inline bool cmin(T& x, T y) {
return y < x ? x = y, true : false;
}
template <typename T>
inline T dmax(T x, T y) {
return x > y ? x : y;
}
template <typena... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
const int Inf = 1e9 + 1;
const long long Mod = 1e9 + 7;
int n, a, b, k, q, l;
vector<int> ans;
string s;
int main() {
cin >> n >> a >> b >> k;
cin >> s;
for (int i = 0; i < n; ++i) {
if (s[i] == '1') {
q += (i - l) / b;
l = i + 1... | 9 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.