solution
stringlengths
52
181k
difficulty
int64
0
6
#include <bits/stdc++.h> using namespace std; const int dx[] = {0, 0, 1, -1}; const int dy[] = {1, -1, 0, 0}; const int N = 4194303; char s[17][17]; int dist[17][17][1 << 16], n, m, M; int qx[N + 5], qy[N + 5], qz[N + 5], front, rear; int px[10], py[10], len, stx, sty; bool can[4]; int main() { scanf("%d%d", &n, &m);...
4
#include <bits/stdc++.h> using namespace std; const int nax = 505; int n; char grid[nax][nax]; int cc[nax][nax]; int cc_size[nax * nax]; int when_added[nax * nax]; const int dx[4] = {-1, 1, 0, 0}; const int dy[4] = {0, 0, -1, 1}; const char EMPTY = '.'; bool inside(int x, int y) { return 0 <= min(x, y) && max(x, y) < n...
5
#include <bits/stdc++.h> using namespace std; const long long m = 1e9 + 7; int main() { long long n; cin >> n; long long abc[n + 1]; long long d[n + 1]; abc[0] = 0; d[0] = 1; for (int i = 1; i <= n; ++i) { d[i] = (3 * (abc[i - 1] % m)) % m; abc[i] = (d[i - 1] % m + 2 * (abc[i - 1] % m) % m) % m; ...
5
#include<bits/stdc++.h> using namespace std; using ll = long long; const int maxn = 1<<20, mod = 1e9 + 7; string s; int n, ans = 1<<30; int p[maxn], sm[maxn], tt[maxn]; void solvep(string s) {//stuff with + p[0] = 0; int gm = 0; //cout << s << '\n'; for(int i = 1; i <= n; i++) { p[i] = p[i-1] + (s[i] == '1' ? -1 ...
0
#include <bits/stdc++.h> using namespace std; int prt; struct Var { string type; string name; bool operator<(const Var& v) const { if (type != v.type) return type < v.type; if (name != v.name) return name < v.name; return false; } bool operator==(const Var& v) const { return type == v.type && ...
4
#include <bits/stdc++.h> using namespace std; int main(){ int A,B,C,K; cin >> A >> B >> C >> K; cout << A+B+C+max({A,B,C})*(pow(2,K)-1) << endl; }
0
#include <bits/stdc++.h> int main() { int *a, i, n, max, t; scanf("%d", &t); while (t--) { scanf("%d %d", &n, &max); a = (int *)malloc(n * sizeof(int)); for (i = 0; i < n; i++) { scanf("%d", &a[i]); } if (a[0] == max) { printf("%d\n", max); } else { for (i = 1; i < n; i++...
1
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; const int inf = 1e9 + 7; int head[maxn], to[maxn << 1], nxt[maxn << 1]; int Vertex; int qu[maxn], qf, qb, dist[2][maxn], fa[maxn], i, v, ok; int dijk(int u, int *Dist) { for (i = 1; i <= Vertex; i++) Dist[i] = inf; Dist[u] = 0; qf = qb = 0; ...
6
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5; int a[N]; int main() { int t, n; scanf("%d", &t); while (t--) { scanf("%d", &n); bool vis[4] = {0}; int maxn = 0, p = 0; for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); int d = a[i] - a[i - 1]; if (i > 1) { ...
2
#include <bits/stdc++.h> using namespace std; const int mod = (int)1e9 + 7; vector<vector<int> > operator*(const vector<vector<int> > &a, const vector<vector<int> > &b) { vector<vector<int> > res(a.size(), vector<int>(b[0].size())); assert(a[0].size() == b.size()); for (int i = 0; i...
4
#include <bits/stdc++.h> using namespace std; const int maxn = 510000; int f[maxn]; int n, d, up; int c[66]; int b[66]; int main() { cin >> n >> d; f[0] = 1; for (int i = 1; i <= n; i++) { int x; cin >> x; for (int j = (up += x); j >= x; j--) if (f[j - x]) f[j] = 1; } int num = 0, ans = 0; ...
4
#include<iostream> #include<cstdio> using namespace std; int main() { int n,m,q,a[2005]; scanf("%d%d%d",&n,&m,&q); for (register int i=1;i<=n;++i) { scanf("%d",a+i); } int l=0,r=2000000000; while (l<r) { int mid=(l+r)>>1; bool ok=0; for (register int i=1;i<=n;++i) { int p=a[i],k=0,tmp=0,cnt=0; for (...
0
#include <bits/stdc++.h> using namespace std; using Real = long double; Real g_err = 1e-9; bool r_eq(Real x, Real y, Real err = g_err) { return abs(x - y) <= err || abs(x - y) <= abs(x) * err; } bool r_le(Real x, Real y, Real err = g_err) { return x - y <= err || x - y <= abs(x) * err; } bool r_ge(Real x, Real y, R...
5
#include <cstdio> #include <algorithm> #include <vector> #include <functional> #include <cassert> #include <map> #include <set> using namespace std; const int MOD = 1e9 + 7; const int N = 5000001; long long fact[N]; long long invfact[N]; long long inv[N]; void init() { fact[0] = fact[1] = 1; for (int ...
0
#include <bits/stdc++.h> const double eps = 1e-8; using namespace std; int a[200005]; int b[200005]; int c[200005]; int d[200005]; int n; int ans; int main() { int t, cases = 0; scanf("%d", &n); int ans = 0x3f3f3f3f; for (int i = 0; i < n; i++) scanf("%d", &a[i]); sort(a, a + n); for (int i = 0; i < n / 2; ...
3
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int count = 0; 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])) { ++count; } if (a[i] < a[i - 1] && a[i] < a[i + 1]) { ...
1
#include <stdio.h> #include <string.h> #include <algorithm> #include <iostream> #include <math.h> #include <assert.h> #include <vector> #include <queue> #include <string> #include <map> #include <set> using namespace std; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; static const dou...
0
#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 = cost; if (m > (T - t))...
4
#include <bits/stdc++.h> const int maxn = 1000010; const int mo = 1000000007; using namespace std; int n, cnt[2]; long long f[maxn]; int main() { scanf("%d", &n); int x; for (int i = 1; i <= n; ++i) scanf("%d", &x), ++cnt[x - 1]; f[0] = f[1] = 1; for (int i = 2; i <= cnt[0]; ++i) f[i] = (f[i - 1] + f[i - 2] *...
4
#include <bits/stdc++.h> const long long N = 2e5 + 10; using namespace std; long long n, a[N], x, m, xx, sum = 0, store[N] = {}, ind = 1, a2[N] = {}; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for (int i = 1; i <= n; i++) cin >> a[i]; while (m--) { int type; cin >> type >> x...
2
#include <bits/stdc++.h> using namespace std; int t[15]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m, a; cin >> n >> m; int mini = INT_MAX, mini2 = INT_MAX, ind = 20; for (int i = 0; i < n; i++) { cin >> a; t[a]++; mini = min(mini, a); } for (int i = 0;...
1
#include<bits/stdc++.h> using namespace std; #define MOD 1000000007; string S; long long dp[100010][13]; int main(){ cin >> S; dp[0][0] = 1; for(int i = 0; i < S.size(); i++){ int num; if(S[i] == '?') num = 10; else num = S[i] - '0'; for(int j = 0; j < 10; j++){ if(num != 10 && num != j) conti...
0
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long lb = 1000; void vrikodara(long long n = 12) { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(n) << fixed; } long long t1, t2, x1, x2; double t0, d = INT_...
3
#include <cstdio> #include <utility> #include <map> using namespace std; char s[510], ans[510]; inline void upd(char &p, int &m, char c, char d) { if (p > c) p = c, m = 0; if (p == c) m |= 1 << d; } void solve() { int n, k; scanf("%d%d%s", &n, &k, s); for (int i = 0; i < n; i++) { s[i] -= 'a'; } if (n == 1) { ...
6
#include <bits/stdc++.h> using namespace std; map<pair<long long, long long>, set<int>> mp; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } bool cross(long long x1, long long y1, long long x2, long long y2) { return (x1 * y2 - x2 * y1); } bool check(long long i, long long j...
5
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9; const long long MOD = 1e9 + 7; void needForSpeed() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } long long gcd(long long a, long long b) { while (b) { a %= b; swap(a, b); } return a; } long long lcm(long long a, lo...
2
#include <bits/stdc++.h> using namespace std; template <class C> void min_self(C &a, C b) { a = min(a, b); } template <class C> void max_self(C &a, C b) { a = max(a, b); } const long long MOD = 1000000007; long long mod(long long n, long long m = MOD) { n %= m, n += m, n %= m; return n; } const int MAXN = 1e5 +...
4
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 100; char ss[N]; char str[N]; int main() { scanf("%s", ss + 1); int n = strlen(ss + 1); for (int i = 1; i <= n; i++) { if (ss[i] == '1' || ss[i] == '2') { puts("No"); return 0; } if (ss[i] == '3') str[i] = '3'; if (ss[i]...
4
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i)) using ll = long long; //using P = pair<int, int>; using namespace std; struct Node { int location; int p, l, r; Node() {} }; struct Point { int id, x, y; Point() {} Point (int id, int x, int y) ...
0
#include <bits/stdc++.h> using namespace std; const int N = 100005; long long ara[N], sum[N]; int main() { long long n, p; scanf("%lld %lld", &n, &p); for (long long i = 1; i <= n; i++) scanf("%lld", &ara[i]), sum[i] = sum[i - 1] + ara[i]; long long ans = 0; for (long long i = 1; i < n; i++) { ans = m...
3
#include <bits/stdc++.h> using namespace std; using ll = long long; #define int ll using VI = vector<int>; using VVI = vector<VI>; #define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i) #define REP(i, n) FOR(i, 0, n) #define PB push_back const int INF = (1LL<<30); template <typename T> T &chmin(T &a, const T &b) {...
0
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:36777216") using namespace std; template <class T> inline T &RD(T &); template <class T> inline void OT(const T &); inline long long RD() { long long x; return RD(x); } inline double &RF(double &); inline double RF() { double x; return RF(x); } inline cha...
5
#include <bits/stdc++.h> using namespace std; const long long N = 3e5 + 5; long long n, a, b, w; signed main() { cin >> n; for (long long i = 1; i <= n; i++) { cin >> a; if (a & 1) if (i & 1) b++; else w++; b += (a >> 1), w += (a >> 1); } cout << min(b, w); return 0; }
2
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0;i<(n);i++) #define name (i++?" ":"") int main(){ int n; cin>>n; vector <int> a(n); REP(i,n) cin>>a[i]; int q; cin>>q; \ REP(i,q){ int b,e,t; cin>>b>>e>>t; swap_ranges(a.begin()+b,a.begin()+e,a.begin()+t); } ...
0
#include <bits/stdc++.h> using namespace std; int main() { for (int i = 0; i < 9; i++) { cout << i << "??<>" << (i + 1) << "\n"; } cout << "9??>>??0\n"; cout << "??<>1\n"; for (int i = 0; i <= 9; i++) { cout << "?" << i << ">>" << i << "?\n"; } cout << "?>>??\n"; cout << ">>?\n"; return 0; }
3
#include <bits/stdc++.h> using namespace std; long long int l, r, x, y, k; void solve(int test) { cin >> l >> r >> x >> y >> k; if ((ceil(l * 1.0 / k) >= x && ceil(l * 1.0 / k) <= y && ceil(l * 1.0 / k) * k <= r) || ((r / k) >= x && (r / k) <= y && (r / k) * k >= l)) { cout << "YES"; } else c...
1
#include <bits/stdc++.h> using namespace std; int n; struct node { int v, next; } edge[500005 << 2]; int adj[500005], adj2[500005], pos, fa[500005], fa2[500005]; int fi_fa[500005], cnt, out[500005][4]; void add(int adj[], int u, int v) { ++pos; edge[pos].v = v, edge[pos].next = adj[u]; adj[u] = pos; } void dfs(...
5
#include<iostream> #include<algorithm> using namespace std; int a[100010]; int main() { int n,m; cin>>n>>m; for(int i=1;i<=m;i++) cin>>a[i]; sort(a+1 ,a+1+m); for(int i=m;i>=2;i--) a[i]=a[i]-a[i-1]; sort(a+2 , a+1+m); int ans=0; for(int i=2;i<=m-n+1;i++) ans+=a[i]; cout<<ans<<endl; }
0
#include <bits/stdc++.h> using namespace std; long long n, a, b; long long x[105], y[105]; long long ans; int main() { cin.sync_with_stdio(0); cin.tie(0); cin >> n >> a >> b; for (long long i = 1; i <= n; ++i) { cin >> x[i] >> y[i]; } for (long long i = 1; i <= n; ++i) { swap(x[i], y[i]); for (l...
3
#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 = cost; if (m > (T - t))...
4
#include<iostream> using namespace std; int main(){ string S; cin>>S; int a=0; for(int i=0;i<4;i++){ if(S[i]=='+')a++; if(S[i]=='-')a--; } cout<<a<<endl; }
0
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); vector<int> a(6); for (int i = 0; i < 6; ++i) { cin >> a[i]; } sort(a.rbegin(), a.rend()); int n; cin >> n; vector<int> b(n); for (int i = 0; i < n; ++i) { cin >> b[i]; } set<pair<int...
1
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; const long double Pi = 3.14159265359; const long long MOD = 1000 * 1000 * 1000 + 7; const long long N = 2e5 + 10; const long long INF = 1e18; long long n, m, L, x, d, t, p; vector<long long> OX; map<long long, vector<pair<long long, long long> ...
4
#include <bits/stdc++.h> using namespace std; struct bData { int openLeft, value, openRight; bData() : openLeft(0), value(0), openRight(0) {} bData(int l, int v, int r) : openLeft(l), value(v), openRight(r) {} }; int log(int x) { int output = 0; while (x > 1) { output++; x /= 2; } return output; }...
5
#include <bits/stdc++.h> using namespace std; int main(){ long long T1, T2, A1, A2, B1, B2; cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2; if(T1 * A1 + T2 * A2 == T1 * B1 + T2 * B2) puts("infinity"); else { if(T1 * A1 + T2 * A2 > T1 * B1 + T2 * B2) { swap(A1, B1); swap(A2, B2);...
0
#include <bits/stdc++.h> using namespace std; inline regex make_regex(const string& user) { return regex("\\b" + user + "\\b"); } void reduce_adjacent(int i, vector<pair<set<string>, string>>& messages) { if (i > 0 && messages[i - 1].first.erase(*messages[i].first.begin()) == 1 && messages[i - 1].first.size()...
3
#include <bits/stdc++.h> using namespace std; int n; char data[200001]; int main() { scanf("%d", &n); scanf("%s", data); int ans = 0; int I = 0; for (; I < n; I++) { if (data[I] == '<') ans++; else break; } I--; for (int J = n - 1; J > I; J--) { if (data[J] == '>') ans++; ...
1
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int SIZE = 1e6 + 10; struct EDGE { int x, y, v; EDGE(int _x = 0, int _y = 0, int _v = 0) : x(_x), y(_y), v(_v) {} bool operator<(const EDGE& b) const { return v < b.v; } } a[SIZE]; int dp[SIZE]; int main() { int n, m; scanf("%d%d", &...
5
#define NDEBUG #include <iostream> #include <cstring> #include <algorithm> #include <vector> #include <map> #include <queue> #include <set> #include <tuple> #include <cassert> #include <unistd.h> #include <cstdio> #include <cstdlib> #include <stack> #include <random> using namespace std; typedef long long ll; struc...
0
#include <bits/stdc++.h> using namespace std; int32_t main() { int64_t n; cin >> n; struct point { int64_t x, y; }; vector<point> a(n + 1); for (int64_t i = 1; i < n + 1; i++) { cin >> a[i].x >> a[i].y; } vector<int64_t> c(n + 1), k(n + 1); for (int64_t i = 1; i < n + 1; i++) { cin >> c[i]...
4
#include <bits/stdc++.h> using namespace std; const int N = 17; typedef long long int ll; const ll inf = 1e18; ll w[1 << N]; ll dp[1 << N]; ll a[N][N]; int main() { int n; cin >> n; for(int i=0;i<n;++i) for(int j=0;j<n;++j) cin >> a[i][j]; int nn = 1 << n; for(int s=0;s<nn;++s) { for(...
0
#include <bits/stdc++.h> #define MAXN (100010) int n, m, tot; std::vector<int> vec[MAXN]; std::deque<int> ans; bool vis[MAXN]; void go(int u, bool mark){ for(auto v : vec[u]){ if(vis[v]) continue; vis[v] = true; if(mark) ans.push_back(v); else ans.push_front(v); go(v, mark); tot ++; break; } } int m...
0
#include<iostream> #include<bitset> using namespace std; int main(void){ int n,c,benefit,ma=-1000000000; cin>>n; bool f[n][10]; int p[n][11]; for(int i=0;i<n;i++)for(int j=0;j<10;j++)cin>>f[i][j]; for(int i=0;i<n;i++)for(int j=0;j<=10;j++)cin>>p[i][j]; bitset<10>bit; for(int b=1;b<1<<10;...
0
#include <bits/stdc++.h> using namespace std; char s[12500], u[2500], t[2500]; int n, m; int main() { for (int i = 0; i < (10000); ++i) s[i] = 'Z'; gets(u); n = strlen(u); for (int i = 0; i < (n); ++i) s[i + 2500] = u[i]; gets(t); m = strlen(t); int res = m; for (int i = 0; i + m < 10000; ++i) { int...
1
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } const int N = 200005; i...
4
#include <iostream> #include <algorithm> #include <vector> #include <cmath> #define int long long using namespace std; const int mod = 1000000007; signed main() { int n, m; cin >> n >> m; int ans = 1; for (int i = 2; i <= sqrt(m); i++) { if (m%i == 0) { int cnt = 0; while (m%i == 0) { m /= i; cnt++; }...
0
#include <bits/stdc++.h> using namespace std; const int oo = (int)1e9; int n, m, le, ri; string s; int val(string s) { int res = 0, i; for (i = s.length() - 1; s[i] != ' '; i--) ; i++; for (int j = i; j < s.length(); j++) res = res * 10 + (s[j] - '0'); return res; } int main() { scanf("%d%d\n", &n, &m);...
1
#include <bits/stdc++.h> using namespace std; long long a[100010], q[100010]; long long min(long long x, long long y) { return x < y ? x : y; } long long max(long long x, long long y) { return x > y ? x : y; } int main() { int n, d, b, i; long long ans1 = 0, ans2 = 0; scanf("%d%d%d", &n, &d, &b); q[0] = 0; fo...
4
#include <bits/stdc++.h> using namespace std; void pass() { return; } const double EPS = 1e-6; mt19937 rnd(rand() << 15 + rand()); const long long MOD = 1e9 + 7; const long long BIG_MOD = 1e18 + 7; const long long MAXN = 1e6 + 7; long long a[MAXN]; long long last[MAXN]; long long myright[MAXN]; signed main() { cout.t...
6
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); int T; cin >> T; int ans = 0; for (int i = 0; i < n; i++) { int d = 0; while (i + d < n) { if (a[i + d] - a[i] > T) break; d++; } a...
2
#include <bits/stdc++.h> using namespace std; class node { public: int val; int idx; }; int n, m, k; int A[1000100]; node B[1000100]; int myfunc(node f1, node f2) { return f1.val < f2.val; } int getPre(int idx) { for (int i = idx; i >= 1; i--) { if (A[i] != A[idx]) return i + 1; } return 1; } int C[20000...
4
#include <bits/stdc++.h> int main() { char s[10000], ans[10000]; int i = 0, j = 0, l; gets(s); l = strlen(s); for (i = 0; i < l; i++) { if (s[i] == ' ' && (s[i + 1] == ' ' || s[i + 1] == '.' || s[i + 1] == ',' || s[i + 1] == '?' || s[i + 1] == '!')) continue; if (s[i] != ...
1
#include<iostream> #include<algorithm> #include<vector> #include<queue> #include<string> using namespace std; int main(){ while(1){ int n; cin>>n; if(n==0) return 0; int yk=0,h=0,m=0,ans=0; for(int i=0;i<n;i++){ string s; cin>>s; if(s=="lu") h++; else if(s=="ld") h--; ...
0
#include <bits/stdc++.h> using namespace std; const int N = 1e2 + 1; const long long MOD = 1e9 + 7; const int base = 257; const int M = 1e6 + 1; const int INFI = 1e8; long long Hash[M], po[M]; long long gethash(long long l, long long r) { return ((Hash[r] - Hash[l - 1] * po[r - l + 1] + MOD * MOD) % MOD); } void prec...
4
#include <bits/stdc++.h> using namespace std; int main() { string s,t; cin>>s>>t; int ct = 0; for(int i=0;i<s.size();i++) ct += (s[i] == t[i]); cout<<ct; return 0; }
0
#include <bits/stdc++.h> using namespace std; bool debug = 0; int n, m, k; int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; string direc = "RDLU"; long long ln, lk, lm; void etp(bool f = 0) { puts(f ? "YES" : "NO"); exit(0); } void addmod(int &x, int y, int mod = 1000000007) { x += y; if (x >= mod) x -= mod; ...
5
#include <bits/stdc++.h> #pragma GCC optimize ("O3") using namespace std; #define optimize ios::sync_with_stdio(0);cin.tie(0);cout.tie(0) typedef long long ll; typedef vector<int> vi; typedef vector<long long> vl; typedef vector<char> vc; typedef pair<int, int> pi; typedef vector<pi> vpi; bool isPalindrome(string s)...
1
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3f; const double eps = 1e-12; const double PI = acos(-1.0); const int mod = 998244353; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } long long gcd(long long a, long long b) { return b == 0 ? a...
2
#include <bits/stdc++.h> using namespace std; int main() { int H,W,C1,C2,D1,D2; cin>>H>>W>>C1>>C2>>D1>>D2; C1--,C2--,D1--,D2--; vector<char> p(H*W); for(int i=0;i<H;i++){ for(int j=0;j<W;j++){ cin>>p[i*W+j]; } } vector<int> seen(H*W,-1); priority_queue<pair<int,int>,vector<pair<int,int>>...
0
#include <bits/stdc++.h> using namespace std; int main() { char ar[1000000 + 7]; int i, l, k, f = 0, n, m, c = 0; scanf("%s", ar); l = strlen(ar); for (i = 0; i < strlen(ar); i++) { if (ar[i] == 'a') { k = i; f = 1; break; } } for (i = 0; i < l; i++) { if (ar[i] == 'a') c++; ...
1
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int n; cin >> n; long long int ans; long long int f = 0; for (long long int i = 3; i <= 360; i++) { if ((n * i) % 180 == 0 && (n * i) / 180 <= i - 2) { f = 1; ans...
3
#include<bits/stdc++.h> using namespace std; #define int long long //BEGIN CUT HERE struct RUP{ int n; vector<int> dat,laz; const int def=INT_MAX; RUP(){} RUP(int n_){init(n_);} void init(int n_){ n=1; while(n<n_) n*=2; dat.clear(); dat.resize(2*n-1,def); laz.clear(); laz.resize(2*n-...
0
#include <bits/stdc++.h> using pii = std::pair<int, int>; using pll = std::pair<long long, long long>; const int maxn = 1e5 + 100; std::vector<int> v[maxn]; int component[maxn]; int current_component = 0; int farthest[maxn]; int component_diameter[maxn]; std::vector<int> in_component[maxn]; std::vector<int> prefix_sum[...
4
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; const int INF = 1 << 30; int dy[] = {-1, 0, 0, 1}; int dx[] = {0, -1, 1, 0}; int n, m; string c[110]; void solve() { c[0] = c[m + 1] = string(n + 2, '.'); for (int i = 1; i <= m; i++) { cin >> c[i]; c[i] = "." ...
0
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC target("sse4") const char nl = '\n'; using namespace std; using ll = long long; using vi = vector<ll>; using vl = vector<ll>; using pii = pair<ll, ll>; using pll = pair<ll, ll>; using str = string; str to_string(char c) { return str(1, c); } str to_string(...
4
#include <bits/stdc++.h> using namespace std; int main() { int num; cin >> num; vector<long long int> vec; vec.push_back(4); vec.push_back(7); int i = 0, j, k; while (1) { k = vec.size(); if (vec[k - 1] > 1000000000) break; for (j = i; j < k; j++) { vec.push_back(vec[j] * 10 + 4); ...
2
#include <bits/stdc++.h> using namespace std; inline long long read() { char ch = getchar(); long long x = 0, f = 1; while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } long long n...
5
#include <bits/stdc++.h> using namespace std; const int MAXN = 4010; const int inf = 99999999; int ti, td, tr, te, i, j, l1, l2, t, t1, t2; string s1, s2; int f[MAXN][MAXN]; int ss1[MAXN][26], ss2[MAXN][26]; int main() { cin >> ti >> td >> tr >> te; cin >> s1 >> s2; memset(f, 0, sizeof(f)); l1 = s1.size(); l2...
3
#include <bits/stdc++.h> using namespace std; template <class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p); template <template <class...> class _TContainer, class... _T> ostream& operator<<(ostream& out, _TContainer<_T...>& _Container); struct graph { public: private: int Vcnt; vector<vector<pa...
1
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ll n, m, a, b, c; cin >> n; vector<ll> v; for (ll i = 0; i < n; i++) { cin >> a; v.push_back(a); } cin >> b >> c; ll ans = 0; for (ll i = 0; i < n; i++) { ll t = v[i] / (b + c); if (v[i] > b && t == 0) t++; ...
6
#include <bits/stdc++.h> using std::cerr; const int N = 1000005, mu = 1e9 + 7; char s[N]; int a[N], n, lst[N], pre[N], dp[N]; int main() { scanf("%s", s + 1); int m = strlen(s + 1), cnt = 0; for (int i = 1; i <= m; i++) { if (s[i] == '1') a[++n] = cnt, cnt = 0; else cnt++; } a[++n] = cnt; ...
5
#include <iostream> using namespace std; int main(){ const string TABLE[] = {".,!? ","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"}; int n; cin >> n; for(int i=0;i<n;++i){ string s; string ans; int k=0,l=-1; bool in = false; cin >> s; for(int j=0;j<s.size();++j){ if(s[j]=='0'){ if(in){ a...
0
#include <bits/stdc++.h> using namespace std; const int MAX = 1e6 + 5; const long long mod = 1e9 + 7; long long gcd(long long a, long long b) { return (!b ? a : gcd(b, a % b)); } long long exp(long long a, long long b) { if (!b) return 1ll; if (b == 1ll) return a; long long p = exp(a, b >> 1); if (b & 1) return...
2
#include <bits/stdc++.h> using namespace std; class Fenwick { private: vector<int> arr; const int size; public: Fenwick(int n) : arr(n + 1), size(n) { for (int it = 0; it < arr.size(); ++it) arr[it] = 0; } void add(int v, int k) { for (; k <= size; k += (k) & (-k)) { arr[k] += v; } } ...
1
#include <bits/stdc++.h> using namespace std; int main() { string s[1009]; int n, p = 0; ; cin >> n; for (int i = 0; i < n; i++) { cin >> s[i]; string x = s[i]; if (x[0] == 'O' && x[1] == 'O' && p == 0) { x[0] = '+'; x[1] = '+'; p = 1; } if (x[3] == 'O' && x[4] == 'O' && ...
1
#include <bits/stdc++.h> using namespace std; int f(int x) { int i, sum = 0; for (i = 1; i <= x; i++) { sum += i; } return sum; } int main() { int n, n1, i, b[70]; scanf("%d", &n); for (i = 1; i <= 70; i++) { if (n >= f(i) && n < f(i + 1)) { n1 = i; i = 71; } } for (i = 1; i <=...
1
#include <bits/stdc++.h> using namespace std; struct SegTree { vector<int> node; int n; SegTree(int N) { node.assign(N * 4, 0); n = N; } long long get(int l, int r, int i, int lq, int rq) { if (l > r || l > rq || r < lq) { return INT_MAX / 2ll; } if (lq <= l && rq >= r) { retur...
4
#include <bits/stdc++.h> using namespace std; int DD, MM, YY; int leap[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int normal[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; bool f(int bd, int bm, int by) { if (bm > 12 || bm == 0) return 0; if (by % 4 == 0) { if (bd == 0 || bd > leap[bm - 1]...
2
#include <bits/stdc++.h> using namespace std; #define LOG(...) fprintf(stderr, __VA_ARGS__) //#define LOG(...) #define FOR(i, a, b) for(int i=(int)(a); i<(int)(b); ++i) #define REP(i, n) for(int i=0; i<(int)(n); ++i) #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define EXIST(s, e) ((...
0
#include <bits/stdc++.h> using namespace std; int n, m; long long dp[2000 + 5][2000 + 5], k[2000 + 5][2000 + 5], c[2000 + 5][2 * 2000 + 5]; void init() {} void Time_decreasing() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } void enter() { scanf("%d %d", &n, &m); } void Combinatoric() { for (int...
5
#include <bits/stdc++.h> struct { inline operator int() { int x; return scanf("%d", &x), x; } inline operator long long() { long long x; return scanf("%lld", &x), x; } template <class T> inline void operator()(T &x) { x = *this; } template <class T, class... A> inline void operator...
3
#include <bits/stdc++.h> using namespace std; void solve() { int n, m; cin >> n >> m; char a[n][m]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) cin >> a[i][j]; int cnt = 0, x; bool vis[n]; memset(vis, 0, sizeof(vis)); vector<int> v; for (int i = 0; i < m; i++) { cnt = 0; for (i...
2
#include <bits/stdc++.h> using namespace std; int main() { int x, y, ex, ey; cin >> x >> y; cin >> ex >> ey; cout << max(abs(x - ex), abs(y - ey)); }
1
#include <bits/stdc++.h> using namespace std; long long a, b, c, l, A, B, C, ans; int main() { cin >> a >> b >> c >> l; l -= (!a + !b + !c); a += !a; b += !b; c += !c; for (long long i = 0; i <= l; i++) A = max(min(l - i, a + i - b - c), -1ll) + 2, B = max(min(l - i, b + i - a - c), -1ll) + 2, C...
1
#include <bits/stdc++.h> using namespace std; const int maxm = 3e5 + 5; int fa[maxm << 1], cnt[maxm << 1], n, k, state[maxm][2]; int Find(int x) { return fa[x] == x ? x : fa[x] = Find(fa[x]); } void Union(int x, int y) { x = Find(x), y = Find(y); if (y == 0) swap(x, y); fa[y] = x; if (x) cnt[x] += cnt[y]; } int...
5
#include <bits/stdc++.h> using namespace std; const int m = 1e9 + 7; const int N = 3e5 + 10; const int64_t INF = 100000000000000018LL; vector<vector<long long>> graph(N); vector<long long> collect; long long odd = 0, even = 0; long long pow(long long a, long long b, long long m) { long long ans = 1; while (b) { ...
4
#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 T, N; int onxt[500202]; int nnxt[500202]; int a[500202]; bool check() { map<int, int> mi; mi[N + 1] = N + 1; for (...
3
#include <bits/stdc++.h> using namespace std; int n, m; char mapp[2333][2333]; int dist[4][2333][2333]; typedef int arr[2333][2333]; template <class T, int siz> struct fdeque { T st[siz + 3]; int head, tail, fsiz; void clr() { head = tail = fsiz = 0; } bool empty() { return fsiz == 0; } int size() { return fs...
5
#include <bits/stdc++.h> using namespace std; int n; int a[100010]; bool f(int bit) { bool flag = 0; int lim = 1 << bit; for (int i = 0; i < bit; i++) { int j; for (j = 0; j < n; j++) { if (a[j] >= lim) { flag = 1; if ((a[j] & (1 << bit) && (a[j] & (1 << i)) == 0)) { break;...
3
#include <bits/stdc++.h> using namespace std; string int2str(int i) { if (i == 0) return ""; string a = "1"; a[0] = '0' + (i % 10); return int2str(i / 10) + a; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<string> s(n); vector<int> t(n), c(2, 0); for (int ...
5