solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
map<string, int> aa;
int main(void) {
int n;
cin >> n;
for (int e = 0; e < n; e++) {
string a;
cin >> a;
if (aa[a] == 0) {
cout << "NO\n";
aa[a]++;
} else {
cout << "YES\n";
}
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long n, a[40] = {1,
2,
4,
8,
16,
32,
64,
128,
256,
512,
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[1000];
int d = 1;
int t;
cin >> t;
for (int i = 1; i <= 1666; i++) {
if (i % 3 == 0 || i % 10 == 3) {
continue;
}
a[d] = i;
d++;
}
while (t--) {
int n;
cin >> n;
cout << a[n] << endl;
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const unsigned long long mod1 = 982886081;
const unsigned long long mod2 = 889930273;
const unsigned long long s1 = 131;
const int N = 3e6;
unsigned long long pm1[N], pm2[N];
pair<unsigned long long, unsigned long long> strhash[N];
void init(char *s, int len) {
pm1[0] = p... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MAX = 100010;
int n, k, a[300];
int main() {
cin >> n >> k;
for (int i = 0, _n = (n); i < _n; ++i) {
cin >> a[i];
}
int ans = INT_MIN;
for (int L = 0, _n = (n); L < _n; ++L) {
for (int R = L, _n = (n); R < _n; ++R) {
... | 7 |
#include<bits/stdc++.h>
using namespace std;
const int maxn = 100 + 10;
int arr[maxn][maxn];
int sum[maxn * 2];
int n,m;
int main(){
int T; scanf("%d",&T);
while(T-- ){
scanf("%d%d",&n,&m);
memset(sum,0,sizeof(sum));
for(int i = 1 ; i <= n ; i++ ){
for(int j = 1 ; j <= m ; ... | 19 |
#include <bits/stdc++.h>
using namespace std;
int cnt[100005];
int gg[500];
int gn;
int ww[100005];
int cc[100005][455];
int n, m;
int dd[100005];
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i) {
scanf("%d", &dd[i]);
if (dd[i] <= n) {
cnt[dd[i]]++;
if (cnt[dd[i]] >= dd[i] && !w... | 10 |
#include <bits/stdc++.h>
using namespace std;
template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P) {
return os << "(" << P.first << "," << P.second << ")";
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
os << "[";
for (auto vv : V) os << vv << ",";
return os << "]";
}... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long int m, n, a[223456], ans, i, j;
set<long long int> s1, s2;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
long long int oi = 1, ei = 2, oc = 0, ec = 0;
for (i = 0; i < n; i++) {
cin >> a[i];
s2.insert(a[i]);
if (... | 11 |
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
struct debug {
~debug() { cerr << endl; }
template <class c>
debug& operator<<(c x) {
cerr << x;
return *this;
}
template <class c, class d>
debug& operator<<(pair<c, d> x) {
*this << "(" << x.fi... | 11 |
#include <bits/stdc++.h>
using namespace std;
using Point = pair<int, int>;
template <typename T>
using Matrix = vector<vector<T>>;
const array<Point, 4> directions = {{{-1, 0}, {0, 1}, {1, 0}, {0, -1}}};
void bfs(int R, int C, const vector<Point>& source, const vector<Point>& target,
Matrix<int>& global_dista... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
int counter = 0, counter1 = 0;
for (int i = 0; i < s.length(); i++) {
if (s[i] == 'A') {
counter++;
} else if (s[i] == 'D') {
counter1++;
}
}
if (counter > counter1) {
cout << "Ant... | 0 |
#include <bits/stdc++.h>
using namespace std;
map<string, int> m;
int main() {
int b;
cin >> b;
string a[b + 1];
for (int i = 1; i <= b; i++) {
cin >> a[i];
}
for (int i = b; i >= 1; i--) {
if (m[a[i]] != 2) {
cout << a[i] << endl;
m[a[i]] = 2;
}
}
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e18;
const int inf = 1e9;
const int MOD = 1e9 + 7;
const int nax = 1000000 + 10;
vector<int> have;
int dp[12][12][1001];
int n;
int ans[nax];
bool solve(int bal, int prev, int step) {
if (step == n + 1) return true;
for (auto x : have) {
i... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> m >> n;
vector<vector<bool>> a(m, vector<bool>(n, false));
for (int i = 0; i < m; i++) {
int s;
cin >> s;
while (s--) {
int j;
cin >> j;
j--;
a[i][j] = tr... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int M = 1e6 + 5;
const int step = 18;
int n, m, q, p[N];
int cnt, head[N], ans[N];
inline int read() {
int s = 0, w = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') w = -1;
ch = getchar();
}
while (ch >= ... | 11 |
#include <bits/stdc++.h>
using namespace std;
struct Pt {
long long x, y;
Pt(long long x_, long long y_) {
x = x_;
y = y_;
}
bool operator<(const Pt& p) const {
if (x < p.x) return true;
if (x > p.x) return false;
return y > p.y;
}
bool contains(const Pt& p) const { return p.y > y + (x -... | 16 |
#include <bits/stdc++.h>
using namespace std;
struct Edge {
int x, y, val, id;
bool operator<(const Edge e) const { return val < e.val; }
};
int n, m;
Edge e[200010];
int tid[200010];
int ans[200010];
bool vis[200010];
void init() {
scanf("%d%d", &n, &m);
for (int i = 0; i < m; i++)
scanf("%d%d%d", &e[i].x,... | 19 |
#include <bits/stdc++.h>
using namespace std;
int N, Q, tot;
int root[200010];
long long ans;
class rec {
public:
int lson, rson;
int s;
} seg[5000010];
long long C2(long long x) { return x * (x - 1) / 2; }
void Init(int &x, int l, int r, int t) {
int xx = x;
x = ++tot;
seg[x] = seg[xx];
seg[x].s++;
if (... | 13 |
#include <bits/stdc++.h>
using namespace std;
vector<int> pos, reg;
map<int, int> back;
int solve(int position, int length) {
if (length == 0) return position;
vector<int>::iterator t =
upper_bound(pos.begin(), pos.end(), position + length);
t--;
int nextone = t - pos.begin();
if (pos[nextone] - positio... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n + 3];
a[0] = 0;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) a[i] += a[i - 1];
int mx = 0;
for (int i = 1; i <= n; i++)
for (int j = i; j <= n; j++) {
mx = max(mx, a[i - 1] + a[n] - a[... | 4 |
#include <bits/stdc++.h>
using namespace std;
void CI(int &_x) { scanf("%d", &_x); }
void CI(int &_x, int &_y) {
CI(_x);
CI(_y);
}
void CI(int &_x, int &_y, int &_z) {
CI(_x);
CI(_y, _z);
}
void CI(int &_a, int &_b, int &_c, int &_d) {
CI(_a, _b);
CI(_c, _d);
}
template <typename T>
void getarray(T a[], int... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, k = 0, p, j, ans = 0;
scanf("%d", &n);
pair<int, int> arr[100001];
arr[0].first = 0;
arr[0].second = 0;
for (int i = 1; i <= n; i++) {
scanf("%d", &x);
if (x >= arr[k].second) {
k++;
ans++;
arr[k].first = x;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
struct people {
int num;
int date;
} P[1000010];
bool cmp(people a, people b) { return a.date < b.date; }
int main() {
int n, i;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &P[i].date);
P[i].num = i + 1;
}
sort(P, P + n, cmp);
printf("%d\n... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int dx[9] = {0, 1, 0, -1, 0, -1, -1, 1, 1};
const int dy[9] = {0, 0, -1, 0, 1, -1, 1, -1, 1};
const double pi = acos(-1.0);
const int N = 30 + 5;
struct point {
long long x, y;
};
int n, du[N];
vector<int> G[N];
point ans[N];
void dfs(int v, int fa, long long x0, lo... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long n, k, o;
int main() {
ios_base ::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
o = (round(n + 1.5 - sqrt(2 * (n + k) + 2.75)));
cout << o << "\n";
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int max(int x, int y) {
if (x > y)
return x;
else
return y;
}
int main() {
string a, b;
int x = 0, y = 0;
cin >> a >> b;
int l = a.length();
for (int i = 0; i < l; i++) {
if (a[i] == '4' && b[i] == '7') x++;
if (a[i] == '7' && b[i] == '4') y++;... | 4 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
const long double PI = 3.141592653589793;
const long long INF = 9223372036854775807ll;
const long long mod = 1e9 + 7;
const int N = 1e5 + 5;
long long tree[4 * N];
long long lazy[4 * N];
long lon... | 14 |
#include <bits/stdc++.h>
using namespace std;
template <typename T = long long>
inline T read() {
T s = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = -1;
ch = getchar();
}
while (isdigit(ch)) {
s = (s << 3) + (s << 1) + ch - 48;
ch = getchar();
}
return s * f;
}
... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 100100;
const long long mod = 1000000007;
long long mpow(long long n, long long p) {
if (p == 0)
return 1;
else {
long long aux = mpow(n, p / 2);
aux *= aux;
aux %= mod;
if (p % 2 == 0)
return aux;
else
return (n * aux... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, grot = 0, grotagn = 0;
cin >> n;
int a[n / 2];
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n / 2);
for (int i = 1; i <= n; i += 2) grot += abs(a[(i - 1) / 2] - i)... | 3 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
const long long INFF = 0x3f3f3f3f3f3f3f3f;
const long long mod = 1000000007;
const double eps = 1e-5;
const int maxn = 2005;
const int maxm = 20005;
const int base = 27;
int n, m;
char str[2505][5005];
int hanming[50... | 14 |
#include <bits/stdc++.h>
using namespace std;
int a[1001][1001];
int m = 0, o1[100001], o2[100001], t[100001];
void f(int n) {
int c = -1;
if (n == 1) return;
for (int i = 1; i <= n; i++) {
bool f = 0;
for (int j = 1; j <= n; j++)
if (a[j][i]) {
f = 1;
break;
}
if (!f) {
... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000005;
int N, M, dp[MAXN], res[MAXN];
vector<pair<int, int>> adj[MAXN];
int check(int v) {
if (dp[v]) return dp[v];
dp[v] = 1;
for (auto p : adj[v]) {
int n = p.first;
if (check(n) + 1 > dp[v]) {
dp[v] = dp[n] + 1;
res[v] = max(r... | 10 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
typedef struct MCMF {
int n, m;
vector<int> ghead, gnxt, gto, gcap;
vector<long long> gcost;
vector<long long> d;
vector<int> bck;
vector<long long> pot;
vector<int> flow;
void init(int _n) {
n... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int tt = 1;
scanf("%d", &tt);
;
while (tt--) {
long long int i, n, m, ans = 0, mx = 0, up = 0;
scanf("%lli %lli", &n, &m);
;
long long int a[n + 5], c[n + 5], b;
for (int i = 0; i < n; i++) {
scanf("%lli", &a[i]);
;
... | 6 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:134217728")
const long long MOD = 1000000007;
const int INF = 1000000000;
const int MAXN = 200005;
const double EPS = 1e-6;
const int HASH_POW = 7;
const double PI = acos(-1.0);
using namespace std;
void my_return(int code) { exit(code); }
int main() {
mt19937 ... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long int n, m, k, a[105][105], ones[105][105];
int main() {
scanf("%lld%lld%lld", &n, &m, &k);
for (long long int i = 0; i < n; i++) {
for (long long int j = 0; j < m; j++) {
scanf("%lld", &a[i][j]);
}
}
for (long long int j = 0; j < m; j++) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 500000 + 10;
char s[maxn];
long long sum[maxn], sum2[maxn];
int isvowel(char c) {
switch (c) {
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
case 'Y':
return 1;
default:
return 0;
}
}
int main() {
double ans... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int ans = 0;
int a[n + 1];
for (int k = 1; k <= n; k++) cin >> a[k];
sort(a + 1, a + 1 + n);
int mx = 1;
for (int k = n; k > 1; k--)
if (a[k] == a[k - 1])
mx++;
else {
ans = max(mx, ans);
mx = 1;
}
... | 4 |
#include <bits/stdc++.h>
using namespace std;
void rd(int &a) { scanf("%d", &a); }
void rd(int &a, int &b) { scanf("%d %d", &a, &b); }
void rd(int &a, int &b, int &c) { scanf("%d %d %d", &a, &b, &c); }
void rd(long long &a) { scanf("%lld", &a); }
void rd(long long &a, long long &b) { scanf("%lld %lld", &a, &b); }
void ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long double x, y, z;
cin >> x >> y >> z;
cout << setprecision(15)
<< ((x * x * x / 2.0L / sqrt(2.0L)) + (y * y * y / sqrt(2.0L)) +
(z * z * z * (5.0L + sqrt(5.0L)) / 8.0L)) /
3.0L;
return 0;
}
| 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
long long f[N][N][N], a[N];
char s[N];
int main() {
int n;
scanf(" %d %s", &n, s + 1);
for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
for (int i = 1; i <= n; i++) {
for (int j = 1; j < i; j++) {
a[i] = max(a[i], a[i - j] + a[j]);
... | 16 |
#include <bits/stdc++.h>
using namespace std;
void _print(long long t) { cerr << t; }
void _print(int t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(long double t) { cerr << t; }
void _print(double t) { cerr << t; }
void _print(unsigned long long t) { cerr << t; }
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, t;
scanf("%d%d%d", &n, &k, &t);
int a = t / k, b = t % k, ans;
if (t <= n)
ans = b + (a ? k - b : 0);
else {
int r = t - n;
a = n / k, b = n % k;
ans = b + (a ? k - b : 0);
ans -= r;
if (ans < 0) ans = 0;
}
printf... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1001;
int countof[MAXN];
int main() {
int n, l, x, minimum = 10000;
cin >> n >> l;
for (int i = 0; i < l; i++) {
cin >> x;
countof[x]++;
}
for (int i = 1; i <= n; i++) minimum = min(minimum, countof[i]);
cout << minimum;
return 0;
}
| 1 |
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+10;
int main()
{
int T;
cin>>T;
while(T--)
{
int a,b;
cin>>a>>b;
cout<<a-1<<' '<<b<<endl;
}
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200005, P = 998244353;
using ll = long long;
int n;
ll dp[N][3], pre[N], suf[N];
vector<pair<int, int>> v[N];
void dfs(int pos, int fa) {
int fp = -1;
for (int i = 0; i < int(v[pos].size()); i++) {
if (v[pos][i].first == fa) {
fp = i;
conti... | 21 |
#include <bits/stdc++.h>
using namespace std;
int sub_ans(int i, int idx, string s) {
if (!(i - 1)) return s[idx] == '4' ? 1 : 2;
return (1 << (i - 1)) * (s[idx] != '4') + sub_ans(i - 1, idx + 1, s);
}
int main() {
ios::sync_with_stdio(false);
string x;
cin >> x;
int ans = (1 << x.size()) - 2 + sub_ans(x.si... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main(){
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(ios::badbit | ios::failbit);
auto __solve_tc = [&](int __tc_num){
int n;
long long k;
cin >> n >> k;
if(n <= 61 && 1LL << n - 1 < k){
cout << "-1\n";
return 0;
}
-- k;
vector<int> res(n);
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int p[100005];
int d[100005];
int ans[100005];
int main() {
int n;
cin >> n;
for (int i = 1; i < n; i++) {
cin >> p[i];
p[i]--;
}
d[0] = 0;
for (int i = 1; i < n; i++) d[i] = d[p[i]] + 1;
int maxd = 0;
for (int i = 0; i < n; i++) maxd = max(maxd, d[i... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, q;
int pre[N], nxt[N];
int sq;
int num;
int cnt;
int now;
int c[N], f[N], t[N];
vector<int> need_resolve;
int calc_nxt(int x) {
int k = sq;
for (; k >= 4; k -= 4) {
x = nxt[nxt[nxt[nxt[x]]]];
}
for (; k--;) {
x = nxt[x];
}
... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<long long> h(n);
for (int i = 0; i < n; i++) {
cin >> h[i];
}
int l = 0, r = 1001001001;
while (l + 1 < r) {
int mid = (l + r) / 2;
vector<long long> w = ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int t;
cin >> t;
while (t--) {
long long int n;
cin >> n;
vector<int> a(n, 0);
long long int even = 0, odd = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (i... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, s, i, j, k, cnt = 1;
cin >> n;
s = pow(2, n);
if (n >= 13) {
i = n - 13;
j = pow(2, i);
s = pow(2, n) - 100 * j;
}
cout << s << endl;
}
| 11 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
const long double pi = acos(-1);
const long long maxn = 2e5 + 5;
const int mod = 1e9 + 7;
const long long INF = 1e18;
const int MX = 2000000001;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
long long t, q, ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int check[10000];
int main() {
int n, k, x;
cin >> n >> k;
for (int i = 0; i < k; i++) {
cin >> x;
check[x] = i + 1;
}
int counter = 0, j;
for (int i = 0; i < k; i++) {
counter = 0;
for (j = 1; j <= n * k; j++) {
if (check[j] == i + 1) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n % 2 == 0) {
cout << "Mahmoud";
} else
cout << "Ehab";
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const double PI = acos(-1.);
const double eps = 1e-15;
const int MOD = 1e9 + 7;
long long power(long long x, long long y) {
if (y == 0) return 1;
long long s = power(x, y / 2);
s *= s;
i... | 4 |
#include <bits/stdc++.h>
using namespace std;
int On(int N, int pos) { return N = N | (1 << pos); }
int Off(int N, int pos) { return N = N & ~(1 << pos); }
bool isOn(int N, int pos) { return (bool)(N & (1 << pos)); }
int main() {
int tc, cs;
int i, j, k;
int n;
cin >> n;
int arr[100005] = {0};
for (i = 0; i... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3005;
const int INF = 0x3f3f3f3f;
const int mod = 10000007;
const double eps = 1e-9;
int __ = 1, kase = 0;
int n, m, d[maxn][maxn];
vector<int> G[maxn];
void init() {}
void read() {
scanf("%d%d", &n, &m);
for (int i = 0; i < m; i++) {
int a, b;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long int bin(long long int a, long long int b) {
if (b == 0) return 1;
if (b & 1) return (a * bin((a * a) % 1000000007, b / 2)) % 1000000007;
return (1 * bin((a * a) % 1000000007, b / 2)) % 1000000007;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cou... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
struct Edge {
long long to;
long long cost;
long long from;
Edge(long long t, long long c, long long f = -1) : to(t), cost(c), from(f) {
;
}
};
long long n;
vector<vector<Edge> > G;
vector<int> subt;
long long count_visit(long long ind... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n, ans;
cin >> n;
ans = (n * (n - 1)) >> 1;
string s;
cin >> s;
vector<int> A, B;
for (int i = 0; i < int(n); i++) {
if (s[i] == 'A')
A.push_back(i);
else
B.push_ba... | 11 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")
const int N = (int)3e7 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const long long linf = (long long)1e18 + 7;
const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0,... | 19 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const int maxn = 100100;
long long exponentiation(long long A, long long B, long long MOD) {
long long ans = 1;
for (; B; A = (A * A) % MOD, B >>= 1)
if (B & 1) ans = (ans * A) % MOD;
return ans;
}
pair<int, int> tree[maxn << 2];
... | 20 |
#include <bits/stdc++.h>
using namespace std;
void solve(long long tc) {
long long n, m;
cin >> n >> m;
vector<long long> v(m);
vector<long long> ans(m);
long long s = 0;
for (long long i = 0; i < m; i++) cin >> v[i], s += v[i];
if (s < n) {
cout << "-1\n";
return;
}
ans[m - 1] = n - v[m - 1] ... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int maxn = 301;
int cl[maxn][maxn], cr[maxn][maxn], cd[maxn][maxn], cu[maxn][maxn];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m, t, tp, tu, td;
cin >> n >> m >> t >> tp >> tu >> td;
vector<vector<int>> gr(n + 1, v... | 15 |
#include <bits/stdc++.h>
#define N 100005
using namespace std;
#define putchar(c) cout << c
template <typename T>
void read(T &a)
{
cin >> a;
// T x = 0,f = 1;
// char ch = getchar();
// while (ch < '0' || ch > '9')
// {
// if (ch == '-') f = -1;
// ch = getchar();
// }
// while (ch >= '0' && ch <= '9')
... | 26 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int n;
char ch[3] =
{
0,
},
cm[3] = {
0,
};
scanf("%d", &n);
scanf("%2s:%2s", ch, cm);
int h = atoi(ch);
int m = atoi(cm);
if (n == 12) {
if (h == 0) {
ch[1] = '1';
} else if (h > 12... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
long long a, b, c;
for (int i = 1; i <= n; i++) {
cin >> a >> b >> c;
printf("%lld\n", a + b + c - 1);
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, a, b;
cin >> n >> a >> b;
string pre = "abcdefghijklmnopqrstuvwxyz";
string p = pre.substr(0, b), ans;
while (ans.size() <= n) {
ans += p;
}
ans = ans.substr(0, n);
cout << ans <<... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, arr[100000];
cin >> N;
for (int i = 0; i < N; cin >> arr[i++])
;
sort(arr, arr + N);
int res = 0;
for (int i = 0; i < N; i++) {
if (arr[i] != arr[0] && arr[i] != arr[N - 1]) {
res++;
}
}
cout << res;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
const long long inf = 1e18;
const int mo = 998244353;
int n;
long long a0;
long long a[N], p[N];
int s[N], ls[N];
void f(int x, long long y) {
for (; x <= n; x += x & -x) a[x] += y;
}
long long q(int x) {
long long r = a0;
for (; x; x -= x & -x... | 17 |
#include <bits/stdc++.h>
using namespace std;
double a, d, x, y;
double calc() {
double tt = 0.0000000;
double s1 = y * y / (2.000000 * a);
if (s1 <= d) {
double rem = d - s1;
tt = y / a;
tt += rem / y;
return tt;
}
return (sqrt((2 * d) / a));
}
int main() {
int n;
scanf("%d", &n);
scanf... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1001000;
long long a[N], b[N], c[N], sum[N];
struct Node {
long long l, r, num;
};
Node tree[4 * N];
map<int, int> m1, m2;
void build(long long l, long long r, long long o) {
tree[o].l = l, tree[o].r = r;
tree[o].num = 0;
if (l == r) return;
lo... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 45;
const long long maxk = 205;
double dp[maxk][maxn][maxn];
long long a[maxn];
long long n, x;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> x;
double N = n * (n + 1) / 2;
for (long long i = 0; i < n; i++)... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n, m, h, t;
vector<vector<int> > g;
int sizes[100 * 1000];
int minht, maxht;
void init() {
scanf("%d %d %d %d", &n, &m, &h, &t);
g.resize(n);
for (int i = 0; i < m; ++i) {
int from, to;
scanf("%d %d", &from, &to);
--from, --to;
g[from].push_back(to... | 12 |
#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int main() {
ios_base::sync_with_stdio(false);
string a, b;
cin >> a >> b;
int i, m = 0, n = 0, k, j;
for (i = 0; i < a.length(); i++) {
if (a[i] != b[i]) {
if (a[i] == '1')
m++;
else
n++;
}
}
if ((m - n) % 2)... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if ((n & (n - 1)) == 0)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int inp;
int num = 0, sum = 0;
scanf("%d", &inp);
n = inp * 2;
for (int i = 0; i < n; ++i) {
int x;
scanf("%*d%*c%d", &x);
sum += x;
if (x == 0) num++;
}
int ans = INT_MAX;
for (int i = 0; i <= inp; ++i) {
if (inp - ... | 10 |
#include <bits/stdc++.h>
using namespace std;
struct matrix {
int a[130][130];
};
struct matrix g, f, e;
struct unit {
int x;
vector<int> w;
};
struct unit a[30];
long long n;
int m, mod = 12345, ans;
int b[30], c[30];
bool cmp(struct unit aa, struct unit bb) { return aa.x > bb.x; }
int gcd(int i, int j) {
if (... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 10;
struct node {
int to;
long long dis;
node() {}
node(int a, long long b) : to(a), dis(b) {}
};
vector<node> g[maxn];
int dep[maxn], dfs[maxn], sum, tot[maxn], f[maxn], d[maxn][30], st;
long long dis[maxn], ans;
int lca(int x, int y) {
... | 23 |
#include <bits/stdc++.h>
using namespace std;
pair<long long, int> dp[66][2][2];
pair<long long, int> getmin(long long L, long long R, int b, bool ig, bool il) {
if (b == -1) {
return make_pair(0, 0);
}
if (dp[b][ig][il].second != -1) return dp[b][ig][il];
pair<long long, int> answer = make_pair(0, -1);
f... | 9 |
#include <bits/stdc++.h>
int N, res;
int v[1000010];
int main() {
scanf("%d", &N);
for (int i = 1; i <= N; ++i) {
int x;
scanf("%d", &x);
++v[x];
}
for (int i = 0; i < 1000010 - 1; ++i) {
res += (v[i] & 1);
v[i + 1] += (v[i] >> 1);
}
res += __builtin_popcount(v[1000010 - 1]);
printf("%... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const int G = 3;
#pragma GCC target("avx")
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("unroll-loops")
inline long long read() {
long long x = 0, f = 1;
char c = getchar();
while ... | 15 |
#include <bits/stdc++.h>
using namespace std;
int A, B, K, Cnt[1 << 20];
bool Prime[1 << 20];
vector<int> Primes;
int main(void) {
for (int i = 2; i <= 1000000; i++) {
Cnt[i] = Cnt[i - 1];
if (Prime[i]) continue;
for (int j = i; j <= 1000000; j += i) Prime[j] = true;
Primes.push_back(i);
Cnt[i]++;... | 8 |
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
struct Dinic {
static const int MXN = 100010;
struct Edge {
int v, f, re;
};
int n, s, t, level[MXN];
vector<Edge> E[MXN];
void init(int _n, int _s, int _t) {
n = _n;
s = _s;
t = _t;
for (int i = 0; i < n; i++) E[i]... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int UNDEF = -1;
const int INF = 2000000000;
const long long INF64 = 4000000000000000000;
const double PI = 3.1415926535897932384626433832795;
const double EPS = 1e-12;
template <typename T>
T sqr(const T &x) {
return x * x;
}
template <typename T>
const string GetSt... | 10 |
#include <bits/stdc++.h>
int n, m;
char map[200][200];
int st[200], en[200];
int abs(int x) { return x > 0 ? x : -x; }
int max(int a, int b) { return a > b ? a : b; }
int min(int a, int b) { return a > b ? b : a; }
int main() {
while (scanf("%d%d", &n, &m) == 2) {
for (int i = 1; i <= n; i++)
for (int j = 1... | 7 |
#include <bits/stdc++.h>
using namespace std;
vector<int> G[2 * 100 * 1000 + 5];
vector<int> dpMax, dpMin, leaves;
void dfs(int node, int l) {
if (G[node].empty()) {
dpMax[node] = dpMin[node] = leaves[node] = 1;
return;
}
for (auto v : G[node]) dfs(v, 1 - l);
int sum = 0, sum2 = 0, minn = 3e5, gminn = 3... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
long long int l = s.size(), lasta = 0, lastabefb = 0, i, ans = 0;
long long int arr[l + 1];
arr[0] = 0;
for (i = 0; i < l; i++) {
if (s[i] == 'a') {
arr[i + 1] = (1 + arr[lasta] + arr[lastabefb]) % 1000000007;
las... | 7 |
#include <bits/stdc++.h>
using namespace std;
struct wall {
int no, x, t;
friend bool operator<(wall a, wall b) {
if (a.x != b.x) return a.x < b.x;
return a.t < b.t;
}
} w[110000 << 1];
struct Point {
int x, y, type, no;
friend bool operator<(Point a, Point b) { return a.y - a.x < b.y - b.x; }
} p[110... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
int main() {
int N, K;
string S;
cin >> N >> K;
cin >> S;
set<char> second;
vector<char> V;
for (int i = 0; i < (int)S.size(); i++) {
second.insert(S[i]);
}
for (set<char>::iterator it = second.begin();... | 7 |
#include <bits/stdc++.h>
long long max(long long x, long long y) { return x > y ? x : y; }
long long min(long long x, long long y) { return x < y ? x : y; }
using namespace std;
const long long INF = 1e18 + 14;
const long long N = 4e6 + 9;
string s;
long long n, m;
long long op[N], cl[N];
struct node {
long long g = ... | 12 |
#include <bits/stdc++.h>
using namespace std;
ifstream fin("date.in");
ofstream fout("date.out");
struct data {
long long nr;
long long val;
long long parcurs;
} curent, adaugare;
bool operator<(data a, data b) {
if (a.parcurs == b.parcurs) return a.val > b.val;
return a.parcurs < b.parcurs;
}
priority_queue<... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f;
const int N = 2e5 + 10;
const long long mod = 998244353;
const bool debug = false;
long double F[N];
void init() {
for (int i = 1; i < N; ++i) F[i] = F[i - 1] + logl(i);
}
long double comb(int n, int m) { return F[n] - F[m] - F[n - m]; }
... | 16 |
#include <bits/stdc++.h>
using LL = long long;
const int maxn = 1011000;
const LL mod = 1000000123;
int seed = 29, n;
char str[maxn];
LL base[maxn], Hash[maxn];
int ans[maxn];
void init() {
memset(base, 0, sizeof(base));
base[0] = 1;
for (int i = 1; i < maxn; i++) {
base[i] = base[i - 1] * seed;
base[i] %... | 19 |
#include <bits/stdc++.h>
using namespace std;
int next_state[110][4], max_len[110];
int dp[1010][15][110];
const int MOD = 1000000009;
int main() {
memset(max_len, -1, sizeof(max_len));
int N, M;
cin >> N >> M;
vector<string> pat(M);
for (int i = 0; i < M; i++) {
cin >> pat[i];
}
vector<string> pfx;
... | 17 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int inf = 1e7;
template <typename T>
T maxi(T x, T y) {
return (x > y) ? x : y;
}
template <typename T>
T mini(T x, T y) {
return (x < y) ? x : y;
}
long long modExpo(long long a, long long b, long long c) {
if (b == 0)
return ... | 11 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.