solution stringlengths 53 181k | difficulty int64 0 13 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3003;
const int maxm = 3003;
const int maxq = 4e5 + 18;
int n, m, q;
int16_t F[maxn][maxn][13];
bool vs[maxn];
bool can_reach[maxn][maxn];
vector<int> adj[maxn];
vector<int> radj[maxn];
void Input() {
cin >> n >> m >> q;
for (int i = 1; i <= m; i++) {
... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int maxLength = 5;
char prev = 'A';
int ans = 0;
for (int i = 0; i < s.length(); i++) {
if (s[i] != prev) {
maxLength = 5;
ans++;
prev = s[i];
} else {
maxLength--;
prev = s[i];
if (max... | 0 |
#include <bits/stdc++.h>
using namespace std;
template <typename Tp>
inline void read(Tp &x) {
static char c;
static bool neg;
x = 0, c = getchar(), neg = false;
for (; !isdigit(c); c = getchar()) {
if (c == '-') {
neg = true;
}
}
for (; isdigit(c); c = getchar()) {
x = x * 10 + c - '0';
... | 11 |
#include <bits/stdc++.h>
using namespace std;
long long mod_pow(long long x, long long n, long long modd) {
long long res = 1;
while (n > 0) {
if (n & 1) res = res * x % modd;
x = x * x % modd;
n >>= 1;
}
return res;
}
long long inv2, inv22;
template <typename T>
void fwt(vector<T>& f) {
int n = f... | 8 |
#include <bits/stdc++.h>
using namespace std;
char s[500009];
int n, k;
char f(int x, int y) {
char cc = 'A' + (k - 1);
for (char c = 'A'; c <= cc; c++) {
if (c != s[x] && c != s[y]) return c;
}
return '0';
}
int main() {
int i, j, m, d, test, t = 0;
while (scanf("%d%d", &n, &k) == 2) {
scanf("%s", ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, i, j, a[307];
int main() {
cin >> n;
for (i = 0; i < n; i++) cin >> a[i];
if (a[0] > 0) cout << "P";
for (i = 1; i < a[0]; i++) cout << "RLP";
cout << "R";
for (i = 1; i < n; i++) {
if (a[i] > 0) cout << "P";
for (j = 1; j < a[i]; j++) cout << "LR... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int base = 131;
const int MOD = 1e9 + 7;
const long long MM = 1ll * MOD * MOD;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
void AddMOD(int &x, int y) {
x += y;
if (x >= MOD) x -= MOD;
}
int Gcd(int x, int y) {
if (y == 0) return x;
re... | 4 |
#include <bits/stdc++.h>
using namespace std;
int a[100005];
int main() {
int n, x, i, zz, zzz;
scanf("%d%d", &n, &x);
int z = 0;
if (n > 2) {
int k = 0;
while (1) {
z = 0;
for (i = 0; i < n - 2; i++) {
z ^= (i + k);
}
zz = 1 << 18;
i = 0;
while (1) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void show(const vector<T> &a) {
for (T x : a) cout << x << " ";
cout << '\n';
}
vector<long long> xx = {1, 0, -1, 0};
vector<long long> yy = {0, 1, 0, -1};
string dir = "LRUD";
const long long N = 2e5 + 50, oo = 3e18 + 500;
const long long mod = 1e9 +... | 4 |
#include <bits/stdc++.h>
using namespace std;
int f[100][100];
int main() {
f[0][0] = 1;
f[0][1] = 1;
f[0][2] = 1;
f[0][3] = 1;
f[0][4] = 1;
f[0][5] = 1;
f[0][6] = 1;
f[0][7] = 0;
f[0][8] = 1;
f[0][9] = 0;
f[0][10] = 1;
f[0][11] = 0;
f[0][12] = 1;
f[0][13] = 0;
f[0][14] = 1;
f[0][15] = 1... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1000000000ll;
const long long inf64 = inf * inf;
const long long base = inf + 7;
bool solve() {
int n;
scanf("%d", &n);
vector<int> x(n + 1);
for (int i = 1; i <= n; i++) {
scanf("%d", &x[i]);
}
sort(x.begin() + 1, x.end());
int ans =... | 7 |
#include <bits/stdc++.h>
using namespace std;
const int mn = 210;
const long double zero = 1e-7;
int hp1, dt1, l1, r1, p1, L;
int hp2, dt2, l2, r2, p2, t1, t2;
double f1[mn], f2[mn], ans;
bool atk(double* f, int l, int r, int p) {
int i, j;
double w;
bool res = 0;
for (i = 1; i <= L; ++i) {
if (f[i] < zero)... | 8 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-10;
struct Point {
double x, y;
Point() {}
Point(double _x, double _y) : x(_x), y(_y) {}
Point operator+(const Point &p) { return Point(x + p.x, y + p.y); }
Point operator-(const Point &p) { return Point(x - p.x, y - p.y); }
Point operator*... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1111;
const int INF = 1000 * 1000 * 1000;
int dx[] = {0, 0, -1, 1};
int dy[] = {-1, 1, 0, 0};
string s[N];
int d[N][N];
queue<pair<int, int> > q;
int n, m;
bool good(int i, int j) {
if (i < 0 || i >= n || j < 0 || j >= m) return false;
return s[i][j] != 'T... | 3 |
#include <bits/stdc++.h>
using namespace std;
int p[105];
int main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int a, b, c;
cin >> a >> b >> c;
p[a] += c;
p[b] -= c;
}
int ans = 0;
for (int i = 1; i <= n; i++) {
if (p[i] > 0) ans += p[i];
}
cout << ans << endl;
retur... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
char s[4000006];
cin >> (s);
int l = strlen(s);
int inc = (l - 1) / n;
for (int i = 0; i < l; i++) {
if (i + 2 < l - 1) {
if (i % n == n - 3) {
if (s[i] != s[i + 1] || s[i + 1] != s[i + 2]) {
inc--;
... | 2 |
#include <bits/stdc++.h>
using namespace std;
signed main(void) {
std::ios::sync_with_stdio(false);
cin.tie(NULL);
long long int t = 1;
cin >> t;
while (t--) {
long long int n;
cin >> n;
vector<long long int> h(n);
long long int cnt = 0;
for (long long int i = 0; i < n; i++) {
cin >>... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long x, y, z, t1, t2, t3;
cin >> x >> y >> z >> t1 >> t2 >> t3;
long long d1 = abs(x - y);
long long ans1 = d1 * t1;
long long ans2 = abs(x - z) * t2 + 2 * t3 + abs(x - y) * t2 + t3;
if (ans1 >= ans2) {
cout << "YES\n";
} else {
cout ... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
struct node {
int id;
long long x, y;
} data[maxn];
int ans[maxn];
int main() {
srand(time(NULL));
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
cin >> data[i].x >> data[i].y;
data[i].id = i;
}
while (true) {
... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long int countSetBits(long long int n) {
if (n == 0)
return 0;
else
return (n & 1) + countSetBits(n >> 1);
}
int main() {
long long int s, x;
cin >> s >> x;
if (x > s || (s - x) % 2) {
cout << 0 << "\n";
return 0;
}
if ((s - x) / 2 & x) {
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, f;
string a;
cin >> n >> k;
vector<string> names(n);
for (int i = 0; i < n; ++i) {
names[i].push_back(rand() % 25 + 65);
f = rand() % 9 + 1;
for (int j = 0; j < f; ++j) names[i].push_back(rand() % 25 + 97);
}
for (int i = 0; ... | 3 |
#include <bits/stdc++.h>
bool local = false;
using namespace std;
template <class T>
void print(T v) {
cout << ((int)(v).size()) << "\n";
for (auto x : v) cout << x << ' ';
cout << "\n";
};
template <class T>
void print1(T v) {
cout << ((int)(v).size()) << "\n";
for (auto x : v) cout << x + 1 << ' ';
cout <... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long t, n, x, y, l, r;
char a[200000 + 5];
map<long long, long long> Map;
long long read() {
char c;
long long x = 0, f = 1;
c = getchar();
while (c > '9' || c < '0') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = (x... | 3 |
#include <bits/stdc++.h>
using namespace std;
int ans;
int val;
int operate = 1;
string s;
int main() {
cin >> s;
for (char c : s) {
if (c == '+' || c == '-') {
ans += val * operate;
operate = (c == '+') ? 1 : -1;
val = 0;
}
val = val * 10 + (c - '0');
}
ans += val * operate;
pri... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cout.tie(0);
cin.tie(0);
srand(time(NULL));
int n, i, j;
cin >> n;
vector<int> v(n);
for (i = 0; i < n; i++) {
cin >> v[i];
}
for (i = 0; i < n; i++) {
long long sum = 0;
for (j = 0; j < v[i]; j++) {... | 0 |
#include <bits/stdc++.h>
using std::cerr;
using std::cin;
using std::cout;
bool MEMST;
const long long N = 5e6 + 5;
long long n, P, f[N], g[N], sum[N];
bool MEMED;
signed main() {
std::ios::sync_with_stdio(false), std::cin.tie(nullptr);
cin >> n >> P;
f[1] = 1;
for (long long i = 1; i <= n; ++i) {
g[i] = (g... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long n, k;
int main() {
cin >> n >> k;
long long a[n + 1], dp[n + 1], ans;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
sort(a + 1, a + n + 1);
long long l = 0, r = 1e9, mid;
while (r - l >= 0) {
memset(dp, 0, sizeof(dp));
for (int i = 0; i <... | 5 |
#include <bits/stdc++.h>
using namespace std;
int t[3000050], len, st, n, m, p, a[3000050], ans, f[3000050];
bool b[3000050];
bool Is_Prime(int x) {
for (int i = 2; i * i <= x; i++)
if (x % i == 0) return 0;
return 1;
}
void DFS(int x, int y) {
if (!y) {
t[++len] = x;
return;
}
DFS(x, y - 1);
fo... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<pair<double, double> > V;
set<pair<double, double> > S;
for (int i = 0; i < n; i++) {
double x, y;
cin >> x >> y;
V.push_back(make_pair(x, y));
S.insert(make_pair(x, y));
}
int f = 0;
for (int i = 0; i < n... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int cnt = 0;
int r = 0;
int n;
int k;
cin >> n >> k;
string sr;
int r1 = 0;
for (; n != 0; n--) {
vector<int> arr(k + 1);
r1++;
cin >> sr;
int i = 0;
for (i = 0; sr[i] != '\0'; i++) {
if (sr[i] - '0' <= k) {
arr... | 1 |
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[1000006];
int n, m;
bool used[1000006];
map<pair<int, int>, int> got;
void go(int x) {
if (used[x]) return;
used[x] = 1;
int i;
for (i = 0; i < adj[x].size(); i++) go(adj[x][i]);
}
int main() {
cin >> n >> m;
int i, j;
for (i = 0; i < m; i++) {... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long s, x;
cin >> s >> x;
if ((s - x) & 1 || s - x < 0) {
cout << "0" << endl;
return 0;
}
long long k = (s - x) >> 1;
long long tmp = x;
long long cnt = 0;
while (tmp) {
cnt++;
tmp = tmp >> 1;
}
long long ans = 1;
for... | 4 |
#include <bits/stdc++.h>
constexpr int N = 200003;
int n, m, len, num[N << 1], nxt[N << 1];
char s1[N], s2[N], S[N << 1];
void mg() {
memcpy(S + 1, s2 + 1, m), S[m + 1] = '$';
memcpy(S + 2 + m, s1 + 1, n);
len = n + m + 1;
}
void getnxt(char s[], int n) {
nxt[1] = 0;
for (int i = 2; i <= n; i++) {
int j =... | 9 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::duration_cast<chrono::nanoseconds>(
chrono::high_resolution_clock::now().time_since_epoch())
.count());
const long int N = 1000005;
const long int LG = 22;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
c... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const long long mod = 1e6 + 3;
long long qpow(long long x, long long y) {
long long ret = 1;
while (y) {
if (y & 1) ret = ret * x % mod;
x = x * x % mod;
y >>= 1;
}
return ret;
}
int main() {
long long n, k;
scanf("%I64d%I64d",... | 7 |
#include <bits/stdc++.h>
using namespace std;
const long long modn = 1000000007;
inline long long mod(long long x) { return x % modn; }
template <class num>
inline void rd(num &x) {
char c;
while (isspace(c = getchar()))
;
bool neg = false;
if (!isdigit(c))
neg = (c == '-'), x = 0;
else
x = c - '0... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 500003;
int n, a[maxn], f[20][maxn], g[20][maxn], Log[maxn];
long long ans = 0;
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 =... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
scanf("%d", &t);
while (t-- > 0) {
string a;
cin >> a;
string b = "";
if (a.length() <= 2) {
cout << a << endl;
continue;
}
for (int i = 0; i < a.length(); i = i + 2) b += a[i];
b = b + a[a.length() - 1];
... | 0 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> v[3005];
long long par[3005];
long long n;
long long dp[3005][3005];
long long M = 1e9 + 7;
long long power(long long a, long long b, long long mod) {
long long x = 1, y = a;
while (b > 0) {
if (b % 2) {
x = (x * y) % mod;
}
y = (y * ... | 9 |
#include <bits/stdc++.h>
using namespace std;
template <typename... T>
void scan(T &...args) {
((cin >> args), ...);
}
template <typename... T>
void print(T... args) {
((cout << args), ...);
}
class Solution_To_Problem {
int r, g, b, m, ans;
array<int, 3> count;
public:
void solution_function() {
scan(r... | 1 |
#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
void Max(T1 &a, T2 b) {
a = max(a, (T1)b);
}
template <typename T1, typename T2>
void Min(T1 &a, T2 b) {
a = min(a, (T1)b);
}
template <int MOD>
struct ModInt {
unsigned x;
ModInt() : x(0) {}
ModInt(signed sig) : x(sig) {}
Mod... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, sx, sy, x, y;
cin >> n >> sx >> sy;
vector<pair<long long int, long long int> > vp;
for (int i = 0; i < n; i++) {
cin >> x >> y;
vp.push_back(make_pair(x, y));
}
long long int r1 = 0, r2 = 0, r3 = 0, r4 = 0;
for (int i = 0... | 2 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<pair<int, int> > G[100010];
int d[100010];
vector<int> t[100010];
inline int read_int() {
int t = 1, x = 0;
char ch = getchar();
while (!isdigit(ch) && ch != '-') ch = getchar();
if (ch == '-') t = -1, ch = getchar();
while (isdigit(ch)) {
x =... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = (1 << 15) + 100;
int n, m;
string cur, prv;
int d[maxn], c[maxn], head[maxn];
int ans;
string num(char c) {
string ret = "";
int x;
x = c >= 'A' ? c - 'A' + 10 : c - '0';
for (int i = 8; i; i /= 2)
if (x & i)
ret += '1';
else
ret... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, p, q;
scanf("%d%d%d%d", &n, &m, &p, &q);
if (q < 0) {
if (n < m) {
puts("DRAW");
return 0;
}
p *= -1;
q *= -1;
swap(p, q);
int d = n - m;
if (d % (p + q) >= p && d % (p + q) <= q) {
printf("FIRST\n%d... | 8 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void r1(T &x) {
x = 0;
char c(getchar());
int f(1);
for (; !isdigit(c); c = getchar())
if (c == '-') f = -1;
for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
x *= f;
}
const int maxn = 1000 + 5;
const int maxm = 25;
bo... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
cout << max(m, n) - 1 << " " << min(m, n);
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
vector<int> Ans;
const int N = 111;
int n, m, Memo[N][N];
map<int, string> Msg;
map<int, string> idUser;
map<string, int> userId;
inline bool isAc(char c) {
return (c == '.' || c == ',' || c == '!' || c == '?' || c == ' ');
}
inline bool isValid(int msg, int id) {
strin... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
double b;
cin >> n >> b;
vector<int> array(n);
vector<double> ans(n);
for (int i = 0; i < n; ++i) {
cin >> array[i];
}
int _max = *max_element(array.begin(), array.end());
int _min = 0;
for (int i = 0; i < n; ++i) {
if (array[... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
;
cin.tie(nullptr);
char ch;
bool flag1, flag2, flag, flag3, flag4;
flag3 = flag4 = false;
int i, len, cnt = 0, tmp, j;
string s, tmps, num, str;
cin >> s;
len = s.size();
s += ';', len++;
num = str = tmps = ... | 4 |
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsi... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 2e9;
int daq(string& s, char c, int l, int r, vector<int>& amount) {
if (l == r) {
amount[s[l] - 'a'] = 1;
return s[l] == c ? 0 : 1;
}
vector<int> la(26, 0), ra(26, 0);
int mid = (l + r) / 2;
int ans, lmin = daq(s, c + 1, l, mid, la),
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int a[20], b[5][5], s, dif[20], cnt[20], n, t;
void dfs(int x, int y) {
if (y == n + 1) {
cout << s << endl;
for (int i = 1; i <= n; i++, cout << endl)
for (int j = 1; j <= n; j++) cout << b[i][j] << " ";
exit(0);
}
int nx = x + 1, ny = y;
if (nx =... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const long long mod = 1000000007;
int basis[N][20], basis_sz[N];
long long pw2[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cout << setprecision(32);
int n, q, l, x;
cin >> n >> q;
memset(basis, -1, sizeof(... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int N = 6001;
long long b[N], a[N];
int vis[N];
char str[N];
int s[N];
long long sum(int l, int r) {
if (l > r) return 0;
long long ans = 0;
for (int k = l; k <= r; k += 2) b[k] = 0, vis[k] = 0;
for (int k = l; k <= r; k += 2) {
if (b[k] == 0) {
b[k]... | 6 |
#include <bits/stdc++.h>
using namespace std;
int n, maxx, dp[300], co[300];
char s[300];
int main() {
scanf("%d", &n);
cin >> (s + 1);
for (register int i = 1; i <= n; i++) {
dp[i] = 1;
for (register int j = 1; j <= i - 1; j++)
if (s[j] > s[i]) {
dp[i] = max(dp[i], dp[j] + 1);
maxx ... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, j, party, total, cnt, A[110], alice, flag;
vector<int> v;
scanf("%d", &n);
total = 0;
for (i = 0; i < n; i++) {
scanf("%d", &A[i]);
total = total + A[i];
}
party = A[0];
alice = A[0];
v.push_back(1);
cnt = 1;
flag = 0;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
long long tt(long long a) {
if (a == 1 || a == 2) {
return 0;
}
if (a == 3) {
return 1;
}
long long k = 0;
long long l = 1;
while (3 * l <= a) {
l *= 3;
k++;
}
return k;
}
string Three(long long a) {
long long x = tt(a);
string m = "";
... | 1 |
#include <bits/stdc++.h>
using namespace std;
bool inD(int x, int y, int r1, int r, int d, bool v) {
double dist = sqrt(double(x) * x + y * y);
if (v) {
printf("dist = %lf\n", dist);
printf("dist + r1 = %lf\n", dist + r1);
printf("dist - r1 = %lf\n", dist - r1);
printf("r = %lf\n", double(r));
p... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
while (cin >> n) {
char ben[10];
cin >> ben;
int cnt = 0;
for (int i = 0; i < n; i++) {
char t[10];
cin >> t;
bool win = true;
for (int j = 0; j < 3; j++) {
if (ben[j] != t[j]) {
win = false;
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10, mod = 1e9 + 7;
int T, n, t, fla = -1;
int a[maxn];
vector<int> q[60];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
t = a[i];
for (int j = 1; t > 0; j++) {
if (t % 2 == 1) q[j].push_back(i);... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long len(long long x, long long y) { return x * x + y * y; }
long long scal(long long x1, long long y1, long long x2, long long y2) {
if (x1 * y2 == x2 * y1) return -1;
return x1 * x2 + y1 * y2;
}
bool in(long long x1, long long y1, long long x2, long long y2, long... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, arr[60], c = 0, ans = 1e9, x = 0;
memset(arr, 0, sizeof(arr));
string s;
cin >> n >> s;
set<char> st;
for (int i = 0; i < n; ++i) {
st.insert(s[i]);
}
c = st.size();
... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int* arr = new int[n];
int a = 0;
for (int i = 0; i < n; i++) {
char temp;
cin >> temp;
if (temp == '(') {
a++;
} else {
a--;
}
arr[i] = a;
}
if (a != 0) {
cout << 0 << endl << 1 << " " << 1... | 8 |
#include <bits/stdc++.h>
using namespace std;
struct SegmentTree {
struct Op {
int h;
};
int l;
int r;
int h;
SegmentTree* lc;
SegmentTree* rc;
bool lazy;
Op op;
SegmentTree(int ll, int rr) {
lazy = false;
l = ll;
r = rr;
h = 0;
if (l == r) return;
int m = (l + r) / 2;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
string s;
bool good[4][4], bad[4][4];
long long ab, ans, a[705], b[705], dp[705][705][3][3];
long long dfs(int l, int r, int x, int y) {
if (l >= r) return 1;
if (dp[l][r][x][y] != -1) return dp[l][r][x][y];
dp[l][r][x][y] = 0;
if (a[l] == r... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long fact[500010], inv[500010];
long long NCR(long long N, long long r) {
if (r > N) return 0;
return (fact[N] * inv[r] % mod) * inv[N - r] % mod;
}
long long pow_mod(long long base, long long power) {
long long res = 1;
while ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = (long long)1 << 62;
const long long MOD = 1e9 + 7;
const int iINF = 1 << 30;
const double PI = 3.14159265359;
vector<vector<int> > adj;
vector<int> dp[2][2];
vector<bool> vis[2][2];
void dfs(int u, int p, int gp, int par) {
dp[p][gp][u] = 1;
for (i... | 6 |
#include <bits/stdc++.h>
using namespace std;
inline int read(int x = 0, int f = 1, char ch = '0') {
while (!isdigit(ch = getchar()))
if (ch == '-') f = -1;
while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
return f * x;
}
const int N = 2e6 + 5;
int n, m, tot;
int head[N], ver[N << 1], nxt[N << 1];
i... | 7 |
#include <bits/stdc++.h>
using namespace std;
struct student {
int st, en, id;
};
bool cmp(student a, student b) {
if (a.st == b.st)
return a.id < b.id;
else
return a.st < b.st;
}
int main() {
int n, k;
int t;
cin >> t;
for (int i = 1; i <= t; i++) {
cin >> n;
student arr[1005];
for (i... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int arr[100000];
int freq[8];
for (int i = 0; i <= 7; i++) freq[i] = 0;
bool failed = 0;
for (int i = 0; i < n; i++) {
cin >> arr[i];
if (arr[i] == 5 || arr[i] == 7) {
failed = 1;
break;
}
freq[arr[i]]+... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e3 + 7;
int n, k, a, b, c, d;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k >> a >> b >> c >> d;
if (n == 4 || k < (n + 1)) {
cout << -1 << "\n";
return 0;
}
vector<int> r1, r2;
r1.push_back(a);
r1.push_back(c);
f... | 4 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, d, np = 0, ans = 0;
cin >> n >> d;
string s;
cin >> s;
for (int i = 0; i < n;) {
int k = -1;
for (int j = ((i + d) < n ? i + d : n - 1); j > i; j--)
if (s[j] == '1') {
k = j;
break;
}
if (k == n - 1) {
... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000000 + 20;
int xor_n[maxn];
int p[maxn];
int n;
int q;
void init() {
xor_n[0] = 0;
for (int i = 1; i < maxn; i++) {
xor_n[i] = i ^ xor_n[i - 1];
}
}
int main() {
init();
while (~scanf("%d", &n)) {
q = 0;
for (int i = 1; i <= n; i++)... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int MAXBUF = 10000;
char buf[MAXBUF], *ps = buf, *pe = buf + 1;
inline bool isdigit(const char& n) { return (n >= '0' && n <= '9'); }
inline void rnext() {
if (++ps == pe)
pe = (ps = buf) +
fread(buf, sizeof(char), sizeof(buf) / sizeof(char), stdin);
}
... | 7 |
#include <bits/stdc++.h>
using namespace std;
bool ask(vector<int> vt) {
printf("? %d ", (int)vt.size());
for (int i = 0; i < vt.size(); i++) printf("%d ", vt[i]);
printf("\n");
fflush(stdout);
int x;
scanf("%d", &x);
return x;
}
int id[3][5][7][8], ans[1005];
pair<int, int> num[11];
vector<int> vt[10];
b... | 13 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 1488;
string s;
long long n, k, chl = 1;
string one() {
string s2 = s;
chl = 0;
for (long long i = 0; i < n; i++) {
long long e0 = s[(i - 1 + n) % n] == 'W' ? 1 : 0;
long long e1 = s[i] == 'W' ? 1 : 0;
long long e2 = s[(i + 1) % n... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b;
cin >> a >> b;
if (a != b) cout << 1;
if (a == b) cout << a;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int n, two, r, now, ans, l;
char c[1000005];
bool three;
int main() {
scanf("%d ", &n);
gets(c);
now = '1' + '0' - c[0];
for (int i = 0; i < n; i++) {
if (c[i] == now) {
r++;
} else {
now = '1' + '0' - now;
r = 1;
ans++;
}
if ... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long city[1001][1001], n, m, lr, gr, lc, gc;
vector<long long> c[1001], r[1001];
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
scanf("%I64d", &city[i][j]);
r[i].push_back(city[i][j]);
c[j].push_back(... | 4 |
#include <bits/stdc++.h>
using namespace std;
struct tree {
tree* l;
tree* r;
long long cnt;
tree() {
l = NULL;
r = NULL;
cnt = 0;
}
};
tree* top = new tree();
void add(long long x) {
tree* cur = top;
for (long long i = 29; i >= 0; i--) {
if (x & (1 << i)) {
if (!cur->r) cur->r = new... | 5 |
#include <bits/stdc++.h>
using namespace std;
long long cnt[200005] = {0};
int main() {
long long n;
cin >> n;
cnt[1] = 10;
long long sum1 = 10, sum2 = 0, sum3 = 0;
for (long long i = 2ll; i <= n; i++) {
sum1 *= 10ll;
sum1 %= 998244353;
sum2 += 2ll * cnt[i - 1ll];
sum2 %= 998244353;
sum2 +... | 5 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
ll r, g, b, ans;
int main() {
cin >> r >> g >> b;
if (max(r, max(g, b)) >= 2 * (r + g + b - max(r, max(g, b))))
ans = r + g + b - max(r, max(g, b));
els... | 5 |
#include <bits/stdc++.h>
using namespace std;
int n, m, Max, Min, d = 0;
int a[101];
int main() {
cin >> n >> m >> Min >> Max;
for (int i = 0; i < m; i++) {
cin >> a[i];
if (a[i] != Min && a[i] != Max) d++;
}
if (d > n - 2) {
cout << "Incorrect" << endl;
return 0;
}
for (int i = 0; i < m; i+... | 2 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 300005, OO = 1110111110111, mod = 1000000007,
mod2 = 998244353;
long long n, a[N], sol;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
long long acc = 0, ... | 5 |
/*
Author: QAQAutoMaton
Lang: C++
Code: C1.cpp
Mail: lk@qaq-am.com
Blog: https://www.qaq-am.com/
*/
#include<bits/stdc++.h>
#define debug(qaq...) fprintf(stderr,qaq)
#define DEBUG printf("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define Debug debug("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define all... | 9 |
#include <bits/stdc++.h>
using namespace std;
int parent[100000];
bool inSet[100000];
set<int> children[100000];
bool respect[100000];
set<int> canDel;
int main() {
int N;
cin >> N;
for (int i = 0; i < N; i++) {
inSet[i] = true;
cin >> parent[i];
if (parent[i] != -1) {
parent[i]--;
childre... | 3 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int main() {
cin >> n >> m;
if (m > 2 * (n + 1) or n > m + 1) {
cout << -1 << endl;
return 0;
}
while (n or m) {
if (m >= 2 && !(n > m - 1)) {
cout << 11;
m -= 2;
} else if (m != 0 && !(n > m)) {
cout << 1;
m -= 1;
... | 3 |
#include <bits/stdc++.h>
using namespace std;
long long comp(long long c) {
long long ans = c;
if (ans % 2 == 0) {
ans /= 2;
ans *= (c + 1);
} else {
ans *= ((c + 1) / 2);
}
return ans;
}
long long worker() {
int n, m;
scanf("%d%d", &n, &m);
vector<int> pid(n + 1);
int i;
for (i = 0; i <... | 5 |
/*
Author : Prathamesh Wagh
*/
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
int MOD = 998244353;
#define int long long
#define dbg(x) cout<<#x<<" = "<<x<<"\n"
#define pb push... | 0 |
#include <bits/stdc++.h>
using namespace std;
const int N = 66;
int c[1 << 16];
void cc() {
int m = 1 << 16, i, j;
for (i = 0; i < m; i = i + 1)
for (j = 1; j < m; j = j + j)
if (i & j) c[i]++;
}
int cnt(long long x) {
if (!x) return 0;
return c[(long long)x & 65535] + cnt(x >> 16);
}
int n, m, a[N], ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 200000 + 5;
int minst[N][27];
int maxst[N][27];
int n;
void inst() {
for (int j = 1; (1 << j) <= n; j++) {
for (int i = 1; i + (1 << j) - 1 <= n; i++) {
minst[i][j] = min(minst[i][j - 1], minst[i + (1 << (j - 1))][j - 1]);
maxst[i][j] = max(m... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
for (int i = 1000000000; i >= 1; i = i / 10) {
int temp = n / i;
if (temp > 0) {
int ans = (temp + 1) * i;
printf("%d\n", ans - n);
break;
}
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 2000;
inline long long read() {
register long long s = 0;
register bool neg = 0;
register char c = getchar();
for (; c < '0' || c > '9'; c = getchar()) neg |= (c == '-');
for (; c >= '0' && c <= '9'; s = s * 10 + (c ^ 48), c = getchar())
;
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 100100;
const long long AA = 1000000;
long long n;
long long num[MAXN];
long long snum[MAXN];
long long nused[MAXN];
long long loc[MAXN];
long long l[2 * MAXN], r[2 * MAXN];
bool lucky(long long x) {
while (x > 0) {
if ((x % 10 != 4) && (x % 10 ... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long fact[200010];
long long fpow(long long a, int b) {
if (b == 0) return 1;
long long tmp = fpow(a, b / 2);
tmp = (tmp * tmp) % 1000000007;
if (b % 2 == 0) return tmp;
return (a * tmp) % 1000000007;
}
long long binomial(int a, int b) {
if (b > a || b < 0 ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9;
const long long N = 3e3 + 1;
const long long mod = 1e7 + 9;
const long double eps = 1E-7;
int ans;
int n, a[N];
int x, y, mx;
void dfs(int v) {
y = max(y, a[v]);
if (v * 2 >= mx) return;
a[v * 2] += a[v];
a[v * 2 + 1] += a[v];
dfs(v * 2)... | 3 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:128777216")
const long long LINF = 1000000000000000000LL;
const int INF = 1000000000;
const long double eps = 1e-9;
const long double PI = 3.1415926535897932384626433832795l;
using namespace std;
void prepare(string s) {
if (s.length() != 0) {
freopen((s + ... | 4 |
#include <bits/stdc++.h>
template <typename T>
void scan(T &x) {
x = 0;
register bool _ = 0;
register T c = getchar();
_ = c == 45;
c = _ ? getchar() : c;
while (c < 48 || c > 57) c = getchar();
for (; c < 48 || c > 57; c = getchar())
;
for (; c > 47 && c < 58; c = getchar()) x = (x << 3) + (x << 1)... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double left, right;
double a, b;
scanf("%lf%lf", &a, &b);
left = a - b;
right = a + b;
if (left < 0) {
cout << "-1\n";
return 0;
}
if (left == 0) {
printf("%lf\n", a);
return 0;
}
if (left < 2 * b) {
printf("%lf\n", right... | 4 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.