solution
stringlengths
52
181k
difficulty
int64
0
6
#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; int __gcd(int a, int b) { return b == 0 ? a : __gcd(b, a % b); } int power(int x, int n) { if (n == 0) return 1; else if (n % 2 == 0) { ...
4
#include<iostream> #include<algorithm> using namespace std; int main() { int m, nmin, nmax; while (cin >> m >> nmin >> nmax&&m&&nmin&&nmax) { int p[200]; for (int i = 0; i < m; i++)cin >> p[i]; int soeji, sa1=p[nmin-1]-p[nmin],sa2; for (int i = nmin - 1; i <= nmax - 1; i++) { if (sa1 <= p[i] - p[i + 1]) { ...
0
#include <bits/stdc++.h> using namespace std; int main() { long long int a, b, c, d, e, f, i, j, k, n, m, t, s, q, l, r, x, y, z; cin >> n >> a; if ((n - a) > (a - 1)) cout << a + 1 << "\n"; else { if ((a - 1) == 0) cout << a << "\n"; else cout << a - 1 << "\n"; } return 0; }
2
#include<cstdio> #include<iostream> #include<vector> #include<string> #include<algorithm> #include<queue> #include<stack> #include<map> #include<set> #include <iomanip> #include<math.h> #define rep0(i,N) for(int i=0;i<N;i++) #define rep1(i,a,N) for(int i=0+a;i<N;i++) #define lint long long int #define SIZE 100005 usi...
0
#include <bits/stdc++.h> using namespace std; int n; int totans; int ans[205]; int getsum(int g1) { int ret = 0; while (g1) { ret += g1 % 10; g1 = g1 / 10; } return ret; } int main() { scanf("%d", &n); for (int i1 = max(0, n - 90); i1 <= n; i1++) if (getsum(i1) + i1 == n) totans++, ans[totans] =...
3
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<string> grid(n); for (int i = 0; i < n; i++) { cin >> grid[i]; } int count = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (grid[i][j] == 'W') { if (i >= 1 and grid[i - 1][j...
2
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); int n, m, i, j, a, b; cin >> n >> m >> i >> j >> a >> b; if ((i + a > n && i - a < 1) || (j + b > m && j - b < 1)) { if ((i == 1 || i == n) && (j == 1 || j == m)) cout << 0 << endl; else cout << "Poo...
1
#include <bits/stdc++.h> using namespace std; int n,x,ans; int a[110]; int main() { scanf("%d%d",&n,&x); for (int i=1;i<=n;i++) scanf("%d",&a[i]); sort(a+1,a+n+1); for (int i=1;i<n;i++) if (x>=a[i]) { ans++; x-=a[i]; } else break; if (x==a[n]) ans++; printf("%d\n",ans); }
0
#include <iostream> #include <vector> using namespace std; int n; vector<int> a; int main(){ int bu, len = 1; cin >> n; cin >> bu; for( int i = 1; i < n; i++ ){ int u; cin >> u; if( bu == u ){ a.push_back(len); len = 1; } else { len++; } bu = u; } a.push_back(len); int ans = 0; for( i...
0
#include <bits/stdc++.h> using namespace std; int main(){ int n; int x,y,z; set<int> a,b,c; cin>>n; cin>>x; for(int i=0;i<x;i++){ int g;cin>>g; a.insert(g); } cin>>y; for(int i=0;i<y;i++){ int g;cin>>g; b.insert(g); } cin>>z; for(int i=0;i<...
0
#include <bits/stdc++.h> using namespace std; const int INF = 1000000001; const long long int INFLL = 10000000001; const long double EPS = 1e-6; const int MAXN = 100005; const int FACTORS_THRESHOLD = 100005; int A[MAXN]; int T[MAXN]; long long int Power(int x, int y) { long long int r = 1; for (int i = 0; i < y; i+...
2
#include <bits/stdc++.h> using namespace std; int main() { int n, x, y, z, l, r; cin >> n; x = 2 * n + 1; y = n + 1; l = y; r = y; z = 0; for (int i = 1; i <= x; i++) { z = 0; for (int j = 1; j <= x; j++) { if (j >= l && j <= r) { cout << z; if (j < y) z = z + 1; ...
2
#include <bits/stdc++.h> using namespace std; struct __ { int x, y, l; bool operator<(const __ &ob) const { if (x != ob.x) return x < ob.x; if (y != ob.y) return y < ob.y; return l < ob.l; } }; set<__> xxx; struct _ { int x, y; }; vector<_> s[400010]; int top; struct node { int fa, w, dep; } a[100...
6
#include <bits/stdc++.h> using namespace std; int main() { int n, temp = 0, sum = 0; cin >> n; for (int i = 1; i <= n; ++i) { cin >> temp; sum += temp; } if (sum % n == 0) cout << n << endl; else cout << n - 1 << endl; }
2
#include<iostream> using namespace std; int main(void) { int i,n,x,y; cin>>n; for(i=1;i<=n;i++){ y=0; if(i%3==0){ y=1; } x=i; while(0<x){ if(x%10==3){ y=1; } x=x/10; } if(y==1){ cout<<" "<<i; } } cout<<endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int cansel_sync = (ios::sync_with_stdio(0), cin.tie(0), 0); const int N = 110; int T, n, m; string s[N]; string ans; bool ok() { for (int i = (0), _ = (n); i < _; i++) { int cnt = 0; for (int j = (0), _ = (m); j < _; j++) cnt += (ans[j] != s[i][j]); if (cnt > ...
6
#include <bits/stdc++.h> using namespace std; struct node { int weight; vector<int> edges; }; struct edge { int x; int y; int w; int p; }; istream& operator>>(istream& is, edge& e) { is >> e.x >> e.y >> e.w >> e.p; e.x--; e.y--; return is; } ostream& operator<<(ostream& os, const edge& e) { return...
5
#include <bits/stdc++.h> using namespace std; bool d[10]; bool f(int n); int main() { int n, r = 0, i; cin >> n; int m = n; while (m > 0) { d[m % 10] = 1; m /= 10; } for (i = 1; i * i < n; i++) { if (n % i != 0) continue; if (f(i)) r++; if (f(n / i)) r++; } if (i * i == n && f(i)) r+...
2
#include <iostream> using namespace std; int main() { int a,b,x; cin>>a>>b>>x; if(a+b>=x&&x>=a)cout<<"YES"; else cout<<"NO"; }
0
#include <bits/stdc++.h> using namespace std; int n, k; int a[2005]; int dp[2005]; bool chk(long long x) { dp[1] = 0; for (int i = 2; i <= n; i++) { dp[i] = i - 1; for (int j = 1; j < i; j++) if (abs(a[i] - a[j]) <= (i - j) * x) dp[i] = min(dp[i], dp[j] + (i - j - 1)); } for (int i = n; i ...
4
#include <bits/stdc++.h> using namespace std; using ld = long double; using ll = int64_t; using pii = pair<int, int>; using ull = uint64_t; ll a[100100]; ll X[100100], Y[100100]; ll gcd(ll a, ll b, ll& x, ll& y) { if (a == 0) { x = 0; y = 1; return b; } ll x1, y1; ll d = gcd(b % a, a, x1, y1); x =...
1
#include <bits/stdc++.h> using namespace std; int n, m, k, numOn, res[200000]; set<int> f[200000]; bool on[200000]; vector<pair<int, int> > v; queue<int> toRemove; void update() { while (!toRemove.empty()) { int r = toRemove.front(); toRemove.pop(); numOn--; for (auto next : f[r]) { f[next].eras...
5
#include <bits/stdc++.h> using namespace std; int main() { int t, n, a, b, ans; cin >> t; while (t--) { cin >> a >> b; if (a == b) cout << 0 << endl; else { if (a > b) swap(a, b); b = b - a; ans = b / 5; if (b % 5 == 0) cout << ans << endl; else if (b % 5 ==...
1
#include <bits/stdc++.h> using namespace std; vector<char> hola; int main() { int tam, total = 0; char a; cin >> tam; for (int i = 0; i < (tam); i++) { cin >> a; hola.push_back(a); total++; a -= '0'; if ((int)a == 0) { cout << total << endl; return 0; } } cout << tam << e...
1
#include <bits/stdc++.h> using namespace std; int val[1000], arr[100022], len[1000]; int main() { int n, m, i, j, k; scanf("%d%d", &n, &m); for (i = 0; i < n; i++) scanf("%d", &arr[i]); memset(val, -1, sizeof(val)); for (i = 0; i < n; i++) { int ele = arr[i]; if (val[ele] != -1) continue; for (j =...
3
#include <bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; int main() { int t; cin >> t; while (t--) { long long n; cin >> n; if (n % 2 == 0) cout << n / 2 - 1 << endl; else cout << n / 2 << endl; } return 0; }
1
#include <bits/stdc++.h> using namespace std; int main() { int n, i, j; cin >> n; long long int dist[n + 1][n + 1], total = 0; for (int i = 1; i < n + 1; i++) for (int j = 1; j < n + 1; j++) { cin >> dist[i][j]; total += dist[i][j]; } total /= 2; int q; cin >> q; while (q--) { in...
3
#include <iostream> #include <algorithm> using namespace std; int main(void){ int a,b,c,d,e,f; while(cin >> a >> b >> c >> d >> e >> f){ if((a|b|c|d|e|f) == 0) break; int MD = a + d, GG = b + e, GO = c + f; int ret = 0; for(int i=0;i<=2;i++){ if(MD >= i && GG >= i && GO >= i) ret = max(ret, (MD-...
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--) { int n; cin >> n; vector<long long> a[n]; for (int i = 0; i < n; i++) { int k; cin >> k; for (int j = 0; j < k; j++)...
2
#include <bits/stdc++.h> using namespace std; const int maxK = 100 + 5; const int maxN = 50 + 5; int k, n, m, q; int cnt[maxK][maxN]; string basic[maxN]; vector<string> res[maxK]; map<string, int> str_int; struct node { string name; int cnt[maxN]; node() { memset(cnt, 0, sizeof cnt); name = ""; } } a[ma...
3
#include <bits/stdc++.h> using namespace std; long long v[110000]; int n; int calc(int y) { int ret = 1; for (int i = 1; i < 1000; i++) { if (ret * 2 > y) return ret; ret *= 2; } return -1; } int main() { cin >> n; for (int i = 0; i < n; i++) cin >> v[i]; long long acc = 0; for (int i = 0; i < n...
1
#include <bits/stdc++.h> using namespace std; long long a, b, m; long long check(long long sum, long long val, long long mov) { long long lo = val, hi = val, los = sum + val, his = sum + val; mov--; while (mov--) { lo = los + 1; los += lo; hi = his + m; his += hi; } if (hi < b) { return 1;...
4
#include <bits/stdc++.h> using namespace std; int main() { int n, rez = 0, c; string a, b; cin >> n >> a >> b; while (n--) { c = abs(a[n] - b[n]); rez += min(c, 10 - c); } cout << rez; return 0; }
1
#include <iostream> #include <string> #include <algorithm> #include <math.h> #include <vector> #include <set> using namespace std; typedef long long LL; static const double EPS = 1e-9; #define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i) #define REP(i,n) FOR(i,0,n) #define P(x) cout << (x) << endl int main(void){ ...
0
#include <bits/stdc++.h> using namespace std; const long long int MOD = 1e9 + 7; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n, m; cin >> n >> m; char a[n][m]; for (long long int i = 0; i < n; i++) { for (long long int j = 0; j < m; j++) { cin >> a[i][j]; } ...
1
#include <bits/stdc++.h> using namespace std; template <class TH> void _dbg(const char *sdbg, TH h) { if (0) cout << sdbg << "=" << h << "\n"; } template <class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) { while (*sdbg != ',') if (0) cout << *sdbg++; if (0) cout << "=" << h << ","; _dbg(sdb...
4
#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--) { string s; long long int i, m, p, j; char c; map<char, long long int> mp; cin >> s; long long int n = s.length(); fo...
4
#include <bits/stdc++.h> using namespace std; void solve() { long long n, c = 0, z, k; cin >> n; if (n % 2 != 0) { cout << "0\n"; return; } for (int i = 1;; ++i) { z = i * 2; k = (n - z) / 2; if (i < k) c++; else break; } cout << c; } int main() { ios_base::sync_with_...
1
#include <bits/stdc++.h> using namespace std; template <class T> inline T min(T &a, T &b) { return a < b ? a : b; } template <class T> inline T max(T &a, T &b) { return a > b ? a : b; } template <class T> void read(T &x) { char ch; while ((ch = getchar()) && !isdigit(ch)) ; x = ch - '0'; while ((ch = ge...
5
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx2,tune=native") #pragma GCC optimize("unroll-loops") using namespace std; const int N = 1e6 + 36; const long long INF = 2e18 + 7; const int MOD = 1e9 + 7; mt19937 gen(19937); vector<int> a, b; vector<pa...
3
#include <bits/stdc++.h> using namespace std; using lli = long long int; const int MOD = 1000000007; const int MOD1 = 998244353; const int maxn = 100010; const int lim = (int)1e9; int n, m, k, x, y, w, res = 0; vector<pair<int, int> > v[2 * maxn]; vector<int> aux[10]; bitset<2 * maxn> bset[10][10]; bitset<2 * maxn> nse...
5
#include <bits/stdc++.h> using namespace std; #define forn(i,n) for(int i=0;i<(int)(n);i++) #define si(c) ((int)(c).size()) #define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++) #define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--) #define all(c) (c).begin(), (c).end() #define D(a) cerr << #a << "=" <<...
0
#include <bits/stdc++.h> using namespace std; bool visited[2001]; long long maxcnt; std::vector<long long> adjlis[2001]; stack<long long> stac; void dfs(long long u) { visited[u] = true; if (!adjlis[u].size()) { if (maxcnt < stac.size()) maxcnt = stac.size(); } for (auto i : adjlis[u]) { if (!visited[i]...
1
#include <bits/stdc++.h> using namespace std; const int NMAX = 1010, inf = 0x3f3f3f3f; const int dl[] = {0, 1, 0, -1}; const int dc[] = {1, 0, -1, 0}; int N, M; int d[3][NMAX][NMAX]; char S[NMAX][NMAX]; queue<pair<int, int>> Q; bool inq[NMAX][NMAX]; void BFS(int d[NMAX][NMAX]) { while (!Q.empty()) { auto now = Q....
3
#include <bits/stdc++.h> int main() { int A[31][31]; int n, i, j; scanf("%d", &n); for (i = 0; i < n; i++) for (j = 0; j < n; j++) scanf("%d", &A[i][j]); int result = 0; for (i = 0; i < n; i++) for (j = 0; j < n; j++) { int column = 0; int c = 0; for (; c < n; c++) column += A[c][j...
1
#include <bits/stdc++.h> using namespace std; void init_ios() { ios_base::sync_with_stdio(0); cin.tie(0); } string a = "BWBWBWBW", b = "WBWBWBWB", c; int main() { init_ios(); bool res = true; for (int i = 1; i <= 8; ++i) { cin >> c; if (c != a && c != b) res = false; } if (res) cout << "YES\n"...
1
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:64777216") using namespace std; const long long maxn = 501; const long long maxk = 200001; const long long maxx = 10001; const long long secret_number = 87468267; const long long linf = 99999999999999999; const long long inf = 100000; const double pi = 3.14159265...
4
#include <bits/stdc++.h> #pragma GCC optimize(3) struct { inline operator int() { int x; return scanf("%d", &x), x; } } read; const int maxn = 50005; long double lk[maxn], lb[maxn]; struct Vector { long double x, y, at; int id; } vec[maxn << 1]; struct Range { int l, r; int id; } ran[maxn]; int getC...
5
#include<bits/stdc++.h> #define ll long long using namespace std; int n,a[20]; ll dp(int l,int r,ll xl,ll xr) { if(l+1==r) return 0; ll ans=1e18; for(int i=l+1;i<r;i++) ans=min(ans,dp(l,i,xl,xl+xr)+dp(i,r,xl+xr,xr)+(xl+xr)*a[i]); return ans; } int main() { scanf("%d",&n); for(int i=1;i<=n;i++)scanf("%d",&a[i]);...
0
#include <bits/stdc++.h> using namespace std; template <typename T, typename T1> ostream &operator<<(ostream &out, pair<T, T1> obj) { out << "(" << obj.first << ", " << obj.second << ")"; return out; } template <typename T, typename T1> ostream &operator<<(ostream &out, map<T, T1> cont) { typename map<T, T1>::con...
2
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; int main() { int N; cin >> N; while (N--) { int a[200005]; int n; cin >> n; int ans = inf, l = 0; for (int i = 0; i < 200005; i++) a[i] = 0; for (int i = 1; i <= n; i++) { int x; cin >> x; if (a[x])...
3
#include <iostream> #include <vector> using namespace std; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a%b); } int main() { vector<int> prime; vector<bool> is_prime(1e5, true); is_prime[0] = is_prime[1] = false; for(int i=2; i<1e5; ++i) { if(is_prime[i]) { prime.push_bac...
0
#include <bits/stdc++.h> using namespace std; struct RTC {}; long long int A, B; map<long long int, long long int> sol; bool gao(long long int cur) { if (cur > B) return false; if (cur == B) return true; if (gao(cur << 1LL)) { sol[cur] = cur << 1LL; return true; } if (gao(cur * 10LL + 1LL)) { sol[...
1
#include<bits/stdc++.h> using namespace std; int main(){ long x,p;cin>>x>>p; cout<<fixed<<setprecision(10)<<50.0*(x+x%2)/p; }
0
#include <bits/stdc++.h> const int INF = 1e9; using namespace std; void dfs(int v, int p, vector<vector<int> > &graph, vector<int> &sz) { sz[v] = 1; for (auto u : graph[v]) if (u != p) { dfs(u, v, graph, sz); sz[v] += sz[u]; } } void dfs(int v, int p, vector<vector<int> > &graph, vector<int> &c,...
2
#include <iostream> #include <algorithm> #include <vector> #include <cstdio> #include <cmath> constexpr double EPS = (1e-10); constexpr double INF = 252521; #define equals(a, b) (fabs(a - b) < EPS) std::vector<int> par, rnk; void init(int n) { par.resize(n); rnk.resize(n); for (int i = 0; i < n; i++) { ...
0
#include <iostream> #include <vector> #include <cmath> #include <string> #include <algorithm> #include <iomanip> #include <map> #include <bitset> #include <cstdio> #include <set> #include <stack> #include <queue> #include <cassert> #include <numeric> #define rep(i,n) Rep(i,0,n) #define Rep(i,k,n) for(int i=k ; i<n ; i+...
0
#include <bits/stdc++.h> using namespace std; void fast(); void debug(int*, int); void test(); void solve(); #define ll long long int #define u_int unsigned int #define u_long unsigned long #define fr first #define sd second #define pb push_back #define vi vector<int> #define vl vector<long long int> #define vvi vec...
1
#include <bits/stdc++.h> using namespace std; int tot[100100]; int maxd = 0; vector<vector<int> > g; void dfs(int v, int d, int p) { maxd = ((maxd < d) ? (d) : (maxd)); tot[d]++; for (int i = (0); i < (g[v].size()); ++i) { int to = g[v][i]; if (to != p) { dfs(to, d + 1, v); } } } int use[10010...
4
#include <bits/stdc++.h> using namespace std; const string dest[16] = { "KIHABARA", "KIHABAR", "KIHABRA", "KIHABR", "KIHBARA", "KIHBAR", "KIHBRA", "KIHBR", "AKIHABARA", "AKIHABAR", "AKIHABRA", "AKIHABR", "AKIHBARA", "AKIHBAR", "AKIHBRA", "AKIHBR"}; string src; int main() { cin >> src; for (int i = 0; i < 16; i++) {...
0
#include <bits/stdc++.h> using namespace std; const int MAXV = 100005; int P[MAXV]; int R[MAXV]; int S[MAXV]; void init(int N) { for (int i = 0; i < N; i++) { P[i] = i; R[i] = 0; S[i] = 1; } } int rep(int i) { if (P[i] != i) P[i] = rep(P[i]); return P[i]; } bool unio(int a, int b) { a = rep(a); ...
2
#include <bits/stdc++.h> using namespace std; const long double pi = 3.1415926535897; const int N = 1010; struct circle { int x, y, r; long double s() { return 1. * r * r * pi; } bool operator<(const circle &y) const { return r < y.r; } } a[N]; long double sqr(long double x) { return x * x; } long double dis(int ...
4
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > v[2]; int n, x; int done[2][2010]; int go(int who) { memset(done, 0, sizeof(done)); int ret = 0, cap = x; while (1) { int mx = -1, pos; for (int i = 0; i < v[who].size(); i++) { if (done[who][i]) continue; if (v[who][i].firs...
1
#include<iostream> using namespace std; int main() { string S; cin>>S; cout<<S.substr(0,3)<<endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; int main() { int n[3] = {0, 0, 0}, first = 0; string s; cin >> s; for (int i = 0; i < s.size(); i += 2) { ++n[s[i] - '1']; } if (n[0]) { cout << '1'; ++first; --n[0]; } if (n[1] && !first) { cout << '2'; ++first; --n[1]; } if ...
1
#include <bits/stdc++.h> using namespace std; int tp, ck, n, i, s, d, ans = 3333, g[3333] = {}; vector<pair<int, int> > f[3333]; void dfs2(int x, int k, int r) { tp += k; ck = max(ck, r); g[x] = 1; r = max(r, 0); for (int j = 0; j < f[x].size(); j++) if (!g[f[x][j].first]) { if (f[x][j].second == 1)...
5
#include <bits/stdc++.h> #pragma GCC optimize("-Ofast") #pragma GCC target( \ "sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native") #pragma GCC optimize("-ffast-math") #pragma GCC optimize("-funroll-loops") #pragma GCC optimize("-funroll-all-loops,-fpeel-loops,-funswitch-loops") using namespace std; lo...
1
#include<bits/stdc++.h> using namespace std; #define mo 1000000007ll #define int long long #define N 2 int ans,n,m,k; char s[1010][1010],tp[1010][1010]; struct no{ int a[N][N]; }; no m1(no x,no y){ no z; memset(z.a,0,sizeof(z.a)); for(int i=0;i<2;i++) for(int j=0;j<2;j++) for(int k=0;k<2;k++) z.a[i][j]=(z....
0
#include<bits/stdc++.h> using namespace std; using ll=long long; int main(){ int i,j,cnt=0; int k,t; cin>>k>>t; int a[t]; for(i=0;i<t;i++)cin>>a[i]; sort(a,a+t,greater<int>()); if(a[0]-1<=k-a[0])cout<<0; else cout<<a[0]-1-(k-a[0]); }
0
#include <stdio.h> #include <algorithm> int a[100000 + 5]; int n; int main() { scanf("%d", &n); for (int i = 0; i < n; ++ i) { int x; scanf("%d", &x); ++ x; a[x] ++; a[x - 1] ++; a[x + 1] ++; } printf("%d\n", *std::max_element(a, a + 100000 + 2)); }
0
#include<bits/stdc++.h> using namespace std; int a,b,c,x,ans=0; int main() { cin>>a>>b>>c>>x; for(int i=0;i<=a;i++) { for(int j=0;j<=b;j++) { for(int k=0;k<=c;k++) { if(i*500+j*100+k*50==x)ans++; } } } cout<<ans; return 0; }
0
#include <bits/stdc++.h> #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; long long gcd(long long a, long long b) { return (a == 0) ? b : gcd(b % a, a); } long long cnt1(long long x) { long long cnt = 0; while (x > 0) ...
2
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ll w,h,x,y; cin>>w>>h>>x>>y; cout<<w*h/2.<<" "<<(x*2==w&&y*2==h)<<endl; }
0
#include <bits/stdc++.h> template <class C> inline void log_c(const C& c) {} template <class C> inline int sz(const C& c) { return static_cast<int>(c.size()); } using namespace std; using num = int64_t; const std::string eol = "\n"; using pii = pair<int, int>; num sum = 0; vector<vector<int>> adj; vector<bool> visite...
3
#include <bits/stdc++.h> using namespace std; const int MAXN = 4020; int a[MAXN]; int calc(int left, int right) { int ret = 0; while (left <= right) { if (!a[left] || !a[right]) { ret += min(a[left] + a[right], 1000 - a[left] - a[right]); } else { ret += 1000 - a[left] - a[right]; } ++le...
3
#include<iostream> using namespace std; int main(){ const int INF=1000000000; int n,c; static int dp[2][5000+2][2]; for(int i=0;i<2;i++)for(int j=0;j<5002;j++){dp[i][j][0]=INF; dp[i][j][1]=INF;} dp[1][1][0]=0; dp[1][0][1]=0; scanf("%d",&n); for(int i=2;i<=n;i++){ int s=i%2,t=1-s; scanf("%d",&c); for(int ...
0
#include<stdio.h> #include<algorithm> using namespace std; int ret; int A[11]; int B[11]; int C[11]; int n; void solve(int a,int b,int c){ if(a==n){ int tmp=0; for(int i=10;i>=0;i--){ tmp*=10;tmp+=C[i]; } ret=max(ret,tmp); return; } int t=A[a]-B[a]-b; if(t<0){ C[a]=t+10; if(c)solve(a+1,0,c-1); ...
0
#include <bits/stdc++.h> using namespace std; int main(int argc, char **argv) { int n; scanf("%d", &n); vector<int> p(n); for (int i = 0; i < n; i++) { scanf("%d", &p[i]); p[i]--; } vector<int> b(n); int cnt_ones = 0; for (int i = 0; i < n; i++) { scanf("%d", &b[i]); if (b[i] == 1) { ...
1
#include <bits/stdc++.h> using namespace std; inline long long ModPow(long long a, long long b, long long mod) { if (b == 0) return 1; if (b == 1) return a; if (b % 2) return (ModPow(a, b - 1, mod) * a) % mod; long long z = ModPow(a, b / 2, mod); return (z * z) % mod; } int main() { long long int p, k; ci...
2
#include <bits/stdc++.h> using namespace std; class node { public: long long int second; long long int length; }; void FastIO() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); } long long int a[3 * 100001], ans[3 * 100001], mem[5001][5001]; long long int n, k, i, j, small, large, small_length,...
2
#include <bits/stdc++.h> using namespace std; const int MAXN = 5001; int dp[MAXN][MAXN], p[MAXN][MAXN]; void Solve() { int n; cin >> n; string s1, s2; cin >> s1 >> s2; vector<int> ind[4]; for (int i = 0; i < n; ++i) { ind[(s2[i] - '0') * 2 + (s1[i] - '0')].emplace_back(i); } for (int x1 = 0; x1 <= i...
2
#include <bits/stdc++.h> using namespace std; long long int ncr[1001][1001]; void ncrdp(void) { for (int i = 0; i < 1001; i++) { ncr[i][0] = 1; ncr[i][i] = 1; } for (int i = 1; i < 1001; i++) { for (int j = 1; j < i; j++) { ncr[i][j] = (ncr[i - 1][j - 1] + ncr[i - 1][j]) % 1000000007; } } ...
2
#include <bits/stdc++.h> using namespace std; const int maxn = 4e5 + 3; const int maxm = 1e6 + 3; const int mod = 1e9 + 7; const int oo = 1061109567; const long long loo = 4557430888798830399; const long double pi = 3.141592653589793238462643383279502884; void input() { if (fopen("abc" ".inp", ...
2
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-9; const long long INF = 1000000000000000000; vector<pair<int, int> > v(8); vector<int> sq(4), par(4); double di(pair<int, int> a, pair<int, int> b) { double res = 0; res = sqrt((double)(a.first - b.first) * (a.first - b.first) + (a.se...
2
#include <bits/stdc++.h> using namespace std; int a[111]; int id[111][111]; int vis[111]; int main() { int n, m, k, q; while (cin >> n >> k) { m = n / k; for (int i = 0; i < n; i++) { cin >> a[i]; vis[i] = 0; } scanf("%d", &q); double minv = 1 << 30, maxv = -1 << 30; for (int i =...
2
#include <bits/stdc++.h> #define upd(x,y) x=x+y>=mu?x+y-mu:x+y; const int mu=1000000007; int n,a[22][22],dp[22][1<<21]; int main(){ scanf("%d",&n); for (int i=1;i<=n;i++) for (int j=0;j<n;j++) scanf("%d",&a[i][j]); dp[0][0]=1; for (int i=0;i<n;i++) for (int j=0;j<(1<<n);j++){ if (!dp[i][j]) continue; for ...
0
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); struct Op { int r; int first; Op(int r, int first) { this->r = r; this->first = first; } }; int main() { int n, m; scanf("%d %d", &n, &m); vector<int> vals(n); for (__typeof(vals.begin()) val = vals.begin(); val != vals.en...
3
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int n; int cnt[N]; void solve() { long long k, n, a, b; cin >> k >> n >> a >> b; if (k - (n - 1) * b <= b) { cout << -1 << endl; return; } long long c = k / a; if (c * a >= k) c--; long long d = (k - n * b) / (a - b); if (d * ...
3
#include <bits/stdc++.h> using namespace std; template <class T> inline void checkmin(T &a, T b) { if (b < a) a = b; } template <class T> inline void checkmax(T &a, T b) { if (b > a) a = b; } int N, X; vector<int> res; void solve() { int n = 0; if (X < (1 << N)) n = (1 << N) / 2 - 1; else n = (1 << N)...
4
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,no-stack-protector") #pragma GCC target( \ "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") using namespace std; vector<int> adj[100010]; int p[100010]; int lev[100010]; int stp[100010][19]; int stm[100010], etm[100010]; int dtm = 0; vector<int> b[...
5
#include <bits/stdc++.h> using namespace std; const long long MAXN = 5e5 + 10; const long long MOD = 998244353; const long long MAXnum = 2e5; const long double eps = 1e-8; const long double inf = 1e20; const long double PI = acos(-1); inline long long read() { long long s = 0, w = 1; char ch = getchar(); while (c...
3
#include <bits/stdc++.h> int main() { int n, c, i, cl, cr, p[50], t[50], tim, m; while (scanf("%d%d", &n, &c) != EOF) { for (i = 0; i < n; i++) scanf("%d", &p[i]); for (i = 0; i < n; i++) scanf("%d", &t[i]); for (i = 0, cl = 0, tim = 0; i < n; i++) { tim += t[i]; m = (p[i] - c * tim); ...
1
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define pi pair<int,int> #define ff first #define ss second #define boost ios::sync_with_stdio(false);cin.tie(nullptr) #include "string" const int N = 2e5 + 5; int xx[4]={0,0,1,-1}; int yy[4] ={1,-1,0,0}; int32_t main(){ boost; int n,m,k; cin>>...
0
#include<cstdio> using namespace std; int n; int p[20010],a[20010],b[20010]; int main() { scanf("%d",&n); for (int i=1;i<=n;i++) scanf("%d",&p[i]); for (int i=1;i<=n;i++) a[i]=1,b[i]=-1; for (int i=1;i<=n;i++) a[p[i]]+=i,b[p[i]+1]-=i; for (int i=1;i<=n;i++) a[i]+=a[i-1],b[i]+=b[i-1]; for (int i=1;i<=n;i++...
0
#include <bits/stdc++.h> using namespace std; int r, c; int main() { scanf("%d%d", &r, &c); int ans = 0; if (r == 1 || c == 1) ans = r * c; else if (r == 2 && c == 2) ans = 4; else if (r * c == 6) ans = 4; else { if (r == 2 || c == 2) { int mx = max(r, c); int tot = mx % 4; ...
2
#include <bits/stdc++.h> using namespace std; const int M = 1000000007; const int MM = 998244353; const long double PI = acos(-1); long long power(long long b, long long e, long long m) { if (e == 0) return 1; if (e & 1) return b * power(b * b % m, e / 2, m) % m; return power(b * b % m, e / 2, m); } long long pow...
4
#include <set> #include <map> #include <cmath> #include <ctime> #include <deque> #include <queue> #include <stack> #include <vector> #include <bitset> #include <string> #include <cstdio> #include <cassert> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <algorithm> #define mk make_...
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll N, M; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> N >> M; cout << abs(N*M - (N+N+M+M-4)) << "\n"; }
0
#include <bits/stdc++.h> using namespace std; const long double EPS = 1e-6; const int INF = 1000000000; int gauss(vector<vector<long double> > a, vector<long double>& ans) { int n = (int)a.size(); int m = (int)a[0].size() - 1; vector<int> where(m, -1); for (int col = 0, row = 0; col < m && row < n; ++col) { ...
3
#include <bits/stdc++.h> using namespace std; const long long maxn = 2e5 + 5; vector<long long> G[maxn]; vector<long long> G1[maxn]; long long n, m, k; long long x, y; vector<long long> p; vector<long long> d; const long long INF = 1e9; void dijk() { priority_queue<pair<long long, long long>, vector<...
4