solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int b[31][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j <= 30; j++) {
b[j][i] = a[i] % 2;
a[i] = a[i] / 2;
}
}
int pr[31][n + 1];
f... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const double eps = 1e-10;
const int INF = 0x3f3f3f3f;
const long long INFLL = 0x3f3f3f3f3f3f3f3f;
const int MAXN = 1e6 + 5;
int a[MAXN];
int n, m;
int check(int i) {
if (i % m != 0)
if (abs(a[i] - a[i - 1]) == 1 || abs(a[i] - a[i - 1]) =... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int FFTMOD = 119 << 23 | 1;
const int INF = (int)1e9 + 23111992;
const long long LINF = (long long)1e18 + 23111992;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
inline long long gcd(long long a, long long b)... | 19 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int e, w, idx;
node(int ee, int ww, int ii) { e = ee, w = ww, idx = ii; }
node() {}
};
struct p {
int idx;
long long d;
p() {}
p(long long dd, int ii) { d = dd, idx = ii; }
bool operator<(const p &a) const { return d > a.d; }
};
int n, m, u;
ve... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[105];
int t;
cin >> t;
while (t--) {
memset(a, 0, sizeof(a));
int n;
int b[105];
cin >> n;
for (int i = 0; i < n; i++) {
cin >> b[i];
a[b[i]]++;
}
int ans = 0;
int len = 2;
for (int i = 0; i < 102; i... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
set<pair<string, string>> s;
while (n--) {
string oldStr, newStr;
cin >> oldStr >> newStr;
auto it = s.lower_bound(make_pair(oldStr, ""));
if (it != s.end() && it->first == oldStr) {
s.insert(make_pair(newStr, it->... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long const LIM = 1e6;
long long n, a[LIM], cnt[LIM], answer;
void dfs(long long u) {
if (u > (1 << (n + 1)) - 1) return;
dfs(2 * u);
dfs(2 * u + 1);
cnt[u] = max(cnt[2 * u] + a[2 * u], cnt[2 * u + 1] + a[2 * u + 1]);
long long diff =
cnt[u] - min(cnt[2 ... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long N, x[100005], d[100005];
int main() {
cin >> N;
for (int i = 1; i <= N; i++) {
cin >> x[i] >> d[i];
}
for (int i = 1; i <= N; i++) {
for (int j = i + 1; j <= N; j++) {
if (x[i] + d[i] == x[j] && x[j] + d[j] == x[i]) {
cout << "YES" <<... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long a[100005];
long long gcd(long long a, long long b) {
if (b == 0) {
return a;
} else
return gcd(b, a % b);
}
int main() {
long long i, n;
string s, h;
cin >> s;
if (s.length() == 1) {
if (s == "4" || s == "8" || s == "0")
cout << 4 << ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> arr;
for (int i = 0; i < n; i++) {
int p;
cin >> p;
arr.emplace_back(p);
}
int anst = -1;
int ansum = INT_MAX;
for (int k = 1; k <= 100; k++) {
int sum = 0;
for (int j = 0; j < arr.size(); j++) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10, LG = 150;
long long a[N], c[N], p[N], dp[N][2];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
c[i] = __builtin_popcountll(a[i]);
}
dp[0][0] = 1;
p[0]... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
string s;
cin >> s;
long long int x = 0, sum = 0;
for (int i = 0; i < n / 2; i++) {
if (s[i] == '?')
x++;
else
sum += s[i] - '0';
}
for (int i = n / 2; i < n; i++) {
if (s[i] == '?')
x--;
... | 9 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int MAXN = 400010;
const int MAXM = 26;
int n;
char s[MAXN];
int tot;
struct node {
int dis;
node *pre, *next[MAXM];
} sa[MAXN], *root;
node *new_node() { return &sa[++tot]; }
int vertex[MAXN];
void build_sa() {
node *cur = root = n... | 27 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 100;
const int MOD = 1e9 + 7;
int n, pot2, inv[N], comb[N];
map<int, vector<int>> cnt;
void print(int n) {
if (abs(n - MOD) < abs(n)) n -= MOD;
cout << n << ' ';
}
int go(vector<int> &cnt) {
sort(cnt.begin(), cnt.end());
long long res = 0;
int ... | 23 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100002;
int n, cnt = 0;
int v[N];
pair<int, int> aux[N];
vector<int> ans[N];
bool vis[N];
void dfs(int u) {
if (vis[u]) return;
vis[u] = 1;
ans[cnt].push_back(u);
dfs(v[u]);
}
int main(void) {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
sca... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int INF = numeric_limits<int>::max();
void read(int &x) {
x = 0;
char ch = getchar();
int f = 1;
while (!isdigit(ch)) (ch == '-' ? f = -1 : 0), ch = getchar();
while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
x *= f;
}
const int N = 3e5 + 233;
co... | 21 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > v2;
vector<pair<int, int> > v1;
bool used1[3000];
bool used2[3000];
int main() {
long long n, x;
cin >> n >> x;
for (int i = 1; i <= n; i++) {
int t, h, m;
cin >> t >> h >> m;
if (t == 0) {
v1.push_back(make_pair(h, m));
}... | 7 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
string chicken =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
void solve() {
int r, c, k;
cin >> r >> c >> k;
vector<string> farm(r);
int rice = 0;
for (int i = 0; i < r; i++) {
cin >> farm[i];
for (int j = 0;... | 9 |
#include <bits/stdc++.h>
using namespace std;
string s;
int main(void) {
int t;
cin >> t;
while (t--) {
cin >> s;
int l = s.length();
vector<int> x;
x.clear();
s = 'p' + s + 'p';
int ans = 0;
for (int i = 1; i <= l; i++) {
if (s[i] == 'o') {
if (i >= 3) {
if (s[... | 6 |
#include <bits/stdc++.h>
using namespace std;
void chmax(int &x, int y) {
if (x < y) x = y;
}
void chmin(int &x, int y) {
if (x > y) x = y;
}
const int N = 100 + 5;
int n, m, a[N][N];
int cnt_row[N], cnt_col[N];
int k;
void check_row() {
for (int i = 1; i <= n; ++i) {
int x = a[i][1];
for (int j = 2; j <=... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, a[200100], tim[200100], query[200100], mx[200100];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int q;
cin >> n;
memset(tim, 0, sizeof(tim));
for (int i = int(0); i < int(n); ++i) cin >> a[i];
int t, p, x;
cin >> q;
for (int... | 8 |
#include <bits/stdc++.h>
using namespace std;
int lower(vector<int>& ar, int i) {
int l = 0, r = ar.size(), ret = -1;
while (l < r) {
int m = (l + r) / 2;
if (ar[m] < i) {
ret = m;
l = m + 1;
} else
r = m;
}
return ret;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);... | 3 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 200200;
ll a[maxn], b[maxn], ans[maxn];
ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a%b);
}
int main(void) {
int n, m; scanf("%d%d", &n, &m);
for (int i=1; i<=n; i++) scanf("%lld", &a[i]);
for (int i=1; i<=m; i++) s... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long FAT_BS(long long a, long long b, long long aa[], long long x) {
while (a <= b) {
long long mid = (a + b) / 2;
if (aa[mid] == x)
return 1;
else if (aa[mid] > x)
b = mid - 1;
else
a = mid + 1;
}
return -1;
}
long long FAT_gcd(... | 12 |
#include<bits/stdc++.h>
#define mod 1000000007
#define pie (3.141592653589)
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout << fixed;
cout.precision(10);
int T = 1;
cin >> T;
while(T--)
{
int n;
cin >> n;
vector<int> c(n);
for(int i = 0; i < n; i++)
{
cin >>... | 7 |
#include<bits/stdc++.h>
const int maxn=105;
using namespace std;
int t,n,k,sum[maxn],x[maxn],y[maxn];
int calc(int i,int j){
return abs(x[i]-x[j])+abs(y[i]-y[j]);
}
int main(){
scanf("%d",&t);
for(;t;t--){
memset(sum,0,sizeof(sum));
scanf("%d %d",&n,&k);
for(int i=1;i<=n;i++)scanf("%d %d",&x[i],&y[i]);
for(i... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long M = 1e8;
int main() {
long long n, i, k, ans = 0, f = 1, p, s = 1, len = 0;
cin >> n;
p = n;
p = p / 10;
while (p > 0) {
p = p / 10;
s = s * 2;
ans += s;
len++;
}
if (n % 10 == 7) {
ans++;
}
n = n / 10;
while (n > 0) {... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<pair<int, char>> a;
vector<int> gi;
for (int i = 0; i < n; i++) {
int first;
char color;
cin >> first >> color;
a.push_back({first, color});
if (color == 'G') {
... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 5;
const int MX = 3e3 + 5;
int r, c, n;
int fa[MX * MX * 2];
bool G[MX][MX * 2];
stack<pair<int, int> > stk;
inline int id(int x, int y) { return (x - 1) * c * 2 + y; }
void I() {
for (int i = 1; i <= r; i++) {
for (int j = 1; j <= 2 * c; j++) {... | 21 |
#include <bits/stdc++.h>
#define maxn 105
#define maxN 10086
using namespace std;
const int p = 1e9 + 7;
int n, q, x;
int b[maxn], c[maxn], f[maxN], g[maxN], sb[maxn];
int cal(int x){
for(int i = 0;i < maxN;i++) g[i] = 1;
for(int i = 1;i <= n;i++){
for(int j = 0;j < maxN;j++) f[j] = 0;
for(int j = max(0, i * ... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 9;
long long dp[2][maxn];
long long q[maxn];
int main() {
long long n, m, d;
cin >> n >> m >> d;
long long t1 = 0, p = 0;
for (long long i = 1; i <= m; i++) {
long long a, b, t;
cin >> a >> b >> t;
long long h = (t - t1) * d;
i... | 13 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long MOD2 = 998244353;
const long long N = 5e5 + 5;
const long double pi = 3.14159265359;
void SRAND() {
auto duration = std::chrono::system_clock::now().time_since_epoch();
auto millis =
std::chrono::duration_cast<std::ch... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
long long POW(long long a, long long b, long long MMM = MOD) {
long long ret = 1;
for (; b; b >>= 1, a = (a * a) % MMM)
if (b & 1) ret = (ret * a) % MMM;
return ret;
}
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, ... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
set<string> wines;
wines.insert("ABSINTH");
wines.insert("BEER");
wines.insert("BRANDY");
wines.insert("CHAMPAGNE");
wines.insert("GIN");
wines.insert("RUM");
wines.insert("SAKE");
wines.insert("TEQUILA");
wines.insert("... | 2 |
#include <bits/stdc++.h>
using namespace std;
priority_queue<long long> q1, q2, q3;
int main() {
int n, cnt = 0;
scanf("%d", &n);
long long sum = 0;
for (int i = 0; i < n; i++) {
int a;
long long b;
scanf("%d%lld", &a, &b);
if (a == 11)
sum += b, cnt++;
else if (a == 10)
q1.push(... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
n--;
cout << n / 2 << endl;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int F, I, T;
cin >> F >> I >> T;
int a[100];
for (int i = 0; i < 100; i++) a[i] = 0;
for (int i = 0; i < F; i++) {
string q;
cin >> q;
for (int j = 0; j < I; j++) {
if (q[j] == 'Y') a[j]++;
}
}
int ans = 0;
for (int i = 0; ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, x, b, y;
cin >> n >> a >> x >> b >> y;
while (a != x && b != y) {
if (a == b) {
cout << "YES";
return 0;
}
if (a != n) {
a++;
} else {
a = 1;
}
if (b != 1) {
b--;
} else {
b = n;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, m, minmove;
char arr[105][10005];
int search(int y) {
int i, j, summove = 0;
for (i = 0; i < n; i++) {
int move;
for (move = 0, j = 0; j < m; move++, j++) {
if (y + j >= m) {
if (arr[i][y + j - m] == '1') break;
} else if (arr[i][y + j... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1ll << 40;
char Char[1000001];
unordered_map<long long, bool> Mp;
unordered_map<long long, int> Edge;
int main(void) {
ios::sync_with_stdio(false);
register char First;
register long long Digit = 0;
register int Length = 0, Ans = 0, P = 0, Q = ... | 11 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long int a, b, n, m;
cin >> a >> b >> n >> m;
long long int mn = min(a, b);
if (mn < m)
cout << "No" << endl;
else {
long long int left = (a + b) - m;
if (left < n)
cout << "No" << endl;
else
cout << "Yes" << endl;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1000000007;
long long prost1 = 36028797018963913;
long long prost2 = 35184372088777;
long long n, m, now_k = 1;
vector<vector<long long> > v;
vector<char> used;
vector<long long> path, cmp;
void init() {
v.resize(m * 2 + 5);
used.resize(m * 2 + 5);... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int n, p;
cin >> n >> p;
for (int i = 1; i <= 40; ++i) {
int x = n - p * i;
if (x <= 0) continue;
if (__builtin_popcount(x) <= i && x >= i) {
cout << i << endl;
return 0;
}
}
cout << -1 <... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 123;
const int mod = 1e9 + 7;
const int INF = 1e9 + 1;
const double eps = 1e-9;
const double pi = acos(-1.0);
long long n, a[N], k, ans;
int main() {
ios_base::sync_with_stdio(0);
cin.tie();
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const long long LLINF = 9223372036854775807LL;
const int mod = 1000000007;
int powmod(int x, int p) {
if (p == 0) return 1;
if (p & 1) return x * (long long)powmod(x, p - 1) % mod;
long long t = powmod(x, p >> 1);
return t * t % mod;
}
in... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n, x;
int main() {
scanf("%d %d", &n, &x);
bool f = true;
for (int i = 0; i < n; i++) {
int a, b;
scanf("%d %d", &a, &b);
if (a == x || a + x == 7 || b == x || b + x == 7) {
f = false;
break;
}
}
if (f)
printf("YES\n");
else
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
const int MAXC = int(1e5) + 10;
int n, k;
int p[N], c[N], l[N];
bool isprime[2 * MAXC];
struct MaxFlow {
const int INF = int(1e6);
int n;
vector<vector<int>> adj;
MaxFlow(int n) : n(n) { adj.resize(n, vector<int>(n, 0)); }
int findAugmentedPath(... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, d;
cin >> n >> d;
int arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
int ans = arr[0];
for (int i = 1; i < n; i++) {
int temp = arr[i];
while (temp > 0 && d >= i) ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
long long mod = 1e9 + 7;
long long mod2;
long long inf = 2e18;
long long n, d, k, M;
long long mul2(long long a, long long b) {
a %= mod2;
b %= mod2;
return (a * b) % mod2;
}
long long add2(long long a, long long b) {
a %= mod2;
b %= mod2;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7, seed = 131, MAXN = 1e5 + 1;
vector<int> primes;
bool sieve[MAXN];
void gen() {
memset(sieve, 1, sizeof sieve);
sieve[0] = sieve[1] = 0;
for (long long i = 2; i < MAXN; ++i) {
if (sieve[i]) primes.push_back(i);
for (long long j = i * i;... | 13 |
#include <bits/stdc++.h>
const int maxn = 2e5 + 10;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
using namespace std;
int f[maxn], n, m, u, v, cnt[maxn], s, fa[maxn], vis[maxn], dep[maxn];
long long w[maxn], dp[maxn], ans = -1;
vector<int> g[maxn];
int find(int x) { return f[x] == -1 ? x : f[x]... | 14 |
#include <bits/stdc++.h>
using namespace std;
int N;
bool f[3000][3000];
bool v[3000][3000];
vector<pair<int, int> > akt;
queue<pair<int, int> > qu;
void visit(int x, int y) {
if (v[x][y]) return;
v[x][y] = true;
qu.push(pair<int, int>(x, y));
while (!qu.empty()) {
int x = qu.front().first, y = qu.front().s... | 11 |
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
int n, m, iTime;
stack<int> st;
vector<bool> inSt;
vector<int> disc, low, szScc, inScc;
vector<vector<int> > gr, adj;
void dfs(int u) {
disc[u] = low[u] = ++iTime;
st.emplace(u);
inSt[u] = true;
for (int v : gr[u]) {
if (!disc[v]) {
d... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
long long n, s, res;
int a[200005];
int main(void) {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
while (cin >> n >> s) {
res = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
sort(a + 1, a + n + 1);
in... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, m, t;
cin >> n >> k >> m >> t;
while (t--) {
int a, b;
cin >> a >> b;
if (a == 1) {
if (b <= k) k++;
n++;
} else {
if (b <= k - 1) {
k -= b;
n -= b;
} else {
n = b;
}
}
... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long solve() {
long long n, maxi = INT_MIN, sum = 0;
cin >> n;
long long arr[n];
for (long long i = 0; i < n; i++) {
cin >> arr[i];
}
if (n == 1) return arr[0];
sort(arr, arr + n);
for (long long i = 0; i < n; i++) {
maxi = max(maxi, arr[i] - su... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> out;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
bool is = true;
for (int j = 0, a; j < n; j++) {
cin >> a;
if (a == 3 || a == 1) is = false;
}
if (is) out.push_back(i + 1);
}
cout << (int)out.size() << endl;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long distance(int a, int b, int n) {
long long d = 0;
if (a <= b) {
d += b - a;
} else {
long long temp = (n - a) + 1;
d += temp + b - 1;
}
return d;
}
void solve() {
int n, m;
cin >> n >> m;
vector<int> a(m);
vector<int> b(m);
int i, j;... | 9 |
#include <bits/stdc++.h>
using namespace std;
const char nl = '\n';
const int INF = 0x3f3f3f3f;
const long long INFLL = 0x3f3f3f3f3f3f3f3f;
const long long MOD = 1e9 + 7;
const long double EPS = 1e-10;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const int N = 2e3;
const int M = 1e6;
in... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> L(n);
for (int i = 0; i < n; i++) cin >> L[i];
reverse(L.begin(), L.end());
int lastKill = -1;
int live = 0;
for (int i = 0; i < n; i++) {
if (lastKill < i) live++;
lastKill = max(lastKill, i + L[i]);
}
c... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200100, oo = 2e9;
inline int read() {
int x = 0, c = getchar(), f = 0;
for (; c > '9' || c < '0'; f = c == '-', c = getchar())
;
for (; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + c - '0';
return f ? -x : x;
}
inline void write(l... | 25 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int M = 1e9 + 7;
int prime[N];
int ans[N];
int nums[N];
vector<int> factor[N];
void SIEVE() {
for (int i = 2; i < N; i++) {
if (prime[i] != 0) continue;
for (int j = i; j < N; j += i) {
prime[j] = i;
}
}
return;
}
int mai... | 7 |
#include <bits/stdc++.h>
using namespace std;
inline long long ADD(long long a, long long b, long long mod) {
return (a + b + mod + mod) % mod;
}
inline long long SUBS(long long a, long long b, long long mod) {
return (a - b + mod + mod) % mod;
}
inline long long MUL(long long a, long long b, long long mod) {
ret... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long int n, k, t[101000], a[101000], res, act, mact;
int main() {
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
cin >> t[i];
if (i < k) act += ((t[i] ^ 1) * a[i]);
res += a[i] * t[i];
}
mact = act;... | 4 |
#include <bits/stdc++.h>
using namespace std;
class Pattern {
public:
vector<vector<char> > V;
bool operator<(const Pattern &P) const { return V > P.V; }
};
int main() {
vector<string> s(6);
for (int i = 0; i < 6; i++) cin >> s[i];
sort((s).begin(), (s).end());
Pattern ANS;
bool first = false;
do {
... | 12 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 5000;
long long coins[N], wts[N];
bool check[N];
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long t = 1;
if (0) cin >> t;
while (t--) {
long long n;
cin >> n;
long long ans;
if (n >= 0)
ans = n;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long int mod = 1e8 + 5e4 + 1;
long long int mod2 = 1e9 + 87;
const double error = 1e-8;
const double PI = acos(-1);
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
inline long long int MOD(long long int x, long long int m = mod) {
long long int y... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n, p, x, f[100000], a;
int main() {
cin >> n;
cin >> p;
int pp[p + 1];
for (int i = 1; i <= p; i++) {
cin >> pp[i];
f[pp[i]]++;
}
cin >> x;
int xx[x + 1];
for (int i = 1; i <= x; i++) {
cin >> xx[i];
f[xx[i]]++;
}
for (int i = 1; i <=... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void afill(T *arr, int size, T val) {
fill(arr, arr + size, val);
}
long long mod = 1e9 + 7;
double eps = 1e-9;
int n, t, m, q, k;
int tree[1 << 20];
void update(int pos, int lo, int hi, int li, int ri, int win) {
if (li > ri || lo > ri || hi < li ... | 7 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ld = long double;
mt19937_64 rng(
(unsigned)chrono::system_clock::now().time_since_epoch().count());
const ld PI = acosl(-1);
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll n;
cin >> n;
map<pa... | 15 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:10240000,10240000")
using namespace std;
const double R = 0.5772156649015328606065120900;
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const double eps = 1e-8;
const double pi = acos(-1.0);
vector<int> G[N];
int num[N];
void dfs(int... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const long long LLINF = 9223372036854775807LL;
const int maxs = 100010;
int dp[maxs];
const int maxn = 310;
int indeg[maxn];
int outdeg[maxn];
int a[maxn];
int To[maxn];
int u[maxn];
const int mod = 1000000007;
int main() {
int n, q, t;
scanf... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e7 + 10;
const int M = 1e9 + 7;
const int inf = 1e9 + 7;
const long long INF = 1e18;
int a[N];
int n;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n;
int x;
long long ans = INF;
int lx, rx;
for (int i = 1; i <= n; i++) {
... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
int g[N][26], f[N], e[N], nc;
int ID[N], K[N], ans[N], L[N];
int gn() {
int p = nc++;
f[p] = e[p] = 0;
memset(g[p], 0, sizeof(g[p]));
return p;
}
void clr() {
nc = 0;
gn();
}
void ins(const string& s, int k, int id) {
int p = 0;
for (... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
srand(time(NULL));
string s;
while (cin >> s) {
int n = ((int)((s).size()));
if (!count(&s[0], &s[0] + n, 'Q')) {
printf("Yes\n");
continue;
}
int i0 = 0;
while (i0 < n && s[i0] != 'Q') i0++;
if (i0 & 1) {
printf(... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int temp = m;
if (m == 1)
cout << n;
else if (n == m) {
while (m--) cout << '1' << " ";
} else if ((n % m) == 0) {
while (temp != 0) {
cout << n / m << " ";
temp--;
}
} else {
int a[m];
... | 0 |
#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);
}
... | 14 |
#include<bits/stdc++.h>
#define llong long long
#define mkpr make_pair
#define x first
#define y second
#define iter iterator
#define riter reverse_iterator
#define y1 Lorem_ipsum_
#define tm dolor_sit_amet_
using namespace std;
inline int read()
{
int x = 0,f = 1; char ch = getchar();
for(;!isdigit(ch);ch=getchar()... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};
long long POW(long long n, long long p) {
if (p == 0) return 1;
long long t = POW(n, p / 2);
if (p & 1) return n * t * t;
return t * t;
}
long long POW_MOD(long long n, long long p, long long M) {
i... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 10;
int matrix[maxn][maxn];
int pow_mod(int a, int b, int p) {
int ans = 1;
while (b) {
if (b & 1) ans = (long long)ans * a % p;
a = (long long)a * a % p;
b >>= 1;
}
return ans;
}
int main() {
int n, m, k, a, b, c, p;
cin >> n ... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int bas = 233;
int n;
char s1[1001000], s2[1001000];
unsigned long long p[1001000], h1[1001000], h2[1001000];
char chg(char x) {
if (x == 'N') return 'S';
if (x == 'S') return 'N';
if (x == 'W') return 'E';
if (x == 'E') return 'W';
}
int main() {
scanf("%d%... | 17 |
#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
void pr(const pair<T1, T2>& x);
template <class T, size_t SZ>
void pr(const array<T, SZ>& x);
template <class T>
void pr(const vector<T>& x);
template <class T>
void pr(const set<T>& x);
template <class T1, class T2>
void pr(const map<T1, T2>& ... | 9 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
char ch = getchar();
int x = 0, f = 1;
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, a[300005], b[300... | 7 |
#include <bits/stdc++.h>
int main() {
int T;
scanf("%d", &T);
for (int t = 0; t < T; ++t) {
int A, B;
scanf("%d%d", &A, &B);
int d = round(pow(1LL * A * B, 1. / 3.));
if (1LL * d * d * d == 1LL * A * B && A % d == 0 && B % d == 0)
puts("Yes");
else
puts("No");
}
}
| 9 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000 * 1000 * 1000;
const long long INF64 = 1000LL * 1000LL * 1000LL * 1000LL * 1000LL * 1000LL;
char a[2100][2100];
int need[2100];
int n;
void Load() {
scanf("%d", &n);
{
int c;
while ((c = getchar()) != 10 && c != EOF)
;
};
for (int ... | 12 |
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
bool check(long long int n, long long int k) {
long long int s = 0, p = n;
while (n > 0) {
if (n <= k)... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t;
cin >> t;
while (t--) {
long long int n, m;
cin >> n >> m;
if (n == 1 || m == 1) {
cout << "YES\n";
} else if (n == 2 && m == 2) {
cout << "YES\n";
} else {
cout << "NO\n";
}
}
}
| 0 |
#include <bits/stdc++.h>
std::mt19937 rng(
(int)std::chrono::steady_clock::now().time_since_epoch().count());
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
long long ans = 0;
std::stack<std::pair<int, int>> st;
auto getCost = [&](int f, int id) {
if (f <= 0) return 0LL;
i... | 16 |
#include <bits/stdc++.h>
using namespace std;
bool check(int x1, int y1, int x2, int y2, int x3, int y3) {
int a = pow(x1 - x2, 2) + pow(y1 - y2, 2);
int b = pow(x2 - x3, 2) + pow(y2 - y3, 2);
int c = pow(x1 - x3, 2) + pow(y1 - y3, 2);
if ((a == b + c && a != 0 && b != 0 && c != 0) ||
(b == a + c && a != ... | 12 |
#include <bits/stdc++.h>
using namespace std;
char f[105][105] = {0};
int dir[8][2] = {{-1, -1}, {-1, 0}, {-1, 1}, {0, -1},
{0, 1}, {1, -1}, {1, 0}, {1, 1}};
int main(int argc, const char* argv[]) {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
scanf("%s", f[i] + 1);
}
bool o... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, k, arr[300030], res = 0, f[20];
int main() {
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) {
cin >> arr[i];
}
for (int i = 0; i < 20; i++) f[i] = 0;
f[0] = -k;
for (int i = 1; i <= n; i++) {
arr[i] += arr[i - 1];
for (int j = 0; j ... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long int t, n, arr[102];
int main() {
long long int i, a;
scanf("%lld", &t);
while (t--) {
scanf("%lld", &n);
long long int ans = 1;
for (i = 1; i <= 100; i++) arr[i] = 0;
for (i = 0; i < n; i++) {
scanf("%lld", &a);
arr[a] = 1;
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a.begin(), a.end());
vector<int> ans;
int nans = 0;
int i = 0;
int j = (n - (n % 2)) / 2;
while (ans.size() < n) {
if (n % 2 and j == n - 1) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
long long dp[505][505];
long long f[505][505];
long long kpow(long long x, int y) {
long long ans = 1;
while (y) {
if (y & 1) {
ans = (ans * x) % mod;
}
x = (x * x) % mod;
y >>= 1;
}
return ans;
}
long long ff[5... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int MX = 3505;
int a[MX];
void solve() {
int n, m, k;
ignore = scanf("%d %d %d", &n, &m, &k);
for (int i = 0; i < n; i++) {
ignore = scanf("%d", a + i);
}
int len = n - m + 1;
int ans = 1;
int L = 1, R = 1000000000;
while (L <= R) {
int M = (L ... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long mxp2(long long a) {
long long ans = pow(2, 60);
while (a % ans) ans /= 2;
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n, q, u, temp;
cin >> n >> q;
string s;
while (q--) {
cin >> u >> s;
for (char... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 20;
int arr[N];
int main() {
int n, k, ans = 0;
scanf("%d%d", &n, &k);
for (int i = 0; i < n; i++) scanf("%d", &arr[i]);
sort(arr, arr + n);
for (int i = 0; i < n; i++) {
if (arr[i] <= k * 2) continue;
int last = k;
if (i) last = ma... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 550;
const int MOD = 1e9 + 7;
const double eps = 1e-8;
const long long INF = 0x3f3f3f3f;
long long maxs(long long x1, long long x2) { return (x1 > x2) ? x1 : x2; }
int main() {
int n, m;
scanf("%d %d", &n, &m);
int hotel, restaurant;
scanf("%d", &ho... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[1000006], f[1000005];
int main() {
ios_base::sync_with_stdio(0);
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
f[0] = 0;
for (int i = 1; i <= n; i++) f[i] = f[i - 1] ^ i;
int ans = 0;
for (int i = 1; i <= n; i++)
if ((n / i) % 2)
a... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, -1, 0, 1, -1, 1, 1, -1};
template <class T>
inline bool get(T& n) {
char c, mul = 1;
n = 0;
while (!isdigit(c = getchar_unlocked()) && (c != EOF) && (c != '-'))
;
if (c == EOF) return false;
if... | 9 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.