code_file1
stringlengths
87
4k
code_file2
stringlengths
85
4k
#include<bits/stdc++.h> #define ll long long using namespace std; #define quick ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0); #define s(x) sort(x.begin(),x.end()) #define sr(x) sort(x.begin(),x.end(),greater<ll>()) #define v1 vector<ll> #define s1 set<ll> #define p1 pair<ll,ll> #define m1 map<ll,ll> #define take(v,n) for(i=0;i<n;i++) cin>>v[i]; #define print(v,n) for(i=0;i<n;i++) cout<<v[i]<<" "; #define ff first #define ss second #define ee '\n'; #define pb push_back #define mp make_pair #define all(v) v.begin(),v.end() #define f(i,x,y) for(i=x;i<y;i++) #define mp make_pair #define yes cout<<"Yes"<<endl #define no cout<<"No"<<endl bool sortbysec(const pair<string,ll> & a, const pair<string,ll> & b) { return (a.second < b.second); } void solve() { ll n,i; cin>>n; vector<pair<string,ll>> p; f(i,0,n) { ll y; string s; cin>>s>>y ; p.pb(mp(s,y)); } sort(all(p), sortbysec); cout<<p[p.size()-2].ff<<ee; } int32_t main() { quick; ll t=1; //cin>>t; while(t--) { solve(); } return 0; }
#include<bits/stdc++.h> using namespace std; using ll = long long; using vs = vector<string>; using vi = vector<int>; using vl = vector<ll>; using vb = vector<bool>; using pi = pair<int, int>; using pl = pair<ll, ll>; using vpi = vector<pair<int, int>>; using vpl = vector<pair<ll, ll>>; using ld = double; #define sz(x) (int)(x).size() #define all(x) x.begin(), x.end() #define ins insert #define nl "\n" const ll MOD = 998244353; ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; } ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; } ll mult(ll x, ll y) { return (x * y) % MOD; } template<typename T> T signum(T a) { return (a > 0) - (a < 0); } template<typename T> T cmp(T a, T b) { return signum(a-b); } template<typename T> bool mins(T& lhs , T& rhs) { if (rhs < lhs) { lhs = rhs; return true; } return false; } template<typename T> bool maxs(T& lhs , T& rhs) { if (rhs > lhs) { lhs = rhs; return true; } return false; } const int MAX = INT_MAX; void gks(int tc) { printf("Case #%d: ", tc); }; int main() { int n; cin>>n; vector<pair<int, string>> a(n); for (int i = 0;i < n;++i) { cin>>a[i].second>>a[i].first; } auto cmp = [&] (const pair<int, string>& lhs, const pair<int, string>& rhs) { return lhs.first > rhs.first; }; sort(all(a), cmp); cout<<a[1].second<<nl; return 0; }
/************************************************************************* > File Name: 2.cpp > Author: Knowledge_llz > Mail: 925538513@qq.com > Blog: https://blog.csdn.net/Pig_cfbsl > Created Time: 2020/10/24 20:09:51 ************************************************************************/ #include<iostream> #include<cstdio> #include<cstdlib> #include<cmath> #include<cstring> #include<algorithm> #define For(i,a,b) for(register int i=(a);i<=(b);++i) #define LL long long using namespace std; int read(){ char x=getchar(); int u=0,fg=0; while(!isdigit(x)){ if(x=='-') fg=1; x=getchar(); } while(isdigit(x)){ u=(u<<3)+(u<<1)+(x^48); x=getchar(); } return fg?-u:u; } const int maxx=4e5+10; LL a[maxx],b[maxx]; LL n,m,u,v,be[maxx],ne[maxx],to[maxx],e=0,sum; bool vis[maxx]; void add(int x,int y){ to[++e]=y; ne[e]=be[x]; be[x]=e; } void dfs(int x){ vis[x]=1; sum+=b[x]; for(int i=be[x];i;i=ne[i]){ int go=to[i]; if(!vis[go]) dfs(go); } } int main() { #ifndef ONLINE_JUDGE freopen("input.in", "r", stdin); freopen("output.out", "w", stdout); #endif n=read(); m=read(); For(i,1,n) a[i]=read(); For(i,1,n) b[i]=read()-a[i]; For(i,1,m){ u=read(); v=read(); add(u,v); add(v,u); } For(i,1,n) if(!vis[i]){ sum=0; dfs(i); if(sum!=0){ printf("No\n"); return 0; } } printf("Yes\n"); return 0; }
#line 2 "header.hpp" //%snippet.set('header')% //%snippet.fold()% #ifndef HEADER_H #define HEADER_H // template version 2.0 using namespace std; #include <bits/stdc++.h> // varibable settings template <class T> constexpr T inf = numeric_limits<T>::max() / 2.1; #define _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i) #define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__) #define _rrep(i, n) rrepi(i, 0, n) #define rrepi(i, a, b) for (ll i = (ll)((b)-1); i >= (ll)(a); --i) #define r_rep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__) #define each(i, a) for (auto &&i : a) #define all(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) #define pb(a) push_back(a) #define mp(a, b) make_pair(a, b) #define mt(...) make_tuple(__VA_ARGS__) #define ub upper_bound #define lb lower_bound #define lpos(A, x) (lower_bound(all(A), x) - A.begin()) #define upos(A, x) (upper_bound(all(A), x) - A.begin()) template <class T, class U> inline void chmax(T &a, const U &b) { if ((a) < (b)) (a) = (b); } template <class T, class U> inline void chmin(T &a, const U &b) { if ((a) > (b)) (a) = (b); } template <typename X, typename T> auto make_table(X x, T a) { return vector<T>(x, a); } template <typename X, typename Y, typename Z, typename... Zs> auto make_table(X x, Y y, Z z, Zs... zs) { auto cont = make_table(y, z, zs...); return vector<decltype(cont)>(x, cont); } template <class T> T cdiv(T a, T b){ assert(a >= 0 && b > 0); return (a+b-1)/b; } #define is_in(x, a, b) ((a) <= (x) && (x) < (b)) #define uni(x) sort(all(x)); x.erase(unique(all(x)), x.end()) #define slice(l, r) substr(l, r - l) typedef long long ll; typedef long double ld; using vl = vector<ll>; using vvl = vector<vl>; using pll = pair<ll, ll>; template <typename T> using PQ = priority_queue<T, vector<T>, greater<T>>; void check_input() { assert(cin.eof() == 0); int tmp; cin >> tmp; assert(cin.eof() == 1); } #if defined(PCM) || defined(LOCAL) #else #define dump(...) ; #define dump_1d(...) ; #define dump_2d(...) ; #define cerrendl ; #endif #endif /* HEADER_H */ //%snippet.end()% #line 2 "solve.cpp" template<class T=ll> using vec = vector<T>; struct Fast { Fast() { std::cin.tie(0); ios::sync_with_stdio(false); } } fast; int solve() { string s;cin>>s; int n = sz(s); int k = n; int sum = 0; vec<int> cnt(3); rep(i, n){ int v = s[i] - '0'; cnt[v%3]++; sum += v; } if (sum % 3 == 0){ cout << 0 << endl; return 0; } else if (sum % 3 == 1){ if (cnt[1] >= 1 && k>1) { cout << 1 << endl; return 0; } if (cnt[2] >= 2 && k>2) { cout << 2 << endl; return 0; } cout << -1 << endl; return 0; } else if (sum % 3 == 2){ if (cnt[2] >= 1 && k>1) { cout << 1 << endl; return 0; } if (cnt[1] >= 2 && k>2) { cout << 2 << endl; return 0; } cout << -1 << endl; return 0; } return 0; } int main(){/*{{{*/ solve(); #if defined(PCM) || defined(LOCAL) check_input(); #endif return 0; }/*}}}*/
#include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #include<string> using namespace std; signed main(){ ios::sync_with_stdio(false); string str; cin>>str; bool flag=true; for(int i=0;i<str.size();++i){ if(i&1){ if(str[i]<'A'||str[i]>'Z'){ flag=false; break; } } else{ if(str[i]<'a'||str[i]>'z'){ flag=false; break; } } } if(flag) cout<<"Yes\n"; else cout<<"No\n"; return 0; }
#include<iostream> using namespace std; typedef long long li; #define yn(i) print((i)?"Yes":"No") #define rep(i,n) for(int i=0;i<(n);i++) #define df 0 template<class T> void print(const T& t){ cout << t << "\n"; } template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); } int diff(string s){ int n=s.size(); rep(i,n){ if((s[i]<'a')!=(i%2==1)) return 0; } return 1; } int main(){ string s; cin >>s; yn(diff(s)); }
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #define f(i,a,b) for(ll i = a; i < (ll) b ; i++ ) #define af(i,a,b) for(ll i = a; i >= (ll) b ; i--) #define rep(i,a,b,k) for(ll i = a; i < (ll) b ; i+= k ) #define arep(i,a,b,k) for(ll i = a; i >= (ll) b ; i-= k) #define ff first #define ss second #define pb push_back #define mp make_pair #define all(a) a.begin(), a.end() #define sz(a) (ll) a.size() #define sor(a) sort( a.begin(), a.end() ) #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL) #define ller ios::sync_with_stdio(false);cin.tie(0) // policy-based using namespace std; typedef long long ll; // ll or ll typedef long double ld; typedef pair<ll,ll> ii ; typedef vector<ll> vi ; typedef vector<ii> vii ; const ll MAX = 3e5 + 20; const ll mod = 1e9 + 7; const ll inf = 2e18; // C function for extended Euclidean Algorithm ll gcdExtended(ll a, ll b, ll* x, ll* y){ // Base Case if (a == 0) { *x = 0, *y = 1; return b; } ll x1, y1; // To store results of recursive call ll gcd = gcdExtended(b % a, a, &x1, &y1); // Update x and y using results of recursive // call *x = y1 - (b / a) * x1; *y = x1; return gcd; } ll tc,x,y,p,q; ll modInverse(ll a, ll m){ ll x, y; ll g = gcdExtended(a, m, &x, &y); ll res = (x % m + m) % m; return res; } int main(){ fastio; cin >> tc; while(tc--){ cin >> x >> y >> p >> q; ll ans = inf; f(i,0,y){ f(j,0,q){ ll m1 = 2*(x+y),m2 = p+q,r1 = x+i,r2 = p + j; ll g = __gcd(m1,m2); if(r1%g != r2%g) continue; ll pp = m1/g, qq = m2/g,rr = (r1-r2)/g; ll alfa = ( (rr%pp + pp)%pp * modInverse(qq,pp))%pp; ll aux = m2*alfa + r2; ans = min(ans,m2*alfa + r2); } } if(ans == inf) cout << "infinity\n"; else cout << ans << endl; } return 0; }
#pragma GCC optimize(2) #pragma GCC optimize(3,"Ofast","inline") #include <bits/stdc++.h> #define inf 0x7fffffff #define ll long long //#define llu unsigned long long #define int long long //#define int __int128 //#define double long double //#define double long long #define re register int //#define void inline void #define eps 1e-8 //#define mod 1e9+7 #define ls(p) p<<1 #define rs(p) p<<1|1 #define pi acos(-1.0) #define pb push_back #define mk make_pair #define P pair < int , int > using namespace std; const int mod=1e9+7; const int M=1e8; const int N=5e5+5;//??????.???? 4e8 int n; struct node { int ver,edge,next; }e[N]; int tot,head[N]; int d[N],f[N]; int ret=1,ans; void add(int x,int y,int z) { e[++tot].ver=y; e[tot].edge=z; e[tot].next=head[x]; head[x]=tot; } void addedge(int x,int y,int z) { add(x,y,z);add(y,x,z); } void dfs(int x,int pre) { for(re i=head[x];i;i=e[i].next) { int y=e[i].ver; int z=e[i].edge; if(y==pre) continue; d[y]=d[x]^z; dfs(y,x); } } void solve() { cin>>n; for(re i=1;i<n;i++) { int x,y,z; scanf("%lld%lld%lld",&x,&y,&z); addedge(x,y,z); } dfs(1,1); for(re i=0;i<=60;i++) { int cnt=0; for(re j=1;j<=n;j++) if((d[j]>>i)&1) cnt++; ans=(ans+(ret*cnt)%mod*(n-cnt))%mod; ret=(ret*2)%mod; } cout<<ans<<endl; } signed main() { int T=1; // cin>>T; for(int index=1;index<=T;index++) { solve(); // puts(""); } return 0; } /* 5 10 -1 -5 -3 5 -1 1 */
#include <bits/stdc++.h> #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define rep(i,n) for(int i=0;i<(int)(n);i++) #define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++) #define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++) #define codefor int test;scanf("%d",&test);while(test--) #define INT(...) int __VA_ARGS__;in(__VA_ARGS__) #define LL(...) ll __VA_ARGS__;in(__VA_ARGS__) #define yes(ans) if(ans)printf("yes\n");else printf("no\n") #define Yes(ans) if(ans)printf("Yes\n");else printf("No\n") #define YES(ans) if(ans)printf("YES\n");else printf("NO\n") #define vector1d(type,name,...) vector<type>name(__VA_ARGS__) #define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__)) #define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__))) #define umap unordered_map #define uset unordered_set using namespace std; using ll = long long; const int MOD=1000000007; const int MOD2=998244353; const int INF=1<<30; const ll INF2=(ll)1<<60; //入力系 void scan(int& a){scanf("%d",&a);} void scan(long long& a){scanf("%lld",&a);} template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);} template<class T> void scan(T& a){cin>>a;} template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);} void in(){} template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);} //出力系 void print(const int& a){printf("%d",a);} void print(const long long& a){printf("%lld",a);} void print(const double& a){printf("%.15lf",a);} template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);} template<class T> void print(const T& a){cout<<a;} template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}} void out(){putchar('\n');} template<class T> void out(const T& t){print(t);putchar('\n');} template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);} //デバッグ系 template<class T> void dprint(const T& a){cerr<<a;} template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}} void debug(){cerr<<endl;} template<class T> void debug(const T& t){dprint(t);cerr<<endl;} template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);} ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; } ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; } ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;} template<class T> void chmax(T &a,const T b){if(b>a)a=b;} template<class T> void chmin(T &a,const T b){if(b<a)a=b;} int main(){ codefor{ INT(n); string s,t,u; cin>>s>>t>>u; string s1(n,'1'),s2(n,'0'); cout<<s1<<s2<<"1"<<endl; } }
#pragma GCC optimize(3,"Ofast","inline") #include<bits/stdc++.h> #define ll long long #define maxn 1000005 #define inf 1e9 #define pb push_back #define rep(i,a,b) for(int i=a;i<=b;i++) #define per(i,a,b) for(int i=a;i>=b;i--) using namespace std; inline int read() { int x=0,w=1; char c=getchar(); while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();} while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();} return w==1?x:-x; } int t,n; char s1[maxn],s2[maxn],s3[maxn]; int main() { //freopen("t1.in","r",stdin); cin>>t; while(t--) { cin>>n; scanf("%s%s%s",s1,s2,s3); printf("1"); rep(i,1,n) printf("0"); rep(i,1,n) printf("1"); puts(""); } return 0; }
#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) // 強さをY以上にしない // 経験値を最大化する // 経験値は最初0 // 強さは最初X // 強さをA倍にして、経験値を1増やす // 強さをB増やして、経験値を1増やす void solve(long long X, long long Y, long long A, long long B){ ll ans = 0; while(1){ if(X > Y/A) break; if(A*X >= Y) break; if(A*X >= X+B) break; X *= A; ans++; } ans += (Y-1-X) / B; cout << ans << endl; } int main(){ long long X; scanf("%lld",&X); long long Y; scanf("%lld",&Y); long long A; scanf("%lld",&A); long long B; scanf("%lld",&B); solve(X, Y, A, B); return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int n, a, b; cin >> n >> a >> b; cout << n-a+b; }
#include "bits/stdc++.h" using namespace std; #define FAST ios_base::sync_with_stdio(false); cin.tie(0); #define pb push_back #define eb emplace_back #define ins insert #define f first #define s second #define cbr cerr<<"hi\n" #define mmst(x, v) memset((x), v, sizeof ((x))) #define siz(x) ll(x.size()) #define all(x) (x).begin(), (x).end() #define lbd(x,y) (lower_bound(all(x),y)-x.begin()) #define ubd(x,y) (upper_bound(all(x),y)-x.begin()) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusive string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); } using ll=long long; using ld=long double; #define FOR(i,s,e) for(ll i=s;i<=ll(e);++i) #define DEC(i,s,e) for(ll i=s;i>=ll(e);--i) using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>; long long LLINF = 1e18; int INF = 1e9+1e6; #define MAXN (100006) ll n, A[MAXN], ans, mod=1e9+7, p2[MAXN], dp[MAXN][2]; ll mult(ll x,ll y) { x %= mod, y %= mod; return x * y % mod; } int main() { FAST cin>>n; FOR(i,1,n) cin>>A[i]; if(n==1) { cout<<A[1]<<'\n'; return 0; } else if(n==2) { cout<<A[1] * 2 % mod<<'\n'; return 0; } p2[0] = 1; FOR(i,1,MAXN-1) p2[i]=p2[i-1]*2%mod; dp[0][0] = 1; FOR(i,1,n) { dp[i][0] = dp[i-1][0] + dp[i-1][1], dp[i][0] %= mod; dp[i][1] = dp[i-1][0]; // dp[i][2] = dp[i-1][2] * 2 + dp[i-1][1], dp[i][0] %= mod; } FOR(i,1,n) { if(i == 1) { ans += (dp[n-1][0] + dp[n-1][1]) % mod * A[i] % mod, ans %= mod; } else { ans += mult(dp[n-i][0] + dp[n-i][1], dp[i-2][0] + dp[i-2][1]) % mod * A[i] % mod, ans %= mod; ans -= mult(dp[n-i][0], dp[i-2][0]) % mod * A[i] % mod, ans += mod, ans %= mod; } } cout<<ans<<'\n'; }
#include <iostream> #include <vector> #include <algorithm> using namespace std; typedef int64_t ll; const ll maxOne = 1'000'000'007; ll add(ll a, ll b){ if(a<0){ a += maxOne; } if(b<0){ b += maxOne; } return (a+b)%maxOne; } ll mul(ll a, ll b){ if(a<0){ a += maxOne; } if(b<0){ b += maxOne; } return (a*b)%maxOne; } ll sub(ll a, ll b){ if(a<b){ a += maxOne; } return (a-b)%maxOne; } int main() { ll n; cin >> n; vector<ll> vals(n); for(auto& val:vals){ cin >> val; } if(n==1){ cout << vals[0] << endl; return 0; } ll dpp = vals[0]; ll dps = 0; ll cp = 1; ll cs = 0; for(ll i=1; i<n; i++){ ll nextDpp = add(dpp, mul(vals[i], add(cp, cs))); nextDpp = add(nextDpp, dps); ll nextDps = sub(dpp, mul(vals[i], cp)); ll nextCp = add(cp, cs); ll nextCs = cp; dpp = nextDpp; dps = nextDps; cp = nextCp; cs = nextCs; } cout << add(dpp, dps) << endl; return 0; }
#include <iostream> using namespace std; int main(void){ double x,y,z;cin >> x >> y >> z; double ta=y/x; for(double i=0;;i++){ double s=i/z; if(s>=ta){ cout << i-1 << endl; return 0; } } }
#pragma GCC target ("avx2") #pragma GCC optimize ("unroll-loops") #pragma GCC optimize ("O3") #include "bits/stdc++.h" #include <unordered_set> #include <unordered_map> #include <random> using namespace std; typedef long long ll; const ll MOD = /*1'000'000'007LL;*/ 998'244'353LL; #define pb push_back #define mp make_pair #define all(x) (x).begin(), (x).end() #define rep(i, n) for(int (i)=0; (i)<(n); (i)++) const int dy[4]={ -1,0,1,0 }; const int dx[4]={ 0,-1,0,1 }; int N; ll H[200000]; int M; ll W[200000]; signed main(){ cin >> N >> M; rep(i, N) cin >> H[i]; rep(i, M) cin >> W[i]; sort(H, H+N); sort(W, W+M); ll tmp = 0; rep(i, N){ if(i%2 == 0) tmp += H[i]; else tmp -= H[i]; } ll ans = LLONG_MAX; int j = 0; rep(i, M){ while(j < N && H[j] < W[i]){ if(j%2 == 0) tmp -= 2*H[j]; else tmp += 2*H[j]; j++; } //cout << tmp << " " << (j%2 == 0 ? -W[i] : W[i]) << endl; ans = min(ans, tmp + (j%2 == 0 ? -W[i] : W[i])); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; // #define int long long const int N=1005; int par[2*N]; int find(int v){ if(par[v]==v)return v; return par[v]=find(par[v]); } bool join(int u,int v){ u=find(u),v=find(v); if(rand()%2)swap(u,v); par[v]=u; return u!=v; } int32_t main(){ ios::sync_with_stdio(0),cin.tie(0); iota(par,par+2*N,0); int h,w; cin >> h >> w; int g[h][w]; for(int i=0;i<h;i++){ for(int j=0;j<w;j++){ char ch; cin >> ch; if(ch=='#')join(i,N+j); } } join(0,h-1); join(0,N); join(0,N+w-1); int ans=2e9; set <int> s; for(int i=0;i<h;i++) s.insert(find(i)); ans=min(ans,(int)s.size()-1); s.clear(); for(int i=0;i<w;i++) s.insert(find(N+i)); ans=min(ans,(int)s.size()-1); cout << ans; }
// #include<bits/stdc++.h> using namespace std; #define PB push_back #define f fiCrst #define s second #define what_is(x) cerr << #x << " is " << x << endl; typedef long long ll; typedef pair<ll, ll> pll; typedef pair<int, int> pii; const int INF = 1000000007; const ll MOD = 998244353; int dp[3001][3001]; void solve_test() { int n, k; cin >> n >> k; dp[0][0] = 1; for(int i=1; i<=n; i++) { for(int j=n; j>=1; j--) { if(j > i) continue; dp[i][j] = dp[i-1][j-1]; if(j * 2 <= i) dp[i][j] = (dp[i][j] + dp[i][2*j]) % MOD; } } cout << dp[n][k]; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); int tests; tests = 1; //cin >> tests; while(tests--) { solve_test(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define mod 10000007 #define F for(int i=0;i<n;i++) #define raftaar ios_base::sync_with_stdio(false);cin.tie(NULL); #define shuru int t;cin>>t;while(t--) int SieveOfEratosthenes(int n) { bool prime[n + 1];int c=0; memset(prime, true, sizeof(prime)); for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) prime[i] = false; } } for (int p = 2; p <= n; p++){ if (prime[p]) c++;} return c; } signed main() { // shuru{ // int c=0; string s;cin>>s;string a; reverse(s.begin(),s.end()); for(int i=0;i<s.size();i++){ if(s[i]=='9') s[i]='6'; else if(s[i]=='6') s[i]='9'; else continue; } cout<<s<<endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define mp make_pair #define fr first #define sc second int n; int p[502]; vector<int> ret; void add(int i){ ret.push_back(i); swap(p[i],p[i+1]); } void solve(int k){ //cerr<<k<<" "<<ret.size()<<endl; if(k==1)return; if(k==2){ if(p[0]!=0)add(0); return; } if(k==3){ while(p[2]!=2){ add(0); add(1); } solve(2); return; } int loc=0; for(int i=0;i<k;i++){ if(p[i]==k-1){ loc=i; break; } } if(loc==k-1){ solve(k-1); return; } if(loc%2==0){ while(loc!=k-1){ add(loc); loc++; } if(ret.size()%2!=0)add(1); solve(k-1); return; } else { if(loc>=3)add(loc-3); else add(loc+1); while(loc!=k-1){ add(loc); loc++; } if(ret.size()%2!=0)add(1); solve(k-1); return; } } int main(){ int T; scanf("%d",&T); for(;T>0;T--){ scanf("%d",&n); for(int i=0;i<n;i++){ scanf("%d",&p[i]); p[i]--; } ret.clear(); solve(n); printf("%d\n",(int)ret.size()); if(ret.size()==0)puts(""); else { for(int i=0;i<ret.size();i++){ printf("%d%c",ret[i]+1,(i+1==ret.size())?'\n':' '); } } } }
#include <bits/stdc++.h> #define ll long long #define ld long double #define pb push_back #define p_b pop_back using namespace std; int main(){ int n, sum = 0; cin >> n; vector<int> v1, v2; for(int i = 0; i < n; i++){ int k; cin >> k; v1.pb(k); } for(int i = 0; i < n; i++){ int k; cin >> k; v2.pb(k); } for(int i = 0; i < n; i++){ sum += v1[i]*v2[i]; } if(sum == 0){ cout << "Yes\n"; } else{ cout << "No\n"; } return 0; }
// // main.cpp // rferf // // Created by Harshita Hazarika on 28/12/20. // Copyright © 2020 Harshita Hazarika. All rights reserved. // #include <algorithm> #include <bitset> #include <deque> #include <iostream> #include <iterator> #include <map> #include<climits> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #include <unordered_map> #include<cmath> #include <unordered_set> using namespace std; typedef long long int ll; ll power(ll x, ll y, ll p) { ll res = 1; x = x % p; if (x == 0) return 0; while (y > 0){ if (y & 1) res = (res*x) % p; y = y>>1; x = (x*x) % p; } return res; } ll modInverse(ll n, ll p) { return power(n, p-2, p); } void solve() { ll n; cin>>n; string str=""; set<string>st; bool flag=false; for(ll i=0;i<n;i++){ string s; cin>>s; if(!flag){ if(s[0]=='!'){ if(st.find(s.substr(1))!=st.end()){ str=s.substr(1); flag=true; } } else{ if(st.find("!"+s)!=st.end()){ str=s; flag=true; } } st.insert(s); } } if(flag){ cout<<str<<"\n"; } else{ cout<<"satisfiable\n"; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // int t; // cin >> t; // while(t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define sim template < class c #define ris return * this #define dor > debug & operator << #define eni(x) sim > typename \ enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c> {i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { #ifdef LOCAL ~debug() { cerr << endl; } eni( != ) cerr << boolalpha << i; ris; } eni( == ) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } #else sim dor(const c&) { ris; } #endif }; #define imie(...)"Line: "<<__LINE__<<" -> " " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// #define int long long vector<int> a; int sz; int calc(vector<int> &arr, bool pari){ map<int, int> mappa; int ans = 0; int n = (int)arr.size(); vector<int> pref(n + 1); for(int i = 1; i <= n; i++){ if(i == 1){ pref[i] = arr[i - 1]; } else{ pref[i] = arr[i - 1] + pref[i - 1]; } } debug() << imie(arr) imie(pref) imie(pari); for(int i = 1; i <= n; i++){ if(pref[i] == 0){ ans++; } int posizione = sz + 1; if(pari){ posizione = i * 2 + 1; } else{ posizione = i * 2 + 2; } if(posizione <= sz){ int currp = pref[i] + a[posizione]; debug() << imie(posizione) imie(a[posizione]) imie(i) imie(pari); ans += mappa[currp]; ans += (currp == 0 ? 1 : 0); } ans += mappa[pref[i]]; mappa[pref[i]]++; } return ans; } int32_t main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; sz = n; vector<int> dispari, pari; a.resize(n + 1); for(int i = 1; i <= n; i++){ cin >> a[i]; } for(int i = 1; i < n; i += 2){ dispari.push_back(a[i] - a[i + 1]); } for(int i = 2; i < n; i += 2){ pari.push_back(a[i] - a[i + 1]); } debug() << imie(dispari) imie(pari); int ans = calc(pari, false) + calc(dispari, true); cout << ans << '\n'; }
#include <bits/stdc++.h> using namespace std; #define M1 1000000007 #define M2 998244353 #define INF 1e18 #define ll long long #define pll pair<ll,ll> #define REP(i,a,b) for(ll i=a;i<b;i++) #define REPR(i,a,b) for(ll i=b-1;i>=a;i--) #define forr(i,n) for(ll i=0;i<n;i++) #define F first #define S second #define pb push_back #define DB pop_back #define mp make_pair #define MT make_tuple #define V(a) vector<a> #define vi vector<int> #define vlli vector <long long> #define endl '\n' #define ce(ele) cout<<ele<<' ' #define cs(ele) cout<<ele<<'\n' #define CASE(t) ll t; cin>>t; while(t--) /********************************************************************/ const double pi = 3.1415926535; /********************************************************************/ //FAST IO// void FAST() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } /********************************************************************/ int main() { FAST(); int n; cin>>n; vi a(n); forr(i,n) {cin>>a[i]; } map <int, int> M; for (int i=0; i<n; i++) { int x=a[i]; for (int i=2; i*i<x; i++) { if (x%i==0){ M[i]++;} while (x%i==0) {x/=i; } } if (x!=0 && x!=1){M[x]++; } } auto it=M.begin(); int stor=-1; int ans=0; while (it !=M.end()) { if ((*it).S > ans) {stor=(*it).F; } ans=max(ans, (*it).S); it++; } cout<<stor<<endl; }
#include <iostream> #include <string> #include <vector> #include <deque> #include <queue> #include <algorithm> #include <iomanip> #include <set> #include <map> #include <bitset> #include <cmath> #include <functional> using namespace std; #define REP(i,n) for(ll (i) = (0);(i) < (n);++i) #define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i) #define PB push_back #define EB emplace_back #define MP make_pair #define FI first #define SE second #define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl;} #define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}} #define ALL(v) v.begin(),v.end() #define Decimal fixed<<setprecision(20) #define INF 1000000000 #define LLINF 1000000000000000000LL #define MOD 1000000007LL typedef long long ll; typedef pair<ll,ll> P; ll tate[2002][2002]; ll yoko[2002][2002]; ll nana[2002][2002]; ll dp[2002][2002]; char mp[2002][2002]; void mod_add(ll &a, ll b) { a += b; a %= MOD; } int main(){ cin.tie(0);cout.tie(0);ios::sync_with_stdio(false); ll h, w;cin >> h >> w; REP(i, h) { REP(j, w) { cin >> mp[i][j]; } } dp[0][0] = 1; tate[0][0] = 1; yoko[0][0] = 1; nana[0][0] = 1; REP(i, h) { REP(j, w) { if (mp[i][j] == '#') continue; if (i == 0 && j == 0) continue; if (i > 0) mod_add(dp[i][j], tate[i-1][j]); if (j > 0) mod_add(dp[i][j], yoko[i][j-1]); if (i > 0 && j > 0) mod_add(dp[i][j], nana[i-1][j-1]); tate[i][j] += dp[i][j]; yoko[i][j] += dp[i][j]; nana[i][j] += dp[i][j]; if (i > 0) { mod_add(tate[i][j], tate[i-1][j]); } if (j > 0) { mod_add(yoko[i][j], yoko[i][j-1]); } if (i > 0 && j > 0) { mod_add(nana[i][j], nana[i-1][j-1]); } } } // SHOW2d(dp, h, w); cout << dp[h-1][w-1] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define ll long long #define endl "\n" #define V vector<ll> #define VT(A) vector<A> #define P pair<ll, ll> #define ST(A) set<A> #define US(A) unordered_set<A> #define M map<ll, ll> #define MT(A,B) map<A,B> #define UM(A,B) unordered_map<A,B> #define PQ(A) priority_queue<A> #define HP(A) priority_queue<A, vector<int>, greater<A>> #define F first #define S second #define T top() #define B back() #define PU push #define PO pop() #define PB push_back #define POB pop_back #define EB emplace_back #define MP make_pair #define MOD 1e9 + 7 #define INF 100000000000000003 #define IN(a) cin >> (a) #define PE(a) cout << (a) << endl #define PS(a) cout << (a) << " " #define PSS(a,b) cout << (a) << " " << (b) << endl; #define MAX(a, b) ((a) < (b) ? (b) : (a)) #define MIN(a, b) ((a) > (b) ? (b) : (a)) #define ALL(v) (v).begin(), (v).end() #define FOR(a, b, c, s) for (ll (a) = (b); (a) < (c); (a)+=s) #define FORL(a, b, c, s) for (ll (a) = (b); (a) <= (c); (a)+=s) #define FORR(a, b, c, s) for (ll (a) = (b); (a) >= (c); (a)-=s) #define FORA(i, a) for(auto& (i) : (a)) #define N 1e7+10 void init_code() { fast; //seive(); } void solve() { // Jai Shree Ram ll h,w,x,y; cin >> h >> w >> x >> y; x--, y--; vector<string> s(h); FOR(i,0,h,1) IN(s[i]); ll res = -3; for(ll i=x; i<h && s[i][y] == '.'; i++) res++; for(ll i=x; i>=0 && s[i][y] == '.'; i--) res++; for(ll j=y; j<w && s[x][j] == '.'; j++) res++; for(ll j=y; j>=0 && s[x][j] == '.'; j--) res++; PE(res); } int main() { init_code(); solve(); return 0; }
#include<bits/stdc++.h> using ll = long long; #define REP(i, n) for (ll i = 0; (i) < ll(n); ++ (i)) #define FOR(i, m, n) for (ll i = (m); (i) <= ll(n); ++ (i)) #define REPR(i, n) for (ll i = ll(n) - 1; (i) >= 0; -- (i)) #define FOR3R(i, m, n) for (ll i = ll(n) - 1; (i) >= ll(m); -- (i)) #define ALL(x) x.begin(),x.end() #define INF (int)1e9 //10^9:∞ #define LLINF (long long)1e12 #define MOD (int)1e9+7 //10^9+7:合同式の法 #define PI 3.141592653589 #define PB push_back #define F first #define S second #define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;} #define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;} #define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;} #define Graph vector<vector<int>> #define PII pair<int,int> #define VI vector<int> #define VVI vector<vector<int>> //VVI a(n, vector<int>(m)); #define VPII vector<pair<int,int>> #define DDD fixed<<setprecision(10) template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> T GCD(T a, T b) { if (b == 0) return a; else return GCD(b, a % b); } template <class T> inline T LCM(T a, T b) { return (a * b) / GCD(a, b); } using namespace std; signed main(){ ios::sync_with_stdio(false); cin.tie(nullptr); //小数の桁数の出力指定 //cout<<fixed<<setprecision(10); int n; cin >> n; vector<ll> a(n+1,0), b(n+1,0), bt(n+1,0); int t; REP(i,n) { cin >> t; ++a[t]; } REP(i,n){ cin >> b[i]; } REP(i,n) { cin >> t; ++bt[b[t-1]]; } ll c = 0; REP(i,n+1){ c += a[i] * bt[i]; } cout << c << endl; }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i, n) for (ll i = 0; i < (ll)(n); i++) #define REPR(i, n) for (ll i = (n); i >= 0; i--) #define FOR(i, m, n) for (ll i = (m); i < (ll)(n); i++) #define BIT(bit, n) for (int bit = 0; bit < (1 << (n)); ++bit) #define INF 1000000000 //配列 vector<型> 配列名(要素数, 初期値); //二次元配列 vector<vector<型>> 配列名(要素数縦,vector<int>(要素数横, 初期値)) //配列のサイズ(二次元縦) 配列名.size(), 二次元横 配列名[0].size() // 1秒間のforループは10^8くらい //小数点桁数 cout << fixed << setprecision(20) << // bit全探索 条件判定 if(bit & (1 << n)) int main() { int N; cin >> N; vector<pair<ll, ll>> x(N); vector<pair<ll, ll>> y(N); vector<pair<ll, ll>> ans(6); vector<pair<ll, ll>> check(6); REP(i, N) { cin >> x[i].first >> y[i].first; x[i].second = i; y[i].second = i; } sort(x.begin(), x.end()); sort(y.begin(), y.end()); ans[0].first = abs(x[0].first - x[N - 1].first); ans[1].first = abs(x[0].first - x[N - 2].first); ans[2].first = abs(x[1].first - x[N - 1].first); ans[3].first = abs(y[0].first - y[N - 1].first); ans[4].first = abs(y[0].first - y[N - 2].first); ans[5].first = abs(y[1].first - y[N - 1].first); check[0].first = x[0].second; check[1].first = x[0].second; check[2].first = x[1].second; check[3].first = y[0].second; check[4].first = y[0].second; check[5].first = y[1].second; check[0].second = x[N - 1].second; check[1].second = x[N - 2].second; check[2].second = x[N - 1].second; check[3].second = y[N - 1].second; check[4].second = y[N - 2].second; check[5].second = y[N - 1].second; REP(i, 6) { ans[i].second = i; } sort(ans.begin(), ans.end()); if (check[ans[4].second].first != check[ans[5].second].first || check[ans[4].second].second != check[ans[5].second].second) { cout << ans[4].first << endl; } else { cout << ans[3].first << endl; } }
#include <bits/stdc++.h> using namespace std; using ll = long long; using PII = pair<int, int>; using VI = vector<int>; #define fst first #define snd second template <typename T> istream &operator>>(istream &in, vector<T> &v) { for (auto &x : v) in >> x; return in; } template <typename T> ostream &operator<<(ostream &out, const vector<T> &v) { for (const auto &x : v) out << x << ' '; return out; } template <typename T> vector<T> scanl1(function<T(T, T)> f, const vector<T> &v) { vector<T> r(v.size()); r[0] = v[0]; for (int i = 1; i < (int)v.size(); i++) { r[i] = f(r[i - 1], v[i]); } return r; } template <typename T, typename A = T, typename B = T> vector<T> zipWith(function<T(A, B)> f, const vector<A> &va, const vector<B> &vb) { vector<T> vt(min(va.size(), vb.size())); for (int i = 0; i < (int)vt.size(); i++) { vt[i] = f(va[i], vb[i]); } return vt; } int main() { #ifdef LOCAL_EXEC freopen("sample.in", "r", stdin); freopen("sample.out", "w", stdout); #else ios_base::sync_with_stdio(false); cin.tie(NULL); #endif int n; cin >> n; vector<ll> a(n), b(n); cin >> a >> b; a = scanl1<ll>([](ll a, ll b) { return max(a, b); }, a); a = zipWith<ll, ll, ll>([](ll a, ll b) -> ll { return a * b; }, a, b); a = scanl1<ll>([](ll a, ll b) { return max(a, b); }, a); cout << a << endl; return 0; }
#include<iostream> #include<cstdio> #include<queue> #define int long long #define uc getchar() #define ph putchar #define R register #define CN const #define rint R int #define cint CN int #define ps ph(' ') #define pe ph('\n') using namespace std; cint inf=1e9+7; cint mix=2e5+5; inline int in(); inline void out(rint y); int n=in(),a[mix],mx,ans; #undef int int main() { #define int long long for(rint i=1;i<=n;++i)a[i]=in(); for(rint i=1;i<=n;++i){ mx=max(mx,a[i]); out(ans=max(ans,mx*in())),pe; } } inline int in() { rint x=0; R bool f=0; R char s=uc; while((s<'0'||'9'<s)&&s!='-')s=uc; if(s=='-')f=1,s=uc; while('0'<=s&&s<='9')(x*=10)+=s^48,s=uc; return f?-x:x; } inline void out(rint x) { if(x<0)ph('-'),x=-x; rint y=x/10; if(y)out(y); ph((x-y*10)^48); }
#include <bits/stdc++.h> #define debug(x) cout << "[" << #x << " = " << x << "] " #define ff first #define ss second #define endl '\n' #define INF 1e9 using namespace std; using ll = long long; using ld = long double; using pii = pair<int,int>; using vi = vector<int>; /*wa? coloca long long que passa; testar casos, n = 0? n = 1? dp: min(solve(l+1,r),solve(l,r-1))? Uma resposta ótima pode ter tamanho 2?*/ void printa(string s, int cont){ int n = s.size() / 2; if(cont & 1){ for(int i = 0; i < n; i++) swap(s[i], s[i+n]); } cout << s << endl; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n; string s; cin >> n >> s; int q, cont = 0; cin >> q; while(q--){ int t, a, b; cin >> t >> a >> b; if(t == 1){ //troca s[a] por s[b] if(a <= n && b <= n && (cont & 1) ){ swap(s[a-1+n],s[b-1+n]); } else if(a > n && b > n && (cont & 1) ){ swap(s[a-1-n], s[b-1-n]); } else { if(cont % 2 == 0) swap(s[a-1], s[b-1]); else swap(s[b-1-n], s[a-1+n]); } } else { //troca os n primeiros com os n ultimos cont++; } } printa(s, cont); }
#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 fi first #define se second #define mp make_pair #define pb push_back #define fbo find_by_order #define ook order_of_key typedef long long ll; typedef pair<ll,ll> ii; typedef vector<ll> vi; typedef long double ld; typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds; vector<int> fact; vector<int> ifact; vector<int> inv; vector<int> pow2; const int MOD = (1e9 + 7); int add(int a, int b) { a+=b; while(a>=MOD) a-=MOD; return a; } void radd(int &a, int b) { a=add(a,b); } int mult(int a, int b) { return (a*1LL*b)%MOD; } void rmult(int &a, int b) { a=mult(a,b); } int modpow(int a, int b) { int r=1; while(b) { if(b&1) r=mult(r,a); a=mult(a,a); b>>=1; } return r; } int choose(int a, int b) { if(a<b) return 0; if(b==0) return 1; if(a==b) return 1; return mult(fact[a],mult(ifact[b],ifact[a-b])); } int inverse(int a) { return modpow(a,MOD-2); } char b[2][2]; int a[2][2]; int c[2][2]; int dp[1111][2]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin>>n; if(n==2) { cout<<1<<'\n'; return 0; } cin>>b[0][0]>>b[0][1]>>b[1][0]>>b[1][1]; for(int i=0;i<2;i++) { for(int j=0;j<2;j++) { a[i][j]=b[i][j]-'A'; } } if(a[0][1]==0) { for(int i=0;i<2;i++) { for(int j=0;j<2;j++) { c[i][j]=(a[j^1][i^1]^1); } } for(int i=0;i<2;i++) { for(int j=0;j<2;j++) { a[i][j]=c[i][j]; } } } //assume A...B B if(a[1][1]==1) { cout<<1<<'\n'; return 0; } //assume B...A B if(a[1][0]==1) { dp[1][1]=1; //length 1, end with 0 for(int i=2;i<=n;i++) { dp[i][0]=add(dp[i-1][0],dp[i-1][1]); dp[i][1]=dp[i-1][0]; } cout<<dp[n][0]<<'\n'; } else { //n>2 cout<<modpow(2,n-3)<<'\n'; } }
#include <bits/stdc++.h> using namespace std; int main(){ int N; cin >> N; vector<int> A; for(int i = 0; i < N; i++){ int x; cin >> x; A.push_back(x); } // Manhattan int64_t M = 0; for(int i = 0; i < N; i++){ M += abs(A.at(i)); } cout << M << endl; // Eucrid int64_t t = 0; double E = 0.00; for(int i = 0; i < N; i++){ t += pow(A.at(i), 2); } E = sqrt(t); cout << fixed << setprecision(15); cout << E << endl; // Chebyshev for(int i = 0; i < N; i++){ A.at(i) = abs(A.at(i)); } sort(A.begin(), A.end()); cout << A.at(N - 1) << endl; return 0; }
#include <iostream> #include <math.h> #include <iomanip> using namespace std; long long arr[100005]; int main(){ int n; cin >> n; int i; long long ans = 0; for(i=0; i<n; i++){ cin >> arr[i]; } for(i=0; i<n; i++){ if(arr[i]<0){ ans += -arr[i]; }else{ ans += arr[i]; } } cout << ans << endl; long long ans1= 0; for(i=0; i<n; i++){ ans1 += arr[i]*arr[i]; } cout << fixed << setprecision(20) << sqrt(ans1) << endl; long long ans2=0; for(int i=0; i<n; i++){ if(arr[i]>ans2 || (-arr[i]>ans2)){ if(arr[i]<0){ ans2 = -arr[i]; } else{ ans2 = arr[i]; } } } cout << ans2 << endl; return 0; }
//#include <atcoder/all> //using namespace atcoder; #include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i, n) for(int i=0; i<n; i++) #define REPR(i, n) for(int i=n-1; i>=0; i--) #define FOR(i, m, n) for(int i=m; i<n; i++) #define ALL(v) v.begin(), v.end() #define bit(n) (1LL<<(n)) #define FIX(d) fixed << setprecision(d) using P = pair<int, int>; using LP = pair<ll, ll>; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const int INF = 1e9; const ll LINF = (1LL<<60); unsigned int xor128(){ static unsigned int x=123456789,y=362436069,z=521288629,w=88675123; unsigned int t = (x^(x<<11)); x=y; y=z; z=w; return( w=(w^(w>>19))^(t^(t>>8)) ); } int n; int cx[200], cy[200], r[200]; int a[200], b[200], c[200], d[200]; ll score(){ double sc = 0.0; REP(i,n){ int area = (c[i]-a[i]) * (d[i]-b[i]); double tmp = 1.0 - (double)min(area,r[i])/max(area,r[i]); sc += 1e9 - 1e9*tmp*tmp; } return (ll)round(sc/n); } ll score_dx(int ind){ int area = (c[ind]-a[ind]+1) * (d[ind]-b[ind]); double tmp = 1.0 - (double)min(area,r[ind])/max(area,r[ind]); tmp = 1e9 - 1e9*tmp*tmp; return (ll)round(tmp/n); } ll score_dy(int ind){ int area = (c[ind]-a[ind]) * (d[ind]-b[ind]+1); double tmp = 1.0 - (double)min(area,r[ind])/max(area,r[ind]); tmp = 1e9 - 1e9*tmp*tmp; return (ll)round(tmp/n); } void init(){ REP(i,n){ a[i] = cx[i]; b[i] = cy[i]; c[i] = cx[i]+1; d[i] = cy[i]+1; } } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n; REP(i,n) cin >> cx[i] >> cy[i] >> r[i]; int ti = clock(); init(); ll mx = score(); //cout << mx << endl; while(clock() - ti < 490 * CLOCKS_PER_SEC / 100){ REP(loop, 300){ int ind = xor128() % n; int xy = xor128() % 2; bool minus = false, plus = false; if(xy==0){ REP(i,n){ if(i==ind) continue; if(max(a[i],a[ind]-1)<min(c[i],c[ind]) && max(b[i],b[ind])<min(d[i],d[ind])){ minus = true; } if(max(a[i],a[ind])<min(c[i],c[ind]+1) && max(b[i],b[ind])<min(d[i],d[ind])){ plus = true; } } if(c[ind]<10000 && !plus){ c[ind]++; if(!chmax(mx, mx+score_dx(ind))) c[ind]--; }else if(a[ind]>0 && !minus){ a[ind]--; if(!chmax(mx, mx+score_dx(ind))) a[ind]++; } }else{ REP(i,n){ if(i==ind) continue; if(max(a[i],a[ind])<min(c[i],c[ind]) && max(b[i],b[ind]-1)<min(d[i],d[ind])){ minus = true; } if(max(a[i],a[ind])<min(c[i],c[ind]) && max(b[i],b[ind])<min(d[i],d[ind]+1)){ plus = true; } } if(d[ind]<10000 && !plus){ d[ind]++; if(!chmax(mx, mx+score_dy(ind))) d[ind]--; }else if(b[ind]>0 && !minus){ b[ind]--; if(!chmax(mx, mx+score_dy(ind))) b[ind]++; } } } //cout << mx << endl; } //cout << mx << endl; REP(i,n) cout << a[i] << " " << b[i] << " " << c[i] << " " << d[i] << '\n'; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ll, int> pli; typedef pair<int, ll> pil; typedef vector<pii> vii; typedef vector<pil> vil; typedef vector<pli> vli; typedef vector<pll> vll; #define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define ff first #define ss second #define pb push_back #define mp make_pair #define sz size() #define all(a) a.begin(), a.end() #define mem(a, b) memset(a, b, sizeof(a)) #define f0(i,n) for(int i=0;i<(n);i++) #define f1(i,n) for(int i=1;i<=(n);i++) #define f2(i,a,n) for(int i=(a);i<=(n);i++) #define fr(i,n,a) for(int i=(n);i>=(a);i--) #define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c)) #define nl "\n" const int INF = 1e9 + 5; const int MXN = 2e5 + 5; const ll LMXN = 1e14; const int MOD = 1e9 + 7; ll cs = 0; void solve(){ int n; cin >> n; ll ans1 = 0, ans3 = 0; double ans2 = 0; f0(i, n){ ll a; cin >> a; ans1 += abs(a); ans2 += abs(a)*abs(a); ans3 = max(ans3, abs(a)); } cout << fixed << setprecision(15); cout << ans1 << nl; cout << sqrt(ans2) << nl; cout << ans3 << nl; } int main(){ //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); //FIO; ll t = 1; //cin >> t; while(t--){ solve(); } return 0; }
#include <bits/stdc++.h> // #include <atcoder/all> // using namespace atcoder; #define _overload3(_1,_2,_3,name,...) name #define _rep(i,n) repi(i,0,n) #define repi(i,a,b) for(int i=int(a);i<int(b);++i) #define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__) #define rrep(i,n) for(int i=int(n-1);i>=int(0);--i) #define fore(i,a) for(auto &i:a) #define all(x) x.begin(),x.end() #define sz(x) ((int)(x).size()) #define bp(x) (__builtin_popcount((long long)(x))) #define pb push_back #define eb emplace_back #define mp make_pair #define V vector #define P pair<int,int> #define TP tuple<int,int,int> #define F first #define S second template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } using ll = long long; using ld = long double; using namespace std; const int INF = 1001001001; const ll INFL = 1001001001001001001; const int MAX = 2e6+1; int main() { ll a,b;cin>>a>>b; if(a>b)swap(a,b); ll ans=1; rep(i,2,b+1){ if(ceil(1.0*a/i)*i+i<=b)ans=i; } cout<<ans<<endl; return 0; }
#include<cstdio>//JZM YYDS!!! #include<cstring> #include<iostream> #include<algorithm> #include<cmath> #include<vector> #include<queue> #include<stack> #include<map> #define ll long long #define MAXN 200005 #define uns unsigned #define MOD 998244353ll #define INF 0x7f7f7f7f #pragma GCC optimize("O2") using namespace std; inline ll read(){ ll x=0;bool f=1;char s=getchar(); while((s<'0'||s>'9')&&s>0){if(s=='-')f^=1;s=getchar();} while(s>='0'&&s<='9')x=(x<<1)+(x<<3)+s-'0',s=getchar(); return f?x:-x; } ll x,y,p,q; inline ll exgcd(ll a,ll b,ll&x,ll&y){ if(b==0){x=1,y=0;return a;} ll res=exgcd(b,a%b,y,x); y-=a/b*x;return res; } signed main() { for(int T=read();T--;){ x=read(),y=read(),p=read(),q=read(); ll md=(x+y)<<1,lim=md*(p+q)+1,ans=lim; ll b=p,a=p+q,K,f,g=exgcd(p+q,md,K,f); for(ll i=x;i<x+y;i++){ ll c=((i-b)%md+md)%md,k=K; if(c%g!=0)continue; c/=g,k=(k*c%md+md)%(md/g); if((k*a+b)%md>=x&&(k*a+b)%md<x+y)ans=min(ans,k*a+b); } md=p+q,b=x,a=(x+y)<<1,g=exgcd((x+y)<<1,md,K,f); for(ll i=p;i<p+q;i++){ ll c=((i-b)%md+md)%md,k=K; if(c%g!=0)continue; c/=g,k=(k*c%md+md)%(md/g); if((k*a+b)%md>=p&&(k*a+b)%md<p+q)ans=min(ans,k*a+b); } if(ans>=lim)printf("infinity\n"); else printf("%lld\n",ans); } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) using ll = long long; using P = pair<int,int>; int main() { int n; cin>>n; vector<int> a(n), b(n), p(n); rep(i, n) cin>>a[i]; rep(i, n) cin>>b[i]; rep(i, n){cin>>p[i]; p[i]--;} bool ok=true; rep(i, n) if(i!=p[i] && a[i]<=b[p[i]]) ok=false; if(!ok){ cout<<(-1)<<endl; return 0; } vector<int> r(n); rep(i, n) r[p[i]]=i; vector<P> li; rep(i, n) li.push_back(P(b[i], i)); sort(li.rbegin(), li.rend()); vector<P> ans; for(auto t : li){ int i=r[t.second]; int j=p[i]; if(i==j) continue; ans.push_back(P(i, j)); swap(p[i], p[j]); swap(r[p[i]], r[p[j]]); } cout<<ans.size()<<endl; for(auto t : ans) cout<<(t.first+1)<<" "<<(t.second+1)<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; string to_string(string s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(bool b) { return (b ? "true" : "false"); } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif /* sorry, this is the bare minimum :'( */ using ll = long long; using ii = pair<int, int>; using vi = vector<int>; #define all(v) begin(v), end(v) #define sz(v) (int)(v).size() #define fi first #define se second int main(int argc, char const *argv[]) { cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit); #ifdef LOCAL freopen("in", "r", stdin); #endif int n; cin >> n; vi a(n), b(n), p(n); for(int& x : a) cin >> x, x--; for(int& x : b) cin >> x, x--; for(int& x : p) cin >> x, x--; debug(a, b, p); vi host(n), to(n), what(n), from(n); set<ii> st; for(int i = 0; i < n; ++i) { from[p[i]] = i; to[i] = p[i]; what[i] = b[p[i]]; if(p[i] != i) { st.insert(ii(what[i], i)); } } vector<ii> ans; while(st.size()) { debug(st); int y = st.begin() -> second; st.erase(st.begin()); if(from[y] == y) continue; int x = from[y]; if(what[x] >= a[x] or what[y] >= a[y]) { cout << "-1" << endl; exit(0); } ans.emplace_back(x+1, y+1); st.erase(ii(what[x], x)); what[x] = what[y]; st.insert(ii(what[x], x)); to[x] = to[y]; from[to[x]] = x; } cout << sz(ans) << "\n"; for(ii& pa : ans) { cout << pa.fi << ' ' << pa.se << "\n"; } return 0; }
#include <bits/stdc++.h> #define rep(i,n) for ((i)=1;(i)<=(n);(i)++) #define rep0(i,n) for ((i)=0;(i)<(n);(i)++) using namespace std; long long n,m,s,i; vector<int> ans; long long gcd(long long x,long long y){ if(!y) return x; long long t=gcd(y,x%y); s+=x/y;return t; } void print(long long x,long long y){ if(!x){ while(y--)ans.push_back(2); return; } if(!y){ while(x--)ans.push_back(1); return; } if(x>y){ while(x>=y){ ans.push_back(3); x-=y; } } else{ while(x<=y){ ans.push_back(4); y-=x; } } print(x,y); } int main(){ srand(time(NULL)); cin>>n; for(;;){ m=(rand()+rand()*65536ll+rand()*65536ll*65536ll/*+rand()*65536ll*65536ll*65536ll*/)%n; s=0; long long g=gcd(n,m); if(s+g>130) continue; print(n,m); printf("%d\n",ans.size());reverse(ans.begin(),ans.end()); rep0(i,ans.size())printf("%d\n",ans[i]); return 0; } return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0;i<(n);i++) #define ALL(v) v.begin(),v.end() using ll=long long; ll Fib[89]; int main(){ Fib[0]=Fib[1]=1; for(int i=2;i<89;i++)Fib[i]=Fib[i-1]+Fib[i-2]; ll n;cin>>n; vector<int> A; for(int i=88;i>=0;i--){ if(n>=Fib[i]){ A.push_back(i); n-=Fib[i]; } } reverse(ALL(A)); vector<int> ans; int now=0; for(int i=0;i<88&&now<A.size();i++){ if(A[now]==i){ ans.push_back(1+(i&1)); now++; } ans.push_back(3+(i&1)); } reverse(ALL(ans)); cout<<ans.size()<<endl; for(int p:ans)cout<<p<<endl; }
#include <iostream> #include <vector> #include <queue> #include <set> #include <map> #include <algorithm> #include <cstring> #define fi first #define se second #define mp make_pair #define all(x) x.begin(), x.end() #define For(it, x, y) for(int it = x; it < y; it ++) #define ios ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0) #define bug(str, x) cerr << "# " << str << " : " << x << '\n' #define here(x) cerr << "here " << x << '\n' using namespace std; typedef long long ll; typedef pair<int, int> pii; const int maxn = 2e5 + 10; const int maxa = 2e5; const int inf = 1e9; int a[maxn]; bool visited[maxn]; vector<int> G[maxn]; void dfs(int v){ visited[v] = true; for(int u : G[v]){ if(!visited[u]){ dfs(u); } } } int main(){ ios; int n; cin >> n; For(i, 0, n){ cin >> a[i]; } For(i, 0, n / 2){ G[a[i]].push_back(a[n - 1 - i]); G[a[n - 1 - i]].push_back(a[i]); } int cnt = 0; For(i, 1, maxa + 1){ if(!visited[i]){ dfs(i); cnt ++; } } cout << maxa - cnt; }
#include <bits/stdc++.h> #define f first #define s second #define all(vec) begin(vec), end(vec) #define pf push_front #define pb push_back #define lb lower_bound #define ub upper_bound #define mk make_pair using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef pair<ll,int> pli; typedef pair<double, int> pdi; const int N = 2e5+3; vector<int> adj[N]; vector<bool> vis(N); int cnt; void dfs(int c){ vis[c] = 1; cnt++; for(auto& i : adj[c]){ if(!vis[i]){ dfs(i); } } } void solve(){ int n, ans = 0; cin >> n; vector<int> a(n+1); for(int i = 1; i <= n; i++)cin >> a[i]; for(int i = 1; i <= n; i++){ // if(a[i] == a[n-i+1])continue; adj[a[i]].pb(a[n-i+1]); adj[a[n-i+1]].pb(a[i]); } for(int i = 1; i < N; i++){ if(!vis[i]){ cnt = 0; dfs(i); ans += cnt-1; } } cout << ans << '\n'; } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("input.in", "r", stdin); // freopen("input.in", "w", stdout); int tc = 1; // cin >> tc; while(tc--)solve(); }
#include <bits/stdc++.h> using namespace std; #define Fi first #define Se second typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define all(x) (x).begin(), (x).end() #define pb push_back #define szz(x) (int)(x).size() #define rep(i, n) for(int i=0;i<(n);i++) typedef tuple<int, int, int> t3; int N, A[100010], B[100010]; int main() { scanf("%d", &N); for(int i=1;i<=N;i++) scanf("%d", A + i); for(int i=1;i<=N;i++) scanf("%d", B + i); priority_queue <ll> pq; ll at = 0; for(int i=1;i<=N;i++) { if(i & 1) { at += B[i]; pq.push(A[i] - B[i]); } else { at += A[i]; pq.push(B[i] - A[i]); } } rep(i, N / 2) at += pq.top(), pq.pop(); printf("%lld\n", at); return 0; }
#include "bits/stdc++.h" using namespace std; const int mod = 1e9 + 7; void solve() { int n; cin >> n; long long dp[2] = {0}, cnt[2] = {0}; cnt[1] = 1; for(int i = 0; i < n; ++i) { int a; cin >> a; auto x = dp[1]; auto y = cnt[1]; dp[1] = (dp[0] - cnt[0] * a) % mod; cnt[1] = cnt[0]; dp[0] = (dp[0] + x + a * (y + cnt[0])) % mod; cnt[0] = (cnt[0] + y) % mod; } cout << ((dp[0] + dp[1]) % mod + mod) % mod << '\n'; } int main() { ios_base :: sync_with_stdio(false); cin.tie(0); solve(); return 0; }
#include<bits/stdc++.h> using namespace std; const int N=1005,mod=998244353; int n,m,f1[N],f2[N],t; char s[N][N]; int main() { scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) scanf("%s",s[i]+1); for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { if(s[i][j]=='R') f1[i+j]=1; if(s[i][j]=='B') f2[i+j]=1; } } t=1; for(int i=2;i<=n+m;i++) { if(f1[i]&&f2[i]) { puts("0"); return 0; } if(!f1[i]&&!f2[i]) t=t*2%mod; } printf("%d\n",t); return 0; }
// F - Potion #include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i,n) for(int i=0;i<(int)(n);++i) ll INF = 1e18; ll dp[101][101]; void init(int k){ rep(i,k+1) rep(j,k) dp[i][j] = -INF; dp[0][0] = 0; } void update(int k, int a){ for(int i=k-1; i>=0; --i) rep(j,k){ int sk = (j + a) % k; dp[i+1][sk] = max(dp[i+1][sk], dp[i][j] + a); } } int main(){ int n; ll x; cin>>n>>x; int A[n]; for(auto&a:A) cin>>a; ll ans = INF; for(int k=1; k<=n; ++k){ init(k); for(int a:A) update(k, a); ll s = dp[k][x%k]; if(s >= 0) ans = min(ans, (x-s)/k); } cout<< ans <<endl; }
#include <bits/stdc++.h> using namespace std; int main(){ int N; cin >> N; unsigned long long a[N],a_max,b[N],b_max,c; for(int i=0;i<N;i++){ cin >> a[i]; } for(int i=0;i<N;i++){ cin >> b[i]; } c = a[0]*b[0]; a_max=a[0]; b_max=b[0]; cout << c << endl; for(int i=1;i<N;i++){ if(a_max < a[i]) a_max=a[i]; if(c < a_max*b[i]) c = a_max*b[i]; cout << c << endl; } return 0; }
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; #define start ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) #define int long long #define ll long long #define vi vector<int> #define pb push_back #define mod 1000000007 #define all(v) v.begin(),v.end() #define maxv(a) *max_element(all(a)) #define minv(a) *min_element(all(a)) #define sumv(a) accumulate(all(a),0) //#define endl '\n' typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > ordered_set; //0 based index //cout<<*X.find_by_order(1)<<endl; // iterator to the k-th element // cout<<X.order_of_key(-5)<<endl; // number of items in a set that are strictly smaller than our item int gcd(int a,int b){ return __gcd(a,b); } int lcm(int a,int b){ return a*(b/gcd(a,b)); } bool isprime(int n){ if(n<=1)return false; for(int i=2;i*i<=n;i++){ if(n%i==0)return false; } return true; } vector<int>divisor(int n) { vector<int>v; for(int i=1;i*i<=n;i++){ if(i*i==n)v.pb(i); else if(n%i==0){ v.pb(i); v.pb(n/i); } } return v; } const int MX=1e6+123; vector<int>fact[MX]; bool is_prime[MX]; vector<int>primes; void sieve(int n){ for(int i=3;i<=n;i+=2)is_prime[i]=1; for(int i=3;i*i<=n;i+=2){ if(is_prime[i]==1){ for(int j=i*i;j<=n;j+=(i+i)){ is_prime[j]=0; } } } is_prime[2]=1; primes.pb(2); for(int i=3;i<=n;i++){ if(is_prime[i]==1){ primes.pb(i); } } } vector<int>primefactor(int n){ vector<int>v; for(auto p:primes){ if(1LL*p*p>n)break; if(n%p==0){ while(n%p==0){ v.pb(p); n/=p; } } } if(n>1)v.pb(n); return v; } int sumofDigit(int n) { int sum=0; while(n!=0) { sum+=n%10; n/=10; } return sum; } bool isPalindrome(string s) { int l=0; int h=s.size()-1; while(l<h) { if(s[l++]!=s[h--]) { return false; } } return true; } int reverse(int x){ int rev=0,rem; while(x!=0){ rem=x%10; rev=rev*10+rem; x/=10; } return rev; } void solve(){ int n; cin>>n; vi v(n); map<int,int>mp; for(int i=0;i<n;i++){ cin>>v[i]; mp[v[i]%200]++; } int ans=0; for(auto x:mp){ ans+=(x.second*(x.second-1))/2; } cout<<ans<<endl; } signed main() { start; int t=1; //cin>>t; while(t--){ solve(); } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pll; typedef pair<int, int> pii; #define all(x) (x).begin(),(x).end() #define X first #define Y second #define sep ' ' #define endl '\n' #define SZ(x) ll(x.size()) const ll MAXN = 1e6 + 10; const ll LOG = 22; const ll INF = 8e18; const ll MOD = 1e9 + 7; //998244353; //1e9 + 9; int n , A[MAXN] , ans[MAXN]; vector<pii> vec; vector<int> stk; int main() { ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); cin >> n; for(int i = 0 ; i < 2 * n ; i++){ cin >> A[i]; vec.push_back({A[i] , i}); } sort(all(vec)); for(int i = 0 ; i < n ; i++){ ans[vec[i].Y] = 1; } for(int i = 0 ; i < 2 * n ; i++){ if(SZ(stk) == 0 || ans[i] == ans[stk.back()]){ cout << '('; stk.push_back(i); } else{ cout << ')'; stk.pop_back(); } } return 0; } /* */
#include <bits/stdc++.h> #define f first #define s second #define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i) #define pb push_back #define all(s) begin(s), end(s) #define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define sz(s) int(s.size()) #define ENDL '\n' #define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__)) #define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__))) using namespace std; template<class t> using vc=vector<t>; template<class t> using vvc=vc<vc<t>>; typedef long long lli; typedef pair<int,int> ii; typedef vector<int> vi; #define deb(x) cout << #x": " << (x) << endl; lli gcd(lli a, lli b){return (b?gcd(b,a%b):a);} lli lcm(lli a, lli b){ if(!a || !b) return 0; return a * b / gcd(a, b); } int popcount(lli x){return __builtin_popcountll(x);} mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int rnd(int n){return uniform_int_distribution<int>(0, n-1)(rng);} lli poww(lli a, lli b){ lli res =1; while(b){ if(b&1) res = res * a; a = a*a; b/=2; } return res; } template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2; // ---- コーディングはここから! ('-')7 void solve(){ int n; cin>>n; cout<<100-(n%100)<<ENDL; } int main(){_ // int t; cin>>t; while(t--) solve(); }
#include <bits/stdc++.h> using namespace std; #define int long long int a,b,c,d; signed main() { cin>>a>>b>>c>>d; if(c*d<=b){cout<<-1;return 0;} cout<<ceil(1.0*a/(d*c-b)); return 0; }
#include<bits/stdc++.h> using namespace std; //==============================AUTHOR:ZETPI=======================================// #define int long long #define fr(i,st,c) for(int i=st;i<c;i++) #define rfr(i,e,c) for(int i=e;i>=c;i--) #define i_output(f1) cout<<(f1?"YES":"NO")<<endl; #define F first #define S second #define pb push_back #define print(n) cout<<n<<endl #define all(x) x.begin(),x.end() #define sortall(x) sort(all(x)) #define thor ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); typedef vector<int> vi; typedef pair<int,int> pi; typedef map<int,int> mpi; typedef set<int> st; int gcd(int a,int b){ if(b==0) return a; return gcd(b,a%b); } const int mod=1'000'000'007; //============================COPYING PROHIBITED======================================// void solve(){ int a,b,c,d; cin>>a>>b>>c>>d; int cyan=a,red=0,cnt=0,f=-1; while(cyan>d*red && b<(c*d)){ cyan+=b; red+=c; cnt++; f=1; } if(f==-1){ print(-1); } else{ print(cnt); } } signed main(){ thor srand(chrono::high_resolution_clock::now().time_since_epoch().count()); int t=1; // cin>>t; while(t--){ solve(); } return 0; }
/** * Author: Wasi Ur Rahman * FROM RMSTU **/ #include <bits/stdc++.h> #define ll long long #define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define ticktock cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n" #define min3(a,b,c) min(a,min(b,c)) #define min4(a,b,c,d) min(d,min3(a,b,c)) #define max3(a,b,c) max(a,max(b,c)) #define max4(a,b,c,d) max(d,max3(a,b,c)) #define all(v) v.begin(),v.end() #define revall(v) v.rbegin(),v.rend() #define pb push_back #define eb emplace_back #define mk make_pair #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define si(x) scanf("%d", &x) #define sii(x, y) scanf("%d %d", &x, &y) #define siii(x, y, z) scanf("%d %d %d", &x, &y, &z) #define siiii(p,x, y, z) scanf("%d %d %d %d",&p, &x, &y, &z) #define sll(x, y) scanf("%lld %lld", &x, &y) #define slll(x, y, z) scanf("%lld %lld %lld", &x, &y, &z) #define read freopen("input.txt","r",stdin) #define write freopen("output.txt","w",stdout) #define println() cout << endl #define no cout << "NO" << endl #define yes cout << "YES" << endl #define printi(x) printf("%d\n") #define printii(x,y) printf("%d %d\n") #define printiii(x,y,z) printf("%d %d %d\n") #define printl(x) printf("%lld\n") #define printll(x,y) printf("%lld %lld\n") #define printlll(x,y,z) printf("%lld %lld %lld\n") using namespace std; /************************************* * A S S E M B L E * **************************************/ template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); } template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); } bool Prime(ll n){if(n <= 1)return false;for (ll i = 2; i<=sqrt(n); i++)if (n % i == 0)return false;return true;} const int mod = 1e9+7; ll add(ll a,ll b){if((a+=b)>=mod)a-=mod;return a;} inline int dec(int a,int b){if((a-=b)<0)a+=mod;return a;} ll mult(ll a,ll b){long long t=1ll*a*b;if(t>=mod)t%=mod;return t;} ll power(ll a,ll b){ll out=1;while(b){if(b&1)out=mult(out,a);a=mult(a,a);b>>=1;}return out;} ll modpow(ll a, ll n, ll mod){ll res=1;while(n>0){if(n&1) res=res*a%mod;a=a*a%mod;n>>=1;}return res;} ll modinverse(ll a,ll M){return modpow(a,M-2,M);} int main(){ boost; int n; cin >> n; vector<int> v(n); int arr[200001]; memset(arr,0,sizeof(arr)); for(int i = 0;i<n;i++) { cin >> v[i]; } vector<int> ans; int m = 0; for(int i = 0;i<n;i++){ arr[v[i]]++; if(arr[m] == 0) cout << m << endl; else{ while(arr[m] != 0) m++; cout << m << endl; } } }
#include <bits/stdc++.h> using namespace std; // type alias typedef long long LL; typedef pair<int,int> II; typedef tuple<int,int,int> III; typedef vector<int> VI; typedef vector<string> VS; typedef unordered_map<int,int> MAPII; typedef unordered_set<int> SETI; template<class T> using VV=vector<vector<T>>; // minmax template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; } template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; } // repetition #define FORE(i,a,b) for(int i=(a);i<=(b);++i) #define REPE(i,n) for(int i=0;i<=(n);++i) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) for(int i=0;i<(n);++i) #define FORR(x,arr) for(auto& x:arr) #define SZ(a) int((a).size()) // collection #define ALL(c) (c).begin(),(c).end() // DP #define MINUS(dp) memset(dp, -1, sizeof(dp)) #define ZERO(dp) memset(dp, 0, sizeof(dp)) // stdout #define println(args...) fprintf(stdout, ##args),putchar('\n'); // debug cerr template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; } void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; } template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); } template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; } #define __KUMATRACE__ true #ifdef __KUMATRACE__ #define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); } #define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; } #define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); } #else #define dump(args...) #define dumpc(ar) #define dumpC(beg,end) #endif // $ cp-batch NeqMin | diff NeqMin.out - // $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address NeqMin.cpp && ./a.out /* 10/10/2020 5:06- */ const int MAX_N=1e6+1; int P[MAX_N]; int N; void solve() { VI viz(MAX_N,0); int res=0; REP(i,N) { viz[P[i]]=1; while(viz[res]==1) ++res; cout<<res<<endl; } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout<<setprecision(12)<<fixed; cin>>N; REP(i,N) cin>>P[i]; solve(); return 0; }
// // Created by Anton Gorokhov // #ifdef lolipop #define _GLIBCXX_DEBUG #endif #include <iostream> #include <cstddef> #include <vector> #include <cstring> #include <string> #include <algorithm> #include <set> #include <map> #include <ctime> #include <unordered_map> #include <random> #include <iomanip> #include <cmath> #include <queue> #include <unordered_set> #include <cassert> #include <bitset> #include <deque> #include <utility> #define int long long #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define ld double using namespace std; mt19937 rnd(time(nullptr)); inline void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } void solve() { int n; cin >> n; map<int, int> m; for (int i = 0; i < n; ++i) { int x; cin >> x; m[x]++; } int ans = (n * (n - 1)) / 2; for (auto i : m) { ans -= (i.second * (i.second - 1)) / 2; } cout << ans << '\n'; } signed main() { #ifdef lolipop freopen("input.txt", "r", stdin); #else fastio(); #endif int T = 1; // cin >> T; while (T--) { solve(); } return 0; }
#include <bits/stdc++.h> #define int long long #define menhera_chan_is_mine ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define pb emplace_back #define pi pair<int, int> #define BE(i) i.begin(),i.end() #define fi first #define se second #define INF 2147483647 #define mkp make_pair #define ist insert #define mod 1000000007 //#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math") //#pragma GCC optimize("O2") using namespace std; int min(int a, int b){return a < b ? a : b;} int max(int a, int b){return a > b ? a : b;} bool isprime(int k){bool is=1 ; for ( int i = 2 ; i <= sqrt(k) ; i++ ) if ( k % i == 0 ) is = 0 ; return is;} const double PI=acos(-1); int n; pi p[66000]; pi dc(int l,int r,int lay) { if (r-l==1) return p[l]; int m=(l+r)/2; pi a=dc(l,m,1); pi b=dc(m,r,1); if (lay==0) { if (a.fi>b.fi) return b; else return a; } else { return (a.fi>b.fi?a:b); } } int32_t main() { menhera_chan_is_mine cin >>n; n=(1<<n); for (int i=0;i<n;i++) cin >>p[i].fi,p[i].se=i; pi res=dc(0,n,0); cout <<res.se+1<<"\n"; return 0; }
#pragma GCC optimize ("O3") #include <bits/stdc++.h> typedef long long ll; using namespace std; const int N = 4e5 + 5; int C[3][3]; void pascal() { for(int i = 0;i < 3;i++) { C[i][0] = C[i][i] = 1; for(int j = 1;j < i;j++) C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % 3; } } int ncrLucas(int n, int r, int p) { if(r == 0) return 1; int ni = n % p, ri = r % p; return (1ll * ncrLucas(n / p, r / p, p) * C[ni][ri]) % p; } int n, a[N]; int main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); pascal(); cin >> n; for(int i = 0;i < n;i++) { char c; cin >> c; if(c == 'B') a[i] = 0; else if(c == 'W') a[i] = 1; else a[i] = 2; } int ans = 0; for(int i = 0;i < n;i++) ans = (ans + (1ll * ncrLucas(n - 1, i, 3) * a[i]) % 3) % 3; if(n % 2 == 0) ans = (3 - ans) % 3; if(ans == 0) cout << 'B'; else if(ans == 1) cout << 'W'; else cout << 'R'; return 0; }
#include <vector> #include <array> #include <stack> #include <queue> #include <list> #include <bitset> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <algorithm> #include <numeric> #include <iostream> #include <iomanip> #include <string> #include <chrono> #include <random> #include <cmath> #include <cassert> #include <climits> #include <cstring> #include <cstdlib> #include <functional> #include <sstream> using namespace std; int main(int argc, char** argv) { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(12); int n; cin >> n; vector<int> P(n, -1); for (int i = 1; i < n; ++i) { cin >> P[i]; --P[i]; } vector<vector<int>> graph(n); for (int i = 1; i < n; ++i) { graph[P[i]].push_back(i); } int rt = 0; const int INF = 1 << 24; vector<int> dp(n, -INF); vector<int> sizes(n, 0); for (int i = n - 1; i >= 0; --i) { int u = i; sizes[u] = 1; long long res = 1; vector<vector<int>> ans(2); for (auto v : graph[u]) { sizes[u] += sizes[v]; ans[(sizes[v] * 3) & 1].push_back(dp[v]); } for (auto& V : ans) { sort(V.begin(), V.end()); } for (auto x : ans[0]) { if (x < 0) { res += x; } } int m = ans[1].size(); // for (int i = 0, j = m - 1, t = 0; t < m; ++t) { // if (t & 1) { // res -= ans[1][j--]; // } else { // res += ans[1][i++]; // } // } for (int j = 0; j < m; ++j) { if (j & 1) { res -= ans[1][j]; } else { res += ans[1][j]; } } if (m & 1) { for (auto x : ans[0]) { if (x > 0) { res -= x; } } } else { for (auto x : ans[0]) { if (x > 0) { res += x; } } } dp[u] = res; } assert((n + dp[rt]) % 2 == 0); cout << (n + dp[rt]) / 2 << '\n'; return 0; }
#include <bits/stdc++.h> #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define endl "\n" #define rep(i,n) repi(i,0,n) #define repi(i,a,n) for(ll i=a;i<(ll)n;++i) #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(),(a).rend() #define Show(val) cout<<(val)<<" " #define Showln(val) cout<<(val)<<endl using namespace std; using ll = long long; using P = pair<ll, ll>; // using P = pair<int, int>; void YN(bool a) { cout << (a ? "Yes" : "No"); } 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; } class UnionFind{ public: vector<int> p; // 親 vector<int> rank; // サイズ・各集合の根のみ有効 UnionFind(int n){ p.resize(n, -1); rank.resize(n, 1); } int root(int x){ if(p[x] == -1) return x; else return p[x] = root(p[x]); // 深さを 1 にしている } void unite(int x, int y){ x = root(x); y = root(y); if(x == y)return; if(rank[x] > rank[y]) swap(x, y); // rankの小さいものを下につける // -> x <= y rank[y] += rank[x]; p[x] = y; } // グループの数 ll root_num() { ll num = 0; for(ll x : p) if (x < 0) num++; return num; } // グループごとに頂点をまとめる: O(N log N) map<int, vector<int>> groups(){ map<int, vector<int>> ret; rep(i, p.size()) ret[root(i)].emplace_back(i); return ret; } //xが属すグループのサイズ int size(int x){ return rank[root(x)]; } bool same(int x, int y){ return (root(x) == root(y)); } }; void solve() { ll n, q, t, q1, q2; cin >> n >> q; vector<ll> cls(n); vector< map<ll, ll> > score(n, map<ll, ll>()); rep(i, n) cin >> cls[i]; rep(i, n) score[i][--cls[i]] = 1; UnionFind uf(n); rep(qi, q) { cin >> t >> q1 >> q2; q1--; q2--; if (t == 1) { if (uf.same(q1, q2)) continue; if (uf.size(q1) > uf.size(q2)) swap(q1, q2); // q1をq2にくっつける ll root1 = uf.root(q1); ll root2 = uf.root(q2); for(const auto& mp : score[root1]) { score[root2][mp.first] += mp.second; } uf.unite(q1, q2); } else if (t == 2) { cout << score[uf.root(q1)][q2] << endl; } } } int main() { fastio; solve(); return 0; }
#include<bits/stdc++.h> #define fr first #define sc second #define pb push_back #define ll long long #define maxheap priority_queue<int> #define minheap priority_queue<int,vector<int>,greater<int>> #define all(v) (v).begin(),(v).end() const double pi = acos(-1.0); const double eps = 1e-12; using namespace std; const int N = 20; const ll INF = 1e18; int n, m; ll pref[N][N]; ll dp[(1 << N)][2]; bool ok(int mask, int idPref){ int kol = 0; for (int i = 0; i < n; i++){ if (mask & (1 << i)){ kol++; } if (pref[idPref][i + 1] < kol){ return false; } } return true; } void solve(){ cin >> n >> m; for (int i = 0; i < N; i++){ for (int j = 0; j < N; j++){ pref[i][j] = INF; } } for (int i = 1; i <= m; i++){ int x, y, z; cin >> x >> y >> z; for (int j = 1; j <= x; j++){ pref[j][y] = min((ll)z, pref[j][y]); } } dp[0][0] = 1; int now = 1; for (int pos = 0; pos < n; pos++){ now = (now ^ 1); int nxt = (now ^ 1); for (int mask = 0; mask < (1 << n); mask++){ dp[mask][nxt] = 0; } for (int mask = 0; mask < (1 << n); mask++){ if (dp[mask][now] == 0){ continue; } assert(__builtin_popcount(mask) == pos); for (int put = 0; put < n; put++){ if (mask & (1 << put)){ continue; } int newMask = (mask | (1 << put)); if (ok(newMask, pos + 1)){ dp[newMask][nxt] += dp[mask][now]; //cout << pos + 1 << " " << put + 1 << " " << mask << " " << newMask << " " << dp[mask][now] << " " << dp[newMask][nxt] << endl; } } } if (pos == n - 1){ cout << dp[(1 << n) - 1][nxt] << endl; return; } } } int main(){ ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0); cout.setf(ios::fixed), cout.precision(6); //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); //freopen("exercise.in","r",stdin); freopen("exercise.out", "w", stdout); int step; step = 1; //cin >> step; for (int i = 1; i <= step; i++){ solve(); } }
#include <iostream> #include <iosfwd> #include <iomanip> #include <cstdio> #include <cstring> #include <cstdlib> #include <ctime> #include <cmath> #include <cassert> #include <cctype> #include <climits> #include <vector> #include <bitset> #include <set> #include <queue> #include <math.h> #include <stack> #include <map> #include <deque> #include <string> #include <list> #include <iterator> #include <sstream> #include <complex> #include <fstream> #include <functional> #include <numeric> #include <utility> #include <algorithm> #include <assert.h> #include <unordered_map> #pragma GCC optimize ("-O3") using namespace std; #define watch(x) cout << (#x) << " = " << (x) << endl #define PI double(2 * acos(0.0)) #define ll long long #define MOD 1000000007 #define all(x) (x).begin(), (x).end() #define INF 1e15 int main() { ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); string s; cin >> s; int n = s.size(); for(int i = 0;i<n;i++){ if(s[i] != '.'){ cout << s[i]; }else break; } }
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; string ans = ""; bool flg = true; for(char c : s) { if(c == '.') { flg = false; } if(flg) { ans += c; } } cout << ans << '\n'; return 0; }
#include<bits/stdc++.h> using namespace std; using namespace std::chrono; const int mod=998244353; const int mex=200005; #define ll long long #define test int t;cin>>t;while(t--) #define fast ios_base::sync_with_stdio(false);cin.tie(NULL); #define fo(i,a,n) for(int i=a;i<n;i++) #define rfo(i,a,b) for(int i=a;i>=b;i--) #define bg begin() #define en end() #define fi first #define se second #define ub upper_bound #define lb lower_bound #define pb push_back #define veci vector<int> #define veclli vector<long long int> #define all(x) x.begin(),x.end() #define sci(x) scanf("%d",&x); #define scc(x) scanf("%c",&x); #define scs(x) scanf("%s",x); #define debug(arr,n) for(int i=0;i<n;i++) printf("%d ",arr[i]); #define sz(x) x.size() #define loop(x) for(auto it=x.begin();it!= x.end();it++) #define int long long int bite[mex]; void update(int x,int vl) { while(x<mex) { bite[x]+=vl; x+=x&-x; } } int query(int x) { int sum=0; while(x) { sum+=bite[x]; x-=x&-x; } return sum; } signed main() { int n,m,w; cin>>n>>m>>w; int x[n+2]; int y[m+2]; fo(i,0,n+2) x[i]=m+1; fo(i,0,m+2) y[i]=n+1; fo(i,0,w) { int x1,y1; cin>>x1>>y1; x[x1]=min(x[x1],y1); y[y1]=min(y[y1],x1); } int ans=0; fo(i,1,x[1]) { ans=ans+y[i]-1; } fo(i,1,y[1]) ans=ans+x[i]-1; //cout<<ans<<endl; int y1=x[1]; vector<int> v[n+3]; fo(i,1,y1) { v[y[i]].pb(i); } fo(i,1,n+1) { if(i<y[1]) update(x[i],1); fo(j,0,sz(v[i+1])) ans=ans-(query(mex-1)-query(v[i+1][j])); } cout<<ans<<endl; }
#include <algorithm> #include <cmath> #include <cstring> #include <cstdio> #include <iostream> #include <sstream> #include <numeric> #include <map> #include <set> #include <queue> #include <vector> using namespace std; typedef long long LL; class BIT { std::vector<long long> bit; long long size; public: BIT() { } BIT(long long sz) { init(sz); } void init(long long sz) { bit = std::vector<long long>((size = sz) + 1); } long long sum(long long i) { LL s = 0; while (i > 0) { s += bit[i]; i -= i & -i; } return s; } void add(long long i, long long x) { while (i <= size) { bit[i] += x; i += i & -i; } } }; LL solve(long long H, long long W, long long M, std::vector<long long> X, std::vector<long long> Y) { LL right = W; vector<LL> min_height(W, H); vector<vector<LL>> blocks(H); for (LL i = 0; i < M; ++i) { min_height[Y[i]] = min(min_height[Y[i]], X[i]); if (X[i] == 0) { right = min(right, Y[i]); } blocks[X[i]].emplace_back(Y[i]); } LL ans = 0; for (LL i = 0; i < right; ++i) { ans += min_height[i]; } BIT bit(W); vector<bool> used(W); for (LL i = right; i < W; ++i) { bit.add(i + 1, 1); used[i] = true; } for (LL i = 1; i < min_height[0]; ++i) { sort(blocks[i].begin(), blocks[i].end()); LL right = blocks[i].empty() ? W : blocks[i][0]; ans += bit.sum(right); for (auto j : blocks[i]) { if (!used[j]) { used[j] = true; bit.add(j + 1, 1); } } } return ans; } int main() { #if DEBUG freopen("in_2.txt", "r", stdin); #endif long long H, W, M; cin >> H >> W >> M; std::vector<long long> X(M), Y(M); for (int i = 0 ; i < M ; i++) { cin >> X[i] >> Y[i]; --X[i]; --Y[i]; } cout << solve(H, W, M, std::move(X), std::move(Y)) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; // #include <atcoder/all> // using namespace atcoder; // using mint = modint1000000007; // using mint2 = modint998244353; typedef int64_t Int; #define all(x) (x).begin(), (x).end() const double EPS = 1e-10; const Int INF = 1e18; const int inf = 1e9; const Int mod = 1e9+7; //const Int mod = 998244353; typedef struct { int64_t to, weight; } edge; Int dx[] = {0, 1, 0, -1, -1, 1, -1, 1}; Int dy[] = {1, 0, -1, 0, -1, -1, 1, 1}; template<class T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) { is >> e; } return is; } bool print_space_enable = false; void print() { std::cout << '\n'; print_space_enable = false; } template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { if (print_space_enable) std::cout << " "; std::cout << fixed << setprecision(15) << head; print_space_enable = true; print(std::forward<Tail>(tail)...); } template<typename T> void print(vector<T> v) { for (size_t i = 0; i < v.size(); i++) { if (i > 0) std::cout << " "; std::cout << v[i]; } std::cout << '\n'; } template<class T> vector<T> make_vec(size_t n, T val) { return vector<T>(n, val); } template<class... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); } bool is_overflow(Int a, Int b) { return a > INF / b; } void solve() { Int k, n, m; cin >> k >> n >> m; vector<Int> a(k); cin >> a; vector<Int> b(k); for (Int i = 0; i < k; i++) { b[i] = (a[i] * m) / n; } Int sum = accumulate(all(b), (Int)0); if (sum > m) { priority_queue<pair<Int, Int>, vector<pair<Int, Int>>, greater<pair<Int, Int>>> q; for (Int i = 0; i < k; i++) { if (b[i] == 0) continue; q.push({abs(n * b[i] - m * a[i]), i}); } for (Int i = 0; i < sum - m; i++) { pair<Int, Int> p = q.top(); q.pop(); b[p.second]--; if (b[p.second] == 0) continue; q.push({abs(n * b[p.second] - m * a[p.second]), p.second}); } } else { priority_queue<pair<Int, Int>, vector<pair<Int, Int>>, greater<pair<Int, Int>>> q; for (Int i = 0; i < k; i++) { q.push({n * b[i] - m * a[i], i}); } for (Int i = 0; i < m - sum; i++) { pair<Int, Int> p = q.top(); q.pop(); b[p.second]++; q.push({n * b[p.second] - m * a[p.second], p.second}); } } print(b); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); solve(); //Int _t; cin >> _t; while (_t--) solve(); return 0; }
//#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i=0; i<n; ++i) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() using ll = int64_t; using ull = uint64_t; using ld = long double; using P = pair<int, int>; using vs = vector<string>; using vi = vector<int>; using vvi = vector<vi>; template<class T> using PQ = priority_queue<T>; template<class T> using PQG = priority_queue<T, vector<T>, greater<T>>; const int INF = 0xccccccc; const ll LINF = 0xcccccccccccccccLL; template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);} template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);} template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;} template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;} #undef _GLIBCXX_DEBUG string to_string(const string &s) {return '"' + s + '"';} string to_string(const char *s) {return to_string(string(s));} string to_string(bool b) {return b?"true":"false";} string to_string(vector<bool> v) { string res = "{"; for(int i = 0; i < int(v.size()); i++) { if(i) res += ", "; res += to_string(v[i]); } res += "}"; return res; } template<size_t N> string to_string(bitset<N> v) { string res; for(size_t i = 0; i < N; i++) res += char('0' + v[i]); return res; } template<class A, class B> string to_string(pair<A, B>); template<class A, class B, class C> string to_string(tuple<A, B, C>); template<class A, class B, class C, class D> string to_string(tuple<A, B, C, D>); template<class A> string to_string(A v) { bool first = true; string res = "{"; for(const auto &x:v) { if(!first) res += ", "; first = false; res += to_string(x); } res += "}"; return res; } template<class A, class B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template<class A, class B, class C> string to_string(tuple<A, B, C> t) { return "(" + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " + to_string(get<2>(t)) + ")"; } template<class A, class B, class C, class D> string to_string(tuple<A, B, C, D> t) { return "(" + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " + to_string(get<2>(t)) + ", " + to_string(get<3>(t)) + ")"; } void debug_out() {cerr << endl;} template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << to_string(H); debug_out(T...); } #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 822 #endif //head int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vvi G(n); rep(i, m) { int a, b; cin >> a >> b; a--; b--; G[a].emplace_back(b); } queue<int> q; int ans = 0; rep(i, n) { vi check(n); check[i] = 1; ans++; q.emplace(i); while(not q.empty()) { int now = q.front(); q.pop(); for(auto ne:G[now]) { if(not check[ne]) { check[ne]++; ans++; q.emplace(ne); } } } } cout << ans << endl; }
#include <algorithm> #include <cmath> #include <cstdlib> #include <iostream> #include <string> #include <vector> using namespace std; typedef long long LL; int main() { int A, B, W; cin >> A >> B >> W; long double w = W * 1000; int vmin = ceil(w/B); int vmax = floor(w/A); if (vmax >= vmin) cout << vmin << " " << vmax << endl; else cout << "UNSATISFIABLE" << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (long i = 0; i < n; i++) int main() { int A, B, M; cin >> A >> B >> M; M *= 1000; int Q = M / A; int W = M / B; if(M % B != 0) W++; int U = 0, O = 0; for(int i = W; i <= Q; i++) { double T = i / 1.0; double R = M / T; if(U == 0) if(A <= R && R <= B) U = i; if(U != 0) if(A <= R && R <= B) O = i; } if(U == 0 && O == 0) cout << "UNSATISFIABLE" << endl; else cout << U << " " << O << endl; }
#include <bits/stdc++.h> using namespace std; const int MAX = 5010; const int MOD = 998244353; int64_t fac[MAX], finv[MAX], inv[MAX]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++){ fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } int64_t COM(int n, int k){ if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } int main() { COMinit(); int N, M; cin >> N >> M; if (M%2 == 1 || N == 1) { cout << 0 << endl; return 0; } vector<int64_t> dp(M+1,0); dp[0] = 1; for (int i = 2; i <= M; i += 2) { int sum = 0; for (int j = 0; j <= i; j += 2) { sum = (sum + (COM(N,j) * dp[(i-j)/2])%MOD )%MOD; } dp[i] = sum; } cout << dp[M] << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define rep(x, L, R) for(int x = (L), _x = (R); x <= _x; x++) #define per(x, R, L) for(int x = (R), _x = (L); x >= _x; x--) #define broken fprintf(stderr, "running on %s %d\n", __FUNCTION__, __LINE__) #define debug(...) fprintf(stderr, __VA_ARGS__) #define SZ(v) (int)(v).size() #define ALL(x) (x).begin(), (x).end() #define x first #define y second #define mp make_pair #define pb push_back template<typename T> inline bool ckmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; } template<typename T> inline bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } typedef pair<int, int> par; typedef long long LL; typedef unsigned long long uLL; typedef double db; const int N = 5000 + 10, md = 998244353; int n, m; int fac[N], ifac[N]; int dp[N][N]; int qpow(int a, int b) { int res = 1; for(; b; b >>= 1, a = 1ll * a * a % md) if(b & 1) res = 1ll * res * a % md; return res; } int b(int n, int m) { if(n < m) return 0; return 1ll * fac[n] * ifac[m] % md * ifac[n - m] % md; } void initfac(int n) { fac[0] = 1; for(int i = 1; i <= n; i++) fac[i] = 1ll * fac[i - 1] * i % md; ifac[n] = qpow(fac[n], md - 2); for(int i = n - 1; i >= 0; i--) ifac[i] = 1ll * ifac[i + 1] * (i + 1) % md; return; } int main() { scanf("%d%d", &n, &m); initfac(n); dp[0][0] = 1; int now = 0; for(int i = 0, k = 1; k <= m; k <<= 1, i++) { for(int j = 0; j <= m; j++) { for(int l = 0; j + l * k <= m && l <= n; l += 2) { dp[i + 1][j + k * l] = (dp[i + 1][j + k * l] + 1ll * dp[i][j] * b(n, l) % md) % md; // cout << dp[i][j] << endl; } } now = i + 1; } printf("%d\n", dp[now][m]); return 0; }
#include <bits/stdc++.h> using namespace std; //#include <atcoder/all> //using namespace atcoder; using ll=long long; #define MOD 998244353 #define INF 1000000000 #define MAX 10000 using Graph=vector<vector<int>>; int main(){ int N; string S; string X; cin>>N>>S>>X; vector<vector<bool>> dp(N+1,vector<bool>(7,false)); dp[N][0]=true; int res=1; for(int i=N-1;i>=0;i--){ int d=S[i]-'0'; if(X[i]=='T'){ for(int j=0;j<7;j++){ dp[i][j]=dp[i+1][j]|dp[i+1][(j+d*res)%7]; } }else{ for(int j=0;j<7;j++){ if(dp[i+1][j]==false||dp[i+1][(j+d*res)%7]==false){ dp[i][j]=false; }else{ dp[i][j]=true; } } } res*=10; res%=7; } if(dp[0][0]==true){ cout<<"Takahashi"<<endl; }else{ cout<<"Aoki"<<endl; } }
#include<bits/stdc++.h> #define fort(i,a,b) for(long long i=a;i<=b;i++) #define forn(i,a,b) for(long long i=a;i>=b;i--) #define x first #define y second #define MP make_pair #define pb push_back #define ii pair<long long ,long long > #define MT make_tuple #define tp tuple bool getbit(long long x,long long y) { return (x>>y)&1; } void h10toh2() { long long x,n; while(1) { std::cin>>x; if (x==-1) return; n=log2(x); forn(i,n,0) std:: cout<<((x>>i)&1);std::cout<<'\n'; } } using namespace std; long long A,B,C,D; int main() { //h10toh2(); //freopen("codeforces.inp","r",stdin); //freopen("codeforces.out","w",stdout); ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin>>A>>B>>C>>D; if (D*C-B>0) cout<<A/(D*C-B)+(A%(D*C-B)!=0)<<'\n';else cout<<"-1\n"; }
#include <bits/stdc++.h> #define arraysize(array) (sizeof(array)/sizeof(array[0])) #define loop(i,a,b) for (int i = a; i < b; i++) #define loopData(array) (cout << array[i] << " ") using namespace std; bool binarySearch(int arra[],int arraySize, int key){ int startPoint, endPoint; int location; startPoint = 0; endPoint = arraySize - 1; while(startPoint <= endPoint){ int midPoint = (startPoint + endPoint) / 2; if(arra[midPoint] == key){ return true; break; } else if(arra[midPoint] < key){ startPoint = midPoint + 1; } else { endPoint = midPoint - 1; } } return false; } void insert(int arra[], int arraySize, int position, int item){ for(int i = arraySize - 1; i >= position-1; i--){ arra[i+1] = arra[i]; } arra[position-1] = item; } int main() { int M, H; cin >> M >> H; if(H % M == 0){ cout << "Yes" << endl; }else { cout << "No" << endl; } }
#include <bits/stdc++.h> using namespace std; using i64 = int_fast64_t; using pii = pair<int, int>; using pll = pair<i64, i64>; #define rep(i, n) for(i64 i = 0; i < n; i++) #define per(i, n) for(i64 i = n - 1; i >= 0; i--) #define REP(i, a, b) for(i64 i = a; i < b; i++) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define fi first #define se second #define debug(...) cerr<<__LINE__<<" ["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__) template <typename T> ostream& operator<<(ostream& os, const vector<T>& vec) { for (auto v : vec) { os << v << ' '; } os << '\n'; return os; } template <typename T1, typename T2> ostream& operator<<(ostream& os, const pair<T1, T2>& pa) { os << '(' << pa.first << ',' << pa.second << ')'; return os; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...); } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const int INF = (1 << 30) - 1; const i64 LINF = (1LL << 62) - 1; void solve() { i64 n, k; cin >> n >> k; rep(i, k) { string s1 = to_string(n); string s2 = to_string(n); sort(rall(s1)); sort(all(s2)); n = stoll(s1) - stoll(s2); } cout << n << endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); solve(); return 0; }
//DUEL #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #define x first #define y second #define pii pair<int,int> #define pb push_back #define eb emplace_back #pragma GCC optimize("unroll-loops") #define shandom_ruffle(a, b) shuffle(a, b, rng) #define vi vector<int> #define vl vector<ll> #define popcnt __builtin_popcount #define popcntll __builtin_popcountll #define all(a) begin(a),end(a) using namespace std; using namespace __gnu_pbds; using ll=long long; using ull=unsigned long long; using ld=long double; int MOD=1000000007; int MOD2=998244353; vector<int> bases; const ll LLINF=1ll<<60; const char en='\n'; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void yes() {cout<<"YES"<<en; exit(0);} void no() {cout<<"NO"<<en; exit(0);} inline int rund() {int x576363482791fuweh=rng();return abs(x576363482791fuweh)%RAND_MAX;} template<class T> void prVec(vector<T> w,bool fl=false) { cout<<w.size()<<en; for (int i=0;i<int(w.size())-1;++i) cout<<w[i]<<' '; if (w.size()) cout<<w[w.size()-1]<<en; if (fl) cout<<flush; } void M998() { swap(MOD,MOD2); } ll raand() { ll a=rund(); a*=RAND_MAX; a+=rund(); return a; } #define rand raand ll raaand() { return raand()*(MOD-7)+raand(); } template<class T> vi compress(vector<T>&v) { set<T> s; for (auto a: v) s.insert(a); vector<T> o(all(s)); vi nv; for (int i=0;i<(int)v.size();++i) nv.pb(lower_bound(all(o),v[i])-o.begin()); return nv; } string to_upper(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A'; return a; } string to_lower(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A'; return a; } ll sti(string a,int base=10) { ll k=0; for (int i=0;i<(int)a.size();++i) { k*=base; k+=a[i]-'0'; } return k; } template<class T> void eras(vector<T>& a,T b) { a.erase(find(a.begin(),a.end(),b)); } string its(ll k,int base=10) { if (k==0) return "0"; string a; while (k) { a.push_back((k%base)+'0'); k/=base; } reverse(a.begin(),a.end()); return a; } ll min(ll a,int b) { if (a<b) return a; return b; } ll min(int a,ll b) { if (a<b) return a; return b; } ll max(ll a,int b) { if (a>b) return a; return b; } ll max(int a,ll b) { if (a>b) return a; return b; } ll gcd(ll a,ll b) { if (b==0) return a; return gcd(b,a%b); } ll lcm(ll a,ll b) { return a/gcd(a,b)*b; } template<class T,class K> pair<T,K> mp(T a,K b) { return make_pair(a,b); } inline int mult(ll a,ll b) { return (a*b)%MOD; } inline int pot(int n,int k) { if (k==0) return 1; ll a=pot(n,k/2); a=mult(a,a); if (k%2) return mult(a,n); else return a; } int divide(int a,int b) { return mult(a,pot(b,MOD-2)); } inline int sub(int a,int b) { if (a-b>=0) return a-b; return a-b+MOD; } inline int add(int a,int b) { if (a+b>=MOD) return a+b-MOD; return a+b; } bool prime(ll a) { if (a==1) return 0; for (int i=2;i<=round(sqrt(a));++i) { if (a%i==0) return 0; } return 1; } int dx[]={0,1,0,-1}; int dy[]={1,0,-1,0}; const int N=300010; int n,a[N],b[N],p[N],pos[N]; bool bio[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); for (int i=0;i<10;++i) bases.push_back(rand()%(MOD-13893829*2)+13893829); cin>>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],pos[p[i]]=i; for (int i=0;i<n;++i) if (p[i]!=i && a[i]<=b[p[i]]) { cout<<-1<<en; exit(0); } vector<pii> re; for (int i=0;i<n;++i) if (!bio[i]) { vi v; int z=i; do { bio[z]=1; v.pb(z); z=p[z]; } while (z!=i); vector<pii> v1; for (auto x: v) v1.pb({b[x],x}); sort(all(v1)); reverse(all(v1)); for (auto x: v1) { int po=pos[x.y],tre=x.y; if (po==tre) continue; re.pb({po,tre}); swap(p[po],p[tre]); swap(pos[p[po]],pos[p[tre]]); } } cout<<re.size()<<en; for (auto a: re) cout<<a.x+1<<' '<<a.y+1<<en; }
#include<cstdio> #include<iostream> #include<cmath> #include<cstring> #include<cctype> #include<cstdlib> #include<vector> #include<algorithm> #include<queue> #define fs(i,x,y) for(int i=(x),_=(y);i<=_;++i) #define fn(i,x,y) for(int i=(x),_=(y);i>=_;--i) #define tor(i,v,x) for(int i=head[x],v=to[i];i;i=nxt[i],v=to[i]) #define Li inline #define ls(x) ch[x][0] #define rs(x) ch[x][1] #define mpi(x,y) make_pair(x,y) #define pi pair<int,int> //#define int ll #define DEBUG printf("%s %d\n",__FUNCTION__,__LINE__) using namespace std; typedef long long ll; typedef double db; template<typename T> void read(T &x){ x=0;char ch=getchar();bool f=0; while(ch<'0'||ch>'9'){ if(ch=='-')f=1; ch=getchar(); } while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+ch-'0',ch=getchar(); x=f?-x:x; } const int N=2e5+7,P=1e9+7; int n,m; char s[N]; int a[N]; int f[20]; bool vis[20];int lst,cnt=0; int add(int x,int y){ x+=y;return x>=P?x-P:x; } signed main(){ scanf("%s",s+1);int len=strlen(s+1);read(m); fs(i,1,len)if(isdigit(s[i]))a[i]=s[i]-'0'; else a[i]=s[i]-'A'+10; f[0]=1;lst=a[1];f[1]=a[1]-1; fs(i,2,len){ fn(j,16,2)f[j]=add((ll)f[j-1]*(16-j+1)%P,(ll)f[j]*j%P); f[1]=add(f[1],15); if(a[i]){ if(!vis[lst])vis[lst]=true,++cnt; fs(j,0,a[i]-1)if(vis[j])f[cnt]=add(f[cnt],1); else f[cnt+1]=add(f[cnt+1],1); lst=a[i]; }else if(!vis[0]){ vis[0]=true;++cnt; } } //最后还要加1 if(!vis[lst])vis[lst]=true,++cnt; if(vis[a[len]])f[cnt]=add(f[cnt],1); else f[cnt+1]=add(f[cnt+1],1); printf("%d\n",f[m]); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ll long long int main(){ ll n,ans; string s; cin >> n >> s; ans=n; for(ll i=0;i<n-2;i++){ if(s.at(i)=='f' && s.at(i+1)=='o' && s.at(i+2)=='x'){ s=s.erase(i,3); n-=3; ans-=3; if(i>0){ i-=2; } if(i>1){ i--; } } } cout << ans; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; #define al(a) a.begin(), a.end() #define ral(a) a.rbegin(), a.rend() #define sz(a) (int)a.size() int main() { int n; cin >> n; string s; cin >> s; string ans; for (char c : s) { ans += c; // substr(最後の3文字前から最後まで)第一引数だけだと指定場所から最後まで if (sz(ans) >= 3 && ans.substr(sz(ans) - 3) == "fox") { //後ろから3文字消去方法 ans.erase(ans.begin() + (sz(ans) - 3), ans.end()); } } cout << sz(ans) << endl; } // stackの得意分野 // const string fox = "fox"; // int main() { // int n; // cin >> n; // string s; // cin >> s; // stack<char> st; // // cout << sz(st) << endl; // for (int i = 0; i < n; ++i) { // st.push(s[i]); // if (sz(st) >= 3 && s[i] == 'x') { // 2以上ではなく 既にpushなので3以上 // string t; // for (int j = 0; j < 3; ++j) { // t = st.top() + t; // st.pop(); // } // if (fox != t) { // for (int j = 0; j < 3; ++j) { st.push(t[j]); } // } // // stack不慣れ // // char o = st.top(); // // st.pop(); // // char f = st.top(); // // st.pop(); // // if (o != 'o' || f != 'f') { // // st.push(f); // // st.push(o); // // st.push(s[i]); // // } // } // } // cout << sz(st) << endl; // } // fを数えとけばいい? ダメ fofoxx このパターン  // int main() { // int n; // cin >> n; // string s; // cin >> s; // int cntf = 0, ans = 0; // for (int i = 0; i < n; ++i) { // if (s[i] == 'f') // cntf++; // else if (s[i] == 'o' && cntf) { //文字列は配列外参照+1までは良いはず // if (s[i + 1] == 'x') { // cntf--; // i++; // } // else { // ans += cntf + 1; // cntf = 0; // } // } // else { // ans += cntf + 1; // cntf = 0; // } // } // if (s.back() == 'f') ans += cntf; // cout << ans << endl; // return 0; // }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll mod = 1000000007; template< typename T > T mod_pow(T x, T n, const T &p) { T ret = 1; while(n > 0) { if(n & 1) (ret *= x) %= p; (x *= x) %= p; n >>= 1; } return ret; } int main() { ll n, m; cin >> n >> m; ll x = mod_pow(10ll, n, m*m); cout << x / m << endl; }
#include <bits/stdc++.h> #define bug1(x) cout<<#x<<" = "<<x<<endl #define bug2(x,y) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<endl #define bug3(x,y,z) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<endl #define bug4(x,y,z,m) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<" "<<#m<<" = "<<m<<endl using namespace std; template<class L, class R> ostream& operator<<(ostream &os, const pair<L,R> &input) { os << "("; os << input.first << "," << input.second; return os << ")"; } template<class T> ostream& operator<<(ostream &os, const vector<T> &input) { os << "[ "; for(auto elem : input) { os << elem << " "; } return os << "]"; } template<class T> ostream& operator<<(ostream &os, const set<T> &input) { os << "{ "; for(auto elem : input) { os << elem << " "; } return os << "}"; } template<class T> ostream& operator<<(ostream &os, const unordered_set<T> &input) { os << "{ "; for(auto elem : input) { os << elem << " "; } return os << "}"; } template<class T> ostream& operator<<(ostream &os, const multiset<T> &input) { os << "{ "; for(auto elem : input) { os << elem << " "; } return os << "}"; } template<class T> ostream& operator<<(ostream &os, const unordered_multiset<T> &input) { os << "{ "; for(auto elem : input) { os << elem << " "; } return os << "}"; } template<class L, class R> ostream& operator<<(ostream &os, const map<L,R> &input) { os << "{ "; for(auto elem : input) { os << "(" << elem.first << " , " << elem.second << ") "; } return os << "}"; } template<class L, class R> ostream& operator<<(ostream &os, const unordered_map<L,R> &input) { os << "{ "; for(auto elem : input) { os << "(" << elem.first << " , " << elem.second << ") "; } return os << "}"; } #define ll long long const int MAXN = 500005; const int INF = 1e9; const int MOD = 998244353; class TaskA { private: int mod; int mul(int a, int b) { return (ll) a * b % mod; } int fastMod(int base, ll pot) { int ans = 1; while (pot) { if (pot & 1) { ans = mul(ans, base); } base = mul(base, base); pot/=2; } return ans; } public: void solveOne(int it){ ll n, m; cin >> n >> m; mod = m * m; int ans = fastMod(10, n); cout << (ans / m) % m << endl; } void solve(){ int tc = 1; for(int it = 1; it <= tc; it++){ solveOne(it); } } }; int main(){ ios_base::sync_with_stdio(false); TaskA solver; solver.solve(); return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define ld long double #define ui unsigned int #define ar array #define vt vector #define pb push_back #define all(c) (c).begin(), (c).end() #define sz(x) (int)(x).size() #define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s)) #define F_OR1(e) F_OR(i, 0, e, 1) #define F_OR2(i, e) F_OR(i, 0, e, 1) #define F_OR3(i, b, e) F_OR(i, b, e, 1) #define F_OR4(i, b, e, s) F_OR(i, b, e, s) #define GET5(a, b, c, d, e, ...) e #define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1) #define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__) #define EACH(x, a) for (auto& x: a) template<class A> void read(vt<A>& v); template<class A, size_t S> void read(ar<A, S>& a); template<class T> void read(T& x) { cin >> x; } void read(double& d) { string t; read(t); d=stod(t); } void read(long double& d) { string t; read(t); d=stold(t); } template<class H, class... T> void read(H& h, T&... t) { read(h); read(t...); } template<class A> void read(vt<A>& x) { EACH(a, x) read(a); } template<class A, size_t S> void read(array<A, S>& x) { EACH(a, x) read(a); } string to_string(char c) { return string(1, c); } string to_string(bool b) { return b?"true":"false"; } string to_string(const char* s) { return string(s); } string to_string(string s) { return s; } string to_string(vt<bool> v) { string res; FOR(sz(v)) res+=char('0'+v[i]); return res; } template<class A> void write(A x) { cout << to_string(x); } template<class H, class... T> void write(const H& h, const T&... t) { write(h); write(t...); } template<class T> void write(const vt<T>& x) { EACH(a, x){ write(a); write(' '); } write("\n"); } void print() { write("\n"); } template<class H, class... T> void print(const H& h, const T&... t) { write(h); if(sizeof...(t)) write(' '); print(t...); } void DBG() { cerr << "]" << endl; } template<class H, class... T> void DBG(H h, T... t) { cerr << to_string(h); if(sizeof...(t)) cerr << ", "; DBG(t...); } //Uncomment line when debugging, and comment out to remove all debug outputs directly // #define _DEBUG #ifdef _DEBUG #define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__) #else #define dbg(...) 0 #endif int main() { ios::sync_with_stdio(0); cin.tie(0); int a,b,c,d; read(a,b,c,d); int den = c*d-b; if(den<=0) print(-1); else { int ans = (a+den-1)/den; cout<<ans<<"\n"; } }
#include<bits/stdc++.h> #define int long long #define ll long long #define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define fs first #define sd second #define rept(x,n) for(int i=x;i<n;i++) #define rrept(n,x) for(int i=n-1;i>=x;i--) #define all(v) v.begin(),v.end() #define mpit map<int,int>::iterator #define stit set<int,int>::iterator #define quit queue<int,int>::iterator #define maxt(a,b,c) max(a,max(b,c)) #define mint(a,b,c) min(a,min(b,c)) #define rsort(v) sort(v.rbegin(),v.rend()) #define pb push_back #define printarr(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" ";cout<<"\n"; #define printvec(v) for(int i = 0;i<v.size();i++)cout<<v[i]<<" ";cout<<"\n"; using namespace std; ll power(ll a,ll b){ll res = 1;while(b){if(b&1)res*=a;a*=a;b/=2;}return res;} ll powerwithmod(ll a,ll b,ll mod){ll res = 1;while(b){if(b&1)res*=a;res%=mod;a*=a;a%=mod;b/=2;}return res;} void sieve(vector<ll>&prime,ll n){ll candidate[n+1]={0};candidate[0]=1;candidate[1]=1;candidate[2]=0; for(ll i = 4;i<=n;i+=2)candidate[i]=1;for(ll i = 3;i*i<=n;i+=2){if(candidate[i]==0){ for(ll j = i*i;j<=n;j+=i){candidate[j] = 1;}}}for(ll i = 2;i<=n;i++){if(candidate[i]==0)prime.pb(i);}} /*-------------------------------------------------------------------------------------------------------*/ void solve() { ll a,b,c,d; cin>>a>>b>>c>>d; ll fir = c*d; ll sec = b; if(fir<=sec) { cout<<"-1\n"; } else { cout<<(a + fir - sec - 1)/(fir-sec); } } signed main() { speed; int t=1; //cin>>t; while(t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(12); int n, d, h; cin >> n >> d >> h; vector<int> a(n), b(n); for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; } long double lo = 0, hi = (long double) h; long double res; for (int i = 0; i < 100; i++) { long double mid = (lo + hi) / 2.0; long double slope = ((long double) h - mid) / (long double) d; bool ok = true; for (int j = 0; j < n; j++) { long double cur = slope * (long double) a[j] + mid; if (cur < (long double) b[j]) { ok = false; } } if (ok) { res = mid; hi = mid - 1; } else { lo = mid + 1; } } cout << max((long double) 0, res) << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; #define lld long long int #define M 1000000007 #define fors(i,n) for(int i=0;i<n;++i) #define fore(i,a,b) for(int i=a;i<=b;++i) #define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define vv vector<int> #define endl "\n" #define test(i) cout<<i<<endl #define itrt int t; cin>>t; fors(i,t) #define itr1 int t; cin>>t; #define ff first #define ss second #define pb push_back #define vmp make_pair #define ppb pop_back #define sorta(arr,n) sort(arr,arr+n) #define sortv(x) sort(x.begin(),x.end()) void file(){ #ifdef LOCAL freopen("demo.in","r",stdin); freopen("demo.out","w",stdout); #endif } // lld sum=0; // vector<int> visited(2001); // vector<int>arr[2001]; // void dfs(int i){ // visited[i]=1; // ++sum; // for(int x:arr[i]){ // if(visited[x]){ // continue; // } // dfs(x); // } // } void run(){ int n; cin>>n; bitset<100001> dp; dp[0]=1; int sum=0; fors(i,n){ int x; cin>>x; sum+=x; dp |= dp<<x; } // cout<<"sum: "<<sum/2<<endl; int temp = sum; for(int i=0;i<=sum;++i){ if(dp[i]){ temp = min(temp,max(i,sum-i)); } } // cout<<"ans:"<<endl; cout<<temp<<endl; } int main(){ fastio; // // file(); int t=1; // cin>>t; for(int nr=0;nr<t;++nr){ run(); } }
#include <iostream> using namespace std; int main(){ int a,b,c; cin >> a >> b >> c; if(a==b){ cout << c << endl; }else if(a==c){ cout << b << endl; }else if(b==c){ cout << a << endl; }else{ cout << "0" << endl; } }
//clear adj and visited vector declared globally after each test case //check for long long overflow //Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod; //Incase of close mle change language to c++17 or c++14 #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #define int long long #define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10); #define pb push_back #define mod 1000000007ll //998244353ll #define lld long double #define mii map<int, int> #define pii pair<int, int> #define ff first #define ss second #define all(x) (x).begin(), (x).end() #define rep(i,x,y) for(int i=x; i<y; i++) #define fill(a,b) memset(a, b, sizeof(a)) #define vi vector<int> #define setbits(x) __builtin_popcountll(x) #define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";} typedef std::numeric_limits< double > dbl; using namespace __gnu_pbds; using namespace std; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; //member functions : //1. order_of_key(k) : number of elements strictly lesser than k //2. find_by_order(k) : k-th element in the set const long long N=200005, INF=2000000000000000000; lld pi=3.1415926535897932; int lcm(int a, int b) { int g=__gcd(a, b); return a/g*b; } int power(int a, int b, int p) { if(a==0) return 0; int res=1; a%=p; while(b>0) { if(b&1) res=(res*a)%p; b>>=1; a=(a*a)%p; } return res; } int32_t main() { IOS; int a, b, c; cin>>a>>b>>c; cout<<21-a-b-c; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base ::sync_with_stdio(0); cin.tie(0); int a, b, c, d; cin >> a >> b >> c >> d; int x= (a * d) - (c * b); cout << x; return 0; }
#include <bits/stdc++.h> using namespace std; #define long long long #define vb vector<bool> #define vi vector<int> #define vii vector<pair<int, int>> #define vs vector<string> #define FOR(i,a,b) for (int i = a; i < b; i++) #define FORs(i,a,b,c) for (int i = a; i < b; i+=c) #define DPMOD 1000000007 int main() { // freopen("input.txt", "r", stdin); int a; cin >> a; int b; cin >> b; int c; cin >> c; int d; cin >> d; cout << a*d - b*c << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); cin.sync_with_stdio(0); int n, k; cin >> n >> k; const int LIM = 3010; const long long MOD = 998244353; long long dp[LIM][LIM]; // dp[i][j] = number of multisets that leave // i elements to choose and j is the remaining sum for(int i = 0; i<LIM; ++i) { for(int j = 0; j<LIM; ++j) { dp[i][j] = 0; } } dp[n][k] = 1; for(int i = n; i>0; --i) { for(int j = LIM-1; j>0; --j) { int ways = dp[i][j]; for(int k = 0; ; ++k) { int next_remaining = j*(1<<k)-1; if(next_remaining >= LIM) { break; } if(next_remaining >= 0) { dp[i-1][next_remaining] = (dp[i-1][next_remaining] + ways) % MOD; } } } } cout << dp[0][0] << endl; }
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(ll i=0;i<n;i++) #define repl(i,l,r) for(ll i=(l);i<(r);i++) #define per(i,n) for(ll i=n-1;i>=0;i--) #define perl(i,r,l) for(ll i=r-1;i>=l;i--) #define fi first #define se second #define pb push_back #define mkp make_pair #define ins insert #define pqueue(x) priority_queue<x,vector<x>,greater<x>> #define all(x) (x).begin(),(x).end() #define CST(x) cout<<fixed<<setprecision(x) #define vtpl(x,y,z) vector<tuple<x,y,z>> #define rev(x) reverse(x); #define lin(x) ll x; cin>>x; #define stin(x) string x; cin>>x; #define yn(x) if(x) { cout<<"Yes"<<endl; } else { cout<<"No"<<endl; } #define YN(x) if(x) { cout<<"YES"<<endl; } else { cout<<"NO"<<endl; } #define co(x) cout<<x<<endl; using ll=long long; using ld=long double; using vl=vector<ll>; using vvl=vector<vector<ll>>; using pl=pair<ll,ll>; using vpl=vector<pl>; using vvpl=vector<vpl>; const ll mod=1000000007; const ll MOD9=998244353; const int inf=1e9+10; const ll INF=4e18; const ll dy[8]={1,0,-1,0,1,1,-1,-1}; const ll dx[8]={0,-1,0,1,1,-1,1,-1}; template <typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); } template <typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); } ll powmod(ll n, ll k, ll m) { ll r=1; for(; k>0; k >>=1) { if(k&1) r=(r*n)%m; n=(n*n)%m; } return r; } ll fact(ll n) { ll a=1; rep(i,n) { a=a*(n-i); } return a; } ll pow(ll a, ll b) { ll x=1; rep(i,b) { x=x*a; } return x; } int main() { lin(X); if(X%100==0) { co(100); } else { ll aa=X%100; co(100-aa); } }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef double db; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpii; typedef vector<pll> vpll; #define FOR(n) for(int i=0;i<n;++i) #define FOR1(n) for(int i=1;i<=n;++i) #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll gcd(ll a, ll b) { return a % b ? gcd(b, a % b) : b; } const ll mod = 1e9 + 7; const ll inf = 0x3f3f3f3f; ll qpow(ll a, ll b) { ll t = 1; while (b != 0) { if (b & 1)t = (t * a) % mod; a = (a * a) % mod; b >>= 1; }return t; } void re(vi& a) { for (auto& t : a)cin >> t; }void re(vl& a) { for (auto& t : a)cin >> t; } void pr(vi& a) { for (auto& t : a)cout << t << " "; cout << endl; } void pr(vl& a) { for (auto& t : a)cout << t << " "; cout << endl; } signed main() { int n; cin >> n; vi a(n), b(n); FOR(n)cin >> a[i] >> b[i]; int ans = inf; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { if (i != j)ans = min(ans, max(a[i], b[j])); else ans = min(ans, a[i] + b[j]); } } cout << ans; }
//#include <fsociety> #include <cmath> #include <deque> #include <algorithm> #include <iterator> #include <list> #include <map> #include <unordered_map> #include <queue> #include <set> #include <unordered_set> #include <stack> #include <string> #include <vector> #include <fstream> #include <iostream> #include <iomanip> #include <stdio.h> //end of libraries ; // freopen("input.in","r",stdin); // freopen("output.out","w",stdout); #define lnf 3999999999999999999 #define inf 999999999 #define PI 3.14159265359 #define endl "\n" #define fi first #define se second #define pb push_back #define ll long long #define all(c) (c).begin(),(c).end() #define sz(c) (int)(c).size() #define mkp(a,b) make_pair(a,b) #define rsz(a,n) a.resize(n) #define pii pair <int,int> #define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0); const int N = 2441; using namespace std; int n , m , value; ll a[ N ][ N ] , ro[ N ] , col[ N ] , mod = 1e9+7 ; map <ll,ll> dia; char ch; int main(){ fcin; cin >> n >> m ; for(int i = 0 ; i < n ; i++) { for(int j = 0 ; j < m ; j++) { cin >> ch; a[i][j] = (ch == '.'); } } ll ans = 0; for(int i = 0 ; i < n ; i++){ for(int j = 0 ; j < m ; j++){ if(!a[i][j]) { dia[i-j] = 0; ro[i] = 0; col[j] = 0; continue; } if(!i && !j) { dia[0] = 1; col[j] = 1; ro[i] = 1; } else { value = dia[ i - j ] % mod; value += col[j] % mod; value %= mod; value += ro[i] % mod; value %= mod; dia[i - j] += value; dia[i-j] %= mod; col[j] += value; col[j] %= mod; ro[i] += value; ro[i] %= mod; if(i == n - 1 && j == m - 1) ans = value; } } } cout << ans << "\n"; return 0; }
#include <iostream> using namespace std; int x; int main() { cin >> x; int now = 1; while (now <= 33) { if (now <= x && now * 100 >= x) { cout << now << endl; exit(0); } now = now + 1; } }
//Update : 2021.5.7 #include<bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long ll; typedef long double ld; typedef pair<int,int> pii ; typedef pair<long long,long long> pll; //#define endl '\n' /*Debugger #define tpc template<class c #define ckt(x) tpc> typename enable_if<sizeof ptb<c>(0) x 1, debug&>::type #define rpt return *this #define dop debug& operator << tpc> struct rge { c b, e; }; tpc> rge<c> range(c x, c y) { return rge<c>{x, y}; } tpc> auto ptb(c* x) -> decltype(cerr << *x, 0); tpc> char ptb(...); struct debug { #ifdef LOCAL ~debug() {cerr << "\u001b[0m\n";} debug() {cerr << "\u001b[92m";} ckt(!=) operator <<(c x) { cerr << boolalpha << x; rpt; } ckt(==) operator <<(c x) { rpt << range(x.begin(), x.end()); } tpc, class b> dop(pair<c,b> x) { rpt << "(" << x.first << ", " << x.second << ")"; } tpc> dop(rge<c> r) { *this << "{"; for(auto it = r.b; it != r.e; ++it) *this << ", "+2*(it==r.b) << *it; rpt << "}"; } #else tpc> dop(const c&) {rpt;} #endif }; #define watch(...) "[" << #__VA_ARGS__ " = " << (__VA_ARGS__) << "] " //调试工具*/ ull M = 1e9+7; //998244353; 1e9+9; const int N = 100005; //105; 455; 1005; 200005; 300005; 4000005; ll n,m,k,a,b,p,q,r,t; //ll A[]; string s; void input(){ cin>>b; } void solve(){ input(); cout<<(b+99)/100<<endl; } void TC(){ int tc=1; //cin>>tc; for(int t=1;t<=tc;t++){ //cout<<"Case #"<<t<<":"; solve(); } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(0); //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); //system(""); //Buat menyalakan warna pada debugger TC(); } /* */
#include <bits/stdc++.h> //#include <atcoder/modint> //#include <atcoder/math> //#include <boost/multiprecision/cpp_int.hpp> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> #pragma GCC optimize("O3") #define REP(i, n) for(int i = 0; i < n; i++) #define REPP(i, n) for(int i = 1; i <= n; i++) #define ALL(obj) (obj).begin(), (obj).end() #define EPS (1e-9) #define INF (1e17) #define PI (acos(-1)) //const double PI = acos(-1); //const double EPS = 1e-15; //long long INF=(long long)1E17; #define i_7 (long long)(1e9+7) //#define i_7 998'244'353 long mod(long a){ long long c = a % i_7; if(c >= 0) return c; return c + i_7; } long long po(long a, long b){ if(b == 0) return 1; long long z = po(a , b / 2); z = mod(z * z); if(b % 2 != 0) z = mod(a * z); return z; } bool prime_(int n){ if(n == 1){ return false; }else if(n == 2){ return true; }else{ for(int i = 2; i <= std::sqrt(n); i++) if(n % i == 0) return false; return true; } } long long gcd_(long long a, long long b){ if(a < b) std::swap(a,b); if(a % b == 0) return b; else return gcd_(b, a % b); } long long lcm_(long long x, long long y){ return (x / gcd_(x,y)) * y; } using namespace std; //using namespace atcoder; //using mint = modint1000000007; //using mint = modint998244353; //using namespace boost::multiprecision; //using namespace __gnu_pbds; int main(){ //using namespace std; string s; cin>>s; int n = s.size(); string ans; for(int i = n - 1; i >= 0; i--){ if(s[i] == '6') ans.push_back('9'); else if(s[i] == '9') ans.push_back('6'); else ans.push_back(s[i]); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define int int64_t using namespace std; const int LG=2e5+5; int a[LG], viz[LG]; vector<int> v[LG]; void dfs(int nod) { viz[nod]=1; for (auto el:v[nod]) if (!viz[el]) dfs(el); } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin>>n; map<int,int> m; for (int i=1;i<=n;i++) { cin>>a[i]; m[a[i]]++; } int ans=m.size(); for (int i=1;i<=n/2;i++) { int f=a[i]; int s=a[n+1-i]; if (f!=s) { v[f].push_back(s); v[s].push_back(f); } } for (int i=1;i<=n;i++) { if (!viz[a[i]]) { dfs(a[i]); ans--; } } cout<<ans; return 0; }
#include<bits/stdc++.h> using namespace std; int a[1005]; int b[1100][1100]; int c[1100]; void gmin(int x) { for(int i=2;i<=x;i++) { if(x%i==0) b[x][++c[x]]=i; } } inline int read() { char ch=getchar(); int x=0,f=1; while(ch>'9'||ch<'0') { if(ch=='-') f=-1; ch=getchar(); } while(ch<='9'&&ch>='0') { x=x*10+ch-'0'; ch=getchar(); } return x*f; } int main() { int n; scanf("%d",&n); for(int i=1;i<=n;i++) { //a[i]=read(); scanf("%d",&a[i]); } int maxx=-1,maxd; for(int i=1;i<=n;i++) { gmin(a[i]); for(int k=1;k<=c[a[i]];k++) { int cnt=0; for(int j=1;j<=n;j++) { if(a[j]%b[a[i]][k]==0) cnt++; if(cnt>maxx) { maxx=cnt; maxd=b[a[i]][k]; } } } } printf("%d",maxd); return 0; }
#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 kaigyo cout<<endl #define eps 1e-7 #define mp(a1,a2) make_pair(a1,a2) #define ALL(a) (a).begin(),(a).end() #define rALL(a) (a).rbegin(),(a).rend() #define puba(a) emplace_back(a) #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(){ string S; scan(S); int N=S.size(); /* int rui[26][200001]={}; rep(k,26){ brep(i,N){ rui[k][i]=rui[k][i+1]+(S[i]-'a'==k); } }*/ /*vint rensoeji; for(int i=N-1;i>=1;--i){ if(S[i-1]==S[i]){ rensoeji.puba(i); } }*/ int charnum[26]={}; bool ren[200001]={}; for(int i=N-1;i>=1;--i){ if(S[i-1]==S[i]) ren[i]=1; } ll ans=0; brep(i,N){ if(ren[i]){ ans+=N-1-i-charnum[S[i]-'a']; rep(k,26){ if(S[i]-'a'==k) charnum[k]=N-1-i; else charnum[k]=0; } } charnum[S[i]-'a']++; } prin(ans); return 0; }
#include <iostream> using namespace std; int64_t gcd(int64_t a, int64_t b) { if (a%b == 0) { return(b); } else { return(gcd(b, a%b)); } } int64_t lcm(int64_t a, int64_t b) { return a * b / gcd(a, b); } int main() { int N; cin >> N; int64_t arrlcm = 1; for(int i = 2; i <= N; i++){ arrlcm = lcm(i,arrlcm); } cout << arrlcm + 1 << endl; return 0; }
//#include <bits/stdc++.h> //using namespace std; #include <set> #include <cstdio> #include <iostream> using namespace std; #define rep(i,_l,_r) for(signed i=(_l),_end=(_r);i<=_end;++i) #define fep(i,_l,_r) for(signed i=(_l),_end=(_r);i>=_end;--i) #define erep(i,u) for(signed i=head[u],v=to[i];i;i=nxt[i],v=to[i]) #define efep(i,u) for(signed i=Head[u],v=to[i];i;i=nxt[i],v=to[i]) #define print(x,y) write(x),putchar(y) //#define debug(...) do {cerr<<__LINE__<<" : ("#__VA_ARGS__<<") = "; Out(__VA_ARGS__); cerr<<flush;} while(0) //template <typename T> void Out(T x) {cerr<<x<<"\n";} //template <typename T,typename ...I> void Out(T x,I ...NEXT) {cerr<<x<<", "; Out(NEXT...);} template <class T> inline T read(const T sample) { T x=0; int f=1; char s; while((s=getchar())>'9'||s<'0') if(s=='-') f=-1; while(s>='0'&&s<='9') x=(x<<1)+(x<<3)+(s^48),s=getchar(); return x*f; } template <class T> inline void write(const T x) { if(x<0) return (void) (putchar('-'),write(-x)); if(x>9) write(x/10); putchar(x%10^48); } template <class T> inline T Max(const T x,const T y) {if(x>y) return x; return y;} template <class T> inline T Min(const T x,const T y) {if(x<y) return x; return y;} template <class T> inline T fab(const T x) {return x>0?x:-x;} template <class T> inline T gcd(const T x,const T y) {return y?gcd(y,x%y):x;} template <class T> inline T lcm(const T x,const T y) {return x/gcd(x,y)*y;} template <class T> inline T Swap(T &x,T &y) {x^=y^=x^=y;} typedef pair <int,int> pii; const int maxn=2e5+5; set <pii> s; int n; long long c[maxn]; set <pii> :: iterator it; int lowbit(int x) { return x&-x; } void add(int x,int k) { while(x<=n) c[x]+=k,x+=lowbit(x); } long long ask(int x) { long long r=0; while(x) r+=c[x],x-=lowbit(x); return r; } int main() { n=read(9); long long ans=0; rep(i,1,n) s.insert(make_pair(read(9)+i,i)); rep(i,1,n) { int x=read(9); it=s.lower_bound(make_pair(x+i,0)); if(it==s.end() || (it->first)!=x+i) return puts("-1"),0; long long tmp=ask(it->second); add(1,1),add(it->second,-1); ans+=tmp+(it->second)-i; s.erase(it); } print(ans,'\n'); return 0; }
#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstring> #include <deque> #include <forward_list> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> PII; typedef pair<int, ll> PIL; typedef pair<ll, int> PLI; typedef pair<ll, ll> PLL; typedef bitset<16> BS; struct edge { int to, cost, id; }; const double PI = 3.14159265358979323846; const double EPS = 1E-09; const ll MOD = 1E+09 + 7; // =998244353; const ll INFL = 1E18; const int INFI = 1E09; const int MAX_N = 20; struct unionfind { vector<int> par, t_rank, siz; vector<bool> cyc; unionfind(int n) //n要素で初期化(1-indexed) : par(n + 1) , t_rank(n + 1) , siz(n + 1) { // n要素で初期化 // 1-indexedになっているので0-indexedで使いたいときは注意 for (int i = 1; i <= n; i++) { par[i] = i; siz[i] = 1; t_rank[i] = 0; } } // 木の根を求める int find(int x) { if (par[x] == x) { return x; } else { return par[x] = find(par[x]); } } // xとyの属する集合を併合 void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (t_rank[x] < t_rank[y]) { par[x] = y; siz[y] += siz[x]; } else { par[y] = x; siz[x] += siz[y]; if (t_rank[x] == t_rank[y]) t_rank[x]++; } } // xとyが同じ集合に属するか否か bool same(int x, int y) { return find(x) == find(y); } // xの属するグループのサイズを求める int size(int x) { return siz[find(x)]; } }; ll dx[4] = { -1, 1, 0, 0 }, dy[4] = { 0, 0, -1, 1 }; int N, M; vector<int> G[MAX_N + 1]; bool used[MAX_N + 1], check[MAX_N + 1]; int C[MAX_N + 1]; void dfs(int v, vector<int>& vec); ll paint(int i, int c, vector<int>& vec); int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> N >> M; auto uft = unionfind(N); fill(C + 1, C + N + 1, -1); for (int i = 1; i <= M; i++) { int a, b; cin >> a >> b; G[a].push_back(b); G[b].push_back(a); uft.unite(a, b); } ll ans = 1; for (int i = 1; i <= N; i++) { if (!used[uft.find(i)]) { vector<int> vec = { i }; dfs(i, vec); // for (auto v : vec) { // cout << v << " "; // } // cout << "\n"; ans *= 3 * paint(0, 0, vec); used[uft.find(i)] = true; } } /* for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { cout << "i = " << i << ", j = " << j << ", dp = " << dp[i][j] << "\n"; } } */ cout << ans << "\n"; return 0; } void dfs(int v, vector<int>& vec) { check[v] = true; for (auto to : G[v]) { if (!check[to]) { vec.push_back(to); dfs(to, vec); } } } ll paint(int i, int c, vector<int>& vec) { if (i + 1 == vec.size()) return 1; ll res = 0; bool usedc[3]; fill(usedc, usedc + 3, false); int v = vec[i], w = vec[i + 1]; C[v] = c; for (auto to : G[w]) { if (C[to] != -1) usedc[C[to]] = true; } for (int _c = 0; _c < 3; _c++) { if (!usedc[_c]) res += paint(i + 1, _c, vec); } C[v] = -1; return res; }
#include <bits/stdc++.h> using namespace std; #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; template<typename T> using Graph = vector<vector<T>>; template<typename T> using Spacial = vector<vector<vector<T>>>; template<typename T> using greater_priority_queue = priority_queue<T, vector<T>, greater<T>>; constexpr int MOD = 1e9+7; constexpr int MOD2 = 998244353; const int dx[4] = { 1, 0, -1, 0 }; const int dy[4] = { 0, 1, 0, -1 }; char interval[2] = {' ', '\n'}; template<typename T> struct is_plural : false_type{}; template<typename T1, typename T2> struct is_plural<pair<T1, T2>> : true_type{}; template<typename T> struct is_plural<vector<T>> : true_type{}; template<typename T> struct is_plural<complex<T>> : true_type{}; template<> struct is_plural<string> : true_type{}; template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second; } template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second; } template<typename T> istream &operator>>(istream &is, vector<T> &vec) { for(auto itr = vec.begin(); itr != vec.end(); ++itr) is >> *itr; return is; } template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { if(vec.empty()) return os; bool pl = is_plural<T>(); os << vec.front(); for(auto itr = ++vec.begin(); itr != vec.end(); ++itr) os << interval[pl] << *itr; return os; } template<typename T> istream &operator>>(istream &is, complex<T> &x) { T a, b; is >> a >> b; x = complex<T>(a, b); return is; } template<typename T> ostream &operator<<(ostream &os, complex<T> &x) { return os << x.real() << ' ' << x.imag(); } bool CoutYN(bool a, string y = "Yes", string n = "No") { cout << (a ? y : n) << '\n'; return a; } 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); } /* -------- <templates end> -------- */ void solve() { ll a, b; cin >> a >> b; vector<int> prime = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71 }; vector<int> pos(72, -1); for(int i=0; i<20; ++i) pos[prime[i]] = i; vector<ll> dp(1<<20, 0); dp[0] = 1; for(ll x=a; x<=b; ++x) { bitset<20> bs(0); for(int i=0; i<20; ++i) { bs.set(i, x % prime[i] == 0); } for(int i=(1<<20)-1; i>=0; --i) { if(!dp[i]) continue; bitset<20> now(i); auto d = now & bs; if(d.none()) { d = now | bs; dp[d.to_ullong()] += dp[i]; } } } cout << accumulate(ALL(dp), 0LL) << endl; } /* -------- <programs end> -------- */ signed main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); solve(); return 0; }
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<vector> #include<queue> #include<set> #include<map> #include<string> #include<cmath> #define SYNC ios::sync_with_stdio(0),cin.tie(0) #define PI acos(-1.0) #define INF 0x3f3f3f3f #define EPS 1e-6 #define endl '\n' using namespace std; const int MAXN = 11450; int N; int A[MAXN]; int L[MAXN], R[MAXN]; void solve(){ cin >> N; A[0] = A[N+1] = -INF; for(int i = 1; i <= N; ++i) L[i] = R[i] = 0; for(int i = 1; i <= N; ++i) cin >> A[i]; for(int i = 1; i <= N; ++i){ int now_min = A[i]; int nowl = i - 1; while(now_min <= A[nowl]) nowl = L[nowl] - 1; L[i] = nowl + 1; } for(int i = N; i >= 1; --i){ int now_min = A[i]; int nowr = i + 1; while(now_min <= A[nowr]) nowr = R[nowr] + 1; R[i] = nowr - 1; } int ans = -INF; for(int i = 1; i <= N; ++i){ int now_ans = A[i] * (R[i] - L[i] + 1); ans = max(ans, now_ans); } cout << ans << endl; } int main(){ SYNC; solve(); }
#include <bits/stdc++.h> #include <unordered_set> // 重複排除した集合 using namespace std; #define ll long long #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { ll N; cin >> N; vector<ll> dp(N); vector<ll> A(N); // vector<Pair<int, int> > B(N); rep(i,N){ cin >> A[i]; } long long ans = 0; rep(left,N){ ll right = left; // [left, right) の総和が x 以下となる最大の right を求める ll min_a = A[left]; /* sum に a[right] を加えても大丈夫なら right を動かす */ while (right < N) { min_a = min(min_a,A[right]); ans = max(ans, min_a*(right-left+1)); ++right; } /* break した状態で right は条件を満たす最大 */ // dp[left] = ans; // cout << sum << endl; } cout << ans; }
#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++) using namespace std; int main() { double A, B; cin >> A >> B; double ans = (1 - B/A)*100; cout << fixed << setprecision(10) << ans << endl; }
//#include<bits/stdc++.h> //typedef long long ll; //const ll mod=1e9+7; //const ll inf=0x3f3f3f3f; //const int N=2e5+5; //using namespace std; // //ll a[N],b[N],c[N]; //int main() //{ // int n; // cin>>n; // for(int i=0;i<n;i++) // { // cin>>a[i]>>b[i]>>c[i]; // } // int ans=inf; // for(int i=0;i<n;i++) // { // if(a[i]<c[i]) ans=min(ans,b[i]); // } // if(ans==inf) ans=-1; // cout<<ans<<endl; // return 0; //} #include<bits/stdc++.h> typedef long long ll; const ll mod=1e9+7; const ll inf=0x3f3f3f3f; const int N=2e5+5; using namespace std; int main() { double a,b;cin>>a>>b; cout<<(a-b)/a*100<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vi2 = vector<vector<int>>; using vl = vector<ll>; using vl2 = vector<vector<ll>>; using vb = vector<bool>; using vb2 = vector<vector<bool>>; using vc = vector<char>; using vc2 = vector<vector<char>>; using vs = vector<string>; using si = set<int>; using vs2 = vector<vector<string>>; using pii = pair<int, int>; using mii = map<int, int>; const int INF = 1e9+1; const ll LINF = 1e18+1; const long double LPI = acos(-1.0); const double PI = acos(-1.0); const int mod = 1000000007; #define MP(a,b) make_pair((a),(b)) #define MT(...) make_tuple(__VA_ARGS__) #define sz(x) (int)(x).size() #define FOR(i,a,b) for(ll i=(a);i<(b);i++) #define REP(i,x) for(int i=0;i<(int)(x);i++) #define REPS(i,x) for(ll i=1;i<=(int)(x);i++) #define RREP(i,x) for(ll i=((int)(x)-1);i>=0;i--) #define RREPS(i,x) for(ll i=((int)(x));i>0;i--) #define ALL(x) (x).begin(),(x).end() #define RALL(x) (x).rbegin(),(x).rend() #define SORT(v) sort(ALL(v)); #define RSORT(v) sort(RALL(v)); #define IN(type,a) type a;cin >> a; #define VIN(type,a,n) vector<type> a(n);cin >> a; #define YES(n) cout << ((n) ? "YES" : "NO" ) << endl; #define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl; #define COUT(x) cout << (x) << endl; #define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl; #define ENDL cout << endl; #define DB(s,x) cout << (s) << " : " << x << endl; #define HOGE COUT("HOGE") template<typename T>inline istream& operator>>(istream&i,vector<T>&v) {REP(j,sz(v))i>>v[j];return i;} template<typename T> bool chmax(T& a, const T& b){if(a<b){a=b;return true;}return false;} template<typename T> bool chmin(T& a, const T& b){if(a>b){a=b;return true;}return false;} template<typename T> T gcd(T a,T b){if(b==0){return a;}else{return gcd(b, a%b);}} template<typename T> T lcm(T a,T b){return a*b/gcd(a, b);} template<typename T> bool isPrime(T a){if(a<=1){return false;} for(T i=2;i*i<=a;i++){if (a%i==0) {return false;}}return true;} template<typename T> T ord(T p,T n){T ans=0;while(true){if(n%p==0){n/=p;ans++;}else{break;}}return ans;} struct mint { ll x; // typedef long long ll; mint(ll x=0):x((x%mod+mod)%mod){} mint operator-() const { return mint(-x);} mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;} mint operator+(const mint a) const { return mint(*this) += a;} mint operator-(const mint a) const { return mint(*this) -= a;} mint operator*(const mint a) const { return mint(*this) *= a;} mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod-2);} mint& operator/=(const mint a) { return *this *= a.inv();} mint operator/(const mint a) const { return mint(*this) /= a;} }; istream& operator>>(istream& is, mint& a) { return is >> a.x;} ostream& operator<<(ostream& os, const mint& a) { return os << a.x;} int main() { IN(ll, n); set<ll> s; REP(i, n){ ll k; cin >> k; s.insert(k); } while (true) { if (s.size()==1) { break; } auto ei = s.end(); ei--; ll k = *ei; s.erase(ei); s.insert(k-*s.begin()); } COUT(*s.begin()); }
#include<stdio.h> int main() { int n,i,j,m=0,k=1000000000,panduan=0; int static a[100000][3]; int static b[100000]; scanf("%d",&n); for(i=0;i<n;i++) { for(j=0;j<3;j++) scanf("%d",&a[i][j]); } b[0]=-1; for(i=0;i<n;i++) { if(a[i][0]<a[i][2]) { b[m]=a[i][1]; m++; panduan=1; } } for(i=0;i<m;i++) { if(b[i]<k) k=b[i]; } if(panduan==0){ printf("-1"); } else { printf("%d",k);} return 0; }
#include <bits/stdc++.h> #include <random> using namespace std; typedef unsigned long long _ulong; typedef long long int lint; typedef pair<lint, lint> plint; typedef pair<double long, double long> pld; #define ALL(x) (x).begin(), (x).end() #define SZ(x) ((lint)(x).size()) #define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;++i) #define IFOR(i, begin, end) for(lint 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 endk '\n' #define fi first #define se second struct fast_ios { fast_ios() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); }; } fast_ios_; template<class T> auto add = [](T a, T b) -> T { return a + b; }; template<class T> auto f_max = [](T a, T b) -> T { return max(a, b); }; template<class T> auto f_min = [](T a, T b) -> T { return min(a, b); }; template<class T> using V = vector<T>; using Vl = V<lint>; using VVl = V<Vl>; template< typename T > ostream& operator<<(ostream& os, const vector< T >& v) { for (int i = 0; i < (int)v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; } template< typename T >istream& operator>>(istream& is, vector< T >& v) { for (T& in : v) is >> in; return is; } template<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; } lint gcd(lint a, lint b) { if (b == 0) return a; else return gcd(b, a % b); } lint ceil(lint a, lint b) { return (a + b - 1) / b; } lint digit(lint a) { return (lint)log10(a); } lint e_dist(plint a, plint b) { return abs(a.fi - b.fi) * abs(a.fi - b.fi) + abs(a.se - b.se) * abs(a.se - b.se); } lint m_dist(plint a, plint b) { return abs(a.fi - b.fi) + abs(a.se - b.se); } void Worshall_Floyd(VVl& g) { REP(k, SZ(g)) REP(i, SZ(g)) REP(j, SZ(g)) chmin(g[i][j], g[i][k] + g[k][j]); } const lint MOD = 1e9 + 7, INF = LLONG_MAX; lint dx[8] = { 1, 0, -1, 0, 1, -1, 1, -1 }, dy[8] = { 0, 1, 0, -1, -1, -1, 1, 1 }; bool YN(bool flag) { cout << (flag ? "YES" : "NO") << endk; return flag; } bool yn(bool flag) { cout << (flag ? "Yes" : "No") << endk; return flag; } struct Edge { lint from, to; lint cost; Edge(lint u, lint v, lint c) { cost = c; from = u; to = v; } bool operator<(const Edge& e) const { return cost < e.cost; } }; struct WeightedEdge { lint to; lint cost; WeightedEdge(lint v, lint c = 1) { to = v; cost = c; } bool operator<(const WeightedEdge& e) const { return cost < e.cost; } }; using WeightedGraph = V<V<WeightedEdge>>; typedef pair<plint, lint> tlint; typedef pair<plint, plint> qlint; typedef pair<string, lint> valstring; lint N, M, K; int main() { cin >> N >> M >> K; Vl arr(K); cin >> arr; long double initok = 1; lint cnt = 1; if (M == 1 && K == 1) { cout << -1 << endk; return 0; } REP(i, K - 1) { if (arr[i] + 1 == arr[i + 1]) cnt++; else cnt = 1; if (cnt >= M) { cout << -1 << endk; return 0; } } auto check = [&](long double e0) { V<long double> dp(N + M + 1, 0); REP(i, K) dp[arr[i]] = -1; long double sum = M; IREP(i, N) { if (dp[i + M + 1] == -1) { sum -= e0 + 1; } else sum -= (dp[i + M + 1] + 1); if (dp[i + 1] == -1) { sum += e0 + 1; } else sum += (dp[i + 1] + 1); if(dp[i] != -1) dp[i] = sum / M; } return dp[0] <= e0; }; long double ok = INF, ng = -1; REP(_, 100) { long double mid = (ok + ng) / 2; if (check(mid)) ok = mid; else ng = mid; } cout << ok << endk; }
#include <iostream> #include <cstdio> #include <string> #include <algorithm> #include <utility> #include <cmath> #include <vector> #include <stack> #include <queue> #include <deque> #include <set> #include <map> #include <tuple> #include <numeric> #include <functional> using namespace std; typedef long long ll; typedef vector<ll> vl; typedef vector<vector<ll>> vvl; typedef pair<ll, ll> P; #define rep(i, n) for(ll i = 0; i < n; i++) #define exrep(i, a, b) for(ll i = a; i <= b; i++) #define out(x) cout << x << endl #define exout(x) printf("%.10f\n", x) #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define pb push_back #define re0 return 0 const ll mod = 1000000007; const ll INF = 1e16; // 'R' = 0, 'P' = 1, 'S' = 2 と対応させる ll f(ll x, ll y) { if(x == y) { return x; } if(x+y == 1) { return 1; } else if(x+y == 2) { return 0; } else if(x+y == 3) { return 2; } } int main() { ll n, k; string s; cin >> n >> k >> s; vl two(k); // two[i] : 2^i(mod.n) two[0] = 1; rep(i, k-1) { two[i+1] = 2*two[i]%n; } vvl dp(k+1, vl(n)); // dp[i][j] : i回戦で、区間の左端がjのときの勝者の手 rep(j, n) { rep(x, 3) { if(s[j] == "RPS"[x]) { dp[0][j] = x; } } } rep(i, k) { rep(j, n) { dp[i+1][j] = f(dp[i][j], dp[i][(j + two[i])%n]); } } out("RPS"[dp[k][0]]); re0; }
#include<bits/stdc++.h> using namespace std; using ll = long long int; using ld = long double; #define pow(n,m) powl(n,m) #define sqrt(n) sqrtl(n) const ll MAX = 5000000000000000000; const ll MOD = 0; random_device rd; mt19937 mt(rd()); int main(){ ll N,M; cin >> N >> M; vector<string> S(M),ans(N),T; map<string,ll> ss; ll m = MAX; for(ll i = 0;i < M;i++) cin >> S[i]; for(ll i = 0;i < M;i++) ss[S[i]] = i + 1; for(ll i = 0;i < M;i++) m = min(m,(ll)S[i].size()); for(ll t = 0;t < 4000;t++){ string a = S[mt() % M]; for(ll i = 0;i < 10;i++){ string b = S[mt() % M]; for(ll j = min(a.size(),b.size());j >= 0;j--){ ll ok = 1; for(ll k = 0;k < j;k++){ if(a[a.size() - j + k] != b[j]) ok = 0; } if(ok){ ll k = j; while(a.size() < N && k < b.size()){ a += b[k]; k++; } break; } } if(a.size() + b.size() <= N){ a += b; } } while(a.size() < N) a += (char)('A' + (mt() % 8)); T.emplace_back(a); } for(ll i = 0;i < N;i++){ ll C = 0; string A = "____________________"; for(ll j = 0;j < T.size();j++){ ll c = 0; string a = T[j] + T[j]; for(ll k = 0;k < N;k++){ for(ll l = m;l < m + 5;l++){ if(ss[a.substr(k,l)] != 0) c++; } } if(C < c){ C = c; A = T[j]; } } string a = A + A; for(ll k = 0;k < N;k++){ for(ll l = m;l < m + 5;l++){ if(ss[a.substr(k,l)] != 0) ss[a.substr(k,l)] = 0; } } ans[i] = A; } for(ll i = 0;i < N;i++) cout << ans[i] << endl; }
#include <iostream> #include <chrono> #include <string> #include <vector> #include <algorithm> class DNA { private: char base[20][20]; public: void inputV(const int& i, const int& j, const std::string& s) { for (int k = 0; k < (int)s.size(); k++) { if (i + k < 20) base[i + k][j] = s[k]; else base[i + k - 20][j] = s[k]; } } void inputH(const int& i, const int& j, const std::string& s) { for (int k = 0; k < (int)s.size(); k++) { if (j + k < 20) base[i][j + k] = s[k]; else base[i][j + k - 20] = s[k]; } } void output() { for (int i = 0; i < 20; i++) { for (int j = 0; j < 20; j++) { std::cout << base[i][j]; } std::cout << std::endl; } } //constructor DNA() { for (int i = 0; i < 20; i++) { for (int j = 0; j < 20; j++) { base[i][j] = '.'; } } } }; int main() { DNA alien; int m; std::cin >> m >> m; std::vector<std::pair<int, std::string>> sequences(m, { 0, "" }); for (int i = 0; i < m; i++) { std::cin >> sequences[i].second; sequences[i].first = (int)sequences[i].second.size(); } sort(sequences.begin(), sequences.end()); int now = 0;; int k = 0; while(now < 20) { for (int i = 0; i < 20; i++) { alien.inputH(i, now + 1, sequences[i].second); } k++; now += sequences[k * 20 - 1].first; } alien.output(); return 0; }
#include<iostream> #include<cstring> #include<algorithm> using namespace std; const int N = 2010,INF = 0x3f3f3f3f; string s; int n,m,tmp,p,ans,sum,minn = INF; int a[N][N]; int main() { cin >> n >> m; for(int i = 0;i < n;i++) { for(int j = 0;j < m;j++) { cin >> a[i][j]; minn = min(minn,a[i][j]); } } for(int i = 0;i < n;i++) { for(int j = 0;j < m;j++) { sum += a[i][j]-minn; } } cout << sum << endl; return 0; }
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("fast-math") #pragma GCC optimize("no-stack-protector") #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 ld long double #define ll long long #define REP(i, a, b) for (ll i = a; i < b; i++) #define REPI(i, a, b) for (ll i = b - 1; i >= a; i--) #define i_os ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define INF (ll)1e18 + 100 #define endl "\n" #define p0(a) cout << a << " " #define p1(a) cout << a << endl #define p2(a, b) cout << a << " " << b << endl #define p3(a, b, c) cout << a << " " << b << " " << c << endl #define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl // SOME BITMASK KNOWLEDGE // 1)x & (x - 1):sets the last one bit of x to zero // power of two exactly when x & (x − 1) = 0. // 2)x & -x:sets all the one bits to zero, except last one bit // 3)x | (x - 1):inverts all the bits after the last one bit #define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> #define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set1; typedef tree<string,null_type,less<string>,rb_tree_tag,tree_order_statistics_node_update> indexed_set2; //1. order_of_key(k) : number of elements strictly lesser than k //2. find_by_order(k) : k-th element in the set // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); ll power(ll a,ll n){ if(n == 0) return 1; ll s = power(a,n/2); s = (s * s); if(n % 2) s = (s * a); return s; } struct Service { ll l,c,f; }; bool compare(Service a,Service b){ if(a.l == b.l){ return a.f > b.f; } return a.l < b.l; } int main() { i_os; ll n,C; cin>>n>>C; vector<Service> v; REP(i,0,n){ ll x,y,z; cin>>x>>y>>z; Service s1,s2; s1.l = x; s1.c = z; s1.f = 0; s2.l = y+1; s2.c = z; s2.f = 1; v.push_back(s1); v.push_back(s2); } sort(v.begin(),v.end(),compare); ll sum = 0; ll ans = 0; ll in = 0; ll st = 1; for(Service s:v){ // cout<<s.l<<" "<<s.f<<" "<<s.c<<endl; if(s.f){ ans += min(C,sum)*(s.l-1-st+1); st = s.l; sum -= s.c; in--; } else { if(in != 0){ ans += min(C,sum)*(s.l-1-st+1); } st = s.l; sum += s.c; in++; } } cout<<ans<<endl; return 0; }
//#define _GLIBCXX_DEBUG //#include "atcoder/all" //using namespace atcoder; #include <bits/stdc++.h> #define int long long #define ll long long using ull = unsigned long long; using namespace std; #define Dump(x) \ if (dbg) { \ cerr << #x << " = " << (x) << endl; \ } #define overload4(_1, _2, _3, _4, name, ...) name #define FOR1(n) for (ll i = 0; i < (n); ++i) #define FOR2(i, n) for (ll i = 0; i < (n); ++i) #define FOR3(i, a, b) for (ll i = (a); i < (b); ++i) #define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c)) #define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__) #define FORR(i, a, b) for (int i = (a); i <= (b); ++i) #define bit(n, k) (((n) >> (k)) & 1) /*nのk bit目*/ namespace mydef { const int INF = 1ll << 60; const int MOD = 1e9 + 7; template <class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return 1; } else return 0; } template <class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } else return 0; } void Yes(bool flag = true) { if (flag) cout << "Yes" << endl; else cout << "No" << endl; } void No(bool flag = true) { Yes(!flag); } void YES(bool flag = true) { if (flag) cout << "YES" << endl; else cout << "NO" << endl; } void NO(bool flag = true) { YES(!flag); } template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); } bool dbg = true; } // namespace mydef using namespace mydef; #define pb push_back //#define mp make_pair #define eb emplace_back #define lb lower_bound #define ub upper_bound #define all(v) (v).begin(), (v).end() #define SZ(x) ((int)(x).size()) #define vi vector<int> #define vvi vector<vector<int>> #define vp vector<pair<int, int>> #define vvp vector<vector<pair<int, int>>> #define pi pair<int, int> //#define P pair<int, int> //#define V vector<int> //#define S set<int> #define asn ans int N; void solve() { } signed main() { cin.tie(nullptr); ios::sync_with_stdio(false); int ans = INF; cin >> N; for (int i = 0; i < N; i++) { int A, P, X; cin >> A >> P >> X; X -= A; if (X > 0) chmin(ans, P); } cout << (ans == INF ? -1 : ans) << endl; solve(); return 0; }
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; int main() { // freopen("1.in", "r", stdin); int n; scanf("%d", &n); int res = INF; for(int i = 1; i <= n; ++ i) { int a, p, x; scanf("%d%d%d", &a, &p, &x); if(a < x) res = min(p, res); } if(res < INF) printf("%d\n", res); else puts("-1"); return 0; }
#include <algorithm> #include <iostream> #include <sstream> #include <string> #include <vector> #include <queue> #include <set> #include <map> #include <cstdio> #include <cstdlib> #include <cctype> #include <cmath> #include <cstring> #include <list> #include <cassert> #include <climits> #include <bitset> #include <chrono> #include <random> using namespace std; #define PB push_back #define MP make_pair #define SZ(v) ((int)(v).size()) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define FORE(i,a,b) for(int i=(a);i<=(b);++i) #define REPE(i,n) FORE(i,0,n) #define FORSZ(i,a,v) FOR(i,a,SZ(v)) #define REPSZ(i,v) REP(i,SZ(v)) std::mt19937 rnd((int)std::chrono::steady_clock::now().time_since_epoch().count()); typedef long long ll; ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } const int MAXN = 500000; int n; char s[MAXN + 1]; char t[MAXN + 1]; int solve() { vector<int> szero; REP(i, n) if (s[i] == '0') szero.PB(i); vector<int> tzero; REP(i, n) if (t[i] == '0') tzero.PB(i); if (SZ(szero) != SZ(tzero)) return -1; int ret = 0; REPSZ(i, szero) if (szero[i] != tzero[i]) ++ret; return ret; } void run() { scanf("%d", &n); scanf("%s", s); scanf("%s", t); printf("%d\n", solve()); } int main() { run(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll n, ans, s[500050], t[500050], f[2]; vector<int> vs, ts; int main() { scanf("%lld", &n); for(int i = 0; i < n; i++) { scanf("%1lld", &s[i]); f[s[i]]++; if(!s[i]) vs.push_back(i); } for(int i = 0; i < n; i++) { scanf("%1lld", &t[i]); f[t[i]]--; if(!t[i]) ts.push_back(i); } if(f[0] || f[1]) puts("-1"); else { for(int i = 0; i < vs.size(); i++) ans += (vs[i] != ts[i]); printf("%lld\n", ans); } return 0; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <utility> #include <vector> #define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i) #define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i) #define rreps(i, n) for (int i = ((int)(n)); i > 0; --i) #define INF INT_MAX / 2 #define INFL 1LL << 60 #define MOD 1000000007 #define CHOOSE(a) CHOOSE2 a #define CHOOSE2(a0, a1, a2, a3, a4, 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 #ifdef _DEBUG #define debug(...) \ CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \ (__VA_ARGS__) #else #define debug(...) #endif using namespace std; using ll = long long; int main() { double a, b; cin >> a >> b; double ans = (b / 100) * a; cout << ans << endl; 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 A, long long B, long long W){ W *= 1000; int minCnt = INT_MAX, maxCnt = -1; rep(i,1,1000001) { if (i * A <= W && W <= i * B) { minCnt = min<int>(i, minCnt); maxCnt = max<int>(i, maxCnt); } } if (minCnt == INT_MAX) { cout << "UNSATISFIABLE" << endl; } else { cout << minCnt << " " << maxCnt << endl; } } signed main(){ // ios_base::sync_with_stdio(false); // cin.tie(NULL); long long A; scanf("%lld",&A); long long B; scanf("%lld",&B); long long W; scanf("%lld",&W); solve(A, B, W); return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using P = pair<int, int>; // auto mod int // https://youtu.be/L8grWxBlIZ4?t=9858 // https://youtu.be/ERZuLAxZffQ?t=4807 : optimize // https://youtu.be/8uowVvQ_-Mo?t=1329 : division const int mod = 1000000007; struct mint { ll x; // typedef long long ll; mint(ll x=0):x((x%mod+mod)%mod){} mint operator-() const { return mint(-x);} mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;} mint operator+(const mint a) const { return mint(*this) += a;} mint operator-(const mint a) const { return mint(*this) -= a;} mint operator*(const mint a) const { return mint(*this) *= a;} mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod-2);} mint& operator/=(const mint a) { return *this *= a.inv();} mint operator/(const mint a) const { return mint(*this) /= a;} }; istream& operator>>(istream& is, mint& a) { return is >> a.x;} ostream& operator<<(ostream& os, const mint& a) { return os << a.x;} int main() { int t; cin >> t; rep(i, t) { ll n, a, b; cin >> n >> a >> b; int e = n-a-b; mint ans, x1, x2, x3, x4; if (e < 0) x4 = 0; else x4 = (mint)(e+2) * (e+1) / 2; x3 = (mint)2 * x4; x2 = (mint)(n-a+1) * (n-b+1) - x3; x1 = x2 * x2; ans = (mint)((n-a+1)*(n-a+1))*(mint)((n-b+1)*(n-b+1)) - x1; cout << ans << endl; } return 0; }
// Coded By : Aj Style // Problem: C - ORXOR // Contest: AtCoder - AtCoder Beginner Contest 197(Sponsored by Panasonic) // URL: https://atcoder.jp/contests/abc197/tasks/abc197_c // Memory Limit: 1024 MB // Time Limit: 2000 ms #include <bits/stdc++.h> #define ll long long int #define ii int #define du double #define jmp "\n" #define vl vector<ll> #define vvl vector<vl> #define pb push_back #define pq_max priority_queue<ll> #define pq_min priority_queue<ll, vi, greater<ll>> #define printv(v) \ for (auto x : v) \ cout << x << " "; \ cout << jmp; #define vi vector<int> #define vb vector<bool> #define ump unordered_map #define SORT(v) sort(v.begin(), v.end()) #define REV(x) reverse(x.begin(), x.end()) #define all(x) x.begin(), x.end() #define SET(x, a) memset(x, a, sizeof(x)) #define si(x) (ll) x.size() #define ff first #define ss second #define I(a) \ for (auto &x : a) \ cin >> x; #define iin insert #define log(args...) \ { \ string _s = #args; \ replace(_s.begin(), _s.end(), ',', ' '); \ stringstream _ss(_s); \ istream_iterator<string> _it(_ss); \ err(_it, args); \ } #define logarr(arr, a, b) \ for (int z = (a); z <= (b); z++) \ cout << (arr[z]) << " "; \ cout << endl; \ using namespace std; using namespace std; // vs tokenizer(string str,char ch) {std::istringstream var((str)); vs v; string t; while(getline((var), t, (ch))) {v.pb(t);} return v;} void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cout << *it << " = " << a << endl; err(++it, args...); } const ll nax = 1e5 + 5; vl a; ll n; ll mn; void r(ll x, ll o, ll i) { if (i == n) { // if (o) x ^= o; mn = min(mn, x); return; } r(((x ^ o)), a[i], i + 1); r(x, (o | a[i]), i + 1); return; } void solve() { // ll n; cin >> n; a = vl(n); I(a); mn = LLONG_MAX; r(0, 0, 0); cout << mn << jmp; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll t = 1; // cin >> t; while (t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define MOD 1000000007 #define F first #define S second #define cn(a, n) \ for (ll i = 0; i < n; i++) \ cin >> a[i]; #define fastio() \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) int main() { fastio(); int A, B; cin >> A >> B; if (A + B >= 15 and B >= 8) { cout << "1"; } else if (A + B >= 10 and B >= 3) { cout << "2"; } else if (A + B >= 3) { cout << "3"; } else { cout << "4"; } }
#include <bits/stdc++.h> using namespace std; const char BLUE = '+'; const int INF = INT_MAX >> 1; int main(void) { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int h, w; cin >> h >> w; vector<string> a(h); for (int i = 0; i < h; i++) { cin >> a[i]; } vector<vector<int>> dp(h, vector<int>(w)); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { dp[i][j] = (1 & (i + j)) ? INF : -INF; } } dp[h - 1][w - 1] = 0; for (int i = h - 1; i >= 0; i--) { for (int j = w - 1; j >= 0; j--) { if (1 & (i + j)) // akoi { if (i > 0) { dp[i - 1][j] = max(dp[i - 1][j], dp[i][j] + ((BLUE == a[i][j]) ? 1 : -1)); } if (j > 0) { dp[i][j - 1] = max(dp[i][j - 1], dp[i][j] + ((BLUE == a[i][j]) ? 1 : -1)); } } else // takashi { if (i > 0) { dp[i - 1][j] = min(dp[i - 1][j], dp[i][j] - ((BLUE == a[i][j]) ? 1 : -1)); } if (j > 0) { dp[i][j - 1] = min(dp[i][j - 1], dp[i][j] - ((BLUE == a[i][j]) ? 1 : -1)); } } } } cout << ((0 == dp[0][0]) ? "Draw" : ((dp[0][0] > 0) ? "Takahashi" : "Aoki")) << endl; return 0; }
#include <bits/stdc++.h> #include <map> #include <math.h> #include <string> #include <string.h> #include <vector> #include <queue> #include <algorithm> using namespace std; using ll = long long; ll modinv(ll a, ll m) { ll b = m, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } ll modpow(ll n) { ll res = 1, a = 2; while (n > 0) { if (n & 1) res = res * a % 1000000007; a = a * a % 1000000007; n >>= 1; } if(res == 0) res = 1000000006; else res -= 1; return res; } ll yaku(ll x){ ll cnt = 0; for(int i = 1; i * i <= x; i++){ if(x % i == 0){ if(i == x % i) cnt++; else cnt += 2; } } return cnt; } int main(){ string X; ll M, ma = -1, ans = 0, cnt; cin >> X >> M; ll siz = X.size(); vector<ll> x(siz); for(int i = 0; i < siz; i++) x.at(i) = X.at(i) - 48; for(int i = 0; i < siz; i++) ma = max(x.at(i), ma); cnt = ma + 1; if(siz == 1){ if(x.at(0) > M) cout << 0 << endl; else cout << 1 << endl; return 0; }else if(siz == 2){ ll m = M; m -= x.at(1); cout << m / x.at(0) - ma << endl; return 0; }else if(siz == 3){ while(1){ if(cnt * (cnt * x.at(0) + x.at(1)) + x.at(2) > M) break; cnt++; ans++; } cout << ans << endl; }else{ reverse(x.begin(), x.end()); while(1){ ll a = 1, s = 0; for(int i = 0; i < siz; i++){ s += a * x.at(i); if(s > M || a > M) break; if(i != siz - 1) a *= cnt; } if(s > M || a > M) break; ans++; cnt++; } cout << ans << endl; return 0; } }
//#include <bits/stdc++.h> #include <iostream> #include <vector> #include <functional> #include <algorithm> #include <map> #include <cstdio> #include <cmath> #include <iomanip> #include <queue> using namespace std; #define rep(i,n) for (int i = 0; i < (n); i++) #define vi vector<int> #define vll vector<long long> #define vb vector<bool> #define vs vector<string> #define all(x) x.begin() , x.end() #define pb push_back #define eb emplace_back #define chmax(x,y) (x) = max((x) , (y)) #define chmin(x,y) (x) = min((x) , (y)) #define fi first #define se second typedef long long ll; typedef unsigned long long ull; typedef long double ld; //const int MOD = int(1e9) + 7; //const int MOD = 998244353; //const ll MOD = ll(1e9) + 7; const ll MOD = 998244353; const ld PI = 3.1415926535897932384626; const int INF = 1001001001; const ll LINF = 1001001001001001001; const int MX = 220000; ll modpow (ll x , ll p) { ll ret = 1; while (p) { if (p % 2 == 1) { ret *= x; ret %= MOD; } x *= x; x %= MOD; p /= 2; } return ret; } vll fact(MX); vll factinv(MX); void init_fact () { fact[0] = 1; for (int i = 1; i < MX; i++) { fact[i] = 1LL * i * fact[i - 1] % MOD; } for (int i = 0; i < MX; i++) { factinv[i] = modpow(fact[i] , MOD - 2); } } bool is_prime (int x) { if (x == 2 || x == 3 || x == 5 || x == 7) { return true; } for (ll i = 2; i*i <= x; i++) { if (x % i == 0) { return false; } } return true; } vb prime_table(MX , true); void init_prime() { for (int i = 2; i < MX; i++) { for (int j = i + i; j < MX; j += i) { prime_table[j] = false; } } return; } map<ll, int> factrization(ll x) { map<ll, int> ret; for (int i = 2; i*i <= x; i++) { while (x % i == 0) { ret[i]++; x /= i; } } if (x > 1) ret[x]++; return ret; } ll moddiv (ll a , ll b) { return a * modpow(b , MOD - 2) % MOD; } ll modsub (ll a , ll b) { if (a >= b) return (a - b) % MOD; else return (MOD - a + b); } ll nCk (ll n , ll k) { return ((fact[n] * factinv[k] % MOD) * factinv[n - k] % MOD); } ll nHk (ll n , ll k) { return nCk(n - 1 + k , k); } // 仕切り- 1 + boll を並べる組み合わせ ll gcd (ll a , ll b) { if (a < b) swap(a , b); if (a % b == 0) return b; else return gcd(b , a % b); } ll lcm (ll a , ll b) { return a / gcd(a , b) * b; } ll lin() { ll x; scanf("%lld" , &x); return x; } int in() { int x; scanf("%d" , &x); return x; } bool is_palindrome (string s) { string t = s; reverse(all(t)); return (s == t); } void io_setup() { cout << fixed << setprecision(20); } void solve () { int n , m; cin >> n >> m; map<int , int> mp1 , mp2; rep(i,n) { int a = in(); mp1[a]++; } rep(i,m) { int a = in(); mp2[a]++; } vi ans; for (auto i : mp1) { if (mp2[i.fi] == 0) ans.pb(i.fi); } for (auto i : mp2) { if (mp1[i.fi] == 0) ans.pb(i.fi); } sort(all(ans)); int SZ = ans.size(); rep(i,SZ) { cout << ans[i]; if (i != SZ - 1) cout << " "; else cout << endl; } return; } int main() { io_setup(); //init_fact(); //init_prime(); solve(); return 0; }
#include <bits/stdc++.h> #define int long long using namespace std; const int inf = 1e18+9; const int mod = 1e9+7; const int maxn = 2e5+8; int n, m; void solve() { int i, j; map<int, int> mp; cin >> n; for (int x = 3, i = 1; x < n; i++, x *= 3) mp[x] = i; for (int x = 5, i = 1; x < n; i++, x *= 5) if (mp.find(n - x) != mp.end()) return (void)(cout << mp[n - x] << " " << i << endl); cout << -1 << endl; } signed main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); //cout << fixed << setprecision(15); int t = 1; //cin >> t; while (t--) solve(); return 0; }
#include <bits/stdc++.h> #define _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) for (int i = (a); i < (b); ++i) #define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__) #define ALL(x) x.begin(), x.end() #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) using namespace std; random_device rnd; mt19937 mt(rnd()); using ll = long long; using lld = long double; using VI = vector<int>; using VVI = vector<VI>; using VL = vector<ll>; using VVL = vector<VL>; using PII = pair<int, int>; const int IINF = 1 << 30; const ll INF = 1ll << 60; const ll MOD = 1000000007; int check(int a, int b, ll n) { ll cur = 1; rep(i, a) { cur *= 3; if (cur > n) { return -1; } } ll tmp = 1; rep(j, b) { tmp *= 5; if (tmp > n) { return -1; } } cur += tmp; assert(cur > 0); if (cur > n) { return -1; } if (cur == n) { return 1; } else { return 0; } } int main() { ll n; cin >> n; rep(i, 1, 100) { rep(j, 1, 100) { ll ret = check(i, j, n); if (ret == -1) { break; } if (ret == 1) { cout << i << " " << j << endl; return 0; } } } cout << -1 << endl; return 0; }
//#define _GLIBCXX_DEBUG #include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; using ll = long long; #define rep(i, s, n) for (ll i = (s); i < (ll)(n); i++) #define all(x) (x).begin(), (x).end() const int INF = 1'000'000'000; const ll llINF = 1'000'000'000'000'000'000; int main() { int N; cin >> N; cout << (1<<N) - 1 << endl; if (N == 1) { cout << "AB" << endl; return 0; } vector<vector<int>> had2 = {{1,1},{1,-1}}; vector<vector<int>> prev = had2, ans = had2; rep(k,2,N+1) { ans = vector<vector<int>>(1<<k,vector<int>(1<<k)); rep(i,0,1<<k) rep(j,0,1<<k) { //cout << i << " " << j << endl; ans[i][j] = prev[i & ~(1<<k-1)][j & ~(1<<k-1)]; } rep(i,1<<k-1,1<<k) rep(j,1<<k-1,1<<k) { ans[i][j] *= -1; } prev = ans; } rep(i,1,1<<N) { rep(j,0,1<<N) { cout << (ans[i][j] == 1 ? 'A' : 'B'); } cout << endl; } }
#include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <iostream> #include <cassert> #include <cmath> #include <string> #include <queue> #include <set> #include <map> #include <cstdlib> using namespace std; #define mp make_pair #define pb push_back #define fi first #define se second #define li long long #define pii pair<int, int> #define vi vector<int> #define li long long #define forn(i, n) for (int i = 0; i < (int)n; i++) #define fore(i, b, e) for (int i = (int)b; i <= (int)e; i++) const int MAXN = 2005; bool visited[MAXN]; vi edges[MAXN]; int n, m; void dfs(int v) { visited[v] = true; for (int u : edges[v]) { if (!visited[u]) dfs(u); } } void add_edge(int row, int col) { edges[row].pb(col + n); edges[col + n].pb(row); } int main() { scanf("%d%d", &n, &m); forn(i, n) { string s; cin >> s; forn(j, m) { if (s[j] == '#') { add_edge(i, j); } } } /*forn(i, n) { add_edge(i, 0); add_edge(i, m - 1); } forn(j, m) { add_edge(0, j); add_edge(n - 1, j); }*/ add_edge(0, 0); add_edge(0, m); add_edge(n - 1, 0); add_edge(n - 1, m - 1); int row_comp = 0; forn(i, n) { if (!visited[i]) { ++row_comp; dfs(i); } } memset(visited, false, sizeof(visited)); int col_comp = 0; fore(i, n, n + m - 1) { if (!visited[i]) { ++col_comp; dfs(i); } } //cerr << row_comp << " " << col_comp << endl; printf("%d", min(row_comp - 1, col_comp - 1)); }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++) #define all(v) begin(v), end(v) #define sz(v) v.size() #define INF 1000000000000000000 //10^17 #define EPSILON 0.00000000000001 // 10^-14 template <typename T> bool chmax(T &a, const T& b) { if (a < b) { a = b; return true; } return false; } template <typename T> bool chmin(T &a, const T& b) { if (a > b) { a = b; return true; } return false; } ll llpow(ll x, ll y){ if(y == 0){ return 1; } if(y % 2 == 0){ ll a = llpow(x, y / 2); return a * a; } else{ ll a = llpow(x, y / 2); return a * a * x; } } //浮動小数点はなるべく使うな、powも気をつけろ int main() { string X; ll M; cin >> X >> M; if(sz(X) == 1){ if(stoll(X) <= M){ cout << 1 << '\n'; return 0; } else{ cout << 0 << '\n'; return 0; } } ll d = 0; rep(i, sz(X)){ chmax(d, ll(X.at(i)-'0')); } ll bound = powl(M, 1.0/(sz(X)-1)) + EPSILON; if(sz(X) == 2){ ll x0 = X.at(0) - '0'; ll x1 = X.at(1) - '0'; ll b = (M-x1) / x0; if(b < d+1){ cout << 0 << '\n'; return 0; } else{ cout << b - (d+1) + 1 << '\n'; return 0; } } if(sz(X) == 3){ ll x0 = X.at(0) - '0'; ll x1 = X.at(1) - '0'; ll x2 = X.at(2) - '0'; long double r = pow(x1*x1-4*x0*(x0-M), 0.5); long double s = (-x1 + r) / (2*x0) + EPSILON; ll b = s; if(b < d+1){ cout << 0 << '\n'; return 0; } else{ cout << b - (d+1) + 1 << '\n'; return 0; } } vector<ll> digit(sz(X)); rep(i, sz(X)){ digit.at(i) = X.at(i) - '0'; } ll ans = 0; rep2(i, d+1, bound+1){ ll val = 0; rep(j, sz(X)){ val += llpow(i, sz(X)-1-j) * digit.at(j); } if(val <= M){ ans++; } } cout << ans << '\n'; }
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; // bool xd=any_of(a.begin(),a.end(),[&](int x){return x==9;}); // all_of, none_of // int cnt=count(a.begin(),a.end(),x); // bool found=binary_search(a.begin(),a.end(),x); true if x in sorted array // int xd=*max_element(a.begin(),a.end()); // min_element typedef long long ll; typedef long double ld; ll m,n; vector<int>x; bool getbase(ll b){ ll res=0; for(auto c:x){ if(res>(m-c)/b)return 0; else res=res*b+c; assert(res<=m); } return 1; } main(){ cin.tie(0);ios::sync_with_stdio(0); string tmp;cin>>tmp>>m;n=x.size(); for(auto c:tmp)x.push_back(c-'0'); if(x.size()==1){ if(m>=x[0])cout<<1<<endl; else cout<<0<<endl; return 0; } else{ ll mxc=*max_element(x.begin(),x.end()); ll l=mxc+1,r=m+1; while(l<r){ ll m=(l+r)/2; if(getbase(m))l=m+1; else r=m; } cout<<l-1-mxc<<endl; } }
#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; } }
#include<bits/stdc++.h> #define si(a) scanf("%d",&a) #define sl(a) scanf("%lld",&a) #define sd(a) scanf("%lf",&a) #define sc(a) scanf("%c",&a) #define ss(a) scanf("%s",a) #define pi(a) printf("%d\n",a) #define pl(a) printf("%lld\n",a) #define pc(a) putchar(a) #define ms(a) memset(a,0,sizeof(a)) #define repi(i, a, b) for(register int i=a;i<=b;++i) #define repd(i, a, b) for(register int i=a;i>=b;--i) #define reps(s) for(register int i=head[s];i;i=Next[i]) #define ll long long #define ull unsigned long long #define vi vector<int> #define pii pair<int,int> #define mii unordered_map<int,int> #define msi unordered_map<string,int> #define lowbit(x) ((x)&(-(x))) #define ce(i, r) i==r?'\n':' ' #define pb push_back #define fi first #define se second #define all(x) x.begin(),x.end() #define INF 0x3f3f3f3f #define pr(x) cout<<#x<<": "<<x<<endl using namespace std; inline int qr() { int f = 0, fu = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-')fu = -1; c = getchar(); } while (c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + c - 48; c = getchar(); } return f * fu; } const int N = 1e3 + 10; int n, m; int a[N], b[N]; int f[N][N]; int main() { n = qr(), m = qr(); repi(i, 1, n)a[i] = qr(); repi(i, 1, m)b[i] = qr(); memset(f, 0x3f, sizeof(f)); f[0][0] = 0; int ans = INF; repi(i, 0, m)f[0][i] = i; repi(i, 0, n)f[i][0] = i; repi(i, 1, n) repi(j, 1, m) { if (a[i] != b[j]) { f[i][j] = min({f[i][j], f[i - 1][j - 1] + 1, f[i][j - 1] + 1, f[i - 1][j] + 1}); } else { f[i][j] = min({f[i][j], f[i - 1][j - 1], f[i][j - 1] + 1, f[i - 1][j] + 1}); } } repi(i, 1, n)repi(j, 1, m)ans = min(ans, f[i][j] + n - i + m - j); pi(ans); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ii> vii; #define FOR(i, a, b) for(int i = a; i < b; i++) #define ROF(i, a, b) for(int i = a; i >= b; i--) #define ms memset #define pb push_back #define F first #define S second ll MOD = 998244353; ll power(ll base, ll n){ if (n == 0) return 1; if (n == 1) return base; ll halfn = power(base, n/2); if (n % 2 == 0) return (halfn * halfn) % MOD; return (((halfn * halfn) % MOD) * base) % MOD; } ll inverse(ll n){ return power(n, MOD-2); } ll add(ll a, ll b){ return (a+b) % MOD; } ll mul(ll a, ll b){ return (a*b) % MOD; } ll gcd(ll a, ll b){ if (a == 0) return b; if (a == 1) return 1; return gcd(b%a, a); } int main(){ ios::sync_with_stdio(false); int v, t, s, d; cin >> v >> t >> s >> d; if (v * t > d || v * s < d){ cout << "Yes\n"; }else{ cout << "No\n"; } return 0; }
/* ->->->->-> Vora Mahammasasim <-<-<-<-<- */ #include<bits/stdc++.h> #define Quick std :: ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0); #define int long long #define pb emplace_back #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define MOD 1000000007 using namespace std; void solve(){ int a,b,c,d; cin>>a>>b>>c>>d; cout<<a*d-b*c<<'\n'; } signed main(){ Quick; int tt = 1; //cin>>tt; while(tt--){ solve(); } return 0; }
#include<iostream> using namespace std; int main() { string a; cin >> a; if(a.find('.') != string::npos) { cout << a.substr(0 , a.find('.')); } else { cout << a; } return 0; }
#include <bits/stdc++.h> #define ll long long #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); using namespace std; char s; int main(){ while(cin >> s){ if(s=='.') break; cout << s; } }
#include <bits/stdc++.h> using namespace std; //#include "testlib.h" #define ff first #define ss second #define all(v) v.begin(),v.end() #define int long long #define ll long long #define M 1000000007 #define MM 998244353 #define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i] #define GCD(m,n) __gcd(m,n) #define LCM(m,n) m*(n/GCD(m,n)) #define mii map<ll ,ll > #define msi map<string,ll > #define rep(a,b) for(ll i=a;i<b;i++) #define rep0(n) for(ll i=0;i<n;i++) #define repi(i,a,b) for(ll i=a;i<b;i++) #define pb push_back #define vi vector<ll> #define vs vector<string> #define ppb pop_back #define endl '\n' #define asdf ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define r0 return 0; #define FORD(i, a, b) for (int i = (int) (a); i >= (int) (b); --i) #define inputoutput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout); #define Set(a, s) (a, s, sizeof (a)) #define FOR repi #define vii vector<pii> #define pii pair<int,int> #define REVERSE(v) reverse(all(v)) #define trav(a, x) for(auto& a : x) #define display(x) trav(a,x) cout<<a<<" ";cout<<endl #define debug cerr<<"bhau"<<endl #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char* name, Arg1&& arg1){ std::cerr << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...); } template<typename T, typename U> static inline void amin(T &x, U y) { if (y < x) x = y; } template<typename T, typename U> static inline void amax(T &x, U y) { if (x < y) x = y; } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); ll max(ll a, ll b) { return (a > b)? a : b;} int min(int a, int b) { return (a < b)? a : b;} const int N = 4e5+10; vi adj[N]; bool vis[N]; int vert; bool tree = 1; void dfs(int v,int p){ vert++; vis[v]=1; for(auto i:adj[v]){ if(i!=p){ if(vis[i]) tree=0; else dfs(i,v); } } } int solve(){ int n;cin>>n; int a,b; rep0(n){ cin>>a>>b; adj[a].pb(b); adj[b].pb(a); } int ans=0; for(int i=1;i<=N;i++){ if(!vis[i]){ tree = 1; vert=0; dfs(i,-1); if(tree){ ans+=vert-1; } else ans+=vert; } } cout<<ans<<endl; return 0; } signed main(){ asdf int t=1; // cin>>t; while(t--){ solve(); } return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; typedef long long ll; struct int_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; struct pair_hash { size_t operator()(pair<int, int> x) const { return int_hash{}(x.first) ^ (int_hash{}(x.second) << 16); } }; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int MOD = 1000000007; const ll INF = numeric_limits<ll>::max(); const int inf = 1e7; const int MX = 100001; //check the limits, dummy pair<int, bool> dfs(int a, int prev, unordered_set<int> &s, unordered_map<int, vector<int>> &mp) { if(s.count(a)) { return {0, false}; } pair<int, bool> res{1, true}; s.insert(a); for(int next : mp[a]) { if(next != prev) { auto [ret_cnt, ret_cycle] = dfs(next, a, s, mp); res.first += ret_cnt; res.second &= ret_cycle; } } return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; unordered_map<int, vector<int>> g; for(int i = 0, a, b; i < n; i++) { cin >> a >> b; g[a].push_back(b); g[b].push_back(a); } unordered_set<int> vis; int res = 0; for(const auto &[a, b] : g) { const auto [num, cyc] = dfs(a, -1, vis, g); res += num - cyc; } cout << res << endl; }
#include<bits/stdc++.h> #define int long long #define x first #define y second #define mp make_pair #define pb push_back #define endl "\n" using namespace std; const int max_n = 1e5+100; const int max_len = 631441 + 100000; const int max_sum = 1e7+100; const int offset = 1e5+10; const int inf = 1e18; signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int a,b,c; cin>>a>>b>>c; if(a>b){ cout<<"Takahashi"<<endl; }else if(b>a){ cout<<"Aoki"<<endl; }else{ if(c==1){ cout<<"Takahashi"<<endl; }else{ cout<<"Aoki"<<endl; } } }
/* Author: Hrujul Thumar */ #include <bits/stdc++.h> #define int long long #define MOD 100000007 #define endl '\n' #define fastio ios::sync_with_stdio(0);cin.tie(0); cout.tie(0); #define pi 3.141592653589793238 #define op(a) cout << (a ? "Takahashi" : "Aoki") << '\n'; const long long MAX_SIZE = 1000000000; using namespace std; int visited[1000000]; int a[10000000]; vector<int> v[1000000]; int diff=-1000000000; int mx=0; void dfs(int l) { mx=max(mx,a[l]); visited[l]=1; for(auto &i:v[l]) { dfs(i); } } signed main() { fastio; int t=1; //cin>>t; while(t--) { int a,b,c; cin>>a>>b>>c; while(a && b){ if(c) { b--; } else a--; c++; c%=2; } if(a && !c)op(1) else if(b && c)op(0) else if(!a && !c)op(0) else if(!b && c)op(1) else if(a && c)op(1) else if(b && !c)op(0) } }
#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #define N 200100 #define MOD 1000000007 //998244353 #define ll long long #define rep(i, n) for(int i = 0; i < n; ++i) #define rep2(i, a, b) for(int i = a; i <= b; ++i) #define rep3(i, a, b) for(int i = a; i >= b; --i) #define eb emplace_back #define pb push_back #define all(c) (c).begin(), (c).end() #define vi vector<int> #define pii pair<int,int> #define pll pair<ll,ll> struct Setup_io { Setup_io() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << fixed << setprecision(15); } } setup_io; int main() { vi a; int n,nn; cin >> n; nn=n; n -= 3; a.pb(6); a.pb(10); a.pb(15); if (n > 0)a.pb(12); n--; rep2(i, 16, 10000) { if (n <= 0)break; if (i % 6 == 0) { a.pb(i); n--; } else if (i % 10 == 0) { a.pb(i); n--; } else if (i % 15 == 0) { a.pb(i); n--; } } //cout << a.size() << endl; rep(i, nn - 1)cout << a[i] << " "; cout << a[nn - 1] << endl; return 0; }
#include "bits/stdc++.h" #define rep(i,b) for(ll i=0;i<b;i++) #define ll long long #define mp make_pair #define pb push_back using namespace std; /*--Input//////////////////////////////////////////////////*/ inline void IN(void){return;} template <typename First, typename... Rest> void IN(First& first, Rest&... rest){ cin >> first; IN(rest...); return; } #define SS(T, ...) T __VA_ARGS__; IN(__VA_ARGS__); #define SV(type,c,n) vector<type> c(n);for(auto& i:c)cin >> i; /*--Output/////////////////////////////////////////////////*/ #define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl #define First(n) cout << ((n) ? "First" : "Second" ) << endl inline int p(void){cout << endl; return 0;} template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;} struct ProconInit { static constexpr int IOS_PREC = 15; static constexpr bool AUTOFLUSH = false; ProconInit() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(IOS_PREC); if(AUTOFLUSH) cout << unitbuf; } } PROCON_INIT; #define vl vector<ll> #define debug(x) cerr<<#x<<" "<<x<<'\n'; #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; } bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second < b.second; } int main(){ SS(ll,N,K) ll ans=0; ll ans2=0; ll R,L; for(R=2;R<=2*N;R++){ L=R-K; if(L>=2&&L<=2*N){ //cout<<R<<" "<<L<<endl; ll tempL,tempR; if(L==2*N)tempL=1; else tempL=L-1; if(tempL>N)tempL-=(tempL-N)*2; if(R==2*N)tempR=1; else tempR=R-1; if(tempR>N)tempR-=(tempR-N)*2; ans+=tempR*tempL; } } p(ans); }
// * Author : Debapriya010 : DEBAPRIYA CHANDRA // * Jalpaiguri Government Engineering College #include<algorithm> #include<bits/stdc++.h> #define ll long long int #define dbl long double #define loop(i,n) for(int i=0;i<n;i++) #define rloop(i,n) for(int i=n-1;i>=0;i--) #define test(t) int t;cin>>t;while(t--) #define debo ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL) #define vi vector<ll> #define sz size() #define iss is_sorted #define bs binary_search #define mod 1000000007 #define c1_Bin __builtin_popcountll #define yos cout<<"YES"<<endl #define nos cout<<"NO"<<endl #define pb push_back #define ppb pop_back #define F first #define S second #define vep vector<pair<ll,ll>> #define mp map<ll,ll> #define all(v) v.begin(),v.end() #define tos to_string using namespace std; bool isPrime(ll n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } bool IsPalindrome( string str) { if (str.empty()) return false; ll i = 0; // first characters ll j = str.length() - 1; // last character while (i < j) { if (str[i] != str[j]) { return false; } i++; j--; } return true; } // Binary Exponentiation fun to calculate pow in 0(logN) ll binpow(ll a, ll b) { if (b == 0) return 1; ll res = binpow(a, b / 2); if (b % 2) return (res * res * a)%mod; return (res * res)%mod; } signed main(){ debo; // test(t){ ll a,b,c,d; cin>>a>>b>>c>>d; int df1=a+b-c*d; ll df2=a+b+b-2*c*d; if(df2<df1) { ll c0=0; ll te=0; while(1) { ++c0; a+=b; te+=c; if(a<=te*d)break; } cout<<c0; } else { cout<<-1; } cout<<endl; // } return 0; }
#include <bits/stdc++.h> typedef long long int LL; typedef unsigned long long int ULL; using namespace std; // 插入此處 int main() { std::ios::sync_with_stdio(false); cin.tie(0); LL A, B, C, D; cin >> A >> B >> C >> D; if (D * C - B > 0) { cout << A / (D * C - B) + (A % (D * C - B) ? 1 : 0) << endl; } else { cout << -1 << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int mod=998244353; char str[20]; int n,a[20],f[1200005],ans=-1; int main(){ cin>>str+1; n=strlen(str+1); for(int i=1;i<=n;i++)a[i]=str[i]-'0'; for(int i=1;i<=n;i++){ f[1<<i-1]=a[i]; if(f[i]%3==0)ans=max(ans,1); } for(int i=1;i<(1<<n);i++){ if(__builtin_popcount(i)==1)continue; f[i]=f[i&-i]+f[i-(i&-i)]; if(f[i]%3==0)ans=max(ans,__builtin_popcount(i)); } if(ans==-1)cout<<ans; else cout<<n-ans; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for(ll i=0;i<(ll)(n);i++) #define ALL(a) (a).begin(),(a).end() using namespace std; using ll=long long; typedef pair<ll,ll> P; ll pow2(ll n, ll a){ ll res=1; rep(i,a) res*=n; return res; } int main(){ ll n; cin>>n; ll s=1e18; for(ll a=1;pow2(3,a)<=s;a++){ for(ll b=1;pow2(5,b)<=s;b++){ if(pow2(3,a)+pow2(5,b)==n){ cout<<a<<" "<<b<<endl; return 0; } } } cout<<-1<<endl; }
#include <iostream> #include <stdio.h> #include <sstream> #include <string> #include <vector> #include <bitset> #include <map> #include <set> #include <queue> #include <deque> #include <algorithm> #include <random> #include <numeric> #include <cmath> #include <complex> #include <stack> #include <memory> #include <cstdio> #include <iomanip> using namespace std; using ll = long long; #define FOR(i,a,b) for(ll i=ll(a); i<ll(b); i++)// a<=i<b i++ のforの開始 #define FOR_(i,b,a) for(ll i=ll(b); ll(a)<i; --i)// b =>i>a i-- のforの開始 #define EACH(e,a) for(auto &(e):(a))//集合aの各要素eを当たる forの開始 #define FIND(e,a,i) vector<ll>::iterator itr=find((a).begin(),(a).end(),e);\ if(itr!=(a).end()){i=itr-(a).begin();} else{i=-1;}//vector aの中に要素eはあるのかあるならindexをiに,なければiは-1 #define ALL(a) (a).begin(),(a).end() #define MAX(a,i) vector<ll>::iterator itr0=max_element((a).begin(),(a).end());\ i=(ll)(itr0-(a).begin());// vector<ll>の最大値の足をiに返す #define MIN(a,i) vector<ll>::iterator itr1=min_element((a).begin(),(a).end());\ i=(ll)(itr1-(a).begin());// vector<ll>の最小値の足をiに返す #define ERASE(a,i) (a).erase((a).begin()+i);//iは0始まり #define ERASES(a,i,j) (a).erase((a).begin()+i,(a).begin()+j);//i,jは0始まり i<= u <jの範囲を消す i!=j #define SORT(a) sort(begin(a),end(a))//小さい順にsort 1,2,3 #define SORT_(a) sort(begin(a),end(a),greater<ll>{})//大きい順にsort 5,4,3 #define OI(s) cout<<(s)<<endl #define OI2(s0,s1) cout<<(s0)<<" "<<(s1)<<endl #define OI3(s0,s1,s2) cout<<(s0)<<" "<<(s1)<<" "<<(s2)<<endl #define OI4(s0,s1,s2,s3) cout<<(s0)<<" "<<(s1)<<" "<<(s2)<<" "<<(s3)<<endl #define OIV(a) FOR(i,0,(a).size()){cout<<a[i]<<" ";} cout<<""<<endl; #define OIVV(a) FOR(i,0,(a).size()){FOR(j,0,(a[i]).size()){cout<<a[i][j]<<" ";}cout<<" "<<endl;} // vector<vector<ll>> A(5,vector<ll>(3,0)); int main() { string S; cin >>S; ll ls; ls = S.size(); vector<string> A(ls); //OIV(A); FOR(i,0,ls) { string s; s = S[ls-1-i]; if(s=="0") A[i] = "0"; else if(s=="1") A[i] = "1"; else if (s=="6") A[i] ="9"; else if(s=="8") A[i] ="8"; else if(s=="9") A[i] = "6"; } //OIV(A); FOR(i,0,ls) { cout<<A[i]; } return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long int #define pb push_back const long double pi = acos(-1); // g++ -std=c++17 -Wshadow -Wall -g -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -o int main(){ // ios_base::sync_with_stdio(false); // cin.tie(NULL); string s; cin>>s; int cnt=0; for(int i=0;i<(int)s.length();i++){ if(s.substr(i,4)=="ZONe")cnt++; } cout<<cnt<<"\n"; return 0; } // ALWAYS TAKE INITITAL MIN AS 2E18 AND INITITAL MAX AS -2E18 // ALWAYS TAKE INITIAL MAX AS 2E18 AND INITIAL MIN AS -2E18 // TAKE ALL INT VARIABLES AS LONG LONG INT // READ WHEN WRITING BINARY SEARCH - // take care of the left and right limits while writing code for binary search - // l should be lower than min. possible ans, and r should be higher than max. possible ans // (MAX. POSSIBLE ANS CAN BE MORE THAN 1e18!!)
#include <bits/stdc++.h> using namespace std; typedef long long int lld; #define all(m) m.begin(),m.end() #define sz(m) lld(m.size()) #define pb push_back #define mod 1000000007 #define st first #define nd second #define endl "\n" #ifdef LOCAL #define debug(...) debug_out(#__VA_ARGS__, __VA_ARGS__) #define debug2(v,a,b) debug2_out(#v,v,a,b) #else #define debug(...) #define debug2(v,a,b) #endif const int N=1e6+100; void swagWaalaFunction() { lld l,r,ans=0; cin>>l>>r; vector<lld> nfac(N); // Counts number of factors // stores -ve value if it is of form a1^x1 * a2^x2 ...., where a1,a2 are primes and some xi%2==0 // Used to calculate mobius for(lld i=2;i<=r;i++) { if(nfac[i]) continue; for(lld j=i;j<=r;j+=i) nfac[j]++; for(lld j=i*i;j<=r;j+=i*i) nfac[j]=-1e18; } // MOBIOUS MAGICCCC !!! for(lld i=2;i<=r;i++) { if(nfac[i]<0) continue; lld cnt=r/i-(l-1)/i; lld pairs=cnt*(cnt-1)/2; if(nfac[i]%2) ans+=pairs; else ans-=pairs; } // Remove multiples for(lld i=max(2LL,l);i<=r;i++) ans-=(r/i-1); ans*=2; // x,y and y,x are different cout<<ans<<endl; } int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); lld tc=1; //cin>>tc; for(int i=0;i<tc;i++) { // cout<<"Case #"<<i+1<<": "; swagWaalaFunction(); } 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; #define ff first #define ss second #define pb push_back #define eb emplace_back #define mp make_pair #define lb lower_bound #define ub upper_bound #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define sz(v) (int)v.size() #define ps(y) cout << fixed << setprecision(y) #define ms(arr, v) memset(arr, v, sizeof(arr)) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define trav(x, v) for(auto &x: v) #define w(t) int t; cin >> t; while(t--) #define rep0(i, n) for(int i = 0; i < n; i++) #define rrep0(i, n) for(int i = n - 1; i >= 0; i--) #define rep1(i, n) for(int i = 1; i <= n; i++) #define rrep1(i, n) for(int i = n; i > 0; i--) #define inp(arr, n) rep0(i, n) cin >> arr[i]; #define rep(i, a, b) for(int i = a; i <= b; i++) #define rrep(i, a, b) for(int i = a; i >= b; i--) typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<ll, ll> pii; typedef vector<ll> vi; typedef vector<vi> vvi; typedef vector<pii> vp; typedef vector<bool> vb; typedef vector<string> vs; typedef map<ll, ll> mii; typedef map<char, ll> mci; typedef priority_queue<ll> pq_mx; typedef priority_queue<ll, vi, greater<>> pq_mn; typedef tree<ll, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> pbds; /* * find_by_order(i) -> returns an iterator to the element at ith position (0 based) * order_of_key(i) -> returns the position of element i (0 based) */ const int N = 2e6 + 5; const int mod = 1e9 + 7; //const int mod = 998244353; const ll inf = 1e18; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void fio() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); } const int M = 1e7 + 5; ll spf[M], mobius[M]; vi primes; void sieve() { rep(x, 2, 1e7) { if (spf[x] == 0) spf[x] = x, primes.pb(x); for (int y = 0; y < sz(primes) and primes[y] <= spf[x] and x * primes[y] <= 1e7; y++) spf[x * primes[y]] = primes[y]; } } void Mobius() { /* * mobius[x] = 1 => x is a square-free +ve int with even no. of prime factors * mobius[x] = -1 => x is a square-free +ve int with odd no. of prime factors * mobius[x] = 0 => x has a squared prime factor */ rep1(x, 1e7) { if (x == 1) mobius[x] = 1; else { if (spf[x] == spf[x / spf[x]]) mobius[x] = 0; else mobius[x] = -mobius[x / spf[x]]; } } } int main() { fio(); sieve(); Mobius(); ll l, r; cin >> l >> r; ll res = (r - l + 1) * (r - l + 1); rep(x, 1, r) { ll cur = r / x - (l - 1) / x; res -= cur * cur * mobius[x]; } // cout << res << endl; rep(x, max(l, 2ll), r) { --res; for (int y = 2 * x; y <= r; y += x) res -= 2; } cout << res; return 0; }
#include <iostream> #include <cstdio> using namespace std; int ans; char s[12]; void read(int &s) { s = 0; bool pd = false; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') pd = true; c = getchar(); } while (c >= '0' && c <= '9') { s = (s << 3) + (s << 1) + (c ^ 48); c = getchar(); } if (pd) s = -s; return; } int main() { scanf("%s", s); for (int i = 0; i <= 11; i++) if (s[i] == 'Z' && s[i + 1] == 'O' && s[i + 2] == 'N' && s[i + 3] == 'e') ans++, i += 3; printf("%d", ans); return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ string S; cin >> S; int flagZ = 0, flagO = 0, flagN = 0, flage = 0; int count = 0; for(int i = 0; i < 12; i++){ if(S.at(i) == 'Z'){ flagZ = 1; continue; } if(S.at(i) == 'O' && flagZ == 1){ flagO = 1; continue; } if(S.at(i) == 'N' && flagO == 1){ flagN = 1; continue; } if(S.at(i) == 'e' && flagN == 1){ count++; flagZ = 0; flagO = 0; flagN = 0; continue; } flagZ = 0; flagO = 0; flagN = 0; } cout << count << endl; }
#include <bits/stdc++.h> #define MOD 1000000007LL using namespace std; typedef long long ll; typedef pair<int,int> P; ll r,x,y; int main(void){ scanf("%lld%lld%lld",&r,&x,&y); ll gg=r*r; ll dist=x*x+y*y; if(gg==dist){ printf("%lld\n",1LL); }else if(gg>dist){ printf("%lld\n",2LL); }else{ ll l=0; ll rr=(x+y)/r+10LL; while(l+1LL<rr){ ll mid=(l+rr)/2LL; ll ggg=gg*mid*mid; if(ggg>=dist){ rr=mid; }else{ l=mid; } } printf("%lld\n",rr); } return 0; }
#include<stdio.h> #include<iostream> #include<algorithm> #include<string> using namespace std; int main() { char c[10]; int e = 0, n = 0, f = 0, ans = 0; for (int i = 0; i < 10; i++) { cin >> c[i]; if (c[i] == 'o') { e++; } else if (c[i] == 'x') { n++; } else { f++; } } if (e > 4) { ans = 0; } if (e == 4) { ans = 24; } if (e == 3) { ans = 24 * f + 12 * 3; } if (e == 2) { ans = 24 * f * (f - 1) / 2 //バラバラ + 36 * f //1個1個2個 + 6 //2個2個 + 8 * 1;} // 1個3個 if (e == 1) { ans = 24 * f * (f - 1) * (f - 2) / 6 //バラバラ + 36 * f * (f - 1) / 2 //1個1個2個 + 6 * f //2個2個 + 8 * f //1個3個 + 1; } // 4個 if (e == 0) { ans = f * (f - 1) * (f - 2) * (f - 3) + 12 * f * (f - 1) * (f - 2) / 2 + 6 * f * (f - 1) / 2 + 4 * f * (f - 1) + f;} printf("%d\n", ans); }
#include<bits/stdc++.h> #define pb push_back using namespace std; #define G getchar() int read() { int x=0; bool flg=false; char ch=G; for (;!isdigit(ch);ch=G) if (ch=='-') flg=true; for (;isdigit(ch);ch=G) x=(x<<3)+(x<<1)+(ch^48); return flg?-x:x; } #undef G #define fi first #define se second typedef long long ll; /*const int mod=; inline int upd(const int &x){return x+(x>>31&mod);} inline void add(int &x,const int &y){x=upd(x+y-mod);} inline void iadd(int &x,const int &y){x=upd(x-y);} int qpow(int x,int y){ int res=1; for (;y;y>>=1,x=1LL*x*x%mod) if (y&1) res=1LL*res*x%mod; return res; }*/ #define rep(i,l,r) for (int i(l);i<=(r);i++) #define per(i,l,r) for (int i(r);i>=(l);i--) int n; void solve(){ n=read(); rep(i,0,n-1){ int x=i*2%n,y=(x+1)%n; printf("%d %d\n",x+1,y+1); } } int main() { for (int T=1;T--;) solve(); }
using namespace std; #include<iostream> #include<bits/stdc++.h> #include<algorithm> #define w(x) int x;cin>>x;while(x--) #define pii pair<int,int> #define mp make_pair #define pb push_back #define lld long double #define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define int long long int int mod = 1e9 + 7; void abc() { FIO; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output2.txt", "w", stdout); #endif } int gcd(int a, int b) { if (b == 0) { return a; } return gcd(b, a % b); } int po(int a, int b) { int res = 1; for (int i = 0; i < 32; i++) { if (b >> i & 1) { res = (res * a) % mod; } a = (a * a) % mod; } return res; } int fun(int n) { int res = 0; while (n) { res += n % 10; n /= 10; } return res; } void solve() { int a, b; cin >> a >> b; int res = max(fun(a), fun(b)); cout << res; } signed main() { abc(); int tt ; //cin >> tt; tt = 1; while (tt--) { solve(); } }
#include<bits/stdc++.h> using namespace std; using int64 = long long; const int mod = 1e9 + 7; // const int mod = 998244353; const int64 infll = (1LL << 62) - 1; const int inf = (1 << 30) - 1; struct IoSetup { IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup; template< typename T1, typename T2 > ostream &operator<<(ostream &os, const pair< T1, T2 > &p) { os << p.first << " " << p.second; return os; } template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; } template< typename T > ostream &operator<<(ostream &os, const vector< T > &v) { for(int i = 0; i < (int) v.size(); i++) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } template< typename T > istream &operator>>(istream &is, vector< T > &v) { for(T &in : v) is >> in; return is; } template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); } template< typename T = int64 > vector< T > make_v(size_t a) { return vector< T >(a); } template< typename T, typename... Ts > auto make_v(size_t a, Ts... ts) { return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...)); } template< typename T, typename V > typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) { t = v; } template< typename T, typename V > typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e, v); } template< typename F > struct FixPoint : F { FixPoint(F &&f) : F(forward< F >(f)) {} template< typename... Args > decltype(auto) operator()(Args &&... args) const { return F::operator()(*this, forward< Args >(args)...); } }; template< typename F > inline decltype(auto) MFP(F &&f) { return FixPoint< F >{forward< F >(f)}; } template< int mod > struct ModInt { int x; ModInt() : x(0) {} ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; } ModInt &operator-=(const ModInt &p) { if((x += mod - p.x) >= mod) x -= mod; return *this; } ModInt &operator*=(const ModInt &p) { x = (int) (1LL * x * p.x % mod); return *this; } ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; } ModInt operator-() const { return ModInt(-x); } ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; } ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; } ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; } ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; } bool operator==(const ModInt &p) const { return x == p.x; } bool operator!=(const ModInt &p) const { return x != p.x; } ModInt inverse() const { int a = x, b = mod, u = 1, v = 0, t; while(b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return ModInt(u); } ModInt pow(int64_t n) const { ModInt ret(1), mul(x); while(n > 0) { if(n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; } friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt< mod >(t); return (is); } static int get_mod() { return mod; } }; using modint = ModInt< mod >; int main() { int N, P; cin >> N >> P; cout << modint(P - 1) * modint(P - 2).pow(N - 1) << "\n"; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> P; #define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0) #define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0) template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;} const char newl = '\n'; const ll mod = 1000000007; //const ll mod = 998244353; const int MAX_N = 100010; ll fact[MAX_N],fact_inv[MAX_N],inv[MAX_N]; ll pow_mod(ll a,ll b) { ll ret; if (b < 0) ret = pow_mod(a,mod+b-1); else if (b == 0) ret = 1; else if (b == 1) ret = a; else { ll c = pow_mod(a,b/2); if (b%2) ret = (c*c)%mod*a%mod; else ret = c*c%mod; } return ret; } void init(int x) { fact[0] = 1;fact[1] = 1; for (int i = 2;i <= x;++i) fact[i] = fact[i-1]*i%mod; fact_inv[x] = pow_mod(fact[x],-1); for (int i = x;i > 0;--i) fact_inv[i-1] = fact_inv[i]*i%mod; for (int i = 1;i <= x;++i) inv[i] = fact_inv[i]*fact[i-1]%mod; } ll combi(ll a, ll b) { return fact[a]*fact_inv[b]%mod*fact_inv[a-b]%mod; } int main() { ll n,p; cin >> n >> p; cout << pow_mod(p-2,n-1)*(p-1)%mod << newl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int INF = (1<<30)-1; const ll LINF = (1LL<<60)-1; #define rep(i, n) for (int i = 0; i < n; i++) #define sz(a) (int)(a.size()) template<class T> bool chmax(T &a, T b) {if (a < b) {a = b;return true;}else return false;} template<class T> bool chmin(T &a, T b) {if (a > b) {a = b;return true;}else return false;} ll mod_pow(ll a, ll n, ll p) { ll ans = 1, tmp = a % p; while (n > 0) { if (n & 1) ans = ans * tmp % p; tmp = tmp * tmp % p; n = (n>>1); } return ans; } //コーナーケースに気をつけろ! int main() { ll n, m, mod = 998244353, ans = 0, tmp = 0; cin >> n >> m; ans = n * mod_pow(m, n, mod) % mod; for (ll l = 1; l <= n-1; l++) { for (ll x = 1; x <= m; x++) { tmp = (tmp + (n-l) * mod_pow(m, n-l-1, mod) % mod * mod_pow(m-x, l-1, mod) % mod) % mod; } } cout << (ans + mod - tmp) % mod << endl; return 0; } //小数点精度 //cout << fixed << std::setprecision(15) << y << endl;
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; //template #define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define ALL(v) (v).begin(),(v).end() using ll=long long int; const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12; template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;} template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;} //end struct UnionFind{ vector<int> par; int n; UnionFind(){} UnionFind(int _n):par(_n,-1),n(_n){} int root(int x){return par[x]<0?x:par[x]=root(par[x]);} bool same(int x,int y){return root(x)==root(y);} int size(int x){return -par[root(x)];} bool unite(int x,int y){ x=root(x),y=root(y); if(x==y)return false; if(size(x)>size(y))swap(x,y); par[y]+=par[x]; par[x]=y; n--; return true; } }; template<unsigned mod=998244353>struct fp { using uint=unsigned; uint v; static uint get_mod(){return mod;} int inv() const{ int tmp,a=v,b=mod,x=1,y=0; while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y); if(x<0){x+=mod;} return x; } fp(ll x=0){init(x%mod+mod);} fp& init(uint x){v=(x<mod?x:x-mod); return *this;} fp operator-()const{return fp()-*this;} fp pow(ll t){fp res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;} return res;} fp& operator+=(const fp& x){return init(v+x.v);} fp& operator-=(const fp& x){return init(v+mod-x.v);} fp& operator*=(const fp& x){v=ll(v)*x.v%mod; return *this;} fp& operator/=(const fp& x){v=ll(v)*x.inv()%mod; return *this;} fp operator+(const fp& x)const{return fp(*this)+=x;} fp operator-(const fp& x)const{return fp(*this)-=x;} fp operator*(const fp& x)const{return fp(*this)*=x;} fp operator/(const fp& x)const{return fp(*this)/=x;} bool operator==(const fp& x)const{return v==x.v;} bool operator!=(const fp& x)const{return v!=x.v;} friend istream& operator>>(istream& is,fp& x){is>>x.v; return is;} friend ostream& operator<<(ostream& os,fp& x){os<<x.v; return os;} }; using Fp=fp<>; template<typename T>struct factorial { vector<T> Fact,Finv,Inv; factorial(int maxx){ Fact.resize(maxx); Finv.resize(maxx); Inv.resize(maxx); Fact[0]=Fact[1]=Finv[0]=Finv[1]=Inv[1]=1; rep(i,2,maxx){Fact[i]=Fact[i-1]*i;} Finv[maxx-1]=Fact[maxx-1].inv(); for(int i=maxx-1;i>=2;i--){Finv[i-1]=Finv[i]*i; Inv[i]=Finv[i]*Fact[i-1];} } T fact(int n,bool inv=0){if(n<0)return 0; return (inv?Finv[n]:Fact[n]);} T inv(int n){if(n<0)return 0; return Inv[n];} T nPr(int n,int r,bool inv=0){if(n<0||n<r||r<0)return 0; return fact(n,inv)*fact(n-r,inv^1);} T nCr(int n,int r,bool inv=0){if(n<0||n<r||r<0)return 0; return fact(n,inv)*fact(r,inv^1)*fact(n-r,inv^1);} }; Fp pre[5010][5010]; int main(){ int n,m; cin>>n>>m; rep(x,1,5005){ pre[x][0]=1; rep(t,0,5005)pre[x][t+1]=pre[x][t]*x; } Fp res; rep(len,1,n+1)rep(v,1,m+1){ if(len==n){ res+=(pre[m-v+1][n]-pre[m-v][n]); continue; } res+=(pre[m-v+1][len]-pre[m-v][len])*(v-1)*pre[m][max(0,n-len-1)]*2; res+=(pre[m-v+1][len]-pre[m-v][len])*(v-1)*(v-1)*pre[m][max(0,n-len-2)]*max(0,n-len-1); } cout<<res<<'\n'; return 0; }
#include<bits/stdc++.h> using namespace std; #define A(x) (x).begin(),(x).end() #define sz(x) ((int)(x).size()) #define int int64_t void _read(); int mod; inline int inv(int a) { a %= mod; if (a < 0) a += mod; int b = mod, u = 0, v = 1; while (a) { int t = b / a; b -= t * a; swap(a, b); u -= t * v; swap(u, v); } assert(b == 1); if (u < 0) u += mod; return u; } void test() { int n,s,k; cin >> n >> s >> k; mod = n; // kx == s; int d = __gcd(k,n); if(s % d) { cout << -1 << '\n'; return; } k /= d; s /= d; n /= d; mod = n; s %= mod; k %= mod; int y = inv(k); int ans = (s * y) % mod; cout << mod - ans << '\n'; } main () { _read(); int tc; cin >> tc; while(tc--) test(); return 0; }; void _read() { ios_base :: sync_with_stdio(false); cin.tie(NULL); #ifdef LOCAL freopen("input.txt","r",stdin); #endif }
#include<bits/stdc++.h> #define endl "\n" #define pb push_back #define ll long long int #define f first #define s second using namespace std; ll mod=1e9+7; struct gcd_type { ll x,y,g; }; gcd_type ext_gcd(ll a,ll b) { if(b==0) return{1,0,a}; gcd_type p= ext_gcd(b,a%b); return {p.y,p.x-a/b*p.y,p.g}; } ll shift(ll a,ll add) { ll l=0,r=(abs(a)/add)+5,ans; while(l<=r) { ll mid=(l+r)/2; if(mid*add>-a)ans=mid,r=mid-1; else l=mid+1; } a+=ans*add; //cout<<ans<<">>>"<<endl; return a; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin>>t; while(t--) { ll n,s,k; cin>>n>>s>>k; gcd_type q=ext_gcd(k,n); if(s%q.g!=0)cout<<"-1"<<endl; else { q.x*=s/q.g,q.y*=s/q.g; ll x=q.x,y=q.y,g=q.g,lcm=(n*k)/g; ll num=(((y%(k/g))*(n%lcm)-s%lcm)%lcm+lcm); //cout<<x<<" "<<y<<" "<<num<<"::::"<<endl; cout<<(num%lcm)/k<<endl; } } return 0; }
//#define _DEBUG #include "bits/stdc++.h" #define CHOOSE(a) CHOOSE2 a #define CHOOSE2(a0,a1,a2,a3,a4,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 #ifdef _DEBUG #define debug(...) CHOOSE((__VA_ARGS__,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 kaigyo cout<<endl #define eps 1e-7 #define mp(a1,a2) make_pair(a1,a2) #define ALL(a) (a).begin(),(a).end() #define rALL(a) (a).rbegin(),(a).rend() typedef long long ll; typedef long double ld; using namespace std; 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; ll H[200001],W[200001]; ll saleft[200001],saright[200001]; int main(){ int N,M; scan(N>>M); rep(i,N) scan(H[i]); rep(j,M) scan(W[j]); sort(H,H+N); sort(W,W+M); rep(i,N/2){ saleft[i+1]=saleft[i]+abs(H[2*i]-H[2*i+1]); } brep1(i,N/2){ saright[i-1]=saright[i]+abs(H[2*i]-H[2*i-1]); } ll ans=INFl; rep(j,M){ int soeji=lower_bound(H,H+N,W[j])-H; int iti=soeji/2; int taisho=iti*2; debug(j,W[j],soeji,iti,taisho); debug(H[taisho]); ll sum=saleft[iti]+saright[iti]+abs(H[taisho]-W[j]); chmin(ans,sum); } prin(ans); return 0; }
#include<stdio.h> #include<stdlib.h> #include<math.h> #define rep(i,N) for(int i=0;i<(int)N;i++) static int IN(void) { int x=0,f=1,c;while(c=getchar(),c<48||c>57){if(c==45)f=-f;} while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f*x; } static void OUT(long x){if(x<0){putchar('-'),x=-x;}if(x>=10){OUT(x/10);}putchar(x-x/10*10+48);} typedef struct List{int nx,v,c,d;}edge; int hsz=0;long minHeap[200001][2],output[2]; static void PUSH(int id,long key) { int i=++hsz,j=i>>1;long sw[2]; minHeap[i][0]=id,minHeap[i][1]=key; while(j) { if(minHeap[i][1]<minHeap[j][1]) { sw[0]=minHeap[j][0],sw[1]=minHeap[j][1]; minHeap[j][0]=minHeap[i][0],minHeap[j][1]=minHeap[i][1]; minHeap[i][0]=sw[0],minHeap[i][1]=sw[1]; i=j;j>>=1; }else break; } } static void POP(void) { int i=1,j=i+1;long sw[2]; output[0]=minHeap[i][0],output[1]=minHeap[i][1]; minHeap[i][0]=minHeap[hsz][0],minHeap[i][1]=minHeap[hsz--][1]; while(j<=hsz) { if(j<hsz&&minHeap[j^1][1]<minHeap[j][1]){j^=1;} if(minHeap[j][1]<minHeap[i][1]) { sw[0]=minHeap[j][0],sw[1]=minHeap[j][1]; minHeap[j][0]=minHeap[i][0],minHeap[j][1]=minHeap[i][1]; minHeap[i][0]=sw[0],minHeap[i][1]=sw[1]; i=j;j=i<<1; }else break; } return; } int main(void) { int N=IN(),M=IN(),vis[100000],esz=0,adj[100000]; long dist[100000];edge e[200000]; rep(i,N){dist[i]=9e18;} rep(i,M) { int A=IN(),B=IN(),C=IN(),D=IN(); e[2*i].nx=adj[A-1];adj[A-1]=2*i+1; e[2*i].v=B;e[2*i].c=C;e[2*i].d=D; e[2*i+1].nx=adj[B-1];adj[B-1]=2*i+2; e[2*i+1].v=A;e[2*i+1].c=C;e[2*i+1].d=D; } dist[0]=0l; PUSH(1,0l); while(hsz) { POP(); int u=output[0]-1;long v=output[1]; if(vis[u]){continue;} for(int i=adj[u];i;i=e[i-1].nx) { int c=e[i-1].c,d=e[i-1].d,to=e[i-1].v;long len=0l; if(d) { int x=sqrt(d)-1; if(d/(x+1)>1+d/(x+2)){x++;} if(d/(x+1)>1+d/(x+2)){x++;} if(v>1l*x){len=1l*c+1l*d/(v+1l);} else{len=1l*c+1l*x-v+1l*d/(1l*x+1l);} }else{len=1l*c;} if(dist[to-1]>v+len){dist[to-1]=v+len;PUSH(to,v+len);} } vis[u]=1; } if(dist[N-1]==9e18){puts("-1");}else OUT(dist[N-1]); }
#define _DEBUG //ヘッダー #include<bits/stdc++.h> using namespace std; //型定義 typedef long long ll; //定数 const ll INF=1e+18; const int MOD=1e+9+7; //デバッグ #define CHOOSE(a) CHOOSE2 a #define CHOOSE2(a0,a1,a2,a3,a4,x,...) x #define debug1(x1) cout<<#x1<<": "<<x1<<endl #define debug2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl #define debug3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl #define debug4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl #define debug5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl #ifdef _DEBUG #define debug(...) CHOOSE((__VA_ARGS__,debug5,debug4,debug3,debug2,debug1,~))(__VA_ARGS__) #else #define debug(...) #endif //REPマクロ #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 REP2(i,a,b) for(ll i=a;i<(ll)(b);i++) #define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--) // 多次元 vector 生成 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...)); } //vectorの扱い #define ALL(x) (x).begin(),(x).end() //sortなどの引数省略 #define SIZE(x) ((ll)(x).size()) //size #define MAX(x) *max_element(ALL(x)) //最大値 #define MIN(x) *min_element(ALL(x)) //最小値 //省略 using vi = vector<int>; using vii = vector<vector<int>>; using vl = vector<ll>; using vll = vector<vector<ll>>; using pii = pair<int,int>; using pll = pair<ll,ll>; int main(){ ll N,K; cin>>N>>K; vl a(N-1,0); REP(i,N-1){ a[i]=i+1; } vll G(N,vl(N,0)); REP(i,N){ REP(j,N){ cin>>G[i][j]; } } ll ans=0; sort(a.begin(),a.end()); do{ vl b(N); REP(i,N-1){ b[i]=a[i]; } b[N-1]=0; ll tmp=0; ll cur=0; REP(i,N){ tmp+=G[cur][b[i]]; cur=b[i]; } if(tmp==K) ans++; }while(next_permutation(a.begin(),a.end())); cout<<ans<<endl; }
#include<bits/stdc++.h> #include<iostream> using namespace std; #define int long long int #define ld long double #define all(x) (x).begin(), (x).end() #define fi first #define se second #define removeDuplicates(a) a.resize(unique(all(a))-a.begin()) #define endl '\n' #define setbits(x) (__builtin_popcount(x)) int mod=1000000007; int INF64=mod*mod+1; void solve(){ int n,k; cin>>n>>k; vector<vector<int>> d(n,vector<int> (n)); for(int i=0;i<n;i++){ for(int j=0;j<n;j++) cin>>d[i][j]; } int ans=0; vector<int> perm(n-1); iota(all(perm),1); do{ int curr=d[0][perm[0]]+d[0][perm.back()]; for(int i=0;i<n-2;i++) curr+=d[perm[i]][perm[i+1]]; ans+=(curr==k); }while(next_permutation(all(perm))); cout<<ans<<endl; } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0); int T=1; // cin>>T; for(int i=1;i<=T;i++){ // cout<<"Case #"<<i<<": "; solve(); } cerr<<"Time : "<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n"; }
// #define _GLIBCXX_DEBUG #include <bits/stdc++.h> // #include <atcoder/all> // g++ main.cpp -std=c++17 -I . using namespace std; // using namespace atcoder; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(v) (v).begin(), (v).end() template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;} template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;} using ll=long long; const int inf = INT_MAX / 2; const ll INF = 1LL << 60; const ll MOD = 1000000007; // const int MOD = 998244353; // cout << fixed << setprecision(15) << ans << endl; // using mint = modint1000000007; //////////////////////////////////////////////////////////////////////////////////////////// int main() { int n;cin>>n; vector<ll> a(n); for(auto&i:a)cin>>i; sort(all(a)); double x = a[n/2]*0.5; double ans = 0; rep(i, n) ans += x + a[i] - min((double)a[i], 2*x); // cout << ans << endl; cout << fixed << setprecision(15) << ans / n << endl; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define loop(i,n) for(ll i=0;i<n;i++) #define loopn(i,j,n) for(ll i=j;i<n;i++) #define m_arr(arr, n) vector<ll>arr(n) #define m_arre(arr) vector<ll>arr #define m_set(sat) set<ll>sat #define ppn(name) pair<ll,ll>name #define pp pair<ll,ll> #define sort_all(arr) sort(arr.begin(), arr.end()) #define pi 3.141592653589793238 #define mod 1000000007 #define inf 1000000000000000000 ll gcd(ll a, ll b){if(a==0)return b;if(b==0)return a;return gcd(b%a, a);} ll power(ll a, ll b) { ll res=1; while(b>0) { if(b%2!=0) res = (res*1ll*a)%mod; b/=2; a=(a*1ll*a)%mod; } return res%mod; } vector<bool>arr(100000); void sieve() { for(ll i=2;i<100000;i++) { if(!arr[i]) { ll temp=i+i; while(temp<100000) { arr[temp]=true; temp+=i; } } } } void solve() { ll n; cin>>n; m_arr(arr, n); loop(i, n)cin>>arr[i]; map<ll, ll>mp; loop(i, n) { mp[arr[i]%200]++; } ll res=0; for(auto it=mp.begin();it!=mp.end();it++) { res+=(it->second*1ll*(it->second-1))/2; } cout<<res<<endl; return; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); //ll t;cin>>t;while(t--) solve(); return 0; }
#pragma region Region_1 #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) #define drep(i, n) for (int i = (n)-1; i >= 0; --i) #define srep(i, s, t) for (int i = s; i < t; ++i) #define rng(a) a.begin(), a.end() #define rrng(a) a.rbegin(), a.rend() using ll = long long; using P = pair<ll, ll>; using VI = vector<int>; using VVI = vector<VI>; using VL = vector<ll>; using VVL = vector<VL>; using VP = vector<P>; using VS = vector<string>; using VC = vector<char>; using VVC = vector<vector<char>>; #define MOD 1000000007 // #define MOD 998244353 const int INF = (int)1e9 + 10; // int max > 2*10^9 const long long INFL = (ll)2e18 + 10; // ll max > 9*10^18 template <class T, class C> bool chmax(T& a, C b) { if (a < b) { a = b; return true; } return false; } template <class T, class C> bool chmin(T& a, C b) { if (a > b) { a = b; return true; } return false; } template <class T> T sum(const vector<T>& v) { T res = 0; for (size_t i = 0; i < v.size(); ++i) res += v[i]; return res; } ///////////////////////////////////////////////////////// // print like python // https://qiita.com/Lily0727K/items/06cb1d6da8a436369eed ///////////////////////////////////////////////////////// void print() { cout << endl; } template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { cout << head; if (sizeof...(tail) != 0) cout << " "; print(forward<Tail>(tail)...); } template <class T> void print(vector<T>& vec) { for (auto& a : vec) { cout << a; if (&a != &vec.back()) cout << " "; } cout << endl; } template <class T> void print(vector<vector<T>>& df) { for (auto& vec : df) { print(vec); } } #pragma endregion Region_1 ///////////////////////////////////////////////////////// struct mint { ll x; // typedef long long ll; int mod; mint(ll x = 0, int mod = MOD) : x((x % mod + mod) % mod), mod(mod) {} mint operator-() const { return mint(-x); } mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } // x^t mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; // 桁ずらし if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod - 2); } mint& operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } }; istream& operator>>(istream& is, mint& a) { return is >> a.x; } ostream& operator<<(ostream& os, const mint& a) { return os << a.x; } int main() { std::cout << std::setprecision(15); ////////////////////////////////////////// int n; cin >> n; VL a(n); rep(i, n) { cin >> a[i]; } VL s(n + 1, 0); VL s2(n + 1, 0); rep(i, n) { s[i + 1] = s[i] + a[i]; } rep(i, n) { s2[i + 1] = s2[i] + s[i + 1]; } ll mv = 0; rep(i, n) { chmax(mv, a[i]); print(mv * (i + 1) + s2[i + 1]); } return 0; }
#include <bits/stdc++.h> using namespace std; //解説見て解きなおし。 int main(){ long long n; cin>>n; vector<long long>list(n); // vector<long long>list2(n); for(int i=0;i<n;i++){ cin>>list.at(i); // list2.at(i)=list.at(i); // if(i>0) list2.at(i)+=list2.at(i-1); } long long total=0;//1+(1+2)+(1+2+3)+...今まで全部の合計 long long amax =0; long long x =0; //1-iの合計をつっこんでおく for(int i=0;i<n;i++){ x += list.at(i); total += x; amax=max(amax,list.at(i)); cout<<total+amax*(i+1)<<endl; } }
#include<bits/stdc++.h> using namespace::std; int n; int main(){ scanf("%d", &n); printf("%d\n", (1 << n) - 1); for(int i = 1; i < (1 << n); i++){ for(int j = 1; j <= (1 << n); j++){ putchar("BA"[__builtin_popcount(i & j) & 1]); } puts(""); } return 0; }
#include <iostream> #include <cmath> using namespace std; typedef long long ll; const int N=1e5+7; ll a,b,c,ans,res; void gao(ll x){ a=1,b=0,c=0; ans=x; while(x!=1){ if(x%2){ c+=pow(2,b); x--; } b++; x/=2; a=x; ans=min(ans,a+b+c); } } int main(){ cin>>res; gao(res); cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; string s1,s2,sm; int t1=0,t2=0,tm; for(int i=0;i<n;i++){ string s; int t; cin >> s >> t; if(t > t1){ sm = s1; tm = t1; s1 = s; t1 = t; s2 = sm; t2 = tm; } else if(t > t2 && t < t1){ s2 = s; t2 = t; } } cout << s2 << endl; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <set> #include <stack> #include <string> #include <string.h> #include <vector> using namespace std; typedef long long ll; #define rep(i, init, end) for(ll i = init; i < end; i++) #define REP(i, init, end) for(ll i = init; i < end + 1; i++) #define rev(i, end, init) for(ll i = init - 1; i >= end; i--) #define REV(i, end, init) for(ll i = init; i >= end; i--) #define PI 3.14159265359 #define EPS 0.0000000001 #define MOD 1000000007 //cout << std::fixed << std::setprecision(15) << y << endl; int main(){ ll N; cin >> N; pair<ll, string> p[N]; string S; ll T; rep(i, 0, N){ cin >> S >> T; p[i] = make_pair(T, S); } sort(p, p + N, greater<pair<ll, string>>()); cout << p[1].second << endl; return 0; }
#include <bits/stdc++.h> //#include <atcoder/all> #define For(i, a, b) for (int(i) = (int)(a); (i) < (int)(b); ++(i)) #define rFor(i, a, b) for (int(i) = (int)(a)-1; (i) >= (int)(b); --(i)) #define rep(i, n) For((i), 0, (n)) #define rrep(i, n) rFor((i), (n), 0) #define fi first #define se second using namespace std; typedef long long lint; typedef unsigned long long ulint; typedef pair<int, int> pii; typedef pair<lint, lint> pll; 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; } template <class T> T div_floor(T a, T b) { if (b < 0) a *= -1, b *= -1; return a >= 0 ? a / b : (a + 1) / b - 1; } template <class T> T div_ceil(T a, T b) { if (b < 0) a *= -1, b *= -1; return a > 0 ? (a - 1) / b + 1 : a / b; } constexpr lint mod = 1000000007; constexpr lint INF = mod * mod; constexpr int MAX = 200010; int main() { int x, y; scanf("%d%d", &x, &y); puts(abs(x - y) <= 2 ? "Yes" : "No"); }
#include <bits/stdc++.h> using namespace std; string to_string(string s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(bool b) { return (b ? "true" : "false"); } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #define pb push_back #define ff first #define ss second #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) ((int) (x).size()) #define endl '\n' typedef long long ll; typedef vector <int> vi; typedef pair <int, int> pi; void solve() { //Test case code goes here int a, b; cin >> a >> b; for (int i = 0; i < a; ++i) { int x; cin >> x; if (x == b) continue; cout << x << " "; } return; } int main() { ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); // cout << fixed << setprecision(15); solve(); return 0; }
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #include <bits/stdc++.h> using namespace std; /* DEBUGGING */ 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 deb(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define deb(x...) #endif /* MACROS */ typedef long long int ll; 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; typedef map<int,int> mii; typedef tuple<int,int,int> tup; #define ff first #define ss second #define pb push_back #define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define lb lower_bound #define ub upper_bound #define all(x) (x).begin(), (x).end() #define lcm(x, y) ((x) * (y) / __gcd(x, y)) #define ps(x,y) fixed<<setprecision(y)<<x #define setbit(x) __builtin_popcountll(x) #define rep(i,a,b) for(int i=a ; i<b ; ++i) #define repr(i,a,b) for(int i=a ; i>=b ; --i) /* CONSTANTS */ #define PI 3.141592653589793 const ll MOD = 1e9 + 7; const ll INF = 1000000000; const ll MAX_N = 1e5 + 3; vi node_col(MAX_N),vis(MAX_N , 0),adj[MAX_N]; mii mp; set<int>ans; void dfs(int node){ vis[node] = 1; mp[node_col[node]]++; if(mp[node_col[node]]==1){ ans.insert(node); } for(auto x:adj[node]){ if(!vis[x]){ dfs(x); } } mp[node_col[node]]--; } void solve(){ int n; cin >> n; rep(i,1,n+1) cin >> node_col[i]; rep(i,1,n){ int a,b; cin >> a >> b; adj[a].pb(b); adj[b].pb(a); } dfs(1); for(auto x:ans) cout << x << "\n"; } int main(){ IOS; solve(); }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; typedef long long int ll; typedef unsigned long long int sll; typedef long double ld; #define A 1000000007 #define D 100000000000000ll #define B 998244353ll #define C 1000000000000000000ll #define M 4000 #define F first #define S second #define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define oset tree<pair<ll,ll>, null_type,greater<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> #define pb push_back #define pf push_front #define pob pop_back #define pof pop_front #define mxe(v) *max_element(v.begin(),v.end()) #define mne(v) *min_element(v.begin(),v.end()) #define rev(v) reverse(v.begin(),v.end()) #define sor(v) sort(v.begin(),v.end()) #define uni(v) unique(v.begin(),v.end()) #define bs binary_search #define lb(v,x) lower_bound(v.begin(),v.end(),x) #define ub(v,x) upper_bound(v.begin(),v.end(),x) #define ve vector #define br break #define PI acos(-1) #define subt cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n" ll n; ve<ll> ch(205,-1),val(205,-1),dp(205,-1); bool com(ll a, ll b) { if(ch[a]==1 || ch[b]==0 || (val[a]!=-1 && val[a]!=b) || (val[b]!=-1 && val[b]!=a) || (ch[a]==0 && ch[b]==1 && val[a]==-1 && val[b]==-1)) return false; return true; } void fun(ll x) { if(dp[x]!=-1) return; ll p=(x+n+n+1)/2; bool ans=0; for(ll i=x+1;i<=p;i++) { bool b=1; for(ll j=x,k=i;j<i;j++,k++) b=(b && com(j,k)); if(b) { fun(i+i-x); ans=(ans || (dp[i+i-x]==1)); } } if(ans) dp[x]=1; else dp[x]=0; } int main() { FAST; cin>>n; for(ll i=0;i<n;i++) { ll a,b; cin>>a>>b; if(a!=-1) { if(ch[a]!=-1) { cout<<"No"; return 0; } ch[a]=0; val[a]=b; } if(b!=-1) { if(ch[b]!=-1) { cout<<"No"; return 0; } ch[b]=1; val[b]=a; } } dp[n+n+1]=1; fun(1); if(dp[1]==1) cout<<"Yes"; else cout<<"No"; subt; return 0; }
#include <bits/stdc++.h> using namespace std; #define ar array #define ll long long const int MAX_N = 1e5 + 5; const ll MOD = 1e9 + 7; const ll INF = 1e9; ll qexp(ll a, ll b, ll m) { ll res = 1; while (b) { if (b % 2) res = res * a % m; a = a * a % m; b /= 2; } return res; } vector<ll> fact; void precompute(int n) { fact.assign(n + 1, 1); for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * i % MOD; } ll nCk(int n, int k) { if (k < 0 || k > n) return 0; return fact[n] * qexp(fact[k], MOD - 2, MOD) % MOD * qexp(fact[n - k], MOD - 2, MOD) % MOD; } // Observation: Counting Diagonal-Avoiding Paths, similar to the method to calculate Catalan number void solve() { ll n, m, k; cin >> n >> m >> k; if (n - m > k) { cout << 0 << "\n"; return; } ll ans = nCk(n + m, n) - nCk(n + m, m + k + 1); if (ans < 0) ans += MOD; cout << ans << "\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); precompute(2e6); int tc = 1; // cin >> tc; for (int t = 1; t <= tc; t++) { // cout << "Case #" << t << ": "; solve(); } }
#include<bits/stdc++.h> using namespace std; #define ll long long int int n,m,t; void solve() { cin>>n>>m>>t; int a[m],b[m],charge=n; bool flag=true; int time=0; for(int i=0;i<=m;++i) { if(i<m) cin>>a[i]>>b[i]; else {a[i]=t; b[i]=t; } charge= charge-(a[i]-time); if(charge<=0) flag=false; charge=min(n, charge+b[i]-a[i]); time=b[i]; } if (flag) cout<<"Yes"; else cout<<"No"; } int main() { ios::sync_with_stdio(0); cin.tie(0); solve(); return 0; }
#ifdef Rahul #include "RAHUL.h" #else #include <bits/stdc++.h> using namespace std; #define error(...) 42; #endif #define SZ(v) int((v).size()) #define ALL(vec) begin(vec), end(vec) typedef long long i64; template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;} template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;} template<typename T> void kek(T ans) {cout << ans << endl; exit(0);} #define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; } const int MOD = (int) 1e9 + 7; const i64 INF = (i64) 1e18 + 42; int main() { cin.tie(nullptr) -> sync_with_stdio(false); int n, t; cin >> n >> t; vector<int> a(n); for (int &x : a) cin >> x; uin(n, 20); int m = SZ(a) - n; set<i64> b; for (int nask = 0; nask < (1 << n); ++nask) { i64 sum = 0; for (int k = 0; k < n; ++k) { if (nask >> k & 1) { sum += a[k]; } } b.insert(sum); } i64 ans = 0; for (int nask = 0; nask < (1 << m); ++nask) { i64 sum = 0; for (int k = 0; k < m; ++k) { if (nask >> k & 1) { sum += a[n + k]; } } if (sum <= t) { uax(ans, sum + *prev(b.upper_bound(t - sum))); } } kek(ans); }
#include <bits/stdc++.h> using namespace std; #define LL long long LL n, t, a[45], px, py; LL x[1100000], y[1100000]; void fx(int p, int ed, LL sum) { if (p > ed) { x[++px] = sum; return; } fx(p + 1, ed, sum); fx(p + 1, ed, sum + a[p]); return; } void fy(int p, int ed, LL sum) { if (p > ed) { y[++py] = sum; return; } fy(p + 1, ed, sum); fy(p + 1, ed, sum + a[p]); return; } int main() { scanf("%lld%lld", &n, &t); for (int i = 1; i <= n; i++) { scanf("%lld", &a[i]); } fx(1, n / 2, 0LL); fy(n / 2 + 1, n, 0LL); sort(x + 1, x + px + 1); sort(y + 1, y + py + 1); LL mx = -1; for (int i = 1; i <= px; i++) { while (py > 0 && x[i] + y[py] > t) py--; if (py == 0) break; mx = max(mx, x[i] + y[py]); } printf("%lld\n", mx); return 0; }
#include <bits/stdc++.h> #define int long long int #define all(x) x.begin(),x.end() #define allr(x) x.rbegin(),x.rend() using namespace std; const int Nx = 1e6+10; class node{ public: //variables int val; node(){ //initialization val = 0; } }; int arr[300001]; node tree[4*Nx]; node merge(node left,node right){ node temp; //merging logic temp.val = (left.val ^ right.val); return temp; } void build(int indx,int start,int end){ if(start == end){ //leaf logic tree[indx].val = arr[start]; return ; } int mid = (start + end) / 2; build(2*indx,start,mid); build(2*indx+1,mid+1,end); tree[indx] = merge(tree[2*indx],tree[2*indx+1]); } node query(int indx,int start,int end,int qs,int qe){ if(qs > end || qe < start){ node temp; return temp; } if(qs <= start && end <= qe){ return tree[indx]; } int mid = (start + end) / 2; return merge(query(2*indx,start,mid,qs,qe),query(2*indx+1,mid+1,end,qs,qe)); } void update(int node,int start,int end,int indx,int val = -1){ if(start == end){ //update logic tree[node].val = (tree[node].val ^ val); return ; } int mid = (start + end)/2; if(indx <= mid){ update(2*node,start,mid,indx,val); }else{ update(2*node+1,mid+1,end,indx,val); } tree[node] = merge(tree[2*node],tree[2*node+1]); } signed main(){ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); int n,q; cin >> n >> q; for(int i = 0;i < n;i++){ cin >> arr[i]; } build(1,0,n - 1); while(q--){ int t,a,b; cin >> t >> a >> b; if(t == 2){ a--; b--; cout << query(1,0,n - 1,a,b).val << "\n"; }else{ a--; update(1,0,n-1,a,b); } } }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; using graph=vector<vector<int>>; void add_undirected_edge(graph& G,int u,int v){ G[u].emplace_back(v); G[v].emplace_back(u); } void add_directed_edge(graph& G,int u,int v){ G[u].emplace_back(v); } int dep[200000]; vector<int> D[200000]; void dfs(int u,int p,const graph& T){ D[dep[u]].emplace_back(u); for(int v:T[u]) if(v!=p) { dep[v]=dep[u]+1; dfs(v,u,T); } } class Euler_tour_for_subtrees{ vector<int> L,R; const graph& Tr; int idx; void dfs(int u,int p){ L[u]=idx++; for(int v:Tr[u]) if(v!=p) dfs(v,u); R[u]=idx; } public: Euler_tour_for_subtrees(const graph& Tr,int root):L(Tr.size()),R(Tr.size()),Tr(Tr),idx(0){ dfs(root,-1); } int get_index(int u)const{ return L[u]; } pair<int,int> get_subtree(int u)const{ return {L[u],R[u]}; } }; int main(){ int n; scanf("%d",&n); graph T(n); for(int v=1;v<n;v++){ int u; scanf("%d",&u); u--; add_undirected_edge(T,u,v); } dfs(0,-1,T); Euler_tour_for_subtrees ET(T,0); int q; scanf("%d",&q); rep(_,q){ int u,d; scanf("%d%d",&u,&d); u--; if(dep[u]>d){ puts("0"); continue; } auto [L,R]=ET.get_subtree(u); if(D[d].empty() || R<=ET.get_index(D[d][0]) || ET.get_index(D[d].back())<L){ puts("0"); continue; } int lo=-1,hi=int(D[d].size())-1; while(hi-lo>1){ int mi=(lo+hi)/2; int idx=ET.get_index(D[d][mi]); if(L<=idx){ hi=mi; } else lo=mi; } int l=hi; lo=0; hi=D[d].size(); while(hi-lo>1){ int mi=(lo+hi)/2; int idx=ET.get_index(D[d][mi]); if(idx<R){ lo=mi; } else hi=mi; } int r=hi; printf("%d\n",r-l); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll, ll> p_ll; typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i) #define ture ture #define flase false #define falg flag #define REP(i, x) for (ll i = 0; i < (ll)(x); i++) #define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++) #define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--) #define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--) #define all(x) (x).begin(), (x).end() const ll MOD = pow(10, 9) + 7; const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18 const int INF = pow(2, 30) - 1; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll comb(ll n,ll k){ ll ans = 1; REP(i, k) { ans *= n - i; ans /= i + 1; } return ans; } int main() { ios::sync_with_stdio(false); cin.tie(0); ll N; string S; cin >> S; ll ans = 0; REP(i,10){ REP(j,10){ REP(k,10){ REP(l,10){ bool flag = true; REP(a,10){ if(S.at(a)=='o'){ if (a == i || a == j || a == k || a == l) { } else { flag = false; break; } } else if(S.at(a)=='x'){ if (a == i || a == j || a == k || a == l){ flag = false; break; } else{ } } } if(flag){ ans++; } flag = true; } } } } cout << ans << endl; /*ll ok = 0, ng = 0, hatena = 0; REP(i,10){ if(S.at(i)=='o'){ ok++; } else if(S.at(i)=='x'){ ng++; } else{ hatena++; } } if(ok>=5){ cout << 0 << endl; } else if(ng)*/ }
/** * author: shu8Cream * created: 15.05.2021 20:32:47 **/ #include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i=0; i<(n); i++) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() using ll = long long; using P = pair<ll,ll>; using vi = vector<ll>; using vvi = vector<vi>; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); string s; cin >> s; ll n = s.size(); ll maru = 0, batsu = 0, hate = 0; rep(i,n){ if(s[i]=='o') maru++; if(s[i]=='x') batsu++; if(s[i]=='?') hate++; } ll ans = 0; rep(i,10)rep(j,10)rep(k,10)rep(l,10){ string t = "xxxxxxxxxx"; t[i] = 'o'; t[j] = 'o'; t[k] = 'o'; t[l] = 'o'; bool f = true; rep(_,10){ if(s[_]=='x' && t[_]=='o') f = false; if(s[_]=='o' && t[_]=='x') f = false; } if(f) ans++; } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; int read(){ int x=0,f=1;char c=getchar(); while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();} while('0'<=c&&c<='9'){x=x*10+c-'0';c=getchar();} return x*f; } int n,flg[200005];string s[200005];char ch[15]; map<string,int>M; int main(){ n=read(); for(int i=1;i<=n;++i){scanf("%s",ch);if(ch[0]=='!')s[i]=ch+1,flg[i]=1;else s[i]=ch;} for(int i=1;i<=n;++i)if(!flg[i])M[s[i]]=1; for(int i=1;i<=n;++i)if(flg[i]&&M[s[i]])return cout<<s[i],0; puts("satisfiable"); }
#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include<iostream> #include<cstdint> #include<cstddef> #include<vector> #include<set> #include<map> #include<algorithm> //#include<atcoder/all> //using namespace atcoder; using namespace std; using i32 = int_fast32_t; using i64 = int_fast64_t; using usize = size_t; using u32 = uint_fast32_t; using u64 = uint_fast64_t; template<typename T> using vec = vector<T>; #define rep(i, n) for (i64 i = 0; i < (i64)(n); ++i) #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() using P = pair<i64,i64>; void solve(){ } int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); i64 n; cin >> n; map<string,i64> mp; vec<string> s(n); rep(i,n){ cin >> s[i]; mp[s[i]]++; } rep(i,n){ string now = s[i]; i64 cnt = 0; if(mp[now] >= 1){ cnt++; } string t = "!"; t = t + now; if(mp[t] >= 1)cnt++; if(cnt == 2){ cout << now << endl; return 0; } } cout << "satisfiable" << endl; }
#include<bits/stdc++.h> using namespace std; #define ll long long ll gcd(ll a, ll b, ll& x, ll& y) { if (b == 0) { x = 1; y = 0; return a; } ll x1, y1; ll d = gcd(b, a % b, x1, y1); x = y1; y = x1 - y1 * (a / b); return d; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll t; cin>>t; while(t--) { ll n,s,k; cin>>n>>s>>k; ll x,y; x=0,y=0; ll g=__gcd(n,k); if(s%g!=0) { cout<<"-1"<<endl; } else { k/=g; n/=g; s/=g; ll a=(-s+n)%n; ll kk=gcd(k,n,x,y); ll b=x; cout<<((a*(b%n))%n+n)%n<<endl; } } }
//#pragma GCC optimize("Ofast") //#pragma GCC target("avx,avx2,fma") //#pragma GCC optimization ("unroll-loops") #include <bits/stdc++.h> using namespace std; using namespace chrono; #define ll long long #define ld long double #define mod 1000000007 #define pb push_back #define inf 1000000000000000000 #define ff first #define ss second #define deb(x) cout<<#x<<" "<<x<<"\n" #define Clear(x) memset(x,0,sizeof(x)) #define all(x) (x).begin(),(x).end() void checkpoint1() { /******think more code less******/ ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); freopen("Error.txt", "w", stderr); #endif } bool comp(pair< ll,ll > &a,pair< ll,ll > &b) { if(a.ff!=b.ff) return a.ff<b.ff; else { if(a.ss>b.ss) return b.ss<a.ss; else if(a.ss<b.ss) return a.ss<b.ss; } return a.ff>b.ff; } ll powe(ll a,ll b) { ll res=1; while(b>0) { if(b&1) { res*=a; res%=mod; } a*=a; a%=mod; b>>=1; } return res; } void terminAtor() { ll n; cin>>n; ll a[n]; ll ans=0,idx=0; for(ll i=0;i<n;i++) cin>>a[i]; for(ll i=2;i<=1000;i++) { ll op=0; for(ll j=0;j<n;j++) { ll oo=a[j]%i; if(oo==0) op++; } if(op>ans) { ans=op; idx=i; } } cout<<idx; } int main() { checkpoint1(); /********************************************************/ auto startrrr = high_resolution_clock::now(); cout << setprecision(20); /*******************************************************/ terminAtor(); /*******************************************************/ auto stoprrr = high_resolution_clock::now(); auto duration = duration_cast<microseconds>(stoprrr - startrrr); #ifndef ONLINE_JUDGE cerr << "Time: " << duration.count()/1000.0<<"\n"; #endif /*******************************************************/ return 0; }
#include<bits/stdc++.h> #define ll long long #define f first #define s second #define pb push_back using namespace std; string s; ll ans,raod[200]; int main(){ ios::sync_with_stdio(false); cin >> s; for(int i=(int)s.size() - 1; i>=1; i--){ if(s[i] == s[i - 1]){ ans += (int)s.size() - i - 1 - raod[s[i] - 'a']; for(int j=0; j<26; j++) raod[j] = 0; raod[s[i] - 'a'] = (int)s.size() - i; } else { raod[s[i] - 'a']++; } } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; namespace Flandre_Scarlet { #define N 200005 #define int long long #define mod 1000000007 #define F(i,l,r) for(int i=l;i<=r;++i) #define D(i,r,l) for(int i=r;i>=l;--i) #define Fs(i,l,r,c) for(int i=l;i<=r;c) #define Ds(i,r,l,c) for(int i=r;i>=l;c) #define MEM(x,a) memset(x,a,sizeof(x)) #define FK(x) MEM(x,0) #define Tra(i,u) for(int i=G.st(u),v=G.to(i);~i;i=G.nx(i),v=G.to(i)) #define p_b push_back #define sz(a) ((int)a.size()) #define all(a) a.begin(),a.end() #define iter(a,p) (a.begin()+p) int I() {char c=getchar(); int x=0; int f=1; while(c<'0' or c>'9') f=(c=='-')?-1:1,c=getchar(); while(c>='0' and c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar(); return ((f==1)?x:-x);} template <typename T> void Rd(T& arg){arg=I();} template <typename T,typename...Types> void Rd(T& arg,Types&...args){arg=I(); Rd(args...);} void RA(int *p,int n) {F(i,1,n) *p=I(),++p;} class Graph { public: struct edge{int v,w,nx;} pe[N<<1]; edge*e; int ph[N]; int *head; int ecnt; void clear() { MEM(pe,-1); MEM(ph,-1); e=pe+2; head=ph+2; ecnt=-1; } void add(int u,int v,int w) { e[++ecnt]=(edge){v,w,head[u]}; head[u]=ecnt; } void ad2(int u,int v,int w) { add(u,v,w),add(v,u,w); } int&st(int u){return head[u];} int&to(int i){return e[i].v;} int&wei(int i){return e[i].w;} int&nx(int i){return e[i].nx;} }G; int n; void Input() { n=I(); G.clear(); F(i,1,n-1) { int u,v,w; Rd(u,v,w); G.ad2(u,v,w); } } int xor_s[N]; void DFS(int u,int f) { Tra(i,u) if (v!=f) { xor_s[v]=xor_s[u]^G.wei(i); DFS(v,u); } } int suf[N]; void Sakuya() { xor_s[1]=0; DFS(1,1); int ans=0; D(k,60,0) { int have=0; F(i,1,n) { if ((xor_s[i]>>k)&1) ++have; } int cur=(have*(n-have))%mod*((1ll<<k)%mod)%mod; // C(have,2)*(1<<k) ans=(ans+cur)%mod; } printf("%lld\n",ans); } void IsMyWife() { Input(); Sakuya(); } } #undef int //long long int main() { Flandre_Scarlet::IsMyWife(); getchar(); return 0; }
#pragma GCC optimize ("O2") #pragma GCC target ("avx") //#include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; #include<iostream> #include<cstring> #include<algorithm> using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please const int CM = 1 << 17, CL = 12; char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct; const ll ma0 = 1157442765409226768; const ll ma1 = 1085102592571150095; const ll ma2 = 71777214294589695; const ll ma3 = 281470681808895; const ll ma4 = 4294967295; inline int getint() { if (ci - owa > 0) { memcpy(cn, owa, CL); ci -= CM; fread(cn + CL, 1, CM, stdin); } int pn = 1; if (*ci == '-') { pn = -pn; ci++; } ll tmp = *(ll*)ci; if ((tmp & ma0) ^ ma0) { int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0); tmp = tmp << dig & ma1; tmp = tmp * 10 + (tmp >> 8) & ma2; tmp = tmp * 100 + (tmp >> 16) & ma3; tmp = tmp * 10000 + (tmp >> 32) & ma4; ci += (72 - dig >> 3); } else { tmp = tmp & ma1; tmp = tmp * 10 + (tmp >> 8) & ma2; tmp = tmp * 100 + (tmp >> 16) & ma3; tmp = tmp * 10000 + (tmp >> 32) & ma4; ci += 8; if ((ct = *ci++) >= '0') { tmp = tmp * 10 + ct - '0'; if (*ci++ == '0') { tmp = tmp * 10; ci++; } } } return pn * tmp; } int main() { cin.tie(0); ios::sync_with_stdio(false); int N = getint(); int k1, k2, x1 = -1e9, x2 = -1e9, y1, y2; int k3, k4, x3 = 1e9, x4 = 1e9, y3, y4; int k5, k6, x5, x6, y5 = -1e9, y6 = -1e9; int k7, k8, x7, x8, y7 = 1e9, y8 = 1e9; rep(i, N) { int x = getint(), y = getint(); if (x2 < x) { k2 = i; x2 = x; y2 = y; if (x1 < x2) { swap(k1, k2); swap(x1, x2); swap(y1, y2); } } if (x4 > x) { k4 = i; x4 = x; y4 = y; if (x3 > x4) { swap(k3, k4); swap(x3, x4); swap(y3, y4); } } if (y6 < y) { k6 = i; x6 = x; y6 = y; if (y5 < y6) { swap(k5, k6); swap(x5, x6); swap(y5, y6); } } if (y8 > y) { k8 = i; x8 = x; y8 = y; if (y7 > y8) { swap(k7, k8); swap(x7, x8); swap(y7, y8); } } } pair<int, ll> list[8]; list[0] = { -x3 + x1, ll(k3 | k1) << 32 | (k3 & k1) }; list[1] = { -x4 + x1, ll(k4 | k1) << 32 | (k4 & k1) }; list[2] = { -x3 + x2, ll(k3 | k2) << 32 | (k3 & k2) }; list[3] = { -x4 + x2, ll(k4 | k2) << 32 | (k4 & k2) }; list[4] = { -y7 + y5, ll(k7 | k5) << 32 | (k7 & k5) }; list[5] = { -y8 + y5, ll(k8 | k5) << 32 | (k8 & k5) }; list[6] = { -y7 + y6, ll(k7 | k6) << 32 | (k7 & k6) }; list[7] = { -y8 + y6, ll(k8 | k6) << 32 | (k8 & k6) }; sort(list, list + 8); if (list[7].second == list[6].second) co(list[5].first); else co(list[6].first); Would you please return 0; }
#include <bits/stdc++.h> #define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); typedef long long ll; typedef long double ld; #define pb push_back #define mp make_pair #define ff first #define ss second #define mod 1000000007 #define pii pair<ll,ll> #define inf 1000000000000000000 #define bpc(x) __builtin_popcountll(x) #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 repi(i,n) for(ll i = 0; i < n; i++) #define hmap gp_hash_table<ll, ll> #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> using namespace std; mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count()); int main() { FAST/**/ ll n; cin>>n; pii arr[n]; rep(n) cin>>arr[i].ff>>arr[i].ss; map<pii,ll> dis; vector<pii> x,y; rep(n) x.pb(mp(arr[i].ff,i)), y.pb(mp(arr[i].ss,i)); sort(x.begin(),x.end()); sort(y.begin(),y.end()); for(ll i=0;i<3;i++) { for(ll j=n-1;j>=n-3;j--) { if(j != i) { ll i1 = x[i].ss, i2 = x[j].ss; if(i1>i2) swap(i1,i2); dis[{i1,i2}] = max(dis[{i1,i2}], max(abs(arr[i1].ff - arr[i2].ff), abs(arr[i1].ss - arr[i2].ss))); } } for(ll j=0;j<3;j++) { if(j != i) { ll i1 = x[i].ss, i2 = x[j].ss; if(i1>i2) swap(i1,i2); //cout<<max(abs(arr[i1].ff - arr[i2].ff), abs(arr[i1].ss - arr[i2].ss))<<"\n"; dis[{i1,i2}] = max(dis[{i1,i2}], max(abs(arr[i1].ff - arr[i2].ff), abs(arr[i1].ss - arr[i2].ss))); } } } for(ll i=0;i<3;i++) { for(ll j=n-1;j>=n-3;j--) { if(j != i) { ll i1 = y[i].ss, i2 = y[j].ss; if(i1>i2) swap(i1,i2); dis[{i1,i2}] = max(dis[{i1,i2}], max(abs(arr[i1].ff - arr[i2].ff), abs(arr[i1].ss - arr[i2].ss))); } } for(ll j=0;j<3;j++) { if(j != i) { ll i1 = y[i].ss, i2 = y[j].ss; if(i1>i2) swap(i1,i2); dis[{i1,i2}] = max(dis[{i1,i2}], max(abs(arr[i1].ff - arr[i2].ff), abs(arr[i1].ss - arr[i2].ss))); } } } vector<ll> v; autoit(dis,it) v.pb(it->ss);// cout<<"for "<<it->ff.ff<<" , "<<it->ff.ss<<" = "<<it->ss<<'\n'; sort(v.begin(),v.end(),greater<ll>()); cout<<v[1]<<"\n"; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 2e3 + 5; const int modu = 1e9 + 7; const double inf = 0x3f3f3f3f; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; typedef long long LL; LL n, m; int main() { // freopen("my.txt", "w", stdout); cin >> n >> m; LL tmp = 1, a = 10; while (n) { if (n&1) tmp = tmp*a % (m*m); a = (a*a) % (m*m); n >>= 1; } cout << tmp / m << endl; return 0; }
#include <cassert> #include <cctype> #include <cmath> #include <cstdio> #include <cstring> #include <ctime> #include <algorithm> #include <bitset> #include <map> #include <set> #include <unordered_map> #include <unordered_set> #include <queue> #include <iostream> #include <string> #include <array> #include <random> #include <chrono> #include <vector> using namespace std; #ifndef ONLINE_JUDGE #define File(s) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout) #else #define File(s) #endif typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define mkp make_pair #define pb push_back #define SP putchar(' ') #define EL putchar('\n') mt19937 rnd(chrono :: steady_clock :: now().time_since_epoch().count()); mt19937_64 rnd64(chrono :: steady_clock :: now().time_since_epoch().count()) ; template<class T> inline void gi(T &x){ char ch; x = 0;int f = 1; while(isspace(ch = getchar())); if(ch == '-') ch = getchar(), f = -1; do x = x * 10 + ch - '0'; while(isdigit(ch = getchar())); x *= f; } template<class T> inline void wi(T x){ static char stk[128]; int top = 0; if(x == 0) putchar('0'); if(x < 0) putchar('-'), x = -x; while(x) stk[++top] = x % 10, x /= 10; while(top) putchar(stk[top--] + '0'); } template<class T, class ...Args> inline void gi(T &x, Args&... args) {gi(x); gi(args...);} template<class T, class ...Args> inline void wi(T x, Args... args) {wi(x); SP; wi(args...);} template<class T> void upmax(T &x, T y) {x = x > y ? x : y;} template<class T> void upmin(T &x, T y) {x = x < y ? x : y;} inline int power(ll x, ll y, ll m) { ll p = 1; for (; y; y >>= 1, x = x * x % m) if (y & 1) p = p * x % m; return p; } int main() { ll n, m; gi(n, m); printf("%lld\n", power(10, n, m * m) / m % m); return 0; }