solution stringlengths 53 181k | difficulty int64 0 27 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int l = 1;
int r = n;
int i = 1;
int cnt = 0;
while (l < r) {
if (i % 2 == 1)
l++;
else
r--;
cnt++;
}
cout << cnt / 2;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
int n, h;
long long dp[36][36], res;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
;
dp[0][0] = 1;
for (int cnt = 1; cnt <= 35; cnt++) {
for (int height = 1; height <= cnt; height++) {
for (int root = 1; root <= cnt; root++) {
long long ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int arr[n];
for (int i = 0; i < n; ++i) {
cin >> arr[i];
}
sort(arr, arr + n);
int diff = arr[1] - arr[0];
for (int i = 1; i < n - 1; ++i) {
if (arr[i + 1] - arr[i... | 0 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return a % b == 0 ? b : gcd(b, a % b); }
int main() {
int n;
cin >> n;
cout << n + n / 2 << endl;
if (n % 2 == 1) {
for (int i = 2; i <= n; i += 2) {
cout << i << ' ';
}
for (int i = 1; i <= n; i += 2) {
cout << i << '... | 8 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long n;
cin >> n;
vector<long long> q(21, 0);
for (long long i = 0; i < n; i++) {
long long a;
cin >> a;
q[a + 10]++;
}
long long ans = 0;
for (long long i = 0; i < 10; i++) ans += ... | 4 |
#include <bits/stdc++.h>
using namespace std;
set<long long> s;
long long a[300005];
bool maximum(long long k, long long n) {
if (k > 0 && a[k] < a[k - 1]) {
return 0;
}
if (k < n - 1 && a[k] < a[k + 1]) {
return 0;
}
return 1;
}
bool minimum(long long k, long long n) {
if (k == n - 1 || k == 0) {
... | 13 |
#include<iostream>
using namespace std;
int main()
{
int arr[1000],arr1[1000],x,y,t,c=0,i,j;
cin >> t;
while(t--)
{
cin >> x >> y;
for(i=0;i<x;i++)
{
cin >> arr[i];
}
for(i=0;i<y;i++)
{
cin >> arr1[i];
}
for(i=0;i<x;... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (a % b == 0) {
return b;
} else
return gcd(b, a % b);
}
int T;
vector<long long> primes;
long long a, m;
long long ans;
long long l, r;
long long cnts(long long fac) { return r / fac - (l - 1) / fac; }
void fenjie(lon... | 10 |
#include <bits/stdc++.h>
using namespace std;
inline bool checkBit(long long n, int i) { return n & (1LL << i); }
inline long long setBit(long long n, int i) {
return n | (1LL << i);
;
}
inline long long resetBit(long long n, int i) { return n & (~(1LL << i)); }
int dx[] = {0, 0, +1, -1};
int dy[] = {+1, -1, 0, 0};... | 11 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = mod * mod;
const long double eps = 1e-5;
const long double pi = acos(-1.0);
void solve() {
vector<int> v[10];
int n;
cin >> n;
string s;
cin >> s;
for (int i = 0; i < n; i++) {
v[s[i] - '0'].push_back(i... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false), cin.tie(nullptr);
using ll = long long;
int n, K;
cin >> n >> K;
auto add = [&](vector<ll>& dp, int cost, ll wgt) -> void {
int r = (int)dp.size();
for (int i = r - 1 - cost; i >= 0; i--) {
dp[i + cost] ... | 20 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> m(101, vector<int>(5, -1));
int main() {
int n;
cin >> n;
int a;
cin >> a;
m[0][0] = 1;
if (a == 1)
m[0][1] = 0;
else if (a == 2)
m[0][2] = 0;
else if (a == 3) {
m[0][1] = 0;
m[0][2] = 0;
}
for (int i = 1; i < n; i++) ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 4;
const int mod = 1e9 + 7;
long long modularExponentiation(long long x, long long n, long long mod) {
long long result = 1;
while (n > 0) {
if (n % 2 == 1) result = (result * x) % mod;
x = (x * x) % mod;
n = n / 2;
}
return result;
}... | 4 |
#include <bits/stdc++.h>
using namespace std;
double pie = 3.14159265358979323846;
long long int M = 1e9 + 7, N, An = 0;
string s1, s2;
long long int recur(long long int l, long long int r, long long int a[]) {
long long int j, x = (l + r) / 2;
if (l > r) return 0;
string st = s1;
for (j = 0; j < x; j++) {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
void solve() {
long long n;
cin >> n;
string a, b;
cin >> a >> b;
vector<long long> ans;
for (long long i = n - 1; i >= 0; i--) {
if... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long max(long long x, long long y) { return x > y ? x : y; }
long long min(long long x, long long y) { return x < y ? x : y; }
void _(long long& a, long long b) {
a = (a % 1000000007 + b % 1000000007) % 1000000007;
a = (a + 1000000007) % 1000000007;
}
long long n;
... | 12 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T _abs(T n) {
return (n < 0 ? -n : n);
}
template <class T>
T _max(T a, T b) {
return (!(a < b) ? a : b);
}
template <class T>
T _min(T a, T b) {
return (a < b ? a : b);
}
template <class T>
T sq(T x) {
return x * x;
}
template <class T>
T gcd(T a... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const int N = 3010;
char s[N], t[N];
int n, m;
int f[N][N];
bool check(int i, char ch) {
if (i > m) return true;
return ch == t[i];
}
int main() {
scanf("%s%s", s + 1, t + 1);
n = strlen(s + 1);
m = strlen(t + 1);
for (int i = 1; i <= ... | 14 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long MAXN = 1e6 + 5;
const long long INF = (1ll << 31);
const double PI = 3.14159265359;
int n, x, ans, a[MAXN];
map<int, int> u;
int main() {
ios_base::sync_with_stdio(false);
cin >> n;
for (int i = 1; i <= n; ++i) {
cin ... | 4 |
#include <bits/stdc++.h>
using namespace std;
char s[25];
int main() {
scanf("%s", s);
int len = strlen(s);
set<string> Set;
string p;
for (int i = 0; i <= len; ++i) {
if (i) p = p + s[i - 1];
for (int j = 0; j < 26; ++j) {
string tag = p;
tag = tag + (char)(j + 'a');
for (int k = i;... | 1 |
#include <bits/stdc++.h>
using namespace std;
int z, o;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
cin >> z >> o;
if (!(z <= o + 1 && o <= 2 * (z + 1))) {
cout << -1;
} else if (z == o || z == o + 1) {
for (int i = 0; i < z + o; ++i) {
cout << i % 2;
}
} else {
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int dp[200005][3];
vector<int> adj[200005];
void dfs(int x, int p) {
int min2 = 1e6;
for (int y : adj[x]) {
if (y == p) continue;
dfs(y, x);
dp[x][0] += dp[y][1];
dp[x][2] += min(dp[y][0], dp[y][2]);
min2 = min(min2, dp[y][0] - min(dp[y][0], dp[y][2]... | 13 |
#include <bits/stdc++.h>
using namespace std;
const int P = 1e9 + 9;
int add(int a, int b) {
if ((a += b) >= P) a -= P;
return a < 0 ? a + P : a;
}
int mul(int a, int b) { return 1ll * a * b % P; }
int kpow(int a, int b) {
int r = 1;
for (; b; b >>= 1, a = mul(a, a)) {
if (b & 1) r = mul(r, a);
}
return... | 17 |
#include <bits/stdc++.h>
const int N = 5e5 + 5;
int A[N];
char IN[500000], *SS = IN, *TT = IN;
inline int read() {
int now = 0;
register char c =
(SS == TT && (TT = (SS = IN) + fread(IN, 1, 500000, stdin), SS == TT)
? EOF
: *SS++);
for (; !isdigit(c);
c = (SS == TT && (TT = (SS ... | 16 |
#include <bits/stdc++.h>
using namespace std;
long long int xo(long long int x, long long int y) {
return (x | y) & (~x | ~y);
}
long long int bin_Expo(long long int x, long long int n) {
if (x == 0) return 0;
if (n == 0)
return 1;
else if (n % 2 == 0)
return bin_Expo(x * x, n / 2);
else
return x ... | 13 |
#include <bits/stdc++.h>
using namespace std;
int d[300005], x[300005], fa[300005], tf[300005];
int head[300005], nxt[600005], v[600005], tot = 0, ans = 0, n, m;
bool p[300005], vis[300005];
inline void add(int a, int b) {
tot++;
nxt[tot] = head[a];
head[a] = tot;
v[tot] = b;
}
inline int read() {
int x = 0, ... | 13 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
double a, b, m;
cin >> a >> b >> m;
double vx, vy, vz;
cin >> vx >> vy >> vz;
double x = a / 2, y = m, z = 0;
for (long long i = 0; i < 1e5; ++i) {
double reqdt = -y / vy;
if (vx > 0) {
reqdt = min(reqdt, (a - x) / vx);
} else if... | 9 |
#include <bits/stdc++.h>
using namespace std;
int n, q, blk;
int a[1000010], org[1000010], frq[1000010];
int tot = 0;
namespace fastio {
int ptr, ye;
char temp[25], str[32333667], out[15333667];
void init() {
ptr = 0, ye = 0;
fread(str, 1, 32333667, stdin);
}
inline int number() {
int i, j, val = 0;
while (str[... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
set<int> st;
for (int i = 0; i < n; i++) {
int t;
cin >> t;
st.insert(t);
}
auto it = st.begin();
it++;
if (it != st.end())
cout << (*it);
else
cout << "NO";
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 15;
long long a[maxn];
vector<unsigned long long> vv[15];
int main() {
unsigned long long n, k;
cin >> n >> k;
unsigned long long cnt = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
int t = int(log10(a[i]) + 1);
vv[t].push_back(a[i... | 11 |
#include <bits/stdc++.h>
using namespace std;
vector<int> mat[1005];
bool flag[1005];
int main() {
int len;
memset(flag, false, sizeof(flag));
scanf("%d", &len);
for (int i = 2; i <= len; i++) {
int nouse;
scanf("%d", &nouse);
mat[nouse].push_back(i);
}
for (int i = 1; i <= len; i++) {
if (m... | 4 |
#include <bits/stdc++.h>
inline long long read() {
long long res = 0, bo = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') bo = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
res = (res << 1) + (res << 3) + ch - '0';
ch = getchar();
}
return bo * res;
}
templa... | 20 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5, M = 1e3 + 5, mo = 1e9 + 7;
int n, a[N], i, cnt, pd[N], x;
int main() {
scanf("%d", &n);
for (i = 1; i <= n; i++) scanf("%d", a + i);
for (i = 1; i <= n; i++)
if (!pd[i]) {
x = i;
while (1) {
pd[x] = 1;
x = a[x];
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long int N = 100010;
const long long int MOD = 1000 * 1000 * 1000 + 7;
long long int mod(long long int n) { return (n % MOD + MOD) % MOD; }
bool comp(pair<int, pair<int, int> > a, pair<int, pair<int, int> > b) {
if (a.second.second > b.second.second)
return... | 7 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
using rl = double;
using pii = pair<int, int>;
const int MAXN = 5009;
const int modd = 1000 * 1000 * 1000 + 7;
int n;
char s[MAXN];
int add(int a, int b) {
a += b;
if (a >= modd) a -= modd;
return a;
}
int mult(int a, i... | 16 |
#include <bits/stdc++.h>
using namespace std;
const int MOD(1000000007);
const int INF((1 << 30) - 1);
const int MAXN();
int main() {
int n, neg = 0, zero = 0, MIN = INF, sum = 0;
scanf("%d", &n);
for (int i = 0; i < 2 * n - 1; i++) {
int x;
scanf("%d", &x);
neg += (x < 0);
zero += (x == 0);
M... | 10 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void cetak(T t) {
cout << t << ')' << endl;
}
template <typename T, typename... V>
void cetak(T t, V... v) {
cout << t;
if (sizeof...(v)) cerr << ", ";
cetak(v...);
}
const int MOD = 1e9 + 7;
const int mx = 1e5 + 10;
string ss, k[mx];
int n, m[... | 17 |
#include <bits/stdc++.h>
using namespace std;
int n, cnt, arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 11,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 11,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 11,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 11};
int m... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long A[5], ans = 0;
int main() {
cin >> A[0] >> A[1] >> A[2];
sort(A, A + 3);
long long s = 1e10;
if (A[2] >= (A[1] + A[0]) * 2) s = A[1] + A[0];
ans = min((A[0] + A[1] + A[2]) / 3, s);
cout << ans;
return 0;
}
| 10 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, k;
cin >> n;
int a[n];
for (int i = 0; i < n; i = i + 1) cin >> a[i];
int max1 = 0, min1 = 1001;
for (int i = 0; i < n - 1;) {
if (i < n - 2 && a[i + 2] > a[i + 1])
max1 = a[i + 2], i += 2;
else
max1 = a[i + 1], i ... | 3 |
#include <bits/stdc++.h>
using namespace std;
int a[5];
signed main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
int x;
scanf("%d", &x);
a[x]++;
}
int tot = a[1] + a[2] * 2 + a[3] * 3 + a[4] * 4;
if (a[1] == 0 && a[2] == 2 && a[3] == 0 && a[4] == 0) {
printf("2");
return 0;... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t, n;
cin >> t;
while (t--) {
cin >> n;
if (n == 1 || n == 0) {
cout << "0" << endl;
} else {
if (n & 1) {
cout << n / 2 << endl;
} else {
cout << n / 2 - 1 << endl;
}
}
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 511;
long long f[2][N][N];
struct node {
int a, b, k;
} a[N];
int n;
long long ans = 0;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d %d %d", &a[i].a, &a[i].b, &a[i].k);
}
sort(a + 1, a + n + 1,
[](const node& a, c... | 18 |
#include <bits/stdc++.h>
using namespace std;
bool more(string curr, string tmp) {
if (tmp.size() > curr.size()) return true;
if (tmp.size() == curr.size() && tmp[0] - '0' > curr[0] - '0') return true;
return false;
}
int main() {
string st;
cin >> st;
vector<string> v;
v.push_back("yummy");
int last = ... | 9 |
#include <bits/stdc++.h>
using namespace std;
struct grana {
int v, f, dir, id;
};
int n, m;
basic_string<grana> e[200005];
int ans[200005];
int unknown[200005], excess[200005];
bool inq[200005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cerr.tie(nullptr);
cin >> n ... | 13 |
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
long long gcd(long long a, long long b) { return (!b ? a : gcd(b, a % b)); }
long long lcm(long long a, long long b) { return ((a * b) / gcd(a, b... | 8 |
#include <bits/stdc++.h>
long long dp[2][2];
int main() {
char start[2 * 1005], end[1005];
int i, j, k, K;
while (scanf("%s %s %d", start, end, &K) != EOF) {
memset(dp, 0, sizeof(dp));
int n = strlen(start);
for (i = n; i < 2 * n; i++) start[i] = start[i - n];
dp[0][0] = 1;
int cur = 1;
lo... | 9 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1050;
int res[N][N];
int ptr;
void add_edge(int u, int v) { res[u][v] = res[v][u] = 1; }
void endd() {
cout << ptr << "\n";
for (int i = 0; i < ptr; ++i) {
for (int j = 0; j < ptr; ++j) {
cout << "NY"[res[i][j]];
}
c... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5040;
char s1[N], s2[N];
int num[30], a[N][30];
multiset<int> st;
int gao(int now) {
multiset<int>::reverse_iterator it;
for (it = st.rbegin(); it != st.rend(); it++) {
if ((*it) > s2[now] - 'a') {
return 1;
} else if ((*it) < s2[now] - 'a') ... | 11 |
#include <bits/stdc++.h>
using namespace std;
bool o;
char ch, ss[1 << 17], *A = ss, *B = ss;
inline char gc() {
return A == B && (B = (A = ss) + fread(ss, 1, 1 << 17, stdin), A == B) ? EOF
: *A++;
}
template <typename _Tp>
inline void rd(_Tp &x... | 19 |
#include <bits/stdc++.h>
int trie[100005][27];
char ch[100005];
int dfs(int n) {
if (n == -1) return 1;
int f1 = 0, f2 = 0, f3 = 0, f4 = 0;
int sum = 0;
for (int i = 1; i <= 26; i++) {
if (trie[n][i] == -1) continue;
sum++;
int res = dfs(trie[n][i]);
if (res == 1) {
f1 = 1;
} else if (... | 11 |
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 100000;
const int RMAX = 320;
int N, Q, ans[NMAX + 2][RMAX], BUCK = 317;
int v[NMAX + 2];
int DIN(int p, int k) {
if (p > N) return 0;
if (ans[p][k] != 0) return ans[p][k];
return ans[p][k] = 1 + DIN(p + v[p] + k, k);
}
int main() {
cin.tie();
ios... | 12 |
#include <bits/stdc++.h>
using namespace std;
long long M = 1000003;
long long bigmod(long long B, long long P) {
if (P == 0) return 1;
if (P % 2 == 0) {
long long ret = (bigmod(B, P / 2) % M);
return ((ret % M) * (ret % M)) % M;
} else
return ((B % M) * (bigmod(B, P - 1) % M)) % M;
}
int main() {
s... | 4 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const int maxN = 110000;
int n, a[maxN];
const int maxD = 350;
int l[maxN], r[maxN];
bool comp(int x, int y) {
return make_pair(l[x] / maxD, r[x]) < make_pair(l[y] / maxD, r[y]);
}
int order[maxN];
int res[maxN];
int cnt[maxN];
... | 19 |
#include <sstream>
#include <cmath>
#include <bits/stdc++.h>
#define int long long int
#define vec vector<int>
#define vecv vector<vec>
#define vecs vector<string>
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fton() for(int i=0;i<n;i++... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
cin >> n;
cout << n / 2 + 1;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
struct P {
int x, y;
};
bool operator<(const P& a, const P& b) {
if (a.x * a.y < b.x * b.y)
return true;
else
return (a.x < b.x);
}
int main() {
int A, B, i, j;
bool flag;
char ch[30];
string str;
char ch1[30][30], ch2[30][30], ch3[30][30];
vector<... | 10 |
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr int N = 1e5 + 5;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int a, b, c;
cin >> a >> b >> c;
int res = 0;
res += min(b, c / 2);
b -= min(b, c / 2);
res += min(a... | 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target( \
"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
using namespace std;
template <typename T1, typename T2>
void ckmin(T1 &a, T2 b) {
if (a > b) a = b;
}
template <typename T1, typename T... | 18 |
#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int INF = 0x3f3f3f3f;
int n, m, useless;
int a[100010], b[100010];
int unhappy = 0;
int match[100010], cnt[100010];
int dp[2][2];
int main() {
scanf("%d%d%d%d", &n, &m, &useless, &useless);
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long int t;
cin >> t;
while (t--) {
long int n, d, i, j, k, count;
cin >> n;
long int a[n], b[n];
for (i = 0; i < n; i++) cin >> a[i];
for (i = 0; i < n; i++) cin >> b[i];
sort(a, a + n);
sort(b, b + n);
for (i = 0; i < n; ... | 0 |
#include <bits/stdc++.h>
using namespace std;
int a[223456];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
int ans = -1;
for (int i = 1; i <= n; i++) {
for (int j = i; j <= n; j++) {
int p = a[j], x = 1;
int y = 0;
for (int u = a[i] - 1, k = i; k <= j; k++)
... | 18 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, k = 0;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
string s;
cin >> s;
int mx = 0;
for (int i = 0; i < n - 1; i++) {
mx = max(a[i], mx);
if (mx > i + 1 && s[i] == '0') {
cout << "NO" << endl;
... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long x;
int n;
cin >> n;
long long min;
set<long long> ans;
vector<long long> trueAns(n);
vector<long long> qArr(n - 1);
vector<long long> table(n, 0);
for (int i = 0; i < qArr.size(); i++) {
cin >> qArr[i];
}
for (int i = 1; i < ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
char arr[100][100];
cin >> n >> m;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) cin >> arr[i][j];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (arr[i][j] == '.') {
if ((i + j) % 2 == 0... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, tot = 0, i, j, k, o[30], g[30], f[30];
void U(int x, int a, int b, int c) {
if (x > n) return;
int i;
U(x + 1, a, c, b);
for (i = 1; i <= o[x]; i++) printf("%d %d\n", a, b);
U(x + 1, c, b, a);
return;
}
void C(int x, int a, int b, int c) {
int i;
if (... | 17 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int MOD = 1e9 + 7;
int dp[N][2], p[N];
vector<int> v;
string t, s;
void KMP(string s) {
p[0] = 0;
int n = (int)s.size();
for (int i = 1, k = 0; i < n; i++) {
while (k > 0 && s[i] != s[k]) k = p[k - 1];
if (s[i] == s[k]) k++;
p[... | 12 |
#include <bits/stdc++.h>
using namespace std;
int readl() {
int x = 0, fg = 1;
char ch = getchar();
while (ch > '9' || ch < '0') {
if (ch == '-') fg = -fg;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
return fg * x;
}
int m, n, a... | 13 |
#include <bits/stdc++.h>
using namespace std;
const long long siz = 1e5 + 5, len = (1 << 7) + 10;
long long t, n, p, m, k, a[siz], pos[siz], dp[siz][len], skill[siz][7];
bool cmp(long long x, long long y) { return a[x] > a[y]; }
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >>... | 15 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 5;
int dp[N][N];
int ispal[N][N];
string s;
int main() {
cin >> s;
for (int len = 1; len <= s.length(); len++)
for (int i = 0, j = i + len - 1; j < s.length(); i++, j++) {
if ((len < 3 && s[i] == s[j]) || (s[i] == s[j] && ispal[i + 1][j - 1... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int c = 300002;
int n, m, ans;
vector<int> sz[c][2];
int be[c], fel[c], tav[c], utveg;
queue<int> q;
vector<int> ut, ut2, ut3;
int hely[c][2], kom[c];
bool v[c][2];
bool jo[c];
void dfs(int a, int s, int ki) {
v[a][s] = true, hely[a][s] = ki;
for (int x : sz[a][s]... | 21 |
#include <bits/stdc++.h>
using namespace std;
int i, j, k, l, n, m, p, x, t, y, num, a[34], b[34], u, flag, q[34];
bool f[34][34][50010], tot[34][34][50010];
int add(int x, int y) {
if (y >= 10)
x *= 100;
else
x *= 10;
x = (x + y) % p;
return x;
}
int main() {
scanf("%d%d", &n, &p);
f[0][0][0] = 1;
... | 21 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200;
int N, L;
int a[MAXN], sgn[MAXN];
int main() {
string s, t;
cin >> s;
sgn[L++] = 1;
while (cin >> s) {
cin >> t;
if (s == "+")
sgn[L++] = 1;
else if (s == "-")
sgn[L++] = -1;
else {
N = atoi(t.c_str());
}
... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3c3c3c3c;
const long long LINF = 1ll * INF * INF * 2;
const int N = 1000001;
int n;
int x[N], y[N];
int a, b, c, d, p, q;
int main(void) {
scanf("%d%d%d", &n, &p, &q);
for (int i = 0; i < n; i++) scanf("%d%d", x + i, y + i);
for (int i = 0; i < n; i+... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFF = 0x3f3f3f3f3f3f3f3fll;
const int MAX = 1e5 + 5;
const int MAX_N = MAX;
const long long MOD = 998244353;
const long double pi = acos(-1.0);
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
template <typename T>
inline ... | 11 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x = 0;
cin >> n;
int A[n], B[n];
for (int i = 1; i < n; i++) {
cin >> A[i];
if (A[i] == 0) i--;
}
for (int i = 1; i < n; i++) {
cin >> B[i];
if (B[i] == 0) i--;
}
for (int i = 1; i < n; i++)
if (A[i] == B[1]) {
x... | 5 |
#include <bits/stdc++.h>
int main() {
char s[50];
gets(s);
int i, j;
int acount = 0;
int n = strlen(s);
for (i = 0; i < strlen(s); i++) {
if (s[i] == 'a') {
acount++;
}
}
if (acount <= n) {
while (acount <= n / 2) {
n = n - 1;
}
}
printf("%d\n", n);
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n, S, k, cnt[100010], flag, x, y;
int K, first[200010], last[200010], a[200010], ne[200010];
char ch;
void read(int &digit) {
int QAQ;
digit = 0;
ch = getchar();
while ((ch < '0' || ch > '9') && (ch != '-')) ch = getchar();
if (ch == '-') {
QAQ = -1;
c... | 10 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
const int MOD = 1000000007;
int a[100001];
pair<int, int> g[100001];
int res[100001];
int main() {
int n, h;
cin >> n >> h;
for (int i = 1; i <= n; ++i) cin >> a[i], g[i] = make_pair(a[i], i);
sort(g + 1, g + n + 1);
sort(a + 1, a + n +... | 10 |
#include <bits/stdc++.h>
using namespace std;
const long long infl = 1e18 + 5;
long long int n, m, k, q, x, y, f, val, t = 1, i, j;
long long int ind = -1, cnt, sz, sm, ans, mx = -1, mn = infl;
int dp[102][102][28][2];
vector<pair<int, int> > v[102];
int rec(int x, int y, int c, int t) {
if (dp[x][y][c][t] != -1) ret... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 204800;
int N, v[maxn];
int R[maxn], L[maxn];
int out[maxn];
int main() {
scanf("%d", &N);
for (int i = 1; i <= N; ++i) {
scanf("%d", v + i);
}
multimap<int, int> st;
for (int i = 1; i <= N; ++i) {
for (auto it = st.upper_bound(v[i]); it !... | 11 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int v;
int id;
} e[(int)1e5 + 1000];
bool cmp(node a, node b) { return a.v < b.v; }
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
scanf("%d", &e[i].v);
e[i].id = i;
}
sort(e + 1, e + 1 + n, cmp);
vector<int> V1, V2;
lon... | 7 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T POW(T B, T P) {
if (P == 0) return 1;
if (P & 1)
return B * POW(B, P - 1);
else
return SQR(POW(B, P / 2));
}
template <typename T>
inline T BigMod(T b, T p, T m) {
if (p == 0) return 1;
if (p % 2 == 0) {
T s = BigMod(b, p... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
const int maxm = 260;
int n, m;
int bit[maxn];
char str[maxn];
set<int> s[maxm];
inline int lowbit(int& x) { return x & (-x); }
int sum(int i) {
int res = 0;
while (i > 0) {
res += bit[i];
i -= lowbit(i);
}
return res;
}
void add(int... | 13 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
const int N = 2019;
char m[N][N];
int f[N], d[N];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%s", m[i]);
int ans = 0;
for (int i = 0; i < n; i++) {
int inv = 0;
for (int j = n - ... | 12 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1E6 + 10;
const int mod = 1E9 + 7;
int a[maxN];
int main() {
ios::sync_with_stdio(false);
long long n, x, y;
cin >> n >> x >> y;
if (n > y || (y - n + 1) * (y - n + 1) + (n - 1) < x) {
cout << -1 << endl;
return 0;
}
cout << (y - n + 1) ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200001;
int n, k, cnt;
int head[N], fa[N], size[N];
long long p[N][6], tot[N][6], f[N][5], ftot[N][5], ans;
struct xint {
int to, next;
} e[N * 2];
void add(int x, int y) {
e[++cnt] = (xint){y, head[x]};
head[x] = cnt;
e[++cnt] = (xint){x, head[y]};
... | 13 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
int a[n];
bool f = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
if (a[i] % 2) f = 1;
}
if (f == 0)
printf("Second");
else
printf("First");
}
| 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int inf = 1e9 + 1;
const int mod = 1e9 + 7;
const double eps = 1e-15;
const int pw = 257;
int n, k, a[N];
set<pair<int, int> > s, S;
int main() {
ios_base ::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> k;
for (int i = 1; i <= n - 1... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e4 + 10;
int main() {
int n, m;
cin >> n >> m;
int ans = 0;
while (n > 1 and m > 1) {
if (n > m) {
n -= 2;
m -= 1;
ans++;
} else {
m -= 2;
n -= 1;
ans++;
}
}
if (n == 1 and m > 1) ans++;
if (m =... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x20202020;
const int mod = 1000000007;
template <class T>
inline void read(T& x) {
bool fu = 0;
char c;
for (c = getchar(); c <= 32; c = getchar())
;
if (c == '-') fu = 1, c = getchar();
for (x = 0; c > 32; c = getchar()) x = x * 10 + c - '0';... | 18 |
#include <bits/stdc++.h>
using namespace std;
char s[410];
int m, len, n, f[210][210][410], t1, t2, t3, tot, ans;
struct Matrix {
int r, c;
int a[410][410];
void clean() { memset(a, 0, sizeof(a)); }
} A, c, t;
int DFS(int l, int r, int x) {
int res = 0;
if (f[l][r][x] != -1) return f[l][r][x];
if (l == r)
... | 22 |
#include <bits/stdc++.h>
using namespace std;
int n, peo, tmp, now, len, cnt, t[25], num[25][205][15];
char ch[15], name[25][15];
bool check(int a, int b) {
int lena = strlen(name[a] + 1), lenb = strlen(name[b] + 1);
if (lena != lenb) return false;
for (int i = 1; i <= lena; i++)
if (name[a][i] != name[b][i])... | 6 |
#include <bits/stdc++.h>
using namespace std;
vector<int> bV;
const long long MOD = 1000000007;
const int MAXN = 200010;
long long F[MAXN], I[MAXN];
long long bigMod(long long a, long long b) {
if (b == 0) return 1;
if (b % 2 == 0) {
long long ret = bigMod(a, b / 2);
return (ret * ret) % MOD;
}
return (... | 13 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long int n, d, i, j, y = 0;
cin >> n >> d;
map<long long int, long long int> a;
for (i = 0; i < n; i++) {
cin >> j;
a[j]++;
y = max(y, j);
}
if (a[d] > 0)
cout << "1\n";
else {
cout << max(2LL, (d - 1 + y) / y) << "\n";
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<char> arr(n, 0);
for (int i = 0; i < 4; i++)
for (int j = i; j < n; j += 4) {
arr[j] = 'a' + i;
}
string str(arr.begin(), arr.end());
cout << str << '\n';
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int t, n, m;
vector<int> g[200200];
int col[200200];
void color(int c, bool cv) {
col[c] = cv;
for (int i : g[c]) {
if (col[i] != -1) continue;
color(i, !cv);
}
}
void print(vector<int> &a) {
printf("%d\n", (int)a.size());
for (int i : a) printf("%d ", i +... | 9 |
#include <bits/stdc++.h>
using namespace std;
int mod;
long long powmod(long long a, long long b) {
long long res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
}
return res;
}
const int N = 1010;
long long dp[N][20], pd[N][20], f[N], t[20];
int ... | 19 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, hehe, ans;
cin >> n >> m;
ans = 1;
hehe = 3;
while (n > 0) {
if (n % 2 == 1) ans = (ans * hehe) % m;
n /= 2;
hehe = (hehe * hehe) % m;
}
cout << (ans - 1 + m) % m << endl;
return 0;
}
| 6 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e2 + 17;
const int MOD = 1e9 + 7;
int main(int argc, char const *argv[]) {
int T;
cin >> T;
while (T--) {
string s;
cin >> s;
int n0 = 0, n1 = 0, n = s.length();
vector<int> vz(s.length() + 2, 0);
for (size_t i = 0; i < n; i++) {
... | 6 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.