solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
long long t, a, b;
cin >> t >> a >> b;
if (t == 1 && a == 1 && b == 1) {
cout << "inf\n";
} else if (b < a || a < t) {
cout << (a == b ? 1 : 0) << endl;
} else if (a == t) {
cout << (a == b ? 2 : 0) << e... | 20 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
int t;
cin >> t;
for (int w = 0; w < t; w++) {
cin >> str;
int xleft = 0, xright = 0, ytop = 0, ydown = 0;
bool X = false, Y = false;
int x = 0, y = 0;
for (int i = 0; i < str.size(); i++) {
char c = str[i];
s... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 200007;
const int MOD = 1000000007;
void solve() {
long long n, a, d;
cin >> n >> a >> d;
cout << a * 445049 * 1500000 + 1 << " " << d * 445049 * 1500000;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
}
| 27 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int id;
int d;
int next;
} side[2020000];
int head[20200];
int cnt = 0;
void init() {
memset(head, -1, sizeof(head));
cnt = 0;
}
void add(int x, int y, int d) {
side[cnt].id = y;
side[cnt].d = d;
side[cnt].next = head[x];
head[x] = cnt++;
}
s... | 12 |
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using std::cin;
using std::cout;
using std::lower_bound;
using std::string;
using std::upper_bound;
using std::vector;
using vi... | 8 |
#include <bits/stdc++.h>
using namespace std;
string grid[3];
int vis[3][110][1000], visID;
int t, n, k;
bool solve(int i, int j, int t) {
if (j == n) return 1;
if (j + t < n && grid[i][j + t] != '.' && grid[i][j + t] != 's') return 0;
if (j + t + 1 < n && grid[i][j + t + 1] != '.') return 0;
if (vis[i][j][t] =... | 9 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &first) {
char c;
bool nega = 0;
while ((!isdigit(c = getchar())) && (c != '-'))
;
if (c == '-') {
nega = 1;
c = getchar();
}
first = c - 48;
while (isdigit(c = getchar())) first = first * 10 + c - 48;
if ... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
n = abs(n);
long long int index = 0;
while (true) {
long long int x = (index * (index + 1)) / 2;
if (x == n) {
cout << index << '\n';
return 0;
}
if (x > n && (x - n) % 2 == 0) {
cout << ind... | 8 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const int mod = (int)1e+9 + 7;
const double pi = acos(-1.);
const int maxn = 100100;
vector<pair<long long, int> > st[maxn];
long long add[maxn];
int main() {
srand(time(0));
const string file = "";
if (!file.empty()) {
freopen((file + ".i... | 17 |
#include <bits/stdc++.h>
using namespace std;
string forb[100];
string w;
vector<pair<int, int> > v;
bool chg[100], caps[100];
char let;
void shifts(int id) {
int i = 0, p;
while (1) {
p = w.find(forb[id], i);
if (p == string::npos) return;
v.push_back(make_pair(p, p + forb[id].size() - 1));
i = p +... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, l, r, c, pl, pr, cl, cr;
cin >> a >> b >> l >> r;
c = a + b;
cl = --l / c;
cr = --r / c;
pl = l % c;
pr = r % c;
if (cl == cr) {
if (pl < a && pr < a) {
cout << pr - pl + 1 << endl;
} else if (pl < a && pr >= a) {
c... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
pair<int, int> perechi[maxn];
int v[maxn];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> v[i];
sort(v + 1, v + n + 1);
perechi[1] = make_pair(v[1], 1);
int poz = 1;
for (int i = 2; i <= n; i++) {
if (v[i] == v[i... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e6 + 7;
queue<int> que[26];
long long ans = 0;
long long temp[maxn];
void Merge(long long a[], long long b[], long long l, long long m,
long long r) {
long long i = l, j = m + 1, k = l;
while ((i <= m) && (j <= r))
if (a[i] <= a[j]... | 11 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000")
using namespace std;
int m[2010][2010], u[2010][2010], n, i1, i2, j1, j2, di[] = {-1, 1, 0, 0},
dj[] = {0, 0, -1, 1}, s, c;
void dfs(int i, int j) {
int k;
i1 = min(i1, i);
i2 = max(i2, i);
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int hh, mm;
cin >> hh >> mm;
int h, d, c, n;
cin >> h >> d >> c >> n;
int leftTime = (60 - mm) + (20 - hh - 1) * 60;
if (hh >= 20 && hh <= 23) {
float cost = h / n + (h % n != 0);
cost = cost * c * 0.8;
cout << fixed << setprecision(4) <... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long Set(long long n, long long pos) { return n | (1LL << pos); }
bool Check(long long n, long long pos) { return (bool)(n & (1LL << pos)); }
long long t[110], w[110];
long long dp2[110][210];
long long dp[110][210];
int main() {
long long cs, ts, i, j, k, x, y, z, q... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int Q = 1e5 + 7;
int H, O;
int C[10007][444], a[Q], W[Q];
int M[Q];
vector<int> T;
void L(int p) {
if (p > 10000) return;
T.push_back(p);
M[p] = true;
p *= 10;
L(p + 4);
L(p + 7);
}
void A(int l, int r, int d) {
int p1 = l / H;
int p2 = r / H;
for (i... | 16 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
struct TNode {
long long value;
long long add;
TNode(long long value_, long long add_) : value(value_), add(add_) {}
TNode() : value(0), add(0) {}
static TNode neutral() { return TNode(INF, 0); }
static TNode combine(const TNode& a, c... | 14 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
int main() {
cin >> n >> n >> k;
cout << (n * (n - 1)) / 2 << endl;
if (k == 1) {
for (int i = (int)(n - 1); i > (int)(0); --i)
for (int j = (int)(1); j < (int)(i + 1); ++j)
cout << j + 1 << " " << j << endl;
} else {
for (int i = (in... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int kMaxM = 100005;
long long min_len[kMaxM];
struct Coupon {
int q;
int w;
bool operator<(const Coupon& other) const { return w > other.w; }
} coupons[kMaxM];
int main() {
int n, m;
int used = 0;
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++) {
... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char a[65005];
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
int sum = 0;
for (int i = 1; i <= n; i++) {
if ((a[i] - '0') % 2 == 0) sum += i;
}
cout << sum;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
while (a && b) a > b ? a %= b : b %= a;
return a + b;
}
long long int lcm(long long int a, long long int b) {
return (max(a, b) / gcd(a, b)) * min(a, b);
}
int main() {
ios::sync_with_stdio(0);
;
long long in... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
using ll = long long;
struct Hole {
int p, c;
} a[N];
int x[N], n, m;
ll dp[N][N], s[N], sum[N];
int main() {
ios::sync_with_stdio(false);
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> x[i];
for (int i = 1; i <= m; i++) cin >> a[i].p >> a[... | 18 |
#include <bits/stdc++.h>
using namespace std;
long long a[100005], n, s, ans;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
while (n--) {
long long x;
cin >> x;
s += x;
a[x]++;
}
if (s == 1 or s == 2 or s == 5) return cout << -1, 0;
while (a[1] > 0 and... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int INF = (long long int)(1LL << 30) - 1;
const double INFd = 100000000000.0;
const long long int INFl = (long long int)9223372036854775807;
const int MAX = 10000;
const long long int MOD = (long long int)998244353;
long long int gcd(long long int a, long long int b) ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)1e18;
const long long mod = (long long)1e9 + 7;
const double eps = (double)1e-9;
const double pi = acos(-1.0);
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};
const int N = 16;
const int M = 5005;
map<long long, int> po... | 16 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T next_int() {
T x = 0, p = 1;
char ch;
do {
ch = getchar();
} while (ch <= ' ');
if (ch == '-') {
p = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + (ch - '0');
ch = getchar();
}
return x * p;... | 16 |
#include <bits/stdc++.h>
using namespace std;
int N, arr[100002], arr2[100002], maxi[100002], mini[100002];
int main() {
scanf("%d", &N);
for (int i = 0; i < N; i++) scanf("%d", &arr[i]);
for (int i = 0; i < N; i++) {
maxi[i] = max(abs(arr[i] - arr[0]), abs(arr[i] - arr[N - 1]));
mini[i] = 1e9 * 2 + 5;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {
int v;
istringstream sin(s);
sin >> v;
return v;
}
template <class T>
inline string toStr(T x) {
ostringstream sout;
sout << x;
return sout.str();
}
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, t;
cin >> n;
int a = 0;
for (int i = 0; i < n; i++) {
cin >> t;
if (a == 1 && t == 0) {
cout << "NO";
return 0;
}
if (t % 2 == 1) a ^= 1;
}
if (a)
cout << "NO";
else
cout << "YES";
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 105;
const long long mod = 1000000007;
int main() {
printf("black\n");
return 0;
}
| 10 |
#include <bits/stdc++.h>
using namespace std;
int oo = (int)1e9;
int main() {
int n;
scanf("%d", &n);
map<int, int> cnt;
int cur;
for (int i = 0; i < n; ++i) {
scanf("%d", &cur);
cnt[cur]++;
}
for (map<int, int>::iterator it = cnt.begin(); it != cnt.end(); ++it) {
if (it->second > ceil(n / 2.0... | 3 |
#include <bits/stdc++.h>
inline long long max(long long a, long long b) { return a > b ? a : b; }
inline long long min(long long a, long long b) { return a < b ? a : b; }
int main() {
long long l, r;
scanf("%lld %lld", &l, &r);
long long t = 1;
while (t <= r) t *= 10;
long long p = min(max(t / 2, l), r);
pr... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long x, y;
void gcdex(long long a, long long b, long long &g, long long &x, long long &y) {
if (!b) {
g = a;
x = 1;
y = 0;
} else {
gcdex(b, a % b, g, y, x);
y -= a / b * x;
}
}
long long safeMul(long long a, long long b, long long mod) {
lo... | 20 |
#include <bits/stdc++.h>
using namespace std;
string s;
bool e = true;
int n, cnt = 0;
int main() {
cin >> n;
cin >> s;
int sz = s.size();
string b = "0000000000";
for (int i = 0; i < n; i++) {
if (s[i] == 'L') {
for (int j = 0; j < 10; j++) {
if (b[j] == '0') {
b[j] = '1';
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b, c, d;
while (scanf("%d", &n) != EOF) {
bool flag = true;
for (int i = 1; i <= 4; i++) {
scanf("%d%d%d%d", &a, &b, &c, &d);
if (flag && min(a, b) + min(c, d) <= n) {
flag = false;
printf("%d %d %d\n", i, min(a... | 3 |
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include<bits/stdc++.h>
#define X first
#define Y second
#define sz(a) (int)a.size()
#define ll long long
using namespace std;
const int mod1 = 1e9 + 7;
const int mod2 = 998244353;
const int N = 2e5 + 100;
struct node{
int tin, tout;
int go_to[2... | 22 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, val;
vector<int> box;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> val;
box.push_back(val);
}
sort(box.begin(), box.end());
for (int i = 0; i < n; i++) {
cout <<... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long int minn(long long int a, long long int b) { return a < b ? a : b; }
long long int maxx(long long int a, long long int b) { return a > b ? a : b; }
long long int mod_exp(long long int a, long long int n, long long int mod) {
if (n == 0) return 1;
if (n % 2 == ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N(100010), L(17), P(53);
int n;
long long sc[N][26];
int glen[L + 1];
bool gray[L + 1][N];
int cnt[N][26];
long long cut[N];
long long ha[N], p[N];
char s[N];
bool same(int x, int y, int len) {
if (x > y) swap(x, y);
long long h1 = ha[x + len - 1] - ha[x - 1],... | 22 |
#include <bits/stdc++.h>
using namespace std;
long long int tt;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int t;
cin >> t;
while (t--) {
long long int n, k;
cin >> n >> k;
long long int x = sqrt(n);
long long int ans = 1e18;
for (long long in... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chkmin(T &a, const T &b) {
return a > b ? a = b, 1 : 0;
}
template <typename T>
inline bool chkmax(T &a, const T &b) {
return a < b ? a = b, 1 : 0;
}
const int oo = 0x3f3f3f3f;
inline int rt2(const long long &first) {
int tmp = sqrt(f... | 16 |
#include <bits/stdc++.h>
using namespace std;
int Day12[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int prime100[] = {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, 101, 103};
template <typename T>
inline bool isLeap(T y) {
return (y % ... | 8 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic ignored "-Wmissing-declarations"
inline int safe_mul(const int x, const int y)
__attribute__((warn_unused_result));
int const mod = 998244353;
inline int safe_mul(const int x, const int y) {
return x * static_cast<long long>(y) % mod;
}
inline v... | 18 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using maxHeap = priority_queue<T, vector<T>, less<T>>;
template <typename T>
using minHeap = priority_queue<T, vector<T>, greater<T>>;
template <typename Iter>
ostream& _out(ostream& s, Iter b, Iter e) {
s << "[";
for (auto it = b; it != e; it++) s... | 10 |
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
struct str {
int i1, j1, i2, j2;
str(int _i1 = -1, int _j1 = -1, int _i2 = -1, int _j2 = -1)
: i1(_i1), j1(_j1), i2(_i2), j2(_j2){};
};
int main() {
int n, k;
cin >> n >> k;
vector<string> s(n);
for (int i = 0; i < int((s).s... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int c1 = 0, c2 = 0, c3 = 0;
for (int i = 0; i < n; i++) {
if (a[i] == 1) {
c1++;
} else if (a[i] == 2) {
c2++;
} else {
c3++;
}
}
cou... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long rec[20000000];
int main() {
long long n, sum;
memset(rec, 0, sizeof(rec));
for (int i = 1; i < 20000000; ++i) rec[i] = i + rec[i - 1];
while (~scanf("%I64d", &n)) {
int i;
sum = 0;
for (i = 1; i < 20000000; ++i) {
if (rec[i] > n) break;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a, b, passenger = 0, max = 0;
while (n--) {
cin >> a >> b;
passenger = (passenger - a) + b;
if (passenger > max) max = passenger;
}
cout << max << "\n";
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int compare(const void* a, const void* b) { return (*(int*)a - *(int*)b); }
int binary_search(const int* arr, int start, int end, const int val) {
int mid = (end + start) / 2;
if (arr[mid] <= val && arr[mid + 1] >= val) {
if (arr[mid] == val && arr[mid + 1] >= val) ... | 6 |
#include <bits/stdc++.h>
inline int read() {
register int x;
register char c;
while (!isdigit(c = getchar()))
;
x = c ^ 48;
while (isdigit(c = getchar())) x = (x << 1) + (x << 3) + (c ^ 48);
return x;
}
int n, m, k;
struct Graph {
int edge_size, head[200010];
int node[200010 << 1], next[200010 << 1]... | 13 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const long long mod = 1e9 + 7;
long long n, k, x, y, s, inv[1 << 18], f[1 << 18], finv[1 << 18], ans;
map<long long, long long> m;
long long c(long long n, long long k) {
return f[n] * (finv[k] * finv[n - k] % mod) % mod;
}
int32_t main() {
io... | 12 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int x, c;
} a[4003];
long long dp[4003];
bool cmp(node a, node b) { return a.x < b.x; }
int main() {
long long sss, te, te2, ans;
int n, i, j;
while (~scanf("%d", &n)) {
for (i = 0; i < n; i++) scanf("%d%d", &a[i].x, &a[i].c);
if (n == 1) {
... | 10 |
#include <bits/stdc++.h>
using namespace std;
void soivez() {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
}
int main() {
int t;
cin >> t;
vector<int> ans(t);
for (int i = 0; i < t; i++) {
int count = 0;
int n;
cin >> n;
stack<int> s;
for (int j = 0; j < n; j++) ... | 3 |
#include <bits/stdc++.h>
int pr[100010][4], a[100010][4], ans[100010], t;
int n;
void solve() {
int p;
int x = ans[t - 1], y = ans[t - 2];
for (int i = 1; i <= pr[x][0]; i++) {
for (int j = 1; j <= pr[y][0]; j++) {
if (pr[x][i] == pr[y][j] && a[pr[x][i]][3] == 0) {
p = pr[x][i];
a[p][3] ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int t[N], n, a, b, nex, i;
long long ans, s;
char c[N];
int main() {
scanf("%d %d %d", &n, &a, &b);
for (i = 1; i <= n; ++i) scanf("%d %c\n", &t[i], &c[i]);
s = ans = 1ll * n * b;
scanf("%d", &nex);
for (i = n; i >= 1; --i) {
if (c[i] == ... | 23 |
#include <bits/stdc++.h>
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const long long MOD = 1e+9 + 7;
const int INFi = 0x7f7f7f7f;
const long long MAXN = 2e+5 + 7... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1024;
int n, m;
int a[MAX_N][MAX_N];
int dp_ud_b[MAX_N][MAX_N];
int dp_du_b[MAX_N][MAX_N];
int dp_ud_g[MAX_N][MAX_N];
int dp_du_g[MAX_N][MAX_N];
int main() {
int i, j, ans = 0;
scanf("%d%d", &n, &m);
for (i = 1; i <= n; i++)
for (j = 1; j <= m; j... | 8 |
#include <bits/stdc++.h>
const long long int MOD = 1e9 + 7;
const double PI = 22.0 / 7.0;
using namespace std;
long long int max(long long int a, long long int b) { return a >= b ? a : b; }
long long int min(long long int a, long long int b) { return a >= b ? b : a; }
long long int onBits(long long int n) { return __bu... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int a, b;
cin >> a >> b;
for (int i = 0; i < b; i++) {
int q[10010] = {0};
int vis[20020] = {0};
int c;
cin >> c;
int m;
for (int j = 0; j < c; j++) {
cin >> m;
if (m > 0 && vis[10010 + m]... | 5 |
#include <bits/stdc++.h>
using namespace std;
char s[300005];
int n, k = 0;
int dp[300005][27];
long long Answer[27];
int cnt[27];
int hi[300005][27];
int lo[300005][27];
int main() {
scanf("%s", &s);
n = strlen(s);
for (int i = 1; i <= n; i++) {
for (int l = 0; l < 26; l++) dp[i][l] = dp[i - 1][l];
dp[i]... | 12 |
#include <bits/stdc++.h>
using ll = long long;
ll cnt[10], cnt1[10], cnt2[10];
int main() {
std::string s;
std::cin >> s;
int n = s.size();
for (int i = 0; i < n; i++) {
cnt[s[i] - '0']++;
cnt1[s[i] - '0']++;
cnt2[s[i] - '0']++;
}
std::stack<std::pair<int, int>> ans1, ans2;
ll ma = -1;
for (... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 500021;
const int LOGN = 21;
int n, par[N], depth[N], freq[N];
char tmp[N + 1];
vector<int> g[N];
void dfs(int u, int p) {
if (p == -1) depth[u] = 0;
par[u] = p;
for (auto v : g[u]) {
if (v == p) continue;
depth[v] = depth[u] + 1;
dfs(v, u);
... | 23 |
#include <bits/stdc++.h>
using namespace std;
void dfs(int node, vector<int> adj[], vector<int>& visit, int arr[]) {
int c = 0;
visit[node] = 1;
for (int i = 0; i < adj[node].size(); i++) {
int child = adj[node][i];
if (visit[child] == 0 && adj[child].size() != 0) {
dfs(child, adj, visit, arr);
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, t;
double p;
double dp[2005][2005];
int main() {
cin >> n >> p >> t;
dp[1][1] = p;
dp[1][0] = 1 - p;
for (int i = 2; i <= t; i++) {
for (int j = 0; j < n; j++) {
if (j <= i) {
dp[i][j] = dp[i - 1][j] * (1 - p) + dp[i - 1][j - 1] * p;
}... | 9 |
#include <bits/stdc++.h>
using namespace std;
struct aaa {
int x, y;
} a[1010];
;
int n, i, j, x, ans[1010][1010];
bool cmp(aaa a, aaa b) { return a.x > b.x; }
int main() {
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%d", &a[i].x);
a[i].y = i;
}
sort(a + 1, a + n + 1, cmp);
for (i = 1; i <= a... | 18 |
#include <bits/stdc++.h>
int main() {
long long a, b, i, j, n, x, ans[100010];
scanf("%lld %lld %lld", &n, &a, &b);
for (i = 1; i <= n; i++) {
scanf("%lld", &x);
ans[i] = (x * a) % b;
if (ans[i] / a)
ans[i] /= a;
else
ans[i] = 0;
}
printf("%lld", ans[1]);
for (i = 2; i <= n; i++)... | 7 |
#include <bits/stdc++.h>
const long long mod = 1e9 + 7;
const double ex = 1e-10;
using namespace std;
int main() {
long long N;
cin >> N;
long long ans = 0;
if (N < 9)
ans = 1;
else {
long long k = 1;
long long t = N;
while (t != 0) {
t /= 10;
k *= 10;
}
k = k / 10;
ans... | 1 |
#include <bits/stdc++.h>
const int md = 1000000009;
int n, m, i, k;
long long r;
int main() {
scanf("%d%d", &n, &m);
k = r = 1;
for (i = 0; i < m; i++)
if ((k *= 2) >= md) k -= md;
for (i = 0; i < n; i++) {
if (--k < 0) k += md;
r = (r * k) % md;
}
printf("%d\n", int(r));
return 0;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
scanf("%lld", &n);
long long x;
scanf("%lld", &x);
long long y1 = 7 - x;
long long i;
long long flag = 0;
for (i = 0; i < n; i++) {
long long a, b;
scanf("%lld", &a);
scanf("%lld", &b);
if (a == x || a == y1 || b == ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
unsigned short t, n, digit;
cin >> t;
for (int i = 0; i < t; i++) {
cin >> n;
if (n == 10000)
cout << 1 << "\n" << 10000 << endl;
else {
int count = 0;
unsigned short d[4];
for (int j = 0; j < 4; j++) {
d[j] = n... | 0 |
#include <bits/stdc++.h>
using namespace std;
string s;
int x, y;
int main() {
cin >> s;
for (int i = 0; i < s.size(); i++) {
if (s[i] == 'x') {
x++;
} else {
y++;
}
}
if (x > y) {
x -= y;
y = 0;
} else {
y -= x;
x = 0;
}
for (int i = 0; i < y; i++) {
cout << "y... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-9;
const long long MOD = 1e9 + 7;
pair<long long, int> inp[100100];
int right_dir_sum[100100], left_dir_sum[100100];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout << setprecision(20);
int n;
cin >> n;
long long l, ... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x7fffffff;
const int MINF = 0x80000000;
const long long mod = 1000000007;
const int cons = 100001;
int main() {
int a, b;
scanf("%d%d", &a, &b);
int tmp;
int tmpm;
int ans = a;
while (1) {
tmp = a / b;
if (tmp == 0) break;
tmpm = a %... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int speed[4300], ram[4097], hdd[505], cost[1005], i, j;
int n;
cin >> n;
for (i = 0; i < n; i++) {
cin >> speed[i] >> ram[i] >> hdd[i] >> cost[i];
}
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
if (speed[i] < speed[j] && ram[i] ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, i, k, a[10], b[10], order[10], mu[10], result, Max, Min;
bool check[10];
void process(int x) {
if (x == k) {
int t;
memset(b, 0, sizeof(b));
for (int i = 1; i <= n; ++i) {
t = a[i];
for (int j = 0; j < k; ++j) {
b[i] = b[i] + mu[k - ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 15;
const int inf = 1e9;
const int md = 1e9 + 7;
int n;
vector<int> g[maxn];
int root;
int len[maxn];
int u[maxn];
vector<vector<int> > fenf;
vector<int> num[maxn];
vector<pair<int, int> > z;
int sum(int w, int r) {
int res = 0;
for (; r >= 0; r =... | 13 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
const int N = 1000000 + 5;
const int mod = 1e9 + 7;
const int inf = 2e9;
vector<int> vis(100 + 5, 0);
vector<int> adj[100 + 5];
vector<int> p(N, 0);
bool cmp(pair<int, int> a, pair<int, int> b) { return a.first > b.first; }
int main() {
int n, m, i, x... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int T = 1;
cin >> T;
while (T--) {
int n, m, k;
cin >> n >> m >> k;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int K = k;
k = min(k, m - 1);
... | 8 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T poww(T b, T p) {
long long a = 1;
while (p) {
if (p & 1) {
a = (a * b);
}
p >>= 1;
b = (b * b);
}
return a;
}
template <class T>
inline T poww2(T b, int p) {
T a = 1;
while (p) {
if (p & 1) {
a = (a * b... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int N = 220;
int n, k, m, p;
long double sum, res;
long long a[N], dp[N][N], q[N];
int main() {
ios_base::sync_with_stdio(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
sum += a[i];
}
cin >> p;
if (p >= sum) {
co... | 11 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
long long n, a[1001], b[1001];
cin >> n;
for (long long i = 1; i <= n; i++) cin >> a[i], a[i] |= a[i - 1];
for (long long i = 1; i <= n; i++) cin >> b[i], b[i] |= b[i - 1];
long long ans = 0;
for ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int t;
int main() {
ios_base::sync_with_stdio(0);
cout.tie(0);
cin.tie(0);
cin >> t;
while (t--) {
vector<int> v((int)1e6 + 5);
vector<int> a;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
a.push_back(x);
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
long long int b[n], arr[n];
for (int i = 0; i < n; i++) {
cin >> b[i];
arr[i] = b[i];
}
sort(arr, arr + n);
int fl... | 2 |
#include <bits/stdc++.h>
using namespace std;
class trio {
public:
long long first, second, third;
};
long long power(long long x, long long y) {
long long ans = 1, second = x;
while (y) {
if (y & 1) {
ans *= second;
ans %= 998244353;
}
second *= second;
second %= 998244353;
y >>=... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
int x, y, z;
cin >> x >> y >> z;
if (x == y && y >= z) {
cout << "YES\n";
cout << x << " " << z << " " << z << "\n";
} else if (x =... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1005, M = 1.4e7;
int n, a[N], ans[N], l[M];
vector<int> v[2];
void no() {
puts("NO");
exit(0);
}
void yes() {
puts("YES");
for (int i = 0; i < n; i++) printf("%d ", ans[i]);
exit(0);
}
signed main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) ... | 18 |
#include <bits/stdc++.h>
using namespace std;
void printVec(vector<int> v) {
cout << "[";
for (auto val : v) cout << val << ' ';
cout << "]\n";
}
int n;
int main(void) {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
int b;
int v[2];
v[0] = 0;
v[1] = 0;
for (int i = 0; i < n; i++) {
cin >> b;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long pwr(long long a, long long b) {
if (b == 0) return 1;
long long c = pwr(a, b / 2);
c = c * c;
if (b % 2) return c * a;
return c;
}
long long pwr(long long a, long long b, long long m) {
if (b == 0) return 1;
long long c = pwr(a, b / 2, m) % m;
c = ... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 20;
int in[N][N];
int i, j, k, n;
int ans;
void loop(int i, int n, void f(int)) {
(i == n) ? 42 : (f(i), loop(i + 1, n, f), 42);
}
void readInt(int j) { scanf(" %d", &in[i][j]); }
void readLine(int i) {
::i = i;
loop(0, n, &readInt);
}
void relaxJ(int j)... | 12 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
string s;
cin >> s;
int cnt = 0;
for (int i = 0; i < n; i++) {
if (s[i] == '2') {
cnt++;
}
}
if (cnt == 0) {
cout << "YES" << endl;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
cerr << ' ' << H;
dbg_out(T...);
}
const long double pi = 3.14159265359;
const long long mod = 1000000007;
const long long modc = 998244353;
const long long inf... | 5 |
#include <bits/stdc++.h>
using namespace std;
struct debug_t {
template <typename T>
debug_t& operator<<(const T& value) {
return *this;
}
} debug;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int w, h, n;
while (cin >> w >> h >> n) {
set<int> hors{0, h}, verts{0, w};
multiset... | 7 |
#include <bits/stdc++.h>
using namespace std;
int N, K, L, V[1000001], P[1000001];
pair<long long, int> D[1000001];
pair<long long, int> solve2(int l) {
int s = 0, e = 1;
for (int i = 1; i < L; i++) {
D[i] = {D[i - 1].first + V[i], 0};
while (s < e && D[P[e - 1]].first >= D[i].first) e--;
P[e++] = i;
... | 20 |
#include <bits/stdc++.h>
using namespace std;
using ld = long double;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;
using vs = vector<string>;
const int nax = 45;
int dp[nax][nax][nax][nax];... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 555555;
int main() {
int n, t, c, i, res, cnt, num;
while (~scanf("%d%d%d", &n, &t, &c)) {
res = cnt = 0;
for (i = 0; i < n; i++) {
scanf("%d", &num);
if (num <= t)
cnt++;
else {
if (cnt >= c) res += cnt - c + 1;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a[n];
for (int& e : a) cin >> e;
int c = 2005;
vector<vector<int>> dp(n + 1, vector<int>(c, 1e9));
dp[0][0] = 0;... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int MX = 1005, MN = 1000005, inf = 1000000005, mod = 1000000007, L = 1000;
const long long INF = 1000000000000000005LL;
vector<int> kub[MX];
pair<int, int> pkt[MN];
bool comp(int a, int b) { return pkt[a] < pkt[b]; }
int main() {
int n;
scanf("%d", &n);
for (int... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long int q = 0, w = 0, e = 0;
int main() {
ios::sync_with_stdio(false);
cin >> q >> w >> e;
cout << q - max(q - e, w + 1) + 1 << endl;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
struct nd {
double l, r;
} t[500000];
double p[500000];
int n, q;
nd Update(nd a, nd b) {
if ((a.l + 1 == 0) && (a.r + 1 == 0)) return b;
if ((b.l + 1 == 0) && (b.r + 1 == 0)) return a;
nd ret;
ret.l = ret.r = 0;
double l1 = a.l, l2 = b.l, r1 = a.r, r2 = b.r;
... | 17 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.