solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; string findLongestPrefix(string a, string b) { int aLen = a.length(); string pref = ""; for (int i = 0; i < aLen; i++) { if (a[i] == b[i]) pref += a[i]; else break; } return pref; } int main() { ios_base::sync_with_stdio(false); cin.tie(NUL...
1
#include <bits/stdc++.h> int ans, n, v[10] = {1}, r1[10], r2[10], p[10], r3[10]; void dfs(int u) { if (u == ans && v[u] == n) { printf("%d\n", ans); for (int i = 0; i < u; i++) if (r2[i] + 1) printf("lea e%cx, [e%cx + %d*e%cx]\n", r1[i] + 'a', r2[i] + 'a', p[i], r3[i] + 'a'); ...
3
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; long long a[n]; long long sum = 0; for (int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } long long val; val = sum / n; val *= n; while (val < sum || (v...
1
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } int pw(int x, int n, int mod) { int ret = 1; while (true) { if (n & 1) ret = (long long)ret * x % mod; if ((n >>= 1) == 0) return ret; x = (long long)x * x % mod; } } int inv(in...
5
#include <bits/stdc++.h> using namespace std; int main() { int x, y, s; while(cin >> x >> y >> s, x) { int res = 0; for(int i=1; i<=1000; ++i) { for(int j=1; j<=1000; ++j) { if(i*(100+x)/100 + j*(100+x)/100 == s) { res = max(res, i*(100+y)/100 + j...
0
#define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(v) v.begin(), v.end() typedef long long ll; #include <bits/stdc++.h> using namespace std; int main(){ int n,m; cin>>n>>m; vector<ll> X(n),Y(n),Z(n); rep(i,n) cin>>X[i]>>Y[i]>>Z[i]; ll ma=0; rep(i,8){ int a=1,b=1,c=1; if(i&1) a=...
0
#include <cstdio> #include <algorithm> #include <cstring> #include <vector> #include <ctime> #define Rep(i, n) for (int i = 1; i <= n; i ++) #define Rep0(i, n) for (int i = 0; i <= n; i ++) #define RepG(i, x) for (int i = head[x]; i; i = edge[i].next) #define v edge[i].to #define mp(a, b) make_pair(a, b) using name...
0
#include <bits/stdc++.h> using namespace std; int main() { long long a; long long x, y, level, ht; double ans = -1; cin >> a >> x >> y; double c = (double)a; if (y % a != 0) { level = y / a; if (level == 0) { if (x < c / 2 && x > -c / 2) ans = 1; } else { ans = ((double)level * 3) / ...
2
#include <bits/stdc++.h> using namespace std; template <class T> inline void amin(T &x, const T &y) { if (y < x) x = y; } template <class T> inline void amax(T &x, const T &y) { if (x < y) x = y; } template <class Iter> void rprintf(const char *fmt, Iter begin, Iter end) { for (bool sp = 0; begin != end; ++begin)...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j, sum = 0, k = 0, min = 100; cin >> n; for (i = 0; i < n; i++) { cin >> j; if (j % 2 != 0) { k++; if (j < min) { min = j; } } sum += j; } if (k == 0) { cout << 0; } else { if (k % 2 == 0) ...
2
#include <bits/stdc++.h> using namespace std; int tree[110000]; int cc[110000]; int find(int x) { if (x == tree[x]) return x; int fa = tree[x]; tree[x] = find(tree[x]); cc[x] = (cc[x] + cc[fa]) % 1000000007; return tree[x]; } int main() { int i, j, h; int T, n, m; int a, b, c; int k, v, x; while (sc...
5
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; const int N = (int)1e6 + 11; int n, m, l, r, ans = INT_MIN, maxdiff = INT_MIN; vi a, b; void solve() { cin >> n; a.resize(n); for (int i = 0; i < n; i++) cin >> a[i]; cin >> m; b.resize(m); for (int i = 0; i < m; i++) cin >> b[i]; sort(...
3
#include <bits/stdc++.h> using namespace std; using namespace std::chrono; const long long MOD1 = 1e9 + 7; const long long MOD2 = 998244353; const long long INF = 0x3f3f3f3f3f3f3f3fll; const double PI = 3.1415926535897932384626; const long long MAX_SIZE = 2e6 + 6; const long long MAX = INT_MAX; const long long MIN = IN...
5
#include <bits/stdc++.h> using namespace std; int32_t main() { long long n, m, x; cin >> n >> m; x = n + m; string s; for (long long i = 0; i < x; i++) { if (i >= 2 && s[i - 1] == '1' && s[i - 2] == '1') { s += '0'; n--; } else if (i > 0 && s[i - 1] == '0') { s += '1'; m--; ...
3
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int mod = 1000000007; long long wupin[350]; vector<long long> mp[350]; long long a[350]; long long b[350]; long long dp[150000]; long long degree[150000]; long long vis[150000]; long long n, q, t; void Top() { queue<long long> s; memset...
3
#include <bits/stdc++.h> using namespace std; void solve() { string s; cin >> s; vector<long long> dp(s.size()); int prevb = -1; int preva = -1; int prevva = -1; long long pos = 1; int n = s.size(); vector<long long> apos(n + 1); vector<long long> pr(n + 1); for (int i = 0; i < s.size(); ++i) { ...
3
#include <bits/stdc++.h> using namespace std; long long int M = 2 * 1000000000; long long int i, j; bool sortbysecdesc(const pair<int, int> &a, const pair<int, int> &b) { return a.second > b.second; } long long int mod(long long a, long long b) { return (a % b + b) % b; } long long int isPrime(long long int n) { if...
3
#include <iostream> using namespace std; typedef long long ll; ll n, f[310][310], ans; int main(void){ // Your code here! cin >> n; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> f[i][j]; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n;...
0
#include <bits/stdc++.h> using namespace std; int modulas(int a, int n) { if (n == 0) return 1; long long int ans = modulas(a, n / 2); ans = (ans * ans) % 998244353; if (n % 2) ans = (ans * a) % 998244353; return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int ...
3
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; using pil = pair<int, ll>; using pli = pair<ll, int>; using pll = pair<ll, ll>; using vint = vector<int>; using vll = vector<ll>; using vld = vector<ld>; using vpii = vector<pii>; using vpil = vector<...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 1001; const int maxm = 100010; bitset<maxn> mat[maxn]; int n, m, q, ans[maxm], ret; vector<int> link[maxm]; struct Query { int ty, i, j; }; Query Q[maxm]; void dfs(int p) { int r, c; bool tp; if (Q[p].ty == 1) { r = Q[p].i, c = Q[p].j; tp = ...
4
#include <bits/stdc++.h> using namespace std; //#define che #define debug(...) fprintf(stderr,__VA_ARGS__) #define MK make_pair #define PB push_back #define fi first #define se second typedef long long LL; typedef pair<int, int> PII; const int N=3e5 +10 ; const LL MOD = 1e9+7; int pre[N], n, nxt[3]; LL f[N]; char s[N]...
0
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, b, temp; cin >> n >> b; long long a[n]; for (long long i = 0; i < n; i++) { cin >> a[i]; } temp = b; for (long long i = 0; i < n - 1; i++) { for (long long j = i + 1; j <...
2
#include <bits/stdc++.h> using namespace std; double PI = 3.141592653589793238462643383279; const double EPS = 1e-9; const long long MOD = 1000000007; const int inf = 1 << 30; const long long linf = 1LL << 60; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); namespace LCA { vector<vector<int>> G; in...
5
#include <bits/stdc++.h> using namespace std; template <typename _T> inline void read(_T &f) { f = 0; _T fu = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') fu = -1; c = getchar(); } while (c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); } f ...
4
#include <bits/stdc++.h> using namespace std; long long a[1001][1001], b[1001] = {0}, c[1001] = {0}, d[1000001], e[1000001]; int main() { ifstream inf("input.txt"); long long n, m, k, p; cin >> n >> m >> k >> p; for (int i = 1; i <= n; i++) for (int i1 = 1; i1 <= m; i1++) cin >> a[i][i1]; for (int i = 1; ...
2
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); int temp, yes_count = 0; int a[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 49, 25, 9, 4, 53}; string ans; float sq; cout << a[0] << endl; fflush(stdout); cin >> ans; for (int i = 1; ...
3
#include<iostream> using namespace std; int main(){ int ans=1,n,k; cin>>n>>k; for(int i=1;i<=n;i++)ans+=min(ans,k); cout<<ans<<endl; }
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6; long long n; long long vals[MAXN]; long long pref[MAXN]; long long cnt1[MAXN]; long long pr[MAXN]; inline void init() {} inline void solve() { init(); long long ans = 0; for (long long i = 0; i < n; i++) { cin >> vals[i]; vals[i] = __buil...
2
#include <bits/stdc++.h> using namespace std; int n, k, a, b, x, y, i, j, m[100005], p[100005]; string s; int main() { cin >> n >> k >> s; while (i < n) { m[i] = m[i - 1]; if (s[i] == 'b') { m[i]++; } i++; } i = 0; while (i < n) { while (m[j] - m[i - 1] <= k && j < n) { a = max...
3
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 1; i < n - 1; i++) { if (a[i] > a[i - 1] && a[i] > a[i + 1]) { cout << "YES" << "\n"; cout << i << " " << i + 1 << " " << i + 2 << "\...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 1234500; namespace SAM { int ch[maxn][26], fa[maxn], maxlen[maxn], tot, end, cnt; long long siz[maxn], res[maxn]; char ans[100010]; void init() { memset(ch, 0, sizeof(ch)); memset(fa, 0, sizeof(fa)); tot = 2, end = 1, cnt = 0; } inline int idx(char c)...
2
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7, N = 1e5 + 5, INF = 1e18; int main() { std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; long long ans = 0; for (int i = 1; i <= n / 2; i++) { if ((n - i) % i == 0) ans++; } cout << ans << "...
1
#include <bits/stdc++.h> using namespace std; template <typename Tk, typename Tv> ostream& operator<<(ostream& os, const pair<Tk, Tv>& p) { os << "{" << p.first << ',' << p.second << "}"; return os; } const int MAX = 100005; const int MOD = 1000000000 + 7; const int INF = 1000000000; int main() { ios::sync_with_s...
1
#include<bits/stdc++.h> using namespace std; int main(){ int t,n; int count = 0; cin>>t; string s; string ne; while(t--){ cin>>n; cin>>s; sort(s.begin(),s.end()); cout<<s<<endl; } }
1
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; const long double eps = 1e-7; const int inf = 1000000010; const long long INF = 10000000000010LL; const int mod = 1000000007; const int MAXN = 200010; int n, m, u, v, x, y, t, a, b, ans, cnt, mx; int A[MAXN]; int mn[MAXN]; stack<int> st; int ma...
4
#include <bits/stdc++.h> using namespace std; char s[2]; int mark[110], cnt, res[110]; int inc, de, n; int main() { scanf("%s", s); mark[cnt++] = 1; ++inc; while (scanf("%s", s) == 1 && s[0] != '=') { if (s[0] == '-') { mark[cnt++] = -1; ++de; } else { mark[cnt++] = 1; ++inc; ...
1
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18; const long long mod = 1e9 + 7; template <typename T> T gcd(T a, T b) { return (b ? __gcd(a, b) : a); } template <typename T> T lcm(T a, T b) { return (a * (b / gcd(a, b))); } void go() { ios_base::sync_with_stdio(false); cin.tie(NULL); ...
4
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7; vector<int> v[N]; int n, cnt[N], mx = 0; bool vis[N]; void dfs(int x, int c) { vis[x] = true; for (auto el : v[x]) { cnt[c]++; mx = max(mx, c); if (!vis[el]) dfs(el, c + 1); } } int main() { scanf("%d", &n); for (int i = 2; i <= ...
4
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 7; const int mod = 1e9 + 7; char second[N]; int n, ans; int mx[21][N]; int lg[N]; int get(int l, int r) { int z = lg[r - l + 1]; return max(mx[z][l], mx[z][r - (1 << z) + 1]); } void solve() { scanf("\n%s", second); n = strlen(second); vector<i...
4
#include <bits/stdc++.h> using namespace std; const int Size = 10000; char buffer[Size]; const int inf = 0x7fffffff; map<string, int> m; const int size = 8; int G[size][size]; int ar[size]; int aa, b, c; pair<int, int> res; void rec(int id) { if (id == m.size()) { vector<int> a[3]; for (int i = 0; i < m.size(...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, mx1 = 0, mx2 = 0, sum = 0; cin >> n; vector<int> w; vector<int> h; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; w.push_back(a); sum += a; h.push_back(b); if (b > mx1) { mx2 = mx1; mx1 = b; } els...
2
#include <bits/stdc++.h> using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } typedef long long int ...
0
#include <bits/stdc++.h> using namespace std; const long long maxN = 2e5 + 5; const long long MOD = 998244353; const long long inf = 1e18; bool maxi(long long &a, const long long b) { return a < b ? (a = b, true) : false; }; long long n, k, a[maxN], res = 1, dp[2][maxN]; bitset<maxN> vis[2]; vector<long long> v[2], i...
5
#include <bits/stdc++.h> using namespace std; double f[1 << 21]; long long a[1 << 21]; int n; char s[50][25]; int main() { scanf("%d", &n); for (int i = 0; i < n; ++i) scanf("%s", s[i]); int m = strlen(s[0]); for (int i = 0; i < n; ++i) for (int j = i + 1; j < n; ++j) { long long S = 0; for (int...
3
#include <iostream> #include <algorithm> #include <vector> using namespace std; bool exists(vector<int> v, int n) { for (int i = 0; i < v.size(); i++) { if (v[i] == n) return true; } return false; } int main() { while (true) { int n; cin >> n; if (!n) return 0; ...
0
#include<iostream> #include<vector> #include<list> #include<algorithm> #include<map> using namespace std; int main() { int n,q,r; cin >> n; vector<int> v(n); for (int i = 0; i < n; i++) cin >> v[i]; cin >> q; bool w; bool y = true; for (int i = 0; i < q; i++) { cin >> r; ...
0
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int dig(char c) { return c - '0'; } bool good(string s, int m, int d) { int rem = 0; for (int i = 0; i < (int)s.length(); i++) { if (i & 1) { if (dig(s[i]) != d) { return false; } } else if (dig(s[i]) == d) { re...
4
#include <bits/stdc++.h> using namespace std; int n = 10000000; int pr[30000007], m; int d[100000]; bool p[100000]; void pr_simple() { int i, j; m = 1; pr[0] = 2; for (i = 3; i <= n; i += 2) { bool mp = true; for (j = 0; pr[j] * pr[j] <= i; ++j) if (i % pr[j] == 0) { mp = false; br...
3
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; vector<pair<char, int>> sol; for (int i = 97; i < 123; i++) sol.push_back(make_pair(i, 0)); for (int i = 0; i < s.size(); i++) { for (int j = 0; j < sol.size(); j++) if (s[i] == sol[j].first) sol[j].second++; } for (i...
1
#include <bits/stdc++.h> using namespace std; vector<char> v; int main() { ios_base::sync_with_stdio(false); string s; cin >> s; for (int i = 0; i < s.size(); i++) { if (i == 0) v.push_back(s[i]); else if (s[i] == v[v.size() - 1]) v.pop_back(); else v.push_back(s[i]); } if (v.s...
4
#include <cstdio> #include <iostream> #include <string> #include <vector> #include <cmath> #include <algorithm> #include <cstdlib> #include <cstring> #include <map> using namespace std; #define REP(i,j,k) for(int i=j;i<(int)(k);++i) #define rep(i,j) REP(i,0,j) #define F first #define S second typedef pair<int,...
0
#include <bits/stdc++.h> using namespace std; char s[200010]; int g[200010][30]; int main() { int i, j, k; int n, t, m; cin >> t; while (t--) { cin >> n >> m; cin >> s + 1; int ans[30] = {0}; for (i = 1; i <= n; i++) { for (j = 0; j < 26; j++) { g[i][j] = g[i - 1][j]; } ...
3
#include <bits/stdc++.h> using namespace std; const int INF = 2e9 + 5; int main() { cin.tie(0), cin.sync_with_stdio(0); long long n, k, m, d; cin >> n >> k >> m >> d; long long ans = -1; for (int i = 1; i <= d; i++) { long long times = n / k; if (times < i - 1) break; long long hi = n / (k * (i - ...
3
#include<bits/stdc++.h> using namespace std; int sum[200005]; char s[200005]; int main(){ int n; scanf("%d",&n); int i; scanf("%s",s + 1); for(i = 1;i <= n;i++)sum[i] = sum[i-1] + (s[i] == '.'); int ans = 2147483647; for(i = 0;i <= n;i++)ans = min(ans,i - sum[i] + sum[n] - sum[i]); cout<<ans<<endl; return 0...
0
#include <bits/stdc++.h> using std::cin; using std::cout; using std::endl; using std::string; void __Check(bool condition, const char* expression, int line) { if (!condition) { fprintf(stderr, "Check failed at line %d: %s\n", line, expression); exit(-1); } } template <class Collection, class Key> bool Conta...
5
#include <bits/stdc++.h> using namespace std; int a[110], b[110]; int n; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); sort(a + 1, a + 1 + n); int cnt = 0; for (int i = 1; i <= n; i++) { int f = 0, k = 1; for (int j = 1; j <= cnt; j++) if (b[j] < b[k]) k = j; ...
1
#include <bits/stdc++.h> using namespace std; long long max(long long a, long long b) { return a >= b ? a : b; } void solve() { long long n; cin >> n; vector<long long> a(n); map<long long, long long> make_pair; for (long long i = 0; i < n; i++) cin >> a[i]; for (long long i = 0; i < n; i++) make_pair[a[i]]...
4
#include <bits/stdc++.h> int n, r, A[30][30], C[30], R[30]; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) scanf("%d", &A[i][j]); } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { C[i] += A[j][i]; R[i] += A[i][j]; } } for (int i = ...
1
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target("avx,avx2,sse,sse2") using namespace std; time_t current_time; const int N = 2e6 + 10, mod = 1e9 + 7, inf = 1e9; int mat[20][20], n, p; string s; int charset[17][1 << 17]; int done[17][1 << 17][17]; void addall(char ch1, int mask, ch...
6
#include <bits/stdc++.h> using namespace std; int r, c, k; string s[501]; int dx[] = {0, 0, -1, 1}; int dy[] = {1, -1, 0, 0}; bool valid(int x, int y) { if (x < 0 || y < 0 || x >= r || y >= c) return 0; return 1; } void dfs(int x, int y) { if (k == 0) return; for (int i = 0; i < 4; i++) { int X = x + dx[i];...
1
#include <bits/stdc++.h> using namespace std; const long long maxn = 2e5 + 5, inf = 1e18, mod = 1e9 + 7; long long n, m, a[maxn], sum[maxn], ans[maxn], par[maxn]; bool mark[maxn]; vector<long long> adj[maxn]; void dfs(long long u) { mark[u] = 1; sum[u] += a[u]; for (long long j : adj[u]) { if (mark[j]) contin...
6
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; long long int ans = 0; if (n > m) { long long int t = n; n = m; m = t; } for (int i = 1; i <= n; i++) { ans = ans + (m + i) / 5 - i / 5; } cout << ans; return 0; }
1
#include <bits/stdc++.h> using namespace std; const int INF_of_int = 1e9; const long long INF_of_ll = 1e18; template <typename T> void Read(T &x) { bool w = 1; x = 0; char c = getchar(); while (!isdigit(c) && c != '-') c = getchar(); if (c == '-') w = 0, c = getchar(); while (isdigit(c)) { x = (x << 1) ...
2
#include <bits/stdc++.h> using namespace std; using ll = long long; struct city { city *before = nullptr, *after = nullptr; ll id; }; unordered_map<ll, city> cities; unordered_map<ll, vector<ll>> rule_map; int main() { ll n; cin >> n; for (ll i = 0; i < n; i++) { pair<ll, ll> rule; cin >> rule.first >...
3
#include <bits/stdc++.h> using namespace std; char c[2][2], t; string s1, s2; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.precision(11); cout.setf(ios::fixed); srand((uint32_t)time(nullptr)); s1 = ""; s2 = ""; for (int i = 0; i < 2; ++i) { for (int j = 0; j < 2; ++j) { ...
1
#include <bits/stdc++.h> using namespace std; string s; long long int n; int main() { long long int i, j, k, e1, e2, ctr = 0, odd = 0; scanf("%lld", &n); cin >> s; for (i = 0; i < n; i++) { if (!((s[i] - '0') & 1)) { ctr += ((i + 1)); } } printf("%lld\n", ctr); return 0; }
1
#include <bits/stdc++.h> using namespace std; const unsigned long long maxn = 1000 + 10; const int INF = 0x3f3f3f3f; const double eps = 1e-10; const double pi = acos(-1.0); int g[maxn][maxn]; struct haha { int x, y, w; } p[maxn * 10], p0[maxn * 10]; struct Edge { int from, to, dist; }; struct HeapNode { int d, u;...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<vector<int>> Sizes(k); for (int i = 0; i < k; i++) { int c; cin >> c; Sizes[i].resize(c); for (int j = 0; j < c; j++) cin >> Sizes[i][j]; } int ans = 0, single = 0; for (int i = 0; i < k; i++) { ...
1
#include <bits/stdc++.h> using namespace std; int main() { int n, m, buses = 0, placesTaken = 0; cin >> n >> m; for (int i = 0; i < n; i++) { int a; cin >> a; if (placesTaken + a <= m) placesTaken += a; else { buses++; placesTaken = a; } } if (placesTaken > 0) buses++; ...
1
#include <bits/stdc++.h> using namespace std; long long n, big, ans = LLONG_MAX; vector<long long> vec[101234]; long long check(long long z) { long long res = 0, tot = vec[0].size(); vector<long long> ret; for (long long i = 1; i <= big; i++) { long long now = 0, siz = vec[i].size(), poi = siz; for (long ...
3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; int floor[n][2 * m]; for (int i = 0; i < n; i++) { for (int j = 0; j < 2 * m; j++) { cin >> floor[i][j]; } } int count = 0; for (int i = 0; i < n; i++) { ...
1
#include <bits/stdc++.h> int main(void) { int n, m; scanf("%d %d", &n, &m); if (n == 1) printf("%d\n", 1); else if (n / 2 < m) printf("%d\n", m - 1); else printf("%d\n", m + 1); return 0; }
2
#include <iostream> #include <string> #include <vector> #include <map> #include <algorithm> using namespace std; const int MAX_N = 12; typedef pair<int,char> P; // 入力 int n; string s[MAX_N]; // f[c] := 文字 c の係数. int f[256] = {0}; // m[c] := 文字 c に割り当てた数字 (0-9のどれか, まだ割り当てられていないときは -1 ) int m[256] = {0}; // max_digit :...
0
#include <bits/stdc++.h> using namespace std; priority_queue<int> in[50]; map<int, int> to_pop; long long sum[50]; int get_group(int cur) { int ret = 0; while (cur) { ret++; cur = cur / 2; } return ret; } int active = 0; void update(int cur) { int where = get_group(cur); sum[where] += cur; in[wher...
4
#include <bits/stdc++.h> using namespace std; const int kN = 2e5+7; int n; long long res; int a[kN], b[kN]; int main() { cin >> n; for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 0; i < n; ++i) { cin >> b[i]; if (b[i] < a[i]) { cout << "-1" << endl; ...
0
#include <bits/stdc++.h> using namespace std; long long jc[501], Jc[501], f[501], g[501], h[501][501][2], C[501][501], s, ans, F; int n, m, mod, Mod, i, j, k, l; long long qpower(long long a, int b) { long long ans = 1; while (b) { if (b & 1) ans = ans * a % mod; a = a * a % mod; b >>= 1; } retu...
4
#include <bits/stdc++.h> using namespace std; void imprimirVector(vector<long long> v) { if (!v.empty()) { int p = v.size(); cout << "["; for (int i = 0; i < (int)(p - 1); i++) cout << v[i] << ","; cout << v[p - 1] << "]" << endl; } else cout << "[]" << endl; } int toNumber(string s) { int Num...
2
#include <bits/stdc++.h> using namespace std; #define FOR(i,a,b) for(int i = (a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() #define fi first #define se second template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; } template<typename A, typ...
0
#include <bits/stdc++.h> using namespace std; int n; int a[2505][2505]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) scanf("%d", &a[i][j]); for (int i = 1; i <= n; i++) for (int j = i + 1; j <= n; j++) if (a[i][j] != a[j][i] || a[i][i] != 0) { cout ...
6
#include <bits/stdc++.h> using namespace std; long long power(long long a, long long b) { if (b == 0) return (long long)1; long long x = power(a, b / 2); x = x % 1000000007; long long ans = ((long long)(x % 1000000007) * (long long)(x % 1000000007)) % 1000000007; if (b % 2 != 0) ans = ((long long)(a...
3
#include<iostream> #include<climits> #include<algorithm> #include<vector> using namespace std; #define REP(i,b,n) for(int i=b;i<n;i++) #define rep(i,n) REP(i,0,n) #define pb push_back #define mp make_pair #define ALL(C) (C).begin(),(C).end() int dx[]={1,0,-1,0}; int dy[]={0,1,0,-1}; int vis[50]...
0
#include <bits/stdc++.h> using namespace std; inline int in() { int32_t x; scanf("%d", &x); return x; } inline long long lin() { long long x; scanf("%lld", &x); return x; } inline string get() { char ch[2000010]; scanf("%s", ch); return ch; } const int MAX_LG = 21; const long long maxn = 1e5 + 10; con...
4
#include<bits/stdc++.h> long long a,b,k; int main(){ scanf("%lld%lld%lld",&k,&a,&b); if(k<=a)return puts("1"),0; else if(a<=b)return puts("-1"),0; else printf("%lld\n",((k-a)/(a-b)+bool((k-a)%(a-b)))<<1|1); }
0
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:167772160") using namespace std; int p, i, j, res, d, k, dd, rr; string s, w[101], s1, s2, w1, w2; int main() { p = 0; while (getline(cin, s)) { w[p] = s; p++; } sort(w, w + p); res = 0; rr = 0; d = 0; dd = 0; for (i = 0; i < p; i++) { ...
3
#include <bits/stdc++.h> using namespace std; const int N = 300005; int n, k, a[N][2]; long long f[N][2]; int main() { scanf("%d%d", &n, &k); for (int j = 0; j < 2; j++) for (int i = 1; i <= n; i++) scanf("%d", &a[i][j]); for (int j = 0; j < 2; j++) for (int i = 1; i <= n; i++) if ((f[i][j] = max(0L...
6
#include <bits/stdc++.h> using namespace std; long long n; int main() { cin >> n; vector<vector<long long>> a(60 + 8, vector<long long>{}); vector<long long> b(n); for (long long i = 0; i < n; ++i) cin >> b[i]; for (long long i = 0; i < n; ++i) { long long x = b[i]; long long cnt = 0; while (x % 2...
4
#include <bits/stdc++.h> using namespace std; const int mod = (int)1e9 + 7, INF = 0x7fffffff, rx[] = {-1, 0, 1, 0}, ry[] = {0, 1, 0, -1}; const double pi = acos(-1.0), eps = 1e-8; void rd(int &res) { res = 0; char c; while (c = getchar(), c < 48) ; do res = (res << 3) + (res << 1) + (c ^ 48); wh...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; map<int, bool> cur; int ans[maxn]; int main() { queue<int> q; int n, k; scanf("%d%d", &n, &k); int a; for (int i = 1; i <= n; i++) { scanf("%d", &a); if (cur[a] == 0) { q.push(a); if (q.size() > k) { int t = q...
2
#include <iostream> using namespace std; int abs(int a){ return 0 <= a ? a : -a; } int main(){ int n, m; cin >> n >> m; int a[n], b[n], c[m], d[m]; for(int i = 0; i < n; i++) cin >> a[i] >> b[i]; for(int i = 0; i < m; i++) cin >> c[i] >> d[i]; for(int i = 0; i < n; i++){ int dist = 1e9, ans; for(int j = 0;...
0
#include <bits/stdc++.h> using namespace std; int prime[10000] = {0}; void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); } long long power(long long base, long long n) { long long ans = 1; while (n > 0) { if (n % 2) { ans = (ans * base); } base = (base * base); n >>= 1; } r...
1
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; const long double pi = acos(-1.0); const long double eps = 1e-5; const int INF = 0x3f3f3f3f; const long long INFLL = 0x3f3f3f3f3f3f3f3f; int n, m; char a[100][100]; bool n1s() { bool f = true; for (int i = (1); i <= (n); i++) if (a[i]...
2
#include <bits/stdc++.h> using namespace std; vector<int> a; bool isOverflow(int64_t a, int64_t b) { if (a == 0 || b == 0) return false; else return (a > LLONG_MAX / b); } int64_t func(int64_t c) { int64_t cost = 0, pc = 1; for (int ai : a) { long long diff = ai - pc; cost += abs(diff); if (...
2
#include <bits/stdc++.h> using namespace std; const int MAX_N = 30; int a[MAX_N], s[MAX_N]; int main() { ios::sync_with_stdio(false); int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; s[i] = a[i]; } sort(s, s + n); map<int, int> spos; for (int i = 0; i < n; i++) { spos[s[i]] = i; ...
2
#include <stdio.h> int main() { int R; scanf("%d",&R); if( R<1200 ) printf("ABC"); else if (R<2800) printf("ARC"); else printf("AGC"); return 0; }
0
#include <bits/stdc++.h> using namespace std; long long N, L, W; vector<long long> neg, pos; long long INF32 = 0x7fffffff; inline long long div_floor(long long a, long long b) { if (b == 0) return (a > 0 ? +INF32 : -INF32); if (a % b < 0) a -= (b + a % b); return a / b; } int main() { cin >> N >> L >> W; for ...
4
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; int r = 1; while (n--) { cout << 1 << " "; } cout << endl; } }
1
//ALTF4 #include<iostream> #include<algorithm> #include<string> #include<cmath> #include<math.h> #include<stack> #include<vector> #include<queue> #include<cstdio> #include<deque> #include<map> using namespace std; using lli = long long; using ull = unsigned long long; const int maxN = 1e7 + 2; const lli mod = 1e9 + 7...
5
#include <bits/stdc++.h> using namespace std; const int N = 1e2 + 20; int n, a[N][N], sum; int main() { cin >> n; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> a[i][j]; if (i == j || i + j == n - 1 || i == (n - 1) / 2 || j == (n - 1) / 2) { sum += a[i][j]; } } ...
1
#include <bits/stdc++.h> using namespace std; long long a, b, d[200005], c, e[200005], l, r, ans; string n; int main() { cin >> a; while (a--) { ans = 0; cin >> b >> c; l = 0, r = b - 1; for (int s = 0; s < b; s++) cin >> d[s]; for (int s = 0; s < c; s++) cin >> e[s]; sort(d, d + b); sor...
3