solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
long long int arr[n];
for (long long int i = 0; i < n; i++) {
cin >> arr[i];
}
for (long long int i = 0; i < n; i++) {
if (arr[i] % 2 == 0) {
cout << arr[i] - 1 << " ";
} else {
cout << arr[i] << " ... | 0 |
#include <bits/stdc++.h>
int main() {
int t, n, m, a, b, p;
while (~(scanf("%d", &n))) {
p = 0;
if (n >= 0)
printf("%d\n", n);
else {
n = -n;
m = n;
a = n % 10;
b = n / 10 % 10;
while (m != 0) {
m /= 10;
p++;
}
if (p == 2) {
if (a =... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
while (cin >> n) {
int a[127543];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int s = 1;
int max = 0;
for (int i = 1; i < n; i++) {
if (a[i] > a[i - 1]) {
s++;
} else
s = 1;
if (s > max... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct fast_ios {
fast_ios() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
};
} fast_ios_;
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
for (auto &x : v) is >> x;
return is;
}
template <typename T... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int a[1001], b[1001];
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) cin >> b[i];
int ans = 0;
for (int i = 0; i < n; i++) {
int x, y;
x = y = 0;
for (int j = i; j < n; j++) {
x = x | a[j];
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
int n, a[maxn], b[maxn], sgmnt[maxn * 10], A[maxn], B[maxn];
void Build(int v = 1, int l = 0, int r = n - 1) {
sgmnt[v] = r - l + 1;
int mid = l + r >> 1;
if (l < r) {
Build(v * 2, l, mid);
Build(v * 2 + 1, mid + 1, r);
}
}
void Del... | 12 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int32_t tests;
cin >> tests;
for (int32_t test = 0; test < tests; test++) {
int64_t a, b;
cin >> a >> b;
if (a < b) {
swap(a, b);
}
if ((a + b) % 3 == 0 && 2 * ... | 5 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define maxn 200005
int fa[maxn];
int n, m;
ll k;
struct node {
int a, b, c;
node(int a = 0, int b = 0, ll c = 0)
:a(a), b(b), c(c) {}
bool operator<(const node& a)const {
return c < a.c;
}
};
int find(int i) {
while (i != fa[i])i = fa[i] = ... | 10 |
#include <bits/stdc++.h>
using namespace std;
double r, h;
int ans, x;
int main() {
cin >> r >> h;
x = (h + r * (1 - sqrt(3) / 2)) / r;
ans = (1 + 2 * x);
if (2 * h >= r) {
x = (2 * h - r) / (2 * r);
ans = max(ans, 2 + 2 * x);
}
cout << ans << endl;
}
| 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
int n, d, mod, inv[N], f[N][11][N];
int main() {
scanf("%d%d%d", &n, &d, &mod), inv[0] = inv[1] = 1;
if (n <= 2) return puts("1"), 0;
for (int i = 2; i < n; ++i)
inv[i] = 1LL * (mod - mod / i) * inv[mod % i] % mod;
f[1][0][0] = f[1][d - 1][0]... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
int n, m, r, c;
double a[N][N], b[N], tmp[N][N];
double f[N];
void init() {
int i, j;
tmp[1][1] = tmp[1][2] = tmp[m][m - 1] = tmp[m][m] = 1.0 / 3;
for (i = 2; i <= m - 1; ++i)
for (j = i - 1; j <= i + 1; ++j) tmp[i][j] = 0.25;
for (i = 1;... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
cout << ((n % 2) ? n / 2 : n / 2 - 1) << endl;
}
| 2 |
#include <bits/stdc++.h>
int main(void) {
int a[14] = {0};
int b[14] = {0};
long long max = 0;
long long temp = 0;
long long cur;
int i, j, k, fp;
for (i = 0; i < 14; i++) {
scanf("%d", &a[i]);
}
for (i = 0; i < 14; i++) {
if (a[i] == 0)
continue;
else {
memcpy(b, a, sizeof(a))... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a[10];
a[1] = "1";
a[2] = "2";
a[3] = "3";
a[4] = "322";
a[5] = "5";
a[6] = "35";
a[7] = "7";
a[8] = "7222";
a[9] = "7332";
long long int n;
scanf("%I64d", &n);
getchar();
string s;
cin >> s;
vector<string> v;
for (long ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m;
cin >> n >> m;
long long arr[n];
for (long long i = 0; i < n; i++) cin >> arr[i];
vector<long long> v;
cout << 0 << " ";
long long sum = arr[0];
v.push_back(arr[0]);
vector<long long> a;
long long c = 0;
for (long long i = ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s;
cin >> n;
if (n == 0) {
return 0;
} else {
cin >> s;
if (!(n % 2)) {
for (int i = 0; i < n; i++) {
cout << s[i];
if (i == n - 1) break;
if (i & 1) cout << '-';
}
} else {
for (... | 3 |
#include <bits/stdc++.h>
using namespace std;
inline void OPEN(const string &s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
vector<pair<pair<int, int>, int> > p;
char cc[405][405];
int main() {
p.clear();
for (int i = 0; i < (3); ++i) {
int l, w;
cin >> l >>... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long arr[100005];
long long n;
bool check() {
for (long long j = 0; j < (n - 1); j++) {
if (abs(arr[j] - arr[j + 1]) != 1) return false;
}
return true;
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long a, b, c, d, i;
cin >> a >> b ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int oo = int(2e9) + 9;
const double eps = 1e-9;
const double pi = 3.14159265358979323846264338327950;
vector<vector<pair<int, int> > > AdjList(100005);
int main() {
int n, m;
cin >> n >> m;
vector<pair<int, int> > dist(100005);
map<pair<int, int>, int> is;
i... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 20;
struct node {
int val[4][4], Add;
node() {
memset(val, 0, sizeof val);
Add = 0;
}
};
node seg[maxn * 4];
int n;
const int zarib[] = {1, -2, 1};
int Z[4][4];
node merge(node a, node b) {
node c = a;
c.Add = 0;
for (int l = 0; l ... | 19 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void Read(T &n) {
char c;
n = 0;
while (!isdigit(c = getchar()))
;
do {
n = n * 10 + c - '0';
} while (isdigit(c = getchar()));
}
const int N = 1E6 + 2;
const int B = 62;
int n;
long long k, a[N];
int ver1[N], ver2[N];
int Tsize, cnt[... | 21 |
#include <bits/stdc++.h>
using namespace std;
string s, t;
long long ans;
int cnt;
int main() {
int n, m;
cin >> n >> m;
if (m == 0 && n != 1 || n * 9 < m) {
cout << "-1"
<< " "
<< "-1";
return 0;
}
if (m == 0 && n == 1) {
cout << 0 << " " << 0;
return 0;
}
while (ans + 9... | 6 |
#include <bits/stdc++.h>
using namespace std;
void read_file(bool outToFile = true) {}
int n, m, h, s, sh;
long double prob(int j) {
long double ret = 1;
for (int t = s - sh; t >= s - sh - n + j + 1; t--) ret *= t;
for (int t = s; t >= s - n + 1; t--) ret /= t;
for (int t = n; t >= n - j + 1; t--) ret *= t;
f... | 8 |
#include <bits/stdc++.h>
using namespace std;
int A;
int GCD(int a, int b) {
if (b == 0) return a;
return GCD(b, a % b);
}
int solve(int b) {
int n = A, sum = 0;
while (n != 0) {
sum += n % b;
n /= b;
}
return sum;
}
int main() {
int sum = 0;
cin >> A;
for (int b = 2; b <= A - 1; b++) {
su... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
const int inf = 0x3f3f3f3f;
int t;
long long n, m, a, b;
long long ans;
int main() {
cin >> t;
while (t--) {
scanf("%lld%lld%lld%lld", &a, &b, &n, &m);
if (a + b < n + m) {
puts("No");
continue;
}
if (a > b) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long perso[100010], bike[100010], n, m, a;
pair<int, int> check2(long long k, long long s) {
long long count = 0, sum = 0;
for (int i = n - k, j = 0; j < k and i < n; j++, i++) {
if (perso[i] >= bike[j]) {
count++;
sum += bike[j];
} else {
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200010 + 1;
int n, m, ans[MAXN];
pair<pair<int, int>, int> box[MAXN];
bool tag[MAXN];
int main() {
int task;
scanf("%d", &task);
for (int oo = 0; oo < task; oo++) {
scanf("%d", &n);
m = (n << 1) - 1;
for (int i = 0; i < m; i++) {
sca... | 17 |
#include <bits/stdc++.h>
using namespace std;
int t[2 * 400];
int main() {
int n;
while (cin >> n) {
vector<pair<int, pair<int, int> > > a;
int j = 1, k = 0;
for (int i = 0; i < (2 * n - 1) * n; ++i) {
int x;
cin >> x;
a.push_back(pair<int, pair<int, int> >(x, pair<int, int>(j, k)));
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int MAXN = 1000006;
pair<int, int> P[4];
int best, x1, x2, d;
pair<int, int> ANS[4];
bool swapped;
int per[4];
int test(int y1, int y2) {
assert(x2 - x1 == y2 - y1);
pair<int, int> S[] = {pair<int, int>(x1, y1), pair<int, int>(x1, y2),
... | 22 |
#include <bits/stdc++.h>
using namespace std;
int a[1005], p[1005], z[1005], d[1005];
inline void dfs(int k, int n) {
d[k] = 1;
if (!n) return;
for (int i = 0; i <= z[n]; ++i) dfs(k + i * n, n - 1);
}
int main() {
int n, x, k = 0, m = 0;
scanf("%d%d", &n, &x), memset(d, 0, sizeof d), memset(p, 0, sizeof p),
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int col[510][510], num[250010], tg[250010], i, j, n, k, x, y, ans, tot, cnt = 0;
int fx[4] = {1, 0, -1, 0}, fy[4] = {0, 1, 0, -1};
char c[510][510];
void dfs(int x, int y, int color) {
if (x < 1 || y < 1 || x > n || y > n || col[x][y] || c[x][y] != '.') return;
++num[co... | 16 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long size = 1e8;
long long MUL(long long a, long long b) {
return ((a % MOD) * (b % MOD)) % MOD;
}
long long ADD(long long &a, long long &b) {
return ((a % MOD) + (b % MOD)) % MOD;
}
long long SUB(long long a, long long b) {
r... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long p, q, n, x, i;
cin >> p >> q >> n;
for (i = 0; i < n; i++) {
cin >> x;
if (q == 0) {
cout << "NO";
return 0;
}
if (x > p / q) {
cout << "NO";
return 0;
} else {
p -= q * x;
x = p;
p =... | 9 |
#define fast ios::sync_with_stdio(false); cin.tie(0)
#define foru(i, k, n) for (int i = k; i < n; i++)
#define ford(i, k, n) for (int i = k; i >= n; i--)
#define pb push_back
#define ff first
#define ss second
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <bitset>
#include <map>... | 13 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, i, a = 0, b = 0, l;
cin >> n;
for (long long i = 0; i < n; i++) {
cin >> l;
if (l == 1)
a++;
else
b++;
}
if (b <= 1) {
while (b--) {
cout << 2 << " ";
}
while (a--) {
cout << 1 << " ";
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 2;
int group[N], n, m, en[N];
vector<int> adj[N];
set<pair<int, int> > s;
int main() {
ios::sync_with_stdio(false);
cin >> n >> m;
for (int i = 0; i < m; i++) {
int v, u;
cin >> v >> u;
v--, u--;
adj[u].push_back(v);
adj[v].push... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e+18;
const double EPS = 1e-9;
const int MOD = 1000000007;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
signed main() {
int n, m, sx, sy, gx, gy;
bool ok[1000][1000] = {};
char field[1000][1000];
cin >> n >> m;
getchar();
for (int i = 0... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long base = 233;
const long long ff = 1e6 + 1;
const long long mod = 1e9 + 7;
const long long inf = 1e17 + 1;
inline long long read() {
long long x;
scanf("%lld", &x);
return x;
}
long long n, x[ff], y[ff];
double K(long long xx, long long xt, long long yy,... | 10 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
using namespace std;
long long n, m, cycle[200005], present[200005], val[200005], par[200005],
cnt = 1, visited1[200005], visited2[200005], visited3[200005];
vector<long long> adj[200005], radj[200... | 13 |
#include <bits/stdc++.h>
using namespace std;
inline long long rd() {
long long x = 0;
bool neg = false;
char c = getchar();
while (c != '-' && (c < '0' || c > '9')) c = getchar();
if (c == '-') neg = true, c = getchar();
while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
if (neg) x = -x;
... | 22 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int arr[4], c = 0;
for (int i = 0; i < 4; i++) {
cin >> arr[i];
}
sort(arr, arr + 4);
for (int i = 0; i < 4; i++) {
if (arr[i] == arr[i + 1])
c++;
else
continue;
}
cout << c;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll mod = 998244353;
const double eps = DBL_EPSILON;
long long fast_pow(long long a, long long n, long long m) {
long long ans = 1;
w... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MN = 5050;
const int MVAL = 2000000000;
struct data {
int t, l, r, d;
};
int a[MN];
int b[MN];
vector<data> query;
int main() {
int n, m;
scanf("%d %d", &n, &m);
int i;
for ((i) = 0; (i) < (int)(n); ++(i)) a[i] = MVAL;
for ((i) = 0; (i) < (int)(m); ++(... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, x, rem[111] = {0}, d = 0;
cin >> n >> k;
for (int i = 0; i < n; ++i) {
cin >> x;
if (rem[(k - x % k) % k])
d += 2, --rem[(k - x % k) % k];
else
++rem[x % k];
}
cout << d;
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
string S;
cin >> S;
int pos = S.find('0');
if (pos == -1) {
cout << S.substr(1);
} else {
cout << S.substr(0, pos);
cout << S.substr(pos + 1);
}
cout << "\n";
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
const int N = 4e4 + 15;
int n, k, a[N], t[N << 3], add[N << 3];
void push(int v) {
add[v << 1] += add[v];
add[v << 1 | 1] += add[v];
t[v << 1] += add[v];
t[v << 1 |... | 14 |
#include <bits/stdc++.h>
using namespace std;
int m, n;
string s;
int f[2001][2001];
int g[2001][2001];
const int base = 1000000007;
void add(int &x, int y) {
x += y;
if (x >= base) x -= base;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin >> n >> m;
n -= m;
ci... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long ih, num, test, x, c;
cin >> test;
while (test--) {
c = 0;
cin >> num;
cin >> x;
long a[num], b[num];
for (ih = 0; ih < num; ih++) cin >> a[ih];
for (ih = 0; ih < num; ih++) cin >> b[ih];
sort(a, a + num);
sort(b, ... | 0 |
#include <bits/stdc++.h>
int main() {
int n, x, i, j, cnt = 0;
scanf("%d", &n);
int a[n];
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
for (i = 0; i < n; i++) {
if (a[i] != a[i + 1]) cnt++;
}
printf("%d", cnt);
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
int main() {
int n, m;
scanf("%d%d", &n, &m);
vector<int> a(n), ans(m, 0);
vector<pair<long long, int>> q(m);
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
for (int i = 0; i < m; i++) {
scanf("%lld", &q[i].first);
q[i].... | 15 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n, m;
bitset<35> s[10];
int c[10];
set<int> correct_bits;
int ans = 0;
bool consistent(bitset<35>& code) {
bool ans = true;
for (int i = 1; i < m; i++) {
ans &= __builtin_popcountll((code ^ s[i]).to_ullong()) + c[i] == n;
}
return ans;
... | 14 |
#include <bits/stdc++.h>
using namespace std;
int n, m, s, t;
vector<vector<int>> edges;
struct QE {
QE(int n, int d) : node(n), dist(d) {}
int node;
int dist;
};
void Load() {
scanf("%d %d %d %d", &n, &m, &s, &t);
edges = vector<vector<int>>(n + 1, vector<int>());
int a, b;
for (int i = 0; i < m; ++i) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int k;
scanf("%d", &k);
int x = pow(2, 17);
printf("%d %d\n", 2, 3);
printf("%d %d %d\n", x ^ k, x, 0);
printf("%d %d %d\n", k, x ^ k, k);
return 0;
}
| 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, i;
cin >> n;
long long k;
vector<long long> a;
long long int sum = 0;
for (i = 0; i < n; i++) {
cin >> k;
a.push_back(k);
}
for (i = 0; i < n; i++) {
sum = sum + a[i] + i * (a[i] - 1);
}
if (count(a.begin(), a.end(),... | 3 |
//xhxh
//LYC_music yyds!
#include<bits/stdc++.h>
using namespace std;
int read()
{
int pos=1,num=0;
char ch=getchar();
while (!isdigit(ch))
{
if (ch=='-') pos=-1;
ch=getchar();
}
while (isdigit(ch))
{
num=num*10+(int)(ch-'0');
ch=getchar();
}
return pos*num;
}
void write(int x)
{
if (x<0)
{
putchar... | 0 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
vector<pair<int, int>> v;
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
v.push_back({a, b});
}
sort(v.begin(), v.end());
vector<pair<int, int>> fin;
int idx = 0;
while (idx < n) {
int curr = v[idx].f... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string a;
cin >> a;
int x = 0, y = 0;
for (int i = 0; i < n; i++) {
if (a[i] == 'U') y++;
if (a[i] == 'D') y--;
if (a[i] == 'L') x--;
if (a[i] == 'R') x++;
}
int sum = n - (abs(x) + abs(y));
cout << sum << endl... | 2 |
#include <bits/stdc++.h>
using namespace std;
char s[1003];
char res[1003];
int n;
int coun[33];
int coun3[33];
int main() {
scanf("%s", s);
scanf("%d", &n);
int i, j;
for (i = 0; s[i]; i++) coun[s[i] - 'a']++;
int coun2 = 0;
for (i = 0; i < 30; i++)
if (coun[i] > 0) coun2++;
if (coun2 > n) {
prin... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long ar1[200010], ar2[200010];
map<long long, long long> M;
map<long long, long long>::iterator it;
int main() {
long long n, m, i, j, two, ans;
while (scanf("%I64d", &n) == 1) {
M.clear();
two = 0;
for (i = 1; i <= n; i++) {
scanf("%I64d", &ar1[i... | 8 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long llinf = (1LL << 62);
const int inf = (1 << 30);
const int nmax = 1e5 + 50;
const int mod = 1e9 + 7;
using namespace std;
int n, i, j;
long long tot, a[nmax], b[nmax];
pair<l... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long int c[200];
int main() {
long long int t;
cin >> t;
long long int a[t], b[t];
vector<pair<long long int, long long int> > vp;
for (long long int i = 0; i < t; i++) cin >> a[i];
for (long long int i = 0; i < t; i++) {
cin >> b[i];
vp.push_back(m... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
if (a < b) a = b;
}
inline void getint(int &first) {
char c;
while (c = getchar(), c > '9' || c < '0')
;
for (fi... | 15 |
#include <bits/stdc++.h>
using namespace std;
int a, b;
int ans;
int main() {
scanf("%d%d", &a, &b);
if (a == b)
puts("infinity");
else {
int x = a - b;
int i = 1;
for (; i * i < x; i++)
if (x % i == 0) {
if (i > b) ans++;
if (x / i > b) ans++;
}
if (i * i == x && i... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, x, y, vx, vy;
bool flagx = false, flagy = false;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
void exgcd(long long a, long long b, long long &x, long long &y) {
if (b == 0) return x = 1, y = 0, void();
exgcd(b, a % b, x,... | 18 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (a == 0) {
return b;
}
return gcd(b % a, a);
}
int main() {
long long a, b, x, y;
cin >> a >> b >> x >> y;
long long g = gcd(x, y);
x /= g;
y /= g;
long long c1 = a / x;
long long c2 = b / y;
long long a... | 2 |
#include <bits/stdc++.h>
using namespace std;
const unsigned long long P = 239017, MaxN = 2100000, INF = 1000000000;
int a, arr[1000000], sum[1000000], have[1000000];
char s[1000000];
int main() {
scanf("%d%s", &a, s);
int len = strlen(s);
for (int i = 0; i < len; ++i) arr[i] = s[i] - '0';
sum[0] = 0;
for (in... | 8 |
#include <bits/stdc++.h>
long long a[30 + 10];
int b[30 + 10];
int k[30 + 10];
int p[30 + 10];
long long deal[30 + 10][30 + 10];
long long ans;
int n, u, r;
void Xor(long long array[]) {
for (int i = 1; i <= n; i++) array[i] = array[i] ^ b[i];
}
void Add(long long array[]) {
long long tmp[30 + 10];
for (int i = 1... | 12 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18 + 5;
const int mod = 1e9 + 9;
const int N = 1e5 + 5;
int a[N], b[N], d[N], locB[N], locA[N];
int main() {
ios_base::sync_with_stdio(false);
int n;
set<pair<int, int> > pos, neg;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long get_arith(long long a, long long b, long long c, long long N) {
long long res = (a / c) * N * (N - 1) / 2 + (b / c) * N;
a %= c;
b %= c;
if (a) res += get_arith(c, (a * N + b) % c, a, (a * N + b) / c);
return res;
}
long long gcd(long long a, long long b... | 19 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100010;
const ll INF = 1e9 + 69;
int n, a[N];
string good;
bitset <N> mul;
void fuck (int ss, int ee) {
int st = ss, en = ee;
while (st <= ee and a[st] == 1) ++st;
while (en >= ss and a[en] == 1) --en;
ll prod = 1;
for (int... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, t, i, j, p;
cin >> t;
while (t--) {
cin >> n;
long long s = 0;
p = n / 2;
for (i = 1;; i = i + 2) {
s = s + (n - i) * p;
p = p - 1;
if (n == i) {
break;
}
}
cout << 4 * s << endl;
}
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a;
cin >> a;
for (int i = 0; i < a; ++i) {
int b, c;
cin >> b >> c;
int d[b];
int u[b];
int e[c];
for (int j = 0; j < b; ++j) {
cin >> d[j];
u[j] = d[j];
}
for (int k = 0; k < c; ++k) cin >> e[k];
int jk... | 4 |
#include <bits/stdc++.h>
using namespace std;
int Input() {
char c = getchar();
int x = 0, z = 1;
for (; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1;
for (; c >= '0' && c <= '9'; c = getchar())
x = (x << 1) + (x << 3) + (c ^ 48);
return x * z;
}
const int mod(1e9 + 7);
const int maxn(1005);
i... | 18 |
#include <bits/stdc++.h>
int main() {
int l, a, p, c, i, j, k;
scanf("%d%d%d", &l, &a, &p);
i = l * 4;
j = a * 2;
if (i <= j && i <= p)
c = l * 7;
else if (j <= i && j <= p && a >= 2) {
if (j % 2 == 0)
j = a / 2;
else
j = (a - 1) / 2;
c = j * 7;
} else if (p <= i && p <= j && p... | 0 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long i = 1;
while (true) {
cout << "? " << i << " " << 2 * i << endl;
string ans;
cin >> ans;
if (ans == "x") {
break;
}
i *= 2;
}
long long l = i;
long long r = 2 * i;
while (l + 1 < r) {
long long s = (l + ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const long long oo = 1e9 + 7;
int main() {
double a, x1, y1, b, c, d, x, y, f;
int i;
cin >> a >> b >> c >> d;
x = a / b;
y = c / d;
x1 = x;
y1 = (1 - x) * (1 - y);
f = x1;
for (i = 0; i < 10000; i++) {
f = x1 + y1 * f;
}
cout << fixed << setprecis... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long bit[100010], arr[100010], dp[100010][12];
void update(long long val, int idx, int n) {
for (; idx <= n; idx += idx & -idx) bit[idx] += val;
}
long long query(int idx) {
long long sum = 0;
for (; idx > 0; idx -= idx & -idx) sum += bit[idx];
return sum;
}
in... | 11 |
#include <bits/stdc++.h>
using namespace std;
bitset<2002> affect[2000 + 1];
pair<int, int> snake[2000 + 1];
int C[2000 + 1][2000 + 1];
int bonus[2000 + 1];
int range[2000 + 1];
int N, M, R;
void Precalc() {
for (int i = 0; i <= 2000; i++) C[i][0] = 1;
for (int i = 1; i <= 2000; i++)
for (int j = 1; j <= i; j++... | 15 |
#include <bits/stdc++.h>
using namespace std;
void speed_up() {
ios::sync_with_stdio(0);
cin.tie(0);
}
void Inp_Out() {}
void leftrotate(string &s, int d) {
reverse(s.begin(), s.begin() + d);
reverse(s.begin() + d, s.end());
reverse(s.begin(), s.end());
}
void rightrotate(string &s, int d) { leftrotate(s, s.l... | 2 |
#include <bits/stdc++.h>
using namespace std;
int an;
map<string, int> H;
bool is_alpha(char c) { return c >= 'A' && c <= 'Z'; }
void f(char s[], int &offset) {
if (s[offset] == 0) return;
int i;
char name[16];
for (i = offset; is_alpha(s[i]); i++)
;
strncpy(name, s + offset, i - offset);
name[i - offse... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e3 + 5;
int root[MAX_N];
int sz[MAX_N];
int find(int u) {
if (root[u] != u) {
root[u] = find(root[u]);
}
return root[u];
}
void merge(int u, int v) {
u = find(u);
v = find(v);
if (u == v) return;
sz[u] += sz[v];
root[v] = u;
}
int pair... | 7 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double eps = 1e-12;
const int inf = 2000000000;
const long long int infLL = (long long int)2e18;
long long int MOD = 998244353;
int MOD1 = 1000000007;
int MOD2 = 1000000009;
inline bool checkBit(long long int n, long long int i) {
return ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 105;
struct Node {
int val, d, id;
Node() {}
Node(int a, int b, int c) : val(a), d(b), id(c) {}
bool operator<(const Node &n) const {
if (val != n.val) return val > n.val;
return id < n.id;
}
};
int n;
Node arr[MAXN];
bool vis[MAXN];
int m... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5000;
int mod, fact[N], c[N], phi, prc[N], pwra[N];
int rev(int x) {
int pwr[40];
pwr[0] = x;
for (int i = 1; i < 35; i++) {
pwr[i] = (pwr[i - 1] * 1ll * pwr[i - 1]) % mod;
}
int res = 1, v = phi - 1;
for (int j = 30; j >= 0; j--) {
i... | 14 |
#include <bits/stdc++.h>
int read() {
register int x = 0;
register char f = 1, ch = getchar();
for (; !isdigit(ch); ch = getchar())
if (ch == '-') f ^= 1;
for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ '0');
return f ? x : -x;
}
int n, m, cnt, tot;
struct node {
int u, v, t, k;
bo... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
vector<int> h(10);
for (int i = 0; i < s.size(); i++) {
if (s[i] == 'L') {
for (int i = 0; i < 10; i++) {
if (h[i] == 0) {
h[i] = 1;
break;
}
}
} else if (s... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long INF = 1e18 + 10;
long long MOD = 1000000009;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string a, b;
cin >> a >> b;
int n = a.length();
int pref[n];
memset(pref, 0, sizeof pref);
for (long long i = 0; i < n; i++)
if (a[i] == ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int fun(int num, int b) {
if (num == 0) return 0;
return 1 + fun(num / b, b);
}
int main() {
int n1, n2, num, b;
string str, str2;
cin >> n1 >> n2;
num = n1 + n2;
stringstream ss, ss1, ss2;
ss << n1 << n2;
str = ss.str();
vector<int> vec;
for (int i = ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
inline void cmin(int &x, int y) {
if (y < x) x = y;
}
inline void cmax(int &x, int y) {
if (y > x) x = y;
}
using namespace std;
const int N = 2010;
bool vis[N][10][10000];... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int main() {
double x, y;
cin >> x >> y;
x = y * log(x) - x * log(y);
cout << (x > 0 ? ">" : x != 0 ? "<" : "=");
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> v[108];
int n, i, j;
for (i = 0; i < 108; i++) v[i].resize(108);
vector<int> in(108);
scanf("%d", &(n));
;
for (i = 0; i < n; i++) scanf("%d", &(in[i]));
;
for (i = 0; i < n; i++)
for (j = 0; j < in[i]; j++) scanf("%d", &(v[i][... | 1 |
#include <bits/stdc++.h>
using namespace std;
void faster() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
if (0) {
freopen(
"input"
".in",
"r", stdin);
freopen(
"input"
".out",
"w", stdout);
}
}
int n, a[1001], s = 0, cnt = 0;
void solve... | 0 |
#include <bits/stdc++.h>
using namespace std;
void c_inp() {}
int32_t main() {
c_inp();
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
long long arr[n];
for (long long i = 0; i < n; ++i) {
cin >> arr[i];
}
lo... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 218;
const int MAXM = 3200;
const long long MOD = 1000000007LL;
int a[MAXN], b[MAXN];
long long dp[MAXM][MAXN];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; ++i) {
scanf("%d%d", &a[i], &b[i]);
++dp[a[i]][i];
if (a[i... | 10 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cout << *it << " = " << a << "\n";
err(++it, args...);
}
const lo... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1010, MOD = 1e9 + 7;
long long c[MAXN][MAXN];
int main() {
for (int i = 0; i <= 1005; i++) {
c[i][0] = c[i][i] = 1;
for (int j = 1; j < i; j++) {
c[i][j] = ((c[i - 1][j] % MOD) + (c[i - 1][j - 1] % MOD)) % MOD;
}
}
int n, m, k;
cin... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n,cnt;
long long ans,c[400010];
struct tree
{
int l,r;
long long mx1,mx2;
}tr[2000010];
struct node
{
long long a,b;
}a[200010];
inline void build(int rt,int l,int r)
{
tr[rt].l=l;
tr[rt].r=r;
tr[rt].mx1=0;
tr[rt].mx2=0;
if(l==r)
return;
int mid=(l+r)>>1;
bu... | 17 |
#include <bits/stdc++.h>
using namespace std;
int x, t, a, b, da, db, q[100009], w[100009], l, k;
int main() {
cin >> x >> t >> a >> b >> da >> db;
if (x == 0) {
cout << "YES";
return 0;
}
for (int i = 0; i < t; i++) {
q[i] = a;
w[i] = b;
a -= da;
b -= db;
if (q[i] == x || w[i] == x)... | 4 |
#include <bits/stdc++.h>
using namespace std;
char str[51234];
int L[51234][123];
int P[51234][27];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> str;
n = strlen(str);
for (int i = 0; i < 26; ++i) {
int w = n;
P[n][i] = 0x3f3f3f3f;
for (int j = n - 1; j >= 0; --j) {
... | 11 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x) {
x = 0;
char c = getchar();
bool p = 0;
for (; c < '0' || c > '9'; c = getchar())
if (c == '-') p = 1;
for (; c >= '0' && c <= '9'; c = getchar())
x = (x << 3) + (x << 1) + (c ^ 48);
if (p) x = -x;
}
int n;
const in... | 26 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.