Dataset Viewer
Auto-converted to Parquet Duplicate
solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; int main() { uint64_t a, b, amount = 0, buff; cin >> a >> b; while (a != 0) { if (a > b) { amount += a / b; a %= b; } else { amount++; buff = b; b = a; a = buff - b; } } cout << amount << endl; return 0; }
8
#include <bits/stdc++.h> using namespace std; int main() { string a; int i, x; set<char> b; getline(cin, a); for (i = 1; i < a.size() - 1; i += 3) { b.insert(a[i]); } cout << b.size() << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; bool cmp(const int &a, const int &b) { return a < b; } int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int lcm(int a, int b) { return a * (b / gcd(a, b)); } int dp[505][505]; int graph[505][505]; int arr[505]; unsigned long long int ans[505]; bool alive[505]; i...
9
#include <bits/stdc++.h> using namespace std; template <class T, class U> bool cmax(T &a, const U &b) { return a < b ? a = b, 1 : 0; } template <class T, class U> bool cmin(T &a, const U &b) { return b < a ? a = b, 1 : 0; } void _BG(const char *s) { cerr << s << endl; }; template <class T, class... TT> void _BG(con...
13
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; vector<vector<int> > adj(n + 1); vector<int> indeg(n + 1, 0); vector<int> outdeg(n + 1, 0); for (int i = 0; i < m; i++) { int x, y; cin >> x >> y; adj[x].push_back(y)...
4
#include <bits/stdc++.h> using namespace std; int sq(int p) { if (p % 2 == 0) return (p / 2) * (p / 2); else return (p / 2) * (p + 1) / 2; } int main(void) { int n, curr = 0; cin >> n; while (sq(curr) < n) { curr++; } cout << curr; return 0; }
3
#include <bits/stdc++.h> using namespace std; const int M = 1010; int n, m, flag; char ma[M][M]; bool vis[M][M][5][5]; void dfs(int x, int y, int c, int t) { if (x < 1 || y < 1 || x > n || y > m) return; if (t > 2 || ma[x][y] == '*' || vis[x][y][c][t] || flag) return; vis[x][y][c][t] = 1; if (ma[x][y] == 'T') {...
8
#include <bits/stdc++.h> using namespace std; long long arr[50009][9]; int main() { long long n, m, ans = 0; cin >> n >> m; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> arr[i][j]; for (int i = 2; i <= n; i++) arr[i][1] += arr[i - 1][1]; for (int i = 2; i <= m; i++) { for (int j = 1...
5
#include <bits/stdc++.h> using namespace std; char aa[5001]; int n, m; bool avail[5001]; int L[5001], R[5001], U[5001], D[5001]; int cnt[5001]; int encode(int i, int j) { if (i < 0 || i >= n || j < 0 || j >= m) return -1; return i * m + j; } void del(int cur) { int ll = L[cur], rr = R[cur], uu = U[cur], dd = D[cu...
15
#include <bits/stdc++.h> using namespace std; inline long long read() { long long num = 0, neg = 1; char c = getchar(); while (!isdigit(c)) { if (c == '-') neg = -1; c = getchar(); } while (isdigit(c)) { num = (num << 3) + (num << 1) + c - '0'; c = getchar(); } return num * neg; } int n, a...
3
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; map<int, vector<pair<int, int>>> mp; vector<pair<int, int>> shoes; long long memo[MAXN][4]; long long calcState(int ind, int mask) { if (memo[ind][mask] != -1) { return memo[ind][mask]; } if (ind == shoes.size()) { return 0; } aut...
17
#include <bits/stdc++.h> using namespace std; string s[505]; bool vis[505][505]; long long n, m, k; bool chck(long long a, long long b) { if (a > 0 and s[a - 1][b] == '.') return 1; if (a < m - 1 and s[a + 1][b] == '.') return 1; if (b > 0 and s[a][b - 1] == '.') return 1; if (b < m - 1 and s[a][b + 1] == '.') ...
8
#include <bits/stdc++.h> using namespace std; int grid[10][10]; int main() { int n; cin >> n; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { cin >> grid[i][j]; } } for (int k = 0; k < n; ++k) { for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { grid[i][j] ...
12
#include <bits/stdc++.h> using namespace std; inline int setBit(int N, int pos) { return N = N | (1 << pos); } inline int resetBit(int N, int pos) { return N = N & ~(1 << pos); } inline bool checkBit(int N, int pos) { return (bool)(N & (1 << pos)); } struct Vector { long long int x, y; int id; long long int val()...
15
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; long long int q = 0; for (int i = 0; i < n; i++) { cin >> a[i]; q += a[i]; } long long int e = 0; if (q % 2 != 0) q++; for (int i = 0; i < n; i++) { e += a[i]; if (e >= q / 2) { cout << i + 1; ...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 2020; int dp[maxn][maxn]; string st[] = {"1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011"}; char s[maxn][10]; char ans[maxn]; int cal(int a, int b) { int cnt = 0; for (int i = 0;...
9
#include <bits/stdc++.h> using namespace std; int main() { long long int a, b, c, d; cin >> a >> b >> c >> d; if (a == d) { if (c != 0 && a == 0) cout << "0"; else cout << "1"; } else { cout << "0"; } }
3
#include <bits/stdc++.h> using namespace std; long long int buildstack(vector<long long int> adj[], stack<long long int>& s, bool visited[], long long int& f, long long int u, long long int p) { visited[u] = true; s.push(u); for (auto itr = adj[u].begin(); itr != ...
8
#include <bits/stdc++.h> inline int query(int x) { printf("? %d\n", x); std::fflush(stdout); int res; scanf("%d", &res); return res; } int n; inline bool chk(int x) { --x; int t1 = query(x + 1), t2 = query((x + n / 2) % n + 1); if (t1 == t2) { printf("! %d\n", x + 1); std::fflush(stdout); ex...
12
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:5000000000") const long long mod = 1000000007; long long Inf = (long long)2e9; long long LINF = (long long)1e18 + 1e17; using namespace std; int main() { ios::sync_with_stdio(false); long long n, h; cin >> n >> h; if (h >= 2e9) { long long l = 0, r = ...
13
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false), cin.tie(NULL); ; long n, k; cin >> n >> k; vector<int> ar(n); for (int i = 0; i < n; i++) cin >> ar[i]; queue<int> q; for (int i = 1; i <= n; i++) q.push(i); int i = 0; while (!q.empty() && (k--)) { int ...
5
#include <bits/stdc++.h> using std::min; int n, m, a[17][10005], dis[20][20], dp[16][1 << 16][16], ans; int c(int x, int y) { int t = 0x3f3f3f3f3f; for (int i = 1; i < m; i++) t = std::min(t, abs(a[x][i] - a[y][i + 1])); return t; } int main() { scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) for (int ...
12
#include <bits/stdc++.h> using namespace std; void solve() { long long n, _x, _y; cin >> n; pair<pair<long long, long long>, pair<long long, long long> > pts[n]; for (long long i = 0; i < 2 * n; i++) { cin >> _x >> _y; if (i & 1) pts[i / 2].second = {_x, _y}; else pts[i / 2].first = {_x,...
8
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { int n; cin >> n; n = 1 << n; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) cout << (__builtin_parity(i & j) ? '*' : '+'); cout << '\n'; } return 0; }
10
#include <bits/stdc++.h> #pragma GCC optimize(2) #pragma G++ optimize(2) using namespace std; int main() { long long n, a, b; scanf("%lld", &a), scanf("%lld", &b), n = a + b; long long ans = 0; for (long long l = 1, r; l <= n; l = r + 1) { r = n / (n / l); long long t = n / l, al = (a + t) / (1 + t), ar...
19
#include <bits/stdc++.h> #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; template <class T, class S> ostream &operator<<(ostream &o, const pair<T, S> &p) { return o << '(' << p.first << ", " << p.second << ')'; } template <template <class, class...> clas...
15
#include <bits/stdc++.h> using namespace std; int P[100005], c1, c2, g1[20], g2[20], pos[400], st1, mn, st2, e, n, i, j, k, from[170][1 << 9][1 << 9], p[100005], a[100005], cnt, u1[20], u2[20], is[100005]; inline int gcd(int x, int y) { return y ? gcd(y, x % y) : x; } void check(int now, int f1, int f2) { if ...
21
#include <bits/stdc++.h> using namespace std; string a[5205]; string x[505]; int main() { x['0'] = "0000"; x['1'] = "0001"; x['2'] = "0010"; x['3'] = "0011"; x['4'] = "0100"; x['5'] = "0101"; x['6'] = "0110"; x['7'] = "0111"; x['8'] = "1000"; x['9'] = "1001"; x['A'] = "1010"; x['B'] = "1011"; ...
10
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; const int N = 3000005; char A[N], B[N], C[N], S[N]; int la, lb, lc, ls; struct suffix_array { int sa[N], rk[N], hr[N], hs[N]; int sz, tmp[N], bin[N]; void build(char *S, int ls) { sz = max(255, ls); for (int i = (1); i <= (ls); ++i)...
16
#include <bits/stdc++.h> const int INF = 0x3f3f3f3f; const int maxn = 2e5 + 50; const int Mod = 1e9 + 7; const double PI = acos(-1); using namespace std; char s[maxn]; int n, l; int main() { while (scanf("%d %d", &n, &l) != EOF) { memset(s, 0, sizeof(s)); scanf("%s", s); int pos = 0, t = l; for (; pos...
9
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n, h, m, k; cin >> n >> h >> m >> k; vector<int> hi(n); vector<int> mi(n); vector<pair<int, int> > trains; for (int i = 0; i < n; i++) { cin >> hi[i] >> mi[i]; if (mi[i] >= m / 2) { m...
15
#include <bits/stdc++.h> using namespace std; const long long mxN = 1e6; char line[mxN]; int main() { ios_base::sync_with_stdio(false); cin.getline(line, 1e6); vector<string> w; vector<char> s; for (long long i = 0; i < 1e5 + 500; i++) { if (line[i] == '\0') { string t = ""; for (auto it : s) ...
8
#include <bits/stdc++.h> using namespace std; using ll = long long; using uint = unsigned int; using pii = pair<int, int>; using pll = pair<ll, ll>; using ull = unsigned long long; using ld = long double; template <typename T> void _(const char* s, T h) { cerr << s << " = " << h << "\n"; } template <typename T, typen...
13
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; map<int, int> mp; vector<int> x(n), l(m), r(m); for (int i = 0; i < n; i++) { cin >> x[i]; mp[x[i]] = i; } for (int i = 0; i < m; i++) cin >> l[i] >> r[i]; vector<int> c(n); int i = 0; map<int, int>::iterator...
8
#include <bits/stdc++.h> using namespace std; using ll = long long int; ll n, k, A, B, x, tot = 0; int main() { cin >> n >> k >> A >> B; if (k == 1) { cout << (n - 1) * A << "\n"; return 0; } while (n != 1) { if (n % k == 0) { if ((n - (n / k)) * A <= B) { tot += (n - (n / k)) * A; ...
6
#include <bits/stdc++.h> using namespace std; long long int ar[40]; int main() { long long int n, l; cin >> n >> l; long long int arr[40]; cin >> arr[0]; for (int i = 1; i < n; i++) { cin >> arr[i]; arr[i] = min(2 * arr[i - 1], arr[i]); } for (int i = n; i < 40; i++) arr[i] = 2 * arr[i - 1]; lon...
8
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 10; int n, a[maxn]; int main() { scanf("%d", &n); int cur = 0; a[0] = 1; for (int i = 1; i < n; ++i) { a[++cur] = 1; while (cur != 0 && a[cur] == a[cur - 1]) { a[cur - 1]++; --cur; } } for (int i = 0; i <= cur; +...
0
#include <bits/stdc++.h> using namespace std; bool prime(int n) { for (int i = 2; i * i <= n; i++) { if (n % i == 0) { return false; } } return true; } int main() { int a, b; cin >> a >> b; int pr = a + 1; while (!prime(pr)) { pr = pr + 1; } if (pr == b) { cout << "YES\n"; } el...
0
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k; cin >> n >> m; vector<vector<int>> g(n + 1), r(n + 1); vector<int> dist(n + 1, -1); queue<int> q; for (int i = 0; i < m; ++i) { int x1, x2; cin >> x1 >> x2; g[x1].push_back(x2); r[x2].push_back(x1); } cin >> k; vec...
9
#include <bits/stdc++.h> using namespace std; int main() { string s, t; cin >> s >> t; int p = 0, e1 = -1; for (int i = 0; i < t.length(); i++) { if (t[i] == s[p]) p++; if (p == s.length()) { e1 = i; break; } } if (p != s.length()) { cout << 0 << endl; return 0; } p = s.l...
6
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; const int maxn = 3e5 + 10, maxm = 11; int casn, n, m; long long k; struct node { int a, b, flag; }; set<unsigned long long> ck; unordered_map<unsigned long long, int> cnt; unordered_map<unsigned long long, node> dp; unsigned long long pw[40];...
13
#include <bits/stdc++.h> using namespace std; int n; const int MAXN = 1e5 + 1; long long sum1toX[MAXN]; long long sortedSum1toX[MAXN]; int v[MAXN]; int m, l, r, type; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (int i = 0; i < n; i++) { cin >> v[i]; } sum1toX[...
4
#include <bits/stdc++.h> using namespace std; int long long pre[100005], suff[100005], a[100005]; struct point { int long long l, r; }; int main() { ios::sync_with_stdio(0), cin.tie(0); int long long n, flag = 0; cin >> n; map<int long long, struct point> m; for (int long long i = 0; i < n; i++) { cin >...
11
#include <bits/stdc++.h> using namespace std; inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } const double EPS = 1e-9; const double PI = acos(-1.0); int main() { int n; ...
5
#include <bits/stdc++.h> using namespace std; struct Point { int a, b, c, d, e; Point() { a = b = c = d = e = 0; } Point(int aa, int bb, int cc, int dd, int ee) { a = aa; b = bb; c = cc; d = dd; e = ee; } }; Point difference(Point s, Point t) { return Point(s.a - t.a, s.b - t.b, s.c - t.c,...
9
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; long long k; cin >> n >> k; long long a[n]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); long long ans = a[n / 2], med = a[n / 2]; long long numcross = 0; bool domore = tr...
6
#include <bits/stdc++.h> using namespace std; long long modexpo(long long x, long long p) { long long res = 1; x = x % 1000000007; while (p) { if (p % 2) res = res * x; p >>= 1; x = x * x % 1000000007; res %= 1000000007; } return res; } struct compare { bool operator()(const pair<long long, ...
9
#include <bits/stdc++.h> using namespace std; template <class T> inline T min(T &a, T &b) { return a < b ? a : b; } template <class T> inline T max(T &a, T &b) { return a > b ? a : b; } template <class T> void read(T &x) { char ch; while ((ch = getchar()) && !isdigit(ch)) ; x = ch - '0'; while ((ch = ge...
18
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; long long ans = 0; for (int i = (0); i < (n); ++i) { long long t, T, x, cost; cin >> t >> T >> x >> cost; if (t >= T) { ans += cost + m * x; continue; } long long aux1 = cost; if (m > (T - t))...
11
#include <bits/stdc++.h> using namespace std; const int MOD = int(1e9) + 7; int pom[2][2] = {{0, 1}, {1, 1}}; long long tmp; void mulMat(int *A, int *B, int n) { int res[2][2] = {{0}}; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) for (int k = 0; k < n; k++) { tmp = res[i][j]; tm...
15
#include <bits/stdc++.h> using namespace std; class Solution { public: long long solve(long long m, long long d, long long w) { auto gcd = [&](long long a, long long b) { while (a != 0) { b %= a; swap(a, b); } return b; }; long long res = 0; auto n = min(m, d); l...
14
#include <bits/stdc++.h> using namespace std; const int Maxn = 100005; int sum[Maxn]; int need; string s, res; void tryGet() { if (s.length() % 2) { need = s.length() + 1; return; } for (int i = s.length() - 1; i >= 0; i--) if (s[i] > '7') sum[i] = -1; else if (s[i] == '7') if (sum[i +...
10
#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) { cout << *it << " = " << a << "\n"; err(++it, args...); } const long long N = 1e6 + 5, M = 1e9 + 7, inf = 1e18; int t[N]; void up(i...
14
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long i, j, t; cin >> t; while (t--) { long long n; cin >> n; long long a[n + 1], b[n + 1], d[n + 1]; map<long long, long long> vis; for (i = 1; i <= n; i++) { cin >> a[i];...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, m; scanf("%d %d", &n, &m); map<int, vector<pair<int, string> > > M; vector<pair<int, string> > aux; for (int i = 1; i <= m; i++) M[i] = aux; string s; int a, b; for (int i = 0; i < n; i++) { cin >> s >> a >> b; M[a].push_back(pair...
5
#include <bits/stdc++.h> using namespace std; int main() { int q; cin >> q; while (q--) { int n; string s, ans; cin >> n >> s; for (int i = 0; i < 2 * n - 1; i += 2) ans += s[i]; cout << ans << "\n"; } return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int w, h, k, area, guild, result = 0; cin >> w >> h >> k; result = ((w * 2 + h * 2) - 4); if (k > 0) { for (int i = 1; i < k; i++) { result += (((w - 4 * i) * 2 + (h - 4 * i) * 2) - 4); } } cout << result << endl; }
0
#include <bits/stdc++.h> using namespace std; const int maxn = 2e3, inf = 1e9; int n, s, m, k, aa[maxn], dp[maxn][maxn], cnt[maxn], sl[maxn], a[maxn]; vector<pair<int, int>> apear[maxn]; void input() { cin >> n >> s >> m >> k; for (int i = 1; i <= n; i++) { cin >> aa[i]; a[i] = aa[i]; } a[n + 1] = aa[n ...
17
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> q(3 * n + 1); for (int i = 0; i < 3 * n; i++) { int a; cin >> a; q[a] = i; } vector<vector<int>> v(n, vector<int>(3)); for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { cin >> v[i][j]; ...
12
#include <bits/stdc++.h> using namespace std; int count_zero(int n) { int result = 0; while (n) { result += n / 5; n = n / 5; } return result; } int solve(int m) { int flag = 0; for (int i = 0; i < 1000000; i++) { if (count_zero(i) == m) { cout << "5" << endl; cout << i << " " << i +...
5
#include <bits/stdc++.h> using namespace std; long long fac(long long n) { long long p = 1; for (long long i = n; i > 0; i--) { p *= i; } return p; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long test_case = 1; while (test_case--) { string s; cin >> s; char minus = '-'...
4
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:1024000000,1024000000") int c[(500000 + 10)], a[(500000 + 10)], b[(500000 + 10)], id[(500000 + 10)]; int ll[(500000 + 10)], rr[(500000 + 10)]; int h[(500000 + 10)]; bool e[(500000 + 10)]; vector<int> vt[(500000 + 10)], Left[(500000 + 10)], Ri...
18
#include <bits/stdc++.h> using namespace std; int a[2000200], b[2002000], c[2002000]; int main() { int n, m; scanf("%d%d", &n, &m); memset(b, 0, sizeof(b)); for (int i = 0; i < n; i++) { int x; scanf("%d", &a[i]); b[a[i]]++; } sort(a, a + n); int ans = 0, max0 = a[n - 1], max2 = a[n - 1]; in...
4
#include <bits/stdc++.h> using namespace std; int main() { string s, r, p, s1, s2; int res = 0, i; cin >> s; p = s; reverse(s.begin(), s.end()); r = s; if (p != r) { res = p.length(); cout << res; } else { for (i = 1; i <= p.length(); i++) { p.erase(0, 1); s1 = p; reverse(s...
1
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; int n, m; vector<pair<long long, long long>> segments_on[123][2], decomp_a[123][2]; void dfs_a(int h, long long L, long long R, long long l, long long r, int w) { if (L >= l && R <= r) { decomp_a[h][w].push_back({L, R}); return; ...
23
#include <bits/stdc++.h> using namespace std; const int MAXV = 1000006; const int MAXN = 150005; int A[MAXN], par[MAXV], pfact[MAXV], p_comp[MAXV]; vector<int> primes; set<int> ans[MAXV]; int parent(int pos) { if (par[pos] != pos) par[pos] = parent(par[pos]); return par[pos]; } int dsu_merge(int u, int v) { u = p...
19
#include <bits/stdc++.h> using namespace std; int a[300005], n, k; long long dp[300005], ans = -1e9; vector<int> v[300005]; void dfs(int nod, int p, bool f) { dp[nod] = a[nod]; for (int u : v[nod]) { if (u != p) { dfs(u, nod, f); dp[nod] += max(dp[u], 0LL); } } if (f) ans = max(ans, dp[n...
16
#include <bits/stdc++.h> using namespace std; const int MAX = 500 + 9; int dp[MAX + 9][MAX + 9]; vector<int> v; bool check(int i, int j) { for (int i1 = 0; i1 < j - i; i1++) { if (v[i + i1] != v[j - i1]) return false; } return true; } int f(int i, int j) { if (i > j) return 0; if (check(i, j) == true) ret...
11
#include <bits/stdc++.h> using namespace std; int n, m, a[66], b[66]; vector<pair<long long, long long> > v; int ans; int main() { scanf("%d %d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); a[i] *= 2; } for (int i = 1; i <= m; i++) { scanf("%d", &b[i]); b[i] *= 2; } for (int ...
13
#include <bits/stdc++.h> using namespace std; inline long long Phi(long long X) { register long long Return; Return = X; register long long i; for (i = 2; i * i <= X; i++) { if (X % i == 0) { while (X % i == 0) { X /= i; } Return = Return / i * (i - 1); } } if (X > 1) { ...
13
#include <bits/stdc++.h> using namespace std; int main() { vector<int> v; int i, x; for (i = 0; i < 4; i++) { cin >> x; v.push_back(x); } sort(v.begin(), v.end()); if (v[3] < v[2] + v[1] || v[2] < v[0] + v[1]) cout << "TRIANGLE"; else if (v[3] == v[2] + v[1] || v[2] == v[0] + v[1]) cout <<...
1
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 5; long long n, a[N], c[N], p[N]; inline long long read() { long long ret = 0, f = 0; char c = getchar(); while (!isdigit(c)) { if (c == '-') f = 1; c = getchar(); } while (isdigit(c)) { ret = ret * 10 + c - 48; c = getcha...
11
#include <bits/stdc++.h> using namespace std; int main() { char str[10]; char str1[10]; scanf("%s%s", str, str1); int lenth = strlen(str); sort(str, str + lenth); int i = 1; while (str[0] == '0' && lenth != 1) { swap(str[0], str[i]); i++; } if (strcmp(str, str1) == 0) printf("OK\n"); els...
3
#include <bits/stdc++.h> using namespace std; const double PI = 3.1415926535897; const long long INF_LL = 1e18 + 7; const double EPS = 1e-5; const long long INF_int = 1e9 + 7; const long long maxn = 2e5 + 10; const long long mod2 = 1e9 + 9; const long long mod3 = 1e9 + 33; long long p; const long long K = 47500; vector...
9
#include <bits/stdc++.h> using namespace std; int k1, k2, k3; void Enter() { cin >> k1 >> k2 >> k3; if (k1 > k2) swap(k1, k2); if (k1 > k3) swap(k1, k3); if (k2 > k3) swap(k2, k3); } void Solve() { if ((k1 == 1) || (k1 == 2 && k2 == 2) || (k1 == 2 && k2 == 4 && k3 == 4) || (k1 == 3 && k2 == 3 && k3 == 3...
6
#include <bits/stdc++.h> using namespace std; const long long maxn = 2e6, mod = 1e9 + 7; long long n, m, a, b, jc[2222222], injc[2222222], cur, ans; long long binpow(long long a, long long t) { if (t < 0) return binpow(a, (-t) * (mod - 2)); long long res = 1, p = a; for (long long i = t; i; i >>= 1) { if (i &...
16
#include <bits/stdc++.h> using namespace std; int n, m, pa[1005]; int getpa(int x) { if (pa[x] == x) return x; return pa[x] = getpa(pa[x]); } int main() { scanf("%d%d", &n, &m); int ans = 0, a, b, p1, p2; if (m != n - 1) ans = 1; for (int i = 1; i <= n; ++i) pa[i] = i; for (int i = 1; i <= m; ++i) { s...
5
#include <bits/stdc++.h> using namespace std; inline int in() { int res = 0; char c; int f = 1; while ((c = getchar()) < '0' || c > '9') if (c == '-') f = -1; while (c >= '0' && c <= '9') res = res * 10 + c - '0', c = getchar(); return res * f; } const int N = 100010; pair<int, int> a[N]; long long mn[N...
9
#include <bits/stdc++.h> struct eea_result { int g, x, y; }; eea_result eea(int a, int b) { int rx = a, ry = b; int sx = 1, sy = 0; int tx = 0, ty = 1; while (ry != 0) { int t; int q = rx / ry; t = rx - q * ry; rx = ry; ry = t; t = sx - q * sy; sx = sy; sy = t; t = tx - q *...
14
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 9; const int maxm = 3e3 + 9; const long long mod = 998244353; int add[maxn]; long long w[maxn]; long long dp[maxm][maxm]; long long Pow(long long a, long long b) { long long res = 1; a %= mod; while (b) { if (b & 1) res = res * a % mod; ...
15
//#pragma GCC optimize("inline,Ofast,no-stack-protector,unroll-loops,fast-math,O3") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,popcnt,avx,abm") #include <bits/stdc++.h> #define ll long long #define int ll typedef double ld; #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); using namespace s...
5
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; ++i) { cin >> a[i]; } int minn, maxx, count = 0; if (n > 2) { minn = min(a[0], a[1]); maxx = max(a[0], a[1]); for (int i = 2; i < n; ++i) { if (a[i] > maxx) { maxx = a...
0
#include <bits/stdc++.h> using namespace std; struct S { int x, y; } a[3]; bool cmp(S a, S b) { if (a.x == b.x) return a.y < b.y; return a.x < b.x; } set<pair<int, int> > s; int main() { int i; for (i = 0; i < 3; i++) cin >> a[i].x >> a[i].y; sort(a, a + 3, cmp); if (a[0].x == a[1].x) { for (i = a[0]....
8
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if ((a == 0) || (b == 0)) return a + b; return gcd(b, a % b); } long long pow_mod(long long a, long long b) { long long res = 1; while (b) { if (b & 1) res = (res * a) % 1000000007; a = (a * a) % 1000000007; b >>...
12
#include <bits/stdc++.h> using namespace std; long long calc(long long n) { long long i, res = n; for (i = 2; i <= sqrt(n); i++) if (n % i == 0) { while (n % i == 0) n /= i; res -= res / i; } if (n > 1) res -= res / n; return res; } int main() { long long n, k; cin >> n >> k; long long...
13
#include <bits/stdc++.h> using namespace std; static const int INF = 500000000; template <class T> void debug(T a, T b) { for (; a != b; ++a) cerr << *a << ' '; cerr << endl; } int n, k; long long int ans = 0; const long long int mod = 1000000007; int mig[10]; int state[10], vis[10]; bool rec(int v) { if (state[v...
7
#include <bits/stdc++.h> using namespace std; int dp[101][1 << 18], id[66], a[111]; int ans[101][1 << 18], b[111], p[111], mask[111]; int main() { int n, cnt = 0; for (int i = 2; i <= 60; i++) { int flag = 0; for (int j = 2; j < i; j++) if (i % j == 0) flag = 1; if (!flag) p[cnt++] = i; } for ...
12
#include <bits/stdc++.h> using namespace std; const int N = 1000006; int n; int a[N]; long long s[N]; int x[N]; long long y[N]; int top = 0; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &a[i]); for (int i = 1; i <= n; ++i) s[i] = s[i - 1] + a[i]; x[0] = y[0] = 0; for (int i = 1; i <=...
13
#include <bits/stdc++.h> using namespace std; inline long long read() { char c = getchar(); long long x = 0, f = 1; while (c > '9' || c < '0') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); } return x * f; } struct node { long...
11
#include <bits/stdc++.h> using namespace std; int a[30][30]; char st[110][110]; int in[30]; int main() { int n; scanf("%d", &n); for (int i = 0; i < n; ++i) scanf("%s", st[i]); memset(a, 0, sizeof(a)); for (int i = 0; i < n; ++i) for (int j = i + 1; j < n; ++j) { int l1 = strlen(st[i]); int l2...
8
#include <bits/stdc++.h> using namespace std; const int maxn = 3e3 + 15; const double eps = 1e-7; const int INF = 0x3f3f3f3f; long long read() { long long x = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = x * 10...
16
#include <bits/stdc++.h> using namespace std; int mod(int a, int b) { return a >= 0 ? a % b : (b + a % b) % b; } int dceil(int a, int b) { return (a + b - 1) / b; } struct Diff { int x; int y; long long v; }; long long calc(long long x, long long y, long long z) { long long xy = x - y; long long yz = y - z; ...
9
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { string s1, s2, s3; cin >> s1 >> s2 >> s3; int k = 1, n = s1.size(); for (int i = 0; i < n; i++) { if (s1[i] == s2[i]) { if (s1[i] != s3[i] || s2[i] != s3[i]) { k = 0; break; ...
0
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const int N = 2e5 + 5; inline int read() { int res = 0, ch, flag = 0; if ((ch = getchar()) == '-') flag = 1; else if (ch >= '0' && ch <= '9') res = ch - '0'; while ((ch = getchar()) >= '0' && ch <= '9') res = res * 10 + ch - '0...
12
#include <bits/stdc++.h> using namespace std; int main() { int n, m, voy, parado = 1; long long mov = 0; cin >> n >> m; for (int i = 0; i < m; ++i) { cin >> voy; mov += voy - parado; if (parado > voy) mov += n; parado = voy; } cout << mov; return 0; }
2
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N=2e5+10,M=1e9+7,OO=0x3f3f3f3f; int main(){ //freopen("haa.txt","r",stdin); //freopen("myfile.txt","w",stdout); int t; scanf("%d",&t); while(t--){ int n; scanf("%d",&n); vector<int> freq(N); ...
11
#include <bits/stdc++.h> using namespace std; double PI = 3.1415926536f; int main() { string a, b; cin >> a >> b; int i, j, n; i = 0; j = 0; n = b.size(); for (i = 0; i < n; i++) { if (b[i] == a[j]) { j++; } } cout << j + 1; return 0; }
0
#include <bits/stdc++.h> using namespace std; long long sqr(long long x) { return x * x; } long long n, m, k, tot, ans, sum; long long a[1005][1005]; long long sumx[1005], sumy[1005], costx[1005], costy[1005]; string st; char ch; long long calc(long long x, long long y) { if (x < y) return (y - x - 1) * 4 + 2; ...
10
#include <bits/stdc++.h> using namespace std; int main() { long long m, b; cin >> m >> b; long long c = b * m; long long ans = 0; for (long long i = 0; i <= c; i++) { long long y = b - ceil(i * 1.0 / m); long long cur = i * (i + 1) / 2 * (y + 1) + y * (y + 1) / 2 * (i + 1); ans = max(ans, cur); ...
5
#include <bits/stdc++.h> using namespace std; int mod = 1e9 + 7; long long Bpow(long long a, long long s) { if (s == 0) { return 1; } long long u = Bpow(a, s / 2); if (s & 1) return u * u % mod * a % mod; else return u * u % mod; } int main() { int n, m, q; cin >> n >> m >> q; vector<int> po...
12
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
17