solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < (int)(n); ++i) cin >> a[i];
int x = a[n - 1];
sort((a).begin(), (a).end());
cout << (x ^ (a[n - 1])) << endl;
return 0;
}
| 10 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, x, y;
cin >> n >> x >> y;
long long a[n];
for (long long i = 0; i < n; i++) cin >> a[i];
if (x > y)
cout << n << "\n";
else {
long long ans = 0;
vector<long long> v;
for (long long i = 0; i < n; i++) {
if (a[i] <... | 4 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 2e12;
const int MAXN = 2.5e5;
const int MAXM = 2.5e5;
int N, M;
int par[MAXN];
long long V[MAXN];
int sz[MAXN];
vector<int> comp[MAXN];
long long cmin[MAXN];
long long cmax[MAXN];
int main() {
ios_base::sync_with_stdio(0);
cin >> N >> M;
for (int... | 22 |
#include <bits/stdc++.h>
using namespace std;
const int ROOT = 1;
const int LEAF = (1 << 18);
const int S = LEAF * 2;
const int T = 10;
vector<int> suf[S];
int n;
vector<int> query_res;
vector<int> query_cur;
vector<int> query_new;
void st_reset() {
for (int i = 0; i < S; i++) {
suf[i].clear();
if (i >= LEAF)... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k;
cin >> k;
if (k & 1) {
puts("-1");
return 0;
}
for (int i = 1; i <= k; ++i) {
for (int j = 1; j <= k; ++j) {
for (int x = 1; x <= k; ++x) {
if (i & 1) {
if ((j % 4 == 1 || j % 4 == 2) && (x % 4 == 1 || x % 4 ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int score(int p, int t) { return (1000 - p) * 1000 + t; }
int main(int argc, const char* argv[]) {
int n, k;
cin >> n >> k;
--k;
map<int, int> ts;
for (int i = 0; i < n; ++i) {
int p, t;
cin >> p >> t;
ts[score(p, t)] += 1;
}
int res = 0;
for (au... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int A[n];
for (int i = 0; i < n; i++) cin >> A[i];
int a = 0;
vector<string> str(n + 1, "");
if (A[0] == 0) {
char c = 97 + a;
str[0] += c;
a = (a + 1) % 26;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n = 0;
cin >> n;
map<long long, string> mapc;
string m;
for (int i = 0; i < n; i++) {
cin >> m;
mapc[i] = m;
}
long long res = 6;
for (auto& mm : mapc) {
for (auto& ms : mapc) {
if (ms != mm) {
long long tres ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5 * 1000 * 100 + 10;
long long c[maxn];
int par[maxn];
long long size[maxn];
bool mark[maxn];
vector<int> e[maxn];
int get_par(int v) { return (v == par[v] ? v : par[v] = get_par(par[v])); }
void merge(int v, int u) {
v = get_par(v);
u = get_par(u);
i... | 11 |
#include <bits/stdc++.h>
using namespace std;
int c[120], p[120];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cout.precision(16);
;
int t;
cin >> t;
while (t--) {
int n, flag = 0;
cin >> n;
for (int i = 0; i < n; i++) cin >> p[i] >> c[i];
for (int i = 0;... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int a;
cin >> s;
int count1 = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == 'a') count1++;
}
if (count1 > s.size() / 2) {
cout << s.size();
} else {
cout << (count1 * 2 - 1);
}
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, sophepthu;
cin >> sophepthu;
while (sophepthu--) {
cin >> n >> m;
if (n == 1)
cout << 0 << endl;
else if (n == 2)
cout << m << endl;
else
cout << m * 2 << endl;
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int c[1000007], n, m, ans[300005], maxi;
struct node {
int l, r, ind;
} a[1000007];
int lowbit(int x) { return x & -x; }
void modify(int x) {
while (x <= maxi) {
c[x]++;
x += lowbit(x);
}
}
int getsum(int x) {
int ans = 0;
while (x > 0) {
ans += c[x];
... | 14 |
#include <bits/stdc++.h>
int main() {
char a[15];
scanf("%s", a);
int q, c = 0;
int b = strlen(a);
for (int i = b - 1; i >= 0; i--) {
if (a[i] == '0') {
b = b - 1;
} else
break;
}
q = b;
if (b % 2 == 0) {
for (int j = 0; j < b / 2; j++) {
if (a[j] != a[q - 1]) {
c =... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int b = 230;
const int mod = 998244353;
long long pow2(long long a, long long b) {
long long ans = 1;
while (b) {
if (b % 2 == 1) ans = ans * a % mod;
a = a * a % mod;
b /= 2;
}
return ans;
}
vector<int> g[150005];
int par[18][150005];
int depth[15... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t != 0) {
string s;
int n;
cin >> n >> s;
int no_of_forward = 0;
int no_of_reverse = 0;
int result = 0;
for (int i = 0; i < n; i++) {
if (s[i] == '(') {
no_of_forward++;
} else {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
template <class T1>
void deb(T1 e1) {
cout << e1 << endl;
}
template <class T1, class T2>
void deb(T1 e1, T2 e2) {
cout << e1 << " " << e2 << endl;
}
template <class T1, class T2, class T3>
void deb(T1 e1, T2 e2, T3 e3) {
cout << e1 << " " << e2 << " " << e3 << endl;
... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 15;
bool v[N];
int p[N], tot, s, t, H[N];
vector<int> adj[N];
vector<pair<int, int> > ret;
int find(int x) { return x == p[x] ? x : p[x] = find(p[x]); }
void merge(int a, int b) {
a = find(a), b = find(b);
if (a > b) swap(a, b);
p[b] = a;
}
void df... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int M = 1000000007;
int main() {
long long int n, m, k;
long long int te;
cin >> n >> m >> k;
for (int i = 0; i < 4 * k; ++i) cin >> te;
string ans = "";
for (int i = 0; i < n - 1; ++i) ans += 'U';
for (int i = 0; i < m - 1; ++i) ans += 'L';
for (int i... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int a[N];
int cnt[N];
int last[N];
int main() {
int n, k;
scanf("%d %d", &n, &k);
for (int i = 0; i < n; i++) {
scanf("%d", a + i);
for (int j = 0; j < i; j++) {
cnt[abs(a[i] - a[j])]++;
}
}
int max_pair = (k + 1) * k / 2;
... | 16 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n, k;
string s;
cin >> n >> k >> s;
vector<vector<int>> g(k, vector<int>(200, 0));
for (int i = 0; i < n; i++) g[i % k][s[i]]++;
for (int i ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
multiset<int> s;
int mx = 0;
for (int i = 0; i < n; i++) {
int val;
cin >> val;
s.insert(val);
mx = max(mx, val);
}
for (int i = 1; i <= mx; i++) {
if (mx % i == 0) s.erase(s.find(i));
}
cout << mx << " " <... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int grid[n + 1][n + 1];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> grid[i][j];
}
}
bool good = false;
if (n == 1) {
if (grid[0][0] <= 1) {
good = true;
}
} else {
for (int ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, ans = 0;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 1; i < n; i++)
if (a[i - 1] == 1 && a[i + 1] == 1 && a[i] == 0) {
ans++;
a[i + 1] = 0;
}
cout << ans << endl;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
long long ans = 0;
for (int i = (0); i < (n); ++i) {
long long t, T, x, cost;
cin >> t >> T >> x >> cost;
if (t >= T) {
ans += cost + m * x;
continue;
}
long long aux1 = cost;
if (m > (T - t))... | 11 |
#include <bits/stdc++.h>
int main() {
int n, k, i, j;
long int m;
scanf("%d %d", &n, &k);
if (k > (n - 1) / 2) {
printf("-1");
} else {
m = n * k;
printf("%ld\n", m);
for (i = 0; i < n; i++) {
for (j = 1; j <= k; j++) {
printf("%d %d\n", i + 1, (i + j) % n + 1);
}
}
}... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 110;
int n;
char s[MAXN];
int main() {
scanf("%d", &n);
scanf("%s", s + 1);
int ans = n;
for (int i = 1; i <= n; i++) {
if (s[i] != s[i + 1] && i != n) {
ans--;
i++;
}
}
printf("%d\n", ans);
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
struct BiconnectedComponents {
const int NOT_VISITED = -1;
int V;
const vector<int>* aa;
int current_time;
vector<int> ot;
vector<int> low;
vector<bool> articulation;
vector<pair<int, int>> bridges;
BiconnectedComponents(int V, const vector<int> aa[])
... | 25 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n == 3)
cout << 7 << endl;
else {
if (n % 2 == 0) {
for (int i = 0; i < n / 2; i++) cout << 1;
} else {
cout << 7;
int x = (n - 3) / 2;
for (int i = 0; i < x; i++) cout << 1;
}
}
}
| 4 |
#include <bits/stdc++.h>
using namespace std;
struct Point {
double x, y;
Point(double x = 0, double y = 0) : x(x), y(y) {}
};
Point operator+(Point A, Point B) { return Point(A.x + B.x, A.y + B.y); }
Point operator-(Point A, Point B) { return Point(A.x - B.x, A.y - B.y); }
Point operator*(Point A, double p) { retu... | 11 |
#include <bits/stdc++.h>
using namespace std;
pair<pair<int, int>, int> p[100002];
bool isgood(int i, int j, int k) {
double x1 = p[i].first.first, x2 = p[j].first.first, x3 = p[k].first.first,
y1 = p[i].first.second, y2 = p[j].first.second, y3 = p[k].first.second;
if (x1 == x2 && x2 == x3) return false;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int S = 200003;
char buf[1000000], *p1, *p2;
inline char gc() {
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2)
? EOF
: *p1++;
}
inline int rd() {
register int f = 0;
register char c = gc();
while (c < 4... | 17 |
#include <bits/stdc++.h>
inline int read() {
register int x = 0;
register int y = 0;
register char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') y = 1;
c = getchar();
}
while (c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
return y ? -x : x;
}
int d, n, m;
int x[200006], p[2... | 14 |
#include <bits/stdc++.h>
int a[105];
int main() {
int n, i, ans = 0, pre = 0, flag = 0, s = 0;
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%d", &a[i]);
if (a[i] < 0) ans++;
if (ans >= 3) {
s++;
ans = 1;
}
}
printf("%d\n", s + 1);
ans = 0;
for (i = 1; i <= n; i++) {
i... | 2 |
#include <bits/stdc++.h>
using namespace std;
int dp[2000 + 1][2000 + 1];
int sp[2000 + 1];
char str[2000 + 10];
char *trim_line(char *str) { return strtok(str, "\r\n"); }
int addmod(int x, int y, int p) {
long long sum = x;
sum += y;
if (sum >= p) sum -= p;
return (int)sum;
}
int submod(int x, int y, int p) {
... | 17 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
ii solve(vector<vi> g) {
int n = g.size();
vector<int> depth(n, 0);
vector<int> leaf(n, true);
int mx = n - 1;
function<void(int, int)> dfs = [&](int u, int p) {
int cnt = 0;
for (aut... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long a3, b3, c3, d3;
void findIn(long long a1, long long b1, long long c1, long long d1,
long long a2, long long b2, long long c2, long long d2) {
a3 = max(a1, a2);
b3 = max(b1, b2);
c3 = min(c1, c2);
d3 = min(d1, d2);
}
bool valid(long long a, long... | 7 |
#include <bits/stdc++.h>
using namespace std;
using cd = complex<double>;
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;
for (; j & bit; bit >>= 1) j ^= bit;
j ^= bit;
if (i < j) swap(a[i], a[j]);
}
for ... | 18 |
#include <bits/stdc++.h>
using namespace std;
const int k = 300;
const int arr = 1e5 + 100;
vector<int> vec[arr];
vector<pair<int, int> > steck[arr / k + 10];
int too[arr][arr / k + 10], from[arr];
int get_ans(int l, int r, int x) {
for (int i = max(r / k * k, x) + 1; i <= r; i++) {
if (from[i] >= l && from[i] <=... | 22 |
#include <bits/stdc++.h>
using namespace std;
int dp1[155][11255], dp2[155][11255], a[155];
void upd1(int &x, int y) {
if (x < y) x = y;
}
void upd2(int &x, int y) {
if (x > y || x == -1) x = y;
}
int main() {
int n, k, s, i, j, l, loc, ans = 0, sum = 0;
cin >> n >> k >> s;
s = min(s, n * (n - 1) / 2);
for ... | 15 |
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
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(sd... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long mo = 1e9 + 7;
long long fpow(long long a, long long b, long long c) {
a %= c;
long long ans = 1;
while (b > 0) {
if (b & 1) ans = ans * a % c;
b >>= 1;
a = a * a % c;
}
return ans;
}
long long inv[105];
long long dp[50][10005];
long lon... | 14 |
#include <bits/stdc++.h>
using namespace std;
long long Mod(long long x, long long y, int p) {
long long res = 1;
x = x % p;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin... | 7 |
#include <bits/stdc++.h>
using namespace std;
char s[100], zero[100];
int main() {
int n;
scanf("%d", &n);
printf("1 0\n");
fflush(stdout);
scanf("%s", zero);
int l = 0, r = 1e9;
for (int i = 1; i < n; ++i) {
int mid = (l + r) >> 1;
printf("1 %d\n", mid);
fflush(stdout);
scanf("%s", s);
... | 11 |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> c[300005];
int n, x1, x2;
vector<int> check(int a, int b) {
bool flg = false;
int tmp, tmp2, l, l2, i = 0;
for (; i < n; i++) {
tmp = c[i].first;
l = (a + tmp - 1) / tmp;
if (i + l >= n) continue;
tmp2 = c[i + l].first;
l2 = (b + tmp... | 9 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int A, int B) {
if (B) return gcd(B, A % B);
return A;
}
double operating(long long x1, long long y1, long long x2, long long y2) {
return (x1 * y2) - (x2 * y1);
}
int main(int argc, const char* argv[]) {
double polygons[(int)1e5 + 10];
double p[(int)1e5 +... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500000;
char str[MAXN + 5];
int n, T;
int houses;
bool check(int k) {
int c, c2;
int rightmost;
for (rightmost = n - 1; rightmost >= 0; rightmost--)
if (str[rightmost] == 'H') break;
int shops = 0;
for (c = 0; c < n; c++) {
shops += str[c]... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char A[3][3];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
cin >> A[i][j];
}
}
if ((A[0][0] == A[2][2]) && (A[0][1] == A[2][1]) && (A[2][0] == A[0][2]) &&
(A[1][0] == A[1][2]))
cout << "YES";
else
cout << "NO... | 0 |
#include <bits/stdc++.h>
using namespace std;
int ar[200005], col[200005];
int cnt[200005];
int main() {
long long t, n, m, i, ans = 0, mx = 0, k;
cin >> n >> m >> k;
for (i = 0; i < n; i++) {
cin >> ar[i];
if (ar[i] <= m) {
mx++;
}
}
if (m > k)
cout << n << endl;
else
cout << (mx ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int diam, diamcv, center;
vector<int> g[100005];
void dfs(int x, int p, int d) {
if (d > diam) {
diam = d;
diamcv = x;
}
for (int i = 0; i < g[x].size(); i++)
if (g[x][i] != p) dfs(g[x][i], x, d + 1);
}
int dfs2(int x, int p) {
if (x == diamcv) return -d... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 12 + 100;
int n, m;
int a[maxn], b[maxn], c[maxn][maxn];
int main() {
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
c[i][a[i]]++;
for (int j = 1; j <= m; ++j) {
c[i][j] += c[i - 1][j];
}
}
int all = 0;
for (int i... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int N=1e6+5;
long long n,arr[N];
int solve() {
string s;
cin>>s;
char ss[2]={'(',')'};
for(int a=0;a<2;a++)
{
for(int b=0;b<2;b++)
{
for(int c=0;c<2;c++){
stack<char> st;
bool ok=1;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, k;
cin >> n >> k;
vector<vector<int>> a(5, vector<int>(55));
for (int i = 1; i <= 4; ++i) {
for (int j = 1; j <= n; ++j) {
cin >> a[i][j];
}
}
pair<int, int> cur = {2, 1};
int step ... | 13 |
#include <bits/stdc++.h>
using namespace std;
long long rain[3000];
pair<long long, long long> umb[3000];
long long dp[3000][3000];
int main() {
ifstream fin("input.txt", ios::in);
ios_base::sync_with_stdio(false);
cout << setprecision(10);
for (long long i = 0; i < 3000; i++) {
umb[i].first = 2000000000ll;... | 13 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> v[100005];
long long root(long long arr[], long long i) {
while (i != arr[i]) {
i = arr[arr[i]];
}
return i;
}
bool Find(long long a, long long b, long long arr[]) {
long long root_a = root(arr, a);
long long root_b = root(arr, b);
if (root... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int MAX_S = 100;
int n;
int f[MAX_S];
int fNr;
int v[MAX_S];
int main() {
int mNr;
cin >> n >> fNr >> mNr;
for (int i = 0; i < fNr; i++) cin >> f[i];
for (int i = 0; i < mNr; i++) {
int now;
cin >> now;
for (int j = 0; j < fNr; j++)
if (now %... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 500010;
int a[maxn], b[maxn], n;
int main() {
while (cin >> n) {
for (int i = 1; i <= n; i++) scanf("%d", a + i);
int flag = 0, ans = 0;
b[1] = a[1];
b[n] = a[n];
for (int i = 2; i < n; i++) {
b[i] = a[i - 1] + a[i] + a[i + 1] > ... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int N = 305, M = N * N, INF = 0x3f3f3f3f;
int n, own[M];
bool vis[M], G[N][N];
int Dfs(int x) {
for (int i = 1; i <= n; ++i)
if (G[x][i] && !vis[i]) {
vis[i] = 1;
if (!own[i] || Dfs(own[i])) {
own[i] = x;
return 1;
}
}
ret... | 21 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
mt19937_64 rng(
chrono::high_resolution_clock::now().time_since_epoch().count());
int t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
vector<string> v(n);
for (... | 7 |
#include <bits/stdc++.h>
using namespace std;
int n, nr_b;
struct numbers {
int nr;
int o, e;
};
numbers v[200005];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> v[i].nr;
v[i].e = v[i - 1].e;
v[i].o = v[i - 1].o;
if (i % 2 == 0)
v[i].e += v[i].nr;
else
v[i].o += v[... | 4 |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:100000000")
char s[100500];
int a[50], ind[50];
bool use[50];
bool cmp(int i, int j) { return a[i] < a[j]; }
int main() {
int i, j;
gets(s);
int k;
int l = strlen(s);
for (i = 0; i < l; ++i) a[s[i] - 'a']++;
scanf("%d", &k);
for... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const int M = 1e9 + 7;
const int MOD = 998244353;
const double PI = 3.141592653589793238460;
long long int power(long long int a, long long int b) {
long long int res = 1;
if (a == 0) return 0;
if (a == 1) return 1;
for (; b > 0; b >>= 1) {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e7 + 5;
struct bits {
int limits;
int c[maxn];
int lowbit(int x) { return x & -x; }
bits(int _l = 0) : limits(_l) {}
void init(int a) { limits = a; }
void add(int x, int d) {
for (int i = x; i < limits; i += lowbit(i)) {
c[i] += d;
... | 19 |
#include <bits/stdc++.h>
using namespace std;
const int inf_int = 1e8;
const long long inf_ll = 1e16;
const double pi = 3.1415926535898;
bool debug = 0;
const int MAXN = 2e5 + 100;
bool A[1001][10001];
void solve() {
int n, a, b;
cin >> n >> a >> b;
if (n == 2 || n == 3) {
if (a == 1 && b == 1) {
cout <... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
long long n;
cin >> n;
long long a = 1, b = 1;
string k;
for (long long i = 0; i < n; i++) {
cin >> k;
if (k == "UL" || k == "DR")
a++;
else if (k == "ULDR") {
a++;
b++;
} else... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
int x[100010];
int main() {
cin >> n >> k;
for (int i = 1; i < n + 1; ++i) {
if (k) {
cout << 2 * i << " " << 2 * i - 1 << " ";
--k;
} else
cout << 2 * i - 1 << " " << 2 * i << " ";
}
}
| 6 |
#include <bits/stdc++.h>
using namespace std;
string cc, aa;
int n;
int main() {
cin >> n;
cin >> cc >> aa;
int c = 0, a = 0, y = 0, m = 0;
for (int i = 0; i < n; i++) {
if (cc[i] == '0' && aa[i] == '1')
a++;
else if (cc[i] == '1' && aa[i] == '0')
c++;
else if (cc[i] == '1' && aa[i] == '... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 250005;
string s;
struct node {
int dep;
int mx;
int mi;
int lmx;
int rmx;
int ans;
} t[800005];
void pushup(int x) {
t[x].dep = t[x << 1].dep + t[x << 1 | 1].dep;
t[x].mx = max(t[x << 1].mx, t[x << 1 | 1].mx + t[x <... | 19 |
#include <bits/stdc++.h>
using namespace std;
int n, a[200005], f;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
for (int i = 0; i < n - 1 && !f; i++) {
a[i + 1] -= a[i] % 2;
if (a[i + 1] < 0) {
f = 1;
}
}
f |= a[n - 1] % 2;
printf("%s\n", f ? "NO"... | 3 |
#include <bits/stdc++.h>
using namespace std;
string name[16];
int nel[1000][2];
int n, m;
int num(int i) {
int kol = 0;
while (i > 0) {
if (i % 2 == 1) ++kol;
i /= 2;
}
return kol;
}
bool check(int ch) {
bool arr[16];
for (int i = 0; i < 16; ++i) arr[i] = 0;
int i = 0;
while (ch > 0) {
arr[... | 7 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void Min(T &a, T b) {
if (b < a) a = b;
}
const int N = (int)1e4 + 5;
int in[N], out[N];
long long dp[2][N];
int main() {
int n, m;
cin >> n >> m;
for (int i = (1), _t = (n + 1); i < _t; ++i) scanf("%d", &in[i]);
for (int i = (1), _t = (n... | 21 |
#include <bits/stdc++.h>
using namespace std;
long long f[10010];
int A[10010];
long long _Min(long long x, long long y) { return x < y ? x : y; }
int main() {
int n, c, i, j, x;
long long ans = (long long)1 << 60;
scanf("%d%d", &n, &c);
for (i = 1; i <= n; i++) scanf("%d", &A[i]);
for (i = 1; i <= n; i++) {
... | 21 |
#include<bits/stdc++.h>
// #define int long long
using namespace std;
const int M = 2650;
const int N = 1350;
int md;
inline void add(int& a, int b) {
a += b;
if (a >= md) a -= md;
}
inline int mul(int a, int b) {
return (a * 1ll * b) % md;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
... | 16 |
#include <bits/stdc++.h>
using namespace std;
struct point {
long long x, y;
};
int n;
int A[100009];
vector<point> X;
point B[100009];
inline bool cmpx(point a, point b) {
if (a.x == b.x) return a.y < b.y;
return a.x < b.x;
}
inline bool cmpy(point a, point b) {
if (a.y == b.y) return a.x < b.x;
return a.y <... | 14 |
#include <bits/stdc++.h>
using namespace std;
const int maxint = -1u >> 1;
template <class T>
bool get_max(T& a, const T& b) {
return b > a ? a = b, 1 : 0;
}
template <class T>
bool get_min(T& a, const T& b) {
return b < a ? a = b, 1 : 0;
}
const int maxn = 100000 + 5;
int n, m;
vector<int> adj[maxn];
int val[maxn]... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int x[m + 1];
for (int i = 0; i < m + 1; i++) x[i] = 0;
int f = 0;
for (int z = 0; z < n; z++) {
int a, b;
cin >> a >> b;
if (z == 0) {
if (a == 0) {
for (int i = a; i <= min(m, b); i++) x[i] = 1;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> adj[100007], cost[100007];
long long vis[100007], n, p, c, arr[100007], mafia[100007], parent[100007];
void dfs(long long node, long long tot = 0) {
vis[node] = 1;
for (long long i = 0; i < adj[node].size(); ++i) {
if (!vis[adj[node][i]]) {
p... | 8 |
#include <bits/stdc++.h>
static const int Infinity = 1e9;
static void add(std::vector<std::vector<int>> &v,
std::vector<std::vector<bool>> &used,
std::queue<std::pair<int, int>> &queue, int r, int c, int l,
int max) {
if (v[r][c] == Infinity || l > max) return;
if (v[... | 10 |
#include <bits/stdc++.h>
using namespace std;
struct point {
double x, y;
} p[111][3], A, B, C, D;
void prin(point A) { cout << A.x << " " << A.y << endl; }
double area(point a, point b, point c) {
return (((b.x - a.x) * (c.y - a.y)) - ((c.x - a.x) * (b.y - a.y))) / 2;
}
int ins(int tid, point po) {
double ret = ... | 15 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, da = 0, df = 0;
bool nb, na;
cin >> n;
if (n % 400 == 0 or (n % 4 == 0 and n % 100 != 0)) {
nb = true;
df = (da + 1) % 7;
} else
nb = false;
do {
++n;
da = (df + 1) % 7;
if (n % 400 == 0 or (n % 4 == 0 and n % 100 != 0... | 8 |
#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.1415926535897;
long long exp(long long base, long long power, int p) {
if (!base) return 0;
long long t = exp(base, power / 2, p);
if (power & 1)
return t * t * base % p;
else
return t * t % p;
}
void solve() {
string s;
cin >> s... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500010;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
for (; !isdigit(ch); ch = getchar())
if (ch == '-') f = -1;
for (; isdigit(ch); ch = getchar()) x = (x * 10) + (ch ^ 48);
return x * f;
}
int n, m, q, fa[MAXN];
int Hash[MAXN],... | 15 |
#include <bits/stdc++.h>
template <class X, class Y>
X& remin(X& x, Y y) {
return x = (y < x ? y : x);
}
const int NMAX = 2020, INF = (int)1e9;
int n, k, arr[NMAX], minK[NMAX][NMAX];
const bool debug = 0;
bool check(int x) {
std::fill(&minK[0][0], &minK[0][0] + NMAX * NMAX, INF);
minK[1][1] = 0;
for (int prefix... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2000000000;
const double EPS = 1e-9;
int mods(int a, int b) { return (b + (a % b)) % b; }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, x, y, ans = 0, a[26] = {};
string s;
cin >> n;
for (int i = 0; i < n; i++) ... | 1 |
#include <bits/stdc++.h>
using namespace std;
bool comp(pair<long long, long long> a, pair<long long, long long> b) {
return a.first < b.first;
}
pair<long long, long long> color(pair<long long, long long> a, long long m) {
return make_pair((a.second), (m - 1 - a.first));
}
pair<long long, long long> counter(pair<l... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long fuvk = 1e6;
vector<pair<long long, long long>> adj[fuvk];
void dijkstra(long long s, long long n) {
long long distance[n + 1], parent[n + 1];
bool processed[n + 1];
for (long long i = 1; i <= n; ++i) {
distance[i] = 1e18;
parent[i] = -1;
pr... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long n, long long m) {
if (m == 0)
return n;
else
return gcd(m, n % m);
}
int longestsub(string x, string y, int n, int m) {
int lcs[n + 1][m + 1];
int result = 0;
for (int i = 0; i < n + 1; i++) {
for (int j = 0; j < m + 1; j++) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
bool d[505][505];
int main() {
int n, m, c;
scanf("%d%d", &n, &m);
memset(d, 0, sizeof(d));
d[0][0] = 1;
for (int i = 1; i <= n; i++) {
scanf("%d", &c);
for (int j = m; j >= 0; j--) {
for (int k = j; k >= 0; k--) {
if (j >= c) {
d[j... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3000;
int n;
struct side {
int y, next;
} e[N * 2 + 9];
int lin[N + 9], cs;
void Ins(int x, int y) {
e[++cs].y = y;
e[cs].next = lin[x];
lin[x] = cs;
}
void Ins2(int x, int y) {
Ins(x, y);
Ins(y, x);
}
void into() {
scanf("%d", &n);
for (int i ... | 15 |
#include <bits/stdc++.h>
using namespace std;
int n, cnt;
int a[(100100)];
int f[(100100)][3];
pair<int, int> V[(100100)];
int Getpos(int pos, int k, int c) {
if (f[n][c] - f[pos][c] < k) return n + 1;
int l = pos + 1, r = n, mid;
while (l != r) {
mid = l + r >> 1;
if (f[mid][c] - f[pos][c] < k) {
l... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long spf[11];
long long fac[11];
void sieve() {
spf[1] = 1;
for (long long i = 2; i < 11; i++) spf[i] = i;
for (long long i = 4; i < 11; i += 2) spf[i] = 2;
for (long long i = 3; i * i < 11; i++) {
if (spf[i] == i) {
for (long long j = i * i; j < 11; ... | 12 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int MAXN = (int)3e5;
struct Query {
int r;
int pos;
bool operator<(const Query &other) const { return r < other.r; }
};
int arr[MAXN + 1];
vector<Query> qry[MAXN + 1];
int dp[MAXN + 1];
bool sol[MAXN + 1];
void divide(int l, int r) ... | 14 |
#include <bits/stdc++.h>
using namespace std;
int n, m, k;
int arr[100005];
int main() {
cin >> m;
for (int i = 0, x; i < m; i++) {
cin >> x;
if (i == 0) k = x;
k = min(k, x);
}
cin >> n;
for (int i = 0; i < n; i++) cin >> arr[i];
sort(arr, arr + n);
long long sum = 0, cur = 0;
for (int i = ... | 6 |
#include <bits/stdc++.h>
const int maxn = 50010, maxm = 50010, maxq = 50010;
int n, m, q, C, f[maxn], p[maxn], c[maxm];
struct edge {
int to;
edge* next;
} E[maxn], *fir[maxn];
int dep[maxn], siz[maxn], son[maxn], top[maxn];
void init(int i) {
siz[i] = 1;
for (edge* e = fir[i]; e; e = e->next) {
dep[e->to] ... | 23 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T>
ostream &operator<<(ostream &os, const ... | 13 |
#include <bits/stdc++.h>
using namespace std;
void striker() {
int x, y;
cin >> x >> y;
int a = abs(x) + abs(y);
if (x > 0 && y > 0)
cout << 0 << " " << a << " " << a << " " << 0;
else if (x > 0 && y < 0)
cout << 0 << " " << -a << " " << a << " " << 0;
else if (x < 0 && y > 0)
cout << -a << " " ... | 2 |
#include <bits/stdc++.h>
#pragma GCC target("sse4,avx")
struct point {
int x, y;
point() : x(0), y(0) {}
point(int x, int y) : x(x), y(y) {}
};
struct dpoint {
double x, y;
dpoint() : x(0), y(0) {}
dpoint(double x, double y) : x(x), y(y) {}
};
int area(point p1, point p2, point p3) {
return (p2.x - p1.x) ... | 18 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, vertex[22] = {0}, last = 1;
cin >> n;
vertex[1] = 1;
set<int> edges;
for (int i = 2; i <= n; i++) {
while (++last) {
bool norm = true;
for (int j = 1; j < i; j++)
if (edges.count(vertex[j] + last)) {
norm = fal... | 15 |
#include <bits/stdc++.h>
using namespace std;
class tree {
public:
int n;
vector<vector<int>> g;
vector<int> pv;
vector<int> depth;
vector<int> sz;
vector<int> order;
vector<int> pos;
vector<int> end;
int root;
int h;
vector<vector<int>> anc;
tree(int _n) : n(_n) {
g.resize(n);
root = -... | 14 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
void solve(void);
int main(void) {
int t;
scanf("%d", &t);
while (t--) solve();
return 0;
}
void solve(void) {
scanf("%d%d", &n, &m);
if ((n * m) % 2)
printf("%d\n", n * m / 2 + 1);
else
printf("%d\n", n * m / 2);
}
| 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.