solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int lg(long long n) {
assert(n > 0);
int ans = -1;
while (n) {
ans++;
n >>= 1;
}
return ans;
}
template <typename T, int NDIMS>
struct tensor_view {
static_assert(NDIMS >= 0, "NDIMS must be nonnegative");
protected:
std::array<int, NDIMS> shape;
st... | 19 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> foo(string a[], int n) {
pair<int, int> p = {0, 0};
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if ((i + j) % 2 == 0) {
if (a[i][j] == '1')
p.first++;
else
p.second++;
} else {
if... | 6 |
#include <bits/stdc++.h>
using namespace std;
int Maps[2007][2007];
int Fa[2007], N;
int dis[2007][2007];
struct Node {
int L, R, W;
bool operator<(Node a) const { return W < a.W; }
} edge[2007 * 2007];
struct Lists {
int v, w;
};
vector<Lists> G[2007];
int Finds(int x) {
if (x != Fa[x]) Fa[x] = Finds(Fa[x]);
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, a, b, s = 0;
cin >> n >> m;
for (a = m; a >= 0; a--) {
b = n - a * a;
if (a + b * b == m && a >= 0 && b >= 0) s++;
}
cout << s;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
vector<double> v;
void solve(double n, double h) {
if (n <= 1) return;
h = (double)sqrt((n - 1) * h * h / n);
solve(n - 1, h);
v.push_back(h);
}
int main() {
double n;
double h;
cin >> n >> h;
solve(n, h);
for (int i = 0; i < v.size(); ++i) printf("%.12lf ... | 4 |
#include <bits/stdc++.h>
using namespace std;
vector<int> tree[100005];
int depth[100005], subsize[100005];
double ans[100005];
void dfs(int u, int p, int d) {
subsize[u] = 1;
depth[u] = d;
for (int i = 0; i < tree[u].size(); i++) {
int to = tree[u][i];
if (to != p) {
dfs(to, u, d + 1);
subsiz... | 9 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x) {
x = 0;
char c = getchar(), f = 0;
for (; c < '0' || c > '9'; c = getchar())
if (c == '-') f = 1;
for (; c >= '0' && c <= '9'; c = getchar())
x = (x << 1) + (x << 3) + (c ^ 48);
if (f) x = -x;
}
int n, p, q, f[... | 21 |
#include <bits/stdc++.h>
using namespace std;
int n, mid;
int col[5010][5010];
pair<int, int> b[5010];
long long pw[5010];
int dist(int x, int y, int p, int q) { return abs(x - p) + abs(y - q); }
bool dfs(int x, int y) {
for (int i = 1; i <= n; i++)
if (dist(x, y, b[i].first, b[i].second) > mid)
if (!col[b[... | 18 |
#include <bits/stdc++.h>
using namespace std;
int prime[29] = {0, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37,
41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
int b, d;
int i, j, k, l, q;
bool ist2[105];
int min2[105];
int pp[105];
int gcd(int x, int y) {
int r;
while (y) {
r = x % y;
... | 15 |
#include <bits/stdc++.h>
using namespace std;
const long long mod7 = 998244353;
vector<vector<long long> > mul(vector<vector<long long> > &A,
vector<vector<long long> > &B,
long long mod = mod7) {
vector<vector<long long> > res(A.size(), vector<long long>(... | 16 |
#include <bits/stdc++.h>
using namespace std;
long long modd = 1000 * 1000 * 1000 + 7;
template <class T>
class depth_first_search_iterator {
public:
stack<pair<T, T>> todo;
function<bool(T)> notvisited;
function<void(T)> mark_visited;
function<set<T>(T)> neighbors;
depth_first_search_iterator() {}
depth_f... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int r, c;
scanf("%d%d", &r, &c);
if (r == 1 && c == 1) {
cout << 0 << endl;
return 0;
}
int rows[r], cols[c];
if (r == 1) {
rows[0] = 1;
for (int i = 0; i < c; ++i) cols[i] = r + i + 1;
} else if (c == 1) {
cols[0] = 1;
for... | 6 |
#include <bits/stdc++.h>
using namespace std;
int k;
long long a[100005];
long long fpow(long long a, long long b) {
long long r = 1;
for (; b; b /= 2, a = (a * a) % 1000000007)
if (b & 1) r = (r * a) % 1000000007;
return r;
}
void mmul(int a[2][2], int b[2][2]) {
static int c[2][2];
for (int i = 0; i < 2... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x;
cin >> x;
string s;
cin >> s;
if (x % 2 == 0)
for (int i = 0; i < s.size(); i++) {
cout << s[i];
cout << s[++i];
if (i != s.size() - 1) cout << '-';
}
else {
for (int i = 0; i < s.size() - 3; i++) {
cout <<... | 3 |
#include <bits/stdc++.h>
using namespace std;
template <typename Tp>
inline void outarr(Tp _begin, Tp _end, const char* _delim = " ") {
for (Tp current = _begin; current != _end; ++current) {
std::cout << *current << _delim;
}
std::cout << '\n';
}
using ll = long long;
using pii = std::pair<int, int>;
constex... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
string sln;
cin >> sln;
bool fl = 0;
int mx = 0;
if (sln[0] == '?') mx = 2;
for (int i = 1; i < n; ++i) {
if (sln[i] == sln[i - 1] && sln[i] != '?') fl = 1;
if (i < n - 1 && ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n;
cin >> n;
if (n == 2) {
cout << 1;
} else if (n % 2 == 0) {
cout << -1 - ((n / 2) - 1) + n;
} else {
cout << -1 + (n / 2) + 1 - n;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long arr[100010];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
int t = 1;
while (t--) {
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> arr[i];
sort(arr, arr + n);
int x = 14;
if (x % (n - 1))
x = x / (n... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, l;
cin >> n >> l;
map<string, string> m;
string a, b;
while (l--) {
cin >> a >> b;
m[a] = b;
}
string ans = "";
while (n--) {
string word;
cin >> word;
if (m[word].size() < word.size())
ans += m[word];
else
... | 2 |
#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;
string s, p;
cin >> s;
p = s;
sort(s.begin(), s.end());
long long int l = 0;
for (long long int i = 0;... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a = 1, i;
printf("2000\n");
for (i = 1; i <= 1000; i++) {
printf("%d 1 %d 2\n", i, i);
}
for (i = 1000; i >= 1; i--) {
printf("%d 1 %d 2\n", i, i);
}
}
| 9 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int n, ssz;
string s;
int len[222][2];
int dp[222][222][222][2];
int calc(const string &t) {
int tsz = t.size();
for (int i = tsz; i > 0; i--) {
if (s.substr(0, i) == t.substr(tsz - i, i)) return i;
}
return 0;
}
void add(int &a, int b) ... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int v1, v2, t, d, sol = 0, ans = 0;
cin >> v1 >> v2 >> t >> d;
if (v2 < v1) swap(v1, v2);
ans += v1 + v2;
t -= 2;
while (1) {
if (!t) break;
bool k;
for (int i = d; i >= -1 * d; i--) {
k = 0;
if (v1 < v2) {
v1 += i;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
struct node {
long long cost;
long long index;
};
bool cmp(node &x, node &y) {
return ((x.cost != y.cost) ? (x.cost < y.cost) : (x.index <= y.index));
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long n, m, i, j;
cin >... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, sum = 0, s = 0, x;
cin >> n;
for (int i = 19; i < 1000000000; i++) {
x = i;
while (x != 0) {
sum += x % 10;
x /= 10;
}
if (sum == 10) {
s++;
if (s == n) {
cout << i;
break;
}
}
s... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2 * 1e5 + 1;
long long dp[101][N], a[N], b[N];
long long x, y, k, t;
const long long mod = 1e9 + 7;
int main() {
cin >> x >> y >> k >> t;
long long up = k * t * 2;
dp[0][k * t] = 1;
for (long long i = 0; i <= up; i++) {
if (i == 0)
a[i] = dp[... | 14 |
#include <bits/stdc++.h>
using namespace std;
int n;
set<int> s;
void dfs(int num, int x, int y) {
if (num > 0 && num <= n)
s.insert(num);
else
return;
if (num > (100000000)) return;
num *= 10;
dfs(num + x, x, y);
dfs(num + y, x, y);
}
int main() {
scanf("%d", &n);
for (int i = 0; i <= 9; i++) {... | 8 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using db = double;
using vi = vector<int>;
const int inf = 0x3f3f3f3f;
const db eps = 1e-8;
const int mod = 1e9 + 7;
ll qpow(ll a, ll b) {
ll ret = 1;
while (b) {
if (b & 1) ret = ret * a % mod;
a = a * a % mod;
... | 18 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const int maxN = 210000;
const long long P = 1000000007LL;
int n;
vector<int> g[maxN];
int s[maxN], used[maxN], d[maxN], nodes[maxN];
int next_node[maxN], length_to_the_node[maxN];
int is_node(int v) { return g[v].size() == 3; }
v... | 22 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
struct state {
int id, v;
state(int ID, int V) { id = ID, v = V; }
};
bool operator<(state A, state B) {
return A.v < B.v || (A.v == B.v && A.id < B.id);
}
int n, m, data[maxn];
priority_queue<state> Q;
vector<pair<int, int> > V;
vector<int> r... | 14 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
template <typename T>
inline T Abs(T a) {
return a > 0 ? a : -a;
}
template <typename T>
inline T sqr(T a) {
return a * a;
}
template <typename T>
inline void relaxMin(T &a, T b) {
if (b < a) a = b;
}
template <typename T>
in... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n;
string input, s = "";
vector<string> v;
int main() {
cin >> n;
while (n--) {
cin >> input;
v.clear();
s = "";
for (int j = 0; j < input.size(); j++) {
if (input[j] == ':') {
if (j != 0) {
v.push_back(s);
s = "";
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int dp[20010][2];
int ins[20010][2];
int p;
int X[20010];
int Y[20010];
int sol[20010];
int T;
int b;
inline int f(int i, int j) { return (X[i] + Y[j]) % p; }
void compute(int si, int sj, int ei, int ej) {
if (si > ei || sj > ej) return;
if (si == ei && ej == sj) {
... | 17 |
#include <bits/stdc++.h>
using namespace std;
vector<int> graph[10002];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i < n; i++) {
int a, b;
scanf("%d %d", &a, &b);
graph[a].push_back(b);
graph[b].push_back(a);
}
long long cnt = 0;
for (int i = 1; i <= n; i++) {
int sz = graph[i]... | 5 |
#include <bits/stdc++.h>
using namespace std;
vector<int> adjList[200010];
vector<int> factors[200010];
vector<int> nodes[200010];
int parents[200010];
bool valid[200010];
long long int ans[200010];
int P[200010], R[200010];
int findS(int x) {
if (P[x] != x) P[x] = findS(P[x]);
return P[x];
}
void mergeS(int x, int... | 16 |
#include <bits/stdc++.h>
using namespace std;
long long t, n, m, k, c;
void solve();
int main() {
cin >> t;
while (t--) {
solve();
}
}
void solve() {
int a[3];
cin >> a[0] >> a[1] >> a[2] >> n;
sort(a, a + 3);
cout << (n < (2 * a[2] - a[1] - a[0]) || (n - (2 * a[2] - a[1] - a[0])) % 3
?... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 41;
char a[MaxN][MaxN];
int sum[MaxN][MaxN];
int hCur[MaxN][MaxN][MaxN][MaxN];
int sumSq[MaxN][MaxN][MaxN][MaxN];
bool isSumZero(int r1, int c1, int r2, int c2) {
return (sum[r2][c2] - sum[r2][c1 - 1] - sum[r1 - 1][c2] +
sum[r1 - 1][c1 - 1]) == ... | 11 |
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pa pair<int,int>
const int Maxn=300010;
const int inf=2147483647;
const double pi=acos(-1.0);
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();
... | 21 |
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
int IT_MAX;
const int MOD = 1000000;
const int INF = 534567891;
const long long LL_INF = 2234567890123456789ll;
const double PI = 3.141592653589793238;
char in[1050][1050];
int dis[3][1050][1050];
bool chk[3][1050][1050];
priority_queue<pair<... | 14 |
#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... | 13 |
#include <bits/stdc++.h>
using namespace std;
void FastIO() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
}
int main() {
FastIO();
int n;
cin >> n;
vector<int> a(n + 2, 0);
for (int i = (int)1; i <= (int)n; i++) {
cin >> a[i];
}
vector<int> dp(n + 2, 0);
for (int i = (int)1; i... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 100;
const int sqr = 328;
deque<int> block[sqr];
int ans[sqr][MAXN];
int n;
int lastans;
int gen(int k) { return ((k + lastans - 1) % n) + 1; }
void update(int l, int r) {
int vr = block[r / sqr][r % sqr];
block[r / sqr].erase(block[r / sqr].begin... | 19 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
const long long MAX = 2147483647;
long long inv(long long n) {
long long now = 1;
long long base = n;
long long p = MOD - 2;
while (p > 0) {
if (p & 1) now = now * base % MOD;
base = base * base % MOD;
p >>= 1;
}
retu... | 9 |
#include <bits/stdc++.h>
using namespace std;
int N, M, T;
set<pair<int, int> > on;
vector<int> all;
vector<int> ids;
int main() {
cin >> N >> M >> T;
for (int i = 0; i < N; i++) {
int h, m, s;
char c;
cin >> h >> c >> m >> c >> s;
all.push_back(60 * 60 * h + 60 * m + s);
}
int K = 0;
int A = ... | 13 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
long long mypow(long long x, long long p) {
if (p == 0) return 1;
long long r = mypow(x, p / 2);
return r * r % mod * (p % 2 ? x : 1) % mod;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long n, m, a;
cin >> n >... | 15 |
#include <bits/stdc++.h>
using namespace std;
const long long int m = 1000000007;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, x, i;
cin >> n;
int m = (n + 1) / 2, a[100005] = {0};
for (i = 1; i <= m; i++) {
cin >> x;
if (x >= i) a[x - i]++;
}
if (n % 2 == 1)... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
string s;
cin >> s;
int a[26];
for (int i = 0; i < n; i++) {
a[s[i] - 'A'] = i;
}
int active = 0;
int visited[26] = {0};
for (int i = 0; i < n; i++) {
if (visited[s[i] - 'A'] == 0) {
active++;
}
... | 3 |
#include <bits/stdc++.h>
using namespace std;
char s[1010];
char a[52][52];
int main() {
int T;
cin >> T;
while (T--) {
memset(a, 0, sizeof(a));
int n;
cin >> n >> s;
vector<int> v;
for (int i = 0; i < n; i++) {
if (s[i] == '2') v.push_back(i + 1);
}
if (v.size() == 2 || v.size()... | 2 |
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const int MAX_N = 2e5 + 9;
ll dp[MAX_N][2],arr[MAX_N][2]; vector<int>adj[MAX_N];
void dfs(int u , int par = -1){
dp[u][1] = dp[u][0] = 0;
for(auto i : adj[u]){
if(i == par)
continue;
dfs(i,u);
dp[u][1] += m... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
for (int i = 0; i < t; ++i) {
int n, g = 0, s = 0, b = 0, flag;
cin >> n;
long long int a[n];
int v1[n], v2[n];
int size = 0, size1 = 0;
for (int j = 0; j < n; ++j) {
cin >> a[j];
}
v1[0] = 0;
siz... | 7 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream& operator<<(ostream& fout, const vector<T>& vec) {
for (const auto& el : vec) {
fout << el << ' ';
}
return fout;
}
template <class T>
istream& operator>>(istream& fin, vector<T>& vec) {
for (size_t i = 0; i < vec.size(); ++i) {
ci... | 8 |
#include <bits/stdc++.h>
int main() {
int a = 0, x = 0;
scanf("%d", &a);
for (int i = 0; i < a; i++) {
scanf("%d", &x);
if (x % 7 == 0) {
printf("%d\n", x / 7);
} else {
printf("%d\n", (x / 7) + 1);
}
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int ne[N << 1], fi[N], b[N << 1], d[N], n, k, rt;
vector<int> s[N], ans;
void add(int x, int y) {
ne[++k] = fi[x];
b[fi[x] = k] = y;
++d[x];
}
void era(int x) {
for (vector<int>::iterator i = s[x].begin(); i != s[x].end(); ++i)
if (*i == x)... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 4005;
const int S = 1e6 + 10;
int x, n;
int a[N], pref[N];
int cnt[S];
char b[N];
void get() {
scanf("%s", b);
n = strlen(b);
for (int i = 0; i < n; i++) a[i] = b[i] - '0';
}
long long r(int h, int w) { return 1LL * w * (w + 1) * h * (h + 1) / 4; }
int m... | 8 |
#include <bits/stdc++.h>
using namespace std;
struct floor {
int k, f;
} v[1001];
int CheckPossibiltyFlat(int NumberOfFlats, int Floor, bool &IsGood) {
if ((((v[Floor].k - 1) / NumberOfFlats) + 1) == v[Floor].f) {
IsGood = true;
return 1;
} else {
IsGood = false;
return 0;
}
}
int main() {
int... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 2e9;
const int MOD = 1e9 + 7;
const int N = 1e5 + 10;
stack<int> s;
int n, m, ans, low[N], num[N], h[N] = {0}, t[N] = {0};
vector<int> a[N], b[N];
void DFSt(int x) {
static int c = 0;
s.push(x);
num[x] = low[x] = --c;
for (vector<int>::iterator i = a... | 14 |
#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
int main() {
int n;
scanf("%d", &n);
if (n % 4 == 0) {
cout << 0 << endl;
cout << n / 2 << " ";
int l = 1, r = n;
for (int i = 0; i < n / 4; i++) {
cout << l << " " <... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, x, y;
cin >> n >> x >> y;
vector<int> ans;
for (int d = 1; d <= y - x; ++d) {
if ((y - x) % d != 0) continue;
vector<int> res;
bool foundx = false;
int cur = y;
int need =... | 4 |
/* Author : Md Shumail */
/* Goal : Wherever My Practice Takes */
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define UMAX 1e5+9
#define F first
#define S second
#define debug(v) for(auto &x:v)clog<... | 5 |
//#include <GOD>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
#define pb push_back
#define len length
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define frei freopen("input.txt","r",stdin)
#define freo freopen("output.txt","w",stdout)
const ll inf=1... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int bouquet, aux, soma = 0;
set<int> petalsI;
set<int> petalsP;
cin >> bouquet;
while (bouquet--) {
cin >> aux;
soma = soma + aux;
if (aux & 1 == 1)
petalsI.insert(aux);
else
petalsP.insert(aux);
}
if (soma & 1 == 1) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n;
int ans[101010][5], cnt = 0;
inline void add3(int x, int y, int z) {
cnt++;
ans[cnt][0] = 3;
ans[cnt][1] = x;
ans[cnt][2] = y;
ans[cnt][3] = z;
}
inline void add4(int x, int y, int z, int w) {
cnt++;
ans[cnt][0] = 4;
ans[cnt][1] = x;
ans[cnt][2] = y... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
vector<int> V[maxn];
int n, m, q, deg[maxn];
long long ans, res[maxn];
int main() {
scanf("%d%d", &n, &m);
for (int i = 1, x, y; i <= m; i++) {
scanf("%d%d", &x, &y);
if (x > y) swap(x, y);
deg[x]++;
deg[y]++;
V[x].push_back(... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long INF = LONG_LONG_MAX;
const int N = 1e3 + 7;
struct Point {
double x, y;
Point() {}
Point(double x, double y) : x(x), y(y) {}
Point operator-(const Point &rhs) { return Point(x - rhs.x, y - rhs.y); }
} a[N];
double det(Poin... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long arr[5000];
bool num[1000006];
void sieve() {
int sz = sqrt(1000000);
for (int i = 2; i <= sz; i++) {
if (!num[i]) {
for (int j = i * i; j < 1000001; j += i) num[j] = true;
}
}
}
int main() {
sieve();
int t;
int n;
cin >> t;
while (t--... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, m, Q, c[200010];
int F[100010][22], dep[100010];
vector<int> g[100010], s[100010][22];
inline void Combine(vector<int> &a, vector<int> &b, vector<int> &c) {
int head1 = 0, head2 = 0;
a.clear();
while (head1 < b.size() && head2 < c.size()) {
if (b[head1] < c... | 14 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long int i, j, k, l, m, n, o, t;
string second, p, q;
cin >> q;
map<char, long long int> mp;
for (auto c : q) {
mp[c]++;
}
cin >> p;
long long int x = 0;
for (auto c : p) {
if (c != '*') {
x++;
}
}
cin >> t;
n = ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 4;
int n, x1, x2, y3, y2, rec[2 * N], num;
struct no {
int l, r, h, flag;
};
no line[8 * N];
struct nod {
int l, r, cover;
long long sum;
};
nod tree[8 * N];
int cmp(no x, no y) { return x.h < y.h; }
void build(int node, int L, int R) {
tree[node... | 15 |
#include <bits/stdc++.h>
using namespace std;
long long abs(long long, long long);
void solve() {
long long a, b, c, d;
cin >> a >> b >> c;
if (a == b)
cout << a + b + 2 * c << "\n";
else {
d = min(a, b);
cout << d + d + 1 + 2 * c << "\n";
}
}
signed main() {
ios_base::sync_with_stdio(false);
... | 0 |
#include <bits/stdc++.h>
const int long long N = 10e8 + 7;
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
char arr[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) arr[... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long int c[1000][1000], n, ans;
int main() {
cin >> n;
for (int i = 5; i <= 7; i++) {
for (int j = 0; j <= 777; j++) {
for (int k = 0; k <= 777; k++) {
c[j][k] = 0;
}
}
for (int j = 0; j <= i; j++) {
c[0][j] = 1;
}
for ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 4400;
void manacher(char *s, int *d1, int *d2) {
int len = strlen(s);
int l = 0, r = -1;
for (int i = 0; i < len; i++) {
d1[i] = (r < i ? 0 : min(d1[l + r - i], r - i + 1));
for (; i - d1[i] >= 0 && i + d1[i] < len && s[i + d1[i]] == s[i - d1[i]]... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int64_t n, y, j, i, k, l;
cin >> y >> k >> n;
set<int64_t> a;
for (i = k; i <= n; i += k)
if (i - y >= 1) a.insert(i - y);
if (a.empty())
cout << -1;
else
for (set<int64_t>::iterator w = a.begin(); w != a.end(); w++)
cout << *w << ... | 4 |
#include <bits/stdc++.h>
const int N = 2e5 + 6;
struct edge {
int to, nxt;
bool vis;
} e[N << 1];
int head[N], cnt = 1, n, m, dep[N], fa[N], up[N];
bool vis[N];
std::vector<int> out;
void O_R(int now, const int& ed) {
if (now != ed) O_R(fa[now], ed);
out.push_back(now);
}
void output() {
printf("%d", out.size... | 23 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:134217728")
using namespace std;
int cnt[1 << 14];
int add[1 << 14];
int del[1 << 14];
int main() {
int n, m, k;
cin >> n >> m >> k;
vector<int> res;
int now = 0;
for (int i = 1; i <= 2 * (n + m); ++i) {
now -= del[i];
if (now == 0 && i > 1) {
... | 10 |
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const int dxo[8] = {-1, -1, -1, 0, 1, 1, 1, 0},
dyo[8] = ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[300005];
int dp[300005][35];
int solve(int idx, int cur) {
if (idx == n) return 0;
int &ret = dp[idx][cur];
if (~ret) return ret;
int x = min(a[idx], cur);
ret = solve(idx + 1, cur - x) + a[idx] - x;
if (a[idx] / 10 + cur <= 30)
ret = min(ret, a... | 16 |
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
template <class T>
inline void chkmin(T &a, T b) {
if (a > b) a = b;
}
template <class T>
inline void chkmax(T &a, T b) {
if (a < b) a = b;
}
const int MOD = 1e9 + 7;
const int MAXN = 1 << 18;
int a[MAXN];
long long w[MAXN + MAXN];
int wa... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int m;
cin >> m;
set<string> ff;
for (int l = 0; l < m; ++l) {
string s;
cin >> s;
string fuck;
int n = s.size();
for (int i = 0; i < n;) {
if (s[i] == 'k') {
for (int j = i + 1; j < n; ++j) {
if (s[j] == 'k')... | 5 |
#include <bits/stdc++.h>
using namespace std;
int s[100001][3];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> s[i][1] >> s[i][2];
}
int mx = max(s[1][1], s[1][2]);
int t, t1;
for (int i = 2; i <= n; i++) {
t = max(s[i][1], s[i][2]);
t1 = min(s[i][1], s[i][2]);
if (mx ... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long a[200010], b[200010], le[200010], ri[200010], id[200010];
long long n, m, k;
long long ans;
long long search1(long long x) {
long long l = 1, r = m;
while (l <= r) {
long long mid = l + r >> 1;
if (b[mid] == x) return mid;
if (b[mid] > x)
r =... | 9 |
#include <bits/stdc++.h>
int main() {
int n;
int i, j;
int *table;
scanf("%d", &n);
table = (int *)malloc(n * n * sizeof(int));
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
if (i == 0 || j == 0)
*(table + i * n + j) = 1;
else
*(table + i * n + j) =
*(table ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int Inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
int n, m;
char t[205][205];
int cnt = 0, id[205][205][2];
struct Netflow {
struct Edge {
int to, cap, rev;
Edge(int to, int cap, int rev) : to(to), cap(cap), rev(rev) {}
};
vector<Edge> eg... | 20 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int r, b;
cin >> r >> b;
int xr[b], xb[b], yr[b], yb[b];
for (int i = 0; i < b; i++) {
cin >> xr[i] >> yr[i];
}
for (int i = 0; i < b; i++) {
cin >> xb[i] >> yb[i];
}
if (r != b) {
cout << "NO" << endl;
return 0;
}
... | 8 |
#include <bits/stdc++.h>
using namespace std;
long a[200005], b[200005], n, c, dp[200005][2];
int main() {
cin >> n >> c;
for (int i = 2; i <= n; i++) {
cin >> a[i];
}
for (int i = 2; i <= n; i++) {
cin >> b[i];
}
dp[1][0] = 0;
dp[1][1] = c;
for (int i = 2; i <= n; i++) {
dp[i][0] = min(dp[i... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long x, n;
cin >> n;
for (long long i = 0; i < n; i++) {
cin >> x;
if (x % 2 == 0) {
x--;
cout << x << ' ';
} else {
cout << x << ' ';
}
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long pwr(long long base, long long p, long long mod = (1000000007LL)) {
long long ans = 1;
while (p) {
if (p & 1) ans = (ans * base) % mod;
base = (base * base) % mod;
p /= 2;
}
return ans;
}
long long gcd(long long a, long long b) {
if (b == 0) r... | 15 |
#include <bits/stdc++.h>
using namespace std;
int lowbit(int n) { return n & (-n); }
unsigned upbit(unsigned x) {
x = x | (x >> 1);
x = x | (x >> 2);
x = x | (x >> 4);
x = x | (x >> 8);
x = x | (x >> 16);
return (x + 1) >> 1;
}
int lb[100010];
bool used[100010];
set<int> s[100010];
int main() {
int sum, l... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 10;
void IOI2017() {}
long long n, c[N], dp[N][5];
string a[N], b[N];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> c[i];
}
for (int i = 1; i <= n; i++) {
cin >> a[i];
b[i] = a[i];
reverse(b[i].begin(), b[i].e... | 8 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:36777216")
using namespace std;
template <class T>
inline T &RD(T &);
template <class T>
inline void OT(const T &);
inline long long RD() {
long long x;
return RD(x);
}
inline double &RF(double &);
inline double RF() {
double x;
return RF(x);
}
inline cha... | 20 |
#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
ostream &operator<<(ostream &out, pair<T1, T2> a) {
return (out << "(" << a.first << "; " << a.second << ")");
}
template <typename T1>
ostream &operator<<(ostream &cout, vector<T1> &a) {
if ((int)a.size() == 0) return (cout << "()");... | 11 |
#include <bits/stdc++.h>
using namespace std;
ostream& operator<<(ostream& cerr, vector<long long> aux) {
cerr << "[";
for (auto e : aux) cerr << e << ' ';
cerr << "]";
return cerr;
}
struct state {
int x, y;
int where;
};
const int maxN = 100011;
const int maxD = 52;
const int init = 1000000000;
int n, m, ... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int INF = 0x7fffffff;
const double eps = 1e-5;
int n;
int a[3005], res[3005];
int main(void) {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
cin >> n;
cout << "? 1 3" << endl;
cin >> a[0];
cout << "? 2 3" << endl;
cin >> ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, a, b, cnt[100000] = {};
scanf("%d %d", &n, &m);
for (int i = 0; i < m; i++) {
scanf("%d %d", &a, &b);
cnt[a - 1]++;
cnt[b - 1]++;
}
bool ok = 1;
for (int i = 0; i < n; i++)
if (cnt[i] != 2) ok = 0;
if (ok) return 0 * prin... | 4 |
#include <bits/stdc++.h>
using namespace std;
deque<int> generatePrimes(const int MXPRIME) {
vector<bool> isPrime(MXPRIME + 1, 1);
deque<int> primes;
for (int i = 2; i <= MXPRIME; ++i) {
if (!isPrime[i]) {
continue;
}
primes.push_back(i);
for (long long j = (long long)i * i; j <= MXPRIME; j ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char a[105];
cin >> a;
int p = 0, i = 0;
for (int i = 0; i < strlen(a); i++) {
if (a[i] == 'D' && a[i + 1] == 'a' && a[i + 2] == 'n' && a[i + 3] == 'i' &&
a[i + 4] == 'l') {
p++;
i = i + 4;
} else if (a[i] == 'O' && a[i + 1] ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-7;
const double PI = acos(-1.0);
const long long MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
int n;
long long num[3005], dp[3005][3005];
long long b[3005];
int main() {
while (scanf("%d", &n) != EOF) {
... | 15 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, m;
cin >> n >> m;
string s[n];
for (long long i = 0; i < n; ++i) {
cin >> s[i];
}
vector<pair<pair<long long, long long>, long long>> v;
for (long long i = 0; i < n; ++i) ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3005;
const int mod = 998244353;
int n, m;
string s, t;
int dp[N][N];
void add(int& u, int v) { u = (u + v) % mod; }
int solve(int l, int r) {
int& res = dp[l][r];
if (res != -1) return res;
if (l == r) {
return res = ((l > m || t[l] == s[1]) ? 1 : 0... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, y;
cin >> n >> x >> y;
if (x >= n && y >= n)
cout << "Yes";
else
cout << "No";
}
| 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.