code_file1
stringlengths
87
4k
code_file2
stringlengths
82
4k
#include <bits/stdc++.h> using namespace std; #define fo(i, x, y) for (int i = (x); i <= (y); ++i) #define fd(i, x, y) for (int i = (x); i >= (y); --i) typedef long long ll; ll n; ll f[100]; vector<int> ans; int getint() { char ch; int res = 0, p; while (!isdigit(ch = getchar()) && (ch ^ '-')); p = ch == '-'? ch = getchar(), -1 : 1; while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar(); return res * p; } int main() { //freopen("t.in", "w", stdout); cin >> n; ll s = 86; f[0] = f[1] = 1; fo(i, 2, s) f[i] = f[i - 1] + f[i - 2]; fo(i, 0, s) { if (i > 0) { if (i & 1) ans.push_back(4); else ans.push_back(3); } if (f[s - i] > n) continue; n -= f[s - i]; if (i & 1) ans.push_back(2); else ans.push_back(1); } printf("%d\n", ans.size()); fo(i, 0, (int)ans.size() - 1) printf("%d\n", ans[i]); //cerr << "#" << n << endl; return 0; }
#include <algorithm> #include <iostream> #include <vector> #include <map> #include <cstdio> #include <string> #include <cmath> #include <queue> #include <tuple> #include <bitset> #include <cassert> #include <chrono> #include <cstring> #include <iomanip> #include <iostream> #include <random> #include <set> #include <stack> #include <time.h> #include <unordered_map> #include <unordered_set> //#include <bits/stdc++.h> #define maxs(x,y) x = max(x,y) #define mins(x,y) x = min(x,y) #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) #define repr(i, n) for (int i = (n) - 1; i >= 0; i--) #define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++) #define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--) #define SORT(x) sort(x.begin(),x.end()) #define SORTR(x) sort(x.begin(),x.end(),greater<int>()) #define fi first #define se second #define pb push_back #define eb emplace_back #define mp make_pair #define mt make_tuple using namespace std; using ll = long long; using LL = long long; typedef std::pair<int, int> pii; typedef std::pair<int, double> pid; typedef std::vector<int> vi; typedef std::vector<pii> vii; const double PI = 3.14159265358979323846264338327950L; const int mod = 1e9+7; struct mint { ll x; // typedef long long ll; mint(ll x=0):x((x%mod+mod)%mod){} mint operator-() const { return mint(-x);} mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { mint res(*this); return res+=a; } mint operator-(const mint a) const { mint res(*this); return res-=a; } mint operator*(const mint a) const { mint res(*this); return res*=a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod-2); } mint& operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res/=a; } }; const ll INF = 1LL<<60; struct container { int bottom, top, id; container(int id, int bottom, int top) : top(top), bottom(bottom), id(id) { } }; struct Edge { ll to, from, cost; Edge(ll to, ll from, ll cost) :to(to), from(from), cost(cost) {} Edge(): to(-1), from(-1), cost(0){} }; struct Data { ll cost,val; Data(ll cost=0, ll val=0) : cost(cost), val(val){} bool operator<(const Data& a) const { return cost > a.cost; } }; struct edge{ int a,b,c; edge(int a = -1,int b = -1, int c = -1):a(a),b(b),c(c){} bool operator<(const edge& a) const { return c > a.c; } }; struct combination { vector<mint> fact, ifact; combination(int n):fact(n+1),ifact(n+1) { assert(n < mod); fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i; ifact[n] = fact[n].inv(); for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i; } mint operator()(int n, int k) { if (k < 0 || k > n) return 0; return fact[n]*ifact[k]*ifact[n-k]; } }; void solve(){ int a,b,c,d; cin >> a >> b >> c >> d; cout << b-c; } int main() { int T = 1; // cin >> T; while (T--) { solve(); // cout << endl; } }
#include<bits/stdc++.h> using namespace std; int a[4]; int main() { cin>>a[1]>>a[2]>>a[3]; sort(a+1,a+4); if(a[2]-a[1]==a[3]-a[2]) { puts("Yes"); } else { puts("No"); } return 0; }
#include <iostream> using namespace std; int main() { int A1,A2,A3,A4; cin >>A1>>A2>>A3>>A4; if (A1<=A2 &&A1<=A3&&A1<=A4) { cout<<A1; } else if (A2<=A1 &&A2<=A3&&A2<=A4) { cout<<A2; } else if (A3<=A1 &&A3<=A2&&A3<=A4) { cout<<A3; } else if (A4<=A1 &&A4<=A2&&A4<=A3) { cout<<A4; } return 0; }
#include <bits/stdc++.h> using namespace std; #define debug(x) cerr << #x << '=' << x << endl #define rep(i, b, e) for (int i = b; i <= e; i++) char ss1[512345], ss2[512345]; char s1[512345], s2[512345]; int work(char *s1, char *s2, int n) { vector<int> a(1), b(1); int ans = 0; rep (i, 1, n) { if (s1[i] == '0') { a.push_back(i); } if (s2[i] == '0') { b.push_back(i); } } rep (i, 0, a.size() - 1) { if (a.at(i) != b.at(i)) { ans++; } } return ans; } int main(void) { int n, cnt = 0; cin >> n; scanf("%s%s", ss1 + 1, ss2 + 1); rep (i, 1, n) { s1[i] = ss1[i]; s2[i] = ss2[i]; } rep (i, 1, n) { if (ss1[i] == '0') { cnt++; } if (ss2[i] == '0') { cnt--; } } if (cnt != 0) { puts("-1"); return 0; } int ans = work(s1, s2, n); cout << ans; return 0; }
#include <iostream> #include <vector> #include <algorithm> int n; std::string s, t; std::vector<int> a, b; int main() { std::ios::sync_with_stdio(false), std::cin.tie(nullptr); std::cin >> n >> s >> t; for (int i = 0; i < s.length(); ++i) if (s[i] == '0') a.push_back(i); for (int i = 0; i < t.length(); ++i) if (t[i] == '0') b.push_back(i); if (a.size() != b.size()) return std::cout << "-1\n", 0; int ans = 0; for (int i = 0; i < a.size(); ++i) if (a[i] != b[i]) ++ans; std::cout << ans << '\n'; return 0; }
//#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using P = pair<int,int>; using PL = pair<ll,ll>; using PPL = pair<pair<ll,ll>,ll>; #define INF 1000000000 #define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++) #define repp(i, n, s) for (int i = (int)(n); i >= (int)(s); i--) #define mp make_pair #define tp make_tuple #define ALL(vec) vec.begin(), vec.end() long long modinv(long long a, long long m) { long long b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll INFLL = numeric_limits<ll>::max(); ll t;cin>>t; rep(_,0,t){ ll x,y,p,q;cin>>x>>y>>p>>q; ll mod1 = (2*x+2*y)%(p+q); ll ans = INFLL; rep(i,x,x+y){ if (mod1==0 && p<=i%(p+q) && i%(p+q) <p+q){ ans = min(ans, (ll)i); continue; } rep(j,p,p+q){ ll num = i%(p+q); ll num2 = j%(p+q); ll num3 = (num2-num+p+q)%(p+q); ll d = __gcd(__gcd((ll)num3,mod1),p+q); ll mod3 = mod1 / d; num3/=d; ll mod2 = (p+q)/d; if (__gcd(mod3,mod2)==1){ ll a1 = modinv(mod3, mod2); ans = min(ans, (a1*num3)%mod2*(2*x+2*y)+i); } } } if (ans==INFLL){ cout<<"infinity"<<endl; continue; } cout<<ans<<endl; } }
/** * author : cuber_coder * created : 09/05/2021 19:43:08 **/ #include <bits/stdc++.h> using namespace std; #define int long long #define endl "\n" void Solve() { int k, n, m; cin >> k >> n >> m; vector<int> a(k); for (auto &i : a) { cin >> i; } set<pair<long double, int>> b; for (int i = 0; i < k; i++) { long double val = 1.0 * a[i] * m / n; a[i] = (a[i] * m) / n; b.insert({val - a[i], i}); } m -= accumulate(begin(a), end(a), 0LL); for (int i = 0; i < m; i++) { int idx = (*b.rbegin()).second; b.erase(*b.rbegin()); a[idx] += 1; } for (auto i : a) cout << i << " "; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int testcases = 1; // cin >> testcases; for (int i = 1; i <= testcases; i++) { Solve(); } return 0; }
#include <bits/stdc++.h> #define ar array using namespace std; const int mxN = 2e5; vector<int> kids[mxN], starts[mxN], inTs[mxN]; int inT[mxN], outT[mxN]; void dfs(int &T, int cur, int d) { inTs[d].push_back(T); inT[cur] = T++; for (int nxt : kids[cur]) dfs(T, nxt, d+1); outT[cur] = T++; } int main() { cin.tie(0)->sync_with_stdio(0); int n; cin >> n; for (int i = 1; i < n; ++i) { int j; cin >> j; --j; kids[j].push_back(i); } { int T = 0; dfs(T, 0, 0); } int q; cin >> q; for (int qq = 0; qq < q; ++qq) { int i, d; cin >> i >> d; --i; auto lo = lower_bound(inTs[d].begin(), inTs[d].end(), inT[i]); auto hi = upper_bound(inTs[d].begin(), inTs[d].end(), outT[i]); cout << hi-lo << '\n'; } }
#include <cstdio> #include <vector> #include <iostream> #include <map> using namespace std; const int M = 200005; #define pii pair<int,int> #define make make_pair int read() { int x=0,f=1;char c; while((c=getchar())<'0' || c>'9') {if(c=='-') f=-1;} while(c>='0' && c<='9') {x=(x<<3)+(x<<1)+(c^48);c=getchar();} return x*f; } int n,m,tot,f[M],dep[M],ans[M];map<int,int> mp[M]; struct edge { int v,next; }e[2*M];vector<pii> v[M]; void dfs(int u,int fa) { dep[u]=dep[fa]+1; mp[u][dep[u]-1]=1; for(int i=f[u];i;i=e[i].next) { int v=e[i].v; if(v==fa) continue; dfs(v,u); if(mp[u].size()<=mp[v].size()) swap(mp[u],mp[v]); map<int,int>::iterator it=mp[v].begin(); for(;it!=mp[v].end();it++) mp[u][(*it).first]+=(*it).second; } for(int i=0;i<v[u].size();i++) ans[v[u][i].second]=mp[u][v[u][i].first]; } signed main() { n=read(); for(int i=2;i<=n;i++) { int j=read(); e[++tot]=edge{i,f[j]},f[j]=tot; e[++tot]=edge{j,f[i]},f[i]=tot; } m=read(); for(int i=1;i<=m;i++) { int u=read(),d=read(); v[u].push_back(make(d,i)); } dfs(1,0); for(int i=1;i<=m;i++) printf("%d\n",ans[i]); }
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; long long inversion_number(vector<int> &A){ int N = A.size(); vector<int> B = A; sort(B.begin(), B.end()); map<int, int> mp; for (int i = 0; i < N; i++) mp[B[i]] = i + 1; for (int i = 0; i < N; i++) A[i] = mp[A[i]]; long long ans = 0; vector<int> BIT(N + 1, 0); for (int i = 0; i < N; i++){ ans += i; int j; j = A[i]; while (j > 0){ ans -= BIT[j]; j -= j & -j; } j = A[i]; while (j <= N){ BIT[j]++; j += j & -j; } } return ans; } int main(){ cin.tie(0); ios::sync_with_stdio(0); int N; cin >> N; vector<int> a(N); rep(i,N) cin >> a[i]; auto b = a; ll ans = inversion_number(b); cout << endl; rep(i,N){ cout << ans << endl; ans = ans + N - 1 - a[i] - a[i]; } }
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(ll i=0;i<(ll)n;i++) #define dump(x) cerr << "Line " << __LINE__ << ": " << #x << " = " << (x) << "\n"; #define spa << " " << #define fi first #define se second #define ALL(a) (a).begin(),(a).end() #define ALLR(a) (a).rbegin(),(a).rend() using ld = long double; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<ld, ld>; template<typename T> using V = vector<T>; template<typename T> using P = pair<T, T>; template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); } template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); } template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){os << "(" << v.first << ", " << v.second << ")"; return os;} template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; } template<class T> ostream& operator<<(ostream& os, const vector<vector<T>> &v){ for(auto &e : v){os << e << "\n";} return os;} struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; template <class T> void UNIQUE(vector<T> &x) {sort(ALL(x));x.erase(unique(ALL(x)), x.end());} template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } void fail() { cout << -1 << '\n'; exit(0); } inline int popcount(const int x) { return __builtin_popcount(x); } inline int popcount(const ll x) { return __builtin_popcountll(x); } template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++) {cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<"\n";}}; template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0]; for(ll i=1;i<n;i++)cerr spa v[i]; cerr<<"\n";}; const ll INF = (1ll<<62); // const ld EPS = 1e-10; // const ld PI = acos(-1.0); const ll mod = (int)1e9 + 7; //const ll mod = 998244353; int main(){ ll N; cin >> N; V<ll> C(N); REP(i, N) cin >> C[i]; V<ll> A(N-1), B(N-1); REP(i, N-1) cin >> A[i] >> B[i], A[i]--, B[i]--; using Graph = V<V<ll>>; Graph G(N); REP(i, N-1){ G[A[i]].push_back(B[i]); G[B[i]].push_back(A[i]); } V<ll> used(202020, 0); V<ll> res; auto dfs = [&](auto self, ll now, ll par)->void{ if(used[C[now]] == 0) res.push_back(now); used[C[now]]++; for(auto next: G[now]){ if(next == par) continue; self(self, next, now); } used[C[now]]--; }; dfs(dfs, 0, -1); sort(ALL(res)); for(auto x: res) cout << x+1 << endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef unsigned long long int ll; const int MOD = 1000000007; void solve(){ int n,m; cin>>n>>m; int **arr = new int*[n]; int s = INT_MAX; for(int i=0;i<n;i++){ arr[i] = new int[m](); for(int j=0;j<m;j++){ cin>>arr[i][j]; s = min(s,arr[i][j]); } } int ans = 0; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ ans = ans + (abs(arr[i][j]-s)); } } cout<<ans<<endl; return; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t=1; //cin>>t; while(t--){ solve(); } return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <complex> #include <cstdio> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <sys/types.h> #include <unistd.h> #include <vector> #pragma region macros #define _overload(_1, _2, _3, name, ...) name #define _rep(i, n) _range(i, 0, n) #define _range(i, a, b) for (int i = int(a); i < int(b); ++i) #define rep(...) _overload(__VA_ARGS__, _range, _rep, )(__VA_ARGS__) #define _rrep(i, n) _rrange(i, n, 0) #define _rrange(i, a, b) for (int i = int(a) - 1; i >= int(b); --i) #define rrep(...) _overload(__VA_ARGS__, _rrange, _rrep, )(__VA_ARGS__) #pragma endregion macros using namespace std; template <class T> bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; } template <class T> bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; } using ll = long long; using R = long double; const R EPS = 1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7 inline int sgn(const R &r) { return (r > EPS) - (r < -EPS); } inline R sq(R x) { return sqrt(max(x, 0.0L)); } const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; const pid_t pid = getpid(); // Problem Specific Parameter: using edge = struct { int to; }; using G = vector<vector<edge>>; vector<int> bfs(const G &graph, int s, int inf) { const int n = graph.size(); vector<int> dist(n, inf); queue<int> q; dist[s] = 0, q.push(s); while (!q.empty()) { int v = q.front(); q.pop(); for (auto &e: graph[v]) { int nc = dist[v] + 1, nv = e.to; if (chmin(dist[nv], nc)) q.push(nv); } } return dist; } int dp[1 << 17][17]; int main(void) { int n, m; cin >> n >> m; G graph(n); rep(i, m) { int a, b; cin >> a >> b; graph[a - 1].push_back({b - 1}); graph[b - 1].push_back({a - 1}); } int k; cin >> k; vector<int> c(k); rep(i, k) { cin >> c[i]; c[i]--; } const int inf = 1 << 25; int cost[20][20]; rep(i, k) { const int src = c[i]; vector<int> dist = bfs(graph, src, inf); rep(j, k) { cost[i][j] = dist[c[j]]; } } rep(mask, 1 << k) rep(i, k) { dp[mask][i] = inf; } rep(i, k) { dp[1 << i][i] = 0; } rep(mask, 1 << k) rep(i, k) { if ((mask >> i) & 1) { rep(j, k) { if ((mask >> j) & 1) { continue; } const int nmask = mask | (1 << j); chmin(dp[nmask][j], dp[mask][i] + cost[i][j]); } } } int ans = inf; rep(i, k) { chmin(ans, dp[(1 << k) - 1][i] + 1); } if (ans == inf) { ans = -1; } cout << ans << endl; return 0; }
#line 2 "/home/defineprogram/Desktop/Library/template/template.cpp" #include <bits/stdc++.h> using namespace std; #define ll long long #define rep(i, n) for (int i = 0; i < n; i++) #define REP(i, n) for (int i = 1; i < n; i++) #define rev(i, n) for (int i = n - 1; i >= 0; i--) #define REV(i, n) for (int i = n - 1; i > 0; i--) #define all(v) v.begin(), v.end() #define PL pair<ll, ll> #define PI pair<int,int> #define len(s) (int)s.size() template <class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true; } return false; } template <class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true; } return false; } constexpr ll inf = 3e18; #line 3 "/home/defineprogram/Desktop/Library/structure/UnionFind.cpp" class UnionFind { int N; vector<int> par, siz; public: int find(int x) { assert(x < N); return (par[x] == x ? x : par[x] = find(par[x])); } void merge(int x, int y) { assert(x < N && y < N); x = find(x); y = find(y); if (x == y) return; if (siz[x] > siz[y]) swap(x, y); par[x] = y; siz[y] += siz[x]; } bool same(int x, int y) { return find(x) == find(y); } int size(int x) { return siz[find(x)]; } UnionFind(int N) : N(N), siz(N, 1), par(N) { iota(all(par), 0); } }; /* @brief Union Find @docs docs/UnionFind.md */ #line 3 "main.cpp" int H,W; int main() { cin.tie(0); ios::sync_with_stdio(false); cin>>H>>W; UnionFind uf(H+W); uf.merge(0,H-1); uf.merge(0,H); uf.merge(0,H+W-1); rep(i,H)rep(j,W){ char c; cin>>c; if(c=='#')uf.merge(i,j+H); } set<int>ans1,ans2; rep(i,H){ ans1.insert(uf.find(i)); } rep(i,W){ ans2.insert(uf.find(i+H)); } cout<<min(len(ans1),len(ans2))-1<<"\n"; }
#include <bits/stdc++.h> //#include <atcoder/all> #define endl "\n" using namespace std; typedef long long ll; typedef pair<ll, ll> l_l; typedef pair<int, int> i_i; template<class T> inline bool chmax(T &a, T b) { if(a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T &a, T b) { if(a > b) { a = b; return true; } return false; } const long long INF = 1e18; //const ll mod = 1000000007; ll N; ll A[301000]; ll B[301000]; struct SegmentTree { private: int n; vector<ll> node; public: SegmentTree() { int sz = 201000; n = 1; while(n < sz) n *= 2; node.resize(2*n-1, 0); for(int i=0; i<sz; i++) node[i+n-1] = 0; for(int i=n-2; i>=0; i--) node[i] = (node[2*i+1] + node[2*i+2]); } void update(int x, int val) { x += (n - 1); node[x] = val; while(x > 0) { x = (x - 1) / 2; node[x] = (node[2*x+1] +node[2*x+2]); } } // hannkaikukann ll getsum(int a, int b, int k=0, int l=0, int r=-1) { if(r < 0) r = n; if(r <= a || b <= l) return 0; if(a <= l && r <= b) return node[k]; ll vl = getsum(a, b, 2*k+1, l, (l+r)/2); ll vr = getsum(a, b, 2*k+2, (l+r)/2, r); return (vl + vr); } }; int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N; map<ll, vector<ll>> mpA, mpB; for(int i = 0; i < N; i++) { cin >> A[i]; mpA[A[i]+i].push_back(i); } for(int i = 0; i < N; i++) { cin >> B[i]; mpB[B[i]+i].push_back(i); } vector<ll> p(N); for(auto tmp : mpA) { auto v = tmp.second; auto u = mpB[tmp.first]; if(v.size() != u.size()) { cout << "-1" << endl; return 0; } for(int i = 0; i < u.size(); i++) { p[u[i]] = v[i]; } } ll ans = 0; SegmentTree seg; for(auto val : p) { ans += seg.getsum(val, N); seg.update(val, 1); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define REP(i, s, n) for (int i = s; i < (int)(n); i++) #define ALL(a) a.begin(), a.end() #define MOD 1000000007 using namespace std; using ll = long long; int main() { int N, Q; cin >> N; vector<int> A(N), T(N); REP(i, 0, N) cin >> A[i] >> T[i]; cin >> Q; vector<ll> X(Q); REP(i, 0, Q) cin >> X[i]; set<ll> S; REP(i, 0, Q) S.insert(X[i]); ll offset = 0; REP(i, 0, N) { if (T[i] == 1) { offset += A[i]; } else if (T[i] == 2) { auto itr = S.lower_bound(A[i] - offset); bool deleted = false; auto jtr = S.begin(); while (jtr != itr) { jtr = S.erase(jtr); deleted = true; } if (deleted) { S.insert(A[i] - offset); } } else { auto itr = S.lower_bound(A[i] - offset); bool deleted = false; while (itr != S.end()) { itr = S.erase(itr); deleted = true; } if (deleted) { S.insert(A[i] - offset); } } } // for (auto x : S) cout << x << " "; // cout << endl; REP(i, 0, Q) { auto itr = S.lower_bound(X[i]); if (itr != S.begin() && (itr == S.end() || *itr > X[i])) itr = prev(itr); // cout << "# i : " << i << ", X[i] : " << X[i] << ", itr : " << *itr << endl; cout << *itr + offset << endl; } return 0; }
#include <bits/stdc++.h> #define int long long using namespace std; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int a[n], t[n]; for (int i = 0; i < n; i++) cin >> a[i] >> t[i]; int q; cin >> q; int x[q]; for (int i = 0; i < q; i++) cin >> x[i]; int lazy = 0; int lo = -1e17, hi = 1e17; for (int i = 0; i < n; i++) { if (t[i] == 1) lazy += a[i]; else if (t[i] == 2) lo = max(lo, a[i]-lazy); else hi = min(hi, a[i]-lazy); } int loVal = lo; int hiVal = hi; for (int i = 0; i < n; i++) { if (t[i] == 1) { loVal += a[i]; hiVal += a[i]; } if (t[i] == 2) { loVal = max(loVal, a[i]); hiVal = max(hiVal, a[i]); } if (t[i] == 3) { loVal = min(loVal, a[i]); hiVal = min(hiVal, a[i]); } } for (int i = 0; i < q; i++) { if (x[i] <= lo) cout << loVal << '\n'; else if (x[i] >= hi) cout << hiVal << '\n'; else cout << x[i]+lazy << '\n'; } cout << '\n'; } /* */
// Created by ash_98 #include<bits/stdc++.h> using namespace std; #define mx 200005 #define ll long long #define mod 1000000007 int ar[mx]; char ch[mx]; int n,m,ii,k; pair<ll,int> chk(vector<ll>c,vector<ll>b,int bat) { vector<ll>a; int sz=c.size(); for(int i=0;i<sz;i++) { if(i!=bat)a.push_back(c[i]); } int sz1=a.size(); int sz2=b.size(); ll re=1e18; int id=-1; for(int i=0;i<sz1;i++) { int be=0,en=sz2-1; int shuru=-1; while(be<=en) { int mid=(be+en)/2; if(b[mid]<a[i]) { shuru=mid; be=mid+1; } else en=mid-1; } if((shuru+1)<sz2) { ll val=abs(a[i]-b[shuru+1]); if(val<re) { re=val; id=i; } } if(shuru!=-1) { ll val=abs(a[i]-b[shuru]); if(val<re) { re=val; id=i; } } } return {re,id}; } ll func(vector<ll>a,vector<ll>b,vector<ll>c) { ll re=chk(a,b,-1).first; int sz3=c.size(); if(sz3<2)return re; pair<ll,int>re1=chk(c,a,-1); pair<ll,int>re2=chk(c,b,re1.second); re=min(re,re1.first+re2.first); re1=chk(c,b,-1); re2=chk(c,a,re1.second); re=min(re,re1.first+re2.first); return re; } void solve() { vector<ll>R,B,G; scanf("%d",&n); n*=2; for(int i=1;i<=n;i++) { ll x; char cc; cin>>x>>cc; if(cc=='R')R.push_back(x); else if(cc=='B')B.push_back(x); else G.push_back(x); } int sz1=R.size(); int sz2=B.size(); int sz3=G.size(); sort(R.begin(),R.end()); sort(G.begin(),G.end()); sort(B.begin(),B.end()); if(sz1%2==0 && sz2%2==0 && sz3%2==0) { printf("0\n"); return; } if(sz1%2==0) { printf("%lld\n",func(B,G,R)); } else if(sz2%2==0) { printf("%lld\n",func(G,R,B)); } else { printf("%lld\n",func(B,R,G)); } } int main() { int t=1; //scanf("%d",&t); while(t--)solve(); return 0; }
#include<bits/stdc++.h> #define For(a,b,c) for(int a=b;a<=c;++a) #define Dor(a,b,c) for(int a=b;a>=c;--a) #define CC(_...) fprintf(stderr,_) using namespace std; typedef long long LL; enum{N=400007}; int n,S[3]; LL ans; struct O { LL a; int c; bool operator < (const O &_) const { return a<_.a; } }A[N]; int main() { scanf("%d",&n); For(i,1,n*2) { char c[9]; scanf("%lld%s",&A[i].a,c); if(*c=='R') A[i].c=0; if(*c=='G') A[i].c=1; if(*c=='B') A[i].c=2; } For(i,1,n*2) ++S[A[i].c]; LL a=(S[0]&1),b=(S[1]&1),c=(S[2]&1),p,q,ac,bc,ca,cb; if(!a&&!b&&!c) { puts("0"); return 0; } if(a&&b) p=0,q=1; if(a&&c) p=0,q=2; if(b&&c) p=1,q=2; sort(A+1,A+1+n*2); a=b=c=-1LL<<59,ac=bc=ca=cb=ans=1LL<<59; For(i,1,n*2) { if(A[i].c==p) { ca=min(ca,A[i].a-c); ans=min(ans,A[i].a-b); a=A[i].a; } else if(A[i].c==q) { cb=min(cb,A[i].a-c); ans=min(ans,A[i].a-a); b=A[i].a; } else { ac=min(ac,A[i].a-a); bc=min(bc,A[i].a-b); c=A[i].a; } } ans=min(ans,min(ca,ac)+min(cb,bc)); printf("%lld",ans); return 0; }
#include<stdio.h> #include<string.h> #include<math.h> #include<stdlib.h> #include<algorithm> using namespace std; inline void MAX(int &a,const int &b) {if(b>a) a=b;} inline void MIN(int &a,const int &b) {if(b<a) a=b;} inline int max(const int &a,const int &b) {return a>b?a:b;} inline int min(const int &a,const int &b) {return a<b?a:b;} const int N=2e5+5; int mx,n,m,a[N],b[N]; int tmp[N],len; struct BIT { int c[N]; long long d[N]; inline void addc(int pos,int key) {for(int i=pos ; i<=mx ; i+=i&-i) c[i]+=key;} inline void addd(int pos,long long key) {for(int i=pos ; i<=mx ; i+=i&-i) d[i]+=key;} inline int sumc(int pos) {int res=0;for(int i=pos ; i ; i-=i&-i) res+=c[i];return res;} inline long long sumd(int pos) {long long res=0;for(int i=pos ; i ; i-=i&-i) res+=d[i];return res;} inline long long query(int key) { return sumd(mx)-sumd(key)+1LL*sumc(key)*tmp[key]; } }TA,TB; struct ask { int t,x; long long y; inline ask (int T=0,int X=0,int Y=0) : t(T),x(X),y(Y) {} }w[N]; int q; int main() { tmp[++len]=0; scanf("%d%d",&n,&m); scanf("%d",&q); for(int i=1 ; i<=q ; ++i) scanf("%d%d%d",&w[i].t,&w[i].x,&w[i].y),tmp[++len]=w[i].y; sort(tmp+1,tmp+len+1); mx=unique(tmp+1,tmp+len+1)-tmp-1; TA.addc(1,n),TB.addc(1,m); long long ans=0; for(int i=1 ; i<=q ; ++i) { int t=w[i].t,x=w[i].x,y=w[i].y,p=lower_bound(tmp+1,tmp+mx+1,y)-tmp; if(t==1) { int po=lower_bound(tmp+1,tmp+mx+1,a[x])-tmp; ans-=TB.query(po),TA.addc(po,-1),TA.addd(po,-a[x]); ans+=TB.query(p),TA.addc(p,1),TA.addd(p,y); a[x]=y; } else { int po=lower_bound(tmp+1,tmp+mx+1,b[x])-tmp; ans-=TA.query(po),TB.addc(po,-1),TB.addd(po,-b[x]); ans+=TA.query(p),TB.addc(p,1),TB.addd(p,y); b[x]=y; } printf("%lld\n",ans); } return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int, int> #define pll pair<ll, ll> #define vi vector<int> #define vll vector<ll> #define vpii vector<pair<int,int>> #define vpll vector<pair<ll,ll>> #define fr(i,k,n) for (int i = k; i < n; ++i) #define fri(i,k,n) for (int i = k; i >= n; --i) #define pb push_back #define mp make_pair #define all(arr) arr.begin(),arr.end() #define ff first #define ss second const double pi=3.1415926535897932384626433832795; const int inf=1e9; const ll inf2=1e18; const int mod=1e9+7; void boost(){ ios_base::sync_with_stdio(false); cin.tie(NULL); } const int bs=440,N=2e5+3,M=(N+bs-1)/bs; ll cnt[2][N],sqcnt[2][M]; ll sum[2][N],sqsum[2][M]; ll t,x,y,z,i1,i2,i3,i4; ll ans=0; vector<vll> val(2,vll(N,0)); vi diff; void fun(ll f){ z=val[t][x]; i1=lower_bound(all(diff),z)-diff.begin(); i3=i1; while(i3>=0 && (i3/bs)==(i1/bs)){ ans+=(f*cnt[i2][i3]*z); i3--; } while(i3>=0){ ans+=(f*sqcnt[i2][i3/bs]*z); i3-=bs; } i3=i1+1; while(i3<N && (i3/bs)==(i1/bs)){ ans+=f*sum[i2][i3]; i3++; } while(i3<N && (i3/bs)<M){ ans+=f*sqsum[i2][i3/bs]; i3+=bs; } } void solve(){ int n,m,q; cin>>n>>m>>q; vector<pair<int,pii>> qry(q); fr(i,0,q){ cin>>qry[i].ff>>qry[i].ss.ff>>qry[i].ss.ss; qry[i].ff--; diff.pb(qry[i].ss.ss); } diff.pb(0); sort(all(diff)); diff.erase(unique(all(diff)),diff.end()); cnt[0][0]=sqcnt[0][0]=n; cnt[1][0]=sqcnt[1][0]=m; fr(i,0,q){ t=qry[i].ff;x=qry[i].ss.ff;y=qry[i].ss.ss; i2=1-t; fun(-1); cnt[t][i1]--; sqcnt[t][i1/bs]--; sum[t][i1]-=z; sqsum[t][i1/bs]-=z; val[t][x]=y; fun(1); cnt[t][i1]++; sqcnt[t][i1/bs]++; sum[t][i1]+=y; sqsum[t][i1/bs]+=y; cout<<ans<<endl; } return; } int main() { boost(); int tc=1; //cin>>tc; while(tc--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(long (i)=1;(i)<(n+1);(i)++) #define mod 998244353 int main(){ int N; long long S; S = 2329089562801; cout << S << endl; }
#include <iostream> #include <string> #include <math.h> #include <vector> #include <algorithm> #include <iomanip> #include <set> #include <queue> #include <deque> #include <map> #include <stack> #include <cmath> using namespace std; #define mod 1000000007 #define ten5 100005 #define ten52 200015 #define ten53 300005 #define ten6 1000005 #define PI 3.1415926 #define pb(x) push_back(x) #define all(x) x.begin(),x.end() #define mkpr(x1,x2) make_pair(x1,x2) typedef long long int ll; ll num[ten52]; ll hcf(ll a,ll b) { if(a==b || b==0) return a; if(a>b) return hcf(b,a%b); else return hcf(a,b%a); } int main(void) { ll m=0,n,i=1,j=0,k=1,t=1,ans=2; cin>>n; for(i=3;i<=n;i++) { ans=ans*i/hcf(ans,i); } cout<<ans+1; return 0; }
#ifdef LOGX #define _GLIBCXX_DEBUG #endif #include <bits/stdc++.h> using namespace std; //#include <atcoder/all> //using namespace atcoder; /*---------macro---------*/ #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define rep2(i, s, n) for (int i = s; i < (int)(n); ++i) #define ALL(a) a.begin(),a.end() #define RALL(a) a.rbegin(),a.rend() #define mybit(i,j) (((i)>>(j))&1) /*---------type/const---------*/ typedef long long ll; typedef unsigned long long ull; typedef std::string::const_iterator state; //構文解析 const ll big=1000000007; //const ll big=998244353; const double EPS=1e-8; //適宜変える const int dx[4]={1,0,-1,0}; const int dy[4]={0,1,0,-1}; const char newl='\n'; struct{ constexpr operator int(){return -int(1e9)-10;} constexpr operator ll(){return -ll(1e18)-10;} }neginf; struct{ constexpr operator int(){return int(1e9)+10;} constexpr operator ll(){return ll(1e18)+10;} constexpr auto operator -(){return neginf;} }inf; /*---------debug---------*/ #ifdef LOGX #include <template/debug.hpp> #else #define dbg(...) ; #define dbgnewl ; #define prt(x) ; #define _prt(x) ; #endif /*---------function---------*/ template<typename T> T max(const std::vector<T> &a){T ans=a[0];for(T elem:a){ans=max(ans,elem);}return ans;} template<typename T> T min(const std::vector<T> &a){T ans=a[0];for(T elem:a){ans=min(ans,elem);}return ans;} template<typename T,typename U> bool chmin(T &a,const U b){if(a>b){a=b;return true;}return false;} template<typename T,typename U> bool chmax(T &a,const U b){if(a<b){a=b;return true;}return false;} bool valid(int i,int j,int h,int w){return (i>=0 && j>=0 && i<h && j<w);} template<class T,class U>T expm(T x,U y,const ll mod=big){T res=1;while(y){if(y&1)(res*=x)%=mod;(x*=x)%=mod;y>>=1;}return res;} template<class T,class U>T exp(T x,U y){T res=1;while(y){if(y&1)res*=x;x*=x;y>>=1;}return res;} constexpr long long primetest[]={2,3,61}; constexpr long long primetest_big[]={2,325,9375,28178,450775,9780504,1795265022}; //O(N^(1/4)) //N>2^32では__int128_tが使える環境に限る bool isprime(const long long x){ if(x==0 || x==1)return false; const long long d=(x-1)/((x-1)&-(x-1)); if(x<(1LL<<32)){ if(x==2 || x==3 || x==61)return true; for(long long e:primetest){ long long t=d; long long y=expm(e,t,x); if(y==1)continue;//とりあえずテスト通過. while(y!=x-1){//y=-1になったらその時点でテスト通過. y=(y*y)%x;//y=e^2t modx. if(y==1 || t==x-1)return false;//y==1:1の平方根に1,-1以外が存在.t==x-1:e^t!=1. t<<=1; } } return true; } else{ for(__int128_t e:primetest_big){ long long t=d; __int128_t y=expm(e,t,x); if(y==1)continue;//とりあえずテスト通過. while(y!=x-1){//y=-1になったらその時点でテスト通過. y=(y*y)%x;//y=e^2t modx. if(y==1 || t==x-1)return false;//y==1:1の平方根に1,-1以外が存在.t==x-1:e^t!=1. t<<=1; } } return true; } } int main(){ std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.precision(10); /*--------------------------------*/ ll a,b;cin >> a >> b; vector<ll> ps; rep(i,b-a+1){ if(isprime(i))ps.emplace_back(i); } vector<int> has; for(ll i=a;i<=b;i++){ int now=0; rep(j,ps.size())if(i%ps[j] == 0)now|=1<<j; has.emplace_back(now); } vector<ll> dp(1<<ps.size()); dp[0]=1; rep(i,b-a+1)for(int S=(1<<ps.size())-1;S>=0;S--){ if((S&has[i]) == 0)dp[S|has[i]]+=dp[S]; } ll ans=0; for(ll x:dp){ ans+=x; } cout << ans << newl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define ALL(x) ((x).begin()), ((x).end()) #define READ(x) (cin >> (x)) #define WRITE_N(x) (cout << (x) << endl) #define WRITE(x) (cout << (x)) #define WRITE_YESNO(x) (WRITE_N((x) ? "Yes" : "No")) #define PRECISE_COUT std::cout << std::setprecision(15) << std::fixed bool xor_logic(bool x, bool y) { return (x && y) || (!x && !y); } int main() { // get values from input cin.tie(0); ios::sync_with_stdio(false); int A, B; cin >> A >> B; // main procedure // output cout << 2 * A + 100 - B << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<(n);++i) typedef long long int ll; int main() { string n; cin >> n; int numbers[n.length()]; int i = 0; int sum = 0; for (auto c : n) { numbers[i] = c - '0'; sum += numbers[i]; ++i; } int t = 0; for (int i=0; i<n.length(); ++i) { for (int j=0; j<=n.length()-i; ++j) { t = 0; for (int k=j; k<j+i; ++k) { t += numbers[k]; } if ((sum-t) % 3 == 0) { cout << i << endl; return 0; } } } cout << -1 << endl; }
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,a,b) for(int i=a;i>=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() //#pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } //--------------------------------------------------------------------------------------------------- /*---------------------------------------------------------------------------------------------------             ∧_∧       ∧_∧  (´<_` )  Welcome to My Coding Space!      ( ´_ゝ`) /  ⌒i @hamayanhamayan0     /   \    | |     /   / ̄ ̄ ̄ ̄/  |   __(__ニつ/  _/ .| .|____      \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ string S; string zone = "ZONe"; //--------------------------------------------------------------------------------------------------- void _main() { cin >> S; int ans = 0; rep(i, 0, S.length()) if (S.substr(i, 4) == zone) ans++; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll mod = 1e9 + 7; int n; const int maxn = 5e5 + 10; char s[maxn], t[maxn]; queue<int> q; int main() { while(~scanf("%d%*c", &n)) { while(!q.empty()) q.pop(); int cnt1 = 0, cnt2 = 0; ll ans = 0; for(int i = 1; i <= n; i++) scanf("%1d", &s[i]), cnt1 += s[i]; for(int i = 1; i <= n; i++) scanf("%1d", &t[i]), cnt2 += t[i]; for(int i = 1; i <= n; i++) if(s[i] == 1) q.push(i); for(int i = 1; i <= n; i++) { if(t[i] == 0) { if(!q.empty() && q.front() <= i) { cnt1 -= 2; if(cnt1 < cnt2) { ans = -1; break; } int x = q.front(); q.pop(); int y = q.front(); q.pop(); ans += y-x; } } else { int x = q.front(); q.pop(); ans += x-i; } } printf("%lld\n", ans); } //system("pause"); return 0; }
#include<iostream> #include<assert.h> #define int long long #define endl '\n' #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define infi INT_MAX #define rinfi INT_MIN #define inf LLONG_MAX #define rinf LLONG_MIN #define ff first #define ss second #ifndef ONLINE_JUDGE #define line cout<<"here - "<<__LINE__<<"\n"; #define dbg(a) cout<<#a<<" --> "<<(a)<<"\n"; #define db(a,b) cout<<#a<<" --> "<<(a)<<"\n";cin>>b; #else #define line #define dbg(a) #define db(a,b) #endif char _; using namespace std; int i,j,a; string s,t; void go() { while(i<a && s[i]=='0') i++; } main() { // fast int tc=1,k; // cin>>tc; // getchar(); while(tc--) { cin>>a; cin>>s>>t; int ans=0; i=0;j=0; a=s.size(); while(j<a) { while(i<a && s[i]=='0') i++; while(j<a && t[j]=='0') j++; int cnt=i; int ok=0,m=0; while(i<j && j<a && i<a) { int cnt=i; i++; go(); ans+=i-cnt; i++; go(); } dbg(ans) if(j<a && t[j]=='1') { if(i<j || i>=a) { cout<<-1<<endl; return 0; } } else if(j==a){ break; } dbg(i) dbg(j) ans+=i-j; i++; j++; } dbg(i) dbg(j) assert(i<=a); assert(j<=a); for(;i<a;i++) { if(s[i]=='1') { int cnt=i; i++; go(); if(i>=a) { cout<<-1<<endl; return 0; } ans+=i-cnt; } } cout<<ans<<endl; i=0,j=0; } }
#pragma GCC optimize ("O2") #pragma GCC target ("avx2") //#include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; #include<iostream> #include<cstring> using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please const int IM = 2e9; int dat[400004]; int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; dat[0] = -IM; ll kotae = -IM * ll(N); for (int i = N + 1; i > 1; i--) { cin >> dat[i]; kotae += dat[i]; } for (int i = 2; i < N + 2; i++) { int p = 2 + (dat[2] > dat[3]); int v = dat[i] - IM; while (v > dat[p]) { dat[p >> 1] = dat[p]; p <<= 1; p += dat[p] > dat[p + 1]; } dat[p >> 1] = v; int a; cin >> a; kotae += a; p = i; v = a - IM; while (v < dat[p >> 1]) dat[p] = dat[p >> 1], p >>= 1; dat[p] = v; kotae -= dat[1]; } co(kotae); Would you please return 0; }
#include <iostream> #include <queue> using namespace std; typedef long long ll; int main() { int n; cin >> n; ll a[400005]; for(int i = 0; i < n * 2; i++) cin >> a[i]; priority_queue<ll> que; ll ans = 0; for(int i = 0; i < n; i++){ que.push(a[i]); que.push(a[n * 2 - i - 1]); ans += que.top(); que.pop(); } cout << ans << endl; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define endl '\n' #define fi first #define se second #define For(i, l, r) for (int i = l; i < r; i++) #define ForE(i, l, r) for (int i = l; i <= r; i++) #define FordE(i, l, r) for (int i = l; i >= r; i--) #define Fora(v, a) for (auto v: a) #define bend(a) a.begin(), a.end() #define isz(a) ((signed)a.size()) typedef long long ll; typedef long double ld; typedef pair <int, int> pii; typedef vector <int> vi; typedef vector <pii> vpii; typedef vector <vi> vvi; const int N = 1e3 + 5, inf = 1e9 + 7; int dp1[N], dp2[N]; signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen(".inp", "r", stdin); // freopen(".out", "w", stdout); int a, b, w; cin >> a >> b >> w; w *= 1000; int ansa = (w + b - 1) / b, ansb = w / a; if (ansa > ansb){ cout << "UNSATISFIABLE" << endl; } else{ cout << ansa << ' ' << ansb << endl; } } /* ==================================================+ INPUT: | --------------------------------------------------| --------------------------------------------------| ==================================================+ OUTPUT: | --------------------------------------------------| --------------------------------------------------| ==================================================+ */
#include <bits/stdc++.h> using namespace std; int main(){ int a,b,w,x,y; cin >> a >> b >> w; w *= 1000; if((w + b -1) / b * a <= w){ cout << (w + b - 1) / b << endl;; } if((w / a) * b >= w){ cout << w / a << endl; } else{ cout << "UNSATISFIABLE" << endl; } }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <tuple> #include <vector> #define mkp make_pair #define mkt make_tuple #define rep(i, n) for (int i = 0; i < (n); ++i) #define all(v) v.begin(), v.end() using namespace std; typedef long long ll; const ll MOD = 1e9 + 7; // const ll MOD = 998244353; template <class T> void chmin(T &a, const T &b) { if (a > b) a = b; } template <class T> void chmax(T &a, const T &b) { if (a < b) a = b; } void add(ll &a, ll b) { a = (a + b) % MOD; } void mul(ll &a, ll b) { a %= MOD; b %= MOD; a = a * b % MOD; } void solve() { int N; cin >> N; vector<ll> A(N); rep(i, N) cin >> A[i]; vector<vector<vector<int>>> idxs(N + 1, vector<vector<int>>(N + 1)); for (int k = 1; k <= N; k++) { ll sum = 0; idxs[k][0].push_back(0); for (int i = 0; i < N; i++) { sum += A[i]; sum %= k; idxs[k][sum].push_back(i + 1); } } vector<vector<int>> nxt(N + 1, vector<int>(N + 1, -1)); for (int k = 1; k <= N; k++) { for (int rest = 0; rest < k; rest++) { for (int j = 0; j + 1 < idxs[k][rest].size(); j++) { nxt[idxs[k][rest][j]][k] = idxs[k][rest][j + 1]; } } } vector<vector<ll>> dp(N + 1, vector<ll>(N + 1, -1)); auto rec = [&](auto &&rec, int now, int divisor) -> ll { if (now == N) return 1; if (dp[now][divisor] != -1) return dp[now][divisor]; ll sum = 0; ll res = 0; if (nxt[now][divisor] != -1) { add(res, rec(rec, nxt[now][divisor], divisor)); if (nxt[now][divisor] < N) add(res, rec(rec, nxt[now][divisor], divisor + 1)); } return dp[now][divisor] = res; }; ll ans = rec(rec, 0, 1); cout << ans << endl; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); solve(); return 0; }
//#define _GLIBCXX_DEBUG #include <bits/stdc++.h> #define FOR(i, a, b) for (ll i = (a); i < (b); ++i) #define REP(i, n) FOR(i,0,n) #define BFOR(bit,a,b) for(int bit = (a); bit < (1<<(b)); ++bit) #define BREP(bit,n) BFOR(bit,0,n) using namespace std; using ll = long long; int main() { ll n; string t; cin >> n >> t; if(t == "1"){ ll ans = 1e10 * 2; cout << ans << endl; return 0; } if(t == "0"){ ll ans = 1e10; cout << ans << endl; return 0; } if(t == "00"){ ll ans = 0; cout << ans << endl; return 0; } if(t == "10"){ ll ans = 1e10; cout << ans << endl; return 0; } if(t == "01"){ ll ans = 1e10-1; cout << ans << endl; return 0; } if(t == "11"){ ll ans = 1e10; cout << ans << endl; return 0; } if(t[0] != '1' || t[1] != '1' || t[2] != '0'){ if(t[0] == '1' && t[1] == '0'){ t = "1"+t; n++; } else if(t[0] == '0'){ t = "11"+t; n += 2; } else{ cout << 0 << endl; return 0; } } if(t[n-3] != '1' || t[n-2] != '1' || t[n-1] != '0'){ if(t[n-1] == '1' && t[n-2] == '1'){ t = t+"0"; n++; } else if(t[n-1] == '1'){ t = t+"10"; n += 2; } } if(n % 3 != 0){ cout << 0 << endl; return 0; } string s; REP(i,n/3) s += "110"; ll ans; if(s == t) ans = 1e10 - n/3+1; else ans = 0; cout << ans << endl; }
#include <bits/stdc++.h> // #include <atcoder/modint> #define rng(a) a.begin(),a.end() #define rrng(a) a.rbegin(),a.rend() #define INF 2000000000000000000 #define ll long long #define ld long double #define pll pair<ll, ll> using namespace std; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll N; cin >> N; vector<pll> data(N); vector<vector<ll>> connection(N); for (ll i = 0; i < N - 1; ++i) { ll a, b; cin >> a >> b; a -= 1, b -= 1; connection.at(a).push_back(b); connection.at(b).push_back(a); data.at(i) = {a, b}; } queue<pll> q;//now, par vector<ll> par(N, -1); q.push({0, -1}); while (!q.empty()) { ll now = q.front().first, p = q.front().second; q.pop(); for (ll i = 0; i < connection.at(now).size(); ++i) { ll next = connection.at(now).at(i); if (next == p) { continue; } par.at(next) = now; q.push({next, now}); } } vector<ll> ans(N, 0); ll Q; cin >> Q; ll sum = 0; for (ll i = 0; i < Q; ++i) { ll t, e, x; cin >> t >> e >> x; e -= 1; ll a = data.at(e).first, b = data.at(e).second; if (t == 2) { swap(a, b); } if (par.at(a) == b) { ans.at(a) += x; } else { ans.at(b) -= x; sum += x; } } q.push({0, -1}); while (!q.empty()) { ll now = q.front().first, p = q.front().second; q.pop(); for (ll i = 0; i < connection.at(now).size(); ++i) { ll next = connection.at(now).at(i); if (next == p) { continue; } ans.at(next) += ans.at(now); q.push({next, now}); } } for (ll i = 0; i < N; ++i) { cout << ans.at(i) + sum << "\n"; } }
#include <bits/stdc++.h> using namespace std; using lint = long long int; using P = pair<int, int>; using PL = pair<lint, lint>; #define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++) #define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--) #define REP(i, n) FOR(i,0,n) #define IREP(i, n) IFOR(i,0,n) #define ALL(a) (a).begin(),(a).end() constexpr int MOD = 1000000007; constexpr lint B1 = 1532834020; constexpr lint M1 = 2147482409; constexpr lint B2 = 1388622299; constexpr lint M2 = 2147478017; constexpr int INF = 2147483647; void yes(bool expr) {cout << (expr ? "Yes" : "No") << "\n";} template<class T>void chmax(T &a, const T &b) { if (a<b) a=b; } template<class T>void chmin(T &a, const T &b) { if (b<a) a=b; } struct Node; vector<Node> V; struct Node { vector<int> nbr; int d; lint ans = 0; lint tmp = 0; bool vst = false; void dfsd(int _d) { d = _d; vst = true; for(int x : nbr) if(!V[x].vst) V[x].dfsd(_d+1); } void dfs(lint val) { ans = val + tmp; vst = true; for(int x : nbr) if(!V[x].vst) V[x].dfs(ans); }; }; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int N; cin >> N; vector<int> a(N-1), b(N-1); V = vector<Node>(N); REP(i, N-1) { cin >> a[i] >> b[i]; a[i]--; b[i]--; V[a[i]].nbr.push_back(b[i]); V[b[i]].nbr.push_back(a[i]); } V[0].dfsd(0); int Q; cin >> Q; lint all = 0; REP(q, Q) { lint t, e, x; cin >> t >> e >> x; e--; if(t == 1) { if(V[a[e]].d < V[b[e]].d) { V[b[e]].tmp -= x; all += x; } else { V[a[e]].tmp += x; } } else { if(V[a[e]].d > V[b[e]].d) { V[a[e]].tmp -= x; all += x; } else { V[b[e]].tmp += x; } } } REP(i, N) V[i].vst = false; V[0].dfs(0); REP(i, N) cout << V[i].ans + all << "\n"; }
/* * @Author: zhl * @Date: 2020-10-18 20:56:45 */ #include<bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int A[N], B[N], n; int ans; void dfs(int now, stack<int> s, int sum) { if (now == n) { if (s.empty()) { ans = max(ans, sum); return; } } if (!s.empty()) { int tp = s.top(); int d = max(A[tp] + A[now + 1], B[tp] + B[now + 1]); s.pop(); dfs(now + 1, s, sum + d); s.push(tp); } if (n - now >= s.size()) { s.push(now + 1); dfs(now + 1, s, sum); } } int main() { cin >> n; long long ans = 0; for (int i = 1; i <= n; i++)cin >> A[i], ans += A[i]; for (int i = 1; i <= n; i++)cin >> B[i], B[i] -= A[i]; vector<int>a, b; for (int i = 1; i <= n; i++) { if (i & 1)a.push_back(B[i]); else b.push_back(B[i]); } sort(a.begin(), a.end(), greater<int>()); sort(b.begin(), b.end(), greater<int>()); for (int i = 1; i <= n / 2; i++) { if (a[i - 1] + b[i - 1] > 0) { ans += a[i - 1] + b[i - 1]; } } cout << ans << endl; }
#include <bits/stdc++.h> #define ll long long #define sz(x) ((int) (x).size()) #define all(x) (x).begin(), (x).end() #define vi vector<int> #define pii pair<int, int> #define rep(i, a, b) for(int i = (a); i < (b); i++) using namespace std; template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<ll> a(n), b(n); ll cost = 0; rep(i, 0, n) { cin >> a[i]; cost += a[i]; } vector<ll> ve[2]; rep(i, 0, n) { cin >> b[i]; ve[i % 2].push_back(b[i] - a[i]); } sort(all(ve[0]), greater<>()); sort(all(ve[1]), greater<>()); int idx = 0; while(idx < n / 2 && ve[0][idx] + ve[1][idx] > 0) { cost += ve[0][idx] + ve[1][idx]; idx++; } cout << cost << '\n'; }
#include <iostream> #include <algorithm> #include <cmath> #include <vector> #include <string> #include <iomanip> #include <functional> #include <deque> #include <stack> #include <queue> #include <bitset> #include <map> #include <set> #include <unordered_set> using namespace std; typedef long long ll; #define rep(i,n) for (ll i = 0; i < (ll)(n); i++) #define REP(i,n) for (ll i = 1; i <= (ll)(n); i++) #define all(v) v.begin(), v.end() #define pb push_back #define fcout cout<<fixed<<setprecision(15) #define PI 3.1415926535897932384626433832795028841971693993751058209749445923078160628620899 const ll MOD = 1000000007; const ll MOD2 = 998244353; const ll INF = 1000000000000000000; const ll NIL = -1; const ll dx[4] = { 0,1,0,-1 }; const ll dy[4] = { 1,0,-1,0 }; double N, D, H, d[1010], h[1010]; int main() { cin >> N >> D >> H; rep(i, N) cin >> d[i] >> h[i]; double ans = 0; rep(i, N) { double k; k = (H - h[i]) * D / (D - d[i]); ans = max(ans, H - k); } fcout << ans << endl; return 0; }
#include <iostream> using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(0); int a,b,c,d; cin>>a>>b>>c>>d; cout<<a*d-c*b<<'\n'; }
#include <bits/stdc++.h> using namespace std; int main(){ int A,B; cin >> A >> B; cout << (A+B)/2 << " " << (A-B)/2 << endl; }
#include <bits/stdc++.h> #define int long long using namespace std; int32_t main(){ ios::sync_with_stdio(0); cin.tie(0); int n; cin>>n; string s; cin>>s; string t; while((int)t.size() < n+4) t+="110"; int ans=0; for(int i=0;i<3;i++){ if(s!=t.substr(i,n)) continue; ans+=(int)1e10-(n+i-1)/3; } cout<<ans; return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long int main() { ll i,j,n; n = 4; vector<ll> a(n); ll s = 0; for(i=0;i<n;i++) cin>>a[i], s+=a[i]; for(i=0;i<n;i++) { if(s-a[i] == a[i]) { cout<<"Yes"; return 0; } } for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { if(s-(a[i]+a[j]) == a[i]+a[j]) { cout<<"Yes"; return 0; } } } cout<<"No"; }
#include "bits/stdc++.h" using namespace std; #define dracarys ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); //#pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") //#pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC target("avx2") #define ll long long #define ld long double #define pb push_back #define fi first #define se second #define all(x) x.begin(),x.end() #define dbg(x) cout << "[ " << x << " ] " #define ump unordered_map mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count(); struct chash{ int operator()(int x) const { return x ^ RANDOM; } }; void solve(int tt){ int n = 4; vector<ll> v(n); for (auto& it : v) cin >> it; ll sum = accumulate(all(v),0); bool flag = 0; for (int i = 0;i < (1 << n);i++){ ll sub = 0; for (int j = 0;j < n;j++){ if (i & (1 << j)){ sub += v[j]; } } flag |= (sub * 2ll == sum); } if (sum % 2 == 0 and flag){ cout << "Yes\n"; } else cout << "No\n"; } int main(){ // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif dracarys int tt = 0,t = 1; //cin >> t; while(t--){solve(++tt);} cerr << "processor time: " << clock() / (double) CLOCKS_PER_SEC << "s "; return 0; }
#include<bits/stdc++.h> using namespace std; int main () { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int T = 1; //~ cin >> T; for (int t = 1; t <= T; ++t) { int n; cin >> n; int input[n + 1]; for (int i = 1; i <= n; ++i) { cin >> input[i]; } set<int> nums; nums.insert(0); for (int i = 1; i <= n; ++i) { nums.insert(i); } for (int i = 1; i <= n; ++i) { set<int>:: iterator it = nums.begin(); if (*it == input[i]) { nums.erase(it); it = nums.begin(); cout << *it << "\n"; } else { while (i <= n and *it != input[i]) { cout << *it << "\n"; nums.erase(input[i]); ++i; } if (i <= n) { nums.erase(it); it = nums.begin(); cout << *it << "\n"; } } } } }
#include "bits/stdc++.h" // #include <bits/stdc++.h> using namespace std; // #include <atcoder/all> // using namespace atcoder; using ll = long long; template <typename T> void print_vec(const vector<T>& v, bool is_reverse=false, ll num=0){ if(num == 0) num = (ll)v.size(); cout << endl; cout << "i= ";for(ll i=0; i<num; i++) cout << i << " ";cout << endl; cout << " "; if(is_reverse) for(ll i=num-1; i>=0; i--){ cout<<v[i]; if(i!=0) cout<<" ";} else for(ll i=0; i<num; i++){ cout<<v[i]; if(i!=num-1) cout<<" ";} cout << endl; } // template <typename T> // void print_pairvec(const vector<T> &v, ll num=0){ // if(num == 0) num = (ll)v.size(); // cout << endl; for(ll i=0; i<num; i++){ cout << v[i].first << " " << v[i].second << endl;} // } template <typename T> void print_pairvec(const T &_pair, ll num=0){ cout << endl; for(pair<ll, int> x: _pair){ cout << x.first << " " << x.second << endl;} } template <typename T> void print_vec2(const vector<vector<T>>& v){ cout << endl; cout << " "; for(ll i=0; i<v[0].size(); i++) cout << i << " "; cout << endl; for(ll i=0; i<v.size(); i++){ cout << "i=" << i << ": "; for(ll j=0; j<v[i].size(); j++){ if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << " "; else cout << "\x1B[31m" << v[i][j] << " ";//https://stackoverrun.com/ja/q/12618775 } cout << "\x1B[0m" << endl; } } int main(){ ll N; cin >> N ; vector<ll> p(N); vector<bool> is_p(N+1, false); for(int i=0; i<N; i++) cin >> p[i]; // for(int i=0; i<N; i++) is_p[p[i]] = true; ll ans = 0; for(int i=0; i<N; i++){ is_p[p[i]] = true; while(is_p[ans] == true) ans++; cout << ans << endl; } // cout << ans << endl; return 0; // cout << fixed;//小数点を確実に10桁で表示するためのもの // cout << setprecision(10); }
/*#pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") */ #include<bits/stdc++.h> using namespace std; #define ll long long #define f first #define s second #define Fast ios_base::sync_with_stdio(false);cin.tie(NULL); typedef pair<ll , pair<ll, ll> > pi; int pow(int x,int y){ int res=1; while(y){ if(y&1) res*=x; y>>=1; x*=x; } return res; } struct Compare { constexpr bool operator()(pi const & a, pi const & b) const noexcept { return a.first < b.first || (a.first == b.first && a.second.first > b.second.first); } }; void prefix_function( string s,ll arr[] ) { long long border=0; arr[0]=0; for(long long i=1;i<s.size();i++) { while(border>0 && s[i]!=s[border]) border=arr[border-1]; if(s[i]==s[border]) border++; else border=0; arr[i]=border; } }//send mod-2 for a^-1 if mod is a prime number ll mod=998244353; ll add( ll a , ll b) { return (((a%mod)+(b%mod))%mod); } ll mul(ll a,ll b) { return (((a%mod)*(b%mod))%mod); } ll binpow(ll a, ll b) { ll res = 1; while (b) { if (b & 1) res = mul(res, a); a = mul(a, a); b >>= 1; } return res; } ll subs(ll a,ll b) { return (((a%mod)-(b%mod)+mod)%mod); } ll dv(ll a,ll b) { ll inv=binpow(b,mod-2); return mul(a,inv); } ll dsu_arr[100000]; ll dsu_sz[100000]; void dsu(ll n) { for(ll i=0;i<=n;i++) { dsu_arr[i]=i; dsu_sz[i]=1; } } ll find(ll x) { ll root=x; while (root!=dsu_arr[root]) { root=dsu_arr[root]; } while(x!=dsu_arr[x]) { dsu_arr[x]=root; x=dsu_arr[x]; } return root; } ll merge(ll x,ll y) { ll root1=find(x); ll root2=find(y); if(root1==root2) return 0ll; if(dsu_sz[x]>dsu_sz[y]){ dsu_arr[root2]=root1; dsu_sz[root1]+=dsu_sz[root2]; } else { dsu_sz[root2]+=dsu_sz[root1]; dsu_arr[root1]=root2; } return 1ll; } /* vector<ll>adj[100005]; bool vis[100005]; ll dist[100005]; void bfs(ll c) { vis[c]=true; dist[c]=0; queue<ll>q; q.push(c); while(!q.empty()) { ll x=q.front(); q.pop(); for(ll i=0;i<adj[x].size();i++) { ll y=adj[x][i]; if(!vis[y]) { vis[y]=true; dist[y]=dist[x]+1; q.push(y); } } } } */ int main() { Fast ll n; string s; cin>>s; n=s.size(); vector<ll>sura; ll mx=-1; for(ll mask=0;mask<(1<<n);mask++) { ll sum=0; ll h=0; for(ll i=0;i<n;i++ ) { if(mask& (1<<i)) { h++; sum+=(s[i]-'0'); } } if(sum%3==0 && sum>0) { mx=max(mx,h); } } if(mx==-1) { cout<<mx<<endl; } else { cout<<n-mx<<endl; } }
#include <algorithm> #include <vector> #include <cstdio> #include <cmath> #define int long long const int N = 100005, INF = 0x3f3f3f3f3f3f3f3fll; int n, x, ans = INF, cnt, tot; std::vector<int> R, G, B, a[3], b[2]; char c[5]; int find(std::vector<int> a, std::vector<int> b) { int an = INF; if(a.size() == 0 || b.size() == 0) return an; for(int i = 0; i < (signed)a.size(); i++) { int pos = std::lower_bound(b.begin(), b.end(), a[i]) - b.begin(); int x = INF; if(pos == 0) x = std::abs(b[0] - a[i]); else if(pos == b.end() - b.begin()) x = std::abs(b[pos-1]-a[i]); else x = std::min(std::abs(b[pos]-a[i]), std::abs(b[pos-1]-a[i])); an = std::min(an, x); } return an; } signed main() { scanf("%lld", &n); n = 2 * n; for(int i = 1; i <= n; i++) { scanf("%lld%s", &x, c); if(c[0] == 'R') R.push_back(x); if(c[0] == 'G') G.push_back(x); if(c[0] == 'B') B.push_back(x); } // printf("%d %d %d", R.size(), G.size(), B.size()); if(R.size() % 2 == 0 && G.size() % 2 == 0 && B.size() % 2 == 0) return puts("0"), 0; if(R.size() % 2 == 1) a[++cnt] = R; else b[++tot] = R; if(G.size() % 2 == 1) a[++cnt] = G; else b[++tot] = G; if(B.size() % 2 == 1) a[++cnt] = B; else b[++tot] = B; std::sort(a[1].begin(), a[1].end()); std::sort(a[2].begin(), a[2].end()); std::sort(b[1].begin(), b[1].end()); ans = find(a[1], a[2]); ans = std::min(find(a[1], b[1]) + find(a[2], b[1]), ans); printf("%lld", ans); return 0; }
#include <bits/stdc++.h> #if __has_include(<atcoder/all>) #include <atcoder/all> using namespace atcoder; #endif using namespace std; using ll = long long; struct Edge { ll to; ll cost; }; using Graph = vector<vector<Edge>>; using P = pair<ll, ll>; #define mp make_pair #define REP(i, n) for (int i = 0; i < (n); ++i) #define SORT(v) sort((v).begin(), (v).end()) #define RSORT(v) sort((v).rbegin(), (v).rend()) #define ALL(v) (v).begin(), v.end() const ll MOD = 1000000007; const ll nmax = 8; const ll INF = LLONG_MAX; const int MAX = 510000; bool graph[nmax][nmax]; long long fac[MAX], finv[MAX], inv[MAX]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } ll COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF)); void warshall_floyd(ll n) { for (size_t i = 0; i < n; i++) { for (size_t j = 0; j < n; j++) { for (size_t k = 0; k < n; k++) { dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]); } } } } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; } ll mulMod(ll a, ll b) { return (((a % MOD) * (b % MOD)) % MOD); } ll powMod(ll a, ll p) { if (p == 0) { return 1; } else if (p % 2 == 0) { ll half = powMod(a, p / 2); return mulMod(half, half); } else { return mulMod(powMod(a, p - 1), a); } } ll ceil(ll a, ll b) { return (a + b - 1) / b; } void solve(long long N, long long C, std::vector<long long> a, std::vector<long long> b, std::vector<long long> c) { map<ll, ll> zip; map<ll, ll> unzip; vector<ll> all; for (int i = 0; i < N; i++) { all.push_back(a[i]); all.push_back(b[i]); } SORT(all); all.erase(unique(ALL(all)), all.end()); for (int i = 0; i < all.size(); i++) { zip[all[i]] = i; unzip[i] = all[i]; } vector<ll> sum(all.size() + 1, 0); for (int i = 0; i < N; i++) { sum[zip[a[i]]] += c[i]; sum[zip[b[i]]] -= c[i]; } for (int i = 0; i < sum.size(); i++) { sum[i + 1] += sum[i]; } // for (int i = 0; i < sum.size(); i++) // { // cout << sum[i] << " "; // } // cout << endl; ll ans = 0; for (int i = 0; i < sum.size() - 2; i++) { // cout << unzip[i] << " " << unzip[i + 1] << " " << sum[i] << endl; if (sum[i] > C) { ans += (unzip[i + 1] - unzip[i]) * C; } else { ans += (unzip[i + 1] - unzip[i]) * sum[i]; } // cout << sum[i] << " "; } // if (sum[sum.size() - 2] > C) // { // ans += C; // } // else // { // ans += sum[sum.size() - 2]; // } // cout << endl; cout << ans << endl; } int main() { long long N; scanf("%lld", &N); long long C; scanf("%lld", &C); std::vector<long long> a(N); std::vector<long long> b(N); std::vector<long long> c(N); for (int i = 0; i < N; i++) { scanf("%lld", &a[i]); scanf("%lld", &b[i]); scanf("%lld", &c[i]); ++b[i]; } solve(N, C, std::move(a), std::move(b), std::move(c)); return 0; }
#include <iostream> #include <vector> #include <algorithm> #include <map> #include <numeric> #include <string> #include <cstdio> #include <cstring> #include <queue> #include <stack> #include <set> #include <cmath> #include <bitset> #include <iomanip> using namespace std; using ll = long long; using ull = unsigned long long; #define all(x) (x).begin(),(x).end() #define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i)) #define pb push_back #define mp make_pair #define fi first #define se second #define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) #define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl constexpr int INF = 1e9+7; constexpr ll INFL = 9*1e18; constexpr int dx[4] = { 1, 0, -1, 0 }; constexpr int dy[4] = { 0, 1, 0, -1 }; // constexpr int dx[8] = {1, 1, 0,-1,-1,-1, 0, 1}; // constexpr int dy[8] = {0, 1, 1, 1, 0,-1,-1,-1}; int inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数 ull inline power(ull a,ull b){ull res = 1;rep(i,b)res *= a;return res;} template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和 template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数 template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数 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; } template<typename T>inline void print(T&& x){cout<<setprecision(32)<<x<<endl;} string to_oct(int n){string s;while(n){s = to_string(n%8) + s;n /= 8;}return s;} int main(){ #define int ll int n,c;cin>>n>>c; vector<pair<int,int>> a; rep(i,n){ int _a,_b,_c;cin>>_a>>_b>>_c; a.push_back(make_pair(_a,_c)); a.push_back(make_pair(_b+1,-_c)); } sort(all(a)); int crt_day = 0; ll ans = 0; ll sum = 0; for(int i = 0;i < a.size();i++){ int days = a[i].fi - crt_day; if(i != 0 && a[i-1].fi != a[i].fi || i == a.size()-1){ ans += min(sum, c) * days; } sum += a[i].se; crt_day = a[i].fi; } print(ans); return 0; }
#include <iostream> #include <string> #include <vector> using namespace std; int main() { int H,W,count; char a; count = 0; cin >> H >> W; vector<vector<char>> S(H, vector<char>(W)); for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { cin >> S[i][j]; } } for (int i = 0; i <= H-2; i++) { for (int j = 0; j <= W-2; j++) { a = S[i][j]; if (a == '.') { if (a == S[i][j + 1]) { count += 1; } if (a == S[i + 1][j]) { count += 1; } } } } for (int i = 0; i <= H - 2; i++) { a = S[i][W-1]; if (a == '.') { if (a == S[i + 1][W - 1]) { count += 1; } } } for (int i = 0; i <= W - 2; i++) { a = S[H-1][i]; if (a == '.') { if (a == S[H - 1][i + 1]) { count += 1; } } } cout << count; return 0; }
#include<iostream> #include<string> #include<algorithm> #include<cmath> #include<ctime> #include<map> #include<vector> #include<math.h> #include<stdio.h> #include<stack> #include<queue> #include<tuple> #include<cassert> #include<set> #include<bitset> #include<functional> #include <fstream> //#include<bits/stdc++.h> #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #define rep(i, x) for(ll i = 0; i < x; i++) #define rep2(i, x) for(ll i = 1; i <= x; i++) #define all(a) (a).begin(),(a).end() #define puts(x) cout << (x) << endl; using ll = long long; using ld = long double; using namespace std; const ll INF = 10000000000000000; const int intINF = 1000000000; const ll mod = 1000000007; const ll MOD = 998244353; const ld pi = 3.141592653589793238; bool isprime(int p) { if (p == 1) return false; for (int i = 2; i < p; i++) { if (p % i == 0) return false; } return true; } ll gcd(ll a, ll b) { if (a < b)swap(a, b); if (a % b == 0)return b; return gcd(b, a % b); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll keta(ll n) { ll res = 0; while (n >= 1) { res += n % 10; n /= 10; } return res; } ll modpow(ll x, ll y) { ll res = 1; while (y) { if (y % 2) { res *= x; res %= mod; } x = x * x % mod; y /= 2; } return res; } ll nCk(ll n, ll k) { ll a = 1, b = 1; for (int h = n - k + 1; h <= n; h++) { a *= h; a %= mod; } for (int h = 1; h <= k; h++) { b *= h; b %= mod; } return a * modpow(b, mod - 2) % mod; } //printf("%.10f\n", n); typedef pair <ll, ll> P; ll dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 }; struct edge { ll to, cost; }; struct status { ll cost; ll bango; bool operator<(const status& rhs) const { return cost < rhs.cost; }; bool operator>(const status& rhs) const { return cost > rhs.cost; }; }; signed main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); //cout << fixed << setprecision(15); //input ll n, m; cin >> n >> m; vector<P> a(n); vector<ll> mi(n + 1); rep(i, n) { cin >> a[i].first; a[i].second = i + 1; mi[i + 1] = a[i].first; } sort(all(a)); reverse(all(a)); vector<ll> x(m), y(m); vector<vector<ll>> G(n + 2); rep(i, m) { cin >> x[i] >> y[i]; G[y[i]].push_back(x[i]); } vector<ll> ma(n + 2, 0 - INF); vector<bool> visit(n + 2); rep(i, a.size()) { queue<ll> que; ll cnt = a[i].first; if (!visit[a[i].second]) { que.push(a[i].second); } while (que.size()) { ll q = que.front(); que.pop(); for (int i = 0; i < G[q].size(); i++) { if (!visit[G[q][i]]) { que.push(G[q][i]); visit[G[q][i]] = true; ma[G[q][i]] = cnt; } } } } ll ans = 0 - INF; rep2(i, n) { ans = max(ans, ma[i] - mi[i]); } cout << ans << endl; return 0; }
#include <iostream> #include <stack> #include <string> #include <vector> #pragma warning(disable:4996) using namespace std; #define int long long stack<int>way; int N,M,K; double ex[200100]; double ep[200100]; double epex[200100]; vector<pair<int, int>>x; signed main() { ios_base::sync_with_stdio(false); cin >> N>>M >> K; int i; for (i = 0; i < K; i++) { int a; cin >> a; ep[a] = 1; } for (i = N; i <= N + M; i++) { ex[i] = 0; } double curex = 0, curep = 0,expex=0; for (i = N - 1; i >= 0; i--) { int isb = ep[i] >= 0.99999999; if (isb) goto T; ep[i] = curep; if (ep[i] <=0.999999999) { ex[i] = ((curex))/(M-curep*M)+1; if(curep>0) epex[i] = expex / (curep*M)+1; } else { if (!isb) { if (curep > 0) epex[i] = expex / (curep*M) + 1; } } T: curex -= ex[i + M]*(1-ep[i+M]); curep -= ep[i + M]/M; expex -= epex[i + M]*ep[i+M]; curex += ex[i]*(1-ep[i]); curep += ep[i]/M; expex += epex[i]*ep[i]; } i = 0; if (ep[i] >= 0.99999999) cout << -1; else { cout << ((1 - ep[i]) * ex[i] +epex[i]*ep[i]) / (1 - ep[i]); } }
#include <bits/stdc++.h> using namespace std; //#include <atcoder/all> //using namespace atcoder; #define rep(i,n) for (int i = 0; i < (n); ++i) #define rep1(i,n) for (int i = 1; i <= (n); ++i) #define bit(n,k) ((n>>k)&1) //nのk bit目 #define vec(T) vector<T> #define vvec(T) vector<vector<T>> using ll = long long; using P = pair<int,int>; 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; } const ll llINF = 1LL << 60; const int iINF = 1e9; //------------------------------------------------ using Pd = pair<double,double>; struct Solver{ Pd add(Pd a,Pd b){ a.first += b.first; a.second += b.second; return a; } Pd sub(Pd a,Pd b){ a.first -= b.first; a.second -= b.second; return a; } Pd div(Pd a,int m){ a.first /= m; a.second /= m; return a; } void solve(){ int N,M,K; cin >> N >> M >> K; vec(Pd) dp(N+M+10); vec(int) st(N); int cnt=0; int pre,now; pre=-1; rep(ki,K){ cin >> now; if(now==pre+1) cnt++; else cnt=0; if(cnt==M-1){ cout << -1 << endl; return; } st[now] = 1; pre = now; } Pd csum = {0,0}; for(int i = N-1; i>=0; i--){ csum = add(csum,dp[i+1]); csum = sub(csum,dp[i+M+1]); if(st[i]){ dp[i].first = 1.0; }else{ dp[i] = div(csum,M); dp[i].second += 1.0; } } double ans; ans = dp[0].second/(1.0-dp[0].first); printf("%6.4f\r\n",ans); } }; int main(){ int testcasenum=1; //cin >> testcasenum; rep1(ti,testcasenum){ Solver solver; solver.solve(); } return 0; }
//#pragma GCC optimize ("O2") //#pragma GCC target ("avx2") //#include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; #include<cstdio> #include<cstring> #include<algorithm> using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please //おそそう const int CM = 1 << 17, CL = 12; char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct; const ll ma0 = 1157442765409226768; const ll ma1 = 1085102592571150095; const ll ma2 = 71777214294589695; const ll ma3 = 281470681808895; const ll ma4 = 4294967295; inline int getint() { if (ci - owa > 0) { memcpy(cn, owa, CL); ci -= CM; fread(cn + CL, 1, CM, stdin); } ll tmp = *(ll*)ci; if ((tmp & ma0) ^ ma0) { int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0); tmp = tmp << dig & ma1; tmp = tmp * 10 + (tmp >> 8) & ma2; tmp = tmp * 100 + (tmp >> 16) & ma3; tmp = tmp * 10000 + (tmp >> 32) & ma4; ci += (72 - dig >> 3); } else { tmp = tmp & ma1; tmp = tmp * 10 + (tmp >> 8) & ma2; tmp = tmp * 100 + (tmp >> 16) & ma3; tmp = tmp * 10000 + (tmp >> 32) & ma4; ci += 8; if (*ci++ == '0') { tmp = tmp * 10; ci++; } } return tmp; } void pakuri_sort(int N, ll A[]) { const int b = 8; ll tmp[100001]; rep(k, 4) { int kazu[1 << b] = {}, kazu2[1 << b] = {}; rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++; rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i]; for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i]; k++; rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++; rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i]; for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i]; } } ll li[300]; int li2[300]; int main() { //cin.tie(0); //ios::sync_with_stdio(false); int N = getint(), M = getint(); int w[8]; rep(i, N) w[i] = getint(); ll lv[100001]; rep(i, M) { ll l = getint(); int v = getint(); lv[i] = l << 32 | v; } pakuri_sort(M, lv); lv[M] = 1000000001ll; rep(i, 1 << N) { rep(j, N) if (i >> j & 1) li[i] += w[j]; li[i] = li[i] << 30 | i; } sort(li, li + (1 << N)); int saidai = 0; int k = 0; rep(i, 1 << N) { while ((lv[k] & (1 << 30) - 1) < li[i] >> 30) { if (saidai < lv[k] >> 32) saidai = lv[k] >> 32; k++; } li[i] = ll(saidai) << 30 | (li[i] & (1 << 30) - 1); } rep(i, 1 << N) li2[li[i] & (1 << 30) - 1] = li[i] >> 30; rep(i, N) { if (w[i] > (lv[0] & (1 << 30) - 1)) { printf("-1"); return 0; } } int P[8]; rep(i, N) P[i] = i; int kotae = 1e9; do { int tmp[8] = {}; rep(p, N - 1) { int omosa = 1 << P[p]; for (int q = p + 1; q < N; q++) { omosa |= 1 << P[q]; int kari = tmp[p] + li2[omosa]; if (tmp[q] < kari) tmp[q] = kari; } } if (kotae > tmp[N - 1]) kotae = tmp[N - 1]; } while (next_permutation(P, P + N)); printf("%d\n", kotae); Would you please return 0; }
#include<bits/stdc++.h> #define int long long #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,avx,avx2") #pragma GCC optimize("unroll-loops") #define ri register signed #define rd(x) x=read() using namespace std; const int N=2e5+5; const int maxn=5e6+5; const int mod=998244353; inline int read(){int x=0,f=1;char ch=getchar();while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;} inline int ksm(int x,int y,int z){int ret=1;while (y){if (y&1) ret=(ret*x)%z;x=(x*x)%z;y>>=1;}return ret;} int inv[maxn],fac[maxn],ifc[maxn]; void Init(int n) { inv[1]=1;for (ri i=2;i<=n;i++)inv[i]=inv[mod%i]*(mod-mod/i)%mod; fac[0]=1;for (ri i=1;i<=n;i++) fac[i]=fac[i-1]*i%mod; ifc[0]=1;for (ri i=1;i<=n;i++) ifc[i]=ifc[i-1]*inv[i]%mod; } int C(int n,int m){if (m>n || m<0) return 0;return fac[n]*ifc[m]%mod*ifc[n-m]%mod;} int n,k,ans,res; vector<int> T[N]; int dep[N]; void dfs(int u,int fa,int lim) { for (int v:T[u]) if (v!=fa) dfs(v,u,lim); if (u!=1) { if (T[u].size()==1) dep[u]=0; else { dep[u]=-n; int mn=n,mx=-n; for (int v:T[u]) if (v!=fa) mx=max(mx,dep[v]+1),mn=min(mn,dep[v]+1); if (mx+mn<0) dep[u]=mn; else dep[u]=mx; if (dep[u]==lim) {res++;dep[u]=-lim-1;} } } else { int mn=n,mx=-n; for (int v:T[u]) mx=max(mx,dep[v]+1),mn=min(mn,dep[v]+1); if (mx+mn<0) dep[u]=mn; else dep[u]=mx; if (dep[u]>=0) res++; } } bool chk(int x) { res=0; for (int i=1;i<=n;i++) dep[i]=0; dfs(1,0,x); return res<=k; } signed main() { rd(n);rd(k); if (k==n) {puts("0");return 0;} for (int i=1,x,y;i<n;i++) rd(x),rd(y),T[x].push_back(y),T[y].push_back(x); int l=1,r=n; while (l<=r) { int mid=(l+r)/2; if (chk(mid)) ans=mid,r=mid-1; else l=mid+1; } cout<<ans<<endl; }
#pragma GCC optimize("Ofast") #include <iostream> #include <stdio.h> #include <string> #include <vector> #include <algorithm> #include <cstdlib> #include <cmath> #include <iomanip> #include <cctype> #include <sstream> #include <stack> #include <deque> #include <queue> #include <list> #include <set> #include <map> #include <unordered_map> using namespace std; using ll = long long; using P = pair<ll, ll>; using Po = pair<double, double>; template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; #define REP(i,n) for(ll i=0;i<ll(n);i++) #define REPD(i,n) for(ll i=n-1;i>=0;i--) #define FOR(i,a,b) for(ll i=ll(a);i<=ll(b);i++) #define FORD(i,a,b) for(ll i=ll(a);i>=ll(b);i--) #define PB push_back #define MP make_pair #define SZ(x) ll(x.size()) #define ALL(x) x.begin(),x.end() #define NIL -1 #define INF pow(2,31)-1 #define MOD 1000000007 #define PI 3.14159265358979323846 #define endl "\n" #define EPS 1e-9 template <class T, class U> bool chmin(T& t, const U& u) { if (t > u) { t = u; return true; } else return false; } template <class T, class U> bool chmax(T& t, const U& u) { if (t < u) { t = u; return true; } else return false; } ll powmod(ll x, ll n, ll mod) { ll s = 1; REP(i, n) { s = s * x % mod; } if (s < 0)s += mod; return s; } signed main() { ll n; cin >> n; V<ll> a(n), b(n); REP(i, n)cin >> a[i]; REP(i, n)cin >> b[i]; ll c = 0; REP(i, n) { c += a[i] * b[i]; } c ? cout << "No" << endl : cout << "Yes" << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >>n; vector <long long> a(n), b(n); for (int i = 0; i < n; ++i) { cin >>a[i]; } for (int i = 0; i < n; ++i) { cin >>b[i]; } long long res = 0; for (int i = 0; i < n; ++i) { long long cur = a[i] * b[i]; res += cur; } if (res == 0) { cout <<"Yes"<<endl; } else { cout <<"No"<<endl; } }
#include<iostream> #include<string> #include<iomanip> #include<cmath> #include<vector> #include<algorithm> #include<utility> using namespace std; #define int long long #define endl "\n" constexpr long long INF = (long long)1e18; constexpr long long MOD = 1'000'000'007; struct fast_io { fast_io(){ std::cin.tie(nullptr); std::ios::sync_with_stdio(false); }; } fio; signed main(){ cout<<fixed<<setprecision(10); int A, B; vector<int> num; vector<vector<int>> dp; vector<int> p; int ans = 0; int n; cin>>A>>B; for(int i = 2; i <= B - A; i++){ bool flag = false; for(int j = 2; j * j <= i; j++){ if(i%j == 0) { flag = true; break; } } if(!flag) p.push_back(i); } n = p.size(); num.resize(B - A + 1); dp.resize(B - A + 2, vector<int>(1<<n)); for(int i = A; i <= B; i++){ int bit = 0; for(int j = 0; j < n; j++){ if(i%p[j] == 0) { bit |= (1<<j); } } num[i-A] = bit; } dp[0][0] = 1; for(int i = A; i <= B; i++){ for(int j = 0; j < 1<<n; j++){ if(!(num[i-A]&j)) dp[i-A+1][num[i-A]|j] += dp[i-A][j]; dp[i-A+1][j] += dp[i-A][j]; } } for(int j = 0; j < 1<<n; j++){ ans += dp[B - A + 1][j]; } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> #define ff first #define ss second #define endl '\n' using namespace std; const long long INF = (long long) 1e18; const int mod = (int) 1e9+7; const int MAXN = (int) 3e5+5; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; typedef pair<ll,ll> pll; ll n, t; ll a[MAXN]; int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr);cout.tie(nullptr); #ifdef Local freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/int.txt","r",stdin); freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/out.txt","w",stdout); #endif cin>>n>>t; for(int i = 0; i < n; i++) cin>>a[i]; int m = n / 2; vector<int> vc; int ans = 0; for(int i = 0; i < (1<<m); i++){ ll top = 0; for(int j = 0; j < m; j++){ if((1<<j) & i) top += a[j]; } if(top > t) continue; vc.push_back(top); ans = max(ans,(int) top); } sort(vc.begin(), vc.end()); int len = (n - m); for(int i = 0; i < (1<<len); i++){ ll top = 0; for(int j = 0; j < len; j++){ if((1<<j) & i) top += a[m + j]; } if(top > t) continue; ans = max(ans,(int) top); int ot = upper_bound(vc.begin(), vc.end(), t - top) - vc.begin(); //cout<<top<<" "<<vc[ot - 1]<<endl; if(ot != 0) ans = max(ans, (int)top + vc[ot - 1]); } cout<<ans<<endl; #ifdef Local cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds "; #endif }
/*** author: yuji9511 ***/ #include <bits/stdc++.h> // #include <atcoder/all> // using namespace atcoder; using namespace std; using ll = long long; using lpair = pair<ll, ll>; using vll = vector<ll>; const ll MOD = 1e9+7; const ll INF = 1e18; #define rep(i,m,n) for(ll i=(m);i<(n);i++) #define rrep(i,m,n) for(ll i=(m);i>=(n);i--) ostream& operator<<(ostream& os, lpair& h){ os << "(" << h.first << ", " << h.second << ")"; return os;} #define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];}; void print() {} template <class H,class... T> void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);} void solve(){ ll N,C; cin >> N >> C; vll a(N),b(N),c(N); rep(i,0,N) cin >> a[i] >> b[i] >> c[i]; typedef struct { ll pos; ll val; ll t; } P; vector<P> v; rep(i,0,N){ v.push_back({a[i], c[i], 0}); v.push_back({b[i]+1, c[i], 1}); } sort(v.begin(), v.end(),[](P p1, P p2){ if(p1.pos == p2.pos){ return p1.t < p2.t; } return p1.pos < p2.pos; }); ll ans = 0; ll sum = 0; ll prev_pos = -1; for(auto &e: v){ if(prev_pos != -1){ if(sum <= C){ ans += sum * (e.pos - prev_pos); }else{ ans += C * (e.pos - prev_pos); } } if(e.t == 0){ sum += e.val; }else{ sum -= e.val; } prev_pos = e.pos; } print(ans); } int main(){ cin.tie(0); ios::sync_with_stdio(false); solve(); }
/* Hardwork allways pays off */ //You never know how close to the solution you are ,so keep practicing #include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/tree_policy.hpp> #include <functional> // for less #include <iostream> using namespace __gnu_pbds; using namespace std; #define int long long #define ld long double #define pb push_back #define lb lower_bound #define ub upper_bound #define pii pair<int,int> #define endl '\n' #define REP(i,n) for(int i=1;i<=n;i++) #define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower) #define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper) #define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define all(x) (x).begin(), (x).end() #define mod1 998244353 #define mod 1000000007 #define pie 3.141592653589793238 #define printv(x) for(i=0;i<x.size();i++) cout<<x[i]<<" "; #define printA(x,n) for(i=0;i<n;i++) cout<<x[i]<<" "; #define F first #define S second #define vi vector<int> typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; void make_unique(vector<int> vec) { sort(all(vec)); vec.resize(unique(all(vec)) - vec.begin()); } bool isPowerOfTwo(int n) { if(n==0) return false; return (ceil(log2(n)) == floor(log2(n))); } int cceil(int x, int y){ return (x+y-1)/y; } struct Cmp { bool operater(const pair<int,int> &a,const pair<int,int> &b) { return (a.second)<(b.second); } }; bool cmp(const pair<int,int> &a,const pair<int,int> &b) { return (a.second)<(b.second); } signed main() { ios; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif // cout.precision(1); // cout<<fixed; int t=1; // init(); // cin>>t; while(t--) { int n,x,i,j,flag=0,count=0,sum=0; int v,ti,s,d; cin>>v>>ti>>s>>d; if(ti*v<=d&&s*v>=d) cout<<"No"<<endl; else cout<<"Yes"<<endl; } return 0; }
#include<bits/stdc++.h> #define rep(i,n)for(int i=0;i<(int)(n);i++) using namespace std; using P=pair<int,int>; int main(){ double x,y,z; cin>>x>>y>>z; cout<<floor((y*z-1)/x)<<endl; }
#include <bits/stdc++.h> using namespace std; int main(){ double X, Y, Z, v, a, b; cin >> X >> Y >> Z; v = Y / X; a = Z * v; long long int d = a; if(d == a){ cout << d-1 << endl; }else{ cout << d << endl; } return 0; }
// #define _GLIBCXX_DEBUG // for STL debug (optional) #include <iostream> #include <iomanip> #include <cstdio> #include <string> #include <cstring> #include <deque> #include <list> #include <queue> #include <stack> #include <vector> #include <utility> #include <algorithm> #include <map> #include <set> #include <complex> #include <cmath> #include <limits> #include <cfloat> #include <climits> #include <ctime> #include <cassert> #include <numeric> #include <fstream> #include <functional> #include <bitset> using namespace std; using ll = long long int; using int64 = long long int; template<typename T> void chmax(T &a, T b) {a = max(a, b);} template<typename T> void chmin(T &a, T b) {a = min(a, b);} template<typename T> void chadd(T &a, T b) {a = a + b;} int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; const int INF = 1LL << 29; const ll LONGINF = 1LL << 60; const ll MOD = 1000000007LL; int main() { int N; cin >> N; string s; cin >> s; if(s.front() != s.back()) { cout << 1 << endl; return 0; } else { char c = s.front(); for(int i=0; i+1<N; i++) { if(s[i] != c and s[i+1] != c) { cout << 2 << endl; return 0; } } cout << -1 << endl; return 0; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; template<typename T> void view_1d(vector<T> V, string sep) { for (ll i=0; i<V.size(); i++) { cout << V[i]; if (i == V.size() - 1) { cout << endl; } else { cout << sep; } } } template<typename T> void view_2d(vector<vector<T>> V, string sep) { for (ll i=0; i<V.size(); i++) { for (ll j=0; j<V[i].size(); j++) { cout << V[i][j]; if (j == V[i].size() - 1) { cout << endl; } else { cout << sep; } } } } //==============================// int main() { int N; string S, T; cin >> N >> S >> T; int tmp = 0; for (int i=0; i<N; i++) { tmp += (S[i] - '0') - (T[i] - '0'); } int ans = 0; if (tmp == 0) { vector<int> cnt_S, cnt_T; for (int i=0; i<N; i++) { if (S[i] == '0') cnt_S.push_back(i); if (T[i] == '0') cnt_T.push_back(i); } for (int j=0; j<cnt_S.size(); j++) { if (cnt_S[j] != cnt_T[j]) ans++; } } else { ans = -1; } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; #define ll long long int #define f(i,a,n) for(ll i=a;i<n;i++) #define w(x) ll _t;cin>>_t;f(x,1,_t+1) #define br cout<<"\n" ll mod=1e9+7; template<class T> void printArr(T arr,int n){ cout<<"\n[";f(i,0,n) cout<<arr[i]<<", "; cout<<"]\n"; } ll gcd(ll a,ll b){ if(b == 0) return a; return gcd(b,a%b); } ll lcm(ll a,ll b){ return (a*b)/gcd(a,b); } ll poww(ll a,ll m){ ll res=1; a = a%mod; for(;m;m>>=1){ if(m&1){ res=(res*a)%mod; } a=(a*a)%mod; } return res; } bool cmp(pair<int,int> &a,pair<int,int> &b){ return a.second>=b.second; } /*int lpf[1000001]; void createLPF(){ f(i,0,1000001) lpf[i]=INT_MAX; lpf[1]=1; for(int i=2;i*i<=1000000;i++){ if(lpf[i]==INT_MAX){ lpf[i] = i; for(int j=2*i;j<=1000000;j+=i) lpf[j] = min(lpf[j],i); } } }*/ int main(){ ios::sync_with_stdio(false);cin.tie(0); //w(_x)//testcases { ll n;cin>>n; ll a[1<<n]; f(i,0,1<<n) cin>>a[i]; vector<int> notlost; f(i,0,1<<n) notlost.push_back(i); ll ans = -1; for(int i=0;i<n;i++){ vector<int> newin; for(int j=0;j<notlost.size()-1;j+=2){ int p1=notlost[j],p2=notlost[j+1]; if(a[p1]>a[p2]) {newin.push_back(p1);ans = p2;} else {newin.push_back(p2);ans = p1;} } notlost = newin; } cout<<ans+1; } return 0; }
// This code wrote by chtholly_micromaker(MicroMaker) #include <bits/stdc++.h> #define reg register #define int long long #define ALL(x) (x).begin(),(x).end() #define mem(x,y) memset(x,y,sizeof x) #define sz(x) (int)(x).size() #define ln std::puts("") #define lsp std::putchar(32) #define pb push_back #define MP std::make_pair #define dbg(x) std::cerr<<__func__<<"\tLine:"<<__LINE__<<' '<<#x<<": "<<x<<"\n" #define dprintf(x...) std::fprintf(stderr,x) #define rep(i,a,b) for(int i=(a);i<=(b);++i) #define per(i,b,a) for(int i=(b);i>=(a);--i) template <class t> inline void read(t &s){s=0; reg int f=1;reg char c=getchar();while(!isdigit(c)){if(c=='-')f=-1;c=getchar();} while(isdigit(c))s=(s<<3)+(s<<1)+(c^48),c=getchar();s*=f;return;} template<class t,class ...A> inline void read(t &x,A &...a){read(x);read(a...);} template <class t> inline void write(t x){if(x<0)putchar('-'),x=-x; int buf[21],top=0;while(x)buf[++top]=x%10,x/=10;if(!top)buf[++top]=0; while(top)putchar(buf[top--]^'0');return;} inline void setIn(std::string s){freopen(s.c_str(),"r",stdin);return;} inline void setOut(std::string s){freopen(s.c_str(),"w",stdout);return;} inline void setIO(std::string s=""){setIn(s+".in");setOut(s+".out");return;} template <class t>inline bool checkmin(t&x,t y){if(x>y){x=y;return 1;}return 0;} template <class t>inline bool checkmax(t&x,t y){if(x<y){x=y;return 1;}return 0;} inline int lowbit(int x){return x&(-x);} int a[1<<16|5],loser; inline int dfs(int l,int r) { if(l==r) return read(a[l]),a[l]; reg int mid=(l+r)>>1,L=dfs(l,mid),R=dfs(mid+1,r); loser=std::min(L,R); return std::max(L,R); } signed main(void) { int n;read(n); dfs(1,1<<n); for(int i=1;i<=(1<<n);++i) if(loser==a[i]) write(i),ln; return 0; } /* * Check List: * 1. Input / Output File (OI) * 2. long long * 3. Special Test such as n=1 * 4. Array Size * 5. Memory Limit (OI) int is 4 and longlong is 8 * 6. Mod (a*b%p*c%p not a*b*c%p , (a-b+p)%p not a-b ) * 7. Name ( int k; for(int k...)) * 8. more tests , (T=2 .. more) * 9. blank \n after a case */
#include <iostream> #include <string> #include <vector> #include <queue> #include <stack> #include <set> #include <cctype> #include <cmath> #include<deque> #include<map> #include<algorithm> #include<iomanip> #include<numeric> using namespace std; #define rep(i,n) for(int i = 0; i < n; i++) #define rep1(i,begin,end) for(int i = begin; i < end; i++) #define all(c) c.begin(), c.end() #define ll long long #define INF 2e9 #define LINF 9223372036854775807 #define cout(n) cout << fixed << setprecision(n) #define pii pair<int,int> #define pll pair<long long,long long> #define mod 1000000007; template<typename T>pair<T, T> max_idx(vector<T>& a) { T ans = 0; T index = 0; for (int i = 0; i < a.size(); i++) { if (a[i] > ans) { ans = a[i]; index = i; } }pair<T, T> ret = { ans,index }; return ret; } template<typename T>pair<T, T> min_idx(vector<T>& a) { T ans = INF; T index = 0; for (int i = 0; i < a.size(); i++) { if (a[i] < ans) { ans = a[i]; index = i; } }pair<T, T> ret = { ans, index }; return ret; } long long Factorial(int n) { ll sum = 1; for (int i = n; i > 0; i--) { sum *= i; }return sum; } int main() { int a, b, c; cin >> a >> b >> c; vector<int> d(3); d[0] = a; d[1] = b; d[2] = c; sort(all(d)); reverse(all(d)); cout << d[0] + d[1] << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define deb(x) cout << #x << " " << x << endl; #define mod 1000000007 #define fast std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); #define endl "\n" const ll INF = 1e18; const ll NEGINF = -1 * INF; /*NOTES: Take care of ll vs int Never use an iterator after erasing it */ void solve() { vector<int> a(3); for (int i = 0; i < 3; i++) { cin >> a[i]; } sort(a.begin(), a.end()); cout << a[1] + a[2] << endl; } int main() { fast; #ifndef ONLINE_JUDGE freopen("/home/kalit/Desktop/Data Structures-Algo-Competitive/src/codeforces/input.txt", "r", stdin); freopen("/home/kalit/Desktop/Data Structures-Algo-Competitive/src/codeforces/output.txt", "w", stdout); #endif int T = 1; while (T--) { solve(); } //cout<< "Done in " << clock() / CLOCKS_PER_SEC <<"sec"<< endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(){ ll N;cin>>N; vector<ll> A(N); for(ll i=0;i<N;i++){ cin>>A[i]; } ll ans=0; sort(A.rbegin(), A.rend()); for(ll i=0; i<N; i++){ ans += A[i]*(N-1-i) - A[i]*i; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main(){ int N; cin >> N; vector<int> A(N),B(N),C(N); for (int i = 1; i <= N; ++i) cin >> A[i]; for (int i = 1; i <= N; ++i) cin >> B[i]; for (int i = 1; i <= N; ++i) cin >> C[i]; vector<int> count(N); for(int j = 1; j <= N; ++j) count[B[C[j]]] += 1; long long num = 0; for(int i = 1; i <= N; ++i) num += count[A[i]]; cout << num << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N; long long int X; cin >> N >> X; vector<int> A(N); for (int i = 0; i < N; i++) cin >> A.at(i); long long int ans = 2000000000000000000; for (int C = 1; C <= N; C++) { int MOD = X % C; vector<vector<vector<long long int>>> DP(N + 1, vector<vector<long long int>>(C + 1, vector<long long int>(C, -1))); DP.at(0).at(0).at(0) = 0; for (int i = 1; i <= N; i++) { for (int j = 0; j <= C; j++) { for (int k = 0; k < C; k++) { if (DP.at(i - 1).at(j).at(k) != -1) DP.at(i).at(j).at(k) = DP.at(i - 1).at(j).at(k); int kk = k - (A.at(i - 1) % C); if (kk < 0) kk += C; if (j > 0 && DP.at(i - 1).at(j - 1).at(kk) != -1) DP.at(i).at(j).at(k) = max(DP.at(i).at(j).at(k), DP.at(i - 1).at(j - 1).at(kk) + A.at(i - 1)); } } } if (DP.at(N).at(C).at(MOD) > 0) ans = min(ans, (X - DP.at(N).at(C).at(MOD)) / C); } cout << ans << endl; }
//#define _DEBUG #include "bits/stdc++.h" //#include <atcoder/all> #define CHOOSE(a) CHOOSE2 a #define CHOOSE2(a0,a1,a2,a3,a4,a5,x,...) x #define debug_1(x1) cout<<#x1<<": "<<x1<<endl #define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl #define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl #define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl #define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl #define debug_6(x1,x2,x3,x4,x5,x6) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<", "#x6<<": "<<x6<<endl #ifdef _DEBUG #define debug(...) CHOOSE((__VA_ARGS__,debug_6,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__) #else #define debug(...) #endif #define rep(index,num) for(int index=0;index<(int)num;index++) #define rep1(index,num) for(int index=1;index<=(int)num;index++) #define brep(index,num) for(int index=(int)num-1;index>=0;index--) #define brep1(index,num) for(int index=(int)num;index>0;index--) #define scan(argument) cin>>argument #define prin(argument) cout<<argument<<endl #define kaigyo cout<<endl #define eps 1e-7 #define mp(a1,a2) make_pair(a1,a2) #define ALL(a) (a).begin(),(a).end() #define rALL(a) (a).rbegin(),(a).rend() #define puba(a) emplace_back(a) #define pubamp(a,b) emplace_back(mp(a,b)) typedef long long ll; typedef long double ld; using namespace std; //using namespace atcoder; typedef pair<ll,ll> pll; typedef pair<int,int> pint; typedef vector<int> vint; typedef vector<ll> vll; typedef vector<pint> vpint; typedef vector<pll> vpll; template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } ll INFl=(ll)1e+18+1; int INF=1e+9+1; int main(){ int N; ll X,A[101]; scan(N>>X); rep(i,N) scan(A[i]); ll ans=INFl; rep1(chkosu,N){ ll dp[101][101][100]={};//dp[i][j][mod]:i個目まで見てj個選んでいて魔力の総和%chkosuがmodであるような魔力の最大値 rep(i,N+1) rep(j,chkosu+1) rep(mod,chkosu) dp[i][j][mod]=-INFl; dp[0][0][0]=0; rep(i,N){ rep(j,chkosu+1){ rep(mod,chkosu){ if(j<chkosu) chmax(dp[i+1][j+1][(mod+A[i])%chkosu],dp[i][j][mod]+A[i]); chmax(dp[i+1][j][mod],dp[i][j][mod]); } } } ll canReachMaryokuMax=dp[N][chkosu][X%chkosu]; debug(chkosu,canReachMaryokuMax,X%chkosu,(X-canReachMaryokuMax)/chkosu); if(canReachMaryokuMax<=0) continue; assert(canReachMaryokuMax<=X); chmin(ans,(X-canReachMaryokuMax)/chkosu); } prin(ans); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 1e5 + 10; const int inf = 1e9; int a[maxn], b[maxn]; int main(){ ios_base::sync_with_stdio(false); int n, L; cin >> n >> L; for (int i = 1; i <= n; i++) cin >> a[i]; a[0] = 0, a[n+1] = L+1; for (int i = 1; i <= n; i++) cin >> b[i]; b[0] = 0, b[n+1] = L+1; int last = 1; ll answer = 0; set<pair<int,int>> S, T; for (int i = 0; i <= n+1; i++){ S.insert({a[i]-i,-i}); T.insert({a[i]-i,+i}); } for (int i = 1; i <= n+1; i++){ if (a[i] > b[i]){ if (b[i-1]+1 == b[i]){ answer ++; continue; } auto it = S.lower_bound({b[i]-i,-inf}); if ((*it).first != b[i]-i) return cout << "-1\n", 0; answer += i+(*it).second; } if (a[i] < b[i]){ if (b[i]+1 == b[i+1]){ answer ++; continue; } auto it = T.lower_bound({b[i]-i,-inf}); if ((*it).first != b[i]-i) return cout << "-1\n", 0; answer += (*it).second-i; } } cout << answer << '\n'; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--) #define rrep(i,n) RREP(i,(n)-1,0) #define all(v) v.begin(), v.end() #define endk '\n' const int inf = 1e9+7; const ll longinf = 1LL<<60; const ll mod = 1e9+7; const ll mod2 = 998244353; const ld eps = 1e-10; template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;} template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;} int main() { cin.tie(0); ios::sync_with_stdio(false); int a, b; cin >> a >> b; int ans = 0; for(int i=1; i<=b-a+1; i++) { int _a = (a+i-1)/i, _b = b/i; if(_b-_a+1 >= 2) { chmax(ans, i); } } cout << ans << endk; return 0; }
#include<bits/stdc++.h> #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") #define endl "\n" #define pb push_back #define ll long long #define d1(x) cerr << #x << "--> " << x << endl #define d2(x,y) cerr << #x << "--> " << x << " | " << #y << "--> " << y <<endl #define d3(x,y,z) cerr << #x << "--> " << x << " | " << #y << "--> " << y <<" | " << #z << "--> "<< z<< endl #define d4(x,y,z,w) cerr << #x << "--> " << x << " | " << #y << "--> " << y <<" | " << #z << "--> "<< z << " | "<< #w << "--> " << w <<endl #define vpll vector<pair<ll,ll>> #define F first #define S second using namespace std; ll mode = 1e9 + 7; const ll maxn = 2*1e5 + 5; const ll inf = 10000000000000; ll __lcm(ll a, ll b){ return (a*b)/__gcd(a,b); } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); ll getRand(ll l, ll r){ uniform_int_distribution<int> uid(l, r); return uid(rng); } template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) { return out << "(" << a.F << ", " << a.S << ")"; } template <class A> ostream& operator << (ostream& out, const vector<A> &v) { out << "["; for (int i=0;i<v.size();i++) { if(i) out << ", "; out << v[i]; } return out << "]"; } void solve(){ ll n,C; cin>>n>>C; map<ll,ll> mp; for (int i=0;i<n;i++){ ll a,b,c; cin>>a>>b>>c; mp[a]+=c; mp[b+1]-=c; } ll cur_sum = 0, ans = 0; pair<ll,ll> prev = {-1, -1}; for (auto i:mp){ if (prev.F==-1){ prev = i; continue; } ll days = (i.F - prev.F); cur_sum += prev.S; ans += min( cur_sum, C )*days; prev = i; } cout<<ans<<endl; return; } int main(){ #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); #endif srand(time(0)); ios::sync_with_stdio(0); cin.tie(0); ll test_case = 1; //cin>>test_case; while(test_case--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define eps 1e-9 #define INF 2000000000 // 2e9 #define LLINF 2000000000000000000ll // 2e18 (llmax:9e18) #define all(x) (x).begin(), (x).end() #define sq(x) ((x) * (x)) #define rep(i, x) for (int i = 0; i < (int)(x); i++) #define drep(i, x) for (int i = ((int)(x)-1); i >= 0; i--) #define popcount __builtin_popcount #define next __next #define prev __prev #ifndef LOCAL #define dmp(...) ; #else #define dmp(...) \ cerr << "[ " << #__VA_ARGS__ << " ] : " << dump_str(__VA_ARGS__) << endl #endif // ---------------- Utility ------------------ template <class T> bool chmin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } template <class T> bool chmax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } template <class T> using MaxHeap = priority_queue<T>; template <class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>; template <class T> vector<T> vect(int len, T elem) { return vector<T>(len, elem); } // ----------------- Input ------------------- template <class T, class U> istream &operator>>(istream &is, pair<T, U> &p) { return is >> p.first >> p.second; } template <class T> istream &operator>>(istream &is, vector<T> &vec) { for (int i = 0; i < vec.size(); i++) is >> vec[i]; return is; } // ----------------- Output ------------------ template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << p.first << ',' << p.second; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &e : v) os << e << " "; return os; } template <class T> ostream &operator<<(ostream &os, const deque<T> &d) { for (const T &e : d) os << e << " "; return os; } template <class T> ostream &operator<<(ostream &os, const set<T> &s) { os << "{ "; for (const T &e : s) os << e << " "; return os << "}"; } template <class T, class U> ostream &operator<<(ostream &os, const map<T, U> &m) { os << "{ "; for (const auto &[key, val] : m) os << "( " << key << " -> " << val << " ) "; return os << "}"; } template <class TupleTy, size_t... I> void dump_tuple(ostream &os, const TupleTy t, std::index_sequence<I...>) { (..., (os << (I == 0 ? "" : ",") << std::get<I>(t))); } template <class... Args> ostream &operator<<(ostream &os, const tuple<Args...> &t) { os << "("; dump_tuple(os, t, std::make_index_sequence<sizeof...(Args)>()); return os << ")"; } void dump_str_rec(ostringstream &) {} template <class Head, class... Tail> void dump_str_rec(ostringstream &oss, Head &&head, Tail &&... tail) { oss << ", " << head; dump_str_rec(oss, forward<Tail>(tail)...); } template <class T, class... U> string dump_str(T &&arg, U &&... args) { ostringstream oss; oss << arg; dump_str_rec(oss, forward<U>(args)...); return oss.str(); } // --------------- Fast I/O ------------------ void fastio() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20); } // ------------------ ACL -------------------- // #include <atcoder/modint> // constexpr int MOD = 998244353; // constexpr int MOD = 1000000007; // using mint = atcoder::static_modint<MOD>; // ostream &operator<<(ostream &os, const mint &v) { // return os << v.val(); // } // ------------ End of template -------------- #define endl "\n" using ll = long long; using pii = pair<int, int>; void solve() { int N, X; cin >> N >> X; vector<int> A(N); cin >> A; vector<int> ans; for (int v : A) if (v != X) ans.push_back(v); for (int i = 0; i < ans.size(); i++) { cout << ans[i]; if (i + 1 < ans.size()) cout << ' '; else cout << endl; } return; } int main() { fastio(); solve(); // int t; cin >> t; while(t--)solve(); // int t; cin >> t; // for(int i=1;i<=t;i++){ // cout << "Case #" << i << ": "; // solve(); // } return 0; }
#include <iostream> #include <string> #include <vector> #include <deque> #include <queue> #include <algorithm> #include <iomanip> #include <set> #include <map> #include <bitset> #include <cmath> #include <functional> using namespace std; #define REP(i,n) for(ll (i) = (0);(i) < (n);++i) #define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i) #define PB push_back #define EB emplace_back #define MP make_pair #define FI first #define SE second #define ALL(v) v.begin(),v.end() #define Decimal fixed<<setprecision(20) #define INF 1000000000 #define LLINF 1000000000000000000LL #define MOD 1000000007LL typedef long long ll; typedef pair<ll,ll> P; template<typename T> void show_vector(vector<T> v) { for (auto ele: v)cout << ele << " " ;cout << endl; } template<typename T> void show_vector(vector<vector<T>> v) { for (auto ele: v)show_vector(ele); } template<typename T> void show_vector(vector<vector<vector<T>>> v) { for (auto ele: v) { show_vector(ele); cout << endl; } } int main(){ cin.tie(0);cout.tie(0);ios::sync_with_stdio(false); ll n, m;cin >> n >> m; map<int, int> mp; REP(i, n) { ll a;cin >> a;mp[a]++; } REP(i, m) { ll b;cin >> b;mp[b]++; } for(auto ele: mp) { if(ele.SE == 1)cout << ele.FI << " "; } cout << endl; return 0; }
//~ while (clock()<=69*CLOCKS_PER_SEC) //~ #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("O3") //~ #pragma GCC target ("avx2") //~ #pragma GCC optimize("Ofast") //~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") //~ #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define sim template < class c #define ris return * this #define dor > debug & operator << #define eni(x) sim > typename \ enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { #ifdef LOCAL ~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } #else sim dor(const c&) { ris; } #endif }; #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " #define shandom_ruffle random_shuffle using ll=long long; using pii=pair<int,int>; using pll=pair<ll,ll>; using vi=vector<int>; using vll=vector<ll>; const int nax=1000*1007; int n; char wcz[nax]; int main() { scanf("%d", &n); scanf("%s", wcz+1); int row=1; for (int i=1; i<=n; i++) { if (wcz[i]!=wcz[1]) row=0; } int wyn=nax; if (wcz[1]!=wcz[n]) wyn=1; for (int i=2; i<n; i++) { if (wcz[i]!=wcz[1] && wcz[i+1]!=wcz[1]) wyn=min(wyn, 2); } if (wyn==nax) wyn=-1; printf("%d\n", wyn); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define mp make_pair #define fr first #define sc second struct Graph{ int n; vector<vector<pair<int,int>>> G; Graph(int n_){ init(n_); } Graph(){} virtual void init(int n_){ n=n_; G=vector<vector<pair<int,int>>>(n,vector<pair<int,int>>()); } virtual void add_edge(int u,int v,int i=0){ G[u].push_back(mp(v,i)); } }; Graph g; vector<int> num,used; int dfs(int v,int i,int p,int k){ if(num[v]!=-1)return k; num[v]=k++; if(i!=-1)used[i]=1; for(auto ed: g.G[v]){ k=dfs(ed.fr,ed.sc,v,k); } return k; } void dfs_tree(int n,int m){ num.resize(n,-1); used.resize(m,0); int k=0; for(int i=0;i<n;i++){ if(num[i]==-1)k=dfs(i,-1,-1,k); } } int main(){ int n,m; scanf("%d%d",&n,&m); vector<int> a(m),b(m); for(int i=0;i<m;i++){ scanf("%d%d",&a[i],&b[i]); a[i]--; b[i]--; } vector<int> c(n); for(int i=0;i<n;i++)scanf("%d",&c[i]); g.init(n); for(int i=0;i<m;i++){ if(c[a[i]]==c[b[i]]){ g.add_edge(a[i],b[i],i); g.add_edge(b[i],a[i],i); //cerr<<a[i]<<" "<<b[i]<<endl; } } dfs_tree(n,m); //for(int i=0;i<n;i++)cerr<<num[i]<<" "; cerr<<endl; //for(int i=0;i<m;i++)cerr<<used[i]<<" "; cerr<<endl; for(int i=0;i<m;i++){ if(c[a[i]]!=c[b[i]]){ if(c[a[i]]>c[b[i]])puts("->"); else puts("<-"); } else { int t=used[i]; if(num[a[i]]<num[b[i]])t++; if(t==1)puts("<-"); else puts("->"); } } }
#include <bits/stdc++.h> #include <bits/extc++.h> using namespace std; using namespace __gnu_pbds; #define int long long #define ull unsigned long long #define ld long double #define rep(a) rep1(i,a) #define rep1(i,a) rep2(i,0,a) #define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++) #define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--) #define all(a) a.begin(),a.end() #define pii pair<int,int> #define pb push_back //#define inf 1010000000 #define inf 4000000000000000000 #define eps 1e-9 #define sz(a) ((int)a.size()) #define pow2(x) (1ll<<(x)) #define ceiling(a,b) (((a)+(b)-1)/(b)) #define print0(a) cout << (a) << ' ' #define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) #define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> #ifdef i_am_noob #define bug(...) cerr << "#" << __LINE__ << ' ' << #__VA_ARGS__ << "- ", _do(__VA_ARGS__) template<typename T> void _do(T && x) {cerr << x << endl;} template<typename T, typename ...S> void _do(T && x, S&&...y) {cerr << x << ", "; _do(y...);} #else #define bug(...) 826 #endif template<typename T> void print(T && x) {cout << x << "\n";} template<typename T, typename... S> void print(T && x, S&&... y) {cout << x << ' ';print(y...);} const int Mod=1000000007,Mod2=998244353; const int MOD=Mod; const int maxn=100005; //i_am_noob int n,m,e[maxn][3],a[105]; vector<pii> adj[105]; bool vis[105]; void dfs(int u, int par){ vis[u]=true; for(auto p: adj[u]){ int v=p.first; if(vis[v]){ if(e[p.second>=0?p.second:-p.second-1][2]==2){ if(p.second>=0) e[p.second][2]=1; else e[-p.second-1][2]=0; } continue; } if(e[p.second>=0?p.second:-p.second-1][2]==2){ if(p.second>=0) e[p.second][2]=1; else e[-p.second-1][2]=0; } dfs(v,u); } } signed main(){ ios_base::sync_with_stdio(0),cin.tie(0); #ifdef i_am_noob freopen("input1.txt","r",stdin); freopen("output1.txt","w",stdout); #endif cin >> n >> m; rep(m){ cin >> e[i][0] >> e[i][1]; e[i][0]--,e[i][1]--; } rep(n) cin >> a[i]; rep(m){ if(a[e[i][0]]>a[e[i][1]]) e[i][2]=1; else if(a[e[i][0]]<a[e[i][1]]) e[i][2]=0; else adj[e[i][0]].pb({e[i][1],i}),adj[e[i][1]].pb({e[i][0],-i-1}),e[i][2]=2; } rep(n) if(!vis[i]) dfs(i,-1); rep(m){ if(e[i][2]==2) print("a"); print(e[i][2]?"->":"<-"); } return 0; }
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <cmath> #include <queue> using std::cout; using std::cin; using std::string; using std::vector; using std::endl; int main() { const long long mod = 998244353; int h, w; cin >> h >> w; vector<string> graph(h); for (int i = 0; i < h; i++) { cin >> graph[i]; } long long ans = 1; int groups = 0; for (int i = 0; i < h; i++) { if (ans == 0) break; int y = i; int x = 0; char diag = '.'; while (y >= 0 && x <= w - 1) { if (graph[y][x] == 'R') { if (diag == 'B') ans = 0; else diag = 'R'; } if (graph[y][x] == 'B') { if (diag == 'R') ans = 0; else diag = 'B'; } y--; x++; } if (diag == '.') { groups++; } } for (int i = 1; i < w; i++) { if (ans == 0) break; int y = h - 1; int x = i; char diag = '.'; while (y >= 0 && x <= w - 1) { if (graph[y][x] == 'R') { if (diag == 'B') ans = 0; else diag = 'R'; } if (graph[y][x] == 'B') { if (diag == 'R') ans = 0; else diag = 'B'; } y--; x++; } if (diag == '.') { groups++; } } if (ans != 0) { for (int i = 0; i < groups; i++) { ans = ans * 2 % mod; } } cout << ans; return 0; }
#pragma GCC optimize ("O3") #pragma GCC target ("sse4") #include<bits/stdc++.h> //gouravrj code:P using namespace std; #define fo(i,n) for(int i=0;i<n;i++) #define Fo(i,k,n) for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1) #define ll long long #define pb push_back #define mp make_pair #define F first #define S second #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define tr(it, a) for(auto it = a.begin(); it != a.end(); it++) #define PI 3.1415926535897932384626 #define INF 0x3f3f3f3f3f3f3f3fLL typedef pair<int, int> pii; typedef pair<ll, ll> pl; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpii; typedef vector<pl> vpl; typedef vector<vi> vvi; typedef vector<vl> vvl; const int mod = 1000000007; const int N = 3e5, M = N; /*******************************************************************************************/ template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { os << "["; for (int i = 0; i < v.size(); ++i) {if (i) os << ", "; os << v[i]; } os << "]\n"; return os; } template <typename T> ostream& operator<<(ostream& os, const set<T>& v) { os << "{"; for (auto it : v) { os << it; if (it != *v.rbegin()) os << ", "; } os << "}\n"; return os; } template <typename T> ostream& operator<<(ostream& os, const multiset<T>& v) { os << "{"; for (auto it : v) { os << it; if (it != *v.rbegin()) os << ", "; } os << "}\n"; return os; } template <typename T, typename S> ostream& operator<<(ostream& os, const map<T, S>& v) { os << "{"; for (auto it : v) { os << "(" << it.first << " : " << it.second << ")"; if (it != *v.rbegin()) os << ", "; } os << "}\n"; return os; } template <typename T, typename S> ostream& operator<<(ostream& os, const unordered_map<T, S>& v) { os << "{"; for (auto it : v) { os << "(" << it.first << " : " << it.second << ")"; os << ", "; } os << "}\n"; return os; } template <typename T, typename S> ostream& operator<<(ostream& os, const pair<T, S>& v) { os << "("; os << v.first << ", " << v.second << ")"; return os; } template <typename T> inline istream &operator>>(istream &in, vector<T> &a) { for (auto &x : a) in >> x; return in; } #ifndef ONLINE_JUDGE const string COLOR_RESET = "\033[0m", BRIGHT_GREEN = "\033[1;32m", BRIGHT_RED = "\033[0;31m", BRIGHT_CYAN = "\033[1;36m"; vector<string> tokenizer(const string args) { string tk = args; vector<string> v; for (int i = 0; i < tk.size(); i++) { string s = ""; int j = i; while (j < tk.size() && tk[j] != ',')s += tk[j++]; i = j; v.push_back(s); } reverse(all(v)); return v; } void debugg(vector<string> args) { cerr << "\b\b "; } template <typename Head, typename... Tail> void debugg(vector<string>args, Head H, Tail... T) { if (!sz(args))return ; cerr << " [" << BRIGHT_CYAN << args.back() << ": " << BRIGHT_GREEN << H << COLOR_RESET << "] "; if (sz(args)) {args.pop_back(); debugg(args, T...);} } #define deb(...) { debugg(tokenizer(#__VA_ARGS__), __VA_ARGS__, __LINE__);cerr<<'\n'; } #endif #ifdef ONLINE_JUDGE #define deb(...) #endif /*******************************************************************************************/ void run_case() { ll int t, i, j, k, p, x, y, u, n, m, w; ll A,B; cin>>A>>B; long double ans=A*(B/(100*1.0)); cout<<fixed<<setprecision(8)<<ans<<'\n'; }//end /*******************************************************************************************/ int main() { cin.tie(0)->sync_with_stdio(0); #ifndef ONLINE_JUDGE //freopen("/home/gourav/input1.txt", "r", stdin); freopen("/home/gourav/output1.txt", "w", stdout); //freopen("error.txt", "w", stderr); #endif int t = 1; //int T; // cin >> t; Fo(T, 1, t + 1) { // cout<<"Case #"<<T<<": "; run_case(); } cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl; return 0; }
#include <cstdio> const double eps=1e-6; int n; double a[100005]; inline double min(double a,double b) { return a<b?a:b; } double calc(double x) { double ans=0; for(int i=1;i<=n;i++) { ans+=x+a[i]-min(a[i],x*2.0); } //printf("%.6lf %.6lf\n",x,ans); return ans; } int main() { scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%lf",&a[i]); } double l=0.0,r=1e9; while((r-l)>eps) { double a=l+(r-l)/3.0; double b=r-(r-l)/3.0; if(calc(a)<calc(b)) { r=b; }else { l=a; } } printf("%.6lf\n",min(calc(l),calc(r))/(1.0*n)); return 0; }
#include <iostream> #include <string> #include <vector> #include <set> #include <map> #include <queue> #include <stack> #include <algorithm> #include <math.h> #include <cassert> #define rep(i,n) for(int i = 0; i < n; ++i ) using namespace std; using ll = long long; ll x[100005],y[100005]; int main() { int n; cin >> n; rep(i,n){ int a; cin >> a; x[a]++; } vector<int> b(n); rep(i,n) cin >> b[i]; rep(i,n){ int c; cin >> c; --c; y[b[c]]++; } ll ans = 0; rep(i,n+1) ans += x[i]*y[i]; cout << ans << endl; }
#include <bits/stdc++.h> #define LL long long const int maxn=1e5+5; using namespace std; LL ans=0; int op[80]; LL ans1[80]; LL ans2[80]; int main() { LL n; cin>>n; for(int i=1;i<=n;i++) { string s; cin>>s; if(s=="AND") op[i]=1; else op[i]=0; } memset(ans1,0,sizeof(ans1)); memset(ans2,0,sizeof(ans2)); ans1[0]=1; ans2[0]=1; for(int i=1;i<=n;i++) { if(op[i]==1) ///and { ans1[i]=ans1[i-1]; ans2[i]=ans1[i-1]+ans2[i-1]*2; } else ///or { ans1[i]=ans1[i-1]*2+ans2[i-1]; ans2[i]=ans2[i-1]; } } /*for(int i=0;i<=n;i++) cout<<ans1[i]<<" "; cout<<endl; for(int i=0;i<=n;i++) cout<<ans2[i]<<" "; cout<<endl;*/ cout<<ans1[n]<<endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) using ll = long long; using P = pair<int,int>; int main() { int n; cin >> n; vector<ll> dp(2, 1); vector<ll> ndp(2, 0); rep(i,n) { string s; cin >> s; rep(xi,2) { rep(xi1,2) { int yi1; if (s == "AND") { yi1 = xi & xi1; } else { yi1 = xi | xi1; } ndp[yi1] += dp[xi]; } } swap(ndp, dp); ndp.clear(); ndp.resize(2); } ll ans = dp[1]; cout << ans << endl; return 0; }
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author Pine1999 */ #include <bits/stdc++.h> using namespace std; void CNeqMin(std::istream& in, std::ostream& out) { int n; in >> n; vector<int> p(n); vector<bool> exist(400050); int ans = 0; for (int i = 0; i < n; ++i) { in >> p[i]; exist[p[i]] = true; while (exist[ans]) ++ans; out << ans << '\n'; } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); std::istream& in(std::cin); std::ostream& out(std::cout); CNeqMin(in, out); return 0; }
#include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define int long long #define pb push_back #define mp make_pair #define pii pair<int, int> #define vi vector<int> #define mii map<int, int> #define pqb priority_queue<int> #define pqs priority_queue<int, vi, greater<int>> #define mod 1000000007 #define ps(x, y) fixed << setprecision(y) << x #define w(x) \ int x; \ cin >> x; \ while (x--) #define fastIO \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define fo(i, n) for (int i = 0; i < n; i++) #define Fo(i, k, n) for (int i = k; i < n; i++) int32_t main(){ string str; cin >> str; int count = 0; for(int i = 0; i < str.size(); i++){ if(str[i]=='Z' && str[i+1]=='O' && str[i+2]=='N' && str[i+3]=='e'){ count++; i += 3; } } cout << count << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef signed long long ll; #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define FORR2(x,y,arr) for(auto& [x,y]:arr) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;} template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;} //------------------------------------------------------- int N; int A[402020]; ll mo=3; ll fact[403030]; ll fact3[403030]; ll modpow(ll a, ll n=mo-2) { ll r=1; while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1; return r; } ll comb(int A,int B) { int C=A-B; if(fact3[A]>fact3[B]+fact3[C]) return 0; return fact[A]*modpow(fact[B]*fact[C])%mo; } void solve() { int i,j,k,l,r,x,y; string s; cin>>N; fact[0]=1; fact3[0]=0; for(i=1;i<=N-1;i++) { fact[i]=fact[i-1]; fact3[i]=fact3[i-1]; x=i; while(x%3==0) { fact3[i]++; x/=3; } fact[i]=fact[i]*x%3; } cin>>s; ll ret=0; FOR(i,N) { if(s[i]=='B') A[i]=0; if(s[i]=='W') A[i]=1; if(s[i]=='R') A[i]=2; if(N%2==1) { ret+=comb(N-1,i)*A[i]; } else { ret-=comb(N-1,i)*A[i]; } } ret=(ret%3+3)%3; cout<<"BWR"[ret]<<endl; } int main(int argc,char** argv){ string s;int i; if(argc==1) ios::sync_with_stdio(false), cin.tie(0); FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin); cout.tie(0); solve(); return 0; }
#include<bits/stdc++.h> using namespace std; const int N=400005; int n,a[N],f[]={1,1,2},sum; char s[N]; int c(int n,int m) { if(n<m) return 0; if(n<3) return f[n]*f[m]*f[n-m]%3; return c(n%3,m%3)*c(n/3,m/3)%3; } int main() { scanf("%d%s",&n,s+1); for(int i=1;i<=n;i++) if(s[i]=='W') a[i]=1; else if(s[i]=='R') a[i]=2; for(int i=1;i<=n;i++) sum=(sum+a[i]*c(n-1,i-1))%3; if(n%2==0) sum=(3-sum)%3; if(sum==0) puts("B"); if(sum==1) puts("W"); if(sum==2) puts("R"); return 0; }
#include <cmath> #include <algorithm> #include <bitset> #include <iostream> #include <set> #include <string> #include <tuple> #include <unordered_set> #include <vector> using namespace std; int main() { ios_base::sync_with_stdio(false); string input; cin >> input; auto sub = input; size_t itr = 0; int count = 0; for (size_t i = 0; i < input.length(); i++) { if (sub.find("ZONe") == string::npos) break; count++; itr = sub.find("ZONe"); if (itr > input.length() - 4) continue; sub = sub.substr(itr + 4); } cout << count << endl; return 0; }
#include <iostream> #include <vector> #include <map> #include <algorithm> #include <set> #include <queue> #include <cmath> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<long long> vll; typedef vector<vector<long long>> vvll; typedef pair<int,int> pii; typedef pair<long long, int> pli; typedef pair<int, long long> pil; #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define rrep(i, n) for(int i = (int)(n)-1;i >= 0;i--) #define repr(i, a, b) for(int i = (int)a; i <= (int)b; i++) #define all(x) (x).begin(),(x).end() #define sz(x) (x).size() constexpr ll mod = 998244353; ll gcd(ll a, ll b){ if (a%b == 0)return(b); else return(gcd(b, a%b)); } ll inv(ll x){ ll res = 1; ll k = mod - 2; ll y = x; while(k){ if(k&1)res = (res*y)%mod; y = (y*y) % mod; k /= 2; } return res; } int main(){ cin.tie(0); ios::sync_with_stdio(false); string s; cin >> s; string ret = "Yes"; rep(i,s.length()) { if (s[i] >= 'a' && s[i] <= 'z') { if (i % 2 != 0) ret = "No"; } else { if (i % 2 != 1) ret = "No"; } } cout << ret << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int l; cin >> l; ll ans = 1; for (int i = 1; i <= 11; i++) { ans*= l - i; ans/= i; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pll = pair<ll, ll>; using tlll = tuple<ll, ll, ll>; //constexpr ll MOD = 1e9 + 7; constexpr ll MOD = 998244353; //constexpr ll MOD = ; ll mod(ll A, ll M) {return (A % M + M) % M;} constexpr ll INF = 1LL << 60; template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;} template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;} ll divceil(ll A, ll B) {return (A + (B - 1)) / B;} #define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false) int main() { ll L; cin >> L; const ll M = 210; vector<vector<ll>> C(M, vector<ll>(M, 0)); C.at(0).at(0) = 1; for (ll i = 0; i < M - 1; i++) { for (ll j = 0; j < i + 1; j++) { C.at(i + 1).at(j) += C.at(i).at(j); C.at(i + 1).at(j + 1) += C.at(i).at(j); } } /* for (ll i = 0; i < M; i++) { for (ll j = 0; j < M; j++) { cerr << C.at(i).at(j) << " "; } cerr << endl; } //*/ ll ans = C.at(L - 1).at(11); cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define R cin>> #define ll long long #define ln cout<<endl #define in(a) insert(a) #define pb(a) push_back(a) #define pd(a) printf("%.10f\n",a) #define mem(a) memset(a,0,sizeof(a)) #define all(c) (c).begin(),(c).end() #define iter(c) __typeof((c).begin()) #define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--) #define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++) #define rep(i,n) REP(i,0,n) #define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++) ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;} template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);} template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;} const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1}; typedef pair<ll,ll> P; vector<string> C(vector<string> s) { ll n=s.size(); rep(i,n)REP(j,i+1,n) swap(s[i][j],s[j][i]); return s; } ll n,m; string s[1000]; ll calc(vector<string> t) { ll cnt=0; rep(k,m) { ll f=0; rep(l,2) { rep(i,n) { rep(j,n) { if(t[i].substr(0,s[k].size())==s[k]) f=1; rotate(t[i].begin(),t[i].begin()+1,t[i].end()); } } t=C(t); } cnt+=f; } return cnt; } vector<string> ans; ll MM; void solve(vector<string> t) { ll d=calc(t); if(MM<d) { MM=d; ans=t; } rep(k,5) { random_shuffle(all(t)); rep(i,n) rotate(t[i].begin(),t[i].begin()+rand()%n,t[i].end()); ll d=calc(t); if(MM<d) { MM=d; ans=t; } } } void Main() { srand((unsigned)time(NULL)); cin >> n >> m; rep(i,m) R s[i]; vector<string> v[15]; rep(i,m) v[s[i].size()].pb(s[i]); rep(e,35) { vector<string> t(n); rrep(i,15) { random_shuffle(all(v[i])); rep(j,v[i].size()) { ll M=MAX,x=0; string rr; rep(k,n) { rep(l,t[k].size()+1) { string r1=t[k].substr(l); if(r1.size()<=v[i][j].size()) { string r2=v[i][j].substr(0,r1.size()); if(r1==r2) { ll d=t[k].size()+v[i][j].size()-r1.size(); if(d<=n&&M>d) { M=d; x=k; rr=t[k]+v[i][j].substr(r1.size()); } } } if(l+v[i][j].size()<=t[k].size()) { r1=t[k].substr(l,v[i][j].size()); if(r1==v[i][j]) { M=0; x=k; rr=t[k]; } } } } if(rand()%(i+3)==0) M=MAX; if(M!=MAX) t[x]=rr; } } rep(i,n) { while(t[i].size()<n) { //t[i]+='.'; t[i]+=(char)(rand()%8+'A'); } } solve(t); } rep(i,n) pr(ans[i]); } int main(){Main();return 0;}
#include <iostream> #include <iomanip> #include <string> #include <stack> #include <vector> #include <complex> #include <math.h> #include <stdio.h> #include <algorithm> #include <utility> #include <functional> #include <iterator> #include <map> #include <set> #include <queue> #include <list> #include <regex> #include <limits> #include <time.h> #include <cstdint> #include <unordered_map> #include <unordered_set> #include <bitset> #include <limits.h> using namespace std; using pii = pair<int,int>; using ll=long long; using ld=long double; #define pb push_back #define mp make_pair #define sc second #define fr first #define stpr setprecision #define cYES cout<<"YES"<<endl #define cNO cout<<"NO"<<endl #define cYes cout<<"Yes"<<endl #define cNo cout<<"No"<<endl #define rep(i,n) for(ll i=0;i<(n);++i) #define Rep(i,a,b) for(ll i=(a);i<(b);++i) #define rrep(i,n) for(ll i=n-1;i>=0;i--) #define rRep(i,a,b) for(ll i=a;i>=b;i--) #define crep(i) for(char i='a';i<='z';++i) #define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;}); #define ALL(x) (x).begin(),(x).end() #define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; #define endl '\n' int ctoi(const char c){ if('0' <= c && c <= '9') return (c-'0'); return -1; } ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));} ll lcm(ll a,ll b){return a*b/gcd(a,b);} constexpr ll MOD=1000000007; constexpr ll INF=1000000011; constexpr ll MOD2=998244353; constexpr ll LINF = 1001002003004005006ll; constexpr ld EPS=10e-8; template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; } template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; } template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;} template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;} template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;} template<class T> ostream& operator<<(ostream& os, vector<T>& v){ for(auto i=begin(v); i != end(v); ++i){ if(i !=begin(v)) os << ' '; os << *i; } return os; } class DisjointSet{ public: vector<int> rank,p,sz; DisjointSet(){} //初期化 DisjointSet(int size){ rank.resize(size,0); p.resize(size,0); sz.resize(size,1); rep(i,size){ makeSet(i); } } void makeSet(int x){ p[x]=x; rank[x]=0; } bool same(int x,int y){ return findSet(x)==findSet(y); } void unite(int x,int y){ if(!same(x,y)) link(findSet(x),findSet(y)); } int size(int key){ return sz[findSet(key)]; } void link(int x,int y){ if(rank[x]>rank[y]){ p[y]=x; sz[x]+=sz[y]; } else{ p[x]=y; sz[y]+=sz[x]; if(rank[x]==rank[y]){ rank[y]++; } } } int findSet(int x){ // 根を返す if(x!=p[x]){ p[x]=findSet(p[x]); } return p[x]; } }; map<ll,ll> S,T; int main(){ ll N,M; cin >> N >> M; DisjointSet X; X=DisjointSet(N+1); // N頂点(0-indexed)を用意 vector<ll> A(N),B(N); rep(i,N){ cin >> A[i]; } rep(i,N){ cin >> B[i]; } rep(i,M){ ll a,b;cin>>a>>b;a--;b--; X.unite(a,b); } rep(i,N){ S[X.findSet(i)]+=A[i]; T[X.findSet(i)]+=B[i]; } for(auto P : S){ if(S[P.fr]!=T[P.fr]){ cNo; return 0; } } cYes; }
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < (n); i++) using namespace std; int c[100010], cnt[100010], good[100010]; vector<int> e[100010]; void dfs(int now, int p = -1) { if (cnt[c[now]] == 0) good[now] = true; cnt[c[now]]++; for (auto to : e[now]) if (to != p) dfs(to, now); cnt[c[now]]--; } int main() { int n; cin >> n; REP(i, n) cin >> c[i]; REP(i, n-1) { int a, b; cin >> a >> b; e[--a].push_back(--b); e[b].push_back(a); } dfs(0); REP(i, n) if (good[i]) cout << i+1 << '\n'; return 0; }
#include<bits/stdc++.h> #define pb push_back #define all(v) v.begin(),v.end() #define allr(v) v.rbegin(),v.rend() #define SORT(v) sort(all(v)) #define int long long #define ff first #define ss second #define mod 1000000007 #define endl "\n" using namespace std; void oj() { ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } vector<int>v[200005]; int n; vector<int>color; set<int>st; vector<int>ans; void dfs(int x, int par) { bool ok = false; if(st.find(color[x]) == st.end()) { st.insert(color[x]); ans.pb(x); ok = true; } for(auto el : v[x]) { if(el != par) dfs(el, x); } if(ok) st.erase(color[x]); } void solve() { cin>>n; color = vector<int>(n + 1); for(int i = 1; i <= n; i++) cin>>color[i]; for(int i = 0; i < n - 1; i++) { int a, b; cin>>a>>b; v[a].pb(b); v[b].pb(a); } dfs(1, 0); SORT(ans); for(auto el : ans) cout<<el<<endl; } signed main() { oj(); // int t; cin>>t; // while(t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define fast ios_base::sync_with_stdio(false);cin.tie(NULL); void contest() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int main() { contest(); fast ///// CODE BELOW ////////// long long int a, b; cin >> a >> b; long long int sm = 0; long long int sm2 = 0; if (a >= b) { for (int i = 1; i <= a; i++) { cout << i << " "; sm += i; } for (int i = 1; i <= b - 1; i++) { cout << (-i) << " "; sm2 += i; } sm2 = -sm2; cout << -(sm + sm2); } else { for (int i = 1; i <= b; i++) { cout << (-i) << " "; sm2 += i; } sm2 = -sm2; for (int i = 1; i <= a - 1; i++) { cout << i << " "; sm += i; } cout << -(sm + sm2); } }
#include<iostream> #include<string> #include<cstdio> #include<vector> #include<cmath> #include<algorithm> #include<functional> #include<iomanip> #include<queue> #include<ciso646> #include<random> #include<map> #include<set> #include<bitset> #include<stack> #include<unordered_map> #include<unordered_set> #include<utility> #include<cassert> #include<complex> #include<numeric> #include<array> using namespace std; //#define int long long typedef long long ll; typedef unsigned long long ul; typedef unsigned int ui; constexpr ll mod = 1000000007; const ll INF = mod * mod; typedef pair<int, int>P; #define stop char nyaa;cin>>nyaa; #define rep(i,n) for(int i=0;i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define Rep(i,sta,n) for(int i=sta;i<n;i++) #define rep1(i,n) for(int i=1;i<=n;i++) #define per1(i,n) for(int i=n;i>=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) #define all(v) (v).begin(),(v).end() typedef pair<ll, ll> LP; typedef long double ld; typedef pair<ld, ld> LDP; const ld eps = 1e-12; const ld pi = acosl(-1.0); ll mod_pow(ll x, ll n, ll m = mod) { if (n < 0) { ll res = mod_pow(x, -n, m); return mod_pow(res, m - 2, m); } if (abs(x) >= m)x %= m; if (x < 0)x += m; ll res = 1; while (n) { if (n & 1)res = res * x % m; x = x * x % m; n >>= 1; } return res; } struct modint { ll n; modint() :n(0) { ; } modint(ll m) :n(m) { if (n >= mod)n %= mod; else if (n < 0)n = (n % mod + mod) % mod; } operator int() { return n; } }; bool operator==(modint a, modint b) { return a.n == b.n; } modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; } modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; } modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; } modint operator+(modint a, modint b) { return a += b; } modint operator-(modint a, modint b) { return a -= b; } modint operator*(modint a, modint b) { return a *= b; } modint operator^(modint a, ll n) { if (n == 0)return modint(1); modint res = (a * a) ^ (n / 2); if (n % 2)res = res * a; return res; } ll inv(ll a, ll p) { return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p); } modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); } modint operator/=(modint& a, modint b) { a = a / b; return a; } const int max_n = 1 << 16; modint fact[max_n], factinv[max_n]; void init_f() { fact[0] = modint(1); for (int i = 0; i < max_n - 1; i++) { fact[i + 1] = fact[i] * modint(i + 1); } factinv[max_n - 1] = modint(1) / fact[max_n - 1]; for (int i = max_n - 2; i >= 0; i--) { factinv[i] = factinv[i + 1] * modint(i + 1); } } modint comb(int a, int b) { if (a < 0 || b < 0 || a < b)return 0; return fact[a] * factinv[b] * factinv[a - b]; } modint combP(int a, int b) { if (a < 0 || b < 0 || a < b)return 0; return fact[a] * factinv[a - b]; } void solve() { int a, b; cin >> a >> b; vector<int> ans; bool sw = false; if (a < b) { sw = true; swap(a, b); } int sum = 0; rep1(i, a) { ans.push_back(i); sum += i; } rep1(i, b - 1) { ans.push_back(-i); sum -= i; } ans.push_back(-sum); if (sw) { rep(i, ans.size())ans[i] *= -1; } rep(i, a + b){ if (i > 0)cout << " "; cout << ans[i]; } cout << "\n"; } signed main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(10); //init_f(); //init(); //expr(); //int t; cin >> t;rep(i,t) //while(cin>>n,n) //solve(); solve(); return 0; }
#include<cstdio> #define F(i,l,r) for(int i=l,i##_end=r;i<i##_end;++i) using namespace std; template<typename T>void read(T &x) { bool neg=false; unsigned char c=getchar(); for(;(c^48)>9;c=getchar())if(c=='-')neg=true; for(x=0;(c^48)<10;c=getchar())x=(x<<3)+(x<<1)+(c^48); if(neg)x=-x; } int a,b,c; int main() { read(a);read(b);read(c); puts(a*a+b*b<c*c?"Yes":"No"); return 0; }
#define MOD_TYPE 1 #pragma region Macros #include <bits/stdc++.h> using namespace std; #if 0 #include <boost/multiprecision/cpp_int.hpp> #include <boost/multiprecision/cpp_dec_float.hpp> using Int = boost::multiprecision::cpp_int; using lld = boost::multiprecision::cpp_dec_float_100; #endif #if 0 #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #endif using ll = long long int; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; using pld = pair<ld, ld>; template <typename Q_type> using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>; //constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353); constexpr ll MOD = 3; constexpr int INF = (int)1e9 + 10; constexpr ll LINF = (ll)4e18; constexpr ld PI = acos(-1.0); constexpr ld EPS = 1e-9; constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0}; constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0}; #define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i) #define rep(i, n) REP(i, 0, n) #define REPI(i, m, n) for (int i = m; i < (int)(n); ++i) #define repi(i, n) REPI(i, 0, n) #define MP make_pair #define MT make_tuple #define YES(n) cout << ((n) ? "YES" : "NO") << "\n" #define Yes(n) cout << ((n) ? "Yes" : "No") << "\n" #define possible(n) cout << ((n) ? "possible" : "impossible") << "\n" #define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n" #define all(v) v.begin(), v.end() #define NP(v) next_permutation(all(v)) #define dbg(x) cerr << #x << ":" << x << "\n"; struct io_init { io_init() { cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(30) << setiosflags(ios::fixed); }; } io_init; template <typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } inline ll CEIL(ll a, ll b) { return (a + b - 1) / b; } template <typename A, size_t N, typename T> inline void Fill(A (&array)[N], const T &val) { fill((T *)array, (T *)(array + N), val); } template <typename T, typename U> constexpr istream &operator>>(istream &is, pair<T, U> &p) noexcept { is >> p.first >> p.second; return is; } template <typename T, typename U> constexpr ostream &operator<<(ostream &os, pair<T, U> &p) noexcept { os << p.first << " " << p.second; return os; } #pragma endregion // -------------------------------------- void solve() { ll a, b, c; cin >> a >> b >> c; Yes(a*a+b*b<c*c); } int main() { solve(); }
#include<bits/stdc++.h> using namespace std; int main() { int sum = 0; int day = 1; int n; cin >> n; for(int i = 1; i < n; i++) { sum += i; if(sum >= n) { break; } day++; } cout << day << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; typedef vector<ll> vl; typedef vector<bool> vb; typedef vector<string> vs; typedef vector<char> vc; typedef queue<ll> ql; typedef deque<ll> dql; typedef priority_queue<ll> pql; typedef set<ll> sl; typedef pair<ll, ll> pl; typedef map<ll, ll> ml; typedef vector<vl> vvl; typedef vector<pl> vpl; #define rep(i, n) for(ll i = 0; i < ll(n); i++) #define rep2(i, k, n) for(ll i = ll(k); i <= ll(n); i++) #define rep3(i, n, k) for(ll i = ll(n); i >= ll(k); i--) #define all(v) (v).begin(), (v).end() ll mod(ll a, ll b) {return (a % b + b) % b;} ll quo(ll a, ll b) {return (a - mod(a, b)) / b;} template <typename T, typename U> bool chmin(T &a, const U b) {if(a > b) {a = b; return 1;} return 0;} template <typename T, typename U> bool chmax(T &a, const U b) {if(a < b) {a = b; return 1;} return 0;} const ll INF = 1LL << 60; const ll MOD = 1e9 + 7; //const ll MOD = 998244353; const ll MAX = 2e5; const ld eps = 1e-9; const char newl = '\n'; int main() { ios::sync_with_stdio(false); cin.tie(0); ll n; string ans; cin >> n; vl a(2*n); rep(i, 2*n) cin >> a[i]; vpl vec(2*n); rep(i, 2*n) vec[i] = pl(a[i], i); sort(all(vec)); vb plus(2*n, 1); rep(i, n) plus[vec[i].second] = 0; ll cnt = 0; rep(i, 2*n) { if(plus[i]) { if(cnt >= 0) ans += '('; else ans += ')'; cnt++; }else { if(cnt <= 0) ans += '('; else ans += ')'; cnt--; } } cout << ans << newl; return 0; }
#include <bits/stdc++.h> #define fi first #define se second #define sz(a) (int)(a).size() #define all(a) (a).begin(), (a).end() #define reset(a, v) memset((a), v, sizeof(a)) using namespace std; typedef long long ll; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<ii> vii; ll x, y, a, b; bool isOverflow(ll x, ll a) { return (ll)1e18/x < a; } int main() { cin >> x >> y >> a >> b; ll ans = 0; while (1) { // cout << x << "\n"; // cout << ans << "\n"; if (isOverflow(x,a) || x*a >= x+b) { if (x+b >= y) { cout << ans << "\n"; return 0; } else { ans += (y-x-1)/b; cout << ans << "\n"; return 0; } } else { if (x*a >= y) { cout << ans << "\n"; return 0; } else { x *= a; ans++; } } } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pll; typedef vector<ll> vll; typedef vector<vector<ll>> vvll; typedef vector<pll> vpll; void INX(){} template<typename Head, typename... Tail> void INX(Head&& head, Tail&&... tail) { cin >> head; INX(forward<Tail>(tail)...); } void OUTX(){} template<typename Head, typename... Tail> void OUTX(Head&& head, Tail&&... tail) { cout << head << endl; OUTX(forward<Tail>(tail)...); } #define ADD emplace_back #define MP make_pair #define VVEC(type) vector<vector<type>> ll myproduct(ll x, ll y) { return (__LONG_LONG_MAX__ / x < y) ? __LONG_LONG_MAX__ : x * y; } ll mysum(ll x, ll y) { return (__LONG_LONG_MAX__ - x < y) ? __LONG_LONG_MAX__ : x + y; } int main() { ll X, Y, A, B; INX(X, Y, A, B); ll result = 0; //exp while(true) { ll method1 = myproduct(X, A); ll method2 = mysum(X, B); if(method1 >= Y && method2 >= Y) { break; } else if(method1 > method2) { //continue to choose method2(Atcoder gym) result += (Y - X - 1) / B; break; } else { X = method1; result++; } } OUTX(result); return 0; }
#include <iostream> #include <vector> #include <map> #include <set> #include <queue> #include <algorithm> #include <string> #include <cmath> #include <cstdio> #include <iomanip> #include <fstream> #include <cassert> #include <cstring> #include <unordered_set> #include <unordered_map> #include <numeric> #include <ctime> #include <bitset> #include <complex> #include <chrono> #include <random> #include <functional> using namespace std; string inv(string s) { string res; for (auto t : s) { if (t == 'A') { res.push_back('B'); } else { res.push_back('A'); } } return res; } vector<string> op(vector<string> a) { vector<string> res; for (auto t : a) { res.push_back(t + t); } for (auto t : a) { res.push_back(t + inv(t)); } string s(a[0].size(), 'A'); res.push_back(s + inv(s)); // for (auto t : a) { // res.push_back(inv(t) + t); // } return res; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); int k; cin >> k; if (k == 1) { cout << 1 << endl; cout << "AB" << endl; exit(0); } vector<string> v = { "AABB", "ABAB", "ABBA" }; for (int i = 2; i < k; i++) { v = op(v); } cout << v.size() << '\n'; for (auto s : v) { cout << s << '\n'; } }
#include "bits/stdc++.h" //#include "atcoder/all" using namespace std; //using namespace atcoder; //using mint = modint1000000007; //const int mod = 1000000007; //using mint = modint998244353; //const int mod = 998244353; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define rep2(i,l,r)for(int i=(l);i<(r);++i) #define rrep(i, n) for (int i = (n-1); i >= 0; --i) #define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i) #define all(x) (x).begin(),(x).end() #define allR(x) (x).rbegin(),(x).rend() #define endl "\n" int popcount(long long n) { n = (n & 0x5555555555555555) + (n >> 1 & 0x5555555555555555); n = (n & 0x3333333333333333) + (n >> 2 & 0x3333333333333333); n = (n & 0x0f0f0f0f0f0f0f0f) + (n >> 4 & 0x0f0f0f0f0f0f0f0f); n = (n & 0x00ff00ff00ff00ff) + (n >> 8 & 0x00ff00ff00ff00ff); n = (n & 0x0000ffff0000ffff) + (n >> 16 & 0x0000ffff0000ffff); n = (n & 0x00000000ffffffff) + (n >> 32 & 0x00000000ffffffff); return n; } char ans[2048][2048]; int main() { int N; cin >> N; int K = (1 << N) - 1; cout << K << endl; rep(i, (1 << N)) { rep(j, (1 << N)) { ans[i][j] = 'A'; } } rep(i, K) { rep(j, (1 << N)) { long long pop = popcount((i + 1) & j); if (0 == pop % 2) { ans[i][j] = 'B'; } else { ans[i][j] = 'A'; } } } rep(i, K) { rep(j, (1 << N)) { cout << ans[i][j]; } cout << endl; } return 0; }
//#include <bits/stdc++.h> #include <iostream> #include <numeric> #include <string> #include <vector> #include <cmath> #include <cassert> #include <algorithm> using namespace std; bool check(int a, int b, int w, int& min, int& max) { int imin = int(w / b); int imax = int(w / a); auto diff = float(b - a); min = imax; max = imin; bool is_ok = false; for (int i = imin; i <= imax; ++i) { for (int j = 0; j <= i; ++j) { auto ww = a * j; if ((w - ww) <= (i - j) * b) { is_ok = true; min = std::min(min, i); max = std::max(max, i); break; } } } return is_ok; } int main(void) { int a = 1, b = 2, w = 1; cin >> a >> b >> w; w = w * 1000; int min, max; bool is_ok; //is_ok = check(100, 200, 2000, min, max); //assert(is_ok && min == 10 && max == 20); //is_ok = check(120, 150, 2000, min, max); //assert(is_ok && min == 14 && max == 16); //is_ok = check(300, 333, 1000, min, max); //assert(is_ok == false); is_ok = check(a, b, w, min, max); if (is_ok) cout << min << " " << max << endl; else cout << "UNSATISFIABLE" << endl; return 0; }
#include<bits/stdc++.h> #define rep(i,n) for(int i = 0; (i) < n;i++) using namespace std; using ll = long long; vector<int> g[200000]; ll A[200000]; ll Max_cost[200000]; ll Find_Max(int u){ if(Max_cost[u] != -1) return Max_cost[u]; ll v = 0; for(int x:g[u]){ v = max({v,A[x],Find_Max(x)}); } Max_cost[u] = v; return Max_cost[u]; } int main(){ int N,M; cin >> N >> M; rep(i,N){ long long v; cin >> v; A[i] = v; } rep(i,M){ int u,v; cin >> u >> v; u--; v--; g[u].push_back(v); } rep(i,N) Max_cost[i] = -1; rep(i,N){ if(Max_cost[i] == -1){ Find_Max(i); } } ll result = - 1000000001; rep(i,N){ /* cout << Max_cost[i] << endl; */ if(Max_cost[i] == 0) continue; ll c = Max_cost[i] - A[i]; result = max(result,c); } cout << result << endl; return 0; }
#define _USE_MATH_DEFIMES #include <algorithm> #include <array> #include <bitset> #include <cassert> #include <cctype> #include <climits> #include <clocale> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <regex> #include <set> #include <sstream> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> const int MOD = 1'000'000'007; const int MOD2 = 998'244'353; const int INF = 1'000'000'000; //1e9 const int NIL = -1; const long long LINF = 1'000'000'000'000'000'000; // 1e18 const long double EPS = 1E-10L; template<class T, class S> inline bool chmax(T &a, const S &b){ if(a < b){a = b; return true;} return false; } template<class T, class S> inline bool chmin(T &a, const S &b){ if(b < a){a = b; return true;} return false; } template<class T, class S> inline bool exist(std::set<T> &s, const S &e){ return (s.find(e) != std::end(s)); } int main(){ int L, R; std::cin >> L >> R; long long ans{}; std::vector<long long> cnt(R+1, 0); for(int g{R}; g >= 2; --g){ long long k{R/g - (L-1)/g}, c{k * k}; for(int i{2*g}; i <= R; i += g){ c -= cnt[i]; } cnt[g] = c; if(std::max(2, L) <= g && g <= R){ c -= 2 * k - 1; } ans += c; } std::cout << ans << std::endl; return 0; }
#include "bits/stdc++.h" using namespace std; typedef long long ll; ll phi[1010000]; void EULERinit() { ll top=1000000; for(int i=2;i<=top;++i)phi[i]=i; for(int i=2;i<=top;++i) { if(phi[i]==i)for(int j=i;j<=top;j+=i)phi[j]-=phi[j]/i; phi[i]+=phi[i-1]; } } ll f1(ll l,ll r){ ll ans=0; for(int i=l;i<=r;i++){ for(int j=l;j<=r;j++){ ll gcd=__gcd(i,j); if(gcd!=1&&gcd!=i&&gcd!=j) ans++; } }return ans; } ll f(ll n){ if(n==0) return 0; ll sum=n*n,cnt=0; for(ll i=2;i<=n;i++){ cnt+=(n/i-1)*2+1; } return sum-cnt-phi[n]*2-1; } const int MAXN = 1000000+10; ll cnt[MAXN]; ll mu[MAXN],prime[MAXN]; ll num[MAXN]; bool vis[MAXN]; int pcnt; /*求解Mobinus函数*/ void Mobinus() { memset(vis,0,sizeof(vis)); pcnt=0; mu[1]=1; for(int i=2;i<MAXN;i++){ if(!vis[i]){ prime[pcnt++]=i; mu[i]=-1; } for(int j=0;j<pcnt&&i*prime[j]<MAXN;j++){ vis[i*prime[j]]=1; if(i%prime[j])mu[i*prime[j]]=-mu[i];//i是素数的情况 else { mu[i*prime[j]]=0; break; } } } } ll Main(ll l,ll r) { Mobinus(); int n=r-l+1; ll Max=-99999999,ans=0; ll a[MAXN]; memset(cnt,0,sizeof(cnt)); memset(num,0,sizeof(num)); for(int i=0;i<n;i++){ a[i]=l+i; Max=max(a[i],Max); } for(int i=0;i<n;i++){ num[a[i]]++; } for(int i=1;i<=Max;i++){ for(int j=i;j<=Max;j+=i) cnt[i]+=num[j]; } for(int i=1;i<=Max;i++){ ans+=(mu[i]*cnt[i]*(cnt[i]-1))>>1; } return ans; } ll ff(ll l,ll r){ ll sum=(r-l+1)*(r-l+1); ll cnt=0; for(ll i=max(2LL,l);i<=r;i++){ cnt+=(r/i-1)*2+1; } //cout<<sum<<" "<<cnt<<" "<<Main(l,r)<<" "<<phi[r]<<endl; if(l>1) return sum-cnt-Main(l,r)*2; else return sum-cnt-phi[r]*2-1; } int main() { ll l,r; EULERinit(); cin>>l>>r; //cout<< f(r) - f(l - 1)<<endl; cout << ff(l,r)<< endl; //cout << f1(l,r) << endl; //cout<<f(l-1)<<endl; return 0; }
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; using pll = pair<ll, ll>; using vl = vector<ll>; using vvl = vector<vl>; using vvvl = vector<vvl>; using pdd = pair<double, double>; using vd = vector<double>; using vvd = vector<vd>; using vvvd = vector<vvd>; using pbb = pair<bool, bool>; using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>; using pss = pair<string, string>; using vs = vector<string>; using vvs = vector<vs>; using vvvs = vector<vvs>; #define repeat(counter, start, goal, step) for (int counter = (int)(start); counter < (int)(goal); counter += step) #define rep(counter, times) repeat(counter, 0, times, 1) #define rep2(counter, start, goal) repeat(counter, start, goal, 1) #define rep0(times) repeat(counter, 0, times, 1) #define rrepeat(counter, start, goal, step) for (int counter = (int)(start); counter > (int)(goal); counter -= step) #define rep3(counter, start, goal) rrepeat(counter, start, goal, 1) #define rrep(counter, start, goal) rrepeat(counter, start - 1, goal - 1, 1) #define all(container) begin(container), end(container) template <typename T> bool chmax(T &x, const T &y) { if (x < y) { x = y; return true; } return false; } template <typename T> bool chmin(T &x, const T &y) { if (x > y) { x = y; return true; } return false; } void yn(bool flag) { cout << (flag ? "yes" : "no") << "\n"; } void Yn(bool flag) { cout << (flag ? "Yes" : "No") << "\n"; } void YN(bool flag) { cout << (flag ? "YES" : "NO") << "\n"; } void set_prec(const int &digits) { cout << fixed << setprecision(digits); cerr << fixed << setprecision(digits); } template <typename T> void pr(const T &obj) { cerr << obj; } template <typename T, typename ...Ts> void pr(const T &first, const Ts &...rest) { pr(first); pr(", "); pr(rest...); } template <typename S, typename T> void pr(const pair<S, T> &pair) { pr("("); pr(pair.first); pr(", "); pr(pair.second); pr(")"); } template <typename T> void pr(const vector<T> &vec) { pr("{"); for (T obj : vec) { pr(obj); pr(", "); } pr("}"); } template <typename T> void pr(const vector<vector<T>> &vv) { pr("\n"); rep(index, vv.size()) { pr("["); pr(index); pr("]: "); pr(vv[index]); pr("\n"); } } template <typename T> void pr(const set<T> &vec) { pr("{"); for (T obj : vec) { pr(obj); pr(", "); } pr("}"); } template <typename S, typename T> void pr(const map<S, T> &map) { pr("{"); for (pair<S, T> pair : map) { pr("("); pr(pair.first); pr(": "); pr(pair.second); pr("), "); } pr("}"); } #define db(obj) cerr << #obj << ": "; pr(obj); cerr << " " #define dl(obj) db(obj); cerr << "\n"; #define dm(...) cerr << "(" << #__VA_ARGS__ << "): ("; pr(__VA_ARGS__); cerr << ") " #define dml(...) dm(__VA_ARGS__); cerr << "\n" // #include <atcoder/all> // using namespace atcoder; // const ll MOD = 1000000007; // const ll MOD = 998244353; int main() { int N, S, D; cin >> N >> S >> D; vi X(N), Y(N); rep(i, N) cin >> X[i] >> Y[i]; bool f = false; rep(i, N) if (X[i] < S && Y[i] > D) f = true; Yn(f); }
#include <bits/stdc++.h> #define REP(i,a,b) for (int i = (a); i <= (b); ++i) using namespace std; const int maxn = 2e5+10; int n, a[maxn], b[maxn], p[maxn]; int pre[maxn]; vector<pair<int,int> > ans; void debug() { printf("p: "); REP(i,1,n) printf("%d%c", p[i], " \n"[i==n]); printf("pre: "); REP(i,1,n) printf("%d%c", pre[i], " \n"[i==n]); } void solve(int i) { int mn = i; vector<int> loop; for (int x = p[i]; x != i; x = p[x]) { if (b[p[x]] < b[p[mn]]) mn = x; } for (int x = pre[mn]; x != mn; x = pre[x]) { ans.push_back(make_pair(x, p[x])); } for (int x = p[i]; x != i; x = p[x]) { loop.push_back(x); } // printf("SOLVE: %d %d\n", i, (int)loop.size()); for (int x = 0; x < (int)loop.size(); ++x) { p[loop[x]] = pre[loop[x]] = loop[x]; } } signed main() { scanf("%d", &n); REP(i,1,n) scanf("%d", a+i); REP(i,1,n) scanf("%d", b+i); REP(i,1,n) scanf("%d", p+i), pre[p[i]] = i; REP(i,1,n) { if (p[i] != i && b[p[i]] >= a[i]) { puts("-1"); return 0; } } REP(i,1,n) if (p[i] != i) solve(i); printf("%d\n", (int)ans.size()); REP(i,0,(int)ans.size()-1) { printf("%d %d\n", ans[i].first, ans[i].second); } }
#line 1 "/workspaces/compro/lib/template.hpp" #line 1 "/workspaces/compro/lib/io/vector.hpp" #include <iostream> #include <vector> #ifndef IO_VECTOR #define IO_VECTOR template <class T> std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) { int size = v.size(); for (int i = 0; i < size; i++) { std::cout << v[i]; if (i != size - 1) std::cout << " "; } return out; } template <class T> std::istream &operator>>(std::istream &in, std::vector<T> &v) { for (auto &el : v) { std::cin >> el; } return in; } #endif #line 4 "/workspaces/compro/lib/template.hpp" #include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; i++) #define FOR(i, m, n) for (int i = m; i < n; i++) #define ALL(v) (v).begin(), (v).end() #define coutd(n) cout << fixed << setprecision(n) #define ll long long int #define vl vector<ll> #define vi vector<int> #define MM << " " << using namespace std; template <class T> void chmin(T &a, T b) { if (a > b) a = b; } template <class T> void chmax(T &a, T b) { if (a < b) a = b; } // 重複を消す。計算量はO(NlogN) template <class T> void unique(std::vector<T> &v) { std::sort(v.begin(), v.end()); v.erase(std::unique(v.begin(), v.end()), v.end()); } #line 2 "main.cpp" long long solve(const vl &base, const vl &v1, const vl &v2) { // v1, v2でminを見る ll ans = 1e18; int len1 = v1.size(); REP(i, len1) { auto idx = lower_bound(ALL(v2), v1[i]) - v2.begin(); chmin(ans, abs(v1[i] - v2[idx])); if (idx > 0) { chmin(ans, abs(v1[i] - v2[idx - 1])); } } // baseをはさむ int lenb = base.size(); ll bv1 = 1e18, bv2 = 1e18; if (lenb == 0) { return ans; } REP(i, lenb) { // dp1の更新 auto idx = lower_bound(ALL(v1), base[i]) - v1.begin(); if (idx < v1.size()) chmin(bv1, abs(base[i] - v1[idx])); if (idx > 0) { chmin(bv1, abs(base[i] - v1[idx - 1])); } } REP(i, lenb) { // dp2の更新 auto idx = lower_bound(ALL(v2), base[i]) - v2.begin(); if (idx < v2.size()) chmin(bv2, abs(base[i] - v2[idx])); if (idx > 0) { chmin(bv2, abs(base[i] - v2[idx - 1])); } } chmin(ans, bv1 + bv2); return ans; } // generated by online-judge-template-generator v4.7.1 (https://github.com/online-judge-tools/template-generator) int main() { int N; std::cin >> N; vl r, g, b; REP(i, 2 * N) { ll a; char c; cin >> a >> c; if (c == 'R') { r.push_back(a); } else if (c == 'G') { g.push_back(a); } else { b.push_back(a); } } sort(ALL(r)); sort(ALL(g)); sort(ALL(b)); int cr, cg, cb; cr = r.size(); cg = g.size(); cb = b.size(); if (cr % 2 == 0 && cb % 2 == 0 && cg % 2 == 0) { cout << 0 << endl; } else if (cr % 2 == 0) { cout << solve(r, g, b) << endl; } else if (cg % 2 == 0) { cout << solve(g, r, b) << endl; } else if (cb % 2 == 0) { cout << solve(b, r, g) << endl; } else { assert(false); } return 0; }
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <sys/types.h> #include <unistd.h> #include <vector> #pragma region macros #define _overload(_1, _2, _3, name, ...) name #define _rep(i, n) _range(i, 0, n) #define _range(i, a, b) for (int i = int(a); i < int(b); ++i) #define rep(...) _overload(__VA_ARGS__, _range, _rep, )(__VA_ARGS__) #define _rrep(i, n) _rrange(i, n, 0) #define _rrange(i, a, b) for (int i = int(a) - 1; i >= int(b); --i) #define rrep(...) _overload(__VA_ARGS__, _rrange, _rrep, )(__VA_ARGS__) #pragma endregion macros using namespace std; template <class T> bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; } template <class T> bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; } using ll = long long; using R = long double; const R EPS = 1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7 inline int sgn(const R &r) { return (r > EPS) - (r < -EPS); } inline R sq(R x) { return sqrt(max(x, 0.0L)); } const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; const pid_t pid = getpid(); // Problem Specific Parameter: int main(void) { int n, m; cin >> n >> m; vector<int> w(n); rep(i, n) cin >> w[i]; vector<int> l(m), v(m); rep(i, m) { cin >> l[i] >> v[i]; } const int wmax = *max_element(begin(w), end(w)); rep(i, m) { if (wmax > v[i]) { cout << -1 << endl; return 0; } } using pii = pair<int, int>; vector<pii> bridge; rep(i, m) { bridge.push_back(pii(v[i], l[i])); } sort(begin(bridge), end(bridge)); rep(i, 1, m) { chmax(bridge[i].second, bridge[i - 1].second); } bridge.erase(unique(begin(bridge), end(bridge)), end(bridge)); m = bridge.size(); // rep(i, m) { // cerr << bridge[i].first << " " << bridge[i].second << endl; // } vector<int> ary(n); iota(begin(ary), end(ary), 0); const ll inf = 1LL << 30; ll ans = inf; do { ll dist[8][8]; rep(i, n) rep(j, n) { dist[i][j] = (i == j) ? 0 : inf; } // d_i <= d_{i + 1} rep(i, n - 1) { dist[i + 1][i] = 0; } rep(f, n) rep(t, f + 1, n) { int cur = 0; rep(i, f, t + 1) { cur += w[ary[i]]; } auto it = lower_bound(begin(bridge), end(bridge), pii(cur, 0)); if (it != begin(bridge)) { const int tar = prev(it)->second; chmin<ll>(dist[t][f], -tar); } } rep(k, n) rep(i, n) rep(j, n) { chmin(dist[i][j], dist[i][k] + dist[k][j]); } // cerr << "Dist:" << endl; // cerr << dist[0][n - 1] << endl; // cerr << dist[n - 1][0] << endl; chmin(ans, -dist[n - 1][0]); } while (next_permutation(begin(ary), end(ary))); cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)n;i++) #define rep1(i,n) for(int i=1;i<=(int)n;i++) #define sp(n) cout << fixed << setprecision(n) 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 ll; using namespace std; int main(void){ ll a,b;cin>>a>>b; for(ll res=b;res>=1;res--){ ll buf=(a+res-1)/res; ll buf1=buf*res,buf2=(buf+1)*res; if((a<=buf1&&buf1<=b)&&(a<=buf2&&buf2<=b)){ cout<<res<<endl; return 0; } } }
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 #define ll long long typedef pair<ll, ll> ii; typedef vector<ll> vi; typedef vector<bool> vb; typedef vector<vi> vvi; typedef vector<ii> vii; typedef vector<vii> vvii; #define pq priority_queue #define ff first #define ss second #define pb push_back #define tc int t; cin>>t; while(t--) #define file_read(x,y) freopen(x, "r", stdin); \ freopen(y, "w", stdout); int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); double a,b; cin >> a >> b; cout << setprecision(9) << (a - b) / (double) a * 100 << "\n"; }
#include <cstdio> #include <map> typedef long long LL; LL x, y; std::map<LL, LL> mp; inline LL abs_(LL x) { return x < 0 ? -x : x; } inline LL min_(LL a, LL b, LL c) { return a > b ? (b > c ? c : b) : (a > c ? c : a); } inline LL min_(LL a, LL b) { return a > b ? b : a; } LL solve(LL t) { if(mp[t]) return mp[t]; else if(t == 1) return mp[t] = abs_(x - t); else if(t & 1) return mp[t] = min_(abs_(x - t), solve((t + 1) / 2) + 2, solve((t - 1) / 2) + 2); else return mp[t] = min_(abs_(x - t), solve(t / 2) + 1); } int main() { std::scanf("%lld%lld", &x, &y); std::printf("%lld\n", solve(y)); return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int x,y; cin >> x >> y; int ans=0; if(x==y){ ans=x; }else{ ans=3-x-y; } cout << ans <<endl; }
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; #define all(x) (x).begin(), (x).end() #define dbl(k, x) fixed << setprecision(k) << (x) template <typename _T> inline void _DBG(const char *s, _T x) { cerr << s << " = " << x << "\n"; } template <typename _T, typename... args> void _DBG(const char *s, _T x, args... a) { while (*s != ',') cerr << *s++; cerr << " = " << x << ','; _DBG(s + 1, a...); } #define _upgrade \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__) // ********************** CODE ********************** // long long go(long long sum, long long del, long long n) { if (n == 0) { if (sum != 0 && sum % 3 == 0) { return del; } else { return 1e18; } } int last = n % 10; n /= 10; return min(go(sum + last, del, n), go(sum, del + 1, n)); } int main() { _upgrade; long long n; cin >> n; long long res = go(0LL, 0LL, n); cout << (res == 1e18 ? -1 : res) << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define fi first #define se second #define int long long int #define pii pair<int,int> const int INF= 1e12; const int MAX=5e6+5; const int MAXK=105; const int mod = 1e9+7; int gcd(int a, int b) { while(b!=0) { a=a%b; swap(a,b); } return a; } int binpow(int a,int b) { int res=1; while(b>0) { if(b%2==1) res=res*a%mod; a=a*a%mod; b/=2; } return res; } /* * check modulus when using binpow */ void solve() { double val = 1.08; int n; cin>>n; val=floor(val*n); //cout<<val<<"\n"; if(val<206) { cout<<"Yay!"; } else if(val==206) { cout<<"so-so"; } else { cout<<":("; } } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif // ONLINE_JUDGE int t=1; //cin>>t; for(int i=1;i<=t;i++) { //cout<<"Case #"<<i<<": "; solve(); } }
#include<iostream> #include<string> #include<algorithm> #include<vector> #include<queue> #include<set> #include<cmath> #include<iomanip> #define pi 3.14159265358979323846 #define mod 1000000007 #define int long long #define elif else if #define rep(i, a, n) for(int i = a; i < n; i++) using namespace std; signed main(){ int n, m = 0, t = 0; double y = 0; cin >> n; rep(i, 0, n){ int k; cin >> k; if(k < 0){ k *= (-1); } m += k; if(k > t){ t = k; } y += k * k; } y = sqrt(y); cout << m << "\n" << setprecision(20) << y << "\n" << t << "\n"; }
/*#pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") */ #include<bits/stdc++.h> using namespace std; void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif #define ll long long #define f first #define s second #define Fast ios_base::sync_with_stdio(false);cin.tie(NULL); typedef pair<ll , pair<ll, ll> > pi; int pow(int x,int y){ int res=1; while(y){ if(y&1) res*=x; y>>=1; x*=x; } return res; } struct Compare { constexpr bool operator()(pi const & a, pi const & b) const noexcept { return a.first < b.first || (a.first == b.first && a.second.first > b.second.first); } }; void prefix_function( string s,ll arr[] ) { long long border=0; arr[0]=0; for(long long i=1;i<s.size();i++) { while(border>0 && s[i]!=s[border]) border=arr[border-1]; if(s[i]==s[border]) border++; else border=0; arr[i]=border; } }//send mod-2 for a^-1 if mod is a prime number ll mod=998244353; ll add( ll a , ll b) { return (((a%mod)+(b%mod))%mod); } ll mul(ll a,ll b) { return (((a%mod)*(b%mod))%mod); } ll binpow(ll a, ll b) { ll res = 1; while (b) { if (b & 1) res = mul(res, a); a = mul(a, a); b >>= 1; } return res; } ll subs(ll a,ll b) { return (((a%mod)-(b%mod)+mod)%mod); } ll dv(ll a,ll b) { ll inv=binpow(b,mod-2); return mul(a,inv); } ll dsu_arr[100000]; ll dsu_sz[100000]; void dsu(ll n) { for(ll i=0;i<=n;i++) { dsu_arr[i]=i; dsu_sz[i]=1; } } ll find(ll x) { ll root=x; while (root!=dsu_arr[root]) { root=dsu_arr[root]; } while(x!=dsu_arr[x]) { dsu_arr[x]=root; x=dsu_arr[x]; } return root; } ll merge(ll x,ll y) { ll root1=find(x); ll root2=find(y); if(root1==root2) return 0ll; if(dsu_sz[x]>dsu_sz[y]){ dsu_arr[root2]=root1; dsu_sz[root1]+=dsu_sz[root2]; } else { dsu_sz[root2]+=dsu_sz[root1]; dsu_arr[root1]=root2; } return 1ll; } /* vector<ll>adj[100005]; bool vis[100005]; ll dist[100005]; void bfs(ll c) { vis[c]=true; dist[c]=0; queue<ll>q; q.push(c); while(!q.empty()) { ll x=q.front(); q.pop(); for(ll i=0;i<adj[x].size();i++) { ll y=adj[x][i]; if(!vis[y]) { vis[y]=true; dist[y]=dist[x]+1; q.push(y); } } } } */ int main() { Fast ll test; ll n; cin>>n; double b=0; ll a=0,c=0; for(ll i=0;i<n;i++) { ll k; cin>>k; a+=abs(k); c=max(c,abs(k)); b+=(k*k); } double d=sqrt(b*1.00); cout<<setprecision(15)<<fixed; cout<<a<<'\n'<<d<<'\n'<<c<<endl; }
#include <iostream> #include <algorithm> using namespace std; const int N = 1e6 + 1; long long pre[N],a[N]; int n; int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) a[i] = a[i - 1] + a[i]; for (int i = 1; i <= n; i++) pre[i] = pre[i - 1] + a[i]; long long res = 0 , value = 0; for (int i = 1; i <= n; i++){ value = max(value,a[i]); res = max(res,pre[i - 1] + value); } cout << res; return 0; }
/* Solved by sid2104 on 11/11/2020 22:32 */ #include <bits/stdc++.h> using namespace std; #define int long long #define float long double #define pb push_back #define ld long double #define f(i,a,b) for(int i=a;i<b;i++) #define mp make_pair #define pii pair<int,int> #define vi vector<int> #define vpii vector<pair<int,int> > #define mii map<int,int> #define all(a) (a).begin(),(a).end() #define debug(x) cout<<#x<<" is "<<(x)<<endl;cout.flush(); //#define debug(x) ; //#define debug(x) ; // === Debug macro starts here === int recur_depth = 0; #ifdef DEBUG #define dbg(x) {++recur_depth; auto x_=x; --recur_depth; cerr<<string(recur_depth, '\t')<<"\e[91m"<<__func__<<":"<<__LINE__<<"\t"<<#x<<" = "<<x_<<"\e[39m"<<endl;} #else #define dbg(x) #endif template<typename Ostream, typename Cont> typename enable_if<is_same<Ostream,ostream>::value, Ostream&>::type operator<<(Ostream& os, const Cont& v){ os<<"["; for(auto& x:v){os<<x<<", ";} return os<<"]"; } template<typename Ostream, typename ...Ts> Ostream& operator<<(Ostream& os, const pair<Ts...>& p){ return os<<"{"<<p.first<<", "<<p.second<<"}"; } // === Debug macro ends here === #define mp make_pair #define x first #define y second #define pb push_back #define endl '\n' #define si(x) (int)((x).size()) #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define txt freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #define elasped_time 1.0 * clock() / CLOCKS_PER_SEC #define tree vector<vector<int> > #define PI 3.14159265358979323846 int inf=99999999999; const int mod=1e9+7; const int cmp=1e17; inline int gcd(int a, int b) { while (a > 0 && b > 0) { if (a > b) a %= b; else b %= a; } return a + b; } void inp(int n,int arr[]) { f(i,0,n) cin>>arr[i]; } int ans=0; void solve() { int sum=0; int curr=0; int currm=0; int n; cin>>n; f(i,0,n) { int k; cin>>k; curr+=k; currm=max(curr,currm); ans=max(ans,sum+currm); sum+=curr; } cout<<ans<<endl; } main() { IOS; solve(); }
#include <bits/stdc++.h> using namespace std; #define ll long long #define pll pair<ll, ll> #define pii pair< #define fi first #define se second #define pb push_back const int N = 2002; const ll mod = 1e12+7; ll m, n, t, k, a[N], ans, b[N], d[N], tong, idx, mn, c[N]; vector< pll > adj[N], adt[N]; vector<ll> kq, v; string s; void check(ll x) { if(kq.empty())return; vector<ll> pre, res; for(int i = 0; i < kq.size(); i ++) { if(a[kq[i]] >= x)pre.pb(kq[i]); } swap(kq, pre); if(kq.empty())return; priority_queue< ll, vector<ll>, greater<ll> > pq; pq.push(a[kq[0]]); for(int i = 1; i < kq.size(); i ++) { if(kq[i] == kq[i-1] + 1)pq.push(a[kq[i]]); else { while(pq.size() >= k) { res.pb(pq.top()); pq.pop(); } while(!pq.empty())pq.pop(); pq.push(a[kq[i]]); } } while(pq.size() >= k) { res.pb(pq.top()); pq.pop(); } if(res.size() < m)return; sort(res.begin(), res.end()); ans = min(ans, res[m-1] - res[0]); } void sol() { cin >> n; for(int i = 1; i <= n; i ++) { cin >> a[i]; if(a[i] < 1 || a[i] > n) { cout << "No"; return; } ++b[a[i]]; } for(int i = 1; i <= n; i ++) { if(b[i] != 1) { cout << "No"; return; } } cout << "Yes"; } int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); sol(); } /* nC1 * (m-1)^(i-1) + */
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ll N; cin >> N; vector<ll> A(N); for (int i=0; i<N; i++) { cin >> A[i]; } sort(A.begin(), A.end()); for (int i=1; i<N; i++) { if ((A[0] == 1) && (A[i-1] + 1 == A[i])) { // Do nothing } else { cout << "No" << endl; return 0; } } cout << "Yes" << endl; }
// #define _GLIBCXX_DEBUG // for STL debug (optional) #include <iostream> #include <iomanip> #include <cstdio> #include <string> #include <cstring> #include <deque> #include <list> #include <queue> #include <stack> #include <vector> #include <utility> #include <algorithm> #include <map> #include <set> #include <complex> #include <cmath> #include <limits> #include <cfloat> #include <climits> #include <ctime> #include <cassert> #include <numeric> #include <fstream> #include <functional> #include <bitset> using namespace std; using ll = long long int; using int64 = long long int; template<typename T> void chmax(T &a, T b) {a = max(a, b);} template<typename T> void chmin(T &a, T b) {a = min(a, b);} template<typename T> void chadd(T &a, T b) {a = a + b;} int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; const int INF = 1LL << 29; const ll LONGINF = 1LL << 60; const ll MOD = 1000000007LL; int main() { int N; cin >> N; string s, t; cin >> s >> t; ll pari_1 = 0, pari_2 = 0; for(int i=0; i<N; i++) { if(s[i] == '0') pari_1++; if(t[i] == '0') pari_2++; } // 0 の個数について S のほうがおおい if(pari_1 > pari_2) { puts("-1"); return 0; } pari_1 %= 2; pari_2 %= 2; // 偶奇があってない if(pari_1 != pari_2) { puts("-1"); return 0; } // 貪欲にマッチさせる vector<int> js; for(int i=0; i<N; i++) if(t[i] == '1') js.emplace_back(i); int M = js.size(); ll ans = 0, pre = -1, j = 0; for(int i=0; i<N; i++) { if(s[i] == '0') continue; // T 側の 1 とマッチ if(j < M and js[j] <= i) { ans += i - js[j++]; } else { // まだ存在しない if(pre < 0) pre = i; else { // 存在するのでマッチさせる ans += i - pre; pre = -1; } } } // 最後までマッチしていない if(j != M or pre >= 0) puts("-1"); else printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; const int max_n = 505555, inf = 1000111222; char buf[max_n]; string read() { scanf("%s", buf); return buf; } int n; string s, t; void wa() { puts("-1"); exit(0); } int main() { //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); scanf("%d", &n); s = read(); t = read(); vector<int> a, b; for (int i = 0; i < n; ++i) { if (s[i] == '1') { a.push_back(i); } if (t[i] == '1') { b.push_back(i); } } if (a.size() % 2 != b.size() % 2) { wa(); } long long ans = 0; int pos = 0; for (int i : b) { while (pos < a.size() && a[pos] < i) { ans += a[pos + 1] - a[pos]; //cout << "$" << a[pos] << " " << a[pos + 1] << endl; pos += 2; } if (pos >= a.size()) { wa(); } //cout << "@" << a[pos] << " " << i << endl; ans += a[pos] - i; ++pos; ++i; } if (pos % 2 != a.size() % 2) { wa(); } while (pos < a.size()) { ans += a[pos + 1] - a[pos]; pos += 2; } cout << ans << "\n"; return 0; }
#include <iostream> #include <algorithm> #include <string> #include <vector> #include <set> #include <cmath> #include <stdio.h> #include <list> #include <numeric> #include <stack> #include <queue> #include <tuple> #include <bitset> #include <map> #include <math.h> #include <cstring> //ceil(a/b) (a + (b - 1))/ b using namespace std; #define rep(i,n) for(int i = 0; i < (n); i++) typedef long long ll; typedef pair<int,int> P; const int inf=1000000007; const int mod=1e9 + 7; const double PI=3.14159265358979323846; int dx[] = {1,-1,0,0}; int dy[] = {0,0,1,-1}; int cans(bool f){ if(f) cout << "Yes" << endl; else cout << "No" << endl; return 0; } int main() { int H,W; cin >> H >> W; char S[H][W]; rep(i,H) { rep(j,W) { cin >> S[i][j]; } } int ans = 0; rep(i,H-1) { rep(j,W-1) { int num = 0; if(S[i][j] == '#') num++; if(S[i][j+1] == '#') num++; if(S[i+1][j] == '#') num++; if(S[i+1][j+1] == '#') num++; if(num == 1 || num == 3) ans++; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=(0);i<(n);i++) using namespace std; typedef long long ll; template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } bool check(vector<char> v){ int cnt = count(v.begin(),v.end(), '.'); return cnt % 2 == 1; } int main(){ cin.tie(0); ios::sync_with_stdio(false); int h, w; cin >> h >> w; vector<string> b(h); rep(i, h) cin >> b[i]; int ans = 0; rep(i, h-1) rep(j, w-1){ if(check({b[i][j], b[i][j+1], b[i+1][j], b[i+1][j+1]})) ans++; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define FOR(i, m, n) for (int i = (m); i < (int)(n); i++) int solve(string S) { if ("atcoder" < S) { return 0; } rep(i, S.size()) { if (S[i] > 't') { return i - 1; } else if (S[i] > 'a') { return i; } } return -1; } int main() { int T; cin >> T; rep(i, T) { string S; cin >> S; cout << solve(S) << endl; } }
#include<bits/stdc++.h> #define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i) #define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i) #define foreach(i, n) for(auto &i:(n)) #define all(x) (x).begin(), (x).end() #define bit(x) (1ll << (x)) #define lambda(RES_TYPE, ...) (function<RES_TYPE(__VA_ARGS__)>)[&](__VA_ARGS__) -> RES_TYPE #define method(FUNC_NAME, RES_TYPE, ...) function<RES_TYPE(__VA_ARGS__)> FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__) using namespace std; using ll = long long; using pii = pair<int,int>; using pll = pair<ll,ll>; //const ll MOD = (ll)1e9+7; const ll MOD = 998244353; const int INF = (ll)1e9+7; const ll INFLL = (ll)1e18; template<class t> using vvector = vector<vector<t>>; template<class t> using vvvector = vector<vector<vector<t>>>; template<class t> using priority_queuer = priority_queue<t, vector<t>, greater<t>>; template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;} template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;} #ifdef DEBUG #define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl; #else #define debug(x) (void)0 #endif namespace templates{ ll modpow(ll x, ll b){ ll res = 1; while(b){ if(b&1)res = res * x % MOD; x = x * x % MOD; b>>=1; } return res; } ll modinv(ll x){ return modpow(x, MOD-2); } bool was_output = false; template<class t> void output(t a){ if(was_output)cout << " "; cout << a; was_output = true; } void outendl(){ was_output = false; cout << endl; } ll in(){ ll res; scanf("%lld", &res); return res; } template<class t> istream& operator>>(istream&is, vector<t>&x){ for(auto &i:x)is >> i; return is; } template<class t, class u> istream& operator>>(istream&is, pair<t, u>&x){ is >> x.first >> x.second; return is; } template<class t> t in(){ t res; cin >> res; return res; } template<class t> void out(t x){ cout << x; } template<class t> vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){ sort(line.begin(),line.end(),comp); return line; } template<class t> vector<t> reversed(vector<t> line){ reverse(line.begin(),line.end()); return line; } } using namespace templates; ll func(){ string str = in<string>(); int res = INF; string atcoder = "atcoder"; if(str > atcoder)return 0; rep(i,min<int>(str.size(),atcoder.size())){ rep(j,str.size()){ if(i==j)continue; swap(str[i],str[j]); if(atcoder < str.substr(0,min<int>(str.size(),atcoder.size()+1)))chmin(res,abs(i-j)); swap(str[i],str[j]); } } if(res==INF)return -1; return res; } int main(){ int n = in(); rep(i,n){ cout << func() << endl; } return 0; }
#include<iostream> #include<math.h> #include<bits/stdc++.h> #include<queue> #include<cstdio> #include<vector> #include<algorithm> #include<string> #define rep(i,n) for (int i=0;i<(n);++i) using ll = long long; using namespace std; using P = pair<int,int>; #define INF 110000 int main(){ ll a,b,c,d; cin>>a>>b>>c>>d; if(b - (c*d) >= 0){ cout<<-1<<endl; return 0; } d = (c*d)-b; int count = 0; if(a%d == 0) count = a/d; else count = (a/d) + 1; cout<<count<<endl; return 0; }
#define MOD_TYPE 2 #pragma region Macros #include <bits/stdc++.h> using namespace std; #if 0 #include <boost/multiprecision/cpp_int.hpp> #include <boost/multiprecision/cpp_dec_float.hpp> using Int = boost::multiprecision::cpp_int; using lld = boost::multiprecision::cpp_dec_float_100; #endif #if 1 #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #endif using ll = long long int; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; using pld = pair<ld, ld>; template <typename Q_type> using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>; constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353); constexpr int INF = (int)1e9 + 10; constexpr ll LINF = (ll)4e18; constexpr ld PI = acos(-1.0); constexpr ld EPS = 1e-8; constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0}; constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0}; #define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i) #define rep(i, n) REP(i, 0, n) #define REPI(i, m, n) for (int i = m; i < (int)(n); ++i) #define repi(i, n) REPI(i, 0, n) #define MP make_pair #define MT make_tuple #define YES(n) cout << ((n) ? "YES" : "NO") << "\n" #define Yes(n) cout << ((n) ? "Yes" : "No") << "\n" #define possible(n) cout << ((n) ? "possible" : "impossible") << "\n" #define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n" #define all(v) v.begin(), v.end() #define NP(v) next_permutation(all(v)) #define dbg(x) cerr << #x << ":" << x << "\n"; struct io_init { io_init() { cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(30) << setiosflags(ios::fixed); }; } io_init; template <typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } inline ll CEIL(ll a, ll b) { return (a + b - 1) / b; } template <typename A, size_t N, typename T> inline void Fill(A (&array)[N], const T &val) { fill((T *)array, (T *)(array + N), val); } template <typename T, typename U> constexpr istream &operator>>(istream &is, pair<T, U> &p) noexcept { is >> p.first >> p.second; return is; } template <typename T, typename U> constexpr ostream &operator<<(ostream &os, pair<T, U> &p) noexcept { os << p.first << " " << p.second; return os; } #pragma endregion // -------------------------------------- void solve() { int n; cin >> n; vector<ld> a(n); rep(i, n) cin >> a[i]; auto f = [&](const ld x) { ld sum = 0; rep(i, n) { sum += x + a[i] - min(a[i], x * 2); } return sum / n; }; auto ternary_search = [&]() { ld left = 0, right = LINF; rep(simulate_times, 300) { ld t1 = (2.0 * left + right) / 3.0; ld t2 = (left + 2.0 * right) / 3.0; if (f(t1) > f(t2)) left = t1; else right = t2; } return f(left); }; cout << ternary_search() << "\n"; } int main() { solve(); }
#include<cstdio> #include<algorithm> using namespace std; int main(void) { int a,b,c; scanf("%d%d%d",&a,&b,&c); if(a*a+b*b<c*c) printf("Yes\n"); else printf("No\n"); return 0; }
#include<bits/stdc++.h> #define endl '\n' using namespace std; const int mod=1e9+7; //Note: // 1.Perform binary search on sorted array only. // 2.For ceil caculations we can use something like ceil(10/(double)3)-->>4 #define ff first #define ss second #define pb push_back #define int long long #define MOD 1000000007 #define mod 1000000007 #define mod2 998244353 #define inf 1e18 #define ps(x,y) fixed<<setprecision(y)<<x #define ll long long #define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); const int N = 200005; bool myCompare(int a,int b) { return a>b; } bool isPrime(int n) { if (n <= 1) return false; for (int i = 2; i*i<= n; i++) if (n % i == 0) return false; return true; } bool isPalindrome(string str) { int l = 0; int h = str.length() - 1; while (h > l) { if (str[l++] != str[h--]) { return false; } } return true; } vector<bool>prime(N + 1,true); void SieveOfEratosthenes(int n) { // memset(prime, true, sizeof(prime)); prime[0]=prime[1]=false; for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) prime[i] = false; } } } int power(int x, unsigned int y) { int res = 1; // Initialize result while (y > 0) { // If y is odd, multiply x with result if (y & 1) res = res*x%mod; // y must be even now y = y>>1; // y = y/2 x = x*x % mod; // Change x to x^2 } return res%mod; } ll fastModuloExponentiation(ll a,ll b,ll M) { ll result=1; while(b>0){ if(b&1){ result=(result*a)%M;} a=(a*a)%M; b=b>>1; } return result; } int modInv(int a){return power(a,MOD-2);} int fact[N],inv[N]; void factorial(int n){ fact[0]=1; for(int i=1;i<=n;i++){ fact[i]=fact[i-1]*i; if(fact[i]>=MOD) fact[i]%=MOD; } } void InvFactorial(int n){ inv[0]=1; for(int i=1;i<=n;i++) inv[i]=modInv(fact[i]); } int ncr(int n,int r){ if(n<r||n<0||r<0) return 0; int b=inv[n-r]; int c=inv[r]; int a=fact[n]*b; if(a>=MOD) a%=MOD; a*=c; if(a>=MOD) a%=MOD; return a; } void solve() { int a,b,c; cin>>a>>b>>c; int x=a*a; int y=b*b; int z=c*c; // cout<<x<<" "<<y<<" "<<z; if((x+y)<z) cout<<"Yes"; else cout<<"No"; } signed main() { ios; int test; test=1; int tc=1; // factorial(N-1); // InvFactorial(N-1); // SieveOfEratosthenes(N-1); // cin>>test; while(test--) { //cout<<"Case #"<<tc<<": "; solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main(){ double a, b; cin >> a >> b; double c = 100*b/a; cout << 100-c << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(ll i = 0; i < (n); ++i) #define repA(i, a, n) for(ll i = a; i < (n); ++i) #define repD(i, a, n) for(ll i = a; i > (n); --i) #define trav(a, x) for(auto& a : x) #define all(x) x.begin(), x.end() #define sz(x) (long long) (x).size() #define fill(a) memset(a, 0, sizeof(a)) #define fst first #define snd second // #define mp make_pair #define pb push_back void __print(int x) {cout << x;} void __print(long x) {cout << x;} void __print(long long x) {cout << x;} void __print(unsigned x) {cout << x;} void __print(unsigned long x) {cout << x;} void __print(unsigned long long x) {cout << x;} void __print(float x) {cout << x;} void __print(double x) {cout << x;} void __print(long double x) {cout << x;} void __print(char x) {cout << '\'' << x << '\'';} void __print(const char *x) {cout << '\"' << x << '\"';} void __print(const string &x) {cout << '\"' << x << '\"';} void __print(bool x) {cout << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';} template<typename T> void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";} void _print() {cout << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define dbg(x...) cout << "[" << #x << "] = ["; _print(x) #else #define dbg(x...) #endif const long double PI = 3.141592653589793238462643383; typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<long long int> vll; typedef vector<double> vd; typedef vector<pii> vii; long long Ceil(long long a, long long b){ if(a%b==0) return a/b; else return (a/b)+1; } ll p=1000000007; // ll p = 1000000000000000000+5; float E = 0.00000000000001; ll power(ll x, ll y){ if(y==0){ return 1; } if(y%2==0){ ll q=power(x,y/2); q=q%p; return (q*q)%p; } ll q=power(x,y/2); q=q%p; return ((x%p)*((q*q)%p))%p; } bool isPowerOfTwo (long long x) { /* First x in the below expression is for the case when x is 0 */ return x && (!(x&(x-1))); } long long int gcd(long long int a, long long int b){ if (a == 0) return b; return gcd(b % a, a); } long long int mod(long long int a, long long int b) { long long int ret = a%b; return ret>=0? ret: ret+b; } int main(){ std::ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t = 1; // cin>>t; while(t--){ float a,b; cin>>a>>b; std::cout << std::fixed << std::setprecision(2); cout<<abs((b/a-1)*100); } return 0; }
#include<bits/stdc++.h> #define ll long long #define ld long double #define pb push_back #define mp make_pair #define fi first #define se second #define REP(i,j) for(int i=0;i<j;i++) #define REPA(i,j) for(int i=1;i<=j;i++) #define FORN(i,j,k) for(int i=j;i<k;i++) #define vi vector<int> #define vvi vector<vi > #define pii pair<int,int> #define vpii vector<pii > #define all(a) a.begin(),a.end() using namespace std; const int INF=1<<30; inline void read(ll &x){ // short neg=1; x=0; char c=getchar(); /*while(c<'0'||c>'9'){ if(c=='-')neg=-1; c=getchar(); }*/ while(c>='0'&&c<='9'){ x=(x<<3)+(x<<1)+(c^48),c=getchar(); } // x*=neg; } ll f(ll n,ll m){ if(n==0)return 1; if(n&1)return 10*f(n-1,m)%m; else{ ll k=f(n/2,m); return k*k%m; } } ll n,m; int main(void){ read(n); read(m); ll A=f(n,m); ll B=f(n,m*m); printf("%lld",(B-A)/m); return 0; }
/* ______________________ _______ _______ _______ _______ ( ____ \__ __( __ \ ( ____ | ___ | ____ ( ___ ) | ( \/ ) ( | ( \ ) | ( )| ( ) | ( \/ ( ) | | (_____ | | | | ) | | (____)| (___) | (_____| (___) | (_____ ) | | | | | | | __) ___ (_____ ) ___ | ) | | | | | ) | | (\ ( | ( ) | ) | ( ) | /\____) |__) (__| (__/ ) | ) \ \_| ) ( /\____) | ) ( | \_______)_______(______/___|/ \__// \_______)/ \| (_____) I didn't come this far to only come this far */ #include <bits/stdc++.h> using namespace std; #define int long long int #define pb push_back #define mp make_pair #define fl(i, a, b) for (int i = a; i < b; i++) #define vi vector<int> #define e1(a) \ int a; \ cin >> a; #define e2(a, b) \ int a, b; \ cin >> a >> b; #define e3(a, b, c) \ int a, b, c; \ cin >> a >> b >> c; #define av(arr, n) \ vector<int> arr(n); \ fl(i, 0, n) cin >> arr[i]; #define aa(arr, n) \ int arr[n]; \ fl(i, 0, n) cin >> arr[i]; #define es(s) \ string(s); \ cin >> (s); #define rz resize #define sz(s) s.size() #define mod 1000000007 #define ff first #define ss second #define tn -10e15 #define bg 10e15 #define all(x) (x).begin(), (x).end() #define pii pair<int, int> #define mii map<int, int> #define st(a, n) memset(a, n, sizeof(a)) #define vl(n) cout << n << "\n" #define vs(n) cout << n << " " #define el cout << "\n" #define vn(n) cout << n #define dsc greater<int>() #define ps(x, y) fixed << setprecision(y) << x #define R return #define B break #define C continue #define YC cout << "YES" \ << "\n" #define YS cout << "Yes" \ << "\n" #define NC cout << "NO" \ << "\n" #define NS cout << "No" \ << "\n" #define lcm(a, b) (a / __gcd(a, b)) * b #define pa(a) \ for (auto e : a) \ cout << e << " " const int N = 4e5 + 5; // Twist the ques // tweek well know algos // if(eq)try to simplify // Read the statements carefully void solve() { e2(n, m); int a[n][m]; int mx = bg; fl(i, 0, n) { fl(j, 0, m) { cin >> a[i][j]; mx = min(a[i][j], mx); } } int ans = 0; fl(i, 0, n) { fl(j, 0, m) { ans += a[i][j] - mx; } } vl(ans); } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); return 0; }
#include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; if (a == b && a != c) cout << c << endl; else if (a == c && a != b) cout << b << endl; else if (b == c && b != a) cout << a << endl; else if (a != b && b != c) cout << "0" << endl; else if(a == b && b == c) cout << a << endl; }
#include <iostream> #include <vector> using namespace std; int main(void){ // Your code here! int A,B,W; vector<int> candi; scanf("%d %d %d",&A,&B,&W); W = W * 1000; if(W%B == 0 && W/B<=W/A) printf("%d %d\n", W/B, W/A); else if(W/B+1<=W/A) printf("%d %d\n", W/B+1,W/A); else printf("UNSATISFIABLE\n"); }
#include<iostream> using namespace std; int main(){ int N; cin >> N; if(N%2==0)cout << "White" << endl; if(N%2==1)cout << "Black" << endl; return 0; }
// --------------------------------------------------<C++ TEMPLATE>------------------------------------------------ /** * Nitin Gangwar * @wargang (codechef,codeforces,spoj,gfg) * MNNIT allahabad * CSE'23 * [email protected] **/ #include <bits//stdc++.h> using namespace std; // MACROS #define int long long #define mp make_pair #define pb push_back #define MAX 1e9 #define MIN -1e9 #define PI 3.1415926535897932384626433832795 #define mod 1000000007 #define set(x) memset(x, 0, sizeof(x)) #define clr(x) memset(x, -1, sizeof(x)) #define ff first #define ss second #define rep(i,n) for(int i=0;i<(n);i++) #define FOR(i,a,b) for(int i=(a);i<=(b);i++) #define FORD(i,a,b) for(int i=(a);i>=(b);i--) #define test() int t;cin>>t;while(t--) #define endl "\n" typedef priority_queue<int> maxHeap; typedef priority_queue<int, vector<int>, greater<int>> minHeap; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<string> vs; typedef vector<pii> vpii; typedef vector<vi> vvi; typedef map<int, int> mpii; typedef set<int> seti; typedef multiset<int> mseti; // typedef long int ld; // typedef unsigned long int lu; // typedef long long int ll; // typedef unsigned long long int llu; const int T2 = 105; const int T3 = 1005; const int T4 = 10005; const int T5 = 100005; void solve(){ int n; cin>>n; if(n&1) cout<<"Black"; else cout<<"White"; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE // for getting input from input.txt freopen("input.txt", "r", stdin); // for writing output to output.txt freopen("output.txt", "w", stdout); #endif int t=1; // cin>>t; while(t--){ solve(); } return 0; }
#include<bits/stdc++.h> using namespace std; const int N=2e5+5; int n; string s,t; int main(){ cin>>n>>s>>t; reverse(s.begin(),s.end()); reverse(t.begin(),t.end()); s=" "+s;t=" "+t; int base=1; bool con[10],tmp[10]; for(int i=0;i<10;i++)con[i]=0,tmp[i]=0; con[0]=1; for(int i=1;i<=n;i++){ if(t[i]=='T'){ for(int i=0;i<10;i++)tmp[i]=0; int add=base*(s[i]-'0')%7; for(int i=0;i<7;i++)if(con[i])tmp[(i+add)%7]=1; for(int i=0;i<7;i++)if(tmp[i])con[i]=1,tmp[i]=0; }else{ bool tmp[2][10]; for(int i=0;i<7;i++)tmp[0][i]=tmp[1][i]=0; int add=base*(s[i]-'0')%7; for(int i=0;i<7;i++)if(con[i])tmp[0][i]=1,tmp[1][(i+add)%7]=1; for(int i=0;i<7;i++)con[i]=(tmp[0][i]&&tmp[1][i]); } base=base*10%7; } if(con[0])cout<<"Takahashi\n"; else cout<<"Aoki\n"; return 0; }
#include<bits/stdc++.h> using namespace std; void __print(int x){cout<<x;}void __print(long x){cout<<x;} void __print(long long x){cout<<x;}void __print(unsigned x){cout<<x;} void __print(unsigned long x){cout<<x;}void __print(unsigned long long x){cout<<x;} void __print(float x){cout<<x;}void __print(double x){cout<<x;} void __print(long double x){cout<<x;}void __print(char x){cout<<'\''<<x<<'\'';} void __print(const char *x){cout<<'\"'<<x<<'\"';}void __print(const string &x){cout<<'\"'<<x<<'\"';} void __print(bool x) {cout<<(x?"true":"false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';} template<typename T> void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";} void _print() {cout << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define debug(x...) cout << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif #define lp(i,a,b) for (ll i=a;i<=b;i++) #define rp(i,a,b) for (ll i=a;i>=b;i--) #define ms(a,x) memset(a,x,sizeof a) #define ll long long #define ff first #define ss second #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define pb push_back #define nl cout<<"\n" #define gcd(a,b) __gcd((a),(b)) #define lcm(a,b) ((a)*(b))/(gcd(a,b)) #define sq(a) ((a)*(a)*(a)) #define sz(a) (int) a.size() #define mod 1000000007 #define PI (2*acos(0.0)) const ll N=2e5+5; vector<array<ll,2>> g[N]; ll A[N]; void dfs(ll node,ll p,ll x) { A[node]=x; for(auto [adj,cost]:g[node]) { if(adj!=p) dfs(adj,node,x^cost); } } void solve() { ll n; cin>>n; lp(i,1,n-1) { ll a,b,c; cin>>a>>b>>c; g[a].pb({b,c}); g[b].pb({a,c}); } dfs(1,-1,0); ll res=0; lp(i,0,60) { ll one=0,zero=0; lp(j,1,n) { if(A[j] & 1ll<<i) one++; else zero++; } res=((res)+(1ll<<i)%mod*one%mod*zero%mod)%mod; } cout<<res; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int T=1; //cin>>T; while(T--) solve(); }
#include <cmath> #include <iostream> #include <string> #include <algorithm> #include <vector> #include <queue> #include <map> #include<cstdio> #include<functional> #include <bitset> #include <iomanip> #include <cctype> #include <list> #include <cassert> #define rep(i, n) for (ll i = 0; i < (n); i++) #define repr(i, n) for(ll i = n; i >= 0; i--) #define ll long long #define repi(i,a,b) for(ll i=a;i<b;++i) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() using namespace std; template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } const ll INF = 1000000000000000000; const ll MOD = 1e9 + 7; using vvv = vector<vector<vector<ll>>>; using vv = vector<vector<ll>>; using vec = vector<ll>; using P = pair<ll, ll>; bool isOK(ll n,ll k, vv al, ll mid) { vv tmp1(n, vec(n)); rep(i, n) { rep(j, n) { if (al[i][j] <= mid) { tmp1[i][j] = 1; } } } vv tmp2(n, vec(n)); rep(i, n) { rep(j, n) { if(j - 1 >= 0) tmp2[i][j] = tmp1[i][j] + tmp2[i][j - 1]; else tmp2[i][j] = tmp1[i][j]; } } rep(j, n) { rep(i, n) { if (i - 1 >= 0) tmp2[i][j] = tmp2[i][j] + tmp2[i - 1][j]; } } ll cnt = -1; rep(i, n) { rep(j, n) { if (i + k >= n || j + k >= n) break; ll r = tmp2[i + k][j + k]; if (i - 1 >= 0) { r -= tmp2[i - 1][j + k]; } if (j - 1 >= 0) { r -= tmp2[i + k][j - 1]; } if (i - 1 >= 0 && j - 1 >= 0) { r += tmp2[i - 1][j - 1]; } cnt = max(cnt, r); } } if (((k + 1) * (k + 1)) % 2 && cnt >= (k + 1) * (k + 1) / 2 + 1) return true; else if (((k + 1) * (k + 1)) % 2 == 0 && cnt >= (k + 1) * (k + 1) / 2) return true; else return false; } int main(void) { ll n, k; cin >> n >> k; vv al(n, vec(n)); ll mv = 0; rep(i, n) { rep(j, n) { ll a; cin >> a; mv = max(mv, a); al[i][j] = a; } } int ng = -1; int ok = mv; while (abs(ok - ng) > 1) { int mid = (ok + ng) / 2; if (isOK(n, k - 1,al, mid)) ok = mid; else ng = mid; } cout << ok << endl; system("pause"); }
#include <iostream> #include <string> #include <vector> #include <set> #include <map> #include <queue> #include <stack> #include <algorithm> #include <math.h> #include <cassert> #define rep(i,n) for(int i = 0; i < n; ++i ) using namespace std; using ll = long long; int main() { int n; cin >> n; vector<int> a(n),b(n); rep(i,n) cin >> a[i] >> b[i]; vector<int> p(2*n,-1),l(2*n,-1),r(2*n,-1); vector<bool> v(2*n+1); v[0] = [&]{ rep(i,n){ if(a[i]!=-1){ --a[i]; if(l[a[i]]!=-1||r[a[i]]!=-1) return false; l[a[i]]=i; } if(b[i]!=-1){ --b[i]; if(l[b[i]]!=-1||r[b[i]]!=-1) return false; r[b[i]]=i; } if(a[i]!=-1&&b[i]!=-1){ if(b[i]<=a[i]) return false; p[a[i]] = b[i]; p[b[i]] = a[i]; } } return true; }(); auto f = [&](int a,int b){ if(r[a]!=-1) return false; if(l[b]!=-1) return false; if(l[a]!=-1&&r[b]!=-1&&l[a]!=r[b]) return false; if(p[a]!=-1&&p[a]!=b) return false; if(p[b]!=-1&&p[b]!=a) return false; return true; }; for(int p=0;p<2*n;p+=2){ if(!v[p]) continue; for(int d=1;p+2*d<=2*n;++d){ if(v[p+2*d]) continue; v[p+2*d] = [&]{ rep(i,d) if(!f(p+i,p+d+i)) return false; return true; }(); } } cout << (v[2*n]?"Yes":"No") << endl; }
#include<bits/stdc++.h> using namespace std; int main(){ char a,b,c; cin>>a>>b>>c; if(a==b&&b==c){ cout<<"Won"<<endl; }else{ cout<<"Lost"<<endl; } }
#include <iostream> #include <algorithm> #include <cmath> #include <limits> #include <iomanip> #include <vector> #include <cstring> #include <queue> #include <map> #include <set> #include <numeric> #include <unordered_map> #include <unordered_set> typedef long long ll; #define rep(i,n) for(int i=0;i<n;i++) #define rep1(i,n) for(int i=1;i<=n;i++) #define rrep(i,n) for(int i=n-1;i>=0;i--) #define REP(i,L,R) for(int i=L;i<R;i++) using namespace std; typedef long double ld; typedef pair<int,int> P; typedef pair<ll,ll> Pll; typedef vector<vector<int>> Graph; typedef vector<string> Grid; const int dx[4] = {0,1,0,-1}; const int dy[4] = {1,0,-1,0}; template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;} template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;} //#define DEBUG //declaration area /* struct{ constexpr operator int(){return int(1e9)+1;} constexpr operator ll(){return ll(1e18)+1;} constexpr auto operator-(){ struct{ constexpr operator int(){return -int(1e9)-1;} constexpr operator ll(){return -ll(1e18)-1;} }_ret; return _ret; } }inf; */ //struct area //function area //main area int main(){ string s; cin >> s; if(s[0] == s[1] && s[1] == s[2]) cout << "Won" << endl; else cout << "Lost" << endl; } /* */
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> P; const ll INF=1e18; const int MOD=1e9+7; ll dp[1<<18][18]; int main(){ int N; cin >> N; int x[N],y[N],z[N]; for(int i=0;i<N;i++){ cin >> x[i] >> y[i] >> z[i]; } for(int i=0;i<(1<<18);i++){ for(int j=0;j<18;j++){ dp[i][j]=INF; } } dp[0][0]=0; for(int bit=0;bit<(1<<N);bit++){ for(int i=0;i<N;i++){ for(int j=0;j<N;j++){ ll res=abs(x[j]-x[i])+abs(y[j]-y[i])+max(0,z[j]-z[i]); dp[bit|(1<<j)][j]=min(dp[bit|(1<<j)][j],dp[bit][i]+res); } } } cout << dp[(1<<N)-1][0] << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; // -------------------------------------------------------- template<class T> bool chmax(T& a, const T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> bool chmin(T& a, const T b) { if (b < a) { a = b; return 1; } return 0; } #define FOR(i,l,r) for (int i = (l); i < (r); ++i) #define REP(i,n) FOR(i,0,n) #define ALL(c) (c).begin(), (c).end() #define RALL(c) (c).rbegin(), (c).rend() #define SORT(c) sort(ALL(c)) #define RSORT(c) sort(RALL(c)) #define MIN(c) *min_element(ALL(c)) #define MAX(c) *max_element(ALL(c)) #define SUM(c) accumulate(ALL(c), 0) #define SUMLL(c) accumulate(ALL(c), 0LL) #define SZ(c) ((int)(c).size()) #define debug(x) cerr << #x << " = " << (x) << '\n'; using P = pair<int,int>; using VP = vector<P>; using VVP = vector<VP>; using VS = vector<string>; using VI = vector<int>; using VVI = vector<VI>; using VLL = vector<ll>; using VVLL = vector<VLL>; using VB = vector<bool>; using VVB = vector<VB>; using VD = vector<double>; using VVD = vector<VD>; static const double EPS = 1e-10; static const double PI = acos(-1.0); static const ll MOD = 1000000007; // static const ll MOD = 998244353; static const int INF = 1 << 30; // 1073741824 // static const ll INF = 1LL << 62; // 4611686018427387904 // -------------------------------------------------------- // #include <atcoder/all> // using namespace atcoder; static const int MAX_N = 17; VVI dp((1 << MAX_N), VI(MAX_N, INF)); struct city { int X, Y, Z; }; int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(10); int N; cin >> N; vector<city> C(N); REP(i, N) { int X, Y, Z; cin >> X >> Y >> Z; C[i] = city{X, Y, Z}; } VVI G(N, VI(N, INF)); REP(i, N-1) FOR(j,i+1,N) { city a = C[i]; city b = C[j]; G[i][j] = abs(b.X - a.X) + abs(b.Y - a.Y) + max(0, b.Z - a.Z); G[j][i] = abs(a.X - b.X) + abs(a.Y - b.Y) + max(0, a.Z - b.Z); } dp[0][0] = 0; FOR(S, 1, (1 << N)) { FOR(u, 0, N) { if (!(S & (1 << u))) continue; int T = S - (1 << u); FOR(v, 0, N) { if (G[v][u] == INF) continue; dp[S][u] = min(dp[S][u], dp[T][v] + G[v][u]); } } } int ans = dp[(1 << N) - 1][0]; cout << ans << '\n'; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> pi; typedef vector<ll> vi; typedef vector<pi> vpi; typedef long double ld; const int inf = 1e9 + 7; const int mod = 998244353; const int maxn = 1e6 + 3; #define pb push_back #define mp make_pair #define ff first #define ss second #define rep(i, a, b) for(int i = a; i < b; i++) #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() #define lb lower_bound #define ub upper_bound #define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod); #define mod_in(a) exp(a, mod-2) #define ncr(n, r) ((ft[n]*mod_in((ft[r]*ft[(n)-(r)])%mod))%mod) #define deb(x) cout << #x << " " << x << endl; #define flash ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define endl '\n' /*#include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template<typename T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; template<typename T> using ordered_multiset = tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;*/ ll prime[4000005]; ll exp(ll a,ll b); void sieve(ll n); ll gcd(ll a ,ll b); ll countdigit(ll n); vector<ll>ft; int main() { flash; ll t=1; // sieve(4000003); //ft.pb(1); //fact(10000001); //cin >> t; ll n,m; cin >> n >> m; if (m == 0) { cout << 1; return 0; } ll a[m]; rep(i,0,m){ cin>>a[i]; } sort(a,a+m); vector<ll>gaps; rep(i,1,m){ gaps.pb(a[i]-a[i-1]-1); } gaps.pb(n-a[m-1]); gaps.pb(a[0]-1); ll ans = n; if (!gaps.empty()) for (auto i : gaps) { if (i > 0) ans = min(ans, i); } ll count = 0; if (!gaps.empty()) for (auto i : gaps) { if (i > 0) count += (i/ans + (i%ans != 0)); } cout << count; } // // // // // // IMPORTANT FUNCTIONS ll exp(ll a, ll b) { int res=1; while(b) { if(b&1) res=(res*a)%mod; a=(a*a)%mod; b>>=1; } return res%mod; } ll gcd(ll a,ll b){ if(a==0)return b; return gcd(b%a,a); } void sieve(ll n) { for(ll i=0;i<=n;i++) { prime[i]=1; } prime[0]=0;prime[1]=0; for(ll i=2;i<=n;i++) { if(prime[i]==1) { for(ll j=2;i*j<=n;j++) { prime[i*j]=0; } } } } ll countdigit(ll n) { return floor(log10(n) + 1); }
#ifdef DEBUG #define _GLIBCXX_DEBUG #endif #include "bits/stdc++.h" using namespace std; #define all(x) (x).begin(), (x).end() #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define un_map unordered_map #define rep(i,a,n) for (int i = a; i < n; ++i) #define rrep(i,a,n) for (int i = a; i >= n; --i) #define irep(i,a,n,inc) for (int i = a; i < n; i += inc) #define endl "\n" typedef long long ll; void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif #define int long long long long POW(long long a, long long b) { long long ans = 1; while (b) { if(b & 1) { ans = ans * a; } a = a * a; b /= 2; } return ans; } int const nax = 2e5 + 11; int a[nax]; int n, m; int32_t main() { IOS; cin >> n >> m; for (int i = 1; i <= m; ++i) cin >> a[i]; a[m + 1] = n; sort(a, a + m + 2); int minn = 1e18; for (int i = 1; i < m + 2; ++i) { int x = a[i] - a[i - 1]; if (i != m + 1) { if (x > 1) { minn = min(minn, x - 1); } }else { if (x) { minn = min(minn, x); } } } //debug(minn); if (minn == 1e18) { cout << 0; return 0; } int ans = 0; for (int i = 1; i < m + 2; ++i) { int y = a[i] - a[i - 1]; if (i != m + 1) { ans += (y + minn - 2) / minn; }else { ans += (y + minn - 1) / minn; } } cout << ans; }
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/hash_policy.hpp> using namespace std; using namespace __gnu_pbds; #define LL long long #define int long long #define ull unsigned long long #define fi first #define se second #define pll pair<LL, LL> #define pii pair<int, int> #define fastio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); #define SZ(x) ((int)(x.size())) #define LC (id<<1) #define RC (id<<1|1) constexpr int N = 1e6+9; constexpr int M = 1e9+7; #ifdef int constexpr int INF = 0x3f3f3f3f3f3f3f3f; constexpr int INF2 = 0xcfcfcfcfcfcfcfcf; #else constexpr int INF = 0x3f3f3f3f; constexpr int INF2 = 0xcfcfcfcf; #endif signed main() { fastio; int n; cin >> n; vector<int> fa(n, -1); vector<vector<int>> ch(n); for (int i = 1; i < n; i++) { cin >> fa[i]; fa[i]--; ch[fa[i]].emplace_back(i); } vector<int> sz(n, 1); // sz*2 + sz-1 vector<int> dp(n, 0); function<void(int)> dfs = [&](int u) { dp[u] = 1; array<vector<pii>, 2> sub; for (int v: ch[u]) { dfs(v); sz[u] += sz[v]; sub[sz[v]&1].emplace_back(dp[v], sz[v]-dp[v]); } sort(sub[0].begin(), sub[0].end(), [](const pii& p1, const pii& p2) { return p1.fi-p1.se > p2.fi-p2.se; }); sort(sub[1].begin(), sub[1].end(), [](const pii& p1, const pii& p2) { return p1.fi-p1.se < p2.fi-p2.se; }); while (!sub[0].empty() && sub[0].back().fi <= sub[0].back().se) { dp[u] += sub[0].back().fi; sub[0].pop_back(); } while (!sub[0].empty()) { if (SZ(sub[1]) & 1) dp[u] += sub[0].back().se; else dp[u] += sub[0].back().fi; sub[0].pop_back(); } for (int i = 0; i < SZ(sub[1]); i++) { if (i & 1) dp[u] += sub[1][i].se; else dp[u] += sub[1][i].fi; } }; dfs(0); cout << dp[0] << "\n"; return 0; }
#include<bits/stdc++.h> using namespace std; #define ALL(x) begin(x),end(x) #define rep(i,n) for(int i=0;i<(n);i++) #define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; #define mod 1000000007 using ll=long long; const int INF=1000000000; const ll LINF=1001002003004005006ll; int dx[]={1,0,-1,0},dy[]={0,1,0,-1}; // ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;} template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;} struct IOSetup{ IOSetup(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(12); } } iosetup; template<typename T> ostream &operator<<(ostream &os,const vector<T>&v){ for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==(int)v.size()?"":" "); return os; } template<typename T> istream &operator>>(istream &is,vector<T>&v){ for(T &x:v)is>>x; return is; } // graph template // ref : https://ei1333.github.io/library/graph/graph-template.cpp template<typename T=int> struct Edge{ int from,to; T w; int idx; Edge()=default; Edge(int from,int to,T w=1,int idx=-1):from(from),to(to),w(w),idx(idx){} operator int() const{return to;} }; template<typename T=int> struct Graph{ vector<vector<Edge<T>>> g; int V,E; Graph()=default; Graph(int n):g(n),V(n),E(0){} size_t size(){ return g.size(); } void resize(int k){ g.resize(k); } inline const vector<Edge<T>> &operator[](int k)const{ return (g.at(k)); } inline vector<Edge<T>> &operator[](int k){ return (g.at(k)); } void add_directed_edge(int from,int to,T cost=1){ g[from].emplace_back(from,to,cost,E++); } void add_edge(int from,int to,T cost=1){ g[from].emplace_back(from,to,cost,E); g[to].emplace_back(to,from,cost,E++); } void read(int m,int pad=-1,bool weighted=false,bool directed=false){ for(int i=0;i<m;i++){ int u,v;cin>>u>>v; u+=pad,v+=pad; T w=T(1); if(weighted) cin>>w; if(directed) add_directed_edge(u,v,w); else add_edge(u,v,w); } } }; // 結局小さいのからとらせればいい説 signed main(){ int n;cin>>n; Graph<> g(n); for(int i=1;i<n;i++){ int j;cin>>j;j--; g.add_directed_edge(j,i); } vector<int> dp(n,0);// dp[i] : iの1を取る手順の人の利得 vector<int> sz(n,0); function<void(int)> dfs=[&](int cur){ int s=1; for(auto &e:g[cur]){ dfs(e); s+=sz[e]; } sz[cur]=s; int res=1;// A-B bool A=false; { vector<int> ch,no; for(auto &e:g[cur]){ if(sz[e]%2) ch.push_back(dp[e]); else no.push_back(dp[e]); } sort(ALL(ch)); sort(ALL(no)); int chi=0,noi=0; while(chi<(int)ch.size() or noi<(int)no.size()){ // 相手に押し付けたい if(noi<(int)no.size() and no[noi]<0){ if(!A) res+=no[noi]; else res-=no[noi]; noi++; } else if(chi<(int)ch.size()){ if(!A) res+=ch[chi]; else res-=ch[chi]; chi++; A^=1; }else{ if(!A) res+=no[noi]; else res-=no[noi]; noi++; } } } dp[cur]=res; }; dfs(0); cout<<(dp[0]+n)/2<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; using ll = long long; int main(){ double N; cin >> N; double ans = 0; for(int i=1; i<N; i++){ ans += N/i; } printf("%.10f",ans); }
#include<bits/stdc++.h> using namespace std; const int maxn=1e6+10; double dp[maxn]; int main() { int n;scanf("%d",&n); dp[0]=0; for(int i=1;i<=n;i++){ dp[i]=(dp[i-1]*(n-i+1)+n)/(n-i+1); } printf("%.10lf\n",dp[n]-1); }
//AUTHOR: RAVAN_2070 //PUNE INSTITUTE OF COMPUTER TECHNOLOGY /* I ♥ CLARICE STARLING... EXPLAINATION BELOW-> */ #include<bits/stdc++.h> using namespace std; typedef unsigned long long int ull; typedef long long int ll; typedef long double ld; typedef vector<ll> vi; typedef vector<pair<ll,ll>> vii; typedef pair<ll,ll> pii; typedef map<ll,ll> mii; #define MOD7 1000000007 #define MOD9 1000000009 #define pi 3.1415926535 #define Test_cases ll TC;cin>>TC;while(TC--) #define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define pb push_back #define mp make_pair #define F first #define S second #define lb lower_bound #define ub upper_bound #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(), x.rend() #define sp(x) fixed<<setprecision(x) #define sz(x) (ll)(x.size()) #define fo(i,a,b) for(i=a;i<b;i++) #define foe(i,a,b) for(i=a;i<=b;i++) const ll INF = (ll)2e18 + 77; ll num(ll a,int f) { vector<ll>d; while(a) { d.pb(a%10); a/=10; } if(f==0)sort(all(d)); else sort(all(d),greater<ll>()); ll ans=0ll; for(auto dg:d) { ans*=10; ans+=dg; } return ans; } void solve() { ll N,K,i;cin>>N>>K; ll a=N; foe(i,1,K) { a=(num(a,1)-num(a,0)); } cout<<a<<"\n"; } int main() { fastio //Test_cases solve(); return 0; }
#include <bits/stdc++.h> using namespace std; // function to count the no of removal of digits // to make a very large number divisible by 3 int divisible(string num) { int n = num.length(); // add up all the digits of num int sum = accumulate(begin(num), end(num), 0) - '0' * 1; // if num is already is divisible by 3 // then no digits are to be removed if (sum % 3 == 0) return 0; // if there is single digit, then it is // not possible to remove one digit. if (n == 1) return -1; // traverse through the number and find out // if any number on removal makes the sum // divisible by 3 for (int i = 0; i < n; i++) if (sum % 3 == (num[i] - '0') % 3) return 1; // if there are two numbers then it is // not possible to remove two digits. if (n == 2) return -1; // Otherwise we can always make a number // multiple of 2 by removing 2 digits. return 2; } // driver program to test the above function int main() { string num ;cin>>num; cout << divisible(num); return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<n;i++) using namespace std; using P=pair<int,int>; using ll=long long; using ld=long double; int main(){ ll n,m,x,y,inf=1e18; cin >> n >> m >> x >> y; x--; y--; vector<vector<vector<ll>>> a(n,vector<vector<ll>>(0,vector<ll>(3))); rep(i,m){ ll c,d,t,k; cin >> c >> d >> t >> k; c--; d--; a[c].emplace_back(); a[d].emplace_back(); a[c][(int)a[c].size()-1]={d,t,k}; a[d][(int)a[d].size()-1]={c,t,k}; } vector<ll> b(n,inf); queue<int> q; q.push(x); b[x]=0; while(q.size()){ int now=q.front(); q.pop(); rep(i,(int)a[now].size()){ ll p=(b[now]-1)/a[now][i][2]+1;//発車時刻 p*=a[now][i][2]; if(b[now]==0) p=0; if(b[a[now][i][0]]>p+a[now][i][1]){ b[a[now][i][0]]=p+a[now][i][1]; q.push(a[now][i][0]); } } } if(b[y]==inf) cout << -1 << endl; else cout << b[y] << endl; }
#pragma GCC optimize("Ofast") #pragma GCC optimization ("unroll-loops") #include <bits/stdc++.h> #define IOS ios_base::sync_with_stdio(0); cin.tie(0); #define pb push_back #define fi first #define se second #define ins insert #define sz(x) (int)x.size() #define dbg(x) cout << x << "\n"; const int N = 1e5 + 5; const long long int mod = 1e9 + 7; const long long int Mod = 998244353; const long double Pi = acos(-1); const long long int Inf = 4e18; using namespace std; struct nxt{ long long int to, ti, in; }; vector <struct nxt> g[N]; vector <long long int> ans(N); long long int Dijkstra (long long int x, long long int y){ ans.assign(N, Inf); ans[x] = 0; set < pair <long long int, long long int> > s; s.ins({0, x}); while(!s.empty()){ long long int cur = s.begin()->fi, idx = s.begin()->se; s.erase(s.begin()); for(auto u: g[idx]){ long long int upd = cur; if(cur % u.in != 0){ upd = ((cur + u.in - 1)/u.in) * u.in; } if(ans[u.to] > upd + u.ti){ ans[u.to] = upd + u.ti; s.ins({ans[u.to], u.to}); } } } if(ans[y] == Inf) return -1; else return ans[y]; } void TestCase (){ long long int n, m, x, y; cin >> n >> m >> x >> y; for(int i = 1; i<=m; i++){ long long int u, v, t, k; cin >> u >> v >> t >> k; g[u].pb({v, t, k}); g[v].pb({u, t, k}); } cout << Dijkstra(x, y); } int main(){ IOS; int T = 1; // cin >> T; while(T--){ TestCase(); } return 0; }
#include <bits/stdc++.h> using namespace std; // using mint = long double; // using mint = modint998244353; // using mint = modint1000000007; typedef long long ll; typedef pair<ll, ll> P; typedef pair<ll, P> T; typedef pair<ll, vector<ll>> Pd; const ll INF = 1e18; const ll fact_table = 320000; priority_queue<ll> pql; priority_queue<P> pqp; // big priority queue priority_queue<ll, vector<ll>, greater<ll>> pqls; priority_queue<P, vector<P>, greater<P>> pqps; // small priority queue // top pop ll dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}; ll dy[8] = {0, 1, 0, -1, -1, 1, 1, -1}; //↓,→,↑,← #define p(x) cout << x << "\n"; #define el cout << "\n"; #define pe(x) cout << x << " "; #define ps(x) cout << fixed << setprecision(25) << x << endl; #define pu(x) cout << (x); #define pb push_back #define lb lower_bound #define ub upper_bound #define pc(x) cout << x << ","; #define rep(i, n) for (ll i = 0; i < (n); i++) #define rep2(i, a, b) for (ll i = a; i <= (b); i++) #define rep3(i, a, b) for (ll i = a; i >= (b); i--) #define all(c) begin(c), end(c) #define sorti(v) sort(all(v)) #define sortd(v) \ sort(all(v)); \ reverse(all(v)); #define SUM(v) accumulate(all(v), 0LL) #define MIN(v) *min_element(all(v)) #define MAX(v) *max_element(all(v)) typedef vector<ll> vec; typedef vector<vector<ll>> mat; // vec v(n) -> 長さnのベクトルを宣言 // mat dp(h, vec(w)) -> h * w の行列を宣言 // const ll mod = 1000000007ll; const ll mod = 998244353ll; ll mypow(ll a, ll b, ll m = mod) { ll x = 1; while (b) { while (!(b & 1)) { (a *= a) %= m; b >>= 1; } (x *= a) %= m; b--; } return x; } vec rv(ll read) { vec res(read); for (int i = 0; i < read; i++) { cin >> res[i]; } return res; } /* ll fact[fact_table + 5], rfact[fact_table + 5]; void c3_init() { fact[0] = rfact[0] = 1; for (ll i = 1; i <= fact_table; i++) { fact[i] = (fact[i - 1] * i) % mod; } rfact[fact_table] = mypow(fact[fact_table], mod - 2, mod); for (ll i = fact_table; i >= 1; i--) { rfact[i - 1] = rfact[i] * i; rfact[i - 1] %= mod; } return; } ll c3(ll n, ll r) { return (((fact[n] * rfact[r]) % mod) * rfact[n - r]) % mod; } */ bool icpc = false; bool multicase = false; ll n, m; ll xd[200005], yd[200005]; bool solve() { cin >> n; vector<P> xmax, xmin, ymax, ymin; rep(i, n) { ll x, y; cin >> x >> y; xd[i] = x, yd[i] = y; xmax.pb(P(x, i)); xmin.pb(P(x, i)); sorti(xmin); sortd(xmax); ymax.pb(P(y, i)); ymin.pb(P(y, i)); sorti(ymin); sortd(ymax); if (i >= 2) { xmin.pop_back(); xmax.pop_back(); ymin.pop_back(); ymax.pop_back(); } } set<P> st; rep(i, 2) { rep(j, 2) { st.insert(P(xmax[i].second, xmin[j].second)); st.insert(P(ymax[i].second, ymin[j].second)); } } vec v; for (auto pa : st) { auto [a, b] = pa; ll dis = max(abs(xd[a] - xd[b]), abs(yd[a] - yd[b])); v.pb(dis); } sortd(v); ll ans = v[1]; p(ans); return true; } /* */ int main() { // ios::sync_with_stdio(false); // cin.tie(nullptr); if (icpc) { while (solve()) ; return 0; } ll q, testcase = 1; if (multicase) { cin >> q; } else { q = 1; } while (q--) { // cout << "Case #" << testcase << ": "; solve(); testcase++; } // solve(); return 0; }
/* One more time, one more time “Please just lemme roll for another day” That’s what she said, What she said Don’t you know the meanings are hidden under cover? “One more time? Stop it’s fine.” “Are’nt you getting tired of doing this?” “I’ll stop your breath from rolling out… for now.” */ /* ... - "How many times will you try?" .. - "As long as I can bear it" */ #include <bits/stdc++.h> #define fastio() \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define pb push_back #define show(x) cout << (#x) << " : " << x << endl; #define ll long long #define ull unsigned long long #define ld long double #define pow power #define mp make_pair #define ff first #define ss second #define pii pair<ll, ll> #define sq(x) ((x) * (x)) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define siz(a) int((a).size()) #define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i)) #define Forn(i,a,b) for(int (i)=(a);(i) >= (b); --(i)) #define endl "\n" #define pi 3.14159265 const ll mod = 1000 * 1000 * 1000 + 7; const ll mod1 = 998244353; const ll INF = 1ll*1000*1000*1000*1000*1000*1000 + 7; //typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; //typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; using namespace std; ll power(ll x, ll y) { ll res = 1; while (y > 0) { if (y & 1) res = (long long)(res*x); y = y>>1; x = (long long)(x*x); //cout<<x<<'\n'; } return res; } // Stolen Templates template <typename T> T MIN(T first) { return first; } template <typename T, typename... Args> T MIN(T first, Args... args) { return min(first, MIN(args...)); } template <typename T> T MAX(T first) { return first; } template <typename T, typename... Args> T MAX(T first, Args... args) { return max(first, MAX(args...)); } // Stolen Templates end here int main() { #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif fastio(); ll n; cin>>n; vector <ll> x(n); vector <ll> y(n); vector <pii> tx(n); vector <pii> ty(n); For(i,0,n) { cin>>x[i]>>y[i]; tx[i].ff = x[i]; tx[i].ss = i; ty[i].ff = y[i]; ty[i].ss = i; } ll av1,av2; sort(all(tx)); sort(all(ty)); if (ty.back().ff - ty[0].ff >= tx.back().ff - tx[0].ff) { av1 = ty.back().ss; av2 = ty[0].ss; } else { av1 = tx.back().ss; av2 = tx[0].ss; } ll ans = 0; For(i,0,n) { tx[i].ff = x[i]; tx[i].ss = i; ty[i].ff = y[i]; ty[i].ss = i; } vector <pii> cx[3]; vector <pii> cy[3]; For(i,0,n) { if (tx[i].ss != av1) { cx[0].pb(tx[i]); cy[0].pb(ty[i]); } if (tx[i].ss != av2) { cx[1].pb(tx[i]); cy[1].pb(ty[i]); } if (tx[i].ss != av1 and tx[i].ss != av2) { cx[2].pb(tx[i]); cy[2].pb(ty[i]); } } For(i,0,3) { sort(all(cx[i])); sort(all(cy[i])); ans = max(ans,cy[i].back().ff - cy[i][0].ff); ans = max(ans,cx[i].back().ff - cx[i][0].ff); } cout<<ans; return 0; } // check all product based operations for integer overflow // careful of renamed variables especially in loops //python interactive_runner.py python local_testing_tool.py 0 -- c.exe
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> P; const int MAX = 550; const int MAXM = 1e8+50; struct Edge{ int v, w, next; }es[MAXM]; int head[MAX*MAX], k, n, m; int A[MAX][MAX], B[MAX][MAX]; int id[MAX][MAX], idx; int d[MAX*MAX]; bool vis[MAX*MAX]; void add(int u, int v, int w) { es[++k].next = head[u]; es[k].v = v; es[k].w = w; head[u] = k; } int dij() { fill(d, d+n*m+1, 1e7); priority_queue<P, vector<P>, greater<P> > q; q.push(P(0, 1)); d[1] = 0; while (q.size()) { int u = q.top().second; q.pop(); if (vis[u]) continue; vis[u] = true; //if (u == n*m) return d[u]; for (int i = head[u]; i; i = es[i].next) { int v = es[i].v; if (!vis[v] && d[v]>d[u]+es[i].w) { d[v] = d[u] + es[i].w; q.push(P(d[v], v)); } } } return d[n*m]; } int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) id[i][j] = ++idx; for (int i = 1; i <= n; i++) for (int j = 1; j < m; j++) scanf("%d", &A[i][j]); for (int i = 1; i < n; i++) for (int j = 1; j <= m; j++) scanf("%d", &B[i][j]); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (j > 1) { add(id[i][j], id[i][j-1], A[i][j-1]); //add(id[i][j-1], id[i][j], A[i][j-1]); } if (j < m) { add(id[i][j], id[i][j+1], A[i][j]); //add(id[i][j+1], id[i][j], A[i][j]); } if (i < n) { add(id[i][j], id[i+1][j], B[i][j]); //add(id[i+1][j], id[i][j], B[i][j]); } if (i > 1) { for (int k = i-1; k >= 1; k--) { add(id[i][j], id[k][j], i-k+1); } } } } printf("%d\n", dij()); return 0; }
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,a,b) for(int i=a;i>=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() //#pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } //--------------------------------------------------------------------------------------------------- /*---------------------------------------------------------------------------------------------------             ∧_∧       ∧_∧  (´<_` )  Welcome to My Coding Space!      ( ´_ゝ`) /  ⌒i @hamayanhamayan0     /   \    | |     /   / ̄ ̄ ̄ ̄/  |   __(__ニつ/  _/ .| .|____      \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ int H, W, A[505][505], B[505][505]; //--------------------------------------------------------------------------------------------------- template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>; int vis[505][505]; ll D[505][505]; ll dijk() { rep(y, 0, H) rep(x, 0, W) D[y][x] = infl; rep(y, 0, H) rep(x, 0, W) vis[y][x] = 0; min_priority_queue<pair<ll, int>> que; D[0][0] = 0; que.push({ 0, 0 }); while (!que.empty()) { auto q = que.top(); que.pop(); ll cst = q.first; int x = q.second % W; int y = q.second / W; if (x == W - 1 && y == H - 1) return cst; if (vis[y][x]) continue; vis[y][x] = 1; if (x < W - 1) if (chmin(D[y][x + 1], cst + A[y][x])) que.push({ D[y][x + 1], y * W + x + 1 }); if (0 < x) if (chmin(D[y][x - 1], cst + A[y][x - 1])) que.push({ D[y][x - 1], y * W + x - 1 }); if (y < H - 1) if (chmin(D[y + 1][x], cst + B[y][x])) que.push({ D[y + 1][x], (y + 1) * W + x }); rep(dy, 1, y + 1) if (chmin(D[y - dy][x], cst + 1 + dy)) que.push({ D[y - dy][x], (y - dy) * W + x }); } } //--------------------------------------------------------------------------------------------------- void _main() { cin >> H >> W; rep(y, 0, H) rep(x, 0, W - 1) cin >> A[y][x]; rep(y, 0, H - 1) rep(x, 0, W) cin >> B[y][x]; cout << dijk() << endl; }
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #define ff first #define ss second #define pb push_back #define eb emplace_back #define mp make_pair #define lb lower_bound #define ub upper_bound #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define sz(v) (int)v.size() #define ps(y) cout << fixed << setprecision(y) #define ms(arr, v) memset(arr, v, sizeof(arr)) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define trav(x, v) for(auto &x: v) #define w(t) int t; cin >> t; while(t--) #define rep0(i, n) for(int i = 0; i < n; i++) #define rrep0(i, n) for(int i = n - 1; i >= 0; i--) #define rep1(i, n) for(int i = 1; i <= n; i++) #define rrep1(i, n) for(int i = n; i > 0; i--) #define inp(arr, n) rep0(i, n) cin >> arr[i]; #define rep(i, a, b) for(int i = a; i <= b; i++) #define rrep(i, a, b) for(int i = a; i >= b; i--) typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<ll, ll> pii; typedef vector<ll> vi; typedef vector<vi> vvi; typedef vector<pii> vp; typedef vector<bool> vb; typedef vector<string> vs; typedef map<ll, ll> mii; typedef map<char, ll> mci; typedef priority_queue<ll> pq_mx; typedef priority_queue<ll, vi, greater<>> pq_mn; typedef tree<ll, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> pbds; /* * find_by_order(i) -> returns an iterator to the element at ith position (0 based) * order_of_key(i) -> returns the position of element i (0 based) */ const int N = 2e6 + 5; const int mod = 1e9 + 7; //const int mod = 998244353; const ll inf = 1e18; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void fio() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); } const int M = 1e7 + 5; ll spf[M], mobius[M]; vi primes; void sieve() { rep(x, 2, 1e7) { if (spf[x] == 0) spf[x] = x, primes.pb(x); for (int y = 0; y < sz(primes) and primes[y] <= spf[x] and x * primes[y] <= 1e7; y++) spf[x * primes[y]] = primes[y]; } } void Mobius() { /* * mobius[x] = 1 => x is a square-free +ve int with even no. of prime factors * mobius[x] = -1 => x is a square-free +ve int with odd no. of prime factors * mobius[x] = 0 => x has a squared prime factor */ rep1(x, 1e7) { if (x == 1) mobius[x] = 1; else { if (spf[x] == spf[x / spf[x]]) mobius[x] = 0; else mobius[x] = -mobius[x / spf[x]]; } } } int main() { fio(); sieve(); Mobius(); int l, r; cin >> l >> r; if(l == 1) ++l; ll res = 0; rep(x, 2, r) { ll cur = r / x - (l - 1) / x; res -= cur * cur * mobius[x]; } // cout << res << endl; rep(x, l, r) { --res; for (int y = 2 * x; y <= r; y += x) res -= 2; } cout << res; return 0; }
#pragma GCC optimize(2) #include <cstdio> #include <vector> #include <iostream> using namespace std; #define int long long #define maxn 1000005 vector < int > d[maxn]; int cnt; bool vis[maxn]; int prime[maxn], mu[maxn], pre[maxn]; void init( int n ) { mu[1] = 1; for( int i = 2;i <= n;i ++ ) { if( ! vis[i] ) prime[++ cnt] = i, mu[i] = -1; for( int j = 1;j <= cnt && i * prime[j] <= n;j ++ ) { vis[i * prime[j]] = 1; if( i % prime[j] == 0 ) { mu[i * prime[j]] = 0; break; } mu[i * prime[j]] = -mu[i]; } } for( int i = 1;i <= n;i ++ ) pre[i] = pre[i - 1] + mu[i]; } int calc( int n, int m ) { if( n > m ) swap( n, m ); int last, ans = 0; for( int i = 1;i <= n;i = last + 1 ) { last = min( n / ( n / i ), m / ( m / i ) ); ans += ( pre[last] - pre[i - 1] ) * ( n / i ) * ( m / i ); } return ans; } signed main() { int L, R; scanf( "%lld %lld", &L, &R ); init( R ); int ans = 0; for( int k = 2;k <= R;k ++ ) { int l = ( L - 1 ) / k, r = R / k; ans += calc( r, r ) - calc( l, r ) - calc( r, l ) + calc( l, l ); } for( int i = 2;i <= R;i ++ ) for( int j = i << 1;j <= R;j += i ) d[j].push_back( i ); for( int i = max( 2ll, L );i <= R;i ++ ) { for( int j = d[i].size() - 1;~ j;j -- ) if( d[i][j] >= L ) ans --; else break; ans -= ( R / i ); } printf( "%lld\n", ans ); return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (n); ++i) #define ALL(v) v.begin(), v.end() using namespace std; using ll = long long; using P = pair<int,int>; int main(){ int h , w; cin >> h >> w; int n = h * w; vector<int> v(n); rep(i,n){ cin >> v[i]; } int Min = *min_element(ALL(v)); int sum = 0; rep(i,n){ sum += v[i] - Min; } cout << sum; }
//Codeforcesで128bit整数を使いたいとき //→__int128_tを使う&GNU C++17 (64)で提出する //インクルードなど #include <iostream> // cout, endl, cin // string, to_string, stoi #include <vector> // vector #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <utility> // pair, make_pair #include <tuple> // tuple, make_tuple #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include <map> // map #include <queue> // queue, priority_queue #include <set> // set #include <stack> // stack #include <deque> // deque #include <unordered_map> // unordered_map #include <unordered_set> // unordered_set #include <bitset> // bitset #include <cctype> // isupper, islower, isdigit, toupper, tolower #include <string> using namespace std; typedef long long ll; //イテレーション #define REP(i,n) for(ll i=0;i<ll(n);i++) #define REPD(i,n) for(ll i=n-1;i>=0;i--) #define FOR(i,a,b) for(ll i=a;i<=ll(b);i++) #define FORD(i,a,b) for(ll i=a;i>=ll(b);i--) #define FORA(i,I) for(const auto& i:I) //x:コンテナ #define ALL(x) x.begin(),x.end() #define SIZE(x) ll(x.size()) //定数 #define INF32 2147483647 //2.147483647×10^{9}:32bit整数のinf #define INF64 9223372036854775807 //9.223372036854775807×10^{18}:64bit整数のinf #define MOD 998244353 //問題による //略記 #define F first #define S second //出力(空白区切りで昇順に) #define coutALL(x) for(auto i=x.begin();i!=--x.end();i++)cout<<*i<<" ";cout<<*--x.end(); #define coutall(x) {for(int i=0;i<sizeof(x)/sizeof(x[0]);i++){cout<<x[i]<<"|";};};cout; //aをbで割る時の繰上げ,繰り下げ ll myceil(ll a,ll b){return (a+(b-1))/b;} ll myfloor(ll a,ll b){return a/b;} signed main(){ ll a[10000],h,w,m=INF32,ans=0; cin>>h>>w; REP(i,h*w){ cin>>a[i]; if(a[i]<m){m=a[i];}; ans+=a[i]; }; cout<<ans-h*w*m; }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define ub upper_bound #define lb lower_bound #define bs binary_search #define fi first #define se second #define int long long using pii = pair<int,int>; using ll = long long; const int maxn = 2e5; const int inf = 1e18; const int mod = 1e9+7; void open_io() { freopen("in","r",stdin); freopen("out","w",stdout); } void fast_io() { ios::sync_with_stdio(0); cout.tie(0); cin.tie(0); } int n,m; int cost[maxn+5]; int ans[maxn+5]; int maxval[maxn+5]; vector<int> adj[maxn+5]; bool vis[maxn+5]; void dfs(int u) { vis[u] = 1; ans[u] = maxval[u] = -inf; for(int v : adj[u]) { if(not vis[v]) dfs(v); maxval[u] = max({maxval[u],cost[v],maxval[v]}); } ans[u] = maxval[u] - cost[u]; } int solve() { int ret = -inf; for(int i=1;i<=n;i++) if(not vis[i]) dfs(i); for(int i=1;i<=n;i++) ret = max(ret,ans[i]); return ret; } int32_t main () { //open_io(); fast_io(); cin >> n >> m; for(int i=1;i<=n;i++) cin >> cost[i]; while(m--) { int a,b; cin >> a >> b; adj[a].pb(b); } cout << solve() << endl; }
#include<bits/stdc++.h> #define For(i,a,b) for(register int i=(a);i<=(b);++i) #define pb push_back #define pr pair<int,int> #define fi first #define se second #define LL long long #define mk(a,b) make_pair(a,b) using namespace std; int read(){ char x=getchar(); int u=0,fg=0; while(!isdigit(x)){ if(x=='-') fg=1; x=getchar(); } while(isdigit(x)){ u=(u<<3)+(u<<1)+(x^48); x=getchar(); } return fg?-u:u; } const int maxx=1e5+10; int n,m,sum=0,cnt=0,mx,ans=1e9; int w[10],tmp[10],s[10],dis[10],v[maxx],l[maxx]; int p[10]={0,1,2,3,4,5,6,7,8}; pr a[maxx]; bool cmp(pr x,pr y){ if(x.fi!=y.fi) return x.fi<y.fi; return x.se>y.se; } int iso(int x){ x=lower_bound(v+1,v+cnt+1,x)-v-1; return l[x]; } int solve(){ s[0]=0; For(i,1,n){ tmp[i]=w[p[i]]; s[i]=s[i-1]+tmp[i]; dis[i]=0;} For(i,2,n) For(j,1,i-1){ dis[i]=max(dis[i],dis[j]+iso(s[i]-s[j-1])); if(dis[i]>=ans) return dis[i]; } return dis[n]; } int main() { #ifndef ONLINE_JUDGE freopen("input.in", "r", stdin); freopen("output.out", "w", stdout); #endif int u1,u2; n=read(); m=read(); For(i,1,n){ w[i]=read(); mx=max(w[i],mx);} For(i,1,m){ u1=read(); u2=read(); a[i]=mk(u2,u1); if(u2<mx){ printf("-1\n"); return 0; } } sort(a+1,a+m+1,cmp); v[++cnt]=a[1].fi; l[cnt]=a[1].se; For(i,2,m) if(a[i].se>l[cnt]){ v[++cnt]=a[i].fi; l[cnt]=a[i].se; } do{ ans=min(ans,solve()); }while(next_permutation(p+1,p+n+1)); printf("%d\n",ans); return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=1e2+5; int x[N],y[N]; int main() { int n; cin>>n; for(int i=1;i<=n;i++) { cin>>x[i]>>y[i]; } int flag=0; for(int i=1;i<=n;i++) { for(int j=i+1;j<=n;j++) { for(int k=j+1;k<=n;k++) { if(x[i]*y[j]-x[j]*y[i]+x[j]*y[k]-x[k]*y[j]+x[k]*y[i]-y[k]*x[i]==0) { flag=1; //cout<<x[i]<<" "<<y[i]<<" "<<x[j]<<" "<<y[j]<<" "<<x[k]<<" "<<y[k]<<endl; break; } } if(flag==1) break; } if(flag==1) break; } if(flag==1) cout<<"Yes"<<endl; else cout<<"No"<<endl; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int,int>; int main() { ll N; cin >> N; vector<ll> x(N); vector<ll> y(N); rep(i, N) { cin >> x.at(i) >> y.at(i); } for (int i = 0; i < N - 2; ++i) { for (int j = i + 1; j < N - 1 ; ++j) { for (int k = j + 1; k < N ; ++k) { if ((x.at(k) - x.at(i)) * (y.at(j) - y.at(i)) == (x.at(j) - x.at(i)) * (y.at(k) - y.at(i))) { cout << "Yes" << endl; return 0; } } } } cout << "No" << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < n; i++) #define rep2(i, x, n) for(int i = x; i <= n; i++) #define rep3(i, x, n) for(int i = x; i >= n; i--) #define each(e, v) for(auto &e: v) #define pb push_back #define eb emplace_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define sz(x) (int)x.size() using ll = long long; using pii = pair<int, int>; using pil = pair<int, ll>; using pli = pair<ll, int>; using pll = pair<ll, ll>; //const int MOD = 1000000007; const int MOD = 998244353; const int inf = (1<<30)-1; const ll INF = (1LL<<60)-1; template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;}; template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;}; struct io_setup{ io_setup(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout << fixed << setprecision(15); } } io_setup; template<int mod> struct Mod_Int{ int x; Mod_Int() : x(0) {} Mod_Int(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} Mod_Int &operator += (const Mod_Int &p){ if((x += p.x) >= mod) x -= mod; return *this; } Mod_Int &operator -= (const Mod_Int &p){ if((x += mod - p.x) >= mod) x -= mod; return *this; } Mod_Int &operator *= (const Mod_Int &p){ x = (int) (1LL * x * p.x % mod); return *this; } Mod_Int &operator /= (const Mod_Int &p){ *this *= p.inverse(); return *this; } Mod_Int &operator ++ () {return *this += Mod_Int(1);} Mod_Int operator ++ (int){ Mod_Int tmp = *this; ++*this; return tmp; } Mod_Int &operator -- () {return *this -= Mod_Int(1);} Mod_Int operator -- (int){ Mod_Int tmp = *this; --*this; return tmp; } Mod_Int operator - () const {return Mod_Int(-x);} Mod_Int operator + (const Mod_Int &p) const {return Mod_Int(*this) += p;} Mod_Int operator - (const Mod_Int &p) const {return Mod_Int(*this) -= p;} Mod_Int operator * (const Mod_Int &p) const {return Mod_Int(*this) *= p;} Mod_Int operator / (const Mod_Int &p) const {return Mod_Int(*this) /= p;} bool operator == (const Mod_Int &p) const {return x == p.x;} bool operator != (const Mod_Int &p) const {return x != p.x;} Mod_Int inverse() const{ assert(*this != Mod_Int(0)); return pow(mod-2); } Mod_Int pow(long long k) const{ Mod_Int now = *this, ret = 1; for(; k > 0; k >>= 1, now *= now){ if(k&1) ret *= now; } return ret; } friend ostream &operator << (ostream &os, const Mod_Int &p){ return os << p.x; } friend istream &operator >> (istream &is, Mod_Int &p){ long long a; is >> a; p = Mod_Int<mod>(a); return is; } }; using mint = Mod_Int<MOD>; int main(){ int N; cin >> N; vector<int> a(N); rep(i, N){ cin >> a[i]; a[i]--; } vector<int> used(N, false); int K = 0; rep(i, N){ //if(used[i]) continue; int ptr = i; set<int> s; while(true){ if(used[ptr]) break; used[ptr] = true; s.emplace(ptr); ptr = a[ptr]; if(s.count(ptr)) {K++; break;} } } cout << mint(2).pow(K)-1 << '\n'; }
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/hash_policy.hpp> using namespace std; using namespace __gnu_pbds; #define LL long long #define int long long #define ull unsigned long long #define fi first #define se second #define pll pair<LL, LL> #define pii pair<int, int> #define fastio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); #define SZ(x) ((int)(x.size())) #define LC (id<<1) #define RC (id<<1|1) constexpr int N = 1e3+9; constexpr int M = 1e9+7; #ifdef int constexpr int INF = 0x3f3f3f3f3f3f3f3f; constexpr int INF2 = 0xcfcfcfcfcfcfcfcf; #else constexpr int INF = 0x3f3f3f3f; constexpr int INF2 = 0xcfcfcfcf; #endif int n, k; int t[N][N]; int ans; int vis[N]; int cur; void dfs(int i, int u) { if (i == n) { cur += t[u][1]; ans += cur == k; cur -= t[u][1]; return; } for (int j = 1; j <= 8; j++) { if (!vis[j]) { vis[j] = 1; cur += t[u][j]; dfs(i+1, j); cur -= t[u][j]; vis[j] = 0; } } } signed main() { fastio; cin >> n >> k; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { cin >> t[i][j]; } } vis[1] = 1; dfs(1, 1); cout << ans << "\n"; return 0; }
#include<bits/stdc++.h> #define fs first #define se second #define pb push_back #define cppio ios::sync_with_stdio(false);cin.tie(0) using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef vector<int> VI; const int maxn=2e5+5; const ll inf=0x3f3f3f3f; const ll mod=1e9+7; int a[maxn],b[maxn]; int main(){ int n; scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d",a+i); } for(int i=1;i<=n;i++){ scanf("%d",b+i); } int l=0,r=1010; for(int i=1;i<=n;i++){ l=max(a[i],l); r=min(b[i],r); } printf("%d\n",max(0,r-l+1)); return 0; }
#include<iostream> #include <bits/stdc++.h> using namespace std; #define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define l long #define ll long long #define ull unsigned long long #define ui unsigned int #define vi vector<int> #define vll vector<ll> #define pb push_back #define ld long double #define mp make_pair #define pii pair<int,int> #define mod 1000000007 #define rep(i,n) for(int i=0;i<n;i++) #define all(v) v.begin(),v.end() int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n; cin>>n; ll a[n+1]; ll sum=0; vector<ll> v(401,0); for(int i=0;i<n;i++) { cin>>a[i]; a[i]=a[i]+200; v[a[i]]++; } for(int i=0;i<401;i++) { for(int j=i;j<401;j++) { sum+=(j-i)*(j-i)*v[i]*v[j]; } } cout<<sum<<endl; }
#include <iostream> #include <algorithm> using namespace std; int a, b, n, ans, ans2; struct A { int a, b, num; }Ans[10001]; bool C (A a, A b) { return a.a < b.a; } bool D (A a, A b) { return a.b < b.b; } int main () { cin >> n; for (int i = 0; i < n; i++) { cin >> Ans[i].a >> Ans[i].b; Ans[i].num = i; } sort (Ans, Ans + n, C); ans = Ans[0].a; ans2 = Ans[1].a; int s = Ans[0].num; sort (Ans, Ans + n, D); if (s == Ans[0].num) { cout << min (ans + Ans[0].b, min (max (ans, Ans[1].b), max (ans2, Ans[0].b))) << endl; } else { cout << max(ans, Ans[0].b); } return 0; }
#include <bits/stdc++.h> using namespace std; const int N=1e6+5; long long arr[N]; int solve() { long long n, mn=LLONG_MAX; cin>>n; set<long long>st; for(int i=0;i<n;i++) { cin >> arr[i]; st.insert(arr[i]); mn = min(mn, arr[i]); } long long ans=mn*n; for(auto j=st.begin();j!=st.end();j++) { long long curan=0; for(int i=0;i<n;i++) { if(arr[i]>=*j) curan+=*j; else curan = 0; ans=max(ans,curan); } curan=0; } cout<<ans; return 0; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt" ,"r" ,stdin); freopen("output.txt" ,"w" ,stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); // int t; // cin>>t; // while(t--) solve(); return 0; }
// code by lynmisakura. wish to be accepted! #include<bits/stdc++.h> using namespace std; #define rep(i,N) for(int i = 0;i < N;i++) #define rng(i,a,b) for(int i = a;i < b;i++) #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define lmd(func) auto func = [&] #define mp make_pair #define pb push_back #define eb emplace_back #define debug(arr) cout << #arr << " = " << arr << '\n' #define debug2(a,b) cout<<"["<<#a<<","<<#b<<"] = "<<"["<<a<<","<<b<<"]\n" #define debug3(a,b,c) cout<<"["<<#a<<","<<#b<<","<<#c<<"] = "<<"["<<a<<","<<b<<","<<c<<"]\n" template<class T> ostream &operator << (ostream& out, const vector<T>& arr) { cout << "{"; for (int i = 0; i < arr.size(); i++)cout << (!i ? "" : ", ") << arr[i]; cout << "}"; return out; } template<class T> ostream &operator << (ostream& out, const vector<vector<T> >& arr) { cout << "{\n"; for (auto& vec : arr)cout << " " << vec << ",\n"; cout << "}"; return out; } template<class S,class T> ostream &operator << (ostream& out, const pair<S,T>& p){ cout << "{" << p.first << "," << p.second << "}" << '\n'; return out; } template<class T> istream &operator >> (istream& in, vector<T>& arr) { for (auto& i : arr)cin >> i; return in; } template<class S,class T> istream &operator >> (istream& in,pair<S,T>& p){ cin >> p.first >> p.second; return in; } using ll = long long; using ld = long double; using vi = vector<int>; using vl = vector<ll>; using pi = pair<int,int>; using pl = pair<ll,ll>; using vpi = vector<pi>; using vpl = vector<pl>; ///////////////////////////////////////////////////////////////////////////// template<class T> void chmin(T& a,T b){ a = min(a,b);} template<class T> void chmax(T& a,T b){ a = max(a,b);} int n; ll mx[200020],mn[200020]; ll dp[200020][2]; int main(void){ cin.tie(0); ios::sync_with_stdio(false); //cout << fixed << setprecision(20); cin >> n; rep(i,n+1){ mx[i] = -INT_MAX; mn[i] = INT_MAX; } vector<int> cs; vector<pair<ll,ll>> a(n); rep(i,n){ ll x,c;cin >> x >> c; c--; a[i] = mp(x,c); cs.pb(c); } sort(all(cs)); cs.erase(unique(cs.begin(),cs.end()),cs.end()); rep(i,n){ auto[x,c] = a[i]; c = lower_bound(all(cs),c) - cs.begin(); chmax(mx[c],x); chmin(mn[c],x); } rep(i,200020)rep(j,2) dp[i][j] = (1LL << 55); int i = 0; dp[i][0] = abs(mx[i]) + mx[i] - mn[i]; dp[i][1] = abs(mn[i]) + mx[i] - mn[i]; // debug2(mn[i],mx[i]); i++; n = cs.size(); for(;i < n;i++){ ll l = mn[i-1],r = mx[i-1]; ll nl = mn[i],nr = mx[i]; chmin(dp[i][0] , dp[i-1][0] + abs(l - nr) + nr - nl); chmin(dp[i][0] , dp[i-1][1] + abs(r - nr) + nr - nl); chmin(dp[i][1] , dp[i-1][0] + abs(l - nl) + nr - nl); chmin(dp[i][1] , dp[i-1][1] + abs(r - nl) + nr - nl); } cout << min(dp[n-1][0] + abs(mn[n-1]),dp[n-1][1] + abs(mx[n-1])) << '\n'; }
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; long long n,x,a[110],f[110][110][110],ans=1145141919810233454; int main() { scanf("%lld %lld",&n,&x); for(int i=1;i<=n;++i) scanf("%lld",&a[i]); for(int s=1;s<=n;++s) { memset(f,-0x3f,sizeof(f)); f[0][0][0]=0; for(int i=1;i<=n;++i) { for(int j=1;j<=min(s,i);++j) { for(int k=0;k<n;++k) f[i][j][k]=max(f[i-1][j][k],f[i-1][j-1][((k-a[i])%s+s)%s]+a[i]); } } if(f[n][s][x%s]>=0) ans=min(ans,(x-f[n][s][x%s])/s); } printf("%lld\n",ans); return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ string S; int64_t M,z=0; cin>>S>>M; int64_t N=S.size(),K=*max_element(S.begin(),S.end())-'0'; if(N<2){ cout<<(M<K?0:1); return 0; } int64_t ok=0,ng=M+10; while(ng-ok>1){ __int128 m=(ok+ng)/2,sum=0,temp=1,l=0; for(int j=N-1;j>=0;temp*=m,j--){ sum+=(S[j]-'0')*temp; if(temp>M){ l=1; break; } } if(l||sum>M)ng=m; else ok=m; } cout<<max(z,ok-K); }
#pragma GCC optimize ("O2") #pragma GCC target ("avx") //#include<bits/stdc++.h> #include<iostream> #include<cstring> //#include<atcoder/all> //using namespace atcoder; using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please char cn[1200010]; char* ci = cn, * di = cn, ct; char tc[200002], *d1 = tc + 100000, *d2 = tc + 200000; const char d[2] = "0"; int main() { cin.tie(0); ios::sync_with_stdio(false); rep(i, 100000) tc[i] = '0'; rep(i, 100000) d1[i] = '1'; d2[0] = '0'; d2[1] = '\n'; fread(cn, 1, 1200010, stdin); int T = 0; while ((ct = *ci++) >= '0') T = T * 10 + ct - '0'; rep(t, T) { int N = 0; while ((ct = *ci++) >= '0') N = N * 10 + ct - '0'; memcpy(di, d1 - N, N); di += N; memcpy(di, d2 - N, N + 2); di += N + 2; ci += 6 * N + 3; } fwrite(cn, 1, di - cn, stdout); Would you please return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define rrep(i, n) for (int i = n - 1; i >= 0; i--) using namespace std; #define INF ((1<<30)-1) #define LINF (1LL<<60) #define EPS (1e-10) typedef long long ll; typedef pair<ll, ll> P; const int MOD = 1000000007; const int MOD2 = 998244353; ll dp[101][1000010]; int main(){ int n, k; ll m; cin >> n >> k >> m; dp[0][0] = 1; for(int i = 1; i <= n; i++){ ll tmp[i+1] = {}; rep(j, 1000010){ int x = j % i; tmp[x] += dp[i-1][j]; if (j - i*(k+1) >= 0) { tmp[x] += m - dp[i-1][j-i*(k+1)]; tmp[x] %= m; } dp[i][j] = tmp[x]; dp[i][j] %= m; } } for(int i = 1; i <= n; i++){ ll res = 0; rep(j, 1000010) { res += (dp[i-1][j] * dp[n-i][j])%m; res %= m; } res *= k + 1; res += m - 1; res %= m; cout << res << endl; } return 0; }
#include <bits/stdc++.h> #define LL long long #define PII pair<int, int> #define PLL pair<LL, LL> #define all_of(v) (v).begin(), (v).end() #define sort_unique(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end())))) #define fi first #define se second const int MAXN = 101; //const LL INF = (LL) 1e9 + 8763; //const LL MOD = (LL) 1e9 + 7; using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int n, mod, k, ans[MAXN], dp[MAXN][MAXN*MAXN*MAXN]; inline int add(int x, int y) { int sum = x + y; if (sum >= mod) sum -= mod; return sum; } void solve() { cin >> n >> k >> mod; int bound = n * (n + 1) / 2 * k; dp[0][0] = 1; for (int i = 1; i <= n; i++) { for (int r = 0; r < i; r++) { int sum = 0; for (int j = r; j <= bound; j += i) { sum = add(sum, dp[i - 1][j]); if (j - (k + 1) * i >= 0) { sum = add(sum, -dp[i - 1][j - (k + 1) * i] + mod); } dp[i][j] = sum; } } } for (int i = 1; i <= n; i++) { int a = i - 1, b = n - i; for (int j = 0; j <= bound; j++) { // cout << "At " << i << ' ' << j << " -> " << dp[a][j] << ' ' << dp[b][j] << '\n'; if (dp[a][j] == 0 || dp[b][j] == 0) continue; ans[i] = (ans[i] + (LL) dp[a][j] * dp[b][j] % mod * (k + 1) % mod) % mod; } ans[i] = (ans[i] - 1 + mod) % mod; } for (int i = 1; i <= n; i++) { cout << ans[i] << "\n"; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int tc = 1; // cin >> tc; for (int i = 1; i <= tc; i++) { solve(); } return 0; }
#include <bits/stdc++.h> //#include <atcoder/all> typedef long long ll; using namespace std; //using namespace atcoder; #define _overload(_1, _2, _3, name, ...) name #define _rep(i, n) for(ll i = 0; i < (ll)n; i++) #define _reps(i, s, n) for(ll i = (ll)(s); i < (ll)n; i++) #define REP(...) _overload(__VA_ARGS__, _reps, _rep,)(__VA_ARGS__) #define all(v) (v).begin(),(v).end() #define UNIQUE(v) (v).erase( unique( all(v) ), (v).end() ); #define MOD 1000000007 ll powll(ll x, ll n){ ll r = 1; while( n > 0 ){ if( n & 1 ) r = x * r; x = x * x; n >>= 1; } return r; } int main(){ ll n; cin >> n; REP(i, 1, 38) REP(j, 1, 26){ if( powll(3, i) + powll(5, j) == n ){ cout << i << " " << j << endl; return 0; } } cout << -1 << endl; return 0; }
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<cmath> #include<vector> #include<queue> #include<stack> #include<ctime> #include<map> #define ll long long #define MAXN 200005 #define uns unsigned #define INF 0x3f3f3f3f #define lowbit(x) ((x)&(-(x))) using namespace std; inline ll read(){ ll x=0;bool f=1;char s=getchar(); while((s<'0'||s>'9')&&s>0){if(s=='-')f^=1;s=getchar();} while(s>='0'&&s<='9')x=(x<<1)+(x<<3)+s-'0',s=getchar(); return f?x:-x; } int n; ll sum,mx,a[MAXN],ans; int main() { n=read(); for(int i=1;i<=n;i++)a[i]=read(); for(int i=1;i<=n;i++){ mx=max(mx,a[i]); sum+=a[i],ans+=sum; printf("%lld\n",ans+mx*i); } return 0; }
#include <bits/stdc++.h> #include <bits/stdint-intn.h> #include <algorithm> #include <cstdint> using namespace std; int main() { int N; cin >> N; vector<int> A(N); for (int i = 0; i < N; i++) { string s; cin >> s; if (s == "AND") { A[i] = 0; } else { A[i] = 1; } } int64_t count0 = 1; int64_t count1 = 1; for (int i = 0; i < N; i++) { int64_t next0 = 0; int64_t next1 = 0; if (A[i]) { // OR // 0 | 0 = 0 // 0 | 1 = 1 // 1 | 0 = 1 // 1 | 1 = 1 next0 = count0; next1 = count0 + count1 * 2; } else { // AND // 0 & 0 = 0 // 0 & 1 = 0 // 1 & 0 = 0 // 1 & 1 = 1 next0 = count0 * 2 + count1; next1 = count1; } count0 = next0; count1 = next1; } cout << count1 << endl; return 0; }
//D #include <bits/stdc++.h> using namespace std; #define sc scanf #define pr printf #define ll long long #define int long long #define mst(x) memset(x, 0 ,sizeof x) #define FILE_OUT freopen("out", "w", stdout); #define FILE_IN freopen("in", "r", stdin); #define debug(a,b) cout<<a<<" : "<<b<<endl; #define INF 0x3f3f3f3f3f3f const ll MAX_N = 1e5+5; const ll mod = 1e9+7; int N, M, K; int arr[MAX_N]; char s[MAX_N]; int dp[MAX_N][2][2]; void solve(){ sc("%lld", &N); dp[0][0][1] = 0; dp[0][0][0] = 1; dp[0][1][1] = 1; dp[0][1][0] = 0; for (int i = 1; i <= N; ++i){ getchar(); sc("%s", s); if (s[0]=='A'){ dp[i][1][1] += dp[i-1][1][1] + dp[i-1][0][1]; dp[i][1][0] += dp[i-1][1][0] + dp[i-1][0][0]; dp[i][0][1] = 0; dp[i][0][0] += dp[i-1][1][0] + dp[i-1][1][1] + dp[i-1][0][1] + dp[i-1][0][0]; }else{ dp[i][1][1] += dp[i-1][1][1] + dp[i-1][0][1] + dp[i-1][1][0] + dp[i-1][0][0]; dp[i][1][0] = 0; dp[i][0][1] += dp[i-1][1][1] + dp[i-1][0][1]; dp[i][0][0] += dp[i-1][1][0] + dp[i-1][0][0]; } } pr("%lld", dp[N][0][1]+dp[N][1][1]); } signed main() { #ifndef ONLINE_JUDGE FILE_OUT #endif int T = 1;//sc("%lld", &T); while (T--) solve(); return 0; }
#include <bits/stdc++.h> #define ll long long int #define vec vector<ll> #define vecp vector<pair<ll,ll> > #define mapp map<ll,ll> #define mapit map<ll,ll>::iterator #define mapr map<pair<ll,ll>,ll> #define maprit map<pair<ll,ll>,ll>::iterator #define fs first #define sc second #define bg begin() #define en end() #define pb push_back #define fin(x,y) for(x=0;x<y;x++) #define fin1(x,y) for(x=1;x<y;x++) #define mod1 1000000007 #define INF 1000000000000000000 #define twodp vector<vec >dp(n+1,vec(k+1,0)) #define all(x) x.bg,x.en #define rel(x) x.rbegin(),x.rend() using namespace std; ll gcd(ll a,ll b) { if(a==0 || b==0) return a+b; else return __gcd(a,b); } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll a,b;cin>>a>>b; ll i,j,k,l;ll ans=0; fin1(i,a+1) { fin1(j,b+1) { l=j+100*i; ans+=l; } } cout<<ans; return 0; }
/** * author: shu8Cream * created: 02.05.2021 10:37:54 **/ #include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i=0; i<(n); i++) #define all(x) (x).begin(), (x).end() using ll = long long; using P = pair<ll,ll>; using vi = vector<double>; using vvi = vector<vi>; int n; double D,H; bool check(double mid, vi &d, vi & h){ rep(i,n){ if((h[i]-mid)*D>(H-mid)*d[i]) return false; } return true; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cin >> n >> D >> H; vi d(n),h(n); rep(i,n) cin >> d[i] >> h[i]; double ok = 0.0, ng = 10000.0; int loop = 100; while(loop--){ double mid = (ok + ng) / 2.0; if(check(mid,d,h)) ng = mid; else ok = mid; } printf("%.10lf\n", ok); }
#include <bits/stdc++.h> #define rep(i,n)for(int i=0;i<(n);i++) using namespace std; typedef long long ll; typedef pair<int,int>P; const int MOD=1000000007; //~ const int MOD=998244353; const int INF=0x3f3f3f3f; const ll INFL=0x3f3f3f3f3f3f3f3f; int c[300000]; unordered_map<int,int>mp[300000]; vector<int>v[300000]; int par[300000]; void merge(int x,int y){//x<-y if(v[x].size()<v[y].size())swap(x,y); for(auto&p:mp[y]){ mp[x][p.first]+=p.second; } for(int i:v[y]){ v[x].push_back(i); par[i]=x; } } int main(){ int n,q;cin>>n>>q; rep(i,n)scanf("%d",&c[i]),c[i]--; rep(i,n){ par[i]=i; v[i].push_back(i); mp[i][c[i]]++; } rep(i,q){ int ty;scanf("%d",&ty); int a,b;scanf("%d%d",&a,&b);a--;b--; if(ty==1){ a=par[a];b=par[b]; if(a!=b)merge(a,b); } else{ a=par[a]; if(!mp[a].count(b))puts("0"); else printf("%d\n",mp[a][b]); } } }
#ifdef LOCAL #define _GLIBCXX_DEBUG #endif #include<bits/stdc++.h> using namespace std; #define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++) #define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--) #define all(x) (x).begin(), (x).end() typedef long long ll; typedef long double ld; typedef pair<ll,ll> Pll; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<vvl> vvvl; constexpr ll INF = numeric_limits<ll>::max()/4; constexpr ll n_max = 2e5+10; #define int ll const long double pi = 3.14159265358979323846; template <typename A, typename B> string to_string(pair<A, B> p); string to_string(const string &s) {return '"' + s + '"';} string to_string(const char *c) {return to_string((string) c);} string to_string(bool b) {return (b ? "true" : "false");} template <size_t N> string to_string(bitset<N> v){ string res = ""; for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]); return res; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for(const auto &x : v) { if(!first) res += ", "; first = false; res += to_string(x); } res += "}"; return res; } template <typename A, typename B> string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";} void debug_out() {cerr << endl;} template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif template<class T> bool chmax(T &a, T b){if(a < b){a = b; return true;} return false;} template<class T> bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;} signed main(){ cin.tie(nullptr); ios::sync_with_stdio(false); ll n,m; cin >> n >> m; vector<ll> w(n); for(int i = 0; i < n; i++) cin >> w[i]; vector<Pll> lv(m); for(auto &[l, v] : lv){ cin >> l >> v; } rep(i,0,n){ bool ok = true; for (auto [l, v] : lv) { ok &= v >= w[i]; } if(!ok){ cout << -1 << endl; return 0; } } map<ll, ll> mp; rep(i,0,1LL << n){ ll tmp = 0; rep(j,0,n){ if((i >> j) & 1){ tmp += w[j]; } } if (mp.count(tmp)) continue; ll len = 0; rep(j,0,m){ auto [l, v] = lv[j]; if (tmp > v) chmax(len, l); } mp[tmp] = len; } vector<ll> v(n); iota(all(v), 0); ll ans = INF; do { vector<ll> pos(n); rep(i,0,n){ ll tmp = w[v[i]]; ll tpos = pos[i]; rep(j, i + 1, n) { tmp += w[v[j]]; ll len = mp[tmp] + tpos; if(chmax(pos[j], len)){ rep(k, j, n) chmax(pos[k], pos[k - 1]); } } } // debug(v, pos); chmin(ans, pos.back() - pos[0]); } while (next_permutation(all(v))); cout << ans << endl; }