solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int amax = *max_element(a.begin(), a.end());
int amin = *min_element(a.begin(), a.end());
vector<int> l(m),... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k, i, j, s;
cin >> s >> k;
vector<long long> v(200), v1(200);
v[0] = 1, v1[0] = 1;
i = 1;
for (; v[i - 1] <= s; i++) {
if (i - k - 1 >= 0)
v[i] = v1[i - 1] - v1[i - k - 1];
else
v[i] = v1[i - 1];
v1[i] = v1[i - 1... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long scal(pair<int, int> a, pair<int, int> b) {
return (long long)a.first * (long long)a.second +
(long long)b.first * (long long)b.second;
}
long long mul(pair<int, int> a, pair<int, int> b) {
return (long long)a.first * (long long)b.second -
(lo... | 27 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, k, w, i, ans;
cin >> n >> k;
for (i = k - 1; i >= 1; i--) {
if (n % i == 0) {
w = i;
n = n / i;
break;
}
}
ans = w + n * k;
cout << ans;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
inline int gi() {
int data = 0, m = 1;
char ch = 0;
while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
if (ch == '-') {
m = 0;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
data = (data << 1) + (data << 3) + (ch ^ 48);
ch = getchar(... | 25 |
#include <bits/stdc++.h>
using namespace std;
int main() {
unsigned long long n;
cin >> n;
n++;
if (n == 1) {
cout << "0";
return 0;
}
if (n % 2) {
cout << n;
} else {
cout << n / 2;
}
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
bool can[105][105];
char ch;
int n;
cin >> n;
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j) {
cin >> ch;
can[i][j] = (ch == 'E' ? false : true);
}
bool r = false, c = false;
for (int i = 0; i < n; ++i)
for (int j ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int BLOCK = 301;
const int CNT = (100010 + BLOCK - 1) / BLOCK;
const int n = CNT * BLOCK;
const int N = n + 10;
inline void upd(int &a, int b) { a = ((a == 0 || b == 0) ? a + b : min(a, b)); }
int a[2][N];
int b[2][CNT];
bool zeros[2][CNT];
vector<int> c[2][CNT];
int ... | 23 |
#include <bits/stdc++.h>
using namespace std;
const int dx[] = {0, -1, 0, 1, -1, 1, 1, -1};
const int dy[] = {1, 0, -1, 0, 1, 1, -1, -1};
const double EPS = 1e-9;
const long double PI = 3.1415926535897932384L;
const long long int INF = 9223372036854775807;
const int MOD = 1000000000 + 7;
const int MAX = 10000000 + 7;
v... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int c = 5002;
int n, m, maxi, dp[c][c];
string a, b;
int main() {
cin >> n >> m >> a >> b;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
dp[i][j] = max({dp[i - 1][j] - 1, dp[i][j - 1] - 1, 0});
if (a[i - 1] == b[j - 1]) dp[i][j] = m... | 10 |
#include <bits/stdc++.h>
int main() {
int n, a, b, c, countx = 0;
scanf("%d %d %d %d", &n, &a, &b, &c);
for (int i = 0; i <= c; i++)
for (int j = 0; j <= b; j++)
if (2 * (n - 2 * i - j) <= a && 2 * (n - 2 * i - j) >= 0) countx++;
printf("%d", countx);
}
| 7 |
#include <bits/stdc++.h>
const int maxn = 20000 + 3;
const int INF = 0x3f3f3f3f;
inline int getint() {
bool flag = 0;
register int n = 0;
register char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') flag = 1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
n = ch - '0' + (n << ... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
long long n, i;
string str, a;
cin >> n >> a >> str;
for (i = 0; i < str.length(); i++) {
if (str[i] == 'w') break;
}
if (i == str.length()) {
if (n <= 29)
cout << "12\n";
else if (n == 30)
cou... | 1 |
#include <bits/stdc++.h>
using namespace std;
int N, K;
int dp[405][405];
int fr[405];
vector<pair<int, int> > took[405][405];
vector<pair<int, int> > adj[405];
int sz[405];
void DFS1(int u, int p) {
sz[u] = 1;
for (pair<int, int> v : adj[u]) {
if (v.first == p) continue;
DFS1(v.first, u);
fr[v.first] =... | 14 |
#include <bits/stdc++.h>
using namespace std;
template <typename T1>
void print_list(const T1& a) {
cerr << a << endl;
}
template <typename T1, typename T2>
void print_list(const T1& a, const T2& b) {
cerr << a << " " << b << endl;
}
template <typename T1, typename T2, typename T3>
void print_list(const T1& a, cons... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<int> A(n);
for (long long int i = 0; i < n; i++) {
cin >> A[i];
}
multiset<pair<int, int>> dp;
int prev = 20;
dp.insert({A[0] + 89, 50});
dp.insert({A... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000001;
const long double EPS = 1e-9;
const int MOD = 1000000007;
const long long LLINF = 1000000000000000001;
const int maxn = 400000;
const int maxb = 40;
long long dp[maxn][maxb];
long long v[maxn];
int n;
int main() {
cin >> n;
for (int i = 1; i ... | 16 |
#include <bits/stdc++.h>
using namespace std;
int GET_INT() {
int ret;
scanf("%d", &ret);
return ret;
}
int f[100005];
int nodes, edges;
bool seen[100005];
vector<int> adj[100005], adj_inv[100005];
bool isPure[100005];
bool interesting[100005];
void dfs_inv(int u) {
isPure[u] = 1;
seen[u] = 1;
if (f[u] != 1... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long a[200010], n, trakm[200010], sum;
vector<long long> v;
bool chck(long long x) {
long long pos, tmp, tmp2 = 1e9, xx = x;
if (x > sum) return 0;
while (1) {
pos = upper_bound(a + 1, a + n + 1, x) - a - 1;
if (pos == 0 || pos >= tmp2) {
return x =... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1100;
const long long mod = 1e9 + 7;
const double eps = 1e-9;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
const int inf = 0x3f3f3f3f;
int hsort[maxn][maxn], hnum[maxn];
int ls... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 205;
int N, M;
bool degree[MAXN], visited[MAXN * MAXN];
struct Edge {
Edge() {}
Edge(int end, int id) : end(end), id(id) {}
int end, id;
};
vector<Edge> eList[MAXN];
int firstEdgeId[MAXN];
void DFS(int x) {
int s = eList[x].size();
for (int &i = f... | 14 |
#include <bits/stdc++.h>
using namespace std;
int dp[2][5001];
int cum[5001];
int A[5001];
int main() {
int n, m, i, j, k;
double x;
scanf("%d%d", &n, &m);
for (i = 1; i <= n; i++) {
scanf("%d%lf", &A[i], &x);
}
int prev = 0, curr = 1;
fill(dp[0], dp[0] + m + 1, 0);
for (i = 1; i <= n; i++) {
cu... | 9 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int d, f, t;
long long c;
} pro[1000010];
long long fo[100010];
bool vis[100010];
long long sum1[1000010];
long long sum2[1000010];
bool cmp(node a, node b) { return a.d < b.d; }
int main() {
int n, m, k;
scanf("%d %d %d", &n, &m, &k);
for (int i = 1... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int oo = (int)1e9;
const double PI = 2 * acos(0.0);
const double eps = 1e-7;
int dx[] = {1, 0, 0, -1, -1, -1, 1, 1};
int dy[] = {0, 1, -1, 1, 1, -1, 1, -1};
const int MOD = 1e9 + 7;
int calc(int r, int n) {
int aa = r, bb = n;
while (r > 0 && n > 0) {
if (r % ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 400000;
vector<pair<int, int> > G[maxn], bccg[maxn];
int low[maxn], disc[maxn], bcc[maxn], vis[maxn], artifact[maxn], t, cnt;
stack<int> bccstack;
void dfs(int u, int p) {
bccstack.push(u);
low[u] = disc[u] = t++;
vis[u]++;
int sz = G[u].size();
i... | 15 |
#include <bits/stdc++.h>
using namespace std;
const long long int Maxn3 = 1e3 + 10;
const long long int Maxn4 = 1e4 + 10;
const long long int Maxn5 = 1e5 + 10;
const long long int Maxn6 = 1e6 + 10;
const long long int Maxn7 = 1e7 + 10;
const long long int Maxn8 = 1e8 + 10;
const long long int Maxn9 = 1e9 + 10;
const lo... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int sz = 50000;
map<long long, long long> vis;
vector<long long> v;
long long sum(long long n) { return (n * (n + 1)) / 2; }
void pre() {
v.push_back(2);
vis[2] = 1;
for (int i = 2; i <= sz; i++) {
long long ans = sum(i) * 2 + sum(i - 1);
vis[ans] = 1;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int oo = 1e9;
template <typename num>
inline num ceil(num a, num b) {
return (a + b - 1) / b;
}
template <typename num>
inline num lcm(num a, num b) {
return a * (b / __gcd(a, b));
}
const int MAXN = 1e5 + 5;
const int K = 10;
int index(ch... | 20 |
#include <bits/stdc++.h>
inline int cmp(double x, double y = 0, double tol = 1e-7) {
return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
}
using namespace std;
inline long long gcd(long long a, long long b) {
return (b ? gcd(b, a % b) : a);
}
inline long long lcm(long long a, long long b) { return (a / gcd(a, b)) *... | 16 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
const long long INF = 1e18 + 1;
using namespace std;
signed main() {
std::ios::sync_with_stdio(false);
long long n, m;
cin >> n >> m;
array<long long, 2> f = {-1, -1}, l;
for (long long i = 0; i < (n); i++) {
for (long long j = (0); j < ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const double inf = 1e20, eps = 1e-9;
char s[100], t[100];
int main() {
scanf("%s%s", s, t);
int first = *t - *s;
int second = s[1] - t[1];
printf("%d\n", max(abs(first), abs(second)));
char cx = first > 0 ? 'R' : 'L';
char cy = second > 0 ? 'D' : 'U';
int dx =... | 2 |
#include <bits/stdc++.h>
using namespace std;
pair<double, double> A[102];
pair<double, double> P;
int i, j, k, t;
double Aux, Ans;
int N;
bool ok;
double det(const pair<double, double> &A, const pair<double, double> &B,
const pair<double, double> &C) {
return (A.first * B.second + B.first * C.second + C.f... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 50;
const int inf = 0x3f3f3f3f;
const int M = 5000 * 4;
int n, m, k;
vector<int> p[MAXN], pf[MAXN];
int a[MAXN];
int dis[MAXN];
int vis[MAXN];
void bfs() {
queue<int> q;
q.push(a[k]);
vis[a[k]] = 1;
while (!q.empty()) {
int x = q.front();
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int INF = int(1e9);
const long long INFll = 1ll * INF * INF;
const int MOD = 1000000007;
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; ++i) cin >> a[i];
int m;
cin >> m;
vector<int> q... | 16 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
int n, k;
char s[1001];
string name[1000];
vector<int> g[1000];
bool used[1000];
string readName() {
string ret;
while (isalpha(s[k])) ret += s[k++];
return ret;
}
vector<int> get() {
if (s[k] == ':') k++;
vector<int> ret... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e3 + 5;
const int INF = -0x3f3f3f3f;
int n, ai[maxn], f[maxn][maxn], g[maxn][maxn][2], dp[maxn][2][2];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &ai[i]);
ai[i]--;
}
memset(g, -0x3f, sizeof(g));
memset(f, -0x... | 10 |
#include <bits/stdc++.h>
using namespace std;
map<pair<long long, long long>, long long> mp;
int main(int argc, char** argv) {
int q;
cin >> q;
while (q--) {
long long t, v, u, w;
cin >> t;
if (t == 1) {
cin >> v >> u >> w;
long long d1 = 0;
long long d2 = 0;
long long x = 1;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
bool cmp(char a, char b) { return a < b; }
int main() {
char s[114514], ans[114514];
gets(s);
gets(ans);
if (strlen(s) != strlen(ans)) {
cout << "WRONG_ANSWER";
return 0;
}
long long len;
len = strlen(s);
sort(s, s + len, cmp);
for (int i = 0; i < ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
long long int a[n + 1];
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
long long int up[n + 1];
for (int i = 1; i <= n; i++) {
up[i] = 0;
}
vector<pair<long long int, long long int> > v;
int q;
cin >> q;
for (int ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6;
long long n, m, k, a[MAXN];
inline long long cal_page(long long num) {
if (num % k == 0)
return num / k;
else
return num / k + 1;
}
int main() {
long long flag = 0, num = 0, book = 0;
cin >> n >> m >> k;
for (int i = 1; i <= m; i++) c... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;
int main() {
int n, m;
cin >> n >> m;
string s;
cin >> s;
vector<vector<vector<int>>> sums(n + 10,
vector<vector<int>>(3, vector<int>(3, 0)));
for (int i = 0; i < n; i++) {
for (int j = 0; j < 3;... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
int sum = 6 + 10 + 14;
int a = 6;
int b = 10;
int c = 14;
while (t--) {
int num;
cin >> num;
if (num > sum) {
int temp = num - sum;
if (temp == a || temp == b || temp == c) {
temp = temp - 1;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
long a[1000005];
int main() {
long n, i, j, k = 0;
char ch;
scanf("%ld", &n);
long ctr = 0, echr = 0, x;
while (n--) {
scanf(" %c", &ch);
scanf("%ld", &x);
if (ch == '+') {
if (a[x] <= 0) {
if (echr == 0)
ctr++;
else
... | 5 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
const int MAXN = 102;
int n, arr[MAXN];
vector<int> newone;
int solve(int f, int s) {
newone.clear();
for (int i = (int)0; i < (int)n; ++i) {
if (i == f || i == s) continue;
newone.push_back(arr[i]);
}
int ans... | 7 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
int main() {
int n, m, k;
scanf("%d%d%d", &n, &m, &k);
vector<int> color(n);
vector<vector<int> > cpos(m + 1);
vector<int> apos(m + 1, 0);
vector<int> bpos(m + 1, 0);
for (int i = 0; i < (int)(n); ++i) {
int c;
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
vector<long long> v;
map<long long, long long> m;
long long a[n];
for (long long i = 0; i < n; i++) {
cin >> a[i];
m[a[i]]++;
if (m[a[i]] == 2) v.push_ba... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long int N = 3e5 + 100;
long long int n, k, d[N], e[N], dp[N], m = 0;
vector<long long int> v;
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n >> k;
for (int i = 2; i <= n; i++) d[i]++;
for (int i = 2; i <= n; i++) {
e[i] =... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int n;
cin >> n;
map<int, int> c;
int ans = 0;
for (int i = 0, v; i < n; ++i) {
cin >> v;
++c[v];
}
int t;
t = min(c[1], c[2]);
c[1] -= t, c[2] -= t;
c[3] += t;
ans += t;
if (c[2] == 0 && c[1] == 0) {
cout << ans;
ret... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int N = (int)2e5 + 3;
const int INF = 1e9 + 7;
int n, k, used[N], a[N], used2[N];
int main() {
scanf("%d %d", &n, &k);
for (int i = 1; i <= k; ++i) {
scanf("%d", a + i);
used2[a[i]] = 1;
}
for (int i = 1; i <= k; ++i) {
for (int j = 1; j <= n; ++j)... | 1 |
#include <bits/stdc++.h>
using namespace std;
char a[55][55];
long long dp[55][55][55][55];
long long n;
long long solve(long long x1, long long x2, long long y1, long long y2) {
if (x1 > x2 || y1 > y2 || x1 > n || y1 > n) return 0;
long long temp = 1;
long long ans = dp[x1][x2][y1][y2];
if (ans != -1) return d... | 15 |
#include <bits/stdc++.h>
using namespace std;
long long fast_pow(long long x, long long y, long long p);
map<long long, vector<pair<long long, long long>>> save;
class Node {
public:
long long a, b, profit;
};
Node node[5001];
long long dp[5001][5001];
long long n;
long long rec(long long pos, long long k) {
if (p... | 13 |
#include <bits/stdc++.h>
using namespace std;
long double EPS = 0.000000001;
int di[] = {0, 1, 0, -1};
int dj[] = {1, 0, -1, 0};
int sum(int n) { return (n * (n + 1)) / 2; }
int main() {
int n, m;
cin >> n >> m;
vector<int> v(m);
priority_queue<int> q;
for (int i = 0; i < m; i++) {
cin >> v[i];
q.push... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 55;
int main() {
int t, n, a[N];
cin >> t;
while (t--) {
cin >> n;
int i;
memset(a, 0, sizeof(a));
for (i = 1; i <= n; i++) cin >> a[i];
sort(a + 1, a + n + 1);
int min1 = a[1];
int max1 = a[n];
if (n == 1) {
cout <<... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d;
scanf("%d%d%d%d", &a, &b, &c, &d);
int ans = 0;
ans += (abs(a - c) + 1 + abs(b - d) + 1);
ans *= 2;
if (a == c) ans += 2;
if (b == d) ans += 2;
printf("%d\n", ans);
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, ss;
int i, a = 0, b = 0, c = 0;
cin >> s;
s[s.size()] = 'c';
for (i = 0; i < s.size(); i++) {
if (s[i] == 'a') {
if (s[i + 1] == 'c') {
cout << "NO";
return 0;
} else
a++;
} else if (s[i] == 'b') {... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n, k;
cin >> n >> k;
vector<int> a(2 * n + 2, 0);
for (int i = 1; i <= (2 * n + 1); i++) cin >> a[i];
for (int i = 2; i <= (2 * n + 1); i += 2) {
if (!k) break;
if (a[i] - 1 > a[i - 1] && a[i... | 3 |
#include <bits/stdc++.h>
using namespace std;
void ga(int N, int *A) {
for (int i(0); i < N; i++) scanf("%d", A + i);
}
struct EG {
int a, b, w, p;
void gt() { scanf("%d%d%d%d", &a, &b, &w, &p); }
} E[(200009)];
struct st {
int C, I;
bool operator<(const st &r) const { return C > r.C; }
};
int C[(200009)];
pr... | 18 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const long long m = 998244353;
long long int power(long long int x, long long int y, long long int m) {
if (y == 0) return 1;
long long int p = power(x, y / 2, m) % m;
p = (p * p) % m;
return (y % 2 == 0) ? p : (x * p) % m;
}
long long in... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long n, k;
multiset<long long> mp;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> k;
for (int i = 0; i < n; i++) {
long long el;
cin >> el;
mp.insert(el);
}
long long cur = 0;
deque<long long> ar;
long long... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MX = 1e5 + 22;
vector<vector<int> > G(MX);
int N;
int arr[MX];
int M;
int ni[MX];
int vis[MX];
int ans[MX];
int dfs(int x, int j) {
vis[x] = 1;
int res = 1;
ans[x] = j;
for (int i = 0; i < G[x].size(); i++) {
int ch = G[x][i];
ni[ch]++;
}
for (... | 10 |
#include <bits/stdc++.h>
constexpr int N = 100005;
using namespace std;
int n, m, a[N], b[N];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d%d", &a[i], &b[i]);
}
sort(a + 1, a + 1 + n);
sort(b + 1, b + 1 + n);
long long ans = n;
for (int i = n; i >= 1; --i) {
ans += max(a[i... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long double EPS = 1e-8;
const long double PI = acos(-1.0L);
const int MAXN = 1e5;
int main() {
map<string, int> numd = {{"monday", 0}, {"tuesday", 1}, {"wednesday", 2},
{"thursday", 3}, {"friday", 4}, {"saturday", 5... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
string ans = "";
vector<string> v;
string func(string s) {
int cnt = 0;
for (int i = (int)s.size() - 1; i >= 0; i--)
if (s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' ||
s[i] == 'u') {
++cnt;
if (cnt == k) return s.substr(i);... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<int> A(n);
for (int i = 0; i < n; i++) {
cin >> A[i];
}
int sum = 0;
for (auto x : A) {
sum += x;
}
int even = 0, odd = 0;
for (auto x : A) {
if... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long n, a, b, x;
long long bin(int v) {
long long l = 1, r = v, mid, ans = 0, res = 0, t;
while (l <= r) {
mid = (l + r) / 2;
if (mid * a / b > ans) {
ans = mid * a / b;
t = ans * b;
t = ceil((t + 0.0) / a);
res = t;
}
l = mi... | 7 |
#include <bits/stdc++.h>
const int N = 100005;
int n, cnt, last[N * 2], w[N * 2], tot, t[N * 2], deg[N * 2];
struct data {
int l, r;
} a[N];
struct edge {
int to, next, use;
} e[N * 10];
void addedge(int u, int v) {
deg[u]++;
deg[v]++;
e[++cnt].to = v;
e[cnt].next = last[u];
last[u] = cnt;
e[++cnt].to =... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
long long answ = (n - 2) * (n - 2);
cout << answ;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
int d[maxn][2];
int c[maxn][maxn];
int used[maxn];
int main() {
int n, m, s, t;
scanf("%d%d%d%d", &n, &m, &s, &t);
memset(c, inf, sizeof(c));
memset(d, inf, sizeof(d));
memset(used, 0, siz... | 8 |
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ii = pair<int, int>;
using vii = vector<ii>;
using l = long long;
using vl = vector<l>;
using vvl = vector<vl>;
using ll = pair<l, l>;
using vll = vector<ll>;
using vvll = vector<vll>;
using lu = unsigned long long;
usin... | 16 |
#include <bits/stdc++.h>
void err() { std::cout << '\n'; }
template <typename T, typename... Args>
void err(T a, Args... args) {
std::cout << a << ' ';
err(args...);
}
void pt() { std::cout << '\n'; }
template <typename T, typename... Args>
void pt(T a, Args... args) {
std::cout << a << ' ';
pt(args...);
}
usin... | 16 |
#include <bits/stdc++.h>
using namespace std;
int n, m, par[100005 * 10], w[100005 * 10], ta, qs;
pair<int, int> x[100005 * 10], y[100005 * 10];
pair<pair<int, int>, pair<int, int> > q[100005 * 20];
int find(int a) {
if (par[a] == a) return a;
return par[a] = find(par[a]);
}
int main() {
scanf("%d%d", &n, &m);
... | 14 |
#include <bits/stdc++.h>
using namespace std;
struct po {
double t, p, x, y;
};
int cmp(po p1, po p2) {
if (p1.t != p2.t) return p1.t < p2.t;
return p1.p < p2.p;
}
po p[1000];
int n;
double maxp;
double sqr(double a) { return a * a; }
double len(po p1, po p2) { return sqrt(sqr(p1.x - p2.x) + sqr(p1.y - p2.y)); }
... | 10 |
#include <bits/stdc++.h>
using namespace std;
int answer, users, n, m, t, i, FreeID, hours, minutes, seconds;
bool completed;
pair<int, pair<int, int> > events[300000];
int id[300000];
int c[300000];
void work() {
scanf("%d%d%d", &n, &m, &t);
for (i = (1); i <= (n); i++) {
char u;
scanf("%d%c%d%c%d", &hours... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long int arr[1000100];
long long int pow2[1000100];
long long int mul[1000100];
const long long int M = 998244353;
long long int expo(long long int x, long long int y) {
long long int res = 1;
x = x % M;
while (y > 0) {
if (y & 1) res = (res * x) % M;
y =... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5;
int a[maxn + 5];
long long sum[maxn + 5], b[maxn + 5];
double c[maxn + 5];
int main() {
int type, x, q, num = 0;
double max1 = 0;
scanf("%d", &q);
while (q--) {
scanf("%d", &type);
if (type == 1) {
scanf("%d", &x);
num++;
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const int maxn = 1e6 + 10;
const int inf = 0x3f3f3f3f;
int n, m;
int dp[maxn][3][3];
int sum[maxn];
int main() {
while (~scanf("%d %d", &n, &m)) {
memset(sum, 0, sizeof sum);
for (int i = 0; i < n; i++) {
int x;
scanf("%d"... | 14 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 2 * 1e5 + 100;
long long n, a[N], b[N], dg[N], ans, vi[N];
vector<long long> p, e[N];
void dfs(long long x) {
for (long long i = 0; i < (long long)e[x].size(); i++) {
long long u = e[x][i];
dfs(u);
}
for (long long i = 0; i < (long long)e[x... | 12 |
#include <bits/stdc++.h>
using namespace std;
struct point {
double x, y;
double dist(point t) {
return sqrt((x - t.x) * (x - t.x) + (y - t.y) * (y - t.y));
}
};
int main() {
int n, m, ma = 9999999, mi = -1;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int k, f;
cin >> k >> f;
if (k % f != 0... | 7 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimization("unroll-loops")
std::pair<int, int> DR[] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1},
{-1, 1}, {-1, -1}, {1, 1}, {1, -1}};
using namespace std;
template <class c>
struct rge {
c b, e;
};
template <class c>
rge<c> ran... | 14 |
#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-6;
const int INF = (int)(INT_MAX - 100);
const long long mod = (int)(1e+9 + 7);
const int N = (int)(0);
int main() {
int n, k;
cin >> n >> k;
vector<int> v(n);
for (int i = 0; i < n; i++) scanf("%d", &v[i]);
long long x = sqrt(1.0 * (2LL... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long a[202020], k = 1, ans, mod = 1e9 + 7;
long long quick_power(long long a, long long b = mod - 2) {
long long s = 1;
for (; b; b >>= 1, a = a * a % mod)
if (b & 1) s = s * a % mod;
return s;
}
int main() {
int i, n;
scanf("%d", &n);
for (i = 1; i <= ... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n;
vector<int> v1(n);
for (int i = 0, a; i < n; i++) cin >> v1[i];
cin >> m;
vector<int> v2(m);
for (int i = 0, a; i < m; i++) cin >> v2[i];
sort(v1.begin(), v1.end());
sort(v2.begin(), v2.end());
cout << v1[v1.size() - 1] <... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n = 0;
cin >> n;
map<string, pair<int, int>> mp;
vector<pair<string, pair<int, int>>> log;
map<string, int> names;
for (int i = 0; i < n; ++i) {
string name;
cin >> name;
int score = 0;
cin >> score;
auto it = mp.find(name);
... | 7 |
#include <bits/stdc++.h>
using namespace std;
#define fast() \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define ll long long int
#define pb push_back
#define mp make_pair
#define pf push_front
#define rep(i, a, b, k) for (ll i = a; i < b;... | 5 |
#include <bits/stdc++.h>
using namespace std;
char a[1000];
int main() {
int n;
cin >> n;
int cnt1 = 0, cnt2 = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
cnt1 += (a[i] == 'X');
}
cout << abs(n / 2 - cnt1) << endl;
if (n / 2 - cnt1 < 0) {
for (int i = 0; i < n; i++) {
if (cnt1 > n / 2 ... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long read() {
long long x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
return x * f;
}
const int maxn = 60;
const ... | 19 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0;
char c = 0;
while (c < '0' || c > '9') c = getchar();
while ('0' <= c && c <= '9') x = 10 * x + c - '0', c = getchar();
return x;
}
const int N = 4003;
int n, k, sum[N][N];
int dp[N], cnt[N];
int stk[N], dex[N];
int hd, tl;
inline in... | 18 |
#include <bits/stdc++.h>
using namespace std;
struct union_find {
vector<int> parent;
vector<int> size;
int components = 0;
union_find(int n = -1) {
if (n >= 0) init(n);
}
void init(int n) {
parent.resize(n + 1);
size.assign(n + 1, 1);
components = n;
for (int i = 0; i <= n; i++) parent[... | 20 |
#include <bits/stdc++.h>
using namespace std;
template <class t, class u>
void chmax(t &first, u second) {
if (first < second) first = second;
}
template <class t, class u>
void chmin(t &first, u second) {
if (second < first) first = second;
}
struct item {
int index;
int cost;
};
vector<item> stools, pencils;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T _sq(T a) {
return a * a;
}
template <class T>
inline T _sqrt(T a) {
return (T)sqrt((double)a);
}
template <class T, class X>
inline T _pow(T a, X y) {
T z = 1;
for (int i = 1; i <= y; i++) {
z *= a;
}
return z;
}
template <class T... | 12 |
#include <bits/stdc++.h>
using namespace std;
namespace INPUT {
const int L = 1 << 15;
char _buf[L], *S, *T, c;
char _gc() {
if (S == T) {
T = (S = _buf) + fread(_buf, 1, L, stdin);
if (S == T) return EOF;
}
return *S++;
}
void readi(int &X) {
for (c = _gc(); c < '0' || c > '9'; c = _gc())
;
X = c... | 16 |
#include <bits/stdc++.h>
using namespace std;
long long D[13333350 * 2];
int n, x, y;
int main() {
scanf("%d%d%d", &n, &x, &y);
memset(D, 63, sizeof(D));
D[0] = 0;
D[1] = x;
int i = 1;
while (i < 13333350) {
D[i + i] = min(D[i + i], D[i] + y);
D[i + 1] = min(D[i + 1], D[i] + x);
if (D[i] + x < D... | 12 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
int main() {
int n, m, x, y, z, p;
cin >> n >> m >> x >> y >> z >> p;
x %= 4;
y %= 2;
z %= 4;
for (int i = 1; i <= p; i++) {
int r, c;
scanf("%d%d", &r, &c);
int nn = n, mm = m;
for (int nima ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1e3 + 10;
const int maxm = 5e5 + 10;
const long long INF = 1e18;
long long powmod(long long x, long long y) {
long long t;
for (t = 1; y; y >>= 1, x = x * x % mod)
if (y & 1) t = t * x % mod;
return t;
}
long long gcd(long... | 8 |
#include <bits/stdc++.h>
long long a[100009];
void inti() {
a[1] = 2;
for (long long i = 2; i <= 100000; i++) {
a[i] = i * (i + 1) * (i + 1) - i + 1;
}
}
int main() {
inti();
int n;
while (scanf("%d", &n) != EOF) {
for (int i = 1; i <= n; i++) {
printf("%lld\n", a[i]);
}
}
return 0;
}
| 8 |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")
using namespace std;
const int N = 5e5 + 7, inf = 1e9 + 7, mod = 1e9 + 7;
const long long linf = (long long)1e18 + 7;
const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, i, max = 0, mx = 0, j, sum = 0, d, m;
vector<pair<int, int> > a;
vector<pair<int, int> >::iterator it;
cin >> n;
for (i = 0; i < n; i++) {
cin >> m;
max = 0;
for (j = 0; j < m; j++) {
cin >> d;
if (max < d) max... | 5 |
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cstring>
using namespace std;
const int N = 4e3 + 10;
int g[N][6];
int n, m, k;
int l[N], r[N];
int get(int l, int r, int ll, int rr) {
return max(0, min(rr, r) - max(ll, l) + 1);
}
int main() {
scanf("%d %d %d", &n, &m, &k);
for (int i = 1;... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base ::sync_with_stdio(false);
int n, m;
int r1_min = INT_MAX, l1_max = -INT_MAX;
int r2_min = INT_MAX, l2_max = -INT_MAX;
cin >> n;
int l1[n], r1[n];
for (int i = 0; i < n; i++) {
cin >> l1[i] >> r1[i];
l1_max = max(l1[i], l1_max);
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int t = 0;
cin >> t;
for (int i = 0; i < t; ++i) {
int n = 0, cnt = 0;
bool flag = false;
cin >> n;
int arr[n], lim = n * (n - 1) / 2 - 1;
for (int j = 0; j < n; ++j) cin >> arr[j];
for (int j = 1; j ... | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.