solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long N = 100 + 10;
char mat[N][N];
char flip(char ch) {
if (ch == '1') return '0';
return '1';
}
void update(long long a, long long b, long long c, long long d, long long e,
long long f) {
mat[a][b] = flip(mat[a][b... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
long long int n, m;
cin >> n >> m;
if (n % 10 == 0) {
cout << "1";
} else if (n % 10 == m) {
cout << "1";
} else {
long long int temp;
for (int i = 2;; ++i) {
temp = n * i;
if (temp % 10 == 0) {
... | 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int MAX = 2e5 + 5;
const long long MAX2 = 11;
const long long MOD = 998244353;
const long long MOD2 = 1000000006;
const long long INF = 2e18;
const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1, 0};
c... | 17 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double EPS = 1e-6;
const int MOD = (int)1e9 + 7;
long long Bigmod(long long b, long long p, long long m) {
if (p == 0) return 1LL;
if (p % 2 == 0) {
long long c = Bigmod(b, p / 2, m);
return ((c % m) * (c % m)) % m;
} else
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 123;
vector<pair<int, int> > nen;
pair<int, int> a[N];
struct node {
int mx1, mx2, sz, ed;
} lt[2 * N];
int par[2 * N], n, res[2 * N], cnt, vt, ok[6];
int get(int u) {
if (u == par[u]) return u;
return par[u] = get(par[u]);
}
int main() {
ios_bas... | 16 |
#include<bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int N, M; cin >> N >> M;
const int MOD = 1e9 + 7;
int tot = 1;
vector<int> ans;
vector<int> par(M); iota(par.begin(), par.end(), 0);
vector<bool> good(M);
auto get_par = [&](int v) {
while (v != par[v]) ... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n, t;
double p;
double f[2001][2001];
int main() {
cin >> n >> p >> t;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= t; ++j)
f[i][j] = p * (f[i - 1][j - 1] + 1) + (1 - p) * f[i][j - 1];
printf("%.6lf", f[n][t]);
return 0;
}
| 9 |
#include <bits/stdc++.h>
using namespace std;
void rset();
void init_test();
void solve();
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed;
cout.precision(20);
init_test();
return 0;
}
template <typename T>
void chmin(T& a, T b) {
if (a > b) a = b;
}
template <typename T>
void chmax... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7, N = 100005;
inline void read(int &x) {
char ch;
int t = 0;
x = 0;
for (ch = getchar(); ch < '0' || ch > '9'; ch = getchar())
if (ch == '-') t = 1;
for (; ch >= '0' && ch <= '9'; x = x * 10 + ch - 48, ch = getchar())
;
if (t) x = ... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t;
cin >> t;
while (t--) {
long long int n;
cin >> n;
cout << 1 << " " << n - 1 << endl;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long min(long long a, long long b) {
if (a >= b)
return b;
else
return a;
}
int main() {
string s;
cin >> s;
long long len = s.length();
char ch = 'a';
long long count = 0, rotation = 0;
for (int i = 0; i < len; i++) {
count = s[i] - ch;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int e = 100 + 2;
const int e1 = 1e6;
const long long mod = 1e9 + 7;
int dist[e][e];
int v[e1];
int mark[e1], trace[e1], dp[e1];
void track(int x) {
if (!x) return;
track(trace[x]);
cout << v[x] << " ";
}
int main() {
int n;
cin >> n;
for (int i = 1; i <= n... | 9 |
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
template <class T>
class SegmentTree {
private:
int _size = 1;
T _def;
std::vector<T> _nodes;
std::function<T(T, T)> _op;
std::function<T(T, T)> _update_op;
public:
SegmentTree(int size, T default_value, std::function<T(T, T)> op,
... | 17 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T>
void read(T &x) {
char ch;
x = 0;
int f = 1;
while (isspace(ch = getchar_unlocked()))
;
if (ch == '-') ch = getchar_unlocked(), f = -1;
do x = x * 10 + (ch - '0');
while (isdigit(ch = getchar_unlocked()));
x *= f;... | 20 |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> v[100002];
const int h_num = 2;
long long int B[] = {1011235817, 1011235817, 1011235817, 987654347, 1011235817,
1021328611, 987654347, 1011235817, 1000000007};
struct HASH {
vector<long long int> val;
bool emp;
HASH(int v_ = 0)... | 21 |
#include <bits/stdc++.h>
using namespace std;
int a, s, d[28], f[28], g[28], h, j, k, l, i, n, m;
string pas;
void dfs(int idx) {
pas += (char)(idx + 96);
h++;
if (!d[idx]) return;
dfs(d[idx]);
}
string x;
int main() {
cin >> n;
for (i = 0; i < n; i++) {
cin >> x;
if (x.size() == 1) g[x[0] - 96] = 1... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 32;
int n, m;
int deg[maxn];
bool g[maxn][maxn];
bool vis[maxn][4];
bool placed[maxn];
pair<long long, long long> p[maxn];
void dfs(int i, long long len) {
placed[i] = true;
for (int j = 1; j <= n; ++j)
if (!placed[j] && g[i][j]) {
if (!vis[i]... | 12 |
#include <bits/stdc++.h>
using namespace std;
int stuff[64];
int main() {
int N, W, M;
cin >> N >> W >> M;
W *= M;
for (int i = 0; i < N; i++) stuff[i] = W;
int per = (N * W) / M;
bool p = true;
;
int idx = 0;
vector<vector<pair<int, int> > > v(M);
int idxCnt = 0;
for (int i = 0; i < M; i++) {
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n;
int tg[4 * 100007];
pair<int, int> t[4 * 1000007];
pair<int, int> combine(pair<int, int> a, pair<int, int> b) {
if (a.first < b.first) return a;
if (b.first < a.first) return b;
return make_pair(a.first, a.second + b.second);
}
void build(vector<int> &a, int v,... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m, i, j, k, a, b, c, s, aa, bb;
cin >> n >> m;
vector<vector<int>> x(n, vector<int>(m));
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) cin >> x[i][j];
}
a = 0;
b = 1000000000;
while (a ... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long f(long long n) {
if (n < 0) return 0;
return n * (n + 1) / 2;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
long long A, B, C, D;
cin >> A >> B >> C >> D;
long long ans = 0;
for (long long i = C; i <= D;... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353, g = 3, N = 5e5 + 10;
int n, x, y, nv[200010], a[19][N], rv[N], len, L, ivg;
inline int ad(int x, int y) {
x += y;
return x >= mod ? x - mod : x;
}
inline int dc(int x, int y) {
x -= y;
return x < 0 ? x + mod : x;
}
inline int fp(int x, int... | 21 |
#include <bits/stdc++.h>
using namespace std;
int n, m, x, y;
double f[1005][1005], C[1005], A[1005];
int main() {
scanf("%d%d%d%d", &n, &m, &x, &y);
if (m == 1) {
double ans = 0;
for (int i = n - 1; i >= x; i--) ans += 2;
printf("%.4f", ans);
return 0;
}
for (int i = n - 1; i >= x; i--) {
f... | 16 |
#include <bits/stdc++.h>
using namespace std;
long long t, n, m, xx[8005], a[8005], flag, vis[8005];
vector<long long> v;
int cmp(long long x, long long y) { return x > y; }
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> t;
while (t--) {
int n1, n2, n3, flag = 0;
cin >> n1 >... | 7 |
#include <bits/stdc++.h>
using namespace std;
vector<int> v[200001], v1;
int main() {
int n, m, x, mx1 = -1, mx = -1;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &m);
mx = -1;
for (int j = 0; j < m; j++) {
scanf("%d", &x);
v[i].push_back(x);
if (mx < x) {
mx = ... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, k, a, b, x, y, i, p[100005], t[100005];
int main() {
cin >> n >> m >> k;
while (i < n) {
cin >> p[i];
t[p[i]] = i;
i++;
}
i = 0;
while (i < m) {
cin >> x;
if (t[x] != 0) {
y += t[x] / k;
t[x]--;
t[p[t[x]]]++;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
long long a[n];
long long sum = 0;
for (long long i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
static const double EPS = 1e-10;
template <typename T, typename S>
vector<T>& operator<<(vector<T>& a, S b) {
a.push_back(b);
return a;
}
template <typename T>
void operator>>(vector<T>& a, int b) {
while (b--)
if (!a.empty()) a.pop_back();
}
bool isprime(int n) {... | 9 |
#include <bits/stdc++.h>
using namespace std;
char ch, last;
int n, a, b, rez;
int main() {
cin >> n >> a >> b;
last = '*';
for (int i = 1; i <= n; i++) {
cin >> ch;
if (ch == '.') {
if (last == 'a') {
if (b > 0)
b--;
else {
last = '*';
continue;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int nos[2048];
bool used[2048];
int main() {
int N;
cin >> N;
vector<pair<int, int> > v(N);
for (int i = 0; i < N; i++) {
int x;
cin >> x;
nos[i] = abs(x);
v[i] = make_pair(nos[i], i);
}
sort(v.rbegin(), v.rend());
int total = 0;
int idx = 0;... | 14 |
#include <bits/stdc++.h>
using namespace std;
struct comp {
bool operator()(pair<int, int> a, pair<int, int> b) const {
if (a.first != b.first) return a.first > b.first;
return a.second < b.second;
};
};
int aft[300000], bef[300000];
int n, m;
map<int, int> maps;
set<pair<int, int>, comp> s;
set<int> sets;
... | 14 |
#include <bits/stdc++.h>
using namespace ::std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
string a, b;
vector<int> ans;
cin >> a >> b;
for (int i = n - 1; i > 0; i--)
if (a[i] != b[i]) {
if (a[i] != a[0]) ans.push_back(1), a[0] = !(a[0] - '0') + '0';
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f, M = 1e9 + 7;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1), EPS = 1e-9;
const int N = 101;
long long b[N];
long long o;
int n, k;
long long fastmod(long long a, long long m = M) {
return (-m < a and a < m) ? a : a % m;
}... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
int p[N], h[N], vis[N];
vector<int> ar[N];
int dfs(int node, int par) {
vis[node] = 1;
for (int child : ar[node]) {
if (vis[child] == 0) {
p[node] += dfs(child, node);
}
}
return p[node];
}
int main() {
int n, k, t, m, z;
cin... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 111;
int cnt[MAX_N][MAX_N];
vector<int> l;
vector<pair<int, int> > gr[MAX_N];
int used[MAX_N];
inline void add(int v, int u, int c) { gr[v].push_back({u, c}); }
void dfs(int v, int c) {
for (int i = 0; i < (int)l.size(); ++i) ++cnt[l[i]][v], ++cnt[v][l[i... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 10;
const long long mod = 1e9 + 7;
const long double eps = 1e-10;
const int inf = 1e6;
int n, d;
long long k;
long long a[maxn];
long long ac[maxn];
long long bc[maxn];
long long b[maxn];
bool check(long long t) {
memset(b, 0, sizeof(b));
long lon... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, count = 0;
cin >> n;
string s;
cin >> s;
for (int i = 0; i < n; i++) {
if (s[i] == '1') count++;
if (s[i] == '0') {
cout << count;
count = 0;
}
}
cout << count;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, k, p;
cin >> n >> k;
char str[n];
scanf("%s", str);
for (long long int i = 0; i < n; i++) {
if (k == 0) break;
if (i != n - 1)
if (str[i] == '4' && str[i + 1] == '7') {
if (i > 0 && i % 2 == 1 && str[i - 1] == '4... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long a[1000001];
int main() {
long long n;
cin >> n;
cout << n * (n + 1) << endl;
for (int i = n; i >= 0; i--) {
int x = 0;
if (a[i]) continue;
for (int j = 0; j <= 32; j++) {
if ((1ll << (j)) > i) {
x = j;
break;
}
}... | 9 |
#include <bits/stdc++.h>
using namespace std;
string word;
stack<char> f;
void print() {
if (f.empty()) return;
char ch = f.top();
f.pop();
print();
cout << ch;
}
int main() {
cin >> word;
for (int i = 0; i < word.length(); i++) {
if (f.empty()) {
f.push(word[i]);
} else {
if (word[i] ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
struct P {
long long x, y;
P operator-(const P &a) const { return (P){x - a.x, y - a.y}; }
long long operator*(const P &a) const {
return 1ll * x * a.y - 1ll * y * a.x;
}
bool operator<(const P &a) const { return x == a.x ? y < a.y : x < ... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 99999999;
const int N = 100010;
const int M = 5005;
int f[M], a[N], b[N];
vector<int> v[N];
int main() {
int n, m, s, e;
cin >> n >> m >> s >> e;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= m; i++) {
cin >> b[i];
v[b[i]].pu... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const double eps = 1e-9;
long long X, Y;
long long dx, dy;
string cmd;
int mx[] = {0, 0, -1, 1};
int my[] = {1, -1, 0, 0};
pair<long long, long long> rax, ray;
int main() {
cin >> X >> Y;
cin >> cmd;
if (X == 0 && Y == 0) {
cout << "Yes"... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int cnt[26] = {0};
int i, tmp;
map<int, int> m;
char in[7];
m[6] = 1;
m[15] = 1;
m[24] = m[33] = 2;
m[114] = 2;
m[123] = 3;
m[222] = 6;
m[1113] = 5;
m[1122] = 8;
m[11112] = 15;
m[111111] = 30;
cin >> in;
for (i = 0; in[i] != ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s;
cin >> s;
int i;
double ans = 0;
string t = "";
for (i = 0; i < s.length(); i++) {
if (s[i] == '.') {
if (s[i + 3] >= '0' && s[i + 3] <= '9' && (i + 3 < s.length())) continue;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, b;
cin >> n;
m = (n / 7) * 2;
b = n % 7;
switch (b) {
case 0:
cout << m << " " << m;
return 0;
case 1:
cout << m << " " << m + 1;
return 0;
case 2:
cout << m << " " << m + 2;
return 0;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-7;
const long double PI = acos(0.0) * 2.0;
mt19937_64 rng((unsigned long long)new char);
const int mod = 1e9 + 7;
const long long INF = 9e18;
const int maxn = 510;
char s[maxn][maxn];
long long dp[2][maxn][maxn];
inline void add(long long& x, long long... | 15 |
#include <bits/stdc++.h>
using namespace std;
long long dyn[5007][5007];
long long A[300007];
int main() {
int N, K;
scanf("%d %d ", &N, &K);
;
for (int i = (0); i < (N); i++) cin >> A[i];
sort(A, A + N);
int len = (N - 1) / K + 1;
int shortsCnt = (K - N % K) % K;
for (int groups = (1); groups < (K); gr... | 12 |
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[500001];
int dist[500001];
bool visited[500001];
int bfs(int i) {
queue<int> q;
q.push(i);
visited[i] = true;
vector<pair<int, int>> time;
while (!q.empty()) {
int temp = q.front();
q.pop();
for (int j = 0; j < adj[temp].size(); j++) {
... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 300005;
const int INF = (int)1e9;
struct Node {
int p;
int link = -1;
int go[26], nxt[26];
bool leaf;
char pch;
Node(int p = -1, char pch = '$') : p(p), pch(pch) {
fill(go, go + 26, -1);
fill(nxt, nxt + 26, -1);
}
};
vector<Node> aho(1... | 18 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:32000000")
#pragma GCC optimize("O3")
using namespace std;
int n, I;
long long arr[400005];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin.sync_with_stdio(0);
cout.sync_with_stdio(0);
cout.precision(8);
srand(time(0));
cin... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
string to_string(string s) { return '"' + s + '"'; }
string to_string(char s) { return string(1, s); }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A>... | 9 |
#include <bits/stdc++.h>
using namespace std;
int N, M;
vector<int> G[200005];
int Next[200005];
int Array[200005];
int Sz[200005], Size[200005];
int sum, cnt;
bool Blocked[200005];
struct Solution {
int x, y, y2;
} S[400005];
bool first;
int End[200005], Start[200005];
int aux, source;
unordered_set<int> X[200005];
... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
const int P = 1000000009;
int n, a, b, k;
long long ans = 0, part;
char s[N];
void exGcd(int a, int b, int& x, int& y);
int rev(int a);
int mpow(int x, int k);
int main() {
scanf("%d%d%d%d", &n, &a, &b, &k);
scanf("%s", s);
long long ra = rev(a),... | 10 |
#include <bits/stdc++.h>
using namespace std;
int nf, ne, ns, rf, re, rs, df, de, xm;
double ans;
double cold[25], wf[25], we[25], f[25][25][25], cve[25][25], cvf[25][25];
void dp() {
int i, j;
for (i = 1; i <= xm; ++i) {
wf[i] = 0;
for (j = 1; j <= xm; ++j) wf[i] += cold[j] * cvf[j][i];
}
for (i = 1; i... | 18 |
#include <bits/stdc++.h>
using namespace std;
int t[1000 * 1000 + 10];
int sp[1000 * 1000 + 10];
int suma(int i, int j) { return sp[j] - sp[i - 1]; }
int policz(int i, int aktw, int zos) {
if (zos == 0) return aktw;
return aktw + suma(i + 1, i + zos);
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int... | 8 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1, c = getchar();
while (!isdigit(c)) {
if (c == '-') f = -1;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f == 1 ? x : -x;
}
const int N = 2e5 + 4;
int n, id... | 9 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int cnt[30];
int main() {
int T;
cin >> T;
while (T--) {
memset(cnt, 0, sizeof(cnt));
int n;
cin >> n;
for (int i = 1, x; i <= n; i++) {
cin >> x;
for (int j = 0; j < 30; j++) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(NULL);
long long n, L;
scanf("%lld %lld", &n, &L);
vector<long long> C(n);
for (int i = 0; i < n; i++) {
scanf("%lld", &C[i]);
i > 0 ? C[i] = min(C[i], C[i - 1] * 2) : NULL;
}
long long ans = LLO... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
char s[110][10010];
int dis[110][10010];
int n, m;
bool check() {
for (int i = 1; i <= n; i++) {
bool flag = 0;
for (int j = 0; j < m; j++) {
if (s[i][j] == '1') flag = 1;
}
if (!flag) return 1;
}
return 0;
}
int main(... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long msb(long long x) { return 63 - __builtin_clzll(x); }
long long f(long long x) {
if (x == 1) {
return 0;
}
long long p = 1ll << msb(x);
if (x - p > 0) {
long long y = x - p;
return p + f(p) + f(y);
} else {
return 2 * f(x / 2) + x / 2;
}... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long int pos(long long int n) {
if (n >= 0) {
return n;
}
return -n;
}
long long int gcd(long long int a, long long int b) {
if (a == 0) {
return b;
}
return gcd(b % a, a);
}
long long int a[100005];
bool visited[100005];
map<long long int, long lon... | 12 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
if (n < 3)
cout ... | 3 |
#include <bits/stdc++.h>
using namespace std;
struct neededLetter {
int A, C, T, G;
};
int n;
string s;
neededLetter diff[55];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
cin >> s;
for (int i = 0; i < n; ++i) {
diff[i].A = s[i] - 'A';
diff[i].C = s[i] - 'C';
di... | 2 |
#include <bits/stdc++.h>
using namespace std;
int s, x1, x2, t1, t2, p, d, ans;
int main() {
cin >> s >> x1 >> x2 >> t1 >> t2 >> p >> d;
if (x1 > p) {
ans = (x1 - (p * d)) * t1;
d = 1;
}
if (p > x1) {
ans = ((d == -1) ? p - x1 : 2 * s - (x1 + p)) * t1;
d = -1;
}
if (x2 > x1) {
ans += (x2... | 8 |
#include <bits/stdc++.h>
using namespace std;
int a[500][500];
int main() {
int n, t;
while (scanf("%d%d", &n, &t) == 2) {
memset(a, 0, sizeof(a));
a[200][200] = n;
int sz = 0;
while (1) {
bool flag = true;
for (int i = 200 - sz; i <= 200 + sz; i++)
for (int j = 200 - sz; j <= 20... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long int r, c, n, k, a[60][60], x, y, ans, ans1;
int main() {
cin >> r >> c >> n >> k;
for (long long int i = 1; i <= n; i++) {
cin >> x >> y;
a[x][y] = 1;
}
for (long long int i = 1; i <= r; i++) {
for (long long int j = 1; j <= i; j++) {
for... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;
priority_queue<int, vector<int>, greater<int> > pq;
vector<int> v[100000];
long long vec[100000];
pair<long long, long long> dp[100000];
void go(int o, int pa) {
for (int i = ... | 10 |
#include <bits/stdc++.h>
const int factor_N = 10000005;
using namespace std;
int read() {
char c = getchar();
int x = 0, f = 1;
for (; !isdigit(c); c = getchar())
if (c == '-') f = -1;
for (; isdigit(c); c = getchar()) x = x * 10 + c - 48;
return x * f;
}
struct Node {
int t, a, b;
};
const int N = 2e5 ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int mp[500];
int n, a, b;
while (~scanf("%d%d%d", &n, &a, &b)) {
if (a > b) swap(a, b);
for (int i = 1; i <= n; i++) mp[i] = i;
int ans = 0;
int p = 1;
int flag = 0;
while (1) {
ans++;
for (int i = 2; i <= n; i += 2) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a = 0, b = 0, c, d, e, f = 0, l, g, m, n, k, i, j, t, p, q;
cin >> n;
for (i = 0; i < n; i++) {
f = 0;
cin >> a >> b;
c = abs(a - b);
f += c / 5;
c = c % 5;
f += c / 2;
c = c % 2;
f += c;
cout << f << '\n';
... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, x;
cin >> n >> x;
vector<int> a(n), b(n);
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
if (a[i] > b[i]) {
swap(a[i], b[i]);
}
}
int cnt[1001];
for (int i = 0; i < 1001; i++) {... | 2 |
#include <bits/stdc++.h>
using namespace std;
int h, w;
char grid[1501][1501];
bool viz[1501][1501];
pair<int, int> where[1501][1501];
const int di[] = {-1, 0, 1, 0}, dj[] = {0, 1, 0, -1};
int mod(int a, int b) {
int res = a % b;
if (res < 0) res += b;
return res;
}
int main() {
ios_base::sync_with_stdio(false)... | 12 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long int t;
cin >> t;
while (t--) {
long long int n;
cin >> n;
long long int arr[n];
for (long long int i = 0; i < n; i++) cin >> arr[i];
if (arr[0] < arr[n - 1])
... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
const int mod = 1e9 + 9;
struct Node {
int x, y;
Node() {}
Node(int x, int y) : x(x), y(y) {}
bool operator<(const Node& a) const {
if (x != a.x) return x < a.x;
return y < a.y;
}
};
int n;
Node a[MAXN];
int vis[MAXN];
map<Node, in... | 13 |
#include <bits/stdc++.h>
using namespace std;
char ch, B[1 << 20], *S = B, *T = B;
int aa, bb;
int rd() {
while (ch = (S == T && (T = (S = B) + fread(B, 1, 1 << 20, stdin), S == T)
? 0
: *S++),
!(ch >= '0' && ch <= '9') && ch != '-')
;
ch == '-' ? aa = bb = 0 : (aa... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 110000;
inline int read() {
int rtn = 0, f = 1;
char ch = getchar();
for (; !isdigit(ch); ch = getchar())
if (ch == '-') f = -1;
for (; isdigit(ch); ch = getchar()) rtn = (rtn << 1) + (rtn << 3) + ch - '0';
return rtn * f;
}
int n, fa[maxn], c... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, i;
cin >> n;
long long a[n], b[n];
for (i = 0; i < n; i++) cin >> a[i] >> b[i];
for (i = 0; i < n; i++) {
if (a[i] - b[i] != 0) {
cout << "rated";
return 0;
}
}
long long flag = 0;
for (i = 0; i < n - 1; i++) {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int a[1000000];
int b[1000000];
int dp[2][1000000];
int n, k;
int tables(int l, int r) {
if (l >= n) return 0;
if (l < 0) l = 0;
if (r < 0) return 0;
if (r >= n) r = n - 1;
if (r < l) return 0;
if (l == 0) return b[r];
return b[r] - b[l - 1];
}
int test(int st... | 11 |
#include <bits/stdc++.h>
using namespace std;
struct edge {
double x, y, ang;
bool operator<(const edge& p) const { return ang < p.ang; }
} a[100008];
int main() {
int i, j, k, l, n, m, t, x, y;
cin >> n;
for (i = 0; i < n; i++) {
scanf("%lf %lf", &a[i].x, &a[i].y);
if (a[i].x < 0 && a[i].y == 0) {
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 57;
const int Mod = 1000000007;
int n, K, C[maxN][maxN];
int F[maxN][maxN][2];
void Plus(int &x, int y);
int main() {
scanf("%d%d", &n, &K);
F[1][0][0] = 1;
F[0][0][1] = 1;
for (int i = 0; i <= n; i++)
for (int j = C[i][0] = 1; j <= i; j++)
... | 18 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0;
bool f = 1;
char c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-') f = 0;
for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ '0');
if (f) return x;
return -x;
}
const int N = 1e5;
const int M = 2.5... | 18 |
#include <bits/stdc++.h>
using namespace std;
inline void read(long long &x) {
long long w = 1;
x = 0;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') w = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
x *= w;
}
struct road {
l... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
if (n == 1) {
scanf("%d", &n);
printf("%d\n", n);
printf("%s\n", string(n, 'a').c_str());
return 0;
}
vector<pair<int, char>> v(n);
int odd = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &v[i].first);
... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int a[maxn], b[maxn];
long long dp[maxn];
int main() {
int n;
int maxn = 0;
long long ans;
while (cin >> n) {
memset(b, 0, sizeof(b));
for (int i = 1; i <= n; i++) {
cin >> a[i];
b[a[i]]++;
maxn = max(maxn, a[i]);
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
cin >> T;
string s, c;
getchar();
while (T--) {
getline(cin, s, ' ');
getline(cin, c, '\n');
bool f = false;
string a = s;
sort(a.begin(), a.end());
int m = min(s.length(), c.length());
int ci = s.length();
for (... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, i, x, y, c = 0, d = 0;
cin >> n;
vector<long long int> v(n);
for (i = 0; i < n; i++) cin >> v[i];
sort(v.begin(), v.end());
x = v[0];
y = v[n - 1];
for (i = 0; i < n; i++) {
if (v[i] == x) c++;
if (v[i] == y) d++;
}
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int T, ans = 0, len1, len2, len3, a[30], b[30];
string s, t, p;
inline int read() {
int red = 0, f_f = 1;
char ch = getchar();
while (ch > '9' || ch < '0') {
if (ch == '-') f_f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') red = red * 10 + ch - '0... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long add = 1, t, h, n, i, j, mn = 100003LL * 100003LL, k, mx = 0, rz = 0,
tot, m, obj, st, cnt = 0, cnti = 0, s = 0, nri = 0, a[4], b = 0,
c = 0, a2, b2, a3, b3;
n = 500;
m = 1000000;
cout << n << '\n';
int r = m, x = m / ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int bigp = 10000007;
int H, Q, N, V, E, p, xc, yc, dg;
int hash1[15000005], hash2[15000005];
char st[10];
double ans;
void mplus(int S, int E) {
int e = S % bigp;
while ((hash1[e] != 0) && (hash1[e] != S)) ++e;
hash1[e] = S;
hash2[e] += E;
}
int getsize(int S)... | 17 |
#include <bits/stdc++.h>
using namespace std;
struct segtree {
int64_t n;
vector<pair<int64_t, int64_t>> seg;
segtree(int64_t n)
: n(n), seg(2 * n, {(int64_t)(1e17 + 1), (int64_t)(1e17 + 1)}) {}
pair<int64_t, int64_t> f(pair<int64_t, int64_t> a, pair<int64_t, int64_t> b) {
return min(a, b);
}
void... | 16 |
#include <bits/stdc++.h>
using namespace std;
int n, b[1005];
long long a[1005];
vector<int> A, B, ansA, ansB;
vector<pair<long long, long long> > tA, tB;
long long qry(int x, int y, int z, int w) {
printf("%d %d %d %d\n", x, y, z, w);
fflush(stdout);
long long ret;
scanf("%lld", &ret);
return ret;
}
int main... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c;
cin >> a;
cin >> b;
cin >> c;
if (a <= b && a <= c) {
cout << "YES";
} else {
cout << "NO";
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
vector<vector<long long> > v(300005);
long long vis[300005];
long long ct;
long long pmod(long long x, long long n) {
long long res = 1;
while (n) {
if (n & 1) {
res = (res * x) % mod;
}
x = (x * x) % mod;
n /= 2;
}
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int ara[n + 5][m + 5];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> ara[i][j];
}
}
vector<int> vr[n + 5], vc[m + 5];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, a[101000], cnt1[201000], cnt2[201000], chand1[101000], chand2[101000];
int check(int t) {
int i = 0, j = 0, o = 0, d = 0;
bool ch = 1;
while (ch) {
ch = 0;
if (cnt1[i + t] < cnt2[j + t] && i + t <= chand1[n - 1]) {
o++;
j = chand2[cnt1[i + t... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, m, s, l, ok[100005], x[100005];
int used[100005];
vector<int> g[100005];
vector<int> gg[100005];
void dfs(int v) {
used[v] = l;
ok[l]++;
for (int i = 0; i < g[v].size(); i++) {
int to = g[v][i];
if (!used[to]) {
dfs(to);
}
}
}
int main() {
... | 7 |
#include <bits/stdc++.h>
int nn, n, m, sum;
int limit[203][203];
int flow[203][203];
void maxflow() {
int i, j, delta, x;
int last[203];
bool check[203];
do {
memset(last, 0, sizeof(last));
memset(check, false, sizeof(check));
last[1] = 203;
do {
i = 0;
do {
i++;
if (... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n, m, h, counter = 0;
vector<int> U, num, dfs_num, dfs_low, vis1, vis2;
vector<vector<int> > adj, adj2, scc;
stack<int> st;
void tarjanSCC(int v) {
dfs_num[v] = dfs_low[v] = counter++;
st.push(v);
vis1[v] = vis2[v] = 1;
for (int i = 0; i < adj[v].size(); ++i) {
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int a[100001], maxi[100001];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = n - 1; i >= 0; i--) {
maxi[i] = max(maxi[i + 1], a[i]);
}
for (int i = 0; i < n; i++) {
cout << max(maxi[i + 1] - a[i] + 1, 0) << '... | 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.