code_file1
stringlengths
87
4k
code_file2
stringlengths
82
4k
#define _USE_MATH_DEFINES #include <algorithm> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <ctime> #include <complex> #include <deque> #include <functional> #include <iostream> #include <list> #include <map> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> #include <queue> #define INF 1010101010LL #define INFLL 1010101010101010101LL using namespace std; using Complex = complex<double>; const int mod = 1000000007; //const int mod = 998244353; int main() { int n; string s, t; cin >> n >> s >> t; long long ans = 0; queue<int> q; for (int i = 0; i < n; i++) { if (s[i] != t[i]) { q.push(i); i++; while (i < n) { if (s[i] == '1') { s[i] = '0'; ans += i - q.front(); q.pop(); } if (s[i] != t[i]) { q.push(i); } if (q.empty()) { break; } else { i++; } } if (!q.empty()) { cout << -1 << endl; return 0; } } } cout << ans << endl; return 0; }
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> #define pi 3.141592653589793238 #define int long long #define ll long long #define ld long double using namespace __gnu_pbds; using namespace std; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; mt19937 rnd(time(0)); long long powm(long long a, long long b,long long mod) { long long res = 1; while (b > 0) { if (b & 1) res = res * a %mod; a = a * a %mod; b >>= 1; } return res; } int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } const int mod=998244353; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); #ifndef ONLINE_JUDGE if(fopen("INPUT.txt","r")) { freopen("INPUT.txt","r",stdin); freopen("OUTPUT.txt","w",stdout); } #endif int n,m,k; cin>>n>>m>>k; int ans=0; if(n==1&&m==1) { cout<<k; return 0; } else if(n==1||m==1) { cout<<powm(k,n+m-1,mod); return 0; } for(int i=1;i<=k;i++) { int z=(powm(i,n,mod))-powm(i-1,n,mod)+mod; z%=mod; z*=(powm(k-i+1,m,mod)); z%=mod; ans+=z; ans%=mod; } cout<<ans; }
#include<bits/stdc++.h> #define For(i,a,b) for(register int i=(a);i<=(b);++i) #define Rep(i,a,b) for(register int i=(a);i>=(b);--i) //#define int long long using namespace std; inline int read() { char c=getchar();int x=0;bool f=0; for(;!isdigit(c);c=getchar())f^=!(c^45); for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48); if(f)x=-x;return x; } #define fi first #define se second #define pb push_back #define mkp make_pair typedef pair<int,int>pii; typedef vector<int>vi; #define mod 998244353 struct modint{ int x; modint(int o=0){x=o;} modint &operator = (int o){return x=o,*this;} modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;} modint &operator -=(modint o){return x=x-o.x<0?x-o.x+mod:x-o.x,*this;} modint &operator *=(modint o){return x=1ll*x*o.x%mod,*this;} modint &operator ^=(int b){ modint a=*this,c=1; for(;b;b>>=1,a*=a)if(b&1)c*=a; return x=c.x,*this; } modint &operator /=(modint o){return *this *=o^=mod-2;} modint &operator +=(int o){return x=x+o>=mod?x+o-mod:x+o,*this;} modint &operator -=(int o){return x=x-o<0?x-o+mod:x-o,*this;} modint &operator *=(int o){return x=1ll*x*o%mod,*this;} modint &operator /=(int o){return *this *= ((modint(o))^=mod-2);} template<class I>friend modint operator +(modint a,I b){return a+=b;} template<class I>friend modint operator -(modint a,I b){return a-=b;} template<class I>friend modint operator *(modint a,I b){return a*=b;} template<class I>friend modint operator /(modint a,I b){return a/=b;} friend modint operator ^(modint a,int b){return a^=b;} friend bool operator ==(modint a,int b){return a.x==b;} friend bool operator !=(modint a,int b){return a.x!=b;} bool operator ! () {return !x;} modint operator - () {return x?mod-x:0;} }; #define maxn 200005 int n,a[maxn],b[maxn],cnt; map<int,int>mp,mp2,id; inline int ID(int x){ if(!id.count(x))return id[x]=++cnt; return id[x]; } inline int ABS(int x){ return x<0?-x:x; } vector<int>va[maxn],vb[maxn]; int pa[maxn],pb[maxn],p[maxn],tmp[maxn]; long long tot; int t[maxn]; void msort(int l,int r) { if(l==r)return; int m=(l+r)/2; msort(l,m); msort(m+1,r); int p=l,i=l,j=m+1; while(i<=m&&j<=r) { if(a[i]>a[j]) { tot+=m-i+1; t[p++]=a[j++]; } else t[p++]=a[i++]; } while(i<=m)t[p++]=a[i++]; while(j<=r)t[p++]=a[j++]; for(i=l;i<=r;i++)a[i]=t[i]; } signed main() { n=read(); For(i,1,n)a[i]=read()+i,mp[a[i]]++,ID(a[i]); For(i,1,n)b[i]=read()+i,mp2[b[i]]++; for(auto it:mp) if(mp2[it.fi]!=it.se){ puts("-1"); return 0; } For(i,1,n)va[ID(a[i])].pb(i); For(i,1,n)vb[ID(b[i])].pb(i); long long res=0,now=0; For(i,1,cnt){ int sz=va[i].size(); For(j,0,sz-1){ int u=++now; pa[va[i][j]]=u; pb[vb[i][j]]=u; } } For(i,1,n)tmp[pb[i]]=i; For(i,1,n)pa[i]=tmp[pa[i]],a[i]=pa[i]; msort(1,n); cout<<tot; return 0; }
#include <bits/stdc++.h> using namespace std; // 0-indexed template <class T> struct BIT { int treesize; vector<T> lst; // constructor BIT(int newn = 0) : treesize(newn), lst(newn + 1, 0) {} // a_place += num void add(int place, T num) { ++place; while (place <= treesize) { lst[place] += num; place += place & -place; } } // sum between [0,place) T sum(int place) { T res = 0; while (place > 0) { res += lst[place]; place -= place & -place; } return res; } // sum [l,r) T sum(int left, int right) { return sum(right) - sum(left); } }; int n; vector<int> a, b; long long solve(); int main() { cin >> n; a.resize(n); for (int i = 0; i < n; ++i) { cin >> a[i]; a[i] += i; } b.resize(n); for (int i = 0; i < n; ++i) { cin >> b[i]; b[i] += i; } cout << solve() << endl; return 0; } long long solve() { { vector<int> va = a, vb = b; sort(va.begin(), va.end()); sort(vb.begin(), vb.end()); for (int i = 0; i < n; ++i) if (va[i] != vb[i]) return -1; map<int, vector<int>> mp; for (int i = 0; i < n; ++i) mp[b[i]].push_back(i); for (int i = n - 1; i >= 0; --i) { long long now = a[i]; a[i] = mp[now].back(); mp[now].pop_back(); } } long long res = 0; BIT<long long> bit(n); for (int i = 0; i < n; ++i) { res += bit.sum(a[i], n); bit.add(a[i], 1); } return res; }
#include<bits/stdc++.h> using namespace std; #define int long long #define REP(i,m,n) for(int i=(m);i<(n);i++) #define rep(i,n) REP(i,0,n) #define pb push_back #define all(a) a.begin(),a.end() #define rall(c) (c).rbegin(),(c).rend() #define mp make_pair #define endl '\n' #define vec vector<ll> #define mat vector<vector<ll> > #define fi first #define se second typedef long long ll; typedef unsigned long long ull; typedef pair<ll,ll> pll; typedef long double ld; typedef complex<double> Complex; const ll INF=1e9+7; const ll inf=INF*INF; const ll MAX=110; vector<ll>ans(MAX*MAX,-1); vector<vector<ll> >G(MAX); vector<vector<ll> >idx(MAX,vector<ll>(MAX)); vector<vector<ll> >re(MAX,vector<ll>(MAX,0)); vector<ll>used(MAX,0); void dfs(ll v,ll p){ if(p>=0&&ans[idx[p][v]]==-1){ ans[idx[p][v]]=re[p][v]; } if(used[v])return; used[v]=1; for(auto e:G[v]){ if(e==p)continue; dfs(e,v); } } signed main(){ ll n,m;cin>>n>>m; vector<ll>a(m),b(m),c(n); rep(i,m)cin>>a[i]>>b[i]; rep(i,n)cin>>c[i]; rep(i,m){ a[i]--;b[i]--; re[b[i]][a[i]]=1; idx[a[i]][b[i]]=i; idx[b[i]][a[i]]=i; if(c[a[i]]>c[b[i]])ans[i]=0; else if(c[a[i]]<c[b[i]])ans[i]=1; else{ G[a[i]].pb(b[i]); G[b[i]].pb(a[i]); } } rep(i,n){ if(G[i].size()==0)continue; if(used[i])continue; dfs(i,-1); } rep(i,m){ cout<<(ans[i]?"<-":"->")<<endl; } }
#line 2 "/home/defineprogram/Desktop/Library/template/template.cpp" #include<bits/stdc++.h> using namespace std; #define ll long long #define rep(i,n) for(ll i=0;i<n;i++) #define REP(i,n) for(ll i=1;i<n;i++) #define rev(i,n) for(ll i=n-1;i>=0;i--) #define all(v) v.begin(),v.end() #define P pair<ll,ll> #define len(s) (ll)s.size() 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; } constexpr ll inf = 3e18; #line 3 "/home/defineprogram/Desktop/Library/structure/UnionFind.cpp" class UnionFind{ using size_type=int32_t; size_type N; vector<size_type>par,siz; public: size_type find(size_type x){ assert(x<N); return (par[x]==x?x:par[x]=find(par[x])); } void merge(size_type x,size_type y){ assert(x<N&&y<N); x=find(x);y=find(y); if(x==y)return; if(siz[x]>siz[y])swap(x,y); par[x]=y;siz[y]+=siz[x]; } bool same(size_type x,size_type y){ return find(x)==find(y); } size_type size(size_type x){ return siz[find(x)]; } UnionFind(size_type N):N(N),siz(N,1),par(N){ iota(all(par),0); } }; /* @brief Union Find @docs docs/UnionFind.md */ #line 3 "main.cpp" int main(){ cin.tie(0);ios::sync_with_stdio(false); ll N,M;cin>>N>>M; if(N<=2){ if(M==0){ rep(i,N)cout<<i*2+1<<" "<<i*2+2<<endl; }else { cout<<"-1\n"; } }else { if(M<0||M>N-2)cout<<"-1\n"; else { cout<<1<<" "<<10000000<<endl; rep(i,M+1)cout<<2+i*2<<" "<<3+i*2<<endl; rep(i,N-M-2)cout<<100000000+i*2<<" "<<100000000+i*2+1<<endl; } } }
#pragma region templates //#pragma GCC optimize("Ofast") //#pragma GCC optimize("unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using db = double; using ld = long double; template<typename T> using V = vector<T>; template<typename T> using VV = vector<vector<T>>; template<typename T> using PQ = priority_queue<T>; template<typename T> using PQR = priority_queue<T,vector<T>,greater<T>>; #define fs first #define sc second #define pb push_back #define mp make_pair #define mt make_tuple #define eb emplace_back #define lb(c, x) distance((c).begin(), lower_bound(all(c), (x))) #define ub(c, x) distance((c).begin(), upper_bound(all(c), (x))) #define all(v) (v).begin(),(v).end() #define siz(v) (ll)(v).size() #define rep(i,a,n) for(ll i=a;i<(ll)(n);++i) #define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i) #define ENDL '\n' typedef pair<int,int> Pi; typedef pair<ll,ll> PL; constexpr ll mod = 998244353; constexpr ll INF = 1000000099; constexpr ll LINF = (ll)(1e18 +99); const ld PI = acos((ld)-1); constexpr ll dx[4]={-1,0,1,0},dy[4]={0,1,0,-1}; template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;} template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;} template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;} inline void Yes() { cout << "Yes" << ENDL; } inline void No() { cout << "No" << ENDL; } inline void YES() { cout << "YES" << ENDL; } inline void NO() { cout << "NO" << ENDL; } template<typename T,typename Y> inline T mpow(T a, Y n) { T res = 1; for(;n;n>>=1) { if (n & 1) res = res * a; a = a * a; } return res; } template <typename T> vector<T> finddivisor(T x) { //整数xの約数(xを含む) vector<T> divisor; for(T i = 1; (i * i) <= x; i++) { if(x % i == 0) { divisor.push_back(i); if(i * i != x) { divisor.push_back(x / i);} } } sort(divisor.begin(), divisor.end()); return divisor; } template <typename T> V<T> prefix_sum(const V<T>& v) { int n = v.size(); V<T> ret(n + 1); rep(i, 0, n) ret[i + 1] = ret[i] + v[i]; return ret; } template<typename T> T rand(T l,T r){ static random_device rd; static mt19937 g(rd()); return uniform_int_distribution<T>(l,r)(g); }//[] template<typename T> istream& operator >> (istream& is, vector<T>& vec){ for(auto&& x: vec) is >> x; return is; } template<typename T,typename Y> ostream& operator<<(ostream& os,const pair<T,Y>& p){ return os<<"{"<<p.fs<<","<<p.sc<<"}"; } template<typename T> ostream& operator<<(ostream& os,const V<T>& v){ os<<"{"; for(auto e:v)os<<e<<","; return os<<"}"; } template<typename ...Args> void debug(Args&... args){ for(auto const& x:{args...}){ cerr<<x<<' '; } cerr<<ENDL; } #pragma endregion templates signed main(){ cin.tie(0);cerr.tie(0);ios::sync_with_stdio(false); cout<<fixed<<setprecision(20); ll n;cin>>n; string s;cin>>s; V<ll> pac(26,0); rep(i,0,n)pac[s[i]-'a']++; sort(all(pac)); if(s[0]!=s[n-1])cout<<1<<ENDL; else if(pac.back()>n/2)cout<<-1<<ENDL; else cout<<2<<ENDL; } //(・_・)(・_・)(・_・)(・_・) //CHECK overflow,what to output? //any other simpler approach?
// Problem: C - Max GCD 2 // Contest: AtCoder - Japanese Student Championship 2021 // URL: https://atcoder.jp/contests/jsc2021/tasks/jsc2021_c // Memory Limit: 1024 MB // Time Limit: 2000 ms // Parsed on: 17-04-2021 12:52:09 IST (UTC+05:30) // Author: Kapil Choudhary // ******************************************************************** // कर्मण्येवाधिकारस्ते मा फलेषु कदाचन | // मा कर्मफलहेतुर्भूर्मा ते सङ्गोऽस्त्वकर्मणि || १.४७ || // ******************************************************************** #include<bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define pb push_back #define mp make_pair #define F first #define S second #define PI 3.1415926535897932384626 #define deb(x) cout << #x << "=" << x << endl #define deb2(x, y) cout << #x << "=" << x << ", " << #y << "=" << y << endl typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<ull> vull; typedef vector<pii> vpii; typedef vector<pll> vpll; typedef vector<vi> vvi; typedef vector<vll> vvll; typedef vector<vull> vvull; mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count()); int rng(int lim) { uniform_int_distribution<int> uid(0,lim-1); return uid(rang); } const int INF = 0x3f3f3f3f; const int mod = 1e9+7; int max_gcd(vi &v, int n) { int high = 0; for (int i = 0; i < n; i++) high = max(high, v[i]); int count[high + 1] = {0}; for (int i = 0; i < n; i++) count[v[i]]++; int counter = 0; for (int i = high; i >= 1; i--) { int j = i; counter = 0; while (j <= high) { if(count[j] >=2) return j; else if (count[j] == 1) counter++; j += i; if (counter == 2) return i; } } } void solve() { int a, b; cin >> a >> b; int n = b - a + 1; vi v(n); int x = a; for(int i = 0; i < n; i++) v[i] = x++; cout << max_gcd(v, n) << "\n"; } int main() { ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); srand(chrono::high_resolution_clock::now().time_since_epoch().count()); // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif int t = 1; // int test = 1; // cin >> t; while(t--) { // cout << "Case #" << test++ << ": "; solve(); } return 0; }
#pragma GCC optimize("-Ofast","-funroll-all-loops") #pragma GCC optimize(2) #pragma GCC optimize(3,"Ofast","inline") #include <bits/stdc++.h> using namespace std; //#define int long long //#define ULL unsigned long long #define fi first #define se second #define ls 2 * rt #define rs 2 * rt + 1 #define PII pair<int,int> #define PDD pair<double, double> #define gcd(a,b) __gcd(a,b) #define lowbit(x) (x & (-x)) typedef long long ll; const int N = 1e5 + 5; const int M = 2e5 + 5; const int mod = 1e9 + 7; const int inf = 0x3f3f3f3f; // const ll mod = 1e9 + 7; // const ll inf = 0x3f3f3f3f3f3f3f3f; int n, m; int k; int dist[20][100010]; int c[20]; int dp[18][1 << 18]; int vis[100010]; vector<int> path[100010]; void bfs(int u){ for(int i = 1; i <= n; i++){ dist[u][i] = inf; } memset(vis, 0, sizeof vis); dist[u][c[u]] = 0; queue<int> q; q.push(c[u]); vis[c[u]] = 1; while(!q.empty()){ int f = q.front(); q.pop(); for(auto v : path[f]){ if(!vis[v]){ vis[v] = 1; dist[u][v] = dist[u][f] + 1; q.push(v); } } } } int solve(int i, int zt){ if(zt == (1 << k) - 1){ return 0; } if(dp[i][zt] != -1){ return dp[i][zt]; } int res = inf; for(int j = 0; j < k; j++){ if(((1 << j)&zt)){ continue; } res = min(res, solve(j, zt | (1 << j)) + dist[j][c[i]] ); } return dp[i][zt] = res; } void solve(){ cin >> n >> m; for(int i = 1; i <= m; i++){ int a, b; cin >> a >> b; path[a].push_back(b); path[b].push_back(a); } cin >> k; for(int i = 0; i < k; i++){ cin >> c[i]; bfs(i); } int ok = 1; for(int i = 0; i < k; i++){ if(dist[i][c[0]] >= inf){ ok = 0; break; } } if(!ok){ cout << "-1" << "\n"; return ; } memset(dp, -1, sizeof dp); int ans = inf; for(int i = 0; i < k; i++){ ans = min(ans, 1 + solve(i, 1 << i)); } cout << ans << "\n"; return ; } int main(){ solve(); #ifndef ONLINE_JUDGE cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; #endif return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i,a,b) for(int i=a;i<=b;i++) using LL = long long; const int Nmax=1e5+9,INF=987'654'321; int N,M,a,b,dist[19][19],K,C[19],D[Nmax],Nt; int visited[Nmax],q,dp[19][(1<<19)],ans=INF; vector <int> adj[Nmax]; int F(int s, int e) { fill(D+1,D+N+1,INF); fill(visited+1,visited+N+1,0); queue <int> Q; D[s]=0; visited[s]=1; Q.push(s); while (!Q.empty()) { q=Q.front(); Q.pop(); for (auto u : adj[q]) { if (visited[u]) continue; D[u]=D[q]+1; visited[u]=1; Q.push(u); } } return D[e]; } int DFS(int place, int visited) { if (dp[place][visited]<INF) return dp[place][visited]; if (visited==(1<<K)-1) return 0; REP(k,1,K) { if (((visited>>(k-1))&1)==0) dp[place][visited]=min(dp[place][visited],dist[place][k]+DFS(k,visited|(1<<(k-1)))); } // cout<<place<<" "<<visited<<" "<<dp[place][visited]<<"\n"; return dp[place][visited]; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin>>N>>M; REP(j,1,M) { cin>>a>>b; adj[a].push_back(b); adj[b].push_back(a); } cin>>K; Nt=(1<<K)-1; REP(k,1,K) cin>>C[k]; REP(i,1,K-1) { REP(j,i+1,K) { dist[i][j]=dist[j][i]=F(C[i],C[j]); if (dist[i][j]==INF) ans=-1; // cout<<i<<" "<<j<<" "<<dist[i][j]<<endl; } } if (ans==-1) cout<<-1; else { REP(i,1,K) { REP(j,0,Nt) dp[i][j]=INF; } REP(i,1,K) { ans=min(ans,1+DFS(i,1<<(i-1))); } cout<<ans; } return 0; }
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { long long N, M; cin >> N >> M; vector<long long> H(N), W(M); for (long long i = 0; i < N; i++) cin >> H[i]; for (long long i = 0; i < M; i++) cin >> W[i]; sort(H.begin(), H.end()); vector<long long> sum1((N + 1) / 2), sum2((N + 1) / 2); for(long long i = 0; i + 1 < N; i += 2) sum1[i / 2 + 1] = sum1[i / 2] + H[i + 1] - H[i]; for(long long i = N - 2; i > 0; i -= 2) sum2[i / 2] = sum2[i / 2 + 1] + H[i + 1] - H[i]; long long result = 1e18; for (long long i = 0; i < M; i++) { long long ind = lower_bound(H.begin(), H.end(), W[i]) - H.begin(); if (ind % 2 == 1) ind--; long long tmp = sum1[ind/2]+sum2[ind/2]+abs(W[i]-H[ind]); result = result > tmp ? tmp : result; } cout << result << endl; 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 mod 1000000007 #define pb push_back #define ll long long int #define ull unsigned ll #define ld long double #define vi vector<int> #define vl vector<ll> #define v2i vector<vector<int>> #define v2l vector<vector<ll>> #define ppi pair<int,int> #define ppl pair<ll,ll> #define vpi vector<ppi> #define vpl vector<ppl> #define all(x) x.begin(),x.end() #define ff first #define ss second #define forn(i,a,b) for(int i=a;i<b;i++) #define forr(i,a,b) for(int i=a;i>=b;i--) #define forv(i,m) for(auto i : m) #define p2d(v) for(auto a:v){for(auto b:a)cout<<b<<" ";cout<<endl;} #define p1d(v) for(auto a:v)cout<<a<<" ";cout<<endl; #define ppd(v) for(auto a:v)cout<<a.ff<<" "<<a.ss<<endl; #define imx INT_MAX #define imn INT_MIN #define inf 9000000000000000000 #define minf -inf #define endl "\n" #define fast ios_base::sync_with_stdio(false);cin.tie(NULL); #define sze size() #define rvs reverse #define itr iterator #define pre cout<<fixed<<setprecision(10); #define umap unordered_map #define uset unordered_set #define pi 3.141592653589793 #define MAXN 100005 #define test1(x) cout << #x " = " << x << endl; #define test2(x,y) cout << #x " = " << x << " " << #y " = " << y << endl; #define test3(x,y,z) cout << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << endl; #define test4(w,x,y,z) cout << #w " = " << w << " " << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << endl; #define oset tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> /* const ll infinity = 9e18; bool compare(ll a,ll b) {return a > b;} bool compare1(ppl a,ppl b) {return a.ff > b.ff;} bool compare2(ppl a,ppl b) {return a.ss < b.ss;} bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;} ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;} ll power(ll a,ll b,ll md = mod) {ll product = 1; while(b){if(b&1){product = (product*a)%md;}a = (a*a)%md;b = b>>1;} return product%md;} ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);} ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; } */ int main() { fast /* #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif //*/ ll n,m; cin>>n>>m; vl a(n),b(m); forn(i,0,n) { cin>>a[i]; } forn(i,0,m) { cin>>b[i]; } sort(all(a)); sort(all(b)); ll mid = a[(n/2)]; ll total = 0; vl c(n,0),d(n,0); for(int i = 1; i < n; i += 2) { c[i] = total + (a[i]-a[i-1]); if(i+1 < n) c[i+1] = c[i]; total = c[i]; } total = 0; for(int i = n-2; i >= 0; i -= 2) { d[i] = total + (a[i+1]-a[i]); if(i-1 >= 0) d[i-1] = d[i]; total = d[i]; } // p1d(c) // p1d(d) ll mini = inf; forn(i,0,m) { ll idx = upper_bound(all(a),b[i]) - a.begin(); // test1(idx) ll x = idx-1 >= 0 ? c[idx-1] : 0; ll y = idx < n ? d[idx] : 0; if((idx&1)) { // x = idx-1 >= 0 ? c[idx-1] : 0; // y = idx < n ? d[idx] : 0; // test1(a[idx-1]) mini = min(mini,x + abs(b[i]-a[idx-1]) + y); } else { // test1(a[idx-1]) mini = min(mini,x + abs(a[idx]-b[i]) + y); } // test3(x,y,x + abs(a[idx]-b[i]) + y) } cout<<mini; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define MOD 1000000007 #define PI 3.1415926535897932384626433832795 #define ee cout << "\n" #define pb push_back #define mkp make_pair #define sall(v) sort(v.begin(), v.end()) #define fo(i, n) for (ll i = 0; i < n; i++) #define vl vector<ll> #define vll vector<pair<ll, ll>> #define mpl map<ll, ll> #define pr pair<ll, ll> //Fast input output void setIO(string s = "") { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin.exceptions(cin.failbit); if (s.size()) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } } void solve() { ll n; cin >> n; cout << (n + 99) / 100; ee; } int main() { setIO(); ll totalTestCase = 1; // cin>>totalTestCase; for (ll testCase = 1; testCase <= totalTestCase; testCase++) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ long long int n; cin>>n; long long int ans=n/100; if(n%100!=0) ans+=1; cout<<ans; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) int main() { long N; cin >> N; vector<long> A(N); rep(i, N) cin >> A[i]; long ans = 0; rep(i, N) { long C = 1000000; for(int j = i; j < N; j++) { C = min(C, A[j]); ans = max(ans, C*(j+1-i)); } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define endl "\n" #define pb push_back #define mp make_pair #define int long long #define ff first #define ss second #define double long double #define all(v) v.begin(), v.end() #define allr(v) v.rbegin(), v.rend() #define dbg(x) cout << "~~~~~" << #x << "--->" << x << endl; #define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++) #define present(container, element) (container.find(element) != container.end()) #define sz(a) ((int)(a).size()) #define setbit(n) (__builtin_popcount(n)) typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int,int> ii; const int inf = 1e10 + 7; const double eb=1e-9; const int mod = 1e9 + 7; template <class T> T add(T v1,T v2, int mo=mod) { return (v1%mo + v2%mo)%mo; } template<class T> T subtract(T v1,T v2,int mo=mod) { return (v1%mo - v2%mo)%mo; } template<class T> T mult(T v1, T v2,int mo=mod) { return (v1%mo * v2%mo )%mo; } template<class T,class P> void build_st(vector<T> &a,vector<P> &segT,int start,int end,int tidx) { if(start==end) { segT[tidx]=a[start]; return; } int mid=start+(end-start)/2; build_st(a,segT,start,mid,tidx*2); build_st(a,segT,mid+1,end,2*tidx+1); segT[tidx]=segT[tidx*2]+segT[tidx*2+1]; } template<class T,class P> void update_st(vector<T> &a,vector<T> &segT,int start,int end,int tidx,int idx,T val) { if(start==end) { segT[tidx]=a[idx]=val; return; } int mid=start+(end-start)/2; if(idx>mid) update_st(a,segT,mid+1,end,2*tidx+1,idx,val); else update_st(a,segT,start,mid,2*tidx,idx,val); segT[tidx]=segT[2*tidx]+segT[2*tidx+1]; } template<class T> T query_st(vector<T> &segT,int start,int end,int tidx,int left,int right) { if(start>right || end<left) return 0; if(start>=left && end<=right) return segT[tidx]; int mid=start+(end-start)/2; T val1=query_st(segT,start,mid,2*tidx,left,right); T val2=query_st(segT,mid+1,end,2*tidx+1,left,right); return val1+val2; } template <class T> void in(vector<T> &a, int n, int g = 0) { for (int i = g; i < n + g; i++) cin >> a[i]; } template <class T> void pv(vector<T> &a) { for (auto i : a) cout << i << " "; cout << endl; } template <class T> void pvv(vector<vector<T>>&a) { for(auto i:a) { for(auto j:i) cout<<j<<" "; cout<<endl; } } /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ void solver() { int n;cin>>n; vi a(n); in(a,n); int ans=0; for(int i=0;i<n;i++) { int mn=inf; for(int j=i;j<n;j++) { mn=min(mn,a[j]); ans=max(ans,(j-i+1)*mn); // dbg(mn); } } cout<<ans; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout<<fixed<<setprecision(15); int t = 1; // cin>>t; while (t--) { solver(); } }
#include <iostream> using namespace std; const int maxn=2e5; const int maxa=2e5+1; int N; int A[maxn]; int rt[maxa]; int fndrt(int a){ return rt[a]=(a==rt[a])?a:fndrt(rt[a]); } int main() { while(cin>>N){ //higha will minimize the amount of array being updated. int higha=1; for(int i=0;i<N;i++){ cin>>A[i]; higha=max(higha,A[i]); } //Set all numbers to represent themselves for(int i=0;i<higha;i++){ rt[i]=i; } //P and Q are theh numbers that A[i] or A[j] represents //basically we changed all A[i] or A[j] to P or Q int P,Q; int operations=0; for(int i=0,j=N-1;i<j;i++,j--){ P=fndrt(A[i]); Q=fndrt(A[j]); //If they are not the same number, //then change the first number to represent the second number if(P!=Q){ //Add one more operation operations++; //Change the representation of the first number to the second number rt[P]=Q; } } cout<<operations<<'\n'; } }
#include <bits/stdc++.h> using namespace std; #define int long long int #define yes cout<<"YES\n"; #define no cout<<"NO\n"; #define fl(n) for(int i=0;i<n;i++) #define flj(n) for(int j=0;j<n;j++) #define flo(n) for(int i=1;i<=n;i++) #define mii map<int,int> #define mci map<char,int> #define V vector<int> #define vp vector<pair<int,int>> #define pb push_back #define pp pair<int,int> #define ff first #define ss second #define S set<int> #define all(v) v.begin(),v.end() #define gr greater<int>() #define show2(a, b) cout<<a<<' '<<b<<endl; #define show3(a, b, c) cout<<a<<' '<<b<<' '<<c<<endl; const long long mod=1000000007; const int N=2e5+5; const long double PI=3.14159265358; vector<vector<int>> adj; bool vis[N]; // main code; int c; map<int,vector<int>> mp; map<int,bool> visited; void dfs(int j){ visited[j]=true; c++; for(auto u:mp[j]){ if(!visited[u]) dfs(u); } } int32_t main(){ int t=1; //cin>>t; while(t--){ int n; cin>>n; int a[n]; fl(n){ cin>>a[i]; visited[a[i]]=false; } for(int i=0;i<n/2;i++){ mp[a[i]].pb(a[n-i-1]); mp[a[n-i-1]].pb(a[i]); } int ans=0; for(auto it:mp){ if(!visited[it.ff]){ c=0; dfs(it.ff); ans+=max(0ll,c-1); } } cout<<ans; } return 0; }
#include <cstring> #include <cmath> #include <cstdio> #include <algorithm> #include <string> #include <map> #include <iostream> #include <vector> #include <queue> #include <unordered_map> #include <random> #include <stack> #include <set> #include <list> #include <unordered_set> //#include <atcoder/convolution> //#include <atcoder/modint> #define bug(x) cout<<"zdongdebug1: "<<x<<endl; #define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl; #define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl; #define bug4(x, y, z, w) cout<<"zdongdebug4: "<<x<<" "<<y<<" "<<z<<" "<<w<<endl; using namespace std; //using Modint = atcoder::modint998244353; typedef long long ll; void ex_gcd(ll a,ll b, ll& d,ll& x,ll& y){ if(!b) {d=a;x=1;y=0;} else { ex_gcd(b,a%b,d,y,x); y-=a/b*x;} } ll inv(ll a,ll n) { ll d,x,y; ex_gcd(a,n,d,x,y); return d==1?(x%n+n)%(n/d):-1; } ll gcd(ll x, ll y){ if(y==0)return x; return gcd(y, x%y); } const int maxn = 200005; const int mod = 1000000007; vector<int>e[maxn]; int d[maxn], pnt[maxn]; int ans[maxn]; bool onit[maxn]; void bfs(int x) { memset(d, -1, sizeof(d)); queue<int>q; d[x] = 0; pnt[x] = 0; q.push(x); while(!q.empty()){ int x = q.front(); q.pop(); for(int i=0;i<e[x].size();i++){ int y = e[x][i]; if(d[y]!=-1)continue; d[y] = d[x] + 1; pnt[y] = x; q.push(y); } } } int ret; void dfs(int x,int fa){ ret++; ans[x] = ret; int idx = -1; for(int i=0;i<e[x].size();i++){ int y = e[x][i]; if(y==fa)continue; if(onit[y]){ idx = y; continue; } dfs(y, x); ret++; } if(idx!=-1){ dfs(idx, x); ret++; } } int main() { #ifdef suiyuan2009 freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin); //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout); #endif int n; cin>>n; for(int i=1;i<n;i++){ int x,y; cin>>x>>y; e[x].push_back(y); e[y].push_back(x); } bfs(1); int mx=-1, idx; for(int i=1;i<=n;i++){ if(mx<d[i]){ mx = d[i]; idx = i; } } bfs(idx); mx = -1; for(int i=1;i<=n;i++){ if(mx<d[i]){ mx = d[i]; idx = i; } } int cur = idx; while(cur!=0){ onit[cur] = 1; cur = pnt[cur]; } ret = 0; dfs(idx, 0); for(int i=1;i<n;i++){ cout<<ans[i]<<" "; } cout<<ans[n]<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define fRead(x) freopen(x,"r",stdin) #define fWrite(x) freopen (x,"w",stdout) #define LL long long #define ULL unsigned long long #define ff first #define ss second #define pb push_back #define PI acos(-1.0) #define mk make_pair #define pii pair<int,int> #define pll pair<LL,LL> #define min3(a,b,c) min(a,min(b,c)) #define max3(a,b,c) max(a,max(b,c)) #define min4(a,b,c,d) min(a,min(b,min(c,d))) #define max4(a,b,c,d) max(a,max(b,max(c,d))) #define SQR(a) ((a)*(a)) #define FOR(i,a,b) for(int i=a;i<=b;i++) #define ROF(i,a,b) for(int i=a;i>=b;i--) #define REP(i,b) for(int i=0;i<b;i++) #define MEM(a,x) memset(a,x,sizeof(a)) #define ABS(x) ((x)<0?-(x):(x)) #define all(v) v.begin(),v.end() #define SORT(v) sort(v.begin(),v.end()) #define REV(v) reverse(v.begin(),v.end()) #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define FastRead ios_base::sync_with_stdio(0);cin.tie(nullptr); #ifdef VAMP #define debug(...) __f(#__VA_ARGS__, __VA_ARGS__) template < typename Arg1 > void __f(const char* name, Arg1&& arg1){ cout << name << " = " << arg1 << std::endl; } template < typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names+1, ','); cout.write(names, comma - names) << " = " << arg1 <<" | "; __f(comma+1, args...); } #else #define debug(...) #endif const int N = 200005; vector<LL>g[N]; LL n , U[N] , V[N] , q; LL par[N]; LL ara[N] , add[N]; void dfs(LL node,LL pre) { par[node] = pre; for(LL i : g[node]){ if(i == pre)continue; dfs(i,node); } } void dfs2(LL node,LL pre,LL has){ has = has + add[node]; ara[node] = has; for(LL i : g[node]){ if(i == pre)continue; dfs2(i,node,has); } } int main() { #ifdef VAMP clock_t tStart = clock(); freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif cin >> n; for(LL i = 1;i < n;i++){ LL u , v; cin >> U[i] >> V[i]; u = U[i]; v = V[i]; g[u].push_back(v); g[v].push_back(u); } dfs(1,0); LL total = 0; cin >> q; while(q--){ LL tp , e , x; cin >> tp >> e >> x; if(tp == 1){ LL a = U[e]; LL b = V[e]; if(par[a] == b){ add[a] += x; }else{ total += x; add[b] -= x; } }else{ LL a = V[e]; LL b = U[e]; if(par[a] == b){ add[a] += x; }else{ total += x; add[b] -= x; } } // FOR(i,1,n)cout << add[i] << "\n"; // cout << endl; } dfs2(1,0,total); FOR(i,1,n)cout << ara[i] << "\n"; #ifdef VAMP fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC); #endif }
#include<bits/stdc++.h> using namespace std; #define INF 0x3f3f3f3f #define swap(a,b) (a^=b^=a^=b) #define ll long long int #define ull unsigned long long int #define uint unsigned int #define format(a) memset(a,0,sizeof(a)) #define rep(x,y,z) for(int x=y;x<=z;x++) #define dec(x,y,z) for(int x=y;x>=z;x--) #define mst(x) memset(x,0,sizeof(x)) #define mid ((l+r)>>1) const int maxn=1e5+10; inline int read() { int ans=0; char last=' ',ch=getchar(); while(ch<'0'|ch>'9')last=ch,ch=getchar(); while(ch>='0' && ch<='9')ans=ans*10+ch-'0',ch=getchar(); if(last=='-')ans=-ans; return ans; } int n; string s; int a[105]; int b[maxn][105]; int sm[105],snum[105],bi[105],bnum[105]; bool check(int cur) { rep(i,1,n) { int val=a[i]/cur; int les=a[i]-a[i]/cur*cur; rep(j,1,cur) { b[j][i]=val; if(j<=les)b[j][i]++; } } rep(i,1,n-1) { bool ok; if(s[i-1]=='<')ok=0; else ok=1; rep(j,1,cur) { if(!ok&&b[j][i]>=b[j][i+1])return 0; if(ok&&b[j][i]<=b[j][i+1])return 0; } } return 1; } int main() { cin>>n>>s; n++; rep(i,1,n)cin>>a[i]; int l=1,r=10000; while(l+1<r) { if(check(mid))l=mid; else r=mid; //cout<<l<<" "<<r<<endl; } //cout<<check(2)<<endl; if(check(r))l=r; check(l); cout<<l<<"\n"; rep(i,1,l) { rep(j,1,n)cout<<b[i][j]<<" "; cout<<"\n"; } return 0; }
#include<iostream> #include<algorithm> #include<vector> #include<map> #include<set> #include<string> #include<cstring> #include<queue> #include<stack> #include<numeric> using namespace std; #define INF (1 << 30) - 1 #define LINF 1LL << 60 const int MOD = 1000000007; using ll = long long; using P = pair<int, int>; int main(){ int n; string s; cin >> n; cin >> s; vector<int> a(n + 1); for(int i = 0; i <= n; i++){ cin >> a[i]; } vector<int> d(n); int min_d = INF; for(int i = 0; i < n; i++){ d[i] = abs(a[i] - a[i + 1]); min_d = min(min_d, d[i]); } int k = min_d; vector<vector<int>> b(k, vector<int>(n + 1)); for(int i = 0; i <= n; i++){ for(int j = 0; j < k; j++)b[j][i] = a[i] / k; for(int j = 0; j < a[i] % k; j++)b[j][i] += 1; } cout << k << endl; for(int i = 0; i < k; i++){ for(int j = 0; j <= n; j++){ cout << b[i][j] << ' '; } cout << endl; } return 0; }
#pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target("avx,avx2,sse,sse2") #include <bits/stdc++.h> #define mem(a,x) memset(a,x,sizeof(a)) #define gi(x) scanf("%d",&x) #define gi2(x,y) scanf("%d%d",&x,&y) #define gll(x) scanf("%lld",&x) #define gll2(x,y) scanf("%lld%lld",&x,&y) using namespace std; const double eps=1e-8; typedef long long ll; const int MAXN=205; const ll mod=1e9+7; const int inf=0x3f3f3f3f; using namespace std; int a[MAXN]; int dp[MAXN][40005]; vector< pair<int,int> >b[MAXN][40005]; vector<int> last[MAXN][40005]; int main(){ int n; cin>>n; int sum=0; for(int i=1;i<=n;i++){ cin>>a[i]; a[i]%=200; sum+=a[i]; } dp[0][0]=1; last[0][0].push_back(-1); for(int i=1;i<=n;i++){ for(int j=0;j<200;j++){ dp[i][j]=dp[i-1][j]; if(dp[i-1][j]>=1&&last[i-1][j].size()){ last[i][j].push_back(last[i-1][j][0]); } if(dp[i-1][(j-a[i]+200)%200]>=1){ dp[i][j]=dp[i-1][(j-a[i]+200)%200]; last[i][j].push_back(i); } if(j!=0&&last[i][j].size()>=2){ stack<int>s[2]; for(int k=0;k<2;k++){ int t=last[i][j][k]; int m=j; while(1){ s[k].push(t); m-=a[t]; m+=200;m%=200; if(last[t-1][m][0]!=-1) t=last[t-1][m][0]; else{ break; } } } printf("Yes\n"); for(int k=0;k<2;k++){ cout<<s[k].size(); while(s[k].size()){ cout<<" "<<s[k].top(); s[k].pop(); } cout<<endl; } return 0; } } } printf("No\n"); // for(int i=1;i<=n;i++){ // for(int j=0;j<=sum;j++){ // if(dp[i][j]){ // cout<<i<<' '<<j<<' '<<dp[i][j]<<endl; // } // } // } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vector<int> A(N); for (auto &&e : A) { cin >> e; } vector<vector<int>> X(200); for (int i = 0; i < N; i++) { X[A[i] % 200].emplace_back(i); } for (int i = 0; i < 200; i++) { if ((int)X[i].size() >= 2) { cout << "Yes" << '\n'; cout << 1 << ' ' << X[i][0] + 1 << '\n'; cout << 1 << ' ' << X[i][1] + 1 << '\n'; return 0; } } vector<bitset<200>> Y(200); for (int i = 0; i < N; i++) { auto Z = Y; if (Y[A[i] % 200].any()) { cout << "Yes" << '\n'; cout << 1 << ' ' << i + 1 << '\n'; vector<int> c; for (int j = 0; j < N; j++) { if (Y[A[i] % 200][j]) c.emplace_back(j); } cout << c.size() << ' '; for (const auto &e : c) { cout << e + 1 << (&e == &c.back() ? '\n' : ' '); } return 0; } if (Y[0].any()) { cout << "Yes" << '\n'; cout << 1 << ' ' << i + 1 << '\n'; vector<int> c; for (int j = 0; j < N; j++) { if (Y[0][j] || i == j) c.emplace_back(j); } cout << c.size() << ' '; for (const auto &e : c) { cout << e + 1 << (&e == &c.back() ? '\n' : ' '); } return 0; } Z[A[i] % 200][i] = 1; for (int j = 0; j < 200; j++) { if (Y[j].none()) continue; if (Y[(j + A[i]) % 200].any()) { bitset<200> b = Y[(j + A[i]) % 200], c = Y[j]; c[i] = 1; for (int k = 0; k < N; k++) { if (b[k] && c[k]) { b[k] = 0; c[k] = 0; } } if (b.any() && c.any()) { cout << "Yes" << '\n'; vector<int> bb, cc; for (int k = 0; k < N; k++) { if (b[k]) bb.emplace_back(k); if (c[k]) cc.emplace_back(k); } cout << bb.size() << ' '; for (const auto &e : bb) { cout << e + 1 << (&e == &bb.back() ? '\n' : ' '); } cout << cc.size() << ' '; for (const auto &e : cc) { cout << e + 1 << (&e == &cc.back() ? '\n' : ' '); } return 0; } } Z[(j + A[i]) % 200] = Y[j]; Z[(j + A[i]) % 200][i] = 1; } Y = Z; } cout << "No" << '\n'; return 0; }
#include <bits/stdc++.h> #if __has_include(<atcoder/all>) #include <atcoder/all> using namespace atcoder; #endif #define repp(i, l, r) for (long long i = (l); i < (r); i++) #define rep(i, n) for (long long i = 0; i < (n); ++i) #define per(i, n) for (long long i = (n); i >= 0; --i) #define all(v) v.begin(), v.end() const int INF = 1 << 30; const long long LINF = 1LL << 60; const long long int MOD = 1000000007; using namespace std; using ll = long long; using P = pair<int, int>; using PLI = pair<long long, long long>; 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; } //ミョ(-ω- ?) int main() { cin.tie(nullptr); ios::sync_with_stdio(false); ll n, k; cin >> n >> k; map<ll, ll> mp; rep(i, n) { ll in; cin >> in; mp[in]++; } ll res = 0; ll recent = LONG_LONG_MAX; rep(i, n + 1) { // if (mp[i] >= k) continue; if (mp[i] == 0) break; chmin(recent, mp[i]); res += max(0ll, i + 1) * min(k, recent) - max(0ll, i) * min(k, recent); // recent =mp[i]; } cout << res << "\n"; return 0; }
#include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } #define rep(i,cc,n) for(int i=cc;i<n;++i) #define lrep(i,cc,n) for(long long i=cc;i<n;++i) #define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i) #define rrep(i,cc,n) for(int i=cc;i>=n;--i) #define pii pair<int, int> #define pll pair<long long, long long> using ll = long long; const vector<int> dx = {1, 0, -1, 0}; const vector<int> dy = {0, 1, 0, -1}; const vector<int> dx2 = {1, 1, 1, 0, 0, 0, -1, -1, -1}; const vector<int> dy2 = {1, 0, -1, 1, -1, 0, 1, 0, -1}; const double PI = 3.1415926535; const ll inf = 1001001001; const ll e9 = 1000000000; const ll mod = 1000000007; const ll mod2 = 998244353; const ll MAX = 1000000; const int MOD = 1000000007; const ll big = (1ll<<60); ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; } int main(){ int a, b; cin >> a >> b; vector<int>ans; if(a>=b){ int sum = 0; rep(i, 0, a){ ans.push_back(i+1); sum += (i+1); } rep(i, 0, b-1){ ans.push_back(-(i+1)); sum -= (i+1); } ans.push_back(-sum); }else{ int sum = 0; rep(i, 0, b){ ans.push_back(-(i+1)); sum += (i+1); } rep(i, 0, a-1){ ans.push_back(i+1); sum -= (i+1); } ans.push_back(sum); } for(auto i:ans)cout << i << " "; cout << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int a, b, w; cin >> a >> b >> w; w *= 1000; int min_orange = -1; int max_orange = -1; if (w % b == 0) min_orange = w / b; else if ((w / b + 1) * b - w <= (b - a) * (w / b + 1)) min_orange = w / b + 1; if (w % a == 0) max_orange = w / a; else if ((w / a) * a - w <= (b - a) * (w / a)) max_orange = w / a; //cout << min_orange << endl; if (min_orange == -1 || max_orange == -1) cout << "UNSATISFIABLE" << endl; else cout << min_orange << " " << max_orange << endl; return 0; }
#include <bits/stdc++.h> #define int long long using namespace std; int cx[1000005]; int ci[1000005]; signed main(){ int a,b,w; memset(ci,0X3f,sizeof(ci)); memset(cx,0,sizeof(cx)); ci[0] = 0; cin>>a>>b>>w; w = w*1000; int judge = 0; for(int i=a;i<=b;i++) for(int j=i;j<=w;j++){ cx[j] = max(cx[j],cx[j-i]+1); ci[j] = min(ci[j],ci[j-i]+1); } //4557430888798830399 if(ci[w]==4557430888798830399) cout<<"UNSATISFIABLE"; else cout<<ci[w]<<" "<<cx[w]; }
#include<bits/stdc++.h> using namespace std; /**templates**/ typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef vector<ll> vl; #define si(x) scanf("%d",&x) #define sl(x) scanf("%lld",&x) #define sull(x) scanf("%llu",&x) #define sf(x) scanf("%lf",&x) #define ss(x) scanf(" %s",x) #define sc(x) scanf(" %c",&x) #define pi acos(-1.0) #define pb push_back #define aa first #define bb second #define sz(x) (ll)(x).size() #define cas printf("Case %lld: ",++t) #define casline printf("Case %lld:\n",++t) //#define cas cout<<"Case "<<++t<<": " //#define casline cout<<"Case "<<++t<<":"<<endl; #define distance(x1,y1,x2,y2)((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)) #define endl "\n" #define bug cout<<"bugggggggggggg "<<endl; #define fast ios_base::sync_with_stdio(0);cin.tie(nullptr); ///no printf/scanf #define clean fflush(stdout) const ll mod = 1000000007; const ll inf = 1LL<<62; const ll mx = 100005; const double eps = 1e-10; ll dx[10]={1,0,-1,0}; ll dy[10]={0,-1,0,1}; ///ll dx[] = {1,-1,0,0,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1,1,-1}; /// 8 Direction ///ll dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1}; /// Knight Direction ll power(ll a,ll b) { if(b==0)return 1; ll x=power(a,b/2); x=x*x; if(b%2)x=x*a; return x; } ll bigmod(ll a,ll b) { if(b==0)return 1; ll x=bigmod(a,b/2)%mod; x=(x*x)%mod; if(b%2)x=(x*a)%mod; return x; } ll Set(ll N,ll pos){return N=N | (1LL<<pos);} ll reset(ll N,ll pos){return N= N & ~(1LL<<pos);} bool check(ll N,ll pos){return (bool)(N & (1LL<<pos));} /** ...ENDING OF TEMPLATE... */ ll arr[1005],brr[1005]; ll dp[1005][1005],n,m; ll solve(ll i,ll j) { // if(i>n and j>m) // return 0; if(i>n) return (m-j+1); if(j>m) return (n-i+1); ll &ret=dp[i][j]; if(ret!=-1) return ret; ret=(arr[i]!=brr[j])+solve(i+1,j+1); ret=min(ret,solve(i+1,j)+1); ret=min(ret,solve(i,j+1)+1); return ret; } int main() { // freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); // fast; ///no printf/scanf /** Use "long double"(%Lf) instead of double for precision safety*/ ll tst,a,b,c,k,res=0,ans=0,t=0; sl(n),sl(m); for(ll i=1;i<=n;i++) { sl(arr[i]); } for(ll i=1;i<=m;i++) { sl(brr[i]); } memset(dp,-1,sizeof(dp)); res=solve(1,1); cout<<res<<endl; return 0; }
// https://atcoder.jp/contests/abc185/tasks/abc185_e #include<bits/stdc++.h> using namespace std; int main() { int n,m; cin>>n>>m; int a[n+1],b[m+1]; for (int i=1;i<=n;++i) { cin>>a[i]; } for (int i=1;i<=m;++i) { cin>>b[i]; } int f[n+1][m+1]; memset(f,0x3f,sizeof f); f[0][0] = 0; for (int i=0;i<=n;++i) { for (int j=0;j<=m;++j) { if (i == 0 || j == 0) { // f[0][1] = 1, f[3][0] = 3 f[i][j] = max(i,j); continue; } // 删除 i f[i][j] = min(f[i][j], f[i-1][j]+1); // 删除 j f[i][j] = min(f[i][j], f[i][j-1]+1); // 保留 i 和 j f[i][j] = min(f[i][j], f[i-1][j-1] + ((a[i] != b[j]) ? 1 : 0)); } } cout<<f[n][m]<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int inf=0x3f3f3f3f; const ll INF=0x3f3f3f3f3f3f3f; const double pi=3.1415926535897932384626; inline ll read(){ ll x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9'){ if(ch=='-') f=-1; ch=getchar(); } while(ch>='0'&&ch<='9'){ x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); } return x*f; } ll b,c,ans; int main(){ b=read(),c=read(); if(b==0) ans=c; else if(c==1) ans=2; else if(2*abs(b)>=c) ans=2*c-1; else{ ans=c+2*abs(b); if(b>0) --ans; } printf("%lld\n",ans); return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #pragma GCC optimize("-Ofast") //#pragma GCC optimize("trapv") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native") #pragma GCC optimize("-ffast-math") #pragma GCC optimize("-funroll-loops") using namespace std; using namespace __gnu_pbds; #define vi vector<int> #define vll vector<ll> #define vii vector<pair<int, int>> #define vvi vector<vi> #define vvii vector<vii> #define pii pair<int, int> #define pll pair<ll, ll> #define loop(_) for (int __ = 0; __ < (_); ++__) #define forn(i, n) for (int i = 0; i < n; ++i) #define pb push_back #define f first #define s second #define sz(_) ((int)_.size()) #define all(_) _.begin(), _.end() #define uni(_) unique(_) #define lb lower_bound #define ub upper_bound #define si set<int> #define ms multiset<int> #define qi queue<int> #define pq prioriry_queue<int> #define mi map<int, int> #define inc(i, l, r) for (int i = l; i <= r; i++) #define dec(i, l, r) for (int i = l; i >= r; i--) using lll = __int128; using ll = long long; using ld = long double; const int N = 1e5 + 7; const ll mod = 1e9 + 7; const ll inf = 2e18; auto ra = [] {char *p = new char ; delete p ; return ll(p) ; }; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count() * (ra() | 1)); typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> os; int n; void nor(pll &pr) { if (pr.f > pr.s) swap(pr.f, pr.s); } ll sum(pll x) { return x.s - x.f + 1; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); #ifndef ONLINE_JUDGE freopen("in.in", "r", stdin); #endif ll b, c; cin >> b >> c; pair<ll, ll> in1, in2; in1 = {b - (c / 2), b + (c - 2) / 2}; in2 = {-b - (c - 1) / 2, -b + (c - 1) / 2}; nor(in1), nor(in2); ll ans = sum(in1) + sum(in2) - max(0ll, sum({max(in1.f, in2.f), min(in1.s, in2.s)})); cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define ll long long #define ld long double template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } using P=pair<long long,long long>; #define rep(i,n) for(long long i=0; i<(long long)n; i++) #define req(i,n) for(long long i=n-1; i>=0; i--) #define range(i,a,b) for(long long i=a; i<b; i++) #define all(x) (x).begin(), (x).end() #define sz(x) ((long long)(x).size()) #define COUT(x) cout << x << endl #define pb push_back #define mp make_pair #define F first #define S second #define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w) #define pri_que priority_queue #define vint vector<int> #define vvint vector<vector<int>> #define vi vector<int> #define vvi vector<vector<int>> #define vs vector<string> #define vvc vector<vector<char>> #define vc vector<char> #define vp vector<pair<int,int>> #define vb vector<bool> #define vvb vector<vector<bool>> #define show(x) cout<<#x<<"="<<x<<endl; #define SUM(x) accumulate(x.begin(),x.end(),0) #define MAX(x) *max_element(x.begin(),x.end()) #define MIN(x) *min_element(x.begin(),x.end()) #define couty cout<<"Yes"<<endl #define coutn cout<<"No"<<endl #define coutY cout<<"YES"<<endl #define coutN cout<<"NO"<<endl #define yn(x) cout<<(x?"Yes":"No")<<endl #define YN(x) cout<<(x?"YES":"NO")<<endl long long gcd(long long a,long long b){return b?gcd(b,a%b):a;} long long lcm(long long a, long long b){return a/gcd(a,b)*b;} const long long dx[8]={1,0,-1,0,1,-1,-1,1}; const long long dy[8]={0,1,0,-1,1,1,-1,-1}; const long long INF = 1e15; const long long MOD = 1e9+7; signed main(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(15); int n; cin >> n; vi a(n); rep(i,n)cin >> a[i]; int res1=0,res3=-1*INF; ld res2=0.0; rep(i,n) res1+=abs(a[i]); rep(i,n) res2+=a[i]*a[i]; res2=sqrt(res2); rep(i,n) res3=max(res3,abs(a[i])); cout<<res1<<endl<<res2<<endl<<res3<<endl; }
#include <bits/stdc++.h> using namespace std; using INT = long long int; using VINT = vector<INT>; using VVINT = vector<VINT>; using DBL = long double; const int BX = 1; INT N, M; map<INT, VINT> E; void init() { cin >> N >> M; for ( INT ix = 0 + BX; ix < M + BX; ix++ ) { INT a, b; cin >> a >> b; E[ a ].push_back( b ); } } void dfs( const INT id, set<INT>& visited ) { if ( visited.count( id ) > 0 ) { return; } visited.insert( id ); for ( auto it = E[ id ].cbegin(); it != E[ id ].cend(); it++ ) { dfs( *it, visited ); } } void kick() { init(); INT res = 0; for ( INT id = 0 + BX; id < N + BX; id++ ) { set<INT> visited; dfs( id, visited ); res += visited.size(); } cout << res << endl; } int main() { kick(); return 0; }
#include "bits/stdc++.h" using namespace std; #define endl "\n" #define endly " " #define int long long #define sz(x) ((int)x.size()) #define len(x) ((int)x.length()) #define ff first #define ss second #define all(x) begin(x), end(x) #define tc() int test; cin>>test; while(test--) #define pii pair<int,int> int32_t main() { ios::sync_with_stdio(false); cin.tie(0); 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; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define mod 1000000007 #define fast ios_base::sync_with_stdio(false);cin.tie(NULL); #define each(x,v) for(auto& (x) : (v)) #define f(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++) #define b(i,a,b) for(ll i=(ll)(a);i>=(ll)(b);i--) #define pb push_back #define eb emplace_back #define fi first #define se second #define mp make_pair #define mem(mat,f) memset(mat, f, sizeof(mat)) #define all(v) (v).begin(),(v).end() #define rall(v) (v).rbegin(),(v).rend() #define make(a,n) ll *a=new ll[n](); #define maxq(x) priority_queue<x> #define minq(x) priority_queue<x,vector<x>,greater<x>> #define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--)) const ll INF = 1LL << 60; bool isSquare(long double x){ if (x >= 0) { long long sr = sqrt(x); return (sr * sr == x); } return false; } int countDigit(long long n){ if (n == 0) return 0; return 1 + countDigit(n / 10); } int gcd(int a, int b){ if (b == 0) return a; return gcd(b, a % b); } inline ll max(ll a1,ll a2){ if(a1>a2){ return a1; }else{ return a2; } } inline ll min(ll a1,ll a2){ if(a1<a2){ return a1; }else{ return a2; } } /*int multiply(int x, int res[], int res_size) { int carry = 0; for (int i = 0; i < res_size; i++) { int prod = res[i] * x + carry; res[i] = prod % 10; carry = prod / 10; } while (carry) { res[res_size] = carry % 10; carry = carry / 10; res_size++; } return res_size; } ll power(int x, int n){ if(n == 0 ){ return 1; } int res[100000]; int res_size = 0; int temp = x; while (temp != 0) { res[res_size++] = temp % 10; temp = temp / 10; } for (int i = 2; i <= n; i++) res_size = multiply(x, res, res_size); ll ans=0; for (int i = res_size - 1; i >= 0; i--) ans=((ans*10)%mod+res[i]%mod)%mod; return ans%mod; }*/ ll multiply(ll x, ll res[], ll res_size) { ll carry = 0; for (ll i=0; i<res_size; i++) { ll prod = res[i] * x + carry; res[i] = prod % 10; carry = prod/10; } while (carry) { res[res_size] = carry%10; carry = carry/10; res_size++; } return res_size; } ll fact(ll n) { ll res[50005]; res[0] = 1; ll res_size = 1; for (ll x=2; x<=n; x++) { res_size = multiply(x, res, res_size); } ll a=0; for (ll i=res_size-1; i>=0; i--){ a=((a*10)%mod+res[i])%mod; } return a%mod; } ll pf[505]; void primeFactors(ll n){ while (n % 2 == 0) { pf[2]++; n = n/2; } for (ll i = 3; i <= sqrt(n); i = i + 2) { while (n % i == 0) { pf[i]++; n = n/i; } } if (n > 2) pf[n]++; } class node{ public: int s; int e; int p; }; bool compare(node a1,node a2){ return a1.e<a2.e; } ////////////////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////////////////// int main(){ fast; ll a,b,c; cin>>a>>b>>c; if(a==b){ cout<<c<<endl; } else if(b==c){ cout<<a<<endl; } else if(a==c){ cout<<b<<endl; }else{ cout<<"0"<<endl; } return 0; }
//#define _GLIBCXX_DEBUG #include <bits/stdc++.h> #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 namespace std; using ll = int64_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;} //head int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vi x(n), y(n), z(n); rep(i, n) cin >> x[i] >> y[i] >> z[i]; vvi dist(n, vi(n)); rep(i, n) { rep(j, n) { int u = abs(x[i]-x[j]) + abs(y[i]-y[j]) + max(0, z[j]-z[i]); dist[i][j] = u; } } vvi dp(1<<n, vi(n, INT_MAX)); dp[1][0] = 0; for(int i = 1; i < (1<<n)-1; i++) { rep(j, n) if((i>>j&1) and dp[i][j] != INT_MAX) { int now = dp[i][j]; rep(k, n) if(~i>>k&1) { chmin(dp[i|(1<<k)][k], now+dist[j][k]); } } } int ans = INT_MAX; for(int i = 1; i < n; i++) { chmin(ans, dp[(1<<n)-1][i]+dist[i][0]); } cout << ans << endl; }
#include <iostream> #include <algorithm> #include <vector> #include <string> #include <utility> #include <set> #include <map> #include <cmath> #include <queue> #include <cstdio> #include <limits> #define rep(i,n) for(int i = 0; i < n; ++i) #define rep1(i,n) for(int i = 1; i <= n; ++i) using namespace std; template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; } template<class T> inline int sz(T &a) { return a.size(); } using ll = long long; using ld = long double; using pi = pair<int,int>; using pl = pair<ll,ll>; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; const int inf = numeric_limits<int>::max(); const ll infll = numeric_limits<ll>::max(); //**************************************** // Graph template //**************************************** // status of edge template <typename X> struct Edge{ int from; int to; X cost; Edge() = default; Edge(int from, int to, X cost) : from(from), to(to), cost(cost) {} }; // status of node template <typename X> struct Node{ int idx; vector<Edge<X>> edge; Node() = default; explicit Node(int idx) : idx(idx) {} }; template <typename X> class Graph{ private: int n; // number of node int m; // number of edge vector<Node<X>> node; void Init_Node() { rep(i,n) node.emplace_back(i); } public: explicit Graph(int n) : n(n) { Init_Node(); } // edges have no-weight Graph(int n, int m, vector<int> from, vector<int> to) : n(n), m(m) { Init_Node(); rep(i,m) { add_edge(from[i], to[i]); add_edge(to[i], from[i]); } } // edges have weight Graph(int n, int m, vector<int> from, vector<int> to, vector<X> cost) : n(n), m(m) { Init_Node(); rep(i,m) { add_edge(from[i], to[i], cost[i]); add_edge(to[i], from[i], cost[i]); } } void add_edge(int from, int to, X cost = 1) { node[from].edge.emplace_back(from, to, cost); } void Solve() { vi d(n, -1); d[0] = 0; auto dfs = [&](auto self, int v)->void{ for(auto next: node[v].edge) { int w = next.to; if(d[w] != -1) continue; if(d[v] == next.cost) { d[w] = (d[v] + 1) % n; self(self, w); } else { d[w] = next.cost; self(self, w); } } }; dfs(dfs, 0); rep(i,n) cout << d[i]+1 << "\n"; } }; int main() { int n,m; cin >> n >> m; vi a(m),b(m),c(m); rep(i,m) { cin >> a[i] >> b[i] >> c[i]; a[i]--; b[i]--; c[i]--; } Graph<int> gp(n, m, a, b, c); gp.Solve(); return 0; }
#include<bits/stdc++.h> using namespace std; using ll = long long; using pint = pair<int,int>; int main() { int N;cin >> N; int m = N - 1; vector<int> A(N); for(auto &i: A) cin >> i; int ans = 1<<30; for(int bit = 0; bit < (1<<m); bit++) { vector<int> b = {A[0]}; for(int i = 0; i < N - 1; i++) { if((1 << i) & bit) { b.push_back(0); } b.back() |= A[i + 1]; } int sum = accumulate(b.begin(), b.end(), 0, [](int x, int y){return (x xor y);}); ans = min(ans, sum); } cout << ans << endl; }
#include<bits/stdc++.h> #define all(k) k.begin(),k.end() #define repk(i,a, n) for(int i=a;i<=n;i++) #define rep(i,a, n) for(int i=a;i<n;i++) #define per(i,a,n) for(int i=n-1;i>=a;i--) #define pb push_back #define ppb pop_back #define eb emplace_back #define ll long long #define ull unsigned long long #define pci pair<int,int> #define vc vector<char> #define vs vector<set<pi>> #define vi vector<int> #define vl vector<ll> #define vvi vector<vi> #define vb vector<bool> #define vpc vector<pci> #define vvc vector<vc> #define mi map<int,int> #define mset map<string,set<char>> #define umap unordered_map #define int int64_t using namespace std; #define fi first #define se second #define mod 1000000007 void sol() { int n; cin >> n; vi a(n); rep(i,0,n)cin>>a[i]; auto deep = [&](auto && deep, int i, int x, int o) -> int { if (i == n) return x ^ o; return min(deep(deep, i + 1, x, o | a[i]), deep(deep, i + 1, x ^ o, a[i])); }; cout << deep(deep, 0, 0, 0); } int32_t main() { int t=1; // for(cin>>t;t;t--) sol(); return 0; }
#include<bits/stdc++.h> using namespace std; using namespace std::chrono; //const int mod=1e9+7; 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 power(int a,int b,int mod) { int ans=1,f=a; while(b) { if(b&1ll) ans=ans*f%mod; f=f*f%mod; b=b>>1ll; } return ans; } signed main() { string s; cin>>s; int n=sz(s); int fr[26]={0},ans=0; rfo(i,sz(s)-1,1) { if(s[i]==s[i-1]) { ans=ans+(n-i-1-fr[s[i]-'a']); fo(i,0,26) fr[i]=0; fr[s[i]-'a']=n-i; } else fr[s[i]-'a']++; } cout<<ans<<endl; }
#include <bits/stdc++.h> #define fi first #define se second #define pb push_back #define mp make_pair #define all(x) begin(x),end(x) #define F(i,n) for (int i = 0; i < n; ++i) #define F1(i,n) for (int i = 1; i <= n; ++i) #define dbg(x) cerr << #x << " = " << x << endl #define dbgg(x) cerr << #x << " = " << x << ' ' #define T(x) x[pool] #define mineq(x,y) { if ((x) > (y)) (x) = (y); } #define maxeq(x,y) { if ((x) < (y)) (x) = (y); } #define MEOW cout << "meowwwww" << '\n'; system("pause"); #define int long long using namespace std; typedef vector<int> vi; typedef pair<int, int> pii; template<typename T> ostream& operator <<(ostream &s, const vector<T> &c) { s << "[ "; for (auto it : c) s << it << " "; s << "\b]\n"; return s; } template<typename T> ostream& operator <<(ostream &s, const pair<int, T> &c) { s << "[ "; cout << c.fi << " , " << c.se << " ] "; return s; } int n; string a; void input() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> a; } void solve() { int ok = 0; if (a[0] == a[n - 1]) { for (int i = 0; i < n - 1; ++i) if (a[i] != a[0] && a[i + 1] != a[0]) ok = 2; } else ok = 1; if (ok) cout << ok << '\n'; else cout << "-1\n"; } main() { input(); solve(); }
#include <bits/stdc++.h> typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; char win(char a,char b){ if (a == 'R' && b == 'P') return b; if (a == 'P' && b == 'S') return b; if (a == 'S' && b == 'R') return b; else return a; } int main(){ int n,k; cin >> n >> k; string s; cin >> s; while(k--){ s += s; string t; for(int i = 0;i<2*n;i+= 2){ t += win(s[i],s[i+1]); } s = t; } cout << s[0] << endl; }
#include <iostream> #include <vector> #include <string> #include <list> #include <queue> #include <algorithm> #define rep(i, n) for(i = 0; i < (n); i++) #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) #define MOD 1000000007 #define PI 3.14159265358979323846 #define INF 1 << 30 using namespace std; typedef long long ll; typedef pair<int, int> pp; int main(void) { int num, m, i; ll a = 0, b = 0; cin >> num >> m; string s; rep(i, num) { cin >> s; int x = 0; for (char c : s) { if (c == '1') x++; } if (x & 1) a++; else b++; } cout << a * b << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") using ll = long long; using ld = long double; #define mp make_pair const int p = 998244353; int mul(int a, int b) { return (1LL * a * b) % p; } int add(int a, int b) { int s = (a+b); if (s>=p) s-=p; return s; } int sub(int a, int b) { int s = (a+p-b); if (s>=p) s-=p; return s; } int po(int a, int deg) { if (deg==0) return 1; if (deg%2==1) return mul(a, po(a, deg-1)); int t = po(a, deg/2); return mul(t, t); } int inv(int n) { return po(n, p-2); } mt19937 rnd(time(0)); /* const int N = 1200000; vector<int> facs(N), invfacs(N); void init() { facs[0] = 1; for (int i = 1; i<N; i++) facs[i] = mul(facs[i-1], i); invfacs[N-1] = inv(facs[N-1]); for (int i = N-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1); } int C(int n, int k) { if (n<k) return 0; if (n<0 || k<0) return 0; return mul(facs[n], mul(invfacs[k], invfacs[n-k])); } */ /*struct DSU { vector<int> sz; vector<int> parent; void make_set(int v) { parent[v] = v; sz[v] = 1; } int find_set(int v) { if (v == parent[v]) return v; return parent[v] = find_set(parent[v]); } void union_sets(int a, int b) { a = find_set(a); b = find_set(b); if (a != b) { if (sz[a] < sz[b]) swap(a, b); parent[b] = a; sz[a] += sz[b]; } } DSU (int n) { parent.resize(n); sz.resize(n); for (int i = 0; i<n; i++) make_set(i); } };*/ int solve(int l, int r, int pos) { return max(r, pos) - min(l, pos); } int main() { ios_base::sync_with_stdio(0); cin.tie(nullptr); int n, l; cin>>n>>l; vector<int> a(n+2), b(n+2); for (int i = 1; i<=n; i++) cin>>a[i]; for (int i = 1; i<=n; i++) cin>>b[i]; a[0] = 0; b[0] = 0; a[n+1] = l+1; b[n+1] = l+1; vector<int> A; for (int i = 0; i<n+1; i++) A.push_back(a[i+1]-a[i]-1); vector<int> B; for (int i = 0; i<n+1; i++) B.push_back(b[i+1]-b[i]-1); a = A; b = B; ll ans = 0; n++; int cur = 0; for (int i = 0; i<n; i++) if (b[i]!=0) { while (cur<n && a[cur]==0) cur++; int l = cur; while (b[i]>0) { if (b[i]<a[cur]) {cout<<-1; return 0;} b[i]-=a[cur]; if (b[i]==0) { ans+=max(i, cur) - min(i, l); cur++; break; } cur++; } } cout<<ans; }
#include <bits/stdc++.h> using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353 #define int ll #define pii pll #define f first #define s second #define pb emplace_back #define forn(i,n) for(int i=0;i<(n);++i) #define sz(a)((int)(a).size()) #define sqr(x) ((x)*(x)) struct init{init(){cin.tie(0);iostream::sync_with_stdio(0);cout<<fixed<<setprecision(10);cerr<<fixed<<setprecision(5);}~init(){ #ifdef LOCAL #define dbg(...) _(#__VA_ARGS__,__VA_ARGS__) cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n"; #else #define dbg(...) #endif }}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());const int D=4,dx[]={+1,0,-1,0},dy[]={0,+1,0,-1}; const int N=1e5+5; int a[N],b[N],p[N]; void no(){ cout<<"-1\n"; exit(0); } int f[N]; int g(int l,int r){ if(l>r)return 0; return f[r]-(l==0?0:f[l-1]); } int32_t main(){ int n,l; cin>>n>>l; for(int i=1;i<=n;++i)cin>>a[i]; for(int i=1;i<=n;++i)cin>>b[i]; a[n+1]=b[n+1]=l+1; map<int,int> mp; mp[0]=0; for(int i=1;i<=n;++i){ p[i]=-1; mp[a[i]-i]=i; if(mp.find(b[i]-i)!=mp.end()){ p[i]=mp[b[i]-i]; } } mp.clear(); mp[a[n+1]-(n+1)]=n+1; for(int i=n;i>=1;--i){ mp[a[i]-i]=i; if(p[i]==-1&&mp.find(b[i]-i)!=mp.end()){ p[i]=mp[b[i]-i]; } if(p[i]==-1)no(); } p[0]=0; p[n+1]=n+1; for(int i=1;i<=n;++i){ if(p[i]>p[i+1])no(); f[p[i]]=1; } for(int i=1;i<=n+1;++i)f[i]+=f[i-1]; int ans=0; for(int i=1;i<=n;++i){ if(i==p[i])continue; if(i<p[i])ans+=g(i+1,p[i]); if(i>p[i])ans+=g(p[i],i-1); } cout<<ans<<'\n'; return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2") #define REP(i, N) for (int i = 0; i < (int)N; i++) using namespace std; constexpr long long llinf = 1LL << 62; using ll = long long; namespace FastIO { struct Strs { char strs[10000 * 4]; constexpr Strs() : strs() { for (int i = 0; i < 10000; ++i) { int j = i; for (int t = 3; t >= 0; --t) { strs[i * 4 + t] = j % 10 + '0'; j /= 10; } } } } constexpr strs; static constexpr size_t buf_size = 1 << 17; char buf_in[buf_size], buf_out[buf_size]; size_t pt_in = 0, pt_out = 0, tail_in = 0; inline size_t num_digits(long long x) { if (x >= (long long)1e9) { if (x >= (long long)1e18) return 19; if (x >= (long long)1e17) return 18; if (x >= (long long)1e16) return 17; if (x >= (long long)1e15) return 16; if (x >= (long long)1e14) return 15; if (x >= (long long)1e13) return 14; if (x >= (long long)1e12) return 13; if (x >= (long long)1e11) return 12; if (x >= (long long)1e10) return 11; return 10; } else { if (x >= (long long)1e8) return 9; if (x >= (long long)1e7) return 8; if (x >= (long long)1e6) return 7; if (x >= (long long)1e5) return 6; if (x >= (long long)1e4) return 5; if (x >= (long long)1e3) return 4; if (x >= (long long)1e2) return 3; if (x >= (long long)1e1) return 2; return 1; } } inline void load() { memcpy(buf_in, buf_in + pt_in, tail_in - pt_in); size_t width = tail_in - pt_in; tail_in = width + fread(buf_in + width, 1, buf_size - width, stdin); pt_in = 0; } inline void flush() { fwrite(buf_out, 1, pt_out, stdout); pt_out = 0; } inline void scan(char& c) { c = buf_in[pt_in++]; } template <class T> inline void scan(T& x) { if (pt_in + 32 > tail_in) load(); char c; bool minus = 0; x = 0; scan(c); while (c >= '0') { x = x * 10 + (c & 15); scan(c); } if (minus) x = -x; } inline void print(char c) { buf_out[pt_out++] = c; } template <class T> inline void print(T x) { if (pt_out > buf_size - 32) flush(); if (x < 0) { print('-'); x = -x; } size_t digits = num_digits(x); int i; for (i = pt_out + digits - 4; i > (int)pt_out; i -= 4) { memcpy(buf_out + i, strs.strs + (x % 10000) * 4, 4); x /= 10000; } memcpy(buf_out + pt_out, strs.strs + x * 4 + (pt_out - i), 4 + i - pt_out); pt_out += digits; } inline void print(const char* s) { if (pt_out > buf_size - 32) flush(); for (int i = 0; s[i] != 0; ++i) print(s[i]); } template <class T> inline void println(T x) { print(x); print('\n'); } struct SetUp { SetUp() { load(); } ~SetUp() { flush(); } } setup; } // namespace FastIO using FastIO::print; using FastIO::println; using FastIO::scan; constexpr int mx = 200001; int main() { int N, M; scan(N); scan(M); int H[mx], W[mx]; REP(i, N) scan(H[i]); REP(i, M) scan(W[i]); sort(H, H + N); sort(W, W + M); ll left[N + 1], right[N + 1]; left[0] = right[N] = 0; for (int i = 2; i <= N; i += 2) left[i] = left[i - 2] + H[i - 1] - H[i - 2]; for (int i = N - 2; i >= 0; i -= 2) right[i] = right[i + 2] + H[i + 1] - H[i]; int p = 0; ll ans = llinf; REP(i, M) { while (p < N && H[p] <= W[i]) p++; if (p % 2 == 0) { ans = min(ans, left[p] + right[p + 1] + H[p] - W[i]); } else { ans = min(ans, left[p - 1] + right[p] + W[i] - H[p - 1]); } } println(ans); return 0; }
#include <bits/stdc++.h> #include <vector> using namespace std; long long mypow(long a, long b) { long long powed = 1; if (b == 0) { return 1; } else { for (long i=0; i<b; i++) { powed = powed * a; } return powed; } } int main() { long long N; cin >> N; // bの最大値を求める long long bmax = 0; while (true) { if (mypow(2, bmax) <= N) { bmax = bmax; } else { break; } bmax += 1; } long long apbpc_min = 9223372036854775807; // bが大きい方から順番に最少となるa,b,cを試す for (long long b=bmax; b >= 0; b--) { // aの最大値を求める long long amax = floorl(N / mypow(2, b)); long long apbpc_before; long long c = N - amax * mypow(2, b); long long apbpc = amax + b + c; if (apbpc_min > apbpc) { apbpc_min = apbpc; } } cout << apbpc_min << endl; return 0; }
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") typedef long long int ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int,int> pt; typedef pair<ll,ll> pll; #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> //#define ordered_set tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> #define vint vector<int> #define vll vector<long long> #define endl '\n' #define fi first #define se second #define pb push_back #define F(i,n) for(int i = 0;i<n;i++) #define Fr(i,l,r) for(int i = l;i <= r;i++) #define rF(i,n) for(int i = n-1;i>=0;i--) #define Max 1000001 #define intinf 2147483647 #define longlonginf 9223372036854775807 #define MOD 998244353 #define MOD2 1000000007 #define fastio ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL) #define all(arr) arr.begin(),arr.end() //#define sort(vec) sort(vec.begin(),vec.end()) //#define reverse(vec) reverse(vec.begin(),vec.end()) ll Lpow(ll a,ll b) { ll ans = 1; while(b > 0) { if(b%2) ans = (ans*a); a = (a*a); b = b/2; } return ans; } ll Lpow(ll a,ll b,ll M) { ll ans = 1; while(b > 0) { if(b%2) ans = (ans*a)%M; a = (a*a)%M; b = b/2; } return ans; } ll x,y; ll ans; map<ll,ll> mape; void sch(ll y,ll turns) { ans = min(ans,abs(y - x) + turns); if(mape[y] <= turns && mape[y] != 0) return; else { mape[y] = turns; if(y%2) { sch(y + 1,turns + 1); sch(y - 1,turns + 1); } else sch(y/2,turns + 1); } } int main() { fastio; ans = longlonginf; cin >> x >> y; sch(y,0); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; #define int ll #define fast(); ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define tests() int t; cin>>t; while(t--) #define endl '\n' #define sz(x) ll((x).size()) #define F first #define S second #define mp make_pair #define vi vector <ll> #define pii pair<ll, ll> #define pdi pair<double, ll> #define pb(x) push_back(x) #define pf(x) push_front(x) #define all(x) x.begin(),x.end() #define f(i,n) for(ll i=0;i<n;i++) #define shout() {cout << "I'm Here...!!!" << endl;} #define dbg(x) { cout<< #x << ": " << (x) << endl; } #define dbg2(x,y) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; } #define dbgv(x) { cout<< #x << ": "; for(auto i : x) cout << i << ' '; cout << '\n'; } int inf = 1e18 + 100; int mod = 1e9 + 7; double pi = 3.1415926; int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } int fpow(int a, int b, int _mod = mod) { if (b == 0)return 1; int t = (fpow(a, b / 2, _mod)); if (b % 2 == 0)return (t * t) % _mod; else return ((a) * (t * t)) % _mod; } vi parent; void make_set(int n) { parent.resize(n); f(i, n) parent[i] = i; } int find_set(int v) { if (v == parent[v]) return v; return parent[v] = find_set(parent[v]); } bool union_sets(int a, int b) { a = find_set(a); b = find_set(b); parent[b] = a; return a != b; } signed main() { int x, y, res = 0; cin >> x >> y; if (x >= y) { cout << x - y << endl; return 0; } res = y - x; int t = 1, k = 0, s = 1; while (x*s < 2*y) { k++; s *= 2; t = (k+1)*s; int d = abs(y - x*s); if (d > x * s) continue;//res = min(res, k + (d - t) + k + 1); else { int q = 0; int ss = s/2; while (d > 0) { q += d / s, d %= s; if (d > ss) d = min(ss * 2 - d, d - ss), q++; ss /= 2; } res = min(res, q + k); } } cout << res << endl; }
#include<iostream> #include<string> #include<cstdio> #include<vector> #include<cmath> #include<algorithm> #include<functional> #include<iomanip> #include<queue> #include<ciso646> #include<random> #include<map> #include<set> #include<bitset> #include<stack> #include<unordered_map> #include<utility> #include<cassert> #include<complex> #include<numeric> #include<array> #define rep(i,n) for(int i=0;i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define Rep(i,sta,n) for(int i=sta;i<n;i++) #define rep1(i,n) for(int i=1;i<=n;i++) #define per1(i,n) for(int i=n;i>=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) #define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n"); #define all(v) (v).begin(),(v).end() #define all_rev(v) (v).rbegin(),(v).rend() #define debug(x) cout << #x << ": " << x << '\n'; #define degreeToRadian(deg) (((deg)/360)*2*M_PI) #define radianTodegree(rad) (((rad)/2/M_PI)*360) 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; } using namespace std; using ll = long long; using P = pair<int,int>; using PL = pair<ll, ll>; const ll INF = 1LL<<60; const int MOD = 1e9 + 7; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; int main() { //cin.tie(0);ios::sync_with_stdio(false); //cout << fixed << setprecision(15); ll x = 10000000000; int n; string t; cin >> n >> t; for (int i = 2; i < t.size(); i++) { if (t[i - 2] == '1') { if (t[i - 1] == '1') { if (t[i] != '0') { cout << 0 << endl; exit(0); } } else if (t[i - 1] == '0') { if (t[i] != '1') { cout << 0 << endl; exit(0); } } } else if (t[i - 2] == '0') { if (t[i - 1] == '1' && t[i] == '1') { continue; } else { cout << 0 << endl; exit(0); } } } if (t == "1") { cout << 2 * x << endl; }else if (t == "00") { cout << 0 << endl; } else if (t == "11" || t == "0" || t == "10") { cout << x << endl; } else { if (t[0] == '0') { // 0110110 -> 110110 t = t.substr(1); x--; } else if (t[0] == '1' && t[1] == '0') { // 10110110 -> 110110 t = t.substr(2); x--; } if (t.size() > 2) { x = (x - (t.size() / 3)) + 1; if (t.size() % 3) x--; } cout << x << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long int li; typedef long double ld; typedef vector<li> vi; typedef pair<li,li> pi; #define PB push_back #define MP make_pair #define F first #define S second #define B begin() #define E end() #define f(i,l,r) for(li i=l;i<=r;++i) #define fr(i,l,r) for(li i=l;i>=r;--i) #define u_map unordered_map #define endl "\n" #define debug(x) cerr<<#x<<" = "<<x<<endl li fastpow(li base,li exp,li M) { li res=1; while(exp>0) { if(exp&1) res=(res*base)%M; base=(base*base)%M; exp>>=1; } return res; } void solve() { li n; cin>>n; li a[n]; map<li,li> cnt; f(i,0,n-1) { cin>>a[i]; cnt[a[i]]++; } map<li,li> cnt2; li ans=0; f(i,0,n-1) { cnt2[a[i]]++; ans+= n-i-1-(cnt[a[i]]-cnt2[a[i]]); } cout<<ans; } int main() { //remove this in kickstart #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("error.txt", "w", stderr); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); li t=1; // cin>>t; f(i,1,t) { // cout<<"Case #"<<i<<": "; solve(); } return 0; }
#include<bits/stdc++.h> #define N 200006 #define LL __int128 #define int long long using namespace std; int T,t; int X,Y,p,q; int mod1,mod2; int ai[12],bi[12]; inline int qr() { char a=0;int w=1,x=0; while(a<'0'||a>'9'){if(a=='-')w=-1;a=getchar();} while(a<='9'&&a>='0'){x=(x<<3)+(x<<1)+(a^48);a=getchar();} return w*x; } LL exgcd(LL a,LL b,LL &x,LL &y) { if(!b) { x=1,y=0; return a; } LL d=exgcd(b,a%b,y,x); y-=a/b*x; return d; } LL mul(LL a,LL b,LL mod) { LL ans=0; while(b) { if(b&1) ans=(ans+a)%mod; a=(a+a)%mod; b>>=1; } return ans; } LL excrt() { LL x,y; LL M=bi[1],ans=ai[1]; for(int i=2;i<=2;i++) { LL a=M,b=bi[i],c=(ai[i]-ans%b+b)%b; LL gcd=exgcd(a,b,x,y),bg=b/gcd; if(c%gcd!=0) return -1; x=mul(x,c/gcd,bg); ans+=x*M; M*=bg; ans=(ans%M+M)%M; } return (ans%M+M)%M; } signed main() { T=qr(); while(T--) { X=qr(); Y=qr(); p=qr(); q=qr(); mod1=(X+Y)<<1; mod2=(p+q); LL ans=2e18; int opl=0; for(register int i=0;i<Y;i++) { for(register int j=p;j<p+q;j++) { bi[1]=mod1; bi[2]=mod2; ai[1]=i+X; ai[2]=j; LL ans1=excrt(); if(ans1==-1) continue; opl=1; ans=min(ans1,ans); } } if(opl) cout<<(long long)ans<<endl; else cout<<"infinity"<<endl; } return 0; }
#include<bits/stdc++.h> #define rep(i, n) for (Int i = 0; i < (int)(n); i++) #define rrep(i,n) for(Int i=(n)-1;i>=0;i--) #define FOR(i,a,b) for(Int i=a;i<=Int(b);i++) #define __MAGIC__ ios::sync_with_stdio(false);cin.tie(nullptr); //#include <atcoder/all> //using namespace atcoder; typedef long long Int; const long long INF = 1ll << 60; using namespace std; using p = pair<int,int>; using Graph = vector<vector<int>>; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; int main(){ __MAGIC__ int a, b, c, d; cin >> a >> b >> c >> d; int ans = -1000000; ans = max(ans,a-c); ans = max(ans,a-d); ans = max(ans,b-c); ans = max(ans,b-d); cout << ans << endl; // cout << (ans ? "Yes" : "No") << endl; return 0; }
#include<iostream> #include<bits/stdc++.h> using namespace std; #define X first #define Y second #define endl "\n" #define int long long int #define FASTIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define rep(i, a, b) for(int i = a; i < (b); ++i) typedef pair<int, int> pii; typedef vector<int> vi; 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 int n,m,k,i,j,mod; vector<int> a,b,p; void solvetestcase(){ cin>>n; a.resize(n); b.resize(n); p.resize(n); for(auto &x:a) cin>>x; for(auto &x:b) cin>>x; for(auto &x:p) { cin>>x; x--; } for(int i=0;i<n;++i) { if(a[i]>b[p[i]]||i==p[i]) continue; cout<<-1<<endl; return; } vi itr(n); iota(itr.begin(),itr.end(),0); sort(itr.begin(),itr.end(),[&](const int &x,const int &y){ return a[x]>a[y]; }); debug(itr); vector<pii> ans; for(auto u:itr) { while(p[u]!=u) { const int v=p[u]; assert(a[u]>b[p[u]]); assert(a[v]>b[p[v]]); ans.push_back({u,v}); swap(p[u],p[v]); } } cout<<ans.size()<<endl; for(auto x:ans) cout<<x.X+1<<" "<<x.Y+1<<endl; } int32_t main(void) { FASTIO; int testcases=1; // cin>>testcases; for(int tc=1;tc<=testcases;++tc){ solvetestcase(); } return 0; }
#include <cstring> #include <iostream> using namespace std; typedef long long ll; int net[1000001]; //指向下一结点的指针 int vis[1000001]; //对每个结点进行不同的标记 int ans, n, ringID, p; void search() { for (int i = 1; i <= n; ++i) { if (vis[i]) continue; p = i; ++ringID; //对每一种环进行一种不同的标记,新的起点必须更换新的染色 while (vis[p] == 0) //当前结点未被染色 { vis[p] = ringID; //染色 p = net[p]; //指向下一个点 if (vis[p] == ringID) //下一个点的颜色和当前染色相同,则说明存在一个环 ++ans; } } } int qmi(int a, int k, int p) { int res = 1; while (k) { if (k & 1) res = (ll)res * a % p; k >>= 1; a = (ll)a * a % p; } return res; } int main() { cin >> n; ans = 0; ringID = 1; memset(vis, 0, sizeof(vis)); for (int i = 1; i <= n; ++i) { scanf("%d", &net[i]); if (net[i] == i) { vis[i] = ringID++; //先对自环进行预处理 ans++; } } search(); cout << qmi(2, ans, 998244353) - 1 << endl; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define PI 3.14159265 template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } int main() { ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); ll l, ans =0; cin >> l; ll last = 1; for(int i = 11; i > 0; i--) { ans = (last*(l - i))/(12-i); last = ans; } cout << ans; }
#include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(v) v.begin(), v.end() using vi = vector<int64_t>; using vvi = vector<vi>; using vc = vector<char>; using vvc = vector<vc>; using vd = vector<long double>; using vvd = vector<vd>; using pii = pair<int64_t, int64_t>; using vp = vector<pii>; using vvp = vector<vp>; int64_t INF = 1e18; int64_t mod = 1e9 + 7; int main() { int64_t l; cin >> l; int64_t half; vi pre_ans(210, 0); for (int i = 2; i <= 190; i++) { for (int j = 2; j <= 190; j++) { for (int k = 2; k <= 190; k++) { half = i + j + k; if (half > l - 6) continue; pre_ans[half] += (i-1) * (j-1) * (k-1); } } } int64_t ans = 0; for (int i=6; i <= l-6;i++) { ans += pre_ans[i] * pre_ans[l-i]; } cout << ans << endl; }
#include<bits/stdc++.h> //#include<atcoder/all> using namespace std; //using namespace atcoder; using ll = long long; using Graph = vector<vector<int>>; using P = pair<int, int>; #define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i)) #define rrep(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i)) #define all(x) (x).begin(),(x).end() #define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w) constexpr ll INF = 1LL << 30; constexpr ll mod = 100000; //(ll)1e9 + 7; constexpr double PI = 3.1415926535897932; 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; } inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } int dx[] = { 0,1,1 ,0 }; int dy[] = { 0,0, 1,1 }; int main() { init(); int H, W; cin >> H >> W; vector<string>vec(H); vector<vector<int>>cnt(H + 1, vector<int>(W + 1, 0)); rep(i, 0, H)cin >> vec[i]; int ans = 0; rep(i, 0, H) { rep(j, 0, W) { if (vec[i][j] == '#') { rep(k, 0, 4)cnt[i + dy[k]][j + dx[k]]++; } } } rep(i, 0, H + 1)rep(j, 0, W + 1)if (cnt[i][j] % 2 == 1)ans++; cout << ans << "\n"; return 0; }
#include<bits/stdc++.h> using namespace std; int main() { long long int h,w,i,j,black,white,sum; cin>>h>>w; char ar[h][w]; string str; for (i=0;i<h;i++) { cin>>str; for(j=0;j<w;j++) ar[i][j]=str[j]; } sum=0; for (i=0;i<h-1;i++) { for (j=0;j<w-1;j++) { white=black=0; if (ar[i][j]=='#') black++; else white++; if (ar[i][j+1]=='#') black++; else white++; if (ar[i+1][j]=='#') black++; else white++; if (ar[i+1][j+1]=='#') black++; else white++; if ((black==3 && white==1) || (white==3 && black==1)) sum++; } } cout<<sum; return 0; }
#include<bits/stdc++.h> using namespace std; #define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define scn(n) scanf("%d",&n) #define lscn(n) scanf("%lld",&n) #define rep(i,st,n) for(int i=st;i<n;i++) typedef long long ll; #define pri(n) printf("%d\n",n) #define lpri(n) printf("%lld\n",n) #define var(n) int n; scn(n) #define F first #define S second #define all(x) (x).begin(),(x).end() #define pb(n) push_back(n) #define pii pair<int,int> const int N=3e3+6; const ll M = 998244353; ll dp[N][N]; // dp[i][j] is the number of ways with i // elements and j sum. int main() { int n,k; cin>>n>>k; dp[0][0] = 1; for(int i = 1;i<=n;i++) { for(int sum = 1;sum<=i;sum++) { ll req = sum; while(req<=i) { dp[i][sum] += dp[i-1][req-1]; if(dp[i][sum]>=M) dp[i][sum]-=M; req*=2; } } } lpri(dp[n][k]); }
#include<bits/stdc++.h> #define PI 3.141592653589793238462 #define eps 1e-10 using namespace std; typedef long long ll; typedef long double db; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef pair<db,db> pdd; ll d[3005][3005],mod=998244353; ll dfs(ll n,ll k){ if(n<k) return 0; if(k==0) return !n; if(d[n][k]!=-1) return d[n][k]; d[n][k]=(dfs(n-1,k-1)+dfs(n,k<<1))%mod; return d[n][k]%mod; } int main(){ memset(d,-1,sizeof(d)); ll n,k;cin>>n>>k;dfs(n,k); cout<<dfs(n,k)%mod<<endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long N; cin >> N; int S = 0, one = 0, two = 0, len = 0; while(N>0){ if((N%10)%3 == 1){ one++; }else if((N%10)%3 == 2){ two++; } S += N%10; N = N/10; len++; } if(len == 1){ if(S%3 == 0){ cout << "0" << endl; }else{ cout << "-1" << endl; } }else if(len == 2){ if(S%3 == 0){ cout << "0" << endl; }else if(S%3 == 1){ if(one >= 1){ cout << "1" << endl; }else{ cout << "-1" << endl; } }else{ if(two >= 1){ cout << "1" << endl; }else{ cout << "-1" << endl; } } }else{ if(S%3 == 0){ cout << "0" << endl; }else if(S%3 == 1){ if(one >= 1){ cout << "1" << endl; }else if(two >= 2){ cout << "2" << endl; }else{ cout << "-1" << endl; } }else{ if(two >= 1){ cout << "1" << endl; }else if(one >= 2){ cout << "2" << endl; }else{ cout << "-1" << endl; } } } }
#include <iostream> #include <vector> #include <algorithm> using namespace std; using ll = long long; int main() { ll n; cin >> n; vector<int> b; int k = 1; ll m = n; while(m > 0){ if(m/10 != 0){ k++; } b.emplace_back(m%10); m/=10; } if(n%3==0){ cout << 0 << endl; return 0; } int ans = k+1; for(int i=1;i<(1<<k)-1;i++){ ll sum = 0; int cnt = 0; for(int bit=0;bit<k;bit++){ ll div = 1; if((i>>bit) & 1){ // 削除する桁数を更新 cnt++; }else{ // sumに加算 sum = sum*10 + b[bit]; } div *= 10; } if(sum%3 == 0){ ans = min(ans,cnt); } } if(ans == k+1) ans = -1; cout << ans << endl; }
//tejustiwari #include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define pb push_back #define mp make_pair #define all(v) v.begin(),v.end() #define f(i,a,b,c) for( i=a; i<b;i+=c) #define rf(i,a,b,c) for( i=b-1;i>=a;i-=c) #define fo(i,n) for( i=0; i < n ; i++) #define rfo(i,n) for( i=n-1; i >=0 ; i--) #define mem(a,b) memset(a, (b), sizeof(a)) #define alldec(v) v.begin(),v.end(),greater<int>() #define fio ios_base::sync_with_stdio(0); cin.tie(0); #define debug1(x) cout<<#x<<"="<<x<<endl; #define debug2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl; #define debug3(x,y,z) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl; #define debug4(x,y,z,w) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<" "<<#w <<"="<<w<<endl; #define debugarray(arr,n) for(int i=0;i<n;i++) {cout<<"i="<<i<<" arr[i]="<<arr[i]<<"\n";} #define debugmatrix(a,n,m) cout<<setw(5*m+8)<<"MATRIX\n\n";for(int i=0;i<n;i++){for(int j=0;j<m;j++){cout<<setw(10)<<a[i][j];}cout<<"\n";} #define file_io freopen("Input_file_name.txt","r",stdin);freopen("Output_file_name.txt","w",stdout) typedef long long int ll; typedef vector<int> vi; typedef vector<ll> vll; typedef pair<int,int> pi; typedef pair<ll,ll> pll; const ll M =1000000007; const ll M1 = 998244353; const double PI = 3.141592653589793; vll primefactors, factors, fact; bool isPowerTwo(ll x) {return(x && !(x&(x-1)));} ll power(ll a, ll b) {ll r=1;while(b){if(b&1)r=(r*a);a=(a*a);b>>=1;}return r;} ll powerM(ll a,ll b) {ll r=1;while(b){if(b&1)r=(r*a)%M;a=(a*a)%M;b>>=1;}return r;} void getFactorial(ll n) {fact.pb(1);for(ll i=1;i<=n;i++)fact.pb((i*1ll*fact[i-1])%M);} bool isPrime(ll n) {if(n<2)return false;for(ll i=2;i*i<=n;i++)if(n%i==0)return false;return true;} ll modi(ll a) {ll m=M,s=1,p=0; while(a>1){ll q=a/m,t=m;m=a%m;a=t;t=p;p=s-q*p;s=t;}return s>=0?s:s+M;} void getFactors(ll n) {factors.clear();for(ll i=1;i*i<=n;i++){if(n%i==0){factors.pb(i);if(n/i!=i)factors.pb(n/i);}}sort(all(factors));} ll add(ll a,ll b) {return((a%M)+(b%M)+M)%M;} ll sub(ll a,ll b){return((a%M)-(b%M)+M)%M;} ll mul(ll a,ll b){return((a%M)*(b%M))%M;} void getPrimeFactors(ll n) {primefactors.clear();for(ll i=2;i*i<=n;i++){if(n%i==0){primefactors.pb(i);while(n%i==0)n=n/i;}}if(n!=1)primefactors.pb(n);} bool isSubstring(string s1, string s2){ if (s1.find(s2) != string::npos) return true; else return false; } ll ncr(ll n, ll r) {if(r==0)return 1;fact[0]=1;for(int i=1;i<=n;i++)fact[i]=fact[i-1]*i%M;return(fact[n]*modi(fact[r])%M*modi(fact[n-r])%M)%M;} //--------------------------------------------------------------------Template Above-------------------------------------------------------------------- int main(){ ll n,ans=0; cin>>n; ans=n+1; ans-=((ll)sqrtl(8*n+9)-1)/2; if(n==1) cout<<"1"; else cout<<min(ans,n-1); return 0; } //------------------------------------------------------------------------------------------------------------------------------------------------------
#include <bits/stdc++.h> using namespace std; int main() { using ll = long long; ll n; cin >> n; ll l = 0, r = 2e9; while (r - l > 1) { ll m = (l + r) / 2; (m * (m + 1) / 2 <= n + 1 ? l : r) = m; } cout << n - l + 1 << endl; return 0; }
#include<bits/stdc++.h> #define rep(i, n) for (int i = 0, length = n; i < length; i++) #define fi first #define se second #define lb lower_bound #define ub upper_bound #define ep emplace #define epb emplace_back #define scll static_cast<long long> #define sz(x) static_cast<int>((x).size()) #define pfll(x) printf("%lld\n", x) #define ci(x) cin >> x #define ci2(x, y) cin >> x >> y #define ci3(x, y, z) cin >> x >> y >> z #define ci4(w, x, y, z) cin >> w >> x >> y >> z #define co(x) cout << x << endl #define co2(x, y) cout << x << " " << y << endl #define co3(x, y, z) cout << x << " " << y << " " << z << endl using namespace std; typedef long long ll; typedef pair<int, int> P; typedef priority_queue<int> PQ; typedef priority_queue<int, vector<int>, greater<int>> PQG; typedef priority_queue<P> PQP; typedef priority_queue<P, vector<P>, greater<P>> PQPG; const int MAX_N = 2e5, MOD = 1e9 + 7, INF = 1e9; int n, k, a[800][800]; int comp(int x) { int sum[n + 1][n + 1]; rep(i, n + 1) sum[0][i] = 0; rep(i, n + 1) sum[i][0] = 0; rep(i, n) rep(j, n) sum[i + 1][j + 1] = sum[i][j + 1] + (a[i][j] >= x); rep(i, n - k + 1) { int tmp = 0; rep(j, k) tmp += sum[i + k][j] - sum[i][j]; rep(j, n - k + 1) { tmp += sum[i + k][j + k] - sum[i][j + k] - sum[i + k][j] + sum[i][j]; if (tmp < k * k / 2 + 1) return false; } } return true; } int main() { ci2(n, k); rep(i, n) rep(j, n) ci(a[i][j]); int l = 0, r = 1e9 + 1; while (r - l > 1) { int mid = (l + r) / 2; ((comp(mid)) ? l : r) = mid; } co(l); return 0; }
#define rep(i, n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(), v.end() typedef long long ll; #include <bits/stdc++.h> using namespace std; ll A[810][810]; ll B[810][810]; ll S[810][810]; ll n,k; bool f(ll x){ for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ if(A[i][j]<=x) B[i][j]=1; else B[i][j]=0; } } for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ S[i][j]=S[i][j-1]+B[i][j]; } } for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ S[i][j]+=S[i-1][j]; } } bool b=false; for(int i=1;i+k-1<=n;i++){ for(int j=1;j+k-1<=n;j++){ if(S[i+k-1][j+k-1]-S[i+k-1][j-1]-S[i-1][j+k-1]+S[i-1][j-1]>=k*k-k*k/2){ b=true; break; } } if(b) break; } if(b) return true; else return false; } int main(){ cin>>n>>k; rep(i,n){ rep(j,n) cin>>A[i+1][j+1]; } ll ng=-1,ok=1e9+1; while(ok-ng>1){ ll mid=(ng+ok)/2; if(f(mid)) ok=mid; else ng=mid; } cout<<ok<<endl; f(4); return 0; }
#include<bits/stdc++.h> #define ll long long #define dl long double #define pb push_back #define F first #define S second #define endl "\n" #define rep(i,a,b) for(i=a;i<b;i++) #define all(v) v.begin(),v.end() #define allr(v) v.rbegin(),v.rend() #define mod 1000000007LL #define CIN(V,s,n) for(int i=s;i<n;i++){cin >> V[i];} #define COUT(V,s,n) {for(int i=s;i<n;i++){cout << V[i] << " " ;} cout << endl;} #define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define CLEAR(V); for(ll i=0;i<V.size();i++) V[i] = 0; #define N 1000001LL #define tmod 998244353LL using namespace std; bool sBs(const pair<int,int> &a,const pair<int,int> &b) { return (a.second < b.second); } ll Powb(ll b,ll n,ll m); ll BS(vector<pair< ll ,ll > > &PS,ll s,ll e,ll ser); ll MI(ll a, ll m); ll P[N+1]; void Sieve(int n=N); int main() { fast; ll q=1,t; //cin >> q; t = q; while(q--) { ll i,j,n,m,k,l=0,r=0,a=0,b=0,c=0,d=0,e,g=1,p,u,v,w,x,y,z,flag=1; //n=m=k=i=j=l=r=a=b=c=d=u=v=w=p=x=y=0; string s; cin >> s; n = s.size(); for(i=0;i<n;i++) { if (i%2==0) { if (s[i] - 'A' < 26 and s[i] - 'A' >= 0) { flag = 0; break; } } else { if (s[i] - 'a' < 26 and s[i] - 'a' >= 0) { flag = 0; break; } } } if (flag) cout << "Yes"; else cout << "No"; } return 0; } //***************************************************************************************************************************************** ll Powb(ll b,ll n,ll m) { if(n==0) return 1LL; if(n==1) return b; ll temp = Powb(b,n/2,m); if(n%2==0){return (temp*temp)%m;} else{return (b*((temp*temp)%m))%m;} } ll BS(vector<pair<ll,ll> > &PS,ll s,ll e,ll ser) { if(s>e) return s; ll mid = (s+e)/2; if(PS[mid].F==ser) { return mid; } else if(PS[mid].F > ser) { return BS(PS,s,mid-1,ser); } else return BS(PS,mid+1,e,ser); } ll MI(ll a, ll m) { ll m0 = m; ll y = 0, x = 1; if (m == 1) return 0; while (a > 1) { ll q = a / m; ll t = m; m = a % m, a = t; t = y; y = x - q * y; x = t; } if (x < 0) x += m0; return x; } void Sieve(int n) { //memset(P,1,sizeof(P)); P[0] = 0; P[1]= 0; for(int i=2;i<=n;i++) P[i] = 1; for(ll i=2;i*i<=n;i++) { if(P[i]==1) { for(ll j=i*i;j<=n;j+=i) { P[j]=0; } } } }
#include<bits/stdc++.h> using namespace std; int main() { int n,i,e,j; //e=1;; //while(e--) { cin>>n; long a[n],b[n],c[n],max,d; for(i=0;i<n;i++) cin>>a[i]; for(i=0;i<n;i++) cin>>b[i]; c[0]=0; max=a[0]; for(i=1;i<n;i++) { if(a[i]>max) { max=a[i]; c[i]=i; } else c[i]=c[i-1]; } // for(i=0;i<n;i++) // cout<<c[i]<<" "; long long dp[n]; dp[0]=a[0]*b[0]; for(i=1;i<n;i++) { dp[i]=dp[i-1]; long long t=a[c[i]]*b[i]; if(dp[i]<t) dp[i]=t; } for(i=0;i<n;i++) cout<<dp[i]<<"\n"; } }
#include <iterator> #include <algorithm> #include <list> #include <deque> #include <string> #include <iostream> using namespace std; int main(){ string str,str2; cin >> str; for (int i = str.size()-1;i >=0;i--){ if (str[i] == '0') str.erase(i,1); else i = -1; } str2 =str; reverse(str.begin(),str.end()); if (str == str2) cout << "Yes"; else cout << "No"; }
#include <iostream> using namespace std; int main(){ int n; cin >> n; if (n==0){ cout << "Yes\n"; return 0; } while (n%10==0) n/=10; int n_inv=0,t=n; while (t>0) { n_inv = (t%10)+(n_inv<<3)+(n_inv<<1); t/=10; } cout << (n==n_inv?"Yes\n":"No\n"); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define rep(i, a, b) for (int i = a; i <= b; i++) #define rev_rep(i, a, b) for (int i = a; i >= b; i--) #define vi vector<int> #define pb push_back #define pi pair<int, int> #define mod = 1e9 + 7 void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void __print(char x) { cerr << '\'' << x << '\''; } void __print(const char *x) { cerr << '\"' << x << '\"'; } void __print(const string &x) { cerr << '\"' << x << '\"'; } void __print(bool x) { cerr << (x ? "true" : "false"); } template <typename T, typename V> void __print(const pair<T, V> &x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; } template <typename T> void __print(const T &x) { int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; } void _print() { cerr << "]\n"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); } #ifndef ONLINE_JUDGE #define debug(x...) \ cerr << "[" << #x << "] = ["; \ _print(x) #else #define debug(x...) #endif /* ************************************ CODE STATRTS HERE *************************************/ void solve() { int n , k ; cin>>n>>k; int sum = 0; rep(i,1,n) { rep(j,1,k) sum += i*100 + j; } cout<<sum<<endl; } int main() { int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define S second #define F first #define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define vll vector<long long int> #define vld vector<long double> #define pll pair<long long int,long long int> #define mod 1000000007 #define mod2 998244353 #define ll long long int #define ld long double #define pi 3.141592653589793238 #define Endl endl #define endl "\n" const int N = 1e6 + 5; const ll inf = 1e18; // unordered_map<ll,ll> rk; // bool cmp(ll a,ll b) // { // return rk[a] < rk[b]; // } void solve() { ll a,b; cin>>a>>b; a=a+b; if(a>=15 && b>=8) cout<<"1"; else if(a>=10 && b>=3) cout<<"2"; else if(a>=3) cout<<"3"; else cout<<"4"; } void debug(ll tt) {} // [L,R] make a window which matches with prefix of s signed main() { FAST; int t = 1; //cin >> t; //fill(); while(t--) { solve(); } }
#include <bits/stdc++.h> #define endl "\n" using namespace std; typedef long long ll; typedef vector<ll> vl; typedef pair<ll, ll> PP; #define rep(i, n) for (ll i = 0; i < ll(n); i++) #define rrep(i, n) for (ll i = n - 1; i > -1; i--) #define all(v) v.begin(), v.end() #define pb push_back #define fi first #define se second template <class X> void print(X x) { cout << x << endl; } void print(vl x) { for (ll i : x) { cout << i << " "; } cout << endl; } const ll INF = (1LL << 61) - 1; const ll MOD = 1000000007 /*998244353*/; const ll MAX_N = 500010; ll a, b, c, d, e, f, h, x, y, z, p, q, n, t, r, k, w, l, ans, i, j, u, v, m; ll codeforces = 1; string S, T; vector<vl> g(MAX_N * 10); vl A, B; ll masu[2001][2001]; vector<vector<PP>> V(26); vl dis = vl(MAX_N * 10, INF); void input() { cin >> h >> w; rep(i, h) { cin >> S; rep(j, w) { if (S[j] == 'S') { e = i; f = j; } else if (S[j] == 'G') { r = i; t = j; } else if (S[j] == '#') { masu[i][j] = -1; } else if (S[j] != '.') { V[S[j] - 'a'].pb({i, j}); masu[i][j] = S[j] - 'a' + 1; } } } } void solve() { rep(i, h) { rep(j, w) { if (i > 0 && masu[i][j] != -1 && masu[i - 1][j] != -1) g[i * w + j].pb((i - 1) * w + j); if (i < h - 1 && masu[i][j] != -1 && masu[i + 1][j] != -1) g[i * w + j].pb((i + 1) * w + j); if (j > 0 && masu[i][j] != -1 && masu[i][j - 1] != -1) g[i * w + j].pb(i * w + j - 1); if (j < w - 1 && masu[i][j] != -1 && masu[i][j + 1] != -1) g[i * w + j].pb(i * w + j + 1); } } queue<ll> q; q.push(e * w + f); dis[e * w + f] = 0; while (!q.empty()) { int v = q.front(); q.pop(); for (ll x : g[v]) { if (dis[x] == INF) { dis[x] = dis[v] + 1; q.push(x); } } a = v / w; b = v % w; //print({v, a, b, masu[a][b]}); if (masu[a][b] > 0) { p = masu[a][b] - 1; rep(i, V[p].size()) { e = V[p][i].fi; f = V[p][i].se; masu[e][f] = 0; if (dis[e * w + f] == INF) { dis[e * w + f] = dis[v] + 1; q.push(e * w + f); } } } masu[a][b] = 0; } if (dis[r * w + t] < INF) print(dis[r * w + t]); else print(-1); } int main() { // cout<<fixed<<setprecision(15); cin.tie(0); ios::sync_with_stdio(false); input(); while (codeforces--) { solve(); } }
#include<iostream> #include<cstdio> using namespace std; const int N=5002020,INF=2e9; int n,m,cnt,tot; char s[2020][2020]; int id[1000],v[N],dis[N],stk[N<<3]; bool vis[N]; int dx[]={1,-1,0,0}; int dy[]={0,0,1,-1}; struct Edge{int to,next,w;}e[N<<4]; void add(int x,int y,int z){ e[++tot].to=y; e[tot].next=v[x]; v[x]=tot; e[tot].w=z; } int get(int x,int y){return (x-1)*m+y;} bool check(int x,int y){ if(x<=n && y<=m && x>=1 && y>=1 && s[x][y]!='#')return 1; return 0; } void spfa(int x){ for(int i=1;i<=cnt;i++)dis[i]=INF; dis[x]=0; int top; stk[top=1]=x; for(int i=1;i<=top;i++){ int w=stk[i]; vis[w]=0; for(int p=v[w];p;p=e[p].next){ int kp=e[p].to; if(dis[kp]>dis[w]+e[p].w){ dis[kp]=dis[w]+e[p].w; if(!vis[kp])vis[stk[++top]=kp]=1; } } } } int main() { cin>>n>>m; for(int i=1;i<=n;i++) scanf("%s",s[i]+1); cnt=get(n,m); for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ if(s[i][j]=='#')continue; for(int k=0;k<4;k++){ int x=dx[k]+i,y=dy[k]+j; if(check(x,y))add(get(i,j),get(x,y),1),add(get(x,y),get(i,j),1); } if(s[i][j]>='a' && s[i][j]<='z'){ if(!id[s[i][j]])id[s[i][j]]=++cnt; add(get(i,j),id[s[i][j]],1); add(id[s[i][j]],get(i,j),0); } } } int bg; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) if(s[i][j]=='S')bg=get(i,j); spfa(bg); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) if(s[i][j]=='G'){ if(dis[get(i,j)]<INF)printf("%d\n",dis[get(i,j)]); else puts("-1"); } return 0; }
#include<bits/stdc++.h> #define ll long long #define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define w(t) ll t;cin>>t;while(t--) #define pb push_back #define mp make_pair #define fi first #define se second #define all(x) x.begin(), x.end() #define fo(i,a,n) for(ll i=a;i<n;i++) #define precision cout<<fixed<<setprecision(10) const ll mod=1e9+7; using namespace std; int main() { IOS ll n,s=0,r; cin>>n; fo(i,0,n) { ll a,b; cin>>a>>b; r=((b*(b+1))/2)-((a*(a-1))/2); s=s+r; } cout<<s; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; int n; ll x,a[55]; map<ll,ll> mem[55]; ll dfs(const int& i,const ll& v){ if(i==0)return v==0; if(mem[i].find(v)!=mem[i].end())return mem[i][v]; ll nv=v%a[i]; mem[i][v]=dfs(i-1,nv); if(nv&&a[i]+v!=a[i+1]+nv)mem[i][v]+=dfs(i-1,a[i]-nv); return mem[i][v]; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>n>>x; for(int i=1;i<=n;i++){ cin>>a[i]; } cout<<dfs(n,x%a[n])<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; 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; } const int MOD = 1e9+7; const int INF = 0x3f3f3f3f; const ll LLINF = 0x3f3f3f3f3f3f3f3f; const int MAXN = 100005; const int MAXM = 1000005; ll a[MAXN], vis[MAXN]; int main(){ ll A, B , C; cin >> A >> B >> C; int ans = 0; if(A<0 && B < 0 || A >= 0 && B >= 0) { if(A < B) ans = -1; else if(A == B) ans = 0; else ans = 1; } else if(A < 0 && B >= 0) { if(C%2 == 1) { ans = -1; } else { if(-1*A < B) ans = -1; else if(-1*A == B) ans = 0; else if(-1*A > B) ans = 1; } } else if(B<0 && A >= 0) { if(C%2 == 1) { ans = 1; } else { if(-1*B < A) ans = 1; else if(-1*B == A) ans = 0; else if(-1*B > A) ans = -1; } } if(ans == -1) cout << "<" << endl; else if(ans == 0) cout << "=" << endl; else cout << ">" << endl; return 0; }
#include <iostream> #include <algorithm> #include <iomanip> #include <queue> #include <stack> #include <set> #include <map> #include <cstdlib> #include <cstdio> #include <vector> #include <stdlib.h> #include <cstring> #include <cmath> #include <math.h> #include <string> typedef long long ll; using namespace std; #define inf 1e9 int a,b,c; void solve(){ cin >> a >> b >> c; a = 7-a; b = 7-b; c = 7-c; cout <<a+b+c; } int main(){ solve(); return 0; }
#include <iostream> #include <cstring> #include <vector> using namespace std; int main(void){ int N, M; cin >> N >> M; vector<int> node; node.reserve(N); int input; for(int i=0; i<N; ++i){ cin >> input; node.push_back(input); } for(int i=0; i<N; ++i){ cin >> input; node.at(i)-=input; } long long int sum = 0; int c, d; for(int i=0; i<M; ++i){ cin >> c >> d; --c, --d; if(node.at(c)) sum+=node.at(c), node.at(c)=0; if(node.at(d)) sum+=node.at(d), node.at(d)=0; } if(sum!=0){ cout << "No" << endl; return 0; } for(int i=0; i<N; ++i){ if(node.at(i)){ cout << "No" << endl; return 0; } } cout << "Yes" << endl; return 0; }
#include <iostream> #include <iomanip> #include <cstdlib> #include <cstring> #include <string> #include <bitset> #include <cmath> #include <algorithm> #include <climits> #include <vector> #include <queue> #include <stack> #include <map> #include <set> using namespace std; //infの設定 #define INF32 2147483647 #define INF64 9223372036854775807 #define PRIME 1000000007 #define PI 3.141592653589793238 //repマクロ #define rep(i,m,n) for (int i=(m); (i)<(int)(n); ++(i)) #define rrep(i,m,n) for (int i=(m); (i)>(int)(n); --(i)) //その他 #define eb emplace_back #define ALL(v) v.begin(), v.end() typedef long long ll; typedef pair<long long,long long> Pl; //#define int long long //UnionFind木 struct UnionFind{ vector<int> par; UnionFind(int n):par(n){ for(int i=0;i<n;i++) par.at(i)=i; } int root(int x){ if(par.at(x)==x) return x; return par.at(x)=root(par.at(x)); } int merge(int x,int y){ int rx=root(x); int ry=root(y); if(rx==ry) return 0; par.at(rx)=ry; return 1; } bool isSame(int x,int y){ int rx=root(x); int ry=root(y); return rx==ry; } }; int main(){ int N,M; cin>>N>>M; vector<int> A(N),B(N); rep(i,0,N) cin>>A[i]; rep(i,0,N) cin>>B[i]; UnionFind UF(N); rep(i,0,M){ int c,d;cin>>c>>d; UF.merge(c-1,d-1); } map<int,ll> ma; rep(i,0,N){ int key=UF.root(i); if(ma.count(key)==0){ ma.emplace(key,A[i]-B[i]); }else{ ma.at(key)+=A[i]-B[i]; } } for(auto k:ma){ if(k.second!=0){ cout<<"No"<<endl; return 0; } } cout<<"Yes"<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define mp make_pair #define pb push_back #define pf push_front #define ff first #define ss second #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define gcd(a,b) __gcd((a),(b)) #define lcm(a,b) ((a)*(b))/gcd((a),(b)) #define endl "\n" #define pi 3.14159265358979323846 #define inf 1000000000 #define setbits(x) __builtin_popcountll(x) #define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> typedef long long ll; typedef long double ld; #define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); const int N = 1e5+50; const ll mod = 1e9+7; const ll INF = 1e18; // int dx[9]={-1,-1,-1,0,1,1,1,0,0}; // int dy[9]={-1,0,1,1,1,0,-1,-1,0}; int dx[] = {-1,0,1,0}; int dy[] = {0,1,0,-1}; bool compare(const pair<ll, ll>&i, const pair<ll, ll>&j) { return i.second < j.second; } ll fact[N]; vector<bool> is_prime(100000,true); vector<int>prime; void pre() { fact[0]=1; for(ll i=1;i<N;i++) { fact[i]=i*fact[i-1]; fact[i]%=mod; } } ll modexp(ll x,ll n) { ll r=1; while(n){ if(n&1) r=(r*x)%mod; x=(x*x)%mod; n>>=1; } return r%mod; } ll modinv(ll x) { return modexp(x,mod-2); } ll ncr(ll n,ll r) { if(n<r) return 0; ll ans=(fact[n]%mod * modinv(fact[r])%mod * modinv(fact[n-r])%mod)%mod; return ans; } ll exp(ll x,ll n) { ll r=1; while(n){ if(n&1) r=(r*x); x=(x*x); n>>=1; } return r; } int n; vector<int>C(N); vector<int>adj[N]; bool vis[N]; map<int,int>m; int ver; vector<int>ans; void dfs(int x){ vis[x]=1; if(m[C[x]]==0) ans.pb(x); m[C[x]]++; for(auto ch:adj[x]){ if(!vis[ch]){ dfs(ch); } } m[C[x]]--; } void solve() { cin>>n; for(int i=1;i<=n;i++) cin>>C[i]; for(int i=0;i<n-1;i++){ int a,b; cin>>a>>b; adj[a].pb(b); adj[b].pb(a); } dfs(1); sort(ans.begin(),ans.end()); for(auto x:ans) cout<<x<<endl; return ; } int32_t main() { fio // #ifdef ONLINE_JUDGE // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); // #endif // pre(); int t=1; // cin>>t; for(int i=0;i<t;i++) { solve(); } return 0; }
#define _USE_MATH_DEFIMES #include <algorithm> #include <array> #include <bitset> #include <cassert> #include <cctype> #include <climits> #include <clocale> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <regex> #include <set> #include <sstream> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> const int MOD = 1'000'000'007; const int MOD2 = 998'244'353; const int INF = 1'000'000'000; //1e9 const int NIL = -1; const long long LINF = 1'000'000'000'000'000'000; // 1e18 const long double EPS = 1E-10; template<class T, class S> inline bool chmax(T &a, const S &b){ if(a < b){ a = b; return true; } return false; } template<class T, class S> inline bool chmin(T &a, const S &b){ if(b < a){ a = b; return true; } return false; } std::set<int> dfs(int cur, int prv, std::vector<int> &C, std::set<int> &c, std::vector<std::vector<int>> &G){ std::set<int> rt; if(c.find(C[cur]) == std::end(c)) rt.insert(cur); c.insert(C[cur]); for(auto v: G[cur]){ if(v == prv) continue; std::set<int> b{dfs(v, cur, C, c, G)}; if(b.size() > rt.size()) swap(b, rt); for(auto e: b){ rt.insert(e); } } if(rt.find(cur) != std::end(rt)) c.erase(C[cur]); return rt; } int main(){ int N; std::cin >> N; std::vector<int> C(N); for(auto &e: C) std::cin >> e; std::vector<std::vector<int>> G(N); { int A, B; for(int i{0}, i_len{N-1}; i < i_len; ++i){ std::cin >> A >> B; G[--A].push_back(--B); G[B].push_back(A); } } std::set<int> c; std::set<int> ans{dfs(0, NIL, C, c, G)}; for(auto e: ans){ std::cout << e+1 << "\n"; } return 0; }
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization ("unroll-loops") #include<bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<int,int> pii; typedef vector<int> vii; typedef vector<pii> vpii; typedef unordered_map<int,int> umap; typedef long double ld; #define fi first #define se second #define pb push_back #define mp make_pairNa #define popcount __builtin_popcount #define case cout<<"Case "<<z-t<<": "; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n,m,i,j,k; cin>>n>>m; pair<ll,ll> fnd[n]; for(i=0;i<n;i++) cin>>fnd[i].fi>>fnd[i].se; sort(fnd,fnd+n); ll ans=m; for(i=0;i<n;i++){ if(ans>=fnd[i].fi) ans+=fnd[i].se; else break; } cout<<ans<<endl; }
#include <iostream> #include <vector> #include <algorithm> using namespace std; typedef long long ll; typedef unsigned long long ull; #define rep(i,n) for(int i=0;i<(n);i++) #define mod (1000000007) int main() { int N,W; cin >> N >> W; cout << (N / W) << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define debug(x) cerr << #x << " : " << x << endl; using namespace std; using ll = long long; vector<string> s(800); vector<vector<char>> a(20, vector<char>(20)); // 部分列は構成済みか vector<bool> used(800, false); int main() { int n, m; cin >> n >> m; rep(i,m) cin >> s[i]; rep(i,n) { int w=0; rep(j, m) { if(w+s[j].size() < n && !used[j]) { for(int k=w; k < w+s[j].size(); k++) { a[i][k] = s[j][k-w]; } w += s[j].size(); used[j] = true; } if(w == n) break; } while(w<n) { a[i][w] = '.'; w++; } } rep(i,n) { rep(j,n) { cout << a[i][j]; } cout << endl; } }
#include <iostream> #include <vector> #include <tuple> #include <algorithm> #include <set> #include <map> #include <cmath> #include <queue> #define ll long long #define rep(i,n) for(int i = 0;i < (int)n;i ++) using namespace std; ll n,m; vector<vector<ll>> ans(20,vector<ll>(20,-1)); vector<vector<ll>> a; vector<tuple<ll,ll>> b; void GETVALUE(){ cin >> n >> m; rep(i,m){ string s; cin >> s; a.push_back({}); rep(j,(s.size())){ a[i].push_back(s[j]-'A'); } b.push_back(make_tuple((s.size()),i)); } sort(b.begin(),b.end()); } void PUTVALUE(){ rep(i,n){ rep(j,n){ if(ans[i][j] == -1){ cout << '.'; }else{ char l = 'A'+ans[i][j]; cout << l; } } cout << endl; } } void MAKEANS(){ m = b.size(); ll I = 0; rep(i,n){ ll p = 0; while(p + get<0>(b[I]) <= n){ for(ll j:a[get<1>(b[I])]){ ans[i][p] = j; p ++; } I ++; if(I >= m)break; } if(I >= m)break; if(p >= n-1)continue; rep(j,n-p){ ans[i][p+j] = a[get<1>(b[I])][j]; } I ++; } } void SORTANS(){ m = b.size(); vector<vector<ll>> END(64); vector<vector<ll>> STA(64); rep(i,m){ ll x = a[i].size(); STA[a[i][0]*8+a[i][1]].push_back(i); END[a[i][x-2]*8+a[i][x-1]].push_back(i); } rep(i,64){ while((not END[i].empty()) and (not STA[i].empty())){ ll p = END[i].back(); ll q = STA[i].back(); END[i].pop_back(); STA[i].pop_back(); for(ll j = (b.size())-1;j >= 0;j --){ if(get<1>(b[j]) == p or get<1>(b[j]) == q){ b.erase(b.begin()+j); } } ll s1 = a[p].size(); ll s2 = a[q].size(); rep(j,s2-2){ a[p].push_back(a[q][j+2]); } b.insert(b.begin(),make_tuple(s1+s2-2,p)); } } } int main(void){ GETVALUE(); rep(i,10)SORTANS(); MAKEANS(); PUTVALUE(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll, ll> pll; const ll LongINF=1e13+7; const int INF=1e9+7; const int dx[]={0,1,0,-1}; const int dy[]={1,0,-1,0}; 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, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);} template<class T,class Y>T LCM(T a,Y b){return (a*b)/GCD(a,b);} void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない using vi=vector<int>; using vii=vector<vi>; #define REP(i,a,b) for(ll i=(a);i<(b);i++) #define rep(i,n) REP(i,0,n) #define pb push_back #define rv reverse #define ALL(a) (a).begin(),(a).end() #define decimal(x) fixed<<setprecision(x) int main(){ int a,b; cin>>a>>b; cout<<2*a+100-b<<endl; return 0; } /* */
#include <iostream> using namespace std; int main() { int n,m; int c; cin>>m>>n; cout<<(( 2*m+100)-n); }
#include<iostream> #include<bits/stdc++.h> #include<vector> #define vi vector<int> #define lli long long int #define fo(i,n) for(int i=1;i<=n;i++) #define foo(i,n) for(int i=0;i<n;i++) #define ff first #define ss second #define pb push_back #define vii vector<lli> #define ok ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); using namespace std; #define vp vector<pair<lli,lli>> #include <map> #include <stdio.h> #include <stdlib.h> #include <string.h> int main(){ lli v[4],t=0; foo(j,4) cin>>v[j]; foo(i,4) t+=v[i]; if(t%2) { cout<<"No"; return 0; } lli s = 0; lli mask = 15; fo(i,mask){ s=0; foo(j,4){ if(i&(1<<j)){ s+=v[j]; } } if(s==t/2){ cout<<"Yes"; return 0; } } cout<<"No"; return 0; }
//#pragma GCC target("avx2") #pragma GCC optimize("O3") //#pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include <prettyprint.hpp> #define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__); #else #define debug(...) 83; #endif void d_err() { cerr << endl; } template <typename H, typename... T> void d_err(H h, T... t) { cerr << h << " "; d_err(t...); } template <typename T> void print(T x) { cout << x << "\n"; } #define ALL(x) (x).begin(), (x).end() #define FOR(i, m, n) for (ll i = (m); i < (n); ++i) #define REVFOR(i, m, n) for (ll i = (n - 1); i >= (m); --i) #define REP(i, n) FOR(i, 0, n) #define REVREP(i, n) REVFOR(i, 0, n) #define fi first #define se second #define pb push_back #define mp make_pair #define eb emplace_back #define bcnt __builtin_popcountll typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<ll> vll; typedef pair<ll,ll> Pll; typedef pair<int,int> Pin; ll INF = 1e16; int inf = 1e9; int main(){ cin.tie(0); ios_base::sync_with_stdio(false); cout << fixed << setprecision(20); ll n; cin >> n; set<ll> s; FOR(i, 1, sqrt(n) + 1) { if (n % i == 0) { s.insert(i); if (i * i != n) s.insert(n / i); } } for(auto &e: s) print(e); }
#include <bits/stdc++.h> using namespace std; #define SF(A) sort(A.begin(), A.end()) #define LF(A) sort(A.rbegin(), A.rend()) #define COUNT(A,B) count(A.begin(),A.end(),B) #define REP(i,b,e) for(i=b;i<e;i++) int main() { int i; long long int A, B, C, D, b, r; cin >> A >> B >> C >> D; if (B >= C * D) { cout << "-1" << endl; return 0; } b = A; r = 0; long long int count = 0; while (r * D < b) { b += B; r += C; count++; } cout << count << endl; }
#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の小さいものを下につける rank[y] += rank[x]; p[x] = y; } // グループの数 ll root_num() { ll num = 0; for(ll x : p) if (x < 0) num++; return num; } //xが属すグループのサイズ int size(int x){ return rank[root(x)]; } bool same(int x, int y){ return (root(x) == root(y)); } }; // 100 は 上 / 101 は 下 ll dist2rsq[102][102]; void solve() { ll n, xi, yi; cin >> n; // tuple<x, y> vector<tuple<ll, ll>> pos(n); // tuple<dist, idx, idx> vector<tuple<double, ll, ll>> dist; rep(i, n) { cin >> xi >> yi; pos[i] = make_tuple(xi, yi); } rep(i, n-1) repi(j, i+1, n) { ll x1, y1, x2, y2; tie(x1, y1) = pos[i]; tie(x2, y2) = pos[j]; double _2r = hypot(x1 - x2, y1 - y2); dist.emplace_back(_2r, i, j); } rep(i, n) { // n:100 は 上 / n+1:101 は 下 dist.emplace_back(100 - get<1>(pos[i]), i, n); dist.emplace_back(100 + get<1>(pos[i]), i, n+1); } sort(ALL(dist)); double ac = 0.0, wa = 300.0; while(wa - ac > 0.00005) { double wj = (ac + wa) / 2.0; UnionFind uf(n + 2); for(const auto& d : dist) { double _2r; ll i, j; tie(_2r, i, j) = d; if (_2r < wj) uf.unite(i, j); else break; } if ( uf.same(n, n+1) ) wa = wj; else ac = wj; } printf("%.5lf\n", ac / 2.0); } int main() { fastio; solve(); return 0; }
#include <iostream> #include <vector> #include <iomanip> #include <string> #include <algorithm> #include <cmath> #include <map> #include <functional> using ll = long long; using vll = std::vector<ll>; using namespace std; #define REP(i, x, n) for(int i = x; i < (n); i++) #define rep(i, n) REP(i, 0, n) template<class T> void gi(T &x){ int minus=0; x=0; char c=getchar(); for(;c<'0'||c>'9'; c=getchar()) minus|=(c=='-'); for(;c>='0'&&c<='9'; c=getchar()) x=(x<<1)+(x<<3)+(c^48); if(minus) x=-x; } const ll MOD=1000000007; int main() { ll t; gi(t); auto square = [](ll n, ll md){ return n*n%md; }; auto choose2 = [](ll n, ll md){ return n*(n-1)/2%md; }; rep(i,t){ ll n,a,b; gi(n),gi(a),gi(b); if(a+b > n){ printf("%lld\n", 0LL); continue; } ll all = (square(n-a+1,MOD)*square(n-b+1,MOD))%MOD; ll notoverlaped = choose2(n-a-b+2,MOD)*2%MOD; ll overlaped = square((((n-a+1)*(n-b+1)%MOD- notoverlaped+MOD)%MOD),MOD); ll ans = (all - overlaped +MOD)%MOD; printf("%lld\n", ans); } return 0; }
#include <bits/stdc++.h> // #include <atcoder/all> using namespace std; // using namespace atcoder; #define DEBUG(x) cerr<<#x<<": "<<x<<endl; #define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl; #define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;} typedef long long ll; #define int ll #define vi vector<int> #define vl vector<ll> #define vii vector< vector<int> > #define vll vector< vector<ll> > #define vs vector<string> #define pii pair<int,int> #define pis pair<int,string> #define psi pair<string,int> #define pll pair<ll,ll> template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); } template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); } template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; } #define X first #define Y second #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rep1(i,n) for(int i=1;i<=(int)(n);i++) #define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--) #define rrep1(i,n) for(int i=(int)(n);i>0;i--) #define REP(i,a,b) for(int i=a;i<b;i++) #define in(x, a, b) (a <= x && x < b) #define all(c) c.begin(),c.end() template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; } #define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end()); const ll inf = 1000000001; const ll INF = (ll)1e18 + 1; const long double pi = 3.1415926535897932384626433832795028841971L; #define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl; // int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; // int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 }; vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1}; // vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 }; #define fio() cin.tie(0); ios::sync_with_stdio(false); const ll MOD = 1000000007; // const ll MOD = 998244353; // #define mp make_pair //#define endl '\n' signed main() { fio(); int t; cin >> t; while (t--) { ll n, a, b; cin >> n >> a >> b; if (a + b > n) { cout << 0 << endl; continue; } if (a < b) swap(a, b); vl kouho; kouho.push_back(0); kouho.push_back(b); kouho.push_back(n - a - b + 1); kouho.push_back(n - a + 1); sort(all(kouho)); // UNIQUE(kouho); // DEBUG_VEC(kouho); ll ans = (n - a + 1) * (n - a + 1) % MOD * (n - b + 1) % MOD * (n - b + 1) % MOD; // DEBUG(ans); rep (i, 3) { rep (j, 3) { ll r1 = kouho[i + 1] - kouho[i], r2 = kouho[j + 1] - kouho[j]; ll add = r1 * r2 % MOD; // DEBUG(pll(r1, r2)); ll s1 = max(0LL, kouho[i] - b + 1), t1 = max(0LL, kouho[j] - b + 1); ll s2 = min(kouho[i] + a, n - b + 1), t2 = min(kouho[j] + a, n - b + 1); // DEBUG(pll(s1, s2)); // DEBUG(pll(t1, t2)); (add *= (s2 - s1) * (t2 - t1) % MOD) %= MOD; // DEBUG(add); (ans -= add) %= MOD; } } cout << (ans % MOD + MOD) % MOD << endl; } }
#include <bits/stdc++.h> #define endl "\n" using namespace std; void setup() { #ifdef LOCAL freopen("input", "r", stdin); #else ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #endif } int main() { setup(); int N, W; cin >> N >> W; long long line[200020]; memset(line, 0, sizeof(long long) * 200020); for (int i = 0; i < N; i++) { int S, T, P; cin >> S >> T >> P; line[S] += P; line[T] -= P; } bool no = line[0] > W; for (int i = 1; i < 200020; i++) { line[i] += line[i-1]; if (line[i] > W) { no = true; break; } } if (no) cout << "No" << endl; else cout << "Yes" << endl; }
#include "bits/stdc++.h" typedef long long ll; #define all(x) (x).begin(), (x).end() // sortなどの引数を省略 #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define max3(x, y, z) max(x, max(y, z)) #define min3(x, y, z) min(x, min(y, z)) #ifdef _MSC_FULL_VER //デバッグ出力 #define dout cout #define debug() if (true) #define check(x) std::cout << "★" << #x << "の値:" << (x) << endl #define pass(x) std::cout << "☆" << x << endl #else #define dout \ if (false) cout #define debug() if (false) #define check(x) \ if (false) cout << "★" << #x << "の値:" << (x) << endl #define pass(x) \ if (false) cout << "☆" << x << endl #endif using namespace std; //#define int long long; double dist(double x1, double y1, double x2, double y2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); } ll idist(ll x1, ll y1, ll x2, ll y2) { return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2); } signed main() { ll N,w; cin >> N >> w; vector<pair<ll,ll>> a(N); vector<pair<ll,ll>> b(N); rep(i,N){ ll tmp0,tmp1,tmp2; cin >> tmp0 >> tmp1 >> tmp2; a[i] = make_pair(tmp0,tmp2); b[i] = make_pair(tmp1,tmp2); } sort(all(a)); sort(all(b)); ll d = 0; ll m = 0; rep(i,N){ while(a[i].first >= b[d].first){ m-=b[d].second; d++; } m+=a[i].second; //cout << i << " " << d << endl; if(m>w){ //cout << i <<" " << d << endl; cout << "No"; return 0; } } cout << "Yes"; }
/** * author: Eccentric_9 * created: 12.05.2021 17:34:05 **/ #include<bits/stdc++.h> using namespace std; /*-----<Defines>-----*/ #define fast() ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define all(x) begin(x),end(x) #define rz(x) resize(x) #define asn(x,y) assign(x,y) #define mem(a,b) memset(a,b,sizeof(a)) #define sz(x) ((int)size(x)) #define eb emplace_back #define pb push_back #define pf push_front #define pob pop_back #define pof pop_front #define ins insert #define vi vector<int> #define vl vector<long long> #define pll pair<long long,long long> #define mll map<long long,long long> #define sl set<long long> #define F first #define S second #define remax(a,b) a=max(a,b) #define remin(a,b) a=min(a,b) #define bitcount(x) __builtin_popcountll(x) #define iceil(n,x) (((n)-1)/(x)+1) #define flush fflush(stdout) #define FOR(i,a,b) for(int i=a;i<=b;i++) #define FORD(i,a,b) for(int i=a;i>=b;i--) #define r(i,n) FOR(i,0,n-1) #define w(x) int t;cin>>t;while(t--) #define en '\n' #define sp <<" "<< using ull=unsigned long long; using ll=long long; using ld=long double; /*-----</Defines>-----*/ /*-----<Debugging Stuff>-----*/ string to_string(char s) { string res="'''";res[1]=s;return res; } 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.F)+", "+to_string(p.S)+")"; } template<typename A> string to_string(A v) { bool first=1; string res="{"; for(const auto &x:v) { if(!first) res+=", "; first=0; res+=to_string(x); } res+="}"; return res; } void debug() { cout<<"\n"; } template<typename Head, typename... Tail> void debug(Head H, Tail... T) { cout<<" "<<to_string(H); debug(T...); } #define show(...) cout << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__) /*-----</Debugging Stuff>-----*/ /*-----<Mod Operations>-----*/ const int M=1e9+7; inline int add(int a,int b,int p=M){ a=a+b; if(a>=p) a-=p; return a; } inline int sub(int a,int b,int p=M){ a=a-b; if(a<0) a+=p; return a; } inline int mul(int a,int b,int p=M){ a=(a*1ll*b)%p; return a; } /*-----</Mod Operations>-----*/ /*-----<Constants>-----*/ const ld pi=acos(-1),eps=1e-9; const ll inf=1e18; const int N=1e4+5,K=255; /*-----</Constants>-----*/ ll n, m, q, k, l, r, x, y, z; const ll template_array_size = 1e6; ll a[template_array_size]; ll b[template_array_size]; ll c[template_array_size]; string s, t; ll ans = 0; void solve() { ll c; cin>>n>>c; mll m; r(i,n){ ll a,b,cc; cin>>a>>b>>cc; m[a]+=cc; m[b+1]-=cc; }auto it=m.begin(); ll val=it->S,r=it->F; it++; for(it;it!=m.end();it++){ val+=it->S; it->S=val; }it=m.begin(); val=it->second; ans=0; for(it;it!=m.end();it++){ if(it==m.end()) break; ans+=(it->F-r)*(min(c,val)); val=it->S; r=it->F; }cout<<ans; } int main() { /*#ifndef nipun_mitra freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif*/ fast(); //w(x) solve(); }
#include<iostream> #include<iomanip> #include<cassert> #include<math.h> #include<complex> #include<algorithm> #include<utility> #include<queue> #include<stack> #include<string.h> #include<string> #include<set> #include<map> #include<unordered_map> #include<functional> #include<vector> #include<bitset> using namespace std; typedef long long ll; typedef pair<ll,ll> L_L; const ll INF=2e18; const ll MOD=1e9+7; template <typename T> class Zip { public: vector<T> d; bool flag; Zip() { flag = false; } void add(T x) { d.push_back(x); flag = true; } ll getNum(T x) { // T need to have operator < !! if (flag) { sort(d.begin(), d.end()); d.erase(unique(d.begin(), d.end()), d.end()); flag = false; } return lower_bound(d.begin(), d.end(), x) - d.begin(); } ll size() { if (flag) { sort(d.begin(), d.end()); d.erase(unique(d.begin(), d.end()), d.end()); flag = false; } return (ll)d.size(); } }; ll N,C; map<ll,ll> sum; ll a[200010],b[200010],c[200010]; int main(){ cin>>N>>C; Zip<ll> zp; for(ll i=0;i<N;i++){ cin>>a[i]>>b[i]>>c[i]; zp.add(a[i]); zp.add(a[i]-1); zp.add(b[i]); zp.add(b[i]+1); } for(ll i=0;i<N;i++){ sum[a[i]]+=c[i]; sum[b[i]+1]-=c[i]; } ll ans=0; for(ll i=1;i<zp.size();i++){ sum[zp.d[i]] += sum[zp.d[i-1]]; ans+=min(C,sum[zp.d[i-1]])*(zp.d[i]-zp.d[i-1]); } cout<<ans<<endl; return 0; }
#include<bits/stdc++.h> typedef long long ll; #define int ll using namespace std; const int mod = 1e9+7; const int MAXN = 100000005; signed main(){ std::ios::sync_with_stdio(false); int a,b,c; cin >>a >> b>>c; c *= 1000; int maxn,minn; minn = c/b; maxn = c/a; if(c-minn*b <= minn*(b-a) && c - maxn*a <= minn*(b-a)){ if(c - minn*b != 0) minn++; cout << minn << ' ' << maxn; return 0; } else cout << "UNSATISFIABLE"; return 0; }
#include<bits/stdc++.h> #define int long long #define rd(x) x=read() #define seg(x,y) (seg){x,y} using namespace std; const int N=1e5+5; const int M=505; const int inf=0x3f3f3f3f; const int mod=1e9+7; inline int read(){int x=0,f=1;char ch=getchar();while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;} int ksm(int x,int y){int ret=1;while (y){if (y&1) ret=(ret*x)%mod;x=(x*x)%mod;y>>=1;}return ret;} int n,m,ans; void solve(int x,int y) { if (x%y==0) {ans+=x*2-y;return;} ans+=(x-x%y)*2; solve(y,x%y); } signed main() { int a,b,c,d; rd(a);rd(b);rd(c);rd(d); cout<<min(min(a,b),min(c,d))<<endl; }
#include<bits/stdc++.h> #define rep(i,n) for(int i=0;i<n;i++) using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<long long> vl; typedef vector<vector<int>> vvi; typedef vector<vector<long long>> vvl; const int INF=1e8; void chmin(int& x, int y){ x=min(x,y);} int main(){ int n; cin >> n; vi x(n),y(n),z(n); rep(i,n) cin >> x[i] >> y[i] >> z[i]; int n2=1<<n; vvi dist(n,vi(n)); rep(i,n) rep(j,n) dist[i][j]=abs(x[j]-x[i])+abs(y[j]-y[i])+max(0,z[j]-z[i]); vvi dp(n2,vi(n,INF)); rep(i,n){ if(i==0) continue; dp[1<<i][i]=dist[0][i]; } rep(i,n2){ rep(j,n){ if(!(i>>j&1)) continue; rep(k,n){ if(i>>k&1) continue; chmin(dp[i|1<<k][k],dp[i][j]+dist[j][k]); } } } cout << dp[n2-1][0]; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)(n);i++) #define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++) #define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--) #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++) #define setp(n) fixed << setprecision(n) template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } #define ll long long #define vll vector<ll> #define vi vector<int> #define pll pair<ll,ll> #define pi pair<int,int> #define all(a) (a.begin()),(a.end()) #define rall(a) (a.rbegin()),(a.rend()) #define fi first #define se second #define pb push_back #define ins insert #define debug(a) cerr<<(a)<<endl #define dbrep(a,n) rep(_i,n) cerr<<(a[_i])<<" "; cerr<<endl #define dbrep2(a,n,m) rep(_i,n){rep(_j,m) cerr<<(a[_i][_j])<<" "; cerr<<endl;} using namespace std; template<class A, class B> ostream &operator<<(ostream &os, const pair<A,B> &p){return os<<"("<<p.fi<<","<<p.se<<")";} template<class A, class B> istream &operator>>(istream &is, pair<A,B> &p){return is>>p.fi>>p.se;} //------------------------------------------------- //--Extended GCD //------------------------------------------------- ll extgcd(ll a, ll b, ll &x, ll &y) { if (b==0){ x = 1; y = 0; return a; } ll d = extgcd(b,a%b,y,x); y -= a/b*x; return d; } //------------------------------------------------- int main(void) { cin.tie(0); ios::sync_with_stdio(false); int t; cin>>t; while(t--){ ll N,S,K; cin>>N>>S>>K; ll g = __gcd(K,N); if (S%g!=0){ cout<<"-1\n"; continue; } N/=g; S/=g; K/=g; ll inv,_; extgcd(K,N,inv,_); inv=(inv+N)%N; cout<<inv*(N-S)%N<<"\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; const long long inf = 1LL<<60; using ll = long long; int main(){ double a, b; cin >> a >> b; cout << fixed << setprecision(10) << b*a/100.0 << endl; }
#include <iostream> #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; #define nl "\n" #define sp " " #define rep(i,n) for(i=0;i<n;i++) #define repe(i,e,n) for(i=e;i<=n;i++) #define pb push_back #define eb emplace_back #define fi first #define se second #define vl vector<ll> #define vvl vector<vl> #define pll pair<ll,ll > #define vpll vector<pll> #define vvpll vector<vpll> #define mp make_pair #define mt make_tuple #define len length() #define val(n,t) get<n>(t) #define rev(p) reverse(p.begin(),p.end()) #define all(x) x.begin(),x.end() #define deb(x) cout<<#x<<" = "<<x<<"\n"; #define sortv(vec) sort(vec.begin(),vec.end()) #define np(str) next_permutation(str.begin(),str.end()) #define mset(a,val) memset(a,val,sizeof(a)); #define popcount(x) __builtin_popcountll(x) #define ub(v,val) upper_bound(v.begin(),v.end(),val) #define lb(v,val) lower_bound(v.begin(),v.end(),val) #define np(str) next_permutation(str.begin(),str.end()) #define PI 3.14159265358979323846264338327950288419716939937510 long long int M = 1e9 + 7 ; long long int inf = 1e18 + 7; #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); //CLOCK ll begtime = clock(); #define time() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //CLOCK ENDED // modular exponentiation ll binpow(ll a, ll b) { ll res = 1; while (b > 0) { if (b % 2 == 1) res *= a; a *= a; b /= 2; } return res; } //binomial ll modinv(ll n) { return binpow(n, M - 2); } int main() { IOS; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif // ll n, m, i, j, k, l, x, y, z, t, s, tc = 1; double a, b; cin >> a >> b; double ans = a * (b / 100); cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long const int inf = 1e12; #define D long double #define NeedForSpeed ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); int MOD = 1000000007; #define fi first #define se second #define endl '\n' // random_device rd; // mt19937 rng(rd()); // int getRand(int l,int r){ // get random number in the range [l,r] // uniform_int_distribution<int> uid(l,r); // return uid(rng); // } const int N = 1e5 + 10; int n , q ; string s ; void go(){ cin >> n >> s >> q; bool f = 1; for(int i = 0 ; i < q ; i++){ int t , a , b ; cin >> t >> a >> b; if(!f){ if(a>n)a-=n;else a+=n ; if(b>n)b-=n;else b+=n ; } if(t==1){ swap(s[a-1],s[b-1]); }else{ f=f^1; } } if(!f){ for(int i = n ; i < 2*n ; i++)cout << s[i]; for(int i = 0 ; i < n ; i++)cout << s[i]; }else{ cout << s; } } signed main() { // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); NeedForSpeed int t = 1; cout << fixed << setprecision(12) ; // cin >> t; while(t--){ // cout << "Case #" << cases << ": "; go(); } }
#include <bits/stdc++.h> using namespace std; //#pragma GCC optimize("Ofast") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define ms(s, n) memset(s, n, sizeof(s)) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define FORd(i, a, b) for (int i = (a) - 1; i >= (b); --i) #define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++) #define sz(a) int((a).size()) #define present(t, x) (t.find(x) != t.end()) #define all(a) (a).begin(), (a).end() #define uni(a) (a).erase(unique(all(a)), (a).end()) #define pb push_back #define pf push_front #define mp make_pair #define fi first #define se second #define prec(n) fixed<<setprecision(n) #define bit(n, i) (((n) >> (i)) & 1) #define bitcount(n) __builtin_popcountll(n) typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pi; typedef vector<int> vi; typedef vector<pi> vii; //const int MOD = (int) 1e9 + 7; const int MOD = 119 << 23 | 1; const int FFTMOD = 119 << 23 | 1; const int INF = (int) 1e9 + 23111992; const ll LINF = (ll) 1e18 + 23111992; const ld PI = acos((ld) -1); const ld EPS = 1e-9; inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;} inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;} template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;} template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;} inline ull isqrt(ull k) {ull r = sqrt(k) + 1; while (r * r > k) r--; return r;} inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;} inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;} inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;} inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;} inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);} inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;} inline int sign(ld x, ld y) {return sign(x - y);} mt19937 mt(chrono::high_resolution_clock::now().time_since_epoch().count()); inline int mrand() {return abs((int) mt());} inline int mrand(int k) {return abs((int) mt()) % k;} #define db(x) cerr << "[" << #x << ": " << (x) << "] "; #define endln cerr << "\n"; void chemthan() { int n, m, k; cin >> n >> m >> k; vector<string> s(n); FOR(i, 0, n) FOR(j, 0, m) s[i] += "z"; FOR(i, 0, k) { int u, v; cin >> u >> v; u--, v--; cin >> s[u][v]; } vector<vi> dp(n, vi(m)); int iv = inv(3); dp[0][0] = fpow(3, n * m - k); FOR(i, 0, n) FOR(j, 0, m) { if (s[i][j] == 'R') { if (j + 1 < m) { addmod(dp[i][j + 1], dp[i][j]); } } else if (s[i][j] == 'D') { if (i + 1 < n) { addmod(dp[i + 1][j], dp[i][j]); } } else if (s[i][j] == 'X') { if (j + 1 < m) { addmod(dp[i][j + 1], dp[i][j]); } if (i + 1 < n) { addmod(dp[i + 1][j], dp[i][j]); } } else { if (j + 1 < m) { addmod(dp[i][j + 1], mult(iv, 2 * dp[i][j])); } if (i + 1 < n) { addmod(dp[i + 1][j], mult(iv, 2 * dp[i][j])); } } } cout << dp[n - 1][m - 1] << "\n"; } int32_t main(int32_t argc, char* argv[]) { ios_base::sync_with_stdio(0), cin.tie(0); if (argc > 1) { assert(freopen(argv[1], "r", stdin)); } if (argc > 2) { assert(freopen(argv[2], "wb", stdout)); } chemthan(); cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; return 0; }
#include <iostream> #include <algorithm> #include <iomanip> #include <cmath> #include <cstring> #include <stack> #include <vector> #include <map> #include <set> #include <queue> #include <algorithm> #include <unordered_map> #include <fstream> #define rep(i,a,n) for(int i=a;i<=n;i++) #define max(a,b) (a>b?a:b) #define min(a,b) (a>b?b:a) #define pb push_back typedef long long ll; using namespace std; const int mod=1e9+7; const ll N=100005; const double esp=1e-6; void debug(ll x) { cout<<111<<" "<<x<<'\n'; } ll n,m,k,tt; ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); } int main() { ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); //ifstream s("photo.in"); //ofstream c("photo.out"); //freopen("photo.in", "r", stdin); //freopen("photo.out", "w", stdout); tt=1; //cin>>tt; while(tt--) { cin>>n; string s; cin>>s; if(s[0]!=s[n-1]) cout<<1<<'\n'; else { int f=0; for(int i=1;i<=n-3;i++) if(s[i]!=s[0]&&s[i+1]!=s[n-1]) f=1; if(f) cout<<2<<'\n'; else cout<<-1<<'\n'; } } return 0; } /* */
#include<bits/stdc++.h> #define F first #define S second #define LL long long #define MP make_pair #define PB push_back #define I insert const LL mod=1000000007, N=200005; using namespace std; LL n, m, i, j, k, l, r, t, ans[N]; LL fix[N], p[N], fox[N]; vector < LL > v[N]; void go ( LL u, LL par = 0 ){ fix[u] = fix[par] + 1; p[u] = par; for ( LL i = 0; i < v[u].size(); ++i ){ if ( v[u][i] == par ) continue; go ( v[u][i], u ); } } void jo ( LL u, LL par = 0 ){ LL bb = 0; ans[u] = ++t; for ( LL i = 0; i < v[u].size(); ++i ){ if ( v[u][i] == par ) continue; if ( fox[v[u][i]] ){ bb = v[u][i]; continue; } jo(v[u][i], u); } if ( bb ){ jo ( bb, u); } ++t; } int main(){ ios_base::sync_with_stdio(false); cin >> n; for ( i = 1; i < n; ++i ){ cin >> l >> r; v[l].PB(r); v[r].PB(l); } go ( 1 ); l = 1; for ( i = 1; i <= n; ++i ){ if ( fix[l] < fix[i] ) l = i; } go ( l ); r = 1; for ( i = 1; i <= n; ++i ){ if ( fix[r] < fix[i] ) r = i; } k = r; while ( k != l ){ fox[k] = 1; k = p[k]; } t = 0; jo(l); for ( i = 1; i <= n; ++i ) cout << ans[i] << " "; return 0; } // IIIIIIIII OOOOO A NN N EEEEEEEEEE // I O O A A N N N E // I O O A A N N N E // I O O A A N N N E // I O O AAAAAAAAA N N N EEEEEEEE // I O O A A N N N E // I O O A A N N N E // I O O A A N N N E // IIIIIIIII OOOOO A A N NN EEEEEEEEEE ___ KAPANADZE
#include <bits/stdc++.h> using namespace std; #define int long long #define pi pair<int,int> #define f first #define s second #define ld long double signed main() { ios_base::sync_with_stdio(0); cin.tie(nullptr); int x,y; cin>>x>>y; if(x>y) swap(x,y); if(y-x<3) cout<<"Yes"; else cout<<"No"; // int n; // cin>>n; // vector<int> a(n); // for(int i=0;i<n;i++) // cin>>a[i]; return 0; }
#include<bits/stdc++.h> #define ll long long #define x first #define y second #define pi pair #define K 1000000007 using namespace std; ll a[2000000]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll test_case=1;//cin>>test_case; while(test_case--) { ll m,h;cin>>m>>h; if(h%m==0)cout<<"Yes"<<endl; else cout<<"No"<<endl; } return 0; }
#define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(v) v.begin(), v.end() typedef long long ll; #include <bits/stdc++.h> using namespace std; int main(){ ll b,c; cin>>b>>c; if(b==0) cout<<c<<endl; else if(b>0){ if(c==1) cout<<2<<endl; else if(c==2) cout<<3<<endl; else cout<<c-1+min(2*b,c)<<endl; } else{ if(c==1) cout<<2<<endl; else if(c==2) cout<<3<<endl; else cout<<c+min(2*(-b),c)<<endl; } return 0; }
#include "bits/stdc++.h" #define rep(i,a,n) for(int i=a;i<=n;i++) #define per(i,a,n) for(int i=n;i>=a;i--) #define pb push_back #define mp make_pair #define FI first #define SE second #define maxn 200000 #define mod 1000000007 #define inf 0x3f3f3f3f 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 namespace std; typedef long long ll; typedef pair<int,int> pii; typedef vector<int> vi; typedef double db; int main() { ll B,C; scanf("%lld%lld",&B,&C); vector<pair<ll,ll>> s; s.pb({B-C/2,B}); s.pb({-B,-B+(C-1)/2}); s.pb({-B-(C-1)/2,-B}); if(C>=2) s.pb({B,B+(C-2)/2}); sort(s.begin(),s.end()); ll rt=-8e18,ans=0; for(auto [l,r]: s) { if(r>rt) { if(l>rt) ans+=r-l+1; else ans+=r-rt; rt=r; } } printf("%lld\n",ans); return 0; }
#include "bits/stdc++.h" using namespace std; #define int long long using ll = long long; using P = pair<ll, ll>; const ll INF = (1LL << 61); ll mod = 998244353; 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 { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod - 2); } mint& operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } }; istream& operator>>(istream& is, mint& a) { return is >> a.x; } ostream& operator<<(ostream& os, const mint& a) { return os << a.x; } signed main() { ios::sync_with_stdio(false); cin.tie(0); ll N, M, K; cin >> N >> M >> K; if (N == 1) { mint ans = mint(K).pow(M); cout << ans << endl; return 0; } if(M == 1){ mint ans = mint(K).pow(N); cout << ans << endl; return 0; } mint ans = 0; for (int i = 1; i <= K; i++) { mint now = 0; now = mint(i).pow(N) - mint(i - 1).pow(N); now *= mint(K - i + 1).pow(M); ans += now; } cout << ans << endl; return 0; }
#line 2 "/Users/kaage/Desktop/ProgrammingWorkspace/library/other/template.hpp" #define _CRT_SECURE_NO_WARNINGS #pragma target("avx2") #pragma optimize("O3") #pragma optimize("unroll-loops") #include <string.h> #include <algorithm> #include <bitset> #include <cassert> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <memory> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define rep(i, n) for (int i = 0; i < (n); i++) #define REP(i, n) for (int i = 1; i <= (n); i++) #define all(V) V.begin(), V.end() typedef unsigned int uint; typedef long long lint; typedef unsigned long long ulint; typedef std::pair<int, int> P; typedef std::pair<lint, lint> LP; constexpr int INF = INT_MAX / 2; constexpr lint LINF = LLONG_MAX / 2; constexpr double eps = DBL_EPSILON; constexpr double PI = 3.141592653589793238462643383279; template <class T> class prique : public std::priority_queue<T, std::vector<T>, std::greater<T>> { }; template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return true; } return false; } template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return true; } return false; } inline lint gcd(lint a, lint b) { while (b) { lint c = a; a = b; b = c % b; } return a; } inline lint lcm(lint a, lint b) { return a / gcd(a, b) * b; } bool isprime(lint n) { if (n == 1) return false; for (int i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return true; } template <typename T> T mypow(T a, lint b) { T res(1); while (b) { if (b & 1) res *= a; a *= a; b >>= 1; } return res; } lint modpow(lint a, lint b, lint m) { lint res(1); while (b) { if (b & 1) { res *= a; res %= m; } a *= a; a %= m; b >>= 1; } return res; } template <typename T> void printArray(std::vector<T>& vec) { rep(i, vec.size()) { std::cout << vec[i]; std::cout << (i == (int)vec.size() - 1 ? "\n" : " "); } } template <typename T> void printArray(T l, T r) { T rprev = std::prev(r); for (T i = l; i != r; i++) { std::cout << *i; std::cout << (i == rprev ? "\n" : " "); } } LP extGcd(lint a, lint b) { if (b == 0) return {1, 0}; LP s = extGcd(b, a % b); std::swap(s.first, s.second); s.second -= a / b * s.first; return s; } LP ChineseRem(const lint& b1, const lint& m1, const lint& b2, const lint& m2) { lint p = extGcd(m1, m2).first; lint tmp = (b2 - b1) * p % m2; lint r = (b1 + m1 * tmp + m1 * m2) % (m1 * m2); return std::make_pair(r, m1 * m2); } template <typename F> inline constexpr decltype(auto) lambda_fix(F&& f) { return [f = std::forward<F>(f)](auto&&... args) { return f(f, std::forward<decltype(args)>(args)...); }; } template <typename T> std::vector<T> make_vec(size_t n) { return std::vector<T>(n); } template <typename T, class... Args> auto make_vec(size_t n, Args&&... args) { return std::vector<decltype(make_vec<T>(args...))>( n, make_vec<T>(std::forward<Args>(args)...)); } #line 2 "main.cpp" int N; int main() { std::cin >> N; lint res = 1; REP(i, N) res = lcm(res, i); std::cout << res + 1 << std::endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++) #define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--) #define all(v) v.begin(), v.end() void chmax(ll &x, ll y) {x = max(x,y);} void chmin(ll &x, ll y) {x = min(x,y);} int main() { ll N, M; cin >> N >> M; vector<pair<ll,ll>> m(M); rep(i,M) { ll a, b; cin >> a >> b; a--; b--; m[i] = {a,b}; } ll K; cin >> K; vector<pair<ll,ll>> k(K); rep(i,K) { ll c, d; cin >> c >> d; c--; d--; k[i] = {c,d}; } ll ans = 0; rep(bit,1<<K) { vector<ll> vec(N); rep(i,K) { ll x = k[i].first, y = k[i].second; if ((bit>>i)&1) vec[x]++; else vec[y]++; } ll cnt = 0; rep(i,M) { ll x = m[i].first, y = m[i].second; if (vec[x]>=1 && vec[y]>=1) cnt++; } ans = max(ans,cnt); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main () { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int T = 1; //~ cin >> T; for (int test_case = 1; test_case <= T; ++test_case) { int n,m; cin >> n >> m; pair<int,int> a[m + 1]; for (int i = 1; i <= m; ++i) cin >> a[i].first >> a[i].second; int k; cin >> k; pair<int,int> b[k + 1]; int res = 0; for (int i = 1; i <= k; ++i) cin >> b[i].first >> b[i].second; for (int bit = 0; bit < (1 << k); ++bit) { int count[n + 1]; for (int i = 1; i <= n; ++i) count[i] = 0; for (int i = 1; i <= k; ++i) { if (bit & (1 << (i - 1))) { ++count[b[i].second]; } else { ++count[b[i].first]; } } int total = 0; for (int i = 1; i <= m; ++i) { total += (count[a[i].first] and count[a[i].second]); } res = max(res,total); } cout << res << '\n'; } //cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n'; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=1;i<=n;++i) #define mp make_pair #define pb push_back #define rep(i,n) for(int i=1;i<=n;++i) #define size sze typedef long long LL; const int pri[15]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47}; int n; int a[100]; int main() { cin>>n; for(int i=1;i<=n;i++)scanf("%d",&a[i]); long long ans=-1; for(int i=0;i<(1<<15);i++) { long long ret=1; for(int j=0;j<15;j++) if ((1<<j)&i)ret=ret*pri[j]; int flag=1; for(int i=1;i<=n;i++) if (__gcd(1ll*a[i],ret)==1)flag=0; if (!flag)continue; if (ans==-1 || ans>ret)ans=ret; } cout<<ans<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; const int MAX = 200010; bool is[MAX]; int main(){ int N; cin >> N; int ans = 0; for(int i=0; i<N; i++){ int x; cin >> x; is[x] = true; while(is[ans]){ ans++; } cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int solve(int h, int w, vector<string> s) { int res = 0; for(int i = 0; i < h - 1; i++) { for(int j = 0; j < w - 1; j++) { int black = 0; if(s[i][j] == '#') black++; if(s[i][j + 1] == '#') black++; if(s[i + 1][j] == '#') black++; if(s[i + 1][j + 1] == '#') black++; if(black == 1 || black == 3) { //cout << "i: " << i << " J " << j << " -> " << black <<endl; res++; } } } return res; } int main() { int h, w; cin >> h >> w; vector<string> s(h); for(int i = 0; i < h; i++) { cin >> s[i]; } cout << solve(h, w, s) << endl; }
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int(i)=0;i<(n);i++) int main(){ int h,w,ans=0; vector<string> s(11); cin>>h>>w; REP(i,h) cin>>s.at(i); REP(i,h) REP(j,w){ if(s.at(i).at(j)=='#'){ int dx[4]={-1,0,1,0},dy[4]={0,1,0,-1}; bool f[4]={0,0,0,0}; REP(k,4){ if(s.at(i+dy[k]).at(j+dx[k])=='.'){ ans++; f[k]=1; } } if(s.at(i).at(j+1)=='#') REP(k,4){ if(s.at(i+dy[k]).at(j+1+dx[k])=='.'&&f[k]) ans--; } if(s.at(i+1).at(j)=='#') REP(k,4){ if(s.at(i+1+dy[k]).at(j+dx[k])=='.'&&f[k]) ans--; } } } cout<<ans<<endl; }
//yukicoder@cpp14 //coder:luckYrat(twitter:@luckYrat_) //dijkstraから逃げるな //おすすめの曲 //https://soundcloud.com/nagiha/alice-in-a-xxxxxxxx //https://soundcloud.com/synthion/sweetheart //せんげん! #include <iostream> #include <cmath> #include <algorithm> #include <iomanip> #include <string> #include <vector> #include <set> #include <stack> #include <queue> #include <map> #include <bitset> #include <cctype> #include <utility> #include <climits> //なまえくーかん! using namespace std; using ll = long long; using P = pair<ll,ll>; //てーすう! const int mod = 1000000007; const int inf = (1<<30)-1; const ll linf = (1LL<<62LL)-1; const double EPS = (1e-10); //でふぁいん! #define anyfill(n,s) setw(n) << setfill(s) #define loop(s) for(int i = 0; s > i; i++) #define rep(i,q) for(int i = 0; (q) > i; i++) #define repp(i,n,q) for(int i = n; (q) > i; i++) #define dep(i,q) for(int i = (q); 0 < i; i--) //みじかく! #define pb push_back #define mkp make_pair #define fir first #define scn second #define ednl endl //いぇすのー! #define YesNo(a) (a?"Yes":"No") #define YESNO(a) (a?"YES":"NO") #define yesno(a) (a?"yes":"no") //きんぼーnほーこー!! P ar4[4] = {mkp(0,1),mkp(0,-1),mkp(1,0),mkp(-1,0)}; P ar8[8] = {mkp(-1,-1),mkp(-1,0),mkp(-1,1),mkp(0,-1),mkp(0,1),mkp(1,-1),mkp(1,0),mkp(1,1)}; /* 確認ポイント cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる 計算量は変わらないが楽できるシリーズ min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる */ __attribute__((constructor)) void initial() { cin.tie(0); ios::sync_with_stdio(false); } int main(){ int n;cin>>n; vector<int> A(n); for(int i = 0; n > i; i++){ cin>>A[i]; } sort(A.begin(),A.end()); for(int i = 1; n >= i; i++){ if(A[i-1] != i){ cout << "No" << endl; return 0; } } cout << "Yes" << endl; return 0; }
#include<bits/stdc++.h> using namespace std; int n, x[50]; int prime[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47}; int gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> x[i]; long long ans = 0x3f3f3f3f3f3f3f3f; for (int i = 0; i < (1<<15); i++) { long long val = 1; for (int j = 0; j < 15; j++) if (i & (1<<j)) val *= prime[j]; bool flag = 1; for (int j = 1; j <= n; j++) if (gcd(val, x[j]) == 1) flag = 0; if (flag) ans = min(ans, val); } cout << ans << endl; }
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<cmath> #include<vector> #include<queue> #include<stack> #include<map> #define ll long long #define MAXN 300005 #define uns unsigned #define INF 0x3f3f3f3f 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 n,s; int main() { n=read(),s=n; for(int b=0;(1ll<<b)<=n;b++){ ll B=(1ll<<b),a=n/B,c=n-a*B; s=min(s,a+b+c); } printf("%lld\n",s); return 0; }
#include <bits/stdc++.h> using namespace std; long long diff; map<long long, long long> dp; long long fun(long long n, long long m) { if(n>=m) return dp[m] = (n-m); long long res=m-n; if(m%2) { long long r1, r2; if(!dp[m-1]) r1 = fun(n, m-1); else r1 = dp[m-1]; if(!dp[m+1]) r2 = fun(n, m+1); else r2 = dp[m+1]; res = min(res, 1+min(r1, r2)); } else { long long r3; if(!dp[m/2]) r3 = fun(n, m/2); else r3 = dp[m/2]; res = min(res, 1+r3); } return dp[m] = res; } int main() { long long n, m; cin >> n >> m; long long res = fun(n, m); cout << res; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; const int maxn=1e6+5; //const int mod = 1000000007; const int mod = 998244353; template<long long MOD> struct ModInt{ using ll = long long; ll val; void setval(ll v) { val = v % MOD; }; ModInt(): val(0) {} ModInt(ll v) { setval(v); }; ModInt operator+(const ModInt &x) const { return ModInt(val + x.val); } ModInt operator-(const ModInt &x) const { return ModInt(val - x.val + MOD); } ModInt operator*(const ModInt &x) const { return ModInt(val * x.val); } ModInt operator/(const ModInt &x) const { return *this * x.inv(); } ModInt operator-() const { return ModInt(MOD - val); } ModInt operator+=(const ModInt &x) { return *this = *this + x; } ModInt operator-=(const ModInt &x) { return *this = *this - x; } ModInt operator*=(const ModInt &x) { return *this = *this * x; } ModInt operator/=(const ModInt &x) { return *this = *this / x; } bool operator==(const ModInt &x) const { return (*this).val == x.val; } friend ostream& operator<<(ostream &os, const ModInt &x) { os << x.val; return os; } friend istream& operator>>(istream &is, ModInt &x) { is >> x.val; x.val = (x.val % MOD + MOD) % MOD; return is; } ModInt pow(ll n) const { ModInt a = 1; if(n == 0) return a; int i0 = 64 - __builtin_clzll(n); for(int i = i0 - 1; i >= 0; i--){ a = a * a; if((n >> i) & 1) a *= (*this); } return a; } ModInt inv() const { return this->pow(MOD - 2); } }; using mint = ModInt<mod>; mint pow(mint x, long long n) { return x.pow(n); } int main() { int T;cin>>T;while(T--) { ll n;cin>>n; int cnt=0; while(n%2==0) n/=2,cnt++; if(cnt==0) cout<<"Odd"; else if(cnt==1) cout<<"Same"; else cout<<"Even"; cout<<endl; } return 0; }
#include<iostream> using namespace std; int main(){ int T; cin >> T; long long j, c[T]; for(int i = 0; i < T; i++){ cin >> j; c[i] = j; } for(int i = 0; i < T; i++){ if(c[i] % 2 != 0){ cout << "Odd\n"; } else if(c[i] % 4 == 0){ cout << "Even\n"; } else { cout << "Same\n"; } } }
#include<bits/stdc++.h> using namespace std; #define ll long long #define ld long double //#define mn LLONG_MAX //#define mx LLONG_MIN #define mod 1000000007 #define f(i,a,b) for(ll i=a;i<b;i++) #define pb(a) push_back(a) ll prime[][2]={{0,0},{2,3},{11,13},{101,103},{1009,1013}, {10007,10009},{100003,100013},{1000003,1000033},{10000019,10000079},{100000007,100000037}}; ll arr[]={0,1,10,100,1000,10000,100000,1000000,10000000,100000000,100000000,1000000000}; bool sortbysec(const pair<ll,ll>&a,const pair<ll,ll>&b){ return (a.second<b.second); } bool ff(const pair<int ,int>&a,const pair<int,int>&b)//sorting a parir of first element increasing wise and if they are equal second element in decreasing wise {if(a.first==b.first) return (a.second>b.second); else return (a.first<b.first);} ll fact(ll n){ ll ans=1; while(n>0){ ans*=n; n--; } return ans; } void primme(ll n){ vector<ll>v(n,0); for(ll i=2;i<=n;i++){ if(v[i]==0){ for(ll j=i*i;j<=n;j+=i){ v[j]=1; } }} for(ll i=2;i<=n;i++) if(v[i]==0) cout<<i<<" "; cout<<"\n"; } void solve(){ ll n; cin>>n; ll a[n],i; map<ll,ll>m; for(i=0;i<n;i++){ cin>>a[i]; m[a[i]]++; } while(n){ if(m[n]!=1) { cout<<"No\n"; return; } --n; } cout<<"Yes\n"; } int main() { int t=1; // cin>>t; while(t--) solve(); }
#include <bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; vector<bool> t(n,false); bool ans = true; for(int i=0; i<n; i++){ int a; cin >> a; if(t[a-1]) ans = false; t[a-1] = true; } if(ans) cout << "Yes" << endl; else cout << "No" << endl; }
#define DEBUG 0 #include <bits/stdc++.h> #define all(v) (v).begin(), (v).end() #define pb push_back #define rep(i,n) for(int i=0; i<(n); i++) #define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--) #define REP(i, begin, end) for(int i = int(begin); i < int(end); i++) using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; template<class T>using numr=std::numeric_limits<T>; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } const int INF = 1e9; const ll LLINF = 1e16; const int mod = 1000000007; const int mod2 = 998244353; void debug_impl() { std::cerr << std::endl; } template <typename Head, typename... Tail> void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); } #if DEBUG #define debug(...)\ do {\ std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\ debug_impl(__VA_ARGS__);\ std::cerr << std::noboolalpha;\ } while (false) #else #define debug(...) {} #endif template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr> std::istream& operator>> (std::istream& is, Container& v) { for (auto & x : v) { is >> x; } return is; } template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr > std::ostream& operator<< (std::ostream& os, Container const& v) { os << "{"; for (auto it = v.begin(); it != v.end(); it++) {os << (it != v.begin() ? "," : "") << *it;} return os << "}"; } // UF木 struct UnionFind { vector< int > data; UnionFind() = default; explicit UnionFind(size_t sz) : data(sz, -1) {} bool unite(int x, int y) { x = find(x), y = find(y); if(x == y) return false; if(data[x] > data[y]) swap(x, y); data[x] += data[y]; data[y] = x; return true; } int find(int k) { if(data[k] < 0) return (k); return data[k] = find(data[k]); } int size(int k) { return -data[find(k)]; } bool same(int x, int y) { return find(x) == find(y); } }; int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); int n,m; cin >> n >> m; vector<ll> a(n); cin >> a; vector<ll> b(n); cin >> b; UnionFind uf(n); rep(i,m){ int c,d; cin >> c >> d; c--;d--; uf.unite(c, d); } vector<ll> ans(n), res(n); rep(i,n){ ll num = uf.find(i); ans[num] += a[i]; res[num] += b[i]; } rep(i,n){ if(ans[i] != res[i]){ cout << "No\n"; return 0; } } cout << "Yes" << endl; }
#include <bits/stdc++.h> using namespace std; #define ffor(i, a, b) for (int i = a ; i <= (int) b ; i++) #define rfor(i, a, b) for (int i = (int) a ; i >= b ; i--) #define vec vector #define PB push_back #define MP make_pair #define MT make_tuple #define F first #define S second using ll = long long int; // watch out for overflows in your code using pii = pair<int,int>; //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void debug() { cout << "\n"; }; template <typename T, typename... Targs> void debug(T t, Targs... args) { cout << t << " "; debug(args...); } template <typename T1, typename T2> inline ostream& operator << (ostream& os, const pair<T1,T2>& p) { return os << "(" << p.F << ", " << p.S << ")"; } template <typename T> inline ostream& operator << (ostream& os, const vec<T>& v) { for(auto& t : v) { os << t << " "; } return os; } template <typename T> inline ostream& operator << (ostream& os, const vec<vec<T>>& m) { for(auto& v : m) { for(auto& t : v) { os << t << " "; } os << "\n"; } return os; } template <typename T> inline ostream& operator << (ostream& os, const set<T>& v) { for(auto& t : v) { os << t << " "; } return os; } template <typename K, typename V> inline ostream& operator << (ostream& os, const map<K,V>& m) { for(auto& p : m) { os << p.F << " -> " << p.S << "\n"; } return os; } const ll INF = 9 * 1e18; int N; vec<ll> lo, hi; ll dist(ll st, ll fn, ll x) { return abs(x-st) + abs(st-fn); } vec<vec<ll>> dp; void compute_dp() { dp.assign(N+1, vec<ll>(2,0)); ffor(c, 1, N) { if(lo[c] == lo[c-1] && hi[c] == hi[c-1]) { dp[c][0] = dp[c-1][0]; dp[c][1] = dp[c-1][1]; } else { dp[c][0] = min(dp[c-1][0] + dist(hi[c], lo[c], lo[c-1]), dp[c-1][1] + dist(hi[c], lo[c], hi[c-1])); dp[c][1] = min(dp[c-1][0] + dist(lo[c], hi[c], lo[c-1]), dp[c-1][1] + dist(lo[c], hi[c], hi[c-1])); } } } //////////////////////////////////////////////////////////////////////// int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> N; lo.assign(N+1, INF); hi.assign(N+1, -INF); lo[0] = hi[0] = 0; ffor(i, 1, N) { ll x; int c; cin >> x >> c; lo[c] = min(lo[c], x); hi[c] = max(hi[c], x); } ffor(c, 1, N) { if(lo[c] == INF) lo[c] = lo[c-1]; if(hi[c] == -INF) hi[c] = hi[c-1]; } compute_dp(); cout << min(dp[N][0] + abs(lo[N]), dp[N][1] + abs(hi[N])) << "\n"; }
//#include <atcoder/all> #include <bits/stdc++.h> //using namespace atcoder; using namespace std; typedef long long ll; #define MOD (long long)(1e9+7) #define INF (1LL<<60) #define rep(i,n) for(ll i = 0; i < (n); i++) #define rep1(i,n) for(ll i = 1; i <= (n); i++) template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } // 最大公約数 ll gcd(ll a, ll b) { if(b == 0) return a; return gcd(b, a % b); } // mod m におけるa の逆元 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; } // 素因数分解 vector<pair<ll, ll>> prim; void pf(ll n) { ll s = sqrt(n); ll r = 0; for(ll i = 2; i <= s; i++) { if((n % i) == 0) { r = 0; do { r++; n = n / i; } while((n % i) == 0); prim.push_back({i, r}); } } if(n > s) { prim.push_back({n, 1}); } } // 2項係数 /* ll ncrmod(ll n, ll r) { ll ans; return ans; } */ // 繰り返し二乗法 ll powmod(int a, int n){//aのn乗を計算します(MOD)。 ll x = 1; while(n > 0){//全てのbitが捨てられるまで。 if(n&1){//1番右のbitが1のとき。 x = (x*a) % MOD; } a = (a*a) % MOD; n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。 } return x; } ll f(ll a, ll b) { ll ret; if(a > b) ret = a * 1000000 + b; else ret = b * 1000000 + a; return ret; } void solve() { ll N; cin >> N; vector<ll> x(N), y(N); rep(i, N) cin >> x[i] >> y[i]; vector<pair<ll,ll>> x1; vector<pair<ll,ll>> y1; rep(i, N) { x1.push_back({x[i], i}); y1.push_back({y[i], i}); } sort(x1.begin(), x1.end()); sort(y1.begin(), y1.end()); vector<pair<ll,ll>> m; m.push_back({x1[N-1].first-x1[0].first, f(x1[N-1].second, x1[0].second)}); m.push_back({x1[N-2].first-x1[0].first, f(x1[N-2].second, x1[0].second)}); m.push_back({x1[N-1].first-x1[1].first, f(x1[N-1].second, x1[1].second)}); m.push_back({y1[N-1].first-y1[0].first, f(y1[N-1].second, y1[0].second)}); m.push_back({y1[N-2].first-y1[0].first, f(y1[N-2].second, y1[0].second)}); m.push_back({y1[N-1].first-y1[1].first, f(y1[N-1].second, y1[1].second)}); sort(m.rbegin(), m.rend()); if(m[0].second != m[1].second) { cout << m[1].first << endl; } else { cout << m[2].first << endl; } } int main(void) { // ll t; cin >> t; rep(i, t) solve(); }
#include <bits/stdc++.h> using namespace std; #define vi vector<int> #define ff first #define ss second #define pb push_back #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define ps(x) fixed << setprecision(10) << x #define mod 1000000007 #define inf 1e18 #define w(tc) int tc; cin >> tc; for (int i = 1; i <= tc; ++i) #define PI 3.14159265358979323846264338327950L #define span(a) begin(a), end(a) #define ll long long const int N = 109; double dp[N][N][N]; double calc(int a, int b, int c) { if (a >= 100 or b >= 100 or c >= 100) return 0; if (dp[a][b][c] >= 0) return dp[a][b][c]; double tot = a + b + c; dp[a][b][c] = 1 + a / tot * calc(a + 1, b, c) + b / tot * calc(a, b + 1, c) + c / tot * calc(a, b, c + 1); return dp[a][b][c]; } inline void solve() { memset(dp, -1, sizeof(dp)); int a, b, c; cin >> a >> b >> c; double ans = calc(a, b, c); cout << ps(ans); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //w(tc) solve(); return 0; }
#include <iostream> #include <algorithm> #include <map> #include <set> #include <queue> #include <bitset> #include <climits> #include <cmath> #include <complex> #include <functional> #include <cassert> #include <stack> #include <numeric> #include <iomanip> #include <limits> #include <random> #include <unordered_set> #include <chrono> typedef int64_t ll; typedef std::pair<int, int> Pii; typedef std::pair<ll, ll> Pll; typedef std::pair<double, double> Pdd; #define rip(_i, _n, _s) for (int _i = (_s); _i < (int)(_n); _i++) #define all(_l) _l.begin(), _l.end() #define rall(_l) _l.rbegin(), _l.rend() #define MM << " " << template<typename _T> using MaxHeap = std::priority_queue<_T>; template<typename _T> using MinHeap = std::priority_queue<_T, std::vector<_T>, std::greater<_T>>; template<typename _T> inline bool chmax(_T &_l, const _T _b) { if (_l < _b) { _l = _b; return true; } return false; } template<typename _T> inline bool chmin(_T &_l, const _T _b) { if (_l > _b) { _l = _b; return true; } return false; } template<typename _T> void vdeb(const std::vector<_T> &bb) { for (unsigned int i = 0;i < bb.size();i++) { if (i == bb.size() - 1) std::cout << bb[i]; else std::cout << bb[i] << ' '; } std::cout << '\n'; } template<typename _T> void vdeb(const std::vector<std::vector<_T>> &bb) { for (unsigned int i = 0;i < bb.size();i++) { // std::cout << i << ' '; vdeb(bb[i]); } std::cout << '\n'; } using namespace std; void solve() { int n; cin >> n; vector<int> da(n); rip(i,n,0) cin >> da[i]; vector<int> ans; int c = 0; while(1) { int flg = 0; for(int i = n-2; i >= 0; i--) { if((i^c^1)&1) { if(da[i] > da[i+1]) { ans.push_back(i+1); swap(da[i], da[i+1]); flg = 1; break; } } else { if(da[i] > da[i+1]) { flg = 2; } } } if(flg == 2) { if((c&1) == 1) { swap(da[1], da[2]); ans.push_back(2); } else { swap(da[1], da[0]); ans.push_back(1); } } else if(flg == 0){ break; } c++; } cout << ans.size() << endl; vdeb(ans); } int main() { int t; cin >> t; rip(i,t,0) solve(); }
#pragma GCC optimize ("Ofast") #include<bits/stdc++.h> using namespace std; inline int my_getchar_unlocked(){ static char buf[1048576]; static int s = 1048576; static int e = 1048576; if(s == e && e == 1048576){ e = fread_unlocked(buf, 1, 1048576, stdin); s = 0; } if(s == e){ return EOF; } return buf[s++]; } inline void rd(int &x){ int k; int m=0; x=0; for(;;){ k = my_getchar_unlocked(); if(k=='-'){ m=1; break; } if('0'<=k&&k<='9'){ x=k-'0'; break; } } for(;;){ k = my_getchar_unlocked(); if(k<'0'||k>'9'){ break; } x=x*10+k-'0'; } if(m){ x=-x; } } inline void rd(char &c){ int i; for(;;){ i = my_getchar_unlocked(); if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){ break; } } c = i; } inline int rd(char c[]){ int i; int sz = 0; for(;;){ i = my_getchar_unlocked(); if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){ break; } } c[sz++] = i; for(;;){ i = my_getchar_unlocked(); if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){ break; } c[sz++] = i; } c[sz]='\0'; return sz; } struct MY_WRITER{ char buf[1048576]; int s; int e; MY_WRITER(){ s = 0; e = 1048576; } ~MY_WRITER(){ if(s){ fwrite_unlocked(buf, 1, s, stdout); } } } ; MY_WRITER MY_WRITER_VAR; void my_putchar_unlocked(int a){ if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){ fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout); MY_WRITER_VAR.s = 0; } MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a; } inline void wt_L(char a){ my_putchar_unlocked(a); } inline void wt_L(int x){ int s=0; int m=0; char f[10]; if(x<0){ m=1; x=-x; } while(x){ f[s++]=x%10; x/=10; } if(!s){ f[s++]=0; } if(m){ my_putchar_unlocked('-'); } while(s--){ my_putchar_unlocked(f[s]+'0'); } } inline void wt_L(long long x){ int s=0; int m=0; char f[20]; if(x<0){ m=1; x=-x; } while(x){ f[s++]=x%10; x/=10; } if(!s){ f[s++]=0; } if(m){ my_putchar_unlocked('-'); } while(s--){ my_putchar_unlocked(f[s]+'0'); } } template<class T> inline T popFirst(multiset<T> &a){ T res = *(a.begin()); a.erase(a.begin()); return res; } template<class T> inline T getFirst(multiset<T> &a){ return *(a.begin()); } template<class T> inline T popFirst(set<T> &a){ T res = *(a.begin()); a.erase(a.begin()); return res; } template<class T> inline T getFirst(set<T> &a){ return *(a.begin()); } int N; char S[500000+2]; char T[500000+2]; int main(){ int i; int x; int y; long long res = 0; set<int> ss; set<int> tt; rd(N); rd(S); rd(T); for(i=(0);i<(N);i++){ if(S[i]=='1'){ ss.insert(i); } } for(i=(0);i<(N);i++){ if(T[i]=='1'){ tt.insert(i); } } while(ss.size() || tt.size()){ if(ss.size()==0){ wt_L(-1); wt_L('\n'); return 0; } if(tt.size()==0 || getFirst(ss) < getFirst(tt)){ if(ss.size()==1){ wt_L(-1); wt_L('\n'); return 0; } x = popFirst(ss); y = popFirst(ss); res += y - x; continue; } else{ x = popFirst(ss); y = popFirst(tt); res += x - y; } } wt_L(res); wt_L('\n'); return 0; } // cLay varsion 20201115-1 // --- original code --- // int N; // char S[5d5+2], T[5d5+2]; // { // int x, y; // ll res = 0; // set<int> ss, tt; // rd(N,S,T); // rep(i,N) if(S[i]=='1') ss.insert(i); // rep(i,N) if(T[i]=='1') tt.insert(i); // while(ss.size() || tt.size()){ // if(ss.size()==0) wt(-1), return 0; // if(tt.size()==0 || getFirst(ss) < getFirst(tt)){ // if(ss.size()==1) wt(-1), return 0; // x = popFirst(ss); // y = popFirst(ss); // res += y - x; // continue; // } else { // x = popFirst(ss); // y = popFirst(tt); // res += x - y; // } // } // wt(res); // }
#include <bits/stdc++.h> #define ll long long #define str string #define pii pair<int, int> #define pll pair<ll, ll> #define fi first #define se second #define vc vector<char> #define vvc vector<vc> #define vi vector<int> #define vll vector<ll> #define vvi vector<vi> #define vvll vector<vll> #define vvvll vector<vvll> #define vs vector<str> #define vvs vector<vs> #define vpii vector<pii> #define vvpii vector<vpii> #define vpll vector<pll> #define vvpll vector<vpll> #define vb vector<bool> #define vvb vector<vb> #define rep(i, a, b) for (int i = (a); i < int(b); i++) #define repi(i, a, b) for (int i = (a); i <= int(b); i++) using namespace std; ll INF = LONG_LONG_MAX; ll mod = 1000000000 + 7; template <typename T, typename L> void read(vector<T> & _data, L & _size, bool _shift) { _data.resize(_size + (ll)_shift); for (ll i = (ll)_shift; i < _size + (ll)_shift; i++) cin >> _data[i]; } template <typename T, typename L> void read(vector<vector<T>> & _data, L & _rows, L & _cols, bool _shiftRows, bool _shiftCols) { _data.resize(_rows + (ll)_shiftRows); for (ll i = 0; i < _rows + (ll)_shiftRows; i++) _data[i].resize(_cols + (ll)_shiftCols); for (ll i = (ll)_shiftRows; i < _rows + (ll)_shiftRows; i++) for (ll j = (ll)_shiftCols; j < _cols + (ll)_shiftCols; j++) cin >> _data[i][j]; } template <typename T> void write(vector<T> & _data, bool _shift) { for (ll i = (ll)_shift; i < _data.size(); i++) cout << _data[i] << " "; cout << endl; } //TODO: SOLUTION char playGame(str & s, int l, int r) { if (l == r) return s[l]; char w1 = playGame(s, l, (l + r) / 2); char w2 = playGame(s, (l + r) / 2 + 1, r); if (w1 == 'R') { if (w2 == 'P') return w2; else return w1; } if (w1 == 'P') { if (w2 == 'S') return w2; else return w1; } if (w1 == 'S') { if (w2 == 'R') return w2; else return w1; } return w1; } void solve() { int n, k; cin >> n >> k; str s; cin >> s; if (k <= 15) { str w; while (w.size() < pow(2, k)) w += s; cout << playGame(w, 0, pow(2, k) - 1); return; } int played = 0; while (played < k) { str a; s += s; for (int i = 0; i < n; i++) a.push_back(playGame(s, 2*i, 2*i + 1)); s = a; played++; } cout << s[0] << endl; } int main() { // TODO: Set value of this variable manually bool _multipleTestCases = false; if (_multipleTestCases) { ll t; cin >> t; while (t--) solve(); } else { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) char win[256][256]; int main() { // editorial // 区間長2nの隣同士の対戦結果から // 区間長nの列を生成 win['R']['R'] = win['R']['S'] = win['S']['R'] = 'R'; win['P']['P'] = win['P']['R'] = win['R']['P'] = 'P'; win['S']['S'] = win['S']['P'] = win['P']['S'] = 'S'; int n, k; string s; cin >> n >> k >> s; rep(x, k) { string t = s + s; rep(i, n) { int a = t[i * 2], b = t[i * 2 + 1]; s[i] = win[a][b]; } } cout << s[0] << "\n"s; return 0; }
#include<bits/stdc++.h> using namespace std; using ll = long long; const long long INF = 1LL << 60; struct Edge { int to; pair<ll,ll>w; Edge(int to, pair<ll,ll> w) : to(to), w(w) {} }; using Graph = vector<vector<Edge>>; template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } else return false; } int main() { int N, M, s; cin >> N >> M; s=0; Graph G(N); for (int i = 0; i < M; ++i) { int a, b;cin>>a>>b;a--;b--; ll w,d; cin>>w>>d; G[a].push_back(Edge(b, {w,d})); G[b].push_back(Edge(a,{w,d})); } // ダイクストラ法 vector<long long> dist(N, INF); dist[s] = 0; // (d[v], v) のペアを要素としたヒープを作る priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> que; que.push(make_pair(dist[s], s)); // ダイクストラ法の反復を開始 while (!que.empty()) { // v: 使用済みでない頂点のうち d[v] が最小の頂点 // d: v に対するキー値 int v = que.top().second; long long d = que.top().first; que.pop(); // d > dist[v] は,(d, v) がゴミであることを意味する if (d > dist[v]) continue; // 頂点 v を始点とした各辺を緩和 for (auto e : G[v]) { for(int t=(int)sqrt(e.w.second)-2;t<=(int)sqrt(e.w.second)+2;t++){ if(t<0)continue; if(dist[v]<=t){ if (chmin(dist[e.to], t + e.w.first+e.w.second/(t+1))) { // 更新があるならヒープに新たに挿入 que.push(make_pair(dist[e.to], e.to)); } } else{ if (chmin(dist[e.to], dist[v] + e.w.first+e.w.second/(dist[v]+1))) { // 更新があるならヒープに新たに挿入 que.push(make_pair(dist[e.to], e.to)); } } } } } // 結果出力 if (dist[N-1] < INF) cout << dist[N-1] << endl; else cout << -1 << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mp make_pair #define nline "\n" const ll M1=1e9+7; const ll M=998244353; const ll N=100005; const ll INF_ADD=1e18; const ll INF_MUL=1e13; #define f first #define s second #define pll pair<ll,ll> #ifndef ONLINE_JUDGE #define debug(x) cerr<<#x<<" "; _print(x); cerr<<nline; #else #define debug(x); #endif void _print(ll x){cerr<<x;} template<class T,class V> void _print(pair<T,V> p) {cerr<<"{"; _print(p.first);cerr<<","; _print(p.second);cerr<<"}";} template<class T>void _print(vector<T> v) {cerr<<" [ "; for (T i:v){_print(i);cerr<<" ";}cerr<<"]";} template<class T>void _print(set<T> v) {cerr<<" [ "; for (T i:v){_print(i); cerr<<" ";}cerr<<"]";} template<class T>void _print(multiset<T> v) {cerr<< " [ "; for (T i:v){_print(i);cerr<<" ";}cerr<<"]";} template<class T,class V>void _print(map<T, V> v) {cerr<<" [ "; for(auto i:v) {_print(i);cerr<<" ";} cerr<<"]";} //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ll optimal(ll x,ll t){ ll sq=sqrt(x); set<ll> comp; comp.insert(t+x/(t+1)); if(sq>t) comp.insert(sq+x/(sq+1)); sq++; if(sq>t) comp.insert(sq+x/(sq+1)); sq++; if(sq>t) comp.insert(sq+x/(sq+1)); sq=sqrt(x); sq--; if(sq>t) comp.insert(sq+x/(sq+1)); sq--; if(sq>t) comp.insert(sq+x/(sq+1)); ll best=*(comp.begin()); return best; } void solve(){ ll n,m; cin>>n>>m; vector<vector<pll>> adj(n+2); vector<ll> ans(n+5,INF_ADD); priority_queue<pll> prefer; prefer.push({0,1}); vector<vector<ll>> a(m+4,vector<ll>(5,0)); ans[1]=0; for(ll i=1;i<=m;i++){ for(ll j=1;j<=4;j++) cin>>a[i][j]; adj[a[i][1]].pb({a[i][2],i}); adj[a[i][2]].pb({a[i][1],i}); } while(prefer.size()){ auto it=prefer.top(); prefer.pop(); if(ans[it.s]!=-it.f) continue; ll node=it.s,instant=-it.f; for(auto chld:adj[node]){ ll compare=(a[chld.s][3]+optimal(a[chld.s][4],instant)); if(compare<ans[chld.f]){ prefer.push({-compare,chld.f}); ans[chld.f]=compare; } } } if(ans[n]!=INF_ADD) cout<<ans[n]; else cout<<"-1"; } int main() { 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 ll t=1; //cin>>t; while(t--){ solve(); } /* Correct data type? Infinity? Base case? */ cerr<<"Time:"<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n"; }
#include <bits/stdc++.h> using namespace std; /* MAGIC */ #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") /* ALIASES */ typedef long long lli; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pi; typedef pair<lli, lli> pl; typedef pair<ld, ld> pd; typedef vector<int> vi; typedef vector<ld> vd; typedef vector<lli> vl; typedef vector<pi> vpi; typedef vector<pl> vpl; /* DEFINITIONS */ #define mp make_pair #define pb push_back #define F first #define S second #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() #define allr(x) rbegin(x), rend(x) #define fo(i, a, b) for(auto i=a; i<(b); i++) #define forev(i, b, a) for(auto i = (b)-1; i >= a; i--) #define sortall(x) sort(all(x)) #define sz(x) (int)x.size() #define nl "\n" #define deb(...) logger(#__VA_ARGS__, __VA_ARGS__) template<typename ...Args> void logger(string vars, Args&&... values) { cout << vars << " = "; string delim = ""; (..., (cout << delim << values, delim = ", ")); } /* UTILITIES */ // ====================> Python-like print void print() { cout << "\n"; } template <typename T> void print(T &&t) { cout << t << "\n"; } template <typename T, typename... Args> void print(T &&t, Args &&... args) { cout << t << " "; print(forward<Args>(args)...); } // ====================> cin >> vector<T> template<typename T> istream& operator>>(istream &istream, vector<T> &v) { for (auto &it : v) cin >> it; return istream; } // ====================> cout << vector<T> template<typename T> ostream& operator<<(ostream &ostream, const vector<T> &c) { for (auto &it : c) cout << it << " "; return ostream; } /* CONSTANTS */ const ld PI = 4 * atan((ld)1); const lli MOD = 1000000007; const lli INF = 2e18; /*===========================================================================*/ void solve() { lli a, b, c; cin >> a >> b >> c; if (a >= 0 && b >= 0) { if (a > b) print(">"); else if (a < b) print("<"); else print('='); } else { if (c % 2 == 0) { if (abs(a) > abs(b)) { print(">"); } else if (abs(b) > abs(a)) { print("<"); } else if (abs(a) == abs(b)) print("="); } else { if (a < b) { print("<"); } else if (b < a) { print(">"); } else print("="); } } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t = 1; // cin >> t; fo(i, 0, t) { solve(); } return 0; }
#include<cstdio> #include<cmath> using namespace std; int a,b,c; int main() { scanf("%d%d%d",&a,&b,&c); if(c%2==0) { a=abs(a); b=abs(b); } if(a>b) printf(">"); else if(a==b) printf("="); else printf("<"); return 0; }
#include <bits/stdc++.h> using namespace std; #include <algorithm> #define ll long long int #define pb push_back #define fo(i, n) for (int i = 0; i < n; i++) #define vct vector<long long int> int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n; cin>>n; ll ans =0; if(n>=1000) ans = ans + n-999; if(n>=1000000) ans = ans + n-999999; if(n>=1000000000) ans = ans + n-999999999; if(n>=1000000000000) ans = ans + n-999999999999; if(n>=1000000000000000) ans = ans + n-999999999999999; cout<<ans<<endl; return 0; }
/* これを入れて実行 g++ code.cpp ./a.out */ #include <iostream> #include <cstdio> #include <stdio.h> #include <vector> #include <string> #include <cstring> #include <queue> #include <deque> #include <stack> #include <algorithm> #include <utility> #include <set> #include <map> #include <unordered_map> #include <unordered_set> #include <cmath> #include <math.h> #include <tuple> #include <iomanip> #include <bitset> #include <functional> #include <cassert> #include <random> #define all(x) (x).begin(),(x).end() #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; typedef long long ll; typedef long double ld; int dy4[4] = {-1, 0, +1, 0}; int dx4[4] = {0, +1, 0, -1}; int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1}; const long long INF = 1LL << 61; const ll MOD = 1e9 + 7; bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){ return f.second > s.second; } 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; } ll conbinationMemo[201][12]; void cmemoInit(){ rep(i, 201){ rep(j, 12){ conbinationMemo[i][j] = -1; } } } ll nCr(ll n, ll r){ if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r]; if(r == 0 || r == n){ return 1; } else if(r == 1){ return n; } return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1)); } ll nPr(ll n, ll r){ r = n - r; ll ret = 1; for (ll i = n; i >= r + 1; i--) ret *= i; return ret; } //-----------------------ここから----------- template<class T> T fastpow(T a, T b){ T res = 1; while(b > 0){ if(b & 1){ res *= a; } a *= a; b >>= 1; } return res; } int main(void){ ll n; cin >> n; string s = to_string(n); ll ans = 0; rep(i, s.size() - 1){ ans += fastpow(10LL, (ll)i) * 9 * (i / 3); } ans += fastpow(10LL, (ll)s.size() - 1) * (ll)(s[0] - '0' - 1) * (ll)((s.size() - 1) / 3); ll now = s[0] - '0'; ll cnt = s.size() - 1; while(cnt--) now *= 10; now--; ans += (n - now) * (ll)((s.size() - 1) / 3); cout << ans << endl; // ll ans2 = 0; // for(ll i = 1; i <= n; i++){ // string ss = to_string(i); // ans2 += (ss.size() - 1) / 3; // } // cout << ans2 << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define MOD 1000000007 ll powermd(long long x, int y, ll p) { ll res = 1; // Initialize result x = x % p; // Update x if it is more than or // equal to p // if (x == 0) return 0; // In case x is divisible by p; while (y > 0) { // If y is odd, multiply x with result if (y & 1) res = (res*x) % p; // y must be even now y = y>>1; // y = y/2 x = (x*x) % p; } return res; } //ll mpow(ll x,ll y){ // if(y==0) // return 1; // ll res=mpow(x,y/2); // res=res*res%mod; // if(y&1) // res=res*x%MOD; // return res; //} // ll mpow(ll n,ll t){ // if(t==0) return 1; // ll ret=mpow(n,t/2); // ret=ret*ret%MOD; // if(t%2==1) ret=ret*n%MOD; // return ret; // } void solve(){ ll n,p; cin>>n>>p; cout<<(powermd(p-2,n-1,1000000007)*(p-1))%1000000007; } int main(){ // ios::sync_with_stdio(false); // cout.tie(0); // cin.tie(NULL); int t; // cin>>t; t=1; while(t--) { // int n; // cin>>n; solve(); } }
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author aajisaka */ #include<bits/stdc++.h> using namespace std; 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 #define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr) #define rep(i,n) for(int i=0; i<(int)(n); i++) #define all(v) v.begin(), v.end() template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } using ll = long long; using ull = unsigned long long; using P = pair<ll, ll>; constexpr long double PI = 3.14159265358979323846264338327950288L; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); class AAtCoderJumper { public: void solve(istream& cin, ostream& cout) { SPEED; int n; cin >> n; for(int i=0; i<n; i++) { int a = i*2; int b = i*2+1; cout << a%n+1 << ' ' << b%n+1 << endl; } } }; signed main() { AAtCoderJumper solver; std::istream& in(std::cin); std::ostream& out(std::cout); solver.solve(in, out); return 0; }
/* ID:ACwisher LANG:C++ TASK: */ #include<bits/stdc++.h> using namespace std; typedef long long LL; //const int N=; typedef long long ll; ll n; int m; int power(int a,ll b,int mo){ int ret=1; while(b){ if(b&1) ret=1ll*ret*a%mo; a=1ll*a*a%mo; b>>=1; } return ret; } int main(){ // freopen(".in","r",stdin); // freopen(".out","w",stdiout); scanf("%lld%d",&n,&m); int mm=m*m; int k=power(10,n,mm); printf("%d\n",k/m); return 0; }
/*######################################################################## # File Name: A.cpp # Author: SoMnus_L # Mail: [email protected] # Created Time:日 1/10 14:45:58 2021 ########################################################################*/ #include <bits/stdc++.h> #define ll long long #define fi first #define se second #define pb push_back #define me memset #define rep(a,b,c) for(int a=b;a<=c;++a) #define per(a,b,c) for(int a=b;a>=c;--a) const int N = 1e6 + 10; const int mod = 1e9 + 7; const int INF = 0x3f3f3f3f; using namespace std; typedef pair<int,int> PII; typedef pair<ll,ll> PLL; ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;} ll lcm(ll a,ll b) {return a/gcd(a,b)*b;} ll n,m; ll fpow(ll a,ll k,ll mod){ ll res=1; while(k){ if(k&1) res=res*a%mod; k>>=1; a=a*a%mod; } return res; } int main() { ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); cin>>n>>m; cout<<fpow(10,n,m*m)/m%m<<'\n'; return 0; }
#include <iostream> #include <vector> #include <map> using namespace std; typedef long long ll; ll INF = 1000000000000000; struct segment_tree{ int n; vector<ll> seg; segment_tree(vector<ll> v){ n = v.size(); seg.resize(2*n); for(int i=0;i<n;i++) seg[i + n] = v[i]; for(int i=n - 1;i>0;i--) seg[i] = seg[i<<1] + seg[i<<1|1]; } void update(int p,ll val){ for(seg[p += n] += val;p>1;p>>=1) seg[p>>1] = seg[p] + seg[p^1]; } ll query(int l,int r){ ll res = 0; for(l += n,r += n; l<r;l>>=1,r>>=1){ if(l&1) res += seg[l++]; if(r&1) res += seg[--r]; } return res; } void clear(){for(int i=0;i<2*n;i++) seg[i] = 0;} }; int t[200010],x[200010],y[200010]; int main(){ int i,n,m,q; cin >> n >> m >> q; vector<int> a(n),b(m); map<int,int> mp; mp[0]++; for(i=0;i<q;i++){ cin >> t[i] >> x[i] >> y[i]; t[i]--; x[i]--; mp[y[i]]++; } vector<ll> v,u; for(auto x:mp) v.push_back(x.first); for(i=0;i<v.size();i++) mp[v[i]] = i; int k = v.size(); u.resize(k); vector<segment_tree> seg(2,segment_tree(u)),seg_num(2,segment_tree(u)); for(i=0;i<n;i++) seg[0].update(mp[a[i]],a[i]),seg_num[0].update(mp[a[i]],1); for(i=0;i<m;i++) seg[1].update(mp[b[i]],b[i]),seg_num[1].update(mp[b[i]],1); ll ans = 0; for(i=0;i<q;i++){ ll now; int j = x[i]; if(t[i]==0) now = a[j]; else now = b[j]; ans -= seg_num[1 - t[i]].query(0,mp[now])*now + seg[1 - t[i]].query(mp[now],k); if(t[i]==0){ seg[0].update(mp[a[j]],-a[j]); seg_num[0].update(mp[a[j]],-1); a[j] = y[i]; }else{ seg[1].update(mp[b[j]],-b[j]); seg_num[1].update(mp[b[j]],-1); b[j] = y[i]; } seg[t[i]].update(mp[y[i]],y[i]); seg_num[t[i]].update(mp[y[i]],1); ans += seg_num[1 - t[i]].query(0,mp[y[i]])*y[i] + seg[1 - t[i]].query(mp[y[i]],k); cout << ans << "\n"; } }
#include <bits/stdc++.h> using namespace std; using ll = long long int; using ull = unsigned long long int; using P = pair<int, int>; using P3 = pair<int,P>; using PP = pair<P, P>; constexpr int INF32 = 1 << 29; constexpr ll INF64 = 1LL << 62; constexpr ll MOD = 1000000007; // constexpr ll MOD = 998244353; constexpr int di[] = {0, 1, 0, -1}; constexpr int dj[] = {1, 0, -1, 0}; constexpr int di8[] = {0, 1, 1, 1, 0, -1, -1, -1}; constexpr int dj8[] = {1, 1, 0, -1, -1, -1, 0, 1}; constexpr double EPS = 1e-10; const double PI = acos(-1); #define ALL(v) (v).begin(),(v).end() #define REP(i,n) for(int i=0,i_len=n; i<i_len; ++i) template<typename T1,typename T2> bool chmax(T1 &a, T2 b) { if (a<b) { a=b; return 1; } return 0; } template<typename T1,typename T2> bool chmin(T1 &a, T2 b) { if (b<a) { a=b; return 1; } return 0; } void compress(vector<int> &x, map<int, int> &zip) { sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end()); for (int i = 0; i < x.size(); i++) { zip[x[i]] = i+1; } } template <typename T> struct BIT { int N; std::vector<T> bit; BIT() = default; BIT(int n) {init(n);} void init(int n){ N = n; bit.assign(n+1, 0); } T getSum(int i) { // i番目までの要素の和を求める(1-index) T sum = 0; while (i > 0) { sum += bit[i]; i -= i & -i; } return sum; } void add(int i, T x) { // i番目の要素にxを加算 while (i <= N) { bit[i] += x; i += i & -i; } } }; int solve(){ int n, m, q; cin >> n >> m >> q; vector<P3> query; vector<int> num; REP(i,q){ int t, x, y; cin >> t >> x >> y; x--; query.emplace_back(t,P(x,y)); num.emplace_back(y); } num.emplace_back(0); map<int,int> zip; compress(num, zip); vector<ll> a(n), b(m); ll res = 0; BIT<ll> bitA(num.size()), bitB(num.size()), bitA2(num.size()), bitB2(num.size()); bitA.add(zip[0], n); bitB.add(zip[0], m); REP(i,q){ int t, x, y; t = query[i].first; x = query[i].second.first; y = query[i].second.second; if(t == 1){ res -= bitB.getSum(zip[a[x]]) * a[x]; res += bitB.getSum(zip[y]) * y; if(a[x] < y){ res -= bitB2.getSum(zip[y]) - bitB2.getSum(zip[a[x]]); }else{ res += bitB2.getSum(zip[a[x]]) - bitB2.getSum(zip[y]); } bitA.add(zip[a[x]],-1); bitA.add(zip[y],1); bitA2.add(zip[a[x]],-a[x]); bitA2.add(zip[y],y); a[x] = y; }else{ res -= bitA.getSum(zip[b[x]]-1) * b[x]; res += bitA.getSum(zip[y]-1) * y; if(b[x] < y){ res -= bitA2.getSum(zip[y]-1) - bitA2.getSum(zip[b[x]]-1); }else{ res += bitA2.getSum(zip[b[x]]-1) - bitA2.getSum(zip[y]-1); } bitB.add(zip[b[x]],-1); bitB.add(zip[y],1); bitB2.add(zip[b[x]], -b[x]); bitB2.add(zip[y], y); b[x] = y; } cout << res << endl; } return 0; } int main(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20); // int t; cin >> t; for(int i=0;i<t;i++) solve(); // while(!solve()); solve(); return 0; }
// #pragma GCC optimize("Ofast,unroll-loops") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") #include <bits/stdc++.h> #define ll long long int #define vi vector<int> #define vvi vector<vector<int>> #define vll vector<long long> #define vs vector<string> #define vc vector<char> #define vb vector<bool> #define forn(i, s, n) for(ll i=(ll)s; i<(ll)(n); i++) #define all(c) c.begin(),c.end() #define pb push_back #define pll pair<long long int, long long int> #define pii pair<int, int> #define pss pair<string, string> #define ull unsigned long long int #define lld long double #define F first #define S second #define PI 3.141592653589793238 #define prec(n) fixed<<setprecision(n) #define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr) #define itsval(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); itval(_it, args); } using namespace std; // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; void itval(istream_iterator<string> it) {} template<typename T, typename... Args> void itval(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; itval(++it, args...); } const ll MOD = 1e9 + 7; template <typename T> inline void print(T x) {cout << x << "\n";} template <typename T> inline void printvec(T x) {for (auto a : x)cout << a << ' '; cout << '\n';} // ----------------------------------------------------------------------- struct custom { bool operator()(const pair<ll, pll> &p1, const pair<ll, pll> &p2)const { return p1.F < p2.F; } }; // Calculate a^b % MOD ------------------------------------------------- ll get_pow(ll a, ll b, ll M = MOD) { ll res = 1; while (b) { if (b & 1) res = (res * a) % M; a = (a * a) % M; b >>= 1; } return res; } // --------------------------------------------------------------------- const ll N = 2e5 + 5, inf = 2e18; void solve() { ll a[2][2]; forn(i, 0, 2) forn(j, 0, 2) cin >> a[i][j]; ll ans = -inf; forn(i, 0, 2) { forn(j, 0, 2) ans = max(ans, a[0][i] - a[1][j]); } cout << ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int test = 1; clock_t z = clock(); // cin >> test; forn(tes, 0, test) { solve(); } debug("Total Time:%.4f\n", (double)(clock() - z) / CLOCKS_PER_SEC); return 0; }
#include <bits/stdc++.h> using namespace std; #define INF ((int64_t)1e16) int main() { int N; int64_t X; cin >> N >> X; vector<int64_t> A(N); for (auto &a : A) { cin >> a; } vector<int64_t> cnt(N); for (int i = 0; i < N; i++) { int j = N - 1 - i; cnt.at(j) = X / A.at(j); X %= A.at(j); } vector<int64_t> limit(N); for (int i = 0; i < N - 1; i++) { limit.at(i) = A.at(i + 1) / A.at(i); } limit.at(N - 1) = INF / A.at(N - 1); vector<int64_t> ans1(N, 0); vector<int64_t> ans2(N, 0); if (cnt.at(0) > 0) { ans1.at(0) = 1; } ans2.at(0) = 1; for (int i = 1; i < N; i++) { ans1.at(i) = ans1.at(i - 1); ans2.at(i) = ans2.at(i - 1); if (cnt.at(i) + 1 < limit.at(i)) { ans2.at(i) += ans1.at(i - 1); } if (cnt.at(i) > 0) { ans1.at(i) += ans2.at(i - 1); } } cout << ans2.at(N - 1) << endl; return 0; }
#include "bits/stdc++.h" //#include "atcoder/all" using namespace std; //using namespace atcoder; //using mint = modint1000000007; //const int mod = 1000000007; //using mint = modint998244353; //const int mod = 998244353; //const int INF = 1e9; //const long long LINF = 1e18; //const bool debug = false; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i,l,r)for(int i=(l);i<(r);++i) #define rrep(i, n) for (int i = (n-1); i >= 0; --i) #define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i) #define all(x) (x).begin(),(x).end() #define allR(x) (x).rbegin(),(x).rend() #define endl "\n" #define P pair<int,int> template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; } template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; int ans = 0; rep(i, n) { int a; cin >> a; if (a >= 10)ans += a - 10; } cout << ans << endl; return 0; }
#include <iostream> #include <vector> #include <algorithm> #include <map> #include <string.h> using namespace std; #define int long long #define f first #define s second #define pb push_back #define pii pair<int, int> signed main() { ios_base::sync_with_stdio(0); cin.tie(0); int a, b, ans = 0; cin >> a; for (int i = 0; i < a; ++i) { cin >> b; ans += max(0LL, b - 10); } cout << ans << endl; return 0; }
//#define _GLIBCXX_DEBUG #include<bits/stdc++.h> using namespace std; template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); } template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); } typedef long long ll; typedef vector<int> vint; typedef pair<int, int> pint; typedef vector<long long> vlong; typedef vector<string> vstring; #define vpush(a,x) a.push_back(x); #define rep(i, n) REP(i, 0, n) #define all(v) v.begin(), v.end() #define REP(i, x, n) for(int i = x; i < n; i++) const int INF = 1 << 30; const ll LINF = (ll)1 << 60; const int dx[] = {1,0,-1,0,1,1,-1,-1}; const int dy[] = {0,-1,0,1,1,-1,-1,1}; #define stp(x) setprecision(x) const long double PI=3.14159265358979323846264338327950; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin>>n; vector<int> cnt(500,0); vector<int> a(n); rep(i,n){ cin>>a[i]; cnt[a[i]+200]++; } ll ans=0; rep(i,n){ cnt[a[i]+200]--; REP(j,-200,201){ ans+=pow(abs((j)-a[i]),2)*cnt[j+200]; } } cout<<ans<<'\n'; return(0); }
#include<bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int,int> #define fi first #define se second #define all(x) x.begin(),x.end() #define sz(x) (int)x.size() #define pb push_back #define faster ios_base::sync_with_stdio(0);cin.tie(0); #define mem(a,v) memset(a,v,sizeof(a)) const ll INF=1e18; const int mod=1e9+7; const int iinf=1e9+10; const int xd[4]={1,0,-1,0},yd[4]={0,1,0,-1},mxN=2e5+2; map<string,int> mp,mp1; string s[mxN]; int main(){ faster int n; cin>>n; for(int i=0;i<n;i++){ cin>>s[i]; string g=""; if(s[i][0]=='!'){ for(int j=1;j<sz(s[i]);j++) g+=s[i][j]; mp1[g]++; } else { g=s[i]; mp[g]++; } } for(auto a:mp){ //cout<<"a.fi="<<a.fi<<"\n"; if(mp1.find(a.fi)!=mp1.end()){ cout<<a.fi;exit(0); } } cout<<"satisfiable"; }
#include <bits/stdc++.h> using namespace std; mt19937 rng(58); typedef double db; const int N = 10000; bool sold[N][N]; struct rect{ int lx, ly, rx, ry; rect(){} rect(int x, int y){ lx = x; rx = x + 1; ly = y; ry = y + 1; } rect(int _lx, int _ly, int _rx, int _ry){ lx = _lx; ly = _ly; rx = _rx; ry = _ry; } bool contains(int x, int y) const{ return lx <= x && x < rx && ly <= y && y < ry; } int area() const{ return (rx - lx) * (ry - ly); } bool intersects(const rect& other) const{ return max(lx, other.lx) < min(rx, other.rx) && max(ly, other.ly) < min(ry, other.ry); } void write() const{ cout << lx << ' ' << ly << ' ' << rx << ' ' << ry << endl; } }; inline bool can_extend(rect& r, int dir){ if (dir == 0){ if (r.rx < N){ for(int i = r.ly; i < r.ry; ++i){ if (sold[r.rx][i]){ return false; } } for(int i = r.ly; i < r.ry; ++i){ sold[r.rx][i] = 1; } r.rx++; return true; } }else if (dir == 1){ if (r.lx > 0){ for(int i = r.ly; i < r.ry; ++i){ if (sold[r.lx - 1][i]){ return false; } } r.lx--; for(int i = r.ly; i < r.ry; ++i){ sold[r.lx][i] = 1; } return true; } }else if (dir == 2){ if (r.ry < N){ for(int i = r.lx; i < r.rx; ++i){ if (sold[i][r.ry]){ return false; } } for(int i = r.lx; i < r.rx; ++i){ sold[i][r.ry] = 1; } r.ry++; return true; } }else{ if (r.ly > 0){ for(int i = r.lx; i < r.rx; ++i){ if (sold[i][r.ly - 1]){ return false; } } r.ly--; for(int i = r.lx; i < r.rx; ++i){ sold[i][r.ly] = 1; } return true; } } return false; } struct query{ int x, y, r, id; void read(int _id){ cin >> x >> y >> r; id = _id; } db score(rect R){ if (!R.contains(x, y)) return 0; db val = min(r, R.area()) / (db) max(r, R.area()); cerr << val << endl; return 1 - (1 - val) * (1 - val); } }; int main(){ int n; cin >> n; vector<query> queries(n); for(int i = 0; i < n; ++i){ queries[i].read(i); } vector<rect> answer(n); for(int i = 0; i < n; ++i){ answer[i] = rect(queries[i].x, queries[i].y); sold[queries[i].x][queries[i].y] = true; } vector<int> order(n); iota(order.begin(), order.end(), 0); sort(order.begin(), order.end(), [&](int u, int v) {return queries[u].r > queries[v].r;}); for(int i: order){ query q = queries[i]; rect& answer_now = answer[i]; vector<int> order_dir = {0, 1, 2, 3}; while(answer_now.area() < q.r){ shuffle(order_dir.begin(), order_dir.end(), rng); bool extended = false; for(int dir: order_dir){ if (can_extend(answer_now, dir)){ extended = true; break; } } if (!extended){ break; } } } db score = 0; for(int i = 0; i < n; ++i){ score += queries[i].score(answer[i]); } score /= n; score *= 1000000000; cerr << (int)score << endl; for(int i = 0; i < n; ++i){ for(int j = 0; j < i; ++j){ if (answer[i].intersects(answer[j])){ assert(false); } } } for(int i = 0; i < n; ++i){ answer[i].write(); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef unsigned uint; typedef long long ll; typedef unsigned long long ull; typedef long double ldbl; typedef pair<int, int> pii; typedef pair<uint, uint> puu; typedef pair<ll, ll> pll; typedef pair<ull, ull> pull; typedef pair<double, double> pdd; typedef vector<int> vi; typedef vector<uint> vu; typedef vector<ll> vll; typedef vector<ull> vull; typedef vector<pii> vpii; typedef vector<puu> vpuu; typedef vector<pll> vpll; typedef vector<pull> vpull; typedef vector<string> vstr; typedef vector<double> vdbl; typedef vector<ldbl> vldbl; #define pb push_back #define ppb pop_back #define pfr push_front #define ppfr pop_front #define emp emplace #define empb emplace_back #define be begin #define rbe rbegin #define all(x) (x).be(), (x).end() #define rall(x) (x).rbe(), (x).rend() #define fir first #define sec second #define mkp make_pair #define brif(cond) if (cond) break #define ctif(cond) if (cond) continue #define retif(cond) if (cond) return void canhazfast() {ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);} template<typename T> T gcd(T a, T b) {return b ? gcd(b, a%b) : a;} template<typename T> T extgcd(T a, T b, T &x, T &y) { T x0 = 1, y0 = 0, x1 = 0, y1 = 1; while (b) { T q = a/b; a %= b; swap(a, b); x0 -= q*x1; swap(x0, x1); y0 -= q*y1; swap(y0, y1); } x = x0; y = y0; return a; } int ctz(uint x) {return __builtin_ctz(x);} int ctzll(ull x) {return __builtin_ctzll(x);} int clz(uint x) {return __builtin_clz(x);} int clzll(ull x) {return __builtin_clzll(x);} int popcnt(uint x) {return __builtin_popcount(x);} int popcntll(ull x) {return __builtin_popcountll(x);} int bsr(uint x) {return 31^clz(x);} int bsrll(ull x) {return 63^clzll(x);} #define N 200 #define W 10000 #define MULT 1e9 struct C { int x, y, r; }; struct R { int a, b, c, d; }; int per[N]; C c[N]; R ans[N]; bool cmp_xy(int l, int r) { return c[l].x != c[r].x ? c[l].x < c[r].x : c[l].y < c[r].y; } bool cmp_yx(int l, int r) { return c[l].y != c[r].y ? c[l].y < c[r].y : c[l].x < c[r].x; } bool cmp_r(int l, int r) { return c[l].r < c[r].r; } bool inside(const C &com, const R &rec) { return com.x >= rec.a && com.x < rec.c && com.y >= rec.b && com.y < rec.d; } double calc(const C &com, const R &rec) { retif(!inside(com, rec)) 0.0; int s = (rec.c-rec.a)*(rec.d-rec.b); double t = 1.0-(double)min(com.r, s)/max(com.r, s); return 1.0-t*t; } double eval(int n) { double res = 0.0; for (int i = 0; i < n; ++i) res += calc(c[i], ans[i]); return res*MULT/n; } void dumb_split(int b, int e, int xl = 0, int xh = W, int yl = 0, int yh = W) { int m = -1, pos = -1; if (b+1 == e) { int u = per[b]; ans[u] = {xl, yl, xh, yh}; return; } sort(per+b, per+e, cmp_xy); for (int i = b+1; i < e; ++i) { int u = per[i-1], v = per[i]; if (c[u].x != c[v].x) { pos = (c[u].x+c[v].x+1)/2; m = i; break; } } if (m >= 0) { dumb_split(b, m, xl, pos, yl, yh); dumb_split(m, e, pos, xh, yl, yh); return; } sort(per+b, per+e, cmp_yx); for (int i = b+1; i < e; ++i) { int u = per[i-1], v = per[i]; if (c[u].y != c[v].y) { pos = (c[u].y+c[v].y+1)/2; m = i; break; } } assert(m >= 0); dumb_split(b, m, xl, xh, yl, pos); dumb_split(m, e, xl, xh, pos, yh); } int main() { canhazfast(); int n; /// in cin >> n; for (int i = 0; i < n; ++i) cin >> c[i].x >> c[i].y >> c[i].r; iota(per, per+n, 0); /// 0 /*for (int i = 0; i < n; ++i) { ans[i] = {c[i].x, c[i].y, c[i].x+1, c[i].y+1}; }*/ /// 1 dumb_split(0, n); /// out for (int i = 0; i < n; ++i) cout << ans[i].a << ' ' << ans[i].b << ' ' << ans[i].c << ' ' << ans[i].d << '\n'; cerr << eval(n) << '\n'; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <chrono> #include <typeinfo> using namespace std; using namespace std::chrono; using namespace __gnu_pbds; #define lli long long int #define fr(i,a,b) for(lli i=a;i<b;i++) #define bfr(i,a,b) for(lli i=a;i>=b;i--) #define fio ios_base::sync_with_stdio(false); cin.tie(NULL),cout.tie(NULL); #define tc int t;cin>>t;while(t--) //#define mod 1000000007LL #define mod2 998244353LL #define PI 3.14159265359 #define all(vec) vec.begin(),vec.end() #define ld long double #define pb push_back #define ordered_set tree<lli, null_type,less<lli>, rb_tree_tag,tree_order_statistics_node_update> lli pmod(lli x,lli y,lli mod){lli res=1;while(y>0){if(y&1)res = ((res%mod)*(x%mod))%mod;y>>=1;x= ((x%mod)*(x%mod))%mod;}return res;} lli power(lli x,lli y){lli res=1;while(y>0){if(y&1)res=res*x;y>>=1;x=x*x;}return res;} lli gcd(lli a , lli b) { if(b==0) return a; a%=b; return gcd(b,a); } lli cnt=0; void solve(vector<vector<lli>> mat,lli a,lli b,lli row,lli col) { lli x=-1,y=-1; fr(i,0,row) {fr(j,0,col) if(mat[i][j]==0) {x=i,y=j;break;} if(x!=-1)break; } if(x==-1){cnt++; return;} mat[x][y]=1; if(b>0)solve(mat,a,b-1,row,col); mat[x][y]=0; if(a>0 && x+1<row && mat[x+1][y]==0){ mat[x][y]=2; mat[x+1][y]=2;solve(mat,a-1,b,row,col); mat[x+1][y]=0; mat[x][y]=0; } if(a>0 && y+1<col && mat[x][y+1]==0){ mat[x][y]=3; mat[x][y+1]=3; solve(mat,a-1,b,row,col); mat[x][y]=0; mat[x][y+1]=0; } return; } int main() { fio lli row,col,a,b; cin>>row>>col>>a>>b; vector<vector<lli>> mat(row,vector<lli>(col,0)); solve(mat,a,b,row,col); cout<<cnt; return 0;}
#include<iostream> #include<string> #include<vector> #include<stack> #include<queue> #include<set> #include<map> #include<algorithm> #include<cstring> using namespace std; int n, m; bool visited[20][20]; int recur(int x, int y, int a, int b) { int ret = 0; if (y == m) { x++; y = 0; } if (x == n) { return 1; } if (visited[x][y]) ret += recur(x, y + 1, a, b); else { if (a && y < m - 1 && !visited[x][y + 1]) { visited[x][y] = true; visited[x][y + 1] = true; ret += recur(x, y + 1, a - 1, b); visited[x][y] = false; visited[x][y + 1] = false; } if (a && x < n - 1 && !visited[x + 1][y]) { visited[x][y] = true; visited[x + 1][y] = true; ret += recur(x, y + 1, a - 1, b); visited[x][y] = false; visited[x + 1][y] = false; } if (b) { visited[x][y] = true; ret += recur(x, y + 1, a, b - 1); visited[x][y] = false; } } return ret; } int main() { int a, b; cin >> n >> m >> a >> b; cout << recur(0, 0, a, b); }
#include <iostream> #include <math.h> #include <numeric> #include <vector> #include <utility> #include <algorithm> #include <map> #include <queue> #include <queue> #include <stack> #include <sstream> #include <set> typedef long long ll; const int dx[8]={1,0,-1,0,1,-1,-1,1}; const int dy[8]={0,1,0,-1,1,1,-1,-1}; const int dr[4] = {-1, 0, 1, 0}; const int dc[4] = { 0, 1, 0,-1}; const int INF = 1e9; #define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i) #define REP(i, n) FOR(i, 0, n) #define SORT(a) sort(a.begin(),a.end()) #define REVERSE(a) reverse(a.begin(),a.end()) int guki (int a){ if(a%2==0) return 0; else return 1; } int gcd(int a, int b){ if(a%b==0){ return b; }else{ return (gcd(b,a%b)); } } int lcm(int a, int b){ int x = gcd(a,b); return (a*b/x); } using namespace std; // now struct UnionFind { vector<int> d; UnionFind(int n=0) : d(n,-1){} int Find (int x){//根の番号を探す if(d[x] < 0) return x; return d[x] = Find(d[x]); } bool unite (int x, int y){ x = Find(x); y = Find(y); if(x == y ) return false; if(d[x] < d[y]){ swap(x,y); } d[x] += d[y]; d[y] = x; return true; } bool same(int x, int y){ return Find(x) == Find(y); } int size(int x) { return (-d[Find(x)]); } }; ll nCr (ll n, ll r){ ll ans = 1; for(ll i = n ; i > n-r ; i --){ ans *= i; } for(ll i = 1 ; i<= r; i ++){ ans /= i; } return ans ; } int nPr (int n,int r){ int ans = 1; for(int i = n ; i > n-r ; i --){ ans *= i; } return ans ; } // 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;} ll modd = 1e9+ 7; ll wa (ll n,ll mi, ll ma){ ll ans = n * (mi+ma) /2; return ans; } int r5 (int a){ int x = a * a * a * a * a; return x; } struct Edge {int to,id;}; vector<vector<Edge>> g; vector<int> ans; void dfs(int v,int c = -1, int p = -1){ int k = 1; REP(i,g[v].size()){ int u = g[v][i].to, ei = g[v][i].id; if(u == p ) continue; if(c == k) k++; ans[ei] = k; k++; dfs(u,k-1,v); } } int main(){ ll n,ans; string s; cin >> n >> s; vector<char> k; for(auto c :s){ k.push_back(c); if(k.size() >= 3 && k[k.size()-3] =='f' && k[k.size()-2] == 'o' && k[k.size()-1] == 'x'){ k.pop_back(); k.pop_back(); k.pop_back(); } } cout << k.size() <<endl; }
#include<bits/stdc++.h> using namespace std; using namespace std::chrono; const int mod=1e9+7; const int mex=300005; #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++) int main() { int n; cin>>n; string s; cin>>s; stack<char> st; fo(i,0,sz(s)) { if(sz(st)<2) st.push(s[i]); else if(s[i]=='x') { char y=st.top(); st.pop(); char y1=st.top(); st.pop(); if(y1=='f'&&y=='o') continue; else { st.push(y1); st.push(y); st.push(s[i]); } } else st.push(s[i]); } cout<<sz(st)<<endl; }
#include <bits/stdc++.h> #define rep(i, n) for (auto i = 0; i < n; ++i) #define ALL(a) a.begin(), a.end() using namespace std; using ll = long long int; const int MOD_NUM = 1e9 + 7; int main() { // Input int T; cin >> T; rep(i, T) { // Input int L, R; cin >> L >> R; // Process ll x = max(R - L * 2 + 1, 0); ll ans = x * (x + 1) / 2; // Output cout << ans << endl; } return 0; }
#include<bits/stdc++.h> #define fo(i,a,b) for((i)=(a);i<=(b);i++) #define rfo(i,a,b) for((i)=(a);i>=(b);i--) #define inrange(x,y,z) (((x)>=(y))&&((x)<=(z))) #define ALL(vec) (vec).begin(),(vec).end() #define SOR(vec) sort(ALL(vec)) #define UNI(vec) (vec).erase(unique(ALL(vec)),(vec).end()) using namespace std; int n; long long a[200100],b[200100],ma,res; int main(){ #ifdef FILIN #ifndef DavidDesktop freopen(FILIN,"r",stdin); freopen(FILOUT,"w",stdout); #endif #endif ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); cin>>n; for(int i=1;i<=n;i++) cin>>a[i]; for(int i=1;i<=n;i++) cin>>b[i]; for(int i=1;i<=n;i++){ ma=max(ma,a[i]); res=max(res,ma*b[i]); cout<<res<<endl; } return 0; }
#include<iostream> using namespace std; class Solver { private: int sy, sx, gy, gx, result; string ans; public: void input() { cin >> sy >> sx >> gy >> gx; ans = ""; } void output() { cout << ans << endl; } void getResult() { cin >> result; } void solve() { if(sy < gy) for(int i = 0; i < gy - sy; i++) ans += "D"; else for(int i = 0; i < sy - gy; i++) ans += "U"; if(sx < gx) for(int i = 0; i < gx - sx; i++) ans += "R"; else for(int i = 0; i < sx - gx; i++) ans += "L"; } void play() { for(int i = 0; i < 1000; i++) { input(); solve(); output(); getResult(); } } }; int main() { Solver solver; solver.play(); return 0; }
//By: Luogu@rui_er(122461) #include <bits/stdc++.h> #define rep(x,y,z) for(int x=y;x<=z;x++) #define per(x,y,z) for(int x=y;x>=z;x--) #define debug printf("Running %s on line %d...\n",__FUNCTION__,__LINE__) using namespace std; typedef long long ll; const int N = 1e5+5; int n, ans; char s[N]; template<typename T> void chkmin(T &x, T y) {if(x > y) x = y;} template<typename T> void chkmax(T &x, T y) {if(x < y) x = y;} int main() { scanf("%d%s", &n, s+1); if(s[1] != s[n]) return puts("1")&0; rep(i, 1, n-1) if(s[1] != s[i] && s[i+1] != s[n]) return puts("2")&0; puts("-1"); return 0; }
#include <bits/stdc++.h> using namespace std; using lint = long long int; using P = pair<int, int>; using PL = pair<lint, lint>; #define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++) #define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--) #define REP(i, n) FOR(i,0,n) #define IREP(i, n) IFOR(i,0,n) #define ALL(a) (a).begin(),(a).end() constexpr int MOD = 1000000007; constexpr lint B1 = 1532834020; constexpr lint M1 = 2147482409; constexpr lint B2 = 1388622299; constexpr lint M2 = 2147478017; constexpr int INF = 2147483647; void yes(bool expr) {cout << (expr ? "Yes" : "No") << "\n";} template<class T>void chmax(T &a, const T &b) { if (a<b) a=b; } template<class T>void chmin(T &a, const T &b) { if (b<a) a=b; } struct Two1 { lint idx, AB, BA; bool operator < (const Two1 &other) const { return AB > other.AB; } }; struct Two2 { lint idx, AB, BA; bool operator < (const Two2 &other) const { return BA > other.BA; } }; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); lint N; cin >> N; vector<lint> A(N), B(N); REP(i, N) cin >> A[i]; REP(i, N) cin >> B[i]; lint score = 0; vector<lint> AB; vector<lint> BA; for(int i=0; i<N; i+=2) { if(A[i]+A[i+1] >= B[i]+B[i+1]) { score += A[i]+A[i+1]; AB.push_back(B[i+1]-A[i+1]); BA.push_back(B[i]-A[i]); } else { score += B[i]+B[i+1]; AB.push_back(A[i]-B[i]); BA.push_back(A[i+1]-B[i+1]); } } sort(ALL(AB), greater<lint>()); sort(ALL(BA), greater<lint>()); lint ans = score; REP(i, AB.size()) { score += AB[i] + BA[i]; chmax(ans, score); } cout << ans << endl; }
#include "bits/stdc++.h" using namespace std; #define rep(i, a, b) for(int i=a; i<=b; i++) #define trav(a, x) for(auto& a : x) #define all(x) begin(x), end(x) #define sz(x) (int) x.size() #define f first #define s second #define nl "\n" #define pb push_back typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pii; const int MOD = 1e9+7; template<class T> using pqg = priority_queue<T,vector<T>,greater<T>>; int n, q; ll a, mn, mx, d, t; int main(){ ios::sync_with_stdio(false); cin.tie(0); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); mx=1e18; mn=-1e18; d=0; cin >> n; rep(i, 1, n){ cin >> a >> t; if(t==1){ d+=a; mn+=a; mx+=a; } else if(t==2){ if(a>mx) mx=mn=a; else if(a>mn) mn=a; } else{ if(a<mn) mx=mn=a; else if(a<mx) mx=a; } } cin >> q; rep(i, 1, q){ cin >> a; cout << min(mx, max(mn, a+d)) << nl; } }
#include <iostream> #include <string> #include <cstring> #include <algorithm> #include <functional> #include <cmath> #include <set> #include <queue> #include <deque> #include <vector> #include <climits> #include <sstream> #include <iomanip> #include <map> #include <stack> using namespace std; using ui = unsigned int; using ull = unsigned long long; using ll = long long; using vi = vector<int>; using vvi = vector<vector<int>>; using vvvi = vector<vector<vector<int>>>; using vui = vector<ui>; using vl = vector<ll>; using vvl = vector<vector<ll>>; using vvvl = vector<vector<vector<ll>>>; template <typename T> using vv = vector<vector<T>>; template <typename T> using vvv = vector<vector<vector<T>>>; struct BIT { vector<ll> Data; int N; ll Init; BIT(int n, ll init = 0) { N = n; Data.resize(N + 1, init); Init = init; } void add(int i, ll v) { while (i <= N) { Data[i] += v; i += i & -i; } } ll getSum(int i) { auto sum = 0ll; while (i > 0) { sum += Data[i]; i -= i & -i; } return sum; } }; ll calc(int X, int Y, vi& a, vi& b, vi& listA, vi& listB, BIT& cntA, BIT& cntB, BIT& sumA, BIT& sumB) { auto ret = 0ll; auto oldB = lower_bound(listB.begin(), listB.end(), a[X]) - listB.begin(); auto newB = lower_bound(listB.begin(), listB.end(), Y) - listB.begin(); ret -= cntB.getSum(oldB) * a[X]; ret += cntB.getSum(newB) * Y; ret -= sumB.getSum(newB); ret += sumB.getSum(oldB); auto oldA = lower_bound(listA.begin(), listA.end(), a[X]) - listA.begin(); auto newA = lower_bound(listA.begin(), listA.end(), Y) - listA.begin(); cntA.add(oldA + 1 , -1); cntA.add(newA + 1, 1); sumA.add(oldA + 1, -a[X]); sumA.add(newA + 1, Y); a[X] = Y; return ret; } int main() { int N, M, Q; cin >> N >> M >> Q; set<int> sA; set<int> sB; struct query { int T; int X; int Y; }; vector<query> q(Q); for (auto i = 0; i < Q; ++i) { cin >> q[i].T >> q[i].X >> q[i].Y; --q[i].X; if (q[i].T == 1) { sA.insert(q[i].Y); } else { sB.insert(q[i].Y); } } sA.insert(0); sB.insert(0); vi listA(sA.begin(), sA.end()); vi listB(sB.begin(), sB.end()); auto numA = (int)listA.size(); auto numB = (int)listB.size(); BIT cntA(numA); BIT cntB(numB); BIT sumA(numA); BIT sumB(numB); cntA.add(1, N); cntB.add(1, M); vi a(N); vi b(M); auto ans = 0ll; for (auto i = 0; i < Q; ++i) { if (q[i].T == 1) { ans += calc(q[i].X, q[i].Y, a, b, listA, listB, cntA, cntB, sumA, sumB); } else { ans += calc(q[i].X, q[i].Y, b, a, listB, listA, cntB, cntA, sumB, sumA); } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define ull unsigned long long #define ll long long #define ui unsigned int #define us unsigned short #define inf_int 1e9 #define inf_ll 1e18 #define mod 1000000007 #define smod 998244353 int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); int n; cin >> n; vector<pair<double, int>> v; for(int x=0;x<n;x++){ int t; double l, r; cin >> t >> l >> r; if(t == 2){ r -= 0.1; } else if(t == 3){ l += 0.1; } else if(t == 4){ l += 0.1; r -= 0.1; } if(l <= r){ v.push_back({l, 1}); v.push_back({r+0.01, -1}); } } sort(v.begin(), v.end()); ll ans = 0, cnt = 0; for(int x=0;x<v.size();x++){ pair<double, int> p = v[x]; if(p.second == 1){ ans += cnt; cnt++; } else { cnt--; } // cout << p.first << " " << p.second << " -> " << ans << "\n"; } cout << ans << "\n"; return 0; }
# pragma GCC optimize ("O3") # pragma GCC optimize ("Ofast") # pragma GCC optimize ("unroll-loops") #define _CRT_SECURE_NO_WARNINGS #include <bits/stdc++.h> #define rep(i,a,b) for(int i = (a); i < (b); i++) #define rep2(i,a,b) for(int i = (b) - 1; i >= (a); i--) #define all(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) #define pb push_back #define x first #define y second using namespace std; using ll = long long; using tl = tuple<ll, ll, ll, ll>; using pl = pair<ll, ll>; using pi = pair<int, int>; using ld = long double; const int MAX = 2001, INF = 1e9; const int dx[] = {1, 0}, dy[] = {0, 1}; int H, W, dp[MAX][MAX]; string S[MAX]; inline bool valid(int x, int y){ return 0 <= x && x < H && 0 <= y && y < W; } inline int f(char x){ return x == '+' ? 1 : -1; } int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); cin >> H >> W; rep(i, 0, H) cin >> S[i]; rep2(i, 0, H) rep2(j, 0, W){ if(i == H - 1 && j == W - 1) continue; int ans = -INF; rep(t, 0, 2){ int x = i + dx[t], y = j + dy[t]; if(!valid(x, y)) continue; ans = max(ans, -dp[x][y] + f(S[x][y])); } dp[i][j] = ans; } if(dp[0][0] == 0) cout << "Draw"; else if(dp[0][0] > 0) cout << "Takahashi"; else cout << "Aoki"; }
#include <bits/stdc++.h> using namespace std; //#include <atcoder/all> //using namespace atcoder; #define rep(i, n) for(int i = 0, i##_len=(n); i < i##_len; ++i) #define all(x) (x).begin(), (x).end() #define len(x) ((int)(x).size()) void _cin() {} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail) { cin >> head; _cin(forward<Tail>(tail)...); } #define cin(Type, ...) Type __VA_ARGS__; _cin(__VA_ARGS__) #define cinv(Type, xs, n) vector<Type> xs(n); rep(i, n) cin >> xs[i] #define cinv2(Type, xs, ys, n) vector<Type> xs(n), ys(n); rep(i, n) cin >> xs[i] >> ys[i] #define cinv3(Type, xs, ys, zs, n) vector<Type> xs(n), ys(n), zs(n); rep(i, n) cin >> xs[i] >> ys[i] >> zs[i] #define cinvv(Type, xs, h, w) vector<vector<Type>> xs(h, vector<Type>(w)); rep(i, h) rep(j, w) cin >> xs[i][j] 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 Type> void print(vector<Type> &vec) { for (auto& a : vec) { cout << a; if (&a != &vec.back()) cout << " "; } cout << endl; } template <class Type> void print(vector<vector<Type>> &df) { for (auto& vec : df) { print(vec); } } void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; } void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; } void yesno(bool b) { cout << (b ? "yes" : "no") << endl; } template<class Integer>bool chmax(Integer &a, const Integer &b) { if (a < b) { a = b; return 1; } return 0; } template<class Integer>bool chmin(Integer &a, const Integer &b) { if (b < a) { a = b; return 1; } return 0; } using ll = long long; void Main() { map<ll, ll> mp; cin(int, n); cin(ll, C); rep(i, n) { cin(ll, a, b, c); mp[a] += c; mp[b + 1] -= c; } ll ans = 0, now = 0, pre = 0; for(auto [k, v] : mp) { ans += min(now, C)*(k - pre); pre = k; now += v; } print(ans); } signed main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(16); Main(); }
#include <bits/stdc++.h> #define rep(i, n) for(int(i) = 0; (i) < (n); (i)++) #define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++) #define ALL(v) (v).begin(), (v).end() #define LLA(v) (v).rbegin(), (v).rend() #define SZ(v) (v).size() #define INT(...) \ int __VA_ARGS__; \ read(__VA_ARGS__) #define LL(...) \ ll __VA_ARGS__; \ read(__VA_ARGS__) #define DOUBLE(...) \ double __VA_ARGS__; \ read(__VA_ARGS__) #define CHAR(...) \ char __VA_ARGS__; \ read(__VA_ARGS__) #define STRING(...) \ string __VA_ARGS__; \ read(__VA_ARGS__) #define VEC(type, name, size) \ vector<type> name(size); \ read(name) using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using Graph = vector<vector<int>>; template <typename T> struct edge { int to; T cost; edge(int t, T c) : to(t), cost(c) {} }; template <typename T> using WGraph = vector<vector<edge<T>>>; const int INF = 1 << 30; const ll LINF = 1LL << 60; const int MOD = 1e9 + 7; template <class T> inline vector<T> make_vec(size_t a, T val) { return vector<T>(a, val); } template <class... Ts> inline auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec(ts...))>(a, make_vec(ts...)); } void read() {} template <class T> inline void read(T &a) { cin >> a; } template <class T> inline void read(vector<T> &v) { for(auto &a : v) read(a); } template <class T, class S> inline void read(pair<T, S> &p) { read(p.first), read(p.second); } template <class Head, class... Tail> inline void read(Head &head, Tail &... tail) { read(head), read(tail...); } template <class T> inline void chmax(T &a, T &b) { (a < b ? a = b : a); } template <class T> inline void chmin(T &a, T &b) { (a > b ? a = b : a); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); INT(N, W); cout << N / W << endl; }
#include<string> using namespace std; #include<bits/stdc++.h> #define lli long long int #define mods 1000000007 #define pb push_back #define mp make_pair #define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) int main(){ lli n,w; cin>>n>>w; cout<<n/w; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> ii; typedef vector<ii> vii; typedef long double ld; typedef pair<ll, ll> pll; #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 = 1000000007; ll INF = 1000000000; 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 a1, a2, a3; cin >> a1 >> a2 >> a3; int a = min(a1, min(a2, a3)), b = max(a1, max(a2, a3)); if (3 * (a+b) == 2*(a1 + a2 + a3)){ cout << "Yes\n"; }else{ cout << "No\n"; } return 0; }
//#include <bits/stdc++.h> using namespace std; #include <iostream> int main() { int A1,A2,A3; cin>>A1>>A2>>A3; if( A3-A2==A2-A1 || A3-A1==A1-A2 ||A2-A1==A1-A3 ||A2-A3==A3-A1 ||A1-A2==A2-A3 ||A1-A3==A3-A2 ) { cout<<"Yes"<<endl; } else { cout<<"No"<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0; i<(n); i++) typedef long long ll; int main(){ string s; cin>>s; ll cnt=0; for(int k=0; k<10000; k++){ bool ans=true; string r=to_string(k); if(r.size()<4) r=string(4-r.size(),'0')+r; for(int i=0; i<10; i++){ if(s[i]=='o'){ bool flg=false; for(int j=0; j<4; j++){ if(r[j]-'0'==i) flg=true; } if(!flg) ans=false; }else if(s[i]=='x'){ bool flg=true; for(int j=0; j<4; j++){ if(r[j]-'0'==i) flg=false; } if(!flg) ans=false; } } if(ans) cnt++; } cout<<cnt<<endl; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #define int long long #define ll long long #define F(type, i, a, b, incr) for (type i = a; i <= (type)(b); i += (type)(incr)) #define RF(type, i, a, b, decr) for (type i = a; i >= (type)(b); i -= (type)(decr)) #define sz(a) sizeof(a) #define deb(a) cerr << " [" << #a << "->" << a << "] " #define next_line cerr << '\n' #define all(a) a.begin(), a.end() #define iter(it, s) for (auto it = s.begin(); it != s.end(); it++) #define setbits(x) __builtin_popcountll(x) using namespace __gnu_pbds; using namespace std; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; typedef pair<int, int> pii; typedef pair<ll,ll> pll; vector<int> Fact(11); int ncr(int n, int r){ return (Fact[n] / (Fact[n - r] * Fact[r])); } void solve() { string s; cin >> s; int o_c = 0, q_c = 0; for(char c: s){ o_c += (c == 'o'); q_c += (c == '?'); } int ans=0; F(int, i, 0, 9, 1){ if(s[i] == 'x') continue; F(int, j, 0, 9, 1){ if(s[j] == 'x') continue; F(int, k, 0, 9, 1){ if(s[k] == 'x') continue; F(int, l, 0, 9, 1){ if(s[l] == 'x') continue; set<int> st; st.insert(i); st.insert(j); st.insert(k); st.insert(l); int ps_g = o_c; for(int x: st) ps_g = ps_g - (s[x] == 'o'); if(ps_g > 0) continue; ans ++; } } } } cout << ans << '\n'; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // freopen("Debug.txt", "w", stderr); #else #endif Fact[0] = 1; F(int, i, 1, 10, 1){ Fact[i] = Fact[i - 1] * i; } // cout << fixed << setprecision(10); // int _t; // cin>>_t; // F(int, i, 1, _t, 1){ // cout << "Case #" << i << ": "; solve(); // } }
#include <iostream> using namespace std; int main(){ int n; cin >> n; if (n%2 == 0) cout << "White" << endl; else cout << "Black" << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) #define _GLIBCXX_DEBUG int main(){ int N; cin >> N; if(N%2 == 0){ cout << "White" << endl; } else{ cout << "Black" <<endl; } }
#include <iostream> using namespace std; int main() { int n, w; cin >> n >> w; cout << n/w << endl; return 0; }
#include <iostream> using namespace std; //ios::sync_with_stdio(0); //cin.tie(0); int main() { int a, b; cin >> a >> b; int mn = min(a, b); int mx = max(a, b); string ans = mn + 3 > mx ? "Yes" : "No"; cout << ans; return 0; }
#include<bits/stdc++.h> #define ll long long int #define vll vector<ll> #define mod 1e9+7 #define endl "\n" #define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define pb push_back #define inp(V,n) for(int i=0;i<n;i++){cin >> V[i];} #define all(v) v.begin(),v.end() #define allr(v) v.rbegin(),v.rend() #define sz size() #define oup(v,n) {for(int i=0;i<n;i++){cout << v[i] << " " ;} cout << endl; using namespace std; int main() { int t=1; //cin>>t; while(t--) { ll n,m,i; cin>>n; ll ans; vll v; for(i=1;i*i<=2*n;i++) { if(2*n%i==0) { v.pb(i); ans=2*n/i; if(i==ans) continue; else v.pb((2*n)/i); } } ll cnt=0; for(i=0;i<v.size();i++) { ans=(2*n)/v[i]; ll chk=v[i]-1; if((ans-chk)%2==0) cnt++; else continue; } cout<<cnt<<endl; } return 0; }
#pragma GCC optimize("Ofast") #include <iostream> // cout, endl, cin #include <string> // string, to_string, stoi #include <vector> // vector #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <utility> // pair, make_pair #include <tuple> // tuple, make_tuple #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include <map> // map #include <queue> // queue, priority_queue #include <set> // set #include <stack> // stack #include <deque> // deque #include <unordered_map> // unordered_map #include <unordered_set> // unordered_set #include <bitset> // bitset #include <cctype> // isupper, islower, isdigit, toupper, tolower #include <iomanip> // setprecision #include <complex> // complex #include <math.h> #include <cmath> #include <functional> #include <cassert> using namespace std; using ll = long long; using P = pair<ll,ll>; constexpr ll INF = 1e18; constexpr int inf = 1e9; constexpr ll mod = 1000000007; // constexpr ll mod = 998244353; const int dx[8] = {1, 0, -1, 0,1,1,-1,-1}; const int dy[8] = {0, 1, 0, -1,1,-1,1,-1}; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const char eol = '\n'; // -------------------------------------------------------------------------- int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); ll N; cin >> N; N *= 2; int ans = 0; for(ll i=1; i*i<=N; i++){ if(N%i == 0){ ll A = N/i; ll B = i; if(A > B) swap(A,B); // A < B if((A+B-1)%2) continue; if((B-A-1)%2) continue; ll X = (A+B-1)/2; ll Y = (B-A-1)/2; if(X>Y && X>0 && Y>=0){ ans += 2; } } } cout << ans << eol; return 0; }
#include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define rep(i, n) FOR(i, 0, n - 1) using namespace std; typedef long long ll; template <class T> inline bool dpmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class T> inline bool dpmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } const string YES = "Yes"; const string NO = "No"; void solve(long long A, long long B, long long C) { if (A * A + B * B < C*C) { cout << YES << endl; } else { cout << NO << endl; } } // Generated by 2.3.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the // default template now. You can remove this line by using your custom template) int main() { long long A; std::scanf("%lld", &A); long long B; std::scanf("%lld", &B); long long C; std::scanf("%lld", &C); solve(A, B, C); return 0; }
#include<iostream> #include<algorithm> #include<vector> #include<string> #include<cstdlib> #include<cmath> #include<map> #include<queue> #include<stack> #include<set> #include<iomanip> #include<iterator> #include<sstream> using namespace std; const long long mod=1000000007; int main() { long long n,m,t,a,b,k=0,h=0,r; cin>>n>>m>>t; r=n; while(m--) { cin>>a>>b; n-=(a-k); if(n<=0) { h++; } n+=(b-a); if(n>r) { n=r; } k=b; } n-=(t-k); if(n<=0) { h++; } if(h) { cout<<"No"<<endl; } else { cout<<"Yes"<<endl; } return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long signed main() { int V,T,S,D; cin>>V>>T>>S>>D; if(D*1.0/V>=T&&D*1.0/V<=S) cout<<"No\n"; else cout<<"Yes\n"; return 0; }
#include <bits/stdc++.h> #ifdef local #define debug(args...) qqbx(#args, args) template <typename ...T> void qqbx(const char *s, T ...args) { int cnt = sizeof...(T); ((std::cerr << "(" << s << ") = (") , ... , (std::cerr << args << (--cnt ? ", " : ")\n"))); } #else #define debug(...) ((void)0) #endif // local #define pb emplace_back #define all(v) begin(v),end(v) #define endl '\n' #define F first #define S second #define int long long #define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0) #define VI vector<int> #define rep(i,m,n) for(int i = m;i<=n;++i) #define res(i,m,n) for(int i = m;i>=n;--i) #define gcd(a,b) __gcd(a,b) #define lcm(a,b) a*b/gcd(a,b) #define Case() int _;cin>>_;for(int Case = 1;Case<=_;++Case) using namespace std; signed main(){ IOS; double v,t,s,d; cin>>v>>t>>s>>d; double a = d/v; cout<<(string)(t<=a and a<=s?"No\n":"Yes\n"); }
#include<iostream> #include<string> #include<vector> #include<set> #include<iomanip> #include<algorithm> #include<cmath> #include<bitset> #include<queue> #include<stack> using namespace std; typedef long long ll; using Graph = vector<vector<int>>; #define FOR(i,a,b) for(size_t i=(a); i<(b); ++i) #define REP(i, n) FOR(i, 0, n) #define NREP(i, n) FOR(i, 1, n+1) template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } const ll MOD=1000000007; int main(void){ ll n; cin >> n; if(n<=2){ cout << 1 << endl; return 0; } ll sum=0,s=0; NREP(i,n){ sum+=i; if(sum>(n+1)){ s=i; break; } } cout << n-s+2 << endl; }
#include<bits/stdc++.h> using namespace std; int main() { int n; vector<string> s; cin>>n; for(int i=0;i<n;i++) { string temp; cin>>temp; s.push_back(temp); } long long int power[60]; power[0] = 1; for(int i=1;i<=60;i++) power[i] = power[i-1] * 2; int length = s.size()-1; long long int ttl = 0; for(int i=length;i>=0;i--) { if(s[i][0] == 'O') ttl += power[i+1]; } cout<<ttl+1<<"\n"; }
#include<stdio.h> static inline int IN(void) { int x=0,f=0,c=getchar();while(c<48||c>57){f^=(c==45),c=getchar();} while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x; } static inline void OUT(long x){if(x<0){putchar('-'),x=-x;}if(x>=10){OUT(x/10);}putchar(x%10+48);} static inline long Min(long a,long b){return a<b?a:b;} static inline long Max(long a,long b){return a>b?a:b;} int main(void) { int N=IN(),A=0,T=0,Q=0,X=0;long mn=-5e18,mx=5e18,sum=0; while(N--) { A=IN(),T=IN(); if(T==1){sum+=A;mn+=A;mx+=A;} else if(T==2){if(mn<A){mn=A;}if(mx<A){mx=A;}} else{if(mn>A){mn=A;}if(mx>A){mx=A;}} } Q=IN();while(Q--){X=IN();OUT(Min(Max(X+sum,mn),mx));puts("");} }
#include<bits/stdc++.h> #define maxn 200010 #define int long long // #define maxn // #define mod using namespace std; const long long INF=1ll<<60; // template<class T>T ABS(T x) {return x<0?-x:x;} //int ksm(int x,int y) {int r=1;while(y) y&1?r=1ll*r*x%mod:0,x=1ll*x*x%mod,y>>=1;return r;} int read() { int s=0,w=1; char ch=getchar(); while(ch<'0'||ch>'9') {if(ch=='-')w=-1;ch=getchar();} while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48),ch=getchar(); return s*w; } // struct Edge{int to,next;}a[maxn]; // int h[maxn],cnt; // void add(int x,int y) {a[++cnt]=(Edge){y,h[x]},h[x]=cnt,a[++cnt]=(Edge){x,h[y]},h[y]=cnt;} struct Xi{int vl,nm;}X[maxn]; bool cmp(Xi x,Xi y) {return x.vl<y.vl;} int A[maxn],T[maxn],n,Q,pr[maxn]; int ABS(int x) {return x<0?-x:x;} signed main() { // freopen("pai.in","r",stdin); // freopen("pai2.out","w",stdout); n=read(); for(int i=1;i<=n;i++) A[i]=read(),T[i]=read(); Q=read(); for(int i=1;i<=Q;i++) X[i]=(Xi){read(),i}; sort(X+1,X+1+Q,cmp); int l=1,r=Q,tt=0,wl=INF,wr=INF; for(int i=1;i<=n;i++) if(T[i]==1) tt+=A[i],wl+=A[i],wr+=A[i]; else if(T[i]==2) { // cerr<<wl<<' '<<wr<<'\n'; while(l<=Q&&l<r+1&&X[l].vl+tt<A[i]) X[l].vl=A[i]-tt,++l; wl=(ABS(wl-INF)<1e16?A[i]:max(A[i],wl)); if(ABS(wr-INF)>1e16) wr=max(wr,A[i]); // cerr<<wl<<'?'<<wr<<'\n'; } else if(T[i]==3) { // cerr<<wl<<' '<<wr<<'\n'; while(r&&r>l-1&&X[r].vl+tt>A[i]) X[r].vl=A[i]-tt,--r; wr=(ABS(wr-INF)<1e16?A[i]:min(wr,A[i])); if(ABS(wl-INF)>1e16) wl=min(wl,A[i]); // cerr<<wl<<' '<<wr<<'\n'; } else assert(0); for(int i=1;i<=l-1;i++) pr[X[i].nm]=wl; for(int i=r+1;i<=Q;i++) pr[X[i].nm]=wr; for(int i=l;i<=r;i++) pr[X[i].nm]=X[i].vl+tt; for(int i=1;i<=Q;i++) cout<<pr[i]<<'\n'; return 0; } // if(l-1>=r+1) // { // tt=A[i]; // for(int j=i+1;j<=n;j++) // if(T[j]==1) tt+=A[j]; // else if(T[j]==2) tt=max(tt,A[j]); // else if(T[j]==3) tt=min(tt,A[j]); // else assert(0); // for(int j=1;j<=Q;j++) cout<<tt<<'\n'; // return 0; // }
#include <iostream> #include <iomanip> #include <vector> #include <algorithm> using namespace std; using ll = long long; bool comp(const pair<ll, ll> a, const pair<ll, ll> b) { if (a.first == b.first) { return a.second < b.second; } else { return a.first < b.first; } } ll Kth(vector<pair<ll, ll>>& B, ll K) { auto l = lower_bound(B.begin(), B.end(), make_pair(K, INT64_MIN), comp); ll ans; if (l != B.end()) { ans = l->second - (l->first - K + 1); } else { l--; ans = l->second + (K - l->first); } return ans; } void Main() { // input ll N, Q; cin >> N >> Q; vector<ll> A(N); for (ll i = 0; i < N; i++) { cin >> A[i]; } vector<ll> K(Q); for (ll i = 0; i < Q; i++) { cin >> K[i]; } // process vector<pair<ll, ll>> B(N); ll before = 0; ll count = 0; for (ll i = 0; i < N; i++) { count += A[i] - before - 1; before = A[i]; B[i] = make_pair(count, A[i]); } // output for (ll i = 0; i < Q; i++) { ll ans = Kth(B, K[i]); cout << ans << endl; } } int main() { std::cout << std::fixed << std::setprecision(15); Main(); return 0; }
/* * Author: Moon-light */ #include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define mp make_pair #define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0) #define lowbit(x) ((x)&(-x)) #define sz(x) ((int)x.size()) #define fr(x) freopen(x,'r',stdin) #define fw(x) freopen(x,'w',stdout) #define mst(x,a) memset(x,a,sizeof(x)) #define all(a) begin(a),end(a) #define bitcnt(x) (__builtin_popcountll(x)) #define rep(i,a,b) for(int i = (a);i<=(b); ++i) #define per(i,a,b) for(int i = (a);i>=(b); --i) typedef long long LL; typedef pair<int,int> PII; typedef pair<LL,LL> PLL; typedef pair<double,double> PDD; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<double> VB; typedef double db; template <class T> void clear(T& a) { T().swap(a);} template <class T,class S> inline bool upmin(T& a,const S&b){ return a>b ? a=b,1:0;} template <class T,class S> inline bool upmax(T&a, const S&b){ return a<b? a=b,1:0;} //fast read(improved by fread) char buf[1<<21],*p1=buf,*p2=buf; inline int getc(){ return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++; } inline int redi() { int ret = 0,f = 0;char ch = getc(); while (!isdigit (ch)) { if (ch == '-') f = 1; ch = getc(); } while (isdigit (ch)) { ret = ret * 10 + ch - 48; ch = getc(); } return f?-ret:ret; } //global variable const int N = 1; const int mod = 1e9+7; //functions LL qmi(LL a,LL k,LL mod){ LL res = 1; while(k){ if(k&1) res = res*a%mod; k >>= 1; a = a*a%mod; } return mod; } int gcd(int a,int b) { return b==0? a:gcd(b,a%b); } // //code from here! Come on! Have a pleasant experience~ int main() { IO; int a,b,c,d; cin>>a>>b>>c>>d; cout<<min(a,min(b,min(c,d)))<<endl; return 0; }
#include<cstdio> #include<cstring> #include<cmath> #include<cassert> #include<iostream> #include<iomanip> #include<map> #include<unordered_map> #include<set> #include<unordered_set> #include<vector> #include<algorithm> #include<string> #include<queue> using namespace std; #define DEBUG(x) cout<<#x<<"="<<x<<endl #define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl typedef long long ll; const int MAXN=10; const ll MOD=1e9+7; ll _gcd(ll a,ll b){if(b==0)return a;return _gcd(b,a%b);} ll gcd(ll a,ll b){a=abs(a),b=abs(b);if(a<b)swap(a,b);return _gcd(a,b);} ll qpow(ll a,ll n){ll rt=1;while(n){if(n&1)rt=(rt*a)%MOD;a=a*a%MOD;n>>=1;}return rt;} ll factor[MAXN]; void cal_factor(){factor[0]=1;for(int u=1;u<MAXN;u++){factor[u]=(factor[u-1]*u)%MOD;}} ll C(ll n,ll k){if(n<k)return 0;return factor[n]*qpow(factor[n-k],MOD-2)%MOD*qpow(factor[k],MOD-2)%MOD;} template <int _MOD> struct Mint { int v = 0; Mint() {} Mint(int _v) : v((_v%_MOD+_MOD)%_MOD) {} Mint(long long _v) : v(static_cast<int>((_v%_MOD+_MOD)%_MOD)) {} Mint operator = (const int &_v) { return *this = Mint(_v); } Mint operator = (const long long &_v) { return *this = Mint(_v); } bool operator ! () const { return !this->v; } bool operator < (const Mint &b) const { return v < b.v; } bool operator > (const Mint &b) const { return v > b.v; } bool operator == (const Mint &b) const { return v == b.v; } bool operator != (const Mint &b) const { return v != b.v; } bool operator <= (const Mint &b) const { return v < b.v || v == b.v; } bool operator >= (const Mint &b) const { return v > b.v || v == b.v; } Mint operator + (const Mint &b) const { return Mint(v+b.v); } Mint operator - (const Mint &b) const { return Mint(v-b.v); } Mint operator * (const Mint &b) const { return Mint(1ll*v*b.v); } Mint operator / (const Mint &b) const { return Mint(b.inv()*v); } Mint& operator += (const Mint &b) { return *this = *this+b; } Mint& operator -= (const Mint &b) { return *this = *this-b; } Mint& operator *= (const Mint &b) { return *this = *this*b; } Mint& operator /= (const Mint &b) { return *this = *this/b; } Mint operator - () const { return Mint(-v); } Mint& operator ++ () { return *this += 1; } Mint& operator -- () { return *this -= 1; } Mint operator ++ (int) { Mint tmp = *this; *this += 1; return tmp; } Mint operator -- (int) { Mint tmp = *this; *this -= 1; return tmp; } Mint pow(int p) const { Mint res(1), x(*this); while (p) { if (p&1) res = res*x; x *= x; p >>= 1; } return res; } Mint inv() const { return pow(_MOD-2); } friend istream& operator >> (istream &is, Mint &mt) { return is >> mt.v; } friend ostream& operator << (ostream &os, const Mint &mt) { return os << mt.v; } }; using mint = Mint<MOD>; void solve(){ int t; cin>>t; while(t--){ ll n,a,b; cin>>n>>a>>b; if(a+b>n){ cout<<0<<"\n";continue; } mint x=n-a+1, y=n-b+1,z=n-a-b+1; z=z*(z+1); z=x*y-z; cout<<x*x*y*y-z*z<<"\n"; } } // #define LOCAL int main() { #ifdef LOCAL freopen("in.txt","r",stdin); #endif ios::sync_with_stdio(false); cin.tie(0); solve(); }
#include <bits/stdc++.h> constexpr int DEBUG = 0; using namespace std; using int64 = long long; #define REPEAT(i, l, r) for (int i = (int)(l); i < (int)(r); i++) using Complex = complex<double>; int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(10); int n; cin >> n; double x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; Complex c1(x1, y1); Complex c2(x2, y2); Complex c0 = (c1 + c2) * 0.5; Complex c3 = (c1 - c0) * Complex(cos(M_PI * 2.0 / n), sin(M_PI * 2.0 / n)) + c0; cout << c3.real() << " " << c3.imag() << endl; }
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0;i<(n);i++) #define N 100 #define INF 1000000005 #define INFLL (ll)1e17 #define ER 1e-10 #define PI 3.1415926535897 typedef long long ll; #define ALL(v) (v).begin(),(v).end() #define SZ(x) int(x.size()) #define IN(a) cin>>(a) #define OUT(a) cout<<(a)<<endl typedef pair<int,int> P; const int MAX = (1<<20); const int MOD = 998244353; //ダイクストラ法 struct edge{int to,cost;}; vector<edge>G1[MAX],G2[MAX]; int d1[MAX],d2[MAX]; int prever[MAX]; void dijkstra(int s,int V,int d[MAX],vector<edge>G[MAX]){ priority_queue<P,vector<P>,greater<P>>que; for(int i=0;i<V;i++){ d[i]=INF; prever[i]=-1; } d[s]=0; que.push(P(0,s)); while(!que.empty()){ P p=que.top(); que.pop(); int v=p.second; if(d[v]<p.first)continue; for(int i=0;i<G[v].size();i++){ edge e=G[v][i]; if(d[e.to]>d[v]+e.cost){ d[e.to]=d[v]+e.cost; prever[e.to]=v; que.push(P(d[e.to],e.to)); } } } } void solve(){ int n,m; cin>>n>>m; int p=n; REP(i,m){ int a,b,c; cin>>a>>b>>c; a--;b--; if(a==b){ G1[a].push_back({n,0}); G1[n].push_back({a,c}); G2[a].push_back({n,c}); G2[n].push_back({a,0}); n++; }else{ G1[a].push_back({b,c}); G2[b].push_back({a,c}); } } REP(i,p){ dijkstra(i,n,d1,G1); dijkstra(i,n,d2,G2); int tmp=INF; REP(j,n){ if(i==j||d1[j]==INF||d2[j]==INF)continue; tmp=min(tmp,d1[j]+d2[j]); } if(tmp==INF)OUT(-1); else OUT(tmp); } } int main(){ solve(); return 0; }
#include <bits/stdc++.h> #define fir first #define sec second #define PB push_back #define MP make_pair using namespace std; #define REP(i, _a, _b) for (int (i) = (int)(_a); (i) < (int)(_b); (i)++) #define REV(i, _b, _a) for (int (i) = (int)(_b) - 1; (i) >= (int)(_a); (i)--) template <class T> void chkmax(T& x, T y) { x = (x > y ? x : y); } template <class T> void chkmin(T& x, T y) { x = (x < y ? x : y); } typedef long long LL; typedef pair <int, int> pi; const int N = 2e5 + 5; int n, m; void bad() { printf("-1\n"); exit(0); } int main(){ scanf("%d%d", &n, &m); if (m < 0) bad(); if (m == 0){ REP(i, 0, n) printf("%d %d\n", 2 * i + 1, 2 * i + 2); return 0; } if (n < m + 2) bad(); int l = 1, r = 2 * n; for (int i = 1; i <= n - m - 1; i++, l++, r--) printf("%d %d\n", l, r); l--, r++; for (int i = 0; i < m + 1; i++) printf("%d %d\n", 2 * i + 1 + l, 2 * i + 2 + l); return 0; }
#include<bits/stdc++.h> /*--------------->Logic%2==0---------------->*/ #define CASE(t) printf("Case %d: ",t) #define gcd(a,b) __gcd(a,b) #define lcm(a,b) ((a)*(b))/gcd(a,b) #define PI 2*acos(0.0) #define ll long long int #define endl '\n' using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); ll a[4]; cin>>a[0]>>a[1]>>a[2]>>a[3]; sort(a,a+4); if(a[0]+a[2]==a[1]+a[3]) { cout<<"Yes"<<endl; } else if(a[0]+a[3]==a[1]+a[2]) { cout<<"Yes"<<endl; } else if(a[0]+a[1]+a[2]==a[3]) { cout<<"Yes"<<endl; } else { cout<<"No"<<endl; } /*---------->HaPpY CoDiNg----------->*/ return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define REP(i, n) for (int i = 0; i < n; ++i) #define rREP(i, n) for (int i = n - 1; i >= 0; --i) #define FOR(i, a, b) for (int i = a; i <= b; ++i) #define rFOR(i, a, b) for (int i = a; i >= b; --i) #define aFOR(i, V) for (auto i : V) #define ALL(vec) vec.begin(), vec.end() #define rALL(vec) vec.rbegin(), vec.rend() #define INF 1'000'000'007 // 10^9 + 7 #define MOD 1'000'000'007 // 10^9 + 7 #define lINF 1'000'000'000'000'000'007 // 10^18 + 7 void printv(vector<int> v) { REP(i, v.size() - 1) cout << v[i] << " "; cout << v[v.size() - 1] << endl; } void printv(vector<char> v) { REP(i, v.size() - 1) cout << v[i] << " "; cout << v[v.size() - 1] << endl; } void printv(vector<vector<int>> v) { aFOR(v2, v) { REP(i, v2.size() - 1) cout << v2[i] << " "; cout << v2[v2.size() - 1] << endl; } } void printv(vector<vector<char>> v) { aFOR(v2, v) { REP(i, v2.size() - 1) cout << v2[i] << " "; cout << v2[v2.size() - 1] << endl; } } void printv(vector<string> v) { aFOR(i, v) { cout << i << endl; } } // ------------------------------ int main() { vector<int> vec(4); int sum = 0; REP(i, 4) { cin >> vec[i]; sum += vec[i]; } int flag = 0; REP(i, 1 << 4) { int tmp1 = 0; int tmp2 = sum; REP(j, 4) { if (i & (1 << j)) { tmp1 += vec[j]; tmp2 -= vec[j]; } } if (tmp1 == tmp2) flag = 1; } if (flag) cout << "Yes" << endl; else cout << "No" << endl; return 0; }