solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; char str[200005]; bool cck(int n) { int tot = 0; for (int i = 1; i <= n; i++) tot += (str[i] == str[1]); return tot == n; } int main() { int t; scanf("%d", &t); while (t--) { int n; scanf("%d %s", &n, str + 1); if (cck(n)) { printf("%d\n", (n +...
9
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5; int v[maxn + 10]; int main() { int t; scanf("%d", &t); memset(v, -1, sizeof(v)); for (int i = 1; i <= t; i++) { int x, n; scanf("%d%d", &x, &n); int ans = 0; for (int j = 1; j * j <= x; j++) { if (x % j == 0) { int...
11
#include <bits/stdc++.h> using namespace std; int maxx = 0; int main() { int i, j, k, l, n, h[101] = {0}; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; h[a[i]]++; } for (int i = 0; i < 101; i++) { if (h[i] > maxx) maxx = h[i]; } cout << endl; cout << maxx; }
0
#include <bits/stdc++.h> using namespace std; vector<vector<int> > bags; int parent[70010], coin[70010], taken[70010], contained_bags[70010]; int main() { int n, totalcoin, maxa = 0, maxbag; cin >> n >> totalcoin; bags.assign(70010, vector<int>()); for (int i = 0; i < n; i++) { cin >> coin[i]; bags[coin...
19
#include <bits/stdc++.h> using namespace std; const int MAXN = (int)1e5 + 10; int n, m, s[MAXN], f[MAXN], id[MAXN]; long long Tohka[MAXN], t[MAXN]; map<int, vector<int> > h; bool cmp(int a, int b) { return t[a] < t[b]; } int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; ++i) scanf("%I64d%d%d", &t[i], ...
14
#include <bits/stdc++.h> using namespace std; long long bit[200005]; inline void upd(long long idx, long long val) { while (idx < 200005) { bit[idx] += val; idx += (idx & -idx); } } inline long long que(long long idx) { long long ans = 0; while (idx > 0) { ans += bit[idx]; idx -= (idx & -idx); ...
11
#include <bits/stdc++.h> using namespace std; template <typename... T> void r(T&... args) { ((cin >> args), ...); } template <typename... T> void w(T&&... args) { ((cout << args << " "), ...); } template <typename T> void disp(T arr) { for (long long i = 0; i < arr.size(); i++) { cout << arr[i] << " "; } ...
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); int n; cin >> n; int N = n; string s = ""; while (n) { int rem = n % 10; n /= 10; s.push_back(char(rem + 48)); } reverse(s.begin(), s.end()); n = N; int ans = INT_MAX; int ok = 0; ...
6
#include <bits/stdc++.h> using namespace std; char s[100][100]; char tmp[100][100]; char tmp2[100][100]; int a, b; void rotate180() { for (int i = 0; i < a; i++) for (int j = 0; j < b; j++) tmp2[a - i - 1][b - j - 1] = tmp[i][j]; for (int i = 0; i < a; i++) for (int j = 0; j < b; j++) tmp[i][j] = tmp2[i][j]...
10
#include <bits/stdc++.h> using namespace std; int n, k, a[400000], n1, n2, spt; int f[6000][6000]; int main() { cin.tie(NULL); ios_base::sync_with_stdio(false); cin >> n >> k; for (int i = 1; i <= n; ++i) cin >> a[i]; sort(a + 1, a + n + 1); n1 = n % k; spt = n / k + 1; n2 = k - n1; for (int i = 0; i ...
12
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; if (n == 4 || k < n + 1) { cout << -1 << '\n'; return 0; } int a, b, c, d; cin >> a >> b >> c >> d; int taken[n + 1]; for (int i = 0; i <= n; i++) taken[i] = 0; taken[a] = taken[b] = taken[c] = taken[d] = 1; ...
8
#include <bits/stdc++.h> using namespace std; char a[100005][15]; int n, m, start[100001], finish[100001], block[100001], block_no; pair<int, int> last[100005][15]; void build(int index) { for (int i = start[index]; i <= finish[index]; i++) { for (int j = 1; j <= m; j++) { if (a[i][j] != '^') continue; ...
19
#include <bits/stdc++.h> using namespace std; int main() { std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; long long query = 1; while (query--) { long long k, n, count = 0, i; string s; cin >> k >> s; n = s.length(); vector<long long> v; v.push_back(0); for (lon...
8
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const double pi = acos(-1), eps = 1e-8; const int maxn = 1e5 + 10; const int N = 1e6 + 10, M = 4e7 + 7, mod = 998244353; int n, m; vector<int> G[N]; int de[N]; int o, e; bool vis[N]; void dfs(int x, int f) { de[x] = de[f] + 1; if (vis[x]) { ...
10
#include <bits/stdc++.h> using namespace std; const long double pi = 3.1415926535897932384626433832795l; template <typename T> inline auto sqr(T x) -> decltype(x * x) { return x * x; } template <typename T> inline T abs(T x) { return x > T() ? x : -x; } template <typename T1, typename T2> inline bool umx(T1& a, T2 ...
14
#include <bits/stdc++.h> using namespace std; bool jo(string a, string b) { int sa = a.size(), sb = b.size(); for (int i = 0; i + sa <= sb; i++) { if (a == b.substr(i, sa)) { bool jo = 1; for (int j = 0; j < i; j++) { if (b[j] == '0') jo = 0; } for (int j = i + sa; j < sb; j++) ...
12
#include <bits/stdc++.h> int inp() { char c = getchar(); while (c < '0' || c > '9') c = getchar(); int sum = 0; while (c >= '0' && c <= '9') { sum = sum * 10 + c - '0'; c = getchar(); } return sum; } int cnt = 1; int n, minl[1000010], minr[1000010], maxl[1000010], maxr[1000010], ans[1000010], cc...
18
#include <bits/stdc++.h> using namespace std; vector<int> digit, ip; int d[20]; vector<vector<int> > ans; void show(int n, int m) { if (n == 4) { if (d[m] == -1) { ans.push_back(ip); } } else if (d[m] == 0) { ip[n] = 0; show(n + 1, m + 1); } else { ip[n] = 0; for (int i = m; d[i] != ...
12
#include <bits/stdc++.h> using namespace std; int main() { long long i, j, n, m, a; while (cin >> n) { long long t[100005] = {0}; long long dp[100005] = {0}; m = 0; for (i = 1; i <= n; i++) { cin >> a; if (a > m) m = a; t[a]++; } dp[0] = 0; dp[1] = t[1]; for (i = 2;...
7
#include <bits/stdc++.h> using namespace std; string s, str; int pre[200005]; int num, s_len, len; bool Check(int xx) { string ch = str; for (int i = 1; i <= xx; i++) { ch[pre[i] - 1] = '.'; } int j = 0; for (int i = 0; i < len; i++) { if (ch[i] == s[j]) { j++; } if (j == s_len) break; ...
9
#include <bits/stdc++.h> int main() { int a[100000], n, i, in = 0, j, k, i0, i1, fg = 0; scanf("%d", &n); for (i = 1; i <= n; i++) { scanf("%d", &a[i]); } if (a[1] == 0) { for (j = 1; a[j] == 0; j++) { in++; } } else { for (j = 1; a[j] == 1; j++) { in++; } } if (in == n) ...
9
#include <bits/stdc++.h> using namespace std; #define li long long int #define le long double #define mod 1000000007 #define maxe 4000000 vector<bool> pu(maxe+1,false); vector<li> pr; class dop {public: li n,p,k,q,r; string s,v; void get(); }; void seive() {for(li i=2;(i)<=maxe;i++){if(!pu[i]){ for(li j=(2*i);j<=ma...
1
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void __print(int x) { cout << x; } void __print(long x) { cout << x; } void __print(long long x) { ...
9
#include <bits/stdc++.h> using namespace std; const int N = 200010; struct edge { int to, next; } e[N * 2]; int head[N], ecnt; inline void adde(int from, int to) { e[++ecnt] = (edge){to, head[from]}, head[from] = ecnt; e[++ecnt] = (edge){from, head[to]}, head[to] = ecnt; } int dep[N], fa[N][18], dfn[N], dfsn; voi...
22
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<pair<int, int>> v(n); for (int i = 0; i < n; ++i) { cin >> v[i].first >> v[i].second; if (v[i].first > v[i].second) swap(v[i].first, v[i].second); } bool a; if (v[0].second >= v[1].second) a = 1; else if (v[0]...
2
#include <bits/stdc++.h> using namespace std; long long climbTheHill(vector<int> slope) { vector<int> tmp2(slope); sort(tmp2.begin(), tmp2.end()); vector<int> sorted_slope; sorted_slope.push_back(tmp2[0]); for (int i = 1; i < tmp2.size(); i++) { if (tmp2[i] != tmp2[i - 1]) sorted_slope.push_back(tmp2[i]);...
14
#include <bits/stdc++.h> using namespace std; double ans, a, b, c; int main() { cin >> a >> b >> c; ans += a * a * a * sqrt(2.0) / 12.0; ans += b * b * b * sqrt(2.0) / 6.0; ans += c * c * c * sqrt((15.0 + 5.0 * sqrt(5.0)) / 2.0) / 12.0; printf("%.11lf\n", ans); return 0; }
9
#include <bits/stdc++.h> using namespace std; const int M = 100030; const int N = 50; const double eps = 1e-8; const double dinf = 1e15; const int MOD = 100000007; int n; int cnt[M], rch[M]; vector<int> xv; bool vis[M]; void work(int x, int c = 0) { if (x > 100000 || vis[x]) return; xv.push_back(x); vis[x] = 1; ...
11
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, h, m; cin >> n >> h >> m; int a[n + 5]; for (int i = 1; i <= n; i++) { a[i] = h; } while (m--) { int l, r, x; cin >> l >> r >> x; for (int i = l; i <= r; i++) { a[i] =...
0
#include <bits/stdc++.h> using namespace std; int prime[150005]; long long p[150005], nn; long long mod = 1e9 + 7; long long dev[150005]; int main() { dev[1] = 1; for (int i = 2; i < 150005; i++) { dev[i] = (mod - mod / i) * dev[mod % i] % mod; } for (int i = 2; i < 150005; i++) if (prime[i] == 0) { ...
15
#include <bits/stdc++.h> using namespace std; const int inf = ~0U >> 1, maxn = 100000 + 10; long long a; long long s[maxn], cnt[maxn]; void setIO(string name) {} long long gI() { char c = getchar(); while ((c < '0' || c > '9') && c != '-') c = getchar(); long long p = 0, flag = 1; if (c == '-') flag = -1, c = g...
8
#include <bits/stdc++.h> using namespace std; int a[105]; int dp[2][10005][105]; int cnt[105]; int main() { int n; cin >> n; for (int i = 1; i <= n; ++i) { cin >> a[i]; } sort(a + 1, a + n + 1); dp[0][0][0] = 1; for (int i = 1; i <= n; ++i) ++cnt[a[i]]; int sum = 0; int as = 0; for (int i = 1; i...
13
#include <bits/stdc++.h> using namespace std; const bool testcases = 1; void print(int a[], int n) { for (int i = 0; i < n; i++) cout << a[i] << " "; cout << "\n"; } unsigned long long int logn(unsigned long long int n, unsigned long long int r) { return (n > r - 1) ? 1 + logn(n / r, r...
12
#include <bits/stdc++.h> using namespace std; map<string, int> m; int main() { int i, n, j, mx = -1000; cin >> n; string S1, S2, S3; m["polycarp"] = 1; for (i = 0; i < n; i++) { cin >> S1 >> S2 >> S3; for (j = 0; j < S1.size(); j++) S1[j] = tolower(S1[j]); for (j = 0; j < S3.size(); j++) S3[j] = t...
4
#include <bits/stdc++.h> using namespace std; vector<pair<long, long> > v; int main() { long long n, m, x, low, up; scanf("%lld", &n); m = n / 2; for (int i = 0; i < n; i++) { scanf("%lld", &x); low = sqrt(x); up = low + 1; low = low * low; up = up * up; v.push_back(pair<long, long>(min(...
8
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; priority_queue<int> lista; for (int i = 0; i < n; i++) { int aux; cin >> aux; lista.push(-aux); } long long tot = 0; for (int i = 0; i < k; i++) { tot -= lista.top(); lista.pop(); } cout << tot << e...
4
#include <bits/stdc++.h> using namespace std; using LL = long long; using PLL = pair<LL, LL>; using VL = vector<LL>; using VLL = vector<PLL>; using VVL = vector<vector<LL> >; const LL INF = 1e18 + 7; const LL MOD = 998244353LL; const LL N = 2e6 + 7; LL n, m; LL inv[N]; LL ans; inline LL solve() { cin >> n >> m; LL ...
22
#include <bits/stdc++.h> using namespace std; long long i, j, n, m, k, t, l, r, x, y, s, a[1000009], d[100009]; bool ok, vis[1000009]; long long mn = -1000000009, mx = 1000000009; vector<long long> g[100009]; string p, q; queue<int> st; int main() { cin >> n; a[1] = 1; a[2] = 1; d[1] = 1; for (i = 3; i <= 100...
0
#include <bits/stdc++.h> using namespace std; const int MAX = 500010; struct LADY { int b, s, r; } l[MAX]; struct SegmentTreeNode { int l, r; int mx; }; class SegmentTree { public: void buildTree(int tn, int l, int r); void insert(int tn, int p, int val); int query(int tn, int p); private: SegmentTreeN...
16
#include <bits/stdc++.h> using namespace std; int main() { int a; cin >> a; double ans = 0; for (int i = a; i > 0; i--) { ans += (double)1 / i; } cout << fixed << setprecision(6) << ans << endl; return 0; }
2
#include <bits/stdc++.h> using namespace std; int n, q; char a[36], b[36]; int recursion(char c, int s) { int ttl = 0; if (s == n - 1) return 1; for (int i = 0; i < q; i++) if (c == b[i]) { ttl += recursion(a[i], s + 1); } return ttl; } int main() { cin >> n >> q; for (int i = 0; i < q; i++) c...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 505; const int maxm = 1000005; const int mod = 998244353; int n, m, c[maxm], l[maxn], r[maxn]; long long f[maxn << 2][maxn << 2]; long long dp(int L, int R) { if (L == R + 1) return 1; if (L > R) return 0; if (~f[L][R]) return f[L][R]; if (L == R) r...
14
#include <bits/stdc++.h> using namespace std; const int N = 200000 + 77, Mod = 998244353; int n, q; int lzS[N << 2], lzM[N << 2], S[N << 2]; set<pair<int, int> > R[N]; inline void Shift(int l, int r, int id) { S[id] = (S[id] * 1ll * lzM[id] + lzS[id] * 1ll * (r - l)) % Mod; if (r - l > 1) { lzS[id << 1] = (lzS[...
17
#include <bits/stdc++.h> using namespace std; const int maxN = 501; int n, a[maxN], dp[maxN][maxN]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for (int(i) = (0); (i) < (n); ++(i)) cin >> a[i]; for (int Len = 1; Len <= n; Len++) { for (int l = 0; l <= n - Len; l++) { int r = l +...
11
#include <bits/stdc++.h> using namespace std; template <typename T, typename S> ostream &operator<<(ostream &os, const pair<T, S> &v) { os << "("; os << v.first << "," << v.second << ")"; return os; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "["; long long sz = v.size...
13
#include<bits/stdc++.h> using namespace std; #define ll long long int #define pi (3.141592653589) #define mod 1000000007 #define dd double #define ff first #define ss second #define pb push_back #define mp make_pair #define pura(v) v.begin(),v.end() #define w(t) while(t--) #define fl(i,a,b) for(int i=a;i<b;i++) #define...
2
#include <bits/stdc++.h> using namespace std; int a, b, c, d, e, f; int main() { cin >> c >> d >> e >> f >> a >> b; cout << max(0, min(min(min(c - 1, d - 1), min(e - 1, f - 1)), b) - a + 1); return 0; }
3
#include <bits/stdc++.h> using namespace std; const int MAXN = 11, MAXL = 100000 + 10; struct State { int len, fa, num[MAXN], tr[26]; State() : len(0), fa(0) { memset(num, 0, sizeof(num)); memset(tr, 0, sizeof(tr)); } State(int len, int fa, int numr, int ref) : len(len), fa(fa) { memset(num, 0, size...
9
#include <bits/stdc++.h> using namespace std; const int N = 100050; long double x[N], y; int k, n; inline long double sqr(long double x) { return x * x; } inline long double dis(int p) { return sqrt(sqr(x[n + 1] - x[p]) + sqr(y)); } inline long double dis(int l, int r) { if (l > r) return 0; return min(dis(l), dis(...
18
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; char c[2005], s[2005]; long long dp1[2005][2005], dp2[2005][2005], mod = 1e6 + 3; signed main() { scanf("%s", c + 1); long long len, n = 0; len = strlen(c + 1); bool f = 0; for (long long i = 1; i <= len; i++) { if (!isdigit(c[i])...
18
#include <bits/stdc++.h> using namespace std; int32_t main() { long long t; cin >> t; while (t--) { long long a; cin >> a; if (a == 180) { cout << -1 << endl; continue; } long long k = 180; for (long long i = 2; i <= 180; i++) { if (a % i == 0 && k % i == 0) { a /...
8
#include <bits/stdc++.h> using namespace std; const long long MAXN = 1e5 + 10; long long a[MAXN], cnt[MAXN]; int32_t main() { ios::sync_with_stdio(false); cin.tie(0); long long n, id1 = -1; cin >> n; for (long long i = 0; i < n; i++) cin >> a[i]; for (long long i = 0; i < n / 2; i++) if (a[i] != a[n - i...
17
#include <bits/stdc++.h> using namespace std; int an[5005], t[5005], cnt[5005]; template <typename _Tp> struct cmp : public binary_function<_Tp, _Tp, bool> { bool operator()(const _Tp& __x, const _Tp& __y) const { return __x.second == __y.second ? __x.first > __y.first : __x.se...
7
#include <bits/stdc++.h> using namespace std; const int N = 1000005; char ans[N]; int n, r; int best = 100000000; void chkseq(int A, int B) { int dif = 0, len = 0, rA = A, rB = B; while (B) { len += A / B; dif += A / B - 1; A %= B; swap(A, B); } --dif; if (A == 1 && len == n && dif < best) { ...
13
#include <bits/stdc++.h> using namespace std; string seg[10] = {"1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011"}; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long T = 1; while (T--) { long long N, K; ci...
9
#include <bits/stdc++.h> using namespace std; int N, Q; int A[100101]; pair<int, int> res[200201]; int main() { scanf("%d %d", &N, &Q); deque<int> dq; for (int i = 1; i <= N; i++) { int x; scanf("%d", &x); dq.push_back(x); } for (int i = 1; i <= N + N; i++) { int a = dq.front(); dq.pop_fro...
7
#include<bits/stdc++.h> using namespace std; typedef long long LL; const int N=505; int _suf[N*N],_ssuf[N*N]; int d[N*N],n,md,*suf=_suf+600,f[N],*ssuf=_ssuf+600,pre[N*N],binom[N][N],fac[N]; inline void upd(int&a){a+=a>>31&md;} int main(){ cin>>n>>md; d[0]=1; for(int i=1;i<n;++i){ int lim=i*(i+1)/2; suf[lim]=ssuf...
19
#include <bits/stdc++.h> const int magicconst = 73743071; using namespace std; const int maxn = 300500; long long ans[maxn]; long long dp[maxn]; int w[maxn]; pair<pair<int, int>, int> qr[maxn]; int main() { int n, p; scanf("%d", &n); for (int i = 0; i < (int)(n); ++i) scanf("%d", w + i); scanf("%d", &p); for ...
13
#include<bits/stdc++.h> using namespace std; int main(){ int t; cin>>t; for(int o=0; o<t; o++){ int n; cin>>n; vector<long double> diamond, miner; for(int i=0; i<2*n; i++){ int a, b; cin>>a>>b; a=abs(a); b=abs(b); if(a==0) miner.push_back(b); e...
4
#include <bits/stdc++.h> using namespace std; const int N = 100100; int n, m, dd[N], a[N], d[N]; bool vis[N]; inline bool check(int k) { for (int i = 0; i < k; i++) d[i] = dd[i]; memset(vis, 0, sizeof vis); for (int j, i = k - 1; i >= 0; i--) { j = d[i]; if (vis[j]) d[i] = 0; vis[j] = 1; } for (in...
9
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; int main() { int tests; cin >> tests; for (int test = 0; test < tests; ++test) { ull n, m; string cells, prev, next; cin >> n >> m; cin >> cells; prev = cells; next = cells; for (int i = 0; i < m; ++i) { ...
0
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 1; const long long inf = 0x7ffffffffff; const long long NINF = -inf; const long long mod = 998244353; template <class T> inline void read(T &res) { char c; T flag = 1; while ((c = getchar()) < '0' || c > '9') if (c == '-') flag = -1; res =...
11
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> a1, a2; int vis[100020]; signed main() { scanf("%d%d", &n, &m); long long tot = n + m, ans = 0; while (ans * (ans + 1) / 2 <= tot) ans++; ans--; for (int p = ans; n > 0 && p > 0; --p) { if (n >= p) { n -= p, vis[p] = 1, a1.push_back...
8
#include <bits/stdc++.h> using namespace std; const int N = 305, mod = 10007; char s[N]; int n, m, M, f[N][N][N], g[N], h[N]; struct matrix { int a[N][N]; matrix() { memset(a, 0, sizeof a); } matrix operator*(const matrix &d) const { matrix t; for (int i = 0; i <= M; i++) { for (int j = 0; j <= M; j...
22
#include <bits/stdc++.h> using namespace std; long long power(long long n, long long m) { long long res = 1; while (m > 0) { if (m % 2 == 1) { res = (res % 1000000007 * n % 1000000007) % 1000000007; } n = n % 1000000007 * n % 1000000007; m = m >> 1; } return res; } int main() { long long...
7
#include <bits/stdc++.h> using namespace std; struct Point { int x, y; inline Point() {} inline Point(int _x, int _y) { x = _x; y = _y; } } po[6000]; int n, r; inline int sqr(int x) { return x * x; } int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}; inline bool ok(int x, int y) { int a = sqr(x), b = sqr...
19
#include <bits/stdc++.h> using namespace std; int main(void) { string s, t, min, max; int minNum = 0, similar = 0; unsigned int i, j; getline(cin, s); getline(cin, t); if (s.empty() && t.empty()) minNum = 0; else if (!s.empty() && !t.empty()) { if (s.size() >= t.size()) { max = s; min ...
1
#include <bits/stdc++.h> using namespace std; using namespace chrono; auto TimeStart = high_resolution_clock::now(); auto TimeStop = high_resolution_clock::now(); void StartTimer(); void StopTimer(); const int N = 75; const int inf = 1e9; struct SStateBall { int x, y, z; bool operator==(const SStateBall &A) const {...
13
#include <bits/stdc++.h> using namespace std; struct node { int stat; int doosra; }; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; int stat[n + 1]; for (int i = 1; i <= n; i++) cin >> stat[i]; vector<int> temp[n + 1]; for (int i = 1; i <= m; i++) { int va...
12
#include <bits/stdc++.h> using namespace std; double PI = 3.1415926535897932384626433832795; int arr[201], vis[1000], vis2[10000], vis3[1234]; vector<int> v1, v2; map<int, int> mp; int main() { int n, ans = 0; scanf("%d", &n); for (int i = 0; i < n * 2; ++i) { scanf("%d", &arr[i]); vis[arr[i]]++; } bo...
11
#include <bits/stdc++.h> using namespace std; void c_p_c() {} int main(int argc, char const *argv[]) { c_p_c(); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int n; string s, t = "RGB"; int ans = 0; cin >> n >> s; for (int i = 1; i < n; i++) { if (s[i] == s[i - 1]) { ans++; for...
6
#include <bits/stdc++.h> using namespace std; template <class _T> inline string tostr(const _T& a) { ostringstream os(""); os << a; return os.str(); } vector<vector<int> > pre; int current = 0; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } bool correct(int x) { for (int i = 0; i < pr...
11
#include <bits/stdc++.h> using namespace std; int depth[200005] = {0}; int dp[200005][20]; int size[200005] = {0}; int centPar[200005] = {0}; bool cent[200005] = {false}; int mn[200005]; vector<int> adj[200005]; void dfs(int u, int pre) { depth[u] = depth[pre] + 1; size[u] = 1; dp[u][0] = pre; mn[u] = 50000009;...
16
#include <bits/stdc++.h> const int N = 110; using namespace std; int a[N], p[N]; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> a[i]; p[i] = p[i - 1] + a[i]; } long long res = 0; for (int i = 0; i < m; i++) { int l, r; ...
4
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); ll a, b; cin >> a >> b; ll s = 0; ll k = 1; while (s + k <= a + b) { s += k++; } --k; ll t = 0; ll l = 1; while (t <= a) { t += l++...
8
#include <bits/stdc++.h> using namespace std; struct Point { int x, y; } p1, p2, p3; struct Point2 { double x, y; }; bool Find; int Ral(Point2 p1, Point2 p2, Point2 p3) { double x1 = p2.x - p1.x; double y1 = p2.y - p1.y; double x2 = p3.x - p2.x; double y2 = p3.y - p2.y; double c = x1 * y2 - x2 * y1; if ...
18
#include <bits/stdc++.h> using namespace std; int n, q, position; long long seg[1 << 20]; long long query(int s, int e, int l, int r, int node, int lev) { if (position & (1 << lev)) { l = s + e - l; r = s + e - r; swap(l, r); } if (e < l || r < s) return 0LL; if (s == l && e == r) return seg[node]; ...
16
#include <bits/stdc++.h> using namespace std; int const N = 5e2 + 10, M = 1e4 + 10; int n, m, k; pair<int, int> p[M]; int l[M + M], r[M + M]; struct union_find { int par[N], sz[N]; int root(int v) { if (par[v] == v) return v; return root(par[v]); } }; union_find pre[M], suf[M]; int par[N], sz[N]; void res...
11
#include <bits/stdc++.h> using namespace std; pair<pair<int, int>, int> ara2[200005]; int ara[200005], i, n; bool comp(pair<pair<int, int>, int> x, pair<pair<int, int>, int> y) { if (x.first.second < y.first.second) return true; return false; } int main() { cin >> n; for (i = 0; i < n; i++) { cin >> ara[i];...
5
#include <bits/stdc++.h> using namespace std; const int max_n = 100000, alpha = 256; struct pair_l { int num; string s; pair_l *nt; } * nodes[max_n]; int n, bingo; int aut[alpha][max_n]; long long amt = 0; int automa(int c, int state) { return aut[c][state]; } void build_aut() { string t; cin >> t; t += cha...
12
#include <bits/stdc++.h> using namespace std; int A[1000010], B[1000010], par[1000010], C[1000010], vis[1000010]; int dep[1000010]; vector<int> adj[1000010], cd[1000010]; map<int, int> M[1000010]; vector<int> cyc; vector<int> basis; void dfs(int v, int p, int d) { par[v] = p; vis[v] = 1; dep[v] = d; for (int i ...
15
#include <bits/stdc++.h> using namespace std; using ll = long long; using PII = pair<ll, ll>; template <typename T> void chmin(T &a, const T &b) { a = min(a, b); } template <typename T> void chmax(T &a, const T &b) { a = max(a, b); } struct FastIO { FastIO() { cin.tie(0); ios::sync_with_stdio(0); } } fa...
15
#include <bits/stdc++.h> using namespace std; const int N = 55; int G[N][N]; int Ci[N]; int n; struct node_ans { int x, y, x0, y0; } ans[100000]; int ans_cnt; void cyh() { ans_cnt = 0; int e, f, e00, f00, s = 0; for (e = 1; e <= n; e++) for (f = 1; f <= Ci[e]; f++) { s++; if (G[e][f] - s) { ...
7
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; vector<int> vertices[maxn]; int n, m; int s[maxn], e[maxn]; char vis[maxn]; bool flag = true; void dfs(int ver, bool color) { vis[ver] = color; int sz = vertices[ver].size(); for (int i = 0; i < sz; i++) { int to = vertices[ver][i]; i...
9
#include <bits/stdc++.h> using namespace std; int main() { string s; char vt_ht = 'a'; cin >> s; for (int i = 0; !(i >= s.length() - 1 || vt_ht == 'z'); i++) { if (s[i] <= vt_ht) { s[i] = vt_ht; vt_ht++; } } if (vt_ht == 'z') { s[s.length() - 1] = 'z'; cout << s; } else { c...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int a[maxn]; int main() { int T; scanf("%d", &T); while (T--) { int n; scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d", &a[i]); } long long sum = 0; for (int i = 2; i <= n; ++i) { if (a[i - 1] >...
4
#include <bits/stdc++.h> using namespace std; void factorizar(long long x, set<long long>& primos) { long long p = x; for (long long i = 2; i * i <= x; i++) { if (p % i == 0) { primos.insert(i); while (p % i == 0) p /= i; } } if (p > 1) primos.insert(p); } long long hacerDP(long long p, vect...
15
#include <bits/stdc++.h> using namespace std; long long int Pow(long long int a, long long int b, long long int md, long long int ans = 1) { for (; b; b >>= 1, a = a * a % md) if (b & 1) ans = ans * a % md; return ans % md; } const long long int MAXN = 1e6 + 10; const long long int INF = 8e18;...
10
#include <bits/stdc++.h> using namespace std; #define endl "\n" #define pb push_back #define int long long #define fast ios_base::sync_with_stdio(false);cin.tie(NULL); #define be(v) v.begin(),v.end() typedef vector<string> VS; typedef vector<int> VI; typedef vector<VI> VVI; signed main() { fast #ifndef ONLIN...
0
#include <bits/stdc++.h> long long dp[2][200003]; int main() { long long n, m, x, r, i, c, j, k, ans; scanf("%I64d%I64d%I64d", &n, &m, &x); if (n > m) { printf("0\n"); return 0; } dp[0][0] = 1; r = 0; for (i = 0; i < m; i++) { r = 1 - r; c = 1 - r; for (j = 0; j <= n * (n + 1) + n; j++...
19
#include <bits/stdc++.h> using namespace std; const int N = 101000; int n, K, head[N], etot, dfn[N], dfp[N], plca[N][20], dep[N], tim, sum; struct edge { int v, next; } g[N << 1]; set<int> st; void add_edge(int u, int v) { g[etot] = (edge){v, head[u]}; head[u] = etot++; } void dfs(int u, int fa, int deep) { dep...
18
#include <bits/stdc++.h> using namespace std; const double eps = 1E-8; const int dx4[4] = {1, 0, 0, -1}; const int dy4[4] = {0, -1, 1, 0}; const int inf = 0x3f3f3f3f; const int MOD = 1E9 + 7; const int N = 105; int n, k, ans, f[N][50], g[50]; vector<int> edge[N]; int F(int x) { return x + k; } int Add(long long x, long...
17
#include <bits/stdc++.h> using namespace std; int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; void moha() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); } const long double eps = 1e-10; const long long N = 1e9 + 1, MOD = 1000000007; int main() { moha(); int n; cin >> n; int a[n + 1]; int c ...
5
#include <bits/stdc++.h> using namespace std; const long long INFLL = 1e18; const int MAXN = 3e5; const long long INF = 1e9; const long long kek = 998244353; int main() { ios_base::sync_with_stdio(0); cin.tie(0); ; long long n, m; cin >> n >> m; vector<long long> t(101, 0); long long sum = 0; for (int i...
4
#include <bits/stdc++.h> using namespace std; const int maxN = 52, maxA = 50001 * maxN; int dp[maxN / 2][maxA], T[maxN]; vector<int> ans[2]; bool ans0[maxN]; int main() { int n; scanf("%d", &n); for (int i = (1); i < (int)(n * 2 + 1); i++) scanf("%d", T + i); sort(T + 1, T + n * 2 + 1); dp[0][0] = n * 2 + 1; ...
23
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); string s; cin >> s; int cnt = s.size() / 2; if (s.size() & 1) for (int i = 1; i < s.size(); i++) if (s[i] == '1') { cnt++; break; } cout << cnt; return 0; }
2
#include <bits/stdc++.h> using namespace std; int main() { int tt; cin >> tt; while (tt--) { int n; cin >> n; char sq[52][52] = {0}; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) { cin >> sq[i][j]; } bool ans = true; for (int i = 0; i < n - 1; i++) for (...
5
#include <bits/stdc++.h> using namespace std; const int N = 2e3, M = 1e6, INF = 1e9 + 123, MOD = 1e9 + 7, KEY = 1001; const double EPS = 0.000000001; template <typename T> inline T sqr(T t) { return t * t; } inline void file() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } char ch; struct point ...
15
#include <bits/stdc++.h> using namespace std; using ll = long long; constexpr int kMaxN = 1e5 + 7; struct node { int p = -1; }; node reps[kMaxN]; int find(int x) { if (reps[x].p == x) { return x; } return reps[x].p = find(reps[x].p); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.ti...
12
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 5; const int INF = 1e6 + 1; int main() { int n, d; string s; cin >> n >> d; cin >> s; int ans = 0; int cur = 0; if (s[0] == '0' || s[n - 1] == '0') { cout << -1 << endl; } else { while (1) { if (cur == n - 1) break; ...
0