solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b, k = 0;
cin >> n >> a >> b;
if (a + b < n)
cout << ++b;
else
cout << n - a;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
struct node {
int dist;
long long c;
bool operator<(const node &temp) const {
if (c == temp.c) return dist > temp.dist;
return c < temp.c;
}
};
set<node> heap[301000];
set<node>::iterator it;
vector<node> g[301000];
node now;
int ... | 21 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
const int MAX = 1e6 + 10;
int s[MAX];
int p[MAX];
vi flip[MAX];
ll best = 1e14;
int res, canti, n;
ll bigsum, bigsum2, smallsum, smallsum2;
int red(int x) {
if (x > n) x -= n;
return x;
}
ll shift(int i) {
bigsum += canti;... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, i, j, m, k;
cin >> n >> m >> k;
int arr[n + 1][m + 1];
vector<int> vec(m + 1, 0);
for (i = 1; i < n + 1; ++i) {
for (j = 1; j < m + 1; ++j) {
cin >> arr[i][j];
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
long long len = s.length();
bool pernah[100005] = {false};
long long jaw = 0;
for (long long i = 0; i < len; i++) {
if (!pernah[i]) {
long long byk = 0;
bool woi = false;
for (long long j = i + 1; j < len; j... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 12e5 + 100;
const int mod = 998244353, modg = 3, modi = 332748118;
long long a[maxn], b[maxn];
long long pow_mod(long long a, long long b) {
long long ans = 1;
while (b) {
if (b & 1) ans = ans * a % mod;
a = a * a % mod, b >>= 1;
}
return an... | 17 |
#include <bits/stdc++.h>
using namespace std;
long long powMod(long long a, long long b) {
if (b == 1) {
return a % 1000000007;
}
if (b == 0) {
return 1 * 1LL;
}
long long temp = powMod(a, b / 2);
if (b % 2 == 0) {
return (temp * temp) % 1000000007;
} else {
return ((temp * temp) % 1000000... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int p[2503];
vector<pair<int, int> > a[102];
int root(int x) { return p[x] < 0 ? x : p[x] = root(p[x]); }
void mer(int x, int y) {
if ((x = root(x)) == (y = root(y))) return;
if (p[x] > p[y]) swap(x, y);
p[x] += p[y];
p[y] = x;
}
int main... | 15 |
#include <bits/stdc++.h>
const int maxn = 2e5 + 5;
const int mod = 998244353;
using namespace std;
void solve() {
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
v[i]++;
}
vector<vector<long long> > dp(2, vector<long long>(n + 5));
dp[0][0] = 1;
for (int i = 0; i < ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n, m, second;
vector<int> g[200005];
vector<int> r[200005];
vector<int> cyc[200005];
int visit[200005];
int SCC[200005];
void dfs(int u) {
visit[u] = 1;
for (int v : g[u]) {
if (visit[v]) continue;
dfs(v);
}
}
bool color[200005], vis[200005];
stack<int> st... | 12 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename V>
void bugp(const pair<T, V> &x) {
cerr << '{' << x.first << ", " << x.second << '}' << endl;
}
template <typename T, typename U, typename V>
void bugpp(const pair<T, pair<U, V> > &x) {
cerr << '{' << x.first << ", {" << x.second.first <<... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int M = 100005;
int a[M];
int has[M * 10 * 2];
int l[M * 10];
int main() {
int n;
int maxx = -1;
int minx = 100 * M;
int tmp, tmp2;
scanf("%d", &n);
int ch = -1;
for (int i = 0; i < n; i++) {
int x;
scanf("%d", &x);
if (has[x] == 0) {
h... | 5 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 500005;
int n, m, c, c0;
int t[N], a[N], b[N];
int id[N];
ll f() {
iota(id, id + n, 0);
sort(id, id + n, [](int i, int j) { return t[i] < t[j]; });
ll sum = 0;
multiset<pair<int, int>> s;
int last = 0;
ll ans = 0;
id[n] = n,... | 19 |
#include <bits/stdc++.h>
using namespace std;
int n, k, mid, a[200010], sz[200010], siz[200010], dp1[200010];
vector<int> g[200010];
void dfs(int x, int fa) {
sz[x] = (a[x] >= mid);
siz[x] = dp1[x] = 1;
int mx = 0;
for (int i = 0, v; i < g[x].size(); i++) {
v = g[x][i];
if (v == fa) continue;
dfs(v,... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
long long x1, x2, y1, y2;
cin >> x1 >> y1 >> x2 >> y2;
cout << 1 + (x2 - x1) * (y2 - y1) << "\n";
}
}
| 8 |
#include <bits/stdc++.h>
using namespace std;
long long calLog(int b) {
long long count = 0;
while (b % 2 == 0) {
count++;
b = b / 2;
}
if (b > 1) {
return 0;
}
return count;
}
long long solve(long long n) {
long long k;
long long x = 1;
bool flag = false;
while (1) {
if (n % x == 0)... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5000;
vector<pair<int, int> > E[MAXN];
int ans = ~0U >> 1, u[MAXN], d[MAXN][3], n;
void dfs(int v) {
int nv, tp, d1 = 0, d2 = 0;
d[v][0] = 0;
u[v] = 1;
for (int i = 0; i < (int)E[v].size(); i++) {
nv = E[v][i].first, tp = E[v][i].second;
if ... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios ::sync_with_stdio(false);
int n, a, d;
while (cin >> n >> a >> d) {
double last = 0.0;
for (int i = (1), _b = (n); i <= _b; i++) {
int t0, v;
cin >> t0 >> v;
double t1 = v / (double)a;
double d1 = a * t1 * t1 / 2.0;
... | 8 |
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define Mod 1000000007
#define MAXN 200005
using namespace std;
struct Edge {
int v,w,type;
};
vector<Edge> G[MAXN];
ll dis[MAXN][(1 << 2)];
struct State {
int u;
ll dis;
int s;
bool operator < (const State& a) const{
return dis > a.dis;
}
}... | 16 |
#include <bits/stdc++.h>
const int N = 500005, mod = 1000000007;
int n;
std::pair<int, int> p[N];
long long qaq(std::pair<int, int> a, std::pair<int, int> b) {
return (long long)a.first * b.second - (long long)a.second * b.first;
}
int operator*(std::pair<int, int> a, std::pair<int, int> b) {
int ret = qaq(a, b) % ... | 21 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
vector<long long int> A;
cin >> n;
while (n--) {
int x;
cin >> x;
A.push_back(x);
}
sort(A.begin(), A.end());
int ct = 0;
int fz = 0;
for (auto i : A) {
if (i < 0)
ct++;
else if (i == 0) {
fz = ... | 1 |
#include <bits/stdc++.h>
#pragma optimize("Ofast")
using namespace std;
using ll = long long int;
using ull = unsigned long long int;
using dd = double;
using ldd = long double;
using si = short int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
void solve() {
int a;
cin >> a;
int d = 1;
while (d <= a) ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int a[2006];
char c[2006][2006];
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
scanf("%s", c[i]);
for (int j = 0; j < m; j++) a[j] += c[i][j] == '1';
}
for (int i = 0; i < n; i++) {
bool ok = true;
for (int j = 0; j < m && ok;... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int val, len;
node() {
val = 0;
len = 0;
}
};
int a[200010];
int ans[200010];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
stack<node> s;
for (int i = 0; i < n; i++) {
int len = 0;
while (!s.e... | 11 |
#include <bits/stdc++.h>
using namespace std;
tuple<int, int, int, int> rect[200000];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
vector<int> vl, vr, vd, vu;
int l, r, d, u;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> l >> d >> r >> u;
vl.push_back(l);
v... | 8 |
#include <bits/stdc++.h>
using namespace std;
int f(int n) {
int sum = 0;
while (n) {
sum += (n % 10);
n /= 10;
}
return sum;
}
int main() {
int n;
cin >> n;
vector<int> ans;
for (int i = n - 1; i >= max(0, n - 100); i--) {
if (i + f(i) == n) {
ans.push_back(i);
}
}
sort(ans.be... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
set<string> s;
void add(string &temp) {
for (int i = (m - 1); i >= (0); --i) {
if (temp[i] == '0') {
temp[i] = '1';
break;
}
temp[i] = '0';
}
}
void sub(string &temp) {
for (int i = (m - 1); i >= (0); --i) {
if (temp[i] == '1') {
... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
set<char> s;
string p;
getline(cin, p);
for (int i = 0; i < p.size(); i++) {
if (p[i] >= 'a' && p[i] <= 'z') s.insert(p[i]);
}
cout << s.size() << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int cnt[10], l, s[105];
long long ans, f[12][105], c[105][105];
long long solve(int n) {
memset(f, 0, sizeof(f));
memset(s, 0, sizeof(s));
for (int i = 1; i <= 10; ++i) s[i] = s[i - 1] + cnt[i - 1];
f[0][0] = 1;
for (int i = 1; i ... | 11 |
#include <bits/stdc++.h>
using namespace std;
void solve();
int main(int argc, char const *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
}
int we[1100];
int bu[1100];
int fa[1100];
int dp[1100];
int totalwe[1100];
int totalbu[1100];
vector<int> groups[1100];
int find_par(int x) { return fa[x... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long pw(long long a, long long n, long long m) {
long long res = 1;
while (n) {
if (n & 1) res = res * a % m;
a = a * a % m;
n /= 2;
}
return res;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long t;
cin >>... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
string ans[200010];
int step[200010];
int n, m, k, tot;
void dfs(int r) {
if (k == 0) return;
if (r == 1) {
if (k && m - 1) {
step[++tot] = (k >= m - 1 ? m - 1 : k);
ans[tot] = "R";
k -= step[tot];
}
if (k && ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
long long power(long long b, long long p) {
return p ? ((p & 1 ? b : 1) * power((b * b) % MOD, p >> 1)) % MOD : 1LL;
}
const int _fSZ = 2e5 + 5;
long long fact[_fSZ];
void init_fact() {
fact[0] = 1;
for (int i = 1; i < _fSZ; ++i) fact[i] = (... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int count;
cin >> count;
int global_max = 0;
int local_max = 0;
char c;
string text;
getline(cin, text);
getline(cin, text);
for (unsigned int i = 0; i < text.length(); i++) {
c = text[i];
if (c >= 'A' && c <= 'Z') {
local_max++;... | 0 |
#include <bits/stdc++.h>
using namespace std;
int a, b, mod;
int main() {
scanf("%d%d%d", &a, &b, &mod);
for (int i = 0; i <= a && i < mod; i++) {
if ((mod - (long long)i * 1000000000 % mod) % mod > b) {
printf("1 %.9d\n", i);
return 0;
}
}
printf("2\n");
return 0;
}
| 10 |
#include <bits/stdc++.h>
using namespace std;
long long int mod = 1000000007;
vector<long long int> initializeDiffArray(vector<long long int>& A);
void update(vector<long long int>& D, long long int l, long long int r,
long long int x);
void getArray(vector<long long int>& A, vector<long long int>& D);
long... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1000;
long long n, grid[N][N];
void run() {
cin >> n;
long long fill = 0;
for (long long i = 0; i < n / 2; i++) {
for (long long j = 0; j < n / 2; j++) {
grid[i][j] = 4 * fill + 1;
grid[i][j + n / 2] = 4 * fill + 2;
grid[i + n... | 10 |
#include <bits/stdc++.h>
using namespace std;
template <class A, class B>
ostream& operator<<(ostream& out, const pair<A, B>& a) {
return out << "(" << a.first << ", " << a.second << ")";
}
template <class A>
ostream& operator<<(ostream& out, const vector<A>& a) {
out << "[";
for (auto it = a.begin(); it != a.end... | 7 |
#include <bits/stdc++.h>
using namespace std;
vector<int> ans[200020];
int mx;
int main() {
string s;
cin >> s;
int ind = 1;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '0') {
ans[ind++].push_back(i);
mx = max(mx, ind);
} else {
ind--;
if (!ind || !ans[ind].size()) return pu... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i;
cin >> n;
int min = INT_MAX, max = INT_MIN;
int arr[n], arr2[n], x = -1;
for (i = 0; i < n; i++) {
cin >> arr[i] >> arr2[i];
if (arr[i] < min) min = arr[i];
if (arr2[i] > max) max = arr2[i];
}
for (i = 0; i < n; i++) {
if... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long x, y, a, k;
int main() {
char s;
string l = "", r = "";
cin >> x >> s >> y;
cin >> a;
k = (y + a) / 60;
y = (y + a) % 60;
x = (x + k) % 24;
if (x / 10 == 0) {
l += '0';
}
if (y / 10 == 0) {
r += '0';
}
cout << l << x << ':' << r << ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int lp[15000005];
int qtd[15000005];
int v[300005];
int gcd(int a, int b) {
if (!b) return a;
return gcd(b, a % b);
}
int main() {
int n;
lp[1] = 1;
for (int i = 2; i <= 15000000; i++) {
if (!lp[i]) {
lp[i] = i;
for (long l... | 10 |
#include <bits/stdc++.h>
using namespace std;
double p[200000], val[200000];
int N, M, C;
inline void checkmax(double &x, double c) {
if (x < c) x = c;
}
struct SegmentTree {
double ls[200000 << 2], rs[200000 << 2], sum[200000 << 2], best[200000 << 2];
double ans;
void up(int o) {
sum[o] = sum[o << 1] + sum... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int p = 10007;
int n, m, f[510][210][210], a[310][310];
char s[210];
bool odd;
int power(int x, int k) {
int ret = 1;
for (; k; k >>= 1, x = x * x % p)
if (k & 1) ret = ret * x % p;
return ret;
}
void gauss_elimination(int n) {
for (int i = 1; i <= n; ++i)... | 22 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
double ans = 0;
cin >> n;
for (int i = 1; i <= n; i++) {
ans += (double)1.0 / i;
}
cout << ans;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int dp1[5010][5010], dp2[5010][5010], n, b, c[5010], d[5010], x, sz[5010];
vector<int> g[5010];
void dfs(int node) {
dp1[node][0] = 0;
dp1[node][1] = c[node];
dp2[node][1] = c[node] - d[node];
sz[node] = 1;
for (const auto &it : g[node]... | 16 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void cetak(T t) {
cout << t << ')' << endl;
}
template <typename T, typename... V>
void cetak(T t, V... v) {
cout << t;
if (sizeof...(v)) cout << ", ";
cetak(v...);
}
const int MOD = 1e9 + 7;
int add(int x, int y) {
int ret = x + y;
if (ret... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n;
int num[17];
int sum;
void juge2() {
printf("%d %d\n", num[0], num[3]);
printf("%d %d\n", num[2], num[1]);
}
void juge3() {
if (num[1] + num[3] + num[8] == sum) {
printf("%d %d %d\n", num[1], num[6], num[5]);
printf("%d %d %d\n", n... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000007;
const long double PI = 2 * acos(0.0);
const vector<long long int> dx = {1, -1, 0, 0};
const vector<long long int> dy = {0, 0, 1, -1};
template <typename T = long long int>
vector<T> ga(long long int n, bool oneIndexed = false) {
vecto... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long S, K;
bool ansflag = false;
vector<long long> fib;
vector<long long> path;
void recur(int n, int sum) {
if (sum == 0) {
cout << ((int)((path).size())) + 1 << endl << "0 ";
for (int i = 0; i < ((int)((path).size())); ++i) {
cout << path[i] << " ";
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
map<string, string> mp;
int t;
int n;
cin >> n;
cin >> t;
while (t--) {
string s1, s2;
cin >> s1 >> s2;
mp[s1] = s2;
}
while (n--) {
string m;
cin >> m;
if (m.length() <= mp[m].length()) {
cout << m << ' ';
} el... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, m, ans, mod = 0;
cin >> n >> m;
long long int num[n];
for (long long int i = 0; i < n; i++) {
cin >> num[i];
}
for (long long int i = 0; i < n; i++) {
ans = (num[i] + mod) / m;
cout << ans << " ";
mod = (mod + num[i]... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int Mod = 1000000007, N = 5001;
int n, total[N][N], dp[N][N], up[N], down[N], pre[N];
string s, str;
void add(int &a, long long b) {
if (b > Mod) b %= Mod;
a += b;
while (a > Mod) a -= Mod;
}
long long inverse(int a, int b) {
if (b == 1) return a;
long long ... | 16 |
#include <bits/stdc++.h>
using namespace std;
struct step {
int x1, y1;
int x2, y2;
int x3, y3;
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
vector<vector<int>> a(n, vector<int>(m, 0));
vector<step> ans;
for ... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 105;
int b[12][MAX][MAX], d[MAX][MAX];
int get(int t, int x1, int y1, int x2, int y2) {
return b[t][x2][y2] - b[t][x2][y1 - 1] - b[t][x1 - 1][y2] +
b[t][x1 - 1][y1 - 1];
}
vector<int> m[MAX][MAX];
int main() {
ios_base::sync_with_stdio(false);
... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
;
long long n, i;
cin >> n;
long long purple = 0, blue = 0, green = 0, yellow = 0, red = 0, orange = 0;
for (i = 0; i < n; i++) {
string a;
cin >> a;
if (a.compare("blue") == 0) blue++;
... | 0 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
const int MAX = 2e9;
int main()
{
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int t;
cin >> t;
while (t--) {
map<ll, int>mp;
int n;
cin >> n;
n += 2;
vector<ll... | 4 |
#include <bits/stdc++.h>
using namespace std;
mt19937_64 gen(chrono::high_resolution_clock::now().time_since_epoch().count());
template <typename T>
T randInt(T min, T max) {
uniform_int_distribution<T> dist(min, max);
return dist(gen);
}
template <typename T>
T randDouble(T min, T max) {
uniform_real_distributio... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const unsigned gen_seed =
std::chrono::system_clock::now().time_since_epoch().count();
std::mt19937_64 gen(gen_seed);
long long gcd(long long a, long long b, long long& x, long long& y) {
if (a == 0) {
x = 0;
y = 1;
return ... | 23 |
#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
ostream& operator<<(ostream& out, pair<T1, T2> pair) {
return out << "(" << pair.first << ", " << pair.second << ")";
}
int N;
int in[3005];
int groups[3005];
int gg = 0;
vector<pair<int, int> > ans;
int dfs(int at) {
groups[at] = gg;
if ... | 13 |
#include <bits/stdc++.h>
using namespace std;
int n;
long long cnt = 1;
int main() {
cin >> n;
for (int i = 2; i <= n; i++) cnt = (cnt * 3) % 1000003;
cout << cnt;
}
| 5 |
#include <bits/stdc++.h>
long long int ciel(double a) {
long long int ret = a;
if (a - ret > 0.0000000001) ret++;
return ret;
}
long long int gcd(long long int a, long long int b) {
if (a < b) return gcd(b, a);
if (a % b == 0) return b;
return gcd(b, a % b);
}
double fgcd(double a, double b) {
if (fabs(a)... | 7 |
// Problem : E. Partition Game
// Contest : Codeforces - Codeforces Round #721 (Div. 2)
// URL : https://codeforces.com/contest/1527/problem/E
// Memory Limit : 256 MB
// Time Limit : 3000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include <bits/stdc++.h>
using namespace std;
struct Node{
i... | 17 |
#include <bits/stdc++.h>
using namespace std;
int z[2000010];
char buf[2000010];
int build(int n, int ml) {
int L = 0, R = 0;
for (int i = 1; i < n; i++) {
if (i > R || z[i - L] >= R - i + 1) {
L = i;
R = max(R, i);
while (R < n && buf[R - L] == buf[R]) R++;
z[i] = R-- - L;
} else
... | 4 |
#include <bits/stdc++.h>
int main() {
int i, n, res = 0, j;
scanf("%d", &n);
int h[n], g[n];
for (i = 0; i < n; i++) scanf("%d %d", &h[i], &g[i]);
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
if (h[i] == g[j]) res++;
printf("%d", res);
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
int main() {
int M, N;
cin >> M >> N;
double p = 0;
double res = 0;
for (int i = 1; i <= M; i++) {
double np = pow(1.0 * i / M, N);
res += i * (np - p);
p = np;
}
printf("%.12f\n", res);
}
| 8 |
#include <bits/stdc++.h>
using namespace std;
struct team {
int score;
int miss, point;
string name;
} a[4];
int len = 0;
int find(string s) {
for (int i = 0; i < len; i++)
if (a[i].name == s) return i;
a[len].score = a[len].miss = a[len].point = 0;
a[len++].name = s;
return len - 1;
}
int id[4];
int ... | 10 |
#include <bits/stdc++.h>
using namespace std;
map<long long int, int> mp;
int a[200010];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
mp[0] = 1;
long long int tot = 0, ans = 0;
for (int i = 1; i <= n; i++) {
tot += a[i];
if (mp[tot]) {
ans++;
mp.clear... | 7 |
#include <bits/stdc++.h>
using namespace std;
int arr[150] = {0};
int main() {
int i;
string str;
cin >> str;
for (i = 0; i < str.length(); i++) arr[(int)str[i]]++;
vector<int> v;
v.push_back(arr[(int)'B']);
v.push_back(arr[(int)'l']);
v.push_back(arr[(int)'b']);
v.push_back(arr[(int)'s']);
v.push_b... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
vector<long long> nums;
for (int i = 0; i < n; i++) {
int a;
scanf("%d", &a);
nums.push_back(a);
}
sort(nums.begin(), nums.end(), greater<int>());
long long ans = 0;
long long cul = 0;
int bound = 1;
for (... | 6 |
#include <bits/stdc++.h>
using namespace std;
int arr[100005];
void init() {
for (int i = 0; i < 100005; i++) {
arr[i] = i;
}
}
int root(int i) {
while (i != arr[i]) {
arr[i] = arr[arr[i]];
i = arr[i];
}
return i;
}
bool unionn(int x, int y) {
int r_x = root(x);
int r_y = root(y);
if (r_x ==... | 16 |
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <numeric>
#include<cctype>
#include<deque>
#include<iomanip>
#include<queue>
#include<cstring>
#include<stack>
#include... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
int i;
long long a[n];
for (i = 0; i < n; i++) cin >> a[i];
long long minm = 3000000007;
sort(a, a + n);
for (i = 0; i < n / 2; i++) {
minm = min(minm, a[i + n / 2] - a[i]);
}
cout << minm << endl;
return 0;
}
| 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
int a[t], b[t];
for (int i = 0; i < t; i++) {
cin >> a[i] >> b[i];
int k = (24 - a[i]) * 60 - b[i];
cout << k << endl;
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const char s[27] = "abcdefghijklmnopqrstuvwxyz";
int main() {
int n;
cin >> n;
while (n--) {
int x, y;
cin >> x >> y;
int t = x / y;
for (int i = 0; i < t; i++)
for (int j = 0; j < y; j++) cout << s[j];
int k = x % y;
for (int i = 0; i < ... | 0 |
#include <bits/stdc++.h>
using namespace std;
struct MinCostMaxFlow {
struct Node {
int x, y, cap, cost;
int next;
} edge[1000005];
int e, head[10005], dis[10005], prev[10005], record[10005], inq[10005];
void addEdge(int x, int y, int cap, int cost) {
edge[e].x = x, edge[e].y = y, edge[e].cap = cap,... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long power2[65];
long long n;
vector<long long> V;
void generete_power() {
int i;
power2[0] = 1;
for (i = 1; i < 63; i++) {
power2[i] = power2[i - 1] * 2;
}
}
void binary_search(long long st, long long ed, long long tar) {
long long mid = (st + ed) / 2;
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const int maxm = 3e6 + 5;
const long long mod = 998244353;
long long fac[maxn];
long long fpow(long long a, long long b) {
long long ans = 1;
while (b) {
if (b & 1) ans = ans * a % mod;
a = a * a % mod;
b >>= 1;
}
return ans;
}
... | 15 |
#include <bits/stdc++.h>
using namespace std;
bool is_sort(int ar[], int n) {
for (int i = 0; i < n - 1; i++) {
if (ar[i] > ar[i + 1]) return false;
}
return true;
}
int main() {
int t;
cin >> t;
int n, x, ar[105] = {0}, ty;
ty = t;
while (t--) {
cin >> n;
for (int i = 0; i < n; i++) {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxm = 1e6 + 5;
int buf[maxm];
double q[maxm];
int len[maxm];
void run_case() {
int n;
scanf("%d", &n);
int top = 0;
for (int i = 1; i <= n; ++i) scanf("%d", &buf[i]);
q[++top] = buf[1], len[1] = 1;
for (int i = 2; i <= n; ++i) {
double now = buf[i... | 13 |
#include <bits/stdc++.h>
static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;
template <class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;
int main() {
ll x, y, a1, a2, b1, b2, xx, yy, t;
cin >> x >> y >> a1 >> a2 >> ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int pri = (1e9) + 7;
int h1[5010], f1[5010];
int main() {
int *h = h1, *s = f1, *t;
int i, j, a, b, n, k, ans = 0;
scanf("%d%d%d%d", &n, &a, &b, &k);
if (b < a) {
b = n + 1 - b;
a = n + 1 - a;
}
for (i = 1; i < a; i++) s[i] = 0;
for (i = a; i < b... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const long double pi = 3.141592653589793238462;
const long double eps = 1e-6;
const long long mod = 1e9 + 7;
bool b(string a, string b) {
for (long long i = 0; i < a.size(); ++i)
if (a[i] < b[i])
return 0;
else if (a[i] > b[i])
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n;
string s[55];
int a[55][55];
int dp[55][55][55][55];
int f[55][55];
int func(int xa, int ya, int xb, int yb) {
return f[xb + 1][yb + 1] - f[xa][yb + 1] - f[xb + 1][ya] + f[xa][ya];
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ce... | 15 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename T>
using min_queue = priority_queue<T, vector<T>, greater<T>>;
template <typename Node, typename FromT = typename Node::FromT,
typename UpdateT = typename Node::UpdateT>... | 11 |
#include <bits/stdc++.h>
using namespace std;
int const MAXN = 2000;
int const MAXM = 2000;
int n, m;
int white(char ch) { return ch == ' ' || ch == ',' || ch == '(' || ch == ')'; }
struct var_t {
string name, type;
void read(string st) {
string cur;
st += (char)' ';
int cnt = 0;
for (int i = 0; i <... | 10 |
#include<iostream>
#include<cmath>
#include<stdlib.h>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
const int MAXN = 1e6+10;
const int mod= 1e9+7;
typedef long long ll;
#define eps 1e-4
int b[MAXN];
int c[MAXN];
int tot1=0,tot2=0;
int a[M... | 7 |
#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <cmath>
#include <functional>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <map>
#include <set>
#ifdef XLor
#define dbg(args...) cout << "\033[32;1m" << #args << " -> ", err(args)
void err() ... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, s2;
cin >> s >> s2;
map<char, int> mp;
map<char, int> m;
for (int i = 0; i < s.length(); i++) {
if (mp[s[i]] == 0)
mp[s[i]] = 1;
else
mp[s[i]]++;
}
for (int i = 0; i < s2.length(); i++) {
if (m[s2[i]] == 0)
... | 4 |
#include <bits/stdc++.h>
using namespace std;
bool in_array(char arr[], int arr_len, char query) {
bool is_in = false;
for (int i = 0; i < arr_len; i++) {
char lower_case_query = tolower(query);
if (lower_case_query == arr[i]) {
is_in = true;
return is_in;
}
}
return is_in;
}
int main() ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
vector<int> level(n, 0);
vector<int> at_level_count(n, 0);
at_level_count[0] = 1;
for (int i = 1; i < n; ++i) {
int parent;
scanf("%d", &parent);
--parent;
level[i] = level[parent] + 1;
at_level_count[leve... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long n, n1, n2, ans, flist[1000005], fn;
void updateans(long long a, long long b, long long c) {
if (a > 0 && b > 0 && c > 0) {
if (a == b) {
if (b == c)
ans++;
else
ans += 3;
} else if (b == c)
ans += 3;
else
ans +... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
std::ios_base::sync_with_stdio(false);
int n, K;
cin >> n >> K;
vector<tuple<int, int, int>> a, b;
for (int i = 0; i < n; ++i) {
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
a.emplace_back(x1 + x2, y1 + y2, i);
... | 15 |
#include <bits/stdc++.h>
using namespace std;
int p[21], d[2100200], a[200200], n, m, b[200200], h = 0;
string s[200200];
void pre(void) {
p[0] = 1;
for (int i = 1; i < 21; ++i) p[i] = p[i - 1] << 1;
}
void read(void) {
cin >> n;
for (int i = 0; i < n; ++i) cin >> s[i];
m = s[0].length();
b[0] = m;
for (i... | 20 |
#include <bits/stdc++.h>
using namespace std;
long long link[2 * 100000 + 1], sizet[2 * 100000 + 1], n, m, res = 0;
long long find(long long x) {
while (x != link[x]) x = link[x];
return x;
}
bool same(long long i, long long j) { return find(i) == find(j); }
void unite(long long i, long long j) {
i = find(i);
j... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long modex(long long a, long long b) {
long long ans = 1;
a %= 1000000007;
if (a == 0) return 0;
while (b > 0) {
if (b & 1) ans = (ans * a) % 1000000007;
b = b >> 1;
a = (a * a) % 1000000007;
}
return ans;
}
long long modex1(long long a, long lo... | 11 |
#include <bits/stdc++.h>
using namespace std;
int q, n, o, z, f;
char ch[100000];
int sum[100000];
int main() {
cin >> q;
while (q--) {
f = -1;
o = 0;
cin >> n;
for (int i = 1; i <= n; i++) sum[i] = 0;
for (int i = 1; i <= n; i++) {
cin >> ch[i];
sum[i] = sum[i - 1] + ch[i] - '0';
... | 1 |
#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];
string s;
getline(cin, s);
bool ok = true;
for (int j = 0; j < n; j++) {
getline(cin, s);
int cnt = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == 'a')
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
for (int i = 0; i < 10000; i++) {
if (i * (i - 1) >= n) {
cout << i * 2 + (i - 1) * 2;
return 0;
}
if (i * i >= n) {
cout << i * 4;
return 0;
}
}
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-6;
const double PI = 3.14159265358979323846264338f;
const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const long long mod = (int)1e9 + 7;
const int MAXN = 1000005;
inline int read() {
int c = 0, f = 1;
char ch = getchar();
while (ch < '0'... | 14 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.