solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
vector<int> a(6);
int sum = 0;
int main() {
for (int i = 0; i < 6; i++) {
cin >> a[i];
sum += a[i];
}
for (int i = 0; i < 6; i++)
for (int j = 0; j < 6; j++)
if (i != j)
for (int k = 0; k < 6; k++)
if (k != i && k != j)
... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long n;
bitset<500069> a;
struct val {
long long mx = 0, c[2] = {0, 0};
bool ft[2] = {1, 1}, jd = 1;
} v0;
struct segtree {
long long l, r;
val ans[2];
bool lz;
segtree *p[2];
val mrg(val x, val y) {
if (x.mx && y.mx) {
long long w;
val z;... | 20 |
#include <bits/stdc++.h>
using namespace std;
char s1[200005], s2[200005];
int N;
long double calc(char c) {
long double s = 0;
for (int i = 0; i < N; i++)
if (s1[i] == c) s += (N - i);
long double res = 0;
long double p = 0;
long double sum = s;
long double minus = 0;
for (int i = 0; i < N; i++) {
... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 26;
bitset<1250507> f[N << 1][N];
bool fl[N << 1];
int n, k, g[2][N], w[N << 1], e[N];
inline void solve(int v, int k, int q) {
if (v == 0) return;
if (f[k][q][v] && !f[k - 1][q][v])
e[++e[0]] = k, solve(v - w[k], k - 1, q - 1);
else
solve(v, k -... | 23 |
#include <bits/stdc++.h>
using namespace std;
int n, m, ans, grid[5001][5001], cnt[5001], tmp;
string s;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> s;
for (int j = 1; j <= m; j++) {
if (s[j - 1] == '1') grid[... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int inf = (1 << 30);
const int MX = 201;
int a[MX], b[MX], c[MX], d[MX];
int dp[21][1201], n, m, mx, c0, d0;
int main() {
scanf("%d%d%d%d", &n, &m, &c0, &d0);
a[0] = 1000, b[0] = 1;
c[0] = c0;
d[0] = d0;
for (int i = 1; i <= m; i++) scanf("%d%d%d%d", &a[i], ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long double a, b;
cin >> a >> b;
long double res = 0.5;
if (b == 0) {
printf("1\n");
continue;
}
if (4 * b < a)
res += 0.5 - b / a;
else
res += a / 16 / b;
printf("%.10... | 10 |
#include <bits/stdc++.h>
using namespace std;
bool a[205][205];
string f;
int i, x = 101, y = 101;
int main() {
a[x][y] = 1;
cin >> f;
for (i = 0; i < f.size(); i++) {
if (f[i] == 'U') {
x--;
if (a[x][y] == 1 || a[x - 1][y] == 1 || a[x][y - 1] == 1 ||
a[x][y + 1] == 1) {
cout << ... | 6 |
#include <bits/stdc++.h>
using namespace std;
bool ok = true;
long long n, m, real_n;
long long a[100001];
bool in_a[200002];
int not_a[100001];
int checks = 0;
unordered_set<int> dict;
unordered_set<int> tried;
bool reversed = false;
bool exists(long long x) {
unordered_set<int>::const_iterator got = dict.find(x);
... | 18 |
#include <bits/stdc++.h>
using namespace std;
int minn(int a, int b, int c, int d) { return min(a, min(b, min(c, d))); }
int cal(int a, int b, int c, int d) { return abs(a - c) + abs(b - d); }
int main() {
int n, x1, y1, x2, y2;
while (scanf("%d%d%d%d%d", &n, &x1, &y1, &x2, &y2) != EOF) {
if (x1 == x2 && (x1 ==... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
string s[110];
for (long long i = 0; i < n; i++) cin >> s[i];
map<string, long long> mp;
for (long long i = 0; i < n; i++) {
string str;
for (long long j = 0; j < n; j++) {
if (s[i][j] == '0') str.push_back((char... | 4 |
#include <bits/stdc++.h>
const long long N = 200005;
long long n, a[N], b[N], pos = -1, m;
long long co(long long x) { return (!x) ? n : x; }
signed main() {
scanf("%lld", &n);
for (long long i = 1; i <= n; i++) scanf("%lld", &a[i]), b[i] = a[i];
a[0] = b[0] = b[n];
for (long long i = 1; i <= n; i++) m = std::m... | 16 |
#include <bits/stdc++.h>
using namespace std;
long long int arr[1000001];
char str[100001];
int main() {
ios::sync_with_stdio(false);
cin.clear();
long long int t, n, i, j = 0, ans = 0, count = 0, sum = 0, k = 0;
cin >> n;
for (i = 0; i < n; i++) {
cin >> arr[i];
}
i = n - 2;
str[n - 1] = '+';
sum... | 11 |
#include <bits/stdc++.h>
using namespace std;
int t;
void test_case() {
int n_0, n_1, n_2;
cin >> n_0 >> n_1 >> n_2;
string result;
if (n_1 > 0 && n_0 == 0 && n_2 == 0) {
n_1++;
while (n_1 > 0) {
if (result.empty())
result.push_back('0');
else if (result.back() == '1')
result... | 7 |
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;
#define St first
#define Nd second
#define Pb push_back
#define print_pair(p) "{" << (p).St << ", " << (p).Nd << "} "
#define list_format(i, n)... | 3 |
#include <bits/stdc++.h>
using namespace std;
double x[3], y[3], r[3];
const double t0 = 1e9;
const double EPS = 1e-6;
inline double sqr(const double x) { return x * x; }
double sigma(double dx, double dy) {
double ret(0), t[3] = {0};
for (int i = 0; i < 3; ++i)
t[i] = sqrt(sqr(dx - x[i]) + sqr(dy - y[i])) / r[... | 18 |
#include <bits/stdc++.h>
using namespace std;
long long i, j, k, l, n, m, x;
set<long long> st;
long long res[200009], pos[200009];
vector<long long> q;
int main() {
cin >> n;
long long cnt = 0;
for (i = 1; i <= 2 * n; i++) {
char t;
cin >> t;
if (t == '+')
st.insert(++cnt), q.push_back(0);
... | 9 |
#include<bits/stdc++.h>
#define rep(i,x,y) for(auto i=(x);i<=(y);++i)
#define dep(i,x,y) for(auto i=(x);i>=(y);--i)
#define fr first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int>pii;
const int N=2e5+10;
const int mo=1e9+7;
const ll inf=1e18;
char s1[N],s2[N];
int lq[N],rq[N],a[N*4],... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, min, max, cur = 0;
cin >> n;
vector<pair<int, int>> v(n);
set<int> s;
s.insert(0);
for (int i = 0; i < n - 1; i++) {
cin >> v[i].first;
}
v[0].second = 0;
min = v[0].second;
max = v[0].second;
for (int i = 0; i < n - 1; i++) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
template <typename Tp>
inline void read(Tp &x) {
static char c;
static bool neg;
x = 0, c = getchar(), neg = false;
for (; !isdigit(c); c = getchar()) {
if (c == '-') {
neg = true;
}
}
for (; isdigit(c); c = getchar()) {
x = x * 10 + c - '0';
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
int t, sx, sy, ex, ey, ans;
cin >> t;
cin >> sx;
cin >> sy;
cin >> ex;
cin >> ey;
ans = 0;
int q, w;
q = ex - sx;
w = ey - sy;
char one, two;
vector<char> wind;
int i;
char ch;
ch = getchar();
for (i = 1; i ... | 4 |
#include <bits/stdc++.h>
using namespace std;
void qmax(int &x, int y) {
if (x < y) x = y;
}
void qmin(int &x, int y) {
if (x > y) x = y;
}
inline int read() {
char s;
int k = 0, base = 1;
while ((s = getchar()) != '-' && s != EOF && !(isdigit(s)))
;
if (s == EOF) exit(0);
if (s == '-') base = -1, s =... | 17 |
#include <bits/stdc++.h>
using namespace std;
priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
greater<pair<long long, long long>>>
q;
signed main() {
map<long long, long long> m;
map<long long, long long>::iterator it;
long long n;
cin >> n;
for (long long i =... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 128;
int n, x;
double p[N];
struct Mat {
static const int N = ::N;
double a[N][N];
Mat() {}
Mat(double v) {
for (int i = (0); i < (N); i++)
for (int j = (0); j < (N); j++) a[i][j] = i == j ? v : 0;
}
void print() {
for (int i = (0); i... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long l, r, m;
cin >> l >> r >> m;
for (long long a = l; a <= r; a++) {
int rem = m % a;
if (rem <= r - l) {
if (rem - m != 0) {
cout << a << " " << r << " " << r - rem << endl;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
vector<int> all_x, all_y;
map<pair<int, int>, int> all_tree;
int pos_x[1000006], pos_y[1000006], value_x[1000006], value_y[1000006];
map<int, int> difference;
int minus_mod(int a, int b, int m) { return (a - b + m + m) % m; }
int main() {
int n, m, dx, dy, i;
scanf("%d"... | 12 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long inf = 0x3f3f3f3f;
const long long nax = 0;
int n;
int main() {
ios_base::sync_with_stdio(0);
cin.tie();
cout.tie();
cin >> n;
vector<long long> f(65);
f[1] = 0;
f[2] = 2;
for (int i = 3; i <= n; ++i) {
f[i] ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a1, a2, b1, b2, c1, c2;
cin >> a1 >> a2 >> b1 >> b2 >> c1 >> c2;
if (a1 * (b2 - c2) + b1 * (c2 - a2) + c1 * (a2 - b2) == 0) {
cout << "No";
return 0;
} else if (((a1 - b1) * (a1 - b1) + (a2 - b2) * (a2 - b2)) ==
((c1 - b1)... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
long long int hh, mm;
cin >> hh >> mm;
long long int h, d, c, n;
cin >> h >> d >> c >> n;
if (hh >= 20)
cout << (h / n + ((h % n > 0) ? 1 : 0)) * c * 0.8 << '\n';
else {
cout << min((h / n + ((h % n > 0) ?... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int l[4];
for (int i = 0; i < 4; ++i) cin >> l[i];
bool t, s, i;
sort(l, l + 4);
if ((l[0] + l[1] > l[2] && l[1] + l[2] > l[0] && l[0] + l[2] > l[1]) ||
(l[1] + l[2] > l[3] && l[2] + l[3] > l[1] && l[1] + l[3] > l[2]))
cout << "TRIANGLE" << ... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void printRange(T &x) {
for (auto y : x) cout << y << ' ';
cout << endl;
}
const int maxn = 7e4 + 10;
int n;
struct S {
int len;
long long x;
bool operator<(const S &rhs) const {
if (len < rhs.len) return true;
if (rhs.len < len) retu... | 8 |
#include <bits/stdc++.h>
using namespace std;
set<long long int> t;
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
int g = 0, s = 0, b;
for (int j = 1; j <= m; j++) {
char x;
cin >> x;
x == 'G' ? g = j : x == 'S' ? s = j : b = 0;
}
if (g > s) {
cout <<... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
struct Matrix {
int r, c;
T a[4][4];
Matrix() { memset(a, 0, sizeof a); }
Matrix(int si) {
memset(a, 0, sizeof a);
r = c = si;
for (int i = 0; i < si; i++) a[i][i] = 1;
}
Matrix operator*(const Matrix &rhs) {
Matrix<T> ret;
... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, x, y;
cin >> n >> m;
x = n % m;
y = n / m;
long long a1 = ((y * (y - 1) / 2 * (m - x) + y * (y + 1) / 2 * x)),
a2 = ((n - m) * (n - m + 1) / 2);
cout << a1 << " " << a2 << endl;
return 0;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
string s, r1, r2;
bool broj() {
int i;
if (s == "") return false;
if (s.size() == 1) {
if (s[0] >= '0' && s[0] <= '9') {
return true;
} else {
return false;
}
}
if (s[0] >= '1' && s[0] <= '9') {
for (i = 1; i < s.size(); i++)
if (... | 8 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T getint() {
T x = 0, p = 1;
char ch;
do {
ch = getchar();
} while (ch <= ' ');
if (ch == '-') p = -1, ch = getchar();
while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
return x * p;
}
template <typename T1, typena... | 19 |
#include <bits/stdc++.h>
using namespace std;
int row[1010];
int main() {
int n, m, k;
scanf("%d %d %d", &n, &m, &k);
memset(row, 0x3f3f3f3f, sizeof row);
long long ans = 0;
for (int i = (0); i < (n); ++i) {
int r, c;
scanf("%d %d", &r, &c);
row[r] = min(c, row[r]);
}
for (int i = 1; i <= m; +... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n;
map<int, int> up, down;
int orientation(pair<int, int> a, pair<int, int> b, pair<int, int> c) {
pair<int, int> ab = {b.first - a.first, b.second - a.second};
pair<int, int> bc = {c.first - b.first, c.second - b.second};
int64_t cross = 1ll * ab.first * bc.secon... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, a, b;
cin >> n >> k;
vector<int> v[n + 1];
for (int i = 1; i <= n; i++) v[i].push_back(0);
for (int i = 0; i < k; i++) {
cin >> a >> b;
v[a][0]++;
v[b][0]++;
v[a].push_back(b);
v[b].push_back(a);
}
int cnt[3] = {0};
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2004;
int n, a, b;
bool Macierz[N][N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> a >> b;
if ((a > 1 && b > 1)) {
cout << "NO";
getchar();
getchar();
return 0;
}
if (n == 2 && a == 1 && b == 1) return cout <<... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
int n, a, b;
cin >> n >> a >> b;
if (a && a > n - 2) {
cout << -1 << endl;
return 0;
}
vector<int> ret(n, 1);
for (int i = 0; i < (int)(b); i++) ret[1 + i] = ret[i] * 2;
if (!b && a) {
ret[0] = 10;
r... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, y;
bool odd = false;
cin >> x >> y;
for (int i = 0; i < x; i++) {
if (i % 2 == 0) {
for (int j = 0; j < y; j++) cout << "#";
cout << "\n";
} else {
if (odd == false) {
for (int k = 0; k < y - 1; k++) cout << ".";... | 0 |
#include <bits/stdc++.h>
using namespace std;
int N, x[1005], y[1005];
double L, R;
int main() {
scanf("%d", &N);
for (int i = 1; i <= N; i++) scanf("%d%d", &x[i], &y[i]);
L = x[1], R = x[2], x[N + 1] = x[1], y[N + 1] = y[1];
if (L > R) swap(L, R);
for (int i = 2; i <= N; i++) {
double k, b, xx;
if (y... | 17 |
#include <bits/stdc++.h>
using namespace std;
long long h, w, p = 1ll, a, b, temp, times = 30ll;
int main() {
scanf("%lld%lld", &h, &w);
while (times--) {
if (p <= h && (p << 2ll) <= 5ll * w) {
temp = min(w, 5ll * p >> 2ll);
if (p * temp > a * b || (p * temp == a * b && a < p)) {
a = p;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 5;
const double INF = 1e6;
const double eps = 1e-16;
const double pi = acos(-1);
template <typename T>
void chkmax(T &x, T y) {
x = max(x, y);
}
template <typename T>
void chkmin(T &x, T y) {
x = min(x, y);
}
template <typename T>
void read(T &x) ... | 22 |
#include <bits/stdc++.h>
using namespace std;
const int nm = 110;
int n, a[nm];
string res[nm];
void solve() {
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
a[n + 1] = 0;
res[0] = string(max(a[1], 1), 'a');
for (int i = 1; i <= n; ++i) {
res[i] = res[i - 1].substr(0, a[i]);
int l = max... | 4 |
#include <bits/stdc++.h>
using namespace std;
char inp[101][101] = {0};
char ans[101][101] = {0};
const int op[][2] = {-1, 0, -1, 1, -1, -1, 1, -1, 1, 0, 1, 1, 0, -1, 0, 1};
int count(int i, int j) {
int x = 0;
for (int t = 0; t < 8; t++) {
if (inp[i + op[t][0]][j + op[t][1]] == '*' && i + op[t][0] >= 0 &&
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int frq[10000];
int main() {
int n, x, i, T;
scanf("%d", &n);
memset(frq, 0, sizeof frq);
for (i = 0; i < n; i++) {
scanf("%d", &x);
frq[x]++;
}
for (i = 1; i < 10000; i++) frq[i] += frq[i - 1];
scanf("%d", &T);
int mx = frq[T];
for (i = 1; i < 100... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
vector<int> a(n);
for (int &x : a) cin >> x;
int mx = *max_element(a.begin(), a.end());
vector<int> vis(mx + 1, -1), cnt(mx + 1), dis(mx + 1, 0);
for (int i = ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int inf = (1 << 30) - 1;
const int N = 200005;
array<int, 9> id = {inf, inf, inf, inf, inf, inf, inf, inf, inf};
struct node {
array<int, 9> a;
int best;
node() {
a = id;
best = 2 * inf;
}
};
vector<node> tree(4 * N, node());
vector<int> val(N, 0);
int... | 15 |
#include <bits/stdc++.h>
template <class T>
inline void read(T &res) {
char ch;
while (ch = getchar(), !isdigit(ch))
;
res = ch ^ 48;
while (ch = getchar(), isdigit(ch)) res = res * 10 + ch - 48;
}
template <class T>
inline void put(T x) {
if (x > 9) put(x / 10);
putchar(x % 10 + 48);
}
using std::pair;... | 25 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
template <typename T>
bool mmax(T &m, const T q) {
if (m < q) {
m = q;
retu... | 16 |
#include <bits/stdc++.h>
using namespace std;
struct f {
int a;
int b;
} s[1005];
bool cmp(f x, f y) {
if (x.b != y.b) return x.b > y.b;
return x.a > y.a;
}
int main() {
int n, i;
while (scanf("%d", &n) != EOF) {
for (i = 0; i < n; i++) scanf("%d%d", &s[i].a, &s[i].b);
sort(s, s + n, cmp);
int n... | 3 |
#include <bits/stdc++.h>
using namespace std;
#define N 100100
int id[300], x[N], fst[30], lst[30], cnt[30];
int n, a, b;
bool dp[1<<20];
char ch[30], s[N];
inline bool good(int y) {
int l = n, r = 0, tot = 0;
for (int i = 0; i < 20; i ++) if (y >> i & 1) {
if (cnt[i]) {
tot += cnt[i];... | 27 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
int a[N], b[N], d[N], f[N], to[N];
bool ban[N];
int main() {
int n, m;
scanf("%d %d", &n, &m);
for (int i = 1; i <= m; i++)
scanf("%d %d", &a[i], &b[i]), d[a[i]]++, d[b[i]]++, to[i] = m - i + 1;
for (int i = 1; i <= n; i++) f[i] = (d[i] + ... | 16 |
#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... | 6 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
using namespace std;
const long long N = 2e5 + 100, OO = 1e9 + 7, T = 1e6 + 10, mod = 1e9 + 7,
M = 10301, P = 6151, SQ = 280, lg = 70;
long long nxt[N], v[N], b[N],... | 14 |
#include <bits/stdc++.h>
using namespace std;
vector<string> A(8);
map<char, int> best;
void check(int x, int y) {
if (A[x][y] == '.')
return;
else if (A[x][y] == 'W') {
for (int i = 0; i < x; i++) {
if (A[i][y] == 'B') return;
}
best['W'] = min(best['W'], x);
} else {
for (int i = x + 1... | 4 |
#include <bits/stdc++.h>
using namespace std;
char str[100010];
int cnt[3];
int aux;
int l, r;
int main() {
scanf("%s", str);
int tam = strlen(str);
cnt[0] = cnt[1] = cnt[2] = 0;
for (int i = 0; i < tam; i++) {
if (str[i] == '?')
cnt[2]++;
else
cnt[str[i] - '0']++;
}
if (str[tam - 1] == ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long long UNDEF = -1;
const long long INF = 1ULL << 58ULL;
template <typename T>
inline bool chkmax(T &a, T b) {
return a < b ? a = b, true : false;
}
template <typename T>
inline bool chkmin(T &a, T b) {
return a > b ? a = b, true : false;
}
pair<long long, long ... | 22 |
#include <bits/stdc++.h>
using namespace std;
void solve(long long testcase) {
long long n;
cin >> n;
vector<long long> v(n);
map<long long, vector<long long>> mp;
for (long long i = 0; i < n; i++) {
cin >> v[i];
mp[v[i]].push_back(i);
}
vector<long long> a, b;
long long c = 1;
for (auto p : m... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MX = 2005;
const long long MOD = 1000000007;
const long long P1 = 998244353;
const long long P2 = 1000000009;
const long long R = 1331;
void add(long long &x, const long long &y) { x = (x + y) % MOD; }
char str[2][MX], tar[MX];
int n, m;
void input() {
scanf("%s... | 24 |
#include <bits/stdc++.h>
using namespace std;
int n, d, a[2000];
int main() {
cin >> d >> n;
for (int i = 0; i < n; i++) cin >> a[i];
long long res = 0;
for (int i = 0; i < n - 1; i++) res += d - a[i];
cout << res;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int c[1000005], d[1000005];
;
int n, q;
int main() {
cin >> n >> q;
int a = 0, b = 1;
for (int i = 0; i < q; i++) {
int x, y;
scanf("%d", &x);
if (x == 1) {
scanf("%d", &y);
a = (a + y + n) % n;
b = (b + y + n) % n;
} else {
a ^... | 10 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int main() {
int n, m;
cin >> n >> m;
cout << gcd(n - 1, m - 1) + 1;
return 0;
}
| 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int n = s.length();
vector<bool> used(26, false);
for (int i = 0; i < n; i++) {
for (int j = s[i] - 'a' + 1; j < 26; j++) {
used[j] = true;
}
if (used[s[i] - 'a']) {
cout << "Ann" << endl;
} else {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, x;
cin >> n >> x;
cout << min(4 * n - x, 3 * n + x - 1) << endl;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1.0);
int dblcmp(double d) {
if (fabs(d) < eps) return 0;
return d > eps ? 1 : -1;
}
struct team {
string name;
int sc;
int g, m;
team() {}
team(string sv) {
name = sv;
sc = g = m = 0;
}
bool operato... | 10 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T extgcd(T a, T b, T& x, T& y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
T q = a / b;
T g = extgcd(b, a - q * b, y, x);
y -= q * x;
return g;
}
long long a1, b1, a2, b2;
long long f(long long N) {
long long x, y;
long long g... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int w = 0;
int b = 0;
for (int i = 0; i < 8; i++) {
cin >> s;
for (int j = 0; j < 8; j++) {
char p = s[j];
if (p == 'Q') {
w += 9;
} else if (p == 'q') {
b += 9;
} else if (p == 'R') {
w ... | 1 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, -1, 1, -1, 1};
const int maxn = 1e5 + 10;
const int maxx = 600005;
c... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 7, inf = 1e9 + 7;
int n, s, m, d;
int tm(int a, int b) { return a * 60 + b; }
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> s;
int ans = inf;
vector<int> a(n);
for (int i = 0; i < n; i++) {
int b, c;
cin >> b >> c;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long int inf = 1e9 + 7;
const long long int mod = 998244353;
long long int maxi(long long int a, long long int b) {
if (a >= b) return a;
return b;
}
long long int mini(long long int a, long long int b) {
if (a >= b) return b;
return a;
}
int checkper(vec... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long maxx = 1e6 + 5;
bool dd[maxx], check, d1[maxx];
long long tr[maxx], val[maxx];
long long b, n, m, k, q, c, f[maxx], x, y, tong = 0;
vector<long long> st[maxx];
bool prime(long long v) {
if (v < 2) return false;
for (int i = 2; i <= v / i; i++) {
if (... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e6;
const long long mod = 1e9 + 7;
const long long inf = 1e9;
long long a[610][610], f[2][610][610];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cerr.tie(nullptr);
int n;
cin >> n;
for (int i = 0; i <= 310... | 12 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const int MAX = 2e5 + 4;
const int MOD = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n - 1);
vector<int> adj[n + 1];
for (int i = 0; i < n - 1; i++) {
cin >> a[i];
adj[a... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, t1, t2, k;
cin >> n >> t1 >> t2 >> k;
pair<double, int> arr[n];
arr[0].first = 0;
arr[0].second = 0;
for (int i = 0; i < n; i++) {
long long int u1, u2;
cin >> u1 >> u2;
arr[i] = make_pair(-max(u1 * t1 * (100 - k) + u2 *... | 4 |
#include <bits/stdc++.h>
long long dp[11][51], count;
int z[51];
char q[51];
int lun;
int flag(int k, int *x) {
int y = 0;
for (int i = 0; i < k - 1; i++) {
if (x[i] - x[i + 1] > 1 || x[i] - x[i + 1] < -1) {
y = 1;
break;
}
}
return y;
}
long long DFS(int n, int r) {
if (dp[n][r] != 0) ret... | 9 |
#include <bits/stdc++.h>
using namespace std;
inline long long readint() {
long long a = 0;
char c = getchar(), f = 1;
for (; c < '0' || c > '9'; c = getchar())
if (c == '-') f = -f;
for (; '0' <= c && c <= '9'; c = getchar())
a = (a << 3) + (a << 1) + (c ^ 48);
return a * f;
}
const int MaxN = 300005... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b;
cin >> a;
for (auto i : a)
if (isdigit(i)) b += i;
sort(b.begin(), b.end());
for (int i = 0; i < b.size(); i++) {
if (i != 0) cout << "+";
cout << b[i];
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 410;
int n, m;
int nxt[N][26];
char s[N], t[N];
void init() {
for (int j = 0; j <= 25; j++) {
nxt[n][j] = n + 1;
nxt[n + 1][j] = n + 1;
}
for (int i = n - 1; i >= 0; i--) {
for (int j = 0; j <= 25; j++) nxt[i][j] = nxt[i + 1][j];
nxt[i][s... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int ax, ay, bx, by, cx, cy, q;
cin >> ax >> ay >> bx >> by >> cx >> cy;
q = (bx - ax) * (cy - by) - (by - ay) * (cx - bx);
if (q == 0)
cout << "TOWARDS\n";
else if (q > 0)
cout << "LEFT\n";
else
cout << "RIGHT\n";
return 0;
}... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, S;
cin >> n >> S;
int a[n];
for (int i = 0; i <= n - 1; i++) cin >> a[i];
int left = 1, right = n;
int middle = (left + right) / 2;
int k = 0, T = 0;
while (left <= right) {
middle = (left + right) / 2;
long long int b[n];
for... | 7 |
#include <bits/stdc++.h>
using namespace std;
template <class T1>
void deb(T1 e1) {
cout << e1 << endl;
}
template <class T1, class T2>
void deb(T1 e1, T2 e2) {
cout << e1 << " " << e2 << endl;
}
template <class T1, class T2, class T3>
void deb(T1 e1, T2 e2, T3 e3) {
cout << e1 << " " << e2 << " " << e3 << endl;
... | 15 |
#include <bits/stdc++.h>
using namespace std;
char s[100005];
int main() {
int num = 0, ans = 0, len;
scanf("%s", s);
ans = 1;
len = strlen(s);
num = s[len - 1] - '0';
if (num % 2 == 0)
ans += 1;
else
ans += 4;
if (len >= 2) {
num = (s[len - 2] - '0') * 10 + s[len - 1] - '0';
if (num % 4... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, a, b, c;
int input(void) {
scanf("%d%d%d%d", &n, &a, &b, &c);
return 0;
}
int solve(void) {
int x, ans = 0;
for (register int y = 0; y <= b; y++) {
for (register int z = 0; z <= c; z++) {
x = (n - y - (z << 1)) << 1;
if (0 <= x && x <= a) ans+... | 7 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:128777216")
using namespace std;
struct Basket {
int id;
int val;
void init(int i, int n) {
this->id = i + 1;
val = abs((n + 1) - (i + 1) * 2);
}
bool operator<(const Basket &b) const {
return val < b.val || val == b.val && id < b.id;
}
} ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> v1(n), v2(n - 1), v3(n - 2);
for (int i = 0; i < n; ++i) cin >> v1[i];
for (int i = 0; i < n - 1; ++i) cin >> v2[i];
for (int i = 0; i < n - 2; ++i) cin >> v3[i];
sort(v1.begin(), v1.end());
sort(v2.begin(), v2.end()... | 3 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > ord;
bool comp(pair<int, int> a, pair<int, int> b) {
if (a.first != b.first) {
return a.first > b.first;
}
return a.second < b.second;
}
int main() {
string entrada;
cin >> entrada;
for (int i = 0; i < entrada.size(); i++) {
ord.p... | 3 |
#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
const int N = 1e5 + 2;
int n, a, b, p[N], cntEdge[N];
vector<int> g[2 * N];
map<int, int> mp;
void addEdge(int x1, int x2) {
g[x1 ^ 1].emplace_back(x2);
g[x2 ^ 1].emplace_back(x1);
}
bool mark... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long v[4005], d[4005], p[4005];
long long ans[4005];
long long flag[4005];
int n;
int main() {
memset(flag, 0, sizeof(flag));
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%lld%lld%lld", &v[i], &d[i], &p[i]);
int tot = 0;
for (int i = 1; i <= n; i++) {... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long mode(long long x, long long m) { return (x % m + m) % m; }
long long mod = 1000000007;
long double pi = 2 * acos(0.0);
bool tt(long double ar[], long double v[], long long n, long double mid) {
long double maxi = INT_MIN;
long double mini = INT_MAX;
for (lon... | 8 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
namespace input {
template <class T>
void re(complex<T>& x);
template <class T1, class T2>
void re(pair<T1, T2>& p);
template <class T>
void re(vector<T>& a);
template <class T, size_t SZ>
void re... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
ios::sync_with_stdio(false);
cin.tie(0);
int n, d, seq[110];
cin >> n >> d;
for (int i = 0; i < n; ++i) {
cin >> seq[i];
}
sort(seq, seq + n);
int cnt = 0, start = 0, end = 0;
while (end < n) {
if (seq[end] ... | 4 |
#include <bits/stdc++.h>
struct Show {
int l;
int r;
};
bool order(Show a, Show b) { return a.l < b.l; }
struct My {
int time;
int num;
};
bool operator<(const My &a, const My &b) { return a.time > b.time; };
int main() {
int n;
std::cin >> n;
std::vector<Show> shows(n);
std::priority_queue<My> heap;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int nxt[3000000][2];
int val[3000000];
int pw[27];
int tot;
void upd(int x, int value) {
int cur = 0;
for (int i = 26; i >= 0; --i) {
int d = x & pw[i];
if (d > 0) d = 1;
if (!nxt[cur][d]) nxt[cur][d] = ++tot;
cur = nxt[cur][d];
val[cur] += value;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
register int x = 0, f = 1;
register char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = 0;
ch = getchar();
}
while (isdigit(ch)) {
x = x * 10 + (ch ^ '0');
ch = getchar();
}
return f ? x : -x;
}
const int N = 1e5 ... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 1e5 + 6;
const long long mx = 1e9;
int dp[410][410];
string s, t;
void solve() {
int n, m;
cin >> s >> t;
n = s.length();
m = t.length();
for (int k = 0; k <= m - 1; k++) {
int y = m - k;
memset(dp, -1, sizeof(dp));
... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200002;
int n, m, k;
bool b[N];
struct node {
int id;
long long w;
} a[N];
inline int read() {
int x = 0, k = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') k = -1;
c = getchar();
}
while (c >= '0' && c <= '9') x = (x <... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long int n;
cin >> n;
for (long long int i = 0; i < n; i++) {
long long int a, x;
cin >> a;
x = a;
vector<int> v;
for (long long int i = 2; i <= sqrt(a); i++) {
if... | 5 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.