solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; long long int f(long long int x) { long long int ans = 1; while (x) { ans = ans * (x % 10); x /= 10; } return ans; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); long long int n; cin >> n; vector<long long int> p_10(11); p_10[0] = 1; ...
4
#include <bits/stdc++.h> using namespace std; const unsigned mod = 998244353; const unsigned _mod = 1e9 + 7; const long long infi = 0x3f3f3f3f3f3f3f3fll; const int inf = 0x3f3f3f3f; long long read() { long long x = 0, f = 1; char ch = getchar(); while (ch > '9' || ch < '0') { if (ch == '-') f = -1; ch = g...
11
#include <bits/stdc++.h> using namespace std; string to_string(char c) { return string(1, c); } string to_string(bool b) { return b ? "true" : "false"; } string to_string(const char* s) { return (string)s; } string to_string(string s) { return s; } template <class A> string to_string(complex<A> c) { stringstream ss; ...
13
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 7; long long t, n, m, p, f, sum; long long mx[MAXN][2]; priority_queue<int> Q; int main(int argc, char const *argv[]) { int t; cin >> t; while (t--) { cin >> n >> m; sum = (1 + n) * n / 2; p = (n - m) / (m + 1); f = (n - m) % (m ...
9
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int i, j, n, m; cin >> n; vector<vector<int> > arr(n, vector<int>(200)); vector<vector<int> > ar1(201); for (i = 0; i < n; i++) { for (j ...
10
#include <bits/stdc++.h> using namespace std; template <typename T> inline void Read(T &x) { char c = getchar(); bool f = false; for (x = 0; !isdigit(c); c = getchar()) { if (c == '-') { f = true; } } for (; isdigit(c); c = getchar()) { x = x * 10 + c - '0'; } if (f) { x = -x; } } ...
26
#include <bits/stdc++.h> const int MAXN = 4e4 + 5, MAXM = 5e4 + 5, MOD = 1000000007, INF = 0x3f3f3f3f, N = 2e5; const long long INFL = 0x3f3f3f3f3f3f3f3f; const double eps = 1e-7; using namespace std; int n, m; long long k; vector<long long> solve(vector<int> &a) { vector<long long> ans(a.size() + 1); for...
7
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 1; int num[maxn]; int p[maxn]; bool vis[maxn]; int n; int sup[maxn], len[maxn]; vector<int> lis() { memset(sup, 7, (n + 1) * sizeof(sup[0])); for (int i = 1; i <= n; ++i) { len[i] = lower_bound(sup, sup + n + 1, p[i]) - sup + 1; sup[len[i]...
26
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long INFF = 0x3f3f3f3f3f3f3f3fll; const long long M = 1e9 + 7; const long long maxn = 1e6 + 7; const double eps = 0.00000001; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } template <typename T> inline T abs(...
15
#include <bits/stdc++.h> using namespace std; long long z, r, n, ma[100005], t[100005], x[100005], y[100005], val[100005], dp[505][505], ans; int main() { ios_base::sync_with_stdio(false); long long tt = 1; while (tt--) { cin >> r >> n; t[1] = 0, x[1] = 1, y[1] = 1; for (int i = 2; i <= n + 1; i++...
12
#include <bits/stdc++.h> using namespace std; int n, m, base, mod; int main() { scanf("%d %d %d\n", &n, &m, &mod); if (m >= mod) { printf("2\n"); return 0; } n = min(n, mod - 1), base = 1000000000 % mod; int sum = 0; for (int i = 0; i <= n; i++) { if (sum + m < mod && sum != 0) { printf("1...
10
#include <bits/stdc++.h> using namespace std; int main() { long int n, i; cin >> n; long int a[n], b[n], ct = 0, *temp; bool done = false; for (i = 0; i < n; i++) { cin >> a[i]; ct++; if (a[i] >= 0) b[i] = (-a[i] - 1); else b[i] = a[i]; } if (ct % 2 == 0) { for (i = 0; i < ...
7
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cerr.writ...
16
#include <bits/stdc++.h> using namespace std; int main() { int n, k, i, Max = 1e6; int a[300005]; cin >> n >> k; for (i = 0; i < n; ++i) { cin >> a[i]; Max = min(Max, a[i]); } bool flag = false; while (!flag) { flag = true; for (i = 0; i < n; ++i) while (a[i] % Max > k) --Max, flag =...
13
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fLL; const double PI = acos((long double)-1.0); const double EPS = 1e-8; const int MOD = 1073741824; template <typename T> void cmin(T &x, T y) { if (y < x) x = y; } template <typename T> void cmax(T &x, ...
4
#include <bits/stdc++.h> using namespace std; string s; int main() { getline(cin, s); for (int i = 1; i < s.length(); i++) { if (s[i] == s[i - 1]) while ((s[i] == s[i - 1]) || (s[i] == s[i + 1])) { s[i]++; if (s[i] > 'z') s[i] = 'a'; } } cout << s << endl; return 0; }
5
#include <bits/stdc++.h> const int N = 2505; int n, x[N], y[N]; double dis[N][N], f[N][N][2]; inline int read() { int now = 0, f = 1; register char c = getchar(); for (; !isdigit(c); c == '-' && (f = -1), c = getchar()) ; for (; isdigit(c); now = now * 10 + c - '0', c = getchar()) ; return now * f; } ...
15
#include <bits/stdc++.h> using namespace std; long long int mod = 998244353, n, m, k, flag; vector<set<long long int>> adj; set<long long int> used; void bfs(long long int u) { used.erase(u); queue<long long int> q; q.push(u); while (q.size()) { long long int u = q.front(); q.pop(); vector<long long...
11
#include <bits/stdc++.h> using namespace std; const int maxn = 5005; const int INF = 1 << 20; const int MOD = 1000000007; bool vis[maxn]; int x[maxn], y[maxn]; int a[maxn], b[maxn]; int n, ans1, ans2; void init() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d%d", &x[i], &y[i]); a[i] = x[i] + y[...
18
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:16777216") using namespace std; template <class _T> inline string tostr(const _T& a) { ostringstream os(""); os << a; return os.str(); } const long double PI = 3.1415926535897932384626433832795; const long double EPS = 1e-9; int n, p1, p2, p3, t1, t2, a[200...
1
#include <bits/stdc++.h> using namespace std; string shuffled, substring, head, _back; int cnt[11]; int k; int main() { cin >> shuffled; cin >> substring; int n = shuffled.size(); int temp = 1; for (int i = 1; i <= 7; i++) { temp *= 10; if (n - i <= temp - 1) { k = n - i; break; } } ...
15
#include <bits/stdc++.h> using namespace std; void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << ", "; err(++it, args...); } long long mod(long long n) { return (n % 1000000007 + 1000000007) % 100...
9
#include <bits/stdc++.h> using namespace std; const int N = 100010; long long divisor = 1; int divide(long long x) { int d_cnt = 0; int cnt = 0; divisor = x; for (int i = 2; i <= x / i; i++) if (x % i == 0) { int s = 0; while (x % i == 0) { x /= i, s++; if (d_cnt < 2) { ...
6
#include <bits/stdc++.h> using namespace std; bool ok(int i, int j) { return i >= 0 && j >= 0 && i < 4 && j < 4; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); vector<int> d1{-1, 0, 1}; string s[4]; for (int i = 0; i < 4; ++i) cin >> s[i]; bool can = false, isnt = false; for (int i = 0...
3
#include <bits/stdc++.h> using namespace std; int N, M, x, foo; int a[10005]; int res = 2; multiset<int> pos; int cntZero = 0; set<pair<int, int> > used; int main() { scanf("%d", &N); for (int i = 0; i < N; i++) { scanf("%d", a + i); if (a[i] == 0) cntZero++; } for (int i = 0; i < N; i++) { pos.inse...
12
#include <bits/stdc++.h> unsigned long long int M = 1000000007; using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; vector<int> city; int mini = *min_element(arr, arr + n), flag = 0; bool still = ...
1
#include <bits/stdc++.h> using namespace std; struct Point { long long x, y; Point() : x(), y() {} Point(int _x, int _y) : x(_x), y(_y) {} void read() { scanf("%lld%lld", &x, &y); } Point operator-(const Point& p) const { return Point(x - p.x, y - p.y); } Point operator+(const Point& p) const { return Point...
18
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 100; pair<int, int> a[N]; int tavan(int k, int m) { if (k == 0) return 1; int ans = tavan(k / 2, m); if (ans == -1) return -1; ans *= ans; if (k % 2 == 1) ans *= 4; if (ans > m) return -1; return ans; } int main() { ios::sync_with_stdio(0...
8
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> std::istream& operator>>(std::istream& i, pair<T, U>& p) { i >> p.first >> p.second; return i; } template <typename T> std::istream& operator>>(std::istream& i, vector<T>& t) { for (auto& v : t) { i >> v; } return i; } templat...
10
#include <bits/stdc++.h> using namespace std; bool cmp(pair<int, double> a, pair<int, double> b) { return a.first * a.second * (1 - b.second) > b.first * b.second * (1 - a.second); } int n; pair<int, double> ar[50000]; double ans, len; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf...
13
#include <bits/stdc++.h> using namespace std; int ans; int main() { int n; cin >> n; int a[n]; int lst = n - 1; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i] == 1) lst = i; } int frst = 0; for (int i = 0; i < n; i++) { if (a[i] == 1) { frst = i; break; } } for (int ...
1
#include <bits/stdc++.h> using namespace std; long long add(long long a, long long b) { a += b; if (a >= 998244353) a -= 998244353; return a; } long long sub(long long a, long long b) { a -= b; if (a < 0) a += 998244353; return a; } long long mul(long long a, long long b) { return (a * b) % 998244353; } lon...
16
#include <bits/stdc++.h> using namespace std; template <class T> inline void read(T &num) { num = 0; T f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') num = num * 10 + ch - '0', ch = getchar(); num *= f; } const int...
21
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; long long INF = 1e18; bool isPrime(long long n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (long long i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return fals...
7
#include <bits/stdc++.h> using namespace std; const long long INF = 1E9 + 7; template <class C> void mini(C& a4, C b4) { a4 = min(a4, b4); } template <class C> void maxi(C& a4, C b4) { a4 = max(a4, b4); } long long n, m, k, len[2], ile[2], val; pair<long long, long long> best; map<pair<long long, long long>, vector...
16
#include <bits/stdc++.h> using namespace std; const long long N = (long long)(1e6) + 322; const long long inf = (long long)(1e18) + 322; const long long INF = (long long)(1e18) + 322; const long long mod = 998244353; vector<pair<char, long long>> v[N]; long long a[N], n, m, dp[N], cnt[N], lexmn[N]; long long alllex = 0...
18
#include <bits/stdc++.h> using namespace std; string s; int p[1001]; int sum[26]; int main() { vector<long long> p(1001); vector<long long> sum(26); cin >> s; long long n = s.length(); for (int i = 0; i < n; ++i) sum[s[i] - 'a']++; int max = 0; for (int i = 0; i < 26; i++) if (sum[i] > sum[max]) max =...
5
#include <bits/stdc++.h> using namespace std; inline int getint() { int res = 0, fh = 1; char ch = getchar(); while ((ch < '0' || ch > '9') && ch != '-') ch = getchar(); if (ch == '-') fh = -1, ch = getchar(); while (ch <= '9' && ch >= '0') res = res * 10 + ch - '0', ch = getchar(); return res * fh; } int n...
18
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int maxn = 1e5 + 5; const long long INF = 1LL << 60; void go() { long long n, m; cin >> n >> m; long long sum = 0; vector<int> v; long long s = 0, s2 = 0; for (int i = 0; i < m; i++) { int x, y; cin >> x >> y; v.push_ba...
19
#include <bits/stdc++.h> using namespace std; int fa[1000005][26], fb[1000005][26]; char a[1000005], b[1000005]; long long n, m; int gcd(int n, int m) { return (!m) ? n : gcd(m, n % m); } int main() { scanf("%I64d%I64d", &n, &m); scanf("%s", a); scanf("%s", b); int la = strlen(a), lb = strlen(b), d = gcd(la, lb...
11
#include <bits/stdc++.h> using namespace std; int cnt[16]; int a[1010]; set<long long> s[10][2]; map<long long, long long> mp[10][2]; long long cal() { long long ans = 0; for (int i = 15; i >= 0; i--) { ans = ans * 11 + cnt[i]; } return ans; } long long dfs(int dep, bool zeros) { if (dep == 0) { if (a...
17
#include <bits/stdc++.h> int main() { int m, n; scanf("%d%d", &m, &n); printf("%d", m * n / 2); }
0
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; vector<int> adj[N]; int p[N]; int dp[N]; int lvl[N]; int n, x; int dfs(int u = 0, int par = -1, int l = 0) { p[u] = par; lvl[u] = l; dp[u] = l; for (int nxt : adj[u]) { if (nxt != par) { dp[u] = max(dp[u], dfs(nxt, u, l + 1)); } ...
9
#include <bits/stdc++.h> using namespace std; int n, m; int a[1507][1507]; int pref[1507][1507]; int LEAVES = 1; long long tr[6 * 1507]; long long dp[1507]; long long query(int where, int IL, int IR, int CURL, int CURR) { if (IL > IR) { return -1000000007; } if (IR < CURL || CURR < IL) { return -100000000...
11
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const int inf = 1e9 + 10; vector<int> v[N << 2]; int lef[N << 2]; int rig[N << 2]; pair<int, int> point[N]; int px[N]; int py[N]; void build(int p, int l, int r) { v[p].resize(r - l + 1); if (l == r) { v[p][0] = point[l].second; lef[p] = p...
17
#include <bits/stdc++.h> #define all(x) x.begin(), x.end() using namespace std; typedef long long ll; typedef vector<ll> dlist; typedef vector<dlist> matrix; void solve(){ int n, m; cin >> n; vector<vector<int>> data(n, vector<int>(n, 0)); for(int i = 1; i < (n + 1) / 2; ++i){ for(int a = 0...
7
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; vector<int> v(n); vector<int> freq(101, 0); for (int i = 0; i < n; ++i) { cin >> v[i]; freq[v[i]]++; } int sum = 0; for (int i = 1; i <= 100; ++i) if (freq[i] == 1) sum++; int mu...
7
#include <bits/stdc++.h> using namespace std; long long cnt[1000009], a[200009], ans[200009], answer = 0; struct node { long long L, R, i; } q[200009]; bool cmp(node x, node y) { if (x.L / 1000 != y.L / 1000) { return x.L / 1000 < y.L / 1000; } return x.R < y.R; } void add(long long position) { long long ...
14
#include <bits/stdc++.h> using namespace std; template <class T, class first> inline bool checkbit(T a, first pos) { T t = 1; return ((a & (t << pos)) > 0); } template <class T, class first> inline T setbit(T a, first pos) { T t = 1; return (a | (t << pos)); } template <class T, class first> inline T resetbit(T...
15
#include <bits/stdc++.h> using namespace std; char z[22]; int zlen; vector<int> stk; int now; bool print; bool recur(int idx) { if (idx == zlen) { int fin = 0; for (int n = now; n; n /= 10) fin += n % 10; if (fin < 10) { if (print) { printf("%d", stk[0]); for (int i = 1; i < stk.size...
17
#include <bits/stdc++.h> using namespace std; int main() { string a, b, c, d; cin >> a >> b >> c >> d; int first = a.size() - 2; int second = b.size() - 2; int z = c.size() - 2; int w = d.size() - 2; int n = 0, m = 0; if ((first <= second / 2) && (first <= z / 2) && (first <= w / 2)) { ++n; a = ...
5
#include <bits/stdc++.h> using namespace std; vector<int> G[100005]; int a[100005], b[100005], pre, len, c, p[100005], n, m, s, t, f, v[100005]; void D(int x) { p[c++] = x; v[x] = 1; f |= x == t; for (int d : G[x]) if (!v[d]) D(d); } int main() { cin >> n >> m; t = m + 1; cin >> pre; for (int i = 1;...
13
#include <bits/stdc++.h> static int _m1[100000], _idx1[100000], _m2[100000], _idx2[100000], _r_count[100000] = {}; static int solve(int N, int pi[static N]) { if (N == 1) return pi[0]; _m1[0] = pi[0], _m2[0] = pi[0], _idx1[0] = 0, _idx2[0] = 0; if (pi[1] < pi[0]) { _m1[1] = pi[0], _m2[1] = pi[1], _idx1[1]...
9
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; vector<long long> a(n); for (long long i = 0; i < n; i++) cin >> a[i]; if (a.size() > 2) { a.push_back(-1); vector<long long> v; long long x = 2; for (long long i = 2; i <= n; i++) { if (a[i] != (a[i - 1] +...
3
#include <bits/stdc++.h> int main() { char nick[101]; int cont = 0; scanf("%s", nick); char *s; for (int i = 0; i < 26; ++i) { s = strchr(nick, i + 97); if (s != NULL) ++cont; } if (cont % 2 != 0) printf("%s\n", "IGNORE HIM!"); else printf("%s\n", "CHAT WITH HER!"); return 0; }
0
#include <bits/stdc++.h> using namespace std; long long n, m, ip, sum; long long make_sg(long long tar) { if (tar == 0) return 0; long long low = 0, high = (long long)1e9, val; while (low <= high) { long long mid = (low + high) >> 1; if ((mid) * (mid + 1) / 2 <= tar) { low = mid + 1; val = mid...
13
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; clock_t time_p = clock(); void rtime() { time_p = clock() - time_p; cerr << "Time Taken : " << fixed << (float)(time_p) / CLOCKS_PER_SEC << "\n"; } bool isPrime(long long n) { for (long long i = 2; i * i <= n; ++i) { if (n % i == ...
0
#include <bits/stdc++.h> using namespace std; int main() { float r, h; cin >> r >> h; if ((((int)h / (int)r + 1) * r) - h <= ((2 - sqrt(3)) * r) / 2) { cout << ((int)(h / r) * 2) + 3; } else if ((((int)h / (int)r + 1) * r) - h > (((2 - sqrt(3)) * r) / 2) && (((int)h / (int)r + 1) * r - h) <= r ...
11
#include <bits/stdc++.h> using namespace std; const long long MOD = 998244353; const double oula = 0.57721566490153286060651209; using namespace std; long long n; bool Check(long long mid) { long long sum1 = 0, sum2 = 0; long long tmp = n; long long t; while (tmp) { if (tmp >= mid) { tmp -= mid; ...
7
#include <bits/stdc++.h> using namespace std; void Open() {} char trip[110]; int main() { Open(); int n; scanf("%d", &n); scanf("%s", trip); bool flag = true; for (int len = 1; len < n && flag; len++) { for (int i = 0; i < n && flag; i++) { if (trip[i] == '.') continue; if (i + 4 * len < n) ...
5
#include <bits/stdc++.h> using namespace std; const int MAXN = 10000 + 10; int n, three, two, one; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { int t; scanf("%d", &t); if (t % 3 == 0) three++; if (t % 3 == 1) one++; if (t % 3 == 2) two++; } printf("%d\n", three / 2 + min(one,...
5
#include <bits/stdc++.h> template <typename T> class IntegerIterator { public: using value_type = T; using difference_type = std::ptrdiff_t; using pointer = T*; using reference = T; using iterator_category = std::input_iterator_tag; explicit IntegerIterator(T value) : value(value) {} IntegerIterator& ope...
18
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { int c = a % b; while (c != 0) { a = b; b = c; c = a % b; } return b; } struct UnionFind { vector<int> par; UnionFind(int N) : par(N) { for (int i = 0; i < N; i++) par[i] = i; } int root(int x) { if (par[x] == x) re...
10
#include <bits/stdc++.h> using namespace std; const int N = 110; map<string, int> mp, mp2; string cur[N]; void sol1(int n) { string ans; for (int i = 1; i <= n; ++i) { cout << "? " << i << ' ' << i << '\n'; fflush(stdout); char x; cin >> x; ans.push_back(x); } cout << "! " << ans << '\n'; } ...
16
#include <bits/stdc++.h> using namespace std; bool isReflectionEqual(string s) { unordered_set<char> symmetric = {'A', 'H', 'I', 'M', 'O', 'T', 'U', 'V', 'W', 'X', 'Y'}; int n = s.length(); for (int i = 0; i < n; i++) if (symmetric.find(s[i]) == symmetric.end()) return false...
2
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return a ? gcd(b % a, a) : b; } pair<int, int> a[2100000]; map<string, int> m; int main() { cin.sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i = 0; i < n; i++) { string s; cin >> s; if (s == "typed...
10
#include <bits/stdc++.h> const int N = 100000; const int D = 20; int n; std::vector<int> tree[N]; int depth[N], shortcut[N][D]; void prepare(int p, int u) { depth[u] = ~p ? depth[p] + 1 : 0; shortcut[u][0] = p; for (int i = 0; ~shortcut[u][i]; ++i) { shortcut[u][i + 1] = shortcut[shortcut[u][i]][i]; } for...
20
#include <bits/stdc++.h> using namespace std; int n, s, a[10000]; int main() { ios_base::sync_with_stdio(false); int i, tot = 0, mx = -1; cin >> n >> s; for (i = 0; i < n; i++) { cin >> a[i]; tot += a[i]; mx = max(mx, a[i]); } tot -= mx; if (tot <= s) { cout << "YES\n"; } else { cout...
0
#include <bits/stdc++.h> const long long maxn = 2e5 + 10; using namespace std; long long N, arr[maxn], ans, x, f; signed main() { ios::sync_with_stdio(false); cin >> N; for (register long long i = 1; i <= N; ++i) { cin >> arr[i]; } cin >> x >> f; for (register long long i = 1; i <= N; ++i) { if (arr...
6
#include <bits/stdc++.h> using namespace std; struct margin { int left, right; }; int main() { int test; cin >> test; while (test--) { int n; cin >> n; int arr[n], i = 0, sum = 0; while (i < n) { cin >> arr[i]; sum += arr[i]; i++; } sort(arr, arr + n); if (sum > 0) ...
1
#include <bits/stdc++.h> using namespace std; const int mxn = 1e5 + 5; const int sz = 1 << 17; int n; char s[mxn], t[mxn << 1]; int z[mxn << 1]; int m[sz]; int suflen[mxn]; pair<int, int> mx[sz << 1]; void Z(char *s, int *z) { int n = strlen(s); int L = 0, R = 0; for (int i = 0; i < int(n); ++i) if (i) { ...
20
#include <bits/stdc++.h> using namespace std; int n, ans = 0; vector<char> v; int main() { ios_base::sync_with_stdio(false), cin.tie(nullptr); cin >> n; v.resize(n); for (int i = 0; i < n; i++) cin >> v[i]; int it = 0; while (it < n && v[it] == '<') { ans++; it++; } it = n - 1; while (it >= 0 ...
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int t, i, j, k, n, m, a, b, c; cin >> n; for (i = 0; i < n; i++) { cin >> j; while (j % 2 == 0) j /= 2; while (j % 3 == 0) j /= 3; if (i == 0) c = j; if (j != c) break; } if (j != c) cout << ...
5
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 1e3 + 10; int main() { int n, m, v; cin >> n >> m >> v; if (m < n - 1 or m > (n - 1) * (n - 2) / 2 + 1) cout << -1 << '\n'; else { int u; if (v == n) u = n - 1; else u = n; cout << v << " " << u << ...
9
#include <bits/stdc++.h> using namespace std; int i, j, n, k, tot, ans, sum, b, t, head, tail, x; int h[100005]; bool f[1000005], g1[100005], g2[100005]; string st; char ch; int main() { ios::sync_with_stdio(false); cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> ch; if (ch == '-') g1[i] = true...
6
#include <bits/stdc++.h> using namespace std; vector<int> a, b; int n; int main() { cin >> n; for (int i = 0; i < n; i++) { int tmp; cin >> tmp; if (tmp) a.push_back(tmp); } for (int i = 0; i < n; i++) { int tmp; cin >> tmp; if (tmp) b.push_back(tmp); } int i = 0, j = 0; while (a[0...
5
#include <bits/stdc++.h> using namespace std; bool debug = 0; long long ans; int n, m, k, area[2506][2506]; char s[2506][2506]; void init() { for (int i = 0; i < (n); i++) for (int j = 0; j < (m); j++) if (s[i][j] == '1') area[i][j] = 1; for (int i = 0; i < (n); i++) { for (int j = 0; j < (m); j++) ...
22
#include <bits/stdc++.h> using namespace std; const int mod = (int)1e9 + 7; int i, i0, n, m, ans, a[5005], cnt[5005], sum[5005]; vector<int> v[5005]; long long cal(int x) { long long res = 0; for (int i = 0; i < v[x].size(); i++) { if (v[x][i] <= cnt[x]) res += upper_bound(v[x].begin() + i + 1, v[x].end()...
17
#include <bits/stdc++.h> using namespace std; const int inf_int = 2e9; const long long inf_ll = 2e18; int Gcd(int p, int q) { return q == 0 ? p : Gcd(q, p % q); } int Pow(int p, int q) { int ans = 1; while (q) { if (q & 1) ans = ans * p; p = p * p; q >>= 1; } return ans; } inline int read() { int ...
6
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; int n, m, a[maxn], pos, mask[maxn]; vector<int> e[maxn], out; bool vis[maxn], odd; void search(int now) { vis[now] = 1; if (a[now]) odd = 1; for (int i = 0; i < e[now].size(); i++) if (!vis[e[now][i]]) search(e[now][i]); } void dfs(int now...
14
#include <bits/stdc++.h> int main() { int i, j = 0, N; scanf("%d", &N); int a[N]; for (i = 0; i < N; i++) { scanf("%d", &a[i]); } for (i = 1; i < N - 1; i++) { if (a[i] < a[i - 1] && a[i] < a[i + 1] || a[i] > a[i - 1] && a[i] > a[i + 1]) j++; } printf("%d", j); }
0
#include <bits/stdc++.h> using namespace std; const long long MAXN = 2e5 + 5; const long long MOD = 1e9 + 7; const long long INF = 1e18; mt19937 rnd(time(0)); vector<pair<long long, long long> > go = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; long long n; bool okinds(long long i, long long j) { return (i >= 0 && i < n && j ...
12
#include <bits/stdc++.h> using namespace std; template <typename... As> struct tpl : public std::tuple<As...> { using std::tuple<As...>::tuple; tpl(std::tuple<As...> const& b) { std::tuple<As...>::operator=(b); } template <typename T = tuple<As...>> typename tuple_element<0, T>::type const& x() const { retu...
22
#include <bits/stdc++.h> using namespace std; int n, m, k, s, px[5010], py[5010], dx[210], dy[210], c[5010]; int he[210 * 2], ad[5010 * 4], ne[5010 * 4], di[5010 * 4], wi[5010 * 4], t; void addE(int x, int y, int z, int w) { ++t, ne[t] = he[x], he[x] = t, ad[t] = y, di[t] = z, wi[t] = w; ++t, ne[t] = he[y], he[y] =...
22
#include <bits/stdc++.h> using namespace std; bool OF(long long a, long long b) { if (a == 0 || b == 0) return false; long long result = a * b; if (a == result / b) return false; else return true; } long long mo = 1e9 + 7; vector<long long> v; long long ans = 1, now = 1, x, n; int main() { ios_base::s...
9
#include <bits/stdc++.h> using namespace std; const long double eps = 1e-13; const long double PI = acos(-1); const int INF = (int)1e9; const long long INFF = (long long)1e18; const int mod = (int)1e9 + 7; const int MXN = (int)1e5 + 7; const int K = 7001; bitset<K> mask[K]; bitset<K> ck; bitset<K> re[K]; void build() {...
17
#pragma GCC optimize(2) #include <bits/stdc++.h> #define INF 1000000000 #define LINF 1000000000000000000 #define MOD 1000000007 #define mod 998244353 #define INF63 1061109567 #define INF127 9187201950435737471 #define UINF 18446744073709551615 #define F first #define S second #define ll long long #define N 100010 using...
13
#include <bits/stdc++.h> using namespace std; int main() { double a, b, c, d; double x1, x2; cin >> a >> b >> c; if (a == 0) { if (b == 0) { if (c == 0) cout << -1 << endl; else cout << 0 << endl; } else printf("1\n%f\n", -1 * c / b); } else { d = b * b - 4 * a * ...
12
#include <bits/stdc++.h> using namespace std; char a[2005]; int dp[3][2005]; int main() { int t, n, m; cin >> t; while (t--) { char s[3] = {'R', 'G', 'B'}; dp[0][0] = dp[1][0] = dp[2][0] = 0; scanf("%d%d%s", &n, &m, a); int an = m; for (int i = 0; i < n; ++i) { for (int j = 0; j <= 2; ++...
7
#include <bits/stdc++.h> using namespace std; int main() { int x; cin >> x; string s1[x], s2[x]; for (int i = 0; i < x; i++) { cin >> s1[i]; } for (int i = 0; i < x; i++) { for (int j = 0; j < s1[i].length(); j += 2) { s2[i].push_back(s1[i][j]); } s2[i].push_back(s1[i][s1[i].length() -...
0
#include <bits/stdc++.h> #include <unordered_map> using namespace std; #include <math.h> #define ll long long int #define ld long long double #define pb push_back #define pll pair<ll, ll> #define vi vector<int> #define vl vector<ll> #define vvl vector<vector<ll> > #define vvi vector<vector<int> > #define vlp vector<p...
0
#include <bits/stdc++.h> using namespace std; const long double pi = 3.1415926535897932384626433832795; const long double eps = 1e-9; int n, x, y; int A[1000][1000]; pair<int, int> F[1000][1000]; int DP1[1000][1000], DP2[1000][1000]; pair<int, int> P1[1000][1000], P2[1000][1000]; int main() { cin >> n; for (int i =...
12
#include <bits/stdc++.h> using namespace std; int main() { double a, b, c; cin >> c >> b >> a; double s = 0; s += c * c * c * (sqrt(2.0)) / 12; s += (b * b * b * sqrt(2)) / 6; s += (5 * a * a * a * tan(0.3 * 3.14159265358979323846) * tan(0.3 * 3.14159265358979323846) * sqrt(3 * (tan(0.2 * 3....
9
#include <bits/stdc++.h> using namespace std; int32_t main() { int N, out = INT_MAX; cin >> N; vector<int> A(N); for (auto &a : A) cin >> a; for (int v = 0; v < N; v++) { int c = 0; for (int i = 0; i < N; i++) { int aux = 2 * (abs(v - i) + i + v); c += aux * A[i]; } out = min(out, ...
2
#include <bits/stdc++.h> using namespace std; const int MAXN = 200005; multiset<pair<int, int> > mst; pair<int, int> a[MAXN]; int main() { ios::sync_with_stdio(false); cin.tie(0); int d, full, n; cin >> d >> full >> n; long long ans = 0; for (int i = 1; i <= n; i++) { cin >> a[i].first >> a[i].second; ...
14
#include <bits/stdc++.h> using namespace std; const int dx4[4] = {0, 1, 0, -1}; const int dy4[4] = {1, 0, -1, 0}; const int dx8[8] = {0, 1, 0, -1, 1, -1, 1, -1}; const int dy8[8] = {1, 0, -1, 0, 1, -1, -1, 1}; int main() { ios::sync_with_stdio(false); cin.tie(0); ; int t; cin >> t; while (t--) { long lo...
3
#include <bits/stdc++.h> using namespace std; void dfs(int v, vector<bool> &used, vector<int> &col, vector<int> &all, vector<vector<int> > &g) { used[v] = true; for (int u : g[v]) { if (used[u]) continue; col[u] = 1 - col[v]; dfs(u, used, col, all, g); } all.push_back(v); } int main() { i...
13
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { cout << i + n << " "; } }
4
#include <bits/stdc++.h> using namespace std; template <class T> inline T abs(T a) { return a > 0 ? a : -a; } int n; int m; pair<int, int> r[100000]; bool myless(pair<int, int> a, pair<int, int> b) { swap(a.first, a.second); swap(b.first, b.second); return a < b; } long long t[800000]; const long long mod = 100...
9
#include <iostream> #include <cstdio> #include <vector> #include <cstring> #include <algorithm> #include <queue> using namespace std; int N, T, arr[3011], dp[3011][3011]; int main() { if (fopen("data.in", "r")) freopen("data.in", "r", stdin); cin >> T; while (T--) { cin >> N; ...
19