solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
struct edge {
int u, v, next;
};
struct edge e[200010];
struct unit {
int l, r;
};
struct unit b[100010];
struct tree {
int tag;
bitset<1000> val;
};
struct tree t[400010];
int n, m, nq, num, tot, opt, x, y, z;
int head[100010], a[100010], w[100010];
bitset<1000> an... | 20 |
#include <bits/stdc++.h>
using namespace std;
int n, i, j, len = 0;
string s, dir[10000], t;
int main() {
cin >> n;
for (i = 0; i < n; ++i) {
cin >> s;
if (s == "pwd") {
cout << '/';
for (j = 0; j < len; ++j) {
cout << dir[j] << '/';
}
cout << '\n';
} else {
cin >> ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2002;
const int mod = 998244353;
int mul(int a, int b) { return a * 1ll * b % mod; }
int add(int a, int b) {
if (a + b >= mod) return a + b - mod;
return a + b;
}
int dpl[N][N], dpr[N][N];
char s[N];
int main() {
scanf("%s", s + 1);
int n = strlen(s + ... | 18 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool vmin(T& a, T b) {
return (a > b) ? (a = b, true) : (false);
}
template <typename T>
bool vmax(T& a, T b) {
return (a < b) ? (a = b, true) : (false);
}
template <typename T>
T smax(T x) {
return x;
}
template <typename T, typename... K>
T sma... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
int n = (a - b) / (2 * b);
int m = (a + b) / (2 * b);
if ((n <= 0 && m <= 0) || (b > a))
cout << "-1" << endl;
else {
double ans = HUGE_VAL;
if (n > 0) ans = double(a - b) / (2 * n);
if (m > 0) ans = min(ans,... | 9 |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define allr(x) x.rb... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, m, l[101][10001], r[101][10001], sol, sol1;
char a[101][10001];
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) cin >> a[i][j];
for (int i = 1; i <= n; i++) l[i][0] = r[i][m + 1] = 0xFFFFFF;
for (int i = 1; i <= n; i+... | 7 |
#include <bits/stdc++.h>
using namespace std;
struct UnionFind {
vector<int> data;
int sz;
UnionFind(int sz) : data(sz, -1), sz(sz) {}
bool unionSet(int x, int y) {
if ((x = root(x)) == (y = root(y))) return false;
if (data[x] > data[y]) swap(x, y);
data[x] += data[y];
data[y] = x;
sz--;
... | 4 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
template <class T>
using pq = priority_queue<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;
int scan() { return getchar(); }
template <class T>
void scan(T a) {
cin >> a;
}
void scan(int &a) { cin >> a; }
void scan(... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000005;
int n, a[MAXN], b[MAXN], A, B;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
if (i == 1) A = a[1];
}
for (int i = n; i; --i) {
a[i] = a[i] - a[i - 1];
}
for (int i = 1; i <= n; ++i) {
s... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long n, m;
vector<long long> G[20];
long long ans;
bool f[20];
long long dp[(1 << 19) + 5][20];
signed main() {
long long a, b;
scanf("%lld", &(n));
scanf("%lld", &(m));
for (long long i = 1; i <= m; i++) {
scanf("%lld", &(a));
scanf("%lld", &(b));
... | 14 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<pair<int, int>, int> > m[1000];
int main(int argc, char const *argv[]) {
ios_base::sync_with_stdio(0);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
m[b / 1000].push_back(make_pair(make_pair(a, b), i + 1));
}
boo... | 13 |
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N=2e5+5;
int val[N],tv[N],tt[N],minn[N];
int main()
{
int n,k,i;
scanf("%d%d",&n,&k);
for(i=1;i<=n;i++) scanf("%d",&val[i]),tv[i]=val[i];
sort(tv+1,tv+n+1);
int l=1,r=n,ans=0;
while(l<=r)
{
int mid=(l+r... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long min(long long a, long long b) {
if (a <= b)
return a;
else
return b;
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
long long n;
cin >> n;
;
cout << "25"
<< "\n";
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long n, x[100005], y[100005];
signed main() {
scanf("%lld", &n);
for (long long i = 1; i <= n; i++) {
scanf("%lld%lld", &x[i], &y[i]);
}
if (n & 1) return puts("NO") * 0;
double ansx = 1.0 * (x[1] + x[n / 2 + 1]) / 2,
ansy = 1.0 * (y[1] + y[n / 2... | 10 |
/*
{
######################
# Author #
# Gary #
# 2021 #
######################
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
... | 24 |
#include <bits/stdc++.h>
using namespace std;
int c[1001];
unsigned long long comb[1010][1010];
void init() {
int i, j;
for (i = 0; i < 1010; i++) comb[i][0] = 1;
for (i = 1; i < 1010; i++) {
for (j = 1; j <= i; j++) {
comb[i][j] = comb[i - 1][j] + comb[i - 1][j - 1];
comb[i][j] %= 1000000007;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 10000;
long long n, sum = 0;
long long ans = 1;
long long mod = 1000000000 + 7;
long long a[1000][1000];
long long num;
int32_t main() {
cin >> n;
a[0][0] = 1;
for (long long i = 1; i < 1000; i++) {
a[i][0] = 1;
for (long long j = 1; j <... | 7 |
#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;
char A[105][105];
bitset<105> row, col;
cin >> n;
for (int i = 0; i < n; ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 500;
int d, n, m;
pair<int, int> p[maxn];
deque<pair<int, int> > Q;
int main(int argc, char *argv[]) {
scanf("%d%d%d", &d, &n, &m);
int cur = 0, cap = n;
for (int i = 0; i < m; ++i) scanf("%d%d", &p[i].first, &p[i].second);
p[m].first = d, p[m... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long v[4010], d[4010], p[4010];
bool gone[4010];
int n;
vector<int> r;
queue<int> ev;
int main() {
while (scanf("%d", &n) == 1) {
for (int i = (0); i < (n); i++)
scanf("%lld %lld %lld", &v[i], &d[i], &p[i]);
int i = 0;
memset(gone, 0, sizeof(gone));... | 10 |
#include <bits/stdc++.h>
using namespace std;
inline void NO() { cout << "NO\n"; }
inline void YES() { cout << "YES\n"; }
inline void NEG() { cout << "-1\n"; }
template <typename T>
inline bool chkmax(T &a, T b) {
return a < b ? a = b, true : false;
}
template <typename T>
inline bool chkmin(T &a, T b) {
return a >... | 10 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
const double PI = acos(-1.0);
using namespace std;
const int N = 509, M = 1000000;
int n, m, dis[N][N], in[N][N], ans[N][N], t[N][N];
vector<int> adj[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
;
cin >> n >> m;
int u, v, d;
memset(dis, '?', ... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, q[100001], a[100001], qm;
cin >> m;
for (int i = (0); i <= (m - 1); i++) cin >> q[i];
sort(q, q + m);
cin >> n;
for (int i = (0); i <= (n - 1); i++) cin >> a[i];
sort(a, a + n);
qm = q[0];
long long sum = 0;
for (int i = n - 1, j =... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000 * 1000 * 1000 + 7;
struct edge {
int from, to;
int capacity, flow;
int cost;
int revEdge;
edge() {}
edge(int _from, int _to, int _capacity, int _flow, int _cost, int _revEdge) {
from = _from;
to = _to;
capacity = _capacity;
f... | 14 |
#include <bits/stdc++.h>
using namespace std;
vector<int> e[300000];
int D[300000];
int P[300000];
int was[300000];
void bfs(int s, int forb) {
queue<int> q;
P[s] = -1;
D[s] = 0;
q.push(s);
while (!q.empty()) {
int x = q.front();
q.pop();
vector<int> &ee = e[x];
for (int i = 0; i < ee.size(); ... | 18 |
#include <bits/stdc++.h>
using namespace std;
string s, ans;
int maxx, tt;
int main() {
int cas, n, i, a, b, c, d, e, f, g;
scanf("%d", &n);
maxx = -100000000;
for (i = 0; i < n; i++) {
cin >> s;
scanf("%d%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f, &g);
tt = a * 100 - b * 50 + c + d + e + f + g;
if (... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long int n, k;
cin >> n >> k;
long long int a, b, c, d;
cin >> a >> b >> c >> d;
if (n == 4 || k < n + 1) {
cout << -1 << "\n";
return 0;
}
long long int i;
deque<long long int... | 8 |
#include <bits/stdc++.h>
using namespace std;
struct Points {
int x, y;
};
int main() {
int r, c, n, k;
cin >> r >> c >> n >> k;
int counter = 0;
vector<Points> points(n);
bool is_violas[r][c];
for (int i = 0; i < r; i++)
for (int j = 0; j < c; j++) is_violas[i][j] = false;
for (int i = 0; i < n; i+... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, x, i, j, x1;
unsigned long long kol = 0, sum = 0;
int main() {
cin >> n;
for (i = 0; i < n; i++) {
cin >> x;
if (i == 0 || x == x1)
kol++;
else {
sum += kol * kol - kol * (kol - 1) / 2;
kol = 1;
}
x1 = x;
}
sum += kol * k... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int SIZE = 2e5 + 5;
const int inf = 0x7f7f7f7f;
int n, m, num, tim;
int head[SIZE], fa[SIZE], siz[SIZE], son[SIZE], dfn[SIZE], idx[SIZE], bel[SIZE],
dep[SIZE], ans[SIZE];
struct ms {
int u, ti, id, key;
bool operator<(const ms &a) const {
return dep[u] + t... | 25 |
#include <bits/stdc++.h>
int main() {
int n, m, a, b;
int s[50][50];
int t, r(1 << 30);
std::scanf("%d%d", &n, &m);
for (int i(0); i < n; ++i) {
for (int j(0); j < m; ++j) std::scanf("%d", &s[i][j]);
}
std::scanf("%d%d", &a, &b);
for (int x(0); x < 2; ++x) {
for (int i(0); i + a <= n; ++i) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n % 2 == 0) {
cout << "white" << endl;
cout << 1 << " " << 2 << endl;
} else {
cout << "black" << endl;
}
return 0;
}
| 9 |
#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
c b, e;
};
template <class c>
rge<c> range(c i, c j) {
return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
template <class c>
debug& operator<<(const c&... | 6 |
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
using namespace std;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef long long ll;
template <typename T>
inline void read(... | 25 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 400;
int n, m;
int a[maxn];
string s[maxn];
int can[maxn];
int N;
void dfs(int i) {
if (can[i]) return;
can[i] = 1;
for (int j = 0; j <= i && j <= n; ++j)
if (N - i >= n - j) dfs(i - j + n - j);
}
int main() {
cin >> n;
int af;
N = 2 * n - 1... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n, t;
cin >> n >> t;
string s;
cin >> s;
string y = s;
sort(y.begin(), y.end());
reverse(y.begin(), y.end());
if (s == y) {
cout << s;
return 0;
}
long long sec = 0;
wh... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const double eps = 1e-12;
int n, x, y, m, cnt, _end[N];
double p, q, a[N], b[N];
struct Point {
int x, y;
};
pair<double, int> tmp[N];
set<pair<int, int>> S;
template <typename _Tp>
inline void IN(_Tp& x) {
char ch;
bool flag = 0;
x = 0;
whi... | 25 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
int main() {
cin.sync_with_stdio(false);
cout << setprecision(15);
int t, n, l;
cin >> t;
while (t--) {
cin >> n >> l;
vector<int> a(n);
for (auto i = (0); i < (n); ++i) cin >> a[i];
double lo = 0, hi = 1e9 + 5, mid;
wh... | 7 |
#include <bits/stdc++.h>
using namespace std;
struct Edge {
int to;
bool is_positive;
Edge() {}
Edge(int a, bool b) : to(a), is_positive(b) {}
};
int M, N;
vector<int> raw[200200];
vector<Edge> G[400400];
bool visited[400400];
bool satisfied[400400];
bool ans[200200];
void dfs(int v, int p) {
if (visited[v]) ... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 300005, maxm = 512;
const double pi = acos(-1.0);
const long long mod = 998244353LL;
const double eps = 1e-8;
long long ksm(long long a, long long k) {
long long r = 1;
while (k > 0) {
if (k & 1) r *= a, r %= mod;
a = a * a % mod;
k >>= 1;
... | 14 |
#include <bits/stdc++.h>
int const MOD = 998244353;
int invmod(int a) {
int b = MOD;
assert(0 <= a);
assert(a < MOD);
int ax = 1, bx = 0;
while (b) {
int q = a / b;
a -= b * q;
ax -= bx * q;
std::swap(a, b);
std::swap(ax, bx);
}
assert(a == 1);
if (ax < 0) ax += MOD;
assert(ax >= 0... | 15 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
long long n, l;
void Input() { cin >> n >> l; }
void Solve() {
vector<long long> a(n);
for (long long i = 0; i < n; i++) cin >> a[i];
sort(a.begin(), a.end());
long long ans = 0;
for (long long i = l; i <= 100; i++) {
long long t ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x1, y1, x2, y2, x3, y3, x4, y4, d;
cin >> x1 >> y1 >> x2 >> y2;
if (x1 == x2) {
d = abs(y1 - y2);
x3 = d + x2;
x4 = x3;
y3 = y2;
y4 = y1;
} else if (y1 == y2) {
d = abs(x1 - x2);
x4 = x1;
x3 = x2;
y4 = y1 + d;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, l, a[100], temp, max;
while (cin >> n >> l) {
max = 0;
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
if (l <= a[n - 1]) {
for (int i = l; i <= a[n - 1]; i++) {
temp = 0;
for (int j = 0; j < n; j++) tem... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 100;
const long long p = 998244353;
long long a[maxn];
long long qpow(long long a, long long n, long long p) {
long long ans = 1;
while (n) {
if (n & 1) ans *= a, ans %= p;
a *= a, a %= p;
n >>= 1;
}
return ans;
}
int main() {
in... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int a[maxn];
int prefix[maxn];
pair<int, int> data[maxn];
int n;
double INF = 1e15;
struct line {
int k;
int b;
line(int k = 0, int b = 0) : k(k), b(b){};
bool operator<(const line& rhs) const {
return k == rhs.k ? b < rhs.b : k > rhs.k;... | 21 |
#include <bits/stdc++.h>
using namespace std;
const int SZ = 5e6 + 10;
const long long INF = 1e9 + 10;
const long double eps = 1e-8;
long long read() {
long long n = 0;
char a = getchar();
bool flag = 0;
while (a > '9' || a < '0') {
if (a == '-') flag = 1;
a = getchar();
}
while (a <= '9' && a >= '0... | 17 |
#include <bits/stdc++.h>
using namespace std;
inline double foo(int a, int b) {
double val = (double)std::pow(a + b, 2) / (double)(b * a);
return val;
}
void solve(std::vector<int>& st, int n) {
std::sort(st.begin(), st.end());
std::unordered_map<int, int> cnt;
int c = 1;
for (int i = 1; i != st.size(); ++i... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie();
int k, n, s, p;
cin >> k >> n >> s >> p;
int cnt = (n + s - 1) / s;
cnt *= k;
cout << (cnt + p - 1) / p;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 402;
int a[maxn], f[maxn][2];
int n, m, s, ans;
int main() {
int i, j, k;
scanf("%d%d", &n, &m);
while (m--) {
scanf("%d", &k);
while (k--) {
scanf("%d", &i);
a[i] = ++s;
}
}
for (k = 1; k <= n; k++)
if (!a[k]) break;
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int MN = 500 + 10;
const int inf = (1 << 30);
int dp[MN][27][27], n, m;
char arr[MN][MN];
int cnt(int p, int a, int b) {
if (p == -1) return 0;
int s = 0;
char ch1 = 'a' + a;
char ch2 = 'a' + b;
for (int i = 0; i < m; i++) {
if (i % 2 && arr[p][i] != ch2... | 12 |
#include <bits/stdc++.h>
using namespace std;
double dp[2][2][250][280];
inline int val(int st) {
int cnt = 0;
for (int i = 0; i < 8; ++i, ++cnt)
if (st & (1 << i)) break;
return cnt;
}
int main() {
int x, K, p;
scanf("%d%d%d", &x, &K, &p);
double mul = 1.0 * p / 100, add = 1 - mul;
int fg = (x >> 8) ... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int n, a, b, lo(0), lc(0), ro(0), rc(0);
cin >> n;
while (n--) {
cin >> a >> b;
if (a)
lo++;
else
lc++;
if (b)
ro++;
else
rc++;
}
cout << mi... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
std::cerr... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
int n, m, a, b, k, s[105], t[105], g[105][105], cnt[105], dp[105][105];
bool must[105][105];
bool on(int i, int j) { return g[s[i]][j] + g[j][t[i]] == g[s[i]][t[i]]; }
int main() {
scanf("%d%d%d%d", &n, &m, &a, &b);
memset(g, 0x3f, sizeof g);... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long n;
cin >> n;
long long ans = n;
while (n >= 10) {
long long value = n % 10;
long long value1 = n / 10;
n = value + value1;
ans += value1;
}
cout << ans << "\n";
}
... | 1 |
#include<bits/stdc++.h>
#include<string.h>
#define ll long long
#include<vector>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int mod=1e9+7;
ll fact[200005];
void fat(int n=200005){
fact[0]=1;
for(int i=1;i<n;i++){
fact[i]=(fact[i-1]*i)%mod;
}
}
int main(){
IOS;
int t;... | 6 |
#include <bits/stdc++.h>
using namespace std;
const double INF = 1E18;
const double EPS = 1e-9;
const int MAXN = 1E5 + 10;
vector<pair<long long, long long> > a[5];
int n, k;
long long b, c;
int main() {
cin >> n >> k >> b >> c;
if (c * 5 < b) b = c * 5;
for (int i = 0; i < n; i++) {
long long t;
cin >> t... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, m2, l = 0, r, i;
cin >> n >> m;
m--;
r = n;
vector<long long> res(n);
for (m2 = (long long)(1) << (n - 2), i = 1; m2 > 0; m2 >>= 1, i++) {
if (m2 & m)
res[--r] = i;
else
res[l++] = i;
}
res[l] = i;
for (i = ... | 6 |
#include <bits/stdc++.h>
using namespace std;
bool prost(int n) {
for (int i = 2; i < n / 2 + 1; ++i) {
if (n % i == 0) {
return false;
}
}
return true;
}
int nok(int x, int y) {
int a = x;
int v = y;
int c = 0;
for (;;) {
if (x == 0 || y == 0) {
c = max(x, y);
break;
}
... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct abc {
int rc, x;
} st[1000000];
int k = 0, ans = 0;
int main() {
ios_base::sync_with_stdio(false);
int n, m;
cin >> n >> m;
int a[n][m];
if (m < n) {
int mm = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> a[i]... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t;
cin >> t;
while (t--) {
long long int n, m;
cin >> n >> m;
long long int a[n];
unordered_set<long long int> s;
for (long long int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < m; i++) {
long long int x;... | 4 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimization("unroll-loops, no-stack-protector")
#pragma GCC target("avx,avx2,fma")
class min_cost_flow {
public:
struct edge_node {
long long to;
long long capacity, flow;
long long cost;
long long reverse_id;
... | 16 |
#include <bits/stdc++.h>
using namespace std;
bool func(int i) {
vector<int> v(10, 0);
while (i) {
int k = i % 10;
i = i / 10;
v[k]++;
if (v[k] == 2) return false;
}
return true;
}
int main() {
int a, b;
cin >> a >> b;
vector<int> v;
int k = a;
for (int i = 0; i < b - a + 1; i++) {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, arr[100][2], a, b, c, sum;
memset(arr, 0, sizeof(arr));
scanf("%d %d", &n, &m);
for (int i = 0; i < m; i++) {
scanf("%d %d %d", &a, &b, &c);
arr[a - 1][1] += c;
arr[b - 1][0] += c;
}
sum = 0;
for (int i = 0; i < n; i++) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
vector<int> g[10];
int F[1000100];
int f(int n) {
if (F[n] != 0) return F[n];
int nn = n;
int m = 1;
while (n) {
if (n % 10) m *= n % 10;
n /= 10;
}
return F[nn] = m;
}
int G(int n) {
if (n < 10) return n;
return G(f(n));
}
signed main() {
int q;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
using PII = pair<int, int>;
class Event {
public:
int i, j;
long long value;
Event(int i = 0, int j = 0, long long value = 0) : i(i), j(j), value(value){};
bool operator<(const Event &rhs) const { return value < rhs.value; }
};
vector<long long> a, b;
vector<Event>... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2005;
const int MOD = 998244353;
int TC;
int N, K;
string S, A, B;
int C[26];
bool cant[26];
int op = 0;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> TC;
while (TC--) {
memset(C, -1, sizeof C);
memset(cant, 0, sizeof can... | 15 |
#include <bits/stdc++.h>
using namespace std;
int t, n, k, s;
int le[111], ra[111];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n;
for (t = 1; t <= n; t++) cin >> le[t] >> ra[t];
cin >> k;
for (t = 1; t <= n; t++)
if (k <= ra[t]) s++;
cout << s;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
ifstream in("input.txt");
ofstream out("output.txt");
vector<int> v[500001];
vector<vector<int>> v2(101), g2(101);
vector<pair<int, int>> vi[100001];
set<int> st;
int vis[500001] = {0};
int a[100001];
vector<int> arr;
vector<int> ar;
int ma = 0;
void dfs(int x, int p) {
m... | 8 |
#include <bits/stdc++.h>
using namespace std;
bool fun(const pair<long long int, long long int> &a,
const pair<long long int, long long int> &b) {
if (a.second == b.second) {
return a.first > b.first;
} else {
return a.second > b.second;
}
}
int main() {
ios_base::sync_with_stdio(NULL);
cin.t... | 3 |
#include <bits/stdc++.h>
using namespace std;
int start[411111], finish[411111], L[411111], R[411111], M[411111], was[411111],
px[411111], py[411111], cn = 0;
int h, m, n;
void Init(int h, int m) {
int pos = 0;
for (int i = 0; i < h; i++)
if (!was[i]) {
int j = i;
start[cn] = pos;
pos++;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
struct Dsu {
int n, m;
vector<vector<pair<int, int>>> par;
Dsu(int n_ = 0, int m_ = 0) : n(n_), m(m_) {
par = vector<vector<pair<int, int>>>(n, vector<pair<int, int>>(m));
}
bool valid(int x, int y) { return min(x, y) >= 0 && min(n - x, m - y) > 0; }
pair<in... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int m1, m2, h1, h2;
char c;
cin >> h1 >> c >> m1 >> h2 >> c >> m2;
int sum1 = h1 * 60 + m1;
int sum2 = h2 * 60 + m2;
sum1 -= sum2;
if (sum1 < 0) sum1 += 24 * 60;
h1 = sum1 / 60;
m1 = sum1 % 60;
if (h1 < 10) cout << 0;
cout << h1 << ":";
... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long a[100005];
long long maxzuo[100005];
long long maxyou[100005];
long long minzuo[100005];
long long minyou[100005];
int main() {
long long n, p, q, r;
cin >> n >> p >> q >> r;
for (int i = 1; i <= n; i++) cin >> a[i];
long long maxx = a[1];
long long minn... | 7 |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:64000000")
using namespace std;
const int MAXN = 100000 + 10;
vector<int> g[MAXN];
bool used[MAXN];
int timer, tin[MAXN], fup[MAXN], color[MAXN];
int n, cnt = 0;
set<pair<int, int> > bridges;
void IS_BRIDGE(int a, int b) {
bridges.insert(make_pair(min(a, b), ma... | 8 |
#include <bits/stdc++.h>
using namespace std;
string s[2000];
int main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
for (int i = 1; i <= n; ++i) cin >> s[i];
int ans = 0;
for (int i = 0; i < 7; ++i) {
int cnt = 0;
for (int j = 1; j <= n; ++j) {
cnt += s[j][i] - '0';
}
ans = max(an... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, m, v, c1, c2, q, a[120000], b[120000];
int main() {
while (cin >> n >> m >> c1 >> c2 >> v) {
for (int i = 0; i < c1; i++) {
cin >> a[i];
}
for (int i = 0; i < c2; i++) {
cin >> b[i];
}
int q;
cin >> q;
while (q--) {
int... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, t, ans;
vector<int> v[102], vec;
int main() {
cin >> n >> t;
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
v[x].push_back(y);
}
for (int i = 1; i <= t; i++) {
vector<int> temp;
for (int j = 0; j < ((int)vec.size()) / 2; j++)
... | 13 |
#include <bits/stdc++.h>
using namespace std;
long int mod = 1000000007;
int n;
vector<long long> cost;
vector<string> str, rev;
long long dp[100010][2];
long long func(int pos, int flip) {
if (pos == n - 1) {
return 0;
}
if (dp[pos][flip] != -1) {
return dp[pos][flip];
}
long long ans = 1e16;
if (f... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 5;
const int M = 1e6 + 5;
struct DSU {
int fa[N];
int find(int x) { return (x == fa[x]) ? x : (fa[x] = find(fa[x])); }
void init(int n) {
for (int i = 0; i <= n; i++) fa[i] = i;
}
void joint(int u, int v) {
u = find(u), v = find(v);
... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
const int mod = 1000000007;
void add(int &x, int y) {
if ((x += y) >= mod) x -= mod;
}
int d[21][N];
int lp[N], pr[N], len = 0;
void precalc() {
for (int r = 0; r <= 1000000; ++r) d[0][r] = 1;
for (int i = 1; i < 20; ++i) d[i][0] = 2;
for (int... | 17 |
#include <bits/stdc++.h>
using namespace std;
int n, m, a[100005], l[100005], r[100005], b, c;
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%d", a + i);
l[i] = 1 + (a[i] <= a[i - 1] ? l[i - 1] : 0);
}
for (int i = n; i >= 1; i--) r[i] = 1 + (a[i] <= a[i + 1] ? r[i + 1] : 0);... | 9 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool GetMin(T &a, T b) {
return ((a <= b) ? false : (a = b, true));
}
template <typename T>
bool GetMax(T &a, T b) {
return ((a >= b) ? false : (a = b, true));
}
const long long N = 233;
const long long SX = 2333 + 10;
const long long MOD = 1e9 + 7... | 15 |
#include <bits/stdc++.h>
using namespace std;
int ans[1000100], n, m, c[1000100];
vector<int> q[1000100], belong[1000100], line[1000100];
inline int getint() {
int w = 0, q = 0;
char c = getchar();
while ((c < '0' || c > '9') && c != '-') c = getchar();
if (c == '-') q = 1, c = getchar();
while (c >= '0' && c... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
while (cin >> n >> m) {
vector<vector<pair<int, string> > > p(m, vector<pair<int, string> >());
for (int i = 0; i < n; ++i) {
pair<int, string> q;
int r;
cin >> q.second >> r >> q.first;
p[r - 1].push_back(q);
}... | 5 |
#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
const int N = 2002, NN = 502, mod = 1e9 + 7, mod1 = 1e9 + 9, Base = 317,
Base1 = 371;
int n, K, pw[NN], pw1[NN], lcp[N], mn[N][11], id[N];
string s[N];
struct Hash {
vector<pair<int, i... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, ans = 1, now = 1, INF = (int)1e9;
cin >> n;
vector<int> A(n), D((int)1e7, INF);
for (int i = 0; i < n; i++) cin >> A[i];
D[0] = -INF;
for (int i = 0; i < n; i++) {
int j = int(upper_bound(D.begin(), D.end(), A[i]) - D.begin());
if (D[... | 7 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
long long t;
cin >> t;
while (t--) {
long long n, cnt = 0;
cin >> n;
long long ans = (n % 10 - 1) * 10;
while (n != 0) {
n /= 10;
cnt++;
}
ans += ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
string s, a, b;
vector<long long> dp[2];
long long n;
cin >> n;
cin >> s;
long long x = (n + 1) / 2;
while (s[x] == '0') {
x++;
if (x == n) {
x = -1;
break;
}
... | 7 |
#include <bits/stdc++.h>
using namespace std;
map<int, int> A3;
int main() {
double x1, y1, a, mn = -1;
cin >> x1 >> y1 >> a;
for (int i = 0; i < a; i++) {
double xn, yn, speedn;
cin >> xn >> yn >> speedn;
if (mn == -1) {
mn = sqrt((xn - x1) * (xn - x1) + (yn - y1) * (yn - y1)) / speedn;
} e... | 1 |
#include <bits/stdc++.h>
template <class T>
T gcd(T a, T b) {
T r;
while (b != 0) {
r = a % b;
a = b;
b = r;
}
return a;
}
template <class T>
T lcm(T a, T b) {
return a / gcd(a, b) * b;
}
using namespace std;
const long long MOD = 1e18;
long long m, n, k, a[200005];
string s;
int main() {
double... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int mod = (int)1e9 + 7;
int n, m, X;
int f[2][350][350], sw;
int Ans;
void dpto(int x, int& a) {
if (a += x, a >= mod) a -= mod;
}
void trans(int x, int a[][350], int b[][350]) {
for (int i = 0; i <= n; i++)
for (int j = 0; j <= n; j++) b[i][j] = 0;
for (int... | 19 |
#include <bits/stdc++.h>
using namespace std;
long long n;
vector<long long> arr;
vector<long long> s;
vector<long long> lazy;
void build(long long id = 1, long long l = 0, long long r = n) {
if (r - l == 1) {
s[id] = arr[l];
return;
}
long long mid = (l + r) / 2;
build(2 * id, l, mid);
build(2 * id +... | 14 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long res = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
res = res * 10 + c - '0';
c = getchar();
}
return res * f;
}
const long l... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, i, j, k, x, y, z, sum = 0, ans = 0, ma = 0, mi = 2000000000,
a[100005] = {0}, p, mini = 2000000000,
maxi = 0, pos, po;
long long b[100005] = {0}, low, mid, high;
strin... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000000 + 23;
string s, ss;
int word[maxn], ans, a[maxn], last, l, r, len, html[maxn], type[maxn],
dad[maxn], x, size, n, m, node;
map<string, int> M;
char c;
vector<int> G[maxn];
void init(int k) {
while (x < n) {
x++;
if (type[x] == 1) retur... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2020202020;
int N;
int X[1010];
int Y[1010];
vector<pair<int, int> > V[1010];
vector<pair<int, int> > H[1010];
vector<int> xs, ys;
bool chk[1010];
struct DSU {
int p[1010];
int n, com;
void init(int _n) {
n = com = _n;
for (int i = 1; i <= n; i... | 20 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long N = 105;
long long m;
struct node {
long long row, col;
long long data[N][N];
node(long long n, long long m) {
row = n;
col = m;
for (long long i = 0; i <= n; i++)
for (long long j = 0; j <= n; j++) data... | 15 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.