func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; const int MAXN = 3e5 + 5; vector<int> adj[MAXN]; vector<pair<int, int>> q[MAXN]; int n, m; long long ans[MAXN], depval[MAXN]; void dfs(int u, int dep, int pre, long long cur) { for (auto pr : q[u]) { depval[dep] += pr.second; if (dep + pr.first... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 300 + 5; const int MBIT = 15 + 5; const int INF = 0x3f3f3f3f; int n, m, MT, dp[MBIT][MAXN][MAXN]; int ans[2][MAXN][MAXN]; inline void umax(int& a, const int& b) { a = max(a, b); } void init() { MT = (int)floor(log2((long double)n)); ... |
#include <bits/stdc++.h> using namespace std; bool matrix[2005][2005]; int main() { ios::sync_with_stdio(false); int n, m, k; cin >> n >> m >> k; string s; getline(cin, s); for (int y = 0; y < n; y++) { getline(cin, s); for (int x = 0; x < m; x++) matrix[x][y] = s[x] == . ; ... |
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18; const long long Mod = 1e9 + 7; const long double Pi = acos(-1); long long n, m, k; struct Weapon { long long Pow, Val; } a[200009], b[200009]; struct Monster { long long Att, Def, Val; } c[200009]; bool Cmp1(Weapon x, ... |
#include <bits/stdc++.h> using namespace std; int n, q = 524288, p, ans = 1, lz; int s[1048576], r[1048576]; int getsum(int t) { if (t >= q) { if (r[t] > lz - q) { return 0; } else { return s[t]; } } if (r[t] <= lz - q) { return s[t]; } else if (r[t * 2] <... |
#include <bits/stdc++.h> using namespace std; const int INF = 2147483647; const long long LLINF = 9223372036854775807LL; const int maxn = 100010; const int mod = 1000000007; int psum[7][maxn]; int t[7][maxn * 4]; bool needset[7][maxn * 4]; int tset[7][maxn * 4]; int a[maxn]; inline int calcsum(int... |
#include <bits/stdc++.h> using namespace std; map<string, int> mp; int n, m; int a[110], b[110]; int main() { while (~scanf( %d%d , &n, &m)) { mp.clear(); for (int i = 0; i < (n); ++i) scanf( %d , a + i); for (int i = 0; i < (m); ++i) { string s; cin >> s; mp[s]++... |
#include <bits/stdc++.h> using namespace std; const int maxn = 250000 + 5; long long dp[maxn]; int main() { long long n, m; scanf( %lld %lld , &n, &m); dp[0] = dp[1] = 1; for (long long i = 2; i <= n; i++) { dp[i] = ((dp[i - 1] % m) * (i % m)) % m; } long long sum = 0; for (lon... |
#include <bits/stdc++.h> using namespace std; long n; vector<long> prec; int main() { ios_base::sync_with_stdio(0); prec.push_back(2); prec.push_back(7); prec.push_back(2); prec.push_back(3); prec.push_back(3); prec.push_back(4); prec.push_back(2); prec.push_back(5); prec... |
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); string s; cin >> s; int a[s.length()]; int n = s.length(); int ans = 0; for (int i = 0; i < n; i++) { int x = s[i] - ... |
#include <bits/stdc++.h> using namespace std; int cnt[1005]; vector<long long int> csum; string str; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; int m; cin >> n >> m; long long int x; cin >> x; csum.push_back(x); for (int i = 1; i < n; i++) { cin... |
#include <bits/stdc++.h> using namespace std; vector<vector<int> > init(int n, int v) { vector<vector<int> > ret; for (int i = 0; i < (n); ++i) { vector<int> l; l.resize(n); for (int j = 0; j < (n); ++j) l[j] = v; ret.push_back(l); } return ret; } void dump(const vector<v... |
#include <bits/stdc++.h> using namespace std; int main() { long long n, m, a, b; cin >> n >> m >> a >> b; if (n % m == 0) { cout << 0; } else { long long j = n % m; cout << min(j * b, (m - j) * a); } return 0; } |
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c, n; cin >> a >> b >> c >> n; int d = n - (a + b - c); if ((a - c) >= 0 && (b - c) >= 0 && c >= 0 && d > 0) { cout << d << endl; } else cout << -1 << endl; return 0; } |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; const int inf = 0x3f3f3f3f; int b[maxn]; int a[maxn]; int ma[maxn]; int pre[maxn * 10]; int _find(int x) { return x == pre[x] ? x : pre[x] = _find(pre[x]); } void _union(int x, int y) { x = _find(x), y = _find(y); if (x < ... |
#include <bits/stdc++.h> using namespace std; const int M = 1e9 + 7, N = 1e6 + 5; char a[51][51]; int n, m; int vis[51][51]; void dfs(int i, int j) { vis[i][j] = 1; if (i - 1 >= 0 and a[i - 1][j] == # and vis[i - 1][j] == 0) dfs(i - 1, j); if (i + 1 < n and a[i + 1][j] == # and vis[i + 1][j]... |
#include <bits/stdc++.h> using namespace std; struct Tree { long long maxv[80005]; void pushup(int x) { maxv[x] = max(maxv[x << 1], maxv[x << 1 | 1]); } void update(int x, int l, int r, int p, long long v) { if (l == r) { maxv[x] = v; return; } if (p <= ((l + r) >> 1)) ... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5, oo = 0x3f3f3f3f; const long long M = 1e12 + 105; int dx[] = {1, 0, -1, 0}; int dy[] = {0, -1, 0, 1}; int main() { int c, r, ans = 0; scanf( %d %d , &r, &c); char second[r][c]; for (int i = 0; i < r; i++) scanf( %s , second[... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 300005; int sum; int main() { int n, k; scanf( %d%d , &n, &k); for (int i = 0, x; i < n; ++i) scanf( %d , &x), sum += x; for (int i = 0;; ++i) { if (2 * sum >= (2 * k - 1) * (n + i)) { printf( %d n , i); break; ... |
#include <bits/stdc++.h> using namespace std; int64_t pre[200001]; int64_t dp[200001]; int n; int main() { cin >> n; for (int i = 1; i <= n; ++i) { cin >> pre[i]; pre[i] += pre[i - 1]; } int64_t mx = -1e15; for (int i = n - 1; i >= 1; --i) { dp[i] = max(pre[n], mx); ... |
#include <bits/stdc++.h> using namespace std; string s[3]; int l[3]; int a[101][101][101]; int d[101][101][101]; int e[101][26]; int go(int x, int y, int z) { if (a[x][y][z] != -1) return a[x][y][z]; if (z == l[2]) return -1e9; if (x == l[0] || y == l[1]) return 0; int &r = a[x][y][z]; ... |
#include <bits/stdc++.h> using namespace std; long long int m = 1000000007; int size = 1000004; bool mo(long long int n) { int t = 0; while (n) { if (n % 10 == 3) t++; n = n / 10; } if (t >= 3) return true; else return false; } int main() { long long int n; ... |
#include <bits/stdc++.h> using namespace std; const int N = 1 << 16; int n, xa, xb, a[20], b[20], ca[N], cb[N], f[N][140], ans = 0x7fffffff; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n; char c; for (int i = 1; i <= n; i++) { cin >> c >> a[i] >> b[i]; xa +=... |
#include <bits/stdc++.h> using namespace std; int n, m, k; string A[505]; bool a[505][505]; int star[505][505]; int col[505][505]; int main() { cin >> n >> m >> k; for (int i = 0; i < n; i++) cin >> A[i]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) a[i][j] = A[i][j] == 1 ; ... |
#include <bits/stdc++.h> using namespace std; bool comp(int a[2], int b[2]) { if (a[0] != b[0]) return a[0] > b[0]; else return a[1] > b[1]; } int main() { int n; cin >> n; int ob[n][2], cl[n][2]; for (int i = 0; i < n; i++) { cin >> ob[i][0] >> ob[i][1]; } for ... |
#include <bits/stdc++.h> using namespace std; const long long A = 100000000000000LL, N = 300228; long long t[N * 4], i, j, n, m, a[N], p[N], o, b, l, r; void modi(long long v, long long l, long long r, long long p, long long g) { if (p < l || p > r) return; if (l == r) { t[v] = g; return; ... |
#include <bits/stdc++.h> using namespace std; bool desc(pair<long long, long long> a, pair<long long, long long> b) { return a.first > b.first; } long long counter = 0, countedge = 0; void addEdge(vector<long long> adj[], long long u, long long v) { adj[u].push_back(v); adj[v].push_back(u); } ... |
#include <bits/stdc++.h> using namespace std; int n, q, a[2000000], f[2000000], fst[2000000], nx[2000000]; int main() { srand(time(0)); scanf( %d %d , &n, &q); for (int i = 1; i <= n; i++) scanf( %d , &a[i]); for (; q--;) { long long b; cin >> b; int answer = 2e9, j = 1; lo... |
#include <bits/stdc++.h> using namespace std; const int N = 100000 + 10; int n; int a[N], indexes[N], parent[N], rrank[N], ccount[N]; bool used[N]; int get_set(int v) { if (v == parent[v]) return v; return parent[v] = get_set(parent[v]); } void create_set(int v) { parent[v] = v; rrank[v]... |
#include <bits/stdc++.h> using namespace std; long long int m; long long int power(long long int x, long long int y) { long long int res = 1; while (y > 0) { if (y & 1) res = res * x; res %= m; y = y >> 1; x = x * x; x %= m; } return res; } long long int inv(long ... |
#include <bits/stdc++.h> using namespace std; int n, m; long long u; long long a[1000]; long long d[1000]; long long minn = -1e17; int main() { scanf( %d%d , &n, &m); for (int i = 1; i <= n; ++i) { scanf( %lld , &a[i]); d[i] = minn; } for (int i = n; i >= 0; --i) { for (i... |
#include <bits/stdc++.h> using namespace std; const long double EPS = 1E-9; const int INF = (int)1E9; const long long INF64 = (long long)1E18; const long double PI = 2 * acos(.0); int main() { bool cumple[1005]; for (int i = 0; i < (int)(1005); i++) cumple[i] = false; string word; cin >> wor... |
#include <bits/stdc++.h> using namespace std; int n, m, a[100][100], f[2000000], p; char s[30][30]; int main() { scanf( %d%d , &n, &m); for (int i = 0; i < n; i++) scanf( %s , s[i]); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) scanf( %d , &a[i][j]); memset(f, 0x3f, sizeof(f)); ... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t--) { int n, k; cin >> n >> k; string s; cin >> s; vector<int> pos; vector<int> v; fo... |
#include <bits/stdc++.h> using namespace std; int n, m; int a[300005], w[300005]; long long ksm(long long a, long long b) { if (!b) return 1; long long ns = ksm(a, b >> 1); ns = ns * ns % 998244353; if (b & 1) ns = ns * a % 998244353; return ns; } long long dp[3005][3005]; int main() {... |
#include <bits/stdc++.h> using namespace std; int ToInt(string& s, int len) { int r = 0; for (int i = 0, max_ = (len); i < max_; ++i) { r *= 10; r += s[i] - 0 ; } return r; } int GCD(int a, int b) { return b != 0 ? GCD(b, a % b) : a; } int LCM(int a, int b) { return a * (b / GCD(a... |
#include <bits/stdc++.h> using namespace std; int main() { bool flag = true; int n, m; cin >> n; cin >> m; char prev; for (int i = 0; i < n; i++) { string row; cin >> row; if (i != 0 && row[0] == prev) { flag = false; } for (int j = 1; j < m; j++) { ... |
#include <bits/stdc++.h> using namespace std; vector<int> v[100010], ans; int idx = 1; void dfs(int cur, int prev) { if ((int)v[cur].size() == 1 && cur != idx) ans.push_back(cur); else { for (int i = 0; i < (int)v[cur].size(); i++) { int j = v[cur][i]; if (j != prev) dfs(j, c... |
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f, mod = 1000000007; const double pi = 3.1415926535897932, eps = 1e-6; void chmax(int &x, int y) { if (x < y) x = y; } void chmin(int &x, int y) { if (x > y) x = y; } int B = 333; int n, top = 101000, cnt; string s[100005... |
#include <bits/stdc++.h> using namespace std; const int MAXn = 100 + 13; int n, k, t[MAXn]; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> t[i]; cin >> k; sort(t, t + n); int i = 0, j = 0, d = 0, num = 0, ans = 0; while (j < n) { d = t[j++] - t[i]; while (d > k) d ... |
#include <bits/stdc++.h> using namespace std; int ans[200010]; int main() { int n; cin >> n; if (n & 1) { puts( YES ); bool f = true; for (int i = 0; i < n; i++) { if (f) ans[i + n] = (i + 1) * 2, ans[i] = (i + 1) * 2 - 1; else ans[i] = (i + 1) * 2... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long q; cin >> q; while (q--) { long long a, b, m; cin >> a >> b >> m; if (a == b) { cout << 1 << << a << n ; continue; } ... |
#include <bits/stdc++.h> using namespace std; long long n, m, p, d[100005], sum[100005], f[105][100005], s[100005], a[100005], q[100005], head, tail, g[100005]; inline long long getint() { long long x = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ) { if (ch == - ) f = -1; ... |
#include <bits/stdc++.h> using namespace std; int main() { bool c5 = true; string s; cin >> s; int d = s.length(); for (int i = 0; i <= d; i++) { for (char a = a ; a <= z ; a++) { c5 = true; s.insert(i, 1, a); int d1 = s.length(); for (int j = 0; j < d1 / ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<pair<int, int> > j(n); for (int i = 0; i < n; i++) { cin >> j[i].first; j[i].second = i; } sort(j.begin(), j.end()); if (n == 1) cout << ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; int vas = min(n, m); int pet = n + m - 1 - vas; cout << pet << << vas; } |
#include <bits/stdc++.h> using std::cin; using std::cout; using std::endl; using std::ifstream; using std::max; using std::min; using std::ofstream; using std::string; int dp[2204][2204]; int vec[21][2]; int x, y, vec_num_n, max_dist_d; int dfs(int ori_x, int ori_y, int off_x, int off_y) { i... |
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; const int mod = 998244353; int read() { int 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 << 1) + (x << 3) + c - 0 , ... |
#include <bits/stdc++.h> using namespace std; int main() { long long n, d, m; cin >> n >> d >> m; long long ans = 0; long long a[n]; vector<long long> big, small; for (long long i = 0; i < n; i++) cin >> a[i]; for (long long i = 0; i < n; i++) { if (a[i] > m) big.push_back(... |
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using D = double; using uint = unsigned int; template <typename T> using pair2 = pair<T, T>; using pii = pair<int, int>; using pli = pair<ll, int>; using pll = pair<ll, ll>; mt19937 rng(chrono::steady_clock... |
#include <bits/stdc++.h> using namespace std; using ull = unsigned long long; using ll = long long; using ld = long double; using vi = vector<ll>; using vvi = vector<vi>; using vb = vector<bool>; using ii = pair<ll, ll>; constexpr bool LOG = false; void Log() { if (LOG) cerr << n ; } templ... |
#include <bits/stdc++.h> using namespace std; template <class T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf( %d , &x); } void _R(long long &x) { scanf( %lld , &x); } void _R(double &x) { scanf( %lf , &x); } void _R(char &x) { scanf( %c , &x); } void _R(char *x) { scanf( %s , x); } void... |
#include <bits/stdc++.h> using namespace std; int main() { long long d1, d2, d3; cin >> d1 >> d2 >> d3; long long x1 = d1 + d2 + d3; long long x2 = d1 + d1 + d2 + d2; long long x3 = d1 + d1 + d3 + d3; long long x4 = d2 + d2 + d3 + d3; x1 = min(x1, min(x2, min(x3, x4))); cout << x1 <<... |
#include <bits/stdc++.h> using namespace std; const int sz = 501; const int sz2 = 16; int n, m; string a[sz]; bool dp[sz][sz][sz2][sz2]; void solve() { cin >> n >> m; for (int i = 0; i < n; i++) cin >> a[i]; long long ans = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++)... |
#include <bits/stdc++.h> using namespace std; const int maxn = 4e3 + 7; const int mod = 1e9 + 7; const int INF = 1e9 + 7; const int maxl = 20; const int SQ = 70; int n; int a[maxn], ps[maxn]; int dp[maxn][SQ][SQ]; int32_t main() { ios_base::sync_with_stdio(false), cin.tie(), cout.tie(); ; ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = (int)(1e6 + 7); const long long oo = (long long)(1e18); const double esp = (double)1e-6; const long long MOD = (long long)(1e9 + 7); int n, x, y, fre[MAXN]; vector<int> adj[MAXN]; void dfs(int u, int t) { if (u == t) return; fre[u] =... |
#include <bits/stdc++.h> using namespace std; int main() { int c = 0; long long t = 0; string s, s2; cin >> s >> s2; int n = s2.size() - s.size(); for (int i = 0; i < n; i++) { c += s2[i] - 0 ; } for (int i = 0; i < s.size(); i++) { c += s2[i + n] - 0 ; if (i) c -... |
#include <bits/stdc++.h> #pragma GCC target( avx,tune=native ) using namespace std; bitset<300000013> unprime; int main() { if (fopen( FILENAME.in , r )) { freopen( FILENAME.in , r , stdin); freopen( FILENAME.out , w , stdout); } ios_base::sync_with_stdio(false); cin.tie(NULL); ... |
#include <bits/stdc++.h> using namespace std; int n; int main() { scanf( %d , &n); if (n == 1) { puts( white ); cout << 1 << << 2 << endl; return 0; } if (n & 1) { puts( black ); return 0; } puts( white ); cout << 1 << << 2 << endl; return 0; ... |
#include <bits/stdc++.h> using namespace std; const int N = 200005; long long dp[N][5]; long long DP[N]; int head[N], nex[N * 2], to[N * 2], tot = 0; int n, k; long long ans = 0; void add(int u, int v) { to[++tot] = v; nex[tot] = head[u]; head[u] = tot; } void dfs(int u, int fa, int d) {... |
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353, MAXn = 2e5 + 2; long long arr[MAXn]; long long qp(long long a, long long e) { if (e == 0) return 1; if (e == 1) return a; if (!(e & 1)) { a = qp(a, e / 2); return a * a % MOD; } return a * qp(a, e - 1) % MOD... |
#include <bits/stdc++.h> using namespace std; namespace SHENZHEBEI { inline char gc() { return getchar(); } inline long long read() { long long x = 0, f = 1; char ch = gc(); for (; !isdigit(ch); ch = gc()) if (ch == - ) f = -1; for (; isdigit(ch); ch = gc()) x = x * 10 - 48 + ch; retu... |
#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, k; cin >> n >> k; long long int a[n + 2]; memset(a, -1, sizeof a); bool ok = f... |
#include <bits/stdc++.h> using namespace std; const int N = 110; const int memsize = 20000; struct Node { char val; int kill = 0; Node *failed = NULL; Node *pre = NULL; vector<Node *> child; Node() {} Node(char _val, Node *_pre) : val(_val), pre(_pre) {} int find_char(char c) { ... |
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int len = s.length(); for (int i = 0; i < len; i = i + 1) { if (s[i] != a && s[i] != y && s[i] != e && s[i] != i && s[i] != o && s[i] != u && s[i] != A && s[i] != Y && s[i] != E ... |
#include <bits/stdc++.h> using namespace std; const int NIL = -1; template <class T> inline T mx(T a, T b) { return a > b ? a : b; } template <class T> inline T mi(T a, T b) { return a < b ? a : b; } template <class T> inline void sw(T &a, T &b) { T t = a; a = b; b = t; } tem... |
#include <bits/stdc++.h> using namespace std; const int N = 105; const int mod = 1e9 + 7; int sub[N][N][N]; int pref[N][N]; int suff[N][N]; int ans[N]; int pw[N]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, X; cin >> n >> X; string s; cin >> s; s = & + s; ... |
#include <bits/stdc++.h> using namespace std; int memo[2700][2700]; string S; int N; int doit(int lo, int hi) { if (lo == hi) { return 1; } if (lo > hi) { return 0; } int &ret = memo[lo][hi]; if (ret != -1) return ret; ret = 0; if (S[lo] == S[hi]) { ret = max(... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<pair<int, int> > sort_positions; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; sort_positions.push_back(make_pair(a[i], i)); } sort(a, a + n); sort(sort_positions.begin(), sort_posit... |
#include <bits/stdc++.h> using namespace std; const int dx[] = {0, 1, 0, -1}; const int dy[] = {1, 0, -1, 0}; int n, m; char a[1010][1010]; int d1[1010][1010], d2[1010][1010], d3[1010][1010]; vector<pair<int, int> > s1, s2, s3; int ans = 0x3f3f3f3f; int ax, ay; void bfs(int d[1010][1010], char id) {... |
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; const int N = 1000010; int n, cnt[N], ans, val[N]; long long a[N]; template <typename T> void gi(T &x) { x = 0; register char c = getchar(), pre = 0; for (; c < 0 || c > 9 ; pre = c, c = getchar()) ; for (; c... |
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 7, mod = 1e9 + 7, inf = 1e9 + 7; const long long linf = (long long)1e18 + 7; const long double eps = 1e-15, pi = 3.141592; const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1}, dy[] = {0, 1, 0, -1, 1, -1, 1, -1}; int n, sz; long long an... |
#include <bits/stdc++.h> using namespace std; long long n, m, sum, t; int main() { scanf( %I64d%I64d , &n, &m); for (int i = 0; i < n; i++) { scanf( %I64d , &t); sum += t; if (t && sum >= m) { printf( %I64d , sum / m); sum %= m; } else printf( 0 ); } ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int s[maxn]; priority_queue<int, vector<int>, greater<int> > que; int main() { int n; scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d , &s[i]); que.push(s[i]); } sort(s, s + n); int ans = 0; ... |
#include <bits/stdc++.h> using namespace std; map<int, bool> childL, childR; int main() { ios::sync_with_stdio(false); cin.tie(0); ; int n, a; cin >> n; cin >> a; multiset<int> mulset; mulset.insert(a); for (int i = 1; i < n; i++) { cin >> a; auto ite = mulset.lower... |
#include <bits/stdc++.h> using namespace std; const int p = 1000000007; int pow3[10]; int main() { pow3[0] = 1; pow3[1] = 3; pow3[2] = pow3[1] * 3; pow3[3] = pow3[2] * 3; pow3[4] = pow3[3] * 3; pow3[5] = pow3[4] * 3; pow3[6] = pow3[5] * 3; map<char, int> myMap; char c; lo... |
#include <bits/stdc++.h> using namespace std; const int maxm = 1e6 + 5; int a[maxm]; int n; struct BIT { int c[maxm]; int lowbit(int i) { return i & -i; } void add(int i, int t) { while (i < maxm) { c[i] += t, i += lowbit(i); } } int ask(int i) { int ans = 0; ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string str; cin >> str; int L = 0; for (int l = n / 2; l >= 1; l--) { if (str.substr(0, l) == str.substr(l, l)) { L = l; break; } } if (L == 0) cout << n; else cout... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; string s; cin >> s; bool flag = false; for (int i = 1; i <= n; i++) { if (s[i - 1] == 0 ) { if (i... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; const int S = 320; int a[N]; int dp[S + 1][N]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; int q, p, k; cin >> q; for (int j = 1; j <= S; j++) { for (int i = n; i >= 1; 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; template <class c> struct rge { c b, e; }; template <class c> rge<c> range(c i, c j) { return rge<c>{i, j}; } template <class c> auto dud(c* x) -> decltype(cerr << *x, 0); template <class c> char dud(...); struct debug { template <class c... |
#include <bits/stdc++.h> using namespace std; int n, a[100010], mx1 = -100010, mx2 = -100010 - 10, ans = 1, cnt[100010]; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) { if (a[i] > mx1) { mx2 = mx1; mx1 = a[i]; cnt[a[i]]--; ... |
#include <bits/stdc++.h> using namespace std; bool visited[10000]; int main() { ios::sync_with_stdio(false); ios_base::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); string input; int counter; while (cin >> input) { counter = 0; for (int i = 0; i < input.size() - ... |
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); template <class T> inline T SQR(T a) { return a * a; } int C[100001][3]; bool can(int *A, int n, int k) { int pos = k; for (int i = (0), ei = (k); i < ei; i++) C[i][0] = A[i]; int cnt = 0; while (pos < n && cnt... |
#include <bits/stdc++.h> using namespace std; const long long MAX_N = 4e3 + 10; const long long MAX_M = 65 + 10; const long long mod = 1e9 + 7; const int INF = 1e9; inline long long bpow(long long t, long long n) { long long ans = 1; while (n > 0) { if (n & 1) ans = (ans * t) % mod; t = ... |
#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, ... |
#include <bits/stdc++.h> using namespace std; int n, sum, dp[1 << 16], arc[16][16], d[16]; void Floyd() { int k, i, j; for (k = 0; k < n; k++) for (i = 0; i < n; i++) for (j = 0; j < n; j++) arc[i][j] = min(arc[i][j], arc[i][k] + arc[k][j]); } int getans() { int i, j, x, t, totol; ... |
#include <bits/stdc++.h> using namespace std; struct Point { double x; double y; Point(double _x = 0, double _y = 0) : x(_x), y(_y) {} double length() const { return sqrt(x * x + y * y); } double distance(const Point& other) const { return Point(x - other.x, y - other.y).length(); } ... |
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn=1e6+7; const int inf=2e9; const ll inff=1e18; const ll mod=1e9+7; #define pii pair<int,int> #define mkp make_pair #define F first #define S second #define pb push_back #define sz(v) ((int)(v).size()) #define ... |
#include <bits/stdc++.h> using namespace std; long long n, k; bool f(long long x, long long y, long long z) { if ((k - x - y - z) < 0 || (k - x - y - z) % 3 != 0) return false; long long m = max(x, max(y, z)), p = n - (k + 3 * m - (x + y + z)); if (p < 0 || p % 3 != 0) return false; return true; ... |
#include <bits/stdc++.h> using namespace std; int N, K, S; int q[153]; vector<vector<int> > prev_, next_; const int INF = 1e9; int main() { scanf( %d%d%d , &N, &K, &S); S = min(S, N * (N - 1) / 2); for (int i = 1; i <= N; i++) scanf( %d , &q[i]); prev_ = vector<vector<int> >(K + 1, vector<in... |
#include <bits/stdc++.h> using namespace std; const int inf = 1e9; const double eps = 1e-9; const double INF = inf; const double EPS = eps; vector<long long> V; int cmp(long long b, long double d, long long a) { if (d > 2e18) return 1; if (b > a) return 1; if (b == a) return 0; return -1; ... |
#include <bits/stdc++.h> using namespace std; const double sn = 1e-6; int n; int arr[35]; int res; bool visited[310][310]; bool notAgain[310][310][35][8]; pair<int, int> dirs[8] = {{0, 1}, {1, 1}, {1, 0}, {1, -1}, {0, -1}, {-1, -1}, {-1, 0}, {-1, 1}}; void dfs(int dir, ... |
#include <bits/stdc++.h> using namespace std; const int INF = INT_MAX; const signed long long int LINF = LLONG_MAX; const double EPS = 1e-9; const int MOD = 1000000007; const int MAXN = 100001; const int ALPH = 26; const int DALPH = 52; int q; map<string, string> match, rmatch; set<string> current... |
#include <bits/stdc++.h> using namespace std; const int maxn = 2005, maxm = 200005; vector<int> g[maxn]; int tmp, vis[maxn], dis[maxn], mp[maxn][maxn]; int n, m, ans, cnt, tot, res, ecnt, info[maxn], nx[maxm], v[maxm]; int id, en, dfn[maxn], low[maxn], ori[maxn], sta[maxn], outd[maxn]; void add(int u1, in... |
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; const int M = 5e3 + 10; const int mod = 1e9 + 7; int cnt[M][M]; void init() { for (int i = 1; i < M; i++) { int p = i; for (int j = 1; j <= i; j++) cnt[i][j] = cnt[i - 1][j]; for (int j = 2; j <= p; j++) { if... |
#include <bits/stdc++.h> using namespace std; template <class T1, class T2> inline istream& operator>>(istream& fin, pair<T1, T2>& pr) { fin >> pr.first >> pr.second; return fin; } template <class T0, class T1, class T2> inline istream& operator>>(istream& fin, tuple<T0, T1, T2>& t) { fin >> get... |
#include <bits/stdc++.h> using namespace std; const int bigp = 1000000007; int N, K, ans; int a[105]; int dp[105][105][2]; int main() { scanf( %d , &K); N = 0; while (K > 0) { ++N, a[N] = K % 2, K /= 2; } for (int i = 1; i <= N / 2; i++) swap(a[i], a[N + 1 - i]); memset(dp, 0, ... |
#include <bits/stdc++.h> using namespace std; typedef vector<int> vi; typedef pair<int, int> ii; using namespace std; int n, q, len = 0, nxt[100005], nxtb[100005], disb[100005]; int main() { int a, b, c, op; scanf( %d%d , &n, &q); len = n / 327 + 1; for (int i = 1; i <= n; ++i) { scanf... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.