solution stringlengths 53 181k | difficulty int64 0 13 |
|---|---|
#include <bits/stdc++.h>
using namespace std;
int t, a[1001][1001], d[1001][1001];
int check(int v) {
if (v % 3 == 2 || v == 2) return 2;
if (v % 3 == 1 || v == 1) return 1;
if (v % 3 == 0) return 3;
}
int main() {
cin >> t;
for (int i = 1; i <= t; ++i) {
int n, one = 0, two = 0, cnt = 0;
cin >> n;
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int di[4] = {-1, 1, 0, 0};
int dj[4] = {0, 0, 1, -1};
int main() {
int n, m, k;
cin >> n >> m >> k;
vector<vector<int> > a(n);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
char c;
cin >> c;
if (c == '.') {
a[i].push_back(... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
char a[1005];
int dp[1005];
dp[0] = 1;
cin >> n >> a;
for (int i = 1; i < n; i++) {
if (a[i - 1] == '=')
dp[i] = dp[i - 1];
else if (a[i - 1] == 'R')
dp[i] = dp[i - 1] + 1;
else if (dp[i - 1] > 1) {
dp[i] = 1;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 2e9;
const long long MB = 20;
const long long MOD = 998244353;
const long long maxN = 1e7 + 1;
vector<vector<long long>> g;
vector<bool> used;
vector<long long> h, pr;
long long n, m, k, q = -1, st = -1;
void dfs(long long v) {
used[v] = true;
for ... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, rt, delta, now, limit, m;
int weight[N], sz[N], value[N];
pair<int, int> p[N];
vector<int> a[N];
template <typename T>
inline void chkmax(T &x, T y) {
x = max(x, y);
}
template <typename T>
inline void chkmin(T &x, T y) {
x = min(x, y);
}
... | 9 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int main() {
long long fib[100005];
fib[0] = fib[1] = 1;
for (int i = 2; i <= 100000; ++i) {
fib[i] = (fib[i - 1] + fib[i - 2]) % MOD;
}
int n, m;
scanf("%d%d", &n, &m);
printf("%I64d\n", 2LL * (fib[n] + fib[m] + MOD - 1) ... | 4 |
#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void pn(Arg1&& arg1) {
cout << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void pn(Arg1&& arg1, Args&&... args) {
cout << arg1 << " ";
pn(args...);
}
template <typename Arg1>
void ps(Arg1&& arg1) {
cout << arg1 << " ";
}
templ... | 0 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template <typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;... | 12 |
#include <bits/stdc++.h>
using namespace std;
bool init[101010], goal[101010];
vector<int> v[101010], z;
int r(int a, int b, bool f1, bool f2) {
bool f = init[a] ^ goal[a] ^ f1;
int x = f;
if (f) z.push_back(a);
for (int c : v[a]) {
if (c != b) x += r(c, a, f2, f ? f1 ^ 1 : f1);
}
return x;
}
int main()... | 2 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
long long mod = 1e9 + 7;
long long power(long long x, long long n, long long mod) {
long long res = 1;
x %= mod;
while (n) {
if (n & 1) res = (res * x) % mod;... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000;
int K, c, x, y, m, n, cnt, t, mx;
pair<pair<int, int>, int> a[maxn + 5];
int main() {
scanf("%d", &n);
for (int i = (1); i <= int(n); i++) {
scanf("%d%d%d%d%d", &K, &c, &x, &y, &m);
t = 0;
for (int j = (1); j <= int(K); j++) {
... | 5 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e5 + 7;
const long long mod = 1e9 + 7;
const long long INF = 1e6 + 7;
const long long mlog = 20;
const long long SQ = 400;
long long n, k;
long long root;
long long a[maxn], dp[maxn], sz[maxn];
vector<long long> adj[maxn];
bool mark[maxn];
bool dfs(l... | 9 |
#include <bits/stdc++.h>
using namespace std;
static int s_n = 0, s_m = 0;
int s_arr[1024][1024] = {0};
int s_rrr[1024][1024] = {0};
int s_crr[1024][1024] = {0};
int s_res = 0;
int main() {
cin >> s_n >> s_m;
for (int r = 1; r <= s_n; r++) {
for (int c = 1; c <= s_m; c++) {
scanf("%d", &s_arr[r][c]);
... | 2 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2.5e5;
int n, k, mod;
int f[maxn + 5][20];
int ans;
namespace usual {
int fac[maxn + 5], ifac[maxn + 5];
int add(int ta, int tb) { return ta + tb >= mod ? ta + tb - mod : ta + tb; }
int sub(int ta, int tb) { return ta < tb ? ta - tb + mod : ta - tb; }
int k... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, k, n, m, l, t = -1, arr[10000] = {0};
scanf("%d %d %d", &n, &m, &k);
int a[n][m];
for (i = 0; i < n; i++)
for (j = 0; j < m; j++) a[i][j] = 0;
for (l = 0; l < k; l++) {
scanf("%d %d", &i, &j);
i--;
j--;
a[i][j] = 1;
i... | 1 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
struct Treap {
struct node {
long long key, prior, sum;
long long sz;
node *l, *r;
node(long long x)
: key(x), sum(x), sz(1), prior(rnd()), l(nullptr), r(nullptr) {}
};
using ... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
while (n % 10 == 0) {
n = n / 10;
}
long long int k = n;
long long int ne = 0;
while (k) {
ne = ne * 10 + k % 10;
k = k / 10;
}
if (ne == n)
cout << "YES";
else
cout << "NO";
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int bit[4][12][12][maxn];
char s[maxn];
char e[20];
int q, x, l, r, y;
int ans;
int n, n1;
char c;
int sum(int a, int b, int c, int i) {
int s = 0;
while (i > 0) {
s += bit[a][b][c][i];
i -= i & -i;
}
return s;
}
void add(int a, int... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int M = 130;
const int MOD = 1000000000 + 7;
int divisors[M], pivot[N];
int a[N], b[N];
int n;
int power(int x, int y) {
if (y == 0) return 1;
int result = power(x, y >> 1);
result = (long long)result * result % MOD;
if (y & 1) {
resu... | 6 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<bool> > pic, ray, vis;
vector<int> ans;
int cnt;
void floodfill(int x, int y) {
if (vis[x][y] || !pic[x][y]) return;
vis[x][y] = true;
if (!pic[x - 2][y] && !pic[x + 2][y]) {
if (!pic[x][y - 1] && (!pic[x - 2][y + 5] || !pic[x + 2][y + 5]))
ray... | 7 |
#include <bits/stdc++.h>
using namespace std;
void init_code() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
const long long N = 3e5;
int a[N];
int ma[N];
int dp[4001][4001][2];
int n;
int make(int i, int j, int k) {
if (i == 2 * n) {
if (j == n) return 1;
return 0;
}
if (dp[i][j][k] == -1) ... | 5 |
#include <bits/stdc++.h>
using namespace std;
struct node {
int v, id;
bool operator<(const node& tmp) const { return v < tmp.v; }
};
vector<node> fi;
vector<node> se;
long long ans;
int mark[200005];
int cnt;
int qi[5];
int main() {
int n, m, i, j, a, b, c, d, k;
cin >> n >> k;
ans = 2000000007;
ans *= 200... | 7 |
#include <bits/stdc++.h>
using namespace std;
int DP[105][105];
int solve(int a, int b) {
if (a == 0 || b == 0) return 0;
if (DP[a][b] != -1) return DP[a][b];
int chargeA = 0;
int chargeB = 0;
if (b - 2 >= 0) chargeA += 1 + solve(a + 1, b - 2);
if (a - 2 >= 0) chargeB += 1 + solve(a - 2, b + 1);
DP[a][b] ... | 1 |
#include <bits/stdc++.h>
using namespace std;
const long long oo = 1e18 + 7;
const long long MOD = 1e9 + 7;
const int N = 1e5 + 7;
const double pi = acos(-1);
vector<pair<long long, int> > a;
int n;
long long st[4 * N];
bool cmp(pair<long long, int> a, pair<long long, int> b) {
if (abs(a.first - b.first) > 0.0001) re... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int prime = 151;
const long long mod = 1e9 + 7;
const int maxn = 5e1 + 5;
const int inf = 0x3f3f3f3f;
int t, n;
vector<string> vt(maxn);
inline bool ok() {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (vt[i][j] == '1') {
if (i == ... | 2 |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-4;
const long double PI = acos((long double)-1.0);
const long long int MOD = 1e9 + 7;
long long int powmod(long long int a, long long int b, long long int mod) {
long long int res = 1;
a %= mod;
for (; b; b >>= 1) {
if (b & 1) res = res * a %... | 5 |
#include <bits/stdc++.h>
using namespace std;
int a[110], b[22], c[10010], d[10010], f[1100000], g[22][22], n, t, m, p, i, j,
k, x;
void bfs(int x) {
memset(d, 0x3f, sizeof(d));
queue<int> q;
q.push(x), d[x] = 0;
while (q.size()) {
x = q.front(), q.pop();
for (int i = 1; i <= m; i++) {
if (x >... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long n, m, L, s, t;
vector<pair<long long, long long> > adj[1111];
vector<long long> todo;
long long w[11111], u[11111], v[11111], d[1111];
void dijkstra() {
for (long long i = 0; i <= n; i++) d[i] = (1LL << 60);
d[s] = 0LL;
priority_queue<pair<long long, long lo... | 7 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string uncle;
string cat;
string dog;
cin >> uncle;
cin >> cat;
cin >> dog;
if (uncle == "rock" && cat == "rock" && dog == "rock") {
cout << "?";
} else if (uncle == "rock" && cat == "rock" && dog == "paper") {
cout << "S";
} else if (... | 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
;
int t;
cin >> t;
while (t--) {
string s;
cin >> s;
long long n = s.length(), c1 = 0, ca = 0, cb = 0;
for (int i = 0; i < n; i++) {
if (isdigit(s[i])) {
c1++;
} else if ((s[i] - 'a') >=... | 2 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, i, m, ans = 0;
cin >> n >> m;
vector<long long> vec(m);
for (i = 0; i < m; i++) {
cin >> vec[i];
}
ans += vec[0] - 1;
for (i = 0; i < m - 1; i++) {
if (vec[i] <= vec[i + 1]) {
ans += vec[i + 1] - vec[i];
} else {
... | 1 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s = "ROYGBIV";
int n, x, r;
cin >> n;
x = n % 7;
r = n / 7;
for (int i = 0; i < r; i++) {
cout << s;
n = n - 7;
}
if (x > 3) cout << s.substr(0, x);
if (x <= 3 && x > 1) cout << s.substr(x, n);
if (x == 1) cout << 'G';
retur... | 2 |
#include <bits/stdc++.h>
using namespace std;
bool sortsec(const pair<int, int> &a, const pair<int, int> &b) {
return a.first + a.second > b.first + b.second;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, r;
int a, b;
vector<pair<int, int> > vect, rect;
cin >> n >> r;
for (int i = 0; i ... | 6 |
#include <bits/stdc++.h>
using namespace std;
bool prime(int p) {
for (int i = 2; i * i <= p; ++i) {
if (p % i == 0) return 0;
}
return 1;
}
int main() {
int p, y;
cin >> p >> y;
int pp = y;
while (!prime(pp)) --pp;
for (int i = y; i > pp; --i) {
bool yes = 1;
for (int j = 2; j <= p; ++j) {
... | 3 |
#include <bits/stdc++.h>
inline int in() {
int k = 0;
char ch = getchar();
bool p = 1;
while (ch < '-') ch = getchar();
if (ch == '-') ch = getchar(), p = 0;
while (ch > '-') k = k * 10 + ch - '0', ch = getchar();
return p ? k : -k;
}
const int YL = 1e9 + 7, N = 1 << 20;
inline int MO(const int &x) { retu... | 10 |
#include <bits/stdc++.h>
const int maxn = 1e4 + 100;
int T, n, a[maxn], ans1[maxn * 3], ans2[maxn * 3], ans3[maxn * 3], cnt;
int main() {
scanf("%d", &T);
while (T--) {
scanf("%d", &n);
cnt = 0;
int sum = 0;
for (int i = 1; i <= n; ++i) scanf("%d", a + i), sum += a[i];
if (sum % n) {
puts(... | 6 |
#include <bits/stdc++.h>
using namespace std;
struct Edge {
int t, f, next;
Edge() {}
Edge(int a, int b, int c) : t(a), f(b), next(c) {}
};
Edge e[5000000];
int head[100010], vs, vt, tot;
inline void addEdge(int x, int y, int z) {
e[++tot] = Edge(y, z, head[x]);
head[x] = tot;
e[++tot] = Edge(x, 0, head[y])... | 12 |
#include <bits/stdc++.h>
int n, m;
long long lb, ub, mid;
long long a[100024];
inline bool C(long long x) {
int index = n, k = 0;
long long cur = a[index], tee = x;
while (index > 0 && k < m) {
x = tee - index;
if (x <= 0) return 0;
while (x >= cur) {
x -= cur;
--index;
if (index < 1... | 7 |
#include <bits/stdc++.h>
const int MAX_N = 100000;
int N;
int A[MAX_N + 1];
int C[MAX_N + 1];
int min(int a, int b) { return a < b ? a : b; }
bool isPalindrome() {
int i = 0;
int j = N - 1;
while (i <= j && A[i] == A[j]) {
++i;
--j;
}
return i > j;
}
struct Result {
Result() : ok(false) {}
Result(... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2000003;
char s[maxn], t[maxn], tt[maxn];
int kmp[maxn];
int main() {
int T;
scanf("%d", &T);
while (T--) {
scanf("%s", s + 1);
int n = strlen(s + 1), p, len = 0;
for (p = 1; p <= n / 2 && s[p] == s[n - p + 1]; p++)
;
if (p > n /... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, l, c, d, p, nl, np;
cin >> n >> k >> l >> c >> d >> p >> nl >> np;
int a = k * l / nl;
int b = c * d;
int z = p / np;
int m = min(a, b);
m = min(m, z);
cout << m / n;
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
long long int n, a, k;
char s[2000007], res[2000007];
bool vis[2000007];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
long long int maxn = -1;
for (long long int i = 0; i < n; ++i) {
cin >> s >> k;
long long int len = strlen(s);
lon... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10, size = 1 << 20, mod = 998244353, inf = 2e9;
const long long INF = 1e15;
template <class o>
void qr(o& x) {
char c = getchar();
x = 0;
int f = 1;
while (!isdigit(c)) {
if (c == '-') f = -1;
c = getchar();
}
while (isdigit(c)) x = x... | 12 |
#include <bits/stdc++.h>
const double EPS = 1e-9;
const int INT_INF = 1 << 31 - 1;
const long long I64_INF = 1ll << 63 - 1ll;
const double PI = acos(-1.0);
using namespace std;
int n, r;
int res = INT_INF;
char second[1005000];
int sz = 0;
void go(int a, int b, int id, int was) {
if (a == 1 && b == 1 && id == 1 && re... | 6 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> f, a, b, c;
vector<long long> v[110000];
long long n, dp[110000], p[110000];
int pcnt = 0, cnt;
bool prime(int n) {
int i;
if ((n != 2 && !(n % 2)) || (n != 3 && !(n % 3)) || (n != 5 && !(n % 5)) ||
(n != 7 && !(n % 7))) {
return false;
}
... | 9 |
#include <bits/stdc++.h>
using namespace std;
long long arr[200005];
long long fib[200005], MOD = 1000000000;
int n, m;
long long tree1[(200005 << 2)], tree2[(200005 << 2)];
int lChild(int ind) { return (ind << 1) + 1; }
int rChild(int ind) { return (1 + ind) << 1; }
void init(long long *tree, long long *coeff, int ind... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 1e5 + 8;
int n, ZZ, L[12], R[12];
long long ans;
char s[N];
queue<int> q;
struct SAM {
int tot, rt, last, go[N][26], fa[N], Len[N], sz[N], cnt[N][11], deg[N];
SAM() { tot = last = rt = 1; }
void expand(int w, int t) {
int p = last, np = ++tot;
... | 8 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e6 + 3;
long long quickpow(long long a, long long x) {
long long ans = 1;
while (x) {
if (x & 1) ans = ans * a % mod;
x >>= 1;
a = a * a % mod;
}
return ans;
}
int main() {
long long n, k, x = 0, m = 0;
cin >> n >> k;
while ((1ll <... | 7 |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
int s1 = 0, s2 = 0;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
if (x == 1)
s1++;
else
s2++;
}
if (s2) {
cout << "2 ";
s2--;
}
if (s1) {
cout << "1 ";
s1--;
}
while (s2) {
... | 2 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
if (n % 2 == 0)
cout << 2;
else
cout << 1;
return 0;
}
| 2 |
#include <bits/stdc++.h>
using namespace std;
struct o {
int x;
double y;
} area[1010];
bool cmp(o x, o y) { return (x.y < y.y); }
int n, tot, iCross, cross[1010];
vector<int> p, q;
int main() {
cin >> n;
for (int i = 3; i <= n; i++) {
cout << "1 1 2 " << i << endl;
cout.flush();
double iArea;
c... | 7 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
string s;
cin >> s;
sort(s.begin(), s.end());
if (s[0] != s.back()) {
cout << s << '\n';
} else {
cout << "-1\n";
}
}
return 0;
}
| 0 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int z;
cin >> z;
string s;
cin >> s;
long l, r;
l = r = 0;
long i = 0;
long le = s.length();
while (i < le && s[i] == '<') {
l++;
i++;
}
i = le - 1;
while (i > -1 && s[i] == '>') {
r++;
i--;
}
cout << r + l;
return ... | 1 |
#include <bits/stdc++.h>
using namespace std;
bool triangle(long long int a, long long int b, long long int c) {
long long int temp[] = {a, b, c};
sort(temp, temp + 3);
return (temp[0] + temp[1] > temp[2]);
}
signed main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
long long int n;
cin >> ... | 1 |
#include <bits/stdc++.h>
using namespace std;
int n, v, a[30], b[30], sum;
int main() {
scanf("%d %d", &n, &v);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
sum += a[i];
}
for (int i = 0; i < n; i++) scanf("%d", &b[i]);
double minn = 1e10;
for (int i = 0; i < n; i++) minn = min(minn, b[i] / dou... | 3 |
#include <bits/stdc++.h>
using namespace std;
struct ball {
double x;
double v;
double m;
double time;
ball() {}
ball(double x_, double v_, double m_, double t_)
: x(x_), v(v_), m(m_), time(t_) {}
};
struct boom {
int b1;
int b2;
double time;
boom() {}
boom(int b1_, int b2_, double time_) : ... | 6 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
int mx = *max_element(v.begin(), v.end());
int mn = *min_element(v.begin(), v.end());
int ind1 = 0, ind2 = 0;
for... | 0 |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
int main() {
int n;
map<int, int> m;
scanf("%d", &n);
int x;
for (int i = 0; i < n * n; i++) {
scanf("%d", &x);
m[x]++;
}
vector<int> a;
map<int, int>::iterator it... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long int mod = 1e9 + 7;
long long int powe(long long int a, long long int b, long long int mod) {
if (b == 0) return 1;
long long int x = powe(a, b / 2, mod) % mod;
if (b % 2 == 0)
return (x * x) % mod;
else
return (((x * x) % mod) * a) % mod;
}
long lo... | 3 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const long double PI = acosl((long double)-1.0);
const long long LINF = ((1ull << 63) - 1ull);
const int MOD = 1000000007;
const int MAXN = 1000005;
int n, m, k;
int v1[MAXN], v2[MAXN];
pair<int, int> w[MAXN];
int ans[1001];
int p... | 8 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int t = sqrt(n);
if (n % t == 0) {
int h = n / t;
for (int i = 1; i <= h; ++i) {
for (int j = n - t + 1; j <= n; ++j) cout << j << " ";
n = n - t;
}
cout << '\n';
} else {
int h = n / t;
int resst =... | 4 |
#include <bits/stdc++.h>
using namespace std;
double const INF = DBL_MAX / 2;
double const eps = 1e-8;
struct ball {
double x, v, m;
int id;
ball(double x = 0, double v = 0, double m = 0, int id = 0)
: x(x), v(v), m(m), id(id) {}
double after(double t) { return x + t * v; }
bool operator<(ball const &rh... | 6 |
#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int n, x, ans;
set<int> s;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x;
v.push_back(x);
}
reverse(v.begin(), v.end());
for (int k : v) {
if (s.find(k) == s.end()) {
ans = k;
s.insert(k);
}
}
cout << ... | 1 |
#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int main() {
int n, a, b, i, j, x, y, t;
scanf("%d", &t);
while (t--) {
v.clear();
int flag = 0, flag2 = 0;
scanf("%d", &n);
while (n--) {
scanf("%d", &a);
v.push_back(a);
}
for (i = 0; i < v.size(); i++) {
if (... | 1 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const int N = 2005;
int n;
long long ans;
pair<int, int> a[N];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d %d", &a[i].first, &a[i].second);
}
for (int i = 1; i <= n; i++) {
vector<double> v;
for (int j ... | 9 |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
int b, n, x, y, t, d, p, q;
scanf("%d", &n);
x = 0;
for (b = 2; b < n; b++) {
t = n;
while (t > 0) {
x += t % b;
t /= b;
}
}
y = n - 2;
if (x >= y) {
p = x;
q = y;
} else {
p = y;
q =... | 1 |
#include <bits/stdc++.h>
using namespace std;
int cnt[100000], dp[30005][500];
int main() {
int n, x, d;
cin >> n >> d;
int mi = d, mx = d, pi = d, px = d;
for (long long i = 0; i < n; i++) {
scanf("%d", &x);
cnt[x]++;
}
int an = 0, i = d, k = max(0, d - 245);
for (int i = 30000; i >= d; i--) {
... | 5 |
#include <bits/stdc++.h>
int main() {
long long a, b;
long long mod = 1000000007;
long long inv2 = 500000004;
while (scanf("%I64d%I64d", &a, &b) == 2) {
long long ans = 0, a1, a2;
a1 = ((b - 1) * b) % mod;
a1 = (a1 * inv2) % mod;
a2 = (a * b) % mod;
a2 = (a2 * (a + 1)) % mod;
a2 = (a2 * ... | 4 |
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long inf = 4e18;
const long long N = 5e5 + 5;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long tt = 1;
cin >> tt;
while (tt--) {
long long n;
cin >> n;
string s;
cin >> s;
... | 4 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
s.push_back('a');
int k = 1, p = 0;
int i = 0;
while (i < (s.length() - 1)) {
if (s[i] != s[i + 1]) {
k = 1;
p++;
} else if (k >= 5) {
k = 1;
p++;
} else
k++;
i++;
}
cout << p << ... | 0 |
#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
x = 0;
char ch = getchar();
int pd = 1;
while (ch < '0' || ch > '9') {
if (ch == '-') pd = -pd;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
x *= pd;
}
inline void writ... | 3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
long long n, m, t;
long long ans[N];
pair<long long, pair<long long, long long> > a[N];
vector<long long> vR, vL;
long long get(long long l, long long r, vector<long long> &v) {
return upper_bound(v.begin(), v.end(), r) -
lower_bound(v.begi... | 10 |
#include <bits/stdc++.h>
using namespace std;
int n, m, Q, col;
int vis[100005], f[100005], sz[100005];
vector<int> d[100005], v[100005];
int pos[100005];
long long s[100005];
vector<long long> sum[100005];
map<pair<int, int>, long long> mp;
void dfs(int x, int last) {
vis[x] = col;
f[x] = 0;
for (int i = 0; i < ... | 8 |
#include <bits/stdc++.h>
using namespace std;
int i, n, t, k, sum = 0, x;
bool a[10], b;
int main() {
scanf("%d%d", &n, &k);
for (i = 0; i < n; i++) {
scanf("%d", &t), b = 1;
for (x = 0; x <= k; x++) a[x] = 0;
while (t) a[t % 10] = 1, t /= 10;
for (x = 0; x <= k; x++)
if (!a[x]) b = 0;
if ... | 1 |
#include <bits/stdc++.h>
const int inf = (1ll << 31) - 1;
using namespace std;
pair<int, int> b[111];
int a[111];
int n;
int m;
int main() {
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> b[i].first;
b[i].second = i;
}
sort(b, b + n);
for (int i = 0; i < n; i++) {
a[b[i].second] = i % 2;
}
... | 4 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 51123987;
int len, n;
char s[4000010], tmp[2000010];
long long p[4000010];
long long sum, ans;
long long le[4000010], ri[4000010];
int main() {
scanf("%d%s", &len, tmp + 1);
s[++n] = '@';
for (int i = 1; i <= len; i++) {
s[++n] = '#';
s[++n] = ... | 10 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, x;
vector<int> a;
cin >> n >> x;
bool f = false;
for (i = 0; i < n; i++) {
int q;
cin >> q;
if (q == x) f = true;
a.push_back(q);
}
int ans = 0;
if (!f) {
n++;
ans++;
a.push_back(x);
}
sort(a.begin(), a.... | 3 |
#include <bits/stdc++.h>
using namespace std;
bool check(string t) {
bool ans = true;
for (int i = 0; i < t.length() - 1; i++) {
ans &= (abs(t[i] - t[i + 1]) != 1);
}
return ans;
}
int main() {
int t;
cin >> t;
while (t--) {
string s;
cin >> s;
string even = "", odd = "";
for (int i = ... | 5 |
#include <bits/stdc++.h>
using namespace std;
char text[200001];
int txtlen;
char target[200001];
int len;
int rorder[200001];
bool evaluate(int n) {
int tlen = 0;
for (decltype(0) i = 0; i < txtlen; i++) {
if (rorder[i] < n) continue;
if (text[i] != target[tlen]) continue;
tlen++;
if (tlen == len) ... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
int main() {
scanf("%d%d", &n, &k);
if (n == 2 || n == 3) {
printf("-1\n");
return 0;
}
if (k == 1 || k > 3) {
printf("-1\n");
return 0;
}
if (k == 2) {
if (n == 4)
printf("-1\n");
else {
printf("%d\n", n - 1);
... | 8 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
int32_t main() {
ios_base ::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int64_t t;
cin >> t;
while (t--) {
int64_t n, a, b, c, d;
cin >> n >> a >> b >> c >> d;
bool ret = 0;
fo... | 0 |
#include <bits/stdc++.h>
template <class T>
struct _iter_wrapper {
T begin_, end_;
T begin() { return begin_; }
T end() { return end_; }
};
template <class T>
_iter_wrapper<const T*> span(const T* arr, int n) {
return _iter_wrapper<const T*>{arr, arr + n};
}
template <class T, int N>
_iter_wrapper<const T*> spa... | 12 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using ld = long double;
const int mod = 1e9 + 7;
const ll inf = 1e9;
const ll INF = 2e18;
const int N = 2e6 + 66;
int p[N], used[N];
void solve() {
int n;
cin >> n;
if (n == 1) return void(cou... | 6 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
const double eps = 1e-10;
const long long linf = 1e18 + 7;
const long long hh = 523;
int dp[2][200007];
int ans[2][200007];
vector<int> G[2][200007];
int fa[200007];
long long res = 0, sum0 = 0, sum1 = 0;
void dfs(int v, int p) {
fa[v] = p;
dp[0... | 7 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void r1(T &x) {
x = 0;
char c(getchar());
int f(1);
for (; c < '0' || c > '9'; c = getchar())
if (c == '-') f = -1;
for (; '0' <= c && c <= '9'; c = getchar()) x = (x * 10) + (c ^ 48);
x *= f;
}
const int maxn = 5e5 + 5;
const int maxk ... | 2 |
#include <bits/stdc++.h>
using namespace std;
int T;
long long a[200080];
long long b[200080];
string s;
long long n;
long long ans;
long long now;
long long num = 0;
int main() {
cin >> n;
cin >> s;
ans = (n * (n - 1)) / 2;
now = 0;
for (int i = 1; i <= n - 1; i++) {
if (s[i] == s[i - 1]) continue;
n... | 5 |
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
const int maxn = 505;
int a[maxn], dp[maxn][maxn];
int n;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
dp[i][j] = 999;
... | 5 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, t;
cin >> n >> t;
if (t == 10) {
if (n == 1)
cout << -1 << endl;
else {
for (int i = 0; i < n - 1; i++) cout << 1;
cout << 0 << endl;
}
} else {
for (int i = 0; i < n; i++) cout << t;
cout << endl;
}
retu... | 1 |
#include <bits/stdc++.h>
using namespace std;
bool issqr(long long n) {
long long r = round(sqrt((n)));
return n == r * r;
}
int main() {
long long k = 1;
int n;
cin >> n;
long long a[100005];
for (int i = 0; i < n / 2; i++) {
cin >> a[i];
}
int ap = 0;
long long ps = 0;
long long o[100005];
... | 5 |
#include <bits/stdc++.h>
const int Bs = 317, N = 2e5 + 10, mod = 998244353;
template <typename T>
void chkmax(T &x, T y) {
x = x > y ? x : y;
}
template <typename T>
void chkmin(T &x, T y) {
x = x > y ? y : x;
}
template <typename T>
void add(T &x, T y, T mod) {
x = x + y > mod ? x + y - mod : x + y;
}
template <... | 10 |
#include <bits/stdc++.h>
using namespace std;
long long sum[300001];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
for (int i = 1; i <= m; i++) {
long long a, b, c;
cin >> a >> b >> c;
sum[a] -= c;
sum[b] += c;
}
vector<int> v;
for (in... | 6 |
#include <bits/stdc++.h>
using namespace std;
long long arr[15000000];
int main() {
long long int n, p, q, i, j, x, k, c;
c = 0;
for (i = 1;; i++) {
c += i;
arr[i] = c;
if (c > 100000000001000) break;
}
cin >> n;
for (i = 0;; i++) {
if (n > arr[i] && n <= arr[i + 1]) {
if (n == arr[i +... | 1 |
#include <bits/stdc++.h>
inline int read() {
int data = 0, w = 1;
char ch = getchar();
while (ch != '-' && !isdigit(ch)) ch = getchar();
if (ch == '-') w = -1, ch = getchar();
while (isdigit(ch)) data = data * 10 + (ch ^ 48), ch = getchar();
return data * w;
}
const int N(1e5 + 100);
struct edge {
int nex... | 12 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[510];
int kk[510];
bool allSame(int l, int r) {
int num = a[l];
for (int i = l + 1; i <= r; i++) {
if (a[i] != num) {
return false;
}
}
return true;
}
int startIdx(int l, int r) {
int mx = 0;
int idx = l;
for (int i = l; i <= r; i... | 5 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 300005;
int n, u, v, x, trie[maxn << 1][26], sz[maxn << 1], tot, cnt[maxn], res;
char op[2];
int merge(int a, int b) {
if (!a || !b) return a + b;
int rt = ++tot;
sz[rt] = 1;
for (int i = 0; i < 26; ++i) {
trie[rt][i] = merge(trie[a][i], trie[b]... | 8 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout << setprecision(20) << fixed;
long long n, w;
cin >> n >> w;
long long a[n];
long long x;
vector<pair<long long, long long>> v;
long long s = 0;
for (long long i = 0; i < n; i++) {
... | 3 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long power(long long x, long long y, long long 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;
}
signed main() {
long long t = 1;
w... | 4 |
#include <bits/stdc++.h>
using namespace std;
int n, m, father[1000010];
vector<int> a[1000010], num[1000010];
vector<pair<int, int> > wz[1000010];
map<int, int> mp;
map<int, int> ans, mxx, mxy;
priority_queue<pair<pair<int, int>, int>, vector<pair<pair<int, int>, int> >,
greater<pair<pair<int, int>, int... | 7 |
#include <bits/stdc++.h>
using namespace std;
long long curr_edges, vertices;
vector<vector<int> > graph;
void DFS(int i, vector<bool> &visited) {
curr_edges += graph[i].size();
visited[i] = true;
for (int j = 0; j < graph[i].size(); j++) {
if (visited[graph[i][j]] == false) {
vertices++;
DFS(grap... | 3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int y, b, r;
cin >> y >> b >> r;
if (r <= b && r <= y)
cout << (r + (r - 1) + (r - 2));
else if (b < r && b <= y)
cout << (b * 3);
else if (y < b && r - y > 1)
cout << y * 3 + 3;
else
cout << y * 3;
}
| 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.