code_file1
stringlengths
87
4k
code_file2
stringlengths
85
4k
#include <algorithm> #include <cassert> #include <cstdint> #include <iostream> #include <map> #include <vector> #define REP_(i, a_, b_, a, b, ...) \ for (int i = (a), lim##i = (b); i < lim##i; i++) #define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__) #define ALL(obj) obj.begin(), obj.end() using namespace std; using Int = int64_t; int main() { Int N; cin >> N; vector<Int> vec; Int sum = 0; REP(i, N) { Int a, b; cin >> a >> b; vec.push_back(2 * a + b); sum -= a; } sort(ALL(vec)); reverse(ALL(vec)); REP(i, N) { sum += vec[i]; if (sum > 0) { cout << i + 1 << endl; break; } } return 0; }
// #include<vector> // #include<iostream> // #include<stdio.h> // #include<string> // #include<algorithm> #include<bits/stdc++.h> using namespace std; int main() { int a,b; cin >> a >> b; if ( b >= 8 && a+b >= 15) { cout << 1 << endl; return 0; } if ( b >= 3 && a+b >= 10) { cout << 2 << endl; return 0; } if ( a+b >= 3) { cout << 3 << endl; return 0; } cout << 4 << endl; }
#include<bits/stdc++.h> #define pb push_back #define pl pair<ll,ll> #define pll pair<ll,pair<ll,ll>> #define ll long long #define vl vector<ll> #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); #define mp make_pair #define w(t) int t;cin>>t;while(t--) #define inf 1e18 #define fi(a,n) for(ll i=a;i<n;i++) #define fr(i,a,b) for(ll i=a;i>=b;i--) #define fj(a,n) for(ll j=a;j<n;j++) #define k(a,n) for(ll k=a;k<n;k++) #define endl "\n" #define all(v) (v).begin(),(v).end() #define set1(x) __builtin_popcount(x) #define gcd(a,b) __gcd(a,b) #define mem1(a) memset(a,-1,sizeof(a)) #define mem0(a) memset(a,0,sizeof(a)) using namespace std; const ll mod= 1000000007; const ll N =1000005; ll v[N]; vl m(N,1); ll f[N]; void seive() { m[1]=1; fi(2,N) { if(!v[i]) { for(ll j=i;j<N;j+=i) { if(j%(i*i)==0)m[j]=0; m[j]=-m[j]; v[j]=1; } } } } void solve() { ll l,r; cin>>l>>r; fi(l,r+1) { f[i]++; } ll ans=0; // fi(1,10)cout<<m[i]<<endl; fi(1,r+1) { if(m[i]==0)continue; ll temp=0; for(ll j=i;j<r+1;j+=i) { temp+=(f[j]); } // cout<<i<<" "<<temp<<endl; ans+=(temp*(temp-1)/2*m[i]); } ll x=r-l+1; ans=((x*(x-1))/2)-ans; // cout<<ans<<endl; ll kk=0; fi(max(2LL,l),r+1) { for(ll j=i;j<r+1;j+=i) { if(i==j)continue; else kk++; } } cout<<2*(ans-kk)<<endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE // for getting input from input.txt freopen("input.txt", "r", stdin); // for writing output to output.txt freopen("output.txt", "w", stdout); #endif // w(t) seive(); solve(); }
#include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> using namespace std; #define pb push_back #define ll long long int #define pll pair<ll,ll> #define mp make_pair # define fio ios_base::sync_with_stdio(false); cin.tie(NULL) const int MAX_N = 2e6+1; ll mod = 1e9+7; int main() { fio; int l,r; cin>>l>>r; ll store[r+1]; ll ans = 0; for(int i=r;i>=2;i--){ store[i] =0; for(int j=i;j<=r;j+=i){ store[i] -= store[j]; } ll low = (l-1)/i; ll high = r/i; store[i] += (high-low) * (high-low); ans += store[i]; } for(int i=max(2,l);i<=r;i++){ ll high = r/i; ans -= (2*high - 1); } cout<<ans; return 0; }
#include <cmath> #include <deque> #include <algorithm> #include <iterator> #include <list> #include <tuple> #include <map> #include <unordered_map> #include <queue> #include <set> #include <unordered_set> #include <stack> #include <string> #include <vector> #include <fstream> #include <iostream> #include <functional> #include <numeric> #include <iomanip> #include <stdio.h> //end of libraries #define lnf 3999999999999999999 #define inf 999999999 #define PI 3.14159265359 #define endl "\n" #define fi first #define se second #define pb push_back #define ll long long #define all(c) (c).begin(),(c).end() #define sz(c) (ll)(c).size() #define mkp(a,b) make_pair(a,b) #define make_unique(a) sort(all(a)),a.erase(unique(all(a)),a.end()) #define rsz(a,n) a.resize(n) #define pii pair <ll,ll> #define rep(i,n) for(ll i = 0 ; i < n ; i++) #define drep(i,n) for(ll i = n-1 ; i >= 0 ; i--) #define crep(i,x,n) for(ll i = x ; i < n ; i++) #define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0); const ll max_n = 300000; using namespace std; ll n,m,k; ll dp[max_n]; ll mod = 998244353; ll binpow(ll a, ll b) { a %= mod; ll res = 1; while (b) { if (b%2) res = res * a % mod; a = a * a % mod; b /= 2; } return res % mod; } ll sub(ll a , ll b){ a%=mod; b%=mod; return (((a-b)%mod)+mod)%mod; } ll prod(ll a , ll b){ a%=mod; b%=mod; return ((a*b)%mod); } ll add(ll a , ll b){ a%=mod; b%=mod; return (a+b)%mod; } int main(){ fcin; cin >> n >> m >> k; dp[1]=1; ll s = 1; crep(i,2,k+1) { dp[i] = sub(binpow(i,n),s); s+=dp[i]; } ll ans = 0; crep(i,1,k+1) { ans = add(prod(binpow(k-i+1,m),dp[i]),ans); } if(n == 1 or m == 1){ if(n==1) cout << binpow(k,m) << "\n"; else cout << binpow(k,n) << "\n"; return 0; } cout << ans << "\n"; /* */ return 0; }
#include<bits/stdc++.h> using namespace std; using LL = long long; constexpr LL mod = 998244353; LL power(LL a, LL r){ LL res = 1; for(; r; r >>= 1, a = a * a % mod) if(r & 1) res = res * a % mod; return res; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); LL N, M, K, ans = 0; cin >> N >> M >> K; for(int i = 1; i <= K; i += 1) ans += (power(i, N) - power(i - 1, N) + mod) * power(K - i + 1, M) % mod; if(N == 1) ans = power(K, M); if(M == 1) ans = power(K, N); cout << ans % mod; return 0; }
//PochurSolveKortaHobaa #include<bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int a,b,c; cin>>a>>b>>c; if(c==0){ while(1){ a--; if(a<=0){ cout<<"Aoki"; break; } b--; if(b<=0){ cout<<"Takahashi"; break; } } } else{ while(1){ b--; if(b<=0){ cout<<"Takahashi"; break; } a--; if(a <=0){ cout<<"Aoki"; break; } } } /*if(c==0){ if(a>b)cout<<"Takahashi"; else cout<<"Aoki"; } else{ if(a>b)cout<<"Aoki"; else cout<<"Takahashi"; }*/ } /* -NEVER GIVE UP. -Recite QURAN. -The harder it looks the easier it'll be. -Remember how you started. -Why you doing this? */
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define INF 1000000000 #define endl "\n" #define all(s) s.begin(),s.end() #define pb push_back #define pi 3.1415926536 #define dig(a) fixed<<setprecision(a) #define fast() ios_base::sync_with_stdio(false); cin.tie(NULL); const int M = 1e9+7; const int maxx = 1e7+5; ll power(ll a, ll n) { ll res = 1; while (n) { if (n % 2) {res = (res * a) % M;} n >>= 1; a = (a * a) % M;} return res; } const int m = 105; double dp[m][m][m]; double solve(int a, int b, int c){ if(a>=100 || b>=100 || c>=100) return 0; if(dp[a][b][c]) return dp[a][b][c]; double res = 0; res+=solve(a+1,b,c)*a; res+=solve(a,b+1,c)*b; res+=solve(a,b,c+1)*c; res = res/(a+b+c)+1; dp[a][b][c] = res; return res; } int main(){ fast(); int a,b,c; cin>>a>>b>>c; cout<<dig(9)<<solve(a,b,c); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i,srt,end) for(ll i = (srt); i < (ll)(end); i++) ll MOD=1000000007; ll mod=998244353; int inf=1000001000; ll INF=1e18+5; //cout << std::fixed << std::setprecision(15) << y << endl; // For debug // Ref: https://qiita.com/ysuzuki19/items/d89057d65284ba1a16ac #define dump(var) do{std::cerr << #var << " : ";view(var);}while(0) template<typename T> void view(T e){std::cerr << e << "\n";} template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cerr << e << " "; } std::cerr << "\n";} template<typename T> void view(const std::vector<std::vector<T> >& vv){ std::cerr << "\n"; for(const auto& v : vv){ view(v); } } template<typename T> void dump_cout(const T& v) { for(long long i = 0; i < v.size(); i++) std::cout << v[i] << (i == v.size()-1 ? "\n" : " "); } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); ll x; cin >> x; ll ans = (x/100+1)*100 - x; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using lint = long long; constexpr lint inf = 1LL << 60; constexpr lint mod = 1000000007; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int x; cin >> x; cout << 100 - x % 100 << endl; return 0; }
#include <bits/stdc++.h> #define se second #define sz(x) (int)(x.size()) #define ll long long #define rep(i,x,y) for(int i = x; i <= y; ++i) #define repr(i,x,y) for(int i = x; i >= y; --i) #define pb push_back #define mp make_pair #define fi first #define ull unsigned ll #define pi 3.14159265358979 using namespace std; const int N = (int)(1e6) + 322; const ll INF = 2e18 + 17; const int inf = 2e9; const int mod = 1000000007; const double eps = 1e-9; template<typename T> void pop_front(vector<T>& vec) { assert(!vec.empty()); vec.erase(vec.begin()); } int gcd(int a, int b) { return b ? gcd (b, a % b) : a; } int nbr_bits(int a){ return log2(a)+1; } int fastpow(int a, int n, int mod) { if(n==0) return 1; if(n%2==0){ int res = fastpow(a,n/2,mod); res*=res; res%=mod; return res; } int res = (fastpow(a,n-1,mod)*a)%mod; return res; } // --------------------------------------------------- int p[N]; stack<string> answers; int find(int u){ if(p[u]==u) return u; return p[u] = find(p[u]); } bool bubleSort(vector<int> v, int n){ int ans = 0; int m = (n * (n -1)) / 2; rep(i, 0, n-1){ rep(j, 0, n-2){ if(v[j] > v[j + 1]){ swap(v[j], v[j + 1]); ans++; } } } if(ans < m) return true; else return false; } int n; bool isPalinadrome(string str){ if(str.size() == 1) return true; rep(i, 0, (str.size() / 2) - 1 ) { if(str[i] == str[str.size() - i - 1]) continue; return false; } return true; } ll fact(ll n) { if(n == 0 || n == 1 ) return 1; else return (n * fact(n-1)) % mod; } signed main() { ios_base::sync_with_stdio(false); int a, b, c; cin >> a >> b >> c; int a2 = fastpow(a, 2, mod); int b2 = fastpow(b, 2, mod); int c2 = fastpow(c, 2, mod); int sum = a2 + b2; if(sum < c2) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
/* ** *** In the name of God *** ** */ // Only Haider is Amir al-Momenin #include <bits/stdc++.h> using namespace std; typedef long long ll; const ll maxn = 2e5 + 10; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int a,b,c; cin >> a >> b >> c; if (a * a + b * b < c * c) cout << "Yes"; else cout << "No"; return 0; } /* _ _ _ _ _ _ _ _ _ _ _ _ / / \ / / | / / | /``````\ \ |`````| | |`````| | / \ \ | | | | | | / \ \ | | | | | | / /\ \ \ | | | | | | / / /\ \ \ | | | | | | / / / \ \ \ | | | | | | / / /_ _ \ \ \ | | | | | | / /_ _ _ _ \ \ \ | | | | | | / \ \ | | |_ _ _ _ | | | / _ _ _ _ _ _ _ \ \ | | / /| | | | / / / \ \ \ | |/_ _ _ _ / | | | | / / / \ \ / | | / | | / /_ _ _/_/ \_ _ _\/ |_ _ _ _ _ _ _ _|/ |_ _ _|/ */
#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() #define rall(v) v.rbegin(), v.rend() using ll = long long; using pii = pair<int, int>; using pll = pair<long long, long long>; using Graph = vector<vector<int>>; const long long INF = 1LL << 60; const int SINF = 1LL << 29; const ll mod = 1000000000+7; const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; 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; } int main() { // N:日, C:プライムの1日の値段 ll N, C; cin >> N >> C; // a~b日目の終わりまでサービスを使う, プライムでないときは1日あたりc円 vector<ll> a(N), b(N), c(N); rep(i, N) cin >> a[i] >> b[i] >> c[i]; map<ll, ll> mp; rep(i, N) { mp[a[i]] += c[i]; mp[b[i]+1] += -c[i]; } vector<pair<ll, ll>> vp; for(auto m:mp) { vp.push_back(make_pair(m.first, m.second)); } ll X = 0, ans = 0; // rep(i, vp.size()){ // cout << vp[i].first << " " << vp[i].second << endl; // } rep(i, vp.size()-1) { X += vp[i].second; if(X < C) ans += (vp[i+1].first - vp[i].first) * X; else ans += (vp[i+1].first-vp[i].first) * C; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define repr(i, a, b) for (int i = a; i < b; i++) #define rep(i, n) for (int i = 0; i < n; i++) typedef long long ll; typedef pair<ll,ll> P; #define mod 1000000007 ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;} ll lcm(ll x,ll y) {return x/gcd(x,y)*y;} int main(){ ll n,m; cin >> n >> m; vector<ll> a(n,0); rep(i,n){ cin >> a[i]; } vector<ll> kazu(n+1,0); rep(i,m){ kazu[a[i]]++; } ll now; for(ll i=0;i<=n;i++){ if(kazu[i]==0){ now=i; break; } } for(ll i=0;i<n-m;i++){ kazu[a[i]]--; kazu[a[i+m]]++; if(kazu[a[i]]==0&&i<now){ now=i; } } cout << now << endl; return 0; }
#include<bits/stdc++.h> #include <stdio.h> #include <algorithm> #define all(x) x.begin(),x.end() #define sc(x) scanf("%d",&x) #define scl(x) scanf("%lld",&x) #define LL long long #define LD long double #define pb push_back #define F first #define S second const double PI=3.1415926535897932384626433; const int KL=1e6; const LL MOD=1e9+7; using namespace std; /* typedef complex<double> point; #define x real() #define y imag() */ LL q,x,y,z,n,m,mn=1e9,mx=-1e9,ans,k; string t; bool a[2*KL+10]; map <LL,LL> mp; int main() { scl(n); for(LL i=1;i<=n;i++){ scl(x); mp[x]++; ans+= (i-mp[x]); } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define mp make_pair #define pb push_back #define eb emplace_back #define f first #define s second #define fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); #define int long long #define endl "\n" int solve(){ int N,tot=0,sq=0; cin >> N; vector<int> A(N),suff(N); for(int i=0;i<N;i++){ cin >> A[i]; sq += A[i]*A[i]; } suff[N-1]=A[N-1]; for(int i=N-2;i>=0;i--) suff[i]=suff[i+1]+A[i]; int temp=0; for(int i=0;i<N-1;i++) temp+=A[i]*suff[i+1]; return (N-1)*sq-2*temp; } int32_t main(){ fast; int t; //cin >> t; t=1; while(t--){ cout << solve() << endl; } }
#include<iostream> #include<algorithm> #include<cstdlib> #include<sstream> #include<cstring> #include<cstdio> #include<string> #include<deque> #include<cmath> #include<queue> #include<set> #include<map> using namespace std; struct Dog { int pos; long long cute; int type; //0--R, 1--G, 2--B bool isUsed; }; std::vector<Dog> dog[3]; int r[3]; int n; int totalN; long long minDist; void clearAll() { for (int i = 0 ; i < 3 ; i++) { for (int j = 0 ; j < dog[i].size() ; j++) { dog[i][j].isUsed = false; } } } bool compareDog(const Dog &a, const Dog &b) { return a.cute < b.cute; } long long check(int a, int b, int d) { std::vector<Dog> curDogs; for (int i = 0 ; i < dog[a].size() ; i++) { if (!dog[a][i].isUsed) { curDogs.push_back(dog[a][i]); } } for (int i = 0 ; i < dog[b].size() ; i++) { if (!dog[b][i].isUsed) { curDogs.push_back(dog[b][i]); } } sort(curDogs.begin(), curDogs.end(), compareDog); long long minDist = -1; int minPosA, minPosB; int startPos, endPos; if (d == 1) { startPos = 0; endPos = curDogs.size() - 1; } else { startPos = curDogs.size() - 2; endPos = -1; } for (int i = startPos ; i != endPos ; i = i + d) { if (curDogs[i].type != curDogs[i + 1].type) { long long curDist = abs(curDogs[i].cute - curDogs[i + 1].cute); if ((minDist == -1) || (minDist > curDist)) { minDist = curDist; if (curDogs[i].type == a) { minPosA = curDogs[i].pos; minPosB = curDogs[i + 1].pos; } else { minPosB = curDogs[i].pos; minPosA = curDogs[i + 1].pos; } } } } dog[a][minPosA].isUsed = true; dog[b][minPosB].isUsed = true; return minDist; } int main(void) { scanf("%d", &n); totalN = n * 2; for (int i = 0 ; i < totalN ; i++) { long long cute; char ch; int type; scanf("%lld %c", &cute, &ch); if (ch == 'R') { type = 0; } else if (ch == 'G') { type = 1; } else if (ch == 'B') { type = 2; } Dog newDog; newDog.cute = cute; newDog.type = type; newDog.isUsed = false; dog[type].push_back(newDog); } for (int i = 0 ; i < 3 ; i++) { for (int j = 0 ; j < dog[i].size() ; j++) { dog[i][j].pos = j; } } int oddCount = 0; std::vector<int> oddPos; int evenPos; for (int i = 0 ; i < 3 ; i++) { r[i] = dog[i].size() % 2; if (r[i] == 1) { oddCount++; oddPos.push_back(i); } else { evenPos = i; //如果只有一个偶数,后面要用 } } if (oddCount == 0) { printf("0\n"); return 0; } long long curMin; //先做下两个奇数的 minDist = check(oddPos[0], oddPos[1], 1); clearAll(); if (dog[evenPos].size() >= 2) { long long numA, numB; numA = check(oddPos[0], evenPos, 1); numB = check(oddPos[1], evenPos, 1); clearAll(); curMin = numA + numB; if (minDist > curMin) minDist = curMin; numA = check(oddPos[1], evenPos, 1); numB = check(oddPos[0], evenPos, 1); clearAll(); curMin = numA + numB; if (minDist > curMin) minDist = curMin; numA = check(oddPos[0], evenPos, -1); numB = check(oddPos[1], evenPos, -1); clearAll(); curMin = numA + numB; if (minDist > curMin) minDist = curMin; numA = check(oddPos[1], evenPos, -1); numB = check(oddPos[0], evenPos, -1); clearAll(); curMin = numA + numB; if (minDist > curMin) minDist = curMin; } printf("%lld\n", minDist); return 0; }
#include <iostream> #include <vector> #include <algorithm> #include <cmath> #define rep(i,n) for(int i =0;i<(n);++i) using namespace std; using ll = long long; struct DataType { ll val; char col; }; constexpr ll ll_max {1001001001001001}; int main(int argc, char** argv) { int n; cin >> n; std::vector<vector<ll>> a(3); rep(i,2*n) { DataType tmp; cin >> tmp.val >> tmp.col; if (false); else if (tmp.col == 'R') a[0].push_back(tmp.val); else if (tmp.col == 'G') a[1].push_back(tmp.val); else if (tmp.col == 'B') a[2].push_back(tmp.val); } std::sort(a[0].begin(), a[0].end()); std::sort(a[1].begin(), a[1].end()); std::sort(a[2].begin(), a[2].end()); int a_mod = a[0].size() % 2; int b_mod = a[1].size() % 2; int c_mod = a[2].size() % 2; if (a_mod == 0 && b_mod == 0 && c_mod == 0) { cout << "0\n"; } else { int idx_1, idx_2; if (a_mod == 1) idx_1 = 0; else if (b_mod == 1) idx_1 = 1; if (c_mod == 1) idx_2 = 2; else if (b_mod == 1) idx_2 = 1; int idx_3 = 3 - idx_1 - idx_2; ll min_val {ll_max}; rep(i, a[idx_1].size()) { auto it = std::lower_bound(a[idx_2].begin(), a[idx_2].end(), a[idx_1][i]); if (it != a[idx_2].end()) min_val = std::min(min_val, *it - a[idx_1][i]); if (it != a[idx_2].begin()) min_val = std::min(min_val, std::abs(*(--it) - a[idx_1][i])); } ll min_val_tmp1 {ll_max}; rep(i, a[idx_1].size()) { auto it = std::lower_bound(a[idx_3].begin(), a[idx_3].end(), a[idx_1][i]); if (it != a[idx_3].end()) min_val_tmp1 = std::min(min_val_tmp1, *it - a[idx_1][i]); if (it != a[idx_3].begin()) min_val_tmp1 = std::min(min_val_tmp1, std::abs(*(--it) - a[idx_1][i])); } ll min_val_tmp2 {ll_max}; rep(i,a[idx_2].size()) { auto it = std::lower_bound(a[idx_3].begin(), a[idx_3].end(), a[idx_2][i]); if (it != a[idx_3].end()) min_val_tmp2 = std::min(min_val_tmp2, *it - a[idx_2][i]); if (it != a[idx_3].begin()) min_val_tmp2 = std::min(min_val_tmp2, std::abs(*(--it) - a[idx_2][i])); } cout << std::min(min_val, min_val_tmp1 + min_val_tmp2) << '\n'; } }
#include<bits/stdc++.h> // #include<atcoder/all> // #include<boost/multiprecision/cpp_int.hpp> using namespace std; // using namespace atcoder; // using bint = boost::multiprecision::cpp_int; using ll = long long; using ull = unsigned long long; using P = pair<int,int>; #define rep(i,n) for(ll i = 0;i < (ll)n;i++) #define ALL(x) (x).begin(),(x).end() #define MOD 1000000007 int main(){ int n; cin >> n; cout << 3*5*7*11 << " "; n--; if(n){ cout << 2*3 << " "; n--; } if(n){ cout << 2*5 << " "; n--; } if(n){ cout << 2*7 << " "; n--; } if(n){ cout << 2*11 << " "; n--; } if(n){ cout << 2*6 << " "; n--; } if(n){ cout << 2*9 << " "; n--; } for(int i = 12;i <= 5000;i++){ if(n == 0)break; if(i%3 == 0 || i%5 == 0 || i%7 == 0 || i%11 == 0){ n--; cout << 2*i << " \n"[n == 0]; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); string s; cin >> s; int n = s.size(); vector<char> cs(n*2+1,'0'); int l = n-1; int r = n; int nl = 0; for (int i=0;i<n;i++) { if (s[i] == 'R') { nl = 1-nl; continue; } if (nl == 1) { cs[l] = s[i]; if (cs[l] == cs[l+1] && cs[l] != '0') { cs[l] = '0'; cs[l+1] = '0'; l++; } else l--; } if (nl == 0) { cs[r] = s[i]; if (cs[r] == cs[r-1] && cs[r] != '0') { cs[r] = '0'; cs[r-1] = '0'; r--; } else r++; } } string ans = ""; for (int i=0;i<=2*n;i++) { if (cs[i] != '0') { ans += cs[i]; } } if (nl == 1) reverse(ans.begin(),ans.end()); cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; signed main() { int n,sum=0; cin>>n; int arr1[n]; int arr2[n]; for(int i=0;i<n;i++) { cin>>arr1[i]; } for(int i=0;i<n;i++) { cin>>arr2[i]; } for(int i=0;i<n;i++) { sum+=arr1[i]*arr2[i]; } if(sum==0)cout<<"Yes"<<endl; else cout<<"No"<<endl; }
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <math.h> #include <vector> using namespace std; using ll = long long; using Graph = vector<vector<int> >; #define INF 500010 int main(){ int n, A[INF], B[INF], C[INF]; cin>>n; for(int i=1;i<=n;i++) cin>>A[i]; for(int i=1;i<=n;i++) cin>>B[i]; for(int i=1;i<=n;i++) cin>>C[i]; ll ac[INF], bc[INF]; memset(ac, 0, sizeof(ac)); memset(bc, 0, sizeof(bc)); for(int i=1;i<=n;i++) ac[A[i]]++; for(int i=1;i<=n;i++) bc[B[C[i]]]++; ll s=0; for(int i=1;i<=n;i++){ s+=ac[i]*bc[i]; } cout<<s<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> p_ll; template<class T> void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; } #define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++) #define all(vec) vec.begin(), vec.end() #define rep(i,N) repr(i,0,N) #define per(i,N) for (ll i=(ll)N-1; i>=0; i--) #define popcount __builtin_popcount const ll LLINF = pow(2,61)-1; const ll INF = pow(2,30)-1; ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); } ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } int main() { ll N; cin >> N; string S; cin >> S; ll Q; cin >> Q; ll T[Q], A[Q], B[Q]; rep(i,Q) { cin >> T[i] >> A[i] >> B[i]; A[i]--; B[i]--; } bool flip = false; rep(i,Q) { if (T[i]==1) { if (flip) { A[i] = (A[i]+N) % (2*N); B[i] = (B[i]+N) % (2*N); } swap(S[A[i]],S[B[i]]); } else flip = !flip; } string result = flip ? S.substr(N,N) + S.substr(0,N) : S; cout << result << endl; return 0; }
#pragma region Macros #include <bits/stdc++.h> #if defined(LOCAL) || defined(ONLINE_JUDGE) || defined(_DEBUG) #include <atcoder/all> #endif using namespace std; #define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i) #define REPR(i, n) for(int i=(n); i>=0; --i) #define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i) #define EACH(i, v) for(const auto& i : v) #define ALL(x) (x).begin(),(x).end() #define ALLR(x) (x).rbegin(),(x).rend() 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>using vec = vector<T>; template<class T, class U>using umap = unordered_map<T, U>; template<class T>using uset = unordered_set<T>; using ll = long long; using ld = long double; using P = pair<ll, ll>; //using T = tuple<ll, ll, ll>; using vl = vec<ll>; #define fi first #define se second #define el endl constexpr ll INF = numeric_limits<ll>::max()/2-1; #pragma endregion #pragma region IOMacros template<class T> istream &operator>>(istream &stream, vec<T>& o){REP(i, o.size())stream >> o[i];return stream;} template<class T> ostream &operator<<(ostream &stream, vec<T>& objs){REP(i, objs.size())stream << objs[i] << " ";stream << el;return stream;} #define I(T, ...) ;T __VA_ARGS__;__i(__VA_ARGS__); void __i() {} template<class T, class... Ts> void __i(T&& o, Ts&&... args){cin >> o;__i(forward<Ts>(args)...);} void O() {cout << el;} template<class T, class... Ts> void O(T&& o, Ts&&... args){cerr << o << " ";O(forward<Ts>(args)...);} #pragma endregion void Main(); int main(){ std::cin.tie(nullptr); std::cout << std::fixed << std::setprecision(15); Main(); return 0; } void Main(){ I(ll, N); I(string, S); I(ll, Q); bool isswap = false; REP(i, Q){ I(ll, T, A, B); --A, --B; if(T==1){ if(isswap){ if(A>=N){ A-=N; }else{ A+=N; } if(B>=N){ B-=N; }else{ B+=N; } } swap(S[A], S[B]); }else{ isswap=!isswap; } } if(isswap){ cout << S.substr(N) << S.substr(0, N) << el; }else{ cout << S << el; } }
#include<bits/stdc++.h> typedef long long ll; #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define last freopen("input.txt","r",stdin);freopen("output.txt","w",stdout); #define fr first #define sc second #define lcm(a,b) (a*b)/__gcd(a,b) #define com(i,n) for(int i=0;i<n;i++) #define dom(i,n) for(int i=1;i<=n;i++) #define mom(i,n) for(int i=n;i>=0;i--) #define sortI(a,n) sort(a,a+n) #define sortD(a,n) sort(a,a+n,greater<int>()) #define sortvi(a) sort(a.begin(),a.end()) #define sortvd(a) sort(a.begin(),a.end(),greater<int>()) #define sumall(a,x) accumulate(a.begin(),a.end(),x) #define pi 3.14159265358979323846264338327950 #define endl '\n' using namespace std; int main() { ll n,x; string s; cin>>n>>x>>s; com(i,n) { if(s[i]=='x') { if(x>0) x--; } else x++; } cout << x << endl; }
#include<bits/stdc++.h> using namespace std; //#define pb push_back //typedef long long ll; int main() { int n,x; cin>>n>>x; string s; cin>>s; for(int i=0;i<n;i++) { if(s[i]=='o')x++; else if(x>0)x--; } cout<<x<<endl; return 0; }
#pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include<stdio.h> using ll=long long; constexpr int mod=1000000007; int N,M,K,inv[2000000]={1,1}; int main(){ for(int i=2;i<2000000;++i)inv[i]=ll(inv[mod%i])*(mod-mod/i)%mod; for(int i=2;i<2000000;++i)inv[i]=ll(inv[i])*inv[i-1]%mod; scanf("%d %d %d",&N,&M,&K); int p=1; for(int i=2;i<=N+M;++i)p=ll(p)*i%mod; int ans=ll(p)*inv[N]%mod*inv[M]%mod; if(N+M<=K||N==K){ printf("%d\n",ans); return 0; } if(N>M+K){ puts("0"); return 0; } ++K; ans-=ll(p)*inv[N-K]%mod*inv[M+K]%mod; if(ans<0)ans+=mod; printf("%d\n",ans); }
#include <bits/stdc++.h> #include <random> #include <chrono> using namespace std; //#pragma GCC optimize("Ofast") //#pragma GCC optimize ("unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<ll,ll> pll; typedef pair<double,double> pdd; //mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); template<typename T> void _do(T x){cerr<<x<<"\n";} template<typename T,typename ...U> void _do(T x,U ...y){cerr<<x<<", ";_do(y...);} #define dbg(...) cerr<<#__VA_ARGS__<<" = ";_do(__VA_ARGS__); const int MOD1=1e9+7; const int MOD2=998244353; const ll INF=2e18; const ld PI=3.14159265358979323846; ll gcd(ll a,ll b){if(b==0) return a; return gcd(b,a%b);} ll fpow(ll a,ll b,ll m) { if(!b) return 1; ll ans=fpow(a*a%m,b/2,m); return (b%2?ans*a%m:ans); } ll inv(ll a,ll m) {return fpow(a,m-2,m);} #define MottoHayaku ios::sync_with_stdio(false);cin.tie(0); #define rep(i,n) for(ll i=0;i<n;i++) #define rep1(i,n) for(ll i=1;i<=n;i++) #define repk(i,m,n) for(int i=m;i<n;i++) #define F first #define S second #define pb push_back #define SZ(a) ((ll)a.size()) #define reset(a) memset(a,0,SZ(a)) #define cd(a,b) ((a+b-1)/b) #define pow2(a) (1LL<<a) #define LB(a,x) (lower_bound(a.begin(),a.end(),x)) #define LPOS(a,x) (lower_bound(a.begin(),a.end(),x)-a.begin()) #define UB(a,x) (upper_bound(a.begin(),a.end(),x)) #define UPOS(a,x) (upper_bound(a.begin(),a.end(),x)-a.begin()) #define uni(c) c.resize(distance(c.begin(),unique(c.begin(),c.end()))) #define unisort(c) sort(c.begin(),c.end()),uni(c) ll fac[2000005]; int main() { MottoHayaku ll n,m,k; cin>>n>>m>>k; if(n>m+k) { cout<<"0\n"; return 0; } fac[0]=1; rep1(i,n+m) fac[i]=fac[i-1]*i%MOD1; ll a=fac[n+m]*inv(fac[n],MOD1)%MOD1*inv(fac[m],MOD1)%MOD1; ll b; if(n+m<m+k+1) b=0; else b=fac[n+m]*inv(fac[m+k+1],MOD1)%MOD1*inv(fac[n-k-1],MOD1)%MOD1; cout<<(a-b+MOD1)%MOD1<<"\n"; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define all(x) (x).begin(),(x).end() template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;} template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;} int dx[4]={0,1,0,-1}, dy[4]={1,0,-1,0}; long double eps = 1e-9; long double pi = acos(-1); signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); int n; cin>>n; string s; cin>>s; int m = n+1; int a[m]; int k = 1e9; for(int i=0;i<m;i++)cin>>a[i]; for(int i=1;i<m;i++)chmin(k,abs(a[i]-a[i-1])); cout << k << endl; vector<vector<int>> ans(k); for(int i=0;i<k;i++){ for(int j=0;j<m;j++){ ans[i].push_back(a[j]/k); } } int rem[m]={}; for(int i=0;i<m;i++)rem[i] = a[i] % k; for(int i=0;i<k;i++){ for(int j=0;j<m;j++){ if(rem[j]){ ans[i][j]+=1; rem[j]--; } cout << ans[i][j] << " "; } cout << endl; } }
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; const int N = 505; int m, n; char A[N][N]; struct Data { int r,c; } F[N][N]; int poww[1005]; Data combine(Data X, Data Y) { if(X.r > Y.r) swap(X, Y); if(X.r + X.c < Y.r) return {-1,-1}; X.c -= Y.r - X.r; return {Y.r,min(X.c, Y.c)}; } int G[1005]; int main() { if(fopen("A.inp","r")) { freopen("A.inp","r",stdin); freopen("A.out","w",stdout); } cin >> m >> n; poww[0] = 1; for(int i = 1; i <= m + n; i++) poww[i] = (poww[i-1] * 2)%MOD; for(int i = 1; i <= m; i++) for(int j = 1; j <= n; j++) cin >> A[i][j]; for(int i = 1; i <= m; i++) for(int j = 1; j <= n; j++) { int k = 0; if(A[i][j] == 'R') k = 1; if(A[i][j] == 'B') k = 2; if(G[i+j]) { if(G[i+j] != k && k > 0) { cout << 0; return 0; } } else G[i+j] = k; } int cnt = 0; for(int i = 2; i <= m + n; i++) cnt += (G[i] == 0); cout << poww[cnt]; }
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; int n, m; string a[2005]; int hor[2005], ver[2005], diag[5005]; int dp[2005][2005]; int offset(int x) { return x + 2500; } int add(int x, int y) { return ((long long) (x + y)) % INF; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> a[i]; a[i] = "." + a[i]; } dp[1][1] = hor[1] = ver[1] = diag[offset(1 - 1)] = 1; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (a[i][j] == '#') { hor[i] = ver[j] = diag[offset(i - j)] = 0; continue; } if (i == 1 && j == 1) continue; dp[i][j] = add(add(hor[i], ver[j]), diag[offset(i - j)]); hor[i] = add(hor[i], dp[i][j]); ver[j] = add(ver[j], dp[i][j]); diag[offset(i - j)] = add(diag[offset(i - j)], dp[i][j]); } } cout << dp[n][m] << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for(ll i = 0; i < (ll)(n); i++) typedef long long ll; typedef pair<ll, ll> P; const ll INF = 1e18; const ll MOD = 1000000007; int N, M; void dfs(int t, vector<P> &V, set<int> &checked, vector<vector<int>> &G) { for(auto &i : G[t]) { if(checked.count(i)) continue; V.push_back(P(i, t)); checked.insert(i); dfs(i, V, checked, G); } return; } int C[25]; ll search(int now_id, vector<P> &V, vector<vector<int>> &G) { if(now_id == V.size()) { for(auto &s : V) { for(auto &t : G[s.first]) { if(C[s.first] == C[t]) { return 0; } } } return 1; } if(now_id == 0) { ll ret = 0; C[V[now_id].first] = 1; ret += search(now_id + 1, V, G); C[V[now_id].first] = 0; C[V[now_id].first] = 2; ret += search(now_id + 1, V, G); C[V[now_id].first] = 0; C[V[now_id].first] = 3; ret += search(now_id + 1, V, G); C[V[now_id].first] = 0; return ret; } else { ll ret = 0; for(int i = 1; i <= 3; ++i) { if(C[V[now_id].second] != i) { C[V[now_id].first] = i; ret += search(now_id + 1, V, G); C[V[now_id].first] = 0; } } return ret; } } int main() { cin >> N >> M; vector<vector<int>> G(N); REP(i, M) { int A, B; cin >> A >> B, A--, B--; G[A].push_back(B), G[B].push_back(A); } ll ans = 1; set<int> checked; REP(i, N) { if(checked.count(i)) continue; vector<P> V; set<int> s; s.insert(i); V.push_back(P(i, -1)); dfs(i, V, s, G); for(auto &x : V) { checked.insert(x.first); } ans *= search(0, V, G); } cout << ans << endl; }
#include <bits/stdc++.h> #define int long long int using namespace std; signed main(){ ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); int a , b; cin>>a>>b; cout<<(a+b)/2<<" "<<(a-b)/2<<"\n"; }
#include<iostream> #include<algorithm> #include<string> #include<vector> #include<cstdlib> #include<queue> #include<set> #include<cstdio> #include<map> #include<cassert> using namespace std; #define ll long long #define reps(i, a, b) for(int i = a; i < b; i++) #define rreps(i, a, b) for(int i = a-1; i >= b; i--) #define rep(i, n) reps(i, 0, n) #define rrep(i, n) rreps(i, n, 0) #define P pair<int, int> #define vec vector<ll> #define mat vector<vec> const ll mod = 1000000007; const int INF = 1001001001; int main(){ ll n, x; cin >> n >> x; vec a(n); vec r(n-1); rep(i, n) cin >> a[i]; rep(i, n-1) r[i] = a[i+1] / a[i]; vec X(n); ll x_ = x; rrep(i, n){ X[i] = x_ / a[i]; x_ %= a[i]; } // rep(i, n){ // cout << X[i] << " "; // }cout << endl; // rep(i, n){ // cout << r[i] << " "; // }cout << endl; mat dp(n, vec(2)); dp[0][0] = 1; dp[0][1] = 0; rep(i, n-1){ if(X[i] == r[i]-1){ dp[i+1][0] = dp[i][0]; dp[i+1][1] = dp[i][0] + dp[i][1]; }else if(X[i] == 0){ dp[i+1][0] = dp[i][0] + dp[i][1]; dp[i+1][1] = dp[i][1]; }else{ dp[i+1][0] = dp[i][0] + dp[i][1]; dp[i+1][1] = dp[i][0] + dp[i][1]; } // cout << dp[i+1][0] << " " << dp[i+1][1] << endl; } cout << dp[n-1][0] + dp[n-1][1] << endl; }
#include<iostream> #include<algorithm> #include<cstring> #define debug(a) cout<<#a<<" = "<<a<<endl using namespace std; typedef long long ll; const int N = 5010; const int MOD = 998244353; int n , m; ll C[N]; ll f[N]; ll Q_power(ll a ,ll b){ ll res = 1; while(b){ if(b & 1) res = res * a % MOD; b >>= 1; a = a*a % MOD; } return res; } ll X_1(ll a){ return Q_power(a ,MOD - 2) ;} void init(){ C[0] = 1; for(int i = 1 ; i <= n ; i ++){ C[i] = C[i - 1] * (n - i + 1) % MOD * X_1(i) % MOD; } } ll F(int m){ if(~f[m] == 0){ f[m] = 0; if(!(m & 1)){ for(int i = 0 ; i * 2 <= m ; i ++){ f[m] = (f[m] + C[i * 2] * F(m / 2 - i) % MOD) % MOD; } } } return f[m]; } int main(){ cin >> n >> m; memset(f,0xff,sizeof f); init(); f[0] = 1; cout << F(m) << endl; return 0; }
#include<cstdio> #include<algorithm> #include<cstring> #define ll long long #define fo(i,x,y) for(ll i=x;i<=y;i++) #define fd(i,x,y) for(ll i=x;i>=y;i--) using namespace std; const int N=5010,M=5010; const int E=17; const ll mod=998244353; ll n,m,i,j,k,tot,ans,s,t,x,y,z; ll f[E][M]; ll e[E]; ll jie[M],ny[M]; void read(ll &a) { a=0; char c=getchar(); while (c<'0'||c>'9') c=getchar(); while (c>='0'&&c<='9') {a=a*10-48+c; c=getchar();} return; } ll ksm(ll i,ll j) { ll re=1; while (j>0) { if (j&1) re=re*i%mod; j/=2; i=i*i%mod; } return re; } void ycl() { jie[0]=1; fo(i,1,M-1) jie[i]=jie[i-1]*i%mod; ny[M-1]=ksm(jie[M-1],mod-2); fd(i,M-2,0) ny[i]=ny[i+1]*(i+1)%mod; } ll C(ll x,ll y) {return jie[x]*ny[y]%mod*ny[x-y]%mod;} int main() { ycl(); read(n); read(m); e[1]=1; fo(i,2,E-1) e[i]=e[i-1]*2; f[0][0]=1; fo(i,1,E-1) { if (e[i]>m) {t=i-1; break;} for (j=0;j<=m/e[i]&&j<=n;j+=2) { fo(k,0,m-e[i]*j) f[i][k+e[i]*j]=(f[i][k+e[i]*j]+f[i-1][k]*C(n,j))%mod; } } ans=f[t][m]; printf("%lld\n",ans); }
#include<bits/stdc++.h> using namespace std; #define int long long const int mod=998244353; signed main(){ int a,b,c; cin>>a>>b>>c; a=a*(a+1)/2; b=b*(b+1)/2; c=c*(c+1)/2; a%=mod;b%=mod;c%=mod; cout<<a*b%mod*c%mod; return 0; }
#include <bits/stdc++.h> using namespace std ; const int N = 105 ; double dp[N][N][N] ; double solve(int a, int b, int c){ if(a == 100 || b == 100 || c == 100){ return 0 ; } if(dp[a][b][c]){ return dp[a][b][c] ; }else{ int num = a+b+c ; double ans = 1.0 + (double)(1.0*a/num)*solve(a+1, b,c) + (double)(1.0*b/num)*solve(a, b+1 ,c) + (double)(1.0*c/num)*solve(a, b,c+1) ; return dp[a][b][c] = ans ; } } int main(){ int a, b, c ; double ans = 0 ; cin >> a >> b >> c ; solve(a,b, c) ; printf("%.9lf", dp[a][b][c]) ; return 0 ; }
#include "bits/stdc++.h" using namespace std; #define sim template < class c #define ris return * this #define dor > debug & operator << #define eni(x) sim > typename \ enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { #ifdef LOCAL ~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } #else sim dor(const c&) { ris; } #endif }; #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " using ll = long long; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<pair<int, int>> edges(n - 1); vector<vector<int>> adj(n); for(int i = 0; i < n-1; i++){ int a, b; cin >> a >> b; --a, --b; edges[i] = {a, b}; adj[a].push_back(b); adj[b].push_back(a); } vector<int> depth(n, -1); queue<int> q; depth[0] = 0; q.push(0); while(!q.empty()){ int x = q.front(); q.pop(); for(int y: adj[x]){ if(depth[y] < 0){ depth[y] = 1 + depth[x]; q.push(y); } } } vector<ll> save(n); int Q; cin >> Q; while(Q--){ int t, e, x; cin >> t >> e >> x; auto [a, b] = edges[e - 1]; if(t == 2) swap(a, b); if(depth[a] < depth[b]){ save[0] += x; save[b] -= x; } else{ save[a] += x; } } assert(q.empty()); q.push(0); while(!q.empty()){ int x = q.front(); q.pop(); for(int y: adj[x]){ if(depth[y] > depth[x]){ save[y] += save[x]; q.push(y); } } } for(ll i: save){ cout << i << "\n"; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> p_ll; template<class T> void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; } #define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++) #define all(vec) vec.begin(), vec.end() #define rep(i,N) repr(i,0,N) #define per(i,N) for (ll i=(ll)N-1; i>=0; i--) const ll MOD = pow(10,9)+7; const ll LLINF = pow(2,61)-1; const ll INF = pow(2,30)-1; vector<ll> fac; void c_fac(ll x=pow(10,7)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; } ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { ll d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; } ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; } ll modpow(ll x, ll p) { ll result = 1, now = 1, pm = x; while (now<=p) { if (p&now) { result = result * pm % MOD; } now*=2; pm = pm*pm % MOD; } return result; } ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); } ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } struct edge { ll to, d1, d2; }; vector<vector<edge>> adj; vector<ll> result; ll pl = 0; void dfs(ll n=0, ll p=-1, ll sum=0) { result[n] += sum; for (auto x: adj[n]) { if (x.to==p) continue; pl += x.d2; dfs(x.to,n,sum+(x.d1-x.d2)); } } int main() { ll N; cin >> N; ll a[N-1], b[N-1]; rep(i,N-1) { cin >> a[i] >> b[i]; a[i]--; b[i]--; } ll toa[N-1] = {}, tob[N-1] = {}; ll Q; cin >> Q; rep(i,Q) { ll t, e, x; cin >> t >> e >> x; e--; if (t==1) toa[e] += x; else tob[e] += x; } adj.resize(N); rep(i,N-1) { adj[a[i]].push_back({b[i],tob[i],toa[i]}); adj[b[i]].push_back({a[i],toa[i],tob[i]}); } result.resize(N); dfs(); rep(i,N) result[i] += pl; debug(all(result)); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll INF = 1LL << 60; ll MOD = 1000000000 + 7; int main() { string s, t = ""; bool rev = false; cin >> s; for (int i = 0; i < s.size(); i++) { if (s[i] == 'R') { rev = !rev; continue; } if (t == "") { t += s[i]; continue; } if (!rev) { if (s[i] == t[t.size() - 1]) { t.pop_back(); continue; } t += s[i]; } if (rev) { if (s[i] == t[0]) { t.erase(t.begin()); continue; } t.insert(0, {s[i]}); } } string ans = ""; if (!rev) ans = t; if (rev) { for (int i = t.size() - 1; i >= 0; i--) ans += t[i]; } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; #define gc() getchar() #define pc(a) putchar(a) #define int long long #define inf (1ll<<60) inline int read() { int x=0,f=1; char c=gc(); while(c<'0'||c>'9') { if(c=='-') f=-f; c=gc(); } while(c>='0'&&c<='9') x=x*10+c-'0',c=gc(); // cout<<x<<endl; return x*f; } int nnu[25]; inline void write(int x) { if(x<0) pc('-'),x=-x; if(!x) { pc('0'); return; } int tp=0; while(x) nnu[++tp]=x%10,x/=10; while(tp) pc(nnu[tp--]+'0'); return; } #define ma 500005 char s[ma]; int cnt[ma]; signed main() { int A=read(),B=read(),C=read(),D=read(); B=D*C-B; // cout<<B<<endl; if(B<=0) puts("-1"); else cout<<(int)max(0.0,ceil(1.0*A/B)); }
/****Bismillahir rahmanir rahim****/ #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<long long> vl; typedef vector<double> vd; #define All(a) a.begin(),a.end() template <typename T> void get_vector(T &a) { for(auto &e: a) cin >> e; } template <typename T> void put_vector(T a) { for(auto e :a)cout << e << " "; cout << endl; } int main() { int n; cin >> n; vd a(n),b(n),c(n),d(n); int x = 0,y = 0; for(int i = 0 ;i <n; i++) { cin >> a[i]>>b[i]; x += a[i];y += b[i]; a[i]*=n;b[i]*=n; } for(int i = 0; i<n ; i++) { a[i] -= x; b[i]-= y; }x = 0, y = 0; for(int i = 0 ;i <n; i++) { cin >> c[i]>>d[i]; x += c[i];y += d[i]; c[i]*=n;d[i]*=n; } for(int i = 0; i<n ; i++) { c[i] -= x; d[i]-= y; } double X,Y; for(int i=0; i<n; i++){ if(a[i]!=0 || b[i]!=0){ swap(a[i],a[0]); swap(b[i],b[0]); } } X = a[0]; Y = b[0]; // put_vector(a); put_vector(b);put_vector(c);put_vector(d); //cout << "x = " << X << " Y = " << Y << endl; const double diff = 1e-6; string ans = "No"; for(int i = 0; i <n;i++) { double angle = atan2(d[i],c[i]) - atan2(Y,X); bool ok = true; for(int j = 0; j<n; j++) { double cx = a[j]*cos(angle) - b[j]*sin(angle); double cy = a[j]*sin(angle) + b[j]*cos(angle); bool ok2 = false; for(int k = 0; k<n; k++) { if(abs(cx-c[k])<=diff&&abs(cy-d[k])<=diff)ok2 = true; } ok &= ok2; } if(ok)ans = "Yes"; } cout << ans << endl; return 0; }
/* ______________________ _______ _______ _______ _______ ( ____ \__ __( __ \ ( ____ | ___ | ____ ( ___ ) | ( \/ ) ( | ( \ ) | ( )| ( ) | ( \/ ( ) | | (_____ | | | | ) | | (____)| (___) | (_____| (___) | (_____ ) | | | | | | | __) ___ (_____ ) ___ | ) | | | | | ) | | (\ ( | ( ) | ) | ( ) | /\____) |__) (__| (__/ ) | ) \ \_| ) ( /\____) | ) ( | \_______)_______(______/___|/ \__// \_______)/ \| (_____) One day I will be Candidate Master on Codeforces I didn't come this far to only come this far */ #include <bits/stdc++.h> using namespace std; #define int long long int #define pb push_back #define mp make_pair #define fe(i, a, b) for (int i = a; i <= b; i++) #define fl(i, a, b) for (int i = a; i < b; i++) #define vi vector<int> #define e1(a) int a; cin>>a; #define e2(a,b) int a,b; cin>>a>>b; #define e3(a,b,c) int a,b,c; cin>>a>>b>>c; #define av(arr,n) vector<int> arr(n); fl(i,0,n) cin>>arr[i]; #define aa(arr,n) int arr[n]; fl(i,0,n) cin>>arr[i]; #define es(s) string(s); cin >> (s); #define rz resize #define sz(s) s.size() #define mod 1000000007 #define ff first #define ss second #define tn -10e15 #define bg 10e15 #define all(x) (x).begin(), (x).end() #define pii pair<int, int> #define mii map<int,int> #define st(a, n) memset(a, n, sizeof(a)) #define vl(n) cout << n << "\n" #define vs(n) cout << n << " " #define el cout<<"\n" #define vn(n) cout << n #define dsc greater<int>() #define ps(x,y) fixed<<setprecision(y)<<x #define R return #define B break #define C continue #define YC cout<<"YES"<<"\n" #define YS cout<<"Yes"<<"\n" #define NC cout<<"NO"<<"\n" #define NS cout<<"No"<<"\n" #define lcm(a,b) (a/__gcd(a,b))*b #define pa(a) for(auto e:a)cout<<e<<" " const int N = 4e5 + 5; void solve() { e1(n); aa(a, n); vi f(202, 0); vi f2(202, 0); fl(i,0,n){ if(a[i]>0) f[abs(a[i])]++; else { f2[abs(a[i])]++; } } int ans = 0; fl(i,0,n){ int x = a[i]; fe(j,0,201){ if(f[j]>0){ int p = abs(x - j); p *= p; ans += p * f[j]; } } fe(j, 0, 201) { if(f2[j]>0){ int p = abs(x + j); p *= p; ans += p * f2[j]; } } } vl(ans/2); } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(ll i=0;i<ll(n);i++) #define REP(i,k,n) for(ll i=k;i<ll(n);i++) #define all(a) a.begin(),a.end() #define eb emplace_back #define lb(v,k) (lower_bound(all(v),k)-v.begin()) #define ub(v,k) (upper_bound(all(v),k)-v.begin()) #define fi first #define se second #define PQ(T) priority_queue<T> #define SPQ(T) priority_queue<T,vector<T>,greater<T>> #define UNIQUE(a) sort(all(a));a.erase(unique(all(a)),a.end()) #define decimal cout<<fixed<<setprecision(10) #define summon_tourist cin.tie(0);ios::sync_with_stdio(false) using ll=long long; using P=pair<ll,ll>; using vi=vector<ll>; using vvi=vector<vi>; using vvvi=vector<vvi>; constexpr ll inf=1001001001001001; constexpr int INF=1001001001; constexpr int mod=3; template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;} template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;} template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);} template<class T> void out(T a){cout<<a<<'\n';} template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';} template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';} template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';} template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);} void YesNo(bool b){if(b)out("Yes");else out("No");} void yesno(bool b){if(b)out("yes");else out("no");} void YESNO(bool b){if(b)out("YES");else out("NO");} ll modpow(ll a,ll b){ll c=1;while(b>0){if(b&1){c=a*c%mod;}a=a*a%mod;b>>=1;}return c;} vi calc(ll x){vi v;while(x>0){v.eb(x%10);x/=10;}reverse(all(v));return v;} ll bb(char c){ if(c=='B') return 0; if(c=='W') return 1; if(c=='R') return 2; } vi v(410000),cnt(410000); void init(ll n){ v[1]=1,cnt[1]=0; REP(i,2,n+5){ if(i%3==0){ ll j=i,c=0; while(j%3==0){j/=3; c++;} v[i]=v[i-1]*j%3; cnt[i]=cnt[i-1]+c; } else{ v[i]=v[i-1]*i%3; cnt[i]=cnt[i-1]; } } } ll COM(ll n,ll r){ if(r==0||n==r) return 1; else if(cnt[n]>cnt[r]+cnt[n-r]) return 0; else{ ll a=v[n],b=v[r]*v[n-r]%3; if(a==b) return 1; else return 2; } } int main(){ ll n; cin>>n; init(n); string c; cin>>c; ll sum=0; rep(i,n){ if(i>n-i-1) break; sum+=bb(c[i])*COM(n-1,i)%mod; sum%=mod; //out(sum); if(i<n-i-1) sum+=bb(c[n-1-i])*COM(n-1,i)%mod; sum%=mod; //out(sum); } ll ans; if(n%2==0) ans=(3-sum)%3; else ans=sum; if(ans==0) out("B"); else if(ans==1) out("W"); else out("R"); /*REP(i,1,10){ rep(j,i+1) cout<<COM(i,j); cout<<endl; }*/ }
#include<iostream> #include<iterator> #include<algorithm> #include<climits> #include<map> #include<set> #include<cmath> #include<numeric> #include<string> #include<sstream> #include<cstdio> #include<vector> #include<bitset> // #include <atcoder/segtree> #define ll long long using namespace std; int main() { ll n, m; cin >> n >> m; ll a[101] = {0}; ll b[101] = {0}; for(int i = 1; i <= m; ++i){ cin >> a[i] >> b[i]; } ll k; cin >> k; ll c[17] = {0}; ll d[17] = {0}; for(int i = 1; i <= k; ++i){ cin >> c[i] >> d[i]; } unsigned long long pow2k = (unsigned long long)pow(2,k); ll max_meet_count = 0; for (unsigned long long i = 0; i < pow2k; ++i){ ll dish[101] = {0}; bitset<64> bs(i); for(int shift=0; shift<k; ++shift){ bool valid = (i>>shift)&1ull; if (valid){ dish[c[shift+1]]+=1; }else{ dish[d[shift+1]]+=1; } } ll meet_count = 0; for(int j = 1; j <= m; ++j){ if (dish[a[j]] > 0 && dish[b[j]] > 0){ ++meet_count; } } if (max_meet_count < meet_count){ max_meet_count = meet_count; } } cout << max_meet_count << endl; }
#include <iostream> #include <algorithm> #include <cmath> #include <limits> #include <iomanip> #include <vector> #include <cstring> #include <queue> #include <deque> #include <map> #include <set> #include <numeric> #include <unordered_map> #include <unordered_set> typedef long long ll; typedef long double ld; #define rep(i,n) for(int i=0;i<n;i++) #define rep1(i,n) for(int i=1;i<=n;i++) #define rrep(i,n) for(int i=n-1;i>=0;i--) #define REP(i,L,R) for(int i=L;i<R;i++) using namespace std; typedef vector<vector<int>> Graph; //decralation //struct area // Erathostenes's sieve //main area int main(){ ll N; cin >> N; vector<ll> A(N); rep(i,N) cin >> A[i]; vector<ll> cnt(200,0); rep(i,N) cnt[(A[i])%200]++; ll ans = 0; rep(i,200){ ans += cnt[i]*(cnt[i]-1)/2; } cout << ans << endl; } /* */
#include <bits/stdc++.h> #include <strings.h> using namespace std; int main(){ string question, no_rev; char this_char, prev_char; int i = 0, rev; cin >> question; rev = -1; while((this_char = question[i++]) != '\0'){ if(this_char == 'R'){ rev *= -1; } else if (rev == -1) { no_rev.push_back(this_char); } else { no_rev.insert(0, 1, this_char); } } if(rev == 1){ reverse(no_rev.begin(),no_rev.end()); } i = 0; prev_char = '\0'; string answer; while((this_char = no_rev[i++]) != '\0'){ if(this_char == prev_char){ answer.pop_back(); } else { answer.push_back(this_char); } prev_char = answer[answer.length() - 1]; } cout << answer << '\n'; }
#include <bits/stdc++.h> // using namespace std; typedef long long LL; typedef pair<int, int> pii; typedef pair<LL, LL> pll; typedef pair<string, string> pss; typedef vector<LL> vi; typedef vector<vi> vvi; typedef vector<pii> vii; typedef vector<LL> vl; typedef vector<vl> vvl; double EPS = 1e-9; LL INF = 60; long long INFF = 1000000000000000005LL; double PI = acos(-1); int dirx[8] = { -1, 0, 0, 1, -1, -1, 1, 1 }; int diry[8] = { 0, 1, -1, 0, -1, 1, -1, 1 }; #define FOR(a, b, c) for (int(a) = (b); (a) < (c);) #define FORN(a, b, c) for (int(a) = (b); (a) < (c); ++(a)) #define FORD(a, b, c) for (int(a) = (b); (a) >= (c); --(a)) #define FORSQ(a, b, c) for (int(a) = (b); (a) * (a) <= (c); ++(a)) #define FORC(a, b, c) for (char(a) = (b); (a) <= (c); ++(a)) #define FOREACH(a, b) for (auto&(a) : (b)) #define REP(i, n) FOR(i, 0, n) #define REPN(i, n) FORN(i, 1, n) #define MAX(a, b) a = max(a, b) #define MIN(a, b) a = min(a, b) #define SQR(x) ((LL)(x) * (x)) #define RESET(a, b) memset(a, b, sizeof(a)) #define fi first #define se second #define mp make_pair #define pb push_back #define ALL(v) v.begin(), v.end() #define ALLA(arr, sz) arr, arr + sz #define SIZE(v) (int)v.size() #define SORT(v) sort(ALL(v)) #define REVERSE(v) reverse(ALL(v)) #define SORTA(arr, sz) sort(ALLA(arr, sz)) #define REVERSEA(arr, sz) reverse(ALLA(arr, sz)) #define PERMUTE next_permutation #define TC(t) while (t--) int main() { double a,b,x,y; cin>>a>>b; x = (a+b)/2.0; y = a-x; cout<<x<<" "<<y<<endl; }
#include<bits/stdc++.h> using namespace std; int main(){ int A,B; cin >> A >> B; cout << (A+B)/2 << " " << (A-B)/2 << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define re register #define pb push_back #define fi first #define se second const int N=1e7+10; const int mod7=1e9+7; const int mod=998244353; const int M=1e7; const double pi=acos(-1); void read(int &a) { a=0;int d=1;char ch; while(ch=getchar(),ch>'9'||ch<'0') if(ch=='-') d=-1; a=ch^48; while(ch=getchar(),ch>='0'&&ch<='9') a=(a<<3)+(a<<1)+(ch^48); a*=d; } void read(ll &a) { a=0;int d=1;char ch; while(ch=getchar(),ch>'9'||ch<'0') if(ch=='-') d=-1; a=ch^48; while(ch=getchar(),ch>='0'&&ch<='9') a=(a<<3)+(a<<1)+(ch^48); a*=d; } int main() { int n;read(n); printf("%d\n",n-1); return 0; }
#include <bits/stdc++.h> #define REP(i, a, b) for (int i = a; i <= b; ++i) #define ll long long #define N 100010 using namespace std; int n, cnt; bool f; char ch, a[N], b[N]; inline int read(){ int s = 0, w = 1; char ch = getchar(); for (; ch < '0' || ch > '9'; w *= ch == '-' ? -1 : 1, ch = getchar()); for (; ch >= '0' && ch <= '9'; s = s * 10 + ch - '0', ch = getchar()); return s * w; } int main(){ n = read(); for (int i = 1; i <= n + 1; ++i){ cin >> a[i]; if (a[i] != a[i - 1]) b[++cnt] = a[i]; if (a[i] == a[i - 1] && b[cnt] != b[cnt - 1]) b[++cnt] = a[i]; } cnt--; if (b[1] != b[cnt]){ puts("1"); exit(0); } ch = b[1]; f = 0; for (int i = 1; i <= cnt; ++i){ if (ch == b[i]) f = 0; if (ch != b[i]){ if (f == 1){ puts("2"); exit(0); } f = 1; } } if (f) puts("1"); else puts("-1"); 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, K; cin >> N >> K; int ijk_sum; int num = 0; auto num_s = [&](int s){ if(s < 3) return 0LL; if(s <= N+2) return (s-2)*(s-1)/2; if(s <= 2*N+1) return (s-1)*(2*N-s+2)/2 + (3*N-s+1)*(-N+s-2)/2; else return (3*N-s+1)*(3*N-s+2)/2; }; auto num_two = [&](int t){ if(t < 2) return 0LL; if(t <= N+1) return t-1; if(t <= 2*N) return 2*N-t+1; else return 0LL; }; for(ijk_sum=3; ijk_sum<=3*N; ijk_sum++){ int ns = num_s(ijk_sum); if(num + ns >= K) break; num += ns; } int i; for(i=1; i<=N; i++){ int nt = num_two(ijk_sum-i); if(num + nt >= K) break; num += nt; } int j = max(1LL, ijk_sum-i-N), k = min(ijk_sum-i-1, N); j += K-num-1; k -= K-num-1; cout << i << " " << j << " " << k << endl; return 0; }
#include <cstdio> #include <algorithm> using namespace std; long long dp[4][3000005]; int ans[4]; int main() { int n,st; long long k,sum,now; int all; scanf("%d%lld",&n,&k); dp[0][0]=1; for(int i=1;i<=3;i++) { sum=0; for(int j=0;j<=i*n;j++) { dp[i][j]=sum; sum+=dp[i-1][j]; if(j>=n) sum-=dp[i-1][j-n]; } } now=0; for(int i=0;i<=3*n;i++) { now+=dp[3][i]; if(now>=k) { all=i; k-=now-dp[3][i]; break; } } now=0; for(int i=1;i<=n;i++) { now+=dp[2][all-i]; if(now>=k) { ans[1]=i; for(int j=1;j<=n;j++) if(all-ans[1]-j>=1&&all-ans[1]-j<=n) { ans[2]=j; ans[3]=all-ans[1]-ans[2]; break; } for(int j=0;j<k-(now-dp[2][all-i])-1;j++) { ans[2]++; ans[3]--; } printf("%d %d %d\n",ans[1],ans[2],ans[3]); break; } } return 0; }
#pragma GCC optimize ("Ofast") #include<bits/stdc++.h> using namespace std; template<class S, class T> inline S max_L(S a,T b){ return a>=b?a:b; } inline int my_getchar_unlocked(){ static char buf[1048576]; static int s = 1048576; static int e = 1048576; if(s == e && e == 1048576){ e = fread_unlocked(buf, 1, 1048576, stdin); s = 0; } if(s == e){ return EOF; } return buf[s++]; } inline void rd(long long &x){ int k; int m=0; x=0; for(;;){ k = my_getchar_unlocked(); if(k=='-'){ m=1; break; } if('0'<=k&&k<='9'){ x=k-'0'; break; } } for(;;){ k = my_getchar_unlocked(); if(k<'0'||k>'9'){ break; } x=x*10+k-'0'; } if(m){ x=-x; } } inline void rd(char &c){ int i; for(;;){ i = my_getchar_unlocked(); if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){ break; } } c = i; } inline int rd(char c[]){ int i; int sz = 0; for(;;){ i = my_getchar_unlocked(); if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){ break; } } c[sz++] = i; for(;;){ i = my_getchar_unlocked(); if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){ break; } c[sz++] = i; } c[sz]='\0'; return sz; } struct MY_WRITER{ char buf[1048576]; int s; int e; MY_WRITER(){ s = 0; e = 1048576; } ~MY_WRITER(){ if(s){ fwrite_unlocked(buf, 1, s, stdout); } } } ; MY_WRITER MY_WRITER_VAR; void my_putchar_unlocked(int a){ if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){ fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout); MY_WRITER_VAR.s = 0; } MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a; } inline void wt_L(char a){ my_putchar_unlocked(a); } inline void wt_L(long long x){ int s=0; int m=0; char f[20]; if(x<0){ m=1; x=-x; } while(x){ f[s++]=x%10; x/=10; } if(!s){ f[s++]=0; } if(m){ my_putchar_unlocked('-'); } while(s--){ my_putchar_unlocked(f[s]+'0'); } } template<class S, class T> inline S chmax(S &a, T b){ if(a<b){ a=b; } return a; } int N; char X[70]; long long M; int main(){ int i; long long res = 0; long long d; long long mx; long long b; __int128_t val; N = rd(X); rd(M); for(i=(0);i<(N);i++){ X[i] -= '0'; } int Q5VJL1cS; char e98WHCEY; if(N==0){ e98WHCEY = 0; } else{ e98WHCEY = X[0]; for(Q5VJL1cS=(1);Q5VJL1cS<(N);Q5VJL1cS++){ e98WHCEY = max_L(e98WHCEY, X[Q5VJL1cS]); } } d =e98WHCEY; if(N==1){ if(X[0] <= M){ res++; } wt_L(res); wt_L('\n'); return 0; } if(N==2){ res = (M - X[1]) / X[0] - d; chmax(res, 0); wt_L(res); wt_L('\n'); return 0; } long long FmcKpFmN; long long xr20shxY; long long WYIGIcGE; FmcKpFmN = d; xr20shxY = 1e9; while(FmcKpFmN < xr20shxY){ if((FmcKpFmN + xr20shxY)%2==0){ WYIGIcGE = (FmcKpFmN + xr20shxY) / 2; } else{ WYIGIcGE = (FmcKpFmN + xr20shxY + 1) / 2; } val = 0; for(i=(0);i<(N);i++){ val = val * WYIGIcGE + X[i]; if(val > M){ break; } } if(val <= M){ FmcKpFmN = WYIGIcGE; } else{ xr20shxY = WYIGIcGE - 1; } } b =xr20shxY; res = b - d; wt_L(res); wt_L('\n'); return 0; } // cLay version 20210103-1 [bug fixed 4] // --- original code --- // int N; char X[70]; // ll M; // { // ll res = 0, d, mx, b; // __int128_t val; // rd(X@N,M); // rep(i,N) X[i] -= '0'; // d = max(X(N)); // // if(N==1){ // if(X[0] <= M) res++; // wt(res); // return 0; // } // if(N==2){ // res = (M - X[1]) / X[0] - d; // res >?= 0; // wt(res); // return 0; // } // b = bsearch_max[ll,b,d,1e9][ // val = 0; // rep(i,N){ // val = val * b + X[i]; // if(val > M) break; // } // ](val <= M); // res = b - d; // wt(res); // }
#include <iostream> #include <cstdio> #include <vector> #include <iomanip> #include <unordered_map> #include <unordered_set> #include <algorithm> #include <map> #include <set> #include <cmath> using namespace std; string toBase(long long M, long long b) { string s; while (M) { long long maxVal = min(9LL, (M%b)); if (M%b > 9) { for (int i = 0; i < s.size(); ++i) { s[i] = '9'; } } s += (maxVal+'0'); M /= b; } reverse(s.begin(), s.end()); return s; } int main() { string X; long long M; cin >> X >> M; long long minb = 0; long long maxb = M; // d*B^X <= M => logd + X log B <= log M => X log B <= logM - logd reverse(X.begin(), X.end()); for (int i = 0; i < X.size(); ++i) { long long digit = X[i]-'0'; minb = max(minb, digit+1LL); } if (X.size() == 1) { //only one digit maxb = minb; } long long low = minb; long long up = maxb; long long ans = minb-1; // cout << "DEBUG " << low << " " << maxb << endl; // cout << exp(log(1)) << endl; reverse(X.begin(), X.end()); while (low <= up) { long long mid = (low+up) / 2; bool ok = true; string MS = toBase(M, mid); // cout << "DEBUGGO " << mid << " " << MS << endl; if (MS.size() < X.size() || (MS.size() == X.size() && MS < X)) { ok = false; } if (ok) { low = mid+1; ans = mid; } else { up = mid-1; } } cout << (ans-minb)+1 << endl; return 0; }
#include <iostream> #include <vector> #include <algorithm> #include <map> #include <stdio.h> #include <math.h> #include <iomanip> #include <queue> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double lld; #define rep(i,n) for(int i = 0; i < (n); i++) #define pb push_back #define eb emplace_back #define fi first #define se second #define all(x) x.begin() , x.end() #define vi vector<int> #define vP vector<pair<int,int>> #define vll vector<ll> const static int INF = 1001001001; const static ll LINF = 1001001001001001001LL; const static lld PI = 3.1415926535897932384626L; const static int MOD = 1000000009; //const static int MOD = 998244353; template < typename T > T gcd (T a , T b) { if (a < b) swap(a , b); if (a % b == 0) return b; else return gcd (b , a % b); } template < typename T > T lcm (T a , T b) { return (a / gcd (a , b) * b); } template < typename T > void chmin (T &a , T b) { if (a > b) a = b; } template < typename T > void chmax (T &a , T b) { if (a < b) a = b; } void io_setup () { cout << fixed << setprecision(30); cin.tie(0); ios::sync_with_stdio(false); } //memo ////v.erase(unique(v.begin(), v.end()), v.end()); int main () { io_setup(); lld n; cin >> n; lld ans = 0.0; for (int i = 1; i <= n - 1; i++) { ans += n / (lld)i; } cout << ans << endl; return 0; }
#include <cmath> #include<bits/stdc++.h> using namespace std; #define int long long #define rep(i,a,b) for(int i=a; i<b; ++i) #define all(x) x.begin(),x.end() const long long INF=1e18; const int32_t M=1e9+7; const int32_t MM=998244353; int digits (int a1) { int a=a1; int x = 0; while(a!=0){ a/=10; x++; } return x; } void solve() { int n; cin >> n; int d = digits(n); int nr = n; vector<int> di; rep(i,0,d){ di.push_back(nr%10); nr/=10; } reverse(all(di)); int ans = 0; int y=1; for(int i=2; i<d; i+=2){ int b = (i/2); if(i!=2) y*=10; ans += 9*y; } if(d%2==1){ cout << ans << endl; return; } int l=0,r=0; int p = (d/2)-1; for(int i=0;i<d/2;i++){ l += di[i]*pow(10,p-i); r += di[(d/2)+i]*pow(10,p-i); } int k = l-pow(10,p); k++; ans += k; if(l<=r) cout << ans << endl; else cout << ans-1 << endl; } int32_t main() { ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); int t=1;//cin>>t; while(t--) solve(); return 0; }
#include<iostream> #include <algorithm> #include <vector> #include <string> #include <cmath> #include <iomanip> using namespace std; typedef long long ll; typedef pair<int,int> P; int main(){ string A, B; cin >> A >> B; int nA=0, nB=0; for(int i=0;i<3;i++){ nA += A[i]-'0'; nB += B[i]-'0'; } cout << max(nA, nB) <<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define endl "\n" #define ll long long #define ld long double #define rep(i,n) for (ll i = 0;i<(n);++i) #define all(v) v.begin(),v.end() template <typename T>bool chmax(T &a, const T& b) {if (a < b) {a = b;return true;}return false;} template <typename T>bool chmin(T &a, const T& b) {if (a > b) {a = b;return true;}return false;} vector<long long> divisor(long long n){vector<long long> res;long long i = 1;while (i*i<=n){if(n%i==0){res.push_back(i);}i++;}if(res.size()==0)return res;for(long long i = res.size()-1-(res.back()*res.back()==n);i>=0;--i){res.push_back(n/res[i]);}return res;} long long safe_mod(long long x,long long m){x%=m;if(x<0){x+=m;}return x;} long long modpow(long long x,long long n,long long mod){long long ans=1;while(n>0){if(n&1){ans*=x;ans%=mod;}n>>=1;x*=x;x%=mod;}return ans;} long long intpow(long long x,long long n){long long ans=1;while(n>0){if(n&1){ans*=x;}n>>=1;x*=x;}return ans;} vector<pair<long long,long long>> factor_lst(long long n){vector<pair<long long,long long>> factor_lst;long long d=2;while(d*d<=n){if(n%d==0){long long num=0;while(n%d==0){num+=1;n/=d;}factor_lst.push_back({d,num});}d+=1;}if(n!=1){factor_lst.push_back({n,1});}return factor_lst;} #define Uniq(a) sort(all(a));a.erase(unique(all(a)),end(a)) int msb(int x){return x==0 ? -1:32-__builtin_clz(x);}//1-indexed int lsb(int x){return x==0 ? 32:__builtin_ctz(x)+1;}//1-indexed int popcnt(int x){return __builtin_popcount(x);} int popcnt(long long x){return __builtin_popcount(x);} template<typename T> void print(vector<T> &v){for(int i=0;i<v.size();++i){if(i)cout<<" ";cout<<v[i];}cout<<endl;} template<typename T> void print(T* v,int size){for(int i=0;i<size;++i){if(i)cout<<" ";cout<<v[i];}cout<<endl;} const ll LINF=4*1e18; const ll MINF=5*1e15; const int INF=2*1e9; const ld PI=acosl(-1); void Main(); int main(){cout<<fixed<<setprecision(15);Main();} void Main(){ int A,B;cin>>A>>B; vector<int> ans; if(A>=B){ int y=(A*(A+1)-B*(B+1))/2; rep(i,A)ans.push_back(i+1); rep(i,B)ans.push_back(-(i+1)); ans.back()-=y; } else{ int y=(B*(B+1)-A*(A+1))/2; rep(i,A)ans.push_back(i+1); rep(i,B)ans.push_back(-(i+1)); ans[A-1]+=y; } rep(i,A+B){ if(i)cout<<" "; cout<<ans[i]; } cout<<endl; }
#include <bits/stdc++.h> #define int long long using namespace std; int n, m; signed main() { cin >> n >> m; // for(int i = 1; i <= n; ) if(m == 0) { for(int k = 1, i = 1; i <= n; ++i, k += 2) { cout << k << ' ' << k + 1 << endl; } return 0; } if(m > 0 && m < n - 1) { int mx = 0; for(int i = n - m - 1 + 3, k = 1; k <= m + 1; ++k, i += 2) { cout << i << ' ' << i + 1 << endl; mx = i + 1; } int l = n - m - 1 + 2; for(int k = 1; k <= n - m - 1; ++k) { cout << --l << ' ' << ++mx << endl; } } else { cout << -1; } }
//#pragma GCC optimize ("O2") //#pragma GCC target ("avx2") //#include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; #include<cstdio> #include<cstring> #include<algorithm> using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please //おそそう const int CM = 1 << 17, CL = 12; char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct; const ll ma0 = 1157442765409226768; const ll ma1 = 1085102592571150095; const ll ma2 = 71777214294589695; const ll ma3 = 281470681808895; const ll ma4 = 4294967295; inline int getint() { if (ci - owa > 0) { memcpy(cn, owa, CL); ci -= CM; fread(cn + CL, 1, CM, stdin); } ll tmp = *(ll*)ci; if ((tmp & ma0) ^ ma0) { int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0); tmp = tmp << dig & ma1; tmp = tmp * 10 + (tmp >> 8) & ma2; tmp = tmp * 100 + (tmp >> 16) & ma3; tmp = tmp * 10000 + (tmp >> 32) & ma4; ci += (72 - dig >> 3); } else { tmp = tmp & ma1; tmp = tmp * 10 + (tmp >> 8) & ma2; tmp = tmp * 100 + (tmp >> 16) & ma3; tmp = tmp * 10000 + (tmp >> 32) & ma4; ci += 8; if (*ci++ == '0') { tmp = tmp * 10; ci++; } } return tmp; } void pakuri_sort(int N, ll A[]) { const int b = 8; ll tmp[100001]; rep(k, 4) { int kazu[1 << b] = {}, kazu2[1 << b] = {}; rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++; rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i]; for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i]; k++; rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++; rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i]; for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i]; } } ll li[300]; int li2[300]; int main() { //cin.tie(0); //ios::sync_with_stdio(false); int N = getint(), M = getint(); int w[8]; rep(i, N) w[i] = getint(); ll lv[100001]; rep(i, M) { ll l = getint(); int v = getint(); lv[i] = l << 32 | v; } pakuri_sort(M, lv); lv[M] = 1000000001ll; rep(i, 1 << N) { rep(j, N) if (i >> j & 1) li[i] += w[j]; li[i] = li[i] << 30 | i; } sort(li, li + (1 << N)); int saidai = 0; int k = 0; rep(i, 1 << N) { while ((lv[k] & (1 << 30) - 1) < li[i] >> 30) { if (saidai < lv[k] >> 32) saidai = lv[k] >> 32; k++; } li[i] = ll(saidai) << 30 | (li[i] & (1 << 30) - 1); } rep(i, 1 << N) li2[li[i] & (1 << 30) - 1] = li[i] >> 30; rep(i, N) { if (w[i] > (lv[0] & (1 << 30) - 1)) { printf("-1"); return 0; } } int P[8]; rep(i, N) P[i] = i; int kotae = 1e9; do { int tmp[8] = {}; rep(p, N - 1) { int omosa = 1 << P[p]; for (int q = p + 1; q < N; q++) { omosa |= 1 << P[q]; int kari = tmp[p] + li2[omosa]; if (tmp[q] < kari) tmp[q] = kari; } } if (kotae > tmp[N - 1]) kotae = tmp[N - 1]; } while (next_permutation(P, P + N)); printf("%d\n", kotae); Would you please return 0; }
#include <sys/time.h> #include <iostream> #include <iomanip> #include <algorithm> #include <utility> #include <cmath> #include <string> #include <vector> #include <set> #include <map> #include <queue> #include <stack> #include <deque> #include <utility> #include <cctype> using namespace std; using ll = long long; using i_i = pair<int, int>; #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define mkp(a, b) make_pair(a, b) const ll MOD = 1000000007; int main() { int h,w; cin >> h >> w; string s[h]; rep(i, h) { cin >> s[i]; } ll ch[h][w]; ll cv[h][w]; ll cr[h][w]; ll total = 0; rep(y, h) { rep(x, w) { ch[y][x] = 0; cv[y][x] = 0; cr[y][x] = 0; if (s[y][x] == '.') { total ++; } } } rep(y, h) { int count = 0; int start = 0; rep(x, w) { if (s[y][x] == '.') { if (count == 0) { start = x; } count++; } else { if (count == 0) continue; for (int cx = start; cx < x; cx++) { ch[y][cx] = count; } count = 0; } } if (count > 0) { for (int cx = start; cx < w; cx++) { ch[y][cx] = count; } } } rep(x, w) { int count = 0; int start = 0; rep(y, h) { if (s[y][x] == '.') { if (count == 0) { start = y; } count++; } else { if (count == 0) continue; for (int cy = start; cy < y; cy++) { cv[cy][x] = count; } count = 0; } } if (count > 0) { for (int cy = start; cy < h; cy++) { cv[cy][x] = count; } } } rep(y, h) { rep(x, w) { cr[y][x] = ch[y][x] + cv[y][x]; if (cr[y][x] > 0) cr[y][x] --; } } vector<ll> power2(2010 * 2010, 0); power2[0] = 1; rep(i,2010 * 2010) { power2[i + 1] = power2[i] * 2; power2[i + 1] %= MOD; } ll ans = 0; rep(y, h) { rep(x, w) { if (cr[y][x] == 0) continue; ll cur = (power2[cr[y][x]] - 1) * power2[total - cr[y][x]]; cur %= MOD; ans += cur; ans %= MOD; } } cout << ans << endl; return 0; }
#include "bits/stdc++.h" #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; #define ub upper_bound #define lb lower_bound #define isrt insert #define clr clear #define rsz resize #define ff first #define ss second #define lli long long int #define pb push_back #define pf push_front #define mkp make_pair #define pii pair<lli,lli> #define vi vector<int> #define mii map<lli,lli> #define pqb priority_queue<int> #define pqs priority_queue<int,vi,greater<int> > #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define INF 1e9 #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(v) v.begin(),v.end() #define endl "\n" const double PI = acos(-1); typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; lli maxm(lli a, lli b) { return (a >= b ? a : b); } lli minm(lli a, lli b) { return (a <= b ? a : b); } lli power(lli x, lli y, lli p) { lli 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; } lli nCrmodp(lli n, lli r, lli p) { if (r == 0) return 1; if (r == 1) return n; lli pro = 1, k = n; while (k > r) { pro *= k; pro %= p; --k; } k = 2; while (k <= (n - r)) { pro *= power(k, (p - 2), p); pro %= p; ++k; } return pro; } lli first_big(lli n, lli k, vector<lli> arr) { lli l, r, ans = n; l = 0; r = n - 1; while (l <= r) { lli m = l + (r - l) / 2; if (arr[m] > k) { ans = m; r = m - 1; } else l = m + 1; } return ans; } lli last_small(lli n, lli k, vector<lli> arr) { lli l, r, ans = -1; l = 0; r = n - 1; while (l <= r) { lli mid = (l + r) / 2; if (arr[mid] <= k) { ans = mid; l = mid + 1; } else r = mid - 1; } return ans; } void c_p_c() { 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 } #define MAXN 4000010 int main() { c_p_c(); lli h, w, k = 0, pro = 1, c = 0; vector<lli>pow_mod(MAXN); for (int i = 0; i < MAXN; ++i) { pow_mod[i] = pro; pro *= 2; pro %= mod; } cin >> h >> w; string str; char v[h][w]; lli arr[h][w]; memset(arr, 0, sizeof(arr)); for (int i = 0; i < h; ++i) { cin >> str; for (int j = 0; j < w; ++j) { v[i][j] = str[j]; if (str[j] == '.') ++k; } } for (lli i = 0; i < h; ++i) { for (lli j = 0; j < w; ++j) { if (v[i][j] == '.') ++c; else { if (c != 0) for (int p = j - c; p < j; ++p) arr[i][p] += c; c = 0; } } if (c != 0) for (int p = w - c; p < w; ++p) arr[i][p] += c; c = 0; } for (lli i = 0; i < w; ++i) { for (lli j = 0; j < h; ++j) { if (v[j][i] == '.') ++c; else { if (c != 0) for (int p = j - c; p < j; ++p) arr[p][i] += (c - 1); c = 0; } } if (c != 0) for (int p = h - c; p < h; ++p) arr[p][i] += (c - 1); c = 0; } lli ans = pow_mod[k]; ans *= k; ans %= mod; for (int i = 0; i < h; ++i) for (int j = 0; j < w; ++j) if (arr[i][j] != 0) { ans -= pow_mod[k - arr[i][j]]; ans = (ans + mod) % mod; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; #define FOR(i, n) for(int (i)=0; (i)<(n); (i)++) #define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++) #define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--) template<class T, class U> void umin(T& x, const U& y){ x = min(x, (T)y);} template<class T, class U> void umax(T& x, const U& y){ x = max(x, (T)y);} template<class T, class U> void init(vector<T> &v, U x, size_t n) { v=vector<T>(n, (T)x); } template<class T, class U, typename... W> void init(vector<T> &v, U x, size_t n, W... m) { v=vector<T>(n); for(auto& a : v) init(a, x, m...); } int n, q; vector<map<int, int>> H; vector<int> p; int par(int x){ if (p[x] == x) return x; return p[x] = par(p[x]); } void merge(int x, int y){ int px = par(x); int py = par(y); if (px == py) return; if (H[px].size() < H[py].size()) swap(px, py); p[py] = px; for(auto it : H[py]) H[px][it.first] += it.second; } int get(int x, int ci){ int px = par(x); return H[px][ci]; } int main(int argc, char** argv) { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << fixed << setprecision(15); if (argc == 2 && atoi(argv[1]) == 123456789) freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin); cin >> n >> q; p.resize(n+1); H.resize(n+1); FOR(i, n){ int ci; cin >> ci; H[i+1][ci]++; p[i+1] = i+1; } FOR(i, q){ int t, x, y; cin >> t >> x >> y; if (t == 1) merge(x, y); else cout << get(x, y) << '\n'; } if (argc == 2 && atoi(argv[1]) == 123456789) cout << clock()*1.0/CLOCKS_PER_SEC << " sec\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define FOR(i, a) for(int i = 0; i < (int) a; i++) #define PB push_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define F first #define S second typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; int ans = 1e9+7; FOR(i, n){ int a, b, c; cin >> a >> b >> c; if(c > a) ans = min(ans, b); } if(ans == 1e9+7) cout << "-1\n"; else cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> #define REP(i, s, n) for (int i = s; i < (int)(n); i++) #define ALL(a) a.begin(), a.end() #define MOD 1000000007 using namespace std; using ll = long long; int main() { int x, y, z; cin >> x >> y >> z; cout << (y * z + x - 1) / x - 1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i,srt,end) for(ll i = (srt); i < (ll)(end); i++) //ll MOD=1000000007; //ll mod=998244353; //int inf=1000001000; //ll INF=1e18+5; //cout << std::fixed << std::setprecision(15) << y << endl; // For debug // Ref: https://qiita.com/ysuzuki19/items/d89057d65284ba1a16ac #define dump(var) do{std::cerr << #var << " : ";view(var);}while(0) template<typename T> void view(T e){std::cerr << e << "\n";} template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cerr << e << " "; } std::cerr << "\n";} template<typename T> void view(const std::vector<std::vector<T> >& vv){ std::cerr << "\n"; for(const auto& v : vv){ view(v); } } template<typename T> void dump_cout(const T& v) { for(long long i = 0; i < v.size(); i++) std::cout << v[i] << (i == v.size()-1 ? "\n" : " "); } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); ll x, y, z; cin >> x >> y >> z; ll ans = 0; rep(i,0,10000000){ if(z*y > x*i) ans = max(ans, i); } cout << ans << endl; return 0; }
// #pragma GCC optimize("Ofast,unroll-loops") // #pragma GCC target("avx,avx2,fma") #include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define dd double #define ld long double #define sl(n) scanf("%lld", &n) #define si(n) scanf("%d", &n) #define sd(n) scanf("%lf", &n) #define pll pair <ll, ll> #define pii pair <int, int> #define mp make_pair #define pb push_back #define all(v) v.begin(), v.end() #define inf (1LL << 61) #define loop(i, start, stop, inc) for(ll i = start; i <= stop; i += inc) #define for1(i, stop) for(ll i = 1; i <= stop; ++i) #define for0(i, stop) for(ll i = 0; i < stop; ++i) #define rep1(i, start) for(ll i = start; i >= 1; --i) #define rep0(i, start) for(ll i = (start-1); i >= 0; --i) #define ms(n, i) memset(n, i, sizeof(n)) #define casep(n) printf("Case %lld:", ++n) #define pn printf("\n") #define pf printf #define EL '\n' #define fastio std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); vector <ll> dv; int main() { ll n; cin >> n; for(ll i = 1; i * i <= n; i++) { if(n % i != 0) continue; dv.pb(i); if(n/i != i) dv.pb(n/i); } sort(all(dv)); for(ll &d : dv) pf("%lld\n", d); return 0; }
#include <iostream> #include <fstream> #include <vector> #include <algorithm> #include <stack> #include <cassert> #include <map> #include <numeric> #include <cstring> #include <set> #include <ctime> #include <queue> #include <cmath> #include <iomanip> #include <iterator> using namespace std; class InputReader { public: InputReader() {} InputReader(const char *file_name) { input_file = fopen(file_name, "r"); cursor = 0; fread(buffer, SIZE, 1, input_file); } inline InputReader &operator >>(int &n) { while((buffer[cursor] < '0' || buffer[cursor] > '9') && buffer[cursor] != '-') { advance(); } int sign = 1; if (buffer[cursor] == '-') { sign = -1; advance(); } n = 0; while('0' <= buffer[cursor] && buffer[cursor] <= '9') { n = n * 10 + buffer[cursor] - '0'; advance(); } n *= sign; return *this; } private: FILE *input_file; static const int SIZE = 1 << 17; int cursor; char buffer[SIZE]; inline void advance() { ++ cursor; if(cursor == SIZE) { cursor = 0; fread(buffer, SIZE, 1, input_file); } } }; long long cmmdc(long long a, long long b) { while (b) { long long r = a % b; a = b; b = r; } return a; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); //ifstream cin("input.txt"); int n; cin >> n; long long answer = 1; for (long long i = 2; i <= n; i++) { answer = answer * i / cmmdc(answer, i); } cout << answer + 1 << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define all(v) v.begin(), v.end() #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define repr(i, n) for (ll i = (n-1); i >= 0; i--) #define Rep(n) for (ll _ = 0; _ < (ll)(n); _++) template <class S>S sum(vector<S>& a) {return accumulate(all(a), S());} template <class S>S max(vector<S>& a) {return *max_element(all(a));} template <class S>S min(vector<S>& a) {return *min_element(all(a));} ll max(int a, ll b) { return max((ll)a, b); } ll max(ll a, int b) { return max(a, (ll)b); } ll min(int a, ll b) { return min((ll)a, b); } ll min(ll a, int b) { return min(a, (ll)b); } void Main(); int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(20); Main(); return 0; } void Main(){ int k; cin >> k; ll ans = 0; for(int a=1; a <= k; a++){ for(int b = 1; b <= k; b++){ if(a * b > k){ break; } ans += (ll)k / (a * b); } } cout << ans << endl; }
/* 少加头文件,爆零两行泪 DP后效性,爆零两行泪 文件读入错,爆零两行泪 文件名写错,爆零两行泪 调完不编译,爆零两行泪 结论不证明,爆零两行泪 数组没开够,爆零两行泪 ll开 int,爆零两行泪 dp 没初值,爆零两行泪 深搜没边界,爆零两行泪 广搜忘出队,爆零两行泪 模数没看清,爆零两行泪 越界不特判,爆零两行泪 多测不清空,爆零两行泪 空间胡乱开,爆零两行泪 无向变有向,爆零两行泪 调试忘删除,爆零两行泪 文件不保存,爆零两行泪 题目提交错,爆零两行泪 */ #pragma GCC optimize("Ofast") #include<bits/stdc++.h> #define ll long long #define gmax(x,y) x=max(x,y) #define gmin(x,y) x=min(x,y) #define F first #define S second #define P pair #define FOR(i,a,b) for(int i=a;i<=b;i++) #define rep(i,a,b) for(int i=a;i<b;i++) #define V vector #define RE return #define ALL(a) a.begin(),a.end() #define MP make_pair #define PB emplace_back #define PF emplace_front #define FILL(a,b) memset(a,b,sizeof(a)) #define lwb lower_bound #define upb upper_bound using namespace std; P<int,int> p[20000005]; int a[2005],cnt; signed main(){ ios::sync_with_stdio(0); cin.tie(0); int n,mini=1e9; cin>>n; FOR(i,1,n){ cin>>a[i]; gmin(mini,a[i]); for(int j=1;j*j<=a[i];j++){ if(a[i]%j==0){ p[++cnt]=MP(j,i); if(j*j!=a[i])p[++cnt]=MP(a[i]/j,i); } } } sort(p+1,p+cnt+1); int GCD=a[p[1].S],ans=0; FOR(i,2,cnt){ if(p[i].F!=p[i-1].F){ // cout<<p[i-1].F<<' '<<GCD<<'\n'; if(GCD==p[i-1].F)ans++; GCD=a[p[i].S]; }else{ GCD=__gcd(GCD,a[p[i].S]); } if(p[i].F>mini)break; } if(GCD<=mini&&GCD==p[cnt].F)ans++; cout<<ans; RE 0; }
#include <iostream> #include <sstream> #include <string> #include <list> #include <vector> #include <queue> #include <algorithm> #include <climits> #include <cstring> #include <cmath> #include <stack> #include <iomanip> #include <tuple> #include <functional> #include <cfloat> #include <map> #include <set> #include <array> #include <stdio.h> #include <string.h> #include <random> #include <cassert> using ll = long long; using ull = unsigned long long; using uint = unsigned int; using namespace std; #define int long long #define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end()) #define SORT(v) sort((v).begin(), (v).end()) #define RSORT(v) sort((v).rbegin(), (v).rend()) #define ARY_SORT(a, size) sort((a), (a)+(size)) #define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end())) #define REVERSE(v) (reverse((v).begin(), (v).end())) #define ARY_REVERSE(v,a) (reverse((v), (v)+(a))) #define REP(i, n) for (int (i)=0; (i) < (n); (i)++) #define REPE(i, n) for (int (i)=0; (i) <= (n); (i)++) #define CONTAINS_MAP(m, a) ((m).find((a)) != m.end()) #define CONTAINS_SET(m, a) ((m).find((a)) != m.end()) void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; exit(0); } void Yes() { cout << "Yes" << endl; exit(0); } void No() { cout << "No" << endl; exit(0); } int K; int S[10]; int T[10]; signed main() { cin >> K; string s; string t; cin >> s; cin >> t; for (int i = 0; i < 4; i++) { S[s[i] - '0']++; T[t[i] - '0']++; } int all = (K * 9 - 8) * (K * 9 - 9); int sum = 0; for (int i = 1; i <= 9; i++) { for (int j = 1; j <= 9; j++) { S[i]++; T[j]++; int score_i = 0; int score_j = 0; for (int k = 1; k <= 9; k++) { int ss = 1; for (int l = 0; l < S[k]; l++) { ss *= 10; } int tt = 1; for (int l = 0; l < T[k]; l++) { tt *= 10; } score_i += k * ss; score_j += k * tt; } S[i]--; T[j]--; if (score_i > score_j) { if (i == j) { int rest = K - (S[i] + T[i]); int pat = rest * (rest - 1); sum += pat; } else { int rest_i = K - (S[i] + T[i]); int rest_j = K - (S[j] + T[j]); sum += rest_i * rest_j; } } } } cout << fixed << setprecision(10); cout << (sum / (double)all) << endl; //cout << sum << "/" << all << endl; }
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define eb emplace_back #define mp make_pair #define lb lower_bound #define ub upper_bound #define ins insert #define ull unsigned long long #define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) #define ff first #define ss second #define fly ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0); #define nl "\n" #define sz(a) (int)(a).size() #define all(a) (a).begin(),(a).end() #define fl(a,x) memset(a,x,sizeof(a)); #define pt(a,x) cout << get<x>(a) << " " ; #define mt make_tuple #define vec vector #define ld long double #define eps 1e-9 #define int long long const int mod = (int) 1e9 + 7 ; const int MOD = (int) 998244353 ; const int INF = (int) 1e18 ; typedef vector<int> vii; typedef pair<int,int> pii; typedef vector<pii> vpi; typedef vector<vector<int> > vv; #define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); } void err(istream_iterator<string> it) {} template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; err(++it, args...); } void solve() { int n; cin >> n ; int x[n], y[n]; rep(i,0,n) cin >> x[i] >> y[i] ; int ans = 0 ; for(int i = 0 ; i < n ; ++i) { for(int j = i+1 ; j < n ; ++j) { ld slope = (ld)(y[j]-y[i])/(ld)(x[j]-x[i]) ; if(slope >= -1 and slope <= 1) ++ans ; } } cout << ans ; } int32_t main() { #ifdef LOCAL freopen("error.txt", "w", stderr); #endif fly; // int t; cin >> t; while(t--) solve() ; // cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; return 0; }
#include<bits/stdc++.h> using namespace std; int n,m; int main(){ cin>>n>>m; cout<<n*(1+m)*m/2+m*(1+n)*n/2*100; }
#include <iostream> using namespace std; typedef long long int ll; int main(void){ ll n, k; cin >> n >> k; ll ans = 0; for (int i=0; i<n; i++) { for (int j=0; j<k; j++) { ans += 100*(i+1) + j+1; } } cout << ans << endl; return 0; }
#include<algorithm> #include<iostream> #include<vector> #include<string> #include<queue> #define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i) #define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i) #define all(x) (x).begin(), (x).end() using namespace std; using ll = long long; template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;} template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;} using P = pair<ll, ll>; int main() { cin.tie(0); ios::sync_with_stdio(false); int N; ll K; cin >> N >> K; vector<ll> A(N); for (auto& a : A) { cin >> a; } vector<ll> cnt(N + 1, 0); for (auto& a : A) { ++cnt[a]; } priority_queue<P, vector<P>, greater<P>> que; rep(i, 0, N + 1) { que.emplace(cnt[i], i); } ll now_cnt = 0; ll max_a = N + 1; ll ans = 0; while (K) { while (!que.empty() && max_a < que.top().second) { que.pop(); } if (que.empty()) { break; } P now = que.top(); que.pop(); ll diff = min(max(now.first - now_cnt, 0LL), K); ans += max_a * diff; now_cnt += diff; max_a = now.second; K -= diff; } cout << ans << endl; return 0; }
#include "bits/stdc++.h" using namespace std; #define ll long long const int inf = 1e3+10; const int row[]={1,-1,0,0},col[]={0,0,1,-1}; int main() { int h,w; cin>>h>>w; string ab[h]; int st=0,st1=0,gi,gj; vector <pair<int,int> > v[26]; int alphavis[26]; memset(alphavis,0,sizeof(alphavis)); for (int i = 0; i < h; ++i) { cin>>ab[i]; for (int j= 0; j<w ; ++j) { if(ab[i][j]=='S') { st=i,st1=j; } else if(ab[i][j]=='G') { gi=i; gj=j; } else if(ab[i][j]>='a'&&ab[i][j]<='z') { v[ab[i][j]-'a'].push_back({i,j}); } } } queue<pair<int,int> >q; q.push({st,st1}); int visit[h][w]; memset(visit,-1,sizeof(visit)); visit[st][st1]=0; while(!q.empty()) { auto it=q.front(); int r=it.first; int c=it.second; q.pop(); for(int i=0;i<4;i++) { int rr=r+row[i],cc=c+col[i]; if(rr>=0&&rr<h&&cc>=0&&cc<w&&ab[rr][cc]!='#') { if(visit[r][c]+1<visit[rr][cc]||visit[rr][cc]==-1) { if(ab[rr][cc]>='a'&&ab[rr][cc]<='z') { int sized=v[ab[rr][cc]-'a'].size(); if(alphavis[ab[rr][cc]-'a']==0){ for(int k=0;k<sized;k++) { int x=ab[rr][cc]-'a'; if(v[x][k].first==rr&&v[x][k].second==cc) visit[v[x][k].first][v[x][k].second]=visit[r][c]+1; else visit[v[x][k].first][v[x][k].second]=visit[r][c]+2; q.push({v[x][k].first,v[x][k].second}); } alphavis[ab[rr][cc]-'a']=1; } else visit[rr][cc]=visit[r][c]+1; } else { visit[rr][cc]=visit[r][c]+1; q.push({rr,cc}); } } } } } cout<<visit[gi][gj]<<endl; return 0; }
#include <bits/stdc++.h> #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define rep(i,n) for(int i=0;i<(int)(n);i++) #define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++) #define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++) #define codefor int test;scanf("%d",&test);while(test--) #define INT(...) int __VA_ARGS__;in(__VA_ARGS__) #define LL(...) ll __VA_ARGS__;in(__VA_ARGS__) #define yes(ans) if(ans)printf("yes\n");else printf("no\n") #define Yes(ans) if(ans)printf("Yes\n");else printf("No\n") #define YES(ans) if(ans)printf("YES\n");else printf("NO\n") #define popcount(v) __builtin_popcount(v) #define vector1d(type,name,...) vector<type>name(__VA_ARGS__) #define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__)) #define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__))) #define umap unordered_map #define uset unordered_set using namespace std; using ll = long long; const int MOD=1000000007; const int MOD2=998244353; const int INF=1<<30; const ll INF2=(ll)1<<60; //入力系 void scan(int& a){scanf("%d",&a);} void scan(long long& a){scanf("%lld",&a);} template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);} template<class T> void scan(T& a){cin>>a;} template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);} void in(){} template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);} //出力系 void print(const int& a){printf("%d",a);} void print(const long long& a){printf("%lld",a);} void print(const double& a){printf("%.15lf",a);} template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);} template<class T> void print(const T& a){cout<<a;} template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}} void out(){putchar('\n');} template<class T> void out(const T& t){print(t);putchar('\n');} template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);} //デバッグ系 template<class T> void dprint(const T& a){cerr<<a;} template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}} void debug(){cerr<<endl;} template<class T> void debug(const T& t){dprint(t);cerr<<endl;} template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);} ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; } ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; } ll modinv(ll a, ll m) {ll b = m, u = 1, v = 0;while (b) {ll t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;} ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;} template<class T> void chmax(T &a,const T b){if(b>a)a=b;} template<class T> void chmin(T &a,const T b){if(b<a)a=b;} int main(){ LL(n,k); vector2d(ll,a,n,2); in(a); sort(all(a)); ll now=0,ans=0; for(int i=0;i<n;i++){ if((a[i][0]-now)<=k){ k-=a[i][0]-now; k+=a[i][1]; now=a[i][0]; }else{ out(now+k); return 0; } } out(now+k); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main(){ int N; cin >> N; double x0,y0,xN2,yN2; cin >> x0 >> y0; cin >> xN2 >> yN2; // 中心座標を求める double xc = (x0 + xN2) / 2.0; double yc = (y0 + yN2) / 2.0; // 回転させる必要がある角度は360/N度 double degree = 360.0 / N; double theta = degree * M_PI / 180.0; // xc,ycを中心にthetaラジアン回転させる double x1 = (x0 - xc) * cos(theta) - (y0 - yc) * sin(theta) + xc; double y1 = (x0 - xc) * sin(theta) + (y0 - yc) * cos(theta) + yc; cout << fixed << setprecision(8) << x1 << ' ' << y1 << endl; }
#include<bits/stdc++.h> using namespace std; int main() { int a,b,x,y; cin>>a>>b>>x>>y; if (a<=b) cout<<(b-a)*min(y,2*x)+x; else cout<<(a-b-1)*min(y,2*x)+x; return 0; }
#include <stdio.h> #include <math.h> #define PI 3.1415926535 int main() { int a; scanf("%d",&a); int x1,y1,x2,y2; scanf("%d%d%d%d",&x1,&y1,&x2,&y2); double xr = (double)(x1+x2)/2; double yr = (double)(y1+y2)/2; double xvec = x1 - xr; double yvec = y1 - yr; double xvec2 = cos(2*PI/a) * xvec - sin(2*PI/a) * yvec; double yvec2 = sin(2*PI/a) * xvec + cos(2*PI/a) * yvec; printf("%.12lf %.12lf",xvec2 + xr, yvec2 + yr); }
// author: Halit #include <bits/stdc++.h> int main() { int n; std::cin >> n; std::vector<int> a(n); for (int& el : a) { std::cin >> el; } constexpr double eps = 0.0000001; auto check = [&](double x) { long double compute = 0; for (int a_i : a) { compute += x + a_i - std::min(double(a_i), 2*x); } return compute / n; }; double l = 0, r = 1e9+7; for (int i = 1;i <= 100; ++i) { double point_1 = (r-l)/3 + l; double point_2 = (r-l)/3 * 2 + l; if (check(point_2)-check(point_1) > eps) r = point_2; else l = point_1; } double ans = l; std::cout << std::fixed << std::setprecision(7) << check(ans); }
#include<cstdio> #include<cstring> #include<algorithm> #include<map> #include<math.h> #include<iostream> #include<cmath> #include<queue> #include<vector> #define IOS ios::sync_with_stdio(false);cin.tie();cout.tie(0) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pll; const int N=1e5+10; const int mod=1e9+7; double a[N],s[N]; int main() { IOS; int n; cin>>n; double n1=n*1.0; for(int i=1;i<=n;i++) { cin>>a[i]; } sort(a+1,a+n+1); for(int i=1;i<=n;i++) s[i]=s[i-1]+a[i]; double sum=1e18; for(int i=1;i<=n;i++) { double w=a[i]/2; double w1=(s[n]-s[i])-(n-i-i)*w; sum=min(sum,w1); //cout<<sum/n1<<endl; } printf("%.6lf",sum/n1); return 0; }
#include<bits/stdc++.h> using namespace std; void leftrotate(string &s, int d) { reverse(s.begin(), s.begin()+d); reverse(s.begin()+d, s.end()); reverse(s.begin(), s.end()); } int main(){ string s; cin>>s; leftrotate(s, 1); cout << s << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin>>n; ++n; // long long a=109109109109109109; // long long b=109109108641970782; // long long c=467138327; // long double x=sqrt(1+8*n); // long long d=(x+1.0)/2.0; // cout<<n-d+1; long long i=1; while(i*(i+1)/2<=n){ ++i; } cout<<n-i+1; }
#include <bits/stdc++.h> #include <unordered_map> #include <unordered_set> #define pb push_back #define mpr make_pair #define pii pair<int, int> #define ll long long #define dl long double #define all(arr) arr.begin(), arr.end() #define fi first #define se second #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define pie 3.14159265358979323846264338327950L #define mid(l, r) l + (r - l) / 2 #define memo(arr) memset(arr, 0,sizeof(arr)); #define mem1(arr) memset(arr,-1,sizeof(arr)); #define vec vector<int> #define yes cout << "YES" << endl; #define no cout << "NO" << endl; #define endl "\n" #define int long long #define sz(x) (int)x.size() #define template_array_size (int)1e6 + 6 #define INF (int)1e18 #define trace1(x) cerr << #x << ": " << x << endl; #define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl; #define trace3(x, y, z) cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl; #define trace4(a, b, c, d) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl; #define trace5(a, b, c, d, e) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl; #define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl; #define trace7(arr) for(auto it : arr) cerr<<it<<" "; cout<<endl; using namespace std; int gcd(int a,int b){ if(!a)return b;return gcd(b%a,a);} int lcm(int a, int b) { return (a*b)/ gcd(a,b);} const int N = 3e5; const int mod = 1e9 + 7; void sout(){ cout<<endl; } template <typename T,typename... Types> void sout(T var1,Types... var2){ cout<<var1<<" "; sout(var2...); } template<typename T> void sout(vector<T> arr) { for(auto it : arr) { cout<<it<<" "; } sout(); } //____________________________________________ void test_case () { int n; cin>>n; vector<int> arr(n); for(auto &it : arr) { cin>>it; } sort(all(arr)); int ans = 0; int sum = 0; for(int i=0; i<n; i++) { ans+= (i * arr[i]) - sum; sum+= arr[i]; } cout<<ans; } int32_t main () { ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cout << fixed << setprecision(10); #ifndef ONLINE_JUDGE // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); #endif int t = 1; // cin >> t; while (t--) { test_case(); } cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; } /* stuff you should look for * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * WRITE STUFF DOWN * DON'T GET STUCK ON ONE APPROACH */ /* run in terminal g++ -std=c++14 -o a actionKamen.cpp && ./a */
#include<bits/stdc++.h> using namespace std; #define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define MOD 1000000007 #define MOD1 998244353 #define INF 1e18 #define nline "\n" //#define pb push_back //#define ppb pop_back //#define mp make_pair //#define ff first //#define ss second #define PI 3.141592653589793238462 //#define set_bits __builtin_popcountll //#define sz(x) ((int)(x).size()) //#define all(x) (x).begin(), (x).end() typedef long long ll; typedef unsigned long long ull; typedef long double lld; // typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update > pbds; // find_by_order, order_of_key #ifndef ONLINE_JUDGE #define debug(x) cerr << #x <<" "; _print(x); cerr << endl; #else #define debug(x) #endif void _print(ll t) {cerr << t;} void _print(int t) {cerr << t;} void _print(string t) {cerr << t;} void _print(char t) {cerr << t;} void _print(lld 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.first); cerr << ","; _print(p.second); 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 << "]";} bool isValid(ll arr[], ll n, ll q, ll total){ ll count=0; ll time=0; for(ll i=0;i<n;i++){ ll j=1; time=0; while(1){ time+=j*arr[i]; j++; if(time>total) break; count++; } } return count>=q; } int main(){ #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("Error.txt","w",stderr); freopen("output.txt","w",stdout); #endif fastio(); int t; t=1; while(t--){ ll a,b,c; cin>>a>>b>>c; cout<<21-(a+b+c); } }
#include <bits/stdc++.h> #define lg long long int #define loop(i, s, e) for (lg i = s; i <= e; i++) #define iloop(i, s, e) for (lg i = e; i >= s; i--) #define pb push_back #define mp make_pair #define mod 1000000007 using namespace std; lg min(lg a, lg b) { return a < b ? a : b; } lg max(lg a, lg b) { return a > b ? a : b; } lg lcm(lg a, lg b) { return (a * b) / __gcd(a, b); } lg ans = 0; lg n, a,b; lg bin_Search(vector<lg>& nums, lg low,lg high,lg num){ if(nums[low]>=num) return low; else if(nums[high]<=num) return high+1; else if(high-low<2) return high; else { lg mid = (low+high)/2; if(nums[mid]>num) return bin_Search(nums,low,mid,num); else if(nums[mid]<num) return bin_Search(nums,mid,high,num); else return mid; } } int main() { cin>>n>>a>>b; cout<<n-a+b<<endl; }
#include "bits/stdc++.h" using namespace std; #define int long long #define pb push_back #define ppb pop_back #define pf push_front #define ppf pop_front #define all(x) (x).begin(),(x).end() #define uniq(v) (v).erase(unique(all(v)),(v).end()) #define sz(x) (int)((x).size()) #define fr first #define sc second #define pii pair<int,int> #define rep(i,a,b) for(int i=a;i<b;i++) #define mem1(a) memset(a,-1,sizeof(a)) #define mem0(a) memset(a,0,sizeof(a)) #define ppc __builtin_popcount #define ppcll __builtin_popcountll template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.fr>>a.sc;return in;} template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.fr<<" "<<a.sc;return out;} template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;} template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;} const long long INF=1e18; const int32_t M=1e9+7; const int32_t MM=998244353; const int N=25; int ans = 1; vector<int> v[N]; int vis[N]; int col[N]; int lvl[N]; int dfs(int z){ int ret = 1; vis[z] = 1; for(int x:v[z]){ if(vis[x] != 0 && lvl[x] != lvl[z] + 1){ if(col[x] == col[z]){ ret = 0; } continue; } lvl[x] = lvl[z] + 1; int tmp = 0; rep(i,1,4){ if(i == col[z]) continue; col[x] = i; tmp += dfs(x); col[x] = 0; } ret *= tmp; } return ret; } void solve(){ int n,m; cin >> n >> m; rep(i,0,m){ int a,b; cin >> a >> b; v[a].pb(b); v[b].pb(a); } rep(i,1,n+1){ if(vis[i]) continue; col[i] = 1; lvl[i] = 1; ans *= 3 * dfs(i); } cout << ans; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0); //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); #ifdef SIEVE sieve(); #endif #ifdef NCR init(); #endif int t=1; //cin>>t; while(t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; const int md = 998244353; int n, m, i, j, r; char s[505][505], c[1010]; void solve() { scanf("%d%d", &n, &m); for (i = 0; i < n; i++) { scanf("%s", s[i]); for (j = 0; j < m; j++) if (s[i][j] != '.') { if (c[i + j] != 0 && c[i + j] != s[i][j]) { puts("0"); return ;} c[i + j] = s[i][j]; } } for (r = 1, i = 0; i <= n + m - 2; i++) if (c[i] == 0) r = (r * 2) % md; printf("%d\n", r); } int main() { ios::sync_with_stdio(false), cin.tie(nullptr); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const int mxn = 500+10; const int mod = 998244353; ll powmod(ll a, ll b) { ll ret = 1; while(b) { if(b&1ll) ret*=a, ret%=mod; a*=a; a%=mod; b>>=1; } return ret; } map<char, int> diag[2*mxn]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m; cin>>n>>m; for(int i=0; i<n; i++) for(int j=0; j<m; j++) { char c; cin>>c; diag[i+j][c]++; } ll ans = 1; for(int i=0; i<n+m-1; i++) { if(diag[i].count('R') and diag[i].count('B')) { ans = 0; break; } if(diag[i].count('R') or diag[i].count('B')) continue; ans*=2; ans%=mod; } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N; string T; cin >> N >> T; auto solve = [&]() -> long long { long long V = 10000000000LL; if (T == "0") return V; else if (T == "1") return V * 2; if (T.size() >= 1 && T.substr(0, 1) == "0") T = T.substr(1), --V; else if (T.size() >= 2 && T.substr(0, 2) == "10") T = T.substr(2), --V; if (T.size() % 3 == 1) { if (T.substr(T.size()-1) != "1") return 0; T = T.substr(0, T.size()-1); --V; } else if (T.size() % 3 == 2) { if (T.substr(T.size()-2) != "11") return 0; T = T.substr(0, T.size()-2); --V; } for (int i = 0; i < T.size(); i += 3) if (T.substr(i, 3) != "110") return 0; return V - T.size()/3 + 1; }; cout << solve() << endl; }
#include<cstdio> int main(){ unsigned N; scanf("%u\n", &N); bool T[N]; char tmp; for (unsigned i = 0; i < N; i++){ scanf("%c", &tmp); T[i] = tmp == '1'; } unsigned long long answer = 0; bool flag = true; for (unsigned i = 0; i < N; i++){ if(T[i] ^ (i%3 != 2)){ flag = false; break; } } if(flag) answer += 10000000000 - (N-1)/3; flag = true; for (unsigned i = 0; i < N; i++){ if(T[i] ^ (i%3 != 1)){ flag = false; break; } } if(flag) answer += 10000000000 - N/3; flag = true; for (unsigned i = 0; i < N; i++){ if(T[i] ^ (i%3 != 0)){ flag = false; break; } } if(flag) answer += 10000000000 - (N+1)/3; printf("%llu\n", answer); return 0; }
#include<bits/stdc++.h> using namespace std; #define ff first #define ss second #define ll long long #define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) ll M=1e9+7; void cal(vector<ll>&v){ v[0]=1; ll b=2; for(ll i=1;i<=4000000;i++){ v[i]=b*v[i-1]; v[i]%=M; } return ; } int main(){ io; ll n,m; cin>>n>>m; string s[n]; for(ll i=0;i<n;i++)cin>>s[i]; ll tot=0; vector<vector<ll> >left(n,vector<ll>(m,0)),right(n,vector<ll>(m,0)),up(n,vector<ll>(m,0)),down(n,vector<ll>(m,0)); for(ll i=0;i<n;i++){ for(ll j=0;j<m;j++){ if(s[i][j]=='.')tot++; if(s[i][j]=='#')continue; if(j-1>=0)left[i][j]=1+left[i][j-1]; else left[i][j]=1; if(i-1>=0)up[i][j]=1+up[i-1][j]; else up[i][j]=1; } } for(ll i=n-1;i>=0;i--){ for(ll j=m-1;j>=0;j--){ if(s[i][j]=='#')continue; if(j+1<m)right[i][j]=1+right[i][j+1]; else right[i][j]=1; if(i+1<n)down[i][j]=1+down[i+1][j]; else down[i][j]=1; } } vector<ll>v(4000004); cal(v); ll ans=0; for(ll i=0;i<n;i++){ for(ll j=0;j<m;j++){ if(s[i][j]=='#')continue; ll ilum=left[i][j]+right[i][j]+up[i][j]+down[i][j]-3; ll val=(v[ilum]-(ll)1); ll rem=tot-ilum; val*=(v[rem]); // cout<<ilum<<" "<<rem<<" "<<tot<<endl; val%=M; ans+=val; ans%=M; } } cout<<ans<<endl; return 0; }
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,a,b) for(int i=a;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; } //--------------------------------------------------------------------------------------------------- vector<int> makePrimes(int n) { // [2,n] vector<int> res, pr(n + 1, 1); pr[0] = pr[1] = 0; rep(p, 2, sqrt(n) + 2) if (pr[p]) for (int x = p * 2; x <= n; x += p) pr[x] = 0; rep(p, 2, n + 1) if (pr[p]) res.push_back(p); return res; } /*---------------------------------------------------------------------------------------------------             ∧_∧       ∧_∧  (´<_` )  Welcome to My Coding Space!      ( ´_ゝ`) /  ⌒i @hamayanhamayan0     /   \    | |     /   / ̄ ̄ ̄ ̄/  |   __(__ニつ/  _/ .| .|____      \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ ll A, B; ll dp[74][1 << 20]; int msk[73]; //--------------------------------------------------------------------------------------------------- void _main() { cin >> A >> B; auto ep = makePrimes(72); // cout << ep.size() << endl; == 20 for (ll x = A; x <= B; x++) rep(i, 0, 20) if (x % ep[i] == 0) msk[x - A] |= 1 << i; dp[0][0] = 1; for (ll x = A; x <= B; x++) rep(lcm, 0, 1 << 20) { if ((lcm & msk[x - A]) == 0) dp[x - A + 1][lcm | msk[x - A]] += dp[x - A][lcm]; dp[x - A + 1][lcm] += dp[x - A][lcm]; } ll ans = 0; rep(lcm, 0, 1 << 20) ans += dp[B - A + 1][lcm]; cout << ans << endl; }
#include <iostream> #include <vector> #include <map> #include <unordered_map> #include <set> #include <unordered_set> #include <cmath> #include <algorithm> #include <climits> #include <iomanip> #define endl "\n" #define debug(x) cout << #x << " : " << x << endl; #define debug2(x, y) cout << #x << " : " << x << ", " << #y << " : " << y << endl; #define FASTIO ios_base::sync_with_stdio(false),cin.tie(0); typedef long long ll; using namespace std; int main() { FASTIO int n; cin >> n; map <string, bool> mp; map <string, bool> mp_r; for(int i = 0; i < n; i ++) { string s; cin >> s; if(s[0] == '!') { s.erase(0, 1); mp_r[s] = true; } else mp[s] = true; if(mp[s] == true && mp_r[s] == true) { cout << s << endl; return 0; } } cout << "satisfiable" << endl; }
/* CODE TEMPLATE APRATIM */ #include <bits/stdc++.h> #pragma optimize("O3") using namespace std; #define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define ll long long int #define veci vector<ll> #define it map<string, vv>::iterator #define MOD 1000000007 #define N (ll)3e+5 #define test int T;cin>>T;while(T--) #define nl "\n" #define FULL(iii) iii.begin(),iii.end() #define setbit(_) __builtin_popcount(_) #define INF 9223372036854775807 #define TOUPR(str) transform(str.begin(), str.end(),str.begin(), ::toupper) #define TOLWR(str) transform(str.begin(), str.end(),str.begin(), ::tolower) #define pb push_back #define len(s) s.length() #define pb push_back #define eb emplace_back #define S second #define F first #define len(s) s.length() #define coutp cout<<setprecision(15) #define pow(a,b) (ll)(pow(a,b)+0.5) #define bin(x) stoull(x,0,2) #define lld long double #define yy cout<<"Yes"<<nl; #define nn cout<<"No"<<nl; map<ll,ll> mapy; veci mapv; class Graph { private: map<ll,veci>m; public: void edges(ll source, ll destination) { m[source].pb(destination); m[destination].pb(source); } vector<ll> BFS(ll s) { queue<ll> q; map<ll,ll>vis; veci x; vis[s]=1; q.push(s); while(!q.empty()) { s=q.front();x.pb(s); q.pop(); for(auto node:m[s]) { if(!vis[node]) vis[node]=1,q.push(node); } } return x; } }; ll powi(ll a,ll b) { if(b==0) return (ll)1; if(b==1) return a; else if(b%2) return a*powi(a,b-1); else return powi(a*a,b/2); } ll b(vector<ll>a,ll n) { ll l=0,r=n-1; while(l<=r) { int m = r-(r-l)/2; if(a[m]==0) l = m+1; else{ if(a[m-1]==0 || m==0) return m; else r = m-1; } } return -1; } bool prime(ll n) { ll i; if(n==0 || n==1) return 0; for(i=2;i*i<=n;i++) { if(n%i==0) return 0; } return 1; } ll nearest_prime(ll n) { ll i; for(i=n+1;;i++) { if(prime(i)){ if(!prime(i-n)) return i-n; } } return 0; } void primeFactors(ll n) { ll i; while(n%2==0) { mapv.pb(2); n/=2; } for(i=3;i*i<=n;i=i+2) { while (n%i==0) { mapv.pb(i);n/=i; } } if(n>2) mapv.pb(n); } // void rev(int a, int b, veci a) // { int i; // for(i=a;i<b;i++) // { // a[i]=a[b-i-1]; // } // for(auto i:a)cout<<i<<" "; // } map<string,int> vis; map<string,vector<string>>stry; //vector<string> stry[1000]; void dfs(string v) { vis[v]=1; //cout<<v<<" "; for(auto i:stry[v]) { if(vis[i]==0) dfs(i); } } ll solve(ll dp[][1000], ll a[],ll low,ll high,ll turn) { if (low == high) return a[low] * turn; if (dp[low][high] != 0) return dp[low][high]; dp[low][high] = max(a[low] * turn + solve(dp, a, low + 1, high, turn + 1), a[high] * turn + solve(dp, a, low, high - 1, turn + 1)); return dp[low][high]; } int search(ll n) { ll i; string s=to_string(n); for(i=0;i<s.size();i++) { if(s[i]!='0') { if(n%(s[i]-'0')!=0) return 0; } }return 1; } int main() { fio; //test { ll n,i; cin>>n; set<string> s; string x; vector<string> a; for(i=0;i<n;i++) cin>>x,a.pb(x),s.insert(x); //for(auto i:s) cout<<i<<" "; for(i=0;i<n;i++) { // if(a[i][0]!='!') { string x=a[i]; a[i]='!'+a[i]; if(s.find(a[i])!=s.end()) { cout<<x; return 0; } } } cout<<"satisfiable"; } } /* 4 1 2 4 7 7 1 2 4 8 10 12 6 7 1 2 3 4 5 6 8 */
#include<bits/stdc++.h> using namespace std; #define fi(a,b) for(int i=a;i<b;i++) #define fj(a,b) for(int j=a;j<b;j++) #define ff first #define ss second #define ll long long #define ld long double #define ull unsigned long long #define bp(x) __builtin_popcount(x) #define pr(x) for(auto it: x) cout<<it<<" "; cout<<endl; #define getMax(x) max_element(x.begin(),x.end()) #define getMin(x) min_element(x.begin(),x.end()) #define endl "\n" typedef vector<int> vi; typedef vector< pair<int,int> > vii; typedef vector<long long> vl; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef vector< pair<ll,ll> > vll; //int dx[]={1,0,-1,0}; //int dy[]={0,1,0,-1}; //int dx[]={-1,0,1,1,1,0,-1,-1}; //int dy[]={-1,-1,-1,0,1,1,1,0}; //Time Complexity - O(log(n)log(m)) struct FenwickTree { vector<ll> bit; // binary indexed tree int n; FenwickTree(int n) { this->n = n; bit.assign(n, 0); } ll sum(int r) { ll ret = 0; for (; r >= 0; r = (r & (r + 1)) - 1) ret += bit[r]; return ret; } ll sum(int l, int r) { return sum(r) - sum(l - 1); } void upd(int idx, int delta) { for (; idx < n; idx = idx | (idx + 1)) bit[idx] += delta; } }; void nikal_pehli_fursat_mai(){ ll n, m, q; cin>>n>>m>>q; vector<array<ll, 3>>qry(q); map<ll, ll>id; int cnt = 0; vl a(n), b(m); fi(0, q){ fj(0, 3) cin>>qry[i][j]; id[qry[i][2]]; } id[0]; for(auto it: id) id[it.ff] = cnt++; FenwickTree fa1(cnt+10), fa2(cnt+10), fb1(cnt+10), fb2(cnt+10); ll ans = 0; fa1.upd(0, n); fb1.upd(0, m); fi(0, q){ ll t = qry[i][0], x = qry[i][1], y = qry[i][2]; x--; if(t==1){ ll curr = a[x]; ans -= fb1.sum(0, id[curr])*curr; ans -= fb2.sum(id[curr]+1, cnt+5); ans += fb1.sum(0, id[y])*y; ans += fb2.sum(id[y]+1, cnt+5); fa1.upd(id[curr], -1); fa1.upd(id[y], 1); fa2.upd(id[curr], -curr); fa2.upd(id[y], y); a[x] = y; } else{ ll curr = b[x]; ans -= fa1.sum(0, id[curr])*curr; ans -= fa2.sum(id[curr]+1, cnt+5); ans += fa1.sum(0, id[y])*y; ans += fa2.sum(id[y]+1, cnt+5); fb1.upd(id[curr], -1); fb1.upd(id[y], 1); fb2.upd(id[curr], -curr); fb2.upd(id[y], y); b[x] = y; } cout<<ans<<endl; } } int main(){ ios::sync_with_stdio(0); cin.tie(0); int tc=1; // cin>>tc; while(tc--){ nikal_pehli_fursat_mai(); } }
#include <bits/stdc++.h> using namespace std; #define int long long typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ii> vii; #define pb push_back #define ld long double #define f first #define s second #define in insert #define sz(x) (int)x.size() #define all(x) (x).begin(), (x).end() #define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); const int INF = 1e18 + 5; const int mod = 1e9 + 7; const int N = 2e5 + 314; const long double pi = 3.14; void solve(){ int x, y, a, b; cin >> x >> y >> a >> b; int cnt = 0; while(1){ if(y / a < x)break; if(a * x >= y)break; if(a * x >= b + x)break; x *= a; cnt++; } cnt += (y - x - 1) / b; cout << cnt << "\n"; } signed main(){ speed; int t=1; //cin>>t; while(t--)solve(); }
#include <iostream> #include <numeric> #include <vector> #include <algorithm> #include <iostream> #include <functional> #include <cstdlib> #include <cmath> #include <utility> #include <cmath> #include <list> #include <iterator> static int check7(int base, int chk) { while(1){ if((chk % base) == 7){ return 0; } chk /=base; if(chk == 0){ return 1; } } } static long long int diffSum(std::vector<long long int>& vec) { long long int sum = std::accumulate(vec.begin(), vec.end(), 0LL); long long int ret = 0; long long int size = vec.size(); /* for(int i = 0 ; i < size; i++){ ret += vec[i]*i - sum; sum += vec[i]; } */ for(auto itr = vec.begin(); itr != vec.end(); itr++){ sum -= (*itr); size--; ret += (*itr) * size - sum; } return ret; } bool IsPrimeNumber(long long n) { bool ret = true; if( n < 2){ return false; } for(long long i = 2; (i * i) <= n; i++){ if((n % i) == 0){ ret = false; break; } } return ret; } long long GetPrimeNumber(long long n) { long long ret = n; if( n < 2){ return false; } for(long long i = 2; (i * i) <= n; i++){ if((n % i) == 0){ ret = i; } } return ret; } /* long long GetMaxPrimeNumber(long long n) { long long ret = n for(long long i = 2; (i * i) < n ; i++){ if((n % i) == 0){ ret = i; } } return ret; } long long int leastCommonMultiple(int n1, int n2) { int small_n = (n1 < n2) ? n1 : n2; int large_n = (n1 < n2) ? n2 : n1; //std::cout << "large_n : " << large_n; long long int ret = 1; int sn = small_n; int ln = large_n; for(int i = 2; (i * i) < small_n; i++){ if(IsPrimeNumber(i) == false) continue; while(1){ bool endflag = true; if((sn % i) == 0){ sn /= i; endflag = false; } if((ln % i) == 0){ ln /= i; endflag = false; } if(endflag){ break; }else{ ret *= i; large_n = (sn < ln) ? sn : ln; } } } std::cout << ret << " " << ln << " " << sn << std::endl; int t1 = (sn < ln) ? ln : sn; int t2 = (sn < ln) ? sn : ln; if((t1 % t2) == 0){ ret *= t1; }else{ ret = ret*t1*t2; } return ret; } */ float ClacProbability(int A, int B, int C) { float ret; ret = A/(A + B + C); return ret; } long long Combination(long long n, long long k) { long long ret = 1; long long demoninator = 1; if( k <= 0){ return 1; } if(n/2 < k){ k = n -k; } for(int i = 0; i < k; i++){ ret *= (n - i)%(long long)(10e9 + 7); demoninator *= (i + 1)%(long long)(10e9 + 7); } return ret/demoninator; } long long CountBaseN(long long N, long long base_count[]) { while(1){ base_count[((N % 10) % 3)]++; N /= 10; if(N <= 0){ break; } } return base_count[0] + base_count[1] + base_count[2]; } int main() { std::vector<long long> T(3, 0); std::cin >> T[0] >> T[1] >> T[2]; std::sort(T.begin(), T.end()); std::cout << T[2] + T[1] << std::endl; return 0; }
/* Name: Rishad Nur; BRUR, CSE, mail: [email protected]; */ #include<bits/stdc++.h> using namespace std; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif long long int n,m,i,j,k,l,x=0,y,a,sum=0,b; cin>>n>>m>>l; sum=n+m+l; x=min(n,min(m,l)); cout<<sum-x<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define maxn 100005 ll dp[105][maxn] , n, arr[105] , zog , vag; ll solve(ll pos , ll sum) { if(sum>vag)return 0LL; if(pos == n+1) { return sum; } if(dp[pos][sum]!=-1)return dp[pos][sum]; ll ans1 = 0 , ans2 = 0; if(sum+arr[pos]<=vag)ans1 = solve(pos + 1 , sum + arr[pos]); ans2 = solve(pos + 1 , sum); return dp[pos][sum]=max(ans1 , ans2); } int main() { scanf("%lld",&n); memset(dp , -1 , sizeof(dp)); for(ll i=1;i<=n;i++) { scanf("%lld",&arr[i]); zog+=arr[i]; } vag = zog/2; //cout << zog << endl; ll ans = solve(1 , 0); printf("%lld\n",zog-ans); }
#include<bits/stdc++.h> using namespace std; #define I inline int #define V inline void #define ll long long int #define isnum(ch) ('0'<=ch&&ch<='9') #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 REP(u) for(int i=h[u],v;v=e[i].t,i;i=e[i].n) #define gc (_op==_ed&&(_ed=(_op=_buf)+fread(_buf,1,100000,stdin),_op==_ed)?EOF:*_op++) char _buf[100000],*_op(_buf),*_ed(_buf); I getint(){ int _s=0,_f=1;char _ch=gc; while(!isnum(_ch))(_ch=='-')&&(_f=-1),_ch=gc; while(isnum(_ch))_s=_s*10+_ch-48,_ch=gc; return _s*_f; } const int N=20,mod=998244353,INF=0x3f3f3f3f; V check(int&x){x-=mod,x+=x>>31&mod;} V cmax(int&x,int y){if(x-y>>31)x=y;} V cmin(int&x,int y){if(y-x>>31)x=y;} int n,now; int X[N],Y[N],Z[N],dp[1<<N][N]; I dis(int x,int y){ return abs(X[x]-X[y])+abs(Y[x]-Y[y])+max(0,Z[y]-Z[x]); } V input(){ n=getint(); FOR(i,0,n-1)X[i]=getint(),Y[i]=getint(),Z[i]=getint(); } V init(){ FOR(i,0,(1<<n)-1)FOR(j,0,n-1)dp[i][j]=INF; dp[1][0]=0; } V work(){ int l=(1<<n)-1,u,v,t,flag; FOR(i,1,l){ do{ flag=0; FOR(u,0,n-1)FOR(v,0,n-1){ t=1<<v|i; if(dp[i][u]+dis(u,v)<dp[t][v]) dp[t][v]=dp[i][u]+dis(u,v),flag=1; } }while(flag); } cout<<dp[l][0]; } int main(){ input(); init(); work(); // } 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 Rep(i,j,n) for(int i = j; i < (int)(n); i++) using Graph = vector<vector<int>>; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; int main(){ int n; cin >> n; vector<pair<int,int>> x(n), y(n); rep(i,n) cin >> x[i].first >> y[i].first; rep(i,n){ x[i].second = i; y[i].second = i; } sort(x.begin(), x.end()); sort(y.begin(), y.end()); int ans = max(max(abs(x[1].first - x[n-1].first), abs(x[0].first - x[n-2].first)), max(abs(y[1].first - y[n-1].first), abs(y[0].first - y[n-2].first ))); if(x[n-1].second == y[n-1].second && x[0].second == y[0].second){ cout << ans << endl; }else{ cout << max( min(abs(x[n-1].first - x[0].first), abs(y[n-1].first - y[0].first)),ans) << endl; } return 0; }
#include <bits/stdc++.h> #define int long long #define mod 1000000007 #define read(a) for(auto &x : a) cin >> x #define all(a) a.begin(), a.end() #define write(a) for(auto x : a) cout << x << " ";cout << endl #define heap priority_queue<pair<int, int>, vector<pair<int, int>>, cmp> using namespace std; #ifndef ONLINE_JUDGE #define deb(x) {cerr << #x <<" = "; _print(x); cerr << endl;} #else #define deb(x) #endif typedef long long ll; typedef unsigned long long ull; typedef long double lld; // void _print(int t) {cerr << t;} void _print(ll t) {cerr << t;} void _print(string t) {cerr << t;} void _print(char t) {cerr << t;} void _print(lld 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.first); cerr << ","; _print(p.second); 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 << "]";} vector<pair<int, int>> merge(vector<pair<int, int>> &v1, vector<pair<int, int>> &v2, vector<pair<int, int>> &a){ vector<pair<int, int>> ans; for(auto p : v1){ int total = count(all(v1), p) + count(all(v2), p); total = min(total, (int)count(all(a), p)); int already = count(all(ans), p); while(already < total){ ans.push_back(p); already++; } } for(auto p : v2){ int total = count(all(v1), p) + count(all(v2), p); total = min(total, (int)count(all(a), p)); int already = count(all(ans), p); while(already < total){ ans.push_back(p); already++; } } return ans; } main(){ ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0); int n; cin >> n; vector<pair<int, int>> a(n), vec, vec2; // set<pair<int, int>> pos; for(auto &p : a) cin >> p.first >> p.second; sort(all(a)); for(int i = 0; i < 3; i++){ vec.push_back(a[i]); vec.push_back(a[n - 1 - i]); } for(auto &p : a) swap(p.first, p.second); sort(all(a)); for(auto &p : a) swap(p.first, p.second); for(int i = 0; i < 3; i++){ vec2.push_back(a[i]); vec2.push_back(a[n - 1 - i]); } vector<int> ans; // for(auto p : pos) vec.push_back(p); // deb(vec); // deb(vec2); vec = merge(vec, vec2, a); // deb(vec); for(int i = 0; i < (int)vec.size(); i++){ for(int j = i + 1; j < (int)vec.size(); j++){ int dx = llabs(vec[i].first - vec[j].first); int dy = llabs(vec[i].second - vec[j].second); int d = max(dx, dy); ans.push_back(d); } } sort(all(ans)); assert(ans.size() >= 2); // deb(ans); cout << ans[ans.size() - 2] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ long long t;cin>>t; while(t--){ long long l,r;cin>>l>>r; if(l*2ll>r)cout<<0<<endl; else{ long long d=r-l; long long f=d-l+1; long long g=f*(f+1); long long h=g/2; cout<<h<<endl; } } }
#include <bits/stdc++.h> using namespace std ; #define i64 int64_t // typecast using i64(x) #define int int64_t #define ld long double #define f(i,a,b) for(int i = int(a); i < int(b); ++i) #define endl '\n' #define PQ priority_queue #define LB lower_bound #define UB upper_bound #define fr first #define sc second #define all(a) (a).begin(),(a).end() #define allr(a) (a).rbegin(),(a).rend() #define sz(x) ((int)(x).size()) #define mem0(a) memset(a, 0, sizeof(a)) #define mem1(a) memset(a, -1, sizeof(a)) //#ifndef ONLINE_JUDGE template<typename T> void __p(T a) { cout<<a; } template<typename T, typename F> void __p(pair<T, F> a) { cout<<"{"; __p(a.first); cout<<","; __p(a.second); cout<<"}\n"; } template<typename T> void __p(std::vector<T> a) { cout<<"{"; for(auto it=a.begin(); it<a.end(); it++) __p(*it),cout<<",}\n"[it+1==a.end()]; } template<typename T, typename ...Arg> void __p(T a1, Arg ...a) { __p(a1); __p(a...); } template<typename Arg1> void __f(const char *name, Arg1 &&arg1) { cout<<name<<" : "; __p(arg1); cout<<endl; } template<typename Arg1, typename ... Args> void __f(const char *names, Arg1 &&arg1, Args &&... args) { int bracket=0,i=0; for(;; i++) if(names[i]==','&&bracket==0) break; else if(names[i]=='(') bracket++; else if(names[i]==')') bracket--; const char *comma=names+i; cout.write(names,comma-names)<<" : "; __p(arg1); cout<<" | "; __f(comma+1,args...); } //#endif void setIO(string s = "") { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin.exceptions(cin.failbit); if(sz(s)){ freopen((s+".in").c_str(),"r",stdin); freopen((s+".out").c_str(),"w",stdout); } } void solve(){ int L, R ; cin >> L >> R ; int temp = max(int(0),R - 2*L + 1) ; cout << temp*(temp+1)/2 << endl ; } signed main(){ setIO() ; int T ; cin >> T ; f(_,0,T){ solve() ; } }
#include <bits/stdc++.h> using namespace std; #define il inline #define re register #define Rep(i, s, e) for (re int i = s; i <= e; ++i) #define Dep(i, s, e) for (re int i = s; i >= e; --i) #define file(a) freopen(#a".in", "r", stdin), freopen(#a".out", "w", stdout) const int N = 200010; il int read() { int x = 0; bool f = true; char c = getchar(); while (!isdigit(c)) {if (c == '-') f = false; c = getchar();} while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); return f ? x : -x; } int n; char s[N]; int st[N], top; int main() { n = read(), scanf("%s", s + 1); Rep(i, 1, n) { st[++top] = s[i]; if (top >= 3 && st[top] == 'x' && st[top - 1] == 'o' && st[top - 2] == 'f') top -= 3; } printf("%d", top); return 0; }
#include<bits/stdc++.h> using namespace std; #define vec vector<int> #define vecp vector<pair<int,int>> #define ll long long #define ull unsigned long long #define pb push_back #define fi first #define se second #define fr1(i,a,b) for(int i=a;i<b;i++) #define fr2(i,a,b) for(int i=a;i>=b;i--) #define fr3(i,a,b) for(int i=a;i<=b;i++) #define umap unordered_map<int,int> #define omap map<int,int> #define uset unordered_set<int> #define oset set<int> #define pr pair<int,int> #define endl "\n" #define mod 1000000007 #define all(v) v.begin(),v.end() void solve() { int n; cin>>n; string S; cin>>S; fr1(i,0,n-2) { if(i+2<n) { string sub=S.substr(i,3); if(sub=="fox") { S.erase(i,3); if(i>2) i-=3; else i=-1; n=S.size(); } } if(S.size()==0) { cout<<0<<endl; return ; } } cout<<S.size()<<endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t=1; //cin>>t; fr3(i,1,t){ solve(); } }
const long long MOD = 1e9 + 7; const long long INF = 1e9; const long long INFLL = 1e18; #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<vector<int> > vvi; typedef vector<ll> vll; typedef complex<double> cd; #define forn(i, n) for (int i = 0; (i) != (n); (i)++) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define popcount(x) __builtin_popcount(x) #define popcountll(x) __builtin_popcountll(x) #define fi first #define se second #define re return #define pb push_back #define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin()) #ifdef LOCAL #define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl #define ln cerr << __LINE__ << endl #else #define dbg(x) void(0) #define ln void(0) #endif // LOCAL int cx[4] = {-1, 0, 1, 0}; int cy[4] = {0, -1, 0, 1}; string Yes[2] = {"No\n", "Yes\n"}; string YES[2] = {"NO\n", "YES\n"}; string Possible[2] = {"Impossible\n", "Possible\n"}; string POSSIBLE[2] = {"IMPOSSIBLE\n", "POSSIBLE\n"}; int ok(int x, int n) { return 0 <= x && x < n; } void solve() { ll n; cin >> n; if (n % 4 == 0) { cout << "Even\n"; } else if (n % 2 == 1) { cout << "Odd\n"; } else { cout << "Same\n"; } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int t = 1; cin >> t; while (t--) { solve(); } }
#include<bits/stdc++.h> #include <cstdlib> #define ll long long int #define ve vector<int> #define vl vector<long long int> #define vd vector<double> #define vs vector<string> #define vve vector<vector<int>> #define all(a) a.begin(),a.end() using namespace std; const int MAX = 510000; const int MOD = 1000000007; int main(){ int t; cin>>t; ll kesu; for(int i=0;i<t;i++){ cin>>kesu; if(kesu%4==0) cout<<"Even"<<endl; else if(kesu%2==0) cout<<"Same"<<endl; else cout<<"Odd"<<endl; } return 0; }
#include <bits/stdc++.h> #define ll long long #define inf 0x3f3f3f3f #define pii pair<int, int> #define int long long using namespace std; const int maxn = 3e5+10; template <typename _tp> inline void read(_tp& x) { char ch = getchar(), sgn = 0; while (ch ^ '-' && !isdigit(ch)) ch = getchar(); if (ch == '-') ch = getchar(), sgn = 1; for (x = 0; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0'; if (sgn) x = -x; } vector<int>e[maxn]; int L[maxn], R[maxn], tim; vector<int>v[maxn]; int d[maxn], d1[maxn]; void dfs(int u, int dep){ L[u] = ++tim; d[tim] = dep; d1[u] = dep; v[dep].push_back(L[u]); for(auto v: e[u]){ dfs(v, dep+1); } R[u] = tim; } bool isson(int u, int v){ return(L[u] >= L[v] && L[u] <= R[v]); } signed main(){ int n; scanf("%lld", &n); for(int i = 2; i <= n; ++i){ int a; scanf("%lld", &a); e[a].push_back(i); } dfs(1, 0); int q; scanf("%lld", &q); while(q--){ int a, b; scanf("%lld%lld", &a, &b); if(d1[a] > b){ printf("0\n"); continue; } else if(d1[a] == b){ printf("1\n"); continue; } cout << upper_bound(v[b].begin(), v[b].end(), R[a]) - lower_bound(v[b].begin(), v[b].end(), L[a]) << endl; //printf("%lld\n", ans); } //return 0; } /* 7 1 1 2 2 4 2 4 1 2 7 2 4 1 5 5 */
#include<iostream> #include<string> #include<vector> #include<algorithm> #include<bitset> #include<set> #include<map> #include<stack> #include<queue> #include<deque> #include<list> #include<iomanip> #include<cmath> #include<cstring> #include<functional> #include<cstdio> #include<cstdlib> #include<numeric> using namespace std; #define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define rep(i, n) repr(i, 0, n) #define INF 2e9 #define MOD 1000000007 //#define MOD 998244353 #define LINF (long long)4e18 #define jck 3.141592 #define PI acos(-1.0) const double EPS = 1e-10; using ll = long long; using Pi = pair<int,int>; using Pl = pair<ll,ll>; int main(){ int T; cin >> T; while(T--) { string s; cin >> s; int n = s.size(); string t = "atcoder"; if(s > t){ cout << 0 << endl; continue; } bool ok = false; rep(i,n) { if(s[i] != 'a') ok = true; } if(!ok){ cout << -1 << endl; continue; } int ans = INF; repr(i,1,n){ if(s[i] > 't') { ans = min(ans,i-1); } else if(s[i] != 'a') { ans = min(ans,i); } } cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define pll pair<ll,ll> #define ff first #define ss second #define pb push_back #define endl "\n" const ll maxn=3e3+10; const ll mod =1e9+7 ; const ll base=3e18; ll cnt[maxn]; ll f[maxn]; ll dp[maxn]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); if (fopen("t.inp", "r")) { freopen("test.inp", "r", stdin); freopen("test.out", "w", stdout); } ll n; cin>>n ; for (int i=1;i<=n;i++) { ll x; cin>> x; f[i]=f[i-1]+x; } ll ans=1; for (int j=1;j<=n;j++) { dp[j]=1; } for (int k=2;k<=n;k++) { for (int j=1;j<=n;j++) { ll pre=dp[j]; dp[j]=cnt[f[j]%k]; cnt[f[j]%k]=(cnt[f[j]%k]+pre)%mod; // if (k==2) cout <<dp[j]<<" "<<f[j]<<endl; } for (int j=0;j<=n;j++) cnt[j]=0; ans=(ans+dp[n])%mod; } cout <<ans; }
#include <bits/stdc++.h> #define ms(a,b) memset(a, b, sizeof(a)) #define rep(a,b,c) for(int a = (int)(b); a < (int)(c); a++) #define fi first #define se second #define pb push_back #define pf push_front #define m_p(a,b) make_pair(a, b) #define lson l,mid,o << 1 #define rson mid + 1,r,o << 1 | 1 #define ls o << 1 #define rs o << 1 | 1 #define inf 0x3f3f3f3f using namespace std; typedef long long ll; typedef unsigned long long ull; typedef double db; typedef pair<int,int> pii; inline bool isdigit(char& ch) { return ch >= '0' && ch <= '9'; } template<class T> void read(T &x) { x = 0; ll f = 1;char ch = getchar(); for (;!isdigit(ch);ch = getchar()) if (ch == '-') f = -1; for (; isdigit(ch);ch = getchar()) x = (x << 1) + (x << 3) + ch - '0'; x *= f; } template<class T> inline void write(T x) { if (x == 0) {putchar('0');return ;} if (x < 0) {putchar('-');x = -x;} int _stk[65],_top = 0; for (;x;x /= 10) _stk[++_top] = x % 10 + 48; for (;_top;_top--)putchar(_stk[_top]); } const int MAXN = 3030; const ll mod = 1e9 + 7; ll sum[MAXN], arr[MAXN]; ll dp[MAXN][MAXN], f[MAXN][MAXN]; int main () { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n; cin >> n; rep(i, 1, n + 1) { cin >> arr[i]; sum[i] = sum[i-1] + arr[i]; } dp[0][0] = 1; rep(i, 1, n + 1) { rep(j, 1, i + 1) { f[j][sum[i-1] % j] += dp[i-1][j-1]; f[j][sum[i-1] % j] %= mod; } rep(j, 1, i + 1) { dp[i][j] = f[j][sum[i] % j] % mod; /*rep(k, 0, i) { dp[i][j] += dp[k][j-1] * ((sum[i] - sum[k]) % j == 0); if (dp[i][j] >= mod) dp[i][j] -= mod; }*/ } } ll ans = 0; rep(i, 0, n + 1) { ans += dp[n][i]; ans %= mod; } cout << ans; return 0; }
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> //required #include <ext/pb_ds/tree_policy.hpp> //required // template starts using namespace __gnu_pbds; //required using namespace std; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // ordered_set <int> s; // s.find_by_order(k); returns the (k+1)th smallest element // s.order_of_key(k); returns the number of elements in s strictly less than k #define MOD (1000000000+7) // change as required #define pb(x) push_back(x) #define mp(x,y) make_pair(x,y) #define all(x) x.begin(), x.end() #define print(vec,l,r) for(int i = l; i <= r; i++) cout << vec[i] <<" "; cout << endl; #define input(vec,N) for(int i = 0; i < (N); i++) cin >> vec[i]; #define debug(x) cerr << #x << " = " << (x) << endl; #define leftmost_bit(x) (63-__builtin_clzll(x)) #define rightmost_bit(x) __builtin_ctzll(x) #define set_bits(x) __builtin_popcountll(x) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); typedef long long int ll; // start of highly risky #defines #define int ll // disable when you want to make code a bit faster #define endl '\n' // disable when dealing with interactive problems // End of highly risky #defines template <typename T> class segtree{ public: struct item{ T val; }; item sentinel;// the out of range value vector<item> arr;//[4*MAXN]; // MAXN = 2e5 T N; segtree(const T sz){ N = 1; sentinel.val = 0; // for sum:sentinal_val = 0, min = 1e17, max = -1e7, XOR = 0, gcd = 1 while(N < sz) N <<= 1; arr.resize(2*N); for(int i = 0; i < 2*N; i++) arr[i] = sentinel; } item combine(item a, item b){ item res; res.val = a.val^b.val; return res; } void build(vector<T> &vec,int index, int l, int r){ if(l == r){ if(l >= (int)vec.size()) return; arr[index].val = vec[l]; return; } int m = (l+r)/2; build(vec,2*index,l,m); build(vec,2*index+1,m+1,r); arr[index] = combine(arr[2*index],arr[2*index+1]); } void build(vector<T> &vec){ build(vec,1,0,N-1); } // 0 based indexing for upd_index void update(int index, int l, int r, int upd_index,T upd_val){ if(l > upd_index || upd_index > r) return; if(l == r){ arr[index].val = upd_val; return; } int m = (l+r)/2; update(2*index,l,m,upd_index,upd_val); update(2*index+1,m+1,r,upd_index,upd_val); arr[index] = combine(arr[2*index],arr[2*index+1]); } // 0 based indexing for upd_index void update(int upd_index, T upd_val){ update(1,0,N-1,upd_index,upd_val); } item query(int index, int l, int r, int lx, int rx){ if(l > rx || lx > r) return sentinel; if(lx <= l && r <= rx){ return arr[index]; } int m = (l+r)/2; return combine(query(2*index,l,m,lx,rx), query(2*index+1,m+1,r,lx,rx)); } // assuming lx and rx are 0 based // query returns the answer in the range [lx,rx] // including lx and rx T query(int lx, int rx){ return query(1,0,N-1,lx,rx).val; } }; void solve(){ // code starts from here int N, Q; cin >> N >> Q; vector<int> vec(N); input(vec,N); segtree<int> s(N); s.build(vec); while(Q--){ int t,x,y; cin >> t >> x >> y; if(t == 1){ vec[x-1] ^= y; s.update(x-1,vec[x-1]); } else cout << s.query(x-1,y-1) << endl; } } signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int T; // cin >> T; T = 1; while(T--){ solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++) #define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--) #define all(v) v.begin(), v.end() ll op(ll x, ll y) {return x^y;} // 関数 ll e = 0; // 元 ll len = 1; // セグメントの長さ void seg_len(ll N) { while (len<=N) {len *= 2;} } struct segtree { vector<ll> vec; segtree(ll N) : vec(2*len) { rep(i,2*len) vec[i] = e; } void set(ll id, ll x) { id += len; vec[id] = x; while (1) { id /= 2; if (id==0) break; vec[id] = op(vec[2*id],vec[2*id+1]); } } ll get(ll id) { id += len; return vec[id]; } ll prod(ll l, ll r) { l += len; r += len; ll res = e; while (l<r) { if (l%2) { res = op(res,vec[l]); l++; } l /= 2; if (r%2) { res = op(res,vec[r-1]); r--; } r /= 2; } return res; } }; int main() { ll N, Q; cin >> N >> Q; seg_len(N); segtree seg(N); rep(i,N) { ll A; cin >> A; seg.set(i,A); } vector<ll> T(Q), X(Q), Y(Q); rep(i,Q) cin >> T[i] >> X[i] >> Y[i]; rep(i,Q) { ll t = T[i], x = X[i]-1, y = Y[i]; if (t==1) { ll nv = seg.get(x) ^ y; seg.set(x,nv); } else if (t==2) { ll ans = seg.prod(x,y); cout << ans << endl; } } }
#include <bits/stdc++.h> #include <cstdlib> #define rep(i, n) for (int i = 0; i < n; i++) #define YesNo(T) if(T){cout << "Yes" << endl;}else{cout << "No" << endl;} using namespace std; typedef long long ll; int main() { int n, s, d; cin >> n >> s >> d; vector<int> x(n), y(n); rep(i, n) cin>>x[i] >> y[i]; bool damage = false; rep(i,n){ if(x[i]<s && y[i]>d){ damage = true; break; } } YesNo(damage); return 0; }
/** Seek God..Trust God..Praise God..**/ #include<bits/stdc++.h> using namespace std; #define fRead(x) freopen("x.txt","r",stdin) #define fWrite(x) freopen ("x.txt","w",stdout) #define mt make_tuple #define ld long double #define ll long long #define ull unsigned long long #define ff first #define ss second #define pb push_back #define INF 2e16 #define PI acos(-1.0) #define mp make_pair #define pii pair<int,int> #define pll pair<LL,LL> #define endl "\n"; #define min3(a,b,c) min(a,min(b,c)) #define max3(a,b,c) max(a,max(b,c)) #define min4(a,b,c,d) min(a,min(b,min(c,d))) #define max4(a,b,c,d) max(a,max(b,max(c,d))) #define SQR(a) ((a)*(a)) #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 REP(i,b) for(int i=0;i<b;i++) #define MEM(a,x) memset(a,x,sizeof(a)) #define ABS(x) ((x)<0?-(x):(x)) #define SORT(v) sort(v.begin(),v.end()) #define REV(v) reverse(v.begin(),v.end()) #define yes cout << "Yes" << endl; #define no cout << "No" << endl; #define Yes cout << "YES" << endl; #define No cout << "NO" << endl; //#define FASTIO ios_base::sync_with_stdio(0);cin.tie(nullptr); ///..................Sort by second element in a pair in decending order............. /// bool SortbySecDesc(const pair<long long,long long > &a, const pair<long long,long long > &b) { return a.second>b.second; } ///.........................first element of pair in descending order..........................////// bool sortinrev(const pair<int,int> &a, const pair<int,int> &b) { return (a.first > b.first); } ///.............................................................TEMPLATE.................................................///// /// Convert String to Int //// int String_to_int(string s) { stringstream geek(s); int ans = 0; geek >> ans; return ans; } /// string to int /// int S_I(string s) { return stoi(s); } /* /// int to string /// string I_S(int n) { return atoi(n); } */ /* long long Prime[3000000],nPrime; long long mark[10000002]; void seive(long long int n) { long long int i,j,limit=sqrt(n*1.0)+2; mark[1]=1; for(i=4; i<=n ;i+=2) mark[i]=1; Prime[nPrime++]=2; for(i=3; i<=n; i+=2) { if(!mark[i]) { Prime[nPrime++]=i; if(i<=limit) { for(j=i*i; j<=n ;j+=i*2) { mark[j]=1; } } } } } */ int main() { ll n , s , d; cin >> n >> s >> d; bool f = 0; for(int i=0; i<n; i++) { ll a , b; cin >> a >> b; if(a<s && b>d) { f = 1; } } if(f) { yes; } else { no; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; #define MOD 1000000007LL #define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++) #define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++) #define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++) #define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++) #define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--) #define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--) #define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--) #define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--) #define iter(i, it) for(auto &(i): (it)) template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) { cout << "(" << m.first << ", " << m.second << ")"; return s; } template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) { ll c = 0; cout << "{ "; iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", "); cout << "}"; return s; } template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) { cout << "{ "; rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", "); cout << "}"; return s; } template<typename T> ostream& operator<<(ostream &s, const list<T> &v) { ll c = 0; cout << "{ "; iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", "); cout << "}"; return s; } int main(void) { ll A, B, C; cin >> A >> B >> C; if(A * A + B * B < C * C) cout << "Yes"; else cout << "No"; cout << endl; return 0; }
#include <iostream> #include <string> #include <vector> #include <cmath> using std::cin; using std::cout; using std::endl; using std::string; using std::vector; int main(){ int a, b, c; cin >> a >> b >> c; if(a*a + b*b < c*c){ cout << "Yes" << endl; }else{ cout << "No" << endl; } }
#include<bits/stdc++.h> using namespace std; #define Mod(x) (x>=P)&&(x-=P) #define rep(i,a,b) for(ll i=a,i##end=b;i<=i##end;++i) #define drep(i,a,b) for(ll i=a,i##end=b;i>=i##end;--i) #define erep(i,a) for(ll i=hd[a];i;i=nxt[i]) typedef long long ll; void Max(ll &x,ll y){x<y&&(x=y);} void Min(ll &x,ll y){x>y&&(x=y);} bool vio; char IO; ll rd(ll res=0){ bool f=0; while(IO=getchar(),IO<48||IO>57) f|=IO=='-'; do res=(res<<1)+(res<<3)+(IO^48); while(IO=getchar(),isdigit(IO)); return f?-res:res; } const ll M=1005; ll nxt[M],to[M],hd[M],ecnt,n,m; bool mk[M],fl; ll dep[M]; void Add(ll a,ll b){ nxt[++ecnt]=hd[a],to[hd[a]=ecnt]=b; } void dfs(ll x){ if(!fl)return ; erep(i,x){ ll y=to[i]; if(!mk[y])continue; if(dep[y]==-1)dep[y]=dep[x]^1,dfs(y); else if(dep[y]==dep[x])fl=0; } } bool let; int main(){ cerr<<(&vio-&let)/1024.0/1024<<endl; n=rd(),m=rd(); rep(i,1,m){ ll a=rd(),b=rd(); Add(a,b),Add(b,a); } ll S=(1<<n)-1,res=0; rep(k,0,S){ rep(i,1,n)mk[i]=0,dep[i]=-1; rep(i,1,n)if(1<<(i-1)&k) mk[i]=1; ll ans=1; fl=1; rep(i,1,n)if(!mk[i]) erep(j,i)if(!mk[to[j]])fl=0; rep(i,1,n)if(mk[i]&&dep[i]==-1) ans=ans*2,dep[i]=0,dfs(i); if(fl)res+=ans; } printf("%lld",res); return 0; }
//include <atcoder> #include <iostream> #include <algorithm> #include <cmath> #include <tuple> #include <string> #include <vector> #include <queue> #include <deque> #include <stack> #include <set> #include <unordered_set> #include <map> #include <unordered_map> #define flush fflush(stdout) #define endl '\n' #define all(v) v.begin(), v.end() using namespace std; //using namespace atcoder; typedef long long ll; typedef pair<int, int> P; typedef pair<ll, ll> Pl; const int mod1 = (int)1e9 + 7, mod2 = (int)998244353; const int INF = (int)1e9; const ll LINF = (ll)1e18 + 10; const int di[8] = {1, 0, -1, 0, 1, 1, -1, -1}, dj[8] = {0, 1, 0, -1, -1, 1, -1, 1}; #define rep0(i, n) for (i = 0; i < n; i++) #define rep1(i, a, b) for (i = a; i < b; i++) template <typename T> T my_abs(T x){ return (x >= 0)? x : -x; } template <typename T> void chmax(T &a, T b){ a = max(a, b); } template <typename T> void chmin(T &a, T b){ a = min(a, b); } ll gcd(ll a, ll b){ if (a > b) return gcd(b, a); if (a == 0) return b; return gcd(b % a, a); } bool incld_bit(int bit, int i){ return ((bit>>i) & 1) == 1; } // -------------------------------------------------------------------------------- int main(void){ int i, j; int a, b, c; cin >> a >> b >> c; int ans; if (a == b){ ans = c; }else if (b == c){ ans = a; }else if (c == a){ ans = b; }else{ ans = 0; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #include<cmath> #include<string> #define pb push_back #define x first #define y second #define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0) #define all(x) x.begin(),x.end() #define int long long #define ll long long using namespace std; void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} //void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif // look for all edge cases //search for a pattern void solve(){ int a,b; cin >> a >> b; int ans = 1; for(int i = 2 ; i < (b - a) + 1; i++){ int val1 = a/i; int val2 = b/i; val2 += (a % i == 0) ? 1:0; //debug(val2, val1); if(val2 - val1 > 1){ ans = i; } } cout << ans ; } signed main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); return 0; }
#include <bits/stdc++.h> #include <unistd.h> #define rep(i,j,n) for(i=j;i<n;i++) #define repi(i,j,n) for(i=j;i>n;i--) #define pie 3.141592653589793238 #define ll long long #define ld long double #define vll vector<ll> #define pll pair<ll,ll> #define vpll vector<pll> #define pb push_back #define F first #define S second #define endl '\n' #define UQ(x) (x).resize(distance((x).begin(),unique(x.begin(),x.end()))) using namespace std; mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); mt19937_64 rnd64(chrono::high_resolution_clock::now().time_since_epoch().count()); ll power(ll a,ll m,ll mod){ ll ans = 1; while(m){ if(m%2) ans *= a, ans %= (mod); a = (a*a) % mod; m >>= 1; } return ans; } struct custom_hash { // Credits: https://codeforces.com/blog/entry/62393 static uint64_t splitmix64(uint64_t x) { // http://xorshift.di.unimi.it/splitmix64.c 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); } size_t operator()(pair<int64_t, int64_t> Y) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(Y.first * 31 + Y.second + FIXED_RANDOM); } }; const long long inf = 1e18; const long long M = 1000000007; void solve(){ ll i,j,_; ll n, m; cin >> n >> m; // brute(n,m,0); if(n == 1 && m == 0) { cout << 1 << ' ' << 2 << endl; return; } if(m < 0 || m > n - 2) { cout << - 1 << endl; return; } cout << 1 << ' ' << 2 * (m + 2) << endl; j = 2; rep(i,1,m + 2) { cout << j << ' ' << j + 1 << endl; j += 2; } n -= m + 2; j++; while(n--) { cout << j << ' ' << j + 1 << endl; j += 2; } } int main() { ios::sync_with_stdio(0); cin.tie(0); ll T=1; // cin>>T; while(T--){ solve(); } 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 N; string S; vector<int> L, R; vector<int> nxt(vector<int> A){ int K = inf; rep(i, N) chmin(K, abs(A[i+1]-A[i])); if(K == 1) return A; vector<int> ret(N+1); int m = *min_element(all(A)); rep(i, N+1){ ret[i] = (A[i]-m)/K; } return ret; } int main(){ cin >> N >> S; vector<int> A(N+1); rep(i, N+1) cin >> A[i]; L.assign(N+1, 0), R.assign(N+1, 0); rep(i, N+1){ int tmp = 0; rep3(j, i-1, 0){ if(A[j] < A[j+1]) tmp--; else tmp++; chmin(L[i], tmp); } tmp = 0; rep2(j, i+1, N){ if(A[j-1] > A[j]) tmp--; else tmp++; chmin(R[i], tmp); } } int K = inf; rep(i, N) chmin(K, abs(A[i+1]-A[i])); cout << K << '\n'; rep(i, K){ vector<int> v = nxt(A); rep(j, N+1) cout << v[j] << (j == N? '\n' : ' '); rep(j, N+1) A[j] -= v[j]; } }
/*** author: yuji9511 ***/ #include <bits/stdc++.h> // #include <atcoder/all> // using namespace atcoder; using namespace std; using ll = long long; using lpair = pair<ll, ll>; const ll MOD = 1e9+7; const ll INF = 1e18; #define rep(i,m,n) for(ll i=(m);i<(n);i++) #define rrep(i,m,n) for(ll i=(m);i>=(n);i--) #define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];}; void print() {} template <class H,class... T> void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);} #define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << "\n" void solve(){ ll N,K; cin >> N >> K; ll ans = 0; rep(ab,2,2*N+1){ ll cd = ab - K; if(cd >= 2 && cd <= 2*N){ ll n1 = 0, n2 = 0; if(ab <= N){ n1 = ab-1; }else{ n1 = 2 * N - ab + 1; } if(cd <= N){ n2 = cd - 1; }else{ n2 = 2 * N - cd + 1; } ans += n1 * n2; } } print(ans); } int main(){ cin.tie(0); ios::sync_with_stdio(false); solve(); }
#include<bits/stdc++.h> #define ll long long #define rep(i,a,b) for(int i=a;a<b?i<b:i>b;a<b?i+=1:i-=1) #define f first #define s second #define pb push_back #define tc int t;cin>>t;while(t--) #define mp make_pair using namespace std; long long countConsecutive(long long N) { long long count = 0; for (long long L = 1; L * (L + 1) < 2 * N; L++) { double a = (1.0 * N-(L * (L + 1)) / 2) / (L + 1); if (a-(long long)a == 0.0) count++; } return count; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n; cin>>n; cout<<2*(countConsecutive(n)+1); }
#include<iostream> #include<cstdio> #include<stack> #include<queue> #include<algorithm> #include<string> #include<set> #include<map> #include<vector> #include<math.h> #include<stdio.h> #include<tuple> #include<string.h> #include <numeric> #include<unordered_map> using namespace std; #define sim template < class c #define ris return * this #define dor > debug & operator << #define eni(x) sim > typename \ enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { #ifdef LOCAL ~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } #else sim dor(const c&) { ris; } #endif }; #define pp(...) "\033[94m [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m" #define pp1(...) "\033[1;47;35m" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m" //Macro overload #define PP_CAT( A, B ) A ## B #define PP_EXPAND(...) __VA_ARGS__ // Macro overloading feature support #define PP_VA_ARG_SIZE(...) PP_EXPAND(PP_APPLY_ARG_N((PP_ZERO_ARGS_DETECT(__VA_ARGS__), PP_RSEQ_N))) #define PP_ZERO_ARGS_DETECT(...) PP_EXPAND(PP_ZERO_ARGS_DETECT_PREFIX_ ## __VA_ARGS__ ## _ZERO_ARGS_DETECT_SUFFIX) #define PP_ZERO_ARGS_DETECT_PREFIX__ZERO_ARGS_DETECT_SUFFIX ,,,,,,,,,,,0 #define PP_APPLY_ARG_N(ARGS) PP_EXPAND(PP_ARG_N ARGS) #define PP_ARG_N(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N,...) N #define PP_RSEQ_N 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 #define PP_OVERLOAD_SELECT(NAME, NUM) PP_CAT( NAME ## _, NUM) #define PP_MACRO_OVERLOAD(NAME, ...) PP_OVERLOAD_SELECT(NAME, PP_VA_ARG_SIZE(__VA_ARGS__))(__VA_ARGS__) //Overload dg_ #define dg(...) PP_MACRO_OVERLOAD(dg, __VA_ARGS__) #define dg_1(x) debug() <<"\033[0;33mLine(" << __LINE__ <<")\033[0m"<<"\033[1;36m->"<<"\033[0m"<< pp(x) #define dg_2(x,y) debug() << "\033[0;33mLine(" << __LINE__ <<")\033[0m"<<"\033[1;36m->"<<"\033[0m"<< pp(x) pp(y) #define dg_3(x,y,z) debug() << "\033[0;33mLine(" << __LINE__ <<")\033[0m"<<"\033[1;36m->"<<"\033[0m"<< pp(x) pp(y) pp(z) #define dg_4(w,x,y,z) debug() << "\033[0;33mLine(" << __LINE__ <<")\033[0m"<<"\033[1;36m->"<<"\033[0m"<< pp(w) pp(x) pp(y) pp(z) #define dg_5(w,x,y,z,z1) debug() << "\033[0;33mLine(" << __LINE__ <<")\033[0m"<<"\033[1;36m->"<<"\033[0m"<< pp(w) pp(x) pp(y) pp(z) pp(z1) #define dg_6(w,x,y,z,z1,z2) debug() << "\033[0;33mLine(" << __LINE__ <<")\033[0m"<<"\033[1;36m->"<<"\033[0m"<< pp(w) pp(x) pp(y) pp(z) pp(z1) pp(z2) #define sf(...) PP_MACRO_OVERLOAD(sf, __VA_ARGS__) #define sf_1(x) scanf("%lld",&x); #define sf_2(x, y) scanf("%d %d", &x,&y); // #define int long long #define all(x) x.begin() , x.end() #define clr(x , y) memset(x , y , sizeof x); #define sz(x) (int)x.size() using lint = long long int; const int Mod = 1e9 + 7; const lint inf = 1e18; const int N = 2e5; signed main() { ios::sync_with_stdio(false); cin.tie(0); lint n; cin >> n; lint ans = 0; for(lint i = 1;i <= min(n , 10000000ll); i++) { lint m = 2 * n; // if(m % i) continue; lint a = m/i; lint b = i - 1; if(b > a) swap(a, b); dg(i , m , a , b); lint f = (a + b) / 2; lint s = (a - b) / 2; if(f > s) swap(f , s); lint v = ( i * (f + s) ) / 2; if(f > 0 && v == n) { dg(f , s , v); ans++; if(f > 0) ans++; } } cout << ans << '\n'; }
#include <bits/stdc++.h> using namespace std; const int MX = 1e5 +5; int N, zeroNum = 0; double ans = 0; int main(){ cin.tie(nullptr), ios::sync_with_stdio(false); cin >> N; for(int i = 1; i < N; i++) ans += ((double)N / (double)i); cout.precision(9); cout << fixed << ans; }
#include <bits/stdc++.h> using namespace std; int main() { string S; cin >> S; int cnt = 0; for (int i = 0; i < 9; i++) { if (S.substr(i, 4) == "ZONe") cnt++; } cout << cnt << endl; }
#ifdef LOGX #define _GLIBCXX_DEBUG #endif #include <bits/extc++.h> using namespace std; //#include <atcoder/all> //using namespace atcoder; /*---------macro---------*/ #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = s; i < (int)(n); i++) #define ALL(a) a.begin(),a.end() #define RALL(a) a.rbegin(),a.rend() #define mybit(i,j) (((i)>>(j))&1) /*---------type/const---------*/ typedef long long ll; typedef unsigned long long ull; typedef std::string::const_iterator state; //構文解析 const int big=1000000007; //const int big=998244353; const double EPS=1e-8; //適宜変える const int dx[4]={1,0,-1,0}; const int dy[4]={0,1,0,-1}; const char newl='\n'; struct{ constexpr operator int(){return -int(1e9)-10;} constexpr operator ll(){return -ll(1e18)-10;} }neginf; struct{ constexpr operator int(){return int(1e9)+10;} constexpr operator ll(){return ll(1e18)+10;} constexpr auto operator -(){return neginf;} }inf; /*---------debug---------*/ #ifdef LOGX #include <template/debug.hpp> #else #define dbg(...) ; #define dbgnewl ; #define prt(x) ; #define _prt(x) ; #endif /*---------function---------*/ template<typename T> T max(const std::vector<T> &a){T ans=a[0];for(T elem:a){ans=max(ans,elem);}return ans;} template<typename T> T min(const std::vector<T> &a){T ans=a[0];for(T elem:a){ans=min(ans,elem);}return ans;} template<typename T,typename U> bool chmin(T &a,const U b){if(a>b){a=b;return true;}return false;} template<typename T,typename U> bool chmax(T &a,const U b){if(a<b){a=b;return true;}return false;} bool valid(int i,int j,int h,int w){return (i>=0 && j>=0 && i<h && j<w);} template<class T,class U>T expm(T x,U y,const ll mod=big){T res=1;while(y){if(y&1)(res*=x)%=mod;(x*=x)%=mod;y>>=1;}return res;} template<class T,class U>T exp(T x,U y){T res=1;while(y){if(y&1)res*=x;x*=x;y>>=1;}return res;} int main(){ std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.precision(10); /*------------------------------------*/ int n; cin >> n; vector<ll> v(2*n); ll sum=0; rep(i,2*n)cin >> v[i], sum+=v[i]; priority_queue<ll,vector<ll>,greater<ll>> pq; ll ans=0; rep(i,n){ pq.push(v[n-i-1]); pq.push(v[n+i]); ans+=pq.top(); pq.pop(); } cout << sum-ans << newl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; ll ans = 0; vector<ll> v(2 * n); for (int i = 0; i < 2 * n; i++) { cin >> v.at(i); ans += v.at(i); } priority_queue<ll, vector<ll>, greater<ll>> pq; for (int i = n - 1; i >= 0; i--) { pq.push(v.at(i)); pq.push(v.at(2 * n - i - 1)); ans -= pq.top(); pq.pop(); } cout << ans << '\n'; }
#include <bits/stdc++.h> #define forn(i,n) for(int i=0;i<(int)n;i++) #define ce(e,i,n) cout<<e<<" \n"[i==(int)n-1]; using namespace std; int main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); // = 0 - [i] {} '\n' p _ ? ^ int n; long long c,x,y,z;; cin>>n>>c; vector<pair<long long,long long>>a; forn(i,n){ cin>>x>>y>>z; a.push_back({x-1,z}); a.push_back({y,-z}); } sort(a.begin(),a.end()); long long ans=0,b=0,to=0; //for(auto e:a)cout<<e.first<<" "<<e.second<<endl; forn(i,a.size()){ ans+=min(c,to)*(a[i].first-b); b=a[i].first; to+=a[i].second; } cout<<ans<<'\n'; }
#include <bits/stdc++.h> #define sz(v) ((int)(v).size()) #define all(v) ((v).begin()),((v).end()) #define allr(v) ((v).rbegin()),((v).rend()) #define pb push_back #define mp make_pair #define Y imag() #define X real() #define clr(v,d) memset( v, d ,sizeof(v)) #define angle(n) atan2((n.imag()),(n.real())) #define vec(a,b) ((b)-(a)) #define length(a) hypot( (a.imag()),(a.real()) ) #define normalize(a) (a)/(length(a)) #define dp(a,b) (((conj(a))*(b)).real()) #define cp(a,b) (((conj(a))*(b)).imag()) #define lengthsqrt(a) dp(a,a) #define rotate0( a,ang) ((a)*exp( point(0,ang) )) #define rotateA(about,p,ang) (rotate0(vec(about,p),ang)+about) #define lcm(a,b) ((a*b)/(__gcd(a,b))) #define reflection0(m,v) (conj((v)/(m))*(m)) #define reflectionA(m,v,p0) (conj( (vec(p0,v))/(vec(p0,m)) ) * (vec(p0,m)) ) + p0 #define same(p1,p2) ( dp( vec(p1,p2),vec(p1,p2)) < eps ) #define point complex<long double> #define PI acos(-1) typedef long long ll ; typedef unsigned long long ull; const double eps= (1e-15); using namespace std; int dcmp(double a,double b){ return fabs(a-b)<=eps ? 0: (a>b)? 1:-1 ;} int getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1;} int setBit1(int num, int idx) {return num | (1<<idx);} ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);} ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);} void GO(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);} int countNumBit1(int mask) {int ret=0; while (mask) {mask &= (mask-1);++ret; }return ret;} const ll N=200000+5,mod=998244353,sh=1000000,inf=100000000; ll a[N],b[N],c[N]; map<ll,ll> arr; int main(){ GO(); int T=1; // cin>>T; while(T--){ int n,cc; cin>>n>>cc; for(int i=0;i<n;i++){ cin>>a[i]>>b[i]>>c[i]; arr[a[i]]+=c[i]; arr[b[i]+1]-=c[i]; } ll ans=0; auto pre=arr.begin(); for(auto it=next(arr.begin());it!=arr.end();it++){ ll ff=(*it).first; ll ss=(*it).second; (*it).second+=(*pre).second; ans+= (ff-(*pre).first)*min(cc*1ll,(*pre).second); pre=it; } cout<<ans<<"\n"; } }
// Problem : B - Achieve the Goal // Contest : AtCoder - AtCoder Beginner Contest 151 // URL : https://atcoder.jp/contests/abc151/tasks/abc151_b // Memory Limit : 1024 MB // Time Limit : 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) #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; //Macros #define ll long long #define db long double #define pb push_back #define eb emplace_back #define pii pair<int,int> #define vi vector<int> #define vii vector<pii> #define mi map<int,int> #define mii map<pii,int> #define fi first #define se second #define all(a) (a).begin(),(a).end() #define sz(x) (int)x.size() #define mod 1000000007 #define EPS 1e-9 #define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0) #define inf 1e10 #define PI acos(-1.0) #define int long long template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define N 100005 //Solution void solve(){ int n,k,m,a; cin>>n>>k>>m; int ans = n*m; for(int i=0;i<n-1;i++) cin>>a, ans -= a; ans = max(ans,0LL); cout<<(ans <= k ? ans : -1)<<endl; } signed main(){ io; //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); int tests; //cin>>tests; tests = 1; while(tests--){ solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ll long long const long long MOD = 1000000007; int main(){ int a,b,c; cin >> a >> b >> c; int ans=21-a-b-c; cout << ans << endl; }
#include<bits/stdc++.h> #define g return using namespace std;int M,h=1e9,n,k,l=-1,r=1e6,a,b,i=1;vector<vector<int>> v;struct d{int m,s,f;};d x(int o,int p=h){if(v[o].size()==1&&o)g{0,-1,0};int t=h,s=-h,c=0,f=0;for(int& e:v[o])if(p-e){auto [j,y,z]=x(e,o);t=min(t,y);s=max(s,y);f|=z,c+=j;}t=abs(t);if(o){if(t<=s&&f){if(s)g{c,s-1,1};g{c,0,0};}if(t-M)g{c,-t-1,0};g{c+1,M-1,1};}if(t<=s&&f)g{c,0,0};g{c+1,0,0};}main(){cin>>n>>k;v.resize(n);for(;i<n;i++){cin>>a>>b;a--;b--;v[a].push_back(b);v[b].push_back(a);}while(r-l>1){M=(r+l)/2;if(M)(x(0).m>k?l:r)=M;else(n>k?l:r)=0;}cout<<r;}
#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 = 2e5 + 5; int n,m,mid,ans; std::vector<int> G[MAXN]; int f[MAXN],g[MAXN]; inline void dfs(int v,int fa=0){ f[v] = 1e9;g[v] = -1e9; for(auto x:G[v]){ if(x == fa) continue; dfs(x,v); f[v] = std::min(f[v],f[x]+1); g[v] = std::max(g[v],g[x]+1); } if(f[v] > mid) g[v] = std::max(g[v],0); if(f[v]+g[v] <= mid) g[v] = -1e9; if(g[v] == mid) ++ans,g[v] = -1e9,f[v] = 0; } inline bool chk(int x){ mid = x;ans = 0;dfs(1); if(g[1] != -1e9) ++ans; return ans <= m; } int main(){ scanf("%d%d",&n,&m); FOR(i,2,n){ int u,v;scanf("%d%d",&u,&v); G[u].pb(v);G[v].pb(u); } int l = 0,r = n,ans = -1; while(l <= r){ int mid = (l + r) >> 1; if(chk(mid)) ans = mid,r = mid-1; else l = mid+1; } printf("%d\n",ans); return 0; }
/************************************************************************* > File Name: 1.cpp > Author: Knowledge_llz > Mail: [email protected] > Blog: https://www.cnblogs.com/Knowledge-Pig/ > Created Time: 2021/4/10 19:57:22 ************************************************************************/ #include<bits/stdc++.h> #define For(i,a,b) for(int i=(a);i<=(b);++i) #define LL long long #define pb push_back #define fi first #define se second #define pr pair<int,int> #define mk(a,b) make_pair(a,b) using namespace std; int read(){ char x=getchar(); int u=0,fg=0; while(!isdigit(x)){ if(x=='-') fg=1; x=getchar(); } while(isdigit(x)){ u=(u<<3)+(u<<1)+(x^48); x=getchar(); } return fg?-u:u; } int n,a[2021],c[2021]; char s[2021]; int main() { #ifndef ONLINE_JUDGE freopen("input.in", "r", stdin); freopen("output.out", "w", stdout); #endif n=read(); scanf("%s",s+1); For(i,0,n) a[i]=read(); int ans=1e9; For(i,1,n) ans=min(ans,abs(a[i]-a[i-1])); printf("%d\n",ans); For(i,0,ans-1){ For(j,0,n) printf("%d ",a[j]/ans+(i<a[j]%ans)); printf("\n"); } return 0; }
#include<bits/stdc++.h> using namespace std; using ll = long long; using vl = vector<ll>; #define rep(i,n) for(int i=0;i<(n);i++) #define rrep(i,n) for(int i=(n)-1;i>=0;i--) #define rep1(i,n) for(int i=1;i<=(n);i++) #define rrep1(i,n) for(int i=(n);i>0;i--) #define fore(i_in,a) for (auto& i_in: a) #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define fio() cin.tie(nullptr);ios::sync_with_stdio(false); #define DEBUG_CTN(v) cerr<<#v<<":";for(auto itr=v.begin();itr!=v.end();itr++) cerr<<" "<<*itr; cerr<<endl template<class T> bool chmax(T &a, const T &b) {if (a<b) { a = b; return true; } return 0;} template<class T> bool chmin(T &a, const T &b) {if (a>b) { a = b; return true; } return 0;} template<class T> void print(const T &t) { cout << t << "\n"; } const ll INF = 1LL << 62; const int iINF = 1 << 30; ll n,k; int main() { fio(); cin>>n>>k; while(k--){ if(n%200==0) n/=200; else n=n*1000+200; } print(n); } //3min
#include<bits/stdc++.h> using namespace std; int main(){ long long int N,M; cin >> N >> M; vector<pair<long long int,long long int>> vec(M); for(int i=0;i<M;i++){ long long int X,Y; cin >> X >> Y; vec[i] = make_pair(X,Y); } sort(vec.begin(),vec.end()); map<long long int,vector<int>> Map; for(int i=0;i<M;i++) Map[vec[i].first].push_back(vec[i].second); map<long long int,bool> P; P[N] = true; for(auto x:Map){ vector<int> ope = x.second; map<long long int,int> judge; for(int i=0;i<ope.size();i++){ long long int Y = ope[i]; if(P[Y-1]) judge[Y] = 1; if(P[Y+1]) judge[Y] = 1; if(P[Y] && judge[Y] == 0) judge[Y] = 2; } for(auto y:judge){ if(y.second == 1) P[y.first] = true; if(y.second == 2) P[y.first] = false; } } int ans = 0; for(auto x:P) if(x.second) ans++; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define ln '\n' #define REP(i, n) for (int i = 0; i < (int)(n); ++i) #define FOR(i, a, b) for (int i = (a); i <= (int)(b); ++i) #define FORR(i, a, b) for (int i = (a); i >= (int)(b); --i) #define ALL(c) (c).begin(), (c).end() typedef long long ll; typedef vector<int> VI; typedef vector<ll> VL; typedef vector<VI> VVI; typedef vector<VL> VVL; typedef pair<int, int> P; typedef pair<ll, ll> PL; typedef vector<P> VP; typedef vector<PL> VPL; typedef vector<string> VS; int main() { cin.tie(0); ios::sync_with_stdio(false); int h, w, x, y; cin >> h >> w >> x >> y; x--; y--; VS vs(h); REP(i, h) cin >> vs[i]; int cnt = 1; FOR(i, x + 1, h - 1) { if (vs[i][y] == '#') break; cnt++; } FORR(i, x - 1, 0) { if (vs[i][y] == '#') break; cnt++; } FOR(i, y + 1, w - 1) { if (vs[x][i] == '#') break; cnt++; } FORR(i, y - 1, 0) { if (vs[x][i] == '#') break; cnt++; } cout << cnt << ln; 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; template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // macros #define int long long #define ll long long #define ld long double #define TIME clock() * 1.0 / CLOCKS_PER_SEC #define sz(x) ((int)((x).size())) template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_string(const string& s) { return '"' + s + '"'; } string to_string(const char& s) { return to_string(string(1, s)); } string to_string(const char* s) { return to_string((string) s); } string to_string(bool b) { return (b ? "1" : "0"); } string to_string(vector<bool> v) { bool first = true; string res = "{"; for (int i = 0; i < static_cast<int>(v.size()); i++) { if (!first) { res += ", "; } first = false; res += to_string(v[i]); } res += "}"; return res; } template <size_t N> string to_string(bitset<N> v) { string res = ""; for (size_t i = 0; i < N; i++) { res += static_cast<char>('0' + v[i]); } return res; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")"; } template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")"; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) template <typename T1, typename T2> inline auto mini(T1 a, T2 b) { return (a < b ? a : b); } template<typename T, typename... Args> inline auto mini(T a, Args... args) { return mini(a, mini(args...)); } template <typename T1, typename T2> inline auto maxi(T1 a, T2 b) { return (a > b ? a : b); } template<typename T, typename... Args> inline auto maxi(T a, Args... args) { return maxi(a, maxi(args...)); } template<typename T> T gcd(T a, T b) { if(a==0 or b==0) return a+b; return gcd(b, a%b) ; } template<typename T> T lcm(T a, T b) { if(a==0 or b==0) return 0; return a/gcd(a, b)*b; } // random number generator mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // use mt19937_64 for 64 bit // constants const long double eps = LDBL_EPSILON; const int inf = 1e15; const int modn = 1e9+7; const int maxn = 2e5+3; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // Your code here int n; cin >> n; vector<array<int, 2>> a(n); for(int i = 0; i < n; i++) { cin >> a[i][0] >> a[i][1]; } bool flag = 1; for(int i = 0; i < n and flag; i++) { for(int j = i + 1; j < n and flag; j++) { for(int k = j + 1; k < n and flag; k++) { int num1 = a[j][1] - a[i][1]; int den1 = a[j][0] - a[i][0]; int num2 = a[k][1] - a[j][1]; int den2 = a[k][0] - a[j][0]; if(num1 * den2 == num2 * den1) { flag = 0; } } } } cout << (flag == 0 ? "Yes\n" : "No\n"); return 0; }
#include<bits/stdc++.h> #define ll long long #define pb push_back #define all(x) x.begin(), x.end() #define sz(x) (int)(x.size()) #define pll pair<ll, ll> #define vi vector<int> #define vll vector<ll> #define INF (1 << 30) #define MOD 1000000007 #define ld long double #define tc ll tt; cin >> tt; while(tt--) #define fio ios_base::sync_with_stdio(0), cin.tie(NULL) using namespace std; int get(int s, int t) { // 0....9 // (0.5).........(8.5) return t - s; } int main() { int N, m, t, last; cin >> N >> m >> t; int store = N; last = 0; while (m--) { int a, b; cin >> a >> b; N -= get(last, a); if (N <= 0) break; N += get(a, b); if (N > store) N = store; last = b; } if (N > 0) N -= get(last, t); if (N > 0) cout << "Yes\n"; else cout << "No\n"; }
#include <bits/stdc++.h> #define REP(i, n) for(int i = 0; i < n; ++i) using namespace std; using LLONG = long long; LLONG K, N, M; vector<LLONG> As, Bs; bool CanDo(const LLONG x) { vector<LLONG> Ls(K), Rs(K); REP(i, K) { LLONG Ai = As[i]; Ls[i] = (M * Ai - x + N - 1) / N; Rs[i] = (M * Ai + x) / N; } LLONG sumB = accumulate(Ls.begin(), Ls.end(), 0LL); REP(i, K) Bs[i] = Ls[i]; REP(i, K) { if (sumB >= M) break; LLONG maxDiff = min(M - sumB, Rs[i] - Ls[i]); sumB += maxDiff; Bs[i] += maxDiff; } return accumulate(Ls.begin(), Ls.end(), 0LL) <= M && M <= accumulate(Rs.begin(), Rs.end(), 0LL); } int main() { cin >> K >> N >> M; As.assign(K, 0); Bs.assign(K, 0); REP(i, K) cin >> As[i]; LLONG ng = 1; LLONG ok = N * M; while (ok > ng + 1) { LLONG m = (ok + ng) / 2; if (CanDo(m)) { ok = m; } else { ng = m; } } CanDo(ok); for (const LLONG bi : Bs) { cout << bi << ' '; } cout << endl; }
#include <bits/stdc++.h> #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define rep(i,n) for(int i=0;i<(int)(n);i++) #define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++) #define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++) #define codefor int test;scanf("%d",&test);while(test--) #define INT(...) int __VA_ARGS__;in(__VA_ARGS__) #define LL(...) ll __VA_ARGS__;in(__VA_ARGS__) #define yes(ans) if(ans)printf("yes\n");else printf("no\n") #define Yes(ans) if(ans)printf("Yes\n");else printf("No\n") #define YES(ans) if(ans)printf("YES\n");else printf("NO\n") #define popcount(v) __builtin_popcount(v) #define vector1d(type,name,...) vector<type>name(__VA_ARGS__) #define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__)) #define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__))) #define umap unordered_map #define uset unordered_set using namespace std; using ll = long long; const int MOD=1000000007; const int MOD2=998244353; const int INF=1<<30; const ll INF2=(ll)1<<60; //入力系 void scan(int& a){scanf("%d",&a);} void scan(long long& a){scanf("%lld",&a);} template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);} template<class T> void scan(T& a){cin>>a;} template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);} void in(){} template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);} //出力系 void print(const int& a){printf("%d",a);} void print(const long long& a){printf("%lld",a);} void print(const double& a){printf("%.15lf",a);} template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);} template<class T> void print(const T& a){cout<<a;} template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}} void out(){putchar('\n');} template<class T> void out(const T& t){print(t);putchar('\n');} template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);} //デバッグ系 template<class T> void dprint(const T& a){cerr<<a;} template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}} void debug(){cerr<<endl;} template<class T> void debug(const T& t){dprint(t);cerr<<endl;} template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);} ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; } ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; } ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;} template<class T> void chmax(T &a,const T b){if(b>a)a=b;} template<class T> void chmin(T &a,const T b){if(b<a)a=b;} int main(){ LL(k,n,m); vector<ll> a(k),b(k); in(a); ll sumv=0; rep(i,k){ b[i]=a[i]*m/n; sumv+=b[i]; } vector<pair<double,int>> vec(k); rep(i,k){ vec[i].first=(double)abs((b[i]+1)*n-a[i]*m)/n*m; vec[i].second=i; } sort(all(vec)); m-=sumv; rep(i,m){ b[vec[i].second]++; } out(b); }
#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*=1000; n+=200; } } cout << n << endl; }
//#define _GLIBCXX_DEBUG #include <bits/stdc++.h> #include <algorithm> #define rep(i,n) for(int i=0;i<(n);++i) #define all(a) (a).begin(),(a).end() using namespace std; using Graph = vector<vector<int>>; typedef long long ll; //using Graph = vector<vector<pair<ll,ll>>>; const int mod =1e+9+7; const int dy[4]={0,1,0,-1}; const int dx[4]={1,0,-1,0}; const ll INF=1e18; int main(){ ll a,b; cin>>a>>b; ll c=a+b; if(c>=15&&b>=8)cout<<1<<endl; else if(c>=10&&b>=3)cout<<2<<endl; else if(c>=3)cout<<3<<endl; else cout<<4<<endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<long long> VL; typedef vector<vector<long long>> VVL; typedef pair<int,int> P; typedef tuple<int,int,int> tpl; #define ALL(a) (a).begin(),(a).end() #define SORT(c) sort((c).begin(),(c).end()) #define REVERSE(c) reverse((c).begin(),(c).end()) #define EXIST(m,v) (m).find((v)) != (m).end() #define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin() #define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin() #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i) #define RREP(i,n) RFOR(i,n,0) #define en "\n" constexpr double EPS = 1e-9; constexpr double PI = 3.1415926535897932; constexpr int INF = 2147483647; constexpr long long LINF = 1LL<<60; constexpr long long MOD = 1000000007; // 998244353; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } vector<bool> used; vector<int> dir; // left==0, right==1, other -1 vector<int> p; bool connect(int i, int j){ if(used[i]==false && used[j]==false) return true; else if(used[i]==true && used[j]==false){ if(p[i]==-1 && dir[i]==1) return true; else return false; } else if(used[i]==false && used[j]==true){ if(p[j]==-1 && dir[j]==0) return true; else return false; } else{ if(p[i]==j && p[j]==i) return true; else return false; } } int dp[300][300]; int rec(int l, int r){ if(dp[l][r] != -1) return dp[l][r]; if(r-l<2) return dp[l][r] = 0; int len = (r-l)/2; bool flag = true; REP(i,len){ if(!connect(l+i,l+i+len)){ flag = false; break; } } int ret = 0; if(flag) ret = 1; for(int m=l+2; m<=r-2; m+=2){ if(rec(l,m)==1 && rec(m,r)==1) ret = 1; } return dp[l][r] = ret; } void Main(){ int N; cin >> N; VI A(N), B(N); REP(i,N){ cin >> A[i] >> B[i]; if(A[i]>0) A[i]--; if(B[i]>0) B[i]--; } REP(i,N){ if(A[i]==2*N-1 || B[i]==0){ cout << "No" << en; return; } if(A[i]!=-1 && B[i] !=-1 && B[i]<=A[i]){ cout << "No" << en; return; } } VI cnt(2*N,0); REP(i,N){ if(A[i]!=-1){ cnt[A[i]]++; if(cnt[A[i]]>1){ cout << "No" << en; return; } } if(B[i]!=-1){ cnt[B[i]]++; if(cnt[B[i]]>1){ cout << "No" << en; return; } } } used.assign(2*N,false); dir.assign(2*N,-1); p.assign(2*N,-1); REP(i,N){ if(A[i]!=-1){ used[A[i]] = true; dir[A[i]] = 1; p[A[i]] = B[i]; } if(B[i]!=-1){ used[B[i]] = true; dir[B[i]] = 0; p[B[i]] = A[i]; } } REP(i,300)REP(j,300) dp[i][j] = -1; int ans = rec(0,2*N); cout << (ans==1 ? "Yes" : "No") << en; return; } int main(void){ cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15); int t=1; //cin>>t; REP(_,t) Main(); return 0; }
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; int n,a[100005],vis[100005],f[100005]; bool check(int x,int y) { if(vis[x]==2||vis[y]==1) return 0; if(vis[x]&&a[x]&&a[x]!=y) return 0; if(vis[y]&&a[y]&&a[y]!=x) return 0; if(vis[y]&&vis[x]&&!a[x]) return 0; return 1; } int main() { scanf("%d",&n); for(int i=1;i<=n;i++) { int x,y; scanf("%d%d",&x,&y); if((x!=-1&&vis[x])||(y!=-1&&vis[y])) { printf("No\n"); return 0; } if(x!=-1&&y!=-1) { if(x>=y) { printf("No\n"); return 0; } a[x]=y,a[y]=x; } if(x!=-1) vis[x]=1; if(y!=-1) vis[y]=2; } f[0]=1; for(int i=1;i<=2*n;i++) { for(int j=i-2;j>=0;j-=2) if(f[j]) { int fl=1; for(int l=j+1,r=j+(i-j)/2+1;r<=i;l++,r++) if(!check(l,r)) { fl=0; break; } if(fl) { f[i]=1; break; } } } if(f[2*n]) printf("Yes\n"); else printf("No\n"); return 0; }
#include<bits/stdc++.h> #define Pair pair<ll,int> #define ar array #define ll long long #define ull unsigned long long #define pb push_back using namespace std ; const ll LLMAX = 9223372036854775807; const int INF = 1e9; int n, m, k; vector<int> adj[100005]; int dist[18][100005]; int arr[18]; void bfs(int idx){ dist[idx][arr[idx]] = 0; queue<int> q; q.push(arr[idx]); while(!q.empty()){ int cur = q.front(); q.pop(); for(int k : adj[cur]){ if(dist[idx][k]==INF){ dist[idx][k] = dist[idx][cur]+1; q.push(k); } } } } int dp[18][1<<18]; int solve(int last, int s){ if(s==(1<<k)-1) return 0; if(dp[last][s]!=-1) return dp[last][s]; int ans = INF; for(int i=0; i<k; i++){ if((1<<i)&s) continue; ans = min(ans, solve(i, (1<<i)|s) + dist[last][arr[i]]); } return dp[last][s] = ans; } int main(){ memset(dp, -1, sizeof(dp)); cin>>n>>m; for(int i=0; i<m; i++){ int a, b; cin>>a>>b; adj[a].pb(b); adj[b].pb(a); } cin>>k; for(int i=0; i<k; i++){ cin>>arr[i]; } for(int i=0; i<k; i++){ for(int j=0; j<=n; j++){ dist[i][j] = INF; } bfs(i); } for(int i=0; i<k; i++){ if(dist[i][arr[0]] == INF){ cout<<-1<<endl; return 0; } } /* for(int i=0; i<k; i++){ cout<<"src "<<i<<endl; for(int j=1; j<=n; j++) cout<<dist[i][j]<<" "; cout<<endl; } */ int ans = INF; for(int i=0; i<k; i++){ ans = min(ans, 1+solve(i, 1<<i)); } cout<<ans<<endl; }
#include <bits/stdc++.h> // clang-format off using namespace std; using ll = int64_t; using ull = uint64_t; using pll = pair<ll,ll>; const ll INF = 4e18; void print0() {} template<typename Head,typename... Tail> void print0(Head head,Tail... tail){cout<<fixed<<setprecision(15)<<head;print0(tail...);} void print() { print0("\n"); } template<typename Head,typename... Tail>void print(Head head,Tail... tail){print0(head);if(sizeof...(Tail)>0)print0(" ");print(tail...);} // clang-format on char win(char a, char b) { if ((a == 'R' && b == 'P') || (a == 'S' && b == 'R') || (a == 'P' && b == 'S')) { return b; } return a; } int main() { ll n0, k; cin >> n0 >> k; vector<char> s(n0); for (ll i = 0; i < n0; i++) { cin >> s[i]; } for (ll depth = k; depth > 0; depth--) { ll n = s.size(); vector<char> nxt; nxt.push_back(win(s[0], s[1])); for(ll i = 2; (i % n) != 0; i += 2) { nxt.push_back(win(s[i % n], s[(i + 1) % n])); } s = nxt; } print(s[0]); }
#include <iostream> #include <math.h> #include <vector> #include <string> #include <numeric> #include <unordered_set> #include <iomanip> #include <algorithm> using namespace std; int main(){ string s; cin >> s; string t; bool reverse_judge=false; for(int i=0;i<s.size();i++){ if(s[i]=='R'){ reverse_judge = !reverse_judge; } else{ if(reverse_judge){ if(t[0]==s[i]) t.erase(t.begin()); else t.insert(t.begin(),s[i]); //else t = s[i] + t; } else if( t[t.size()-1]==s[i] ) t.pop_back(); else t += s[i]; } } if(reverse_judge){ reverse(t.begin(),t.end()); } cout << t << endl; }
// 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(); string s; cin >> s; ll isrev = 0; deque<char>ans; for (auto d : s) { if (d == 'R') { isrev = 1 - isrev; } else { if (!isrev) { ans.push_back(d); } else { ans.push_front(d); } } } if (isrev)rev(ans); stack<char>lol; for (auto d : ans) { if (lol.empty() || lol.top() != d) { lol.push(d); // cout << d; } else { lol.pop(); } } ans.clear(); while (sz(lol)) { ans.pb(lol.top()); lol.pop(); } rev(ans); for (auto d : ans)cout << d; return 0; }
#include <bits/stdc++.h> using namespace std; const int N=2e5+2; queue<int>q[N]; long long ans=0; int n,a[N],b[N],c[N],f[N]; void add(int x,int y) { while(x) { f[x]+=y; x^=x&-x; } } int qry(int x) { int res=0; while(x<=n) { res+=f[x]; x+=x&-x; } return res; } int main() { scanf("%d",&n); for(int i=1;i<=n;++i) scanf("%d",&a[i]); for(int i=1;i<=n;++i) { scanf("%d",&b[i]); c[i]=b[i]+i; } sort(c+1,c+n+1); for(int i=1;i<=n;++i) q[lower_bound(c+1,c+n+1,b[i]+i)-c].push(i); for(int i=1;i<=n;++i) { int x=lower_bound(c+1,c+n+1,a[i]+i)-c; if(q[x].empty()||a[i]+i!=c[x]) { puts("-1"); return 0; } a[i]=q[x].front(); q[x].pop(); ans+=qry(a[i]); add(a[i],1); } printf("%lld",ans); }
#include <bits/stdc++.h> using namespace std; #define int long long int #define vi vector<int> #define vvi vector<vector<int>> #define mii map<int,int> #define pii pair<int,int> #define ff first #define ss second #define ce cout << endl ; #define pb push_back #define mkp make_pair #define py cout << "YES" << endl ; #define pn cout << "NO" << endl ; #define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) ; bool cmp(pii& a , pii& b){ int asum = a.ff + a.ss , bsum = b.ff + b.ss ; return asum + a.ff > bsum + b.ff ; } const int l = 2e7 + 1 , mod = 1e9 + 7 ; vi prime(l , 0) , phi(l + 1) , store(l , 0) ; vvi factor(l) ; void f(){ prime[1] = 1 , prime[0] = 1 ; for(int i = 2 ; i < l ; i++){ if(!prime[i]){ for(int j = i*i ; j < l ; j+=i) prime[j] = 1 ; } } for(int i = 2 ; i < l ; i++){ if((not prime[i]) and (not prime[i-2])) store[i] = 1 ; store[i]+=store[i-1] ; } } int factorial(int n){ int ans = 1 ; for(int i = 2 ;i<=n ;i++) ans*=i ; return ans ; } int lcm(int a , int b){ return (a*b) / __gcd(a , b) ; } void print(vi &a){ for(auto it : a) cout << it << " " ; } int modadd(int a , int b){ return (a%mod + b%mod) % mod ; } int modsub(int a , int b){ return ( ( ( a % mod ) - ( b % mod ) ) + mod ) % mod ; } int modmul(int a , int b){ return ( (a % mod) * (b % mod) ) % mod ; } int fast_mod_expo(int base , int power , int ans){ if(power > 0){ if(power & 1) ans = modmul(ans , base) ; power >>= 1 , base = modmul(base , base) ; return fast_mod_expo(base , power , ans) ; } else return ans ; } void store_divisors(){ for(int i = l-1 ; i > 0 ; i--) { for(int j = i ; j < l ; j+=i) factor[j].pb(i) ; } } int EulerTotientfuunction(int n){ int ans = n ; for(int i = 2 ; i < n ; i++){ if(n%i==0){ while(n%i==0)n/=i; ans-=ans/i ; } } if(n > 1) ans-=ans/n ; return ans ; } int binarysearch(int* a , int l , int r , int key){ if(l <= r){ int mid = (l + r)>>1 ; if(a[mid] < key) l = mid + 1 ; if(a[mid] > key) r = mid - 1 ; if(a[mid] == key) return key ; return binarysearch(a , l , r , key) ; } else return 0 ; } class graph{ int v ; list<int> *l ; public: void create_list(int v){ this->v = v ; l = new list<int>[v+1] ; } void addedge(int u , int v){ l[u].pb(v) ; l[v].pb(u) ; } void print_list(){ for(int i = 1 ; i <= v ; i++){ cout << "Vertex:" << i << "->" ; for(auto it : l[i]) cout << it << "->" ; ce } } }; void solve(){ int n , aoki = 0 , takashi = 0 , ans = 0 ; cin >> n ; vector<pii> a ; for(int i = 0 , l , r ; i < n ; i ++){ cin >> l >> r ; a.pb(mkp(l , r)) ; aoki+=l ; } sort(a.begin() , a.end() , cmp) ; for(int i = 0 ; i<n and aoki>=takashi ; i ++ , ans++){ takashi += a[i].ff + a[i].ss ; aoki -= a[i].ff ; } cout << ans ; } int32_t main() { int t = 1 ; //cin >> t ; while(t--) solve() ; return 0; }
#include<iostream> #include<string> int main() { char S, T; std::cin >> S; std::cin >> T; if (S == 'Y') T = std::toupper(T); std::cout << T << std::endl; return 0; }
#include <bits/stdc++.h> using namespace std; using int128 = __int128_t; using int64 = long long; using int32 = int; using uint128 = __uint128_t; using uint64 = unsigned long long; using uint32 = unsigned int; #define ALL(obj) (obj).begin(),(obj).end() template<class T> using priority_queue_reverse = priority_queue<T,vector<T>,greater<T>>; constexpr int64 MOD = 1'000'000'000LL + 7; //' constexpr int64 MOD2 = 998244353; constexpr int64 HIGHINF = 1'000'000'000'000'000'000LL; constexpr int64 LOWINF = 1'000'000'000'000'000LL; //' constexpr long double PI = 3.1415926535897932384626433L; template <class T> vector<T> multivector(size_t N,T init){return vector<T>(N,init);} template <class... T> auto multivector(size_t N,T... t){return vector<decltype(multivector(t...))>(N,multivector(t...));} template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}} template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;} template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;} template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;} template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;} template <class T>ostream &operator<<(ostream &o, const deque<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;} template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;} void print(void) {cout << endl;} template <class Head> void print(Head&& head) {cout << head;print();} template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);} 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);} vector<string> split(const string &str, const char delemiter) {vector<string> res;stringstream ss(str);string buffer; while( getline(ss, buffer, delemiter) ) res.push_back(buffer); return res;} inline constexpr int msb(int x) {return x?31-__builtin_clz(x):-1;} inline constexpr int64 ceil_div(const int64 a,const int64 b) {return (a+(b-1))/b;}// return ceil(a/b) void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;} void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;} void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;} map<int64,int64> mp; int64 X,Y; int64 dfs(int64 x) { if(mp.count(x)) return mp[x]; if(x == 1) mp[x]=abs(X-x); else if(x%2 == 1) { mp[x] = min({abs(X-x),dfs((x+1)/2)+2,dfs((x-1)/2)+2}); } else if(x%2 == 0) { mp[x] = min({abs(X-x),dfs(x/2)+1}); } return mp[x]; } /** * @url * @est */ int main() { cin.tie(0);ios::sync_with_stdio(false); cin >> X >> Y; mp[X] = 0; int64 ans = dfs(Y); cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define fi first #define se second #define pii pair<long long,long long> #define mp make_pair #define pb push_back #define WTF puts("wtf") string s[3]; ll to[26],p[10]; void solve() { cin>>s[0]>>s[1]>>s[2]; ll cnt=0; for(ll i=0;i<3;i++) { for(ll j=0;j<s[i].size();j++) { char now=s[i][j]; if(!to[now-'a']) cnt++,to[now-'a']=cnt; } } if(cnt>10) { puts("UNSOLVABLE"); return; } else { for(ll i=1;i<=10;i++) p[i]=i; ll n[3]; do { n[0]=n[1]=n[2]=0; for(ll i=0;i<3;i++) for(ll j=0;j<s[i].size();j++) { n[i]*=10; n[i]+=p[to[s[i][j]-'a']]-1; } if(p[to[s[0][0]-'a']]>1&&p[to[s[1][0]-'a']]>1&&p[to[s[2][0]-'a']]>1) { if(n[0]+n[1]==n[2]) { cout<<n[0]<<"\n"<<n[1]<<"\n"<<n[2]; return; } } }while(next_permutation(p+1,p+11)); puts("UNSOLVABLE"); return; } } signed main() { ll _=1; //cin>>_; while(_--) solve(); return 0; }
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<vector> using namespace std; typedef long long LL; const int N = 200010; vector<char> v; int find(char c) { return lower_bound(v.begin(), v.end(), c) - v.begin(); } vector<int> g[3]; int num[10]; bool dfs(int u, int state) { if(u == v.size()) { LL x[3] = {0}; for(int i = 0; i < 3; i ++) for(int j : g[i]) x[i] = x[i] * 10 + num[j]; if(x[0] + x[1] == x[2]) { printf("%lld\n%lld\n%lld\n", x[0], x[1], x[2]); return true; } return false; } for(int i = 0; i < 10; i ++) if(!(state >> i & 1)) { if(!i and (g[0][0] == u or g[1][0] == u or g[2][0] == u)) continue; num[u] = i; if(dfs(u + 1, state | (1 << i))) return true; } return false; } int main() { string s[3]; for(int i = 0; i < 3; i ++) { cin >> s[i]; for(char c : s[i]) v.push_back(c); } sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); if(v.size() > 10) return 0 * puts("UNSOLVABLE"); for(int i = 0; i < 3; i ++) { for(char c : s[i]) g[i].push_back(find(c)); //for(int j : g[i]) printf("%d ", j); puts(""); } if(!dfs(0, 0)) puts("UNSOLVABLE"); return 0; }
#include <cstdio> #include <cstdlib> #include <cmath> #include <climits> #include <cfloat> #include <map> #include <utility> #include <set> #include <iostream> #include <memory> #include <string> #include <vector> #include <algorithm> #include <functional> #include <sstream> #include <complex> #include <stack> #include <queue> #include <cstring> #include <iomanip> #include <cassert> using namespace std; typedef long long ll; int main() { ll A, B; cin >> A >> B; vector<int> primes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71}; vector<ll> dp(1 << 20, 0); dp[0] = 1; for (int i = 0; i < B - A + 1; i++) { ll cur = A + i; int modmask = 0; for (int j = 0; j < 20; j++) { if (cur % primes[j] == 0) { modmask |= (1 << j); } } for (int mask = (1 << 20) - 1; mask >= 0; mask--) { if ((mask & modmask) == 0) { dp[(mask | modmask)] += dp[mask]; } } } ll ans = 0; for (int i = 0; i < (1 << 20); i++) { ans += dp[i]; } cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 1e5+5; ll b,c,ans,t1,t2,t3,t4; int main(){ cin>>b>>c; if(c==1){ if(b==0){ cout<<"1\n"; return 0; }else{ cout<<"2\n"; return 0; } } t1=b-c/2; t2=b+c/2-1; t3=-b-(c-1)/2; t4=-b+(c-1)/2; if(t2<t3||t4<t1){ ans=t2-t1+t4-t3+2; cout<<ans<<'\n'; return 0; } ans=max(t2,t4)-min(t1,t3)+1; cout<<ans<<'\n'; return 0; }
#include<iostream> #include<algorithm> #include<string> #include<vector> #include<cstdlib> #include<queue> #include<set> #include<cstdio> #include<map> #include<cassert> using namespace std; #define ll long long #define reps(i, a, b) for(int i = a; i < b; i++) #define rreps(i, a, b) for(int i = a-1; i >= b; i--) #define rep(i, n) reps(i, 0, n) #define rrep(i, n) rreps(i, n, 0) #define P pair<int, int> #define vec vector<int> #define mat vector<vec> const ll mod = 1000000007; const int INF = 1001001001; struct mint { ll x; mint(ll x=0):x((x%mod+mod)%mod){} mint operator-() const { return mint(-x);} mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { mint res(*this); return res+=a; } mint operator-(const mint a) const { mint res(*this); return res-=a; } mint operator*(const mint a) const { mint res(*this); return res*=a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod-2); } mint& operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res/=a; } }; istream& operator>>(istream& is, const mint& a){ return is >> a.x; } ostream& operator<<(ostream& os, const mint& a){ return os << a.x; } int main(){ int h, w; cin >> h >> w; string s[h]; rep(i, h) cin >> s[i]; // 0: そこ, 1: 縦, 2: 横, 3: 斜め vector<vector<vector<mint> > > dp(h, vector<vector<mint> >(w, vector<mint>(4))); dp[0][0][0] = 1; dp[0][0][1] = 1; dp[0][0][2] = 1; dp[0][0][3] = 1; rep(i, h-1) { if(s[i+1][0] == '#') continue; dp[i+1][0][0] = dp[i][0][1]; dp[i+1][0][1] = dp[i][0][1] + dp[i+1][0][0]; dp[i+1][0][2] = dp[i+1][0][0]; dp[i+1][0][3] = dp[i+1][0][0]; } rep(j, w-1) { if(s[0][j+1] == '#') continue; dp[0][j+1][0] = dp[0][j][2]; dp[0][j+1][1] = dp[0][j+1][0]; dp[0][j+1][2] = dp[0][j][2] + dp[0][j+1][0]; dp[0][j+1][3] = dp[0][j+1][0]; } rep(i, h-1){ rep(j, w-1){ if(s[i+1][j+1] == '#') continue; dp[i+1][j+1][0] = dp[i][j+1][1] + dp[i+1][j][2] + dp[i][j][3]; dp[i+1][j+1][1] = dp[i][j+1][1] + dp[i+1][j+1][0]; dp[i+1][j+1][2] = dp[i+1][j][2] + dp[i+1][j+1][0]; dp[i+1][j+1][3] = dp[i][j][3] + dp[i+1][j+1][0]; } } // rep(i, h){ // rep(j, w){ // cout << dp[i][j][0] << " "; // }cout << endl; // } cout << dp[h-1][w-1][0] << endl; }
#include <bits/stdc++.h> using namespace std; double dp[105][105][105]; int main() { int a, b, c; scanf("%d%d%d", &a, &b, &c); for (int i = 99; i >= 0; i--) { for (int j = 99; j >= 0; j--) { for (int k = 99; k >= 0; k--) { int tot = i + j + k; dp[i][j][k] = (1.0 * i / tot) * (dp[i + 1][j][k] + 1) + (1.0 * j / tot) * (dp[i][j + 1][k] + 1) + (1.0 * k / tot) * (dp[i][j][k + 1] + 1); } } } printf("%.12lf\n", dp[a][b][c]); }
#include"bits/stdc++.h" using namespace std; #define ll long long #define endl "\n" #define fastio ios_base::sync_with_stdio(false) const int lmt=3e5+100; ll a[lmt],n,pre[lmt]; int main(){ fastio; cin>>n; for(int i=1;i<=n;i++){ cin>>a[i]; a[i]=(i%2)?a[i]:-a[i]; } for(int i=1;i<=n;i++){ pre[i]=pre[i-1]+a[i]; } map<ll,ll>cnt; cnt[0]=1; ll ans=0; for(int i=1;i<=n;i++){ ans+=cnt[pre[i]]; cnt[pre[i]]++; } cout<<ans<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef int64_t ll; typedef long double ld; const ll MOD=1000000007; const ll MODA=998244353; ll vx[4]={0,1,0,-1}; ll vy[4]={1,0,-1,0}; #define rep(i,n) for(ll i=0;i<(ll)(n);i++) long long gcd(long long a,long long b){ ll gcdmax=max(a,b); ll gcdmin=min(a,b); while(true){ if(gcdmax%gcdmin==0)break; else gcdmax%=gcdmin; swap(gcdmin,gcdmax); } return gcdmin; } ll pow(ll N,ll P,ll M){ if(P==0)return 1; else if(P%2==0){ ll t=pow(N,P/2,M); return t*t%M; } else return N*pow(N,P-1,M)%M; } vector<ll> find_divisor(ll N){ ll k=1; while(k*k<=N){ k++; } vector<ll> A(1); rep(i,k){ if(i==1)A.at(0)=1; else if(i>=2){ if(N%i==0)A.push_back(i); } } ll t=0; t=A.size(); rep(i,t){ if(A.at(t-i-1)*A.at(t-i-1)!=N)A.push_back(N/A.at(t-1-i)); } return A; } vector<ll> fac; vector<ll> finv; vector<ll> inv; void COMinit(ll N,ll P){ rep(i,N+1){ if(i==0){ fac.push_back(1); finv.push_back(1); inv.push_back(1); } else if(i==1){ fac.push_back(1); finv.push_back(1); inv.push_back(1); } else{ fac.push_back(fac.at(i-1)*i%P); inv.push_back(P-inv.at(P%i)*(P/i)%P); finv.push_back(finv.at(i-1)*inv.at(i)%P); } } } ll COM(ll n,ll k,ll P){ if(n<k)return 0; if(n<0||k<0)return 0; return fac.at(n)*(finv.at(k)*finv.at(n-k)%P)%P; } struct UnionFind { vector<ll> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 UnionFind(ll N) : par(N) { //最初は全てが根であるとして初期化 for(ll i = 0; i < N; i++) par[i] = i; } ll root(ll x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根} if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(ll x, ll y) { // xとyの木を併合 ll rx = root(x); //xの根をrx ll ry = root(y); //yの根をry if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける } bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す ll rx = root(x); ll ry = root(y); return rx == ry; } }; int main(){ ll N; cin>>N; vector<ll> A(N); rep(i,N){ ll a; cin>>a; if(i==0)A.at(i)=a; else if(i%2==0)A.at(i)=A.at(i-1)+a; else A.at(i)=A.at(i-1)-a; } sort(A.begin(),A.end()); ll ans=0; ll count=0; rep(i,N){ if(i==0)count++; else if(A.at(i)==A.at(i-1)){ ans+=count; count++; } else{ count=1; } if(A.at(i)==0)ans++; } cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; #define int long long #define bug(x) cout << #x << " >>>>>>> " << x << '\n' #define _ << " , " << #define Max(a, b) (a > b ? a : b) #define Min(a, b) (a < b ? a : b) #define ii pair<int, int> #define fi first #define se second #define UNTIL(t) while (clock() < (t) * CLOCKS_PER_SEC) #define SZ(a) (int)a.size() const int MAX = 400100; //2 * 10^5 const int MOD = 1000000007; //10^9 + 7 const int OO = 0x3f3f3f3f; // 0x3f3f3f3f; const double EPS = 1e-9; //10^-9 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int score(string str) { int s = 0; map<char, int> c; for(char a : str) c[a]++; for(int i = 1; i < 10; i++) { int j = i, e = c[i + '0']; while(e--) { j *= 10; } s += j; } return s; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); string a, b; int k; cin >> k >> a >> b; map<char, int> cnt; for(char i = '0'; i <= '9'; i++) cnt[i] = k; for(int i = 0; i < 4; i++) cnt[a[i]]--; for(int i = 0; i < 4; i++) cnt[b[i]]--; int ganha = 0, tot = 0; for(char i = '1'; i <= '9'; i++) { for(char j = '1'; j <= '9'; j++) { a.back() = i; b.back() = j; if(!cnt[i] or !cnt[j]) continue; int p = cnt[i]; cnt[i]--; p *= cnt[j]; cnt[i]++; if(score(a) > score(b)) ganha += p; tot += p; } } cout << ((1.0 * ganha) / tot) << endl; return 0; } /* Before submit: Check the corners cases Check solution restrictions For implementation solutions: Check the flow of the variables For intervals problems: Think about two pointers For complete search: Think about cuts If you get WA: Reread your code looking for stupid typos Try various manual testcases Recheck the correctness of your algorithm Reread the statement Write a straightforward solution, create lots of testcases by yourself, and compare both solutions Change the coder (if you're with a team) Give up. You may have other tasks to solve. */
#include<bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define F first #define S second #define pb push_back #define mp make_pair #define mod 1000000007 #define vlli vector<ll> #define vi vector<int> #define vs vector<string> #define vplli vector< pair< ll,ll> > #define plli pair< ll,ll > #define vps vector< pair< string, string> > #define vpi vector< pair< int, int> > #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0) #define forn(i,a,n) for(ll i=a;i<n;i++) #define forr(i,n,a) for(ll i=n-1;i>=a;i--) #define scan(arr,a,n) for(ll i=(a);i<(n);i++)cin>>(arr)[i]; #define print(arr,a,n) for(ll i=(a);i<(n);i++)cout<<(arr)[i]<<" "; const ll inf = 1e18; ll add(ll x, ll y) {ll res = x + y; return (res >= mod ? res - mod : res);} ll mul(ll x, ll y) {ll res = x * y; return (res >= mod ? res % mod : res);} ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + mod : res);} ll power(ll x, ll y) {ll res = 1; x %= mod; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;} ll mod_inv(ll x) {return power(x, mod - 2);} int main(){ fast; #ifndef ONLINE_JUDGE freopen("input1.txt","r",stdin); freopen("output1.txt","w",stdout); #endif ll k; cin>>k; string s, t; cin>>s>>t; ll tt = 9*k - 8; vlli a, b, ca(10, 0), cb(10, 0); forn(i, 0, 4){ a.pb(s[i]-'0'); ca[a[i]]++; b.pb(t[i]-'0'); cb[b[i]]++; } ll c = 0, d = 0; a.pb(0); b.pb(0); forn(i, 1, 10){ if(ca[i]+cb[i]>k){ cout<<"0.0000000"<<endl; return 0; } } forn(i, 1, 10){ if(ca[i]+cb[i]==k){ continue; } a[4]=i; ca[i]++; forn(j, 1, 10){ if(cb[j]+ca[j]==k){ continue; } b[4]=j; ll sa = 0, sb = 0; vlli cca = ca, ccb = cb; ccb[j]++; forn(ii, 1, 10){ sa+=(ii*pow(10, cca[ii])); sb+=(ii*pow(10, ccb[ii])); } if(sa>sb){ // print(a, 0, 5); // print(b, 0, 5); if(i == j){ ll z = k-(ca[i]-1)-cb[i]; c+=(z*(z-1)); } else { c+=(k-ca[i]+1-cb[i])*(k-cb[j]-ca[j]); } } } ca[i]--; } d=(tt*(tt-1)); // cout<<c<<" "<<d<<endl; ld ans = (ld)(c)/(ld)(d); cout<<fixed<<setprecision(10)<<ans<<endl; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> pi; struct edge{ll b,c,d;}; int n; vector<edge>graph[100005]; vector<int>g[100005]; bool v[100005]; void dfs(int cur){ v[cur] = 1; for(int nxt:g[cur]){ if(!v[nxt]) dfs(nxt); } } ll ternary(ll t,ll d){ ll h = sqrt(d); ll ret = d/(t+1); for(ll i = max((ll)0,h-5); i<=h+5; i++){ if(t>=i) continue; ret = min(ret,i-t+d/(i+1)); } return ret; } ll dist[100005]; void dijkstra(int start){ for(int i=1; i<=n; i++) dist[i] = INT64_MAX; dist[start] = 0; priority_queue<pi,vector<pi>,greater<pi> >pq; pq.push(pi(dist[start],start)); while(!pq.empty()){ int cur = pq.top().second; ll d = pq.top().first; pq.pop(); if(dist[cur]<d) continue; if(cur==n) continue; for(edge e : graph[cur]){ int nxt = e.b; ll cc = e.c; ll dd = e.d; ll w = ternary(d,dd); if(dist[nxt]>d+w+cc){ dist[nxt] = d+w+cc; pq.push(pi(dist[nxt],nxt)); } } } } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int m; cin>>n>>m; for(int i=0; i<m; i++){ ll a,b,c,d; cin>>a>>b>>c>>d; graph[a].push_back((edge){b,c,d}); graph[b].push_back((edge){a,c,d}); g[a].push_back(b); g[b].push_back(a); } dfs(1); if(!v[n]){ cout<<-1; return 0; } dijkstra(1); cout<<dist[n]; }
#ifdef MY_LOCAL #define MY_NAMESPACE(ns) namespace ns { #define MY_NAMESPACE_ } #define MY_DEBUG(s) s #define MY_IS_DEBUG (true) #else #define MY_NAMESPACE(ns) #define MY_NAMESPACE_ #define MY_DEBUG(s) #define MY_IS_DEBUG (false) #endif #include <algorithm> #include <bitset> #include <cmath> #include <deque> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <random> #include <set> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; typedef unsigned int uint; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<int, ll> pil; typedef pair<ll, int> pli; typedef pair<ll, ll> pll; constexpr int IMIN = numeric_limits<int>::min(); constexpr int IMAX = numeric_limits<int>::max(); constexpr ll LLMIN = numeric_limits<ll>::min(); constexpr ll LLMAX = numeric_limits<ll>::max(); #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() template <typename T> bool chmax(T& maxval, T const& newval) { if (newval > maxval) { maxval = newval; return true; } return false; } template <typename T> bool chmin(T& minval, T const& newval) { if (newval < minval) { minval = newval; return true; } return false; } MY_NAMESPACE(testbed) int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, m; cin >> n >> m; vector<vector<tuple<int, ll, ll>>> e(n); rep(i, 0, m) { int a, b; ll c, d; cin >> a >> b >> c >> d; a--; b--; e[a].push_back({ b, c, d }); e[b].push_back({ a, c, d }); } auto priority_fn = [](pil const& lhs, pil const& rhs)->bool // return true to prioritize rhs { return (rhs.second < lhs.second); }; vector<ll> min_time(n, LLMAX); priority_queue<pil, vector<pil>, decltype(priority_fn)> q(priority_fn); q.push({ 0, 0 }); min_time[0] = 0; while (!q.empty()) { int this_city; ll this_time; tie(this_city, this_time) = q.top(); q.pop(); if (this_time > min_time[this_city]) continue; fore(edge, e[this_city]) { int next_city = get<0>(edge); ll cval = get<1>(edge); ll dval = get<2>(edge); ll next_time = this_time; if (dval == 0) { next_time += cval; } else { ll min_move = LLMAX; ll wait_time = max((ll)sqrt((double)dval) - 1LL - this_time, 0LL); for (ll adj = -2; adj <= 2; adj++) { ll this_wait_time = max(wait_time + adj, 0LL); ll this_move = this_wait_time + cval + dval / (this_time + this_wait_time + 1LL); chmin(min_move, this_move); } next_time += min_move; } if (chmin(min_time[next_city], next_time)) { q.push({ next_city, next_time }); } } } ll ans = min_time[n - 1]; if (ans == LLMAX) ans = -1; cout << ans << "\n"; return 0; } MY_NAMESPACE_
#include<bits/stdc++.h> using namespace std; #define all(x) (x).begin(),(x).end() #define ll long long #define ld long double #define pb push_back #define FR first #define SC second #define MOD 1000000007 #define LLMN LLONG_MIN #define LLMX LLONG_MAX #define LDMX LDBL_MAX #define LDMN LDBL_MIN #define MAX 1000010 #define pll pair<ll, ll> #define vl vector<ll> #define vll vector< vl > #define vb vector<bool> #define vbb vector< vb > #define vpl vector<pll> #define vpll vector< vpl > void solve() { ll x, y, a, b; cin>>x>>y>>a>>b; ll ans = 0; while(1) { if(x > y / a) break; if(a * x >= y) break; if(a * x > x + b) break; x *= a; ans++; } ans += (y - x - 1) / b; cout<<ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); ll t = 1; //cin>>t; while(t--) { solve(); } return 0; }
#include <bits/stdc++.h> #include <cstdlib> #include <math.h> #include <string> #include <time.h> using ld = long double; using ull = unsigned long long; using ll = long long; using namespace std; int main() { //始点(r1, c1)、終点(r2, c2) int r1, c1, r2, c2; cin >> r1 >> c1 >> r2 >> c2; int r = r2 - r1; int c = c2 - c1; int ans = 3; // absは絶対値 if (!r && !c) { ans = 0; } else if (r == c || r == -c || abs(r) + abs(c) <= 3) { ans = 1; } else if ((r ^ c ^ 1) & 1 || abs(r + c) <= 3 || abs(r - c) <= 3 || abs(r) + abs(c) <= 6) { ans = 2; } cout << ans << endl; }
#include<bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (n); ++i) using namespace std; #define pri(str) cout << str << endl using ll = long long; using P = pair<int, int>; const ll MX = 1e18; const long double PI = acos(-1); 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; } template<class T> inline vector<T> divisor(T n) { vector<T> ret; for (T i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(ret.begin(), ret.end()); return ret; } template<class T> inline vector<pair<T, T>> prime_factor(T n) { vector<pair<T, T>> ret; for (T i = 2; i * i <= n; i++) { if (n % i != 0) continue; T tmp = 0; while (n % i == 0) { tmp++; n /= i; } ret.push_back(make_pair(i, tmp)); } if (n != 1) ret.push_back(make_pair(n, 1)); return ret; } int main() { int n; cin >> n; vector<int> a(n); rep(i, n){cin >> a[i]; a[i]--;} vector<int> b(n); rep(i, n){cin >> b[i]; b[i]--;} vector<int> c(n); rep(i, n){cin >> c[i]; c[i]--;} vector<int> bc(n); rep(i, n) bc[b[c[i]]] += 1; ll count = 0; rep(i, n) { count += bc[a[i]]; } pri(count); return 0; }
#include <bits/stdc++.h> #define ll long long using namespace std; const int N = 1e5 + 10; int a[N], b[N], cnt[N], cnt2[N]; //map<int, int> mp, mp2; 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 int n; cin >> n; for(int i = 1; i <= n; i++){ cin >> a[i]; cnt[a[i]]++; //mp[a[i]]++; } for(int i = 1; i <= n; i++){ cin >> b[i]; } int x; for(int i = 1; i <= n; i++){ cin >> x; cnt2[b[x]]++; //mp2[b[x]]++; } ll ans = 0; for(int i = 1; i <= n; i++){ ans += (cnt[i] * 1LL * cnt2[i]); } cout << ans << '\n'; /* for(auto i: mp){ auto it = mp2.find(i.first); if(it != mp2.end()){ ans += (i * (*it)) << '\n'; } } */ return 0; }
#include <iostream> #include <string> using namespace std; int main(){ long long t, n, max, flag = 0, i, ans; cin >> t >> n; max = 100 * n / t + 1; i = max; while (flag == 0){ if ((100 + t) * i / 100 - ((100 + t) * (i - 1) / 100) == 2){ ans = (100 + t) * i / 100 - 1; flag = 1; } i--; } cout << ans << endl; return 0; }
using namespace std; #include <bits/stdc++.h> #define ll long long ll t,n; int main(){ scanf("%lld%lld",&t,&n); ll c=0; for (int i=1;i<=100;++i) c+=max((t+100)*i/100-(t+100)*(i-1)/100-1,0ll); ll d=(n-1)/c; n-=d*c; for (ll i=d*100+1;i;++i){ ll tmp=max((t+100)*i/100-(t+100)*(i-1)/100-1,0ll);; // printf("%lld %lld\n",i,tmp); if (n>tmp) n-=tmp; else{ printf("%lld\n",(ll)((t/100.0+1)*(i-1))+n); return 0; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int A,B;cin>>A>>B; if(A>B){ cout<<(A-B)/2+B<<" "<<(A-B)/2<<endl; } else{ cout<<(B-A)/2+A<<" "<<((B-A)/2)-((B-A)/2)*2<<endl; } }
#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 = 1e5+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(){ read(n,m,q); pair<int, int> a[n]; // val, wt rep(i,0,n){ read(x,y); a[i] = {y,x}; } sort(a, a+n); reverse(a, a+n); int c[m]; rep(i,0,m){ read(c[i]); } rep(i,0,q){ read(l,r); l--, r--; vector<int>v; for(int i = 0; i < m; ++i){ if(i >= l && i <= r) continue; v.push_back(c[i]); } sort(all(v)); int ans = 0; for(int i = 0; i < n; ++i){ int val = a[i].first, wt = a[i].second; for(int i = 0; i < v.size(); ++i){ if(v[i] == -1) continue; if(wt <= v[i]){ ans += val; v[i] = -1; break; } } } prn(ans); } } 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; }
//Let's join Kaede Takagaki Fan Club !! #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <ctime> #include <cassert> #include <string> #include <algorithm> #include <vector> #include <queue> #include <stack> #include <functional> #include <iostream> #include <map> #include <set> #include <unordered_map> #include <unordered_set> #include <cassert> #include <iomanip> #include <chrono> #include <random> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; #define int long long #define L __int128 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; } #define sz 1 ll F[sz],R[sz]; void make(){ F[0] = 1; for(int i=1;i<sz;i++) F[i] = F[i-1]*i%mod; for(int i=0;i<sz;i++) R[i] = modpow(F[i],mod-2); } ll C(int a,int b){ if(b < 0 || a < b) return 0; return F[a]*R[b]%mod*R[a-b]%mod; } void solve(){ unordered_set<int>ex; int n, m; cin >> n >> m; map<int, vc<int>>M; set<P>black; rep(i, m){ int x,y; cin >> x >> y; M[x].pb(y); black.insert(mp(x, y)); } ex.insert(n); for(auto at:M){ vc<int>v = at.b; vc<int>zan; for(auto k:v){ for(int a=k-1;a<=k+1;a++){ if(ex.find(a) != ex.end()){ zan.pb(a); ex.erase(ex.find(a)); } } } for(auto a:zan){ if(black.find(mp(at.a, a)) == black.end()) ex.insert(a); if(black.find(mp(at.a, a-1)) != black.end()) ex.insert(a-1); if(black.find(mp(at.a, a+1)) != black.end()) ex.insert(a+1); } } o(ex.size()); } signed main(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20); int t; t = 1; //cin >> t; while(t--) solve(); }
#include <algorithm> #include <iostream> #include <map> #include <vector> using namespace std; int main() { long long n, c; cin >> n >> c; vector<long long> ai(n), bi(n), ci(n); for (int i = 0; i < n; i++) { cin >> ai[i] >> bi[i] >> ci[i]; } map<long long, long long> m; for (int i = 0; i < n; i++) { m[ai[i]] += ci[i]; m[bi[i] + 1] -= ci[i]; } vector<long long> d(0), s(0); for (map<long long, long long>::iterator i = m.begin(); i != m.end(); i++) { d.push_back(i->first); s.push_back(i->second); } for (int i = 1; i < static_cast<int>(d.size()); i++) { s[i] += s[i - 1]; } long long res = 0; for (int i = 1; i < static_cast<int>(d.size()); i++) { res += (d[i] - d[i - 1]) * min(s[i - 1], c); } cout << res << endl; }
#include <bits/stdc++.h> using namespace std; int main(){ int count_all_str; string search_str; string tmp; string new_str; cin >> count_all_str >> search_str; for(int i = 1;i <= count_all_str;i++){ cin >> tmp; if(tmp != search_str){ new_str += tmp; new_str += " "; } int size = new_str.size(); if(i == count_all_str && size != 0){ int size = new_str.size(); new_str = new_str.replace(size - 1, 1, ""); } } cout << new_str << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (n); i++) using P = pair<int,int>; using ll = long long; int main() { int n,x; cin >> n >> x; int a[n]; rep(i,n){ cin >> a[i]; } vector<int> ans; rep(i,n){ if(a[i]!=x){ ans.push_back(a[i]); } } rep(i,ans.size()){ if(i==ans.size()-1){ cout << ans.at(i); } else{ cout << ans.at(i) << ' '; } } cout<< endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N,S,D; int A=0; vector<int> X(N); vector<int> Y(N); vector<int> CX(N); vector<int> CY(N); cin >> N >> S >> D; for (int i=0; i<N; i++){ cin >> X.at(i) >> Y.at(i); } for (int i=0; i<N; i++){ CX.at(i) = S - X.at(i); CY.at(i) = D - Y.at(i); } for (int i=0; i<N; i++){ if(CX.at(i)>0 && CY.at(i)<0 ){ A = 1; cout << "Yes" << endl; break; } } if (A==0){ cout << "No" << endl; } }
#include <bits/stdc++.h> using namespace std; #define all(v) v.begin(),v.end() #define MP make_pair #define MT make_tuple typedef int64_t ll; #define PA pair<ll,ll> #define TU tuple<ll,ll,ll> #define vi vector<ll> #define vii vector<vector<ll> > #define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++) #define rep2(i,m,n) for(ll (i)=(m); (i)<(ll)(n); (i)++) const ll INF = 1ll<<30; const ll INF2 = 1ll<<32; int main() { ll n; string s,x; cin >>n>>s>>x; vi v(n); rep(i,n) v.at(i) = s.at(i)-'0'; //iターン終了時にmod7でjと合同であるとき高橋くんが勝つならtrue vector<vector<bool>> dp(n+1,vector<bool>(7,false)); dp.at(n).at(0) = true; vi mod_pow_10 = {1,3,2,6,4,5}; //mod_pow_10.at((n-1-i)%6) for(ll i=n-1; i>=0; i--) { rep(j,7) { if(x.at(i)=='T') { if( dp.at(i+1).at((ll)(j%7)) || dp.at(i+1).at((ll)((j+v.at(i)* mod_pow_10.at((n-1-i)%6) )%7)) ) dp.at(i).at(j) = true; } if(x.at(i)=='A') { if( dp.at(i+1).at((ll)(j%7)) && dp.at(i+1).at((ll)((j+v.at(i)* mod_pow_10.at((n-1-i)%6) )%7)) ) dp.at(i).at(j) = true; } } } if(dp.at(0).at(0)) cout <<"Takahashi" << endl; else cout <<"Aoki" << endl; }
#include<bits/stdc++.h> using namespace std; #define en '\n' #define endl '\n' #define ll long long signed #define pb push_back #define append push_back #define all(v) (v).begin(),(v).end() #define FOR(i,a,b,k) for(int i=a; k>0?i<b:i>b; i+=k) #define fori(a) for(int i=0; i<a; i++) #define forj(a) for(int j=0; j<a; j++) #define fork(a) for(int k=0; k<a; k++) #define MOD 1000000007 #define MAX 1000010 #define mset(a,s,k) memset(a,k,s*sizeof(a[0])) #define ff first #define ss second #define __ <<" "<< #define _ <<en ll pow_(ll a,ll e,ll m=MOD){ll r=1;while(e){if(e&1)r=r*a%m;a=a*a%m;e>>=1;}return r;} int inv(ll a) {return int(pow_(a,MOD-2,MOD));}int add(ll a, ll b){return (a+b+MOD)%MOD;} int mul(ll a, ll b) {return (MOD+a*b%MOD)%MOD;}int di(ll a, ll b){return mul(a,inv(b));}ll ceil(ll a,ll b){return a/b+(a%b!=0);} template<typename T1,typename T2>ostream&operator<<(ostream&O,pair<T1,T2>a){O<<"( ";O<<a.ff<<", "<<a.ss;O<<" )";return O;} template<typename T>ostream&operator<<(ostream&O,vector<T>V){O<<"[ ";fori(V.size())O<<V[i]<<(i==V.size()-1?"":", ");O<<" ]";return O;} template<typename T>ostream&operator<<(ostream&O,set<T>S){O<<"{ ";for(T i:S)O<<i<<", ";O<<" }";return O;} template<typename T1,typename T2>ostream&operator<<(ostream&O,map<T1,T2>S){O<<"{ ";for(auto i:S)O<<i<<", ";O<<" }";return O;} template<typename T=int>class print{public:vector<T>V;print(vector<T>v){V=v;cout<<" <"<<V<<"> ";} print(T*x,int N){fori(N)V.push_back(x[i]);cout<<" <"<<V<<"> ";}friend ostream&operator<<(ostream&O,print p){return O;}}; #define vi vector<int> #define tp pair<int,int> ll A[MAX],B[MAX], vis[MAX]; int N,M; void reset(); vector<int> G[MAX]; ll dfs(int x){ if(vis[x]) return 0; vis[x]=1; ll r=0; for(auto i: G[x]){ r+=dfs(i); } return r+A[x]-B[x]; } int solve(){ cin>>N>>M; reset(); fori(N){ cin>>A[i];} fori(N){ cin>>B[i];} fori(M){ int a,b; cin>>a>>b; a--; b--; G[a].push_back(b); G[b].push_back(a); } fori(N) if(dfs(i)) return 0; return 1; } void reset(){ fori(N) G[i].clear(); fori(N) vis[i]=0; // Clear Vectors, maps, sets // Set default values of arr } signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t=1; while(t--){ // solve(); // cout<<solve()<<en; cout<<(solve()?"Yes":"No")<<endl; } return 0; }
#include <cstdio> #include <cstdlib> using namespace std; #define ll long long const ll MAXN = 400011; struct fhqTreap { ll tot, rt; ll val[MAXN], sum[MAXN], sz[MAXN], ls[MAXN], rs[MAXN], rd[MAXN]; void pushup(ll u) {sz[u] = sz[ls[u]] + sz[rs[u]] + 1; sum[u] = sum[ls[u]] + sum[rs[u]] + val[u];} void split(ll u, ll k, ll &x, ll &y) { if(!u) {x = y = 0; return;} if(val[u] <= k) x = u, split(rs[u], k, rs[u], y); else y = u, split(ls[u], k, x, ls[u]); pushup(u); } ll merge(ll u, ll v) { if(!u || !v) return u | v; if(rd[u] < rd[v]) {rs[u] = merge(rs[u], v); pushup(u); return u;} else {ls[v] = merge(u, ls[v]); pushup(v); return v;} } ll add(ll k) { rd[++tot] = rand(); sz[tot] = 1; val[tot] = sum[tot] = k; return tot; } void insert(ll k) { ll x, y; split(rt, k, x, y); rt = merge(merge(x, add(k)), y); } ll cb(ll k) { ll x, y; split(rt, k, x, y); ll ans = sz[x] * k + sum[y]; rt = merge(x, y); return ans; } void delet(ll k) { ll x, y, z; split(rt, k, x, z); split(x, k - 1, x, y); y = merge(ls[y], rs[y]); rt = merge(merge(x, y), z); } } t[2]; ll q; ll len[2]; ll w[2][MAXN]; 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*10+C-'0'; C = getchar();} return X * F; } int main() { ll ans = 0; len[1] = read(); len[0] = read(); q = read(); for(ll i = 0; i < 2; ++i) for(ll j = 1; j <= len[i]; ++j) t[i].rt = t[i].merge(t[i].rt, t[i].add(0)); for(ll i = 1, opt, x, y; i <= q; ++i) { opt = (read() & 1); x = read(); y = read(); t[opt].delet(w[opt][x]); t[opt].insert(y); ans -= t[opt^1].cb(w[opt][x]); w[opt][x] = y; ans += t[opt^1].cb(w[opt][x]); printf("%lld\n", ans); } return 0; }
#include "bits/stdc++.h" #define MOD 1000000007 #define rep(i, n) for(ll i=0; i < (n); i++) #define rrep(i, n) for(ll i=(n)-1; i >=0; i--) #define ALL(v) v.begin(),v.end() #define rALL(v) v.rbegin(),v.rend() #define FOR(i, j, k) for(ll i=j;i<k;i++) #define debug_print(var) cerr << #var << "=" << var <<endl; #define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" " #define fi first #define se second using namespace std; typedef long long int ll; typedef vector<ll> llvec; typedef vector<double> dvec; typedef pair<ll, ll> P; typedef long double ld; struct edge{ll x, c, k;}; ll mod(ll a, ll mod){ ll res = a%mod; if(res<0)res=res + mod; return res; } ll modpow(ll a, ll n, ll mod){ ll res=1; while(n>0){ if(n&1) res=res*a%mod; a=a*a%mod; n>>=1; } return res; } ll modinv(ll a, ll mod){ ll b=mod, u=1, v=0; while(b){ ll t=a/b; a-=t*b; swap(a, b); u-=t*v; swap(u, v); } u%=mod; if(u<0)u+=mod; return u; } ll gcd(ll a, ll b){ ll r = a%b; if(r==0) return b; else return gcd(b, a%b); } bool is_prime(ll n){ ll i = 2; if(n==1)return false; if(n==2)return true; bool res = true; while(i*i <n){ if(n%i==0){ res = false; } i = i+1; } //if(i==1)res = false; if(n%i==0)res=false; return res; } struct dijkstra{ ll N; llvec d; vector<vector<edge>> e; dijkstra(ll n){ N = n; //d = llvec(N, 1e18); e = vector<vector<edge>>(N); } void add_edge(ll from, ll to, ll cost, ll k){ e[from].push_back({to, cost, k}); } void run(ll start){ priority_queue<P, vector<P>, greater<P>> que; que.push({0, start}); d = llvec(N, 1e18); d[start]=0; while(!que.empty()){ P q = que.top();que.pop(); ll dc = q.first; ll x = q.second; if(dc>d[x]){ continue; }else{ for(auto ip: e[x]){ if(d[ip.x]<=((d[x]+ip.k-1)/ip.k) * ip.k +ip.c){ continue; }else{ d[ip.x]= ((d[x]+ip.k-1)/ip.k) * ip.k +ip.c; que.push({d[ip.x], ip.x}); } } } } } }; /************************************** ** A main function starts from here ** ***************************************/ int main(){ ll N, M, X, Y; cin >> N >> M >> X >> Y; dijkstra dijk(N); X--;Y--; rep(i, M){ ll a, b, c, d; cin >> a >> b >> c >> d; a--;b--; dijk.add_edge(a, b, c, d); dijk.add_edge(b, a, c, d); } dijk.run(X); ll ans = dijk.d[Y]; if(ans>1e15)ans=-1; cout << ans<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define gc getchar_unlocked #define ll long long #define PI 3.1415926535897932384626 #define si(x) scanf("%d", &x) #define sl(x) scanf("%lld", &x) #define ss(s) scanf("%s", s) #define pi(x) printf("%d\n", x) #define pl(x) printf("%lld\n", x) #define ps(s) printf("%s\n", s) #define br printf("\n") #define fo(i, n) for(i=0;i<n;i++) #define Fo(i, k, n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1) #define deb(x) cout << #x << " = " << x << endl; #define deb2(x, y) cout << #x << " = " << x << ", " << #y << " = " << y << endl #define deba(i, a, n) fo(i, n){cout << a[i] << " ";} #define pb push_back #define mp make_pair #define F first #define S second #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define clr(x) memset(x, 0, sizeof(x)) #define sortall(x) sort(all(x)) #define tr(it, x) for(auto it = x.begin(); it != x.end(); it++) #define trr(it, x) for(auto it = x.rbegin(); it != x.rend(); it+) 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; mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count()); int rng(int lim) { uniform_int_distribution<int> uid(0,lim-1); return uid(rang); } const int mod = 1000000007; const int N = 3e5; bool comp(int a, int b) { return (a < b); } int getIndex(vector<int> v, int K) { auto it = find(v.begin(), v.end(), K); if (it != v.end()) { int index = it - v.begin(); return index; } else { return -1; } } /* ========== SOLUTION ========= */ void solution() { string s; cin>>s; reverse(s.begin(), s.end()); for (int i = 0; i < s.length(); ++i) { if (s[i] == '6') { s[i] = '9'; } else if (s[i] == '9') { s[i] = '6'; } } cout<<s; } /* ========== SOLUTION ========= */ int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); srand(chrono::high_resolution_clock::now().time_since_epoch().count()); // freopen("input.txt", "r", stdin); // freopen("error.txt", "w", stderr); // freopen("output.txt", "w", stdout); solution(); cout<<"\n"; // int t=1; // cin>>t; // while(t--) { // solution(); // cout<<endl; // } return 0; }
#include <bits/stdc++.h> #include <vector> #include <iostream> #include<algorithm> #include<string> #include <map> #include <queue> #include <stack> #include<set> #include<tuple> #include<time.h> #include<list> #define DIV 998244353 using namespace std; using ll = long long; using ldb = long double; int main() { string s; cin >> s; vector<int> cnt(10); int len = s.size(); for (int i = 0; i < len; i++) { cnt[s[i] - '0']++; } if (len == 1) { if (cnt[8] == 1) cout << "Yes" << endl; else cout << "No" << endl; } else if (len == 2) { bool flag = false; for (int i = 0; i < 100; i += 8) { vector<int> ned(10); int temp = i; ned[temp % 10]++; temp /= 10; ned[temp % 10]++; bool hachi = true; for (int j = 0; j <= 9; j++) { if (cnt[j] < ned[j]) { hachi = false; break; } } if (hachi) { flag = true; break; } } if (flag) cout << "Yes" << endl; else cout << "No" << endl; } else { bool flag = false; for (int i = 0; i <= 1000; i += 8) { vector<int> ned(10); int temp = i; ned[temp % 10]++; temp /= 10; ned[temp % 10]++; temp /= 10; ned[temp % 10]++; bool hachi = true; for (int j = 0; j <= 9; j++) { //printf("ned[%d]=%d\n", j, ned[j]); if (cnt[j] < ned[j]) { hachi = false; break; } } if (hachi) { flag = true; //cout << "i=" << i << endl; break; } } if (flag) cout << "Yes" << endl; else cout << "No" << endl; } }
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (int)(n); ++i) using namespace std; using ll = long long; int main() { int n; cin >> n; bool ans = true; int ok[200][200] = {}; vector<int> a(n), b(n); vector<int> h(n * 2); rep(i, n) { cin >> a[i] >> b[i]; a[i]--; b[i]--; if (a[i] != -2 && b[i] != -2 && a[i] >= b[i]) ans = false; } rep(i, n) { if (a[i] != -2 && b[i] == -2) { if (h[a[i]] != 0) ans = false; h[a[i]] = 1; } if (b[i] != -2 && a[i] == -2) { if (h[b[i]] != 0) ans = false; h[b[i]] = -1; } if (a[i] != -2 && b[i] != -2) { if (h[a[i]] != 0 || h[b[i]] != 0) ans = false; h[a[i]] = 2; h[b[i]] = -2; ok[a[i]][b[i]] = 1; } } // h[i] = -2,-1,0,1,2 rep(i, n * 2) rep(j, i){ // j < i if (ok[j][i] == 1) continue; if (h[i] == 0 && h[j] == 0) continue; if (h[i] == -1 && h[j] == 0) continue; if (h[i] == 0 && h[j] == 1) continue; ok[j][i] = -1; } if (!ans) { cout << "No" << endl; return 0; } // 7,10,17,19,28,32 // last = 0,2,4,6,... // i = 1,3,5,7,... vector<int> ed; ed.push_back(0); for (int i = 1; i < n * 2; i += 2) { for (int last : ed) { int mid = (i + last + 1) / 2; bool check = true; for (int j = mid; j <= i; j++) { if (ok[last + j - mid][j] == -1) check = false; } if (check) { ed.push_back(i + 1); break; } } } if (ed[ed.size() - 1] == n * 2) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
#include <bits/stdc++.h> #if __has_include(<atcoder/all>) #include <atcoder/all> using namespace atcoder; #endif using namespace std; using Graph = vector<vector<int>>; using Grid= vector<string>; using vin= vector<int>; using ll=long long; using ull=unsigned long long; using vll= vector<ll>; using vbl=vector<bool>; using vch=vector<char>; using P=pair<int ,int>; //const long double pi=acos(-1); #define ft first #define sd second #define fn front #define pb push_back #define eb emplace_back #define it insert #define si(v) int((v).size()) #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rell(i,n) for (ll i=0; i< (ll)(n); i++) #define sot(x) sort(x.begin(), x.end()) #define rese(x) reverse(x.begin(), x.end()) #define vnn(x,y,s,name) vector<vector<int>> name(x, vector<int>(y,s)) #define mse(x) memset(x, 0, sizeof(x)) #define mii(x,y,z) min(x,min(y,z)) #define maa(x,y,z) max(x,max(y,z)) #define cps CLOCKS_PER_SEC #define yes cout<<"Yes"<<"\n" #define no cout<<"No"<<"\n" #define cset(x) cout<<fixed<<setprecision(x) //const int INF=1001001001; //998244353 1000000007 int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin>>n; vin x(n),y(n); rep(i,n) cin>>x[i]>>y[i]; int cnt=0; rep(i,n){ for(int j=i+1;j<n;j++){ if(abs((y[j]-y[i]))<=abs((x[j]-x[i]))) cnt++; } } cout<<cnt<<endl; }
#include <bits/stdc++.h> using namespace std; const int N = 2010; int X[N], Y[N]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d%d", &X[i], &Y[i]); int res = 0; for (int i = 1; i <= n; i++) for (int j = i + 1; j <= n; j++) if (X[i] != X[j]) { double k = (Y[j] - Y[i]) / (double)(X[j] - X[i]); if (-1 <= k && k <= 1) res++; } printf("%d\n", res); }
// //#pragma GCC optimize("Ofast") //#pragma GCC target("avx,avx2,fma") //#pragma GCC optimization ("unroll-loops") // //#pragma GCC optimize(3,"Ofast","inline") //#include<unordered_map> //#include<unordered_set> #include<cstdio> #include<iostream> #include<cmath> #include<functional> #include<cstring> #include<string> #include<cstdlib> #include<queue> #include<map> #include<algorithm> #include<set> #include<stack> #include<vector> #include<sstream> #include<list> using namespace std; typedef long long ll; const int INF=0x3f3f3f3f; int mod=104857601; const int maxn=2e6+5; int k[maxn]; int main() { int n,a,b,ma=0,mb=0; cin>>n; n=1<<n; for(int i=1;i<=n;i++) { cin>>k[i]; } n/=2; for(int i=1;i<=n;i++) { if(ma<k[i]) { ma=k[i]; a=i; } } n*=2; for(int i=n/2+1;i<=n;i++) { if(mb<k[i]) { mb=k[i]; b=i; } } if(k[a]>k[b])cout<<b; else cout<<a; return 0; }
#include <bits/stdc++.h> #define ll long long #define pb push_back #define mp make_pair #define PI 2*acos(0.0) using namespace std; #define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int main() { optimize(); ll n; cin >> n; ll m=pow(2,n); ll ar[m]; for(int i=0; i<m; i++) cin >> ar[i]; ll mx1=*max_element(ar,ar+(m/2)); ll mx2=*max_element(ar+(m/2),ar+m); ll k=min(mx1,mx2); for(int i=0; i<m; i++) if(ar[i]==k) { cout << i+1 << endl; break; } }
#include<bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);++i) using namespace std; typedef long long ll; int main() { char s,t; cin >> s>> t; char ans; if (s == 'Y') { ans = t - ('a' - 'A'); cout << ans << endl; } if(s == 'N') cout << t << endl; return 0; }
// #pragma GCC optimize("O3") // #pragma comment(linker, "/stack:200000000") // #pragma GCC optimize("Ofast") // #pragma GCC optimization ("unroll-loops") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <array> #include <cassert> #include <cstdio> #include <cstring> #include <iostream> #include<climits> #include <iomanip> #include <string> #include <sstream> #include <vector> #include <queue> #include <stack> #include <list> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <algorithm> #include <complex> #include <cmath> #include <numeric> #include <bitset> #include <functional> #include <random> #include <ctime> #include <chrono> using namespace std; #define ld long double #define int long long #define pii pair<int,int> #define pb push_back #define endl '\n' #define pi acos(-1) #define init(x,a) memset(x,a,sizeof(x)) #define all(c) c.begin(),c.end() int const mod1 = 998244353; int const mod = 1e9 + 7; int const hashmod = 1610612741; #define bitcount(x) __builtin_popcountll(x) #define l first #define r second const int inf = LLONG_MAX; int toint(const string &s) {stringstream ss; ss << s; int x; ss >> x; return x;} string tostring ( int number ) {stringstream ss; ss << number; return ss.str();} #define trace1(x) cerr<<#x<<": "<<x<<endl #define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl #define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl #define haha ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); // * Using PBDS * /*typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> os; */ struct cmp { bool operator() (pii a, pii b) { return (a.l < b.l); } }; int modexp(int x, int n) { if (n == 0) { return 1; } else if (n & 1) { return (modexp((x * x) % mod, n / 2) % mod * x % mod) % mod; } else { return (modexp((x * x) % mod, n / 2) % mod); } } int modinv(int n) { return modexp(n, mod - 2) % mod; } int gcd(int a, int b) { if (b == 0) { return a; } return gcd(b, a % b); } bool comp2(pair<pii, int> a, pair<pii, int> b) { if (a.l.l == b.l.l) return a.r < b.r; return (a.l.l < b.l.l ); } bool comp1(pii a, pii b) { return a.l < b.l; } signed main() { haha #ifndef ONLINE_JUDGE freopen("inp3.txt", "r", stdin); freopen("out2.txt", "w", stdout); #endif char c, t; cin >> c >> t; if (c == 'Y') { cout << (char)toupper(t); } else cout << (char)t; }
#include <queue> #include <vector> #include <iostream> #include <utility> using namespace std; using ll = int64_t; using pll = pair<ll,ll>; int main() { ll a,b,X,Y; cin >> a >> b >> X >> Y; a--; b--; // 0-99: A // 100-199: B vector<vector<pll>> E(200, vector<pll>{}); for(ll i=0; i<100; i++) { E[i].push_back(make_pair(100+i, X)); E[100+i].push_back(make_pair(i, X)); } for(ll i=0; i<99; i++) { E[i+1].push_back(make_pair(100+i, X)); E[i+100].push_back(make_pair(1+i, X)); } for(ll i=0; i<99; i++) { E[i].push_back(make_pair(i+1, Y)); E[i+1].push_back(make_pair(i, Y)); E[100+i].push_back(make_pair(101+i, Y)); E[101+i].push_back(make_pair(100+i, Y)); } vector<int> SEEN(200, false); priority_queue<pll,vector<pll>,greater<pll>> Q; Q.push(make_pair(0, a)); while(!Q.empty()) { pll dx = Q.top(); Q.pop(); ll x = dx.second; if(SEEN[x]) { continue; } SEEN[x] = true; if(x==100+b) { cout << dx.first << endl; return 0; } for(pll e : E[x]) { Q.push(make_pair(dx.first+e.second, e.first)); } } }
#include<iostream> #include<cstring> #include<cstdio> using namespace std; int main(){ int a, b, x, y; cin >> a >> b >> x >> y; int ans = 0; if(a == b){ printf("%d\n",x); }else if(a < b){ ans += x; ans += min(2 * x, y) * (b - a); printf("%d\n",ans); }else{ ans += x; ans += min(2 * x, y) * (a - b - 1); printf("%d\n",ans); } return 0; }