solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
long long spf[100005];
long long fpow(long long x, long long y) {
x = x % 1000000007;
long long res = 1;
while (y) {
if (y & 1) res = res * x;
res %= 1000000007;
y = y >> 1;
x = x * x;
x %= 1000000007;
}
return res;
}
long long inv(long long a,... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long b, long long md) {
return (!b ? 1
: (b & 1 ? a * power(a * a % md, b / 2, md) % md
: power(a * a % md, b / 2, md) % md));
}
const int xn = 2e5 + 10;
const int xm = -20 + 10;
const int sq = 320;
cons... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
bool ok(char c, char b, char a) {
string res = "";
res += c;
res += b;
res += a;
sort(res.begin(), res.end());
return res == "ABC";
}
string get(string x) {
for (int i = 0; i < x.size(); ++i) {
if (x[i] == '.') x[i] = '1';
}
retu... | 4 |
#include <bits/stdc++.h>
using namespace std;
int dp[2001][2001], sum[2001][2001];
int n, m, ans;
int main() {
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++) {
dp[i][1] = 1;
for (int j = 2; j <= m; j++) {
dp[i][j] = (dp[i][j - 1] + sum[i - 1][j]) % 1000000007;
sum[i][j] = (sum[i][j - 1] + ... | 16 |
#include <bits/stdc++.h>
using namespace std;
long long c, hr, hb, wr, wb, ans;
long long check(long long x) { return x * hr + (c - x * wr) / wb * hb; }
int main() {
cin.sync_with_stdio(false);
cin >> c >> hr >> hb >> wr >> wb;
for (int i = 0; i <= min(c / wr, 100000ll); i++) ans = max(ans, check(i));
swap(hr, ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100;
string s[MAX_N];
int div(int n) {
int ans = 0;
for (int i = 1; i * i <= n; i++) {
if (n % i == 0) ans += 2;
}
int u = sqrt(n);
if (u * u == n) ans--;
return ans;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 55;
const long long INF = 1e18;
long long nn[MAXN], mm[MAXN];
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> nn[i];
for (int i = 0; i < m; i++) cin >> mm[i];
long long ans = INF;
f... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 5;
int n, m;
long long s[MAX];
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) s[i] = s[i - 1] + i;
long long mx = 0, mn = 1e15;
for (int i = 1; i <= n; i++) {
mx = max(mx, s[i - 1] + s[n - i]);
mn = min(mn, s[i - 1] + ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int MX = 1000005;
int n, m, hp[MX], aux[MX], s, res;
vector<int> a;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> hp[i];
aux[i] = hp[i];
s += hp[i];
}
res = (s + n - 1) / n;
for (in... | 23 |
#include <bits/stdc++.h>
using namespace std;
int __i__, __j__;
class _Debug {
public:
template <typename T>
_Debug& operator,(T val) {
cout << val << endl;
return *this;
}
};
int elim[1024];
int main() {
int n, k;
cin >> n >> k;
int i, j, l;
int b = max(k / 2, 1);
for (i = 0; i < (n / b) / 2; ... | 22 |
#include <bits/stdc++.h>
using namespace std;
long long w[100002];
bool c[100002];
long long sum = 0, csum = 0, ans = 0;
int main() {
int n, k, t;
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> w[i], sum += w[i];
for (int i = 0; i < k; i++) {
cin >> t;
c[t] = true;
}
for (int i = 1; i <= n; i++)... | 6 |
#include <bits/stdc++.h>
using namespace std;
void islam() {
ios::sync_with_stdio(false);
cin.tie(NULL);
}
vector<long long> v;
long long n, m, ans = 0;
int main() {
islam();
cin >> n;
while (n--) {
long long a;
cin >> a;
v.push_back(a);
}
for (int i = 0; i < v.size(); i++) {
long long a =... | 5 |
#include <bits/stdc++.h>
using namespace std;
int a[100005], b[100005];
priority_queue<int, vector<int>, greater<int> > q;
vector<int> p[100005], vt[100005];
int main() {
int n, i, j, now, ans, sum = 0, cnt, res = 0, st;
set<int> cd;
cin >> n;
for (i = 1; i <= n; i++) {
scanf("%d%d", &a[i], &b[i]);
p[a[... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long inf = 0x3f3f3f3f3f3f3f3f;
const int N = 1e6 + 10;
const long long mod = 1e9 + 7;
int n, m, t;
char mz[1010][1010];
int dx[]{0, 0, -1, 1};
int dy[]{-1, 1, 0, 0};
int d[1010][1010];
queue<pair<int, int> > q;
int leg(int x, int y) { ... | 12 |
#include <bits/stdc++.h>
long long power(long long a, long long b, long long mod);
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1.0);
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int N = 1e6 + 5;
int testnum = 0;
int n, m;
int a[N], b[N];
int pos[N];
void INIT() {... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long int a[2000000];
using cd = complex<long double>;
vector<cd> A(262144 * 2), B(262144 * 2);
vector<cd> C(262144 * 2);
const double PI = acos(-1);
void fft(vector<cd> &a, bool invert) {
int n = a.size();
for (int i = 1, j = 0; i < n; i++) {
int bit = n >> 1;
... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 50;
char s[maxn];
pair<int, int> seg[maxn];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
int a, b;
cin >> a >> b;
cin >> s;
int len = strlen(s);
int cnt = 0;
long lon... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f3f3f3f3f;
struct _EDGE {
long long u, v;
long long cap, fl;
_EDGE(long long uu, long long vv, long long capp, long long fll) {
u = uu, v = vv, cap = capp, fl = fll;
}
};
struct FLOW {
const long long inf = 0x3f3f3f3f3f3f3f3f;
... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1E9 + 7;
template <class C>
void mini(C& a4, C b4) {
a4 = min(a4, b4);
}
template <class C>
void maxi(C& a4, C b4) {
a4 = max(a4, b4);
}
struct MSS {
pair<int, pair<int, int> > mss, left, right, sum;
MSS(int x, int p) {
sum = pair<int, pair<int, ... | 20 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> A(n);
for (auto &a : A) cin >> a;
vector<int> F(32);
for (auto a : A)
for (int i = 0; i < 32; i++) F[i] += (a >> i) & 1;
int bst{}, ans{};
for (int j = 0; j < n;... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MAX = 2e5 + 5;
const int INF = 1e9 + 10;
int dp[MAX];
string add(int v, string s) {
int i = s.size() - 1;
int carry = v;
while (carry != 0 && i >= 0) {
int d = s[i] - '0';
d += carry;
carry = d / 10;
d %= 10;
s[i]... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
cout << (2 * pow(n, 2)) - (2 * n) + 1 << endl;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
void RI() {}
template <typename... T>
void RI(int& head, T&... tail) {
scanf("%d", &head);
RI(tail...);
}
const int N = 1e5 + 5, MOD = 2147483647, BASE = 1e9 + 7;
char str[N];
long long pw[N], tgv[10][N];
struct Node {
int l, r, tag;
long long val;
Node() {}
Nod... | 17 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9;
int n, m;
long long a[200001], fibo[200001], fibosum0[200001], fibosum1[200001];
struct Segment_Tree {
int left, right, len;
long long s0, s1, lazy;
} tree[200001 << 2];
struct Data {
long long a[2][2];
} bb[200001], one, b;
inline Data oper... | 15 |
#include <bits/stdc++.h>
int calc(int p, int t) { return std::max(3 * p / 10, p - p / 250 * t); }
int main() {
std::ios::sync_with_stdio(false);
int a;
int b;
int c;
int d;
std::cin >> a;
std::cin >> b;
std::cin >> c;
std::cin >> d;
const int mscore = calc(a, c);
const int vscore = calc(b, d);
i... | 1 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
a[i]--;
}
int c[n];
for (int i = 0; ... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 200;
const int INF = 0x3f3f3f3f;
int n, k, a[105], minn = INF, x;
int main() {
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> x;
if (k % x == 0) minn = min(minn, k / x);
}
cout << minn;
return 0;
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void amin(T &x, U y) {
if (y < x) x = y;
}
template <typename T, typename U>
inline void amax(T &x, U y) {
if (x < y) x = y;
}
template <int MOD>
struct ModInt {
static const int Mod = MOD;
unsigned x;
ModInt() : x(0) {}
... | 17 |
#include <bits/stdc++.h>
using namespace std;
void READ(vector<long long> &v, long long n) {
long long a;
for (long long i = 0; i < n; i = i + 1) {
cin >> a;
v.push_back(a);
}
}
void PRINT(vector<long long> &v, long long a = 0) {
for (long long i = a; i < v.size(); i = i + 1) {
cout << v[i] << " ";
... | 8 |
#include <bits/stdc++.h>
const int N = 5000 + 10;
long long a[N];
int n, d[N];
int two[N];
bool ok(int i, int j) {
if (a[i] % a[j] != 0) return false;
if (two[j] == 0) return true;
if (two[j] - two[i] == j - i) return true;
if (two[j] - two[i] < j - i && j - two[j] > i) return true;
if (two[j] - two[i] < j - ... | 16 |
#include <bits/stdc++.h>
using namespace std;
using namespace std;
struct complex {
double r, i;
complex(double _r = 0.0, double _i = 0.0) {
r = _r;
i = _i;
}
complex operator+(const complex &b) { return complex(r + b.r, i + b.i); }
complex operator-(const complex &b) { return complex(r - b.r, i - b.i... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, num[100];
cin >> a >> b >> c;
num[0] = a + b + c;
num[1] = a * (b + c);
num[2] = a * b * c;
num[3] = (a + b) * c;
sort(num, num + 4);
cout << num[3] << endl;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
vector<int> polje[2001];
int n;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
int x;
scanf("%d", &x);
polje[i].push_back(x);
}
}
for (int i = 0; i < n; i++) {
if (polje[i][i] != 0) {
cout << "N... | 11 |
#include <bits/stdc++.h>
using namespace std;
set<int> S;
map<int, int> P;
int n, m, nxt[100005];
int A[100005], data[3005], sum[3005];
unsigned long long ans;
bool check(int a) {
for (; a;) {
if (a % 10 != 4 && a % 10 != 7) return 0;
a /= 10;
}
return 1;
}
void Add(int a, unsigned long long &x) {
S.ins... | 21 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int p[N], du[N], dv[N], ok[N];
int find(int x) { return (p[x] == x) ? x : p[x] = find(p[x]); }
int main() {
int ver, ne;
cin >> ver >> ne;
for (int i = 1; i <= ver; i++) p[i] = i;
int x, y;
for (int i = 0; i < ne; i++) {
cin >> x >> y;
... | 7 |
#include <bits/stdc++.h>
using namespace std;
bool vis[40010];
int N, M, K, num[110], cnt[20], minDis[40010], minN[31][31], dp[1 << 21 + 1],
cnt1[1 << 21 + 1];
queue<int> q;
inline void Dijk(int dir) {
memset(minDis, 0x3f, sizeof(minDis));
minDis[cnt[dir]] = 0;
q.push(cnt[dir]);
while (!q.empty()) {
int... | 20 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void out(T x) {
cout << x << endl;
exit(0);
}
const long long mod = 1e9 + 7;
const int maxn = (1 << 22) + 10;
const int inf = 1e9;
int n, m;
int f[23];
bool clique[maxn];
int dp[maxn];
int nxt[maxn];
int main() {
ios_base::sync_with_stdio(false);... | 16 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
int main() {
ios::sync_with_stdio(false);
cout.precision(10);
int n, m;
cin >> n >> m;
vector<set<int>> G(n);
vector<bool> B(n, true);
for (int i = 0; i < m; ++i) {
int a, b;
cin >> a >> b;
a--;
b--... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const double EPS = 1e-8;
const double PI = acos(-1);
long long n, m;
char a[1000001];
char b[1000001];
int chainID[1000001];
int numInChain[1000001][26];
int main() {
while (cin >> n >> m) {
scanf("%s%s", a, b);
int A = strlen(a);
int ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int l = s.size();
cout << (26 * (l + 1)) - l << endl;
return 0;
}
| 1 |
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int maxn = 2e6 + 10;
const ll mod = 1e9 + 7;
ll a[maxn];
int main()
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
ll sum = 0;
ll mx = -1;
for(int i = 1; i <= n; i++)
{
ci... | 6 |
#include <bits/stdc++.h>
int main() {
int t, check;
long long n, k;
scanf("%d", &t);
for (int i = 0; i < t; i++) {
scanf("%lld%lld", &n, &k);
check = 0;
for (int j = 1; j <= n; j++) {
if (check == 0) {
if (k <= (n - j) * (n - j - 1) / 2ll) {
printf("a");
} else {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
double PI = 3.1415926535897932384626433832795;
vector<pair<int, int> > v;
vector<int> ans1, ans2;
int main() {
int n, mx = 0;
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
pair<int, int> p;
scanf("%d", &p.first);
p.second = i + 1;
v.push_back(p);
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, l, c = 0, m;
bool t[100005] = {0};
int a[100005];
cin >> n >> l;
int ara[n];
for (int i = 0; i < n; i++) {
cin >> ara[i];
}
for (int i = n - 1; i >= 0; i--) {
if (t[ara[i]] == 0) {
c++;
t[ara[i]] = 1;
}
a[i] = ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int a[5];
int n, u;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &u);
a[u]++;
}
long long ans = 0;
int mn = min(a[1], a[2]);
ans += mn;
a[1] -= mn;
a[2] -= mn;
a[3] += mn;
if (a[1] != 0) {
a[3] += (a[1] / 3);
a... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long n, k, ans = INT64_MAX;
long long v[10];
char s[9][9];
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.precision(10), cout << fixed;
scanf("%d%d", &n, &k);
for (int i = 0; i < n; ++i) scanf("%s", &s[i]);
for (int i = 0; i < k; ++i) v[i] = i;
d... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void print_vector(vector<T> x) {
for (int i = 0; i < x.size(); ++i) {
cout << x[i] << " ";
}
cout << endl;
}
template <typename T>
void print_array(T array[], int n) {
for (int i = 0; i < n; ++i) {
cout << array[i] << " ";
}
cout <<... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000100;
long long dp[MAXN][2], n, a[MAXN];
long long f(int idx, int formIncreasing) {
if (idx >= n - 1) {
return 0;
}
if (dp[idx][formIncreasing] != -1) {
return dp[idx][formIncreasing];
}
long long ans = 0;
if (formIncreasing) {
if... | 16 |
#include <bits/stdc++.h>
using namespace std;
int mask(int n) {
int ans = 0;
int t = 1;
while (n != 0) {
int d = n % 10;
if (d == 4 || d == 7) {
ans += d * t;
t *= 10;
}
n /= 10;
}
return ans;
}
int main() {
int a, b;
cin >> a >> b;
for (int i = a + 1;; i++) {
if (mask(i)... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigmod(T p, T e, T M) {
long long int ret = 1;
for (; e > 0; e >>= 1) {
if (e & 1) ret = (ret * p) % M;
p = (p * p) % M;
}
return (T)ret;
}
template <class T>
inline T gcd(T a, T b) {
if (b == 0) return a;
return gcd(b, a % b)... | 13 |
#include <bits/stdc++.h>
using namespace std;
string s;
int n;
bool f(int a) {
if ((s[a] == 'A' && s[n - a - 1] == 'A') ||
(s[a] == 'H' && s[n - a - 1] == 'H') ||
(s[a] == 'I' && s[n - a - 1] == 'I') ||
(s[a] == 'M' && s[n - a - 1] == 'M') ||
(s[a] == 'O' && s[n - a - 1] == 'O') ||
(s[a]... | 8 |
#include <bits/stdc++.h>
using namespace std;
int cnt[1000010];
long long int get(long long int N, long long int S) {
long long int lm = 0, l = 0;
for (int i = 0; i < N; i++) cnt[i] = -1;
for (int i = 0; i < N; i++) {
if (cnt[i] == -1) {
long long int t = 0;
for (int j = i; j < N; j += S) {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int sa[100001], ba[100001];
int n, s;
int main() {
scanf("%d %d", &n, &s);
for (int i = 0; i < n; i++) {
char c;
int p, q;
scanf("%c", &c);
scanf("%c %d %d", &c, &p, &q);
if (c == 'B')
ba[p] += q;
else
sa[p] += q;
}
int pos = 0;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, row[104], col[105];
string s[N];
vector<pair<int, int> > ans;
bool check(int *arr) {
for (int i = 0; i < n; i++)
if (arr[i] == 0) return false;
return true;
}
int main() {
cin >> n;
for (int i = 0; i < n; i++) cin >> s[i];
for (i... | 7 |
#include <bits/stdc++.h>
int main() {
int n, s = 0;
scanf("%i", &n);
for (int i = 0; i < n; ++i) {
int x;
scanf("%i", &x);
s += x * (i + 1);
}
printf("%i\n", s);
}
| 12 |
#include <bits/stdc++.h>
using namespace std;
long long cnt = 0;
bool mark[33][33][222];
long double dp[33][33][222];
pair<long long, long long> a[10000];
long long p[1111];
pair<long long, long long> fun(long long fi, long long se, long long l,
long long r) {
pair<long long, long long>... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long int mod = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int p[2 * n + 1];
int i;
vector<int> ind;
int maxi = 0;
for (i = 1; i <= 2 * n; i++) {
cin ... | 10 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int my_rand(int l, int r) { return uniform_int_distribution<int>(l, r)(rng); }
int Set(int N, int pos) { return N = N | (1 << pos); }
int reset(int N, int pos) { return N = N & ~(1 << pos); }
bool check(in... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)(1e5) + 100;
const int INF = (1 << 30);
const double PI = acos(-1.0);
const double EPS = (1e-6);
int main() {
int n, A = 0, G = 0;
string second = "";
cin >> n;
for (int i = 1; i <= n; i++) {
int a, g;
cin >> a >> g;
if (abs(a + A -... | 7 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
inline long long getint() {
long long _x = 0, _tmp = 1;
char _tc = getchar();
while ((_tc < '0' || _tc > '9') && _tc != '-') _tc = getchar();
if (_tc == '-') _tc = getchar(), _tmp = -1;
while (_tc >= '0' && _tc <= '9') _x *= 10, _x += (_... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 8005;
vector<int> g[maxn];
vector<int> rev[maxn];
stack<int> st;
int n, m, scc, idx;
int low[maxn], dfn[maxn], instack[maxn], fa[maxn];
int ans[maxn];
int in[maxn];
int opp[maxn], c[maxn];
int nd[maxn];
void tarjan(int now) {
dfn[... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, y;
while (scanf("%d%d", &x, &y) == 2) {
int n = 0;
bool ciel = true;
while (1) {
n++;
if (n % 2) {
if (x >= 2 && y >= 2) {
x -= 2;
y -= 2;
} else if (x >= 1 && y >= 12) {
x -= 1;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b, ab;
scanf("%lld%lld%lld", &a, &b, &ab);
long long q1 = 0;
if (a + b) q1 = 1;
long long qab = 2 * ab + 2 * min(a, b);
if (a > b) qab++;
long long qba = 0;
if (b) {
b--;
qba = 1 + 2 * ab;
qba += 2 * min(a, b);
if (a... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n, avail;
int L[500011], R[500011];
vector<int> adj[500011];
void solve(int v, int p) {
int deg = (int)adj[v].size();
if (p != v) deg--;
R[v] = avail + deg;
avail = R[v];
int cnt = 1;
for (int u : adj[v]) {
if (u == p) continue;
avail++;
L[u] = R... | 14 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int maxn = 200010;
const double eps = 1e-10;
const int inf = 0x3f3f3f3f;
double add(double a, double b) {
if (abs(a + b) < eps * (abs(a) + abs(b))) return 0;
return a + b;
}
struct P {
double x, y;
int id;
... | 18 |
#include <bits/stdc++.h>
using namespace std;
int mt[111][111];
int rowsum[111];
int colsum[111];
bool flipRow[111];
bool flipCol[111];
int main(void) {
int n = 0;
int m = 0;
scanf("%d %d", &n, &m);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
scanf("%d", &mt[i][j]);
rowsum[i] += ... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, x, y, maxi = 0;
long long arr[1000], arr1[1000];
cin >> n;
for (int i = 0; i < n; i++) cin >> arr[i];
for (int i = 0; i < n; i++) cin >> arr1[i];
for (int i = 0; i < n; i++) {
x = arr[i];
y = arr1[i];
for (int j = i + 1; j <... | 1 |
#include <bits/stdc++.h>
std::vector<int> vec[100010];
int r[100010];
int cnt[100010];
bool del[100010], inQueue[100010];
bool judge(int x) {
std::vector<int> t;
for (int i : vec[x])
if (!del[i]) t.push_back(i);
for (int i : t)
if (i != x) {
for (int j : t) {
if (i == j) break;
if (!... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int count25 = 0, count50 = 0, count100 = 0;
for (int i = 0; i < n; i++) {
int num;
cin >> num;
if (num == 25)
count25++;
else if (num == 50)
if (count25 > 0) {
count25--;
count50++;
} el... | 3 |
#include <bits/stdc++.h>
using namespace std;
bool check(int year) {
if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) return true;
return false;
}
void solve() {
int x;
scanf("%d", &x);
int day = 0;
bool flag = check(x);
do {
if (check(x))
day += 366;
else
day += 365;
day... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
long long n, m;
cin >> n >> m;
long long o1 = 0, e1 = 0;
long long o2 = 0, e2 = 0;
for (int i = 0; i < n; ++i) {
long long x;
cin >> x;
if (x % 2 == 0)
e1++;
else
o1++;
}
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
void boost() {
ios_base ::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
const int maxN = 3e5;
long long t, a[maxN], sum;
int main() {
long long n, l = 0, mn = INF;
cin >> n >> t;
for (int i = 1; i <= n; i++) {
cin >> a[i];
... | 9 |
#include <bits/stdc++.h>
std::string to_lower(const std::string& login) {
std::string temp;
for (size_t i = 0; i < login.size(); ++i) {
temp += tolower(login[i]);
}
return temp;
}
int main() {
std::string login;
std::cin >> login;
login = to_lower(login);
int n;
std::cin >> n;
std::vector<std::s... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void read(T &x) {
char c;
bool op = 0;
while (c = getchar(), c < '0' || c > '9')
if (c == '-') op = 1;
x = c - '0';
while (c = getchar(), c >= '0' && c <= '9') x = x * 10 + c - '0';
if (op) x = -x;
}
template <class T>
void write(T x) {
... | 20 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void maxtt(T& t1, T t2) {
t1 = max(t1, t2);
}
template <typename T>
void mintt(T& t1, T t2) {
t1 = min(t1, t2);
}
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "URDL";
long long ln, lk, lm;
void etp(b... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3000 + 10, inf = 1e9 + 1;
struct MCMF {
struct Edge {
int to, rev, cap, w;
Edge() {}
Edge(int a, int b, int c, int d) : to(a), cap(b), w(c), rev(d) {}
};
int n, s, t;
vector<int> p, id, d;
bitset<maxn> inque;
vector<Edge> G[maxn];
... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int a;
cin >> a;
vector<int> b(6);
for (int i = 0; i < 6; i++) {
b[i] = (a >> i) & 1;
}
vector<int> c(6);
c[4] = b[0];
c[1] = b[1];
c[3] = b[2];
c[2] = b[3];
... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long inf = 1e18;
long long n, k;
string s;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> k;
cin >> s;
long long ans = inf;
if (k > n) {
cout << -1;
return 0;
}
long long mn = inf;
sort(s.begin(), s.end... | 1 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAXN = 1e5 + 4;
pair<int, int> a[MAXN];
ll sum[MAXN];
int n, c_f, c_m, max_a;
ll m;
bool cmp(const pair<int, int> &A, const pair<int, int> &B) {
return A.second < B.second;
}
int main() {
cin >> n >> max_a >> c_f >> c_m >> m;
for (int i... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, a, d;
cin >> n >> a >> d;
long long int t[n], v[n];
pair<long long int, long long int> tv[n];
for (int i = 0; i < n; i++) {
cin >> t[i] >> v[i];
tv[i] = {t[i], i};
}
sort(tv, tv + n);
cout << setprecision(15);
double t... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MX = 1e5 + 100;
long long n, m, k, l, r, x, start[MX], a1[MX], a2[MX], dp[MX];
string s;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 0; i < MX; i++) dp[i] = 1e9, start[i] = 1;
for (int j = 1; j <=... | 8 |
#include <bits/stdc++.h>
const double PI = 3.141592653589793238463;
using namespace std;
inline long long add(long long a, long long b) {
a += b;
if (a >= 1000000007) a -= 1000000007;
return a;
}
inline long long sub(long long a, long long b) {
a -= b;
if (a < 0) a += 1000000007;
return a;
}
inline long lon... | 14 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9 + 7;
int cost[7][7], a[7], b[7];
int n, m, dp[16000][5], tdp[16000][5], p5[7];
void chmin(int &x, int y) {
x = min(x, y);
}
string rep(int x) {
string res;
while(x) {
res += (char)('0' + (x % 5));
x /=... | 24 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000 * 1000 * 1000 + 7;
const long long LINF = INF * (long long)INF;
const double PI = 3.14159265358979323846264338327;
struct circle {
double x, y, r;
double getSquare() { return PI * r * r; }
};
const int SIZE = 1000 + 47;
vector<int> g[SIZE];
circle a... | 12 |
#include <bits/stdc++.h>
using namespace std;
unordered_map<string, int> Id;
int GetId(string &name) {
static int tot = 0;
if (!Id.count(name)) {
Id[name] = ++tot;
return tot;
}
return Id[name];
}
vector<string> entry[30];
bool IsSuffix(string &a, string &b) {
int na = a.length(), nb = b.length();
i... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e2 + 7;
double dp[2][N][N];
double prei[N], prej[N], prek[N];
int data[N];
double c2(int n) { return (n * (n - 1)) >> 1; }
int main() {
int n, m;
scanf("%d%d", &n, &m);
m = min(m, 900);
for (int i = (1); i < (n + 1); ++i) scanf("%d", &data[i]);
for ... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const long long MXLL = 4e18;
const int Sz = 1110111;
inline void Read_rap() {
ios_base ::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
inline void randomizer3000() {
unsigned int seed;
asm("rdtsc" : "=A"(se... | 7 |
#include <bits/stdc++.h>
using namespace std;
pair<long long, int> m[400000];
vector<int> co;
long long kr[400000], su[400000];
int n, x, y, yb, xb;
long long k;
int main() {
k = -9000000000;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> kr[i];
m[i].first = kr[i];
m[i].second = i;
}
if (kr[0] > 0... | 6 |
#include <bits/stdc++.h>
using namespace std;
int isprime(int n) {
bool prime = true;
for (int i = 2; i <= n / 2; i++) {
if (n % i == 0) {
prime = false;
}
}
if (prime)
return 0;
else
return 1;
}
int main() {
int n;
cin >> n;
int x = 4;
int y = n - x;
while (1) {
int i = is... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 10010;
int main() {
string s;
int n, i, j, k;
cin >> n >> s;
string ss = s;
for (i = 0; i < n; i++) {
int cha = s[0] - '0';
for (j = 0; j < n; j++) {
s[j] = (s[j] - '0' + 10 - cha) % 10 + '0';
}
if (s... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long i, j, z, state = 0;
char s[1000000];
gets(s);
long size;
size = strlen(s);
for (i = 0; i < size; i++) {
if (s[i] == 'a' && state == 0)
;
if (s[i] == 'a' && state != 0) break;
if (s[i] != 'a') s[i] -= 1, state++;
}
if (stat... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MX = 1000005;
int s;
vector<int> Mod_num[MX];
int main() {
int n, k, m;
scanf("%d%d%d", &n, &k, &m);
for (int i = 1; i <= n; i++) {
int a;
scanf("%d", &a);
Mod_num[a % m].push_back(a);
}
for (int i = 0; i < MX; i++)
if ((int)Mod_num[i].si... | 5 |
#include <bits/stdc++.h>
using namespace std;
int a[100100];
long long b[100100];
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
int n;
scanf("%d", &n);
for (int i = (0); i < (n); ++i) scanf("%d", &a[i]);
sort(a, a + n);
b[0] = 0;
for (int i = (0); i... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 7;
const long long Mod = 1e9 + 7;
long long n, m;
map<long long, long long> l, r;
long long cnt1 = 0, cnt2 = 0;
long long a[N], b[N];
long long sz[N] = {};
long long fa[N] = {};
long long bi[N] = {};
inline long long Mul(long long x, long long y) {... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
int a;
int val, valmax = 0;
int index;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a;
if (a % m == 0)
val = a / m;
else
val = a / m + 1;
if (val >= valmax) {
index = i;
valmax = val;
}
... | 2 |
#include <bits/stdc++.h>
using namespace std;
char string_in_buffer[(int)2e6];
void fast_scan(int &first) { scanf("%d", &first); }
void fast_scan(long long &first) { scanf("%lld", &first); }
void fast_scan(unsigned long long &first) { scanf("%llu", &first); }
void fast_scan(double &first) { scanf("%lf", &first); }
void... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, temp = 0, j;
cin >> n;
int a[n];
for (i = 0; i < n; i++) cin >> a[i];
string str;
for (i = 0, j = n - 1; i <= j;) {
if (i == j & a[i] > temp) {
str += 'L';
i++;
} else if (a[i] < a[j] && a[i] > temp) {
temp = a[i]... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int Nmax = 3e5 + 112;
int q, n, f[Nmax], pa[Nmax], ans;
vector<int> a[Nmax], kq[Nmax];
void dp(int u, int p) {
pa[u] = p;
int tmp = a[u].size();
if (u != p) tmp -= 1;
for (int v : a[u]) {
if (v == p) continue;
dp(v, u);
f[u] = max(f[u], f[v] + (tmp... | 14 |
#include <bits/stdc++.h>
using namespace std;
void solve(long long n, long long k, vector<long long>& arr) {
set<long long> s;
int i;
for (i = 0; i < n; i++) s.insert(arr[i]);
if (s.size() > k) {
cout << "-1\n";
return;
}
vector<int> ans;
for (auto it = s.begin(); it != s.end(); it++) {
ans.pu... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 50;
int num[maxn];
map<pair<int, int>, int> mat;
int a[maxn];
int main() {
int n, p;
scanf("%d%d", &n, &p);
memset(num, 0, sizeof(num));
mat.clear();
for (int i = 0; i < n; i++) {
int x, y;
scanf("%d%d", &x, &y);
if (x > y) swap(... | 11 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.