solution stringlengths 53 181k | difficulty int64 0 13 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
long long n = 0;
cin >> n;
vector<long long> v(n);
for (long long i = 0; i < n; i++) cin >> v[i];
cout << "1 1" << endl;
long long v0d = n - (v[0] % n);
cout << v0d << endl;
v[0] += v0d;
if (n... | 4 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-') f = -1;
for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
return x * f;
}
const int MAXN = 200010;
const int INF = 2147483600;
int N, M;
vector<int... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
const int MAXN = 5050;
const int MAXE = 1e6;
int n, m;
int v[N];
int good[N][2];
int sz[N];
int d[N][50];
int cnt[N][50];
int no[N][50];
int edge_cnt, src, snk, node_cnt, que_sz;
int head[MAXN], work[MAXN], to[MAXE], cap[MAXE], nxt[MAXE];
int que[MAXN], d... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int palindrome[17] = {0, 70, 140, 210, 280, 350, 601, 671, 741,
811, 881, 951, 1202, 1272, 1342, 1412, 1440};
int h, m, ans, temp;
scanf("%d:%d", &h, &m);
temp = 60 * h + m;
for (int i = 0; i <= 16; i++) {
ans = pali... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long lnf = 0x3f3f3f3f3f3f3f3f;
const double dnf = 1e18;
const int mod = 1000000007;
const double eps = 1e-8;
const double pi = acos(-1.0);
const int maxn = 2000100;
const int maxm = 100100;
const int up = 100000;
int n, k, m;
long long... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long t, n, m;
int bits[100];
map<long long, int> logTwo;
int main() {
for (int i = 0; i <= 60; i++) {
long long a = pow(2, i);
logTwo[a] = i;
}
cin >> t;
while (t--) {
memset(bits, 0, sizeof(bits));
cin >> n >> m;
for (int i = 0; i < m; i++)... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long ans[2000100][5], n, mod[5];
long long count(long long x, long long mod3) {
if (x == n) {
if (!mod3)
return 1;
else
return 0;
}
if (ans[x][mod3] == -1) {
long long val = 0;
long long tmp = 1e9 + 7;
for (int i = 0; i < 3; i++) {... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long int lowBit(long long int n) {
for (long long int i = 0; i < 30; i++) {
long long int p = 1 << i;
if (n & p) return 1 << i;
}
}
int32_t main() {
long long int n, k;
cin >> n >> k;
long long int kk = k;
long long int y = k;
long long int half =... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int S = 1005, D = 55, K = 10;
const long long mod = 1000000007ll;
int fail[S * D], ch[S * D][K], trans[S * D][K], tot = 0;
bool vis[S * D];
int newnode() {
int x = ++tot;
fail[x] = 0, vis[x] = false;
for (int i = 0; i < K; i++) ch[x][i] = trans[x][i] = 0;
retu... | 12 |
#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;
vector<int> c(n + 1);
int x, curr_ptr = 1;
for (int i = 1; i <= n; i++) {
cin >> x;
c[x] = i;
}
for (int i = 0; i < n; i++) {
cin >> x;
if (curr_ptr ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 110;
long long n, k, h, A, a[N], p[N], cnt, son[N][2], op[N], de[N];
long long win[N], t[N];
unordered_map<long long, long long> mp;
inline void add(long long &a, long long b) {
a = ((a + b >= 998244353) ? a + b - 998244353 : a + b);
}
inline void del(... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000;
const int MAXNUM = 100000;
int n;
int max_x[MAXNUM + 1];
int max_y;
int w[MAXN];
int res[MAXN][2];
int lookup(int t) {
int p = 0, q = max_y;
while (p < q) {
int y = (p + q) / 2;
if (y - max_x[y] < t)
p = y + 1;
else
q = y... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000000 + 10;
int a[N];
int main() {
int n, t, ans, best, i, l;
double minn, p;
ios::sync_with_stdio(false);
cin.tie(0);
cin >> t;
while (t--) {
cin >> n;
for (i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
ans = 1;
for (i = 1,... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string a;
cin >> n >> a;
int c1 = 0, c2 = 0, c3 = 0, c4 = 0, ans = -1;
for (int i = 0; i < n; i++) {
if (i % 2 == 0) {
if (a[i] == 'b')
c1++;
else if (a[i] == 'r')
c2++;
} else if (i % 2 == 1) {
if (a[i... | 3 |
#include <bits/stdc++.h>
using namespace std;
const double pi = 3.14159265359;
const long long int Maxi = 1e18;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
long long n, m, i, j, l, k = 0, p = 0, s = 0, t = 1, x, y, z, r, c;
long long a[100005] = {0};
map<string, string> mp;
c... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 12;
const int MAXR = 1;
const int MAXC = 1;
const int MAXBITS = 64;
const int INF = (int)1e9;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
priority_queue<int, vector<int>, greater<int>> q1;
priority_queue<int, vector<int>, less<int>> q2;
void l() { ;... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int mod2 = 1e9 + 7;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a[n];
for (long long i = 0; i < n; i++) cin >> a[i];
map<int, int> m;
for (long long i = 0; i < n; i++) ++m[a[i]];
vector<int> v;
for (auto it = ... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long A[2], B[2], C[2];
int check(long long p, long long q) {
long long a, b, c;
a = (-C[0] * p - C[1] * q);
b = (-C[1] * p + C[0] * q);
c = (C[0] * C[0] + C[1] * C[1]);
return (a % c == 0 && b % c == 0);
}
int check2() {
if (A[0] == B[0] && A[1] == B[1]) re... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, l, r;
long long S, sum, cnt, cur, ans;
struct point {
long long x, y;
} a[1000005 << 1], pre[1000005 << 1];
point operator-(const point a, const point b) {
return (point){a.x - b.x, a.y - b.y};
}
point operator+(const point a, const point b) {
return (point){a.... | 10 |
#include <bits/stdc++.h>
using namespace std;
set<char> save;
string frase;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
getline(cin, frase);
for (int i = 0; i < frase.size(); ++i)
if (isalpha(frase[i])) save.insert(frase[i]);
cout << save.size() << "\n";
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n, a[333][333], f[2][333][333], l[666], r[666];
int main() {
int z = 0;
cin >> n;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) scanf("%d", a[i] + j);
for (int j = 0; j < n; j++)
for (int k = 0; k < n; k++) f[0][j][k] = -1000111222;
f[0][0][0... | 6 |
#include <bits/stdc++.h>
using namespace std;
bool same_char();
bool can_swap();
string s1, s2;
int main() {
cin >> s1 >> s2;
bool possible = true;
if (s1 != s2) {
possible = same_char();
if (possible) {
possible = can_swap();
}
}
if (possible) {
cout << "YES\n";
} else {
cout << "... | 1 |
#include <bits/stdc++.h>
using namespace std;
struct ddt {
int pos;
vector<int> attempts;
int sum;
ddt(int pos_) {
pos = pos_;
sum = 0;
}
};
int main() {
int n, A, B;
cin >> n >> A >> B;
vector<int> a(n);
for (auto& i : a) {
cin >> i;
++i;
}
int ans = 1e9;
vector<int> res;
queu... | 9 |
#include <bits/stdc++.h>
using namespace std;
int ans = 1e9, sum1, sum2, mx1, mx2;
char ch[10];
pair<int, int> a[20];
int dp[1 << 16][260], sum[1 << 16][2], b[20];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%s%d%d", ch, &a[i].first, &a[i].second);
sum1 += a[i].first, sum2 +=... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;
inline int in() {
int x = 0, flag = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '0') flag = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
x = (x << 3) + (x << 1) + (ch ^ 48... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int oo = (int)1e9;
const double PI = 2 * acos(0.0);
const double eps = 1e-9;
int vals[5];
int solve(int n) {
for (int i = 0; i < (int)(5); i++) {
if (n + i < 5 && vals[n + i]) {
vals[n + i]--;
return n + i;
}
if (n - i >= 0 && vals[n - i]) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
using vv = vector<vector<T>>;
template <class T>
ostream &operator<<(ostream &os, const vector<T> &t) {
os << "{";
for (int(i) = 0; (i) < (t.size()); ++(i)) {
os << t[i] << ",";
}
os << "}" << endl;
return os;
}
template <class S, class T>
o... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100006;
const int MOD = 1000000007;
char S[N], W[N];
int n, cnt;
long long calMax() {
long long res = 1;
for (int i = 0; i < n; i++) {
if (S[i] != '?' && W[i] != '?') {
if (S[i] >= W[i])
res *= 1;
else
return 0;
contin... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, l1, l2, result, element;
cin >> t;
for (int i = 0; i < t; i++) {
int a[1000], b[1000];
result = 0;
cin >> l1 >> l2;
for (int j = 0; j < l1; j++) {
cin >> a[j];
}
for (int k = 0; k < l2; k++) {
cin >> b[k];
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b, c, d;
int m, p, q;
while (scanf("%d%d%d%d%d", &n, &a, &b, &c, &d) != EOF) {
long long cnt = 0;
for (int i = 1; i <= n; i++) {
m = i + b - c;
p = i + a - d;
q = m + a - d;
if (m >= 1 && m <= n && p >= 1 && p <= ... | 3 |
///...................SUBHASHIS MOLLICK...................///
///.....DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING....///
///.............ISLAMIC UNIVERSITY,BANGLADESH.............///
///....................SESSION-(14-15)....................///
#include<bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long a[26];
vector<long long> occ[26];
map<long long, long long> m;
long long pref[100003];
int main() {
string s;
long long i;
for (i = 0; i < 26; i++) cin >> a[i];
cin >> s;
for (i = 0; i < s.size(); i++) occ[s[i] - 'a'].push_back(i);
for (i = 0; i < s.si... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, x, p;
vector<int> v;
int main() {
cin >> n;
v.clear();
v.resize(n);
if (n == 1) {
cin >> x;
if (x == 1) {
cout << 1 << endl;
} else {
cout << 0 << endl;
}
return 0;
}
for (int i = 0; i < n; i++) {
cin >> v[i];
}
int... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD2 = 998244353;
void solve() {
long long n, s;
cin >> n >> s;
if (s < 2 * n)
cout << "NO";
else {
cout << "YES"
<< "\n";
for (long long i = 0; i < n - 1; i++) {
cout << 1 << " ";
}
cout << s - (n - 1) << "\n";
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
double PI = 4 * atan(1);
vector<int> nodes[200000];
vector<int> par[200000];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, t, k;
cin >> n >> t >> k;
int cur = 1, curk = n - t;
nodes[0].push_back(cur++);
for (int i = ... | 6 |
#include <bits/stdc++.h>
using namespace std;
map<int, bool> vis;
map<int, vector<int>> AdjList;
vector<int> Route;
int n, e, u, v;
void CreatingAdjListGraph() {
cin >> e;
for (int i = 0; i < e; ++i) {
cin >> u >> v;
AdjList[u].push_back(v);
AdjList[v].push_back(u);
}
}
void DFSRec(int root) {
Route... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, m, q, a[11][100005];
int comps[400005], lt[11][400005], rt[11][400005];
pair<int, int> par[3][1000001];
pair<int, int> par_find(pair<int, int> xp) {
return par[xp.second][xp.first] == xp
? xp
: par[xp.second][xp.first] = par_find(par[xp.se... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long a[110];
int main() {
int T;
scanf("%d", &T);
while (T--) {
int n;
scanf("%d", &n);
long long su = 0;
long long ma = 0;
for (int i = 1; i <= n; i++) {
sca... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int a[maxn], b[maxn], t[maxn];
int m, n, c;
int main() {
while (scanf("%d %d %d", &n, &m, &c) != EOF) {
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
t[0] = 0;
for (int i = 1; i <= m; ++i) {
scanf("%d", &b[i]);
t[i] = t[... | 2 |
#include <bits/stdc++.h>
using namespace std;
inline int rd() {
int x = 0, w = 1;
char c = getchar();
while (!isdigit(c) && c != '-') c = getchar();
if (c == '-') w = -1, c = getchar();
while (isdigit(c)) x = x * 10 + c - 48, c = getchar();
return x * w;
}
const int N = 400005;
int n, m, cc, c[N], hd[N], f[... | 12 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int INF = 1e9;
const double EPS = 1e-8;
struct node {
int num, id, add;
bool operator<(const node &a) const {
return num > a.num || (num == a.num && id < a.id);
}
} a[105];
int pre[105];
int n;
int ok(int i, int j) {
node x =... | 7 |
#include <bits/stdc++.h>
#pragma GCC optimization("O3")
using namespace std;
int main() {
;
ios_base::sync_with_stdio(false);
cin.tie(NULL);
;
int N;
cin >> N;
long long int arr[N];
for (int i = 0; i < N; i++) {
cin >> arr[i];
}
if (N == 1 || N == 2) {
cout << N << "\n";
return 0;
}
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
int n, q;
int ar[N + 2], ls[N + 2];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> ar[i];
}
vector<int> v;
cin >> q;
while (q--) {
int t;
cin >> t;
if (... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d, e, f;
scanf("%d %d %d %d %d %d", &e, &f, &a, &b, &c, &d);
if (a > c) swap(a, c);
if (b > d) swap(b, d);
if ((d - b) >= 5 || (c - a) >= 5)
printf("Second\n");
else {
if ((d - b) == 4 && (c - a) == 4)
printf("Second\n");
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const long long mxi = 100005;
vector<long long> dp[mxi];
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL);
;
long long n;
cin >> n;
long long ar[n];
long long cnt[33];
for (int i = 1; i <= n; i++) {
cin >> ar[i]... | 3 |
#include <bits/stdc++.h>
using namespace std;
string keyb = "qwertyuiopasdfghjkl;zxcvbnm,./";
map<char, int> m;
int main() {
for (int i = 0; i < keyb.size(); i++) {
m[keyb[i]] = i;
}
char ori;
string in;
cin >> ori;
cin >> in;
if (ori == 'R') {
for (int i = 0; i < in.size(); i++) {
cout << k... | 0 |
#include <bits/stdc++.h>
using namespace std;
int m[112345], p[112345];
int main() {
int n;
cin >> n;
int mn = 105, ans = 0;
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
mn = min(mn, y);
ans += mn * x;
}
cout << ans << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int g[2048];
int num[2048];
void un(int a, int b);
int Find(int x);
int main() {
int n, like, dislike, a, b, grp;
while (cin >> n) {
grp = 0;
for (int i = 1; i <= n; i++) {
g[i] = i;
num[i] = 1;
}
cin >> like;
for (int i = 0; i < like; i+... | 3 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> v[105];
int a[105][105];
int n, m;
long long f(int low, int high, int k) {
long long ans = 0;
for (int i = 0; i < n; i++) {
int idx = a[i][k];
if (v[i][idx].first >= low && v[i][idx].second <= high) ans++;
}
return ans * ans;
}
int mai... | 10 |
#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T>
inline string toString(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
inline int readInt() {
int x;
scanf("%d", &x);
return x;
}
map<string, in... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long powmod(long long base, long long exp, long long MOD) {
long long res = 1;
while (exp > 0) {
if (exp % 2 == 1) res = (res * base) % MOD;
base = (base * base) % MOD;
exp /= 2;
}
return (res % MOD);
}
const long long... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int M = 150000 + 10;
struct TREE {
int l, r;
double maxsub;
double maxprefix, maxsuffix;
double sum;
} tree[4 * M];
int a[M];
int p[M];
double E[M];
void build(int isize, int l, int r, int node) {
tree[node].l = l;
tree[node].r = r;
if (l == r) {
tre... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long n, k, ans = 0;
int main() {
cin >> n >> k;
long long i = 1;
while (n >= 2 && i <= k) {
ans = ans + (n - 1) * 2 - 1;
n = n - 2;
i++;
}
cout << ans;
return 0;
}
| 2 |
//Bismillahir Rahmanir Raheem
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define eb emplace_back
#define vl vector<ll>
#define pa pair<ll,ll>
#define mod 1000000007
#define maxN 1000000
#define dekhao(tc,ans) cout<<"Case "<<tc<<": "<<ans<<"\n"
const double pi=acos(-1.0);
using namespace std;
... | 2 |
#include <bits/stdc++.h>
int T, fl, cur, res, x[5], y[5], p[5], c[5], rx[5], ry[5], d[5];
struct value {
int val;
bool has;
inline void reset() { has = 0; }
inline void set(int x) {
if (has) {
if (val != x) fl = 0;
} else {
val = x, has = 1;
}
}
} vx, vy, kx, ky, k;
inline int calc(int... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, i, j, s = 1, m = 1;
scanf("%d", &t);
int a[t];
for (i = 0; i < t; i++) {
scanf("%d", &a[i]);
}
for (i = 1; i < t; i++) {
if (a[i] > a[i - 1]) {
s++;
if (s > m) m = s;
} else {
s = 1;
}
}
printf("%d", m);
... | 0 |
#include <bits/stdc++.h>
static const bool debug = 0;
using ll = long long;
int INF_int = 2147483647;
ll INF_ll = 9223372036854775807;
using namespace std;
int main() {
if (!debug) {
std::ios::sync_with_stdio(false);
cin.tie(0);
};
int n;
cin >> n;
if (n > 5) {
cout << "1 2\n2 3\n2 4\n3 5\n3 6\n";... | 3 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class t, class u>
void chmax(t& first, u second) {
if (first < second) first = second;
}
template <class t, class u>
void chmin(t& first, u second) {
if (second < first) first = second;
}
template <class t>
using vc = vector<t>;
template ... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long i, j, n, m;
bool vis[1000009];
vector<int> ans, g[1000009];
int main() {
scanf("%d%d", &n, &m);
for (i = 1; i <= m; i++) {
int x, y;
scanf("%d%d", &x, &y);
g[x].push_back(y);
}
for (i = 1; i <= n; i++)
if (!vis[i]) {
for (j = 0; j < g... | 11 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
using namespace std;
const int N = 100000 + 10;
const long long MOD = 1000000000 + 7;
const long long INF = 1000000010;
const long long LOG = 17;
int n, sz[N], fen[2][N], L[N], R[N], st[N], ft[N], Time, par[N], ans[N];
bool... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, x1, y1, x2, y2;
;
cin >> n;
cout << "YES\n";
for (long long i = 0; i < n; i++) {
cin >> x1 >> y1 >> x2 >> y2;
if (x1 % 2 == 0 && y1 % 2 == 0) cout << "1\n";
if (x1 % 2 == 0 && y1 % 2 != 0) cout << "2\n";
if (x1 % 2 != 0 &&... | 6 |
#include <bits/stdc++.h>
using namespace std;
int t;
int a, b, c, d;
int main() {
scanf("%d", &t);
while (t--) {
scanf("%d%d%d%d", &a, &b, &c, &d);
if (b >= a) {
printf("%d\n", b);
continue;
}
if (d >= c) {
printf("-1\n");
continue;
}
a -= b;
d = c - d;
int t ... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T abs(T t) {
return t < 0 ? -t : t;
}
const long long modn = 1000000007;
inline long long mod(long long x) { return x % modn; }
const int MAXN = 1123456;
long long n, m, k;
long long s[MAXN];
long long ult[MAXN];
int main() {
scanf("%lld", &... | 5 |
#include <bits/stdc++.h>
using namespace std;
void pencilcase(long long a, long long b, long long c, long long d,
long long k) {
if (k <= 1) {
cout << -1 << endl;
return;
}
long long pen;
long long pencil;
if (a % c > 0) {
pen = (a / c) + 1;
} else {
pen = (a / c);
}
if (... | 0 |
#include <bits/stdc++.h>
using namespace std;
int tot, toz, nm[11];
long long ans, tom = 1, mul[20];
vector<pair<int, int> > num;
void dfs(int x) {
for (int i = 1; i <= num[x].second; i++) {
tot++;
tom *= i;
if (!num[x].first) toz = i;
if (x == num.size() - 1) {
ans += mul[tot] * (tot - toz) / t... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b;
int x, y, m = 0;
cin >> n;
for (int i = 1; i <= n / 2; i++) {
a = i;
b = n - i;
while (a != b) {
if (a > b) {
a = a - b;
} else {
b = b - a;
}
}
if ((a == 1) && (i < (n - i)) &&
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300;
int n, m, k, t;
vector<int> v;
void ubaci(int x) {
int lim = v.size();
vector<int> res;
for (int i = 0; i < x - 1; i++) res.push_back(v[i]);
res.push_back(0);
for (int i = x - 1; i < lim; i++) res.push_back(v[i]);
v = res;
}
int nadi(vector... | 4 |
#include <bits/stdc++.h>
using namespace std;
int dfs(int *graph, int n) {
int maxDepth = 0, tmp, i, j;
for (i = 1; i <= n; i++) {
tmp = 1, j = i;
while (graph[j] != -1) {
tmp++;
j = graph[j];
}
maxDepth = maxDepth > tmp ? maxDepth : tmp;
}
return maxDepth;
}
int main() {
int n, ma... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
const int p = 1e9 + 7;
int n, k, suf[N], pre[N], fac[N];
void read(int &x) {
int flg = 1;
x = 0;
char c = getchar();
while (!isdigit(c)) {
if (c == '-') flg = -1;
c = getchar();
}
while (isdigit(c)) x = x * 10 + c - '0', c = getcha... | 9 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:64000000")
const int maxn = 18;
const int maxm = 110;
const int maxmask = (1 << maxn) - 1;
const int infi = 1e9 + 7;
const long long infl = 1e18;
const long double eps = 1e-10;
const long long mod = 1e9 + 7;
int ar[100500];
long long dp[2010]... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
void sync_stdio() {
cin.tie(NULL);
ios_base::sync_with_stdio(false);
}
struct Sync_stdio {
Sync_stdio() {
cin.tie(NULL);
ios_base::sync_with_stdio(false);
}
} _sync_stdio;
struct FAIL {
FAIL() {
cout << "CHANGE!!!"
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n > 36)
cout << "-1";
else {
if (n % 2 == 1) {
cout << "9";
n--;
}
for (int i = 0; i < n / 2; i++) {
cout << "8";
}
}
}
| 2 |
#include <bits/stdc++.h>
const int mod = 1e9 + 7;
const int N = 100050, M = 105;
struct Matrix {
int a[M][M];
Matrix operator*(const Matrix& b) const {
Matrix c;
int i, j, k;
for (i = 0; i < M; i++)
for (j = 0; j < M; j++) c.a[i][j] = 0;
for (i = 0; i < M; i++)
for (j = 0; j < M; j++)
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int g[1010];
int mark[2010];
int save[1010];
int bin[1100];
int num[1100];
int find(int x) {
if (x == bin[x]) return x;
return bin[x] = find(bin[x]);
}
int main() {
int n, x;
scanf("%d%d", &n, &x);
for (int i = 1; i <= n; i++) {
scanf("%d", &g[i]);
}
for (... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios ::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
map<int, int> used;
for (int c = 0; c < (n); c++) {
int x, y, total = 0;
cin >> x >> y;
for (int i = 1; i * i <= x; i++) {
if (x % i == 0) {
int start = c - y, e... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int iinf = 1e9 + 7;
const long long linf = 1ll << 60;
const double dinf = 1e10;
void scf(int &x) {
bool f = 0;
x = 0;
char c = getchar();
while ((c < '0' || c > '9') && c != '-') c = getchar();
if (c == '-') {
f = 1;
c = getchar();
}
while (c >= ... | 8 |
// 及时当勉励,岁月不待人!
//当前状态 : attempted
//#include<bits/stdc++.h>;
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<vector>
#include<cmath>
#include<string>
#include<iomanip>
#define MP make_pair
#define fuck() int t;cin>>t;while(t--)
using name... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> a(n);
for (int &e : a) cin >> e;
bool ok = true;
for (int i = 0; i < n - 1; i++) {
if (a[i] + 1 < a[i + 1]) {
ok = false;
break;
}
}
co... | 3 |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:16777216")
using namespace std;
const double Pi = acos(-1.0);
const int INF = 1000000000;
const int MAX = 250007;
const int MAX2 = 2000000;
const int BASE = 10;
const int ST = 1000000007;
const int CNT = 100;
int p[MAX];
int t[MAX];
bool Comp(pair<int, int> a, pa... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n, ans[200100], st = 1, i;
double s[200100], sum = 0;
int main() {
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%lf", &s[i]);
sum += s[i];
}
for (i = 1; i <= n; i++)
if ((sum - s[i]) / (n - 1) == s[i]) ans[st++] = i;
if (st != 1) {
printf... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100020;
char s[MAXN];
struct XYZ {
int x, y, z;
} xyz[MAXN];
int main() {
scanf("%s", s);
int len = strlen(s);
int x = 0, y = 0, z = 0;
xyz[0].x = x;
xyz[0].y = y;
xyz[0].z = z;
for (int i = 1; i <= len; ++i) {
if (s[i - 1] == 'x')
... | 3 |
#include <bits/stdc++.h>
using namespace std;
vector<int> a[200005];
int deep[200005];
int f[200005];
int b[200005][21];
int kk[200005];
int flag, k;
void dfs(int u, int fu) {
f[u] = fu;
b[u][0] = fu;
for (int i = 1; i <= 20; i++) b[u][i] = b[b[u][i - 1]][i - 1];
deep[u] = deep[fu] + 1;
for (int i = 0; i < (i... | 5 |
#include <bits/stdc++.h>
using namespace std;
int levo[5002][5002], mg[5003][5003], a[5003];
int main() {
ios::sync_with_stdio(false);
int n, m, res = 0, i, j, k, x;
string s;
cin >> n >> m;
for (i = 1; i <= n; i++) {
cin >> s;
for (j = 1; j <= m; j++) mg[i][j] = s[j - 1] - '0';
}
for (i = 1; i <=... | 4 |
#include <bits/stdc++.h>
int n, r[501000], _[501000][20], Max[501000][20];
int MAX(int a, int b) { return a + r[a] > b + r[b] ? a : b; }
long long Ans;
int Query(int a, int b) {
if (b >= 2 * n) b = 2 * n - 1;
int l(b - a + 1), k;
for (k = 0; (1 << k + 1) <= l; k++)
;
return MAX(Max[a][k], Max[b - (1 << k) +... | 5 |
#include <bits/stdc++.h>
using namespace std;
int t, n, p, id, ix, iy;
int a[500000];
int b[500000];
long long int isum;
void print() {
for (int j = 0; j < id; j++) {
isum += b[j] * 1ll;
}
printf("%lld\n", isum);
}
void is_calculatein(int i) {
if (i < 0 || i >= n) return;
if (i == 0) {
if (a[i] > a[i ... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long int a[1100000], s[1100000];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
long long int n, k;
cin >> n >> k;
for (long long int i = 1; i <= n; i++) {
cin >> a[i];
}
if (n == 1) {
cout << 1 << " " << a[1] << endl;
return 0;
}
sort(... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline void chkmin(T1 &x, T2 y) {
if (x > y) x = y;
}
template <typename T1, typename T2>
inline void chkmax(T1 &x, T2 y) {
if (x < y) x = y;
}
using ll = long long;
using ld = long double;
const string FILENAME = "input";
const int M... | 12 |
#include <bits/stdc++.h>
int l;
int h;
int s;
int main() {
int n, x;
scanf("%d %d", &n, &x);
int e;
for (int i = 0; i < n; ++i) {
scanf("%d ", &e);
if (e < x) {
++l;
} else if (e == x) {
++s;
}
}
h = n - l - s;
int half = (n + 1) / 2;
if (l < half) {
if (s + l >= half) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
string s;
cin >> s;
int mat = (n * (n - 1)) / 2;
int c2 = 0;
int in;
for (int i = 0; i < n; i++)
if (s[i] == '2') {
c2++;
in = i;
}
int d = (n * n) - n + c2 - (c2 * c2);
if (c2 == 1 || c2 == 2)
cout... | 1 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int main() {
int n, l[300], c[300];
cin >> n;
for (int i = 0; i < n; i++) cin >> l[i];
for (int i = 0; i < n; i++) cin >> c[i];
unordered_map<int, int> um;
for (int i = 0; i < n; i++)
if (um.find(l[i]) ... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long const mod = pow(2, 32);
inline long long add(long long a, long long b) {
return ((a % mod) + (b % mod) + mod) % mod;
}
inline long long mul(long long a, long long b) {
return (((a % mod) * (b % mod)) % mod + mod) % mod;
}
inline long long sub(long long a, long... | 8 |
#include <cstdlib>
#include <cstdarg>
#include <cassert>
#include <cctype> // tolower
#include <ctime>
#include <cmath>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <stdexcept>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <vector>
#include <string>
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000006;
int n, m;
int a[N], b[N];
int q[33];
int main() {
ios_base::sync_with_stdio(false);
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
int j = 0;
while (a[i]) {
if (a[i] % 2 == 1) ++q[j];
a[i] /= 2;
++j;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using u64 = uint64_t;
using u32 = uint32_t;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vpi = vector<pi>;
static constexpr int INF = (int)1e9 +... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
while (n--) {
long long int x, y;
cin >> x >> y;
long long int sum = 0;
if (y % 10 == 0) {
sum = 0;
} else if (y % 5 == 0) {
long long int w = x / y;
long long int t = w % 10;
w = w / 10;
... | 2 |
#include <bits/stdc++.h>
const long double PI = atan2(0, -1);
using namespace std;
const int N = 100;
vector<int> a(N + 1);
int main() {
int n, m;
cin >> n >> m;
if (m == 0) {
cout << 0;
return 0;
}
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
sort(a.rbegin(), a.rend());
long long s =... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 105;
int n, m, x, y;
char ch;
int DP[MAXN][MAXN][28][2];
vector<vector<pair<int, int> > > v;
int dp(int i, int j, int prev, bool ok) {
int &ret = DP[i][j][prev][ok];
if (~ret) return ret;
ret = 0;
if (!ok) {
for (auto k : v[i])
if (k.first... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000;
int n, m, head[maxn + 1], link[maxn * 2 + 1], adj[maxn * 2 + 1];
bool visit[maxn + 1];
int bfs(int s) {
memset(visit, false, sizeof(visit));
queue<int> q;
q.push(s);
int p;
visit[s] = true;
do {
p = q.front();
q.pop();
int i ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MX = 2e5 + 5;
const long long INF = 1e18;
const long double PI = 4 * atan((long double)1);
template <class T>
bool ckmin(T& a, const T& b) {
return a > b ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T& a, const T& b) {
return a < b ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, a, x, b, y;
cin >> n >> a >> x >> b >> y;
a--, x--, b--, y--;
while (true) {
if (a == b) {
cout << "YES\n";
return 0;
}
if (a == x || b == y) {
break;
}
a = (a + 1) % ... | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.