solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 10;
int n, a, b;
bool vis[N];
void solve() { return; }
int main() {
int _;
cin >> _;
while (_--) {
cin >> a >> b;
n = a + b;
for (int i = 0; i <= n; i++) vis[i] = false;
int A = n / 2, B = n - A, Min;
if (a <= B)
Min = 0;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int n;
cin >> n;
cout << 2 - n*n;
} | 14 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 2e18;
const long long N = 2e5 + 1;
const long long mod = 1e8 + 0;
const long double eps = 1E-7;
int a[N];
int t[4 * N];
int lz[4 * N];
int n, p, x, y;
void push(int v) {
if (lz[v] == 0) {
return;
} else {
t[v * 2] += lz[v];
t[v * 2 + 1]... | 14 |
#include <bits/stdc++.h>
using namespace std;
int p[1000001], a[1000001], b[1000001], ans[1000001], vis[1000001], cnt;
vector<int> ve[1000001];
void dfs(int n);
void solve();
bool cmp(int a, int b);
int main() {
int n, m, num1, num2;
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%d", &p[i]);
for (i... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b, c, d;
scanf("%d", &n);
for (int i = 1; i <= 4; i++) {
scanf("%d %d %d %d", &a, &b, &c, &d);
if (min(a, b) + min(c, d) <= n) {
printf("%d %d %d\n", i, min(a, b), n - min(a, b));
return 0;
}
}
printf("-1\n");
retur... | 3 |
#include <bits/stdc++.h>
using namespace std;
vector<int> ans;
int get(int n) {
int sum = 0, cur = n;
while (cur != 0) {
sum += cur % 10;
cur /= 10;
}
return sum;
}
bool check(int n) {
int sum = 0, cur = n;
for (int i = 2; i * i <= cur; i++)
if (cur % i == 0) {
int cursum = get(i);
w... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 50000 + 5, inf = 0x3f3f3f3f;
struct edge {
int to, nxt, val, cost;
} e[N << 5];
int head[N], cnt = 1, maxflow, vis[N], dis[N];
long long mincost;
int s, t;
void add_edge(int x, int y, int z, int cost) {
e[++cnt].to = y;
e[cnt].val = z;
e[cnt].cost = co... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
int trie[N][26], k, win[N], lose[N], n, m;
void insert(string key) {
int u = 0;
for (int i = 0; i <= key.length() - 1; i++) {
int id = key[i] - 'a';
if (!trie[u][id]) trie[u][id] = ++k;
u = trie[u][id];
}
}
void run(int t) {
win[t]... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
struct node {
int w, c, num;
node(int _w, int _c) : w(_w), c(_c) {}
node(int _w, int _c, int _num) : w(_w), c(_c), num(_num) {}
node() {}
long long cnt() const { return 1LL * (w - w / 2) * num; }
bool operator<(const node &b) const {
... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n, q, M, bl[N], vis[N], cc[N];
struct Que {
int op, x;
} B[N];
struct TO {
int to, d, t;
};
vector<TO> V[N];
vector<int> E[N];
void build(int x, int lst, int dep, int wh) {
if (vis[x] && x > 1) V[lst].push_back((TO){x, dep, wh});
for (aut... | 24 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> res;
int arr[n + 2];
for (int i = 1; i <= n; i++) {
cin >> arr[i];
}
if (arr[n] == 0) {
for (int i = 1; i <= n + 1; i++) {
cout << i << " ";
... | 4 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n;
cin >> n;
long long a[n];
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
long long ans = a[0];
for (int i = 1; i < n; i++) {
ans = max(ans, a[i] - a[i - 1]);
}
cout << ans << endl;
}
int main() {
long long t;
c... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t;
cin >> t;
while (t--) {
int a, b, c, d;
cin >> a >> b >> c >> d;
int odd = 0, sum = a + b + c + d;
if (a % 2) odd++;
if (b % 2) odd++;
if (c % 2) odd++;
if (d % 2... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = (1e5);
long long a[N];
string L = "L";
string R = "R";
string solve(int a[], int c, int l, int r) {
string s = "";
if (c >= a[r] && c >= a[l]) return s;
if (l > r) return s;
if (c < a[l] && c < a[r]) {
if (a[l] < a[r]) {
return L + solve(a, a... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long solve() {
long long n;
cin >> n;
long long a = 2, b = 3, ans = 2;
for (; b <= n; ans++) {
b += a;
a = b - a;
}
return ans - 1;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
while (t-... | 8 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long int n;
cin >> n;
string s, s1;
cin >> s >> s1;
deque<char> q, q1;
for (auto it : s) {
q.push_back(it);
}
for (auto it : s1) {
q1.push_back(it);
}
vector<long long int> ans;
int check = 0;
long long int curr = n;
whi... | 5 |
#include <bits/stdc++.h>
using namespace std;
char ss[200000];
int sit[200000];
int main() {
int n, a, b, k;
scanf("%d%d%d%d", &n, &a, &b, &k);
scanf("%s", ss + 1);
int t = 0;
int num = 0;
int cnt = 0;
for (int i = 1; i <= n; i++) {
if (ss[i] == '1') {
t = 0;
} else
t++;
if (t % b ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3F3F3F3F;
template <class T>
inline T& checkmin(T& a, T b) {
if (b < a) a = b;
}
template <class T>
inline T& checkmax(T& a, T b) {
if (b > a) a = b;
}
int main() {
int n;
double p, f, g, h;
scanf("%d", &n);
f = 0;
g = 1;
h = 0;
for (int ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int SIZE = 1e5 + 5;
int a[SIZE];
struct T {
int id;
int p;
} ne[SIZE];
;
bool cmp(const T &a, const T &b) { return a.p < b.p; }
int main(int argc, char const *argv[]) {
int n, k, sum;
while (~scanf("%d %d", &n, &k)) {
for (int i = 0; i < n; ++i) {
sc... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n;
struct Point {
int len, id;
} p[2 * N];
bool cmp(Point x, Point y) { return x.len > y.len; }
vector<pair<int, int>> res;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, t, a[100], b[1000];
for (cin >> t; t--;) {
cin >> n;
long long ans = 0;
long long m = LONG_LONG_MAX, mn = LONG_LONG_MAX;
for (int i = 1; i <= n; i++) {
cin >> a[i];
m = min(a[i], m);
}
for (int i = 1; i <= n;... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int N = 2100;
int a[N];
int dp1[N][N][2][2];
int dp2[N][N][2][2];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", a + i);
a[i]--;
}
for (int i = 1; i <= n; i++)
for (int j = i; j <= n; j... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, i, x, k, j;
cin >> n;
cin >> m;
long long niz[n + 1], rj1[m], rj2[m];
niz[0] = 0;
for (i = 1; i <= n; i++) {
cin >> x;
niz[i] = niz[i - 1] + x;
}
for (i = 0; i < m; i++) {
cin >> x;
k = 0;
for (j = n / 2; j >=... | 2 |
#include <bits/stdc++.h>
using namespace std;
vector<int> pf(string s) {
vector<int> p(s.size());
for (int i = 1; i < (int)s.size(); i++) {
int k = p[i - 1];
while (k > 0 && s[i] != s[k]) {
k = p[k - 1];
}
if (s[i] == s[k]) {
k++;
}
p[i] = k;
}
return p;
}
signed main() {
i... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
long long n, ans = 0;
cin >> n;
long long a[n];
for (long long i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
for (long long j = n - 1; j >= 0; j--) {
if (a[j] <= j + 1) {
ans = j... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, k;
long long p, s, r, c, u, v;
long long ans = -1e18;
long long rr[1000001];
long long rc[1000001];
long long a[1001][1001];
priority_queue<long long> qr, qc;
int main(void) {
scanf("%I64d%I64d%I64d%I64d", &n, &m, &k, &p);
for (long long i = (1); i <= (n... | 12 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
string toStr(const T &x) {
stringstream s;
s << x;
return s.str();
}
template <class T>
int toInt(const T &x) {
stringstream s;
s << x;
int r;
s >> r;
return r;
}
int items[100001];
int counti[100001];
int main() {
int t;
cin >> t;
v... | 4 |
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long double eps = 1e-7;
const int inf = 1000000010;
const long long INF = 10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 3000010, LOG = 20;
int n, m, k, u, v, x, y, t, a, b;
int L[MAXN]... | 20 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
const int inf = 0x3f3f3f3f;
const int maxn = 2e3 + 10;
const int mod = 1e9 + 7;
const double eps = 1e-6;
int di[8][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1},
{-1, -1}, {-1, 1}, {1, -1}, {1, 1}};
clock_t _st = clock(... | 13 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:65777216")
using namespace std;
const long double EPS = 1e-11;
const int INF = 2000000000;
const long long lINF = 9223372036854775807;
const long double PI = 3.14159265358979323846;
int main() {
long long y1, y2, yw, xb, yb, r, A, B, C;
long double ans, yp, S... | 12 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n;
cin >> n;
vector<long long> odd, even;
long long a[n];
for (long long i = 0; i < n; i++) {
cin >> a[i];
if (a[i] % 2)
odd.push_back(a[i]);
else
even.push_back(a[i]);
}
sort(odd.begin(), odd.end());
sort(eve... | 6 |
#include <bits/stdc++.h>
using namespace std;
function<void(void)> ____ = []() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
};
const int MAXN = 1e5 + 7;
int n, a, b, root[MAXN];
vector<int> A;
int findx(int x) { return x == root[x] ? x : root[x] = findx(root[x]); }
int sta[MAXN], bel[MAXN];
int ma... | 12 |
#include <bits/stdc++.h>
using namespace std;
int d4x[4] = {1, 0, -1, 0};
int d4y[4] = {0, 1, 0, -1};
int d8x[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int d8y[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const int oo = 1e8;
const int maxN = 250;
int visited[maxN], pre[maxN], a[maxN];
int c[maxN][maxN], f[maxN][maxN];
pair<int, int> Even... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, k, id, num1, num2, mn = 0, mx = 0, i;
string s;
cin >> x >> k;
vector<int> v;
v.assign(x, 0);
for (i = 0; i < k; i++) {
cin >> id;
if (id == 1) {
cin >> num2 >> num1;
v[num1] = 1;
v[num2] = 1;
} else {
cin ... | 4 |
#include <bits/stdc++.h>
using namespace std;
long double asd;
long long i, l, r, o, t, c, p, w, k, m, h, n, f1, f2, f3, j, a, b, x33, y11,
y22, ans, ans1, ans2, mn, mx, sum, x, y, kol;
int main() {
cin.tie(0);
cout.tie(0);
cin >> t;
while (t--) {
cin >> n;
for (i = 0; i < n; i++) {
cin >> a;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
const int M = 1e6 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
int a[N], ans[N];
void solve() {
int n, m, d;
cin >> n >> m >> d;
for (long long i = 1; i < m + 1; i++) cin >> a[i];
int sum = 0;
for (long long i = 1; i < m + 1; i++)... | 9 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
int t;
cin >> t;
while (t--) {
int n, s;
cin >> n >> s;
int a[n];
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
bool flag = true;
for (int i = 0; i < n; ++i) ... | 5 |
#include <bits/stdc++.h>
#define MOD 998244353
using namespace std;
int n, m, dp[1001][1001][4], ans;
string x, y;
int main()
{
cin >> x >> y;
x = '$'+x, y = '$'+y;
n = x.length(), m = y.length();
for(int i = 0; i<n; i++)
for(int j = 0; j<m; j++)
{
if(i>0)
{
... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
int x[maxn], y[maxn], t[maxn], ord[maxn];
double p[maxn], dp[maxn];
bool cmp(int i, int j) { return t[i] < t[j]; }
inline long long dist(long long x, long long y) { return (x * x + y * y); }
inline long long square(long long x) { return x * x; }
int m... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int c = 2002;
int n, m, bcs, bal[c], invbal[c], jcs, jobb[c], invjobb[c];
long long ert[c], distbal[c], distjobb[c], dp[c][c][2], sum, ans;
vector<int> sz[c], s[c], sor;
bool v[c];
priority_queue<pair<long long, int> > q;
void dijkstra(int kezd) {
q.push({0, kezd});... | 21 |
#include <bits/stdc++.h>
int n;
int main() {
scanf("%d", &n);
if (n == 3) {
printf("5\n");
return 0;
}
n -= (n & 1);
for (int i = 0; i <= n; ++i)
if ((i + 1) * i * 2 >= n) {
printf("%d\n", i + i + 1);
return 0;
}
return 0;
}
| 9 |
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 200010;
const double PI = acos(-1);
class Point {
public:
double x, y, r;
Point() {}
Point(double x, double y, double r = 0) : x(x), y(y), r(r) {}
Point operator-(const Point &a) const { return Point(x - a.x, y - a.y); }
} p[MaxN], o, ol;
int n, a;... | 24 |
#include <bits/stdc++.h>
using namespace std;
namespace input {
template <class T>
void scan(T& x) {
cin >> x;
}
template <class T>
void scan_iter(const T& begin, const T& end) {
for (T it = begin; it != end; it++) {
scan(*it);
}
}
template <class T, class... Ts>
void scan(T& t, Ts&... ts) {
scan(t);
scan... | 9 |
#include <bits/stdc++.h>
using namespace std;
bool used[1005][1005];
char G[1005][1005];
bool has[1005][1005];
const int DY[4] = {0, 1, 0, -1};
const int DX[4] = {1, 0, -1, 0};
vector<pair<int, int>> pos;
int n, m;
bool ok(int i, int j) { return !(i < 0 || j < 0 || i >= n || j >= m); }
bool hit;
void ff(int i, int j) {... | 17 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, k;
const long long MOD = 1000000007;
vector<int> p(500005, -1);
map<long long, vector<pair<int, int>>> edges;
int comp(int x) { return (p[x] == -1 ? x : p[x] = comp(p[x])); }
bool join(int i, int j) {
int a = comp(i), b = comp(j);
bool con = (a == b);
... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 50;
const int B = 350;
const int INF = 0x3f3f3f3f;
int n, A[N];
long long off_k[N], off_o[N];
deque<long long> D[N];
inline long long get(int i) {
if (i == -1 || (int)D[i / B].size() <= i % B) return -(long long)INF * INF;
return D[i / B][i % B] + of... | 24 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x) {
cin >> x;
}
template <typename T, typename T0>
void read(T &x, T0 &y) {
cin >> x >> y;
}
template <typename T, typename T0, typename T1>
void read(T &x, T0 &y, T1 &z) {
cin >> x >> y >> z;
}
bool isPowerOfTwo(int x) { return x &... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 100005;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long t;
cin >> t;
while (t--) {
long long i, j, k, n, m, ans = 0, cnt = 0, sum = 0;
cin >> n;
long long a[n];
for (i = 0; i < n; i+... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<int> a;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
a.push_back(x);
}
long long res = 0;
int cur = INT_MAX;
for (int i = n - 1; i >= 0; i--)... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
long long int t;
cin >> t;
while (t--) {
string s, t, st = "abc";
cin >> s >> t;
sort(s.begin(), s.end());
long long int a1 = 0, b1 = 0, c1 = 0;
for (int i = 0;... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2 * 1e5 + 5;
int a[N], dp[N];
vector<int> g[N];
int dfs1(int u, int p) {
int res = 0;
if (a[u] == 1) {
res += 1;
} else {
res -= 1;
}
for (int i : g[u]) {
if (i != p) {
res += max(0, dfs1(i, u));
}
}
return dp[u] = res;
}
vo... | 10 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
int N, A, B;
double d[2003], a[2003], b[2003], ab[2003];
pair<int, int> calc(double c1, double c2) {
int ans1 = 0, ans2 = 0, rem = 0;
for (int i = 1; i <= N; i++) {
double add1 = a[i] - c1, add2 = b[i] - c2;
double add3 = ab[i] - c1 - c2... | 22 |
#include <bits/stdc++.h>
long l[4][2] = {{1, 0}, {-1, 0}, {0, -1}, {0, 1}}, d[700001] = {0},
du[700001] = {0}, num[1005][1005] = {0}, head[700001] = {0},
e[4000001] = {0}, next[4000001] = {0}, stack[700001] = {0},
dfn[700001] = {0}, low[700001] = {0}, c[700001] = {0}, opp[700001] = {0},
e2[4000001] ... | 12 |
#include <bits/stdc++.h>
using namespace std;
void result(int u, int d, int z) {
if (z == 0) {
if (u == d)
printf("0");
else if (u > d)
printf("+");
else
printf("-");
} else {
if (u + z < d)
printf("-");
else if (d + z < u)
printf("+");
else
printf("?");
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const int mod = 1e9 + 7;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
vector<int> G[5005];
int V[5005];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < m; i++) {
int x, y;
scanf("%d%d", &x, &y);
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
const int N = 1e2 + 10;
int flag[N][N];
char board[N][N];
int main() {
int n, m;
cin >> n >> m;
memset((flag), (0), sizeof(flag));
for (int i = 0; i < n; i++) cin >> board[i];
for (int i = 0; i < n; i++) {
map<char, int> mc;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int OO = (int)2e9;
const double eps = 1e-9;
int daysInMonths[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int di[] = {-1, 0, 1, 0};
int dj[] = {0, 1, 0, -1};
struct Round {
int x;
string name;
};
int main() {
std::ios_base::sync_with_stdio(false);
... | 7 |
#include <bits/stdc++.h>
using namespace std;
struct ptr_less {
bool operator()(const int &n1, const int &n2) { return n1 % 10 < n2 % 10; }
};
int N, K;
int rating, val, add;
int skills[100000];
priority_queue<int, vector<int>, ptr_less> que;
int main() {
scanf("%d%d", &N, &K);
for (int i = 0; i < N; i++) {
s... | 6 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long x = 0;
bool f = false;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') f = true;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = (x << 3) + (x << 1) + (c ^ '0');
c = getchar();
}
return f... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, d[(3222)][(3222)], x, y, l, x2, y2, l2;
vector<long long> e[(3222)];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
for (int i = 0; i < (3222); i++)
for (int j = 0; j < (3222); j++) d[i][j] = ((long long)1e9);
cin >> n >> m;
for (int i ... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int rest_k;
char maze[500][500];
int visited[500][500];
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
bool safe(int x, int y) { return (0 <= x && x < n && 0 <= y && y < m); }
void dfs(int x, int y) {
if (rest_k == 0) return;
if (!safe(x, y)) return;... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, m;
cin >> n >> m;
char ar[n + 5][m + 5];
long long int counter = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> ar[i][j];
if (ar[i][j] == '*') counter++;
}
}
long long int horizontal[n ... | 6 |
#include <bits/stdc++.h>
const int BUFFER_SIZE = 1 << 26 | 1;
struct InputOutputStream {
char ibuf[BUFFER_SIZE], *s;
InputOutputStream() : s(ibuf) {
ibuf[fread(ibuf, 1, BUFFER_SIZE, stdin)] = '\0';
}
template <typename T>
inline InputOutputStream &operator>>(T &x) {
while (!isdigit(*s)) ++s;
for (... | 20 |
#include <bits/stdc++.h>
using std::max;
using std::min;
const int inf = 0x3f3f3f3f, Inf = 0x7fffffff;
const long long INF = 0x3f3f3f3f3f3f3f3f;
std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count());
template <typename _Tp>
_Tp gcd(const _Tp &a, const _Tp &b) {
return (!b) ? a : gcd(b, a % b);... | 22 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long md = 1234567891;
const long long bil = 1000000000;
const char aa = 'a';
const double eps = 1E-9;
const int mil = 1000000;
const int ths = 1000;
const int maxn = 1001;
const int dr[] = {0, -1, 0, 1};
const int dc[] = {1, 0, -... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double y1, y2, yw, x, y, r;
while (~scanf("%lf%lf%lf%lf%lf%lf", &y1, &y2, &yw, &x, &y, &r)) {
double xw = x * (yw - r - r - y1) / (yw + yw - r - r - r - y1 - y);
if (xw <= 0 || xw >= x) {
printf("-1\n");
continue;
}
double k = (y... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, k;
string str = "", buff;
cin >> n;
while (n--) {
cin >> buff;
if (buff[0] == 'p')
cout << str + '/' << endl;
else {
cin >> buff;
if (buff[0] == '/')
str = buff;
else
str += '/' + buff;
}... | 6 |
#include <bits/stdc++.h>
int larger(int m, int n) {
if (m > n)
return m;
else
return n;
}
int main() {
int a, b, c, c1, c2, c3, c4, c5, s1, s2, s3, s4;
scanf("%d%d%d", &a, &b, &c);
c1 = a + (b * c);
c2 = a * (b + c);
c3 = a * b * c;
c4 = (a + b) * c;
c5 = a + b + c;
s1 = larger(c1, c2);
s2... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
int odd = 0, even = 0;
cin >> odd;
while (odd--) {
cin >> n >> m;
int largest = 0;
int counter = 0;
while (n > 0 && m > 0) {
if (n == m) {
n = 0;
counter++;
} else {
if (n > m) {
co... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;
long long gcd(long long a, long long b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
long long power(long long x, long long y) {
long long res = 1;
while (y > 0) {
if (y ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int inp[3000005];
bool cmp(int x, int y) { return x > y; }
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%d", &inp[i]);
for (int i = 1, temp; i <= n; i++) {
temp = m;
sort(inp + 1, inp + 1 + i, cmp);
for (int j = 1; j ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 5e6;
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
long long n;
cin >> n;
long long x[n], y[n];
for (long long i = 0; i < n; i++) cin >> x[i] >> y[i];
long long maax = 0;
long long maxx = *max_element(x, x + n),... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
vector<int> A, B;
char s[N];
int n;
void read_input() {
cin >> s;
n = strlen(s);
}
void solve() {
for (int i = 0, p = n - 1; i < n; i++)
if (s[i] ^ ')') {
while (p && s[p] ^ ')') p--;
if (i >= p) break;
A.push_back(i), B.pu... | 4 |
#include <bits/stdc++.h>
using namespace std;
vector<int> edge[100001];
int cnt[100001];
int par[100001];
int sz[100001];
int find(int x) {
if (par[x]) return par[x] = find(par[x]);
return x;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> cp;
for (int i = 1... | 11 |
#include <bits/stdc++.h>
using namespace std;
bool isprime(int i) {
if ((i % 2 == 0 && i != 2) || i == 1) return 0;
for (int j = 3; j * j <= i; j += 2)
if (i % j == 0) return 0;
return 1;
}
int main() {
vector<int> v;
int n, d;
cin >> n;
for (int i = 2; i <= n; i++) {
if (isprime(i)) {
d = i... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, k, n, w, h;
long long res = 0;
cin >> w >> h;
for (i = 1; i * 2 <= w; i++)
for (j = 1; j * 2 <= h; j++) res += (h - 2 * j + 1) * (w - 2 * i + 1);
cout << res << endl;
return 0;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
long long c[100010], old[100010];
int main() {
long long k1, k2, k3, t1, t2, t3;
int n;
scanf("%I64d%I64d%I64d", &k1, &k2, &k3);
scanf("%I64d%I64d%I64d", &t1, &t2, &t3);
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%I64d", &c[i]);
old[i] = c[i];... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long a[110000];
long long s(long long m) { return m * (m + 1) / 2; }
int main() {
int n, k;
cin >> n >> k;
for (int i = 1; i <= k; i++) {
long long ans =
max((int)(a[i - 1] + 1),
(int)ceil((double)n / (double)(pow(2.0, k + 1 - i) - 1)));
... | 11 |
#include <bits/stdc++.h>
using namespace std;
char s[1000006];
int pre[1000006];
int vis[1000005];
void prefix(int l) {
pre[0] = -1;
for (int i = 1, j = -1; i <= l; i++) {
while (j != -1 && s[j] != s[i - 1]) j = pre[j];
pre[i] = ++j;
}
}
int main() {
memset(vis, 0, sizeof(vis));
cin >> s;
int l = st... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXN = 1005;
string a;
map<char, int> mp;
int fa[MAXN];
struct node {
int cnt;
int ve[MAXN];
} cnt[MAXN];
int find(int x) { return fa[x] == x ? fa[x] : fa[x] = find(fa[x]); }
void merge(int x, int y) {
int fx = find(x), fy = find(... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
if (m == 3 && n >= 5)
cout << -1 << endl;
else {
if (m == 3 && n == 4)
puts("-1 0\n1 0\n0 2\n0 1");
else {
for (int i = 1; i <= m; i++) cout << i << " " << i * i + 343231 << endl;
n -= m;
for ... | 15 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const int INF = 0x3fffffff;
int main() {
int N, ans = 0;... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long int max(long long int a, long long int b) {
if (a > b) return a;
return b;
}
long long int min(long long int a, long long int b) {
if (a < b) return a;
return b;
}
long long int power(long long int x, long long int y,
long long int m = ... | 0 |
#include <bits/stdc++.h>
using namespace std;
map<char, int> mp;
int main() {
int i, j, k, n, m;
cin >> n;
char str[2 * n];
for (i = 1; i <= 2 * n - 2; i++) {
cin >> str[i];
}
int cnt = 0;
for (i = 1; i <= 2 * n - 2; i++) {
if (i % 2 == 1) {
mp[str[i] - 'a']++;
}
if (i % 2 == 0) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 10;
int a[N];
bool cmp(int x, int y) { return x > y; }
int main() {
std:
ios::sync_with_stdio(false);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i];
sort(a + 1, a + 1 + n, cmp);
int a... | 0 |
#include <bits/stdc++.h>
using namespace std;
void Freopen() {
freopen(
"title"
".in",
"r", stdin);
freopen(
"title"
".out",
"w", stdout);
}
int read() {
int g = 0, f = 1;
char ch = getchar();
while (ch < '0' || '9' < ch) {
if (ch == '-') f = -1;
ch = getchar();
}... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 79;
class maxi_decrease {
public:
vector<int> v;
void insert(int val) {
if (val < 0) return;
if (v.size() <= val) v.resize(val + 1, 0);
v[val]++;
}
void decrease(int val) {
if (val < 0) return;
v[val]--;
if (val > 0) v... | 21 |
#include <bits/stdc++.h>
using namespace std;
int n, r, c, k, sum = 0;
bool flag[15][15];
int main() {
cin >> r >> c >> n >> k;
for (int i = 1; i <= n; i++) {
int x, y;
cin >> x >> y;
flag[x][y] = 1;
}
for (int i1 = 1; i1 <= r; i1++) {
for (int j1 = 1; j1 <= c; j1++)
for (int i2 = i1; i2 <... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k;
cin >> k;
string s = "";
k--;
for (int i = 1; true; i++) {
if (s.length() > k) {
cout << s[k];
return 0;
} else {
int copy = i;
string x = "";
while (i / 10) {
x = char(i % 10 + 48) + x;
i /... | 2 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n;
cin >> n;
vector<long long> a(n);
for (long long i = 0; i < n; i++) {
cin >> a[i];
}
long long ans = 0;
while (true) {
bool sorted = true;
for (long long i = 0; i < n - 1; i++) {
if (a[i] > a[i + 1]) {
sort... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
long long calc(vector<long long> &sum, vector<long long> &odd, vector<long long> &even, int L, int R){
long long P = 0, C = 0;
C += sum[L];
if (L % 2 == 0){
P += even[R] - even[L];
C += odd[R] - odd[L];
} else {
P += odd[... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, i, c, x1, o;
double a, d, x = 0, l, a1;
cin >> a >> d;
cin >> n;
cout << fixed << setprecision(4);
a1 = a * 4;
for (i = 0; i < n; i++) {
x += d;
x1 = int(x / a);
if (x1 % 4 == 0) cou... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n;
map<long long, pair<int, int> > m;
map<long long, pair<int, int> >::iterator it;
long long arr[300010], bit[300010];
void insert(long long x, int i) {
for (; i <= n; i += (i & -i)) {
bit[i] += x;
}
}
long long search(int i) {
long long suma = 0;
for (; i ... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long b, long long m) {
return b ? (b & 1 ? (a * power((a * a) % m, b >> 1, m)) % m
: power((a * a) % m, b >> 1, m))
: 1;
}
int main() {
int n;
cin >> n;
pair<int, int> pos1, pos2;
cin >> pos1.first >... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void setmax(T &a, T b) {
if (b > a) a = b;
}
template <class T>
inline void setmin(T &a, T b) {
if (b < a) a = b;
}
const int maxn = 2100;
const long double Pi = 3.14159265358979323846;
int a[maxn][maxn], a2[maxn][maxn], was[maxn][maxn], num, m... | 11 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int main() {
int sum = 0;
int l, r, x, y;
cin >> l >> r >> x >> y;
if (y % x) {
cout << 0 << endl;
return 0;
}
long long k = y / x;
for (int i = 1; i <= sqrt(k + 0.5); i++) {
if (k % i) contin... | 8 |
#include <bits/stdc++.h>
using namespace std;
vector<bool> f(150000000, 0);
int Rand() { return (rand() << 15) | rand(); }
int main() {
int a, b, i, j, temp, answer;
srand((unsigned)time(0));
scanf("%d%d", &a, &b);
f.clear();
temp = (int)(sqrt(b));
for (i = 3; i <= temp; i += 2)
if (!f[i >> 1]) {
... | 14 |
#include <bits/stdc++.h>
using namespace std;
struct node {
long long sm;
node *ch[26];
node() {
sm = 1;
for (int i = 0; i < 26; i++) ch[i] = NULL;
}
};
void merge(node *t1, node *t2) {
for (int i = 0; i < 26; i++) {
if (t1->ch[i] != NULL && t2->ch[i] != NULL)
merge(t1->ch[i], t2->ch[i]);
... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base ::sync_with_stdio(false);
string s, t;
cin >> s >> t;
vector<int> arr(t.length());
arr[0] = 0;
int next = 0;
int j = 1;
while (j < t.length()) {
if (t[j] == t[next]) {
next++;
arr[j] = next;
j++;
} else {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long n;
cin >> n;
long long a[n + 1];
for (long long i = 1; i <= n; ++i) {
cin >> a[i];
}
vector<pair<long long, long long>> v;
for (long long i ... | 17 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.