code_file1
stringlengths
87
4k
code_file2
stringlengths
85
4k
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define ff first #define ss second #define int long long #define pb push_back #define mp make_pair #define 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 zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define inf 1e18 #define ps(x,y) fixed<<setprecision(y)<<x #define mk(arr,n,type) type *arr=new type[n]; #define w(x) int x; cin>>x; while(x--) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; void init() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } const int maxN = 3e5 + 5; int a[maxN] = {0}; int n; void update(int idx, int val) { while (idx <= n) { a[idx] ^= val; idx += (idx & -idx); } } int query(int idx) { int ans = 0; while (idx > 0) { ans ^= a[idx]; idx -= (idx & -idx); } return ans; } int32_t main() { init(); int q; cin >> n >> q; for (int i = 0; i < n; ++i) { int x; cin >> x; update(i + 1, x); } while (q--) { int t, x, y; cin >> t >> x >> y; if (t == 1) { update(x, y); } else { cout << (query(y) ^ query(x - 1)) << "\n"; } } return 0; }
#include <bits/stdc++.h> #define mp make_pair #define fi first #define se second #define pb push_back #define eb emplace_back #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define forn(i, n) for (int i = 0; i < (int)(n); ++i) #define for1(i, n) for (int i = 1; i <= (int)(n); ++i) #define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i) #define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i) #define rep(i, l, r) for (int i = (l); i <= (r); i++) #define per(i, r, l) for (int i = (r); i >= (l); i--) #define ms(x, y) memset(x, y, sizeof(x)) #define SZ(x) int(x.size()) #define fk cerr<<"fk"<<endl #define db(x) cerr<<(#x)<<'='<<(x)<<endl using namespace std; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pii> vpi; typedef vector<vi> vvi; typedef long long i64; typedef vector<i64> vi64; typedef vector<vi64> vvi64; typedef pair<i64, i64> pi64; typedef double ld; template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; } template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; } //1.integer overflow (1e5 * 1e5) (2e9 + 2e9) //2.runtime error //3.boundary condition const int N=300000+100; int n,q,a[N],tv[N*4]; void build(int node,int l,int r){ if(l==r){ tv[node]=a[l]; return; } int mid=(l+r)>>1; build(node<<1,l,mid); build(node<<1|1,mid+1,r); tv[node]=tv[node<<1]^tv[node<<1|1]; } void update(int node,int l,int r,int idx,int val){ if(l==r){ int tt=val^a[l]; tv[node]=tt; a[l]=tt; return; } int mid=(l+r)>>1; if(idx<=mid) update(node<<1,l,mid,idx,val); else update(node<<1|1,mid+1,r,idx,val); tv[node]=tv[node<<1]^tv[node<<1|1]; } int query(int node,int l,int r,int ql,int qr){ if(ql<=l && r<=qr){ return tv[node]; } int ret=0; int mid=(l+r)>>1; if(ql<=mid) ret^=query(node<<1,l,mid,ql,qr); if(qr>mid) ret^=query(node<<1|1,mid+1,r,ql,qr); return ret; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout<<fixed; #ifdef LOCAL_DEFINE freopen("input.txt", "r", stdin); #endif cin>>n>>q; for1(i, n){ cin>>a[i]; } build(1,1,n); forn(i, q){ int t,x,y; cin>>t>>x>>y; if(t==1) update(1,1,n,x,y); else cout<<query(1,1,n,x,y)<<'\n'; } #ifdef LOCAL_DEFINE cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; #endif return 0; }
// Author: Muhesh Kumar #include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using db = long double; using pi = pair<int, int>; using pl = pair<ll, ll>; using vi = vector<int>; using vl = vector<ll>; using vb = vector<bool>; using vs = vector<string>; using vpi = vector<pi>; using vpl = vector<pl>; using vvi = vector<vi>; using vvl = vector<vl>; using vvb = vector<vb>; #define nl '\n' #define fr first #define sc second #define bk back() #define ft front() #define pb push_back #define ppb pop_back #define lb lower_bound #define ub upper_bound #define bg(x) begin(x) #define all(x) bg(x), end(x) #define sz(x) (int) (x).size() #define amax(a, b) a = max(a, b) #define amin(a, b) a = min(a, b) #define trav(a, b) for(auto &a: b) #define rep(i, a, b) for(int i = a; i < b; i++) const ll inf = 1e18 + 10; const db eps = 1e-9; const int mod = 1e9 + 7; ll modadd(ll a, ll b, ll m = mod) { a %= m; b %= m; return (((a + b) % m) + m) % m; } ll modsub(ll a, ll b, ll m = mod) { a %= m; b %= m; return (((a - b) % m) + m) % m; } ll modmul(ll a, ll b, ll m = mod) { a %= m; b %= m; return (((a * b) % m) + m) % m; } ll gcd(ll a, ll b) { return __gcd(a, b); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } template <typename T1, typename T2> inline std::ostream &operator << (std::ostream& os, const std::pair<T1, T2>& p) { return os << "(" << p.first << ", " << p.second << ")"; } template<typename T> inline std::ostream &operator << (std::ostream& os,const std::vector<T>& v) { bool first = true; os << "["; for(unsigned int i = 0; i < v.size(); i++) { if(!first) os << ", "; os << v[i]; first = false; } return os << "]"; } template<typename T> inline std::ostream &operator << (std::ostream& os,const std::vector<vector<T>>& v) { bool first = true; os << "[\n "; for(unsigned int i = 0; i < v.size(); i++) { if(!first) os << ",\n "; os << v[i]; first = false; } return os << "\n]"; } template<typename T> inline std::ostream &operator << (std::ostream& os,const std::set<T>& v) { bool first = true; os << "["; for (typename std::set<T>::const_iterator ii = v.begin(); ii != v.end(); ++ii) { if(!first) os << ", "; os << *ii; first = false; } return os << "]"; } template<typename T1, typename T2> inline std::ostream &operator << (std::ostream& os,const std::map<T1, T2>& v) { bool first = true; os << "[\n "; for (typename std::map<T1, T2>::const_iterator ii = v.begin(); ii != v.end(); ++ii) { if(!first) os << ",\n "; os << *ii ; first = false; } return os << "\n]"; } #ifndef ONLINE_JUDGE #define debug(a) cerr << #a << " " << a << '\n'; #else #define debug(a) #endif int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; string s; cin >> s; stack<char> st; trav (i, s) { st.push(i); if (sz(st) >= 3) { string t; int T = 3; while (T--) { t.pb(st.top()); st.pop(); } reverse(all(t)); if (t != "fox") { trav (j, t) st.push(j); } } } cout << sz(st); return 0; }
#include<bits/stdc++.h> using namespace std; int n,t,i; char s[200005],c[200005]; int main(){ cin >>n; cin >>s; for(int i=0;i<n;i++) if(s[i]=='x'&&t>1&&c[t]=='o'&&c[t-1]=='f') t-=2; else c[++t]=s[i]; cout <<t <<"\n"; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++) #define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--) #define all(v) v.begin(), v.end() void chmax(ll &x, ll y) {x = max(x,y);} void chmin(ll &x, ll y) {x = min(x,y);} void Yes() {cout << "Yes" << endl; exit(0);} void No() {cout << "No" << endl; exit(0);} template<class in_Cout> void Cout(in_Cout x) {cout << x << endl; exit(0);} template<class in_vec_cout> void vec_cout(vector<in_vec_cout> vec) { for (in_vec_cout res : vec) {cout << res << " ";} cout << endl; } const ll inf = 1e18; const ll mod = 1e9 + 7; int main() { ll N, M, Q; cin >> N >> M >> Q; vector<ll> W(N), V(N); rep(i,N) cin >> W[i] >> V[i]; vector<ll> X(M); rep(i,M) cin >> X[i]; vector<pair<ll,ll>> P(N); rep(i,N) P[i] = {V[i],W[i]}; sort(all(P),greater<pair<ll,ll>>()); vector<ll> res(Q); rep(q,Q) { ll l, r; cin >> l >> r; l--; r--; vector<ll> box; rep(i,M) if (i<l || r<i) box.push_back(X[i]); sort(all(box)); ll n = box.size(); vector<bool> used(n); ll tmp = 0; rep(i,N) { ll v = P[i].first, w = P[i].second; rep(j,n) { if (used[j]) continue; if (w<=box[j]) { tmp += v; used[j] = true; break; } } } res[q] = tmp; } for (ll ans : res) cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; #define rep(i, n) for(int i=0; i<n; i++) struct Data { ll w, v; Data(ll w, ll v) : w(w), v(v) {} bool operator < (const Data &d) const { if (d.v == v) { return d.w > w; } else { return d.v < v; } } }; int main() { int N, M, Q; cin >> N >> M >> Q; vector<Data> d; int X[M]; ll W, V; for (int i = 0; i < N; i++) { cin >> W >> V; d.push_back(Data(W, V)); } for (int i = 0; i < M; i++) { cin >> X[i]; } int L, R; sort(d.begin(), d.end()); for (int i = 0; i < Q; i++) { cin >> L >> R; ll ans = 0; L--; R--; bool flag[M] = {}; for (int j = 0; j < N; j++) { int id = -1; for (int k = 0; k < M; k++) { if (L <= k && k <= R) continue; if (!flag[k] && d[j].w <= X[k]) { if (id == -1) { id = k; } else if (X[k] < X[id]) { id = k; } } } if (id != -1) { ans += d[j].v; flag[id] = true; } } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)n;++i) #define irep(i,a,b) for(int i=int(a);i<(int)b;++i) #define rrep(i,a,b) for(int i=int(a);i>=(int)b;--i) #define vi vector<int> #define vvi vector<vector<int>> #define vl vector<ll> #define vvl vector<vector<ll>> #define vvp vector<vector<pair<ll,ll>>> #define vpl vector<pair<ll,ll>> #define vpi vector<pair<int,int>> #define pb push_back #define se second #define fi first #define all(v) v.begin(),v.end() #define v(T) vector<T> #define vv(T) vector<vector<T>> using namespace std; template<typename T> istream& operator>>(istream&i,v(T)&v){rep(j,v.size())i>>v[j];return i;} template<typename T> string join(const v(T)&v){stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);} template<typename T> ostream& operator<<(ostream&o,const v(T)&v){if(v.size())o<<join(v);return o;} using ll = long long; const ll INF = LLONG_MAX-1e9; const double PI = acos(-1); const ll mod = 1e9 + 7; //998244353; template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } ll modpow(ll a,ll b){ if(b == 0){ return 1; } if(b%2 == 0){ ll tmp = modpow(a,b/2); return tmp*tmp%mod; }else{ return modpow(a,b-1)*a%mod; } } ll c[31][31]; int main(void) { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); int a,b; cin >> a >> b; ll k; cin >> k; rep(i,31){ c[i][0] = 1; c[0][i] = 1; } rep(i,30)rep(j,30){ c[i+1][j+1] = c[i+1][j]*(i+j+2); c[i+1][j+1]/= j+1; } int ad = a+b; string ans = ""; rep(i,ad){ if(a == 0) ans += 'b'; else if(c[a-1][b] >= k){ --a; ans += 'a'; }else{ k -= c[a-1][b]; b--; ans+= 'b'; } //cout << c[a-1][b]<< endl; } cout << ans << endl; return 0; }
#pragma GCC optimize("O3") #include<bits/stdc++.h> using namespace std; using ll=long long; using P=pair<ll,ll>; template<class T> using V=vector<T>; #define fi first #define se second #define all(v) (v).begin(),(v).end() const ll inf=(1e18); //const ll mod=998244353; const ll mod=1000000007; ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;} ll LCM(ll c,ll d){return c/GCD(c,d)*d;} struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init; template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } template<class T>void debag(const vector<T> &a){cerr<<"debag :";for(auto v:a)cerr<<v<<" ";cerr<<"\n";} template<class T>void print(const vector<T> &a){for(auto v:a)cout<<v<<" ";cout<<"\n";} struct mint{ using ull=unsigned long long int; ull v; mint(ll vv=0){s(vv%mod+mod);} mint& s(ull vv){ v=vv<mod?vv:vv-mod; return *this; } //オーバーロード mint operator-()const{return mint()-*this;}//mint型にキャスト mint&operator+=(const mint&val){return s(v+val.v);} mint&operator-=(const mint&val){return s(v+mod-val.v);} mint&operator*=(const mint&val){ v=ull(v)*val.v%mod; return *this; } mint&operator/=(const mint&val){return *this*=val.inv();} mint operator+(const mint&val){return mint(*this)+=val;} mint operator-(const mint&val){return mint(*this)-=val;} mint operator*(const mint&val){return mint(*this)*=val;} mint operator/(const mint&val){return mint(*this)/=val;} mint pow(ll n)const{ mint res(1),x(*this); while(n){ if(n&1)res*=x; x*=x; n>>=1ll; } return res; } mint inv()const{return pow(mod-2);} //拡張ユークリッドの互除法 /* mint inv()const{ int x,y; int g=extgcd(v,mod,x,y); assert(g==1); if(x<0)x+=mod; return mint(x); }*/ friend ostream& operator<<(ostream&os,const mint&val){ return os<<val.v; }//出力 bool operator<(const mint&val)const{return v<val.v;} bool operator==(const mint&val)const{return v==val.v;} bool operator>(const mint&val)const{return v>val.v;} }; const ll MAX = 2000010;//設定 mint fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void init(){ fac[0] = fac[1] = 1; for(int i=1;i<MAX;i++)fac[i]=fac[i-1]*i; finv[MAX-1]=fac[MAX-1].inv(); for(int i=MAX-2;i>=0;i--)finv[i]=finv[i+1]*(i+1); for(int i=MAX-2;i>=1;i--)inv[i]=finv[i]+fac[i-1]; } //階乗 mint factor(ll n,ll k){ if (n<k) return 0; if (n<0 || k<0) return 0; return fac[n]*finv[k]; } // 二項係数計算 mint 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]; } int main(){ init(); ll n,m,k; cin>>n>>m>>k; mint ALL=COM(n+m,n); if(n>k+m){ cout<<0<<"\n"; return 0; } cout<<ALL-COM(n+m,m+k+1)<<"\n"; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<long long>A(N+1); for(int i=0; i<N; i++)cin >>A[i]; long long ans=1; sort(A.begin(), A.end()); for(int i=1; i<N+1; i++){ ans*=A[i]-A[i-1]+1; ans%=1000000007; } cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)(n);i++) #define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++) #define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--) #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++) #define setp(n) fixed << setprecision(n) template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } #define ll long long #define vll vector<ll> #define vi vector<int> #define pll pair<ll,ll> #define pi pair<int,int> #define all(a) (a.begin()),(a.end()) #define rall(a) (a.rbegin()),(a.rend()) #define fi first #define se second #define pb push_back #define ins insert #define debug(a) cerr<<(a)<<endl #define dbrep(a,n) rep(_i,n) cerr<<(a[_i])<<" "; cerr<<endl #define dbrep2(a,n,m) rep(_i,n){rep(_j,m) cerr<<(a[_i][_j])<<" "; cerr<<endl;} using namespace std; template<class A, class B> ostream &operator<<(ostream &os, const pair<A,B> &p){return os<<"("<<p.fi<<","<<p.se<<")";} template<class A, class B> istream &operator>>(istream &is, pair<A,B> &p){return is>>p.fi>>p.se;} template<class T> vector<T> make_vec(size_t a){ return vector<T>(a); } template<class T, class... Ts> auto make_vec(size_t a, Ts... ts){ return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); } //------------------------------------------------- //--ModInt //------------------------------------------------- const uint_fast64_t MOD = 1e9+7; class mint { private: using Value = uint_fast64_t; Value n; public: mint():n(0){} mint(int_fast64_t _n):n(_n<0 ? MOD-(-_n)%MOD : _n%MOD){} mint(const mint &m):n(m.n){} friend ostream& operator<<(ostream &os, const mint &a){ return os << a.n; } friend istream& operator>>(istream &is, mint &a){ Value temp; is>>temp; a = mint(temp); return is; } mint& operator+=(const mint &m){n+=m.n; n=(n<MOD)?n:n-MOD; return *this;} mint& operator-=(const mint &m){n+=MOD-m.n; n=(n<MOD)?n:n-MOD; return *this;} mint& operator*=(const mint &m){n=n*m.n%MOD; return *this;} mint& operator/=(const mint &m){return *this*=m.inv();} mint& operator++(){return *this+=1;} mint& operator--(){return *this-=1;} mint operator+(const mint &m) const {return mint(*this)+=m;} mint operator-(const mint &m) const {return mint(*this)-=m;} mint operator*(const mint &m) const {return mint(*this)*=m;} mint operator/(const mint &m) const {return mint(*this)/=m;} mint operator++(int){mint t(*this); *this+=1; return t;} mint operator--(int){mint t(*this); *this-=1; return t;} bool operator==(const mint &m) const {return n==m.n;} bool operator!=(const mint &m) const {return n!=m.n;} mint operator-() const {return mint(MOD-n);} mint pow(Value b) const { mint ret(1), m(*this); while(b){ if (b & 1) ret*=m; m*=m; b>>=1; } return ret; } mint inv() const {return pow(MOD-2);} }; //------------------------------------------------- int main(void) { cin.tie(0); ios::sync_with_stdio(false); int N; cin>>N; vll a(N); rep(i,N) cin>>a[i]; mint ans = 1; sort(all(a)); ll cur = 0; rep(i,N){ ans *= a[i]-cur+1; cur = a[i]; } cout<<ans<<"\n"; return 0; }
#include<bits/stdc++.h> #define LL long long using namespace std; int Len,fact[400010]; char str[400010]; LL ans,KSM[5][400010],f[400010],g[400010]; LL crt_m[1010],crt_r[1010],crt_cnt; inline int read() { int x=0;bool w=0;char ch=0; while(!isdigit(ch)){w|=ch=='-';ch=getchar();} while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();} return w?-x:x; } LL ksm(LL B,LL K,LL P,LL A=1) { for(;K;K>>=1,B=B*B%P) if(K&1)A=A*B%P; return A%P; } LL G(LL N,LL P) { if(g[N]!=-1)return g[N]; return g[N]=(N<P?0:N/P+G(N/P,P)); } LL F(LL N,LL P,LL PK,LL A=1) { if(f[N]!=-1)return f[N]; if(!N)return f[N]=1; return f[N]=KSM[fact[PK]][N/PK]*fact[N%PK]%PK*F(N/P,P,PK)%PK; } LL C_pk(LL N,LL M,LL P,LL PK) { LL fz=F(N,P,PK),fm1=F(M,P,PK),fm2=F(N-M,P,PK); return fz*fm1%PK*fm2%PK*(G(N,P)-G(M,P)-G(N-M,P)==0)%PK; } int main() { fact[0]=1; memset(g,-1,sizeof g); memset(f,-1,sizeof f); for(int i=1;i<=3;i++) if(i%3)fact[i]=fact[i-1]*i%3; else fact[i]=fact[i-1]; KSM[0][0]=KSM[1][0]=KSM[2][0]=1; for(int i=1;i<=400000;i++){ KSM[1][i]=1; KSM[2][i]=KSM[2][i-1]*2%3; } Len=read(); scanf("%s",str+1); for(int i=1;i<=Len;i++) if(str[i]=='B')ans=(ans+C_pk(Len-1,i-1,3,3)*0)%3; else if(str[i]=='W')ans=(ans+C_pk(Len-1,i-1,3,3)*1)%3; else ans=(ans+C_pk(Len-1,i-1,3,3)*2)%3; if(Len%2==0)ans=(-ans+3)%3; if(ans==0)printf("B\n"); else if(ans==1)printf("W\n"); else printf("R\n"); return 0; }
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; int comb[10][10]; int lucas (int n, int k) { int res = 1; while (n > 0) { res *= comb[n % 3][k % 3]; n /= 3; k /= 3; res %= 3; } return res; } signed main() { ios::sync_with_stdio(false); cin.tie(0); comb[0][0] = 1; for (int i = 1; i < 4; i++) { for (int j = 0; j <= i; j++) { comb[i][j] = comb[i - 1][j]; if (j > 0) comb[i][j] += comb[i - 1][j - 1]; } } int n; cin >> n; string s; cin >> s; int res = 0; for (int i = 0; i < n; i++) { int c = 0; if (s[i] == 'R') c = 0; if (s[i] == 'W') c = 1; if (s[i] == 'B') c = 2; res += c * lucas(n - 1, i); res %= 3; } if (n % 2 == 0) res = (3 - res) % 3; cerr << res << endl; if (res == 0) cout << 'R'; if (res == 1) cout << 'W'; if (res == 2) cout << 'B'; cout << endl; return 0; }
#include <bits/stdc++.h> #include <math.h> using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (int)(n); i ++) vector <int> dy = {0, 1, 0, -1}; vector <int> dx = {1, 0, -1, 0}; const int INF = 1000000000; const ll INFLL = 100000000000000000; int main(){ int n, m; cin >> n >> m; vector <ll> a(n); rep(i, n) cin >> a.at(i); vector <vector<int>> G(n); rep(i, m){ int x, y; cin >> x >> y; x--; y--; G.at(x).push_back(y); } vector <ll> dp(n, -INFLL); ll ans = -INFLL; vector <int> seen(n, -1); for(int i = n - 1; i >= 0; i --){ seen.at(i) = 1; auto children = G.at(i); //if(children.size() == 0) continue; //sort(children.rbegin(), children.rend()); // auto great_child = children.at(0); // dp.at(i) = max(dp.at(i), max(dp.at(great_child) + a.at(great_child) - a.at(i), a.at(great_child) - a.at(i))); for(auto child: children){ dp.at(i) = max(dp.at(i), max(dp.at(child) + a.at(child) - a.at(i), a.at(child) - a.at(i))); } ans = max(ans, dp.at(i)); //cout << dp.at(i) << endl; } cout << ans << endl; }
#include <iostream> #include <cstdio> #include <queue> using namespace std; const int maxn = 2050,inf = 1e9; int n,m,x,y,z,last[maxn],ms[maxn],vis[maxn],dis[maxn],g[maxn][maxn]; struct Edge{ int v,w,nxt; }e[maxn]; priority_queue <pair<int,int> > q; int read(){ int x = 0; char c = getchar(); while(c < '0' || c > '9') c = getchar(); while(c >= '0' && c <= '9') x = x * 10 + (c ^ 48),c = getchar(); return x; } inline void insert(int u,int v,int w){ static int cnt = 0; e[++cnt] = {v,w,last[u]},last[u] = cnt; } void Dijkstra(int S){ for(int i = 1; i <= n; i ++) vis[i] = 0,dis[i] = inf; dis[S] = 0,q.push({0,S}); while(!q.empty()){ int u = q.top().second; q.pop(); if(vis[u]) continue; vis[u] = 1; for(int i = last[u]; i; i = e[i].nxt){ int v = e[i].v; if(dis[u] + e[i].w < dis[v]){ dis[v] = dis[u] + e[i].w; q.push({-dis[v],v}); } } } for(int i = 1; i <= n; i ++) g[S][i] = dis[i]; g[S][S] = inf; } int main(){ n = read(),m = read(); for(int i = 1; i <= n; i ++) ms[i] = inf; for(int i = 1; i <= m; i ++){ x = read(),y = read(),z = read(); if(x == y){ ms[x] = min(ms[x],z); continue; } insert(x,y,z); } for(int i = 1; i <= n; i ++) Dijkstra(i); for(int i = 1; i <= n; i ++){ int mn = inf; for(int j = 1; j <= n; j ++) mn = min(mn,g[i][j] + g[j][i]); printf("%d\n",mn == inf && ms[i] == inf ? -1 : min(mn,ms[i])); } return 0; }
#include<bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; using namespace std; int main() { int n; cin >> n; map<int, int> m; rep(i, n) { int a; cin >> a; if (m.count(a)) { m[a] = m[a] + 1; } else { m[a] = 1; } } // (i + j)Cj = dp[i][j] ll dp[300010][10] = {0}; dp[0][0] = 1; for (int i = 0; i <= 300000; i++) { for (int j = 0; j <= 2; j++) { if (i > 0) dp[i][j] += dp[i - 1][j]; if (j > 0) dp[i][j] += dp[i][j - 1]; } } ll ans = dp[n - 2][2]; for (auto v : m) { if (v.second > 1) ans -= dp[v.second - 2][2]; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; // template {{{ using i32 = int; using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; #define range(i, l, r) for (i64 i = (i64)(l); i < (i64)(r); (i) += 1) #define rrange(i, l, r) for (i64 i = (i64)(r) - 1; i >= (i64)(l); (i) -= 1) #define whole(f, x, ...) ([&](decltype((x)) container) { return (f)( begin(container), end(container), ## __VA_ARGS__); })(x) #define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x) #define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl constexpr i32 inf = 1001001001; constexpr i64 infll = 1001001001001001001ll; constexpr i32 dx[] = {0, -1, 1, 0, -1, 1, -1, 1}; constexpr i32 dy[] = {-1, 0, 0, 1, -1, -1, 1, 1}; struct IoSetup { IoSetup(i32 x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup; template <typename T = i64> T input() { T x; cin >> x; return x; } template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != (int)v.size() ? " " : ""); } return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; } template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; } template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; } template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); } template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); } 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); } // }}} void solve() { int n = input(); map<int, int> cnt; i64 ans = 0; range(i, 0, n) { int a = input(); ans += i - cnt[a]; cnt[a]++; } cout << ans << endl; } signed main() { solve(); }
#include <cstdio> #include <algorithm> using namespace std; typedef long long LL; LL mod = 998244353; LL N , M , K; LL qpow(LL a , LL b) { LL res = 1; while(b) { if(b & 1) res = res * a % mod; a = a * a % mod; b >>= 1; } return res; } int main() { scanf("%lld %lld %lld" , &N , &M , &K); if(N == 1 || M == 1) { printf("%lld" , qpow(K , max(N , M))); return 0; } LL ans = 0; for (int i = 1; i <= K; ++i) { ans = (ans + (qpow(i , N) - qpow(i - 1 , N) + mod) % mod * qpow(K - i + 1 , M) % mod) % mod; } printf("%lld" , ans); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; #define fi first #define se second #define mp make_pair #define pb push_back #define rep(i,n) for (int i=1;i <=int(n);i++) #define rrep(i,n) for(int i= int(n);i>=1;i--) #define ffor(i,n) for (int i=0;i <int(n);i++) #define pii pair<int,int> #define type pair<pair<ll,ll>,pair<ll,ll>> int a[1001],b[1001]; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n,d,h; cin >> n >> d >> h; rep(i,n){ cin >> a[i] >> b[i]; } double ans = 0; rep(i,n){ double res = (h - b[i]) * double(d)/(d-a[i]); ans = max (ans,h-res); } cout << ans << '\n'; return 0; } //check for bounds
#include<iostream> #include<vector> #include<bitset> #include<algorithm> using namespace std; unsigned xorshift() { static unsigned y=2463534242; y^=y<<13; y^=y>>17; y^=y<<5; return y; } const int N=20; int M; string S[800]; string outH[N],outW[N]; int G[800][800]; using bit=bitset<800>; bit rest; bit can[N+1][800]; int cnt[800]; int main() { cin>>M>>M; vector<int>idx(M); for(int i=0;i<M;i++) { cin>>S[i]; rest[i]=1; cnt[i]=1; idx[i]=i; } sort(idx.begin(),idx.end(),[](int i,int j){return S[i].size()<S[j].size();}); for(int i:idx)for(int j:idx)if(i!=j&&rest[j]) { for(int k=1;k<=S[i].size();k++) { int len=S[i].size()-k; if(S[j].size()<len)len=S[j].size(); if(S[i].substr(k,len)==S[j].substr(0,len)) { G[i][j]=S[j].size()-len; if(G[i][j]==0) { rest[j]=0; cnt[i]+=cnt[j]; cnt[j]=0; } break; } } } for(int tm=0;tm<N;tm++) { string now=""; if(rest.any()) { vector<vector<int> >dist(N+1,vector<int>(M,0)); vector<vector<int> >pr(N+1,vector<int>(M,-1)); for(int v=0;v<M;v++)if(rest[v]) { for(int u=S[v].size();u<=N;u++) { dist[u][v]=cnt[v]; can[u][v]=rest; can[u][v][v]=0; } } for(int u=0;u<N;u++)for(int v=0;v<M;v++)if(dist[u][v]) { for(int w=0;w<M;w++)if(can[u][v][w]) { int nu=u+G[v][w]; if(nu<=N&&dist[nu][w]<dist[u][v]+cnt[w]) { dist[nu][w]=dist[u][v]+cnt[w]; pr[nu][w]=v; can[nu][w]=can[u][v]; can[nu][w][w]=0; } } } int go=-1; for(int v=0;v<M;v++)if(go==-1||dist[N][v]>dist[N][go])go=v; vector<int>vs; { int nu=N; while(true) { vs.push_back(go); int ngo=pr[nu][go]; if(ngo<0)break; nu-=G[ngo][go]; go=ngo; } } now=S[go]; for(int i=vs.size()-1;i--;) { int d=G[go][vs[i]]; go=vs[i]; now+=S[go].substr(S[go].size()-d); } } while(now.size()<N)now+='.'; cout<<now<<endl; outW[tm]=now+now; for(int j=0;j<N;j++)outH[j]+=now[j]; for(int i=0;i<M;i++)if(rest[i]) { for(int k=0;k<N;k++)if(outW[tm].substr(k,S[i].size())==S[i]) { rest[i]=0; break; } if(rest[i]&&tm+1>=S[i].size()) { for(int j=0;j<N;j++)if(outH[j].substr(tm+1-S[i].size())==S[i]) { rest[i]=0; break; } } } } }
#include <iostream> #include <cmath> #include <string> #include <vector> #include <algorithm> #include <utility> #include <tuple> #include <cstdint> #include <cstdio> #include <map> #include <queue> #include <set> #include <stack> #include <deque> #include <unordered_map> #include <unordered_set> #include <cassert> #include <time.h> #define rep(i, n) for(int i = 0; i < n; i++) #define per(i, n) for(int i = n - 1; i >= 0; i--) using ll = long long; #define vi vector<int> #define vvi vector<vi> #define vl vector<ll> #define vd vector<double> #define vvd vector<vd> #define pii pair<int, int> #define pll pair<ll, ll> #define pdi pair<double, int> #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() using namespace std; constexpr int n = 20; int m; vector<string> s; vector<deque<string>> ss(n + 1); vvi board(n, vi(n)); void tekitou_sort(){ rep(i, n){ int nokori = n; while(true){ bool found = false; for(int j = nokori; j >= 0; j--) if(!ss[j].empty()){ found = true; rep(k, j) board[i][n-nokori+k] = ss[j][0][k] - 'A'; nokori -= j; ss[j].pop_front(); break; } if(!found) break; } } } void inputs(){ cin >> m >> m; s.resize(m); rep(i, m) cin >> s[i]; } int main(){ srand(time(NULL)); inputs(); rep(i, m) ss[s[i].size()].push_back(s[i]); rep(i, n) rep(j, n) board[i][j] = rand() % 8; tekitou_sort(); rep(i, n){ rep(j, s[i].size()) board[i][j] = s[i][j] - 'A'; } rep(i, n){ rep(j, n) printf("%c", board[i][j] + 'A'); printf("\n"); } }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { int a, b, c; cin >> a >> b >> c; cout << 7 * 3 - (a + b + c) << endl; }
#include <bits/stdc++.h> using namespace std; int f(int x){ return 7 - x; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int a, b, c; cin >> a >> b >> c; cout << f(a) + f(b) + f(c) << '\n'; return 0; }
#include<bits/stdc++.h> #define ll long long int #define pll pair<ll,ll> #define vpll vector< pll > #define mpll map<ll,ll> #define MOD 1000000007 #define all(v) v.begin(),v.end() #define s(v) v.size() #define test ll t;cin>>t;while(t--) #define vec vector<ll> #define read0(v,n) for(int i=0;i<n;i++)cin>>v[i]; #define read1(v,n) for(int i=1;i<=n;i++)cin>>v[i]; #define trav(a,x) for (auto& a: x) #define fast ios_base::sync_with_stdio(false);cin.tie(NULL); #define cut(x) {cout<<x;return 0;} #define print(x) {cout<<x<<nl;continue;} #define FOR(i,a,b) for(int i=a;i<=b;i++) #define FORB(i,a,b) for(int i=a;i>=b;i--) #define err1(a) {cout<<#a<<' '<<a<<nl;} #define err2(a,b) {cout<<#a<<' '<<a<<' '<<#b<<' '<<b<<nl;} #define mp make_pair #define pb push_back #define eb emplace_back #define f first #define sc second #define lb lower_bound #define ub upper_bound #define nl '\n' #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #define oset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> ll gcd(ll a, ll b) { if (b==0)return a; return gcd(b, a % b); } ll lcm(ll a,ll b) { return (a*b)/gcd(a,b); } ll bpow(ll a, ll b) { ll ans=1; while(b) { if(b&1) ans=(ans*a)%MOD; b/=2; a=(a*a)%MOD; } return ans; } ll dp[26][200005]; int main() { //fast string s; cin>>s; int n=s(s); s='#'+s; FOR(i,1,n) { int x=s[i]-'a'; dp[x][i]++; } FOR(i,0,25) { FOR(j,1,n) { dp[i][j]+=dp[i][j-1]; } } //FOR(i,0,25)FOR(j,1,n)cout<<dp[i][j]<<(j==n?nl:' '); vector<pair<char,int>> v; FORB(i,n,2) { if(s[i]==s[i-1]) { v.eb(s[i],i); } } if(s(v)==0)cut(0) char x='?';ll r=n; ll ans=0; // trav(it,v)cout<<it.f<<' '<<it.sc<<nl; trav(it,v) { if(it.f!=x) { int y=it.sc; ans+=(n-it.sc)-(dp[it.f-'a'][r]-dp[it.f-'a'][y]); r=y-1; x=it.f; } else { int y=it.sc; ans+=(r-y)-(dp[it.f-'a'][r]-dp[it.f-'a'][y]); r=y-1; } //err2(x,r) //err1(ans) } cut(ans) }
#include <bits/stdc++.h> // clang-format off using namespace std; using ll = long long; using ull = unsigned long long; using pll = pair<ll,ll>; const ll INF = 4e18; void print0() {} template<typename Head,typename... Tail> void print0(Head head,Tail... tail){cout<<fixed<<setprecision(15)<<head;print0(tail...);} void print() { print0("\n"); } template<typename Head,typename... Tail>void print(Head head,Tail... tail){print0(head);if(sizeof...(Tail)>0)print0(" ");print(tail...);} // clang-format on int main() { string s; cin >> s; ll n = s.size(); vector<vector<ll>> rightcnt(n, vector<ll>(27, 0)); // for (ll i = n - 1; i >= 0; i--) { // for (ll c = 0; c < 27; c++) { // if (i < n - 1) rightcnt[i][c] = rightcnt[i + 1][c]; // ll cur = s[i] - 'a'; // rightcnt[i][cur]++; // } // } ll ans = 0; //print(n); for (ll i = n - 1; i >= 0; i--) { ll cur = s[i] - 'a'; for (ll c = 0; c < 27; c++) { if (i + 1 < n) rightcnt[i][c] = rightcnt[i + 1][c]; // print(i, c, rightcnt[i][c]); } rightcnt[i][cur]++; if (i + 2 < n && s[i] == s[i + 1] && s[i] != s[i + 2]) { for (ll c = 0; c < 27; c++) { if (c == cur) { rightcnt[i][c] = (n - i); } else { ans += rightcnt[i][c]; rightcnt[i][c] = 0; } } s[i + 1] = s[i]; s[i + 2] = s[i]; } } print(ans); }
#include <algorithm> #include <iostream> #include <vector> using std::cin; using std::cout; using std::min; using std::sort; using std::vector; struct block { int x, y; } blocks[400000]; int up_most[200001]; vector<vector<int>> sum; void set(int place) { if (!sum[0][place]) { for (int bit = 0; ; ++bit) { ++sum[bit][place]; place >>= 1; if (sum[bit].size() == 1) { break; } } } } int get(int left, int right) { int bit = 0, ret = 0; while (left < right) { if (left & 1) { ret += sum[bit][left]; left = left / 2 + 1; } else { left >>= 1; } if (right & 1) { right >>= 1; } else { ret += sum[bit][right]; right = right / 2 - 1; } ++bit; } return left == right ? ret + sum[bit][left] : ret; } int main() { std::ios_base::sync_with_stdio(false); cin.tie(nullptr); int h, w, m; long long ans = 0; cin >> h >> w >> m; for (int i = w; i; --i) { up_most[i] = h + 1; } for (int i = 0; i < m; ++i) { cin >> blocks[i].x >> blocks[i].y; up_most[blocks[i].y] = min(up_most[blocks[i].y], blocks[i].x); } for (int i = w + 2; ; i = i + 1 >> 1) { sum.push_back(vector<int>(i, 0)); if (i == 1) { break; } } for (int i = 1; i <= w; ++i) { if (up_most[i] == 1) { while (i < w) { set(++i); } break; } else { ans += up_most[i] - 1; } } for (int i = 0; i < h; ++i) { blocks[m + i] = {i + 1, w + 1}; } sort(blocks, blocks + m + h, [](block a, block b) { return a.x == b.x ? a.y < b.y : a.x < b.x; }); for (int x = 2, i = 0; x <= h; ++x) { while (blocks[i].x < x) { set(blocks[i++].y); } if (blocks[i].y == 1) { break; } else { ans += get(1, blocks[i].y - 1); } } cout << ans; return 0; }
#include<bits/stdc++.h> #define int long long using namespace std; vector<int>a[3]; int n,mp[200],x,y,ok,ans=LLONG_MAX,m1=LLONG_MAX,m2=LLONG_MAX; signed main() { ios::sync_with_stdio(0); mp['R']=0,mp['G']=1,mp['B']=2; cin>>n; n<<=1; for(int i=1;i<=n;i++) { int x; char t; cin>>x>>t; a[mp[t]].push_back(x); } ok=1; for(int i=0;i<3;i++) { sort(a[i].begin(),a[i].end()); if(a[i].size()&1) ok=0; } if(ok) { cout<<0<<endl; return 0; } for(int i=0;i<3;i++) if(a[i].size()&1) x=i; for(int i=2;i>=0;i--) if(a[i].size()&1) y=i; int z=3-x-y; for(int i=0;i<a[x].size();i++) { int v=a[x][i]; int p=lower_bound(a[y].begin(),a[y].end(),v)-a[y].begin(); if(p!=a[y].size()) ans=min(ans,abs(v-a[y][p])); if(p) ans=min(ans,abs(v-a[y][p-1])); } for(int i=0;i<a[x].size();i++) { int v=a[x][i]; int p=lower_bound(a[z].begin(),a[z].end(),v)-a[z].begin(); if(p!=a[z].size()) m1=min(m1,abs(v-a[z][p])); if(p) m1=min(m1,abs(v-a[z][p-1])); } for(int i=0;i<a[y].size();i++) { int v=a[y][i]; int p=lower_bound(a[z].begin(),a[z].end(),v)-a[z].begin(); if(p!=a[z].size()) m2=min(m2,abs(v-a[z][p])); if(p) m2=min(m2,abs(v-a[z][p-1])); } if(m1<1e18) ans=min(ans,m1+m2); cout<<ans<<endl; return 0; }
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; int a,b,w,minn = 1e9,maxx = -1e9; bool ok = false; int main() { cin>>a>>b>>w;w*=1000; for(int i=1;;i++) { if (a*i<=w && w<=b*i && !ok){ minn = i;ok = true; } if (a*i>w && ok){ maxx = i-1;break; } if (a*i>1000000)break; } if (!ok){ printf("UNSATISFIABLE");return 0; } cout<<minn<<" "<<maxx; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> using namespace __gnu_pbds; using namespace std; #define getbit(n, i) (((n) & (1LL << (i))) != 0) #define setbit0(n, i) ((n) & (~(1LL << (i)))) #define setbit1(n, i) ((n) | (1LL << (i))) #define togglebit(n, i) ((n) ^ (1LL << (i))) #define lastone(n) ((n) & (-(n))) char gap = 32; #define ll long long #define lll __int128_t #define pb push_back typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); ll hashPrime = 1610612741; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll i,j,k,l,n,m; cin>>n>>m>>l; l *= 1000; ll mini = 0; ll maxi = 0; int flag = 0; for(i = 1;i<=l;i++){ long double temp = (long double)((long double)l/(long double)i); if(temp>=n and temp<=m){ if(flag==0){ flag = 1; mini = i; maxi = i; } else{ mini = min(mini , i); maxi = max(maxi , i); } } } if(flag==0){ cout<<"UNSATISFIABLE\n"; } else{ cout<<mini<<" "<<maxi<<"\n"; } return 0; }
#include<bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main(){ int t; cin>>t; vector<pair<int,int>> m(t); rep(i,t){ cin>>m.at(i).first>>m.at(i).second; } vector<int64_t> nums(t); rep(i,t){ int64_t min_c=m.at(i).first; int64_t max_c=m.at(i).second; if (max_c-min_c>=min_c){ int64_t sum=(1+(max_c-2*min_c+1))*(max_c-2*min_c+1)/2; nums.at(i)=sum; }else nums.at(i)=0; } rep(i,t) cout<<nums[i]<<endl; }
#include<bits/stdc++.h> using namespace std; int read(){ int x=0,f=1;char ch=getchar(); while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int tests,n,a,b; int main(){ a=read(),b=read(); printf("%d\n",2*a-b+100); return 0; }
#include <bits/stdc++.h> using namespace std; #define flush cout.flush using ll = int; using ull = unsigned long long; using ld = long double; using pl = pair<ll, ll>; const ll INF = 1e9 + 7; const ll mod = 1e9 + 7; const ll mod2 = 998244353; const ld eps = 1e-9; const ld PI = acos(-1); const ll LOG = 13; ll bit[LOG]; int main() { ios::sync_with_stdio(false); cin.tie(NULL); for (ll i = 0; i < LOG; ++i) { bit[i] = (1 << i); } ll n, m; cin >> n >> m; vector<ll> good(m + 1, 0); vector<ll> bad(m + 1, 0); good[0] = 1; for (ll p = 0; p < LOG; ++p) { bad.clear(); bad.assign(m + 1, 0); for (ll i = 0; i < n; ++i) { vector<ll> new_good(m + 1, 0); vector<ll> new_bad(m + 1, 0); for (ll j = 0; j <= m; ++j) { new_good[j] = good[j]; new_bad[j] = bad[j]; if (j - bit[p] >= 0) { new_good[j] += bad[j - bit[p]]; new_bad[j] += good[j - bit[p]]; } new_good[j] %= mod2; new_bad[j] %= mod2; } good = new_good; bad = new_bad; } } cout << good[m] << "\n"; return 0; }
#pragma GCC optimize ("Ofast") #include<bits/stdc++.h> #define int long long using namespace std; inline int read() { bool flag=1; int x=0; char c=getchar(); while(c<'0'||c>'9') { if(c=='-') flag=0; c=getchar(); } while(c>='0'&&c<='9') { x=(x<<1)+(x<<3)+c-'0'; c=getchar(); } return (flag?x:~(x-1)); } int n,m,c[5001][5001],f[5001]; const int mod=998244353; signed main() { n=read(); m=read(); for(int i=0;i<=n;i++) { c[i][0]=1; for(int l=1;l<=i;l++) c[i][l]=(c[i-1][l-1]+c[i-1][l])%mod; } f[0]=1; for(int i=0;i<=11;i++) { int t=(1<<i)<<1; for(int l=m;l>=t;l--) for(int j=t,k=2;j<=l;j+=t,k+=2) (f[l]+=f[l-j]*c[n][k]%mod)%=mod; } cout<<f[m]; return 0; }
#pragma GCC optimise ("O1") #include<bits/stdc++.h> using namespace std; #define ll long long #define rep(i,j,n) for(ll i=j;i<n;i++) #define _rep(i,n) for(ll i=n-1;i>=0;i--) #define scn(a) scanf("%lld",&a) #define scns(a,b) scanf("%lld %lld",&a,&b) #define print(a) printf("%lld ",a) #define vec vector<ll> #define pb push_back #define pairs pair<ll,ll> #define f first #define s second #define all(v) v.begin(),v.end() #define srt(v) sort(v.begin(),v.end()) #define read(a) for(auto &it:a) cin>>it; #define write(a) for(auto it:a) cout<<it<<" "; #define yeS(GOOD) GOOD ? cout<<"YES\n" : cout<<"NO\n" #define mem(a,b) memset(a,b,sizeof(a)) #define nl printf("\n") #define inf 1e9 #define zer INT_MIN #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); const int N=2e5 + 5; ll n; int main() { // fast; int t1=1; // cin>>t1; while(t1--) { ll n,x; scns(n,x); string s; cin>>s; for(auto it:s) { if(it=='o') ++x; else { x=max(0LL,--x); } } cout<<x; } }
#include<bits/stdc++.h> using namespace std; int main() { long int n,x; cin>>n>>x; string s; cin>>s; for(int i=0;i<s.length();i++) { if(s[i]=='o') x++; else if(s[i]=='x') { if(x==0) { continue; } else x--; } } cout<<x<<endl; }
#include <iostream> #include <vector> #define MSEED 1000000007 #define MCUT(num) ((num)>=0?((num)%MSEED):((MSEED+(num))%MSEED)) using namespace std; int main() { int n; cin >> n; long long num[n]; for (int i = 0; i < n; i++) { cin >> num[i]; } if (n == 1) cout << num[0] << endl; else { long long pos, neg, pos_prev, neg_prev; long long tp, tn; // loop 0 pos = num[0]; neg = 0; tp = 1; // loop 1 pos_prev = pos; neg_prev = neg; pos = MCUT(pos_prev + num[1]); neg = MCUT(pos_prev - num[1]); tp = tp; tn = tp; // loop 2+ for (int i = 2; i < n; i++) { pos_prev = pos; neg_prev = neg; pos = MCUT(MCUT(pos_prev + num[i] * tp) + MCUT(neg_prev + num[i] * tn)); neg = MCUT(MCUT(pos_prev - num[i] * tp)); long long tntmp = tn; tn = MCUT(tp); tp = MCUT(tp + tntmp); } cout << MCUT(pos + neg) << endl; } return 0; }
#pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target("avx,avx2,sse,sse2") #include <bits/stdc++.h> #define mem(a,x) memset(a,x,sizeof(a)) #define gi(x) scanf("%d",&x) #define gi2(x,y) scanf("%d%d",&x,&y) #define gll(x) scanf("%lld",&x) #define gll2(x,y) scanf("%lld%lld",&x,&y) using namespace std; const double eps=1e-8; typedef long long ll; const int MAXN=100005; const ll mod=1e9+7; const int inf=0x3f3f3f3f; using namespace std; ll dp[MAXN][2]; ll a[MAXN]; int f[MAXN]; int main() { int n; gi(n); for(int i=1;i<=n;i++)gll(a[i]); dp[1][0]=1; for(int i=2;i<=n;i++){ dp[i][0]=(dp[i-1][1]+dp[i-1][0])%mod; dp[i][1]=(dp[i-1][0])%mod; } ll ans=0; ans=(dp[n][1]+dp[n][0])*a[1]%mod; for(int i=2;i<=n;i++){ int l=i-1; ll num=(dp[l][0]+dp[l][1])%mod; int r=n-i+1; num=(num*(dp[r][0]+dp[r][1]))%mod; ans=(ans+num*a[i])%mod; num=dp[l][0]*dp[r][0]%mod; ans=((ans-num*a[i])%mod+mod)%mod; } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define e1 first #define e2 second #define pb push_back #define mp make_pair #define boost {ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } #define eb emplace_back #define OUT(x) {cout << x; exit(0); } #define FOR(i,a,b) for(int i=(a);i<=(b);++i) #define scanf(...) scanf(__VA_ARGS__)?:0 typedef long long int ll; typedef unsigned long long ull; typedef pair <int, int> PII; typedef pair <ll, ll> PLL; typedef pair <PLL, int> PLLI; typedef pair <PII, PII> PP; typedef pair <PII, int> PPI; typedef pair <int, PII> PIP; typedef pair <ll, int> PLI; typedef unsigned int ui; const int inf = 1e9+9; const ll MOD = 1e9+696969; #ifdef DEBUG template<class T> int size(T &&x) { return int(x.size()); } template<class A, class B> ostream& operator<<(ostream &out, const pair<A, B> &p) { return out << '(' << p.first << ", " << p.second << ')'; } template<class T> auto operator<<(ostream &out, T &&x) -> decltype(x.begin(), out) { out << '{'; for(auto it = x.begin(); it != x.end(); ++it) out << *it << (it == prev(x.end()) ? "" : ", "); return out << '}'; } void dump() {} template<class T, class... Args> void dump(T &&x, Args... args) { cerr << x << "; "; dump(args...); } #endif #ifdef DEBUG struct Nl{~Nl(){cerr << '\n';}}; # define debug(x...) cerr << (strcmp(#x, "") ? #x ": " : ""), dump(x), Nl(), cerr << "" #else # define debug(...) 0 && cerr #endif mt19937_64 rng(0); int random(int l, int r) { return uniform_int_distribution<int>(l, r)(rng); } #define rep(i, a, b) for(int i = a; i < (b); ++i) #define trav(a, x) for(auto& a : x) #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() typedef long long LL; typedef pair<int, int> pii; typedef vector<int> vi; const LL INF = 1e18; const int maxn = 300100; const int mod = 998244353; int dr[maxn]; void add(int p, int v) { for (; p < maxn; p += p & (-p)) dr[p] += v; } int get(int p) { int res = 0; for (; p > 0; p -= p & (-p)) res += dr[p]; return res; } ll inv(vector <int> &perm) { int n = perm.size(); ll res = 0; for (int i=n-1; i>=0; --i) { res += get(perm[i]); add(perm[i], 1); } return res; } void solve() { int n; cin >> n; set <PII> q; FOR(i, 0, n-1) { int a; cin >> a; q.insert({a + i, i + 1}); } vector <int> perm; vector <int> B(n + 1); FOR(i, 1, n) { cin >> B[i]; } FOR(i, 1, n) { int a = B[i]; int co = a + i - 1; set <PII> :: iterator szukane = q.lower_bound(make_pair(co, -1)); if (szukane == q.end() || szukane->first != co) { cout << "-1\n"; return; } perm.push_back(szukane -> e2); q.erase(szukane); } debug(perm); cout << inv(perm) << "\n"; } int main() { boost; int tests; tests = 1; //cin >> tests; while (tests--) { solve(); } }
#include<bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int a[N],b[N],bit[N],id[N],x; using ll = long long; map<int,queue<int>> p; int main(void){ int n; ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n; for(int i = 1; i <= n; i++){ cin >> x; p[x + i].push(i); } for(int i = 1; i <= n; i++){ cin >> x; x += i; if(p[x].empty())return puts("-1"),0; id[p[x].front()]=i,p[x].pop(); } ll ans = 0; for(int i = 1; i <= n; i++){ int Now = id[i]; int y = Now; for(;y <= n; y += (y & (-y))) ans += bit[y]; y = Now; for(;y; y -= (y & (-y))) bit[y]++; } cout << ans <<"\n"; }
#include <iostream> #include <vector> using namespace std; bool is_ok (int x) { if (x % 2 != 0) return false; if (x % 3 == 0) return true; if (x % 5 == 0) return true; if (x % 7 == 0) return true; if (x % 11 == 0) return true; return false; } int main () { vector<int> ans; ans.push_back(3 * 5 * 7 * 11); int n; cin >> n; for (int i = 1; i <= 10000 && (int) ans.size() < n; i++) { if (is_ok(i)) { ans.push_back(i); } } for (int i = 0; i < n; i++) { cout << ans[i] << " "; } cout << endl; }
#pragma GCC optimize ("Ofast") #include<bits/stdc++.h> #define int long long using namespace std; inline int read() { bool flag=1; int x=0; char c=getchar(); while(c<'0'||c>'9') { if(c=='-') flag=0; c=getchar(); } while(c>='0'&&c<='9') { x=(x<<1)+(x<<3)+c-'0'; c=getchar(); } return (flag?x:~(x-1)); } int n,now=18; signed main() { n=read()-3; cout<<"6 10 15 "; while(n) { if(now%30==0||now%30==6||now%30==10||now%30==12||now%30==15||now%30==18||now%30==24||now%30==20) { cout<<now<<" "; n-=1; } now++; } return 0; }
#include <iostream> #include <string> #include <vector> #include <map> using ll=long long; using namespace std; int main(){ int N; ll X; cin>>N>>X; vector<ll> A(N); for(int i=0;i<N;i++){ cin>>A[i]; } vector<ll> C(N+1); C[0]=1000000000000000000; for(int i=1;i<=N;i++){ C[i]=A[N-i]; } vector<map<ll,ll>> dp(N+1); dp[0][X]=1; for(int i=1;i<N+1;i++){ for(auto p:dp[i-1]){ ll a=p.first%C[i]; dp[i][a]+=p.second; ll b=C[i]-a; ll num=p.first/C[i]+1; if(C[i]*num<C[i-1] && a!=0){ dp[i][b]+=p.second; } } } /* for(int i=0;i<N+1;i++){ for(auto p:dp[i]){ cout<<"{"<<p.first<<","<<p.second<<"} "; } cout<<endl; } //*/ cout<<dp[N][0]<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define pb push_back #define eb emplace_back #define mp make_pair #define fi first #define se second #define endl "\n" #define debug(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " // const ll mod = 1e9 + 7; const ll mod = 998244353; const ll sz = 1e3 + 5; vector<ll> fac(sz, 1); vector<bool> prime(sz, true); vector<ll> fib(sz, 0); ll powmod(ll a, ll b) { ll res=1; a%=mod; assert(b>=0); for(;b;b>>=1) { if(b&1) res=res*a%mod; a=a*a%mod; } return res; } ll nCr(ll n, ll r) { return ( ( ( (fac[n] * powmod(fac[n-r], mod-2)) % mod ) * powmod(fac[r], mod-2) ) % mod ); } ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a; } ll lcm(ll a, ll b) { return (a / gcd(a,b)) * b; } // * Always PASS arrays, strings etc to functions BY REFERENCE void solve() { int n, m; cin >> n >> m; priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>> > pq; vector<string> arr(n); vector<vector<int>> dist(n, vector<int>(m, 1e9)); vector<vector<pair<int,int> > > pos(26); for (int j = 0; j < n; j++) { cin >> arr[j]; for (int i = 0; i < m; i++) { if (arr[j][i] == 'S') { pq.push({0, j, i}); dist[j][i] = 0; } else if (arr[j][i] >= 'a' && arr[j][i] <= 'z') pos[arr[j][i]-'a'].push_back({j,i}); } } while (!pq.empty()) { auto fr = pq.top(); pq.pop(); int len = fr[0], i = fr[1], j = fr[2]; if (arr[i][j] == 'G') { cout << dist[i][j] << endl; return; } vector<int> dx = {-1, 1, 0, 0}; vector<int> dy = {0, 0, 1, -1}; for (int k = 0; k < 4; k++) { int ii = i + dx[k], jj = j + dy[k]; if (ii < 0 || ii >= n || jj < 0 || jj >= m || arr[ii][jj] == '#') continue; if (dist[ii][jj] <= len + 1) continue; dist[ii][jj] = len + 1; pq.push({dist[ii][jj], ii, jj}); } if (!(arr[i][j] >= 'a' && arr[i][j] <= 'z')) continue; for (auto p: pos[arr[i][j]-'a']) { int ii = p.fi, jj = p.se; if (dist[ii][jj] <= len + 1) continue; dist[ii][jj] = len + 1; pq.push({dist[ii][jj], ii, jj}); } pos[arr[i][j]-'a'].clear(); } cout << -1 << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // fib[1] = 1; // for (int i = 2; i < sz; i++) // fib[i] = (fib[i-1] + fib[i-2]) % mod; // for (ll i = 2; i < sz; i++) // fac[i] = (fac[i-1] * i) % mod; // prime[0] = prime[1] = false; // for (ll i = 2; i*i < sz; i++) { // if (!prime[i]) // continue; // for (ll j = i*i; j < sz; j += i) // prime[j] = false; // } int t = 1; // cin >> t; while(t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; using ll=long long; using ull=unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) ll GCD(ll a,ll b){ return b?GCD(b,a%b):a; } ll A,B; int E[73][73]; int pN; int I[38]; ll G[38]; int dp1[1<<19], dp2[1<<19]; ll solve(){ rep(i,pN) G[i]=0; rep(i,pN) rep(j,pN) if(!E[I[i]][I[j]]) G[i]|=(1ll<<j); int N1=(pN+1)/2, N2=pN/2; ll N1mask = (1ll<<N1)-1; rep(i,1<<N1) dp1[i]=0; rep(i,1<<N2) dp2[i]=0; dp1[0]=dp2[0]=1; rep(d,N1) rep(p,1<<N1) if(!(p&(1<<d))) if(!(p&G[d])) dp1[p|(1<<d)]+=dp1[p]; rep(d,N2) rep(p,1<<N2) if(!(p&(1<<d))) if(!(p&(G[d+N1]>>N1))) dp2[p|(1<<d)]+=dp2[p]; rep(d,N2) rep(p,1<<N2) if(!(p&(1<<d))) dp2[p|(1<<d)]+=dp2[p]; ll ans=0; rep(p,1<<N1){ ll mask = (1ll<<N2)-1; rep(d,N1) if(p&(1ll<<d)) mask &= ~(G[d]>>N1); ans += dp1[p]*dp2[mask]; } return ans; } ll solve2(int x){ int N1=(pN+1)/2, N2=pN/2; ll N1mask = (1ll<<N1)-1; ll allMask = 0; rep(d,pN) if(!E[I[d]][x]) allMask |= (1ll<<d); ll ans=0; rep(p,1<<N1) if(!(p&allMask)){ ll mask = (1ll<<N2)-1; mask &= ~(allMask>>N1); rep(d,N1) if(p&(1ll<<d)) mask &= ~(G[d]>>N1); ans += dp1[p]*dp2[mask]; } return ans; } int main(){ cin>>A>>B; int N = B-A+1; rep(i,N) rep(j,N) E[i][j]=((GCD(A+i,A+j)==1)?1:0); pN=0; rep(i,N) if((A+i)%2==1) I[pN++]=i; ll ans = solve(); rep(i,N) if((A+i)%2==0) ans += solve2(i); cout<<ans<<endl; return 0; }
#define _CRT_SECURE_NO_WARNINGS #include<bits/stdc++.h> #include <chrono> #include <random> #include <unordered_set> using namespace std; typedef long long ll; void solve() { ll a, b; cin >> a >> b; int n = 73; vector<int> s(n); vector<int> prime; for (int i = 2; i < n; i++) { if (s[i] == 0) { s[i] = i; prime.emplace_back(i); for (int j = i; j < n; j += i) { s[j] = i; } } } int m = b - a + 1; n = prime.size(); vector<int> mask(m); for (int i = 0; i < m; i++) { ll x = a + i; for (int j = 0; j < n; j++) { if (x % prime[j] == 0) { mask[i] ^= (1 << j); } } } vector<ll> dp(1 << n); dp[0] = 1; for (int i = 0; i < m; i++) { vector<ll> dp2(1 << n); for (int j = 0; j < (1 << n); j++) { if (dp[j] == 0) continue; dp2[j] += dp[j]; if ((mask[i] & j) == 0) dp2[mask[i] ^ j] += dp[j]; } dp.swap(dp2); } ll ans = 0; for (int i = 0; i < (1 << n); i++) { ans += dp[i]; } cout << ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #if defined(_DEBUG) freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int q = 1; //cin >> q; for (; q > 0; q--) { solve(); //cout << endl; } }
#pragma GCC optimize ("Ofast") #include<bits/stdc++.h> using namespace std; inline int my_getchar(){ static char buf[1048576]; static int s = 1048576; static int e = 1048576; if(s == e && e == 1048576){ e = fread(buf, 1, 1048576, stdin); s = 0; } if(s == e){ return EOF; } return buf[s++]; } inline void rd(long long &x){ int k; int m=0; x=0; for(;;){ k = my_getchar(); if(k=='-'){ m=1; break; } if('0'<=k&&k<='9'){ x=k-'0'; break; } } for(;;){ k = my_getchar(); if(k<'0'||k>'9'){ break; } x=x*10+k-'0'; } if(m){ x=-x; } } struct MY_WRITER{ char buf[1048576]; int s; int e; MY_WRITER(){ s = 0; e = 1048576; } ~MY_WRITER(){ if(s){ fwrite(buf, 1, s, stdout); } } } ; MY_WRITER MY_WRITER_VAR; void my_putchar(int a){ if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){ fwrite(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout); MY_WRITER_VAR.s = 0; } MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a; } inline void wt_L(char a){ my_putchar(a); } inline void wt_L(int x){ int s=0; int m=0; char f[10]; if(x<0){ m=1; x=-x; } while(x){ f[s++]=x%10; x/=10; } if(!s){ f[s++]=0; } if(m){ my_putchar('-'); } while(s--){ my_putchar(f[s]+'0'); } } inline void wt_L(long long x){ int s=0; int m=0; char f[20]; if(x<0){ m=1; x=-x; } while(x){ f[s++]=x%10; x/=10; } if(!s){ f[s++]=0; } if(m){ my_putchar('-'); } while(s--){ my_putchar(f[s]+'0'); } } long long A; long long B; long long C; long long D; int main(){ int i; rd(A); rd(B); rd(C); rd(D); if(D*C - B == 0){ wt_L(-1); wt_L('\n'); exit(0); } long long k = A/(D*C - B); long long ans = -1; for(i=(-1);i<(2);i++){ long long u = k+i; if(A + B * u <= D * C * u ){ ans = u; break; } } if(ans < 0){ ans = -1; } wt_L(ans); wt_L('\n'); return 0; } // cLay version 20210405-1 // --- original code --- // //no-unlocked // ll A, B, C, D; // { // rd(A, B, C, D); // if(D*C - B == 0){ // wt(-1); exit(0); // } // ll k = A/(D*C - B); // ll ans = -1; // rep(i, -1, 2){ // ll u = k+i; // if(A + B * u <= D * C * u ){ // ans = u; break; // } // } // if(ans < 0) ans = -1; // wt(ans); // }
#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 = 1000000000000000000; constexpr int mod = 1000000007; constexpr double eps = 1e-10; 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; } } }*/ 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; } 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; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll a, b, c, d; cin >> a >> b >> c >> d; // a+bx,cx // a+bx<=cdx // a<=(cd-b)x if (c * d - b <= 0) { cout << -1 << endl; return 0; } // a/(cd-b)<=x ll e = (c * d - b); if (a % e == 0) cout << a / e << endl; else cout << a / e + 1 << endl; }
#include<bits/stdc++.h> using namespace std; int main(){ int n,m; int i,j; int count=0; cin >> n; if(n%100!=0){ cout << n/100+1 << endl; }else{ cout << n/100 << endl; } }
#include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } #define rep(i,cc,n) for(int i=cc;i<n;++i) #define lrep(i,cc,n) for(long long i=cc;i<n;++i) #define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i) #define rrep(i,cc,n) for(long i=cc;i>n;--i) #define pii pair<int, int> #define pll pair<long long, long long> using ll = long long; //using mint = modint; const vector<int> dx = {1, 1, 1, 0, 0, 0, -1, -1, -1}; const vector<int> dy = {1, 0, -1, 1, -1, 0, 1, 0, -1}; const double PI = 3.141592653589793; const ll inf = 1001001001; const ll e9 = 1000000000; const ll mod = 1000000007; const ll mod2 = 998244353; const int MAX = 1000000; const ll MOD = 998244353; const ll big = 1ll<<60; ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; } int main(){ int n; cin >> n; cout << (n+99)/100 << endl; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pii; typedef double db; #define fi first #define se second const int MAXN=2e5+10; int a[MAXN], n, pa[MAXN], cnt; set<int> s; inline void pre(int siz) { iota(pa+1, pa+1+siz, 1); cnt=siz; } int find(int u) { return u==pa[u]?u:(pa[u]=find(pa[u])); } inline bool isunion(int u,int v) { return find(u)==find(v); } inline void merge(int u,int v) { if( isunion(u, v) ) return ; pa[find(u)]=find(v); --cnt; } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n; pre(2e5); cnt=0; for(int i=1;i<=n;++i){ cin>>a[i]; if(s.find(a[i])!=s.end()) continue; s.insert(a[i]); ++cnt; } int now=cnt; for(int l=1, r=n;l<r;++l, --r) merge(a[l], a[r]); cout<<now-cnt; cout.flush(); return 0; }
#include<bits/stdc++.h> #define MAXN 300005 #define INF 1000000000000000000LL #define MOD 1000000007 #define F first #define S second using namespace std; typedef long long ll; typedef pair<int,int> P; int n,a[MAXN]; map<ll,int> cnt; int main() { scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]); ll cur=0,ans=0; cnt[cur]++; for(int i=1;i<=n;i++) { if(i&1) cur+=a[i]; else cur-=a[i]; ans+=cnt[cur]; cnt[cur]++; } printf("%lld\n",ans); return 0; }
#include <sstream> #include <queue> #include <stack> #include <set> #include <map> #include <cstdio> #include <cstdlib> #include <cctype> #include <complex> #include <malloc.h> #include <cmath> #include <iostream> #include <string> #include <vector> #include <algorithm> #include <bitset> #include <list> #include <string.h> #include <assert.h> #include <time.h> using namespace std; #define ll long long #define lp(i, e, n) for(ll i = e; i < n; i++) #define IO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define TC(ES) while (ES--) #define fen kmosidnonuw #define jen nrijngijerngair #define jbw nguinerugnru #define mx 0 //inevitability is the unavailabilty of vulnerability. typedef int int32_t; typedef pair<int, int> ii; vector<int> v; const int maxn = 2e5 + 17; //989 void ontheGround(){ string s; for(int i = 1; i <= 3; i++){ cin >> s[i]; } cout << s[2] << s[3] << s[1]; } /* no thats not me. */ int main(){ //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); IO; ll ES = 1; //cin >> ES; TC(ES){ ontheGround(); } return mx; }
#include <bits/stdc++.h> using namespace std; long long INF = 1LL<<60; using ll = long long; using vll = vector<ll>; using mll = map<ll, ll>; #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,a,b) for(int i=a;i>=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } void solve(std::string S){ cout<<S.substr(1) << S[0]<<endl; } int main(){ std::string S; std::cin >> S; solve(S); return 0; }
#include<bits/stdc++.h> using namespace std; int n; string s; int ans(){ if(s.front()!=s.back()) return 1; for(int sz=s.size(),i=1; i<sz; ++i){ if(s[i-1]!=s[0] && s[i]!=s[0]) return 2; } return -1; } int main(){ cin>>n>>s; cout<<ans(); }
#define DEBUG 0 #include <bits/stdc++.h> using namespace std; #if DEBUG // basic debugging macros int __i__,__j__; #define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl #define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl #define printVar(n) cout<<#n<<": "<<n<<endl #define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl #define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;} #define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;} // advanced debugging class // debug 1,2,'A',"test"; class _Debug { public: template<typename T> _Debug& operator,(T val) { cout << val << endl; return *this; } }; #define debug _Debug(), #else #define printLine(l) #define printLine2(l,c) #define printVar(n) #define printArr(a,l) #define print2dArr(a,r,c) #define print2dArr2(a,r,c,l) #define debug #endif // define #define MAX_VAL 999999999 #define MAX_VAL_2 999999999999999999LL #define EPS 1e-6 #define mp make_pair #define pb push_back // typedef typedef unsigned int UI; typedef long long int LLI; typedef unsigned long long int ULLI; typedef unsigned short int US; typedef pair<int,int> pii; typedef pair<LLI,LLI> plli; typedef vector<int> vi; typedef vector<LLI> vlli; typedef vector<pii> vpii; typedef vector<plli> vplli; // ---------- END OF TEMPLATE ---------- int main() { int N; string S; cin >> N >> S; if (S[0] != S.back()) cout << 1 << endl; else { int i; for (i = 0; i < S.size()-1; i++) { if ((S[i] != S[0]) && (S[i+1] != S.back())) { cout << 2 << endl; return 0; } } cout << -1 << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll n,k,ans; ll sum(ll x){ if(x>n+1)return 2*n-x+1; return x-1; } int main(){ cin>>n>>k; k=abs(k); for(int i=2;i+k<=2*n;i++)ans+=sum(i)*sum(i+k); cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define int long long int #define ld long double #define pb push_back #define MOD 1000000007 #define inf 3e18 #define vi vector<int> #define vld vector<ld> #define pii pair<int,int> #define mii map<int,int> #define fi first #define se second #define fastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define db(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << " "<< name << " : " << arg1 <<'\n'; } 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...); } typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> pbds; //order_of_key (k) : Number of items strictly smaller than k . //find_by_order(k) : K-th element in a set (counting from zero) (returns an iterator) void inp_out() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("debug.txt", "w", stderr); #endif } int32_t main() { fastIO inp_out(); int n, x; cin >> n >> x; vector < pii > a(n); for(int i = 0; i < n; ++ i) cin >> a[i].fi >> a[i].se; x *= 100; int cur = 0; for(int i = 0; i < n; ++ i) { cur += (a[i].fi * a[i].se); if(cur > x) { cout << i + 1 << '\n'; return 0; } } cout << - 1; return 0; }
#include<bits/stdc++.h> typedef long long ll; using namespace std; void e(vector<ll> a, vector<ll>& p){ ll c=a.size(),d=p.size(); for(ll bits=0; bits<d; ++bits){ ll sum=0; for(int i=0; i<c; ++i){ if(!(bits&(1<<i))) continue; sum+=a[i]; } p[bits]=sum; } sort(p.begin(),p.end()); } int main(void){ ll n,t; cin>>n>>t; vector<ll> a(n>>1),b((n+1)>>1),p(1<<(n>>1)),q(1<<((n+1)>>1)); for(auto& i:a) cin>>i; for(auto& i:b) cin>>i; e(a,p); e(b,q); ll res=0; for(auto& i:p){ if(i>t) break; res=max(res,i+*(upper_bound(q.begin(),q.end(),t-i)-1)); } cout<<res; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long int; using pll = pair<ll, ll>; using vll = vector<ll>; #define endl "\n" #define space " " #define TLE_na_ho ios_base::sync_with_stdio(false);cin.tie(NULL) #define MAX_SIZE 1024 #define MOD 1000000007 #define pb push_back #define fi first #define se second #define all(v) v.begin(),v.end() #define f(n) for(ll i=0;i<n;i++) #define rep(i,a,n) for(ll i=a;i<n;i++) #define repe(i,a,n) for(ll i=a;i<=n;i++) #define repr(i,a,n) for(ll i=a;i>=n;i--) #define ain(arr,n) for(ll i1=0;i1<n;i1++ ) cin>>arr[i1] #define aout(arr,n) for(ll i1=0;i1<n;i1++ ) cout<<arr[i1]<<space ll testcases; int main() { TLE_na_ho; //READ THE QUESTION PROPERLY!! testcases = 1; //cin>>testcases; while(testcases--) { ll a, b; cin >> a >> b; ll sum = a + b; ll x = sum / 2; ll y = a - x; cout << x << space << y; } }
#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<ll, ll>; const ll INF = ll(10000); void solve(long long N) { set<ll> ans; N -= 3; for (ll i = 12; i <= INF; i += 6) { ans.insert(i); } for (ll i = 20; i <= INF; i += 10) { ans.insert(i); } for (ll i = 30; i <= INF; i += 15) { ans.insert(i); } cout << 6 << " " << 10 << " " << 15 << " "; for (ll a : ans) { if (N == 0) { break; } cout << a << " "; --N; } cout << endl; } // Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) int main() { long long N; scanf("%lld", &N); solve(N); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define ff first #define ss second #define pb push_back #define mp make_pair #define deb(x) cout<< #x << " " << x << "\n"; #define MAX 9223372036854775807 #define MIN -9223372036854775807 #define setbits(n) __builtin_popcountll(n) #define mkunique(a) a.resize(unique(a.begin(),a.end())-a.begin()); //need to sort #define print(s) for(ll u: s) cout<<u<<" "; cout<<"\n"; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const ll mod=1e9+7; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll TT=clock(); vector<ll> a; ll lim=10000; set<ll> s; ll val=3*5; ll j=1; while(1){ if(s.find(val*j)!=s.end()) {j++;continue;} if(val*j>lim) break; a.pb(val*j); s.insert(val*j); j++; } //cout<<a.size()<<"\n"; val=2*3; j=1; while(1){ if(s.find(val*j)!=s.end()) {j++;continue;} if(val*j>lim) break; a.pb(val*j); s.insert(val*j); j++; } //cout<<a.size()<<"\n"; val=2*5; j=1; while(1){ if(s.find(val*j)!=s.end()) {j++;continue;} if(val*j>lim) break; a.pb(val*j); s.insert(val*j); j++; } ll n; cin>>n; vector<ll> b; if(n<=666){ for(ll i=0;i<n-2;i++) b.pb(a[i]); b.pb(2*3); b.pb(2*5); } else if(n<=1999){ for(ll i=0;i<n-1;i++) b.pb(a[i]); b.pb(2*5); } else{ for(ll i=0;i<n;i++) b.pb(a[i]); } ll gc=b[0]; for(ll i=0;i<n;i++){ gc=__gcd(gc,b[i]); cout<<b[i]<<" "; } assert(gc==1); cerr<<"\n\nTIME: "<<(long double)(clock()-TT)/CLOCKS_PER_SEC<<" sec\n"; TT = clock(); return 0; }
#include <bits/stdc++.h> #include <iostream> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define speed \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define ll long long #define ld long double #define pb push_back #define mem1(a) memset(a, -1, sizeof(a)) #define mem0(a) memset(a, 0, sizeof(a)) #define setp(x) fixed << setprecision(x) #define endl "\n" #define mod 1000000007 #define mod1 998244353 #define ff first #define ss second #define MAX 500005 #define N 500 #define INF 1000000009 #define all(v) v.begin(), v.end() #define sbit(a) __builtin_popcount(a) template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; typedef pair<ll, ll> pll; typedef pair<pll, ll> ppl; typedef map<ll, ll> mpll; typedef map<vector<ll>, ll> mpvl; ll power(ll x, ll y) { ll res = 1; x = x; if (x == 0) return 0; while (y > 0) { if (y & 1) res = (res * x); y = y >> 1; x = (x * x); } return res; } void solve() { ll n, m; cin >> n >> m; vector<ll> a; for (ll i = 0; i < m; i++) { ll x; cin >> x; a.pb(x); } a.pb(0); a.pb(n); sort(all(a)); if (n == m) { cout << 0 << endl; return; } if (m == 0) { cout << 1 << endl; return; } vector<ll> v; ll len = a.size(); for (ll i = 1; i < len - 1; i++) { v.pb(a[i] - a[i - 1] - 1); } v.pb(a[len - 1] - a[len - 2]); ll mn = 1e18; for (auto it : v) { if (it != 0) { mn = min(mn, it); } } ll ans = 0; for (auto it : v) { ans += (it / mn); if (it % mn) ans++; } cout << ans << endl; } int main() { speed; ll kk; kk = 1; //cin >> kk; while (kk--) { solve(); } }
#include <bits/stdc++.h> using namespace std; int n, m, a[1005], b[1005], dp[1005][1005]; int main (){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m; for (int i=1; i<=n; i++) cin >> a[i]; for (int i=1; i<=m; i++) cin >> b[i]; for (int i=1; i<=max(n, m); i++) dp[0][i]=dp[i][0]=i; for (int i=1; i<=n; i++){ for (int j=1; j<=m; j++){ dp[i][j] = min({dp[i-1][j-1]+int(a[i]!=b[j]), dp[i-1][j]+1, dp[i][j-1]+1}); } } cout << dp[n][m]; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #pragma comment(linker, "/stack:200000000") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") //turn on extra precision //#pragma GCC target("fpmath=387") using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef string str; typedef pair <int,int> pii; typedef pair <ll,ll> pll; typedef vector <int> vi; typedef vector <ll> vll; typedef vector <pii> vpii; typedef vector <pll> vpll; #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> #define ordered_multiset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> #define mp make_pair #define pb push_back #define pob pop_back #define pf push_front #define pof pop_front #define fi first #define se second #define fs first.second #define ss second.second #define ff first.first #define sf second.first #define newl '\n' #define fbo find_by_order #define ook order_of_key #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(),x.rend() #define watch(x) cout << (#x) << " is : " << (x) << newl mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); vi dirx = {0,0,1,-1}; vi diry = {1,-1,0,0}; char to_upper (char x){ if( 97 <= int(x) && int(x) <= 122) return char(x-32); if( 65 <= int(x) && int(x) <= 90) return x; return -1; } char to_lower (char x){ if( 97 <= int(x) && int(x) <= 122) return x; if( 65 <= int(x) && int(x) <= 90) return char(x+32); return -1; } int numerize (char x){ if(48 <= int(x) && int(x) <= 57) return int(x-'0'); if(97 <= int(x) && int(x) <= 122) return int(x-96); if(65 <= int(x) && int(x) <= 90) return int(x-64); return -1; } bool isect (int l1, int r1, int l2, int r2){ return max(l1,l2) <= min(r1,r2); } ll quickpow (ll num1, ll num2, ll MOD){ if(num2==0)return 1%MOD; else if(num2==1)return num1%MOD; else{ ll temp = quickpow (num1,num2>>1LL,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD; if(num2&1) res = ((res%MOD)*(num1%MOD))%MOD; return res; } } ll invmod (ll num, ll MOD){return quickpow (num,MOD-2,MOD);} ll gcd (ll num1, ll num2){ if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ; while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;} return num2; } ll lcm (ll num1 , ll num2){return (ll) (num1/__gcd(num1,num2))*num2;} // end of Template const int MAXN = 2e5 + 5; const ll INF = 1e17; int n; ll lo, hi, a[MAXN], t[MAXN]; ll f(ll x){ for(int i = 1; i <= n; ++i) { if(t[i] == 1) x += a[i]; if(t[i] == 2) x = max(x,a[i]); if(t[i] == 3) x = min(x,a[i]); // watch(x); } return x; } ll binserlo(){ ll l = -INF, r = INF, res = -1; while(l <= r){ ll mid = (l + r) >> 1LL; if(f(mid) <= lo) res = mid, l = mid + 1; else r = mid - 1; } return res; } ll binserhi(){ ll l = -INF, r = INF, res = -1; while(l <= r){ ll mid = (l + r) >> 1LL; if(f(mid) >= hi) res = mid, r = mid - 1; else l = mid + 1; } return res; } int main(){ // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; for(int i = 1; i <= n; ++i) cin >> a[i] >> t[i]; lo = f(-INF), hi = f(INF); ll L = binserlo(), R = binserhi(); int q; cin >> q; while(q--){ ll x, res; cin >> x; if(lo == hi) {cout << lo << newl; continue; } if(x < L) res = lo; else if(x > R) res = hi; else res = lo + (x - L); cout << res << newl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll mod = 1e9+7; const long long INF = 1e17; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); long long n; cin >> n; long long f0 = 0, l = -INF, r = INF; long long memo = 0; for(long long i = 0; i < n; i++){ long long a, t; cin >> a >> t; if(t == 1){ memo += a; f0 += a; l += a; r += a; } else if(t == 2){ f0 = max(f0, (long long)a); l = max(l, (long long)a); r = max(r, (long long)a); } else { f0 = min(f0, (long long)a); l = min(l, (long long)a); r = min(r, (long long)a); } } long long q; cin >> q; vector<long long> ans(q); for(long long i = 0; i < q; i++){ long long x; cin >> x; if(l-memo > x) ans[i] = l; else if(r-memo < x) ans[i] = r; else ans[i] = x+memo; } for(long long i = 0; i < q; i++) cout << ans[i] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll a,b; cin>>a>>b; ll ans=1; if(b>=2*a){ for(ll i=b;i>=a;i--){ if(i*2<=b){ ans=i; break; } } cout<<max(ans,(ll)1); } else{ ll ans=1; for(ll i=1;i<=b;i++){ int ans1=b/i-a/i; if(a%i==0)ans1++; if(ans1>1)ans=max(ans,i); } cout<<ans; } }
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(ll i=0;i<(ll)n;i++) #define dump(x) cerr << "Line " << __LINE__ << ": " << #x << " = " << (x) << "\n"; #define spa << " " << #define fi first #define se second #define ALL(a) (a).begin(),(a).end() #define ALLR(a) (a).rbegin(),(a).rend() using ld = long double; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<ld, ld>; template<typename T> using V = vector<T>; template<typename T> using P = pair<T, T>; template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); } template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); } template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){os << "(" << v.first << ", " << v.second << ")"; return os;} template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; } template<class T> ostream& operator<<(ostream& os, const vector<vector<T>> &v){ for(auto &e : v){os << e << "\n";} return os;} struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; template <class T> void UNIQUE(vector<T> &x) {sort(ALL(x));x.erase(unique(ALL(x)), x.end());} template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } void fail() { cout << -1 << '\n'; exit(0); } inline int popcount(const int x) { return __builtin_popcount(x); } inline int popcount(const ll x) { return __builtin_popcountll(x); } template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++) {cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<"\n";}}; template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0]; for(ll i=1;i<n;i++)cerr spa v[i]; cerr<<"\n";}; const ll INF = (1ll<<62); // const ld EPS = 1e-10; // const ld PI = acos(-1.0); const ll mod = (int)1e9 + 7; //const ll mod = 998244353; bool is_prime(int64_t x) { for(int64_t i = 2; i * i <= x; i++) { if(x % i == 0) return false; } return true; } int main(){ ll A, B; cin >> A >> B; V<ll> primes; for(ll i=2;i<=72;i++){ if(is_prime(i)){ primes.push_back(i); } } ll sz = primes.size(); V<ll> dp(1ll<<sz, 0); dp[0] = 1; for(ll v=A;v<=B;v++){ ll bit = 0; REP(i, sz){ if(v % primes[i] == 0){ bit += (1ll<<i); } } V<ll> td(1ll<<sz, 0); REP(mask, 1ll<<sz){ td[mask] += dp[mask]; if((mask & bit) == 0){ td[mask | bit] += dp[mask]; } } swap(dp, td); } ll res = 0; for(auto x: dp) res += x; cout << res << endl; // dump(primes) // dump(sz) return 0; }
#include <bits/stdc++.h> using namespace std; #define INF 200005 #define MOD 1000000007 #define ping cout << "ping\n" int main() { //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); //ios_base::sync_with_stdio(false); //cin.tie(NULL); int n; cin >> n; string a; cin >> a; int counter=0; for(int i=0;i<n;i++) { int aa=0; int tt=0; int cc=0; int gg=0; for(int k=i;k<n;k++) { if(a[k]=='A') aa++; else if(a[k]=='T') tt++; else if(a[k]=='C') cc++; else if(a[k]=='G') gg++; if(aa==tt && cc==gg) { counter++; } } } cout << counter << "\n"; }
#ifdef DBG_MACRO_NO_WARNING #include <dbg.h> #endif #include <bits/stdc++.h> #define all(c) c.begin(), c.end() #define isz(c) (int)c.size() using namespace std; using ll = long long; using ii = pair<int, int>; using vi = vector<int>; template <typename InputIterator, typename T = typename iterator_traits<InputIterator>::value_type> void read_n(InputIterator it, int n) { copy_n(istream_iterator<T>(cin), n, it); } template <typename InputIterator, typename T = typename iterator_traits<InputIterator>::value_type> void write(InputIterator first, InputIterator last, const char *delim = "\n") { copy(first, last, ostream_iterator<T>(cout, delim)); } int solve(int n, string s) { map<char, vi> pm = { {'A', vi(n, 0)}, {'T', vi(n, 0)}, {'C', vi(n, 0)}, {'G', vi(n, 0)}}; string opts = "AGCT"; for (int i = 0; i < n; ++i) { for (auto c : opts) { pm[c][i] += s[i] == c; if (i != 0) pm[c][i] += pm[c][i - 1]; } } auto sum = [&pm](int l, int r, char c) { return pm[c][r] - (l > 0 ? pm[c][l - 1] : 0); }; int ans = 0; for (int l = 0; l < n - 1; ++l) { for (int r = l + 1; r < n; ++r) { ans += (sum(l, r, 'A') == sum(l, r, 'T') and sum(l, r, 'C') == sum(l, r, 'G')); } } return ans; } int main(void) { ios::sync_with_stdio(false), cin.tie(NULL); int n; string s; cin >> n >> s; cout << solve(n, s) << endl; return 0; }
#include<bits/stdc++.h> #define ll long long using namespace std; ll n,m,K,C[31][61]; int main(){ cin>>n>>m>>K;K--; for(int i=0;i<=60;i++){ C[0][i]=1; for(int j=1;j<=30&&j<=i;j++)C[j][i]=C[j][i-1]+C[j-1][i-1]; } int t=0; for(int i=1;i<=n+m;i++){ if(K>=C[m-t][n+m-i])K-=C[m-t][n+m-i],cout<<'b',t++; else cout<<"a"; } }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for(int i=0; i<(n); ++i) #define RREP(i, n) for(int i=(n);i>=0;--i) #define FOR(i, a, n) for (int i=(a); i<(n); ++i) #define RFOR(i, a, b) for(int i=(a);i>=(b);--i) #define SZ(x) ((int)(x).size()) #define ALL(x) (x).begin(),(x).end() #define DUMP(x) cerr<<#x<<" = "<<(x)<<endl #define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl; template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { REP(i, SZ(v)) { if (i) os << " "; os << v[i]; } return os; } template <class T> void debug(const vector<T> &v) { cout << "["; REP(i, SZ(v)) { if(i) cout << ", "; cout << v[i]; } cout << "]" << endl; } template<class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << p.first << " " << p.second; } template <class T, class U> void debug(const pair<T, U> &p) { cout << "(" << p.first << " " << p.second << ")" << endl; } template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } using ll = long long; using ull = unsigned long long; using ld = long double; using P = pair<int, int>; using vi = vector<int>; using vll = vector<ll>; using vvi = vector<vi>; using vvll = vector<vll>; const ll MOD = 1e9 + 7; const ll MOD998 = 998244353; const int INF = INT_MAX; const ll LINF = LLONG_MAX; const int inf = INT_MIN; const ll linf = LLONG_MIN; const ld eps = 1e-9; const int MAX_C = 61; long long Com[MAX_C][MAX_C]; void calc_com() { memset(Com, 0, sizeof(Com)); Com[0][0] = 1; for (int i = 1; i < MAX_C; ++i) { Com[i][0] = 1; for (int j = 1; j < MAX_C; ++j) { Com[i][j] = (Com[i-1][j-1] + Com[i-1][j]); } } } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(10); ll a, b, k; cin >> a >> b >> k; string ans = ""; calc_com(); ll rem = b; REP(i, a + b - 1) { if(Com[a + b - i - 1][rem] + 1 <= k) { ans += 'b'; k -= Com[a + b - i - 1][rem]; rem--; } else { ans += 'a'; } } if(rem != 0) ans += 'b'; else ans += 'a'; cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define ll long long #define MAXN 200010 using namespace std; vector<pair<ll,ll> > cp(MAXN),dp(MAXN); ll n; void All() { for (ll i=0;i<=n;i++) cp[i]=make_pair(INT_MAX,INT_MIN); } int main() { ///ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll x,c; cin >> n; All(); dp[0].first=0; dp[0].second=0; ///for (ll i=1;i<=n;i++) ///{ /// cout << i << " cp " << cp[i].first << " " << cp[i].second << "\n"; ///} for (ll i=1;i<=n;i++) { cin >> x >> c; cp[c].first=min(cp[c].first,x); cp[c].second=max(cp[c].second,x); } /**for (ll i=1;i<=n;i++) { if (cp[i].first==INT_MAX) continue; cout << i << " cp " << cp[i].first << " " << cp[i].second << "\n"; }**/ ll p=0; cp[p].first=0; cp[p].second=0; for (ll i=1;i<=n;i++) { if (cp[i].first==INT_MAX) continue; dp[i].first=min(dp[p].first+abs(cp[p].first-cp[i].second),dp[p].second+abs(cp[p].second-cp[i].second))+abs(cp[i].first-cp[i].second); dp[i].second=min(dp[p].first+abs(cp[p].first-cp[i].first),dp[p].second+abs(cp[p].second-cp[i].first))+abs(cp[i].first-cp[i].second); p=i; } cout << min(dp[p].first+abs(cp[p].first),dp[p].second+abs(cp[p].second)) << "\n"; return 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<ll> X(N),C(N); REP(i,N){ cin >> X[i] >> C[i]; } vector<pair<ll,ll> > p(N); REP(i,N){ p[i].first=C[i]; p[i].second=X[i]; } sort(p.begin(),p.end()); ll count=1; ll tmp=p[0].first; vector<ll> l,r; l.push_back(p[0].second); REP(i,N){ if(p[i].first!=tmp){ count++; tmp=p[i].first; r.push_back(p[i-1].second); l.push_back(p[i].second); // cout << p[i-1].second << " " <<p[i].second << endl; } } r.push_back(p[N-1].second); ll dp[count+1][2]; dp[0][0]=0; dp[0][1]=0; ll nowl=0,nowr=0; for(ll i=1;i<count+1;i++){ dp[i][0]=min(dp[i-1][0] + abs(r[i-1]-nowl)+abs(l[i-1]-r[i-1]),dp[i-1][1] + abs(r[i-1]-nowr)+abs(l[i-1]-r[i-1])); dp[i][1]=min(dp[i-1][0] + abs(l[i-1]-nowl)+abs(r[i-1]-l[i-1]),dp[i-1][1] + abs(l[i-1]-nowr)+abs(r[i-1]-l[i-1])); nowl=l[i-1]; nowr=r[i-1]; } ll ans = min(dp[count][0]+abs(nowl) , dp[count][1]+abs(nowr)); // answer("cout dp"); //REP(i,4){ // cout << dp[i][0] << " " << dp[i][1] << endl; //} answer(ans); return 0; }
#include <bits/stdc++.h> using namespace std; //int target() int looping(int cnt1, int depth, int res, int limdep, string N1){ depth ++; //cout << limdep << " " << depth << " " << cnt1 << endl; if (res == -1){ if (depth == limdep){ if /*write conditon from here*/ ((stol(N1) % 3) == 0) /*to here*/ res = depth; } if (depth < limdep){ for (int i = 0; i < cnt1; i++){ //start opereation string N2 = N1; N2.erase(N2.begin() + i); //end operation int cnt2 = cnt1-1;//how many decrease the cnt value res = looping(cnt2,depth,res,limdep,N2); } } } return res; } int depth_search(int cnt1, string N1) { /* return the value of depth decresing its cnt number */ int res = -1, depth =-1; for (int limdep = 0; limdep < cnt1; limdep++){ res = looping(cnt1,depth,res,limdep,N1); if (res != -1) break; } return res; } int main(){ string N; cin >> N; int siz = (int)N.length(); int res; res = depth_search(siz,N); cout << res << endl; }
#include<bits/stdc++.h> using namespace std; #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr) typedef long long int ll; typedef long double ld; #define trump(v,a) vector<ll> v(a); for(int i =0;i<a; ++i)cin>>v[i]; #define modi(v) for(auto i:v) cout<<i<<" "; #define debug_pair(obg) for(auto i:obg) cerr<<i.F<<" "<<i.second<<endl; #define F first #define S second #define p2 pair<ll,ll> #define endl "\n" #define pi ld(3.1415926536) std::vector<ll> e; void solve() { ll a = 1, b = 0, c = 0, t = 0, ans = 0, ans2 = 0, k = -1, c1 = 0, c2 = 0, c3, c4 , n = 0, m = 0, x = 2231131199; cin >> a; std::vector<ll> v = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47}; std::vector<ll> y; for (int i = 1; i <= 32768; ++i) { /* code */ k = i; ans = 1; t = 0; while (k) { c = k % 2; k /= 2; if (c) { ans *= v[t]; } t++; } y.push_back(ans); } sort(y.begin(), y.end()); trump(e, a); bool fl = 0, fl2 = 0; for (int i = 0; i < 32768; ++i) { /* code */ fl2 = 1; for (auto j : e) { if (__gcd(y[i], j) == 1) { fl2 = 0; break; } } if (fl2) { cout << y[i]; return; } } } 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 clock_t z = clock(); ll qc = 1; // cin >> qc; for (ll i = 1; i <= qc; i++) solve(); debug("Total Time: % .4Lf\n", (ld)(clock() - z) / CLOCKS_PER_SEC); } /* some good points to think :- 1) Why are you alive 2) Is the array overflowing 3) will you ever be able to solve a graph question.yay! 4) The answer will be trivial always if its not its not worth solving 5) for xor a^b = a+b-2a&b xor of multi element set counts only odd no. of set bits 6) char values are '0' =48 'a' = 97 'A' = 65 7) two pointers are good way for array sum /length based questions 8) dp on sums? 9) make black boxes 10) min/max at central tandencies and just iterate +- 5 around it 11) Always use different array for coloring. 12) Null adjacency list will return from traversal. 13) Add once only in case of trees. */
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <math.h> #include <queue> #include <numeric> #include <iomanip> #include <map> #include <set> using namespace std; using ll = long long; template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; #define pb push_back #define mp make_pair #define fi first #define se second #define For(i,a,b) for(ll i=(a);i<(ll)(b);i++) #define rFor(i,a,b) for(ll i=(a);i>=(ll)(b);i--) #define co(a) cout<<a<<endl #define ce(a) cerr<<a<<endl #define Sort(a) sort((a).begin(),(a).end()) #define Rev(a) reverse((a).begin(),(a).end()) #define Unique(a) (a).erase(unique((a).begin(), (a).end()),(a).end()) #define cfs(a) cout<<fixed<<setprecision(a) constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); } template <class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; } template <class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; } 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) { os << "{"; For(i, 0, v.size()) { if (i) os << ","; os << v[i]; } os << "}"; return os; } #define LOCAL #ifdef LOCAL void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...); } #define debug(...) \ cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl #else #define debug(...) (void(0)) #define dump(x) (void(0)) #endif constexpr ll INF = TEN(18); int main(){ ll a, b, c, d; cin >> a >> b >> c >> d; bool is = false; For(i, 0, 1000000) { if (a + b * i <= c * i * d) { co(i); is = true; break; } } if (!is) { co(-1); } }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i,n) for(ll i=0,endrep=(n); i<endrep; ++i) #define rep1(i,n) for(ll i=1,endrep=(n); i<=endrep; ++i) #define revrep(i,n) for(ll i=(ll)(n)-1; i>=0; --i) inline constexpr ll Inf = (1ULL << 60) -123456789; #define fastio cin.tie(0); ios_base::sync_with_stdio(false); cout<<fixed<<setprecision(10); #define newl '\n' #define YN(e) ((e)?"Yes":"No") #define all(a) begin(a),end(a) #define rall(a) rbegin(a),rend(a) #define delif(c,pred) (c).erase(remove_if(all(c),(pred)), end(c)) template <class T,class U> bool updmax(T& a, U b) { if(b>a){ a=b; return true;} return false;} template <class T,class U> bool updmin(T& a, U b) { if(b<a){ a=b; return true;} return false;} inline constexpr int Mod = 1000000007; //inline constexpr int Mod = 998244353; #define dbg(a) cerr << #a << ": " << (a) << endl; #define dbgs(s) cerr << #s << endl; #define dbg1(a,n) cerr<<#a<<": "; rep(i,n) cerr<<(a)[i]<<" "; cerr<<endl; #define dbg2(m,h,w) cerr<<#m<<":"<<endl; rep(i,(h)){ rep(j,(w))cerr<<(m)[i][j]<<" "; cerr<<endl; } template <class T, class U> ostream& operator << (ostream& os, pair<T,U> v) {os<<v.first<<","<<v.second;return os;} template <class T, size_t N> ostream& operator << (ostream& os, array<T,N> v) {rep(i,N)os<<v[i]<<(i+1<(ll)N?" ":"");return os;} int rng(int n) { return rand()/(RAND_MAX+1.0)*n; } inline constexpr int offset[] = {1,0,-1,0,1}; int main() { fastio; ll ans{}; ll N; string s; cin >> N >> s; ll l = 0, r = N-1; rep(i,N-1) { if (s[l] != s[r]) { ++ans; break; } if (s[l] == s[i]) continue; if (s[i+1] == s[r]) continue; ++ans; l = i+1; } if (ans == 0) ans = -1; cout << ans << endl; }
#include <bits/stdc++.h> #include <chrono> using namespace std; using namespace chrono; typedef long long int ll; typedef vector<int> vii; typedef vector<ll> vll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; #define pb push_back #define odd(x) ((x)&1) #define even(x) (!odd(x)) #define all(v) (v).begin(),(v).end() #define rep(i,n) for(auto i=0;i<n;++i) #define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define TEST_CASE int tc;cin>>tc;while(tc--) #define Clock high_resolution_clock::now() 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;} #ifdef LOCAL #define cerr cout #else #endif #define TRACE #ifdef TRACE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char* name, Arg1&& arg1){ cerr << name << " : " << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...); } #else #define trace(...) #endif void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif // #define TIME /******************************************************************************************************************************/ const ll inf = 2e18; const ll mod = 998244353; const ll N = 10000; int main() { auto start_time = Clock; FASTIO ll n; cin >> n; vll t(n), v(n); vector<string> s(n); rep(i,n) { cin >> s[i] >> t[i]; v[i] = i; } sort(all(v), [&](ll a, ll b){ return t[a] < t[b]; }); cout << s[v[n-2]] << "\n"; auto end_time = Clock; #ifndef TIME return 0; #endif cout << "\nTime elapsed: " << (double)duration_cast<milliseconds>(end_time-start_time).count() << "ms"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N,first=0,second=0,findex=0,sindex=0; vector<string> s(1010); vector<int> t(1010); cin >> N; for (int i = 0; i < N; i++){ cin >> s[i] >> t[i]; } for (int i = 0; i < N; i++){ if(first<t[i]){ second = first; first=t[i]; sindex=findex; findex=i; } else if(second<t[i]){ second=t[i]; sindex=i; } } cout << s[sindex] <<endl; }
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <cmath> using ll = long long; #define rep(i, n) for (ll i = 0; i < (n); i++) using namespace std; int main(){ int h, w; cin >> h >> w; vector<string> s(h); rep(i, h) cin >> s[i]; int ans = 0; rep(i, h)rep(j, w){ if (s[i][j] == '#') continue; if (j+1 < w) if (s[i][j+1] == '.') ans++; if (i+1 < h) if (s[i+1][j] == '.') ans++; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn=1e6+7; const int inf=INT_MAX; const ll inff=1e18; const ll mod=1e9+7; #define pii pair<int,int> #define mkp make_pair #define F first #define S second #define pb push_back #define sz(v) ((int)(v).size()) #define all(v) (v).begin(),(v).end() //#define int ll map<ll,ll> visits; ll x,y,ans=inff; void solve(ll y,ll cnt){ queue<ll> q; q.push(y); visits[y]=1; while (!q.empty()){ ll now=q.front(); q.pop(); ans=min(ans,abs(x-now)+visits[now]-1); if (now&1){ if (!visits[now+1]) visits[now+1]=visits[now]+1,q.push(now+1); if (!visits[now-1]) visits[now-1]=visits[now]+1,q.push(now-1); } else{ if (!visits[now>>1]) visits[now>>1]=visits[now]+1,q.push(now>>1); } } } int32_t main(){ ios::sync_with_stdio(0); cin.tie(0); cin>>x>>y; solve(y,0); cout<<ans<<'\n'; }
#include<algorithm> #include<bitset> #include<cmath> #include<complex> #include<deque> #include<functional> #include<iomanip> #include<iostream> #include<iterator> #include<map> #include<numeric> #include<queue> #include<set> #include<stack> #include<string> #include<unordered_map> #include<unordered_set> #include<utility> #include<vector> #include<chrono> using namespace std; #define rep(i,n) for(int i=0; i<(n); i++) #define FOR(i,x,n) for(int i=x; i<(n); i++) #define vint(a,n) vint a(n); rep(i, n) cin >> a[i]; #define vll(a,n) vll a(n); rep(i, n) cin >> a[i]; #define ALL(n) begin(n),end(n) #define RALL(n) rbegin(n),rend(n) #define MOD (1000000007) // #define MOD (998244353) #define INF (1e9+7) #define INFL (2e18) typedef long long ll; typedef unsigned int ui; typedef unsigned long long ull; using vint=vector<int>; using vll=vector<ll>; using vbool=vector<bool>; template<class T>using arr=vector<vector<T>>; template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;} template<class T>void pl(T x){cout << x << " ";} template<class T>void pr(T x){cout << x << endl;} template<class T>void prvec(vector<T>& a){rep(i, (int)a.size()-1){pl(a[i]);} pr(a.back());} template<class T>void prarr(arr<T>& a){rep(i, (int)a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);} template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } ll modpow(ll a, ll n, ll p) { if (n == 1) return a % p; if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p; long long t = modpow(a, n / 2, p); return (t * t) % p; } int main() { ll n, m; cin >> n >> m; ll t = modpow(10, n, m*m); // modpow(10, 2, 2); pr((t/m)%m); return 0;}
#include<bits/stdc++.h> #define int long long using namespace std; int mod=998244353; const int sz=5e3+1; int fac[sz]; int inv[sz]; int fpow(int a,int b) { int ans=1; while(b) { if(b&1) { ans*=a; ans%=mod; } a*=a; a%=mod; b>>=1; } return ans; } int combo(int n,int r) { if(n<r) { return 0; } return (((fac[n]*inv[r])%mod)*inv[n-r])%mod; } void precomp(int n) { fac[0]=1; for(int i=1;i<=n;i++) { fac[i]=(fac[i-1]*i)%mod; } inv[0]=1; for(int i=1;i<=n;i++) { inv[i]=fpow(fac[i],mod-2); } } int dp[5001][5001]; int solve(int m,int k,int &n) { if(m==0) { return 1; } if(m<k||m%k) { return 0; } if(dp[m][k]) { return dp[m][k]; } int ans=0; for(int i=0;i<=m;i+=k) { int te=solve(m-i,2*k,n)*combo(n,i/k*2); ans+=te; if(ans>mod) { ans%=mod; } } return dp[m][k]=ans; } signed main() { int n,m; cin>>n>>m; precomp(n); if(n==1) { cout<<0; } else { cout<<solve(m,2,n); } return 0; }
#include <bits/stdc++.h> #define ll long long #define f first #define s second #define mod 1e9+7 #define inf 1e18 #define N 1000043 #define mp(a,b) make_pair(a,b) #define pb(a) push_back(a) #define loop(a,b) for(int i=a;i<b;i++) #define test int t; cin >> t; while(t--) #define pll pair<ll,ll> #define int ll using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; string str; cin >> str; vector<int>vec(n,0); bool x=false; int q; cin >> q; for(int i=0;i<q;i++){ int t,a,b; cin >> t >> a >> b; if(t==1){ a--;b--; if(x) { if(a<n) a=n+a; else a=a-n; if(b<n) b=n+b; else b=b-n; } swap(str[a],str[b]); }else{ x=!x; } } if(x){ for(int i=0;i<n;i++){ swap(str[i],str[n+i]); } } cout << str << endl; }
#include <iostream> #include <vector> #include <cmath> #include <algorithm> #include <string> #include <iterator> #include <stack> #include <queue> #include <functional> #include <map> #include <set> #include <tuple> #include <bitset> using namespace std; #define ll long long #define double long double #define vi vector<int> #define vvi vector<vi> #define all(x) (x).begin(), (x).end() #define pii pair<int, int> int main() { ll n, q; string S; int rev = 0; int t, a, b; cin >> n; cin >> S; cin >> q; for (size_t i = 0; i < q; i++) { cin >> t >> a >> b; if (t == 1) { if (rev) { if (a > n) { a -= n; } else { a += n; } if (b > n) { b -= n; } else { b += n; } } swap(S[a - 1], S[b - 1]); } else { if (rev) { rev = 0; } else { rev = 1; } } } if (rev == 0) { cout << S << endl; } else { cout << S.substr(n) << S.substr(0, n) << endl; } return 0; }
//雪花飄飄北風嘯嘯 //天地一片蒼茫 #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/rope> using namespace std; using namespace __gnu_pbds; using namespace __gnu_cxx; #define ll long long #define ii pair<ll,ll> #define iii pair<ii,ll> #define fi first #define se second #define endl '\n' #define debug(x) cout << #x << " is " << x << endl #define pub push_back #define pob pop_back #define puf push_front #define pof pop_front #define lb lower_bound #define ub upper_bound #define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--)) #define all(x) (x).begin(),(x).end() #define sz(x) (int)(x).size() #define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> //change less to less_equal for non distinct pbds, but erase will bug mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); const int MOD=1000000007; ll qexp(ll b,ll p,int m){ ll res=1; while (p){ if (p&1) res=(res*b)%m; b=(b*b)%m; p>>=1; } return res; } ll inv(ll i){ return qexp(i,MOD-2,MOD); } vector<vector<ll> > mul(vector<vector<ll> > i, vector<vector<ll> > j,int m){ vector<vector<ll> > res; for (int x=0;x<i.size();x++){ res.push_back(vector<ll>()); for (int y=0;y<i.size();y++){ res[x].push_back(0); for (int z=0;z<i.size();z++){ res[x][y]=(res[x][y]+i[x][z]*j[z][y])%m; } } } return res; } vector<vector<ll> > mexp(vector<vector<ll> > mat,long long p,int m){ if (p==1) return mat; vector<vector<ll> > res=mexp(mat,p>>1,m); res=mul(res,res,m); if (p&1) res=mul(res,mat,m); return res; } int n,m,k; int arr[105]; vector<vector<ll> > mat; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin.exceptions(ios::badbit | ios::failbit); cin>>n>>m>>k; rep(x,0,n) cin>>arr[x]; if (k==0){ rep(x,0,n) cout<<arr[x]<<endl; return 0; } rep(x,0,n){ mat.pub({}); rep(y,0,n) mat[x].pub(0); mat[x][x]=1; } int a,b; rep(x,0,m){ cin>>a>>b; a--,b--; mat[a][b]=inv(2*m%MOD); mat[b][a]=inv(2*m%MOD); mat[a][a]=(mat[a][a]-inv(2*m%MOD)+MOD)%MOD; mat[b][b]=(mat[b][b]-inv(2*m%MOD)+MOD)%MOD; } mat=mexp(mat,k,MOD); rep(x,0,n){ int ans=0; rep(y,0,n) ans=(ans+mat[x][y]*arr[y])%MOD; cout<<ans<<endl; } }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,n) for (long long i = 0; i < (n); ++i) #define DIV 1000000007 //10^9+7 #define INF LONG_MAX/3 #define bit(n) (1LL<<(n)) template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } int dx[4]={1,0,-1,0}; int dy[4]={0,1,0,-1}; //class -> num map<ll, ll> stu[200005]; // 素集合データ構造 struct UnionFind { // par[i]:データiが属する木の親の番号。i == par[i]のとき、データiは木の根ノードである vector<int> par; // sizes[i]:根ノードiの木に含まれるデータの数。iが根ノードでない場合は無意味な値となる vector<int> sizes; UnionFind(int n) : par(n), sizes(n, 1) { // 最初は全てのデータiがグループiに存在するものとして初期化 for(int i = 0; i < n; i++){ par[i] = i; } } // データxが属する木の根を得る int find(int x) { if (x == par[x]) return x; return par[x] = find(par[x]); // 根を張り替えながら再帰的に根ノードを探す } // 2つのデータx, yが属する木をマージする void unite(int x, int y) { // データの根ノードを得る x = find(x); y = find(y); // 既に同じ木に属しているならマージしない if (x == y) return; // xの木がyの木より大きくなるようにする if (sizes[x] < sizes[y]) swap(x, y); // xがyの親になるように連結する par[y] = x; sizes[x] += sizes[y]; for(auto item: stu[y]) stu[x][item.first] += item.second; // sizes[y] = 0; // sizes[y]は無意味な値となるので0を入れておいてもよい } // 2つのデータx, yが属する木が同じならtrueを返す bool same(int x, int y) { return find(x) == find(y); } // データxが含まれる木の大きさを返す int size(int x) { return sizes[find(x)]; } }; int main(){ ll N, Q; cin >> N >> Q; vector<ll> C(N); rep(i, N) cin >> C[i]; rep(i, N) { stu[i][C[i]]++; } UnionFind uf(N); rep(i, Q) { ll op, a, b; cin >> op >> a >> b; if(op == 1) { a--;b--; uf.unite(a, b); } else { a--; ll g = uf.find(a); cout << stu[g][b] << endl; } } }
#include<bits/stdc++.h> using namespace std; #define Mod(x) (x>=P)&&(x-=P) #define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;++i) #define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;--i) #define erep(i,a) for(int i=hd[a];i;i=nxt[i]) typedef long long ll; void Max(int &x,int y){x<y&&(x=y);} void Min(int &x,int y){x>y&&(x=y);} bool vio; char IO; int rd(int res=0){ bool f=0; while(IO=getchar(),IO<48||IO>57) f|=IO=='-'; do res=(res<<1)+(res<<3)+(IO^48); while(IO=getchar(),isdigit(IO)); return f?-res:res; } const int M=2e5+10; struct node{int x,id;}; vector<node>g[M]; int cnt[M],ans[M],dep[M],n,q; int nxt[M],to[M],hd[M],ecnt; void Add(int a,int b){ nxt[++ecnt]=hd[a],to[hd[a]=ecnt]=b; } void dfs(int x,int f){ rep(i,0,(int)g[x].size()-1) ans[g[x][i].id]-=cnt[g[x][i].x]; dep[x]=dep[f]+1; cnt[dep[x]]++; erep(i,x)dfs(to[i],x); rep(i,0,(int)g[x].size()-1) ans[g[x][i].id]+=cnt[g[x][i].x]; } bool let; int main(){ cerr<<(&vio-&let)/1024.0/1024<<endl; n=rd(); rep(i,2,n)Add(rd(),i); q=rd(); rep(i,1,q){ int x=rd(),y=rd(); g[x].push_back((node){y+1,i}); } dfs(1,0); rep(i,1,q)printf("%d\n",ans[i]); }
#ifdef DEBUG_BUILD # define _GLIBCXX_DEBUG #endif #include <bits/stdc++.h> #ifdef DEBUG_BUILD # include "debugger.hpp" #else # define debug(...) # define debugdo(...) #endif using namespace std; using ll = long long; using ld = long double; using pll = std::pair<ll, ll>; template <class T> using vec = std::vector<T>; template <class T> using vec2 = std::vector<vec<T>>; template <class T> using vec3 = std::vector<vec2<T>>; #define rep(i, N) for (ll i = 0; i < (N); i++) #define rrep(i, N) for (ll i = (N) - 1; i >= 0; i--) #define range(i, A, B) for (ll i = (A); i < (B); i++) constexpr int MOD = 1000000007; constexpr ll INFL = std::numeric_limits<ll>::max(); template <class T> bool chmax(T &a, const T b) { if (a < b) { a = b; return true; } return false; } template <class T> bool chmin(T &a, const T b) { if (a > b) { a = b; return true; } return false; } ll N; vec<ll> P; vec2<ll> C; vec<ll> In, Out, Depth; ll timer = 0; vec2<ll> List; void dfs(const ll now) { In[now] = timer; timer++; List[Depth[now]].push_back(In[now]); for (ll to : C[now]) { Depth[to] = Depth[now] + 1; dfs(to); } Out[now] = timer; timer++; } void Main() { cin >> N; P.resize(N); C.resize(N); range(i, 1, N) { cin >> P[i]; P[i]--; C[P[i]].push_back(i); } In.resize(N); Out.resize(N); Depth.resize(N); List.resize(N); dfs(0); debug(List); debug(In); debug(Out); debug(Depth); ll Q; cin >> Q; rep(q, Q) { ll u, d; cin >> u >> d; u--; const auto& v = List[d]; debug(v); debug(In[u], Out[u], Depth[u]); cout << ( lower_bound(v.begin(), v.end(), Out[u]) - lower_bound(v.begin(), v.end(), In[u]) ) << "\n"; } } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(10); Main(); std::cout << std::flush; std::cerr << "--end--" << std::flush; return 0; }
#include <iostream> #include <vector> #include <algorithm> #define _LIBCPP_DEBUG 0 // clang // #define _GLIBCXX_DEBUG // gcc using namespace std; using ll = long long; int main() { int x, y, z; cin >> x >> y >> z; int res = (y * z - 1) / x; cout << res << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pll = pair<ll,ll>; using pld = pair<ld,ld>; using vll = vector<ll>; using vld = vector<ld>; using vstr = vector<string>; #define _GLIBCXX_DEBUG #define rep(j, m) for (ll j = 0; j < (ll)(m); j++) #define rep2(i, l, n) for (ll i = l; i < (ll)(n); i++) #define all(v) v.begin(), v.end() const ld PI = 3.1415926535897932; const ll MOD = 1000000007; const ll MOD2 = 998244353; vll dx = {-1,0,1,0}; vll dy = {0,-1,0,1}; vll Dx = {-1,-1,-1,0,0,1,1,1}; vll Dy = {-1,0,1,-1,1,-1,0,1}; const ll INF = 1000000000000000; int main() { ll X,Y,Z; cin >> X >> Y >> Z; cout << Z*Y/X - (1 - min(1LL,Z*Y%X)) << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int a, b,c, d; cin>>a>>b>>c>>d; int ans = INT_MIN; for(int i=a;i<=b;i++) { for(int j=c;j<=d;j++) ans = max(ans, i-j); } cout<<ans; }
#include<bits/stdc++.h> using namespace std; using ll = long long; using vl = vector<ll>; using vc = vector<char>; using vvl = vector<vl>; using vvc = vector<vc>; using pll = pair<ll, ll>; using vpll = vector<pll>; #define rep(i, n) for(ll i = 0; i < (ll)(n); i++) #define rep2(i, m, n) for(ll i = (ll)(m); i < (ll)(n); i++) #define rep_inv(i, n, m) for(ll i = (ll)(n); i > (ll)(m); i--) int main(){ ll a, b, c, d; cin >> a >> b; cin >> c >> d; cout << (b - c) << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; // 総数を1000000007(素数)で割った余り const long long mod = 1e9 + 7; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; #define ull unsigned long long #define ld long double #define vi vector<int> #define vll vector<ll> #define vc vector<char> #define vs vector<string> #define vpii vector<pii> #define vpll vector<pll> #define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++) #define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++) #define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--) #define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--) #define sz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define SORT(v, n) sort(v, v + n); #define VSORT(v) sort(v.begin(), v.end()); #define RSORT(x) sort(rall(x)); #define pb push_back #define mp make_pair #define INF (1e9) #define PI (acos(-1)) #define EPS (1e-7) ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; } ull lcm(ull a, ull b) { return a / gcd(a, b) * b; } const string YES = "Yes"; const string NO = "No"; ll multiplecount(ll A, ll B, ll X) { ll countA = (A - 1) / X; ll countB = B / X; ll ans = countB - countA; return ans; } int main() { ll A, B; cin >> A >> B; ll X = B - A; ll ans; for (ll i = X; i > 0; i--) { if (multiplecount(A, B, i) >= 2) { ans = i; break; } } cout << ans << endl; return 0; }
#include<bits/stdc++.h> #define LL long long using namespace std; int n,m; LL a[200010],b[200010]; LL A[200010],B[200010],ans=1e18; inline LL read() { LL x=0,w=0;char ch=0; while(!isdigit(ch)){w|=ch=='-';ch=getchar();} while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();} return w?-x:x; } LL Find(LL x) { int L=1,R=n,M,T=1; while(L<=R){ M=(L+R)>>1; if(a[M]<=x)T=M,L=M+1; else R=M-1; } return T; } int main() { n=read();m=read(); for(int i=1;i<=n;(i++)[a]=read()); for(int i=1;i<=m;*(b+i++)=read()); sort(a+1,a+1+n); //for(int i=1;i<=n;i++) // cout<<a[i]<<' '; //cout<<endl; for(int i=2;i<=n;i+=2){ B[i]=B[i-2]; A[i+1]=A[i-1]; B[i]+=a[i]-a[i-1]; A[i+1]+=a[i+1]-a[i]; } //for(int i=1;i<=n;i++){ // if(i&1)printf("%d ",A[i]); // else printf("%d ",B[i]); //} //cout<<endl; for(int i=1;i<=m;i++){ int pos=Find(b[i]); //cout<<b[i]<<','<<pos<<' '; if(pos&1){ ans=min(ans,B[pos-1]+abs(a[pos]-b[i])+A[n]-A[pos]); ans=min(ans,B[pos-1]+abs(a[pos+1]-b[i])+abs(a[pos]-a[pos+2])+A[n]-A[pos+2]); }else{ ans=min(ans,B[pos-2]+A[n]-A[pos+1]+abs(b[i]-a[pos])+abs(a[pos-1]-a[pos+1])); ans=min(ans,B[pos]+A[n]-A[pos+1]+abs(a[pos+1]-b[i])); } //cout<<ans<<'\n'; } cout<<ans<<'\n'; }
#include <bits/stdc++.h> #define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); #define lowbit(x) (x & -x) #define FOR(i,a,b) for(int i=(a); i< (b); ++i) #define RFOR(i,b,a) for(int i=(b);i>=(a);i--) #define REP(i,a,b) for(int i=(a); i<=(b); ++i) #define PI 3.14159265358979323846264338327950L using namespace std; typedef long long ll; template<typename T> void PrArr(const T a[] , int len){ for(int i = 0;i <= len; i++)cout << a[i] << " "; cout << endl; } template<typename T> void PrVec(const vector<T> a){ for(auto it : a)cout << it << " "; cout << endl; } const int MAX = 0x7ffffff; const int MIN = 0xcf; int test; void slove() { string s1, s2, s3; cin >> s1 >> s2 >> s3; // 1. 记录一下每个字符出现的次数 map<char, int> mp; for(char c : s1) mp[c] ++; for(char c : s2) mp[c] ++; for(char c : s3) mp[c] ++; /* 如果出现的字母数量大于10意味着要出现10个不同数字表示 这样是不可能成立的,所以这种情况下一定不存在解 */ if(mp.size() > 10) { cout << "UNSOLVABLE" << endl; return ; } // 获取到以上出现过哪些字母并组合成一个字符串 string s0; for(auto p : mp) s0 += p.first; int m = s0.size(); vector<int> v(10); for(int i = 0; i < 10 ; i++) v[i] = i; auto val = [&](char c) { for(int i = 0; i < m; i ++) { if(c == s0[i]) { return v[i]; } } return -1; }; do { // 此时数字包含前导0需要排除这种情况。 if(val(s1[0]) == 0 || val(s2[0]) == 0 || val(s3[0]) == 0) { continue; } ll x1 = 0, x2 = 0, x3 = 0; for(auto c : s1) { x1 *= 10; x1 += val(c); } for(auto c : s2) { x2 *= 10; x2 += val(c); } for(auto c : s3) { x3 *= 10; x3 += val(c); } if(x1 + x2 == x3) { cout << x1 << endl; cout << x2 << endl; cout << x3 << endl; return ; } } while(next_permutation(v.begin(),v.end())); cout << "UNSOLVABLE" << endl; } int main() { #ifdef LOCAL auto start_time = clock(); cerr << setprecision(3) << fixed; // 在iomanip中 #endif SIS;slove(); #ifdef LOCAL auto end_time = clock(); cerr << "Execution time: " << (end_time - start_time) * (int)1e3 / CLOCKS_PER_SEC << " ms\n"; #endif }
#include<bits/stdc++.h> using namespace std; int main(){ vector<string> vec(3); for(int i=0; i<3; i++){ cin >> vec[i]; } map<char,int> M; int cnt = 0; for(int i=0; i<3; i++){ for(int j=0; j<vec[i].size(); j++){ if(!M.count(vec[i][j])){ M[vec[i][j]] = cnt; cnt++; } } } if(M.size() > 10){ cout << "UNSOLVABLE" << endl; return 0; } vector<char> num = {'0','1','2','3','4','5','6','7','8','9'}; do{ vector<string> check = vec; for(int i=0; i<3; i++){ for(int j=0; j<vec[i].size(); j++){ check[i][j] = num[M[vec[i][j]]]; } } if(check[0][0] == '0' || check[1][0] == '0' || check[2][0] == '0'){ continue; } int64_t A = stoll(check[0]); int64_t B = stoll(check[1]); int64_t C = stoll(check[2]); if(A + B == C){ cout << A << endl; cout << B << endl; cout << C << endl; return 0; } }while(next_permutation(num.begin(),num.end())); cout << "UNSOLVABLE" << endl; }
#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; //typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> index_set; //typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update>indexed_multiset; #define ull unsigned long long #define ll long long int #define ld long double #define MOD 1000000007 #define pi 3.14159265358979323846 #define N 100005 #define sz(x) ((int)(x).size()) #define test ll t; cin >> t; while(t--) #define all(x) (x).begin(), (x).end() #define ld long double #define bigint int64_t #define vll vector<ll> #define vpll vector<pair<ll,ll>> //#define mp make_pair #define pb push_back #define pll pair<ll,ll> #define vvll vector<vector<ll>> #define fi first #define se second #define ins insert #define endl "\n" #define rep(i,a,n) for(ll (i) = a;(i) < (n); (i)++) #define repn(i,a,n) for(ll (i) = a;(i) <= (n); (i)++) #define repr(i,a,n) for(ll (i) = a;(i) >= (n); (i)--) //-------------------DEBUGGING----------------------- vector<string> vec_splitter(string s) { s += ','; vector<string> res; while (!s.empty()) { res.push_back(s.substr(0, s.find(','))); s = s.substr(s.find(',') + 1); } return res; } void debug_out( vector<string> __attribute__ ((unused)) args, __attribute__ ((unused)) int idx, __attribute__ ((unused)) int LINE_NUM) { cerr << endl; } template <typename Head, typename... Tail> void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) { if (idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") "; stringstream ss; ss << H; cerr << args[idx] << " = " << ss.str(); debug_out(args, idx + 1, LINE_NUM, T...); } #ifdef XOX #define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__) #else #define debug(...) 42 #endif //----------------------------------------------------------------------- //will upsolve from now on. Date: 24th Oct 2020, DIV2 round 678 upto D. void solve() { ll n; cin >> n; vpll v; rep(i, 0, n) { ll x, y; cin >> x >> y; v.pb({x, y}); } sort(all(v)); repn(i, 0, n - 3) { repn(j, i + 1, n - 2) { repn(k, j + 1, n - 1) { ll a = v[i].fi, b = v[i].se; ll c = v[j].fi, d = v[j].se; ll e = v[k].fi, f = v[k].se; ll k1 = d - b, k2 = c - a, k3 = f - d, k4 = e - c; //if (k2 > 0 && k4 > 0) { if ((double)k1 / k2 == (double)k3 / k4 ) { cout << "Yes\n"; return; } //} } } } cout << "No\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); return 0; }
#include<bits/stdc++.h> using namespace std; #define deb(x) cout <<"\n"<< (#x) << " = " << (x) << "\n" const long long INF = 1e18; const long long mod=1e9+7 ; #define ll long long int bool iscolinear(int x1, int y1, int x2, int y2, int x3, int y3) { int a = x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2); if (a == 0) return true; else return false; } void solve() { int n; cin>>n; vector< pair<int,int> > a ; for(int i=0 ; i<n ; ++i) { int x,y; cin>>x>>y; a.push_back(make_pair(x,y)); } for(int i=0 ; i<n ; ++i) { for(int j=i+1 ; j<n ; ++j) { for(int k=j+1 ; k<n ; ++k) { if(iscolinear(a[i].first,a[i].second,a[j].first,a[j].second,a[k].first,a[k].second)) { cout<<"Yes\n"; return ; } } } } cout<<"No\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t=1; // cin>>t; while(t--) solve(); } /* y=mx+c 5=m5+c */
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; #define rep(i, n) for(int i = 0; i < (n); ++i) #define all(x) (x).begin(), (x).end() #define io ios::sync_with_stdio(false); cin.tie(0) void print_vec(const vector<int>& vec) { int n = vec.size(); cout << n << " "; rep(i, n) { cout << vec[i]; if (i != n-1) cout << " "; } cout << endl; } int main() { io; int n; cin >> n; vector<ll> a(n); rep(i, n) cin >> a[i]; int x = min(n, 8); vector<vector<int>> cnt(200); rep(bit, 1 << x) { int s = 0; vector<int> temp; rep(i, x) { if (bit & (1 << i)) { temp.push_back(i+1); s += a[i]; s %= 200; } } if (cnt[s].size()) { cout << "Yes" << endl; print_vec(cnt[s]); print_vec(temp); return 0; } else cnt[s] = temp; } cout << "No" << endl; return 0; }
// Author : Sarthak Kapoor #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; #define int ll #define rep(i,n) for(int i=0;i<n;++i) #define repa(i,a,n) for(int i=a;i<n;++i) #define repr(i,n) for(int i=n-1;i>=0;--i) #define ll long long #define pi pair<int,int> #define pii pair<pi,int> #define vi vector<int> #define pb push_back #define fi first #define sec second #define all(v) v.begin(),v.end() #define s(v) v.size() ll mod = 1000000007; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1] ll gcd(ll a,ll b){ if(b==0)return a; return gcd(b,a%b); } ll fastexp(ll x,ll a){ ll res = 1; while(a>0){ if(a&1){ res = (res*x)%mod; } a=a>>1; x=(x*x)%mod; } return res; } ll inverse(ll n){ return fastexp(n,mod-2); } template <typename T> void add(T &a, T b){ a += b; if(a >= mod)a -= mod; } template <typename T> void sub(T &a, T b){ a -= b; if(a < 0)a += mod; } template <typename T> void mul(T &a, T b){ a *= b; if(a >= mod)a %= mod; } signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin>>n; vi v(n); rep(i,n){ cin>>v[i]; } int offset = 0; map<int,int> mp; mp[v[0]]++; int ans = 0; repa(i,1,n){ if(i%2 == 1){ ans += mp[-offset+v[i]]; offset -= v[i]; mp[-v[i]-offset]++; } else{ ans += mp[-offset-v[i]]; offset += v[i]; mp[-offset+v[i]]++; } // cout<<i<<" "<<ans<<"\n"; // for(auto x:mp){ // cout<<x.fi<<" "<<x.sec<<"\n"; // } // // cout<<"\n"; // cout<<offset<<" offset\n\n"; } cout<<ans; return 0; }
/*Lucky_Glass*/ #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; const int N=2e5+10; inline int Rint(int &r){ int b=1,c=getchar();r=0; while(c<'0' || '9'<c) b=c=='-'? -1:b,c=getchar(); while('0'<=c && c<='9') r=(r<<1)+(r<<3)+(c^'0'),c=getchar(); return r*=b; } int n,m,nstk,cnt; int wei[N],now[N],uni[N],ans[N<<1][2],stk[N],fstk[N]; pair<int,int> lmt[N]; bool vis[N]; void Answer(int a,int b){ a=lmt[a].second,b=lmt[b].second; ans[++m][0]=a,ans[m][1]=b; swap(now[a],now[b]); } int main(){ Rint(n); for(int i=1;i<=n;i++) Rint(lmt[i].first),lmt[i].second=i; for(int i=1;i<=n;i++) Rint(wei[i]); for(int i=1;i<=n;i++) Rint(now[i]); for(int i=1;i<=n;i++) if(now[i]!=i && wei[now[i]]>=lmt[i].first){ printf("-1\n"); return 0; } sort(lmt+1,lmt+1+n); for(int i=1;i<=n;i++){ uni[lmt[i].second]=i; if(lmt[i].second==now[lmt[i].second]) vis[i]=true; } for(int i=1;i<=n;i++) if(!vis[i]){ nstk=0; int tmp=i; while(true){ stk[++nstk]=tmp; tmp=uni[now[lmt[tmp].second]]; if(tmp==i) break; } fstk[cnt=1]=stk[1]; for(int j=2;j<=nstk;j++) if(fstk[cnt]>stk[j]) Answer(fstk[cnt],stk[j]); else fstk[++cnt]=stk[j]; for(int j=1;j<cnt;j++) Answer(fstk[j],fstk[cnt]); } //for(int i=1;i<=n;i++) // printf("%d %d\n",i,now[i]); printf("%d\n",m); for(int i=1;i<=m;i++) printf("%d %d\n",ans[i][0],ans[i][1]); return 0; }
#include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <bits/stdc++.h> using namespace __gnu_pbds; using namespace std; typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") using ll = long long; using ld = long double; #define mp make_pair /* int p = 1e9 + 7; int mul(int a, int b) { return (1LL * a * b) % p; } int add(int a, int b) { int s = (a+b); if (s>=p) s-=p; return s; } int sub(int a, int b) { int s = (a+p-b); if (s>=p) s-=p; return s; } int po(int a, ll deg) { if (deg==0) return 1; if (deg%2==1) return mul(a, po(a, deg-1)); int t = po(a, deg/2); return mul(t, t); } int inv(int n) { return po(n, p-2); }*/ mt19937 rnd(time(0)); /* const int N = 2000005; vector<int> facs(N), invfacs(N); void init() { facs[0] = 1; for (int i = 1; i<N; i++) facs[i] = mul(facs[i-1], i); invfacs[N-1] = inv(facs[N-1]); for (int i = N-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1); } int C(int n, int k) { if (n<k) return 0; if (n<0 || k<0) return 0; return mul(facs[n], mul(invfacs[k], invfacs[n-k])); }*/ /*struct DSU { vector<int> sz; vector<int> parent; vector<bool> cycle; void make_set(int v) { parent[v] = v; sz[v] = 1; } int find_set(int v) { if (v == parent[v]) return v; return parent[v] = find_set(parent[v]); } void union_sets(int a, int b) { a = find_set(a); b = find_set(b); if (a==b) cycle[a] = true; if (a != b) { if (sz[a] < sz[b]) swap(a, b); parent[b] = a; sz[a] += sz[b]; if (cycle[b]) cycle[a] = true; } } DSU (int n) { parent.resize(n); sz.resize(n); cycle.resize(n); for (int i = 0; i<n; i++) make_set(i); } };*/ int main() { ios_base::sync_with_stdio(0); cin.tie(nullptr); int n; cin>>n; vector<int> a(n), b(n), p(n); for (int i = 0; i<n; i++) cin>>a[i]; for (int i = 0; i<n; i++) cin>>b[i]; for (int i = 0; i<n; i++) {cin>>p[i]; p[i]--;} vector<int> have(n); for (int i = 0; i<n; i++) have[i] = b[p[i]]; for (int i = 0; i<n; i++) if (a[i]<=have[i] && p[i]!=i) {cout<<-1; return 0;} vector<pair<int, int>> ops; vector<bool> visited(n); for (int i = 0; i<n; i++) if (p[i]!=i && !visited[i]) { vector<int> bruh = {i}; visited[i] = true; int cur = p[i]; while (cur!=i) { visited[cur] = true; bruh.push_back(cur); cur = p[cur]; } int best = 0; int k = bruh.size(); for (int j = 1; j<k; j++) if (have[bruh[j]]<have[bruh[best]]) best = j; for (int i = 0; i<k-1; i++) { ops.push_back(mp(bruh[(best-i-1+k)%k], bruh[(best-i+k)%k])); } } cout<<ops.size()<<endl; for (auto it: ops) cout<<it.first+1<<' '<<it.second+1<<endl; }
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; typedef long long LL; typedef pair<LL, LL> PII; PII vote[N]; LL n; bool cmp(PII, PII); int main(){ cin >> n; LL va = 0, vb = 0; for(LL i = 1; i <= n; i++){ cin >> vote[i].first >> vote[i].second; va += vote[i].first; } sort(vote + 1, vote + 1 + n, cmp); for(LL i = 1; i <= n; i++){ va -= vote[i].first; vb += (vote[i].second + vote[i].first); if(vb > va){ printf("%lld\n", i); return 0; } } return 0; } bool cmp(PII a, PII b){ if((a.first * 2 + a.second) != (b.first * 2 + b.second)) return (a.first * 2 + a.second) > (b.first * 2 + b.second); else return a.first > b.first; }
#include<bits/stdc++.h> using namespace std; #define setbits(x) __builtin_popcountll(x) #define leadzero(x) __builtin_clz(x) #define trailzero(x) __builtin_ctz(x) #define mod 1000000007 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define ll long long #define int ll #define ld long double #define ff first #define ss second #define pb push_back #define eb emplace_back #define popb pop_back #define endl '\n' #define all(v) v.begin(), v.end() #define sz(x) ((int)((x).size())) typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<int, pii> pip; typedef pair<pii, int> ppi; typedef pair<string, string> pss; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<pii> vii; typedef vector<pll> vll; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<string> vs; ll power(ll a, ll b) { if(b<0) return 1; ll res=1; while(b) { if(b&1) res = (res*a);//%mod; a = (a*a);//%mod; b >>= 1; } return res; } template <class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; } template <class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; } #define rep(i, n) rep2(i, 0, n) #define rep2(i, m, n) for (int i = m; i < (n); i++) bool ispoweroftwo(ll x){ return (x&&!(x&(x-1)));} ll GCD(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;} ll LCM(ll a, ll b) {return a / GCD(a, b) * b;} const int inf = 1e9; const ll INF = 1e18; const ld pi = 3.141592653589793238; int dx[] = {-1, 0, 1, 0}; int dy[] = {0, 1, 0, -1}; char MV[] = {'U', 'R', 'D', 'L'}; //Shoot for the moon - If you miss, you'll end up in the stars //integer to char always remember (char+'0') //--------------------------------------------------------------------------------------- int32_t main() { FIO; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int n; cin >> n; vi a(n), b(n); vector<pll> v; ll aoki = 0, taka = 0; rep(i, n) { cin >> a[i] >> b[i]; v.pb({2 * a[i] + b[i], i}); aoki += a[i]; } sort(all(v)); ll ans = 0; for (int i = n-1; i >= 0 && aoki >= taka; --i) { ans++; int ind = v[i].ss; aoki -= a[ind]; taka += a[ind] + b[ind]; } cout << ans; return 0; }
#include <bits/stdc++.h> #define gc() getchar() using namespace std; typedef long long ll; template <typename T> void rd(T &x){ ll f=1;x=0;char c=gc(); for(;!isdigit(c);c=gc())if(c=='-')f=-1; for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c^48); x*=f; } int a,b; int main(){ rd(a),rd(b); printf("%d\n",(1+a)*a/2*b*100+(1+b)*b/2*a); return 0; }
#include<bits/stdc++.h> #define rep(i, s, n) for (long long i = s; i < (int)(n); i++) #define all(a) a.begin(), a.end() #define put(i) cout<<fixed<<i<<endl #define putl(a) for(auto x:a)cout<<x<<' '; cout<<endl using namespace std; using ll = long long; int main(){ ll n; cin >> n; deque<char> q; rep(i,0,n){ char tmp; cin >> tmp; q.push_back(tmp); ll size = q.size(); if(size > 2 and q[size-1] == 'x' and q[size-2] == 'o' and q[size-3] == 'f'){ q.pop_back(); q.pop_back(); q.pop_back(); } } put(q.size()); }
#include <bits/stdc++.h> using namespace std; bool flg[100][100]; int main() { int n; cin >> n; for(int i = 0; i < n; ++i) { for(int j = 0; j < n; ++j) { char c; cin >> c; flg[i][j] = (c == '1'); } flg[i][i] = true; } for(int k = 0; k < n; ++k) { for(int i = 0; i < n; ++i) { for(int j = 0; j < n; ++j) { flg[i][j] |= (flg[i][k] & flg[k][j]); } } } double ans = 0; for(int i = 0; i < n; ++i) { int cnt = 0; for(int j = 0; j < n; ++j) { cnt += flg[j][i]; } ans += 1.0 / (double)cnt; } printf("%.15f\n", ans); return 0; }
#pragma GCC optimize("Ofast") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #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; #define mp make_pair #define eb emplace_back #define pb push_back #define e1 first #define e2 second #define size(x) (int)x.size() #define all(r) begin(r),end(r) #define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) #define time chrono::high_resolution_clock().now().time_since_epoch().count() #define satori int testCases; cin>>testCases; while(testCases--) typedef unsigned int uint; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; /////////////////// #define DEBUG if(1) /////////////////// ll pot(ll x,ll wyk,ll mod){ ll res=1; while(wyk){ if(wyk&1) res=(res*x)%mod; x=(x*x)%mod; wyk/=2ll; } return res; } int32_t main(){ fastio; ll a,b; cin>>a>>b; if(b==1){ cout<<"0\n"; return 0; } ll residue=pot(10ll,a,b*b); ll res=(residue/b)%b; cout<<res<<'\n'; return 0; }
#include <bits/stdc++.h> #define fi first #define se second #define ll long long #define dl double using namespace std; const int N = 2e6 + 7; const long long mod = 1e9 + 7; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int n,m,k; ll bnp(ll x, ll y) { if(y == 0)return 1ll; if(y % 2){ return x * bnp(x, y - 1) % mod; }else{ ll b = bnp(x, y / 2); return b * b % mod; } } ll f[N]; ll C(ll n, ll k) { if(k > n)return 0ll; return f[n] * bnp(f[n - k] * f[k] % mod, mod - 2) % mod; } void solve() { f[0] = 1; for(int i = 1; i < N; i++)f[i] = f[i - 1] * i % mod; cin >> n >> m >> k; if(n > m + k){ cout << 0; return; } cout << (C(n + m, n) - C(n + m, n - k - 1) + mod) % mod; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); //freopen( "input.txt" , "r" , stdin ); //freopen( "output.txt" , "w" , stdout ); int t = 1; //cin >> t; while(t--){ solve(); } }
#include <iostream> #include <stdio.h> #include <algorithm> #include <cmath> #include <string> #include <vector> #include <iomanip> #include <queue> #include <deque> #include <map> #include <unordered_map> #define rep(i,n) for(int i=0;i<n;i++) #define repn(i,n) for(int i=1;i<=n;i++) #define repr(e,x) for(auto& e:x) using namespace std; typedef long long ll; typedef long double ld; //typedef pair<int,int> P; double const PI=3.141592653589793; int const INF=1001001001; ll const LINF=1001001001001001001; ll const MOD=1000000007; int a,b,c,d; int main(){ cin>>a>>b>>c>>d; int ans; if(a==c && b==d) ans=0; else if(a+b==c+d) ans=1; else if(a-b==c-d) ans=1; else if(abs(a-c)+abs(b-d)<=3) ans=1; else if((a+b+c+d)%2==0) ans=2; else if(abs(a-c)+abs(b-d)<=6) ans=2; else if(abs((a+b)-(c+d))<=3) ans=2; else if(abs((a-b)-(c-d))<=3) ans=2; else ans=3; cout<<ans<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define fr(i,t) for(i=0;i<t;i++) #define fr1(i,r,t) for(i=r;i<t;i++) typedef long long int lli; typedef unsigned long long int ulli; #define inf LONG_MAX #define ff first #define ss second double pie=3.14159265358979323846; #define dbug(x) cout<<#x<<"="<<x<<endl; #define dbug2(x,y) // lli M=1e9+7; lli M=998244353; #define gg cout<<"Case #"<<i+1<<": " #define exact(x) cout<<fixed<<setprecision(8)<<x<<endl int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); lli T,n,i,j,k=0,m,j1,co=0,check,mi,l,sum; lli ans=0; // cin>>T; // fr(i,T) // { cin>>n>>m>>k; ans=((k*(k+1))/2)%M; ans=(ans*(((m*(m+1))/2)%M))%M; ans=(ans*(((n*(n+1))/2)%M))%M; cout<<ans<<endl; // } }
#define _DEBUG #include "bits/stdc++.h" //#include <atcoder/all> #define CHOOSE(a) CHOOSE2 a #define CHOOSE2(a0,a1,a2,a3,a4,a5,x,...) x #define debug_1(x1) cout<<#x1<<": "<<x1<<endl #define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl #define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl #define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl #define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl #define debug_6(x1,x2,x3,x4,x5,x6) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<", "#x6<<": "<<x6<<endl #ifdef _DEBUG #define debug(...) CHOOSE((__VA_ARGS__,debug_6,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__) #else #define debug(...) #endif #define rep(index,num) for(int index=0;index<(int)num;index++) #define rep1(index,num) for(int index=1;index<=(int)num;index++) #define brep(index,num) for(int index=(int)num-1;index>=0;index--) #define brep1(index,num) for(int index=(int)num;index>0;index--) #define scan(argument) cin>>argument #define prin(argument) cout<<argument<<endl #define prind(argument) cout<<std::fixed<<setprecision(13)<<argument<<endl #define kaigyo cout<<endl #define eps 1e-7 #define PI acosl(-1) #define mp(a1,a2) make_pair(a1,a2) #define ALL(a) (a).begin(),(a).end() #define rALL(a) (a).rbegin(),(a).rend() #define puba emplace_back #define pubamp(a,b) emplace_back(mp(a,b)) typedef long long ll; typedef long double ld; using namespace std; //using namespace atcoder; typedef pair<ll,ll> pll; typedef pair<int,int> pint; typedef vector<int> vint; typedef vector<ll> vll; typedef vector<pint> vpint; typedef vector<pll> vpll; template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } ll INFl=(ll)1e+18+1; int INF=1e+9+1; int main(){ int N; vector<pair<int,string>> ts; scan(N); rep(i,N){ int T; string S; scan(S>>T); ts.pubamp(T,S); } sort(rALL(ts)); prin(ts[1].second); return 0; }
#include "bits/stdc++.h" using namespace std; using vi = vector<int>; using vvi = vector<vi>; #define pb push_back #define sz size() #define ice(i, a, b) for (int (i) = (a); (i) < (b); ++(i)) void solve() { int n, m; cin >> n >> m; vi v(n); vvi track(1500001); ice (i, 0, 1500001) { track[i].pb(-1); } ice (i, 0, n) { cin >> v[i]; track[v[i]].pb(i); } ice (i, 0, 1500001) { track[i].pb(n); } ice (i, 0, 1500001) { bool ok = true; ice (j, 1, track[i].sz) { ok &= (track[i][j] - track[i][j - 1] <= m); } if (!ok) { cout << i; return; } } } int main() { solve(); }
#include <bits/stdc++.h> using namespace std; #define poi 400100 typedef long long ll; typedef double db; const int mod = 998244353; int f[poi]; inline int re() { char c = getchar(); int x = 0, k = 1; while (c < '0' || c > '9') { if (c == '-') k = -1; c = getchar(); } while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + c - '0', c = getchar(); return k * x; } void wr(int x) { if (x < 0) putchar('-'), x = -x; if (x > 9) wr(x / 10); putchar(x % 10 + '0'); } int fin(int x) { return f[x] == x ? x : f[x] = fin(f[x]); } inline void bin(int x, int y) { x = fin(x), y = fin(y); f[x] = y; } inline int ksm(int x, int y) { int ans = 1; for (; y; y >>= 1) { if (y & 1) ans = ((ll)ans * x) % mod; x = ((ll)x * x) % mod; } return ans; } signed main() { int n = re(), tot = 0; for (int i = 1; i <= n; i++) f[i] = i; for (int i = 1; i <= n; i++) { int qqq = re(); bin(i, qqq); } for (int i = 1; i <= n; i++) if (fin(i) == i) tot++; wr(ksm(2, tot) - 1); return 0; }
#include<bits/stdc++.h> #define db double using namespace std; int read() { int a=0,f=1,c=getchar(); while(!isdigit(c)) { if(c=='-')f=-1; c=getchar(); } while(isdigit(c)) { a=a*10+c-'0'; c=getchar(); } return a*f; } const int N=1e5+10; const db INF=1e18; int n; int a[N]; int main() { // freopen("1.in","r",stdin); n=read(); for(int i=1;i<=n;++i)a[i]=read(); sort(a+1,a+n+1); db ans=INF,sum=0; for(int i=0;i<=n;++i) { sum+=a[i]; db x=(db)a[i]/2; ans=min(ans,n*x-(sum+(n-i)*x*2)); } ans=(ans+sum)/n; printf("%lf\n",ans); return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (int)(n); i++) using namespace std; using LL = long long; using P = pair<int,int>; using vv = vector<vector<int>>; const int INF = (int)1e9; const LL LINF = (LL)1e18; int main(){ int K; cin >> K; int ans = 0; for(int A = 1; A <= K; A++){ for(int B = 1; B <= K; B++){ if(A * B > K) break; ans += K / (A * B); } } cout << ans << endl; return 0; }
#include <iostream> #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double db; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> #define pll pair<ll,ll> #define pb push_back #define eb emplace_back #define mp make_pair #define ub(v,val) upper_bound(v.begin(),v.end(),val) #define np(str) next_permutation(str.begin(),str.end()) #define lb(v,val) lower_bound(v.begin(),v.end(),val) #define sortv(vec) sort(vec.begin(),vec.end()) #define rev(p) reverse(p.begin(),p.end()); #define v vector #define pi 3.14159265358979323846264338327950288419716939937510 #define len length() #define repc(i,s,e) for(ll i=s;i<e;i++) #define fi first #define se second #define mset(a,val) memset(a,val,sizeof(a)); #define mt make_tuple #define repr(i,n) for(i=n-1;i>=0;i--) #define rep(i,n) for(i=0;i<n;i++) #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define at(s,pos) *(s.find_by_order(pos)) #define set_ind(s,val) s.order_of_key(val) long long int M = 1e9 + 7 ; long long int inf = 9 * 1e18; //CLOCK ll begtime = clock(); #define time() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //CLOCK ENDED ll n, m; // modular exponentiation ll binpow(ll val, ll deg) { if (deg < 0) return 0; if (!deg) return 1 % M; if (deg & 1) return binpow(val, deg - 1) * val % M; ll res = binpow(val, deg >> 1); return (res * res) % M; } //binomial ll modinv(ll n) { return binpow(n, M - 2); } //GCD ll gcd (ll a, ll b) { if (b == 0) return a; else return gcd (b, a % b); } int main() { // your code goes here IOS; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll i, j, t, k, x, y, z, N; cin >> n; ll a[n]; ll pos[n + 1]; rep(i, n) { cin >> a[i]; pos[a[i]] = i; } ll used[n]; mset(used, 0); v<ll> out; ll flg = 0; for (i = n; i >= 1; i--) { x = pos[i]; while (1) { if (x + 1 < n) { if (a[x + 1] > a[x]) { break; } else { if (used[x]) { flg = 1; break; } else { used[x] = 1; out.pb(x + 1); swap(a[x], a[x + 1]); pos[a[x]] = x; pos[a[x + 1]] = x + 1; x++; } } } else break; } } if (flg) cout << -1; else { ll flg = 0; rep(i, n) { if (a[i] != i + 1) flg = 1; break; } if (flg) { cout << -1; } else { if (out.size() != n - 1) cout << -1; else rep(i, out.size()) cout << out[i] << '\n'; } } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 200010; int n, p[N]; int main() { cin >> n; for (int i = 1; i <= n; ++i) { scanf("%d", p + i); } vector <int> ans; for (int i = n; i >= 1; --i) { if (p[i] == i) continue; int at = -1; for (int j = i - 1; j >= 1; --j) if (p[j] == i) { at = j; break; } for (int j = at; j < i; ++j) { ans.emplace_back(j); swap(p[j], p[j + 1]); } for (int j = at + 1; j <= i; ++j) { if (p[j] != j) { cout << "-1\n"; return 0; } } i = at + 1; } for (int i = 1; i <= n; ++i) { if (p[i] != i) { cout << "-1\n"; return 0; } } if (ans.size() != n - 1) { cout << "-1\n"; return 0; } for (int x : ans) printf("%d\n", x); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const long long INF = 1001001001; const long long MOD = 1000000007; const double EPS = 1e-10; int main(){ cin.tie(0); ios::sync_with_stdio(false); int n; cin>>n; int a[n],minv=INF,maxv=-1; for(int i=0;i<n;i++){ cin>>a[i]; minv=min(minv,a[i]); maxv=max(maxv,a[i]); } int preV=minv; while(1){ for(int i=0;i<n;i++)a[i]%=minv; minv=INF; for(int i=0;i<n;i++){ if(a[i]==0)continue; minv=min(minv,a[i]); } if(minv==INF){ cout<<preV<<endl; return 0; } preV=minv; } }
#include <bits/stdc++.h> using namespace std; #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define fi first #define se second #define mp(i,j) make_pair(i,j) typedef long long ll; const int maxn = 1e3+5; vector<int> vec; vector<int> pre; int gcd(int x,int y){ return y? gcd(y,x%y) : x; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; int now = 0; for(int i = 0; i < n; ++i){ int x; cin >> x; now = gcd(now,x); }cout<<now << endl; return 0; }
#include<bits/stdc++.h> #define cs const #define fr first #define se second #define ls (now<<1) #define mp make_pair #define pb push_back #define ll long long #define ppb pop_back #define rs (now<<1|1) #define int long long #define mid ((l+r)>>1) #define low(i) (i&(-i)) #define par pair<int,int> #define cn(x) memset(x, 0, sizeof(x)) #define rep(i, x, y) for(int i=x; i<=y; ++i) #define sep(i, x, y) for(int i=x; i>=y; --i) #define fore(i, x) for(int i=fir[x]; i; i=nex[i]) using namespace std; cs int G = 3; cs int ff = 3e6 + 15; cs int inf = 1e18 + 1; cs int base = 4; cs int M = 998244353; int n, m, a[ff], b[ff], fa[ff]; int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); } void init() { cin >> n >> m; rep(i, 1, n) fa[i] = i; rep(i, 1, n) scanf("%lld", &a[i]); rep(i, 1, n) scanf("%lld", &b[i]); rep(i, 1, m) { int u, v; scanf("%lld %lld", &u, &v); int fau = find(u), fav = find(v); if(fau != fav) fa[fau] = fav, a[fav] += a[fau], b[fav] += b[fau]; } rep(i, 1, n) if(a[find(i)] != b[find(i)]) { puts("No"); return; } puts("Yes"); } signed main() { // freopen("1.in", "r", stdin); // freopen("number.out", "w", stdout); int Ts = 1; while(Ts--) init(); } /* 2 8 push 1 1 1 push 1 2 1 push 2 3 2 put 1 2 put 2 1 put 1 2 put 2 1 pop 1 1 */
#include <bits/stdc++.h> using namespace std; #define ffor(i,o,f) for(int i = o; i < f; i++) #define pb push_back #define mp make_pair #define all(a) (a).begin(), (a).end() #define F first #define S second #define PI 3.14159265358979323846264338327950 #define endl '\n' #define lcm(a,b) (a*b)/__gcd(a,b) typedef long long ll; typedef pair < int, int > pii; typedef vector < int > vi; typedef vector < pii > vii; typedef vector < vi > gi; typedef vector < ll > vll; typedef map < int, int > mii; const int INF = int(1e9 + 7); int main() //IBMG { //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); //freopen("","r",stdin); //freopen("","w",stdout); string s; int aux; bool ok; mii m; mii mm; cin >> s; ffor(i, 0, s.size()) m[s[i]-48] ++; mm = m; if (s.size() == 1) { if (s[0] == '8') cout << "Yes" << endl; else cout << "No" << endl; return 0; } if (s.size() == 2) { for (int i = 16; i <= 96; i += 8) { aux = i; ok = true; while (aux >= 1) { if (m[aux%10] > 0) m[aux%10] --; else ok = false; aux /= 10; } m = mm; if (ok) { cout << "Yes" << endl; break; } else if (i == 96) cout << "No" << endl; } return 0; } for (int i = 104; i <= 992; i += 8) { aux = i; ok = true; while (aux >= 1) { if (m[aux%10] > 0) m[aux%10] --; else ok = false; aux /= 10; } m = mm; if (ok) { cout << "Yes" << endl; break; } else if (i == 992) cout << "No" << endl; } return 0; }
// abc188F.cpp #include <iostream> #include <vector> #include <map> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; ll x; map<ll, ll> memo; ll f(ll y) { if (y == 1)return abs(x - y); if (memo.find(y) != memo.end()) return memo[y]; if (y % 2 == 0) { return memo[y] = min(f(y / 2) + 1, abs(y - x)); } else { return memo[y] = min(min(f(y + 1) + 1,f(y - 1) + 1),abs(y - x)); } } int main() { ll y; cin >> x >> y; cout << f(y) << endl; return 0; }
#include<iostream> #include <vector> #include <algorithm> #include <cmath> #include <map> #include<time.h> using namespace std; //int N=1; int P[11] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; int binary(int bina) { int ans = 0; for (int i = 0; bina > 0; i++) { //ans = ans + (bina % 2) * pow(10, i); bina = bina / 2; } return ans; } int rev(int original) { int reversed = 0; while (original > 0) { reversed = original % 10 + reversed * 10; original = original / 10; } return reversed; } int gcd(int x, int y) { if (x < y) swap(x, y); while (y > 0) { int r = x % y; x = y; y = r; } return x; } int main() { vector<char>s(12); for (int i = 0;i < 12;i++) { cin >> s.at(i); } int cou = 0; for (int i = 0;i < 9;i++) { if (s.at(i) == 'Z' && s.at(i + 1) == 'O' && s.at(i + 2) == 'N' && s.at(i + 3) == 'e') { cou++; } } cout << cou; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define fop(i, n) for(int i=0; i<n; ++i) #define bgen(i) i.begin(),i.end() void chmin(int& a, int& b){if(a > b)a = b;} void chmax(int& a, int& b){if(a < b)a = b;} ll xcy(int i){ ll ic = 1; fop(j, 5) ic *= i-j; return ic/120; } int main() { int l; cin >> l; --l; bool odd = l%2; ll ans = 0; for(int i=6; i<=l-5; ++i){ int i1 = i-1; ll ans1 = xcy(i1); if(odd && i == (l+1)/2) ans1 *= ans1; else{ int i2 = l-i; ans1 *= xcy(i2); } ans += ans1; } cout << ans << endl; }
// C++ implementation to find nCr #include <bits/stdc++.h> using namespace std; // Function to find the nCr long long printNcR(long long n, long long r) { // p holds the value of n*(n-1)*(n-2)..., // k holds the value of r*(r-1)... long long p = 1, k = 1; // C(n, r) == C(n, n-r), // choosing the smaller value if (n - r < r) r = n - r; if (r != 0) { while (r) { p *= n; k *= r; // gcd of p, k long long m = __gcd(p, k); // dividing by gcd, to simplify // product division by their gcd // saves from the overflow p /= m; k /= m; n--; r--; } // k should be simplified to 1 // as C(n, r) is a natural number // (denominator should be 1 ) . } else p = 1; // if our approach is correct p = ans and k =1 return p; } // Driver code int main() { long long n; cin>>n; cout<<printNcR(n-1,11)<<endl; return 0; }
#include <algorithm> #include <iostream> #include <climits> #include <iomanip> #include <cstring> #include <string> #include <vector> #include <queue> #include <cmath> #include <set> #include <map> using namespace std; // ------------------------------------------------ template <typename T> istream &operator>> (istream &is, vector<T> &vec) { for (auto &v : vec) is >> v; return is; } template<typename T> void dout(string name, T arg) { cerr << arg << endl; } template<typename T1, typename... T2> void dout(string names, T1 arg, T2... args) { cerr << arg << " | "; dout(names.substr(names.find(',') + 2), args...); } #ifndef ONLINE_JUDGE #define debug(...) dout(#__VA_ARGS__, __VA_ARGS__) #else #define debug(...) #endif // -------------------------------------------------- #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define ll long long #define mod 1000000007 #define nod 1000000007 #define vi vector<int> #define vll vector<ll> #define pb push_back // D R U L int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; const int mx = 1e6 + 5; const int INF = mod; ll power(ll x, ll y){ ll res = 1; while(y > 0){ if(y & 1) res = (res * x) % nod; y >>= 1; x = (x * x) % nod; } return (res % nod); } // Check for number of Cases!! void solve() { ll n; cin >> n; ll cost; cin >> cost; vector<vll> arr(n, vll(n)); cin >> arr; vll ref; for(int i = 1; i < n; i++) { ref.pb(i); } ll ans = 0; do { ll curr = 0; for(int i = 0; i < ref.size(); i++) { if(i == 0) { curr += arr[0][ref[i]]; }else { curr += arr[ref[i-1]][ref[i]]; } } curr += arr[ref[ref.size() - 1]][0]; if(curr == cost) ans++; }while(next_permutation(all(ref))); cout << ans; } int main(){ #ifndef ONLINE_JUDGE freopen("/ATOMCODES/input.txt", "r", stdin); freopen("/ATOMCODES/output.txt", "w", stdout); freopen("/ATOMCODES/err_output.txt", "w", stderr); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; // cin >> t; while(t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; using ll = long long; using pll = pair<long long, long long>; constexpr char ln = '\n'; constexpr long long MOD = 1000000007; //constexpr long long MOD = 998244353; constexpr long long INF = 1000000000 + 100; constexpr long long LINF = 1000000000000000000 + 100; #define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) #define rep(i,n) for(int i=0;i<(n);i++) #define rept(i, j, n) for(int i=(j); i<(n); i++) template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } int main(){ int N, M; cin >> N >> M; vector<int> X(M), Y(M), Z(M); rep(i, M){ cin >> X[i] >> Y[i] >> Z[i]; } ll dp[1<<18]{}; dp[0] = 1; for(int bit=0; bit<(1<<N); bit++){ vector<int> S; //集合 for(int i=0; i<N; i++){ if((bit>>i)&1){ S.push_back(i+1); } } for(int i=0; i<N; i++){ if((bit>>i)&1)continue; //既に存在する S.push_back(i+1); bool fg = true; //条件判定 rep(j, M){ if(X[j]!=S.size())continue; //丁度になったら数えれば良い int cnt = 0; for(auto s:S){ if(s<=Y[j])cnt++; } if(cnt>Z[j]){ fg = false; } } if(fg)dp[bit+(1<<i)] += dp[bit]; //cout << "bit:" << bit << " dp:" << dp[bit+(1<<i)] << " <- " << dp[bit] << ln; S.pop_back(); } } cout << dp[(1<<N)-1] << ln; }
#include <bits/stdc++.h> using namespace std; int main() { unsigned long long tmp; scanf("%llu", &tmp); __int128 N = tmp; __int128 i = 5; char j = 1; for (; N >= i + 3; i *= 5, ++j) { __int128 t = N - i; char k = 0; while (t > 0 && t % 3 == 0) t /= 3, ++k; if (t == 1) { printf("%d %d\n", k, j); return 0; } } puts("-1"); return 0; }
#include<bits/stdc++.h> #define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i) #define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i) #define foreach(i, n) for(auto &i:(n)) #define all(x) (x).begin(), (x).end() #define bit(x) (1ll << (x)) #define lambda(RES_TYPE, ...) (function<RES_TYPE(__VA_ARGS__)>)[&](__VA_ARGS__) -> RES_TYPE #define method(FUNC_NAME, RES_TYPE, ...) function<RES_TYPE(__VA_ARGS__)> FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__) using namespace std; using ll = long long; using pii = pair<int,int>; using pll = pair<ll,ll>; //const ll MOD = (ll)1e9+7; const ll MOD = 998244353; const int INF = (ll)1e9+7; const ll INFLL = (ll)1e18; template<class t> using vvector = vector<vector<t>>; template<class t> using vvvector = vector<vector<vector<t>>>; template<class t> using priority_queuer = priority_queue<t, vector<t>, greater<t>>; template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;} template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;} #ifdef DEBUG #define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl; #else #define debug(x) (void)0 #endif namespace templates{ ll modpow(ll x, ll b){ ll res = 1; while(b){ if(b&1)res = res * x % MOD; x = x * x % MOD; b>>=1; } return res; } ll modinv(ll x){ return modpow(x, MOD-2); } bool was_output = false; template<class t> void output(t a){ if(was_output)cout << " "; cout << a; was_output = true; } void outendl(){ was_output = false; cout << endl; } ll in(){ ll res; scanf("%lld", &res); return res; } template<class t> istream& operator>>(istream&is, vector<t>&x){ for(auto &i:x)is >> i; return is; } template<class t, class u> istream& operator>>(istream&is, pair<t, u>&x){ is >> x.first >> x.second; return is; } template<class t> t in(){ t res; cin >> res; return res; } template<class t> void out(t x){ cout << x; } template<class t> vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){ sort(line.begin(),line.end(),comp); return line; } template<class t> vector<t> reversed(vector<t> line){ reverse(line.begin(),line.end()); return line; } } using namespace templates; int main(){ ll n = in(); double dx = 3; for(ll x=3,a=1;dx < 2e18 and x<=n;x*=3,++a,dx*=3){ double dy = 5; for(ll y=5,b=1;dx + dy <= 3e18 and y+x<=n;y*=5,++b,dy*=5){ if(x+y==n){ cout << a << " " << b << endl; return 0; } } } cout << -1 << endl; return 0; }
#include <bits/stdc++.h> #define ll long long #define ld long double #define V vector<long long> #define VV vector<vector<long long>> #define VVV vector<vector<vector<long long>>> #define P pair<ll,ll> #define rep(i,n) for(ll (i)=0;(i)<(n);++(i)) #define per(i,n) for(ll (i)=(n)-1;(i)>=0;--(i)) #ifdef LOCAL #define debug(x) cerr<<__LINE__<<": "<<#x<<"="<<x<<endl; #define debugALL(x) cerr<<__LINE__<<": "<<#x<<"=";for(auto i=(x).begin();i!=--(x).end();i++)cerr<<*i<<" ";cerr<<*--(x).end()<<endl; #else #define debug(x) true #define debugALL(x) true #endif using namespace std; int main(){ ll n,k; cin>>n>>k; VV dp(4,V(3*n+1,0)); V sum(3*n+2,0); dp[0][0]=1; rep(i,3){ for(ll j=0;j<=3*n;j++)sum[j+1]=sum[j]+dp[i][j]; rep(j,3*n+1)dp[i+1][j]=sum[j]-sum[max(j-n,0ll)]; } ll ans=1; for(ll s=3;s<=3*n;s++){ if(k<ans+dp[3][s]){ for(ll i=1;i<=n;i++){ if(k<ans+dp[2][s-i]){ for(ll j=1;j<=n;j++){ if(k<ans+dp[1][s-i-j]){ cout<<i<<" "<<j<<" "<<s-i-j<<endl; return 0; }else{ ans+=dp[1][s-i-j]; } } }else{ ans+=dp[2][s-i]; } } }else{ ans+=dp[3][s]; } } }
/** * author: tomo0608 * created: 27.02.2021 21:01:58 **/ #pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; typedef pair<int,int> pii; typedef pair<long long, long long> pll; #define all(x) x.begin(),x.end() #define rep2(i, m, n) for (int i = (m); i < (n); ++i) #define rep(i, n) rep2(i, 0, n) #define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i) #define drep(i, n) drep2(i, n, 0) #define unique(a) a.erase(unique(a.begin(),a.end()),a.end()) template<class T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T> >; template<class T, class U> inline bool chmax(T &a, const U &b) { if (a<b) { a=b; return 1; } return 0; } template<class T, class U> inline bool chmin(T &a, const U &b) { if (a>b) { a=b; return 1; } return 0; } template<class T1, class T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; } template<class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; } template<class T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; } template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; } template<typename T> ostream& operator << (ostream& os, set<T>& set_var) {os << "{"; for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {os << *itr;++itr;if(itr != set_var.end()) os << ", ";itr--;}os << "}";return os;} template <typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &map_var) {os << "{";for(auto itr = map_var.begin(); itr != map_var.end(); itr++) {os << *itr;itr++;if (itr != map_var.end()) os << ", ";itr--;}os << "}";return os;} template<class T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r) #define pb push_back #define eb emplace_back #define elif else if #define mp make_pair #define bit(n, k) ((n >> k) & 1) /*nのk bit目*/ template<typename T> T gcd(T x, T y){if(x%y == 0)return y;return gcd(y, x%y);} template<typename T> T gcd(vector<T> a){T res = a[0];for(auto &x: a)res = gcd(res, x);return res;} template <typename T>T mypow(T x, ll n){T ret = 1;while(n > 0){if(n & 1)(ret *= x);(x *= x);n >>= 1;}return ret;} #define endl '\n' int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}; int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1}; void solve(){ int a,b;cin >> a >> b; cout << 100 - (double)100*b/a << endl; } int main() { cin.tie(0); ios_base::sync_with_stdio(false); cout << setprecision(20); int codeforces = 1; //cin >> codeforces; while(codeforces--){ solve(); } return 0; }
/** Fucc :/ - doanphuc : / ** author: doanphuc. ** **/ #include <bits/stdc++.h> #define TASK "" #define inpf freopen(TASK".inp", "r", stdin) #define outf freopen(TASK".out", "w", stdout) #define FOR(i,x,y) for(int i = x; i <= y ; i ++) #define FORT(i,x,y) for(int i = x; i < y ; i ++) #define FORD(i,x,y) for(int i = x; i >= y ; i --) #define clean(x) memset(x, 0, sizeof(x)) #define F first #define S second #define maxn 1000005 #define pii pair<ll,ll> #define ll long long #define pb push_back #define yes cout << "YES" << endl #define no cout << "NO" << endl #define all(x) (x).begin(), (x).end() #define pia pair<pii, int> #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); using namespace std; const ll MOD = 1e9 + 7 ; ll n, c, e, tr[maxn] ; vector<int> a[maxn] ; void dfs(int u) { if(tr[u]) return ; tr[u] = 1 ; c ++ ; e += a[u].size() ; for(auto v: a[u]) dfs(v) ; } int main() { // inpf; outf; fast; cin >> n ; FOR(i, 1, n) { int u, v ; cin >> u >> v ; a[u].pb(v) ; a[v].pb(u) ; } ll ans = 0 ; FORT(i, 1, maxn) { if(tr[i]) continue ; c = e = 0 ; dfs(i); ans += min(c, e / 2) ; } cout << ans ; }
//AUTHOR: RAVAN_2070 //PUNE INSTITUTE OF COMPUTER TECHNOLOGY /* I ♥ CLARICE STARLING... EXPLAINATION BELOW-> */ #include<bits/stdc++.h> using namespace std; typedef unsigned long long int ull; typedef long long int ll; typedef long double ld; typedef vector<ll> vi; typedef vector<pair<ll,ll>> vii; typedef pair<ll,ll> pii; typedef map<ll,ll> mii; #define MOD7 1000000007 #define MOD9 1000000009 #define pi 3.1415926535 #define Test_cases ll TC;cin>>TC;while(TC--) #define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define pb push_back #define mp make_pair #define F first #define S second #define lb lower_bound #define ub upper_bound #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(), x.rend() #define sp(x) fixed<<setprecision(x) #define sz(x) (ll)(x.size()) #define fo(i,a,b) for(i=a;i<b;i++) #define foe(i,a,b) for(i=a;i<=b;i++) const ll INF = (ll)2e18 + 77; int n,m,k,ans; vector<int>a,b,c,d,dish; void recursion(int pos) { int i; if(pos==k) { int cnt=0; fo(i,0,m) { if(dish[a[i]]&&dish[b[i]])cnt++; } ans=max(ans,cnt); } else { i=pos; dish[c[i]]++;recursion(pos+1);dish[c[i]]--; dish[d[i]]++;recursion(pos+1);dish[d[i]]--; } } void solve() { int i;cin>>n>>m; dish=vector<int>(n,0); a=b=vector<int>(m); fo(i,0,m){cin>>a[i]>>b[i];a[i]--;b[i]--;} cin>>k; c=d=vector<int>(k); fo(i,0,k){cin>>c[i]>>d[i];c[i]--;d[i]--;} recursion(0); cout<<ans<<"\n"; } int main() { fastio //Test_cases solve(); return 0; }
/* dont stick to an approach */ #include <iostream> #include <iomanip> #include <cmath> #include <string> #include <algorithm> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <unordered_map> #include <vector> #include <numeric> #include <cstdlib> typedef long long ll; typedef unsigned long long int ull; typedef long double ldb; #define PB push_back #define For(i, n) for (ll i = 0; i < n; i++) #define PYES cout<<"YES\n" #define PNO cout<<"NO\n" #define PYes cout<<"Yes\n" #define PNo cout<<"No\n" #define Fas ios::sync_with_stdio(0), cin.tie(0), cout.tie(0) const int M=4; using namespace std; //--------------------------------------------functions--------------------------------------------------------// ll power(ll a,ll b){int result=1;while(b>0){if(b%2 == 1){result *= a;}a *= a;b /= 2;}return result;} ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;} ll countSetBits(ll x){ll Count=0;while(x>0){if(x&1) Count++;x=x>>1;}return Count;} bool isPerfectSquare(ll n){ll sr = sqrt(n);if (sr * sr == n)return true;else return false;} ll mod(ll x){return ((x%M + M)%M);} ll add(ll a, ll b){return mod(mod(a)+mod(b));} ll mul(ll a, ll b){return mod(mod(a)*mod(b));} ll powerM(ll a,ll b){ll res=1;while(b){if(b%2==1){res=mul(a,res);}a=mul(a,a);b/=2;}return res;} //------------------------------------sieve of erantothenes----------------------------------------------------// vector<bool> sieve_of_eratothenes(ll n){ vector<bool> a(n+1,1); a[0]=0; a[1]=0; for(ll i=2;i<=sqrt(n);i++){ if(a[i]==1){ for(ll j=2;i*j<=n;j++){ a[j*i]=0; } } } return a; } //----------------------------------------nCr mod ---------------------------------------------------------------// ll modInverse(ll n){ return powerM(n,M-2); } ll nCrM(ll n,ll r){ if(n<r) return 0; if(r==0) return 1; vector<ll> fact(n+1); fact[0]=1; for(ll i=1;i<=n;i++){ fact[i]=mul(fact[i-1],i); } return mul(mul(fact[n],modInverse(fact[r])),modInverse(fact[n-r])); } //-----------------------------------------------solve--------------------------------------------------------// void solve(){ ll a,b,c;cin>>a>>b>>c; a%=10; if(a==5||a==0||a==1||a==6){ cout<<a<<endl; }else if(a==4||a==9){ if (b%2==0){ if(a==4){ cout<<6<<endl; }else{ cout<<1<<endl; } }else{ if(a==4){ cout<<4<<endl; }else{ cout<<9<<endl; } } }else{ ll d=powerM(b,c); if(d==0){ if(a==2){ cout<<6<<endl; }else if(a==3){ cout<<1<<endl; }else if(a==7){ cout<<1<<endl; }else if(a==8){ cout<<6<<endl; } }else if(d==1){ if(a==2){ cout<<2<<endl; }else if(a==3){ cout<<3<<endl; }else if(a==7){ cout<<7<<endl; }else if(a==8){ cout<<8<<endl; } }else if(d==2){ if(a==2){ cout<<4<<endl; }else if(a==3){ cout<<9<<endl; }else if(a==7){ cout<<9<<endl; }else if(a==8){ cout<<4<<endl; } }else if(d==3){ if(a==2){ cout<<8<<endl; }else if(a==3){ cout<<7<<endl; }else if(a==7){ cout<<3<<endl; }else if(a==8){ cout<<2<<endl; } } } } int main(){ Fas; // ll t=0; // cin>>t; // while(t--) solve(); return 0; }
#include<bits/stdc++.h> using namespace std; const int N=1e6+10; char s[N]; int main() { int n,q; cin>>n; scanf("%s",s+1); cin>>q; int t,a,b,now=0; while(q--) { cin>>t>>a>>b; if(t==2) now++; else { if(now&1) { if(a<=n) a+=n; else a-=n; if(b<=n) b+=n; else b-=n; } swap(s[a],s[b]); } } if(now&1) { for(int i=n+1;i<=2*n;i++) cout<<s[i]; for(int i=1;i<=n;i++) cout<<s[i]; } else for(int i=1;i<=2*n;i++) cout<<s[i]; return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define ppb pop_back #define pf push_front #define ppf pop_front #define all(x) (x).begin(), (x).end() #define uniq(v) (v).erase(unique(all(v)), (v).end()) #define sz(x) (int)((x).size()) #define ff first #define ss second #define rep(i, a, b) for(int i = a; i <= b; i++) #define mem1(a) memset(a, -1, sizeof(a)) #define mem0(a) memset(a, 0, sizeof(a)) #define endl "\n" typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pii> vpii; const long long INF = 1e18; const int32_t M = 1e9 + 7; const int32_t MM = 998244353; int binpow(int a, int b) { int res = 1; while (b > 0) { if (b & 1) { res = a * res; } a = a * a; b >>= 1; } return res; } void fast_io() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } void solve() { string s; cin >> s; for (int i = 0; i < sz(s); i++) { if (s[i] == '.') break; cout << s[i]; } } signed main() { fast_io(); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout << setprecision(6) << fixed; string s; cin >> s; for(char x : s) { if(x == '.') break; cout << x; } cout << endl; return 0; }
#include <iostream> #include <iomanip> #include <vector> #include <set> #include <string> #include <queue> #include <algorithm> #include <map> #include <cmath> #include <numeric> #include <list> #include <stack> #include <cstdio> #include <cstdlib> #include <cstring> #include <tuple> #include <deque> #include <complex> #include <bitset> //#include <atcoder/all> using namespace std; //using namespace atcoder; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> pii; typedef vector<pii> vpii; typedef long long ll; typedef vector<ll> vll; typedef vector<vll> vvll; typedef pair<long long, long long> pll; typedef vector<pll> vpll; typedef long double ld; typedef vector<ld> vld; typedef vector<bool> vb; #define rep(i, n) for (ll i = 0; i < (n); i++) #define reps(i, n) for (ll i = 1; i <= (n); i++) #define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--) #define rreps(i, n) for (ll i = (n); i >= 1; i--) #define all(v) (v).begin(), (v).end() template <class T> void chmin(T& a, T b) { a = min(a, b);} template <class T> void chmax(T& a, T b) { a = max(a, b);} constexpr int INF = 1 << 30; constexpr ll INFL = 1LL << 60; constexpr ll MOD = 1000000007; constexpr ld EPS = 1e-12; ld PI = acos(-1.0); struct BIT { // 1-indexed int n; vector<long long> bit; BIT(int n) : n(n), bit(n + 1, 0) {} void add(int i, int w){ for(int x = i; x <= n; x += x & -x) bit[x] += w; } long long sum(int i){ // sum of [1, i] int ret = 0; for(int x = i; x > 0; x -= x &- x) ret += bit[x]; return ret; } long long sum(int l, int r){ // sum of [l, r] return sum(r) - sum(l - 1); } }; void solve() { ll h, w, m; cin >> h >> w >> m; vll x(m), y(m); rep(i, m) { cin >> x[i] >> y[i]; --x[i], --y[i]; } vector<set<ll>> sety(w), setx(h); rep(i, w) sety[i].insert(h); rep(i, h) setx[i].insert(w); rep(i, m) { sety[y[i]].insert(x[i]); setx[x[i]].insert(y[i]); } ll ans = 0; for(ll j = 0; j < *setx[0].begin(); ++j) { ans += *sety[j].begin(); // cout << ans << endl; } set<pll> setob; rep(i, m) setob.emplace(x[i], y[i]); for(ll j = *setx[0].begin()+1; j < w; ++j) { setob.emplace(0, j); } BIT bit(w+2); for(ll i = 0; i < *sety[0].begin(); ++i) { ll r = *setx[i].begin(); ll cntob = bit.sum(r); // cout << i << ' ' << cntob << ' ' << r << endl; ans += cntob; while(!setob.empty() && setob.begin()->first <= i) { ll j = setob.begin()->second; setob.erase(setob.begin()); ll now = bit.sum(j+1, j+1); if(now == 0) bit.add(j+1, 1); } } cout << ans << endl; return; } int main() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); cout << fixed << setprecision(15); solve(); }
#include<bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define fi first #define se second #define lb lower_bound #define ub upper_bound #define ep emplace #define epb emplace_back #define scll static_cast<long long> #define sz(x) static_cast<int>((x).size()) #define pfll(x) printf("%lld\n", x) #define ci(x) cin >> x #define ci2(x, y) cin >> x >> y #define ci3(x, y, z) cin >> x >> y >> z #define co(x) cout << x << endl #define co2(x, y) cout << x << " " << y << endl #define co3(x, y, z) cout << x << " " << y << " " << z << endl using namespace std; typedef long long ll; typedef pair<int, int> P; typedef priority_queue<int> PQ; typedef priority_queue<int, vector<int>, greater<int>> PQG; typedef priority_queue<P> PQP; typedef priority_queue<P, vector<P>, greater<P>> PQPG; const int MAX_N = 2e5, MOD = 1e9 + 7, INF = 1e9; int h, w, m; int mh[MAX_N], mw[MAX_N]; const int ST_SIZE = (1 << 20) - 1; vector<int> dat[ST_SIZE]; void init(int k, int l, int r) { if (r - l == 1) dat[k].push_back(mw[l]); else { int lch = k * 2 + 1, rch = k * 2 + 2; init(lch, l, (l + r) / 2); init(rch, (l + r) / 2, r); dat[k].resize(r - l); merge(dat[lch].begin(), dat[lch].end(), dat[rch].begin(), dat[rch].end(), dat[k].begin()); } } int query(int i, int j, int x, int k, int l, int r) { if (j <= l || r <= i) return 0; else if (i <= l && r <= j) { return upper_bound(dat[k].begin(), dat[k].end(), x) - dat[k].begin(); } else { int lc = query(i, j, x, k * 2 + 1, l, (l + r) / 2); int rc = query(i, j, x, k * 2 + 2, (l + r) / 2, r); return lc + rc; } } int main() { ci3(h, w, m); fill(mh, mh + w, h); fill(mw, mw + h, w); rep(i, m) { int x, y; ci2(x, y); mh[y - 1] = min(mh[y - 1], x - 1); mw[x - 1] = min(mw[x - 1], y - 1); } ll ans = 0; rep(i, mh[0]) ans += mw[i]; init(0, 0, mh[0]); for (int i = 1; i < mw[0]; i++) { ans += query(1, min(mh[i], mh[0]), i - 1, 0, 0, mh[0]); ans += max(mh[i] - mh[0], 0); } co(ans); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int q;q=1; while(q--) { int a,b,x,y;cin>>a>>b>>x>>y; if(a>=b) { if(a==b) cout<<x; else { if(2*x>=y) cout<<x+(a-b-1)*y; else cout<<(a-b)*2*x-x; } } else { if(2*x>=y) cout<<x+(b-a)*y; else cout<<(b-a)*2*x+x; } } }
#include <bits/stdc++.h> using namespace std; #define PI 3.14159265358979323846264338327950L int A = 0, B = 1; int a, b, x, y; vector<vector<int >> dp; queue<pair<int, int>> que; int solver(int ab, int floor) { if (dp[ab][floor] > 0) { return dp[ab][floor]; } if (floor < a) { return 0; } int ret; if (ab == A) { ret = min(solver(A, floor - 1) + y, min(solver(B, floor) + x, solver(B, floor) + x)); } else { ret = min(solver(A, floor) + x, solver(B, floor) + y); } return dp[ab][floor] = ret; } int main(void) { int start = A, end = B; cin >> a >> b >> x >> y; int tmp = a; a = a - tmp; b = b - tmp; if (a > b) { int tmp = a - b; a = 1; b = tmp + 1; start = B; end = A; } vector<int> tmpvec1(b + 3, INT_MAX); vector<vector<int>> tmpDp(2, tmpvec1); dp = tmpDp; dp[start][a] = 0; dp[end][a] = x; pair<int, int> tmpP = make_pair(A, a); que.push(tmpP); for(int i=a;i<=b;i++){ int floor=i; dp[A][floor + 1] = min(dp[A][floor + 1], dp[A][floor] + y); dp[B][floor] = min(dp[B][floor], dp[A][floor] + x); dp[B][floor + 1] = min(dp[B][floor + 1], dp[B][floor] + y); dp[A][floor + 1] = min(dp[A][floor + 1], dp[B][floor] + x); } cout << dp[end][b] << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long #define ll long long #define cs const #define fr first #define se second #define ls (now<<1) #define rs (now<<1|1) #define mid ((l+r)>>1) #define mp make_pair #define pb push_back #define ppb pop_back #define low(i) (i&(-i)) #define par pair<int,int> #define cn(x) memset(x, 0, sizeof(x)) #define rep(i, x, y) for(int i=x; i<=y; ++i) #define sep(i, x, y) for(int i=x; i>=y; --i) #define fore(i, x) for(int i=fir[x]; i; i=nex[i]) cs int G = 3; cs int ff = 1e6 + 15; cs int inf = 1e18 + 1; cs int base = 4; cs int M = 998244353; void Add(int &x, int y) { x = (x + y) % M; if(x < 0) x += M; } int ksm(int x, int y) { return (y % 2 == 1 ? x : 1) * (y ? ksm(x * x % M, y >> 1) : 1) % M; } int fa[ff][2]; int find(int x, int typ) { return fa[x][typ] == x ? x : fa[x][typ] = find(fa[x][typ], typ); } int qz[ff], a[53][53], n, kq, sz[ff][2]; void init() { qz[0] = 1; rep(i, 1, 55) qz[i] = qz[i - 1] * i % M; cin >> n >> kq; rep(i, 1, n) fa[i][0] = fa[i][1] = i, sz[i][0] = sz[i][1] = 1; rep(i, 1, n) rep(j, 1, n) cin >> a[i][j]; rep(i, 1, n) rep(j, i + 1, n) { int tag1 = 0, tag2 = 0; rep(k, 1, n) tag1 |= (a[i][k] + a[j][k] > kq), tag2 |= (a[k][i] + a[k][j] > kq); // cout << i << " " << j << " " << tag1 << " " << tag2 << "\n"; if(!tag1 && find(i, 0) != find(j, 0)) sz[find(j, 0)][0] += sz[find(i, 0)][0], fa[find(i, 0)][0] = find(j, 0); if(!tag2 && find(i, 1) != find(j, 1)) sz[find(j, 1)][1] += sz[find(i, 1)][1], fa[find(i, 1)][1] = find(j, 1); } int s1 = 1, s2 = 1; rep(i, 1, n) s1 = s1 * qz[sz[find(i, 0)][0]] % M, sz[find(i, 0)][0] = 1, s2 = s2 * qz[sz[find(i, 1)][1]] % M, sz[find(i, 1)][1] = 1; cout << s1 * s2 % M; } signed main() { // freopen("triad.in", "r", stdin); // freopen("triad.out", "w", stdout); int Ts = 1; while(Ts--) init(); } /* */
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int pri[maxn], t; bool vis[maxn]; int yue[maxn]; int last[maxn]; void pre() { memset(vis, 0, sizeof(vis)); t = 0; yue[1] = 1; last[1] = 0; for (int i = 2; i < maxn; i++) { if (!vis[i]) { pri[t++] = i; yue[i] = 2; } for (int j = 0; j < t && i * pri[j] < maxn; j++) { vis[i * pri[j]] = true; if (pri[j] % i == 0) { yue[i * pri[j]] = yue[i] + 1; break; } else { // last[i * pri[j]] = 1; yue[i * pri[j]] = yue[i] + 1; } } } } int main() { #ifdef LOAD freopen("../1.txt", "r", stdin); // cout<<"haha"<<endl; #endif int n; scanf("%d", &n); pre(); for (int i = 1; i <= n; i++) { printf("%d%c", yue[i], i == n ? '\n' : ' '); } return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; cout<<(1<<n)-1<<endl; for(int i=1;i<1<<n;i++){ for(int j=0;j<1<<n;j++){ if(__builtin_popcount(j&i)&1) cout<<'B'; else cout<<'A'; } cout<<endl; } }
#include <bits/stdc++.h> using namespace std; using lint = long long int; using P = pair<int, int>; using PL = pair<lint, lint>; #define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++) #define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--) #define REP(i, n) FOR(i,0,n) #define IREP(i, n) IFOR(i,0,n) #define ALL(a) (a).begin(),(a).end() constexpr int MOD = 1000000007; constexpr lint B1 = 1532834020; constexpr lint M1 = 2147482409; constexpr lint B2 = 1388622299; constexpr lint M2 = 2147478017; constexpr int INF = 2147483647; void yes(bool expr) {cout << (expr ? "Yes" : "No") << "\n";} template<class T>void chmax(T &a, const T &b) { if (a<b) a=b; } template<class T>void chmin(T &a, const T &b) { if (b<a) a=b; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int N; cin >> N; vector<string> now; now.push_back("AB"); N--; int len = 2; while(N--) { vector<string> next; string tmp = ""; REP(i, len) tmp += 'A'; REP(i, len) tmp += 'B'; next.push_back(tmp); REP(i, now.size() * 2) { string tmp = ""; tmp += now[i/2]; string tmp2 = now[i/2]; if(i%2 == 1) { REP(j, tmp2.size()) { if(tmp2[j] == 'A') tmp2[j] = 'B'; else tmp2[j] = 'A'; } } tmp += tmp2; next.push_back(tmp); } now = next; len *= 2; } cout << now.size() << "\n"; REP(i, now.size()) cout << now[i] << "\n"; }
#include <bits/stdc++.h> using namespace std; #define int int64_t #define rep(i, a, b) for(int i = a; i < b; ++i) int debug = 1; const int N = 5100, mod = 998244353; int n, m, a[N], dp[20][N], C[N][N]; void calc_c() { rep(i, 0, n + 1) { rep(j, 0, i + 1) { if (j == 0) C[i][j] = 1; else { C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod; } } } } int getC(int n, int k) { return (k > n || k < 0) ? 0 : C[n][k]; } main() { cin >> n >> m; calc_c(); rep(j, 0, m + 1) { if (j % 2 == 0) { dp[0][j] = getC(n, j); } } rep(b, 1, 13) { rep(j, 0, m + 1) { if (j == 0) { dp[b][0] = dp[b - 1][0]; continue; } for (int c = 0; c * (1 << b) <= j; c += 2) { dp[b][j] += getC(n, c) * dp[b - 1][j - c * (1 << b)] % mod; dp[b][j] %= mod; } } } cout << dp[12][m] % mod << '\n'; }
#pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma") #pragma GCC optimize("unroll-loops") #include<bits/stdc++.h> #define N 20005 using namespace std; const int inf=0x3f3f3f3f,mod=998244353; inline int read() { int s=0,f=0; char ch=getchar(); while(ch<48||ch>57)f=(ch=='-'),ch=getchar(); while(ch>47&&ch<58)s=(s<<1)+(s<<3)+(ch^48),ch=getchar(); return f?-s:s; } int n,m,ans,mx,fac[N],inv[N],f[20][N]; int Ksm(int a,int n,int ans=1) { for(; n; n>>=1,a=1ll*a*a%mod)if(n&1)ans=1ll*ans*a%mod; return ans; } int C(int n,int m) { if(n<m)return 0; return 1ll*fac[n]*inv[m]%mod*inv[n-m]%mod; } int Mod(int x) { return x<mod?x:x-mod; } void Add(int &x,int y) { x=Mod(x+y); } signed main() { n=read(),m=read(),fac[0]=1; if(m&1)return puts("0"),0; for(int i=1; i<=n; ++i)fac[i]=1ll*fac[i-1]*i%mod; inv[n]=Ksm(fac[n],mod-2); for(int i=n-1; ~i; --i)inv[i]=inv[i+1]*(i+1ll)%mod; for(int k=0; k<=n; k+=2)f[0][k>>1]=C(n,k); for(int i=0; (1<<i)<m; ++i) { if(mx=i+1,(m>>i+1)&1) { for(int j=1; j<=10000; j+=2) if(f[i][j])for(int k=0; k<=n; k+=2)Add(f[i+1][k+j>>1],1ll*f[i][j]*C(n,k)%mod); } else { for(int j=0; j<=10000; j+=2) if(f[i][j])for(int k=0; k<=n; k+=2)Add(f[i+1][k+j>>1],1ll*f[i][j]*C(n,k)%mod); } } cout<<f[mx][0]; return 0; }
#include <bits/stdc++.h> #define ri register int #define fi first #define se second #define pb push_back #define ppp pop_back #define rez resize using namespace std; typedef unsigned int uit; typedef long long ll; typedef vector <int> poly; typedef pair <ll, int> pli; typedef pair <int, ll> pil; typedef pair <ll, ll> pll; typedef pair <int, int> pii; const int rlen = 1 << 20 | 5; char buf[rlen], *ib = buf, *ob = buf; #define gc() (((ib == ob) && (ob = (ib = buf) + fread(buf, 1, rlen, stdin))), ib == ob ? -1 : *ib++) inline int read() { static int ans, f; static char ch; for (ans = 0, f = 1, ch = gc(); !isdigit(ch); f ^= ch == '-', ch = gc()); for (; isdigit(ch); ans = ((ans << 2) + ans << 1) + (ch ^ 48), ch = gc()); return f ? ans : -ans; } inline ll readl() { static ll ans; static int f; static char ch; for (ch = gc(), ans = 0, f = 1; !isdigit(ch); f ^= ch == '-', ch = gc()); for (; isdigit(ch); ans = ((ans << 2) + ans << 1) + (ch ^ 48), ch = gc()); return f ? ans : -ans; } inline int Read(char *s) { static int len; static char ch; for (ch = gc(), len = 0; !isalpha(ch); ch = gc()); for (; isdigit(ch); s[++len] = ch, ch = gc()); return len; } template <typename T> inline void ckmax(T &a, T b) { a = a > b ? a : b; } template <typename T> inline void ckmin(T &a, T b) { a = a < b ? a : b; } namespace modular { const int mod = 1e9 + 7; inline int add(int a, int b) { return a < mod - b ? a + b : a - mod + b; } inline int dec(int a, int b) { return a < b ? a - b + mod : a - b; } inline int mul(int a, int b) { return (ll) a * b % mod; } inline void Add(int &a, int b) { a = a < mod - b ? a + b : a - mod + b; } inline void Dec(int &a, int b) { a = a < b ? a - b + mod : a; } inline void Mul(int &a, int b) { a = (ll) a * b % mod; } inline int ksm(int a, int p) { static int ret; for (ret = 1; p; p >>= 1, Mul(a, a)) { (p & 1) && (Mul(ret, a), 1); } return ret; } } using namespace modular; const int N = 1e5 + 5; ll n; inline ll calc(ll t) { ll x = t, y = n - t, sz = 0; x = t, y = n - t; ++sz; while (x >= 3 && y >= 3) { if (x > y) { ++sz; x -= y; } else if (x < y) { ++sz; y -= x; } if (x == y) { break; } } return sz + x + y; } int main() { #ifdef ldxcaicai freopen("lx.in", "r", stdin); #endif double tt = (sqrt(5.0) - 1) / 2; n = readl(); ll t, x, y; t = (ll) (tt * (double) n); for (ll i = max(0ll, t - 5000); i <= min(n, t + 5000); ++i) { if (calc(i) <= 130) { x = i, y = n - i; poly res; res.pb(3); while (x >= 3 && y >= 3) { if (x > y) { res.pb(3); x -= y; } else if (x < y) { res.pb(4); y -= x; } if (x == y) { break; } } while (x) { --x; res.pb(1); } while (y) { --y; res.pb(2); } cout << res.size() << '\n'; while (res.size()) { cout << res.back() << '\n'; res.ppp(); } return 0; } } return 0; }
#include <bits/stdc++.h> using namespace std; #define repd(i,a,b) for (int i=(a);i<(b);i++) #define rep(i,n) repd(i,0,n) #define all(x) (x).begin(),(x).end() 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; } typedef long long ll; typedef pair<ll,ll> P; typedef vector<int> vec; using Graph = vector<vector<int>>; const long long INF = 1LL<<60; const long long MOD = 1000000007; const int inf=1e9+7; struct edge { ll to, cost, time; }; //辺 int V; //頂点数 const int MAX_V = 1000000; vector<vector<edge>> G(MAX_V); ll d[MAX_V]; void dijkstra(int s) { //greater<P>でfirstが小さい順に取り出せる //first:最短距離,second:頂点番号 priority_queue<P, vector<P>, greater<P>> que; fill(d, d + V, INF); d[s] = 0; que.push(P(0, s)); while (!que.empty()) { P p = que.top(); que.pop(); int v = p.second; if (d[v] < p.first)continue; rep(i, G[v].size()) { edge e = G[v][i]; ll sta=d[v]; if(d[v]%e.time!=0){ sta+=(e.time-d[v]%e.time); } if (d[e.to] > sta + e.cost) { d[e.to] = sta + e.cost; que.push(P(d[e.to], e.to)); } } } } int main() { ios::sync_with_stdio(false); cin.tie(0); int m,x,y;cin>>V>>m>>x>>y; x--,y--; rep(i,m){ ll a,b,t,k; cin>>a>>b>>t>>k; a--;b--; G[a].push_back({b,t,k}); G[b].push_back({a,t,k}); } dijkstra(x); if(d[y]>=INF)cout<<-1<<endl; else cout<<d[y]<<endl; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(ll i=0;i<n;i++) using namespace std; using ll=long long; using P = pair<int,int>; int main(){ string s; cin >> s; ll c[10]={0}; ll answer=0; ll one = (ll)s[0]-48; ll two =(ll)s[1]-48; ll three =(ll)s[2]-48; if(s.size()==1){ if(one%8==0)answer=1; }else if(s.size()==2){ if((one*10+two)%8==0)answer++; else if((two*10+one)%8==0)answer++; } else if(s.size()==3){ if((one*100+two*10+three)%8==0)answer++; else if((one*100+three*10+two)%8==0)answer++; else if((two*100+one*10+three)%8==0)answer++; else if((two*100+three*10+one)%8==0)answer++; else if((three*100+one*10+two)%8==0)answer++; else if((three*100+two*10+one)%8==0)answer++; } else{ for(ll i=0;i<(ll)s.size();i++){ if(c[(ll)s[i]-48]!=3){ c[(ll)s[i]-48]++; } } ll count=0; for(ll i=1;i<10;i++){ count+=c[i]; } ll an[count]; ll now=0; for(ll i=1;i<10;i++){ for(ll j=0;j<c[i];j++){ an[now]=i; now++; } } for(ll a=0;a<count;a++){ for(ll b=0;b<count;b++){ for(ll c=0;c<count;c++){ if(a==b||b==c||c==a)break; if((an[a]*100+an[b]*10+an[c])%8==0)answer++; } } } } if(answer==0)cout << "No" << endl; else cout << "Yes" << endl; }
#include<bits/stdc++.h> using namespace std; #define ll long long int #define pb push_back // g++ -std=c++17 -Wshadow -Wall -g -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -o int main(){ string s; cin>>s; map<int,int>d; int n=s.length(); for(int i=0;i<n;i++){ d[s[i]-'0']++; } if(n==1)cout<<(s=="8"?"Yes\n":"No\n"); else if(n==2){ string r=s; reverse(r.begin(),r.end()); for(int i=16;i<100;i+=8){ if(stoi(s)==i || stoi(r)==i){ cout<<"Yes\n"; return 0; } } cout<<"No\n"; return 0; } if(n>=3){ int flag=1; for(int i=104;i<1000;i+=8){ map<int,int>num; int N=i; while(N){ num[N%10]++; N/=10; } for(auto x:num){ if(d[x.first]<x.second){ flag=0; break; } } if(flag){ cout<<"Yes\n"; return 0; } flag=1; } cout<<"No\n"; } return 0; }
#include <bits/stdc++.h> //#include <atcoder/all> using namespace std; #define rep(i,x,y) for(ll i=(x);i<(y);i++) #define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--) #define all(x) (x).begin(),(x).end() #define itrout(x) for(int i=0;i<x.size();i++) {cout << x[i] << (i==x.size()-1 ? "\n" : " ");} #ifdef LOCAL #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl #define debugbit(x, n) cerr << #x << " = " << bitset<n>(x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl #define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl #define dassert(...) assert(__VA_ARGS__) #else #define debug(x) #define debugbit(x, n) #define itrdebug(x) #define dassert(...) #endif //#define int long long //using mint = atcoder::modint; typedef long long ll; const ll MOD = 1e9 + 7; const long double EPS = 1e-8; void solve(long long N, long long M, std::vector<long long> a, std::vector<long long> b, std::vector<long long> c){ struct Edge { int index, to; }; vector<vector<Edge>> edges(N+1); rep(i,0,M) { edges[a[i]].push_back(Edge{(int)i, (int)b[i]}); edges[b[i]].push_back(Edge{(int)i, (int)a[i]}); } vector<string> answer(M); vector<int> visited(N+1, false); auto dfs = [&](auto&& self, int current) -> void { visited[current] = true; for (const auto& [edgeIndex, next] : edges[current]) { if (c[current] != c[next]) continue; if (next == b[edgeIndex]) { answer[edgeIndex] = "->"; } else { answer[edgeIndex] = "<-"; } if (visited[next]) continue; self(self, next); } }; rep(i,1,N+1) { if (visited[i]) continue; dfs(dfs, i); } rep(i,0,M) { if (c[a[i]] > c[b[i]]) cout << "->" << endl; else if (c[a[i]] < c[b[i]]) cout << "<-" << endl; else { cout << answer[i] << endl; } } } signed main(){ // ios_base::sync_with_stdio(false); // cin.tie(NULL); long long N; scanf("%lld",&N); long long M; scanf("%lld",&M); std::vector<long long> a(M); std::vector<long long> b(M); for(int i = 0 ; i < M ; i++){ scanf("%lld",&a[i]); scanf("%lld",&b[i]); } std::vector<long long> c(N+1); for(int i = 0 ; i < N ; i++){ scanf("%lld",&c[i+1]); } solve(N, M, std::move(a), std::move(b), std::move(c)); return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long using vec_int = vector<int>; using P = pair<int,int>; using T = tuple<int,int,int>; using ll = long long; #define rep(i, n) for(int i = 0; i < (int)(n); i++) int charToInt(char c){ char zero_num = '0'; return (int)c - (int)zero_num; } signed main(){ int N; cin>>N; int M; cin>>M; vec_int a(M); vec_int b(M); rep(i,M)cin>>a.at(i)>>b.at(i); vec_int c(N); rep(i,N)cin>>c.at(i); vector<vec_int> G(N+1); rep(i,M){ G.at(a.at(i)).push_back(b.at(i)); G.at(b.at(i)).push_back(a.at(i)); } map<P, int> path_map; rep(i, M){ path_map[make_pair(a.at(i), b.at(i))] = i; path_map[make_pair(b.at(i), a.at(i))] = i; } vector<string> ans(M,""); rep(i,M){ if(c.at(a.at(i)-1)>c.at(b.at(i)-1)){ ans.at(i) = "->"; }else if(c.at(a.at(i)-1)<c.at(b.at(i)-1)){ ans.at(i) = "<-"; } } rep(i,M){ if(ans.at(i)==""){ vec_int visited(N+1, 0); visited.at(a.at(i)) =1; stack<P> st; st.push(make_pair(b.at(i), a.at(i))); // node, parent int node_val = c.at(a.at(i)-1); while(!st.empty()){ int node = st.top().first; int parent = st.top().second; st.pop(); int ind = path_map[make_pair(parent, node)]; if(ans.at(ind)!="")continue; if(a.at(ind)==parent && b.at(ind)==node){ ans.at(ind) = "->"; }else{ ans.at(ind) = "<-"; } for(auto next_node: G.at(node)){ if(next_node==parent)continue; if(c.at(next_node-1)!=node_val)continue; st.push(make_pair(next_node, node)); } } } } rep(i,M){ cout<<ans.at(i)<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { // your code goes here int a,b,c,d,m,n; cin>>a>>b>>c>>d; m=max(a,b); n=min(c,d); cout<<m-n<<"\n"; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long int ll; vector<ll> v; int main(){ ios::sync_with_stdio(0); cin.tie(0); ll n,m,i,j,k,a,b,c,t,q,sum = 0,cnt = 0,maxn = 0,ans = 0; cin>>n>>a>>b>>c; a*=n; b*=n; if(a<=c&&c<=b)cout<<"No"; else cout<<"Yes"; }
#include<bits/stdc++.h> typedef long long int ll; typedef unsigned long long int ull; #define BIG_NUM 2000000000 #define HUGE_NUM 4000000000000000000 //オーバーフローに注意 #define MOD 1000000007 #define EPS 0.000000001 using namespace std; #define SIZE 200005 typedef vector<ll> V; typedef vector<V> MATRIX; struct Info{ ll x,y; }; int num_P; int N = 3; Info info[SIZE]; ll table[SIZE][3][3]; MATRIX calc(MATRIX left,MATRIX right){ MATRIX ret(N,V(N)); for(int i = 0; i < N; i++){ for(int k = 0; k < N; k++)ret[i][k] = 0; } for(int row = 0; row < N; row++){ for(int col = 0; col < N; col++){ for(int a = 0; a < N; a++){ ret[row][col] += left[row][a]*right[a][col]; } } } return ret; } //MULTのT乗を計算する MATRIX pow(MATRIX MULT,int count){ MATRIX ret(N,V(N)); for(int row = 0; row < N; row++){ for(int col = 0; col < N; col++){ if(row == col)ret[row][col] = 1; else{ ret[row][col] = 0; } } } while(count > 0){ if(count%2 == 1)ret = calc(ret,MULT); MULT = calc(MULT,MULT); count /= 2; } return ret; } int main(){ scanf("%d",&num_P); for(int i = 1; i <= num_P; i++){ scanf("%lld %lld",&info[i].x,&info[i].y); } MATRIX MULT(N,V(N)); for(int i = 0; i <= 2; i++){ MULT[i][i] = 1; } MATRIX A1(N,V(N)); A1[0][1] = 1,A1[1][0] = -1,A1[2][2] = 1; MATRIX A2(N,V(N)); A2[0][1] = -1,A2[1][0] = 1,A2[2][2] = 1; MATRIX AX(N,V(N)); AX[0][0] = -1,AX[1][1] = 1,AX[2][2] = 1; MATRIX AY(N,V(N)); AY[0][0] = 1,AY[1][1] = -1,AY[2][2] = 1; MATRIX work(N,V(N)); for(int row = 0; row < 3; row++){ for(int col = 0; col < 3; col++){ table[0][row][col] = MULT[row][col]; } } int M; scanf("%d",&M); int command; ll p; for(int i = 1; i <= M; i++){ scanf("%d",&command); if(command == 1){ MULT = calc(A1,MULT); }else if(command == 2){ MULT = calc(A2,MULT); }else{ scanf("%lld",&p); if(command == 3){ for(int row = 0; row < 3; row++){ for(int col = 0; col < 3; col++){ work[row][col] = AX[row][col]; } } work[0][2] = 2*p; MULT = calc(work,MULT); }else{ for(int row = 0; row < 3; row++){ for(int col = 0; col < 3; col++){ work[row][col] = AY[row][col]; } } work[1][2] = 2*p; MULT = calc(work,MULT); } } for(int row = 0; row < 3; row++){ for(int col = 0; col < 3; col++){ table[i][row][col] = MULT[row][col]; } } } int Q; scanf("%d",&Q); int count,index; for(int loop = 0; loop < Q; loop++){ scanf("%d %d",&count,&index); ll x = info[index].x; ll y = info[index].y; ll ans_x = table[count][0][0]*x + table[count][0][1]*y + table[count][0][2]; ll ans_y = table[count][1][0]*x + table[count][1][1]*y + table[count][1][2]; printf("%lld %lld\n",ans_x,ans_y); } return 0; }
#include<bits/stdc++.h> using namespace std; using ll=int64_t; using pll=pair<ll,ll>; struct OP{ pll o={0,0},ex={1,0},ey={0,1}; }; pll operator+(pll a,pll b){return{a.first+b.first,a.second+b.second};} pll operator-(pll a,pll b){return{a.first-b.first,a.second-b.second};} pll operator*(pll a,ll b){return {a.first*b,a.second*b};} OP operator*(const OP& a,const OP& b){ OP ans; ans.o=b.o+b.ex*a.o.first+b.ey*a.o.second; ans.ex=b.ex*a.ex.first+b.ey*a.ex.second; ans.ey=b.ex*a.ey.first+b.ey*a.ey.second; return ans; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); ll N; cin>>N; vector<pair<ll,ll>> point(N); for(auto& [X, Y] : point)cin>>X>>Y; ll M; cin>>M; vector<OP> op(M); for(OP& a:op){ ll type; cin>>type; if(type==1){ a.ex={0,-1}; a.ey={1,0}; } else if(type==2){ a.ex={0,1}; a.ey={-1,0}; }else if(type==3){ ll p; cin>>p; a.o={p*2,0}; a.ex={-1,0}; }else { ll p; cin>>p; a.o={0,p*2}; a.ey={0,-1}; } } op.insert(op.begin(),OP{}); for(ll i=0;i<M;i++)op[i+1]=op[i]*op[i+1]; ll Q; cin>>Q; for(ll i=0;i<Q;i++){ ll A,B; cin>>A>>B; const auto [X, Y] =point[B-1]; pll ans=op[A].o+op[A].ex*X+op[A].ey*Y; cout<<ans.first<<' '<<ans.second<<'\n'; } }
#include<bits/stdc++.h> using namespace std; using ll=long long; int main() { ll n,w; cin>>n>>w; cout<<n/w<<endl; } /* 8888888888888888888888888888 Md. Masud Mazumder University of Chittagong Department of CSE 8888888888888888888888888888 */
#pragma GCC optimize ("O3") #pragma GCC target ("sse4") #include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cmath> #include <vector> #include <list> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <queue> #include <ctime> #include <cassert> #include <complex> #include <stack> #include <string> #include <cstring> #include <chrono> #include <random> #include <bitset> #include <sstream> #include <iomanip> using namespace std; #define int int64_t #define vi vector<int> #define vb vector<bool> #define vbb vector< vector<bool> > #define all(x) (x).begin(), (x).end() #define vii vector< vector<int> > #define rip(dp, n, m) vector< vector<int> > dp(n, vector<int>(m,0)) #define ff first #define ss second #define pii pair<int64_t, int64_t> #define miv map<int, vector<int> > #define mp make_pair #define pb push_back #define prr(x) cout << (#x) <<' ' << (x) << endl #define pr(x) cout << (x) << endl #define f(i,n) for(i=0;i<n;i++) #define pqb priority_queue<int> #define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++) #define autoitr(x,it) for(auto it = x.rbegin(); it != x.rend(); it++) #define rep(n) for(ll i = 0; i < n; i++) #define pqs priority_queue<int,vi,greater<int> > #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define inf 1e18 #define ps(x,y) fixed<<setprecision(y)<<x #define mk(arr,n,type) type *arr=new type[n]; #define w(x) int x; cin>>x; while(x--) #define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int dr8[] = {1,1,0,-1,-1,-1, 0, 1}; int dc8[] = {0,1,1, 1, 0,-1,-1,-1}; int dr4[] = {1,0,0,-1}; int dc4[] = {0,1,-1,0}; int gcd(int a, int b) { if(a%b==0) return b; return gcd(b, a%b); } void inp(int &x) { bool neg=false; register int c; x =0; c=getchar(); if(c=='-') { neg = true; c=getchar(); } for(;(c>47 && c<58);c=getchar()) x = (x<<1) + (x<<3) +c -48; if(neg) x *=-1; } void solve(); int32_t main() { FIO; int t=1; //cin >> t; for(int i=1;i<=t;i++) { solve(); } } void solve() { int i, n, j, m, k, l, t; cin >> n >> m; cout << n/m; }
#include <iostream> #include <string> #include<math.h> #include<vector> #include<algorithm> using ll = long long; using namespace std; int main(void) { ll n, k; cin >> n >> k; ll ans=0; ll before=0; vector<vector<ll>> a(n,vector<ll>(2)); for (int i = 0; i < n; i++) cin >> a[i][0]>>a[i][1]; sort(a.begin(), a.end()); for (int i = 0; i < n; i++) { if (k < (a[i][0]-before)) { ans += k; k = 0; break; } else { k += (a[i][1] + before - a[i][0]); ans =a[i][0]; } before = a[i][0]; } if (k != 0)ans += k; cout << ans << endl; return 0; }
#include<iostream> #include<cstring> #include<algorithm> #define int long long using namespace std; int a[101]; int g1(int x) { if(x==0)return 0; int cnt=0; while(x) { a[++cnt]=x%10; x/=10; } sort(a+1,a+1+cnt); int ans=0; for(int i=cnt;i>=1;i--) { ans*=10; ans+=a[i]; } return ans; } int g2(int x) { if(x==0)return 0; int cnt=0; while(x) { a[++cnt]=x%10; x/=10; } sort(a+1,a+1+cnt); int ans=0; for(int i=1;i<=cnt;i++) { ans*=10; ans+=a[i]; } return ans; } signed main() { int N,K;cin>>N>>K; for(int i=1;i<=K;i++) { int tmp=g1(N)-g2(N); N=tmp; } cout<<N; return 0; }
#include <bits/stdc++.h> using namespace std; //const long nPrime = 1000000007; //const long nPrime = 998244353; int main() { int n,m; cin >> n >> m; vector<vector<pair<int,int>>> vviiNum(n); for(int i = 0; i < m; i++){ int x,y,z; cin >> x >> y >> z; x--, y--; vviiNum[x].push_back(make_pair(y,z)); } vector<long> viDP((1<<n),0); viDP[0] = 1; for(int i = 1; i < (1<<n); i++){ long nCount = 0; vector<long> viCount(n,0); for(int j = 0; j < n; j++){ if((i|(1<<j)) != i){ continue; } nCount++; for(int k = j; k < n; k++){ viCount[k]++; } } bool b = true; for(int j = 0; j < vviiNum[nCount-1].size(); j++){ int y = vviiNum[nCount-1][j].first; int z = vviiNum[nCount-1][j].second; if(viCount[y] > z){ b = false; break; } } if(!b){ continue; } for(int j = 0; j < n; j++){ if((i|(1<<j)) != i){ continue; } viDP[i] += viDP[i^(1<<j)]; } } cout << viDP[(1<<n)-1] << endl; return 0; }
#include<bits/stdc++.h> #define f(i,n) for(long long int i = 0 ; i < n; i++) #define F first #define S second #define vll vector<ll> #define vvll vector<vector<ll>> #define all(s) s.begin(), s.end() #define u_s unordered_set #define u_m unordered_map #define ll long long int #define pb push_back #define pll pair<ll,ll> #define parr(arr) for(auto x: arr)cout<<x<<" ";cout<<endl #define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0) #define testcase ll tt; cin>>tt; while(tt--) using namespace std; vector<vector<pll>> cond; ll n, m; ll dp[18][524300], dp1[18][524300]; bool check(ll idx, ll taken){ if(cond[idx].size() == 0) return 1; if(dp1[idx][taken] != -1) return dp1[idx][taken]; ll pre[n+1] = {}; for(ll i = 1; i <= n; i++){ pre[i] = ((taken & (1<<i)) != 0); pre[i] += pre[i-1]; } for(auto &x: cond[idx]){ if(pre[x.F] > x.S) return dp1[idx][taken] = 0; } return dp1[idx][taken] = 1; } ll helper(ll idx, ll taken){ if(idx == n) return 1LL; if(dp[idx][taken] != -1) return dp[idx][taken]; ll ans = 0; for(ll i = 1; i <= n; i++){ if(taken & (1LL<<i)) continue; taken ^= (1LL<<i); if(check(idx, taken)) ans += helper(idx+1, taken); taken ^= (1LL<<i); } return dp[idx][taken] = ans; } void solve(){ cin>>n>>m; cond.resize(n); while(m--){ ll x , y , z; cin>>x>>y>>z; x--; cond[x].pb({y,z}); } memset(dp,-1,sizeof dp); memset(dp1,-1,sizeof dp1); cout<<helper(0, 0); } int main() { fast; solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long const int nax=1e5+100; struct node { int n,ok; vector<int> par; node(int n):n(n),par(n,-1),ok(n){} bool merge(int x,int y) { x=find(x); y=find(y); if(x==y) return 0; if(par[x]>par[y]) swap(x,y); par[x]+=par[y]; par[y]=x; --ok; return 1; } int find(int v) { if(par[v]<0) return v; return par[v]=find(par[v]); } int get(int x) { return -par[find(x)]; } bool same(int x,int y) { return find(x)==find(y); } vector<int> check() const{ vector<int> res; res.reserve(ok); for(int i=0;i<par.size();i++) if(par[i]<0) res.push_back(i); return res; } }; int32_t main() { int h,w; cin>>h>>w; vector<string> s(h); for(int i=0;i<h;i++) cin>>s[i]; node root(h+w); root.merge(0,h); root.merge(0,h+w-1); root.merge(h-1,w); root.merge(h-1,h+w-1); for(int i=0;i<h;i++) for(int j=0;j<w;j++) if(s[i][j]=='#') { int row=i,col=h+j; root.merge(row,col); } int res=0; for(int i=0;i<h;i++) for(int j=0;j<w;j++) { if(s[i][j]=='#') { if(!root.same(i,0)) { root.merge(i,0); ++res; } } } int e=0,o=0; { for(int i=1;i<=h-2;i++) { bool f=1; for(int j=0;j<w;j++) if(s[i][j]=='#') { f=0; break; } if(f) ++e; } for(int j=1;j<=w-2;j++) { bool f=1; for(int i=0;i<h;i++) if(s[i][j]=='#') { f=0; break; } if(f) o++; } } res+=min(e,o); cout<<res; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long LL; typedef long double LD; typedef pair<LL,LL> pii; typedef pair<LL,pii> ppi; typedef pair<pii,pii> ppp; #define FOR(i, n) for(int i = 1; i<=n; i++) #define F0R(i, n) for(int i = 0; i<n; i++) #define mp make_pair #define pb push_back #define f first #define s second 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 << "["; F0R(i, v.size()) {if (i) cout << ", "; cout << v[i];} return cout << "]";} struct fenwick{ LL sz; vector<array<LL, 2>> tr; fenwick(LL ss){ sz = ss; tr.assign(sz, {0, 0}); } void upd(LL g, array<LL, 2> k){ for(; g<sz; g+=g&-g){ tr[g][0] += k[0]; tr[g][1] += k[1]; } } array<LL, 2> ge(LL g){ array<LL, 2> res = {0, 0}; for(; g>0; g-=g&-g){ res[0] += tr[g][0]; res[1] += tr[g][1]; } return res; } }; //var const LL MX = 400000; LL T, n, m, q, ans = 0, a[200005], b[200005]; fenwick tra(400005), trb(400005); array<LL, 3> queries[200005]; vector<LL> vals; map<LL, LL> indexx; void solve(){ cin >> n >> m >> q; FOR(i, q){ F0R(j, 3){ cin >> queries[i][j]; } vals.pb(queries[i][2]); } vals.pb(0); sort(vals.begin(), vals.end()); vector<LL> equal = vals; vals.clear(); LL pr = -1; for(auto u : equal){ if(u != pr) vals.pb(u); pr = u; } F0R(i, (int)vals.size()) indexx[vals[i]] = i+1; tra.upd(indexx[0], {0, n}); trb.upd(indexx[0], {0, m}); FOR(i, n) a[i] = indexx[0]; FOR(i, m) b[i] = indexx[0]; //cout << vals << '\n'; FOR(z, q){ LL t1, i, x; t1 = queries[z][0], i = queries[z][1], x = queries[z][2]; x = indexx[x]; if(t1 == 1){ tra.upd(a[i], {-vals[a[i] - 1], -1}); ans -= trb.ge(a[i])[1] * vals[a[i] - 1] + (trb.ge(MX)[0] - trb.ge(a[i])[0]); a[i] = x; tra.upd(a[i], {vals[a[i] - 1], 1}); ans += trb.ge(a[i])[1] * vals[a[i] - 1] + (trb.ge(MX)[0] - trb.ge(a[i])[0]); } else{ trb.upd(b[i], {-vals[b[i] - 1], -1}); ans -= tra.ge(b[i])[1] * vals[b[i] - 1] + (tra.ge(MX)[0] - tra.ge(b[i])[0]); b[i] = x; trb.upd(b[i], {vals[b[i] - 1], 1}); ans += tra.ge(b[i])[1] * vals[b[i] - 1] + (tra.ge(MX)[0] - tra.ge(b[i])[0]); } cout << ans << "\n"; } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); T = 1; //cin >> T; FOR(t, T) solve(); cout.flush(); return 0; }
// I SELL YOU...! #include<iostream> #include<vector> #include<algorithm> #include<functional> #include<queue> #include<chrono> #include<iomanip> #include<map> #include<set> using namespace std; using ll = long long; using P = pair<ll,ll>; using TP = tuple<ll,ll,ll>; void init_io(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(18); } const ll MAX = 210,INF=1e15; vector<ll> a(MAX),b(MAX); ll joker = 0; ll n; vector<vector<ll>> dp(MAX,vector<ll>(MAX,-1)); ll solve(ll l,ll r){ if(dp[l][r]!=-1) return dp[l][r]; ll res; ll size = r-l+1; res = 0; vector<ll> cnt(MAX,0); for(int i=0;i<n;i++){ if(a[i]==b[i]&&a[i]==-1) continue; if(l<=a[i]&&a[i]<=r){ cnt[a[i]]++; ll idx; if(b[i]==-1){ idx = min(MAX-1,a[i]+size/2); }else if(b[i]-a[i]==size/2){ idx = b[i]; }else{ res = INF; break; } cnt[idx]++; }else if(l<=b[i]&&b[i]<=r){ cnt[b[i]]++; ll idx; if(a[i]==-1){ idx = max(0ll,b[i]-size/2); }else if(b[i]-a[i]==size/2){ idx = a[i]; }else{ res = INF; break; } cnt[idx]++; } } for(int i=0;i<MAX;i++){ if((l>i||i>r)&&cnt[i]){ res = INF; break; } if(cnt[i]>=2){ res = INF; break; } } for(int i=l;i<l+size/2;i++){ if((cnt[i]+cnt[i+size/2])==0){ res++; } } for(int i=l+2;i<r;i++){ res = min(res,solve(l,i-1)+solve(i,r)); } return dp[l][r] = res; } signed main(){ init_io(); cin >> n; bool can = true; map<ll,ll> mp; for(int i=0;i<n;i++){ cin >> a[i] >> b[i]; if(a[i]==b[i]&&a[i]==-1){ joker++; } mp[a[i]]++; mp[b[i]]++; if(a[i]!=-1&&b[i]!=-1&&a[i] >= b[i]){ can = false; } } for(auto [x,y]:mp){ if(x==-1) continue; if(y!=1){ can = false; break; } } if(!can){ cout <<"No"<<endl; return 0; } ll v = solve(1,n*2); if(v<=joker){ cout << "Yes"<<endl; }else{ cout <<"No"<<endl; } }
#include <bits/stdc++.h> #define rep(i, n) for (lli i = 0; i < (n); i++) #define rrep(i, n) for (lli i = (n)-1; i >= 0; i--) #define vall(x) (x).begin(), (x).end() using namespace std; namespace atcoder {} using namespace atcoder; using lli = long long int; void YESNO(bool), YesNo(bool); template <class T1, class T2> bool chmin(T1 &l, const T2 &r); template <class T1, class T2> bool chmax(T1 &l, const T2 &r); #define int long long int void solve(long long N, std::vector<long long> A, std::vector<long long> B, std::vector<long long> C, std::vector<long long> D, std::vector<long long> E) { int up = 2e9, low = 0; auto check = [&](int there) { int dp[3001][1 << 5][4] = {}; dp[0][0][0] = 1; for (int i = 0; i < N; i++) { int mask = 0; if (A[i] >= there) mask |= 1; if (B[i] >= there) mask |= 2; if (C[i] >= there) mask |= 4; if (D[i] >= there) mask |= 8; if (E[i] >= there) mask |= 16; for (int j = 0; j < 1 << 5; j++) { for (int k = 0; k < 4; k++) { if (k != 3) dp[i + 1][j | mask][k + 1] |= dp[i][j][k]; dp[i + 1][j][k] |= dp[i][j][k]; } } } return dp[N][31][3]; }; while (up - low > 1) { int mid = (up + low) / 2; (check(mid) ? low : up) = mid; } cout << low << endl; } signed main() { long long N; scanf("%lld", &N); std::vector<long long> A(N); std::vector<long long> B(N); std::vector<long long> C(N); std::vector<long long> D(N); std::vector<long long> E(N); for (int i = 0; i < N; i++) { scanf("%lld", &A[i]); scanf("%lld", &B[i]); scanf("%lld", &C[i]); scanf("%lld", &D[i]); scanf("%lld", &E[i]); } solve(N, std::move(A), std::move(B), std::move(C), std::move(D), std::move(E)); return 0; } // -- lib void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; } void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; } template <class T1, class T2> bool chmin(T1 &l, const T2 &r) { return (l > r) ? (l = r, true) : false; } template <class T1, class T2> bool chmax(T1 &l, const T2 &r) { return (l < r) ? (l = r, true) : false; } template <class T1, class T2> void vadd(vector<T1> &v, T2 x) { for (auto &s : v) s += T2(x); }
#include <iostream> using namespace std; using ll=long long; 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; } int main(){ ll MOD=1000000000+7; ll N,P;cin>>N>>P; ll res=P-1; res*=modpow(P-2,N-1,MOD); res=res%MOD; cout<<res<<endl; }
//ll __(){ // _(int,n); // _(string,s); // _(string,t); // vi a,b; // rep(i,n){ // if(s[i] == '1') // a.pb(i); // if(t[i] == '1') // b.pb(i); // } // vi erase; // ll ans = 0; // int l = 0; // rep(i,sz(a)){ // if(l < sz(b) && a[i] >= b[l]){ // ans += a[i]-b[l]; // ++l; // } // else // erase.pb(a[i]); // } // if(l < sz(b) || sz(erase)%2) // return -1; // for(int i = 0; i < sz(erase); i += 2) // ans += abs(erase[i]-erase[i+1]); // return ans; //} // #include <iomanip> #include <vector> #include <utility> #include <iostream> #include <string> #define pb push_back #define REP_ZERO_INT(i,r) for(int i = 0; i < (r); ++i) #define GET_REP_MACRO(_1,_2,_3,_4,NAME,...) NAME #define rep(...) GET_REP_MACRO(__VA_ARGS__,REP_ANY,REP_INT,REP_ZERO_INT)(__VA_ARGS__) #define all(v) (v).begin(), (v).end() #define sz(v) ll(v.size()) #define T1 template<typename T> static using namespace std; typedef long long ll; typedef vector<int> vi; T1 ostream& operator<<(ostream& stream, const vector<T>& t); T1 istream& read(T, T, istream& = cin); #define INPUT_WITHOUT_INIT(type,name) type name; cin >> name #define GET_INPUT_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME #define _(...) GET_INPUT_MACRO(__VA_ARGS__,_IWI,_IWI,_IWI,_IWI,_IWI,_IWI,INPUT_WITHOUT_INIT)(__VA_ARGS__) ll __(){ _(int,n); _(string,s); _(string,t); vi a,b; rep(i,n){ if(s[i] == '1') a.pb(i); if(t[i] == '1') b.pb(i); } vi erase; ll ans = 0; int l = 0; rep(i,sz(a)){ if(l < sz(b) && a[i] >= b[l]){ ans += a[i]-b[l]; ++l; } else erase.pb(a[i]); } if(l < sz(b) || sz(erase)%2) return -1; for(int i = 0; i < sz(erase); i += 2) ans += abs(erase[i]-erase[i+1]); return ans; } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); cout << __() << '\n'; }
#include<bits/stdc++.h> using namespace std; #define endl "\n" #define int long long #define rep(i,j,k) for(int i=j;i<k;i+=1) #define rrep(i,j,k) for(int i=n-1;i>=0;i-=1) #define sorti(v) sort(v.begin(),v.end()) #define sortd(v) sort(v.begin(),v.end(),greater<int>()) #define mm map<int,int> #define vv vector<int> #define tmm map<int,map<int,int>> #define trav(a, x) for(auto& a : x) #define ff first #define ss second #define lb lower_bound #define ub upper_bound #define all(v) v.begin(),v.end() #define pb push_back #define alot(x,y) memset(x,y,sizeof(x)) #define pii pair<int,int> #define code ios::sync_with_stdio(0);cin.tie(0);cout.tie(0) const int MOD=1e9+7; const double pi=acos(-1.0); /*memset(array_name,value_to_be_intialized,sizeof(array_name)); __builtin_popcount(n) count no of set bit in number n next_permutation(s.begin(),s.end()); int binpow(int a,int b){ int res=1; while(b>0){ if(b&1)res*=a; a*=a; b>>=1; } return res; } // lower_bound==> if the element is present it return its first occurence else 1st element which is greater than // upper_bound==> it will always return iterator to element which is greater than searched element */ int32_t main () { code; int tt; //cin>>tt; tt=1; while(tt--){ int n; cin>>n; mm mxa; int a[n+1]; int b[n+1]; cin>>a[0]; mxa[0]=a[0]; for(int i=1;i<n;i++){ cin>>a[i]; mxa[i]=max(mxa[i-1],a[i]); } cin>>b[0]; for(int i=1;i<n;i++){ cin>>b[i]; } cout<<a[0]*b[0]<<'\n'; int ans=a[0]*b[0]; for(int i=1;i<n;i++){ int p=mxa[i]*b[i]; ans=max(ans,p); cout<<ans<<"\n"; } cout<<"\n"; } return 0; }
# include <bits/stdc++.h> #include <cmath> #include <string> #include <vector> using namespace std; typedef long long ll; typedef long double ld; typedef pair <int, int> pii; typedef pair <pii, int> ppi; typedef pair <int, pii> pip; typedef pair <pii, pii> ppp; typedef pair <ll, ll> pll; # define A first # define B second # define endl '\n' # define sep ' ' # define all(x) x.begin(), x.end() # define kill(x) return cout << x << endl, 0 # define SZ(x) int(x.size()) # define lc id << 1 # define rc id << 1 | 1 #define fs(n) fixed << setprecision(n) #define mp(i, j) make_pair(i, j); ll power(ll a, ll b, ll md) { return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md)); } const int xn = 1e5 + 10; const int xm = - 20 + 10; const int sq = 320; const int inf = 1e9 + 10; const ll INF = 1e18 + 10; const int mod = 1e9 + 7;//998244353; const int base = 257; int main(){ ios::sync_with_stdio(0);cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int n, ans = 0; cin >> n; int a[n]; for(int i = 0; i < n; i++){ cin >> a[i]; } for(int i = 0; i < n; i++){ if(a[i] > 10){ ans = ans + (a[i] - 10); } } cout << ans; }
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで str[0]=toupper(str[0]); // g++ hoge.cpp -std=c++17 -I . でコンパイルできる // -fsanitize=undefinedでオーバーフロー検出 #include <bits/stdc++.h> //#include <atcoder/all> #define mod 1000000007 #define INF LLONG_MAX #define ll long long #define endl '\n' #define ln cout<<endl #define Yes cout<<"Yes"<<endl #define NO cout<<"NO"<<endl #define YES cout<<"YES"<<endl #define No cout<<"No"<<endl #define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++) #define rep(i,n) REP(i,0,n) #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() using namespace std; //using namespace atcoder; typedef pair<ll,ll> P; typedef tuple<ll,ll,ll> T; ll dx[4]={1,0,-1,0}; ll dy[4]={0,1,0,-1}; int main() { cin.tie(0); ios::sync_with_stdio(false); ll a,b,c,d,m,n,k,x,y,maxi=0,f=0,mini=INF,sum=0; string str; cin>>str; cout<<str[1]<<str[2]<<str[0]<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { char s[4]; cin >> s; // cout << s << endl; char temp; temp = s[0]; s[0] = s[1]; s[1] = s[2]; s[2] = temp; cout << s << endl; }
#include <bits/stdc++.h> using namespace std; //#pragma GCC optimize("Ofast") //#pragma GCC optimize ("unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define FastIO() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define read() freopen("in.txt","r",stdin) #define write() freopen("out.txt","w",stdout) typedef long long ll; typedef unsigned long long ull; typedef double dbl; typedef float flt; typedef pair<int, int> pii; typedef pair<ll, ll> pl; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpii; typedef vector<pl> vpl; #define pie acos(-1) #define mp make_pair #define pb push_back #define eb emplace_back #define ff first #define ss second #define MAX 300005 #define MOD 1000000007 #define INF 1000000100 #define for0(i, n) for(ll i=0; i<n; i++) #define for1(i, n) for(ll i=1; i<=n; i++) #define forab(i, a, b) for(ll i=a; i<=b; i++) #define forabx(i, a, b, x) for(ll i=a; i<=b; i+=x) #define forinv(i, a, b) for(ll i=a; i>=b; i--) #define clr0(a) memset(a, 0, sizeof(a)) #define ceil(x, y) (x+y-1) / (y) #define max3(a, b, c) max(a, max(b, c)) #define min3(a, b, c) min(a, min(b, c)) #define gcd(a, b) __gcd(a, b) #define lcm(a, b) ((a * b) / __gcd(a, b)) #define sort1(a, x, y) sort(a+x, a+y+1) #define debug(x) cout << "DEBUG " << x << endl; #define Y() cout << "YES" << endl; #define N() cout << "NO" << endl; #define inArr(a, x, y) forab(i, x, y) { cin >> a[i]; } #define outArr(a, x, y) forab(i, x, y) { cout << a[i] << " "; } cout << endl; void solve() { ll n; cin >> n; char a[n+10], b[n+10]; cin >> a; cin >> b; vl a0, b0; ll ca=0, cb=0; for0(i, n) { if (a[i]=='0') { ca ++; a0.pb(i); } if (b[i]=='0') { cb++; b0.pb(i); } } ll ans = 0; if (ca!=cb) { ans = -1; } else { for0(i, ca) { if (a0[i]!=b0[i]) { ans ++; } } } cout << ans << endl; } void testcase() { ll t; cin >> t; while (t--) { solve(); } } int main () { FastIO() //testcase(); solve(); return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #pragma comment(linker, "/stack:200000000") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") //turn on extra precision //#pragma GCC target("fpmath=387") using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef string str; typedef pair <int,int> pii; typedef pair <ll,ll> pll; typedef vector <int> vi; typedef vector <ll> vll; typedef vector <pii> vpii; typedef vector <pll> vpll; #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> #define ordered_multiset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> #define mp make_pair #define pb push_back #define pob pop_back #define pf push_front #define pof pop_front #define fi first #define se second #define fs first.second #define ss second.second #define ff first.first #define sf second.first #define newl '\n' #define fbo find_by_order #define ook order_of_key #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(),x.rend() #define watch(x) cout << (#x) << " is : " << (x) << newl mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); vi dirx = {0,0,1,-1}; vi diry = {1,-1,0,0}; char to_upper (char x){ if( 97 <= int(x) && int(x) <= 122) return char(x-32); if( 65 <= int(x) && int(x) <= 90) return x; return -1; } char to_lower (char x){ if( 97 <= int(x) && int(x) <= 122) return x; if( 65 <= int(x) && int(x) <= 90) return char(x+32); return -1; } int numerize (char x){ if(48 <= int(x) && int(x) <= 57) return int(x-'0'); if(97 <= int(x) && int(x) <= 122) return int(x-96); if(65 <= int(x) && int(x) <= 90) return int(x-64); return -1; } bool isect (int l1, int r1, int l2, int r2){ return max(l1,l2) <= min(r1,r2); } ll quickpow (ll num1, ll num2, ll MOD){ if(num2==0)return 1%MOD; else if(num2==1)return num1%MOD; else{ ll temp = quickpow (num1,num2>>1LL,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD; if(num2&1) res = ((res%MOD)*(num1%MOD))%MOD; return res; } } ll invmod (ll num, ll MOD){return quickpow (num,MOD-2,MOD);} ll gcd (ll num1, ll num2){ if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ; while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;} return num2; } ll lcm (ll num1 , ll num2){return (ll) (num1/__gcd(num1,num2))*num2;} // end of Template int main(){ // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); ios_base::sync_with_stdio(false); cin.tie(NULL); int a,b,c,d; cin >> a >> b >> c >> d; cout << b - c << newl; return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for(int i=0; i<(int)(n); i++) int main(){ int N, ans=0; cin >> N; int A[N]; REP(i, N){ cin >> A[i]; A[i]=A[i]%200; } int M=min(8, N), R[200]={}; vector<int> X={}, Y={}; REP(i, 1<<M){ if(i==0){ continue; } int k=i, d=0, n=0; Y={}; while(k){ if(k%2==1){ n=(n+A[d])%200; Y.push_back(d+1); } k/=2; d++; } if(R[n]){ cout << "Yes\n"; int l=R[n], g=0; while(l){ if(l%2==1){ X.push_back(g+1); } l/=2; g++; } cout << X.size(); REP(j, X.size()){ cout << " " << X[j]; } cout << "\n" << Y.size(); REP(j, Y.size()){ cout << " " << Y[j]; } cout << "\n"; return 0; }else{ R[n]=i; } } cout << "No\n"; }
#include<bits/stdc++.h> #include<string> using namespace std; #define ll long long int #define ld long double #define pb push_back #define all(v) v.begin(),v.end() #define sz(x) ((int)(x).size()) #define fi first #define se second #define deb(x) cout<< #x << '=' << x <<endl #define MOD 1000000007 ll p(ll a , ll n){ if(n == 0){ return 1; } ll res = p(a*a , n / 2); if(n % 2){ res *= a; } return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n; cin>>n; ll ans = 0; set<ll> s; for(ll i = 2; i <= 2e5; i++){ for(ll j = 2; j <= 40; j++){ ll c = p(i , j); if(c > n){ break; } s.insert(c); } } ans = n - (sz(s)); cout<<ans<<"\n"; return 0; }
#include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; ///Welcome to Nasif's Code #define bug printf("bug\n"); #define bug2(var) cout<<#var<<" "<<var<<endl; #define co(q) cout<<q<<endl; #define all(q) (q).begin(),(q).end() #define pi acos(-1) #define inf 1000000000000000LL #define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define MODADD(ADD_X,ADD_Y) (ADD_X+ADD_Y)%MOD #define MODSUB(SUB_X,SUB_Y) ((SUB_X-SUB_Y)+MOD)%MOD #define MODMUL(MUL_X,MUL_Y) (MUL_X*MUL_Y)%MOD #define LCM(LCM_X,LCM_Y) (LCM_X/__gcd(LCM_X,LCM_Y))*LCM_Y template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; typedef long long int ll; typedef unsigned long long int ull; const int MOD = (int)1e9+7; const int MAX = 1e6; int dx[]= {1,0,-1,0,1,-1,1,-1}; int dy[]= {0,1,0,-1,1,-1,-1,1}; int arr[MAX]; int main() { FastRead //freopen("output.txt", "w", stdout); int n,mx=0,ans; cin>>n; for(int i=1; i<=n; i++) cin>>arr[i]; for(int i=2; i<=1000; i++) { int cnt=0; for(int j=1; j<=n; j++) { if(arr[j]%i==0) cnt++; } if(cnt>mx){ mx=cnt; ans=i; } } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; int main(){ int n; cin >> n; int a[n]; rep(i,n) cin >>a[i]; int max=0; int ans=0; for(int i=2;i<1000;i++){ int cnt =0; for(int j=0;j<n;j++){ if(a[j]%i == 0) cnt++; if(max<cnt){ max=cnt; ans=i; } } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define int long long #define forn(i,a,n) for (int i=a; i<n; i++) int n; int a[200005],b[200005],c[200005]; int suma,sumb; signed main(){ ios::sync_with_stdio(false); cin.tie(0); //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); cin>>n; forn(i,0,n){ cin>>a[i]>>b[i]; sumb+=a[i]; c[i]=a[i]+b[i]+a[i]; } sort(c,c+n); reverse(c,c+n); int cur=0; int sum=sumb-suma; while (sum>=0){ sum-=c[cur]; cur++; } cout<<cur<<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; // using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>; void __dbg() { cout << endl; } template<typename Arg, typename... Args> void __dbg(Arg A, Args... B) { cout << " " << A; __dbg(B...); } #define dbg(...) cout << "(" << #__VA_ARGS__ << "):", __dbg(__VA_ARGS__) #define rep(i,a,b) for(int i=a;i<b;i++) #define lprin(n) printf("%lld\n", n) #define lpri(n) printf("%lld ", n) #define lscn(n) scanf("%lld", &n) #define prin(n) printf("%d\n", n) #define pri(n) printf("%d ", n) #define scn(n) scanf("%d", &n) #define vi vector<int> #define ll long long #define pb push_back #define mp make_pair #define F first #define S second const int inf = INT_MAX; const int ninf = INT_MIN; const int mod = 1e9 + 7; const int maxN = 1e6 + 2; int main() { int n; scn(n); vector<ll> a(n), b(n); vi order(n); iota(order.begin(), order.end(), 0); rep(i, 0, n) { lscn(a[i]); lscn(b[i]); } ll B = 0, A = accumulate(a.begin(), a.end(), 0LL); sort(order.begin(), order.end(), [&](const int& i, const int& j){ return (2 * a[i] + b[i]) > (2 * a[j] + b[j]); }); rep(k, 0, n) { int i = order[k]; B += a[i] + b[i]; A -= a[i]; if(B > A) { prin(k + 1); exit(0); } } assert(false); return 0; }
#include <bits/stdc++.h> using namespace std; const long long MOD = 998244353; int main(){ int N; cin >> N; vector<int> W(N); for (int i = 0; i < N; i++){ cin >> W[i]; } int S = 0; for (int i = 0; i < N; i++){ S += W[i]; } if (S % 2 == 1){ cout << 0 << endl; } else { vector<vector<long long>> dp(1, vector<long long>(S / 2 + 1, 0)); dp[0][0] = 1; for (int i = 0; i < N; i++){ vector<vector<long long>> dp2(i + 2, vector<long long>(S / 2 + 1, 0)); for (int j = 0; j <= i; j++){ for (int k = 0; k <= S / 2; k++){ if (dp[j][k] > 0){ dp2[j][k] += dp[j][k]; dp2[j][k] %= MOD; if (k + W[i] <= S / 2){ dp2[j + 1][k + W[i]] += dp[j][k]; dp2[j + 1][k + W[i]] %= MOD; } } } } swap(dp, dp2); } vector<long long> cnt(N + 1, 0); for (int i = 0; i <= N; i++){ cnt[i] = dp[i][S / 2]; } vector<long long> fact(N + 1, 1); for (int i = 1; i <= N; i++){ fact[i] = fact[i - 1] * i % MOD; } long long ans = 0; for (int i = 0; i <= N; i++){ ans += fact[i] * fact[N - i] % MOD * cnt[i] % MOD; } ans %= MOD; cout << ans << endl; } }
#include<bits/stdc++.h> template <typename _Tp>void read(_Tp &x){ char ch(getchar());bool f(false);while(!isdigit(ch))f|=ch==45,ch=getchar(); x=ch&15,ch=getchar();while(isdigit(ch))x=x*10+(ch&15),ch=getchar(); if(f)x=-x; } template <typename _Tp,typename... Args>void read(_Tp &t,Args &...args){read(t);read(args...);} const int N=105,mod=998244353; template<typename _Tp1,typename _Tp2>inline void add(_Tp1 &a,_Tp2 b){(a+=b)>=mod&&(a-=mod);} template<typename _Tp1,typename _Tp2>inline void sub(_Tp1 &a,_Tp2 b){(a-=b)<0&&(a+=mod);} int f[N][20005],g[N][20005]; long long fac[N]; int main(){ fac[0]=fac[1]=1;for(int i=2;i<N;++i)fac[i]=fac[i-1]*i%mod; int n;read(n); f[0][10000]=1;int s=0; for(int i=1,x;i<=n;++i){ read(x),s=std::min(10000,x+s); memset(g,0,sizeof(g)); for(int j=0;j<i;++j){ for(int k=10000-s;k<=10000+s;++k){ if(k-x>=0)add(g[j+1][k-x],f[j][k]); if(k+x<=20000)add(g[j][k+x],f[j][k]); } } memcpy(f,g,sizeof(f)); } int ans=0; for(int i=0;i<=n;++i)add(ans,1LL*f[i][10000]*fac[i]%mod*fac[n-i]%mod); printf("%d\n",ans); return 0; }
#include <iostream> #include <vector> #include <algorithm> #include <iomanip> #include <cmath> #include <queue> #include <string> #include <utility> #include <functional> using namespace std; using ll = long long int; using pii = pair<int,int>; using pll = pair<ll,ll>; int main(){ int N; cin >> N; for(int i=1;i<=N;i++){ //cout << i << ":"; cout << (i-1)/2+1 << " " << (N+i+1)/2 << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cout << (2*i)%n + 1 << " " << (2*i+1)%n + 1 << endl; } }
#include<bits/stdc++.h> using namespace std; using ll=long long; using ld=long double; const ll LL_MAX=LLONG_MAX; struct In{ template<typename T> operator T(){ T x; cin >> x; return x; } }; In in; template <typename T,typename U> void forin(T* x,U n){ for (U i=0;i<n;i++) cin >> x[i]; } template <typename T> int div1(T x) { return x%1000000007; } template <typename T> void out(T x){ cout << x << endl; } template <typename T> T gcd(T x,T y){ if (y == 0) return x; return gcd(y,x%y); } template <typename T> T lcm(T x,T y){ return x*y/gcd(x,y); } int main(){ int n=in; string s=in; int at,cg,ans=0; for (int i=0;i<n;i++){ at=0; cg=0; if (s[i]=='A') at++; else if (s[i]=='T') at--; else if (s[i]=='C') cg++; else if (s[i]=='G') cg--; for (int i2=i+1;i2<n;i2++){ if (s[i2]=='A') at++; else if (s[i2]=='T') at--; else if (s[i2]=='C') cg++; else if (s[i2]=='G') cg--; if (at==0 && cg==0) ans++; } } out(ans); }
#include <bits/stdc++.h> using namespace std; #define mp make_pair #define pb push_back #define eb emplace_back #define f first #define s second #define fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); #define int long long #define endl "\n" #define yn(b) cout << &("NO\n\0YES\n"[4*b]); #define show(a) {for(auto x:a) cout << x << " "; cout << endl;} template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>; void solve(){ int n; cin >> n; int ans = n/100; if(n%100!=0) ans++; cout << ans << endl; } int32_t main(){ fast; int t; //cin >> t; t=1; while(t--){ solve(); } }
#include <iostream> #include <vector> #include <cstdio> #include <sstream> #include <map> #include <string> #include <algorithm> #include <queue> #include <cmath> #include <functional> #include <set> #include <ctime> #include <random> #include <chrono> #include <cassert> #include <tuple> #include <numeric> #include <utility> using namespace std; namespace { using Integer = long long; //__int128; template<class T, class S> istream& operator >> (istream& is, pair<T,S>& p){return is >> p.first >> p.second;} template<class T> istream& operator >> (istream& is, vector<T>& vec){for(T& val: vec) is >> val; return is;} template<class T> istream& operator , (istream& is, T& val){ return is >> val;} template<class T, class S> ostream& operator << (ostream& os, const pair<T,S>& p){return os << p.first << " " << p.second;} template<class T> ostream& operator << (ostream& os, const vector<T>& vec){for(size_t i=0; i<vec.size(); i++) os << vec[i] << (i==vec.size()-1?"":" "); return os;} template<class T> ostream& operator , (ostream& os, const T& val){ return os << " " << val;} template<class H> void print(const H& head){ cout << head; } template<class H, class ... T> void print(const H& head, const T& ... tail){ cout << head << " "; print(tail...); } template<class ... T> void println(const T& ... values){ print(values...); cout << endl; } template<class H> void eprint(const H& head){ cerr << head; } template<class H, class ... T> void eprint(const H& head, const T& ... tail){ cerr << head << " "; eprint(tail...); } template<class ... T> void eprintln(const T& ... values){ eprint(values...); cerr << endl; } class range{ Integer start_, end_, step_; public: struct range_iterator{ Integer val, step_; range_iterator(Integer v, Integer step) : val(v), step_(step) {} Integer operator * (){return val;} void operator ++ (){val += step_;} bool operator != (range_iterator& x){return step_ > 0 ? val < x.val : val > x.val;} }; range(Integer len) : start_(0), end_(len), step_(1) {} range(Integer start, Integer end) : start_(start), end_(end), step_(1) {} range(Integer start, Integer end, Integer step) : start_(start), end_(end), step_(step) {} range_iterator begin(){ return range_iterator(start_, step_); } range_iterator end(){ return range_iterator( end_, step_); } }; inline string operator "" _s (const char* str, size_t size){ return move(string(str)); } constexpr Integer my_pow(Integer x, Integer k, Integer z=1){return k==0 ? z : k==1 ? z*x : (k&1) ? my_pow(x*x,k>>1,z*x) : my_pow(x*x,k>>1,z);} constexpr Integer my_pow_mod(Integer x, Integer k, Integer M, Integer z=1){return k==0 ? z%M : k==1 ? z*x%M : (k&1) ? my_pow_mod(x*x%M,k>>1,M,z*x%M) : my_pow_mod(x*x%M,k>>1,M,z);} constexpr unsigned long long operator "" _ten (unsigned long long value){ return my_pow(10,value); } inline int k_bit(Integer x, int k){return (x>>k)&1;} //0-indexed mt19937 mt(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()); template<class T> string join(const vector<T>& v, const string& sep){ stringstream ss; for(size_t i=0; i<v.size(); i++){ if(i>0) ss << sep; ss << v[i]; } return ss.str(); } inline string operator * (string s, int k){ string ret; while(k){ if(k&1) ret += s; s += s; k >>= 1; } return ret; } } constexpr long long mod = 9_ten + 7; int main(){ long long n,m; cin >> n, m; long long r = my_pow_mod(10, n, m); long long x = my_pow_mod(10, n, m*m); println((x-r) / m); return 0; }
#include <bits/stdc++.h> #define ll long long #define sc scanf #define pr printf using namespace std; const int N = 100010, M = 1 << 13; const double eps = 1e-10; ll n, m; //int w[N], d[N], b[N]; //double x[N], y[N]; //char s[N]; ll powMOD(ll a, ll b, ll MOD) { ll res = 1; while (b) { if (b & 1) res = res * a % MOD; a = a * a % MOD; b >>= 1; } return res; } void solve() { sc("%lld %lld", &n, &m); // ll t = m, x, y; // x = y = 0; // while(t % 2 == 0) t /= 2, x ++ ; // while(t % 5 == 0) t /= 5, y ++ ; // if(x <= n && x * 2 > n && y <= n && y * 2 > n && t == 1) { // // } // else pr("%lld\n", powMOD(10, n, m * m) / m % m); } int main() { // int T; // sc("%d", &T); // while(T --) solve(); return 0; }
#include <algorithm> #include <bitset> #include <complex> #include <deque> #include <iostream> #include <istream> #include <iterator> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #include <tuple> #include <iomanip> #include <random> #include <math.h> #include <stdio.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using pii = pair<int, int>; void display_2int(vector<vector<int>> vec) { int N = vec.size(); for (int i=0; i<N; i++) { for (int j=0; j<vec.at(i).size(); j++) { cout << vec.at(i).at(j); if (j < vec.at(i).size()-1) { cout << " "; } } cout << endl; } } void display_1string(vector<string> strlist) { int N = strlist.size(); for (int i=0; i<N; i++) { cout << strlist.at(i) << endl; } } void display_1int(vector<int> intlist) { int N = intlist.size(); if (N>0){ for (int i=0; i<N - 1; i++) { cout << intlist.at(i) << " "; } cout << intlist.at(N-1) << endl; }else{ cout << endl; } } void display_1ll(vector<long long> lllist) { long long N = lllist.size(); if (N>0){ for (int i=0; i<N - 1; i++) { cout << lllist.at(i) << " "; } cout << lllist.at(N-1) << endl; }else{ cout << endl; } } void display_2string(vector<vector<string>> vec) { int N = vec.size(); for (int i=0; i<N; i++) { for (int j=0; j<vec.at(i).size(); j++) { cout << vec.at(i).at(j); if (j < vec.at(i).size()-1) { cout << " "; } } cout << endl; } } int lstmax(vector<int> lst){ int m = lst.at(0); int n = lst.size(); for (int i=0; i<n-1; i++){ m = max(m, lst.at(i)); } return m; } int lstmin(vector<int> lst){ int m = lst.at(0); int n = lst.size(); for (int i=0; i<n-1; i++){ m = min(m, lst.at(i)); } return m; } int main(){ string a; cin >> a; cout << a.at(1) << a.at(2) << a.at(0) << endl; }
#include <bits/stdc++.h> using namespace std; using LL = long long; LL N, fib[100]; vector<int> ans; int vis[100]; void print() { LL x = 0, y = 0; for (int i : ans) { if (i == 1) x++; if (i == 2) y++; if (i == 3) x = x + y; if (i == 4) y = x + y; } cerr << x << endl; } int main() { #ifndef ONLINE_JUDGE freopen("cpp.in", "r", stdin); #endif fib[0] = fib[1] = 1; for (int i = 2; i < 90; i++) fib[i] = fib[i - 1] + fib[i - 2]; cin >> N; for (int i = 89; ~i; i--) if (N >= fib[i]) N -= fib[i], vis[i] = 1; int lim = 0; for (int i = 1; i < 90; i++) if (vis[i]) lim = i; for (int i = lim, j = 1; ~i; i--, j++) { if (vis[i]) { if (i & 1) ans.push_back(2); else ans.push_back(1); } if (j & 1) ans.push_back(4); else ans.push_back(3); } //print(); printf("%lu\n", ans.size()); for (int i : ans) printf("%d\n", i); return 0; }
#include<bits/stdc++.h> #define LL long long #define dl double #define P pair<int,int> #define SZ(a) ((int)a.size()) using namespace std; const int N = 4e5 + 10; int n,a[N],id[N]; bool cmp(const int &x,const int &y){return a[x] < a[y];} bool c[N]; int main(){ // freopen("in.txt","r",stdin); // freopen("o.txt","w",stdout); std::ios::sync_with_stdio(false); std::cin.tie(nullptr); cin >> n;n *= 2; for(int i = 1;i <= n;i++)cin >> a[i],id[i] = i; sort(id + 1,id + n + 1,cmp); for(int i = 1;i <= n / 2;i++)c[id[i]] = 0; for(int i = n / 2 + 1;i <= n;i++)c[id[i]] = 1; int cnt = 0; for(int i = 1;i <= n;i++){ if(c[i] == 0){ if(cnt < 0)cout << ')'; else cout << '('; cnt++; } else { if(cnt > 0)cout << ')'; else cout << '('; cnt--; } } return 0; } /**/
#include<iostream> #include<algorithm> using namespace std; int N; pair<int,int>A[4<<17]; bool lo[4<<17]; main() { cin>>N; for(int i=0;i<2*N;i++) { cin>>A[i].first; A[i].second=i; } sort(A,A+2*N); for(int i=0;i<N;i++)lo[A[i].second]=true; string ans=""; int now=0; bool up; for(int i=0;i<2*N;i++) { if(now==0) { up=lo[i]; ans+='('; now++; } else { if(up==lo[i]) { ans+='('; now++; } else { ans+=')'; now--; } } } cout<<ans<<endl; }
#include<bits/stdc++.h> #include<math.h> using namespace std; /*------------------------------------------------------------------*/ #define ll long long int #define mp make_pair #define pb push_back #define MOD 998244353 bool isvowel(char c) { if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u') return true; return false; } ll isprime(ll n) { ll ans=1; for(ll i=2;i<=sqrt(n);i++) { if(n%i==0) return 0; } return 1; } ll power(ll a,ll b,ll m) { if(b==0) return 1; if(b==1) return a%m; ll temp=power(a,b/2,m); if(b%2==0) return ((temp%m)*(temp%m))%m; else return ((((temp%m)*(temp%m))%m)*a%m)%m; } const int MAX = 510000; long long fac[MAX], finv[MAX], inv[MAX]; void ncrinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++){ fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } long long ncr(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; } ll c(ll n, ll k) { ll i, j; ll C[n + 1][k + 1]; for (i = 0; i <= n; i++) { for (j = 0; j <= min(i, k); j++) { if (j == 0 || j == i) C[i][j] = 1; else C[i][j] = (C[i - 1][j - 1]%MOD + C[i - 1][j]%MOD)%MOD; } } return C[n][k]%MOD; } ll modInverse(ll a, ll m) { ll m0 = m; ll y = 0, x = 1; if (m == 1) return 0; while (a > 1) { ll q = a / m; ll t = m; m = a % m, a = t; t = y; y = x - q * y; x = t; } if (x < 0) x += m0; return x; } ll fact(ll n) { ll ans=1; for(ll i=1;i<=n;i++) { ans = (ans%MOD * i%MOD)%MOD; } return ans; } /*-----------------------------------------------------------------------------*/ int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); //freopen("1.txt","rt",stdin); //freopen("output.txt","wwt",stdout); ll t; t=1; //cin>>t; //ll t1=0; ll t1=0; while(t--) { ll h,w,x,y; cin>>h>>w>>x>>y; x--; y--; string s[h]; for(ll i=0;i<h;i++) cin>>s[i]; ll cnt=1; for(ll i=x+1;i<h;i++) { if(s[i][y]=='.') cnt++; else break; } for(ll i=x-1;i>=0;i--) { if(s[i][y]=='.') cnt++; else break; } for(ll i=y+1;i<w;i++) { if(s[x][i]=='.') cnt++; else break; } for(ll i=y-1;i>=0;i--) { if(s[x][i]=='.') cnt++; else break; } cout<<cnt<<endl; } }
#include<bits/stdc++.h> using namespace std; int main(){ int h,w,x,y; char s[110][110]; cin >> h >> w >> y >> x; int count = 1; for(int i = 1; i <= h; i++){ for(int j = 1; j <= w;j++){ cin >> s[i][j];//問題文の通りに入力されてる } } for(int i = y;i >= 1;i--){ //同じ列でy~0まで調べる if( s[i][x] == '.' )count++; else{ break; } } for(int i = y;i <= h;i++){ //同じ列をy~hまで調べる if(s[i][x] == '.')count++; else{ break; } } for(int i = x;i >= 1;i--){ //同じ行をx~0まで調べる if(s[y][i] == '.')count++; else{ break; } } for(int i = x;i <= w;i++){ if(s[y][i] == '.')count++; else{ break; } } cout << count - 4 << endl; }
#include <bits/stdc++.h> using namespace std; template<typename T> vector<pair<T, int>> prime_factor(T num) { vector<pair<T, int>> ret; for(T i=2; i*i<=num; ++i) { int cnt = 0; while(num%i == 0) { num /= i; ++cnt; } if(cnt != 0) ret.emplace_back(i, cnt); } if(num != 1) ret.emplace_back(num, 1); return ret; } // if (srt > 0), sorted by ascending order. else if (srt < 0), sorted by descending order. template<typename T> vector<T> divisor(vector<pair<T, int>> &pf, int srt) { vector<T> ret; ret.emplace_back(1); for(auto &p : pf) { int sz = ret.size(); T x; int y; tie(x,y) = p; T d = 1; for(int i=0; i<y; ++i) { d *= x; for(int j=0; j<sz; ++j) { ret.emplace_back(d * ret[j]); } } } if(srt > 0) sort(ret.begin(), ret.end()); else if(srt < 0) sort(ret.rbegin(), ret.rend()); return ret; } template<typename T> vector<T> divisor(const T &num, int srt) { auto pf = prime_factor(num); return divisor(pf, srt); } void solve() { int n; cin >> n; vector<int> a(n); for(auto &x : a) cin >> x; unordered_map<int, int> cnt; map<int, vector<int>, greater<int>> to; to[1] = {}; for(auto &x : a) { auto pf = prime_factor(x); auto div = divisor(pf, 0); for(auto &d : div) { ++cnt[d]; if(!to.count(d)) { for(auto &[p, c] : pf) { if(d % p == 0) { to[d].emplace_back(d / p); } } } } } unordered_set<int> ng; int ans = 1; int MIN = *min_element(begin(a), end(a)); for(auto &[d, vec] : to) { if(d < MIN && !ng.count(d)) ++ans; for(auto &x : vec) { if(cnt[x] < 2 || cnt[x] == cnt[d]) { ng.emplace(x); } } } cout << ans << endl; } signed main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); solve(); return 0; }
#include<bits/stdc++.h> using namespace std; #define N 2005 #define mod 998244353 #define LL long long int n, a_min, i, a[N], j, ans; vector<int> vec; unordered_set<int> Ans; map<int,int> A, ext; int main (void) { scanf("%d",&n); a_min=-1; for (i=1; i<=n; i++) { scanf("%d",&a[i]); if (a_min==-1) a_min=a[i]; else a_min=min(a_min,a[i]); vec.clear(); for (j=1; j*j<=a[i]; j++) if (a[i]%j==0) { vec.push_back(j); if (j*j!=a[i]) vec.push_back(a[i]/j); } sort(vec.begin(),vec.end()); ext.clear(); for (j=vec.size()-1; j>=0; j--) { if (ext.count(A[vec[j]])) continue; ext[A[vec[j]]]=1; Ans.insert(vec[j]); } for (j=0; j<vec.size(); j++) A[vec[j]]=((LL)A[vec[j]]*n+i)%mod; } ans=0; for (auto x:Ans) if (x<=a_min) ans++; printf("%d\n",ans); return 0; }
#include <iostream> #include <map> #include <algorithm> #include <vector> #include <iomanip> #include <sstream> #include <cmath> #include <math.h> #include <string> #include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(n) for( int i = 0 ; i < n ; i++ ) #define REP(n) for( int i = 1 ; i <= n ; i++ ) #define repll(n) for( ll i = 0 ; i < n ; i++ ) #define REPll(n) for( ll i = 1 ; i <= n ; i++ ) #define rep2(n) for( int j = 0 ; j < n ; j++ ) #define REP2(n) for( int j = 1 ; j <= n ; j++ ) #define repll2(n) for( ll j = 0 ; j < n ; j++ ) #define REPll2(n) for( ll j = 1 ; j <= n ; j++ ) int main() { ios::sync_with_stdio(false); cin.tie(0); int n , w; cin >> n >> w; cout << n / w; }
#include <stdio.h> int main(void) { int n, w, i; int count = 0; scanf("%d %d", &n, &w); for (i = n - w; i >= 0; i -= w) count++; printf("%d\n", count); return 0; }