solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
int n;
cin >> n;
int arr[n + 5], left[n + 5], right[n + 5];
for (int i = 0; i < n; ++i) {
cin >> arr[i];
}
left[0] = 1;
int ans = 2;
for (int i = 1; i < n; ++i) {
ans = min(ans, arr[i]);
left[i] = ans;... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 133331;
struct hashNode {
int numVal;
int numCnt;
int test;
hashNode() : numVal(0), numCnt(0) {}
};
hashNode hashTable[MAX];
void insert(int x) {
int pos = x % MAX;
while (hashTable[pos].numVal != 0 && hashTable[pos].numVal != x) {
pos++;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100050;
void solve() {
int a_x_min, a_x_max, a_y_min, a_y_max, a_xandy_min, a_xandy_max, a_xsuby_min,
a_xsuby_max;
int b_x_min, b_x_max, b_y_min, b_y_max, b_xandy_min, b_xandy_max, b_xsuby_min,
b_xsuby_max;
int x, y;
scanf("%d%d", &x, &y);
... | 8 |
#include <bits/stdc++.h>
using namespace std;
bool isDigit(char ch) {
if (ch >= '0' && ch <= '9') return true;
return false;
}
int main() {
string s;
cin >> s;
bool upper = false, lower = false, digit = false;
for (int i = 0; i < s.size(); ++i) {
if (isupper(s[i])) upper = true;
if (islower(s[i])) l... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
float k;
cin >> k;
float a = 0;
int b = 0;
float c = 0;
if (k < 10) {
cout << k;
}
if (k >= 10 && k <= 189) {
a = 9 + (k - 9) / 2;
b = a;
if (b != a) {
b = b + 1;
cout << b / 10;
} else {
cout << b % 10;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 5;
int n, m, t;
int num[MAXN];
int init[MAXN];
int start[MAXN], cir[MAXN];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) scanf("%1d", &init[i]);
for (int i = 1; i <= n; i++) {
cin >> cir[i] >> start[i];
}
int ans = 0;
for (int i ... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int N = 65;
char a[2][N][N];
int P[N];
bool haver[N][N];
bool havel[N][N];
int solve(int r, int c, int t) {
int ans = 1e9;
for (int i = 1; i <= r; i++) {
P[i] = 0;
for (int j = 1; j <= c; j++) {
P[i] = P[i] + (a[t][i][j] == 'P');
if (a[t][i][j]... | 10 |
#include <bits/stdc++.h>
using namespace std;
inline void rd(int &res) {
res = 0;
char c;
while (c = getchar(), c < 48)
;
do res = (res << 1) + (res << 3) + (c ^ 48);
while (c = getchar(), c >= 48);
}
void print(int x) {
if (!x) return;
print(x / 10);
putchar((x % 10) ^ 48);
}
void sc(int x) {
if ... | 6 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T BigMod(T b, T p, T m) {
if (p == 0) return 1;
if (p % 2 == 0) {
T s = BigMod(b, p / 2, m);
return ((s % m) * (s % m)) % m;
}
return ((b % m) * (BigMod(b, p - 1, m) % m)) % m;
}
template <typename T>
T ModInv(T b, T m) {
return BigMo... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t;
cin >> t;
while (t--) {
long long int n, a, b, c, d;
cin >> n >> a >> b >> c >> d;
long long int maxTotal = c + d;
long long int minTotal = c - d;
long long int maxCal = n * (a + b);
long long int minCal = n * (a -... | 1 |
#include <bits/stdc++.h>
using namespace std;
inline void solve() {
long long a, b;
scanf("%I64d", &a), scanf("%I64d", &b);
if (a == 0 && b == 0) {
cout << 1 << "\n";
return;
}
if (a == 0) {
double d = 1. / 2;
printf("%.7f\n", d);
return;
}
if (b == 0) {
cout << 1 << "\n";
retu... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long int n, a[100001], b[100001], ans = -1, i, j, k, rem, x, r;
int main() {
cin >> n;
for (i = 2; i <= n; i++) {
for (j = 2; j * (j + 1) / 2 <= i; j++) {
rem = i - j * (j + 1) / 2;
if (rem % j) continue;
x = 0;
rem /= j;
for (k = ... | 12 |
#include <bits/stdc++.h>
#define M 1000000007
#define fio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define d(x) cout << #x << " " << x << "\n";
#define min(x1, x2) (x1 > x2 ? x2 : x1)
#define max(x1, x2) (x1 < x2 ? x2 : x1)
#define min3(x1, x2, x3) (x3 > min(x1, x2) ? min(x... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int i;
string a, b;
cin >> a >> b;
int ans = 0;
for (i = 0; i < n; i++) {
if (a[i] == '0' && b[i] == '1')
ans++;
else if (i > 0 && a[i - 1] == '1' && b[i] == '... | 0 |
#include <bits/stdc++.h>
using namespace std;
char s[111];
int main() {
while (~scanf("%s", s)) {
int i, k, a = 1, j, p, n = strlen(s);
for (i = 0; i < n; i++) {
if (a == 0) break;
if (s[i] == '0') continue;
for (j = i + 1; j < n; j++) {
if (a == 0) break;
for (k = j + 1; k <... | 7 |
#include <bits/stdc++.h>
using namespace std;
double EPS = 1e-10;
double EQ(double a, double b) { return abs(a - b) < EPS; }
void fast_stream() { std::ios_base::sync_with_stdio(0); }
template <class T>
string IntToString(T num) {
string res;
stringstream ss;
ss << num;
return ss.str();
}
long long StringToInt(s... | 14 |
#include <bits/stdc++.h>
using namespace std;
map<int, int> cnt;
int where_now, times, ans, start, last, first;
deque<int> check;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
int n, k, x;
cin >> n >> k;
int inp[n];
for (int i = 0; i < n; i++) {
cin >> inp[i];
cnt.insert(p... | 8 |
#include <bits/stdc++.h>
using namespace std;
int x[3];
int y[3];
int buf;
int main() {
buf = 0;
cin >> x[0] >> y[0] >> x[1] >> y[1] >> x[2] >> y[2];
for (long long i = 0; i < 3; ++i) {
if (x[i] < y[i]) {
buf = x[i];
x[i] = y[i];
y[i] = buf;
}
}
int n = max(x[0], x[1]);
n = max(n, ... | 9 |
#include <bits/stdc++.h>
int n, m, ans[6010];
char s[2][2010], goal[2010];
int f[2][2010];
void shift(int x) {
int i, j;
if (x < 1 || x > n) return;
ans[++m] = n - x + 1;
for (i = n, j = 1; i >= x; i--, j++) s[m & 1][j] = s[m & 1 ^ 1][i];
for (i = 1; i < x; i++, j++) s[m & 1][j] = s[m & 1 ^ 1][i];
}
int main(... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
long long n;
cin>>t;
while(t--) {
cin>>n;
long long arr[n], ans = 0;
vector<long long> dp(n, 0);
for(int i = 0; i < n; i++)
cin>>arr[i];
for(int i = n-1; i >= 0; i--) {
dp... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int candies, friends;
cin >> candies >> friends;
int high = candies % friends;
int div = candies / friends;
int i;
for (i = 0; i < friends - high; ++i) {
cout << div << " ";
}
for (; i < friends; ++i) {
cout << (div) + 1 << " ";
}
re... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
char s[N][2];
int nid[N];
set<int> S;
vector<int> ans;
bool hav[N];
int main() {
int n, m, i;
scanf("%d%d", &n, &m);
int ma = 0, tc = 0;
for (i = 1; i <= m; ++i) {
scanf("%s%d", s[i], &nid[i]);
if (!hav[nid[i]]) {
hav[nid[i]] = 1;... | 10 |
#include <bits/stdc++.h>
const double Pi = acos(-1.0);
using namespace std;
const int maxA = 1000005;
const long long mod = 1000000007;
int n;
long long bit[maxA];
void update(int p, long long x) {
for (int i = p; i < maxA; i += i & (-i)) bit[i] = (bit[i] + x) % mod;
}
long long query(int p) {
long long res = 0;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-9;
const double EPS = 1e-9;
int main() {
ios_base::sync_with_stdio(false);
int n, k;
cin >> n >> k;
if (k >= n * (n - 1) / 2) return cout << "no solution\n", 0;
for (int i = 0; i < n; i++) cout << "0 " << i << "\n";
return 0;
}
| 5 |
#include <bits/stdc++.h>
using namespace std;
struct point {
int x, y;
bool operator<(const point& a) const {
if (a.x == x) return a.y < y;
return a.x < x;
}
};
point operator-(point a, point b) {
point temp;
temp.x = a.x - b.x;
temp.y = a.y - b.y;
return temp;
}
bool operator==(point a, point b) ... | 13 |
#include <bits/stdc++.h>
int main() {
int a, b, c, d, sum, i, e;
while (scanf("%d%d%d", &a, &b, &c) != EOF) {
sum = 0;
d = 0;
for (i = 1; i <= c; i++) {
d = i * a;
sum += d;
}
e = sum - b;
if (e > 0) {
printf("%d\n", e);
} else {
printf("0");
}
}
return 0;... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const double eps = 1e-9;
int n, a[N], q, untasted[N];
double dp[N][101];
long long cNum[N][6];
long long C(long long n, long long k) {
long long ans = 1;
if (n < N && cNum[n][k]) return cNum[n][k];
for (int i = 0; i < k; ++i) ans *= n - i;
for ... | 18 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
int a = 0, b = 0;
for (int i = 0; i < n; i++) {
int v;
cin >> v;
if (i & 1 && v % 2 == 0) a++;
if (i % 2 == 0 && v % 2 == 1) b++;
}
if (a == b) {
cout << a << endl;
return;
}
cout << -1 << endl;
}
int m... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int V = 1200;
int r[V], c[V], X, Y, x[120], y[120];
int co[10][10], n, m;
int main() {
while (~scanf("%d%d", &n, &m)) {
memset(r, 0, sizeof(r));
memset(c, 0, sizeof(c));
memset(co, 0, sizeof(co));
co[0][2] = co[0][5] = co[0][6] = 1;
co[1][3] = co... | 10 |
#include <bits/stdc++.h>
using namespace std;
int N, Sharp;
inline bool Black(int S) {
int CS;
if (N % 2 == 0) {
int M = N / 2 - 1;
CS = 4 * (M * M / 2 + (M & 1));
S = max(S % 4, S - CS);
if (!S) return true;
} else {
int M = N / 2;
CS = 4 * (M * M / 2 + (M & 1));
S = max(S % 4, S - CS... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, NUM;
int t[400500][100];
void up(int rt) {
for (int i = 0; i < 60; ++i)
t[rt][i] = t[rt << 1][i] + t[rt << 1 | 1][(i + t[rt << 1][i]) % 60];
}
void build(int l, int r, int rt) {
if (l == r) {
int v;
scanf("%d", &v);
for (int i = 0; i < 60; ++i) {
... | 16 |
#include <bits/stdc++.h>
char road[1001];
int n, count;
void readinp() {
FILE *inp = stdin;
fscanf(inp, "%d ", &n);
int i, a, b, c, d;
fscanf(inp, "%d %d ", &a, &b);
for (i = 0; i < n; i++) {
fscanf(inp, "%d %d ", &c, &d);
if (c == a) {
if (d > b)
road[count++] = 'N';
else
... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, s, q;
scanf("%d%d%d", &t, &s, &q);
int dwl = s;
long long int count = 1;
int start = 0;
while (dwl < t) {
start += q;
dwl += q - 1;
if (dwl < t) {
if (start >= dwl) {
count++;
start = 0;
}
}
}
c... | 7 |
#include <bits/stdc++.h>
using namespace std;
int N, A[100005];
int main() {
scanf("%d", &N);
for (int i = 0; i < N; i++) {
scanf("%d", &A[i]);
}
int first = 0, last = 0;
vector<int> s;
while (first < N) {
if (A[first] == 0) {
int a = -1, b = -1, c = -1;
sort(s.begin(), s.end());
f... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long lucky[2048];
int len;
int l1, r1, l2, r2, k;
long long ans;
int itv_and(long long l1, long long r1, long long l2, long long r2);
void init();
void gao();
void print();
void prepare();
long long calc(int l1, int r1, int l2, int r2);
int main() {
prepare();
init... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int r, b;
struct node {
int x, y;
};
node ss[15];
node bb[15];
int main() {
ios::sync_with_stdio(false);
cin >> r >> b;
for (int i = 0; i < r; i++) {
cin >> ss[i].x >> ss[i].y;
}
for (int i = 0; i < b; i++) {
cin >> bb[i].x >>... | 8 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void chmin(T &x, const T &y) {
if (x > y) x = y;
}
template <typename T>
void chmax(T &x, const T &y) {
if (x < y) x = y;
}
int read() {
char c;
while ((c = getchar()) < '-')
;
if (c == '-') {
int x = (c = getchar()) - '0';
while ... | 27 |
#include <bits/stdc++.h>
const int N = 1e5 + 5, P = 1e9 + 7;
int tt, n, f[N], g[N];
std::vector<int> t[N];
inline void dfs(int u) {
f[u] = 1;
int i, v, a = 0, b = 1, c = 1, p, q;
for (i = 0; i < t[u].size(); i++)
dfs(v = t[u][i]),
p = f[u], q = g[u],
f[u] = (f[u] + (long long)p * g[v] + (long ... | 19 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
os << "[";
for (auto u : v) {
os << u;
if (u != *v.rbegin()) os << ",";
}
os << "]" << endl;
return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& s) {... | 5 |
#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... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long k, b, n, t, z = 1;
int main() {
cin >> k >> b >> n >> t;
while (k * z + b <= t) {
z = z * k + b;
n--;
}
cout << (n > 0 ? n : 0);
return 0;
}
| 9 |
#include <bits/stdc++.h>
using namespace std;
bool was[300005];
int arr[300005];
int arr2[300005];
void fin(int n, int k) {
for (int i = 1; i <= 3 * n; i++) {
if (i != k) {
printf("%d ", i);
}
}
}
int main() {
int n, k;
scanf("%d", &n);
for (int i = 0; i < 3 * n; i++) {
scanf("%d", &arr[i]);... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int oo = 1000000000;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
for (int u = (0); u < (t); u++) {
string b, a;
cin >> b;
if (b.size() == 2) {
cout << b << "\n";
} else {
for (int i = 0; i < b... | 0 |
#include <bits/stdc++.h>
using namespace std;
int n;
int last[3000007], pre[3000007], other[3000007], cntt = 0;
int d[3000007], tot[3000007];
int cnt[5];
int tmp[3000007], ansss;
int sz[3000007], ssz[3000007];
bool ck;
vector<int> qq;
int qqq[3000007];
void insert(int u, int v) {
other[++cntt] = v, pre[cntt] = last[u... | 17 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d, e, f;
scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &f);
if (d == 0)
puts("Hermione");
else if (c == 0)
puts("Ron");
else if (b == 0)
puts("Hermione");
else if (a == 0)
puts("Ron");
else if (f == 0)
puts("Hermi... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[100001] = {}, max, b, m = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
max = a[n - 1] - a[0];
for (int i = 1; i < n - 1; i++) {
m = 0;
for (int j = 1; j < n; j++) {
if (j == i) {
b = a[j + 1] - a[j - 1... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T gcd(T a, T b) {
while (b ^= a ^= b ^= a %= b)
;
return a;
}
template <class T>
T lcm(T a, T b) {
return (a / gcd<T>(a, b) * b);
}
template <class T>
inline int countbit(T n) {
return (n == 0) ? 0 : (1 + countbit(n & (n - 1)));
}
template <cl... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, m, a, b;
cin >> n >> m >> a >> b;
if ((a - 1) / m == (b - 1) / m || m == 1) {
cout << 1;
return 0;
}
if (a % m == 1) {
if (b % m == 0 || b == n)
cout << 1;
else
cout << 2;
return 0;
}
if (a % m - b ... | 9 |
#include <bits/stdc++.h>
using namespace std;
void desperate_optimization(int precision) {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(precision);
}
const int N = 1e5;
long long y[N + 5];
long long x[N + 5];
vector<int> candidat... | 14 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
int a[100005];
scanf("%d", &n);
int t = n;
int min = INT_MAX;
int in = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
if (a[i] < min) {
min = a[i];
in = i;
}
}
bool fl = false;
for (int i = in + 1; i < n;... | 1 |
#include <bits/stdc++.h>
using namespace std;
inline string GetString() {
string res;
char st[1000005];
scanf("%s", st);
res = st;
return res;
}
inline string GetSent() {
string res;
char st[1000005];
gets(st);
res = st;
return res;
}
template <typename t>
t in() {
t res = 0;
char c;
int sign ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int n, a[2002], nr;
int gcd(int a, int b) {
int r;
while (b != 0) {
r = a % b;
a = b;
b = r;
}
return a;
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
int gcdi = 0, cnt1 = 0;
for (int i = 1; i <= n; i++) {
gcdi = gcd(gcdi... | 7 |
#include <bits/stdc++.h>
using namespace std;
void operate(long long int num[], string &sign, int h, long long int &small) {
if (h == 3) {
small = min(small, num[0]);
return;
}
long long int c[5];
for (int i = 0; i < 4 - h; i++) {
for (int j = i + 1; j < 4 - h; j++) {
for (int k = 0; k < 5; k+... | 8 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
const int MOD = 1e9 + 7;
ll mpow(ll a, ll n, ll m = MOD) {
n %= (MOD - 1);
ll r = 1;
while (n) {
if (n & 1) r = (r * a) % m;
a = (a * a) % m;
n >>= 1;
}
return r;
}
void matmul(ll a[4][4], ll b[4][4], ll c[4][4]) {
for (int ... | 15 |
#include <bits/stdc++.h>
using namespace std;
long long gi() {
long long x = 0, f = 1;
char ch = getchar();
while (!isdigit(ch)) f ^= ch == '-', ch = getchar();
while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
return f ? x : -x;
}
template <class T>
void cxk(T& a, T b) {
a = a > b ? a : b;
}
templ... | 21 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 10000 + 10, MOD = int(1e9 + 7);
struct matrix {
int d[3][3];
matrix() { memset(d, 0, sizeof d); }
int *operator[](int i) { return d[i]; }
};
matrix multiply(matrix a, matrix b) {
matrix c;
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++... | 13 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
long long n;
cin >> n;
string s;
cin >> s;
long long ans = 1e8;
for (long long i = 0; i < n - 3; i++) {
long long a = 0;
a += min(abs(s[i] - 'A'), 26 - abs(s[i] - 'A'));
a += min(abs(s[i + 1] - 'C'), 26 - abs(s[i + 1] - 'C'));
a +... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, a[101], complexity, first, last;
int used[101];
int p[2];
vector<int> h[2], m[2];
int main() {
cin >> n;
if (n == 1) {
cout << 0;
return 0;
}
for (int i = 0; i < n; ++i) {
cin >> a[i];
used[a[i]] = 1;
}
for (int i = 1; i <= n; i++) {
i... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int ft[N][2];
int get(int x, int id) {
int ans = 0;
for (; x > 0; x -= x & -x) ans += ft[x][id];
return ans;
}
void upd(int x, int id, int val) {
for (; x < N; x += x & -x) ft[x][id] += val;
}
void upd(int l, int r, int id, int val) {
upd(l, ... | 19 |
#include <bits/stdc++.h>
using namespace std;
int n, s, q;
long long weight[1002];
long long arr[32];
vector<pair<long long, int> > vecA, vecB;
long long rnd() { return rand() + 1; }
int main() {
scanf("%d %d %d", &n, &s, &q);
for (int i = 1; i <= n; i++) {
weight[i] = rnd() * rnd() * rnd() * rnd() * rnd();
}... | 18 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return ((a * b) / gcd(a, b)); }
int main() {
int n, i, j, a[101][101], b[101] = {0};
cin >> n;
for (i = 1; i <= n; ++i) {
for (j = 1; j <= n; ++j) {
cin >> a[i][j];
if... | 1 |
#include <bits/stdc++.h>
using namespace std;
const unsigned long long inf = (1ll << 61);
const unsigned long long mod = 1e9 + 7;
const int MX = 5009;
int n, k, v, a[MX], dp[MX][MX][2];
vector<int> sol;
unsigned long long sum = 0;
vector<pair<int, pair<int, int> > > res;
int DP(int x, int y, bool flag = 0) {
if (x ==... | 16 |
#include <bits/stdc++.h>
using namespace std;
int hmt() {
int x = 0;
int c = getchar(), n = 0;
for (; !isdigit(c); c = getchar()) n = (c == '-');
for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
if (n) x = -x;
return x;
}
const int N = 300010;
int n, m, dd[N], pre[N];
set<int> ke[N];
unsigned long lo... | 18 |
#include <bits/stdc++.h>
const int N = 305;
int p[N][N], o[N][N], r[N];
int main() {
int n, i, j, p1, p2, t;
scanf("%d", &n);
for (i = 1; i <= n + 1; i++) {
for (j = 1; j <= n; j++) {
scanf("%d", &p[i][j]);
}
p[i][n + 1] = n + 1;
}
for (i = 1; i <= n + 1; i++)
for (j = 1; j <= n + 1; j++... | 10 |
#include <bits/stdc++.h>
using namespace std;
inline int add(int a, int b) {
a += b;
return a >= 1000000007 ? a - 1000000007 : a;
}
inline int sub(int a, int b) {
a -= b;
return a < 0 ? a + 1000000007 : a;
}
inline int mul(int a, int b) { return (long long int)a * b % 1000000007; }
int Set(int N, int pos) { ret... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios ::sync_with_stdio(0);
int n;
cin >> n;
if (n < 4) {
cout << "NO\n";
} else if (n == 4) {
cout << "YES\n";
cout << 1 << " * " << 2 << " = " << 2 << "\n";
cout << 2 << " * " << 3 << " = " << 6 << "\n";
cout << 4 << " * " << 6 << ... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long in() {
long long a;
scanf("%lld", &a);
return a;
}
double din() {
double a;
scanf("%lf", &a);
return a;
}
long long bigmod(long long b, long long p, long long md) {
if (p == 0) return 1;
if (p % 2 == 1) {
return ((b % md) * bigmod(b, p - 1, md)... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, l, c = 0;
string a;
cin >> a;
l = a.size();
for (i = 0; i < l / 2; i++) {
if ((a[i] == 'A' || a[i] == 'H' || a[i] == 'I' || a[i] == 'M' ||
a[i] == 'O' || a[i] == 'T' || a[i] == 'U' || a[i] == 'V' ||
a[i] == 'W' || a[i] == ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
long long a[66];
a[0] = 1;
vector<string> powers;
powers.push_back(to_string(a[0]));
for (int i = 1; i < 64; i++) {
a[i] = a[i - 1] * 2;
string str = to_string(a[i]);
... | 5 |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define pb push_back
#define INF INT_MAX
ll M = 1e9+7;
ll t;
void solve()
{
ll n,m;
map<ll,ll>mp;
cin>>n>>m;
for(ll i=0;i<m;i++)
{
ll x,y;
cin>>x>>y;
mp[y]= mp[y]|(1<<(x-1));
}
ll FULL = 3;
mp... | 13 |
#include <bits/stdc++.h>
using namespace std;
int a[100005], where[100005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> values;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
int k = 0;
for (int i = 1; i <= n; ++i) {
bool mark = false;
if (a[i] ==... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n;
string s;
vector<pair<int, int> > ve;
char L[] = "RGBYW";
map<char, int> ml;
int f(int s, int a, int b) {
int fa, fb;
int ba, bb;
ba = (s & (1 << (a)));
bb = (s & (1 << (b + 5)));
fa = (ba > 0 ? a : 6);
fb = (bb > 0 ? b : 6);
return fa + fb * 6;
}
bool ... | 9 |
#include <bits/stdc++.h>
#define int long long
#define ff first
#define ss second
#define ll long long
#define pb push_back
#define endl "\n"
using namespace std;
const long long N=100005;
void solve(){
int n;
cin>>n;
int a[n+1];
for(int j=1;j<=n;j++)
cin>>a[j];
int count=0;
for(int j=1;j<... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int Inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
struct UnionFind {
int fa[55];
void inline init() { memset(fa, -1, sizeof(fa)); }
UnionFind() { init(); }
int inline root(int x) { return fa[x] < 0 ? x : fa[x] = root(fa[x]); }
bool inline con... | 23 |
#include <bits/stdc++.h>
using namespace std;
int setbit(int n, int i, int v) {
return ((v) ? (n | (1 << i)) : (n & ~(1 << i)));
}
long long gcd(int i, int j) {
if (j == 0) return i;
return gcd(j, i % j);
}
bool chk(int n, int i) {
if ((n >> i) & 1 == 1) return 1;
return 0;
}
bool T(pair<pair<int, int>, int> ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
for (int x = 0; n; ++x) {
for (int y = 0; y < 3 and n; ++y) {
if (x % 2 == y % 2) cout << x << ' ' << y << '\n', --n;
}
}
}
| 18 |
#include <bits/stdc++.h>
using namespace std;
int n, w, b, cap, sm;
char x;
int main() {
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
cin >> x;
if (x >= 'A' && x <= 'Z') {
if (x == 'Q')
w += 9;
else if (x == 'R')
w += 5;
else if (x == 'B')
... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e5 + 5;
string A, B;
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
long long int t;
cin >> t;
while (t--) {
long long int n, temp = 0;
cin >> n >> A >> B;
A += '0';
B += '0';
vector<long long int> V;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
char get_op(char c) {
if (c == 'R')
return 'L';
else if (c == 'L')
return 'R';
else if (c == 'U')
return 'D';
else if (c == 'D')
return 'U';
else
return '0';
}
void solve() {
long long n;
cin >> n;
;
string str;... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> m >> n;
cout << (n * m) / 2;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
int t;
cin >> t;
int a, b;
int c;
while (t--) {
cin >> a >> b;
if (a % b == 0) {
cout << 0 << "\n";
} else {
c = b - a % b;
cout << c << "\n";
}... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int *arr = (int *)malloc(n * sizeof(int));
long long int sum = 0, temp = 0;
for (int i = 0; i < n; i++) {
cin >> arr[i];
sum += arr[i];
temp += arr[i];
}
sort(arr, arr + n);
for (int i = 0; i < n - 1; i++) {
temp... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, p[100100], g, r, ch;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (long long i = 1; i <= m; i++) {
cin >> p[i];
}
cin >> g >> r;
vector<vector<long long> > dist(m + 5, vector<long long>(g +... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
bool a[91];
memset(a, false, sizeof a);
a[65] = true;
a[72] = true;
a[73] = true;
a[77] = true;
a[79] = true;
a[84] = true;
a[85] = true;
a[86] = true;
a[87] = true;
a[88] = true;
a[89] = true;
char s[100000];
scanf("%s", &s);
in... | 2 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<long long> > adj(100005);
vector<long long> vis(100005, 0);
bool is_lucky(long long n) {
while (n > 0) {
if ((n % 10) != 4 && (n % 10) != 7) {
return false;
}
n /= 10;
}
return true;
}
long long f_ans, conn, tot;
void dfs(long long n, l... | 11 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool Up(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T>
inline bool Down(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
inline int getus() {
int tmp, c;... | 16 |
#include <bits/stdc++.h>
int n, k;
int dp[(2010)][(2010)];
std::vector<std::pair<int, int>> war[(2010) + (2010)];
bool vis[(2010)][(2010)];
char s[(2010)][(2010)];
int main() {
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; ++i) {
scanf("%s", s[i] + 1);
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e6 + 10;
const long long base = 1e9 + 7;
int N, ans;
long long power[maxN], H[maxN];
string S;
vector<int> F;
long long gethash(int x, int y) {
return (H[y] - H[x - 1] * power[y - x + 1] + base * base) % base;
}
bool check(int x) {
long long h = gethas... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
int n, k;
cin >> n >> k;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
vector<vector<int>> dp(n + 1, vector<int... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 60;
const int mod = 1e9 + 7;
bool f[2][1010];
int main() {
int n, m, x;
scanf("%d%d", &n, &m);
memset(f, false, sizeof(f));
bool ans = false;
for (int i = 1; i <= n; i++) {
scanf("%d", &x), x %= m;
f[1][x] = true;
for (int k = 0; k <= ... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 4 * 1e5, M = 7 + 1e9;
double eps = 1e-9;
int m, a[N];
map<int, vector<char> > mp;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
string s;
cin >> s;
int freq[26] = {};
for (int i = 0; i < (int)(s... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long r, c, n, kk, x, y, a[15][15], sum[15][15], ans;
long long read() {
long long ch, x;
x = 0;
ch = getchar();
while (ch < '0' || ch > '9') ch = getchar();
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x;
}
int ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, m, tot, cnt, flag, x, y, ans, col[1005], head[200005], ver[200005],
nxt[200005], exi[1005], dis[1005], f[1005];
void add(int x, int y) {
ver[++tot] = y;
nxt[tot] = head[x];
head[x] = tot;
}
void dfs(int p, int pat) {
exi[p] = cnt;
col[p] = pat;
for (i... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 77, mod = 998244353;
long long f[N], g[N], h[N];
int n, cnt, ls[N];
struct E {
int to, next;
} e[N];
void add(int u, int v) {
e[++cnt].to = v;
e[cnt].next = ls[u];
ls[u] = cnt;
}
void dfs(int u) {
if (!ls[u]) {
g[u] = 1;
return;
}
h... | 17 |
#include <bits/stdc++.h>
using namespace std;
int f[500001], b[500001], a[500001];
int N, A, B, T;
int FIXED;
int fnc(int mid) {
int i;
int p, q, t;
for (i = 0; i < mid; i++) {
p = (f[i] + (i)*A);
q = (b[mid - 1 - i] + (mid - i - 1) * A);
p = p + q + FIXED;
q = p;
p = p + (i)*A;
q = q + (m... | 11 |
#include <bits/stdc++.h>
using namespace std;
int t, num[150];
string temp;
int main() {
cin >> t >> temp;
int now = 0, res = 0x3f3f3f;
for (int i = 0; i < t; i++) {
num[temp[i]]++;
int a = num[temp[i]];
while (num[temp[now]] > 1) {
num[temp[now]]--;
now++;
}
if (a == 1)
res ... | 7 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void amin(T &x, const T &y) {
if (y < x) x = y;
}
template <class T>
inline void amax(T &x, const T &y) {
if (x < y) x = y;
}
template <class Iter>
void rprintf(const char *fmt, Iter begin, Iter end) {
for (bool sp = 0; begin != end; ++begin)... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k, x, n1, n2, n3;
n1 = n2 = n3 = 0;
int p;
cin >> n >> k >> p;
if (k == n)
n3 = n;
else {
if (!(n - 2 * k))
n2 = n;
else if (n - 2 * k < 0) {
n2 = 2 * (n - k);
n3 = k - n2 / 2;
} else {
n2 = 2 * k... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 10000;
const int INF = 100000000;
int n, m, u, v;
int N = 100;
vector<int> a(1001);
long long ans = 0;
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
for (int i = 0; i < m; i++) {
scanf("%d%d", &u, &v);
u--... | 6 |
#include <bits/stdc++.h>
template <typename T>
inline void SWAP(T &a, T &b) {
T tmp = a;
a = b;
b = tmp;
}
template <typename T>
inline T ABS(const T &val) {
return val < 0 ? -val : val;
}
template <typename T>
inline T MAX(T a, T b) {
return a > b ? a : b;
}
template <typename T>
inline T MIN(T a, T b) {
r... | 4 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.