solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long power(long long a, long long b) {
long long res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
}
return res;
}
long long min(long long a, long long b) {
if (a >... | 6 |
#include <bits/stdc++.h>
using namespace std;
int dx[4] = {0, 1, -1, 0};
int dy[4] = {1, 0, 0, -1};
void a() {
long long n;
cin >> n;
vector<long long> v(2 * n + 1);
vector<long long> odd, even;
for (long long i = 1; i <= 2 * n; i++) {
cin >> v[i];
if (v[i] % 2) {
odd.emplace_back(i);
} else... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long l, r;
long long cal(long long n) {
long long t = n, x = 1;
while (t != 0) x *= 10, t /= 10;
x--;
return n * (x - n);
}
int main() {
cin >> l >> r;
long long res = 0, k = 5;
res = max(cal(l), cal(r));
for (int i = 0; i <= 9; i++) {
if (k >= l &&... | 8 |
#include <bits/stdc++.h>
using namespace std;
vector<int> nei[501];
int ideg[501];
bool outcyc[501];
int main() {
int n, m, i;
scanf("%d%d", &n, &m);
for (i = 1; i <= m; i++) {
int x, y;
scanf("%d%d", &x, &y);
nei[x].push_back(y);
}
for (i = 1; i <= n; i++) {
int j, k, outcycno = 0;
fill(i... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<char> calced(n);
vector<string> a(n);
set<string> have;
int res = 0;
for (string& pin : a) {
cin >> pin;
have.insert(pin);
}
for (int i = 0; i < n; i++)... | 6 |
#include <bits/stdc++.h>
using namespace std;
struct SGT {
int minn[1200000], maxn[1200000];
inline void pushup(int o) {
minn[o] = min(minn[o * 2], minn[o * 2 + 1]);
maxn[o] = max(maxn[o * 2], maxn[o * 2 + 1]);
}
void build(int l, int r, int o, int *fir1, int *fir2) {
if (l == r) {
minn[o] = f... | 21 |
#include <bits/stdc++.h>
const int inf = 0xfffffff;
const long long INF = 1ll << 61;
using namespace std;
int n, m;
int nnum[100005 + 55];
int fa[100005 + 55];
int sum[100005 + 55];
typedef struct Node {
int fro, to, nex;
int val;
Node(int a = 0, int b = 0, int c = 0) : fro(a), to(b), val(c) {}
};
Node edge[10000... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}
int pw(int a, int n) {
int ans = 1;
while (n... | 4 |
#include <bits/stdc++.h>
using namespace std;
class node {
public:
long long int second;
long long int length;
};
long long int power(long long int n, long long int k) {
long long int result = 1;
while (k > 0) {
if (k % 2 == 1) result = (result * n) % 1000000009;
n = (n * n) % 1000000009;
k = k / 2... | 8 |
#include <bits/stdc++.h>
int main() {
int a, b, y, sophuttoida;
scanf("%d %d", &a, &b);
y = a - b;
if ((a + b) > 2) {
if (y % 3 == 0) {
sophuttoida = a + b - 3;
} else {
sophuttoida = a + b - 2;
}
} else {
sophuttoida = 0;
}
printf("%d", sophuttoida);
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
inline string get_string() {
char ch[1000000];
scanf("%s", ch);
return ch;
}
inline int get_Int() {
int x;
scanf("%d", &x);
return x;
}
inline string get_String() {
string x;
cin >> x;
return x;
}
inline long long get_long() {
long long x;
cin >> x;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double w, h, w1 = 1, h1 = 1, w2, h2;
cin >> h >> w;
for (int x = 0; (1ll << x) <= h; x++) {
h2 = (1 << x);
w2 = ceil(h2 / 1.25 - 1e-9);
if (w2 < floor(h2 / .8 + 1e-9) + 1e-9 && w2 < w + 1e-9) {
w2 = min(w, floor(h2 / .8 + 1e-9));
i... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 100060;
class Point {
public:
double x, y;
void read() { scanf("%lf%lf", &x, &y); }
Point(double _x = 0, double _y = 0) : x(_x), y(_y) {}
double len() { return sqrt(x * x + y * y); }
} P, v[Maxn];
const double pi = acos(-1);
const double eps = 1e-7... | 11 |
#include <bits/stdc++.h>
using namespace std;
int n;
map<string, int> count_;
string ans[70007];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
string s;
cin >> s;
for (int j = 0; j < 9; j++) {
for (int l = 1; l <= 9 - j; l++) {
string v = s.substr(j, l);
if (count_[v] == 0)... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 5;
int n, a, sol, c[MAX];
multiset<int> s;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a);
c[a]++;
}
for (int i = 0; i <= MAX; i++)
if (c[i]) sol += c[i] - 1;
printf("%d\n", sol + 1);
return 0;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2097152;
int n, m, a[N], r[N], pw, len;
bool vis[N];
struct Complex {
double r, i;
};
inline Complex operator+(Complex a, Complex b) {
return {a.r + b.r, a.i + b.i};
}
inline Complex operator*(Complex a, Complex b) {
return {a.r * b.r - a.i * b.i, a.r * ... | 20 |
#include <bits/stdc++.h>
using namespace std;
struct debugger {
template <typename T>
debugger& operator,(const T& v) {
cerr << v << " ";
return *this;
}
} debug;
template <typename T1, typename T2>
inline ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
return os << "(" << p.first << ", " << p... | 14 |
#include <bits/stdc++.h>
using namespace std;
const long int z = 1000000007;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int k, j;
long long c = 0, sum = 0;
cin >> k;
string s;
cin >> s;
vector<long long> v;
for (int i = 0; i < s.length(); i++) {
if (s[i] == '1') {
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, m, type, x, y, z, sx, sy, sz, Ix, Iy, Iz, cx, cy, k, tot, Q, A, S, tmp;
int L[N * 25], R[N * 25], a[N * 25], rt[N], son[N], ne[N], In[N], Out[N], v[N],
d[N], f[N][20];
void dfs(int x) {
In[x] = m++;
for (int y = son[x]; y; y = ne[y])
... | 21 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
int const nmax = 200000;
class FenwickTree {
private:
int n;
vector<int> aib;
public:
FenwickTree(int n_) {
n = n_;
aib.resize(1 + n);
}
void update(int pos, int val) {
for (int x = pos; x <= n; x += (x ... | 13 |
#include <bits/stdc++.h>
using namespace ::std;
const int maxn = 2100 * 500;
const int maxm = 4100;
const int mod = 1e9 + 7;
const int inf = 1e9 + 500;
vector<pair<char, pair<int, int> > > bach[maxn];
int cn = 2;
int en[maxn];
int trii[maxm][26];
int vazn[maxm][26];
int enn[maxm];
int sz[maxn];
int cnn = 1;
int k;
int ... | 10 |
#include <iostream>
#include <vector>
#include <random>
typedef unsigned long long ull;
typedef signed long long sll;
using namespace std;
size_t vmin(vector<size_t>& values) {
size_t ans = -1;
for (auto& v : values) ans = min(ans, v);
return ans;
}
size_t vmax(vector<size_t>& values) {
size_t ans = 0... | 22 |
#include <bits/stdc++.h>
long long dp[105][105][105];
long long pre[105][105][105];
long long flo[105][105][105];
long long cost[105][105];
long long clr[105];
int main() {
int n, m, cnt;
scanf("%d%d%d", &n, &m, &cnt);
for (int i = 1, p; i <= n; i++) {
scanf("%d", &p);
clr[i] = p;
}
for (int i = 1, p;... | 9 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O2,no-stack-protector,unroll-loops,fast-math")
const long long maxn = 3e5 + 10, maxm = 1e6 + 10, lg = 14, mod = 1e9 + 7,
inf = 1e18;
const long long M = (1 << lg) + 20;
string s;
long long a[lg], b[lg], dp[M], ans = inf;
long long ctn(c... | 25 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chk_mi(T &x, T y) {
return x > y ? x = y, 1 : 0;
}
template <class T>
bool chk_mx(T &x, T y) {
return x < y ? x = y, 1 : 0;
}
template <class T>
T Max(T x, T y) {
return x > y ? x : y;
}
template <class T>
T Min(T x, T y) {
return x < y ? x :... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int N = 405;
int n, m;
int dist[N][N];
vector<int> reach[N][N], adj[N], nx;
double prob[N], dprob[N];
double f(int city) {
double pE = 0;
for (int dist1 = 0; dist1 < n + 1; ++dist1) {
double today = 1.0 / n;
auto& reachables = reach[city][dist1];
if (r... | 21 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string s1, s2;
int i, j, l;
cin >> s1 >> s2;
l = s1.length();
bool ch = false;
for (i = l - 1; i >= 0; i--) {
if (s1[i] != 'z') {
s1[i]++;
for (j = i + 1; j < l; ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int arr[N];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i) scanf("%d", &arr[i]);
sort(arr, arr + n);
int ans = n;
long long sum = 0;
for (int i = 0; i < n; ++i) {
if (sum > arr[i])
--ans;
else
sum +... | 5 |
//我忘不掉夏小姐了。
//如果不是知道了咩粟小姐,说不定我已经对这个世界没有留恋了。
//巫沐小姐真的好可爱啊。做料理的时候笨拙的样子很可爱,故意撒娇,修女小姐也很可爱,唱歌的时候很可爱,生气拍桌子的时候也很可爱。
//所以我离不开星夜小姐了。如果早晨不是有多多小姐的起床闹钟的话,说不定我永远都不愿意睁眼了。如果晚上不是有黎歌小姐的直播预定的话,这一天我都不希望过完了。
//萨摩小姐的眼睛好灵动,如果能映照出我就好了。冷鸢小姐的笑容好温柔,如果只为我一个人绽放就好了。鹿乃小姐的头发好柔顺,如果能让我尽情抚摸就好了。
//白桃小姐这样的存在真的是被允许的吗。
//只是像现在这样默念七海小姐的名字,我就觉得自己是世界上最最最最最幸福的... | 20 |
#include <bits/stdc++.h>
using namespace std;
int mp[505][505];
int main() {
int n;
scanf("%d", &n);
memset(mp, 0, sizeof(mp));
char s[505];
for (int i = 1; i <= n; i++) {
scanf("%s", s + 1);
for (int j = 1; j <= n; j++) {
if (s[j] == 'X') mp[i][j] = 1;
}
}
int ans = 0;
for (int i = 2;... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 2e5 + 5;
int T, n, t[Maxn * 4], m;
long long ans;
struct Node {
long long num;
int ini, seq;
} a[Maxn];
bool cmp1(const Node &a, const Node &b) { return a.num < b.num; }
bool cmp2(const Node &a, const Node &b) { return a.ini < b.ini; }
inline int lowbit... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long n, L, brk, cnt = 0;
cin >> n >> L >> brk;
long long t = 0;
for (long long i = 0; i < n; i++) {
long long x, y;
cin >> x >> y;
cnt = cnt + (x - t) / brk;
t = x + y... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int one[8] = {0};
for (int i = 1; i < 8; i++) one[i] = one[i / 2] + i % 2;
{
int n, m;
cin >> n >> m;
string mat[n];
for (int i = 0; i < n; i++) {
cin >> mat[i];
}
... | 12 |
#include <bits/stdc++.h>
int main() {
int k;
scanf("%d", &k);
int q = 0;
for (int i = 1; i < k; i++) {
for (int j = 1; j < k; j++) {
if ((q % 10) + i >= k)
q += 10 + i - k;
else
q += i;
printf("%d ", q);
}
printf("\n");
q = 0;
}
return 0;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 4e5 + 5;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const long long INF = 9223372036854775807;
long long a[MAXN], b[MAXN], c[MAXN];
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n, m, k;
scanf("%d%d%d", &n, &m, &k);
for ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int Log = 60;
const int N = 210000;
const int mod = 1e9 + 7;
long long p2[Log + 5];
struct edge {
int to, nxt;
long long co;
} e[N * 2];
int h[N], E = 0;
int n, m;
long long lb[Log + 5], tot = 0, cnt[Log + 5], siz[Log + 5];
int used[N], f[N], g[N];
long long lan[N... | 18 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const long long maxn = 200010;
long long n, k;
long long fac[maxn];
long long ifac[maxn];
long long ksm(long long a, long long b) {
long long ret = 1;
while (b != 0) {
if (b % 2 == 1) ret = (ret * a) % mod;
b /= 2;
a = (a * a... | 15 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("fast-math")
#pragma GCC optimize "-O3"
bool ask(int x1, int y1, int x2, i... | 16 |
#include <bits/stdc++.h>
const int MAXN = (int)(1e8);
const int inf = (int)(1e9);
using namespace std;
int main() {
long long n, h, k, s = 0, t = 0, temp = 0;
cin >> n >> h >> k;
for (int i = 0; i < n; i++) {
long long x;
cin >> x;
if (s + x > h) {
temp = (s - (h - x)) / k;
if ((s - (h - x... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, n, m, min = 0, max = 0, c = 0;
cin >> n >> m;
int ar[m], arr[m];
for (int i = 0; i < m; i++) {
cin >> ar[i];
arr[i] = ar[i];
}
while (c < n) {
sort(ar, ar + m);
i = 0;
while (ar[i] == 0 && i < m) i++;
min += ar[i];
... | 3 |
#include <bits/stdc++.h>
int main() {
int n;
int m;
int arr[100];
int x;
int y;
scanf("%d", &n);
int i;
for (i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
scanf("%d", &m);
for (int i = 0; i < m; i++) {
scanf("%d %d", &x, &y);
if ((x - 1) >= 1) {
arr[x - 2] = arr[x - 2] + (y - 1);
... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long pr(long long a, long long b, char c) {
if (c == '+') return a + b;
return a * b;
}
int main() {
vector<int> num(4);
vector<char> sym(3);
vector<bool> check(4, 0);
long long result = 1000000000000;
for (int i = 0; i < 4; i++) cin >> num[i];
for (int... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int max_n = 500005, inf = 1111111111;
int n, m, u[max_n], v[max_n], f[max_n];
vector<int> g[max_n], ans;
void add_edges() {
vector<int> q;
for (int i = 1; i <= n; ++i) {
if (g[i].size() % 2 == 1) {
q.push_back(i);
}
}
if (q.size() % 2 == 1) {
... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, b1, b2, mul, X, Y, a[15], b[15], i;
while (scanf("%I64d %I64d", &n, &b1) == 2) {
for (i = 0; i < n; i++) {
scanf("%I64d", &a[i]);
}
scanf("%I64d %I64d", &m, &b2);
for (i = 0; i < m; i++) {
scanf("%I64d", &b[i]);
... | 3 |
#include <bits/stdc++.h>
using namespace std;
void FastIO() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
}
long long int power(long long int a, long long int b) {
long long int ret = 1;
while (b) {
if (b % 2) ret *= a;
a *= a;
b /= 2;
}
return ret;
}
int main() {
FastIO();
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
char ch;
cin >> ch;
string s;
string s2[100];
getline(cin, s);
int i;
for (i = 0; i < t; i++) {
getline(cin, s2[i]);
}
if (t % 2 == 0) {
cout << "home" << endl;
} else {
cout << "contest" << endl;
}
retur... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y) {
long long res = 1;
while (y) {
if (y & 1) res = (res * x) % 1000000007;
y = y / 2, x = (x * x) % 1000000007;
}
return res % 1000000007;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, m, ans;
char a[22][100002];
int f[21][(1 << 20) + 1];
int main() {
scanf("%d%d", &n, &m);
ans = 1e9;
for (int i = 1; i <= n; i++) scanf("%s", a[i] + 1);
for (int i = 1; i <= m; i++) {
int tmp = 0;
for (int j = 1; j <= n; j++) tmp = tmp * 2 + a[j][i] -... | 18 |
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
struct info {
ll ls, rs, sum, len;
ll sl, sr;
info operator+(const info &t) {
ll nls = (ls == len && sr <= t.sl) ? (ls + t.ls) : ls;
ll nrs = (t.rs == t.len && sr <= t.sl) ? (t.rs + rs) : t.rs;
ll nlen = len + t.len;
ll nsum = sum +... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200100;
int N;
vector<int> edge[MAXN];
int par[MAXN];
int dep[MAXN];
void flood(int cloc, int cdep, int last) {
par[cloc] = last;
dep[cloc] = cdep;
for (int neigh : edge[cloc]) {
if (neigh == last) continue;
flood(neigh, cdep + 1, cloc);
}
}... | 20 |
#include <bits/stdc++.h>
using namespace std;
long long mn = 1e9, mx = -1e9, ans, cnt, sm;
bool ok, okk, used[1000010], use[10010];
string s[13] = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "B", "H"};
int getpos(string a) {
for (int i = 0; i < 12; i++) {
if (s[i] == a) {
return i;
}
}
}
in... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x;
int c[30], r[30];
for (int i = 0; i < 30; i++) {
c[i] = 0;
r[i] = 0;
}
cin >> n;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) {
cin >> x;
c[j] += x;
r[i] += x;
}
int ans = 0;
for (int i = 0;... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int n, m, a[N], b[N];
struct item {
int val, le, ri;
};
item t[4 * N];
inline item mrg(item a, item b) {
if (a.le == -1) {
return b;
}
if (b.le == -1) {
return a;
}
item c;
c.val = a.val + b.val - (a.ri < b.le);
c.le = a.le;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
char G[205][205];
struct LOOP {
int mask;
} LP[205 * 205];
int shu[205][205], flag[205][205];
int dp[205][205], data[10][2], n, m, nct, nn;
bool judge(int x, int y) {
if (x < 1 || x > n || y < 1 || y > m) return false;
return true;
}
char s[1000005];
int mk[1 << 11], ... | 17 |
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
void chmin(T &t, U f) {
if (t > f) t = f;
}
template <class T, class U>
void chmax(T &t, U f) {
if (t < f) t = f;
}
signed main() {
long long a, b, c;
scanf("%lld:%lld%lld", &a, &b, &c);
long long t = a * 60 + b + c;
t %= 24 * 60;
p... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, k;
cin >> n >> k;
long long int pow[n];
for (long long int i = 1; i <= n; i++) cin >> pow[i];
long long int MAX = pow[1], num = 0;
for (long long int i = 2; i <= n && num < k; i++) {
if (pow[i] < MAX)
num++;
else {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string zero = ".";
string one = "-.";
string two = "--";
string code;
cin >> code;
string ans;
for (int i = 0; i < code.length(); i++) {
if (code[i] == '.') {
ans += "0";
continue;
}
if (code[i] == '-') {
if (i + 1 < ... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long fastpow(long long a, long long b,
long long m = (long long)(1e9 + 7)) {
long long res = 1;
a %= m;
while (b > 0) {
if (b & 1) res = (res * a) % m;
a = (a * a) % m;
b >>= 1;
}
return res;
}
int32_t main() {
long long n, m;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, q, k, ans;
string s;
vector<pair<string, string>> teams;
map<string, int> a;
map<string, int> b;
int isB[1005];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 0; i < n; i++) {
string s, t;
cin >> s >> t;
s =... | 11 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double EPS = 1e-6;
const int infi = (int)1e9;
const long long infl = (long long)1e16;
const int MOD = (int)1e9 + 7;
const int MAX = (int)5e5 + 10;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1, 0};
const int dy[] = {0, 0, -1, 1, 1, -1, 1, -... | 9 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> adjList[200005];
long long x[200005], n, dp[200005][2];
long long FastMod(long long a, long long b) {
long long res = 1;
while (b > 0) {
if (b & 1) res = (res * a) % 1000000007;
a = (a * a) % 1000000007;
b = b >> 1;
}
return res;
}
void... | 12 |
#include <bits/stdc++.h>
using namespace std;
double pow(double a, int b) {
double r = 1;
double base = a;
while (b != 0) {
if (b & 1) r *= base;
base *= base;
b >>= 1;
}
return r;
}
int main() {
int n, m;
while (scanf("%d %d", &m, &n) != EOF) {
double ans = 0;
for (int i = 1; i <= m; ... | 8 |
#include <bits/stdc++.h>
using namespace std;
struct p {
int st, en, d;
};
bool cmp(p a, p b) { return a.d < b.d; }
bool cmp1(p a, p b) { return a.st < b.st; }
p b[500005];
long long dp[5005], dp1[5005], dp2[5005];
int a[500005];
int main() {
for (int i = 0; i < 5005; i++)
dp[i] = 100000000000000LL, dp1[i] = 10... | 14 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops", "omit-frame-pointer", "inline")
#pragma GCC option("arch=native", "tune=native", "no-zero-upper")
#pragma GCC target("avx2")
using namespace std;
template <typename T>
void maxtt(T& t1, T t2) {
t1 = max(t1, t2);
}
template <typename T>
void mintt(... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
int i, j, k;
int m, n;
int a, b;
int num;
while (scanf("%d%d", &n, &m) != EOF) {
a = 0;
b = 1000;
while (n--) {
scanf("%d%d", &j, &k);
if (j > k) {
i = k;
k = j;
j = i;
}
if (j > a) ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int R, C, K, Tail;
int Board[60][60], Road[60][60], Best[60][60], Oki[60][60];
int Allow[100000][5];
int Last[60][60];
char Now[5];
int Res;
int Check[30];
char Ans[10000];
int QR[10000], QC[10000];
void pre_process(char now, int left) {
if (now > 'z') {
if (left == 0... | 16 |
#include <bits/stdc++.h>
using namespace std;
char W[510][510];
int p[250010];
int sz[250010];
int n, k;
int find(int x) {
if (x == p[x]) return x;
return p[x] = find(p[x]);
}
void join(int x, int y) {
int xroot = find(x), yroot = find(y);
if (xroot != yroot) {
sz[yroot] += sz[xroot];
p[xroot] = yroot;
... | 16 |
#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e5 + 5, mod = 1e9 + 7, bit = 60;
signed main() {
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
long long int n, t, curr;
cin >> n >> t;
while (t--) {
cin >> curr;
string s;
cin >> s;
for (auto x : s) {
... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 7;
inline int ri() {
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 * 10 + c - 48;
return f ? x : -x;
}
int v[N];
int n, cur, cnt;
int ans;
void o... | 7 |
#include <bits/stdc++.h>
const int inf = 0x3f3f3f3f;
using namespace std;
const int N = 2e6 + 5;
const double eps = 1e-9;
long long mod = 1e9 + 7;
long long n, a, b, c, d, st, len;
struct node {
long long tim, tp;
} p[N];
long long calc1(long long x) {
if (x == -1) return 0;
return x ? a : -b;
}
long long calc2(l... | 16 |
#include <bits/stdc++.h>
using namespace std;
bool br1, br2, br;
long long n, k, x, y, z, mini, maxi, w, l, ind, ini, sum, t, len, r, q, m,
imini;
long long _rank(long long x) {
long long sum = 0;
for (long long i = 1; i < n + 1; i++) sum += min(x / i, m);
return sum;
}
long long bin() {
x = 0;
z = n * m;... | 10 |
#include <bits/stdc++.h>
using namespace std;
string s;
long long n;
vector<long long> v;
bool check(long long x) {
long long pos = 0;
long long ret = 0;
for (int i = 0; i < (int)v.size(); i++) {
pos += v[i];
if (pos > x) {
pos = v[i];
ret++;
}
}
return ret + 1 <= n;
}
int main() {
i... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int m, n;
cin >> m >> n;
int a[111][111];
bool t = true;
int res[101][101];
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) {
res[i][j] = -1;
cin >> a[i][j];
}
}
for (int i = 1; i <= m; i++) {
for (int j =... | 5 |
#include <bits/stdc++.h>
using namespace std;
double a, v, l, d, w, t, vf, v1, xf, x, d1;
double timp(double v0, double l) {
double x, t = 0;
x = (v * v - v0 * v0) / (2 * a);
if (x <= l) {
t += (double)(l - x) / v + x / ((v + v0) / 2);
return t;
} else {
v = (double)sqrt(2 * a * l + v0 * v0);
t ... | 13 |
#include <bits/stdc++.h>
using namespace std;
stack<int> lf;
int q[12345], val[12345], op[12345], memo[12345][123][2];
bool done[12345][123][2], ispls;
string e;
void parse(int l, int r) {
if (e[l] == '(') {
parse(l + 1, q[l] - 1);
parse(q[l] + 1, r - 1);
op[l] = op[l + 1] + op[q[l] + 1] + 1;
} else {
... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int INF = (is_same<int, long long>::value ? 1e18L + 666 : 1e9L + 666);
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
template <class t1, class t2>
bool cmax(t1 &a, const t2 &b) {
if (a < b) {
a = b;
return true;
}
return f... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
void _debug() { cerr << "]" << endl; }
template <typename T>
void _debug(T a) {
cerr << a << ']' << endl;
}
template <typename T, typename... Args>
void _debug(T a, Args... args) {
cerr << a << ", ";
_debug(args...);
}
void solve() {
int n, m, c... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = LLONG_MAX;
int n, q, sq, len, ord, ii, jj, val, mx, mn, mxpos, mnpos;
long long lazy[1000];
vector<pair<long long, long long> > S[1000];
inline int getseg(int pos) { return pos / sq + (pos % sq != 0); }
void prop(int as) {
for (int i = 0; i < S[as].s... | 17 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
if (a < b) swap(a, b);
while (b != 0) {
a %= b;
swap(a, b);
}
return a;
}
int n, m, q;
int x[2000000];
int y[2000000];
int z[2000000];
void place(int i, int a) {
int j = i;
i += m;
x[i] = a;
y[i] = j;
z[i] = j;
while (i > ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int a[27], cnt = 1, m, t, anss = 0, tmp[27], p[1005], num[1005];
char s[15];
long long n;
struct node {
int digit[125][125];
} ans, temp, start;
node times(node aa, node b, int x) {
node c;
for (int i = 0; i < x; i++)
for (int j = 0; j < x; j++) c.digit[i][j] = 0;... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const double eps = 1e-6;
const double pi = 1.00 * acos(-1.00);
void _print(long long t) { cerr << t; }
void _print(int t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(long double t) { cerr << t; ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, a[200005], q, ans[200005], root[200005], len[200005];
int cidx[200005], hang[200005];
long long m[200005];
basic_string<int> inv[200005], qry[200005];
basic_string<int> root_inv[200005], occ[200005], hang_inv[200005];
bool st[200005], cyc[200005];
void dfs1(int x) {
... | 21 |
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 3007;
string a[MAXN], b[MAXN];
long long l[MAXN], r[MAXN];
mt19937 rnd(time(0));
long long MOD = -1;
const long long BASE = 129;
const long long MN = 1e9;
const long long ADD = 1e6 + 7;
bool check(long long n) {
for (long long d = 2; d * d <= n; ++d... | 16 |
#include <bits/stdc++.h>
using namespace std;
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define loop(i, a) for (int i = 0; i < (a); ++i)
#define cont(i, a) for (int i = 1; i <= (a); ++i)
#define circ(i, a, b) for (int i = (a); i <= (b); ++i)
#define range(i, a, b, c) for (int i = (a); (c) > ... | 26 |
#include <bits/stdc++.h>
using namespace std;
void preprocess(void) { return; }
template <typename flow_t = int, typename cost_t = int>
struct mcSFlow {
struct Edge {
cost_t c;
flow_t f;
int to, rev;
Edge(int _to, cost_t _c, flow_t _f, int _rev)
: c(_c), f(_f), to(_to), rev(_rev) {}
};
sta... | 14 |
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
int main(void) {
ios::sync_with_stdio(false);
cin.tie(0);
string s;
cin >> s;
bool eq = true;
string pool;
int conc = 0;
string vowel = "aeiou";
for (int i = (int)(0); i < (int)(s.length()); i++) {
bool is_cons = find... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int oo = 2000000009;
const double eps = 1e-9;
int main() {
int n;
int a[1005];
scanf("%d", &n);
for (int i = int(0); i <= int(n - 1); i++) scanf("%d", &a[i]);
bool f = true;
int ans = 0;
for (int i = 0; i < n - 1; i++) {
int count = 1;
for (int j... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, t;
cin >> s >> t;
int n = s.length();
bool turn = false;
int count = 0, i;
for (i = 0; i < n; i++) {
if (s[i] == t[i])
continue;
else {
count++;
if (turn == false) {
turn = true;
continue;
} ... | 3 |
#include <bits/stdc++.h>
const int INF = (int)(1e9);
const long long INFLL = (long long)(1e18);
const double EPS = 1e-13;
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
vector<int> f(n), s(n), a(n + 1);
for (int i = (0); i < (int)(n); i++) cin >> f[i];
for (int i = (0);... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, x, y;
void gcd(long long a, long long b, long long& d, long long& x, long long& y) {
if (b == 0) {
d = a;
x = 1;
y = 0;
return;
}
gcd(b, a % b, d, y, x);
y -= (a / b) * x;
}
int get(long long x, long long y) {
long long a, b, d, key... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int p = n / (2 * k + 1);
int q = n % (2 * k + 1);
if (p == 0) {
cout << "1\n";
cout << q / 2 + 1 << "\n";
} else if (q == 0) {
cout << p << "\n";
for (int i = 1; i <= p; ++i) {
cout << (k + 1) + (i - 1)... | 5 |
#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 a[105][105];
int main() {
long long cs, ts, i, j, k, x, y, z, q, m, n;
while (scanf("%lld", &n) != EOF) {
mem... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300010;
int n, m, x, k, a[MAXN], c[MAXN];
long long ans, b[MAXN];
void add(int x) {
for (; x <= m; x += x & -x) c[x]++;
}
long long ask(int x) {
long long ans = 0;
for (; x; x -= x & -x) ans += c[x];
return ans;
}
int main() {
scanf("%d%d%d", &n, ... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long w[100010], sum1[100010], sum2[100010];
int main() {
long long n, l, r, Ql, Qr;
cin >> n >> l >> r >> Ql >> Qr;
for (int i = 0; i < n; i++) cin >> w[i];
sum1[0] = w[n] = 0;
for (int i = 1; i <= n; i++) sum1[i] = sum1[i - 1] + w[i - 1] * l;
sum2[n] = 0;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long powmod(long long a, long long b, long long MOD) {
long long ans = 1;
while (b) {
if (b % 2) ans = ans * a % MOD;... | 10 |
#include <bits/stdc++.h>
int n, m, c;
int main() {
scanf("%d%d", &n, &m);
c = n * m - 1;
for (int i = 0; i + i < c; i++)
printf("%d %d\n%d %d\n", i / m + 1, i % m + 1, (c - i) / m + 1,
(c - i) % m + 1);
if (!(c & 1)) printf("%d %d\n", n / 2 + 1, m / 2 + 1);
}
| 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2332;
int n, tot, A[N], B[N], R[N], T[N];
vector<pair<int, int> > V;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &A[i]), R[A[i]] = i;
for (int i = 1; i <= n; i++) scanf("%d", &B[i]), T[B[i]] = i;
for (int i = n; i; i--) {
... | 15 |
#include <bits/stdc++.h>
using namespace std;
int N, serverAx, serverAy, tipo;
int x, y, serverBx, serverBy;
int main() {
scanf("%d", &N);
for (int i = 0; i < N; i++) {
scanf("%d%d%d", &tipo, &x, &y);
if (tipo == 1) {
serverAx += x;
serverAy += y;
} else {
serverBx += x;
serverBy... | 0 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ios_base :: sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n; cin >> n;
vector<int> a(n), oc[n + 1];
for(int i = 0; i < n; i ++){
cin >> a[i];
oc[a[i]].push_back(i);
}
int x = 0, y = 0, ans = 0;
for(int i = 0; i <... | 13 |
#include <bits/stdc++.h>
using namespace std;
int mod = 1e9 + 7;
const int N = 2e5 + 5;
long long n, m, sti, stj;
char s[1005][1005];
bool vis[1005][1005][5][5], f;
bool inrange(int i, int j) {
if (i < n && i >= 0 && j < m && j >= 0 && s[i][j] != '*') return true;
return false;
}
void dfs(int i, int j, long long tu... | 8 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.