solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
long long int pr[500100], su[500100];
long long int ans;
vector<int> v[500100];
void soll(int node, int p, int nd, int cnt) {
cnt %= 2;
if (cnt == 1 && node != 1) {
if (su[node] - nd < 0) {
cout << -1;
exit(0);
}
}
if (cnt == 0 && v[node].size() ... | 8 |
#include <bits/stdc++.h>
using namespace std;
char s[44][44];
int n, m;
void init() {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) scanf("%s", s[i]);
}
char ss[44][44];
int sg[44][44][44][44], tim, cc[2100];
bool bb[44][44][44][44];
int dfs1(int x1, int y1, int x2, int y2) {
if (x1 > x2 || y1 > y2) return 0... | 17 |
#include <bits/stdc++.h>
int main() {
int i, j;
scanf("%d", &i);
while (i > 0) {
scanf("%d", &j);
if (j % 2) j++;
j--;
printf("%d ", j);
i--;
}
puts("");
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> a;
int ans[100009];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
ans[i] = (1 << 30);
}
a.resize(n + 1);
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
}
for (int i = 1; i <= n; ++i) {
ans[i] = min(ans[i], ans[... | 8 |
#include <bits/stdc++.h>
using namespace std;
string str;
int main() {
long long left, right;
while (cin >> str) {
int mid;
left = right = 0;
for (int i = 0; i < str.size(); i++) {
if (str[i] == '^') {
mid = i;
break;
}
}
for (int i = 0; i < str.size(); i++) {
i... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int pos = 0;
int flag = 0;
while (n--) {
int a;
string b;
cin >> a >> b;
if (pos == 0) {
if (b != "South") {
flag = 1;
break;
}
}
if (pos == 20000) {
if (b != "North") {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
double n, p[100005];
void solve() {
double ans = 0, g = 0, s = 0, t = 0;
for (int i = 1; i <= n; i++) {
t = p[i - 1] * (t + 2 * s) + (1 - p[i - 1]);
s = p[i - 1] * s + (1 - p[i - 1]);
g = p[i] * (g + t);
ans += (1 - p[i + 1]... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 800010;
int rg[N];
struct IntervalStree {
int n;
int data[N];
int mx[N];
void init(int *data, int n) {
for (int i = 0; i < n; ++i) this->data[i] = data[i];
this->n = n;
initTree(0, 0, n - 1);
}
void initTree(int root, int rl, int rr) {
... | 15 |
#include <bits/stdc++.h>
using namespace std;
const long long OO = 1e8;
const double EPS = (1e-7);
int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; }
bool x[103];
int n;
int co() {
int count = 0;
for (int i = 1; i < n - 1; i++) {
if (x[i] == 0) {
if (x[i - 1] == 1 && x[i + 1]... | 2 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int, int> > > g;
int ecycl[100001];
int h[100001];
int vcycl[100001];
int reserror;
void dfs(int v, int p) {
for (size_t i = 0; i < g[v].size(); i++) {
int to = g[v][i].first;
int j = g[v][i].second;
if (h[to] == -1) {
h[to] = h[v] + 1... | 21 |
#include <bits/stdc++.h>
using namespace std;
const bool debug = 0;
struct pt {
long long x, y;
pt() {}
pt(long long a, long long b) : x(a), y(b) {}
};
pt operator+(pt a, pt b) { return pt(a.x + b.x, a.y + b.y); }
pt operator-(pt a, pt b) { return pt(a.x - b.x, a.y - b.y); }
pt operator*(pt a, long long b) { retu... | 27 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s1, s2;
cin >> s1;
s2 = "";
for (int i = 0; i < s1.length(); i++) {
if (s1[i] == '.')
s2 = s2 + "0";
else {
if (s1[i + 1] == '.')
s2 = s2 + "1";
else
s2 = s2 + "2";
i++;
}
}
cout << s2;
re... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5100;
int d[MAXN][MAXN], w[MAXN], par[MAXN], ans[MAXN];
pair<int, int> a[MAXN];
vector<pair<int, int> > g[MAXN];
bool mark[MAXN];
void dfs(int v) {
mark[v] = true;
for (int i = 0; i < g[v].size(); i++) {
int u = g[v][i].first, t = g[v][i].second;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3005;
const int mod = 998244353;
int f[N][N];
char s[N], t[N];
int main(void) {
scanf("%s", s + 1);
scanf("%s", t + 1);
int n = strlen(s + 1);
int m = strlen(t + 1);
for (int i = 1; i <= n; i++) {
if (i > m || s[1] == t[i]) {
f[i][i] = 2;
... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int j, i, len;
char alpha[] = {'a', 'A', 'e', 'E', 'i', 'I', 'o', 'O', 'u', 'U', 'y', 'Y'};
string a;
cin >> a;
len = a.length();
for (i = 0; i < len; i++) {
for (j = 0; j < 12; j++)
if (alpha[j] == a[i]) break;
if (j == 12) cout << ".... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long a[10010];
long long n, m, ans, minn = 999999, k, sum;
signed main() {
cin >> n >> m >> k;
for (long long i = 1; i <= n; ++i) {
cin >> a[i];
if (minn > a[i] && i % 2 == 1) minn = a[i];
}
sum = n / 2 + 1;
if (n % 2 == 0 || sum > m)
;
else {
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
srand(time(NULL));
;
int T = 1;
cin >> T;
while (T--) {
int n, m;
cin >> n >> m;
for (int i = 0; i < int(n); i++) {
for (int j = 0; j < int(m); j++) {
if (i |... | 2 |
#include <bits/stdc++.h>
const int N = 3e5 + 233;
int n, m, A[N];
inline int check(int t) {
for (int i = 1, last = 0; i <= n; ++i) {
if (A[i] + t >= m) {
int left = t - (m - A[i]);
if (left >= last) {
continue;
}
}
if (A[i] >= last) {
last = A[i];
continue;
}
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long a, t_a, b, t_b;
cin >> a >> t_a >> b >> t_b;
char c;
long long hr, mn;
cin >> hr >> c >> mn;
int go = 5 * 60;
while (go + t_b <= hr * 60 + mn && go < 5 * 60 + (24 - 5) * 60) go += b;
int te... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2000000000;
const double EPS = 1e-9;
int mods(int a, int b) { return (b + (a % b)) % b; }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, x, notVisible = 0, A[500005];
cin >> n;
for (int i = 0; i < n; i++) cin >> A[... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MX = 1000010;
vector<int> pr;
int pchk[MX];
void sieve() {
for (int i = 2; i < MX; i++) {
if (!pchk[i]) {
pr.push_back(i);
pchk[i] = i;
}
for (int j = 0; j < pr.size() && i * pr[j] < MX; j++) {
pchk[i * pr[j]] = pr[j];
if (i %... | 21 |
#include <bits/stdc++.h>
using namespace std;
int m, k, dist[1000001], n;
vector<int> rodas[1000001];
vector<string> ans;
vector<pair<int, int> > g[1000001];
string s;
void f(int u) {
if (u - 1 == n) return ans.push_back(s);
for (size_t i = 0; i < rodas[u].size(); i++) {
if ((int)ans.size() >= k) break;
s[r... | 13 |
#include <bits/stdc++.h>
using namespace std;
bool isprime(long long int n) {
if (n <= 1) return false;
if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0) return false;
return true;
}
vector<long long int> prime;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
void call(long long int n) {
long long int i, su = 0, m, a = 0;
m = n;
while (m > 1) {
m = m / 2;
a++;
}
n = n * (n + 1) / 2 - pow(2, a + 2) + 2;
cout << n << endl;
}
int main() {
long long int n;
long long int i, x;
cin >> n;
for (i = 0; i < n; ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 501;
const int MAXK = 100500;
bool trap[MAXN];
long double res[MAXN];
long double mx[MAXN][MAXN];
long double mtmp[MAXN][MAXN];
int deg[MAXN];
int sm[MAXN][MAXN];
long double mg[MAXN][2 * MAXN];
int n, m, k;
int bad[MAXN], cnt_b;
long double vec[MAXN];
void... | 20 |
#include <bits/stdc++.h>
using namespace std;
const long long INF_LL = 1e18 + 7;
const int INF_int = 1e9 + 7;
const int maxn = 123;
const int N = 3e5 + 1;
int32_t main() {
cout << fixed << setprecision(15);
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int n;
cin >> n;
int l = 0, r = n / 2;
i... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
int x[300005], y[300005];
int dp[300005][2];
int solve(int a, int b, int c, int d) {
int sol = 1e9, X, Y;
if (a <= k) {
X = a + c;
Y = (X + k - 1) / k - 1;
if (d == Y)
sol = min(sol, X - Y * k);
else if (d > Y && d <= 1LL * c * k)
s... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, a, b, c, d;
cin >> n >> a >> b >> c >> d;
int diff = a - b;
int sum = a + b;
int t1 = n * diff;
int t2 = n * sum;
int td = c - d;
int ts = c + d;
if ((t1 >= td && t1 <= ts) || (t2 >... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long mod_sub(long long a, long long b, long long p) {
if (a >= b) return a - b;
return p + a - b;
}
tuple<long long, long long> closest_under(long long p, long long q, long long n,
long long T);
tuple<long long, long long> ... | 19 |
#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1e9 + 7;
const long long int MOD2 = 998244353;
long double PI = 2 * acos(0.0);
template <typename T>
T gcd(T a, T b) {
return (b == 0) ? a : gcd(b, a % b);
}
template <typename T>
T lcm(T a, T b) {
return a * (b / gcd(a, b));
}
template <typena... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6;
const long long mod = 1e9 + 7;
inline long long read() {
long long s = 0;
register bool neg = 0;
register char c = getchar();
for (; c < '0' || c > '9'; c = getchar()) neg |= (c == '-');
for (; c >= '0' && c <= '9'; s = s * 10 + (c ^ 48), ... | 19 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T gcd(T a, T b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
template <class T>
T power(T a, T b) {
T result = 1;
while (b > 0) {
if (b & 1) result = result * a;
a = a * a;
b >>= 1;
}
return result;
}
template <clas... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200004;
long long sum[N];
int a[N];
int main() {
int n;
scanf("%d", &n);
int i;
for (i = 1; i <= n; i++) scanf("%d", &a[i]);
if (n <= 2) {
printf("%d\n", n);
for (i = 1; i <= n; i++) printf("%d ", a[i]);
return 0;
}
int lidx, midx, ri... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int TAM = 5555;
int h[TAM], n;
int acc[TAM];
int mem[TAM][TAM];
int bs(int from, int to, int val) {
int L = from + 1, R = to, mid;
while (L < R) {
mid = (L + R) / 2;
if (acc[mid] - acc[from] >= val)
R = mid;
else
L = mi... | 13 |
#include <bits/stdc++.h>
using namespace std;
template <class T> int sgn(T x) { return (x > 0) - (x < 0); }
template<class T>
struct Point { typedef Point P; T x, y;
explicit Point(T x_=0, T y_=0) : x(x_), y(y_) {}
bool operator<(P p) const { return tie(x,y) < tie(p.x,p.y); }
bool operator==(P p) const { return tie(... | 20 |
#include <bits/stdc++.h>
using namespace std;
long long int parent[10000];
long long int ranc[10000];
vector<pair<long long int, long long int> > v;
long long int makeset(long long int v) {
parent[v] = v;
ranc[v] = 0;
}
long long int findset(long long int v) {
if (parent[v] == v) {
return parent[v];
} else
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long int diff, a, b, start, s = 0, p = 0;
cin >> a >> b;
diff = abs(a - b);
if (diff == 0)
cout << 0 << endl;
else {
for (start = 1; diff > p; start++) {
s = (start * (start + 1) ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, l, v1, v2, k, nums;
void readData() {
cin >> n >> l >> v1 >> v2 >> k;
nums = (n + k - 1) / k;
}
bool check(double w) {
double len = (double)l;
double timeRemain = w;
for (int i = 1; i <= nums; i++) {
if (timeRemain * v2 < len) {
return false;
... | 11 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target( \
"avx,avx2,fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
int MOD = 1e9 + 7;
vector<vector<double> > p;
vector<int> used;
int n;
vector<double> ans;
vector<double> sm;
vector<double> pr;
int main() {
io... | 19 |
#include <bits/stdc++.h>
using namespace std;
int vis[30005];
int a[30005];
vector<int> g[30005];
int main() {
int i, j, n, m, p;
cin >> n >> m;
for (i = 0; i < m; i++) {
int x, y;
scanf("%d%d", &x, &y);
g[y].push_back(x);
}
a[1] = 1;
for (i = 2; i <= n; i++) {
p = g[i].size();
for (j = ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int a[103];
int main() {
int n, s;
cin >> n >> s;
for (int i = 1; i <= n; i++) {
int h, m;
cin >> h >> m;
a[i] = h * 60 + m;
}
if (a[1] >= s + 1)
return cout << "0 0", 0;
else {
for (int i = 1; i <= n - 1; i++)
if (a[i + 1] - a[i] >= (2... | 3 |
#include <bits/stdc++.h>
using namespace std;
string s;
int p[1000001];
map<int, bool> used;
int main() {
cin >> s;
for (int i = 1; i < s.size(); ++i) {
int j = p[i - 1];
while (j > 0 && s[j] != s[i]) j = p[j - 1];
if (s[i] == s[j]) ++j;
p[i] = j;
if (i != s.size() - 1) used[p[i]] = true;
}
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int c1, c2, c3, c4, n, m, ans1 = 0, ans2 = 0, a, b;
cin >> c1 >> c2 >> c3 >> c4 >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a;
ans1 += min(a * c1, c2);
}
for (int i = 1; i <= m; i++) {
cin >> b;
ans2 += min(b * c1, c2);
}
ans1... | 3 |
#include <bits/stdc++.h>
inline int in() {
int k = 0;
char ch = getchar();
bool p = 1;
while (ch < '-') ch = getchar();
if (ch == '-') ch = getchar(), p = 0;
while (ch > '-') k = k * 10 + ch - '0', ch = getchar();
return p ? k : -k;
}
const int YL = 1e9 + 7, N = 1 << 20;
inline int MO(const int &x) { retu... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 100000;
int a[MAX];
vector<int> edges[MAX];
int ab(int a) { return a < 0 ? -a : a; }
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) cin >> a[i], --a[i];
long long sum = 0LL;
for (int i = 1; i < m; i++) sum += ab(a[i] - a[i - 1]);... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 7;
int n;
int a[MAXN], b[MAXN], ans[MAXN];
int flag;
void dfs(int x) {
if (x < 1) {
flag = 1;
return;
}
for (int i = 0; i <= 3; i++) {
if ((a[x] == (ans[x + 1] | i)) && (b[x] == (ans[x + 1] & i))) {
ans[x] = i;
dfs(x - 1)... | 7 |
#include <bits/stdc++.h>
const int N = 55;
using namespace std;
long long f[N][N], a[N], n, all, sum[N];
int vis[N][N];
long long dp(int l, int r) {
if (l > r) return 0;
if (l == r) {
vis[l][r] = 1;
f[l][r] = a[l];
return f[l][r];
}
if (vis[l][r]) return f[l][r];
vis[l][r] = 1;
f[l][r] = max(dp(... | 7 |
#include <bits/stdc++.h>
using namespace std;
inline int nextint() {
int res = 0;
char c = 0;
while (c < '0' || c > '9') c = getchar();
while (c >= '0' && c <= '9') {
res = res * 10 + c - '0';
c = getchar();
}
return res;
}
vector<int> process(const vector<int>& v) {
vector<int> res;
for (int i ... | 18 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename... T>
void rd(T&... args) {
((cin >> args), ...);
}
template <typename... T>
void wr(T... args) {
((cout << args << " "), ...);
cout << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(n... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int q;
cin >> q;
while (q--) {
long long h, n;
cin >> h >> n;
vector<long long> p(n, 0);
for (int i = 0; i < n; i++) {
cin >> p[i];
}
long long streak = 0, ans = 0;
int i = 0;
while... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
int n, m;
cin >> n >> m;
int arr[n + 1];
int i, j;
int pos[n + 1];
for (i = 1; i <= n; i++) {
cin >> arr[i];
pos[arr[i]] = i;
}
int ans[n + 1];
int next[n + 1];
for (... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t, n, x;
cin >> t;
while (t--) {
cin >> n;
x = sqrt(n << 1);
if (x * (x + 1) <= 2 * n) x++;
cout << n + max(n, x * (x - 1) / 2 + 2) - 2 * x << endl;
}
return 0;
}
| 13 |
#include <bits/stdc++.h>
using namespace std;
const long long int MAX = 9187201950435737471;
const double pi = acos(-1);
const int N = 129;
const long long mod = 1000000007;
const int M = 2147483647;
const int lg = 101;
int n;
long long int A[N];
long long int child[N];
set<long long int> s;
map<long long int, long lon... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200000;
struct Event {
int height, t;
bool state;
Event() {}
Event(int height, int t, bool state) : height(height), t(t), state(state) {}
bool operator<(const Event &rhs) const { return height < rhs.height; }
};
int n, m, p[MAXN], cnt[MAXN];
Event... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n, cnt, c[N][2], sz[N], id[N], d[N];
long long K, a[N];
int get(int x, int y) {
if (!c[x][y]) c[x][y] = ++cnt;
return c[x][y];
}
int main() {
cin >> n >> K;
for (int i = 2; i <= n; i++) {
int x;
long long k;
scanf("%d%lld", &x,... | 21 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
char arr[n];
arr[0] = 'a';
if (n > 1) arr[1] = 'b';
if (n > 2) arr[2] = 'c';
if (n > 3) arr[3] = 'd';
for (int i = 4; i < n; i++) arr[i] = arr[i - 4];
for (int i = 0; i < n; i++) cout << arr[i];
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (a == 0) return b;
return gcd(b % a, a);
}
int main() {
int n;
cin >> n;
long long a[n + 1];
a[0] = 0;
long long s1 = 0, s2 = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
s1 += a[i];
}
sort(a + 1, a ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int ROW[] = {+1, -1, +0, +0};
int COL[] = {+0, +0, +1, -1};
int X[] = {+0, +0, +1, -1, -1, +1, -1, +1};
int Y[] = {-1, +1, +0, +0, +1, +1, -1, -1};
int KX[] = {-2, -2, -1, -1, 1, 1, 2, 2};
int KY[] = {-1, 1, -2, 2, -2, 2, -1, 1};
int GCD(int a, int b) { return b == 0 ? a : ... | 3 |
#include <bits/stdc++.h>
using namespace std;
mt19937 gen(chrono::system_clock::now().time_since_epoch().count());
const int N = 1e5 + 10;
const long long MOD = 1e9 + 7;
const long long p1 = 57, M1 = 1e9 + 3;
const int rx[4] = {-1, 0, 1, 0};
const int ry[4] = {0, 1, 0, -1};
const int hx[8] = {-2, -2, -1, 1, 2, 2, 1, -1... | 7 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
int dir_r[] = {1, 0, -1, 0, -1, 1, -1, 1};
int dir_c[] = {0, 1, 0, -1, -1, 1, 1, -1};
int main(void) {
int a, ta, b, cnt = 0, tb, n1, n2, a_departion, a_arrival, b_arrival,
b_departion;
char ch;
cin >> a >> ta;
cin >> b ... | 8 |
#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;
int cnt1 = 0, cnt2 = 0, ans = 0, ans2 = 0;
string s, p;
for (int i = 0; i < n; i++) {
int k;
cin >> k;
s += k + '0';
}
p = s;
s += p;
for (int... | 1 |
#include <bits/stdc++.h>
using namespace std;
int t[100010], ca, cb, i, j;
int main() {
int n;
scanf("%d", &n);
for (i = 1; i <= n; i++) scanf("%d", &t[i]);
for (i = 1, j = n; i <= j;) ca <= cb ? ca += t[i++] : cb += t[j--];
printf("%d %d", i - 1, n - i + 1);
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long a[3], n;
cin >> a[0] >> a[1] >> a[2] >> n;
long long ans = (n + 3) * (n + 2) * (n + 1) / 6;
for (int i = 0; i < 3; i++) {
for (int j = 0; j <= n; j++) {
long long h = a[i] + j;
... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long n, k;
long long dp[5003][5003], a[5003], xx;
multiset<long long> len[50003];
int main(int argc, char const *argv[]) {
ios_base::sync_with_stdio(false), cin.tie(NULL);
cin >> n >> k >> xx;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
memset(dp, -1, si... | 11 |
#include <bits/stdc++.h>
using namespace std;
int read() {
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 << 1) + (x << 3) + ch - '0', ch = getchar();
return x * f;
}
map<pair<int, int>, int> mp... | 17 |
#include <bits/stdc++.h>
using namespace std;
int n, a[200005], i, j, l, m, cnt = 0, ans[200005], indx = 0;
long long sum = 0;
int main() {
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
sum += a[i];
}
for (i = 1; i <= n; i++) {
if (a[i - 1] * n == sum) {
cnt++;
ans[indx]... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005, maxs = (1 << 17) + 5, mod = 998244353,
inv2 = (mod + 1) / 2;
inline int gi() {
char c = getchar();
while (c < '0' || c > '9') c = getchar();
int sum = 0;
while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
return... | 24 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
long long n, m, a, b;
cin >> n >> m >> a >> b;
if (n * a != m * b) {
cout << "NO\n";
continue;
}
cout << "YES\n";
long long ar[n][m];
memset(ar, 0, sizeof(ar));
long long i =... | 11 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
long long n, d, m;
cin >> n;
vector<long long> a;
long long sum = 0;
for (int i = 0; i < n; i++) {
char ch;
cin >> ch;
a.push_back(ch - '0');
sum += a.back();
}
for (int i = 2; i <= n; i++) {
if (sum % i == 0) {
long ... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long int a[110];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, d, l;
cin >> n >> d >> l;
int i, ms;
bool flag = 0;
if (d <= 0) {
for (i = 0; i < n; i++) {
if (i & 1)
a[i] = l;
else
a[i] = 1;
}
}... | 7 |
#include <bits/stdc++.h>
using namespace std;
char buf[1 << 21], *p1 = buf, *p2 = buf;
long long read() {
long long w = 0, f = 1;
char c = ' ';
while (c < '0' || c > '9')
c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)
? EOF
: *p1++),
f = c == '-' ? -... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9;
const int N = 8e5 + 5;
inline void read(int &x) {
char ch = getchar();
x = 0;
int f = 1;
while (ch < '0' || ch > '9') {
if (ch == '-') ch = getchar();
}
while (ch <= '9' && ch >= '0') {
x = (x << 3) + (x << 1) + ch - '0';
ch = ge... | 15 |
#include <bits/stdc++.h>
using namespace std;
int dp[45][45][45][45];
char a[45][45];
int s[45][45];
int z(int x1, int x2, int y1, int y2) {
x1--, y1--;
return s[x2][y2] - s[x1][y2] - s[x2][y1] + s[x1][y1];
}
int main() {
int n, m, q;
cin >> n >> m >> q;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <=... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long n, tmp, dv;
set<long long> st;
int main() {
cin >> n;
for (long long i = 1; i * i <= n; i++) {
if (n % i != 0) continue;
dv = i;
tmp = (n / dv);
tmp = 1 + tmp + dv * tmp * (tmp + 1) / 2;
st.insert(tmp - n - 1);
dv = n / i;
tmp = (n ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m[64][64];
cin >> n;
int p = 1, q = 2;
memset(m, 0, sizeof(m));
for (int i = 0; i <= n / 2; i++)
for (int j = n / 2 - i; j <= n / 2 + i; j++) m[i][j] = p, p += 2;
for (int i = n / 2 + 1; i < n; i++)
for (int j = i - n / 2; j < -i + 3 ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n;
int xx[105], yy[105];
int cnt, po;
int s1, s2, s3, s4;
int main() {
scanf("%d", &n);
for (int i = 1; i <= 4 * n + 1; i++) {
scanf("%d%d", &xx[i], &yy[i]);
}
for (int x20390 = 0; x20390 <= 50; x20390++) {
for (int y12098 = 0; y12098 <= 50; y12098++) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
float a[105], s, c;
int main() {
int n, b, i;
cin >> n >> b;
s = 0;
for (i = 0; i < n; i++) {
cin >> a[i];
s = s + a[i];
}
s = s + b;
c = s / n;
for (i = 0; i < n; i++) {
if (c < a[i]) {
cout << -1;
return 0;
} else
a[i] = c... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int m, k;
int d[2000];
int s, maxs, fu;
cin >> m >> k;
for (int i = 0; i < m; i++) cin >> d[i];
int c = 0;
fu = 0;
maxs = 0;
int t = 0;
while (c < m) {
cin >> s;
fu += s;
maxs = max(maxs, s);
while (fu < d[c]) {
fu += m... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long i, j, k, l, n, max = 0, min = 0, pr, cost = 0;
cin >> n;
char arr[n], a[n], b[n], c[n];
scanf("%s", arr);
for (i = 1; i < n; i++) {
if (i != n - 1) {
if (arr[i] == arr[i - 1]) {
cost++;
arr[i] = 'R';
if (arr... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, k, a[300000];
long long dp[2][5000 + 1];
int main() {
ios::sync_with_stdio(false);
cin >> n >> k;
for (int i = 0; i < n; ++i) cin >> a[i];
sort(a, a + n);
int n1 = n % k, n2 = k - n % k;
int sz1 = n / k + 1, sz2 = n / k;
dp[0][0] = 0;
for (int i = 1, ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-4;
double gcd(double x, double y) {
while (fabs(x) > eps && fabs(y) > eps) {
if (x > y)
x -= floor(x / y) * y;
else
y -= floor(y / x) * x;
}
return x + y;
}
double a_cos(double a, double b, double... | 13 |
#include <bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
bool Finish_read;
template <class T>
inline void read(T &x) {
Finish_read = 0;
x = 0;
int f = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') f = -1;
if (ch == EOF) return;
ch = getchar();
}
while (isdigit(ch))... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, A[105], B[105], ct1 = 0, ct2 = 0;
cin >> n;
for (int i = 0; i < n; i++) cin >> A[i];
for (int i = 0; i < n; i++) cin >> B[i];
for (int i = 0; i < n; i++) {
if (A[i] == 1 && B[i] == 1) {
A[i] = 0;
B[i] = 0;
}
}
for (int i... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long n, k, ans;
int main() {
cin >> n;
k = 1;
while (n > 1) {
ans += k * (n / 2);
k *= 2;
n -= n / 2;
}
cout << ans;
}
| 11 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const long long INF = 1000 * 1000 * 1000 + 7;
const long long LINF = INF * (long long)INF;
const int MAX = 100100;
vector<int> g[MAX];
vector<int> I[MAX];
int A[MAX];
long long RES[MAX];
int U[MAX];
long long dfs(int x) {
U[x] = true;
long ... | 19 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = (1ll << 62) - 1;
const int M = 1e5 + 5;
long long ar[100005];
long long cnt = 1, tot, res;
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> ar[i];
}
for (int i = 1; i < n; i++) {
i... | 5 |
#include <bits/stdc++.h>
template <typename T>
void MACRO_VAR_Scan(T& t) {
std::cin >> t;
}
template <typename First, typename... Rest>
void MACRO_VAR_Scan(First& first, Rest&... rest) {
std::cin >> first;
MACRO_VAR_Scan(rest...);
}
template <typename T>
void MACRO_VEC_ROW_Init(int n, T& t) {
t.resize(n);
}
tem... | 11 |
#include <bits/stdc++.h>
int i, j, n, a[1000][1000];
int main() {
scanf("%d", &n);
n--;
for (i = 0; i < n; i++)
for (j = 0; j < n; j++) a[i][j] = 1 + (i + j) % n;
for (i = 0; i < n; a[i][i] = 0, i++) a[i][n] = a[n][i] = a[i][i];
for (i = 0; i <= n; i++, puts(""))
for (j = 0; j <= n; j++) printf("%d ",... | 13 |
#include <bits/stdc++.h>
int main() {
int n, a[200003], i, min = 2000000000, mincount = 2000000000, count,
last = -1;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
if (a[i] < min) min = a[i];
}
for (i = 0; i < n; i++) {
if (a[i] == min) {
if (last == -... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b;
cin >> a >> b;
while (a.size() < b.size()) a = "0" + a;
while (b.size() < a.size()) b = "0" + b;
a = "0" + a;
b = "0" + b;
char mx = '0';
for (int i = 0; i < a.size(); i++) mx = max(mx, max(a[i], b[i]));
int base = mx - '0' + 1, c... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
if (n == 1)
printf("-1\n");
else if (n >= 2) {
int gg = n - 1;
printf("2");
while (gg--) printf("3");
printf("\n");
}
}
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int t[4 * 35005], d[4 * 35005], w[35005];
int dp[55][35005];
int n, k;
void build(int k, int u, int l, int r) {
if (l == r - 1) return void(t[u] = dp[k][l]);
int m = (l + r) / 2;
build(k, 2 * u + 1, l, m);
build(k, 2 * u + 2, m, r);
}
void push(int u, int len) {
i... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 100;
struct Node {
long long t, w;
};
Node node[N];
bool cmp(Node a, Node b) {
if (a.t != b.t)
return a.t > b.t;
else
return a.w < b.w;
}
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%I64d%I64d", &nod... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, x1, y1, x2, y2;
cin >> t >> x1 >> y1 >> x2 >> y2;
string s;
cin >> s;
long long x = x2 - x1;
long long y = y2 - y1;
int north = 0, south = 0, east = 0, west = 0;
int ans = -1;
for (int i = 0; i < t; i++) {
if (s[i] == 'N')
nor... | 4 |
#include <bits/stdc++.h>
using namespace std;
string S;
int N, M;
int C[6];
int mask[101010];
int pat[101010][64];
string T;
void solve() {
int i, j, k, l, r, x, y;
string s;
cin >> S;
N = S.size();
for (auto& c : S) C[c - 'a']++;
for (i = 0; i < (N); i++) mask[i] = (1 << 6) - 1;
cin >> M;
for (i = 0; i... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int MAXSIZE = 10000020;
int bufpos;
char buf[MAXSIZE];
void init() {
buf[fread(buf, 1, MAXSIZE, stdin)] = '\0';
bufpos = 0;
}
int readint() {
int val = 0;
for (; !isdigit(buf[bufpos]); bufpos++)
;
for (; isdigit(buf[bufpos]); bufpos++) val = val * 10 + b... | 10 |
#include <bits/stdc++.h>
using namespace std;
int dx[] = {-1, 1, 0, 0, 0, 0, 0, 0};
int dy[] = {0, 0, 1, -1, 0, 0, 0, 0};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long t;
cin >> t;
while (t--) {
long long n, q;
cin >> n >> q;
string s;
cin >> s;
... | 9 |
#include <bits/stdc++.h>
int n, q, k, z[500005], ans[500005];
std::vector<std::pair<int, int> > inc[500005 << 2];
std::vector<std::pair<int, std::pair<int, int> > > start[500005];
namespace dsu {
int fa[500005], size[500005], a[500005 << 4], b[500005 << 4], c[500005 << 4],
d[500005 << 4], sz = 0;
int getf(int x) { ... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int a, b, k;
cin >> a >> b >> k;
if (b == 1) {
if (k) {
cout << "No\n";
} else {
cout << "Yes\n";
cout << "1" + string(a, '0') << "\n";
cout << "1" + string(a, '0') << "\n";... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
const int M = 6e6 + 1;
int n, c;
pair<int, int> a[N];
struct ST {
int tag[M << 2], mx[M << 2];
void up(int x) { mx[x] = max(mx[(x << 1)], mx[(x << 1 | 1)]); }
void push(int x) {
if (!tag[x]) return;
tag[(x << 1)] += tag[x];
mx[(x << ... | 14 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.