solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
int k, a, b;
cin >> k >> a >> b;
int p = a / k;
int q = b / k;
if (a < k && b < k || p == 0 && b % k != 0 || q == 0 && a % k != 0)
cout << -1;
else {
cout << p + q;
}
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
long long n;
long long a[maxn << 1];
int main() {
scanf("%lld", &n);
for (int i = 1; i <= 2 * n; i++) {
scanf("%lld", &a[i]);
}
sort(a + 1, a + 2 * n + 1);
long long ans = (a[2 * n] - a[n + 1]) * (a[n] - a[1]);
for (long long i = 2;... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int l[112345], r[112345], q[112345];
int prefix[31][112345], s[31][112345], cnt[31][112345];
int main() {
ios_base::sync_with_stdio(false);
cin >> n >> m;
for (int i = 0; i < m; ++i) cin >> l[i] >> r[i] >> q[i];
for (int i = 0; i < m; ++i) {
for (int b... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int M = 1e5;
map<int, int> mp;
int num[M + 50];
char str[M + 50];
int main() {
int n;
scanf("%d", &n);
scanf("%s", str + 1);
memset(num, 0, sizeof(num));
for (int i = 1; i <= n; i++) {
int t;
if (str[i] == '0')
t = -1;
else
t = 1;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int cmp();
int a[100005][3];
int p[105];
int main() {
int n, q;
while (~scanf("%d%d", &n, &q)) {
memset(p, 0, sizeof(p));
for (int i = 1; i <= q; ++i) scanf("%d%d%d", &a[i][0], &a[i][1], &a[i][2]);
int ans = 0, f = 0;
for (int i = 1; i <= q; ++i) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
int dx[] = {0, 0, 1, -1, 1, -1, 1, -1}, dy[] = {-1, 1, 0, 0, 1, -1, -1, 1};
int n, k;
vector<int> adj[101], adj2[101];
const ll mod = 1e9 + 7;
void dfs(int x, int from = -1) {
for (int y : adj[x])
if (y != from) {
ad... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 + 2;
int n;
string s;
void solve() {
bool ok = false;
for (int len = 1; len < (int)s.length(); ++len) {
for (int i = 0; i + len - 1 < (int)s.size(); ++i) {
int cnt = 0;
for (int j = i; j < s.size(); j += len) {
if (s[j] == '.... | 5 |
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
int visitados = 0;
bool flag = 0;
bool flag1 = 1;
void dfs(int u, vector<vector<int>> &g, vector<bool> &seen) {
seen[u] = 1;
visitados++;
flag = 0;
for (int v : g[u]) {
if (!seen[v] && flag1) {
flag = 1;
dfs(v, g, seen);
}... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
int a[maxn];
int main() {
int n, k;
scanf("%d%d", &n, &k);
int sum = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
int i;
for (i = 0; i < n; i++) {
if (a[i] <= k) {
sum++;
} else {
break;
}
}
if (i... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > adj[102];
set<int> s;
bool vis[102];
int des;
void dfs(int u, int path) {
if (u == des) {
s.insert(path);
return;
}
if (vis[u]) {
return;
}
vis[u] = true;
for (int i = 0; i < adj[u].size(); i++) {
int v = adj[u][i].first, ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
const int MOD = 1000000007;
int dp[N][N], a[N];
int main() {
int n, k;
scanf("%d %d", &n, &k);
k--;
int ans = 1;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
if (!a[i]) {
ans = (ans * 2) % MOD;
}
}
int ma = (1 << k) -... | 12 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:167772160000")
using namespace std;
void redirectIO() {
ios::sync_with_stdio(false);
cin.tie(0);
}
const int maxT = 1000000;
long long sum[4100000];
long long maxDif1[4100000];
long long maxDif2[4100000];
void recalc(int a, int beg, int end) {
maxDif1[a] = ... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int maxN(1e5 + 11);
typedef int i_N[maxN];
int N, lim, p, q;
long long M, S[maxN];
pair<int, int> A[maxN];
i_N B;
int main() {
scanf("%d %d %d %d %I64d\n", &N, &lim, &p, &q, &M);
for (int i = 1; i <= N; i++) {
int x;
scanf("%d", &x);
A[i] = pair<int, i... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long n, p[200000], tosolve[20000];
long long moves[20000];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) cin >> p[i];
tosolve[1] = 2;
moves[1] = 2;
for (int i = 2; i <= n; i++) {
for (int j = p[i]; j < i... | 8 |
#include <bits/stdc++.h>
using namespace std;
typedef struct _Query {
int id, qLeftPt, qRightPt;
bool operator<(const struct _Query& snd) const {
if (qLeftPt != snd.qLeftPt) return qLeftPt > snd.qLeftPt;
return qRightPt > snd.qRightPt;
}
} Query;
Query qArr[1000010];
int arr[1000010], pos[1000010], len, q... | 17 |
#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
std::cerr... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 300300;
int n, q, last[N], fre[N], su[N];
queue<pair<int, int> > u;
vector<pair<int, int> > v, z;
vector<int> bad;
map<int, int> ma;
int main() {
if (fopen("C.in", "r")) freopen("C.in", "r", stdin);
cin >> n >> q;
for (int t, x, i = 0; i < q; i++) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int arr[5010];
int n;
int awl[5010];
int a5er[5010];
long long dp[5010];
long long solve(int idx) {
if (idx > n) return 0;
long long &ret = dp[idx];
if (ret != -1) return ret;
ret = -1e9;
ret = max(ret, solve(idx + 1));
vector<bool> vis(5005);
int ans = 0;
i... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1000;
int a[N][N], n, m, ans;
int main() {
cin >> n >> m;
for (long long i = 0; i < n; i++) {
for (long long j = 0; j < 2; j++) {
cin >> a[i][j];
}
}
long long d = 0;
for (long long i = 0; i < n; i++) {
for (long long j = 0; j... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
int m, v, t1, t2, t3, t4;
t1 = a / 250;
t2 = b / 250;
t1 = t1 * c;
t2 = t2 * d;
t1 = a - t1;
t2 = b - t2;
t3 = 3 * a / (10);
t4 = 3 * b / (10);
m = max(t3, t1);
v = max(t4, t2);
if (m > v) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char **argv) {
ifstream from;
const long long nmin = 1, nmax = 1000;
long long n, m, res, rt, i, j, k, ax, x;
char ch;
string s, st;
if (0) from.open("test.txt");
vector<string> vs;
n = m = rt = ax = 0;
st = "";
while (cin.get(ch)) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long n, p;
int main() {
while (~scanf("%lld%lld", &n, &p)) {
printf("%.0f\n", log2(p & (-p)) + 1);
}
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
int n, s[200005], a[200005], ans[200005], pos;
int main() {
ios::sync_with_stdio(false);
int T;
cin >> T;
while (T--) {
memset(s, 0, sizeof s);
memset(a, 0, sizeof a);
memset(ans, 0, sizeof ans);
cin >> n;
s[0] = 0;
for (int i = 1; i <= n; i+... | 5 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> v[123456];
long long rev[123456];
bool ishotel[123456];
long long N;
vector<long long> start;
vector<long long> ans;
vector<long long> temp;
long long vis[123456];
void dfs(long long node, long long now) {
vis[node] = now;
long long i, j;
if (v[node]... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int size = 50 + 10;
long long a[size], b[5], res[size];
int main() {
int(N);
scanf("%d", &N);
for (int i = 0; i < (N); ++i) cin >> a[i];
for (int i = 0; i < (5); ++i) cin >> b[i];
long long tot = 0;
for (int i = 0; i < (N); ++i) {
tot += a[i];
for ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 11, MSK = 1 << 5;
bool dp[N << 1][N][N][N][N][N][32];
char res[N][N << 1];
int n, m, a[N], b[N << 1], bl[32][32][6];
char par[N << 1][N][N][N][N][N][32], cntbl[32];
inline int calc(int msk) {
int ted = 0;
bool bb = 0;
for (int i = 0; i < n; i++) {
if... | 16 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int N = 3e5 + 7, mod = 1e9 + 7;
const int inf = N;
int n, m, q;
int fat[N], cen[N], toll[N];
vector<int> adj[N];
inline int find(int x) { return fat[x] = (x == fat[x] ? x : find(fat[x])); }
void link(int u, int v) {
u = ... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n, a[300005], b[300005], ans = 1, ex;
int main() {
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
cout << "1 ";
ex = n;
for (int i = 0; i < n; i++) {
b[a[i]] = 1;
if (a[i] == ex) {
while (b[ex]) ex--, ans--;
ans++;
cout << ans << ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int m[200020], x, i, n;
vector<int> a[200020];
int main() {
cin >> n;
for (i = 1; i <= n; i++) {
cin >> x;
a[x].push_back(i);
}
x = 0;
while (--i) {
while (x >= 0 && a[x].empty()) {
x -= 3;
}
if (x < 0) {
cout << "Impossible";
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
int main() {
int n, ax[5], ay[5], bx[5], by[5];
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d%d%d%d", ax + i, ay + i, bx + i, by + i);
int mask = (1 << n) - 1;
for (int s = 1; s <= mask; s++) {
int AX = INF, AY = INF, BX = ... | 7 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int r1, r2, c1, c2, d1, d2;
cin >> r1 >> r2 >> c1 >> c2 >> d1 >> d2;
for (int i = 1; i < 10; i++) {
for (int j = 1; j < 10; j++) {
if (i + j == r1 && i != j) {
for (int k = 1; k < 10; k++) {
if (i + k == c1 && k + j == d2 && ... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long f[2010][2010];
long long ddd = 998244353;
int main() {
for (int i = 0; i < 2010; i++) {
f[0][i] = 1;
for (int j = 1; j < i; j++) {
f[j][i] = (f[j - 1][i - 1] + f[j][i - 1]) % ddd;
}
f[i][i] = 1;
}
int n;
int m;
int k;
cin >> n >> ... | 7 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using dd = long double;
namespace {
static bool constexpr dbg = 0;
ll constexpr N = 1.1e6, M = 1.1e3;
ll n, m, d[N + 9];
bool dp[M + 9][M + 9];
void init() {
cin >> n >> m;
for (ll i = 1; i <= (ll)(n); ++i) cin >> d[i];
}
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 101;
int f[maxn][maxn * maxn];
int n, a[maxn];
map<int, int> b;
int ans;
vector<pair<int, int> > v;
int main() {
while (cin >> n) {
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
b[a[i]]++;
}
f[0][0] = 1;
for (auto p : b) v... | 13 |
#include <bits/stdc++.h>
using namespace std;
int adj[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
int coradj[4][2] = {{1, 1}, {-1, 1}, {-1, -1}, {1, -1}};
int alladj[8][2] = {{1, 1}, {0, 1}, {-1, 1}, {-1, 0},
{-1, -1}, {0, -1}, {1, -1}, {1, 0}};
int gcd(int a, int b) { return ((b) ? gcd(b, a % b)... | 9 |
#include <bits/stdc++.h>
using namespace std;
ifstream in("in.in");
ofstream out("out.out");
int dp[5005][5005], n, m;
bool v[5005][5005];
char x[5005], y[5005];
int solve(int n, int m) {
if (v[n][m] == 1) return dp[n][m];
v[n][m] = 1;
dp[n][m] = max(dp[n][m], 0);
dp[n][m] = max(dp[n][m], solve(n - 1, m) - 1);
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int l[200000];
int m[200000];
int m1[200000];
int m2[200000];
int main() {
for (int i = 0; i < 200000; i++) {
l[i] = 0;
m[i] = 0;
m1[i] = 0;
m2[i] = 0;
}
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) l[i] = 2;
l[1] = 1;
l[n] = 1;
for ... | 7 |
#include <bits/stdc++.h>
using namespace std;
void inv(long long a, long long b, long long &x, long long &y) {
if (a == 0) {
x = 0;
y = 1;
return;
}
inv((b % a), a, x, y);
long long z = x;
long long zz = y;
x = zz - (b / a) * z;
y = z;
}
int n;
const int MAXN = 300005;
int c[MAXN];
char s[MAXN... | 16 |
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, unsigned long long int y,
long long int p) {
long long int res = 1;
x = x % p;
if (x == 0) return 0;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}... | 14 |
#include <bits/stdc++.h>
using namespace std;
void OJ() {}
int solve() {
long long int n, l, a;
cin >> n >> l >> a;
long long int q = 0, t = 0;
while (n--) {
long long int m, c;
cin >> m >> c;
if ((m - t) >= a) q += (m - t) / a;
t += (m - t);
t += c;
}
q += (l - t) / a;
cout << q;
re... | 2 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b > 0 ? gcd(b, a % b) : a; }
const int INF = 1 << 27;
int n, m;
set<int> bad;
int isBad(int t) {
if (t == 1) return 0;
return bad.count(t) ? -1 : 1;
}
int f(int t) {
if (t == 1) return 0;
int p = 0;
for (int j = 2; j * j <= t;) {
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long mini = 1000 * 1000 * 1000;
long long ans = 0;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
long long tmp = 0;
cin >> tmp;
ans += tmp;
if (tmp % 2 == 1) mini = min(mini, tmp);
}
if (ans % 2 == 0) {
cout << ans;
} e... | 1 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n;
cin >> n;
long long arr[n];
for (int i = 0; i < n; i++) cin >> arr[i];
long long ans = arr[0];
for (int i = 1; i < n; i++) ans &= arr[i];
cout << ans << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.t... | 1 |
#include <bits/stdc++.h>
int main() {
int n;
int j = 0;
scanf("%d", &n);
int arr[n];
for (int i = 2; i <= n; i++) {
arr[i] = 0;
}
for (int i = 2; i <= n; i++) {
if (arr[i] == 0) {
j = i + i;
} else {
continue;
}
while (j <= n) {
arr[j] += 1;
j += i;
}
}
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MN = 100100;
const double EPS = 1e-9;
vector<pair<int, int> > res;
long long a[MN], b[MN], c[MN];
bool near(pair<double, double> x, pair<double, double> y) {
pair<double, double> z =
pair<double, double>(x.first - y.first, x.second - y.second);
return sq... | 20 |
#include <bits/stdc++.h>
using namespace std;
int a[100006];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
int maxx = 0, minn = 1000005;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] <= 500000 && a[i] >= maxx)
maxx = a[i];
else if (a[i] >= 500000 && a[i] <= m... | 3 |
#include <bits/stdc++.h>
using namespace std;
int read() {
char ch = getchar();
int x = 0, pd = 0;
while (ch < '0' || ch > '9') pd ^= ch == '-', ch = getchar();
while ('0' <= ch && ch <= '9') x = x * 10 + (ch ^ 48), ch = getchar();
return pd ? -x : x;
}
const int maxn = 300005;
int n, m, N;
bool cg[22];
long ... | 16 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int maxn = 1e5 + 9;
const int inf = 0x3f3f3f3f;
char x[maxn];
int ct[30][30];
long long dp[maxn * 11];
int main() {
int n, m;
scanf("%d%d%s", &n, &m, x);
int len = strlen(x);
for (int i = 1; i < len; i++) {
ct[x[i] - 'a'][x[i... | 14 |
#include <bits/stdc++.h>
using namespace std;
bool dp[500010];
int main() {
int n, d;
cin >> n >> d;
vector<int> c(n);
for (int i = int(0); i <= int((n)-1); i++) cin >> c[i];
dp[0] = true;
for (int i = 0; i < n; i++) {
for (int j = 500001; j >= 0; j--) {
if (dp[j]) dp[j + c[i]] = true;
}
}
... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long q;
long double t = 0, y = 0, w;
cin >> q >> w;
deque<long double> a;
for (int x = 0; x < q; x++) {
long double r;
cin >> r;
a.push_back(r);
if (a[x] == 0) {
t++;
}
if (a[x] == w) {
y++;
}
}
sort(a.... | 4 |
#include <bits/stdc++.h>
using namespace std;
int rev_bin(int a) {
int ans = 0;
for (int i = 0; i < 8; i++) {
ans <<= 1;
ans |= 1 & a;
a >>= 1;
}
return ans;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
string s;
getline(cin, s);
s = char(0) + s;
int n = s.... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long f[55][2][2], K, d;
int a[55], n;
long long C(int l, int r, int x, int y) {
if (l > r) return 1;
long long& F = f[l][x][y];
if (~F) return F;
F = 0;
for (int i = 0; i <= 1; ++i)
for (int j = 0; j <= 1; ++j)
if (a[l] - !i && a[r] - !j && (l < r |... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e8;
int n, m;
int main() {
cin >> n >> m;
if (n - m > m - 1)
cout << m + 1 << endl;
else if (n - m <= m - 1 && n > 1)
cout << m - 1 << endl;
else
cout << "1" << endl;
return 0;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
int belong[205], Count[205], n;
int ina, inb;
struct node {
int pos, val;
} e[205];
int cmp(const node &a, const node &b) { return a.val < b.val; }
void work(int m, int a, int b) {
int i, c = 0, flag1 = 0, flag2 = 0;
for (i = 1; i <= 2 * n; i++) {
if (e[i].val == ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1001;
const int mod = 1e9 + 7;
long double ans, dp[N][N], all, cnk[N][N];
int n, a[N], m, h;
int main() {
ios_base::sync_with_stdio(0);
cin >> n >> m >> h;
for (int i = 0; i <= 1000; i++) {
cnk[i][i] = cnk[i][0] = 1;
for (int j = 1; j < i; j++) c... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int block_size = 320;
const long long mod = 1e9 + 7;
const long double eps = 1e-9;
const int inf = mod;
const double PI = atan(1) * 4;
template <typename T>
inline int sign(const T &a) {
if (a < 0) return -1;
if (a > 0) return 1;
return 0;
}
template <typename T... | 13 |
#include <bits/stdc++.h>
using namespace std;
namespace IO {
void setIn(string s) { freopen(s.c_str(), "r", stdin); }
void setOut(string s) { freopen(s.c_str(), "w", stdout); }
void setIO(string s = "") {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin.exceptions(cin.failbit);
if (s.size()) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
pair<int, int> a[101];
int main() {
scanf("%d%d", &n, &k);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i].first);
a[i].second = i;
}
sort(a, a + n);
int minn = a[n - 1].first - a[0].first;
int minmove = 0;
vector<pair<int, int>> moves;
for... | 6 |
#include <bits/stdc++.h>
using namespace std;
int N, L, R, X, A[16], Z, l, r, x, C, S;
int main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
cin >> N >> l >> r >> x;
for (int i = 0; i < N; i++) cin >> A[i];
Z = (1 << N);
for (int i = 0; i < Z; i++) {
L = 1e9;
R = 0;
S = 0;
if... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxv = 50010;
const int maxn = 50010;
#pragma warning(disable : 4996)
int T;
string S;
void solve() {
if (S.length() == 1) {
cout << stoll(S) - 1 << endl;
return;
}
string a = "", b = "";
for (int i = 0; i < S.length(); i++) {
if (i % 2)
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 10;
long long PI = acos(-1.0), MOD = 1000000007;
long long n, m, x, y, z, k, sum, ans, l, r, xx, yy, t;
vector<pair<long long, pair<long long, long long>>> v;
vector<long long> v1;
vector<pair<long long, long long>> v2;
vector<pair<long long, long ... | 8 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void init(T& x) {
x = 0;
char ch = getchar();
bool t = 0;
for (; ch > '9' || ch < '0'; ch = getchar())
if (ch == '-') t = 1;
for (; ch >= '0' && ch <= '9'; ch = getchar())
x = (x << 1) + (x << 3) + (ch - 48);
if (t) x = -x;
re... | 24 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const long double eps = 1e-9;
const long double pi = acos(-1.0);
int xabs(int x) { return x < 0 ? -x : x; }
struct see {
int t, l, r;
see() {}
see(int t, int l, int r) : t(t), l(l), r(r) {}
};
int sign(int x) {
if (x == 0) return 0;
return x <... | 11 |
#include <bits/stdc++.h>
using namespace std;
void debug_out() { cout << ']' << '\n'; }
template <typename T, typename... R>
void debug_out(const T &ff, const R &...rr) {
cout << ff;
if (sizeof...(R)) {
cout << ", ";
}
debug_out(rr...);
}
mt19937_64 rang(
chrono::high_resolution_clock::now().time_since_... | 3 |
// did we make our happiness costly or we are greedy
#include<bits/stdc++.h>
using namespace std;
//faster
#define faster \
ios_base::sync_with_stdio(false);\
cin.tie(NULL); \
cout.tie(NULL); \
cerr.tie(NULL);
#define LL ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
pair<int, int> king, r[667];
int k;
bool oc[1002][1002];
for (int i = 1; i < 1000; i++)
for (int j = 1; j < 1000; j++) oc[i][j] = false;
cin >> king.first >> king.second;
for (int i = 1; i <= 666; i++) {
cin >> r[i].first >> r[i].second;
... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t = 1;
cin >> t;
while (t--) {
long long n;
cin >> n;
if (n == 2) {
cout << fixed << setprecision(9) << (double)1 << endl;
continue;
}
double deg = (double)360 / (4 * n);
cout << fixed << setprecision(9)
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int i, j, k, rest, n;
char ch, ch1;
cin >> n >> k;
rest = n - k;
ch = 'a';
for (i = 0; i < k; i++) {
cout << ch;
ch += 1;
}
ch1 = 'a';
for (i = 0, j = 1; i < rest; i++, j++) {
cout << ch1;
ch1 += 1;
if (j == k) {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-6;
const int N = 1 << 17;
int a[N], L[N], R[N];
int main() {
int n, q;
while (~scanf("%d%d", &n, &q)) {
for (int i = 1; i <= n; i++) scanf("%d", a + i);
for (int i = n; i; i--) a[i] = abs... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, d;
cin >> n >> m >> d;
pair<long long, long long> ta[300];
long long bs = 0;
for (int i = 0; i < m; i++) {
int a, b, t;
cin >> a >> b >> t;
ta[i] = make_pair(t, a);
bs += b;
}
sort(ta, ta + m);
long long slope[700] = {0... | 13 |
#include<bits/stdc++.h>
using namespace std;
struct node{
node *succ[2];
bool flag;
int id[2],head;
int val[2];
} vett[1000005];
node* cont=vett;
node* getnode(int x){
node *tmp=cont;
tmp->flag=false;
tmp->id[0]=tmp->id[1]=-1;
tmp->head=x;
tmp->val[0]=tmp->val[1]=0;
tmp->succ[0]=tmp->succ[1]=NULL;
cont++;
... | 23 |
#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
const int N = 1e5 + 5;
long long int n;
long long int a[N];
long long int cnt[N];
bool check(long long int m) {
priority_queue<pair<long long int, long long int>> q;
for (long long int i = 0; i <= n; ++i) cnt[i] = 0;
for (long long int i = 0; i ... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long dp[1000005], F[10];
int k, _10[] = {1, 10, 100, 1000, 10000, 100000}, q;
int N = 999999;
int main() {
scanf("%d", &k);
memset(dp, -0x3f, sizeof(dp));
dp[0] = 0;
for (int i = 0; i <= 5; i++) {
scanf("%lld", &F[i]);
long long rest = (k - 1) * 3;
... | 21 |
#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 5;
const int MAXN = 3e6;
const int M = 1e7;
const long long inf = 1e18;
const int mod = 1e9 + 7;
mt19937_64 rnd(chrono::system_clock::now().time_since_epoch().count());
template <typename T>
void vout(T s) {
cout << s << endl;
exit(0);
}
vector<int> ... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, k, m, opt, x, y, cnt, a[15][N];
bitset<5000> s[N];
struct node {
int val, id;
friend bool operator<(node a, node b) { return a.val > b.val; }
};
int main() {
scanf("%d%d%d", &n, &k, &m);
cnt = k;
for (int i = 1; i <= k; i++) {
for... | 21 |
#include <bits/stdc++.h>
using namespace std;
const long long M = 30001;
long long a[30001], f[30001][700], n, d;
bool used[30001][501];
long long solve(long long x, long long y) {
if (x >= M) return 0;
if (used[x][y]) return f[x][y];
used[x][y] = true;
long long res;
if (y == 1) {
res = a[x] + max(solve(... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 214514;
struct edge {
int v, nt;
long long w;
} e[N << 1];
set<int> tr[N], s;
set<pair<int, int>> id;
int hd[N], sz[N], rt[N];
int n, k, w = 1e9, tot, po, ct;
long long kkr;
void add(int x, int y, int z) {
e[++tot] = {y, hd[x], z};
hd[x] = tot;
}
void ... | 23 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n = 0, temp = 0;
cin >> n;
if (n > 0 && n < 10)
temp = n;
else if (n > 9 && n < 100)
temp = 9 + 2 * (n - 9);
else if (n >= pow(10, 2) && n < pow(10, 3))
temp = 9 + 2 * (90) + 3 * (n - 99);
else if (n >= pow(10, 3) && n < po... | 4 |
#include <bits/stdc++.h>
using namespace std;
int a[11111], n = 0, l1, r1, l2, r2, pl, pr, vl, vr, k;
long long prob = 0;
void rec(int x, int k) {
a[++n] = x;
if (k == 9) return;
rec(x * 10 + 4, k + 1);
rec(x * 10 + 7, k + 1);
}
long long f(int a, int b, int c, int d) {
a = ((a) > (c) ? (a) : (c));
b = ((b)... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, k, mid;
long long S;
long long bit[30];
int ans = 1;
int a[30];
map<pair<int, long long>, long long> mark;
struct point {
int x;
long long y;
} t[1594324];
void dfs1(int x, int y, long long all) {
if (all > S || y > k) return;
if (x == mid + 1) {
t[ans].x... | 13 |
#include <bits/stdc++.h>
int main() {
long long int i, n, sum = 0;
char s[101];
scanf("%lld", &n);
scanf("%s", s);
for (i = 0; i < n; i++) {
if (s[i] == '-') {
if (sum == 0)
sum = 0;
else
sum--;
} else if (s[i] == '+')
sum++;
}
printf("%lld\n", sum);
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
bool isprime(long long n) {
long long i;
for (i = 2; i <= sqrt(n); i++)
if (n % i == 0) return false;
return true;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
if (fopen("inp.txt", "r")) {
freopen("inp.txt", "r", stdin);
freopen("outp.t... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
vector<long long> out[N];
long long indeg[N], outdeg[N];
long long _sqrt = 350;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n, m;
cin >> n >> m;
long long sal[n];
for (long long i = 1; i <= n; i++) sal[i] ... | 16 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const long long mod = 998244353;
vector<vector<long long> > v;
long long n;
long long step[300000];
void init() { v.resize(n); }
long long dfs(long long ver, long long pr = -1) {
long long all = 1;
for (auto to : v[ver]) {
if (to == pr) c... | 11 |
#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cer... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
const int diri[4] = {-1, 0, 1, 0};
const int dirj[4] = {0, 1, 0, -1};
int N;
int key[110000];
vector<int> tree[110000];
pair<int, int> ext[110000];
int M;
vector<pair<int, int> > vect;
long double res[110000];
void extrems(int n) {
if (tree[n].... | 14 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using vi = std::vector<int>;
using vvi = std::vector<vi>;
template <class C>
C& reuniq(C& c) {
c.erase(std::unique((c).begin(), (c).end()), c.end());
return c;
}
template <class C, class X>
int lowpos(const C& c, const X& x) {... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e2 + 10;
int n, k, h, w;
vector<pair<long long, long long> > nums;
int main() {
cin >> n;
int x;
long long rta = 0;
for (int i = 0; i < n; ++i) {
cin >> x;
nums.push_back({x, i});
rta += x;
}
if (n == 1) {
cout << rta << "\n";
... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
struct rec {
int x, y;
};
int n, p;
int s[800], f[800], g[800];
rec a[N];
int cmp(rec a, rec b) { return a.x < b.x || (a.x == b.x && a.y < b.y); }
int main() {
scanf("%d%d", &n, &p);
int m = sqrt(6 * p) + 5;
for (int i = 1; i <= p; i++) {
i... | 21 |
#include <bits/stdc++.h>
using namespace std;
bool used[512][512];
int w, h, x, y;
string str;
int main() {
cin >> w >> h >> x >> y;
cin >> str;
for (int i = (0); i <= (int(str.size()) - 1); ++i) {
if (used[x][y] == false) {
cout << "1 ";
used[x][y] = true;
} else {
cout << "0 ";
}
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
const long long INF = 1e16;
long long dp[N][N];
long long x[N], a[N], b[N], c[N], d[N];
int n, s, e;
int main() {
ios::sync_with_stdio(0);
cin >> n >> s >> e;
--s;
--e;
for (int i = 0; i < n; ++i) cin >> x[i];
for (int i = 0; i < n; ++i) cin ... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int N = 500;
int n, m, mark[N], cnt = 0;
vector<int> g[N];
void dfs(int u);
int main() {
scanf("%d%d", &n, &m);
for (; m--;) {
int u, v;
scanf("%d%d", &u, &v);
u--;
v--;
g[u].emplace_back(v);
}
for (int u = 0; u < n; u++) {
cnt = 0;
... | 14 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T _sq(T a) {
return a * a;
}
template <class T>
inline T _sqrt(T a) {
return (T)sqrt((double)a);
}
template <class T, class X>
inline T _pow(T a, X y) {
T z = 1;
for (int i = 1; i <= y; i++) {
z *= a;
}
return z;
}
template <class T... | 12 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
long long mod = 1e9 + 7;
vector<pair<long long, long long>> adj[2005];
long long w[2005][2005];
long long w_old[2005][2005];
long long ans;
const long long inv2 = (mod + 1) / 2;
const long long NE... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
scanf("%d %d", &n, &k);
int c[n];
for (int i = 0; i < n; i++) scanf("%d", &c[i]);
sort(c, c + n);
long long media1 = 0LL, media2;
for (int i = 0; i < n; i++) media1 += (long long)c[i];
media2 = (media1 % (long long)n) ? (media1 / (long... | 12 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, m, x = 0, has = 0, p = 0, q = 1000;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
int a;
cin >> a;
if (a == 0) x = 1;
if (a < 0) p++;
has += abs(a);
q = min(q, abs(a));
}
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long t;
cin >> t;
while (t--) {
long long a, b, n = 0, c = 0;
cin >> a >> b;
if (a >= b)
n = a - b;
else
n = b - a;
if (n == 0)
cout << c << "\n";
else if ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.precision(20);
long long int a, b;
scanf("%lld%lld", &a, &b);
long long int re = 10;
long long int ans = 1;
for (long long int i = a + 1; i <= b; ++i) {
long long int lov = i % re;
ans = (an... | 3 |
#include <bits/stdc++.h>
using namespace std;
struct less_key {
bool operator()(const pair<double, int32_t>& p1,
const pair<double, int32_t>& p2) {
return p1.first < p2.first ||
(p1.first == p2.first && p1.second > p2.second);
}
};
struct pair_hash {
std::size_t operator()(const p... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long y, k, n, j, i, x, q, d, m, c = 0, l, z, w, e, r, t;
long long lo(long long n) {
long long k = 2, s = n;
while (k * k <= n) {
if (n % (k * k) == 0) return 0;
k++;
}
return 1;
}
int main() {
cin >> n;
for (i = 1; i <= sqrt(n); i++)
if (n % i ... | 5 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.