solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int n, m;
long long a[100005];
long long S[100005][6], C[6][6];
struct Node {
int l, r;
long long s[6], lazy;
Node *lc, *rc;
} *tree = 0;
void print(Node *root);
void Init() {
for (int i = 1; i <= n; i++) {
long long x = 1;
for (int ... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int Mod = 1e9 + 7;
int add(int a, int b) { return a + b >= Mod ? a + b - Mod : a + b; }
int dec(int a, int b) { return a - b < 0 ? a - b + Mod : a - b; }
int mul(int a, int b) { return 1ll * a * b % Mod; }
void Add(int &a, int b) { a = add(a, b); }
void Dec(int &a, in... | 16 |
#include <bits/stdc++.h>
using namespace std;
const long long int N = 5005;
string s[N];
long long int perm[N];
long long int n, k;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> k;
for (long long int i = 0; i < k; i++) {
perm[i] = i;
}
for (long long int i = 0; i < n; i... | 6 |
#include <bits/stdc++.h>
#pragma GCC optimize("inline", 3)
using namespace std;
const int N = 8e5 + 5, B = 20;
char s[N];
int n, fa[N], len[N], sz[N], a[N], cc[N], np = 1, cnt = 1;
map<int, int> c[N];
int poi[N];
vector<int> e[N];
int st[B][N << 1], dfn[N], pos[N], tim;
int qq[N << 1], pre[N], za[N], zb[N], siz;
bool c... | 18 |
#include <bits/stdc++.h>
using namespace std;
const long long int mo = 998244353ll;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long int test;
cin >> test;
while (test--) {
long long int n, k;
cin >> n >> k;
long long int a[200009], pos[200009];
for (long long int... | 10 |
#include <bits/stdc++.h>
using namespace std;
int arr[200010];
int numero[200010];
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> arr[i];
numero[arr[i]]++;
}
int num;
int mayor = numero[0];
for (int i = 1; i < 200010;... | 6 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
using ld = long double;
int32_t main() {
ld base = (ld)clock() / CLOCKS_PER_SEC;
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n;
cin >> n;
vector<ll> a(n)... | 17 |
#include <bits/stdc++.h>
using namespace std;
int dr[8] = {0, 0, -1, 1, -1, -1, +1, +1};
int dc[8] = {-1, 1, 0, 0, -1, +1, -1, +1};
const int N = 205;
void solve() {
int n;
cin >> n;
string a, b;
cin >> a >> b;
vector<int> vec;
for (int i = n - 1; i >= 0; --i) {
if (a[i] == b[i])
continue;
els... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;
const int N = 35;
int n, u, v;
vector<int> adj[N];
long long px[N], py[N];
bool vis[N];
int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};
int opp[4] = {1, 0, 3, 2};
void dfs(int x, long long d... | 12 |
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define all(X) (X).begin(),(X).end()
#define ln "\n"
#define out cout
#define NON_TOGLIERE ios_base::sync_with_stdio(0); cin.tie(0);
#define ll long long
#define VI vector<int>
#define pii pair<int,int>
#define pll pair<long long,long long... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int M = 2e5 + 10;
long long anum[M], bnum[M], fac[M], up[M], down[M];
long long inv(long long a) {
return a == 1 ? 1
: (long long)(1000000007 - 1000000007 / a) *
inv(1000000007 % a) % 1000000007;
}
int main() {
int n;
scanf(... | 14 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> a;
vector<long long> b;
long long n;
void solve() {
int n;
cin >> n;
set<int> last;
n *= 2;
while (n--) {
int a;
cin >> a;
if (last.find(a) == last.end()) {
last.insert(a);
cout << a << " ";
}
}
cout << "\n";
}
int... | 0 |
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<numeric>
#include<limits>
#include<climits>
#include<limits.h>
#include<math.h>
#include<cmath>
#include<cstring>
#include<iomanip>
using namespace std;
int t, n;
int main() {... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int main() {
long long T;
cin >> T;
while (T--) {
long long n, sum = 1;
cin >> n;
for (int i = 1; i < 2 * n; i++) {
sum = (sum * i) % mod;
}
cout << (sum * n) % mod << endl;
}
}
| 0 |
#include <bits/stdc++.h>
namespace cltstream {
char cltin[1048576 + 1], *ih = cltin, *it = cltin;
inline char gc() {
if (ih == it) {
it = (ih = cltin) + fread(cltin, 1, 1048576, stdin);
if (ih == it) return EOF;
}
return *ih++;
}
char cltout[1048576 + 1], *oh = cltout, *ot = cltout + 1048576;
inline void ... | 16 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
long long DP[2][205][1005];
int A[205];
long long g(int i, int o, int j) {
i %= 2;
if (o < 0 || j < 0) {
return 0;
}
return DP[i][o][j];
}
int main() {
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> A[i... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int w, h;
cin >> w >> h;
int u1, d1, u2, d2;
cin >> u1 >> d1;
cin >> u2 >> d2;
for (int i = h; i >= 0; i--) {
w += i;
if (i == d1) w -= u1;
if (i == d2) w -= u2;
if (w ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int n, q;
vector<pair<int, int> > v[maxn];
vector<int> ans, tmp;
bool mark[maxn];
int cnt[maxn], a[maxn], b[maxn];
void dfs(int i) {
tmp.push_back(i);
mark[i] = 1;
for (auto A : v[i])
if (!mark[A.first]) dfs(A.first);
}
void solve2() {
... | 15 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigmod(T p, T e, T M) {
long long ret = 1;
for (; e > 0; e >>= 1) {
if (e & 1) ret = (ret * p) % M;
p = (p * p) % M;
}
return (T)ret;
}
template <class T>
inline T gcd(T a, T b) {
if (b == 0) return a;
return gcd(b, a % b);
}
... | 16 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k, v;
multiset<int> A, B;
int main() {
scanf("%d%d%d", &n, &m, &k);
for (int i = 0; i < n; ++i) {
scanf("%d", &v);
A.insert(v);
}
for (int i = 0; i < m; ++i) {
scanf("%d", &v);
B.insert(v);
}
while (!A.empty() && !B.empty()) {
if (*... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr);
const int INF = 1.01e9;
int N, M; cin >> N >> M;
vector<int> XA(N), YA(N);
for (int i = 0; i < N; ++i) cin >> XA[i] >> YA[i];
vector<int> XB(M), YB(M), T(M);
for (int i = 0; i < M... | 25 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
long long n, l, r;
cin >> n >> l >> r;
long long cur = 0, num = 1, rest = n - 1;
while (cur < l) {
cur += (rest * 2);
if (cur >= l) {
... | 10 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > x;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, h;
cin >> n >> h;
x.resize(n);
for (int i = 0; i < x.size(); ++i) {
cin >> x[i].first >> x[i].second;
}
int ptrl = 0;
int ptrr = 1;
int cnt = 0;
int sum = ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int read() {
int X = 0, w = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') w = -1;
c = getchar();
}
while (c >= '0' && c <= '9') X = X * 10 + c - '0', c = getchar();
return X * w;
}
const int N = 4096 + 10;
int n, Q, a[N], pos[N], ans[... | 25 |
#include <bits/stdc++.h>
using namespace std;
int n, rating, tmp, min0 = -20000001, max0 = 20000001;
int c[200000], d[200000];
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> c[i] >> d[i];
if (d[i] == 1)
min0 = max(tmp, min0);
else
max0 = min(tmp, max0);
tmp -= c[i];
rati... | 8 |
#include <bits/stdc++.h>
using namespace std;
int R = 1e9 + 7;
template <typename T>
T last(vector<T>& v) {
return v[v.size() - 1];
}
template <typename T>
void print(vector<T>& v) {
for (int i = 0; i < v.size(); i++) {
cout << v[i] << ' ';
}
cout << endl;
}
template <typename T1, typename T2>
void print(ve... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 150;
long long s, ans;
inline long long dp(int ot, int la, int lb, long long sm) {
static long long f[N][2], las[N][2];
for (int a = 0, nn = int(ot + 1); a < nn; ++a)
for (int re = 0, nn = int(2); re < nn; ++re) f[a][re] = 0;
f[0][0] = 1;
for (int ... | 24 |
#include <bits/stdc++.h>
using namespace std;
void Suhaib_Sawalha() {
int n, m, k;
cin >> n >> m >> k;
int sec, total;
cin >> sec >> total;
vector<pair<int, int>> Short(m);
for (auto &x : Short) cin >> x.first;
for (auto &x : Short) cin >> x.second;
Short.push_back({sec, 0});
vector<int> por(k), cost(... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long s, a, b, c;
int main() {
int T;
cin >> T;
while (T--) {
cin >> s >> a >> b >> c;
long long t = s / c;
cout << s / c + t / a * b << endl;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int k, out;
vector<int> vec;
cin >> s >> k;
for (int i = 0; i < 26; i++) cin >> out, vec.push_back(out);
out = 0;
int i;
for (i = 0; i < s.size(); i++) out += vec[s[i] - 'a'] * (i + 1);
int l, maximum = *max_element(vec.begin(), vec.... | 2 |
#include <bits/stdc++.h>
using namespace std;
char QAQ;
bool fff;
template <class T>
inline void Read(T &k) {
while (((QAQ = getchar()) < '0' || QAQ > '9') && QAQ != '-')
;
fff = QAQ == '-';
k = fff ? 0 : QAQ - '0';
while ((QAQ = getchar()) >= '0' && QAQ <= '9') k = k * 10 + QAQ - '0';
if (fff) k = -k;
}
... | 22 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3 * 1000 * 100 + 100;
int n, m;
vector<pair<int, int>> adj[N];
bool vis[N];
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int Q;
cin >> Q;
while (Q--) {
cin >> n >> m;
for (int i = 1, v, u; i <= m; i++) {
cin >> v >> ... | 12 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, k;
cin >> n >> k;
if ((n - k) % 2 == 0 && n >= k * k)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
void bsolve() {
int n;
cin >> n;
bool was[n];
for (bool &w : was) w = false;
int answer = -1;
for (int i = 0; i ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 1, MOD = 1e9 + 7;
long long n, ans, a[MAX], q, b[MAX];
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
q = max(q, a[i]);
b[a[i]]++;
if (a[i] == 1) ans++;
}
for (int i = q; i > 1; i--) {
if (b[i] > b[i - 1])... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 400005;
int n, I;
int a[N];
int main() {
scanf("%d %d", &n, &I);
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
}
int bit = min(20, I * 8 / n);
sort(a, a + n);
vector<int> dq;
for (int i = 0; i < n;) {
int j = i;
while (j < n && a[... | 8 |
#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
int upmin(T1 &x, T2 v) {
if (x > v) {
x = v;
return 1;
}
return 0;
}
template <class T1, class T2>
int upmax(T1 &x, T2 v) {
if (x < v) {
x = v;
return 1;
}
return 0;
}
const int INF = 0x3f3f3f3f;
int N, K;
vector<int... | 12 |
#include <bits/stdc++.h>
using namespace std;
bool fexists(const char *filename) {
std::ifstream ifile(filename);
return (bool)ifile;
}
string s;
string SUB(int x, int y) {
string ss = "";
for (int i = x; i <= y; ++i) ss += s[i];
return ss;
}
int use[27];
bool check(string ss) {
for (int i = 0; i < 26; ++i)... | 2 |
#include <bits/stdc++.h>
using namespace std;
long double n, l, v1, v2, k;
long long int check(long double t) {
if (t * v1 >= l) return 1;
long double val = (l / v1) - t;
val /= (v2 - v1);
val *= v1 * v2;
long double a = val / v2, b = val * (v2 - v1);
b /= v2 * (v1 + v2);
long double tot = (a + b) * ceil(... | 11 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, m, d;
cin >> n >> m >> d;
int a[m];
int sum = 0;
for (int i = 0; i < m; i++) {
cin >> a[i];
sum += a[i];
}
if (sum + (m + 1) * (d - 1) < n) {
cout << "NO\n";
return;
}
cout << "YES\n";
vector<int> answer(n);
int j ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int NODE = 300000 + 5, EDGE = 300000 + 5, BIEDGE = EDGE * 2;
int n, m;
int hd[NODE], to[BIEDGE], nxt[BIEDGE];
inline void addedge(int idx, int a, int b) {
nxt[idx] = hd[a];
hd[a] = idx;
to[idx] = b;
}
struct Edge {
int id;
int a, b, len;
inline bool operat... | 15 |
#include <bits/stdc++.h>
using namespace std;
int solve(vector<int> &many, vector<int> &put, int acc) {
head:
for (int k = 4; k >= 3; k--) {
if (many[k] < put[k]) {
for (int i = 1; i <= k - 1; i++)
for (int j = k - 1; j >= i; j--) {
int move;
if (i != j)
move = min(mi... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int n, k, cnt = 0, z = 0;
vector<int> aryN, aryM, aryL;
cin >> n >> k;
for (int i = 0; i < n; i++) {
int num;
cin >> num;
aryN.push_back(num);
aryM.push_back(num);
}
sort(aryN.begin(), aryN.end());
for (int i = 0; i < n; i++) {... | 2 |
#include <bits/stdc++.h>
using namespace std;
double arr[100005];
int main() {
double n;
cin >> n;
double k;
cin >> k;
double maxi = -1;
for (int i = 0; i < n; i++) {
cin >> arr[i];
maxi = max(maxi, arr[i]);
}
double low = 0, high = maxi;
double excess = 0.0, slack = 0.0, mid;
while (high - ... | 8 |
#include <bits/stdc++.h>
int w, n, m;
int cnt[1 << 12], a[1 << 12];
char gate[15];
void fwht(int n, int a[]) {
for (int dim = 0; dim < w; ++dim) {
int len = 1 << dim;
for (int i = 0; i < n; i += len << 1) {
for (int j = i; j < i + len; ++j) {
int u = a[j], v = a[j + len];
if (gate[dim] =... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100 + 7;
int cnt[N];
int main() {
int ans = 0;
int n, k;
cin >> n >> k;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
cnt[x % k]++;
}
for (int i = 0; i * 2 <= k; i++) {
int j = (k - i) % k;
if (i == j)
ans += cnt[i] / 2;
... | 4 |
#include <bits/stdc++.h>
const int MN = 1e5 + 10;
long long f[MN], b = 0x3f3f3f3f3f3f3f3f;
int N, K, id;
int main() {
scanf("%d%d", &N, &K);
for (int i = 0, a; i < N; ++i) scanf("%d", &a), f[i % K] += a;
for (int i = 0; i < K; ++i)
if (f[i] < b) b = f[i], id = i;
printf("%d\n", id + 1);
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
if (a < b) {
a = a + b;
b = a - b;
a = a - b;
}
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int n, a, b, p, q,... | 8 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const long long infLL = 9000000000000000000;
inline bool checkBit(long long n, int i) { return n & (1LL << i); }
inline long long setBit(long long n, int i) {
return n | (1LL << i);
;
}
inl... | 8 |
#include <bits/stdc++.h>
int pmod(int n, int m) { return (n % m + m) % m; }
int next(int n, int m) { return n + pmod(-n, m); }
int main() {
int t;
std::cin >> t;
while (t--) {
int n, k;
std::cin >> n >> k;
std::string str;
std::cin >> str;
std::string oth(str.size(), '0');
int c = 0;
f... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
for (int k, l, m, n, d; cin >> k >> l >> m >> n >> d && k | l | m | n | d;) {
vector<int> a(d + 1);
for (int i = 0; i < a.size(); i += k) a[i] = 1;
for (int i = 0; i < a.size(); i += l) a[i] = 1;
for (int i = 0; i < a.size(); i += m) a[i] = 1;... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n{0};
cin >> n;
while (n--) {
string s, t;
cin >> s >> t;
int a = s.length(), b = t.length();
vector<pair<char, int>> vec, v;
char c = s[0];
int count = 1;
for (int i = 1; i < a; i++) {
if (c == s[i]) {
count+... | 4 |
#include <bits/stdc++.h>
char Gc() {
static char now[1 << 20], *S, *T;
if (T == S) {
T = (S = now) + std::fread(now, 1, 1 << 20, stdin);
if (T == S) return EOF;
}
return *S++;
}
template <typename T>
void Read(T &x) {
x = 0;
int f = 1;
char c;
while ((c = Gc()) < '0' || c > '9')
if (c == '-'... | 14 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
string s;
int zrr[1000005];
int ct[1000005];
void compute_z() {
int l = 0, r = 0;
int sz = s.size();
zrr[0] = sz;
for (int i = 1; i < sz; i++) {
if (r < i) {
l = r = i;
while (r < sz && s[r - l] == s[r]) r++;
zrr[i] =... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int arr[1001] = {0};
cin >> n;
int x = n;
while (n--) {
int num;
cin >> num;
arr[num]++;
}
int sol = 0;
for (int i = 0; i < 1001; i++) {
sol = max(sol, arr[i]);
}
(sol <= ((x + 1) / 2)) ? cout << "YES" : cout << "NO";
... | 3 |
#include <bits/stdc++.h>
int arr[10];
long long factx[101], invf[101];
long long memo[101][11][2];
long long modexp(long long a, long long n) {
long long res = 1;
while (n) {
if (n & 1) res = ((res % 1000000007) * (a % 1000000007)) % 1000000007;
a = ((a % 1000000007) * (a % 1000000007)) % 1000000007;
n ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, A[200], ans = 0, sub = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> A[i];
}
for (int i = 0; i < n; i++) {
sub = 0;
for (int j = i; j < n; j++) {
sub = sub ^ A[j];
ans = max(sub, ans);
}
}
cout << ans;
retu... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int nums[n];
int nums2[n];
for (int i = 0; i < n; i++) {
cin >> nums[i];
cin >> nums2[i];
}
for (int i = 0; i < n; i++) {
int d = 0;
if (nums[i] % nums2[i] != 0) {
d = (nums2[i] * (nums[i] / nums2[i] + 1)) - ... | 0 |
#include <bits/stdc++.h>
using namespace std;
inline long long int modadd(long long int n, long long int m,
long long int p = 1000000007) {
return ((n + m) % p + p) % p;
}
inline long long int modsub(long long int n, long long int m,
long long int p = 1000000007... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2013;
char p[1 << 20], s[205];
int k, n, m, r, i, l1, l2, e;
string y, z;
int main() {
gets(p);
gets(s);
cin >> k;
n = strlen(p);
m = strlen(s);
for (int i = 0; i <= k; ++i) y += "1";
for (int d = 1; d <= min(m, k) && n / k * d <= m; ++d) {
z... | 16 |
#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
using namespace std;
inline int read() {
int x = 0, neg = 1;
char op = getchar();
while (!isdigit(op)) {
if (op == '-') neg = -1;
op = getchar();
}
while (isdigit(op)) {
x = 10 * x + op - '0';
op = getchar();
}
return... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
long long i, j, k;
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
vector<long long> v(n);
for (i = (0); i < (n); i++) cin >> v[i];
vector<long long> odd, even;
for (i... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long MN = 1e6 + 100;
long long t[MN];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long n;
cin >> n;
for (int i = 0; i < n; ++i) {
int w;
cin >> w;
++t[w];
}
long long ans = 0;
for (int i = 0; i < MN - 1; ++i) {
t[i ... | 7 |
#include <bits/stdc++.h>
using namespace std;
map<int, int> cnts;
int mat[20][20];
int main() {
int n, a;
scanf("%d", &n);
for (int i = 0; i < n * n; i++) {
scanf("%d", &a);
cnts[a]++;
}
bool checked = true;
int qaq[4] = {0, 0, 0, 0};
for (auto p : cnts) qaq[p.second % 4]++;
if (n & 1) {
if ... | 9 |
#include <bits/stdc++.h>
using namespace std;
struct Point {
long double x;
long double y;
};
long double cross(Point a, Point b) { return a.x * b.y - a.y * b.x; }
long double dot(Point a, Point b) { return a.x * b.x + a.y * b.y; }
bool cmp(pair<Point, int> a, pair<Point, int> b) {
return atan2(a.first.x, a.first... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
const int N = 200005;
const double PI = 4 * atan(1);
const long long MAX = 9223372036854775807;
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, 1, -1, -1};
long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long double EPS = 1e-8;
const long double PI = acos(-1.0);
const int MAXN = 1e5 + 100;
struct edge {
int u, v, c;
};
vector<edge> g;
vector<int> e[MAXN];
vector<int> en[MAXN];
int used[MAXN];
vector<int> col;
vector<int> vcol;
int cnt = 1;
int d... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int SIGMA = 26;
struct Node {
vector<int> next;
vector<int> go;
int p = -1;
int ch = -1;
int link = -1;
int cnt = 0;
Node() : next(vector<int>(SIGMA, -1)), go(vector<int>(SIGMA, -1)) {}
Node(int p, int ch)
: next(vector<int>(SIGMA, -1)),
... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int N;
cin >> N;
vector<int> a(N);
for (int i = 0; i < N; ++i) {
long long x;
cin >> x;
a[i] = __builtin_popcountll(x);
}
vector<int> pref(N);
pref[0] = a[0];... | 12 |
#include <bits/stdc++.h>
using namespace std;
int dr[] = {0, 0, 1, -1, -1, -1, 1, 1};
int dc[] = {1, -1, 0, 0, -1, 1, -1, 1};
int const MAX = 1e5 + 7;
int const MOD = 1e9 + 7;
int arr[MAX];
map<int, int> mp;
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i) scanf("%d", &arr[i]);
for (int i = 0; i... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int r, g, b, time = 29;
cin >> r >> g >> b;
int n[3] = {r, g, b};
while (n[0] + n[1] + n[2]) {
time++;
if (n[time % 3] >= 2)
n[time % 3] -= 2;
else
n[time % 3] = 0;
}
cout << time << endl;
return 0;
}
| 2 |
#include <bits/stdc++.h>
int main() {
int num;
scanf("%d", &num);
printf("%d", (num + 1) / 2);
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
//freopen("input", "r", stdin);
//freopen("output", "w", stdout);
int t;
cin >> t;
while (t--)
{
int x, y;
cin >> x >> y;
cout << x - 1 << " " << y;
if (t != 0)
cout << "\n";
}
return 0... | 3 |
#include<bits/stdc++.h>
using namespace std;
const int n1=1e9+7;
#define mvi map<int,vector<int>>
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define ll long long
#define pii pair<int,int>
#define vpii vector<pii>
#define pb push_back
#define f first
#define s second
#define all(x) ... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000 * 1000 * 1000 + 7;
vector<vector<int> > mul(vector<vector<int> > &a, vector<vector<int> > &b) {
int n = a.size();
vector<vector<int> > ret(n, vector<int>(n, 0));
for (int k = 0; k < n; ++k)
for (int i = 0; i < n; ++i)
for (int j = 0; j <... | 19 |
#include <bits/stdc++.h>
using namespace std;
int p, y;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int i, j, k;
cin >> p >> y;
for (j = 0; j <= 300 && y > p; j++, y--) {
for (i = 2; i * i <= y; i++) {
if (y % i == 0) {
break;
}
}
if (i * i > y || i > ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7, MAX = 1e5 + 2;
long long n, c, dp[MAX], sum;
vector<long long> arr, cur;
long long sol(int idx) {
if (idx == n) return 0;
long long& ret = dp[idx];
if (~ret) return ret;
ret = sol(idx + 1);
if (idx + c <= n) {
ret = max(ret, sol(... | 12 |
#include <bits/stdc++.h>
int main() {
int p1, p2, n, tx1, tx2, v;
double tempo, min = 1000;
scanf("%d %d", &p1, &p2);
scanf("%d", &n);
for (; n > 0; n--) {
scanf("%d %d %d", &tx1, &tx2, &v);
tempo = (sqrt(((tx1 - p1) * (tx1 - p1)) + ((tx2 - p2) * (tx2 - p2)))) / v;
if (tempo <= min) min = tempo;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9 + 7;
const int MOD = (int)1e9 + 7;
const int N = 2000;
vector<vector<int>> friends(N, vector<int>());
vector<vector<bool>> dislike(N, vector<bool>(N));
vector<bool> vis(N);
vector<int> friendGroup;
set<int> past;
void dfs(const int& node) {
friend... | 7 |
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 998244353
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
#define N 100010
using namespace std;
ll n,a[N... | 19 |
#include <bits/stdc++.h>
using namespace std;
int a, b;
vector<vector<int> > graph(300005);
vector<int> color(300005);
long long PowMod(long long n) {
long long ret = 1;
long long a = 2;
while (n > 0) {
if (n & 1) ret = ret * a % 998244353;
a = a * a % 998244353;
n >>= 1;
}
return ret;
}
void inti... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
set<char> se;
string a, b;
int n, m;
scanf("%d%d", &n, &m);
cin >> a >> b;
string c = "";
c += a[0];
c += b[0];
c += a[n - 1];
c += b[m - 1];
if (c == ">^<v" || c == "<v>^")
printf("YES");
else
printf("NO");
return 0;
}
| 6 |
#include <bits/stdc++.h>
using namespace std;
int n, A, B, C, D, pos, dep[200010], f[200010], g[200010];
int k, la[200010], ff[200010 * 2];
struct info {
int x, y;
bool operator<(const info &p) const {
return x < p.x || (x == p.x && y < p.y);
}
} res;
struct node {
int a, b;
} e[200010 * 2];
void add(int a,... | 17 |
#include <bits/stdc++.h>
using namespace std;
struct candy {
int h;
int m;
};
int findAns(vector<candy> v0, vector<candy> v1, int jmp) {
int typeNow = 0;
int ans = 0;
while (true) {
if (typeNow == 0) {
if (v0.size() == 0) break;
int mostMassInd = -1;
for (int i = 0; i < v0.size(); i++) {... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 155;
const int STATES = 2;
const int MOD = 1000000007;
long long dp[MAXN][MAXN][MAXN][STATES][STATES], sum[MAXN][MAXN][STATES][STATES];
long long get_sum(int x1, int y1, int x2, int y2, int ls, int rs) {
if (y2 < y1 || x2 < x1) return 0;
return sum[x2][... | 16 |
#include <bits/stdc++.h>
using namespace std;
inline char gc() {
static char buf[100000], *p1 = buf, *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
? EOF
: *p1++;
}
inline long long read() {
long long x = 0;
char ch = getchar();
bool positive... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e7 + 1;
long long int spf[MAXN], num[MAXN] = {0}, denom[MAXN] = {0};
vector<long long int> prime;
long long int binpow(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;
b >>= 1;
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long k, p = 9, s = 9, dig = 1;
cin >> k;
while (k > s) {
k = k - s;
dig++;
p = 10 * p;
s = p * dig;
}
p = p / 10;
int d = p / 10;
while (d != 0) {
p = p + d;
d = d / 10;
}
long long num = 0, rem = 0;
if (k % dig ... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long n;
int Tong(int x) {
int d = 0;
while (x) {
d += x % 10;
x /= 10;
}
return d;
}
int main() {
cin >> n;
while (Tong(n) % 4 != 0) n++;
cout << n;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
cout << 2000 << endl;
for (int i = 1; i <= 1000; i++) printf("%d 1 %d 2\n", i, i);
for (int i = 1000; i >= 1; i--) printf("%d 1 %d 2\n", i, i);
return 0;
}
| 9 |
#include <bits/stdc++.h>
using namespace std;
const int OO = (int)1e9 + 7;
const int mod = (int)1e9 + 9;
const int MX = (int)2 * 1e3 + 5;
const int N = (int)1e3 + 5;
const double PI = 2 * acos(0.0);
int main(void) {
ios_base::sync_with_stdio(false);
int n, m, no, mo, xx, yy, z, p;
while (cin >> no >> mo >> xx >> ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int MOD2 = 1007681537;
const int INF = (int)1e9;
const long long LINF = (long long)1e18;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
inline long long gcd(long long a, long long b) {
long long r;
while (... | 22 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 22, INF = 1e9 + 22;
int n, m, d;
int dpd[N], dpu[N];
vector<int> G[N];
void dfsd(int v, int p = -1) {
for (int i = 0; i < (G[v].size()); i++) {
int u = G[v][i];
if (u == p) continue;
dfsd(u, v);
dpd[v] = max(dpd[v], dpd[u] + 1);
}
}
v... | 12 |
#include <bits/stdc++.h>
using namespace std;
const long long size = 200007;
const long long modulo = 1000000007;
const int oo = 1e9;
const double EPS = 1e-2;
const double PI = acos(-1.0);
short dp[607][607];
short l[607], r[607];
void f(int st, int fin) {
if (st > fin)
return;
else if (st == fin)
cout << "... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int p[5] = {8, 6, 4, 2, 4}, h[5] = {4, 2, 1, 0, 0};
int i, j, k, n, m;
int f[210][210][5][3], v[210][210][5][3];
long long C[210][210];
inline void A(long long &x, long long y) { x = (x + y) % 1000000007; }
inline long long M(long long x, long long y) { return x * y %... | 19 |
#include <bits/stdc++.h>
using namespace std;
char a[1000005], b[1000005];
int a1, b1;
int main() {
int f = 0, k1 = 0, i;
scanf("%s%s", a, b);
int la = strlen(a);
int lb = strlen(b);
if (la != lb) {
puts("NO");
} else {
for (i = 0; i < la; i++) {
if (a[i] != b[i]) {
if (f == 0)
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int m, n;
while (cin >> m >> n) {
int a[m][n];
int result = 0;
for (int i = 0; i < m; i++) {
int temp = 1000000000;
for (int j = 0; j < n; j++) {
cin >> a[i][j];
if (a[i][j] < temp) {
temp = a[i][j];
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int d;
int n;
int cnt = 0;
cin >> d;
cin >> n;
int a;
for (int i = 0; i < n; i++) {
cin >> a;
cnt += d - a;
}
cnt -= d - a;
cout << cnt;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int n, ans, l = 0, r = 1e9 + 1, ok, cnt, cnt1, idx, idx1;
pair<int, int> p[300005];
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> p[i].first >> p[i].second;
if (l < p[i].first) {
l = p[i].first;
idx = i;
}
if (r > p[i].second) {... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const double EPS = 1e-8;
const double PI = 2 * acos(0);
const int MAXN = 3e5 + 6;
int n;
string s;
int unclose[MAXN], unopen[MAXN];
bool input() {
cin >> n >> s;
return !cin.fail();
}
bool first_check() {
if (s[0] == ')' || s[n - 1] == '(')... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, a, b;
cin >> n >> m;
vector<vector<int> > v(n);
std::vector<int> v1(n, 0);
for (int i = 0; i < m; ++i) {
cin >> a >> b;
v[a - 1].push_back(b - 1);
v1[a - 1]++;
v1[b - 1]++;
v[b - 1].push_back(a - 1);
}
int k = 1;
in... | 4 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.