solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
const int INF = (int)1e9 + 7, N = (int)1e5 + 123;
const double eps = 1e-9;
int x, mini = INF;
int p[(int)1e6 + 123];
vector<int> pr;
inline void check(int x) {
for (int i = 0; pr[i] * pr[i] <= x; i++) {
if (x % pr[i] =... | 9 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long f = 1, ans = 0;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
ans = ans * 10 + c - '0';
c = getchar();
}
return f * ans;
}
const long l... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long n, k, a, b;
map<long long, long long> mp;
vector<long long> pos(100007, 0);
long long funct(long long st, long long ed) {
if (ed - st + 1 == 1) {
if (mp.find(st) == mp.end())
return a;
else {
return (b * mp[st]);
}
}
long long diff = ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, l, r;
cin >> n >> m >> l >> r;
vector<int> s, v;
for (int i = 0; i < n; i++) {
int t;
cin >> t;
s.push_back(t);
}
for (int i = 0; i < m; i++) {
int t;
cin >> t;
v.push_back(t);
}
int i = 0, j = 0, x = 0;
int a... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, s1;
cin >> s >> s1;
int count_4s = 0, count_7s = 0;
int count_4s1 = 0, count_7s1 = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] != s1[i]) {
if (s[i] == '4') count_4s++;
if (s1[i] == '4') count_4s1++;
if (s[i] == '7'... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e6 + 10;
const long long mo = 1e9 + 7;
long long gcd(long long a, long long b) {
if (b == 0) {
return a;
}
return (gcd(b, a % b));
}
long long exgcd(long long a, long long b, long long& x, long long& y) {
if (b == 0) {
x = 1, y = 0;
... | 5 |
#include <bits/stdc++.h>
const int MAXN = 250 + 5;
int a[MAXN][MAXN], n, m;
char s[MAXN];
bool vis[MAXN][MAXN];
int bel[MAXN][MAXN];
int cnt, ts;
int mnx, mny, mxx, mxy;
inline void dfs(int x, int y) {
vis[x][y] = 1;
++cnt;
bel[x][y] = ts;
mnx = std::min(mnx, x);
mxx = std::max(mxx, x);
mny = std::min(mny, ... | 14 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int add(int a, int b) {
long long x = a + b;
if (x >= 1000000007) x -= 1000000007;
if (x < 0) x += 1000000007;
return x;
}
long long mul(long long a, long long b) { return (a * b) % 1000000007; }
long long pw(long long a, long long b) {
... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int n, k;
const int N = 200020;
long long dp[N];
int qpow(int x, int y) {
int res = 1;
while (y) {
if (y & 1) res = 1ll * res * x % mod;
x = 1ll * x * x % mod;
y >>= 1;
}
return res;
}
void solve() {
cin >> n >> k;
long long ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
while (t--) {
string s, t;
cin >> t;
int m;
cin >> m;
vector<int> f(26), b(m);
for (int i = 0; i < m; i++) cin >> b[i];
for (int i = 0; i <... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int N = 1e5;
int a[24], b[24];
int solved() {
for (int i = 0; i < 6; ++i) {
bool f = 0;
for (int j = 0; j < 4; ++j) {
if (b[i * 4 + j] != b[i * 4]) return 0;
}
}
return 1;
}
void moveU() {
for (in... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 400005;
const long long MOD = 998244353;
const long long G = 3, Ginv = 332748118, Inv2 = 499122177;
template <typename T>
inline void read(T &a) {
T x = 0, flag = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') flag = -1;
ch = ge... | 23 |
#include <bits/stdc++.h>
using namespace std;
int inf = 1e9 + 7;
int n, m;
int a[500005];
int q[2000006];
pair<int, int> g[2000006];
map<int, int> p;
pair<int, int> get(int v, int lr, int rl, int l, int r) {
if (rl < l || lr > r || q[v] > r) return make_pair(inf, inf);
if (lr >= l && rl <= r && g[v].second <= r) re... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long int a, b, c, l, ans;
long long int cal(long long int a, long long int b, long long int c,
long long int l) {
long long int ans = 0;
for (long long int i = ((b + c - a) > (0) ? (b + c - a) : (0)); i <= l; ++i)
ans += (1 + ((l - i) < (a + i... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int inv = numeric_limits<int>::max();
vector<vector<int> > mmul(vector<vector<int> > A, vector<vector<int> > B) {
int N = A.size();
vector<vector<int> > res(N, vector<int>(N, inv));
for (int i = 0; i < (N); i++)
for (int j = 0; j < (N); j++)
for (int k... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, ans = 0;
cin >> n >> m;
for (int i = 2; i <= n; i += 2)
for (int j = 2; j <= m; j += 2) ans += (m - j + 1) * (n - i + 1);
cout << ans << endl;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
int n, K;
bool a[6][105];
int main() {
cin >> n >> K;
int mid = (1 + n) / 2;
if (K % 2 == 0) {
int k = K / 2;
for (int i = 1; i <= (1 + k) / 2; i++)
a[2][mid - i + 1] = 1, a[3][mid - i + 1] = 1;
for (int i = 1; i <= k - (1 + k) / 2; i++)
a[2][m... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double a, b, sum = 0.00, i, n;
cin >> n;
for (i = 0; i < n; i++) {
cin >> a >> b;
sum += b;
}
sum /= i;
sum += 5.00;
printf("%.3lf", sum);
return 0;
}
| 14 |
#include <bits/stdc++.h>
using namespace std;
string s[300003], h, cur, l, r;
int n;
bool ok = 0, q = 0;
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
;
cin >> n;
cin >> h;
for (int i = 0; i < n; i++) cin >> s[i];
while (true) {
q = 0;
for (int i = 0; i < n; i++) {
if... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long n, k;
int main() {
cin >> n >> k;
if (n > k * (k - 1)) {
cout << "NO" << endl;
return 0;
}
cout << "YES" << endl;
long long num = 0;
if (k % 2) {
for (int i = 1; i <= k / 2 && num < n; i++) {
for (int j = 1; j <= k && num < n; j++) {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, count, n;
int flag = 1;
char fst[101];
char ans[101];
char sec[101];
char *a = NULL;
scanf("%s", fst);
scanf("%s", ans);
for (i = 0; i < strlen(ans); ++i) {
if (fst[i] < ans[i]) {
printf("-1");
return 0;
} else {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
vector<int> p, m;
int main() {
int n;
cin >> n;
if (n == 1) {
int x;
cin >> x;
cout << x << endl;
return 0;
}
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
if (x > 0)
p.push_back(x);
else if (x < 0)
m.push_back(x);
}... | 6 |
#include <bits/stdc++.h>
using namespace std;
int Q[110], n;
string goal = "", P = "", PP = "";
char ret1[110], ret2[110];
inline string go(string s) {
for (int x = 0; x < n; x++) ret1[x] = s[Q[x]];
return ret1;
}
inline string goo(string s) {
for (int x = 0; x < n; x++) ret2[Q[x]] = s[x];
return ret2;
}
int ma... | 10 |
#include <bits/stdc++.h>
using namespace std;
map<long long int, int> coun;
set<long long int> g;
int main() {
long long int b, d, l, m;
int i;
long long int u;
int terms = 0;
cin >> b >> d >> l >> m;
for (i = 0; i < m; i++) {
cin >> u;
coun[u] = 1;
}
if (b == 0) {
if (coun[0] == 1)
co... | 9 |
#include <bits/stdc++.h>
using namespace std;
inline char nc() {
static char buf[100000], *p1 = buf, *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
? EOF
: *p1++;
}
inline int read() {
register int x = 0, f = 1;
register char ch = nc();
while... | 15 |
#include <bits/stdc++.h>
long long inf = 1LL << 60;
long long mod = 1000000007;
using namespace std;
int main(void) {
long double n;
cin >> n;
long double ans = n * (n - 1) * (n - 2) * (n - 3) * (n - 4) * n * (n - 1) *
(n - 2) * (n - 3) * (n - 4) / (5 * 4 * 3 * 2);
cout << fixed << setprecis... | 6 |
#include <bits/stdc++.h>
using namespace std;
bool gt(long double a, long double b) { return a > b + 1e-9; }
string a, b;
int fa[26], fb[26];
int main() {
ios::sync_with_stdio(false);
cin >> a >> b;
for (int same = min(((int)(a).size()), ((int)(b).size())); same >= 0;
same--) {
memset(fa, 0, sizeof fa)... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long int tf, fy, hn, n, c, i, a[100000];
cin >> n;
for (i = 0; i < n; i++) {
cin >> a[i];
}
c = 1;
tf = 0;
hn = 0;
fy = 0;
for (i = 0; i < n; i++) {
if (a[i] == 25)
tf++;
else if (a[i] == 50) {
if (tf < 1) {
c =... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
string s;
cin >> s;
int n = s.size();
vector<int> v[26];
for (int i = int(0); i <= int(n - 1); i++) v[s[i] - 'a'].push_back(i);
double ans = 0;
for (int i = int(0); i <= int(25); i++) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 5020;
char bb[MAX], buf[10][MAX];
int an[MAX];
int ss[MAX], sn;
int main() {
for (int i = 0; i < 10; i++) {
scanf("%s", buf[i]);
}
sn = 0;
memset(an, 0, sizeof(an));
int len = 0, n = 0, cur = 0;
for (int i = 0; i < 10; i++) {
if (buf[i][0... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
long long i, j, k;
char x;
for (i = 0; i < t; i++) {
long long n, a, b;
cin >> n >> a >> b;
long long z = n % b;
long long w = n / b;
for (j = 0; j < w * b; j = j + b) {
for (k = 0; k < b; k++) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
template <typename T>
struct fenwick {
int length;
vector<T> tree;
fenwick(int size) {
length = size + 1;
tree.assign(length + 1, 0);
}
fenwick(vector<T>& v) {
length = v.size() + 1;
tree.assign(length + 1, 0);
for (i... | 10 |
#include <bits/stdc++.h>
using namespace std;
inline void upd(int &x, int y) { x < y && (x = y); }
const int N = 150005;
string s;
int main() {
cin >> s;
int n = s.size();
if (n == 1) {
cout << 1 << endl;
return 0;
}
int res = 1, ans = 0;
char last = s[0];
for (int i = 1; i < n; ++i) {
if (las... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double eps = 1e-8;
const int MAXN = 2e5 + 10;
const int MAXM = 1e6 + 10;
const long long mod = 1e9 + 7;
long long a[MAXN];
long long x = 1e9, y = 1e9;
bool judge(long long b, long long c) {
if ((abs(b - c) == 1) || abs(b - c) == y) return... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MX = 100000;
string s;
int n;
int main() {
cin >> n >> s;
for (int i = 0; i < n; i++) {
int l = i - 1;
int r = i;
int cr = 1, cl = 1;
while (s[l] != 'L' && l >= 0) {
if (s[l] == 'R') {
cl++;
}
l--;
}
while (s[r... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long trojkat(long long d) {
if (d < 0) return 0;
return ((d + 1) * (d + 2)) / 2;
}
long long trojkat_inny(long long d) {
assert(d >= 0);
d++;
long long k = d / 2;
if (d % 2 == 0)
return k * (k + 1);
else
return (k + 1) * (k + 1);
}
long long fragm... | 13 |
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pi = pair<int, int>;
const int MAXN = 50005;
const int MAXT = 132000;
pi merge(pi a, pi b) {
if (a < b) swap(a, b);
if (a.first == b.first) a.second = min(a.second, b.second);
return a;
}
int n;
struct seg {
pi tree[MAXT];
int lazy[MA... | 21 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigmod(T p, T e, T M) {
long long int ret = 1;
for (; e > 0; e >>= 1) {
if (e & 1) ret = (ret * p) % M;
p = (p * p) % M;
}
return (T)ret;
}
template <class T>
inline T gcd(T a, T b) {
if (b == 0) return a;
return gcd(b, a % b)... | 14 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
int t;
cin >> t;
while (t--) {
int n, res;
cin >> n;
if (n == 2 || n == 3) {
cout << -1 << endl;
continue;
}
res = n;
vector<int> o, e;
for (int i =... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t;
cin >> t;
while (t--) {
long long int n, k;
cin >> n >> k;
long long int a = (int(k / 2)) * (2 + ((k - 1) * 2));
if (k % 2 == 1) a += k;
if (n % 2 == 1 && k % 2 == 1 && n >= a)
cout << "YES" << endl;
else if ... | 3 |
#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
using pii = pair<int, int>;
using vi = vector<int>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vlli = vector<long long int>;
using vpii = vector<pair<int, int>>;
const int N = 500005;
mt19937 rng(chrono::steady_clock::now().ti... | 14 |
#include <bits/stdc++.h>
#pragma GCC optimize "trapv"
using namespace std;
const long long MOD = 1e9 + 7;
void print() { cout << endl; }
void printArray() { return; }
void read() { return; }
template <typename T, typename... Args>
void print(T a, Args... arg) {
cout << a << " ";
print(arg...);
}
template <typename ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
static long long int n, m, a, b, d;
cin >> n >> m >> a >> b;
d = n % m;
cout << min(d * b, a * (m - d)) << endl;
return 0;
}
| 2 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const long long maxn = 1e6 + 100;
const long long inf = 1e15;
long long n, m, k, t;
int main() {
ios_base ::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long q, w, e, a, b, c;
cin >> t;
for (e = 0; e < t; e++) {
cin >> n;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
regex r("^(1|14|144)*$");
if (regex_match(s, r)) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 30030;
const int MAXK = 220;
const int inf = 1e9;
int f[MAXN][MAXK][2][5];
int best[MAXK][2][5];
int a[MAXN];
int s[MAXN];
int main(void) {
int n, k;
scanf("%d %d", &n, &k);
for (int i = (0); i < (n); ++i) scanf("%d", a + i);
s[0] = 0;
for (int i ... | 19 |
#include <bits/stdc++.h>
using namespace std;
struct gauss {
vector<int> mat, basis;
int reduce(int n) {
for (auto x : mat) {
int msb = 1 << (31 - __builtin_clz(x));
if (n & msb) n ^= x;
}
return n;
}
void add(int n) {
int r = reduce(n);
if (r) {
basis.push_back(n);
m... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 30;
const long long INF = 1e18;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 2;
const int mov[4][2] = {-1, 0, 1, 0, 0, 1, 0, -1};
const int Mov[8][2] = {-1, -1, -1, 0, -1, 1, 0, -1, 0, 1, 1, -1, 1, 0, 1, 1};
inline int read() {
int x = 0, f = 1;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int d, n, i;
cin >> d;
cin >> n;
int a[n];
int x, sum = 0;
for (i = 0; i < n - 1; i++) {
cin >> x;
sum += d - x;
}
cin >> x;
cout << sum;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int f[100050];
int main() {
int n;
int ans = 1;
int x = 0;
while (~scanf("%d", &n)) {
memset(f, 0, sizeof(f));
for (int i = 0; i < n; i++) {
scanf("%d", &x);
f[x] = f[x - 1] + 1;
ans = max(ans, f[x]);
}
printf("%d\n", n - ans);
}
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
vector<int> G[N][10];
vector<int> vi, a0, a1;
bool vis[N];
int rk[N], pre[N], num[N];
int main() {
int n, m;
scanf("%d%d", &n, &m);
while (m--) {
int u, v, w;
scanf("%d%d%d", &u, &v, &w);
G[u][w].push_back(v);
G[v][w].push_back(u)... | 14 |
#include <bits/stdc++.h>
using namespace std;
class vec {
public:
int x, y;
vec() : x(), y() {}
vec(int tx, int ty) : x(tx), y(ty) {}
vec operator-(const vec &t) const { return vec(x - t.x, y - t.y); }
long long operator*(const vec &t) const {
return (long long)x * t.y - (long long)y * t.x;
}
bool op... | 20 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, s, p;
cin >> k >> n >> s >> p;
int y = (s > n) ? s : n;
int paperperperson = (y % s == 0) ? y / s : (y / s) + 1;
int paper = k * paperperperson;
int pack = (paper % p == 0) ? paper / p : (paper / p) + 1;
cout << pack << endl;
return 0;... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long g, l, r, x, m, menor, resposta = -1;
cin >> g;
l = g;
r = g * 8;
while (l <= r) {
m = (l + r) / 2;
menor = 0;
x = 0;
for (long long i = 2; i <= cbrt(m); i++) {
x += m / (i * i * i);
menor = max(menor, m - m % (i *... | 9 |
#include <bits/stdc++.h>
const size_t ioSize = 1 << 21;
char iBuf[ioSize], *iS, *iE;
inline char getc() {
return iS == iE ? iE = iBuf + fread(iS = iBuf, 1, ioSize, stdin),
iS == iE ? EOF : *iS++ : *iS++;
}
template <typename T>
void readi(T &x) {
char c;
for (c = getc(); !isdigit(c); c = getc(... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000006;
int OGR[MAXN][3];
void NIE() {
puts("IMPOSSIBLE");
exit(0);
}
vector<int> LE[MAXN], PR[MAXN], ANS;
int dfs(int u, int mus) {
for (typeof(LE[u].begin()) it = LE[u].begin(); it != LE[u].end(); ++it)
if (*it <= u) NIE();
for (typeof(PR[u].... | 16 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, rem[100004], cost[100004], t, d, kind, num, dif, total;
struct s {
int price, idx;
} v[100004];
queue<s> q;
bool cmp(s a, s b) {
if (a.price == b.price) return a.idx < b.idx;
return a.price < b.price;
}
int main() {
cin >> n >> m;
for (int i = 1; i... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
scanf("%d", &N);
if (N < 3) {
printf("-1");
return 0;
}
printf("6\n15\n10\n");
for (int i = 4; i <= N; i++) printf("%d\n", 30 * (i - 3));
return 0;
}
| 9 |
#include <bits/stdc++.h>
using namespace std;
int dp[101000][110] = {0};
struct query {
int l;
int r;
int k;
query() {}
query(int _l, int _r, int _k) : l(_l), r(_r), k(_k) {}
bool operator<(query a) const { return r > a.r; }
};
int mypow(int x, int n) {
int a = x, ans = 1;
while (n) {
if (n & 1) ans... | 17 |
#include <bits/stdc++.h>
using namespace std;
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
const long long N = 2e5 + 5, NN = (1LL << 10) + 5, mod = 998244353;
bool isprime(long long n) {
for (int i = 2; i <= n / i; i++)
if (n % i == 0) return 0;
return 1;
}
int main() {
ios_base::sync_with_stdio(fals... | 4 |
#include <bits/stdc++.h>
using namespace std;
map<pair<pair<int, int>, char>, int> M;
int t;
string s;
int main() {
ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
cout.tie(NULL);
if (fopen(""
".inp",
"r")) {
freopen(
""
".inp",
"r", stdin);
freopen(
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double x, y, sum = 0;
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> x >> y;
sum += y;
}
sum /= n;
sum += 5;
printf("%.3f", sum);
return 0;
}
| 14 |
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#incl... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int f[N], tot = 0;
char a[N], ans[N];
stack<char> s;
int main() {
scanf("%s", a + 1);
int n = strlen(a + 1);
f[n + 1] = 100;
for (int i = n; i >= 1; i--) {
f[i] = min(a[i] - '0', f[i + 1]);
}
for (int i = 1; i <= n; i++) {
while (... | 9 |
#include <bits/stdc++.h>
using namespace std;
int a[205];
bool vis[205];
vector<int> g[205];
vector<int> cycle;
vector<vector<int>> ans;
struct Edge {
int u, v;
long long cap, flow;
Edge() {}
Edge(int u, int v, long long cap) : u(u), v(v), cap(cap), flow(0) {}
};
struct Dinic {
int N;
vector<Edge> E;
vect... | 15 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void chkmin(T &a, T b) {
if (a > b) a = b;
}
template <class T>
inline void chkmax(T &a, T b) {
if (a < b) a = b;
}
const double pi = 4 * atan(1);
double px[5000], py[5000];
int id[600][10];
int main() {
int N, i, j, np = 0;
double R, d, x,... | 15 |
#include <bits/stdc++.h>
const int N = 155, oo = 1000000007;
int n, m, ans, f[N][N][4], g[N][N][4];
int rec(int k, int x1, int x2, int y1, int y2) {
if (x1 > x2 || y1 > y2) return 0;
return (0LL + f[x2][y2][k] + f[x1 - 1][y1 - 1][k] - f[x1 - 1][y2][k] -
f[x2][y1 - 1][k]) %
oo;
}
int main() {
sc... | 16 |
#include <bits/stdc++.h>
using namespace std;
int n, i, j, k, x, y, z, m, q, h, r, timer, mx;
int a[100500], tin[100500], tout[100500], w[100500], lvl[100500],
up[100500][20];
vector<pair<int, int> > g[100500];
vector<int> f;
int l = 18;
void dfs(int v, int lv, int p) {
tin[v] = ++timer;
lvl[v] = lv;
up[v][0]... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e6 + 100;
long long n, m, k, a[5005][5005];
pair<long long, long long> rows[5005], col[5005];
int main() {
cin >> n >> m >> k;
for (long long i = 1; i <= k; i++) {
long long t, x, y;
cin >> t >> x >> y;
if (t == 1) {
rows[x].first = ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
int n, m;
while (cin >> n >> m) {
int k = 0;
int t;
vector<int> a(n + m + 1);
vector<long long> vis(m);
for (int i = 1; i <= n + m; i++) cin >> a[i];
for (int i =... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, y, z, xsum(0), ysum(0), zsum(0);
cin >> n;
while (n--) {
cin >> x >> y >> z;
xsum += x;
ysum += y;
zsum += z;
}
if (xsum == 0 && ysum == 0 && zsum == 0) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int M = 2e5 + 10;
int a[M];
int b[M];
int vis[M];
map<int, int> mp;
int tree[M];
int lowerbit(int x) { return x & (-x); }
void add(int x, int y) {
for (int i = x; i < M; i += lowerbit(i)) {
tree[i] += y;
}
}
long long int query(int x) {
long long int ans = 0... | 9 |
#include <bits/stdc++.h>
using namespace std;
void ask(long long x) {}
long long tr;
vector<long long> que;
long long ask() {
printf("%d ", que.size());
for (int i = 0; i < que.size(); i++) printf(" %lld", que[i]);
printf("\n");
fflush(stdout);
int x = 0;
scanf("%d", &x);
if (x == -1) exit(0);
if (x == ... | 22 |
#include <bits/stdc++.h>
using namespace std;
bool pri[100000 + 5];
int np, prime[2000], ans, a, b;
void init() {
int i, j, k, times, base;
np = 0;
prime[++np] = 2;
for (i = 0; i < 3000; i++) {
memset(pri, true, sizeof(pri));
for (j = 2; j <= np; j++) {
if (prime[j] <= (i + 1) * 100000 / prime[j])... | 14 |
#include <bits/stdc++.h>
using namespace std;
template <class C>
void mini(C& _a4, C _b4) {
_a4 = min(_a4, _b4);
}
template <class C>
void maxi(C& _a4, C _b4) {
_a4 = max(_a4, _b4);
}
template <class TH>
void _dbg(const char* sdbg, TH h) {
cerr << sdbg << '=' << h << endl;
}
template <class TH, class... TA>
void ... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
int k;
int f1 = 0, f2 = 0, f3 = 0;
vector<int> a, b, c, ab, bc, ca, abc;
for (int i = 1; i <= n; i++) {
cin >> k >> s;
sort(s.begin(), s.end());
{
if (s.size() == 1) {
if (s[0] == 'A') {
... | 4 |
#include <bits/stdc++.h>
int gcd(int a, int b) {
if (a % b == 0) {
return (b);
} else {
return (gcd(b, a % b));
}
}
int main() {
int n, i, g, max, val;
scanf("%d", &n);
int a[n];
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
g = a[0];
max = a[0];
for (i = 1; i < n; i++) {
if (a[i... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, mod;
cin >> a >> b >> mod;
for (int j = 0; j < min(a + 1, mod); j++) {
long long theta = 1ll * j * 1e9;
theta %= mod;
theta = mod - theta;
theta %= mod;
if (theta <= b) continue;
cout << 1 << endl;
cout.width(9);
... | 10 |
#include <bits/stdc++.h>
int min[100010 << 2], R[100010 << 2], F[100010 << 2], G[100010 << 2];
inline void set(int x, int a, int b) {
if (min[x] >= a) {
min[x] = b;
F[x] = b;
if (!G[x]) G[x] = a;
}
}
inline void update(int &x, int &y, int &z) {
if (z > x)
y = x, x = z;
else if (z < x && z > y)
... | 22 |
#include <bits/stdc++.h>
using namespace std;
static const int MOD = 1000000007;
static const long long MODL = 1000000000000000003LL;
static const double eps = 1e-8;
template <class T>
inline T MIN(const T x, const T y) {
return (x < y) ? x : y;
}
template <class T>
inline T MAX(const T x, const T y) {
return (x > ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<pair<int, int>> a(n);
for (int i = 0; i < n; i++) cin >> a[i].first >> a[i].second;
sort(a.begin(), a.end());
int l = a[0].first;
int r = a[0].second;
int cnt = 0;
for (int i = 1; i < n; i++) {
if (a[i].first > l &&... | 7 |
#include <bits/stdc++.h>
int A[1 << 12], n;
int B[1 << 12];
char buf[100];
void fwt(bool inv = false) {
const int U = 1 << n;
for (int i = 0; i < n; ++i) {
const int mid = 1 << i;
if (buf[i] == 'A' || buf[i] == 'a') {
if (!inv) {
for (int j = 0; j < U; j += mid << 1)
for (int k = j; ... | 20 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long inf = 1e18;
const long double pai = acos(-1);
long long n, MX = 4294967295;
string s[100009];
long long N[100009];
long long en[100009];
long long num[109], here[100009];
long long val[109][100009];
long long mx[109];
void o... | 8 |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define deb(x) cerr<<"["<<#x<<": "<<x<<"]"<<endl;
#define F first
#define S second
#define debp(x) cerr<<"["<<#x<<": "<<x.F<<" , "<<x.S<<"]"<<endl;
#define debv(v) cerr<<"{"<<#v<<":";for(auto i:v)cerr<<" "<<i;cerr<<"}"<<endl;
#define get(v) for(auto &i... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k, l;
scanf("%d %d", &k, &l);
if (l == 1) return printf("YES \n -1\n"), 0;
int tmp = 1;
for (int i = 1; tmp <= l; i++) {
tmp *= k;
if (tmp == l) return printf("YES \n %d\n", i - 1), 0;
if (l % tmp != 0) return printf("NO \n"), 0;
}
... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long x, y, z;
char a[505][505];
bool r[505], c[505];
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
;
cin >> x;
for (int i = 0; i < x; i++) {
for (int j = 0; j < x; j++) {
cin >> a[i][j];
}
}
for (int i = 1; i < x - 1; i++) {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k, i, j, c = 0, m, n, a, b;
string s = "aeiou", ss = "aeiou";
cin >> k;
for (i = 5; i < k; i++) {
if (k % i == 0) {
a = i;
break;
}
}
b = k / a;
if (a < 5 || b < 5) {
cout << -1;
return 0;
}
for (i = 0; i < 1000... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MX = 2e5 + 5, LMX = 19;
int n, q, p[MX], a[MX], inv[MX], lvl[MX];
vector<int> adj[MX];
int cn = 1, ini[MX], st[2 * MX][LMX];
void dfs(int u) {
ini[u] = cn;
st[cn][0] = u;
cn++;
for (int v : adj[u]) {
dfs(v);
st[cn][0] = u;
cn++;
}
}
int LCA(i... | 21 |
#include <bits/stdc++.h>
using namespace std;
char c[7][51];
int b[7];
int v[7];
bool judge() {
if (v[b[1]] + v[b[6]] - 1 != v[b[3]] || v[b[2]] + v[b[5]] - 1 != v[b[4]])
return false;
if (c[b[1]][v[b[1]] - 1] != c[b[4]][0] ||
c[b[4]][v[b[4]] - 1] != c[b[6]][0] ||
c[b[5]][v[b[5]] - 1] != c[b[6]][v[b[... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int n, b, a, mxa, arr[maxn];
int main() {
scanf("%d %d %d", &n, &b, &a);
mxa = a;
for (int i = 0; i < n; ++i) scanf("%d", arr + i);
int i = 0;
for (; i < n; ++i) {
if (arr[i] == 1 && a < mxa && b > 0) {
++a, --b;
} else if (... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 5;
const long long linf = 1e18 + 5;
const int N = 1000 + 5;
int n;
bool h[N];
pair<int, int> a[N];
int main() {
ios ::sync_with_stdio(0);
cin >> n;
long long ans = linf;
for (int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second;
for (int ... | 11 |
#include <bits/stdc++.h>
using namespace std;
char a[5010][5010];
int main() {
int n, i;
scanf("%d", &n);
for (i = 0; i < n; i++) scanf("%s", a[i]);
vector<int> b(1, 0);
for (i = 1; i < n; i++) {
int l = 0, r = i - 1;
while (l < i && a[i][b[l]] == '0') l++;
while (r >= 0 && a[i][b[r]] == '1') r--;... | 12 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
long long query(long long t, long long i, long long j, long long k) {
cout << t << " " << i << " " << j << " " << k << endl;
long long ans;
cin >> ans;
if (t == 2) ans *= -1;
return ans;
}
signed main() {
ios_base::sync_with_stdio(fals... | 15 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long mpow(long long base, long long exp) {
base %= mod;
long long result = 1;
while (exp > 0) {
if (exp & 1) result = ((long long)result * base) % mod;
base = ((long long)base * base) % mod;
exp >>= 1;
}
return re... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int DIV = 1000000007;
int main(int argc, char* argv[]) {
FILE* f = stdin;
int n, x, y, x1 = -2000, y1 = -2000, x2 = -2000, y2 = -2000;
fscanf(f, "%d\n", &n);
for (int i = 0; i < n; i++) {
fscanf(f, "%d %d\n", &x, &y);
if (i == 0) {
x1 = x;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int a[10010];
int main() {
int n, suma = 0, sumb = 0;
cin >> n;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
if (x == 100) suma++;
if (x == 200) sumb++;
}
if (suma == 0 || sumb == 0) {
if (suma == 0 && sumb % 2 == 0) {
cout << "YES";
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int M = 1005;
bool visit[M];
long long int dist[M];
vector<pair<int, int> > g1[M], g2[M];
int n, m, t, quant;
void calc(int second) {
memset(visit, 0, sizeof visit);
fill_n(dist, M, 1e15);
dist[second] = 0;
priority_queue<pair<long long int, int> > q;
q.push... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long N = 1e5 + 10;
void solve() {
long long n, k;
cin >> n >> k;
vector<bool> vis(2 * n + 1, false);
vector<pair<long long, long long>> a;
for (long long i = 0; i < k; i++) {
long long x, y;
cin >> x >> y;
if (... | 10 |
#include <bits/stdc++.h>
using namespace std;
const double PI =
3.141592653589793238462643383279502884197169399375105820974944;
int n, m;
int bl;
int a[100005], nex[100005], steps[100005], b[100005];
int main() {
scanf("%d%d", &n, &m);
bl = sqrt(n);
for (int i = 0; i < (n); i++) scanf("%d", &a[i]), b[i] = i /... | 19 |
#include <bits/stdc++.h>
using namespace std;
int tavan(int x, int y) {
int res = 1;
while (y) {
res *= y % 2 ? x : 1;
res %= ((int)1e9 + 7);
x *= x;
x %= ((int)1e9 + 7);
y /= 2;
}
return res;
}
int n, m, a[((int)301 * 1000)], even, odd, ans;
vector<int> bad, v_even, v_odd, now_even, now_odd... | 11 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.