solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
long long n, m, a[300005], b[300005], sum;
int main() {
cin >> n;
sum = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
sort(a, a + n);
cin >> m;
for (int i = 0; i < m; i++) {
int h;
cin >> h;
b[i] = sum - a[n - h];
}
for (... | 1 |
#include <bits/stdc++.h>
using namespace std;
namespace debug {
void err() { cout << endl; }
template <template <typename...> class T, typename t, typename... Args>
void err(T<t> a, Args... args) {
for (auto x : a) cout << x << ' ';
err(args...);
}
template <typename T, typename... Args>
void err(T a, Args... args)... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int x;
vector<int> a, b, c;
for (int i = 1; i <= n; i++) {
cin >> x;
if (x == 1)
a.push_back(i);
else if (x == 2)
b.push_back(i);
else
c.push_back(i);
}
int m = min(min(a.size(), b.size()), c.size... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
vector<long long> in;
cin >> n;
long long i, x, paid = 0, energy = 0;
in.push_back(0);
for (i = 0; i < n; i++) {
cin >> x;
in.push_back(x);
}
if (n == 1) {
cout << x << endl;
return 0;
}
for (i = 0; i < n; i++) {... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long expo_pow(long long x, long long y) {
if (y == 0) return 1;
y = y % (mod - 1);
x %= mod;
if (y == 0) y = mod - 1;
long long res = 1;
while (y) {
if (y & 1) res = (res * x) % mod;
x = (x * x) % mod;
y >>= 1;
}... | 0 |
#include <bits/stdc++.h>
const long long p = 7340033;
template <class t>
inline void read(t &s) {
s = 0;
register long long f = 1;
register char c = getchar();
while (!isdigit(c)) {
if (c == '-') f = -1;
c = getchar();
}
while (isdigit(c)) s = (s << 3) + (s << 1) + (c ^ 48), c = getchar();
s *= f;... | 15 |
#include <bits/stdc++.h>
using namespace std;
char s[100010];
char ss[100010];
int x[33];
int g[33];
int main() {
cin >> s >> ss;
int h = strlen(s);
int p = strlen(ss);
memset(x, 0, sizeof(x));
memset(g, 0, sizeof(g));
for (int i = 0; i < h; i++)
if (s[i] == '?') s[i] = 'z' + 1;
for (int i = 0; i < p;... | 7 |
#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<pair<int, int>> a(n);
int edge = 0;
for (auto& i : a) {
cin >> i.first >> i.second;
edge += i.first;
}
assert(edge % 2 == 0);
edge /= 2;
assert(edge <... | 7 |
#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
vector<int> vec;
int check(int x) {
int ret = 0;
int last = 0;
while (true) {
int tmp =
(int)(lower_bound(vec.begin() + last, vec.end(), x) - vec.begin());
if (tmp == vec.size())
break;
else
ret += x;
last = tmp + ... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 100000000LL;
const long double EPS = 1e-9;
bool done[3009];
int used[3009];
struct Edge {
int from, to, next;
long long cap, flow;
long long cost;
Edge(int from, int to, int next, long long cap, long long cost) {
this->from = from;
this... | 15 |
#include <bits/stdc++.h>
using ll = long long int;
using namespace std;
string g = "aabb";
void solve() {
ll x, y, n;
cin >> x >> y >> n;
ll cnt = 0;
for (ll i = 0; i <= x; i++) {
for (ll j = 0; j <= y; j++) {
if ((i + j) == n) cnt++;
}
}
cout << cnt << "\n";
}
int main() {
int t = 1;
whil... | 3 |
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
void solve(std::istream& in, std::ostream& out) {
int n;
in >> n;
if (n <= 2) {
out << "-1\n";
return;
}
out << "10\n15\n";
n -= 2;
for (int i = 6; n > 0; i += 6) {
if (i % 5) {
out << i << "\... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
vector<vector<pair<long long, int> > > v(N), g(N);
long long inf = (long long)1e18;
int n, m;
int st, en;
long long dis[N][N];
int t[N], c[N];
void dijkstra(int src, bool flag) {
set<pair<long long, int> > pq;
pq.insert({0, src});
for (int i = 1... | 11 |
#include <bits/stdc++.h>
using namespace std;
inline void inp(int &n) {
n = 0;
int ch = getchar();
int sign = 1;
while (ch < '0' || ch > '9') {
if (ch == '-') sign = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
n = (n << 3) + (n << 1) + ch - '0', ch = getchar();
n = n * sign;
}
const i... | 12 |
#include<bits/stdc++.h>
using namespace std;
int main () {
ios::sync_with_stdio(0);
cin.tie(0);
long long t = 1;
cin >> t;
while (t--) {
long long n, k;
cin >> n >> k;
vector<pair<long long, long long>> a;
vector<long long> t(k);
vector<long long> ans(n, -1)... | 7 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
char s[99];
int n;
int main() {
scanf("%d", &n);
scanf("%s", s);
int cnt = 0;
for (int i = 0; s[i]; ++i) {
if (s[i] == '0') {
printf("%d", cnt);
cnt = 0;
} else
cnt++;
}
printf("%d", cnt);
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[1000009];
int ans;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
sort(a, a + n);
n = unique(a, a + n) - a;
ans = 0;
for (int i = n - 1; i >= 0; i--) {
int j = 2;
while (1) {
int k = a[i] / j + 1;
i... | 13 |
#include <bits/stdc++.h>
using namespace std;
inline int _sread(char *s) {
char c = getchar();
int len = 0;
for (; !(c >= 'a' && c <= 'z'); c = getchar())
;
for (; c >= 'a' && c <= 'z'; s[++len] = c, c = getchar())
;
s[++len] = 0;
return len - 1;
}
const int P = 1e9 + 7;
const int N = 2005;
inline v... | 24 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
if (n <= 4) {
if (n == 2) {
printf("1");
}
if (n == 3) {
printf("3");
}
if (n == 4) {
printf("6");
}
return 0;
}
int x = n;
int digit = 0;
while (x >= 10) {
x /= 10;
dig... | 10 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
using min_queue = priority_queue<T, vector<T>, greater<T>>;
const int MOD = 1000000007;
const int MOD2 = 1000000009;
const int INF = 0x3f3f3f3f;
const long long BINF = 0x3f3f3f3f3f3f3f3fLL;
int n, a[200005], b[200005], p[200005], pp[200005];
int solve() {... | 5 |
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:33554432")
using namespace std;
int IT_MAX = 1 << 18;
const long long MOD = 1000000009;
const int INF = 0x3f3f3f3f;
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const double ERR = 1e-10;
int in[2550][2];... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const int INF2 = 0x3f3f3f3f;
const long long INF64 = 1e18;
const double INFD = 1e30;
const double EPS = 1e-6;
const double PI = acos(-1);
const int MOD = 998244353;
template <typename T>
inline T read() {
T X = 0, w = 0;
char ch = 0;
while ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n, m, a, b;
vector<vector<int> > g;
vector<bool> used;
vector<int> c;
set<pair<int, int> > d;
int main() {
cin >> n >> m;
g.resize(n);
used.resize(n);
for (int i = (0); i < (m); i++) {
cin >> a >> b;
a--;
b--;
g[a].push_back(b);
g[b].push_bac... | 9 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, w = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') w = -1;
c = getchar();
}
while (c <= '9' && c >= '0') {
x = (x << 1) + (x << 3) + c - '0';
c = getchar();
}
return w == 1 ? x : -x;
}
int n, m,... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
if (a > b)
cout << "First" << endl;
else
cout << "Second" << endl;
return 0;
}
| 0 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:133217728")
using namespace std;
long long res[555][555];
long long MOD;
long long cnt(long long n) { return n * (n - 1) / 2; }
long long go(int a, int b) {
if (!a && !b) return 1;
if (res[a][b] != -1) return res[a][b];
long long t = 0;
if (a > 1) t += cn... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 10;
int main() {
int f = 0;
string s, ss, ans;
cin >> s >> ss;
ans = "";
int len = s.length();
for (int i = 0; i < len; i++) {
if (s[i] == ss[i]) {
ans += '1';
} else {
ans += (f == 1 ? s[i] : ss[i]);
f = f == 0 ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 50;
int a[N];
vector<int> adj[N];
vector<int> child[N];
long long sum[N];
long long mx[N];
long long ans = LLONG_MIN;
void dfs1(int cur, int par) {
long long summ = a[cur];
bool leaf = true;
for (auto nxt : adj[cur]) {
if (nxt == par) {
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int MODA = 1000003;
inline void print(char pt) { printf("%c\n", pt); }
inline void print(int pt) { printf("%d ", pt); }
inline void print(long long pt) { printf("%I64d\n", pt); }
inline void print(double pt) { printf("%.20f\n", pt); }
inline void print(char pt[]) { pr... | 11 |
#include <bits/stdc++.h>
int x4[4] = {0, 0, -1, 1};
int y4[4] = {-1, 1, 0, 0};
int x8[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
int y8[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
int xhorse[8] = {1, 2, 1, 2, -1, -2, -1, -2};
int yhorse[8] = {2, 1, -2, -1, 2, 1, -2, -1};
using namespace std;
int ans = 0;
int k, a, b, v;
int main() {
sc... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int n, k, h[200003], nw[200003];
long long f[200003], inv[200003];
long long mypow(long long x, long long times) {
if (x == 0) return times == 0;
if (times == 0) return 1;
long long ret = mypow(x, times / 2);
ret = ret * ret % mod;
if (t... | 14 |
#include <bits/stdc++.h>
using namespace std;
using cd = complex<double>;
const long long INF = 1e18;
const long long mod = 998244353;
const double Pi = acos(-1);
void Fastio() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
int n, m;
int Vis[505], par[505];
vector<int> Adj[505];
vector<int> Cyc;
b... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long int a[5010], fv[510], joy[20], dp[5010][510], c[100010], fvc[100010];
set<long long int> s;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long int n, k, x;
cin >> n >> k;
long long int nk = n * k;
memset(c, 0, sizeof c);
m... | 12 |
#include <bits/stdc++.h>
using namespace std;
void fun() {}
long long int __gcd(long long int a, long long int b) {
if (b == 0)
return a;
else
return __gcd(b, a % b);
}
void dfs(int par, int vis[], vector<int> g[]) {
for (int i = 0; i < g[par].size(); i++) {
int child = g[par][i];
if (!vis[child])... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, m, tx, ty = 0;
int main() {
cin >> n >> m;
for (int i = 1; i <= n / 2; ++i) {
for (int j = 1; j <= m; ++j) {
printf("%d %d\n", i, j);
printf("%d %d\n", n - i + 1, m - j + 1);
}
}
if (n & 1) {
for (int i = 1; i <= m / 2; ++i) {
pr... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main(int, char**) {
string str;
cin >> str;
vector<int> data;
for (auto c : str) {
if (c >= '0' && c <= '9') {
data.push_back(int(c - '0'));
} else if (c >= 'A' && c <= 'Z') {
data.push_back(int(c - 'A') + 10);
} else if (c >= 'a' && c <=... | 7 |
#include <bits/stdc++.h>
const int N = 10007, inf = 0x3f3f3f3f;
using namespace std;
struct evt {
int p, x, id;
};
evt eventos[N + N];
unsigned char ans[N];
int cmp(evt a, evt b) {
if (a.p == b.p) {
if (a.x < 0 and b.x > 0) return 1;
if (b.x < 0 and a.x > 0) return 1;
return 0;
}
return a.p < b.p;
}... | 14 |
#include <bits/stdc++.h>
using namespace std;
int a[60][60], b[60][60];
int n, m;
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) scanf("%d", &a[i][j]);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) scanf("%d", &b[i][j]);
for (int i = 1; i <= n; ... | 6 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
long long t, n, v;
vector<long long> a, b;
cin >> t;
while (t--) {
a.clear();
b.clear();
cin >> n;
long long mn = 1000000001;
for (long long i = (0); i < (n); i++) {
cin >> v;
a.push_back(v);
if (mn > v) mn = v;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n, i, lim, X = 0;
string str;
cin >> n >> str;
lim = str.size();
for (i = 0; i < lim; i++)
if (str[i] == 'X') X++;
int changes = abs((n / 2) - X);
cout << changes << endl;
char ch1,... | 1 |
#include <bits/stdc++.h>
using namespace std;
char s[55][55];
int cnt[55][55];
int dp[55][55][55][55];
int calc(int x1, int y1, int x2, int y2) {
return cnt[x2][y2] - cnt[x1 - 1][y2] - cnt[x2][y1 - 1] + cnt[x1 - 1][y1 - 1];
}
int dfs(int x1, int y1, int x2, int y2) {
if (calc(x1, y1, x2, y2) == 0) return 0;
int &... | 15 |
#include <bits/stdc++.h>
using namespace std;
int dp[1000005], n, x, a, i, j, k, d[105][105], e[105][105], fre[105];
void mrg() {
int i, j, k, tmp[105][105] = {0};
for (i = 0; i <= 100; i++)
for (j = 0; j <= 100; j++) {
int res = 0;
for (k = 0; k <= 100; k++)
res = (res + 1ll * d[i][k] * d[k... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, digit = 0, tmp, nine = 0, one = 0, i, ones = 1, res = 0;
cin >> n;
tmp = n;
while (tmp) {
digit++;
tmp = tmp / 10;
}
if (digit - 1 > 0) {
for (long long int i = 1; i <= digit - 1; i++) {
nine = nine + 9;
res ... | 4 |
#include <bits/stdc++.h>
const int MV = 9000000;
int vis[MV];
char str[MV];
int f(int x) {
if (x == 0)
return 1;
else if (x == 1)
return 0;
else if (x == 2 || x == 3 || x == 5 || x == 7) {
vis[x]++;
return 0;
} else if (x == 4) {
vis[3]++;
vis[2] += 2;
return 0;
} else if (x == 6) ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n;
int x[1024], y[1024], c[1024];
int pts[1024];
int chull[1024], tp;
int chull_size;
int ans_l[1024], ans_r[1024], ans_len = 0;
void add_edge(int u, int v) {
ans_l[ans_len] = u;
ans_r[ans_len] = v;
ans_len++;
}
void print_ans() {
printf("%d\n", ans_len);
for ... | 24 |
#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long b) {
long long res = 1LL;
while (b > 0) {
if (b & 1) res = (res * a) % 998244353;
b /= 2;
a = ((a % 998244353) * (a % 998244353)) % 998244353;
}
return res % 998244353;
}
long long n, k;
long long ans;
long long arr... | 14 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool chkmax(T &a, T b) {
return a < b ? a = b, 1 : 0;
}
template <typename T>
bool chkmin(T &a, T b) {
return a > b ? a = b, 1 : 0;
}
const int maxn = 2e3 + 5;
const int fx[4] = {0, 1, 0, -1};
const int fy[4] = {1, 0, -1, 0};
int n, k, f[maxn][maxn... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long max(long long a, long long b) {
if (a < b) return b;
return a;
}
long long min(long long a, long long b) {
if (a < b) return a;
return b;
}
struct segmentTree {
vector<long long> v;
vector<long long> mini;
vector<long long> pos;
long long sz;
voi... | 8 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void fast() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
void solve() {
int n, k;
cin >> n >> k;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++) cin >> a[i];
int ans = 0, ind = 0;
int curr = 0;
for (int i = 2; i < k... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 500 + 10;
char a[maxN][maxN];
char b[maxN][maxN];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) cin >> a[i][j];
int mnx = 2e9, mny = 2e9, mxx = -1,... | 6 |
#include <bits/stdc++.h>
int main() {
int n, k, i, f[3000], g[3000], j, key, a, c, time;
scanf("%d %d", &n, &k);
for (i = 1; i <= n; i++) {
scanf("%d", &f[i]);
}
for (j = 2; j <= n; j++) {
key = f[j];
i = j - 1;
while (i > 0 && f[i] > key) {
f[i + 1] = f[i];
i = i - 1;
}
f[... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long int bin(int a, int b) {
if (b == 0) return 1;
long long int x = bin(a, b / 2);
if (b % 2)
return x * x * a;
else
return x * x;
}
int main() {
std::ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
if (n > 3) {
long lon... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if ((a == 0) || (b == 0)) return a + b;
return gcd(b, a % b);
}
long long pow_mod(long long a, long long b) {
long long res = 1;
while (b) {
if (b & 1) res = (res * a) % 1000000007;
a = (a * a) % 1000000007;
b >>... | 12 |
#include <bits/stdc++.h>
using namespace std;
map<long long, long long> ma[25][25];
long long pre[25][25];
long long n, m, k;
long long ans;
void dfs1(long long x, long long y, long long cur) {
if (x > n || y > m) return;
cur ^= pre[x][y];
if (x + y == (n + m + 2) / 2) {
ma[x][y][cur]++;
return;
}
dfs... | 13 |
#include <bits/stdc++.h>
using namespace std;
struct data {
int l, r, id;
};
int n, t, a[200005], res, c[200005 * 10];
long long ans = 0;
data b[200005];
pair<long long, int> kq[200005];
bool comp(data p, data q) {
if (p.l / res != q.l / res) return p.l / res < q.l / res;
return p.r < q.r;
}
bool comp1(pair<long ... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long dp[150000], a[15000], n, tot, x, MOD = 1e9 + 7;
int main() {
scanf("%lld", &n);
memset(dp, 0, sizeof(dp));
for (int i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
if (a[i] == -1) tot++;
}
for (int i = 1; i <= n; i++)
if (a[i] != -1 && a[a[i]] ==... | 12 |
#include <bits/stdc++.h>
using namespace std;
map<int, int> X, Y;
int n, q;
set<int> s;
int main() {
cin >> n >> q;
X[0] = Y[0] = 0;
for (int i = 0; i < q; i++) {
int x, y;
char d;
cin >> x >> y >> d;
if (s.find(x) != s.end())
cout << "0\n";
else {
s.insert(x);
auto a = X.low... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long power(long long x, long long y, long long p) {
long long res = 1;
x = x % p;
if (x == 0) return 0;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x = (x * x)... | 2 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target( \
"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
using namespace std;
const int N = 50005;
const int inf = 1000 * 1000 * 1000;
const int mod = 1000 * 1000 * 1000 + 7;
int t;
int n, k;
int main() {
mt1993... | 9 |
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define io_o() ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fst first
#define scd second
#define endl "\n"
#define mkpair make_pair
#de... | 11 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Matrix = vector<vector<long long>>;
long long constexpr MOD = 1000000007;
long long mod(long long x) { return x % MOD; }
Matrix mul(Matrix& a, Matrix& b, long long n) {
Matrix c = vector<vector<long long>>(n + 1, vector<long long>(n + 1));
fo... | 13 |
#include <bits/stdc++.h>
using namespace std;
const double TL = 2.99999;
const long long MAXN = 1000000;
int main() {
ios::sync_with_stdio(0);
int prime[25] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41,
43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
int i = 0;
int k = 0;
for (lon... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 7340033;
int f[32][1020];
int g[32][1020];
int main() {
int cnt, T;
for (int i = 0; i <= 30; i++) f[i][0] = g[i][0] = 1;
for (int i = 1; i <= 30; i++)
for (int j = 1; j <= 1000; j++) {
for (int k = 0; k < j; k++)
f[i][j] =
... | 15 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T &Min(T &x, const T &y) {
return y < x ? (x = y) : x;
}
template <typename T>
inline T &Max(T &x, const T &y) {
return x < y ? (x = y) : x;
}
inline int read() {
int x = 0, f = 1;
char c = getchar();
for (; !isdigit(c); c = getchar())... | 9 |
#include <bits/stdc++.h>
using namespace std;
char arr[502][502];
int main() {
ios_base::sync_with_stdio(false);
int o = 0, z = 0;
cin >> o >> z;
for (int i = 1; i <= o; i++)
for (int j = 1; j <= z; j++) {
cin >> arr[i][j];
}
for (int i = 1; i <= o; i++)
for (int j = 1; j <= z; j++) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
vector<int> rem[100100];
int main() {
int n, k, m;
scanf("%d %d %d", &n, &k, &m);
for (int i = 0; i < n; i++) {
int num;
scanf("%d", &num);
rem[num % m].push_back(num);
}
for (int i = 0; i < m; i++) {
if (rem[i].size() >= k) {
printf("Yes\n")... | 5 |
#include <bits/stdc++.h>
using namespace std;
queue<int> q;
int a[200010];
int main() {
int n, i, j, k, flag = 1, t;
scanf("%d", &n);
scanf("%d", &a[0]);
for (i = 1; i <= n; i++) {
scanf("%d", &a[i]);
if (a[i] > 1 && a[i - 1] > 1) flag = 0;
}
if (flag == 1) {
printf("perfect\n");
return 0;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<vector<int>> g;
vector<vector<pair<int, int>>> pr;
vector<int> dis;
void f(vector<pair<int, int>>& a, pair<int, int> e) {
a.push_back(e);
sort(a.rbegin(), a.rend());
a.erase(unique(a.begin(), a.end()), a.end());
if ((int)a.size() == 4) {
a.pop_b... | 20 |
#include <bits/stdc++.h>
using namespace std;
long long tree1[1000001], tree2[1000001];
void build(long long l, long long r, long long cur) {
if (l == r) {
tree1[cur] = 0;
tree2[cur] = 0;
return;
}
long long m = (l + r) / 2;
build(l, m, 2 * cur + 1);
build(m + 1, r, 2 * cur + 2);
tree1[cur] = 0;... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 12000;
struct edge {
int a, b, c, f;
};
void ex0() {
cout << "unfair\n";
exit(0);
}
int n, b, q;
int go[MAXN];
int cc[MAXN];
int gg[6];
int was[MAXN * 2];
int s, t;
vector<edge> ed;
vector<int> eds[MAXN * 2];
void make_edge(int a, int b, int c) {
ed... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2005, MAXM = 4e6 + 5;
int n, m, to[MAXM];
char s[MAXN];
inline int getid(int x, int y) { return (x - 1) * m + y; }
int f[MAXM], ans;
bool vis[MAXM], ins[MAXM];
void Dfs(int u) {
if (ins[u]) {
int p = u;
do {
vis[p] = 1;
p = to[p];
... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 10;
int m, k, d[maxn], s[maxn];
int main() {
cin >> m >> k;
int cnt1 = 0, cnt2 = 0, x = 0, time = 0;
for (int i = 1; i <= m; i++) cin >> d[i];
for (int i = 1; i <= m; i++) cin >> s[i];
for (int i = 1; i <= m; i++) {
x = max(x, s[i]);
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n;
const int MODULO = 1000000007;
void solve() {
long long sum1 = 1;
long long sum2 = 1;
for (int i = 0; i < n; i++) {
sum1 *= 27;
sum1 %= MODULO;
sum2 *= 7;
sum2 %= MODULO;
}
sum1 -= sum2;
if (sum1 < 0) {
sum1 += MODULO;
}
cout << su... | 7 |
#include <bits/stdc++.h>
struct val {
long long x;
int y, d;
val *p, *l, *r;
} g1[100001], g2[100001], *rt1[100001], *rt2[100001], *nil = g1;
struct node {
long long x;
int y;
bool operator<(const node &b) const { return x < b.x; }
} a[100001];
struct vale {
long long x;
int y;
bool operator<(const va... | 21 |
#include <bits/stdc++.h>
using namespace std;
const long long MAXVAL = (long long)1e18 + 1;
const long long MOD = 1000000007;
const int INF = 1000000000 + 1;
long long poww(int x, long long pow) {
if (pow == 0ll) return 1;
if (pow == 1ll) return x % MOD;
long long ans = poww(x, pow >> 1) % MOD;
ans = (ans * ans... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[2 * n];
for (int i = 0; i < n; i++) {
cin >> a[i];
a[i + n] = a[i];
}
int l = 0, r = 1;
int ans = -1;
while (l < n) {
if (a[r] >= a[r - 1]) {
r++;
if (r - l == n) {
if (l == 0) {
a... | 4 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> moves(5000001), dp(5000001);
const int N = 5000000;
vector<bool> prime(N + 1, true);
void precompute() {
for (int i = 2; i <= N; i++) {
if (prime[i])
for (int j = i; j <= N; j += i) {
int count = 0, n = j;
while (n % i == 0) cou... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int m;
cin >> m;
string s;
cin >> s;
for (char c = 'a'; c <= 'z'; ++c) {
vector<int> get;
int lastPossibleChar = -1;
int lastIndex = -1;
bool found = true;
for (int i = 0; i <... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int oo = 0x7fffffff;
int Hash[1000007], hn, ans[1000007];
struct da {
int l, r, val;
int mid() { return (l + r) / 2; }
int len() { return (r - l + 1); }
} tree[1000007 << 2];
struct node {
int op, time, num, id;
bool operator<(const node& a) const {
if (... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int dx[] = {+1, -1, 0, 0};
const int dy[] = {0, 0, +1, -1};
int main() {
ios_base ::sync_with_stdio(false);
cin.tie(NULL);
string s;
cin >> s;
int a, b, kol;
int size = s.size();
for (int i = 1; i <= 5; i... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int maxn = 1000005;
int n;
char s[maxn];
vector<int> a;
int f[maxn][3];
inline void pd(int &ret, int val) {
if (val == -1) return;
ret = max(ret, val + 1);
}
int main() {
scanf("%s", s);
n = strlen(s);
for (int i = 0; i < n; i++)
... | 14 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool read(T &n) {
T x = 0, tmp = 1;
char c = getchar();
while ((c < '0' || c > '9') && c != '-' && c != EOF) c = getchar();
if (c == EOF) return false;
if (c == '-') c = getchar(), tmp = -1;
while (c >= '0' && c <= '9') x *= 10, x += (c... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 3;
int t, n, k, a[N];
int main() {
cin >> t;
while (t --) {
cin >> n >> k;
for (int i = 0; i < n; ++ i)
cin >> a[i];
sort(a, a + n);
if (k == 0) {
printf("%d\n", n);
continue;
}
if (a[0] != 0) {
int flag = 1;
for (int... | 3 |
#include <bits/stdc++.h>
using namespace std;
int sum[100010];
int pro[100010];
int main() {
int n;
string s;
cin >> s;
cin >> n;
for (int i = 0; i < s.size() - 1; i++) {
if (s[i] == s[i + 1]) {
sum[i + 1] = 1;
}
}
for (int i = 1; i <= s.size() + 1; i++) {
sum[i] += sum[i - 1];
}
for... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
const int MOD = 1000000007;
struct Node {
int x, y, id;
Node() {}
Node(int _x, int _y, int _i) {
x = _x;
y = _y;
id = _i;
}
bool operator<(const Node &n) const { return x > n.x; }
};
int n, k;
vector<pair<int, int> > e[N];
vector<... | 14 |
#include <bits/stdc++.h>
using namespace std;
set<int> d;
vector<int> D;
int main(int argc, char const *argv[]) {
int n, m;
cin >> n >> m;
cout << max(n, m) - 1 << " " << min(n, m) << endl;
return 0;
}
| 5 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int N = 200031;
int n, m, q, a[N], b[N];
long long S[N][2];
long long total_sum;
vector<long long> V;
int count_odd(int x) { return x / 2 + x % 2; }
int count_even(int x) { return x / 2; }
long long make_query(long long val) {
long long re... | 13 |
#include <bits/stdc++.h>
using namespace std;
char str[20][20];
int main() {
FILE *fi, *fout;
fi = stdin;
fout = stdout;
int i, j, l, c;
for (i = 1; i <= 11; i++) {
if (i != 4 && i != 8)
for (j = 1; j <= 3; j++)
fscanf(fi, "%s", str[i] + (j - 1) * 3 + 1 + j - 1);
}
for (i = 1; i <= 11; i... | 6 |
#include <bits/stdc++.h>
using namespace std;
int s[1000001];
int main() {
for (int i = 1; i <= 1000001; i++) s[i] = 1;
for (int i = 1; i <= 1000001; i++)
for (int j = i * 2; j <= 1000001; j += i) s[j]++;
long long tong = 0;
int a, b, c;
cin >> a >> b >> c;
for (int i = 1; i <= a; i++)
for (int j = ... | 5 |
#include <bits/stdc++.h>
using std::queue;
using std::vector;
const int N = 100005;
namespace FLOW {
const int M = 2000005;
struct edge {
int to, nxt, fl;
} e[M];
int n, S, T, head[N], dis[N], iter[N], top;
inline void init(void) {
std::fill(head + 1, head + n + 1, 0);
top = 1;
}
inline void adde(int x, int y, in... | 25 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void checkmin(T &a, T b) {
if (a > b) a = b;
}
template <class T>
inline void checkmax(T &a, T b) {
if (a < b) a = b;
}
const double eps = 1e-7;
const int N = 1;
const int M = 200000;
const long long P = 10000000097ll;
const int INF = 0x3f3f3f3... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void out(T x) {
cout << x << endl;
exit(0);
}
using ll = long long;
const int maxn = 1e6 + 5;
const int N = 2e5;
vector<ll> fac[maxn];
ll n, m, l, r;
vector<ll> ans[maxn];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0)... | 22 |
#include <bits/stdc++.h>
using namespace std;
double a, b;
int main(void) {
cin >> a >> b;
double c = (a + b) / 2, d = (a - b) / 2;
a = c;
b = d;
if (a < 0 || b < 0) {
cout << "-1\n";
return 0;
}
if (a == b) {
cout << "-1\n";
return 0;
}
if (a < b) swap(a, b);
int k = (int)(b / (a - ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000;
bool chack(int x) {
int book[20] = {0};
while (x) {
int k = x % 10;
if (book[k] == 0)
book[k] = 1;
else
return false;
x /= 10;
}
return true;
}
int main() {
int l, r;
cin >> l >> r;
for (int i = l; i <= r; i++... | 0 |
#include <bits/stdc++.h>
using namespace std;
int p[5004], q[5002], row[5002], col[5011];
int main() {
int n, m, k, i, j, x, y, c;
cin >> n >> m >> k;
for (i = 1; i <= k; i++) {
cin >> c >> x >> y;
if (c == 1) {
row[x] = y;
p[x] = i;
} else {
col[x] = y;
q[x] = i;
}
}
f... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long ksm(long long a, long long b) {
if (!b) return 1;
long long ns = ksm(a, b >> 1);
ns *= ns, ns %= 1000000007;
if (b & 1) ns *= a, ns %= 1000000007;
return ns;
}
struct edge {
int u, v, c;
long long w;
bool flag;
edge *rev;
edge *next;
} pool[100... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFF = 0x3f3f3f3f3f3f3f3fll;
const long long M = 998244353;
const long long maxn = 1e6 + 7;
const double pi = acos(-1.0);
const double eps = 0.0000000001;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
t... | 18 |
#include <bits/stdc++.h>
using namespace std;
void FastIO() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
cout.precision(15);
}
long long modpow(long long a, long long p, long long mod) {
long long ret = 1;
while (p) {
if (p & 1) ret = (ret * a) % mod;
a = (a * a) % mod;
p /= 2;... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long min(long long a, long long b) { return (a < b) ? a : b; }
long long max(long long a, long long b) { return (a > b) ? a : b; }
long long fp(long long a, long long b) {
if (b == 0) return 1;
long long x = fp(a, b / 2);
x = (x * x) % mo... | 13 |
#include <bits/stdc++.h>
using namespace std;
const long long maxx = 790;
const long long maxn = 400000 + 7;
const long long mod = 998244353;
const long long maxs = 500000 + 7;
const long long maxm = 400000 + 7;
const long long maxk = 1008 + 7;
const long long maxw = 100 + 7;
const long long maxh = 100 + 7;
const doubl... | 12 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.