code_file1
stringlengths
87
4k
code_file2
stringlengths
82
4k
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { long long int N, C_SUNUKE; scanf("%lld %lld", &N, &C_SUNUKE); getchar(); vector<pair<int,int>> events; for (int i=0; i < N; i++) { int a, b, c; scanf("%d %d %d", &a, &b, &c); events.emplace_back(a-1, c); events.emplace_back(b, -c); getchar(); } sort(events.begin(), events.end()); long long int cost = 0, total_cost = 0, t = 0; for (auto [x,y] : events) { if (t != x) { total_cost += min(cost, C_SUNUKE) * (x-t); t = x; } cost += y; } cout << total_cost << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; bool ll_sqrt(ll x, ll& lower_bound, ll& upper_bound) { constexpr ll ll_max = numeric_limits<ll>::max(); bool first_boost = true; lower_bound = 0; upper_bound = x; while (upper_bound - lower_bound > 1) { if (first_boost) { ll guess = (ll)sqrt((double)x); lower_bound = max(guess - 1, (ll)0); upper_bound = lower_bound + 3; first_boost = false; } ll newval = (lower_bound + upper_bound) / 2; if ((newval != 0) && (newval > ll_max / newval)) // newval*newval becomes overflow upper_bound = newval; // because overflow means newval is too big else { ll newval_sqr = newval * newval; if (newval_sqr < x) lower_bound = newval; else upper_bound = newval; } } if ((upper_bound != 0) && (upper_bound > ll_max / upper_bound)) { if (lower_bound * lower_bound == x) upper_bound = lower_bound; } else { if (lower_bound * lower_bound == x) upper_bound = lower_bound; else if (upper_bound * upper_bound == x) lower_bound = upper_bound; } bool is_exact = (lower_bound == upper_bound); return is_exact; } ll ll_ceil(ll x, int digit); ll ll_floor(ll x, int digit); ll ll_floor(ll x, int digit) { if (x < 0) return -ll_ceil(-x, digit); ll div = 1; while (digit != 0) { div *= 10; digit--; } ll modval = x % div; ll ans = x - modval; return ans; } ll ll_ceil(ll x, int digit) { if (x < 0) return -ll_floor(-x, digit); ll div = 1; while (digit != 0) { div *= 10; digit--; } ll modval = x % div; ll ans = x - modval; if (modval != 0) ans += div; return ans; } int main() { ll N, C; cin >> N >> C; ll a[N]; ll b[N]; ll c[N]; map<ll, list<ll>> start; map<ll, list<ll>> stop; unordered_set<ll> visited; priority_queue<ll,vector<ll>,greater<ll>> q; for (ll i = 0; i < N; i++) { cin >> a[i] >> b[i] >> c[i]; start[a[i]].push_front(i); stop[b[i]].push_front(i); if(!visited.count(a[i])){ q.push(a[i]); visited.insert(a[i]); } if(!visited.count(b[i])){ q.push(b[i]); visited.insert(b[i]); } } ll ans = 0; ll payPday = 0; ll pre=0; while(!q.empty()){ ll day = q.top();q.pop(); ans+=min(payPday, C)*(day-pre-1); if(start.count(day)>0){ for(ll service:start[day]){ payPday+=c[service]; } } ans+=min(payPday, C); if(stop.count(day)>0){ for(ll service:stop[day]){ payPday-=c[service]; } } pre=day; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define ll long long using namespace std; //reverse(s.begin(),s.end()) ll gcd(ll a,ll b){ ll s=1,c; while(a&&b){ if((~a&1)&&(~b&1)) a>>=1,b>>=1,s<<=1; else if(~a&1)a>>=1; else if(~b&1)b>>=1; else if(a>b)a=a-b; else c=b-a,b=a,a=c; } if(!a)return b*s; if(!b)return a*s; } int main(){ ll n=1;cin>>n; ll k;ll ans = 6987268688401; cout<<ans; }
/* Basic Inclusion */ #define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; /* definition */ #define rep(i, N) for (ll i = 0; i < (ll)(N); i++) #define repp(i, N) for (ll i = 1; i <= (ll)(N); i++) #define per(i, N) for (ll i = (ll)(N)-1; i >= 0; i--) #define pper(i, N) for (ll i = (ll)(N); i > 0; i--) #define pub(n) push_back(n) #define pob(n) pop_back(n) #define all(v) (v).begin(), (v).end() #define grsort(v) sort((v).begin, (v).end, greater<>()) #define setpre(i) cout << fixed << setprecision((ll)(i)) #define tstr to_string #define bpop(n) __builtin_popcount(n) /* I am lazy XD */ #define co(ans) cout << (ans) #define out(ans) << (ans) #define margin << " " #define fin << endl #define enter cout << endl /* Common */ #define ll long long #define dd double #define cc char #define ss string ll cin_long_long(){ ll value; cin >> value; return value; } dd cin_double(){ dd value; cin >> value; return value; } cc cin_char(){ cc value; cin >> value; return value; } ss cin_string(){ ss value; cin >> value; return value; } #define cinl cin_long_long() #define cind cin_double() #define cinc cin_char() #define cins cin_string() #define mod 1000000007 #define inf 9223372036854775807 #define minf -9223372036854775807 #define pi 3.1415926535897932384626433832795028 ll bit(ll N){ return (1 << N); } /* template functions */ ll ctol(char c){ switch (c){ case '1': return 1; break; case '2': return 2; break; case '3': return 3; break; case '4': return 4; break; case '5': return 5; break; case '6': return 6; break; case '7': return 7; break; case '8': return 8; break; case '9': return 9; break; case '0': return 0; break; default: return 0; break; } } /* main functions*/ /* main */ int main(void){ ll N = cinl; vector<ll> A(N); vector<ll> note(N,1); rep(i,N) A[i] = cinl; rep(i,N){ if(A[i] <= 0 || A[i] > N){ co("No") fin; return 0; } else{ if(note[A[i]-1] == 0){ co("No") fin; return 0; } note[A[i]-1]=0; } } co("Yes") fin; } // /* fin */
#include<cstdio> #include<cstring> #include<algorithm> #include<vector> #include<set> using namespace std; typedef long long LL; const int N = 200010; int n; char a[N], player[N]; int w[N]; int f[N][7]; int dfs(int u, int k) { if(f[u][k] != -1) return f[u][k]; if(u == n) { if(player[u] == 'T') { if((k + w[u]) % 7 == 0) return f[u][k] = 1; if(k % 7 == 0) return f[u][k] = 1; return f[u][k] = 0; } else { if((k + w[u]) % 7) return f[u][k] = 0; if(k % 7) return f[u][k] = 0; return f[u][k] = 1; } } if(player[u] == 'T') { if(dfs(u + 1, (k + w[u]) * 10 % 7)) return f[u][k] = 1; if(dfs(u + 1, k * 10 % 7)) return f[u][k] = 1; return f[u][k] = 0; } else { if(!dfs(u + 1, (k + w[u]) * 10 % 7)) return f[u][k] = 0; if(!dfs(u + 1, k * 10 % 7)) return f[u][k] = 0; return f[u][k] = 1; } } int main() { scanf("%d%s%s", &n, a + 1, player + 1); for(int i = 1; i <= n; i ++) w[i] = a[i] - '0'; memset(f, -1, sizeof f); if(dfs(1, 0)) puts("Takahashi"); else puts("Aoki"); return 0; }
#include <bits/stdc++.h> using namespace std; #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define input_output freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); template <typename Arg1> void prn(Arg1&& arg1) { cout<<arg1<<"\n";} template <typename Arg1, typename... Args> void prn(Arg1&& arg1, Args&&... args) { cout<<arg1<<" "; prn(args...); } template <typename Arg1> void prs(Arg1&& arg1) { cout<<arg1<<" ";} template <typename Arg1, typename... Args> void prs(Arg1&& arg1, Args&&... args) { cout<<arg1<<" "; prs(args...); } template <typename Arg1> void read(Arg1&& arg1) { cin>>arg1; } template <typename Arg1, typename... Args> void read(Arg1&& arg1, Args&&... args) { cin>>arg1; read(args...); } #define int long long #define all(ds) ds.begin(), ds.end() #define uniq(v) (v).erase(unique(all(v)),(v).end()) #define gcd(x,y) __gcd(x,y) #define rep(i,a,b) for(int i=a;i<b;i++) #define precise(x) cout<<fixed<<setprecision(x) #define endl "\n" const long long INF = 1e18; const int32_t MOD = 1e9+7; const int N = 5e5+5; int n, m, k, q, r, l, x, y, z; int a[N], b[N], c[N]; string s, t; int ans = 0; void solve(){ int n; string s, x; read(n,s,x); vector<int>dp(7); dp[0] = 1; int ten = 1; for(int i = n-1; i >= 0; --i){ vector<int> old(7); swap(old, dp); // rem = (rem*10)%7; for(int j = 0; j < 7; ++j){ int nj = (ten * (s[i]-'0') + j)%7; if(x[i] == 'T'){ dp[j] = old[j] | old[nj]; } else{ dp[j] = old[j] & old[nj]; } } ten = (ten*10)%7; } if(dp[0] == 1) { prn("Takahashi"); } else{ prn("Aoki"); } } signed main() { #ifndef ONLINE_JUDGE input_output #else fastio #endif #ifdef SIEVE sieve(); #endif #ifdef NCR init(); #endif int t = 1; // cin>>t; while(t--){ solve(); } return 0; }
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> //using namespace __gnu_pbds; using namespace std; #define ff first #define ss second #define ll long long #define pb push_back #define mii map<int,int> #define pqb priority_queue<int> #define pqs priority_queue<int,vi,greater<int> > #define mod 1000000007 #define sp(x,y) fixed<<setprecision(y)<<x #define t(x) int x; cin>>x; while(x--) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define setbits(x) __builtin_popcountll(x) #define zerobits(x) __builtin_ctzll(x) #define fo(i,n) for(i=0;i<n;i++) #define PI 3.1415926535897932384626 #define vinput(p,x) for(int i=0;i<x;i++) cin>>p[i].ff>>p[i].ss; typedef pair<int, int> pii; typedef pair<ll, ll> pl; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpii; typedef vector<pl> vpl; typedef vector<vi> vvi; typedef vector<vl> vvl; //typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; int mpow(int base, int exp) { base %= mod; int result = 1; while (exp > 0) { if (exp & 1) result = ((ll)result * base) % mod; base = ((ll)base * base) % mod; exp >>= 1; } return result; } void SOE(int n) { bool pr[n+1]; memset(pr, true, sizeof(pr)); for (int p=2; p*p<=n; p++) { if (pr[p] == true) { for (int i=p*2; i<=n; i += p) pr[i] = false; } } for (int p=2; p<=n; p++) if (pr[p]) cout << p << " "; } bool isP(int n) { bool flag=1; for (int i = 2; i <= sqrt(n); i++) { if (n % i == 0) { flag = 0; break; } } if(n<=1) flag=0; else if(n==2) flag=1; return flag; } double convt(string s,string a) { double x=(s[0]-'0')*10 + (s[1]-'0'); x=(double)((int)x%12); if(a[0]=='P') x+=12; double y=(s[3]-'0')*10 + (s[4]-'0'); x=x+(y/100); return x; } void aks() { ll a, b,c ,d; cin>>a>>b>>c>>d; ll ans=-300; for(ll i=a;i<=b;i++) for(ll j=c;j<=d;j++) { if(ans<=i-j) ans=i-j; } cout<<ans<<"\n"; } int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); srand(chrono::high_resolution_clock::now().time_since_epoch().count()); // code here // t(x) aks(); return 0; }
#include<iostream> #include<iomanip> #include<vector> #include<algorithm> #include<string> #include<cmath> #include<map> #include<set> #include<queue> #include<cstring> #include<tuple> #define rep(i,n) for(int i = 0;i < (n);i++) using namespace std; using ll = long long; const int INF = 1 << 30; int main(){ int a,b,c,d; cin >> a >> b; cin >> c >> d; cout << b - c<< endl; }
#include <bits/stdc++.h> int ri() { int n; scanf("%d", &n); return n; } #define MOD 1000000007 int main() { int n = ri(); int a[n]; for (auto &i : a) i = ri(); std::sort(a, a + n); int prev = 0; int res = 1; for (auto i : a) { res = (int64_t) res * (1 + i - prev) % MOD; prev = i; } printf("%d\n", res); return 0; }
/* author: madhav_1999 aka orthodoxparadox 18 April 2021 at 5:38 PM */ #include <bits/stdc++.h> #include <ext/pb_ds/detail/standard_policies.hpp> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define dbl long double #define int ll #define ll long long #define pii pair<int, int> #define len(x) (int) x.size() #define rev(a) reverse(all(a)) #define oiint ostream_iterator<int>(cout, " ") #define pb push_back #define mp make_pair #define ff first #define ss second #define endl '\n' #define all(a) a.begin(), a.end() #define initialise(a, x) memset(a, x, sizeof(a)) #define onlyunique(v) v.erase(unique(all(v)), v.end()); //only for sorted vector #define inf 2e18 #pragma GCC optimize ("O3") #pragma GCC optimize ("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define _CRT_SECURE_NO_WARNINGS #ifdef MADHAV #define dbg(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << endl;} template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " "; __f(comma + 1, args...);} #else #define dbg(...) 42 #endif template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(int i=0;i<(int)v.size();++i) x<<v[i]<<" ";return x;} template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;} template <typename X> ostream& operator << (ostream& x,const multiset<X>& v){for(auto it:v) x<<it<<" ";return x;} template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;} template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; } typedef tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); struct pair_hash {inline std::size_t operator()(const std::pair<int, int> & v) const {return v.first*31+v.second;}}; const int MOD = 1e9 + 7; int takemod(int a, int mod = MOD){a%=mod;if(a<0)a+=mod;return a;} int fast_exp(int base, int expo, int mod = MOD) { int res=1; while(expo>0) { if(expo&1) res=(res*base)%mod; base=(base*base)%mod; expo>>=1;} return res;} int modinv(int a, int mod = MOD){return takemod(fast_exp(takemod(a, mod), mod-2, mod), mod);} void solve() { int n; cin >> n; int a[n]; for(int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n, greater<int>()); int ans = 1; for(int i = 1; i < n; i++) { ans = takemod(ans * (a[i - 1] - a[i] + 1)); } ans = takemod(ans * (a[n - 1] + 1)); cout << ans << endl; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifdef MADHAV freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("error.txt", "w", stderr); #endif clock_t t1, t2; t1 = clock(); int tt = 1; // cin >> tt; while(tt--) solve(); #ifdef MADHAV t2 = clock(); cout << "\n\ntime taken: " << (t2-t1)/(dbl)CLOCKS_PER_SEC; #endif return 0; }
#include<bits/stdc++.h> using namespace std; int main() { long long N, A, P, X, s=0, a[100000]; cin>>N; for(int i=0; i<N; i++) { cin>>A>>P>>X; if(X>A) { a[i]=P; } else { a[i]=0; } } for(int i=0; i<N; i++) { s=s+a[i]; } if(s==0) { cout<<"-1"<<endl; } else { sort(a, a+N); for(int i=0; i<N; i++) { if(a[i]>0) { cout<<a[i]<<endl; i=N; } } } return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long int int main(){ int n; cin>>n; ll a[n]; ll p[n]; ll x[n]; for(int i=0;i<n;i++){ cin>>a[i]>>p[i]>>x[i]; } ll ans = INT_MAX; for(int i=0;i<n;i++){ int diff = x[i]-a[i]; if(diff>0){ ans = min(ans,p[i]); } } if(ans==INT_MAX)ans = -1; cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define vi vector<int> #define vll vector<ll> #define pii pair<int,int> #define pll pair<ll,ll> #define vpi vector<pii> #define vpll vector<pll> #define endl '\n' #define fi first #define se second #define pb push_back #define eb emplace_back #define em emplace #define mp make_pair #define rep(i, n) for (ll i = 0; i < n; ++i) #define rep2(i, n, m) for (ll i = n; i <= m; ++i) #define rep3(i, n, m) for (ll i = n; i >= m; --i) #define all(v) v.begin(), v.end() #define si(v) int(v.size()) #define UNIQUE(v) sort(all(v)), v.erase(unique(all(v)),v.end()) #define INT(...) int __VA_ARGS__; IN(__VA_ARGS__); #define LL(...) ll __VA_ARGS__; IN(__VA_ARGS__); #define STR(...) string __VA_ARGS__; IN(__VA_ARGS__); #define CHR(...) char __VA_ARGS__; IN(__VA_ARGS__); #define LD(...) ld __VA_ARGS__; IN(__VA_ARGS__); /* const ll mod = 1e9 + 7; */ const ll mod = 998244353; const ll infll = (1LL << 62) - 1; const ll inf = (1LL << 30) - 1; template<class S, class T> inline bool chmax(S &a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class S, class T> inline bool chmin(S &a, T b) { if (a > b) { a = b; return 1; } return 0; } template<class T> using pq = priority_queue<T>; template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>; void IN() {} template <class Head, class... Tail> void IN(Head &head, Tail &... tail) { cin >> head; IN(tail...); } class mint { private: ll x; public: constexpr mint(const ll x = 0) noexcept : x((x % mod + mod) % mod) {} constexpr ll value() noexcept { return x; } constexpr mint operator += (const mint right) noexcept { if ((x += right.x) >= mod) x -= mod; return *this; } constexpr mint operator -= (const mint right) noexcept { if ((x += mod - right.x) >= mod) x -= mod; return *this; } constexpr mint operator *= (const mint right) noexcept { x = x * right.x % mod; return *this; } constexpr mint operator /= (const mint right) noexcept { return *this *= right.inv(); } constexpr mint operator + (const mint right) const noexcept { return mint(*this) += right; } constexpr mint operator - (const mint right) const noexcept { return mint(*this) -= right; } constexpr mint operator / (const mint right) const noexcept { return mint(*this) /= right; } constexpr mint operator * (const mint right) const noexcept { return mint(*this) *= right; } constexpr mint inv() const { return pow(mod-2); } constexpr mint pow(ll n) const { if (n == 0) return 1; mint a = pow(n>>1); a *= a; if (n & 1) a *= *this; return a; } }; signed main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << fixed << setprecision(15); LL(a, b, c); mint aa = (a * (a + 1)) / 2; mint bb = (b * (b + 1)) / 2; mint cc = (c * (c + 1)) / 2; cout << (aa * bb * cc).value() << endl; }
/* * @date:2021-04-24 20:37:33 * @source:https://atcoder.jp/contests/abc199/tasks/abc199_f */ #include <bits/stdc++.h> using namespace std; const int MAXN = 100 + 5; const int MOD = 1e9 + 7; int N, M, K; long long A[MAXN]; int Num[MAXN]; struct Matrix { long long A[MAXN][MAXN]; Matrix() { memset(A, 0, sizeof A); } Matrix operator * (const Matrix &x) const { Matrix c = Matrix(); for (int i = 1; i <= N; ++i) { for (int j = 1; j <= N; ++j) { for (int k = 1; k <= N; ++k) { c.A[i][j] = (c.A[i][j] + A[i][k] * x.A[k][j] % MOD) % MOD; } } } return c; } } a; long long poww(long long x, int t) { long long res = 1; for (; t; t >>= 1) { if (t & 1) res = res * x % MOD; x = x * x % MOD; } return res; } Matrix poww(Matrix &x, int t) { Matrix res = x; for (--t; t; t >>= 1) { if (t & 1) res = res * x; x = x * x; } return res; } int main() { scanf("%d%d%d", &N, &M, &K); for (int i = 1; i <= N; ++i) scanf("%lld", &A[i]); if (!K) { for (int i = 1; i <= N; ++i) { printf("%lld\n", A[i]); } return 0; } long long p = poww(M, MOD - 2), two = poww(2, MOD - 2); for (int i = 1, u, v; i <= M; ++i) { scanf("%d%d", &u, &v); ++Num[u], ++Num[v]; a.A[u][v] = a.A[v][u] = p * two % MOD; } for (int i = 1; i <= N; ++i) { a.A[i][i] = p * (M - Num[i] + two * Num[i]) % MOD; } a = poww(a, K); for (int i = 1; i <= N; ++i) { long long x = 0; for (int j = 1; j <= N; ++j) { x = (x + A[j] * a.A[i][j]) % MOD; } printf("%lld\n", x); } return 0; }
#include <iostream> #include <cmath> using namespace std; int main() { int N; cin >> N; int x0, y0, xn, yn; cin >> x0 >> y0; cin >> xn >> yn; double pi_n = 2.0 * M_PI / static_cast<double>(N); double cx = static_cast<double>(x0 + xn) / 2.0; double cy = static_cast<double>(y0 + yn) / 2.0; double x1 = x0 - cx; double y1 = y0 - cy; double xx1 = cos(pi_n) * x1 - sin(pi_n) * y1; double yy1 = sin(pi_n) * x1 + cos(pi_n) * y1; x1 = xx1 + cx; y1 = yy1 + cy; printf("%.11f %.10f\n", x1, y1); return 0; }
#include <math.h> #include <algorithm> #include <iomanip> #include <iostream> #include <string> #include <vector> using namespace std; int main() { int N; cin >> N ; vector<int> X(N); long long M=0, C=0; long double U = 0.0; for (int i = 0; i < N; i++){ int temp; cin >> temp; M += abs(temp); U += pow(abs(temp), 2); if (C < abs(temp)) C = abs(temp); } U = pow(U, 0.5); cout << M << endl; cout << setprecision(20) << fixed << U << endl; cout << C << endl; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define nl "\n" #define sp " " void solve() { int n; cin>>n; int arr[n]; for(int i=0;i<n;i++) { cin>>arr[i]; } int arr1[n]={0}; for(int i=0;i<n;i++) { arr1[arr[i]-1]++; } for(int i=0;i<n;i++) { if(arr1[i]!=1) { cout<<"No"<<nl; return; } } cout<<"Yes"<<nl; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll t; t = 1; //cin>>t; while(t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using db = long double; using vi = vector<int>; using vl = vector<ll>; using pi = pair<int, int>; using pl = pair<ll, ll>; template<typename T> using pqg = priority_queue<T, vector<T>, greater<T> >; #define FOR(i, a, n) for(int i=(a); i<(n); ++i) #define ROF(i, a, n) for(int i=(n)-1; i>=(a); --i) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) int((x).size()) #define ins insert #define pb push_back #define fi first #define se second #define lb lower_bound #define ub upper_bound #define endl '\n' mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template<typename T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template<typename T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } #define ts to_string string ts(char c) { return string(1, c); } string ts(const char* s) { return (string)s; } string ts(const string& s) { return '"' + s + '"'; } string ts(bool b) { return (b ? "true" : "false"); } string ts(vector<bool> v) { string res = "{"; FOR(i, 0, sz(v)) res += char('0' + v[i]); res += "}"; return res; } template <size_t SZ> string ts(bitset<SZ> b) { string res; FOR(i, 0, SZ) res += char('0' + b[i]); return res; } template <typename A, typename B> string ts(pair<A, B> p); template <typename A> string ts(A v) { bool first = 1; string res = "{"; for (const auto& x: v) { if (!first) res += ", "; first = 0; res += ts(x); } res += "}"; return res; } template <typename A, typename B> string ts(pair<A, B> p) { return "(" + ts(p.fi) + ", " + ts(p.se) + ")"; } void dbgOut() { cerr << "]" << endl; } template <typename H, typename... T> void dbgOut(H h, T... t) { cerr << ts(h); if (sizeof...(t)) cerr << ", "; dbgOut(t...); } #ifdef LOCAL #define dbg(...) cerr << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", dbgOut(__VA_ARGS__) #else #define dbg(...) 0 #endif const int MOD = 1e9+7; // 998244353; const ll INF = 1e18; const int MX = 2e5+5; void solve() { int n; cin >> n; vi a(n); FOR(i, 0, n) cin >> a[i]; sort(all(a)); FOR(i, 0, n) { if (a[i] != i + 1) { cout << "No" << endl; return; } } cout << "Yes" << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); #ifdef LOCAL auto begin = std::chrono::high_resolution_clock::now(); #endif solve(); #ifdef LOCAL auto end = std::chrono::high_resolution_clock::now(); cerr << "\nExecution time: " << std::chrono::duration_cast<std::chrono::duration<double>> (end-begin).count() << " seconds\n"; #endif }
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0;i<(n);i++) #define ALL(v) v.begin(),v.end() using ll=long long; ll d[1234567]; signed main(){ ll ans=0; ll l,r;cin>>l>>r; for(ll g=2;g<=r;g++){ d[g]++; if(d[g]){ ll A=(r/g-(l-1)/g)*(r/g-(l-1)/g); ans+=d[g]*A; for(int i=2;g*i<=r;i++)d[g*i]-=d[g]; } if(g>=l){ ans-=((r/g-(l-1)/g)*2-1); } } cout<<ans<<endl; } /* 4,4 4,6 6,4 6,6 6,6 -4,4 */
//header{{{ #pragma GCC optimize("Ofast") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/tag_and_trait.hpp> #include <ext/pb_ds/trie_policy.hpp> using namespace __gnu_pbds; using namespace std; #define rep(i,n) for(int i=0;i<(n);++i) #define reps(i,n) for(int i=1;i<=(n);++i) #define all(x) begin(x),end(x) #define Fixed fixed << setprecision(12) #define int int_fast64_t using pii = pair<int,int>; constexpr int INF = 0x3f3f3f3f; constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL; constexpr int mod1 = 1e9+7; constexpr int mod2 = 998244353; template <class Func> class FixPoint : Func { public: explicit constexpr FixPoint(Func&& f) noexcept : Func(forward<Func>(f)) {} template <class... Args> constexpr decltype(auto) operator()(Args&&... args) const { return Func::operator()(*this, std::forward<Args>(args)...); } }; template <class Func> static inline constexpr decltype(auto) makeFixPoint(Func&& f) noexcept { return FixPoint<Func>{forward<Func>(f)}; } template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); } template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); } template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >; template <class T> using max_heap = priority_queue<T>; template <class A, class B> using umap = unordered_map<A,B>; template <class T> using Set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template <class K, class V> using Umap = gp_hash_table<K, V>; using Trie = trie<string, null_type, trie_string_access_traits<>, pat_trie_tag, trie_prefix_search_node_update>; inline int square(int a){ return a * a;} inline int updiv(int a,int b){ return (a + b - 1) / b; } constexpr int dx[] = {1,0,-1,0,1,1,-1,-1}; constexpr int dy[] = {0,-1,0,1,1,-1,-1,1}; //}}} //}}} signed main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); cout.setf(ios_base::fixed); cout.precision(10); int n, cnt = 0; string s; cin >> n >> s; for(int i = 0; i < n; ++i){ int a, t, c, g; a = t = c = g = 0; for(int j = i; j < n; ++j){ a += (s[j] == 'A'); t += (s[j] == 'T'); c += (s[j] == 'C'); g += (s[j] == 'G'); cnt += (a == t && c == g); } } cout << cnt << '\n'; return 0; }
#include<iostream> #include<vector> #include<algorithm> #include<set> #include<map> #include<queue> #include<cmath> #include<iomanip> #include<cstring> #include<complex> #include<cstdio> #define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1; #define fi first #define se second #define pb push_back #define pii pair<int,int> #define ppi pair<pii,int> #define pip pair<int,pii> #define ll long long #define pll pair<ll,ll> #define rep(i,n) for(int i=0;i<n;i++) #define repd(i,n) for(int i=n-1;i>=0;i--) #define inf 1000000001 #define inf1 1000000000000000001 #define mod 1000000007 #define pie 3.14159265358979323846 #define N 100005 #define mid(l,r) l+(r-l)/2 #define removeduplicates(vec) vec.erase( unique( vec.begin(), vec.end() ), vec.end() ) #define memset1(v) memset(v,-1,sizeof(v)) #define memset0(v) memset(v,0,sizeof(v)) using namespace std; int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1}; int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1}; void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;} ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);} void solve(){ map<int,vector<int>>id; int n,m; cin>>n>>m; for(int i=0;i<m;i++){ int x,y; cin>>x>>y; id[x].pb(y); } map<int,int>vis; vis[n]=1; for(auto p:id){ int x=p.fi; map<int,int>vis1; for(int y:p.se){ if(vis.find(y+1)!=vis.end())vis1[y]=1; if(vis.find(y-1)!=vis.end())vis1[y]=1; } for(int y:p.se)if(vis.find(y)!=vis.end())vis.erase(y); for(pii p1:vis1)vis[p1.fi]=1; } cout<<vis.size(); } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t=1; //cin>>t; while(t--){ solve(); } }
#include <bits/stdc++.h> #define INF LLONG_MAX/2 #define rep(i,n) for(int i = 0; i <(n) ; i++) using namespace std; typedef long long ll; typedef __int128_t LL; //入出力では使えないことに注意が必要. 計算過程で途中64bitを超える可能性があるときに使う typedef pair<ll,ll> pll; #define all(x) (x).begin(), (x).end() 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; } // vector<vector<ll> > dp(N+1, vector<ll>(2, 0)); // vector<vector<vector<ll> > > dp(N, vector<vector<ll> >(M, vector<ll>(L, 0))); int main(){ ll N, M; cin >> N >> M; ll offset = 300010; vector<vector<bool> > dp(2, vector<bool>(600020, false)); vector<pll> p; for(ll i=0; i<M; i++){ ll x, y; cin >> x >> y; y-=N; if(y<-200010 || 200010<y){ continue; } p.push_back(pll(x,y)); } if(p.size()==0){ cout << 1 << endl; return 0; } sort(all(p), greater<pll>()); dp[0][0+offset] = true; dp[1][0+offset] = true; ll now_x= 0; while(p.size()>0) { pll point = p.back(); p.pop_back(); now_x = point.first; vector<ll> ys; ys.push_back(point.second); while(p.size()>0 && p.back().first==now_x){ ys.push_back(p.back().second); p.pop_back(); } for(ll pawn: ys){ dp[1][pawn+offset] = dp[0][pawn-1+offset] || dp[0][pawn+1+offset]; } dp[0] = dp[1]; } ll ans = 0; for(ll i = 0; i<dp[0].size(); i++){ ans += dp[0][i]; } cout << ans << endl; return 0; }
//By Vasu Agrawal #include<iostream> #include<bits/stdc++.h> typedef long long int ll; #define pb push_back #define pob pop_back #define mk make_pair #define fr first #define sc second #define pu push #define ins insert #define mod 1000000007 #define mem(a,val) memset(a,val,sizeof(a)) #define V(a) vector<a> #define pp pair<ll,ll> #define lb(a,n) lower_bound(a.begin(),a.end(),n)-a.begin() #define ub(a,n) upper_bound(a.begin(),a.end(),n)-a.begin() #define F(i,n) for(ll i=0;i<n;i++) #define in(a,n) F(i,n) cin>>a[i] #define in1(a,n) f(i,n) cin>>a[i] #define out1(a,n); f(i,n) cout<<a[i]<<" ";cout<<endl; #define out(a,n); F(i,n) cout<<a[i]<<" ";cout<<endl; #define f(i,n) for(ll i=1;i<=n;i++) #define all(a) a.begin(),a.end() #define vasu2907 ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); using namespace std; bool isprime(ll n) //Time Complexity--->sqrt(n) { if (n <= 1) return false; if (n <= 3) return true; if (n%2 == 0 || n%3 == 0) return false; for (int i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0) return false; return true; } vector<ll> prime; void sieve(ll n) { bool bakh[n+1];memset(bakh, true, sizeof(bakh)); for (ll p=2; p*p<=n; p++) { if (bakh[p] == true) { for (ll i=p*p; i<=n; i += p) bakh[i] = false; } } for (ll p=2; p<=n; p++) if (bakh[p]) prime.pb(p); }//Taken from https://www.geeksforgeeks.org/eulers-totient-function-for-all-numbers-smaller-than-or-equal-to-n/ ll eulertotient(ll z) //Time--->n/logn { ll fac=z; for(ll i=0;prime[i]*prime[i]<=z;i++) { if(z%prime[i]==0) { fac-=(fac/prime[i]); while(z%prime[i]==0) z/=prime[i]; } } if(z>1) fac-=(fac/z); return fac; } //Taken from https://www.geeksforgeeks.org/modular-exponentiation-power-in-modular-arithmetic/ ll power(ll x,ll y,ll p) { ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res*x) % p; y = y>>1; x = (x*x) % p; }return res; } //Taken from https://www.geeksforgeeks.org/euclidean-algorithms-basic-and-extended/ ll gcd(ll a,ll b) { if (a == 0) return b; return gcd(b % a, a); } ll lcm(ll a,ll b) { ll g=gcd(a,b); ll ans=(a*b)/g; return ans; } //Taken from https://www.geeksforgeeks.org/multiplicative-inverse-under-modulo-m/ ll modInverse(ll a, ll m) { ll hvf=gcd(a,m); if(hvf==1) return power(a,m-2,m); return -1;} void multiply(ll F[2][2], ll M[2][2]) { ll x = F[0][0]*M[0][0] + F[0][1]*M[1][0]; ll y = F[0][0]*M[0][1] + F[0][1]*M[1][1]; ll z = F[1][0]*M[0][0] + F[1][1]*M[1][0]; ll w = F[1][0]*M[0][1] + F[1][1]*M[1][1]; F[0][0] = x; F[0][1] = y; F[1][0] = z; F[1][1] = w; } void powermat(ll F[2][2], ll n) { if( n == 0 || n == 1) return; ll M[2][2] = {{1,1},{1,0}}; powermat(F, n/2); multiply(F, F); if (n%2 != 0) multiply(F, M); } ll fib(ll n) { ll F[2][2] = {{1,1},{1,0}}; if (n == 0) return 0; powermat(F, n-1); return F[0][0]; } V(ll) merge(V(ll) v1,V(ll) v2) { V(ll) temp; ll i=0,j=0; while(i<v1.size() && j<v2.size()) { if(v1[i]<v2[j]) temp.pb(v1[i]),i++; else temp.pb(v2[j]),j++; } while(i<v1.size()) temp.pb(v1[i]),i++; while(j<v2.size()) temp.pb(v2[j]),j++; return temp; } //id=(id&(id+1))-1 //ll fetch(ll id) //{ //} //id=(id|(id+1)) //void update(ll id) //{ //} //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); // Code Starts Here int main() { vasu2907; ll n,a=0,b=0,ans=0; cin>>n; string st; cin>>st; map<char,ll> mp; mp['A']=0, mp['T']=1,mp['C']=2,mp['G']=3; ll ar[4]; F(i,n) { a=0;b=0; mem(ar,0); for(ll j=i;j<n;j++) { ar[mp[st[j]]]+=1; if(ar[0]==ar[1] && ar[2]==ar[3]) ans+=1; } } cout<<ans<<endl; }
#include <cstdio> using namespace std; const int MAX_N = 5010; int A[MAX_N], Prefix[4][MAX_N]; int N; char GetChar() { char c; do c = getchar(); while (c == ' ' || c == '\n' || c == '\r'); return c; } void ReadA() { const char *s = "ATCG"; for (int i = 1; i <= N; i++) { char c = GetChar(); for (int j = 0; j < 4; j++) if (c == s[j]) A[i] = j; } } void GetPrefix() { for (int i = 1; i <= N; i++) { for (int j = 0; j < 4; j++) Prefix[j][i] = Prefix[j][i - 1]; Prefix[A[i]][i]++; } } int GetAns() { int ans = 0; for (int i = 1; i < N; i++) for (int j = i + 1; j <= N; j++) if ( Prefix[0][j] - Prefix[0][i - 1] == Prefix[1][j] - Prefix[1][i - 1] && Prefix[2][j] - Prefix[2][i - 1] == Prefix[3][j] - Prefix[3][i - 1]) ans++; return ans; } int main() { #ifdef _DEBUG freopen("input.txt", "r", stdin); #endif scanf("%d", &N); ReadA(); GetPrefix(); printf("%d\n", GetAns()); 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>; const int inf = 100100101; const ll ll_inf = 1e9+7; const int mod = 1000000007; template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; } int main(){ int n, x; cin >> n >> x; vector<int> v(n), p(n); rep(i,n) cin >> v[i] >> p[i]; x *= 100; double al = 0; rep(i,n) { al += v[i]*p[i]; if(al > x) { cout<<i+1<<endl; return 0; } } cout<<-1<<endl; return 0; }
#include <bits/stdc++.h> #include <time.h> #include <queue> #define ll long long int #define mp make_pair #define ff first #define ss second #define forr(i,a,n) for(ll i=a;i<n;i++) #define ford(i,a,n) for(ll i=n-1;i>=a;i--) #define all(v) v.begin(),v.end() #define testc ll ts;\ cin>>ts;\ while(ts--) #define arn ll n;\ cin>>n;\ ll a[n];\ forr(i,0,n)cin>>a[i];\ #define arr(a,n) ll a[n];\ forr(i,0,n)cin>>a[i];\ #define sss <<" "<< #define nnn <<"\n" #define nl cout<<"\n"; #define prtitr(v) for(auto itr=v.begin(); itr!=v.end() ; itr++)cout<<*itr<<" "; #define fitr(v) for(auto itr=v.begin(); itr!=v.end() ; itr++) using namespace std; ll M=1e9+7; ll cdiv(ll a,ll b){ return (a%b==0)?a/b:a/b+1; } ll myMod(ll a, ll b){ ll r = a % b; return r < 0 ? r + b : r; } ll ModPow(ll a,ll b,ll M) { if(M==1)return 0; a%=M; ll ans=1,t=1; while(t>0&&t<=b) { if(t&b) { ans*=a; ans%=M; } t<<=1; a*=a; a%=M; } return ans; } ll Pow(ll a,ll b) { if(M==1)return 0; ll ans=1,t=1; while(t>0&&t<=b) { if(t&b) { ans*=a; } t<<=1; a*=a; } return ans; } ll gcd(ll a, ll b) { if (a == 0) return b; return gcd(b % a, a); } int countSetBits(int n) { int count = 0; while (n > 0) { count++; n &= (n-1); } return count; } // Function that return count of // flipped number int FlippedCount(int a, int b) { // Return count of set bits in // a XOR b return countSetBits(a^b); } struct Point{ int x,y; }; bool isPrime(ll n){ if (n <= 1) return false; for (ll i = 2; i*i <= n; i++) if (n % i == 0) return false; return true; } ll modInverse(ll n, ll p) { return ModPow(n, p - 2, p); } ll nCrModP(ll n, ll r, ll p) { if (n < r) return 0; if (r == 0) return 1; ll fac[n + 1]; fac[0] = 1; for (int i = 1; i <= n; i++) fac[i] = (fac[i - 1] * i) % p; return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n,x; cin>>n>>x; ll v[n], p[n]; forr(i,0,n)cin>>v[i]>>p[i]; ll ans=-1; ll s=0; forr(i,0,n){ s+=v[i]*p[i]; if(s>x*100){ ans=i; break; } } if(ans!=-1)cout<<ans + 1 nnn; else cout<< - 1 nnn; return 0; }
#include <bits/stdc++.h> using namespace std; const long long INF = 1LL << 60; // 十分大きな値に typedef long long ll; typedef long double ld; int main() { ll N, K; cin >> N >> K; for (ll i=0; i<K; i++) { if (N%200==0) { N /= 200; } else { N *= 1000; N += 200; } } cout << N << endl; }
#include "bits/stdc++.h" using namespace std; // 定義 typedef long long ll; typedef pair<ll, ll> P; #define ALL(x) (x).begin(),(x).end() #define REP(i, n) for(ll i = 0 ; i < (ll)n ; ++i) #define REPN(i, m, n) for(ll i = m ; i < (ll)n ; ++i) #define VL vector<ll> #define VVL vector<vector<ll>> #define VVVL vector<vector<vector<ll>>> #define INF (ll)2e9 #define INF_LL 1LL<<60 //#define MOD 998244353 #define MOD 1000000007 ll Ceil(ll val, ll div) { return (val + div - 1) / div; } ll CeilN(ll val, ll div) { return Ceil(val, div) * div; } ll FloorN(ll x, ll n) { return (x - x % n); } bool IsOdd(ll x) { return ((x & 1) == 1); } bool IsEven(ll x) { return ((x & 1) == 0); } void Solve() { ll N; cin >> N; ll cnt = 0; vector<P> two; ll multi = 1; while (multi <= N) { two.emplace_back(cnt, multi); multi *= 2; cnt++; } VL ans; for (auto t : two) { ll b = N / t.second; ll a = t.first; ll c = N % t.second; ll ansOne = a + b + c; ans.emplace_back(ansOne); } sort(ALL(ans)); cout << ans.front() << endl; } // メイン int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(15); Solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define R cin>> #define ll long long #define ln cout<<endl #define in(a) insert(a) #define pb(a) push_back(a) #define pd(a) printf("%.10f\n",a) #define mem(a) memset(a,0,sizeof(a)) #define all(c) (c).begin(),(c).end() #define iter(c) __typeof((c).begin()) #define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--) #define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++) #define rep(i,n) REP(i,0,n) #define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++) ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;} template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);} template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;} const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1}; typedef pair<ll,ll> P; vector<string> C(vector<string> s) { ll n=s.size(); rep(i,n)REP(j,i+1,n) swap(s[i][j],s[j][i]); return s; } ll n,m; string s[1000]; ll calc(vector<string> t) { ll cnt=0; rep(k,m) { ll f=0; rep(l,2) { rep(i,n) { rep(j,n) { if(t[i].substr(0,s[k].size())==s[k]) f=1; rotate(t[i].begin(),t[i].begin()+1,t[i].end()); } } t=C(t); } cnt+=f; } return cnt; } vector<string> ans; ll MM; void solve(vector<string> t) { ll d=calc(t); if(MM<d) { MM=d; ans=t; } rep(k,5) { random_shuffle(all(t)); rep(i,n) rotate(t[i].begin(),t[i].begin()+rand()%n,t[i].end()); ll d=calc(t); if(MM<d) { MM=d; ans=t; } } } void Main() { srand((unsigned)time(NULL)); cin >> n >> m; rep(i,m) R s[i]; vector<string> v[15]; rep(i,m) v[s[i].size()].pb(s[i]); rep(e,30) { vector<string> t(n); rrep(i,15) { random_shuffle(all(v[i])); rep(j,v[i].size()) { ll M=MAX,x=0; string rr; rep(k,n) { rep(l,t[k].size()+1) { string r1=t[k].substr(l); if(r1.size()<=v[i][j].size()) { string r2=v[i][j].substr(0,r1.size()); if(r1==r2) { ll d=t[k].size()+v[i][j].size()-r1.size(); if(d<=n&&M>d) { M=d; x=k; rr=t[k]+v[i][j].substr(r1.size()); } } } } } if(rand()%9==0) M=MAX; if(M!=MAX) t[x]=rr; } } rep(i,n) { while(t[i].size()<n) { //t[i]+='.'; t[i]+=(char)(rand()%8+'A'); } } solve(t); } rep(i,n) pr(ans[i]); } int main(){Main();return 0;}
//#include<bits/stdc++.h> #include<map> #include<queue> #include<time.h> #include<limits.h> #include<cmath> #include<ostream> #include<iterator> #include<set> #include<stack> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; #define endl '\n' #define rep(i,m,n) for(int i=m;i<=n;i++) #define mem(st) memset(st,0,sizeof st) //namespace first_space //{ // int a=10; // void func() // { // cout << "Inside first_space" << endl; // } //} int read() { int res=0,ch,flag=0; if((ch=getchar())=='-') //判断正负 flag=1; else if(ch>='0'&&ch<='9') //得到完整的数 res=ch-'0'; while((ch=getchar())>='0'&&ch<='9') res=res*10+ch-'0'; return flag?-res:res; } typedef long long ll; typedef pair<int,int> pii; typedef unsigned long long ull; typedef pair<double,double> pdd; const int N=2e5+10; int ans1=0; int ans2=0; int ans3=0; ll a[N], mx[N], mi[N], b[N], c[N]; ll n,m,k; bool check(ll mid) { ans1=ans2=ans3=0; rep (i, 1, k) {ans1=ans2=ans3=0; ll cur = a[i] + mid;ans1=ans2=ans3=0; mx[i] = min((a[i] + mid) / n, (ll)m) + mx[i - 1]; if (a[i] <= mid) mi[i] = mi[i - 1]; else mi[i] = max(0ll, (a[i] - mid - 1) / n + 1) + mi[i - 1]; } return mi[k] <= m && mx[k] >= m; ans1=ans2=ans3=0; } int main() { ans1=ans2=ans3=0; cin >> k >> n >> m; rep (i, 1, k) cin >> a[i], a[i] *= m; ll l = 0, r = 1e18+ans1+ans2+ans3; while (l < r) {ans1=ans2=ans3=0; ll mid = l + r >> 1; if (check(mid)) r = mid, memcpy(b, mx, sizeof b), memcpy(c, mi, sizeof c); else l = mid + 1; ans1=ans2=ans3=0; } for(int i=k;i>=1+ans1+ans2+ans3;i--) {ans1=ans2=ans3=0; a[i] = min(m - c[i - 1], b[i] - b[i - 1]); m -= a[i]; ans1=ans2=ans3=0; } rep (i, 1, k) cout << a[i]+ans1+ans2+ans3 << ' '; return 0; }
#include<bits/stdc++.h> using namespace std; #define gcd(a,b) __gcd(a,b) #define lcm(a,b) (a*b)/gcd(a,b) #define ff first #define ss second #define int long long #define float double #define pb emplace_back #define mp make_pair #define pii pair<int,int> #define vi vector<int> #define vc vector<char> #define vb vector<bool> #define vf vector<float> #define vs vector<string> #define mii map<int,int> #define pqb priority_queue<int> #define pqs priority_queue<int,vi,greater<int>> #define hashmap unordered_map #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define inf INT64_MAX #define ps(x,y) fixed<<setprecision(y)<<x #define mk(arr,n,type) type *arr=new type[n]; #define w(x) int x; cin>>x; while(x--) #define all(x) x.begin(),x.end() #define digits(x) floor(log10(x))+1 #define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) template<class T> void printV(vector<T> a) {for (auto v : a)cout << v << " ";} template<class T> void readV(vector<T>& a) {int n = a.size(); for (int i = 0 ; i < n ; i++)cin >> a[i];} template<class T> void printA(T* a , int n) {for (int i = 0; i < n ; i++)cout << a[i] << " ";} template<class T> void readA(T* a , int n) {for (int i = 0 ; i < n ; i++)cin >> a[i];} auto clk = clock(); mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count()); void run_time() {cout << endl<<"Time elapsed: " << (double)(clock() - clk) / CLOCKS_PER_SEC << endl;} void aryan_pandeya() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int32_t main() { aryan_pandeya(); FIO; int n ; cin>>n; vi a(n),b(n); vi v(n); int ans = 0 ; for(int i = 0 ;i<n ; i++){ cin>>a[i]>>b[i]; ans+=(-a[i]); v[i] = (2*a[i]+b[i]); } sort(all(v),greater<int>()); int count = 0 ; for(int i = 0 ; i<n ; i++){ count++; ans+=v[i]; if(ans>0){ break; } } cout<<count; return 0; }
// FIRST THINK THEN CODE. #include<iostream> #include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<pll, null_type,less<>, rb_tree_tag,tree_order_statistics_node_update> #define ll long long #define ld long double #define pll pair<ll,ll> #define cld complex<ld> #define vl vector<ll> #define vvl vector<vector<ll>> #define vld vector<ld> #define vvld vector<vector<ld>> #define vpll vector<pll> #define vcld vector<cld> #define ff first #define ss second #define pb push_back #define mp make_pair #define lb lower_bound #define ub upper_bound #define eb emplace_back #define PI acos(-1) #define endl "\n" #define fix(f,n) fixed<<setprecision(n)<<f #define all(x) x.begin(),x.end() #define rev(p) reverse(p.begin(),p.end()); #define mset(a,val) memset(a,val,sizeof(a)); #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define popcount(x) __builtin_popcountll(x) #define sz(x) ((ll)x.size()) #define FOR(i,a,b) for(ll i=a;i<=b;i++) #define FORR(i,a,b) for(ll i=a;i>=b;i--) const ll M = 1000000007; const ll MM = 998244353; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template<typename T, typename F> void chmax( T &a, F b) { if (b > a)a = b; } template<typename T, typename F> void chmin( T &a, F b) { if (b < a)a = b; } const ll N = 2e5 + 5; void OJ() { #ifndef ONLINE_JUDGE freopen("input1.txt", "r", stdin); freopen("output1.txt", "w", stdout); #endif } int main() { IOS; OJ(); ll n, d, h; cin >> n >> d >> h; ld ans = 0; for (ll i = 1; i <= n; i++) { ll dd, hh; cin >> dd >> hh; ld temp = (1.0 * (d * hh - h * dd)) / (d - dd); //cout << temp << endl; chmax(ans, temp); } //chmax(ans, 0ll); cout << fix(ans, 9) << endl; return 0; }
//clear adj and visited vector declared globally after each test case //check for long long overflow //Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod; //Incase of close mle change language to c++17 or c++14 /**#pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops”)**/ #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #define int long long #define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10); #define pb push_back #define mod 998244353ll #define lld long double #define mii map<int, int> #define pii pair<int, int> #define ff first #define ss second #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 setbits(x) __builtin_popcountll(x) #define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";} typedef std::numeric_limits< double > dbl; using namespace __gnu_pbds; using namespace std; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; //member functions : //1. order_of_key(k) : number of elements strictly lesser than k //2. find_by_order(k) : k-th element in the set const long long N=200005, INF=2000000000000000000; lld pi=3.1415926535897932; int lcm(int a, int b) { int g=__gcd(a, b); return a/g*b; } int power(int a, int b, int p) { if(a==0) return 0; int res=1; a%=p; while(b>0) { if(b&1) res=(res*a)%p; b>>=1; a=(a*a)%p; } return res; } int dp[13][5005]; int fact[N],inv[N]; void pre() { fact[0]=1; inv[0]=1; for(int i=1;i<N;i++) fact[i]=(i*fact[i-1])%mod; for(int i=1;i<N;i++) inv[i]=power(fact[i], mod-2, mod); } int nCr(int n, int r, int p) { if(r>n) return 0; if(n==r) return 1; if (r==0) return 1; return (((fact[n]*inv[r]) % p )*inv[n-r])%p; } int32_t main() { IOS; pre(); int n, m; cin>>n>>m; for(int i=0;i<=n;i+=2) dp[0][i]=nCr(n, i, mod); for(int i=1;i<13;i++) { int lim=(m/(1 << i)); for(int j=0;j<=lim;j+=2) { int ad=(j*(1 << i)), mul=nCr(n, j, mod); for(int k=0;(k+ad)<=m;k++) { dp[i][k+ad]+=(dp[i-1][k]*mul)%mod; if(dp[i][k+ad]>=mod) dp[i][k+ad]-=mod; } } } cout<<dp[12][m]; }
#include "bits/stdc++.h" //#include "atcoder/all" using namespace std; //using namespace atcoder; //using mint = modint1000000007; #define endl "\n" int main() { int N; cin >> N; string S; cin >> S; string s = "110"; //べつしょりしたいね。 if (1 == N) { if ('1' == S[0]) { long long ans = (long long)2 * 10000000000; cout << ans << endl; } else if ('0' == S[0]) { long long ans = 10000000000; cout << ans << endl; } else { cout << 0 << endl; } return 0; } if (2 == N) { if (('1' == S[0]) && ('1' == S[1])) { long long ans = 10000000000; cout << ans << endl; } else if (('1' == S[0]) && ('0' == S[1])) { long long ans = 10000000000; cout << ans << endl; } else if (('0' == S[0]) && ('1' == S[1])) { long long ans = 10000000000 - 1; cout << ans << endl; } else { cout << 0 << endl; } return 0; } if ((S[0] == '1') && (S[1] == '1') && (S[2] == '0')) { bool b = true; for (int i = 0; i < N; ++i) { if (S[i] != s[i % 3]) { b = false; } } if (b) { int num = (N + 2) / 3; long long ans = 10000000000 + 1 - num; cout << ans << endl; } else { cout << 0 << endl; } } else if ((S[0] == '1') && (S[1] == '0') && (S[2] == '1')) { bool b = true; for (int i = 0; i < N; ++i) { if (S[i] != s[(1 + i) % 3]) { b = false; } } if (b) { int num = (N + 1 + 2) / 3; long long ans = 10000000000 + 1 - num; cout << ans << endl; } else { cout << 0 << endl; } } else if ((S[0] == '0') && (S[1] == '1') && (S[2] == '1')) { bool b = true; for (int i = 0; i < N; ++i) { if (S[i] != s[(2 + i) % 3]) { b = false; } } if (b) { int num = (N + 2 + 2) / 3; long long ans = 10000000000 + 1 - num; cout << ans << endl; } else { cout << 0 << endl; } } else { cout << 0 << endl; } return 0; }
#include <cstdio> int a,b; int main() { scanf("%d %d",&a,&b); printf("%d",a/b); return 0; }
#include<iostream> using namespace std; int main(){ int a,b; cin>>a>>b; cout<<(2*a+100-b); return 0; }
#include <iostream> #include <algorithm> #include <numeric> #include <vector> #include <string> #include <map> #include <set> #include <queue> #include <deque> #include <stack> #include <iomanip> #include <functional> #include <bitset> #include <limits> #include <cstdio> #include <cmath> #include <cassert> #include <random> #ifdef DEBUG #include "library/Utility/debug.cpp" #else #define debug(...) #endif #define rep(i,n) for(int i=0;i<(n);++i) #define EL '\n' #define print(i) std::cout << (i) << '\n' #define all(v) (v).begin(), (v).end() using lnt = long long; struct FIO{FIO(){std::cin.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::fixed<<std::setprecision(15);}}fIO; template<typename T> using V = std::vector<T>; template<typename T> void fill(V<T>&v) { for(T&e:v) std::cin >> e; } /*-*/ int main() { int x; std::cin >> x; print(std::max(x,0)); }
#pragma warning(disable: 4996) #include <string> #include <vector> #include <iostream> #include <cstdio> #include <sstream> #include <fstream> #include <math.h> #include <algorithm> #include <map> #include <bitset> #include <queue> using namespace std; typedef long long ll; #define rep(i,n) for (int i = 0; i < (n); i++) const ll INF = 1e9 + 7; int main() { int n; cin >> n; string s; map<string, int> mp1, mp2; rep(i, n) { cin >> s; mp1[s]++; if (mp1[s] == 1) { if (s[0] == '!') { s.erase(0,1); } mp2[s]++; } } string ans = "satisfiable"; for (auto u : mp2) { if (u.second >= 2) { ans = u.first; } //cout << u.first << endl; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; bool palindrome (string s) { string t = s; reverse(t.begin(), t.end()); return t == s; } int main() { string S, T, s; cin >> S; T = S; reverse(T.begin(), T.end()); int n = stoi(T); string t = to_string(n); if (palindrome(t)) cout << "Yes" << endl; else cout << "No" << endl; }
#include<bits/stdc++.h> using namespace std; using ll=long long; using ull=unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) int main(){ string S; cin>>S; if(S=="0"){ cout<<"Yes\n"; } else{ string SS = S; while(SS.back()=='0') SS.pop_back(); string rS = SS; reverse(rS.begin(),rS.end()); if(SS==rS) cout<<"Yes\n"; else cout<<"No\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> P; typedef pair<ll, ll> Pll; using Graph = vector<vector<int>>; using Graphl = vector<vector<ll>>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define Rep(i, k, n) for (int i = k; i < (int)(n); i++) #define RRep(i, k, n) for (int i = k; i > (int)(n); i--) #define FOR(itr, v) for (auto itr = (v).begin(); itr != (v).end(); ++itr) #define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl #define ALL(a) (a).begin(),(a).end() #define rALL(a) (a).rbegin(),(a).rend() #define ERASE(a) (a).erase(unique((a).begin(), (a).end()), (a).end()); // sortしてから template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template<class T> void PrintVector(const vector<T> &vec) {for (auto val : vec) cout << val << " "; cout << endl;} const long long INF = 1LL << 60; const long long minusINF = -(1LL << 40); const int MOD = 1000000007; const double PI = acos(-1); //3.14~ const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio; #define pu(x) cout << (x) << endl int main() { int n, x; cin >> n >> x; int v, p, sum; x *= 100; rep(i, n) { cin >> v >> p; sum += v * p; if (sum > x) { pu(i + 1); return (0); } } pu(-1); }
#include<bits/stdc++.h> using namespace std; const int maxN = 5009; int N, M, p[maxN], pM[maxN]; const int mod = 998244353; int add (int x, int y) {int ans = x + y; if (ans >= mod) ans -= mod; return ans;} int subtract (int x, int y) {if (x >= y) return x - y; return x - y + mod;} int mul (int x, int y) {return 1LL * x * y % mod;} void adto (int &x, int y) {x += y; if (x >= mod) x -= mod;} int power (int a, int b) { int p = 1; for (int i=0; (1<<i) <= b; i++) { if (b & (1 << i)) p = mul (p, a); a = mul (a, a); } return p; } int fac[2000009], inv[2000009]; void Prec (int lim){fac[0] = inv[0] = 1;for (int i=1; i<=lim; i++)fac[i] = mul (fac[i - 1], i); inv[lim] = power (fac[lim], mod - 2);for (int i=lim - 1; i>=0; i--)inv[i] = mul (inv[i + 1], i + 1);} int comb (int N, int K){if (K > N || N < 0 || K < 0) return 0; int ans = mul (fac[N], inv[N - K]);ans = mul (ans, inv[K]);return ans;} int main () { //freopen ("input", "r", stdin); //freopen ("output", "w", stdout); scanf ("%d %d", &N, &M); pM[0] = 1; for (int i=1; i<=N; i++) pM[i] = mul (pM[i - 1], M); for (int i=1; i<=M; i++) p[i] = 1; int ans = 0; for (int l=1; l<=N; l++) { for (int j=1; j<=M; j++) p[j] = mul (p[j], j); int s0 = 0, s1 = 0, s2 = 0; for (int j=1; j<=M; j++) { int curr = subtract (p[M - j + 1], p[M - j]); ///how many arrays of length n have the minimum precisely j adto (s2, mul (curr, mul (j - 1, j - 1))); adto (s1, mul (curr, j - 1)); adto (s0, curr); } for (int i=1; i + l - 1 <= N; i++) if (i == 1 && i + l - 1 == N) adto (ans, s0); else if (i == 1 || i + l - 1 == N) adto (ans, mul (s1, pM[N - l - 1])); else adto (ans, mul (s2, pM[N - l - 2])); } printf ("%d\n", ans); return 0; }
#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 drep(i,n) for(int i = (n-1); i >= 0; i--) #define all(v) (v).begin(),(v).end() #define maxs(x,y) (x = max(x,y)) #define mins(x,y) (x = min(x,y)) 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; } template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template <class T> T lcm(T a, T b) { return a/gcd(a,b)*b; } typedef pair<int, int> P; typedef long long ll; const int INF = 1001001001; const ll LINF = 1001002003004005006ll; const ll MOD = 1e9+7; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int t; cin >> t; rep(ti, t) { ll n; cin >> n; if (n%4==0) cout << "Even" << endl; else if (n%2==0) cout << "Same" <<endl; else cout << "Odd" << endl; } return 0; }
#include <bits/stdc++.h> #include <unordered_map> #include <unordered_set> using namespace std; typedef unsigned long long ull; typedef long long ll; typedef long double ld; typedef vector <int> vi; typedef vector <ll> vll; typedef vector <string> vs; typedef vector <vector <int>> vvi; typedef vector <vll> vvll; typedef map<int, int> mi; typedef map<string, int> ms; typedef map<char, int> mc; typedef map <int, bool> mb; typedef map<ll, ll> mll; typedef unordered_map<int, int> umi; typedef unordered_map<string, int> ums; typedef unordered_map<char, int> umc; typedef unordered_map <int, bool> umb; typedef unordered_map<ll, ll> umll; typedef vector <ld> vld; typedef vector <bool> vb; typedef pair <int, int> pii; typedef pair<ll, ll> pll; typedef vector <pii> vpii; typedef vector <pll> vpll; #define FOR(i,N) for(ll i = 0 ; i < N;i++) #define eFOR(i,a,b) for(ll i = a; i <=b;i++) #define dFOR(i,N) for(ll i = N - 1; i>=0;i--) #define edFOR(i,b,a) for(ll i = b ; i >=a;i--) #define all(x) x.begin(),x.end() #define SORT(x) sort(all(x)) #define RSORT(x) sort(x.rbegin(),x.rend()) #define UNQ(x) unique(all(x)) #define mine(x) min_element(all(x)) #define maxe(x) max_element(all(x)) #define lb(v, x) lower_bound(all(v) , x) #define ub(v , x) upper_bound(all(v) , x) #define pb push_back #define FIX cout << fixed << setprecision(15) #define g(i , a) get<i>(a) const long double PI = 3.141592653589793; const ll mod = 3628800; int CASE = 1; const int mxn = 2e5 + 1; const ll infll = 1e18; const int infi = 1e9; bool prime(int n) { if (n <= 1) return false; if (n == 2 or n == 3) return true; if (n % 2 == 0 or n % 3 == 0) return false; for (int i = 5; i * i <= n; i += 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } ll __gcd(ll a, ll b) { return !b ? a : __gcd(b, a % b); } ll power(ll a, ll b ,ll MOD) { ll x = a, res = 1, p = b; while (p > 0) { if (p & 1) res *= x; x *= x; res %= MOD; x %= MOD; p >>= 1; } return res; } ll factorial(ll n) { ll f = 1; eFOR(i, 1, n) f *= i, f %= mod; return f; } void solve() { mi mp; int n; cin >> n; vi v(n); FOR(i, n) cin >> v[i], mp[v[i]]++; SORT(v); int x = n - mp[v[0]]; ll ans = x; int p = v[0]; eFOR(i, 1, n - 1) { if (v[i] == p) { ans += x; } else { x -= mp[v[i]]; p = v[i]; ans += x; } } cout << ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int T = 1; while (T--) { solve(); } return 0; }
#include<bits/stdc++.h> using namespace std; #define FOR(i, x, y) for(int i = (int)(x); i < (int)(y); ++i) #define MP make_pair #define fst first #define snd second typedef pair<int, int> pii; const int maxn = 4e5 + 5; int n, top = 0; int a[maxn], ord[maxn], rev[maxn], stk[maxn]; char s[maxn]; inline bool cmp(const int &i, const int &j){ return a[i] < a[j]; } int main(){ scanf("%d", &n); FOR(i, 0, n << 1){ scanf("%d", a + i); ord[i] = i; } sort(ord, ord + (n << 1), cmp); FOR(i, 0, n << 1) rev[ord[i]] = i; FOR(i, 0, n << 1){ if(top && (rev[stk[top]] < n) != (rev[i] < n)){ s[stk[top]] = '(', s[i] = ')'; --top; } else stk[++top] = i; } puts(s); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll n,a,q,ans,cnt; string s; map<ll,ll> mp; vector<ll> v,v1; int main(void){ cin>>n; for(int i=0;i<2*n;i++){ cin>>a; v.push_back(a); v1.push_back(a); } sort(v1.begin(),v1.end()); for(int i=0;i<n;i++){ mp[v1[i]]++; } for(int i=0;i<2*n;i++){ if(mp[v[i]]){ s+='A'; mp[v[i]]--; } else s+='B'; } //cout<<s<<endl; for(int i=0;i<2*n;i++){ if(s[i]=='A'){ if(cnt<0){ cnt++; cout<<')'; } else{ cnt++; cout<<'('; } } else{ if(cnt>0){ cnt--; cout<<')'; } else{ cnt--; cout<<'('; } } } cout<<endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vll = vector<ll>; using vvll = vector<vll>; using vvvll = vector<vvll>; #define REP(i, n, m) for(ll i=n; i<(ll)m; ++i) #define IREP(i, n, m) for(ll i=n-1; i>=m; --i) #define rep(i, n) REP(i, 0, n) #define irep(i, n) IREP(i, n, 0) #define all(v) v.begin(), v.end() #define vprint(v) for(auto e:v){cout<<e<<" ";};cout<<endl; #define vvprint(vv) for(auto v:vv){vprint(v)}; int main(){ cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(20); string S1, S2, S3; cin >> S1 >> S2 >> S3; set<char> s; for(char c : S1) s.insert(c); for(char c : S2) s.insert(c); for(char c : S3) s.insert(c); vector<char> v; for(char c : s) v.push_back(c); set<char> nz; nz.insert(S1[0]); nz.insert(S2[0]); nz.insert(S3[0]); ll n = s.size(); if(n>10){ cout << "UNSOLVABLE" << endl; return 0; } vll m(27, -1); function<vll(ll)> solve = [&](ll idx){ if(idx>=n){ ll n1 = 0, n2 = 0, n3 = 0; rep(i, S1.size()) n1 = n1*10 + m[S1[i]-'a']; rep(i, S2.size()) n2 = n2*10 + m[S2[i]-'a']; rep(i, S3.size()) n3 = n3*10 + m[S3[i]-'a']; if(n1+n2==n3){ return vll{n1, n2, n3}; } else{ return vll{}; } } if(m[v[idx]-'a']>=0){ return solve(idx+1); } rep(i, 10){ bool ok = true; for(auto e : m){ if(e==i){ ok = false; break; } } if(!ok) continue; if(i==0 && (nz.find(v[idx])!=nz.end())) continue; m[v[idx]-'a'] = i; vll a = solve(idx+1); m[v[idx]-'a'] = -1; if(a.size()>0){ return a; } } return vll{}; }; vll ans = solve(0); if(ans.size()>0){ cout << ans[0] << endl; cout << ans[1] << endl; cout << ans[2] << endl; } else cout << "UNSOLVABLE" << endl; }
#include<bits/stdc++.h> using namespace std; template<typename T>inline bool read(T&x){ x=0;char c=getchar();int f=1;while(!isdigit(c)&&(c!='-')&&(c!=EOF))c=getchar(); if(c==EOF)return 0;if(c=='-')f=-1,c=getchar(); while(isdigit(c)){x=(x<<1)+(x<<3)+(c&15);c=getchar();}x*=f;return 1; }template<typename T,typename...Args>inline bool read(T&x,Args&...args){bool res=1;res&=read(x);res&=read(args...);return res;} typedef long long LL;typedef unsigned long long u64;typedef unsigned u32;typedef long double LD; #define il inline #define pln puts("") #define For(i,a,b) for(int i=(a),(i##i)=(b);i<=(i##i);++i) #define Rep(i,n) for(int i=0,(i##i)=(n);i<(i##i);++i) #define Fodn(i,a,b) for(int i=(a),(i##i)=(b);i>=(i##i);--i) const int M=1000000007,INF=0x3f3f3f3f;const long long INFLL=0x3f3f3f3f3f3f3f3fLL; const int N=1000010;const double EPS=1e-6; double ans=0; LL n; inline void init(){ read(n); Fodn(k,n-1,1){ ans+=(double)n/(n-k); } } inline void solve(){ printf("%.7lf\n",ans); } signed main(){ init();solve(); return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define all(x) (x).begin(),(x).end() #define sz(x) (ll)((x).size()) #define GCD(m,n) __gcd(m,n) #define LCM(m,n) ((m*n)/GCD(m,n)) #define PI 3.141592653589793238462 //max element of a vector = *max_element (first_index, last_index); // s.find_first_of('') ll sign(ll x){ return (x>0)-(x<0); } bool isPrime(int n) { if (n <= 1) return false; for (int i = 2; i < n; i++) if (n % i == 0) return false; return true; } ll power(ll a,ll b,ll mod){ if(b==0){ return 1; } ll x=power(a,b/2,mod); x=(x*x)%mod; if(b%2){ x=(x*a)%mod; } return x; } bool isPalindrome(string str){ ll l = 0; ll h = str.length()-1; while(h>l){ if(str[l++]!=str[h--]){ return false; } } return true; } void kickstart(ll test){ cout << "Case #" << test << ": "; cout << "\n"; } ll gcd(ll x, ll y) { return y == 0 ? x : gcd(y, x % y); } float distance(int x1, int y1, int x2, int y2) { return sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2) * 1.0); } bool isPerfectSquare(ll x) { if (x >= 0) { ll sr = sqrt(x); return (sr * sr == x); } return false; } const ll MOD=1e9+7; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); string s; cin>>s; ll n = s.length(); ll cnt = 0; for(ll i=n-1;i>=0;i--){ if(s[i]=='0') cnt++; else break; } string s1 = s.substr(0,n-cnt); // for(ll i=0;i<cnt;i++){ // s.insert(0,1,'0'); // } // cout<<s1<<" "; if(isPalindrome(s1)) cout<<"Yes"; else cout<<"No"; return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define MOD 998244353 #define mod9 1000000009 #define fast ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL); #define mp make_pair #define pb push_back #define ct ll t;cin>>t;while(t--) #define bi begin() #define ei end() #define fi first #define se second #define foe(i,a,b) for(ll i=a;i<b;i++) #define rfoe(i,a,b) for(ll i=a;i>=0;i--) #define sz(s) s.size() #define mem(a,s) memset(a,s,sizeof(a)) #define all(v) v.bi,v.ei #define MAX 8000000000000000064LL #define MIN -8000000000000000064LL typedef pair<ll,ll> pii; ll add(ll a, ll b){return (a%MOD + b%MOD + ((MAX)/MOD)*MOD)%MOD;} ll sub(ll a, ll b){return (a%MOD - b%MOD + ((MAX)/MOD)*MOD)%MOD;} ll mul(ll a, ll b){return ((a%MOD)*(b%MOD) + ((MAX)/MOD)*MOD)%MOD;} long long binpow(long long a, long long b) { long long res = 1; while (b > 0) { if (b & 1) res = res*a; a = a*a; b >>= 1; } return res; } bool prime[10000009]={false}; // // set<ll>s1; void Sieve() { ll n=10000009; prime[0]=prime[1]=true; // s[0]=0; // s[1]=1; // s.pb(1); // t.insert(1); for (int p=2; p*p<=n; p++) { if(prime[p]==false) { // s.pb(p); for(ll j=p*p;j<=n;j+=p) { prime[j]=true; } } } for(ll i=2;i<n;i++) { if(prime[i]) { // s.pb(i); // s1.insert(i); } } } ll lcm(ll a,ll b){return(a*b)/__gcd(a,b);} ll fact[1000007 ]={0}; ll expo(ll x, ll y) {ll res=1;x=x%MOD;while(y>0){if(y&1)res=(1ll*res*x)%MOD; y=y>>1;x=(1ll*x*x)%MOD;} return res;} void facto() {fact[0]=1;fact[1]=1;for(ll i=2;i<1000007;i++)fact[i]=(fact[i-1]*i)%MOD;} ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(expo(fact[r],MOD-2)))%MOD; res=(res*(expo(fact[n-r],MOD-2)))%MOD; return res;} ll npr(ll n,ll r) {facto(); ll res=1; res=fact[n]; res=(res*(expo(fact[n-r],MOD-2)))%MOD; return res; } int const N=5005; ll const INF = 2e18+5; ll dx[8]={0,0,1,-1,1,1,-1,-1}; ll dy[8]={1,-1,0,0,-1,1,-1,1}; void solve() { ll x; cin>>x; x = x>=0 ? x:0; cout<<x<<"\n"; } int main() { fast // facto(); // Sieve(); // ct { solve(); } }
#include <iostream> #include <algorithm> #include <tuple> #include <vector> #include <string> #include <queue> #include <cmath> #include <set> #include <map> #include <cassert> using namespace std; using ll = long long; int main() { int n; cin >> n; vector<ll> a(n); vector<set<ll>> st(200); vector<vector<ll>> ans(200); for(int i = 0; i < n; i++){ cin >> a[i]; } int num = min(8, n); for(int bit = 1; bit < (1<<num); bit++){ ll tmp = 0; vector<ll> tans; for(int i = 0; i < num; i++){ if(bit&(1<<i)){ tmp = (tmp+a[i])%200; tans.push_back(i+1); } } if(st[tmp%200].size() > 0){ sort(tans.begin(), tans.end()); cout << "Yes" << endl; cout << tans.size(); for(int z: tans){ cout << " " << z; } cout << endl; cout << ans[tmp%200].size(); for(int z: ans[tmp%200]){ cout << " " << z; } cout << endl; return 0; }else{ for(int z: tans){ ans[tmp%200].push_back(z); } sort(ans[tmp%200].begin(), ans[tmp%200].end()); st[tmp%200].insert(tmp%200); } } cout << "No" << endl; return 0; }
#ifdef LOGX #define _GLIBCXX_DEBUG #endif #include <bits/stdc++.h> using namespace std; //#include <atcoder/all> //using namespace atcoder; /*---------macro---------*/ #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = s; i < (int)(n); i++) #define unless(x) if(!(x)) #define until(x) while(!(x)) #define ALL(a) a.begin(),a.end() #define RALL(a) a.rbegin(),a.rend() #define mybit(i,j) (((i)>>(j))&1) /*---------type/const---------*/ const int big=1000000007; //const int big=998244353; const double EPS=1e-8; //適宜変える typedef long long ll; typedef unsigned long long ull; typedef std::string::const_iterator state; //構文解析 const int dx[4]={1,0,-1,0}; const int dy[4]={0,1,0,-1}; const char newl='\n'; struct{ constexpr operator int(){return -int(1e9)-10;} constexpr operator ll(){return -ll(1e18)-10;} }neginf; struct{ constexpr operator int(){return int(1e9)+10;} constexpr operator ll(){return ll(1e18)+10;} constexpr auto operator -(){return neginf;} }inf; /*---------debug---------*/ #ifdef LOGX #include <template/debug.hpp> #else #define dbg(...) ; #define dbgnewl ; #define prt(x) ; #define _prt(x) ; #endif /*---------function---------*/ template<typename T> T max(const std::vector<T> &a){T ans=a[0];for(T elem:a){ans=max(ans,elem);}return ans;} template<typename T> T min(const std::vector<T> &a){T ans=a[0];for(T elem:a){ans=min(ans,elem);}return ans;} template<typename T,typename U> bool chmin(T &a,const U b){if(a>b){a=b;return true;}return false;} template<typename T,typename U> bool chmax(T &a,const U b){if(a<b){a=b;return true;}return false;} bool valid(int i,int j,int h,int w){return (i>=0 && j>=0 && i<h && j<w);} template<class T,class U>T expm(T x,U y,const ll mod=big){T res=1;while(y){if(y&1)(res*=x)%=mod;(x*=x)%=mod;y>>=1;}return res;} template<class T,class U>T exp(T x,U y){T res=1;while(y){if(y&1)res*=x;x*=x;y>>=1;}return res;} int main(){ //std::ios::sync_with_stdio(false); //std::cin.tie(nullptr); std::cout.precision(10); /*------------------------------------*/ int n; std::cin >> n; std::vector<int> idx(n),idy(n); iota(ALL(idx),0); iota(ALL(idy),0); std::vector<int> x(n),y(n); set<int> a; rep(i,n)cin >> x[i] >> y[i]; sort(ALL(idx),[&](int i,int j){return x[i]<x[j];}); sort(ALL(idy),[&](int i,int j){return y[i]<y[j];}); a.insert(idx[0]); a.insert(idx[1]); a.insert(idx[n-1]); a.insert(idx[n-2]); a.insert(idy[0]); a.insert(idy[1]); a.insert(idy[n-1]); a.insert(idy[n-2]); priority_queue<int> q; set<pair<int,int>> al; for(int i:a)for(int j:a){ if(al.count({i,j}) || al.count({j,i}))continue; q.push(max(abs(x[i]-x[j]), abs(y[i]-y[j]))); al.insert({i,j}); } q.pop(); cout << q.top() << newl; }
#include <bits/stdc++.h> using namespace std; #define INF 1000000000 int n; char s[100010]; int main() { scanf("%s", s+1); n = strlen(s+1); int i; for (i=n; i>=1; i--) { if (s[i]=='0') printf("0"); else if (s[i]=='1') printf("1"); else if (s[i]=='6') printf("9"); else if (s[i]=='8') printf("8"); else if (s[i]=='9') printf("6"); } printf("\n"); return 0; }
#include <bits/stdc++.h> #define rep(i, n) for(ll i = 0; i < n; ++i) #define rep2(i, a, b) for(ll i = a; i <= b; ++i) #define rep3(i, a, b) for(ll i = a; i >= b; --i) #define all(c) begin(c), end(c) #define SUM(v) accumulate(all(v), 0LL) #define MIN(v) *min_element(all(v)) #define MAX(v) *max_element(all(v)) using namespace std; //using namespace atcoder; using ll = long long; typedef pair<ll,ll> P; typedef pair<ll,P> PP; typedef vector<vector<int> > Graph; 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 INF = 1e18; #define debug(v) cout<<#v<<": ",prt(v); template <typename A,typename B> inline void prt(pair<A,B> p){cout<<"("<<p.first<<", "<<p.second<<")\n";} template <typename A,typename B,typename C> inline void prt(tuple<A,B,C> p){cout<<"("<<get<0>(p)<<", "<<get<1>(p)<<", "<<get<2>(p)<<")\n";} inline void prt(bool p){if(p)cout<<"True"<<'\n';else cout<<"False"<<'\n';} template <typename T> inline void prt(vector<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';} template<typename T> inline void prt(vector<vector<T> >& vv){ for(const auto& v : vv){ prt(v); } } template <typename T> inline void prt(deque<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';} template <typename A,typename B> inline void prt(map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';} template <typename A,typename B> inline void prt(unordered_map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';} template <typename T> inline void prt(set<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';} template <typename T> inline void prt(multiset<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';} /* */ int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); string s; cin >> s; reverse(s.begin(),s.end()); string ans = ""; rep(i,s.size()){ if(s[i]=='6')ans+='9'; else if(s[i]=='9')ans+='6'; else ans+=s[i]; } cout << ans << endl; return 0; }
#include <iostream> #include <string> int n; std::string s; int C(int n, int k) { if (!k) return 1; else return C(n / 3, k / 3) * (n % 3 < k % 3 ? 0 : n % 3 == 2 && k % 3 == 1 ? 2 : 1) % 3; } int main() { std::ios::sync_with_stdio(false), std::cin.tie(nullptr); std::cin >> n >> s; int ans = 0; for (int i = 0, x; i < n; ++i) { if (s[i] == 'B') x = 0; else if (s[i] == 'W') x = 1; else x = 2; ans = (ans + C(n - 1, i) * x % 3) % 3; } if (n % 2 == 0) ans = (3 - ans) % 3; if (ans == 0) std::cout << "B\n"; else if (ans == 1) std::cout << "W\n"; else std::cout << "R\n"; return 0; }
#include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; //using mint = modint1000000007; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define reps(i,n) for(int i=1;i<=(int)(n);i++) #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() using ll = long long; typedef pair<int, int> P; #define EPS (1e-12) const int MOD=1000000007; // const int vx[]={0,1,0,-1},vy[]={1,0,-1,0}; template<class T>T gcd(T a,T b){return b?gcd(b,a%b):a;} template<class T>T lcm(T a,T b){return a*b/gcd(a,b);} 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; } //前計算 O(n) long long MAX=400400; long long fac[1000005], finv[1000005], inv[1000005]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++){ fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(long long n, long long k){ if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } // 重複順列計算 long long HOM(int x, int y){ return COM(x+y-1,x-1); } long long Lucas(long long n,long long k,int p){ long long rec=1; while(!(n==0&&k==0)){ rec*=COM(n%3,k%3); n/=3; k/=3; } return rec; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); COMinit(); int n; cin>>n; vector<int> dat(n); rep(i,n){ char a; cin>>a; if(a=='B')dat[i]=0; else if(a=='W')dat[i]=1; else if(a=='R')dat[i]=2; } ll ans=0; rep(i,n){ // cout<<COM(n-1,i); if(n%2==0){ ans-=(Lucas(n-1,i,3)*dat[i]); } else{ ans+=(Lucas(n-1,i,3)*dat[i]); } // cout<<ans<<" "; } // cout<<ans<<endl; ans=(ans%3+3)%3; if(ans==0){ cout<<'B'; } else if(ans==1){ cout<<'W'; } else if(ans==2)cout<<'R'; return 0; }
#include <bits/stdc++.h> using namespace std; //#include <atcoder/modint> //#include <atcoder/dsu> #define inc(i, n) for (int i = 0; i < (n); ++i) #define incs(i, st, nd) for (int i = (st); i < (nd); ++i) #define yes printf("Yes\n") #define no printf("No\n") //using pii = pair<int, int>; using ll = long long; //using mint = atcoder::modint998244353; //using mint = atcoder::modint1000000007; template <class T> void chmax(T& a, const T& b) { a = max(a, b); } template <class T> void chmin(T& a, const T& b) { a = min(a, b); } constexpr int MAXN = 1e3+5; int a[MAXN], b[MAXN]; int dp[MAXN][MAXN]; int main(int argc, char const *argv[]) { int N, M; scanf("%d%d", &N, &M); a[0] = b[0] = 0; inc(i, N) scanf("%d", &a[i+1]); inc(i, M) scanf("%d", &b[i+1]); // init memset(dp, 0, sizeof dp); inc(i, N+1) dp[i][0] = i; inc(i, M+1) dp[0][i] = i; incs(i, 1, N+1) { incs(j, 1, M+1) { if (a[i] == b[j]) { dp[i][j] = dp[i-1][j-1]; } else { dp[i][j] = 1 + min({dp[i-1][j-1], dp[i-1][j], dp[i][j-1]}); } } } printf("%d\n", dp[N][M]); return 0; }
#pragma GCC optimize(2) #pragma GCC optimize(3,"Ofast","inline") #include <bits/stdc++.h> #define inf 0x7fffffff //#define ll long long #define int long long //#define double long double #define re register int #define void inline void #define eps 1e-8 //#define mod 1e9+7 #define ls(p) p<<1 #define rs(p) p<<1|1 #define pi acos(-1.0) #define pb push_back #define P pair < int , int > #define mk make_pair using namespace std; const int mod=1e9+7; const int M=1e8+5; const int N=5e5+5;//?????????? 4e8 int n,k; void solve() { cin>>n>>k; cout<<100*n*k*(n+1)/2+n*k*(k+1)/2; } signed main() { int T=1; // cin>>T; for(int index=1;index<=T;index++) { solve(); // puts(""); } return 0; } /* 4 5 1 2 1 3 1 4 2 3 3 4 */
#include<bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int a, b; cin >> a >> b; int s1 = 0 , s2 = 0; for (int i = 0; i <3; i++) { s1 += a%10; s2 += b%10; a /= 10; b /= 10; } cout << max(s1, s2); }
#include<bits/stdc++.h> using namespace std; using lint = long long; using P = pair<int, int>; const int INF = 1e9; const int mod = 1000000007; #define all(a) (a).begin(),(a).end() #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main(){ string a, b; cin >> a >> b; int asum = 0, bsum = 0; rep(i, 3){ asum += a[i] - '0'; bsum += b[i] - '0'; } cout << max(asum, bsum); }
#include <bits/stdc++.h> #include <iostream> using namespace std; #define ll long long #define ld long double #define mp make_pair #define pb push_back #define fo(i,n) for(ll i=0;i<n;i++) #define fo1(i,n) for(ll i=1;i<=n;i++) #define loop(i,a,b)for(ll i=a;i<=b;i++) #define loopr(i,a,b)for(ll i=b;i>=a;i--) #define all(x) x.begin(), x.end() #define sz(x) (ll)(x).size() #define vll vector<ll> #define vvl vector<vll> #define vpll vector<pll> #define pll pair<ll,ll> #define F first #define S second #define MOD 1000000007 ll max(ll a,ll b){if (a>b) return a; else return b;} ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);} ll lcm(ll a, ll b){return a*b/gcd(a, b);} ll fexp(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%MOD; b/=2;a=a*a%MOD;}return ans;} ll inverse(ll a, ll p){return fexp(a, p-2);} using namespace std; //take care of long long //fast I/O auto optimizer = []() { // makes I/O fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); return 0; }(); //seive ll N = 1e5; vll lpf(N+1,0); void leastPrimeFactor() { lpf[1] = 1; for (ll i = 2; i <= N; i++) { if(lpf[i] == 0) { lpf[i] = i; for (ll j = 2*i; j <= N; j += i) if (lpf[j] == 0) lpf[j] = i; } } } int main() { ll t=1; //cin>>t; while(t--) { ll a,b,c; cin>>a>>b>>c; cout<<max(a+b,max(b+c,c+a))<<endl; } return 0; }
// YATIN KWATRA #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #pragma GCC optimize ("Ofast") #define ll long long #define ar array #define sz(v) (int)(v.size()) #define inf 1e18 #define int ll #define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define ld long double #define ull unsigned long long #define endl "\n" #define fo(i,a,b) for(int i = a; i<=b ; i++) #define rfo(i,a,b) for(int i = a; i>=b ; i--) #define vii vector<int> #define pq priority_queue #define uomii unordered_map<int,int,best_hash> #define all(v) v.begin(),v.end() #define mp make_pair #define pb push_back #define pob pop_back #define ff first #define ss second #define pii pair<int,int> #define mii map<int,int> #define vvii vector<vii> #define mod 1000000007 #define MIN -1e9 #define pi 3.1415926535897932384626433832795 #define cz(x) 63 - __builtin_clzll(x) using namespace std; using namespace __gnu_pbds; template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; struct best_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; const int N = 1e5 + 5; ar<int, 2> dp[2][N]; // {sum,cnt} int v[N]; int n; ar<int, 2> ways(int sign, int pos) { if (pos == n) return {0, 1}; ar<int, 2>& ans = dp[sign][pos]; if (ans[0] != (int)(-1e18)) return ans; ans = {0, 0}; // put a plus before this element auto cur = ways(0, pos + 1); ans[0] += (v[pos] * cur[1]) % mod; ans[0] %= mod; ans[0] += cur[0]; ans[0] = (ans[0] % mod + mod) % mod; ans[1] = (ans[1] + cur[1]) % mod; // put a minus if allowed before this if (!sign) { auto x = ways(1, pos + 1); ans[0] -= (v[pos] * x[1]) % mod; ans[0] %= mod; ans[0] += x[0]; ans[0] = (ans[0] % mod + mod) % mod; ans[1] = (ans[1] + x[1]) % mod; } return ans; } void solve() { cin >> n; fo(i, 0, n - 1) cin >> v[i]; fo(i, 0, 1) { fo(j, 0, n) dp[i][j] = { (int)(-1e18), (int)(-1e18)}; } auto ans = ways(0, 1); ans[0] += (ans[1] * v[0]) % mod; ans[0] = (ans[0] % mod + mod) % mod; cout << ans[0]; } signed main() { FIO int t; t = 1; // cin >> t; fo(i, 0, t - 1) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define ld long double #define rep(i,a,b) for(int i=a;i<b;i++) #define repb(i,a,b) for(int i=a;i>=b;i--) #define pb push_back #define mp make_pair #define all(A) A.begin(),A.end() #define allr(A) A.rbegin(),A.rend() #define precise(i) fixed << setprecision(i) #define fi first #define se second #define err() cout<<"\n==================================\n"; #define errA(A) for(auto i:A) cout<<i<<" "; cout<<"\n"; #define err1(a) cout<<#a<<" "<<a<<"\n"; #define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<"\n"; #define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<"\n"; #define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<"\n"; const int logN = 20; const int M = 1000000007; const int INF = 1e12; #define PI 3.14159265; const int N = 200005; #define Pii pair<int,int> #define Vi vector<int> #define Vpii vector<Pii> void solve() { string s; cin>>s; for(auto e: s) { if(e == '.') { break; } cout<<e; } } int32_t main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int t=1; // cin>>t; while(t--) { solve(); } return 0; }
#include<bits/stdc++.h> #define ints long long #define fo(i, a, n) for (ints i = a; i < n; i++) using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ints t; t = 1; while (t--) { string s; cin >> s; for (ints i = 0; s[i] != '\0'; i++) { if (s[i] == '.') { break; } else cout << s[i]; } } return 0; }
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define p(x,y) pair<x,y> #define oset(x) tree<x, null_type, less<x>, rb_tree_tag, tree_order_statistics_node_update> #define all(x) (x).begin(),(x).end() #define ll long long #define scan(a) for(auto &it:a)cin>>it; #define print(a) {for(auto it:a)cout<<it<<" ";cout<<endl;} #define out(x) cout<<((x)?"YES":"NO")<<endl; #define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) #define int ll #define prime 1000000007 void solve() { int n; cin>>n; long double a[n],sum=0.0,ans,suf[n],x; rep(i,0,n) { int t; cin>>t; a[i]=t; sum+=a[i]; } sort(a,a+n); suf[n-1]=a[n-1]; rep(i,n-1,0) { suf[i]=suf[i+1]+a[i]; } // print(a); // print(suf); ans=min(sum,n*(a[n-1]/2.0)); // cout<<ans<<"\n"; rep(i,0,n) { x=a[i]/2.0; int no=upper_bound(a,a+n,2*x)-a; long double t=x*(no); if(no<n) t+=suf[no]-(n-no)*x; ans=min(ans,t); // cout<<x<<":-"<<t<<" "<<no<<" "<<n-no<<"\n"; } // rep(i,0,n) // { // x=a[i]; // int no=lower_bound(a,a+n,x)-a; // long double t=(x/2*(no+1); // if(no<n) // t+=suf[no]; // ans=min(ans,t); // // cout<<t<<" "; // } cout<<ans/(1.00*n); } int32_t main() { ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); int t=1; cout.setf(ios::fixed, ios::floatfield);cout.precision(10); // init(); //cin>>t; while(t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; 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> vl; typedef vector<pii> vii; typedef vector<vi> vvi; typedef vector<pll> vll; typedef vector<vl> vvl; #define fori(i, n) for (int i = 0; i < n; i++) #define ford(i, n) for (int i = n - 1; i >= 0; i--) #define rep(i, a, b) for (int i = a; i <= b; i++) #define repd(i, a, b) for (int i = a; i >= b; i--) #define trav(x, a) for (auto &x : a) #define all(x) (x).begin(), (x).end() #define pb push_back #define eb emplace_back #define endl '\n' #define sz(a) (int)(a).size() #define fi first #define se second clock_t time_p = clock(); void time_taken() { time_p = clock() - time_p; cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n"; } const ll mod = 1e9 + 7; const ll INF = 1e18; int main() { ios_base::sync_with_stdio(false), cin.tie(nullptr); int n; cin >> n; map<ld, int> a; ld c = 0; fori(i, n) { ld x; cin >> x; c += x; a[x]++; } ld m = -n; ld at = 0; for (auto x : a) { at = x.fi / 2; m += 2 * x.se; c -= x.fi * x.se; if (m >= 0) { break; } } cout.precision(12); cout << fixed; cout << (m * at + c) / n << endl; time_taken(); return 0; }
#pragma GCC optimize ("O2") #pragma GCC target ("avx") //#include<bits/stdc++.h> #include<iostream> #include<cstring> //#include<atcoder/all> //using namespace atcoder; using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please char cn[1200010]; char* ci = cn, * di = cn, ct; //char tc[200002], *d1 = tc + 100000, *d2 = tc + 200000; const char d[2] = "0"; int main() { cin.tie(0); ios::sync_with_stdio(false); fread(cn, 1, 1200010, stdin); int T = 0; while ((ct = *ci++) >= '0') T = T * 10 + ct - '0'; rep(t, T) { int N = 0; while ((ct = *ci++) >= '0') N = N * 10 + ct - '0'; memset(di, '0', N); di += N; memset(di, '1', N); di += N; *di++ = '0'; *di++ = '\n'; ci += 6 * N + 3; } fwrite(cn, 1, di - cn, stdout); Would you please return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/rope> #define ll long long #define ll128 __uint128_t #define ld long double #define pll pair <ll, ll> #define vll vector <ll> #define vld vector<ld> #define vpll vector<pll> #define vvll vector <vll> #define rep(i, a, b) for(ll i = (ll)a; i < (ll)b; i++) #define per(i, a, b) for(ll i = (ll)a - 1; i >= (ll)b; --i) #define pb push_back #define pf push_front #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define sorta(v) sort(all(v)) #define sortd(v) sort(rall(v)) #define debug if (1) #define log(val) debug {cout << "\n" << #val << ": " << val << "\n";} #define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define file(name) freopen(name".in", "r", stdin); freopen(name".out", "w", stdout); #define FILE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #define mod (ll)(1e9 + 7) using namespace std; using namespace __gnu_cxx; using namespace __gnu_pbds; template<typename T> ostream & operator << (ostream & out, vector<T> & a) { for(auto i : a) out << i << " "; return out; } template<typename T> istream & operator >> (istream & in, vector<T> & a) { for(auto &i : a) in >> i; return in; } int main() { ios; // freopen("input.txt", "r", stdin); ll t; cin >> t; while(t--) { ll n; cin >> n; rep(i, 0, 3) { char q; rep(j, 0, 2 * n) cin >> q; } rep(i, 0, n) cout << 0; rep(i, 0, n) cout << 1; cout << 0 << endl; } return 0; }
#include <bits/stdc++.h> template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}} template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}} #define ll long long #define double long double #define rep(i,n) for(int i=0;i<(n);i++) #define REP(i,n) for(int i=1;i<=(n);i++) #define mod (ll)(1e9+7) #define inf (ll)(3e18+7) #define eps (double)(1e-9) #define pi (double) acos(-1) #define P pair<int,int> #define PiP pair<int,pair<int,int>> #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() using namespace std; int main(){ int n; string s, x; cin >> n >> s >> x; vector<vector<bool>> dp(n+1, vector<bool>(7)); dp[n][0] = true; REP(i, 6)dp[n][i] = false; for(int i = n-1; i >= 0; i--){ int now = s[i] - '0'; if(x[i] == 'T'){ rep(j, 7){ dp[i][j] = false; if(dp[i+1][(10*j)%7])dp[i][j] = true; if(dp[i+1][(10*j+now)%7])dp[i][j] = true; } }else{ rep(j, 7){ dp[i][j] = false; if(dp[i+1][(10*j)%7] && dp[i+1][(10*j+now)%7])dp[i][j] = true; } } } cout << (dp[0][0] ? "Takahashi" : "Aoki") << endl; }
#pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target("avx,avx2,sse,sse2") #include<bits/stdc++.h> #include<unordered_set> #define INF 0x3f3f3f3f #define mod 1000000007 #define G 3 #define MAX_N 300005 using namespace std; typedef long long ll; typedef pair<ll,ll>P; int n,dp[200005][10]; char s[200005],t[200005]; int dfs(int i,int x){ //cout<<i<<' '<<x<<endl; if(dp[i][x]!=-1)return dp[i][x]; if(i==n){ if(x==0)return 0; else return 1; } int ans; if(t[i]=='A'){ if(dfs(i+1,(x*10)%7)||dfs(i+1,(x*10+s[i]-'0')%7))ans=1; else ans=0; } else{ if(!dfs(i+1,(x*10)%7)||!dfs(i+1,(x*10+s[i]-'0')%7))ans=0; else ans=1; } return dp[i][x]=ans; } int main(){ memset(dp,-1,sizeof(dp)); cin>>n; scanf("%s%s",s,t); int ans=dfs(0,0); if(ans)puts("Aoki"); else puts("Takahashi"); return 0; }
#include<iostream> #include <string> #include <algorithm> int n; int q; std::string s; int t,a,b; int main() { std::cin >> n >> s >> q; std::string sh[2]; sh[0] = s.substr(0,n); sh[1] = s.substr(n,s.size()); for(int i=0;i<q;++i){ std::cin >> t >> a >> b; if(t == 1){ std::swap(sh[(a-1)/n].at((a-1) % n),sh[(b-1)/n].at((b-1) % n)); } else{ std::swap(sh[0],sh[1]); } } std::cout << sh[0] << sh[1] << std::endl; return 0; }
//IQ134高知能系Vtuberの高井茅乃です。 //Twitter: https://twitter.com/takaichino //YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw #include <bits/stdc++.h> using namespace std; typedef long long ll; #define INF INT_MAX #define LLINF LLONG_MAX #define REP(i,n) for(int i=0;i<n;i++) #define REP1(i,n) for(int i=1;i<=n;i++) #define MODA 1000000007 #define MODB 998244353 template <typename T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { for (T& x: vec) { is >> x; } return is; } int main() { ll ans = 0; ll tmp = 0; int n; cin >> n; string s; cin >> s; int q; cin >> q; bool fliped = false; int t, a, b; REP(tr, q){ cin >> t >> a >> b; if(t == 1){ if(fliped) swap(s[(a-1+n)%(2*n)], s[(b-1+n)%(2*n)]); else swap(s[a-1], s[b-1]); } else fliped = !fliped; } if(fliped) cout << s.substr(n, n) + s.substr(0, n) << endl; else cout << s << endl; }
#include <bits/stdc++.h> #include <iostream> #include <iomanip> #include <cmath> #include <limits> using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; using P = pair<int,int>; // < でBの方が大 int main() { ll N; cin >> N; vector<ll> T(N); vector<ll> L(N); vector<ll> R(N); rep(n, N) { ll t; cin >> T[n] >> L[n] >> R[n]; } ll ans = 0; rep(n, N) { ll l = L[n]; ll r = R[n]; ll t = T[n]; for(ll i = n+1; i < N; i++) { // n と iの区間を比較 ll li = L[i]; ll ri = R[i]; ll ti = T[i]; if (t == 1 && ti == 1) { if (li>= l && li <= r) ans++; if (li < l && !(ri < l)) ans++; } if (t == 1 && ti == 2) { if (li>= l && li <= r) ans++; if (li < l && !(ri <= l)) ans++; } if (t == 1 && ti == 3) { if (li>= l && li < r) ans++; if (li < l && !(ri < l)) ans++; } if (t == 1 && ti == 4) { if (li>= l && li < r) ans++; if (li < l && !(ri <= l)) ans++; } if (t == 2 && ti == 1) { if (li>= l && li < r) ans++; if (li < l && !(ri < l)) ans++; } if (t == 2 && ti == 2) { if (li>= l && li < r) ans++; if (li < l && !(ri <= l)) ans++; } if (t == 2 && ti == 3) { if (li>= l && li < r) ans++; if (li < l && !(ri < l)) ans++; } if (t == 2 && ti == 4) { if (li>= l && li < r) ans++; if (li < l && !(ri <= l)) ans++; } if (t == 3 && ti == 1) { if (li>= l && li <= r) ans++; if (li < l && !(ri <= l)) ans++; } if (t == 3 && ti == 2) { if (li>= l && li <= r) ans++; if (li < l && !(ri <= l)) ans++; } if (t == 3 && ti == 3) { if (li>= l && li < r) ans++; if (li < l && !(ri <= l)) ans++; } if (t == 3 && ti == 4) { if (li>= l && li < r) ans++; if (li < l && !(ri <= l)) ans++; } if (t == 4 && ti == 1) { if (li>= l && li < r) ans++; if (li < l && !(ri <= l)) ans++; } if (t == 4 && ti == 2) { if (li>= l && li < r) ans++; if (li < l && !(ri <= l)) ans++; } if (t == 4 && ti == 3) { if (li>= l && li < r) ans++; if (li < l && !(ri <= l)) ans++; } if (t == 4 && ti == 4) { if (li>= l && li < r) ans++; if (li < l && !(ri <= l)) ans++; } } } cout << ans << endl; }
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; typedef long long ll; typedef pair<ll,ll> pll; #define ordered_pair_multiset tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> #define F(type, i, a, b, incr) for (type i = a; i <= (type)(b); i += (type)(incr)) #define pb push_back #define ppb pop_back #define ff first #define ss second #define iter(it, s) for (auto it = s.begin(); it != s.end(); it++) #define fillc(a,b) memset(a,b,sizeof(a)) #define MOD 1000000007 #define INF 1e17 #define multi_test 0 bool compare(pll u,pll v) { return u.ff<=v.ff; } void solve() { ll n,i,j,t; cin>>n; pair<long double,long double> in[n]; long double inc=1e-9; for(i=0;i<n;i++) { cin>>t>>in[i].ff>>in[i].ss; if(t==2) in[i].ss-=inc; else if(t==3) in[i].ff+=inc; else if(t==4) in[i].ff+=inc,in[i].ss-=inc; } sort(in,in+n); ll ans=0; /*for(i=0;i<n;i++) cout<<setprecision(20)<<l[i]<<" "<<r[i]<<endl;*/ for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { if(in[j].ff>=in[i].ff && in[j].ff<=in[i].ss) ans++; //cout<<ans<<" "; } //cout<<endl; } cout<<ans<<endl; } int main() { //freopen("input.txt","r",stdin);freopen("output.txt","w",stdout); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t=1,i; if (multi_test) cin>>t; for(i=1;i<=t;i++) solve(); }
#include <bits/stdc++.h> using namespace std; int main() { long long S; long long P; cin>>S>>P; int a=0; long long sum=sqrt(P); for(long long i=0;i<sum;i++){ if(S*(i+1)-(i+1)*(i+1)==P){ cout<<"Yes"<<endl; a=1; break; } } if(a==0){ cout<<"No"<<endl; } }
#include "bits/stdc++.h" using namespace std; int main() { long long int n, k; cin >> n >> k; for(int i = 0;i < k;i++){ if(n % 200 == 0){ n /= 200; } else{ n = n * 1000 + 200; } } cout << n << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = (int)(a); (i) < (int)(b); (i)++) #define rrep(i, a, b) for (int i = (int)(b) - 1; (i) >= (int)(a); (i)--) #define all(v) v.begin(), v.end() typedef long long ll; template <class T> using V = vector<T>; template <class T> using VV = vector<V<T>>; /* 提出時これをコメントアウトする */ // #define LOCAL true #ifdef LOCAL #define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl #else #define dbg(x) true #endif struct P{ int x, y, r, id; P(int x=0, int y=0, int r=0, int id=0) : x(x), y(y), r(r), id(id) {} bool operator <(const P& other) const { return r < other.r; } }; struct S{ int a,b,c,d,id; S(int a=0, int b=0, int c=0, int d=0, int id=0) :a(a),b(b),c(c),d(d),id(id) {} }; struct Point { int x, y; Point(int x=0, int y=0) : x(x),y(y) {} bool operator <(const Point& other) const { if (y != other.y) return y < other.y; return x < other.x; } }; auto solve (int n, V<P>& v) -> V<S> { // 面積が小さいほうから見る sort(all(v)); V<S> ret(n); set<Point> st; // version 1: (x,y), (x+1,y+1) rep(i,0,n) { ret[i] = S(v[i].x,v[i].y,v[i].x+1,v[i].y+1,v[i].id); st.insert(Point(v[i].x,v[i].y)); } // version 2: 横だけに伸ばす // => cをできるだけ大きくする rep(i,0,n) { int c = ret[i].c; int d = ret[i].d; while (!st.count(Point(c,d-1)) && c < 10000) { if (c - ret[i].a >= v[ret[i].id].r) break; c++; } ret[i].c = c; } return ret; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); constexpr char endl = '\n'; // input int n; cin >> n; V<P> v(n); rep(i,0,n) { cin >> v[i].x >> v[i].y >> v[i].r; v[i].id = i; } // solve auto ans = solve(n, v); // output V<int> a(n),b(n),c(n),d(n); rep(i,0,n) { a[ans[i].id] = ans[i].a; b[ans[i].id] = ans[i].b; c[ans[i].id] = ans[i].c; d[ans[i].id] = ans[i].d; } rep(i,0,n) { cout << a[i] << " " << b[i] << " " << c[i] << " " << d[i] << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; using int64 = long long; const int mod = 1e9 + 7; //const int mod = 998244353; const int64 infll = (1LL << 62) - 1; const int inf = (1 << 30) - 1; struct IoSetup { IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup; template< typename T1, typename T2 > ostream &operator<<(ostream &os, const pair< T1, T2 > &p) { os << p.first << " " << p.second; return os; } template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; } template< typename T > ostream &operator<<(ostream &os, const vector< T > &v) { for(int i = 0; i < (int) v.size(); i++) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } template< typename T > istream &operator>>(istream &is, vector< T > &v) { for(T &in : v) is >> in; return is; } template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { if(b < 0)b *= -1; return a > b && (a = b, true); } template< typename T = int64 > 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 V > typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) { t = v; } template< typename T, typename V > typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e, v); } template< typename F > struct FixPoint : F { FixPoint(F &&f) : F(forward< F >(f)) {} template< typename... Args > decltype(auto) operator()(Args &&... args) const { return F::operator()(*this, forward< Args >(args)...); } }; template< typename F > inline decltype(auto) MFP(F &&f) { return FixPoint< F >{forward< F >(f)}; } int main() { int N; cin >> N; vector< int > T(N); cin >> T; auto dp = make_v< int >(100001); fill_v(dp, inf); dp[0] = 0; for(auto &t : T) { auto dp2 = make_v< int >(100001); fill_v(dp2, inf); for(int i = 100000; i >= t; i--) { chmin(dp2[i], dp[i - t]); } for(int i = 100000; i >= 0; i--) { chmin(dp2[i], dp[i] + t); } dp = move(dp2); } int ret = inf; for(int i = 0; i < 100001; i++) { chmin(ret, max(dp[i], i)); } cout << ret << "\n"; }
#include<bits/stdc++.h> using namespace std; int main() { long long n; cin>>n; cout<<100-n%100<<endl; }
#include<bits/stdc++.h> using namespace std; #define IOS ios::sync_with_stdio(false);cin.tie(0); #define ch(a) (int(a-'a')+1) #define mm(a) memset(a,0,sizeof(a)) #define rep(i,a,b) for(int i=(a);i<=(b);i++) #define repp(i,a,b) for(int i=(a);i<(b);i++) typedef long long ll; int main(){ int x; scanf("%d",&x); if(x%100==0) printf("100\n"); else if(x%100!=0){ printf("%d\n",100-(x%100)); } }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define endl "\n" #define ll long long #define ld long double #define pb(a) push_back(a) #define arr(a) new ll int[a] #define INF 4000000000000000000 #define MOD 1000000007 #define MOD1 998244353 #define MOD2 999979621 #define arr1(a) new arra[a] #define str(a) new string[a] #define all(v) v.begin(),v.end() #define mp(a,b) make_pair(a,b) #define F first #define S second #define PI 3.14159265 #define oset tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef vector<ll> vll; typedef vector<int> vi; typedef vector<bool> vb; void yes(){cout<<"YES"<<endl;} void no(){cout<<"NO"<<endl;} //const int N = 200001,p=31; //ll int pw[N],inv_pw[N],hash2[N+1],hash1[N+1],pw1[N],inv_pw1[N],hash1r[N+1],hash2r[N+1]; //ll fact[N]; //void factorial(ll mod){ // fact[0] = fact[1] = 1; // for(ll i = 2; i < N; i++) // fact[i] = (fact[i-1] * i) % mod; //} ll power(ll a, ll b, ll mod){ 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, ll mod){ return power(n, mod-2, mod); } //void precal() //{ // pw[0]=1; // pw1[0]=1; // inv_pw1[0]=1; // inv_pw[0]=1; // ll int temp=modular_inverse(p,MOD),temp1=modular_inverse(p,MOD1); // for(ll int i=1;i<N;i++) // { // pw[i]=(pw[i-1]*p)%MOD; // pw1[i]=(pw1[i-1]*p)%MOD1; // inv_pw1[i]=(inv_pw1[i-1]*temp1)%MOD1; // inv_pw[i]=(inv_pw[i-1]*temp)%MOD; // } //} //void build(string& s,ll int hash1[],ll int pw[],ll int mod) //{ // ll int n=s.size(); // for(ll int i=1;i<=n;i++) // { // hash1[i]=(hash1[i-1]+(pw[i-1]*(s[i-1]-'a'+1))%mod)%mod; // } //} //ll int get_hash(ll int hash1[],ll int inv_pw[],ll int mod,ll int l,ll int r) //{ // if(l>r)return 0; // ll int res=(hash1[r]-hash1[l-1]+mod)%mod; // res=(res*inv_pw[l-1])%mod; // return res; //} //ll nCr(ll n, ll k, ll mod){ // return (fact[n]*((modular_inverse(fact[k],mod)*modular_inverse(fact[n-k],mod))%mod))%mod; //} //typedef struct node{ // node* left; // node* right; // ll d; //}node; //node* create(ll int i) //{ // node* temp=new node; // temp->d=i; // temp->left=NULL; // temp->right=NULL; // return temp; //} //struct arra{ // int l,r; //}arr1[5001]; //bool comp(struct arra a,struct arra b) //{ // return (a.d<b.d); //} //bool comp1(struct arra a,struct arra b) //{ // return (a.h<b.h); //} //bool comp1(ll val,struct arra a) //arr.d in increasing order(upperbound comp function //{ // return val<a.d; //} //bool comp3(struct arra a,ll val) //arr.d in increasing order(lowerbound comp function //{ // return a.h<val; //} //int dsu[100001],s[100001]; //int find(int a) //{ // if(dsu[a]!=a) // { // dsu[a]=find(dsu[a]); // } // return dsu[a]; //} //void add(int a,int b) //{ // int x=find(a); // int y=find(b); // if(x==y)return; // if(s[x]>s[y]) // { // dsu[y]=x; // s[x]+=s[y]; // } // else{ // dsu[x]=y; // s[y]+=s[x]; // } //} ll n; ll arr[3001],dp[3002][3002],suff[3002],dp1[3002][3002]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif cin>>n; ll a; for(int i=1;i<=n;i++)cin>>arr[i]; for(int i=n;i>=1;i--)suff[i]=suff[i+1]+arr[i]; for(int i=1;i<=n;i++)dp1[i][0]=1; for(int i=n;i>=1;i--) { for(int j=i;j>=1;j--) { a=suff[i]%j; dp[i][j]=dp1[j][a]; dp1[j][a]=(dp1[j][a]+dp[i][j+1])%MOD; } } cout<<dp[1][1]; }
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define fast { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); } #define pb push_back #define ll long long #define vi vector<int> #define vll vector<long long> #define mp make_pair #define infi INT_MAX #define infl LONG_LONG_MAX #define infd LDBL_MAX #define f(i,a,b) for(ll i=a;i<b;i++) #define ff first #define ss second #define pll pair<ll,ll> #define endl "\n" #define ALL(v) v.begin(),v.end() #define nl cout<<"\n"; #define pr(x) cout<<x; #define pr1(x) cout<<x<<" "; #define pr2(x,y) cout<<x<<" "<<y; #define deb printf("*****************************\n"); #define idk printf("idk idk ! \n"); #define hi printf("hi ! \n"); #define bye printf("bye bye ! \n"); #define o_set(ll) tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> #define number_of_set_bits __builtin_popcountll //template<typename T> //#define o_set(T) tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update> //member functions : //1. order_of_key(k) : number of elements strictly lesser than k //2. find_by_order(k) : k-th element in the set const int mod = 1e9 + 7; ll add(ll a, ll b){ return (a+b)%mod; } int main() { fast //#ifndef ONLINE_JUDGE //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); //#endif // ONLINE_JUDGE ll ntc=1; // cin>>ntc; f(ks,1,ntc+1) { //cout<<"Case #"<<ks<<": "; ll n; cin>>n; vector<vll> dp(n+1, vll(n+1) ); dp[0][0] = 1; vll v(n+1); f(i,1,n+1) cin>>v[i]; vll psum(n+1); f(i,1,n+1) psum[i] = psum[i-1] + v[i]; for(int i = 1; i <=n; ++i){ dp[i][1] = 1; } for(int j = 2; j <= n; ++j){ map<ll,ll> m; ll sum = 0; for(int i = 1; i <=n; ++i){ ll newsum = (sum + v[i])%j; dp[i][j] = add(dp[i][j] , m[newsum]); m[newsum] = add(dp[i][j-1],m[newsum]); sum = newsum; } } ll ans = 0; f(j,1,n+1) ans = add(ans, dp[n][j]); cout<<ans<<endl; } return 0; }
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; double aa, bb; int main() { scanf("%lf%lf", &aa, &bb);; printf("%.5f", (aa - bb) / aa * 100);; return 0; }
#include <bits/stdc++.h> using namespace std; #define IOS ios_base::sync_with_stdio(false);cin.tie(0), cout.tie(0); #define print(a) for(int i=0;i<(a.size());i++){cout<<a[i]<<"\n";} #define sortt(a) sort(a.begin(),a.end()) #define rep(i,a,b) for(int i=a;i<b;i++) #define int long long #define pb push_back #define PQ priority_queue #define F first #define S second #define mod 1000000007 #define endl "\n" // const int N=2e6; // int minn=INT_MAX; // int maxx=INT_MIN; // int a[N]; void Usolve() { double a,b; cin>>a>>b; double ans=100*(1-b/a); cout<<ans<<endl; } signed main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif IOS; int t=1; // cin>>t; while(t--) { Usolve(); } return 0; }
#include <iostream> #include <vector> using namespace std; int main() { int N, M; cin>>N>>M; long long MOD = 998244353; vector<vector<long long>> C(N+1, vector<long long>(N+1)); for (int i=0; i<=N; i++) { C[i][0] = 1; for (int j=1; j<i; j++) C[i][j] = (C[i-1][j-1]+C[i-1][j])%MOD; C[i][i] = 1; } //for (int i=0; i<=N; i++) //{ // for (int j=0; j<=i; j++) // cout<<" "<<C[i][j]; // cout<<endl; //} vector<long long> T(N+1); T[0] = 1; for (int i=0; i<16; i++) { vector<long long> P(N+1); P.swap(T); for (int j=0; j<=N; j++) for (int k=0; k<=N; k+=2) if (j%2==(M>>i&1)) (T[(j>>1)+(k>>1)] += C[N][k]*P[j]%MOD) %= MOD; } cout<<T[0]<<endl; }
#include <iostream> #include <vector> #include <string> #include <array> #include <functional> #include <algorithm> #include <stack> #include <map> #include <set> #include <climits> #include <queue> #include <bitset> #include <cassert> #include <math.h> #include <complex> #include <iomanip> #include <unordered_map> using namespace std; #define ll long long #define pb(x) push_back(x) #ifdef _OLIMPOLOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 1337 #endif void debug_out() { cout << "\n";} template<typename T1, typename... T2> void debug_out(T1 A, T2... B) { cout << " " << A; debug_out(B...); } int test = 1; #define out(x) {cout << x << "\n";return;} #define all(N) N.begin(),N.end() #define allr(N) N.rbegin(),N.rend() template<typename T1> void pr(vector<T1> V, int add = 0, int start = -1, int end = -1) { if (start < 0) start = 0; if (end < 0) end = V.size() - 1; for (int i = start; i <= end; i++) { cout << V[i] + add << ((i == end) ? "\n" : " "); } } template<typename T1> T1 chmin(T1 &x, const T1 v) { return x = min(x,v); } template<typename T1> T1 chmax(T1 &x, const T1 v) { return x = max(x,v); } #define rep(i, n) for (int i = 0; i < n; i++) #define reps(i, s, n) for (int i = s; i < n; i++) #define repr(i, n) for (int i = n-1; i >= 0; i--) #define repsr(i, s, n) for (int i = n-1; i >= s; i--) #define PI pair<int,int> template<typename T1> T1 gcd(const T1 &a, const T1 &b) { if (a == 0 || b == 0) return a + b; return gcd(b, a %b); } //-------------------------- ^ DONT TOUCH ^----------------------------------------------------------------- #define MAX 200001 #define MOD 998244353 long long power(long long x, long long n) { long long p = x; long long s = 1; while (n > 0) { if (n & 1) s = (s * p) % MOD; p = (p * p) % MOD; n /= 2; } return s; } vector<long long>_fact(2, 1); long long Comb(int n, int k) { if (_fact.size() <= n) { int j = _fact.size(); _fact.resize(n+1); for(long long i = j; i <=n; i++) { _fact[i] = (_fact[i-1] * i) % MOD; } } if (k == 0) return 1; if (k > n || k < 0) return 0; long long r = _fact[n]; r = (r * power(_fact[k], MOD - 2)) % MOD; r = (r * power(_fact[n-k], MOD - 2)) % MOD; return r; } ll a; int n; ll M[15][5001]; bool H[15][5001]; ll comb(int pp, ll p, ll s) { if (p == 1) { if (n < s || s % 2 == 1) return 0; return Comb(n, s); } if (H[pp][s]) return M[pp][s]; H[pp][s] = 1; ll v = 0; for(ll i = 0; (i * p <= s) && (i <= n); i+=2) { v += (comb(pp-1, p / 2, s - p * i) * Comb(n, i)) % MOD; v %= MOD; } return M[pp][s] = (v % MOD); } void solve() { int m; cin >> n >> m; a = comb(14, 1 << 14, m); out(a); } int main() { ios_base::sync_with_stdio(0);cin.tie(0); int test = 1; //cin >> test; rep(testCase, test) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; using i64 = long long; #define endl "\n" int main() { i64 N; cin >> N; vector<i64> A(N); for (i64 i = 0; i < N; i++) { cin >> A[i]; } N = min(N, 8LL); vector<i64> p(200, -1); for (i64 bit = 1; bit < (1LL << N); bit++) { i64 sum = 0; for (i64 i = 0; i < N; i++) { if (bit & (1 << i)) { (sum += A[i]) %= 200; } } if (p[sum] == -1) { p[sum] = bit; } else { cout << "Yes" << endl; i64 x = 0, y = 0; for (i64 i = 0; i < N; i++) { if (p[sum] & (1LL << i)) { x++; } if (bit & (1LL << i)) { y++; } } cout << x; for (i64 i = 0; i < N; i++) { if (p[sum] & (1LL << i)) { cout << " " << i + 1; } } cout << endl << y; for (i64 i = 0; i < N; i++) { if (bit & (1LL << i)) { cout << " " << i + 1; } } cout << endl; return 0; } } cout << "No" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main(void){ int n; cin>>n; vector<long long> A(n); for(int i=0;i<n;i++) cin>>A[i]; long long ans = 10e17; for(int i=0;i<(1<<n);i++){ long long xorv = 0; long long orv = 0; for(int j=0;j<=n;j++){ if(j < n) orv = orv | A[j]; if(((i>>j)&1) || j==n){ xorv = xorv ^ orv; orv = 0; } } ans = min(ans, xorv); } cout << ans << endl; }
#include <cmath> #include <bits/stdc++.h> using namespace std; int main(){ long r, x, y; cin >> r >> x >> y; double f=sqrt(x*x+y*y); if(f<r){ cout << ceil(f/(double)r)+1 << endl; }else{ cout << ceil(f/(double)r) << endl; } return 0; }
#include <bits/stdc++.h> #define endl "\n" #define rep(i, n) for(int i = 0; i < int(n); i++) #define rep2(i, s, n) for(int i = (s); i < int(n); i++) #define e_b emplace_back #define all(x) (x).begin(),(x).end() using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> ipair; typedef pair<ll, ll> lpair; template <class T> ostream &operator << (ostream &o, const vector<T> &v) //vectorの中身を見る {o << "{"; for(int i = 0; i < (int)v.size(); i++) o << (i > 0 ? ", ":"") << v[i]; o << "}"; return o;} void map_p(map<int, int> &d){cout << "map: "; for(auto a : d){cout << "{" << a.first << ":" << a.second << "}, ";} cout << endl;} //mapの中身を見る void set_p(set<int> &d){cout << "set: "; for(int a : d){cout << a << ", ";} cout << endl;} //setの中身を見る int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12); ll r, x, y; cin >> r >> x >> y; ll dis_2 = x * x + y * y; ll now = 0; while(dis_2 >= now * now){ now++; } now--; // コーナーケース if(now < r){ cout << 2 << endl; return 0; } ll ans = 0; if(now * now == dis_2){ ans = (now - 1) / r + 1; }else{ if(now % r == 0) ans = (now - 1) / r + 1 + 1; else ans = (now - 1) / r + 1; } cout << ans << endl; return 0; }
#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; in(ts); while(ts--) { in(l,r); l*=2; if(l>r)o(0); else x=r-l+1,o((x*(x+1))/2); nw; } }
#include<bits/stdc++.h> using namespace std; int t; long long ans; long long l,r; int main() { cin>>t; for(int o=1;o<=t;o++) { cin>>l>>r; if(r<2*l) { printf("0\n"); continue; } ans=(r-l+1ll)*(r-2ll*l+1ll); ans-=r*(r-2ll*l+1ll)/2ll; cout<<ans<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin>>n; vector<int> a(n),b(n); for(int i = 0;i<n;++i){ cin>>a[i]; } for(int i = 0;i<n;++i){ cin>>b[i]; } int left = INT_MIN; int right = INT_MAX; for(int i = 0;i<n;++i){ left = max(left,a[i]); right = min(right,b[i]); } cout<< max(0,right-left+1); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int nem[1000]={0}; int N; cin >> N; int a[N], b[N]; for (int i = 0; i < N; i++) { cin >> a[i]; } for (int i = 0; i < N; i++) { cin >> b[i]; } for (int i = 0; i < N; i++) { for (int j = 0; j <1000; j++) { if (j < a[i]-1) { nem[j]++; } if (j > b[i] - 1) { nem[j]++; } else continue; } } int counter = 0; for (int k = 0; k < 1000; k++) { if (nem[k] == 0) { counter++; } } cout << counter << endl; }
// Author : heyuhhh // Created Time : 2021/03/26 09:30:22 #include<bits/stdc++.h> #define MP make_pair #define fi first #define se second #define pb push_back #define sz(x) (int)(x).size() #define all(x) (x).begin(), (x).end() #define INF 0x3f3f3f3f using namespace std; typedef long long ll; typedef pair<int, int> pii; //head const int N = 1e5 + 5; void run() { int n, m; cin >> n >> m; vector<string> s(n); for (int i = 0; i < n; i++) { cin >> s[i]; } int even = 0, odd = 0; ll ans = 1ll * n * (n - 1) / 2; for (int i = 0; i < n; i++) { int cnt = 0; for (int j = 0; j < m; j++) { cnt += (s[i][j] - '0'); } if (cnt & 1) { ans -= odd; ++odd; } else { ans -= even; ++even; } } cout << ans << '\n'; } int main() { #ifdef Local freopen("input.in", "r", stdin); #endif ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout << fixed << setprecision(20); run(); return 0; }
#include <bits/stdc++.h> #define ADD(a, b) a = (a + ll(b)) % mod #define MUL(a, b) a = (a * ll(b)) % mod #define MAX(a, b) a = max(a, b) #define MIN(a, b) a = min(a, b) #define rep(i, a, b) for(int i = int(a); i < int(b); i++) #define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--) #define all(a) (a).begin(), (a).end() #define sz(v) (int)(v).size() #define pb push_back #define sec second #define fst first #define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef pair<int, pi> ppi; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vl> mat; typedef complex<double> comp; void Debug() {cerr << '\n'; } template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){ cerr<<arg<<" ";Debug(rest...);} template<class T>ostream& operator<<(ostream& out,const vector<T>& v) { out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;} template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){ out<<"("<<v.first<<", "<<v.second<<")";return out;} const int MAX_N = 500010; const int MAX_V = 100010; const double eps = 1e-6; const ll mod = 1000000007; const int inf = (1 << 30) - 1; const ll linf = 1LL << 60; const double PI = 3.14159265358979323846; mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng) /////////////////////////////////////////////////////////////////////////////////////////////////// int N; string S; int A[MAX_N]; void solve() { cin >> N; cin >> S; for(int i = 0; i < N + 1; i++) cin >> A[i]; int K = 10000; for(int i = 0; i < N; i++) MIN(K, abs(A[i] - A[i + 1])); cout << K << "\n"; for(int j = 0; j < K; j++) { for(int i = 0; i < N + 1; i++) { cout << (A[i] + j) / K << " "; } cout << "\n"; } } uint32_t rd() { uint32_t res; #ifdef __MINGW32__ asm volatile("rdrand %0" :"=a"(res) ::"cc"); #else res = std::random_device()(); #endif return res; } int main() { #ifndef LOCAL ios::sync_with_stdio(false); cin.tie(0); #endif cout << fixed; cout.precision(20); cerr << fixed; cerr.precision(6); rng.seed(rd()); #ifdef LOCAL //freopen("in.txt", "wt", stdout); //for tester if(!freopen("in.txt", "rt", stdin)) return 1; #endif solve(); cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int n, a[200010], b[200010]; long long ans = 0; priority_queue <int, vector <int>, greater <int> > q; int main() { scanf("%d", &n); for (int i = n - 1; i >= 0; --i) { scanf("%d", &a[i]); ans += a[i]; } for (int i = 0; i < n; ++i) { int b; scanf("%d", &b); q.push(a[i]); q.push(b); ans += b; ans -= q.top(); q.pop(); } printf("%lld\n", ans); return 0; }
/** * author: mahfuzz * created: 01.11.2020 **/ #include <iostream> #include <math.h> #include <iomanip> using namespace std; typedef long long ll; int main(int argc, char* argv[]){ ios_base::sync_with_stdio(0); cin.tie(NULL); int n; cin >> n; ll man = 0, cheb = 0; double euclid; for(int i = 0; i < n; i++){ ll x; cin >> x; x = abs(x); man += x; cheb = max(cheb, x); euclid += ((x * 1.0) * (x * 1.0)); } cout << man << "\n"; cout <<fixed << setprecision(10)<< sqrt(euclid) << "\n"; cout << cheb << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> iint; typedef pair<ll,ll> llll; #define ALL(x) (x).begin(),(x).end() const ll zero = 0; const ll one = 1; const ll INF = 9223372036854775807; //10^18 const int inINF = 2147483647; //10^9 const ll MOD = 1000000007; //10^9+7 const ll MOD2 = 998244353; void Yes() {printf("Yes\n");} void No() {printf("No\n");} void YES() {printf("YES\n");} void NO() {printf("NO\n");} int main(){ int N; cin >> N; vector<ll> a(N); for (int i = 0; i < N; i++) { cin >> a[i]; } vector<ll> c(200, 0); for (int i = 0; i < N; i++) { c[a[i] % 200]++; } ll ans = 0; for (ll i = 0; i < 200; i++) { ans += c[i] * (c[i] - 1) / 2; } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; #define N 500050 typedef long long ll; inline ll read(){ ll x=0,f=1; char c=getchar(); while(c<'0'||c>'9'){ if(c=='-')f=-1; c=getchar(); } while(c>='0'&&c<='9'){ x=(x<<1)+(x<<3)+c-'0'; c=getchar(); } return x*f; } int n,a[N],b[N],ans; char s[N],t[N]; int main(){ n=read(); scanf("%s",s+1); scanf("%s",t+1); int sa=0,sb=0; for(int i=1;i<=n;++i)a[i]=s[i]-'0',sa+=a[i],b[i]=t[i]-'0',sb+=b[i]; if(sa^sb)return !printf("-1\n"); int i=1,j=1; while(true){ while(i<=n&&a[i])++i; while(j<=n&&b[j])++j; if(i>n&&j>n)break; if(i^j)++ans; ++i,++j; } printf("%d\n",ans); return 0; }
#include <bits/stdc++.h> // #include <atcoder/all> using namespace std; // 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 rrep(i, n) for (int i = n - 1; i >= 0; i--) #define rrep1(i, n) for (int i = n; i >= 1; i--) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define eb emplace_back #define fi first #define se second template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; typedef long long int ll; typedef pair<int, int> P; // typedef modint1000000007 mint; void speedUpIO() { cin.tie(nullptr); ios::sync_with_stdio(false); } template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } /*--------------------------------------------------*/ const int INF = (int)1e9; const int MAX = (int)1e5; void solve() { int m, h; cin >> m >> h; cout << ((h % m == 0) ? "Yes" : "No") << "\n"; } int main() { speedUpIO(); solve(); return 0; }
//#define _GLIBCXX_DEBUG //#include <atcoder/all> #include <bits/stdc++.h> #include <chrono> #include <random> #ifndef ATCODER_DSU_HPP #define ATCODER_DSU_HPP 1 #include <algorithm> #include <cassert> #include <vector> namespace atcoder { // Implement (union by size) + (path compression) // Reference: // Zvi Galil and Giuseppe F. Italiano, // Data structures and algorithms for disjoint set union problems struct dsu { public: dsu() : _n(0) {} dsu(int n) : _n(n), parent_or_size(n, -1) {} int merge(int a, int b) { assert(0 <= a && a < _n); assert(0 <= b && b < _n); int x = leader(a), y = leader(b); if (x == y) return x; if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y); parent_or_size[x] += parent_or_size[y]; parent_or_size[y] = x; return x; } bool same(int a, int b) { assert(0 <= a && a < _n); assert(0 <= b && b < _n); return leader(a) == leader(b); } int leader(int a) { assert(0 <= a && a < _n); if (parent_or_size[a] < 0) return a; return parent_or_size[a] = leader(parent_or_size[a]); } int size(int a) { assert(0 <= a && a < _n); return -parent_or_size[leader(a)]; } std::vector<std::vector<int>> groups() { std::vector<int> leader_buf(_n), group_size(_n); for (int i = 0; i < _n; i++) { leader_buf[i] = leader(i); group_size[leader_buf[i]]++; } std::vector<std::vector<int>> result(_n); for (int i = 0; i < _n; i++) { result[i].reserve(group_size[i]); } for (int i = 0; i < _n; i++) { result[leader_buf[i]].push_back(i); } result.erase( std::remove_if(result.begin(), result.end(), [&](const std::vector<int>& v) { return v.empty(); }), result.end()); return result; } private: int _n; // root node: -1 * component size // otherwise: parent std::vector<int> parent_or_size; }; } // namespace atcoder #endif // ATCODER_DSU_HPP using namespace std; using namespace atcoder; #define rep(i,n) for (int i = 0;i < (int)(n);i++) using ll = long long; const ll MOD=1000000007; //const ll MOD=998244353; //using mint = modint998244353; //using mint = modint1000000007; const long long INF = 1LL << 60; const double pi=acos(-1.0); int dx[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0}; int dy[9] = {0, 1, 0, -1, 1, -1, -1, 1, 0}; 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; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); // cout << fixed << setprecision(15); ll N,M; cin>>N>>M; if(M==0) { ll l=1; rep(i,N){ cout<<l<<' '<<l+1<<'\n'; l+=2; } return 0; } if(M<0||N<M+2) {cout<<-1<<'\n'; return 0;} rep(i,N-M-1) cout<<i+1<<' '<<int(1e9)-i<<'\n'; ll l=N-M; rep(i,M+1){ cout<<l<<' '<<l+1<<'\n'; l+=2; } return 0; }
#include<iostream> #include<sstream> #include<iomanip> #include<cstdlib> #include<algorithm> #include<vector> #include<map> #include<cmath> #include<string> #include<numeric> #include<queue> #define rep(i,p) for(long long int i=0;i<p;i++) #define reep(i,p) for(long long int i=1;i<=p;i++) #define ll long long #define MOD 1000000007 #define INF 9223372036854775800 using namespace std; int main(){ ll int N; cin >> N; vector< vector < ll int > > C(N,vector< ll int > (N) ); ll int Su=0; rep(i,N){ rep(j,N){ cin >> C[i][j]; Su += C[i][j]; } } vector< vector < ll int > > kari; vector< ll int > A(N); vector< ll int > B(N); //cout << Su << endl << endl; /* rep(i,100){ ll int sum = 0; A[0] = i; rep(j,N){ B[j] = C[0][j] - A[0]; sum += B[j] * N; } rep(j,N){ A[j] = C[j][0] - B[j]; sum += A[j] * N; } rep(j,N){ cout << sum << endl; } } */ rep(i,N){ rep(k,N){ ll int sum = 0; A[i] = 0; rep(j,N){ B[j] = C[i][j] - A[i]; sum += B[j] * N; } rep(j,N){ A[j] = C[j][k] - B[k]; sum += A[j] * N; } // cout << sum << endl; if( sum == Su ){ A[0] = A[0] - (*min_element(A.begin(),A.end())); rep(j,N){ B[j] = C[0][j] - A[0]; sum += B[j] * N; } rep(j,N){ A[j] = C[j][0] - B[0]; sum += A[j] * N; } rep(a,N){ rep(b,N){ if( C[a][b] != A[a] + B[b] ){ cout << "No" << endl; return 0; } } } cout << "Yes" << endl; rep(j,N-1){ cout << A[j] << " "; } cout << A[N-1] << endl; rep(j,N-1){ cout << B[j] << " "; } cout << B[N-1] << endl; return 0; } // rep(j,N){ // cout << A[0] - (*min_element(A.begin(),A.end())) << " " << // A[0] + (*min_element(B.begin(),B.end())) << endl; // } // cout << endl; } } cout << "No" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long const int MAXN = 5e2 + 50; int diffa[MAXN], diffb[MAXN]; int a[MAXN], b[MAXN], c[MAXN][MAXN]; bool check(int n) { for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) if (a[i] + b[j] != c[i][j] || a[i] < 0 || b[j] < 0) return false; return true; } signed main(/*int argc, char *argv[]*/) { //ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) cin >> c[i][j]; int mn1 = 0x3f3f3f3f, res1 = 0, mn2 = 0x3f3f3f3f, res2 = 0; for (int i = 2; i <= n; ++i) diffb[i] = c[1][i] - c[1][i - 1], res1 += diffb[i], mn1 = min(mn1, res1); for (int i = 2; i <= n; ++i) diffa[i] = c[i][1] - c[i - 1][1], res2 += diffa[i], mn2 = min(mn2, res2); for (int i = 2; i <= n; ++i) { for (int j = 2; j <= n; ++j) { if (c[i][j] - c[i][j - 1] != diffb[j]) { puts("No"); system("pause"); return 0; } } } //cout << mn1 << ' ' << mn2 << '\n'; for (int i = -mn2; i <= c[1][1] + mn1; ++i) { a[1] = i, b[1] = c[1][1] - a[1]; //if (b[1] - mn1 < 0) break; for (int i = 2; i <= n; ++i) a[i] = a[i - 1] + diffa[i], b[i] = b[i - 1] + diffb[i];; if (check(n)) { puts("Yes"); for (int i = 1; i <= n; ++i) cout << a[i] << " \n"[i == n]; for (int i = 1; i <= n; ++i) cout << b[i] << " \n"[i == n]; system("pause"); return 0; } } puts("No"); system("pause"); return 0; }
#include<iostream> #include<vector> #include<iomanip> using namespace std; int score(string S){ int res=0; vector<int> a(10); for(char c: S)a[c-'0']++; for(int i=1; i<=9; i++){ int x=1; for(int j=0; j<a[i]; j++)x*=10; res+=i*x; } return res; } int main(){ int K; long long cnt=0; string S,T; cin >> K >> S >> T; vector<int> c(10,K); for(int i=0; i<4;i++){ c[S[i]-'0']--; c[T[i]-'0']--; } for(int i=1; i<=9;i++)for(int j=1; j<=9; j++){ S[4] = '0' + i; T[4] = '0' + j; if(score(S) > score(T)){ cnt += (long long)c[i]*(c[j]-(i==j)); } } long long u=9LL*K-8; cout << fixed << setprecision(9) << (double)cnt/(u*(u-1)) << endl; }
#include<bits/stdc++.h> #define rep(i, a, b) for(int i = a; i <= b ; ++i) #define per(i, a, b) for(int i = b ; i >= a ; --i) #define int long long using namespace std; double card[10]; int S[6],T[6]; bool bigger() { int sums=0,sumt=0; for(int i=1;i<=9;i++) { int x=i; for(int j=1;j<=5;j++)if(S[j]==i)x*=10; sums+=x; x=i; for(int j=1;j<=5;j++)if(T[j]==i)x*=10; sumt+=x; } return sums>sumt; } signed main() { double tot;int K; cin>>K; tot=(double)(9*K); string s,t; cin>>s>>t; tot-=8.0; for(int i=1;i<=9;i++)card[i]=K; rep(i,0,3) { S[i+1]=(int)(s[i]-'0'); T[i+1]=(int)(t[i]-'0'); card[S[i+1]]--; card[T[i+1]]--; } double win=0.0; rep(i,1,9) { if(card[i]==0)continue; rep(j,1,9) { if(card[j]==0)continue; if(i==j)continue; S[5]=i;T[5]=j; if(bigger()) { double base=tot*(tot-1.0); double son=(double)(card[i]*card[j]); son/=base; win+=son; } } if(card[i]>=2) { S[5]=i;T[5]=i; if(bigger()) { double base=tot*(tot-1.0); double son=(double)(card[i]*(card[i]-1)); son/=base; win+=son; } } } // if(win>1.0)win=1.0; printf("%.8f",win); return 0; }
///Bismillahir Rahmanir Rahim #include "bits/stdc++.h" #define ll long long #define int ll #define fi first #define si second #define mp make_pair #define pb push_back #define pi pair<int,int> #define nd(a,b,c) mp(mp(a,b),c) #define clr(x) memset(x,0,sizeof(x)); #define f(i,l,r) for(int i=l;i<=r;i++) #define rf(i,r,l) for(int i=r;i>=l;i--) #define done(i) cout<<"done = "<<i<<endl; #define show(x,y) cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl; #define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; const ll inf=2e18; const int mod=1e9+7; const int M=200005; int a[M]; main() { fast int n,m; cin>>n>>m; if(m==0) { cout<<"1\n";return 0; } f(i,1,m) { cin>>a[i]; } sort(a+1,a+m+1); m=unique(a+1,a+m+1)-a-1; a[0]=0; a[m+1]=n+1; int mn=n; int ses=0; f(i,1,m+1) { int lft=a[i-1]+1; int rgt=a[i]-1; if(lft<=rgt) { mn=min(mn,rgt-lft+1); } } f(i,1,m+1) { int lft=a[i-1]+1; int rgt=a[i]-1; if(lft<=rgt) { int len=rgt-lft+1; ses+=((len+mn-1)/mn); } } cout<<ses<<"\n"; return 0; }
#include <iostream> #include <cmath> #include <vector> #include <algorithm> #include <cstring> #include <map> #include <set> #include <numeric> #include <cassert> using namespace std; void setIO(const string &name = "") { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); if (name.length()) { freopen((name + ".in").c_str(), "r", stdin); freopen((name + ".out").c_str(), "w", stdout); } } typedef long long ll; #define int ll #define INF int(1e18) + 15 #define mod 1000000007 #define DO if(true) #define vt vector #define rep(i, a, b) for(auto (i)=a;(i)<(b);(i)++) #define trav(a, x) for(auto& (a): (x)) struct RMQ { int size = 1; vt<int> v, logTable; vt<vt<int>> table; void makeLogTable(){ logTable.assign(size + 1, 0); rep(i, 2, size + 1){ logTable[i] = logTable[i / 2] + 1; } } void makeTable(){ table.assign(logTable.back() + 1, vt<int>(size)); table[0] = v; for(int row = 1; row <= logTable.back(); row++){ for(int i = 0; (i + (1 << row)) <= size; i++){ table[row][i] = min(table[row - 1][i], table[row - 1][i + (1 << (row - 1))]); } } } void init(int n, const vt<int>& x){ size = n; v = x; makeLogTable(); makeTable(); } int calc(int l, int r){ int lg = logTable[r - l]; int res = min(table[lg][l], table[lg][r - (1 << lg)]); return res; } }; #define N int(1e4) + 10 int n; vt<int> a; signed main() { setIO(); cin >> n; a.resize(n); trav(c, a){ cin >> c; } RMQ rmq; rmq.init(n, a); auto binLeft = [&](int idx){ int lo = 0, hi = idx; int res = idx; while(lo <= hi){ int mid = (lo + hi) / 2; if(rmq.calc(mid, idx + 1) == a[idx]){ res = mid; hi = mid - 1; }else { lo = mid + 1; } } return res; }; auto binRight = [&](int idx){ int lo = idx, hi = n - 1; int res = idx; while(lo <= hi){ int mid = (lo + hi) / 2; if(rmq.calc(idx, mid + 1) == a[idx]){ res = mid; lo = mid + 1; }else { hi = mid - 1; } } return res; }; vt<int> s(n), e(n); rep(i, 0, n){ s[i] = binLeft(i); e[i] = binRight(i); } int ans = *max_element(a.begin(), a.end()); rep(i, 0, n){ ans = max(ans, (e[i] - s[i] + 1) * a[i]); } cout << ans << '\n'; return 0; }
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,a,b) for(int i=a;i>=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() //#pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } //--------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------- void _main(){ double N; cin >> N; double ans = 0; rep(i,1,N)ans += 1.0*N/(N-i); printf("%.9f\n", ans); return; }
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <queue> #include <utility> #include <tuple> #include <cmath> #include <numeric> #include <set> #include <map> #include <array> #include <complex> #include <iomanip> #include <cassert> using ll = long long; using std::cin; using std::cout; using std::endl; 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 = (int)1e9 + 7; const long long INF = 1LL << 60; void solve() { using real = long double; int n; cin >> n; std::vector<real> dp(n + 1); for (int i = 1; i < n; ++i) { dp[i + 1] = (dp[i] + (real)n / (real)(n - i)); } cout << std::fixed << std::setprecision(15) << dp[n] << "\n"; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); int kkt = 1; //cin >> kkt; while(kkt--) solve(); return 0; }
#include <iostream> #include <vector> #include <array> #include <list> #include <queue> #include <stack> #include <set> #include <map> #include <unordered_map> #include <unordered_set> #include <utility> #include <string> #include <sstream> #include <algorithm> #include <random> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <cmath> #include <cassert> #include <climits> #include <bitset> #include <functional> #include <iomanip> #include <random> #define FOR_LT(i, beg, end) for (decltype(end) i = beg; i < end; i++) #define FOR_LE(i, beg, end) for (decltype(end) i = beg; i <= end; i++) #define FOR_DW(i, beg, end) for (decltype(beg) i = beg; end <= i; i--) #define REP(n) for (decltype(n) repeat_index = 0; repeat_index < n; repeat_index++) using namespace std; template<typename T, size_t S> T minval(const T(&vals)[S]) { T val = numeric_limits<T>::max(); FOR_LT(i, 0, S) { val = min(val, vals[i]); } return val; } template<typename T, size_t S> T maxval(const T(&vals)[S]) { T val = numeric_limits<T>::min(); FOR_LT(i, 0, S) { val = max(val, vals[i]); } return val; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout << fixed << setprecision(20); int n, m; cin >> n >> m; vector<int> as(n); for (auto& a : as) { cin >> a; } vector<int> cs(n + 1); set<int> uu; FOR_LE(i, 0, n + 1) uu.insert(i); FOR_LT(i, 0, m) { if (cs[as[i]] == 0) uu.erase(as[i]); cs[as[i]]++; } int l = 0; int r = m; int ans = *uu.begin(); while (r != n) { cs[as[l]]--; if (cs[as[l]] == 0) uu.insert(as[l]); if (cs[as[r]] == 0) uu.erase(as[r]); cs[as[r]]++; ans = min(ans, *uu.begin()); l++; r++; } 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; vvi adj(MAXN); vi arr(MAXN); bool check(int u, int c) { for (int v : adj[u]) if (arr[v] == c) return false; return true; } vi dd(MAXN); set<int> s; int n; int cnt3 = 0; int brute(int idx) { if (idx == n) return 1; if (dd[idx] == 0) { s.emplace(idx); return brute(idx + 1); } int ans = 0; for (int i = 0; i < 3; ++i) if (check(idx, i)) { arr[idx] = i; ans += brute(idx + 1); arr[idx] = -1; } return ans; } int poww() { int ans = 1; for (int i = 0; i < s.size(); ++i) ans *= 3; return ans; } // #define MULTIPLE_TEST_CASES void solve(const int test) { cin >> n; int m; cin >> m; while (m--) { int u, v; cin >> u >> v; --u, --v; if (u < v) swap(u, v); ++dd[u]; ++dd[v]; adj[u].eb(v); } int val = brute(0); cout << poww() * val << 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 for (int i = 1; i <= t; ++i) solve(i); }
#include <iostream> #include <string> #include <vector> #include <array> #include <stack> #include <queue> #include <deque> #include <algorithm> #include <set> #include <map> #include <unordered_map> #include <bitset> #include <cmath> #include <functional> #include <cassert> #include <iomanip> #include <numeric> #include <memory> #include <random> #define VV(a, b, c, d) vector<vector<d>>(a, vector<d>(b, c)) #define VVV(a, b, c, d, e) vector<vector<vector<e>>>(a, VV(b, c, d, e)); #define all(obj) (obj).begin(), (obj).end() typedef long long ll; typedef long double ld; typedef std::vector<ll> v1; typedef std::vector<v1> v2; typedef std::vector<v2> v3; using namespace std; long long floor_sum(long long n,long long m,long long a,long long b){ long long res=0; if(a>=m){ res+=n*(n-1)/2*(a/m); a%=m; } if(b>=m){ res+=n*(b/m); b%=m; } long long y_max=(a*(n-1)+b)/m; if(y_max==0) return res; return res+y_max+floor_sum(y_max,a,m,(a*(n-1)+b)-m*y_max); } void solve(){ ll x, y, p, q; scanf("%lld %lld %lld %lld", &x, &y, &p, &q); ll l = 0, r = 1000000000; if(floor_sum(r, p+q, 2*(x+y), x+y+q-1) == floor_sum(r, p+q, 2*(x+y), x)){ std::cout << "infinity" << '\n'; return; } while(r-l>1){ ll mid = (l+r)/2; if(floor_sum(mid, p+q, 2*(x+y), x+y+q-1) == floor_sum(mid, p+q, 2*(x+y), x)) l = mid; else r = mid; } ll distsum = 2*(r-1)*(x+y) + x; if(distsum % (p+q) >= p) printf("%lld\n", distsum); else printf("%lld\n", distsum + (p - distsum % (p+q))); } int main(){ int t; scanf("%d\n", &t); for(int i=0;i<t;i++) solve(); }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; int main(){ int x1,y1,x2,y2; scanf("%d%d%d%d",&x1,&y1,&x2,&y2); if(x1==x2 && y1==y2){ puts("0"); } else if(x1+y1==x2+y2 || x1-y1==x2-y2 || abs(x1-x2)+abs(y1-y2)<=3){ puts("1"); } else if((x1+y1)%2==(x2+y2)%2){ puts("2"); } else{ int ans=3; for(int dx=-3;dx<=3;dx++) for(int dy=-3;dy<=3;dy++) if(abs(dx)+abs(dy)<=3) { int x3,y3; x3=x1+dx; y3=y1+dy; if(x3+y3==x2+y2 || x3-y3==x2-y2 || abs(x3-x2)+abs(y3-y2)<=3){ ans=2; } x3=x2+dx; y3=y2+dy; if(x1+y1==x3+y3 || x1-y1==x3-y3 || abs(x1-x3)+abs(y1-y3)<=3){ ans=2; } } printf("%d\n",ans); } return 0; }
#include<bits/stdc++.h> using namespace std; const int N=1e4+10; int a[N],b[N],pre[N]; int main() { int n; cin>>n; for(int i=0;i<n;i++) { cin>>a[i]; pre[a[i]]++; } for(int i=0;i<n;i++) { cin>>b[i]; pre[b[i]+1]--; } int ans=0; for(int i=0;i<N;i++) pre[i]+=pre[i-1]; for(int i=0;i<N;i++) { if(pre[i]>=n) ans++; } cout<<ans; return 0; }
#include<iostream> #include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin>>n; vector<int> a; for (int i = 0; i < n; ++i) { int k; cin>>k; a.push_back(k); } int ans=0; for (int i = 0; i < a.size(); ++i) { int min=a[i]; for (int j = i; j <a.size() ; j++) { if(a[j]<min) min=a[j]; //cout<<min<<' '<<i<<' '<<j<<' '; if (min*(j-i+1)>ans) ans=min*(j-i+1); //cout<<ans<<endl; } } cout<<ans; }
#include<bits/stdc++.h> using namespace std; ///******************************** C o n t a i n e r ********************************/// typedef unsigned long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef vector<pii> vii; typedef vector<pll> vll; ///*********************************** C o n s t ***********************************/// const int N=1e6+123; const double PI = acos(-1); const ll MOD=1000000007; ///1e9+7 ///********************************** M a r c o ***********************************/// #define pb push_back #define MP make_pair #define F first #define S second #define test ll tc; cin>>tc; while(tc--) #define forn(i,n) for(i=0;i<n;i++) #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define sz(x) x.size() #define el <<'\n' #define sp <<' ' #define print(a) {for(auto x:a)cout<<x<<" ";cout<<endl;} #define mem(a,b) memset(a, b, sizeof(a)) #define gcd(a,b) __gcd(a,b) #define lcm(a,b) (a*(b/gcd(a,b))) #define sqr(a) (a)*(a) #define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout); #define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield); ///*********************************** F u n c t i o n ***********************************/// ll powmod(ll a,ll b,ll MOD){ a%=MOD;if(!a) return 0;ll pr=1;while(b>0){if(b&1){pr*=a;pr%=MOD;--b;}a*=a;a%=MOD;b/=2;}return pr;} ll modinverse(ll a){return powmod(a,MOD-2,MOD);} bool isPrime(ll n){ if(n<=1)return false;if(n<=3)return true;if(n%2==0 or n%3==0)return false;for(ll i=5;i*i<=n;i+=6){if(n%i==0 or n%(i+2)==0)return false;}return true;} void seive(bool a[]){vl v; ll mx=sqrt(N),ii,jj;for(ii=3;ii<=mx;ii+=2)if(!a[ii])for(jj=ii*ii;jj<N;jj+=2*ii)a[jj]=true; v.pb(2);for(ii=3;ii<N;ii+=2)if(!a[ii])v.pb(ii);} void numofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<N;jj+=ii){if(jj==ii*ii) a[jj]++; else a[jj]+=2;}}} void sumofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<N;jj+=ii){if(jj==ii*ii) a[jj]+=ii; else a[jj]+=ii+jj/ii;}}} ///**************************************************** C o d e ****************************************************/// ///-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=/// ll n; ll dp[205][205]; ll rec(ll position, ll cut) { if(cut==11) return (position>0); if(dp[position][cut]==-1){ ll ans=0,i,j; for(i=1;i<position;i++){ ans+=rec(position-i,cut+1); } dp[position][cut]=ans; } return dp[position][cut]; } void _case() { cin>>n; mem(dp,-1); cout<<rec(n,0)<<endl; } main() { fastio(); _case(); } ///See you soon
//#pragma GCC optimize(3) #include <bits/stdc++.h> using namespace std; #define lson l,mid,rt<<1 #define rson mid+1,r,rt<<1|1 #define inf 0x3f3f3f3f #define INF 0x7fffffff #define infll 0x3f3f3f3f3f3f3f3f #define il inline #define re register #define pb push_back #define db double #define ll long long #define ull unsigned long long #define pii pair<int,int> #define pll pair<ll,ll> #define puu pair<ull,ull> #define MP make_pair #define lowbit(x) x&(-x) #define fi first #define se second il ll read() { char ch = getchar(); ll p = 1,data = 0; while(ch<'0'||ch>'9') { if(ch == '-')p = -1; ch = getchar(); } while(ch>='0'&&ch<='9') { data = data*10+(ch^48); ch = getchar(); } return p*data; } il ll gcd(ll a,ll b) { if(!a || !b) return (!a)?b:a; while(b ^= a ^= b ^= a %= b); return a; } il ll lcm(ll a,ll b) { return a*b/gcd(a,b); } void exgcd(ll a, ll b, ll &x,ll &y) { if(!b) x = 1, y = 0; else { exgcd(b, a % b, y, x); y -= x * (a / b); } } il ll qpow(ll a,ll b) { ll r = 1; while(b) { if(b&1)r = a*r; a = a*a; b>>=1; } return r; } const int mod = 1e9+7; int main() { int n = read(); ll t = 1; for(int i = 2; i <= n; i++) t = lcm(i,t); cout<<t+1<<endl; return 0; } /* */
// Parasparopagraho Jīvānām #pragma GCC optimize ("O3") #pragma GCC target ("sse4") #include <bits/stdc++.h> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> #include <ext/rope> using namespace __gnu_pbds ; using namespace __gnu_cxx ; using namespace std ; typedef long long ll ; typedef long double ldb ; typedef pair<int, int> pii ; typedef pair<int, ll> pil ; typedef pair<ll,ll> pll ; typedef vector<int> vi ; typedef vector<ll> vll ; typedef vector<pii> vpi ; typedef vector<pll> vpl ; typedef vector<bool> vb ; typedef vector<pair<ll,int> > vpli ; typedef vector<int,pil> edges ; typedef vector<vi> matrix ; typedef priority_queue<int> pqu ; template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update> ; #define rep(i,a,b) for (int i = (a); i <= (b); i++) #define per(i,b,a) for (int i = (b); i >= (a); i--) #define mp make_pair #define eb emplace_back #define pb push_back #define pob pop_back #define fi first #define se second #define ins insert #define bk back #define con continue #define lbd lower_bound #define ubd upper_bound #define sz(x) (int)x.size() #define all(x) begin(x), end(x) #define pr cout << // I don't like this but my laptop's 'O' key is not functioning well /* Careful when using long long __builtin_clz(int x) {} //: the number of zeros at the beginning of the number __builtin_ctz(int x) {} //: the number of zeros at the end of the number __builtin_popcount(int x) {} //: the number of ones in the number __builtin_parity(int x) {} //: the parity (even or odd) of the number of ones */ const int mod1 = 1000000007 ; const int mod2 = 998244353 ; const ll infl = 4e18 ; const int infi = 2e9 ; const int maxn = 1e6 + 5 ; const int block = 500 ; const int logn = 60 ; const int alpha = 27 ; const ldb pi = acos(-1) ; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) ; int rng_lr(int a, int b) { int ret ; ret = uniform_int_distribution<int>(a, b)(rng) ; return ret ; // For shuffling use shuffle(all, rng) ; } ll modpow(ll a, ll b, int MOD) { ll res = 1 ; while(b) { if(b&1) { res = res*a ; res %= MOD ; } a *= a ; a %= MOD ; b >>= 1 ; } return res%MOD ; } void upmin(int &a, int b) { if(a < b) { a = b ; } } void relax(int &a, int b) { if(a > b) { a = b ; } } ll add(ll a, ll b, int MOD) { a += b ; if(a >= MOD) { a -= MOD ; } return a ; } ll sub(ll a, ll b, int MOD) { a -= b ; if(a < 0) { a += MOD ; } return a ; } ll mul(ll a, ll b, int MOD) { b %= MOD ; a *= b ; a %= MOD ; return a ; } ll inverse(ll a, ll MOD) { a = modpow(a, MOD - 2, MOD) ; return a ; } ll lcm(ll a, ll b) { ll ret ; ll g = __gcd(a, b) ; ret = a/g ; ret = ret*b ; return ret ; } int icast(char ch) { return int(ch-'a') ; } void hyn(int a, int b) { if(a == b) cout << "YES\n" ; else cout << "NO\n" ; } void pyd(int a, int b) { if(a == b) cout << "First\n" ; else cout << "Second\n" ; } // Check constraints + overflows + types in typedef int main() { ios::sync_with_stdio(false) ; cin.tie(NULL) ; int n ; string s ; cin >> n >> s ; if(s[0] != s[n-1]) { pr "1\n" ; return 0 ; } rep(i,1,n-2) { if(s[i] != s[0] && s[i + 1] != s[0]) { pr "2\n" ; return 0 ; } } pr "-1\n" ; return 0 ; }
#include <bits/stdc++.h> using namespace std; #define pi acos(-1.0) #define pb push_back #define mp make_pair #define ll long long #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define testcase ll T; cin >> T; for (ll tc = 1; tc <= T; tc++) #define M 1000000007 #define MM 998244353 #define eps 1e-8 #define eq(x,y) (fabs((x)-(y)) < eps) #define r2 1.41421356237 ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;} int main() { //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //testcase { ll ans=0; int n,m; cin>>n>>m; char g[n+2][m+2]={}; for(int i=0;i<n+2;i++) { for(int j=0;j<m+2;j++) { g[i][j]='#'; } } for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { char q; cin>>q; g[i][j]=q; } } for(int i=1;i<=n;i++) { int c=1; for(int j=1;j<=m+1;j++) { if(g[i][j]=='.' && g[i][j-1]=='.') { c++; } else { ans+=c-1; c=1; } } //cout<<ans<<'\n'; //ans+=((c*(c-1))/2); c=1; } for(int i=1;i<=m;i++) { int c=1; for(int j=1;j<=n+1;j++) { if(g[j][i]=='.' && g[j-1][i]=='.') { c++; } else { ans+=c-1; c=1; } } //cout<<ans<<'\n'; //ans+=((c*(c-1))/2); c=1; } cout<<ans; //} return 0; }
#include <bits/stdc++.h> using namespace std; template<typename T = int> vector<T> create(size_t n){ return vector<T>(n); } template<typename T, typename... Args> auto create(size_t n, Args... args){ return vector<decltype(create<T>(args...))>(n, create<T>(args...)); } int main(){ ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> a(n); for(int i = 0; i < n; i++) cin >> a[i]; auto get = [&](long double p){ long double sum = 0; for(int i = 0; i < n; i++){ sum += p + a[i] - min((long double) a[i], 2 * p); } return sum; }; long double lo = 0, hi = 1e9; for(int r = 0; r < 200; r++){ long double f1 = lo + (hi - lo) / 3, f2 = lo + 2 * (hi - lo) / 3; if(get(f1) < get(f2)) hi = f2; else lo = f1; } cout << fixed << setprecision(12) << get(lo)/n << '\n'; return 0; }
#include<iostream> #include<string> #include<vector> #include<algorithm> using namespace std; int gcd(int, int); int main(void){ //init val int n, kosuu = 0; cin >> n; int *a;int *b;int *c; a = new int[n]; b = new int[n]; c = new int[1000]; for (int i = 0; i < n; i++){ cin >> a[i]; } for (int i = 0; i < n; i++){ cin >> b[i]; } for (int i = 0; i < 1000; i++){ c[i] = 0; } //main code for (int i = 0; i < n; i++){ for (int j = a[i] - 1; j < b[i]; j++){ c[j]++; } } for (int i = 0; i < 1000; i++){ if (c[i] == n){ kosuu++; } } cout << kosuu << endl; return 0; } int gcd(int x, int y){ if (x%y == 0){ return y; }else{ return gcd(y, x%y); } }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define T \ int t; \ cin >> t; \ while (t--) #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) #define PI 3.141592653589793238462643383 #define pb push_back #define all(s) s.begin(), s.end() void print(bool flag) { if (flag) { cout << "Yes" << endl; } else { cout << "No" << endl; } } int main() { fast; ll n, w; cin >> n >> w; bool flag = true; ll s[n], t[n], p[n]; ll mx = INT_MIN; for (int i = 0; i < n; i++) { cin >> s[i] >> t[i] >> p[i]; mx = max(mx, t[i]); } vector<ll> ans(mx + 1, 0); for (int i = 0; i < n; i++) { ans[s[i]] += p[i]; ans[t[i]] += (-1 * p[i]); } ll temp = 0; for (int i = 0; i <= mx; i++) { temp += ans[i]; //cout << temp << " "; if (temp > w) { flag = false; } } print(flag); }
#include<bits/stdc++.h> using namespace std; using ll=long long; int main() { int n; int D; int H; cin >> n >> D >> H; vector<int> d(n), h(n); for(int i=0; i<n; ++i) cin >> d[i] >> h[i]; double ans = 0; for(int i=0; i<n; ++i) { double b = double(D * h[i] - d[i] * H) / (D - d[i]); ans = max(ans, b); } printf("%.10lf\n", ans); }
#include<iostream> #include<string> #include<algorithm> #include<vector> #include<iomanip> #include<math.h> #include<complex> #include<queue> #include<deque> #include<stack> #include<map> #include<set> #include<bitset> #include<functional> #include<assert.h> #include<numeric> using namespace std; #define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i ) #define rep(i,n) REP(i,0,n) using ll = long long; constexpr int inf=1e9+7; constexpr ll longinf=1LL<<60 ; constexpr ll mod=1e9+7 ; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin>>n; vector<int> ans(n+1); ans[1]=1; for(int i=1;i<=n;i++){ for(int j=2*i;j<=n;j+=i){ ans[j]=max(ans[i]+1,ans[j]); } } rep(i,n)cout<<ans[i+1]<<" \n"[i+1==n]; return 0; }
#include"bits/stdc++.h" using namespace std; typedef long long ll; int main(){ ll n; cin>>n; ll count=1; ll p=2; vector<ll>a(n); for(ll i=0;i<n;i++){ a[i]=count; if(i+2==p){ count++; p=p*2; } } for(ll i=0;i<n;i++){ cout<<a[i]<<" "; } }
//BY: YASH JAIN, CF: BitSane #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; #define May_the_fork_be_with_you ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define all(x) (x).begin(), (x).end() #define rall(v) v.rbegin(),v.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, n) for (int i = (int)(n) - 1; i >= 0; --i) #define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i) #define deb(x) cout<<#x<<": "<<x<<endl; #define debn(x) cout<<#x<<": "<<x<<" "; #define MOD 1000000007 #define mod 998244353 #define INF 1e18 #define ll long long #define f first #define s second #define pb push_back #define eb emplace_back #define endl "\n" #define int long long #define N 100005 #define sq(x) ((x)*(x)) typedef vector<int> vi; ll gcd(ll a, ll b) {if (!b)return a; return gcd(b, a % b);} ll power(ll x, ll y, ll p = INF) {ll res = 1; x %= p; while (y > 0) {if (y & 1)res = (res * x) % p; y = y >> 1; x = (x * x) % p;} return res;} // Do Not use power when calculating powers of 2 (its inefficient) void solve() { double x, y, z; cin >> x >> y >> z; double pr = y / x; for (double i = 1000000; i >= 0; i--) { double cur = i / z; if (cur < pr) { cout << (int)i; break; } } } int32_t main() { #ifndef ONLINE_JUDGE // for geting input form input.txt freopen("input.txt", "r", stdin); // for wrting output to output.txt freopen("output.txt", "w", stdout); #endif May_the_fork_be_with_you int t = 1; int x = 1; // cin >> t; cout << fixed << setprecision(12); while (t--) { // cout << "Case #" << x << ": "; solve(); x++; } #ifndef ONLINE_JUDGE cerr << "Time Taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl; #endif }
/* بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ لَا إِلَٰهَ إِلَّا ٱللَّٰهُ مُحَمَّدٌ رَسُولُ ٱللَّٰهِ */ #include<bits/stdc++.h> using namespace std; #define ll long long #define sort(v) sort(v.begin(),v.end()) #define rev(v) reverse(v.begin(),v.end()) #define pb push_back ll mod= 1000000007; vector<ll>sv; ll ar[1000000+9]= {0}; void seiv() { ll n=1000000,i,j; ar[1]=1; for(i=4; i<=n; i+=2)ar[i]=1; for(i=3; i<=n; i+=2) { if(ar[i]==0) { for(j=i*i; j<=n; j+=i*2)ar[j]=1; } } for(i=2; i<=n; i++) { if(ar[i]==0)sv.pb(i); } } int main() { // seiv(); ll t; // cin>>t; // while(t--) { ll a,b,c=0,d=0,e=0,i,j,k=0,l=1; cin>>a>>b>>c; c=b*c; if(c%a==0){ cout<<(c-1)/a<<endl; } else cout<<c/a<<endl; } return 0; }
#include <bits/stdc++.h> #define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define int long long int #define MAX 1e9 #define MIN -1e9 #define mod 1000000007 #define pb push_back #define all(x) (x).begin(), (x).end() #define debug(x) cerr<<#x<<'='<<(x)<<endl; #define output(x) cout << ( x ? "Yes" : "No" ) << '\n' ; #define mxn 100005 using namespace std; void solve(){ int x; cin >> x ; cout << max(0LL, x) << '\n' ; } int32_t main() { FLASH int t = 1; // cin >> t; while(t--){ solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int x; cin>>x; if(x<0) { cout<<0<<"\n"; } else { cout<<x<<"\n"; } return 0; }
#include<bits/stdc++.h> using namespace std; #define ff first #define ss second #define pb push_back #define mp make_pair #define ll long long #define ld long double #define pii pair<ll,ll> #define vi vector<ll> #define mii map<ll,ll> #define pqi priority_queue<ll> //max pq #define pqd priority_queue<ll,vi,greater<ll> > #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define MOD 1000000007 #define inf 1e18 #define ps(x,y) fixed<<setprecision(y)<<x #define pw(b,p) pow(b,p) + 0.1 #define f(i,k,n) for(ll i=k;i<n;i++) #define fd(i,start,end) for(ll i=start;i>=end;i--) ll power(ll a, ll b, ll mod) {ll res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) {if (b & 1)res = res * a % mod; a = a * a % mod;} return res;} ll power(ll a, ll b) {ll res = 1; assert(b >= 0); for (; b; b >>= 1) {if (b & 1)res = res * a ; a = a * a;} return res;} ll min( ll a, ll b) { return (a < b) ? a : b;} ll max(ll a, ll b) {return (a > b) ? a : b;} ll gcd (ll a, ll b) {if (a == 0) return b; return gcd(b % a, a);} void bwayne() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } // ll n; // cin >> n; // vi a(n); // f(i, 0, n) { // cin >> a[i]; // } // vector<vi> a(n,vector<vi>(m,0)); // f(i,0,n){ // f(j,0,m){ // cin>>a[i][j]; // } // } void solve() { ll n; cin >> n; vi a(n), b(n); f(i, 0, n) { cin >> a[i] >> b[i]; } ll ans = inf; f(i, 0, n) { ans = min(ans, a[i] + b[i]); } // cout << ans; f(i, 0, n) { f(j, 0, n) { if (i == j) continue; else ans = min(ans, max(a[i], b[j])); } } cout << ans; } int main() { bwayne();// remember ll t = 1; // cin >> t; for (ll tt = 1; tt <= t; tt++) { // cout << "Case #" << tt << ": "; solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; template<class T,class U> using P = pair<T,U>; template<class T> using vec = vector<T>; template<class T> using vvec = vector<vec<T>>; #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) int main(){ int n; cin >> n; vec<ll> a(n); rep(i, n) cin >> a[i]; sort(a.begin(), a.end()); vec<ll> s(n+1, 0); rep(i, n) s[i+1] = s[i] + a[i]; ll ans = 0; rep(i, n) { ans += (s[n] - s[i]) - (n - i) * a[i]; } cout << ans << endl; }
#include <iostream> #include <string> #include <bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; vector<vector<int>> v (n, vector<int>(3)); for (int i = 0; i < n; i++) { cin >> v[i][0] >> v[i][1] >> v[i][2]; } vector<int> a(n), p(n), x(n); int counter = 0, min_price = 1000000000; for (int i = 0; i < n; i++){ a[i] = v[i][0], p[i] = v[i][1], x[i] = v[i][2]; if (x[i] - a[i] <= 0){ counter++; } else{ min_price = min (p[i], min_price); } } if (counter == n) cout << -1 << endl; else cout << min_price << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define IOS ios::sync_with_stdio(false); cin.tie(0); #define FOR(i,s,n) for(int i = (s); i < (n); i++) #define REP(i,n) FOR(i,0,n) #define RREP(i,n) for(int i = (n); i >= 0; i--) #define ALL(n) (n).begin(), (n).end() #define RALL(n) (n).rbegin(), (n).rend() #define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n'; #define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n'; #define OUT(n) cout << (n) << '\n'; using ll = long long; using ull = unsigned long long; using pii = pair<int,int>; using pll = pair<ll,ll>; int main(void) { IOS auto nc2 = [](ll n){return n * (n-1) / 2;}; int n; cin >> n; ll ans = 0; REP(i,n) { int a, b; cin >> a >> b; ans += nc2(b+1) - nc2(a); } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < n; i++) #define rep2(i, x, n) for(int i = x; i <= n; i++) #define rep3(i, x, n) for(int i = x; i >= n; i--) #define each(e, v) for(auto &e: v) #define pb push_back #define eb emplace_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define sz(x) (int)x.size() using ll = long long; using pii = pair<int, int>; using pil = pair<int, ll>; using pli = pair<ll, int>; using pll = pair<ll, ll>; const int MOD = 1000000007; //const int MOD = 998244353; const int inf = (1<<30)-1; const ll INF = (1LL<<60)-1; template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;}; template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;}; struct io_setup{ io_setup(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout << fixed << setprecision(15); } } io_setup; int main(){ int N; cin >> N; ll X; cin >> X; X *= 100; ll S = 0; int ans = inf; rep(i, N){ ll V, P; cin >> V >> P; S += V*P; if(S > X) chmin(ans, i); } cout << (ans == inf? -1 : ans+1) << '\n'; }
#include<bits/stdc++.h> using namespace std; #define int long long #define F first #define S second #define pii pair<int,int> #define pb push_back #define vi vector<int> #define endl "\n" #define all(a) a.begin(),a.end() void solve() { int n; int m; cin >> n >> m; vector<int> v; for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; v.pb(x * y); } int ans = -1; int sum = 0; int i = 0; while (i < n) { sum += v[i]; //cout << sum << endl; if (sum > m * 100) { ans = i + 1; break; } i++; } cout << ans; } void init() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int32_t main() { init(); //int t;cin>>t;while(t--) { solve(); } return 0; }
#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 FOR(i, m, n) for (int i = m; i <= n; i++) #define FORR(i, m, n) for (int i = m; i >= n; i--) #define SORT(v, n) sort(v, v + n) using namespace std; using ll = long long; using vll = vector<ll>; using vvll = vector<vector<ll>>; using P = pair<ll, ll>; using Graph = vector<vector<int>>; using Edge = pair<int, ll>; const ll INF = 1LL << 60; const int MAX = 100000; const int MOD = 1000000007; int main() { // cin高速化 cin.tie(0); ios::sync_with_stdio(false); int n, a; // 入力。1オリジン cin >> n; int ans = 0; REP(i, n) { cin >> a; if (a > 10) ans += a - 10; } cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> #define pb push_back #define mp make_pair #define sz(x) (int)(x).size() #define S second #define F first #define all(x) (x).begin(), (x).end() using namespace std; using ll = long long; void setIO(string name = "") { ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL); if (sz(name)) { freopen((name + ".in").c_str(), "r", stdin); freopen((name + ".out").c_str(), "w", stdout); } } const int inf = 1e9; const ll INF = 1e18; const int mod = 1e9 + 7; const int MAXN = 1e6 + 5; int n; void solve() { cin >> n; int ret = 0; for (int i = 1; i <= n; i++) { int x; cin >> x; if (x > 10) ret += (x - 10); } cout << ret; } main() { setIO(); int tt = 1; // cin >> tt; while (tt--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) #define REP(i,a,b) for(int i = (a); i < (b); i++) #define MOD 1000000007 int main(void) { int n; cin >> n; int res; // 1/2 res (res+1) >= n // res (res+1) >= 2n for(res=0; res<n; res++) { if(res*(res+1)/2 >= n) break; } cout << res << endl; }
#include <cstdio> #include <iostream> #include <string> #include <algorithm> #include <cstring> #include <utility> #include <vector> #include <map> #include <set> #include <cmath> #include <queue> #include <bitset> #include <stack> #include <deque> using namespace std; typedef long long LL; typedef pair<int, int> pii; typedef pair<LL, LL> pll; const LL MOD = (LL)1e9 + 7; LL mul(LL a, LL b) { return (a * b) % MOD; } int main() { int N; scanf("%d", &N); vector<int> A; for (int i = 0; i < N; i++) { int tmp; scanf("%d", &tmp); A.push_back(tmp); } sort(A.begin(), A.end()); A.erase(unique(A.begin(), A.end()), A.end()); int pre = 0; LL ans = 1; for (int i : A) { int dif = i - pre; ans = mul(ans, dif + 1); pre = i; } printf("%lld\n", ans); return 0; }
#include <iostream> #include <map> using namespace std; using lint = long long; void solve() { lint x, y; cin >> x >> y; map<lint, lint> dp; auto dfs = [&](auto&& f, lint p) -> lint { if (dp.count(p)) return dp[p]; auto& ret = dp[p]; // 2で割らない場合 ret = abs(p - x); // 2で割る場合 for (int d = -1; d <= 1; ++d) { lint np = p + d; if (np < 0 || np % 2 != 0 || np / 2 >= p) continue; // 最後の条件は無限ループを省くのに必要 ret = min(ret, f(f, np / 2) + abs(d) + 1); } return ret; }; cout << dfs(dfs, y) << "\n"; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for(int i=0; i<(n); ++i) #define RREP(i, n) for(int i=(n);i>=0;--i) #define FOR(i, a, n) for (int i=(a); i<(n); ++i) #define RFOR(i, a, b) for(int i=(a);i>=(b);--i) #define SZ(x) ((int)(x).size()) #define ALL(x) (x).begin(),(x).end() #define DUMP(x) cerr<<#x<<" = "<<(x)<<endl #define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl; template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { REP(i, SZ(v)) { if (i) os << " "; os << v[i]; } return os; } template <class T> void debug(const vector<T> &v) { cout << "["; REP(i, SZ(v)) { if(i) cout << ", "; cout << v[i]; } cout << "]" << endl; } template<class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << p.first << " " << p.second; } template <class T, class U> void debug(const pair<T, U> &p) { cout << "(" << p.first << " " << p.second << ")" << endl; } template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } using ll = long long; using ull = unsigned long long; using ld = long double; using P = pair<int, int>; using vi = vector<int>; using vll = vector<ll>; using vvi = vector<vi>; using vvll = vector<vll>; const ll MOD = 1e9 + 7; const ll MOD998 = 998244353; const int INF = INT_MAX; const ll LINF = LLONG_MAX; const int inf = INT_MIN; const ll linf = LLONG_MIN; const ld eps = 1e-9; template<int m> struct mint { int x; mint(ll x = 0) : x(((x % m) + m) % m) {} mint operator-() const { return x ? m - x : 0; } mint &operator+=(mint r) { if ((x += r.x) >= m) x -= m; return *this; } mint &operator-=(mint r) { if ((x -= r.x) < 0) x += m; return *this; } mint &operator*=(mint r) { x = ((ll) x * r.x) % m; return *this; } mint inv() const { return pow(m - 2); } mint &operator/=(mint r) { return *this *= r.inv(); } friend mint operator+(mint l, mint r) { return l += r; } friend mint operator-(mint l, mint r) { return l -= r; } friend mint operator*(mint l, mint r) { return l *= r; } friend mint operator/(mint l, mint r) { return l /= r; } mint pow(ll n) const { mint ret = 1, tmp = *this; while (n) { if (n & 1) ret *= tmp; tmp *= tmp, n >>= 1; } return ret; } friend bool operator==(mint l, mint r) { return l.x == r.x; } friend bool operator!=(mint l, mint r) { return l.x != r.x; } friend ostream &operator<<(ostream &os, mint a) { return os << a.x; } friend istream &operator>>(istream &is, mint &a) { ll x; is >> x; a = x; return is; } }; using Int = mint<MOD>; ll modpow(ll x, ll n, ll m) { ll res = 1; while(n > 0) { if(n & 1) { res *= x; res %= m; } x *= x; x %= m; n /= 2; } return res; } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(10); ll a, b, c; cin >> a >> b >> c; vll v = {a%10}; ll now = a%10; while(1) { now *= a%10; now %= 10; if(now == a%10) break; v.push_back(now); } ll val = modpow(b, c, SZ(v)); cout << v[(val+SZ(v)-1)%SZ(v)] << endl; return 0; }
#include <algorithm> #include <iostream> #include <string> #include <vector> #define pb push_back #define pi pair<int, int> #define l first #define r second #define all(x) x.begin(), x.end() using namespace std; const int maxn = 2e3 + 1; int v[maxn]; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int a, b; cin >> a >> b; int cx = 1e9; int p = min(a, b); for (int i = 0; i < p; i++) { v[i] = cx; v[i + p] = -cx; --cx; } a -= p; b -= p; if (b) { int nbx = 0; for (int i = 2 * p - 1; i < 2 * p + b; i++) v[i] = -(++nbx); v[p - 1] = nbx * (nbx + 1) / 2; } if (a) { v[p - 1] = 1; int nbx = 1; for (int i = 2 * p; i < 2 * p + a; i++) v[i] = (++nbx); v[2 * p - 1] = - nbx * (nbx + 1) / 2; } for (int i = 0; i < 2 * p + a + b; i++) cout << v[i] << ' '; return 0; }
#include<iostream> #include<vector> #include<stack> #include<tuple> using namespace std; int main(int argc, char* argv[]) { int A, B, W; cin >> A >> B >> W; W *= 1000; auto D = B - A; const auto k = W / A; int maxCount = 0; int minCount = 2147483647; bool flag = false; for (auto i = 1; i <= k; i++) { const auto R = W - i * A; if (R <= D * i) { maxCount = max(maxCount, i); minCount = min(minCount, i); flag = true; } } if (flag) { cout << minCount << " " << maxCount << endl; } else { cout << "UNSATISFIABLE" << endl; } return 0; }
#include <bits/stdc++.h> #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() using namespace std; typedef long long ll; typedef long double ld; const int INF=1<<30; //const ll INF=1LL<<60; int main() { int n; cin >> n; long double x; cin >> x; vector<int> v(n); vector<int> p(n); rep(i,n) cin >> v[i] >> p[i]; ll ans = 0; rep(i,n) { ans+=(p[i]*v[i]); if(ans>x*100) { cout<<i+1<<endl; return 0; } } cout<<-1<<endl; return 0; }
// 解き直し. // https://atcoder.jp/contests/agc052/editorial/880 // C++(GCC 9.2.1) #include <bits/stdc++.h> using namespace std; #define repex(i, a, b, c) for(int i = a; i < b; i += c) #define repx(i, a, b) repex(i, a, b, 1) #define rep(i, n) repx(i, 0, n) #define repr(i, a, b) for(int i = a; i >= b; i--) #define pb push_back int main(){ // 1. 入力情報. int T; scanf("%d", &T); // 2. 各テストケースに解答. rep(i, T){ // 2-1. 入力情報. int N; char s1[202020], s2[202020], s3[202020]; scanf("%d %s %s %s", &N, s1, s2, s3); string S1(s1), S2(s2), S3(s3); // 2-2. 解説通り. string ans = ""; rep(j, N) ans.pb('0'); rep(j, N) ans.pb('1'); ans.pb('0'); // 2-3. 出力. printf("%s\n", ans.c_str()); } return 0; }
#include<bits/stdc++.h> using namespace std; int main() { int tc,o; scanf("%d",&tc); for(o=1;o<=tc;o++) { long long n,m,a,b,c,d,e,f,g,h,p,q,r,fr,sc,tr,sz=0,tz,i,j,k,mx=LLONG_MIN,mn=LLONG_MAX; long long x=0,y=0,cnt=0,res=0,ans=0,sum=0; long long flg=0,flag=1,na=0,as=1; vector<long long>u,v,w; vector< pair<long long,long long> >vct; vector<string>vst; set<long long>st,nt,tt; map<long long,long long>mp,nq,qr; string str,ttr,ntr; //scanf("%lld",&n); scanf("%lld %lld",&n,&m); g=m-n; if(g>=n) { h=g-n+1; f=h*(h+1); f=f/2; ans=f; } printf("%lld\n",ans); } return 0; }
#include <bits/stdc++.h> using namespace std; int main(void) { long long int T,ans; scanf("%lld",&T); long long int L[T],R[T]; for(int i=0;i<T;i++){ ans = 0; scanf("%lld %lld",&L[i],&R[i]); if(R[i]-2*L[i]>=0){ ans=(R[i]-2*L[i]+2)*(R[i]-2*L[i]+1)/2; } printf("%lld\n",ans); } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pdd; #define lc u << 1 #define rc u << 1 | 1 #define mid (t[u].l + t[u].r) / 2 #define INF 0x3f3f3f3f #define lowbit(x) x & (-x) #define mem(a, b) memset(a , b , sizeof(a)) #define FOR(i, x, n) for(int i = x;i <= n; i++) // const ll mod = 998244353; // const ll mod = 1e9 + 7; // const double eps = 1e-6; // const double PI = acos(-1); // const double R = 0.57721566490153286060651209; const int N = 1e6 + 10; ll t[N]; void modify(int x, int n) { while(x <= n) { t[x]++; x += lowbit(x); } } ll query(int x) { ll ans = 0; while(x) { ans += t[x]; x -= lowbit(x); } return ans; } struct Point { int x, y; friend bool operator < (const Point &a,const Point &b){ return a.x == b.x ? a.y < b.y : a.x < b.x; } friend bool operator == (const Point &a,const Point &b){ return a.x == b.x && a.y == b.y; } }p[N]; bool vis[N]; void solve() { int H, W, M; cin >> H >> W >> M; int upx = H + 1, upy = W + 1; for(int i = 1;i <= M; i++) { cin >> p[i].x >> p[i].y; if(p[i].x == 1) upy = min(upy, p[i].y); if(p[i].y == 1) upx = min(upx, p[i].x); } for(int i = upx + 1;i <= H; i++) { ++M; p[M].x = i; p[M].y = 1; } for(int j = upy + 1;j <= W; j++) { ++M; p[M].y = j; p[M].x = 1; } sort(p + 1, p + M + 1); M = unique(p + 1, p + M + 1) - (p + 1); int h = 1; ll ans = 0; for(int i = 1;i <= M; i++) { // 纵向扫描 if(vis[p[i].y] == 0) { vis[p[i].y] = 1; modify(p[i].y, W); } // 横向扫描 if(i == M || p[i + 1].x != p[i].x) { ans += query(W) - query(p[h].y - 1); h = i + 1; } } cout << (1ll * H * W - ans) << endl; } signed main() { ios_base::sync_with_stdio(false); //cin.tie(nullptr); //cout.tie(nullptr); #ifdef FZT_ACM_LOCAL // int size=40<<20; // __asm__ ("movq %0,%%rsp\n"::"r"((char*)malloc(size)+size)); freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); signed test_index_for_debug = 1; char acm_local_for_debug = 0; do { if (acm_local_for_debug == '$') exit(0); if (test_index_for_debug > 20) throw runtime_error("Check the stdin!!!"); auto start_clock_for_debug = clock(); solve(); auto end_clock_for_debug = clock(); cout << "Test " << test_index_for_debug << " successful" << endl; cerr << "Test " << test_index_for_debug++ << " Run Time: " << double(end_clock_for_debug - start_clock_for_debug) / CLOCKS_PER_SEC << "s" << endl; cout << "--------------------------------------------------" << endl; } while (cin >> acm_local_for_debug && cin.putback(acm_local_for_debug)); #else solve(); #endif return 0; }
// I SELL YOU...! #include<iostream> #include<vector> #include<algorithm> #include<functional> #include<queue> #include<chrono> #include<iomanip> #include<map> #include<set> using namespace std; using ll = long long; using P = pair<ll,ll>; using TP = tuple<ll,ll,ll>; void init_io(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(18); } template <typename Monoid > struct SegmentTree{ using F = function< Monoid(Monoid,Monoid) >; int sz; vector<Monoid> seg; const F f; const Monoid M; SegmentTree(int n,const F f,const Monoid &M) : f(f),M(M){ sz = 1; while(sz<n) sz<<=1; seg.assign(sz*2,M); } void set(int k,const Monoid &v){ seg[k+sz] = v; } void build(){ for(int k=sz-1;k>0;k--){ seg[k] = f(seg[2*k],seg[2*k+1]); } } void update(int k,const Monoid &v){ k += sz; seg[k] = v; while(k >>= 1){ seg[k] = f(seg[2*k],seg[2*k+1]); } } Monoid que(int a,int b){ Monoid L=M,R=M; for(a+=sz, b+=sz;a<b;a>>=1,b>>=1){ if(a&1) L = f(L,seg[a++]); if(b&1) R = f(seg[--b],R); } return f(L,R); } Monoid operator[](const int &k) const{ return seg[k+sz]; } }; signed main(){ init_io(); ll h,w,m; cin >> h >> w >> m; vector<vector<ll>> xb(h,vector<ll>()); vector<vector<ll>> yb(w,vector<ll>()); SegmentTree<ll> seg(w,[](ll a,ll b){return a+b;}, 0ll); vector<ll> xlen(h+1); vector<ll> ylen(w+1); vector<ll> x(m),y(m); for(int i=0;i<m;i++){ cin >> x[i] >> y[i]; x[i]--; y[i]--; xb[x[i]].push_back(y[i]); yb[y[i]].push_back(x[i]); } ll ans = 0; for(int i=0;i<w;i++){ sort(yb[i].begin(),yb[i].end()); if(yb[i].empty()){ ans += h; }else{ if(yb[i].front()==0){ for(int j=i;j<w;j++){ seg.update(j, 1ll); } break; }else{ ans += yb[i].front(); } } } for(int i=1;i<h;i++){ sort(xb[i].begin(),xb[i].end()); ll r = -1; if(xb[i].empty()){ r = w; }else if(xb[i].front()!=0){ r = xb[i].front(); }else{ break; } ans += seg.que(0, r); for(auto py: xb[i]){ seg.update(py, 1); } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #ifdef LOCAL #include "../../../cp/lib/debug.hpp" #else #define debug(...) #endif int main() { cin.tie(0)->sync_with_stdio(0); ll n, c; cin >> n >> c; multiset<pair<ll, ll>> st; for (int i = 0; i < n; i++) { int a, b, x; cin >> a >> b >> x; st.insert({a, x}); st.insert({b + 1, -x}); } ll cur = 0, ans = 0, prev = -1; for (auto&& [x, y] : st) { if (prev != -1) ans += min(cur, c) * (x - prev); cur += y; debug(x, y, cur, ans); prev = x; } cout << ans << '\n'; }
#include <bits/stdc++.h> using namespace std; const int N=1050; const int INF=0x3f3f3f3f; // dp[i][j]表示点i到点j的最短回文串路径 int dp[N][N]; int n,m,u,v; char c[2]; vector<int> g[N][30]; int main(){ // freopen("in.txt","r",stdin); scanf("%d%d",&n,&m); queue<pair<int,int>> q; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ dp[i][j]=INF; } } for(int i=1;i<=n;i++){ dp[i][i]=0; q.push({i,i}); } for(int i=1;i<=m;i++){ scanf("%d%d %s",&u,&v,c); int w=c[0]-'a'; g[u][w].push_back(v); g[v][w].push_back(u); if(u!=v){ // important dp[u][v]=1; dp[v][u]=1; q.push({u,v}); } } while(!q.empty()){ auto t=q.front(); q.pop(); int tu=t.first; int tv=t.second; for(int i=0;i<26;i++){ if(!g[tu][i].empty() && !g[tv][i].empty()){ // 可以向两边拓展这个字符 for(int j=0,us=g[tu][i].size();j<us;j++){ for(int k=0,ts=g[tv][i].size();k<ts;k++){ int ttu=g[tu][i][j]; int ttv=g[tv][i][k]; if(dp[ttu][ttv]>dp[tu][tv]+2){ dp[ttu][ttv]=dp[tu][tv]+2; dp[ttv][ttu]=dp[tu][tv]+2; q.push({ttu,ttv}); } } } } } } printf("%d\n",dp[1][n]==INF?-1:dp[1][n]); return 0; }
#pragma GCC optimize("-Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma") #pragma GCC optimize("unroll-loops") // #include <atcoder/all> // #include <bits/stdc++.h> #include <complex> #include <queue> #include <set> #include <unordered_set> #include <list> #include <chrono> #include <random> #include <iostream> #include <algorithm> #include <cmath> #include <string> #include <vector> #include <map> #include <unordered_map> #include <stack> #include <iomanip> #include <fstream> using namespace std; // using namespace atcoder; typedef long long ll; typedef long double ld; typedef pair<int,int> p32; typedef pair<ll,ll> p64; typedef pair<p64,p64> pp64; typedef pair<double,double> pdd; typedef vector<ll> v64; typedef vector<int> v32; typedef vector<vector<int> > vv32; typedef vector<vector<ll> > vv64; typedef vector<vector<p64> > vvp64; typedef vector<p64> vp64; typedef vector<p32> vp32; typedef pair<ll,p64> tp; ll MOD = 998244353; double eps = 1e-12; #define forn(i,e) for(ll i = 0; i < e; i++) #define forsn(i,s,e) for(ll i = s; i < e; i++) #define rforn(i,s) for(ll i = s; i >= 0; i--) #define rforsn(i,s,e) for(ll i = s; i >= e; i--) #define ln '\n' #define dbg(x) cout<<#x<<" = "<<x<<ln #define mp make_pair #define pb push_back #define fi first #define se second #define INF 2e18 #define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) #define all(x) (x).begin(), (x).end() #define sz(x) ((ll)(x).size()) #define zero ll(0) #define set_bits(x) __builtin_popcountll(x) // #define mint modint998244353 ll mpow(ll a, ll b){ if(a==0) return 0; if(b==0) return 1; ll t1 = mpow(a,b/2); t1 *= t1; t1 %= MOD; if(b%2) t1 *= a; t1 %= MOD; return t1; } ll mpow(ll a, ll b, ll p){ if(a==0) return 0; if(b==0) return 1; ll t1 = mpow(a,b/2,p); t1 *= t1; t1 %= p; if(b%2) t1 *= a; t1 %= p; return t1; } ll modinverse(ll a, ll m){ ll m0 = m; ll y = 0, x = 1; if (m == 1) return 0; while (a > 1){ ll q = a / m; ll t = m; m = a % m, a = t; t = y; y = x - q * y; x = t; } if (x < 0) x += m0; return x; } mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count()); ll range(ll l, ll r){ return l + mt()%(r-l+1); } ll rev(ll v){ return mpow(v,MOD-2); } ll nc2(ll n){ return (n*(n-1))/2; } ll dp[101][10001][101]; ll fac[101]; void solve() { fac[0] = 1; forsn(i, 1, 101) { fac[i] = i*fac[i-1]; fac[i] %= MOD; } ll n; cin>>n; v64 w(n); forn(i, n) cin>>w[i]; ll tot = 0; dp[0][0][0] = 1; forn(i, n) { tot += w[i]; forn(j, 10001) { forn(k, n+1) { dp[i+1][j][k] = dp[i][j][k]; if(j-w[i] >= 0 && k-1 >= 0) { dp[i+1][j][k] += dp[i][j-w[i]][k-1]; dp[i+1][j][k] %= MOD; } } } } if(tot%2 == 1) { cout<<0<<ln; } else { ll ans = 0; forn(el, n+1) { //cout<<el<<" "<<dp[n][tot/2][el]<<ln; ll temp = dp[n][tot/2][el]*fac[el]; temp %= MOD; temp *= fac[n-el]; temp %= MOD; ans += temp; ans %= MOD; } cout<<ans<<ln; } } int main() { fast_cin(); ll t=1; // cin >> t; forn(i,t) { // cout << "Case #" << i+1 << ": "; solve(); } return 0; }
#include<bits/stdc++.h> #define mp make_pair #define pb push_back #define LL long long #define mod 998244353 using namespace std; int n; char s[110000]; int f[11010][110]; int a[110]; long long fac[110]; int main() { fac[0]=1; for(int i=1;i<=100;i++)fac[i]=fac[i-1]*i%mod; cin>>n; for(int i=1;i<=n;i++)scanf("%d",&a[i]); int sum=0; for(int i=1;i<=n;i++)sum+=a[i]; if (sum%2!=0){ puts("0"); return 0; } f[0][0]=1; for(int i=1;i<=n;i++) for(int j=sum;j>=0;j--) for(int k=n;k>=0;k--) if (j-a[i]>=0 && k-1>=0) (f[j][k]+=f[j-a[i]][k-1])%=mod; long long ans=0; for(int i=1;i<=n;i++) { //cout<<i<<" "<<f[sum/2][i]<<endl; ans=(ans+f[sum/2][i]*fac[i]%mod*fac[n-i]%mod)%mod; } cout<<ans<<endl; return 0; }
//#define _GLIBCXX_DEBUG #include <bits/stdc++.h> #define rep(i, n) for(int i=0; i<n; ++i) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() using namespace std; using ll = int64_t; using ld = long double; using P = pair<int, int>; using vs = vector<string>; using vi = vector<int>; using vvi = vector<vi>; template<class T> using PQ = priority_queue<T>; template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >; const int INF = 0xccccccc; const ll LINF = 0xcccccccccccccccLL; template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);} template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);} template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;} template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;} //head int main() { ios::sync_with_stdio(false); cin.tie(0); ll b, c; cin >> b >> c; ll ul = b-c/2, ur = max(b, b+c/2-1); ll dl = min(-b, -b-(c-1)/2), dr = max(-b, -b+(c-1)/2); ll l = min(ul, dl), r = max(ur, dr); ll ans = r-l+1; if(ul > dr) ans -= ul-dr-1; if(dl > ur) ans -= dl-ur-1; cout << ans << endl; }
#include <bits/stdc++.h> #define REP(i, n) for(ll i = 0; i < n; i++) #define REPR(i, n) for(ll i = n - 1; i >= 0; i--) #define FOR(i, m, n) for(ll i = m; i <= n; i++) #define FORR(i, m, n) for(ll i = m; i >= n; i--) #define SORT(v, n) sort(v, v+n) #define MAX 100000 #define inf 1000000007 using namespace std; using ll = long long; using vll = vector<ll>; using vvll = vector<vector<ll>>; using P = pair<ll, ll>; using graph = vector<vector<int>>; using Grid = vector<vector<bool>>; int main() { ll b, c, ans; ans = 0; cin >> b >> c; if(b == 0){ if(c < 2){ cout << 1 << endl; return 0; }else{ ans = c; } }else if(b > 0){ // b > 0 if(c < 3){ cout << c+1 << endl; return 0; }else{ if(2 * b - c > 0){ ans = 3 + (c-2)*2; }else{ ans = (c-2) + (2 * b + 1); } } }else{ // b < 0 if(c < 3){ cout << c+1 << endl; return 0; }else{ if(-2 * (-b) + 1 - c > 0){ ans = 3 + (c-2)*2; }else{ ans = (c-1) + (2 * (-b) + 1); } } } cout << ans << endl; return 0; }
#include <iostream> #include <string> using namespace std; int main() { char c1, c2, c3; cin >> c1 >> c2 >> c3; if (c1 == c2 && c1 == c3 && c2 == c3) { cout << "Won" << "\n"; } else { cout << "Lost" << "\n"; } }
#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 ms(x, y) memset(x, y, sizeof(x)) #define SZ(x) int(x.size()) #define fk cout<<"fk"<<endl #define db(x) cout<<(#x)<<'='<<(x)<<endl #define db2(x,y) cout<<(#x)<<'='<<(x)<<' '<<(#y)<<'='<<(y)<<endl using namespace std; typedef pair<int, int> pii; typedef vector<int> vi; typedef long long i64; 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; } void fastio(){ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout<<fixed;} //1.integer overflow (1e5 * 1e5) (2e9 + 2e9) //2.runtime error //3.boundary condition int a,b,c; int main() { fastio(); cin>>a>>b>>c; if(!c){ cout<<(a-b>=1?"Takahashi":"Aoki")<<'\n'; } else{ cout<<(b-a>=1?"Aoki":"Takahashi")<<'\n'; } return 0; }
#include <algorithm> #include <cctype> #include <cmath> #include <cstring> #include <iostream> #include <sstream> #include <numeric> #include <map> #include <set> #include <queue> #include <vector> using namespace std; typedef long long LL; static const LL INF = 1LL << 60; struct Dijkstra { vector<vector<pair<long long, long long>>> edges; Dijkstra(long long size) : edges(size) { } void add_edges(std::vector<long long>& A, std::vector<long long>& B) { for (int i = 0; i < A.size(); ++i) { add_edge(A[i], B[i]); } } void add_edges(std::vector<long long>& A, std::vector<long long>& B, std::vector<long long>& C) { for (int i = 0; i < A.size(); ++i) { add_edge(A[i], B[i], C[i]); } } void add_edge(long long a, long long b, long long c = 1) { edges[a].push_back({ b, c }); } vector<long long> get_min_costs(long long start) { vector<long long> min_costs(edges.size(), 1LL << 60); priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, greater<>> q; q.emplace(make_pair(0, start)); while (!q.empty()) { pair<long long, long long> top = q.top(); q.pop(); long long cost = top.first, node = top.second; if (cost > min_costs[node]) continue; for (auto kv : edges[top.second]) { long long next_node = kv.first; long long next_cost = top.first + kv.second; if (next_cost < min_costs[next_node]) { min_costs[next_node] = next_cost; q.emplace(make_pair(next_cost, next_node)); } } } return min_costs; } }; void solve(long long N, long long M, std::vector<long long>& A, std::vector<long long>& B, std::vector<long long>& C) { Dijkstra dijkstra(N); dijkstra.add_edges(A, B, C); for (int i = 0; i < N; i++) { vector<LL> costs = dijkstra.get_min_costs(i); LL ans = costs[i]; cout << (ans < INF ? ans : -1) << endl; } } int main() { long long N, M; std::cin >> N >> M; std::vector<long long> A(M), B(M), C(M); for (int i = 0; i < M; i++) { std::cin >> A[i] >> B[i] >> C[i]; --A[i]; --B[i]; } solve(N, M, A, B, C); return 0; }
//================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> #define ci(t) cin>>t #define co(t) cout<<t #define LL long long #define fa(i,a,b) for(int i=a;i<b;++i) #define fd(i,a,b) for(int i=a;i>b;--i) #define setp pair<pair<int,int>,int> #define setl pair<LL,LL> #define M_PI 3.14159265358979323846 #define micro 0.000001 using namespace std; #ifdef OHSOLUTION #define ce(t) cerr<<t #define AT cerr << "\n=================ANS=================\n" #define AE cerr << "\n=====================================\n" #else #define AT #define AE #define ce(t) #define __popcnt __builtin_popcount #endif 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); } pair <int, int> vu[9] = { {0,1},{0,-1},{1,0} ,{-1,0},{0,0},{1,1}, {-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 = 2e3 + 7; const int INF = 1e8 + 7; const LL LNF = 1e18 + 7; const LL mod = 1e9+7; int v, e; priority_queue<setl, vector<setl>, lcmp> pq; vector<setl> adj[max_v]; int dist[max_v]; bool vist[max_v]; int dijk(int sp) { while (!pq.empty()) pq.pop(); fill(dist, dist + v, INF); memset(vist, 0, sizeof(vist)); pq.push({ sp,0 }); dist[sp] = 0; int ret = INF; while (!pq.empty()) { setl cur; do { cur = pq.top(); pq.pop(); } while (!pq.empty() && vist[cur.first]); if (vist[cur.first]) break; vist[cur.first] = 1; for (auto x : adj[cur.first]) { if (dist[x.first] > dist[cur.first] + x.second) { dist[x.first] = dist[cur.first] + x.second; pq.push({ x.first,dist[x.first] }); } if (x.first == sp) { ckmin(ret, dist[cur.first] + x.second); } } } return ret == INF ? -1 : ret; } int main() { #ifdef OHSOLUTION freopen("input.txt", "r", stdin); #endif ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ci(v >> e); fa(i, 0, e) { int x, y, cost; ci(x >> y >> cost); --x, --y; adj[x].push_back({ y,cost }); } fa(i, 0, v) co(dijk(i) << "\n"); return 0; }
#include<bits/stdc++.h> using namespace std; int main() { int n,a[1000]; long long sum=0; cin>>n; for(int i=1;i<=n;i++) { cin>>a[i]; if(a[i]>=10) sum+=a[i]-10; } cout<<sum<<endl; return 0; }
/* “A man wrapped up in himself makes a very small bundle.” */ #include<bits/stdc++.h> using namespace std; #define int long long int #define double long double #define pb push_back #define mp make_pair #define F first #define S second #define all(x) x.begin(), x.end() #define clr(x) memset(x, 0, sizeof(x)) #define sortall(x) sort(all(x)) #define tr(it, a) for(auto it = a.begin(); it != a.end(); it++) #define PI 3.1415926535897932384626 const int mod = 1'000'000'007; const int N = 3e5, M = N; //======================= #ifndef ONLINE_JUDGE template<typename T> void __p(T a) { cerr<<a; } template<typename T, typename F> void __p(pair<T, F> a) { cerr<<"["; __p(a.first); cerr<<","; __p(a.second); cerr<<"]"; } template<typename T> void __p(std::vector<T> a) { cerr<<"["; for(auto it=a.begin(); it<a.end(); it++) __p(*it),cerr<<",]"[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) { cerr<<name<<" : "; __p(arg1); cerr<<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; cerr.write(names,comma-names)<<" : "; __p(arg1); cerr<<" | "; __f(comma+1,args...); } #define trace(...) cerr<<"Line:"<<__LINE__<<" ", __f(#__VA_ARGS__, __VA_ARGS__) #else #define trace(...) #endif //======================= void precompute(){ } void solve() { int a,b; cin>>a; int ans=0; for(int i=0;i<a;i++){ cin>>b; if(b>10)ans+=b-10; } cout<<ans; return; } int32_t main(){ ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int t = 1; //cin >> t; while(t--) { solve(); } return 0; }
#include <bits/stdc++.h> #define fi first #define se second #define DB double #define U unsigned #define P std::pair #define LL long long #define LD long double #define pb emplace_back #define MP std::make_pair #define SZ(x) ((int)x.size()) #define all(x) x.begin(),x.end() #define CLR(i,a) memset(i,a,sizeof(i)) #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 DEBUG(x) std::cerr << #x << '=' << x << std::endl const int MAXN = 1e5 + 5; int n,a[MAXN]; int main(){ scanf("%d",&n);LL sm = 0,now = 0; FOR(i,1,n) scanf("%d",a+i),sm += a[i]; std::sort(a+1,a+n+1); LL ans = 1e18; FOR(i,1,n){ // 2x = a[i] now += a[i]; ans = std::min(ans,2ll*sm+1ll*a[i]*n-2ll*now-2ll*(n-i)*a[i]); } printf("%.10f\n",1.0*ans/(2*n)); return 0; }
#include <bits/stdc++.h> #define Mod 1000000007 using namespace std; typedef long long ll; inline int read() { int out = 0; bool flag = false; register char cc = getchar(); while (cc < '0' || cc > '9') { if (cc == '-') flag = true; cc = getchar(); } while (cc >= '0' && cc <= '9') { out = (out << 3) + (out << 1) + (cc ^ 48); cc = getchar(); } return flag ? -out : out; } inline void write(int x, char ch) { if (x < 0) putchar('-'), x = -x; if (x == 0) putchar('0'); else { int num = 0; char cc[22]; while (x) cc[++num] = x % 10 + 48, x /= 10; while (num) putchar(cc[num--]); } putchar(ch); } int fpow(int x, int y) { int res = 1; while (y) { if (y & 1) res = 1ll * res * x % Mod; x = 1ll * x * x % Mod; y >>= 1; } return res; } const int N = 1e5 + 10; void inc(int &x, int y) { x += y; if (x >= Mod) x -= Mod; } int n, a[N]; double ans = 1e15, sum, p; int main() { n = read(); for (int i = 1; i <= n; i++) a[i] = read(), p += a[i]; sort(a + 1, a + n + 1); for (int k = 0; k < n; k++) { sum += a[k]; if (2 * k - n < 0) { ans = min(ans, -sum + (2.0 * k - n) * (a[k + 1] * 0.5)); } else ans = min(ans, -sum + (2.0 * k - n) * (a[k] * 0.5)); } ans += p; ans /= n; printf("%.10lf", ans); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (long long i = 0; i < (n); i++) using ll = long long; using P = pair<ll, ll>; template<class T> bool chmax(T &a, T b) {if (a < b) {a = b;return true;}else return false;} template<class T> bool chmin(T &a, T b) {if (a > b) {a = b;return true;}else return false;} int main() { ll n; cin >> n; vector<ll> a(n); rep(i, n) cin >> a[i]; vector<ll> sum(n+1); sum[0] = 0; for (int i = 1; i <= n; i++) { sum[i] = sum[i-1] + a[i-1]*a[i-1]; } vector<ll> sum2(n+1); sum2[0] = 0; for (int i = 1; i <= n; i++) { sum2[i] = sum2[i-1] + a[i-1]; } ll ans = 0; for (int i = 1; i < n; i++) { ans += i * a[i]*a[i] -2 * a[i] * sum2[i] + sum[i]; } cout << ans << endl; }
#include <bits/stdc++.h> #define pb push_back #define mp make_pair #define fr first #define sc second #define clr(a) memset(a, 0, sizeof(a)) #define sz(x) x.size() #define rep(n) for (ll i = 0; i < n; i++) #define repc(i, n) for (ll i = 0; i < n; i++) #define FOR(i, x, y) for (ll i = x; i < y; i++) #define DEC(i, x, y) for (ll i = x; i >= y; i--) #define all(v) v.begin(), v.end() #define min3(a, b, c) min(a, min(b, c)) #define max3(a, b, c) max(a, max(b, c)) #define alla(a, n) a, a + n using namespace std; // Some typedef's typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll> ii; typedef vector<ll> vi; typedef vector<ii> vii; ll lcm(ll a, ll b) { return (a * (b / __gcd(a, b))); } // Some constants const int inf = 1e9 + 7; const double eps = 1e-6; const double pi = 1.00 * acos(-1.00); #ifndef ONLINE_JUDGE #define debug(x) cerr << #x <<" "; _print(x); cerr << endl; #else #define debug(x) #endif void _print(int t) {cerr << t;} void _print(string t) {cerr << t;} void _print(char t) {cerr << t;} void _print(ll t) {cerr << t;} void _print(double t) {cerr << t;} void _print(ull t) {cerr << t;} template <class T, class V> void _print(pair <T, V> p); template <class T> void _print(vector <T> v); template <class T> void _print(set <T> v); template <class T, class V> void _print(map <T, V> v); template <class T> void _print(multiset <T> v); template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";} template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} void solve() { int a[3]; rep(3) cin>>a[i]; sort(a,a+3); cout<<a[1]+a[2]; } signed main() { #ifndef ONLINE_JUDGE freopen("Error.txt", "w", stderr); freopen("Input.txt","r",stdin); freopen("Output.txt","w",stdout); #endif ios_base::sync_with_stdio(false);cin.tie(NULL); ll t = 1; // cin >> t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> #include <string> using namespace std; #define ll long long int #define ld long double #define pb push_back #define mp make_pair #define fi first #define se second #define mod 1000000007 #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define fr(i,a,n) for(i=a;i<n;i++) #define frn(i,a,n) for(i=a;i<=n;i++) #define vll vector<ll> #define pll pair<ll,ll> #define vp vector<pll> #define ub upper_bound #define lb lower_bound #define mem(x,y) memset(x,y,sizeof(x)) #define all(v) v.begin(),v.end() #define qll queue<ll> #define sll set<ll> //(a/b)%mod = (a%mod*powermod(b,mod-2,mod))%mod ll power(ll x,ll n) { if(n==0) return 1; else if(n%2 == 0) //n is even return power(x*x,n/2); else //n is odd return x*power(x*x,(n-1)/2); } int highestPowerof2(int n) { int p = (int)log2(n); return (int)pow(2, p); } ll powermod(ll x, ll y, ll p) { ll res = 1; x = x % p; if (x == 0) return 0; while (y > 0) { if (y & 1) res = (res*x) % p; y = y>>1; x = (x*x) % p; } return res; } int main() { ll n; cin>>n; ll a[n]; ll b[n]; ll i,val=0,ans; vector<int>mx(n,0); for(i=0;i<n;i++) { cin>>a[i]; } for(i=0;i<n;i++) { cin>>b[i]; } mx[0]=a[0]; ll res=a[0]; for(i=0;i<n;i++) { res=max(a[i],res); mx[i]=res; } ans=a[0]*b[0]; cout<<ans<<endl; ll ans1=ans; for(i=1;i<n;i++) { ans1=max(ans1,b[i]*mx[i]); cout<<ans1<<endl; } }
#include <iostream> #include <set> #define int long long signed main() { std::ios::sync_with_stdio(false); std::cin.tie(0); int ans = 0; std::set<std::pair<int, int> > chosen; int n; std::cin >> n; int m = 2*n-1; int a[2*n]; for(int i = 0; i < 2*n; i++) std::cin >> a[i]; for(int i = n-1; i >= 0; i--) { std::pair<int, int> x = {a[i], i}, y = {a[m-i], m-i}; std::pair<int, int> next = std::max(x, y); ans += next.first; chosen.insert(next); std::pair<int, int> nopt = std::min(x, y); if((*chosen.begin()).first < nopt.first) { ans -= (*chosen.begin()).first; chosen.erase(chosen.begin()); chosen.insert(nopt); ans += nopt.first; } } std::cout << ans << std::endl; return 0; }
#include <bits/stdc++.h> using ull = unsigned long long int; using ll = long long; using ld = long double; using pii = std::pair<int,int>; using pll = std::pair<ll, ll>; using vi = std::vector<int> ; using vvi = std::vector<vi> ; using vll = std::vector<ll>; using vvll = std::vector<vll>; using vd = std::vector<double> ; using vvd = std::vector<vd> ; using qi = std::queue<int> ; using vpii = std::vector<std::pair<int, int> >; using vpll = std::vector<pll>; using namespace std; #define rep(i,j) for(int (i)=0;(i)<(j);(i)++) #define drep(i,j) for(int (i)=(j);(i) >= 0;(i)--) template<class T1, class T2> inline void chmin(T1 &a, T2 b){if(a > b) a = b;} template<class T1, class T2> inline void chmax(T1 &a, T2 b){if(a < b) a = b;} template<class T> inline void pri(T a){cout << a << endl;} template<class Z> using vec = vector<Z>; template<class T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>; inline void IN(void){ return; } template <typename First, typename... Rest> void IN(First& first, Rest&... rest){ cin >> first; IN(rest...); return; } inline void OUT(void){ cout << endl; return; } template <typename First, typename... Rest> void OUT(First first, Rest... rest){ cout << first << " " ; OUT(rest...); return; } const int max_n = 3 * (1e5) + 1; const int max_m = 83 * (1e5) + 1; const int INF = int(1e9); const long long int INFL = (long long int)1e18; int n,m,k; string S; int ans; void solve() { int N; ll C; IN(N,C); vector<pair<int,int>> eve(2*N); for(int i=0;i < 2*N; i+= 2) { int a,b,c;IN(a,b,c); eve[i] = {a,c}; eve[i+1] = {b+1,-c}; } sort(eve.begin(),eve.end()); ll ans = 0; ll cost = 0; int day = 1; rep(i,2*N) { auto e = eve[i]; ll t = e.first - day; day = e.first; if(cost > C)ans += t * C; else ans += t * cost; cost += e.second; } cout << ans << endl; } signed main (int argc, char* argv[]) { cin.tie(0); ios::sync_with_stdio(false); int cases=1; //IN(cases); while(cases--)solve(); //pri(ans); //for(auto c : ans){cout << c << endl;} //cout << fixed << setprecision(15) << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep2(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define rep(i,n) rep2(i,0,n) #define rep1(i,n) rep2(i,1,n+1) #define FOR(i) for(cin>>i;i>0;i--) #define elif else if #define pb push_back #define ll long long #define mp make_pair #define all(x) x.begin(),x.end() #define re(x) {cout<<x<<endl;return 0;} //#define x first //#define y second using namespace std; int n,t[2222],l[2222],r[2222],ans=0; int main() { cin>>n; rep(i,n) { cin>>t[i]>>l[i]>>r[i]; if(t[i]%2==0) r[i]-=1; if(t[i]>2) l[i]+=1; } rep(i,n) rep2(j,i+1,n) { if((l[i]<=r[j]&&r[i]>=l[j])||(l[j]<=r[i]&&r[j]>=l[i])||(r[j]+1==l[i]&&t[j]%2==0&&t[i]>2)||(r[i]+1==l[j]&&t[i]%2==0&&t[j]>2)) ans++; } re(ans) return 0;}
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<ctime> #include<algorithm> #include<queue> #include<set> #include<map> #include<bitset> #include<vector> #include<unordered_map> using namespace std; typedef long long ll; typedef unsigned int ui; ll read() { ll x=0,f=1;char ch=getchar(); while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();} while(isdigit(ch))x=x*10+(ch^48),ch=getchar(); return x*f; } void write(ll x) { if(x<0)putchar('-'),x=-x; if(x>9)write(x/10); putchar(x%10+48); } void writes(ll x) {write(x),putchar(' ');} void Writes(ll x) {write(x),putchar('\n');} #define mp make_pair #define pb push_back #define N 3030 int n; int A[N]; int main() { n=read(); A[1]=2*89,A[2]=3*5*7*89; for(int i=1,j=3;i<=10000 and j<=1100;++i) { if(i%89 != 0 and i%7 != 0 and i%5 !=0 and i%3 == 0 and i%2 == 0) A[j++]=i; } for(int i=1,j=1101;i<=10000 and j<=1900;++i) { if(i%89 != 0 and i%7 != 0 and i%5 == 0 and i%2 == 0) A[j++]=i; } for(int i=1,j=1901;i<=10000 and j<=2500;++i) { if(i%89 != 0 and i%7 == 0 and i%2 == 0) A[j++]=i; } for(int i=1;i<=n;++i) writes(A[i]); return 0; }
#include <stdio.h> #include <algorithm> #include <assert.h> #include <cmath> #include <deque> #include <iostream> #include <limits.h> #include <map> #include <math.h> #include <queue> #include <set> #include <stdlib.h> #include <string.h> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> #include <functional> #include <iomanip> #define ll long long #define rep2(i,a,b) for(int i=a;i<=b;++i) #define rep(i,n) for(int i=0;i<n;i++) #define rep3(i,a,b) for(int i=a;i>=b;i--) #define REP(e,v) for(auto e:v) #define pii pair<int,int> #define pll pair<ll,ll> #define mp make_pair #define mt make_tuple #define pq priority_queue<int> #define pqg priority_queue<int,vector<int>,greater<int>> #define pb push_back #define vec vector<int> #define vecvec vector<vec> #define vecll vector<ll> #define vecpii vector<pii> #define vecpll vector<pll> #define vecbl vector<bool> #define endl "\n" #define ALL(c) (c).begin(),(c).end() using namespace std; int in() {int x;scanf("%d",&x);return x;} ll lin() {ll x;scanf("%lld",&x);return x;} string stin(){string s;cin>>s;return s;} double len(double a,double b,double c, double d){ return sqrt((a-c)*(a-c) + (b-d)*(b-d)); } struct UnionFindTree{ vec par,size,rank,height;//par[i]:iの親,size[i]:iの属する木の要素数,rank[i]:iが、自分の属する木の何階層目にあるか,height[i]:iを根とする部分木の高さ int setNum;//木が何本あるか UnionFindTree(int n):par(n),size(n),rank(n),height(n){ rep(i,n){ par[i]=i; size[i]=1; rank[i]=-1; height[i]=1; } setNum=n; } int root(int x){ if(par[x]==x)return x; return root(par[x]); } void unite(int x, int y){ int rx=root(x); int ry=root(y); if(rx==ry)return; if(height[rx]<height[ry]){ par[rx]=ry; size[ry]+=size[rx]; }else{ par[ry]=rx; size[rx]+=size[ry]; if(height[rx]==height[y]) height[rx]++; } setNum--; } bool same(int x, int y){ return root(x)==root(y); } int getSize(int x){//xの属する木の要素数 return size[root(x)]; } int getSetNum(){//木の本数 return setNum; } int getRank(int x){//xが何階層目にあるか if(par[x]==x)return 0; return getRank(par[x])+1; } int getHeight(int x){//xの属する木の高さ return height[root(x)]; } }; int main(){ int n=in(); vector<double> x(n),y(n); rep(i,n){ x[i]=in()*1.0; y[i]=in()*1.0; } UnionFindTree tree(n+2); vector<pair<double,pii>> v; double ans=100.0; rep(i,n){ v.pb(mp(50.0-y[i]/2,mp(i,n))); v.pb(mp(y[i]/2+50.0,mp(i,n+1))); rep(j,n)if(i!=j){ v.pb(mp(len(x[i],y[i],x[j],y[j])*1.0/2,mp(i,j))); } } sort(ALL(v)); REP(e,v){ int a = e.second.first,b = e.second.second; tree.unite(a,b); if(tree.same(n,n+1)){ cout << fixed << setprecision(10) << e.first << endl; return 0; } } }
#include<bits/stdc++.h> using namespace std; inline int read(){ int res=0; bool zf=0; char c; while(((c=getchar())<'0'||c>'9')&&c!='-'); if(c=='-')zf=1; else res=c-'0'; while((c=getchar())>='0'&&c<='9')res=(res<<3)+(res<<1)+c-'0'; return (zf?-res:res); } inline bool check(int x){ int tmp=x; while(x){ if(x%10==7)return 0; x/=10; } x=tmp; while(x){ if(x%8==7)return 0; x/=8; } return 1; } signed main(){ int n=read(),ans=0; for(register int i=1;i<=n;++i){ if(check(i))++ans; } printf("%d\n",ans); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n,tmp; int amax=-1; int bmin=10000; cin>>n; for(int i=0;i<n;i++){ cin>>tmp; if(tmp>amax){ amax=tmp; } } for(int i=0;i<n;i++){ cin>>tmp; if(tmp<bmin){ bmin=tmp; } } if(bmin<amax){ cout<<0; }else{ cout<<(bmin-amax+1); } cout<<endl; //cout<<amax<<endl; //cout<<bmin<<endl; }
#include <bits/stdc++.h> #define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a) #define rep2(i, s, n) rep3(i, s, n, 1) #define rep(i, n) rep2(i, 0, n) using namespace std; using ll = long long; using ull = unsigned long long; using P = pair<int, int>; int main() { vector<ll> rui(1000001); ll sum = 0; rep(i, 1000001){ rui[i] = sum; sum += (i+1); } int n; cin >> n; ll res = 0; rep(i, n){ int a, b; cin >> a >> b; res += rui[b] - rui[a-1]; } cout << res << endl; return 0; }
#include<cstdio> #include<algorithm> using namespace std; #define fi first #define se second #define rep(i, l, r) for(int i=(l), i##_end_=(r); i<=i##_end_; ++i) #define fep(i, l, r) for(int i=(l), i##_end_=(r); i>=i##_end_; --i) typedef long long ll; template<class T>inline T fab(T x){ return x<0? -x: x; } template<class T>inline T readin(T x){ x=0; int f=0; char c; while((c=getchar())<'0' || '9'<c) if(c=='-') f=1; for(x=(c^48); '0'<=(c=getchar()) && c<='9'; x=(x<<1)+(x<<3)+(c^48)); return f? -x: x; } const int maxn=2e5; int a[maxn+5], n; int cnt[205]; inline void input(){ n=readin(1); rep(i, 1, n) a[i]=readin(1); } signed main(){ input(); rep(i, 1, n) ++cnt[a[i]%200]; ll ans=0; rep(i, 1, n) ans+=cnt[a[i]%200]-1; ans>>=1; printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define mod 1000000007 //10e9+7 #define pb push_back #define mod1 998244353 // want to become a good coder :p void chalega() { ll a,b; cin>>a>>b; ll sum1=0,sum2=0; ll x=0,y=0; while(a>0) { x=a%10; sum1+=x; a/=10; } while(b>0) { y=b%10; sum2+=y; b/=10; } if(sum1>sum2) { cout<<sum1<<endl; } else { cout<<sum2<<endl; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); chalega(); }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pll = pair<ll,ll>; using pld = pair<ld,ld>; using vll = vector<ll>; using vld = vector<ld>; using vstr = vector<string>; #define _GLIBCXX_DEBUG #define rep(j, m) for (ll j = 0; j < (ll)(m); j++) #define rep2(i, l, n) for (ll i = l; i < (ll)(n); i++) #define all(v) v.begin(), v.end() const ld PI = 3.1415926535897932; const ll MOD = 1000000007; const ll MOD2 = 998244353; vll dx = {-1,0,1,0}; vll dy = {0,-1,0,1}; vll Dx = {-1,-1,-1,0,0,1,1,1}; vll Dy = {-1,0,1,-1,1,-1,0,1}; const ll INF = 1000000000000000; int main() { ll N; cin >> N; string S; cin >> S; if (S[0] != S[N - 1]) {cout << 1 << endl;} else { ll flag = 0; rep(i,N - 1) { if (S[i] != S[0] && S[i + 1] != S[0]) {cout << 2 << endl;flag++;break;} } if (flag == 0) {cout << -1 << endl;} } }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define ff first #define ss second #define all(x) (x).begin(), (x).end() #define len(x) int((x).size()) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define randint(n) uniform_int_distribution<int>(1, (n))(rng) const int mxn=200100; int link[mxn]; int sz[mxn]; map<int,int> M[mxn]; int C[mxn]; int head(int u) { while(u!=link[u]) u=link[u]; return u; } void join(int a, int b) { a=head(a); b=head(b); if(a==b) return; if(sz[a]<sz[b]) swap(a,b); sz[a]+=sz[b]; link[b]=a; // if(len(M[b])>len(M[a])) swap(M[a],M[b]); for(auto thing:M[b]){ M[a][thing.ff] += thing.ss; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); #ifdef ARTHUR_LOCAL ifstream cin("input.txt"); #endif int n,q; cin>>n>>q; // cout << len(M[200]); for(int i=1; i<=n; i++) cin>>C[i]; for(int i=1; i<=n; i++){ link[i]=i; sz[i]=1; M[i][C[i]] = 1; } while(q--){ int t; cin>>t; if(t==1){ int a,b; cin>>a>>b; join(a,b); } else{ int x,y; cin>>x>>y; cout << M[head(x)][y] << "\n"; } } }
#include <bits/stdc++.h> using namespace std; #define int long long #define rep(i, n) for (int i = 0; i < (int) (n); i++) #define reps(i, n) for (int i = 1; i <= (int) (n); i++) #define all(a) (a).begin(), (a).end() #define uniq(a) (a).erase(unique(all(a)), (a).end()) #define dump(a) cerr << #a " = " << (a) << endl using vint = vector<int>; using pint = pair<int, int>; using vpint = vector<pint>; template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>; constexpr double PI = 3.1415926535897932384626433832795028; constexpr int DY[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0}; constexpr int DX[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0}; int bit(int n) { return 1LL << n; } int sign(int a) { return (a > 0) - (a < 0); } int cdiv(int a, int b) { return (a - 1 + b) / b; } template<typename T> T sq(T a) { return a * a; } template<typename T> void fin(T a) { cout << a << endl; exit(0); } template<typename T, typename U> bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; } template<typename T, typename U> bool chmin(T &a, const U &b) { if (b < a) { a = b; return true; } return false; } template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &a) { os << "(" << a.first << ", " << a.second << ")"; return os; } template<typename T, typename U, typename V> ostream &operator<<(ostream &os, const tuple<T, U, V> &a) { os << "(" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << ")"; return os; } template<typename T> ostream &operator<<(ostream &os, const vector<T> &a) { os << "("; for (auto itr = a.begin(); itr != a.end(); itr++) { os << *itr << (next(itr) != a.end() ? ", " : ""); } os << ")"; return os; } template<typename T> ostream &operator<<(ostream &os, const deque<T> &a) { os << "("; for (auto itr = a.begin(); itr != a.end(); itr++) { os << *itr << (next(itr) != a.end() ? ", " : ""); } os << ")"; return os; } template<typename T> ostream &operator<<(ostream &os, const set<T> &a) { os << "{"; for (auto itr = a.begin(); itr != a.end(); itr++) { os << *itr << (next(itr) != a.end() ? ", " : ""); } os << "}"; return os; } template<typename T> ostream &operator<<(ostream &os, const multiset<T> &a) { os << "{"; for (auto itr = a.begin(); itr != a.end(); itr++) { os << *itr << (next(itr) != a.end() ? ", " : ""); } os << "}"; return os; } template<typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &a) { os << "{"; for (auto itr = a.begin(); itr != a.end(); itr++) { os << *itr << (next(itr) != a.end() ? ", " : ""); } os << "}"; return os; } struct setup { static constexpr int PREC = 20; setup() { cout << fixed << setprecision(PREC); cerr << fixed << setprecision(PREC); } } setup; signed main() { int N; string T; cin >> N >> T; if (N == 1) { if (T == "1") { fin((int) 2e10); } else { fin((int) 1e10); } } string S_ = ""; rep(i, 100000) { S_.push_back('1'); S_.push_back('1'); S_.push_back('0'); } int ans = 0; rep(i, 3) { if (S_.substr(i, N) == T) { ans = (int) 1e10 - (N + i - 1) / 3; } } cout << ans << endl; }
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <cmath> #include <queue> #include <map> #include <iomanip> using namespace std; using ll = long long int; vector<string> myspliter(const string &s, const char delimiter){ vector<string> res; string part = ""; for(auto &p: s){ if(p == delimiter){ if(part.length() > 0) res.push_back(part); part = ""; }else{ part += p; } } if(part.length() > 0) res.push_back(part); return res; } ll transToInt(vector<string> str){ ll ans = 0; ans += stoi(str[0])*10000; if(str.size() == 2){ while(str[1].length() < 4) str[1] += '0'; ans += stoi(str[1]); } return ans; } ll solve(ll x, ll y, ll r){ ll ans = 0; for(ll i = -2'000'000'000; i <= 2'000'000'000; i += 10000){ if(r*r-(i-y)*(i-y) < 0) continue; ll inner = x; ll outer = 4'000'000'000; ll border = r*r-(i-y)*(i-y); while(outer-inner > 1){ ll mid = (outer+inner)/2; if((mid-x)*(mid-x) <= border) inner = mid; else outer = mid; } ll left = x*2-inner; ll right = inner; if(left <= 0){ left = left/10000 - 1; }else{ left = (left-1)/10000; } if(right < 0){ right = (right+1)/10000; }else{ right = right/10000 + 1; } ans += max(right - left - 1, 0LL); // if(right > 1 && left < -1) ans++; // if(i == 00000) cerr << left << " " << right << " " << inner << endl; } return ans; } int main(){ string x0, y0, r0; cin >> x0 >> y0 >> r0; ll x = transToInt(myspliter(x0, '.')); ll y = transToInt(myspliter(y0, '.')); ll r = transToInt(myspliter(r0, '.')); cout << solve(x, y, r) << endl; return 0; }
#include<iostream> #include<math.h> using namespace std; int main() { long double x,y,r; cin>>x>>y>>r; r+=1e-14; long long ans=0; long long ll=ceil(x-r); long long rr=floor(x+r); //cout<<ll<<" "<<rr<<endl; for(int i=ll;i<=rr;i++){ if(r*r-(1.0*i-x)*(1.0*i-x)<0) continue; long double yy=sqrt(r*r-(1.0*i-x)*(1.0*i-x)); long long tmp=floor(y+yy)-ceil(y-yy)+1; ans+=tmp; } cout<<ans<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; const long long N=1e6+10; inline int read(){ int x=0,f=1;char ch=getchar(); while(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();} while(isdigit(ch)){x=x*10+ch-48;ch=getchar();} return x*f; } long long n,a[N],tot; signed main(){ cin>>n; for(int i=1;i<=sqrt(n);i++){ if(n%i==0){ a[++tot]=i; if(i!=sqrt(n)) a[++tot]=n/i; } } sort(a+1,a+tot+1); for(int i=1;i<=tot;i++) { printf("%lld\n",a[i]); } return 0; }
/*** I came, I saw, I conquered. ***/ #include <bits/stdc++.h> using namespace std; typedef long long ll;typedef unsigned long long ull; #define sc(a) cin >> a #define pf(a) cout << a << endl #define forIn(arr, num) for(ll i = 0; i < num; i++) cin >> arr[i]; #define vpnt(ans) for(ll i = 0; i < ans.size(); i++) cout << ans[i] << (i + 1 < ans.size() ? ' ' : '\n'); #define mod 1000000007 #define pb push_back #define all(v) (v).begin(), (v).end() #define GET_SET_BITS(a) (__builtin_popcount(a)) #define GET_SET_BITSLL(a) ( __builtin_popcountll(a)) #define GET_TRAIL_ZERO(a) (__builtin_ctz(a)) #define GET_LEAD_ZERO(a) (__builtin_clz(a)) #define GET_PARITY(a) (__builtin_parity(a)) #define no cout << "NO" << endl #define yes cout << "YES" << endl void go() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } /*----------------------------------------------------------------*/ void solve() { ll n; sc(n); set<ll> s; s.insert(1); s.insert(n); for(ll i = 2;i * i <= n;i++) { if(n % i == 0) { s.insert(i); s.insert(n / i); } } for(auto it : s) { pf(it); } } int main() { go(); solve(); return 0; }
//Let's join Kaede Takagaki Fan Club !! #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; #define int long long typedef long long ll; typedef pair<int,int> P; typedef pair<int,P> P1; typedef pair<P,P> P2; #define pu push #define pb push_back #define eb emplace_back #define mp make_pair #define eps 1e-7 #define INF 1000000000 #define a first #define b second #define fi first #define sc second #define rng(i,a,b) for(int i=int(a);i<int(b);i++) #define rep(i,x) for(int i=0;i<x;i++) #define repn(i,x) for(int i=1;i<=x;i++) #define SORT(x) sort(x.begin(),x.end()) #define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end()) #define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) #define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) #define all(x) x.begin(),x.end() #define si(x) int(x.size()) #ifdef LOCAL #define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl #else #define dmp(x) void(0) #endif template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b;return true;}else return false;} template<class t,class u> bool chmin(t&a,u b){if(b<a){a=b;return true;}else return false;} template<class t> using vc=vector<t>; template<class t,class u> ostream& operator<<(ostream& os,const pair<t,u>& p){ return os<<"{"<<p.fi<<","<<p.sc<<"}"; } template<class t> ostream& operator<<(ostream& os,const vc<t>& v){ os<<"{"; for(auto e:v)os<<e<<","; return os<<"}"; } template<class T> void g(T &a){ cin >> a; } template<class T> void o(const T &a,bool space=false){ cout << a << (space?' ':'\n'); } //ios::sync_with_stdio(false); const ll mod = 1000000007;//998244353 mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count()); template<class T> void add(T&a,T b){ a+=b; if(a >= mod) a-=mod; } ll modpow(ll x,ll n){ ll res=1; while(n>0){ if(n&1) res=res*x%mod; x=x*x%mod; n>>=1; } return res; } int n, m, q; int zan[3][3]; int x[200005], y[200005]; int ty[200005], val[200005]; int ans[2][200005]; vc<P>Q[200005]; void solve(){ rep(i, 3) zan[i][i] = 1; cin >> n; repn(i, n) cin >> x[i] >> y[i]; cin>>m; repn(i, m){ cin >> ty[i]; if(ty[i] >= 3) cin >> val[i]; } cin>>q; rep(i, q){ int a, b; cin >> a >> b; Q[a].eb(b, i); } repn(i, m+1){ for(auto at:Q[i-1]){ int v = at.a, id = at.b; ans[0][id] = x[v] * zan[0][0] + y[v] * zan[0][1] + zan[0][2]; ans[1][id] = x[v] * zan[1][0] + y[v] * zan[1][1] + zan[1][2]; } if(i == m+1) break; int nxt[3][3] = {}; int v[3][3] = {}; if(ty[i] == 1){ v[0][1] = 1; v[1][0] = -1; v[2][2] = 1; } else if(ty[i] == 2){ v[0][1] = -1; v[1][0] = 1; v[2][2] = 1; } else if(ty[i] == 3){ v[0][0] = -1; v[0][2] = 2LL * val[i]; v[1][1] = v[2][2] = 1; } else{ v[0][0] = 1; v[1][1] = -1; v[1][2] = 2LL*val[i]; v[2][2] = 1; } rep(i, 3) rep(j, 3) rep(k, 3){ nxt[i][k] += v[i][j] * zan[j][k]; } rep(i, 3) rep(j, 3) zan[i][j] = nxt[i][j]; } rep(i, q) cout<<ans[0][i]<<" "<<ans[1][i]<<'\n'; } signed main(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20); int t; t = 1; //cin >> t; while(t--) solve(); }
//#pragma GCC optimize(2) #include<cstdio> #include<iostream> #include<string> #include<cstring> #include<map> #include<cmath> #include<cctype> #include<vector> #include<set> #include<queue> #include<algorithm> #include<sstream> #include<ctime> #include<cstdlib> #define X first #define Y second #define L (u<<1) #define R (u<<1|1) #define pb push_back #define mk make_pair #define Mid (tr[u].l+tr[u].r>>1) #define Len(u) (tr[u].r-tr[u].l+1) #define random(a,b) ((a)+rand()%((b)-(a)+1)) #define db puts("---") using namespace std; //void rd_cre() { freopen("d://dp//data.txt","w",stdout); srand(time(NULL)); } //void rd_ac() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//AC.txt","w",stdout); } //void rd_wa() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//WA.txt","w",stdout); } typedef long long LL; typedef unsigned long long ULL; typedef pair<int,int> PII; const int N=200010,mod=1e9+7,INF=0x3f3f3f3f; const double eps=1e-6; int n,k; int a[N]; char s[N]; int f[N][20]; int dfs(int pos,int state,int flag,int lead) { int cnt=__builtin_popcount(state); if(cnt>k) return 0; if(pos==n+1) return cnt==k&&lead; if(flag&&lead&&f[pos][cnt]!=-1) return f[pos][cnt]; int x=flag? 15:a[pos]; int ans=0; for(int i=0;i<=x;i++) (ans+=dfs(pos+1,(!lead&&i==0)? state:state|(1<<i),flag||i<x,lead||i!=0))%=mod; if(flag&&lead) f[pos][cnt]=ans; return ans; } int main() { // ios::sync_with_stdio(false); // cin.tie(0); scanf("%s%d",s+1,&k); n=strlen(s+1); for(int i=1;i<=n;i++) if(s[i]>='A'&&s[i]<='Z') a[i]=s[i]-'A'+10; else a[i]=s[i]-'0'; memset(f,-1,sizeof(f)); printf("%d",dfs(1,0,0,0)); return 0; } /* */
#include <bits/stdc++.h> #define ll long long using namespace std; ll INF = 1e15; ll n, m, k; ll dp[1 << 17][20]; ll helper(vector<vector<ll>>& adj, ll from, ll to) { queue<ll> q; q.push(from); ll ret = 0; vector<bool> visited(n + 1, false); visited[from] = true; while(!q.empty()) { ret++; ll sz = q.size(); while(sz--) { auto t = q.front(); q.pop(); for(auto nt : adj[t]) { if(visited[nt]) continue; visited[nt] = true; if(nt == to) return ret; q.push(nt); } } } return INF; } ll helper2(vector<vector<ll>>& dist, ll idx, ll status) { if(status == ((1 << k) - 1)) return 0; if(dp[status][idx] != -1) return dp[status][idx]; ll ret = INF; for(ll i = 0; i < k; i++) { if(!((status >> i) & 1)) { ll can = dist[idx][i] + helper2(dist, i, status | (1 << i)); ret = min(ret, can); } } dp[status][idx] = ret; return ret; } ll mst(vector<vector<ll>>& dist) { ll ret = INF; memset(dp, -1, sizeof(dp)); for(ll i = 0; i < k; i++) { ll status = (1 << i); ll can = helper2(dist, i, status); ret = min(ret, can); } return ret; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m; vector<vector<ll>> adj(n + 1); ll a, b; for(ll i = 0; i < m; i++) { cin >> a >> b; adj[a].push_back(b); adj[b].push_back(a); } cin >> k; vector<ll> c(k); for(ll i = 0; i < k; i++) cin >> c[i]; vector<vector<ll>> dist(k, vector<ll>(k, 0)); for(ll i = 0; i < k; i++) { for(ll j = i + 1; j < k; j++) { ll num = helper(adj, c[i], c[j]); if(num >= INF) { cout << -1 << endl; return 0; } dist[i][j] = num; dist[j][i] = num; } } cout << mst(dist) + 1 << endl; return 0; }
#include <bits/stdc++.h> // #include <atcoder/all> using namespace std; // using namespace atcoder; #define int long long signed main(){ // cout << fixed << setprecision(10) << flush; int n, m; cin >> n >> m; vector<int> a(m), b(m); vector<vector<int>> e(n), er(n); for(int i=0; i<m; i++){ cin >> a[i] >> b[i]; a[i]--; b[i]--; e[a[i]].push_back(b[i]); er[b[i]].push_back(a[i]); } int ans = 0; for(int i=0; i<n; i++){ vector<int> vis(n, 0); vis[i] = 1; queue<int> q; for(int j=0; j<e[i].size(); j++){ q.push(e[i][j]); } while(!q.empty()){ int v = q.front(); q.pop(); if(vis[v]) continue; vis[v] = 1; for(int k=0; k<e[v].size(); k++){ if(!vis[e[v][k]]) q.push(e[v][k]); } } for(auto v: vis){ ans += v; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int N; cin >> N; if(N%100==0){ cout << N/100 << endl; } else{ cout << N/100+1 << endl; } }
#include <bits/stdc++.h> #define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i) #define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i) #define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i) #define rreps(i, n) for(int i=((int)(n)); i>0; --i) #define ALL(v) v.begin(), v.end() using namespace std; using ll = long long; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } int main(int argc, char **argv) { int n; cin >> n; cout << ((n + 99) / 100) << endl; }
#pragma GCC optimize("Ofast") #include<bits/stdc++.h> using namespace std; #define ll int #define ld long double #define For(i,x,y) for(ll i = (ll)(x);i <= (ll)(y);++i) #define FOr(i,x,y) for(ll i = (ll)(x);i >= (ll)(y);--i) #define rep(i,x,y) for(ll i = (ll)(x);i < (ll)(y);++i) #define fi first #define se second #define pa pair<ll,ll> #define pb push_back #define y1 y11111111111111 #define debug puts("@@@@@@@@@@@@@@@@@@@") #define cpy(a,b) memcpy(a,b,sizeof(b)) inline ll read() { ll x = 0,f = 1;char ch = getchar(); while(ch < '0' || ch > '9'){if(ch == '-')f = -1;ch = getchar();} while(ch >= '0' && ch <= '9'){x = x*10+ch-'0';ch = getchar();} return x*f; } void write(ll x) { if(x < 0) putchar('-'), x= -x; if(x > 9)write(x/10); putchar(x%10+'0'); } const ll N=200010; ll n,a[N]; vector<ll>ans; bool ok(){ For(i,1,n-1)if(a[i]>a[i+1])return 0; return 1; } void swp(ll i,ll j){ swap(a[i],a[j]); ans.pb(i); } int main(){ ll T=read(); for(;T--;){ n=read(); ans.clear(); For(i,1,n)a[i]=read(); for(;;){ if (ok())break; bool fl=0; For(i,1,n-1)if(i&1){ if (a[i]>a[i+1]){ swp(i,i+1); fl=1; break; } } if(!fl){ if(n&1) swp(n-2,n-1); else swp(n-1,n); } if (ok())break; fl=0; For(i,1,n-1)if(!(i&1)){ if (a[i]>a[i+1]){ swp(i,i+1); fl=1; break; } } if(!fl){ if(n&1) swp(n-1,n); else swp(n-2,n-1); } } cout<<ans.size()<<endl;; rep(i,0,ans.size())write(ans[i]),putchar(' ');puts(""); } }
#include<bits/stdc++.h> #define ll long long int #define ld long double #define inf LLONG_MAX>>2 #define MAX 1000000 #define mod 1000000007 #define pb push_back #define f(i,a,n,x) for ((i)=(a);(i)<(n);(i)+=(x)) #define fd(i,a,n,x) for ((i)=(a);(i)>=(n);(i)-=(x)) #define fi first #define se second #define mk make_pair #define pi pair #define vt vector #define ms multiset #define is insert #define um unordered_map using namespace std; void read(vt<ll> &a,ll n){ll i,temp;f(i,0,n,1){cin>>temp;a.pb(temp);}} ll fa[MAX]; ll power(ll p,ll q){ ll res=1; p%=mod; while(q){ if (q&1) res=(res*p)%mod; q>>=1; p=(p*p)%mod; } return res; } ll fact(ll n){ if (n<=1) return fa[n]=1; if (fa[n]) return fa[n]; return fa[n]=(n*fact(n-1))%mod; } ll ncr(ll n,ll r){ if (!r) return 1; return (((fact(n)*power(fact(n-r),mod-2))%mod)*power(fact(r),mod-2))%mod; } void solve(){ ll i,j,sum,ans=inf,count; string s; cin>>s; f(j,0,1<<s.length(),1){ sum=count=0; f(i,0,s.length(),1) if (!((1<<i)&j)) sum+=s[i]-'0'; else count++; if (!(sum%3)) ans=min(ans,count); } cout<<(ans==s.length()?-1:ans)<<endl; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll t=1; //cin>>t; while(t--) solve(); return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long LL; typedef vector<int> vi; typedef vector<vi> vii; #define fi first #define se second #define pb push_back #define forn(i,n) for(int i=0;i<(n);i++) #define for1(i,n) for(int i=1;i<=n;i++) #define forr(i,n) for(int i=n;i>=0;i--) #define all(x) x.begin(), x.end() #define sz(x) ((int)x.size()) const int MAXN = 1e5 +5; void fio(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int main(){ fio(); int n; cin >> n; string s; cin>>s; int q; cin >> q; int sw = 0; while(q--){ int t; cin >> t; int a, b; cin >> a >> b; a--, b--; if(t == 2){ sw^=1; } else{ if(sw){ if(a < n){ a+= n; } else{ a-=n; } if(b < n){ b+= n; } else{ b-=n; } } swap(s[a], s[b]); } } if(sw){ for(int i = n; i < 2*n ; i++) cout << s[i]; forn(i, n){ cout << s[i]; } cout << "\n"; } else{ for(auto i:s) cout << i; cout << "\n"; } return 0; }
#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstring> #include <deque> #include <forward_list> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> PII; typedef pair<int, ll> PIL; typedef pair<ll, int> PLI; typedef pair<ll, ll> PLL; typedef bitset<16> BS; struct edge { int to, cost, id; }; const double PI = 3.14159265358979323846; const double EPS = 1E-09; const ll MOD = 1E+09 + 7; // =998244353; const ll INFL = 1E18; const int INFI = 1E09; const int MAX_N = 2E+05; ll dx[4] = { -1, 1, 0, 0 }, dy[4] = { 0, 0, -1, 1 }; int N, Q; string S; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> N >> S >> Q; //cout << "S = " << S << ", T = " << T << "\n"; bool mv = false; for (int i = 1; i <= Q; i++) { int t, a, b; cin >> t >> a >> b; a--; b--; if (t == 1) { if (!mv) { swap(S[a], S[b]); } else { if (a >= N) a -= N; else a += N; if (b >= N) b -= N; else b += N; swap(S[a], S[b]); } } else { mv = !mv; } } /* for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { cout << "i = " << i << ", j = " << j << ", dp = " << dp[i][j] << "\n"; } } */ string ans = ""; if (mv) { string l = S.substr(0, N); string r = S.substr(N, N); ans = ans + r + l; } else { ans = S; } cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef double dbl; typedef float flt; #define for0(i, n) for(ll i=0; i<n; i++) #define for1(i, n) for(ll i=1; i<=n; i++) #define forab(i, a, b) for(ll i=a; i<=b; i++) #define clr0(a) memset(a, 0, sizeof(a)) void solve() { ll n; cin >> n; ll a[n+5][n+5]; for1(i, n) { for1(j, n) { cin >> a[i][j]; } } ll row[n+5], col[n+5]; bool pos = true; for1(j, n) { if (j==1) { row[j] = 0; } else { row[j] = a[1][j] - a[1][1]; } } for1(i, n) { if (i==1) { col[i] = 0; } else { col[i] = a[i][1] - a[1][1]; } } forab(i, 2, n) { forab(j, 2, n) { ll rd = a[i][j] - a[i][1]; ll cd = a[i][j] - a[1][j]; if (rd!=row[j] || cd!=col[i]) { pos = false; } } } if (!pos) { cout << "No" << endl; } else { cout << "Yes" << endl; ll rmn=99999999; ll cmn=99999999; ll offset; for1(i, n) { rmn = min(rmn, row[i]); cmn = min(cmn, col[i]); } if (rmn<=cmn) { offset = abs(rmn); } else { offset = a[1][1] - abs(cmn); } /* forab(i, 0, a[1][1]) { bool fnd = true; for1(j, n) { if (row[1]+i + col[j]+a[1][1]-i != a[1][j]) { fnd = false; break; } } if (fnd==true) { offset = i; break; } } */ for1(i, n) { cout << col[i]+a[1][1]-offset << " "; } cout << endl; for1(j, n) { cout << row[j]+offset << " "; } cout << endl; } } void testcase() { ll t; cin >> t; while (t--) { solve(); } } int main () { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //testcase(); solve(); 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; const int N = 1e5; int parent[N], color[N]; vector<int> adj[N]; map<int, int> cnt_color; set<int> ans; void defineParents() { memset(parent, -1, sizeof(parent)); parent[0] = 0; queue<int> fila; fila.push(0); while(!fila.empty()) { int v = fila.front(); fila.pop(); for(auto u: adj[v]) { if(parent[u] == -1) { parent[u] = v; fila.push(u); } } } } void dfs(int x) { if(cnt_color[color[x]] == 0) ans.insert(x + 1); cnt_color[color[x]]++; for(auto u: adj[x]) { if(u != parent[x]) { dfs(u); } } cnt_color[color[x]]--; } int main() { int n; cin >> n; for(int i = 0; i < n; i++) cin >> color[i]; for(int i = 1; i < n; i++) { int u, v; cin >> u >> v; u--; v--; adj[u].push_back(v); adj[v].push_back(u); } defineParents(); dfs(0); for(auto x: ans) cout << x << endl; return 0; }
#include <stdio.h> #include <set> #include <utility> typedef long long ll; int main(void) { ll i, j, k, n, q; scanf("%lld", &n); ll a, t, b[2] = {(ll)-1e16, (ll)1e16}, s = 0, x; for(i = 0; i < n; ++i) { scanf("%lld%lld", &a, &t); if(t == 1) s += a; else if(t == 2) { if(b[1] + s < a) b[0] = b[1], s = a - b[0]; else if(b[0] + s < a) b[0] = a - s; } else { if(b[0] + s > a) b[0] = b[1], s = a - b[0]; else if(b[1] + s > a) b[1] = a - s; } } scanf("%lld", &q); for(i = 0; i < q; ++i) { scanf("%lld", &x); if(x < b[0]) printf("%lld\n", b[0] + s); else if(x < b[1]) printf("%lld\n", x + s); else printf("%lld\n", b[1] + s); } return 0; }
#include<iostream> #include<algorithm> #include<cstdio> #include<cmath> #include<vector> #include<utility> #include<queue> #include<deque> #include<stack> #include<set> #include<map> #include<bitset> #include<string> #include<functional> #include<iomanip> #define rep(i,n,m) for(int i=(n);i<(int)(m);i++) #define reps(i,n,m) for(int i=(n);i<=(int)(m);i++) #define all(v) v.begin(), v.end() #define allr(v) v.rbegin(), v.rend() #define SZ(x) ((int)(x).size()) #define pb push_back #define fs first #define sc second #define lb lower_bound #define ub upper_bound #define LB(a,x) lb(all(a), x) - a.begin() #define UB(a,x) ub(all(a), x) - a.begin() #define chartoint(c) (int)((c) - '0') #define chartoll(c) (long long)((c) - '0') #define bpc(x) __builtin_popcount(x) #define bpcll(x) __builtin_popcountll(x) #define fps(n) fixed << setprecision(n) #define MOD 1000000007 #define itn int #define enld endl #define ednl endl #define icn cin #define cotu cout #define Endl endl #define stirng string using namespace std; typedef long long ll; const double pi = 3.141592653589793; using Graph = vector<vector<int>>; 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;} template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ std::fill( (T*)array, (T*)(array+N), val ); } double dp[105][105][105]; int main(){ cin.tie(0);ios::sync_with_stdio(false); int a,b,c; cin >> a >> b >> c; for(int i=99;i>=a;i--){ for(int j=99;j>=b;j--){ for(int k=99;k>=c;k--){ dp[i][j][k] += (double)i/(i+j+k)*(dp[i+1][j][k]+1)+(double)j/(i+j+k)*(dp[i][j+1][k]+1)+(double)k/(i+j+k)*(dp[i][j][k+1]+1); } } } cout << fps(20) << dp[a][b][c] << endl; return 0; }
#pragma GCC optimize("O3") #pragma GCC target("sse4") #include <algorithm> #include <cmath> #include <deque> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #include <iomanip> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> #include <string> // ヘッダファイルインクルード #include <typeinfo> using namespace std; // 名前空間指定 using namespace std; // using namespace __gnu_pbds; typedef long long ll; typedef long double ld; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef pair<ld, ld> pd; typedef vector<int> vi; typedef vector<ld> vd; typedef vector<ll> vl; typedef vector<pi> vpi; typedef vector<pl> vpl; template <class T> #define FOR(i, a, b) for (int i = a; i < (b); i++) #define F0R(i, a) for (int i = 0; i < (a); i++) #define FORd(i, a, b) for (int i = (b)-1; i >= a; i--) #define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--) #define sz(x) (int)(x).size() #define mp make_pair #define pb push_back #define f first #define s second #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() #define shandom_ruffle random_shuffle const int MOD = 1000000007; const ll INF = 1e18; const int MX = 100001; // check the limits, dummy const ll infl = 1LL << 60; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } template <class T> void print(const vector<T> v) { cout << "[ "; F0R(i, v.size()) { cout << v[i] << ' '; } cout << "]" << '\n'; } int mod(int i, int j) { return (i % j) < 0 ? (i % j) + 0 + (j < 0 ? -j : j) : (i % j + 0); } // -------------------------------------------------------- // This is tool // -------------------------------------------------------- void Main() { ios_base::sync_with_stdio(0); cin.tie(0); int a, b, x, y, ans = 0; cin >> a >> b >> x >> y; if (a == b || a == b + 1) { ans = x; } else { int diff=0; diff = min(abs(b-a),abs(b-(a-1))); // cout << diff ; if (2*x <= y) { ans = x + diff *2*x; } else { ans =x + diff * y; } } cout << ans ; } int main() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(15); Main(); }