code_file1
stringlengths
87
4k
code_file2
stringlengths
85
4k
#include "bits/stdc++.h" using namespace std; #define all(c) c.begin(),c.end() #define sz(x) int(x.size()) #define ar array typedef long long ll ; typedef vector<int> vi; #define mod 1000000007 ll exp(ll x,ll y){ x%=mod; ll res=1; while(y){ if(y&1) res=res*x%mod; x=x*x%mod; y>>=1; } return res; } ll fact(ll n){ ll res=1; for(ll i=2;i<=n;++i) (res*=i)%=mod; return res; } bool isprime(ll n){ for(ll i=2;i*i<=n;++i) if(n%i==0) return 0; return 1; } map<ll,ll>mp1,mp2; ll f1(ll x,ll y){ if(y<=x) { return abs(x-y); } if(mp1.count(y)) return mp1[y]; ll ans1=0,ans2=0; if(y%2) { ans1+=2+f1(x,(y-1)/2); ans2+=2+f1(x,(y+1)/2); return mp1[y]=min(ans1,ans2); } else return mp1[y]=1+f1(x,y/2); } ll f2(ll x,ll y){ if(y<=2*x) { return abs(x-y); } if(mp2.count(y)) return mp2[y]; ll ans1=0,ans2=0; if(y%2) { ans1+=2+f2(x,(y-1)/2); ans2+=2+f2(x,(y+1)/2); return mp2[y]=min(ans1,ans2); } else return mp2[y]=1+f2(x,y/2); } int main() { //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll x,y; cin>>x>>y; cout<<min(f1(x,y),f2(x,y)); return 0; }
#include <bits/stdc++.h> #define rep(i, n) for(int i = 0; i < n; i++) using namespace std; typedef long long ll; const int INF = 1 << 30; const ll LLINF = 1LL << 60; int mod = 1000000007; int main(void){ ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vector<ll> A(N); rep(i, N) cin >> A[i]; vector<ll> B(N, 0); rep(i, N-1) B[i+1] = B[i] + A[i+1]*(i+1); ll mx = -1, sum = 0; for(ll k = 1; k <= N; k++){ mx = max(mx, A[k-1]); sum += A[k-1]; cout << k*(mx + sum) - B[k-1] << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef std::vector<std::vector<int64_t> > Graph; #define rep(i, n) for (int64_t i = 0; i < n; ++i) #define rep2(i, n) for (int64_t i = 1; i <= n; ++i) #define repb(i, l, n) for (int64_t i = l; i < n; ++i) #define repb2(i, l, n) for (int64_t i = l; i <= n; ++i) #define repc(i, l, n, d) for (int64_t i = l; i < n; i+=d) #define repc2(i, l, n, d) for (int64_t i = l; i <= n; i+=d) #define repe(a, b) for (auto&(a) : (b)) #define ALL(v) (v).begin(), (v).end() #define Sort(x) sort(ALL(x)) #define Sort_rev(x) Sort(x);reverse(ALL(x)) #define mp(a, b) make_pair((a), (b)) #define Push_back(a, b) push_back( mp( (a), (b) ) ) #define ctoi(c) (c)-'0' template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } template<typename V,typename T> bool find_num(V v, T num) { if ( find(ALL(v), num) == v.end() ) { return false; } return true; } const int inf = 0x3fffffff; const int64_t INF = 0x3fffffffffffffff; const int64_t MOD = 1e9+7; int main() { int64_t n; cin >> n; std::vector<int64_t> x(n), y(n); rep(i, n) { cin >> x[i] >> y[i]; } int64_t ans = 0; rep(i, n-1) { repb(j, i+1, n) { // if ( x[i] <= x[j] ) { if ( y[i]-abs(x[j]-x[i]) <= y[j] && y[j] <= y[i]+abs(x[j]-x[i]) ) { ++ans; } // } else { // } } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define rrep(i, n) for(int i = 1; i <= (int)(n); i++) #define drep(i, n) for(int i = (n)-1; i >= 0; i--) #define ALL(x) (x).begin(), (x).end() #define dup(x,y) (((x)+(y)-1)/(y)) #define srep(i,s,t) for (int i = s; i < t; ++i) using namespace std; typedef long long ll; typedef pair<int, int> P; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; const ll LINF = 1001002003004005006ll; const int INF = 1001001001; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const int mod = 1000000007; // const int mod = 998244353; int main() { int n; cin >> n; vector<int> x(n), y(n), z(n); rep(i, n) cin >> x[i] >> y[i] >> z[i]; int n2 = 1<<n; vvi dp(n2, vi(n, INF)); vvi dist(n, vi(n)); rep(i, n) rep(j, n) { int now = abs(x[j] - x[i]); now += abs(y[j] - y[i]); now += max(0, z[j] - z[i]); dist[i][j] = now; } rep(i, n) { if (i == 0) continue; dp[1<<i][i] = dist[0][i]; } rep(i, n2) rep(j, n) { if (~i>>j&1) continue; rep(k, n) { if (i>>k&1) continue; chmin(dp[i|1<<k][k], dp[i][j] + dist[j][k]); } } cout << dp[n2-1][0] << endl; }
# include <bits/stdc++.h> # define N 110 int a[N]; bool f[N][100010]; int main() { int n,i,j,sum=0; scanf("%d",&n); for(i=1;i<=n;i++) scanf("%d",a+i), sum+=a[i]; f[0][0]=true; for(i=0;i<n;i++) { for(j=0;j<=100000;j++) { if(f[i][j]) f[i+1][j+a[i+1]]=true, f[i+1][j]=true; } } int mid=(sum+1)/2; for(j=mid;!f[n][j];j++); printf("%d\n",j); return 0; }
/* @uthor: Amit Kumar user -->GitHub: drviruses ; CodeChef: dr_virus_ ; Codeforces,AtCoder,Hackerearth,Hakerrank: dr_virus; */ #include <bits/stdc++.h> #include <chrono> using namespace std; using namespace std::chrono; //#include <boost/multiprecision/cpp_int.hpp> //namespace mp = boost::multiprecision; //#define ln mp::cpp_int; #define int long long #define double long double #define uint unsigned long long #define all(vec) vec.begin(),vec.end() #define endl "\n" int google_itr = 1; #define google(x) cout<<"Case #"<<x<<": " #define pi 3.14159265358979323846264338327950L vector<string> vec_splitter(string s) { s += ','; vector<string> res; while(!s.empty()) { res.push_back(s.substr(0, s.find(','))); s = s.substr(s.find(',') + 1); } return res; } void debug_out( vector<string> __attribute__ ((unused)) args, __attribute__ ((unused)) int idx, __attribute__ ((unused)) int LINE_NUM) { cerr << endl; } template <typename Head, typename... Tail> void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) { if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") "; stringstream ss; ss << H; cerr << args[idx] << " = " << ss.str(); debug_out(args, idx + 1, LINE_NUM, T...); } #define XOX #ifdef XOX #define deb(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__) #else #define deb(...) 42 #endif const int mod = 1e9+7; const int inf = 1e18; unordered_set<string> seen; int res = INT_MAX; void minimumTimeRequired(vector<int>& jobs, int k, int start, vector<int>& assigned, int prefer) { // make a copy of the assignment, and use it to calculate the cache key and the workload of the worker with heaviest workload vector<int> a = assigned; sort(a.begin(), a.end()); string key = ""; int heaviest = 0; for (int num: a) { heaviest = max(heaviest, num); key += to_string(num) + "_"; } // pruning trick 2 if (heaviest > res) return; // pruning trick 1 if(seen.find(key)!=seen.end()) return; seen.insert(key); if (start >=(int) jobs.size()) { // Found a possible assignment, check to see if it's better than what we have seen int sln = 0; for (int i=0; i<assigned.size(); i++) { sln = max(sln, assigned[i]); } res = min(res, sln); return; } unordered_set<int> tried; for (auto j=0; j<assigned.size(); j++) { int i = (j + prefer) % k; if (tried.find(assigned[i]) != tried.end()) continue; tried.insert(assigned[i]); assigned[i] += jobs[start]; // pruning trick 3: force the next iteration to try to do assignments from the next worker minimumTimeRequired(jobs, k, start+1, assigned, prefer+1); assigned[i] -= jobs[start]; } } void virus(){ int n, ans = 0; cin >> n; vector <int> arr(n); for(auto &i:arr) cin >> i; vector<int> assigned(2); sort(all(arr), greater <int>()); minimumTimeRequired(arr, 2, 0, assigned, 0); cout << res << endl; } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); /*#ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif*/ int t = 1; //cin >> t; while(t--){ auto start = system_clock::now(); virus(); auto stop = system_clock::now(); duration<double> duration = (stop - start); //cerr << "\nTime: "<< fixed << setprecision(10) << (double)duration.count() <<"sec"<< endl; //your code goes here } return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; template<typename T> ostream& operator<<(ostream &os, vector<T> &v){ string sep = " "; if(v.size()) os << v[0]; for(int i=1; i<v.size(); i++) os << sep << v[i]; return os; } template<typename T> istream& operator>>(istream &is, vector<T> &v){ for(int i=0; i<v.size(); i++) is >> v[i]; return is; } #ifdef DBG void debug_(){ cout << endl; } template<typename T, typename... Args> void debug_(T&& x, Args&&... xs){ cout << x << " "; debug_(forward<Args>(xs)...); } #define dbg(...) debug_(__VA_ARGS__) #else #define dbg(...) #endif int main() { ios_base::sync_with_stdio(false); cout << setprecision(20) << fixed; int n; cin >> n; vector<int> a(n), b(n); cin >> a >> b; cout << max(0, *min_element(b.begin(), b.end()) - *max_element(a.begin(), a.end()) + 1) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long template <typename T> void print(T a, string message = "debug: "); template <typename T> void printvec(vector<T> a, string message = "debug: "); int n; vector<int> a, b; int main() { cin >> n; a.resize(n); b.resize(n); int amin = 0, bmax = 1000; for (int i = 0; i < n; i++) { cin >> a[i]; if (amin < a[i]) { amin = a[i]; } } for (int i = 0; i < n; i++) { cin >> b[i]; if (bmax > b[i]) { bmax = b[i]; } } if (bmax - amin + 1 > 0){ cout << bmax - amin + 1 << endl; }else{ cout << 0 << endl; } return 0; } template <typename T> void print(T a, string message) { cout << message << a << endl; } template <typename T> void printvec(vector<T> a, string message) { for (ll i = 0; i < a.size(); i++) { cout << message << "[" << i << "]: " << a[i] << endl; } }
//#pragma GCC optimize(2) #include<bits/stdc++.h> #define CT printf("\n-------------------------\n"); using namespace std; typedef long long ll; const int inf=0x3f3f3f3f; const ll Inf=1ll<<60ll; typedef pair<int,int> pii; const int N=100005; priority_queue<pii,vector<pii>,greater<pii> > q[26]; int n,dp[N]; char s[N]; int main(){ // freopen(".in","r",stdin); // freopen(".out","w",stdout); scanf("%d",&n); scanf("%s",s+1); memset(dp,0x3f,sizeof(dp)); dp[0]=0; for(int i=0;i<=n;++i){ for(int j=0;j<26;++j){ if(q[j].empty()||j==s[i]-'a')continue; pii tmp=q[j].top(); dp[i]=min(dp[i],dp[tmp.second]+1); } if(i==n)break; q[s[i+1]-'a'].push(make_pair(dp[i],i)); } if(dp[n]==inf){puts("-1");return 0;} printf("%d\n",dp[n]); // fclose(stdin);fclose(stdout); return 0; }
#include <bits/stdc++.h> using namespace std; #define all(hoge) (hoge).begin(), (hoge).end() #define en '\n' using ll = long long; using ull = unsigned long long; #define rep(i, m, n) for(ll i = (ll)(m); i < (ll)(n); ++i) #define rep2(i, m, n) for(ll i = (ll)(n)-1; i >= (ll)(m); --i) #define REP(i, n) rep(i, 0, n) #define REP2(i, n) rep2(i, 0, n) template<class T> using vec = vector<T>; template<class T> using vvec = vector<vec<T>>; typedef pair<ll, ll> P; using tp = tuple<ll, ll, ll>; constexpr long long INF = 1LL << 60; constexpr int INF_INT = 1 << 25; //constexpr long long MOD = (ll) 1e9 + 7; constexpr long long MOD = 998244353LL; using ld = long double; static const ld pi = 3.141592653589793L; using Array = vector<ll>; using Matrix = vector<Array>; /* #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") */ 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; } void solve() { int n; cin >> n; vec<ll> a(n); REP(i, n) cin >> a[i]; vec<ll> used(n, 0); set<int> b; REP(i, n - 1) { if (a[i] > i + 1 and a[i + 1] < i + 2) { used[i] = 1; b.insert(i); } } vec<int> ans; while (b.size()) { auto it = b.begin(); b.erase(it); int i = *it; //cout<<i+1<<en; used[i] = -1; ans.push_back(i + 1); swap(a[i], a[i + 1]); if (i - 1 >= 0) { if (used[i - 1] != -1) { if (a[i - 1] > i and a[i] < i + 1) { used[i-1] = 1; b.insert(i - 1); } else { used[i-1] = 0; b.erase(i - 1); } } } if (i + 2 < n) { if (used[i + 1] != -1) { if (a[i + 1] > i+2 and a[i + 2] < i + 3) { used[i+1] = 1; b.insert(i + 1); } else { used[i+1] = 0; b.erase(i + 1); } } } } if (ans.size() != n-1) { cout << -1 << en; return; } REP(i, n) { if (a[i] != i + 1) { cout << -1 << en; return; } } for (auto i:ans) cout << i << en; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); /* ll t; cin >> t; REP(i, t - 1) { solve(); }*/ solve(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back #define mp make_pair #define fir first #define sec second #define all(a) a.begin(), a.end() #define fast_io ios_base::sync_with_stdio(false); cin.tie(0); const int maxn = 200010; const int MOD = 1e9+7; const int INF = 1e9; const ll LINF = 1e18; int n, m, a[maxn], b[maxn]; map<int, int> M, N; string s, ss; set<int> S; int main() { int n, ans=0, ans2=0; cin >> n; for(int i = 0; i < n; i++) cin >> a[i]; for(int i = 2; i <= 1000; i++) { int cnt = 0; for(int j = 0; j < n; j++) { if(a[j]%i==0) cnt++; } if(ans<cnt) ans=cnt, ans2=i; } cout << ans2; }
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <utility> #include <tuple> #include <cstdint> #include <cstdio> #include <map> #include <queue> #include <set> #include <stack> #include <deque> #include <unordered_map> #include <unordered_set> #include <bitset> #include <cctype> #include <cmath> #include <iomanip> #include <ctype.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi >; using vl = vector<ll>; using vvl = vector<vl >; using pairi = pair<int, int>; using pairl = pair<ll, ll>; #define TR "," #define TS " " #define rep(i,N) for(ll i=0;i<(ll)N;++i) #define rpt(i,a,b) for(ll i=a;i<(ll)b;++i) #define all(v) v.begin(), v.end() #define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) ll gcd(int a, int b) { if (a < b) swap(a, b); if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll x, ll y) { return x / gcd(x, y) * y; } void printVector(const vector<ll>& vec) { for (ll value : vec) { cout << value << " "; } cout << endl; } vector<int> IntegerToVector(int bit, int N) { vector<int> S; for (int i = 0; i < N; ++i) { if (bit & (1 << i)) { S.push_back(i); } } return S; } const int MAX = 510000; const int MOD = 1000000007; long long fac[MAX], finv[MAX], inv[MAX]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } ll COM(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } int main() { ll M = 0, N, ans = 0;; cin >> N; vl A(N); rep(i, N) cin >> A[i]; rep(i, N) M = max(A[i], M); vl B(M+1,0); rep(i, N) { rpt(j, 2, A[i]+1) { if (A[i] % j == 0) { ++B[j]; } } } rep(i, M+1) { ans = max(ans, B[i]); } rep(i, M+1) { if (B[i] == ans) { cout << i << endl; return 0; } } }
#include <bits/stdc++.h> using namespace std; using ll = long long; typedef pair<ll,ll> P; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define EFOR(i,a,b) for(int i=(a);i<=(b);++i) #define REP(i,n) FOR(i,0,n) #define FORE(i,I) for(const auto &(i):(I)) #define ALL(x) (x).begin(),(x).end() #define SIZE(x) ll(x.size()) #define INF32 2147483647 #define INF64 9223372036854775807 #define MOD 1000000007 #define PI acos(-1) #define endl '\n' template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } int main() { cin.tie(0); ios_base::sync_with_stdio(false); string s; cin >> s; reverse(ALL(s)); REP(i,SIZE(s)){ if(s[i] == '6') s[i] = '9'; else if(s[i] == '9') s[i] = '6'; } cout << s << endl; return 0; }
#include <cmath> #include <iostream> #include <string> #include <algorithm> #include <vector> #include <queue> #include <map> #include<cstdio> #include<functional> #include <bitset> #include <iomanip> #include <cctype> #include <list> #include <cassert> #define rep(i, n) for (ll i = 0; i < (n); i++) #define repr(i, n) for(ll i = n; i >= 0; i--) #define ll long long #define repi(i,a,b) for(ll i=a;i<b;++i) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() using namespace std; template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } const ll INF = 1000000000000000000; const ll MOD = 1e9 + 7; using vvv = vector<vector<vector<ll>>>; using vv = vector<vector<ll>>; using vec = vector<ll>; using P = pair<ll, ll>; int main(void){ ll n; cin >> n; vector<int> digits; while(n) digits.push_back(n % 10), n /= 10; ll ans = 20; rep(i, pow(2, digits.size())){ ll cnt = 0; ll sum = 0; rep(j, digits.size()){ if (i & (1 << j)) { //if(i >> j & 1){ ++cnt; sum += digits[j]; } } if(sum % 3 == 0 && cnt != 0) ans = min(ans, (ll)digits.size() - cnt); } cout << (ans == 20 ? -1 : ans); }
#include <bits/stdc++.h> #define faster ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define ff first #define ss second using namespace std; void file() { freopen ( "CHUYEN.inp", "r", stdin ); freopen ( "CHUYEN.out", "w", stdout ); } typedef pair<int, int> ii; const int maxn = 1e2 + 7; int n, m; vector<ii> ds; vector<vector<int>> dsk; int mau[maxn]; int c[maxn]; int e[maxn][maxn]; void dfs ( int u ) { mau[u] = 1; for ( int v : dsk[u] ) { if ( ( c[u] > c[v] || c[u] == c[v] ) && !e[u][v] && !e[v][u] ) e[u][v] = 1, dfs ( v ); } } void solve() { for ( int i = 1; i <= n; ++i ) if ( mau[i] == 0 ) dfs ( i ); for ( int i = 0; i < ds.size(); ++i ) { int u, v; u = ds[i].ff; v = ds[i].ss; if ( e[u][v] ) cout << "->"; else cout << "<-"; cout << '\n'; } } void input() { cin >> n >> m; dsk.assign ( n + 1, vector<int>() ); for ( int i = 1; i <= m; ++i ) { int u, v; cin >> u >> v; ds.push_back ( {u, v} ); dsk[u].push_back ( v ); dsk[v].push_back ( u ); } for ( int i = 1; i <= n; ++i ) cin >> c[i]; } signed main() { faster; //file(); input(); solve(); }
#include <bits/stdc++.h> using namespace std; using ll = int64_t; using ld = long double; using P = pair<ll, ll>; using Pld = pair<ld, ld>; using Vec = vector<ll>; using VecP = vector<P>; using VecB = vector<bool>; using VecC = vector<char>; using VecD = vector<ld>; using VecS = vector<string>; template <class T> using Vec2 = vector<vector<T>>; #define REP(i, m, n) for(ll i = (m); i < (n); ++i) #define REPN(i, m, n) for(ll i = (m); i <= (n); ++i) #define REPR(i, m, n) for(ll i = (m)-1; i >= (n); --i) #define REPNR(i, m, n) for(ll i = (m); i >= (n); --i) #define rep(i, n) REP(i, 0, n) #define repn(i, n) REPN(i, 1, n) #define repr(i, n) REPR(i, n, 0) #define repnr(i, n) REPNR(i, n, 1) #define all(s) (s).begin(), (s).end() template <class T1, class T2> bool chmax(T1 &a, const T2 b) { if (a < b) { a = b; return true; } return false; } template <class T1, class T2> bool chmin(T1 &a, const T2 b) { if (a > b) { a = b; return true; } return false; } template <class T> istream &operator>>(istream &is, vector<T> &v) { for (T &i : v) is >> i; return is; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &i : v) os << i << ' '; return os; } void _co() { cout << '\n'; } template <class Head, class... Tail> void _co(Head&& head, Tail&&... tail) { cout << ' ' << head; _co(forward<Tail>(tail)...); } template <class Head, class... Tail> void co(Head&& head, Tail&&... tail) { cout << head; _co(forward<Tail>(tail)...); } void ce() { cerr << '\n'; } template <class Head, class... Tail> void ce(Head&& head, Tail&&... tail) { cerr << head << ' '; ce(forward<Tail>(tail)...); } void sonic() { ios::sync_with_stdio(false); cin.tie(nullptr); } void setp(const int n) { cout << fixed << setprecision(n); } constexpr int64_t LINF = 1000000000000000001; constexpr int64_t MOD = 1000000007; constexpr int64_t MOD_N = 998244353; constexpr long double EPS = 1e-11; const double PI = acos(-1); Vec ans; Vec a, b; template <class T> struct Graph { struct edge { int64_t from, to; T dist; bool operator<(const edge &rhs) const { return dist < rhs.dist; } bool operator>(const edge &rhs) const { return dist > rhs.dist; } edge &operator+=(const edge &rhs) { to = rhs.to; dist += rhs.dist; return *this; } edge operator+(const edge &rhs) { return edge(*this) += rhs; } }; int64_t V; vector<T> dist; vector<vector<edge>> edges; bitset<100000> is_visited; Graph(int64_t v) : V(v) { edges = vector<vector<edge>>(V); dist = vector<T>(V, numeric_limits<T>::max()); } void add_edge(int64_t a, int64_t b, T d = 1, bool is_dual = false) { edges[a].push_back(edge{a, b, d}); if (is_dual) edges[b].push_back(edge{b, a, d}); } void dfs(ll v, ll p, T c) { // ce(v, p, c); if (c != -1) { if (is_visited[c]) return; is_visited[c] = true; if (v == b[c]) ans[c] = 1; else ans[c] = 2; } // ce("ok", v, p, c); for (auto e : edges[v]) { if (e.to == p) continue; dfs(e.to, v, e.dist); } } }; int main(void) { ll n, m; cin >> n >> m; a.resize(m); b.resize(m); rep(i, m) cin >> a[i] >> b[i]; Vec c(n); cin >> c; Graph<ll> g(n); ans.resize(m); rep(i, m) a[i]--, b[i]--; rep(i, m) { if(c[a[i]] > c[b[i]]) ans[i] = 1; else if (c[a[i]] < c[b[i]]) ans[i] = 2; else g.add_edge(a[i], b[i], i, true); } rep(i, n) g.dfs(i, i, -1); rep(i, m) { if (ans[i] == 1) co("->"); else co("<-"); } return 0; }
#include<bits/stdc++.h> using namespace std; const int N=5e5+5; char s[N],t[N],zhan[N]; int top; int main() { int n; scanf("%s",s+1); n=strlen(s+1); int l=n+1,r=n,rev=0; for(int i=1;i<=n;i++) if(s[i]=='R') { rev^=1; } else { if(rev) l--,t[l]=s[i]; else r++,t[r]=s[i]; } for(int i=l;i<=r;i++) { zhan[++top]=t[i]; if(zhan[top]==zhan[top-1]) top-=2; } if(!rev) for(int i=1;i<=top;i++) printf("%c",zhan[i]); else for(int i=top;i>=1;i--) printf("%c",zhan[i]); return 0; }
#include<bits/stdc++.h> using namespace std; #define REP(i, n) for (int i=0; i<(n); ++i) #define all(x) (x).begin(),(x).end() const int INF = 1e9+1; using ll = long long; using p = pair<int, int>; using v = vector<int>; int main() { string S; cin >> S; string T; int n = 0; bool R = false; for (auto x : S) { if (x == 'R') { R = !R; } else { int j = 0; if (R) { j = 0; if (x == T[j]) { n--; T = T.substr(1); continue; } T = x + T; } else { j = n-1; if (x == T[j]) { n--; T = T.substr(0, n); continue; } T += x; } n++; } } if (R) reverse(all(T)); cout << T << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #if __has_include(<atcoder/all>) #include <atcoder/all> using namespace atcoder; #endif #define REP(i, n) for (int i = 0; i < (int)n; i++) #define FOR(i, m, n) for (int i = (int)m; i < (int)n; i++) #define REPR(i, n) for (int i = (int)n - 1; i >= 0; i--) #define FORR(i, m, n) for (int i = (int)n - 1; i >= (int)m; i--) #define REPE(i, v) for (auto i : v) #define ALL(v) v.begin(), v.end() #define endl "\n" #define yes cout << "Yes" << endl #define no cout << "No" << endl using Graph = vector<vector<int> >; using WeightedGraph = vector<vector<pair<int, int> > >; using LD = long double; using VI = vector<int>; using VVI = vector<vector<int> >; using PII = pair<int, int>; using MII = map<int, int>; using SI = set<int>; template <typename T> using V = vector<T>; template <typename T> using VV = vector<vector<T> >; template <typename T> using VVV = vector<vector<vector<T> > >; void print() {cout << endl;} template <typename Head, typename... Tail> void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " ";print(forward<Tail>(tail)...);} template <typename T> void print(vector<T> &vec) {for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " ";} cout << endl;} template <typename T> void print(vector<vector<T> > &df) { for (auto& vec : df) { print(vec);}} template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template <typename T> void SORT (T &v) {sort(v.begin(), v.end());} template <typename T> void SORTR (T &v) {sort(v.begin(), v.end(), greater<>());} template <typename T> T GCD(T x,T y) {return __gcd(x,y);} template <typename T> T LCM(T x,T y) {return x/__gcd(x,y)*y;} template <typename T> int SZ(T v) {return v.size();} template <typename T> T PCNT(T x) {return __builtin_popcountll(x);} template <typename T> T BIT(T x) {return 1LL<<(x);} int MOD = 1000000007; int INF = 2000000000; long double PI = acosl(-1); int32_t main() { chrono::system_clock::time_point start_time, end_time; start_time = chrono::system_clock::now(); ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(10); int ans = 0; int N, M; cin >> N; vector<int> A(N); cin >> M; vector<int> B(M); MII m; REP (i, N) { cin >> A[i]; m[A[i]]++; } REP (i, M) { cin >> B[i]; m[B[i]]++; } set<int> s; REP (i, N) { if (m[A[i]] == 1) { s.insert(A[i]); } } REP (i, M) { if (m[B[i]] == 1) { s.insert(B[i]); } } for (auto i : s) { cout << i << ' '; } cout << endl; end_time = chrono::system_clock::now(); assert(chrono::duration_cast<chrono::milliseconds>(end_time-start_time).count() < 6000); return 0; } /* cd ~/Desktop/Programming/AtCoder/contest/jsc2021/jsc2021_b && sh shellscripts/test_cpp.sh cd ~/Desktop/Programming/AtCoder/contest/jsc2021/jsc2021_b && sh shellscripts/etest_cpp.sh cd ~/Desktop/Programming/AtCoder/contest/jsc2021/jsc2021_b && sh shellscripts/submit_cpp.sh */
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define ALL(c) (c).begin(),(c).end() #define RALL(c) (c).rbegin(),(c).rend() #define ZERO(c) memset(c, 0, sizeof(c)) using ll = long long; using P = pair<int,int>; const int INF = 1e9 + 5; const ll INFL = 1e18 + 5; int N, M, a,b,c; set<int> A, B, C; vector<int> v(3000); int main() { cin >> N >> M; rep(i,N) { cin >> a; A.insert(a); } rep(i,M) { cin >> b; B.insert(b); } for (auto elem : A) { if (B.count(elem) == 0) C.insert(elem); } for (auto elem : B) { if (A.count(elem) == 0) C.insert(elem); } for (auto elem : C) cout << elem << endl; }
#include<bits/stdc++.h> using namespace std; typedef long long int lli; #define all(arr) arr.begin(),arr.end() #define f first #define s second #define debug1(x) cout<<x<<"\n" #define debug2(x,y) cout<<x<<" "<<y<<"\n" #define debug3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n" #define nl cout<<"\n"; #define pq priority_queue #define inf 0x3f3f3f3f #define test cout<<"abcd\n"; #define pi pair<int,int> #define pii pair<int,pi> #define pb push_back #define gc getchar_unlocked #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 ll long long #define si(x) scanf("%d",&x) #define sl(x) scanf("%lld",&x) #define ss(s) scanf("%s",s) #define pl(x) printf("%lld\n",x) #define ps(s) printf("%s\n",s) #define deb(x) cout << #x << "=" << x << endl #define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl #define pb push_back #define mp make_pair #define F first #define S second #define clr(x) memset(x, 0, sizeof(x)) #define sortall(x) sort(all(x)) #define tr(it, a) for(auto it = a.begin(); it != a.end(); it++) #define PI 3.1415926535897932384626 #define MOD 1000000007 #define space ' ' 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; template <typename T> void input(vector<T> &arr,lli n) { T temp; for(lli i=0;i<n;i++) cin>>temp, arr.push_back(temp); } template <typename T> void output(vector<T> arr) { for(auto x:arr) cout<<x<<" "; cout<<endl; } template <typename T> void input_set(set<T> &arr,lli n) { T temp; for(lli i=0;i<n;i++) cin>>temp, arr.insert(temp); } lli mul(lli a, lli b) { return (a%MOD*b%MOD)%MOD; } lli power(lli a,lli b) { lli ans = 1; while(b > 0) { if(b&1) ans = mul(ans, a); a = mul(a,a);; b >>= 1; } return ans; } lli sumnatural(lli n){ lli sum = (n* (n+1)) / 2; return sum; } lli suminrange(lli l,lli r){ return sumnatural(r) - sumnatural(l-1); } void solve() { lli n,sum=0; cin >> n; while(n--){ lli a,b; cin >> a >> b; sum = sum + suminrange(a,b); //cout << a << b << endl; //cout << suminrange(a,b) << endl;; } cout << sum; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); }
#include <bits/stdc++.h> using namespace std; typedef unsigned long long int ULLI; int main() { int n; ULLI a, b; ULLI sum = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a >> b; sum += (a + b) * (b - a + 1) / 2; } cout << sum << endl; return 0; }
#include<bits/stdc++.h> #define ll long long using namespace std; int read() { char c; int w=1; while((c=getchar())>'9'||c<'0')if(c=='-')w=-1; int ans=c-'0'; while((c=getchar())>='0'&&c<='9')ans=(ans<<1)+(ans<<3)+c-'0'; return ans*w; } char s[61]; ll m; int n; ll base[600]; bool check(ll x) { base[1]=1; ll nowans=s[1]-'0'; for(int i=2;i<=n;i++) { if(1.0*x*base[i-1]>m)return false; base[i]=base[i-1]*x; if(1.0*(s[i]-'0')*base[i]+nowans>m)return false; nowans+=base[i]*(s[i]-'0'); } return true; } int main(){ scanf("%s",s+1); cin>>m; n=strlen(s+1); if(n==1) { if(m<s[1]-'0') { puts("0"); return 0; } else { puts("1"); return 0; } } reverse(s+1,s+n+1); int num=0; for(int i=1;i<=n;i++)num=max(num,s[i]-'0'); ll l=num+1; ll r=m; ll ans=0; if(!check(num+1)) { puts("0"); return 0; } while(l<=r) { ll mid=l+r>>1; // cout<<mid<<endl; if(check(mid))ans=mid,l=mid+1; else r=mid-1; } cout<<ans-num<<endl; return 0; }
#include <bits/stdc++.h> #include <cassert> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using P = pair<int, int>; /* struct Edge { int to; int weight; Edge(int t, int w) : to(t), weight(w) {} }; using Graph = vector<vector<Edge>>; */ using Graph = vector<vector<int>>; const long long INF = 1LL << 60; const int INT_INF = 1000000000; int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; // int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {-1, 0, 1, 1, -1, 1, 0, -1}; bool check(ll x, string X, ll M) { // x้€ฒๆ•ฐ ll sum = 0; for (int i = 0; i < X.size(); i++) { if (sum > M / x) return false; else sum = sum * x + (ll)(X[i] - '0'); } if (sum <= M) return true; else return false; } // sum + c, (sum + c) * x + c,... ใ‚’็นฐใ‚Š่ฟ”ใ™ int main() { ios::sync_with_stdio(false); cin.tie(nullptr); string X; cin >> X; ll M; cin >> M; int d = 0; for (int i = 0; i < X.size(); i++) { int now = X[i] - '0'; d = max(d, now); } if (X.size() == 1) { if (M >= d) cout << 1 << endl; else cout << 0 << endl; return 0; } ll left = d, right = M + 10; while (left + 1 < right) { ll mid = (left + right) / 2; if (check(mid, X, M)) left = mid; else right = mid; cerr << "left: " << left << " right: " << right << endl; } cout << left - d << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < n; i++) #define rep2(i, x, n) for(int i = x; i <= n; i++) #define rep3(i, x, n) for(int i = x; i >= n; i--) #define each(e, v) for(auto &e: v) #define pb push_back #define eb emplace_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define sz(x) (int)x.size() using ll = long long; using pii = pair<int, int>; using pil = pair<int, ll>; using pli = pair<ll, int>; using pll = pair<ll, ll>; const int MOD = 1000000007; //const int MOD = 998244353; const int inf = (1<<30)-1; const ll INF = (1LL<<60)-1; template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;}; template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;}; struct io_setup{ io_setup(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout << fixed << setprecision(15); } } io_setup; int main(){ int A, B; cin >> A >> B; A--; rep3(i, B, 1){ if((B/i)-(A/i) >= 2) {cout << i << '\n'; return 0;} } }
#include <iostream> #include <cmath> #include <vector> #include <algorithm> #include <functional> using namespace std; using ll = long long int; using P = pair<int, int>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) const ll INF = 1LL << 60; const double pi = acos(-1); ll mod = 1000000007; struct Edge { int to; long long w; Edge(int to, long long w) : to(to), w(w) {} }; struct dsu { vector<int> d; dsu(int n = 0): d(n,-1) {} int findRoot(int x) { if(d[x] < 0) return x; return d[x] = findRoot(d[x]); } bool unite(int x,int y) { x = findRoot(x); y = findRoot(y); if(x == y) return false; if(d[x] > d[y]) swap(x,y); d[x] += d[y]; d[y] = x; return true; } bool same(int x,int y) { return findRoot(x) == findRoot(y);} int size(int x) {return -d[findRoot(x)];} }; 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; } // a^n mod ใ‚’่จˆ็ฎ—ใ™ใ‚‹ long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } // a^{-1} mod ใ‚’่จˆ็ฎ—ใ™ใ‚‹ long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); } template <typename T> T my_lower_bound(vector<T> a, T lb, T ub, T k) { while(ub - lb > 1) { T mid = (lb + ub) / 2; if(a[mid] >= k) { ub = mid; }else{ lb = mid; } } return ub; } int main() { ll a, b; cin >> a >> b; ll ans = 1; for(ll i = 2;i <= b / 2;++i) { ll j = 1; if(i * j < a) { if(a % i == 0) j = a / i; else j = a / i + 1; } ll val = i * j; if(a <= val && val <= b && a <= val + i && val + i <= b) { chmax(ans, i); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repi(i, n) for (int i = 0; i < (int)(n);) #define rep0(i, n) for (int i = 0; i <= (int)(n); i++) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) using namespace std; int main(void) { int N; cin >> N; int A; cin >> A; int B; cin >> B; cout << N - A + B << endl; }
#include <bits/stdc++.h> typedef long long ll; typedef long double ld; #define fr(i, a, b) for (ll i = a; i < b; i++) #define rf(i, a, b) for (ll i = a; i >= b; i--) typedef std::vector<long long> vi; #define F first #define S second #define fast \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define mod 1000000007 #define PB push_back #define MP make_pair #define PI 3.14159265358979323846 #define all(a) a.begin(), a.end() #define mx(a) *max_element(all(a)) #define mn(a) *min_element(all(a)) const ll INF = LLONG_MAX / 2; const ll N = 2e5 + 1; using namespace std; int main() { fast; ll t = 1; // std::cin >> t; while (t--) { ll n, i, j = 0, s, d; std::cin >> n >> s >> d; fr(i, 0, n) { ll x, y; cin >> x >> y; if (x < s && y > d) j = 1; } if (j == 1) cout << "Yes\n"; else { cout << "No\n"; } } }
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int maxn=25; int color[maxn]; int n,m,a,b; vector<int>v[maxn]; vector<int>node; int vis[maxn]; void dfs(int s){ vis[s]=1; node.push_back(s); for(int i=0;i<v[s].size();i++) if(!vis[v[s][i]]) dfs(v[s][i]); } ll cnt(int cur){ if(cur==node.size()) return 1; //็›ธไน˜ ๅˆ™returnๅ€ผไธบ1ไธไธบ0 ll ans=0; for(int i=0;i<3;i++){ int ve=node[cur],sign=0; for(int j=0;j<v[ve].size();j++){ if(color[v[ve][j]]==i){ sign=1; break; } } if(!sign){ color[ve]=i; ans+=cnt(cur+1); color[ve]=-1; } } return ans; } int main(){ ios::sync_with_stdio(0); cin>>n>>m; memset(color,-1,sizeof color); memset(vis,0,sizeof vis); for(int i=0;i<m;i++){ cin>>a>>b; v[a].push_back(b); v[b].push_back(a); } ll res=1,k; for(int i=1;i<=n;i++){ if(!vis[i]){ node.clear(); //ๅญ˜ๅฝ“ๅ‰ๅฏไปฅๅˆฐ่พพ็š„ๆ‰€ๆœ‰่Š‚็‚น dfs(i); k=cnt(0); res*=k; } } cout<<res<<endl; return 0; }
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <array> #include <queue> #include <deque> #include <map> #include <set> #include <sstream> #include <cstdio> #include <cstring> #include <cmath> #include <list> #include <numeric> #include <stack> #include <iomanip> #include <random> #include <complex> #include <functional> #include <tuple> #include <new> using namespace std; #define EPS (1e-9) #define INF (1e9) #define MOD (ll)(1e9 + 7) #define PI (acos(-1)) #define REP(i,a,n) for(int i=a;i<n;i++) #define rep(i, n) REP(i,0,n) #define allof(a) (a).begin(), (a).end() #define Yes(q) ((q) ? "Yes" : "No") #define YES(q) ((q) ? "YES" : "NO") #define Possible(q) ((q) ? "Possible" : "Impossible") #define POSSIBLE(q) ((q) ? "POSSIBLE" ; "IMPOSSIBLE") using ll = long long int; ll gcd(ll a, ll b) { if (a < b) swap(a, b); if (b == 0) return a; return gcd(b, a % b); } ll beki(ll a, ll b) { ll tmp = 1; rep(i, b) tmp *= a; return tmp; } ll modPow(ll x, ll a) { if (a == 1) return x; if (a % 2) return (x * modPow(x, a - 1)) % MOD; ll t = modPow(x, a / 2); return ((t % MOD) * (t % MOD)) % MOD; } ll modInv(ll x) { return modPow(x, MOD - 2); } ll modComb(ll n, ll k) { ll tmp = 1; for (int i = 0; i < k; i++) { tmp *= n - i; tmp %= MOD; } for (int i = 1; i <= k; i++) { tmp *= modInv(i); tmp %= MOD; } return tmp; } ll N; vector<ll> A(30); ll ans; int main() { cin >> N; rep(i, N) cin >> A[i]; rep(i, 1 << (N - 1)) { //iใฎnใƒ“ใƒƒใƒˆ็›ฎใŒใŸใฃใฆใŸใ‚‰ใŒๅŒบๅˆ‡ใ‚Š(ใŸใ‹ใ ใ‹100ไธ‡ๅ›ž) ll ortmp = A[0], xortmp = 0; rep(j, N - 1) { if (!((i >> j) & 1)) { ortmp |= A[j + 1]; } else { xortmp ^= ortmp; ortmp = A[j + 1]; } } xortmp ^= ortmp; if (i == 0) ans = xortmp; else ans = min(ans, xortmp); } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; template <class T> ostream &operator << (ostream &os, const vector<T> &p) { os << "["; for (auto&it : p) os << it << " "; return os << "]";} template <class S, class T> ostream &operator << (ostream &os, const pair<S, T> &p) { return os << "(" << p.first << "," << p.second << ")";} #ifndef ONLINE_JUDGE #define deb(...) dbs(#__VA_ARGS__,__VA_ARGS__) template <class T> void dbs(string str, T t) { cerr << str << ":" << t << "\n";} template<class T, class...S> void dbs(string str, T t, S... s) { int idx = str.find(','); cerr << str.substr(0, idx) << ":" << t << ","; dbs(str.substr(idx + 1), s...);} #else #define deb(...){} #endif #define int long long #define ld long double #define fi first #define se second #define mp make_pair #define pb push_back #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define ini(x, y) memset(x, y, sizeof(x)) #define pr(x) {cout << x << '\n'; return;} #define nl cout<< '\n' #define rep(i,n) for(int i = 0; i < n; i++) #define re(i,n) for(int i = 1; i <= n; i++) #define vi vector<int> #define pii pair<int, int> #define vii vector<pii> template<class T> inline T Bit(T x, int i) { return (x >> i) & 1;} template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; } template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; } const int N = 1e5 + 3; // check the limits void solve() { int n, m; cin >> n >> m; vector<pair<int, pii>> g[n + 1]; rep(i, m) { int x, y, c, d; cin >> x >> y >> c >> d; g[x].pb({y, {c, d}}); g[y].pb({x, {c, d}}); } set<pii> s; s.insert({0, 1}); vi dis(n + 1, 1e18); dis[1] = 0; while (sz(s)) { pii p = *s.begin(); s.erase(s.begin()); int v = p.se, w = p.fi; for (auto u : g[v]) { int x = u.fi, c = u.se.fi, d = u.se.se; vi cur{w}; for (int i = sqrt(d) - 1; i <= sqrt(d + 1); i++) { if (w >= i) continue; cur.pb(i); } if (d >= w) cur.pb(d); if (d - 1 >= w) cur.pb(d - 1); for (auto i : cur) { int time = i + (d / (i + 1)) + c; if (dis[x] > time) { s.erase({dis[x], x}); dis[x] = time; s.insert({dis[x], x}); } } } } int ans = dis[n]; if (ans >= 1e14) ans = -1; cout << ans << '\n'; } signed main() { ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0); //int t; cin >> t; //while (t--) solve(); }
#include <bits/stdc++.h> using namespace std; using ll = long long; constexpr long long MOD = 1000000007; constexpr long long MOD2 = 998244353; constexpr long long INF = 1LL << 60; const long double PI = acosl(-1.0); constexpr long double EPS = 1e-11; 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; } ll c[100000 + 2], d[100000 + 2]; struct edge { long long to, cost, strict; }; struct graph{ long long v; vector<vector<edge>> adj; vector<long long> dist, used; graph(long long n) { init(n); } void init(long long n){ v = n; adj.resize(v); dist.assign(v, INF); used.assign(v, 0LL); } void add_edge(long long stt,long long gol,long long cst,long long ks){ edge e; e.to = gol; e.cost = cst; e.strict = ks; adj[stt].emplace_back(e); } void dijkstra(long long stt){ for (long long i = 0; i < v;i++){ dist[i] = INF; } dist[stt] = 0; //cost,to priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, greater<pair<long long, long long>>> pq; pq.push({0LL, stt}); while(!pq.empty()){ auto p = pq.top(); pq.pop(); long long vertex = p.second; if (dist[vertex] < p.first) continue; for (auto e : adj[vertex]) { ll time = dist[vertex]; if (time < sqrtl(e.strict) - 1) time = sqrtl(e.strict); time += e.strict / (time + 1); if (chmin(dist[e.to], time + e.cost)) pq.push({dist[e.to], e.to}); } } } long long prim(){ priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, greater<pair<long long, long long>>> pq; long long res = 0; pq.push({0LL, 0LL}); while(!pq.empty()){ long long cst = pq.top().first, vertex = pq.top().second; pq.pop(); if (used[vertex]) continue; used[vertex] = 1; res += cst; for(auto e:adj[vertex]){ if (!used[e.to]) pq.push({e.cost, e.to}); } } return res; } }; int main(){ ll n, m; cin >> n >> m; graph g(n); for (ll i = 0; i < m; i++) { ll a,b; cin >> a >> b >> c[i] >> d[i]; a--; b--; g.add_edge(a, b, c[i], d[i]); g.add_edge(b, a, c[i], d[i]); } g.dijkstra(0); if(g.dist[n-1]==INF){ cout << "-1" << endl; } else cout << g.dist[n - 1] << endl; }
#include <bits/stdc++.h> using namespace std; #define ld long double #define ll long long #define P pair<int,int> #define fi first #define se second #define rep(i,n) for(int i=0;i<n;i++) #define all(v) v.begin(),v.end() #define pb push_back #define eb emplace_back template<class T>void chmax(T &a,T b){if(a<b)a=b;} template<class T>void chmin(T &a,T b){if(a>b)a=b;} constexpr int INF=1000000000; constexpr ll llINF=1000000000000000000; constexpr int mod=1000000007; constexpr double eps=1e-8; const double pi=acos(-1); int dx[]={0,1,0,-1},dy[]={1,0,-1,0}; int Random(int mi,int ma){ random_device rnd; mt19937 mt(rnd());//32bit //[mi,ma] uniform_int_distribution<int>engine(mi,ma); return engine(mt); } int gcd(int a,int b){ if(b==0)return a; return gcd(b,a%b); } int lcm(int a,int b){ return a/gcd(a,b)*b; } bool prime(int a){ if(a==1)return false; for(int i=2;i*i<=a;i++){ if(a%i==0)return false; } return true; } int modpow(int a,int b){ if(b==0)return 1; if(b%2)return modpow(a,b-1)*a%mod; int memo=modpow(a,b/2); return memo*memo%mod; } vector<int>kaijo,invkaijo; void init_fact(int n){ kaijo.resize(n+1); invkaijo.resize(n+1); kaijo[0]=1; for(int i=1;i<=n;i++){ kaijo[i]=kaijo[i-1]*i; kaijo[i]%=mod; } rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2); } vector<vector<int>>C,sC; void init_comb(int n,int m){ C.resize(n+1,vector<int>(m+1,0)); sC.resize(n+1,vector<int>(m+1,0)); C[0][0]=1; for(int i=1;i<=n;i++){ C[i][0]=1; for(int j=1;j<=m;j++){ C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod; } } rep(i,n+1){ rep(j,m){ sC[i][j+1]=(sC[i][j]+C[i][j])%mod; } } } int comb(int a,int b){ if(a<b)return 0; if(a<0||b<0)return 0; return kaijo[a]*invkaijo[a-b]%mod*invkaijo[b]%mod; } int inv(int x){ x=modpow(x,mod-2); return x; } signed main(){ cin.tie(0);ios::sync_with_stdio(false); int n; cin>>n; vector<int>p(2*n),pa(2*n,-1); rep(i,n){ int a,b; cin>>a>>b; if(a>=0){ a--; if(p[a]){ puts("No"); return 0; } p[a]=(i+1); } if(b>=0){ b--; if(p[b]){ puts("No"); return 0; } p[b]=-(i+1); } if(a>=0&&b>=0){ if(a>b){ puts("No"); return 0; } pa[a]=b; pa[b]=a; } } vector<bool>dp(2*n,false); dp[0]=true; rep(i,2*n){ for(int j=i+1;j<2*n;j+=2){ int t=(j-i+1)/2; bool ok=true; rep(k,t){ int x=i+k,y=x+t; if(pa[x]>=0&&pa[y]!=x){ ok=false; } if(pa[x]!=y&&pa[y]>=0){ ok=false; } if(p[x]!=0&&p[y]!=0&&p[x]+p[y]!=0){ ok=false; } if(p[x]<0&&p[y]>0){ ok=false; } } dp[j+1]=dp[j+1]|(dp[i]&ok); } } cout<<(dp[2*n]?"Yes":"No")<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 204; bool dp[maxn][maxn]; int l[maxn],r[maxn],vis[maxn]; int w[maxn]; int main() { int n; scanf("%d",&n); bool ok = true; for(int i = 1,a,b;i <= n;++i){ scanf("%d%d",&a,&b); if(a!=-1&&b==-1){ if(vis[a]){ ok = false; } vis[a] = 1; l[a] = 1; } else if(a==-1&&b!=-1){ if(vis[b]){ ok = false; } vis[b] = 1; r[b] = 1; } else if(a!=-1&&b!=-1){ if(vis[a]||vis[b]||a>=b){ ok = false; } vis[a] = vis[b] = 1; l[a] = r[b] = 1; w[a] = w[b] = b-a; } } if(!ok){ printf("No\n"); return 0; } for(int len = 2;len <= 2*n;len += 2){ for(int i = 1;i <= 2*n;++i){ int j = i+len-1; if(j > 2*n)break; int tmp = len/2; bool ok = true; for(int k = i;k <= j-tmp;++k){ if(r[k])ok=0; if(l[k]&&w[k]>0){ if(w[k]!=tmp)ok=0; } if(!w[k]&&l[k]&&r[k+tmp])ok=0; } for(int k = j-tmp+1;k <= j;++k){ if(l[k])ok=0; } dp[i][j] |= ok; for(int k = i;k < j;++k){ dp[i][j] |= dp[i][k]&dp[k+1][j]; } } } if(dp[1][2*n])printf("Yes\n"); else printf("No\n"); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ri register int #define rep(io, st, ed) for(int io = st; io <= ed; io ++) #define drep(io, ed, st) for(int io = ed; io >= st; io --) #define gc getchar inline int read() { int p = 0, w = 1; char c = gc(); while(c > '9' || c < '0') { if(c == '-') w = - 1; c = gc(); } while(c >= '0' && c <= '9') p = p * 10 + c - '0', c = gc(); return p * w; } const int limn = 8e5 + 5; int n, far, lst, cnt; int cap[limn], node[limn], nxt[limn], dep[limn], maxd[limn], son[limn]; void addedge(int u, int v) { nxt[++ cnt] = cap[u]; cap[u] = cnt; node[cnt] = v; } void dfs(int o, int fa) { #define cur node[i] maxd[o] = o; son[o] = 0; for(int i = cap[o]; i; i = nxt[i]) if(fa != cur) { dep[cur] = dep[o] + 1; dfs(cur, o); if(dep[ maxd[cur] ] > dep[ maxd[o] ]) maxd[o] = maxd[cur], son[o] = cur; } } int E[limn]; void dfs2(int o, int fa) { E[o] = E[lst] + dep[o] + dep[lst] - 2 * dep[fa]; lst = o; for(int i = cap[o]; i; i = nxt[i]) if(cur != fa && cur != son[o]) dfs2(cur, o); if(son[o]) dfs2(son[o], o); } int main() { n = read(); rep(i, 2, n) { int u = read(), v = read(); addedge(u, v); addedge(v, u); } dfs(1, 0); //find the diamter int u = maxd[1]; dep[u] = 1; dfs(u, 0); //reset it! dfs2(u, 0); rep(i, 1, n) printf("%d ", E[i]); printf("\n"); return 0; }
// Template #include <iostream> #include <vector> #include <algorithm> #include <numeric> #include <iomanip> #include <tuple> #include <utility> #include <queue> #include <set> #include <map> #include <array> #include <cassert> #include <cmath> #define rep_override(x, y, z, name, ...) name #define rep2(i, n) for (int i = 0; i < (int)(n); ++i) #define rep3(i, l, r) for (int i = (int)(l); i < (int)(r); ++i) #define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__) #define all(x) (x).begin(), (x).end() using namespace std; using ll = long long; constexpr int inf = 1001001001; constexpr ll infll = 3003003003003003003LL; template <typename T> inline bool chmin(T &x, const T &y) { if (x > y) { x = y; return true; } return false; } template <typename T> inline bool chmax(T &x, const T &y) { if (x < y) { x = y; return true; } return false; } template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &element : vec) is >> element; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { for (int i = 0, vec_len = (int)vec.size(); i < vec_len; ++i) { os << vec[i] << (i + 1 == vec_len ? "" : " "); } return os; } struct IOSET { IOSET() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } ioset; // Main int main() { int n, m; cin >> n >> m; vector<vector<int>> g(n); rep(i, m) { int a, b; cin >> a >> b; --a; --b; g[a].push_back(b); } int ans = 0; rep(i, n) { queue<int> q; vector<int> ch(n, 0); q.push(i); ch[i] = 1; while (!q.empty()) { int v = q.front(); q.pop(); for (int u : g[v]) { if (exchange(ch[u], 1) == 0) q.push(u); } } ans += accumulate(all(ch), 0); } cout << ans << '\n'; }
#include <algorithm> #include <bitset> #include <complex> #include <deque> #include <iostream> #include <istream> #include <iterator> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #include <tuple> #include <iomanip> #include <random> #include <math.h> #include <stdio.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using pii = pair<int, int>; void display_2int(vector<vector<int>> vec) { int N = vec.size(); for (int i=0; i<N; i++) { for (int j=0; j<vec.at(i).size(); j++) { cout << vec.at(i).at(j); if (j < vec.at(i).size()-1) { cout << " "; } } cout << endl; } } void display_1string(vector<string> strlist) { int N = strlist.size(); for (int i=0; i<N; i++) { cout << strlist.at(i) << endl; } } void display_1int(vector<int> intlist) { int N = intlist.size(); if (N>0){ for (int i=0; i<N - 1; i++) { cout << intlist.at(i) << " "; } cout << intlist.at(N-1) << endl; }else{ cout << endl; } } vvi saiki(int n, int r, int &ans){ if(n==r){ vvi lst(1, vi(n)); for(int i=0; i<n; i++){ lst.at(0).at(i) = i; } ans++; return lst; } if(r==0){ vvi lst(1, vi(0)); ans++; return lst; } vvi lst; vvi lst1 = saiki(n-1, r, ans); vvi lst2 = saiki(n-1, r-1, ans); for(int i=0; i<lst1.size(); i++){ lst.push_back(lst1.at(i)); } for(int i=0; i<lst2.size(); i++){ lst2.at(i).push_back(n-1); lst.push_back(lst2.at(i)); } return lst; } int main(){ int ans=0; int cnt = 0; //vvi a = saiki(6, 2, ans); //display_2int(a); //cout << ans << endl; int H, W, A, B; cin >> H >> W >> A >> B; vvi lst=saiki(H*W, A, ans); int bit = pow(2, A); if (A ==8){ if (H == 4){ cout << 36 << endl; } else{ cout << 34 << endl; } }else{ for (int i=0; i<ans; i++){ for(int j=0; j<bit; j++){ int b = j; vi bitlst(A); for(int k=0; k<A; k++){ //cout << b << endl; int a = b/(int)pow(2, A-k-1); bitlst.at(k) = a; b = b % (int)pow(2, A-k-1); } //display_1int(bitlst); vvi board(H, vi(W)); bool bb = true; for(int k=0; k<A; k++){ int c = lst.at(i).at(k); int y = c/W; int x = c%W; if(bitlst.at(k) == 0){ if(x == W-1){ bb = false; break; }if(board.at(y).at(x)==1 || board.at(y).at(x+1) ==1){ bb = false; break; } board.at(y).at(x)=1; board.at(y).at(x+1) =1; }else{ if(y == H-1){ bb = false; break; }if(board.at(y).at(x)==1 || board.at(y+1).at(x) ==1){ bb = false; break; } board.at(y).at(x)=1; board.at(y+1).at(x) =1; } } if(bb){ cnt++; } } } cout << cnt << endl; } }
#include <iostream> #include <cmath> using namespace std; int main() { double a,b,c,d; cin >> a >> b >> c >> d; if(c*d-b<=0) cout << -1 << endl; else { cout << ceil(a/(c*d-b)) << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 10005; int n, e; int a[N], L[N], R[N], h[N]; int main() { ios::sync_with_stdio(false); cin.tie(0); while (cin >> n) { for (int i = 1; i <= n; i++) cin >> a[i]; e = 0; for (int i = 1; i <= n; i++) { while (e > 0 && a[i] < a[h[e - 1]]) R[h[--e]] = i; h[e++] = i; } while (e > 0) R[h[--e]] = n + 1; // for (int i = 1; i <= n; i++) cout << R[i] << ' '; // puts(""); e = 0; for (int i = n; i >= 1; i--) { while (e > 0 && a[i] < a[h[e - 1]]) L[h[--e]] = i; h[e++] = i; } while (e > 0) L[h[--e]] = 0; int ans = 0; for (int i = 1; i <= n; i++) ans = max(ans, a[i] * (R[i] - L[i] - 1)); cout << ans << '\n'; } return 0; }
#include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <tuple> #include <type_traits> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++) #define RREP(i, n) for(int i = (n)-1; i >= 0; i--) #define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++) #define RRANGE(i, a, b) for(int i = (b)-1, i##_MACRO = (a); i >= i##_MACRO; i--) #define EACH(e, a) for(auto&& e : a) #define ALL(a) std::begin(a), std::end(a) #define RALL(a) std::rbegin(a), std::rend(a) #define FILL(a, n) memset((a), n, sizeof(a)) #define FILLZ(a) FILL(a, 0) #define INT(x) (static_cast<int>(x)) #define PRECISION(x) std::fixed << std::setprecision(x) using namespace std; using ll = long long; using VI = std::vector<int>; using VI2D = std::vector<vector<int>>; using VLL = std::vector<long long>; using VLL2D = std::vector<vector<long long>>; constexpr int INF = 2e9; constexpr long long INFLL = 2e18; constexpr double EPS = 1e-10; constexpr double PI = acos(-1.0); constexpr int dx[] = {-1, 0, 1, 0}; constexpr int dy[] = {0, -1, 0, 1}; template <typename T, std::size_t N> struct make_vector_type { using type = typename std::vector<typename make_vector_type<T, (N - 1)>::type>; }; template <typename T> struct make_vector_type<T, 0> { using type = typename std::vector<T>; }; template <typename T, size_t N> auto make_vector_impl(const std::vector<std::size_t>& ls, T init_value) { if constexpr(N == 0) { return std::vector<T>(ls[N], init_value); } else { return typename make_vector_type<T, N>::type( ls[N], make_vector_impl<T, (N - 1)>(ls, init_value)); } } template <typename T, std::size_t N> auto make_vector(const std::size_t (&ls)[N], T init_value) { std::vector<std::size_t> dimensions(N); for(int i = 0; i < N; i++) { dimensions[N - i - 1] = ls[i]; } return make_vector_impl<T, N - 1>(dimensions, init_value); } template <typename T> std::vector<T> make_vector(std::size_t size, T init_value) { return std::vector<T>(size, init_value); } template <typename T> constexpr int sign(T x) { return x < 0 ? -1 : x > 0 ? 1 : 0; } template <> constexpr int sign(double x) { return x < -EPS ? -1 : x > EPS ? 1 : 0; } template <typename T, typename U> constexpr bool chmax(T& m, U x) { m = max<T>(m, x); return m < x; } template <typename T, typename U> constexpr bool chmin(T& m, U x) { m = min<T>(m, x); return m > x; } template <typename T> constexpr T square(T x) { return x * x; } template <typename T> constexpr T pow(T a, int n) { T ret = 1; while(n != 0) { if(n % 2) { ret *= a; } a *= a; n /= 2; } return ret; } template <typename T> constexpr T diff(T a, T b) { return abs(a - b); } const int MOD = 200; int main() { int n; cin >> n; VI a(n); EACH(e, a) { cin >> e; } EACH(e, a) { e %= MOD; } int x = min(n, 8); VI count(MOD, 0); RANGE(s, 1, 1 << x) { int mod_sum = 0; REP(i, x) { if((s & (1 << i)) != 0) { mod_sum += a[i]; mod_sum %= MOD; } } count[mod_sum]++; } auto found_iter = find_if(ALL(count), [](auto x) { return x >= 2; }); if(found_iter == count.end()) { cout << "No" << endl; return 0; } int found_num = distance(count.begin(), found_iter); VI result; RANGE(s, 1, 1 << x) { int mod_sum = 0; REP(i, x) { if((s & (1 << i)) != 0) { mod_sum += a[i]; mod_sum %= MOD; } } if(mod_sum == found_num) { result.push_back(s); } } cout << "Yes" << endl; REP(k, 2) { cout << __builtin_popcount(result[k]) << " "; REP(i, 8) { if((result[k] & (1 << i)) != 0) { cout << i + 1 << " "; } } cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() #define FOR(i, a, b) for (int i = a; i <= (b); i++) #define ROF(i, a, b) for (int i = a; i >= (b); i--) #define y1 awefakhlrv using pii = pair<int, int>; using vpii = vector<pii>; using vi = vector<int>; using vvi = vector<vi>; using ll = long long; using pll = pair<ll, ll>; using vpll = vector<pll>; using vll = vector<ll>; using vvll = vector<vll>; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int x, y; cin >> x >> y; cout << (abs(x - y) <= 2 ? "Yes" : "No") << endl; }
#include <bits/stdc++.h> using namespace std; int main(){ int x, y; cin >> x >> y; if((x < y && y - x < 3) || (x > y && x - y < 3)){ cout << "Yes" << endl; }else{ cout << "No" << endl; } }
#include <bits/stdc++.h> #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define rrep(i, n) for(int i = 1; i <= (int)(n); i++) #define drep(i, n) for(int i = (n)-1; i >= 0; i--) #define ALL(x) (x).begin(), (x).end() #define dup(x,y) (((x)+(y)-1)/(y)) #define srep(i,s,t) for (int i = s; i < t; ++i) using namespace std; typedef long long ll; typedef pair<int, int> P; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; const ll LINF = 1001002003004005006ll; const int INF = 1001001001; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const int mod = 1000000007; // const int mod = 998244353; int main() { int n, m; cin >> n >> m; vvi g(n); vi a(n); rep(i, n) cin >> a[i]; rep(i, m) { int x, y; cin >> x >> y; --x; --y; g[x].push_back(y); } vi dp(n, INF*2); int ans = -INF; rep(i, n) { chmax(ans, a[i] - dp[i]); for (int j : g[i]) { chmin(dp[j], dp[i]); chmin(dp[j], a[i]); } } cout << ans << endl; }
#include <bits/stdc++.h> #define INF 1'000'000'000'000'000'000 #define MAX_N 200'000 #define MAX_M 200'000 using namespace std; typedef long long ll; typedef pair<ll, ll> pll; ll N, M; ll A[MAX_N]; ll B[MAX_N]; ll X[MAX_M], Y[MAX_M]; void solve() { for (ll i = 0; i < N; ++i) { B[i] = A[i]; } vector<pll> V; for (ll i = 0; i < M; ++i) { V.push_back({X[i], Y[i]}); } sort(V.begin(), V.end()); ll res = -INF; for (auto [x, y] : V) { res = max(res, A[y] - B[x]); B[y] = min(B[x], B[y]); } printf("%lld\n", res); } int main() { cin >> N >> M; for (ll i = 0; i < N; ++i) { cin >> A[i]; } for (ll i = 0; i < M; ++i) { cin >> X[i] >> Y[i]; --X[i]; --Y[i]; } solve(); }
/* Auther: ghoshashis545 Ashis Ghosh ๐Ÿ˜Ž College: Jalpaiguri Govt Enggineering College */ #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #include <bits/stdc++.h> #include<algorithm> #include<string> using namespace std; #define ll int // #define int long long #define ld long double #define ff first #define ss string #define se second #define sp(x) cout << fixed << setprecision(x) #define endl "\n" #define ub upper_bound #define lb lower_bound #define vi vector<int> #define ipair pair<int,int> #define vpi vector<ipair> #define clr(a,x) memset(a,x,sizeof(a)) #define alt(v) v.begin(),v.end() #define ralt(v) v.rbegin(),v.rend() #define pb emplace_back #define mp make_pair #define PI 3.1415926535897932384626 #define cntb(x) __builtin_popcount(x) #define fab(i,a,b) for(int i=(a);i<(b);i++) #define fba(i,a,b) for(int i=(b);i>=(a);i--) bool ispoweroftwo(int n){return n&(!(n&(n-1)));} int mod=1000000007; // int mod=998244353; int dx[] = {1,0,-1,0}; int dy[] = {0,-1,0,1}; bool test = 0; // const int inf = 1e18; const int N = 2e5+5; int n,q; vector<int>adj[N]; int depth[N],ans[N]; vector<pair<int,int>>res[N]; void dfs(int u){ for(auto it : adj[u]){ depth[it] = depth[u] + 1; dfs(it); } } vector<vector<int>>m; void dfs1(int u,int c){ int sz = (int)adj[u].size(); for(auto it : res[u]){ int x = c+it.ff; if(x == c+1) ans[it.se] += sz; else m[x].pb(it.se); } for(auto it : m[c+1]) ans[it] += sz; for(auto it : adj[u]) dfs1(it,c+1); for(auto it : res[u]){ int x = c+it.ff; if(x != c+1) m[x].pop_back(); } } void solve(int tc = 0) { cin >>n; for(int i = 2,x; i <= n; ++i) cin >>x,adj[x].pb(i); dfs(1); cin >>q; for(int i = 1; i <= q; ++i){ int x,d; cin >> x >> d; if(depth[x] > d) continue; else if(depth[x] == d){ ans[i] = 1; continue; } res[x].push_back({d-depth[x],i}); } m.resize(n+1); dfs1(1,0); for(int i = 1; i <= q; ++i) cout<<ans[i]<<"\n"; } signed main() { ios_base::sync_with_stdio(false);cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t=1; if(test) cin>>t; for(int i = 1; i <= t; ++i){ // cout<<"Case #"<<i<<": "; solve(i); } 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'); } } 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; } long long FmcKpFmN; long long xr20shxY; long long WYIGIcGE; FmcKpFmN = d; xr20shxY = 1e18; 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,1e18][ // val = 0; // rep(i,N){ // val = val * b + X[i]; // if(val > M) break; // } // ](val <= M); // res = b - d; // wt(res); // }
#include<bits/stdc++.h> using namespace std; int main(){ int a, b, c, d; cin >>a>>b>>c>>d; cout << a*d-b*c <<endl; }
#include <iostream> using namespace std; typedef long long ll; ll x,y,a,b,cnt,A; int main(void){ cin>>x>>y>>a>>b; while(1){ if(y/a<=x){ cnt+=(y-x-1)/b; break; } if(x*a<x+b){ x*=a; cnt++; } else{ A=(x*a-x)/b; cnt+=A; x+=b*A; } } cout<<cnt<<endl; }
#include<bits/stdc++.h> #include<stdio.h> #define int long long #define pb push_back #define fo(i,a,n) for(int i=a;i<n;i++) #define foo(i,a,n) for(int i=a;i>=n;i--) #define sn s.length() #define get(n) cin>>n #define put(n) cout<<n //getline(cin >> ws, x); eats whitespace // round() nearest int after round using namespace std; signed main() { int t=1; // cin>>t; while(t--) { int n,x; cin>>n; string s; cin>>s; vector<char>c; fo(i,0,n) { if(s[i]=='x'&&c.size()>1) { x=c.size(); char cc=c[x-1]; c.pop_back(); x=c.size()-1; if(c[x]=='f'&&cc=='o') c.pop_back(); else { c.push_back(cc); c.pb(s[i]); } } else c.pb(s[i]); } cout<<c.size(); } }
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, n) for (int i = a; i < (int)n; i++) #define REP(i, n) FOR(i, 0, n) int H, W; char S[10][10]; int dh[8]{ -1, -1, 0, 1, 1, 1, 0, -1 }; int dw[8]{ 0, 1, 1, 1, 0, -1, -1, -1 }; bool check(int h, int w, int d, char c) { return S[h+dh[d%8]][w+dw[d%8]] == c; } int main() { cin >> H >> W; REP(i, H) REP(j, W) cin >> S[i][j]; int ans = 0; REP(i, H) REP(j, W) if (S[i][j] == '#') { for (int k = 0; k < 8; k += 2) { ans += (check(i, j, k, '.') && check(i, j, k+2, '.')); ans += (check(i, j, k, '#') && check(i, j, k+1, '.') && check(i, j, k+2, '#')); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0 ; i < (n) ; i++) #define rep1(i,n) for(int i = 1 ; i <= (n) ; i++) #define rrep(i,n) for(int i = (n) - 1 ; i >= 0 ; i--) #define rrep1(i,n) for(int i = (n) ; i > 0 ; i--) #define INF 1001001001 #define MOD 1000000007 using ll = int64_t; using P = pair<int, int>; using PL = pair<ll,ll>; using PD = pair<double,double>; using vi = vector<int>; using vvi = vector<vector<int>>; using vl = vector<ll>; using vvl = vector<vector<ll>>; using p_q = priority_queue<int, vi, greater<int>>; #define v(n) vector<n> #define vv(n) vector<vector<n>> #define vvv(n) vector<vector<vector<n>>> #define p_q(n) priority_queue<(n), v(n), greater<n>> #define line cout << "================================" << endl; #define Yn(x) ((x) ? "Yes" : "No") #define yn(x) ((x) ? "yes" : "no") #define mmax(a,b) a = max(a,b) #define mmin(a,b) a = min(a,b) #define debug(x) cout << #x" : " << (x) << endl; #define output(x) cout << (x) << endl; #define outs(x) cout << #x << endl; #define mod(n,x) ((n)%(x)) #define all(a) (a).begin(),(a).end() class alucrex{ public: void vin(vi& a){rep(i,a.size())cin>>a[i];} void vvin(vvi& a){rep(i,a.size())rep(j,a[i].size())cin>>a[i][j];} void vvdes(vvi& a){rep(i,a.size()){rep(j,a[i].size()){ cout << a[i][j] << " ";}cout<<endl; }} void vinl(vl& a){rep(i,a.size())cin>>a[i];} void vvinl(vvl& a){rep(i,a.size())rep(j,a[i].size())cin>>a[i][j];} void vvdesl(vvl& a){rep(i,a.size()){rep(j,a[i].size()){ cout << a[i][j] << " ";}cout<<endl; }} }; int main(){ alucrex al; ll a, b, c;cin >> a >> b >> c; a *= a; b*= b; c*= c; cout << Yn(a+b<c) << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define sorts(s) sort(s.begin(), s.end()) #define sortu(s) sort(s.begin(), s.end(), greater<>()) typedef long long int ll; using Graph = vector<vector<int>>; int main(void) { int i = 0, j = 0, k = 0; int N; ll MOD = (1e+9)+7; cin >> N; vector<ll> A(N); rep(i, N) { cin >> A[i]; } vector<ll> fib(N+1); rep(i, N) { if (i == 0) { fib[i+1] = 1; } else if (i == 1) { fib[i+1] = 2; } else { fib[i+1] = (fib[i-1] + fib[i]) % MOD; } } vector<ll> plus(N-1), mins(N-1); rep(i, N-1) { if (i == 0) { plus[i] = 1; mins[i] = 1; } else { plus[i] = (plus[i-1] + mins[i-1]) % MOD; mins[i] = plus[i-1]; } } rep(i, N-2) { plus[i] = (fib[N-1-i] * plus[i]) % MOD; mins[i] = (fib[N-2-i] * mins[i]) % MOD; } ll ans = (A[0] * fib[N]) % MOD; rep(i, N-1) { ans += (A[i+1] * plus[i]) % MOD; ans %= MOD; ans -= (A[i+1] * mins[i]) % MOD; if (ans < 0) { ans += MOD; } else { ans %= MOD; } } cout << ans << endl; //cout << fixed << setprecision(4) << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define ll long long #define ld long double 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; } using P=pair<long long,long long>; #define rep(i,n) for(long long i=0; i<(long long)n; i++) #define req(i,n) for(long long i=n-1; i>=0; i--) #define range(i,a,b) for(long long i=a; i<b; i++) #define all(x) (x).begin(), (x).end() #define sz(x) ((long long)(x).size()) #define COUT(x) cout << x << endl #define pb push_back #define mp make_pair #define F first #define S second #define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w) #define pri_que priority_queue #define vint vector<int> #define vvint vector<vector<int>> #define vi vector<int> #define vvi vector<vector<int>> #define vs vector<string> #define vvc vector<vector<char>> #define vc vector<char> #define vp vector<pair<int,int>> #define vb vector<bool> #define vvb vector<vector<bool>> #define show(x) cout<<#x<<"="<<x<<endl; #define SUM(x) accumulate(x.begin(),x.end(),0) #define MAX(x) *max_element(x.begin(),x.end()) #define MIN(x) *min_element(x.begin(),x.end()) #define couty cout<<"Yes"<<endl #define coutn cout<<"No"<<endl #define coutY cout<<"YES"<<endl #define coutN cout<<"NO"<<endl #define yn(x) cout<<(x?"Yes":"No")<<endl #define YN(x) cout<<(x?"YES":"NO")<<endl long long gcd(long long a,long long b){return b?gcd(b,a%b):a;} long long lcm(long long a, long long b){return a/gcd(a,b)*b;} const long long dx[8]={1,0,-1,0,1,-1,-1,1}; const long long dy[8]={0,1,0,-1,1,1,-1,-1}; const long long INF = 1e15; const long long MOD = 1e9+7; signed main(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(15); int a,b; cin >> a >> b; cout<<max(2*a+100-b,0LL)<<endl; }
#include <iostream> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) using ll = long long; using P = pair<int, int>; int main() { int a, b; cin >> a >> b; int ans = 2 * a + 100 - b; cout << ans << endl; return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> #define m_p make_pair #define sz(x) (int)x.size() #define line cerr<<"--------------------\n"; #define see(x) cerr<<x<<" " #define seeln(x) cerr<<x<<endl #define out(x) cerr<<#x<<" = "<<x<<" " #define outln(x) cerr<<#x<<" = "<<x<<endl #define outarr(x,l,r) cerr<<#x"["<<l<<"-"<<r<<"] = "; for (int _i=l;_i<=r;++_i) cerr<<x[_i]<<" ";cerr<<endl; using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; #define gc() getchar() //char buf[1<<23],*p1=buf,*p2=buf; //#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++) template <class T> void read(T &x) { x=0; char c=gc(); int flag=0; while (c<'0'||c>'9') flag|=(c=='-'),c=gc(); while (c>='0'&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=gc(); if (flag) x=-x; } template <class T> inline T _max(T a,T b){return a>b ? a : b;} template <class T> inline T _min(T a,T b){return a<b ? a : b;} template <class T> inline bool checkmax(T &a,T b){return b>a ? a=b,1 : 0;} template <class T> inline bool checkmin(T &a,T b){return b<a ? a=b,1 : 0;} int n,k,mod; int Add(int x,int y){x+=y; return x>=mod ? x-mod : x;} int Sub(int x,int y){x-=y; return x<0 ? x+mod : x;} int Mul(int x,int y){return (ll)x*y%mod;} void add(int &x,int y){x=Add(x,y);} void sub(int &x,int y){x=Sub(x,y);} void mul(int &x,int y){x=Mul(x,y);} int dp[102][128000]; void init() { read(n); read(k); read(mod); dp[0][0]=1; for (int i=1;i<=n;++i) { int tmp=_min(i,50); for (int r=0;r<=k;++r) { for (int j=r*i;j<=tmp*(tmp+1)/2*k;++j) { add(dp[i][j],dp[i-1][j-r*i]); } } } } int calc(int x) { int tmp=_min(x-1,n-x); int ans=0; for (int i=0;i<=tmp*(tmp+1)/2*k;++i) { if (i) add(ans,Mul(Mul(dp[x-1][i],dp[n-x][i]),k+1)); else add(ans,k); } return ans; } void solve() { for (int i=1;i<=n;++i) { printf("%d\n",calc(i)); } } int main() { init(); solve(); return 0; }
/* Average = a is the same as sum of abs(i-a) = 0 * which is the same as sum of i-a (for all i to the left) = a-i (for all i to the right) * so let dp[i][j] = number of ways to form sum of j using 1...i */ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define FOR(i, a, b) for(ll i = (ll)a; i <= (ll)b; i++) #define DEC(i, a, b) for(ll i = (ll)a; i >= (ll)b; i--) typedef pair<ll, ll> pi; typedef pair<pi, ll> pii; typedef pair<ll, pi> ipi; typedef pair<pi, pi> pipi; #define mp make_pair #define f first #define s second typedef vector<ll> vi; typedef vector<pi> vpi; typedef vector<pii> vpii; #define pb push_back #define pf push_front #define all(v) v.begin(), v.end() #define size(v) (ll) v.size() #define disc(v) sort(all(v)); v.resize(unique(all(v)) - v.begin()); #define INF (ll) 1e9 + 100 #define LLINF (ll) 1e18 #define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define sandybridge __attribute__((optimize("Ofast"), target("arch=sandybridge"))) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //can be used by calling rng() or shuffle(A, A+n, rng) inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss ll n, k, mod, dp[105][1000005]; int main() { fastio; cin >> n >> k >> mod; dp[0][0] = 1; FOR(i, 1, n) { vi v(i, 0); FOR(j, 0, k*n*(n+1)/2) { ll m = j % i; v[m] = (v[m] + dp[i-1][j]) % mod; if (j - ((k+1) * i) >= 0) v[m] = (v[m] - dp[i-1][j - ((k+1) * i)] + mod) % mod; dp[i][j] = v[m]; } } FOR(i, 1, n) { ll ans = 0; FOR(j, 0, k*i*(i+1)/2) (ans += dp[i-1][j] * dp[n-i][j]) %= mod; cout << (ans * (k+1) - 1 + mod) % mod << "\n"; } }
#include<bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; using namespace std; int h, w; int memo[2000][2000]; int inf = INT_MAX; string s[2000]; int f(int i, int j) { if (i == h - 1 && j == w - 1) return 0; if (memo[i][j] != -inf) return memo[i][j]; int res = -inf; if (i < h - 1) res = max(res, (s[i + 1][j] == '+' ? 1 : -1) - f(i + 1, j)); if (j < w - 1) res = max(res, (s[i][j + 1] == '+' ? 1 : -1) - f(i, j + 1)); return memo[i][j] = res; } int main() { cin >> h >> w; rep(i, h) cin >> s[i]; rep(i, h) rep(j, w) memo[i][j] = -inf; int ans = f(0, 0); if (ans == 0) cout << "Draw"; if (ans > 0) cout << "Takahashi"; if (ans < 0) cout << "Aoki"; return 0; }
#include <bits/stdc++.h> #define fileio \ freopen("C:\\Users\\PRISM17\\Desktop\\in.txt", "r", stdin); \ freopen("C:\\Users\\PRISM17\\Desktop\\out.txt", "w", stdout); #define fastio \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define dbg(x) cout << #x << " : " << x << endl; #define rep(i, a, b) for (int i = (a); i <= (b); i++) #define mid (st[id].l + st[id].r >> 1) #define lson (id << 1) #define rson (id << 1 | 1) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> PII; typedef pair<ll, ll> pll; typedef pair<double, double> pdd; const int inf = 0x3f3f3f3f; const int INF = 1e9; const int N = 2e3 + 7; char mp[N][N]; int n, m; int dp[N][N][2]; inline int get(int x, int y){ char ch = mp[x][y]; return ch == '+' ? 1 : -1; } int dfs(int x, int y, int op) { if (x == n && y == m) return 0; int &ans = dp[x][y][op]; if (ans != -1) return ans; if (op) { ans = -inf; if (x < n) ans = max(dfs(x + 1, y, op ^ 1) + get(x + 1, y), ans); if (y < m) ans = max(dfs(x, y + 1, op ^ 1) + get(x, y + 1), ans); } else { ans = inf; if (x < n) ans = min(dfs(x + 1, y, op ^ 1) - get(x + 1, y), ans); if (y < m) ans = min(dfs(x, y + 1, op ^ 1) - get(x, y + 1), ans); } return ans; } int main() { memset(dp, -1, sizeof dp); cin >> n >> m; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin >> mp[i][j]; } } int res = dfs(1, 1, 1); if (res > 0) puts("Takahashi"); else if (res < 0) puts("Aoki"); else puts("Draw"); }
#include <bits/stdc++.h> using namespace std; #define ll long long void print(vector<int> &a){for(auto l : a) cout<<l<<" "; cout<<'\n';} void solve(){ int n,m; cin>>n>>m; int a[n][m]; int mi = INT_MAX; for(int i=0;i<n;++i){ for(int j=0;j<m;++j) cin>>a[i][j], mi=min(mi,a[i][j]); } int ans = 0; for(int i=0;i<n;++i){ for(int j=0;j<m;++j) ans+= a[i][j] - mi; } cout<<ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); //freopen("lex.in", "r", stdin);//freopen("output.txt", "w", stdout); int t = 1; //cin>>t; while(t--){ solve(); } }
#include <bits/stdc++.h> #include <stdlib.h> #include <ctype.h> #include <regex> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define Sort(a) sort(a.begin(), a.end()) int main(){ int H,W; cin >> H >> W; vector<vector<int>> data(H, vector<int>(W)); rep(i,H){ rep(j,W){ cin >> data.at(i).at(j); } } int min = data.at(0).at(0); rep(i,H){ rep(j,W){ if(data.at(i).at(j) < min){ min = data.at(i).at(j); } } } int count = 0; rep(i,H){ rep(j,W){ count += (data.at(i).at(j) - min); } } cout << count; }
#include <bits/stdc++.h> using namespace std; #define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #define int long long #define ld long double #define fi first #define se second #define all(uiet) uiet.begin(),uiet.end() #define read(UIET, n) for(int i = 0; i < n; ++i) cin >> UIET[i] #define out(UIET, n) for(int i = 0; i < n; ++i) cout << UIET[i] << " " #define mp make_pair #define pb push_back #define eb emplace_back #define vpp vector<pair< int, int > > #define pll pair<int , int > #define ppll pair < pll , pll > #define debug(n1) cout << n1 << endl #define len(a) ((int) (a).size()) #define endl "\n" #define mod 1000000007 const int INF = (1LL<<60)-1; const int maxN = 1000001; int32_t main(){ SPEED; int t = 1; //cin >> t; while(t--){ int n, m; cin >> n >> m; if(abs(n - m) < 3) cout << "Yes" << endl; else cout << "No" << endl; } } /* 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 */
#include <bits/stdc++.h> using namespace std; int main(){ int x,y,abs; cin >> x >> y; abs = max(x-y,y-x); if(abs<3){ cout << "Yes"; } else{ cout << "No"; } }
/* ยฉ 2021-03-28 06:53:10 Franco1010 All Rights Reserved */ // #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math") // #pragma GCC target("avx,avx2,fma") #include <bits/stdc++.h> #define f first #define s second #define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i) #define pb push_back #define all(s) begin(s), end(s) #define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define sz(s) int(s.size()) #define ENDL '\n' using namespace std; typedef long double ld; typedef long long lli; typedef pair<lli,lli> ii; typedef vector<lli> vi; #define deb(x) cout << #x": " << (x) << endl; using uint=unsigned; using ull=unsigned long long; struct modinfo{uint mod,root;}; template<modinfo const&ref> struct modular{ static constexpr uint const &mod=ref.mod; static modular root(){return modular(ref.root);} uint v; //modular(initializer_list<uint>ls):v(*ls.bg){} modular(lli vv=0){s(vv%mod+mod);} modular& s(uint vv){ v=vv<mod?vv:vv-mod; return *this; } modular operator-()const{return modular()-*this;} modular& operator+=(const modular&rhs){return s(v+rhs.v);} modular&operator-=(const modular&rhs){return s(v+mod-rhs.v);} modular&operator*=(const modular&rhs){ v=ull(v)*rhs.v%mod; return *this; } modular&operator/=(const modular&rhs){return *this*=rhs.inv();} modular operator+(const modular&rhs)const{return modular(*this)+=rhs;} modular operator-(const modular&rhs)const{return modular(*this)-=rhs;} modular operator*(const modular&rhs)const{return modular(*this)*=rhs;} modular operator/(const modular&rhs)const{return modular(*this)/=rhs;} modular pow(int n)const{ modular res(1),x(*this); while(n){ if(n&1)res*=x; x*=x; n>>=1; } return res; } modular inv()const{return pow(mod-2);} friend modular operator+(int x,const modular&y){ return modular(x)+y; } friend modular operator-(int x,const modular&y){ return modular(x)-y; } friend modular operator*(int x,const modular&y){ return modular(x)*y; } friend modular operator/(int x,const modular&y){ return modular(x)/y; } friend ostream& operator<<(ostream&os,const modular&m){ return os<<m.v; } friend istream& operator>>(istream&is,modular&m){ lli x;is>>x; m=modular(x); return is; } bool operator<(const modular&r)const{return v<r.v;} bool operator==(const modular&r)const{return v==r.v;} bool operator!=(const modular&r)const{return v!=r.v;} explicit operator bool()const{ return v; } }; extern constexpr modinfo base{998244353,3}; // extern constexpr modinfo base{1000000007,0}; //modinfo base{1,0}; using mint=modular<base>; //COMBI const int vmax=(1<<21)+10; mint fact[vmax],finv[vmax],invs[vmax]; void initfact(){ fact[0]=1; fore(i,1,vmax)fact[i]=fact[i-1]*i; finv[vmax-1]=fact[vmax-1].inv(); for(int i=vmax-2;i>=0;i--)finv[i]=finv[i+1]*(i+1); for(int i=vmax-1;i>=1;i--)invs[i]=finv[i]*fact[i-1]; } mint choose(int n,int k){ return fact[n]*finv[n-k]*finv[k]; } mint binom(int a,int b){ return fact[a+b]*finv[a]*finv[b]; } mint catalan(int n){ return binom(n,n)-(n-1>=0?binom(n-1,n+1):0); } const lli N = 2e5 + 5; lli p[N]; vi primes; lli n, m; set<vi> st; void dfs(vi& v, lli cur){ if(sz(v) == n){ st.insert(v); return; } lli foo = cur; while(foo <= m){ v.pb(foo); dfs(v, foo); v.pop_back(); foo += cur; } } mint f(lli x){ mint res = 1; while(x > 1){ lli foo = p[x]; lli cnt = 0; while(p[x] == foo){ x /= p[x]; cnt++; } res *= choose(n - 1 + cnt, cnt); } return res; } int main(){ _ p[0] = p[1] = 1; for(lli i = 2; i < N; i++) if(!p[i]) for(lli j = i; j < N; j += i) p[j] = i; // fore(i, 0, N) if(!p[i]) primes.pb(i); // freopen("file.in","r",stdin); // freopen("file.out","w",stdout); initfact(); cin >> n >> m; mint ans = 0; fore(i, 2, m + 1){ ans += f(i); } cout << ans + mint(1) << ENDL; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll, ll> pll; #define pb push_back typedef long double ld; #define fi first #define se second #define PI 3.14159265358979323846264338327950288419716939937510 #define mp make_pair #define vvl vector<vector<ll>> #define vll vector<ll> #define vpll vector<pll> /* #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> */ ll inf = 1e18; ll p = 998244353 ; ll power(ll x, ll y, ll p) { ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } ll pwr(ll x, ll y) { ll res = 1; x = x ; while (y > 0) { if (y & 1) res = (res * x) ; y = y >> 1; x = (x * x) ; } return res; } ll modInverse(ll n, ll p) { return power(n, p - 2, p); } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); ll i, y, x, z, g, key, h, n, m, t, a, b, c, j, k; ll t2, t3, t4, t1, t5, t6; string s; ll l, r; //cin >> t; t = 1; while (t--) { cin >> n >> x; ll ncr[x + 1][x + 1]; memset(ncr, 0, sizeof(ncr)); ncr[0][0] = 1; vll val(x + 1, 0); val[0] = n; ll arr[n]; for (i = 0; i < n; i++) { cin >> arr[i]; t1 = arr[i]; for (j = 1; j <= x; j++) { val[j] = (val[j] + t1) % p; t1 = (t1 * arr[i]) % p; } } for (i = 1; i <= x; i++) { for (j = 0; j <= x; j++) { ncr[i][j] = ncr[i - 1][j]; if (j) { ncr[i][j] = (ncr[i][j] + ncr[i - 1][j - 1]) % p; } } } for (k = 1; k <= x; k++) { ll ans = 0; for (i = 0; i <= k; i++) { t1 = (ncr[k][i] * val[i]) % p; t1 = (t1 * val[k - i]) % p; ans = (ans + t1); } //cout << ans << "\n"; t2 = power(2, k, p); t2 = (t2 * val[k]) % p; ans = ((ans - t2) % p + p) % p; ans = (ans * modInverse(2, p)) % p; cout << ans << "\n"; } } return 0; }
#include <iostream> #include <string> #include <algorithm> #include <stdio.h> #include <vector> #include <math.h> #include <iomanip> #include <set> #define I int #define LL long long #define F float #define S string #define B bool #define C char #define N 200001 #define PI 3.14159265358979 using namespace std; int main() { C a,b,c; cin>>a>>b>>c; if(a==b&&b==c) { cout<<"Won"; } else cout<<"Lost"; return 0; }
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<cmath> #define res register int #define LL long long #define oo 0x3f3f3f3f using namespace std; LL Fastmul(LL a,LL b,LL p){ LL ans=0; while(b>0){ if(b&1) ans=(ans+a)%p; a=a*2%p; b>>=1; } return ans; } LL Fastpow(LL a,LL b,LL p){ LL ans=1; while(b>0){ if(b&1) ans=ans*a%p; a=Fastmul(a,a,p); b>>=1; } return ans%p; } int mp[10][4]={{0,0,0,0},{1,1,1,1},{2,4,8,6},{3,9,7,1},{4,6,4,6},{5,5,5,5},{6,6,6,6},{7,9,3,1},{8,4,2,6},{9,1,9,1}}; int main(){ int a,b,c; cin>>a>>b>>c; b=Fastpow(b,c,4); a=a%10; if(b==0) b=4; cout<<mp[a][b-1]; return 0; }
// ARC107.cpp #include <iostream> using namespace std; using ll = long long; int n; ll f(int k) { return max(0,min(k - 1, 2 * n - k + 1)); } // a+b==c+d+Kใชใ‚‰ // a+b==xใฎๆ™‚ใ€ // c+d==x-K int main() { int k; cin >> n >> k; ll ans = 0; for (int x = 2; x <= 2 * n;x++) { ans += f(x) * f(x - k); } cout << ans << endl; }
// ********************************************************************************* // * MURTAZA MUSTAFA KHUMUSI * // * NIT-DGP,CSE - 2019-2023 * // ********************************************************************************* #include <bits/stdc++.h> using namespace std; typedef long long ll; #define MOD 1000000007; #define loop(i, a, n) for (int i = a; i < n; i++) #define loop1(i, b, n) for (int i = b; i <= n; i++) #define loopit(a) for (auto it = a.begin(); it != a.end(); it++) #define ms(a, b) memset(a, b, sizeof(a)) #define pb(a) push_back(a) #define MP make_pair #define pi pair<int, int> #define ff first #define ss second #define bloop(i, a, b) for (int i = a; i > b; i--) #define bloop1(i, a, b) for (int i = a; i >= b; i--) #define PQ priority_queue<int> pq; #define vi vector<int> #define si set<int> #define MPQ priority_queue<pi, vector<int>, greater<pi>> mpq; #define io \ ios_base::sync_with_stdio(0); \ cin.tie(NULL); const int maxm = 300005; // ll m = 1e9 + 7; ll m = 998244353; vector<vi> adj; vi h; vi sz; vi in; ll add(ll a, ll b, ll mod = m) { return ((a % mod) + (b % mod)) % mod; } ll mul(ll a, ll b, ll mod = m) { return ((a % mod) * (b % mod)) % mod; } ll sub(ll a, ll b, ll mod = m) { return ((a % mod) - (b % mod) + mod) % mod; } ll modmul(ll a, ll b, ll mod = m) { ll ans = 0; a = a % mod; while (b) { if (b & 1) ans = add(ans, a, mod); a = mul(a, 2, mod); b >>= 1; } return ans; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll fe(ll base, ll exp, ll mod = m) { ll ans = 1; while (exp) { if (exp & 1) ans = mul(ans, base, mod); base = mul(base, base, mod); exp >>= 1; } return ans; } void dfs_h_sz(int cur, int par) { h[cur] = h[par] + 1; sz[cur]++; for (const auto &v : adj[cur]) { if (v == par) continue; dfs_h_sz(v, cur); sz[cur] += sz[v]; } } void buildGraph(int n, int m) { adj = vector<vi>(n + 1); h = vector<int>(n + 1); sz = vector<int>(n + 1); in = vector<int>(n + 1); loop(i, 0, m) { int a, b; cin >> a >> b; adj[a].pb(b); adj[b].pb(a); } dfs_h_sz(1, 0); } struct cmp { bool operator()(const pi &a, const pi &b) { return a.ff < b.ff; } }; ll modin(ll a) { return fe(a, m - 2); } ll sum(ll a) { return mul(mul(a, a + 1), modin(2)); } void solve() { int n,k; ll sum = 0; cin>>n>>k; int a = abs(k); int arr[maxm] ={0}; // int arr[maxm] = {0}; loop1(i,1,2*n){ if(i<=n) arr[i] = i-1; else arr[i] = 2*n-i+1; } loop1(i,2,2*n){ if(2<=i+k && i+k<=2*n) sum += 1LL*arr[i]*arr[i+k]; } cout<<sum<<"\n"; } int main() { io; // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int test; // cin >> test; test = 1; while (test--) { solve(); } return 0; }
#include <bits/stdc++.h> #define FASTIO using namespace std; using ll = long long; using Vi = std::vector<int>; using Vl = std::vector<ll>; using Pii = std::pair<int, int>; using Pll = std::pair<ll, ll>; constexpr int I_INF = std::numeric_limits<int>::max(); constexpr ll L_INF = std::numeric_limits<ll>::max(); template <typename T1, typename T2> inline bool chmin(T1& a, const T2& b) { if (a > b) { a = b; return true; } return false; } template <typename T1, typename T2> inline bool chmax(T1& a, const T2& b) { if (a < b) { a = b; return true; } return false; } template <std::ostream& os = std::cout> class Prints { private: class __Prints { public: __Prints(const char* sep, const char* term) : sep(sep), term(term) {} template <class... Args> #if __cplusplus >= 201703L auto operator()(const Args&... args) const -> decltype((os << ... << std::declval<Args>()), void()) { #else void operator()(const Args&... args) const { #endif print(args...); } template <typename T> #if __cplusplus >= 201703L auto pvec(const T& vec, size_t sz) const -> decltype(os << std::declval<decltype(std::declval<T>()[0])>(), void()) { #else void pvec(const T& vec, size_t sz) const { #endif for (size_t i = 0; i < sz; i++) os << vec[i] << (i == sz - 1 ? term : sep); } template <typename T> #if __cplusplus >= 201703L auto pmat(const T& mat, size_t h, size_t w) const -> decltype(os << std::declval<decltype(std::declval<T>()[0][0])>(), void()) { #else void pmat(const T& mat, size_t h, size_t w) const { #endif for (size_t i = 0; i < h; i++) for (size_t j = 0; j < w; j++) os << mat[i][j] << (j == w - 1 ? term : sep); } private: const char *sep, *term; void print() const { os << term; } void print_rest() const { os << term; } template <class T, class... Tail> void print(const T& head, const Tail&... tail) const { os << head, print_rest(tail...); } template <class T, class... Tail> void print_rest(const T& head, const Tail&... tail) const { os << sep << head, print_rest(tail...); } }; public: Prints() {} __Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); } }; Prints<> prints; Prints<std::cerr> prints_err; //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ll dp[101][101]; void solve() { ll N, K; cin >> N >> K; Vl A(N); for (ll i = 0; i < N; i++) { cin >> A[i]; } ll ans = L_INF; for (ll k = 1; k <= N; k++) { for (ll j = 0; j <= k; j++) { for (ll r = 0; r < k; r++) { dp[j][r] = -L_INF; } } dp[0][0] = 0; for (ll i = 0; i < N; i++) { for (ll j = k; j >= 0; j--) { for (ll r = 0; r < k; r++) { ll r_nxt = (r + A[i]) % k; if (j > 0 && dp[j - 1][r] != -L_INF) { chmax(dp[j][r_nxt], dp[j - 1][r] + A[i]); } } } } ll mx = dp[k][K % k]; if (mx != -L_INF) { chmin(ans, (K - mx) / k); } } prints()(ans); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% int main() { #ifdef FASTIO std::cin.tie(nullptr), std::cout.tie(nullptr); std::ios::sync_with_stdio(false); #endif #ifdef FILEINPUT std::ifstream ifs("./in_out/input.txt"); std::cin.rdbuf(ifs.rdbuf()); #endif #ifdef FILEOUTPUT std::ofstream ofs("./in_out/output.txt"); std::cout.rdbuf(ofs.rdbuf()); #endif std::cout << std::setprecision(18) << std::fixed; solve(); std::cout << std::flush; return 0; }
#include <iostream> #include <algorithm> #include <unordered_set> #include <set> #include <vector> #include <queue> #include <map> #include <numeric> #include <math.h> #include <complex> using namespace std; #define rep(i, n) for (long long int i = 0; i < (long long int)(n); i++) #define irep(i, n) for (long long int i = 1; i <= (long long int)(n); i++) #define drep(i, n, diff) for (long long int i = 0; i < (long long int)(n); i += diff) #define mod 1000000007 #define INF 1001001001001001011 #define ld(val) printf("%s : %lld\n", #val, val); #define sd(val) printf("%s : %s\n", #val, val.c_str()); typedef long long int ll; typedef pair<ll, ll> P; typedef pair<P, P> PP; typedef tuple<ll, ll, ll> TP; int main() { ll x, y, a, b; cin >> x >> y >> a >> b; ll ans =0; while((double)a<(double)y/x && a*x<x+b) { x*=a; ans++; } ll v = (y-x-1)/b; cout << ans + v << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(){ ll n; cin >> n; vector<ll> a(n); ll tmp1=0, tmp2=0; for(ll i=0; i<n; i++){ cin >> a[i]; tmp1 += a[i]; tmp2 += a[i]*a[i]; } ll ans; ans = n*tmp2 - tmp1*tmp1; cout << ans << endl; }
#include <iostream> #include <vector> #include <algorithm> #include <math.h> using namespace std; int main() { int n; cin >> n; // std::vector<int> vect(n); std::vector<int> v(401,0); long long int temp; for (int i = 0; i < n; ++i) { // cin >> vect[i]; cin >> temp; v[temp+200]++; } long long int res = 0; for (int i = 1; i < 401; ++i) { for (int j = 0; j < i; ++j) { temp = i-j; res += (temp * temp) * v[i] * v[j]; } } cout << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int const double pi = 3.14159265358979; const ll inf = 1e17; const int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}; const int dy[] = {1, 0, -1, 0, 1, -1, 1, -1}; #define pii pair<int,int> #define pll pair<ll,ll> #define endl "\n" #define dtor(deg) (((deg)/360)*2*pi) #define all(a) a.begin(),a.end() #define overload(_1,_2,_3,_4,name,...) name #define _rep1(n) for(int i = 0; i < (n); i++) #define _rep2(i,n) for(int i = 0; i < (n); i++) #define _rep3(i,a,b) for(int i = (a); i < (b); i++) #define _rep4(i,a,b,c) for(int i = (a); i < (b); i += (c)) #define rep(...) overload(__VA_ARGS__,_rep4,_rep3,_rep2,_rep1)(__VA_ARGS__) #define _rrep1(n) for(int i = (n) - 1; i >= 0; i--) #define _rrep2(i,n) for(int i = (n) - 1; i >= 0; i--) #define _rrep3(i,a,b) for(int i = (b) - 1; i >= (a); i--) #define _rrep4(i,a,b,c) for(int i = (b) - 1; i >= (a); i -= (c)) #define rrep(...) overload(__VA_ARGS__,_rrep4,_rrep3,_rrep2,_rrep1)(__VA_ARGS__) #define vec(type,name,...) vector<type> name(__VA_ARGS__) #define vv(type,name,size,...) vector<vector<type>> name(size,vector<type>(__VA_ARGS__)) #define ForEach(a,b) for_each(a.begin(),a.end(),b) struct Edge { int to; ll cost; Edge(int to, ll cost) : to(to), cost(cost) {} }; using Graph = vector<vector<Edge>>; template <class T> bool chmin(T& a, T b){ if(a > b){ a = b; return 1; } return 0; } template <class T> bool chmax(T& a, T b){ if(a < b){ a = b; return 1; } return 0; } void Main(){ ll n; cin >> n; cout << max((ll)0, n - 999999999999999) + max((ll)0, n - 999999999999) + max((ll)0, n - 999999999) + max((ll)0, n - 999999) + max((ll)0, n - 999) << endl; } signed main(){ cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(10) << fixed; Main(); }
#include <bits/stdc++.h> using namespace std; #define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define pb push_back #define fixx(n) fixed << setprecision(n) #define F first #define S second #define PI 3.14159265358979323846 #define ll long long int #define int ll #define double long double const int mod = 1e9 + 7; const int modd = 998244353; const int N = 1e5; signed main() { FAST; int n; cin >> n; int k = 1000; int ans = 0; while(k <= n){ ans += (n - k + 1); k *= 1000; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; typedef long long ll; #define MAX 100 double dp[MAX+1][MAX+1][MAX+1]; int main(void){ int a, b, c; cin >> a >> b >> c; for (int i = MAX-1; i >= 0; i--){ for (int j = MAX-1; j >= 0; j--){ for (int k = MAX-1; k >= 0; k--){ double now = 0; if (i+j+k == 0) continue; now += dp[i+1][j][k] * i; now += dp[i][j+1][k] * j; now += dp[i][j][k+1] * k; dp[i][j][k] = now / (i + j + k) + 1; } } } printf("%.10f\n", dp[a][b][c]); return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define forin(in) for(ll i=0; i<(ll)in.size(); i++) cin>>in[i] #define forout(out) for(ll i=0; i<(ll)out.size(); i++) cout<<out[i]<<endl #define rep(i, n) for(ll i=0; i<(n); i++) #define rep_up(i, a, n) for (ll i = a; i < n; ++i) #define rep_down(i, a, n) for (ll i = a; i >= n; --i) #define P pair<ll, ll> template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } #define all(v) v.begin(), v.end() #define fi first #define se second #define vvvll vector<vector<vector<ll>>> #define vvll vector<vector<ll>> #define vll vector<ll> #define pqll priority_queue<ll> #define pqllg priority_queue<ll, vector<ll>, greater<ll>> constexpr ll INF = (1ll << 60); constexpr ll mod = 1000000007; double v[110][110][110]; //func(a,b,c):v[a][b][c]ใ‚’่ฟ”ใ™ double func(int a,int b,int c) { if(a >= 100||b >= 100||c >= 100) return 0.0; if(v[a][b][c] > -1) return v[a][b][c]; double ans = 0; ans += (double)(a) / (a+b+c)*(func(a+1,b,c) + 1); ans += (double)(b) / (a+b+c)*(func(a,b+1,c) + 1); ans += (double)(c) / (a+b+c)*(func(a,b,c+1) + 1); v[a][b][c] = ans; return v[a][b][c]; } int main() { int a, b, c; cin >> a >> b >> c; memset(v, -1, sizeof(v)); cout << fixed << setprecision(10) << func(a,b,c) << endl; }
#include <iostream> #include <algorithm> #include <vector> #include <string> #include <cmath> #include <queue> #include <iomanip> #include <random> using namespace std; typedef long long ll; typedef pair<int, int> pii; const int mod = 1000000007; ll po(ll a, ll b) { ll c = 1; while (b) { if (b % 2) c = c * a % 998244353; a = a * a % 998244353; b >>= 1; } return c; } int main() { ios::sync_with_stdio(false); int n, m; ll z = 0, d[15][5003] = {}, f[1000006] = {1}, g[1000006] = {}; for (int i = 1; i <= 1000000; i++) f[i] = f[i - 1] * i % 998244353; for (int i = 0; i <= 1000000; i++) g[i] = po(f[i], 998244351); cin >> n >> m; d[0][0] = 1; for (int i = 1; i <= 13; i++) { for (int j = 0; j <= m; j++) { for (int k = 0; k * (1 << (i - 1)) <= j && k <= n; k += 2) { d[i][j] = (d[i][j] + d[i - 1][j - k * (1 << (i - 1))] * f[n] % 998244353 * g[k] % 998244353 * g[n - k]) % 998244353; } //cout << d[i][j] << " \n"[j == m]; } } cout << d[13][m] << '\n'; }
#pragma GCC optimize ("O2") #pragma GCC target ("avx2") //#include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; #include<iostream> #include<cstring> using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please const int CM = 320000; char cn[CM], * ci = cn, ct; const ll ma0 = 1157442765409226768; const ll ma1 = 1085102592571150095; const ll ma2 = 71777214294589695; const ll ma3 = 281470681808895; const ll ma4 = 4294967295; inline int getint() { ll tmp = *(ll*)ci; int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0); tmp = tmp << dig & ma1; tmp = tmp * 10 + (tmp >> 8) & ma2; tmp = tmp * 100 + (tmp >> 16) & ma3; tmp = tmp * 10000 + (tmp >> 32) & ma4; ci += 72 - dig >> 3; return tmp; } const int MAX = 10000; class shuturyoku_unko { public: char C[MAX * 5]; constexpr shuturyoku_unko() : C() { rep(i, MAX) { int X = i; rep(j, 4) { C[i * 5 + 3 - j] = '0' + X % 10; X /= 10; } C[i * 5 + 4] = '\n'; } } }; constexpr shuturyoku_unko f; const int dm = 260000; char dn[dm], * di = dn; void putint(ll A) { int dig = 1; if (A >= 100000000) { if (A >= 100000000000) dig = 4; else if (A >= 10000000000) dig = 3; else if (A >= 1000000000) dig = 2; memcpy(di + 4 + dig, f.C + A % 10000 * 5, 5); A /= 10000; memcpy(di + dig, f.C + A % 10000 * 5, 4); memcpy(di, f.C + A / 10000 * 5 + 4 - dig, dig); di += 9 + dig; } else { if (A >= 10000) { if (A >= 10000000) dig = 4; else if (A >= 1000000) dig = 3; else if (A >= 100000) dig = 2; memcpy(di + dig, f.C + A % 10000 * 5, 5); memcpy(di, f.C + A / 10000 * 5 + 4 - dig, dig); di += 5 + dig; } else { if (A >= 1000) dig = 4; else if (A >= 100) dig = 3; else if (A >= 10) dig = 2; memcpy(di, f.C + A * 5 + 4 - dig, dig + 1); di += 1 + dig; } } } int main() { cin.tie(0); ios::sync_with_stdio(false); fread(cn, 1, 320000, stdin); int T = getint(); rep(t, T) { int L = getint(), R = getint(); ll tmp = R - L - L; if (tmp >= 0) putint((tmp + 2) * (tmp + 1) >> 1); else putint(0); } fwrite(dn, 1, di - dn, stdout); Would you please return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; using ll = long long; using ld = long double; const int INF = 1e9; const ll LIN = 1e18; int main() { ll N; cin >> N; ll ans = LIN; for (ll i = 0; i < 64;i++) { ll b = ((ll)1 << i); ll a = N / b, c = N % b; ans = min(ans, a + i + c); } cout<<ans<<endl; }
#include<iostream> using namespace std; int main() { int N; cin >> N; cout << N - 1 << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define asll unsigned long long #define ll long long #define ld long double #define imt int #define pii pair<int,int> #define st first #define nd second #define psbk(x) push_back(x); #define For(x,a,b) for(int x=(a);x!=(b+((b-a)/abs(b-a)));x+=(b-a)/abs(b-a)) #define FOR(x,n) for(int x=0;x<(n);x++) #define m_p make_pair #define kj <<" "<< #define kjb <<" "; #define dg <<","<< #define ml <<endl; #define co cout<< #define ter cout<<endl; #define sibi cout<<"TES"<<endl; #define tes(x) cout<<"TES"<<x<<endl; #define kpr(x) cout<<"("<<x.st dg x.nd <<")" ml #define kkor(p) cout<<"("<<p.x dg p.y <<")" ml #define kera(x,m) for( int i = 0;i < m ; i++ ){ cout<<"x["<< i <<"] =" kj x[i] ml} asll M=1e9+7; int h,w,n,m; int p,q,r; int ma[1505][1505]; int terang[1505][1505]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(0); //freopen("stdin.in", "r", stdin) //freopen("stdout.out", "w", stdout) srand(time(0)); cin>>h>>w>>n>>m; FOR(i,h+1){ //hix[i]=0; FOR(j,w+1){ ma[i][j]=1; terang[i][j]=0; //hiy[j]=0; } } FOR(i,n){ cin>>p>>q; ma[p][q]=2; //hiy[q]=1; } FOR(i,m){ cin>>p>>q; ma[p][q]=0; } ll ctr=0; //c//o "-" ml int kai=0; For(i,1,h){ kai=0; For(j,1,w){ if(ma[i][j]==2){ kai=1; } else if(ma[i][j]==0){ kai=0; } if(kai==1 && ma[i][j]){ terang[i][j]=1; } } } kai=0; For(i,1,h){ kai=0; For(j,w,1){ if(ma[i][j]==2){ kai=1; } else if(ma[i][j]==0){ kai=0; } if(kai==1 && ma[i][j]){ terang[i][j]=1; } } } kai=0; For(j,1,w){ kai=0; For(i,1,h){ if(ma[i][j]==2){ kai=1; } else if(ma[i][j]==0){ kai=0; } if(kai==1 && ma[i][j]){ terang[i][j]=1; } } } kai=0; For(j,1,w){ kai=0; For(i,h,1){ if(ma[i][j]==2){ kai=1; } else if(ma[i][j]==0){ kai=0; } if(kai==1 && ma[i][j]){ terang[i][j]=1; } } } For(i,1,h){ For(j,1,w){ //co terang[i][j] kjb; if(terang[i][j]){ ctr++; } } //ter } co ctr ml }
#include <stack> #include <queue> #include <bitset> #include <unordered_set> #include <unordered_map> #include <map> #include <set> #include <tuple> #include <cmath> #include <random> #include <algorithm> #include <vector> #include <iostream> #include <fstream> #include <chrono> #include <numeric> #define fio ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr) #define rng mt19937_64 rnd(chrono::system_clock::now().time_since_epoch().count()) #define ri(...) i64 __VA_ARGS__; rx(__VA_ARGS__) #define rc(...) char __VA_ARGS__; rx(__VA_ARGS__) #define rs(...) string __VA_ARGS__; rx(__VA_ARGS__) #define rvi(x, n) vi x(n); cin >> x #define rvvi(x, n, m) vvi x(n, vi(m)); cin >> x #ifndef ONLINE_JUDGE #define dbg(...) cerr << '[' << #__VA_ARGS__ << "]: "; dbg_log(__VA_ARGS__) #else #define dbg(...) ;; #endif #define fa(i, v) for (auto &i : v) #define fi(i, n) for (i32 i = 0; i < n; i++) #define fp(i, n) for (i32 i = 1; i < n; i++) #define fr(i, n) for (i32 i = n - 1; i >= 0; i--) #define fu(i) ri(__i); fi(i, __i) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() using namespace std; typedef uint32_t u32; typedef int32_t i32; typedef uint64_t u64; typedef int64_t i64; #ifdef __SIZEOF_INT128__ typedef __uint128_t u128; typedef __int128_t i128; #endif typedef vector<i64> vi; typedef vector<vi> vvi; typedef pair<i64, i64> pi; template<typename T> inline istream &operator>>(istream &in, vector<T> &v) { fa(x, v) in >> x; return in; } template<typename T> inline ostream &operator<<(ostream &out, const vector<T> &v) { fa(x, v) out << x << ' '; return out; } template<typename T> inline void rx(T &x) { cin >> x; } template<typename T, typename... R> inline void rx(T &x, R &... l) { cin >> x; rx(l...); } template<typename T> inline void dbg_log(const T &x) { cerr << x << endl; } template<typename T, typename... R> inline void dbg_log(const T &x, const R &... l) { cerr << x << ", "; dbg_log(l...); } template<typename T> inline void wl(const T &x) { cout << x << '\n'; } template<typename T, typename... R> inline void wl(const T &x, const R &... l) { cout << x << ' '; wl<R...>(l...); } int main() { fio; ri(h, w, n, m); vvi mat(h, vi(w)); fi(i, n) { ri(a, b); mat[a - 1][b - 1] |= 0x10; } fi(i, m) { ri(c, d); mat[c - 1][d - 1] |= 0x20; } fi(i, h) { fp(j, w) { if (!(mat[i][j] & 0x30) && (mat[i][j - 1] & 0x11)) { mat[i][j] |= 0x01; } } fp(j, w) { if (!(mat[i][w - j - 1] & 0x30) && (mat[i][w - j] & 0x12)) { mat[i][w - j - 1] |= 0x02; } } } fi(j, w) { fp(i, h) { if (!(mat[i][j] & 0x30) && (mat[i - 1][j] & 0x14)) { mat[i][j] |= 0x04; } } fp(i, h) { if (!(mat[h - i - 1][j] & 0x30) && (mat[h - i][j] & 0x18)) { mat[h - i - 1][j] |= 0x08; } } } fa(row, mat) { dbg(row); } i64 res = 0; fi(i, h) { fi (j, w) { if (mat[i][j] & 0x1F) { res++; } } } wl(res); return 0; }
#include <iostream> #include <algorithm> #include <vector> #include <cstring> #include <map> #include <set> #include <unordered_map> #include <unordered_set> #include <queue> #include <iomanip> #include <math.h> #include <limits.h> #include <string> #include <bitset> using namespace std; #define pb push_back #define mp make_pair #define sz(x) ((int)x.size()) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define manytests int TT;cin >> TT; while (TT--) #define FOR(i,a,b) for (int i = (a); i < (b); ++i) #define FORd(i,a,b) for (int i = (a); i >= (b); --i) int dx[8] = {-1, 1, 0, 0, 1, 1, -1, -1}, dy[8] = {0, 0, 1, -1, 1, 1, -1, -1}; #define ll long long #define ld long double #define fi first #define se second #define rev reverse #define vi vector<int> #define vl vector<ll> #define vc vector<char> #define vd vector<double> #define vs vector<string> #define vld vector<ld> #define vb vector<bool> #define vvi vector<vi> #define pii pair<int, int> #define vpi vector<pii> int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int x, y; cin >> x >> y; if (x > y) swap(x, y); if (x+3>y) cout << "Yes\n"; else cout << "No\n"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef unsigned long long int ull; typedef long double ld; #define MULTI 1 void pre() { } #define SQR(x) ((x)*(x)) void solve() { ll l, r; cin >> l >> r; if (r >= 2 * l) { ll x = r - 2 * l + 1; ll ans; if (x % 2 == 1) ans = SQR((x + 1) / 2); else ans = x / 2 * (x / 2 + 1); cout << 2 * ans - (r / 2 - l + 1) << endl; } else cout << 0 << endl; } int main() { pre(); #ifdef MULTI int T; cin >> T; for (int t = 0; t < T; ++t) { #endif solve(); #ifdef MULTI } #endif return 0; }
#include<bits/stdc++.h> using namespace std; int h,w,a,b; int res=0; bool vis[20][20]; void dfs(int n,int m) //n 2*1 m 1*1 { int flag=0; for(int i=1;i<=h;i++) { for(int j=1;j<=w;j++) { if(!vis[i][j]) { flag=1; if(m) { vis[i][j]=1; dfs(n,m-1); vis[i][j]=0; } if(n) { if(j+1<=w&&!vis[i][j+1]) { vis[i][j]=1; vis[i][j+1]=1; dfs(n-1,m); vis[i][j]=0; vis[i][j+1]=0; } if(i+1<=h&&!vis[i+1][j]) { vis[i][j]=1; vis[i+1][j]=1; dfs(n-1,m); vis[i][j]=0; vis[i+1][j]=0; } } return ; } } } if(!flag) res++; } int main() { cin>>h>>w>>a>>b; dfs(a,b); cout<<res<<endl; }
#include <string> #include <iostream> using namespace std; using ll=long long; using ull=unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) const int W=30, H=30; const int query_num = 1000; int main(){ for(int i=0; i<query_num; i++){ int sy,sx,ty,tx; cin >> sy >> sx >> ty >> tx; string ans = ""; while(sx != tx){ if(sx < tx){ ans += "R"; sx++; } else{ ans += "L"; sx--; } } while(sy != ty){ if(sy < ty){ ans += "D"; sy++; } else{ ans += "U"; sy--; } } cout << ans << "\n" << flush; int result; cin >> result; } return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ ios::sync_with_stdio(false); cin.tie(nullptr); } } ios_do_not_sync_instance;
#include <bits/stdc++.h> using namespace std; int main() { long long a,b,c,d; cin >> a >> b >> c >> d; long long n = 0; long long mizu = a; long long aka = 0; if (b >= c*d){ cout << -1 << endl; } else { while (mizu > aka * d) { mizu += b; aka += c; n++; } cout << n << endl; } }
#include <bits/stdc++.h> #define M0D 1000000007 #define rep(i, n) for(int i=0; i<n; i++) using namespace std; int main(){ int n,k,m,ans; cin >> n >> k >> m; int a[n],sum=0; rep(i,n-1){ cin >> a[i]; sum += a[i]; } ans = n*m - sum; if(ans>k) cout << "-1" << endl; else if(ans<0) cout << "0" << endl; else cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using llong = long long; using ullong = unsigned long long; int main() { int N, Q; cin >> N >> Q; vector<ullong> A(N); for (auto &x: A) cin >> x; sort(A.begin(), A.end()); for (int q = 0; q < Q; ++q) { ullong K; cin >> K; ullong target = K; size_t d1 = 0; while (true) { auto pos = lower_bound(A.begin(), A.end(), target); size_t d2 = distance(A.begin(), pos); ullong num = 0; if (d1 == d2) { if (*pos == target) { num = d2 + 1; } else { cout << target << endl; break; } } else { if (*pos == target) num = d2 + 1; else num = d2; } d1 = d2; target = K + num; } } }
#include<iostream> #include<bits/stdc++.h> using namespace std; long long int missingK(long long int arr[],int n, long long int k) { long long int l = 0, u = n - 1, mid; while(l <= u) { mid = (l + u)/2; long long int numbers_less_than_mid = arr[mid] - (mid + 1); if(numbers_less_than_mid == k) { if(mid > 0 && (arr[mid - 1] - (mid)) == k) { u = mid - 1; continue; } return arr[mid]-1; } if(numbers_less_than_mid < k) { l = mid + 1; } else if(k < numbers_less_than_mid) { u = mid - 1; } } if(u < 0) return k; long long int less = arr[u] - (u + 1); k -= less; return arr[u] + k; } int main(){ int n,q; cin>>n>>q; long long int a[n]; for(int i=0;i<n;i++) cin>>a[i]; long long int k; while(q--){ cin>>k; cout<<missingK(a,n,k)<<endl; } }
#include <bits/stdc++.h> using namespace std; #define int long long #define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); #define all(x) (x).begin(), (x).end() #define pb push_back #define pii pair<int, int> #define ff first #define ss second #define PI acos(-1) #define ld long double template<class T> bool chmin(T& a, const T& b) {return a>b? a=b, true:false;} template<class T> bool chmax(T& a, const T& b) {return a<b? a=b, true:false;} const int mod = 1e9+7, N = 2e5+5; inline int msb(int val){return sizeof(int)*8-__builtin_clzll(val)-1;} int a[N], n, m, k; int b[N]; void solve(int test_case){ int i, j; cin >> n; for(i=0;i<n;i++) cin >> a[i] >> b[i]; int ans = mod; for(i=0;i<n;i++){ chmin(ans, a[i] + b[i]); } for(i=0;i<n;i++){ int al = a[i]; int mn = mod; for(j=0;j<n;j++){ if(i == j)continue; chmin(mn, b[j]); } chmin(ans, max(al,mn)); } cout << ans << '\n'; return; } signed main(){ FASTIO; //~ #define MULTITEST 1 #if MULTITEST int _T; cin >> _T; for(int T_CASE = 1; T_CASE <= _T; T_CASE++) solve(T_CASE); #else solve(1); #endif return 0; }
#include<bits/stdc++.h> using namespace std; using I=int; const int M = 1<<18; I n,s,t,F[M],p[M],E[M],d[M],D; vector<I>G[M]; void dfs(I x,I f,I&s) { F[x]=f;d[x]=d[f]+1;if(d[x]>d[s])s=x; for (I&y:G[x])if(y^f)dfs(y,x,s); } void dfs2(I u,I f) { E[u]=++D; for(I&v:G[u])if(v!=f&&!p[v])dfs2(v,u); for(I&v:G[u])if(v!=f&&p[v])dfs2(v,u); ++D; } I main() { cin>>n; for(I u,v,i=1;i<n;++i) { cin>>u>>v; G[u].push_back(v); G[v].push_back(u); } dfs(1,0,s),dfs(s,0,t); for(I u=t;u;u=F[u])p[u]=1; dfs2(s,0); for(I i=1;i<=n;++i)cout<<E[i]<<" \n"[i==n]; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; int64_t K; cin >> K; vector<vector<int64_t>> dp(4, vector<int64_t>(4 * N + 10, 0)); dp[0][0] = 1; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3 * N + 1; j++) { dp[i + 1][j + 1] += dp[i][j]; dp[i + 1][j + N + 1] -= dp[i][j]; } for (int j = 0; j < 3 * N + 1; j++) { dp[i + 1][j + 1] += dp[i + 1][j]; } } int x = 0; for (int i = 0; i < 3 * N + 1; i++) { if (K <= dp[3][i]) { x = i; break; } K -= dp[3][i]; } for (int i = 1; i < N + 1; i++) { int mi = max(1, x - i - N); int ma = min(N, x - i - 1); if (mi > ma) continue; if (K > ma - mi + 1) { K -= ma - mi + 1; continue; } int j = mi + K - 1; int k = x - i - j; cout << i << ' ' << j << ' ' << k << '\n'; return 0; } return 0; }
#include<bits/stdc++.h> using namespace std; const long long mod=1e9+7,INF=1e18; #define ll long long #define line cout<<"\n"; #define flush cout<<endl; #define pll pair<ll,ll> #define x first #define y second #define p_all(arr) for(auto i:arr){cout<<i<<" ";}cout<<"\n"; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); ll t=1; // cin>>t; for(ll test=1;test<=t;test++) { string s; ll k; cin>>s>>k; ll n=s.size(); vector<ll> num(n); for(int i=0;i<n;i++) { if(s[i]<='9') { num[i]=s[i]-'0'; } else { num[i]=10+s[i]-'A'; } } ll dp[n+1][17][2]; memset(dp,0,sizeof(dp)); dp[0][1][1]=num[0]-1; for(int i=0;i<n;i++) dp[i][0][1]=1; set<ll> set1; set1.insert(num[0]); dp[0][1][0]=1; for(int i=1;i<n;i++) { ll c1=0,c2=num[i]; for(auto v:set1) { if(v<num[i]) c1++; } c2-=c1; set1.insert(num[i]); dp[i][set1.size()][0]=1; for(ll l=0;l<=16;l++) { dp[i][l][1]=(dp[i][l][1]+l*dp[i-1][l][1])%mod; if(l<16) { if(l==0) dp[i][l+1][1]=(dp[i][l+1][1]+(15LL-l)*dp[i-1][l][1])%mod; else dp[i][l+1][1]=(dp[i][l+1][1]+(16LL-l)*dp[i-1][l][1])%mod; } dp[i][l][1]=(dp[i][l][1]+c1*dp[i-1][l][0])%mod; if(l<16) dp[i][l+1][1]=(dp[i][l+1][1]+c2*dp[i-1][l][0])%mod; } } cout<<(dp[n-1][k][0]+dp[n-1][k][1])%mod<<"\n"; } return 0; }
#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #define REP(i, n) for (ll i = 0; i < n; i++) #define REPR(i, n) for (ll i = n; i >= 0; i--) #define FOR(i, m, n) for (ll i = m; i < n; i++) #define FORR(i, m, n) for (ll i = m; i >= n; i--) #define REPO(i, n) for (ll i = 1; i <= n; i++) #define ll long long #define INF (ll)1 << 60 #define MINF (-1 * INF) #define ALL(n) n.begin(), n.end() #define MOD 1000000007 #define P pair<ll, ll> int main(){ ll t; cin >> t; REP(i, t){ ll n; string a; cin >> n >> a >> a >> a; cout << 0; REP(i, n)cout << 1; REP(i, n)cout << 0; cout << endl; } }
/* -*- coding: utf-8 -*- * * a.cc: A - Long Common Subsequence */ #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<iostream> #include<string> #include<vector> #include<map> #include<set> #include<stack> #include<list> #include<queue> #include<deque> #include<algorithm> #include<numeric> #include<utility> #include<complex> #include<functional> using namespace std; /* constant */ const int MAX_N = 100000; /* typedef */ /* global variables */ char s[MAX_N * 2 + 4]; /* subroutines */ /* main */ int main() { int tn; scanf("%d", &tn); while (tn--) { int n; scanf("%d", &n); for (int i = 0; i < 3; i++) scanf("%s", s); for (int i = 0; i < n; i++) putchar('0'); for (int i = 0; i < n; i++) putchar('1'); putchar('0'); putchar('\n'); } return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define FASTIO {ios_base::sync_with_stdio(false);cin.tie(NULL);} //************ functions ll gcd(ll a,ll b){ if(b==0) return a; return gcd(b,a%b); } ll pow(ll a,ll m){ ll m0 = m; ll y = 0, x = 1; if (m == 1) return 0; while (a > 1) { // q is quotient ll q = a / m; ll t = m; // m is remainder now, process same as // Euclid's algo m = a % m, a = t; t = y; // Update y and x y = x - q * y; x = t; } // Make x positive if (x < 0) x += m0; return x; } int main(){ FASTIO; //sieve(); int t; cin>>t; while(t--){ ll n,s,k; cin>>n>>s>>k; ll a,b,c; ll d=gcd(k,gcd(n-s,n)); a=k/d; b=(n-s)/d; c=n/d; //cout<<a<<' '<<b<<' '<<c<<' '<<d<<endl; if(gcd(a,c)!=1) cout<<-1; else{ cout<<pow(a,c)*b%c; } cout<<endl; } }
#include<iostream> #include<string> #include<vector> #include<utility> #include<algorithm> #include<map> #include<set> #include<cstdlib> #include<cmath> #include<numeric>//fill #include<iomanip> #include<functional>//https://cpprefjp.github.io/reference/functional/function.html #include<cstdlib>//https://cpprefjp.github.io/reference/cstdlib.html #include<queue> #include<deque> #include<cassert> #include<stack> #include <iterator> // std::back_inserter //#include<atcoder/all> using namespace std; //using namespace atcoder; const double PI = acos(-1); using ll = long long; using P = pair<ll,ll>; #define rep(i,n)for(ll i=0;i<(n);i++) #define repp(x,arr) for(auto& x:arr) #define repp2(x,y,arr) for(auto& [x,y]:arr) #define all(a) (a.begin()),(a.end()) const ll MOD = 1e9 + 7; const ll inf = (ll)1e18+6; // ใƒ‡ใƒ•ใ‚ฉใƒซใƒˆใฏๆ•ดๆ•ฐ้ƒจใ‚‚ๅซใ‚ใŸๆกๆ•ฐๆŒ‡ๅฎš //cout <<setprecision(); ll myPow(ll x, ll n, ll m) { if (n == 0) return 1; if (n % 2 == 0) return myPow(x * x % m, n / 2, m); else return x * myPow(x, n - 1, m) % m; } double dl[4] = { 0,0,0.1,0.1 }; double dr[4] = { 0,-0.1,0,-0.1 }; int main() { ios::sync_with_stdio(false); //ll a, b, c, d; //cin >> a >> b >> c >> d; //if (a == 0) { // cout << 0; // return 0; //} //if (c <= b) { // cout << -1; // return 0; //} //ll aka = 0; //ll mizu = a; //ll ans = 0; //while (mizu > aka * d) { // ans++; // aka += c; // mizu += b; //} //cout << ans; ll N; cin >> N; vector<double>l(N), r(N); rep(i, N) { int t; cin >>t>> l[i] >> r[i]; t--; l[i] += dl[t]; r[i] += dr[t]; } ll ans = 0; for (int i = 0; i < N; i++) { for (int j = i + 1; j < N; j++) { if(r[j]<l[i]||r[i]<l[j])continue; ans++; } } cout << ans; }
#include <cstdio> const int Maxn=400000; int fac[Maxn+5],num[Maxn+5],inv_f[Maxn+5],inv_n[Maxn+5]; void init(){ fac[0]=1; for(int i=1;i<=Maxn;i++){ fac[i]=fac[i-1],num[i]=num[i-1]; int x=i; while(x%3==0){ x/=3; num[i]++; } fac[i]=1ll*fac[i-1]*x%3; } inv_f[Maxn]=fac[Maxn],inv_n[Maxn]=num[Maxn]; for(int i=Maxn-1;i>=0;i--){ int x=i+1; inv_f[i]=inv_f[i+1],inv_n[i]=inv_n[i+1]; while(x%3==0){ x/=3; inv_n[i]--; } inv_f[i]=1ll*inv_f[i+1]*x%3; } } int C(int n,int m){ if(num[n]-inv_n[m]-inv_n[n-m]!=0){ return 0; } return fac[n]*inv_f[m]*inv_f[n-m]%3; } char s[Maxn+5]; int main(){ init(); int n; scanf("%d",&n); scanf("%s",s+1); int ans=0; for(int i=1;i<=n;i++){ int val=(s[i]=='B'?0:(s[i]=='W'?1:2)); ans=(ans+1ll*C(n-1,i-1)*val)%3; } if(ans==0){ putchar('B'); } else if((ans&1)^(n&1)){ putchar('R'); } else{ putchar('W'); } return 0; }
using namespace std; #include <bits/stdc++.h> #define N 400005 #define ll long long int n; char str[N]; int c[3][3]; int C(int m,int n){ // if (m<n) return 0; // return fac[m]*ifac[n]%mo*ifac[m-n]%mo; if (m<3 && n<3) return c[m][n]; return C(m/3,n/3)*C(m%3,n%3); } int id[255]; int re[3]={'B','W','R'}; int main(){ // freopen("in.txt","r",stdin); scanf("%d%s",&n,str); for (int i=0;i<3;++i){ c[i][0]=1; for (int j=1;j<3;++j) c[i][j]=(c[i-1][j-1]+c[i-1][j])%3; } int ans=0; id['B']=0,id['W']=1,id['R']=2; for (int i=0;i<n;++i) ans+=id[str[i]]*C(n-1,i); if (n-1&1) ans*=-1; ans=(ans%3+3)%3; printf("%c\n",re[ans]); return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long LL; set<string> Set; LL getMin(string s){ sort(s.begin(), s.end()); LL ans = 0; for(int i = 0;i<s.size();++i) { ans = ans *10+s[i]-'0'; } return ans; } LL getMax(string s){ sort(s.begin(), s.end(), greater<LL>()); LL ans = 0; for(int i = 0;i<s.size();++i) { ans = ans *10+s[i]-'0'; } return ans; } string getString(LL d){ string s=""; if(d==0) { return "0"; } while(d){ s += d%10+'0'; d/=10; } reverse(s.begin(),s.end()); return s; } int main() { string s; LL d; cin >> d; s = getString(d); int n; cin >> n; LL b=d, a=0; while(n--){ a = getMin(s); b = getMax(s); s = getString(b-a); //cout << a << " " << b << " " << s << "\n"; } cout <<s << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; using namespace chrono; #if __has_include(<atcoder/all>) #include <atcoder/all> using namespace atcoder; #endif int main() { int64_t n, k; cin >> n >> k; auto f = [](int64_t x) -> int64_t { string s(to_string(x)), t(s); sort(s.begin(), s.end(), greater<>()); sort(t.begin(), t.end()); return stoll(s) - stoll(t); }; int64_t a = n; for (int64_t i = 0; i < k; i++) { a = f(a); } cout << a << endl; return 0; }
// {{{ by unolight #include <bits/stdc++.h> #include <unistd.h> #pragma GCC diagnostic ignored "-Wunused-result" #pragma GCC diagnostic ignored "-Wunused-function" #define SZ(x) ((int)(x).size()) #define ALL(x) begin(x),end(x) #define RALL(x) rbegin(x),rend(x) #define REP(i,n) for ( int i=0; i<int(n); i++ ) #define REP1(i,a,b) for ( int i=(a); i<=int(b); i++ ) #define MP make_pair #define PB push_back using namespace std; typedef int64_t LL; typedef pair<int,int> PII; typedef vector<int> VI; namespace { namespace unolight { // Read Input template<class T> void _R( T &x ) { cin>>x; } void _R( int &x ) { scanf("%d",&x); } void _R( int64_t &x ) { scanf("%" PRId64,&x); } void _R( double &x ) { scanf("%lf",&x); } void _R( char &x ) { scanf(" %c",&x); } void _R( char *x ) { scanf("%s",x); } void R() {} template<class T, class... U> void R( T& head, U&... tail ) { _R(head); R(tail...); } // Write Output template<class T> void _W( const T &x ) { cout<<x; } void _W( const int &x ) { printf("%d",x); } void _W( const int64_t &x ) { printf("%" PRId64,x); } void _W( const double &x ) { printf("%.16f\n",x); } void _W( const char &x ) { putchar(x); } void _W( const char *x ) { printf("%s",x); } template<class T> void _W( const vector<T> &x ) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); } void W() {} template<class T, class... U> void W( const T& head, const U&... tail ) { _W(head); putchar(sizeof...(tail)?' ':'\n'); W(tail...); } #ifdef UNOLIGHT #include "dump.hpp" #else #define dump(...) #endif template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; } template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; } template<class T> using MaxHeap = priority_queue<T>; template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>; template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) { sort(begin(v),end(v),f); v.resize(unique(begin(v),end(v))-begin(v)); } // }}} void main() { int n; R(n); VI a(n),b(n); REP(i,n) R(a[i]); REP(i,n) R(b[i]); int l=0,r=1000; REP(i,n) { chmax(l,a[i]); chmin(r,b[i]); } int ans=max(0,r-l+1); W(ans); } // {{{ main }} int main() { unolight::main(); return 0; } // }}}
#include "bits/stdc++.h" #define int long long using namespace std; using i128 = __int128_t; random_device rd; mt19937 gen(rd()); #define random_shuffle(begin, end) shuffle(begin, end, gen) template <typename T, typename U> ostream& operator << (ostream& out, const pair <T, U> &p) { out << p.first << ": " << p.second; return out; } template <typename Container> ostream& print_container(ostream& out, const Container &container, const string &open, const string &close, const string sep=", ") { out << open; for (const auto &elem : container) out << elem << sep; out << "\b\b" << close << endl; return out; } template <typename T> ostream& operator << (ostream& out, const vector<T> &v) { return print_container(out, v, "[", "]"); } template <typename T> ostream& operator << (ostream& out, const set<T> &s) { return print_container(out, s, "{", "}"); } template <typename T> ostream& operator << (ostream& out, const unordered_set<T> &s) { return print_container(out, s, "{", "}"); } template <typename K, typename V> ostream& operator << (ostream& out, const map<K, V> &s) { return print_container(out, s, "{", "}"); } template <typename K, typename V> ostream& operator << (ostream& out, const unordered_map<K, V> &s) { return print_container(out, s, "{", "}"); } template<typename... Args> void writeln(Args... args) { ((cout << args << " "), ...); cout << endl; } namespace std { template <typename T, typename U> struct hash<pair <T, U> > { size_t operator()(const pair <T, U> &p) const { hash<int> hasher; size_t seed = 0; seed ^= hasher(p.first) + 0x9e3779b9 + (seed<<6) + (seed>>2); seed ^= hasher(p.second) + 0x9e3779b9 + (seed<<6) + (seed>>2); return seed; } }; } // End of template int32_t main() { ios_base::sync_with_stdio(false); #ifdef LOCAL_JUDGE if (freopen("input.txt", "r", stdin) == NULL) { cerr << "Couldn't open file for reading" << endl; return 0; } #endif int n; cin >> n; vector <int> a(n), b(n); for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 0; i < n; ++i) cin >> b[i]; int ma = a[0], mi = b[0]; for (int i = 0; i < n; ++i) { ma = max(ma, a[i]); mi = min(mi, b[i]); } cout << max(0LL, mi - ma + 1) << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; //#define int long long #define rep(i, n) for (int i = 0; i < (int)(n); i++) //g++ a.cpp //./a.out //oj d https://atcoder.jp/contests/abc205/tasks/abc205_a //oj t int main(){ double a, b; cin >> a >> b; double c; c = a / 100; double d; d = c * b; cout << d << endl; }
#include <bits/stdc++.h> using namespace std; int main(){ double a,b;cin>>a>>b; cout<<(a/100)*b; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int v, t, s, d; cin >> v >> t >> s >> d; if (v * t <= d && d <= v * s) { cout << "No\n"; } else { cout << "Yes\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int a,b,c; cin>>a>>b>>c; if(c%2==0){ a = abs(a); b = abs(b); if(a>b){ cout<<">"; return 0; }else if(a==b){ cout<<"="; return 0; }else{ cout<<"<"; return 0; } } // if i'm here c is odd so now if a>b if(a>b){ cout<<">"; return 0; }else if(a==b){ cout<<"="; return 0; }else{ cout<<"<"; return 0; } }
#include <bits/stdc++.h> // #include <atcoder/all> // using namespace atcoder; #define _overload3(_1,_2,_3,name,...) name #define _rep(i,n) repi(i,0,n) #define repi(i,a,b) for(int i=int(a);i<int(b);++i) #define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__) #define rrep(i,n) for(int i=int(n-1);i>=int(0);--i) #define fore(i,a) for(auto &i:a) #define all(x) x.begin(),x.end() #define sz(x) ((int)(x).size()) #define bp(x) (__builtin_popcount((long long)(x))) #define pb push_back #define eb emplace_back #define mp make_pair #define V vector #define P pair<int,int> #define TP tuple<int,int,int> #define F first #define S second 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; } using ll = long long; using ld = long double; using namespace std; const int INF = 1001001001; const ll INFL = 1001001001001001001; const int MAX = 2e6+1; template<int MOD> struct Fp { long long val; constexpr Fp(long long v = 0) noexcept : val(v % MOD) { if (val < 0) val += MOD; } constexpr int getmod() { return MOD; } constexpr Fp operator - () const noexcept { return val ? MOD - val : 0; } constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; } constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; } constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; } constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; } constexpr Fp& operator += (const Fp& r) noexcept { val += r.val; if (val >= MOD) val -= MOD; return *this; } constexpr Fp& operator -= (const Fp& r) noexcept { val -= r.val; if (val < 0) val += MOD; return *this; } constexpr Fp& operator *= (const Fp& r) noexcept { val = val * r.val % MOD; return *this; } constexpr Fp& operator /= (const Fp& r) noexcept { long long a = r.val, b = MOD, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } val = val * u % MOD; if (val < 0) val += MOD; return *this; } constexpr bool operator == (const Fp& r) const noexcept { return this->val == r.val; } constexpr bool operator != (const Fp& r) const noexcept { return this->val != r.val; } friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept { return os << x.val; } friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept { if (n == 0) return 1; auto t = modpow(a, n / 2); t = t * t; if (n & 1) t = t * a; return t; } }; const int MOD = 1000000007; //const int MOD = 998244353; using mint = Fp<MOD>; int main() { int n;cin>>n; V<ll> a(n); rep(i,n)cin>>a[i]; a.push_back(0); sort(all(a)); mint ans=1; rep(i,1,n+1){ ans*=a[i]-a[i-1]+1; } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> // #include <atcoder/all> #define rep(i, s, t) for (int i = s; i < t; ++i) using namespace std; // using namespace atcoder; using ll = long long; using P = pair<int, int>; constexpr int INF = (int)2e9; constexpr ll INFll = (ll)1e18; constexpr int MOD = 1e9 + 7; struct edge { int to, cost; edge(int t, int c) : to(t), cost(c) {} }; vector<vector<edge>> G; int R, C; int dijkstra(int s, int t) { priority_queue<P, vector<P>, greater<P>> que; vector<int> d(2 * R * C, INF); que.emplace(s, 0); d[s] = 0; while (!que.empty()) { auto p = que.top(); que.pop(); int curd = p.first, curv = p.second; if (curd > d[curv]) continue; for (auto e : G[curv]) { if (curd + e.cost < d[e.to]) { d[e.to] = curd + e.cost; que.emplace(d[e.to], e.to); } } } return d[t]; } int main() { cin >> R >> C; G.resize(2 * R * C); rep(r, 0, R) rep(c, 0, C - 1) { int a; cin >> a; G[r * C + c].emplace_back(r * C + c + 1, a); G[r * C + c + 1].emplace_back(r * C + c, a); } rep(r, 0, R - 1) rep(c, 0, C) { int b; cin >> b; G[r * C + c].emplace_back((r + 1) * C + c, b); } rep(r, 0, R) rep(c, 0, C) { G[r * C + c].emplace_back(r * C + c + R * C, 1); G[r * C + c + R * C].emplace_back(r * C + c, 0); } rep(r, 0, R - 1) rep(c, 0, C) { G[(r + 1) * C + c + R * C].emplace_back(r * C + c + R * C, 1); } cout << dijkstra(0, R * C - 1) << endl; }
#include<bits/stdc++.h> #define ll long long #define mi 0x7fffffff using namespace std; int num; int betercallabdo(vector<int>arr) { int sum=0,n=arr.size(); for(int i=0;i<n-1;i++){ int min1=mi,pos=0; for(int j=i;j<n;j++) { min1=min(min1,arr[j]); if(min1==arr[j])pos=j; } reverse(arr.begin()+i,arr.begin()+pos+1); sum+=abs(pos-i)+1; } return sum; } void H2A() { /* int n,k; scanf("%d%d",&n,&k); vector<int>v(n); for(int i=0;i<n;i++)v[i]=i+1; int counter=0; do{ int ans=betercallabdo(v); if(ans==k) { printf("Case #%d: ",++num); for(int i=0;i<n;i++) {if(i!=n-1)cout<<v[i]<<" ";else cout<<v[i];}cout<<"\n";return; } }while(next_permutation(v.begin(),v.end())); printf("Case #%d: ",++num); cout<<"IMPOSSIBLE\n";*/ string s; cin>>s;cout<<s[1]<<s[2]<<s[0]; } int main() { int t=1;//scanf("%d",&t); while(t--) H2A(); }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double int main() { string S; cin >> S; int ans = 0; for (int i = 0; i < 9; i++) { if (S.substr(i, 4) == "ZONe") ans++; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define ALL(x) ((x).begin()), ((x).end()) #define READ(x) (cin >> (x)) #define WRITE_N(x) (cout << (x) << endl) #define WRITE(x) (cout << (x)) #define WRITE_YESNO(x) (WRITE_N((x) ? "Yes" : "No")) #define PRECISE_COUT std::cout << std::setprecision(15) << std::fixed bool xor_logic(bool x, bool y) { return (x && y) || (!x && !y); } #define DIVIDER 1000000007LL ll solve(ll N, ll A, ll B) { if (A + B > N) { return 0; } ll retv = (((N - A + 1) * (N - A + 1)) % DIVIDER) * (((N - B + 1) * (N - B + 1)) % DIVIDER); retv %= DIVIDER; ll x = (N - A + 1) * (N - B + 1) - (N - A - B + 1) * (N - A - B + 2); x = x % DIVIDER; retv = (retv - ((x * x) % DIVIDER) + DIVIDER) % DIVIDER; return retv; } int main() { // get values from input cin.tie(0); ios::sync_with_stdio(false); int T; cin >> T; // main procedure vector<ll> ans; for (size_t i = 0; i < T; i++) { ll N, A, B; cin >> N >> A >> B; ans.push_back(solve(N, A, B)); } // output for (size_t i = 0; i < T; i++) { cout << ans[i] << endl; } return 0; }
#include <bits/stdc++.h> #define sz(x) (int)(x).size() #define all(x) (x).begin(), (x).end() using namespace std; typedef long long ll; typedef unsigned long long llu; typedef pair<int, int> pii; typedef pair<double, double> pdd; typedef pair<int, pii> piii; typedef pair<ll, ll> pll; typedef pair<ll, int> pli; typedef pair<int, ll> pil; typedef pair<string, int> psi; typedef pair<char, int> pci; typedef pair<int, char> pic; const int MOD = 1e9 + 7; const long double PI = 3.141592653589793238462643383279502884197; ll fac[1] = {1}, inv[1] = {1}; ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} ll mp(ll a,ll b){ll ret=1;while(b){if(b&1)ret=ret*a%MOD;a=a*a%MOD;b>>=1;}return ret;} ll cmb(ll r, ll c) {return (c>r||c<0) ? 0:fac[r] * inv[c] % MOD * inv[r - c] % MOD;} ll sum = 0; ll dd[200000]; ll ans[200000]; vector<int> v[200000]; int p[200000]; pii ed[200000]; // ์—ฌ๊ธฐ๋ฅผ ๋ฃจํŠธ๋กœ ํ•˜๋Š” ์• ๋“ค.. void pre(int o, int pa) { p[o] = pa; for (int i : v[o]) { if (i == pa) continue; pre(i, o); } } void go(int o, int pa, ll ss) { ss += dd[o]; ans[o] = sum + ss; for (int i : v[o]) { if (i == pa) continue; go(i, o, ss); } } int main() { int n; scanf("%d", &n); for (int i = 0; i < n - 1; i++) { int a, b; scanf("%d %d", &a, &b); a--; b--; ed[i] = {a, b}; v[a].push_back(b); v[b].push_back(a); } pre(0, 0); int q; scanf("%d", &q); for (int i = 0; i < q; i++) { int a,b,c; scanf("%d %d %d", &a, &b, &c); b--; if (a == 1) { if (p[ed[b].second] == ed[b].first) { sum += c; dd[ed[b].second] -= c; } else dd[ed[b].first] += c; } else { if (p[ed[b].first] == ed[b].second) { sum += c; dd[ed[b].first] -= c; } else dd[ed[b].second] += c; } } go(0, 0, 0); for (int i = 0; i < n; i++) printf("%lld\n", ans[i]); } // author: rdd6584
#include <algorithm> #include <cctype> #include <cmath> #include <cstring> #include <iostream> #include <sstream> #include <numeric> #include <map> #include <set> #include <queue> #include <vector> using namespace std; typedef long long LL; int solve(std::vector<int> &r, std::vector<int> &c) { LL ans = 0; LL x = abs(c[1] - c[0]), y = abs(r[1] - r[0]); LL h = (x + y) / 2; if (h >= 3) { ++ans; x = abs(x - h); y = abs(y - h); } if (x > y) swap(x, y); if (x == y) { ans += x >= 1; } else { ans += 1 + !(x <= 2 && y <= 2 || x == 0 && y == 3); } return ans; } int solve2(std::vector<int>& r, std::vector<int>& c) { const int dy[4] = { -1, -1, 1, 1 }; const int dx[4] = { -1, 1, -1, 1 }; set<pair<int, int>> s; vector<pair<int, int>> q; q.emplace_back(make_pair(r[0], c[0])); for (int i = 0; i < 3; ++i) { vector<pair<int, int>> nq; for (auto kv : q) { if (kv.first == r[1] && kv.second == c[1]) return i; for (int y = kv.first - 3; y <= kv.first + 3; ++y) { for (int x = kv.second - 3; x <= kv.second + 3; ++x) { if (abs(kv.first - y) >= 3 && x != kv.second) continue; if (abs(kv.second - x) >= 3 && y != kv.first) continue; if (s.find(make_pair(y, x)) == s.end()) { s.insert(make_pair(y, x)); nq.emplace_back(make_pair(y, x)); } } } for (int d = 3; d <= 8; ++d) { for (int dir = 0; dir < 4; ++dir) { int y = kv.first + dy[dir] * d, x = kv.second + dx[dir] * d; if (s.find(make_pair(y, x)) == s.end()) { s.insert(make_pair(y, x)); nq.emplace_back(make_pair(y, x)); } } } } q = nq; } return 3; } int main() { std::vector<int> r(2), c(2); for (int i = 0; i < 2; i++) { std::cin >> r[i]; std::cin >> c[i]; } int ans = solve(r, c); cout << ans << endl; #if defined(_WIN32) && defined(NDEBUG) for (int t = 0; t < 1000; ++t) { r = { (rand() % 10) - 5, (rand() % 10) - 5 }; c = { (rand() % 10) - 5, (rand() % 10) - 5 }; int x = solve(r, c); int y = solve2(r, c); if (x != y) { printf("FAILED! %d,%d,%d,%d\n", r[0], c[0], r[1], c[1]); ++x; } } #endif return 0; }
#include<bits/stdc++.h> using namespace std; #define inf 1001000009 #define infmx 1e18ll #define ff first #define ss second #define ll long long #define pb push_back #define IOS ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL) #define all(x) x.begin(),x.end() ///debug #define wh(x) cerr<<#x<<" is "<<x<<endl; #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){cout<<endl;} template<class H,class... T>void err(istream_iterator<string>it,H a,T... t){cerr<<*it<<" = "<<a<<" | ";err(++it,t...);} template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;}; template<class T>auto&operator<<(ostream& os,vector<T>_v){bool a=1;for(auto x:_v){os<<(a?"":" ")<<x;a=0;}return os;} /// typedef pair<ll,ll>pi; typedef pair<long long,long long>pll; typedef pair<pi,ll>ppi; typedef pair<ll,pi>pip; typedef vector<ll>vi; typedef vector<pi>vpi; const ll mod=1e9+7; ll power(ll a,ll p){ll r=1,y=a;while(p){if(p&1)r=(1LL*r*y)%mod;p>>=1;y=(1LL*y*y)%mod;}return r;} const ll N=2100000; ll ara[N]; int main() { IOS; ll a,b; ll c,d; cin>>a>>b>>c>>d; ll ans; if(a==c&&b==d)ans=0; else if(a-b==c-d)ans=1; else if(a+b==c+d)ans=1; else if(abs(c-a)+abs(d-b)<=3)ans=1; else if((abs(a-b)%2)==(abs(c-d)%2))ans=2; else if(abs((a-b)-(c-d))<=3)ans=2; else if(abs((a+b)-(c+d))<=3)ans=2; else if(abs(a-c)+abs(b-d)<=6)ans=2; else ans=3; cout<<ans<<endl; }
#include <algorithm> #include <iomanip> #include <array> #include <bitset> #include <cassert> #include <cmath> #include <cstdio> #include <deque> #include <functional> #include <iostream> #include <iterator> #include <map> #include <queue> #include <set> #include <string> #include <sstream> #include <unordered_map> #include <unordered_set> #include <utility> #include <numeric> #include <vector> using namespace std; #if __has_include(<atcoder/all>) #include <atcoder/all> using namespace atcoder; #endif #define GET_MACRO(_1, _2, _3, NAME, ...) NAME #define _rep(i, n) _rep2(i, 0, n) #define _rep2(i, a, b) for(int i = (int)(a); i < (int)(b); i++) #define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() using i64 = long long; template<class T, class U> bool chmin(T& a, const U& b) { return (b < a) ? (a = b, true) : false; } template<class T, class U> bool chmax(T& a, const U& b) { return (b > a) ? (a = b, true) : false; } template<typename T>istream& operator>>(istream&i,vector<T>&v){rep(j,v.size())i>>v[j];return i;} template<typename T>string join(vector<T>&v){stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);} template<typename T>ostream& operator<<(ostream&o,vector<T>&v){if(v.size())o<<join(v);return o;} template<typename T>string join(vector<vector<T>>&vv){string s="\n";rep(i,vv.size())s+=join(vv[i])+"\n";return s;} template<typename T>ostream& operator<<(ostream&o,vector<vector<T>>&vv){if(vv.size())o<<join(vv);return o;} template<class T> using pq = priority_queue<T, vector<T>, greater<T>>; const int MAX_V = 200005; vector<int> to[MAX_V]; int dep[MAX_V]; int in[MAX_V]; int out[MAX_V]; int k; vector<int> ls[MAX_V]; // ๆทฑใ•ใ”ใจใฎ้ ‚็‚นใƒชใ‚นใƒˆ void dfs(int v, int d) { in[v] = k; // ๆฅใŸๆ™‚ใซไฝ•็•ชใ ใฃใŸใ‹ k++; dep[v] = d; for(auto i : to[v]) dfs(i, d + 1); out[v] = k; // ๅธฐใฃใฆใใŸใจใใซไฝ•็•ชใ ใฃใŸใ‹ } int calc(int d, int r) { // ls[d]ๅ†…ใง๏ผŒrใ‚ˆใ‚Šๅคงใใ„่ฆ็ด ๆ•ฐใ‚’ๆ•ฐใˆใ‚‹๏ผŽ return lower_bound(all(ls[d]), r) - ls[d].begin(); } int main() { int n; cin >> n; rep(i, n - 1) { int p; cin >> p; to[p - 1].push_back(i + 1); } dfs(0, 0); rep(i, n) ls[dep[i]].push_back(in[i]); rep(i, n) sort(all(ls[i])); int q; cin >> q; while(q--) { int u, d; cin >> u >> d; --u; int ans = calc(d, out[u]) - calc(d, in[u]); // ls[d] ใฎไธญใง [in[u], out[u]) ใงใ‚ใ‚‹้ƒจๅˆ†ใ‚’ๆ•ฐใˆใ‚‹ cout << ans << endl; } return 0; }
/** ____ ____ ____ ____ ____ ||a |||t |||o |||d |||o || ||__|||__|||__|||__|||__|| |/__\|/__\|/__\|/__\|/__\| **/ #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N_MAX = 200000; int n; int a[N_MAX * 2 + 2]; int p[N_MAX * 2 + 2]; bool cmp (const int &x, const int &y) { return a[x] < a[y]; } bool color[N_MAX * 2 + 2]; set <int> sPos; set <pair <int, int>> sPair; bool answer[N_MAX * 2 + 2]; void del (int i) { set <int> :: iterator it = sPos.find(i); set <int> :: iterator itl, itr; bool L = false, R = false; itl = it; if(itl != sPos.begin()) { L = true; itl--; if(color[*itl] != color[i]) sPair.erase(make_pair(*itl, i)); } itr = it; itr++; if(itr != sPos.end()) { R = true; if(color[i] != color[*itr]) sPair.erase(make_pair(i, *itr)); } if(L == true && R == true) { if(color[*itl] != color[*itr]) sPair.insert(make_pair(*itl, *itr)); } sPos.erase(i); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for(int i = 1; i <= n * 2; i++) cin >> a[i]; for(int i = 1; i <= n * 2; i++) p[i] = i; sort(p + 1, p + n * 2 + 1, cmp); for(int i = 1; i <= n; i++) color[p[i]] = 1; for(int i = 1; i <= n * 2; i++) sPos.insert(i); for(int i = 1; i < n * 2; i++) if(color[i] != color[i + 1]) sPair.insert(make_pair(i, i + 1)); while(sPair.empty() == false) { pair <int, int> p = *sPair.begin(); answer[p.first] = 0; answer[p.second] = 1; del(p.first); del(p.second); } assert(sPos.empty() == true); for(int i = 1; i <= n * 2; i++) if(answer[i] == 0) cout << "("; else cout << ")"; cout << "\n"; return 0; }
#include <bits/stdc++.h> #define fi first #define se second #define ll long long #define ld long double #define pb push_back #define pf push_front #define pll pair<ll,ll> #define ppl pair<pll,ll> #define plp pair<ll,pll> #define pi 3.14159265358979323846264338327950 const ll MOD=1e9 + 7; const ll N=2e5 + 7; using namespace std; //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // use rng for random number generation ll POWER(ll base,ll expo) { ll ret=1; while(expo) { if(expo&1)ret=ret*base; expo>>=1; base=base*base; } return ret; } ll ext_gcd(ll a,ll b,ll& x,ll& y) { ll d = a; if(b == 0){ x = 1; y = 0; } else{ d = ext_gcd(b,a%b,y,x); y -= (a/b)*x; } return d; } ll mod_inv(ll a,ll m) { ll x,y; ext_gcd(a,m,x,y); return (x%m + m)%m; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll test_cases = 1; //cin>>test_cases; while(test_cases --) { //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); ll a,b,k; cin>>a>>b>>k; string s; for(ll i=0;i<a;i++)s += 'a'; for(ll i=a;i<a+b;i++)s += 'b'; k--; ll l = 0, r = a; ll n = a + b; while(k > 0){ ll x = (n - r); ll num = n - r + 1; ll denom = 2; ll st = -1; for(ll i=r-1;i>=l;i--){ if(k - x >= 0){ k -= x; st = i; x = (x*num)/denom; if(k == 0){ ll cnta = 0; ll cntb = 0; for(ll j=i;j<n;j++){ if(s[j] == 'a')cnta++; else cntb++; } for(ll j=i;j<n;j++){ if(cntb > 0){ s[j] = 'b'; cntb--; } else if(cnta){ s[j] = 'a'; cnta--; } } } num++; denom++; } else break; } if(k == 0)break; if(st != -1){ swap(s[st-1],s[r]); k--; l = st + 1; r = r + 1; } else break; } while(k > 0){ k--; bool ok = next_permutation(s.begin(),s.end()); } cout<<s; } return 0; }
#include <bits/stdc++.h> using namespace std; #define IO ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0); #define int long long #define double long double #define vi vector<int> #define vvi vector<vi> #define pii pair<int, int> #define vii vector<pii> #define endl '\n' #define pb push_back #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define mod 1000000007 int C[61][31]; void solve() { int a, b, k; cin >> a >> b >> k; C[0][0] = 1; for (int i = 1; i <= a + b; i++) { for (int j = 0; j <= a; j++) { if (i - 1 >= 0 && j - 1 >= 0) C[i][j] = C[i - 1][j - 1]; if (i - 1 >= 0) C[i][j] += C[i - 1][j]; } } // for (int i = 1; i <= a + b; i++) { // for (int j = 0; j <= a; j++) { // cerr << C[i][j] << ' '; // } // cerr << endl; // } while (a > 0 && b > 0) { int v = C[a + b - 1][a - 1]; if (v >= k) { cout << 'a'; a--; } else { cout << 'b'; b--; k -= v; } } cout << string(a, 'a'); cout << string(b, 'b'); cout << endl; } signed main() { IO; int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n = 0, k = 0; cin >> n >> k; vector<int> v(n, 0); vector<int> cnt(3e5 + 5, 0); long long ans = 0; for(int i = 0; i < n; i++) { cin >> v[i]; cnt[v[i]]++; } for(int i = 0; i < 3e5 + 5; i++) { int temp = k - cnt[i]; if(temp > 0) { ans += temp * i; k = cnt[i]; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; void solve(long long N, long long K, std::vector<long long> a){ map<ll, int> mp; for(int i = 0;i < N;i++){ mp[a[i]]++; } ll ans = 0; for(int i = 0;i < K;i++){ for(int j = 0;j < 1e9;j++){ if(mp[j] != 0){ mp[j]--; }else{ ans += j; break; } } } cout<<ans<<endl; } int main(){ long long N; scanf("%lld",&N); long long K; scanf("%lld",&K); std::vector<long long> a(N); for(int i = 0 ; i < N ; i++){ scanf("%lld",&a[i]); } solve(N, K, std::move(a)); return 0; }
//Bismillahir Rahman-ir Rahim #include<bits/stdc++.h> #include<cstdio> #define PI acos(-1) #define F first #define S second #define debug(x) cout<<'>'<<#x<<":"<<x<<endl #define tara ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) #define Y printf("YES\n") #define N printf("NO\n") #define ll long long #define lll __int128 #define ull unsigned long long #define pii pair<int,int> #define pll pair<long,long> #define eb emplace_back #define pb push_back #define sc scanf #define pf printf #define endl '\n' #define INF 1<<30 #define ll_INF 1LL<<62 #define MODU 998244353 const int M=1e5; #define on(x) (marked[x/64] & (1<<((x%64)/2))) #define mark(x) marked[x/64] |= (1<<((x%64)/2)) using namespace std ; int marked[M/64 + 2]; void bitsieve(int n) { for (int i = 3; i * i < n; i += 2) { if (!on(i)) { for (int j = i * i; j <= n; j += i + i) { mark(j); } } } } bool bitisPrime(int num) { return num > 1 && (num == 2 || ((num & 1) && !on(num))); } bool isPrime(int n) { if (n <= 1) return false; for (int i = 2; i < n; i++) if (n % i == 0) return false; return true; } int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } struct node{ int x, y ; }; bool cmp(int a, int b ){ return a>b ; } int main(){ //tara ; int n ; cin>>n ; ll sum=0 ; while(n--){ int a, b ; cin>>a>>b ; a-- ; ll aa=0,bb=0 ; if(a&1){ aa=(a+1)/2 ; aa*=a ; } else { aa=a/2 ; aa*=(a+1) ; } if(b&1){ bb=(b+1)/2 ; bb*=b ; } else { bb=b/2 ; bb*=(b+1) ; } sum+=(bb-aa) ; } cout<<sum<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int n; scanf("%d",&n); long long sum=0; for(int i=1;i<=n;i++){ long long a,b; scanf("%lld%lld",&a,&b); sum=sum+(a+b)*(b-a+1)/2; } printf("%lld\n",sum); }
#include <bits/stdc++.h> using Int = long long; // clang-format off using pii = std::pair<Int, Int>; #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 RREP_(i, a_, b_, a, b, ...) for (Int i = Int(b) - 1, low##i = (a); i >= low##i; i--) #define RREP(i, ...) RREP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__) #define ALL(v) std::begin(v), std::end(v) struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io; #ifndef dump #define dump(...) #endif // clang-format on struct in { template <class T> operator T() { T t; std::cin >> t; return t; } }; void out() { std::cout << "\n"; } template <class Head, class... Tail> void out(Head&& h, Tail&&... t) { std::cout << h << (sizeof...(Tail) == 0 ? "" : " "), out(std::forward<Tail>(t)...); } template <class T> bool chmin(T& a, const T& b) { return a > b ? a = b, true : false; } template <class T> bool chmax(T& a, const T& b) { return a < b ? a = b, true : false; } template <class T> using V = std::vector<T>; /** * author: knshnb * created: Tue Mar 30 22:53:03 JST 2021 **/ /// @docs src/Helper/BinarySearch.md template <class F> long long binary_search(long long ok, long long ng, F check) { while (std::abs(ok - ng) > 1) { long long mid = (ok + ng) / 2; (check(mid) ? ok : ng) = mid; } return ok; } signed main() { Int n = in(), K = in(); V<V<Int>> g(n); REP(i, n - 1) { Int u = (Int)in() - 1, v = (Int)in() - 1; g[u].push_back(v); g[v].push_back(u); } auto check = [&](Int mid) { Int cnt = 0; V<Int> no_ma(n, 0), mi(n, 1e18); auto dfs = [&](auto&& self, int v, int prv = -1) -> void { for (int s : g[v]) { if (s == prv) continue; self(self, s, v); chmin(mi[v], mi[s] + 1); chmax(no_ma[v], no_ma[s] + 1); } if (no_ma[v] + mi[v] <= mid) no_ma[v] = -1; if (no_ma[v] >= mid) { cnt++; no_ma[v] = -1; mi[v] = 0; } }; dfs(dfs, 0); if (no_ma[0] >= 0) cnt++; return cnt <= K; }; Int ans = binary_search(n, -1, check); out(ans); }
#include <bits/stdc++.h> #define rep(i, n) for(int i=0; i<(int)(n); i++) #define FILL0(x) memset(x,0,sizeof(x)) #define FILL1(x) memset(x,-1,sizeof(x)) using namespace std; typedef long long ll; typedef pair<ll, ll> P; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); int a, b; cin >> a >> b; a += b; if(a>=15 && b>=8){ cout << 1 << endl; }else if(a>=10 && b>=3){ cout << 2 << endl; }else if(a>=3){ cout << 3 << endl; }else{ cout << 4 << endl; } return 0; }
#include <bits/stdc++.h> #include <fstream> #define FIXED_FLOAT(x) std::fixed <<std::setprecision(20) << (x) #define all(v) (v).begin(), (v).end() using namespace std; #define forn(i,n) for (int i = 0; i < (n); ++i) using ll = long long; int mod = (ll)1e9 + 7; #define PI acos(-1) typedef pair<int, int> pairs; typedef complex<ll> G; const int INF = 1e9 + 1; const int N = 1.5e6 + 10; const double eps = 1e-3; template <typename XPAX> void ckma(XPAX &x, XPAX y) { x = (x < y ? y : x); } template <typename XPAX> void ckmi(XPAX &x, XPAX y) { x = (x > y ? y : x); } ll power(ll a, ll b){ if(!b) return 1; ll c=power(a,b/2); c=(1LL*c*c); if(b%2) c=(1LL*c*a); return c; } int mul(int a, int b) { return a * 1ll * b % mod; } int add(int a, int b) { int s = (a+b); if (s>=mod) s-=mod; return s; } template<long long mod = 1000000007> struct modint{ long long a; modint() : a(0){} modint(long long t){ a = t % mod; if(a < 0) a += mod; } operator long long() const{ return a; } bool operator==(const modint &x) const{ return a == x.a; } bool operator!=(const modint &x) const{ return a != x.a; } modint operator-() const{ return modint(a ? (mod - a) : 0); } modint operator~() const{ return pow(mod - 2); } modint operator+(const modint &x) const{ return modint(*this) += x; } modint operator-(const modint &x) const{ return modint(*this) -= x; } modint operator*(const modint &x) const{ return modint(*this) *= x; } modint operator/(const modint &x) const{ return modint(*this) /= x; } modint &operator+=(const modint &x){ a += x.a; if(a >= mod) a -= mod; return *this; } modint &operator-=(const modint &x){ a -= x.a; if(a < 0) a += mod; return *this; } modint &operator*=(const modint &x){ a = a * x.a % mod; return *this; } modint &operator/=(const modint &x){ a = a * (~x).a % mod; return *this; } friend ostream &operator<<(ostream &os,const modint &x){ return os << x.a; } friend istream &operator>>(istream &is,modint &x){ long long t; is >> t; x = modint(t); return is; } modint pow(long long x) const{ modint ret = 1,tmp = a; for(;x;tmp *= tmp,x >>= 1){ if(x & 1) ret *= tmp; } return ret; } }; const ll MOD = 1e9 + 7; using Mint = modint<MOD>; struct FenwickTree { vector<int> bit; // binary indexed tree int n; FenwickTree(int n) { this->n = n; bit.assign(n, 0); } FenwickTree(vector<int> a) : FenwickTree(a.size()) { for (size_t i = 0; i < a.size(); i++) add(i, a[i]); } int sum(int r) { int ret = 0; for (; r >= 0; r = (r & (r + 1)) - 1) ret += bit[r]; return ret; } int sum(int l, int r) { return sum(r) - sum(l - 1); } void add(int idx, int delta) { for (; idx < n; idx = idx | (idx + 1)) bit[idx] += delta; } }; template<class T> struct Combination{ vector<T> fact,factinv; Combination(int n) : fact(n + 1),factinv(n + 1){ fact[0] = 1; for(int i = 1;i <= n;i++) fact[i] = fact[i - 1] * T(i); factinv[n] = ~fact[n]; for(int i = n;i >= 1;i--) factinv[i - 1] = factinv[i] * T(i); } T nCr(int n,int r){ if(n < 0 || r < 0 || n < r) return 0; return fact[n] * factinv[r] * factinv[n - r]; } T factorial(int x) { if(x < 0)return 0; return fact[x]; } }; void done() { int a, b; cin >> a >> b; cout << (b%a == 0 ? "Yes" : "No"); } void solve() { } void emer() { // start from here // // } void another() { } void test_case() { int t; cin >> t; forn(p, t) { //cout << "Case #" << p + 1 << ": "; done(); } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); done(); // 5 4 3 2 1 }
#include<bits/stdc++.h> using namespace std; #define ll long long #define endl '\n' const int Modulo=1e9+7; int N=1e5+5; bool myCompare(int a,int b) { return a>b; } bool checkPrime(int n) { int flag=1; for(int i=2;i<=sqrt(n);i++) { if(n%i==0) flag=0; } if(flag) return true; else return false; } vector<bool>prime(N + 1,true); void SieveOfEratosthenes(int n) { // memset(prime, true, sizeof(prime)); prime[0]=prime[1]=false; for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) prime[i] = false; } } } ll power(ll a,ll b) { ll result=1; while(b>0){ if(b&1){ result=(result*a);} a=(a*a); b=b>>1; } return result; } ll fastModuloExponentiation(ll a,ll b,ll M) { ll result=1; while(b>0){ if(b&1){ result=(result*a)%M;} a=(a*a)%M; b=b>>1; } return result; } void solve() { float a,b; cin>>a>>b; int discount=a-b; float ans=(float(discount)/float(a))*100; cout<<ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // SieveOfEratosthenes(n); // int t; // cin >> t; // while (t--) solve(); }
// #pragma GCC optimize("Ofast,unroll-loops") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") #include <bits/stdc++.h> #define ll long long int #define vi vector<int> #define vvi vector<vector<int>> #define vll vector<long long> #define vs vector<string> #define vc vector<char> #define vb vector<bool> #define forn(i, s, n) for(ll i=(ll)s; i<(ll)(n); i++) #define all(c) c.begin(),c.end() #define pb push_back #define pll pair<long long int, long long int> #define pii pair<int, int> #define pss pair<string, string> #define ull unsigned long long int #define lld long double #define F first #define S second #define PI 3.141592653589793238 #define prec(n) fixed<<setprecision(n) #define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr) #define itsval(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); itval(_it, args); } using namespace std; // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; void itval(istream_iterator<string> it) {} template<typename T, typename... Args> void itval(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; itval(++it, args...); } const ll MOD = 1e9 + 7; template <typename T> inline void print(T x) {cout << x << "\n";} template <typename T> inline void printvec(T x) {for (auto a : x) cout << a << ' '; cout << '\n';} // ----------------------------------------------------------------------- struct custom { bool operator()(const pair<int, pii> &p1, const pair<int, pii> &p2)const { return p1.F < p2.F; } }; // Calculate a^b % MOD ------------------------------------------------- ll get_pow(ll a, ll b, ll M = MOD) { ll res = 1; while (b) { if (b & 1) res = (res * a) % M; a = (a * a) % M; b >>= 1; } return res; } // --------------------------------------------------------------------- const ll N = 1e5 + 5, inf = 2e18; lld dp[N]; void solve() { ll n; cin >> n; lld ans = 0; forn(i, 1, n + 1) ans += ((lld)n) / (lld)i; cout << prec(10) << ans - 1; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output1.txt", "w", stdout); #endif int test = 1; //cin >> test; clock_t z = clock(); forn(tes, 0, test) { // cout << "Case #" << tes + 1 << ": "; solve(); } debug("Total Time:%.4f\n", (double)(clock() - z) / CLOCKS_PER_SEC); return 0; }
#include <stdio.h> #include <set> #include <map> #include <unordered_map> #include <unordered_set> #include <list> #include <queue> #include <stack> #include <cmath> #include <ctime> #include <cstdio> #include <vector> #include <string> #include <bitset> #include <cctype> #include <cstdlib> #include <cstring> #include <utility> #include <numeric> #include <complex> #include <sstream> #include <fstream> #include <iomanip> #include <cassert> #include <iostream> #include <iterator> #include <algorithm> #include <functional> //#include <atcoder/all> //using namespace atcoder; using namespace std; typedef long long ll; const double EPS = 1e-9; typedef vector<int> vint; typedef vector<vector<int>> v2int; typedef vector<vector<vector<int>>> v3int; typedef vector<ll> vll; typedef vector<vector<ll>> v2ll; typedef vector<vector<vector<ll>>> v3ll; typedef list<int> liint; typedef pair<int, int> pint; typedef vector<pair<int, int>> vpint; typedef vector<pair<ll, ll>> vpll; typedef vector<pair<ll, int>> vpll_int; typedef vector<pair<int, ll>> vpint_ll; typedef set<pair<int, int>> spint; typedef set<pair<ll, int>> spll; typedef unordered_map<int, unordered_set<int>> Graph; const int INF = int(2e9); const ll LINF = ll(2e9) * ll(2e9); #define rep(i, n) REP(i, 0, n) #define ALL(v) v.begin(), v.end() #define MSG(a) cout << #a << " " << a << endl; #define REP(i, x, n) for(int i = x; i < n; i++) template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; } template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string S; cin >> S; ll ans = 0; int N = S.size(); unordered_map<char, int> num; for (int i = N - 1; i >= 1; i--) { if (S[i] == S[i - 1]) { ans += (N - 1 - i) - num[S[i]]; REP(c, 'a', 'z' + 1) { num[c] = 0; } num[S[i]] = N - i; } else { num[S[i]]++; } } cout << max(0LL, ans) << endl; return 0; }
#include <cstring> #include <iostream> #include <algorithm> #include <set> using namespace std; typedef pair<int, int> E; const int N = 250005; const int M = 1e8; const int R = 505; int n, m; int h[N], e[M], ne[M], w[M], idx; int dist[N]; set<E> q; inline int id(int x, int y) { return (x - 1) * m + y; } inline void add(int a, int b, int c) { e[++idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx; } int dijkstra(int S, int T) { memset(dist, 0x3f, sizeof dist); dist[S] = 0, q.insert({0, S}); while (q.size()) { int t = (*q.begin()).second; if (t == T) break; q.erase(q.begin()); for (int i = h[t]; i; i = ne[i]) { if (dist[e[i]] > dist[t] + w[i]) { if (q.find({dist[e[i]], e[i]}) != q.end()) { q.erase({dist[e[i]], e[i]}); } dist[e[i]] = dist[t] + w[i]; q.insert({dist[e[i]], e[i]}); } } } return dist[T]; } int main() { scanf("%d%d", &n, &m); for (int i = 1, j, x; i <= n; ++i) { for (j = 1; j < m; ++j) { scanf("%d", &x); add(id(i, j), id(i, j + 1), x); add(id(i, j + 1), id(i, j), x); } } for (int i = 1, j, x; i < n; ++i) { for (j = 1; j <= m; ++j) { scanf("%d", &x); add(id(i, j), id(i + 1, j), x); } } for (int x = 1; x <= n; ++x) { for (int y = 1; y <= m; ++y) { for (int r = 1; r < x; ++r) { add(id(x, y), id(x - r, y), r + 1); } } } printf("%d\n", dijkstra(id(1, 1), id(n, m))); return 0; }
// ๅ•้กŒใฎ URL ใ‚’ๆ›ธใ„ใฆใŠใ // #include <bits/stdc++.h> using namespace std; #define ENABLE_PRINT #if defined(ENABLE_PRINT) #define Print(v) \ do {\ cout << #v << ": " << v << endl; \ }while(0) #define PrintVec(v) \ do {\ for(int __i = 0; __i < v.size(); ++__i) \ { \ cout << #v << "[" << __i << "]: " << v[__i] << endl; \ }\ }while(0) #else #define Print(v) ((void)0) #define PrintVec(v) ((void)0) #endif #define rep(i, n) for(int i = 0; i < (int)(n); ++i) using ll = long long; struct D { int to; int cost; }; ll INF = 100100100100100100; vector<ll> calc(int s, int vmax, vector<vector<D>>& g) { vector<ll> dist(vmax, INF); using P = pair<int, int>; priority_queue<P, vector<P>, greater<P>> q; vector<bool> visit(vmax); q.push({0, s}); while(!q.empty()) { auto t = q.top(); q.pop(); auto index = t.second; auto cost = t.first; if(visit[index]) continue; visit[index] = true; if(cost >= dist[index]) continue; dist[index] = cost; for(auto to : g[index]) { q.push({cost + to.cost, to.to}); } } return dist; } int main(int, const char**) { int R, C; cin >> R >> C; vector<vector<int>> A(R, vector<int>(C)); vector<vector<int>> B(R, vector<int>(C)); rep(i, R) rep(j, C - 1) cin >> A[i][j]; rep(i, R - 1) rep(j, C) cin >> B[i][j]; int vmax = R * C; vector<vector<D>> V(vmax * 2); rep(i, vmax) { auto& v = V[i]; auto y = i / C; auto x = i % C; if(x < C - 1) { v.push_back({i + 1, A[y][x]}); } if(x > 0) { v.push_back({i - 1, A[y][x - 1]}); } if(y < R - 1) { v.push_back({i + C, B[y][x]}); } } rep(i, C) { rep(j, R - 1) { auto ty = R - j - 1; auto toy = ty - 1; auto dty = ty + R; auto dtoy = dty - 1; auto& dv = V[dty * C + i]; dv.push_back({dtoy * C + i, 1}); auto& tdv = V[dtoy * C + i]; tdv.push_back({toy * C + i, 1}); auto& v = V[ty * C + i]; v.push_back({dty * C + i, 0}); } } auto dists = calc(0, vmax * 2, V); #if 0 rep(i, R) { rep(j, C) { printf("%lld ", dists[i * C + j]); } printf("\n"); } #endif cout << dists[vmax - 1] << endl; return 0; }
#include <bits/stdc++.h> #define ll long long #define sz(x) ((int) (x).size()) #define all(x) (x).begin(), (x).end() #define vi vector<int> #define vl vector<long long> #define pii pair<int, int> #define REP(i,a) for (int i = 0; i < (a); i++) #define add push_back using namespace std; template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>; const ll MOD = 1000000007LL; //const ll MOD = 998244353LL; int ni() { int x; cin >> x; return x; } ll nl() { ll x; cin >> x; return x; } double nd() { double x; cin >> x; return x; } string next() { string x; cin >> x; return x; } struct DisjointSetUnion { vi parent; vi weight; int count; //number of components DisjointSetUnion(int N) { count = N; parent.assign(N,0); REP(i,N) parent[i] = i; weight.assign(N,1); } //"find" int root(int p) { if (p==parent[p]) return p; int r = root(parent[p]); parent[p] = r; return r; } //"union" void connect(int p, int q) { p = root(p); q = root(q); if (p==q) return; if (weight[p]<weight[q]) { parent[p] = q; weight[q] += weight[p]; } else { parent[q] = p; weight[p] += weight[q]; } count--; } bool connected(int p, int q) { return root(p)==root(q); } }; ll in(int L, int R, int g) { int lo = (L+g-1)/g; int hi = R/g; return (hi-lo+1LL); } int main() { #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif ios::sync_with_stdio(false); cin.tie(0); int L = max(2,ni()); int R = ni(); if (L>R) { cout << 0; return 0; } const int maxn = 1000000; ll dp[maxn+1]; ll ans = 0LL; for (int i = R; i >= 2; i--) { dp[i] = in(L,R,i)*in(L,R,i); for (int j = 2*i; j <= R; j += i) dp[i] -= dp[j]; ans += dp[i]; } //remove people who divide each other ll bad = 0LL; for (int x = L; x < R; x++) { bad += in(x+1,R,x); } ans = ans-2*bad-(R-L+1); cout << ans; }
#include <bits/stdc++.h> using namespace std; long long L, R; long long T[1000005]; int main() { cin >> L >> R; if (L < 2) { L = 2; } long long ans = 0; for (int g = R; g >= 2; g--) { long long w = R/g - (L-1)/g; T[g] = w*w; for (int gg = g*2; gg <= R; gg+=g) { T[g] -= T[gg]; } ans += T[g]; } for (int i = L; i <= R; i++) { ans -= R/i*2-1; } cout << ans << endl; // long long ans2 = 0; // for (int x = L; x <= R; x++) { // for (int y = x+1; y <= R; y++) { // int g = gcd(x, y); // if (g != 1 && x != g && y != g) { ans2 += 2; } // } // } // cout << ans2 << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; #define rep(i, n) for(int i = 0; i < (n); ++i) #define io ios::sync_with_stdio(false); cin.tie(0) // geometry using C = complex<double>; int main() { io; int n; cin >> n; double a, b, c, d; cin >> a >> b >> c >> d; C A(a, b), B(c, d); C O = (A + B) / 2.0; double rad = 2.0 * M_PI / n; C r(cos(rad), sin(rad)); C ans = O + (A - O)*r; cout << real(ans) << ' ' << imag(ans) << endl; return 0; }
#include<bits/stdc++.h> #include <math.h> using namespace std; #define rep(i,n) for(ll i=0;i<n;i++) #define repl(i,l,r) for(ll i=(l);i<(r);i++) #define per(i,n) for(ll i=n-1;i>=0;i--) #define perl(i,r,l) for(ll i=r-1;i>=l;i--) #define fi first #define se second #define pb push_back #define mkp make_pair #define ins insert #define pqueue(x) priority_queue<x,vector<x>,greater<x>> #define all(x) (x).begin(),(x).end() #define CST(x) cout<<fixed<<setprecision(x) #define vtpl(x,y,z) vector<tuple<x,y,z>> #define rev(x) reverse(x); #define lin(x) ll x; cin>>x; #define stin(x) string x; cin>>x; #define yn(x) if(x) { cout<<"Yes"<<endl; } else { cout<<"No"<<endl; } #define YN(x) if(x) { cout<<"YES"<<endl; } else { cout<<"NO"<<endl; } #define co(x) cout<<x<<endl; using ll=long long; using ld=long double; using vl=vector<ll>; using vvl=vector<vector<ll>>; using pl=pair<ll,ll>; using vpl=vector<pl>; using vvpl=vector<vpl>; const ll mod=1000000007; const ll MOD9=998244353; const int inf=1e9+10; const ll INF=4e18; const ld pi=3.14159265368979; const ll dy[8]={1,0,-1,0,1,1,-1,-1}; const ll dx[8]={0,-1,0,1,1,-1,1,-1}; template <typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); } template <typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); } ll powmod(ll n, ll k, ll m) { ll r=1; for(; k>0; k >>=1) { if(k&1) r=(r*n)%m; n=(n*n)%m; } return r; } ll fact(ll n) { ll a=1; rep(i,n) { a=a*(n-i); } return a; } ll pow(ll a, ll b) { ll x=1; rep(i,b) { x=x*a; } return x; } int main() { lin(N); lin(a); lin(b); lin(c); lin(d); ld xm=(ld)(a+c)/(ld)2; ld ym=(ld)(b+d)/(ld)2; //vector radius ld x=a-xm; ld y=b-ym; ld theta=(ld)2*3.14159265358979/(ld)N; ld z1=cos(theta)*x-sin(theta)*y; ld z2=sin(theta)*x+cos(theta)*y; CST(15); cout<<xm+z1<<" "<<ym+z2<<endl; }
#include<bits/stdc++.h> using namespace std; typedef long long int in; int main() { in a,b,c,d; cin>>a>>b>>c>>d; cout<<min({a,b,c,d}); return 0; }
#include <bits/stdc++.h> #include <iostream> #include <iomanip> #include <cmath> #include <algorithm> using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) using ll = long long; using ull = unsigned long long; using P = pair<int,int>; using C = complex<double>; int solve() { ll r1, c1, r2, c2; cin >> r1 >> c1; cin >> r2 >> c2; if (r1 == r2 && c1 == c2) return 0; if (r1 + c1 == r2 + c2) return 1; if (r1 - c1 == r2 - c2) return 1; if (abs(r1-r2) + abs(c1-c2) <= 3) return 1; if ((r1+c1) % 2 == (r2+c2) % 2) return 2; if (abs(r1-r2) + abs(c1-c2) <= 6) return 2; if (abs((r1+c1)-(r2+c2)) <= 3 || abs((r1-c1)-(r2-c2)) <= 3) return 2; return 3; } int main() { cout << solve() << endl; }
#include<iostream> #include<utility> #include<algorithm> #include<set> #include<vector> #include<cmath> #define forn(i, x, n) for(int i = x; i < (int)(n); i++) using namespace std; typedef long long ll; const int mod = 998244353; const bool DEBUG = 0; vector<int> primes; vector<int> lp(2e5+1); void sieve(){ forn(i, 2, lp.size()){ if(lp[i] == 0){ lp[i] = i; primes.push_back(i); } for(int j = 0; j < primes.size() && primes[j] <= i && primes[j]*i < lp.size(); j++){ lp[primes[j]*i] = primes[j]; } } } void solve(){ int k; cin>>k; sieve(); ll ans = 1; forn(i, 2, k+1){ ll prod = 1; for(ll tmp = i, x = lp[tmp]; tmp > 1; x = lp[tmp]){ ll p = 0; while(tmp%x == 0) tmp /= x, p++; if(DEBUG) cout<<i<<' '<<p<<'\n'; prod *= (p+2)*(p+1)/2; } if(DEBUG) cout<<prod<<'\n'; ans += prod; } cout<<ans; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; //cin>>t; //while(t--) cout<<solve()<<'\n'; while(t--) solve(), cout<<'\n'; }
#include <bits/stdc++.h> #define int long long #define double long double using namespace std; const int INF = 1000000000000000000; using Graph = vector<vector<int>>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) signed main(){ int K; cin >> K; int ans = 0; for( int i = 1; i <= K; i++ ){ for( int j = 1; j <= K; j++ ){ if( i*j > K ) break; ans += K/(i*j); } } cout << ans << endl; }
// C - Made Up #include <bits/stdc++.h> #define repi(i, s, n) for(int i=(int)(s); i<(int)(n); ++i) #define rep(i, n) repi(i, 0, n) #define rrep(i, n, s) for(int i=(int)(n-1); i>=(int)(s); --i) using namespace std; using ll = long long; using ull = unsigned long long; int main(){ int n; cin >> n; map<int, int> a; vector<int> b(n); rep(i, n){ int aa; cin >> aa; ++a[aa]; } rep(i, n) cin >> b[i]; vector<int> d(n, 0); rep(i, n){ int c; cin >> c; ++d[c-1]; } ll ans = 0; rep(i, n){ if(d[i]){ if(a[b[i]]){ ll v =(ll)a[b[i]]*d[i]; ans += v; } } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pll; using Graph = vector<vector<ll>>; #define all(x) (x).begin(), (x).end() //string ใฎ sort ใจใ‹ใฏใ“ใ‚Œ #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) const ll MOD = 1000000007; const ll INF = 1e18; //1*10^18 const double PI = 3.141592653589793238; //18ๆก const ll MAX = 1e6; long long fac[MAX], finv[MAX], inv[MAX]; int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; } ll gcd(ll x, ll y) { return (x % y) ? gcd(y, x % y) : y; } //ๆœ€ๅคงๅ…ฌ็ด„ๆ•ฐ ll lcm(ll x, ll y) { return x / gcd(x, y) * y; } //ๆœ€ๅฐๅ…ฌๅ€ๆ•ฐ ll powll(ll a, ll n) { //O(log n) ll res = 1; while (n > 0) { if (n & 1) //(n & 1)=(n % 2 !=0) { res = res * a; } a = a * a; n >>= 1; //(n & 1)=(n % 2 !=0) } return res; } ll modpow(ll a, ll n, ll mod) //O(log n) { ll res = 1; while (n > 0) { if (n & 1) //(n & 1)=(n % 2 !=0) { res = res * a % mod; } a = a * a % mod; n >>= 1; //(n>>=1)=(n/2) } return res; } int ReturnDigit(ll num) { string number = to_string(num); return number.length(); } // ใƒ†ใƒผใƒ–ใƒซใ‚’ไฝœใ‚‹ๅ‰ๅ‡ฆ็† void COMinit() //MODใฏ็ด ๆ•ฐใ˜ใ‚ƒใชใ„ใจใ ใ‚ˆ๏ผ๏ผ { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // ไบŒ้ …ไฟ‚ๆ•ฐ่จˆ็ฎ— long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } struct UnionFind { vector<int> par; // par[i]:iใฎ่ฆชใฎ็•ชๅทใ€€(ไพ‹) par[3] = 2 : 3ใฎ่ฆชใŒ2 UnionFind(int N) : par(N) { //ๆœ€ๅˆใฏๅ…จใฆใŒๆ นใงใ‚ใ‚‹ใจใ—ใฆๅˆๆœŸๅŒ– for (int i = 0; i < N; i++) par[i] = i; } int root(int x) { // ใƒ‡ใƒผใ‚ฟxใŒๅฑžใ™ใ‚‹ๆœจใฎๆ นใ‚’ๅ†ๅธฐใงๅพ—ใ‚‹๏ผšroot(x) = {xใฎๆœจใฎๆ น} if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(int x, int y) { // xใจyใฎๆœจใ‚’ไฝตๅˆ int rx = root(x); //xใฎๆ นใ‚’rx int ry = root(y); //yใฎๆ นใ‚’ry if (rx == ry) return; //xใจyใฎๆ นใŒๅŒใ˜(=ๅŒใ˜ๆœจใซใ‚ใ‚‹)ๆ™‚ใฏใใฎใพใพ par[rx] = ry; //xใจyใฎๆ นใŒๅŒใ˜ใงใชใ„(=ๅŒใ˜ๆœจใซใชใ„)ๆ™‚๏ผšxใฎๆ นrxใ‚’yใฎๆ นryใซใคใ‘ใ‚‹ } bool same(int x, int y) { // 2ใคใฎใƒ‡ใƒผใ‚ฟx, yใŒๅฑžใ™ใ‚‹ๆœจใŒๅŒใ˜ใชใ‚‰trueใ‚’่ฟ”ใ™ int rx = root(x); int ry = root(y); return rx == ry; } }; // // ๆฑŽ็”จ็š„ใชไบŒๅˆ†ๆŽข็ดขใฎใƒ†ใƒณใƒ—ใƒฌๅˆคๅฎš้ƒจๅˆ† // bool isOK(int index, int key) { // if (a[index] >= key) return true; // else return false; // } // ๆฑŽ็”จ็š„ใชไบŒๅˆ†ๆŽข็ดขใฎใƒ†ใƒณใƒ—ใƒฌ // int binary_search(int key) { // int left = -1; //ใ€Œindex = 0ใ€ใŒๆกไปถใ‚’ๆบ€ใŸใ™ใ“ใจใ‚‚ใ‚ใ‚‹ใฎใงใ€ๅˆๆœŸๅ€คใฏ -1 // int right = (int)a.size(); // ใ€Œindex = a.size()-1ใ€ใŒๆกไปถใ‚’ๆบ€ใŸใ•ใชใ„ใ“ใจใ‚‚ใ‚ใ‚‹ใฎใงใ€ๅˆๆœŸๅ€คใฏ a.size() // /* ใฉใ‚“ใชไบŒๅˆ†ๆŽข็ดขใงใ‚‚ใ“ใ“ใฎๆ›ธใๆ–นใ‚’ๅค‰ใˆใšใซใงใใ‚‹๏ผ */ // while (right - left > 1) { // int mid = left + (right - left) / 2; // if (isOK(mid, key)) right = mid; // else left = mid; // } // /* left ใฏๆกไปถใ‚’ๆบ€ใŸใ•ใชใ„ๆœ€ๅคงใฎๅ€คใ€right ใฏๆกไปถใ‚’ๆบ€ใŸใ™ๆœ€ๅฐใฎๅ€คใซใชใฃใฆใ„ใ‚‹ */ // return right; // } int main() { // COMinit(); // srand((unsigned int)time(NULL));//--> rand() ll i, j, k, l, ans=0; ll n; ll t[5000]; string s[5000]; pair<ll ,string> p[5000]; cin >> n; for(i=0; i<n; i++) { cin>>p[i].second; cin>>p[i].first; } sort(p,p+n,greater<pair<int, string>>()); for(i=0; i<n; i++) { // cout<<p[i].second<<" "<<p[i].first<<endl; } cout << p[1].second << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int count = 0; for (int i = 0; i < N; i++) { int x; cin >> x; if (x > 10) count += x - 10; } cout << count << endl; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef pair<string,string> pss; typedef pair<ll,ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<pii> vpi; typedef vector<ll> vl; typedef vector<vl> vvl; #define f(i,a,b) for(int (i)=(a);(i)<(b);(i)++) #define d(i,a,b) for(int (i)=a;(i)>=(b);(i)--) #define foreach(a,b) for(auto&(a) : (b)) #define MAX(a,b) max(a,b) #define MIN(a,b) min(a,b) #define fi first #define se second #define mp make_pair #define all(v) v.begin(),v.end() #define Sort(v) sort(all(v)) #define Reverse(v) reverse(all(v)) #define Permute next_permutation #define TC(t) while(t--) #define pb push_back #define pf push_front #define IM INT_max #define IMI INT_MIN void solve(){ int t; cin>>t; int sum=0; TC(t){ int k; cin>>k; if(k/10>0) sum=sum+k-10; } cout<<sum; } int main(){ #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); freopen("error.txt","w",stderr); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); return 0; }
/* ID: ghallya2 TASK: ride PROG: ride LANG: C++ */ #include<cstdio> #include<iostream> #include<map> #include<set> #include<vector> #include<cstring> #include<cassert> #include<sstream> #include<cmath> #include<algorithm> #include<queue> #include<limits> #include<ctime> #include<stack> #include<bits/stdc++.h> #include<string> #include<stdlib.h> #include<stdio.h> #include<cstdlib> #include<unordered_set> #include<unordered_map> #include<complex> #include<chrono> #include<random> #include<bitset> #define forb(i,a,b) for(ll i=a;i<b;i++) #define fore(i,a,b) for(ll i=a;i<=b;i++) #define F first #define S second #define mp make_pair #define sortba(a,i,n) sort(a+i,a+n+i) #define sortra(a,i,n) sort(a+i,a+n+i,greater<int>()) #define sortb(a) sort(a.begin(),a.end()) #define sortr(a) sort(a.begin(),a.end(),greater<ll> ()) #define inf LLONG_MAX typedef long long int ll; typedef long double ld; using namespace std; const ll M=1e9+7; ll kombinasi(ll a,ll b){ ll ans=1,j=1;; ll y=max(b,a-b); for(ll i=a;i>y;i--){ ans*=i; ans%=M; ans/=j; j++; } return ans; } void solve(){ } int main() { //freopen("swap.in", "r", stdin); //freopen("swap.out", "w", stdout); ll n; cin>>n; ll a[n]; forb(i,0,n){ cin>>a[i]; } ll ans=0; forb(i,0,n){ ll mins=a[i]; forb(j,i,n){ mins=min(mins,a[j]); ans=max(mins*(j-i+1),ans); } } cout<<ans<<endl; }
/* "An anomaly, I'm Muhammad Ali Cause I know one day I'm gonna be the" - Greatest, Eminem */ #pragma GCC optimize ("O3") #pragma GCC target ("sse4") #include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef long long int ll; #define ff first #define Shazam ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define ss second #define all(c) c.begin(),c.end() #define endl "\n" #define test() int t; cin>>t; while(t--) #define fl(i,a,b) for(int i = a ; i <b ;i++) #define get(a) fl(i,0,a.size()) cin>>a[i]; #define pra(a) fl(i,0,a.size()) cout<<a[i]<<" "; cout<<endl; #define pr(a,n) fl(i,0,n) cout<<a[i]<<" "; cout<<endl; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; const ll INF = 2e18; const int inf = 2e9; const int mod1 = 1e9 + 7; int main(){ Shazam; int n; cin >> n; vector<ll> a(n), b(n); get(a); get(b); ll sum = 0; for(int i = 0; i < n; i++){ sum += (a[i] * b[i]); } cout <<( sum ? "No" : "Yes") << endl; return 0; }
///******* In the name of Allah *******/// #include <bits/stdc++.h> using namespace std; #define fastio ios_base::sync_with_stdio(false), cin.tie(NULL); #define nl '\n' void Ok() { long int a,b,c,d,e,f,g,h,t,i,j,k,l,m,n,Mn,Mx; long int ans_1,ans_2,ans_3,cnt_1,cnt_2,cnt_3,flag_1,flag_2,flag_3,temp,sum; double aa,bb,cc,dd,ee,ff,gg; char aaa,bbb,ccc,ddd; string spc,in,store; fastio; Mn = 999; for(i=1;i<=4;i++) { cin>>a; Mn = min(a,Mn); } cout<<Mn<<nl; return; } int main() { Ok(); return 0; }
#include <bits/stdc++.h> using namespace std; main(){ string s;cin>>s; for (int i = 0; i < s.size(); ++i) { /* code */ if(s[i]=='.'){ cout<<s.substr(0,i); break; } if(i==s.size()-1)cout<<s; } }
#include<bits/stdc++.h> //Ithea Myse Valgulious namespace chtholly{ typedef long long ll; #define re0 register int #define rel register ll #define rec register char #define gc getchar //#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<23,stdin),p1==p2)?-1:*p1++) #define pc putchar #define p32 pc(' ') #define pl puts("") /*By Citrus*/ char buf[1<<23],*p1=buf,*p2=buf; inline int read(){ int x=0,f=1;char c=gc(); for (;!isdigit(c);c=gc()) f^=c=='-'; for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0'); return f?x:-x; } template <typename mitsuha> inline bool read(mitsuha &x){ x=0;int f=1;char c=gc(); for (;!isdigit(c)&&~c;c=gc()) f^=c=='-'; if (!~c) return 0; for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0'); return x=f?x:-x,1; } template <typename mitsuha> inline int write(mitsuha x){ if (!x) return 0&pc(48); if (x<0) pc('-'),x=-x; int bit[20],i,p=0; for (;x;x/=10) bit[++p]=x%10; for (i=p;i;--i) pc(bit[i]+48); return 0; } inline char fuhao(){ char c=gc(); for (;isspace(c);c=gc()); return c; } }using namespace chtholly; using namespace std; const int yuzu=2e5; typedef int fuko[yuzu|10]; fuko a; int main() { for (int t=read();t--;) { int i,n=read(); for (i=1;i<=n;++i) a[i]=read(); sort(a+1,a+n+1); if (n&1) puts("Second"); else { int lxy=0; for (i=1;i<=n;i+=2) lxy|=a[i]^a[i+1]?1:0; puts(lxy?"First":"Second"); } } }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using P = pair<int, int>; vector<int> in(200005, 0); vector<int> out(200005, -1); vector<vector<int>> in_D(200005); int cnt = 0; void dfs(int v, int d, vector<vector<int>> &G) { in[v] = cnt; in_D[d].push_back(in[v]); cnt++; for (auto &nv : G[v]) { dfs(nv, d + 1, G); } out[v] = cnt; cnt++; } int main() { int n; cin >> n; vector<int> p(n); // 0ใŒๆ น rep(i, n - 1) { cin >> p[i + 1]; p[i + 1]--; } int q; cin >> q; vector<int> u(q), d(q); rep(i, q) { cin >> u[i] >> d[i]; u[i]--; } vector<vector<int>> G(n); rep(i, n - 1) { G[p[i + 1]].push_back(i + 1); } dfs(0, 0, G); rep(i, q) { int ans = lower_bound(in_D[d[i]].begin(), in_D[d[i]].end(), out[u[i]]) - lower_bound(in_D[d[i]].begin(), in_D[d[i]].end(), in[u[i]]); cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int MAX32 = 2147483647; const long long MAX64 = 9223372036854775807; const double PI = 3.14159265358979323846; int main() { long long n, m, sum, min = MAX64, a = 0, b = 0, c = 0, ind; cin >> n >> m; vector<long long> h(n), w(m), dp(n, 0); for (int i = 0; i < n; i++) { cin >> h[i]; } for (int i = 0; i < m; i++) { cin >> w[i]; } sort(h.begin(), h.end()); h.push_back(MAX64); for (int i = 0; i < n; i++) { if (i >= 2) { c = dp[i - 2]; } if (i % 2) { dp[i] = h[i] - a + c; b = h[i]; } else { a = h[i]; dp[i] = h[i] - b + c; } } for (int i = 0; i < m; i++) { ind = lower_bound(h.begin(), h.end(), w[i]) - h.begin(); if (ind >= 2) { b = 1; } else { b = 0; } if (ind % 2) { sum = b * dp[ind - 2] + w[i] - h[ind - 1] + dp[n - 1] - dp[ind - 1]; } else { sum = b * dp[ind - 1] + h[ind] - w[i] + dp[n - 1] - dp[ind]; } if (min > sum) { min = sum; } } cout << min << endl; }
#include <bits/stdc++.h> using namespace std; #define sz(x) ((int) (x).size()) typedef pair<int, int> pii; typedef long long ll; const int maxn = 2e5 + 5; const int maxk = 300 + 5; template<class T> void print(T & x){ cout << x; } template<class T,class U> void print(pair<T,U> & p){cout << "("; print(p.first); cout << ", "; print(p.second); cout << ")"; } template<class T> void print(vector<T> & v) { cout << "{"; if (sz(v)) print(v[0]); for (int i = 1; i < sz(v); i++) cout << ", ", print(v[i]); cout << "}\n"; } const int MOD = 998244353; const int inv2 = (MOD + 1) / 2; ll A[maxn], f[maxk], rf[maxk], sum[maxk], p[maxk], inv[maxk], pb[maxk], self[maxn][maxk]; inline ll add(ll a, ll b) { // ๅธฆๅ‡ๆณ• return ((a + b) % MOD + MOD) % MOD; } inline ll mul(ll a, ll b) { return (a * b) % MOD; } ll c(int n, int k) { return (k < 0 || k > n) ? 0 : mul(f[n], mul(rf[n-k], rf[k])); } ll fpow(ll a, ll n) { a %= MOD; ll ret = 1; for (; n; n >>= 1, a = mul(a, a) ) if (n & 1) ret = mul(ret, a); return ret; } int n, m; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for (int i = 1;i <= n; ++i) { cin >> A[i]; } inv[0] = inv[1] = 1; for(int i = 2; i <= max(2,m); ++ i) { inv[i]=(ll)(MOD-MOD/i)*inv[MOD%i]%MOD; } f[0] = rf[0] = 1; for (int i = 1;i <= m; ++i) { f[i] = mul(f[i-1], i); rf[i] = mul(rf[i-1], inv[i]); } for (int i = 1;i <= n; ++i) { self[i][0] = 1; for (int k = 1;k <= m; ++k) { self[i][k] = mul(self[i][k-1], A[i]); } } for (int k = 0;k <= m; ++k) { p[k] = 0; for (int i = 1;i <= n; ++i) { p[k] = add(p[k], self[i][k]); } } for (int i = 1;i <= m; ++i) { pb[i] = mul(p[i], fpow(2, i)); } for (int x = 1; x <= m; ++x) { ll ans = 0; for (int i = 0;i <= x; ++i) { ans = add(ans, mul(c(x, i), mul(p[i], p[x-i]))); } ans = add(ans, -pb[x]); ans = mul(ans, inv2); cout << ans << endl; } return 0; }
//----AUTHOR:kkdrummer----/ #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> //#include <boost/multiprecision/cpp_int.hpp> //using namespace boost::multiprecision; using namespace __gnu_pbds; using namespace std; typedef long long ll; typedef double ld; typedef unordered_set<ll> usll; typedef unordered_multiset<ll> umsll; typedef multiset<ll> msll; typedef set<ll> sll; typedef vector<ll> vll; typedef pair<ll,ll> pll; typedef vector<pll> vpll; typedef priority_queue<ll> pqll; typedef vector<int> vi; typedef set<int> si; typedef multiset<int> msi; typedef unordered_multiset<int> umsi; typedef unordered_set<int> usi; typedef pair<int,int> pi; typedef vector<pi> vpi; typedef priority_queue<int> pqi; typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ind_si; typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ind_sll; typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> ind_msi; typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> ind_msll; #define in insert #define fi first #define se second #define pb push_back #define mp make_pair #define be begin #define en end #define itr iterator #define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define mo 1000000007 #define inf 8222372026854775807 #define ninf -inf #define ima 2047483647 #define imi -ima #define oncnt __builtin_popcount #define zerobegin __builtin_clz #define zeroend __builtin_ctz #define parity __builtin_parity #define eps 1e-9 #define coutd cout<<setprecision(6)<<fixed #define mems(dp,x) memset(dp,x,sizeof(dp)) #define fbo find_by_order #define ook order_of_key #define all(x) x.be(),x.en() #define upb upper_bound #define lowb lower_bound #define lte(v,x) (upb(all(v),x)-v.be()) #define gte(v,x) (v.end()-lowb(all(v),x)) #define gt(v,x) (v.en()-upb(all(v),x)) #define lt(v,x) (lowb(all(v),x)-v.be()) const ld PI= 3.1415926535897932384626433832792884197169399375105820974944; inline ll mpow(ll x,ll n){if(n==0)return 1;if(x==0)return 0;if(n==1)return(x%mo);ll u=(mpow(x,n/2));u=(u*u)%mo;if(n%2!=0)u=(u*x%mo)%mo;return u;} inline ll minv(ll x){return mpow(x,mo-2);} inline ll mmul(ll a,ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);} inline ll madd(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a+b>=mo)return(a+b)%mo;return(a+b);} inline ll msub(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;return(((a-b)%mo+mo)%mo);} inline ll mdiv(ll a,ll bb){if(a>=mo)a=a%mo;ll b=minv(bb);if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);} inline ll gcd(ll a,ll b){return __gcd(a,b);} inline ll lcm(ll a,ll b){return (a*b)/gcd(a,b);} int main() { io int testcases=1; // cin>>testcases; while(testcases--) { ll m,h; cin>>m>>h; if(h%m)cout<<"No"; else cout<<"Yes"; }return 0;}
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for( int i = 0 ; i < n ; i++ ) int main() { int m , h ; cin >> m >> h ; if( h % m == 0 )cout << "Yes" << endl ; else cout << "No" << endl; }
#include <iostream> #include <algorithm> #include <map> #include <set> #include <queue> #include <stack> #include <numeric> #include <bitset> #include <cmath> static const int MOD = 1000000007; using ll = long long; using u32 = unsigned; using u64 = unsigned long long; using namespace std; template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208; int main() { string s; cin >> s; if(s[0] == s[1] && s[1] == s[2]) puts("Won"); else puts("Lost"); return 0; }
#include<bits/stdc++.h> using namespace std; #define tezi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define pb push_back #define rep(i,a,b) for(int i=a;i<b;i++) #define all(c) c.begin(),c.end() #define ll long long #define ull unsigned long long #define traverse(c,it) for(auto it=c.begin();it!=c.end();it++) #define lowerb(v,a) lower_bound(v.begin(),v.end(),a) #define lowerbarr(v,n,a) lower_bound(v,v+n,a) #define upperb(v,a) upper_bound(v.begin(),v.end(),a) #define upperbarr(v,n,a) upper_bound(v,v+n,a) #define maxval(v) max_element(v.begin(),v.end()) #define maxarr(v,n) max_element(v,v+n) #define minval(v) min_element(v.begin(),v.end()) #define minarr(v,n) min_element(v,v+n) #define sz(a) (ll)a.size() #define fr first #define se second #define PI 3.1415926536 #define vi vector<int> #define pii pair<int,int> #define mem0(v) memset(v,0,sizeof(v)) #define memf(v) memset(v,false,sizeof(v)) #define memt(v) memset(v,true,sizeof(v)) #define mem(v,a) memset(v,a,sizeof(v)) #define npos string::npos #define MAX 300000 #define MOD 998244353 #define precision(x) setprecision(x) #define mp make_pair // #define inf (ll)1e5 /**************SIEVE****************/ bool prime[MAX+1]; vector<ll> v; void sieve(){ // Create a boolean array "prime[0..n]" and initialize // all entries it as true. A value in prime[i] will // finally be false if i is Not a prime, else true. memset(prime, true, sizeof(prime)); for (long p=2; p*p<=MAX; p++) { // If prime[p] is not changed, then it is a prime if (prime[p] == true) { // Update all multiples of p greater than or // equal to the square of it // numbers which are multiple of p and are // less than p^2 are already been marked. for (long i=p*p; i<=MAX; i += p) prime[i] = false; } } for(long p=2;p<=MAX;p++) { if(prime[p])v.pb(p); } } /**************gcd****************/ ll gcd(ll a,ll b) { if(a>b)swap(a,b); if (a == 0) return b; return gcd(b%a, a); } /**************POWER****************/ ll binpow(ll a, ll b) { if (b == 0) return 1; ll res = binpow(a, b / 2)%MOD; if (b % 2) return (((ll)res * (ll)res %MOD)* (ll)a)%MOD; else return ((ll)res * (ll)res)%MOD; } /**************MAIn****************/ void solve() { char a,b,c; cin>>a>>b>>c; if(a==b && b==c) { cout<<"Won"; } else cout<<"Lost"; } int main() { tezi int T=1; //cin>>T; while(T--) { solve(); } }
#include <bits/stdc++.h> #define pii pair<int, int> #define pll pair<long long, long long> #define L(n) (n << 1) #define R(n) (n << 1 | 1) #define print_vector(n) for(auto a0 : n) cout << a0 << ' '; cout << endl; #define vector_sort(n) sort(n.begin(), n.end()) #define print_array(n, l, r) for(int a0 = l; a0 <= r; a0++) cout << n[a0] << ' '; cout << '\n'; #define MIN(a, b) (a < b ? a : b) #define MAX(a, b) (a > b ? a : b) #define ABS(a) ((a) > 0 ? (a) : -(a)) using namespace std; template<class T> istream & operator >> (istream &in, pair<T, T> &p) { in >> p.first >> p.second; return in; } template<class T> ostream & operator <<(ostream &out, pair<T, T> &p) { out << p.first << ' ' << p.second; return out; } template<class Tuple, std::size_t N> struct TuplePrinter { static void print(ostream &out, const Tuple& t) { TuplePrinter<Tuple, N-1>::print(out, t); out << ' ' << get<N-1>(t); } }; template<class Tuple> struct TuplePrinter<Tuple, 1> { static void print(ostream &out, const Tuple& t) { out << get<0>(t); } }; template<class... Args> ostream & operator <<(ostream &out, const tuple<Args...> &p) { TuplePrinter<decltype(p), sizeof...(Args)>::print(out, p); return out; } int N; long long A[300005]; map<pll, int> cnt; int main() { ios_base::sync_with_stdio(0); cin >> N; pll offset = {}; long long ans = 0; for (int i = 1; i <= N; i++) cin >> A[i]; for (int i = 1; i <= N; i++) { pll now = offset; pll new_start = offset; // cout << offset << "\n"; if (i & 1) { now.second -= A[i]; // now.first = -now.first; // now.second = -now.second; ans += cnt[now]; new_start.first -= A[i]; cnt[new_start]++; offset.second += A[i + 1] - A[i]; }else { now.first -= A[i]; // now.first = -now.first; // now.second = -now.second; ans += cnt[now]; new_start.second -= A[i]; cnt[new_start]++; offset.first += A[i + 1] - A[i]; } // cout << " -> " << new_start << "\n"; // cout << " -> " << now << "\n"; } cout << ans << "\n"; }
#include<iostream> #include<vector> #include<algorithm> #include<stdlib.h> #include<utility> #include<functional> #include<cfenv> #include<cmath> #include<string> #include<queue> #include<stack> #include<map> #include<set> #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) #define vint vector<ll> #define vvint vector<vint> #define P pair<int,int> #define INT_MAX 2147483647 #define MOD 1000000007 #define PI 3.14159265358979323846 #define all(a) (a).begin(),(a).end() using namespace std; typedef long long ll; #define MAX 1000000000000 int main(void) { unsigned long long x, y, a, b; cin >> x >> y >> a >> b; unsigned long long e = 0; if(x>=1000000000){ e += (y - x) / b; if ((y - x) % b == 0) { e--; } cout << e << endl; return 0; } while (true) { if (a*x < x + b) { x *= a; e++; } else { break; } if (x >= y) { e--; cout << e << endl; return 0; } } e += (y - x) / b; if ((y - x) % b == 0) { e--; } cout << e << endl; return 0; }
#include <bits//stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; // MACROS #define int long long #define pb push_back #define MAX 1e17 #define MIN -1e17 #define mod 1000000007 #define eps 1e-9 #define set(x) memset(x, 0, sizeof(x)) #define clr(x) memset(x, -1, sizeof(x)) #define ff first #define ss second #define rep(i,a,b) for(int i=a;i<b;i++) #define sz(x) x.size() #define endl "\n" #define deb(x) cout << #x << "=" << x << endl #define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl #define all(x) x.begin(), x.end() #define lb(a,x) lower_bound(all(a),x) #define ub(a,x) upper_bound(all(a),x) typedef priority_queue<int> maxHeap; typedef priority_queue<int, vector<int>, greater<int>> minHeap; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<string> vs; typedef vector<pii> vpii; typedef vector<vi> vvi; typedef map<int, int> mpii; typedef set<int> seti; typedef multiset<int> mseti; template<typename T> using pbds = tree<T , null_type , less<T> , rb_tree_tag , tree_order_statistics_node_update>; 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;} // typedef long long int ll; // cout << fixed << setprecision(9) << int mpow(int base, int exp); const int T2 = 105; const int T3 = 1005; const int T4 = 10005; const int T5 = 100005; const int N = 3e5; int arr[N]; void solve() { long double x, y, r; cin >> x >> y >> r; r = nextafter(r, INFINITY); int ans = 0; for (int i = ceil(x - r); i <= floor(x + r); i++) { long double tmp = sqrt(r * r - (x - i) * (x - i)); int from = ceil(y - tmp), to = floor(y + tmp); ans += to - from + 1; } cout << ans; } /* TIPS 1. for interactive prob remove fastio and endl 2. for vector pass as reference 3. dont use set and clr when n * t is very large use loop till n instead. 4. */ int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE // for getting input from input.txt freopen("input.txt", "r", stdin); // for writing output to output.txt freopen("output.txt", "w", stdout); #endif int t = 1; // cin >> t; for (int i = 1; i <= t; i++) { // cout<<"Case #"<<i<<": "; solve(); } return 0; } int mpow(int base, int exp) { base %= mod; int result = 1; while (exp > 0) { if (exp & 1) result = ((int)result * base) % mod; base = ((int)base * base) % mod; exp >>= 1; } return result; }
#include <bits/stdc++.h> using namespace std; int main() { /* ios::sync_with_stdio(false); cin.tie(0);*/ double x,y,X,Y; cin>>x>>y>>X>>Y; double ans,d; d=y*(X-x)/(Y+y); ans=x+d; cout <<fixed<<setprecision(6)<<ans<<"\n"; return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int N, K; cin >> N >> K; cout << (100 * N + K + 101) * N * K / 2 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int total = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= k; j++) { total += (i * 100 + j); } } cout << total; return 0; }
#include<bits/stdc++.h> using namespace std; int main() { char S[10]; int i; cin >> S; for(i=0; i<3; i++) { cout << S[1] << S[2] << S[0]; break; } return 0; }
#include<iostream> #include<cmath> #include<string> using namespace std; int main(){ string ss; cin>>ss; string p,t; p[0]=ss[1]; p[1]=ss[2]; p[2]=ss[0]; for(int i=0;i<=2;i++){ t += p[i]; } cout<<t; return 0; }
#include <bits/stdc++.h> #define rep(i,cc,n) for(int i=cc;i<=n;++i) #define drep(i,cc,n) for(int i=cc;i>=n;--i) template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } const long long INF = 1LL <<60; const long long MOD = 1000000007; typedef long long ll; using namespace std; ll gcd(ll m,ll n){ if(n==0) return m; return gcd(n,m%n); } int main(){ int a,b; cin >> a >> b; int ans; rep(i,1,b){ int tmp = 0; if(b / i > 1) tmp = b / i; else break; if(i * (tmp - 1) >= a && i * (tmp - 1) <= b) ans = i; } cout << ans << endl; return 0; }
#include<iostream> #include<bits/stdc++.h> using namespace std; #define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); typedef int _loop_int; #define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i) #define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i) #define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i) #define DEB(x) cout << #x << " " << x << endl; #define DEB_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl #define ALL(a) (a).begin(),(a).end() #define CHMIN(a,b) a=min((a),(b)) #define CHMAX(a,b) a=max((a),(b)) typedef long long int LL; typedef pair<int, int> PI; typedef pair<LL, LL> PLL; typedef pair<int, PI> PPI; typedef vector<int> VI; typedef vector<LL> VLL; typedef vector<vector<int>> VVI; void solve() { int a, b; cin >> a >> b; FORR(i, 1, b) { int ra = max(i, a); int k = ra / i; int proda = i*k; if (proda < a) proda = i*(++k); if (proda > b) continue; int prodb = i*(k+1); if (prodb >= a && prodb <= b) { cout << i << endl; return; } } } int main() { IOS // int t; // cin >> t; // while (t--) { solve(); // } return 0; }
// Copyright 2020 Tsutomu ISHIKAWA // Author: Tsutomu ISHIKAWA #include <iostream> #include <climits> #include <algorithm> #include <cmath> #include<string> using namespace std; // DPใƒ†ใƒผใƒ–ใƒซ int x; int main() { cin >> x; if (x < 0) { cout << 0 << endl; return 0; } else { cout << x << endl; return 0; } }
#include<bits/stdc++.h> //#include<atcoder/all> using namespace std; using ll = long long; int main() { int n;cin >> n; n = max(n,0); cout<< n<< endl; }
#include "bits/stdc++.h" using namespace std; typedef long long li; int main() { cin.tie(0); ios::sync_with_stdio(false); li n; cin >> n; vector<li> xs(n); for (int i = 0; i < n; ++i) { cin >> xs[i]; } li ans = xs[0]; for (int i = 0; i < n; ++i) { ans = __gcd(ans, xs[i]); } cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; using u64 = uint_least64_t; using s64 = int_least64_t; using ll = uint_least64_t; int main(){ u64 n; cin >> n; vector<u64> a(n); for (u64 i = 0; i < n; i++){ cin >> a[i]; } sort(a.begin(), a.end()); // a.erase(unique(a.begin(), a.end()), a.end()); u64 sum; for (u64 i = 0; i < a.size(); i++){ if (i == 0){ sum = a[i]%1000000007 +1; }else{ sum *= a[i]%1000000007 - a[i - 1]%1000000007+1; sum = sum % 1000000007; } } cout << sum << endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; typedef pair<ll, ll> LP; typedef unsigned int uint; typedef unsigned long long ull; #define repi(i, a, b) for(int i = int(a); i < int(b); i++) #define rep(i, n) repi(i, 0, n) #define repir(i, a, b) for(int i = int(a); i > int(b); i--) #define repr(i, n) repir(i, n - 1, 0) #define INF 1000000000 #define INF_LL 4000000000000000000 #define all(x) (x).begin(), (x).end() #define UNI(x) (x).erase(unique(all(x)),(x).end()) #define F first #define S second #define MP make_pair #define MT make_tuple int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; int main(){ string a, b; cin >> a >> b; int sa = 0; int sb = 0; rep(i, a.length()){ sa += a[i] - '0'; } rep(i, b.length()){ sb += b[i] - '0'; } cout << max(sa, sb) << endl; }
#include<bits/stdc++.h> using namespace std; int n,a[100010],b[100010],v[2][50010]; long long ans; int main(){ scanf("%d",&n); for(int i=1;i<=n;++i)scanf("%d",&a[i]),ans+=a[i]; for(int i=1;i<=n;++i)scanf("%d",&b[i]),v[i&1][i+1>>1]=b[i]-a[i]; sort(v[0]+1,v[0]+(n>>1)+1),sort(v[1]+1,v[1]+(n>>1)+1); for(int i=(n>>1);i>=1&&v[0][i]+v[1][i]>0;--i)ans+=v[0][i]+v[1][i]; printf("%lld",ans); return 0; }
#include <bits/stdc++.h> using namespace std; // #include <ext/pb_ds/assoc_container.hpp> //required // #include <ext/pb_ds/tree_policy.hpp> //required // using namespace __gnu_pbds; //required // 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 #pragma GCC optimize("-Ofast") #pragma GCC optimize("trapv") #pragma GCC target( \ "sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native") #pragma GCC optimize("-ffast-math") #pragma GCC optimize("-funroll-loops") #pragma GCC optimize("-funroll-all-loops,-fpeel-loops,-funswitch-loops") #define mod (1000000000+7) #define pii pair<ll, ll> #define vi vector<int> #define vvi vector<vector<int>> #define f first #define s second #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 forf(i, a, b) for (int i = (a); i < (b); i++) #define forr(i, a, b) for (ll i = (a); i > (b); i -= 1) #define input(vec, N) for (int i = 0; i < (N); i++) cin >> vec[i]; typedef long long ll; #define ld long double const int N = 1<<18; const int MAXK = 12; const ll INF = 2000000000000000000; const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count(); // struct chash { // int operator()(int x) const { return x ^ RANDOM; } // }; // gp_hash_table<int, unsigned long long, chash> m[12]; ll expo_pow(ll x, ll y) { if (y == 0) return 1; y = y % (mod - 1); x %= mod; if (y == 0) y = mod - 1; ll res = 1; while (y) { if (y & 1) res = (res * x) % mod; x = (x * x) % mod; y >>= 1; } return res; } ll modInverse(ll a, ll m = mod) { return expo_pow(a, m - 2); } void solve (int te){ string s; cin>>s; int cnt[10]; memset(cnt,0,sizeof(cnt)); for(auto x : s){ cnt[x-'0']++; } forf(i,100,1000){ if(i%8==0){ int tcnt[10]; forf(i,0,10) tcnt[i] = cnt[i]; int j = i; int f=0; while(j){ if(!tcnt[j%10]){ f=1; break; } else tcnt[j%10]--; j/=10; } if(!f){ cout<<"Yes"<<'\n'; return; } } } forf(i,0,100){ if(i%8==0){ int tcnt[10]; forf(i,0,10) tcnt[i] = cnt[i]; int j = i; int f=0; while(j){ if(!tcnt[j%10]){ f=1; break; } else tcnt[j%10]--; j/=10; } forf(i,0,10){ if(tcnt[i]){ f=1; break; } } if(!f){ cout<<"Yes"<<'\n'; return; } } } cout<<"No"<<'\n'; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int T = 1; // freopen("f.txt","r",stdin); // freopen("output.txt","w",stdout); //cin >> T; int t=1; // sieve(); while (t<=T) { solve(t); t++; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<bool> vb; typedef map<int, int> mii; typedef pair<int, int> ii; #define INF 0x3f3f3f3f #define INFLL 0x3f3f3f3f3f3f3f3f #define each(x, s) for(auto& x : s) #define loop(x) for(int i = 0;i < x;i++) #define vloop(v, x) for(int v = 0;v < x;v++) #define avg(l, r) l + (r - l) / 2 #define iter(a) a.begin(), a.end() #define riter(a) a.rbegin(), a.rend() #define endl "\n" const ll mod = 1000000007; int main() { ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); vi start = {0, 8, 16, 104}; string s; cin >> s; vi cnt(10, 0), cnt2(10, 0); each(c, s) cnt[c - '0']++; bool ok = false; int n = s.length(); for (int i = start[min(n, 3)];i < 1000 and !ok;i += 8) { string t = to_string(i); each(c, t) { cnt2[c - '0']++; } if (!cnt2[0]) { ok = true; loop(10) { if (cnt2[i] > cnt[i]) ok = false; } } each(c, t) cnt2[c - '0']--; } cout << (ok ? "Yes" : "No") << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { size_t N, M; cin >> N >> M; vector<int> A(M + 2, 0); for (size_t i = 1; i <= M; i++) { cin >> A[i]; } A.back() = N + 1; sort(A.begin(), A.end()); map<int, size_t> count; int minimum = N; for (size_t i = 0; i <= M; i++) { if (A[i] + 1 == A[i + 1]) { continue; } minimum = min(A[i + 1] - A[i] - 1, minimum); count[A[i + 1] - A[i] - 1]++; } int ans = 0; for (pair<int, size_t> c : count) { ans += (c.first + (minimum - 1)) / minimum * c.second; } cout << ans << endl; }
#pragma GCC optimize ("O2") #pragma GCC target ("avx") #include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; #include<iostream> #include<cstring> using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please const int bm = 200001; int BIT[bm]; void add(int A) { while (A > 0) { BIT[A]++; A -= A & -A; } } int query(int A) { int ret = 0; while (A <= bm) { ret += BIT[A]; A += A & -A; } return ret; } ll tmp[200001]; void pakuri_sort(int N, ll A[]) { const int b = 8; 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]; } } int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; ll A[200000], B[200000]; rep1(i, N) cin >> A[i]; rep1(i, N) cin >> B[i]; rep1(i, N) A[i] += i * (1ll << 32 | 1); rep1(i, N) B[i] += i * (1ll << 32 | 1); pakuri_sort(N, A + 1); pakuri_sort(N, B + 1); rep1(i, N) { if ((A[i] ^ B[i]) & (1ll << 32) - 1) { co(-1); return 0; } tmp[A[i] >> 32] = B[i] >> 32; } ll kotae = 0; rep1(i, N) { kotae += query(tmp[i]); add(tmp[i]); } co(kotae); Would you please return 0; }
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define rng(i, a, b) for (int i = int(a); i < int(b); ++i) #define rep(i, b) rng(i, 0, b) #define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); --i) #define per(i, b) gnr(i, 0, b) #define all(obj) begin(obj), end(obj) #define allr(obj) rbegin(obj), rend(obj) #define cinv(a) rep(i, (int)a.size()) cin >> a[i] #define pb push_back #define eb emplace_back #define sz(x) (int)(x).size() typedef long long ll; typedef pair<int, int> Pi; typedef vector<Pi> vp; typedef vector<vp> vvp; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<char> vc; typedef vector<vc> vvc; typedef vector<bool> vb; typedef vector<vb> vvb; 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; } template <typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>; const int di[] = {0, -1, 0, 1}; const int dj[] = {1, 0, -1, 0}; const int MOD = 1e9 + 7; const int INF = 1e9; const ll LINF = 1e15; const long double eps = 1e-10; const char nl = '\n'; ll power(ll a, ll b) { return b ? power(a * a % MOD, b / 2) * (b % 2 ? a : 1) % MOD : 1; } ll C(int n, int k) { ll x = 1, y = 1; for (int i = 1; i <= k; ++i) { x = x * (n - i + 1) % MOD; y = y * i % MOD; } return x * power(y, MOD - 2) % MOD; } struct UF { vi d; UF(int n) : d(n, -1) {} int root(int x) { if (d[x] < 0) return x; return d[x] = root(d[x]); } bool unite(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (d[x] > d[y]) swap(x, y); d[x] += d[y]; d[y] = x; return true; } bool same(int x, int y) { return root(x) == root(y); } int size(int x) { return -d[root(x)]; } }; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; double x0, y0, xn, yn; cin >> x0 >> y0 >> xn >> yn; complex<double> a{x0, y0}, b{xn, yn}; auto o = (a+b)/2.0; double angle = 2*M_PI/n; complex<double> c{cos(angle), sin(angle)}; auto ans = o + (a-o)*c; cout << ans.real() << " " << ans.imag() << nl; }
#include <iostream> #include <vector> #include <unordered_set> #include <algorithm> using namespace std; struct Node { int id; long long int c; long long int diff; int depth; vector<Node *> next; }; void travel(Node *curr, long long int currentDiff, Node *from = nullptr) { currentDiff += curr->diff; curr->c = currentDiff; for(auto &n : curr->next) { if(n != from) travel(n, currentDiff, curr); } } void setDepth(Node *curr, Node *from = nullptr) { if(from == nullptr) curr->depth = 0; else curr->depth = from->depth + 1; for(auto &n : curr->next) { if(n != from) setDepth(n, curr); } } int main() { int N, Q; cin >> N; auto nodes = vector<Node>(N); auto edges = vector<pair<int,int>>(N-1); int id = 1; for(auto& n : nodes) { n.id = id++; n.next = vector<Node *>(); n.diff = 0; n.c = 0; } for(auto& e : edges) { int a, b; cin >> a >> b; a--; b--; e.first = a; e.second = b; nodes[a].next.push_back(&nodes[b]); nodes[b].next.push_back(&nodes[a]); } // set depth, nodes[0] is root Node *root = &nodes[0]; setDepth(root); cin >> Q; for(int i = 0; i < Q; i++) { int t, e, x; int start, goal; cin >> t >> e >> x; e--; Node *a = &(nodes[edges[e].first]); Node *b = &(nodes[edges[e].second]); if(t == 2) swap(a, b); if( a->depth >= b->depth ) { a->diff += x; } else { root->diff += x; b->diff -= x; } } long long int currentDiff = 0; travel(root, currentDiff); for(auto n : nodes) { cout << n.c << endl; } return 0; }
#include <bits/stdc++.h> #define ALL(A) (A).begin(), (A).end() #define ll long long #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; 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 dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 }; // i<4:4way i<8:8way int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 }; const ll mod = 1e9 + 7; const ll INF = -1 * ((1LL << 63) + 1); const int inf = -1 * ((1 << 31) + 1); int main(void){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); int n; string s,t; cin >> n; rep(i,n){ char hoge; cin >> hoge; s.push_back(hoge); } rep(i,n){ char hoge; cin >> hoge; t.push_back(hoge); } int q; cin >> q; rep(_,q){ int T,a,b; cin >> T >> a >> b; a--;b--; if(T==1){ if(b < n){ swap(s[a],s[b]); }else if(a>=n){ swap(t[a-n],t[b-n]); }else{ swap(s[a],t[b-n]); } } else{ swap(s,t); } } cout << s << t << endl; }
#include<bits/stdc++.h> using namespace std; int main() {int a,b,c; cin >> a >> b >> c; if(a==b) cout << c << endl; else if(b==c) cout << a << endl; else if(a==c) cout << b << endl; else cout << 0 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; vector<bool> s(n); for(int i = 0; i < n; i++){ string now; cin >> now; if(now == "AND") s.at(i) = true; else s.at(i) = false; } long long ans = 1; reverse(s.begin(), s.end()); for(long long i = 0; i < n; i++){ if(s.at(i)) continue; long long sum = 1; for(int j = 0; j < n-i; j++) sum *= 2; ans += sum; } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; #define ll long long int main() { ll n; cin>>n; n=1<<n; ll left=0,right=0; map<ll,ll>mp; ll a[n+1]; for(ll i=1; i<=n; i++) { cin>>a[i]; mp[a[i]]=i; } for(ll i=1; i<=n; i++) { if(i<=n/2) left=max(left,a[i]); else right=max(right,a[i]); } if(left<right) cout<<mp[left]<<endl; else cout<<mp[right]<<endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin>> n; for (int i=0; i<n; ++i) { cout<< (i*2)%n+1 << " " << (i*2+1)%n+1 <<endl; } return 0; }
#include<bits/stdc++.h> using namespace std; unsigned long long n,k,sum,l; unsigned long long cf(unsigned long long x,unsigned long long y) { unsigned long long ans=1; for(int i=1;i<=y;i++) { ans*=x; } return ans; } int main() { scanf("%llu",&n); k=n; int p; for(int i=1;;i++) { if(k==0) break; k/=10; p++; } int m=(p-1)/3; for(int i=1;i<=m;i++) { sum+=(n+1-cf(1000,i)); } cout<<sum<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define deb(x) cout << #x << " " << x << endl; #define mod 1000000007 #define fast std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); #define endl "\n" const ll INF = 1e18; const ll NEGINF = -1 * INF; /*NOTES: Take care of ll vs int Never use an iterator after erasing it */ const int N = 2e5 + 5; vector<array<ll, 2>> adjList[N]; ll dist[N]; void dfs(int currNode, int parent, ll currDist) { dist[currNode] = currDist; for (array<ll, 2> v : adjList[currNode]) { if (v[0] != parent) { dfs(v[0], currNode, currDist ^ v[1]); } } } ll my_pow(ll a, ll n, ll m = INF) { ll res = 1; while (n) { if (n % 2) { res = (res * a) % m; n--; } a = (a * a) % m; n /= 2; } return res; } void solve() { int n; cin >> n; ll u, v, w; for (int i = 0; i < n - 1; i++) { cin >> u >> v >> w; u--; v--; adjList[u].push_back({v, w}); adjList[v].push_back({u, w}); } dfs(0, -1, 0ll); ll ans = 0; for (ll i = 0; i < 60; i++) { ll cntOnes = 0; ll cntZeros = 0; for (int j = 0; j < n; j++) { if (dist[j] & (1ll << i)) { cntOnes++; } else { cntZeros++; } } ll totCnt = (cntOnes * cntZeros) % mod; ans = (ans + ((1ll << i) % mod * totCnt) % mod); } ans = ans % mod; //ans = (ans % mod * my_pow(2, mod - 2, mod) % mod) % mod; cout << ans << endl; } int main() { fast; #ifndef ONLINE_JUDGE freopen("/home/kalit/Desktop/Data Structures-Algo-Competitive/src/codeforces/input.txt", "r", stdin); freopen("/home/kalit/Desktop/Data Structures-Algo-Competitive/src/codeforces/output.txt", "w", stdout); #endif int T = 1; while (T--) { solve(); } //cout<< "Done in " << clock() / CLOCKS_PER_SEC <<"sec"<< endl; return 0; }
// I SELL YOU...! #include<iostream> #include<vector> #include<algorithm> #include<functional> #include<queue> #include<chrono> #include<iomanip> #include<map> #include<set> using namespace std; using ll = long long; using P = pair<ll,ll>; using TP = tuple<ll,ll,ll>; void init_io(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(18); } const ll MOD = 998244353; const ll MAX = 5100; bool can[MAX][MAX][3]; ll dp[MAX][MAX]={}; 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; } signed main(){ init_io(); ll H,W,K,fi=1,mv; cin >> H >> W >> K; mv = modinv(3,MOD); vector<ll> h(K),w(K); vector<char> c(K); for(int i=0;i<MAX;i++){ for(int j=0;j<MAX;j++){ for(int k=0;k<3;k++){ can[i][j][k] = true; } } } for(ll i=0;i<H*W-K;i++){ fi *= 3; fi %= MOD; } for(int i=0;i<K;i++){ cin >> h[i] >> w[i] >> c[i]; h[i]--; w[i]--; for(int j=0;j<3;j++){ can[h[i]][w[i]][j] = false; } if(c[i]=='R') can[h[i]][w[i]][0] = true; if(c[i]=='D') can[h[i]][w[i]][1] = true; if(c[i]=='X') can[h[i]][w[i]][2] = true; } dp[0][0] = 1; for(int i=0;i<H;i++){ for(int j=0;j<W;j++){ ll nv = dp[i][j]; if(can[i][j][0]&&can[i][j][1]&&can[i][j][2]){ nv = (nv*2*mv); nv %= MOD; dp[i][j+1] = (dp[i][j+1]+nv)%MOD; dp[i+1][j] = (dp[i+1][j]+nv)%MOD; }else if(can[i][j][0]){ dp[i][j+1] = (dp[i][j+1]+nv)%MOD; }else if(can[i][j][1]){ dp[i+1][j] = (dp[i+1][j]+nv)%MOD; }else if(can[i][j][2]){ dp[i][j+1] = (dp[i][j+1]+nv)%MOD; dp[i+1][j] = (dp[i+1][j]+nv)%MOD; } } } cout << (dp[H-1][W-1]*fi)%MOD << endl; }
#include<iostream> #include<vector> #include<cmath> #include<iomanip> #define int long long #define endl '\n' #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define infi INT_MAX #define rinfi INT_MIN #define inf LLONG_MAX #define rinf LLONG_MIN #define ff first #define ss second #ifndef ONLINE_JUDGE #define line cout<<"here - "<<__LINE__<<"\n"; #define dbg(a) cout<<#a<<" --> "<<(a)<<"\n"; #define db(a,b) cout<<#a<<" --> "<<(a)<<"\n";cin>>b; #else #define line #define dbg(a) #define db(a,b) #endif char _; using namespace std; const int mx=2e5+10; main() { // fast int tc=1,i,j,k; // cin>>tc; while(tc--) { int n,w; cin>>n>>w; int s,t,p; vector<int>aa(mx,0); for(i=0;i<n;i++) { cin>>s>>t>>p; aa[s]+=p; aa[t]-=p; } int ok=1; for(i=0;i<mx;i++) { if(i) aa[i]+=aa[i-1]; if(aa[i]>w) ok=0; } if(ok) cout<<"Yes"<<endl; else cout<<"No"<<endl; } }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define FILL0(x) memset(x, 0, sizeof(x)) #define FILL1(x) memset(x, -1, sizeof(x)) using namespace std; typedef long long ll; typedef pair<ll, ll> P; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); int n; ll w; cin >> n >> w; ll sp[200010], tp[200010]; FILL0(sp); FILL0(tp); int tmax = 0; rep(i, n) { int s, t; ll p; cin >> s >> t >> p; chmax(tmax, t); sp[s] += p; tp[t] += p; } ll water = 0; rep(i, tmax + 2) { water += sp[i]; water -= tp[i]; if (water > w) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; return 0; }
#include <iostream> #include <iomanip> #include <vector> #include <set> #include <string> #include <queue> #include <algorithm> #include <map> #include <cmath> #include <numeric> #include <list> #include <stack> #include <cstdio> #include <cstdlib> #include <cstring> #include <tuple> #include <deque> #include <complex> #include <bitset> using namespace std; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> pii; typedef vector<pii> vpii; typedef long long ll; typedef vector<ll> vll; typedef vector<vll> vvll; typedef pair<long long, long long> pll; typedef vector<pll> vpll; typedef long double ld; typedef vector<ld> vld; typedef vector<bool> vb; #define rep(i, n) for (ll i = 0; i < (n); i++) #define reps(i, n) for (ll i = 1; i <= (n); i++) #define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--) #define rreps(i, n) for (ll i = (n); i >= 1; i--) #define all(v) (v).begin(), (v).end() template <class T> void chmin(T& a, T b) { a = min(a, b);} template <class T> void chmax(T& a, T b) { a = max(a, b);} constexpr int INF = 1 << 30; constexpr ll INFL = 1LL << 60; constexpr ll MOD = 1000000007; constexpr ld EPS = 1e-12; ld PI = acos(-1.0); void solve() { ll n, a, b; cin >> n >> a >> b; cout << n - a + b << endl; return; } int main() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); cout << fixed << setprecision(15); solve(); }
#include <iostream> #include <vector> #include <algorithm> #include <stack> #include <map> #include <tuple> #include <cstdio> #include <cmath> #include <cassert> #include <functional> #define _LIBCPP_DEBUG 0 using namespace std; using ll = long long; int main() { int n,a,b; cin >> n >>a>>b; cout << n-a+b << endl; }
/* ุจูุณู’ู…ู ุงู„ู„ู‘ูŽู€ู‡ู ุงู„ุฑู‘ูŽุญู’ู…ูŽู€ูฐู†ู ุงู„ุฑู‘ูŽุญููŠู…ู ( ุฅูู†ู ุงู„ู’ุญููƒู’ู…ู ุฅูู„ู‘ูŽุง ู„ูู„ู‘ูŽู‡ู ) */ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii; typedef unsigned long long ull; typedef long double ld; const long double pi=acos(-1); #define x first #define y second #define read(n,a) for(int i=0;i<n;i++)cin>>a[i]; #define rep(i,z,n) for(ll i=z;i<n;i++) #define rrep(i,z,n) for(ll i=z-1;i>=n;i--) #define all(v) v.begin(),v.end() #define clr(v,d) memset(v,d,sizeof(v)); ll a[200004]; ll b[200004]; //int dx[] = {0, 0, 1,1, 1,-1,-1,-1}; //int dy[] = {1,-1, 0,1,-1, 0,1 ,-1}; int dx[] = {0,0,1,-1}; int dy[] = {1,-1,0,0}; string s, ss; ll n,m,k,w; ll ans ,ans1; ll mod = 1e9 +7; int main() { cin.tie(0); cin.sync_with_stdio(0); //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); int t=1; //cin>>t; while(t--) { cin>>n; s=to_string(n); m=s.size(); ans=1e9; rep(i,0,(1<<m)-1) { k=0; w=0; rep(j,0,m) { if(i& 1<<j)continue; k*=10; k+=s[j]-'0'; k%=3; w++; } if(k%3==0)ans=min(ans,m-w); } if(ans==1e9)ans=-1; cout<<ans; } return 0; }
/* HARE KRSNA HARE KRSNA KRSNA KRSNA HARE HARE HARE RAMA HARE RAMA RAMA RAMA HARE HARE */ #include<bits/stdc++.h> using namespace std; #define nl "\n" #define ff first #define ss second #define pp pop_back #define pf pop_front #define pb push_back #define lb lower_bound #define ub upper_bound #define all(x) x.begin(),x.end() #define test ll t; cin>>t; while(t--) #define loop(i,s,n) for(ll i=s;i<n;i++) #define rloop(i,s,n) for(ll i=s;i>=n;i--) #define fill(a,value) memset(a,value,sizeof(a)) #define debug1(a,n) loop(i,0,n) cout<<a[i]<<" "; cout<<nl; #define debug2(a) for(auto x : a) cout<<x<<" "; cout<<nl; #define debug4(a) for(auto x : a) cout<<x.ff<<" "<<x.ss<<nl; #define debug3(a,n,m) loop(i,0,n){ loop(j,0,m) cout<<a[i][j]<<" "; cout<<nl; } typedef long long ll; typedef long double ld; typedef stack<ll> sll; typedef queue<ll> qll; typedef deque<ll> dll; typedef vector<ll> vll; typedef vector<char> vc; typedef vector<string> vs; typedef pair<ll, ll> pll; typedef vector<pll> vpll; typedef pair<ll, pll> ppll; typedef vector<vector<ll>> vvll; typedef priority_queue<ll> pqll; const ll mod = 1000000007; const ll mod2 = 998244353; const ld pi = 3.1415926535; //acos((ld) - 1); set<string> S; void rec(string s, ll len) { if (!len) { S.insert(s); return; } rec(s + '1', len - 1); rec(s + '0', len - 1); } void solve() { string n; cin >> n; rec("", n.size()); // debug2(S); ll ans = 9e18; for (auto x : S) { if ((ll)count(all(x), '0') == x.size()) continue; ll sum = 0; // cout << x << nl; loop(i, 0, x.size()) { if (x[i] == '1') sum += (n[i] - 48); } if (sum && sum % 3 == 0) { ans = min(ans, (ll)count(all(x), '0')); // cout << sum << " " << x << nl; } } if (ans == 9e18) ans = -1; cout << ans << nl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif // test solve(); return 0; }
//Show them your PROGRESS #include <bits/stdc++.h> using namespace std; #define int long long int #define pb push_back const int M = 1e9 + 7; const int MAX = 2e6 + 5; #define selena ios_base::sync_with_stdio(false);cin.tie(NULL); #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") int findMaxGCD(vector<int> arr, int n) { // Calculating MAX in array int high = 0; for (int i = 0; i < n; i++) high = max(high, arr[i]); int count[high + 1] = {0}; for (int i = 0; i < n; i++) count[arr[i]]++; int counter = 0; for (int i = high; i >= 1; i--) { int j = i; counter = 0; while (j <= high) { if(count[j] >=2) return j; else if (count[j] == 1) counter++; j += i; if (counter == 2) return i; } } } void solve(){ int n, m; cin >> n >> m; vector<int> v; for(int i = n; i <= m; i++) v.pb(i); cout << findMaxGCD(v, v.size()) << "\n"; } int32_t main() { selena int tc = 1; //cin >> tc; while(tc--){ solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; // TYPEDEF ------------------------------ typedef long long ll; typedef long double ld; typedef pair<ll, ll> Pair; typedef vector<ll> vll; typedef vector<ld> vld; typedef vector<vector<ll>> Graph; typedef vector<string> vs; typedef vector<pair<ll, ll>> Pll; typedef queue<ll> qll; typedef map<ll, ll> mll; // REPEAT ------------------------------ #define REP(i,n) for(ll i=0;i<(ll)(n);i++) #define REPD(i,n) for(ll i=n-1;i>=0;i--) #define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++) #define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--) // UTIL ------------------------------ #define pb push_back #define paired make_pair #define ALL(a) (a).begin(),(a).end() // ๆณจๆ„๏ผ›https://kimiyuki.net/blog/2015/09/25/competitive-programming-coding/ #define SORT(a) sort((a).begin(),(a).end()) #define RSORT(a) sort((a).rbegin(), (a).rend()) #define REVERSE(x) reverse(ALL(x)) #define MAX(x) *max_element(ALL(x)) #define MIN(x) *min_element(ALL(x)) #define SUM(x) accumulate(ALL(x), (ll)0) #define COUNT(x, y) count(ALL(x), y); template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } // PRINT ------------------------------ #define COUT(a) cout << (a) << endl; #define YES cout << "YES" << endl; #define NO cout << "NO" << endl; #define Yes cout << "Yes" << endl; #define No cout << "No" << endl; // DEBUG ------------------------------ #define LINE cerr << "[debug] line: " << __LINE__ << "\n"; #define debug(...) {debug_all(#__VA_ARGS__, __VA_ARGS__);} template < typename T > void _debug_print(T const& a) {cerr << a << ", ";} template < typename... Args > void debug_all(string s, Args... args) { cerr << "[debug] " << s << " = "; using swallow = std::initializer_list<int>; (void)swallow{ (void( _debug_print(args) ), 0)... }; cerr << endl; } #define debugV(v) cerr << "[debugV] " << #v << ":"; REP(z, v.size()) cerr << " " << v[z]; cerr << "\n"; // CONST ------------------------------ constexpr ll INF = 0x3f3f3f3f3f3f3f3f; constexpr ld PI = 3.141592653589793238462643383279; // or M_PI //###################################################################### //# ใ“ใ“ใ‹ใ‚‰ไธ‹ใซๆ›ธใ„ใฆใ„ใ # //###################################################################### void Main() { ll n; cin >> n; vll a(n), b(n), c(n); REP(i, n) cin >> a[i]; REP(i, n) cin >> b[i]; REP(i, n) cin >> c[i]; vll countb(n+1, 0); vll countc(n+1, 0); // REP(i, n) { // countb[b[i]]++; // } REP(i, n) { countc[c[i]]++; } REP(i, n) { ll t = b[i]; countb[t] += countc[i+1]; } ll ans = 0; REP(i, n) { ll t = a[i]; ans += countb[t]; } COUT(ans); } int main() { cin.tie(0); ios_base::sync_with_stdio(false); cout << fixed << setprecision(15); Main(); } /* 3 2 */
#include <iostream> using namespace std; int main(void) { int N, A, B; cin >> N >> A >> B; N -= A; if (N < 0) { N = 0; } N += B; cout << N << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define endl "\n" #define int long long const int N = 2e5 + 5; int32_t main() { IOS; int a, b, n; cin >> n >> a >> b; cout << n - a + b; return 0; }
#include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <string> #include <queue> #include <stack> #include <set> #include <map> #include <iomanip> #include <utility> #include <tuple> #include <functional> #include <bitset> #include <cassert> #include <complex> #include <stdio.h> #include <time.h> #include <numeric> #include <random> #include <unordered_map> #include <unordered_set> #define all(a) a.begin(),a.end() #define rep(i, n) for (ll i = 0; i < (n); i++) #define pb push_back #define debug(x) cerr << __LINE__ << ' ' << #x << ':' << (x) << '\n' #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; typedef long double ld; typedef pair<ll, ll> P; typedef complex<ld> com; template<class T> using prique = priority_queue<T, vector<T>, greater<T>>; constexpr int inf = 1000000010; constexpr ll INF = 1000000000000000010; constexpr int mod1e9 = 1000000007; constexpr int mod998 = 998244353; constexpr ld eps = 1e-12; constexpr ld pi = 3.141592653589793238; constexpr ll ten(int n) { return n ? 10 * ten(n - 1) : 1; }; int dx[] = { 1,0,-1,0,1,1,-1,-1 }; int dy[] = { 0,1,0,-1,1,-1,1,-1 }; void fail() { cout << "-1\n"; exit(0); } void no() { cout << "No\n"; exit(0); } template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; } template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; } template<class T> istream &operator >> (istream &s, vector<T> &v) { for (auto &e : v) s >> e; return s; } template<class T> ostream &operator << (ostream &s, const vector<T> &v) { for (auto &e : v) s << e << ' '; return s; } struct fastio { fastio() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); cerr << fixed << setprecision(20); } }fastio_; int main() { vector<int> a(4); cin >> a; int s = accumulate(all(a), 0); rep(i, 16) { int k = 0; rep(j, 4) { if (i >> j & 1) k += a[j]; } if (k * 2 == s) { cout << "Yes\n"; return 0; } } cout << "No\n"; }
// Author: param3435 #include <bits/stdc++.h> #pragma GCC optimize ("-O2") using namespace std; #define LL long long #define LD long double #define divisor 1000000007 #define INFP LLONG_MAX #define INFN LLONG_MIN #define pb push_back #define pf push_front #define pob pop_back #define pof pop_front #define mp make_pair #define pLL pair<LL, LL> #define loop(i,a,b) for(LL i = a; i < b; i++) #define loopd(i,a,b) for(LL i = a; i > b; i--) #define numberOfOnes(n) __builtin_popcountll(n) #define parity(n) __builtin_parityll(n) // = 1 when numberOfOnes(n) is odd #define leadingZeros(n) __builtin_clzll(n) #define trailingZeros(n) __builtin_ctzll(n) #define gcd(first, second) __gcd(first, second) #define debug(x) cout << #x << " = " << x << '\n' #define all(x) (x).begin(), (x).end() #define sz(x) (LL)(x).size() #define sum(x) (accumulate((x).begin(), (x).end(), 0LL)) #define minE(x) (*min_element((x).begin(), (x).end())) #define maxE(x) (*max_element((x).begin(), (x).end())) #define minI(x) ( min_element((x).begin(), (x).end()) - (x).begin()) #define maxI(x) ( max_element((x).begin(), (x).end()) - (x).begin()) #define lB(x, y) ( lower_bound((x).begin(), (x).end(), (y)) - (x).begin()) #define uB(x, y) ( upper_bound((x).begin(), (x).end(), (y)) - (x).begin()) #define FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) template<typename T> istream& operator>>(istream& is, vector<T> &v) {for (auto& i : v) is >> i; return is;} template<typename T> ostream& operator<<(ostream& os, vector<T> v) {for (auto& i : v) os << i << ' '; return os;} template<typename T, typename U> istream& operator>>(istream& is, pair<T, U> &p) {is >> p.first >> p.second; return is;} template<typename T, typename U> ostream& operator<<(ostream& os, pair<T, U> p) {os << p.first << ' ' << p.second; return os;} bool sortbysec(const tuple<int, int, int>& a, const tuple<int, int, int>& b) { return (get<1>(a) < get<1>(b)); } void solve() { LL N, Q, num = 1; cin >> N >> Q; vector<LL>A(N); vector<tuple<LL, LL, LL>> K; cin >> A; loop(i, 0, Q) { cin >> num; K.pb({num, i, 0}); } sort(all(A)); sort(all(K)); /*loop(i, 0, Q) { cout << get<0>(K[i]) << ' ' << get<1>(K[i]) << ' ' << get<2>(K[i]) << '\n'; }*/ LL j = 0, c = get<0>(K[0]), r = 0; loop(i, 0, N) { beg: if (c < A[i]) { get<2>(K[j]) = c; j++; if (j == Q) { break; } c = i + get<0>(K[j]); goto beg; } else if (i == N - 1) { for (; j < Q; j++) { get<2>(K[j]) = N + get<0>(K[j]); } break; } else c++; } sort(K.begin(), K.end(), sortbysec); /*loop(i, 0, Q) { cout << get<0>(K[i]) << ' ' << get<1>(K[i]) << ' ' << get<2>(K[i]) << '\n'; }*/ loop(i, 0, Q) { cout << get<2>(K[i]) << '\n'; } return; } int main() { FastIO; LL T = 1; // cin >> T; loop(i, 0, T - 1) { solve(); cout << '\n'; } solve(); return 0; }
#include<ctime> #include<cstdio> #include<cctype> using namespace std; const int N=2e5+10; int read() { char c; int x=0,f=1; while(!isdigit(c=getchar())) f-=2*(c=='-'); while (isdigit(c)){ x=x*10+(c-48)*f; c=getchar(); } return x; } char str[N],stack[N]; int n,f,o,res,top; int main() { #ifndef ONLINE_JUDGE freopen("B.in","r",stdin); freopen("B.out","w",stdout); #endif clock_t t1=clock(); //-------- n=read(); res=n; scanf("%s",str+1); for(int i=1;i<=n;++i){ switch(str[i]){ case 'f': ++top; stack[top]='f'; break; case 'o': ++top; stack[top]='o'; break; case 'x': if(top&&stack[top]=='o'&&stack[top-1]=='f'){ stack[top]=0; --top; stack[top]=0; --top; res-=3; } else{ while(top){ stack[top]=0; --top; } } break; default: while(top){ stack[top]=0; --top; } break; } } printf("%d",res); //-------- clock_t t2=clock(); fprintf(stderr,"time:%0.3lfs",1.0*(t2-t1)/CLOCKS_PER_SEC); return 0; }
// https://atcoder.jp/contests/abc203/tasks/abc203_c #include <bits/stdc++.h> using namespace std; #define ll long long #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) for (int i = (0); i < (n); ++i) #define ALL(obj) (obj).begin(), (obj).end() #define chmin(a, b) a = min(a, b) #define chmax(a, b) a = max(a, b) #define vi vector<int> #define vvi vector<vi> #define P pair<int, int> #define DEBUG(val) cout << #val << " : " << val << endl #define MOD 1000000007 int main() { ll n, k; cin >> n >> k; map<ll, ll> mp; REP(i, n) { ll a, b; cin >> a >> b; mp[a] += b; } ll ans = 0; for (auto [a, b] : mp) { if (a - ans > k) { ans += k; k = 0; break; } else { k -= (a - ans); ans = a; k += b; } } ans += k; cout << ans << endl; }