solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int f[1050][1050], n, m, K, link[15][15];
int get() {
int f = 0, v = 0;
char ch;
while (!isdigit(ch = getchar()))
if (ch == '-') break;
if (ch == '-')
f = 1;
else
v = ch - 48;
while (isdigit(ch = getchar())) v = v * 10 + ch - 48;
if (f == 1) return... | 17 |
#include <bits/stdc++.h>
using namespace std;
inline void readUI(int *i) {
register int t = 0;
register char z = getchar();
while (z < '0' || '9' < z) {
z = getchar();
}
while ('0' <= z && z <= '9') {
t = (t << 1) + (t << 3) + z - '0';
z = getchar();
}
*i = t;
}
inline void writeL(long long in... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, m;
cin >> n >> k >> m;
int A[n];
for (int i = 0; i < n; i++) cin >> A[i];
int freq[m];
memset(freq, 0, sizeof freq);
for (int i = 0; i < n; i++) freq[A[i] % m]++;
int isPossible = 0, j;
for (int i = 0; i < m; i++)
if (freq[i] >= ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)53;
const int MOD = (int)1e9 + 7;
const int infint = (int)1e9;
const long double eps = (long double)1e-3;
const long long inf = (long long)1e15;
int n;
long long a[MAXN], b[MAXN], id;
long double dp[MAXN][MAXN];
set<long long> S;
unordered_map<long lon... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int limit = 1005;
int n;
int p[limit];
int seen[limit];
int nsol;
string sol[limit];
void generate(int u, vector<int> &lista) {
if (seen[u]) return;
seen[u] = 1;
lista.push_back(u);
generate(p[u], lista);
}
int main() {
ios::sync_with_stdio(false);
cin >> ... | 22 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, r, f = 0;
cin >> n >> r;
long long m = min(n, r);
if (m == n) {
m--;
f++;
}
cout << (m * (m + 1) / 2) + f << endl;
}
int main() {
int t = 1;
cin >> t;
while (t--) solve();
return 0;
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T read(T &x, T f = 0) {
char c = getchar();
x = 0;
while (c < '0' || c > '9') {
if (c == '-') f = 1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0', c = getchar();
}
return x = f ? -x : x;
}
const int maxn =... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 999999067;
int a[200007][3];
int main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i][0] >> a[i][1];
}
if (n == 3) {
cout << 1 << " " << 2 << " " << 3;
return 0;
}
cout << 1 << " ";
n... | 8 |
#include <bits/stdc++.h>
using namespace std;
const double PI = 2 * acos(0.0);
const int Mod = 1E9 + 7;
inline void yes() { std::cout << "Yes\n"; }
inline void no() { std::cout << "No\n"; }
using namespace std;
long long int isPrime(long long int num) {
long long int flag = 0;
for (long long int i = 1; i <= num; i+... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 70005;
int n;
string s[N];
map<string, int> gl, lc[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> s[i];
for (int j = 0; j < 9; j++) {
string cur = "";
for (int k ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 100007;
struct eT {
void setd(int _u, int _v, int _l) { u = _u, v = _v, last = _l; }
int u, v, last;
} edge[M... | 19 |
#include <bits/stdc++.h>
using namespace std;
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
const int INF = 1 << 29;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n >> b) & 1; }
inline void set_bit(int& n, int b) { n |= two(b); }
inline void unset_bit(int& n, int b... | 7 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const unsigned long long prime = 999983;
const int INF = 0x3f3f3f3f;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-9;
const long long mod = 1e9 + 7;
const unsigned long long mxx = 1333331;
... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long g, f, d, t, y, flag, n;
int main() {
cin >> f;
while (f--) {
cin >> d;
if (d == 2)
cout << 2 << endl;
else {
if (d % 2 == 0)
cout << 0 << endl;
else
cout << 1 << endl;
}
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, count = 0, flag = 0;
cin >> n >> x;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
for (int i = 0; a[i] <= x && i < n; i++) {
count++;
if (a[i] == x) flag = 1;
}
if (flag == 0)
cout << x - coun... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, x, aux, halp = 1;
map<long long, long long> gud;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> x;
while (n > 0 && m > 0) {
if ((n * m) % 2 == 0) {
aux = (n * m) / 2;
} else
aux = ((n * m) / 2) + 1;
gu... | 8 |
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<sstream>
#include<algorithm>
#include<bitset>
#include<stack>
#include<map>
#include<set>
#include<ctime>
#include<cstdlib>
#define rep(i,n) for(int i=0;(i)<(n);i++)
#define rep1(i,n) for(int... | 15 |
#include <bits/stdc++.h>
using namespace std;
int n, m, counts[20];
string in[20], lhs, rhs, temp;
map<string, int> hs;
vector<int> ps[20];
int main() {
int i, j;
cin >> n >> m;
for ((i) = 0; (i) < (int)n; (i)++) {
cin >> in[i];
hs.insert(make_pair(in[i], i));
}
for ((i) = 0; (i) < (int)m; (i)++) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int M = 18, N = (1 << (M - 1)), mod = 998244353;
int qpow(int x, int y = mod - 2) {
int res = 1;
for (; y; x = (long long)x * x % mod, y >>= 1)
if (y & 1) res = (long long)res * x % mod;
return res;
}
int n, k, c, fac[N], ifac[N], inv[N], all;
void init(int ... | 24 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
printf("%d\n", n * 3 / 2);
for (int i = 2; i <= n; i += 2) {
if (i == 2) {
printf("%d", i);
} else {
printf(" %d", i);
}
}
for (int i = 1; i <= n; i += 2) {
printf(" %d", i);
}
for (int i = 2; ... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
const int N = 2e5 + 10;
int flag[N];
int main() {
int n;
string str;
cin >> n >> str;
int cnt1 = 0, cnt2 = 0;
for (auto &c : str)
if (c == 'D')
cnt1++;
else
cnt2++;
int cnt = 0;
int p = 0;
while (1) {
if... | 7 |
#include <bits/stdc++.h>
int pow1(int k) {
int s = 1;
while (k--) s *= 10;
return s;
}
int main() {
int n, m;
int i;
int count = 0;
int a[15] = {0};
scanf("%d%d", &n, &m);
while (m > 0) {
a[count++] = m % 10;
m /= 10;
}
int tmp = 0;
for (i = 0; i < count; i++) tmp += a[i] * pow1(count - ... | 4 |
#include <bits/stdc++.h>
unsigned max(unsigned a, unsigned b) { return a > b ? a : b; }
char A[1111], B[1111];
unsigned D[11][1111][1111], M[11][1111][1111];
int main() {
unsigned x, y, z, i, j, k, a, b;
scanf("%u%u%u%s%s", &x, &y, &z, A + 1, B + 1);
for (k = 0; k++ < z;)
for (i = 0; i++ < x;)
for (j = ... | 11 |
#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
if (n == 0)
cout << "0 1\n0 " << m << "\n0 0\n0 " << m - 1 << '\n';
else if (m == 0)
cout << "1 0\n" << n << " 0\n0 0\n" << n - 1 << " 0\n";
else if (n >= m) {
if (n + sqrt(n * n + m * m) >= 2 * sqrt(n * n + (m - 1... | 10 |
#include <bits/stdc++.h>
using namespace std;
vector<int> L[100005], W[100005];
bool vis[100005];
long long comp;
bool isLucky(int n) {
while (n > 0) {
if (n % 10 != 4 && n % 10 != 7) return false;
n /= 10;
}
return true;
}
void DFS(int node) {
if (vis[node]) return;
vis[node] = true;
comp++;
for ... | 11 |
#include <bits/stdc++.h>
using namespace std;
char buf[1024];
int n;
int main() {
gets(buf);
sscanf(buf, "%d", &n);
int last = 0, ans = 1, cnt = 0;
for (int i = 0; i < n; ++i) {
gets(buf);
int h = (buf[1] - '0') * 10 + (buf[2] - '0');
int m = (buf[4] - '0') * 10 + (buf[5] - '0');
int t = (buf[7]... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long binarySearch(int arr[], long long l, long long r, long long x) {
if (r > l) {
long long mid = l + (r - l) / 2;
if (arr[mid] >= x)
return binarySearch(arr, l, mid, x);
else
return binarySearch(arr, mid + 1, r, x);
} else {
return r;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int h, w, temp, ans = 0;
cin >> h >> w;
while (h != w && h > 0 && w > 0) {
if (h > w) {
temp = h;
h = w;
w = temp;
}
ans += (w / h);
w = (w % h);
}
cout << ans << endl;
return 0;
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
int Query(int i, int j) {
printf("? %d %d\n", i, j);
fflush(stdout);
int k;
scanf("%d", &k);
return k;
}
const int maxn = 10000;
int n, p[maxn], b[maxn];
int ans[maxn][2];
int cnt, tmp[maxn], inv[maxn];
int out[maxn];
int cnttmp[maxn], cntinv[maxn];
int main(void)... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5100;
char sz[maxn];
int len;
int dpl[maxn][maxn], dpr[maxn][maxn];
int main() {
scanf("%s", sz + 1);
len = strlen(sz + 1);
memset(dpl, -1, sizeof(dpl));
memset(dpr, -1, sizeof(dpr));
for (int i = 1; i <= len; i++) {
int s1 = 0, s2 = 0;
fo... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int c = 0;
while (n != 0) {
++c;
n--;
if (c % m == 0) n++;
}
cout << c;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
char s[200050];
int l, n, tot, uf[200050], cnt, rd[9];
bool ff[200050], f[9];
bool check(int i) {
int r = 0;
while (i) r += i % 10, i /= 10;
return r < 10;
}
void out() {
stack<int> sta;
int r = 0, j = 0, k = 1, _n = n;
for (int t = 0; t < 8; ++t) {
j = j + ... | 17 |
#include <bits/stdc++.h>
using namespace std;
int n, m, t, num = 0, maxsize = 0;
vector<int> open, ans;
int main() {
ios_base::sync_with_stdio(false), cin.tie(nullptr);
cin >> n >> m >> t;
ans.resize(n);
int time, prevtime = 0;
for (int z = 0; z < n; z++) {
string s;
cin >> s;
time = 0;
time +... | 13 |
#include <bits/stdc++.h>
using namespace std;
int l, p, q;
int main() {
scanf("%d%d%d", &l, &p, &q);
double a = 1.0 * l * p / (0.0 + p + q);
double aa = 2.0 * l * p / (0.0 + p + q);
printf("%.5lf", aa - a);
}
| 1 |
#include <bits/stdc++.h>
using namespace std;
template <class Read>
void in(Read &x) {
x = 0;
int f = 0;
char ch = getchar();
while (ch < '0' || ch > '9') {
f |= (ch == '-');
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
x = f ?... | 8 |
#include <bits/stdc++.h>
int i, j, k, l, m, n, a[1000000];
int main() {
int top;
scanf("%d", &n);
a[0] = -1;
top = 0;
for (i = 0; i < n; i++) {
scanf("%d", &m);
if (m > a[top])
a[++top] = m;
else {
int high = top, low = 1, mid;
while (low <= high) {
mid = (high + low) / 2... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int v[30005];
int f[30005];
int fl1, fl2, f2, f1;
int p1, p2, r1, r2;
int i, j;
int sol = 0, nex, flag = 0, first = 0, paux, r2aux;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &v[i]);
}
if (n == 2) {
printf("%d\n%... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int64_t q;
cin >> q;
for (int i = 0; i < q; ++i) {
int64_t k, n, a, b;
cin >> k >> n >> a >> b;
int64_t ans = 0;
if (min(a, b) * n >= k) {
cout << -1 << endl;
continue;
} else {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int const N = 1e5 + 2, MOD = 1e9 + 7;
long long fast_power(long long base, long long pw) {
long long res = 1;
while (pw > 0) {
if (pw & 1) res = (res * base);
base = base * base;
pw >>= 1;
}
return res;
}
int main() {
ios::sync_with_stdio(0);
cin.tie... | 5 |
#include <bits/stdc++.h>
using namespace std;
int t, n;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
;
cin >> t;
while (t--) {
cin >> n;
while (n--) {
cout << 100 << " ";
}
cout << "\n";
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int c[65][65][65];
int d[65][65][65];
int inf = 1 << 30;
int main() {
int n, m, r;
cin >> n >> m >> r;
for (int k = 0, _e(m); k < _e; k++)
for (int i = 0, _e(n); i < _e; i++)
for (int j = 0, _e(n); j < _e; j++) cin >> c[k][i][j];
for (int l = 0, _e(m); l <... | 10 |
#include <bits/stdc++.h>
int main() {
std::ios::sync_with_stdio(false);
int N, K;
std::cin >> N >> K;
std::map<int, int> sums;
sums[0] = 0;
for (auto i = 0; i < N; ++i) {
int a;
std::cin >> a;
auto sum = 0;
for (auto j = 1; j <= K; ++j) {
sum += a;
if (!sums.count(sum))
s... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string r;
cin >> r;
set<char> x1 = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
set<char> x;
int uk = 0;
if (r.size() < 26) co... | 5 |
#include <bits/stdc++.h>
using namespace std;
int a[1000020], b[1000020];
int la, lb, i, head, tail, x, ans = 0, ii;
int l1, l2, r1, r2;
int que[2000010];
bool check(int x) {
if (l1 == -1) {
l1 = r1 = x;
return true;
}
if (l2 == -1) {
if (r1 < x) {
r1 = x;
return true;
}
if (x < l1... | 12 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, ans = 1;
cin >> n >> a;
vector<int> X;
vector<int> O;
for (; n > 0; --n) {
if (n % 2 == 0)
X.push_back(n);
else
O.push_back(n);
}
reverse(O.begin(), O.end());
if (a % 2 == 0) {
for (int i = 0; i < X.size(); ++i)... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2010;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
char web[100010];
int n, m, sum1, sum2, k;
long long dp[maxn][maxn];
void init() {
dp[0][0] = 1LL;
for (int i = 1; i < maxn; ++i) {
for (int j = 0; j <= i; ++j) {
if (j == 0)
d... | 12 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const double PI = acos(-1.0);
bool ans[55][55];
int main() {
int n;
cin >> n;
bool a;
ans[1][1] = 1;
ans[n][n] = 0;
for (int i = 3; i <= n; i += 2) {
cout << "? " << i - 2 << " " << 1 << " " << i << " " << 1 << endl;
cin >> a;... | 16 |
#include <bits/stdc++.h>
using namespace std;
long long d[111111], s[111111];
queue<long long> q;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long n, i, u, x = 0;
cin >> n;
for (i = 0; i < n; i++) {
cin >> d[i] >> s[i];
x += d[i];
if (d[i] == 1) q.push(i);
}
... | 7 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const long long maxb = 30;
struct custom_hash {
static uint64_t splitmix64(uint64_t first) {
first += 0x9e3779b97f4a7c15;
first = (first ^ (first >> 30)) * 0xbf58476d1ce4e5b9;
first = (first ... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, target;
double getAngle(int x, int y) {
int d = y - x;
return 180. * d / n;
}
void solve(int i, int& j, double& diff) {
int l = i;
int r = n;
while (l + 1 != r) {
int m = (l + r) / 2;
if (getAngle(i, m) <= target) {
l = m;
} else {
r... | 5 |
#include <bits/stdc++.h>
using namespace std;
int _I() {
int x;
scanf("%d", &x);
return x;
}
long long _L() {
long long x;
scanf("%lld", &x);
return x;
}
long long gcd(long long x, long long y) {
if (x % y == 0)
return y;
else
return gcd(y, x % y);
}
long long lcm(long long x, long long y) {
x... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
char x, y;
int kq = 0;
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
cin >> x >> y;
if (x == '1' || y == '1') kq++;
}
printf("%d", kq);
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int n, m;
char c;
cin >> n >> m >> c;
char dp[n + 1][m + 1];
for (long long int i = 1; i <= n; i++) {
for (long long int j = 1; j <= m; j++) {
cin >> dp[i][j];
}
}
set<ch... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
struct node {
int l, r, pos;
bool operator<(const node &t) const { return l < t.l; }
} a[300006];
priority_queue<int, vector<int>, greater<int> > p;
int L, R, ans;
int n, k;
int main() {
scanf("%d%d", &n, &k);
for (int i = 1; i <= n... | 13 |
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
template <class T>
int size(T &&x) {
return int(x.size());
}
template <class A, class B>
ostream &operator<<(ostream &out, const pair<A, B> &p) {
return out << '(' << p.first << ", " << p.second << ')';
}
template <class T>
auto operator<<(ostream ... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, mx, cnt = 1, ch = 1;
cin >> n;
int a[n];
if (n == 1) {
cout << 0;
return 0;
}
vector<int> b(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
b[i] = a[i];
}
mx = b[0];
sort(b.begin(), b.end());
for (int i = 1; i < n; i+... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n = 5, p[6] = {0, 1, 2, 3, 4, 5}, g[6][6];
long long ans;
void find();
int main() {
ios_base::sync_with_stdio(0);
for (int i = (int)(1); i < (int)(n + 1); ++i)
for (int j = (int)(1); j < (int)(n + 1); ++j) cin >> g[i][j];
do {
find();
} while (next_permu... | 4 |
#include <bits/stdc++.h>
using namespace std;
int check(int n) {
int ct = 0;
while (n) {
n /= 5;
ct += n;
}
return ct;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int m;
cin >> m;
vector<int> a;
int i = 1, cnt = 0;
while (i > 0) {
if (check(i) == m) {
cnt++;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool chkmax(T &x, T y) {
return x < y ? x = y, true : false;
}
template <typename T>
bool chkmin(T &x, T y) {
return x > y ? x = y, true : false;
}
const double PI = 3.14159265358979323846;
const double eps = 1e-10;
int n, m, a[55];
double f[55][55... | 14 |
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
struct custom_hash {
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM =
chrono::steady_clock::now().time_since_epoch().count();
x ^= FIXED_RANDOM;
return x ^ (x >> 16);
}
};
void solve() {
int n,... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2505;
int n, m, nd, S[N];
int dep[N], fa[N * 2];
vector<int> e[N], E[N * 2];
int f[N][N][3];
int tmp[N][3], sz[N];
void UPD(int &x, int y) { x < y ? x = y : 233; }
void dfs(int x) {
dep[x] = dep[fa[x]] + 1;
for (auto i : e[x])
if (!dep[i]) {
fa[i... | 23 |
#include <bits/stdc++.h>
using namespace std;
long long ans, kq, n;
string s;
int dem;
int main() {
cin >> n;
while (n > 0) {
n--;
cin >> s;
ans = 0;
dem = 0;
for (int j = 0; j <= s.size() - 1; j++) {
if (s[j] == '0')
dem++;
else {
kq = 0;
for (int i = j; i <=... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 500000;
mt19937 Rand(time(0));
int mod[3];
struct hasher {
int a[3];
hasher(int x = 0) { a[0] = a[1] = a[2] = x; }
friend hasher operator+(const hasher &a, const hasher &b) {
hasher res;
for (int i = 0; i < 3; ++i) {
res.a[i] = a.a[i] + b.a... | 24 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 5;
char s[N];
int q;
char y[N], c[3];
bitset<N> state[26], ans;
int main() {
scanf("%s%d", (s + 1), &q);
int n = strlen(s + 1);
for (register int i = 1; i <= n; i++) state[s[i] - 'a'].set(i);
while (q-- > 0) {
int op, l, r;
scanf("%d%d... | 22 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 500005;
const int inf = 1050000009;
int n, k;
int a[maxn], b[maxn];
struct segment_tree {
int sz;
vector<int> mn, add, arr;
void push(int v) {
mn[v] += add[v];
if (2 * v + 1 < 4 * sz) {
add[2 * v] += add[v];
add[2 * v + 1] += add[v... | 14 |
#include <bits/stdc++.h>
int dr[] = {2, 2, -2, -2, 1, -1, 1, -1};
int dc[] = {1, -1, 1, -1, 2, 2, -2, -2};
int dr1[] = {0, 0, 0, 1, 1, 1, -1, -1, -1};
int dc1[] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};
int dr2[] = {0, 0, 1, -1};
int dc2[] = {1, -1, 0, 0};
using namespace std;
long long int mark[32000];
vector<long long int> v... | 11 |
#include <bits/stdc++.h>
using namespace std;
constexpr size_t kMaxN{2100};
int n;
long long field[kMaxN + 10][kMaxN + 10];
bool color[kMaxN + 10][kMaxN + 10];
int left_diag[kMaxN + 10][kMaxN + 10];
int right_diag[kMaxN + 10][kMaxN + 10];
long long left_diag_sum[3 * kMaxN + 10];
long long right_diag_sum[3 * kMaxN + 10]... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
scanf("%d %d", &n, &m);
int a[100005];
a[0] = 0;
for (int i = 1; i <= n; i++) {
int c, t;
scanf("%d %d", &c, &t);
a[i] = c * t + a[i - 1];
}
int j = 1;
for (int i = 1; i <= m; i++) {
int x;
scanf("%d", &x);
m:
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 305001;
const int SQRT = 350;
const long double PI = acos(-1);
string s[2];
vector<pair<char, int> > v[2];
int t;
int solve() {
for (int i = 0; i < 2; i++) {
cin >> s[i];
v[i].clear();
v[i].push_back(make_pair(s[i][0], 1));
for (int j = 1; j ... | 4 |
#include <bits/stdc++.h>
using namespace std;
void getlps(vector<int> w, vector<int> &lps) {
int len = 0;
int i;
lps[0] = 0;
i = 1;
while (i < w.size()) {
if (w[i] == w[len]) {
len++;
lps[i] = len;
i++;
} else {
if (len != 0) {
len = lps[len - 1];
} else {
... | 10 |
#include <bits/stdc++.h>
using namespace std;
string s1, s2;
int i, l, r, ax;
deque<char> deck;
int main(void) {
cin >> s1;
cin >> s2;
for (i = 0; i < s1.size(); i++) {
deck.push_back(s1[i]);
if (s1[i] == '|') {
l = i;
r = s1.size() - i - 1;
}
}
ax = s2.size();
if ((l + r + ax) % 2 =... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<pair<int, int> > a;
double dp[51][51][51];
bool vis[51][51][51];
double solve(double x[], int i, int j, int k) {
if (j < 0) return 1e12;
if (i == n) return 0;
if (vis[i][j][k]) return dp[i][j][k];
double ret =
x[i] + solve(x, i + 1,
... | 17 |
#include <bits/stdc++.h>
using namespace std;
priority_queue<pair<long long, pair<int, int> > > heap;
long long calc(int x, int y) {
y++;
int ai = x / y, bi = x / y + 1, aj, bj;
bj = (x % y);
aj = y - bj;
return 1ll * ai * ai * aj + 1ll * bi * bi * bj;
}
int main() {
ios::sync_with_stdio(false);
int n, m;... | 14 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, sm = 0;
cin >> n;
vector<long long> v[3];
for (long long i = 0; i < n; i++) {
long long x;
cin >> x;
v[x % 3].push_back(x);
sm += x;
sm %= 3;
}
for (long lo... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
int n, t, k, a[200009], pai[200009];
int main() {
while (scanf("%d%d%d", &n, &t, &k) == 3) {
int lo = 0, hi = 0;
int last = 1;
for (int(i) = (0); (i) < (t); ++(i)) {
scanf("%d", &a[i]);
lo += max(0, last - a[i]);
hi... | 13 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const int inf = (int)1e9;
const int MAX_N = 600;
int main() {
long long n, x, y;
cin >> n >> x >> y;
int ans = (n * y) / 100;
if ((n * y) % 100) ans++;
ans -= x;
cout << max(ans, 0) << endl;
return 0;
}
| 1 |
#include <bits/stdc++.h>
const int INF = 0x7f7f7f7f;
using namespace std;
long long n, x, y, c;
bool check(long long p) {
long long cnt = p * p + (p + 1) * (p + 1);
long long up = p - x, dn = p + x - n + 1, le = p - y, ri = p + y - n + 1,
curc = 0, curl = 0;
if (up > 0) curc += up * up;
if (dn > 0) ... | 10 |
#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...);
}
template ... | 17 |
#include <bits/stdc++.h>
using namespace std;
int n, t, a[3001], b[3001], key[3001];
bool flag;
char s[3001][101];
inline bool cmp(int x, int y) { return a[x] < a[y]; }
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%s%d", s[i], &a[i]);
key[i] = i;
}
sort(key + 1, key + n + 1, cmp);... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
char s[555][555];
int dp[555][27][27];
int pre[555][27][27];
int diff[555][27][27];
void print(int r, int x, int y) {
if (r == -1) return;
print(r - 1, pre[r][x][y] / 10000, pre[r][x][y] % 10000);
int i;
for (i = 0; i < m; i++) {
if (i & 1)
putch... | 12 |
#include <bits/stdc++.h>
using namespace std;
bool check(char ch) {
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
return true;
else
return false;
}
int main(void) {
string a, b;
cin >> a >> b;
int n = a.length(), m = b.length();
if (n != m) {
cout << "NO\n";
return 0;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 2;
int a[N], dp[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int q;
cin >> q;
while (q--) {
int n;
cin >> n;
fill(dp, dp + n + 2, 1);
for (int i = 1; i <= (n); i++) cin >> a[i];
for (int i = ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1E5 + 5;
int bit[10], k, first, m, n;
long long Cnt(int lop, long long ac, bool as, bool ae, long long bc, bool bs,
bool be) {
if (lop == k) return bc;
return Cnt(lop + 1, bc, bs, be, ac + bc + (ae * bs), as, be);
}
string Make(int c, bool... | 12 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; ++i) cin >> a[i];
int f, s;
cin >> s >> f;
--f;
--s;
int tot1 = 0;
for (int i = s; i < f; ++i) tot1 += a[i];
int best = tot1;
int bestd = 0;
for (int d... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const int INF2 = 0x3f3f3f3f;
const long long INF64 = 1e18;
const double INFD = 1e30;
const double EPS = 1e-6;
const double PI = 3.14159265;
const long long MOD = 998244353;
inline int read() {
int X = 0, w = 0;
char ch = 0;
while (!isdigit(... | 16 |
#include <bits/stdc++.h>
using namespace std;
int ara[4][402], dp[4][111], m;
int solve(int row, int col) {
if (col == m)
return 1;
else if (dp[row][col] != -1)
return dp[row][col];
else {
int p = 0, q = 0, r = 0, s, t, u, v, fr, sc, tr;
fr = col + 1;
u = (col - 1) * 2;
if (ara[row][fr + u... | 9 |
#include <bits/stdc++.h>
int n, i, j;
using namespace std;
int main() {
string a[10];
scanf("%d", &n);
a[1] = "+------------------------+";
a[2] = "|#.#.#.#.#.#.#.#.#.#.#.|D|)";
a[3] = "|#.#.#.#.#.#.#.#.#.#.#.|.|";
a[4] = "|#.......................|";
a[5] = "|#.#.#.#.#.#.#.#.#.#.#.|.|)";
a[6] = "+-----... | 3 |
#include <bits/stdc++.h>
using namespace std;
namespace INPUT {
const int L = 1 << 15;
char _buf[L], *S, *T, c;
char _gc() {
if (S == T) {
T = (S = _buf) + fread(_buf, 1, L, stdin);
if (S == T) return EOF;
}
return *S++;
}
void readi(int &X) {
for (c = _gc(); c < '0' || c > '9'; c = _gc())
;
X = c... | 20 |
#include <bits/stdc++.h>
using namespace std;
void init() { return; }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
init();
int n, k;
cin >> n >> k;
double x[n], y[n];
double ans = 0;
double speed = 50.0;
for (int i = 0; i < n; i++) {
cin >> x[i] >> y[i];
if (i >= 1) {
do... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, d, x, y;
int t;
cin >> t;
while (t--) {
cin >> n;
cin >> x;
cin >> y;
cin >> d;
long long e = n + 1;
if ((y - x) % d == 0) {
e = abs(y - x) / d;
}
long long c = n + 1, a = n + 1;
if ((y - 1) % d == ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, q;
cin >> n >> q;
vector<long long> powe(n + 1, 0);
powe[0] = 1;
for (long long i = 1; i <= n; i++) powe[i] = (powe[i - 1] * 2) % 1000000007;
vector<long long> A(n, 0), pre(n, 0);
string s;
cin >> s;
for (long long i = 0; i < n; i... | 8 |
#include <bits/stdc++.h>
using namespace std;
bool polin(string s) {
int len = s.size();
int i, j, many = 0;
for (i = 0, j = len - 1; (i < (len / 2)); i++, j--) {
if (s[i] != s[j]) {
many++;
}
}
if (many == 1) return true;
if (many == 0) {
if (len & 1) return true;
return false;
}
... | 2 |
#include <bits/stdc++.h>
using namespace std;
long long n, t, k, tdist, ans, ap;
vector<pair<long long, long long> > v;
long long summ;
int main() {
ios_base::sync_with_stdio(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> t;
v.push_back(make_pair(t, i));
}
sort(v.begin(), v.end());
cin >> k;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3010;
int n, u, v, dist[maxn], degree[maxn];
bool vis[maxn];
vector<int> G[maxn];
void bfs() {
queue<int> q;
for (int i = 1; i < n + 1; i++)
if (degree[i] == 1) q.push(i);
while (!q.empty()) {
int x = q.front();
q.pop();
vis[x] = 1;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
vector<int> type(2 * 100005);
vector<int> type2(2 * 100005);
int first = 0;
int counter1 = 0;
int counter2 = 0;
int f2 = 0;
int counter12 = 0;
int counter22 = 0;
void dfs(int x, vector<pair<int, int> > adj[]) {
if (type[x] == 1)
counter1++;
else
counter2++;
fo... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long k, size[15];
long long sum = 0, boxSum[15];
map<long long, long long> need, boxOf;
map<long long, vector<long long>> cycle;
map<long long, int> bmCycle;
map<int, set<pair<int, long long>>> bmsOfBox;
vector<long long> box[15];
vector<long long> auxCycles;
bool alre... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, j;
char in[55][55];
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf(" %s", in[i]);
}
for (i = 1; i < n - 1; i++) {
for (j = 1; j < n - 1; j++) {
if (in[i][j] == '.') {
if (in[i - 1][j] == '.' && in[i + 1][j] == '.' &... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 500005;
int n, k, a[Maxn], b[Maxn];
long long ans;
priority_queue<pair<long long, bool> > Pr;
int main() {
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
long long lt = 0, rt ... | 21 |
#include <bits/stdc++.h>
using namespace std;
long long d_sum(long long n) {
long long res = 0;
while (n) {
res += n % 10;
n /= 10;
}
return res;
}
void solve() {
long long n, s;
cin >> n >> s;
long long old = n;
long long sum = d_sum(n);
if (sum <= s) {
cout << "0\n";
return;
}
lo... | 7 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.