solution stringlengths 53 181k | difficulty int64 0 13 |
|---|---|
#include <bits/stdc++.h>
int main() {
int n, k;
while (scanf("%d %d", &n, &k) == 2) {
int i;
for (i = 1; i <= n - k - 1; i++) printf("%d ", i);
for (i = n; i > n - k; i--) printf("%d ", i);
printf("%d\n", n - k);
}
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
long long i, m, n;
int main() {
string s, e;
cin >> s;
n = s.length();
long long c = 0, co = 0;
for (i = 0; i < n; i++) {
e = s.substr(i, 5);
if (e == "heavy")
c++;
else if (e == "metal")
co += c;
}
cout << co;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 + 10;
const int maxl = (1 << 18);
const int INF = 1e9;
int dp[maxn][maxl];
int par[maxn][maxl];
int n;
int a[maxn];
int val[70];
int prime[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59};
int ms[70];
int Solve(int pos, int mask) {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a1, b1, a2, b2, a3, b3;
cin >> a1 >> b1 >> a2 >> b2 >> a3 >> b3;
int sum1 = a1 + a3 + a2;
int sum2 = b1 + b3 + b2;
printf("3\n");
printf("%d %d\n", sum1 - 2 * a1, sum2 - 2 * b1);
printf("%d %d\n", sum1 - 2 * a2, sum2 - 2 * b2);
printf("%d %d... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 300005;
int n, a, b, c, d, start, len;
int t[N], q[N];
long long sum[N];
int main() {
scanf("%d%d%d%d%d%d%d", &n, &a, &b, &c, &d, &start, &len);
for (int i = 1; i <= n; i++) {
scanf("%d%d", &t[i], &q[i]);
if (q[i])
sum[i] = sum[i - 1] + c;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double res = 0;
int n;
cin >> n;
vector<double> vec(n + 1);
for (long long i = 0; i < ((long long)n + 1); i++) cin >> vec[i];
for (long long i = 0; i < ((long long)(n - 1) / 2 + 1); i++)
for (int j = n / 2 + 1; j <= n; j++) {
int a = (n - ... | 8 |
#include <bits/stdc++.h>
using namespace std;
struct node {
double x, v, m;
};
int n;
double t;
node a[12];
double b[12][12];
pair<vector<int>, double> timMin() {
pair<vector<int>, double> c;
c.second = 101;
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if (abs(b[i][j] - c.second... | 6 |
#include <bits/stdc++.h>
using namespace std;
int a[1000];
int t, n;
bool kt;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> t;
while (t--) {
cin >> n;
kt = true;
for (int i = 1; i <= n; i++) cin >> a[i];
sort(a + 1, a + n + 1);
for (int i = 2; i <= n; i++)
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const int maxt = (1 << 19) + 20;
vector<pair<pair<int, int>, int> > ad[maxn];
vector<pair<pair<int, int>, int> > qs[maxn];
set<pair<int, int> > st;
set<pair<int, int> >::iterator it1, it2, it3;
int n, q;
long long val[maxt], taga[maxt], tagb[maxt]... | 8 |
#include <bits/stdc++.h>
using namespace std;
bool isPrime(const int& num) {
for (int i = 2; i <= ceil(sqrt(num)); i++)
if (num % i == 0) return false;
return true;
}
vector<vector<int>> tree;
vector<bool> visited;
int ans = 0;
int aux = 0;
int main() {
int n;
cin >> n;
vector<int> tree(n + 1);
vector<i... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long int n, sum = 0, cnt = 0, c;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = n - 1; i >= 0; i--) {
sum = sum + a[i];
if (sum > cnt) {
c... | 1 |
#include <bits/stdc++.h>
int main() {
double xA, yA, xB, yB, xC, yC;
scanf("%lf %lf\n%lf %lf\n%lf %lf\n", &xA, &yA, &xB, &yB, &xC, &yC);
double result = (xB - xA) * (yC - yB) - (xC - xB) * (yB - yA);
if (result == 0) {
puts("TOWARDS");
} else if (result < 0) {
puts("RIGHT");
} else {
puts("LEFT"... | 2 |
#include <bits/stdc++.h>
using namespace std;
vector<int> wyn;
int tab[1000002];
int it = 0;
void erastotenes(int n) {
for (int i = 2; i <= n; i++) {
if (tab[i] == 0) {
for (int j = 2 * i; j <= n; j += i) {
tab[j] = 1;
}
int j = i * i;
wyn.push_back(i);
while (j <= n) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int case1(string str1, int n) {
char ch0 = 'r';
char ch1 = 'b';
int oddiff = 0, evendiff = 0;
for (int i = 0; i < n; i++) {
if (i % 2 == 0) {
if (str1[i] != ch0) {
evendiff++;
}
} else {
if (str1[i] != ch1) {
oddiff++;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long n, m, l = 0, p = 0, i, flag = 0, k, j, r = 0, q = 0, t, d;
cin >> n;
long long a[n];
vector<long long> v;
for (long long i = 0; i < n; i++) {
cin >> a[i];
v.push_back(a[i]);... | 4 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
string s;
int m;
cin >> s >> m;
vector<int> cnt(26);
for (char c : s) {
cnt[c - 'a']++;
}
vector<int> b(m);
for (int i = 0; i < m; i++) {
cin >> b[i];
}
vector<char> str(m);
vector<int> dist(m);
set<int> pos, filled;
int larg... | 5 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:200000000")
const int MN = 50;
const long long inf = (1ll << 63) - 1;
long long dp[MN][MN];
int arr[MN], n;
long long solve(int x, int y) {
if (x < 0 || y < 0) return -inf;
if (!x && !y) return 0ll;
if (dp[x][y] != -1ll) return dp[x][y]... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
string alp = "abcdefghijklmnopqrstuvwxyz";
set<char> st;
st.insert('a');
int idx = 0;
for (int i = 0; i < s.size(); i++) {
if (st.find(s[i]) == st.end()) {
cout << "NO"
<< "\n";
return 0;
} else {... | 1 |
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int a[4];
char ans[40][50];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
for (int i = 0; i < 40; i++) {
for (int j = 0; j < 50; j++) {
ans[i][j] = '#';
}
}
for (int i = 0; i < 4; i++) cin >> a... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int x;
cin >> x;
cout << x / 2 << "\n";
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 5;
struct p {
int x, y;
} c[MAX * 5];
int n, m, num, ans, top, cnt, tot, Ans, ANS;
int pos[MAX], pre[MAX], vis[MAX], sum[MAX], ww[MAX], w[MAX], h[MAX], st[MAX],
dfn[MAX], low[MAX], siz[MAX];
bool use[MAX], Use[MAX];
void add(int x, int y) { c[++n... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, n, a[100001], max = -1;
int d[100001] = {0};
a[0] = 0;
cin >> n;
for (i = 1; i <= n; i++) cin >> a[i];
d[1] = 1;
d[2] = 2;
for (i = 3; i <= n; i++)
if (a[i] == a[i - 1] + a[i - 2]) {
if (d[i - 1] > 1)
d[i] = d[i - 1] + 1... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e4 + 10;
const int maxm = 1010;
const int base = 31337;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int logo = 16;
const int off = 1 << logo;
const int treesiz = off << 1;
const int rn = 1e7 + 19;
int n, k, q;
int tour[treesiz];
vector<int> ... | 10 |
#include <bits/stdc++.h>
int main() {
int n, i, ilk = 1;
scanf("%d", &n);
for (i = 1; i < n; i++) {
ilk += i;
if (ilk > n) ilk %= n;
printf("%d ", ilk);
}
printf("\n");
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int g[1000005], pos[1000005];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) scanf("%d", &g[i]), pos[g[i]] = i;
int cnt = 0;
for (int i = 1; i <= n; i++)
if (g[i] != i) {
swap(pos[i], pos[g[i]]);
swap(g[i], g[pos[g[i]]]);
cnt++;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
struct Point {
T x, y;
Point() {}
Point(T xx, T yy) : x(xx), y(yy) {}
bool operator==(const Point<T> &p2) { return x == p2.x && y == p2.y; }
bool operator!=(const Point<T> &p2) { return x != p2.x || y != p2.y; }
bool operator<(const Point<T... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
struct node {
int minstep = 0x3f3f3f3f, cnt;
} stat[5005];
int endstep[5005];
inline int dis(int cur, int dst) {
if (dst >= cur)
return dst - cur;
else
return n - cur + dst;
}
int main() {
cin >> n >> m;
int s, d;
for (int i = 0; i < m; ++i) {
... | 4 |
#include <bits/stdc++.h>
const int N = 2010, p = 998244353;
int n, l, k, ans, f[2 * N][N][2];
inline void ad(int &x, int y) { x = (x + y) % p; }
inline int fp(int x, int y, int z = 1) {
for (; y; y >>= 1, x = 1LL * x * x % p)
if (y & 1) z = 1LL * z * x % p;
return z;
}
int main() {
f[0][0][0] = 1;
scanf("%d... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long n;
cin >> n;
if (n % 4 == 0)
cout << "YES\n";
else
cout << "NO\n";
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
const int N = 654;
const long double eps = 1e-10;
struct vec2 {
long double x, y;
vec2(long double x0 = 0.0, long double y0 = 0.0) : x(x0), y(y0) {}
vec2 *read() {
scanf("%Lf%Lf", &x, &y);
return this;
}
inline vec2 operator*(long double k) const { return vec2(x * k, y * k); }... | 12 |
#include <bits/stdc++.h>
using namespace std;
char s[200100];
int f[200100], nxt[200100], head[200100], ed[200100], len[200100];
int find(int x) {
if (head[x] == x) return x;
return head[x] = find(head[x]);
}
void link(int a, int b) {
nxt[a] = b + 1;
head[b + 1] = a;
}
int sum(int x) {
int r = 0;
while (x) ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000005;
int n, m;
vector<int> adj[MAXN], ans;
set<int> rem;
bool use[MAXN];
void dfs(int u) {
rem.erase(u);
for (int i = 0; i < (int)adj[u].size(); i++) rem.erase(adj[u][i]);
if (!rem.empty()) dfs(*rem.begin());
if (!use[u]) {
use[u] = true;
... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
string s;
vector<string> str;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s;
str.push_back(s);
}
for (int i = 1; i < n; i++) {
for (int j = 0; j < n - i; j++) {
if... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
int n1, n2, n3;
cin >> n1 >> n2 >> n3;
vector<int> v[n + 1];
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
v[a].push_back(b);
v[b].push_back(a);
}
auto ou... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10, mod = 998244353, proot = 3,
fft_maxn = (1 << 18) | 10;
vector<int> g[maxn];
int n, k, ans, f[maxn], fac[maxn], ifac[maxn], siz[maxn];
inline int pow_mod(int x, int n) {
int y = 1;
while (n) {
if (n & 1) {
y = (long long)y *... | 11 |
#include <bits/stdc++.h>
using namespace std;
struct SegTree {
int size;
vector<long long> seg;
SegTree() {}
SegTree(int size) {
this->size = size;
seg.resize(1 << (size + 1));
}
void init() {
for (int i = 0; i < (1 << (size + 1)); i++) seg[i] = 1e18;
}
void update(int i, long long val) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int N = 2e5 + 2, M = 2e5 + 2;
int n, m, s, w[N];
vector<pii> a[N];
pii e[M];
bool b[M];
int no[N];
ll ww[N];
bool re[N];
vector<int> aa[N];
int tmr = 0, tin[N], fup[N], lab[N], cnt;
bool used[M];
stack<int> stk;
void d... | 7 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n;
cin >> n;
long long arr[n];
vector<long long> a, b;
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
sort(arr, arr + n);
for (int i = 0; i < n; i++) {
if (arr[i] == arr[i + 1] && arr[i + 1] == arr[i + 2]) {
cout << "NO... | 1 |
#include<bits/stdc++.h>
#define it register int
#define ct const int
#define il inline
using namespace std;
typedef long long ll;
#define rll register ll
#define cll const ll
const int N=1000005;
int n,m;
ll a[N],b[N],d,x;
il ll gcd(cll a,cll b){return !b?a:gcd(b,a%b);}
int main(){
scanf("%d%d",&n,&m);it i;
for(i=1;... | 4 |
#include <bits/stdc++.h>
using namespace std;
bool double_equals(double a, double b, double epsilon = 0.001) {
return std::abs(a - b) < epsilon;
}
int main() {
long double a, b;
cin >> a >> b;
cout << std::setprecision(15);
cout << fixed;
long double l1 = pow(a, 1 / a) * (10000000000);
long double l2 = po... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
long long a[600010];
map<long long, vector<pair<int, int>>> possiblex;
long long p2[600010];
void genp2() {
p2[0] = 1;
for (int i = 0; i++ < 600010 - 1;) {
p2[i] = p2[i - 1] * 2 % ((long long)1e9 + 7);
}
}
int dsu[600010];
int setcnt;
int findp(int u)... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long n, k, t;
bool ok(long long x) { return k <= (x * (x + 1)) / 2ll; }
long long bsrh() {
long long l = 1, r = n - 2;
while (l < r) {
long long mid = (l + r) / 2;
if (ok(mid)) {
r = mid;
} else {
l = mid + 1;
}
}
return l;
}
int mai... | 2 |
#include <bits/stdc++.h>
double p[1010][1010];
double du(int x) { return x; }
void f(int n, int m) {
if (p[n][m] > 0) return;
if (n == 0) {
p[0][m] = 1 / du(m + 1);
return;
}
if (m == 0) {
p[n][0] = 1;
return;
}
f(m - 1, n);
f(m, n - 1);
double a, b, c, d, pr;
a = m / du(m + 1) * (1. -... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> A(n);
for (int i = 0; i < n; ++i) cin >> A.at(i);
int ans = 0, j = 1;
sort(A.begin(), A.end());
for (int i = 0; i < n; ++i) {
if (j >= n) break;
while (true) {
if (A.at(i) < A.at(j)) {
++j;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100;
char s[maxn][maxn];
int main() {
int T;
cin >> T;
while (T--) {
int r, c;
cin >> r >> c;
for (int i = 1; i <= r; i++) scanf("%s", s[i] + 1);
int cnt = 0;
for (int i = 1; i <= r; i++)
for (int j = 1; j <= c; j++) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, tot, ans, lim;
char s[50];
int g[50][50], fa[50], size[50], id[50], p[50];
vector<int> a[50];
int lg[(1 << 23) + 5], f[(1 << 23) + 5], G[(1 << 23) + 5];
int find(int x) {
if (x != fa[x]) fa[x] = find(fa[x]);
return fa[x];
}
void link(int x, int y) {
int rx = fi... | 11 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const double pi = acos(-1.0);
int n;
long long a[211111], t[211111];
void inc(int i, long long d) {
for (; i < n; i = (i | (i + 1))) t[i] += d;
}
long long get(int i) {
long long res = 0;
for (; i >= 0; i = (i & (i + 1)) - 1) res += t[i];
re... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
class TOWER {
public:
int index;
int height;
bool operator<(const TOWER& Y) const { return height < Y.height; }
};
multiset<TOWER> s;
TOWER smallest, largest;
int main() {
ios_base::sync_with_stdio(0);
int n, k, x;
cin >> n >> k;
for (in... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 300000 + 5;
int mod = 998244353;
void add(long long &x, long long y) { (x += y) %= mod; }
void mul(long long &x, long long y) { (x *= y) %= mod; }
long long power(long long a, long long n) {
long long b = 1;
for (; n; n /= 2, mul(a, a)) {
if (n & 1) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long ret = -1000000000000000000LL;
long long rv = ret;
long long dp[1000005];
int a[1000005];
long long get(int n) {
if (n < 0) return 0;
return dp[n];
}
void solve() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
}
for (i... | 8 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
void solve() {
string s;
cin >> s;
vector<long long> v(26, 0);
for (long long i = 0; i < s.size(); i++) v[s[i] - 'a']++;
long long cnt1 = 0, cnt2 = 0;
for (long long i = 0; i < 26; i++) {
if (v[i] >= 2)
cnt2++;
else if (v[i... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int max_n = 1e5 + 10;
struct node {
string ss;
char cnt;
int num;
void change(char c) {
num++;
int len = ss.size();
if (len < 10) {
ss = c + ss;
} else {
if (ss[5] == '.') {
for (int i = 4; i >= 1; --i) {
ss[i] = s... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[100005];
int b[100005];
int buscar(int len, int p) {
int l, r, mid;
l = 1, r = len, mid = (l + r) >> 1;
while (l <= r) {
if (p > b[mid])
l = mid + 1;
else if (p < b[mid])
r = mid - 1;
else
return mid;
mid = (l + r) >> 1;
... | 3 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const long double eps = 1e-7;
const int inf = 1000000010;
const long long INF = 10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 110, TOF = 550000;
long long n, m, k, u, v, x, y, t, a, b, ans;
long long A[MAXN];
int dp[MAXN][TO... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long k, m, n, a, j = 1, i, b;
vector<int> v;
set<int> s;
int main() {
cin >> n >> m;
for (i = 0; i < n; i++) {
cin >> a;
s.insert(a);
}
i = 0;
while (b + j <= m) {
if (s.find(j) != s.end()) {
j++;
continue;
}
v.push_back(j);
... | 2 |
#include <bits/stdc++.h>
long long n, ans, num, sum;
const long long mod = 1000000007ll;
long long pow(long long a, long long b) {
long long r = 1ll;
while (b) {
if (b & 1) r = r * a % mod;
a = a * a % mod;
b >>= 1;
}
return r % mod;
}
int main() {
scanf("%I64d", &n);
num = pow(27ll, n);
sum =... | 3 |
#include <bits/stdc++.h>
using namespace std;
bool flg;
int l, r, q, n, ans[100];
char b[200];
string a;
void solve(string s) {
int cp = 0, dp = 1, len = (int)s.length() - 1;
while (0 <= cp && cp <= len) {
flg = 0;
if ('0' <= s[cp] && s[cp] <= '9') {
int x = s[cp] - '0';
s[cp]--;
ans[x]++;... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,a,b;
string s;
cin>>n>>a>>b>>s;
vector<char> aa(n);
for(int i=0;i<n;i++)
aa[i]=s[i];
sort(aa.begin(),aa.end());
aa.erase(unique(aa.begin(),aa.end()),aa.end());
int m=aa.size();
vector<int> v(n);
for(int i=0;i<n;... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
double ans = 0;
for (int i = n - 1; i >= 0; i--) {
if (i - 1 >= 0) ans += pow(a[i], ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long MAX = 1e7 + 5;
const long long INF = 1e9 + 5;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n, m, k;
cin >> n >> m >> k;
bool b[2 * 10005][11];
for (int i = 0; i < n; i++) {
for (int j = 0; j ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
const long long int MAX = 1e9 + 7;
void array_show(int *array, int array_n, char middle = ' ') {
for (int i = 0; i < array_n; i++)
printf("%d%c", array[i], (i != array_n - 1 ? middle : '\n'));
}
void array_show(long long int *array, int array_... | 4 |
#include <bits/stdc++.h>
using namespace std;
int a[1010], b[1010], dp[1010];
struct ro {
int w, b;
vector<int> t;
} c[1010];
int father[1010];
int find(int x) {
if (father[x] == x) return x;
return father[x] = find(father[x]);
}
void Union(int x, int y) {
x = find(x);
y = find(y);
if (x > y) father[x] = ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
const int maxn = 100505;
long long ans[maxn][3];
long long ansr[maxn][3];
int ansp[maxn][3][5];
struct node1 {
int c, s, z;
} a[maxn], b[maxn];
bool cmp1(node1 a, node1 b) {
if (a.s != b.s)
return a.s < b.s;
else
return a.c < b.c;
}
void work() {
i... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 300000 + 100;
const int maxm = 2000000 + 100;
const int maxt = 3000000 + 100;
const int maxk = 10 + 3;
const long long unit = 1LL;
const int INF = 0x3f3f3f3f;
const long long Inf = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-3;
const double inf = 1e15;
cons... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MX = 2e6 + 10;
const int mod = 1e9 + 7;
const long long int inf = 1LL << 62;
int fq[300];
int main() {
int n, k;
string str;
cin >> n >> k >> str;
for (char ch : str) {
fq[ch]++;
if (fq[ch] > k) {
printf("NO\n");
goto outer;
}
}
... | 0 |
#include <bits/stdc++.h>
const double PI = acos(-1.0);
template <class T>
T gcd(T a, T b) {
return b ? gcd(b, a % b) : a;
}
template <class T>
T lcm(T a, T b) {
return a / gcd(a, b) * b;
}
template <class T>
inline T Min(T a, T b) {
return a < b ? a : b;
}
template <class T>
inline T Max(T a, T b) {
return a > ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int query(int y) {
cout << y << "\n";
fflush(stdout);
int t;
cin >> t;
if (t == 0 || t == -2) exit(0);
return t;
}
int main() {
int m, n;
cin >> m >> n;
int p[n];
for (int i = 0; i < n; i++) {
int t = query(1);
p[i] = t == 1;
}
int l = 2, r =... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long abs1(long long x) {
if (x < 0) {
return -x;
}
return x;
}
int main() {
long long n, k, p, i, j, answer = 0, answer2 = 1e18, cnt, places[10005],
keys[10005];
cin >> n >> k >> p;
for (i = 0; i < n; i++) {
cin >> places[... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 11;
int main() {
int n, k;
cin >> n >> k;
int stat = 0;
deque<pair<int, int> > d;
for (int i = 1; i <= n; i++) {
int a;
cin >> a;
stat += a / 10;
d.push_back(make_pair(a % 10, a));
}
sort(d.begin(), d.end());
reverse(d.... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 300000 + 5;
int d[maxn], n, m;
int to[maxn * 2], head[maxn], nex[maxn * 2], tol;
void insert(int u, int v) {
++tol, to[tol] = v, nex[tol] = head[u], head[u] = tol;
++tol, to[tol] = u, nex[tol] = head[v], head[v] = tol;
}
int p, ans[maxn * 2], vis[maxn],... | 6 |
#include <bits/stdc++.h>
using namespace std;
string out(int sum) {
string s;
s = "";
while (sum > 0) {
s.push_back('0' + sum % 10);
sum /= 10;
}
reverse(s.begin(), s.end());
return s;
}
string tall;
int ans;
bool back(string s, int p, int sum, vector<bool> add, int last) {
if (p == s.size()) {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const double e = 2.718281828;
void ox90() {
ios_base::sync_with_stdio(false);
cin.tie(0);
}
vector<string> G;
const int di[]{1, 0, -1, 0};
const int dj[]{0, 1, 0, -1};
bool visit[1501][1501];
int n, m, win = 0, a, b, xplane[1501][1501], yplane[1501][1501];
void dfs(int ... | 6 |
#include <bits/stdc++.h>
int flag[50000];
char s[10];
int n, res;
int x, y, t;
int main() {
memset(flag, 0, sizeof(flag));
res = 0;
scanf("%d", &n);
while (n--) {
scanf("%d", &x);
scanf("%d", &y);
t = x * 100 + (y % 10) * 10 + y / 10;
if (flag[t] == 0) {
for (int i = 0; i < 4; i++) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
const long long MOD = 1e9 + 7;
void solve() {
int k;
cin >> k;
if (k % 2 == 0) {
cout << (1ll << k / 2) << "\n";
return;
}
cout << 0 << "\n";
return;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NU... | 1 |
#include <bits/stdc++.h>
using namespace std;
multiset<long long int> ans;
stack<long long int> table;
int main() {
std::ios::sync_with_stdio(false);
string s = "";
string str;
long long int i = 0;
while (cin >> str) {
s += str;
i++;
if (i == 10) break;
}
long long int l = 0;
long long int s... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
int to[2 * N], nxt[2 * N], head[N], size[N], ans[N][5], n, u, v, rt, cnt, flag,
tot, id, ii, a, b, c, m, d;
inline void add(int u, int v) {
to[++cnt] = v;
nxt[cnt] = head[u];
head[u] = cnt;
}
inline void dfs1(int u, int fa) {
size[u] = 1;
i... | 9 |
#include <bits/stdc++.h>
const int N = 2e5 + 10;
const int mod = 998244353;
using namespace std;
pair<int, int> operator+(pair<int, int> a, pair<int, int> b) {
if (a.first < b.first) {
if (a.second > b.first) a.second = b.first;
return a;
} else {
if (b.second > a.first) b.second = a.first;
return b... | 7 |
#include <bits/stdc++.h>
using namespace std;
bool cmp_pair_F_2(pair<int, int> x, pair<int, int> y) {
return x.first > y.first;
}
bool cmp_pair_S_2(pair<int, int> x, pair<int, int> y) {
return x.second > y.second;
}
bool cmp_pair_S_1(pair<int, int> x, pair<int, int> y) {
return x.second < y.second;
}
bool cmp(int... | 5 |
#include <bits/stdc++.h>
int xx[4][5] = {
{0, 0, 0, 1, 2}, {0, 1, 1, 1, 2}, {0, 1, 2, 2, 2}, {0, 1, 1, 1, 2}};
int yy[4][5] = {
{0, 1, 2, 1, 1}, {2, 0, 1, 2, 2}, {1, 1, 0, 1, 2}, {0, 0, 1, 2, 0}};
struct num {
int x, y, z;
};
int l[(20 * 20 * 25)], r[(20 * 20 * 25)], d[(20 * 20 * 25)], u[(20 * 20 * 25)],
... | 7 |
#include <bits/stdc++.h>
using namespace std;
map<string, int> m;
map<string, int> m2;
int main() {
int n, score, maxi = -1000000;
string best = "", name;
bool flag = true;
scanf("%d", &n);
vector<pair<string, int> > rounds;
rounds.reserve(1002);
for (int i = 0; i < n; i++) {
cin >> name;
cin >> s... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
int norm(int a) {
while (a >= MOD) a -= MOD;
while (a < 0) a += MOD;
return a;
}
int mul(int a, int b) { return int(a * 1ll * b % MOD); }
int n, k;
vector<int> a;
inline bool read() {
if (!(cin >> n >> k)) return false;
a.resize(n);
fo... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXFACE = 100000;
struct Face {
int nside, id;
};
bool operator<(const Face &a, const Face &b) { return a.nside > b.nside; }
int nface;
Face face[MAXFACE];
int ansn;
vector<int> ans[M... | 12 |
#include <bits/stdc++.h>
int matrix[1001][1001];
int row, column, rowl[1001], coll[1001];
int main(void) {
int req;
char type;
int n1, n2;
scanf("%d %d %d", &row, &column, &req);
for (int i = 1; i <= row; i++) {
for (int j = 1; j <= column; j++) {
scanf("%d", &matrix[i][j]);
}
}
for (int i =... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, l = 0, r;
long long h[100005], d[100005];
bool check(long long x) {
long long cur = 1;
for (long long i = 1; i <= n; ++i) {
long long next = 0;
if (h[i] <= d[cur])
next = h[i] + x;
else {
long long now = h[i] - d[cur];
if (n... | 5 |
#include <bits/stdc++.h>
using namespace std;
constexpr int MAXN = 500005;
int n;
string var[MAXN];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
cin >> var[i];
}
for (int i = n - 1; i >= 1; --i) {
if (var[i] > var[i + 1]) {
int j = 0;
for (; j < min((int)var[i + 1].size(), (i... | 5 |
#include <bits/stdc++.h>
inline long long read() {
long long x = 0;
char c = getchar(), f = 1;
for (; c < '0' || '9' < c; c = getchar())
if (c == '-') f = -1;
for (; '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0';
return x * f;
}
inline void write(long long x) {
static char buf[20];
int len... | 11 |
#include <bits/stdc++.h>
using namespace std;
template <class TH>
void _dbg(const char *sdbg, TH h) {
cerr << sdbg << "=" << h << "\n";
}
template <class TH, class... TA>
void _dbg(const char *sdbg, TH h, TA... a) {
while (*sdbg != ',') cerr << *sdbg++;
cerr << "=" << h << ",";
_dbg(sdbg + 1, a...);
}
int t[500... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 222222;
vector<int> all;
set<int> occ;
set<int>::iterator it, it2;
map<int, int> here, wh;
set<pair<int, int> > s;
int nn, t, q, len, st, p, le, ri, i;
int z, x, v, ans, ll, rr, xx, low, high;
int id[maxn], il[maxn], ir[maxn];
int cr[maxn], a[maxn], h[maxn]... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int m, i, n;
double sum, temp;
cin >> m >> n;
sum = 0.00000000000;
for (i = 1; i <= m; i++) {
temp = i * (pow(((double)i / m), n) - pow(((double)(i - 1) / m), n));
sum = sum + temp;
}
printf("%.12lf", sum);
return 0;
}
| 4 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int N = (int)1e6 + 100;
const int M = (int)2e6 + 100;
const int inf = (int)1e9 + 100;
int main() {
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
srand(time(0));
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.... | 4 |
#include <bits/stdc++.h>
using namespace std;
int matchings[2001];
int pref[2001][2001];
int revpos[2001][2001];
void cpp_wrapper_irving(int N) {
int proposal_to[N];
int proposal_from[N];
int proposed_to[N];
for (int i = 0; i < N; i++) proposal_to[i] = N;
for (int i = 0; i < N; i++) proposal_from[i] = N;
fo... | 13 |
#include <bits/stdc++.h>
int main() {
char a[105], b[105], ans[105];
gets(a);
gets(b);
int i, len = strlen(a);
for (i = 0; i < len; i++) {
if (a[i] != b[i]) {
ans[i] = '1';
} else
ans[i] = '0';
}
ans[len] = '\0';
printf("%s", ans);
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 200000000;
struct Point {
int x, y;
Point(int _x, int _y) {
x = _x;
y = _y;
}
};
bool operator<(const Point a, const Point b) { return a.x < b.x; }
long long solve(vector<Point> v) {
int n = (int)v.size();
vector<int> MINI(n + 1);
vector<... | 10 |
#include <bits/stdc++.h>
using namespace std;
int a[10000], sum, L[10000], apr[100100], tot[10000], dp[502][5002], v[510];
int main() {
int n, m, i, j, k;
scanf("%d%d", &n, &m);
for (i = 1; i <= n * m; i++) scanf("%d", &a[i]);
for (i = 1; i <= n; i++) {
int x;
scanf("%d", &x);
if (!apr[x]) {
s... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
char s[100];
int m = 0, x = 0;
for (int i = 97; i <= 122; i++) {
s[m] = i;
m++;
k--;
if (k == 0) break;
}
for (int i = m; i < n; i++) {
s[i] = s[x];
x++;
}
for (int i = 0; i < n; i++) cout << s[... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
int cheak(int x) {
int sum = x;
while (x) {
sum += x / k;
x /= k;
}
if (sum >= n) return 1;
return 0;
}
int main() {
scanf("%d%d", &n, &k);
int head = 1, tail = n;
while (head <= tail) {
int mid = (head + tail) / 2;
if (cheak(mid))
... | 3 |
#include <bits/stdc++.h>
using namespace std;
priority_queue<pair<long long, long long>, vector<pair<long long, long long> >,
greater<pair<long long, long long> > >
q1;
priority_queue<pair<long long, long long>, vector<pair<long long, long long> >,
greater<pair<long long, long long> > ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n;
long* a;
long gcd(long a, long b) {
if (a == 0 || b == 0)
return a + b;
else
return gcd(b % a, a);
}
int main() {
cin >> n;
a = new long[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
long g = 0;
long max = 0;
for (int i = 0; i < n; i+... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long n, k, a[101], base = 1e9 + 7;
long long check(long long x) {
long long res = 0;
while (x > 0) {
res += x % 2;
x /= 2;
}
return res % 3;
}
struct node {
long long c[101][101], sum;
void khoitao(bool tt) {
sum = 0;
for (int i = 0; i < n; ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const double eps = 1e-9;
const int maxn = 100000 + 10;
char t(char c) {
if (c == 'L') return 'U';
if (c == 'U') return 'L';
if (c == 'R') return 'D';
if (c == 'D') return 'R';
}
vector<string> transpose(vector<string> A) {
int n = (int)A... | 9 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.