solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
# define rep(i,a,b) for(int i=(a); i<=(b); ++i)
# define drep(i,a,b) for(int i=(a); i>=(b); --i)
typedef long long int_;
inline int readint(){
int a = 0; char c = getchar(), f = 1;
for(; c<'0'||c>'9'; c=getchar())
if(c == '-') f = -f;
for(; '0'<=c&&c<='9'; c=getchar())... | 19 |
#include <bits/stdc++.h>
using namespace std;
int const N = 1e6 + 10;
long long t, n, k;
string s;
bool mark[N];
void solve() {
cin >> n >> k;
cin >> s;
int cnt = 0;
for (int i = 0; i < n; i++) mark[i] = (s[i] == '1');
for (int i = 0; i < n; i++) {
if (!mark[i]) {
if (k - (i - cnt) >= 0) {
m... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long double e = 1, a, b, c, d, p, s;
cin >> a >> b >> c >> d;
s = (1 - a / b) * (1 - c / d);
p = s;
while (e > 0.000000000001) {
long double h = p;
p = p * s + s;
e = p - h;
}
cout << (p + 1) * (a / b) << endl;
return 0;
}
| 5 |
#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
using namespace std;
const long long mod = 998244353;
string s;
void solve() {
cin >> s;
long long pow10[11], pow9[11];
pow9[0] = 1;
pow10[0] = 1;
for (int i = 1; i < 11; i++) {
pow9[i] = pow9[i - 1] * 9;
pow10[i] = pow10[i - 1] * 10;
}
int n = ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int a[401];
int n, w1, w2, ans, t1, t2;
int greedy(int l, int r, int &m) {
int t = 0;
for (int i = l; i <= r; i++) {
t = t + m / a[i];
m = m % a[i];
}
if (r != n) t++;
m = a[l - 1] - 1 - m + a[r];
return t;
}
int main() {
cin >> n;
for (int i = 1; i ... | 18 |
#include <bits/stdc++.h>
using namespace std;
string st;
long long z;
int main() {
ios::sync_with_stdio(false);
cin >> st;
for (int i = 0; i < st.size(); i++)
if (st[i] == 'A')
z++;
else if (st[i] == '1')
z += 10;
else
z += st[i] - 48;
cout << z << endl;
return 0;
}
| 11 |
#include <bits/stdc++.h>
using namespace std;
long long a, b, x, y;
long long MY_gcd(long long a, long long b) {
if (b == 0) return a;
return MY_gcd(b, a % b);
}
int main() {
scanf("%lld%lld%lld%lld", &a, &b, &x, &y);
long long GCD = MY_gcd(x, y);
x /= GCD;
y /= GCD;
long long t1 = a / x;
long long t2 =... | 2 |
#include <bits/stdc++.h>
using namespace std;
struct comp {
bool operator()(const vector<long long>& a,
const vector<long long>& b) const {
return a[0] < b[0];
}
};
int main() {
set<vector<long long>, comp> a;
long long n, k;
cin >> n >> k;
vector<long long> s(n);
for (int i = 0; i <... | 8 |
#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
void solve() {
int n;
cin >> n;
pair<int, int> p[n];
for (int i = 0; i < n; i++) {
int a, b;
char c;
cin >> a >> c >> b;
p[i].first = a;
p[i].second = b;
}
sort(p, p + n);
int ans = -1;
... | 9 |
#include <bits/stdc++.h>
const int maxn = 2000 + 10;
int n, ans, x[maxn], y[maxn];
using namespace std;
map<pair<int, int>, int> a;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d%d", &x[i], &y[i]);
for (int j = 1; j < i; j++) {
ans += a[make_pair(x[i] + x[j], y[i] + y[j])]++;
... | 11 |
#include <bits/stdc++.h>
using namespace std;
struct Trie {
struct node {
node *child[26] = {};
int many = 0;
string orig;
} root;
void add(const string &s, const string &orig) {
node *v = &root;
for (int i = 0; i < (int)s.size(); ++i) {
char c = s[i];
node *&next = v->child[c - 'a... | 11 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void smn(T &a, const T &b) {
if (b < a) a = b;
}
template <class T>
inline void smx(T &a, const T &b) {
if (b > a) a = b;
}
template <class T>
inline T rev(const T &a) {
T _ = a;
reverse(_.begin(), _.end());
return _;
}
const double eps =... | 17 |
#include <bits/stdc++.h>
using namespace std;
int x, ans, n, num_1;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> x;
if (x == -1 && num_1 == 0)
ans++;
else if (x == -1 && num_1 > 0)
num_1--;
else
num_1 += x;
}
cout << ans << "\n";
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, i, cnt = 1;
cin >> n;
char a[n];
cin >> a;
for (i = 0; i < n - 1; i++) {
if (a[i] == a[i + 1]) {
cnt++;
}
}
cout << cnt / 2 << endl;
}
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.141593;
const long long mod = 1000000007;
const long long INF = 1e15;
const long long nax = 1e5 + 5;
long long dx[] = {0, 0, 1, -1};
long long dy[] = {1, -1, 0, 0};
string ds = "RLDU";
long long parent[200001] = {0};
long long size[200001] = {0};
lo... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 2e5 + 10, MAXK = 10086;
long long dis[MAXK], a[MAXN], c[MAXN], h, n, m, k;
bool vis[MAXN];
set<pair<long long, long long> > q;
struct Edge {
long long ver, nxt, w;
} e[MAXN * 2];
long long tot = 0, head[MAXN];
void add(long long u, long long v, long... | 17 |
#include <bits/stdc++.h>
using namespace std;
inline int M(int x) { return x >= 1000000007 ? x - 1000000007 : x; }
inline int M1(int x) { return x < 0 ? x + 1000000007 : x; }
int n, m, a[5127], f[5127], g[5127], f1[5127];
inline int ksm(int p, int k) {
int res = 1;
while (k) {
if (k & 1) res = 1ll * res * p % 1... | 22 |
#include <bits/stdc++.h>
using namespace std;
int n, a, b;
vector<int> g[100010];
int mxdep[100010][4];
void dfs(int u, int pa) {
memset(mxdep[u], 0, sizeof mxdep[u]);
for (int v : g[u])
if (v != pa) {
dfs(v, u);
mxdep[u][3] = mxdep[v][0] + 1;
for (int i = 2; i >= 0; i--) {
if (mxdep[u... | 22 |
#include <bits/stdc++.h>
using namespace std;
const int mxn = 1e0 + 1;
double eps = 1e-9;
int ncase = 1;
long long N, M, a, b, c;
bool _cmp(const pair<int, int>& i, const pair<int, int>& j) {
return ((i.first == j.first) ? (i.second > j.second) : (i.first < j.first));
}
struct Node {
int x, y;
Node(int a = 0, int... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long lim = 200005;
long long p[200005][25];
void solve() {
for (long long i = 1; i <= lim; i++) {
for (long long j = 0; j <= 20; j++) {
long long t = 0;
if (((1 << j) & i) == 0) {
t = 1;
}
p[i][j] = p[i - 1][j] + t;
}
}
}
sig... | 5 |
#include <bits/stdc++.h>
using namespace std;
inline void pisz(int n) { printf("%d\n", n); }
template <typename T, typename TT>
ostream &operator<<(ostream &s, pair<T, TT> t) {
return s << "(" << t.first << "," << t.second << ")";
}
template <typename T>
ostream &operator<<(ostream &s, vector<T> t) {
for (int(i) = ... | 16 |
#include <bits/stdc++.h>
using namespace std;
int read() {
char ch = getchar();
int x = 0, y = 1;
while (!isdigit(ch) && ch != '-') ch = getchar();
if (ch == '-') {
y = -1;
ch = getchar();
}
while (isdigit(ch)) {
x = (x << 1) + (x << 3) + ch - '0';
ch = getchar();
}
return x * y;
}
const... | 18 |
#include <bits/stdc++.h>
const int N = 300005, K = 20;
int m, maxd, dep[N], fa[N][K], s1[N], s2[N], top1, top2;
void add(int u, int v) {
dep[u] = dep[v] + 1, fa[u][0] = v;
for (int i = 1; i < K; ++i) fa[u][i] = fa[fa[u][i - 1]][i - 1];
}
int lca(int u, int v) {
if (dep[u] < dep[v]) u ^= v ^= u ^= v;
int ret = d... | 20 |
#include <bits/stdc++.h>
namespace QiFeng233 {
long long a, l, r, b;
void solve() {
scanf("%lld", &a);
b = ((long long)1e18 % a * 9 % a * 9 % a + 1 % a) % a;
printf("%lld %lld", 1 + a - b, (long long)1e18 + a - b);
}
} // namespace QiFeng233
signed main() {
QiFeng233::solve();
return 0;
}
| 17 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 500010;
vector<int> G[maxn];
int n, cnt = 1;
int ans[maxn][2];
vector<pair<int, int> > res;
void dfs2(int cur, int pre, int len) {
int size;
if (cur == 1)
size = G[1].size();
else
size = G[cur].size() - 1;
cnt += size + 1;
ans[cur][0] = le... | 14 |
#include <bits/stdc++.h>
int main() {
int i, n, m, ary[5][2] = {{0, 100}, {0, 0}, {100, 0}, {1, 1}, {1, 2}};
scanf("%d%d", &n, &m);
if (m == 3) {
if (n >= 5) {
puts("-1");
} else {
for (m = 0; m < n; m++) printf("%d %d\n", ary[m][0], ary[m][1]);
}
return 0;
}
int X = 10000;
for (... | 15 |
#include <bits/stdc++.h>
using namespace std;
inline long long pow(long long a, long long b, long long mo) {
if (!a) return 0;
long long tmp = 1;
for (; b; b >>= 1) {
if (b & 1) tmp = (long long)tmp * a % mo;
a = (long long)a * a % mo;
}
return tmp;
}
template <class T>
inline void R(T &xx) {
xx = 0... | 18 |
#include <bits/stdc++.h>
using namespace std;
int n, m, V[4000010], g[4000010], b[4000010], ff, i, a[4000010], ln, f[4000010],
j, ap, gs[4000010], ans[4000010];
struct mjj {
int x, y, z, a;
} c[4000010];
bool cmp(mjj x, mjj y) { return x.x < y.x; }
int ask(int l, int r, int L, int R, int cur) {
int mid = (l + r... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int inv = 1000000000;
const int minv = -inv;
const int max_n = 1000 + 5;
const int max_k = max_n;
const int max_nct = max_n;
const int max_m = 100000 + 5;
int n, m, k;
vector<int> adjl[max_n];
int c[max_k];
bool visited[max_n] = {0};
int ct[max_n];
int nct, szct[max_n... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int maxn = 100000 + 5;
int n;
cin >> n;
vector<int> g[maxn];
int a[maxn];
fill(a, a + maxn, -1);
for (int i = 1, u, v; i < n; i++) {
cin >> u >> v;
g[u].push_back(i);
g[v].push_back(i);
}
int label = 0;
for (int i = 1; i <= n; i+... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
std::array<long long int, 21> vals{0};
for (int i = 0; i < n; i++) {
int num;
cin >> num;
if (num >= 0) {
vals[num]++;
} else {
vals[10 - num]++;
}
}
long long int sum = 0;
for (int i = 1; i < 11; i... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 9;
int inf = 1e9;
double eps = 1e-2;
ifstream in("input.txt");
ofstream out("output.txt");
int main() {
int n;
cin >> n;
int ans = 0;
while (n > 1) {
ans++;
n /= 2;
}
ans++;
cout << ans;
return 0;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
vector<int> G[N];
int alice[N], bob[N];
void dfs(int x, int fa, int *d) {
d[x] = d[fa] + 1;
for (int i = 0; i < (int)G[x].size(); ++i) {
if (G[x][i] != fa) {
dfs(G[x][i], x, d);
}
}
}
int main() {
int n, x;
cin >> n >> x;
for ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100001;
int spf[MAXN];
int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
void precal() {
spf[1] = 1;
for (int i = 2; i < MAXN; i++) spf[i] = i;
for (int i = 4; i < MAXN; i += 2) spf[i] = 2;
for (int i = 3; i * i < MAXN; i++) {
if (spf[i] =... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long i, j, l, m, n;
string s1, s2;
long k[100005];
long l1, l2;
cin >> s1;
cin >> s2;
l1 = s1.size();
l2 = s2.size();
if (l1 != l2) {
cout << "NO" << endl;
} else {
j = 0;
for (i = 0; i < l1; i++) {
if (s1[i] != s2[i]) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
bool IsPrime(long long int x) {
bool isPrime = true;
for (long long int a = 2; a * a <= x; a++) {
if (x % a == 0) return false;
}
return true;
}
long long int B[1005][1005], C[20000], A[1005][1005];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
co... | 2 |
#include <bits/stdc++.h>
using namespace std;
int inline read() {
int num = 0, neg = 1;
char c = getchar();
while (!isdigit(c)) {
if (c == '-') neg = -1;
c = getchar();
}
while (isdigit(c)) {
num = (num << 3) + (num << 1) + c - '0';
c = getchar();
}
return num * neg;
}
const int maxn = 100... | 11 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e6 + 5, mod = 1e9 + 7, inf = 1e9 + 7;
const ll INF = 1e18 + 5;
map<int, int> mp[N];
set<pair<int, int> > st[N];
int dp[N];
int a[N], b[N], w[N];
int main() {
ios ::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
for (i... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n;
const int maxn = 100010;
struct node {
int c;
int s;
int rank;
node() {}
node(int _c, int _s, int _r) : c(_c), s(_s), rank(_r) {}
bool operator<(const node& rhs) const {
if (c == rhs.c) return s > rhs.s;
return c < rhs.c;
}
} a[maxn];
struct seg... | 9 |
#include <bits/stdc++.h>
using namespace std;
int M = 1e9 + 7;
const int NMAX = 1e4;
void print(vector<string> &a) {
cout << "YES" << endl;
for (size_t i = 0; i < a.size(); i++) cout << a[i] << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vector<int> a(n);
for (... | 5 |
#include <bits/stdc++.h>
using namespace std;
double cos60 = cos(3.1415926535897932384626433832795 / 3.);
double cos30 = cos(3.1415926535897932384626433832795 / 6.);
int main() {
int n = 6;
vector<double> a(n);
for (int i = 0; i < n; ++i) cin >> a[i];
double b1 = a[1] * cos60;
double b2 = a[1] * cos30;
doub... | 8 |
#include <bits/stdc++.h>
int dx[] = {0, -1, 0, 1, -1, 1, -1, 1};
int dy[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int MOD = 1e8, N = 2e5 + 5, oo = 1e9;
const double pi = acos(-1);
using namespace std;
long double ncr(long long n, long long r) {
if (n < r) return 0.0;
long double ans = 1;
int i = n, j = 2, ok = 1;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int a[2022];
inline void Solve() {
int n;
cin >> n;
for (register int i = 1; i <= n; i++) {
cin >> a[i];
}
vector<int> A;
for (int i = n; i != 1; i -= 2) {
int p1, p2;
for (register int j = 1; j <= i; j++) {
if (a[j] == i) {
p1 = j;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long arr[100005];
int main() {
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
long long m;
cin >> arr[0];
m = arr[0];
for (int i = 1; i < n; i++) {
cin >> arr[i];
m = min(arr[i], m);
}
vector<long long> x;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int NMax = 110000;
int N, M, P, A[NMax], B[NMax];
int T, Q[NMax];
int D[NMax], nn, dp[NMax];
map<int, int> have;
int POW(int a, int b, int p) {
long long ret = 1, tmp = a;
while (b) {
if (b & 1) {
ret = (ret * tmp) % p;
--b;
}
tmp = (tmp * ... | 18 |
#include <bits/stdc++.h>
using namespace std;
int n;
string s;
int main() {
scanf("%d", &n);
char c = 'a';
if (n == 0) s = 'a';
while (n) {
int m = 1;
while (m * (m + 1) / 2 <= n) m++;
n -= m * (m - 1) / 2;
while (m) s += c, m--;
c++;
}
cout << s << endl;
return 0;
}
| 8 |
#include <bits/stdc++.h>
using namespace std;
int N, M, S;
vector<vector<int> > adj;
vector<int> U, V, W;
vector<int> X, sz, par;
void dfs(int u, int fe) {
sz[u] = X[u];
for (int i = 0; i < adj[u].size(); i++) {
int e = adj[u][i];
int v = U[e] + V[e] - u;
if (e == fe) continue;
dfs(v, e);
sz[u] ... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
cout << "\n";
if (n % m == 0) {
cout << "YES";
} else {
cout << "NO";
}
}
cout << "\n";
return 0;
}
| 0 |
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
double sqr(double a) { return a * a; }
const long long int inf = 100000000000000000LL;
struct Node {
Node() { u = 0; }
int v;
int u;
vector<int> nbr;
};
struct Point {
int x, y;
int used;
Point() { used = 0; }
};
struct St {
l... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 9;
int n, m;
double arr[N];
inline int read() {
char c = getchar();
int ret = 0, f = 1;
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c <= '9' && c >= '0') {
ret = ret * 10 + c - '0';
c = getchar(... | 17 |
#include <bits/stdc++.h>
using namespace std;
struct query {
int t, i, j, k, id;
};
query q[100005];
int parent[100005];
vector<int> g[100005];
int ans[100005];
int n, m, qq;
bool a[1005][1005];
int total = 0;
void printA() {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) cout << a[i][j];
cout ... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
while (c--) {
if (a < b) {
a++;
} else {
b++;
}
}
cout << min(a, b) * 2;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int arr1[1005];
int arr2[1005];
int main() {
int t;
cin >> t;
while (t--) {
int x;
cin >> x;
x++;
arr1[0] = 0, arr2[0] = 0;
for (int i = 1; i < x; i++) {
cin >> arr1[i];
cin >> arr2[i];
}
for (int i = 0; i < x; i++) {
for ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int b[n];
int diff[n];
map<long long, long long> m;
for (int i = 0; i < n; i++) {
cin >> b[i];
diff[i] = b[i] - i;
m[diff[i]] += b[i];
}
map<long long, long long>::iterator itr;
long long ma = -1;
for (itr = m.be... | 6 |
#include <bits/stdc++.h>
using namespace std;
int arr[123465];
std::vector<int> ans;
int main(int argc, char const *argv[]) {
int n;
int ctr, val;
cin >> n;
for (int i = 1; i <= n; i++) {
scanf("%d", arr + i);
}
for (int j = 30; j >= 0; j--) {
ans.clear();
long long int val = powl(2, j);
lon... | 10 |
#include <bits/stdc++.h>
using namespace std;
bool prime[(long long int)1e7 + 1];
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
return (a.second < b.second);
}
vector<long long int> primeFactors(long long int n) {
vector<long long int> result;
if (n % 2 == 0) {
result.push_back(2);
wh... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int mxn = 1e5 + 5;
mt19937 rng;
struct Node {
long long v, t;
int sz;
Node *ls, *rs;
Node(long long _v) : v(_v), t(), sz(1), ls(), rs() {}
void push(long long _t) { v += _t, t += _t; }
void pushdown() {
if (t) {
if (ls) ls->push(t);
if (rs)... | 24 |
#include <bits/stdc++.h>
using namespace std;
template <typename S, typename T>
ostream& operator<<(ostream& out, pair<S, T> const& p) {
out << '(' << p.first << ", " << p.second << ')';
return out;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> const& v) {
long long l = v.size();
for (long... | 14 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-6;
const int inf = (int)1e9;
const int MAX_N = 100 + 10;
const int REM = inf + 7;
long long n, k, p;
int main() {
cin >> n >> k >> p;
bool is_odd = n % 2;
long long np = n - is_odd;
long long kp = k - is_odd;
long long ee = -1, es = -1;
if ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = (long long)1e9 + 7;
const int inf = (int)2e9;
const long long INF = (long long)1e18;
const int base = 1000 * 1000 * 1000;
const int maxn = 105;
const long double pi = acosl(-1.0);
const long double eps = 1e-9;
int get(long long n) {
int res = 0;
wh... | 8 |
#include <bits/stdc++.h>
int main() {
char a[3][3];
int i, j;
for (i = 0; i < 3; i++) scanf("%s", a[i]);
if (a[0][0] == a[2][2] && a[0][1] == a[2][1] && a[0][2] == a[2][0] &&
a[1][0] == a[1][2])
printf("YES\n");
else
printf("NO\n");
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
char op[5];
struct Node {
struct Node *next[2];
int num;
};
int length;
Node *head;
int bit[N][35], tmp[35];
void Init() {
head = new Node;
for (int i = 0; i < 2; i++) {
head->next[i] = NULL;
head->num = 0;
}
}
void Insert(int x) {
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int main() {
ios_base ::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> v[n + 1];
int st;
cin >> st;
long long int sum = 0;
vector<int> pre(n + 5, 0);
for (int j = 1; j < m; j++) {
int x;
cin >> x;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
int n;
long long dp[N], ans[N], fdp[N];
vector<int> edge[N];
vector<int> L[N], R[N];
long long fastPow(long long a, long long b) {
long long ans = 1;
wh... | 15 |
#include <bits/stdc++.h>
using namespace std;
inline void boost() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
}
const int MXN = 1e5 + 5;
int n, k, x, a[MXN], f[1025], c[1025];
int main() {
boost();
cin >> n >> k >> x;
for (int i = 1; i <= n; i++) cin >> a[i], f[a[i]]++;
while (k--) {
for (i... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 10;
const long long int INFLL = (long long int)1e18 + 10;
const long double EPS = 1e-8;
const long double EPSLD = 1e-18;
const long long int MOD = 1e9 + 7;
template <class T>
T &chmin(T &a, const T &b) {
return a = min(a, b);
}
template <class T>
T &... | 15 |
#include <bits/stdc++.h>
using namespace std;
vector<int> nodesLink[1000005];
bool mark[1000005];
int total = 0;
int k;
int calculate(int x) {
mark[x] = true;
if (nodesLink[x].size() == 1) {
return 1;
} else {
vector<int> tmp;
for (int i = 0; i < nodesLink[x].size(); i++) {
if (!mark[nodesLink[x... | 16 |
#include <bits/stdc++.h>
using namespace std;
vector<int> ready[3], temp[3];
int done[203], n, part[203], cnt[3], init[203], total;
vector<int> store[203];
int doit(int no) {
int ans = 0;
for (int v = cnt[no]; v < ready[no].size(); v++) {
ans++, total++;
int d = ready[no][v];
for (int i = 0; i < store[d... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
scanf("%i %i", &n, &k);
int arr[n];
set<pair<int, int> > piles;
for (int i = 0; i < n; i++) {
scanf("%i", &arr[i]);
piles.insert(make_pair(-arr[i], i));
}
int ans[n][k];
memset(ans, 0, sizeof(int) * n * k);
int offset = 0, c ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int ans = 0;
void gen(vector<int> &A, vector<vector<int>> &G, int i) {
if (i < G.size()) {
for (int j = 0; j < 6; ++j) {
A[i] = j;
gen(A, G, i + 1);
}
} else {
bool was[6][6];
for (int a = 0; a < 6; ++a) {
for (int b = 0; b < 6; ++b) wa... | 9 |
#include <bits/stdc++.h>
using namespace std;
deque<pair<int, int> > dq;
int N, M, T;
vector<int> ans;
int main() {
bool reachMax = false;
scanf("%d%d%d", &N, &M, &T);
int h, m, s;
int last = 0;
for (int i = 0; i < N; ++i) {
scanf("%d:%d:%d", &h, &m, &s);
int cur = h * 3600 + m * 60 + s;
while (!d... | 13 |
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
const int mod = 998244353;
long long mypow(long long a, long long n){
long long ans = 1;
while (n) {
if (n & 1)
ans = ans * a % mod;
a = a * a % mod;
n >>= 1;
}
return ans;
}
string s;
long long f[100005];
long long inv[100... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 7 + 1e9;
const int inf = 1e9 + 5;
const long long INF = (long long)1e18 + 5;
const int N = 1e5 + 5;
int a[N], b[N], pre[N];
int ans[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m, c;
cin >> n >> m >> c;
for (... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int n, x, y;
string s;
cin >> n;
bool b = false;
for (int i = 0; i < n; i++) {
cin >> s >> x >> y;
if (x >= 2400 && y > x) {
b = true;
}
}
if (... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int a[4];
for (int i = 0; i < 4; ++i) {
cin >> a[i];
}
sort(a, a + 4);
if (a[0] + a[1] ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
void mad(long long &a, long long b) {
a = (a + b) % 1000000007;
if (a < 0) a += 1000000007;
}
long long gcd(long long a, long long b) {
if... | 16 |
#include <bits/stdc++.h>
int t[1005], r[1005];
int main(void) {
int k, m, n, x, y;
scanf("%d %d %d", &n, &m, &k);
for (int i = 0; i < 1005; ++i) r[i] = 0;
while (n--) {
scanf("%d %d", &x, &y);
if (!r[x])
t[x] = y;
else if (y < t[x])
t[x] = y;
r[x]++;
}
x = 0;
for (int i = 1; i ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 100 + 5;
const double EPS = 1e-10;
int n, k, epsi, Ox, Oy;
int x[maxN], y[maxN], dis[maxN];
double yes[maxN], no[maxN];
double dp[maxN][maxN];
inline int P2(int x) { return x * x; }
inline bool ok(double R) {
double RR = R * R;
for (int i = 1; i <= n; i... | 13 |
#include <bits/stdc++.h>
int dp[103][53][2][2];
char str[103];
int MAXI(int a, int b) {
if (a > b) return a;
return b;
}
int MINI(int a, int b) {
if (a < b) return a;
return b;
}
int main() {
int i, j, k, l, n, ans = 0;
scanf("%s", str);
scanf("%d", &n);
for (i = 0; str[i]; ++i) {
for (j = 0; j <= n... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100009;
int x, y, n, m, i, u, w, z, sum, best, j, k, t, ans;
int a[N], d[N];
int main() {
cin >> n >> x;
k = n;
while (n >= x) {
ans += n / x;
n = n / x + (n % x);
}
ans += k;
cout << ans;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
LL solve(LL a, LL b) {
if (a == b) return 0;
if (a > b) swap(a, b);
for (int i = 1;; i++) {
a += i;
if (a >= b && (a + b) % 2 == 0) return i;
}
return -1;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MXN = 2009, mol = 1000000007;
int N;
int a[MXN], p[MXN] = {};
int n1, n2;
void init() {
scanf("%d", &N);
for (int i = 1; i <= N; i++) {
scanf("%d", a + i);
if (a[i] != -1) p[a[i]] = i;
}
n1 = n2 = 0;
for (int i = 1; i <= N; i++) {
if (a[i] ==... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
if (n > m)
cout << "YES" << endl;
else {
vector<int> a(n, 0);
for (int i = 0; i < n; ++i) {
cin >> a[i];
a[i] %= m;
}
vector<vector<int> > can(n + 1, vector<int>(m, 0));
can[0][0] = 1;
for... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 21, MASK = 1 << N;
int dp[N][MASK], n, m, ans;
string s[N];
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> s[i];
for (int j = 0; j < m; j++) {
int tmp = 0;
for (int i = ... | 18 |
#include <bits/stdc++.h>
using namespace std;
const double PI = atan2(0, -1);
int n;
double r, v, s, f, dist;
double solve(double ang) {
double lo = dist - 1, hi = dist + 1, mid;
for (int times = 0; times < (int)(100); ++times) {
mid = 0.5 * (lo + hi);
double nang = ang - mid;
if (mid + cos(nang) < dist... | 17 |
#include <bits/stdc++.h>
using namespace std;
long long Pow(long long a, long long b, long long MOD) {
a %= MOD;
long long res = 1;
while (b) {
if (b & 1) res = (res * a) % MOD;
b /= 2;
a = (a * a) % MOD;
}
return res;
}
const int maxn = 200000 + 10;
const int MOD = 1e9 + 7;
int cnt[maxn];
struct ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
int n;
cin >> n;
vector<int> V;
vector<bool> B;
for (int i = 0; i < n; i++) {
string S;
cin >> S;
if (i == 0) {
V.resize((int)S.size(), -1);
B.resize((int)S.size(), 0);
}
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b;
cin >> n >> a >> b;
if (4 * a + 2 * b <= n)
cout << "1" << endl;
else if (2 * a + b <= n) {
cout << "2" << endl;
} else if ((a + max(a, b) <= n) || (4 * a <= n))
cout << "3" << endl;
else if (a + min(a, b) <= n)
cout << ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long m, n;
while (cin >> m >> n) {
map<long, long> mp;
map<long, long>::iterator it;
long j = 0, c[100001] = {0}, d[100001] = {0}, i1, x, kk = 0, ss = 0, i,
zz = 0, k, a1, b1;
for (i1 = 0; i1 < n; i1++) {
cin >> a1 >> b1;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int e = 40;
int n;
long long m, a[e], ans = 0;
vector<long long> ve[2];
set<long long> se[2];
void dfs(int pl, int sum, int lim, int t) {
sum %= m;
if (!se[t].count(sum)) ve[t].push_back(sum);
if (pl > lim) return;
dfs(pl + 1, (sum + a[pl]) % m, lim, t);
dfs... | 10 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
int n, m;
int main() {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base ::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
int a[n], b[n], c = n;
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (a[i] =... | 6 |
#include <bits/stdc++.h>
using namespace std;
int vis[1000];
int Pow[5];
int change(string p) {
int sum = 0;
for (int i = 0; i < p.size(); i++) {
sum += (p[i] - 48);
sum *= 10;
}
return sum / 10;
}
string minstr(string s) {
int i = 0, j = 1, k = 0;
int len = s.size();
while (j < len && i < len && ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int Max = 1e5 + 9, inf = 1e9;
vector<int> S;
int A[Max], dp[2][Max], T[Max], Ans[Max];
int main() {
int n, mx = -1;
cin >> n;
for (int i = 1; i <= n; i++) cin >> A[i];
S.push_back(-inf);
for (int i = 1; i <= n; i++) {
vector<int>::iterator it = lower_bou... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int OO = 1 << 28;
int di[] = {1, 0, -1, 0};
int dj[] = {0, 1, 0, -1};
int n, r;
int arr[51];
double dp[51][51][51];
long long choose(unsigned n, unsigned k) {
static vector<vector<long long> > mem;
if (n < k) return 0;
if (mem.size() <= n) mem.resize(n + 1);
i... | 14 |
#include <bits/stdc++.h>
using namespace std;
template <class T, class L>
bool smax(T& x, L y) {
return x < y ? (x = y, 1) : 0;
}
template <class T, class L>
bool smin(T& x, L y) {
return x > y ? (x = y, 1) : 0;
}
const int maxn = 1e5 + 17;
int n, a[maxn], b[maxn];
int main() {
ios::sync_with_stdio(0), cin.tie();... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)1.e5;
int p[maxn];
int find(int x) { return p[x] == x ? x : p[x] = find(p[x]); }
bool join(int x, int y) {
x = find(x), y = find(y);
if (x == y) return false;
if (rand() & 1) swap(x, y);
p[x] = y;
return true;
}
int main() {
for (int _n(max... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int size = 47;
int sum[size][size];
int good[size][size][size][size];
int dp[size][size][size][size];
int source[size][size];
int main() {
int n, m, qs;
cin >> n >> m >> qs;
for (int i = 1; i < n + 1; ++i) {
for (int j = 1; j < m + 1; ++j) {
char c;
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int a = 0, b = 0;
int i = 1;
while (a * b != n && n != 1) {
if (n % i == 0 && n / i < k) {
a = i;
b = n / a;
}
i++;
}
cout << (n == 1 ? k + 1 : a * k + b);
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1061109567;
const long long LINF = 4557430888798830399ll;
const int MOD = 1000000007;
template <typename T>
void read(T &x) {
x = 0;
char c = getchar();
if (c == EOF) exit(0);
while (!isdigit(c)) c = getchar();
while (isdigit(c)) {
x = x * 10 +... | 12 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.