solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
const int mod = 1e9 + 7;
int digit[maxn];
int dp[10][2][1 << 10];
int n, k;
int g[1 << 10];
int dfs(int len, bool lim, int s) {
if (len == 0) return g[s] <= k;
int &x = dp[len][lim][s];
if (~x) return x;
int low = lim ? digit[len] : 0;
in... | 13 |
#include <bits/stdc++.h>
using namespace std;
int c[2][110][110], dp[110], s[500010], n, k, p;
void update(int f, int t, int x, int w) {
for (int i = x + 1; i <= p + 1; i += i & -i) c[f][t][i] = min(c[f][t][i], w);
}
int query(int f, int t, int x) {
int res = 0x3f3f3f3f;
for (int i = x + 1; i; i -= i & -i) res = ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 10010;
const int M = 15;
const double eps = 1e-7;
const int INF = 1 << 30;
int n;
struct node {
double x, y, z;
node() { x = y = z = 0; }
node(double xx, double yy, double zz) {
x = xx;
y = yy;
z = zz;
}
} poy[N], ori;
double vp, vs, prelen... | 13 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)1e18;
const long long mod = (long long)1e9 + 7;
const double pi = acos(-1.0);
const double eps = (double)1e-9;
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};
const int N = 200500;
const int block = 450;
long long cur, ... | 15 |
#include <bits/stdc++.h>
using namespace std;
int r1, r2, c1, c2, d1, d2;
int a[2][2];
bool solve() {
if (a[0][0] + a[0][1] != r1) return false;
if (a[1][0] + a[1][1] != r2) return false;
if (a[0][0] + a[1][0] != c1) return false;
if (a[0][1] + a[1][1] != c2) return false;
if (a[0][0] + a[1][1] != d1) return ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int Inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
struct Point {
long long x, y;
Point() : x(0), y(0) {}
Point(long long x, long long y) : x(x), y(y) {}
long long operator*(long long pos) const { return x * pos + y; }
};
struct DynLichao {
st... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
long long int x = 1LL << (n + 1);
cout << x - 2;
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long powerm(long long x, long long y, long long M) {
long long res = 1;
while (y) {
if (y & 1) res = (res * x) % M;
y = y >> 1;
x = (x * x) % M;
}
return res % M;
}
long long power(long long x, long long y) {
long long res... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
string n;
int len;
int solve_00() {
int pos[20], cnt = 0;
for (int i = 0; i < len; i++)
if (n[i] == '0') pos[++cnt] = i;
if (cnt < 2) return inf;
return len - 1 - pos[cnt] + len - 2 - pos[cnt - 1];
}
int solve_other(int l1, int l2) {
... | 13 |
#include <bits/stdc++.h>
using namespace std;
int u, v, mod;
inline int add(int a, int b) {
if ((a += b) >= mod) a -= mod;
return a;
}
inline int mult(int a, int b) {
long long t = 1ll * a * b;
if (t >= mod) t %= mod;
return t;
}
inline int power(int a, int b) {
int out = 1;
while (b) {
if (b & 1) out... | 19 |
#include <bits/stdc++.h>
using namespace std;
struct query {
int l, r, id;
query() : l(0), r(0), id(0){};
query(int l, int r, int id) : l(l), r(r), id(id){};
};
int n, t, a[202020], num[1000001], bb[202020], ll, rr;
vector<query> qq[400];
long long ans[202020], cur = 0;
bool cmp(query q1, query q2) {
if (q1.r <... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200010;
int n, a[MAXN], b[MAXN];
int main() {
int T;
cin >> T;
while (T--) {
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i], b[i] = a[i];
sort(b + 1, b + n + 1);
int l = 1, r = n;
for (int i = 1; i <= n; i++) {
if (a[i] =... | 7 |
#include <bits/stdc++.h>
using namespace std;
struct aha {
long long ind, val;
aha() { ind = val = 0; }
} A[100005], B[100005];
long long C[200005], len = 0;
map<long long, long long> Ans;
int main() {
long long n, m;
cin >> n;
for (long long i = 1; i <= n; i++) {
cin >> A[i].ind >> A[i].val;
C[++len]... | 2 |
#include <bits/stdc++.h>
#pragma GCC optmize(2)
using namespace std;
constexpr int maxn = 2e5 + 100, inf = 0x7fffffff;
struct IO {
private:
static constexpr int ibufsiz = 1 << 20;
char ibuf[ibufsiz + 1], *inow = ibuf, *ied = ibuf;
static constexpr int obufsiz = 1 << 20;
char obuf[obufsiz + 1], *onow = obuf;
... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n, m, nr, k, i, j, l, c, a[11][11], s[11][11], cnt, v, w, sol;
int main() {
cin >> n >> m >> nr >> k;
for (i = 1; i <= nr; i++) {
cin >> l >> c;
a[l][c] = 1;
}
for (i = 1; i <= n; i++)
for (j = 1; j <= m; j++)
s[i][j] = a[i][j] + s[i - 1][j] + ... | 3 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
long long a1, b1, a2, b2;
cin >> a1 >> b1 >> a2 >> b2;
int cnt = 0;
long long area1 = a1 * b1;
long long area2 = a2 * b2;
long long com = gcd(area1, ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const long long cs = 200005;
const long long mod = 1000000007;
const double PI = 2 * acos(0.0);
void solve() {
long long int t, n, m, a, b, c, d, e, i, j, k, x, y, z, cnt = 0, cnt1 = 0;
bool flag = false;
cin >> n >> m >> x >> y;
cnt = x;... | 12 |
#include <bits/stdc++.h>
const int N = 510;
int DP[N][N], t[N][N], n, m, k;
int dx[] = {-2, -1, -1, -1, 0}, dy[] = {-1, -2, -1, 0, -1};
char map[N][N];
bool ok(int a, int b) {
for (int i = 0; i < 5; i++)
if (map[a + dx[i]][b + dy[i]] == '0') return 0;
return 1;
}
bool ok(int mid, int i, int j, int l) {
if (DP... | 12 |
#include <bits/stdc++.h>
using namespace std;
long ans;
string a;
bool comp(long a, long b) { return (a < b); }
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> a;
if (a.length() > 3)
for (int i = 0; i < a.length() - 3; i++) {
long l = 1, r = a.length() - i - 3;
if ((a[i] == 'b') &&... | 4 |
#include <bits/stdc++.h>
using namespace std;
int solve(int i, vector<int>* graph, int current_time, int level,
pair<int, int>* exp_time, vector<vector<pair<int, int>>>& levels,
int* vals, int* arr) {
if (levels.size() <= level) levels.push_back(vector<pair<int, int>>());
levels.at(level).push_b... | 14 |
#include <bits/stdc++.h>
using namespace std;
int par[1005];
int find(int x) {
if (par[x] == x)
return x;
else
return par[x] = find(par[x]);
}
void unity(int a, int b) {
int x = find(a);
int y = find(b);
par[x] = par[y];
}
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 10;
const long long INF = 1e18;
const int maxn = 1e4 + 5;
const int mod = 1e9 + 7;
long long n, k, l, m;
struct matrix {
int dat[2][2];
matrix() {}
matrix(int a, int b, int c, int d) {
dat[0][0] = a, dat[0][1] = b;
dat[1][0] = c, dat[1][1... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int count = 0;
string str;
cin >> str;
for (int i = 0; i < str.size(); i++) {
if (str[i] == 'H' || str[i] == 'Q' || str[i] == '9') {
count = count + 1;
break;
}
}
if (count > 0) {
cout << "YES";
} else {
cout << "NO";
... | 1 |
#include <bits/stdc++.h>
using namespace std;
list<long long int> l[100010];
long long int a[100010];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int n, m;
cin >> n >> m;
long long int i, x, y, ans;
bool flag;
for (i = 0; i < m; i++) {
cin >> x >> y;
x--;
y--;
l... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
long long int t;
cin >> t;
while (t--) {
long long int n;
cin >> n;
string a, b;
cin >> a >> b;
int has[26] = {0};
std::vector<int> v;
long long int cnt = 0;
for (long long int i = 0; i < n; i++)... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000006;
int n, q;
vector<vector<long long>> c;
vector<vector<int>> banned;
set<vector<int>> blocked;
long long sum[N];
long long ans = 0;
vector<int> ansv;
string getStr(vector<int>& a) {
string tmp = "";
for (int i = 0; i < (int)(n); ++i) {
tmp = tmp... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
string ans[] = {
"Washington", "Adams", "Jefferson", "Madison", "Monroe",
"Adams", "Jackson", "Van Buren", "Harrison", "Tyler",
"Polk", "Taylor", "Fillmore", "Pierce", "Buchanan",
"Lincoln", "Johnso... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 2;
const int LOG = 17;
const int inf = 1e9;
int jump[LOG][maxn];
int depth[maxn];
bool red[maxn];
int tin[maxn];
int tout[maxn];
int tmr = 0;
int dist[maxn];
int nearest[maxn];
queue<int> q;
vector<int> e[maxn];
vector<int> New;
int n;
void dfs(int v,... | 16 |
#include <bits/stdc++.h>
using namespace std;
int t, n, k, i, ansk;
string s, pr, sf, anss;
int main() {
ios_base::sync_with_stdio(0);
cin >> t;
while (t--) {
cin >> n >> s;
anss = s, ansk = 1;
for (k = 1; k <= n; k++) {
pr = s.substr(0, k - 1), sf = s.substr(k - 1);
if ((n - (k - 1)) & 1)... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, i;
cin >> n;
long long int a[n], b[n];
for (i = 0; i < n; i++) cin >> a[i];
for (i = 0; i < n; i++) cin >> b[i];
long long int dp[n + 1][2];
dp[0][0] = 0;
dp[0][1] = 0;
for (i = 1; i <= n; i++) {
dp[i][0] = max(a[i - 1] + ... | 6 |
#include <bits/stdc++.h>
using namespace std;
void preprocess() {}
int main() {
int n, m, a, b;
scanf("%d", &n);
;
scanf("%d", &m);
;
scanf("%d", &a);
;
scanf("%d", &b);
;
int ans = 0;
while (n >= m) {
if (b < a * m)
ans += b;
else
ans += a * m;
n -= m;
}
if (n > 0) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n;
int tree[300010 + 1];
int a[300010 + 1];
int get(int pos) {
int ret = 0, i;
for (i = pos; i; i -= (i & -i)) ret += tree[i];
return ret;
}
void update(int pos, int val) {
int i;
for (i = pos; i <= 300010; i += (i & -i)) tree[i] += val;
}
int vis[300010];
voi... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
set<int> x, y;
vector<int> ans;
for (int i = 0; i < n * n; i++) {
int a, b;
scanf("%d", &a);
scanf("%d", &b);
if (x.find(a) == x.end() && y.find(b) == y.end()) {
x.insert(a);
y.insert(b);
ans.p... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a1, b1, c1, a2, b2, c2;
scanf("%d%d%d%d%d%d", &a1, &b1, &c1, &a2, &b2, &c2);
if (a1 == 0 && b1 == 0 && c1 != 0) {
puts("0");
return 0;
}
if (a2 == 0 && b2 == 0 && c2 != 0) {
puts("0");
return 0;
}
if (a1 == 0 && b1 == 0 || a2 =... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e7 + 10;
const long long INF = 1e18;
const double eps = 0.0000001;
const long long mod = 1e9 + 7;
long long n, m;
pair<int, int> a[N];
map<int, int> maps;
void add(int x, int y) {
maps[x] += y;
if (maps[x] == 0) maps.erase(x);
}
int main() {
ios::sync_w... | 2 |
#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];
}
vector<pair<int, int>> P(n);
for (int i = 0; i < n; i++) {
P[i] = make_pair(a[i], i);
}
sort(P.rbegin(), P.rend());
vector<int> b(n);
for (int i = 0; i... | 18 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void pv(T a, T b) {
for (T i = a; i != b; ++i) cerr << *i << ' ';
cout << endl;
}
long long rev(long long x) {
long long res = 0;
for (; x; x /= 10) res = res * 10 + (x % 10);
return res;
}
long long gcd(long long a, long long b) { return b != 0... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, i, j, dp[55][15], sum;
string st;
bool bo = 1;
int main() {
cin >> st;
for (i = 0; i <= 9; i++) dp[0][i] = 1;
for (i = 0; i < st.length() - 1; i++) {
for (j = 0; j <= 9; j++) {
dp[i + 1][(j + st[i + 1] - '0') / 2] += dp[i][j];
if ((j + ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 123;
const int mod = 1e9 + 7;
const int INF = 1e9 + 1;
const long long INFL = 3e18 + 1;
const double pi = acos(-1.0);
inline void DoBetter() {
unsigned int FOR;
asm("rdtsc" : "=a"(FOR));
srand(FOR);
ios_base::sync_with_stdio(0);
cin.tie(0);
c... | 4 |
#include <bits/stdc++.h>
using namespace std;
bool compare(const pair<int, int> a, const pair<int, int> b) {
if (a.first == b.first)
return (a.second < b.second);
else
return (a.first > b.first);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
if (n % 2... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const int N = 210000;
long long n, k;
long long f[N], g[N];
long long qpow(long long a, long long b) {
long long res = 1;
for (; b > 0; b /= 2, a = a * a % mod)
if (b % 2) res = res * a % mod;
return res;
}
void init(int m) {
f[0] = 1;... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int M = 5000000;
int n, m, a[N];
long long k;
vector<int> v;
struct persistent_tree {
int lson[M], rson[M], c[M], T[M];
int tot, m;
void Init(int t, int _m) {
tot = 0;
m = _m;
T[t] = bulid(1, m);
}
int bulid(int l, int r) {
... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxm = 2e5 + 10;
const int maxn = 1e5 + 10;
const int N = 2e5 + 1;
int a[maxn], b[maxn], head[maxn];
int root[maxn];
struct node {
int ls, rs, flag;
long long b, k;
} tree[maxm * 15];
struct Edge {
int v, nxt;
} ed[maxm];
int ecnt, c... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000009;
const long long INFL = 1759849216489136867ll;
const double eps = 1e-9;
void solve();
int main() {
clock_t t_start, t_end;
solve();
return 0;
}
void solve() {
int n, m;
cin >> n >> m;
vector<vector<int> > matrix(n, vector<int>(m));
v... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int Max = 1e5 + 10;
int n, x, y;
int A[Max];
int B[Max];
set<pair<int, int>, greater<pair<int, int>>> _01, _02, _10, _12, _20, _21;
set<int> ansA, ansB;
int res;
void upd(int i, int cur, int nxt) {
int a = A[i], b = B[i];
if (cur == 0) {
_01.erase(make_pair(a,... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char c;
int ans = 0;
for (int i = 1; i < 6; i++) {
for (int j = 1; j < 6; j++) {
cin >> c;
if (c == '1') ans = abs(3 - i) + abs(3 - j);
}
}
cout << ans;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int oneMatch(int a, int b, int c, int d) {
if (a == c && b != d) return a;
if (b == d && a != c) return b;
if (a == d && b != c) return a;
if (b == c && a != d) return b;
return -1;
}
int n, m, ans = 0, a1[20], a2[20], b1[20], b2[20];
int main() {
scanf("%d%d", ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int MAXN = (int)200 + 7;
int n, m;
int second[MAXN][MAXN];
char a[MAXN][MAXN];
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> a[i][j];
}
}
int ans = 0;
for (int i =... | 11 |
#include <bits/stdc++.h>
using namespace std;
void answer() {
long long n, m, ans = 0, x1, x2, y1, y2, ans1;
cin >> n >> x1 >> x2 >> y1 >> y2;
std::vector<pair<long long, long long>> v;
for (int i = 0; i <= n; i++) v.push_back({i, 0});
for (int i = 1; i <= n; i++) v.push_back({n, i});
for (int i = 1; i <= n... | 5 |
#include <bits/stdc++.h>
using namespace std;
int read() {
int k = 0, f = 1;
char c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-') f = -1;
for (; isdigit(c); c = getchar()) k = k * 10 + c - '0';
return k * f;
}
int n, m;
pair<int, int> a[15], b[15];
int vis1[15][15], vis2[15][15];
int ans1[... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
const int inf = 1e8;
int dp[N], n, k, a[N];
bool isok(int x) {
dp[1] = 0;
for (int i = 2; i <= n; i++) {
dp[i] = i - 1;
for (int j = i - 1; j >= 1; j--) {
if (abs(a[j] - a[i]) <= 1ll * x * (i - j)) {
dp[i] = min(dp[i], dp[j] + i... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int m, n;
cin >> m;
vector<long long> A(m);
for (int i = 0; i < m; ++i) {
cin >> A[i];
}
cin >> n;
vector<long long> B(n);
for (int j = 0; j < n; ++j) {
cin >> B... | 8 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int s = 0, w = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') w = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
return s * w;
}
const long long p = 1000000007;
long ... | 19 |
#include <bits/stdc++.h>
using namespace std;
const long long int maxn = 5e3 + 5, mod = 998244353;
long long int n, x, f[maxn], dp[maxn][maxn], inv[maxn];
long long int binpow(long long int base, long long int exp) {
base %= mod;
long long int answer = 1;
while (exp) {
if (exp & 1) {
answer *= base;
... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
if (n != 1)
cout << 6 * n << " " << 5 * n;
else
cout << "25"
<< " "
<< "24";
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double a, b;
cin >> a >> b;
printf("%.13f\n", ((b * b) - (a * a)) / (2 * a));
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> all;
vector<int> ori;
for (int i = 0; i < n; i++) {
int t;
cin >> t;
all.push_back(t);
ori.push_back(t);
}
sort(all.begin(), all.end());
vector<stack<int>>... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k;
scanf("%lld%lld", &n, &k);
long long ans = 0;
n--;
for (int i = 0; i < k && n > 0; i++) {
ans += 2 * n - 1;
n -= 2;
}
printf("%lld\n", ans);
return 0;
}
| 4 |
#include <bits/stdc++.h>
const long long SZ = 401010;
const long long INF = 1e18;
const long long MOD = 1000000007;
const long long mod = 998244353;
long long opnmbr = 1;
using namespace std;
void solve() {}
long long answr = 0;
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 50;
const int INF = 1234567;
int c[MAXN][MAXN], f[MAXN][MAXN], k2[MAXN][MAXN], d[MAXN], len[MAXN];
int n, k;
bool used[MAXN];
int SPFA(int s, int t, int &ret) {
queue<int> que;
fill(d, d + n, INF);
fill(len, len + n, INF);
fill(used, used + n, 0);
... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5010;
const long long MOD = 4294967296;
const int MX = 100000000;
bitset<MX + 1> mrk;
int n, A, B, C, D;
long long ev(long long first) {
long long tr = (first * first) % MOD;
return (A * (tr * first) % MOD + B * tr + C * first + D) % MOD;
}
long long ct(lo... | 17 |
#include <bits/stdc++.h>
int main() {
long int n, m, add, s, f, t, s1, s2, choice;
scanf("%ld %ld", &n, &m);
add = (m - 1) << 1;
while (n--) {
scanf("%ld%ld%ld", &s, &f, &t);
if (f == s) {
printf("%d\n", t);
continue;
}
s1 = s - 1;
s2 = 2 * m - 1 - s;
while (1) {
if (s1... | 5 |
#include <bits/stdc++.h>
using namespace std;
int abc;
mt19937 rnd(time(0));
int rd(int l, int r) {
uniform_int_distribution<> ee(l, r);
return ee(rnd);
}
const int mxn = 2e5 + 3, sq = 500;
int n, a[mxn], b[mxn], m, ee[sq][sq], ti[mxn], s[mxn];
void add(int x, int l, int t) {
if (x > m) return;
x = max(x, l);
... | 14 |
#include <bits/stdc++.h>
using namespace std;
const long long MM = 1e9 + 7;
const int N = 160;
int n, m;
long long F[4][N][N], S[4][N][N];
long long mod(long long x) { return (x + MM) % MM; }
void add(long long &a, long long b) { a = mod(a + b); }
void prepare_pref(long long f[N][N], long long s[N][N]) {
for (int i =... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, i;
cin >> n;
int a[n], b[n], c[n];
vector<pair<int, int> > v;
for (i = 0; i < n; i++) {
cin >> a[i];
b[i] = (~a[i]);
c[i] = b[i];
}
for (i = 1; i < n; i++) {
b[i] = b[i] &... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 23;
const int MOD = 1e9 + 7;
string s;
string t;
char ch;
int x, ans, res = INF, n;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> s;
n = s.size();
char ch;
for (int i = 0; i < 26; i++) {
ch = 'a' + i;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
string s[12] = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "B", "H"};
map<string, int> m;
void init() {
for (int i = 0; i < 12; ++i) {
m[s[i]] = i;
}
}
bool cal(string a, string b, string c) {
int x = (m[b] - m[a] + 12) % 12;
int y = (m[c] - m[b] + 12... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T load() {
T r;
cin >> r;
return r;
}
template <typename T>
vector<T> loadMany(int n) {
vector<T> rs(n);
generate(rs.begin(), rs.end(), &load<T>);
return rs;
}
struct StrInt {
StrInt(const string& ref) : ref(ref) {}
int operator[](int i... | 15 |
#include <bits/stdc++.h>
using namespace std;
int a[1000000];
bool vis[1000000];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, k;
cin >> n >> k;
set<int> s;
for (int i = 0; i < n; i++) cin >> a[i], s.insert(a[i]);
sort(a, a + n);
int ret = n;
for (int i = 0; i < n; i++) ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
long long a = n / 10;
long long r = n % 10;
if (r <= 5)
cout << a * 10 << endl;
else
cout << (a + 1) * 10 << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
const int maxn = 200010;
int n, m, k, L, R, t, countn = 0;
char s[200050];
char op[15], cc;
int rson[maxn << 2], rt[maxn << 2], lson[maxn << 2];
int tot[maxn << 2];
char b[256];
void pushup(int root) {
int ls = root << 1;
int rs = root << 1 | 1;
rson[root] = rson[rs];
lson[root] = lson[... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long infLL = 0x3f3f3f3f3f3f3f3fLL;
const int maxn = 100000 + 5;
int psz;
struct Edge {
int v, w;
Edge *next;
} pool[maxn * 2], *e[maxn];
void add_edge(int u, int v, int w) {
Edge *i = pool + psz++;
i->v = v, i->w = w, i->next =... | 16 |
#include <bits/stdc++.h>
using namespace std;
namespace IO {
void setIn(string s) { freopen(s.c_str(), "r", stdin); }
void setOut(string s) { freopen(s.c_str(), "w", stdout); }
void setIO(string s = "") {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin.exceptions(cin.failbit);
if (s.size()) {
... | 15 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int T;cin>>T;
while(T--){
int d,k;cin>>d>>k;
int a=d/sqrt(2);
a=a/k*k;
if(1ll*a*a+1ll*(a+k)*(a+k)<=1ll*d*d) cout<<"Ashish\n";
else cout<<"Utkarsh\n";
}
return 0;
} | 9 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
vector<int> p[maxn];
int ans, f;
void dfs(int start, int finish, int s) {
if (s > ans) {
ans = s;
f = start;
}
int i;
for (i = 0; i < (int)p[start].size(); i++) {
int to = p[start][i];
if (to != finish) {
dfs(to, start... | 7 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <class T>
inline bool Min(T &a, T b) {
return a > b ? (a = b, true) : false;
}
template <class T>
inline bool Max(T &a, T b) {
return a < b ? (a = b, tru... | 11 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
template <typename T, typename E>
struct SegmentTree {
using F = function<T(T, T)>;
using G = function<T(T, E, long long)>;
using H = function<E(E, E)>;
long long n;
vector<T> dat;
vector<E> laz;
F f;
G g;
H h;
T ti;
E ei;
Se... | 14 |
#include <bits/stdc++.h>
int list[35];
int min(int a, int b) {
if (a < b)
return a;
else
return b;
}
int main() {
int t, n, i, k;
list[0] = 1;
for (i = 1; i <= 30; i++) list[i] = list[i - 1] * 2 + 1;
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
for (i = 1; i <= 30; i++)
if (list[i... | 11 |
#include <bits/stdc++.h>
using namespace std;
class DSU {
private:
long long n;
long long *id;
long long *w;
long long *mm;
long long *arr;
public:
DSU(long long n, long long arr[]) {
this->n = n;
id = new long long[n + 1];
w = new long long[n + 1];
mm = new long long[n + 1];
this->ar... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct Edge {
int a, b;
int l, h;
int cost;
bool operator<(Edge o) const {
if (a != o.a) {
return a < o.a;
}
if (b != o.b) {
return b < o.b;
}
return 0;
}
};
Edge edge[20];
int numEdge;
int n;
int minFlow;
int maxCost;
int flowVerte... | 14 |
#include <bits/stdc++.h>
using namespace std;
inline int Getint() {
int Ret = 0;
char Ch = ' ';
bool Flag = 0;
while (!(Ch >= '0' && Ch <= '9')) {
if (Ch == '-') Flag ^= 1;
Ch = getchar();
}
while (Ch >= '0' && Ch <= '9') {
Ret = Ret * 10 + Ch - '0';
Ch = getchar();
}
return Flag ? -Ret ... | 15 |
#include <bits/stdc++.h>
using namespace std;
void fastio() {
ios_base::sync_with_stdio(0);
cin.tie(0);
}
int main() {
fastio();
long long int n;
cin >> n;
long long int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
long long int x, f;
cin >> x >> f;
long long int ans = 0;
for (int i = ... | 6 |
#include <bits/stdc++.h>
using namespace std;
void solve();
int main() {
ios::sync_with_stdio(0);
solve();
return 0;
}
int R;
vector<pair<int, int> > head, tail;
int H[300][300];
int Dp(pair<int, int> u) {
if (u.first + u.second > R) return 0;
if (H[u.first][u.second] != -1) return H[u.first][u.second];
int... | 13 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
int used[1010];
int ans[1010][1010];
int h[1010];
int n;
int cur;
void solve() {
int ma = 0;
for (int i = (int)(0); i < (int)(n); ++i) {
if (!used[i]) ma = max(h[i],... | 18 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-10;
struct point {
double x, y;
} C, A, ans;
int dcmp(double u) {
if (fabs(u) <= eps)
return 0;
else
return u > eps ? 1 : -1;
}
double R;
double dis(point a, point b) {
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));... | 8 |
#include <bits/stdc++.h>
using namespace std;
const unsigned long long p = 1000000007;
const unsigned int D = 29;
unsigned long long sum[50010][30];
unsigned int a[50010], l[50010], r[50010], key[50010];
unsigned int l0[50010], r0[50010], key0[50010], x[50010];
unsigned int n, m, tot, tot0;
int find(int l, int r, int x... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int MN = 1e5 + 100;
vector<int> v1[MN];
vector<int> v2[MN];
vector<int> group;
bool used1[MN];
bool used2[MN];
bool used3[MN];
void findGroup(int x) {
used1[x] = 1;
group.push_back(x);
for (auto y : v1[x]) {
if (!used1[y]) {
findGroup(y);
}
}
}
i... | 14 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const long double eps = 1e-6;
int32_t main() {
cout << fixed << setprecision(15);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n;
cin >> n;
long double l = -inf, r = inf;
long double fueled = 0;
long double l... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 300000 + 5;
const int INF = 0x3f3f3f3f;
int n, c[N];
int colormax[N], colormin[N], colormax1[N], colormax2[N];
int main() {
scanf("%d", &n);
memset(colormin, 0x3f, sizeof(colormin));
for (register int i = 1; i <= n; i++)
scanf("%d", &c[i]), colormax[... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long g(int n) {
bool first = 1;
long long res = 0;
long long mul = 1;
while (n) {
int v = min(first ? 8 : 9, n);
res += mul * v;
n -= v;
first = 0;
mul *= 10;
}
return res;
}
const int M = 18;
const long long inf = 1e18;
long long solve(... | 14 |
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void ... | 20 |
#include <bits/stdc++.h>
using namespace std;
long long const MOD = 1e9 + 7;
int n;
map<pair<string, int>, vector<pair<string, int>>> g;
set<pair<string, int>> answer;
map<string, int> used;
queue<pair<string, int>> q;
pair<string, int> start;
void go() {
vector<pair<string, int>> tmp;
while (!q.empty()) {
tmp.... | 11 |
#include <bits/stdc++.h>
using namespace std;
void solution() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; ++i) cin >> a[i];
sort(a.begin(), a.end());
for (int i = 1; i < n; ++i) {
if (a[i] == a[i - 1]) {
cout << "YES\n";
return;
}
}
cout << "NO\n";
}
int main() {
io... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, q, m;
string s;
char c;
cin >> n >> s;
int k[26][1501] = {}, dp[26][1501] = {};
for (int i = 0; i < 26; i++)
for (int j = 0; j < n; j++)
k[i][j] = (s[j] - 'a' == i ? 0 : 1) + (j == 0 ? 0 : k[i][j - 1]);
for (int i = 0; i < 26; i++... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int Max = 1e6 + 10;
long long mn[Max * 4], mx[Max * 4], sum[Max * 4], sz[Max * 4], lazy[Max * 4];
vector<pair<long long, pair<long long, long long> > > A;
long long Y[Max], Z[Max];
void build(long long tl = 1, long long tr = Max, long long idx = 1) {
lazy[idx] = -1;... | 20 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 2e5 + 42;
long long need[N];
int a[N], ans[N];
long long n, m;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> a[i];... | 15 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-ffloat-store")
#pragma GCC optimize("-fno-defer-pop")
long long int power(long long int a, long long int b, long long int m) {
if (b == 0) return 1;
if (b == 1) return a % m;
lon... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char s[5][5];
int i, j;
for (i = 0; i < 4; i++) {
scanf("%s", s[i]);
}
int f = 0;
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
int sum = 0;
if (s[i][j] == '#') sum++;
if (s[i + 1][j] == '#') sum++;
if (s[i][j +... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e3 + 5, mod = 1e9 + 7;
long long int dp[2 * N][2 * N];
long long int n;
long long int solve(long long int i, long long int c) {
if (c < 0) return 0;
if (i == 2 * n) {
if (c == 0)
return 1;
else
return 0;
}
if (dp[i][c] ==... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
string s;
cin >> s;
int contA = 0, contI = 0, contF = 0;
for (int i = 0; i < N; i++) {
if (s[i] == 'A') contA++;
if (s[i] == 'I') contI++;
if (s[i] == 'F') contF++;
}
if (contI <= 1) {
if (contI == 1)
cout ... | 2 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.