solution stringlengths 53 181k | difficulty int64 0 13 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long int a[3], ans = 0;
cin >> a[0] >> a[1] >> a[2];
sort(a, a + 3);
if (a[0] != a[1] && a[1] != a[2] && a[0] != a[2]) {
ans += abs(a[1] - a[2] + 1) + abs(a[1] - a[0] - 1) + abs(a[0] - a[2] + 2);
... | 0 |
#include <bits/stdc++.h>
const int INF = (int)1e9 + 1;
int main() {
int n;
std::cin >> n;
std::vector<int64_t> a(n);
for (auto& it : a) std::cin >> it;
std::vector<std::vector<bool>> g(n, std::vector<bool>(n, false));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (i == j) continue... | 3 |
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<stack>
#include<string>
#include<map>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<iomanip>
#include<cctype>
#include<deque>
#include<ctime>
#include<sstream>
#include<list>
... | 2 |
#include<bits/stdc++.h>
using namespace std;
struct dsu{
int n;
vector<int> p;
dsu(int _n): n(_n){
p.resize(n + 5);
iota(p.begin(), p.end(), 0);
}
inline int par(int u){
return p[u] = (u == p[u] ? u : par(p[u]));
}
bool unite(int u, int v){
u = par(u);
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-6;
const double PI = acos(-1.0);
bool is_prime(long long n) {
for (long long i = 2; i * i <= n; i++) {
if (n % i == 0) return 0;
}
return 1;
}
long long calc(long long... | 8 |
#include <bits/stdc++.h>
int sb(int a, int b) {
if (a % b == 0)
return b;
else
return sb(b, a % b);
}
int main() {
int n, i, max = 0, a[110];
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%d", &a[i]);
max = max > a[i] ? max : a[i];
}
int k = a[1];
for (i = 2; i <= n; i++) k = sb(k, ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 51;
long long n;
bool ans[N][N];
long long Q = 0;
long long get(long long x1, long long y1, long long x2, long long y2) {
++Q;
if (Q > n * n) {
cout << "Q\n";
exit(1);
}
cout << "? " << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << '\n';
... | 8 |
#include <bits/stdc++.h>
using namespace std;
constexpr double eps = 1e-13;
constexpr int M = 1e9 + 7;
constexpr int N = 5e5 + 100;
long long qpower(long long x, long long p) {
long long ans = 1;
while (p) {
if (p & 1) ans = ans * x % M;
x = x * x % M;
p >>= 1;
}
return ans;
}
vector<pair<int, int> ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(0.0) * 2.0;
const double eps = 1e-12;
const int step[8][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1},
{1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
template <class T>
inline T abs1(T a) {
return a < 0 ? -a : a;
}
template <class T>
inline ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 4;
int n, m, a, b, ay[N], by[N], l[N], linkY[N << 1];
void read() {
cin >> n >> m >> a >> b;
for (int i = 1; i <= n; ++i) {
cin >> ay[i];
}
for (int i = 1; i <= m; ++i) {
cin >> by[i];
}
for (int i = 1; i <= m; ++i) {
cin >> l[i];... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int *w = new int[n];
int *h = new int[n];
for (int i = 0; i < n; i++) {
cin >> w[i] >> h[i];
}
int max_first = 0;
int max_second = 0;
int max_number = 0;
long long int total_width = 0;
for (int i = 0; i < n; i++) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
string a;
string b = "QAQ";
int sum;
void dfs(int times, int pos) {
if (times == 3) {
sum++;
return;
}
for (int i = pos + 1; i < a.length(); i++) {
if (b[times] == a[i]) dfs(times + 1, i);
}
}
int main() {
cin >> a;
dfs(0, -1);
cout << sum << endl;... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long a[100009];
int main() {
long long i, j, n, sum;
cin >> n;
for (i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
for (sum = 0, i = 0, j = n - 1; i < n; j--, i++) {
sum += (a[i] * a[j]) % 10007;
}
cout << sum % 10007 << endl;
return 0;
}... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b, c;
cin >> a >> b >> c;
if (a == b)
cout << "YES" << endl;
else if (c == 0)
cout << "NO" << endl;
else if ((a > b && c < 0 && (b - a) % c == 0) ||
(a < b && c > 0 && (b - a) % c == 0))
cout << "YES" << endl;
els... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
vector<pair<int, int> > arr, A, B;
for (int i = 0; i < n; i++) {
int first;
scanf("%d", &first);
arr.push_back({first, i});
}
sort(arr.begin(), arr.end());
int left = (n + 2) / 3;
int right = n - left * 2;
f... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int dp[1055][1055];
int fact[100005];
int rev[100005];
int arr[100005];
int n, k;
int cnt;
int ans;
int sz;
void addMod(int &a, int b) {
a += b;
if (mod <= a) {
a -= mod;
}
}
int binPow(int a, int b) {
int ret = 1;
for (; b > 0; b >>= ... | 6 |
#include <bits/stdc++.h>
using namespace std;
vector<int> v;
map<long long, long long> mp;
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
v.push_back(a);
}
int pos = find(v.begin(), v.end(), m) - v.begin();
long long ans = 0;
int lft = 0, rgt = 0, len = 1;... | 5 |
#include <bits/stdc++.h>
using namespace std;
char a[1005][1005];
long long b[1005];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
scanf(" %c", &a[i][j]);
if (a[i][j] == '*') {
++b[j];
}
}
}
long long ans = 0;
fo... | 4 |
#include <bits/stdc++.h>
using namespace std;
char s[555][555];
bool ok(int x, int y) {
bool c[555];
c['f'] = c['a'] = c['c'] = c['e'] = 0;
for (int i = 0; i < 2; ++i)
for (int j = 0; j < 2; ++j) c[s[i + x][j + y]] = 1;
return c['f'] && c['a'] && c['c'] && c['e'];
}
int main(void) {
int n, m;
cin >> n >... | 0 |
#include <bits/stdc++.h>
long long ni() {
int c = getchar();
while (c < '0' || c > '9') c = getchar();
long long ret = 0;
while (c >= '0' && c <= '9') {
ret = ret * 10 + c - '0';
c = getchar();
}
return ret;
}
long long gcd(long long a, long long b) {
while (b > 0) {
long long t = a % b;
a... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 550000 + 7;
const long long MOD = 1e9 + 7;
char ss[50010];
int len;
struct Seg {
int ls[MAXN * 4], rs[MAXN * 4], sum[MAXN * 4], rt[550010 << 1], pos[MAXN * 4],
dfn = 0;
void init() {
for (int i = 1; i <= dfn; i++)
rt[i] = ls[i] = r... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long read() {
long long x = 0, f = 0;
char ch = getchar();
while (!isdigit(ch)) f |= ch == '-', ch = getchar();
while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
return f ? -x : x;
}
const int N = 1000005, mod = 1e9 + 7;
int n, m, a, b;... | 8 |
#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cout << *it << " = " << a << endl;
err(++it, args...);
}
const int mod = 1e9 + 7;
void solve() {
int n, m, x, y;
cin >> n >> m... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x;
cin >> x;
int a[x];
long long counter = 0, sum = 0;
for (int i = 0; i < x; i++) {
cin >> a[i];
sum += a[i];
}
counter = sum;
sort(a, a + x);
for (int i = 0; i < x - 1; i++) {
sum -= a[i];
counter += (sum);
counter +=... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, t;
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
if (n >= 2)
printf("%d\n", n - 2);
else
printf("0\n");
}
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
const int max_n = 5005, inf = 1011111111;
int n, p[max_n], b[max_n];
int pos[max_n];
vector<pair<vector<int>, pair<vector<int>, vector<int>>>> all;
vector<pair<vector<int>, pair<vector<int>, vector<int>>>> my_all;
void find_b() {
for (int i = 0; i < n; ++i) {
pos[p[i]... | 6 |
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
int const N = 1e5 + 10, inf = 1e18 + 10;
int n, v, x[N], t[N], dp1[N], dp2[N], mn1[N], mn2[N], ans1, ans2;
pii p[N];
int32_t main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x... | 7 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma comment(linker, "/STACK:2000000")
using namespace std;
template <int D, typename T>
struct Vec : public vector<Vec<D - 1, T>> {
static_assert(D >= 1, "Vector dimension must be greater than zero!");
template <typename...... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[100005];
int dp[1005];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
memset(dp, 0x3f, sizeof(dp));
for (int i = 1; i <= n; i++) cin >> a[i];
dp[0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= 511; j... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
void __print(int x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (!b) return a;
return gcd(b, a % b);
}
size_t highestOneBitPosition(uint64_t a) {
size_t bits = 0;
while (a != 0) {
++bits;
a >>= 1;
};
return bits;
}
bool multiplication_is_safe(long long a, long long b) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
map<int, long long> A[2], sum[2];
int ansMax = -1;
long long ans, total[2];
void update(int m, long long ways) {
if (m > ansMax) {
ansMax = m;
ans = ways;
} else if (m == ansMax) {
ans += ways;
}
}
int main() {
int N, M;
scanf("%d%d", &N, &M);
for (i... | 10 |
#include <bits/stdc++.h>
using namespace std;
char s[1000];
bool mirror(char a, char b) {
if (a == 'A' && b == 'A') return 1;
if (a == 'M' && b == 'M') return 1;
if (a == 'T' && b == 'T') return 1;
if (a == 'U' && b == 'U') return 1;
if (a == 'V' && b == 'V') return 1;
if (a == 'W' && b == 'W') return 1;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, a;
cin >> t;
while (t--) {
cin >> a;
if (360 % (180 - a) == 0)
cout << "YES\n";
else
cout << "NO\n";
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
vector<int> g[30010];
char vis[30010], cycle[30010];
int dist[30010];
bool achei = false;
int n;
stack<int> p;
void dfs(int u, int lst) {
if (achei) return;
if (vis[u]) {
while (p.top() != u) {
cycle[p.top()] = 1;
p.pop();
}
cycle[u] = 1;
p.p... | 4 |
#include <bits/stdc++.h>
using namespace std;
string str[105];
class node {
public:
int a, b, c, d, e, f;
node(int a1, int b1, int c1, int d1, int e1, int f1) {
a = a1;
b = b1;
c = c1;
d = d1;
e = e1;
f = f1;
}
};
void flip(vector<int> ans) {
for (int i = 0; i < 6; i += 2) {
if (str... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 10100;
const double eps = 1e-9;
struct node {
int x, y;
node operator+(const node &q) const { return node{x + q.x, y + q.y}; }
node operator-(const node &q) const { return node{x - q.x, y - q.y}; }
bool operator==(const node &q) const { return x == q.x... | 9 |
#include <bits/stdc++.h>
using namespace std;
vector<int> g[213700];
vector<int> gT[213700];
vector<int> g2[213700];
bool vis1[213700];
int kol = 1;
int num[213700];
int revnum[213700];
void dfs1(int a) {
vis1[a] = true;
for (int i = 0; i < g[a].size(); i++) {
if (!vis1[g[a][i]]) {
dfs1(g[a][i]);
}
... | 7 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T>
inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
bool great[1005];
int t[1005], l[1005], r[10... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 500010, inf = 1e9 + 233;
int n, m;
int f[maxn][2], a[maxn], b[maxn];
template <typename T>
inline void read(T &k) {
int f = 1;
k = 0;
char c = getchar();
while (c < '0' || c > '9') c == '-' && (f = -1), c = getchar();
while (c <= '9' && c >= '0') ... | 12 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:60000000")
using namespace std;
template <class T>
T sqr(T x) {
return x * x;
}
double const pi = 3.1415926535897932384626433832795;
int const inf = (int)1e9 + 1;
long long const inf64 = (long long)4e18 + 1;
const string name = "b";
int l1, l2, r1, r2, k;
long ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, m, i, j;
int g[111][111], rez[111][111], mini;
int ln[111], co[111], p1, p2;
int ans;
int main() {
scanf("%d%d", &n, &m);
mini = 1111;
for (i = 1; i <= n; i++)
for (j = 1; j <= m; j++)
scanf("%d", &g[i][j]), mini = min(mini, g[i][j]), rez[i][j] = g[i]... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int m[5], w[5];
for (int i = 0; i < 5; i++) cin >> m[i];
for (int i = 0; i < 5; i++) cin >> w[i];
int hs, hu;
cin >> hs >> hu;
int sum = 0;
for (int i = 0; i < 5; i++) {
sum +=
max(3 * (500 + 500 * i) / 10,
(1 * (500 + 500 ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
const int INF = 0x3f3f3f3f;
char s[MAXN][10];
int id = 0, vis[MAXN], ans = 0;
map<char, int> mp;
struct Node {
char ch;
long long val;
} num[MAXN];
bool cmp(Node a, Node b) { return a.val > b.val; }
long long fast_pow(int a, int x) {
long lon... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, perm[305], m[305][305];
char s[305];
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &perm[i]);
}
memset(m, 0, sizeof(m));
for (int i = 0; i < n; i++) {
scanf("%s", s);
for (int j = 0; j < n; j++) {
if (s[j] == ... | 4 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
vector<int> ad[2005];
int ara[2005], sz[2005], ans_ara[2005];
set<int> st;
void dfs(int src, int pre) {
sz[src] = 1;
for (int v : ad[src]) {
if (v == pre) continue;
dfs(v, src);
sz[src] += sz[v];
}
}
void dfs2(int src, int pre) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long N = 1e5;
const long long inf = 1e9;
template <typename... T>
void read(T&... args) {
((cin >> args), ...);
}
template <typename... T>
void write(T&&... args) {
((cout << args << " "), ...);
}
template <typename... T>
void w... | 4 |
#include <bits/stdc++.h>
using namespace std;
using lld = int64_t;
const lld INF = static_cast<lld>(1) << 60;
const int N = 5000 + 5;
lld arr[N], dp[N][2];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, k, x;
cin >> n >> k >> x;
for (int i = 1; i <= n; ++i) cin >> arr[i];
int me = 0... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n, k;
int a[maxn];
map<vector<pair<int, int> >, int> mp;
int main() {
scanf("%d%d", &n, &k);
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
long long ans = 0;
for (int i = 0; i < n; i++) {
vector<pair<int, int> > v1;
for (int ... | 5 |
#include <bits/stdc++.h>
using namespace std;
vector<int> prime;
const int N = 5e6 + 10;
bool pri[N];
int mu[N];
int phi[N];
int sum1[N], sum2[N];
void init() {
memset(pri, true, sizeof(pri));
mu[1] = 1;
phi[1] = 1;
for (int i = 2; i < N; i++) {
if (pri[i]) {
prime.push_back(i);
mu[i] = -1;
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int x0, y0, ax, ay, bx, by;
cin >> x0 >> y0 >> ax >> ay >> bx >> by;
long long int xs, ys, t;
cin >> xs >> ys >> t;
long long int ans = 0;
long long int _x0 = x0, _y0 = y0;
while (1) {
long long int _t = t;
long long int x = xs, ... | 4 |
#include <bits/stdc++.h>
using namespace std;
vector<int> primes;
int n;
int cnt[1000][1000];
int mat[5][5];
bool check(int x) {
for (int i = 2; i * i <= x; ++i)
if (x % i == 0) return false;
return true;
}
int calc(int m) {
if (m == n) return 1;
if (n - m == 2) {
int x = 0, y = 0;
for (int i = 0; i... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int LIM = 2e5 + 5;
long long a[LIM], b[LIM];
int solve() {
int m;
cin >> m;
int flag = 1;
int flag2 = 0;
for (int i = 0; i < m; i++) {
cin >> a[i];
b[i] = a[i];
if (i > 0) {
if (a[i] < a[i - 1]) {
flag = 0;
}
}
}
sort(... | 3 |
#include <bits/stdc++.h>
int ans = -1;
char s[4][105];
int strlen(char x[]) {
for (int i = 0;; i++)
if (!x[i]) return i;
}
int main() {
scanf("A.%[^\n]\n", s[0]);
scanf("B.%[^\n]\n", s[1]);
scanf("C.%[^\n]\n", s[2]);
scanf("D.%[^\n]\n", s[3]);
for (int i = 0; i < 4; i++) {
int sh = 0, lo = 0;
fo... | 2 |
#include <bits/stdc++.h>
void distinct_numbers_in_arr(int arr[100], int n) {
for (int i = 1; i < n; i++) {
for (int j = i; j < n; j++) {
if (arr[i - 1] == arr[j]) arr[j] = 0;
}
}
}
int gcd(int a, int b) {
int d = 0;
for (int i = 1; i <= a; i++)
if (b % i == 0 && a % i == 0) d = i;
return d;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long sol(long long x, long long y, long long z) {
return (x - y) * (x - y) + (y - z) * (y - z) + (z - x) * (z - x);
}
int main() {
long long t;
cin >> t;
while (t--) {
vector<long long> a(3);
for (int i = 0; i < 3; i++) {
cin >> a[i];
}
ve... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long sum_d(long long x) {
long long sum = 0;
while (x != 0) {
sum += x % 10;
x = x / 10;
}
return sum;
}
int main() {
long long n, k, l, r, mid, ans = 0;
cin >> n >> k;
l = 1;
r = n;
while (l <= r) {
mid = (l + r) / 2;
if (mid - sum_d(... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
int dis[N][N][2], vis[N][N][2];
int n, x[2], y[2];
struct node {
int x, y, z, d;
bool operator<(const node &a) const { return d > a.d; }
} now;
priority_queue<node> q;
char mp[N][N];
int ... | 3 |
#include <bits/stdc++.h>
using namespace std;
void __print(long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long tt = 1000000007;
inline int read() {
int Res = 0, f = 1;
char ch = getchar();
while (ch > '9' || ch < '0') f = (ch == '-' ? -f : f), ch = getchar();
while (ch >= '0' && ch <= '9') Res = Res * 10 + ch - '0', ch = getchar();
return Res * f;
}
long lo... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const long long NLINF = 0xf7f7f7f7f7f7f7f7;
const int INF = 0x3f3f3f3f, NINF = 0xf7f7f7f7;
const int MOD1 = 1e9 + 7, MOD2 = 1e9 + 9;
const int N = 1e5 + 10;
string s;
int n;
string sum(string a, string b) {
int off = 0, cur = 0;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const long long M = (long long)1e9 + 7;
int Int() {
int x;
scanf("%d", &x);
return x;
}
long long Long() {
long long x;
scanf("%I64d", &x);
return x;
}
void Char(char* ch) { scanf("%s", ch); }
template <typename t>
t abs(t a) {
if (a >= ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int k, n;
int m[1000];
void solve() {
char board[k][k];
int acum[k][k + 1];
int acum2[k][k + 1];
memset(acum, 0, sizeof(acum));
memset(board, 0, sizeof(board));
int xc = k / 2, yc = xc;
for (int x = 0; x < k; x++) {
acum2[x][0] = 0;
for (int y = 0; y <... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, r1, r2;
cin >> n >> r1 >> r2;
int A[n + 1];
for (int i = 1; i <= n; ++i) {
if (i == r1)
A[i] = 0;
else
cin >> A[i];
}
int v = r2, u = A[r2];
while (u != 0) {
int x = A[u];
A[u] = v;
v = u;
u = x;
}
fo... | 4 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, m;
cin >> n >> m;
vector<long long> cnt(m, 0), ans(n);
vector<pair<long long, long long>> a;
long long req = n / m;
for (long long i = 0; i < n; i++) {
long long xx;
cin >> xx;
ans[i] = xx;
cnt[xx % m]++;
if (cnt[x... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const int N = 1000000 + 10;
const int M = 1000;
const string st2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string s1 = "abcdefghijklmnopqrstuvwxyz";
pair<int, int> a[N];
int b[N];
string ans[N], da[N];
int main() {
cin >> b[1] >> b[2] >> b[3]... | 5 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > s;
struct block {
int u;
int l;
int d;
int r;
};
vector<block> bl;
void step(int &bp, int &state) {
int dx, dy, x, y;
x = bl[bp].u;
y = bl[bp].l;
dx = -1;
dy = -1;
if (state / 2 == 0) {
y = bl[bp].r;
dy = 1;
} else if (stat... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 200000;
const int MAXSUMLEN = 200000;
const int MAXT = MAXSUMLEN + 1;
const int MAXQ = 500000;
const int ASIZE = 26;
typedef struct Q {
int x, sgn, l, r, idx;
} Q;
int n, nq;
i... | 10 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
int main() {
fast();
int a, b, c, d;
cin >> a >> b >> c >> d;
cout << 2 * (a + b + d) + 4;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = (long long)1e9 + 7;
const long long maxn = (long long)4e5 + 7;
const long long maxe = (long long)1e6 + 7;
const long long INF = (long long)1e17 + 7;
const double PI = acos(-1);
int dx[4] = {0, 0, 1, -1};
int dy[4] = {-1, 1, 0, 0};
int n;
struct E {
i... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
pair<int, int> arr[n];
for (int i = 0; i < n; i++) {
scanf("%d %d", &arr[i].first, &arr[i].second);
}
sort(arr, arr + n, [](pair<int, int> a, pair<int, int> b) {
if (a.second == 100 && b.second != 100) return true;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
vector<int> vec;
int result[50000];
int MIN(int i, int j) {
int ans = 1e9;
for (int a = i; a <= j; a++) {
ans = min(ans, vec[a]);
}
return ans;
}
int main() {
int n, m;
scanf("%d %d", &n, &m);
for (int i = 0; i < (n); i++) vec.push_back(i + 1);
int limit... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e+6 + 100;
int main() {
int n, q, ans = 0;
cin >> n;
vector<int> mass(maxN);
for (int i = 0; i < n; i++) {
scanf("%d", &q);
mass[q]++;
}
for (int i = 0; i < maxN - 1; i++) {
mass[i + 1] += mass[i] / 2;
if (mass[i] % 2 != 0) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, a, r, m, i;
cin >> n >> a >> r >> m;
long long ar[n + 1];
long long pref[n + 2];
memset(pref, 0, sizeof(pref));
for (i = 1; i <= n; i++) {
cin >> ar[i];
}
long long z = min(m, a + r);
sort(ar + 1, ar + n + 1);
for (i = 1; i ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
long long power(long long n, long long p) {
if (p == 0) return 1;
if (p == 1) return n;
if (p % 2)
return power(n, p - 1) * n;
else {
long long x = power(n, p / 2);
retu... | 2 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-8;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int maxn = 2e5 + 10;
int n;
int a[maxn];
int bit[maxn];
vector<int> v[maxn];
long long sum(int i) {
long long res = 0;
while (i) {
res += bit[i];
i -= i & -i;
}
return res;
}... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 10;
const int MM = 1e9 + 7;
long long gcd(long long p, long long q) { return q ? gcd(q, p % q) : p; }
long long pw(long long p, long long q) {
long long ret = 1;
for (; q; q >>= 1) {
if (q & 1) ret = ret * p % MM;
p = p * p % MM;
}
ret... | 6 |
#include <bits/stdc++.h>
using namespace std;
int a[100005];
int f[100005];
int b[100005];
vector<int> ant[100005];
int main() {
int n, m;
scanf("%d %d", &n, &m);
for (int i = 0; i < n; i++) scanf("%d", &f[i]);
for (int i = 0; i < m; i++) scanf("%d", &b[i]);
for (int i = 0; i < n; i++) ant[f[i]].push_back(i);... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cout << fixed << setprecision(12);
long long int n, m, a[505], x, y, w;
long double ans = 0;
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i];
while (m--) {
cin >> x >> y >> w;
ans = max(ans, (long doubl... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, size_t N>
long long SIZE(const T (&t)[N]) {
return N;
}
template <typename T>
long long SIZE(const T &t) {
return t.size();
}
string to_string(const string s, long long x1 = 0, long long x2 = 1e9) {
return '"' + ((x1 < s.size()) ? s.substr(x1, x2... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int n, D, Ans, cnt, X, h[3005], g[3005], ans[3005];
int f[3005][3005], F[3005][3005], fac[3005], inv[3005];
struct node {
int to, next;
} e[3005];
void Addedge(int x, int y) { e[++cnt] = (node){y, h[x]}, h[x] = cnt; }
int Ksm(int a, int n) {
int... | 9 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
istream &operator>>(istream &is, vector<T> &arr);
template <typename T>
ostream &operator<<(ostream &os, vector<T> &arr);
int INF = 1e9 + 5;
void nope() {
cout << -1 << endl;
exit(0);
}
int main() {
int sum, limit;
cin >> sum >> limit;
vector... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int main() {
while (~scanf("%d%d%d", &n, &m, &k)) {
if (k >= m)
printf("1\n");
else if (n + k < m)
printf("0\n");
else {
double ans = 1;
for (int i = 1; i <= k + 1; i++) ans = ans * (m - i + 1) / (n + i);
ans = 1.0 - ... | 8 |
#include <bits/stdc++.h>
int main() {
long long n;
scanf("%I64d", &n);
long long a[n];
long long i, j;
for (i = 0; i < n; i++) {
scanf("%I64d", &a[i]);
}
long long count = 0;
long long less = 0;
long long more = 0;
for (i = 1; i < n; i++) {
for (j = 0; j < i; j++) {
if (a[j] < a[i]) {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long n, x;
long long num[21], f[1 << 20], g[21][21];
int main() {
cin >> n;
for (; n--;) {
cin >> x;
++num[--x];
for (int i = 0; i < 20; ++i) g[x][i] += num[i];
}
memset(f, 1, sizeof(f));
f[0] = 0;
for (int i = 0; i < 1 << 20; ++i)
for (int ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 10;
const int LIM = 80;
char pass[LIM + 1];
char nums[N][N + 1];
int main() {
cin >> pass;
for (int i = 0; i < N; i++) cin >> nums[i];
for (int i = 0; i < LIM; i += N)
for (int j = 0; j < N; j++)
if (!strncmp(pass + i, nums[j], N)) cout << j;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int readint() {
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();
}
return x * f;
}
int n, q, m, tot = 0;
int c... | 13 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int a, b, c, d;
cin >> a >> b >> c >> d;
for (long long int i = 0; i < 100; i++) {
for (long long int j = 0; j < 100; j++) {
if (b + (i * a) == d + (j * c)) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
string FILENAME = "filename";
unordered_map<int, unordered_set<int>> G;
unordered_map<int, int> mapper;
unordered_map<int, int> id;
int dpth[100001];
void preorder(unordered_map<int, unordered_set<int>> G) {
deque<pair<int, int>> S;
unordered_set<int> VST;
S.push_back... | 6 |
#include <bits/stdc++.h>
using namespace std;
long double a, b;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> a >> b;
int k1 = (a + b) / (2 * b), k2 = (a - b) / (2 * b);
long double x1 = -1, x2 = -1;
if (k1 > 0) {
x1 = (a + b) / (long double)(k1 * 2);
}
if (k... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000010;
char ch[MAXN], tmp[MAXN];
int a[MAXN];
int main() {
while (scanf("%s", tmp) != EOF) {
int n = strlen(tmp);
for (int i = 0, j = n - 1; j >= 0; --j, ++i) ch[i] = tmp[j];
ch[n] = 0;
memset(a, 0, sizeof(a));
int pres(-1000), pret(... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<vector<long long int> > M(n, vector<long long int>(m));
vector<vector<long long int> > N(n, vector<long long int>(m, 0));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m;... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int max_n = 100011, inf = 1000111222;
int n, leaf[max_n];
vector<int> g[max_n], val[max_n], num[max_n], ans_u, ans_v, ans_x;
void dfs1(int v, int p = -1) {
leaf[v] = v;
for (int to : g[v]) {
if (to == p) {
continue;
}
dfs1(to, v);
leaf[v] = l... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1002, inf = 2000;
int n, m, u, v, c, sum, ans[N], dist[N], mark[N];
vector<int> g[N];
int solve(int x) {
fill(dist, dist + N, inf);
queue<int> q;
q.push(x);
dist[x] = 0;
int res = 0;
while (q.size()) {
int u = q.front();
q.pop();
res = ... | 9 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int k, d, t;
};
int main() {
int n, q;
cin >> n >> q;
struct node a[q];
for (int i = 0; i < q; i++) {
cin >> a[i].t >> a[i].k >> a[i].d;
}
int s[n + 1], ss[n + 1], res[q], sum = 0, k = 0;
for (int i = 0; i <= n; i++) ss[i] = s[i] = 0;
for... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int x[n], y[n];
map<int, int> M;
for (int i = 0; i < n; i++) cin >> x[i] >> y[i];
for (int i = 0; i < n; i++) {
M[x[i]]++;
}
for (int i = 0; i < n; i++) {
int h = n - 1 + M[y[i]];
int a = n - 1 - M[y[i]];
cout <<... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, k;
cin >> n >> k;
vector<int> acc(1e6 + 1);
{
vector<int> cnt(1e6 + 1);
for (int i = 0; i < n; i++) {
int a;
cin >> a;
cnt[a]++;
}
for (int i = 1; i < 1e6 + 1; i++) {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long sum = 0;
long long mid = 0;
string s;
cin >> s;
for (long i = 0; i < s.length(); i++)
if (s[i] == '^') {
mid = i;
break;
}
for (long i = 0; i < s.length(); i++)
if (s[i] >= '1' && s[i] <= '9') sum += (((s[i] - '0'))... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t, n, p, q, c;
cin >> t;
while (t--) {
cin >> n;
c = (long long int)sqrt(n) + (long long int)cbrt(n) -
(long long int)(sqrt(cbrt(n)));
cout << c << endl;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
int main() {
int a, b;
scanf("%d %d", &a, &b);
if (a > b) {
printf("%d ", b);
a = a - b;
printf("%d", a / 2);
} else {
printf("%d ", a);
b = b - a;
printf("%d", b / 2);
}
return 0;
}
| 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.