func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int x = 1; while (n > 0) { if (n == 3) { cout << x << << x << << 3 * x << ; break; } else { for (int i = 0; i < (n + 1) / 2; i++) { cout << x << ; } ... |
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const double eps = 1e-9; const int inf = 2000000000; const long long infLL = 9000000000000000000; inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; } inline bool checkBit(long long n, int i) { return n & (1LL << i); } ... |
#include <bits/stdc++.h> using namespace std; const int INF = 123456789; template <class T> void scanint(T& x) { register int c = getchar(); x = 0; int m = 0; if (c == - ) { m = 1; } for (; (c < 48 || c > 57); c = getchar()) ; for (; c > 47 && c < 58; c = getchar()) { ... |
#include <bits/stdc++.h> using namespace std; int n, q, a[300005], ans[300005]; vector<pair<int, int> > queries[300005]; int tree[1200006]; void upd(int l, int r, int pos, int x) { if (l == r) { tree[pos]++; return; } int mid = l + r >> 1; if (x <= mid) upd(l, mid, pos << 1, ... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int tests; cin >> tests; for (int test = 0; test < (int)(tests); test++) { int n; cin >> n; map<int, int> m; for (int i = 0; i < (int)(n); i++) { int x; cin... |
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const long long inf64 = 1e18; const int N = 1e6 + 5; int n, m; vector<int> g[N], gr[N]; int ptr = 1; int del[N]; int mark[N]; void solve() { while (ptr <= n && del[ptr]) ptr++; if (ptr > n) return; int v = ptr++; for ... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int pre[N][32], suf[N][32], mx[N][32]; int n, a[N]; long long ans; void init() { for (int i = 0; i < n; i++) mx[i][0] = i; for (int i = 1; (1 << i) < N; i++) { for (int j = 0; j < n; j++) { mx[j][i] = (a[mx[j][i - 1]... |
#include <bits/stdc++.h> using namespace std; long long int n, m, k, dp[2020][2020]; long long int getDp(long long int x, long long int y) { if (x == n) return y == k; if (~dp[x][y]) return dp[x][y]; long long int &ret = dp[x][y] = 0; ret = getDp(x + 1, y); ret = (ret + (getDp(x + 1, y + 1) * ... |
#include <bits/stdc++.h> using namespace std; const int MX = 1 << 19; struct node { long long left, right, cnt, tot, length; }; struct segtree { node t[MX * 2]; node merge(node& l, node& r) { node ans; ans.left = l.left + r.left + l.length * r.cnt; ans.right = l.right + r.right +... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10, mod = 998244353; int n, p[N], c[N]; void add(int& x, int y) { x += y; if (x >= mod) { x -= mod; } } int mul(int x, int y) { return (long long)x * y % mod; } int qpow(int v, int p) { int result = 1; for (; p; p ... |
#include <bits/stdc++.h> using namespace std; const int N = 100100; int n, q; long long int m; vector<long long int> mods; long long int w[N]; long long int phi(long long int x) { long long int ans = x; for (long long int i = 2; i * i <= x; i++) { if (x % i == 0) { ans -= ans / i; ... |
#include <bits/stdc++.h> using namespace std; string s[1005]; long long int M[1005][1005], T[1005][1005]; queue<pair<long long int, long long int> > q; long long int xr[] = {0, 0, -1, 1}; long long int xc[] = {-1, 1, 0, 0}; int main() { ios_base::sync_with_stdio(false); cout.tie(0); cin.tie(0)... |
#include <bits/stdc++.h> using namespace std; int n, m, k, x, y, a, b, d[2010][2010], v[2010][2010]; bool solve(int x, int y, int k) { int l = max(1, x - k), r = min(x + k, n), t; for (int i = l; i < r + 1; i++) { t = k - abs(i - x); if (y - t > 0 && !v[i][y - t]) return a = i, b = y - t, 1; ... |
#include <bits/stdc++.h> using namespace std; vector<int> g[100100]; int a[100100], b[100100], s[100100]; int n, sa, sb; double ans; void dfs(int v, int p) { s[v] = 1; for (int i = 0; i < g[v].size(); i++) { int u = g[v][i]; if (u == p) continue; dfs(u, v); s[v] += s[u]; ... |
#include <bits/stdc++.h> using namespace std; const long long N = 1e9 + 7; const int P = 1e6 + 9; long long n, m; long long bin_pow(int a, int x) { if (x == 1) return a % N; if (x % 2 == 0) return (bin_pow(a, x / 2) * bin_pow(a, x / 2)) % N; if (x % 2 != 0) return (bin_pow(a, x - 1) * (a % N)) % N... |
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fll; const int MAX = 1e3 + 10; vector<int> g[MAX]; int qt[MAX]; int dfs(int i, int p = -1) { int ret = 1; for (int j : g[i]) if (j != p) ret += dfs(j, i); return qt[i] = ret;... |
#include <bits/stdc++.h> using namespace std; int a[100000]; int m[100001]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } m[n] = 1e9 + 1; for (int i = n - 1; i >= 0; i--) { m[i] = min(m[i + 1], a[i]); } for (int i = 0; i < n; i++) { ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int x, s = 0, t = 0, m, ans = 0, hp = 0; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; if (a[0] == 1) t++; else s++; for (int i = 1; i < n; i++) { if (a[i] != a[i - 1] && hp == 0) { ... |
#include <bits/stdc++.h> using namespace std; int main() { int a[11][11] = {0}, n; cin >> n; for (int i = 0; i < n; i++) { a[0][i] = 1; a[i][0] = 1; } for (int i = 1; i < n; i++) { for (int j = 1; j < n; j++) { a[i][j] = a[i - 1][j] + a[i][j - 1]; } } cout... |
#include <bits/stdc++.h> using namespace std; inline void boost() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } const long long maxn = 2e6 + 123; const long long inf = 1e9 + 123; const long long linf = 1e18 + 123; const long long mod = 1e9 + 7; const double eps = 1e-9; const d... |
#include <bits/stdc++.h> using namespace std; void mejor(int player, long long int k, int *arr, int n) { if (player == 0) { if (player + k >= n - 1) cout << n << endl; else { for (int i = 0; i < k; i++) { if (arr[player] < arr[player + 1 + i]) { mejor(player + 1... |
#include <bits/stdc++.h> int main() { int len, i, l = 0, r = 0, u = 0, d = 0, dif1, dif2; scanf( %d , &len); char str[101]; scanf( %s , str); for (i = 0; i < len; i++) { if (str[i] == L ) l++; else if (str[i] == R ) r++; else if (str[i] == U ) u++; ... |
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3f; const int MOD = (int)1e9 + 7; const int N = (int)1e6 + 7; const int M = (int)-1; int a[N], cnt[100]; int main() { int T; cin >> T; while (T--) { long long n; int m... |
#include <bits/stdc++.h> const int mod = 1000000007; const int seed = 131; char s[100005], t[1000005]; int hshv[1000005]; int powm(int a, int b) { int ret = 1; while (b) { if (b & 1) ret = 1LL * ret * a % mod; a = 1LL * a * a % mod; b >>= 1; } return ret; } void gethash(c... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) using namespace std; template <typename T> void ckmn(T& a, T b) { a = min(a, b); } template <typename T> void ckmx(T& a, T b) { a = max(a, b); } void rd(int& x) { scanf( %i , &x); } void rd(long long& x) { scanf( %lld , &x); } void rd(... |
#include <bits/stdc++.h> using namespace std; int n, q; int p[100001]; int sz[100001]; int bc[100001]; int top[100001]; int newi[100001]; int sr[100001]; vector<int> c[100001]; pair<int, int> zero = {0, -1e9}; pair<int, int> f(pair<int, int> x, pair<int, int> y) { return {x.first + y.first, ma... |
#include <bits/stdc++.h> using namespace std; int ch[300010][26]; int ans[300010], maxdep = 0; int N; int merge(vector<int> now) { int res = now.size() - 1; vector<int> next; for (int i = 0; i < 26; i++) { next.clear(); for (int j = 0; j < now.size(); j++) if (ch[now[j]][i]) ne... |
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 10; int par[maxn], sub[maxn], col[maxn]; vector<pair<int, int>> parHis, colHis, subHis; bool bad[maxn]; int c[maxn]; int root(int x) { while (x != par[x]) { x = par[x]; } return x; } int getCol(int x) { int res ... |
#include <bits/stdc++.h> using namespace std; using Int = long long; constexpr static int mod = 1e9 + 7; constexpr static int inf = (1 << 30) - 1; constexpr static Int infll = (1LL << 61) - 1; int Competitive_Programming = (ios_base::sync_with_stdio(false), cin.tie(nullptr), cout << fixed << se... |
#include <bits/stdc++.h> using namespace std; const int N = 500001; const int sqN = 708; int ans[N]; int fre[N]; int v[N]; int block[sqN]; int answer = 0; struct query { int l; int r; int idx; } Q[N]; bool comp(query &q1, query &q2) { if (q1.l / sqN != q2.l / sqN) { return q1... |
#include <bits/stdc++.h> using namespace std; const long long N = 5000; long long cumulative[N + 10], arr[N + 10][3]; signed main() { ios ::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n, q; cin >> n >> q; vector<pair<long long, long long> > pi; for (long long i = 0; i ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; long long int test = 1; for (int loop = 0; loop < test; loop++) { long long int num, val; cin >> num >> val; vector<long long int> arr; long ... |
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; const int MOD = 1e9 + 7; const int dx[4] = {0, 0, -1, 1}; const int dy[4] = {-1, 1, 0, 0}; const int N = 101; int n, m, a[N][N], psum[N][N], T; bool Check_1() { if (psum[1][m] == 0) return true; if (psum[n][1] == 0) return tr... |
#include <bits/stdc++.h> using namespace std; struct P { long long x, y; }; P rotate90(P a) { P b; b.x = -a.y, b.y = a.x; return b; } P ar[4], br[4], cr[4]; P add(P a, P b) { P c; c.x = a.x + b.x; c.y = a.y + b.y; return c; } long long dis(P a, P b) { return (a.x - ... |
#include <bits/stdc++.h> using namespace std; long long hit(long long n) { return ((1 + n) * n) / 2; } int main() { long long m, n; scanf( %lld%lld , &n, &m); long long hasilmin, hasilmax; hasilmin = hit(n / m) * (n % m) + hit(n / m - 1) * (m - n % m); hasilmax = hit(n - m); printf( %lld %... |
#include <bits/stdc++.h> using namespace std; long long int n, m, sx, sy, vx, vy; inline long long int extgcd(long long int a, long long int b, long long int &x, long long int &y) { if (!b) { x = 1; y = 0; return a; } long long int d = extgcd(b, a % b, x... |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:500000000 ) using namespace std; bool isq[22 * 22 * 22 * 22]; bool isSquare(int n) { return isq[n]; } int main() { int n, m; cin >> n >> m; for (int i = 1; i <= 22 * 22; i++) isq[i * i] = true; for (int columnLine = 0; columnLine <= m; c... |
#include <bits/stdc++.h> using namespace std; const int N = 5e3 + 5, M = 2e6 + 5, Mod = 1e9 + 7; int add(int a, int b) { return ((a += b) >= Mod) ? (a - Mod) : (a); } int gcd(int a, int b) { return (!b) ? (a) : (gcd(b, a % b)); } bool _pool[M << 1]; bool *_top = _pool; bool *alloc(int sz) { bool *top ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int t; cin >> t; while (t--) { long long int n; string s; cin >> n >> s; map<long long int, vector<long long int>> mp; for (long... |
#include <bits/stdc++.h> int min(int a, int b) { return a < b ? a : b; } int n, m, t1, t2, val[1024]; long long ans; int main() { scanf( %d%d , &n, &m); for (int i = 1; i <= n; i++) { scanf( %d , &val[i]); } for (int i = 1; i <= m; i++) { scanf( %d%d , &t1, &t2); ans += min(val... |
#include <bits/stdc++.h> using namespace std; int main() { long long a; cin >> a; for (int i = a; i >= 1; i--) { if (a % i == 0) { cout << i << ; a = i; } } } |
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; vector<long long> arr(n); for (int i = 0; i < n; i++) { cin >> arr[i]; } long long c = 0; for (int i = 0; i < n; i++) { c += arr[i] - 1; if (c % 2 == 0) cout << 2 << n ; ... |
#include <bits/stdc++.h> using namespace std; char cross[101][101]; int main() { int n; while (cin >> n) { for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> cross[i][j]; int ok = 0; for (int i = 1; i < n - 1; i++) { for (int j = 1; j < n - 1; j++) { ... |
#include <bits/stdc++.h> namespace std { template <typename...> using void_t = void; } template <typename T, typename _ = void> struct is_container : std::false_type {}; template <typename... Ts> struct is_container_helper {}; template <typename T> struct is_container< T, typename std::conditi... |
#include <bits/stdc++.h> using namespace std; struct no { int r; int l; int p; }; int main() { int n; double v; double a[110]; double b[110]; cin >> n >> v; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cin >> b[i]; if (b... |
#include <bits/stdc++.h> typedef long long ll; #define f(i,a,b) for(i=a;i<b;i++) using namespace std; int main() { ll n,i,sum=0, count=0; cin>>n; vector<ll> a(n); f(i,0,n) cin>>a[i]; priority_queue <int, vector<int>, greater<int>> p; f(i,0,n){ if(a[i]>=0) su... |
#include <bits/stdc++.h> using namespace std; int ml, mr, wl, wr; int main() { cin >> ml >> mr >> wl >> wr; if ((ml * 2 + 3 > wr && wr >= ml - 1) || (mr * 2 + 3 > wl && wl >= mr - 1)) { cout << YES ; return 0; } else { cout << NO ; return 0; } return 0; } |
#include <bits/stdc++.h> using namespace std; struct que { int l, r, y, val; bool operator<(const que &v) const { return y < v.y; } }; int n, k, x[100010], y[100010], cnt[100010 * 2], pre[100010 * 2]; long long ans[100010]; vector<que> q; vector<int> h; int main() { scanf( %d%d , &n, &k); ... |
#include <bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<int, int>; using vi = vector<int>; using vll = vector<ll>; using vii = vector<ii>; const ll MOD = 998244353; const ll INF = 1e15 + 9; const int MAXN = 1000006; int n, m, a[MAXN], p[MAXN], b[MAXN]; int ind[MAXN], se... |
#include <bits/stdc++.h> using namespace std; template <class T> inline T checkmin(T &a, T b) { return (a < b) ? a : a = b; } template <class T> inline T checkmax(T &a, T b) { return (a > b) ? a : a = b; } template <class T> T GCD(T a, T b) { if (a < 0) return GCD(-a, b); if (b < 0) re... |
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int a[1000005]; map<int, int> ht; map<int, int>::reverse_iterator its; long long mul(long long a, long long b) { long long res = 1; while (b) { if (b % 2 == 1) res = (res * a) % mod; a = (a * a) % mod; b /= 2; ... |
#include <bits/stdc++.h> #pragma GCC optimize( unroll-loops ) using namespace std; const long long N = 2e5 + 36; const long long M = 1e3 + 36; const long long INF = 2e9 + 7; const long long MOD = 987654323; const int X[8] = {1, 1, -1, -1, 2, 2, -2, -2}; const int Y[8] = {2, -2, 2, -2, 1, -1, 1, -1}; s... |
#include <bits/stdc++.h> using namespace std; mt19937 rd(chrono::steady_clock::now().time_since_epoch().count()); long long rand(long long l, long long r) { return uniform_int_distribution<long long>(l, r)(rd); } const int N = 49; int n, m, d[N][N]; int b[N]; signed main() { ios_base::sync_with_... |
#include <bits/stdc++.h> using namespace std; int n, m; const int N = 1e6, M = 1e6; pair<int, int> adj[M + 7]; long long val[N + 7]; long long sum[N + 7]; long long res = 0; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); void addRes(int numb) { res += 1LL * numb * (numb - 1) /... |
#include <bits/stdc++.h> using namespace std; bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); } long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } long long lcm(long long a, long long b) { return (a * b) / gcd(... |
#include <bits/stdc++.h> using namespace std; int inf = 1000000005; long long int llinf = 2000000000000000005LL; long long int mod = 1000000007; long long int mod9 = 1000000009; double pi = 3.1415926535897; double eps = 1e-15; int dx[] = {1, -1, 0, 0, 1, -1, 1, -1}, dy[] = {0, 0, 1, -1, 1, 1, -1, -1}; ... |
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { int t; cin>>t; int arra[10] = { 0, 3, 17, 151, 1117, 11941, 117653, ... |
#include <bits/stdc++.h> using namespace std; const long long oo = 1000000000000000000LL; const int N = 100005; vector<pair<int, int>> ds; long long data[2][100005]; int x[N], p[N], c[N], st[N]; long long val[N]; int main() { int n, m; scanf( %d%d , &n, &m); for (int i = 1; i <= n; i++) { ... |
#include <bits/stdc++.h> using namespace std; int n; double sv[500050]; struct info { int x, v; } A[500050]; int main() { scanf( %d , &n); int l = 0; for (int i = 0; i < n; i++) scanf( %d %d , &A[i].x, &A[i].v); int st = n, nd = -1; for (int i = 0; i < n; i++) if (A[i].v > 0) {... |
#include <bits/stdc++.h> using namespace std; long long ex(long long a, long long b) { long long tmp = 1; for (int i = 0; i < b; i++) { tmp = tmp * a; } return tmp; } int main() { long long r, l, tmp, ans = -1; bool good = 1; cin >> l >> r; for (long long i = l; i <= r; i++... |
#include <bits/stdc++.h> using namespace std; long long n, m; long long ar[1000001], dp[1001][1001]; long long calc(long long idx, long long rem) { if (rem == 0 && idx != 0) return 1; if (idx >= n) return 0; long long &b = dp[idx][rem]; if (b != -1) return b; else b = 0; b |=... |
#include <bits/stdc++.h> using namespace std; long long pow(long long a, long long b, long long MOD) { long long x = 1, y = a; while (b > 0) { if (b % 2 == 1) { x = (x * y); if (x > MOD) x %= MOD; } y = (y * y); if (y > MOD) y %= MOD; b /= 2; } return x;... |
#include <bits/stdc++.h> using namespace std; void solve() { long long int n; cin >> n; vector<long long int> s(2 * n); for (int i = 0; i < 2 * n; i++) cin >> s[i]; sort(s.begin(), s.end()); if (s[0] == s[2 * n - 1]) { cout << -1 << n ; return; } for (int i = 0; i < 2 *... |
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 10, LG = 45; long long n, ts, Mx, B[N], S[N]; struct Node { int32_t l, r, c; Node() { l = r = c = 0; } }; vector<Node> A; inline long long Creat() { return (ts++); } inline void Add(long long val, long long tp) { long lo... |
#include <bits/stdc++.h> using namespace std; int fuck[2010], de[2010], n; char mp[2010][2010]; int check() { sort(fuck + 1, fuck + 1 + n); int sum = 0; for (int i = 1; i < n; i++) { sum += fuck[i]; if (sum == i * (i - 1) / 2) return 0; } return 1; } int main() { cin >> n... |
#include <bits/stdc++.h> int n, a, b, p; char s[51]; int main(void) { scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d %s , &a, s); b = 0; p = a / 2; for (int j = 0; j < a; j++) { if (s[j] == ( ) { b++; } else { if (b > 0) { ... |
#include <bits/stdc++.h> using std::cin; using std::cout; using std::pair; using std::set; using std::sort; using std::string; using std::vector; int main() { int n, m; cin >> n >> m; vector<vector<pair<string, int>>> byreg(m); for (int i = 0; i < n; i++) { string a; int b, c... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1010; const int INF = 100000000; string str[maxn]; int dp[maxn][maxn]; int n, m, ans; int flag[maxn][maxn]; int dir[4][2] = {0, -1, 0, 1, 1, 0, -1, 0}; char ch[5] = { D , I , M , A }; vector<pair<int, int> > q; bool Ok(int ki, int k... |
#include <bits/stdc++.h> std::mt19937 rng( (int)std::chrono::steady_clock::now().time_since_epoch().count()); const int ms = 110000; const int bs = 1000; const int MOD = 998244353; void add(int &a, int b) { a = a + b < MOD ? a + b : a + b - MOD; } int *pivot; bool comp(int x1, int x2) { return pivot... |
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; long long int inverse(long long int i) { if (i == 1) return 1; return (MOD - ((MOD / i) * inverse(MOD % i)) % MOD + MOD) % MOD; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long m, n, x; ... |
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1.0); const double eps = 1e-8; const int inf = 1 << 30; const int mod = int(1e9) + 7; const int base = 257; const int maxn = 2005; int n, m, d[maxn][maxn], ans = -1, sx = -1, sy = -1; char c[maxn][maxn]; int get(int xa, int ya, in... |
#include <bits/stdc++.h> using namespace std; long long int dp[205][205][205]; long long int n, k; string s, t; char c1, c2; long long int solve(long long int pos, long long int k, long long int cnt) { if (pos >= n) { return 0; } if (dp[pos][k][cnt] != -1) return dp[pos][k][cnt]; long ... |
#include <bits/stdc++.h> using namespace ::std; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } long long add(long long a, long long b, long long m = 1000000007) { return (a % m + b % m + 2 * m) % m; } long long mul(long long a, long long b, long long m = 1000000007) { r... |
#include <bits/stdc++.h> using namespace std; void Rd(int &res) { res = 0; char p; while (p = getchar(), p < 0 ) ; do { res = (res * 10) + (p ^ 48); } while (p = getchar(), p >= 0 ); } void Max(int &x, int y) { if (x < y) x = y; } struct W { int to, nx, d; } Lis[1... |
#include <bits/stdc++.h> using namespace std; const long long int N = 70, M = 11, MA = 1030; long long int dp[M][N][M][MA], dps[M][N][MA], dpt[M][N], n, q, b, l, r, x; vector<long long int> v; long long int get(long long int a, long long int b) { long long int x = a, ans, mask = 0, l; v.resize(0); ... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast,no-stack-protector,unroll-loops,fast-math,O3 ) #pragma GCC target( sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx ) using namespace std; template <class U, class V> istream& operator>>(istream& is, pair<U, V>& p) { is >> p.first >> p.second; ret... |
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; int A[1 << 21], B[1 << 21]; long long level_index1[21]; long long level_index2[21]; long long mergesort(int begin, int end, int level) { if (begin == end) return 0; long long inv_index = 0; int middle = (begin + end) / 2; ... |
#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; int main() { int n, minn = 1000000, indx; cin >> n; int arr[n + 1]; for (int i = 1; i <= n; i++) cin >> arr[i]; for (int i = 1; i < n; i++) { if (abs(arr[i] - arr[i + 1]) < minn) { minn = abs(arr[i] - arr[i + 1]); indx = i; ... |
#include <bits/stdc++.h> const int maxn = 300 + 10; char st[maxn][maxn]; int n, m, p; int main() { scanf( %d%d%d , &n, &m, &p); for (int i = 1; i <= n; i++) scanf( %s , st[i] + 1); for (int k = 1; k <= n; k++) { for (int i = 1 + k; i + k <= n; i++) for (int j = 1 + k; j + k <= m; j++) ... |
#include <bits/stdc++.h> using namespace std; long long int power(long long int x, long long int y) { int temp; if (y == 0) return 1; temp = power(x, y / 2); if (y % 2 == 0) return temp * temp; else return x * temp * temp; } long long int fun(long long int n) { if (n == 0) ... |
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) using namespace std; struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t ope... |
#include <bits/stdc++.h> using namespace std; const int N = 5e3 + 7; long long M = 1e9 + 7; long long dp[N]; long long g[N][30]; int n; vector<int> a; int ch[N][N]; int main() { ch[0][0] = 1; cin >> n; for (int i = 1; i <= n; i++) { for (int j = 0; j <= i; j++) { if (j == 0) ... |
#include <bits/stdc++.h> using namespace std; bool a[2001][2001], w[2001][2001]; int n, fi, fj, si, sj, dist, s, clr = 4; inline bool val(int x, int y) { return (x > 0 && y > 0 && x < n && y < n); } inline void clear(int x, int y) { s = 0; for (int i = 0; i < clr; i++) for (int j = 0; j < clr; j... |
#include <bits/stdc++.h> using namespace std; const long long INF = 999999999; const long long INFL = 99999999999999999LL; const double EPSILON = 0.00000001; const long long MOD = 1000000007; long long a[100005]; int32_t main() { long long n, t; scanf( %I64d , &n); ; scanf( %I64d , &t); ... |
#include <bits/stdc++.h> using namespace std; int fr[200004]; struct cmp { bool operator()(int a, int b) const { return a > b; } }; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; auto make = [](vector<int>& a, int pos) { swap(a[pos + 2], a[pos + 1]); ... |
#include <bits/stdc++.h> using namespace std; void solve() { long long int x, y; cin >> x >> y; if (x == 1) { if (y <= 1) { cout << yes << endl; return; } else { cout << no << endl; return; } } else if (x == 2 || x == 3) { if (y <= 3) { ... |
#include <bits/stdc++.h> using namespace std; struct Bitset { int sz, len; vector<unsigned int> v; Bitset(int szz) { len = szz; sz = szz + 31 >> 5; v.clear(); v.resize(sz, 0); } Bitset operator<<=(int x) { int d = x >> 5, r = x & 31; for (int i = sz - 1; i >= ... |
#include <bits/stdc++.h> using namespace std; int n, m, t, i, j, k; long long a[2000005]; long long ans, sum; int main() { scanf( %d%d , &n, &m); for (i = 1; i <= m * 2; i++) { scanf( %d , &t); a[t]++; } for (i = 1; i <= n; i++) ans += a[i] * (n - 1 - a[i]); printf( %lld n , (l... |
#include <bits/stdc++.h> using namespace std; int mat[1010][1010]; int main() { int n, a, b; cin >> n >> a >> b; if (a > 1 && b > 1) { puts( NO ); return (0); } if (n > 1 && n <= 3 && a == 1 && b == 1) { puts( NO ); return (0); } puts( YES ); if (a == 1 && b... |
#include <bits/stdc++.h> using namespace std; int main() { long long T, n, k; cin >> T; while (T--) { cin >> n >> k; long long ans = 0; while (n) { if (n % k != 0) ans += n % k, n -= n % k; else ans++, n /= k; } cout << ans << endl; }... |
#include <bits/stdc++.h> using namespace std; int arr[100][100]; int row[100]; vector<pair<pair<int, int>, pair<int, int> > > v; int pos[30000][2]; int main() { int n; int sum = 0; while (scanf( %d , &n) == 1) { v.clear(); sum = 0; for (int i = 1; i <= n; i++) scanf( %d , &ro... |
#include <bits/stdc++.h> using namespace std; int n, a[3]; int dp[310][310]; string name[2] = { BitAryo , BitLGM }; int mem(int x, int y) { if (dp[x][y] != -1) return dp[x][y]; int mn = 1; for (int i = 1; i <= x; i++) mn = min(mn, mem(x - i, y)); for (int i = 1; i <= y; i++) mn = min(mn, mem(... |
#include <bits/stdc++.h> struct Point { double x, y; }; struct Polygon { Point p[100000]; int n; inline double get(int i, double x) { if (i < 0) return p[0].y; if (i >= n - 1) return p[n - 1].y; return p[i].y + (x - p[i].x) * (p[i + 1].y - p[i].y) / (p[i + 1].x - p[i... |
#include <bits/stdc++.h> using namespace std; struct edge { int from, to, vis, next; } e[400020]; int top, head[200020]; vector<int> g[200020]; int in[200020], gg[200020]; int n, m, k; int ans[200020], cnt; void add_edge(int from, int to) { e[++top].to = to; e[top].from = from; e[top].... |
#include <bits/stdc++.h> using namespace std; vector<long long> s; vector<long long>::iterator it; long long n, m, a; long long sum = 0; int main() { cin >> n >> m; for (long long i = 0; i < n; ++i) { cin >> a; s.push_back(a); sum += a; } if (m > sum) cout << -1 << en... |
#include <bits/stdc++.h> const double eps = (1e-9); using namespace std; int dcmp(long double a, long double b) { return fabsl(a - b) <= eps ? 0 : (a > b) ? 1 : -1; } int getBit(long long num, int idx) { return ((num >> idx) & 1ll) == 1; } int setBit1(int num, int idx) { return num | (1 << idx); } lon... |
#include <bits/stdc++.h> using namespace std; int log2(int x) { return 31 - __builtin_clz(x); } int main(void) { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); int n, q; cin >> n >> q; vector<long long> a(n); for (int i = 0; i < (int)(n); i++) { cin >> a[i]; } for... |
#include <bits/stdc++.h> using namespace std; int weight[11]; int total = 0; int bd2 = 0; int mem[11][5001]; int m; bool wasal = false; int arr[1001]; int knapsack(int i, int prev, int totalPrev, int me, int all, int counter) { arr[counter - 1] = prev; if (i == m) { wasal = true; b... |
#include <bits/stdc++.h> using namespace std; template <typename T> T cross(complex<T> a, complex<T> b) { return imag(conj(a) * b); } template <typename T> T dot(complex<T> a, complex<T> b) { return real(conj(a) * b); } struct __Query { static bool query; }; bool __Query::query = false; ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.