func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; struct node { int to, nxt, v; } e[1000005]; queue<int> que; int n, m, head[1000005], cnt, l, r, vis[1000005], pre[1000005], tot; int sum, ans[1000005], ppp, minn = 1023456789, dfn[1000005], id[1000005]; inline void add(int from, int to, int v) { e[++cn... |
#include <bits/stdc++.h> using namespace std; void exec() { int n, k; cin >> n >> k; map<int, int> es; for (int i = 1; i <= k + 1; i++) { string query = ? ; for (int j = 1; j <= k + 1; j++) { if (j == i) { continue; } query += + to_string(j); ... |
#include <bits/stdc++.h> using namespace std; string to_string(string s) { return + s + ; } string to_string(const char *s) { return to_string((string)s); } string to_string(bool b) { return (b ? true : false ); } template <typename A, typename B> string to_string(pair<A, B> p) { return ( + ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 105000; int a[maxn], ans[maxn]; int n, p, res1, res2; bool judge1(int k) { int sum = 0; for (int i = 1; i <= n; i++) { if (a[i] <= k) sum++; else { int tmp = a[i] - k; sum -= tmp; if (sum < 0) re... |
#include <bits/stdc++.h> using namespace std; int b[1100000], a[1100000], pre[1100000]; int main() { int n, m, k, i, j, s, cnt, len = 0, max = 0; long long ans = 0; scanf( %d%d%d , &n, &m, &k); for (i = 1; i <= m; ++i) { scanf( %d , &s); b[s] = 1; } b[n] = 1; for (i = 1; i ... |
#include <bits/stdc++.h> int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int32_t n, m, k; std::cin >> n >> m >> k; if (n % 2 == 0) { std::cout << Marsel n ; } else { bool avail = k == 1; for (int32_t i = 2; i * i <= m; ++i) { if (m % i == 0) { ... |
#include <bits/stdc++.h> using namespace std; const int N = 1 << 19; const double PI = acos(-1); int n, x; int a[N]; vector<long long> f, g, h; long long res[N]; int rev[N]; void calc_rev(int n, int logn) { for (int i = 0; i < n; ++i) { rev[i] = 0; for (int j = 0; j < logn; ++j) ... |
#include <bits/stdc++.h> using namespace std; int n, m, k, cla[30], a[200 + 5], hd[2 * 200 + 5], len = 0; char s[30]; struct Edge { int v, net; } e[2 * 160000 + 5]; void addi(int u, int v) { e[len] = (Edge){v, hd[u]}; hd[u] = len++; } void add(int u, int v) { addi(u, v); addi(v <= n ... |
#include <bits/stdc++.h> using namespace std; struct Exam { int s, d, c, id; bool operator<(const Exam &e1) const { return d < e1.d; } }; const int N = 105; int n, m, to[N]; Exam e[N]; int main() { cin >> n >> m; for (int i = 1; i <= m; i++) { cin >> e[i].s >> e[i].d >> e[i].c; ... |
#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 = 5007; const double eps = 0.00000001; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } template <typename T> ... |
#include <bits/stdc++.h> const double PI = acos(-1); using namespace std; template <class T> ostream& operator<<(ostream& out, vector<T> v) { out << v.size() << n ; for (auto e : v) out << e << n ; return out; } struct point { long long x, y; point() {} point(const point& a) { x ... |
#include <bits/stdc++.h> using namespace std; string s[51]; int n, m; bool check(int i, int j) { for (int k = 1; k <= n; ++k) if (s[k][j] == # && s[k] != s[i]) return false; return true; } signed main() { ios::sync_with_stdio(false); cin >> n >> m; for (int i = 1; i <= n; ++i) ci... |
#include <bits/stdc++.h> using namespace std; template <typename T> T gcd(T a, T b) { while (a > 0 && b > 0) { if (a > b) a %= b; else b %= a; } return a + b; } void YES_NO(bool YES_NO, bool isExit = true) { if (YES_NO) cout << YES << endl; else co... |
#include <bits/stdc++.h> int r, g, b; int mins; int total; int tour; int cycles; int main() { scanf( %d %d %d , &r, &g, &b); if (r >= 2) { r -= 2; } else if (r == 1) { r -= 1; } mins = 30; tour = 1; total = r + g + b; while (total > 0) { if (tour == 1) { ... |
#include <bits/stdc++.h> using namespace std; int cap[1000000], flow[1000000]; int to[1000000], _prev[1000000], last[10000], used[10000], level[10000]; struct MaxFlow { int V, E; MaxFlow(int n) { int i; V = n; E = 0; for ((i) = 0; (i) < (int)(V); (i)++) last[i] = -1; } vo... |
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; const long long LINF = 1e18; int n, m, k; bool noted[13]; bool connected[13][13]; int cnt = 0; set<long long> st; set<set<int>> sets; vector<int> vec[13]; long long pw[13]; bool visitedd[13]; map<long long, bool> visiteddd[13][... |
#include <bits/stdc++.h> using namespace std; char s[2000005], str[2000005]; int pre[2000005]; int find(int x) { return x == pre[x] ? x : pre[x] = find(pre[x]); } int main() { int n, q, x; while (scanf( %d , &n) != EOF) { for (int i = 1; i < 2000005; i++) pre[i] = i; int maxx = 0; wh... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 500; int n, s, deg[N], cnt; int main() { scanf( %d%d , &n, &s); for (int i = 1; i < n; i++) { int x, y; scanf( %d%d , &x, &y); deg[x]++; deg[y]++; } for (int i = 1; i <= n; i++) if (deg[i] == 1) cnt++... |
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 50; const int magic = 2500; struct Node { int from, to, delta, add; Node(int from, int to, int delta, int add) : from(from), to(to), delta(delta), add(add) {} }; int n, a[maxn], c[maxn], q[maxn], id[maxn], b[maxn], ans[maxn... |
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f, N = 3.1e5; int n, m, dis[N], fm[N]; vector<int> vec[N]; void bfs() { memset(dis, 0x3f, sizeof(dis)); queue<int> q; q.push(1); dis[1] = 0; while (!q.empty()) { int u = q.front(); q.pop(); for (int v ... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t-- > 0) { int n, m; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } int i = 0, t = 0, f = 0; while (i < n - 1) { if (a[0] != 1) { f = 1... |
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC target( popcnt ) using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<pair<char, int>> arr; for (int i = 0; i < 2 * n; i++) { char sym; cin >> sym; int ... |
#include <bits/stdc++.h> using namespace std; int main() { int q; cin >> q; int l[500], r[500], d[500], ans[500]; for (int i = 0; i < q; i++) { cin >> l[i] >> r[i] >> d[i]; int quo; if (d[i] < l[i]) { ans[i] = d[i]; } else { quo = int(r[i] / d[i]); ans... |
#include <bits/stdc++.h> using namespace std; long long n, v[100010], c[100010], l[100010], r, mx = 0; map<long long, long long> dp, path, acp; vector<long long> ans, vt[3 * 100010]; void getdp(long long x) { long long i, ss; dp.clear(); path.clear(); acp.clear(); for (i = 0; i < vt[x].siz... |
#include <bits/stdc++.h> using namespace std; const int N = 300005, M = 25; const long long p = 998244353ll; inline long long expo(long long a, int b = 998244351) { long long c = 1ll; while (b) { if (b & 1) c = c * a % p; b >>= 1; a = a * a % p; } return c; } long long FAC[... |
#include <bits/stdc++.h> using namespace std; void ga(int N, int *A) { for (int i(0); i < N; i++) cin >> A[i]; } int main(void) { ios_base::sync_with_stdio(false); string num; getline(cin, num); int ln = num.length(); int b = 0; int st = 0; int en = ln; bool dot = 0; for ... |
#include <bits/stdc++.h> using namespace std; int n, m; int a[1000005]; inline int Pow_Log(int x, int p) { int sol = 1; while (p) { if (p & 1) { sol = (1LL * sol * x) % 1000000009; --p; } p >>= 1; x = (1LL * x * x) % 1000000009; } return sol; } int mai... |
#include <bits/stdc++.h> using namespace std; long long int n, m, a, b, c, d, k, x, y, z, ans = 0, total = 0; long long int arr[201000] = {0}; int main(void) { cin >> n >> m; for (int i = 0; i < n; i++) cin >> arr[i]; sort(arr, arr + n); a = (n / 2); ans += abs(arr[a] - m); for (int i = ... |
#include <bits/stdc++.h> using namespace std; string file[10005]; unordered_map<string, pair<int, int> > ss; unordered_map<string, bool> sk; void deal(const string &in, int loc) { sk.clear(); int len = in.size(); string temp; for (int i = 1; i <= len; ++i) { for (int j = 0; j <= len - i;... |
#define DEBUG 0 #include <bits/stdc++.h> using namespace std; #if DEBUG // basic debugging macros int __i__,__j__; #define printLine(l) for(__i__=0;__i__<l;__i__++){cout<< - ;}cout<<endl #define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl #define printVar(n) cout<<#n<< : <<n<... |
#include <bits/stdc++.h> using namespace std; long long n, a[100069]; int main() { long long t, rr, i; bool bad; scanf( %lld , &t); for (rr = 0; rr < t; rr++) { scanf( %lld , &n); for (i = 1; i <= n * 4; i++) { scanf( %lld , a + i); } sort(a + 1, a + n * 4 + 1); ... |
#include <bits/stdc++.h> using namespace std; int n, m, len, kmpA[100010], ans, kmpB[100010], mxA[100010], mxB[100010]; char S[100010], A[100010], B[100010]; int main() { scanf( %s , S + 1); n = strlen(S + 1); scanf( %d , &m); while (m--) { scanf( %s , A); kmpA[0] = -1; len = s... |
#include <bits/stdc++.h> using namespace std; bitset<1005> tt[30]; unordered_map<bitset<1005>, int> ff; pair<bitset<1005>, int> ar[1000005]; int bc[1000005]; void print(bitset<1005> t) { for (int i = 0; i < 12; ++i) { if (t[i]) { putchar( 1 ); } else { putchar( 0 ); } ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; while (t--) { long long n1, n2, n3; cin >> n1 >> n2 >> n3; vector<long long> a, b, c; for (long long i = (0); i < (n1); i++) { ... |
#include <bits/stdc++.h> using namespace std; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); const int INF = 2e9; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, p; cin >> n >> p; vector<int> a(n); for (int i = 0; i < (int)(n); i++) cin >> a[i]; ... |
#include <bits/stdc++.h> using namespace std; int getReverted(int num) { bool bin[8] = {0}; for (int j = 0; num != 0; j++) { bin[j] = num % 2; num /= 2; } for (int j = 0; j < 8; j++) { num += (int)bin[j] * pow(2, 7 - j); } return num; } int strSize(char *str) { int ... |
#include <bits/stdc++.h> using namespace std; string getmin(string prev, string cur) { if (prev.length() < cur.length()) { for (int i = 0; i < cur.length(); i++) { if (cur[i] == ? ) cur[i] = (i == 0) ? 1 : 0 ; } return cur; } if (prev.length() > cur.length()) return ; ... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); int t, ang; cin >> t; while (t--) { cin >> ang; int ans = -1; for (int i = 3; i <= 360; ++i) { int k = ang * i / 180; if ((ang * i) % 180 == 0 && 360 % i == 0 && 1 <= k && k <= i - 2... |
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 1; char a[N], b[N]; vector<int> g[26]; bool vis[26][26]; vector<pair<char, char> > sol; char go[26]; int main() { scanf( %s%s , a, b); int n = strlen(a); for (int i = 0; i < n; ++i) { if (a[i] == b[i]) continue; in... |
#include <bits/stdc++.h> using namespace std; void solve() { int n, k; cin >> n >> k; long long a[n * k]; for (int i = 0; i < n * k; i++) { cin >> a[i]; } long long sum = 0; int jump = ((n + 1) / 2); if (n % 2 == 0) jump++; int count = 0; for (int i = n * k - jump; coun... |
#include <bits/stdc++.h> using namespace std; int main() { int n; string input, temp; bool f1, f2; cin >> n; getline(cin, input); for (int i = 0; i < n; i++) { f1 = false; f2 = false; getline(cin, input); if (input.length() > 4) { temp = input.substr(0, 5); ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } sort(arr, arr + n); int runsum = 0; int pen = 0; int k = 0; while (runsum <= 350 && ((runsum + arr[k]) <= 710) && k < n) runsum +... |
#include <bits/stdc++.h> using namespace std; int temp1[26]; int temp2[1001][26]; set<int> myset[1001]; set<int> empty; vector<int> myvec; int main() { int n; cin >> n; string str; cin >> str; int m; cin >> m; string arr[m]; for (int i = 0; i < m; i++) { cin >> arr[i]... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 100; vector<int> G[MAXN]; map<int, int> cnt; bool vis[MAXN]; int sz; int cN, c[MAXN], b[MAXN]; int dp[MAXN]; void dfs(int u) { vis[u] = true; sz++; for (int i = 0; i < G[u].size(); i++) { int v = G[u][i]; if (... |
#include <bits/stdc++.h> using namespace std; int read() { int xx = 0, ff = 1; char ch = getchar(); while (ch > 9 || ch < 0 ) { if (ch == - ) ff = -1; ch = getchar(); } while (ch >= 0 && ch <= 9 ) { xx = xx * 10 + ch - 0 ; ch = getchar(); } return xx * ff;... |
#include<bits/stdc++.h> #define pb push_back using namespace std; typedef long long ll; const int maxn=1e6+100; const int M=1000000007; typedef array<int,41> A; bool vis[50]; int f[50],n,mx,F[50][50],G[50][50],p[50],nf[50],inv[50]; int ways[50][50][50]; map<A,int> dp[41][41][41]; void add(int &x,i... |
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string s; cin >> s; long long l = s.length(); vector<char> s1; long long pos = -1; for (long long i = 0; i < l; i++) { if (s[i] == a ) pos = i; else ... |
#include <bits/stdc++.h> using namespace std; struct node { long long x, y; int id; bool operator<(const node& b) const { if (y != b.y) return y < b.y; else return x < b.x; } } a[210000], b[210000], c, d[210000]; vector<node> q; int n, num, last; int ans[210000]; ... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, a, b; cin >> n >> a >> b; int N = n; if (abs(a - b) > 1) { cout << -1 << n ; continue; } if (a + b > n - 2) { cout << -1 << n ; continu... |
#include <bits/stdc++.h> char str[110]; int main() { int len, t, _max = 0; scanf( %s , str); len = strlen(str); for (int i = 0; i < len; i++) for (int j = i + 1; j < len; j++) { t = 0; while (str[i + t] == str[j + t]) t++; if (t > _max) _max = t; } printf( %d ... |
#include <bits/stdc++.h> using namespace std; const long long N = 100; long long n, m, dp[N][N], a[N][N], b[N][N], c[N], len; char go[N][N][N]; char str[N << 1]; inline long long read() { long long sym = 0, res = 0; char ch = 0; while (!isdigit(ch)) sym |= (ch == - ), ch = getchar(); while ... |
#include<bits/stdc++.h> #define ll long long #define vi vector<int> #define vl vector<ll> #define pb push_back #define FASTANDFURIOUS ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); #define rep(i,a,b) for(ll i=a;i<b;i++) #define For(i,n) for(ll i=0;i<n;i++) #define MOD 1000000007 #define... |
#include <bits/stdc++.h> using namespace std; long long int a1, b1, a2, b2; int main() { scanf( %lld %lld , &a1, &b1); scanf( %lld %lld , &a2, &b2); long long int p, q, ans = 0; p = (a1 * b1); q = (a2 * b2); long long int tp = 0, tq = 0, thp = 0, thq = 0; while ((p % 3) == 0) { p... |
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; int t, k, l[1005], r[1005], lenl, lenr; long long f[1005][1005][2]; long long dfs(int *x, int Index, int d, int q, int lim) { if (Index < 1) return (long long)q; if (!lim && f[Index][d][q] != -1) return f[Index][d][q]; lo... |
#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 = ... |
#include <bits/stdc++.h> using namespace std; pair<pair<int, int>, int> a[100001]; pair<int, int> ans[100001]; int n, m, i, j, k, l, r, t, last, b[100001], x, y; map<int, pair<int, int> > mp; int main() { cin >> n >> m; for (i = 0; i < m; i++) { cin >> a[i].first.first >> a[i].first.second; ... |
#include <bits/stdc++.h> using namespace std; const int inv = 1000000000; const int minv = -inv; const int max_n = 500000 + 5; const int max_cn2 = max_n / 2 + 5; int n, cn2, fn2; int a[max_cn2]; int x; long long q[max_cn2]; int main() { scanf( %d , &n); cn2 = (n + 1) / 2; fn2 = n / 2; ... |
#include <bits/stdc++.h> using namespace std; const int INF = 1000 * 1000 * 1000 + 7; const long long LINF = 1LL * INF * INF; const int MAX = 1e5 + 7; const double PI = acos(-1.); const double EPS = 1e-7; const int MOD = 998244353; const int MAXF = 1000000000; int dx[] = {1, -1, 0, 0}; int dy[] = {0... |
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define mod 1000000007 int main(){ int n;cin>>n; int summ = 0; while(n>9){ int summ = 0; while(n>9){ summ = summ + n%10; n = n/10; } summ = summ + n; ... |
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); double d, L, v1, v2; cin >> d >> L >> v1 >> v2; double distance; int i, r; cout << fixed << setprecision(20) << (L - d) / (v1 + v2); return 0; } |
#include <bits/stdc++.h> using namespace std; int key; long long dis[1000]; struct pt { long long x, y, z; } f[8], point[8]; long long meow(int a, int b) { long long ta, tb, tc; ta = f[a].x - f[b].x; tb = f[a].y - f[b].y; tc = f[a].z - f[b].z; return (ta * ta + tb * tb + tc * tc); ... |
#include <bits/stdc++.h> using namespace std; template <typename T> void read(T &x) { x = 0; char c; for (c = getchar(); !isdigit(c); c = getchar()) ; for (; isdigit(c); c = getchar()) x = x * 10 + c - 0 ; } const int N = 255, P = 998244353, oo = 0x3f3f3f3f; int mul(int a, int b) { re... |
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; const int MX = 3001; map<pair<int, int>, bool> forbidden[MX]; struct Graph { int d[MX][MX]; int parent[MX][MX]; vector<int> adj[MX]; void addEdge(int u, int v) { adj[u].push_back(v); adj[v].push_back(u); } v... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cout.tie(0); cin.tie(0); cout.precision(10); bool vozr = 1, ub = 1, same; int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; if (i != 0 && a[i] > a[i - 1]) u... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n; while (cin >> n) { string s; cin >> s; long long a0 = 0, a1 = 0, a2 = 0; for (long long i = 0; i < s.size(); i++) { if (s[i] == 0 ) { ... |
#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 << endl; err(++it, args...); } int main() { ios_base::sync_with_stdio(false); ci... |
#include <bits/stdc++.h> using namespace std; const int N = 1e+6 + 5; int lp[N], ans = 1e+9; set<int> factors; void factorise(int n, int isv) { int cnt = 0, ans = 0, n1 = n; while (n % 2 == 0) { cnt++; n = n / 2; } if (cnt) { ans = max(ans, 2); if (isv) factors.insert(2... |
#include <bits/stdc++.h> using namespace std; int a, s, d, f, g, h, j, k, l, i, n, m; int main() { cin >> n >> m >> k; l = n * m * k / 100; for (i = 0; i < n; i++) { if (l > m) { cout << m; l = l - m; } else if (l > 0) { cout << l; l = 0; } else ... |
#include<bits/stdc++.h> using namespace std; #define ll long long template <typename Arg1> //print with endl void pn(Arg1&& arg1) { cout<<arg1<< n ;} template <typename Arg1, typename... Args> void pn(Arg1&& arg1, Args&&... args) { cout<<arg1<< n ; pn(args...); } //print with space template <ty... |
#include <bits/stdc++.h> using namespace std; char str[40], ans[2][40], p[40]; int pre[40], sum[40]; int main() { scanf( %s , str); int L = 0, R = 0; bool mark = true; memset(pre, -1, sizeof(pre)); for (int i = 0; i < 27; i++) { int a = str[i] - A ; sum[a]++; if (pre[a] ==... |
#include <bits/stdc++.h> using namespace std; int N; vector<int> V; bool Do() { while (V.size() > 0 && V.back() % 2 == 0) V.pop_back(); if (V.size() == 0) return false; int sum = 0; int p = -1; for (int i = 0; i < V.size(); ++i) { if (V[i] % 2 && i < V.size() - 1) p = i; sum += V... |
#include <bits/stdc++.h> using namespace std; void toogle(vector<vector<int> >& v, int i, int j) { if (v[i][j] == 1) { v[i][j] = 0; } else if (v[i][j] == 0) { v[i][j] = 1; } } int main() { vector<vector<int> > v(3, vector<int>(3, 1)); int i, j, e; for (i = 0; i < 3; i++) { ... |
#include <bits/stdc++.h> using namespace std; struct edge { int to, next; } e[200010]; int n, m, q, cnt, father[100010], fa[100010][30], a[100010], dis[100010], deep[100010], head[100010]; inline void add(int u, int v) { cnt++; e[cnt].to = v; e[cnt].next = head[u]; head[u] = cnt; }... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int n, x; vector<int> a, b, c; cin >> n; for (int i = 0; i < n; i++) { cin >> x; if (x == 1) a.push_back(i + 1); else if (x == 2) b.push_back(i + 1); else c.pus... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; const int N = 1e6 + 100; pair<int, int> seg[4 * N]; int lazy[4 * N]; void shift(int nod) { lazy[nod * 2] += lazy[nod]; lazy[nod * 2 + 1] += lazy[nod]; seg[nod * 2].first += lazy[nod]; seg[nod * 2 + 1].first += lazy[n... |
#include <bits/stdc++.h> using namespace std; int a[1000001] = {0}, n; int main() { cin >> n; long long sum = 0; long s = 0, s1 = 0, s2 = 0, s3 = 0; for (int k = 1; k <= n; ++k) { cin >> a[k], sum += a[k]; if (a[k] == 1) ++s; else if (a[k] == 2) ++s1; else i... |
#include <bits/stdc++.h> using namespace std; int main() { int n; long long k; cin >> n >> k; k -= (long long)n * (n + 1) / 2; if (k < 0) { cout << -1 << endl; return 0; } long long sum = (long long)n * (n + 1) / 2; vector<int> ans; for (int i = n - 1; i >= 0; i--) { ... |
#include <bits/stdc++.h> using namespace std; const int N = 1e4 + 10; int cnt[100 + 2][N + 2]; string s[100 + 2]; set<int> on[100 + 2], of[100 + 2]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> s[i]; s[i... |
#include <bits/stdc++.h> using namespace std; long long mod = 998244353; struct bucket { long long size, minm; vector<long long> off; vector<long long> dps; vector<long long> pre; bucket(long long b) { size = b; off = vector<long long>(b); pre = vector<long long>(b); dp... |
#include <bits/stdc++.h> using namespace std; char s[100005]; int main() { int n; cin >> n; int k = min(n, 4); for (int i = 0; i < k; i++) for (int j = i; j < n; j += 4) s[j] = i + a ; s[n] = 0 ; cout << s << endl; return 0; } |
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j, s = 0, o; cin >> n; char *a[n + 1], str[n + 1]; for (i = 0; i < n; i++) { cin >> str; a[i] = (char *)malloc(n + 1); strcpy(a[i], str); } for (i = 0; i < n && s == 0; i++) for (j = 0; j < n && s ==... |
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int SIZE = 1e6 + 10; vector<pair<int, int> > headd[10][2]; bitset<10000000> used; int ad[10000000]; bool valid(long long x) { int lt = x % 10; x /= 10; int flag = 0; while (x) { int tmp = x % 10; x /= ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int foot = n / 36; float b = n % 36; int kkk = b / 3; double kk = kkk + 0.5; float inch = b / 3; if (inch >= kk) inch = ceil(inch); else if (inch < kk) inch = floor(inch); int sss = (float... |
#include <bits/stdc++.h> using namespace std; const double pi = 3.14159265359; long long max(long long a, long long b) { if (a >= b) return a; else return b; } long long min(long long a, long long b) { if (a <= b) return a; else return b; } bool valid(int i, int j, ... |
#include <bits/stdc++.h> using namespace std; string a, b; int f1[100005], f2[100005], res, p1, p2, k, dp2[100005]; int main() { cin >> a >> b; int n = a.length(); int m = b.length(); a = # + a; b = # + b; int p = 1; for (int i = 1; i <= m; i++) { if (p > n) break; wh... |
#include <bits/stdc++.h> using namespace std; template <typename INT> struct TripleDXY { INT d, x, y; TripleDXY(INT _d = 0, INT _x = 0, INT _y = 0) : d(_d), x(_x), y(_y) {} }; template <typename INT> TripleDXY<INT> egcd(INT a, INT b) { bool neg_a = a < 0; if (neg_a) a = -a; bool neg_b = ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); string s1; cin >> s1; string s2; cin >> s2; string s3; cin >> s3; vector<pair<char, int> > cnt(26); for (int i = int(0); i < int(int(s1.size())); i++) { char c = s1[i]; ... |
#include <bits/stdc++.h> using namespace std; long long ar[5000005]; int main() { string s; cin >> s; long long sz = s.size(); long long cnt = 0; for (int i = 0; i < sz; i++) { long long l = 0, w = 0; for (int j = i; j < sz; j++) { if (s[j] == ( ) l++; el... |
#include <bits/stdc++.h> using namespace std; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __prin... |
#include <bits/stdc++.h> #define il inline #define ll long long const int N=2e5+5,B=316; int n,q,b[N],c[N]; ll a[N],lz[N]; il int jump(int x){return x?std::max(a[x]-lz[x/B],0ll):-1;} il void rebuild(int x,int v) { if (c[x]+v>B) return ; c[x]+=v; int i; for (i=x*B; i<x*B+B; i++) b[i]=jump(i)... |
#include <bits/stdc++.h> using namespace std; struct pi { bool dir; int node; int edge; }; const int mxn = 200005; int n; vector<pi> graph[mxn]; int dp1[mxn]; vector<int> vv; int ans = 1000000000; void dfs1(int v, int p) { for (int i = 0; i < graph[v].size(); i++) { pi u = grap... |
#include <bits/stdc++.h> using namespace std; using ll = long long; using pi = pair<ll, ll>; const ll inf = 0x3f3f3f3f3f3f3f3f; const ll minf = 0xc0c0c0c0c0c0c0c0; ll A[400400]; ll B[400400]; inline bool between(ll le, ll ri, ll first) { return le <= first && first <= ri; } signed main() { i... |
#include <bits/stdc++.h> using namespace std; void work(); int main() { work(); return 0; } char S[222222]; char T[222222]; int t[256][256]; void work() { int n; while (scanf( %d , &n) == 1) { memset(t, 0, sizeof(t)); int ans = 0; scanf( %s%s , S + 1, T + 1); for ... |
#include <bits/stdc++.h> using namespace std; int h; int seq[200010]; int par[200010]; int cur, cur_par, rem = -1, rem_par; int main() { scanf( %d , &(h)); for (int i = 0; i < h + 1; i++) scanf( %d , &(seq[i])); cur_par = 1; cur = 1; for (int i = 0; i < h; i++) { if (rem == -1 && s... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 10; long long a[MAXN], dp[MAXN]; int main() { long long n, ans = 0; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = n - 2; i >= 0; i--) { dp[i] = dp[i + 1]; if (a[i + 1] == 0) dp[i]++; } for ... |
#include <bits/stdc++.h> using namespace std; void FastIO() { ios_base::sync_with_stdio(false); cin.tie(0); cout.precision(20); } int main() { FastIO(); int A, B; while (cin >> A >> B) { int M = min(A, B); int N = max(A - M, B - M); cout << M << << N / 2 << endl; ... |
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; int n, m, a[16][11234], b[16][16], c[16][16], dp[1 << 16][16]; void solve(int u) { for (int i = 0; i < 1 << n; ++i) for (int j = 0; j < n; ++j) dp[i][j] = 0; dp[1 << u][u] = inf; for (int i = 0; i < 1 << n; ++i) fo... |
#include <bits/stdc++.h> using namespace std; long long m, loc, t; long long now; class SegTree { private: long long F2(long long k) { return 1 << (long long)ceil(log2(k)); } vector<long long> seg; void Merge(long long cur) { seg[cur] = seg[2 * cur] + seg[2 * cur + 1]; } public: SegTree... |
#include <bits/stdc++.h> using namespace std; int n, T, t[1005] = {0}, v; int main() { std::ios::sync_with_stdio(false); scanf( %d , &n); for (int i = 1; i <= n; i++) { scanf( %d , &v); t[v]++; } scanf( %d , &T); int ans = 0, sum = 0; for (int i = 1; i <= 1000; i++) { ... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int q; cin >> q; while (q--) { int n, k; cin >> n >> k; int s[n]; char c; for (int i = 0; i < n; i++) { cin >> c; if (c == R ) ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.