code_file1
stringlengths
87
4k
code_file2
stringlengths
85
4k
#include<bits/stdc++.h> #define I inline #define max(a,b) ((a)>(b)?(a):(b)) #define min(a,b) ((a)<(b)?(a):(b)) #define abs(x) ((x)>0?(x):-(x)) #define re register #define ll long long #define db double #define N 100 #define mod 1000000007 #define eps (1e-4) #define U unsigned int #define IT set<ques>::iterator #define Gc() getchar() #define Me(x,y) memset(x,y,sizeof(x)) using namespace std; int n,A[N+5],B[N+5],flag;db nowx,nowy; struct point{db A,B;}S[N+5],C[N+5];I bool cmp(point x,point y){return x.A==y.A?(x.B<y.B):(x.A<y.A);} int main(){ //freopen("1.in","r",stdin); re int i,j;scanf("%d",&n);for(i=1;i<=n;i++) scanf("%d%d",&A[i],&B[i]);for(i=1;i<=n;i++) scanf("%lf%lf",&C[i].A,&C[i].B);sort(C+1,C+n+1,cmp); for(db i=0;i<=360;i+=(5e-4)){nowx=cos(i);nowy=sin(i); for(j=1;j<=n;j++) S[j].A=A[j]*nowx-B[j]*nowy,S[j].B=A[j]*nowy+B[j]*nowx;sort(S+1,S+n+1,cmp); flag=0;nowx=S[1].A-C[1].A;nowy=S[1].B-C[1].B;for(j=2;j<=n;j++) if(abs(S[j].A-C[j].A-nowx)>eps||abs(S[j].B-C[j].B-nowy)>eps){flag=1;break;} if(!flag){printf("Yes\n");return 0;} }printf("No\n"); }
#include <bits/stdc++.h> using namespace std; // clang-format off // #include <atcoder/all> // using namespace atcoder; // using mint = modint1000000007; // using mint = modint998244353 using ll = int64_t; template <class T> istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v) cin >> a; return is; } template <class T> istream& operator>>(istream& is, vector<pair<T, T>>& v) { for (auto& a : v) cin >> a.first >> a.second; return is; } template <class T> istream& operator>>(istream& is, vector<tuple<T, T, T>>& v) { for (auto& a : v) { T a1, a2, a3; cin >> a1 >> a2 >> a3; a = {a1, a2, a3}; } return is; } template<typename T> istream& operator>>(istream &is, complex<T>& c) { double x, y; is >> x >> y; c.real(x); c.imag(y); return is; } template <class T> ostream& operator<<(ostream& os, vector<T>& v) { for (auto& a : v) os << a << " "; os << endl; return os; } 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; } #define all(v) begin(v), end(v) #define rall(v) rbegin(v), rend(v) #define TRC1(a) cout << #a ":" << a #define TRC2(a, b) TRC1(a); cout << " "; TRC1(b) #define TRC3(a, b, c) TRC2(a, b); cout << " "; TRC1(c) #define TRC4(a, b, c, d) TRC3(a, b, c); cout << " "; TRC1(d) #define GET_NAME(_1,_2,_3,_4,NAME,...) NAME #define TRC(...) GET_NAME(__VA_ARGS__, TRC4, TRC3, TRC2, TRC1) (__VA_ARGS__) << endl using veci = vector<int>; using vecll = vector<ll>; using Pi = pair<int, int>; using Ti = tuple<int, int, int>; #define _overload3(_1,_2,_3,name,...) name #define _rep(i,n) repi(i,0,n) #define repi(i,a,b) for(int i=int(a);i<int(b);++i) #define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__) const int IINF = INT32_MAX; const ll LINF = INT64_MAX; // cout << fixed << setprecision(15); void solve(); int main() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(15); solve(); return 0; } // clang-format on void solve() { int N; cin >> N; veci A(N); cin >> A; map<int, int> mp; rep(i, N) { mp[A[i]]++; } ll ans = 0; int k = N; for (int a : A) { ans += k - mp[a]; mp[a]--; k--; } cout << ans << endl; }
#line 1 "F.cpp" #include <bits/stdc++.h> using namespace std::literals::string_literals; using i64 = std::int_fast64_t; using std::cout; using std::cerr; using std::endl; using std::cin; template<typename T> std::vector<T> make_v(size_t a){return std::vector<T>(a);} template<typename T,typename... Ts> auto make_v(size_t a,Ts... ts){ return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); } int main() { int n, t; scanf("%d%d", &n, &t); std::vector<int> a(n); for(auto& v: a) scanf("%d", &v); int A = n / 2, B = n - n / 2; std::vector<i64> X, Y; for(int i = 0; i < (1 << A); i++) { i64 sum = 0; for(int j = 0; j < A; j++) if(i >> j & 1) sum += a[j]; X.push_back(sum); } for(int i = 0; i < (1 << B); i++) { i64 sum = 0; for(int j = 0; j < B; j++) if(i >> j & 1) sum += a[j + A]; Y.push_back(sum); } sort(begin(X), end(X)); sort(begin(Y), end(Y)); i64 ans = 0; int cur = Y.size() - 1; for(int i = 0; i < X.size(); i++) { while(cur >= 0 and X[i] + Y[cur] > t) cur--; if(cur != -1) ans = std::max(ans, X[i] + Y[cur]); } assert(ans <= t); printf("%lld\n", ans); return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <list> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> //#include <atcoder/convolution> //#include <atcoder/modint> //using Modint = atcoder::modint998244353; using namespace std; typedef long long ll; void ex_gcd(ll a, ll b, ll &d, ll &x, ll &y) { if (!b) { d = a; x = 1; y = 0; } else { ex_gcd(b, a % b, d, y, x); y -= a / b * x; } } ll inv(ll a, ll n) { ll d, x, y; ex_gcd(a, n, d, x, y); return d == 1 ? (x % n + n) % (n / d) : -1; } ll gcd(ll x, ll y) { if (y == 0) return x; return gcd(y, x % y); } const int maxn = 1000005; const int mod = 998244353; vector<int>prim; bool b[maxn]; void init(){ for(int i=2;i<maxn;i++){ if(!b[i]){ prim.push_back(i); for(int j=i+i;j<maxn;j+=i)b[j]=1; } } } vector<int>p,c; void dfs(int pos, int cur, int cnt, int l, int r, int& sum){ if(cur>r)return; if(pos==p.size()){ if(cnt==0)return; int tt = r/cur-(l-1)/cur; if(cnt&1)sum += tt; else sum -= tt; return; } dfs(pos+1, cur * p[pos], cnt+1, l,r,sum); dfs(pos+1, cur, cnt, l, r, sum); } void dfs2(int pos, int cur, int l, int r, int&sum){ if(cur>r)return; if(pos==p.size()){ if(cur>=l&&cur<=r)sum++; return; } int tt = 1; for(int i=0;i<=c[pos];i++){ dfs2(pos+1, cur*tt, l,r,sum); tt*=p[pos]; } } int solve(int l, int x) { if(l>=x)return 0; p.clear(); c.clear(); int cur = x; for(int i=0;prim[i]*prim[i]<=cur;i++){ int tt = prim[i]; if(cur%tt==0){ int cnt = 0; while(cur%tt==0){ cur/=tt; cnt++; } p.push_back(tt); c.push_back(cnt); } } if(cur>1){ p.push_back(cur); c.push_back(1); } int sum = 0; dfs(0,1,0,l,x-1,sum); int sum2=0; dfs2(0,1,l,x-1,sum2); return sum-sum2; } int main() { #ifdef suiyuan2009 freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin); freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout); #endif init(); int l,r; cin>>l>>r; ll ret = 0; for(int i=l+1;i<=r;i++){ ret += solve(max(2, l), i); } cout<<ret*2<<endl; return 0; }
#include <iostream> #include <iomanip> #include <algorithm> #include <array> #include <cassert> #include <optional> #include <utility> #include <vector> #include <cmath> // #include <atcoder/all> template <class InputIterator> std::ostream& range_output(std::ostream& os_arg, InputIterator first_arg, InputIterator last_arg){ if(first_arg != last_arg){ do{ os_arg << *(first_arg++); if(first_arg == last_arg) break; os_arg << ' '; } while(true); } return os_arg; } template <class Tp> std::ostream& operator << (std::ostream& os_arg, const std::vector<Tp>& arr_arg){ return range_output(os_arg, arr_arg.cbegin(), arr_arg.cend()); } template <class Tp, std::size_t Size> std::ostream& operator << (std::ostream& os_arg, const std::array<Tp, Size>& arr_arg){ return range_output(os_arg, arr_arg.cbegin(), arr_arg.cend()); } template <class S, class T> std::ostream& operator << (std::ostream& os_arg, const std::pair<S, T>& pair_arg){ return os_arg << '(' << pair_arg.first << ", " << pair_arg.second << ')'; } #ifndef ONLINE_JUDGE template <typename Head> void dump_out(Head head_arg){ std::cerr << head_arg << '\n'; } template <typename Head, typename... Tail> void dump_out(Head head_arg, Tail... tail_args){ std::cerr << head_arg << ", "; dump_out(tail_args...); } #define dump(...) do { std::cerr << "[in line " << __LINE__ << "] " << #__VA_ARGS__ << " : "; dump_out(__VA_ARGS__); } while(false) #else #define dump(...) (void(0)) #endif template <class S, class T> bool chmax(S& x, const T& y){ if(x < y){ x = y; return true; } return false; } template <class S, class T> bool chmin(S& x, const T& y){ if(x > y){ x = y; return true; } return false; } struct nimotsu { int size, value; }; int main(void){ std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(16); int n, m, q; std::cin >> n >> m >> q; std::vector<nimotsu> P(n); for(int i = 0; i < n; ++i) std::cin >> P[i].size >> P[i].value; std::sort(P.begin(), P.end(), [](const nimotsu& x, const nimotsu& y){ if(x.value != y.value) return x.value > y.value; return x.size < y.size; }); std::vector<int> X(m); for(int i = 0; i < m; ++i) std::cin >> X[i]; // [l, r) const auto solve = [&](int l, int r) -> int { std::vector<int> S; S.reserve(m - (r - l)); for(int i = 0; i < l; ++i) S.push_back(X[i]); for(int i = r; i < m; ++i) S.push_back(X[i]); std::sort(S.begin(), S.end()); long long int used = -1; int res = 0; for(const int s : S){ for(int i = 0; i < n; ++i){ if(((used >> i) & 1) and P[i].size <= s){ res += P[i].value; used ^= (1LL << i); break; } } } return res; }; while(q--){ int l, r; std::cin >> l >> r; --l; std::cout << solve(l, r) << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG #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++) using Int = long long; int vmax(vector<int> w,vector<int> v, vector<int> x){ int n=w.size(); int m=x.size(); int ans=0; sort(x.begin(),x.end()); rep(i,m){ vector<int> can_keep_num(0); rep(j,n){ if(w[j]<=x[i]){ can_keep_num.push_back(j); } } if(can_keep_num.size()==0) continue; int max_num=0; int can_max=0; for(int j: can_keep_num){ if(v[j]>can_max){ can_max=v[j]; max_num=j; } else if(v[j]==can_max){ if(w[j]>w[max_num]) max_num=j; } } ans+=can_max; w[max_num]=1000001; } return ans; } int main(){ int n,m,q;cin>>n>>m>>q; vector<int> w(n); vector<int> v(n); vector<int> x(m); rep(i,n){ cin>>w[i]>>v[i]; } rep(i,m) cin>>x[i]; rep(i,q){ vector<int> y(m); rep(j,m) y[j]=x[j]; int l,r; cin>>l>>r; rep2(j,l-1,r) x[j]=0; cout<<vmax(w,v,x)<<endl; rep(j,m) x[j]=y[j]; } }
#include <bits/stdc++.h> using namespace std; using ll = long long; void solve() { int n; cin>>n; ll a, sum=0, high=0, ans=0; for(int i=0; i<n; i++) { cin>>a; sum+=a; ans+=sum; high=max(high, a); cout<<ans+(i+1)*high<<endl; } return; } int main() { #ifdef bipinpathak (void)!freopen("input.txt", "r", stdin); (void)!freopen("output.txt", "w", stdout); #endif ios::sync_with_stdio(false); cin.tie(NULL); auto start=clock(); int t = 1; //cin>>t; for(int i=0; i<t; i++) { //cout<<"Case #"<<i+1<<": "; solve(); } double used= (double) (clock()-start); used=(used*1000)/CLOCKS_PER_SEC; cerr<<fixed<<setprecision(2)<<used<<" ms"<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long int main(){ ll N,max = 0,sum = 0,ans = 0; cin >> N; vector<ll> A(N),B(N); for(ll i = 0; i < N; i++) { cin >> A.at(i); } for(ll i = 0; i < N; i++){ if(max < A.at(i)) max = A.at(i); sum += A.at(i); ans += sum; cout << ans + (i + 1) * max << endl; } }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)n;i++) using namespace std; using ll = long long; using P = pair<int, int>; int main() { int n; cin >> n; vector<ll> a(n); rep(i, n) cin >> a[i]; ll ans = 0; rep(i, n) ans += abs(a[i]); cout << ans << endl; ans = 0; rep(i, n) ans += a[i] * a[i]; cout << fixed << setprecision(15) << sqrt(ans) << endl; ans = 0; rep(i, n) ans = max(abs(a[i]), ans); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #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 { #ifndef ONLINE_JUDGE ~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__) << "] " // debug & operator << (debug & dd, P p) { dd << ", " << p.x << ", " << p.y << ")"; return dd; } #define ll long long const ll nax = 2e5 + 5; vector<ll> edges[nax], vis(nax, 0); ll cnt = 0; void dfs(ll node) { cnt++; vis[node] = 1; for(ll x: edges[node]) { if(vis[x] == 0) { dfs(x); } } } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("error.txt", "w", stderr); #endif ll n; cin >> n; vector<ll> a(n); for(ll i = 0; i < n; ++i) { cin >> a[i]; } for(ll i = 0; i < n; ++i) { edges[a[i]].push_back(a[n - i - 1]); edges[a[n - i - 1]].push_back(a[i]); } ll ans = 0; for(ll i = 0; i < nax; ++i) { if(vis[i] == 0) { cnt = 0; dfs(i); ans = ans + max(0ll, cnt - 1); } } cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; using ll = long long; int main() { ll n,m; cin >> m >> n; ll ar[m*n]; ll min = 101; for(ll i = 0; i < m*n; i++) { cin >> ar[i]; if(ar[i] < min) min = ar[i]; } ll kount = 0; for(ll i = 0; i < m*n; i++) { if(ar[i] > min) kount = kount + ar[i] - min; } cout << kount << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define tcase int _; cin >> _; while(_--) //#define int long long const int MOD = 1e9+7; const int MAX = 1e6; const int INF = 2e9; int v[1000][1000]; void solve() { int h,w; cin >> h >> w; int mn = INF; for(int i=0; i<h; i++) for(int j=0; j<w; j++) { cin >> v[i][j]; mn = min(mn, v[i][j]); } int ans=0; for(int i=0; i<h; i++) for(int j=0; j<w; j++) ans += v[i][j] - mn; cout << ans << endl; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); solve(); return 0; }
//https://atcoder.jp/contests/zone2021/tasks/zone2021_c #include <bits/stdc++.h> using namespace std; typedef long long ll; bool chk(vector<vector<int>> &arr, int mid) { int n=arr.size(); set<int> st; for (int i = 0; i < n; i++) { int c=0; for (int j = 0; j < 5; j++) { int bit=0; if(arr[i][j]>=mid) bit=1; c+=(bit<<j); } st.insert(c); } for(auto e:st) for(auto f:st) for(auto g:st) { if((e|f|g)==31) return 1; } return 0; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<vector<int>> arr(n, vector<int>(5, 0)); for (int i = 0; i < n; i++) { for (int j = 0; j < 5; j++) cin >> arr[i][j]; } int l = 1, r = 1e9 + 1; while (l < r) { int mid = (l + r)/2; if(chk(arr,mid)) l=mid+1; else r=mid; } cout<<l-1<<endl; }
#include <bits/stdc++.h> #define _overload3(_1,_2,_3,name,...)name #define _rep(i,n)repi(i,0,n) #define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i) #define MSVC_UNKO(x)x #define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__)) #define all(c)c.begin(),c.end() #define write(x)cout<<(x)<<'\n' using namespace std; using ll = long long; template<class T>using vv = vector<vector<T>>; template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); } constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60; struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa; int main() { int N; cin >> N; array<vector<int>, 5> A; rep(i, 5) A[i].resize(N); rep(i, N) cin >> A[0][i] >> A[1][i] >> A[2][i] >> A[3][i] >> A[4][i]; int low = 1, high = 1e9 + 1; vector<int> B(N); array<int, 1 << 5> cnt; while (high - low > 1) { int mid = (low + high) / 2; B.assign(N, 0); rep(k, 5) rep(i, N) { B[i] |= (A[k][i] >= mid) << k; } fill(all(cnt), 0); rep(i, N) { cnt[B[i]]++; } bool ok = false; rep(a, 1 << 5) { if (cnt[a] == 0) continue; rep(b, 1 << 5) { if (cnt[b] == 0) continue; rep(c, 1 << 5) { if (cnt[c] == 0) continue; int bit = a | b | c; if (bit == (1 << 5) - 1) ok = true; } } } if (ok) low = mid; else high = mid; } write(low); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ii> vii; #define FOR(i, a, b) for(int i = a; i < b; i++) #define ROF(i, a, b) for(int i = a; i >= b; i--) #define ms memset #define pb push_back #define F first #define S second ll MOD = 998244353; ll power(ll base, ll n){ if (n == 0) return 1; if (n == 1) return base; ll halfn = power(base, n/2); if (n % 2 == 0) return (halfn * halfn) % MOD; return (((halfn * halfn) % MOD) * base) % MOD; } ll inverse(ll n){ return power(n, MOD-2); } ll add(ll a, ll b){ return (a+b) % MOD; } ll mul(ll a, ll b){ return (a*b) % MOD; } ll gcd(ll a, ll b){ if (a == 0) return b; if (a == 1) return 1; return gcd(b%a, a); } int main(){ ios::sync_with_stdio(false); int n; cin >> n; vi X(n), Y(n); FOR(i, 0, n) cin >> X[i] >> Y[i]; int m; cin >> m; vector<ll> sX(m+1), sY(m+1), valX(m+1), valY(m+1), cnt(m+1); sX[0] = 1; sY[0] = 1; FOR(i, 1, m+1){ int op; cin >> op; if (op == 1){ cnt[i] = cnt[i-1] + 1; valX[i] = valY[i-1]; valY[i] = -valX[i-1]; if (cnt[i] % 2 == 1){ sX[i] = -sX[i-1]; sY[i] = sY[i-1]; }else{ sX[i] = sX[i-1]; sY[i] = -sY[i-1]; } continue; } if (op == 2){ cnt[i] = cnt[i-1] + 1; valX[i] = -valY[i-1]; valY[i] = valX[i-1]; if (cnt[i] % 2 == 1){ sX[i] = sX[i-1]; sY[i] = -sY[i-1]; }else{ sX[i] = -sX[i-1]; sY[i] = sY[i-1]; } } if (op == 3){ ll p; cin >> p; cnt[i] = cnt[i-1]; valX[i] = 2*p - valX[i-1]; valY[i] = valY[i-1]; if (cnt[i] % 2 == 0){ sX[i] = -sX[i-1]; sY[i] = sY[i-1]; }else{ sX[i] = sX[i-1]; sY[i] = -sY[i-1]; } continue; } if (op == 4){ ll p; cin >> p; cnt[i] = cnt[i-1]; valX[i] = valX[i-1]; valY[i] = 2*p - valY[i-1]; if (cnt[i] % 2 == 0){ sX[i] = sX[i-1]; sY[i] = -sY[i-1]; }else{ sX[i] = -sX[i-1]; sY[i] = sY[i-1]; } } } int q; cin >> q; while (q--){ int a, b; cin >> a >> b; ll x = valX[a], y = valY[a]; if (cnt[a] % 2 == 1){ y += sX[a] * X[b-1]; x += sY[a] * Y[b-1]; }else{ x += sX[a] * X[b-1]; y += sY[a] * Y[b-1]; } cout << x << " " << y << '\n'; } return 0; }
#include<bits/stdc++.h> using namespace std; #define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define int long long int #define fi first #define se second #define pub push_back #define pi pair<int,int> #define all(v) (v).begin(), (v).end() #define rep(i, l, r) for(int i=(int)(l);i<(int)(r);i++) #define repd(i, l, r) for (int i=(int)(l);i>=(int)(r);i--) #define clrg(i, l, r) for(int i=(int)(l);i<(int)(r);i++)vis[i]=0,v[i].clear(); int power(int x, unsigned int y){int res = 1;while (y > 0){ if (y & 1){res = res*x;} y = y>>1;x = x*x;}return res;} int powermod(int x, unsigned int y, int p){int res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;} #define print2d(mat,n,m){for(int i=0;i<(int)(n);i++){for(int j=0;j<(m);j++){cout<<mat[i][j]<<" ";}cout<< endl;}} #define clr(a,x) memset(a,x,sizeof(a)) #define rr(v) for(auto &val:v) #define print(v) for (const auto itr : v){cout<<itr<<' ';}cout<<"\n"; #define ln length() #define sz size() #define mod 1000000007 #define elif else if int32_t main(){ fastIO int n,y; cin>>n>>y; map<int,int> mp; int ans=0; rep(i,0,n){ int a,b,c; cin>>a>>b>>c; mp[a]+=c; mp[b+1]-=c; } int prev=-1; rr(mp){ if(prev!=-1){ ans+=(val.fi-prev)*y; } prev=val.fi; } prev=-1; rr(mp){ if(prev!=-1){ if(y>mp[prev])ans-=(val.fi-prev)*y,ans+=(val.fi-prev)*mp[prev]; val.se+=mp[prev]; } prev=val.fi; } cout<<ans<<"\n"; return 0; }
#include<bits/stdc++.h> using namespace std; int n; int main() { cin >> n; vector<vector<int> > C( n,vector<int>( n ) ); vector<int> A( n ), B( n ); for( auto &i:C ) for( auto &j:i ) cin >> j; int minval=numeric_limits<int>::max(),mini=0,minj=0; for( int i=0;i<n;++i ) { for( int j=0;j<n;++j ) { if( C[i][j]<minval ) minval=C[i][j],mini=i,minj=j; } } for( int i=0;i<n;++i ) B[i]=C[mini][i]; for( int i=0;i<n;++i ) { if( C[i][minj]-minval<0 ) exit( ( puts( "No" ),0 ) ); A[i]=C[i][minj]-minval; for( int j=0;j<n;++j ) { if( ( C[i][minj]-minval )^( C[i][j]-B[j] ) ) exit( ( puts( "No" ),0 ) ); } } puts( "Yes" ); for( int i:A ) cout << i << ' '; cout << "\n"; for( int i:B ) cout << i << ' '; cout << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int n; vector<long long> a, b; vector<vector<long long>> c; bool solve(); int main() { cin >> n; c.resize(n); for (auto &v : c) { v.resize(n); for (auto &p : v) cin >> p; } if (solve()) { for (long long i = 0; i < n; ++i) for (long long j = 0; j < n; ++j) assert(c[i][j] == a[i] + b[j]); cout << "Yes" << endl; for (long long i = 0; i < n; ++i) cout << a[i] << " \n"[i == n - 1]; for (long long i = 0; i < n; ++i) cout << b[i] << " \n"[i == n - 1]; } else cout << "No" << endl; return 0; } bool solve() { { long long sum = 0; for (int i = 0; i < n; ++i) sum += c[i][i]; for (int i = 0; i < n; ++i) { long long now = 0; for (int j = 0; j < n; ++j) now += c[(i + j) % n][j]; if (now != sum) return 0; } } a.resize(n); b.resize(n); vector<vector<long long>> memo(n, vector<long long>(n, 0)); vector<long long> sum(n); for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) sum[i] += c[i][j]; for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) { if (abs(sum[i] - sum[j]) % n != 0) return 0; memo[i][j] = (sum[i] - sum[j]) / n; } for (int i = 0; i < n; ++i) { bool ch = 1; for (int j = 0; j < n; ++j) if (memo[i][j] > 0) ch = 0; if (ch) { b = c[i]; for (int j = 0; j < n; ++j) a[j] = memo[j][i]; return 1; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; vector<vector<int>> adj(n); for (int i = 0; i < m; ++i) { int u, v; cin >> u >> v; --u, --v; adj[u].push_back(v); adj[v].push_back(u); } vector<bool> vis(n, 0); int sz; function<void(int)> dfs1 = [&](int u) { sz++; vis[u] = 1; for (int v : adj[u]) if (!vis[v]) dfs1(v); }; int offset, pos; vector<int> colour(n); function<bool(int)> dfs2 = [&](int u) { pos++; for (int v : adj[u]) { if (colour[v] == colour[u]) { return false; } if (colour[v] == -1) { colour[v] = (colour[u] + ((offset >> pos) & 1) + 1) % 3; if (!dfs2(v)) return false; } } return true; }; long long ans = 1; for (int i = 0; i < n; ++i) { if (vis[i]) continue; sz = 0; dfs1(i); int cur = 0; for (offset = 0; offset < (1 << (sz - 1)); ++offset) { colour.assign(n, -1); colour[i] = 0; pos = -1; if (dfs2(i)) cur += 3; } ans *= cur; } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0; i < (int)n; i++) using ll = long long; using P = pair<int,int>; int main(){ int n, m; cin >> n >> m; vector<P> v(n); vector<vector<int>> g(n); vector<int> a(m), b(m); rep(i,m) { cin >> a[i] >> b[i]; a[i]--; b[i]--; g[a[i]].push_back(b[i]); g[b[i]].push_back(a[i]); } vector<int> c(n,-1); ll cnt = 0; rep(i,n) if(g[i].size() == 0) cnt++; ll ans = 0; auto dfs = [&](auto self, int id) -> void { if(id == m) { ans++; return; } if(c[a[id]] != -1 and c[b[id]] != -1) { if(c[a[id]] != c[b[id]]) self(self,id+1); } else if(c[a[id]] != -1) { rep(i,3) if(i != c[a[id]]) { c[b[id]] = i; self(self,id+1); c[b[id]] = -1; } } else if(c[b[id]] != -1) { rep(i,3) if(i != c[b[id]]) { c[a[id]] = i; self(self,id+1); c[a[id]] = -1; } } else { rep(i,3) rep(j,3) { if(i != j) { c[a[id]] = i, c[b[id]] = j; self(self,id+1); c[a[id]] = -1, c[b[id]] = -1; } } } return; }; dfs(dfs,0); rep(i,cnt) ans *= 3; cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; using lli = long long; #define rep(i,n) for(int i=0;i<n;i++) 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; } void printv(vector<lli> x){ cout << "{"; rep(i, x.size()){ cout << x[i]; if(i != x.size()-1) cout << " "; } cout << "}" << endl; } lli n; int main(void){ cin >> n; vector<lli> a(n); rep(i, n) cin >> a[i]; sort(a.begin(), a.end()); for(int i = 1; i < n; i++) a[i]%=a[0]; sort(a.begin(), a.end()); while(1){ bool f = true; rep(i, n){ if(a[i] != 0 && a[n-1]%a[i] != 0){ f = false; } } lli mv; rep(i, n){ if(a[i] != 0){ mv = a[i]; break; } } if(f){ cout << mv << endl; return 0; } rep(i, n) a[i]%=mv; } return 0; }
#pragma GCC optimize("Ofast") #include<bits/stdc++.h> using namespace std; //#include<boost/multiprecision/cpp_int.hpp> //#include<boost/multiprecision/cpp_dec_float.hpp> //namespace mp=boost::multiprecision; //#define mulint mp::cpp_int //#define mulfloat mp::cpp_dec_float_100 struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init; #define max3(a,b,c) max(a,max(b,c)) #define min3(a,b,c) min(a,min(b,c)) constexpr int MOD=1000000007; //constexpr int MOD=998244353; #define INF (1<<30) #define LINF (lint)(1LL<<56) #define endl "\n" #define rep(i,n) for(lint (i)=0;(i)<(n);(i)++) #define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--) #define Flag(x) (1<<(x)) #define Flagcount(x) __builtin_popcountll(x) #define pint pair<int,int> #define pdouble pair<double,double> #define plint pair<lint,lint> #define fi first #define se second typedef long long lint; int dx[8]={1,1,0,-1,-1,-1,0,1}; int dy[8]={0,1,1,1,0,-1,-1,-1}; const int MAX_N=2e5+5; //struct edge{lint to,num;}; //vector<int> bucket[MAX_N/1000]; lint LCM(lint a,lint b){ if(a==0 || b==0) return 0; lint tmp,r,x; x=a*b; if(a<b) tmp=a,a=b,b=tmp; r=a%b; while(r!=0) a=b,b=r,r=a%b; x=x/b; return x; } lint GCD(lint a,lint b){ if(a==0 || b==0) return max(a,b); else return (a*b)/LCM(a,b); } int main(void){ int N; cin >> N; lint A[N]; rep(i,N) cin >> A[i]; lint ans=A[0]; for(int i=1;i<N;i++) ans=GCD(ans,A[i]); cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, l, r) for (int i = (l); i < (r); i++) using namespace std; typedef long long ll; ll dp[101][101][10001], MOD = 998244353, f[101]; int main() { f[0] = 1; rep(i, 0, 100) f[i + 1] = (f[i] * (i + 1)) % MOD; int N; cin >> N; vector<int> W(N); ll s = 0; rep(i, 0, N) { cin >> W[i]; s += W[i]; } if (s % 2) { cout << 0 << endl; return 0; } dp[0][0][0] = 1; rep(i, 0, N) { rep(j, 0, N) { rep(k, 0, j * 100 + 100) { dp[i + 1][j][k] = (dp[i + 1][j][k] + dp[i][j][k]) % MOD; dp[i + 1][j + 1][k + W[i]] = (dp[i + 1][j + 1][k + W[i]] + dp[i][j][k]) % MOD; } } } ll ans = 0; rep(i, 1, N) { ans = (ans + f[i] * f[N - i] % MOD * dp[N][i][s / 2]) % MOD; } cout << ans << endl; /* rep(i, 0, N + 1) { rep(j, 0, 101) { rep(k, 0, 10001) { if (dp[i][j][k] > 0) cout << i << " " << j << " " << k << " " << dp[i][j][k] << endl; } } } */ }
/* Lucky_Glass */ #include <cstdio> #include <cstring> #include <algorithm> const int N = 105, MOD = 998244353; inline int add(int a, const int &b) { return (a += b) >= MOD ? a - MOD : a; } inline int sub(int a, const int &b) { return (a -= b) < 0 ? a + MOD : a; } inline int mul(const int &a, const int &b) { return int(1ll * a * b % MOD); } #define ITERON(a, b, fun) a = fun(a, b) int n; int dp[2][N * N * 2][N], bino[N][N]; #define f(i, s, k) dp[(i) & 1][(s) + N * N][k] int main() { scanf("%d", &n); f(0, 0, 0) = 1; for (int i = 1, tmp, sum = 0; i <= n; ++i) { scanf("%d", &tmp); for (int s = -sum; s <= sum; ++s) for (int k = 0; k <= i; ++k) f(i, s, k) = 0; for (int s = -sum; s <= sum; ++s) for (int k = 0; k <= i; ++k) { ITERON(f(i, s + tmp, k + 1), mul(f(i - 1, s, k), k + 1), add); ITERON(f(i, s - tmp, k), mul(f(i - 1, s, k), i - k), add); } sum += tmp; } int ans = 0; for (int k = 0; k <= n; ++k) ITERON(ans, f(n, 0, k), add); printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #define gp __gnu_pbds #define iset(T) gp::tree<T,gp::null_type,less<T>,gp::rb_tree_tag,gp::tree_order_statistics_node_update> using namespace std; #define SQ(x) ((x)*(x)) #define u unsigned #define ull unsigned long long #define ll long long #define ld long double #define test(x) cout<<"here "<<x<<endl; #define debug(x) cout<<(#x)<<": "<<(x)<<endl; #define inputstl(v) for(auto& x:v) cin>>x; #define input(arr,n) for(ull i=0;i<n;++i){cin>>arr[i];} #define print(arr,n) for(ull i=0;i<n;++i){cout<<arr[i]<<" ";}cout<<'\n'; #define printall(x) for(auto y:x){cout<<y<<' ';}cout<<'\n'; #define printallpii(x) for(auto y:x){cout<<y.fi<<','<<y.se<<' ';}cout<<'\n'; #define fi first #define se second #define pb push_back #define eb emplace_back #define mp make_pair #define mt make_tuple #define pii pair<int,int> #define mod (ll)(998244353) #define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); #define SENSITIVITY 1e-9 #define EQUAL(x1,x2) [](auto x1,auto x2){double ep=0.0001;double pos=x1-x2;if(pos<0){pos=-pos;}double maxi=(x1>x2)?(x1):(x2);if(pos/(maxi*ep)<SENSITIVITY)return true;else return false;}(x1,x2) bool isPrime(ll a) { if(a==1) return false; for(ll i=2; i*i<=a; ++i) { if(a%i==0) { return false; } } return true; } bool isPali(string s) { int _size=(s.length())/2; for(int i=0; i<_size; ++i) { if(s.at(i)!=s.at(s.length()-1-i)) { return false; } } return true; } int gcd(int a,int b) { if(a==0) { return b; } else if(b==0) { return a; } else { int shift=__builtin_ctz(a|b); a>>=__builtin_ctz(a); do { b>>=__builtin_ctz(b); if(a>b) { a=a^b; b=a^b; a=a^b; } b-=a; } while(b); return a<<shift; } } ll gcdll(ll a,ll b) { if(a==0) { return b; } else if(b==0) { return a; } else { ll shift=__builtin_ctzll(a|b); a>>=__builtin_ctzll(a); do { b>>=__builtin_ctzll(b); if(a>b) { a=a^b; b=a^b; a=a^b; } b-=a; } while(b); return a<<shift; } } ll power(ll a,ll b,ll _mod) { ll temp=a; ll ans=1; int limit=63-__builtin_clzll(b); int index=0; while(index<=limit) { if(b&(1ll<<index)) { ans=(ans*temp)%_mod; } ++index; temp=(temp*temp)%_mod; } return ans; } int main() { // #define cin fin // ifstream fin; // fin.open("input.txt",ios_base::in); fastio; int tt=1; cin>>tt; while(tt--) { ll L,R,c,d; cin>>L>>R; if(2*L>R) { cout<<0<<'\n'; continue; } c=2*L; d=R; ll s=((d-c+1)*(c+d))/2; cout<<s-(d-c+1)*c+(d-c+1)<<'\n'; } return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define For(i,a,b,c) for(ll i=a;i<b;i+=c) #define For2(i,a,b,c) for(ll i=a;i>=b;i-=c) #define vec_ll vector<vector<ll>> #define vec_pr vector<pair<ll,ll>> #define p_ll pair<ll,ll> #define pbk push_back #define mkpr make_pair #define fst first #define snd second void print(ll *arr, ll n){ For(i,0,n,1)cout<<arr[i]<<" "; cout<<endl; } void print_vec(vector<ll> &vec, ll n){ For(i,0,n,1)cout<<vec[i]<<" "; cout<<endl; } bool s_sec(const pair<ll,ll> &a, const pair<ll,ll> &b) { return (a.second < b.second); } ll fast_expo(ll a, ll p){ //cout<<a<<" "; ll x=p-2; ll curr=a; ll ans=1; while(x!=0){ if(x%2==1){ ans=(ans*curr)%p; } x/=2; curr=(curr*curr)%p; } return ans; } /// /// int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll t; cin>>t; while(t--){ ll L,R; cin>>L>>R; ll ans=0; if(R>=2*L){ ll len=(R-2*L)+1; if(len%2==0){ ll half=(len/2); ans=2*half*(half+1); ans-=(half); } else{ ll half=(len+1)/2; ans=(2*half*half); ans-=half; } } cout<<ans<<"\n"; } }
/* @uthor: Amit Kumar user -->GitHub: drviruses ; CodeChef: dr_virus_ ; Codeforces,AtCoder,Hackerearth,Hakerrank: dr_virus; */ #include <bits/stdc++.h> #include <chrono> using namespace std; using namespace std::chrono; //#include <boost/multiprecision/cpp_int.hpp> //namespace mp = boost::multiprecision; //#define ln mp::cpp_int; #define int long long #define double long double #define uint unsigned long long #define all(vec) vec.begin(),vec.end() #define endl "\n" int google_itr = 1; #define google(x) cout<<"Case #"<<x<<": " #define pi 3.14159265358979323846264338327950L vector<string> vec_splitter(string s) { s += ','; vector<string> res; while(!s.empty()) { res.push_back(s.substr(0, s.find(','))); s = s.substr(s.find(',') + 1); } return res; } void debug_out( vector<string> __attribute__ ((unused)) args, __attribute__ ((unused)) int idx, __attribute__ ((unused)) int LINE_NUM) { cerr << endl; } template <typename Head, typename... Tail> void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) { if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") "; stringstream ss; ss << H; cerr << args[idx] << " = " << ss.str(); debug_out(args, idx + 1, LINE_NUM, T...); } #define XOX #ifdef XOX #define deb(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__) #else #define deb(...) 42 #endif const int mod = 1e9+7; const int inf = 1e18; void virus(){ int len; cin >> len; set <int> arr; for(auto i=0; i<=200000; i++) arr.insert(i); for(auto i=0; i<len; i++){ int val; cin >> val; arr.erase(val); cout << *arr.begin() << endl; } } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); /*#ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif*/ int t = 1; //cin >> t; while(t--){ auto start = high_resolution_clock::now(); virus(); auto stop = high_resolution_clock::now(); auto duration = duration_cast<seconds>(stop - start); //cerr << "\n Time: "<<duration.count()<<endl; //your code goes here } return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n; cin>>n; vector<bool> used(200001,0); int x=0; vector<int> p(n); for(int i=0;i<n;i++){ cin>>p[i]; used[p[i]]=true; while(used[x]){ x++; } cout<<x<<'\n'; } return 0; }
#include<bits/stdc++.h> using namespace std; # define ll long long # define read read1<ll>() # define Type template<typename T> Type T read1(){ T t=0; char k; bool vis=0; do (k=getchar())=='-'&&(vis=1);while('0'>k||k>'9'); while('0'<=k&&k<='9')t=(t<<3)+(t<<1)+(k^'0'),k=getchar(); return vis?-t:t; } # define fre(k) freopen(k".in","r",stdin);freopen(k".out","w",stdout) char Str[400005]; int a[400005],s,b[400005];; bool vis[400005]; int sta[400005]; int main(){ s=read;int n=s*2; for(int i=1;i<=n;++i)a[i]=read,b[i]=i; nth_element(b+1,b+s+1,b+n+1,[&](const int &x,const int &y){return a[x]<a[y];}); for(int i=1;i<=s;++i)vis[b[i]]=1; for(int i=1;i<=n;++i){ if(!*sta)sta[++*sta]=i,Str[i]='('; else{ if(vis[sta[*sta]]^vis[i])--*sta,Str[i]=')'; else sta[++*sta]=i,Str[i]='('; } }puts(Str+1); return 0; }
#include<bits/stdc++.h> using namespace std; // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/detail/standard_policies.hpp> // using namespace __gnu_pbds; #pragma GCC optimize("O3") #ifdef LOCAL #include "/Users/lbjlc/Desktop/coding/debug_utils.h" #else #define print(...) ; #define printn(...) ; #define printg(...) ; #define fprint(...) ; #define fprintn(...) ; #endif #define rep(i, a, b) for(auto i = (a); i < (b); i++) #define rrep(i, a, b) for(auto i = (a); i > (b); i--) #define all(v) (v).begin(), (v).end() #define pb push_back // #define mp make_pair #define fi first #define se second #define maxi(x, y) x = max(x, y) #define mini(x, y) x = min(x, y) // long long fact(long long n) { if(!n) return 1; return n*fact(n-1); } // #define endl '\n' mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int get_random() { static uniform_int_distribution<int> dist(0, 1e9 + 6); return dist(rng); } #define solve_testcase int T;cin>>T;for(int t=1;t<=T;t++){solve(t);} typedef unsigned long long ull; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<double, double> pdd; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<vvi> vvvi; typedef vector<pii> vpii; typedef vector<pll> vpll; typedef vector<pdd> vpdd; typedef vector<long long> vll; #define bd(type,op,val) bind(op<type>(), std::placeholders::_1, val) template<class T> void make_unique(T & v) { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); } int geti() { int x; cin >> x; return x; } long long getll() { long long x; cin >> x; return x; } double getd() { double x; cin >> x; return x; } // pair<int, int> a(geti(), geti()) does not work // pair<int, int> a({geti(), geti()}) works, since it uses initializer. const int MAXN = 3e5 + 100; void solve(int tt) { // cout<<"Case #"<<tt<<": "; } array<int,3> e[MAXN]; int c[MAXN],vis[MAXN]={}; vpii graph[MAXN]; void dfs(int i, int p) { vis[i]=1; print("vis",i); for(auto [j,idx]:graph[i]) { if(j==p)continue; if(c[j]>c[i]) continue; print(i,j); if(e[idx][2]<0) { if(e[idx][0] == i) e[idx][2]=1; else e[idx][2]=0; } if(!vis[j]) dfs(j,i); } } int main(int argc, char * argv[]) { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); // solve_testcase; int n,m; cin>>n>>m; int u,v; rep(i,0,m){ cin>>u>>v; e[i][0] = u; e[i][1] = v; e[i][2] = -1; graph[u].pb({v,i}); graph[v].pb({u,i}); } rep(i,1,n+1) { cin>>c[i]; } rep(i,1,n+1) { if(!vis[i]) dfs(i,-1); } printn(e,m); rep(i,0,m) { if(e[i][2]==1)cout<<"->"<<endl; else cout<<"<-"<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,n) for(ll i=0;i<(ll)(n);i++) #define rep1(i,n) for(ll i=1;i<=(ll)(n);i++) int main(){ ios::sync_with_stdio(false); cin.tie(0); ll n,k; cin >> n >> k; k = abs(k); ll ans = 0; for(ll ab = k+2; ab<=2*n;ab++){ ll abc, cdc; if(ab-1 < n){ abc = ab-1; } else{ abc = 2*n-ab +1; } ll cd = ab-k; if(cd-1 < n){ cdc = cd-1; } else{ cdc = 2*n-cd +1; } ans += abc*cdc; // cout << ans << endl; } cout << ans << endl; 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 - 1; i >= b; i--) #define rng(a) a.begin(), a.end() #define rrng(a) a.rbegin(), a.rend() #define pb push_back #define eb emplace_back #define fi first #define se second #define ll long long #define out(x) std::cout << fixed << setprecision(15) << x << '\n'; return 0 #define INT(...) int __VA_ARGS__; in(__VA_ARGS__) #define LL(...) long long __VA_ARGS__; in(__VA_ARGS__) #define STR(...) string __VA_ARGS__; in(__VA_ARGS__) #define VEC(t,a,s) vector<t>a(s); in(a) #define VEC2(t,a,b,s) vector<t>a(s),b(s);rep(i,0,s)in(a[i],b[i]) #define VEC3(t,a,b,c,s) vector<t>a(s),b(s),c(s);rep(i,0,s)in(a[i],b[i],c[i]) #define VEC4(t,a,b,c,d,s) vector<t>a(s),b(s),c(s),d(s);rep(i,0,s) in(a[i],b[i],c[i],d[i]) void scan(int& x) {std::cin >> x;} void scan(ll& x) {std::cin >> x;} void scan(double& x) {std::cin >> x;} void scan(std::vector<int>& x) {rep (i, 0, x.size()) std::cin >> x[i];} void scan(std::vector<ll>& x) {rep (i, 0, x.size()) std::cin >> x[i];} void in(){} template<class T> void print(const T& x) {std::cout << x << '\n';} template<class Head, class... Tail> void in(Head& head, Tail&... tail) {scan(head); in(tail...);} 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;} using namespace std; int main() { LL(N, K); auto cnt = [&](int x) { if (x < 2) return 0; if (N < x / 2) return 0; int ret = ((x / 2) - max(1LL, (x - N)) + 1) * 2 - (x % 2 == 0); return ret; }; ll ans = 0; rep (r, 2, 500000) { int l = r + K; ans += (ll)cnt(l) * cnt(r); } out(ans); }
#pragma region Macros #include <bits/stdc++.h> using namespace std; using ll = long long; #define REP2(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; ++i) #define REP3(i, l, r) for (int i = (l), i##_len = (int)(r); i < i##_len; ++i) #define GET_MACRO_REP(_1, _2, _3, NAME, ...) NAME #define REP(...) GET_MACRO_REP(__VA_ARGS__, REP3, REP2) (__VA_ARGS__) #define RREP2(i, n) for (int i = (n - 1); i >= 0; --i) #define RREP3(i, l, r) for (int i = (r - 1), i##_len = (l); i >= i##_len; --i) #define GET_MACRO_RREP(_1, _2, _3, NAME, ...) NAME #define RREP(...) GET_MACRO_REP(__VA_ARGS__, RREP3, RREP2) (__VA_ARGS__) #define IN(type, n) type n; cin >> n #define INALL(type, v, s) vector<type> v(s); for (auto &e : v) { cin >> e; } #define ALL(x) (x).begin(), (x).end() #define SZ(x) ((int)(x).size()) #ifdef _DEBUG #define DEBUG(x) cout << #x << ": " << x << endl #else #define DEBUG(x) #endif 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; } void yes() { cout << "Yes" << endl; } void no() { cout << "No" << endl; } #pragma endregion vector<int> get_divisors(int n) { vector<int> divisors; for (int i = 1; i * i <= n; ++i) { if (n % i != 0) continue; divisors.emplace_back(i); if (n / i != i) divisors.emplace_back(n / i); } return divisors; } int main() { IN(int, N); vector<int> A(N); int min = INT_MAX; REP(i, N) { IN(int, a); chmin(min, a); A.at(i) = a; } map<int, int> divisors; for (auto const &a : A) { for (auto const &d : get_divisors(a)) { if (d > min) continue; divisors[d]++; } } int count = 0; bool min_flag = true; for (auto itr = divisors.begin(); itr != divisors.end(); ++itr) { vector<int> cand; REP(i, N) { if (A.at(i) % itr->first == 0) { cand.emplace_back(A.at(i)); } } if (cand.size() < 2) continue; int gcd = cand.at(0); REP(i, 1, cand.size()) { gcd = __gcd(gcd, cand.at(i)); } if (gcd == itr->first) { count++; if (itr->first == min) min_flag = false; } } if (min_flag) count++; cout << count << endl; return 0; }
#include <iostream> #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double db; #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>; #define pll pair<ll,ll> #define pb push_back #define eb emplace_back #define mp make_pair #define ub(v,val) upper_bound(v.begin(),v.end(),val) #define np(str) next_permutation(str.begin(),str.end()) #define lb(v,val) lower_bound(v.begin(),v.end(),val) #define sortv(vec) sort(vec.begin(),vec.end()) #define rev(p) reverse(p.begin(),p.end()); #define v vector #define pi 3.14159265358979323846264338327950288419716939937510 #define len length() #define repc(i,s,e) for(ll i=s;i<e;i++) #define fi first #define se second #define mset(a,val) memset(a,val,sizeof(a)); #define mt make_tuple #define repr(i,n) for(i=n-1;i>=0;i--) #define rep(i,n) for(i=0;i<n;i++) #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define at(s,pos) *(s.find_by_order(pos)) #define set_ind(s,val) s.order_of_key(val) long long int M = 1e9 + 7 ; long long int inf = 9 * 1e18; //CLOCK ll begtime = clock(); #define time() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //CLOCK ENDED ll n, m; // modular exponentiation ll binpow(ll val, ll deg) { if (deg < 0) return 0; if (!deg) return 1 % M; if (deg & 1) return binpow(val, deg - 1) * val % M; ll res = binpow(val, deg >> 1); return (res * res) % M; } //binomial ll modinv(ll n) { return binpow(n, M - 2); } int main() { // your code goes here IOS; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll i, j, t, k, x, y, z, N; cin >> n >> m >> k; map<ll, ll> fail; rep(i, k) { cin >> x; fail[x] = 1; } // dp[i]=a*dp[0]+b; db dp_sum[n + m], dp_carry[n + m];//dp_sum[i] denotes b of dp[i] and dp_carry[i] denotes the a of dp[i] rep(i, n + m) { dp_carry[i] = 0; dp_sum[i] = 0; } db sum = 0, car = 0; for (i = n - 1; i > 0; i--) { if (fail[i]) { dp_carry[i] = 1; dp_sum[i] = 0; } else { dp_carry[i] = car / db(m); dp_sum[i] = 1.0 + sum / db(m); } sum += dp_sum[i]; car += dp_carry[i]; sum -= dp_sum[i + m]; car -= dp_carry[i + m]; } sum = 1.0 + sum / db(m); car = car / db(m); // rep(i, n + m) { // cout << dp_sum[i] << ' '; // } db ans = sum / (1.0 - car); if (ans <= 0 || (1.0 - car) < 1e-7) cout << -1; else cout << fixed << setprecision(5) << ans; return 0; }
#include<bits/stdc++.h> using namespace std; # define ll long long # define read read1<ll>() # define Type template<typename T> Type T read1(){ T t=0; char k; bool vis=0; do (k=getchar())=='-'&&(vis=1);while('0'>k||k>'9'); while('0'<=k&&k<='9')t=(t<<3)+(t<<1)+(k^'0'),k=getchar(); return vis?-t:t; } # define fre(k) freopen(k".in","r",stdin);freopen(k".out","w",stdout) int a[200005],s; int main(){ s=read;int v=0;ll ans=0,t=0; for(int i=1;i<=s;++i) a[i]=read; for(int i=1;i<=s;++i){ v=max(v,a[i]);t+=a[i]; ans+=t; printf("%lld\n",ans+1ll*v*i); } return 0; }
/* #include <stdio.h> int main(){ int l,a,i,j; long long int ans = 1; scanf("%d", &l); a = (l-1) % 11; for(i = 1; i <= 11; i++){ ans *= (l-i) / (11 - i - 1 + a); } printf("%lld", ans); } */ #include <stdio.h> long long combi(int, int); int main() { int n, r = 11; scanf("%d", &n); n -= 1; printf("%lld\n", combi(n, r)); } long long combi(int n, int r) { if (r == 0) { return 1; } return (n - r + 1) * combi(n, r - 1) / r; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; #define rep(i,s,n) for(ll i = s; i < (ll)(n); i++) #define Rep(i,s,n) for(int i = s-1;i >= (int)(n); i--) int main() { int sx, sy, gx, gy,dist; cin >> sx >> sy >> gx >> gy; dist = min(abs(sx + sy - gx - gy), abs(sx - sy - gx + gy)); if (sx == gx && sy == gy) cout << 0 << endl; else if (sx + sy == gx + gy || sx - sy == gx - gy || abs(sx - gx) + abs(sy - gy) <= 3) cout << 1 << endl; else if ((sx + sy + gx + gy) % 2 == 0 || dist <= 3) cout << 2 << endl; else if (abs(sx - gx) + abs(sy - gy) <= 6) cout << 2 << endl; else cout << 3 << endl; }
//* #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") //*/ #include <bits/stdc++.h> // #include <atcoder/all> using namespace std; // using namespace atcoder; #define DEBUG(x) cerr<<#x<<": "<<x<<endl; #define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl; #define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;} typedef long long ll; #define int ll #define vi vector<int> #define vl vector<ll> #define vii vector< vector<int> > #define vll vector< vector<ll> > #define vs vector<string> #define pii pair<int,int> #define pis pair<int,string> #define psi pair<string,int> #define pll pair<ll,ll> template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); } template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); } template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; } #define X first #define Y second #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 rrep(i,n) for(int i=(int)(n)-1;i>=0;i--) #define rrep1(i,n) for(int i=(int)(n);i>0;i--) #define REP(i,a,b) for(int i=a;i<b;i++) #define in(x, a, b) (a <= x && x < b) #define all(c) c.begin(),c.end() void YES(bool t=true) {cout<<(t?"YES":"NO")<<endl;} void Yes(bool t=true) {cout<<(t?"Yes":"No")<<endl;} void yes(bool t=true) {cout<<(t?"yes":"no")<<endl;} void NO(bool t=true) {cout<<(t?"NO":"YES")<<endl;} void No(bool t=true) {cout<<(t?"No":"Yes")<<endl;} void no(bool t=true) {cout<<(t?"no":"yes")<<endl;} 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; } #define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end()); const ll inf = 1000000001; const ll INF = (ll)1e18 + 1; const long double pi = 3.1415926535897932384626433832795028841971L; #define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl; // int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; // int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 }; vi dx = {0, 1, 0, -1}, dy = {-1, 0, 1, 0}; // vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 }; #define fio() cin.tie(0); ios::sync_with_stdio(false); const ll MOD = 1000000007; // const ll MOD = 998244353; // #define mp make_pair //#define endl '\n' int calc(pll xy1, pll xy2) { int ans = inf; if (xy1 == xy2) ans = 0; else if (xy1.first + xy1.second == xy2.first + xy2.second) ans = 1; else if (xy1.first - xy1.second == xy2.first - xy2.second) ans = 1; else if ((xy1.first + xy1.second) % 2 == (xy2.first + xy2.second) % 2) ans = 2; for (int dy = -3; dy <= 3; dy++) { for (int dx = -3; dx <= 3; dx++) { int add = 1; if (dy == 0 and dx == 0) add = 0; pll xy = xy1; xy.first += dx; xy.second += dy; if (xy == xy2) chmin(ans, add); } } return ans; } signed main() { fio(); pll xy1, xy2; cin >> xy1.first >> xy1.second >> xy2.first >> xy2.second; xy1.first += 10; xy1.second += 10; xy2.first += 10; xy2.second += 10; ll ans = INF; for (int dy = -3; dy <= 3; dy++) { for (int dx = -3; dx <= 3; dx++) { if (abs(dy) + abs(dx) > 3) continue; int add = 1; if (dy == 0 and dx == 0) add = 0; pll xy = xy1; xy.first += dx; xy.second += dy; add += calc(xy, xy2); chmin(ans, add); } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define fastio ios_base::sync_with_stdio(0);cin.tie(0) #define fp(i,a,b) for(int i=a ; i<b ; i++) #define fn(i,a,b) for(int i=a ; i>=b ; i--) #define ones(x) __builtin_popcount(x) #define pb push_back #define ff first #define ss second #define all(x) x.begin(),x.end() typedef long long ll; typedef long double ld; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pii> vpii; typedef vector<pll> vpll; const int M=1e6+5; const int inf=1e9; const int mod=1e9+7; void go(){ int n; cin >> n; ll r = 16LL*27LL*25LL*7LL*11LL*13LL*17LL*19LL*23LL*29LL; cout << r+1 << "\n"; } int main(){ fastio; int tst=1; //cin >> tst; while (tst--) go(); return 0; }
#include <iostream> #include<bits/stdc++.h> using namespace std; #define long long long int main() { long int n; cin>>n; long int ans=1LL; for(long int i=2;i<=n;i++) { long int temp = __gcd(ans,i); ans*=(i/temp); } cout<<ans+1LL<<endl; // your code goes here return 0; }
#include<iostream> #include<stdio.h> #include<vector> #include<algorithm> #include<list> #include<string.h> #include<math.h> #include<set> #include<string> #include<queue> #include<map> #include<unordered_map> #include<stack> //#include<unordered_set> //#pragma GCC optimize (3) //#define segmenttree true #ifdef segmenttree #define lc (rt<<1) #define rc (lc|1) #define mid ((l+r)>>1) #endif #define reg register using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll> pll; typedef pair<int, int> pii; typedef pair<int, ll> pil; typedef pair<double, double> pdd; typedef pair<char, char> pcc; typedef pair<ll, bool> plb; const int MAX = 2005; const ll INF = 1e10; const ll MOD = 1e9 + 7; const double PI = 3.1415926535; const double EPS = 1e-5; ll n, m, a, Sum; inline ll pow_mod(ll a, ll b, ll mod){ ll ans = 1; a %= mod; while(b) { if(b & 1) ans = ans * a % mod; a = a * a % mod; b >>= 1; } return ans; } inline ll inv(ll num, ll mod){ return pow_mod(num, mod - 2, mod) % mod; } ll C(ll x, ll y){ ll temp = 1; for(int i = 1; i <= y; ++i){ temp = temp * (x - i + 1) % MOD; temp = temp * inv(i, MOD) % MOD; } return temp; } int main(){ // ios::sync_with_stdio(false); scanf("%lld %lld", &n, &m); for(int i = 1; i <= n; ++i){ scanf("%lld", &a); Sum += a; } printf("%lld", C(m + n, n + Sum)); return 0; }
#include <bits/stdc++.h> using namespace std; typedef int_fast32_t int32; typedef int_fast64_t int64; const int32 inf = 1e9+7; const int32 MOD = 1000000007; const int64 llinf = 1e18; #define YES(n) cout << ((n) ? "YES\n" : "NO\n" ) #define Yes(n) cout << ((n) ? "Yes\n" : "No\n" ) #define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n" ) #define ANS(n) cout << (n) << "\n" #define REP(i,n) for(int64 i=0;i<(n);++i) #define FOR(i,a,b) for(int64 i=(a);i<(b);i++) #define FORR(i,a,b) for(int64 i=(a);i>=(b);i--) #define all(obj) (obj).begin(),(obj).end() #define rall(obj) (obj).rbegin(),(obj).rend() #define fi first #define se second #define pb(a) push_back(a) typedef pair<int32,int32> pii; typedef pair<int64,int64> pll; 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; } template<int64 mod> struct ModInt{ int64 x; constexpr ModInt(int64 y = 0):x((y%mod+mod)%mod){} constexpr ModInt& operator+=(const ModInt& a){ if((x += a.x) >= mod) x -= mod; return *this; } constexpr ModInt& operator-=(const ModInt& a){ if((x -= a.x) < 0)x += mod; return *this; } constexpr ModInt& operator*=(const ModInt& a){ x = x * a.x % mod; return *this; } constexpr ModInt& operator/=(const ModInt& a){ *this *= a.inv(); return *this; } constexpr ModInt operator-() const { return ModInt(-x); } constexpr ModInt operator+(const ModInt& a) const { return ModInt(*this) += a; } constexpr ModInt operator-(const ModInt& a) const { return ModInt(*this) -= a; } constexpr ModInt operator*(const ModInt& a) const { return ModInt(*this) *= a; } constexpr ModInt operator/(const ModInt& a) const { return ModInt(*this) /= a; } constexpr ModInt operator++(){ *this += ModInt(1); return *this; } constexpr ModInt operator++(int){ ModInt old = *this; ++*this; return old; } constexpr ModInt operator--(){ *this -= ModInt(1); return *this; } constexpr ModInt operator--(int){ ModInt old = *this; --*this; return old; } constexpr bool operator==(const ModInt& a) const { return x == a.x; } constexpr bool operator!=(const ModInt& a) const { return x != a.x; } constexpr ModInt pow(int64 r) const { if(!r)return 1; ModInt res = pow(r>>1); res *= res; if(r & 1) res *= *this; return res; } constexpr ModInt inv() const { return pow(mod-2); } friend istream& operator>>(istream& is, ModInt& a){ int64 t; is >> t; a = ModInt(t); return is; } friend ostream& operator<<(ostream& os, const ModInt& a){ return os << a.x; } }; using mint = ModInt<MOD>; mint comb(int32 n, int32 r){ if(r > n)return 0; r = min(r,n-r); mint res = 1; REP(i,r){ res *= n-i; res /= i+1; } return res; } int main(){ cin.tie(0); ios::sync_with_stdio(false); int32 n,m; cin >> n >> m; vector<int32> a(n); REP(i,n)cin >> a[i]; // { // vector<vector<mint>> dp(n+1,vector<mint>(m+1)); // dp[0][0] = 1; // REP(i,n){ // REP(j,m+1){ // REP(k,j+1){ // // dp[i+1][j] += dp[i][j-k] * comb(k,a[i]); // dp[i+1][j] += dp[i][k] * comb(j-k,a[i]); // } // } // } // mint ans = 0; // REP(i,m+1)ans += dp[n][i]; // ANS(ans); // REP(i,m+1){ // REP(j,n+1){ // cout << dp[j][i] << " "; // } // cout << endl; // } // } { int64 sumA = 0; REP(i,n)sumA += a[i]; // mint ans = 0; // REP(i,m+1-sumA){ // ANS(comb(sumA + n + i - 1, i)); // ans += comb(sumA + n + i - 1, i); // } // ANS(ans); // ANS(comb(n+m,m-sumA)); ANS(comb(n+m,n+sumA)); } return 0; }
#include <bits/stdc++.h> using namespace std ; #define int int64_t //be careful about this #define endl "\n" #define f(i,a,b) for(int i=int(a);i<int(b);++i) #define pr pair #define ar array #define fr first #define sc second #define vt vector #define pb push_back #define eb emplace_back #define LB lower_bound #define UB upper_bound #define PQ priority_queue #define sz(x) ((int)(x).size()) #define all(a) (a).begin(),(a).end() #define allr(a) (a).rbegin(),(a).rend() #define mem0(a) memset(a, 0, sizeof(a)) #define mem1(a) memset(a, -1, sizeof(a)) template<class A> void rd(vt<A>& v); template<class T> void rd(T& x){ cin >> x; } template<class H, class... T> void rd(H& h, T&... t) { rd(h) ; rd(t...) ;} template<class A> void rd(vt<A>& x) { for(auto& a : x) rd(a) ;} template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } template<typename T> void __p(T a) { cout<<a; } template<typename T, typename F> void __p(pair<T, F> a) { cout<<"{"; __p(a.first); cout<<","; __p(a.second); cout<<"}\n"; } template<typename T> void __p(std::vector<T> a) { cout<<"{"; for(auto it=a.begin(); it<a.end(); it++) __p(*it),cout<<",}\n"[it+1==a.end()]; } template<typename T, typename ...Arg> void __p(T a1, Arg ...a) { __p(a1); __p(a...); } template<typename Arg1> void __f(const char *name, Arg1 &&arg1) { cout<<name<<" : "; __p(arg1); cout<<endl; } template<typename Arg1, typename ... Args> void __f(const char *names, Arg1 &&arg1, Args &&... args) { int bracket=0,i=0; for(;; i++) if(names[i]==','&&bracket==0) break; else if(names[i]=='(') bracket++; else if(names[i]==')') bracket--; const char *comma=names+i; cout.write(names,comma-names)<<" : "; __p(arg1); cout<<" | "; __f(comma+1,args...); } void setIO(string s = "") { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin.exceptions(cin.failbit); cout.precision(15); cout << fixed; #ifdef ONLINE_JUDGE if(sz(s)){ freopen((s+".in").c_str(),"r",stdin); freopen((s+".out").c_str(),"w",stdout); } #define __f(...) 0 #endif } using ld = long double; signed main(){ setIO() ; int N,H,D; rd(N,D,H); vt<int> d(N),h(N); f(i,0,N) rd(d[i],h[i]); ld ans = 0; f(i,0,N){ ans = max(ans, ((ld)D * (ld)(H - h[i]))/(ld)(d[i] - D) + (ld)H); } cout << fixed << setprecision(10) << ans; }
#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>; using Graph = vector<vector<int>>; int main() { ll b, c; cin >> b >> c; ll mx1 = b + ((c - 2) / 2); ll mn1 = b - (c / 2); ll mx2 = -b + ((c - 1) / 2); ll mn2 = -b - ((c - 1) / 2); ll ans = (mx1 - mn1 + 1) + (mx2 - mn2 + 1) - max(min(mx1, mx2) - max(mn1, mn2) + 1, 0LL); cout << ans << endl; return 0; }
#include<bits/stdc++.h> typedef long long int ll; typedef unsigned long long int ull; #define BIG_NUM 2000000000 #define HUGE_NUM 4000000000000000000 //オーバーフローに注意 #define MOD 1000000007 #define EPS 0.000000001 using namespace std; #define SIZE 55 ll A[SIZE],maxi[SIZE]; ll dp[SIZE][2]; int main(){ ll N,input_X; scanf("%lld %lld",&N,&input_X); for(ll i = 0; i < N; i++){ scanf("%lld",&A[i]); } maxi[N-1] = HUGE_NUM; for(ll i = N-2; i >= 0; i--){ maxi[i] = A[i+1]/A[i]-1; //使える最大枚数 } stack<ll> S; ll X = input_X; for(ll i = N-1; i >= 0; i--){ if(A[i] > X){ S.push(0); }else{ ll num = X/A[i]; S.push(num); X %= A[i]; } } for(ll i = 0; i <= N; i++){ for(int k = 0; k < 2; k++){ dp[i][k] = 0; } } dp[0][0] = 1; //dp[見た桁][繰り上がり有無] := 場合の数 for(ll i = 0; i <= N-1; i++){ ll x = S.top(); S.pop(); for(ll is_up = 0; is_up <= 1; is_up++){ if(dp[i][is_up] == 0)continue; //ルンルンと店員、ともに0 if(is_up+x == 0 || is_up+x == maxi[i]+1){ if(is_up+x == 0){ dp[i+1][0] += dp[i][is_up]; }else{ //is_up+x == maxi[i]+1 ぴったり繰り上がり dp[i+1][1] += dp[i][is_up]; } } //ルンルンが0で店員が非0 if((x+is_up)%(maxi[i]+1) != 0){ ll num = (maxi[i]+1)-(x+is_up); if(num > 0 && num <= maxi[i]){ dp[i+1][1] += dp[i][is_up]; } } //ルンルンが非0で店員が0 if((x+is_up)%(maxi[i]+1) != 0){ dp[i+1][0] += dp[i][is_up]; } } } printf("%lld\n",dp[N][0]); return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define sz(x) int(x.size()) #define show(x) {for(auto i: x){cout << i << " ";} cout << endl;} using namespace std; using ll = long long; using P = pair<ll, int>; map<P, int> mp; int N; vector<ll> A(55); ll solve(ll x, int i) { // i以降のコインを使う ll res; if (i == N - 1) { return 1; } if (mp[P(x, i)] != 0) return mp[P(x, i)]; ll a = A[i], b = A[i+1]; if (x % b == 0) { res = solve(x, i+1); mp[P(x, i)] = res; return res; // iは使わない } ll remain = x % b; x -= remain; res = solve(x, i+1) + solve(x+b, i+1); mp[P(x+remain, i)] = res; return res; } int main() { ll X; cin >> N >> X; rep(i, N) cin >> A[i]; ll ans = solve(X, 0); cout << ans << '\n'; return 0; // 境界、ll, 0, -, 1i, for s&g, debug }
#include<algorithm> #include<bitset> #include<cmath> #include<complex> #include<deque> #include<functional> #include<iomanip> #include<iostream> #include<iterator> #include<map> #include<numeric> #include<queue> #include<set> #include<stack> #include<string> #include<unordered_map> #include<unordered_set> #include<utility> #include<vector> 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 ALL(x) (x).begin(),(x).end() #define SIZE(x) ((ll)(x).size()) #define MAX(x) *max_element(ALL(x)) #define MIN(x) *min_element(ALL(x)) #define D() #define MAXR 100000 #define PB push_back #define MP make_pair #define F first #define S second #define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;} 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 long long INF = 1LL<<60; const long long MOD = 1000000007; int main() { int a, b; cin >> a >> b; cout << (a + b) / 2 << " " << (a - b) / 2 << endl; return 0; }
#include <bits/stdc++.h> #if MYDEBUG #include "lib/cp_debug.hpp" #else #define DBG(...) ; #endif #if __cplusplus <= 201402L template <typename T> T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); } template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } #endif using LL = long long; constexpr LL LINF = 334ll << 53; constexpr int INF = 15 << 26; constexpr LL MOD = 1E9 + 7; namespace Problem { using namespace std; struct RangeSum { using T = double; T operator()(const T &a, const T &b) { return a + b; } static constexpr T id() { return T(0); }; }; template <typename M> struct SegmentTree { using Val = typename M::T; M calc; vector<Val> data; int n; explicit SegmentTree(int size) { n = 1; while (n < size) n <<= 1; data = vector<Val>(n << 1, calc.id()); } explicit SegmentTree(vector<Val> &v) { n = 1; while (n < v.size()) n <<= 1; data = vector<Val>(n << 1); copy(v.begin(), v.end(), data.begin() + n); for (int i = n + (int)v.size(); i < 2 * n; i++) data[i] = calc.id(); for (int i = n - 1; i > 0; --i) { data[i] = calc(data[i * 2], data[i * 2 + 1]); } } void update(int i, Val v) { int k = i + n; data[k] = v; for (k >>= 1; k >= 1; k >>= 1) data[k] = calc(data[k * 2], data[k * 2 + 1]); } Val query(int l, int r) { //get[a,b) Val resl = calc.id(), resr = calc.id(); for (l += n, r += n; l < r; l >>= 1, r >>= 1) { if (l & 1) resl = calc(resl, data[l++]); if (r & 1) resr = calc(data[r - 1], resr); } return calc(resl, resr); } }; class Solver2 { public: int n, m; vector<int> is_return; SegmentTree<RangeSum> a_0, a_x; Solver2(LL n, LL m) : n(n), m(m), is_return(n + 1), a_0(n + 1), a_x(n + 1){}; void solve() { int k; cin >> k; for (int i = 0; i < k; ++i) { int tmp; cin >> tmp; is_return[tmp] = 1; } for (int i = 0, j = 0; i <= n; ++i) { if (is_return[i]) { j++; if (j == m) { cout << -1 << endl; return; } } else { j = 0; } } a_0.update(n, 0); a_x.update(n, 0); for (int i = n - 1; i > 0; --i) { if (is_return[i]) { a_0.update(i, 0); a_x.update(i, 1); } else { double sum_0 = a_0.query(i + 1, min(i + m, n) + 1); double sum_x = a_x.query(i + 1, min(i + m, n) + 1); a_0.update(i, sum_0 / m + 1.0); a_x.update(i, sum_x / m); if (i > 99900) DBG(i, m - (n - i), sum_0 / m + 1.0, sum_x / m) } } double sum_0 = a_0.query(1, min(m, n) + 1); double sum_x = a_x.query(1, min(m, n) + 1); DBG(sum_0 / m + 1.0, sum_x / m) double ans = (sum_0 / m + 1.0) / (1.0 - sum_x / m); cout << ans << endl; } }; } // namespace Problem int main() { std::cin.tie(0); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(12); long long n = 0, m; std::cin >> n >> m; Problem::Solver2 sol(n, m); sol.solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { unsigned long long N,K; cin >> N >> K; for(int i=0;i<K;i++){ if((N%200)==0){ N = N/200; }else{ N = N*1000+200; } } cout << N << endl; }
#include<bits/stdc++.h> using namespace std; int S(int n){ int ret = 0; while(n>0){ ret += n%10; n /= 10; } return ret; } int main(){ int a,b; cin >> a >> b; int Sa = S(a); int Sb = S(b); if(Sa > Sb) cout << Sa << endl; else cout << Sb << endl; return 0; }
#include <bits/stdc++.h> #include <fstream> using namespace std; #define intMax 2147483647 #define rep(i, a, b) for (int i = a; i < b; i++) #define repp(i, a, b) for (int i = a; i >= b; i--) #define be(a) (a.begin(), a.end()) #define rbe(p) (p.rbegin(), p.rend()) #define pb push_back int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, m, k; cin >> n >> m >> k; int sum = 0; rep(i, 1, n) { int a; cin >> a; sum += a; } int r = k * n; if ( r - sum <= m ){ cout << max(r - sum,0); } else{ cout << -1; } }
#include <bits/stdc++.h> using namespace std; string revAB(string str) { for(int i=0;i<str.size();++i) str[i]=(str[i]=='A'?'B':'A'); return str; } int main() { int N,M; cin >> N; M = (1<<N); vector<vector<string>> S(N+1); S[1] = {"AB"}; for(int i=2;i<=N;++i) { int L = (1<<i); S[i].push_back(string(L/2,'A')+string(L/2,'B')); for(int j=0;j<S[i-1].size(); ++j) { S[i].push_back(S[i-1][j]+S[i-1][j]); } for(int j=0;j<S[i-1].size(); ++j) { S[i].push_back(S[i-1][j]+revAB(S[i-1][j])); } } cout << S[N].size() << "\n"; for(auto& s:S[N]) { cout << s << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; #define ull unsigned long long #define MOD (int)(1e9+7) #define MOD1 998244353 #define ceil(x, y) ((((x)%(y))==0)? (x/y) : (x/y+1)) #define FOR(i, N) for(int i = 0; i < N; ++i) #define FOR1(i, N) for(int i = 1; i <= N; ++i) #define vi vector <int> #define pii pair <int, int> #define pb push_back #define mp make_pair #define ff first #define ss second #define mset(a, v) memset(a, v, sizeof(a)) #define all(v) (v).begin(), (v).end() #define INF 2e9 #define EPS 1e-9 #define int long long /*#include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; typedef cc_hash_table<int, int, hash<int>> ht; // while using, comment #define int long long */ void __print(int 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 dbg(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define dbg(x...) #endif using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("in7.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif int T = 1; // cin >> T; FOR1(tt, T){ // cout << "Case #" << tt << ": "; int n; cin >> n; int a[n+1]; FOR1(i, n) cin >> a[i]; int pref[n+1], swing[n+1]; pref[1] = a[1]; swing[1] = a[1]; int curr = a[1]; for(int i = 2; i <= n; i++){ pref[i] = pref[i-1] + a[i]; if(curr + a[i] > swing[i-1]) swing[i] = curr + a[i]; else swing[i] = swing[i-1]; curr += a[i]; } int maxi = 0; curr = 0; for(int i = 1; i <= n; i++){ maxi = max(maxi, curr + swing[i]); curr = curr + pref[i]; } cout << maxi; cout << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; #define INF_LL (int64)1e18 #define INF (int32)1e9 #define REP(i, n) for(int64 i = 0;i < (n);i++) #define FOR(i, a, b) for(int64 i = (a);i < (b);i++) #define all(x) x.begin(),x.end() #define fs first #define sc second using int32 = int_fast32_t; using uint32 = uint_fast32_t; using int64 = int_fast64_t; using uint64 = uint_fast64_t; using PII = pair<int32, int32>; using PLL = pair<int64, int64>; const double eps = 1e-10; template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;} template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;} template<typename T> vector<T> make_v(size_t a){return vector<T>(a);} template<typename T,typename... Ts> auto make_v(size_t a,Ts... ts){ return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); } template<typename T,typename U,typename... V> typename enable_if<is_same<T, U>::value!=0>::type fill_v(U &u,const V... v){u=U(v...);} template<typename T,typename U,typename... V> typename enable_if<is_same<T, U>::value==0>::type fill_v(U &u,const V... v){ for(auto &e:u) fill_v<T>(e,v...); } int main(void){ cin.tie(0); ios::sync_with_stdio(false); int64 N; cin >> N; vector<int64> A(N+1, 0), B(N+1, 0); REP(i, N) cin >> A[i+1]; REP(i, N) A[i+1] += A[i]; int64 maxi = 0, res = 0; FOR(i, 0, N) { chmax(maxi, A[i+1]); A[i+1] += A[i]; chmax(res, A[i] + maxi); } cout << res << endl; }
#define _USE_MATH_DEFINES #include <iostream> #include <sstream> #include <string> #include <list> #include <vector> #include <queue> #include <algorithm> #include <climits> #include <cstring> #include <cmath> #include <stack> #include <iomanip> #include <tuple> #include <functional> #include <cfloat> #include <map> #include <set> #include <array> #include <stdio.h> #include <string.h> #include <random> #include <cassert> using ll = long long; using ull = unsigned long long; using uint = unsigned int; using namespace std; #define int long long #define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end()) #define SORT(v) sort((v).begin(), (v).end()) #define RSORT(v) sort((v).rbegin(), (v).rend()) #define ARY_SORT(a, size) sort((a), (a)+(size)) #define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end())) #define REVERSE(v) (reverse((v).begin(), (v).end())) #define ARY_REVERSE(v,a) (reverse((v), (v)+(a))) #define REP(i, n) for (int (i)=0; (i) < (n); (i)++) #define REPE(i, n) for (int (i)=0; (i) <= (n); (i)++) #define CONTAINS_MAP(m, a) ((m).find((a)) != m.end()) #define CONTAINS_SET(m, a) ((m).find((a)) != m.end()) void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; exit(0); } void Yes() { cout << "Yes" << endl; exit(0); } void No() { cout << "No" << endl; exit(0); } int N, M; int H[200010]; int W[200010]; int A[200010]; int B[200010]; int get(int ary[200010], int a, int b) { return ary[b] - ary[a]; } int func(int k, int w) { if (k % 2 == 0) { int v = get(A, 0, k / 2); int h = H[k] - w; int w = get(B, k / 2, N / 2); return v + h + w; } else { int v = get(A, 0, (k - 1) / 2); int h = w - H[k - 1]; int w = get(B, (k - 1) / 2, N / 2); return v + h + w; } } int cur = 0; //---------- にぶたん[f,f,f,f,'t',t,t,t] ---------- bool isOK(int index) { return cur < H[index]; } int binary_search(int n) { int left = -1; int right = n; while (right - left > 1) { int mid = left + (right - left) / 2; if (isOK(mid)) right = mid; else left = mid; } return right; } signed main() { cin >> N >> M; REP(i, N) cin >> H[i]; REP(i, M) cin >> W[i]; H[N] = LLONG_MAX; ARY_SORT(H, N); A[0] = 0; for (int i = 0; i < N / 2; i++) { int i1 = i * 2; int i2 = i * 2 + 1; A[i + 1] = A[i] + abs(H[i2] - H[i1]); } B[0] = 0; for (int i = 0; i < N / 2; i++) { int i1 = i * 2 + 1; int i2 = i * 2 + 2; B[i + 1] = B[i] + abs(H[i2] - H[i1]); } int ans = LLONG_MAX; REP(i, M) { cur = W[i]; int index = binary_search(N); int a = func(index, cur); ans = min(a, ans); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define ub upper_bound #define lb lower_bound #define endl "\n" #define mod 1000000007 #define rep(i, n) for (int i = 0; i < n; i++) #define repr(i, n) for (int i = n - 1; i >= 0; i--) void solve() { int n, m, q, x, y; cin >> n >> m >> q; vector<pair<int, int>> items; int boxes[m + 1]; rep(i, n) { cin >> x >> y; items.pb({y, x}); } sort(items.begin(), items.end(),greater<pair<int,int>>()); rep(i, m) { cin >> boxes[i]; } multiset<int> s; ll ans = 0; rep(i, q) { cin >> x >> y; for (int i = 0; i < x - 1; i++) { s.insert(boxes[i]); } for (int i = y; i < m; i++) { s.insert(boxes[i]); } for (int i = 0; i < n; i++) { int weight = items[i].second; int val = items[i].first; auto it = s.lower_bound(weight); if (it != s.end()) { ans += val; s.erase(s.find(*it)); } } cout << ans << endl; s.clear(); ans=0; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); return 0; }
#include <bits/stdc++.h> #include <math.h> using namespace std; using ll = long long; int main(){ ll a, b, c; cin >> a >> b >> c; if(c % 2 == 0){ if(abs(a) < abs(b)){ cout << "<" << endl; }else if(abs(a) > abs(b)){ cout << ">" << endl; }else{ cout << "=" << endl; } }else{ if(a < b){ cout << "<" << endl; }else if(a > b){ cout << ">" << endl; }else{ cout << "=" << endl; } } }
#include <bits/stdc++.h> using namespace std; #define nl "\n" #define fi first #define se second #define ll long long #define mp make_pair #define eb emplace_back #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define rnd(x) cout<<setprecision((int)(x)+1) #define f(i,n) for(int i = 0;i <(int)(n);++i) #define fr(i,n) for(int i = (int)(n) - 1;i>=0;i--) #define rep(i,a,b) for(int i = (int)(a); i<=(int) (b); ++i) #define repr(i,a,b) for(int i = (int)(b); i>=(int) (a); i--) typedef vector<int> vi; typedef pair<int, int> pi; #ifndef ONLINE_JUDGE #define debug(x) cerr<<#x<<" = ";_print(x); cerr<<endl; #else #define debug(x) #endif template<class T> int cnt1(T n){ int cnt=0; while(n>0){cnt++;n = n&(n-1);} return cnt; } template<class T> void _print(T a){ cerr<<a; } template<class T> void _print(vector<T> vi){ cerr<<"[ "; for(T i:vi){ _print(i); cerr<<" ";} cerr<<"]"; } const int MAX_N = 1e5 + 1; const ll MOD = 1e9 + 7; const ll INF = 1e9; void Solve(){ int a,b,c; cin>>a>>b>>c; char s = '='; if(c%2==0){ a = abs(a); b = abs(b); } if(a>b) s = '>'; else if(a<b) s = '<'; cout<<s<<nl; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); freopen("output.txt","w",stdout); freopen("error.txt","w",stderr); #endif int t = 1; //cin>>t; rep(i,1,t)Solve(); }
#include<iostream> #include<vector> #include<algorithm> #include<cassert> using namespace std; template< int mod > struct ModInt { int x; ModInt() : x(0) {} ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; } ModInt &operator-=(const ModInt &p) { if((x += mod - p.x) >= mod) x -= mod; return *this; } ModInt &operator*=(const ModInt &p) { x = (int) (1LL * x * p.x % mod); return *this; } ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; } ModInt operator-() const { return ModInt(-x); } ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; } ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; } ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; } ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; } bool operator==(const ModInt &p) const { return x == p.x; } bool operator!=(const ModInt &p) const { return x != p.x; } ModInt inverse() const { int a = x, b = mod, u = 1, v = 0, t; while(b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return ModInt(u); } ModInt pow(int64_t n) const { ModInt ret(1), mul(x); while(n > 0) { if(n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; } friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt< mod >(t); return (is); } static int get_mod() { return mod; } }; constexpr int MOD = 998244353; using mint = ModInt< MOD >; template<typename T> struct Combination{ // T は mint の想定です int N; vector<T> fact_, inv_, finv_; Combination(){} Combination(int n):N(n+1), fact_(N,1), inv_(N,1), finv_(N,1){ int mod = fact_.at(0).get_mod(); for (int i = 2; i < N; i++){ fact_.at(i) = fact_.at(i-1) * i; inv_.at(i) = -inv_.at(mod%i) * (mod/i); finv_.at(i) = finv_.at(i-1) * inv_.at(i); } } void init(int n) { N = n+1; fact_.assign(N, 1); inv_.assign(N, 1); finv_.assign(N, 1); int mod = fact_.at(0).get_mod(); for (int i = 2; i < N; i++){ fact_.at(i) = fact_.at(i-1) * i; inv_.at(i) = -inv_.at(mod%i) * (mod/i); finv_.at(i) = finv_.at(i-1) * inv_.at(i); } } T fact(int n){ if(n < 0) return 0; assert(n<N); return fact_.at(n); } T inv(int n){ if(n < 0) return 0; assert(n<N); return inv_.at(n); } T finv(int n){ if(n < 0) return 0; assert(n<N); return finv_.at(n); } T com(int n, int k){ if (n < k) return 0; if (n < 0 || k < 0) return 0; assert(n<N); return fact_.at(n) * finv_.at(k) * finv_.at(n-k); } T parm(int n, int k){ if (n < k) return 0; if (n < 0 || k < 0) return 0; assert(n<N); return fact_.at(n) *finv_.at(n-k); } T hom(int n, int k){ if(n < 0 || k < 0) return 0; if(k == 0) return 1; assert(n+k-1<N); return com(n+k-1, k); } }; int main(){ int n, m; cin >> n >> m; /* dp_ij = 二進法でi桁目まで見て合計をjにするような方法 i桁目でいくつbitを立てるか(偶数個)を全探索 メモ化再帰: 2^0の位をいくつ立てるかを全探索すると、 (m - cnt)/2 のサイズの同じ問題にできる //*/ Combination<mint> bc(n); vector<mint> memo(m+1); vector<bool> seen(m+1); auto dp = [&](auto f, int sum) -> mint{ if(sum == 0) return 1; if(sum&1) return 0; if(seen[sum]) return memo[sum]; seen[sum] = 1; mint res = 0; for(int i = 0; i*2 <= sum && i*2 <= n; i++){ res += f(f, (sum-i*2)/2) * bc.com(n, i*2); } return memo[sum] = res; }; cout << dp(dp, m) << endl; }
#include <cstdio> #include <iostream> #include <algorithm> #include <cctype> #include <vector> #include <cmath> #include <string> #include <cstring> #include <map> #include <set> #include <queue> using namespace std; using ll = long long; using ull = unsigned long long; template <typename T> void read(T & x){ x = 0; int op = 1; char ch = getchar(); while (!isdigit(ch)){ if (ch == '-') op = -1; ch = getchar();} while (isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48); ch = getchar();} x*= op; } signed main(){ ios::sync_with_stdio(false); int a, b; cin >> a >> b; int sum = 0; for (int i = 0; i < b; ++i) { int t = -900000 - i; cout << t << " "; sum += t; } for (int i = 1; i < a; ++i) { cout << i << " "; sum += i; } cout << -sum << endl; }
#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 template<class T> T T_INF(){ return 1000000000000000000; } template<> int T_INF<int>(){ return 1000000000; } struct Tree{ int n; vector<vector<pair<int,int>>> G; Tree(int n_){ init(n_); } Tree(){} void init(int n_){ n=n_; G=vector<vector<pair<int,int>>>(n); } void add_edge(int u,int v,int i=0){ G[u].push_back(mp(v,i)); } }; struct rooted_tree{ Tree* Tr; int root; vector<pair<int,int>> par; vector<int> dep; vector<int> vs; //pre-orderにvertexを並べたもの vector<int> pre_order; //頂点iがpre-orderで何番目か rooted_tree(Tree* Tr_,int r=0):Tr(Tr_),root(r),par(Tr->n),dep(Tr->n),vs(Tr->n),pre_order(Tr->n,-1){ dfs(mp(r,-1),-1,0,0); } rooted_tree(){} int dfs(pair<int,int> e, int p,int d,int k){ if(pre_order[e.fr]!=-1)return k; par[e.fr]=mp(p,e.sc); dep[e.fr]=d; vs[k]=e.fr; pre_order[e.fr]=k++; for(auto ed: Tr->G[e.fr])k=dfs(ed,e.fr,d+1,k); return k; } }; template<class T> vector<T> dist_on_tree(const Tree &Tr, int s){ vector<T> dist(Tr.n,-1); queue<int> que; dist[s]=0; que.push(s); while(!que.empty()){ int v=que.front(); que.pop(); for(auto ed: Tr.G[v]){ if(dist[ed.fr]!=-1)continue; dist[ed.fr]=dist[v]+1; que.push(ed.fr); } } return dist; } int main(){ int n,k; scanf("%d%d",&n,&k); Tree Tr(n); for(int i=0;i<n-1;i++){ int u,v; scanf("%d%d",&u,&v); u--; v--; Tr.add_edge(u,v); Tr.add_edge(v,u); } rooted_tree rt(&Tr); vector<pair<int,int>> vs; for(int i=0;i<Tr.n;i++)vs.push_back(mp(rt.dep[i],i)); sort(vs.begin(),vs.end(),greater<pair<int,int>>()); int l=0,r=n-1; while(l<r){ int m=(l+r)/2; bool ok=false; if(m<=800){ static int d[200010]; fill(d,d+n,-1); int cnt=0; for(auto p: vs){ int v=p.sc; bool used=false; pair<int,int> loc(v,0); do{ if(d[loc.fr]>=loc.sc){ used=true; break; } loc.fr=rt.par[loc.fr].fr; loc.sc++; }while(loc.fr!=-1&&loc.sc<=m); if(!used){ for(int i=0;i<m&&v!=-1;i++)v=rt.par[v].fr; if(v==-1)v=0; cnt++; if(cnt>k)break; loc=mp(v,0); do{ d[loc.fr]=m-loc.sc; loc.fr=rt.par[loc.fr].fr; loc.sc++; }while(loc.fr!=-1&&loc.sc<=m); } } ok=cnt<=k; } else { static bool used[200010]; fill(used,used+n,false); int cnt=0; for(auto p: vs){ int v=p.sc; if(!used[v]){ for(int i=0;i<m&&v!=-1;i++)v=rt.par[v].fr; if(v==-1)v=0; cnt++; if(cnt>k)break; auto d=dist_on_tree<int>(Tr,v); for(int i=0;i<n;i++)if(d[i]<=m)used[i]=true; } } ok=cnt<=k; } if(ok)r=m; else l=m+1; } cout<<l<<endl; }
//================code===================// //#define TLE #ifdef TLE #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #endif #include <bits/stdc++.h> #include <unordered_map> #include <unordered_set> #include <random> #include <ctime> #define ci(t) cin>>t #define co(t) cout<<t #define LL unsigned long long #define ld long double #define fa(i,a,b) for(LL i=(a);i<(LL)(b);++i) #define fd(i,a,b) for(LL i=(a);i>(LL)(b);--i) #define setp pair<pair<int,int>,int> #define setl pair<LL,LL> #define micro 0.000001 using namespace std; //LL gcd(LL a, LL b) { return a % b ? gcd(b, a % b) : b; } //LL lcm(LL a, LL b) { return (a * b) / gcd(a, b); } #ifdef OHSOLUTION #define ce(t) cerr<<t #define AT cerr << "\n=================ANS=================\n" #define AE cerr << "\n=====================================\n" #define DB(a) cerr << __LINE__ << ": " << #a << " = " << (a) << endl; #else #define AT #define AE #define ce(t) #define __popcnt64 __builtin_popcountll #define __popcnt __builtin_popcount #endif pair <int, int> vu[9] = { {0,1},{1,0},{0,-1} ,{-1,0},{0,0},{1,0}, {-1,1} , {1,-1},{-1,-1} }; //RDLU EWSN template<typename T, typename U> void ckmax(T& a, U b) { a = a < b ? b : a; } template<typename T, typename U> void ckmin(T& a, U b) { a = a > b ? b : a; } struct gcmp { bool operator()(LL a, LL b) { return a < b; } bool operator()(setl a, setl b) { return a.second < b.second; } }; struct lcmp { bool operator()(LL a, LL b) { return a > b; } bool operator()(setl a, setl b) { return a.second > b.second; } }; const int max_v = 2e5 + 7; const int INF = 1e9 + 7; const LL LNF = (LL)5e18 + 7ll; const LL mod = 998244353; vector <int> adj[max_v]; struct node { int cn,sl,mr; }; node dfs(int idx,int dist,int par = -1) { if (~par && adj[idx].size() == 1) return { 0,INF,0 }; node ret = { 0,INF,-INF}; for (auto& x : adj[idx]) if (x != par) { node tmp = dfs(x, dist, idx); ret.cn += tmp.cn; ckmin(ret.sl, tmp.sl+1); ckmax(ret.mr, tmp.mr+1); } //if (ret.mr == -INF) ret.mr = 0; if (ret.sl == INF) { if (ret.mr >= dist) { ret.sl = 0; ret.mr = -INF; ++ret.cn; } } else { if (ret.sl == 2 * dist + 1 || ret.mr>=dist) { ++ret.cn; ret.sl = 0; ret.mr = -INF; } else if (ret.sl > dist) { ckmax(ret.mr, ret.sl - dist - 1); } else if(ret.sl+ret.mr <=dist) { ret.mr = -INF; } } if (par == -1 && ret.mr!=-INF) { ++ret.cn; } return ret; } int main() { #ifdef OHSOLUTION freopen("input.txt", "r", stdin); #endif ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, k; ci(n >> k); vector <setl> test; fa(i, 0, n - 1) { int x, y; ci(x >> y); --x, --y; adj[x].push_back(y); adj[y].push_back(x); if (x > y) swap(x, y); test.push_back({ x,y }); } if (n == k) { co(0); return 0; } int l = 1; int r = n; while (l != r) { int mid = l + r >> 1; if (dfs(0,mid).cn <= k) r = mid; else l = mid + 1; } co(l << "\n"); return 0; }
#include <cstdio> #include <algorithm> using namespace std; char S[105]; int A[105]; int l[105],r[105],lcnt[105],rcnt[105]; int N,t; bool check(int x) { for(int i=0;i<=N;i++) { l[i]=A[i]/x; lcnt[i]=x-A[i]%x; r[i]=A[i]/x+1; rcnt[i]=A[i]%x; } for(int i=0;i<N;i++) if(S[i]=='<') { if(l[i]>=l[i+1]) return false; if(l[i+1]==r[i]&&lcnt[i+1]>lcnt[i]) return false; } else { if(l[i]<=l[i+1]) return false; if(l[i]==r[i+1]&&lcnt[i]>lcnt[i+1]) return false; } return true; } int binaryanswer(int l,int r) { if(l==r) return l; if(r-l==1) { if(check(r)) return r; return l; } int mid=(l+r)/2; if(check(mid)) return binaryanswer(mid,r); else return binaryanswer(l,mid-1); } int main() { scanf("%d",&N); scanf("%s",S); for(int i=0;i<=N;i++) scanf("%d",&A[i]); t=binaryanswer(1,10000); printf("%d\n",t); for(int i=0;i<t;i++) { for(int j=0;j<=N;j++) if(i<A[j]%t) printf("%d ",A[j]/t+1); else printf("%d ",A[j]/t); printf("\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #ifdef LOCAL #include "debug.hpp" #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) #endif int main() { ios::sync_with_stdio(false); cin.tie(0); ll N; cin >> N; string S; cin >> S; vector<ll> A(N + 1, 0); ll K = 1e9; for (ll i = 0; i <= N; i++) { cin >> A[i]; if (i > 0) K = min(K, abs(A[i] - A[i - 1])); } vector<vector<ll>> B(K, vector<ll>(N + 1, 0)); for (ll i = 0; i <= N; i++) { ll q = A[i] / K, r = A[i] % K; for (ll j = 0; j < K; j++) { B[j][i] = q; if (j < r) B[j][i]++; } } cout << K << '\n'; for (ll i = 0; i < K; i++) { cout << B[i][0]; for (ll j = 0; j < N; j++) { cout << ' ' << B[i][j + 1]; } cout << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define FOR(i, a, b) for (int i = a; i < (b); i++) #define range(a) a.begin(), a.end() #define endl "\n" #define Yes() cout << "Yes" << endl #define No() cout << "No" << endl #define MP make_pair using P = pair<int, int>; const unsigned long long mod = 1e9 + 7; const long long INF = 1LL<<60; void chmin(long long &a, long long b) { if (a > b) a = b; } void chmax(long long &a, long long b) { if (a < b) a = b; } struct Edge { ll to; ll cost; Edge(ll to, ll cost) : to(to), cost(cost) {} }; using Graph = vector<vector<Edge>>; using _P = pair<long, int>; /* dijkstra(G,s,dis) 入力:グラフ G, 開始点 s 計算量:O(|E|log|V|) */ vector<ll> dijkstra(const Graph &G, int s) { int N = G.size(); vector<ll> dis(N, INF); priority_queue<_P, vector<_P>, greater<_P>> pq; // 「仮の最短距離, 頂点」が小さい順に並ぶ dis[s] = 0; pq.emplace(dis[s], s); while (!pq.empty()) { _P p = pq.top(); pq.pop(); int v = p.second; //v : 今見ている頂点 if (dis[v] < p.first) { // 最短距離で無ければ無視 continue; } for (auto &e : G[v]) { if (dis[e.to] > dis[v] + e.cost) { // 最短距離候補なら priority_queue に追加 dis[e.to] = dis[v] + e.cost; pq.emplace(dis[e.to], e.to); } } } return dis; } int main(void){ ios::sync_with_stdio(0); cin.tie(0); //頂点数、変数 int N, M; cin >> N >> M; Graph G(N); FOR(i,0,M){ int a, b, w; cin >> a >> b >> w; --a; --b; G.at(a).push_back(Edge(b, w)); } //ダイクストラ法 FOR(i,0,N){ auto dis = dijkstra(G, i); ll ans = INF; FOR(j,0,N){ for(auto x : G.at(j)){ //cout<<x.to<<" "<<i<<endl; if(x.to == i){ ans = min(ans, x.cost + dis.at(j)); } } } //結果出力 if(ans != INF) cout << ans << endl; else cout << -1 << endl; } return 0; }
#include <iostream> #include <vector> #include <queue> using namespace std; int main() { int n, m; scanf("%d %d", &n, &m); vector<vector<pair<int, int>>> e(n); for (int i = 0; i < m; i++) { int a, b, c; scanf("%d %d %d", &a, &b, &c); e[a - 1].push_back({b - 1, c}); } for (int i = 0; i < n; i++) { vector<int> d(n, -1); priority_queue<pair<int, int>> pq; pq.push({0, i}); while (!pq.empty()) { pair<int, int> p = pq.top(); pq.pop(); if (d[p.second] == -1) { d[p.second] = -p.first; for (pair<int, int> q : e[p.second]) { if (d[q.first] == -1) { pq.push({p.first - q.second, q.first}); } } } } int ans = -1; for (pair<int, int> p : e[i]) if (p.first == i && (ans == -1 || p.second < ans)) ans = p.second; for (int j = 0; j < n; j++) { if (j == i || d[j] < 0) continue; for (pair<int, int> p : e[j]) if (p.first == i && (ans == -1 || p.second + d[j] < ans)) ans = p.second + d[j]; } printf("%d\n", ans); } return 0; }
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef unsigned long long ull; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll myRand(ll B) { return (ull)rng() % B; } // 1-indexed template<typename T> struct BIT{ int n; vector<T> bit; BIT(int n_=0):n(n_),bit(n+1){} T sum(int i){ T res=0; for(;i>0;i-=(i&-i))res+=bit[i]; return res; } T sum(int l,int r){ if(l>r)return 0; return sum(r)-sum(l-1); } void add(int i,T a){ if(i==0)return; for(;i<=n;i+=(i&-i)){bit[i]+=a;} } int lower_bound(T k){ // k<=sum(res) if(k<=0)return 0; int res=0,i=1; while((i<<1)<=n)i<<=1; for(;i;i>>=1){ if(res+i<=n&&bit[res+i]<k)k-=bit[res+=i]; } return res+1; } }; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int n,m; cin >> n >> m; int q; cin >> q; vector<ll> v={0}; vector<int> t(q),x(q),y(q); for(int i=0;i<q;i++){ cin >> t[i] >> x[i] >> y[i]; x[i]--; v.push_back(y[i]); } sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()),v.end()); int K=v.size(); BIT<int> bit1(K+1),bit2(K+1); BIT<ll> sum1(K+1),sum2(K+1); ll res=0; bit1.add(1,n); bit2.add(1,m); vector<int> a(n,1),b(m,1); auto getid=[&](int u)->int{ return lower_bound(v.begin(), v.end(),u)-v.begin()+1; }; for(int i=0;i<q;i++){ if(t[i]==1){ int id=a[x[i]]; res-=sum2.sum(id,K); res-=v[id-1]*bit2.sum(id-1); bit1.add(id,-1); sum1.add(id,-v[id-1]); id=getid(y[i]); a[x[i]]=id; res+=sum2.sum(id+1,K); res+=v[id-1]*bit2.sum(id); bit1.add(id,1); sum1.add(id,v[id-1]); } else{ int id=b[x[i]]; res-=sum1.sum(id+1,K); res-=v[id-1]*bit1.sum(id); bit2.add(id,-1); sum2.add(id,-v[id-1]); id=getid(y[i]); b[x[i]]=id; res+=sum1.sum(id+1,K); res+=v[id-1]*bit1.sum(id); bit2.add(id,1); sum2.add(id,v[id-1]); } cout << res << "\n"; } }
#include "bits/stdc++.h" #include<sstream> using namespace std; typedef long long ll; #define _USE_MATH_DEFINES #include <math.h> #define NIL = -1; #define all(x) x.begin(),x.end() const ll INF = 1e9; const long long inf = 1e18; const ll INFL = 1e18; const ll MOD = 1e9 + 7; int digit(ll x) { int digits = 0; while(x > 0){ x /= 10; digits++; } return digits; } ll gcd(long long a,long long b) { if (a < b) swap(a,b); if (b == 0) return a; return gcd(b,a%b); } bool is_prime(long long N){ if (N == 1) return false; for (long long i = 2;i * i <= N;i++){ if (N % i == 0) return false; } return true; } ll lcm(ll a,ll b){ return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b); } double DegreeToRadian(double degree){ return degree * M_PI / 180.0; } long long modpow(long long a, long long b, long long m){ long long ans = 1; while(b > 0){ if (b % 2 == 1){ ans *= a; ans %= m; } a *= a; a %= m; b /= 2; } return ans; } long long comb(long long x, long long y){ int z; if (y == 0) return 1; else { z = modpow(x, y/2, MOD)*modpow(x, y/2, MOD)%MOD; if (y % 2 == 1) z = z*x%MOD; return z; } } vector<pair<long long, long long>> prime_fact(long long x){ vector<pair<long long, long long>> res; for(int i = 2;i*i <= x;i++){ if (x % i == 0){ long long cnt = 0; while(x % i == 0){ cnt++; x /= i; } res.push_back({i, cnt}); } } if (x != 1){ res.push_back({x, 1}); } return res; } int64_t mod_inv(int64_t a, int64_t m){ int64_t b = m, u = 1, v = 0; while(b){ int64_t t = a/b; a -= t*b; swap(a, b); u -= t*v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } // {g, x, y}: ax + by = g tuple<long long, long long, long long> extgcd(long long a, long long b){ if (b == 0) return {a, 1, 0}; long long g, x, y; tie(g, x, y) = extgcd(b, a % b); return {g, y, x - a/b*y}; } int dx[4] = {0,1,0,-1}; int dy[4] = {1,0,-1,0}; ////////////////////////// long long score(vector<long long> cnt){ long long ans = 0; for(int i = 1;i <= 9;i++){ long long res = i; for(int j = 0;j < cnt[i];j++){ res *= 10; } ans += res; } return ans; } int main(){ long long k; string s, t; cin >> k >> s >> t; vector<long long> aoki(10, 0), taka(10, 0), card(10, k); for(int i = 0;i < 4;i++){ int a = int(s[i] - '0'); int b = int(t[i] - '0'); taka[a]++; aoki[b]++; card[a]--; card[b]--; } long long win = 0; for(int i = 1;i < 10;i++){ aoki[i]++; for(int j = 1;j < 10;j++){ taka[j]++; if (score(taka) > score(aoki)){ win += card[i]*(card[j] - (i == j)); } taka[j]--; } aoki[i]--; } long long r = 9*k - 8; cout << (double(win) / r) / (r - 1) << endl; }
#include<bits/stdc++.h> using namespace std; #define ll long long int main() { ll n;cin>>n; ll ans=0; if(n>=1000) ans+=n-999; if(n>=1000000) ans+=n-999999; if(n>=1000000000) ans+=n-999999999; if(n>=1000000000000) ans+=n-999999999999; if(n>=1000000000000000) ans+=n-999999999999999; cout<<ans<<endl; }
#include <bits/stdc++.h> #include <string> #include <cmath> using namespace std; #define ll long long #define ld long double #define pb push_back #define Messi \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define pii pair<ll, ll> #define mod 1000000007 #define vi vector<ll> #define vii vector<pii> #define all(v) v.begin(), v.end() #define mi map<ll, ll> //Never Let U Go!! int main() { Messi; ll n; cin >> n; ll a[5], b[17]={0}; b[0] = 0; b[1] = 9; ll prev = b[1]; for (ll i = 2; i <= 16; i++) { b[i] += ((prev * 10) + b[i - 1]); prev = prev * 10; } ll num = n, dig = 0; while (num > 0) { dig++; num /= 10; } if (dig < 4) { cout << "0\n"; return 0; } ll cnt=1,k=0,ans=0; for (ll i = 4; i < dig; i++) { if(k%3==0) { ans+=cnt*(b[i]-b[i-1]); k++; } else if(k%3==1) { ans+=cnt*(b[i]-b[i-1]); k++; } else if(k%3==2) { ans+=cnt*(b[i]-b[i-1]); cnt++; k=0; } } cout<< ans + (n-b[dig-1])*cnt; return 0; }
#include<bits/stdc++.h> using namespace std; #define sz 200000 #define ll long long #define pb push_back #define pi 2*acos(0.0) #define f first #define s second #define mod 1000000007 #define fastio {ios_base::sync_with_stdio(false);cin.tie(NULL);} #define test ll t; cin>>t; while(t--) const int N = 1e6; bool prime[N+5]; void primenire() { int i, j; prime[0]=true; prime[1]=true; for(i=4; i<=N; i+=2) { prime[i]=true; } for(i=3; i*i<=N; i+=2) { if(!prime[i]) { for(j=i*i; j<=N; j+=2*i) { prime[j]=true; } } } } vector<int> node[100003]; int vis[100003]; int dis[100003]; ll cnt,ans; void dfs(int x) { cnt++; vis[x]=1; for(int i=0;i<node[x].size();i++) { int tmp=node[x][i]; if(!vis[tmp]) { dfs(tmp); } } } ll big_mod(ll base, ll power) { if(power == 0)return 1; int h = big_mod(base, power / 2); h = (h * h) % mod; if(power % 2 )h = (h * base) % mod; return h; } int main() { double a,b; cin>>a>>b; double p = (a*1.0/100*1.0); double pp = (p*1.0*b); cout<<pp<<endl; }
#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 SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl;} #define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}} #define ALL(v) v.begin(),v.end() #define Decimal fixed<<setprecision(20) #define INF 1000000000 #define LLINF 1000000000000000000LL #define MOD 998244353 typedef long long ll; typedef pair<ll,ll> P; struct UF { vector<int> par; // 親のインデックスを記憶する配列 vector<int> sz; // サイズを記憶する。 // 初期化 UF(int n):par(n),sz(n){ for(int i = 0; i < n; i++){ par[i] = i;sz[i] = 1; } } // 親を求める int find(int x) { if (par[x] == x) return x; else return par[x] = find(par[x]); } // xとyの属する集合を併合 void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if(sz[x] > sz[y])swap(x, y); par[x] = y; sz[y] += sz[x]; // マージデクはここでやる(x -> y) } // xとyが同じ集合ならtrue bool same(int x, int y) { return find(x) == find(y); } // 素の集合のサイズを求める int size(int n){return sz[find(n)];} }; int main(){ cin.tie(0);cout.tie(0);ios::sync_with_stdio(false); ll n;cin >> n; UF uf(n); REP(i, n) { ll a;cin >> a;a--; uf.unite(i, a); } ll cou = 0; REP(i, n)if(uf.find(i) == i)cou++; ll ans = 1; REP(i, cou)ans = ans * 2 % MOD; cout << (ans + MOD - 1) % MOD << endl; return 0; }
// https://atcoder.jp/contests/abc180/tasks/abc180_e #include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0; i<(int)(n); i++) #define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++) #define DEBUG 1 #if DEBUG #define _GLIBCXX_DEBUG #define DUMP(a) REP(_i, a.size()) cout << a[_i] << (_i + 1 == a.size() ? "\n" : " ") #define DUMP2D(b) REP(_j, b.size()) DUMP(b[_j]); cout << endl #else #define DUMP(a) #define DUMP2D(b) #endif const int N_MAX = 17; const int X_I_MAX = 1e6; const int Y_I_MAX = 1e6; const int Z_I_MAX = 1e6; const int INF = 1e9; int N; vector<int> X; vector<int> Y; vector<int> Z; int S; vector<vector<int>> d; vector<vector<int>> dp; int main() { cin >> N; X = vector<int>(N); Y = vector<int>(N); Z = vector<int>(N); REP(i, N) cin >> X[i] >> Y[i] >> Z[i]; d = vector<vector<int>>(N, vector<int>(N)); REP(v, N) REP(u, N) { d[v][u] = abs(X[u] - X[v]) + abs(Y[u] - Y[v]) + max(0, Z[u] - Z[v]); } S = 1 << N; dp = vector<vector<int>>(S, vector<int>(N, INF)); dp[S - 1][0] = 0; for (int s = S - 2; s >= 0; s--) { REP(v, N) REP(u, N) if (!(s >> u & 1)){ dp[s][v] = min(dp[s][v], d[v][u] + dp[s | 1 << u][u]); } REP(v, N) REP(u, N) if (s >> u & 1){ dp[s][v] = min(dp[s][v], d[v][u] + dp[s][u]); } } int ans = dp[0][0]; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; template <class A, class B> bool cmin(A& a, B b) { return a > b && (a = b, true); } template <class A, class B> bool cmax(A& a, B b) { return a < b && (a = b, true); } template <typename T> class Dinic { public: static_assert(std::is_integral<T>::value, "Integral required."); struct edge { int to; T cap; int rev; }; private: const int V; T max_cap; vector<int> level, iter, que; static unsigned long long floor2(unsigned long long v) { v = v | (v >> 1), v = v | (v >> 2); v = v | (v >> 4), v = v | (v >> 8); v = v | (v >> 16), v = v | (v >> 32); return v - (v >> 1); } void bfs(const int s, const T base) { fill(level.begin(), level.end(), -1); level[s] = 0; int qh = 0, qt = 0; for (que[qt++] = s; qh < qt;) { int v = que[qh++]; for (edge& e : G[v]) { if (level[e.to] < 0 && e.cap >= base) { level[e.to] = level[v] + 1; que[qt++] = e.to; } } } } T dfs(const int v, const int t, const T base, const T f) { if (v == t) return f; T sum = 0; for (int& i = iter[v]; i < (int)G[v].size(); i++) { edge& e = G[v][i]; if (e.cap >= base && level[v] < level[e.to]) { T d = dfs(e.to, t, base, min(f - sum, e.cap)); if (d > 0) { e.cap -= d; G[e.to][e.rev].cap += d; sum += d; if (f - sum < base) break; } } } return sum; } public: vector<vector<edge> > G; Dinic(const int node_size) : V(node_size), max_cap(0), level(V), iter(V), que(V), G(V) {} void add(const int from, const int to, const T cap) { G[from].push_back((edge){to, cap, (int)G[to].size()}); G[to].push_back((edge){from, (T)0, (int)G[from].size() - 1}); max_cap = max(max_cap, cap); } T solve(const int s, const int t) { T flow = 0; for (T base = floor2(max_cap); base >= 1;) { bfs(s, base); if (level[t] < 0) { base >>= 1; continue; } fill(iter.begin(), iter.end(), 0); flow += dfs(s, t, base, numeric_limits<T>::max()); } return flow; } }; signed main() { cin.tie(nullptr)->sync_with_stdio(false); int N; cin >> N; int MX = N + 4e5 + 2; Dinic<int> D(MX); for (int i = 0; i < N; i++) { D.add(MX - 2, i, 1); int a, b; cin >> a >> b, a--, b--; D.add(i, N + a, 1); D.add(i, N + b, 1); } for (int i = 0; i < 4e5; i++) { D.add(N + i, MX - 1, 1); } cout << D.solve(MX - 2, MX - 1) << '\n'; }
//#include <atcoder/all> //using namespace atcoder; #include <bits/stdc++.h> using namespace std; typedef long long ll; #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, m, n) for(int i=m; i<n; i++) #define ALL(v) v.begin(), v.end() #define SIZE(x) int(x.size()) #define bit(n) (1LL<<(n)) #define FIX(d) fixed << setprecision(d) using P = pair<int, int>; using vvi = vector<vector<int>>; using vvl = vector<vector<ll>>; 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 int INF = 2e9; const ll LINF = (1LL<<60); int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n,w; cin >> n >> w; vector<int> s(n), t(n), p(n); REP(i,n) cin >> s[i] >> t[i] >> p[i]; vector<ll> sums(2e5+1, 0); REP(i,n){ sums[s[i]] += p[i]; sums[t[i]] -= p[i]; } REP(i,2e5) sums[i+1] += sums[i]; REP(i,2e5){ if(sums[i]>w){ cout << "No\n"; return 0; } } cout << "Yes\n"; return 0; }
#include<bits/stdc++.h> using namespace std; using ll = long long; const int MT = 200010; int main() { int N; cin >> N; ll W; cin >> W; vector<ll> imos(MT + 1); for(int i = 0; i < N; i++) { ll s, t, p; cin >> s >> t >> p; imos[s] += p; imos[t] -= p; } for(int i = 0; i < MT; i++)imos[i + 1] += imos[i]; cout << (*max_element(imos.begin(), imos.end()) <= W ? "Yes" : "No") << endl; }
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <climits> #include <cstdlib> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <vector> #define DEBUG 1 using namespace std; constexpr int kMod = 1000000007; typedef long long LL; pair<int, int> p(LL N) { set<LL> v; for (LL i = 1; i * i <= N; ++i) { if (N % i == 0) { v.insert(i); v.insert(N/i); } } int cnt_o = 0, cnt_e = 0; for (auto i : v) { if (i % 2 == 0) ++cnt_e; else ++cnt_o; } return {cnt_o, cnt_e}; } template<typename T1, typename T2> ostream& operator << (ostream& os, const pair<T1, T2>& p){ os << "{" << p.first << "," << p.second << "} "; return os; } int main() { int T; cin >> T; for (int i = 0; i < T; ++i) { LL c; cin >> c; if (c % 2 == 1) { cout << "Odd" << endl; } else { c /= 2; if (c % 2 == 1) cout << "Same" << endl; else cout << "Even" << endl; } } }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define debug(x) cerr << #x << " = " << x << endl; #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define MSET(c, v) memset(c, v, sizeof(c)) const ll INF = 1e17; const int NEGINF = 0xC0C0C0C0; const int NULO = -1; const double EPS = 1e-10; const ll mod = 1e9 + 7; int dx[] = {0,1,-1,0}; int dy[] = {1,0,0,-1}; const int maxn = 1e3 + 10; void solveTestCase() { ll n; cin >> n; if(n & 1) { cout << "Odd\n"; } else { if(n % 4 == 0) { cout << "Even\n"; } else { cout << "Same\n"; } } } int main() { ios::sync_with_stdio(false); int test; cin >> test; // test = 1; while(test--) { solveTestCase(); } return 0; }
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <cstdio> #include <cstring> #include <cmath> using namespace std; using ll = long long; int main() { ll n; cin >> n; double t = (double)(n + 1); t = sqrt(2 * t + 0.25) - 0.5; int m = 10000; ll x = (ll)t + m; for (int i = 0; i < m * 2; i++) { ll s = x * (x + 1) / 2; if (x * (x + 1) / 2 <= n + 1) break; x--; } cout << n + 1 - x << endl; return 0; }
#include <iostream> #include <cmath> using namespace std; int main() { long long n; cin >> n; long long k = (long long)floor(sqrt(2 * n + (long double)2.25) - (long double)0.5); long long result = n - k + 1; cout << result << endl; }
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define R cin>> #define ll long long #define ln cout<<'\n' #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; void Main() { string s; R s; vector<ll> a[2]; rep(i,s.size()) { if(s[i]=='o') a[0].pb(i); if(s[i]=='x') a[1].pb(i); } ll ans=0; rep(k,10000) { ll u[10]; mem(u); if(!k||k<1000) u[0]=1; ll x=k; while(x) { u[x%10]=1; x/=10; } rep(i,a[0].size()) { if(!u[a[0][i]]) goto next; } rep(i,a[1].size()) { if(u[a[1][i]]) goto next; } ans++; next:; } pr(ans); } int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}
#pragma GCC optimize(2) //#include <bits/stdc++.h> #include <iostream> #include <set> #include <cmath> #include <cstdio> #include <algorithm> #include <cstring> #include <queue> #include <vector> #include <utility> #include <map> #define rush() int T; while(cin>>T) while(T--) #define ms(a,b) memset(a,b,sizeof a) #define lowbit(x) ((x)&(-x)) #define inf 0x7f7f7f7fll #define eps 1e-11 #define sd(a) scanf("%d",&a) #define sll(a) scanf("%lld",&a) #define sll2(a,b) scanf("%lld%lld",&a,&b) #define sll3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c) #define sdd(a,b) scanf("%d%d",&a,&b) #define sddd(a,b,c) scanf("%d%d%d",&a,&b,&c) #define sf(a) scanf("%lf",&a) //#define sc(a) scanf("%c\n",&a) #define ss(a) scanf("%s",a) #define pd(a) printf("%d\n",a) #define pdd(a,b) printf("%d %d\n",a,b) #define pddd(a,b,c) printf("%d %d %d\n",a,b,c) #define pll(a) printf("%lld\n",a) #define pf(a) printf("%.1lf\n",a) #define pc(a) printf("%c",a) #define ps(a) printf("%s\n",a) #define rep(i,a,b) for(int i=(a);i<=(b);i++) #define forn(i,a,b,x) for(int i=(a);i<=(b);i+=(x)) #define per(i,a,b) for(int i=(b);i>=(a);i--) #define pb(a) push_back(a) #define mp(a,b) make_pair(a,b) #define debug(a) cout<<#a<<" : "<<a<<" "<<" ; " #define dbg(a) cout<<#a<<" : "<<a<<endl #define show(a,b) cout<<a<<" :\t"<<b<<"\t*"<<endl #define IOS ios::sync_with_stdio(0); cin.tie(0) #define PAUSE system("pause") #define all(x) x.begin(),x.end() //#define print(a) cout<<a<<endl;continue; #define fr first #define sc second #define ceils(a,b) ((a-1ll+b)/(b)) #define floors(a,b) floor(double(a)/double(b)) using namespace std; //inline void swap(int &x,int &y){x^=y^=x^=y;} typedef long long ll; //using ui=unsigned int; typedef unsigned long long ull; typedef pair<int,int> pii; const double pi=acos(-1.0); const int dx[]={0,1,0,-1}; const int dy[]={1,0,-1,0}; const int limit=5e5; int read() { int s=0; char c=getchar(),lc='+'; while (c<'0'||'9'<c) lc=c,c=getchar(); while ('0'<=c&&c<='9') s=s*10+c-'0',c=getchar(); return lc=='-'?-s:s; } void write(int x) { if (x<0) putchar('-'),x=-x; if (x<10) putchar(x+'0'); else write(x/10),putchar(x%10+'0'); } void print(int x,char c='\n') { write(x); putchar(c); } ll mod=2147483648; const int N=3e5+5; int n, m, _; int i, j, k; int a[N]; int pos[N]; vector<int> ans; signed main() { //IOS; rush(){ sd(n); rep(i, 1, n) sd(a[i]), pos[a[i]] = i; int opt = 1; rep(i, 1, n){ if(i == pos[i]) continue; if((pos[i] - 1) % 2 != opt){ if(pos[i] - 2 >= i){ ans.pb(pos[i] - 2); int x = pos[i] - 2, y = pos[i] - 1; swap(pos[a[x]], pos[a[y]]); swap(a[x], a[y]); opt ^= 1; } else { //if(pos[i] == i + 1){ ans.pb(i - 1); ans.pb(i); ans.pb(i - 1); ans.pb(i); ans.pb(i - 1); //ans.pb(i); opt ^= 1; int x = pos[i], y = pos[i] - 1; swap(pos[a[x]], pos[a[y]]); swap(a[x], a[y]); continue; } } for(int j = pos[i] - 1; j >= i; j--){ ans.pb(j); int x = j, y = j + 1; swap(pos[a[x]], pos[a[y]]); swap(a[x], a[y]); opt ^= 1; } } pd(ans.size()); for(auto it : ans) printf("%d ", it); puts(""); ans.clear(); } //PAUSE; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long const ll mod=1e9+7; const ll INF=4e18; const int inf=1e9; const double pi=acos(-1); ll n, ans; ll cek(ll pos, ll pjg){ return pjg*(2*pos+(pjg-1))/2; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for(int len=1;len<=2000000;++len){ ll l=1, r=n; while(l<=r){ ll mid=(l+r)/2; ll cur=cek(mid, len); if(cur==n){ ans+=2; break; } else if(cur>n){ r=mid-1; } else l=mid+1; } } cout << ans << '\n'; }
/****************************************** * AUTHOR : RTG * ******************************************/ #include <bits/stdc++.h> using namespace std; // long long dp[(long long)1e12+1]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE // For getting input from input.txt file FILE *input = freopen("/home/tharun/Documents/cpg/input.txt", "r", stdin); // Printing the Output to output.txt file FILE *output = freopen("/home/tharun/Documents/cpg/output.txt", "w", stdout); int start_time = (int)clock(); #endif long long n; cin>>n; n*=2; long long ans=0; for(long long i=1;i*i<=n;i++){ if(n%i==0){ long long d1=i; long long d2=n/i; if((d2-d1+1)%2==0){ ans++; } } } cout<<2*ans; #ifndef ONLINE_JUDGE // Time taken for execution cout<<"\nTime = "<<clock() - start_time<<"ms"; #endif return 0; }
#include <bits/stdc++.h> #define int long long using namespace std; signed main(){ ios_base::sync_with_stdio(false);cin.tie(NULL); int a,b; cin >> a >> b; vector <int> A(a),B(b); for(int i=0;i<a;i++)A[i]=i+1; for(int i=0;i<b;i++)B[i]=-(i+1); if(a>b){ B[b-1]=-((a*(a+1)/2)-((b*(b-1)/2))); } if(b>a){ A[a-1]=(b*(b+1)/2)-(a*(a-1)/2); } for(int i=0;i<a;i++)cout << A[i] << " "; for(int i=0;i<b;i++)cout << B[i] << " "; }
#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int, int> II; const int MAXN = 1000 + 10; int n, m, a[MAXN], b[MAXN]; int main() { scanf("%d%d", &n, &m); int rev = 0; if (n < m) { rev = 1; swap(n, m); } for (int i = 1; i <= n; ++i) { a[i] = i; } for (int i = 1; i <= m; ++i) { b[i] = i; } int sum = 0; for (int i = 1; i <= n; ++i) { sum += a[i]; } for (int i = 1; i <= m; ++i) { sum -= b[i]; } for (int i = 1; i <= m; ++i) { b[i] += sum / m; } b[m] += sum % m; if (rev == 0) { for (int i = 1; i <= m; ++i) { b[i] = -b[i]; } } else { for (int i = 1; i <= n; ++i) { a[i] = -a[i]; } } for (int i = 1; i <= n; ++i) { printf("%d ", a[i]); } for (int i = 1; i <= m; ++i) { printf("%d ", b[i]); } puts(""); return 0; }
#include <bits/stdc++.h> #define int long long using namespace std; inline int read(){ int s=0,w=1; char ch=getchar(); while(ch<'0'||ch>'9'){ if(ch=='-')w=-1;ch=getchar(); } while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar(); return s*w; } inline bool read(int& a){ int s=0,w=1; char ch=getchar(); if(ch==EOF){ return false; } while(ch<'0'||ch>'9'){ if(ch=='-')w=-1;ch=getchar(); } while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar(); a=s*w; return true; } inline void write(int x){ if(x<0) putchar('-'),x=-x; if(x>9) write(x/10); putchar(x%10+'0'); } inline void writeln(int x){ if(x<0) putchar('-'),x=-x; if(x>9) write(x/10); putchar(x%10+'0'); puts(""); } const int MOD=998244353; int n,k; int f[3010][3010]; signed main(){ read(n),read(k); f[1][1]=1; for(int i=2;i<=n;i++){ for(int j=i;j>=1;j--){ f[i][j]=(f[i-1][j-1]+f[i][j*2])%MOD; } } writeln(f[n][k]%MOD); return 0; }
/*input 2525 425 */ //#include "wall.h" #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; #pragma GCC optimize("unroll-loops,no-stack-protector") //order_of_key #of elements less than x // find_by_order kth element #define ll long long #define ld long double #define pii pair<int,int> #define piii pair<int,pii> typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; #define f first #define s second #define pb push_back #define REP(i,n) for(ll i=0;i<n;i++) #define REP1(i,n) for(int i=1;i<=n;i++) #define FILL(n,x) memset(n,x,sizeof(n)) #define ALL(_a) _a.begin(),_a.end() #define sz(x) (int)x.size() #define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end())))) #define MP make_pair const ll INF64=4e18; const int INF=0x3f3f3f3f; const ll MOD=998244353; const ld PI=acos(-1); const ld eps=1e-9; #define lowb(x) x&(-x) #define MNTO(x,y) x=min(x,(__typeof__(x))y) #define MXTO(x,y) x=max(x,(__typeof__(x))y) ll mult(ll a,ll b){ return ((a%MOD)*(b%MOD))%MOD; } ll mypow(ll a,ll b){ if(b<=0) return 1; ll res=1LL; while(b){ if(b&1){ res=(res*a)%MOD; } a=(a*a)%MOD; b>>=1; } return res; } const ll maxn=3e3+5; const ll maxlg=__lg(maxn)+2; ll dp[maxn][maxn]; ll pref[maxn]; ll rec(int n,int k){ if(n==0 and k==0) return 1; if(k==0) return 0; if(n<k) return 0; if(dp[n][k]) return dp[n][k]; return dp[n][k]=(rec(n-1,k-1)+rec(n,2*k))%MOD; } int main(){ ios::sync_with_stdio(false),cin.tie(0); int n,k; cin>>n>>k; cout<<rec(n,k)<<'\n'; }
#include <bits/stdc++.h> using namespace std; #define int long long int32_t main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int l; cin >> l; vector<array<int, 12>> dp(l + 1); for(int i = 1; i <= l; i++) { dp[i][0] = 1; } for(int cut = 1; cut <= 11; cut++) { dp[1][cut] = 0; } for(int i = 2; i <= l; i++) { for(int cut = 1; cut <= 11; cut++) { dp[i][cut] = dp[i - 1][cut] + dp[i - 1][cut - 1]; } } // for(int i = 1; i <= l; i++) { // for(int cut = 0; cut <= 11; cut++) { // cout << dp[i][cut] << ' '; // } // cout << endl; // } cout << dp[l][11]; return 0; }
#include<iostream> #define FAST ios::sync_with_stdio(false),cin.tie(0),cout.tie(0) using namespace std; typedef long long ll; const int MAXN=1e5+5; ll cal(ll n) { ll ans=1; int cnt=11; for(int i=1;i<12;++i) { ans*=n-i; ans/=i; } return ans; } int main() { FAST; ll n; cin>>n; cout<<cal(n)<<endl; }
#include<iostream> #include<iomanip> #include<string> #include<vector> #include<algorithm> #include<utility> #include<tuple> #include<map> #include<queue> #include<deque> #include<set> #include<stack> #include<numeric> #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> using namespace std; struct Edge { int to; long long weight; Edge() : to(0), weight(0) {} Edge(int to, long long weight) : to(to), weight(weight) {} Edge(const Edge& e) { to = e.to; weight = e.weight; } bool operator>(const Edge &e) const { return weight > e.weight; } bool operator<(const Edge &e) const { return weight < e.weight; } bool operator==(const Edge &e) const { return weight == e.weight; } bool operator<=(const Edge &e) const { return weight <= e.weight; } bool operator>=(const Edge &e) const { return weight >= e.weight; } }; using ll = long long; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; using Graph = vector<vector<int>>; using weightedGraph = vector<vector<Edge>>; using heap = priority_queue<int, vector<int>, greater<int>>; const ll BIL = 1e9; const ll MOD = 1e9 + 7; const ll INF = 1LL << 60; const int inf = 1 << 29; const ld PI = 3.141592653589793238462643383; struct SegmentTree { int sz; vector<int> t; SegmentTree(int n) { sz = 1; while(sz < n) sz *= 2; t.assign(2 * sz - 1, 0); } void init(int idx, ll val) { idx += sz-1; t[idx] = val; return; } void update(int idx, int val) { idx += sz - 1; t[idx] = val; while(idx > 0) { idx = (idx - 1) / 2; if(t[idx] > val) break; t[idx] = val; } return; } void update(int l, int r, ll val, int now=0, int a=0, int b=-1) { if(now >= t.size()) return; if(b < 0) b = sz; if(l < 0) l = 0; if(r > sz) r = sz; if(r < a || l > b) return; if(l <= a && b <= r) { t[now] -= val; return; } update(l, r, val, now*2+1, a, (a+b)/2); update(l, r, val, now*2+2, (a+b)/2, b); return; } int getMax(int l, int r, int now=0, int a=0, int b=-1) { if(now >= t.size()) return 0; if(b < 0) b = sz; if(l < 0) l = 0; if(r > sz) r = sz; if(l > b || r < a) return 0; if(l <= a && r >= b) return t[now]; int res = 0; res = max(res, getMax(l, r, 2*now+1, a, (a+b)/2)); res = max(res, getMax(l, r, 2*now+2, (a+b)/2, b)); return res; } ll getElement(int idx) { if(idx == 0) return t[0]; ll res = t[idx]; return res += getElement((idx-1)/2); } ll operator[](int idx) { idx += sz-1; return getElement(idx); } }; int main(int argc,char* argv[]){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20); int n; cin >> n; vector<ll> a(n); map<int, ll> mp; for(int i=0;i<n;i++) { ll k; cin >> k; k %= 200; a[i] = k; mp[k]++; } ll ans = 0; for(auto e : mp) { if(e.second == 1) continue; ll t = e.second; ans += t * (t-1) / 2; } cout << ans << endl; return 0; }
#include <iostream> #include <vector> #include <cmath> #include <algorithm> #include <cstring> #include <unordered_map> using namespace std; typedef long long ll; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; vector<int> arr(n); vector<int> rem(201, 0); ll ans = 0; for (int i = 0; i < n; i++) { cin >> arr[i]; arr[i] %= 200; ans += rem[arr[i]]; rem[arr[i]]++; } cout << ans << endl; return 0; }
#include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <bits/stdc++.h> using namespace __gnu_pbds; using namespace std; using ll = long long; using ld = long double; typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; #define mp make_pair const int MOD = 998244353; int mul(int a, int b) { return (1LL * a * b) % MOD; } int add(int a, int b) { int s = (a+b); if (s>=MOD) s-=MOD; return s; } int sub(int a, int b) { int s = (a+MOD-b); if (s>=MOD) s-=MOD; return s; } int po(int a, ll deg) { if (deg==0) return 1; if (deg%2==1) return mul(a, po(a, deg-1)); int t = po(a, deg/2); return mul(t, t); } int inv(int n) { return po(n, MOD-2); } mt19937 rnd(time(0)); const int LIM = 3e5 + 5; vector<int> facs(LIM), invfacs(LIM); void init() { facs[0] = 1; for (int i = 1; i<LIM; i++) facs[i] = mul(facs[i-1], i); invfacs[LIM-1] = inv(facs[LIM-1]); for (int i = LIM-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1); } int C(int n, int k) { if (n<k) return 0; if (n<0 || k<0) return 0; return mul(facs[n], mul(invfacs[k], invfacs[n-k])); } /*struct DSU { vector<int> sz; vector<int> parent; void make_set(int v) { parent[v] = v; sz[v] = 1; } int find_set(int v) { if (v == parent[v]) return v; return find_set(parent[v]); } void union_sets(int a, int b) { find_set(a); find_set(b); a = find_set(a); b = find_set(b); if (a != b) { if (sz[a] < sz[b]) swap(a, b); parent[b] = a; sz[a] += sz[b]; }; } DSU (int n) { parent.resize(n); sz.resize(n); for (int i = 0; i<n; i++) make_set(i); } };*/ /* dp[cnt][sum][xor] Bit dp */ int main() { ios_base::sync_with_stdio(0); cin.tie(nullptr); init(); int n, m; cin>>n>>m; vector<int> dp(m+1); dp[0] = 1; for (int sum = 2; sum<=m; sum+=2) { for (int odd = 0; odd<=min(n, sum); odd+=2) { dp[sum] = add(dp[sum], mul(C(n, odd), dp[(sum-odd)/2])); } } cout<<dp[m]; }
#include<bits/stdc++.h> #define x first #define y second #define pb push_back #define eb emplace_back #define all(a) (a).begin(),(a).end() #define SZ(a) (int)(a).size() #define FOR(i, a, b) for(int i=(a); i<=(b); ++i) #define ROF(i, a, b) for(int i=(a); i>=(b); --i) #define make_unique(a) sort(all((a))), (a).resize(unique(all((a)))-(a).begin()) #define pc(x) putchar(x) #define make_pair MP #define make_tuple MT using namespace std; typedef long long i64; typedef tuple<int,int,int> iii; typedef pair<int,int> pii; typedef pair<i64, i64> pll; typedef vector<int> vi; typedef vector<vi> vvi; void solve(){ int n; scanf("%d",&n); vi nxt(n+1); FOR(i, 1, n) scanf("%d",&nxt[i]); vi visit(n+1), onstack(n+1); stack<int> stk; int cnt = 0; FOR(i, 1, n){ if(visit[i]) continue; int nw = i; while(1){ visit[nw] = 1; onstack[nw] = 1; stk.push(nw); if(visit[nxt[nw]]){ if(onstack[nxt[nw]]) ++cnt; while(!stk.empty()){ onstack[stk.top()] = 0; stk.pop(); } break; }else{ nw = nxt[nw]; } } } int ans = 1; int mod = 998244353; FOR(i, 1, cnt) ans = (ans+ans >= mod) ? ans+ans-mod : ans+ans; printf("%d",(ans-1+mod)%mod); } int main(){ solve(); return 0; } /* * * * * * * * * * * */
#include <bits/stdc++.h> using namespace std; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(),(a).rend() #define PRINT(a) cout << (a) << endl #define pb push_back #define eb emplace_back #define mp make_pair #define Fi first #define Se second #define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n'; using ll = long long int; using P = pair<int,int>; using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; using pii = pair<int, int>; template <typename T> using PQ = priority_queue<T>; template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>; 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; } const int INF = 1001001001; const ll LINF = 1001001001001001001ll; const int MOD = 1e9 + 7; int main(){ int x; cin >> x; cout << (x >= 0 ? x : 0 ) << endl; }
#include <bits/stdc++.h> using namespace std; #define all(x) (x).begin(),(x).end() #define print(x) cout << (x) << endl typedef long long ll; using P = pair<int,int>; using Graph = vector<vector<int>>; //const ll MOD = 1000000007; const ll MOD = 998244353; template <typename T> inline bool chmax(T &a, T b) {return a < b ? a = b, true : false;} template <typename T> inline bool chmin(T &a, T b) {return a > b ? a = b, true : false;} void solve() { int n; cin >> n; vector<int> t(n + 1, -1); queue<int> pr; for(int i=2; i<=n; i++){ if(t[i] < 0){ pr.push(i); for(int j=i+i; j<=n; j+=i) t[j] = 0; } } vector<int> a(n + 1, -1); a[1] = 1; for(int i=2; i<=n; i++){ if(t[i] == -1){ a[i] = 2; for(int j=i+i; j<=n; j+=i) a[j] = a[i] + 1; }else{ for(int j=i+i; j<=n; j+=i) a[j] = a[i] + 1; } } for(int i=1; i<n+1; i++) cout << a[i] << " "; int ma = 0; cout << endl; return; } int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(18); int t; //cin >> t; t = 1; while(t--) solve(); return 0; }
#include <bits/stdc++.h> #define mp make_pair #define fi first #define se second #define pb push_back #define eb emplace_back #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define forn(i, n) for (int i = 0; i < (int)(n); ++i) #define for1(i, n) for (int i = 1; i <= (int)(n); ++i) #define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i) #define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i) #define rep(i, l, r) for (int i = (l); i <= (r); i++) #define per(i, r, l) for (int i = (r); i >= (l); i--) #define ms(x, y) memset(x, y, sizeof(x)) #define SZ(x) int(x.size()) #define fk cerr<<"fk"<<endl #define db(x) cerr<<(#x)<<'='<<(x)<<endl using namespace std; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pii> vpi; typedef vector<vi> vvi; typedef long long i64; typedef vector<i64> vi64; typedef vector<vi64> vvi64; typedef pair<i64, i64> pi64; typedef double ld; template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; } template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; } //1.integer overflow (1e5 * 1e5) (2e9 + 2e9) //2.runtime error //3.boundary condition const int N=2100; int h,w,vis[N][N],dir[4][2]={{-1,0},{1,0},{0,1},{0,-1}}; char mat[N][N]; vector< pair<int,int> > idx[30]; bool ok(int x,int y){ if(x<1 || x>h || y<1 || y>w) return false; if(mat[x][y]=='#') return false; if(vis[x][y]==1) return false; return true; } int bfs(int sx,int sy){ queue< pair< pair<int,int>,int > > q; q.push(mp(mp(sx,sy),0)); vis[sx][sy]=1; while(!q.empty()){ pair< pair<int,int>,int > now=q.front(); q.pop(); int nx=now.fi.fi,ny=now.fi.se; if(mat[nx][ny]=='G') return now.se; char temp=mat[nx][ny]; if(temp>='a' && temp<='z'){ for(pair<int,int> np:idx[int(temp-'a')]){ vis[np.fi][np.se]=1; q.push(mp(mp(np.fi,np.se),now.se+1)); } idx[int(temp-'a')].clear(); } for(int i=0; i<4; ++i){ int tx=nx+dir[i][0]; int ty=ny+dir[i][1]; if(ok(tx,ty)){ //if(mat[tx][ty]=='G') return now.se+1; vis[tx][ty]=1; q.push(mp(mp(tx,ty),now.se+1)); } } } return -1; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed; #ifdef LOCAL_DEFINE freopen("input.txt", "r", stdin); #endif cin>>h>>w; int sx,sy; for1(i, h){ for1(j, w){ cin>>mat[i][j]; if(mat[i][j]>='a' && mat[i][j]<='z'){ int num=int(mat[i][j]-'a'); idx[num].eb(mp(i,j)); } if(mat[i][j]=='S'){ sx=i; sy=j; } } } ms(vis,0); cout<<bfs(sx,sy)<<'\n'; #ifdef LOCAL_DEFINE cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; #endif return 0; }
#include <bits/stdc++.h> #define MOD (long long)(1E9+7) #define rep(i, n) for(int i = 0; i < n; i++) using namespace std; int table[2000][2000]; void bfs(queue<pair<int,int>> &que, vector<vector<pair<int,int>>> &warp, int &now, int &w, int &h) { int n = que.size(); rep(lll,n) { auto x = que.front(); int i = x.first; int j = x.second; que.pop(); if(table[i][j] >=10000000) { int abc = table[i][j] -10000000-1; table[i][j] = now+1; rep(k, warp[abc].size()) { auto yy = warp[abc][k]; if(table[yy.first][yy.second] > now+1) { que.push(make_pair(yy.first,yy.second)); table[yy.first][yy.second] = -1; } } } if(table[i][j] > now || table[i][j] == -1) { table[i][j] = now; if(i>0 && (table[i-1][j] == -1 || table[i-1][j]>now+1)) { que.push(make_pair(i-1,j)); } if(i<h-1 && (table[i+1][j] == -1 || table[i+1][j]>now+1)) { que.push(make_pair(i+1,j)); } if(j>0 && (table[i][j-1] == -1 || table[i][j-1]>now+1)) { que.push(make_pair(i,j-1)); } if(j<w-1 && (table[i][j+1] == -1 || table[i][j+1]>now+1) ) { que.push(make_pair(i,j+1)); } } } if(!que.empty()) { now++; bfs(que, warp, now,w,h); } } int main(){ int h,w,sx,sy,gx,gy; string s; cin >> h >> w; vector<vector<pair<int,int>>> warp(26); rep(i,h)rep(j,w) table[i][j] = -1; rep(i,h) { cin >> s; rep(j,w) { if(s[j] >= 'a' && s[j] <= 'z') { table[i][j] = 10000000+s[j]-'a'+1; warp[(s[j]-'a')].push_back(make_pair(i, j)); } else if(s[j] == 'S') { sx = j; sy = i; } else if(s[j] == 'G') { gx = j; gy = i; } else if(s[j] == '.') { continue; } else if(s[j] == '#') { table[i][j] = -2; } } } queue<pair<int,int>> que; que.push(make_pair(sy,sx)); int now=0; bfs(que, warp, now,w,h); cout << table[gy][gx] << endl; }
#include<bits/stdc++.h> using namespace std; int main(){ int a, b, c; cin >> a >> b >> c; if(a + b == 2 * c || a + c == 2 * b || b + c == 2 * a) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
#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 ff first #define ss second #define int long long #define pb push_back #define mp make_pair #define mt make_tuple #define pii pair<int,int> #define vi vector<int> #define mii map<int,int> #define pqb priority_queue<int> #define max_size 100000000 #define pqs priority_queue<int,vi,greater<int> > #define setbits(x) __builtin_popcountll(x) #define mod 1000000007 #define w(t) int t; cin >> t; while(t--) #define inf 1e3 #define ps(x,y) fixed<<setprecision(y)<<x #define mk(arr,n,type) type *arr=new type[n]; #define range(a,b) substr(a,b-a+1) #define mina(a,b,c) min(a, min(b, c)) #define maxa(a,b,c) max(a, max(b, c)) #define endl '\n' #define trace(x) cerr<<#x<<": "<<x<<" "<<endl; #define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define FOR(x,y) for(int i = x; i < y; i++) #define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> bool sortbysec(const pair<int,int> &a, const pair<int,int> &b){ return (a.second < b.second); } bool specsort(const pair<int,int> &a, const pair<int,int> &b){ if(a.first == b.first) return (a.second < b.second); else return (a.first < b.first); } int64_t ceil_div(int64_t a, int64_t b) {if(a%b != 0){ return ((a/b)+1);} else{ return (a/b);}} double max(double a, double b){ if(a >= b){ return a; } else{ return b; } } double min(double a, double b){if(a <= b){return a;} else{return b;}} bool modd(double a, double b){if(floor(a/b) == ceil(a/b)){return true;} return false;} bool stringsort(const string &a, const string &b){return a.length() > b.length();} int32_t main(){ FIO; int a,b,c; cin >> a >> b >> c; if(a*a + b*b < c*c) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
// Contest: AtCoder Regular Contest 104 (https://atcoder.jp/contests/arc104) // Problem: A: Plus Minus (https://atcoder.jp/contests/arc104/tasks/arc104_a) // region boilerplate #include <algorithm> #include <array> #include <bitset> #include <cassert> #include <cmath> #include <chrono> #include <cstdint> #include <deque> #include <exception> #include <forward_list> #include <functional> #include <initializer_list> #include <iomanip> #include <iostream> #include <iterator> #include <limits> #include <list> #include <map> #include <memory> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <tuple> #include <type_traits> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #if __cplusplus >= 201703L # include <optional> # include <string_view> # include <variant> #endif using namespace std; #if __cplusplus >= 201703L # define all(a) begin(a),end(a) # define sz(x) ((int)size(x)) #else # define all(a) (a).begin(),(a).end() # define sz(x) ((int)(x).size()) #endif #define rep(a, b) for(int a = 0; a < (b); ++a) #define reps(a, b, c) for(int a = (b); a < (c); ++a) #define trav(a, b) for(auto& a : b) using ll = long long; using ld = long double; using u64 = uint64_t; using u32 = uint32_t; using pi = pair<int, int>; using pl = pair<ll, ll>; using vi = vector<int>; using vl = vector<ll>; using vvi = vector<vi>; using vpi = vector<pi>; #if __cplusplus >= 201703L # define MAYBE_UNUSED [[maybe_unused]] #else # define MAYBE_UNUSED #endif MAYBE_UNUSED static constexpr int INF = (int)1e9 + 5; MAYBE_UNUSED static constexpr ll INFL = (ll)1e18 + 5; MAYBE_UNUSED static mt19937 rng((u32)chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count()); //endregion int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int a, b; cin >> a >> b; int y = (a - b) / 2; cout << (a - y) << ' ' << y << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < (n); ++i) using ll = long long; using P = tuple<ll, ll, int>; int main() { int n; cin >> n; vector<P> ps; rep(i, n) { ll x, y; cin >> x >> y; ps.emplace_back(x, y, i); } vector<bool> pushed(n); vector<P> use; auto push = [&]() -> void { rep(i, 3) { auto[x, y, id] = ps[i]; if(pushed[id]) continue; use.push_back(ps[i]); pushed[id] = true; } rep(_i, 3) { int i = n - 1 - _i; auto[x, y, id] = ps[i]; if(pushed[id]) continue; use.push_back(ps[i]); pushed[id] = true; } }; sort(ps.begin(), ps.end()); push(); sort(ps.begin(), ps.end(), [&](auto a, auto b) { auto[x, y, i] = a; auto[xb, yb, ib] = b; return y < yb; }); push(); vector<int> dist; for(auto &[x, y, i] : use) { for(auto &[x2, y2, i2] : use) { if(i == i2) continue; ll d = max(abs(x - x2), abs(y - y2)); dist.push_back(d); } } sort(dist.rbegin(), dist.rend()); cout << dist[2] << '\n'; return 0; }
/* ID: meadri01 LANG: C TASK: test */ #include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> #define int long long #define w(t) int t;cin>>t;while(t--) #define pb push_back #define mk make_pair #define ascSort(v) sort(v.begin(), v.end()) #define descSort(v) sort(v.begin(), v.end(), greater<int>()) #define ff first #define ss second #define pi pair<int,int> #define vi vector<int> #define mi map<int,int> #define fill(a,x) fill(a.begin(), a.end(), x) #define iota(a,x) iota(a.begin(), a.end(), x) #define umapi unordered_map<int,int> const int mod1=998244353; const int mod2=1e9+7; const int inf=mod2; using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>PBDS; void FIO(){ #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); } void usaco(string filename) { // #pragma message("be careful, freopen may be wrong") freopen((filename + ".in").c_str(), "r", stdin); freopen((filename + ".out").c_str(), "w", stdout); } void testcase(){ int n;cin>>n; vi a(n); for(int i=0; i<n; i++)cin>>a[i]; ascSort(a); double x=a[(n-1)/2]/2.0,ans2=0.0,ans1=0.0; for(int i=0; i<n; i++){ if(a[i]<=2.0*x){ ans1+=x; } else{ ans1+=x+a[i]*1.0 - 2*x; } } x=a[(n+1)/2]/2.0; for(int i=0; i<n; i++){ if(a[i]<=2.0*x){ ans2+=x; } else{ ans2+=x+a[i]*1.0 - 2*x; } } cout<<fixed<<setprecision(10)<<min(ans1,ans2)/(n*1.0)<<"\n"; } int32_t main(){ FIO(); //usaco("test"); int t=1; //cin>>t; while(t--){ testcase(); } return 0; }
#include<bits/stdc++.h> using namespace std; /*#include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> is;*/ #define fb find_by_order #define ok order_of_key #define mem(x,y) memset(x,y,sizeof x) typedef long long ll; typedef int ii; typedef pair<ll,ll> pi; typedef vector<pi> vii; #define map unordered_map #define INF 100000000000007 #define pi 3.141592654 #define T while(t--) #define for2(i,a,b) for(i=a;i>=b;i--) #define for3(i,a,b) for(i=a;i<=b;i=i+2) #define for1(i,a,b) for(i=a;i<=b;i=i+1) #define for4(i,a,b) for(i=a;i>=b;i=i-2) #define pb push_back #define pf push_front #define mp make_pair #define ff first #define ss second #define si set<ll> #define se multiset<ll> typedef long double ld; typedef vector<ll> vi; #define all(v) sort(v.begin(),v.end()) #define all1(v) sort(v.rbegin(),v.rend()) #define pff(uuv) printf("%lld\n",uuv) #define pf1(uu) printf("%.20Lf\n",uu) bool comp(pair<ll,char> aa, pair<ll,char> bb) { if (aa.ff != bb.ff) return aa.ff > bb.ff; return aa.ss < bb.ss; } bool comp1(pair<ll,char> aa, pair<ll,char> bb) { if (aa.ff != bb.ff) return aa.ff < bb.ff; return aa.ss > bb.ss; } bool comp2(pair<ll,ll> aa, pair<ll,ll> bb) { if (aa.ff != bb.ff) return aa.ff > bb.ff; return aa.ss < bb.ss; } bool comp3(pair<ll,ll> aa, pair<ll,ll> bb) { if (aa.ff != bb.ff) return aa.ff < bb.ff; return aa.ss > bb.ss; } ll rup(ll ik,ll ikk){ if(ik%ikk==0) return ik/ikk; else return (ik/ikk)+1; } 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); } ld ex(ld x,ld y){ return x+y-min(y,2*x); } ii main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll t=1; //cin>>t; while(t--){ ll n; ll i; ld x; cin>>n; vector<ld> v; vi v2; for1(i,1,n){ cin>>x; v.pb(x/2); v2.pb(x); } all(v); if(n%2==1){ ll pp=rup(n,2); ld sum=0; for1(i,0,n-1){ sum+=ex(v[pp-1],v2[i]); //cout<<sum<<"\n"; } //cout<<sum<<"\n"; sum/=n; pf1(sum); } else{ ll pp=n/2; ll qq=rup(n,2); ld sum=0; ld sum1=0; for1(i,0,n-1){ sum+=ex(v[pp-1],v2[i]); } sum/=n; for1(i,0,n-1){ sum1+=ex(v[qq-1],v2[i]); } sum1/=n; ld ans=min(sum,sum1); pf1(ans); } } }
#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...);} #define debug(x...) cout << #x << " = "; _print(x) typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; #define rep(i,a,b) for (ll i = (a); i < (b); ++i) #define per(i,a,b) for (int i = (b)-1; i >= (a); --i) #define all(x) begin(x), end(x) #define mp make_pair #define pb push_back #define ff first #define ss second #define fast ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL) const int mod = 1e9 + 7, mxn = 1e5 + 1; int solve(){ char s, t; cin>> s>> t; if(s == 'Y') t = (t - 'a') + 'A'; cout<< t<< "\n"; return 0; } //Counting problems: Sometimes easier to find complement of the answer int main() { fast; int t = 1; // cin>> t; while(t--){ solve(); } return 0; } //v.clear(), vis.clear(); vis.resize(n + 1, 0), v.resize(n + 1); /* inv[1] = 1; // inv is ll for(int i=2; i<=mxn; ++i) inv[i]=mod-mod/i*inv[mod%i]%mod;*/ // lower bound >= // upper bound > // vector<int>().swap(vec); //free memory from vec
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main() { char n,s; cin>>n>>s; if(n=='N'){ s=(s>='A'&&s<='Z')?s+32:s; } else{ s=(s>='a'&&s<='z')?s-32:s; } cout<<s; }
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--) #define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++) #define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--) #define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++) #define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++) #define ALL(x) x.begin(), x.end() using ll = long long; using namespace std; int main(){ int n, t; cin >> n >> t; vector<int> a(n); rep(i, n) cin >> a.at(i); vector<int> b, c; rep(i, n){ if(i < n/2){ b.push_back(a.at(i)); }else{ c.push_back(a.at(i)); } } vector<ll> d; rep(bit, 1 << b.size()){ ll add = 0; rep(i, b.size()){ if((bit & (1 << i)) != 0){ add += b.at(i); } } d.push_back(add); } sort(ALL(d)); d.push_back(LLONG_MAX); ll ans = 0; rep(bit, 1 << c.size()){ ll add = 0; rep(i, c.size()){ if((bit & (1 << i)) != 0){ add += c.at(i); } } if(add > t) continue; auto itr = upper_bound(ALL(d), t - add); itr--; add += *itr; ans = max(ans, add); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define eb emplace_back #define ii pair<int, int> #define OK (cerr << "OK" << endl) #define debug(x) cerr << #x " = " << (x) << endl #define ff first #define ss second #define int long long #define tt tuple<int, int, int> #define all(x) x.begin(), x.end() #define vi vector<int> #define vii vector<pair<int, int>> #define vvi vector<vector<int>> #define vvii vector<vector<pair<int, int>>> #define Mat(n, m, v) vector<vector<int>>(n, vector<int>(m, v)) #define endl '\n' constexpr int INF = (sizeof(int) == 4 ? 1e9 : 2e18) + 1e5; constexpr int MOD = 1e9 + 7; constexpr int MAXN = 2e5 + 3; set<int, greater<int>> s; int n; vi arr; int ans = INF; int m; void f1(int idx, int cur) { if (idx == n / 2) { s.emplace(cur); return; } f1(idx + 1, cur); f1(idx + 1, cur + arr[idx]); } void f2(int idx, int cur) { if (idx == n) { auto it = s.lower_bound(m - cur); if (it != s.end()) ans = min(ans, m - (cur + *it)); return; } f2(idx + 1, cur); f2(idx + 1, cur + arr[idx]); } // #define MULTIPLE_TEST_CASES void solve() { cin >> n >> m; arr.resize(n); for (int &x : arr) cin >> x; f1(0, 0); f2(n / 2, 0); cout << m - ans << endl; } signed main() { // const string FILE_NAME = ""; // freopen((FILE_NAME + string(".in")).c_str(), "r", stdin); // freopen((FILE_NAME + string(".out")).c_str(), "w", stdout); ios_base::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); int t = 1; #ifdef MULTIPLE_TEST_CASES cin >> t; #endif while (t--) solve(); }
#include <iostream> #include <algorithm> using namespace std; int n, k, p[59][59], tp[59][59], ds[59], sz[59]; int uf(int n) { if (ds[n] == n) return n; return ds[n] = uf(ds[n]); } bool chk(int a, int b) { for (int i = 1; i <= n; i++) if (p[i][a] + p[i][b] > k) return false; return true; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> k; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) { cin >> p[i][j]; tp[i][j] = p[i][j]; } long long ans = 1, md = 998244353; for (int ti = 0; ti < 2; ti++) { for (int i = 1; i <= n; i++) { ds[i] = i; sz[i] = 1; } for (int i = 1; i <= n; i++) { for (int j = 1; j < i; j++) { if (chk(i, j)) { int ua = uf(i), ub = uf(j); if (ua != ub) { ds[ub] = ua; sz[ua] += sz[ub]; } } } } for (int i = 1; i <= n; i++) if (uf(i) == i) for (int j = 1; j <= sz[i]; j++) ans = (ans * j) % md; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) p[i][j] = tp[j][i]; } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { ios_base::sync_with_stdio(0); cin.tie(0); map <int, set <int>> g ; int n, m ; cin >> n >> m ; for (int i=0;i<m;++i) { int a, b ; cin >> a >> b ; g[a].insert(b) ; } set <int> res ; res.insert(n) ; n += n ; for (auto r: g) { vector <int> add ; int y = r.first ; for (auto it: g[y]) { for (auto d:{1, -1}) { if (res.count(it+d)) add.push_back(it) ; } } for (auto it: g[y]) res.erase(it) ; for (auto it: add) res.insert(it) ; } cout << res.size() << endl ; return 0; }
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cmath> #include <vector> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <queue> #include <ctime> #include <cassert> #include <complex> #include <string> #include <cstring> #include <chrono> #include <random> #include <bitset> using namespace std; #ifdef LOCAL #define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr); #else #define eprintf(...) 42 #endif using ll = long long; using ld = long double; using uint = unsigned int; using ull = unsigned long long; template<typename T> using pair2 = pair<T, T>; using pii = pair<int, int>; using pli = pair<ll, int>; using pll = pair<ll, ll>; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll myRand(ll B) { return (ull)rng() % B; } #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define fi first #define se second clock_t startTime; double getCurrentTime() { return (double)(clock() - startTime) / CLOCKS_PER_SEC; } const ll MOD = 998244353; ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; } ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; } ll mult(ll x, ll y) { return (x * y) % MOD; } ll bin_pow(ll x, ll p) { if (p == 0) return 1; if (p & 1) return mult(x, bin_pow(x, p - 1)); return bin_pow(mult(x, x), p / 2); } ll rev(ll x) { return bin_pow(x, MOD - 2); } const int N = 5050; int C[N][N]; int dp[N]; int n, m; int main() { startTime = clock(); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); scanf("%d%d", &n, &m); for (int i = 0; i < N; i++) C[i][0] = C[i][i] = 1; for (int i = 1; i < N; i++) for (int j = 1; j < i; j++) C[i][j] = add(C[i - 1][j - 1], C[i - 1][j]); for (int k = 2; k <= n; k += 2) dp[k] = C[n][k]; for (int x = 1; x < m; x++) for (int k = 0; 2 * x + k <= m && k <= n; k += 2) dp[2 * x + k] = add(dp[2 * x + k], mult(dp[x], C[n][k])); printf("%d\n", dp[m]); return 0; }
#include <iostream> using namespace std; int main(){ double a,b; cin>>a; cin>>b; double bKonprs = b / 100; cout<<a*bKonprs<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> p_ll; template<class T> void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; } #define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++) #define all(vec) vec.begin(), vec.end() #define rep(i,N) repr(i,0,N) #define per(i,N) for (ll i=(ll)N-1; i>=0; i--) const ll MOD = pow(10,9)+7; const ll LLINF = pow(2,61)-1; const ll INF = pow(2,30)-1; vector<ll> fac; void c_fac(ll x=pow(10,7)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; } ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { ll d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; } ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; } ll modpow(ll x, ll p) { ll result = 1, now = 1, pm = x; while (now<=p) { if (p&now) { result = result * pm % MOD; } now*=2; pm = pm*pm % MOD; } return result; } ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); } ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } int main() { ll N, X; cin >> N >> X; ll V[N], P[N]; rep(i,N) cin >> V[i] >> P[i]; X *= 100; ll sum = 0; rep(i,N) { sum += V[i] * P[i]; if (sum>X) { cout << i+1 << endl; return 0; } } cout << -1 << endl; return 0; }
#include <bits/stdc++.h> typedef long long ll; using namespace std; const int N = 2e5 + 5, mod = 1e9 + 7; char s[N]; int a[N], k; int add (int a, int b) { return ((a += b) >= mod) ? (a - mod) : a; } int dp[N][20], K; int f (int l, int k) { if (~dp[l][k]) return dp[l][k]; if (l == 0) return k == K; dp[l][k] = (ll)k * f(l - 1, k) % mod; if (k) dp[l][k] = add(dp[l][k], (ll)f(l - 1, k + 1) * (16 - k) % mod); return dp[l][k]; } int main() { memset (dp, -1, sizeof (dp)); cin >> (s + 1) >> K; int len = strlen(s + 1); for (int i = 1; i <= len; ++i) { if (isdigit(s[i])) a[i] = s[i] - '0'; else a[i] = s[i] - 'A' + 10; } int ans = 0; for (int i = len; i >= 2; --i) { for (int j = 1; j < 16; ++j) ans += f (len - i, 1), ans %= mod; ans %= mod; } // cerr << ans << '\n'; int st = 0; for (int i = 1; i <= len; ++i) { for (int j = ((i == 1) ? 1 : 0); j < a[i]; ++j) { int newst = st | (1 << j), cnt = __builtin_popcount(newst); // cerr << len - i << " " << cnt << ":" << f(len - i, cnt) << '\n'; ans = add(ans, f(len - i, cnt)); } st |= (1 << a[i]); } if (__builtin_popcount(st) == K) ans = add(ans, 1); cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define pi pair<int,int> #define pb(x) push_back(x) #define ff first #define ss second #define all(x) x.begin(), x.end() #define dbg(x) cout << #x << ": " << x << "\n" #define dbg2(x, y) cout <<"{ " << #x <<", "<< #y<< " }"<< ": " <<"{ " << x <<", "<< y<< " }" << "\n" const int MAX_N = 1e5 + 1; const int MOD = 1e9 + 7; const int INF = 1e18; void dfs(int st, int i, vector<int> adj[], vector<bool>& vis, vector<vector<int>>& poss){ if(vis[i]) return; vis[i] = true; poss[st][i] = true; for(int j: adj[i]){ dfs(st, j, adj, vis, poss); } } void solve() { int n, m; cin >> n >> m; vector<int> adj[n]; vector<vector<int>> poss(n, vector<int>(n, 0)); for(int i = 0; i < m; i++){ int u, v; cin >> u >> v; u--; v--; adj[u].push_back(v); } for(int i = 0; i < n; i++){ vector<bool> vis(n, false); dfs(i, i, adj, vis, poss); } int ans = 0; for(auto x: poss){ for(auto y: x){ ans += y; } } cout << ans << "\n"; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tc = 1; // cin >> tc; for (int t = 1; t <= tc; t++) { solve(); } }
#include <bits/stdc++.h> #define INF 1e9 #define LINF (1LL << 63 - 1) #define rep(i,n)for(int i=0;(i)<(int)(n);i++) #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++) #define ALL(a) (a).begin(),(a).end() // #define chmax(a, b) a = max(a, b) // #define chmin(a, b) a = min(a, b) #define pb push_back #define fi first #define se second #define sz(x) ((int)x.size()) using namespace std; //using namespace atcoder; using ld = long double; using ll = long long; using P = pair<ll, ll>; template<typename T> bool chmin(T& a, const T& b) { if(a > b){ a = b; return 1;} return 0; } template<typename T> bool chmax(T& a, const T& b) { if(a < b){ a = b; return 1;} return 0; } const ll ZER = 0; const ll MOD = 1e9 + 7; int main(){ // std::cin.tie(0); // std::ios::sync_with_stdio(false); int h, w; cin >> h >> w; ll sum = 0, mi = INF * INF; vector<vector<ll>> s(h, vector<ll> (w)); rep(i, h)rep(j, w)cin >> s[i][j]; rep(i, h){ rep(j, w){ chmin(mi, s[i][j]); } } rep(i, h){ rep(j, w){ sum += s[i][j] - mi; } } cout << sum << endl; }
#include <iostream> #include <string> #include <vector> #include <algorithm> int main() { std::string str; std::cin >> str; std::vector<int> v, mod; int sum = 0; for (int i = 0; i < str.length(); ++i) { v.push_back(str[i] - '0'); sum += v[i]; if (v[i] % 3) mod.push_back(v[i] % 3); } std::sort(mod.begin(), mod.end()); int ans = -1; if (sum % 3 == 0) ans = 0; else if (!mod.empty()) { if (sum % 3 == 1) { if (mod[0] == 1) { ans = 1; } else if (mod.size() > 1 && mod[mod.size() - 2] == 2) { ans = 2; } } else { if (mod[mod.size() - 1] == 2) { ans = 1; } else if (mod.size() > 1) { ans = 2; } } } if (ans == str.length()) ans = -1; std::cout << ans << std::endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll, ll> p_ll; typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i) #define ture ture #define flase false #define falg flag #define REP(i, x) for (ll i = 0; i < (ll)(x); i++) #define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++) #define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--) #define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--) #define all(x) (x).begin(), (x).end() const ll MOD = pow(10, 9) + 7; const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18 const int INF = pow(2, 30) - 1; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } int main() { ios::sync_with_stdio(false); cin.tie(0); ll N; string S; cin >> S; vector<ll> A(S.size()); bool flag = false; ll ans = 10000000000000; REP(i,S.size()){ A.at(i) = S.at(i) - '0'; } ll b = A.size(); for (int bit = 0; bit <= (1 << S.size()); ++bit) { ll tmp = 0; ll tmp1 = 0; for (int i = 0; i < S.size(); ++i) { if (bit & (1 << i)) { // 列挙に i が含まれるか tmp += A.at(i); tmp1++; } } if (tmp % 3 == 0 && tmp > 0) { flag = true; ans = min(ans, b - tmp1); } //cout << bit << " " << b - tmp1 << endl; tmp = 0; tmp1 = 0; } if(flag){ cout << ans << endl; } else{ cout << -1 << endl; } }
/* How To Solve It 1st. Understanding The Problem 未知なもの、データ(与件), 条件 は何か? その条件は未知を決定するために十分か? 条件を分解せよ, 図を描け 2nd. Devising A Plan 類似、関連のある問題、典型問題を知らないか? 役立ちそうな定理やアルゴリズムを知らないか? 問題の一部を解決できるか、一部だけ残して他を切り捨ててみろ 既知のものやデータを変えることはできるか? 3rd. Carrying Out The Plan 各ステップで誤りがないか、正しいと説明できるか? 4th. Looking Back 別解、他の問題に使えそうなものはあるか? */ /*{{{ #include */ #include <iostream> #include <cstdio> #include <string> #include <vector> #include <set> #include <queue> #include <stack> #include <map> #include <tuple> #include <algorithm> #include <utility> #include <cmath>/*}}}*/ /*{{{ namespace R2357 */ namespace R2357 { inline void IN(void){return;} template<class F,class... R>inline void IN(F& f,R&... r){std::cin>>f;IN(r...);} template <class T>inline void OUT(T x){std::cout<<x<<'\n';} template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;} template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;} template<class T=int>T read(){ T x=0; char c; while(((c=getchar())>'9'||c<'0')&&c!='-'); const bool f=(c=='-')&&(c=getchar()); while(x=x*10-48+c,(c=getchar())>='0'&&c<='9'); return f?-x:x; } template<class T>std::istream& operator>>(std::istream& is,std::vector<T>& V){ for(auto& v:V)is>>v; return is; } template<class T1,class T2> std::istream& operator>>(std::istream& is,std::pair<T1,T2>& P){ return is>>P.first>>P.second; } template<class T>inline T ceil_div(T a,T b){ return (a+(b-1))/b; } namespace debug { using namespace std; void Write(void){cerr<<endl;} template<class F,class...R>void Write(F f,R...r){cerr<<' '<<f;Write(r...);} template<class T>void Write(vector<T>& V,int n=-1){ if(n==-1) n = V.size(); for(int i=0;i<n;i++)cerr<<' '<<V[i]; cerr<<endl; } template<class T,class U> void Write(pair<T,U>& p){cerr<<' '<<'{'<<p.first<<','<<p.second<<'}'<<endl;} #include <cxxabi.h> template<class T>string TypeName(T& x){ return string(abi::__cxa_demangle(typeid(T).name(), 0, 0, 0)); } } }/*}}}*/ /*{{{ using */ using namespace std; using namespace R2357; using ll=long long; using ld=long double; using pint=pair<int,int>;/*}}}*/ /*{{{ #define */ #define rep(i,a,b) for(ll i=a;i<ll(b);i++) #define repr(i,a,b) for(ll i=a;i>=ll(b);i--) #define each(x,v) for(auto& x:v) #define el '\n' #define ALL(x) x.begin(),x.end() #define ALLR(x) x.rbegin(),x.rend() #define Unique(x) sort(x.begin(),x.end());x.erase(unique(x.begin(),x.end()),x.end()) #define Fill(v,n) fill(v,v+sizeof(v)/sizeof(*v),n) #define max_element(x) *max_element(x.begin(),x.end()) #define min_element(x) *min_element(x.begin(),x.end()) #define INF 1073741824 // 2e30 #define INFL 2305843009213693952ll // 2e61 #define _FASTIO_ ios::sync_with_stdio(false),cin.tie(nullptr); /*}}}*/ /* NOTE 0. */ // using namespace debug; int main(){ _FASTIO_ int a, b; IN(a, b); if(abs(a-b) < 3) OUT("Yes"); else OUT("No"); return 0; }
#include <bits/stdc++.h> #define fi first #define se second #define o2(x) (x) * (x) #define mk make_pair #define eb emplace_back #define SZ(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define clr(a, b) memset((a), (b), sizeof((a))) #define rep(i,s,t) for(register int i=s;i<t;++i) #define per(i,s,t) for(register int i=s;i>=t;--i) #define GKD std::ios::sync_with_stdio(false);cin.tie(0) #define my_unique(x) sort(all(x)), x.erase(unique(all(x)), x.end()) using namespace std; typedef long long LL; typedef long long int64; typedef unsigned long long uint64; typedef pair<int, int> pii; // mt19937 rng(time(NULL)); // mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count()); // mt19937_64 generator(std::clock()); // shuffle(arr, arr + n, generator); inline int64 read() { int64 x = 0;int f = 0;char ch = getchar(); while (ch < '0' || ch > '9') f |= (ch == '-'), ch = getchar(); while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar(); return x = f ? -x : x; } inline void write(int64 x, bool f = true) { if (x == 0) {putchar('0'); if(f)putchar('\n');else putchar(' ');return;} if (x < 0) {putchar('-');x = -x;} static char s[23]; int l = 0; while (x != 0)s[l++] = x % 10 + 48, x /= 10; while (l)putchar(s[--l]); if(f)putchar('\n');else putchar(' '); } int lowbit(int x) { return x & (-x); } template <class T> T big(const T &a1, const T &a2) {return a1 > a2 ? a1 : a2;} template <class T> T sml(const T &a1, const T &a2) {return a1 < a2 ? a1 : a2;} template <typename T, typename... R> T big(const T &f, const R &... r) {return big(f, big(r...));} template <typename T, typename... R> T sml(const T &f, const R &... r) {return sml(f, sml(r...));} void debug_out() { cout << '\n'; } template <typename T, typename... R> void debug_out(const T &f, const R &... r) { cout << f << " "; debug_out(r...); } #ifdef LH_LOCAL #define debug(...) cout << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__); #else #define debug(...) ; #endif /*================Header Template==============*/ const int INF = 0x3f3f3f3f; const int mod = 998244353;// 998244353 const int MXN = 1500 + 5; const int MXE = 2e6 + 5; int n, m, h, w; int mp[MXN][MXN]; vector<pii> col[MXN], row[MXN]; int main() { #ifdef LH_LOCAL freopen("D:in.txt", "r", stdin); //freopen("D:out.txt", "w", stdout); #endif n = read(), m = read(), h = read(), w = read(); rep(i, 0, h) { int x = read(), y = read(); row[x].eb(mk(y, 1)); col[y].eb(mk(x, 1)); mp[x][y] = 1; } rep(i, 0, w) { int x = read(), y = read(); row[x].eb(mk(y, -1)); col[y].eb(mk(x, -1)); mp[x][y] = -1; } rep(i, 1, n + 1) sort(all(row[i])); rep(j, 1, m + 1) sort(all(col[j])); int ans = 0; rep(i, 1, n + 1) { rep(j, 1, m + 1) { if(mp[i][j] == 1) ++ ans; if(mp[i][j]) continue; int flag = 0; ans += flag; pii tmp = mk(j, 0); int p = lower_bound(all(row[i]), tmp) - row[i].begin(); if(p < (int)row[i].size() && row[i][p].se == 1) flag = 1; -- p; if(p >= 0 && p < (int)row[i].size() && row[i][p].se == 1) flag = 1; tmp = mk(i, 0); p = lower_bound(all(col[j]), tmp) - col[j].begin(); if(p < (int)col[j].size() && col[j][p].se == 1) flag = 1; -- p; if(p >= 0 && p < (int)col[j].size() && col[j][p].se == 1) flag = 1; ans += flag; } } printf("%d\n", ans); #ifdef LH_LOCAL cout << "time cost:" << 1.0 * clock() / CLOCKS_PER_SEC << "s" << endl; // system("pause"); #endif return 0; }
#include <bits/stdc++.h> #include <string> #include <cmath> using namespace std; #define ll long long int #define pb push_back #define Messi ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define pii pair<pair<ll,ll>, ll> #define mod 1000000007 #define vi vector<ll> #define vii vector<pii> #define all(v) v.begin(),v.end() #define mi map<ll, ll> //Never Let U Go!! int main() { Messi; ll n; cin>>n; vector<pii>v; for(ll i=0;i<n;i++) { ll a,b,c; cin>>a>>b>>c; v.pb({{a,c},b}); } ll ans=LONG_MAX; for(auto g:v) { ll t= g.first.first; if(t<g.first.second) ans=min(ans,g.second); } if(ans==LONG_MAX) cout<<"-1"; else cout<<ans; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; vector<string> s(n); set<string> st; for(int i=0;i<n;i++){ cin >> s[i]; st.insert(s[i]); } for(int i=0;i<n;i++){ if(s[i][0]!='!'){ if(st.count('!'+s[i])>=1){ cout << s[i] << endl; return 0; } } } cout << "satisfiable" << endl; }
#include <bits/stdc++.h> using namespace std; #define FASTIO cin.tie(0);ios::sync_with_stdio(0) int main() { FASTIO; string n; cin >> n; map<char, int> ava; for (int i = 0; i < n.size(); i++) { ava[n[i]]++; } if (n.size() >= 3) { for (int i = 104; i < 1000; i+=8) { string mystring = to_string(i); int c = 0; map<char, int> need; for (char i : mystring) { need[i]++; } for (auto pair : need) { if (ava[pair.first] >= pair.second) { c += pair.second; } } if (c == 3) { cout << "Yes" << "\n"; return 0; } } cout << "No" << "\n"; } else if (n.size() == 2) { for (int i = 16; i < 100; i+=8) { string mystring = to_string(i); int c = 0; map<char, int> need; for (char i : mystring) { need[i]++; } for (auto pair : need) { if (ava[pair.first] >= pair.second) { c += pair.second; } } if (c == 2) { cout << "Yes" << "\n"; return 0; } } cout << "No" << "\n"; } else { if (ava['8'] == 1) { cout << "Yes" << "\n"; return 0; } else { cout << "No" << "\n"; return 0; } } }
#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(){ ios::sync_with_stdio(false); cin.tie(nullptr); string s; cin >> s; vector<int> cnt(10); int n = s.size(); if(n == 1){ if(s == "8") cout << "Yes" << endl; else cout << "No" << endl; return 0; } if(n == 2){ int num = (s[0]-'0')*10 + s[1]; if(num % 8 == 0){ cout << "Yes" << endl; return 0; } num = (s[1]-'0')*10 + s[0]; if(num % 8 == 0){ cout << "Yes" << endl; return 0; } cout << "No" << endl; return 0; } rep(i,n){ cnt[s[i]-'0']++; } rep(i,10){ rep(j,10){ rep(k,10){ if(!i || !j || !k) continue; vector<int> c = cnt; c[i]--, c[j]--, c[k]--; bool flag = false; rep(l,10){ if(c[l] < 0)flag = true; } if(flag) continue; int num = i*100 + j*10 + k; if(num % 8 == 0){ cout << "Yes" << endl; return 0; } } } } cout << "No" << endl; }
#include <iostream> #include <vector> using namespace std; int main() { int n; cin >> n; vector<int> v(n); for(auto& nx : v) { cin >> nx; } bool b = 0; for(int i = 0; i < n; ++i) { for(int j = i + 1; j < n; ++j) { if(v[i] == v[j]) { cout << "No" << endl; b = 1; break; } } if(b == 1) break; } if(b == 0) { cout << "Yes" << endl; } return 0; }
// #include <atcoder/all> #include <bits/stdc++.h> #ifndef M_PI #define M_PI 3.14159265358979 #endif #define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI) #define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360) #define rep2(i, m, n) for(long long i = (m); i < (n); ++i) #define rep(i, n) rep2(i, 0, n) #define drep2(i, m, n) for(long long i = (m)-1; i >= (n); --i) #define drep(i, n) drep2(i, n, 0) #define all(x) (x).begin(), (x).end() using namespace std; // using namespace atcoder; typedef long long ll; typedef vector<ll> vll; typedef vector<int> vi; typedef pair<ll, ll> pll; typedef pair<int, int> pi; typedef long double ld; typedef pair<long double, long double> pld; 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; } const ll INF = 1e18; const ll MOD = 1e9 + 7; // const ll MOD = 998244353; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll N; cin >> N; vll A(N); for(auto &e : A) cin >> e; vll P(N, 0); rep(i, N) { ll a = --A[i]; P[a]++; } ll ok = 1; rep(i, N) { if(P[i] != 1) ok = 0; } if(ok == 1) { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < int(n); i++) using namespace std; using ll = long long; const int INF = (1<<30)-1; const long long LINF = (1LL<<62)-1; const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, 1, 0, -1}; 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; } signed main() { ios::sync_with_stdio(false); cin.tie(0); string s; cin >> s; map<int, int> mp; rep(i, s.size()) mp[s[i]-'0']++; rep(i, 1000) { if (i%8) continue; vector<int> num(10); int tmp = i; rep(_, min(3, (int)s.size())) { num[tmp%10]++; tmp /= 10; } bool flag = true; rep(i, 10) { if (mp[i] < num[i]) flag = false; } if (flag) { cout << "Yes\n"; return 0; } } cout << "No\n"; return 0; }
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <queue> #include <map> #include <unordered_map> using namespace std; #define debug(x) cout << #x << '=' << x << '\n' #define rep(i, b, e) for (int i = b; i <= e; i++) const int N = 212345; int n, a[N], b[N], c[N]; unordered_map<int, queue<int>> mp; struct BIT { int c[N], size; inline int lowbit(const int &x) { return x & (-x); } inline void add(int loc, const int &val) { for (; loc <= size; loc += lowbit(loc)) { c[loc] += val; } } inline int query(int loc) { int ret = 0; for (; loc; loc -= lowbit(loc)) { ret += c[loc]; } return ret; } } Bit; int main(){ cin >> n; rep (i, 1, n) { scanf("%d", a + i); a[i] += i; mp[a[i]].push(i); } rep (i, 1, n) { scanf("%d", b + i); b[i] += i; if (mp[b[i]].size() == 0) { puts("-1"); return 0; } c[i] = mp[b[i]].front(); mp[b[i]].pop(); } //rep (i, 1, n) { // debug(c[i]); //} Bit.size = n; long long ans = 0; for (int i = n; i > 0; i--) { ans += Bit.query(c[i] - 1); Bit.add(c[i], 1); } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define fast_io cin.tie(0);ios_base::sync_with_stdio(0); string to_string(string s) { return '"' + s + '"';} string to_string(char s) { return string(1, s);} string to_string(const char* s) { return to_string((string) s);} string to_string(bool b) { return (b ? "true" : "false");} template <typename A> string to_string(A); template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";} template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";} void debug_out() { cout << endl; } void show() { cout << endl; } void pret() { cout << endl; exit(0);} template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cout << " " << to_string(H); debug_out(T...);} template <typename Head, typename... Tail> void show(Head H, Tail... T) {cout <<H<<" "; show(T...);} template <typename Head, typename... Tail> void pret(Head H, Tail... T) {cout <<H<<" "; pret(T...);} #define pr(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) typedef long long ll; // #define int ll typedef long double ld; typedef vector<int> vi; #define disp(x) cout<<x<<" "; #define rep(i,a,b) for(int i=a;i<(int)b;i++) #define fo(i,a,b) for(int i=a;i<=(int)b;i++) #define rf(i,a,b) for(int i=a;i>=(int)b;i--) #define mp make_pair #define pb emplace_back #define F first #define S second #define endl '\n' //cout.setf(ios::fixed);cout.precision(18) const int MOD = 998244353; const int maxn = 2e5+10; ll factorial[maxn], inverse[maxn]; ll power(ll a, ll b){ ll x = 1, y = a; while (b > 0){ if (b%2){ x = (x*y)%MOD; } y = (y*y)%MOD; b /= 2; } return x%MOD; } ll modular_inverse(ll n){ return power(n, MOD-2); } ll nCr(ll n, ll k){ if(n < k) return 0; ll flag= ((factorial[n])*(modular_inverse(factorial[k])))%MOD; return (flag*modular_inverse(factorial[n-k]))%MOD; } void add(int &a, int b){ a += b; if(a >= MOD) a -= MOD; if(a < 0) a += MOD; } const int lognum = 19; int dp[maxn][lognum]; int f(){ int n, m; cin >> n >> m; fo(i, 1, m) dp[i][1] = 1; int ans = m; fo(j, 2, lognum - 1){ if(j > n) break; // vector < bool > visited(m + 1, 0); int curr = 0; fo(i, 1, m){ if(dp[i][j - 1] == 0) continue; for(int k = i + i; k <= m; k += i){ add(dp[k][j], dp[i][j - 1]); } } fo(i, 2, m){ add(curr, dp[i][j]); } // show(j, curr, nCr(n - 1, j - 1)); add(ans, (ll(curr) * nCr(n - 1, j - 1)) % MOD); } return ans; } int32_t main(){ fast_io; int t = 1; factorial[0] = 1; // inverse[0] = 1; fo(i, 1, maxn - 1){ factorial[i] = (factorial[i - 1] * i) % MOD; // inverse[i] = modular_inverse(factorial[i]); } // cin>>t; while(t--){ show(f()); // f(); // if(f()){ // cout<<"YES"<<endl; // } // else cout<<"NO"<<endl; } return 0; }
#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; #ifdef ENABLE_DEBUG #define dump(a) cerr<<#a<<"="<<a<<endl #define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl #else #define dump(a) #define dumparr(a,n) #endif #define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++) #define For(i, a) FOR(i, 0, a) #define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--) #define Rev(i, a) REV(i, 0, a) #define REP(a) For(i, a) #define SIGN(a) (a==0?0:(a>0?1:-1)) typedef long long int ll; typedef unsigned long long ull; typedef unsigned int uint; typedef pair<ll, ll> pll; typedef pair<ll,pll> ppll; typedef vector<ll> vll; typedef long double ld; typedef pair<ld,ld> pdd; pll operator+(pll a,pll b){ return pll(a.first+b.first,a.second+b.second); } pll operator-(pll a,pll b){ return pll(a.first-b.first,a.second-b.second); } pll operator*(ll a,pll b){ return pll(b.first*a,b.second*a); } const ll INF=(1LL<<60); #if __cplusplus<201700L ll gcd(ll a, ll b) { a=abs(a); b=abs(b); if(a==0)return b; if(b==0)return a; if(a < b) return gcd(b, a); ll r; while ((r=a%b)) { a = b; b = r; } return b; } #endif 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(a>b){ a=b; return true; } return false; } template<class S,class T> std::ostream& operator<<(std::ostream& os,pair<S,T> a){ os << "(" << a.first << "," << a.second << ")"; return os; } template<class T> std::ostream& operator<<(std::ostream& os,vector<T> a){ os << "[ "; REP(a.size()){ os<< a[i] << " "; } os<< " ]"; return os; } const long long MOD = 998244353; const long long max_cache=1000000; long long cache_fact[max_cache],cache_inv_fact[max_cache]; long long combination_cached(long long n,long long r){ ll m=MOD; static bool cached=false; if(cached==false){ cached=true; cache_inv_fact[1]=1; for (long long i = 2; i < max_cache; i++) { cache_inv_fact[i]=(m-m/i)*cache_inv_fact[m%i]%m; } for (long long i = 2; i < max_cache; i++){ cache_inv_fact[i]=cache_inv_fact[i]*cache_inv_fact[i-1]%m; } cache_fact[0]=1; for (long long i = 1; i < max_cache; i++) { cache_fact[i]=cache_fact[i-1]*i%m; } } if(r<0||r>n)return 0; if(r==0||r==n)return 1; if(n>m){ std::cerr<<"Combination Error: n is greater than m"<<std::endl; exit(1); } r=min(r,n-r); return cache_fact[n]*cache_inv_fact[r]%m*cache_inv_fact[n-r]%m; } long long homogeneous(long long n,long long r){ return combination_cached(n+r-1,r); } void solve(long long N, long long M){ if(N==1){ cout<<M<<endl; return; } vector<ll> primes{2}; for (ll i = 3; i*i <= M; i+=2) { bool f=true; for (auto &&j : primes) { if(i%j==0){ f=false; break; } } if(f){ primes.push_back(i); } } ll ans=0; FOR(i,1,M+1){ ll cur=i; vector<ll> cnts; for (auto &&p : primes) { ll cnt=0; while(cur%p==0){ ++cnt; cur/=p; } if(cnt>0){ cnts.push_back(cnt); } } if(cur>1){ cnts.push_back(1); } ll curans=1; for (auto &&j : cnts) { curans*=homogeneous(N,j); curans%=MOD; } dump(i); dump(curans); ans=(ans+curans)%MOD; } cout<<ans<<endl; return; } int main(){ cout<<setprecision(1000); long long N; scanf("%lld",&N); long long M; scanf("%lld",&M); solve(N, M); return 0; }
//#pragma GCC optimize ("O3","unroll-loops") #include<iostream> #include<iomanip> #include<cstdio> #include<cstdlib> #include<cassert> #include<cmath> #include<functional> #include<algorithm> #include<numeric> #include<vector> #include<string> #include<queue> #include<stack> #include<deque> #include<set> #include<map> #include<bitset> #include<tuple> #define TEST {IS_TEST=true;} #define fi first #define se second #define pb(x) emplace_back(x) #define pf(x) emplace_front(x) #define emp(x) emplace(x) #define mp(x,y) make_pair(x,y) using namespace std; using ll = int_fast64_t; using v_b = vector <bool>; using v_ll = vector <ll>; using str = string; using v_str = vector <string>; using p_ll = pair < ll,ll >; using vv_b = vector < v_b >; using vv_ll = vector < v_ll >; using vp_ll = vector < p_ll >; using vvv_ll = vector < vv_ll >; using vvp_ll = vector < vp_ll >; using ld = long double; using v_ld = vector <ld>; using vv_ld = vector<v_ld>; bool IS_TEST=false; ll ll_min64=1LL<<63; ll ll_max64=~ll_min64; ll ll_min32=1LL<<31; ll ll_max32=~ll_min32; /*displaying functions for debug*/ template<class T> void show2(const T &x){cerr << x;} template<class T1,class T2> void show2(const pair<T1,T2> &x){ cerr << "{" << show2(x.first) << "," << show2(x.second) << "}"; } template<class T> void show(const T &x){ if (!IS_TEST) return; show2(x); cerr << "\n"; } template<class T> void v_show(const T &v, ll n=-1){ if (!IS_TEST) return; auto itr=v.begin(); ll m=n; while(itr!=v.end() && m!=0 ){ show2(*itr); cerr << " "; itr++; m--;} cerr << "\n"; } template<class T> void vv_show(const T &v, ll n=-1){ if (!IS_TEST) return; cerr << "--------------------------------\n"; auto itr=v.begin(); ll m=n; while(itr!=v.end() && m!=0 ){ v_show(*itr,n); itr++; m--;} cerr << "--------------------------------\n"; } ll max(ll x,ll y){return x>y?x:y;} ll min(ll x,ll y){return x<y?x:y;} template<class T> bool chmax(T& x,const T& y){ if (x>=y) return false; x=y; return true;} template<class T> bool chmin(T& x,const T& y){ if (x<=y) return false; x=y; return true;} template<class T> void quit(T x){cout << x << endl; exit(0);} ll roundup(ll x,ll y){return (x-1)/y+1;} ll remain(ll x,ll y){ ll z=x%y; return z>=0?z:z+y; } v_ll idx_vector(ll n){ v_ll ret(n,0); for(ll i=0;i<n;i++) ret[i]=i; return ret; } //setprecision(12) //sort(##.begin(),##.end(),[&](auto &x, auto &y){if (x<y) return true;}); //ll ok=0,ng=0; while(abs(ok-ng)>1){ll mid=(ok+ng)/2; ( func(mid) ?ok:ng)=mid;} // struct dat{ // dat(){} // bool operator < (const dat& rhs)const {return false; } // }; string el = "\n"; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); ll A,B; cin >> A>> B; if (A>=B){ ll sum = 0; for(ll i=0;i<A;i++){ cout << (i+1) << " "; sum+=(i+1); } for(ll i=0;i<B-1;i++){ cout << (-i-1) << " "; sum-=(i+1); } cout << (-sum) << "\n"; }else{ ll sum = 0; for(ll i=0;i<A-1;i++){ cout << (i+1) << " "; sum+=(i+1); } for(ll i=0;i<B;i++){ cout << (-i-1) << " "; sum-=(i+1); } cout << (-sum) << "\n"; } }
#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) #define fi first #define se second using namespace std; using ll = long long; using ui = unsigned int; using ul = unsigned long long; using ld = long double; using v1i = vector<int>; using v1ll = vector<ll>; using v2i = vector<vector<int>>; using v2ll = vector<vector<ll>>; using v3i = vector<vector<vector<int>>>; using v3ll = vector<vector<vector<ll>>>; using v1b = vector<bool>; using v2b = vector<vector<bool>>; using v3b = vector<vector<vector<bool>>>; using v1c = vector<char>; using v2c = vector<vector<char>>; using v3c = vector<vector<vector<char>>>; constexpr ll MOD = 1000000007; constexpr ll MOD2 = 998244353; int main(){ int n, k, m, ng = -1, ok = 1000000000; cin >> n >> k; m = k * k / 2; v2i v(n, v1i(n)); v2i dp(n+1, v1i(n+1, 0)); rep(i, n) rep(j, n) cin >> v[i][j]; while(ok-ng > 1) { rep(i, n+1) dp[i].resize(n+1, 0); int c = (ng + ok) / 2; rep(i, n) { rep(j, n) { dp[i+1][j+1] = dp[i+1][j] + dp[i][j+1] - dp[i][j]; if(v[i][j] > c) ++dp[i+1][j+1]; } } bool b = 0; rep(i, n-k+1) rep(j, n-k+1) if(dp[k+i][k+j] + dp[i][j] - dp[k+i][j] - dp[i][k+j] <= m) b = 1; if(b) ok = c; else ng = c; } cout << ok << "\n"; return 0; }
#include<iostream> using namespace std; #define ll long long ll pos(int a){ ll sum=1; for(int i=1;i<=a;i++){ sum*=10; } return sum; } ll pp(int n){ ll sum=0; for(int i=1;i<=n;i++){ sum=sum*10+9; } return sum; } int main() { ll n; cin>>n; ll temp=n; int digit=0; while(temp){ temp/=10; digit++; } if(digit%2==0){ digit/=2; ll num=pos(digit); ll t1=n%num;//hou ll t2=n/num;//qian if(t2>t1) cout<<t2-1; else cout<<t2; return 0; } else{ digit=digit/2; ll num=pp(digit); cout<<num<<endl; } return 0; }
#include <iostream> #include <vector> #include <cstdlib> #include <algorithm> #include <string> using namespace std; int main() { string s; cin >> s; int nn = s.length(); int i2 = 9; int i4 = 90; int i6 = 900; int i8 = 9000; int i10 = 90000; if(nn <= 1){ cout<<0; return 0; } else if(nn <= 2){ long long a = stoll(s.substr(0,1)); long long b = stoll(s.substr(1,1)); if(b >= a) cout<<a; else cout<<a-1; } else if(nn <= 3){cout<<i2;} else if (nn<=4){ long long a = stoll(s.substr(0,2)); long long b = stoll(s.substr(2,2)); if(b >= a) cout<<a-10+1+i2; else cout<<a-10+i2; } else if(nn <=5){ cout<<i2+i4; } else if(nn <=6){ long long a = stoll(s.substr(0,3)); long long b = stoll(s.substr(3,3)); if(b >= a) cout<<a-100+1+i2+i4; else cout<<a-100+i2+i4; } else if(nn <= 7){ cout<<i2+i4+i6; } else if(nn <= 8){ long long a = stoll(s.substr(0,4)); long long b = stoll(s.substr(4,4)); if(b >= a) cout<<a-1000+1+i2+i4+i6; else cout<<a-1000+i2+i4+i6; } else if(nn <= 9){ cout<<i2+i4+i6+i8; } else if(nn <= 10){ long long a = stoll(s.substr(0,5)); long long b = stoll(s.substr(5,5)); if(b >= a) cout<<a-10000+1+i2+i4+i6+i8; else cout<<a-10000+i2+i4+i6+i8; } else if(nn <= 11){ cout<<i2+i4+i6+i8+i10; } else if(nn <= 12){ long long a = stoll(s.substr(0,6)); long long b = stoll(s.substr(6,6)); if(b >= a) cout<<a-100000+1+i2+i4+i6+i8+i10; else cout<<a-100000+i2+i4+i6+i8+i10; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define _GLIBCXX_DEBUG #define rep(i, n) for (ll i = 0; i < (n); ++i) #define rep1(i, c, n) for (ll i = c; i < (n); ++i) //以下debug用 #define d(x) cout << #x << "; " << x << endl; #define p(x) cout << x << endl; #define f(x) for (long unsigned int i = 0; i < x.size(); i++) cout << #x << "[" << i << "]; " << x[i] << endl; bool ok = false; vector<pair<ll,ll>> p; const int inf = 1001001001; const ll INF = 1LL << 60; //無限大 ll ans=0,num=0,counter=0; string s; int main(){ int N; cin >> N; vector<ll> v(N); rep(i,N) cin >> v[i]; set<int> b; for (int i = 0; i < N; ++i) b.insert(v[i]); if (b.size() == N){ p("Yes") }else{ p("No") } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = int64_t; using Vll =vector<ll>; using VVll =vector<vector<ll>>; template <class T> using Vec = vector<T>; template <class T> using VVec = vector<vector<T>>; #define INF 9223372036854775807LL/2 void Z(ll i=-1){ if(i==-1)cout<<"Test"<<endl; else cout<<"Test"<<i<<endl; } template <class T> void VVcout(VVec<T> A){ for(auto Vi:A) { for(auto i:Vi)cout<<i<<' '; cout<<endl;}} template <class T> void Vcout(Vec<T> A){ for(auto i:A) cout<<i<<' '; cout<<endl;} template <class T> void chmax(T &x,T y){if(x<y) x=y;} template <class T> void chmin(T &x,T y){if(x==-1 || x>y) x=y;} #define rep(i,n) for(ll i=0;i<n;i++) #define reps(si, i,n) for(ll i=si;i<n;i++) int main(){ ll n,a; cin>>n; Vll B(n,0); rep(i,n){ cin>>a; B.at(a-1)++; } bool ans=true; rep(i,n) if(B.at(i)!=1) ans=false; if(ans) cout<<"Yes"<<endl; else cout<<"No"<<endl; }
/*........................... .........tank.jpg............ ...........................*/ //PointBlank's code (⌐■_■) #include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; template<typename T> using pxx = pair<T, T>; ll power(ll x, ll y); #define repp(I, A, B) for(int I = A; I <= B; I++) #define rep(I, A, B) for(int I = A; I < B; I++) #define rrep(I, B, A) for(int I = B; I >= A; I--) #define pb emplace_back #define ff first #define ss second #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() #define LB lower_bound #define UB upper_bound #define MP make_pair #define quickio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define debug(this) cerr<<"> "<<#this<<" : "<<this<<"\n" #define bitcount(n) __builtin_popcountll(n) #define in_edges(M) repp(I, 1, M){int A, B; cin >> A >> B; v[A].pb(B), v[B].pb(A);} #define in_dedges(M) repp(I, 1, M){int A, B; cin >> A >> B; v[A].pb(B);} #define in_wedges(M) repp(I, 1, M){int A, B, C; cin >> A >> B >> C; v[A].pb(B, C), v[B].pb(A, C);} #define in_dwedges(M) repp(I, 1, M){int A, B, C; cin >> A >> B >> C; v[A].pb(B, C);} #define endl "\n" const ll sp1 = 1e12 + 39; const ll sp2 = 1e15 + 1e5 + 11; const ll INF = 1e18 + 18; const ll MOD = 1e9 + 7; const int inf = 2e9 + 9; const size_t N = 1e6 + 6; int main() //PointBlank's code ¯\_(ツ)_/¯ { quickio ull n; cin >> n; ull a = 3, b = 5; ull x = 1, y = 1; while(a < INF){ b = 5, y = 1; while(b < INF){ if(a + b == n){ cout << x << " " << y; exit(0); } if(b * 5 < b) break; b *= 5, y++; } if(a * 3 < a) break; a *= 3, x++; } cout << -1; } ll power(ll x, ll y){ ll res = 1; x %= MOD; while(y > 0){if(y & 1) res = (res*x) % MOD; y = y>>1, x = (x*x) % MOD;} return res; }
#include<bits/stdc++.h> using namespace std; template<typename T>inline T read(){ T f=0,x=0;char c=getchar(); while(!isdigit(c)) f=c=='-',c=getchar(); while(isdigit(c)) x=x*10+c-48,c=getchar(); return f?-x:x; } #define int long long namespace run{ const int N=4e5+9; int head[N],nex[N],to[N],cnt; inline void add(int u,int v){ nex[++cnt]=head[u]; head[u]=cnt,to[cnt]=v; } int n,m,a[N],b[N],vis[N],tota,totb; inline void dfs(int u){ vis[u]=1,tota+=a[u],totb+=b[u]; for(int i=head[u];i;i=nex[i]) if(!vis[to[i]]) dfs(to[i]); } int main(){ n=read<int>(),m=read<int>(); for(int i=1;i<=n;i++) a[i]=read<int>(); for(int i=1;i<=n;i++) b[i]=read<int>(); for(int i=1;i<=m;i++){ int u=read<int>(),v=read<int>(); add(u,v),add(v,u); } for(int i=1;i<=n;i++) if(!vis[i]){ tota=totb=0,dfs(i); if(tota!=totb) puts("No"),exit(0); } puts("Yes"); return 0; } } #undef int int main(){ #ifdef my freopen(".in","r",stdin); freopen(".out","w",stdout); #endif return run::main(); }
#include <bits/stdc++.h> using namespace std; #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define endl "\n" #define int long long // const int md = 998244353; const int sz = 1e5+1; int A[sz+1]; int B[sz+1]; // int C[sz+1]; vector<int> primes; void sieve(){ primes.clear(); for (int i = 0; i <= sz; ++i) { A[i] = 1; } for (int i = 2; i <= sz; ++i) { if(A[i]){ for (int j = i*i; j <= sz ; j += i) { A[j] = 0; } } } for (int i = 2; i <= sz; ++i) { if(A[i]) primes.push_back(i); } } void solve(){ int a,b;cin>>b>>a; b = 2*(b) + 100; cout<<b-a<<endl; return; } int32_t main() { IOS; // sieve(); // int t;cin >> t; // while (t--) solve(); return 0; }
/**In the name of Allah, the Most Merciful, the Most Merciful.**/ #pragma GCC diagnostic ignored "-Wunused-variable" #pragma GCC diagnostic ignored "-Wunused-parameter" #pragma GCC diagnostic ignored "-Wunused-but-set-variable" #pragma GCC diagnostic ignored "-Wformat" #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; typedef long long ll; typedef unsigned long long ull; #define INF 9223372036854775806 #define pb push_back #define mp make_pair #define MOD 1000000007 #define PI 2*acos(0.0) #define EPS 1e-9 #define base 313 #define base1 431 #define MOD1 999987337 #define maxm 200005 #define maxn 200005 template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; //order_of_key,find_by_order ll max(ll a,ll b) {if(a>b) return a; else return b;} ll min(ll a,ll b) {if(a<b) return a; else return b;} void FastIO(){ ios_base :: sync_with_stdio (false); cin.tie(0); cout.precision(20); } int main() { //what the hell are youing? Think again before coding. FastIO(); int a,b; cin>>a>>b; ll sum=0; for(int i=1;i<=a;i++){ for(int j=1;j<=b;j++){ sum=sum+(i*100+j); } } cout<<sum<<endl; return 0; //you should actually read the stuff at the bottom } /* stuff you should look for * int overflow, array bounds * special cases (n=1?) * do smooth instead of nothing and stay organized * don't get stuck on one approach, try another * don't waste time in one problem, try another * check PI value acos(-1.0) */
#include <bits/stdc++.h> #define inc(i, j, k) for (int i = j; i < k; i++) using namespace std; int f[17][1 << 17], n, g[17][17], x[17], y[17], z[17]; int dp(int i, int s) { if (f[i][s] != -1) return f[i][s]; f[i][s] = 0x3fffffff; inc(j, 0, n) if ((s & (1 << j)) == 0) f[i][s] = min(f[i][s], dp(j, s | (1 << j)) + g[i][j]); return f[i][s]; } int main() { scanf("%d", &n); inc(i, 0, n) scanf("%d%d%d", &x[i], &y[i], &z[i]); inc(i, 0, n) inc(j, 0, n) g[i][j] = abs(x[j] - x[i]) + abs(y[j] - y[i]) + max(0, z[j] - z[i]); inc(i, 1, n) inc(j, 0, 1 << n) f[i][j] = -1; f[0][0] = -1; f[0][(1 << n) - 1] = 0; inc(i, 1, (1 << n) - 1) f[0][i] = 0x3fffffff; printf("%d", dp(0, 0)); return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i) #define all(x) (x).begin(),(x).end() using ll = long long; using P = pair<ll, ll>; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, -1, 0, 1}; string char_to_string(char val) { return string(1, val); } int char_to_int(char val) { return val - '0'; } char inverse_char(char c) { if(isupper(c)) return tolower(c); else return toupper(c); } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } struct edge { ll to, cost; }; int main() { ll H, W, X, Y; cin >> H >> W >> X >> Y; X--; Y--; vector<string> S(H); REP(i, H) cin >> S[i]; ll ans = 0; for(int i = X; i < H; ++i) { if(S[i][Y] == '#') break; ans++; } for(int i = X; i >= 0; --i) { if(S[i][Y] == '#') break; ans++; } for(int i = Y; i < W; ++i) { if(S[X][i] == '#') break; ans++; } for(int i = Y; i >= 0; --i) { if(S[X][i] == '#') break; ans++; } cout << ans - 3 << endl; }
#include <bits/stdc++.h> #define pb push_back #define mp make_pair #define sz(a) a.size() #define re return #define all(a) a.begin(),a.end() #define int long long #define Type int #define rept(i,a,b) for(int i=(a);i<(b);i++) #define rep(i,a) rept(i,0,a) using namespace std; int n,t; int a[44]; vector<int>v1,v2; signed main() { cin>>n>>t; rep(i,n) cin>>a[i]; int mid=n/2; rep(i,1<<mid){ int tt=0; rep(j,mid) if (i>>j&1) tt+=a[j]; if (tt<=t) v1.pb(tt); } rep(i,1<<(n-mid)){ int tt=0; rep(j,n-mid) if (i>>j&1) tt+=a[j+mid]; if (tt<=t) v2.pb(tt); } sort(all(v2)); v2.pb(t+1); int ans=0; rep(i,sz(v1)){ int j=upper_bound(all(v2),t-v1[i])-v2.begin()-1; ans=max(ans,v1[i]+v2[j]); } cout<<ans; re 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long int #define pb push_back int seive[200002]; ll mod = 998244353; ll inv[1000]; ll C(ll a, ll b){ ll temp = 1; for(ll i=0;i<b;i++){ temp = (temp * (a-i))%mod; } for(ll i=0;i<b;i++){ temp = (temp * inv[i+1])%mod; } return temp; } int main() { inv[1] = 1; for(int i = 2; i < 1000; ++i) inv[i] = mod - (mod/i) * inv[mod%i] % mod; for(int i=0;i<200002;i++){ seive[i] = -1; } seive[1]=1; for(int i=2;i<200002;i++){ if(seive[i] == -1){ seive[i] = i; }else{ continue; } for(int j=2*i;j<200002;j=j+i){ if(seive[j]==-1){ seive[j] = i; } } } int n,m; cin>>n>>m; ll ans = m; for(int i=2;i<=m;i++){ int temp = i; int cur = seive[temp]; ll cnt = 0; ll inter = 1; while(temp!=1){ if(cur!=seive[temp]){ inter = (inter * C(cnt+n-2,cnt))%mod; cnt = 0; cur = seive[temp]; } temp = temp/seive[temp]; ++cnt; } inter = (inter * C(cnt+n-2,cnt))%mod; // cout<<inter<<"\n"; ans = (ans + (m/i)*inter)%mod; // cout<<i<<" "; // cout<<ans<<"\n"; } cout<<ans; return 0; }
#include<bits/stdc++.h> #define ll long long int using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n; cin>>n; ll s=0; for (int i = 1; ; ++i) { s+=i; if(s>=n){ cout<<i; break;} } return 0; }
#include <iostream> #include <string> #include <algorithm> #include <vector> #define rep(i,n) for(int i=0;i<n;i++) #define ll long long using namespace std; ll n,a; int main(){ cin >> n; a = 0; while(a*(a+1)/2 < n){ a++; } cout << a << endl; }
#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>; using Pll = pair<ll,ll>; 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; //------------------------------------------------ struct Solver{ void solve(){ int N; cin >> N; vec(ll) a(N); vec(int) t(N); rep(i,N) cin >> a[i] >> t[i]; int Q; cin >> Q; vec(ll) x(Q); rep(i,Q) cin >> x[i]; ll s=0; ll xmin=-llINF, xmax=llINF; rep(i,N){ if(t[i]==1) s+=a[i]; else if(t[i]==2) chmax(xmin, a[i]-s); else if(t[i]==3) chmin(xmax, a[i]-s); } ll y=xmin; rep(i,N){ if(t[i]==1) y+=a[i]; else if(t[i]==2) chmax(y,a[i]); else if(t[i]==3) chmin(y,a[i]); } ll d = y-xmin; if(xmin>xmax){ rep(i,Q) cout << y << endl; }else{ rep(i,Q){ if(x[i]<xmin) cout << y << endl; else if(x[i]>xmax) cout << d + xmax << endl; else cout << d+x[i] << endl; } } } }; int main(){ int testcasenum=1; //cin >> testcasenum; rep1(ti,testcasenum){ Solver solver; solver.solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int mod = 1e9; const int INF = 1001001001; int h, w; int a[2005][2005]; bool visited[2005][2005]; int memo[2005][2005]; int f(int i, int j) { if (i == h - 1 && j == w - 1) return 0; if (visited[i][j]) return memo[i][j]; visited[i][j] = true; int res = -INF; if (j + 1 < w) res = max(res, a[i][j + 1] - f(i, j + 1)); if (i + 1 < h) res = max(res, a[i + 1][j] - f(i + 1, j)); return memo[i][j] = res; } int main() { cin >> h >> w; vector<string> s(h); for (int i = 0; i < h; i++) { cin >> s[i]; } for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { a[i][j] = s[i][j] == '+' ? 1 : -1; } } int score = f(0, 0); if (score == 0) cout << "Draw" << endl; if (score < 0) cout << "Aoki" << endl; if (score > 0) cout << "Takahashi" << endl; return 0; }
#include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <algorithm> #include <queue> using namespace std; const int N = 1e6 + 10, M = 2e6 + 10, inf = 0x3f3f3f3f; const long long Linf = 0x3f3f3f3f3f3f3f3f; inline int read() { bool sym = 0; int res = 0; char ch = getchar(); while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar(); while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar(); return sym ? -res : res; } int n, k, dis[10][10], ans, vis[10], cnt; void dfs(int x, int u, int DIS) { if (x == n) {ans += (DIS + dis[u][1] == k);} vis[u] = 1; for (int v = 1; v <= n; v++) { if (!vis[v]) dfs(x + 1, v, DIS + dis[u][v]); } vis[u] = 0; } int main() { n = read(); k = read(); for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { dis[i][j] = read(); } } dfs(1, 1, 0); printf("%d", ans); return 0; }
#include<bits/stdc++.h> #include <iostream> #include <string> #define lli long long int #define deb1(x) cout<<#x<<" :: "<<x<<"\n"; #define fast ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define deb2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n"; #define deb3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n"; #define deb(v) for(lli i=0;i<v.size();i++) {cout<<v[i]; (i==v.size()-1) ? cout<<"\n":cout<<" "; } #define all(a) a.begin(),a.end() #define ll long long using namespace std; #define f first #define sd second #define pb push_back #define eb emplace_back #define mp make_pair #define sz(x) (ll)x.size() #define vl vector<lli> #define pii pair<lli,lli> lli mod=1e9+7; lli inf=LONG_MAX; using namespace std; lli t,n,x,y,z,k; struct trip{ lli f,sd,th; }; const lli N = 3*100001; int g[9][9]; int ok[10]; int dis[10]; lli sol(int i,int j){ ok[i]=1; lli a=0; int fl=0; for(int l=1;l<n;++l){ if(!ok[l]){ fl=1; a+=sol(l,j+g[i][l]); } } ok[i]=0; if(fl==0){ if(j+g[i][0]==k)return 1; else return 0; } return a; } int main(){ fast t=1; // cin>>t; while(t--){ cin>>n>>k; for(int i=0;i<n;++i){ ok[i]=0; dis[i]=0; for(int j=0;j<n;++j)cin>>g[i][j]; } cout<<sol(0,0)<<endl; } }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(){ string n;cin>>n; ll X = (ll)n.size(); string S; ll Q = stoll(n); if(Q<10){ cout<<0<<endl; return 0; } if(X%2==1){ n=""; for(ll i=0;i<X-1;i++){ n+='9'; } } ll Y = (ll)n.size(); string B; string C; for(ll i=0;i<Y/2;i++){ B+=n[i]; } for(ll i=Y/2;i<Y;i++){ C+=n[i]; } //cout<<B<<endl; ll b = stoll(B); ll c = stoll(C); if(b>c){ cout<<b-1<<endl; }else{ cout<<b<<endl; } }
// execute g++ main.cpp -std=c++14 -I C:\Users\naoya\Desktop\code\Atcoder #include<bits/stdc++.h> //#include<atcoder/all> typedef long long ll; typedef long double ld; using namespace std; //using namespace atcoder; using Pii = pair<int, int>; using Pll = pair<ll, ll>; //ordered_set 重複不可 #include <ext/pb_ds/assoc_container.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>; // use set_function + find_by_order(select itr-num) #define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i) #define ALL(x) (x).begin(),(x).end() #define pb push_back ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;} ll lcm(ll a,ll b){return a/gcd(a,b)*b;} 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;} char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}; char Alpha[26] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'}; int dx[4] = {-1, 1, 0, 0}; int dy[4] = {0, 0, 1, -1}; //cout << std::fixed << std::setprecision(15) << y << endl; //小数表示 int main(){ ll n; cin >> n; vector<ll> lis(n+1); REP(i,0,n){ cin >> lis[i+1]; if((i+1) % 2 == 1){ lis[i+1] *= -1ll; } } REP(i,1,n+1){ lis[i] = lis[i] + lis[i-1]; } map<ll, ll> mp; REP(i,0,n+1){ mp[lis[i]]++; } ll ans = 0; for(auto &x:mp){ ans += (x.second * (x.second-1))/2; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define N 100005 #define MOD 1000000007 #define dd double #define vi vector<int> #define vll vector<ll> #define forr(i, n) for (ll i = 0; i < n; i++) #define revf(i, n) for (ll i = n - 1; i >= 0; i--) #define REP(i, a, b) for (ll i = a; i < b; i++) #define rep1(i, b) for (ll i = 1; i <= b; i++) #define inp(a, n) \ for (ll i = 0; i < n; i++) \ cin >> a[i] #define outp(a, n) \ for (ll i = 0; i < n; i++) \ cout << a[i] << " " #define gcd(a, b) __gcd((a), (b)) #define lcm(a, b) (((a) * (b)) / gcd((a), (b))) #define pb push_back #define mpr make_pair #define ins insert #define BINSC binary_search #define BITOUT __builtin_popcount #define mem(x, n) memset(x, n, sizeof(x)) #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define test \ ll t; \ cin >> t; \ while (t--) #define cn cout << "\n"; int main() { fast ll n,k; cin>>n>>k; ll ar[n],br[n]; vector<pair<ll,ll>>v; forr(i,n) { ll a,b; cin>>a>>b; v.pb(make_pair(a,b)); } sort(v.begin(),v.end()); ll prev=0; ll out=0; for(auto i:v) { ll x=i.first; ll y=i.second; if(x-prev<=k) { out=x; k=k-(x-prev); k+=y; prev=x; } } cout<<out+k; }
#include <bits/stdc++.h> using namespace std; #define rep(i,a,n) for (int i=a;i<n;i++)//iをaからn #define per(i,n,a) for (int i=a-1;i>=n;i--)//iをnからa #define db(x) cout << #x << " = " << x << endl #define db2(x, y) cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"; //デバッグ用 #define all(x) (x).begin(), (x).end() #define INF 10000000000000000 //10^12:∞ #define MOD 1000000007 //10^9+7:合同式の法 #define mp make_pair #define pb push_back #define F first #define S second typedef long long ll; //sort(all(a)); ソート //sort(all(a),greater<int>()); 逆順ソート //a.erase(unique(all(a)), a.end()); ソート後に重複を削除 //cout<< std::fixed << std::setprecision(15)<<0.000001<<endl; 小数点以下を表示させる //vector<vector<int>> data(3, vector<int>(4)); int型の2次元配列(3×4要素の)の宣言 int main() { ll n,k; cin >> n>>k; vector<pair<ll,ll>> friends; ll a,b; rep(i,0,n){ cin>>a>>b; friends.pb(mp(a,b)); } ll ans=k; sort(all(friends)); rep(i,0,n){ if(ans<friends.at(i).F)break; ans+=friends.at(i).S; } cout<<ans; return 0; }
#include <bits/stdc++.h> using i32 = std::int32_t; using u32 = std::uint32_t; using i64 = std::int64_t; using u64 = std::uint64_t; using i128 = __int128_t; using u128 = __uint128_t; using isize = std::ptrdiff_t; using usize = std::size_t; class rep { struct Iter { usize itr; constexpr Iter(const usize pos) noexcept: itr(pos) { } constexpr void operator ++ () noexcept { ++itr; } constexpr bool operator != (const Iter& other) const noexcept { return itr != other.itr; } constexpr usize operator * () const noexcept { return itr; } }; const Iter first, last; public: explicit constexpr rep(const usize first, const usize last) noexcept: first(first), last(std::max(first, last)) { } constexpr Iter begin() const noexcept { return first; } constexpr Iter end() const noexcept { return last; } }; template <class T, T Div = 2> constexpr T INFTY = std::numeric_limits<T>::max() / Div; template <class T> bool setmin(T& lhs, const T& rhs) { if (lhs > rhs) { lhs = rhs; return true; } return false; } template <class F> struct RecLambda: private F { explicit constexpr RecLambda(F&& f): F(std::forward<F>(f)) { } template <class... Args> constexpr decltype(auto) operator () (Args&&... args) const { return F::operator()(*this, std::forward<Args>(args)...); } }; template <class T> using Vec = std::vector<T>; void F_main() { usize N, M; std::cin >> N >> M; Vec<std::array<Vec<usize>, 26>> base(N); Vec<Vec<bool>> between(N, Vec<bool>(N)); for (auto i: rep(0, M)) { usize u, v; char c; std::cin >> u >> v >> c; u -= 1; v -= 1; const usize k = c - 'a'; base[u][k].push_back(v); base[v][k].push_back(u); between[u][v] = between[v][u] = true; } Vec<Vec<usize>> graph(N * N); for (auto u: rep(0, N)) { for (auto v: rep(0, N)) { for (const auto k: rep(0, 26)) { for (const auto x: base[u][k]) { for (const auto y: base[v][k]) { graph[x * N + y].push_back(u * N + v); } } } } } Vec<usize> dist(N * N, INFTY<usize>); std::deque<usize> que; for (auto u: rep(0, N)) { for (auto v: rep(0, N)) { if (u == v) { setmin<usize>(dist[u * N + v], 0); que.push_front(u * N + v); } else if (between[u][v]) { setmin<usize>(dist[u * N + v], 1); que.push_back(u * N + v); } } } while (!que.empty()) { const auto u = que.front(); que.pop_front(); for (const auto v: graph[u]) { if (setmin(dist[v], dist[u] + 2)) { que.push_back(v); } } } const auto ans = dist[0 * N + (N - 1)]; if (ans == INFTY<usize>) { std::cout << -1 << '\n'; } else { std::cout << ans << '\n'; } return; } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); F_main(); return 0; }
#include <bits/stdc++.h> // clang-format off using namespace std; using ll=long long; using ull=unsigned long long; using pll=pair<ll,ll>; const ll INF=4e18; void print0(){}; template<typename H,typename... T> void print0(H h,T... t){cout<<h;print0(t...);} void print(){print0("\n");}; template<typename H,typename... T>void print(H h,T... t){print0(h);if(sizeof...(T)>0)print0(" ");print(t...);} void perr0(){}; template<typename H,typename... T> void perr0(H h,T... t){cerr<<h;perr0(t...);} void perr(){perr0("\n");}; template<typename H,typename... T>void perr(H h,T... t){perr0(h);if(sizeof...(T)>0)perr0(" ");perr(t...);} void ioinit() { cout << fixed << setprecision(15); cerr<<fixed<<setprecision(6); ios_base::sync_with_stdio(0); cin.tie(0); } // clang-format on struct edge { int v; ll cost; }; struct edg2 { int v; ll c; ll d; }; class greater_cost { public: bool operator()(const edge& lh, const edge& rh) const { return lh.cost > rh.cost; } }; using pq_mincost = priority_queue<edge, vector<edge>, greater_cost>; const ll LG = 1e17; vector<vector<edge>> edgcost; vector<vector<edg2>> edgs; vector<ll> c; vector<ll> d; ll dijkstra() { ll n = edgs.size(); vector<bool> done(n, false); pq_mincost pq; pq.push({0, 0}); while (!pq.empty()) { edge e = pq.top(); pq.pop(); ll cost = e.cost; int u = e.v; if (done[u]) continue; done[u] = true; if (u == n - 1) { return cost; } for (auto v : edgs[u]) { ll nc = cost + v.c + v.d / (cost + 1); // 即出発 // t=sqrt(d)付近がよい ll left = sqrt(v.d) - 20; ll right = sqrt(v.d) + 20; for (ll t = left; t <= right; t++) { if(t < cost) continue; ll x = t + v.c + v.d / (t + 1); nc = min(x, nc); } pq.push({v.v, nc}); } } return -1; } int main() { // ダイクストラで三分探索(!?) ioinit(); ll n, m; cin >> n >> m; edgcost.resize(n); edgs.resize(n); c.resize(m); d.resize(m); for (ll i = 0; i < m; i++) { ll a, b; cin >> a >> b >> c[i] >> d[i]; a--; b--; edgs[a].push_back({int(b), c[i], d[i]}); edgs[b].push_back({int(a), c[i], d[i]}); } ll ans = dijkstra(); print(ans); }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using VI = vector<int>; using VL = vector<ll>; using VS = vector<string>; template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>; #define FOR(i,a,n) for(int i=(a);i<(n);++i) #define eFOR(i,a,n) for(int i=(a);i<=(n);++i) #define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i) #define erFOR(i,a,n) for(int i=(n);i>=(a);--i) #define SORT(a) sort(a.begin(),a.end()) #define rSORT(a) sort(a.rbegin(),a.rend()) #define fSORT(a,f) sort(a.begin(),a.end(),f) #define all(a) a.begin(),a.end() #define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x)) #define tp(a,i) get<i>(a) #define line cout << "-----------------------------\n" #define stop system("pause") constexpr ll INF = 1000000000; constexpr ll LLINF = 1LL << 60; constexpr ll mod = 1000000007; constexpr ll MOD = 998244353; constexpr ld eps = 1e-10; constexpr ld pi = 3.1415926535897932; template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; } template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; } inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; } template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& a : v)is >> a; return is; } template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; } template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); } template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); } template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); } template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); } template<class T>inline void print(const T& a) { cout << a << "\n"; } template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); } template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); } template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); } inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; } int sum(const VI& a, int l, int r) { return a[r] - (l == 0 ? 0 : a[l - 1]); } int main() { init(); int n; string s; cin >> n >> s; VI a(n), t(n), c(n), g(n); FOR(i, 0, n) { if (0 < i) { a[i] += a[i - 1]; t[i] += t[i - 1]; c[i] += c[i - 1]; g[i] += g[i - 1]; } if (s[i] == 'A')++a[i]; if (s[i] == 'T')++t[i]; if (s[i] == 'C')++c[i]; if (s[i] == 'G')++g[i]; } int ans = 0; FOR(l, 0, n)FOR(r, l, n) { if (sum(a, l, r) == sum(t, l, r) && sum(c, l, r) == sum(g, l, r))++ans; } print(ans); return 0; }
#include<stdio.h> #include<string.h> #include<algorithm> #include<map> #include<math.h> #define reg register #define ri reg int #define rep(i, x, y) for(ri i = x; i <= y; ++i) #define nrep(i, x, y) for(ri i = x; i >= y; --i) #define DEBUG 1 #define ll long long #define il inline #define swap(a, b) ((a) ^= (b) ^= (a) ^= (b)) #define max(i, j) ((i) > (j) ? (i) : (j)) #define min(i, j) ((i) < (j) ? (i) : (j)) template <class T> inline T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); } namespace IO { #define MAXSIZE (1 << 20) #define isdigit(x) (x >= '0' && x <= '9') char buf[MAXSIZE], *p1, *p2; char pbuf[MAXSIZE], *pp; #if DEBUG #else IO() : p1(buf), p2(buf), pp(pbuf) {} ~IO() { fwrite(pbuf, 1, pp - pbuf, stdout); } #endif inline char gc() { #if DEBUG return getchar(); #endif if(p1 == p2) p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin); return p1 == p2 ? ' ' : *p1++; } inline bool blank(char ch) { return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t'; } template <class T> inline void read(T &x) { register double tmp = 1; register bool sign = 0; x = 0; register char ch = gc(); for(; !isdigit(ch); ch = gc()) if(ch == '-') sign = 1; for(; isdigit(ch); ch = gc()) x = x * 10 + (ch - '0'); if(ch == '.') for(ch = gc(); isdigit(ch); ch = gc()) tmp /= 10.0, x += tmp * (ch - '0'); if(sign) x = -x; } inline void read(char *s) { register char ch = gc(); for(; blank(ch); ch = gc()); for(; !blank(ch); ch = gc()) *s++ = ch; *s = 0; } inline void read(char &c) { for(c = gc(); blank(c); c = gc()); } inline void push(const char &c) { #if DEBUG putchar(c); #else if(pp - pbuf == MAXSIZE) { fwrite(pbuf, 1, MAXSIZE, stdout); pp = pbuf; } *pp++ = c; #endif } template <class T> inline void print(T x) { if(x < 0) { x = -x; push('-'); } static T sta[35]; T top = 0; do { sta[top++] = x % 10; x /= 10; } while(x); while(top) push(sta[--top] + '0'); } template <class T> inline void print(T x, char lastChar) { print(x); push(lastChar); } } using namespace IO; int a[110], f[101][100010]; int main() { f[1][0] = 1; int n, maxn = 0, sum = 0; read(n); rep(i, 1, n) read(a[i]), sum += a[i]; rep(i, 1, n) rep(j, 0, 100010) if(f[i][j]) { if(j + a[i] <= 100000) f[i + 1][j + a[i]] = 1; f[i + 1][j] = 1; } int ans = 99824435; rep(i, 0, sum) if(f[n][i]) ans = min(ans, max(i, sum - i)); print(ans); }
#include <bits/stdc++.h> using namespace std; int main(){ int x,y; cin >> x >> y; if(abs(x-y) >= 3){ cout << "No" << endl; } else{ cout << "Yes" << endl; } }
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG #define rep(i,n) for(int i=0;i<(n);++i) #define repi(i,a,b) for(int i=int(a);i<int(b);++i) #define rrep(i,n) for(int i=((n)-1);i>=0;--i) #define all(x) (x).begin(), (x).end() #define PI 3.14159265358979323846264338327950L #define mod 1000000007 using namespace std; typedef long long ll; typedef long double ld; int main() { int x,y; cin>>x>>y; if(x<y&&x+3>y) cout<<"Yes"; else if(y<x&&y+3>x) cout<<"Yes"; else cout<<"No"; }
/*input 2 3 ..# #.. */ #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; //typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; #pragma GCC optimize("unroll-loops,no-stack-protector") //order_of_key #of elements less than x // find_by_order kth element typedef long long int ll; #define ld double #define pii pair<int,int> #define f first #define s second #define pb push_back #define REP(i,n) for(ll i=0;i<n;i++) #define REP1(i,n) for(int i=1;i<=n;i++) #define FILL(n,x) memset(n,x,sizeof(n)) #define ALL(_a) _a.begin(),_a.end() #define sz(x) (int)x.size() const ll maxn=2e3+5; const ll maxlg=__lg(maxn)+2; const ll INF64=4e18; const int INF=0x3f3f3f3f; const ll MOD=1e9+7; const ld PI=3.14159265358979323846; const ld eps=1e-9; #define lowb(x) x&(-x) #define MNTO(x,y) x=min(x,(__typeof__(x))y) #define MXTO(x,y) x=max(x,(__typeof__(x))y) #define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end())))) #define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin()) #define MP make_pair ll mult(ll a,ll b){ return ((a%MOD)*(b%MOD))%MOD; } ll mypow(ll a,ll b){ ll res=1LL; while(b){ if(b&1) res=mult(res,a); a=mult(a,a); b>>=1; } return res; } string arr[maxn]; vector<int> r[maxn],c[maxn]; int main(){ ios::sync_with_stdio(false),cin.tie(0); int n,m; cin>>n>>m; REP(i,n) cin>>arr[i]; REP(i,n){ r[i].pb(-1); REP(j,m){ if(arr[i][j]=='#') r[i].pb(j); } r[i].pb(m); } int k=n*m; REP(j,m){ c[j].pb(-1); REP(i,n){ if(arr[i][j]=='#') c[j].pb(i),--k; } c[j].pb(n); } ll ans=0; REP(i,n){ REP(j,m){ if(arr[i][j]=='#') continue; ll d=(*upper_bound(ALL(r[i]),j)-*prev(upper_bound(ALL(r[i]),j)))-1; ll d2=(*upper_bound(ALL(c[j]),i)-*prev(upper_bound(ALL(c[j]),i)))-1; //cout<<i<<' '<<j<<' '<<d<<' '<<d2<<'\n'; ans+=mult(mypow(2,d+d2-1)-1,mypow(2,k-(d+d2-1))); ans%=MOD; } } cout<<ans; }
//region #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<string> vs; #define fastio ios_base::sync_with_stdio(0);cin.tie(NULL); #define endl "\n" #define pb push_back #define all(X) begin((X)), end((X)) #define sz(X) (int)(X).size() #define fi first #define se second #define fv(X) for(auto&_:(X))cin>>_ #define fv2(X) for(auto&__:(X))fv(__) #define lbound(X, n) (lower_bound(all(X), n) - begin(X)) #define ubound(X, n) (upper_bound(all(X), n) - begin(X)) #ifdef LOCAL template<size_t S> string to_string(const bitset<S> &x) { return x.to_string(); } string to_string(const string &x) { return '"' + x + '"'; } string to_string(char x) { return string{'\'', x, '\''}; } string to_string(bool x) { return x ? "true" : "false"; } template<typename Head, typename Tail> string to_string(const pair<Head, Tail> &x) { return "(" + to_string(x.first) + ", " + to_string(x.second) + ")"; } template<class T> string to_string(T x) { string ret = "["; for (const auto &i: x) ret += to_string(i) + ", "; if (sz(ret) > 1) ret = ret.substr(0, sz(ret) - 2); return ret += "]"; } string to_string(const char *x) { return string(x); } string to_string() { return ""; } template<typename Head, typename... Tail> string to_string(Head H, Tail... T) { return to_string(H) + ", " + to_string(T...); } #define debug(...) cerr << "[" << #__VA_ARGS__ << "]: " << to_string(__VA_ARGS__) << endl #else #define debug(...) 42 #endif //endregion void solve() { int n; cin >> n; n *= 2; vl R, G, B; for (int i = 0; i < n; i++) { ll a; string c; cin >> a >> c; if (c == "R") R.pb(a); else if (c == "G") G.pb(a); else B.pb(a); } vl even, odd1, odd2; if (sz(R) % 2 == 0 && sz(G) % 2 == 0 && sz(B) % 2 == 0) { cout << 0; return; } if (sz(R) % 2 == 0) { even = R; odd1 = G; odd2 = B; } else if (sz(G) % 2 == 0) { even = G; odd1 = R; odd2 = B; } else { even = B; odd1 = R; odd2 = G; } sort(all(even)); sort(all(odd1)); sort(all(odd2)); auto get_diff_min = [&](vl a1, vl a2, int exclude_idx = -1) { int i = 0, j = 0; ll ret = 4e18; int i1, i2; while (i < sz(a1) && j < sz(a2)) { if (i == exclude_idx) { i++; continue; } if (ret > abs(a1[i] - a2[j])) { ret = abs(a1[i] - a2[j]); i1 = i; i2 = j; } if (a1[i] < a2[j]) i++; else j++; } return vl{ret, i1, i2}; }; auto eo1_diff = get_diff_min(even, odd1); auto eo2_diff = get_diff_min(even, odd2); auto o1o2_diff = get_diff_min(odd1, odd2); if (sz(even) == 0) { cout << o1o2_diff[0]; return; } if (eo1_diff[1] != eo2_diff[2]) { cout << min(o1o2_diff[0], eo1_diff[0] + eo2_diff[0]); return; } int exclude_idx = eo1_diff[1]; auto eo1_exclude_diff = get_diff_min(even, odd1, exclude_idx); auto eo2_exclude_diff = get_diff_min(even, odd2, exclude_idx); cout << min(o1o2_diff[0], min(eo1_exclude_diff[0] + eo2_diff[0], eo1_diff[0] + eo2_exclude_diff[0]) ); } int main() { fastio solve(); return 0; }
//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; void solve() { int n,i;cin>>n; ll x[n],y[n]; fo(i,0,n)cin>>x[i]>>y[i]; int m;cin>>m; ll op[m][2]; fo(i,0,m) { int typ,p=-1; cin>>typ; if(typ>2)cin>>p; op[i][0]=typ; op[i][1]=p; } int q;cin>>q; vector<pair<ll,pii>>queries; fo(i,0,q) { ll a,b;cin>>a>>b; queries.pb(mp(a,mp(b,i))); } sort(all(queries)); ll ansx[q],ansy[q]; int idx=0; i=0; //cout<<"NOW DEAL QUERIES\n"; int signx,signy;signx=signy=1;//positive ll psumx,psumy;psumx=psumy=0ll; int swp=0; while(i<q) { int pt=queries[i].S.F-1; int anspt=queries[i].S.S; ll cx=x[pt]; ll cy=y[pt]; int nextidx=queries[i].F-1; while(idx<=nextidx) { if(op[idx][1]==-1)//Rotation { swp=swp^1; swap(signx,signy); if(op[idx][0]==1)//clockwise 90 { //swap(cx,cy); swap(psumx,psumy); signy=signy^1; psumy=(-1ll)*psumy; } else //counter clockwise 90 { //swap(cx,cy); swap(psumx,psumy); signx=signx^1; psumx=(-1ll)*psumx; } } else { ll p=op[idx][1]; if(op[idx][0]==3) { psumx=(-1ll)*psumx;; psumx+=(p*2ll); signx=signx^1; } else { psumy=(-1ll)*psumy;; psumy+=(p*2ll); signy=signy^1; } } idx++; } //cout<<cx<<" "<<cy<<" "<<signx<<" "<<signy<<" "<<psumx<<" "<<psumy<<"\n"; if(swp)swap(cx,cy); ll fx,fy; fx=cx; fy=cy; if(!signx)fx=(-1ll*fx); if(!signy)fy=(-1ll*fy); fx+=psumx; fy+=psumy; ansx[anspt]=fx; ansy[anspt]=fy; i++; } fo(i,0,q)cout<<ansx[i]<<" "<<ansy[i]<<"\n"; } int main() { fastio //Test_cases solve(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> P; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define print(x) cout << x << endl #define all(v) (v).begin(),(v).end() #define YN(ok) print((ok ? "YES" : "NO")) #define yn(ok) print((ok ? "Yes" : "No")) #define decimal(n) setprecision(30) << n #define Arrays_toString(v) rep(o,(v).size()){cout<<v[o]<<", ";if(o==(v).size()-1){cout<<endl;}} template<class T> void que_toString(queue<T> q){while(q.size()){cout<<q.front()<<", ";q.pop();if(q.empty()){cout<<endl;}}} int main(void){ int n, m, k; cin >> n >> m >> k; vi v(k); rep(i, k) cin >> v[i]; // ans: // マス0 → Nまですごろくする時、サイコロを振る回数の期待値は? // (サイコロの目は1~Mで等確率) // (「ふりだしに戻る」マスもある) // how: // 期待値DPする。 // (点0から点Nに行くのに貼る辺の本数の期待値は?と同値) // 例えば6まで出るならiの期待値は1/6 * (i+1, i+2, ... i+6) + 1 // DAGでない(ループがある)DPなので、dp[地雷] = dp[0] = xとして進める。 // dp[i] = ax + bの形でデータを持つ。(a = dp[i][0], b = dp[i][1]) // -> dp[0] = a * x(=dp[0]) + b // -> dp[0] = b / (1 - a) // dp[i]: マスiからゴールに行くまでに振る回数の期待値 vector<vector<double>> dp(n+1+m, vector<double>(2)); for (int vv : v) { dp[vv][0] = 1; dp[vv][1] = 0; } // sum: 区間長mのdpのsum vector<double> sum(2); for (int i = n+m-1; i >= n; i--) { sum[0] += dp[i][0]; sum[1] += dp[i][1]; } for (int i = n-1; i >= 0; i--) { if (dp[i][0] != 1) { dp[i][0] = sum[0] / m; dp[i][1] = sum[1] / m + 1; } // update sum sum[0] -= dp[i+m][0]; sum[1] -= dp[i+m][1]; sum[0] += dp[i][0]; sum[1] += dp[i][1]; } // for (auto dpi : dp) Arrays_toString(dpi); // x = dp[0][0] * x + dp[0][1] // -> dp[0][1] / (1 - dp[0][0]) = x double res = -1; if (dp[0][0] != 1) res = dp[0][1] / (1 - dp[0][0]); if (res > 1e12) res = -1; print(decimal(res)); }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(ll i=0; i<(ll)n; i++) #define ALL(obj) begin(obj), end(obj) typedef long long ll; int n, m, a, b, cnt; vector<vector<int> > G(22); vector<int> color(22, -1), ts; vector<bool> vit(22, 0); void dfs(int now){ ts.push_back(now); vit[now]=1; for(int i : G[now]){ if(!vit[i]) dfs(i); } } ll DFS(int i){ if(i==ts.size()) return 1; ll ret=0; rep(j, 3){ bool f=1; for(int v:G[ts[i]]){ if(color[v]==j) f=0; } if(!f) continue; color[ts[i]]=j; ret+=DFS(i+1); color[ts[i]]=-1; } return ret; } int main() { cin>>n>>m; ll ans=1; rep(i, m){ cin>>a>>b; a--; b--; G[a].push_back(b); G[b].push_back(a); } rep(i, n){ if(vit[i]) continue; dfs(i); fill(ALL(color), -1); ans*=DFS(0); ts.clear(); } cout<<ans<<endl; return 0; }
#include <iostream> #include <math.h> #include <vector> using namespace std; const int MOD = 998244353; typedef pair <int,int> ii; long long fac(long long a){ if(a==0)return 1; return (a*fac(a-1))%MOD; } int n, k; int en[50][50]; vector < vector <int> > mc, mr; int vi[50][2]; bool cc(int i, int j){ for(int it=0;it<n;it++)if(en[it][i]+en[it][j]>k)return false; return true; } bool cr(int i, int j){ for(int it=0;it<n;it++)if(en[i][it]+en[j][it]>k)return false; return true; } long long cal(int ac, vector < vector <int> > &ad, int ve){ vi[ac][ve] = 1; long long res = 1; for(int i=0;i<ad[ac].size();i++)if(!vi[ad[ac][i]][ve]){ res += cal(ad[ac][i], ad, ve); } return res; } int main(){ cin.tie(0); ios_base::sync_with_stdio(0); cin>>n>>k; for(int i =0;i<n;i++)for(int j=0;j<n;j++){ cin>>en[i][j]; } mr.resize(n); mc.resize(n); long long res = 1; for(int i=0;i<n;i++)for(int j = i+1;j<n;j++){ if(cc(i,j)){ mc[i].push_back(j); mc[j].push_back(i); } if(cr(i,j)){ mr[i].push_back(j); mr[j].push_back(i); } } for(int i=0;i<n;i++){ if(!vi[i][0]){ res = (res * fac(cal(i, mr, 0)))%MOD; } if(!vi[i][1]){ res = (res * fac(cal(i, mc, 1)))%MOD; } } cout<<res<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(ll i=0;i<n;i++) #define repl(i,l,r) for(ll i=(l);i<(r);i++) #define per(i,n) for(ll i=(n)-1;i>=0;i--) #define perl(i,r,l) for(ll i=r-1;i>=l;i--) #define fi first #define se second #define pb push_back #define ins insert #define pqueue(x) priority_queue<x,vector<x>,greater<x>> #define all(x) (x).begin(),(x).end() #define CST(x) cout<<fixed<<setprecision(x) #define rev(x) reverse(x); using ll=long long; using vl=vector<ll>; using vvl=vector<vector<ll>>; using pl=pair<ll,ll>; using vpl=vector<pl>; using vvpl=vector<vpl>; const ll MOD=1000000007; const ll MOD9=998244353; const int inf=1e9+10; const ll INF=4e18; const ll dy[8]={1,0,-1,0,1,1,-1,-1}; const ll dx[8]={0,1,0,-1,1,-1,1,-1}; template <typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); } template <typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); } int main(){ ll a,b;cin >> a >> b; ll c,d;cin >> c >> d; ll t=0; rep(i,1000000){ if(a<=t*d){ cout << i <<endl;return 0; } a+=b;t+=c; } cout << -1 <<endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long A, B, C, D; cin >> A >> B >> C >> D; if( D * C <= B ) { cout << -1 << endl; return 0; } long long a = A; long long b = 0; int ans = 0; while( a > b * D ) { a += B; b += C; ans++; } cout << ans << endl; }
#include<bits/stdc++.h> typedef long long ll; const int INF = 1e9; const int MOD = 1e9 + 7; using namespace std; //ループマクロ #define FOR(i , a , b) for(int i = (a) ; i < (b) ; i++) #define REP(i , n) for(int i = 0 ; i < n ; i++) #define REPR(i , n) for(int i = n ; 0 <= i ; i--) #define ROP(i, n) for(int i = 1 ; i <= n ; i++) //入出力 #define SCOUT(x) cout << (x) << " " #define VECCIN(x) for(auto& ele : (x) ) cin >> ele #define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl; //その他 #define ALL(obj) (obj).begin() , (obj).end() #define SORT(obj) sort(ALL(obj)) #define GSORT(obj) sort(ALL(obj) , greater<int>()) #define P pair<int , int> #define V vector<int> #define VLL vector<long long> #define M map<int, int> #define S set<int> #define PQ priority_queue<int> #define PQG priority_queue<ll , VLL , greater<ll>> int main(void) { ios::sync_with_stdio(false); cin.tie(0); ll N; cin >> N; PQG pq; for(ll i = 1 ; i*i <= N ; i++) if(N % i == 0){ pq.push(i); if(i*i != N) pq.push(N / i); } while(!pq.empty()){ cout << pq.top() << endl; pq.pop(); } return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mp make_pair #define all(a) (a).begin(),(a).end() #define endl "\n" #define yes "YES\n" #define no "NO\n" #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); vector<int>v,pos; vector<int>ans; int n; void perform_operation(int id) { //cout<<id<<endl; assert(id>0); assert(id<n); int select_odd = ans.size()%2; select_odd = 1 - select_odd; assert(id%2 == select_odd); swap(v[id], v[id+1]); pos[v[id]] = id; pos[v[id+1]] = id+1; ans.pb(id); //for(int i=1;i<=n;i++)cout<<v[i]<<" "; //cout<<endl; // for(int i=1;i<=n;i++)cout<<pos[i]<<" "; // cout<<endl; } void solve(int test) { cin>>n; int i,j; v.resize(n+3),pos.resize(n+3); ans.clear(); for(i=1;i<=n;i++) { cin>>v[i]; pos[v[i]] = i; } for(int k=1;k<=n;k++){ for(i=1;i<=n-1;i++) { if(pos[i] == i) { continue; } else { int select_odd = 1-(ans.size()%2); if(select_odd == 1) { if(pos[i]%2==1) { int x1,x2; if((n-1)%2==1)x1 = n-1; else x1 = n-2; if(i%2==1)x2 = i; else x2 = i+1; if(pos[i] != x2 + 1 && pos[i] != x2) perform_operation(x2); else if(pos[i] != x1 + 1 && pos[i] != x1) perform_operation(x1); else { assert(x2 != i); perform_operation(x2); perform_operation(x2-1); } } while(pos[i] != i) { assert(pos[i] > i); perform_operation(pos[i]-1); } } else { if(pos[i]%2==0) { int x1,x2; if((n-1)%2==0)x1 = n-1; else x1 = n-2; if(i%2==0)x2 = i; else x2 = i+1; if(pos[i] != x2 + 1 && pos[i] != x2) perform_operation(x2); else if(pos[i] != x1 + 1 && pos[i] != x1) perform_operation(x1); else { assert(x2!=i); perform_operation(x2); perform_operation(x2-1); } } while(pos[i] != i) { //cout<<pos[i]<<" "<<i<<endl; assert(pos[i] > i); perform_operation(pos[i]-1); } } } assert(pos[i] == i); } } for(i=1;i<=n;i++) { assert(v[i] == i); } assert(n*n >= ans.size()); cout<<ans.size()<<endl; for(auto a:ans) { cout<<a<<" "; } cout<<endl; return; } int main() { //fast; int t = 1; cin>>t; for(int x=1;x<=t;x++) { solve(x); } return 0; }
#include <algorithm> #include <iostream> using namespace std; typedef long long ll; const ll MOD = 998244353; int main() { int n; cin >> n; ll s = 0; ll a[200005]; for(int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); ll ans = 0; for(int i = 0; i < n; i++){ ans = (ans + a[i] * (s + a[i])) % MOD; s = (s * 2 + a[i]) % MOD; } cout << ans << endl; }
#include<bits/stdc++.h> #define L(i, j, k) for(int i = (j); i <= (k); i++) #define R(i, j, k) for(int i = (j); i >= (k); i--) #define ll long long #define sz(a) ((int) a.size()) #define vi vector<int> using namespace std; const int N = 5e5 + 7, inf = 1e9 + 7; int n, a[N], b[N], cnt; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; a[n] = 3 * 5 * 7 * 11; L(i, 1, 5000) if(i % 3 == 0 || i % 5 == 0 || i % 7 == 0 || i % 11 == 0) { a[++cnt] = i * 2; if(cnt == n - 1) break; } L(i, 1, n) cout << a[i] << " "; return 0; }
//Bismillahir Rahmanir Rahim //Allahumma Rabbi Jhidni Elma /*--------Please carefully check-------- 1.Overflow and underflow 2. */ #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; const ld PI = 2*acosl(0.0); const int inf=2e5+7; const int mxN=3000000; #define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define endl "\n" #define pb push_back #define reset(a) memset(a,0,sizeof a) #define gcd(a,b) __gcd((a),(b)) #define lcm(a,b) (a/gcd(a,b)*b) #define abs(a) (a<0?-(a):a) #define debug1(x) cout << #x << "=" << x << endl #define debug2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl #define digit2(x) floor((log2(x))) #define digit2(x) floor((log2(x))) #define sc(a) scanf("%d",&a) #define pf(a) printf("%d\n",a) int main() { int i,n,j; string st,tmp; stack<char>stk; cin>>n; cin>>st; for(j=0,i=0;i<n;i++) { stk.push(st[i]); while(stk.size() and j<3) { tmp+=stk.top(); // cout<<tmp<<endl; stk.pop(); j++; } reverse(tmp.begin(),tmp.end()); //cout<<tmp<<endl; if(tmp=="fox") { tmp.clear(); } else { //cout<<" "; for(j=0;j<(int)tmp.size();j++) { // cout<<tmp[j]; stk.push(tmp[j]); } tmp.clear(); //cout<<endl; } j=0; // cout<<tmp<<endl; } cout<<stk.size()<<endl; // cout<<n<<endl; }
#include <iostream> #include <cstdio> #include <vector> #include <iomanip> #include <unordered_map> #include <unordered_set> #include <algorithm> #include <map> #include <set> #include <cmath> using namespace std; using VI = vector <int>; using SI = set<int>; int main() { int N; string S; cin >> N >> S; SI remain; for (int i = 0; i < N; ++i) { remain.insert(i); } auto iter = remain.begin(); while (iter != remain.end()) { VI now(3, *iter); auto iter2 = iter; ++iter2; if (iter2 != remain.end()) { now[1] = *iter2; auto iter3 = iter2; ++iter3; if (iter3 != remain.end()) { now[2] = *iter3; } } if (S[now[0]] == 'f' && S[now[1]] == 'o' && S[now[2]] == 'x') { int nextVal = -1; auto nextIter = iter; if (iter == remain.begin()) { ++nextIter; ++nextIter; ++nextIter; } else { --nextIter; if (nextIter != remain.begin()) { --nextIter; } } if (nextIter != remain.end()) { nextVal = *nextIter; } // remove remain.erase(remain.find(now[0])); remain.erase(remain.find(now[1])); remain.erase(remain.find(now[2])); N -= 3; if (nextVal >= 0) { iter = remain.find(nextVal); // set can be dangling } else { break; } } else { ++iter; } } cout << N << endl; return 0; }
//#pragma GCC optimize ("O2") //#pragma GCC optimize ("Ofast") // IN THE NAME OF GOD #include <bits/stdc++.h> using namespace std; typedef pair<int, int> pii; template<typename Head> inline void dout(Head in) { cerr << in << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<int> b(n); for (int i = 0; i < n; i++) { cin >> b[i]; } vector<int> cnt(n + 1, 0); for (int i = 0; i < n; i++) { int x; cin >> x; cnt[b[x - 1]]++; } long long ans = 0; for (int i = 0; i < n; i++) { ans += cnt[a[i]]; } cout << ans; return 0; }
#include <bits/stdc++.h> #include <unordered_set> #include <algorithm> using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vll = vector<ll>; using vs = vector<string>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repll(i,n) for (ll i = 0; i < (ll)(n); i++) #define fore(x,a) for(auto&(x) : (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 (b<a) { a=b; return 1; } return 0; } #define ALL(a) (a).begin(), (a).end() const ll INFL = 1e18; const int INFI = 1e9; const int MOD = 1e9 + 7; int main(){ int N; cin >> N; vi es = {2,3,5}; set<int> ans; vi base; rep(i, 3) { int res = 1; rep(j, 3){ if(i != j) res *= es[2-j]; } base.push_back(res); } int max = 0; fore(x, base) chmax(max, x); fore(x, base){ int tmp = x; while(tmp <= 10000){ if(tmp > max) ans.insert(tmp); tmp += x; } } fore(x, ans) base.push_back(x); rep(i, N){ cout << base[i] << " "; } cout << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const long long INF = 1001001001; const long long MOD = /**/1000000007;//*/998244353; const double EPS = 1e-10; int main(){ cin.tie(0); ios::sync_with_stdio(false); int a,b; cin>>a>>b; cout<<2*a+100-b<<endl; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<n;i++) #define repr(i,n) for(int i=n-1;i>=0;i--) #define MAX(a,b) a=a>b?a:b #define MIN(a,b) a=a<b?a:b #define REP(i,x,n) for(int i=x;i<n;i++) #define REPR(i,x,n) for(int i=n-1;i>=x;i--) #define pb push_back #define ALL(obj) (obj).begin(), (obj).end() #define ALLr(obj) (obj).rbegin(), (obj).rend() #define endl "\n" #define F first #define S second #define EN cout<<endl; #define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); using namespace std; typedef long long ll; typedef pair<ll, ll> P; typedef tuple<ll,ll,ll> PP; typedef tuple<ll,ll,ll,ll> PPP; typedef vector<ll> VLL; typedef vector<VLL> VVLL; typedef vector<P> VP; typedef vector<string> VS; typedef priority_queue<ll> PQ; const ll mod=1000000007; template<class T> void out(T a){cout<<a<<'\n';} template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';} template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';} template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);} template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';} template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);} template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);} template<class T> void yes(T b){if(b)out("yes");else out("no");} template<class T> void Yes(T b){if(b)out("Yes");else out("No");} template<class T> void YES(T b){if(b)out("YES");else out("NO");} template<class T> void no(T b){if(b)out("no");else out("yes");} template<class T> void No(T b){if(b)out("No");else out("Yes");} template<class T> void NO(T b){if(b)out("NO");else out("YES");} template<class T> int sint(T s){int n;sscanf(s.c_str(),"%d",&n);return n;} //combsort template<typename T> void cSort(vector<T>& v){size_t h = (v.size()*10)/13;bool is_sorted = false;while(!is_sorted){if(h==1)is_sorted = true;for(size_t i=0; i<v.size()-h; ++i){if(v[i]>v[i+h]){swap(v[i],v[i+h]);if(is_sorted)is_sorted = false;}}if(h>1) h = (h*10)/13;if(h==0) h = 1;}} ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);} ll modpow(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;} //約数列挙 vector<long long> divisor(long long n) {vector<long long> ret;for (long long i = 1; i * i <= n; i++) {if (n % i == 0) {ret.push_back(i);if (i * i != n) ret.push_back(n / i);}}sort(ret.begin(), ret.end()); return ret;} template <int MOD> struct ModInt {int val;ModInt(ll v = 0) : val(v % MOD) {if (val < 0) val += MOD;};ModInt operator+() const { return ModInt(val); }ModInt operator-() const { return ModInt(MOD - val); }ModInt inv() const { return this->pow(MOD - 2); }ModInt operator+(const ModInt& x) const { return ModInt(*this) += x; }ModInt operator-(const ModInt& x) const { return ModInt(*this) -= x; }ModInt operator*(const ModInt& x) const { return ModInt(*this) *= x; }ModInt operator/(const ModInt& x) const { return ModInt(*this) /= x; }ModInt pow(ll n) const {auto x = ModInt(1);auto b = *this;while (n > 0) {if (n & 1) x *= b;n >>= 1;b *= b;}return x;}ModInt& operator+=(const ModInt& x) {if ((val += x.val) >= MOD) val -= MOD;return *this;}ModInt& operator-=(const ModInt& x) {if ((val -= x.val) < 0) val += MOD;return *this;}ModInt& operator*=(const ModInt& x) {val = ll(val) * x.val % MOD;return *this;}ModInt& operator/=(const ModInt& x) { return *this *= x.inv(); }bool operator==(const ModInt& b) const { return val == b.val; }bool operator!=(const ModInt& b) const { return val != b.val; }friend istream& operator>>(istream& is, ModInt& x) noexcept { return is >> x.val; }friend ostream& operator<<(ostream& os, const ModInt& x) noexcept { return os << x.val; }}; constexpr int MOD = 998244353;//1e9 + 7; using mint = ModInt<MOD>; constexpr ll INF = 1e18; int main() { FAST; ll n,k,m,t,a,b; cin>>a>>b; out(2*a+100-b); }
#include<bits/stdc++.h> using namespace std; int n,a,b; void read(int &x) { char ch;bool ok; for(ok=0;!isdigit(ch);ch=getchar()) if(ch=='-') ok=1; for(x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar()); if(ok) x=-x; } int main() { read(n),read(a),read(b); cout<<n-a+b; return 0; }
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; const long long inf = 1LL<<60; using ll = long long; template<int MOD> struct ModInt { static const int Mod = MOD; unsigned x; ModInt() : x(0) { } ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; } ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; } int get() const { return (int)x; } ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; } ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; } ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; } ModInt &operator/=(ModInt that) { return *this *= that.inverse(); } ModInt operator+(ModInt that) const { return ModInt(*this) += that; } ModInt operator-(ModInt that) const { return ModInt(*this) -= that; } ModInt operator*(ModInt that) const { return ModInt(*this) *= that; } ModInt operator/(ModInt that) const { return ModInt(*this) /= that; } ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); } return ModInt(u); } bool operator==(ModInt that) const { return x == that.x; } bool operator!=(ModInt that) const { return x != that.x; } ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; } }; template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a) { st << a.get(); return st; }; template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) { ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; } typedef ModInt<1000000007> mint; int main(){ ll n, m; cin >> n >> m; ll s = 0; vector<int> a(n); for (int i=0; i<n; i++) { cin >> a[i]; s += a[i]; } mint res = mint(1); for (ll r = 0; r < n+s; r++) { res *= mint(n+m-r); res /= mint(n+s-r); } cout << res << endl; }
#include<bits/stdc++.h> #include<vector> #include <iostream> using namespace std; using ll = long long; int main() { int x, y; cin >> x >> y; if (x != y){ cout << 3 - x - y << endl; }else{ cout << x << endl; } return 0; }
/* 十 聖イシドールスよ、迷えるプログラマを導き給え! 十 */ #include <cstddef> #include <iostream> #include <math.h> #include <vector> #include <string> #include <map> #include <algorithm> #include <cmath> #include <deque> #include <queue> #include <cstring> #include <cstdint> #include <tuple> #include <fstream> #include <numeric> /*** MACRO and TYPE DEFINES ***/ #define rep(i, n) \ for (int i = 0; i < n; i++) using ll = long long; using P = std::pair<int, int>; /*** CONST DEFINES ***/ const long long MOD = 998244353; // const long long MOD = 1000000007; const ll INF64 = 9000000000000000000; const int INF32 = 1000000000; /*** UTILITY CLASS ***/ /*** FUNCTIONS ***/ /*** GLOVAL VALIABLES ***/ /*** EXECUTE ***/ int main(void) { #if 0 //ファイルから読み込みたいとき std::ifstream in(); std::cin.rdbuf(in.rdbuf()); #endif int x, y; std::cin >> x >> y; int z = 0; if (x == y) { z = x; } else { int te[] = {0, 1, 2}; te[x] -= 100; te[y] -= 100; rep(i, 3) { if (te[i] >= 0) { z = te[i]; break; } } } std::cout << z << std::endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define db double const int N = 100020; int n, a[N]; int main() { // freopen(".in", "r", stdin); // freopen(".out", "w", stdout); cin >> n; for (int i = 1; i <= n; i++) { int Max = 0; for (int j = 1; j <= (int)sqrt((db)i); j++) if (i % j == 0) { Max = max(Max, a[j]); Max = max(Max, a[i / j]); } a[i] = Max + 1; } for (int i = 1; i <= n; i++) printf("%d ", a[i]); // fclose(stdin); // fclose(stdout); return 0; }
#include<bits/stdc++.h> #define ll long long #define mp make_pair #define f(i,n) for(int i=0;i<n;i++) #define F first #define S second #define pb push_back using namespace std; ll dp[205][15]; ll fun(ll len, ll parts){ if(len<parts) return 0; if(parts==1) return 1; if(dp[len][parts]!=-1) return dp[len][parts]; ll res = 0; for(int i=1;i<=len;i++){ res = res + fun(len-i,parts-1); } dp[len][parts] = res; return res; } void test(){ ll l; cin>>l; memset(dp,-1,sizeof(dp)); cout<<fun(l,12)<<"\n"; } int main(){ std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int tests=1; // cin>>tests; while(tests--){ test(); } }
#include<bits/stdc++.h> using namespace std; #define fast {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);} typedef long long int ll; typedef string S; #define M 1e18 #define AS 250005 #define sp cout<<' ' #define nw cout<<endl #define rt return #define __ template<typename T, typename... Types> void in() {rt;} __ void in(T &a, Types&... b){cin>>(a); in(b...);} void o() {rt;} __ void o(T a, Types... b){cout<<(a);sp; o(b...);} #define fr(Hi,a,n) for(ll Hi=a;Hi<=n;Hi++) #define frm(Hi,a,n) for(ll Hi=n;Hi>=a;Hi--) #define P pair<ll,ll> #define vc vector<ll> #define pb push_back #define MP map<ll,ll> bool sortin(const pair<ll,ll> &e,const pair<ll,ll> &f){return (e.first<f.first);} bool POT(ll x){return x && (!(x&(x-1)));} ll i,j,k,l,m,n,p,q,r,a,b,c,x,y,z,ts,mn=1e18,mod=1e9+7; ll ar[AS],br[AS],xr[AS],tem[AS]; int main() { fast; S s; in(s); n=s.size(); S t="ZONe"; fr(i,0,n-4) { if(s.substr(i,4)==t)c++; } o(c); }
#include<iostream> using namespace std; int main(void) { int c = 0, ans = 0; for (int i = 0; i < 12; i++) { char a; cin >> a; if (a == 'Z') c = 1; else if (c == 1 && a == 'O')c = 2; else if (c == 2 && a == 'N')c = 3; else if (c == 3 && a == 'e') { ans++; c = 0; } } cout << ans << endl; }
#pragma GCC optimize ("O2") #pragma GCC target ("avx2") //#include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; #include<iostream> #include<algorithm> #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 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 getint1() { if (ci - owa > 0) { memcpy(cn, owa, CL); ci -= CM; fread(cn + CL, 1, CM, stdin); } ll tmp = *(ll*)ci; 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; return tmp; } inline int getint2() { if (ci - owa > 0) { memcpy(cn, owa, CL); ci -= CM; fread(cn + CL, 1, CM, stdin); } int pn = 1; if (*ci == '-') { pn = -pn; ci++; } 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 ((ct = *ci++) >= '0') { tmp = tmp * 10 + ct - '0'; if (*ci++ == '0') { tmp = tmp * 10; ci++; } } } return pn * tmp; } int main() { cin.tie(0); ios::sync_with_stdio(false); int N = getint1(); int L[200200], R[200200]; rep1(i, N) L[i] = 2e9; rep1(i, N) R[i] = -2e9; rep(i, N) { int x = getint2(), c = getint1(); if (L[c] > x) L[c] = x; if (R[c] < x) R[c] = x; } ll dp0 = 0, dp1 = 0; ll za0 = 0, za1 = 0; rep1(i, N) { if (L[i] > 1e9) continue; ll tmp = R[i] - L[i] + min(dp0 + abs(L[i] - za0), dp1 + abs(L[i] - za1)); dp0 = R[i] - L[i] + min(dp0 + abs(R[i] - za0), dp1 + abs(R[i] - za1)); dp1 = tmp; za0 = L[i]; za1 = R[i]; } co(min(dp0 + abs(za0), dp1 + abs(za1))); Would you please return 0; }
//#define local #include <bits/stdc++.h> using namespace std; #define endl '\n' #define rep(i,n); for(long long i = 0;i < (n);i++) using ll = long long; using P = pair<long long,long long>; template <class T> using vec = vector<T>; #ifdef local #include "library/debug.cpp" #else #define debug(...) #endif const ll inf = 1e18; struct UnionFind { vector<ll> d; UnionFind(ll n=0): d(n,-1) {} ll root(ll x) { if (d[x] < 0) return x; return d[x] = root(d[x]); } bool unite(ll x, ll y) { x = root(x); y = root(y); if (x == y) return false; if (d[x] > d[y]) swap(x,y); d[x] += d[y]; d[y] = x; return true; } bool same(ll x, ll y) { return root(x) == root(y);} ll size(ll x) { return -d[root(x)];} }; ll n; vec<double> x,y; double dist(ll i ,ll j){return sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));} bool check(double d){ UnionFind uf(n+2); rep(i,n){ for(ll j = i+1;j<n;j++)if(d > dist(i,j))uf.unite(i,j); } rep(i,n){ if(d > 100 + y[i])uf.unite(i,n); if(d > 100 - y[i])uf.unite(i,n+1); } return !uf.same(n,n+1); } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(10); cin >> n; x.resize(n); y.resize(n); rep(i,n)cin >> x[i] >> y[i]; double ok = 0.0,ng=100.0; while(ok + 1e-5< ng){ double mid = (ok+ng)/2.0; if(check(mid*2))ok = mid; else ng = mid; } cout << ok << endl; }
// Problem: B - 200th ABC-200 // Contest: AtCoder - KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200) // URL: https://atcoder.jp/contests/abc200/tasks/abc200_b // Memory Limit: 1024 MB // Time Limit: 2000 ms // // Powered by CP Editor (https://cpeditor.org) #include<bits/stdc++.h> using namespace std; #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL); #define int long long #define ld long double #define pii pair<int,int> #define fi first #define se second #define pb push_back #define all(x) (x).begin(), (x).end() #define rep(i,x,y) for(int i=x; i<y; i++) #define fill(a,b) memset(a,b,sizeof(a)) #define vi vector<int> #define vii vector<pair<int,int>> #define setbits(x) __builtin_popcountll(x) #define w(x) int x; cin>>x; while(x--) #define in(a) for(auto &x: a)cin>>x; #define out(a) for(auto x: a){cout<<x<<' ';}cout<<'\n'; #define inf 1000000000 //#define mm 1000000007 998244353 void print(bool n){if(n)cout<<"YES";else cout<<"NO";cout<<'\n';} signed main(){ int n,k; cin>>n>>k; rep(i,0,k){ if(n%200==0){ n/=200; } else{ n=stoll(to_string(n)+"200"); } } cout<<n; return 0; }
/****************************************************************************** Online C++ Compiler. Code, Compile, Run and Debug C++ program online. Write your code in this editor and press "Run" button to compile and execute it. *******************************************************************************/ #include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n; cin>>n; int k; cin>>k; for(int i=0;i<k;i++){ if(n%200==0){ n=n/200; } else{ n=n*1000+200; } } cout<<n; }
#include<bits/stdc++.h> using namespace std; int main(){ int m,h; cin>>m>>h; if(h%m==0) cout<<"Yes"<<endl; else cout<<"No"<<endl; return 0; }
#include <iostream> #include <iomanip> #include <vector> #include <cmath> #include <algorithm> #include <deque> #include <set> #include <limits> #include <string> #include <map> #include <unordered_map> #include <unordered_set> #include <list> #include <numeric> using namespace std; using ll = long long; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) /* input & output */ #define IN(a) cin >> a #define OUT(a) cout << a << endl #define OUT_PREC(a, n) cout << fixed << setprecision(n) << a << endl /* vector */ #define VEC(t, v, n, ini) vector<t> v(n, ini) #define VEC2(t, v, m, n, ini) vector<vector<t>> v(m, vector<t>(n, ini)) #define VEC3(t, v, k, m, n, ini) vector<vector<vector<t>>> v(k, vector<vector<t>>(m, vector<t>(n, ini))) /* bit */ #define IS_TRUE(bit, i) (bit & (1 << i)) // bitのi成分 #define FLAG_ON(bit, i) (bit|(1 << i)) // bitのi成分をtrueに #define FLAG_OFF(bit, i) (bit & ~(1 << i)) // bitのi成分をfalseに #define ALL_TRUE(n) (1 << n) // 2^n #define CMPSET(bit, s) (bit ^ s) // sのbitに対する補集合 #define INCLUDES(a, b) ((a & b) == b) // aはbを含むか bool solve() { int m, h; cin >> m >> h; return (h % m == 0); } int main() { /* solve */ if(solve()) cout << "Yes" << endl; else cout << "No" << endl; system("pause"); }
#include <iostream> using namespace std; int main(){ int v,t,s,d; cin >> v >> t >> s >> d; if(v * t <= d && d <= v * s){ cout << "No"; }else{ cout << "Yes"; } return 0; }
//#include <bits/stdc++.h> #include <iostream> #include <cstdio> #include <algorithm> #include <cstdlib> #include <string> #include <vector> #include <map> #include <queue> using namespace std; typedef long long ll; typedef vector<int> vint; typedef vector<vector<int> > vvint; typedef vector<long long> vll, vLL; typedef vector<vector<long long> > vvll, vvLL; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) for(int i=0;i<n;++i) #define mod (ll)(1e9+7) #define FIX(a) ((a)%mod+mod)%mod #define ALL(obj) (obj).begin(), (obj).end() #define rALL(obj) (obj).rbegin(), (obj).rend() #define INF 1000000000 //1e9 #define LLINF 2000000000000000000LL //2e18 #define fi first #define se second #define pb push_back int dy[]={0, 0, 1, -1}; int dx[]={1, -1, 0, 0}; int main(){ cin.tie(0); ios::sync_with_stdio(false); int v,t,s,d; cin >> v >> t >> s >> d; if(!(d>=v*t&&d<=v*s)){ cout << "Yes" << endl; }else{ cout << "No" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n,m,i,t,p,q,query,a,b; cin >> n; vector<long long> x(n),y(n); for(i=0; i<n; i++){ cin >> x[i] >> y[i]; } cin >> m; vector<long long> px(m+1),py(m+1),dx(m+1),dy(m+1); px[0]=1; py[0]=2; dx[0]=0; dy[0]=0; for(i=0; i<m; i++){ cin >> t; if(t==1){ px[i+1]=py[i]; py[i+1]=-px[i]; dx[i+1]=dy[i]; dy[i+1]=-dx[i]; }else if(t==2){ px[i+1]=-py[i]; py[i+1]=px[i]; dx[i+1]=-dy[i]; dy[i+1]=dx[i]; }else if(t==3){ cin >> p; px[i+1]=-px[i]; py[i+1]=py[i]; dx[i+1]=2*p-dx[i]; dy[i+1]=dy[i]; }else if(t==4){ cin >> p; px[i+1]=px[i]; py[i+1]=-py[i]; dx[i+1]=dx[i]; dy[i+1]=2*p-dy[i]; } } long long ansx,ansy; cin >> query; for(q=0; q<query; q++){ cin >> a >> b; b--; if(px[a]==1){ ansx=x[b]+dx[a]; }else if(px[a]==2){ ansx=y[b]+dx[a]; }else if(px[a]==-1){ ansx=-x[b]+dx[a]; }else{ ansx=-y[b]+dx[a]; } if(py[a]==1){ ansy=x[b]+dy[a]; }else if(py[a]==2){ ansy=y[b]+dy[a]; }else if(py[a]==-1){ ansy=-x[b]+dy[a]; }else{ ansy=-y[b]+dy[a]; } cout << ansx << ' ' << ansy << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define REP(i, n) for(int (i) = 0; (i) < (n); ++(i)) #define REPR(i, n) for(int (i) = (n); (i) >= 0; --(i)) #define FOR(i, n, m) for(int (i) = (n); (i) < (m); ++(i)) template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return 1; } return 0; } constexpr int INF = 1e9; constexpr ll INFL = 1LL << 61; constexpr ll mod = 1e9+7; int main(){ int N; cin >> N; vector<ll> X(N), Y(N); REP(i, N){ cin >> X[i] >> Y[i]; } int M; cin >> M; vector<bool> need_swap(M+1, false); vector<vector<ll>> add(M+1, vector<ll>(2, 0)); vector<int> x_sign(M+1, 1), y_sign(M+1, 1); REP(i, M){ int op; cin >> op; x_sign[i+1] = x_sign[i]; y_sign[i+1] = y_sign[i]; need_swap[i+1] = need_swap[i]; add[i+1][0] = add[i][0]; add[i+1][1] = add[i][1]; if(op==1){ // (y, -x) add[i+1][0] = add[i][1]; add[i+1][1] = -add[i][0]; need_swap[i+1] = !need_swap[i]; swap(y_sign[i+1], x_sign[i+1]); y_sign[i+1] *= -1; } else if(op==2){ // (-y, x) add[i+1][0] = -add[i][1]; add[i+1][1] = add[i][0]; need_swap[i+1] = !need_swap[i]; swap(y_sign[i+1], x_sign[i+1]); x_sign[i+1] *= -1; } else if(op==3){ int p; cin >> p; // (p+p-x, y) add[i+1][0] = 2*p- add[i][0]; add[i+1][1] = add[i][1]; x_sign[i+1] *= -1; } else{ int p; cin >> p; // (x, p+p-y) add[i+1][0] = add[i][0]; add[i+1][1] = 2*p-add[i][1]; y_sign[i+1] *= -1; } } int Q; cin >> Q; REP(i, Q){ int A, B; cin >> A >> B; B--; ll x = X[B], y = Y[B]; if(need_swap[A]){ swap(x, y); } cout << add[A][0] + x_sign[A] * x << " " << add[A][1] + y_sign[A] * y << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 200200; int n, v[N*2], a[N], b[N]; priority_queue<int,vector<int>,greater<int> > Q; int main() { scanf("%d",&n); for (int i=1;i<=n*2;i++) scanf("%d",v+i); for (int i=1;i<=n;i++) { a[i] = max(v[n+1-i],v[n+i]); b[i] = min(v[n+1-i],v[n+i]); } for (int i=1;i<=n;i++) { if (i != 1) { if (b[i] > Q.top()) { Q.pop(); Q.push(b[i]); } } Q.push(a[i]); } long long sum = 0; for (int i=1;i<=n;i++) { sum += Q.top(); Q.pop(); } printf("%lld\n", sum); }
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; //template #define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define ALL(v) (v).begin(),(v).end() using ll=long long int; const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12; template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;} template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;} //end struct UnionFind{ vector<int> par; int n; UnionFind(){} UnionFind(int _n):par(_n,-1),n(_n){} int root(int x){return par[x]<0?x:par[x]=root(par[x]);} bool same(int x,int y){return root(x)==root(y);} int size(int x){return -par[root(x)];} bool unite(int x,int y){ x=root(x),y=root(y); if(x==y)return false; if(size(x)>size(y))swap(x,y); par[y]+=par[x]; par[x]=y; n--; return true; } }; template<unsigned mod=998244353>struct fp { using uint=unsigned; uint v; static uint get_mod(){return mod;} int inv() const{ int tmp,a=v,b=mod,x=1,y=0; while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y); if(x<0){x+=mod;} return x; } fp(ll x=0){init(x%mod+mod);} fp& init(uint x){v=(x<mod?x:x-mod); return *this;} fp operator-()const{return fp()-*this;} fp pow(ll t){fp res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;} return res;} fp& operator+=(const fp& x){return init(v+x.v);} fp& operator-=(const fp& x){return init(v+mod-x.v);} fp& operator*=(const fp& x){v=ll(v)*x.v%mod; return *this;} fp& operator/=(const fp& x){v=ll(v)*x.inv()%mod; return *this;} fp operator+(const fp& x)const{return fp(*this)+=x;} fp operator-(const fp& x)const{return fp(*this)-=x;} fp operator*(const fp& x)const{return fp(*this)*=x;} fp operator/(const fp& x)const{return fp(*this)/=x;} bool operator==(const fp& x)const{return v==x.v;} bool operator!=(const fp& x)const{return v!=x.v;} friend istream& operator>>(istream& is,fp& x){is>>x.v; return is;} friend ostream& operator<<(ostream& os,fp& x){os<<x.v; return os;} }; using Fp=fp<>; template<typename T>struct factorial { vector<T> Fact,Finv,Inv; factorial(int maxx){ Fact.resize(maxx); Finv.resize(maxx); Inv.resize(maxx); Fact[0]=Fact[1]=Finv[0]=Finv[1]=Inv[1]=1; rep(i,2,maxx){Fact[i]=Fact[i-1]*i;} Finv[maxx-1]=Fact[maxx-1].inv(); for(int i=maxx-1;i>=2;i--){Finv[i-1]=Finv[i]*i; Inv[i]=Finv[i]*Fact[i-1];} } T fact(int n,bool inv=0){if(n<0)return 0; return (inv?Finv[n]:Fact[n]);} T inv(int n){if(n<0)return 0; return Inv[n];} T nPr(int n,int r,bool inv=0){if(n<0||n<r||r<0)return 0; return fact(n,inv)*fact(n-r,inv^1);} T nCr(int n,int r,bool inv=0){if(n<0||n<r||r<0)return 0; return fact(n,inv)*fact(r,inv^1)*fact(n-r,inv^1);} }; int main(){ int n; cin>>n; vector<int> a(n); rep(i,0,n)cin>>a[i]; UnionFind uni(n); rep(i,0,n)uni.unite(i,a[i]-1); Fp res=Fp(2).pow(uni.n)-1; cout<<res<<'\n'; return 0; }
// E - Traveling Salesman among Aerial Cities // 典型: 巡回セールスマン問題 #include <bits/stdc++.h> using namespace std; using vi = vector<int>; #define rep(i,n) for(int i=0;i<(int)(n);++i) int main(){ int n; cin>>n; vi x(n), y(n), z(n); rep(i, n) cin>>x[i]>>y[i]>>z[i]; int m = 1<<n; vector<vi> dp(m, vi(n, 1'000'000'000)); dp[m-1][0] = 0; for(int S=m-2; S>=0; --S){ rep(v, n) rep(u, n){ if(S>>u & 1) continue; int d = max(0, z[u] - z[v]); d += abs(x[u]- x[v]) + abs(y[u]- y[v]); dp[S][v] = min(dp[S][v], dp[S | 1<<u][u] + d); } } cout<< dp[0][0] <<endl; }
#include<bits/stdc++.h> #define SORT(v) sort(v.begin(),v.end()) #define si(n) scanf("%d",&n) #define sii(n,m) scanf("%d %d",&n,&m) #define sl(n) scanf("%lld",&n) #define sll(n,m) scanf("%lld %lld",&n,&m) #define ss(cad) scanf("%s",cad) #define all(v) (v).begin(), (v).end() #define PB push_back #define fst first #define scn second #define DBG(x) cerr << #x << " = " << (x) << endl; #define M 1000000007 #define N_MAX 100010 using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<bool> vb; typedef vector<ll> vl; typedef pair<int,int> pi; typedef vector<pi> vp; int a[20], b[20], c[20]; int dp[1<<18][17]; int pre[18]; int dist(int x, int y){ return abs(a[y] - a[x]) + abs(b[y] - b[x]) + max(0, c[y] - c[x]); } int main(){ memset(dp, 0x3f3f3f3f, sizeof(dp)); int n; si(n); for(int i = 0; i < n; i++){ sii(a[i], b[i]); si(c[i]); pre[i] = (1<<i); } pre[n] = (1<<n); for(int mask = 1; mask < pre[n]; mask++){ for(int i = 0; i < n; i++){ if(mask&pre[i]){ int tmp = mask^pre[i]; if(tmp == 0) dp[mask][i] = dist(0, i); for(int p = 0; p < n; p++){ if(tmp&pre[p]) dp[mask][i] = min(dp[mask][i], dp[tmp][p] + dist(p, i)); } } } } printf("%d\n", dp[(1<<n)-1][0]); return 0; }