code_file1
stringlengths
87
4k
code_file2
stringlengths
85
4k
#include <stdio.h> typedef long long ll; int main(void) { ll i, j, n, ans = 0; scanf("%lld", &n); ll ca[n + 1], b[n], c; for(i = 0; i <= n; ++i) ca[i] = 0; for(i = 0; i < n; ++i) scanf("%lld", &c), ca[c]++; for(i = 0; i < n; ++i) scanf("%lld", &b[i]); for(i = 0; i < n; ++i) scanf("%lld", &c), ans += ca[b[--c]]; printf("%lld", ans); return 0; }
#pragma region Template // clang-format off #define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; // #include <atcoder/all> // using namespace atcoder; #define rep(i, m, n) for (int i = m; i < (int)(n); i++) #define repe(i, m, n) for (int i = m; i <= (int)(n); i++) #define all(x) (x).begin(),(x).end() #define yesno {cout<<"Yes"<<endl;}else{cout<<"No"<<endl;} using ll = long long; using vi = vector<int>; using vvi = vector<vector<int>>; using vs = vector<string>; using pii = pair<int,int>; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } #pragma endregion Template // clang-format on int main() { int n; cin >> n; vector<int> a(n), b(n), c(n); rep(i, 0, n) cin >> a[i]; rep(i, 0, n) cin >> b[i]; rep(i, 0, n) cin >> c[i]; vi cnta(n + 1); vi cntb(n + 1); rep(i, 0, n) { cnta[a[i]]++; cntb[b[c[i] - 1]]++; } ll ans = 0; repe(i, 1, n) ans += (ll)cnta[i] * cntb[i]; cout << ans << endl; }
#include <cassert> #include <iostream> #include <algorithm> #include <cstdio> #include <complex> #include <vector> #include <set> #include <map> #include <cmath> #include <queue> #include <string> #include <cstdlib> #include <memory.h> #include <ctime> #include <bitset> #include <fstream> #include <queue> #include <stack> #include <unordered_map> #include <unordered_set> #include <functional> #include <time.h> #include <chrono> #include <random> #include <stdio.h> #include <stddef.h> #include <stdlib.h> #define UI unsigned int #define LL long long #define ll long long #define GT(it,v) for(auto it:v) #define FU(i,a,b) for(int i=(a);i<(b);i++) #define FD(i,a,b) for(int i=(a);i>(b);i--) #define LD long double #define PI 3.1415926535897932384626 #define PII pair<int,int> #define PLL pair<LL,LL> #define VLL vector<long long > #define VVLL vector<vector<long long > > #define VPLL vector<pair<long long, long long>> #define VVPLL vector<vector<pair<long long, long long>>> #define VD vector<double> #define VVD vector<vector<double> > #define VPD vector<pair<double,double> > #define MP make_pair #define PB push_back #define FI first #define SE second #define SORT(v) std::sort(v.begin(),v.end()) #define GSORT(v,T) sort(v.begin(),v.end(),greater<T>) #define UNIQUE(v) decltype(v.begin()) it = unique(v.begin(),v.end()); v.resize(distance(v.begin(),it)) using namespace std; LL inp, Inp; LL i1, i2, i3, i4, i5, i6, i7, i8; LL MOD = 998244353, MOD1 = (LL)1e9 + 7, MOD2 = (LL)1e9 + 9; long long MOD3 = (long long)1e9 + 21 /*33*/; double eps = 1e-9; LL TMP = (chrono::high_resolution_clock::now().time_since_epoch().count() % MOD + MOD) % MOD; auto STTMP = chrono::steady_clock::now();//auto ENTMP = chrono::steady_clock::now(); //ELTIME = double(chrono::duration_cast<chrono::milliseconds>(ENTMP - STTMP).count()); //time_t result = time(NULL); char SS[26]; ctime_s(SS, sizeof SS, &result); //transform(SS, SS + 26, SS, [](char ch) {return ch == ' ' ? '_' : ch; }); printf("%s", SS);; vector<vector<int>> G; vector<int> vis, minD, maxN, neis; int main() { ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.precision(20); srand((unsigned int)TMP); int N, K; cin >> N >> K; G.resize(N, vector<int>()); for (int i = 0; i < N - 1; i++){ cin >> i1 >> i2; i1--, i2--; G.at(i1).push_back(i2); G.at(i2).push_back(i1); } int low = 1, up = N; while (low < up) { int mid = (low + up) / 2; int use = 0; LL vcnt = 0; vis.assign(N, 0); minD.assign(N, 1e9); maxN.assign(N, -1e9); neis.assign(N, 0); for (int i = 0; i < N; i++) { neis.at(i) = G.at(i).size(); } queue<int> leafs; for (int i = 0; i < N; i++) { if (neis.at(i) <= 1) { leafs.push(i); neis.at(i)++; maxN.at(i) = 0; } } while (!leafs.empty()) { int leaf = leafs.front(); leafs.pop(); neis.at(leaf)--; if (!vis.at(leaf) && neis.at(leaf) <= 1) { // leaf vis.at(leaf) = 1; vcnt++; if (maxN.at(leaf) + minD.at(leaf) <= mid) { maxN.at(leaf) = minD.at(leaf) - mid - 1; } else if(maxN.at(leaf) >= mid || vcnt == N){ minD.at(leaf) = 0, maxN.at(leaf) = -mid - 1; use++; } for (auto nei : G.at(leaf)) { minD.at(nei) = min(minD.at(nei), minD.at(leaf) + 1); maxN.at(nei) = max(maxN.at(nei), maxN.at(leaf) + 1); leafs.push(nei); } } } if (use > K) { low = mid + 1; } else { up = mid; } } cout << low << "\n"; return 0; }
/** * author: Dooloper * created: 11.10.2020 23:12:53 **/ #pragma region Macros #pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; using P = pair<int,int>; using ll = long long; #define rep(i,n) for(int i = 0; i < (n); i++) #define repn(i,n) for(int i = 1; i <= (n); i++) #define pb push_back void debug_out() { cout << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); } #ifdef LOCAL #define debug(...) debug_out(__VA_ARGS__) #else #define debug(...) #endif const double PI = acos(-1); const int mod = 1000000007; class mint { long long x; public: mint(long long x=0) : x((x%mod+mod)%mod) {} mint operator-() const { return mint(-x); } mint& operator+=(const mint& a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint& a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint& a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint& a) const { mint res(*this); return res+=a; } mint operator-(const mint& a) const { mint res(*this); return res-=a; } mint operator*(const mint& a) const { mint res(*this); return res*=a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; return a; } // for prime mod mint inv() const { return pow(mod-2); } mint& operator/=(const mint& a) { return (*this) *= a.inv(); } mint operator/(const mint& a) const { mint res(*this); return res/=a; } friend ostream& operator<<(ostream& os, const mint& m){ os << m.x; return os; } }; #pragma endregion int main() { cin.tie(0); ios_base::sync_with_stdio(false); int n,m; cin >> n >> m; vector<int> w(n); vector<int> sums(1 << n), mn(1 << n); rep(i,n) cin >> w[i]; int mx = *max_element(w.begin(),w.end()); for(int s = 0; s < (1 << n); ++s){ int x = 0; for(int i = 0; i < n; ++i) if(s >> i & 1) x+= w[i]; sums[s] = x; } for(int i = 0; i < m; ++i){ int l,v; cin >> l >> v; if(v < mx){ cout << -1 << "\n"; return 0; } for(int s = 0; s < (1 << n); ++s) if(sums[s] > v) mn[s] = max(mn[s],l); } int ans = 1e9; vector<int> perm(n); iota(perm.begin(), perm.end(), 0); do{ vector<int> pos(n); for(int i = 1; i < n; ++i){ int s = 1 << perm[i]; for(int j = i-1; j >= 0; --j){ s |= 1 << perm[j]; pos[i] = max(pos[i], pos[j] + mn[s]); } } ans = min(ans, pos[n-1]); }while(next_permutation(perm.begin(), perm.end())); cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll mod = 1000000007; int main() { ll b, c; cin >> b >> c; ll result = 0; if (c == 1) { if (b == 0) { cout << 1 << endl; } else { cout << 2 << endl; } return 0; } if (b > 0) { result = b + (c - 2) / 2 - max(1ll, b - c / 2) + 1; result += min(-1ll, - b + (c - 1) / 2) + b + (c - 1) / 2 + 1; if (b <= c / 2) { result++; } } else if (b < 0) { result = -b + (c - 1) / 2 - max(1ll, -b - (c - 1) / 2) + 1; result += min(-1ll, b + (c - 2) / 2) - b + c / 2 + 1; if (-b <= (c-1) / 2) { result++; } } else { result = (c - 1) / 2 + c / 2 + 1; } cout << result << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> P; const ll mod=1e9+7; #define rep(i,n) for (int i = 0; i < (n); i++) ll b,c,ans; int main(){ cin >> b >> c; ll k=c/2; if(c==1){ if(b==0)ans=1; else ans=2; } else if(c%2==1) ans=(k*4+1)-max(0LL,min(b+k-1,k-b)-max(-b-k,b-k)+1); else ans=(k*4-1)-max(0LL,min(b+k-1,k-b-1)-max(-b-k+1,b-k)+1); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using lint = long long int; template<int64_t MOD> struct Mint { int64_t v; Mint() { v = 0; } Mint(int64_t x) { v = x % MOD; if(v < 0) v += MOD; } Mint operator-() { return Mint(-v); }; Mint operator+(Mint x) { return Mint(v + x.v); }; Mint operator-(Mint x) { return Mint(v - x.v); }; Mint operator*(Mint x) { return Mint(v * x.v); }; Mint operator/(Mint x) { return Mint(v * pow(x.v, MOD-2).v); }; Mint& operator+=(Mint x) { return *this = (*this + x); }; Mint& operator-=(Mint x) { return *this = (*this - x); }; Mint& operator*=(Mint x) { return *this = (*this * x); }; Mint& operator/=(Mint x) { return *this = (*this / x); }; static Mint pow(Mint base, int64_t exp) { if(exp == 0) return Mint(1); return pow(base*base, exp/2) * (exp&1 ? base : Mint(1)); } friend ostream& operator<<(ostream& os, Mint x) { return os << x.v; } }; using mint = Mint<1000000007>; template<typename T> vector<T> tensor(int n, T v){ return vector<T>(n, v); } template<typename... Ts> auto tensor(int n, Ts... ts) { return vector<decltype(tensor(ts...))>(n, tensor(ts...)); } int main() { lint h, w; cin >> h >> w; auto S = tensor(h+2, w+2, '#'); for(lint i=1; i<=h; i++) for(lint j=1; j<=w; j++) { cin >> S[i][j]; } auto dp = tensor(h+2, w+2, 4, 1); for(lint i=1; i<=h; i++) for(lint j=1; j<=w; j++) { if(S[i][j] == '.') { dp[i][j+1][0] = dp[i][j][0] + 1; dp[i+1][j][1] = dp[i][j][1] + 1; } else { dp[i][j][0] = dp[i][j][1] = 0; } } for(lint i=h; i>=1; i--) for(lint j=w; j>=1; j--) { if(S[i][j] == '.') { dp[i][j-1][2] = dp[i][j][2] + 1; dp[i-1][j][3] = dp[i][j][3] + 1; } else { dp[i][j][2] = dp[i][j][3] = 0; } } lint dot = 0; for(lint i=1; i<=h; i++) for(lint j=1; j<=w; j++) { dot += S[i][j] == '.'; } mint ans = 0; for(lint i=1; i<=h; i++) for(lint j=1; j<=w; j++) { lint count = 0; for(lint k=0; k<4; k++) count += dp[i][j][k]; count = max(count-3, 0LL); ans += mint::pow(2, dot) - mint::pow(2, dot-count); } cout << ans << endl; }
#define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(v) v.begin(), v.end() typedef long long ll; #include <bits/stdc++.h> using namespace std; const int MOD=1e9+7; int D[2010][2010]; int E[2010][2010]; ll modpow(ll x,ll n){ ll ans=1; while(n){ if(n&1) ans=ans*x %MOD; x=x*x %MOD; n/=2; } return ans; } int a; int f(int i,int j){ return ((modpow(2,D[i][j])-1+MOD)%MOD)*modpow(2,a-D[i][j])%MOD; } int main(){ int h,w; cin>>h>>w; vector<string> A(h); rep(i,h) cin>>A[i]; int cnt=0; rep(i,h){ rep(j,w){ if(A[i][j]=='#'){ D[i][j]=0; cnt++; } else{ if(j==0) D[i][j]=1; else D[i][j]=D[i][j-1]+1; } } } rep(i,h){ for(int j=max(w-2,0);j>=0;j--){ if(D[i][j]==0) continue; if(D[i][j]<D[i][j+1]) D[i][j]=D[i][j+1]; } } rep(j,w){ rep(i,h){ if(A[i][j]=='#') E[i][j]=0; else{ if(i==0) E[i][j]=1; else E[i][j]=E[i-1][j]+1; } } } rep(j,w){ for(int i=max(h-2,0);i>=0;i--){ if(E[i][j]==0) continue; if(E[i][j]<E[i+1][j]) E[i][j]=E[i+1][j]; } } rep(i,h){ rep(j,w){ D[i][j]=max(D[i][j]+E[i][j]-1,0); } } a=h*w-cnt; ll ans=0; rep(i,h){ rep(j,w){ ans=(ans+f(i,j))%MOD; } } cout<<ans<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int mod=998244353; int n,m,ans; int Power(int x,int y){ int ret=1; while(y) { if(y&1)ret=1ll*ret*x%mod; x=1ll*x*x%mod,y>>=1; } return ret; } int main(){ cin>>n>>m; int w1=Power(m*m,mod-2); int w2=Power(m,mod-2); for(int i=2,l=Power(m,n);i<=n;i++){ for(int j=1;j<=m;j++){ int p=1ll*w1*Power(1ll*(m-j)*w2%mod,i-2)%mod*(n-i+1)%mod; ans=(ans+1ll*p*l)%mod; } } cout<<(1ll*n*Power(m,n)%mod-ans+mod)%mod; return 0; }
#include<bits/stdc++.h> using namespace std; #define N 200005 #define mod 998244353 int n,k,ans,a[N],sum[N][305],fac[N],inv[N]; int c(int n,int m){ return 1LL*fac[n]*inv[m]%mod*inv[n-m]%mod; } int main(){ scanf("%d%d",&n,&k); for(int i=1;i<=n;i++)scanf("%d",&a[i]); for(int i=1;i<=n;i++){ int ss=1; for(int j=0;j<=k;j++){ sum[i][j]=(sum[i-1][j]+ss)%mod; ss=1LL*ss*a[i]%mod; } } fac[0]=inv[0]=inv[1]=1; for(int i=1;i<=k;i++)fac[i]=1LL*fac[i-1]*i%mod; for(int i=2;i<=k;i++)inv[i]=1LL*(mod-mod/i)*inv[mod%i]%mod; for(int i=2;i<=k;i++)inv[i]=1LL*inv[i-1]*inv[i]%mod; for(int i=1;i<=k;i++){ ans=0; for(int j=0;j<=i;j++){ ans=(ans+(1LL*sum[n][j]*sum[n][i-j]-sum[n][i]+mod)%mod*(mod+1)/2%mod*c(i,j))%mod; } printf("%d\n",ans); } }
#include<bits/stdc++.h> using namespace std; const long long MOD = 1e9+7; const long long N = 1e5+10; typedef long long ll; typedef long double ld; void test_case() { ld r, x, y; cin >> r >> x >> y; ld dis = sqrt(x * x + y * y); ld res = dis/r; ll ans = ceil(res); if(ans == 1 && ceil(res) != floor(res)) ans++; cout << ans << '\n'; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int tc = 1; // cin >> tc; while(tc--) test_case(); return 0; }
#include <vector> #include <cstdlib> #include <math.h> #include <algorithm> #include <tuple> #include <set> #include <map> #include <iostream> #include <iomanip> #include <limits> using namespace std; # define rep(i, n) for (long long i = 0; i < (long long)(n); i++) int main() { long long r, x, y; cin >> r >> x >> y; long long answer = 0; long long d2 = (x * x) + (y * y); double d = sqrt(d2); if(fmod(d, r) == 0){ answer = d / r; }else if(d < r * 2){ answer = 2; }else{ answer = ceil(d / r); } cout << answer << endl; return 0; }
#include <bits/stdc++.h> using namespace std; /* ループ処理 0からnまで*/ #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { double A, B; cin >> A >> B; cout << A / 100.0 * B << endl; return 0; }
#include<bits/stdc++.h> using namespace std; int main() { int A, B; cin >> A >> B; cout << A * B / 100.0 << endl; }
//Let's join Kaede Takagaki Fan Club !! #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; //#define int long long typedef long long ll; typedef pair<int,int> P; typedef pair<int,P> P1; typedef pair<P,P> P2; #define pu push #define pb push_back #define eb emplace_back #define mp make_pair #define eps 1e-7 #define INF 1000000000 #define a first #define b second #define fi first #define sc second #define rng(i,a,b) for(int i=int(a);i<int(b);i++) #define rep(i,x) for(int i=0;i<x;i++) #define repn(i,x) for(int i=1;i<=x;i++) #define SORT(x) sort(x.begin(),x.end()) #define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end()) #define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) #define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) #define all(x) x.begin(),x.end() #define si(x) int(x.size()) #ifdef LOCAL #define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl #else #define dmp(x) void(0) #endif template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b;return true;}else return false;} template<class t,class u> bool chmin(t&a,u b){if(b<a){a=b;return true;}else return false;} template<class t> using vc=vector<t>; template<class t,class u> ostream& operator<<(ostream& os,const pair<t,u>& p){ return os<<"{"<<p.fi<<","<<p.sc<<"}"; } template<class t> ostream& operator<<(ostream& os,const vc<t>& v){ os<<"{"; for(auto e:v)os<<e<<","; return os<<"}"; } template<class T> void g(T &a){ cin >> a; } template<class T> void o(const T &a,bool space=false){ cout << a << (space?' ':'\n'); } //ios::sync_with_stdio(false); const ll mod = 1000000007;//998244353 mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count()); template<class T> void add(T&a,T b){ a+=b; if(a >= mod) a-=mod; } ll modpow(ll x,ll n){ ll res=1; while(n>0){ if(n&1) res=res*x%mod; x=x*x%mod; n>>=1; } return res; } int pr[15]={2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47}; int v[55]; void solve(){ int n; cin >> n; rep(i, n){ int p; cin >> p; int mask = 0; rep(j,15){ if(p%pr[j] == 0) mask|=(1<<j); } v[i] = mask; } ll ans = 1e18, tmp; rep(mask,(1<<15)){ rep(i,n) if( (v[i] & mask) == 0 ) goto fail; tmp = 1; rep(i,15)if(((mask>>i)&1)) tmp=tmp*pr[i]; chmin(ans,tmp); fail:; } o(ans); } signed main(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20); int t; t = 1; //cin >> t; while(t--) solve(); }
#include<bits/stdc++.h> using namespace std; void solve() { int a,b; cin >> a >> b; int mx=0; for (int k=1; k<=b; k++) { int z = (a+k-1)/k; int first = z*k; int second = (z+1)*k; if (first>=a && second<=b) mx = k; } cout << mx; } int main() { int t=1; //cin >> t; while (t--) solve(); }
#include <iostream> using namespace std; int main(){ int x, y; cin >> x >> y; switch(x+y){ case 0: cout << 0 << endl; break; case 1: cout << 2 << endl; break; case 2: cout << 1 << endl; break; case 3: cout << 0 << endl; break; case 4: cout << 2 << endl; break; } return 0; }
#include <bits/stdc++.h> #include <string> typedef long long int ll; typedef long double ld; using namespace std; ll mod = 1e9 + 7; int solve() { return 0; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll x, y; cin >> x >> y; if (x == y) cout << x << endl; else if ((x == 0 && y == 1) || (x == 1 && y == 0)) cout << 2 << endl; else if ((x == 1 && y == 2) || (x == 2 && y == 1)) cout << 0 << endl; else if ((x == 0 && y == 2) || (x == 2 && y == 0)) cout << 1 << endl; return 0; }
#include<bits/stdc++.h> using namespace std; int a,b,c,l,r; int main(){ cin>>a>>b>>c; c*=1000; l=c/b; if(c%b!=0)l++; r=c/a; if(r<l)puts("UNSATISFIABLE"); else cout<<l<<" "<<r; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> pll; #define MottoHayaku ios::sync_with_stdio(0);cin.tie(0); #define rep(i,n) for(ll i=0;i<n;i++) #define rep1(i,n) for(ll i=1;i<=n;i++) #define F first #define S second #define pb push_back const ll INF=2e18; signed main() { MottoHayaku ll a,b,c; cin>>a>>b>>c; c*=1000; ll mn=INF,mx=-1; rep1(i,1000000) { double tmp=c; double k=c/(double)i; if(k<=b&&k>=a) mn=min(mn,i),mx=max(mx,i); } if(mn==INF) cout<<"UNSATISFIABLE\n"; else cout<<mn<<" "<<mx<<"\n"; }
#include <cmath> #include <iostream> #include <string> #include <algorithm> #include <vector> #include <queue> #include <vector> #include <map> #include<cstdio> #include<functional> #include <bitset> #include <iomanip> #include <cctype> #define rep(i, n) for (int i = 0; i < (n); i++) #define repi(i,a,b) for(int i=int(a);i<int(b);++i) #define repr(i, n) for(int i = n; i >= 0; i--) #define ll long long 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 vv = vector<vector<ll>>; using vec = vector<ll>; using P = pair<ll, ll>; int main() { ll n; cin >> n; map<ll, ll> mp; vec al(n); rep(i, n) { ll a; cin >> a; al[i] = a; } repi(i, 2, 1001) { rep(j, n) { if (al[j] >= i && al[j]%i == 0) { mp[i]++; } } } ll ans = 0; ll max = 0; for (auto item : mp) { if (item.second > max) { max = item.second; ans = item.first; } } cout << ans << endl; system("Pause"); }
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> #define pi 3.141592653589793238 #define int long long #define LL long long #define ld long double using namespace __gnu_pbds; using namespace std; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; mt19937 rnd(time(0)); long long powm(long long a, long long b,long long mod) { long long res = 1; while (b > 0) { if (b & 1) res = res * a %mod; a = a * a %mod; b >>= 1; } return res; } int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); #ifndef ONLINE_JUDGE if(fopen("INPUT.txt","r")) { freopen("INPUT.txt","r",stdin); freopen("OUTPUT.txt","w",stdout); } #endif ld a,b; cin>>a>>b; b=a-b; ld ans=(b/a)*100; cout<<fixed<<setprecision(6)<<ans; }
#include<bits/stdc++.h> using namespace std; //Replace each 0 with a 0, //each 1 with a 1, each 6 with a 9, each 8 with an 8, and each 9 with a 6. int main() { string s;cin>>s; for(int i=s.length()-1;i>=0;i--) {if(s[i]=='6') s[i]='9'; else if(s[i]=='9') s[i]='6'; cout<<s[i]; } // cout<<s; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) using ll = long long; const ll INF = 1LL << 30; using pll = pair<ll, ll>; using Graph = vector<vector<int>>; int main() { ll N; cin >> N; ll cut = 0, ans = 0; while(cut < N) { cut += ans+1; ans++; } cout << ans << endl; }
#include <iostream> using namespace std; int main() { char c[3]; for(int i=0;i<3;i++) { cin>>c[i]; } for(int i=0;i<2;i++) { if(c[i]!=c[i+1]) { cout<<"Lost"; return 0; } } cout<<"Won"; return 0; }
#include <bits/stdc++.h> using namespace std; int a[2]; int main() { cin >> a[0] >> a[1]; if (a[0] == a[1]) { cout << a[0] << endl; } else { for (int i = 0; i < 3; ++i) { bool flag = 1; for (int j = 0; j < 2; ++j) { if (a[j] == i) { flag = 0; break; } } if (flag) { cout << i << endl; break; } } } return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long int ll; int main(){ int x; cin >> x; cout << max(0, x) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int x; cin >> x; if (x < 0) { cout << 0 << endl; } else { cout << x << endl; } }
#include<bits/stdc++.h> using namespace std; #define reg register typedef long long ll; #define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++) static char buf[1<<21],*p1=buf,*p2=buf; #define flush() (fwrite(wbuf,1,wp1,stdout),wp1=0) #define putchar(c) (wp1==wp2&&(flush(),0),wbuf[wp1++]=c) static char wbuf[1<<21];int wp1;const int wp2=1<<21; inline int read(void){ reg char ch=getchar(); reg int res=0; while(!isdigit(ch))ch=getchar(); while(isdigit(ch))res=10*res+(ch^'0'),ch=getchar(); return res; } inline void write(reg int x){ static char buf[32]; reg int p=-1; if(!x) putchar('0'); else while(x) buf[++p]=(x%10)^'0',x/=10; while(~p) putchar(buf[p--]); return; } const int MAXN=500; int n; int p[MAXN]; int main(void){ reg int t=read(); while(t--){ n=read(); for(reg int i=0;i<n;++i) p[i]=read()-1; vector<int> ans; for(int i=0;i<n;++i){ reg int j=find(p,p+n,i)-p; if(i!=j){ if(!((j^ans.size())&1)){ if(j>=i+2){ ans.push_back(j-2); swap(p[j-2],p[j-1]); } else{ ans.push_back(i-1),ans.push_back(i),ans.push_back(i-1),ans.push_back(i),ans.push_back(i-1); swap(p[i],p[j]); continue; } } for(int k=j-1;k>=i;--k){ ans.push_back(k); swap(p[k],p[k+1]); } } } write(ans.size()),putchar('\n'); if(ans.size()) for(reg int i=0,siz=ans.size();i<siz;++i) write(ans[i]+1),putchar(i==siz-1?'\n':' '); else putchar('\n'); } flush(); return 0; }
#include <algorithm> #include <climits> #include <cmath> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <set> #include <stack> #include <string> #include <vector> #define REP(i, n) for(int i = 0; i < n; ++i) using namespace std; using LLONG = long long; const LLONG MOD = 1000000007; struct Vector { LLONG x, y; Vector() { x = y = 0; } Vector(LLONG x, LLONG y) : x(x), y(y) {} const Vector operator+(const Vector& rhs) const { return { x + rhs.x, y + rhs.y }; } }; struct Matrix { LLONG a, b, c, d; Matrix() { a = b = c = d = 0; } Matrix(LLONG a, LLONG b, LLONG c, LLONG d) : a(a), b(b), c(c), d(d) {} const Matrix operator*(const Matrix& rhs) const { return { a * rhs.a + b * rhs.c, a * rhs.b + b * rhs.d, c * rhs.a + d * rhs.c, c * rhs.b + d * rhs.d }; } const Vector operator*(const Vector& rhs) const { return { a * rhs.x + b * rhs.y, c * rhs.x + d * rhs.y }; } }; int main() { int N; cin >> N; vector<Vector> xs(N); REP(i, N) { LLONG x, y; cin >> x >> y; xs[i] = Vector(x, y); } int M; cin >> M; vector<Matrix> ms(M + 1); ms[0] = Matrix(1, 0, 0, 1); vector<Vector> vs(M + 1); REP(i, M) { int op; cin >> op; if (op == 1) { ms[i + 1] = Matrix(0, 1, -1, 0) * ms[i]; vs[i + 1] = Matrix(0, 1, -1, 0) * vs[i]; } else if (op == 2) { ms[i + 1] = Matrix(0, -1, 1, 0) * ms[i]; vs[i + 1] = Matrix(0, -1, 1, 0) * vs[i]; } else if (op == 3) { LLONG p; cin >> p; ms[i + 1] = Matrix(-1, 0, 0, 1) * ms[i]; vs[i + 1] = Matrix(-1, 0, 0, 1) * vs[i] + Vector(2 * p, 0); } else if(op == 4) { LLONG p; cin >> p; ms[i + 1] = Matrix(1, 0, 0, -1) * ms[i]; vs[i + 1] = Matrix(1, 0, 0, -1) * vs[i] + Vector(0, 2 * p); } } int Q; cin >> Q; REP(i, Q) { int ai, bi; cin >> ai >> bi; --bi; const auto v = ms[ai] * xs[bi] + vs[ai]; cout << v.x << ' ' << v.y << endl; } }
#include <bits/stdc++.h> #define rep(i, n) for (long long i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; using V = vector<int>; int main() { int a, b; string ans; cin >> a >> b; ans = b % a == 0 ? "Yes" : "No"; cout << ans << endl; return 0; }
#include <iostream> #include <algorithm> #include <set> using namespace std; typedef long long ll; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll b, c; cin >> b >> c; if (b == 0) { ll l1 = c >> 1; ll l2 = (c - 1) >> 1; cout << l2 + l1 + 1 << '\n'; } else { if (c == 1) { cout << 2 << '\n'; } else if (c == 2) { set<ll> s = { b, b - 1, -b }; cout << s.size() << '\n'; } else { pair<ll, ll> p1(b - (c >> 1), b + ((c - 2) >> 1)); pair<ll, ll> p2(-b -((c - 1) >> 1), -b + ((c - 1) >> 1)); if (p1.first > p2.first) swap(p1, p2); ll l1 = p1.second - p1.first + 1; ll l2 = p2.second - p2.first + 1; ll l3 = max(0ll, p1.second - p2.first + 1); cout << l1 + l2 - l3 << '\n'; } } cin.ignore(2); return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define REP(i, n) FOR(i, 0, n) #define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i) #define ALL(obj) (obj).begin(), (obj).end() #define ALLR(obj) (obj).rbegin(), (obj).rend() #define CEIL(a, b) ((a - 1) / b + 1) template <typename T, typename F> T binarySearch(T ok, T ng, F isOK, T bound = 1) { while (abs(ng - ok) > bound) { T m = (ng + ok) / 2; if (isOK(m)) ok = m; else ng = m; } return ok; } void solve() { int N; cin >> N; // 等差数列の和 S = n(a + l) / 2 auto fn = [&](int m) { return (m * (m + 1) / 2 <= N + 1); }; cout << N - binarySearch(0LL, (int)2e9, fn) + 1 << endl; } signed main() { cin.tie(nullptr)->sync_with_stdio(false); solve(); }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)(n);i++) using namespace std; using ll = long long; const int INF = 1001001001; const ll INF_LL = 1001001001001001001LL; const int MA = 200; int main(void){ int n; cin >> n; vector<ll> a(2*MA+1,0); rep(i,n){ int tmp; cin >> tmp; a[MA+tmp]++; } ll ans = 0; for(int i = 0;i < 2*MA+1;i++){ for(int j = 0;j < 2*MA+1;j++){ ans += a[i]*a[j]*(i-j)*(i-j); } } ans /= 2; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; void fastStd() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); } const int MOD = 1e9+7; int n; vector<int> arr; vector<long long> minim; vector<pair<long long, long long>> dp; vector<pair<long long, long long>> dp2; long long generate(bool plus, int index){ if(index == n-1){ if(plus){ return dp[index].first; } else { return dp[index].second; } } if(plus){ if(dp[index+1].first != -1 && dp[index+1].second != -1){ dp[index].first = (dp[index+1].first + dp[index+1].second) % MOD; } else if(dp[index+1].first != -1) { dp[index].first = (dp[index+1].first + generate(false, index+1)) % MOD; } else if(dp[index+1].second != -1){ dp[index].first = (generate(true, index+1) + dp[index+1].second) % MOD; } else { dp[index].first = (generate(true, index+1) + generate(false, index+1)) % MOD; } return dp[index].first % MOD; } else { if(dp[index+1].first != -1){ dp[index].second = dp[index+1].first; } else { dp[index].second = generate(true, index+1); } return dp[index].second % MOD; } } long long generate2(bool plus, int index){ if(index == 1){ if(plus){ return dp2[index].first; } else { return dp2[index].second; } } if(plus){ if(dp2[index-1].first != -1 && dp2[index-1].second != -1){ dp2[index].first = (dp2[index-1].first + dp2[index-1].second) % MOD; } else if(dp2[index-1].first != -1) { dp2[index].first = (dp2[index-1].first + generate2(false, index-1)) % MOD; } else if(dp2[index-1].second != -1){ dp2[index].first = (generate2(true, index-1) + dp2[index-1].second) % MOD; } else { dp2[index].first = (generate2(true, index-1) + generate2(false, index-1)) % MOD; } return dp2[index].first % MOD; } else { if(dp2[index-1].first != -1){ dp2[index].second = dp2[index-1].first; } else { dp2[index].second = generate2(true, index-1); } return dp2[index].second % MOD; } } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif scanf("%d", &n); arr.resize(n); long long sum = 0; for(int &x : arr){ scanf("%d", &x); sum += x % MOD; sum %= MOD; } if(n == 1){ printf("%d\n", arr[0]); return 0; } minim.resize(n); dp.resize(n, {-1, -1}); dp[n-1] = {1,1}; dp2.resize(n, {-1, -1}); dp2[1] = {1, 1}; long long x = generate(true, 1); x = generate(false, 1); x = generate2(true, n-1); x = generate2(false, n-1); long long ans = (sum * ((dp[1].first + dp[1].second) % MOD)) % MOD; // printf("%lld\n", ans); for(int i = 1; i < n; i++){ minim[i] = ((dp[i].second % MOD) * (dp2[i].second % MOD)) % MOD; ans -= ((arr[i] * minim[i] % MOD) * 2) % MOD; ans = (ans + MOD) % MOD; // printf("%lld %lld %lld %lld\n", dp[i].first, dp[i].second, minim[i], ans); } printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; using ll=long long; #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 template<class T,class U> inline bool chmax(T &a,U b){ if(a<b){ a=b; return true; } return false; } template<class T,class U> inline bool chmin(T &a,U b){ if(a>b){ a=b; return true; } return false; } constexpr int INF=1000000000; constexpr ll llINF=3000000000000000000; constexpr int mod=998244353; 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); } /* vector<vector<ll>>C,sC; void init_comb(int n,int m){ C.resize(n+1,vector<ll>(m+1,0)); sC.resize(n+1,vector<ll>(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; } } }*/ ll gcd(ll a,ll b){ while(a%b){ a%=b; swap(a,b); } return b; } ll lcm(ll a,ll b){ return a/gcd(a,b)*b; } bool isprime(int a){ if(a==1)return false; for(int i=2;i*i<=a;i++){ if(a%i==0)return false; } return true; } vector<int>primes; void init_prime(int n){ primes.push_back(2); for(int i=3;i<=n;i+=2){ bool f=true; for(int j:primes){ if(j*j>i)break; if(i%j==0){ f=false; break; } } if(f)primes.push_back(i); } } ll modpow(ll a,ll b){ ll res=1; while(b){ if(b&1){ res*=a; res%=mod; } a*=a; a%=mod; b>>=1; } return res; } vector<ll>inv,fact,factinv; void init_fact(int n){ inv.resize(n+1); fact.resize(n+1); factinv.resize(n+1); inv[0]=0; inv[1]=1; fact[0]=1; factinv[0]=1; for(ll i=1;i<=n;i++){ if(i>=2)inv[i]=mod-((mod/i)*inv[mod%i]%mod); fact[i]=(fact[i-1]*i)%mod; factinv[i]=factinv[i-1]*inv[i]%mod; } } ll _inv(ll a,ll m=mod){ //gcd(a,m) must be 1 ll b=m,u=1,v=0; while(b){ ll t=a/b; a-=t*b;swap(a,b); u-=t*v;swap(u,v); } u%=m; if(u<0)u+=m; return u; } ll comb(int a,int b){ if(a<b)return 0; if(a<0)return 0; return fact[a]*factinv[a-b]%mod*factinv[b]%mod; } ll multicomb(int a,int b){ return comb(a+b-1,b); } void solve(){ int n,a[20]; cin>>n; rep(i,n)cin>>a[i]; int ans=(1<<30); rep(s,1<<(n-1)){ int X=0,O=a[0]; rep(i,n-1){ if((s>>i)&1){ O|=a[i+1]; } else{ X^=O; O=a[i+1]; } } X^=O; chmin(ans,X); } cout<<ans<<endl; } int main(){ cin.tie(0);ios::sync_with_stdio(false); //int t;cin>>t;while(t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<(n);i++) #define repa(i,a,n) for(int i=(a);i<(n);i++) #define rrep(i,n) for(int i=n;i>=0;i--) #define rrepa(i,a,n) for(int i=n;i>=(a);i--) #define all(a) (a).begin(),(a).end() #define MOD 1000000007 #define cmax(a,b) a=max(a,b) #define cmin(a,b) a=min(a,b) #define vc vector typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<double> vd; typedef vector<vd> vvd; typedef pair<int,int> pi; typedef pair<ll,ll> pl; int main(){ int h,w; cin>>h>>w; int sum=0,tmp,mi=100; rep(i,h)rep(j,w){ cin>>tmp; sum+=tmp; cmin(mi,tmp); } cout<<sum-(mi*h*w); return 0; }
#include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <bitset> #include <complex> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> #include <cassert> #include <functional> using ll = long long; using namespace std; template<typename A, typename B> bool chmin(A &a, const B b) { if (a <= b) return false; a = b; return true; } template<typename A, typename B> bool chmax(A &a, const B b) { if (a >= b) return false; a = b; return true; } #ifndef LOCAL #define debug(...) ; #else #define debug(...) cerr << __LINE__ << " : " << #__VA_ARGS__ << " = " << _tostr(__VA_ARGS__) << endl; template<typename T> ostream &operator<<(ostream &out, const vector<T> &v); template<typename T1, typename T2> ostream &operator<<(ostream &out, const pair<T1, T2> &p) { out << "{" << p.first << ", " << p.second << "}"; return out; } template<typename T> ostream &operator<<(ostream &out, const vector<T> &v) { out << '{'; for (const T &item : v) out << item << ", "; out << "\b\b}"; return out; } void _tostr_rec(ostringstream &oss) { oss << "\b\b \b"; } template<typename Head, typename... Tail> void _tostr_rec(ostringstream &oss, Head &&head, Tail &&...tail) { oss << head << ", "; _tostr_rec(oss, forward<Tail>(tail)...); } template<typename... T> string _tostr(T &&...args) { ostringstream oss; int size = sizeof...(args); if (size > 1) oss << "{"; _tostr_rec(oss, forward<T>(args)...); if (size > 1) oss << "}"; return oss.str(); } #endif constexpr int mod = 1'000'000'007; //1e9+7(prime number) constexpr int INF = 1'000'000'000; //1e9 constexpr ll LLINF = 2'000'000'000'000'000'000LL; //2e18 constexpr int SIZE = 200010; ll power(ll k, ll n, int M) { ll res = 1; for (; n; n /= 2) { if (n & 1) res = res * k % M; k = k * k % M; } return res; } int main() { int N, P; cin >> N >> P; ll ans = (ll)(P - 1) * power(P - 2, N - 1, mod); cout << ans % mod << endl; return 0; }
#include <iostream> #include <algorithm> #include <vector> #include <string> #include <set> #include <cassert> using namespace std; vector<int> opos(const string& s) { int n = s.length(); vector<int> ps; for (int i = 0; i < n; ++i) { if (s[i] == '1') ps.push_back(i); } return ps; } void solve() { int n; string s, t; cin >> n >> s >> t; if (count(s.begin(), s.end(), '0') != count(t.begin(), t.end(), '0')) { cout << "-1\n"; return; } int ans = 0; for (int q = 0; q < 2; ++q) { auto sps = opos(s), tps = opos(t); int m = sps.size(); int p = 0; for (int i = 0; i < m; ++i) { auto& si = sps[i]; auto ti = tps[i]; si = max(si, p); if (si < ti) { ans += ti - si; si = ti; } p = si + 1; } reverse(s.begin(), s.end()); reverse(t.begin(), t.end()); } cout << ans << "\n"; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; #define al(a) a.begin(), a.end() #define ral(a) a.rbegin(), a.rend() #define sz(a) (int)a.size() // s= 000101 // t= 110000 // ans=4 // s= 0101011 // t= 1111000 // ans=3 // s= 1111000 // t= 0101011 // ans=3 // s= 1101100 // t= 0101011 // ans=3 // s= 11010100 // t= 01010101 // ans=4 // s= 11001001 // t= 01010101 // ans=3 // 0の位置が一致していないときは、1個ずつ合わせていくしか無い int main() { int n; cin >> n; string s, t; cin >> s >> t; vector<vector<int>> z(2); for (int i = 0; i < n; ++i) { if (s[i] == '0') z[0].push_back(i); if (t[i] == '0') z[1].push_back(i); } if (sz(z[0]) != sz(z[1])) { cout << -1 << endl; return 0; } int ans = 0; for (int i = 0; i < sz(z[0]); ++i) { if (z[0][i] != z[1][i]) ++ans; } cout << ans << endl; } // 0を何個中継するか? // int main() { // int n; // cin >> n; // string s, t; // cin >> s >> t; // vector<int> cnt(2); // for (int i = 0; i < n; ++i) { // if (s[i] == '1') ++cnt[0]; // if (t[i] == '1') ++cnt[1]; // } // if (cnt[0] != cnt[1]) { // cout << -1 << endl; // return 0; // } // int ans = 0; // bool c = false; // vector<int> cnt2(2); // for (int i = 0; i < n; ++i) { // if (!c && s[i] != t[i]) { // c = true; // if (s[i] == '1') ++ans; // } // if (c) { // if (s[i] == '1') cnt2[0]++; // if (t[i] == '1') cnt2[1]++; // } // if (c && s[i] == '0' && cnt2[0] != cnt2[1]) { ++ans; } // } // cout << ans << endl; // return 0; // }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i, n) for(ll i = 0; i < ll(n); i++) #define REPD(i, n) for(ll i = n-1; i >= 0; i--) #define FOR(i, a, b) for(ll i = a; i < ll(b); i++) #define FORD(i, a, b) for(ll i = a; i > ll(b); i--) #define START ios::sync_with_stdio(false);cin.tie(0); int main() { START int N; cin >> N; if (N % 2 == 0) cout << "White" << endl; else cout << "Black" << endl; }
#include <bits/stdc++.h> using namespace std; int main(){ int x; cin>>x; if(x>=0){ cout<<x; } else{ cout<<0; } }
#include <bits/stdc++.h> using namespace std; /*#include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> */ typedef long long ll; typedef long double ld; typedef unsigned long long ull; #define rep(i,a,b) for(ll i=a;i<=b;++i) #define rrep(i,a,b) for(ll i=a;i>=b;--i) #define FOR(i,n) for(ll i=0;i<n;i++) #define pb push_back #define mp make_pair #define PI 3.14159265358979323846 #define fi first #define se second #define all(x) x.begin(),x.end() #define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); const ll INF = 1e18+7; const ll mod = 998244353; const ll MAXN = 2e6+100; ll poww(ll a, ll b) { if(b<0) return 0LL; ll ans = 1; while (b) { if (b & 1)ans = ans * a; a = a * a; b >>= 1; } return ans; } ll binpow(ll a, ll b) { if (b < 0) return 0LL; if (a <= 0)return 0LL; a %= mod; ll ans = 1LL; while (b) { if (b & 1)ans = ans * a % mod; a = a * a % mod; b >>= 1; } return ans; } ll modinv(ll n) { return binpow(n, mod - 2); } vector<pair<ll,ll>> func(vector<ll> a, vector<ll> b) { vector<ll> x((ll)(b.size()),INF); ll i=0,j=0; while(i<(ll)a.size() && j<(ll)b.size()) { x[j] = min(x[j],abs(a[i]-b[j])); if(a[i]<=b[j]) i++; else j++; } vector<pair<ll,ll>> temp; FOR(i,(ll)(x.size())) { temp.pb(mp(x[i],i)); } sort(all(temp)); return temp; } void solve() { ll n; cin>>n; vector<ll> r,g,b; FOR(i,2*n) { ll a; char c; cin>>a>>c; if(c=='R') r.pb(a); if(c=='G') g.pb(a); if(c=='B') b.pb(a); } ll sr = r.size(), sb = b.size(), sg = g.size(); sort(all(r)); sort(all(g)); sort(all(b)); if(sr%2==0 && sb%2==0 && sg%2==0) { cout<<0; } else { if(sr%2 && sb%2) { vector<pair<ll,ll>> t = func(r,b); ll mn = t[0].fi; if(sg > 0) { vector<pair<ll,ll>> t1,t2; t1 = func(r,g); t2 = func(b,g); if(t1[0].se!=t2[0].se) { mn = min(mn,t1[0].fi+t2[0].fi); } else { mn = min(mn,min(t1[1].fi + t2[0].fi, t1[0].fi + t2[1].fi)); } } cout<<mn; } else if(sr%2 && sg%2) { vector<pair<ll,ll>> t = func(r,g); ll mn = t[0].fi; if(sb > 0) { vector<pair<ll,ll>> t1,t2; t1 = func(r,b); t2 = func(g,b); if(t1[0].se!=t2[0].se) { mn = min(mn,t1[0].fi+t2[0].fi); } else { mn = min(mn,min(t1[1].fi + t2[0].fi, t1[0].fi + t2[1].fi)); } } cout<<mn; } else { vector<pair<ll,ll>> t = func(g,b); ll mn = t[0].fi; if(sr > 0) { vector<pair<ll,ll>> t1,t2; t1 = func(g,r); t2 = func(b,r); if(t1[0].se!=t2[0].se) { mn = min(mn,t1[0].fi+t2[0].fi); } else { mn = min(mn,min(t1[1].fi + t2[0].fi, t1[0].fi + t2[1].fi)); } } cout<<mn; } } } int main() { IOS; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif //ll no_of_test_cases; cin>>no_of_test_cases; ll no_of_test_cases = 1; //cout<<fixed<<setprecision(10); for(ll i=1; i<=no_of_test_cases; i++) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; // clang-format off #define rep(i, n) for ( int i = 0; i < (int)(n); i += 1) #define rrep(i, n) for ( int i = (n) - 1; i >= 0; i -= 1) #define range(i, l, r) for ( int i = (int)(l); i < (int)(r); (i) += 1 ) #define rrange(i, l, r) for ( int i = (int)(r)-1; i >= (int)(l); (i) -= 1 ) #define debug(x) cerr << #x << ": " << (x) << endl; template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << p.first << ' ' << p.second; return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &v) { for ( pair<T1, T2> x : v ) { os << x << "\n"; } return os; } template <typename T> ostream &operator<<(ostream &os, queue<T> v) { if(!v.empty()) { os << v.front(); v.pop(); } while (!v.empty()) { os << " " << v.front(); v.pop(); } return os; } template <typename T> ostream &operator<<(ostream &os, stack<T> v) { if(!v.empty()) { os << v.top(); v.pop(); } while (!v.empty()) { os << " " << v.top(); v.pop(); } return os; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { bool is_f = true; for ( T x : v ) { os << (is_f ? "" : " ") << x; is_f = false; } return os; } template <typename T> ostream &operator<<(ostream &os, const deque<T> &v) { bool is_f = true; for ( T x : v ) { os << (is_f ? "" : " ") << x; is_f = false; } return os; } template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { bool is_f = true; for ( T x : v ) { os << (is_f ? "" : " ") << x; is_f = false; } return os; } using ull = unsigned long long; using ll = long long; using Pll = pair<ll, ll>; using P = pair<int, int>; constexpr ll INF64 = INT64_MAX / 2; constexpr int INF32 = INT32_MAX / 2; constexpr int dy[] = { 0, -1, 1, 0, -1, 1, -1, 1 }; constexpr int dx[] = { -1, 0, 0, 1, -1, -1, 1, 1 }; constexpr int mod998244353 = 998244353; constexpr int mod1000000007 = (int)1e9 + 7; constexpr char newl = '\n'; // clang-format on int main() { int n; string s; cin>>n>>s; vector<int> a(n+1); for(auto &A:a) cin>>A; ll k=INF64; rep(i,n) chmin(k,abs(a[i]-a[i+1])); vector<vector<int>> ans(k,vector<int>(n+1)); rep(j,n+1){ int rem=a[j]%k; rep(i,k){ ans[i][j]=a[j]/k; if(i<rem) ans[i][j]++; } } cout<<k<<endl; rep(i,k){ cout<<ans[i]<<newl; } }
#include <bits/stdc++.h> using namespace std; using ll = long long; // -------------------------------------------------------- template<class T> bool chmax(T& a, const T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> bool chmin(T& a, const T b) { if (b < a) { a = b; return 1; } return 0; } #define FOR(i,l,r) for (ll i = (l); i < (r); ++i) #define RFOR(i,l,r) for (ll i = (r)-1; (l) <= i; --i) #define REP(i,n) FOR(i,0,n) #define RREP(i,n) RFOR(i,0,n) #define ALL(c) (c).begin(), (c).end() #define RALL(c) (c).rbegin(), (c).rend() #define SORT(c) sort(ALL(c)) #define RSORT(c) sort(RALL(c)) #define MIN(c) *min_element(ALL(c)) #define MAX(c) *max_element(ALL(c)) #define SUMLL(c) accumulate(ALL(c), 0LL) #define SZ(c) ((ll)(c).size()) #define BIT(b,i) ((b>>i) & 1) #define PCNT(b) __builtin_popcountll(b) #define CIN(c) cin >> (c) #define COUT(c) cout << (c) << '\n' #define debug(x) cerr << "l." << __LINE__ << " : " << #x << " = " << (x) << '\n' ll llceil(ll a, ll b) { return (a + b - 1) / b; } string toupper(const string& S) { string T(S); REP(i,SZ(T)) T[i] = toupper(T[i]); return T; } string tolower(const string& S) { string T(S); REP(i,SZ(T)) T[i] = tolower(T[i]); return T; } using P = pair<ll,ll>; using VP = vector<P>; using VVP = vector<VP>; using VS = vector<string>; using VVS = vector<VS>; using VLL = vector<ll>; using VVLL = vector<VLL>; using VVVLL = vector<VVLL>; using VB = vector<bool>; using VVB = vector<VB>; using VVVB = vector<VVB>; using VD = vector<double>; using VVD = vector<VD>; using VVVD = vector<VVD>; static const double EPS = 1e-10; static const double PI = acos(-1.0); static const ll MOD = 1000000007; // static const ll MOD = 998244353; static const ll INF = (1LL << 62) - 1; // 4611686018427387904 - 1 // -------------------------------------------------------- // #include <atcoder/all> // using namespace atcoder; int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15); ll B, C; cin >> B >> C; if (C == 0) { COUT(1); return 0; } ll ans = 1; // B or -B if (B == 0) { // 0 --> INF ans += (C-2) / 2; // 0 --> -INF ans += C / 2; } else if (B > 0) { ans++; // -B // B --> 0 ans += min(C/2, B); // B --> INF ans += (C-2) / 2; // B ---> -1 ans += min((C-1)/2, B-1); // B --> -INF ans += (C-1) / 2; } else { ans++; // B // -B --> 0 ans += min((C-1)/2, -B); // -B --> INF ans += (C-1) / 2; // -B ---> -1 ans += min((C-1)/2, -B-1); // -B --> -INF ans += C / 2; } COUT(ans); return 0; }
//#pragma GCC optimize("O3") #include<bits/stdc++.h> #define eps 1e-9 #define MOD1 998244353 #define MOD2 1000000007 #define INV_2 499122177 #define INF 1000000000 #define PI 3.14159265358979323846 using namespace std; int main() { ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); long long x, k, i; cin >> x >> k; i=x; if(x < 0) x-=(2*x); unsigned long long ans; if(x==0) { ans=1; ans+=(k/2)+(k/2)-1+(k%2); } else { ans=2; if(i > 0) { if(k > 1) ans+=(k-1)/2+(k-1)/2-1+((k-1)%2); if(k/2 >= x) ans+=2*x-1; else ans+=(k/2)+(k/2)-1+(k%2); } else { ans+=(k/2)+(k/2)-1+(k%2); if(((k-1)/2) >= x) ans+=2*x-1; else if(k > 1) ans+=(k-1)/2+(k-1)/2-1+((k-1)%2); } } cout << ans << '\n'; } //size
#include "bits/stdc++.h" using namespace std; using ll=long long; using vi=vector<int>; using vvi=vector<vi>; using vll=vector<ll>; using vvll=vector<vll>; using pii=pair<int,int>; #define rep(i,n) for(int i=0;i<(n);i++) #define sor(v) sort(v.begin(),v.end()) #define rev(v) reverse(v.begin(),v.end()) #define pb push_back template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } //const int INF = 1123456789; //const int mod = 1e9+7; const int mod=998244353; ll kaijo[105]; void cal(){ ll res=1; for(int i=1;i<105;i++){ (res*=i)%=mod; kaijo[i]=res; } } int main(){ cal(); int n; cin>>n; ll sum=0; vll w(n); rep(i,n) {cin>>w[i]; sum+=w[i];} if(sum%2){cout<<0<<endl; return 0;} vector<vvll> dp(n+1,vvll(10001,vll(n+1))); dp[0][0][0]=1; rep(i,n){ rep(j,10001)rep(k,n){ (dp[i+1][j][k]+=dp[i][j][k])%=mod; if(j+w[i]<=10000)(dp[i+1][j+w[i]][k+1]+=dp[i][j][k])%=mod; } } sum/=2; ll ans=0; rep(i,n+1){ (ans+=dp[n][sum][i]*kaijo[i]%mod*kaijo[n-i])%=mod; } cout<<ans<<endl; }
#include <bits/stdc++.h> #include <string> #include <cmath> #include <sstream> #include <unordered_map> #define FOR(i, a, b) for (ll i = (a); i < (b); i++) #define FORD(i, a, b) for(ll i = (a-1); i >= (b); i--) #define pb(a) push_back(a) #define mp(a,b) make_pair(a,b) #define ff first #define ss second #define spre cout<<fixed<<setprecision(15); typedef long long int ll; using namespace std; //ll mod=67280421310721; ll mod=998244353; ll INF=1e9; ll po(ll a,ll b) { ll re=1; while(b) { if(b%2==1) { re=(re*a); re%=mod; } a=(a*a); a%=mod; b>>=1; } return re; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("INPUT.txt", "r", stdin); freopen("OUTPUT.txt", "w", stdout); #endif int test=1; // cin>>test; while(test--) { ll n; cin>>n; vector<ll> ans; for(ll i=1;i*i<=n;i++) { if((n%i)==0) { ans.pb(i); if((i*i)!=n) { ans.pb(n/i); } } } sort(ans.begin(),ans.end()); FOR(i,0,ans.size()) cout<<ans[i]<<'\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; //int:2*10**9 typedef long double ld; typedef pair<ll,ll> P; #define REP(i,n) for(ll i = 0; i<(ll)(n); i++) #define FOR(i,a,b) for(ll i=(a);i<=(b);i++) #define FORD(i,a,b) for(ll i=(a);i>=(b);i--) #define vec2(name,i,j,k) vector<vector<ll>> name(i,vector<ll>(j,k)) #define vec3(name,i,j,k,l) vector<vector<vector<ll>>> name(i,vector<vector<ll>>(j,vector<ll>(k,l))) #define pb push_back #define MOD 1000000007 //998244353 #define PI 3.141592653 #define INF 100000000000000 //14 //cin.tie(0);cout.tie(0);ios::sync_with_stdio(false); ll powe(ll a, ll b){//aのb乗のmod ll ret = 1; while(0 < b){ if((b%2) == 0){ a = (a*a); b >>= 1; } else{ ret = (ret*a); b--; } } return ret; } int main(){ vector<vector<string>> ansl(9); FOR(i,1,8){ string d = ""; REP(j,(1ll<<i-1)) d+="AB"; ansl[i].pb(d); } FOR(i,1,7){ REP(j,ansl[i].size()){ string v = ansl[i][j]; string w = ""; string x = ""; REP(k,v.length()){ if (v[k]=='A') { w+="AA"; x+="AB"; } else { w+="BB"; x+="BA"; } } ansl[i+1].pb(w); ansl[i+1].pb(x); } } ll n; cin >> n; cout << ansl[n].size() << endl; REP(i,ansl[n].size()) { cout << ansl[n][i] << endl; } }
#include<bits/stdc++.h> typedef long long int ll; typedef unsigned long long int ull; #define BIG_NUM 2000000000 #define HUGE_NUM 4000000000000000000 //オーバーフローに注意 #define MOD 1000000007 #define EPS 0.000000001 using namespace std; int POW[10]; char table[260]; //最大公約数 ll gcd(ll x,ll y){ x = abs(x); y = abs(y); if(x < y){ swap(x,y); } if(y == 0){ return x; }else{ return gcd(y,x%y); } } //最小公倍数 ll lcm(ll x,ll y){ return (x*y)/gcd(x,y); } int main(){ POW[0] = 1; for(int i = 1; i < 10; i++){ POW[i] = POW[i-1]*2; } int N; scanf("%d",&N); if(N == 1){ printf("1\n"); printf("AB\n"); return 0; } printf("%d\n",POW[N]-1); for(int i = 1; i <= POW[N]-1; i++){ for(int k = 0; k < POW[N]; k++){ int num = __builtin_popcount(i&k); if(num%2 == 0){ printf("A"); }else{ printf("B"); } } printf("\n"); } return 0; }
#include <stdlib.h> #include <cmath> #include <cstdio> #include <cstdint> #include <string> #include <iostream> #include <vector> #include <utility> #include <algorithm> #include <map> using namespace std; using ll = long long; int main(){ string X; cin >> X; ll index=-1; for(ll i=0;i<X.size();++i){ if(X[i]=='.'){ X.erase(i); break; } } cout << X << endl; return 0; }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; using ll = int64_t; int main() { string s; cin >> s; string t; for(int i = 1; i < s.size(); i++) t += s[i]; t += s[0]; cout << t << endl; }
#include <algorithm> #include <iostream> #include <numeric> #include <string> #include <tuple> #include <utility> #include <vector> #define rep(i, a, b) for (int i = int(a); i < int(b); i++) using namespace std; using ll = long long int; // clang-format off #ifdef _DEBUG_ #define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; debug_print(__VA_ARGS__); } while(false) template<typename T, typename... Ts> void debug_print(const T &t, const Ts &...ts) { cerr << t; ((cerr << ", " << ts), ...); cerr << endl; } #else #define dump(...) do{ } while(false) #endif template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); } template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); } 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; } template<typename T, typename... Ts> void print(const T& t, const Ts&... ts) { cout << t; ((cout << ' ' << ts), ...); cout << '\n'; } template<typename... Ts> void input(Ts&... ts) { (cin >> ... >> ts); } template<typename T> istream &operator,(istream &in, T &t) { return in >> t; } // clang-format on template<ll MOD = 1000000007> class ModInt { ll n; ModInt constexpr inverse() const { return ModInt::pow(*this, MOD - 2); } public: ModInt() : n(0) {} ModInt(ll _n) : n(((_n % MOD) + MOD) % MOD) {} ModInt operator+=(const ModInt &m) { n += m.n; if (n >= MOD) n -= MOD; return *this; } ModInt operator-=(const ModInt &m) { n -= m.n; if (n < 0) n += MOD; return *this; } ModInt operator*=(const ModInt &m) { n *= m.n; if (n >= MOD) n %= MOD; return *this; } ModInt operator/=(const ModInt &m) { (*this) *= m.inverse(); return *this; } friend ModInt operator+(ModInt t, const ModInt &m) { return t += m; } friend ModInt operator-(ModInt t, const ModInt &m) { return t -= m; } friend ModInt operator*(ModInt t, const ModInt &m) { return t *= m; } friend ModInt operator/(ModInt t, const ModInt &m) { return t /= m; } ModInt operator=(const ll l) { n = l % MOD; if (n < 0) n += MOD; return *this; } friend ostream &operator<<(ostream &out, const ModInt &m) { out << m.n; return out; } friend istream &operator>>(istream &in, ModInt &m) { ll l; in >> l; m = l; return in; } static constexpr ModInt pow(const ModInt x, ll p) { ModInt<MOD> ans = 1; for (ModInt<MOD> m = x; p > 0; p /= 2, m *= m) { if (p % 2) ans *= m; } return ans; } static constexpr ll mod() { return MOD; } }; using mint = ModInt<>; mint operator"" _m(unsigned long long m) { return mint(m); } const int maxn = 3010; mint dp[maxn][maxn]; mint mp[maxn][maxn]; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin, n; vector<ll> a(n); rep(i, 0, n) { cin, a[i]; } dp[0][0] = 1; mint ans = 0; vector<ll> sum(n + 1, 0); rep(i, 0, n) { sum[i + 1] = sum[i] + a[i]; rep(j, 0, n) { mp[j][sum[i] % (j + 1)] += dp[i][j]; } rep(j, 0, n) { dp[i + 1][j + 1] += mp[j][sum[i + 1] % (j + 1)]; /* rep(k, 0, i + 1) { if (sum[i + 1] % (j + 1) == sum[k] % (j + 1)) { dp[i + 1][j + 1] += dp[k][j]; } } //*/ } } rep(i, 0, n + 1) { ans += dp[n][i]; } print(ans); return 0; }
#include <algorithm> #include <cassert> #include <climits> #include <cmath> #include <complex> #include <cstring> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <tuple> #include <vector> const long long P = 1e9 + 7; const double EPS = 1e-9; using namespace std; void solve() { int n; cin >> n; vector<long long> v(n); for (int i = 0; i < n; i++) cin >> v[i]; vector<vector<long long>> dp(n, vector<long long>(n + 1)); // dp[i][j]: num ways for v[0..i] with j segments // dp[i][j] = r[SUM(v[0..i]) % j] for (int i = 0; i < n; i++) dp[i][1] = 1; for (int k = 2; k <= n; k++) { long long s = 0; vector<long long> ct(k, 0); for (int i = 0; i < n; i++) { s = (s + v[i]) % k; dp[i][k] = ct[s]; ct[s] = (ct[s] + dp[i][k - 1]) % P; } } long long res = 0; for (int k = 1; k <= n; k++) res = (res + dp[n - 1][k]) % P; cout << res << '\n'; } /* YOU CAN DO THIS!! ;) 1. Note the limits! 2. Give logical, short variable names 3. If you are stuck for a long time, skip to next problem 4. Can't prove a pattern (Esp Game Theory)? Brute force for small numbers and observe! */ int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; // int t; // cin >> t; while (t--) { solve(); } }
#pragma region //#pragma optimize("Ofast") #include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> using namespace std; typedef long long ll; #define tr t[root] #define lson t[root << 1] #define rson t[root << 1 | 1] #define rep(i, a, n) for (int i = a; i <= n; ++i) #define per(i, a, n) for (int i = n; i >= a; --i) #pragma endregion const int maxn = 2e5 + 5; int main() { int n, m; scanf("%d%d", &n, &m); m *= 100; rep(i, 1, n) { int x, y; scanf("%d%d", &x, &y); m -= x * y; if (m < 0) { printf("%d\n", i); return 0; } } puts("-1"); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<ll,ll> pll; typedef pair<ll,pll> plp; typedef pair<pll,ll> ppl; typedef pair<pll,pll> ppp; typedef vector<ll> vll; typedef vector<vll> vvll; typedef vector<vvll> vvvll; typedef vector<pll> vpll; typedef vector<plp> vplp; typedef vector<ppl> vppl; typedef vector<ppp> vppp; typedef vector<vpll> vvpll; typedef vector<bool> vbool; typedef vector<vbool> vvbool; typedef vector<double> vd; typedef priority_queue<pll,vpll,greater<pll> > pqpll; typedef priority_queue<pll,vpll> pqrpll; typedef priority_queue<ll, vll, greater<ll> > pqll; typedef priority_queue<ll, vll> pqrll; struct edge{ ll to,cost; edge(ll to,ll cost): to(to), cost(cost){} }; typedef vector<vector<edge>> Graph; #define rep(i,a,n) for(ll i = a;i < n;i++) #define rrep(i,a,n) for(ll i = n-1; i >= a;i--) #define LINF 1000000000000000000 #define INF 1000000000 #define fs first #define sc second #define EPS 1e-10 #define ALL(a) a.begin(), a.end() template<typename T> ll sz(vector<T> &vec){ return (ll)vec.size(); } template<typename T> ll sz(priority_queue<T, vector<T> > &pq) {return (ll)pq.size(); } template<typename T> ll sz(priority_queue<T, vector<T>, greater<T> > &pq) {return (ll)pq.size(); } ll sz(string &s) {return (ll)s.size(); } void chmin(ll &a, ll &b) { if(a > b) a = b; } void chmax(ll &a, ll &b) { if(a < b) a = b; } ll gcd(ll a,ll b){ return ((!b) ?a :gcd(b, a%b)); } ll lcm(ll a,ll b){ return a / gcd(a,b) * b; } ll dx[4] = {0,-1,1,0},dy[4] = {-1,0,0,1}; bool checkindex(ll i,ll n){ return (i < n && i >= 0); } int main(){ ll t; cin >> t; rep(i,0,t){ string s,t; cin >> s; string memo = "atcoder"; t = s; sort(ALL(t),greater<char>()); if(memo < s) cout << 0 << endl; else if(memo >= t) cout << -1 << endl; else{ ll ans = LINF; rep(i,0,sz(memo)){ rep(j,i,sz(s)){ if(s[j] > memo[i]){ ans = min(ans,j-i); break; } } if(s[i] < memo[i]) break; } rep(i,0,sz(s)) if(s[i] != 'a') {ans = min(ans,i); break;} cout << ans << endl; } } return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define gcd __gcd #define INF LONG_LONG_MAX #define rep(i,n) for(int i=0;i<(int)(n);i++) int main(){ string str; cin >> str; int ans=0; rep(i,10000){ vector<bool> flag(10); //最初にフラグを立てる. int x=i; rep(j,4){ flag[x%10]=true; x/=10; } //フラグが立っているかをチェック. int flag2=true; rep(k,10){ if(str[k]=='o' && flag[k]!=true) flag2=false; if(str[k]=='x' && flag[k]==true) flag2=false; } //cout << i << endl; ans+=flag2; } cout << ans << endl; return 0; }
#include <iostream> using namespace std; int main() { char a,b,c; cin >> a >>b >> c ; cout << b<<c<<a; return 0; }
#include <iostream> #include <iomanip> #include <cmath> #include <cstdlib> #include <cstring> #include <climits> #include <algorithm> #include <numeric> #include <utility> #include <random> #include <chrono> #include <string> #include <vector> #include <stack> #include <queue> #include <set> #include <map> #include <unordered_set> #include <unordered_map> using namespace std; typedef long long ll; typedef pair<int, int> pii; //const int mod = 1e9+7; const int MAXN = 110; double d[MAXN], h[MAXN]; int N; double D, H; inline void quickread() { ios::sync_with_stdio(false); cin.tie(nullptr); } double solve(int idx) { if(d[idx] == D) { return H; } return ((H + h[idx])*(D-d[idx]) + h[idx]*d[idx] - H*D)/(D - d[idx]); } int main() { quickread(); cin >> N >> D >> H; for (int i = 0; i < N; i++) { cin >> d[i] >> h[i]; } double res = 0; for (int i = 0; i < N; i++) { res = max(solve(i), res); } cout << fixed << setprecision(6) << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll K,N,M; class Node{ public: ll diff,b,pos; Node(ll _d = 0,ll _b = 0,ll _p = 0):diff(_d),b(_b),pos(_p){ } }; bool operator < (const Node &A,const Node &B){ return A.diff > B.diff; } void solve(){ vector<ll> vec; for(int i=0;i<K;i++){ ll value; cin >> value; vec.push_back(value); } vector<Node> vn; vector<ll> res(K,0); ll sum = 0; for(int i=0;i<K;i++){ ll bi = vec[i]*M/N; ll diff = abs(bi*N - vec[i]*M); sum += bi; vn.push_back(Node(diff,bi,i)); } ll leave = M-sum; sort(vn.begin(),vn.end()); // for(int i = 0;i< K;i++){ // cout << vn[i].diff << " " << vn[i].b << " " << vn[i].pos << endl; // } for(int i = 0;i<leave;i++){ vn[i].b += 1; } for(int i = 0;i< K;i++){ res[vn[i].pos] = vn[i].b; } for(int i = 0;i< K;i++){ cout << res[i] << (i == K-1? '\n':' '); } } int main(void){ ios::sync_with_stdio(false); cin.tie(0); cin >> K >> N >> M; solve(); return 0; }
#line 1 "main_d.cpp" #include <algorithm> #include <array> #include <bitset> #include <cassert> #include <cctype> #include <cstdint> #include <cstdlib> #include <cmath> #include <complex> #include <chrono> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <memory> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <vector> #include <random> #include <utility> #include <limits> #include <list> #include <type_traits> /* template start */ using i64=std::int_fast64_t; using u64=std::uint_fast64_t; #define rep(i, a, b) for (i64 i = (a); (i) < (b); (i)++) #define all(i) i.begin(), i.end() #ifdef LOCAL #define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) #endif void debug_out(){std::cerr<<std::endl;} template<typename Head,typename... Tail> void debug_out(Head h,Tail... t){ std::cerr<<" "<<h; if(sizeof...(t)>0)std::cout<<" :"; debug_out(t...); } template <typename T1, typename T2> std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) { return os << pa.first << " " << pa.second; } template <typename T> std::ostream& operator<<(std::ostream& os, std::vector<T> vec) { for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " "); return os; } template<typename T1,typename T2> inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);} template<typename T1,typename T2> inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);} template<typename Num> constexpr Num mypow(Num a, u64 b,Num id=1) { if(b==0)return id; Num x = id; while (b > 0) { if(b & 1)x*=a; a*=a; b >>= 1; } return x; } /* template end */ void solve(){ i64 n; std::cin>>n; std::vector<i64> a(n); for(auto&& e:a)std::cin>>e; if(n%2==0){ std::sort(all(a)); bool firstwin=false; rep(i,0,n/2){ if(a[2*i] < a[2*i+1])firstwin=true; } if(firstwin)std::cout<<"First\n"; else std::cout<<"Second\n"; return; }else{ std::cout<<"Second\n"; return; } } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); i64 test; std::cin>>test; while(test--)solve(); return 0; }
#include<bits/stdc++.h> using namespace std; using namespace std::chrono; const int mod=1e9+7; const int mex=2002; #define ll long long #define test int t;cin>>t;while(t--) #define fast ios_base::sync_with_stdio(false);cin.tie(NULL); #define fo(i,a,n) for(int i=a;i<n;i++) #define rfo(i,a,b) for(int i=a;i>=b;i--) #define bg begin() #define en end() #define fi first #define se second #define ub upper_bound #define lb lower_bound #define pb push_back #define veci vector<int> #define veclli vector<long long int> #define all(x) x.begin(),x.end() #define sci(x) scanf("%d",&x); #define scc(x) scanf("%c",&x); #define scs(x) scanf("%s",x); #define debug(arr,n) for(int i=0;i<n;i++) printf("%d ",arr[i]); #define sz(x) x.size() #define loop(x) for(auto it=x.begin();it!= x.end();it++) #define int long long signed main() { int n; cin>>n; int a[n],b[n],mx=0,mx2=0; fo(i,0,n) cin>>a[i]; fo(i,0,n) { cin>>b[i]; mx=max(a[i],mx); mx2=max(mx2,b[i]*mx); cout<<mx2<<endl; } }
#include <bits/stdc++.h> #define ll long long using namespace std; const int maxn=100000; int n; int p[maxn+1],a[maxn+1]; int main(){ cin>>n; iota(p,p+n+1,0); for (int i=2;;++i){ int j=i*i; if (j>n) break; if (p[i]!=i) continue; while (j<=n) { p[j]=i; j+=i; } } a[1]=1; cout<<1; for (int i=2;i<=n;++i){ if (p[i]!=i) a[i]=a[i/p[i]]+1; else a[i]=2; cout<<' '<<a[i]; } cout<<'\n'; return 0; }
#include <iostream> #include <cstdio> #include <string> #include <iostream> #include <cstdio> #include <string> #include <algorithm> #include <utility> #include <cmath> #include <vector> #include <queue> #include <deque> #include <set> #include <map> #include <numeric> #include <functional> using namespace std; typedef long long ll; typedef vector<ll> vl; typedef vector<vector<ll>> vvl; typedef pair<ll, ll> P; #define rep(i, n) for(ll i = 0; i < n; i++) #define exrep(i, a, b) for(ll i = a; i <= b; i++) #define out(x) cout << x << endl #define exout(x) printf("%.10f\n", x) #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define pb push_back #define re0 return 0 const ll mod = 1000000007; const ll INF = 1e16; const ll MAX_N = 10010; int main() { string s; cin >> s; ll n = s.size(); deque<char> dQ; ll flip = 0; // sが反転してたら1 rep(i, n) { if(s[i] == 'R') { flip = 1 - flip; } else { if(flip) { dQ.push_front(s[i]); } else { dQ.pb(s[i]); } } } if(flip) { reverse(all(dQ)); } string t = ""; for(auto c : dQ) { t.push_back(c); ll m = t.size(); if(m >= 2 && t[m-2] == t[m-1]) { rep(i, 2) { t.pop_back(); } } } out(t); re0; }
//#pragma GCC optimize "trapv" #pragma GCC optimize("Ofast") #pragma GCC optimize("O3", "unroll-loops") #pragma GCC target("avx,avx2,fma") #include<bits/stdc++.h> #define ll long long int #define fab(a,b,i) for(int i=a;i<b;i++) #define pb push_back #define db double #define mp make_pair #define endl "\n" #define f first #define se second #define all(x) x.begin(),x.end() #define MOD 1000000007 #define vll vector<ll> #define vi vector<int> #define pii pair<int,int> #define pll pair<ll,ll> #define quick ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) ll add(ll x, ll y) {ll res = x + y; return (res >= MOD ? res - MOD : res);} ll mul(ll x, ll y) {ll res = x * y; return (res >= MOD ? res % MOD : res);} ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + MOD : res);} ll power(ll x, ll y) {ll res = 1; x %= MOD; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;} ll mod_inv(ll x) {return power(x, MOD - 2);} using namespace std; map<int,int> m; void fac(int n) { fab(1,sqrt(n)+1,i) { if(n%i==0) { m[i]++; if(n/i!=i) { m[n/i]++; } } } } int main() { quick; int n; cin>>n; ll a[n]; fab(0,n,i) { cin>>a[i]; } ll sum=0; ll ans=0; ll prev=0; ll pref=0; fab(0,n,i) { ans=max(ans,sum+prev); sum+=pref; sum+=a[i]; pref+=a[i]; // cout<<"i:"<<i<<" "<<sum<<" "<<prev<<endl; prev=max(prev,pref); } ans=max(ans,sum); cout<<ans<<endl; //cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define Pint pair<int,int> #define Pll pair<ll,ll> #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); } ll gcd(ll a,ll b){ if(b==0)return a; return gcd(b,a%b); } ll lcm(ll a,ll 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; } ll modpow(ll a,ll b){ if(b==0)return 1; if(b%2)return modpow(a,b-1)*a%mod; ll memo=modpow(a,b/2); return memo*memo%mod; } vector<ll>kaijo,invkaijo; void init_fact(int n){ kaijo.resize(n+1); invkaijo.resize(n+1); kaijo[0]=1; for(ll 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<ll>>C,sC; void init_comb(int n,int m){ C.resize(n+1,vector<ll>(m+1,0)); sC.resize(n+1,vector<ll>(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; } } } ll 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; } ll inv(ll x){ x=modpow(x,mod-2); return x; } void solve(){ int n; cin>>n; ll ans=0,cur=0,sum=0,masum=0; rep(i,n){ ll a; cin>>a; sum+=a; chmax(masum,sum); chmax(ans,cur+masum); cur+=sum; } cout<<ans<<endl; } int main(){ //int t;cin>>t;while(t--) solve(); return 0; }
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <queue> #include <set> /* MACROS START */ #define input std::cin #define for2(i,n) for(int i=0; i<n; i++) #define for3(i,a,n) for(int i=a; i<n; i++) #define for4(i,a,n,s) for(int i=a; i<n; i+=s) using lint = long long int; using namespace std; template <typename T> void printvec(T vec) { for (auto& a: vec) cout << a << " "; cout << endl; } /* MACROS END */ /* LIBRARY START */ /* LIBRARY END */ struct Expectation { double exact = 0, variable = 0; Expectation& operator+=(const Expectation& other) { this->exact += other.exact; this->variable += other.variable; return *this; } Expectation& operator-=(const Expectation& other) { this->exact -= other.exact; this->variable -= other.variable; return *this; } }; Expectation operator/(const Expectation& e, double d) { return {e.exact/d, e.variable/d}; } Expectation operator+(const Expectation& e, int d) { return {e.exact+d, e.variable}; } int main() { std::ios_base::sync_with_stdio(0); int n, m, k; input >> n >> m >> k; set<int> traps; for2(i, k) { int tr; input >> tr; traps.insert(tr); } queue<Expectation> runsum; for2(i, m) { runsum.push({0, 0}); } Expectation sum = {0, 0}; for(int i=n-1; i>0; i--) { if (traps.count(i)) { runsum.push({0, 1}); } else { runsum.push((sum + m) / m); } sum -= runsum.front(); runsum.pop(); sum += runsum.back(); } Expectation exp = (sum + m) / m; if (exp.variable >= 0.999999) std::cout << -1 << std::endl; else { double ans = exp.exact / (1.0 - exp.variable); std::cout << std::fixed << ans << std::endl; } }
#include<bits/stdc++.h> // 76 87 using namespace std; #define rep(x, k, n) for(int x = (k); x < (n); ++x) #define repr(x, k, n) for(int x = (k); x > (n); --x) #define tr(it,a) for(auto it = (a).begin(); it != (a).end(); ++it) #define ll long long #define siz(x) ((int)(x).size()) #define print(x) cout << (x) << '\n' #define prints(x) cout << (x) << " " #define eb emplace_back #define mp make_pair #define F first #define S second #define o2(x) ( (x) * (x) ) #define all(x) (x).begin(), (x).end() #define allr(x) (x).rbegin(), (x).rend() #define clr(x,k) memset(x, k, sizeof(x)) #define sortall(x) sort(all(x)) #define sortalld(x) sort(all(x), greater<int>()) #define printv(v) rep(x, 0, siz(v)){ prints(v[x]); } cout << '\n' #define print2dv(V) rep(y, 0, siz(V)){ printv(V[y]); } #define out(x) cout << ((x) ? "Yes" : "No") << '\n'; #define PI 3.1415926535897932384626 #define inf INT_MAX #define ninf INT_MIN #define int long long // take care of it when too much computation required typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<char> vc; typedef vector<bool> vb; typedef vector<pii> vpii; typedef vector<pll> vpll; typedef vector<vi> vvi; typedef vector<vl> vvl; typedef vector<vc> vvc; typedef vector<vb> vvb; typedef vector<vpii> vvpii; template <typename Arg1> void debug_out(const char* name, Arg1&& arg1){ cout << name << " = " << arg1 << " ]" << '\n'; } template <typename Arg1, typename... Args> void debug_out(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " = " << arg1 <<","; debug_out(comma+1, args...); } #ifndef ONLINE_JUDGE #define deb(...) cout << "[ ", debug_out(#__VA_ARGS__, __VA_ARGS__) #else #define deb(...) #endif mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count()); const int mod = 1e9+7; const int N = 3e5, M = N; /* ->Do not forget to check the edge cases. ->Make sure you are submitting the right file. ->Do not make "easy->complicated". */ /* -> 1, 2, 3, 3, 4, 5 -> 1 + 2 + 3 : (n * (n + 1)) / 2 = 6 -> 3 + 4 + 5 : (5 * 6)/2 - (2 * 3)/2 = */ //----------------------------------------------------------------------------- void Solve_main() { int n, m, k; cin >> n; int l, r, res = 0; rep(i, 0, n){ cin >> l >> r; res += (r * (r + 1))/2; res -= (l * (l - 1))/2; } cout << res << '\n'; } //----------------------------------------------------------------------------- int32_t main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); srand(chrono::high_resolution_clock::now().time_since_epoch().count()); // cout << setprecision(12) << fixed; int tc = 1; // cin >> tc; for(int i = 0; i < tc; i++) { Solve_main(); } cerr << "[time:" << 1.0*clock()/CLOCKS_PER_SEC << "s] "; return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long #define MOD 1000000007 #define pd push_back #define sort(v) sort(v.begin(),v.end()) #define Sort(v) sort(v.begin(),v.end(),greater<int>()) #define display(s) for(auto val:s) cout<<val<<" "; cout<<endl; #define displayMap(mymap) for(auto val:mymap) cout<<val.first<<" -> "<<val.second<<endl; #define Sortcom(v) sort(v.begin(),v.end(),mycompare) #define f(a,b,c) for(int i=a;i<b;i+=c) int solve(){ int a,b,c,d; cin>>a>>b>>c>>d; int R=0,C=0,cnt=0; C = a; if(d*c-b<=0) return -1; return (int)ceil((double)a/(d*c-b)); } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; t=1; // int t; cin>>t; while(t--) { // solve(); cout<<solve()<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll a,b,c,d;cin>>a>>b>>c>>d;ll e=0; ll ans=-1; for(ll x=0;x<=1e8;x++){ ll r=a+b*x; ll l=c*x; if(r<=l*d){ ans=x; break; } } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; bool delimiter, unof = 1; #define F first #define S second #define pb push_back #define ll long long #define all(x) x.begin() , x.end() #define rep(i,s,e) for (int i = s; i < e; ++i) #define rev(i,s,e) for (int i = s; i > e; --i) inline namespace IO{ template<class t> using con=vector<t>; template<class t, class u> using pi=pair<t,u>; template<class t, class u> istream& operator>>(istream& is, pi<t,u>& pr){ is >> pr.F >> pr.S; return is; } template<class t, class u> ostream& operator<<(ostream& os, const pi<t,u>& pr){ delimiter=0; os << (unof ? "\t{" : "") << pr.F << (unof? " , " : " ") << pr.S << (unof? "}" : ""); return os; } template<class t> istream& operator>>(istream& is,con<t>& v){ for (auto &i : v) is >> i; return is; } template<class t> ostream& operator<<(ostream& os,const con<t>& v){ delimiter=1; os << (unof? "[": ""); bool fst = 0; for(auto e:v) os << (unof and fst? ", " : "") << e << (delimiter ? ' ' : '\n'), fst = 1; os << (unof? "]": ""); return os; } } const int N = 1e5 + 9 ; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifdef CLion freopen("input.txt" , "r" , stdin); // freopen("output.txt", "w" , stdout); #endif int a, b; cin >> a >> b; set<ll> s; if (a > b){ int df = a - b; int pos = df + 1, neg = 1; a -= pos; b -= neg; ll sum = 0; rep(i,1,pos + 1){ cout << i << " "; sum += i; s.insert(i); } cout << -sum << " "; s.insert(-sum); } else if (b > a){ int df = b - a; int neg = df + 1, pos = 1; a -= pos; b -= neg; ll sum = 0; rep(i,1,neg + 1){ cout << -i << " "; sum += -i; s.insert(-i); } cout << -sum << " "; s.insert(-sum); } for ( int i = 1e9; a > 0 and b > 0; --i,--a,--b ){ if ( s.count(i) == 0 and s.count(-i) == 0 ){ cout << i << " " << -i << " "; } } return 0; }
#include<bits/stdc++.h> using namespace std; int main () { ios_base::sync_with_stdio(false); cin.tie(0); int a, b; cin >> a >> b; int sum = a * (a + 1) / 2 - b * (b + 1) / 2; for (int i = 1; i <= a; i++) { int x = i; if (sum < 0) x += abs(sum), sum = 0; cout << x << " "; } for (int i = 1; i <= b; i++) { int x = -i; if (sum > 0) x -= sum, sum = 0; cout << x << " "; } cout << "\n"; }
#include <bits/stdc++.h> // #include <atcoder/all> // using namespace atcoder; #define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) #define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++) #define repr(i, n) for (ll i = n; i >= 0; i--) #define pb push_back #define COUT(x) cout << (x) << "\n" #define COUTF(x) cout << setprecision(15) << (x) << "\n" #define ENDL cout << "\n" #define DF(x) x.erase(x.begin()) #define ALL(x) x.begin(), x.end() #define SORT(x) sort(ALL(x)) #define RSORT(x) sort(x.rbegin(), x.rend()) #define REVERSE(x) reverse(ALL(x)) #define MAX(x) *max_element(ALL(x)) #define MAXI(x) max_element(ALL(x)) - x.begin() #define SUM(x) accumulate(ALL(x), 0ll) #define COUNT(x, y) count(ALL(x), y); #define ANS cout << ans << "\n" #define YES cout << "YES\n"; #define NO cout << "NO\n"; #define Yes cout << "Yes\n"; #define No cout << "No\n"; #define init() \ cin.tie(0); \ ios::sync_with_stdio(false) #define LINE cerr << "[debug] line: " << __LINE__ << endl; #define debug(x) cerr << "[debug] " << #x << ": " << x << endl; #define debugV(v) \ cerr << "[debugV] " << #v << ":"; \ rep(z, v.size()) cerr << " " << v[z]; \ cerr << endl; using namespace std; using ll = long long; using ld = long double; using vll = vector<ll>; using vvll = vector<vector<ll>>; using mll = map<ll, ll>; using qll = queue<ll>; using P = pair<ll, ll>; using vp = vector<P>; using vs = vector<string>; template <typename T> inline istream& operator>>(istream& i, vector<T>& v) { rep(j, v.size()) i >> v[j]; return i; } template <typename T1, typename T2> inline istream& operator>>(istream& i, pair<T1, T2>& v) { return i >> v.first >> v.second; } constexpr ll INF = 0x3f3f3f3f3f3f3f3f; constexpr ld PI = 3.141592653589793238462643383279; ll get_digit(ll x) { return to_string(x).size(); } ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } template <class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } ll mod_pow(ll x, ll n, ll mod) { if (n == 0) return 1; ll res = mod_pow(x * x % mod, n / 2, mod); if (n & 1) res *= x; res %= mod; return res; } signed main() { init(); ll N, C; cin >> N >> C; priority_queue<P, vector<P>, greater<P>> q; rep(i, N) { ll a, b, c; cin >> a >> b >> c; q.push({a, c}); q.push({b + 1, -c}); } ll ans = 0; ll before_index = 0; ll before_value = 0; ll now = 0; ll value = 0; while (!q.empty()) { P t = q.top(); q.pop(); // debug(t.first); // debug(t.second); if (now == t.first) { value += t.second; before_value = value; before_index = now; continue; } else { now = t.first; value += t.second; ll l = now - before_index; ans += l * min(C, before_value); before_value = value; before_index = now; // debug(l); // debug(ans); // ENDL; } } ANS; return 0; }
#include <iostream> #include <vector> #include <map> #include <set> #include <algorithm> using namespace std; int n; int64_t C; int minn(int64_t &a, int &b) { return (a < b) ? a : b; } int main(int argc, const char * argv[]) { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> C; vector<int> a(n); vector<int> b(n); vector<int> c(n); set<int> s; map<int, int64_t> changes; for (int i = 0; i < n; ++i) { cin >> a[i] >> b[i] >> c[i]; } for(int i = 0; i < n; ++i) { static_cast<void>(s.insert(a[i])), s.insert(b[i] + 1); changes[a[i]] += c[i]; changes[b[i] + 1] -= c[i]; } vector<int> v(s.begin(), s.end()); int m = int(v.size()); int64_t acc = 0; int64_t ans = 0; for(int i = 0; i < m - 1; ++i) { acc += changes[v[i]]; ans += (min(C, acc)) * (v[i + 1] - v[i]); } cout << ans; return 0; }
#include <iostream> using namespace std; int main(void){ double x,y,z; //take_g, taka_yen, su_g, su_yen cin >> x >> y >> z; // 高橋,すぬの1gあたりの値段 double taka_per_yen = y/x; double su_per_yen; // すぬの1gあたりの値段がより小さくなるまで回す int amp = z*taka_per_yen; while(true){ su_per_yen = amp/z; if(su_per_yen < taka_per_yen || amp <= 0){ break; } amp--; } cout << amp << endl; return 0; }
#include<iostream> #include<algorithm> #include<cstring> #include<cstdio> #include<bitset> #include<cmath> #include<ctime> #include<queue> #include<map> #include<set> #define int long long #define lowbit(x) (x&(-x)) #define mid ((l+r)>>1) #define lc (x<<1) #define rc (x<<1|1) #define max Max #define min Min #define abs Abs using namespace std; inline int read() { int ans=0,f=1; char c=getchar(); while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();} while(c>='0'&&c<='9'){ans=(ans<<1)+(ans<<3)+c-'0';c=getchar();} return ans*f; } inline void write(int x) { if(x<0) putchar('-'),x=-x; if(x/10) write(x/10); putchar((char)(x%10)+'0'); } template<typename T>inline T Abs(T a){return a>0?a:-a;}; template<typename T,typename TT>inline T Min(T a,TT b){return a>b?b:a;} template<typename T,typename TT> inline T Max(T a,TT b){return a>b?a:b;} int n,m,ans; signed main() { n=read();m=1; for(int i=2;i<=n;++i) m=m*i/__gcd(i,m); printf("%lld\n",m+1); return 0; }
#include<bits/stdc++.h> using namespace std; int a,b; int main(){ cin>>a>>b; int t=1000000000; int tt=t; for(int i=1;i<a;i++){ cout<<i<<" "; tt-=i; } cout<<tt<<" "; int ttt=t; for(int i=1;i<b;i++){ cout<<-i<<" "; ttt-=i; } cout<<-ttt; }
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <queue> #include <bitset> #include <cmath> using namespace std; #include<stdio.h> #include <stdlib.h> int main() { double a, b; cin >> a >> b; double ans = 100-((b / a) * 100); cout << ans << endl; }
#include <iostream> #include <vector> #include <string> using namespace std; int main() { int n, s, d, xs, ys; cin >> n >> s >> d; bool dmg = false; for (int i = 0; i < n; ++i) { cin >> xs >> ys; if (xs < s && ys > d) dmg = true; } if (dmg) cout << "Yes\n"; else cout << "No\n"; return 0; }
// C - POW #include <bits/stdc++.h> using namespace std; int main(){ int a, b, c; cin>>a>>b>>c; if((a<0 || b<0) && c%2==0) a = abs(a), b = abs(b); puts(a<b? "<": a>b? ">":"="); }
#include <bits/stdc++.h> using namespace std; int main() { // long long int i,j,k,n,m,t,v,s,d; long double x,y,r; cin>>x>>y>>r; r+=1e-14; long long int sx=ceil(x-r),ex=floor(x+r); long long int c=0; for(long long int i=sx;i<=ex;i++) { if(i>=x-r && i<=x+r) { long double ystart,yend; ystart=y+sqrt(fabs(r*r-(x-i)*(x-i))); yend=y-sqrt(fabs(r*r-(x-i)*(x-i))); long long int ys=floor(ystart),ye=ceil(yend); if(ys>ystart) ys--; if(ye<yend) ye++; if(ys>=ye) c+=ys-ye+1; // if(ceil(ystart)!=ys && belongs(i,ceil(ystart),x,y,r)) // c++; // if(floor(yend)!=ye && belongs(i,floor(yend),x,y,r)) // c++; } } cout<<c; }
// #define ONLINE_JUDGE #include <bits/stdc++.h> using namespace std; using ll = long long; #ifndef ONLINE_JUDGE # define dbg(x) cerr << '#' << #x << ' ' << x << endl # define TIME cerr << "RuningTime: " << clock() << "ms\n", 0 #else # define dbg(x) # define TIME 0 #endif #define mem(a,b) memset(a,b,sizeof(a)) #define endl '\n' const ll base = 1e4; ll input(){ string s; cin >> s; ll res = 0; bool flag = 0; // 标记是否遇到小数点 int cnt = 0; // 记录小数点后位数 for(auto i : s){ if(i == '.'){ flag = 1; continue; } res = res * 10 + (i - '0'); if(flag) cnt++; } while(cnt < 4){ res = res * 10; cnt++; } return res; } int main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); #endif ios::sync_with_stdio(0),cin.tie(0); ll x = input(), y = input(), r = input(); dbg(x); ll lx = x - r, rx = x + r; while(lx % base != 0) lx++; while(rx % base != 0) rx--; ll uy = y, dy = y; while(uy % base != 0) uy++; while(dy % base != 0) dy--; ll ans = 0; for(ll i = lx; i <= rx; i += base){ ll tmpx = abs(x - i); // uy下移 while(tmpx * tmpx + (uy - y) * (uy - y) > r * r) uy -= base; // uy上移到上界+1 while(uy <= y || tmpx * tmpx + (uy - y) * (uy - y) <= r * r) uy += base; // dy上移 while(tmpx * tmpx + (y - dy) * (y - dy) > r * r) dy += base; // dy下移到下界-1 while(dy >= y || tmpx * tmpx + (y - dy) * (y - dy) <= r * r) dy -= base; ans += (uy - dy + base - 2 * base) / base; } cout << ans; }
#include "algorithm" #include "iostream" #include "numeric" #include "iomanip" #include "cstring" #include "math.h" #include "bitset" #include "string" #include "vector" #include "random" #include "chrono" #include "ctime" #include "queue" #include "stack" #include "map" #include "set" #include "ext/pb_ds/assoc_container.hpp" // Common file #include "ext/pb_ds/tree_policy.hpp" // Including tree_order_statistics_node_update #include "ext/pb_ds/detail/standard_policies.hpp" using namespace std; using namespace __gnu_pbds; #define f first #define lgn 25 #define endl '\n' #define sc second #define pb push_back #define N (int)2e5+5 #define PI acos(-1.0) #define int long long #define vi vector<int> #define mod 1000000007 #define ld long double #define eb emplace_back #define mii map<int,int> #define vpii vector<pii> #define pii pair<int,int> #define pq priority_queue #define BLOCK (int)sqrt(N) #define test(x) while(x--) #define all(x) begin(x),end(x) #define allr(x) x.rbegin(),x.rend() #define fo(i,a,n) for(int i=a;i<n;i++) #define rfo(i,n,a) for(int i=n;i>=a;i--) #define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define time() cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n" #define bug(...) __f (#__VA_ARGS__, __VA_ARGS__) typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > OS ; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template <typename Arg1> void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f (const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr (names + 1, ','); cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...); } const int inf = 0x3f3f3f3f; const int INF = 0x3f3f3f3f3f3f3f3f; int n,m,k,q; string s; vi adj[N]; int vis[N],par[N],a[N]; void go() { char x, y; cin >> x >> y; if( x == 'Y' ) { cout << ( char )( y - 'a' + 'A' ) << endl; } else { cout << y << endl; } } int32_t main() { FAST; int t=1; // cin>>t; test(t) go(); }
// clang-format off #include <bits/stdc++.h> using namespace std; #define int long long #define stoi stoll using pii = pair<int,int>; using vi = vector<int>; using vvi = vector<vi>; #define all(c) begin(c), end(c) #define rall(c) rbegin(c), rend(c) #define fore(x, c) for(auto &&x : c) #define rep(i, a, n) for(int i = a, i##len = (int)(n); i < i##len; ++i) #define rrep(i, a, n) for(int i = (int)(n - 1); i >= a; --i) #define sz(c) ((int)c.size()) #define contains(c, x) (c.find(x) != end(c)) #define inseg(l, x, r) ((l) <= (x) && (x) < (r)) #define dump(...) #define pb push_back #define eb emplace_back #define _ 0 const signed INF_ = 1001001001; const long long INF = 1001001001001001001LL; const int DX[9] = {0,1,0,-1,1,1,-1,-1,0}, DY[9] = {-1,0,1,0,-1,1,1,-1,0}; template<class T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;} template<class T> istream& operator>>(istream &is, vector<T> &v) { for (auto i = begin(v); i != end(v); i++) is>>*i;return is;} template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) { is>>p.first>>p.second;return is;} template<class T, class U> bool chmax(T &a, const U &b){return a<b?a=b,1:0;} template<class T, class U> bool chmin(T &a, const U &b){return a>b?a=b,1:0;} template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));} template<class T> using heap = priority_queue<T, deque<T>, greater<T>>; struct before_main_function { before_main_function() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << setprecision(15) << fixed; } } before_main_function; // clang-format on //------------------8<------------------------------------8<-------------------- signed main() { int N; cin >> N; vi ans; rep(i, 1, N + 1) { if (i * i > N) break; if (i * i == N) { ans.pb(i); } else if (N % i == 0) { ans.pb(i); ans.pb(N / i); } } sort(all(ans)); for (int x : ans) cout << x << endl; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> using namespace std; typedef long long ll; #define fi first #define se second #define mp make_pair #define pb push_back #define range(i, a, b, s) for (int i = (a), __##i = (b); i < __##i; i += (s)) #define down(i, a, b, s) for (int i = (a), __##i = (b); __##i < i; i += (s)) const int maxn = 1002; bool vis[maxn]; int n, a[maxn], cnt[maxn], idx = 0, prime[maxn]; template <size_t N> void prepare_primes(int& idx, int prime[N], bool vis[N]) { memset(vis, false, sizeof(bool) * N); range(i, 2, N, 1) { if (!vis[i]) { prime[idx++] = i; range(j, i + i, n, i) vis[j] = true; } } } int main() { // freopen("B.txt", "r", stdin); prepare_primes<maxn>(idx, prime, vis); while (cin >> n) { range(i, 0, n, 1) cin >> a[i]; memset(cnt, 0, sizeof(cnt)); range(i, 0, n, 1) { range(j, 0, idx, 1) { if (a[i] % prime[j] == 0) { cnt[j] += 1; } } } int ans = 1, value = 0; range(i, 0, idx, 1) { if (value < cnt[i]) { value = cnt[i]; ans = prime[i]; } } cout << ans << endl; } return 0; }
#include <iostream> #include <stdio.h> #include <cstring> #include <cstdio> #include <math.h> #include <algorithm> #include <vector> #include <string> #include <stdlib.h> #include <queue> #include <stack> #include <utility> #include <fstream> //#include <random> #include <map> //#include <unordered_map> #include <cstdlib> #include <functional> #include <time.h> //#include <chrono> #include <sstream> #include <iomanip> #include <numeric> #include <iostream> #include <limits> #include <numeric> //#include <type_traits> #define rep(i,n) for(int i=0;i<n;i++) #define rrep(i,n) for(int i=n-1;i>=0;i--) #define FOR(i,a,b) for(int i=a;i<b;i++) #define ll long long #define INF 1000000001 #define MOD 1000000007 #define SORT(s) sort(s.begin(), s.end()); #define REVERSE(s) reverse(s.begin(), s.end()); #define SUM(s) accumulate(s.begin(), s.end(), 0LL); #define P pair<int,int> #define mp make_pair #define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w) //#define int ll int dx[4] = { 0,1,0,-1 }; int dy[4] = { 1,0,-1,0 }; int ndx[8] = { 0,1,0,-1, 1,1,-1,-1 }; int ndy[8] = { 1,0,-1,0, 1,-1,-1,1 }; double pi = 3.141592653589793; using namespace std; int POW(int x, int y) { return int(pow(double(x), double(y))); } double log(double a, double b) { return log(b) / log(a); } int main() { string s; cin >> s; int n = s.size(); vector<int> a(10); rep(i, n) { a[s[i] - '0']++; } if (s.size() == 1) { if (s == "8") { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0; } if (s.size() == 2) { if ((a[0] == 1 && a[8] == 1) || (a[1] == 1 && a[6] == 1) || (a[2] == 1 && a[4] == 1) || (a[3] == 1 && a[2] == 1) || (a[4] == 1 && a[0] == 1) || (a[4] == 1 && a[8] == 1) || (a[5] == 1 && a[6] == 1) || (a[6] == 1 && a[4] == 1) || (a[7] == 1 && a[2] == 1) || (a[8] == 2) || (a[9] == 1 && a[6] == 1)) { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0; } int x = -8; while (x < 1000) { x += 8; auto str = std::to_string(x); if (str.size() == 1)str.push_back('0'); if (str.size() == 2)str.push_back('0'); auto sub = a; sub[str[0] - '0']--; if (sub[str[0] - '0'] < 0) continue; sub[str[1] - '0']--; if (sub[str[1] - '0'] < 0) continue; sub[str[2] - '0']--; if (sub[str[2] - '0'] < 0) continue; cout << "Yes" << endl; return 0; } cout << "No" << endl; return 0; }
/* AUTHOR:SOURABH CREATED:13:12:20 */ #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ordered_set tree<ll , null_type, less< ll >, rb_tree_tag, tree_order_statistics_node_update> #define ll long long int #define ld long double #define fi first #define se second #define pb push_back #define pob pop_back #define W while #define fn(i,x) for(i=0;i<x;i++) #define fs(i,s,x) for(i=s;i<x;i++) #define fr(i,x) for(i=x;i>=0;i--) #define fit(it,s) for(it=s.begin();it!=s.end();it++) #define mp make_pair #define pii pair<int,int> #define pll pair<ll,ll> #define vii vector<int> #define vll vector<ll> #define mii map<int,int> #define mll map<ll,ll> #define mod 998244353 #define MAXN 10000001 #define M 32 using namespace std; using namespace __gnu_pbds; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); //freopen("input.txt","r",stdin); //freopen("out.txt","w",stdout); ll t,n,m,tt,i,l,f,curr; t=1; //cin>>t; W(t--) { cin>>n>>m>>tt; vector<pll> a(m); fn(i,m) cin>>a[i].fi>>a[i].se; l=0; f=1; curr=n; fn(i,m) { curr-=(a[i].fi-l); if(curr<=0) {f=0;break;} curr=min(curr+(a[i].se-a[i].fi),n); l=a[i].se; } curr-=(tt-l); if(curr<=0) f=0; if(f) cout<<"Yes"; else cout<<"No"; } return 0; }
#include <bits/stdc++.h> #define endl '\n' #define fi first #define se second #define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k)) #define forn(i,n) for (int i = 0; i < (n); i++) #define forr(i,a,b) for (int i = a; i <= b; i++) #define all(v) v.begin(), v.end() #define pb(x) push_back(x) using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ii> vii; const int MX = 205; int n, mem[MX]; int x[MX], to[MX], cn; void no () { cout << "No" << endl; exit(0); } int dp (int i) { if (i == 2 * n) return 1; int &res = mem[i]; if (res != -1) return res; res = 0; for (int j = i + 1; j < 2 * n; j += 2) { int m = (i + j) / 2, f = 1, izq = 0, der = 0; int len = j - m; for (int k = i; k <= m; k++) { if (x[k] == 2) f = 0; if (x[k] == 1) { if (to[k] != -1) { if (to[k] != k + len) f = 0; } else { if (x[k + len]) f = 0; izq++; } } } for (int k = m + 1; k <= j; k++) { if (x[k] == 1) f = 0; if (x[k] == 2) { if (to[k] != -1) { if (to[k] != k - len) f = 0; } else { if (x[k - len]) f = 0; der++; } } } f &= izq + der <= len; if (f) res |= dp(j + 1); } return res; } int main () { ios_base::sync_with_stdio(0); cin.tie(0); memset(mem, -1, sizeof(mem)); memset(to, -1, sizeof(to)); cin >> n; forn (i, n) { int a, b; cin >> a >> b; a--, b--; if (a >= 0 && b >= 0 && a > b) no(); if (a >= 0) { if (x[a]) no(); x[a] = 1; if (b >= 0) to[a] = b; } if (b >= 0) { if (x[b]) no(); x[b] = 2; if (a >= 0) to[b] = a; } } if (dp(0)) cout << "Yes" << endl; else no(); return 0; }
#define _USE_MATH_DEFINES #include <iostream> //cin, cout #include <vector> //vector #include <algorithm> //sort,min,max,count #include <string> //string,getline, to_string #include <ios> //fixed #include <iomanip> //setprecision #include <utility> //swap, pair #include <cstdlib> //abs(int) #include <cmath> //sqrt,ceil,M_PI, pow, sin #include <sstream> //stringstream, getline #include <numeric> //gcd, accumlate #include <deque> //deque #include <random> //randam_device #include <limits> //numeric_limits using namespace std; constexpr long long int D_MOD = 1000000007; int main() { int a, b, c; cin >> a >> b >> c; if (a * a + b * b < c * c) { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int a, b, x, y; cin >> a >> b >> x >> y; if (a<=b){ cout << min(x+(b-a)*y, (b-a)*2*x+x) << endl; return 0; } else{ cout << min(x+(a-b-1)*y, (a-b-1)*2*x+x) << endl; return 0; } }
#include <stdio.h> #include <math.h> #include <iostream> #include <algorithm> #include <vector> #include <numeric> #include <string> #include <map> #include <set> #include <bitset> #include <queue> #include <stack> #include <memory.h> #include <iomanip> //#include <atcoder/all> //#include <bits/stdc++.h> using namespace std; typedef long long int lli; //using namespace atcoder; #define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++) #define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--) 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; } } //lli gcd2(lli x, lli y) //{ // lli t; // while (y != 0) // t = x % y, x = y, y = t; // return (x); //} // //lli lcm2(lli x, lli y) //{ // lli xy = x * y; // if (xy < 0) // xy = -xy; // return (xy / gcd2(x, y)); //} /* divisor(n) 入力:整数 n 出力:nのすべての約数 計算量:O(√n) */ vector<long long> divisor(long long n) { vector<long long> ret; for (long long i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(ret.begin(), ret.end()); // 昇順に並べる return ret; } lli eightarray[18]; void num_to_eight(int x) { lli power8 = 1; for (int i = 0; i < 18; i++) { eightarray[i] = (x / power8) % 8; power8 *= 8; } } lli n_array[18]; //N進法 void num_to_N(int x, int N) { lli powerN = 1; for (int i = 0; i < 18; i++) { n_array[i] = (x / powerN) % N; powerN *= N; } } long long gcd(long long a, long long b) { if (b == 0) { return a; } else { return gcd(b, a % b); } } /* lcm2 (a, b) : 2整数版 入力:整数 a, b 出力:aとbの最小公倍数 */ long long lcm2(long long a, long long b) { long long d = gcd(a, b); return a / d * b; } /* lcm (vec) : ベクトルでの多整数版 入力:整数のベクトル vec 出力:すべての要素の最小公倍数 */ long long lcm(const vector<long long> &vec) { long long l = vec[0]; for (int i = 0; i < vec.size() - 1; i++) { l = lcm2(l, vec[i + 1]); } return l; } int main(void) { int N; string s; cin >> N; cout << 100 - (N % 100) << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long #define all(v) (v).begin(), (v).end() signed main(){ int x; cin>>x; cout<<(x<0?0:x); }
#include <climits> #include <iostream> #include <unordered_map> #include <map> #include <vector> #include <unordered_set> #include <iomanip> #include <queue> #include <algorithm> #include <set> #include <cmath> #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #include <iostream> #include <unordered_map> #include <map> #include <vector> #include <unordered_set> #include <iomanip> #include <queue> #include <algorithm> #include <set> #include <cmath> #define MAXN 10000000 using namespace std; long long mod=998244353; int spf[MAXN]; void sieve() { spf[1] = 1; for (int i=2; i<MAXN; i++) // marking smallest prime factor for every // number to be itself. spf[i] = i; // separately marking spf for every even // number as 2 for (int i=4; i<MAXN; i+=2) spf[i] = 2; for (int i=3; i*i<MAXN; i++) { // checking if i is prime if (spf[i] == i) { // marking SPF for all numbers divisible by i for (int j=i*i; j<MAXN; j+=i) // marking spf[j] if it is not // previously marked if (spf[j]==j) spf[j] = i; } } } // A O(log n) function returning primefactorization // by dividing by smallest prime factor at every step unordered_map<int, int> getFactorization(int x) { unordered_map<int, int> factors; while (x != 1) { factors[spf[x]]++; x = x / spf[x]; } return factors; } int main(){ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); int tt=1; sieve(); long long dp[21][200001]; for(int i=20;i>=1;i--){ for(int j=200000;j>=0;j--){ if(i==20 && j==200000){ dp[i][j]=1; continue; } if(j==200000){ dp[i][j]=dp[i+1][j]; continue; } if(i==20){ dp[i][j]=(1+dp[i][j+1])%mod; continue; } dp[i][j]=(dp[i][j+1]+dp[i+1][j])%mod; } } while(tt--){ int n, m; cin>>n>>m; long long ways=1; for(int i=2;i<=m;i++){ unordered_map<int, int> factors=getFactorization(i); long curr=1; for(auto it=factors.begin();it!=factors.end();it++){ curr=(curr*dp[21-(it->second)][200001-n])%mod; } ways=(ways+curr)%mod; } cout<<ways<<endl; } } //3 4 2 1 5 6 //1 2 3
#include <bits/stdc++.h> #define endl '\n' using namespace std; using ll = long long; const int MOD = 998244353; static const int MX = 200100; ll poww(ll a, ll b) { if (b == 0) { return 1; } if (b & 1) { return (a * poww(a, b - 1)) % MOD; } return poww((a * a) % MOD, b >> 1); } ll inv(ll a) { return poww(a, MOD - 2); } ll fact[MX + 1]; ll invfact[MX + 1]; ll C(int n, int k) { return ((fact[n] * invfact[k]) % MOD * invfact[n - k]) % MOD; } int main() { ios::sync_with_stdio(false); cin.tie(0); fact[0] = 1; invfact[0] = 1; for (int i = 1; i <= MX; ++i) { fact[i] = (fact[i - 1] * i) % MOD; // there was linear time formula, but who cares invfact[i] = inv(fact[i]); } static vector<int> sieve(MX + 1); iota(sieve.begin(), sieve.end(), 0); for (int i = 2; i * i <= MX; ++i) { if (sieve[i] < i) continue; for (int j = i * i; j <= MX; j += i) { sieve[j] = i; } } int n, m; cin >> n >> m; ll gans = 0; for (int i = 1; i <= m; ++i) { ll ans = 1; int x = i; for (int cur = sieve[x]; x > 1; cur = sieve[x]) { int cnt = 0; for (; x % cur == 0; cnt++, x /= cur); ans *= C(n + cnt - 1, cnt); ans %= MOD; } gans += ans; if (gans >= MOD) { gans -= MOD; } } cout << gans << endl; }
#include <bits/stdc++.h> #include <vector> // #include <atcoder/all> // using namespace atcoder; using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); int N, M, T; cin >> N >> M >> T; vector<ll> A(M); vector<ll> B(M); for (int i = 0; i < M; i++) { cin >> A[i] >> B[i]; } int capa = N; capa -= A[0]; if (capa <= 0) { cout << "No" << endl; return 0; } capa += B[0] - A[0]; capa = min(capa, N); // cout << capa << endl; for (int i = 1; i < M; i++) { capa -= A[i] - B[i - 1]; if (capa <= 0) { cout << "No" << endl; return 0; } // cout << capa << endl; capa += B[i] - A[i]; capa = min(capa, N); // cout << capa << endl; } capa -= T - B[M - 1]; if (capa <= 0) { cout << "No" << endl; return 0; } cout << "Yes" << endl; return 0; }
#include <bits/stdc++.h> #define ll long long #define sz(x) (int)(x).size() using namespace std; //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //uniform_int_distribution<int>(1000,10000)(rng) ll binpow(ll a, ll b) { ll res = 1; while (b > 0) { if (b & 1) res = res * a; a = a * a; b >>= 1; } return res; } ll gcd(ll a,ll b) { if (b==0) return a; return gcd(b,a%b); } string to_upper(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A'; return a; } string to_lower(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A'; return a; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n,m,t,x,y,c; cin>>n>>m>>t; y=0; c=n; while (m--) { cin>>x; c-=(x-y); if (c<=0) { cout<<"No"; return 0; } cin>>y; c=min(c+y-x,n); } c-=(t-y); if (c<=0) cout<<"No"; else cout<<"Yes"; return 0; }
#include<bits/stdc++.h> using namespace std; #define endl "\n" #define ll long long int int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n; cin>>n; double D,H; cin>>D>>H; double ans=0.0; while(n--) { double d,h; cin>>d>>h; double tan=(d*(H-h))/(D-d); tan=h-tan; ans=max(ans,tan); } cout<<setprecision(15)<<fixed<<ans<<endl; return 0; }
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<long long> VL; typedef vector<vector<long long>> VVL; typedef pair<int,int> Pair; typedef tuple<int,int,int> tpl; #define ALL(a) (a).begin(),(a).end() #define SORT(c) sort((c).begin(),(c).end()) #define REVERSE(c) reverse((c).begin(),(c).end()) #define EXIST(m,v) (m).find((v)) != (m).end() #define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin() #define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin() #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i) #define RREP(i,n) RFOR(i,n,0) #define en "\n" constexpr double EPS = 1e-9; constexpr double PI = 3.1415926535897932; constexpr int INF = 2147483647; constexpr long long LINF = 1LL<<60; constexpr long long MOD = 1000000007; // 998244353; template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;} template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;} void Main(){ int N; double D,H; cin >> N >> D >> H; VI d(N),h(N); REP(i,N) cin >> d[i] >> h[i]; double ng = 0, ok = 1000; REP(_,50){ double b = (ok+ng)/2; double a = (H-b)/D; bool flag = true; REP(i,N){ if(a*d[i]+b < h[i]){ flag = false; break; } } if(flag) ok = b; else ng = b; } cout << ok << en; return; } int main(void){ cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15); int t=1; //cin>>t; while(t--) Main(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; #define eps 1e-9 #define INF 2000000000 // 2e9 #define LLINF 2000000000000000000ll // 2e18 (llmax:9e18) #define all(x) (x).begin(), (x).end() #define sq(x) ((x) * (x)) #ifndef LOCAL #define dmp(...) ; #else #define dmp(...) \ cerr << "[ " << #__VA_ARGS__ << " ] : " << dump_str(__VA_ARGS__) << endl #endif // ---------------- Utility ------------------ template <class T> bool chmin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } template <class T> bool chmax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } template <class T> using MaxHeap = priority_queue<T>; template <class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>; template <class T> vector<T> vect(int len, T elem) { return vector<T>(len, elem); } // ----------------- Input ------------------- template <class T, class U> istream &operator>>(istream &is, pair<T, U> &p) { return is >> p.first >> p.second; } template <class T> istream &operator>>(istream &is, vector<T> &vec) { for (int i = 0; i < vec.size(); i++) is >> vec[i]; return is; } // ----------------- Output ------------------ template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << p.first << ',' << p.second; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &e : v) os << e << " "; return os; } template <class T> ostream &operator<<(ostream &os, const deque<T> &d) { for (const T &e : d) os << e << " "; return os; } template <class T> ostream &operator<<(ostream &os, const set<T> &s) { os << "{ "; for (const T &e : s) os << e << " "; return os << "}"; } template <class T, class U> ostream &operator<<(ostream &os, const map<T, U> &m) { os << "{ "; for (const auto &[key, val] : m) os << "( " << key << " -> " << val << " ) "; return os << "}"; } void dump_str_rec(ostringstream &) {} template <class Head, class... Tail> void dump_str_rec(ostringstream &oss, Head &&head, Tail &&... tail) { oss << ", " << head; dump_str_rec(oss, forward<Tail>(tail)...); } template <class T, class... U> string dump_str(T &&arg, U &&... args) { ostringstream oss; oss << arg; dump_str_rec(oss, forward<U>(args)...); return oss.str(); } // --------------- Fast I/O ------------------ void fastio() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20); } // ------------ End of template -------------- #define endl "\n" ll get(int x, int y) { x = abs(x); y = abs(y); if (x == 0 && y == 0) return 0; ll ret = LLINF; for (ll i = -3; i <= 3; i++) { for (ll j = -3; j <= 3; j++) { if (abs(i) + abs(j) > 3) continue; ll nx = x - i; ll ny = y - j; if (nx == 0 && ny == 0) return 1; if (nx == ny) chmin(ret, 2ll); } } if (x == y) return 1; if ((x + y) % 2 == 0) return 2; if (ret == 2) return 2; return 3; } void solve() { ll a, b, c, d; cin >> a >> b >> c >> d; c -= a; d -= b; c = abs(c); d = abs(d); if (c == d) { cout << ((c == 0) ? 0 : 1) << endl; return; } ll ans = LLINF; for (ll i = -3; i <= 3; i++) { for (ll j = -3; j <= 3; j++) { if (abs(i) + abs(j) > 3) continue; ll nc = c + i; ll nd = d + j; ll cost = (i == 0 && j == 0) ? 0 : 1; chmin(ans, get(nc, nd) + cost); } } cout << ans << endl; return; } int main() { fastio(); solve(); // int t; cin >> t; while(t--)solve(); // int t; cin >> t; // for(int i=1;i<=t;i++){ // cout << "Case #" << i << ": "; // solve(); // } return 0; }
#include<iostream> #include<algorithm> using namespace std; int main() { int a, b, c, d; cin >> a >> b >> c >> d; if(a == c && b == d) { cout << 0; return 0; } if(a + b == c + d || a - b == c - d || abs(a - c) + abs(b - d) <= 3) { cout << 1; return 0; } if((a + b) % 2 == (c + d) % 2 || abs(a+b-c-d) <= 3 || abs(a-b-c+d) <= 3 || abs(a - c) + abs(b - d) <= 6) { cout << 2; return 0; } cout << 3; return 0; }
#pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,fma,abm,mmx,avx,avx2") #include <bits/stdc++.h> #define all(V) V.begin(),V.end() #define pi 3.1415926535897932384626 #define fi fixed<<setprecision(13) #define ll long long #define rep(i, n) for (int i = 0; i < (ll)(n); i++) #define Rep(i, n) for (ll i = 1; i <=(ll)(n); i++) #define reps(i,k,n) for (ll i = (ll)k; i < (ll)(n); i++) #define mp make_pair #define mt make_tuple using namespace std; using V = vector<vector<int>>; using Vc = vector<vector<char>>; using Vb = vector<vector<bool>>; using P = pair<int,int>; using T = tuple<int,int,int>; using Vp = vector<vector<pair<int,int>>>; template<class T> void chmin(T& a,T b){ if(a > b) a=b; } template<class T> void chmax(T& a,T b){ if(a < b) a=b; } template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill( (T*)array, (T*)(array+N), val );} const ll infll = 1LL<<61; const ll inf = 1<<30; const int dx[4] = {0, 0, -1, 1}; const int dy[4] = {1, -1, 0, 0}; struct Edge{ int to; ll w; Edge(int to,ll w) : to(to),w(w){} }; ll nck(ll a,ll b){ ll s=1,x=1; rep(i,b) s=(s*(a-i))/x,x++; return s; } using Graph = vector<vector<Edge>>; /*-------------------------------------------------------------------*/ /*-------------------------------------------------------------------*/ int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); /*----------------------------------------------------*/ int n; cin >> n; int r = 0, g = 0, b = 0; vector<pair<ll, string>> x(2 * n); rep(i, 2 * n){ ll a; string s; cin >> a >> s; if(s == "R") r++; if(s == "G") g++; if(s == "B") b++; x[i] = mp(a, s); } if(r % 2 == 0 && g % 2 == 0 && b % 2 == 0){ cout << 0 << "\n"; return 0; } sort(all(x)); ll RGmin = infll, RBmin = infll, GBmin = infll; if(r % 2 == 0){ rep(i, 2 * n - 1){ if(x[i].second != x[i+1].second ){ if(x[i].second == "R" || x[i+1].second == "R"){ if(x[i].second == "G" || x[i+1].second == "G") chmin(RGmin, abs(x[i].first - x[i+1].first)); else chmin(RBmin,abs(x[i].first - x[i+1].first)); } else chmin(GBmin,abs(x[i].first - x[i+1].first)); } } cout << min(RGmin + RBmin, GBmin) << "\n"; return 0; } if(g % 2 == 0){ rep(i, 2 * n - 1){ if(x[i].second != x[i+1].second ){ if(x[i].second == "G" || x[i+1].second == "G"){ if(x[i].second == "B" || x[i+1].second == "B") chmin(GBmin, abs(x[i].first - x[i+1].first)); else chmin(RGmin,abs(x[i].first - x[i+1].first)); } else chmin(RBmin,abs(x[i].first - x[i+1].first)); } } cout << min(GBmin + RGmin, RBmin) << "\n"; return 0; } if(b % 2 == 0){ rep(i, 2 * n - 1){ if(x[i].second != x[i+1].second ){ if(x[i].second == "B" || x[i+1].second == "B"){ if(x[i].second == "G" || x[i+1].second == "G") chmin(GBmin, abs(x[i].first - x[i+1].first)); else chmin(RBmin,abs(x[i].first - x[i+1].first)); } else chmin(RGmin,abs(x[i].first - x[i+1].first)); } } cout << min(GBmin + RBmin, RGmin) << "\n"; return 0; } } /*制約を確認しろllじゃなくて大丈夫か?*/ /* sample 保存 8 1 5 3 4 5 2 3 1 */
#include<bits/stdc++.h> using namespace std; #define dbg(x) cerr << #x << " = " << x << endl #define rep(i, a, b) for(int i = (a); i <= (b); ++ i) #define MP make_pair #define pb push_back #define fi first #define se second typedef long long LL; typedef unsigned long long u64; typedef unsigned int u32; template <typename Tp> void read(Tp &x){ x = 0; int op = 1; char ch = getchar(); while(!isdigit(ch)){ if(ch == '-') op = -1; ch = getchar(); } while(isdigit(ch)){ x = x*10+ch-'0'; ch = getchar(); } x *= op; } template <typename Tp> void CMax(Tp &x, Tp y){ if(y > x) x = y; } template <typename Tp> void CMin(Tp &x, Tp y){ if(y < x) x = y; } const int N = 1e5 + 10; int n; char s[N]; int main() { scanf("%d", &n); scanf("%s", s + 1); if(s[1] != s[n]){ printf("1"); return 0; } rep(i, 2, n - 2) { if(s[i] != s[1] && s[i + 1] != s[1]){ printf("2"); return 0; } } printf("-1"); return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll mod; ll qpow(ll a, ll n)//计算a^n % mod { ll re = 1; while(n) { if(n & 1)//判断n的最后一位是否为1 re = (re * a) %mod; n >>= 1;//舍去n的最后一位 a = (a * a) %mod;//将a平方 } return re %mod; } int main() { ll n, m; scanf("%lld %lld", &n, &m); mod=m*m; printf("%lld\n", qpow(10, n)/m); }
#include<bits/stdc++.h> #define pi 3.141592653589793238 #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #define MOD 1000000007 #define INF 999999999999999999 #define pb push_back #define ff first #define ss second #define mt make_tuple #define ll long long #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); using namespace std; #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ll power(ll x, ll y, ll p) { int res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } int main() { //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); fast; ll T = 1, i, j; //cin >> T; while (T--) { ll n, m; cin >> n >> m; n = power(10, n, m * m); ll ans = (n / m) % m; cout << ans << endl; } return 0; }
#include <bits/stdc++.h> #include <cmath> #include <unordered_set> using namespace std; using ll = long long; using vi = vector<int>; int main() { double x, y, z; cin >> x >> y >> z; double ans = 10000000; while(y/x <= ans/z){ ans--; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define forin(in ,n) for(ll i=0; i<n; 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> #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; //constexpr ll mod = 998244353; constexpr double pi = 3.14159265358979323846; 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 pt(T val) { cout << val << "\n"; } template <typename T> void pt_vll(vector<T> &v) { ll vs = v.size(); rep(i, vs) { cout << v[i]; if (i == vs - 1) cout << "\n"; else cout << " "; } } ll mypow(ll a, ll n) { ll ret = 1; if(n==0) return 1; if(a==0) return 0; rep(i, n) { if (ret > (ll)(1e18 + 10) / a) return -1; ret *= a; } return ret; } 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; } long long modinv(long long a, long long m) { long long b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } vector<ll> enum_div(ll n){ //約数全列挙 vector<ll> ret; for(ll i = 1 ; i*i <= n ; ++i){ if(n%i == 0){ ret.push_back(i); if(i != 1 && i*i != n){ ret.push_back(n/i); } } } return ret; } int main() { ll z,y,x,ans=INF; cin>>x>>y>>z; ans=(z*y-1)/x; cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> P; const ll mod=998244353; #define rep(i,n) for (int i = 0; i < (n); i++) int n,m; ll dp[10000]; ll fac[5100], finv[5100], inv[5100]; void COMinit(int n) { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < n; i++){ fac[i] = fac[i - 1] * i % mod; inv[i] = mod - inv[mod%i] * (mod / i) % mod; finv[i] = finv[i - 1] * inv[i] % mod; } } ll COM(int n, int k){ if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % mod) % mod; } int main(){ COMinit(5100); cin >> n >> m; dp[0]=1; for(int i=1;i<=m;i++){ if(i%2==1)continue; for(int j=0;j<=n && j<=i;j+=2){ dp[i]+=dp[(i-j)/2]*COM(n,j); dp[i]%=mod; } } cout << dp[m] << endl; return 0; }
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int mod=998244353; inline int addmod(int x) { return x>=mod?x-mod:x; } int n,m,c[5005][5005],f[105][5005],pn=5e3; int main() { for(int i=0;i<=pn;i++) c[i][0]=1; for(int i=1;i<=pn;i++) for(int j=1;j<=pn;j++) c[i][j]=addmod(c[i-1][j-1]+c[i-1][j]); scanf("%d%d",&n,&m); for(int i=0;i<=min(m,n);i+=2) f[0][m-i]=c[n][i]; for(int i=0;i<=14;i++) { for(int k=0;k<=m;k+=2) { int nw=k/2; for(int j=0;j<=min(n,nw);j+=2) f[i+1][nw-j]=addmod(f[i+1][nw-j]+1ll*f[i][k]*c[n][j]%mod); } } printf("%d\n",f[15][0]); return 0; }
/**Bismillahir Rahmanir Rahim.**/ /* Md.Fagun Molla 18ICTCSE006 BSMRSTU(SHIICT) */ #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; using ll=long long; using db=double; ///***************************************************** CONSTANTS ******************************************************/// int const N=1e7+3; ll MOD=1e9+7,fact[N]; const long long inf=(long long)1e18; const long double PI=3.14159265358979; ///************************************************ CONTAINER DEFINITIONS ***********************************************/// typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int,int> pii; typedef pair<ll, ll> pll; typedef vector<pii> vii; typedef vector<pll> vll; ///************************************************ SHORT FORM KEYWORDS *************************************************/// #define PB push_back #define F first #define S second #define MP make_pair #define I insert #define lb lower_bound #define ub upper_bound #define endl '\n' ///************************************************ SHORT FORM FUNCTIONS ************************************************/// #define loop(a,b) for(ll i=a;i<b;i++) #define loopr(a,b) for(ll i=a-1;i>=b;i--) #define mem(a,b) memset(a, b, sizeof(a) ) #define gcd(a,b) __gcd(a,b) #define lcm(a,b) (a*(b/gcd(a,b))) #define sa(v) sort(v.begin(),v.end()) #define sd(v) sort(v.begin(),v.end(),greater<>()) #define rev(s) reverse(s.begin(),s.end()) #define stll(x) stoll(x, nullptr, 10); #define yes cout<<"YES"<<endl; #define no cout<<"NO"<<endl; #define mx(a) *max_element(all(a)) #define mn(a) *min_element(all(a)) #define all(a) a.begin(),a.end() #define mxa(a,N) *max_element(a,a+N) #define mna(a,N) *min_element(a,a+N) #define print(a) {for(auto x:a)cout<<x<<" ";cout<<endl;} #define io() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); ///************************************************ SOLUTION STARTS HERE ************************************************/// ///======================================================================================================================/// void solve(){ ll a,b,c,d; cin>>a>>b>>c>>d; if(a+b==c+d || a+c==b+d || a+d==b+c || a==b+c+d || b==a+c+d || c==a+b+d || d==a+b+c) cout<<"Yes"<<endl; else cout<<"No"<<endl; } int main() { io(); int T=1;//cin>>T; while(T--) solve(); return 0; } /****************ALHAMDULILLAH******************/
#include<bits/stdc++.h> using namespace std; #define db(a) cout<<#a<<"="<<(a)<<'\n'; #define DB(a) {cout<<#a<<"里的元素为 ";for(auto x:a)cout<<x<<' ';cout<<'\n';} #define DBB(a) {cout<<#a<<"里的元素为 ";for(auto x:a)cout<<x.first<<' '<<x.second<<" ";cout<<'\n';} #define bb begin() #define ee end() #define ss size() #define pb push_back #define te int t;cin>>t;while(t--) using ll=long long; int h,w,a,b,ans; void dfs(int s,int pos,int a,int b){ if(s==h*w){ans++;return;} if(1<<s&pos){return dfs(s+1,pos,a,b);} if(b>0)dfs(s+1,pos|1<<s,a,b-1); if(a>0){ if(s%w<w-1)dfs(s+1,pos|1<<s|1<<(s+1),a-1,b); if(s+w<h*w)dfs(s+1,pos|1<<s|1<<(s+w),a-1,b); } } int main(){ ios::sync_with_stdio(false);cin.tie(0); cin>>h>>w>>a>>b; dfs(0,0,a,b); cout<<ans; }
/* * Author: Kewth * Date: echo -n ' ' && date +%Y.%m.%d # Type "!!sh" in Vim. * Solution: To be updated after "Accept". * Digression: * CopyRight: __ __ __ __ | |/ |.-----.--.--.--.| |_| |--. | < | -__| | | || _| | |__|\__||_____|________||____|__|__| */ #include <cstdio> #include <algorithm> #define debug(...) fprintf(stderr, __VA_ARGS__) typedef long long ll; static struct { inline operator int () { int x; return scanf("%d", &x), x; } inline operator ll () { ll x; return scanf("%lld", &x), x; } template<class T> inline void operator () (T &x) { x = *this; } template<class T, class ...A> inline void operator () (T &x, A &...a) { x = *this; this -> operator () (a...); } } read; const int maxn = 3030, mod = 998244353; ll f[maxn][maxn << 1]; int main () { int n = read, m = read; f[0][0] = 1; for (int i = 1; i <= n; i ++) for (int j = i; j; j --) { f[i][j] = (f[i - 1][j - 1] + f[i][j << 1]) % mod; /* g[i][j] = (g[i - 1][j - 1] + f[i][j]) % mod; */ } printf("%lld\n", f[n][m]); /* for (int i = 1; i <= n; i ++) { */ /* for (int j = 1; j <= i; j ++) */ /* debug(" %lld", f[i][j]); */ /* debug("\n"); */ /* } */ }
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <cfloat> #include <chrono> #include <climits> #include <cmath> #include <cstdio> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; template <class T1, class T2> ostream& operator << (ostream& out, const pair <T1, T2> p) { out << '(' << p.first << ',' << p.second << ')'; return out; } template <class T1, class T2> istream& operator >> (istream& in, pair<T1, T2> &p) { in >> p.first >> p.second; return in; } template <class T> istream& operator >> (istream& in, vector<T> &v) { for (T &x : v) in >> x; return in; } template <class T> ostream& operator << (ostream& out, const vector<vector<T>> &v) { for (const vector<T> &x : v) out << x << '\n'; return out; } template <class T> ostream& operator << (ostream& out, const vector<T> &v) { for (const T &x : v) out << x << ' '; return out; } long long gcd (long long a, long long b) { if (b > a) swap(a, b); return (b ? gcd(b, a % b) : a); } using ll = long long; using pii = pair<int, int>; using pll = pair<long long, long long>; using tiii = pair<pair<int, int>, int>; using vi = vector<int>; using vl = vector<long long>; using vvi = vector<vector<int>>; using vvl = vector<vector<long long>>; #define F first #define S second #define First first.first #define Second first.second #define Third second #define mp make_pair #define rep(i,a,b) for (int i = (a); i < (b); i++) #define per(i,b,a) for (int i = (b); i > (a); i--) #define all(x) x.begin(), x.end() #define ret(x) return cout << x, 0; #define throwex throw runtime_error ("Found the error."); const int h = 998244353; signed main() { ios::sync_with_stdio(false); #ifdef ONLINE_JUDGE cin.tie(nullptr); cerr.setstate(ios::failbit); #endif int n, k; cin >> n >> k; ll x = 1; while(n >= k * x * 2) x *= 2; vvl dp(n + 1, vl(n + 1)); dp[0][0] = 1; rep(j, 1, n + 1) { rep(i, 1, n + 1) { ll z = 1; while(i * z - 1 <= n) { (dp[i][j] += dp[i * z - 1][j - 1]) %= h; z *= 2; } } } cout << dp[k][n]; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) using pii = pair<int, int>; using vi = vector<int>; using vii = vector<vi>; using ll = long long; int main() { ll r, x, y; cin >> r >> x >> y; ll distance; distance = x*x + y*y; ll ans = 1; while(1) { if (r*r*ans*ans >= distance) break; ans++; } if (ans == 1) { if (r*r != distance) { cout << 2 << endl; return 0; } } cout << ans << endl; return 0; }
//Code Written by Pinaki Bhattacharjee #include<bits/stdc++.h> using namespace std; // typedef typedef long long ll; typedef long double ld; typedef unsigned int uint; typedef unsigned long long ull; // #define #define LOCAL #define INF 1e18 #define MAX 10000 #define PI 2*acos(0.0) #define endl "\n" #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define ppc __builtin_popcountll #define pinakipb2 ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); // constants const int MOD = (int) 1e9 + 7; // debugger #ifdef LOCAL #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) #else #define trace(...) 42 #endif template <typename Arg1> void __f(const char* name, Arg1&& arg1){ cerr << name << ": " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << ": " << arg1 << " | "; __f(comma + 1, args...); } /*--------------------------------------------------------------------------------------------------------------------------*/ #ifndef ONLINE_JUDGE #define debug(x) cerr << #x << " "; _print(x); cerr << endl; #else #define debug(x); #endif void _print(ll t) {cerr << t;} void _print(int t) {cerr << t;} void _print(string t) {cerr << t;} void _print(char t) {cerr << t;} void _print(ld t) {cerr << t;} void _print(double t) {cerr << t;} void _print(ull t) {cerr << t;} template <class T, class V> void _print(pair <T, V> p); template <class T> void _print(vector <T> v); template <class T> void _print(set <T> v); template <class T, class V> void _print(map <T, V> v); template <class T> void _print(multiset <T> v); template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";} template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} void google(int t) {cout << "Case #" << t << ": ";} ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;} ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} /*--------------------------------------------------------------------------------------------------------------------------*/ int main() { pinakipb2; #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); freopen("error.txt","w",stderr); #endif // Code begins ll r,x,y; cin>>r>>x>>y; ll ans = ceil(sqrt((x*x)+(y*y))); if(x==0 && y==0) { cout<<0<<endl; } else if(ans<r) { cout<<2<<endl; } else if(ans%r==0) { cout<<ans/r<<endl; } else { cout<<ans/r+1<<endl; } // Code ends return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int n,m; cin>>n>>m; vector<int> g(n); for(int i=0;i<m;i++){ int a,b; cin>>a>>b; a--;b--; g[a]|=1<<b; g[b]|=1<<a; } if(m==0){ cout<<n<<endl; return 0; } vector<int> dp(1<<n,n+1); dp[0]=1; for(int i=0;i<n;i++){ for(int j=0;j<(1<<n);j++){ if(dp[j]==1&&(g[i]&j)==j)dp[j|(1<<i)]=1; } } for(int i=0;i<(1<<n);i++){ for(int j=i;--j&=i;){ dp[i]=min(dp[i],dp[i^j]+dp[j]); } } cout<<dp.back()<<endl; }
#include<bits/stdc++.h> using namespace std; #define ALL(x) begin(x),end(x) #define rep(i,n) for(int i=0;i<(n);i++) #define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; #define mod 1000000007 using ll=long long; const int INF=1000000000; const ll LINF=1001002003004005006ll; int dx[]={1,0,-1,0},dy[]={0,1,0,-1}; // ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;} template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;} struct IOSetup{ IOSetup(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(12); } } iosetup; template<typename T> ostream &operator<<(ostream &os,const vector<T>&v){ for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==(int)v.size()?"":" "); return os; } template<typename T> istream &operator>>(istream &is,vector<T>&v){ for(T &x:v)is>>x; return is; } signed main(){ int n,m;cin>>n>>m; vector<vector<int>> g(n,vector<int>(n,false)); rep(i,m){ int u,v;cin>>u>>v;u--,v--; g[u][v]=true; g[v][u]=true; } vector<int> dp(1<<n,INF); dp[0]=0; for(int bit=1;bit<(1<<n);bit++){ bool f=true; for(int i=0;i<n and f;i++)if((bit>>i)&1){ for(int j=i+1;j<n and f;j++)if((bit>>j)&1){ if(!g[i][j])f=false; } } if(f){ dp[bit]=1; // cout<<bit<<" "<<1<<endl; } } for(int bit=1;bit<(1<<n);bit++){ //部分集合bitの部分集合subsetの列挙 int subset=bit; do{ //処理 if(subset!=bit){ chmin(dp[bit],dp[subset]+dp[bit^subset]); } //次の集合計算↓ subset=(subset-1)&bit; }while(subset!=bit);//0の次,-1&bit=bitなので終わり } cout<<dp[(1<<n)-1]<<endl; return 0; }
//@Author: KeinYukiyoshi // clang-format off #include <bits/stdc++.h> //#pragma GCC optimize("Ofast") //#pragma GCC target("avx") #define int long long using namespace std; #define stoi stoll #define fi first #define se second #define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; i++) #define rep2(i, a, b) for (int i = (int)(a), i##_len=(b); i < i##_len; i++) #define rep3(i, a, b) for (int i = (int)(a), i##_len=(b); i >= i##_len; i--) #define FOR(i, a) for (auto &i: a) #define ALL(obj) begin(obj), end(obj) #define _max(x) *max_element(ALL(x)) #define _min(x) *min_element(ALL(x)) #define _sum(x) accumulate(ALL(x), 0LL) const int MOD = 1000000007; // const int MOD = 998244353; const int INF = 10000000000007; // 1e13 + 7 const int INF2 = LLONG_MAX; // 9.2e18 const double EPS = 1e-8; const double PI = 3.14159265358979; template <class T> using V = vector<T>; template <class T> using VV = vector<vector<T>>; template <class T> using VVV = vector<vector<vector<T>>>; template <class T, class S> using P = pair<T, S>; template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b;return true;}return false;} template<class T> bool chmin(T &a, const T &b) {if (b < a) {a = b;return true;}return false;} int _ceil(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); } template<class T> T chmod(T &a, T mod=MOD) {a = a >= 0 ? a % mod : a - (mod * _ceil(a, mod)); return a;}; int _mod(int a, int mod=MOD) {return a >= 0 ? a % mod : a - (mod * _ceil(a, mod));} int _pow(int a, int b) {int res = 1;for (a %= MOD; b; a = a * a % MOD, b >>= 1)if (b & 1) res = res * a % MOD;return res;} struct mint {long long x;mint(long long x = 0) : x((x % MOD + MOD) % MOD) {}mint operator-() const { return mint(-x); }mint &operator+=(const mint a) {if ((x += a.x) >= MOD) x -= MOD;return *this;}mint &operator-=(const mint a) {if ((x += MOD - a.x) >= MOD) x -= MOD;return *this;}mint &operator*=(const mint a) { (x *= a.x) %= MOD;return *this; }mint operator+(const mint a) const { return mint(*this) += a; }mint operator-(const mint a) const { return mint(*this) -= a; } mint operator*(const mint a) const { return mint(*this) *= a; }mint pow(long long t) const {if (!t) return 1;mint a = pow(t >> 1);a *= a;if (t & 1) a *= *this;return a;}mint inv() const { return pow(MOD - 2); }mint &operator/=(const mint a) { return *this *= a.inv(); }mint operator/(const mint a) const { return mint(*this) /= a; }};istream &operator>>(istream &is, mint &a) { return is >> a.x; }ostream &operator<<(ostream &os, const mint &a) { return os << a.x; } // clang-format on class ALongCommonSubsequence { public: static void solve(istream &cin, ostream &cout) { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); int t; cin >> t; rep(_, t) { int N; string S1, S2, S3; cin >> N >> S1 >> S2 >> S3; cout << string(N, '0') + string(N, '1') + '0' << endl; } } }; signed main() { ALongCommonSubsequence solver; std::istream& in(std::cin); std::ostream& out(std::cout); solver.solve(in, out); return 0; }
#include <bits/stdc++.h> #define ll long long #define vi vector<int> #define vll vector<long long> #define pii pair<int,int> #define pll pair<ll,ll> #define sll set<long long> #define si set<int> #define sti stack<int> #define stkl stack<ll> #define qi queue<int> #define pb push_back #define ff first #define ss second #define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); const ll mod=1e9+7; using namespace std; int c=0; ll pow(ll a,ll b){ if(b==0) return 1; ll ans=pow(a,b/2)*pow(a,b/2); if(b&1) return a*ans; return ans; } ll gcd(ll a,ll b){ if(b==0) return a; return gcd(b,a%b); } ll nCr(ll n,ll r){ vll a(r+1); a[0]=1; while(--n){ for(int i=r-1;i>=0;i--) a[i+1]+=a[i]; } return a[r]; } void solve(){ int n; cin>>n; vector<pii> a(1<<n); map<int,int> ma; for(int i=0,x;i<(1<<n);i++){ cin>>x; a[i]={x,i+1}; } for(int i=0;i<n-1;i++){ int m=a.size(); vi b; for(int j=0;j<m-1;j+=2){ if(a[j].ff<=a[j+1].ff){ b.pb(j); } else{ b.pb(j+1); } } int l=0; for(auto k:b){ // cout<<k<<" "; a.erase(a.begin()+k-l); l++; } } sort(a.begin(), a.end()); // for(auto i:a) // cout<<i.ff<<" "<<i.ss<<endl; cout<<a[0].ss<<endl; } int main(){ IOS; int q=1; //cin>>q; while(q--){ c++; solve(); } }
#include<bits/stdc++.h> using namespace std; int main() { int n; cin >> n; n *= 1.08; if(n < 206) { cout << "Yay!" << endl; } else if(n == 206) { cout << "so-so" << endl; } else { cout << ":(" << endl; } return 0; }
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define int long long #define read(a) for(auto &z : a) cin >> z; #define write(a) {for(auto &z : a) cout << z << ' ';cout << '\n';} #define print(a) cout << a << "\n"; #define all(a) a.begin(), a.end() pair<int, int> mov[4] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); int _ = 1, n, m; // cin >> _; outer : while(_--) { cin >> n; int num = floor(n * 1.08); if(num < 206) { cout << "Yay!\n"; } else if(num == 206) { cout << "so-so\n"; } else { cout << ":(\n"; } } return 0; }
#include <iostream> #include <vector> #include <algorithm> #include <string> #include <numeric> #include <utility> #include <tuple> #define REP(i, a, b) for (int i = int(a); i < int(b); i++) using namespace std; using ll = long long int; using P = pair<ll, ll>; // clang-format off #ifdef _DEBUG_ #define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false) template<typename T> void PPPPP(T t) { cerr << t; } template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); } #else #define dump(...) do{ } while(false) #endif template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); } template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); } template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; } template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; } template<typename T> void print(T a) { cout << a << '\n'; } template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); } template<typename T> istream &operator,(istream &in, T &t) { return in >> t; } // clang-format on template<ll MOD = 1000000007> class ModInt { ll n; ModInt constexpr inverse() const { return ModInt::pow(*this, MOD - 2); } public: ModInt() : n(0) {} ModInt(ll _n) : n(((_n % MOD) + MOD) % MOD) {} ModInt operator+=(const ModInt &m) { n += m.n; if (n >= MOD) n -= MOD; return *this; } ModInt operator-=(const ModInt &m) { n -= m.n; if (n < 0) n += MOD; return *this; } ModInt operator*=(const ModInt &m) { n *= m.n; if (n >= MOD) n %= MOD; return *this; } ModInt operator/=(const ModInt &m) { (*this) *= m.inverse(); return *this; } friend ModInt operator+(ModInt t, const ModInt &m) { return t += m; } friend ModInt operator-(ModInt t, const ModInt &m) { return t -= m; } friend ModInt operator*(ModInt t, const ModInt &m) { return t *= m; } friend ModInt operator/(ModInt t, const ModInt &m) { return t /= m; } ModInt operator=(const ll l) { n = l % MOD; if (n < 0) n += MOD; return *this; } friend ostream &operator<<(ostream &out, const ModInt &m) { out << m.n; return out; } friend istream &operator>>(istream &in, ModInt &m) { ll l; in >> l; m = l; return in; } static constexpr ModInt pow(const ModInt x, ll p) { ModInt<MOD> ans = 1; for (ModInt<MOD> m = x; p > 0; p /= 2, m *= m) { if (p % 2) ans *= m; } return ans; } }; using mint = ModInt<998244353>; mint operator"" _m(unsigned long long m) { return mint(m); } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); ll a, b, c; cin, a, b, c; mint ans = 1_m * a * (a + 1) / 2 * 1_m * b * (b + 1) / 2 * 1_m * c * (c + 1) / 2; print(ans); return 0; }
#include "bits/stdc++.h" using namespace std; #include "string" #define int long long #define pi pair <int, int> #define ff first #define ss second #define boost ios::sync_with_stdio(false);cin.tie(nullptr) #define endl '\n' #define vi vector<int> const int M = 998244353; int mod(int m, int mod = M) { m %= mod; return (m + mod) % mod; } int32_t main() { boost; int a, b, c; cin >> a >> b >> c; int aa = a * (a + 1) / 2; aa = mod(aa); int bb = b * (b + 1) / 2; bb = mod(bb); int ans = c * (c + 1) / 2; ans = mod(ans); ans = mod(ans * aa); ans = mod(ans * bb); cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int n, m, a, b, db=1; string s[100]; int main() { cin >> n >> m >> a >> b; a--, b--; for (int i=0; i<n; i++) { cin >> s[i]; } for (int j=b-1; j>=0; j--) { if (s[a][j]=='.') { db++; } else { break; } } for (int j=b+1; j<m; j++) { if (s[a][j]=='.') { db++; } else { break; } } for (int i=a-1; i>=0; i--) { if (s[i][b]=='.') { db++; } else { break; } } for (int i=a+1; i<n; i++) { if (s[i][b]=='.') { db++; } else { break; } } cout << db << "\n"; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main() { int w,h,x,y,i,j,s=0,k; cin>>h>>w>>x>>y; char a[h][w]; for(i=0;i<h;i++){ for(j=0;j<w;j++){ cin>>a[i][j]; } } for(i=x-1;i<x;i++){ for(j=y-1;j<y;j++){ for(k=j+1;k<w;k++){ //cout<<k<<" "<<i<<endl; if(a[i][k]=='.') s++; else break; } //cout<<s<<endl; for(k=j-1;k>=0;k--){ if(a[i][k]=='.') s++; else break; } //cout<<s<<endl; for(k=i+1;k<h;k++){ if(a[k][j]=='.') s++; else break; } //cout<<s<<endl; for(k=i-1;k>=0;k--){ if(a[k][j]=='.') s++; else break; } //cout<<s<<endl; } } cout<<s+1<<endl; }
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "/debug.h" #else #define db(...) #endif #define all(v) v.begin(), v.end() #define pb push_back using ll = long long; const int NAX = 2e5 + 5, MOD = 1000000007; const string FIRST = "First"; const string SECOND = "Second"; auto solveCase(int n, const vector<int64_t> &a) { // TODO: edit here if (n % 2) return SECOND; map<int, int> cnt; for (auto &x : a) cnt[x]++; for (auto &x : cnt) { if(x.second % 2) return FIRST; } return SECOND; } // generated by oj-template v4.7.2 (https://github.com/online-judge-tools/template-generator) int main() { #ifndef LOCAL std::ios::sync_with_stdio(false); std::cin.tie(nullptr); #endif constexpr char endl = '\n'; // failed to analyze input format // TODO: edit here int t, n; cin >> t; for (size_t i = 0; i < t; i++) { cin >> n; vector<int64_t> a(n); for (int i = 0; i < n; ++i) cin >> a[i]; auto ans = solveCase(n, a); cout << ans << '\n'; } return 0; }
#include<iostream> #include<algorithm> using namespace std; int solve(){ int n; scanf("%d",&n); int a[n]; for(int i=0;i<n;i++) scanf("%d",a+i); if(n%2){ puts("Second"); return 0; } sort(a,a+n); for(int i=0;i<n;){ int st=0; while(st+i<n and a[st+i]==a[i]) st++; if(st&1){ puts("First"); return 0; } i+=st; } puts("Second"); return 0; } int main(){ int t; cin>>t; while(t--) solve(); }
#include<bits/stdc++.h> using namespace std ; #define long long ll #define mod 1000000007 int main () { string str ; cin >> str ; int count=0 ; for (int i=0;i<=(str.length()-4);i++) { if(str[i]=='Z') { if(str[i+1]=='O'&&str[i+2]=='N'&&str[i+3]=='e') count++; } } cout<<count<<"\n"; }
#include <bits/stdc++.h> #define ll long long int #define w(t) int t; cin>>t; while(t--) #define F first #define S second #define pb push_back #define mp make_pair #define pii pair<int,int> #define mii map<int,int> #define sp(x,y) fixed<<setprecision(y)<<x using namespace std; int countFreq(string &pat, string &txt) { int M = pat.length(); int N = txt.length(); int res = 0; for (int i = 0; i <= N - M; i++) { int j; for (j = 0; j < M; j++) if (txt[i+j] != pat[j]) break; if (j == M) { res++; j = 0; } } return res; } int main() { ios::sync_with_stdio(false); cin.tie(0); string s,a="ZONe"; cin>>s; cout << countFreq(a, s); return 0; }
#include <bits/stdc++.h> using namespace std ; typedef long long ll ; typedef pair<ll,int> P ; #define MAX_M (ll)100 #define MAX_N 100000 int n , m , X , Y ; struct edge { ll cost ; ll limit ; int to ; }; vector<edge> G[100000] ; ll d[100000] ; ll djikstra(int s , int t){ fill(d,d+n,LLONG_MAX) ; d[s] = 0 ; priority_queue<P,vector<P>,greater<P>> que ; que.push(P(0,s)) ; while(!que.empty()){ P p = que.top() ; que.pop() ; int v = p.second ; if(p.first > d[v]) continue ; for(int i = 0 ; i < G[v].size() ; i++){ edge e = G[v][i] ; if(d[v] % e.limit == 0){ if(d[e.to] > d[v] + e.cost){ d[e.to] = d[v] + e.cost ; que.push(P(d[e.to],e.to)) ; } } else{ ll mod = d[v] / e.limit + 1 ; if(d[e.to] > mod * e.limit + e.cost){ d[e.to] = mod * e.limit + e.cost ; que.push(P(d[e.to],e.to)) ; } } } } return d[t] ; } int main(){ cin >> n >> m >> X >> Y ; for(int i = 0 ; i < m ; i++){ int A , B ; ll tim , k ; cin >> A >> B >> tim >> k ; edge E , F ; E.to = B - 1 ; E.cost = tim ; E.limit = k ; F.to = A - 1 ; F.cost = tim ; F.limit = k ; G[A-1].push_back(E) ; G[B-1].push_back(F) ; } ll ans = djikstra(X-1,Y-1) ; if(ans == LLONG_MAX) cout << -1 << endl ; else cout << ans << endl ; }
#include <iostream> #include <cstdio> #include <string> #include <algorithm> #include <utility> #include <cmath> #include <vector> #include <stack> #include <queue> #include <deque> #include <set> #include <map> #include <tuple> #include <numeric> #include <functional> using namespace std; typedef long long ll; typedef vector<ll> vl; typedef vector<vector<ll>> vvl; typedef pair<ll, ll> P; #define rep(i, n) for(ll i = 0; i < n; i++) #define exrep(i, a, b) for(ll i = a; i <= b; i++) #define out(x) cout << x << endl #define exout(x) printf("%.10f\n", x) #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define pb push_back #define re0 return 0 const ll mod = 1000000007; const ll INF = 1e16; struct Edge { ll to, cost, D; Edge(ll to, ll cost, ll D): to(to), cost(cost), D(D) {} }; struct Data { ll v, x; // いまいる頂点v, 進んだ距離x Data(ll v, ll x): v(v), x(x) {} bool operator<(const Data& hoge) const { return x > hoge.x; } }; ll ceil(ll a, ll b) { // a÷b以上の最小の整数 if(b == 0) { return 0; } return (a+b-1)/b; } int main() { ll n, m, sv, gv; cin >> n >> m >> sv >> gv; sv--; gv--; vector<vector<Edge>> G(n); rep(i, m) { ll a, b, c, d; cin >> a >> b >> c >> d; a--; b--; G[a].emplace_back(b, c, d); G[b].emplace_back(a, c, d); } vl dp(n, INF); // dp[v] : 頂点vまでの距離の最小値 priority_queue<Data> Q; auto push = [&](ll v, ll x) { if(dp[v] <= x) { return; } dp[v] = x; Q.emplace(v, x); }; // ダイクストラ法。計算量はO((V+E)*log(V)) push(sv, 0); while(!Q.empty()) { Data hoge = Q.top(); Q.pop(); ll v = hoge.v, x = hoge.x; if(dp[v] != x) { continue; } for(Edge e : G[v]) { ll u = e.to; ll c = e.cost; ll d = e.D; push(u, d*ceil(x, d) + c); } } if(dp[gv] == INF) { out(-1); } else { out(dp[gv]); } re0; }
#include <bits/stdc++.h> using ll = long long; using namespace std; #define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++) #define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++) #define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--) #define rreps(i, n) for (int i = ((int)(n)); i > 0; i--) #define repi(i, x) \ for (auto i = (x).begin(), i##_fin = (x).end(); i != i##_fin; i++) #define all(x) (x).begin(), (x).end() #define F first #define S second #define mp make_pair #define mt make_tuple #define pb push_back #define eb emplace_back typedef vector<int> Vi; typedef vector<Vi> VVi; typedef pair<int, int> Pi; typedef vector<Pi> VPi; typedef vector<long long> V; typedef vector<V> VV; typedef pair<long long, long long> P; typedef vector<P> VP; template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << "(" << p.first << " " << p.second << ")"; return os; } template <class T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i, v.size()) { if (i) os << " "; os << v[i]; } return os; } template <class T, class U> istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; } template <class T> istream& operator>>(istream& is, vector<T>& v) { rep(i, v.size()) { is >> v[i]; } return is; } const long long INFLL = 1LL << 60; const int INF = 1 << 30; const double PI = acos(-1); #ifdef LOCAL #define dbg(x) cerr << #x << ": " << (x) << '\n' #define say(x) cerr << (x) << '\n' #else #define dbg(x) #define say(x) #endif string solve(bool a) { return ((a) ? "Yes" : "No"); } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; int ans = 0; cin >> n; Vi a(n); cin >> a; int down = INF; rep(i, n) { down = INF; for (int j = i; j < n; j++) { chmin(down, a[j]); chmax(ans, down * (j - i + 1)); } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define fast ios::sync_with_stdio(0);cin.tie(0); #define ll long long int #define INFL 1e18L #define INF 2e9 #define nl '\n' #define ld long double #define precision(x) fixed << setprecision(x) const ll mod = 998244353; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b , a % b); } ll powm(ll a, ll b) { ll res = 1; while (b) { if (b & 1) res = (res * 1LL * a) % mod; b >>= 1LL; a = (a * 1LL * a) % mod; } return res; } const int N = 2e5 + 5; const int M = 10; //--------------------------------------------------------------------------------------------------------------------------// void solve() { int n; cin >> n; ll mn[n][n]; ll a[n]; for (int i = 0; i < n; i++) cin >> a[i]; ll ans = 0; for (int len = 1; len <= n; len++) { for (int i = 0; i <= n - len; i++) { int j = i + len - 1; if (i == j) { mn[i][j] = a[i]; ans = max(ans, mn[i][j]); } else { mn[i][j] = min(a[j], mn[i][j - 1]); ans = max(ans, mn[i][j] * len); } } } cout << ans << nl; } int main() { fast #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int tc = 1; // cin >> tc; int _ = 0; while (_++ < tc) { solve(); } return 0; }
#include <iostream> using namespace std; int N; long long int A[1000006], B[1000006]; int main(void) { cin >> N; for (int i = 1; i <= N; i++) { cin >> A[i]; } for (int i = 1; i <= N; i++) { cin >> B[i]; } long long int ans = 0; for (int i = 1; i <= N; i++) { ans += A[i] * B[i]; } if (ans == 0) { cout << "Yes"<<endl;} else { cout << "No" << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> #define ll long long #define pb push_back #define mp make_pair #define endl "\n" #define int ll #define vi vector<int> #define vb vector<bool> #define vvb vector<vb > #define pii pair<int,int> #define ss second #define ff first #define vpii vector<pii> #define vvi vector<vi > #define vs vector<string> #define vvs vector<vs > #define pqi priority_queue <int> #define minpqi priority_queue <int, vector<int>, greater<int> > #define all(x) x.begin(),x.end() #define mii map<int,int> #define for0(i,n) for(ll i=0;i<n;i++) #define for1(i,n) for(ll i=1;i<=n;i++) #define per(i,n) for(ll i=n-1;i>=0;i--) #define per1(i,n) for(ll i=n;i>0;i--) #define repeat(i,start,n) for(ll i=start;i<n;i++) #define inp(arr,n) ll arr[n];rep(i,n){ cin>>arr[i];} #define inp1(arr,n) ll arr[n+1];rep1(i,n){ cin>>arr[i];} #define inp2d(arr,n,m) ll arr[n][m];rep(i,n)rep(j,m)cin>>arr[i][j]; #define inpg(adj,m) rep(i,m){int a,b;cin>>a>>b;adj[a].pb(b);adj[b].pb(a);} #define print(a,n) for(ll i=0;i<n;i++){ cout<<a[i]<<" ";} #define print1(a,n) for(ll i=1;i<=n;i++){ cout<<a[i]<<endl;} #define mod 1000000007 #define maxx 1000000000000000000 #define PI 3.141592653589793238462643383279 #define mmax(a,b,c) max(a,max(b,c)) #define mmin(a,b,c) min(a,min(b,c)) #define init(arr,a) memset(arr,a,sizeof(arr)) #define lb lower_bound #define ub upper_bound #define er equal_range #define maxe *max_element #define mine *min_element //------------------------------------Code Starts here------------------------------------// void solve() { int n; cin>>n; int a[n],b[n]; for0(i,n)cin>>a[i]; for0(i,n)cin>>b[i]; int sum=0; for0(i,n) { sum+=a[i]*b[i]; } if(sum==0)cout<<"Yes"<<endl; else cout<<"No"<<endl; return; } signed main() { int t=1; //cin>>t; while(t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; #define forn(i, n) for (int i = 0; i < (n); i++) #define pb push_back #define mp make_pair #define MOD 1000000007 #define f first #define s second #define rand(i, j) uniform_int_distribution<ll>((ll)(i), (ll)(j))(rng) mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count()); typedef long long ll; typedef double ld; typedef long double lld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<bool> vb; typedef vector<pii> vpi; typedef vector<pll> vpl; typedef vector<vi> vii; //Printing pairs and vectors template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; } template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) { cout << "["; for (int i = 0; i < (int)v.size(); i++) {if (i) cout << ", "; cout << v[i]; } return cout << "]"; } //2 147 483 647 int max //9 223 372 036 854 775 807 ll max int main(){ cin.tie(0)->sync_with_stdio(0); int n; string s; cin >> n >> s; if(s.at(0) != s.at(n-1)){ cout << 1 << "\n"; }else{ for(int i=1; i<n-1; i++){ if(s.at(i) != s.at(0) && s.at(i+1) != s.at(0)){ cout << 2 << "\n"; return 0; } } cout << -1 << "\n"; } }
#define _GLIBCXX_DEBUG #include <algorithm> #include <cmath> #include <cstdlib> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> // #include <atcoder/all> // using namespace atcoder; using namespace std; using ll = long long; int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); int n, m; cin >> n >> m; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } int cur = 0; vector<int> cnt(n+1, 0); for (int i = 0; i < m; ++i) { cnt[a[i]]++; while (cnt[cur]) cur++; } int ans = cur; int left = 0, right = m-1; for (int i = 0; i < n-m; ++i) { right++; cnt[a[right]]++; cnt[a[left]]--; if (cur > a[left] && cnt[a[left]] == 0) cur = a[left]; left++; while (cnt[cur]) cur++; if (ans > cur) ans = cur; } cout << ans << endl; return 0; }
#include<cstdio> #include<vector> #include<algorithm> #include<iostream> #include<stack> #include<queue> #include<string> using namespace std; const int INF = 1000000001; typedef pair<int, int> P; typedef long long ll; int main(){ int a, b, c; cin >> a >> b >> c; if (a == b) cout << c << endl; else if (a == c) cout << b << endl; else if (b == c) cout << a << endl; else cout << 0 << endl; }
#include <bits/stdc++.h> #define crap ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define db1(x) cout<<#x<<"="<<x<<'\n' #define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n' #define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n' #define rep(i,n) for(ll i=0;i<(n);++i) #define repA(i,a,n) for(ll i=a;i<=(n);++i) #define repD(i,a,n) for(ll i=a;i>=(n);--i) #define repV(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) #define pb push_back // #define mp make_pair #define F first #define S second #define CN cout<<"NO\n" #define CY cout<<"YES\n" #define M_PI 3.14159265358979323846 using namespace std; using ll = long long; #define MAXN 10000001 #define mod 1000000007 void solve(){ ll a,b,c; cin>>a>>b>>c; if(a==b) { cout<<c;return; } if(c==b) { cout<<a;return; } if(a==c) { cout<<b;return; } cout<<"0"; } int main() { crap; #ifndef ONLINE_JUDGE freopen("input.txt","r", stdin) ; freopen("output.txt","w", stdout) ; freopen("error.txt","w", stderr) ; #endif ll t=1; // cin>>t; repA(i,1,t){ // cout<<"Case #"<<i<<": "; solve(); } return 0; }
#include <iostream> using namespace std; int main() { int x,y; cin>>x>>y; int z=min(x,y); int g=max(x,y); if(z+3>g) cout<<"Yes"; else cout<<" No"; return 0; }
// include #include <algorithm> #include <complex> #include <iostream> #include <string> #include <vector> using namespace std; //型短縮 #define ll long long //マクロ定義 #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { ll N, K; cin >> N >> K; ll res = 0; string bigstr = to_string(N); string smallstr = to_string(N); if (K == 0) cout << N; else { rep(i, K) { sort(smallstr.begin(), smallstr.end()); sort(bigstr.begin(), bigstr.end(), greater<int>()); ll big = stoll(bigstr); ll small = stoll(smallstr); if (big - small == res) break; res = big - small; bigstr = to_string(res); smallstr = to_string(res); } cout << res; } return 0; }
#include <iostream> using namespace std; int main() { int N; cin >> N; int x = N/100; if (!(N%100==0)) x++; cout << x; }
//#include <bits/stdc++.h> #include <iostream> #include <vector> #include <queue> #include <stack> #include <list> #include <string> #include <string.h> #include <assert.h> #include <math.h> #include <numeric> #include <cmath> #include <map> #include <unordered_map> #include <set> #include <unordered_set> #include <limits> #include <limits.h> #include <iomanip> #include <algorithm> using namespace std; #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " #define ll long long #define ull unsigned long long #define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define pb push_back #define mkp make_pair #define fi first #define se second void solve() { int N; cin >> N; if(N%100==0) cout << N/100; else { cout << (N/100)+1; } } int main() { //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); IOS; int t = 1; //cin >> t; while(t--) { solve(); } return 0; }
#include <bits/stdc++.h> #include <limits> using namespace std; typedef unsigned long long int ull; typedef long long int ll; #define fi(i,n) for( ll i=0 ; i<n ; i++ ) #define f(i, a, b) for( ll i=a ; i<b ; i++ ) #define vi vector<int> #define pb push_back #define MOD 1000000007 ll digits(ll n) { return floor(log10(double(n))) + 1; } void faster() { ios_base::sync_with_stdio(false); cin.tie(NULL); } ll modularExponentiation(ll x,ll n,ll M) { ll result = 1; while(n>0) { if(n % 2 ==1) { result = ((result%M)*(x%M))%M; } x = ((x%M)*(x%M))%M; n = n/2; } return result%M; } ll d, x, y; void extendedEuclid(ll A, ll B) { // for computing modular inverse // make b as Mod such that gcd of mod and a is 1 // also the coeff x here will denote the modular inverse of a if(B == 0) { d = A; x = 1; y = 0; } else { extendedEuclid(B, A%B); int temp = x; x = y; y = temp - (A/B)*y; // x = y1 // y = x1 - y1*(a/b); } } // DP solution for nCr ll nCrModp(ll n, ll r) { if (r > n - r) r = n - r; ll C[r + 1]; memset(C, 0, sizeof(C)); C[0] = 1; for (ll i = 1; i <= n; i++) { for (ll j = min(i,r); j > 0; j--) { C[j] = (C[j] + C[j - 1]); } } return C[r]; } ll modInverse(ll A, ll M) { extendedEuclid(A,M); return (x%M+M)%M; //x may be negative } // primefactors[a] = primefactors[a/primedivisor[a]] + 1 ll binarySearch(vector<ll>&arr, ll l, ll r, ll x) { while (l <= r) { int m = l + (r - l) / 2; if (arr[m] == x) return m; if (arr[m] < x) l = m + 1; else r = m - 1; } return -1; } vector<ll>v; vector<ll> SieveOfEratosthenes(int n) { bool prime[n+1]; memset(prime, true, sizeof(prime)); for (ll p=2; p*p<=n; p++) { if (prime[p] == true) { for (ll i=p*p; i<=n; i += p) prime[i] = false; } } for (ll p=2; p<=n; p++) if (prime[p]) v.push_back(p); return v; } // 11 12 15 18 2 5 6 8 9 10 double fun(vector<double>&v, double m,double n) { double s = 0; double ma = 0; double mi = 0; fi(i,n) { s += v[i] - m; ma = max(s,ma); mi = min(s,mi); } return ma - mi; } int main() { faster(); ll n; cin>>n; set<ll>st; for(ll i =1;i<=sqrt(n);i++) { if(n%i==0) { st.insert(i); st.insert(n/i); } } for(auto it = st.begin();it!=st.end();it++) { ll a = *it; cout<<a<<endl; } }
#include <iostream> #include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5, OO = 1e9; long long a[N] , j = 0; long long n; void divisor(long long value){ long long i = 1; for( ; i * i < value; ++i){ if(value % i == 0){ a[j] = i; j++; a[j] = value / i; j++; } } if( i * i == value){ a[j] = i; j++; } } int main() { cin >> n; divisor(n); sort(a , a + j); for(int i =0; i<j; ++i){ cout << a[i] << endl; } return 0; }
#include <stdio.h> #include <bits/stdc++.h> using namespace std; typedef long long ll; #define SZ(a) int((a).size()) #define _REP(_1,_2,_3,_4,name,...) name #define _REP4(i,b,e,s) for(decltype(e) _b=(b),_e=(e),i=_b+(0<(s)?0:(s));(0<(s)?i<_e:_e<=i);i+=(s)) #define _REP3(i,b,e) for(decltype(e) _b=(b),_e=(e),i=(_b<_e?_b:_b-1);(_b<_e?i<_e:_e<=i);(_b<_e?i++:i--)) #define _REP2(i,n) for(decltype(n) i=0,_n=(n);i<_n;i++) #define _REP1(n) for(decltype(n) _i=0,_n=(n);_i<_n;_i++) #define REP(...) _REP(__VA_ARGS__,_REP4,_REP3,_REP2,_REP1)(__VA_ARGS__) #define FOR(it,c) for(auto&& it=begin(c);it!=end(c);it++) #define ROF(it,c) for(auto&& it=rbegin(c);it!=rend(c);it++) #define INT(n) int n;assert(0<scanf("%d",&n)) static const int MAXP = 1000000; vector<int> ps, fs; void init(){ fs.reserve(1 + MAXP); for(int i = 0; i <= MAXP; i++){fs.push_back(i);} for(int i = 2; i <= MAXP; i++){ if (fs[i] == i){ ps.push_back(i); for (int j = i; j <= MAXP; j += i){ fs[j] = min(fs[j], i); } } } } bool isprime(const long long& n){ if (n <= MAXP){ return (1 < n && fs[n] == n); } else { for(int p: ps){ if (n % p == 0){return false;} } return true; } } vector<pair<long long, int>> factor(long long n){ vector<pair<long long, int>> v; long long i = n; if (MAXP < i){ for(int p: ps){ int r = 0; while (i % p == 0){r++; i /= p;} if (0 < r){v.push_back(make_pair(p, r));} if (i <= MAXP){break;} } if (MAXP < i){ v.push_back(make_pair(i, 1)); i = 1; } } while(1 < i){ if (v.empty() || (*v.rbegin()).first != fs[i]){ v.push_back(make_pair(fs[i], 1)); } else { (*v.rbegin()).second++; } i /= fs[i]; } return v; } int moebius(long long n){ int m = 1; for(auto pr: factor(n)){ if (pr.second == 1){ m *= -1; } else {m = 0; break;} } return m; } int main(){ ll ans = 0; init(); INT(l); INT(r); REP(i, 2, r / 2 + 1){ int n = r / i - (l - 1) / i; ans += (ll) -moebius(i) * n * (n - 1); if (l <= i){ans -= 2*(n - 1);} } printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> #define s second #define f first #define pb push_back #define endl '\n' #define all(x) (x).begin(), (x).end() #define _ ios_base::sync_with_stdio(0);cin.tie(0); #define read(x) for(auto& qw : (x)) cin >> qw; #define print(x) for(auto& qw : (x)) cout << qw << " "; cout << endl; using namespace std; typedef long long ll; typedef pair<double,double> ii; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fLL; const double EPS = 1e-6; void test_case(){ int N; cin >> N; vector<ii> V(N); for(ii &x : V) cin >> x.f >> x.s; int ans = 0; for(int i = 0; i < N; i++){ for(int j = 0; j < N; j++){ if(j == i) continue; double slope = (V[i].s - V[j].s)/(V[i].f - V[j].f); if(fabs(slope) < 1 + EPS) ans++; } } cout << ans/2 << endl; } int main(){ _ int tt = 1; // cin >> tt; while(tt--){ test_case(); } return 0; }
#include <bits/stdc++.h> int n, m; int main() { scanf("%d%d", &n, &m); if (m == 0) { for (int i = 1; i < 2 * n; i += 2) { printf("%d %d\n", i, i + 1); } } else if (m < 0 || m >= n - 1) { printf("-1\n"); } else { printf("1 1000000000\n"); printf("2 1000000\n"); int k1 = n - 2 - m; int k2 = m; for (int i = 1; i <= k1; ++i) { printf("%d %d\n", 1000000 - i, 1000000 + i); } int tmp = 1000000 + k1 + 1; for (int i = 1; i <= k2; ++i) { printf("%d %d\n", tmp, tmp + 1); tmp += 2; } } return 0; }
#include <iostream> #include <map> #include <vector> using namespace std; int main() { ios_base::sync_with_stdio(false);cin.tie(0); int N,M,i,k=1; cin >> N >> M; if(N == 1 && M ==0){ cout << 1 <<" "<< 2 <<"\n"; return 0; } else if(M == 0 && N%2!=0){ cout << -1; return 0; } else if(M<0){ cout << -1; return 0; } else if(N-M<2){ cout << -1; return 0; } cout << 1 << " " <<2*(M+2)<<"\n"; for(i=2;i<2*(M+2);i+=2){ k++; cout << i <<" "<<i+1<<"\n"; } for(i=2*(M+2)+1;(k+1)<=N;i+=2){ k++; cout << i <<" "<<i+1<<"\n"; } }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int,int>; int main() { double sx, sy, gx, gy; cin >> sx >> sy >> gx >> gy; double ans = (gx - sx)*sy/(sy+gy) + sx; printf("%f06\n", ans); return 0; }
#include <iostream> #include <iomanip> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.precision(16); double sx, sy, gx, gy; cin >> sx >> sy >> gx >> gy; if (sx > gx) { swap(sx, gx); swap(sy, gy); } sy = -sy; double dy = gy - sy, dx = gx - sx; auto check = [&](double x) { return dy * (sx - x) >= dx * sy; }; double l = sx, r = gx, x; for (int it = 0; it < 50; it++) { check(x = (l + r) * 0.5) ? l = x : r = x; } cout << l << '\n'; return 0; }
#include <iostream> #include <algorithm> #include <vector> #include <math.h> #include <set> #include <map> #define repi(i, s, e) for (int i = (s); i < (e); ++i) using namespace std; using ll = int64_t; int main() { int n; cin >> n; ll x[n]; repi(i, 0, n) cin >> x[i]; ll man = 0; repi(i, 0, n) man += abs(x[i]); double euc = 0; repi(i, 0, n) { euc += x[i]*x[i]; } euc = sqrt(euc); ll che = 0; repi(i, 0, n) if(che < abs(x[i])) che = abs(x[i]); cout << man << endl; printf("%.9lf\n", euc); cout << che << endl; return 0 ; }
/** ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡖⠁⠀⠀⠀⠀⠀⠀⠈⢲⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⣼⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⣧⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⣸⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣇⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⣿⣿⡇⠀⢀⣀⣤⣤⣤⣤⣀⡀⠀⢸⣿⣿⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀⢻⣿⣿⣔⢿⡿⠟⠛⠛⠻⢿⡿⣢⣿⣿⡟⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⣀⣤⣶⣾⣿⣿⣿⣷⣤⣀⡀⢀⣀⣤⣾⣿⣿⣿⣷⣶⣤⡀⠀⠀⠀⠀ ⠀⠀⢠⣾⣿⡿⠿⠿⠿⣿⣿⣿⣿⡿⠏⠻⢿⣿⣿⣿⣿⠿⠿⠿⢿⣿⣷⡀⠀⠀ ⠀⢠⡿⠋⠁⠀⠀⢸⣿⡇⠉⠻⣿⠇⠀⠀⠸⣿⡿⠋⢰⣿⡇⠀⠀⠈⠙⢿⡄⠀ ⠀⡿⠁⠀⠀⠀⠀⠘⣿⣷⡀⠀⠰⣿⣶⣶⣿⡎⠀⢀⣾⣿⠇⠀⠀⠀⠀⠈⢿⠀ ⠀⡇⠀⠀⠀⠀⠀⠀⠹⣿⣷⣄⠀⣿⣿⣿⣿⠀⣠⣾⣿⠏⠀⠀⠀⠀⠀⠀⢸⠀ ⠀⠁⠀⠀⠀⠀⠀⠀⠀⠈⠻⢿⢇⣿⣿⣿⣿⡸⣿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠈⠀ ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣼⣿⣿⣿⣿⣧⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠐⢤⣀⣀⢀⣀⣠⣴⣿⣿⠿⠋⠙⠿⣿⣿⣦⣄⣀⠀⠀⣀⡠⠂⠀⠀⠀ ⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠉⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠋⠁⠀⠀ * author: Daredevil666 * institution: IIT Patna **/ #define _USE_MATH_DEFINES #include <bits/stdc++.h> #define nl cout<<"\n"; #define ll long long int #define REP(i,a,n) for(i=a;i<=n;i++) #define F(i,a,b) for(i=a;i<b;i++) #define RF(i,b,a) for(i=b;i>=a;i--) #define IOS ios::sync_with_stdio(false);cin.tie(0); using namespace std; const ll mod=1e16; const ll MAXN=1000200; ll i,j,mask; int main() { IOS /*#ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif // ONLINE_JUDGE*/ ll n; cin>>n; ll a=0,c=0; double b=0; F(i,0,n) { ll x; cin>>x; a+=abs(x); b+=x*x; c=max(c,abs(x)); } b=(double)sqrt(b); cout<<a;nl cout<<fixed<<setprecision(15)<<b;nl cout<<c; return 0; }
#include<bits/stdc++.h> #define DONTSYNC ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) //dont use stdio with iostream functions //input and output are out of order now! #define TEST unsigned long long T; cin>>T; while(T--) //loop over each testcase #define endl "\n" #define fori(a,start,end) for(int a=start;a<end;a++) #define forll(a,start,end) for(long long a=start;a<end;a++) #define forull(a,start,end) for(unsigned long long a=start;a<end;a++) #define MOD 998244353 typedef long long ll; typedef unsigned long long ull; using namespace std; int N,K; int parent(int a,vector<int> &par){ if(par[a]==a){ return a; } par[a]=parent(par[a],par); return par[a]; } void group(int a,int b,vector<int> &par){ int para=parent(a,par),parb=parent(b,par); if(para<parb){ par[parb]=para; } else{ par[para]=parb; } } bool check(int isrow,int a,int b,vector< vector<int> > &mat){ if(isrow){ fori(col,0,N){ if(mat[a][col]+mat[b][col]>K) return false; } } else{ fori(row,0,N){ if(mat[row][a]+mat[row][b]>K) return false; } } return true; } void solve(){ /* code */ cin>>N>>K; long long res=1; vector< vector<int> > mat(N,vector<int>(N)); fori(i,0,N) fori(j,0,N) cin>>mat[i][j]; //////// vector<int> par(N); fori(i,0,N) par[i]=i; fori(a,0,N-1){ fori(b,a+1,N){ if (check(1,a,b,mat)) group(a,b,par); } } vector<int> count(N,1); fori(i,0,N) res=(res*count[parent(i,par)]++)%MOD; ////// fori(i,0,N) par[i]=i; fori(a,0,N-1){ fori(b,a+1,N){ if (check(0,a,b,mat)) group(a,b,par); } } fill(count.begin(),count.end(),1); fori(i,0,N) res=(res*count[parent(i,par)]++)%MOD; cout<<res; } int main() { DONTSYNC; // TEST{ solve(); // } return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> P; const int INF=1e9; const ll MOD=998244353; struct UnionFind{ vector<int> par; vector<int> sizes; UnionFind(int n):par(n),sizes(n,1){ for(int i=0;i<n;i++){ par[i]=i; } } int find(int x) { //xの根を得る if (x == par[x]) return x; return par[x] = find(par[x]); //根を張り替えながら再帰的に根ノードを探す } //2つの要素が属する集合を併合 void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (sizes[x] < sizes[y]) swap(x, y); par[y] = x; sizes[x] += sizes[y]; } //2つの要素が同じ集合に属するか判定する bool same(int x, int y) { return find(x) == find(y); } //集合のサイズを取得 int size(int x) { return sizes[find(x)]; } }; int main(){ int N,K; cin >> N >> K; ll ans=1; ll a[N][N]; for(int i=0;i<N;i++){ for(int j=0;j<N;j++){ cin >> a[i][j]; } } UnionFind ufr(N+10); UnionFind ufl(N+10); vector<int> r[N+1],l[N+1]; for(int i=0;i<N;i++){ for(int j=i+1;j<N;j++){ bool flag=true; bool flag2=true; for(int k=0;k<N;k++){ if(i==j) continue; if((a[k][i]+a[k][j])>K) flag=false; if((a[i][k]+a[j][k])>K) flag2=false; } if(flag) ufr.unite(i,j); if(flag2) ufl.unite(i,j); } } bool usedr[N+10]={}; bool usedl[N+10]={}; for(int i=0;i<N;i++){ if(usedr[ufr.find(i)]) continue; usedr[ufr.find(i)]=true; for(int j=1;j<=ufr.size(ufr.find(i));j++){ ans*=j; ans%=MOD; } } for(int i=0;i<N;i++){ if(usedl[ufl.find(i)]) continue; usedl[ufl.find(i)]=true; for(int j=1;j<=ufl.size(ufl.find(i));j++){ ans*=j; ans%=MOD; } } cout << ans%MOD << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < n; i++) #define rep2(i, x, n) for(int i = x; i <= n; i++) #define rep3(i, x, n) for(int i = x; i >= n; i--) #define each(e, v) for(auto &e: v) #define pb push_back #define eb emplace_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define sz(x) (int)x.size() using ll = long long; using pii = pair<int, int>; using pil = pair<int, ll>; using pli = pair<ll, int>; using pll = pair<ll, ll>; const int MOD = 1000000007; //const int MOD = 998244353; const int inf = (1<<30)-1; const ll INF = (1LL<<60)-1; template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;}; template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;}; struct io_setup{ io_setup(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout << fixed << setprecision(15); } } io_setup; int main(){ int N; cin >> N; vector<ll> L(N+2, INF), R(N+2, -INF); L[0] = 0, R[0] = 0, L[N+1] = 0, R[N+1] = 0; rep(i, N){ ll x; int c; cin >> x >> c; chmin(L[c], x), chmax(R[c], x); } vector<vector<ll>> dp(N+2, vector<ll>(2, INF)); dp[0][0] = 0, dp[0][1] = 0; int pre = 0; rep2(i, 1, N+1){ if(L[i] == INF) {dp[i][0] = dp[pre][0], dp[i][1] = dp[pre][1]; continue;} chmin(dp[i][0], dp[pre][0]+abs(R[i]-L[pre])+abs(L[i]-R[i])); chmin(dp[i][1], dp[pre][0]+abs(L[i]-L[pre])+abs(R[i]-L[i])); chmin(dp[i][0], dp[pre][1]+abs(R[i]-R[pre])+abs(L[i]-R[i])); chmin(dp[i][1], dp[pre][1]+abs(L[i]-R[pre])+abs(R[i]-L[i])); pre = i; } //rep(i, N+2) cout << dp[i][0] << ' ' << dp[i][1] << '\n'; cout << min(dp[N+1][0], dp[N+1][1]) << '\n'; }
#include <bits/stdc++.h> #define int long long #define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); using namespace std; signed main(){ fastio //Equivalent to the problem which we need to collect from the top of the grid down int n; cin >> n; int l[n+1], r[n+1]; fill(l,l+n+1,1e18); fill(r,r+n+1,-1e18); for(int i = 0;i < n;i++){ int x,c; cin >> x >> c; l[c] = min(l[c],x); r[c] = max(r[c],x); } l[0] = r[0] = 0; int dp[n+1][2] = {}; //dp[i][0] => start from left, dp[i][1] start from right for(int i = 1;i <= n;i++){ dp[i][0] = dp[i-1][0], dp[i][1] = dp[i-1][1]; if(l[i]==1e18){ l[i] = l[i-1], r[i] = r[i-1]; continue; } dp[i][0] = min(dp[i-1][0]+abs(l[i]-r[i-1])+r[i]-l[i],dp[i-1][1]+abs(l[i]-l[i-1])+r[i]-l[i]); dp[i][1] = min(dp[i-1][0]+abs(r[i]-r[i-1])+r[i]-l[i],dp[i-1][1]+abs(r[i]-l[i-1])+r[i]-l[i]); } cout << min(dp[n][0]+abs(r[n]),dp[n][1]+abs(l[n])) << "\n"; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; int main() { double sx, sy, gx, gy; cin >> sx >> sy >> gx >> gy; double ty = sy + gy; double tx; if(sx >=0 && gx >= 0){ if(sx > gx){ tx = sx - gx; } else{ tx = gx - sx; } } else if(sx < 0 && gx >=0){ tx = -sx + gx; } else if(sx >=0 && gx < 0){ tx = sx - gx; } else{ if(sx > gx){ tx = sx - gx; } else{ tx = gx - sx; } } double ans; if(sx < gx){ ans = sx + tx*(sy / ty); } else{ ans = sx - tx*(sy / ty); } printf("%.10f\n", ans); }
/* Har Har Mahadev */ //cout<<fixed<<setprecision(11)<<ans<<"\n"; //cin.ignore();getline(cin,s,'\n'); #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef vector<ll> vll; typedef pair<ll,ll> pll; #define lab(i,a,b) for(i=a;i<=b;i++) #define bal(i,a,b) for(i=b;i>=a;i--) #define ff first #define ss second #define pb push_back #define se(v) v.begin(), v.end() #define fst ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define tc ll t;cin>>t;while(t--) #define fceil(a,b) ceil((ld)a/(ld)b) #define dis(v) for(auto it:v)cout<<it<<" " #define yep cout<<"Yes\n" #define nope cout<<"No\n" bool isPrime(ll n){if(n <= 1)return false;if(n <= 3)return true;if(n%2==0||n%3==0)return false;for(ll i=5;i*i<= n;i=i+6)if(n%i==0||n%(i+2)==0)return false;return true;} bool cmp(pll &a, pll &b){ if(a.ss == b.ss)return a.ff < b.ff;return a.ss < b.ss;} const ll MOD = 1e9 + 7; ll powerLL(ll x, ll n){ll result = 1;while (n){if (n & 1)result = result * x % MOD;n = n / 2;x = x * x % MOD;}return result;} int main() { fst ll n,m,i,j,k,f,sum,ans,x,y,z; //tc { m=0,i=0,j=0,f=0,sum=0,x=0,y=0,z=0,ans=0; ll a[3]; cin>>a[0]>>a[1]>>a[2]; sort(a,a+3); if(2*a[1]==a[0]+a[2])yep; else nope; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); int n; cin>>n; int a[n]; for (int i=0;i<n;i++) cin>>a[i]; vector<int> sav(200007,0); int m=0;int nm=1; for (int i=0;i<n;i++) { sav[a[i]]=1; if (sav[m]!=0) { while (sav[m]!=0) { m++; } cout<<m<<"\n"; } else { cout<<m<<"\n"; } } return 0; }
#include <bits/stdc++.h> #define fi first #define se second #define pb push_back #define mp make_pair #define sz(x) ((int)(x).size()) #define endl "\n" #define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr); #define all(x) x.begin(),x.end() #define y1 omg #define INF 1000000010 #define FOR(x, n) for(int x=0; x<n; x++) #define ini(x, n) memset(x, n, sizeof(x)); #define MOD ((int)1e9 + 7) #define atoi(x) ((x)-'0') #define int ll //#define double long double using namespace std; typedef long long ll; typedef pair<int, int> ii; typedef pair<int, ii> iii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<vi> vvi; int dx[] = { 1, -1, 0, 0, 1, 1, -1, -1 }; int dy[] = { 0, 0, 1, -1, 1, -1, 1, -1 }; int n, t; set<int> S; signed main() { fastio; cin >> n; FOR(i, n + 1) S.insert(i); FOR(i, n) { cin >> t; S.erase(t); cout << *S.begin() << endl; } }
#include "bits/stdc++.h" #include <ext/pb_ds/assoc_container.hpp> //#include <boost/multiprecision/cpp_int.hpp> using namespace std; using namespace __gnu_pbds; //using namespace boost::multiprecision; typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; typedef long long ll; typedef vector<ll> VI; typedef vector<vector<ll>> VVI; typedef pair<ll, ll> PII; typedef vector<PII> VPII; typedef set<ll> SI; typedef map<string, ll> MSI; typedef map<ll, ll> MII; typedef pair<ll, PII> PIII; #define flash ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define MP make_pair #define PB push_back #define FF first #define SS second #define MOD 1000000007 #define test ll t;cin>>t;while(t--) #define REP(i,a,b) for (int i = a; i <= b; i++) void solve() { int a,b; cin >> a >> b; int x = INT_MAX-1; int arr[a][b]; for(int i=0;i<a;i++) { for(int j=0;j<b;j++) { cin >> arr[i][j]; x = min(x,arr[i][j]); } } int ans = 0; for(int i=0;i<a;i++) { for(int j=0;j<b;j++) { ans+=(arr[i][j]-x); } } cout << ans << "\n"; return; } int main() { flash; // test // { // solve(); // } solve(); 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; } struct Edge { ll to, cap, rev; Edge(ll _to, ll _cap, ll _rev) { to = _to; cap = _cap; rev = _rev; } }; typedef vector<Edge> Edges; typedef vector<Edges> Graph; void add_edge(Graph &G, ll from, ll to, ll cap, bool revFlag, ll revCap) { G[from].push_back(Edge(to, cap, (ll)G[to].size())); if(revFlag) G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1)); } void solve() { ll n,m; cin>>n>>m; vvec<ll> a(n,vec<ll>(m,0)); ll mi=INF; REP(i,n){ REP(j,m){ cin>>a[i][j]; chmin(mi,a[i][j]); } } ll ans=0; REP(i,n) REP(j,m) ans+=a[i][j]-mi; cout<<ans<<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> #define debug(x) cerr << #x << " = " << x << endl using namespace std; typedef long long LL; const int MAXN = 3005; const int MOD = 998244353; int n, k, dp[MAXN][MAXN]; template <class T> void read(T& x) { x = 0; T f = 1; char ch = getchar(); while (ch < '0' || ch > '9') f = (ch == '-' ? -1 : 1), ch = getchar(); while (ch >= '0' && ch <= '9') x = x * 10 + ch - 48, ch = getchar(); x *= f; } template <class T, class... Args> void read(T& x, Args&... args) { read(x), read(args...); } template <class T> void write(T x) { if (x < 0) putchar('-'), x = -x; if (x > 9) write(x / 10); putchar(x % 10 + '0'); } int make(int n, int k) { if (k > n) return 0; if (n == k) return 1; if (n == 0 || k == 0) return 0; // cout << n << " " << k << endl; if (dp[n][k]) return dp[n][k]; dp[n][k] = (make(n - 1, k - 1) + make(n, k * 2)) % MOD; return dp[n][k]; } signed main() { // freopen("1.in", "r", stdin); read(n, k); cout << make(n, k); return 0; }
#include<bits/stdc++.h> using namespace std; using ll = long long; using vl = vector<ll>; #define rep(i,n) for(int i=0;i<(n);i++) #define rrep(i,n) for(int i=(n)-1;i>=0;i--) #define rep1(i,n) for(int i=1;i<=(n);i++) #define rrep1(i,n) for(int i=(n);i>0;i--) #define fore(i_in,a) for (auto& i_in: a) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define fio() cin.tie(nullptr);ios::sync_with_stdio(false); #define DEBUG_CTN(v) cerr<<#v<<":";for(auto itr=v.begin();itr!=v.end();itr++) cerr<<" "<<*itr; cerr<<endl template<class T> bool chmax(T &a, const T &b) {if (a<b) { a = b; return true; } return 0;} template<class T> bool chmin(T &a, const T &b) {if (a>b) { a = b; return true; } return 0;} template<class T> void print(const T &t) { cout << t << "\n"; } const ll INF = 1LL << 62; const int iINF = 1 << 30; int n,m; string s; int main() { fio(); cin>>n>>m; vl cnt(2,0); rep(i,n) { cin>>s; ll tmp=count(all(s),'1'); cnt[tmp%2]++; } print(cnt[0]*cnt[1]); } //9min 1wa
#include <bits/stdc++.h> #define ll long long #define db long double #define x first #define y second #define mp make_pair #define pb push_back #define all(a) a.begin(), a.end() using namespace std; int main(){ #ifdef LOCAL freopen("E_input.txt", "r", stdin); //freopen("E_output.txt", "w", stdout); #endif ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for (int i = 0; i < n; ++i) { int A = i/2, B = min(n - 1, i/2 + (n+1) / 2); cout << A+1 << " " << B+1 << endl; } }
///****In the name of ALLAH, most Gracious, most Compassionate****// #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair <int, int> pii; #define ALL(a) a.begin(), a.end() #define FastIO ios::sync_with_stdio(false); cin.tie(0);cout.tie(0) #define IN freopen("input.txt","r+",stdin) #define OUT freopen("output.txt","w+",stdout) #define DBG(a) cerr<< "line "<<__LINE__ <<" : "<< #a <<" --> "<<(a)<<endl #define NL cout<<endl template < class T1,class T2> ostream &operator <<(ostream &os,const pair < T1,T2 > &p) { os<<"{"<<p.first<<","<<p.second<<"}"; return os; } const int N=3e5+5; const int oo=1e9+7; int32_t main() { FastIO; int n; cin>>n; for(int i=1;i<=n;i++) cout<<(2*i)%n+1<<" "<<(2*i + 1)%n+1<<"\n"; }
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> #define ud unsigned int #define ll long long #define ull unsigned long long #define MAX_INF 0x3f #define MAX_INF_VAL 0x3f3f3f3f #define MAX_INF_VAL_LL 0x3f3f3f3f3f3f3f3f //#define pi 3.141592653589 #define eps 1e-9 #define F(x) ((x)/3+((x)%3==1?0:tb)) #define G(x) ((x)<tb?(x)*3+1:((x)-tb)*3+2) //#define p 2173412051LL //#define sz 2 using namespace std; template< typename T > void read( T &x ) { x = 0; char ch = getchar(); ll f = 1; while( !isdigit( ch ) ) { if( ch == '-' ) f *= -1; ch = getchar(); } while( isdigit( ch ) ) { x = x * 10 + ch - 48; ch = getchar(); } x *= f; } struct custom_hash { static uint64_t splitmix64( uint64_t x ) { x += 0x9e3779b97f4a7c15; x = ( x ^ ( x >> 30 ) ) * 0xbf58476d1ce4e5b9; x = ( x ^ ( x >> 27 ) ) * 0x94d049bb133111eb; return x ^ ( x >> 31 ); } size_t operator() ( uint64_t x ) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64( x + FIXED_RANDOM ); } }; vector< int > ans; void opt( int ); int main() { ios::sync_with_stdio( false ); cin.tie( 0 ), cout.tie( 0 ); ll n; vector< ll > a, b; { ll x = 1, y = 1; a.push_back( x ); a.push_back( y ); while( true ) { x += y; if( x > 1e18 ) break; a.push_back( x ); swap( x, y ); } } cin >> n; while( a[ a.size() - 1 ] > n ) a.pop_back(); for( auto v: a ) b.push_back( v ); while( true ) { int i = b.size() - 1; if( b[ i ] == n ) break; ll del = n - b[ i ]; int j = 0; while( j + 1 < a.size() && a[ j + 1 ] <= del ) ++j; int fk = i - j; for( int k = b.size() - 1; k >= fk; --k ) b[ k ] += a[ k - fk ]; } ll x = 0, y = 0; for( int i = 0, j = b.size() & 1; i < b.size(); ++i, j = 1 - j ) { if( j ) { x += y; assert( x == b[ i ] || x + 1 == b[ i ] ); opt( 3 ); if( x != b[ i ] ) { ++x; opt( 1 ); } } else { y += x; assert( y == b[ i ] || y + 1 == b[ i ] ); opt( 4 ); if( y != b[ i ] ) { ++y; opt( 2 ); } } } assert( x == n ); cout << ans.size() << '\n'; for( auto v: ans ) cout << v << '\n'; return 0; } void opt( int x ) { ans.push_back( x ); assert( ans.size() <= 130 ); }
#include <bits/stdc++.h> //#include <atcoder/all> using namespace std; #define rep(i,n) for(ll i=0; i<n; i++) #define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++) #define rrep(i,n) for(ll i=n-1; i>=0; i--) #define fi first #define se second long long mo = 1000000007; typedef long long ll; typedef long double ld; typedef pair<int,int> Pii; typedef pair<ll,ll> Pll; typedef pair<ll,Pll> PlP; template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; } template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; } template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";} template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);} string zero_padding(int val, int nf){ ostringstream sout;sout << setfill('0') << setw(nf) << val; return sout.str();}; ld PI=asin(1)*2; //using namespace atcoder; vector<vector<ll>> G(200010); map<Pll,ll> mp; map<Pll,ll> np; vector<ll> ans(200010,0); ll dfs(ll v, ll p){ //sum += mp[Pll(p,v)]; //ans[v] += sum; ll ret = 0; for(auto& u:G[v]){ if(u==p)continue; ret += dfs(u,v); } return np[{v,p}] = ret + mp[{v,p}]; //mp[Pll(-1,v)] += sum; } void bfs(ll v, ll p){ ll ret = 0; for(auto& u:G[v]){ ret += np[{u,v}]; } ans[v] = ret; for(auto& u:G[v]){ if(u == p) continue; np[{v,u}] = ans[v] - np[{u,v}] + mp[{v,u}]; bfs(u,v); } } int main(){ ll N; cin >> N; vector<ll> A(N-1), B(N-1); rep(i,N-1){ cin >> A[i] >> B[i]; A[i]--; B[i]--; G[A[i]].push_back(B[i]); G[B[i]].push_back(A[i]); } ll Q; cin >> Q; vector<ll> T(Q), E(Q), X(Q); rep(i,Q){ cin >> T[i] >> E[i] >> X[i]; E[i]--; } rep(i,Q){ ll e = E[i]; if(T[i] == 1){ mp[Pll(B[e], A[e])] += X[i]; }else{ mp[Pll(A[e], B[e])] += X[i]; } } dfs(0,-1); //for(auto&e:mp){ // cout << e.fi.fi << " " << e.fi.se << " " << e.se << endl; //} bfs(0,-1); rep(i,N){ cout << ans[i] << endl; } }
#include <bits/stdc++.h> using namespace std; #define ll long long #define light ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define vp(v) for(auto it = v.begin(); it != v.end(); it++) cout << *it << " "; cout<<endl; int main() { light ll tx; cin>>tx; ll h1, h2 , t; string s1 , s2 , ts ; cin>>s1>>h1; cin>>s2>>h2; if( h1 < h2){ t = h1 ; ts = s1; h1 = h2 ; s1 = s2 ; h2 = t; s2 = ts; } for(ll i =2; i<tx; i++){ ll he; string m ; cin>>m>>he; if( he > h1 ){ t = h1 ; ts = s1; h1 = he ; s1 = m ; h2 = t; s2 = ts; } else if( h1 > he && h2 < he){ h2 = he ; s2 = m; } } cout<<s2<<endl; }
#include <iostream> #include <cstdio> #include <vector> #include <queue> #include <stack> #include <algorithm> #include <set> #include <map> #include <deque> #include <cmath> #include <string> #include <iomanip> #include <locale> #include <list> #include <bitset> #include <tuple> #include <fstream> using namespace std; #define FORN(i,m,n) for(int i=(m); i<int(n); ++i) #define PRINTARR(a,n) FORN(i,0,n) cout<<a[i]<<" "; cout<<endl #define PRINTVEC(v) FORN(i,0,v.size()) cout<<v[i]<<" "; cout<<endl #define PRINTMAT(m) FORN(j,0,m.size()) {PRINTVEC(m[j]);} typedef long long ll; const int ms = 50; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin>>n; ll ans = 0; FORN(i,0,n){ ll a, b; cin>>a>>b; ans += ((b - a + 1) * (a + b)) >> 1; } cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int a[maxn]; int main() { int T; scanf("%d", &T); for(int cas = 1; cas <= T; ++cas) { int n; scanf("%d", &n); for(int i = 1; i <= n; ++i) scanf("%d", &a[i]); if(n & 1) puts("Second"); else { sort(a + 1, a + n + 1); bool flag = 0; for(int i = 2; i <= n; i += 2) if(a[i] != a[i - 1]) { flag = 1; break; } if(flag) puts("First"); else puts("Second"); } } return 0; }
//Shinchan Loves Coding :)) #include<bits/stdc++.h> using namespace std; #define night_rider ios::sync_with_stdio(false);cin.tie(NULL); #define double long double #define int long long int #define en "\n" #define fi first #define se second #define PB push_back #define all(v) v.begin(),v.end() #define allr(v) v.rbegin(),v.rend() #define rep(i,x,y) for(int i=x ; i<y ; i++) #define erep(i,x,y) for(int i=x ; i<=y ; i++) #define erepr(i,x,y) for(int i=x ; i>=y ; i--) #define repr(i,x,y) for(int i=x ; i>y ; i--) typedef vector<int> vi; typedef vector<vector<int>> vii; typedef pair<int,int> pi; typedef vector<pair<int,int>> pii; //-------------------------------------------------------------------------------------------------------------------------------------------------------------- const int no=3e6+5,modulo=1e9+7,inf=1e18,N=2e3+1; const double PI = 3.1415926535897932384; int ar[no] ,br[no],cr[no];//,dr[no],er[no]; int used[no]; //int color[no]; //pii adj[no]; vi adj[no] ; //LOWER_BOUND(n) - FIRST ELEMENT GREATER THAN EQUAL TO n //UPPER_BOUND(n) - FIRST ELEMENT GREATER THAN n //-------------------------------------------------------------------------------------------------------------------------------------------------------------- int mark[no]; vi ans; void dfs(int node) { used[node]=1; if(!mark[ar[node]]) ans.PB(node); mark[ar[node]]++; for(int child : adj[node]) { if(!used[child]) { dfs(child); } } mark[ar[node]]--; } void solve () { int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0,w=0,k=0; cin>>n; rep(i,1,n+1) cin>>ar[i]; m=n-1; rep(i,0,m) { cin>>x>>y; adj[x].PB(y); adj[y].PB(x); } dfs(1); sort(all(ans)); for(auto ii : ans) cout<<ii<<en; } inline void runn() { #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif } signed main() { night_rider runn(); int t=1; cout<<fixed<<setprecision(15); // cin>>t; rep(i,1,t+1) { // cout << "Case #" << i << ": "; solve(); } }
#pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma") #pragma GCC optimize("unroll-loops") // #include <atcoder/all> // #include <bits/stdc++.h> #include <complex> #include <queue> #include <set> #include <unordered_set> #include <list> #include <chrono> #include <random> #include <iostream> #include <algorithm> #include <cmath> #include <string> #include <vector> #include <map> #include <unordered_map> #include <stack> #include <iomanip> #include <fstream> using namespace std; // using namespace atcoder; typedef long long ll; typedef long double ld; typedef pair<ll, ll> p32; typedef pair<ll, ll> p64; typedef pair<p64, p64> pp64; typedef pair<double, double> pdd; typedef vector<ll> v64; typedef vector<int> v32; typedef vector<vector<int>> vv32; typedef vector<vector<ll>> vv64; typedef vector<vector<char>> vvc64; typedef vector<vector<p64>> vvp64; typedef vector<p64> vp64; typedef vector<p32> vp32; ll MOD = 998244353; double eps = 1e-12; #define forn(i, e) for (ll i = 0; i < e; i++) #define forsn(i, s, e) for (ll i = s; i < e; i++) #define rforn(i, s) for (ll i = s; i >= 0; i--) #define rforsn(i, s, e) for (ll i = s; i >= e; i--) #define ln '\n' #define dbg(x) cout << #x << " = " << x << ln #define mp make_pair #define pb push_back #define fi first #define se second #define f first #define s second #define INF 2e18 #define fast_cin() \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) #define all(x) (x).begin(), (x).end() #define sz(x) ((ll)(x).size()) #define zero ll(0) #define set_bits(x) __builtin_popcountll(x) #define pp pair<ll, p64> #define pc pair<int, char> ll mpow(ll a, ll b) { if (a == 0) return 0; if (b == 0) return 1; ll t1 = mpow(a, b / 2); t1 *= t1; t1 %= MOD; if (b % 2) t1 *= a; t1 %= MOD; return t1; } ll mpow(ll a, ll b, ll p) { if (a == 0) return 0; if (b == 0) return 1; ll t1 = mpow(a, b / 2, p); t1 *= t1; t1 %= p; if (b % 2) t1 *= a; t1 %= p; return t1; } void norm(ll &n) { n %= MOD; n += MOD; n %= MOD; } void dfs(int n, vv64 &adj, v64 &visited, int &count, int &m) { visited[n] = 1; count++; for (int i = 0; i < sz(adj[n]); i++) { m++; int c = adj[n][i]; if (visited[c] == 0) dfs(c, adj, visited, count, m); } } void solve(ll t) { int n; cin >> n; int m = 4e6; vv64 adj(m + 1); for (int i = 1; i <= n; i++) { int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } v64 visited(m + 1, 0); ll ans = 0; for (int i = 1; i <= m; i++) { if (visited[i] == 0) { int count = 0, edges = 0; dfs(i, adj, visited, count, edges); edges /= 2; ans += count; if (edges < count) ans--; } } cout << ans << endl; } int main() { fast_cin(); ll t = 1; // cin >> t; forn(i, t) { solve(i + 1); } }
#include<bits/stdc++.h> using namespace std; const int maxN = 1e6 + 100; int N, M, t[maxN], x[maxN], y[maxN], sz[maxN], vol[maxN]; int tata (int nod) { if (t[nod] == nod) return nod; return t[nod] = tata (t[nod]); } int main () { //freopen ("input", "r", stdin); //freopen ("output", "w", stdout); scanf ("%d", &M); for (int i=1; i<=M; i++) scanf ("%d %d", &x[i], &y[i]), N = max (N, max (x[i], y[i])); for (int i=1; i<=N; i++) t[i] = i, vol[i] = 0, sz[i] = 1; for (int i=1; i<=M; i++) { int a = tata (x[i]), b = tata (y[i]); if (a == b) vol[a] ++; else vol[a] += vol[b] + 1, sz[a] += sz[b], t[b] = a; } int ans = 0; for (int i=1; i<=N; i++) if (tata (i) == i) ans += min (sz[i], vol[i]); printf ("%d\n", ans); return 0; }
#include <iostream> #include <vector> #include <limits> #include <algorithm> #include <map> #include <math.h> using namespace std; using ll = long long; const int INT_INF = numeric_limits<int>::max(); const long long LL_INF = numeric_limits<long long>::max(); int main() { double A, B; cin >> A >> B; double C = 1 - B / A; cout << C * 100 << endl; return 0; }
#include <iostream> using namespace std; int main() { long s,p; cin>>s>>p; for(int i=1; i<=1000000; i++){ if(p%i==0&&i+p/i==s){ cout<<"Yes\n"; return 0; } } cout<<"No\n"; }
#include <algorithm> #include <iomanip> #include <iostream> using ld = long double; int main() { std::cout << std::fixed << std::setprecision(16); int N; ld D, H, res = -1.0; std::cin >> N >> D >> H; ld d, h, y; for (int i = 0; i < N; i++) { std::cin >> d >> h; y = ((h - H) * (-1 * D)) / (d - D); y+=H; // std::cout << y << '\n'; res = std::max(res, y); } ld t = 0.00; res = std::max(res, t); std::cout << res << '\n'; }
#include<bits/stdc++.h> typedef long long int lli; typedef long double lld; typedef long long ll; //Fast Input I/O #define fio ios_base::sync_with_stdio(false), cin.tie(NULL); //Datatype #define vi vector<int> #define vlli vector<long long int> #define vvi vector<vector<int>> #define vvlli vector<vector<long long int>> #define ppi pair<int, int> #define rppi pair<int, pair<int, int>> #define lppi pair<pair<int, int>, int> #define vppi vector<pair<int, int>> #define sppi stack<pair<int int>> #define qppi queue<pair<int, int>> //function #define f first #define s second #define pb(x) push_back(x) #define mkp(i, j) make_pair(i, j) #define lmkp(i,j,k) make_pair(make_pair(i,j),k) #define rmkp(i,j,k) make_pair(i,make_pair(j,k)) //loop #define loop(i,n) for (i = 0; i < n; ++i) #define loops(i,k,n) for (i = k; i <= n; ++i) #define looprev(i,k,n) for (i = k; i >= n; --i) //Const #define inf (int)1e9 #define eps 1e-9 #define PI 3.1415926535897932384626433832795 #define MOD 1000000007 //Print #define prd(n) printf("%d", n) #define prl(n) printf("%lld", n) #define prdn(n) printf("%d\n", n) #define prln(n) printf("%lld\n", n) #define prf(n) printf("%f", n) //Scan #define scd(n) scanf("%d", &n) #define scd2(a, b) scanf("%d %d", &a, &b) #define scd3(a, b, c) scanf("%d %d %d", &a, &b, &c) #define scl(n) scanf("%lld", &n) #define scl2(a, b) scanf("%lld %lld", &a, &b) #define scl3(a, b, c) scanf("%lld %lld %lld", &a, &b, &c) #define scf(n) scanf("%f", &n) #define all(x) (x).begin(), (x).end() using namespace std; void online_judge() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } void solve() { lli i, j, k; lld N, D, H, res = 0; cin >> N >> D >> H; loop(i, N) { lld d, h; cin >> d >> h; lld x = H - ((H - h) * D) / (D - d); res = max(res, x); } cout << res << "\n"; } int main() { fio; online_judge(); cout << fixed << setprecision(20); lli t = 1; //cin >> t; while (t--) { solve(); } return 0; }
#include<bits/stdc++.h> #define ll long long using namespace std; int main(){ int a,b,c,d; cin>>a>>b; cin>>c>>d; int maks = -999999; for(int i=a;i<=b;i++){ for(int j=c;j<=d;j++){ maks = max(maks,i-j); } }cout<<maks<<endl; }
#include<bits/stdc++.h> using namespace std; int main() { int a,b,c,d; cin>>a>>b>>c>>d; int result= b-c; cout<< result <<endl; return 0; }
#include <iostream> #include<vector> #include<algorithm> #include<string> #include<map> #include<set> #include<stack> #include<queue> #include<math.h> using namespace std; typedef long long ll; #define int long long #define double long double typedef vector<int> VI; typedef pair<int, int> pii; typedef vector<pii> VP; typedef vector<string> VS; typedef priority_queue<int> PQ; template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } #define fore(i,a) for(auto &i:a) #define REP(i,n) for(int i=0;i<n;i++) #define eREP(i,n) for(int i=0;i<=n;i++) #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 SORT(c) sort((c).begin(),(c).end()) #define rSORT(c) sort((c).rbegin(),(c).rend()) #define LB(x,a) lower_bound((x).begin(),(x).end(),(a)) #define UB(x,a) upper_bound((x).begin(),(x).end(),(a)) #define INF 1000000000 #define LLINF 9223372036854775807 #define mod 1000000007 #define eps 1e-12 //priority_queue<int,vector<int>, greater<int> > q2; signed main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; int ans = INF; REP(i, N) { int a, p, x; cin >> a >> p >> x; x -= a; if (x > 0)chmin(ans, p); } if (ans == INF)ans = -1; cout << ans << endl; return 0; }
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <functional> using namespace std; struct DataA { int a; char b; }; template<typename T> void vMap(vector<T>& dst, vector<T>& src, function<T(T)> callback) { transform(src.begin(), src.end(), dst.begin(), callback); } int main() { int A, B, C, D; cin >> A >> B >> C >> D; if (B >= C * D) { cout << -1 << endl; return 0; } int i = 0; int diff = C * D - B; while (true) { i++; A -= diff; if (A <= 0) { cout << i << endl; break; } } }
#include <bits/stdc++.h> using namespace std; using lli = long long int; using ii = pair<int, lli>; const int MAXN = 2e5; const lli MOD = 1e9+7; int n; vector<ii> adj[MAXN+1]; lli rootXor[MAXN+1]; void dfs(int u, int p, lli x) { rootXor[u] = x; for(ii v: adj[u]) { if(v.first == p) { continue; } dfs(v.first, u, x ^ v.second); } } lli safeMult(lli a, lli b) { if(!b) { return 0; } if(b%2) { return (safeMult(a, b-1) + a) % MOD; } else { lli aux = safeMult(a, b/2); return (aux + aux) % MOD; } } int main() { scanf("%d", &n); for(int i=0; i<n-1; i++) { int u, v; lli w; scanf("%d %d %lld", &u, &v, &w); adj[u].push_back({v, w}); adj[v].push_back({u, w}); } dfs(1, 1, 0); vector<lli> ones(60, 0); lli ans = 0; for(int i=1; i<=n; i++) { lli cand = 0; for(int j=0; j<60; j++) { lli zeroes = (i-1)-ones[j]; if(rootXor[i]&(lli(1) << j)) { cand += safeMult(lli(1) << j, zeroes); } else { cand += safeMult(lli(1) << j, ones[j]); } cand = cand % MOD; } ans = (ans + cand) % MOD; for(int j=0; j<60; j++) { if(rootXor[i]&(lli(1) << j)) { ones[j]++; } } } printf("%lld\n", ans); }
#include <bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define sc(x) scanf("%lld",&(x)); int n; vector<pair<int,int> > G[200005]; int dp[200005][62][2]; const int mod = 1e9+7; int ans = 0; void dfs(int x,int fa) { int w,t; for(auto &a : G[x]) { if(a.first != fa) { dfs(a.first,x); w = a.second; for(int i = 0; i <= 60; i++) { if((w >> i)&1) { dp[x][i][0] += dp[a.first][i][1]; dp[x][i][1] += dp[a.first][i][0] + 1; } else { dp[x][i][0] += dp[a.first][i][0] + 1; dp[x][i][1] += dp[a.first][i][1] ; } } } } for(auto &a:G[x]){ if(a.first != fa) { t = 1; w = a.second; for(int i = 0; i <= 60; i++) { if((w >> i)&1) { ans += ((dp[x][i][0] - dp[a.first][i][1])*(dp[a.first][i][0] + 1)%mod)*t%mod; ans %= mod; ans += ((dp[x][i][1] - dp[a.first][i][0] -1)*(dp[a.first][i][1])%mod) *t %mod; ans %= mod; } else { ans += (((dp[x][i][0] - dp[a.first][i][0]-1)*dp[a.first][i][1])%mod*t)%mod; ans %= mod; ans += (((dp[x][i][1] - dp[a.first][i][1] )*(dp[a.first][i][0]+1))%mod*t)%mod; ans %= mod; } t *= 2; t %= mod; } /*for(int i = 0; i <= 60; i++){ if(w>>i){ ans += (dp[x][i][0] - (dp[a.first][i][1] + 1)) *(dp[x][i][1] - (dp[a.first][i][0] + 1)); } }*/ } } w = 1; for(int j = 0; j <= 60; j++){ ans += 2*dp[x][j][1] * w; w *= 2; w %= mod; ans %= mod; } } int inv(int x){ int n = mod-2; int ans = 1; while(n){ if(n&1){ ans = ans*x; ans %= mod; } x = (x*x) %mod; n>>=1; } return ans; } signed main() { sc(n) int a,b,w; for(int i = 0; i < n-1; i++) { sc(a)sc(b)sc(w) G[a].push_back({b,w}); G[b].push_back({a,w}); } dfs(1,-1); w = 1; cout << (ans*inv(2))%mod << '\n'; }
// #pragma comment(linker, "/stack:200000000") // #pragma GCC optimize("Ofast") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <bits/stdc++.h> using namespace std; using i128 = __int128_t; using u128 = __uint128_t; using u64 = uint64_t; //define #define int long long #define ll int #define trav(i,v) for(auto i: v) #define rep(i,n) for(int i=0;i<n;i++) #define repu(i,k,n) for(int i=k;i<=n;i++) #define repd(i,k,n) for(int i=k;i>=n;i--) #define se second #define fi first #define pb push_back #define mp make_pair #define all(v) v.begin(), v.end() #define itn int #define sz(x) (int)x.size() //typedef typedef unsigned long long ull; typedef long double ld; typedef std::pair<int, int> pii; typedef std::vector<int> vi; typedef std::vector< pii > vii; typedef std::vector< std::vector<int> > vvi; typedef std::vector< std::pair < pii, int > > vpp; const long long MOD = 1000000007; // const long long MOD = 998244353; const long double PI = 3.141592653589793238; const long long pi = 31415926; const long long inf = 1000000000000000000; const long long small_inf = INT_MAX; int modpow(int x, int n, int mod = MOD){ int res=1; while(n>0){ if(n&1) res=res*x%mod; x=x*x%MOD; n>>=1;} return res;} int power(int x, int n){ int res=1; while(n>0){ if(n&1) res=res*x; x=x*x; n>>=1; } return res;} void init(){ } int find(int a, int b, vi *v){ int n1 = sz(v[a]), n2 = sz(v[b]); int x = 0; int mn = inf; repu(y,0,n2-1){ while(x<n1-1 && v[a][x]<v[b][y]) x++; mn = min(mn,abs(v[a][x]-v[b][y])); if(x) mn = min(mn,abs(v[a][x-1]-v[b][y])); } return mn; } void solve() { /*Don't hurry, nothing good comes if you rush*/ int n; cin>>n; vi cnt(3,0); map<char, int> mm; mm['R'] = 0; mm['G'] = 1; mm['B'] = 2; vector<char> c(2*n+1,0); vi v[3]; repu(i,1,2*n){ int tmp; cin>>tmp>>c[i]; cnt[mm[c[i]]]++; v[mm[c[i]]].pb(tmp); } int odd = 0, f=-1, a=-1, b=-1; rep(i,3){ sort(all(v[i])); if(cnt[i]%2){ if(a==-1) a=i; else b=i; odd++; } else f = i; } if(odd==0){ cout<<0<<endl; return; } if(cnt[f]==0){ cout<<find(a,b,v)<<endl; return; } cout<<min(find(a,f,v)+find(b,f,v), find(a,b,v))<<endl; } signed main(){ // #ifndef ONLINE_JUDGE // freopen("./input.txt", "r", stdin); // freopen("./output.txt", "w", stdout); // #endif ios_base::sync_with_stdio(0); cin.tie(NULL); int t23 = 1, tt23 = 1; // cin>>t23; init(); while(tt23<=t23) { // cout<<"Case #"<<tt23<<": "; solve(); tt23++; } cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll LINF = 1001001001001001001; #ifdef _DEBUG #define show(x) \ cerr << #x << " : "; \ showVal(x) template <typename T> void showVal(const T &a) { cerr << a << endl; } template <typename T> void showVal(const vector<T> &a) { for (const T &v : a) cerr << v << " "; cerr << endl; } template <typename T> void showVal(const vector<vector<T>> &a) { cerr << endl; for (const vector<T> &v : a) showVal(v); } #else #define show(x) #endif int main() { int n; cin >> n; n *= 2; vector<ll> a(n); vector<string> c(n); for (int i = 0; i < n; i++) { cin >> a[i] >> c[i]; } vector<vector<ll>> v(3); for (int i = 0; i < n; i++) { int p; if (c[i] == "R") { p = 0; } else if (c[i] == "G") { p = 1; } else { p = 2; } v[p].push_back(a[i]); } vector<int> t; for (int i = 0; i < 3; i++) { if (v[i].size() & 1) { t.push_back(i); } } ll ans = LINF; if (t.size() == 2) { sort(v[t[1]].begin(), v[t[1]].end()); for (int i = 0; i < v[t[0]].size(); i++) { int l = -1, r = v[t[1]].size(), m; while (abs(l - r) > 1) { m = (l + r) / 2; if (v[t[1]][m] <= v[t[0]][i]) { l = m; } else { r = m; } } if (l >= 0) ans = min(ans, abs(v[t[1]][l] - v[t[0]][i])); if (l + 1 < v[t[1]].size()) ans = min(ans, abs(v[t[1]][l + 1] - v[t[0]][i])); } t.push_back(3 - t[0] - t[1]); if (v[t[2]].size() != 0) { sort(v[t[2]].begin(), v[t[2]].end()); ll tans = 0; for (int d = 0; d < 2; d++) { ll tvans = LINF; for (int i = 0; i < v[t[d]].size(); i++) { int l = -1, r = v[t[2]].size(), m; while (abs(l - r) > 1) { m = (l + r) / 2; if (v[t[2]][m] <= v[t[d]][i]) { l = m; } else { r = m; } } if (l >= 0) tvans = min(tvans, abs(v[t[2]][l] - v[t[d]][i])); if (l + 1 < v[t[2]].size()) tvans = min(tvans, abs(v[t[2]][l + 1] - v[t[d]][i])); } tans += tvans; } ans = min(ans, tans); } } else { ans = 0; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int A, B, C; cin >> A >> B >> C; pair<int, int> p = {A, B}; string ans; string next = C == 0 ? "A" : "B"; while (true) { if (next == "A") { if (p.first < 0) { ans = "Aoki"; break; } p.first--; next = "B"; } else { if (p.second < 0) { ans = "Takahashi"; break; } p.second--; next = "A"; } } cout << ans << endl; }
#pragma GCC optimize("O3") #pragma GCC optimize ("unroll-loops") #define io_init cin.tie(0);ios::sync_with_stdio(0);cout<<fixed<<setprecision(20) #include <bits/stdc++.h> constexpr int INF = 2147483647; constexpr long long int INF_LL = 9223372036854775807; constexpr int MOD = 1000000007; constexpr double PI = 3.14159265358979323846; using namespace std; typedef long long int ll; typedef unsigned long long int ull; int main() { string S[3]; cin >> S[0] >> S[1] >> S[2]; set<char> st; for (int i = 0; i < 3; i++) { for (int j = 0; j < S[i].size(); j++)st.insert(S[i][j]); } if (st.size() > 10) { cout << "UNSOLVABLE" << endl; return 0; } map<char, int> mp; int tmp = 0; for (auto&& x : st) { mp[x] = tmp; tmp++; } vector<int> a = { 0,1,2,3,4,5,6,7,8,9 }; do { if (a[mp[S[0][0]]] == 0 || a[mp[S[1][0]]] == 0 || a[mp[S[2][0]]] == 0)continue; string N[3]; for (int i = 0; i < 3; i++) { N[i] = S[i]; for (int j = 0; j < N[i].size(); j++) { N[i][j] = a[mp[N[i][j]]] + '0'; } } ll n[3]; for (int i = 0; i < 3; i++)n[i] = stoll(N[i]); if (n[0] + n[1] == n[2]) { cout << N[0] << endl << N[1] << endl << N[2] << endl; return 0; } } while (next_permutation(a.begin(), a.end())); cout << "UNSOLVABLE" << endl; }
//#pragma GCC optimize ("O2") //#pragma GCC target ("avx2") #include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please int main() { cin.tie(0); ios::sync_with_stdio(false); int N, M, K; cin >> N >> M >> K; int A[200200] = {}; rep(i, K) { int a; cin >> a; A[a] = 1; } double L = 0, R = 1e18; double dp[200200] = {}; rep(i, 100) { double m = (L + R) / 2; double kari = 0; for (int i = N - 1; i >= 0; i--) { if (A[i] == 0) dp[i] = kari + 1; else dp[i] = m; kari += dp[i] / M; kari -= dp[i + M] / M; } if (dp[0] >= m) L = m; else R = m; } if (L > 1e17) { co(-1); } else { cout << setprecision(12) << L << endl; } Would you please return 0; }
#include <bits/stdc++.h> using namespace std; typedef long double ldb; #define pb push_back const int N = 1500005; struct pldld { ldb x,y; friend pldld operator + (const pldld x,const ldb y) { return {x.x,x.y+y}; } friend pldld operator + (const pldld x,const pldld y) { return {x.x+y.x,x.y+y.y}; } friend pldld operator - (const pldld x,const pldld y) { return {x.x-y.x,x.y-y.y}; } friend pldld operator / (const pldld x,const ldb y) { return {x.x/y,x.y/y}; } }dp[N],s[N]; int a[N],flag[N]; int n,m,k; int main() { cin>>n>>m>>k; for (int i=1;i<=k;++i) cin>>a[i],flag[a[i]]=1; for (int i=n-1;i>=0;--i) { if (flag[i]) dp[i]={1,0};else { dp[i]=((s[i+1]-s[i+m+1])/m)+1; } s[i]=s[i+1]+dp[i]; } if ((1-dp[0].x)<1e-9) {puts("-1");return 0;}; ldb ans=dp[0].y/(-dp[0].x+1); printf("%.10f\n",(double)ans); return 0; }
// Problem: E - Spread of Information // Contest: AtCoder - AtCoder Regular Contest 116 // URL: https://atcoder.jp/contests/arc116/tasks/arc116_e // Memory Limit: 1024 MB // Time Limit: 3000 ms // // Powered by CP Editor (https://cpeditor.org) #include <bits/stdc++.h> using namespace std; inline int read(){ int s=0,w=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();} while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar(); return s*w; } const int N=5e5+5; int n,m,cnt,f[N],g[N],is[N],head[N],ans,gs; struct nood { int nex,to; }; nood e[N*2]; inline void jia(int u,int v) { e[++cnt].nex=head[u]; head[u]=cnt; e[cnt].to=v; } inline void dfs(int u,int fa,int x) { f[u]=1e9; g[u]=-1e9; for ( int i=head[u];i;i=e[i].nex ) { int v=e[i].to; if(v==fa) continue; dfs(v,u,x); f[u]=min(f[v]+1,f[u]); g[u]=max(g[v]+1,g[u]); } if(is[u]&&f[u]>x) g[u]=max(g[u],0); if(g[u]+f[u]<=x) g[u]=-1e9; if(g[u]==x) gs++,g[u]=-1e9,f[u]=0; } inline bool check(int mid) { gs=0; dfs(1,0,mid); gs+=(g[1]>=0); return gs<=m; } int main() { n=read(); m=read(); for ( int i=1;i<=n;i++ ) is[i]=1; for ( int i=1;i<n;i++ ) { int x,y; x=read(),y=read(); jia(x,y); jia(y,x); } int l=0,r=n; while(l<=r) { int mid=(l+r)/2; if(check(mid)) { ans=mid; r=mid-1; } else l=mid+1; } printf("%d\n",ans); return 0; }
//================code===================// //#define TLE #ifdef TLE #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #endif #include <bits/stdc++.h> #include <unordered_map> #include <unordered_set> #include <random> #include <ctime> #define ci(t) cin>>t #define co(t) cout<<t #define LL unsigned long long #define ld long double #define fa(i,a,b) for(LL i=(a);i<(LL)(b);++i) #define fd(i,a,b) for(LL i=(a);i>(LL)(b);--i) #define setp pair<pair<int,int>,int> #define setl pair<LL,LL> #define micro 0.000001 using namespace std; //LL gcd(LL a, LL b) { return a % b ? gcd(b, a % b) : b; } //LL lcm(LL a, LL b) { return (a * b) / gcd(a, b); } #ifdef OHSOLUTION #define ce(t) cerr<<t #define AT cerr << "\n=================ANS=================\n" #define AE cerr << "\n=====================================\n" #define DB(a) cerr << __LINE__ << ": " << #a << " = " << (a) << endl; #else #define AT #define AE #define ce(t) #define __popcnt64 __builtin_popcountll #define __popcnt __builtin_popcount #endif pair <int, int> vu[9] = { {0,1},{1,0},{0,-1} ,{-1,0},{0,0},{1,0}, {-1,1} , {1,-1},{-1,-1} }; //RDLU EWSN template<typename T, typename U> void ckmax(T& a, U b) { a = a < b ? b : a; } template<typename T, typename U> void ckmin(T& a, U b) { a = a > b ? b : a; } struct gcmp { bool operator()(LL a, LL b) { return a < b; } bool operator()(setl a, setl b) { return a.second < b.second; } }; struct lcmp { bool operator()(LL a, LL b) { return a > b; } bool operator()(setl a, setl b) { return a.second > b.second; } }; const int max_v = 2e5 + 7; const int INF = 1e9 + 7; const LL LNF = (LL)5e18 + 7ll; const LL mod = 998244353; vector <int> adj[max_v]; struct node { int cn,sl,mr; }; node dfs(int idx,int dist,int par = -1) { if (~par && adj[idx].size() == 1) return { 0,INF,0 }; node ret = { 0,INF,-INF}; for (auto& x : adj[idx]) if (x != par) { node tmp = dfs(x, dist, idx); ret.cn += tmp.cn; ckmin(ret.sl, tmp.sl+1); ckmax(ret.mr, tmp.mr+1); } //if (ret.mr == -INF) ret.mr = 0; if (ret.sl == INF) { if (ret.mr >= dist) { ret.sl = 0; ret.mr = -INF; ++ret.cn; } } else { if (ret.sl == 2 * dist + 1 || ret.mr>=dist) { ++ret.cn; ret.sl = 0; ret.mr = -INF; } else if (ret.sl > dist) { ckmax(ret.mr, ret.sl - dist - 1); } else if(ret.sl+ret.mr <=dist) { ret.mr = -INF; } } if (par == -1 && ret.mr!=-INF) { ++ret.cn; } return ret; } int main() { #ifdef OHSOLUTION freopen("input.txt", "r", stdin); #endif ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, k; ci(n >> k); vector <setl> test; fa(i, 0, n - 1) { int x, y; ci(x >> y); --x, --y; adj[x].push_back(y); adj[y].push_back(x); if (x > y) swap(x, y); test.push_back({ x,y }); } if (n == k) { co(0); return 0; } int l = 1; int r = n; while (l != r) { int mid = l + r >> 1; if (dfs(0,mid).cn <= k) r = mid; else l = mid + 1; } co(l << "\n"); return 0; }
#include<iostream> using namespace std; int main(){ int N; cin>>N; if(N%2==0) cout<<"White"; else cout<<"Black"; }
#include<bits/stdc++.h> #define eps 1e-9 #define MOD1 998244353 #define MOD2 1000000007 #define INV_2 499122177 #define INF 1000000000 #define PI 3.14159265358979323846 using namespace std; int main() { ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); int m, h; cin >> m >> h; if(h%m == 0) cout << "Yes\n"; else cout << "No\n"; } //size
#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 A[200001], B[200001], 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]; } } const int CM = 1 << 17, CL = 12; char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct; const ll ma0 = 1157442765409226768; const ll ma1 = 1085102592571150095; const ll ma2 = 71777214294589695; const ll ma3 = 281470681808895; const ll ma4 = 4294967295; inline int getint() { if (ci - owa > 0) { memcpy(cn, owa, CL); ci -= CM; fread(cn + CL, 1, CM, stdin); } ll tmp = *(ll*)ci; if ((tmp & ma0) ^ ma0) { int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0); tmp = tmp << dig & ma1; tmp = tmp * 10 + (tmp >> 8) & ma2; tmp = tmp * 100 + (tmp >> 16) & ma3; tmp = tmp * 10000 + (tmp >> 32) & ma4; ci += (72 - dig >> 3); } else { tmp = tmp & ma1; tmp = tmp * 10 + (tmp >> 8) & ma2; tmp = tmp * 100 + (tmp >> 16) & ma3; tmp = tmp * 10000 + (tmp >> 32) & ma4; ci += 8; if ((ct = *ci++) >= '0') { tmp = tmp * 10 + ct - '0'; if (*ci++ == '0') { tmp = tmp * 10; ci++; } } } return tmp; } int main() { cin.tie(0); ios::sync_with_stdio(false); int N = getint(); rep1(i, N) A[i] = ll(i) << 32 | i + getint(); rep1(i, N) B[i] = ll(i) << 32 | i + getint(); 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; // #include <atcoder/all> // using namespace atcoder; #define rep(i,n) for (int i = 0; i < (n); ++i) using ll = long long; void solve(long long N, std::vector<long long> X){ set<int> all; vector<vector<int>> v(N, vector<int>(50)); rep(i, N) { ll x = X[i]; set<int> primes; for (ll j = 2; j <= x; j++) { while (x % j == 0) { primes.insert(j); x /= j; } } for (int p: primes) { all.insert(p); v[i][p] = 1; } } vector<int> al; for (auto a: all) { al.push_back(a); } int s = al.size(); ll ans = 1001001001001001001; for (int b = 0; b < (1 << s); b++) { vector<int> seen(N, 0); ll tmp = 1; rep(i, N) { for (int bi = 0; bi < s; bi++) { if ((b >> bi) & 1) { if (v[i][al[bi]] == 1) { seen[i] = 1; break; } } } } int cnt = 0; for (auto e: seen) { cnt += e; } if (cnt == N) { for (int bi = 0; bi < s; bi++) { if ((b >> bi) & 1) { tmp *= al[bi]; } } ans = min(ans, tmp); } } cout << ans << endl; } // Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools int main(){ long long N; scanf("%lld",&N); std::vector<long long> X(N); for(int i = 0 ; i < N ; i++){ scanf("%lld",&X[i]); } solve(N, std::move(X)); return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #define lb lower_bound #define ub upper_bound #define fe(x) (*(x.begin())) #define le(x) (*(x.rbegin())) #define pb push_back #define load(node,n) bool operator < (const node &n) const #define fbo(x,id) (*(x.find_by_order(id))) #define ook(y) order_of_key(y) #define all(x) (x).begin(),(x).end() #define si(a) scanf("%d",&a) #define sii(a,b) scanf("%d %d",&a,&b) #define siii(a,b,c) scanf("%d %d %d",&a,&b,&c) #define sl(a) scanf("%lld",&a) #define sll(a,b) scanf("%lld %lld",&a,&b) #define slll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c) #define rep(i,a,b) for(ll i = a; i<=b; i++) #define un(x) x.erase(unique(all(x)), x.end()) #define TT long long TC; scanf("%lld",&TC); for(ll tc = 1; tc<=TC; tc++) #define read freopen("input.txt","r",stdin) #define write freopen("output.txt","w",stdout) #define set(x) tree<x,null_type,less<x>,rb_tree_tag,tree_order_statistics_node_update> #define assign(v,n,x) v.clear(); for(int I = 0; I<n; I++) v.pb(x); #define SZ(x) (int)x.size() #define ff first #define ss second #define FF fflush(stdout); #define ms(AR,x) memset(AR,x,sizeof AR); #define case printf("Case %lld: ",tc); using namespace __gnu_pbds; using namespace std; typedef long long ll; typedef pair<ll,ll> pll; typedef pair<int,int> pii; #define mx 200003 ll ara[mx]; map<char,vector<ll> > ar; main(){ //read; int n; si(n); for(int i = 0; i<2*n; i++){ ll x; sl(x); char c; cin>>c; ar[c].pb(x); } ll ans = 0; vector<char> v; char d; for(auto i:ar){ if( SZ(i.ss)%2 ) v.pb(i.ff),ans = 9e18; else d = i.ff; } for(char X:{'R','G','B'}) sort(all(ar[X])); if(SZ(v)){ for(ll i:ar[v[0]]){ int id = lb( all(ar[v[1]]),i ) - ar[v[1]].begin(); id = min( id,SZ(ar[v[1]]) - 1 ); int id2 = id - 1; id2 = max(0,id2); ll x = ar[v[1]][id],y = ar[v[1]][id2]; ans = min( { ans, abs(i-x) , abs(i-y) } ); } if(SZ(ar[d])){ ll tmp[mx]; set<pll> st; for(ll i = 0; i<SZ(ar[d]); i++){ ll x = ar[d][i]; int id = lb( all(ar[v[1]]), x ) - ar[v[1]].begin(); id = min( id,SZ(ar[v[1]]) - 1 ); int id2 = id - 1; id2 = max(0,id2); ll p = min( abs(x - ar[v[1]][id] ) , abs( x - ar[v[1]][id2]) ); tmp[i] = p; st.insert(pll(p,i)); } for(ll i = 0; i<SZ(ar[d]); i++){ pll u = pll(tmp[i],i); st.erase(u); ara[i] = fe(st).ff; st.insert(u); } for(ll i = 0; i<SZ(ar[d]); i++){ ll x = ar[d][i],y,z; int id = lb(all(ar[v[0]]),x) - ar[v[0]].begin(); id = min( id, SZ(ar[v[0]]) - 1); int id2 = id - 1; id2 = max(0,id2); y = ar[v[0]][id]; z = ar[v[0]][id2]; ll p = min( abs(x - y), abs(x - z) ); ans = min(ans, p + ara[i]); } } } cout<<ans; return 0; }
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> using namespace std; const int N=5e5+10; typedef double lb; lb dp[N][2],sum[N][2]; int bk[N],m,n,k; int main(){ cin>>n>>m>>k; for(int i=1,x;i<=k;i++){ cin>>x;bk[x]=1; } dp[n][0]=dp[n][1]=0; for(int i=n-1;i>=0;i--){ if(bk[i]){ dp[i][0]=1;dp[i][1]=0; } else{ dp[i][0]=(sum[i+1][0]-sum[i+m+1][0])/(1.0*m); dp[i][1]=(sum[i+1][1]-sum[i+m+1][1])/(1.0*m)+1.0; } sum[i][0]=sum[i+1][0]+dp[i][0]; sum[i][1]=sum[i+1][1]+dp[i][1]; } if(fabs(dp[0][0]-1.0)<=1e-6){ puts("-1");return 0; } //lb ans=(lb)dp[0][1]/(1.0-dp[0][0]); //cout<<dp[0][1]<<" "<<dp[0][0]<<endl; printf("%.5lf",(lb)(dp[0][1]/(lb)(1.0-dp[0][0]))); }
//インクルード(アルファベット順) #ifndef TEMPLATE #define TEMPLATE #include<algorithm>//sort,二分探索,など #include<bitset>//固定長bit集合 #include<cmath>//pow,logなど #include<ctime> #include<complex>//複素数 #include<deque>//両端アクセスのキュー #include<functional>//sortのgreater #include<iomanip>//setprecision(浮動小数点の出力の誤差) #include<iostream>//入出力 #include<iterator>//集合演算(積集合,和集合,差集合など) #include<map>//map(辞書) #include<numeric>//iota(整数列の生成),gcdとlcm(c++17) #include<queue>//キュー #include<set>//集合 #include<stack>//スタック #include<string>//文字列 //#include<unordered_map>//イテレータあるけど順序保持しないmap //#include<unordered_set>//イテレータあるけど順序保持しないset #include<utility>//pair #include<vector>//可変長配列 #include<valarray>//なんとなく追加 //メモ:表示桁数を大きくする  cout << fixed << setprecision(20) << cm << endl; #include<cstdint> using namespace std; typedef long long ll; //マクロ //forループ関係 //引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか //Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる #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--) //xにはvectorなどのコンテナ #define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい #define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく #define MAX(x) *max_element(ALL(x)) //最大値を求める #define MIN(x) *min_element(ALL(x)) //最小値を求める //定数 #define INF 1000000000000 //10^12:極めて大きい値,∞ #define MOD 1000000007 //10^9+7:合同式の法 #define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用) //略記 #define PB push_back //vectorヘの挿入 #define MP make_pair //pairのコンストラクタ #define F first //pairの一つ目の要素 #define S second //pairの二つ目の要素 #define PI acos(-1.0) #define answer(ans) cout<<ans<<endl; #define input(N) cin >> N ; #endif // TEMPLATE int main(){ ll N; cin >> N; vector<string> S(N); vector<ll> T(N); REP(i,N){ cin >> S[i] >> T[i]; } ll max=0,maxi=-1; ll smax=0,smaxi=-1; if(T[0]>T[1]){ max=T[0]; maxi=0; smax=T[1]; smaxi=1; }else{ max=T[1]; maxi=1; smax=T[0]; smaxi=0; } for(int i=2;i<N;i++){ if(T[i]>max){ smax =max; smaxi = maxi; max = T[i]; maxi=i; }else if(T[i]>smax){ smax=T[i]; smaxi=i; } } cout << S[smaxi] << endl; return 0; }
#include<bits/stdc++.h> using namespace std; using namespace chrono; #define ff first #define ss second #define pb push_back #define ppb pop_back #define int long long #define mp make_pair #define all(x) (x).begin(), (x).end() #define pii pair<int,int> #define vi vector<int> #define mii map<int,int> #define pqb priority_queue<int> #define pqs priority_queue<int,vi,greater<int> > #define setbits(x) __builtin_popcountll(x) #define mod 1000000007 #define mod1 998244353 #define inf 1e18 #define ps(x,y) fixed<<setprecision(y)<<x #define mk(arr,n,type) type *arr=new type[n]; #define range(a,b) substr(a,b-a+1) #define w(x) int x; cin>>x; while(x--) #define trace(x) cerr<<#x<<": "<<x<<" "<<endl; #define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #ifndef ONLINE_JUDGE #define dbg(x) cerr << #x <<" "; _print(x); cerr << endl; #else #define dbg(x) #endif void _print(int t) {cerr << t;} void _print(string t) {cerr << t;} void _print(char t) {cerr << t;} void _print(double t) {cerr << t;} template <class T, class V> void _print(pair <T, V> p); template <class T> void _print(vector <T> v); template <class T> void _print(set <T> v); template <class T, class V> void _print(map <T, V> v); template <class T> void _print(multiset <T> v); template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";} template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]"<<endl;} template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} 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;} int power(int x, unsigned int y, int p){int res = 1;x = x % p;if (x == 0) return 0;while (y > 0){if (y & 1)res = (res*x) % p;y = y>>1;x = (x*x) % p;}return res;} int mod_inverse(int a, int p){return power(a, p - 2, p);} void swap(int &x, int &y) {int temp = x; x = y; y = temp;} vector<int> sieve(int n) {int*arr = new int[n + 1](); vector<int> vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;} int mod_add(int a, int b, int m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} int mod_mul(int a, int b, int m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;} int mod_sub(int a, int b, int m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} int mod_div(int a, int b, int m) {a = a % m; b = b % m; return (mod_mul(a, mod_inverse(b,m), m) + m) % m;} //only for prime m int modfact(int n, int p){if (p <= n)return 0;int res = (p - 1);for (int i = n + 1; i < p; i++)res = (res * mod_inverse(i, p)) % p;return res;} int fact(int n){if (n == 0)return 1;return n * fact(n - 1);} void solve(){ int n; cin>>n; vector<pair<int,string>> v(n); for(int i=0;i<n;i++){ cin>>v[i].ss>>v[i].ff; } sort(all(v)); cout<<v[n-2].ss<<endl; } int32_t main(){ FIO; #ifndef ONLINE_JUDGE freopen("Error.txt", "w", stderr); #endif auto start1 = high_resolution_clock::now(); //w(t) solve(); auto stop1 = high_resolution_clock::now(); auto duration = duration_cast<microseconds>(stop1 - start1); #ifndef ONLINE_JUDGE cerr << "Time: " << duration . count() / 1000 << " ms" <<endl; #endif return 0; }