solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
cerr.writ... | 9 |
#include <bits/stdc++.h>
int arr[200001], seq[200001];
int main() {
int n, t, a, x, index = 1;
double sum = 0;
scanf("%d", &n);
while (n--) {
scanf("%d", &t);
if (t == 1) {
scanf("%d%d", &x, &a);
arr[x - 1] += a;
sum += a * x;
} else if (t == 2) {
scanf("%d", &a);
seq[i... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
int n;
while (cin >> n) {
int polices = 0;
int ans = 0;
for (int i = 0; i < n; i++) {
int val;
cin >> val;
if (val - -1)
polices += val;
else {
if (polices == 0)
ans++;... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long n;
vector<long long> dp(100005, 0);
vector<long long> cnt(100005, 0);
void run_case() {
for (int i = 0; i < 100005; i++) {
dp[i] = 0;
cnt[i] = 0;
}
cin >> n;
for (long long i = 0; i < n; i++) {
long long x;
cin >> x;
cnt[x]++;
}
n =... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 300000;
static int lt[maxn * 4];
static int h[20][maxn];
long long sqr(long long x) { return x * x; }
struct T {
long long D, R;
int P, M;
friend bool operator<(const T &A, const T &B) { return A.D < B.D; }
} S[maxn];
long long srt[maxn];
static int n... | 16 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T rd() {
T nmb = 0;
int sgn = 0;
char chr = getchar();
while (!isdigit(chr)) {
if (chr == '-') sgn = 1;
chr = getchar();
}
while (isdigit(chr)) {
nmb = (nmb << 3) + (nmb << 1) + chr - '0';
chr = getchar();
}
retur... | 15 |
#include <bits/stdc++.h>
using namespace std;
int p[1010], leaf[1010], chil[1010];
int main() {
int n;
scanf("%d", &n);
for (int i = 2; i <= n; i++) scanf("%d", &p[i]);
for (int i = (1); i <= (n); ++i) leaf[i] = 1, chil[i] = 0;
for (int i = (1); i <= (n); ++i) leaf[p[i]] = 0;
for (int i = (1); i <= (n); ++i... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1005;
const int MOD = 1e9 + 7;
int n;
long long dp[N][N], ans;
int main() {
scanf("%d", &n);
dp[0][0] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= i; j++) {
if (j) dp[i][j] = (dp[i][j] + dp[i][j - 1]) % MOD;
dp[i][j] = (dp[i][... | 13 |
#include <bits/stdc++.h>
using namespace std;
int b[100][100];
int a[100];
int main(void) {
int n;
cin >> n;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) cin >> b[i][j];
memset(a, 0, sizeof(a));
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
for (int k = 0; k < 32; k+... | 7 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target( \
"sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,tune=native")
using namespace std;
template <typename T1, typename T2>
inline void mine(T1 &x, const T2 &y) {
... | 17 |
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
cin >> n;
vector<int> v(n + 9);
int mn = INT_MAX;
for (int i = 0; i < (n); i++) {
int x;
cin >> x;
v[i] = x;
;
mn = min(mn, x);
}
int lI = 0;
bool f = 1;
int ans = 1000000009;
for (int i = 0; i < (n); i++) {
if (... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, l, c = 0;
cin >> n >> l;
while (!(l % n)) {
l /= n;
c++;
}
if (l == 1 && c)
cout << "YES\n" << c - 1 << endl;
else
cout << "NO" << endl;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int a, b;
cin >> a >> b;
set<int> answer;
int n = a + b;
if (b > a) swap(a, b);
if (!(n & 1)) {
int diff = a - n / 2;
int cnt = 0;
while (cnt <= b) {
answer.insert(diff);
diff += 2;
++cnt;
}
} else {
a--;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
int ll, rr;
const int maxN = 1e5 + 20;
long long f[maxN][22], ans;
int a[maxN], cnt[maxN];
long long pairs(long long x) { return x * (x - 1) / 2; }
void solve(int l, int r, int j, int ld, int rd) {
int mid = (r + l) / 2;
int nm = 0;
long long mn = 1e18;
wh... | 17 |
#include <bits/stdc++.h>
long long m[200000], t[200000], ans, n;
int main() {
scanf("%I64d", &n);
for (int i = 1; i <= n; ++i) scanf("%I64d", &m[i]), t[i] = m[i] + 1;
for (int i = 2; i <= n; ++i)
if (t[i] < t[i - 1]) t[i] = t[i - 1];
for (int i = n; i >= 2; --i)
if (t[i - 1] < t[i] - 1) t[i - 1] = t[i] ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200000 + 10;
struct qry {
int l, r, u, d;
long long t[10];
} q[MAXN];
vector<pair<int, int> > row[MAXN];
int a[MAXN], sum[MAXN];
int n, m;
void update(int x, int v) {
while (x <= n) {
sum[x] += v;
x += (x & -x);
}
}
int query(int x) {
int ... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, h, p = 1000003;
long long quick_mod(long long a, long long b) {
long long ans = 1;
a %= p;
while (b) {
if (b & 1) {
ans = ans * a % p;
b--;
}
b >>= 1;
a = a * a % p;
}
return ans;
}
long long C(long long n, long long m) ... | 13 |
#include <bits/stdc++.h>
using namespace std;
void die() {
cout << "NO" << endl;
exit(0);
}
const int limit = 1005;
struct elem {
int u, v, val;
elem() {}
elem(int u, int v, int val) : u(u), v(v), val(val) {}
};
int n;
vector<pair<int, int> > g[limit];
int example[limit];
vector<elem> sol;
void precompute(int... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char s[100];
cin >> s;
int k = strlen(s), i;
for (i = 0; i < k; i++) {
if (s[i] == 'e' || s[i] == 'E' || s[i] == 'a' || s[i] == 'o' ||
s[i] == 'y' || s[i] == 'u' || s[i] == 'i' || s[i] == 'A' ||
s[i] == 'O' || s[i] == 'Y' || s[i] == ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int solve(vector<int>& v) {
int ans = v[0] ^ v[1];
vector<int> st;
for (int i = 0; i < v.size(); i++) {
while (!st.empty() && st.back() < v[i]) st.pop_back();
st.push_back(v[i]);
if (st.size() >= 2) ans = max(ans, st[st.size() - 1] ^ st[st.size() - 2]);
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, k;
while (cin >> n >> m >> k) {
int pl[n + 5], gap[n + 5], tot;
for (int i = 0; i < n; ++i) {
cin >> pl[i];
if (i >= 1) gap[i] = pl[i] - pl[i - 1] - 1;
}
tot = pl[n - 1] - pl[0] + 1;
sort(gap + 1, gap + n);
for ... | 6 |
#include <bits/stdc++.h>
using namespace std;
vector<int> fac(int x) {
if (x == 1) return {};
vector<int> ret;
for (int i = 2; i * i <= x; i++) {
if (x % i == 0) {
ret.emplace_back(i);
while (x % i == 0) x /= i;
}
}
if (x != 1) ret.emplace_back(x);
return ret;
}
const int maxn = 112345;
... | 21 |
#include <bits/stdc++.h>
const int mod = 998244353;
const int gmod = 3;
const int inf = 1039074182;
const double eps = 1e-9;
const double pi = 3.141592653589793238462643383279;
const long long llinf = 2LL * inf * inf;
template <typename T1, typename T2>
inline void chmin(T1 &x, T2 b) {
if (b < x) x = b;
}
template <t... | 18 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, a, b;
double al[100005], bl[100005], dbl[100005];
double ans;
long long ansa, ansb;
double dis(double ax, double ay, double bx, double by) {
return (sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by)));
}
double calc(int pa, int pb) {
return (dis(0, 0, a... | 11 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
os << "[";
for (auto const &vv : V) os << vv << ",";
os << "]";
return os;
}
template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P) {
os << "(" << P.first << "," << P.second << ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int LOGN = 20;
struct edge {
int v, id;
edge(const int& _v = 0, const int& _id = 0) {
v = _v;
id = _id;
}
};
int n;
int p[N][LOGN];
int h[N];
int dp[N];
int ans[N];
vector<edge> g[N];
void dfs_lca(int u) {
for (const edge& e : g[... | 11 |
#include <bits/stdc++.h>
using namespace std;
const unsigned long long MOD = 257;
int ans[100005], sg[100005], mex[100005];
void getsg(int n) {
for (int i = 2; i * (i + 1) / 2 <= n; i++) {
if ((2 * n) % i == 0) {
int t = 2 * n / i - i + 1;
if ((t & 1) || t < 0) continue;
t /= 2;
mex[sg[t -... | 12 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9 +7;
const int LM = 2e5 + 4;
int N;
int l,r;
ll fact[LM],ifact[LM];
ll modPow(ll a, int k){
if(k==0) return 1;
ll d = modPow(a,k/2);
if(k&1) return d*d%MOD*a%MOD;
return d*d%MOD;
}
ll modInv(ll a){return modPow(a... | 15 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long x = 0;
bool flag = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') flag = 0;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 1) + (x << 3) + ch - '0';
ch = getchar();
}
re... | 18 |
#include <bits/stdc++.h>
using namespace std;
long long conversion(string p) {
long long o;
o = atol(p.c_str());
return o;
}
string toString(long long h) {
stringstream ss;
ss << h;
return ss.str();
}
int gcd(int a, int b) { return (b == 0 ? a : gcd(b, a % b)); }
int lcm(int a, int b) { return (a * (b / gcd... | 4 |
#include <bits/stdc++.h>
using namespace std;
vector<string> Possible;
void GetAllPossible(int n, string Guss) {
if (Guss.size() == n) {
Possible.push_back(Guss);
} else {
GetAllPossible(n, Guss + "7");
GetAllPossible(n, Guss + "4");
}
}
string Rev(string t) {
string t1 = "";
for (int i = t.size()... | 3 |
#include <bits/stdc++.h>
using namespace std;
pair<long long, int> dist[400000];
long long sum[400000];
long long ans[400000];
int main() {
int n, k;
cin >> n;
for (int i = 1; i <= n; i++) {
long long t;
cin >> t;
dist[i] = pair<long long, int>(t, i);
}
cin >> k;
sort(dist + 1, dist + 1 + n);
... | 12 |
#include <bits/stdc++.h>
using namespace std;
deque<int> st;
int net[500000];
int N, M;
int main() {
int t;
cin >> t;
while (t--) {
long long n, g, b;
cin >> n >> g >> b;
long long mn = (n + 1) / 2;
long long pr = mn / g;
long long pro = (pr) * (g + b);
pro += (mn % g == 0) ? -b : mn % g;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
void setIO(const string &name = "") {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
if (name.length()) {
freopen((name + ".in").c_str(), "r", stdin);
freopen((name + ".out").c_str(), "w", stdout);
}
}
template <typename T>
void read(vec... | 5 |
#include <bits/stdc++.h>
using namespace std;
string s[25];
int n, m;
int msk[25][128], dp[21][1 << 21], arr[25][25];
int sum[25][128];
void solve() {
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> s[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> arr[i][j];
sum... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const double eps = 1e-6;
const int mod = 1e9 + 7;
const int maxn = 1010;
int n;
int main() {
scanf("%d", &n);
int mn = inf;
int ans = 0;
for (int i = 1; i <= n; i++) {
int a, p;
scanf("%d%d", &a, &p);
mn = min(mn, p);
ans ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
using ll = long long;
int n, a[N], f[N], pr[N];
map<int, vector<int> > pos;
map<int, int> pp;
map<int, vector<pair<int, int> > > pf;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i)
scanf("%d", &a[i]), pos[a[i]].push_back(i), pp[a[i]... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
ifstream in("/home/lionell/Developing/acm/codeforces/VK_Cup_2015/in.txt");
int q = 0;
cin >> q;
for (int j = 0; j < q; ++j) {
int m = 0, k = 0;
cin >> m >> k;
int *a = new int[k + 1]();
bool *empty = n... | 13 |
#include <bits/stdc++.h>
using namespace std;
struct info {
long long val;
string name;
};
info data[100000 + 10];
int main() {
long long n, x, y;
cin >> n >> x >> y;
long long a[n + 10];
for (int i = 1; i <= n; i++) cin >> a[i];
vector<int> res;
long long cnt1 = 0, cnt2 = 0;
while (cnt1 < x || cnt2 <... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
int n, k;
cin >> n >> k;
vector<int> h(n);
for (int i = 0; i < h.size(); ++i) cin >> h[i];
;
vector<int> h1(n);
for (int i = 0; i < n - 1; ++i) {
h1[i] = h[i + 1];
}
h1[n - 1... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
if (n % 2 != 0) {
if (a[0] % 2 == 1 && a[n - 1] % 2 == 1)
cout << "Yes" << endl;
else
cout << "No" << endl;
} else {
cout << "No" << endl;
}
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
struct edge {
int next, now;
} d[100010];
struct node {
int r, a, p;
} peo[100010];
struct question {
int mr, l, r, p;
} que[100010];
int sum[100010], c[100010], tree[100010 * 4], pos[100010], ans[100010],
id[100010];
int n, m, k;
bool compare1(const node &x, cons... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const int M = 1000010;
const int mod = 1000000007;
const double eps = 1e-8;
const double Pi = 2 * acos(0.0);
char s[M];
int main() {
ios::sync_with_stdio(0);
cin >> s;
int tmp = 0, zero = 2, con = 0, single = 0;
for (int i = 0; s[i];) {
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n;
double ans, l, r;
int main() {
cin >> n >> r;
l = sqrt(2);
for (int i = 1; i <= n; ++i) {
ans += 2;
ans += (l + 2) * ((i > 1) + (i < n));
if (i > 2) ans += (2 * l) * (i - 2) + 1.0 * (i - 2) * (i - 1);
if (i < n - 1) ans += (2 * l) * (n - 1 - i) ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 50;
const int LOGN = 17;
vector<int> adj[MAXN];
int pa[MAXN][LOGN], level[MAXN];
int n;
void dfs(int x, int p) {
for (auto c : adj[x]) {
if (c != p) {
pa[c][0] = x;
level[c] = level[x] + 1;
dfs(c, x);
}
}
}
void findPa() ... | 11 |
#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int qpow(int x, int y) {
int ret = 1;
while (y) {
if (y & 1) ret = (long long)ret * x % 998244353;
y >>= 1;
x = (long long)x * x % 998244353;
}
return ret;
}
int C(int n, int m) {
if (m > n) return 0;
int a = 1, b = 1;
for (int i = n... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000 * 1000 * 1000 + 7;
const int INF = 1000 * 1000 * 1000;
const long long LINF = (long long)INF * INF;
int n, a[300100];
int cnt[300100];
vector<int> prm[300100];
int dp[1 << 7];
int c[1 << 7];
int check(int x) {
vector<int> prm = ::prm[x];
int sz = pr... | 17 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
if (a == 0) return b;
return gcd(b % a, a);
}
int findGCD(int arr[], int n) {
int result = arr[0];
for (int i = 1; i < n; i++) {
result = gcd(arr[i], result);
if (result == 1) {
return 1;
}
}
return result;
}
int soved(i... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int arr[n + 2];
int count = 0;
int j = 0;
for (int i = 1; i <= n; i++) cin >> arr[i];
for (int i = 1; i < n; i++) {
for (j = 0; i + (1 << j) <= n; j++)
;
arr[i + (1 << (j - 1))] += arr[i];
count += arr[i];
co... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long a, b, c, d;
cin >> a >> b >> c >> d;
cout << b << " " << c << " " << c << endl;
}
}
| 0 |
#include <bits/stdc++.h>
const int mod = 1e9 + 7;
using namespace std;
inline int read() {
int x = 0, y = 0;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') y = 1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
return y ? ... | 17 |
#include <bits/stdc++.h>
using namespace std;
long long K(long long x, int y = 998244353 - 2) {
long long t = 1;
for (; y; y >>= 1, x = x * x % 998244353)
if (y & 1) t = t * x % 998244353;
return t;
}
long long n, x, y, p, np, f[2020][2020], g[2020], h[2020];
void U(long long &x, long long y) { x = (x + y) % ... | 20 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
void solve() {
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
if (x1 != x2 && y1 != y2 && abs(x1 - x2) != abs(y1 - y2))
cout << -1 << "\n";
else if (x1 == x2)
cout << x1 + abs(y1 - y2) << " " << y1 << " " << x2 + abs(y1 - y2) << " ... | 4 |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:16777216")
using namespace std;
const int INF = 1000000000;
const int MAX = 5007;
const int MAX2 = 7000;
const int BASE = 1000000000;
int n;
string S;
int B[26][MAX][26];
int C[26][MAX];
int W[26];
int main() {
cin >> S;
n = (int)S.size();
for (int i = (0);... | 8 |
#include <bits/stdc++.h>
int f(int x) {
int i, j, res = 0;
for (i = j = 1; i <= x; i *= 2, j *= 10)
;
for (i /= 2, j /= 10; i; i /= 2, j /= 10) res += x / i % 2 * j;
return res;
}
int main() {
int i, n;
scanf("%d", &n);
for (i = 1; f(i) <= n; i++)
;
printf("%d", i - 1);
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, i, j, k = 0;
cin >> n;
long long ar[n];
for (i = 0; i < n; i++) cin >> ar[i];
long long one[n + 1], two[n], dp[n][n];
for (i = 0; i < n; i++) {
one[i] = two[i] = 0;
}
for (i = 1; i < n; i++) {
if (ar[i - 1] == 1)
one[i... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long int n;
cin >> n;
long int m = n;
long int count = 1;
m = n / 2;
count = m * 3;
cout << count << endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
#pragma optimize("Ofast")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimiz... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t;
cin >> t;
while (t--) {
long long int a, b;
cin >> a >> b;
long long int x, ans;
x = min(a, b);
ans = (a ^ x) + (b ^ x);
cout << ans << endl;
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, i;
cin >> n;
for (i = 0; i < n; i++) {
cin >> x;
if (x <= 7)
cout << "1\n";
else if (x % 7 == 0) {
cout << x / 7 << endl;
} else
cout << x / 7 + 1 << endl;
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-8;
const double PI = acos(-1);
double sq(double x) { return x * x; }
long long sq(long long x) { return x * x; }
int sign(long long x) { return x < 0 ? -1 : x > 0 ? 1 : 0; }
int sign(int x) { return x < 0 ? -1 : x > 0 ? 1 : 0; }
double sign(double x) {... | 25 |
#include <bits/stdc++.h>
using namespace std;
const int M = 100100;
struct data {
int i, w, isin;
data(int a = 0, int b = 0, int c = 0) { i = a, w = b, isin = c; }
bool operator<(const data &d) const {
if (w == d.w) return isin > d.isin;
return w < d.w;
}
};
vector<data> A;
int cur[M];
pair<int, int> ed... | 9 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int N, M;
string S[1001];
int label[1001][1001];
int sticker = 1;
int siz[1000001];
int dir[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
void dfs(int x, int y) {
if (x < 0 || x >= N || y < 0 || y >= M || ... | 8 |
#include <bits/stdc++.h>
const int maxn = 3e3 + 10;
using namespace std;
long long gcd(long long p, long long q) { return q == 0 ? p : gcd(q, p % q); }
long long qpow(long long p, long long q) {
long long f = 1;
while (q) {
if (q & 1) f = f * p;
p = p * p;
q >>= 1;
}
return f;
}
int n, m, k, t, a[ma... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b;
cin >> a >> b;
for (int i = 0; i < a.length(); i++) {
a[i] = tolower(a[i]);
b[i] = tolower(b[i]);
}
if (a == b)
cout << 0;
else if (a > b)
cout << 1;
else
cout << -1;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(nam... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
int T;
cin >> T;
while (T--) {
long long n, g, b;
cin >> n >> g >> b;
long long n1 = 0, n2 = 0;
if (n % 2 == 0)
n1 = n / 2;
else
n1 = n / 2 + 1;
n2 = n - n1;
long lon... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long inf64 = 0x3f3f3f3f3f3f3f3fLL;
const double oo = 10e9;
const double eps = 10e-9;
const double pi = acos(-1.0);
const int maxn = 111;
int n, m;
vector<int> g[maxn];
vector<int> v[maxn];
int way[maxn];
int tot;
bool inq[maxn];
long l... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long T, n, m, res;
int main() {
cin >> T;
while (T--) {
cin >> n >> m;
if (n < m) {
cout << n << endl;
continue;
}
res = 0;
for (long long i = 1; i * i <= m; i++) {
if (m % i) continue;
if (i != 1) {
long long tmp... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long n, k, a[200005], rem;
bool comp(long long x, long long y) {
if (x % 10 > y % 10)
return true;
else
return false;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k;
for (long long i = 1; i <= n; ++i) cin >> a[i];
sort(a + 1... | 6 |
#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::deque;
using std::get;
using std::greater;
using std::ifstream;
using std::ios_base;
using std::list;
using std::lower_bound;
using std::make_pair;
using std::make_tuple;
using std::map;
using std::max;
using std::max_element;
using std::min;
using st... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 200005;
const int mod = (int)1e9 + 7;
const int inf = (int)1e9;
const int N = 200005;
vector<int> adj[N];
int t[N], mini[N], counter, id[N], scc;
vector<int> s;
vector<int> sol[maxN];
bool valid[maxN];
void dfs(int u) {
t[u] = mini[u] = ++counter;
s.pus... | 11 |
#include <bits/stdc++.h>
using namespace std;
class graph {
public:
long long n;
vector<bool> vis;
vector<long long> *adj;
graph(long long b) {
n = b;
adj = new vector<long long>[n];
vis.resize(n, false);
}
void add_edge(long long b, long long c);
bool dfs(long long b, long long p);
};
void g... | 8 |
#include <bits/stdc++.h>
int main() {
int i = 1, n, j = 0;
int a[1001];
scanf("%d", &n);
while (j <= n) {
if (i < 10)
a[j] = i;
else if (i < 100) {
a[j] = i / 10;
a[j + 1] = i % 10;
j++;
} else if (i < 1000) {
a[j] = i / 100;
a[j + 1] = (i / 10) % 10;
a[j + ... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int x, y;
};
int n, m, e, c[105][105], ans[2 * 105];
node a[105 * 105];
long long kk, f[2 * 105][2 * 105];
bool cmp(node a, node b) { return c[a.x][a.y] < c[b.x][b.y]; }
int main() {
scanf("%d%d%I64d", &n, &m, &kk);
for (int i = (1); i <= (n); i++)
f... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const long long llinf = (long long)9e18;
const int N = (int)1e7 + 111;
const long double PI = (long double)acos(-1);
int main() {
long long ans = 0;
int n, x;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &x);
ans ^= (l... | 8 |
#include <bits/stdc++.h>
using namespace std;
inline long long minOf(long long x, long long y) { return (x < y ? x : y); }
inline long long maxOf(long long x, long long y) { return (x > y ? x : y); }
inline long long mabs(long long x) { return (x < 0 ? -x : x); }
int main() {
int n;
cin >> n;
int grid[1002][1002]... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int n, ans, tot;
int a[maxn], b[maxn];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
sort(a + 1, a + 1 + n);
for (int i = 1, j; i <= n; ++i) {
j = upper_bound(a + 1, a + 1 + n, a[i]) - a - 1;
b[++tot... | 5 |
#include <bits/stdc++.h>
const bool DEBUG = false;
const int N_BASE = 50000;
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<... | 23 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = (long long)1e9 + 7;
const int inf = (int)2e9;
const long long INF = (long long)2e18;
const int base = 1000 * 1000 * 1000;
const int maxn = 200005;
const long double pi = acosl(-1.0);
const long double eps = 1e-9;
void solve() {
string s;
cin >> s;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
bool verify(vector<int>& nums, int op, int m) {
int prev = 0;
for (int i = 0; i < nums.size(); i++) {
if (nums[i] > prev) {
if (nums[i] + op >= m && (nums[i] + op) % m >= prev) {
continue;
} else {
prev = nums[i];
}
} else {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> solution(long long a, long long b, long long n) {
for (long long i = 0; i * a <= n; i++) {
if ((n - (i * a)) % b == 0) {
return {i, (n - (i * a)) / b};
}
}
return {-1, -1};
}
const long long N = 1e6 + 100;
long long ar[N + 100]... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long int n, m;
cin >> n >> m;
long long int days;
if (n == 2)
days = 28;
else if (n == 1 || n == 3 || n == 5 || n == 7 || n == 8 || n == 10 || n == 12)
days = 31;
else
... | 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#pragma GCC optimize("unroll-loops")
using namespace std;
template <class T>
inline void amin(T &x, const T &y) {
if (y < x) x = y;
}
template <class T>
inline void amax(T &x, const T &y) {
if (x < y) x = y;
}
int N;
int A[2222];
vector<... | 12 |
#include <bits/stdc++.h>
using namespace std;
const double g = 10.0, eps = 1e-7;
const int N = 100000 + 10, maxn = 60000 + 10, inf = 0x3f3f3f;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
double ax, ay, bx, by, cx, cy;
cin >> ax >> ay >> bx >> by >> cx >> cy;
if ((ax - bx) * (ax - bx) + (ay - by) * (... | 6 |
#include <bits/stdc++.h>
#pragma GCC optimize(3)
#pragma GCC optimize(2)
using std::cin;
using std::cout;
using std::string;
using std::vector;
static const int MOD = 1000000000 + 7;
static const int N = 300000 + 8;
extern "C" {
__attribute__((always_inline)) inline static long long gcd(long long x,
... | 17 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int P = 998244353;
int power(int a, int b) {
int res = 1;
for (; b > 0; b /= 2, a = ll(a) * a % P) {
if (b % 2 == 1) {
res = ll(res) * a % P;
}
}
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nu... | 22 |
#include <bits/stdc++.h>
int f;
double s, dx, dy, x[3], y[3], r[3], t[3];
double F(double dx, double dy) {
double ret = 0;
for (int i = 0; i < 3; i++)
t[i] =
sqrt(((dx - x[i]) * (dx - x[i])) + ((dy - y[i]) * (dy - y[i]))) / r[i];
for (int i = 0; i < 3; i++)
ret += ((t[i] - t[(i + 1) % 3]) * (t[i] ... | 18 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> l[200010], r[200010];
int a[200010], c[200010];
void work(int n) {
if (a[1] > 1) {
puts("-1");
return;
}
l[1] = r[1] = make_pair(1, 1);
for (int i = 2; i <= n; i++) {
l[i] = l[i - 1].second >= 2
? make_pair(l[i - 1].first + ... | 17 |
#include <bits/stdc++.h>
using namespace std;
struct point {
int x, y;
} p[1005], v[1005];
int convert(int y) {
if (y == 0) return 0;
if (y > 0) return 1;
if (y < 0) return -1;
}
bool clock(point a, point b) {
if (a.x == 0 && a.y == 1 && b.x == 1 && b.y == 0) return true;
if (a.x == 1 && a.y == 0 && b.x == ... | 7 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MAX = 10000000000000;
const int mod = 1e9 + 7;
void solve() {
int n, k;
cin >> n >> k;
string s1 = "";
while (k--) {
int l, r;
cin >> l >> r;
}
for (int i = 0; i < n; i++) {
if (i % 2 == 0)
s1 += "0";
else
... | 5 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int N = 1e4 + 10;
const long double EPS = 1e-10;
int n;
long double x[N], y[N], z[N], vs, vp, px, py, pz;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.setf(ios::fixed), cout.precision(9);
cin >> n;
for (int i = 0; i < n + 1; ... | 13 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
char ch = getchar();
int x = 0, w = 1;
while (ch < '0' || ch > '9') {
if (ch == '-') w = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 1) + (x << 3) + ch - '0', ch = getchar();
}
return x * w;
}
inline long lo... | 20 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
while (n--) {
long long x, y, z, w;
scanf("%I64d%I64d", &x, &y);
z = x * y;
w = pow(z, 1.0 / 3) + 0.5;
if (w * w * w == z && x % w == 0 && y % w == 0)
puts("Yes");
else
puts("No");
}
return 0... | 9 |
#include <bits/stdc++.h>
const double eps = 1e-8;
const int N = 111111;
const int mod = 1000000;
const double pi = acos(-1.0);
const long long INF = 0x7f7f7f7f;
const double inf = 1e50;
template <class T>
inline T minx(T a, T b) {
return (a == -1 || b < a) ? b : a;
}
template <class T>
inline T gcd(T a, T b) {
retu... | 12 |
#include <bits/stdc++.h>
const int inf = 1e8;
const int mod = 1e9 + 7;
double eps = 0.0000000001;
const int maxn = 1e5 + 7;
using namespace std;
string maze[20];
int yaz[3][3][3][3];
int main() {
int i, j, u;
string s[3][3][3];
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
for (u = 0; u < 3; u++) ... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long in() {
int32_t x;
scanf("%d", &x);
return x;
}
inline long long lin() {
long long x;
scanf("%lld", &x);
return x;
}
inline void read(long long *a, long long n) {
for (long long i = 0; i < n; i++) a[i] = in();
}
inline void readL(long long *a, long lo... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
struct edge {
int to, nxt;
} e[N << 1];
int head[N], m, n, u[N], v[N], st[N], ed[N], dfn = 0, f[N], dp[N][21], val[N],
t[N << 2], dep[N];
vector<int> vec[N];
int cnt = 0;
void addedge(int x, int y) {
++c... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long int t, n, i, x, mx, mn, f, j, s, r, y, c, m, k;
cin >> t;
while (t--) {
cin >> n >> k;
vector<long long int> v, v1[n + 2], v2(n + 2, 0);
map<long long int, long long int> M, M1;
map<l... | 6 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:160000000")
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a, b;
a.resize(n + 1);
for (int i = 0; i < n; i++) {
int t;
cin >> t;
a[t] = i;
}
int cnt = 0, cur = 1;
for (int i = 2; i <= n; i++) {
if (a[i] > a[i - 1])
... | 8 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.