solution stringlengths 52 181k | difficulty int64 0 6 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int n, cnt = 1;
int main() {
cin >> n;
while (cnt * 2 <= n) cnt *= 2;
if (n % 2) return cout << (n - 1) / 2, 0;
cout << (n - cnt) / 2;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int MODULO = 1000003;
const int NMAX = 700005;
int n, C, comb[NMAX], fact[NMAX], factinv[NMAX];
int sol;
int Log(int x, int y) {
int p = 1;
while (y) {
if (y & 1) p = (1LL * p * x) % MODULO;
x = (1LL * x * x) % MODULO;
y >>= 1;
}
return p;
}
int Co... | 4 |
#include <bits/stdc++.h>
using namespace std;
vector<int> edges[300005], vis(300005), ans(300005);
vector<set<int> > color(300005);
void bfs(int i) {
queue<int> q;
q.push(0);
while (!q.empty()) {
int clr = 1;
int u = q.front();
q.pop();
set<int> st;
vis[u] = 1;
for (auto i : color[u]) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
class CDiscreteAcceleration {
public:
void solveOne(std::istream &in, std::ostream &out) {
int n;
in >> n;
double l;
in >> l;
double a[n];
for (int i = 0; i < n; ++i) in >> a[i];
double lpos = 0, rpos = l, ls = 1, rs = 1, t = 0;
int lp = 0... | 3 |
#include <bits/stdc++.h>
using namespace std;
int T;
int a, b, c;
int main() {
cin >> T;
while (T--) {
cin >> a >> b >> c;
if (a < b) swap(a, b);
if (a < c) swap(a, c);
if (b < c) swap(b, c);
int ans = 0;
if (a) ans++, a--;
if (b) ans++, b--;
if (c) ans++, c--;
if (a && b) ans++,... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long faktori[30][65];
long long djelitelji[2][30];
int main() {
long long n, b;
cin >> n >> b;
int brd = 0;
for (long long i = 2; i * i <= b; i++) {
if (b % i == 0) {
djelitelji[0][brd] = i;
while (b % i == 0) {
djelitelji[1][brd]++;
... | 3 |
#include <bits/stdc++.h>
int main() {
int n, evn = 0, odd = 0, o, e;
scanf("%d", &n);
int a[n];
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
for (int i = 0; i < n; i++) {
if (a[i] % 2 == 0) {
evn++;
e = i + 1;
} else {
odd++;
o = i + 1;
}
}
if (evn > odd)
... | 1 |
#include <bits/stdc++.h>
int main() {
int n, t;
scanf("%d %d", &n, &t);
if (n < 2 && t == 10)
printf("-1");
else if (t == 10) {
printf("10");
for (int i = 0; i < n - 2; i++) {
printf("0");
}
} else {
for (int i = 0; i < n; i++) {
printf("%d", t);
}
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5, M = 1e3 + 5, mod = 1e9 + 7;
template <typename T>
bool chmin(T& a, T b) {
return (b < a) ? a = b, 1 : 0;
}
template <typename T>
bool chmax(T& a, T b) {
return (b > a) ? a = b, 1 : 0;
}
long long read() {
long long s = 0, f = 1;
char ch = getc... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long x, y;
int tc;
cin >> tc;
while (tc--) {
cin >> x >> y;
if (x - 1 == y) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
}
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
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... | 4 |
#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
using namespace std;
typedef long long int int64;
typedef unsigned long long uint64;
int main(){
int n; cin >> n;
vector<int> a(n);
rep(i ,n) cin >> a[i];
int q; cin >> q;
rep(i ,q){
int com, b , e;
int _min , _m... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double a, b, c, d, e, f;
cin >> a >> b >> c >> d >> e >> f;
if (a == 0 && b != 0 && d != 0)
cout << "Ron";
else if (c == 0 && d != 0)
cout << "Ron";
else if ((b / a) * (d / c) * (f / e) > 1)
cout << "Ron";
else
cout << "Hermione";
}
| 1 |
//Code written by @pulkit0795
#include <iostream>
#include <vector>
#include <map>
#include <set>
using namespace std;
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t;
cin >> t;
while (t--)
{
int n, first;
c... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<vector<pair<int, int> > > edges(n + 1);
vector<bool> edgeisinserted(n - 1, 0);
vector<int> Directnodes(n + 1, 0);
int a = 0, b = 0;
for (int i = 0; i < n - 1; i++) {
scanf("%d %d", &a, &b);
edges[a].push_back(pair<i... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T bigmod(T b, T p, T m) {
if (p == 0) return 1;
T res = bigmod(b, p / 2, m);
res = (res * res) % m;
if (p % 2 == 1) res = (res * b) % m;
return res;
}
int main() {
int i, j, k, n, m, d, a[10];
while (cin >> n) {
for (i = 0; i < 7; i++) c... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
return (b == 0) ? a : gcd(b, a % b);
}
string add(char c, int l) {
string t;
while (l--) t += c;
return t;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
string s;
cin... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.141592653589793238462643l;
void solve();
int main() {
solve();
return 0;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
void solve() {
long long a, b, x1, y1, x2, y2;
cin >> a >> b >> x1 >> y1 >> x2 >> y2;
long... | 2 |
#include <bits/stdc++.h>
using namespace std;
inline int Read() {
char c = getchar();
int num = 0;
while ('0' > c || c > '9') c = getchar();
while ('0' <= c && c <= '9') num = num * 10 + c - '0', c = getchar();
return (num);
}
long long mn, s0, s1;
int nm[1000010 * 2], n, a[1000010], ans, n0, n1;
inline int A... | 2 |
#include <bits/stdc++.h>
using namespace std;
char s1[100000 + 2], s2[32];
int main() {
scanf("%s%s", s1, s2);
int len1 = strlen(s1), len2 = strlen(s2);
int ans = 0;
for (int i = 0, j = 0; i < len1; i++) {
while (s1[i] == s2[j] && j < len2 && i < len1) {
i++, j++;
}
if (j == len2) {
ans+... | 2 |
#include<bits/stdc++.h>
using namespace std;
int n,m;
int p[100005];
int y[100005];
vector<int>v[100005];
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++){
scanf("%d%d",&p[i],&y[i]);
v[p[i]].push_back(y[i]);
}
for(int i=1;i<=n;i++) sort(v[i].begin(),v[i].end());
for(int i=1;i<=m;i++){
printf("%06d",p... | 0 |
#include <bits/stdc++.h>
const double EPS = 1e-7;
const double PI = 3.1415926535897932384626;
const int MAXN = 222222;
const int MOD = 1000000007;
int n, a[MAXN], pred[MAXN], succ[MAXN];
std::vector<std::pair<int, int> > group;
int fpm(int a, long long b) {
int ret = 1;
for (; b; b >>= 1) {
if (b & 1) ret = 1ll... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
const int K = 100005;
int n, m, k;
int t, p;
int l[N], c[N], x[K];
int main() {
scanf("%d%d%d", &n, &m, &k);
x[0] = 0;
for (int i = 1; i <= k; ++i) {
scanf("%d%d%d", &t, &p, &x[i]);
if (t == 1)
l[--p] = i;
else
c[--p] = i;
... | 2 |
#include <iostream>
using namespace std;
int main(){
int n,s[12],o[12];
while(cin>>n){
if(!n)break;
int step=-1;
for(int i=0;i<n;++i) cin>>s[i];
for(int f=1;f;++step){
for(int i=0;i<n;++i) o[i]=s[i];
for(int i=0,count=0;i<n;++i){
count=0;
for(int j=0;j<n;++j){
if(o[i]==o[j])++count;
}
... | 0 |
#include <stdio.h>
int main(void)
{
int a[101];
int n;
int i;
for (i = 0; i < 101; i++){
a[i] = 0;
}
while (scanf("%d", &n) != EOF){
a[n]++;
if (a[0] < a[n]){
a[0] = a[n];
}
}
for (i = 1; i <= 100; i++){
if (a[i] == a[0]){
printf("%d\n", i);
}
}
return (0);
} | 0 |
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;
const int INF = 1001001001;
int main() {
int n, m, l;
cin >> n >> m >> l;
vector<vector<int>> dist(n, vector<int>(n, INF));
rep(i, n) dist[i][i] = 0;
rep(i, m... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 25;
const int inf = 1000000000;
int main() {
int n;
scanf("%d", &n);
int n1 = n / 2;
int n2 = n - n1;
vector<int> pow3(n2 + 1);
pow3[0] = 1;
for (int i = 1; i <= n2; i++) pow3[i] = 3 * pow3[i - 1];
int d[maxn][3];
for (int i = 0; i < n; i+... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int nmax = 2e5 + 42;
int n, inp[nmax];
int least[nmax * 2];
int outp;
vector<int> seen[nmax];
void solve_small(int big, int small) {
for (int i = 1; i + 1 < seen[small].size(); i++)
for (int j = i; j + 1 < seen[small].size(); j++) {
int l = lower_bound(see... | 4 |
#include <cstdio>
#include <cstring>
using namespace std;
#define rep(i,l,r) for (int i=(l);i<=(r);i++)
const int maxn=20;
int a[maxn],b[maxn];
bool u[maxn];
int n,m;
int main() {
while (scanf("%d%d\n",&n,&m),n+m) {
rep(i,1,n) scanf("%d",a+i);
rep(i,1,m) scanf("%d",b+i);
memset(u,true,sizeof(u));
rep(i,1,m) ... | 0 |
#include<cstdio>
#include<string.h>
int main(){
int i,j;
char s[12]={},t[12]={};
for(;~scanf("%s",s);printf("%d\n",*s)){
for(i=0;i<12;++i)s[i]-=48;
for(i=0;i<9;memcpy(s,t,12),++i)
for(j=0;i<9-j;++j)
t[j]=(s[j]+s[j+1])%10;
}
} | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, N, b[300000], c[300000];
long long f[300000], a[300000];
bool cmp(int x, int y) { return a[x] < a[y]; }
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%lld", &a[i]), c[i] = i;
sort(c + 1, c + n + 1, cmp);
for (int i = 1; i <= n; i++) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, s;
cin >> n >> s;
int arr[n], brr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
for (int i = 0; i < n; i++) {
cin >> brr[i];
}
if (arr[0] == 0)
cout << "NO";
else if (arr[0] == 1 && arr[s - 1] == 1)
cout << "YES";
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int limN = 1005;
int ans[limN][limN];
int main() {
int n, d, k;
scanf("%d%d%d", &n, &k, &d);
if (n == 1) {
for (int i = 0; i < d; i++) printf("1\n");
return 0;
}
if (k >= n) {
for (int i = 0; i < d; i++) {
for (int j = 1; j <= n; j++) print... | 3 |
#include <bits/stdc++.h>
using namespace std;
vector<int> G[101];
bool V[101];
bool Vis[101];
int DP[101];
int N;
int Ans = 0;
void DFS(int n,int len){
Ans = max(Ans,len);
DP[n] = max(DP[n],len);
int S = G[n].size();
for(int i=0;i<S;i++){
if(!V[G[n][i]]){
Vis[G[n][i... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
const int maxn = 2e5 + 5;
int Bit[maxn], A[maxn], n;
pair<int, int> P[maxn];
void Update(int i) {
while(i <= n) {
Bit[i]++;
i += i&(-i);
}
}
int Getsum(int i) {
int res = 0;
while(i) {
res += Bit[i];
... | 0 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
int n, cnt;
int ans[1005];
bool prime(int x) {
for (int i = 2; i < x; i++)
if (x % i == 0) return 0;
return 1;
}
int main() {
scanf("%d", &n);
for (int i = 2; i <= n; i++) {
if (!prime(i)) continue;
i... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, i, j, sum, res[100001], m, a[100001], q, k;
map<int, bool> u[100001];
int main() {
scanf("%d %d", &n, &m);
q = 100000;
for (i = 1; i <= n; i++) {
scanf("%d", &a[i]);
u[a[i]][a[i]] = 1;
q = min(q, a[i]);
}
while (m--) {
scanf("%d %d", &i, &j)... | 4 |
#include <bits/stdc++.h>
using namespace std;
string i2s(int a) {
string res = "";
while (a > 0) {
res += char(a % 10 + '0');
a /= 10;
}
return res;
}
int s2i(string s) {
int res = 0;
int j = 1;
for (int i = 0; i < s.length(); i++) {
res += int(s[i] - '0') * j;
j *= 10;
}
return res;
}... | 1 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> B[100005];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
int k, a;
scanf("%d%d", &k, &a);
B[i] = make_pair(k, a);
}
sort(B, B + n);
for (int i = 1; i < n; ++i) {
int p = 2 * (B[i].first - B[i - 1].first);
i... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigmod(T p, T e, T M) {
long long ret = 1;
for (; e > 0; e >>= 1) {
if (e & 1) ret = (ret * p) % M;
p = (p * p) % M;
}
return (T)ret;
}
template <class T>
inline T gcd(T a, T b) {
if (b == 0) return a;
return gcd(b, a % b);
}
... | 5 |
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
int n; cin >> n;
vector<ll> A(n + 1, 0), greedy(n + 1, 0), dp(n + 1, 0);
for(int i = 1; i <= n; i ++) cin >> A[i];
greedy[1] = A[1];
for(int i = 3; i <= n; i += 2){
greedy[i] = greedy[i - 2] + A[i];
}
for(int i = 2; i <= n; i ++... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[1004], t[1004];
int main() {
for (int i = 0; i < 1004; i++) a[i] = 2147483647;
scanf("%d", &n);
int i = 0, k = 1;
for (k = 1; k <= n; k <<= 1) i++;
for (i--; i >= 0; i--) {
for (int j = 0; j < 2; j++) {
int ts = 0;
for (int k = 1; k <=... | 2 |
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vector<int> v(n);
for (auto &e : v) cin >> e;
long long int sum = 0, ans = 0;
map<long long int, int> mp;
mp[0] = 1;
for (auto e : v) {
sum += e... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
char a[1000009], b[1000009];
long long num[30], n, rev[1000009], ans = 1;
long long pw(long long u, long long v) {
if (v == 1) return u;
long long res = pw(u, v / 2);
res = (res * res) % mod;
if (v % 2 > 0) res = (res * u) % mod;
return... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int s[n];
int e[n];
for (int i = 0; i < n; i++) {
cin >> s[i] >> e[i];
}
int i = n - 1;
for (; i >= 0; i--)
if (s[i] <= m && e[i] >= m) break;
int j = i;
while (i >= 0) {
if (s[i] <= s[j] && e[i] >= s[j])... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, ans = 0, i, j;
long long a[13];
for (n = 1; n <= 12; ++n) {
ans = 0;
for (i = 0; i < 9; ++i) {
for (j = 0; j < 9; ++j) {
if (i >= 1 && j >= 5) continue;
... | 2 |
#include <bits/stdc++.h>
int arr[100005], arr2[100005];
int n, a, c, g, t, q, max1, sum;
using namespace std;
void O_o() {
ios::sync_with_stdio(0);
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
}
int main() {
O_o();
bool b = 0;
string s;
cin >> n;
cin >> s;
for (int i = 0; i < s.size(); i++) ... | 2 |
#include <bits/stdc++.h>
#ifdef DEBUG
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif
#ifdef __WIN32
#define LLFORMAT "I64"
#define Rand() ((rand() << 15) + rand())
#else
#define LLFORMAT "ll"
#define Rand() (rand())
#endif
using namespace std;
const int maxn = 6, maxc = 51, maxm = m... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long t, n, x, y;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> t;
while (t--) {
cin >> n >> x >> y;
if (x > y) swap(x, y);
long long tot = x + y;
int guy;
if (x == n)
guy = tot - (n - 1) + 1;
else
guy =... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void rd(T &x) {
x = 0;
char c = getchar();
int f = 1;
while (!isdigit(c)) {
if (c == '-') f = -1;
c = getchar();
}
while (isdigit(c)) x = x * 10 - '0' + c, c = getchar();
x *= f;
}
const int N = 150010, mod = 998244353;
int Po... | 4 |
#include <bits/stdc++.h>
const long long max9 = 10 + 1e9, max6 = 10 + 1e6, max12 = 10 + 1e12,
max15 = 10 + 1e15;
const long long min6 = -1 * max6, min9 = -1 * max9, min12 = -1 * max12,
min15 = -1 * max15;
const long long R = 7 + 1e9, NN = 10 + 1e5;
using namespace std;
int main() {
ios... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5;
int inf = 1e9;
struct seg {
int l, r, mid, ma = 0, lz = 0;
seg *ch[2] = {NULL, NULL};
void push() {
for (auto &i : ch) i->lz += lz, i->ma += lz;
lz = 0;
}
void add(int _l, int _r, int val) {
if (_l <= l and _r >= r) {
lz += val... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
long long int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
int mp = 0;
int mn = INT_MIN;
long long int s = 0;
int p = 0, ne = 0;
for (int i = 0; i < n; i++) {
if (... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000000;
int cnt[N + 1];
int check[N + 1];
set<pair<int, int> > s;
int main() {
int n, A;
scanf("%d %d", &n, &A);
for (int i = 1; i <= N; i++) {
cnt[i] = 0;
s.insert({cnt[i], i});
}
for (int i = 0; i < n; i++) {
int foo;
scanf("%d", &... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MX = 200005;
int h, a[MX];
int hed[MX];
int main() {
ios::sync_with_stdio(false);
cin >> h;
for (int i = 0; i <= h; i++) cin >> a[i];
int it = -1;
for (int i = 1; i <= h; i++)
if (a[i] > 1 && a[i - 1] > 1) {
it = i;
break;
}
if (it ... | 1 |
#include <bits/stdc++.h>
int T;
long long a, m, ans;
long long gcd(long long a, long long b) {
while (b) a %= b, std::swap(a, b);
return a;
}
int main() {
scanf("%d", &T);
while (T--) {
scanf("%lld%lld", &a, &m);
ans = gcd(a, m), a /= ans, m /= ans, ans = m;
for (long long i = 2; (long long)i * i <=... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 7;
const int SS = 4 * N;
struct Query {
int l, r, val;
};
int add[SS], seg[SS];
vector<Query> q[N];
vector<int> cy, cx;
int xl[N], yl[N], xr[N], yr[N];
void comp(vector<int> &v) {
sort(v.begin(), v.end());
v.resize(unique(v.begin(), v.end()) - v.be... | 4 |
#include <bits/stdc++.h>
int main() {
int i, n, m, j, k, c;
scanf("%d %d", &n, &m);
i = 1;
c = 1;
while (i <= n) {
if (i % 2 != 0) {
j = 0;
while (j < m) {
printf("#");
j++;
}
} else {
if (c % 2 != 0) {
printf("\n");
k = 0;
while (k < m -... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long double pi = acos(-1);
long long n, m, k;
int main() {
cin.tie(0);
cin.sync_with_stdio(0);
int t = 1;
while (t--) {
cin >> n;
int o = 0, tw = 0;
for (int i = 0; i < n; i++) cin >> m, o += m == 1, tw += m == 2;
if (tw) cout << "2 ", tw--;
... | 1 |
#include <bits/stdc++.h>
const long long MOD = 1e9 + 7;
using pii = std::pair<long long, long long>;
using namespace std;
const long long maxn = 1e5 + 5;
long long n, a, r, m, h[maxn], pref[maxn], alth[maxn];
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> a >> r >> m;
for (long long ... | 5 |
#include <bits/stdc++.h>
static const int MAXN = 53;
static int n, m;
static bool a[MAXN][MAXN];
int main() {
scanf("%d%d", &n, &m);
getchar();
for (int i = 0; i < n; ++i) {
for (int j = 0; j <= m; ++j) {
a[i][j] = (getchar() == '#');
}
}
for (int i = 0; i < n - 1; ++i) {
for (int j = i + 1;... | 1 |
#include<cstdio>
#include<ctime>
#include<iostream>
using namespace std;
const int md=924844033;
long long dp[2010];
int a[2010];
bool vis[2010];
int f[2010][2010][2];
long long fac[2010];
int n,k;
int main(){
// freopen("c.in","r",stdin);
// freopen("c.out","w",stdout);
scanf("%d%d",&n,&k);
fac[0]=1;
for(int i=1;i<... | 0 |
#include <bits/stdc++.h>
using namespace std;
int N;
long long pow2[128], sum, csum;
char cline[1024];
int main() {
sum = 0;
scanf("%s", cline);
N = strlen(cline);
pow2[0] = 1;
for (int i = 1; i < 128; i++) pow2[i] = (pow2[i - 1] * 2) % 1000000007;
for (int i = 0; i < N; i++) {
if (cline[i] == '1') {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, k, a, b, x;
vector<pair<int, int>> v, w;
bool xd(pair<int, int> a, pair<int, int> b) {
return a.first + a.second > b.first + b.second;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
for (int i = 0; i < n; ++i) {
cin >> a >> b;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[110][110];
bool b[110][110];
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
scanf("%d", &a[i][j]);
}
}
memset(b, 1, sizeof(b));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <=... | 2 |
#include <bits/stdc++.h>
using namespace std;
int ans[60];
int main(void) {
int N, i;
long long K;
cin >> N >> K;
K--;
int L = 0, R = N;
long long two = (1ll << (N - 1));
for ((i) = 0; (i) < (int)(N); (i)++) {
if (K < two / 2) {
ans[L] = i;
L++;
} else {
ans[R - 1] = i;
R--... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int Way[4][2] = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};
const double pi = acos(0.0) * 2;
const int INF = 1000000000;
const int N = 1000000 + 10;
int a[N], b[N], f[N], Ans, n;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
Ans = 1;
f... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
long long int t;
cin >> t;
while (t--) {
long long int n;
cin >> n;
long long int arr[n + 1];
for (long long int i = 0; i < n; i++) {
cin >> arr[i];
}
... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long sqr(long long a) { return a * a; }
long long ints[110][110], dp[110][110];
int main() {
long long n, m;
cin >> n >> m;
for (long long i = 0; i < n; i++) {
long long k;
cin >> k;
for (long long j = 0; j < k; j++) {
long long l, r;
cin ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 400 + 10;
int ups[maxn][maxn], lf[maxn][maxn];
int zx[maxn][maxn], yx[maxn][maxn], n, m;
char a[maxn][maxn];
void Init() {
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
ups[i][j] = ups[i - 1][j] + a[i][j] - '0';
lf[i][j] = ... | 4 |
#include <bits/stdc++.h>
using namespace std;
constexpr int MOD = 1e9 + 7;
constexpr int MAXN = 2e5 + 1;
using ll = long long;
int N, M, K;
bool is[100];
void Solution() {
is[1] = is[7] = is[9] = 1;
if (((N > 9 && N < 30) || is[N / 10] || is[N % 10]) && N != 12)
cout << "NO\n";
else
cout << "YES\n";
}
int... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(10);
long long l, r;
scanf(" %lld %lld", &l, &r);
for (int i = 59; i >= 0; i--)
if ((r >> i) ^ (l >> i)) {
printf("%lld\n", (1LL << (i + 1)) - 1);
return 0;
}
pr... | 4 |
#include <bits/stdc++.h>
using namespace std;
string s;
int l, r, m;
int main() {
cin >> s;
while (s.size() != 3 && s.size() != 7) {
l = 0, r = 1;
do {
cout << "? " << l << " " << r << endl;
cin >> s;
if (s == "y") l = r, r <<= 1;
} while (s == "y");
while (l + 1 < r) {
m = (... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
vector<long long> a(n);
for (long long i = 0; i < n; i++) {
cin >> a[i];
}
vector<long long> dp(n + 1, 100000000000);
vector<long long> rdp(n, 0);
vector<long long> ldp(n, 0);
rdp[n - 1] = 1;
ldp[0] = 1;
for (lon... | 4 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
int n, y, i, j;
scanf("%d", &n);
map<int, int> m;
for (i = 0; i < n * n; ++i) {
scanf("%d", &y);
m[-y]++;
}
int v[1000];
int pos = n - 1;
for (map<int, int>::iterator it = m.be... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7, inv_2 = (mod + 1) / 2;
void Inc(int &x, int y) { x += y, x -= x >= mod ? mod : 0; }
void Dec(int &x, int y) { x -= y, x += x < 0 ? mod : 0; }
int mul(int x, int y) { return 1LL * x * y % mod; }
const int N = 1 << 16;
void fwt_and(vector<int> &f, int... | 5 |
#include <bits/stdc++.h>
using namespace std;
int inf = 1e9;
const int N = 2e5 + 10;
int n, m, cnt;
int a[N], ans[N];
map<int, int> mp;
set<int> st;
vector<int> v;
long long sum = 0, p;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >>... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct data {
int v;
int no;
int top;
} qun[49];
int ji[49];
int q[1009];
int cmp(data a, data b) {
if (a.v == b.v) return a.no < b.no;
return a.v > b.v;
}
int main() {
int n, m;
scanf("%d%d", &n, &m);
int i, j;
for (i = 0; i < m; i++) {
scanf("%d", &q... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, arr[1000009], j = 1, m;
memset(arr, 0, sizeof arr);
cin >> n;
for (int i = 1; i <= n; i++) {
int a;
cin >> a;
for (int k = 0; k < a; k++) {
arr[j++] = i;
}
}
cin >> m;
for (int i = 0; i < m; i++) {
int a;
cin >... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long M = 2e5 + 5;
const long long INF = 1e15 + 5;
const long long MOD = 1e9 + 7;
const long long N = 1e5 + 5;
const double PI = 3.14159265358979323846264338327950288419716939937510;
long long n, m, flag, l[105], r[105], b[105], c[105];
vector<long long> adj[M];
v... | 4 |
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
ll bit[400010],a[200010],b[200010],p[100010],x[100010],y[100010],n,q,inv[300010],m;
vector<ll> v;
map<ll,ll> mp;
ll sum(ll i){
ll s = 0;
while(i>0){
s += bit[i];
i -= i&-i;
}
return s;
}
void ad... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, p, w, d;
scanf("%lld%lld%lld%lld", &n, &p, &w, &d);
for (long long i = 0; i < d && i <= n && p - i * w >= 0; i++) {
if ((p - i * w) % d == 0) {
long long k = min((n - i) / d, (p - i * w) / (w * d));
long long x = i + k * d;
... | 3 |
#include<bits/stdc++.h>
using namespace std;
const long long mod = 1000000007LL;
int main(){
long long n;
cin >> n;
long long a = 1;
long long b = 1;
long long c = 1;
for(long long i = 1;i <= n;i++){
a = a *10 % mod;
b =b * 9 % mod;
c =c * 8 % mod;
}
cout << ((a - 2 * b + c) % mod + mod) % m... | 0 |
#include <iostream>
using namespace std;
int main() {
int k;
cin>>k;
cout<<k/2*(k-k/2)<<endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<set<int> > g;
vector<set<int> > leaves;
struct comp {
bool operator()(int a, int b) const {
if (leaves[a].size() == leaves[b].size()) return a < b;
return leaves[a].size() > leaves[b].size();
}
};
int main() {
int t;
cin >> t;
while (t--) ... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long n, ll, rr, dd, ans = 0, vv;
void init() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> dd >> vv >> ll >> rr;
ans = dd / vv;
ans = ans - (rr / vv - (ll - 1) / vv);
cout << ans << endl;
}
}
int main() {
init();
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
int x[200005], y[200005];
int sgn[200005];
int par[200005];
vector<int> g[200005];
bool check(int a, int b, long long th) {
int icap = x[a] + x[b];
int jcap = y[a] + y[b];
long long z = 1LL * icap * icap + 1LL * jcap * jcap;
return (z <= th);
}
bool checkR(int a, in... | 3 |
#include<cstdio>
#define LL long long
int t;
LL a,b,c,d;
LL gcd(LL a,LL b)
{
if(!b) return a;
return gcd(b,a%b);
}
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
if(a<b) printf("No\n");
else if(d<b) printf("No\n");
else if(c>=b) printf("Yes\n");
else if(b-gcd(b,d)+a%gcd(... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5 + 1e5, MOD = 7 + 1e9;
typedef struct node {
int hp, ak, df;
} node;
node y, m;
bool ok(int i, int j, int k) {
node a;
a.hp = i + y.hp, a.ak = j + y.ak, a.df = k + y.df;
int dt = max(0, m.ak - a.df), dt1 = max(0, a.ak - m.df);
if (dt1 == 0) retur... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
int k;
cin >> k;
int arr[n];
for (int i = 0; i < n; i++) cin >> arr[i];
int mx = k;
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j <= n - 1; j++) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const signed int inf = (signed)(~0u >> 1);
const signed int llf = (signed int)(~0ull >> 1);
template <typename T>
inline void readInteger(T& u) {
static char x;
while (!isdigit(x = getchar()))
;
for (u = x - '0'; isdigit(x = getchar()); u = u * 10 + x - '0')
;... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<int long long> v;
int long long n;
cin >> n;
if (n == 1) {
cout << 1 << endl;
return 0;
}
for (int long long i = 2; i * i <= n; i++) {
if (n % i == 0) {
while (n % i == 0) n /= i;
v.push_back(i);
}
}
if (n > 1)... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, c, count = 1, i;
scanf("%d%d", &n, &c);
int arr[n];
for (i = 0; i < n; i++) scanf("%d", &arr[i]);
for (i = 1; i < n; i++) {
if (arr[i] - arr[i - 1] <= c)
count++;
else
count = 1;
}
printf("%d\n", count);
return 0;
}
| 1 |
#include <bits/stdc++.h>
using i64 = long long;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, m;
std::cin >> n >> m;
std::vector<std::string> s(n);
for (int i = 0; i < n; i++) {
std::cin >> s[i];
}
int ans = 0;
std::vector<bool> less(n - 1);
for (int j = 0; j < m; ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int room[51];
double dp[51][51][51];
int m;
long long comb[60][60];
void count() {
for (int i = 0; i < 51; ++i) {
for (int j = 0; j < 51; ++j) {
if (j == 0)
comb[i][j] = 1;
else if (i == 0)
comb[i][j] = 0;
else
comb[i][j] = co... | 3 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=3e5+10;
struct point{int l,r;}a[N];
int n,m,tot,ans,c[N];
vector<int>vec[N];
int sum(int x){int ret=0;while(x)ret+=c[x],x-=x&-x;return ret;}
void add(int x,int y){while(x<=n)c[x]+=y,x+=x&-x;}
int main()
{
scanf("%d%d",&m,&n);
for(int i=1;i... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int main(){
int n, k;
scanf("%d%d", &n, &k);
long ans = 0;
for(int i = k; i <= n + 1; i++)
ans += (long)(n-i+1)*i + 1;
printf("%ld\n", ans % MOD);
} | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > g[100001];
bool vis[100001];
int dis[100001];
int num[100001];
int fa[100001];
int n, m;
int use[100001];
vector<pair<pair<int, int>, int> > ans;
void spfa() {
queue<int> q;
q.push(1);
dis[1] = 0;
vis[1] = 1;
while (!q.empty()) {
int u ... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long data[111111];
int main() {
int n;
while (cin >> n) {
long long e = 0, ans = 0;
for (int i = 0; i != n; i++) {
int tmp;
cin >> tmp;
while (e > 0) {
if ((tmp ^ data[e]) > ans) ans = (tmp ^ data[e]);
if (tmp > data[e])
... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x) {
x = 0;
char c = getchar();
bool flag = false;
while (!isdigit(c)) {
if (c == '-') flag = true;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
if (flag)... | 4 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.