code_file1
stringlengths
87
4k
code_file2
stringlengths
85
4k
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<vector> #include<cmath> #include<algorithm> #include<map> #include<queue> #include<deque> #include<iomanip> #include<tuple> #include<cassert> #include<set> #include<complex> #include<numeric> #include<functional> #include<unordered_map> #include<unordered_set> using namespace std; typedef long long int LL; typedef pair<int,int> P; typedef pair<LL,LL> LP; const int INF=1<<30; const LL MAX=1e9+7; void array_show(int *array,int array_n,char middle=' '){ for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n')); } void array_show(LL *array,int array_n,char middle=' '){ for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n')); } void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){ if(vec_n==-1)vec_n=vec_s.size(); for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n')); } void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){ if(vec_n==-1)vec_n=vec_s.size(); for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n')); } template<typename T> ostream& operator<<(ostream& os,const vector<T>& v1){ int n=v1.size(); for(int i=0;i<n;i++){ if(i)os<<" "; os<<v1[i]; } return os; } template<typename T1,typename T2> ostream& operator<<(ostream& os,const pair<T1,T2>& p){ os<<p.first<<" "<<p.second; return os; } template<typename T> istream& operator>>(istream& is,vector<T>& v1){ int n=v1.size(); for(int i=0;i<n;i++)is>>v1[i]; return is; } namespace sol{ void solve(){ int n,m; int i,j,k; int a,b,c; cin>>n; vector<P> v1; for(i=0;i<2*n;i++){ cin>>a; v1.push_back({a,i}); } sort(v1.begin(),v1.end()); string ss(2*n,'('); for(i=0;i<n;i++){ a=v1[i].second; ss[a]=')'; } a=-1,b=0; bool flag=false; for(i=0;i<2*n;i++){ if(ss[i]=='(')b++; else b--; if(b<0)flag=true; if(b==0){ if(flag){ for(j=a+1;j<=i;j++){ if(ss[j]=='(')ss[j]=')'; else ss[j]='('; } } a=i; flag=false; } } cout<<ss<<endl; } } int main(){ sol::solve(); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define forn(i,x,n) for(int i = x;i <= n;++i) typedef pair<int,int> pii; #define forr(i,x,n) for(int i = n;i >= x;--i) #define Angel_Dust ios::sync_with_stdio(0);cin.tie(0) #define x first #define y second const int N = 105,MOD = 1e9+7; pii edges[N * N]; int deg[N]; struct Mat { int c[N][N]; Mat() { memset(c,0,sizeof c); } Mat operator*(const Mat& r) const { Mat res; forn(i,1,N - 1) forn(j,1,N - 1) forn(k,1,N - 1) res.c[i][j] = (res.c[i][j] + 1ll*c[i][k] * r.c[k][j] % MOD) % MOD; return res; } void operator*(int r) { forn(i,1,N - 1) forn(j,1,N - 1) c[i][j] = 1ll*c[i][j] * r % MOD; } }; Mat qpow(Mat a,int b,int MOD) { Mat res;forn(i,1,N - 1) res.c[i][i] = 1; while(b) { if(b & 1) res = res * a; a = a * a; b >>= 1; } return res; } int qpow(int a,int b,int MOD) { int res = 1; while(b) { if(b & 1) res = 1ll * res * a % MOD; a = 1ll * a * a % MOD; b >>= 1; } return res; } int main() { // freopen("D://OJCodes//TTT//in.txt","r",stdin); // freopen("D://OJCodes//TTT//out.txt","w",stdout); int n,m,k;scanf("%d%d%d",&n,&m,&k); Mat f,B;forn(i,1,n) scanf("%d",&f.c[1][i]); forn(i,1,m) { int u,v;scanf("%d%d",&u,&v); ++deg[u];++deg[v]; edges[i] = {u,v}; } int m_2fact = qpow(m * 2,MOD - 2,MOD); forn(i,1,m) { int u = edges[i].x,v = edges[i].y; B.c[u][v] = m_2fact; B.c[v][u] = m_2fact; } forn(i,1,n) B.c[i][i] = (2 * m - deg[i]) * 1ll * m_2fact % MOD; B = qpow(B,k,MOD); f = f * B; forn(i,1,n) printf("%d\n",f.c[1][i]); // fclose(stdin); // fclose(stdout); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; template <class T> using vec = vector<T>; template <class T> using vvec = vector<vec<T>>; template<class T> bool chmin(T& a,T b){if(a>b) {a = b; return true;} return false;} template<class T> bool chmax(T& a,T b){if(a<b) {a = b; return true;} return false;} #define all(x) (x).begin(),(x).end() #define debug(x) cerr << #x << " = " << (x) << endl; int main(){ cin.tie(0); ios::sync_with_stdio(false); int N,L; cin >> N >> L; vec<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[N+1] = B[N+1] = L+1; vec<int> C(N+1),D(N+1); for(int i=0;i<=N;i++){ C[i] = A[i+1]-A[i]-1; D[i] = B[i+1]-B[i]-1; } ll ans = 0; int sum = 0,r = 0; for(int i=0;i<=N;i++) if(D[i]){ while(C[r]==0) r++; int l = r; while(r<=N && sum+C[r]<=D[i]){ sum += C[r++]; if(sum==D[i]) break; } if(sum!=D[i]){ cout << "-1\n"; return 0; } if(r<=i) ans += i-l; else if(i<=l) ans += r-i-1; else ans += r-l-1; sum = 0; } cout << ans << "\n"; }
#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; typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> oset; #define sim template < class c #define ris return * this #define dor > debug & operator << #define eni(x) sim > typename \ enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { #ifdef LOCAL ~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } #else sim dor(const c&) { ris; } #endif }; #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " using ll = long long; #define ar array clock_t time_req = clock()*1.0/CLOCKS_PER_SEC; map<int,pair<int,int>> read(int n , int L){ vector<int> v{0}; for(int i = 1 ; i <= n + 1; i++){ int ai = L+1; if(i <= n){ cin >> ai; } v.push_back(ai-i); } map<int,pair<int,int>> interval; for(int i = 0 ; i < (int)v.size() ; i++){ if( i == 0 || v[i] != v[i-1]){ interval[v[i]].first = i; } interval[v[i]].second = i; } return interval; } void test_case() { int n , L; cin >> n >> L; auto a = read(n,L); auto b = read(n,L); debug() << imie(a); debug() << imie(b); ll answer = 0; for(auto pp : b){ int value = pp.first; if(!a.count(value)){ puts("-1"); return; } answer += max(0,a[value].first - b[value].first) + max(0,b[value].second - a[value].second); } cout<<answer<<"\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int T = 1; //cin >> T; while(T--){ test_case(); } }
#include<bits/stdc++.h> #define ll long long using namespace std; const int N=105; int n,m,k; ll f[N][N*N*N]; ll pre[N*N*N]; int main() { cin>>n>>k>>m; const int mod=m; f[0][0]=1; int sum=0; for(int i=1;i<=n;i++) { sum+=i*k; for(int s=0;s<=sum;s++) { /* for(int q=0;q<=k&&i*q<=s;q++) { f[i][s]=(f[i-1][s-q*i]+f[i][s])%mod; }*/ f[i][s]=f[i-1][s]; if(s>=i) f[i][s]+=f[i][s-i]; if(s>=i*(k+1)) f[i][s]-=f[i-1][s-i*(k+1)]; f[i][s]=(f[i][s]+mod)%mod; } } for(int ave=1;ave<=n;ave++) { ll ans=0; int L=ave-1,R=n-ave; for(int j=1;j<=sum;j++) ans=(ans+f[L][j]*f[R][j])%mod; cout<<(ans*(k+1)+k)%mod<<"\n"; } return 0; } /* 2 2 3 1 */
#include <bits/stdc++.h> using namespace std; int main() { long long k,n,m,i,j,cur; cin >> k >> n >> m; vector<long long> a(k),b(k); set<pair<long long,long long>> s; pair<long long,long long> p; cur=0; for(i=0; i<k; i++){ cin >> a[i]; b[i]=((a[i]*m+(n-1))/n); cur+=b[i]; p.first=b[i]*n-a[i]*m; p.second=i; s.insert(p); } cur-=m; auto itr=s.begin(); while(cur>0){ itr=s.end(); itr--; p=*itr; s.erase(itr); b[p.second]--; p.first-=n; s.insert(p); cur--; } for(i=0; i<k; i++){ cout << b[i] << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(){ int N,M; cin >> N >> M; vector<int>A(N); vector<int>B(M); for(int i = 0; i < N; i++){ cin >> A.at(i); } for(int i = 0; i < M; i++){ cin >> B.at(i); } vector<int>cnt(1001); for(int i = 0; i < 1001; i++){ cnt.at(i) = 0; } for(int i = 0; i < N; i++){ cnt.at(A.at(i))++; } for(int i = 0; i < M; i++){ cnt.at(B.at(i))++; } for(int i = 0; i < 1001; i++){ if(cnt.at(i) == 1){ cout << i << " "; } } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0 ; i < (n) ; i++) #define rep1(i,n) for(int i = 1 ; i <= (n) ; i++) #define rrep(i,n) for(int i = (n) - 1 ; i >= 0 ; i--) #define rrep1(i,n) for(int i = (n) ; i > 0 ; i--) #define INF 1001001001 #define MOD 1000000007 using ll = int64_t; using P = pair<int, int>; using PL = pair<ll,ll>; using PD = pair<double,double>; using vi = vector<int>; using vvi = vector<vector<int>>; using vl = vector<ll>; using vvl = vector<vector<ll>>; #define v(n) vector<n> #define vv(n) vector<vector<n>> #define vvv(n) vector<vector<vector<n>>> #define line cout << "================================" << endl; #define Yn(x) cout << ((x) ? "Yes" : "No") << endl; #define yn(x) cout << ((x) ? "yes" : "no") << endl; #define mmax(a,b) a = max(a,b) #define mmin(a,b) a = min(a,b) #define debug(x) cout << #x" : " << x << endl; int main(){ int n, m; cin >> n >> m; vi vec(1001,0); rep(i,n){ int x; cin >> x; vec[x]++; } rep(i,m){ int x; cin >> x; vec[x]++; } rep(i,vec.size()){ if(vec[i] == 1)cout << i << " "; } cout << 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(); int main() { ll n; cin >> n; vl a; while(n > 0) { a.push_back(n % 10); n /= 10; } int m = sz(a); map<int,int> mp; int sum = 0; rep(i,m) { a[i] %= 3; mp[a[i]]++; sum += a[i]; } if(sum % 3 == 0) cout << 0 << "\n"; if(sum % 3 == 1) { if(mp[1] >= 1 && m > 1) cout << 1 << "\n"; else if(mp[2] >= 2 && m > 2) cout << 2 << "\n"; else cout << -1 << "\n"; } if(sum % 3 == 2) { if(mp[2] >= 1 && m > 1) cout << 1 << "\n"; else if(mp[1] >= 2 && m > 2) cout << 2 << "\n"; else cout << -1 << "\n"; } return 0; }
#include<stdio.h> #include<iostream> #include<string.h> #include<algorithm> #include<queue> #include<stack> #include<math.h> #include<map> typedef long long int ll; using namespace std; #define maxn 0x3f3f3f3f #define INF 0x3f3f3f3f3f3f3f3f const int mm=2e5+100; ll d[mm]; ll vis[100000]; int main() { ll n,m,i,j,t,a,b,c,p,k,kk; string s; cin>>s; ll sum=0; for(i=0;i<s.size();i++) { if((s[i]-'0')%3==1) vis[1]++,sum+=1; else if((s[i]-'0')%3==2) vis[2]++,sum+=2; else vis[0]++; } if(sum%3==1) { if(vis[1]==1&&(vis[2]||vis[0])||vis[1]>1) printf("%lld\n",(ll)1); else if(vis[2]==2&&(vis[1]||vis[0])||vis[2]>2) printf("%lld\n",(ll)2); else printf("-1\n"); } else if(sum%3==2) { if(vis[2]==1&&(vis[1]||vis[0])||vis[2]>1) printf("%lld\n",(ll)1); else if(vis[1]==2&&(vis[2]||vis[0])||vis[1]>2) printf("%lld\n",(ll)2); else printf("-1\n"); } else printf("0\n"); }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> pll; #define F(type, i, a, b, incr) for (type i = a; i <= (type)(b); i += (type)(incr)) #define pb push_back #define ppb pop_back #define ff first #define ss second #define iter(it, s) for (auto it = s.begin(); it != s.end(); it++) #define fillc(a,b) memset(a,b,sizeof(a)) #define MOD 1000000007 #define INF 1e17 #define multi_test 0 vector<vector<ll>> v(65,vector<ll>(65,0)); void ncr() { v[0][0]=1; for(ll i=1;i<=60;i++) { v[i][0]=1; //cout<<v[i][0]<<" "; for(ll j=1;j<=i;j++) { v[i][j]=v[i-1][j]+v[i-1][j-1]; //cout<<v[i][j]<<" "; } //cout<<endl; } } void solve() { ll a,b,k,i,j; cin>>a>>b>>k; string s; /*for(i=0;i<=60;i++) { for(j=0;j<=i;j++) cout<<v[i][j]<<" "; cout<<endl; }*/ for(ll i=0;i<a;i++) s+='a'; for(ll i=0;i<b;i++) s+='b'; //cout<<s<<" "; for(ll i=1;i<=b;i++) { ll p=i+a,c=0; //c=v[a+b-p][b-i]; while(k>c) { c=v[a+b-p][b-i]; //cout<<c<<endl; if(k>c) { k-=c; swap(s[p-1],s[p-2]); p--; } } //cout<<a+b-p<<" "<<b-i<<" "<<c<<endl;; } cout<<s<<endl; } int main() { //freopen("input.txt","r",stdin);freopen("output.txt","w",stdout); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ncr(); int t=1,i; if (multi_test) cin>>t; for(i=1;i<=t;i++) solve(); }
/** * @author : xnyuq * @created : 24/05/2021 19:56:30 +07 * @filename : abc202d */ #include <cstdio> #include <iostream> #include <algorithm> #include <vector> #include <set> #include <map> #include <queue> #include <stack> #include <list> #include <chrono> #include <random> #include <cstdlib> #include <cmath> #include <ctime> #include <cstring> #include <iomanip> using namespace std; template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; } void dbg_out() { cerr << endl; } template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); } #ifdef QUYNX_DEBUG #define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__) #else #define dbg(...) #endif const int MX = 35; vector<vector<int64_t>> dp(MX+1, vector<int64_t>(MX+1)); string findKth(int A, int B, int64_t K) { if (A == 0) return string(B, 'b'); if (B == 0) return string(A, 'a'); if (K <= dp[A-1][B]) return "a" + findKth(A-1, B, K); else return "b" + findKth(A, B - 1, K - dp[A-1][B]); } int main() { ios_base::sync_with_stdio(false); #ifndef QUYNX_DEBUG cin.tie(nullptr); #endif int A, B; int64_t K; cin >> A >> B >> K; dp[0][0] = 1; for (int i = 0; i <= A; ++i) { for (int j = 0; j <= B; ++j) { if (i) dp[i][j] += dp[i-1][j]; if (j) dp[i][j] += dp[i][j-1]; } } cout << findKth(A,B,K) << "\n"; }
#include <bits/stdc++.h> #define be(v) (v).begin(),(v).end() #define pb(q) push_back(q) #define rep(i, n) for(int i=0;i<n;i++) #define all(i, v) for(auto& i : v) typedef long long ll; using namespace std; const ll mod=1000000007, INF=(1LL<<60); #define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl; int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); int n, m, a, b; cin >> n >> m; bool ok[n][n]; memset(ok, 0, sizeof(ok)); rep(i, m){ cin >> a >> b; a--; b--; ok[a][b] = ok[b][a] = true; } rep(i, n) ok[i][i] = true; m = 1 << n; bool connect[m]; memset(connect, 0, sizeof(connect)); connect[0] = 1; rep(bit, m){ rep(i, n) if(bit >> i & 1){ if(!connect[bit - (1 << i)]) continue; bool c = true; rep(j, n) if(bit >> j & 1){ if(!ok[i][j]) c = false; } if(c){ connect[bit] = true; break; } } } int cost[m]; rep(i, m) cost[i] = 20; cost[0] = 0; rep(bit, m){ if(connect[bit]) { cost[bit] = 1; continue; } int i = (bit - 1) & bit; for(;i>=1;i=(i-1)&bit){ cost[bit] = min(cost[bit], cost[i] + cost[bit - i]); } } cout << cost[m - 1] << endl; return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <iomanip> #include <iostream> #include <numeric> #include <set> #include <sstream> #include <queue> #include <map> #include <unordered_map> #include <unordered_set> #include <vector> #define rep(i, n) for (int i = 0; i < n; ++i) #define reps(i, s, n) for (int i = s; i < n; i++) #define debug(s, param) std::cerr << s << param << std::endl; using namespace std; using ll = long long; using pi = pair<int, int>; using pl = pair<ll, ll>; const int INF = 1e9; const ll INFL = 1e18; const ll MOD = 1000000007; int main() { ll n, k; cin >> n >> k; map<ll, ll> m; rep (i, n) { ll a, b; cin >> a >> b; m[a] += b; } ll ans = 0; ll current = 0; for (auto [village, money] : m) { ll cost = village - current; if (k >= cost) { ans = village; k -= cost; } else { ans += k; k = 0; break; } k += money; current = village; } ans += k; cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; struct node{long long x,y;}f[200002]; long long n,a=0,b=0,cnt=0; bool cmp(node x,node y){return 2*x.x+x.y>2*y.x+y.y;} int main(){ scanf("%lld",&n); for(int i=0;i<n;++i)scanf("%lld%lld",&f[i].x,&f[i].y),a+=f[i].x; sort(f,f+n,cmp); while(b<=a){b+=f[cnt].x+f[cnt].y;a-=f[cnt].x;++cnt;} printf("%lld",cnt); return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define F(i,a,b) for(int i=(int)(a);i<=(int)(b);i++) #define R(i,b,a) for(int i=(int)(b);i>=(int)(a);i--) #define endl "\n" #define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0) #define out(x) cout<<x<<endl,exit(0) #define pii pair<int,int> #define pb push_back #define all(v) v.begin(),v.end() #define I first #define S second //implementation mistakes: //binary search on unsorted array //1 to 2e5 instead of 0 to 4e5 (bounds) //writing mnn=min(mn,value) //writing n instead of m in bounds //forgot to mod at every step since ai<1e18 and sum would exceed limits //declared the using the global empty string instead of local string //forgot to take input k //intrepreted the question wrongly //wrinting i instead of w[i] //if instead of else if -swapping two times //printing ans without calculating it :):):) int32_t main(){ ios; int n; cin>>n; int sum=0; vector <int> v; F(i,1,n){ int a,b; cin>>a>>b; sum-=a; v.pb(2*a+b); } sort(all(v)); reverse(all(v)); if(sum>0) out(0); F(i,0,n-1){ sum+=v[i]; if(sum>0) out(i+1); } }
#include <bits/stdc++.h> using namespace std; #define lol long long #define mod 1000000007 #define Fast ios_base::sync_with_stdio(false);cin.tie(0); #define rep(i, x, y) for (lol i = x; i <= y; i++) #define repi(i, x, y) for (lol i = x; i >= y; i--) #define TC(x) sci(x); while (x--) #define sci(x) lol x; cin>>x; #define scii(x, y) lol x, y; cin>>x>>y; #define sciii(x, y, z) lol x, y, z; cin>>x>>y>>z; #define F first #define S second #define mp make_pair #define pb push_back int main(){ Fast; scii(x, y); x = min(x, y); scii(z, w); z = min(z, w); cout << min(x, z)<<"\n"; } /*## */
#include<iostream> #include<iomanip> #include<cmath> #include<string> #include<cstring> #include<vector> #include<list> #include<algorithm> #include<map> #include<set> #include<queue> #include<stack> using namespace std; typedef long long ll; #define fi first #define se second #define mp make_pair #define mt make_tuple #define pqueue priority_queue const int inf=1e9+7; const ll mod=1e9+7; const ll mod1=998244353; const ll big=1e18; const double PI=2*asin(1); int main() { int A, B, C, D; cin>>A>>B>>C>>D; cout<<min(A, min(B, min(C, D)))<<endl; }
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); string S; cin >> S; for(int i=0; i<S.length(); i+=2) { if(isupper(S[i])) { cout << "No"; return 0; } } for(int i=1; i<S.length(); i+=2) { if(islower(S[i])) { cout << "No"; return 0; } } cout << "Yes"; return 0; }
#include<iostream> using namespace std; int main() { int n; cin >> n; cout << n-1; }
#include <iostream> #include <tuple> #include <vector> int main() { int N; std::cin >> N; std::vector<std::tuple<int, int>> intervals; for (int i = 0; i < N; ++i) { int t, l, r; std::cin >> t >> l >> r; l = 2 * l + (t >= 3); r = 2 * r - (t % 2 == 0); intervals.emplace_back(l, r); } int count = 0; for (int i = 0; i < N; ++i) { const auto [li, ri] = intervals[i]; for (int j = 0; j < i; ++j) { const auto [lj, rj] = intervals[j]; count += std::max(li, lj) <= std::min(ri, rj); } } std::cout << count << std::endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; // -------------------------------------------------------- template <class T> bool chmax(T& a, const T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T& a, const T b) { if (b < a) { a = b; return 1; } return 0; } #define FOR(i, l, r) for (int i = (l); i < (r); ++i) #define RFOR(i, l, r) for (int i = (r)-1; (l) <= i; --i) #define REP(i, n) FOR(i, 0, n) #define RREP(i, n) RFOR(i, 0, n) #define ALL(c) (c).begin(), (c).end() #define RALL(c) (c).rbegin(), (c).rend() #define SORT(c) sort(ALL(c)) #define RSORT(c) sort(RALL(c)) #define MIN(c) *min_element(ALL(c)) #define MAX(c) *max_element(ALL(c)) #define SUM(c) accumulate(ALL(c), 0) #define SUMLL(c) accumulate(ALL(c), 0LL) #define SZ(c) ((int)(c).size()) #define CIN(c) cin >> (c) #define COUT(c) cout << (c) << '\n' #define debug(x) cerr << #x << " = " << (x) << '\n'; using P = pair<ll, ll>; using VP = vector<P>; using VVP = vector<VP>; using VS = vector<string>; using VI = vector<int>; using VVI = vector<VI>; using VLL = vector<ll>; using VVLL = vector<VLL>; using VB = vector<bool>; using VVB = vector<VB>; using VD = vector<double>; using VVD = vector<VD>; static const double EPS = 1e-10; static const double PI = acos(-1.0); static const ll MOD = 1000000007; // static const ll MOD = 998244353; static const int INF = (1 << 30) - 1; // 1073741824 - 1 // static const ll INF = (1LL << 60) - 1; // 4611686018427387904 - 1 const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; 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; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll N; cin >> N; VD L(N), R(N); REP(i, N) { double t, l, r; cin >> t >> l >> r; if (t == 1) { r += 0.1; } if (t == 3) { l += 0.1, r += 0.1; } if (t == 4) { l += 0.1; } L[i] = l, R[i] = r; } ll ans = 0; REP(i, N) { FOR(t, i + 1, N) { if (L[i] < R[t] && L[t] < R[i]) ans++; // if (max(L[i], L[t]) < min(R[i], R[t])) ans++; } } COUT(ans); }
#include <iostream> #include <cmath> using namespace std; typedef long long ll; int a, b, c; void print() { a < b ? cout << "<" : a == b ? cout << "=" : cout << ">"; } int main() { cin >> a >> b >> c; if (c%2==0) { a = abs(a); b = abs(b); print(); } else { print(); } return 0; }
#include<bits/stdc++.h> #define _GLIBCXX_DEBUG #define rep(i,n) for (ll i = 0; i < (ll)(n); i++) #define Rep(i, j, n) for (ll i = j; i < (n); i++) #define Repr(i, j, n) for (ll i = j; i >= (n); i--) #define all(v) v.begin(),v.end() #define puts(i) cout << i << endl #define INF INT_MAX #define INFL LLONG_MAX 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; } typedef long long ll; using namespace std; #define MOD 1000000007 int main(){ int n,a,b; cin >> n >> a >> b; cout << n-a+b<< endl; }
#include<bits/stdc++.h> using namespace std; #define _ 0 const long long maxn=1e5+5; const long long inf=0x7fffffff; long long n,a[maxn],minv=inf; void dfs(long long k,long long s1,long long s2) { if(k==n+1) { minv=min(minv,s1^s2); return ; } dfs(k+1,s1|a[k],s2); dfs(k+1,a[k],s1^s2); } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); //freopen(".in","r",stdin); //freopen(".out","w",stdout); cin>>n; for(long long i=1;i<=n;i++) cin>>a[i]; dfs(0,0,0); cout<<minv<<endl; return ~~(0^_^0); }
/** * author: MKutayBozkurt * created: 01.04.2021 08:26:08 **/ #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int N; cin >> N; vector<long long> A(N); for (auto &x : A) cin >> x; long long ans = 1e18; for (int i = 0; i < (1 << N); i++) { long long ored = 0, xored = 0; for (int j = 0; j < N; j++) { int k = i & (1 << j); ored |= A[j]; if (k) { xored ^= ored; ored = 0; } } xored ^= ored; ans = min(ans, xored); } cout << ans << '\n'; }
#include<bits/stdc++.h> using namespace std; #define inf 0x3f3f3f3f #define eps 1e-9 #define rep(i,l,r) for(int i=l;i<r;i++) #define rrep(i,r,l) for(int i=r-1;i>=l;i--) typedef long long ll; const int maxn=3e5+5; int n,q,b[maxn]; struct Node{ int l,r,val,mid; void update(int x){ val^=x; } }a[maxn<<2]; void push_up(int x) { a[x].val=a[x<<1].val^a[x<<1|1].val; } void build(int x,int l,int r) { a[x].l=l,a[x].r=r,a[x].mid=(l+r)>>1; if(l!=r){ int mid=a[x].mid; build(x<<1,l,mid); build(x<<1|1,mid+1,r); push_up(x); } else a[x].val=b[l]; } void update(int x,int pos,int val) { a[x].update(val); int l=a[x].l,r=a[x].r; if(l!=r){ int mid=a[x].mid; if(pos<=mid) update(x<<1,pos,val); else update(x<<1|1,pos,val); } } int query(int x,int l,int r) { int L=a[x].l,R=a[x].r; if(l<=L&&R<=r) return a[x].val; else { int mid=a[x].mid,ans=0; if(l<=mid) ans^=query(x<<1,l,r); if(r>mid) ans^=query(x<<1|1,l,r); return ans; } } int main() { cin>>n>>q; rep(i,1,n+1) cin>>b[i]; build(1,1,n); while(q--){ int t,x,y; cin>>t>>x>>y; if(t==1) update(1,x,y); else cout<<query(1,x,y)<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int x, y; cin >> x >> y; vector<vector<int>> cyancheck(51, vector<int>(51)); cyancheck.at(x).at(y) = 1; int k = 2; vector<vector<int>> cyanmond(51, vector<int>(51)); for (int i = 0; i < 50; i++) { for (int j = 0; j < 50; j++) { cin >> cyanmond.at(i).at(j); if(!(j == 0)){ if(cyanmond.at(i).at(j) == cyanmond.at(i).at(j - 1)){ cyancheck.at(i).at(j) = k; cyancheck.at(i).at(j - 1) = k; k++; } } if(!(i == 0)){ if(cyanmond.at(i).at(j) == cyanmond.at(i - 1).at(j)){ cyancheck.at(i).at(j) = k; cyancheck.at(i - 1).at(j) = k; k++; } } } } if(x > 25 && y < 25){ if(!(cyanmond.at(x).at(y) == cyanmond.at(x - 1).at(y)) && !(cyancheck.at(x - 1).at(y) == 1)){ cout << "U"; cyancheck.at(x).at(y) = 1; cyancheck.at(x - 1).at(y) = 1; x = x - 1;} if(!(cyanmond.at(x).at(y) == cyanmond.at(x).at(y + 1)) && !(cyancheck.at(x).at(y + 1) == 1)){ cout << "R"; cyancheck.at(x).at(y) = 1; cyancheck.at(x).at(y + 1) = 1; y = y + 1; } } if(x <= 25 && y < 25){ if(!(cyanmond.at(x).at(y) == cyanmond.at(x + 1).at(y)) && !(cyancheck.at(x + 1).at(y) == 1)){ cout << "D"; cyancheck.at(x).at(y) = 1; cyancheck.at(x + 1).at(y) = 1; x = x + 1;} if(!(cyanmond.at(x).at(y) == cyanmond.at(x).at(y + 1)) && !(cyancheck.at(x).at(y + 1) == 1)){ cout << "R"; cyancheck.at(x).at(y) = 1; cyancheck.at(x).at(y + 1) = 1; y = y + 1; } } if(x > 25 && y >= 25){ if(!(cyanmond.at(x).at(y) == cyanmond.at(x - 1).at(y)) && !(cyancheck.at(x - 1).at(y) = 1)){ cout << "U"; cyancheck.at(x).at(y) = 1; cyancheck.at(x - 1).at(y) = 1; x = x - 1;} if(!(cyanmond.at(x).at(y) == cyanmond.at(x).at(y - 1)) && !(cyancheck.at(x).at(y - 1) == 1)){ cout << "L"; cyancheck.at(x).at(y) = 1; cyancheck.at(x).at(y + 1) = 1; y = y + 1; } } if(x <= 25 && y >= 25){ if(!(cyanmond.at(x).at(y) == cyanmond.at(x + 1).at(y)) && !(cyancheck.at(x + 1).at(y) == 1)){ cout << "D"; cyancheck.at(x).at(y) = 1; cyancheck.at(x + 1).at(y) = 1; x = x + 1;} if(!(cyanmond.at(x).at(y) == cyanmond.at(x).at(y - 1)) && !(cyancheck.at(x).at(y - 1) == 1)){ cout << "L"; cyancheck.at(x).at(y) = 1; cyancheck.at(x).at(y - 1) = 1; y = y - 1; } } }
#include <bits/stdc++.h> using namespace std; int main(int argc, const char *argv[]) { int n; cin >> n; vector<int> va(n); for (int i = 0; i < n; ++i) { cin >> va[i]; } int max_p = 3 * pow(10, 5); vector<int> cnts(max_p, 0); int cur = 0; vector<int> ans; for (int i = 0; i < n; ++i) { cnts[va[i]]++; while (cnts[cur] > 0) { cur++; } ans.push_back(cur); } for (int i = 0; i < ans.size(); ++i) { cout << ans[i] << '\n'; } return 0; }
#define _CRT_SECURE_NO_WARNINGS #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef vector <int> vi; typedef vector <ll> vll; typedef vector <string> vS; typedef vector <vector <int>> vv; typedef map<int, int> mi; typedef map<string, int> ms; typedef map<char, int> mc; typedef string S; typedef map <ll, ll> ml; typedef map <int, bool> mb; typedef vector <ld> vld; typedef vector <bool> vb; typedef map<ll, ll> mll; #define FOR(i,N) for(int i = 0 ; i < N;i++) #define eFOR(i,a,b) for(int i = a; i <=b;i++) #define dFOR(i,N) for(int i = N - 1; i>=0;i--) #define edFOR(i,a,b) for(int i = b ; i >=a;i--) #define all(x) x.begin(),x.end() #define SORT(x) sort(all(x)) #define RSORT(x) sort(x.rbegin(),x.rend()) #define mine(x) min_element(all(x)) #define maxe(x) max_element(all(x)) #define pb push_back #define PI 3.14159265359 const int mod = 1e9 + 7; int CASE = 1; ll __gcd(ll a, ll b) { return !b ? a : __gcd(b, a % b); } void solve() { int n; cin >> n; mb mp; int k = 0; FOR(i, n) { int x; cin >> x; mp[x] = true; while (mp[k]) k++; cout << k << endl; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int T = 1; while (T--) { solve(); } }
#include<bits/stdc++.h> using namespace std; const int mod=1e9+7; int a[105]; long long E[105][105],A[105][105],B[105][105],C[105][105]; long long qpow(long long x,int n){ long long ans=1; for(;n;n>>=1,x=x*x%mod)if(n&1)ans=ans*x%mod; return ans; } void mul(long long a[105][105],int n){ for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ C[i][j]=0; for(int k=1;k<=n;k++)C[i][j]=(C[i][j]+a[i][k]*a[k][j])%mod; } } for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)a[i][j]=C[i][j]; } void mul(long long a[105][105],long long b[105][105],int n){ for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ C[i][j]=0; for(int k=1;k<=n;k++)C[i][j]=(C[i][j]+a[i][k]*b[k][j])%mod; } } for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)a[i][j]=C[i][j]; } void Mqpow(int n,int k){ for(int i=1;i<=n;i++)A[i][i]=1; for(;k;k>>=1,mul(E,n))if(k&1)mul(A,E,n); } int main(){ int n,m,k; scanf("%d%d%d",&n,&m,&k); for(int i=1;i<=n;i++)scanf("%d",&a[i]); for(int i=1;i<=n;i++)E[i][i]=1; int I=qpow(m,mod-2),I2=qpow(2*m,mod-2); for(int i=0;i<m;i++){ int u,v; scanf("%d%d",&u,&v); E[u][u]=(E[u][u]-I2+mod)%mod; E[v][v]=(E[v][v]-I2+mod)%mod; E[u][v]=(E[u][v]+I2)%mod; E[v][u]=(E[v][u]+I2)%mod; } Mqpow(n,k); for(int i=1;i<=n;i++){ long long ans=0; for(int j=1;j<=n;j++)ans=(ans+A[i][j]*a[j])%mod; printf("%lld\n",ans); } }
#include<bits/stdc++.h> // #pragma optimize("-O3") // #pragma GCC optimize("Ofast") // #pragma GCC optimize("unroll-loops") // #pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,avx,mmx,tune=native") using namespace std; #define pb push_back #define mp make_pair #define ff first #define ss second #define INF 1e9 //#define BIG_INF 1e18 #define vi vector<ll> #define sz(a) ll((a).size()) #define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1) // #include <ext/pb_ds/assoc_container.hpp> // Common file // #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update // typedef tree< // ll, // null_type, // less<ll>, // rb_tree_tag, // tree_order_statistics_node_update> // ordered_set; typedef long long ll; const ll BIG_INF = 3e18; ll mod = 1e9+7; ll fast_exp(ll a, ll b) { if(b <= 0) return 1; else { ll res = 1; res = fast_exp(a,b/2); res = (res*res)%mod; if(b%2 == 1) res = (res*a)%mod; return res; } } typedef long double ld; const long long N = 1e5+1000; const long double pi = acos(-1.0); using cd = complex<double>; const double PI = acos(-1); int par[2][N] = {}; int comp[2] = {}; int find_par(int v, int mode) { if(par[mode][v] == v) return v; else return par[mode][v] = find_par(par[mode][v],mode); } void union_find(int a, int b, int mode) { a = find_par(a,mode); b = find_par(b,mode); if(a != b) { par[mode][a] = b; comp[mode]--; } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); //freopen("input.txt","r",stdin); int h, w; cin >> h >> w; char a[h][w] = {}; for(int i = 0; i<h; i++) for(int j = 0; j<w; j++) { cin >> a[i][j]; } a[0][0] = '#'; a[h-1][0] = '#'; a[0][w-1] = '#'; a[h-1][w-1] = '#'; for(int i = 0; i<h; i++) par[0][i] = i; comp[0] = h; for(int i = 0; i<w; i++) par[1][i] = i; comp[1] = w; for(int category = 0; category < w; category++) { int prev = -1; for(int i = 0; i<h; i++) { if(a[i][category] == '#') { if(prev == -1) prev = i; else { union_find(prev,i,0); prev = i; } } } } for(int category = 0; category < h; category++) { int prev = -1; for(int i = 0; i<w; i++) { if(a[category][i] == '#') { if(prev == -1) prev = i; else { union_find(prev,i,1); prev = i; } } } } int ans = min(comp[0],comp[1]); ans--; cout << ans << '\n'; // cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ; return 0; }
//#include <bits/stdc++.h> #include<iostream> #include<cstdio> #include<cmath> #include<string> #include<algorithm> #include<vector> #include<stack> #include<queue> #include<map> #include<set> #define FOR(i,a,b) for(int i=(a);i<(b);i++) #define REP(i,n) FOR(i,0,n) #define pb push_back #define INF 2e9 using namespace std; typedef long long ll;//int64 typedef unsigned long long ull; struct Edge{int to; ll w; Edge (int to, ll w) : to(to), w(w) {} }; typedef vector<vector<int> > Graph; typedef vector<vector<Edge> > Graphw; ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} int dx[4]={1,0,-1,0}; int dy[4]={0,1,0,-1}; template<class T> void chmax(T& a, T b){if(a<b)a=b;} template<class T> void chmin(T& a, T b){if(a>b)a=b;} string s1,s2,s3,S; map<char, int> mp; vector<char> vec; ll kind; int P[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; int main(){ cin >> s1 >> s2 >> s3; S = s1+s2+s3; REP(i,S.length()){ vec.pb(S[i]); } sort(vec.begin(),vec.end()); vec.erase(unique(vec.begin(), vec.end()), vec.end()); REP(i,vec.size()){ mp[vec[i]] = 0; } kind = vec.size(); if(kind > 10){ cout << "UNSOLVABLE"<<endl; return 0; } do { ll n1=0,n2=0,n3=0; REP(i,mp.size()){ mp[vec[i]]=P[i]; } if(mp[s1[0]]==0 || mp[s2[0]]==0 ||mp[s3[0]]==0)continue; //n1 REP(i,s1.length()){ n1 = n1*10 + mp[s1[i]]; } REP(i,s2.length()){ n2 = n2*10 + mp[s2[i]]; } REP(i,s3.length()){ n3 = n3*10 + mp[s3[i]]; } if(n1+n2==n3){ cout<<n1<<endl<<n2<<endl<<n3<<endl; return 0; } } while(next_permutation(P, P + 10)); cout << "UNSOLVABLE"<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vint; typedef vector<vector<int> > vvint; typedef vector<long long> vll, vLL; typedef vector<vector<long long> > vvll, vvLL; #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) for(int i=0;i<n;++i) #define mod (ll)(1e9+7) #define FIX(a) ((a)%mod+mod)%mod #define ALL(obj) (obj).begin(), (obj).end() #define rALL(obj) (obj).rbegin(), (obj).rend() #define INF 1000000000 //1e9 #define LLINF 2000000000000000000LL //2e18 #define fi first #define se second #define pb push_back int dy[]={0, 0, 1, -1}; int dx[]={1, -1, 0, 0}; int main(){ cin.tie(0); ios::sync_with_stdio(false); vector<string> s(3); REP(i,3) cin >> s[i]; string nm; REP(i,26){ char c = (char)('a'+i); REP(j,3){ bool f = false; for(char ci : s[j]){ if(ci==c){ f= true; break; } } if(f){ nm += c; break; } } } int nx = nm.size(); if(nx>10){ cout << "UNSOLVABLE" << endl; return 0; } vector<char> v(10); REP(i,10) v[i]=(char)('0'+i); do { vector<char> vc(26); REP(i,nx){ vc[(int)(nm[i]-'a')] = v[i]; } bool f = false; REP(i,3){ if(vc[(int)(s[i][0]-'a')]=='0'){ f=true; } } if(f) continue; vector<string> t(3,""); REP(i,3){ for(char c:s[i]){ t[i] += vc[(int)(c-'a')]; } } ll a,b,c; a = stoll(t[0]); b = stoll(t[1]); c = stoll(t[2]); if(a+b==c){ REP(i,3){ cout << t[i] << endl; } return 0; } } while( next_permutation(v.begin(), v.end()) ); cout << "UNSOLVABLE" << endl; return 0; }
#include "bits/stdc++.h" #include<sstream> using namespace std; typedef long long ll; #define _USE_MATH_DEFINES #include <math.h> #define NIL = -1; #define all(x) x.begin(),x.end() const ll INF = 1e9; const long long inf = 1e18; const ll INFL = 1e18; const ll MOD = 1e9 + 7; int digit(ll x) { int digits = 0; while(x > 0){ x /= 10; digits++; } return digits; } ll gcd(long long a,long long b) { if (a < b) swap(a,b); if (b == 0) return a; return gcd(b,a%b); } bool is_prime(long long N){ if (N == 1) return false; for (long long i = 2;i * i <= N;i++){ if (N % i == 0) return false; } return true; } ll lcm(ll a,ll b){ return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b); } double DegreeToRadian(double degree){ return degree * M_PI / 180.0; } long long modpow(long long a, long long b, long long m){ long long ans = 1; while(b > 0){ if (b % 2 == 1){ ans *= a; ans %= m; } a *= a; a %= m; b /= 2; } return ans; } long long comb(long long x, long long y){ int z; if (y == 0) return 1; else { z = modpow(x, y/2, MOD)*modpow(x, y/2, MOD)%MOD; if (y % 2 == 1) z = z*x%MOD; return z; } } vector<long long> fact(long long x){ vector<long long> res; for(int i = 1;i*i <= x;i++){ if (x % i == 0){ res.push_back(i); res.push_back(x / i); } } return res; } bool isprime(int p){ if (p == 1) return false; for(int i = 2;i < p;i++){ if (p % i == 0){ return false; } } return true; } vector<pair<long long, long long>> prime_fact(long long x){ vector<pair<long long, long long>> res; for(int i = 2;i*i <= x;i++){ if (x % i == 0){ long long cnt = 0; while(x % i == 0){ cnt++; x /= i; } res.push_back({i, cnt}); } } if (x != 1){ res.push_back({x, 1}); } return res; } int64_t mod_inv(int64_t a, int64_t m){ int64_t b = m, u = 1, v = 0; while(b){ int64_t t = a/b; a -= t*b; swap(a, b); u -= t*v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } // {g, x, y}: ax + by = g tuple<long long, long long, long long> extgcd(long long a, long long b){ if (b == 0) return {a, 1, 0}; long long g, x, y; tie(g, x, y) = extgcd(b, a % b); return {g, y, x - a/b*y}; } int dx[4] = {0,1,0,-1}; int dy[4] = {1,0,-1,0}; ////////////////////////// int main(){ int n, m; cin >> n >> m; vector<int> a(n); for(int i = 0;i < n;i++){ cin >> a[i]; } set<int> st; for(int i = 0;i <= n;i++){ st.insert(i); } int ans = n; vector<int> cnt(n, 0); for(int i = 0;i < m;i++){ cnt[a[i]]++; if (cnt[a[i]] == 1) st.erase(a[i]); } ans = min(ans, *st.begin()); for(int i = m;i < n;i++){ cnt[a[i]]++; cnt[a[i - m]]--; if (a[i] != a[i - m]){ if (cnt[a[i]] == 1) st.erase(a[i]); if (cnt[a[i - m]] == 0) st.insert(a[i - m]); } ans = min(ans, *st.begin()); } cout << ans << endl; }
#include<bits/stdc++.h> // 数値型 using ll= long long; using ull= unsigned long long; using i8 = int8_t; using u8 = uint8_t; using i16 = int16_t; using u16 = uint16_t; using i32 = int32_t; using u32 = uint32_t; using i64 = int64_t; using u64 = uint64_t; using f32 = float; using f64 = double; //イテレーション #define REP(i,n) for(ll i=0;i<ll(n);i++) #define REPD(i,n) for(ll i=n-1;i>=0;i--) #define FOR(i,a,b) for(ll i=a;i<=ll(b);i++) #define FORD(i,a,b) for(ll i=a;i>=ll(b);i--) #define FORA(i,I) for(const auto& i:I) #define FORB(i,I) for(auto& i:I) //x:コンテナ #define ALL(x) x.begin(),x.end() #define SIZE(x) ll(x.size()) //定数 #define INF (int)1e9 //10^9:∞ #define LLINF (long long)1e18 #define PI 3.141592653589 // #define MOD 1000000007 //問題による // #define MOD (int)1e9+7 //10^9+7:合同式の法 //略記 #define FS first #define SC second #define PB push_back #define Graph vector<vector<ll>> #define Pll2 pair<ll,ll> #define Vll vector<ll> #define VVll vector<vector<ll>> #define VPll2 vector<pair<ll,ll>> #define DDD fixed<<setprecision(10) //出力(空白区切りで昇順に) #define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;} #define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;} #define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;} #define coutALL(x) for(auto iii=x.begin();iii!=--x.end();iii++)cout<<*iii<<" ";cout<<*--x.end()<<endl; #define coutline cout<<"======================================================="<<endl; #define coutlinec(x) cout<<string(55, x)<<endl; //その他 #define __MAGIC__ ios::sync_with_stdio(false);cin.tie(nullptr); using namespace std; #define CPP_STR(x) CPP_STR_I(x) #define CPP_CAT(x,y) CPP_CAT_I(x,y) #define CPP_STR_I(args...) #args #define CPP_CAT_I(x,y) x ## y #define ASSERT(expr...) assert((expr)) /*..................DEFINE GLOBAL VARIABLES...................*/ /*.....................DEFINE FUNCTIONS ......................*/ #define sqr(x) ((x) * (x)) // xの二乗値を求める #define cub(x) ((x) * (x) * (x)) // xの三乗値を求める //aをbで割る時の繰上げ,繰り下げ ll myceil(ll a,ll b){return (a+(b-1))/b;} ll myfloor(ll a,ll b){return a/b;} /*.........................MAIN...........................*/ signed main() { //小数の桁数の出力指定 //cout<<fixed<<setprecision(10); __MAGIC__ // ll N, M; cin >> N >> M; // ll sz = N+1; VVll pos(sz, Vll(1, -1)); REP(i, N) { ll a; cin >> a; pos[a].PB(i); } // REP(i, sz){ pos[i].PB(N); } // REP(i, sz) { ll pos_size = SIZE(pos[i]); // coutALL(pos[i]); REP(j, pos_size-1) { if ((pos[i][j+1] - pos[i][j]) > M) { cout << i << endl; return 0; } } } // return 0; }
#include<bits/stdc++.h> using namespace std; ///******************************** C o n t a i n e r ********************************/// typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef vector<pii> vii; typedef vector<pll> vll; ///*********************************** C o n s t ***********************************/// const int N=1e6+123; const double PI = acos(-1); const ll MOD=1000000007; ///1e9+7 ll dx[] = {+1, 0, -1, 0, +1, +1, -1, -1}; ///first 4 for adjacent ll dy[] = {0, +1, 0, -1, +1, -1, +1, -1}; ll dx8[]= {+1, +1, -1, -1, +2, +2, -2, -2}; ///knights move ll dy8[]= {+2, -2, +2, -2, +1, -1, +1, -1}; ///********************************** M a r c o ***********************************/// #define pb push_back #define MP make_pair #define F first #define S second #define test int tc; cin>>tc; while(tc--) #define forn(i,n) for(i=0;i<n;i++) #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define sz(x) x.size() #define el <<'\n' #define sp <<' ' #define print(a) {for(auto x:a)cout<<x<<" ";cout<<endl;} #define mem(a,b) memset(a, b, sizeof(a)) #define gcd(a,b) __gcd(a,b) #define lcm(a,b) (a*(b/gcd(a,b))) #define sqr(a) (a)*(a) #define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout); #define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield); ///*********************************** F u n c t i o n ***********************************/// ll powmod(ll a,ll b){ a%=MOD;if(!a) return 0;ll pr=1;while(b>0){if(b&1){pr*=a;pr%=MOD;--b;}a*=a;a%=MOD;b/=2;}return pr;} ll modinverse(ll a){return powmod(a,MOD-2);} bool isPrime(ll n){ if(n<=1)return false;if(n<=3)return true;if(n%2==0 or n%3==0)return false;for(ll i=5;i*i<=n;i+=6){if(n%i==0 or n%(i+2)==0)return false;}return true;} void seive(bool a[]){ll mx=sqrt(N),ii,jj;for(ii=3;ii<=mx;ii+=2)if(!a[ii])for(jj=ii*ii;jj<N;jj+=2*ii)a[jj]=true;} void numofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<N;jj+=ii){if(jj==ii*ii) a[jj]++; else a[jj]+=2;}}} void sumofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<N;jj+=ii){if(jj==ii*ii) a[jj]+=ii; else a[jj]+=ii+jj/ii;}}} ///**************************************************** C o d e ****************************************************/// ///-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=/// void _case() { ll n,k,i,ans=0; cin>>n>>k; k=abs(k); vl v; v.pb(1), v.pb(2); for(i=2;i<=2*n;i++) v.pb(min(i-1,2*n+1-i)); for(i=2;i+k<=2*n;i++) ans+= (v[i]*v[i+k]); cout<<ans el; } main() { fastio(); _case(); } ///Thank you. ///Brainless_Loco Terminates Here!
#include <bits/stdc++.h> #define ll long long #define F first #define S second #define FF first.first #define FS first.second #define pb push_back using namespace std; const ll N=1000006, INF=1e18, MOD=998244353; int n, k; ll ans; int main(){ios_base::sync_with_stdio(false), cin.tie(0); cin>>n>>k; for (int i=max(1, k+2); i<=2*n; i++){ if(i-k>2*n)break; int j=i-k; ans+=(ll)min((i-1), 2*n-i+1)*min((j-1), 2*n-j+1); } cout<<ans; }
#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; #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" vector<int>to[100005]; int dp[100005]; int sz[100005]; void dfs(int v, int p = -1) { int csub = 0; dp[v] = 1; sz[v] = 1; vector<int>c; for (int e : to[v]) { if (p == e) { continue; } dfs(e, v); sz[v] += sz[e]; int num = dp[e]; if ((num < 0) && (0 == (sz[e] % 2))) { //case1 dp[v] += num; } else if ((num >= 0) && (0 == (sz[e] % 2))) { //case2 csub += num; } else { //case3 c.push_back(num); } } sort(all(c)); c.push_back(csub); rep(i, c.size()) { if (0 == i % 2) { dp[v] += c[i]; } else { dp[v] -= c[i]; } } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; rep(i, N - 1) { int p; cin >> p; p--; to[i + 1].push_back(p); to[p].push_back(i + 1); } dfs(0); int ans = (dp[0] + N) / 2; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; // For Policy Based DS #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; // --------------------------------------- #define endl "\n" #define ff first #define ss second #define int long long #define pb emplace_back #define mp make_pair #define pll pair<int,int> #define vll vector<int> #define vpll vector<pair<int,int>> #define all(c) (c).begin(), (c).end() #define bs binary_search #define pqb priority_queue<int> #define setbits(x) __builtin_popcountll(x) #define mod 1000000007 #define mem(arr,x) memset(arr,x,sizeof(arr)) #define pi 3.14159265358979323846 #define inf 2000000000000000000 #define ps(x,y) fixed<<setprecision(y)<<x #define test(x) int x; cin>>x;while(x--) template<class A> void read(vector<A>& v); template<class A, size_t S> void read(array<A, S>& a); template<class T> void read(T& x) { cin >> x; } void read(double& d) { string t; read(t); d = stod(t); } void read(long double& d) { string t; read(t); d = stold(t); } template<class H, class... T> void read(H& h, T&... t) { read(h); read(t...); } template<class A> void read(vector<A>& x) { for (auto &a : x) read(a); } template<class A, size_t S> void read(array<A, S>& x) { for (auto &a : x) read(a); } const int d4i[4] = { -1, 0, 1, 0}; const int d4j[4] = {0, 1, 0, -1}; const int d8i[8] = { -1, -1, 0, 1, 1, 1, 0, -1}; const int d8j[8] = {0, 1, 1, 1, 0, -1, -1, -1}; void c_p_c() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input", "r", stdin); freopen("output", "w", stdout); #endif } string int_to_string(int n) { ostringstream str1; str1 << n; string sar = str1.str(); return sar; } int pow(int a, int b, int m) { int res = 1; while (b > 0) { if (b % 2) res = (res * a) % m; a = (a * a) % m; b >>= 1; } return res; } int ncr(int n, int k) { if (k == 0) return 1; if (k > n - k) k = n - k; int a = 1, b = 1, d; while (k) { a *= n; b *= k; d = __gcd(a, b); a /= d; b /= d; n--; k--; } return a; } int modinv(int k, int m) { return pow(k, m - 2, m); } /***************************CODE BEGINS**************************************/ void solve () { int n; read(n); int A[n+2]; for(int i=1;i<=n;i++) cin>>A[i]; int ans=-inf; for(int i=1;i<=n;i++){ int t=inf; for(int j=i;j<=n;j++){ t=min(t,A[j]); int k=t*(j-i+1); ans=max(ans,k); } } cout<<ans; } int32_t main() { c_p_c(); // test(x) solve(); // int count=1; // test(x){ // cout<<"Case #"<<count<<": "; // count++; // solve(); // } return 0; }
//#define _GLIBCXX_DEBUG #include<bits/stdc++.h> #include<algorithm>//next_permutation #define rep(i,n) for (int i = 0;i < (n);i++) #define all(v) v.begin(),v.end() #define dec(n) cout << fixed << setprecision(n); #define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ" #define small "abcdefghijklmnopqrstuvwxyz" using namespace std; using ll = long long; using P = pair<ll,ll>; using vl = vector<ll>; using vvl = vector<vl>; ll gcd(ll a,ll b){ if(b == 0) return a; return gcd(b , a % b); } const ll MOD = 1000000007; const ll MAX = 2000001; ll mod(ll a){ return a % MOD; } ll lcm(ll a,ll b){ return (a*b)/gcd(a,b); } vector<pair<ll,ll>> prime_factorize(ll n){ vector<pair<ll,ll>> res; for(ll i=2; i*i <= n; i++){ if(n % i != 0) continue; ll ex = 0; while(n % i == 0){ ex++; n /= i; } res.push_back({i,ex}); } if(n != 1) res.push_back({n,1}); return res; } int main(){ ll x,y,a,b; cin >> x >> y >> a >> b; ll cnt = 0; rep(i,100000000){ if(double(a-1)*x < b and double(a*x) < y){ cnt++; x *= a; } else break; } //cout << cnt << endl; cnt += (y-x-1)/b; cout << cnt << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) #define P pair<int,int> int main() { ll N; cin >> N; int cnt = 0; for(ll i=1;i*(i-1)<2*N;i++){ ll a = N-i*(i-1)/2; if(a%i==0) cnt++; } cout << 2*cnt << endl; }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define eb emplace_back #define x first #define y second #define FOR(i, m, n) for (ll i(m); i < n; i++) #define DWN(i, m, n) for (ll i(m); i >= n; i--) #define REP(i, n) FOR(i, 0, n) #define DW(i, n) DWN(i, n, 0) #define F(n) REP(i, n) #define FF(n) REP(j, n) #define D(n) DW(i, n) #define DD(n) DW(j, n) using ll = long long; using ld = long double; using pll = pair<ll, ll>; using tll = tuple<ll, ll, ll>; using vll = vector<ll>; using vpll = vector<pll>; using vtll = vector<tll>; using gr = vector<vll>; using wgr = vector<vpll>; void add_edge(gr&g,ll x, ll y){ g[x].pb(y);g[y].pb(x); } void add_edge(wgr&g,ll x, ll y, ll z){ g[x].eb(y,z);g[y].eb(x,z); } template<typename T,typename U> ostream& operator<<(ostream& os, const pair<T,U>& p) { cerr << ' ' << p.x << ',' << p.y; return os; } template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { for(auto x: v) os << ' ' << x; return os; } template <typename T> ostream& operator<<(ostream& os, const set<T>& v) { for(auto x: v) os << ' ' << x; return os; } template<typename T,typename U> ostream& operator<<(ostream& os, const map<T,U>& v) { for(auto x: v) os << ' ' << x; return os; } struct d_ { template<typename T> d_& operator,(const T& x) { cerr << ' ' << x; return *this;} } d_t; #define dbg(args ...) { d_t,"|",__LINE__,"|",":",args,"\n"; } #define deb(X ...) dbg(#X, "=", X); #define EPS (1e-10) #define INF (1LL<<61) #define YES(x) cout << (x ? "YES" : "NO") << endl; #define CL(A,I) (memset(A,I,sizeof(A))) #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() int main(void) { ios_base::sync_with_stdio(false); ll a,b,c,d; cin >> a >> b >> c >> d; cout << b-c << endl; return 0; }
#include<bits/stdc++.h> using namespace std; using ll = int64_t; using P = pair<int,int>; #define rep(i, n) for (int i = 0; i < (ll)(n); i++) #define INF 1e9 int main(){ int a,b,c,d; cin>>a>>b>>c>>d; cout<<max(a,b)-min(c,d)<<endl; }
#include <bits/stdc++.h> #define Rep(i,n) for(int i=0;i<n;i++) #define Repr(i,n) for(int i=n;i>=0;i--) #define For(i,m,n) for(int i=m;i<n;i++) #define All(v) v.begin(),v.end() #define Mod (ll)(1e9+7) using namespace std; typedef long long ll; typedef long double ld; typedef vector<long long> vl; const int Inf = INT_MAX / 2; const ll Infl = 1LL << 60; template<class T>bool chmax(T& a,const T& b){if(a<b){a=b;return 1;}return 0;} template<class T>bool chmin(T& a,const T& b){if(b<a){a=b;return 1;}return 0;} int H, W; string A[2020]; bool vis[2020][2020]; int memo[2020][2020]; int dp(int x, int y) { if(vis[y][x]) return memo[y][x]; vis[y][x] = true; int turn = (x + y) % 2; if(x==W-1 && y==H-1)return memo[y][x]=0; if(turn==0) { // Takahashi memo[y][x]=-Inf; if(y<H-1)chmax(memo[y][x],dp(x,y+1)+(A[y+1][x]=='+'?1:-1)); if(x<W-1)chmax(memo[y][x],dp(x+1,y)+(A[y][x+1]=='+'?1:-1)); return memo[y][x]; } else { // Aoki memo[y][x] = Inf; if(y<H-1)chmin(memo[y][x],dp(x,y+1)-(A[y+1][x]=='+'?1:-1)); if(x<W-1)chmin(memo[y][x],dp(x+1,y)-(A[y][x+1]=='+'?1:-1)); return memo[y][x]; } } int main() { cin>>H>>W; For(y,0,H)cin>>A[y]; int opt=dp(0,0); if(0<opt)cout<<"Takahashi"<<endl; else if(opt==0)cout<<"Draw"<<endl; else cout<<"Aoki"<<endl; return 0; }
#include<iostream> #include<sstream> #include<iomanip> #include<cstdlib> #include<algorithm> #include<vector> #include<map> #include<cmath> #include<string> #include<numeric> #include<queue> #define rep(i,p) for(long long int i=0;i<p;i++) #define reep(i,p) for(long long int i=1;i<=p;i++) #define ll long long #define MOD 1000000007 #define INF 9223372036854775800 #define pi 3.14159265359 using namespace std; int main(){ ll int H,W; cin >> H >> W; vector< vector< ll int > > A(H,vector< ll int > (W)); rep(i,H){ string S; cin >> S; rep(j,W){ if( S[j] == '+' ){ A[i][j] = 1; } else{ A[i][j] = -1; } } } if( H==1 && W==1 ){ cout << "Draw" << endl; return 0; } vector< vector< ll int > > dp(H,vector< ll int > (W,-INF)); dp[H-1][W-1] = 0; for( ll int i=1; i<H+W; i++ ){ for( ll int j=0; j<=i; j++ ){ if( j > H-1 || i-j > W-1 ){ continue; } if( (H-1+W-1+i)%2 == 0 ){ ll int kari1=-INF; ll int kari2=-INF; if( H-1-j+1 < H ){ kari1 = dp[H-1-j+1][W-1-i+j] + A[H-1-j+1][W-1-i+j]; } if( W-1-i+j+1 < W ){ kari2 = dp[H-1-j][W-1-i+j+1] + A[H-1-j][W-1-i+j+1] ; } dp[H-1-j][W-1-i+j] = max( kari1, kari2 ); } else{ ll int kari1=INF; ll int kari2=INF; if( H-1-j+1 < H ){ kari1 = dp[H-1-j+1][W-1-i+j] - A[H-1-j+1][W-1-i+j]; } if( W-1-i+j+1 < W ){ kari2 = dp[H-1-j][W-1-i+j+1] - A[H-1-j][W-1-i+j+1] ; } dp[H-1-j][W-1-i+j] = min( kari1, kari2 ); } } } //rep(i,H){ // rep(j,W){ // if( dp[i][j] == -INF ){ // cout << '!' << " " ; // } // else{ // cout << dp[i][j] << " " ; // } // } // cout << endl; //} if( dp[0][0] == 0 ){ cout << "Draw" << endl; } else if(dp[0][0] > 0 ){ cout << "Takahashi" << endl; } else{ cout << "Aoki" << endl; } return 0; }
#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 #define double long double 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 MOD=998244353; const ll inf=INF*INF; const ll mod=MOD; const ll MAX=200010; const double PI=acos(-1.0); signed main(){ ll n;cin>>n; vector<ll>a(0),b(0); vector<ll>c(2*n); rep(i,2*n){ cin>>c[i]; if(i%2==0){ a.pb(c[i]); }else{ b.pb(c[i]); } } sort(all(a)),sort(rall(b)); ll idx=-1; rep(i,n){ if(b[i]<=a[i]){ idx=i; break; } } string ans=""; if(idx==-1){ rep(i,n){ ans+="()"; } }else{ map<ll,ll>aa; map<ll,ll>bb; rep(i,idx){ aa[a[i]]++; bb[b[i]]++; } ll x=0,y=0,z=0,w=0; rep(i,n*2){ if(i%2==0){ if(y>0){ if(aa[c[i]]>0){ ans+=')'; aa[c[i]]--; y--; }else if(w>0){ w--; ans+=')'; }else{ z++; ans+='('; } }else{ if(aa[c[i]]>0){ aa[c[i]]--; ans+='('; x++; }else if(w>0){ w--; ans+=')'; }else{ z++; ans+='('; } } }else{ if(x>0){ if(bb[c[i]]>0){ ans+=')'; bb[c[i]]--; x--; }else if(z>0){ z--; ans+=')'; }else{ w++; ans+='('; } }else{ if(bb[c[i]]>0){ bb[c[i]]--; ans+='('; y++; }else if(z>0){ z--; ans+=')'; }else{ w++; ans+='('; } } } } } cout<<ans<<endl; }
#include <bits/stdc++.h> #include <chrono> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; /*............................................................................*/ #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> /* find_by_order(x) give iterator of the index x order_by_key(x) give the position where x will be placed*/ #define int long long #define lop(i,a,b,c) for (int i=a;i<b;i+=c) #define rlop(i,a,b,c) for (int i=a-1;i>=b;i-=c) #define prii pair <int,int> #define PB push_back #define S second #define F first #define all(x) x.begin(),x.end() #define vvii vector < vector < int > > #define vii vector <int> #define count_1(x) __builtin_popcount(x) #define cn(a) scanf("%lld",&a); #define cn_vl(arr,n) lop(i,0,n,1){scanf("%lld",arr+i);} #define shw_vl(arr,n) lop(i,0,n,1){printf("%lld ",arr[i]);}printf("\n"); const int MAX=2e5+10; /*......................................................................*/ void fastscan(int &number) { bool negative = false; register int c; number = 0; c = getchar(); if (c=='-') { negative = true; c = getchar(); } for (; (c>47 && c<58); c=getchar()) number = number *10 + c - 48; if (negative) number *= -1; } struct dsu { int parent[MAX];int size[MAX]; void init(){ lop (i,1,MAX,1){parent[i]=i;size[i]=1;} } int trace(int a){ return (a==parent[a])?a:parent[a]=trace(parent[a]); } bool connect(int a,int b){ if ((a=trace(a))==(b=trace(b)))return false; if (size[b]>size[a])swap(a,b); parent[b]=a;size[a]+=size[b]; return true; } }ori; struct abc{ int u,c,d; }; int f(int a,int b){ int re=LLONG_MAX; lop (i,-1,2,1){ int z=b+i; if (z<0)z=0; re=min(z+a/(1+z),re); } return re; } vector <abc> adj[MAX];const int INF=LLONG_MAX; void dijsktra(int u,vii &dst,int n){ dst.assign(n+1,INF); dst[u]=0; priority_queue < prii ,vector <prii> ,greater <prii>> q; q.push({0,u}); while (!q.empty()){ int wt=q.top().F; int u=q.top().S;q.pop(); if (wt!=dst[u]){ continue; } //cout<<u<<" "<<wt<<"\n"; for (auto v:adj[u]){ int re=sqrt(v.d); int zr=dst[u]; // cout<<v.u<<" "<<re<<" "; if (wt>re){ re=wt; } zr=re; re=v.c+v.d/(re+1); // cout<<ren"; if (re+zr<dst[v.u]){ dst[v.u]=re+zr; q.push({dst[v.u],v.u}); } } } } void solve(){ int n,m;cn(n)cn(m) lop (i,0,m,1){ int a,b,c,d; cn(a)cn(b)cn(c)cn(d) if (a!=b){ adj[a].PB({b,c,d}); adj[b].PB({a,c,d}); } } vii dst; dijsktra(1,dst,n); int z=dst[n]; if (z==INF){ z=-1; } cout<<z<<"\n"; } int32_t main(){ int t;t=1; // cin>>t; while (t--){ auto t_1=chrono::high_resolution_clock::now(); solve(); auto t_2=chrono::high_resolution_clock::now(); // cout <<". Elapsed (ms): " << chrono::duration_cast<chrono::milliseconds>(t_2 - t_1).count() << endl; } return 0; }
#pragma GCC optimize ("O2") #pragma GCC target ("avx2") //#include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; #include<cstdio> #include<cstring> using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please const int CM = 1 << 17, CL = 12; char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct; const ll ma0 = 1157442765409226768; const ll ma1 = 1085102592571150095; const ll ma2 = 71777214294589695; const ll ma3 = 281470681808895; const ll ma4 = 4294967295; inline int getint() { if (ci - owa > 0) { memcpy(cn, owa, CL); ci -= CM; fread(cn + CL, 1, CM, stdin); } ll tmp = *(ll*)ci; if ((tmp & ma0) ^ ma0) { int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0); tmp = tmp << dig & ma1; tmp = tmp * 10 + (tmp >> 8) & ma2; tmp = tmp * 100 + (tmp >> 16) & ma3; tmp = tmp * 10000 + (tmp >> 32) & ma4; ci += (72 - dig >> 3); } else { tmp = tmp & ma1; tmp = tmp * 10 + (tmp >> 8) & ma2; tmp = tmp * 100 + (tmp >> 16) & ma3; tmp = tmp * 10000 + (tmp >> 32) & ma4; ci += 8; if ((ct = *ci++) >= '0') { tmp = tmp * 10 + ct - '0'; if (*ci++ == '0') { tmp = tmp * 10; ci++; } } } return tmp; } int main() { //cin.tie(0); //ios::sync_with_stdio(false); int N = getint(); int kotae = 2e9; rep(i, N) { int a = getint(); int p = getint(); int x = getint(); if (a < x && p < kotae) kotae = p; } if (kotae > 1e9) printf("-1"); else printf("%d", kotae); Would you please return 0; }
#include <iostream> #include <cmath> #include <string> #include <vector> #include <algorithm> #include <utility> #include <tuple> #include <cstdint> #include <cstdio> #include <map> #include <queue> #include <set> #include <stack> #include <deque> #include <unordered_map> #include <unordered_set> #include <bitset> #include <cctype> #include <climits> #define rep(i, n) for (int i = 0; i < n; i++) using ll = long long; using ld = long double; #define vi vector<int> #define vvi vector<vi> #define vl vector<ll> #define pii pair<int, int> #define pll pair<ll, ll> #define all(a) (a).begin(), (a).end() #define mod 1000000007 using namespace std; struct mint{ ll x; mint(ll x = 0) : x((x + 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; } 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; } friend istream &operator>>(istream &is, mint &a){ return is >> a.x; } friend ostream &operator<<(ostream &os, const mint &a){ return os << a.x; } }; int main(){ int h,w; cin >> h >> w; vector<vector<char>> a(h, vector<char>(w)); rep(i, h) rep(j, w) cin >> a[i][j]; vector<mint> dpx(w), dpy(h), dpz(h + w + 1); mint num = 1; rep(i, h) rep(j, w){ if(a[i][j] == '#'){ dpx[j] = dpy[i] = dpz[j - i + h] = 0; }else{ if(i || j) num = dpx[j] + dpy[i] + dpz[j - i + h]; dpx[j] += num; dpy[i] += num; dpz[j - i + h] += num; } } cout << num << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define vt vector #define all(x) x.begin(), x.end() #define trav(i, x) for(auto &i : x) #define lb lower_bound #define ub upper_bound #define pb push_back #define eb emplace_back void solve() { int n; scanf("%d", &n); vector<int> a(n), b(n); trav(i, a) scanf("%d", &i); trav(i, b) scanf("%d", &i); ll res=0; for(int i = 0; i < n; i++) { res += a[i]*b[i]; } printf((res==0?"Yes":"No")); } int main() { int t = 1, i = 1; while(t--) { // printf("Case #%d: ", i) solve(); i++; } }
#include<bits/stdc++.h> using namespace std; int main(){ int a,b,c,d; cin >> a >> b >> c >> d; cout << a*d-b*c; 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; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define int long long #define reset(x) memset(x,0,sizeof(x)) #define db1(x) cout<<#x<<"="<<x<<'\n' #define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n' #define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n' #define rep(i,n) for(int i=0;i<(n);++i) #define repA(i,a,n) for(int i=a;i<=(n);++i) #define repD(i,a,n) for(int i=a;i>=(n);--i) #define sz(a) (int)a.size() #define pii pair<int,int> #define all(a) a.begin(),a.end() #define PI 3.1415926535897932384626433832795 #define INF 1000000000 #define MOD 1000000007 #define MOD2 1000000009 #define EPS 1e-6 #define pb push_back #define fi first #define se second #define mp make_pair int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); //freopen(".inp", "r", stdin); //freopen(".out", "w", stdout); int n; cin >> n; vector<int> arr; for (int i = 1; i <= n; i++) { int x; cin >> x; arr.pb(x); } sort(all(arr)); int total = n * (n - 1) / 2; for (int i = 0; i < n; i++) { int cnt = 1, ni = i; for (int j = i + 1; j < n; j++) { if (arr[j] == arr[i]) { cnt++; ni = j; } else { break; } } i = ni ; total -= (cnt * (cnt - 1) / 2); } cout << total; }
#include <iostream> #include <bits/stdc++.h> using namespace std; //xd int main(){ long long int n; cin>>n; map<long long int,long long int> frecuencias; vector<int> actualnum; int actual_size=-1; while(n--) { long long int temp; cin>>temp; if(!(frecuencias.find(temp)!=frecuencias.end())) { actualnum.push_back(temp); } frecuencias[temp]++; actual_size++; } long long int cont=0; for(auto it = actualnum.begin(); it != actualnum.end(); ++it) { cont+=frecuencias[*it]*(actual_size-(frecuencias[*it]-1)); actual_size-=frecuencias[*it]; } cout<<cont<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long int ll; #define mod 1000000007 #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); int main(){ fastio ll a,b,c,d; cin>>a>>b>>c>>d; ll sum = a+b+c+d; if(sum%2){ cout<<"No\n"; } else{ bool done = false; for(ll i=0; i<(1<<4); i++){ ll ts=0; if(1&i)ts+=a; if(2&i)ts+=b; if(4&i)ts+=c; if(8&i)ts+=d; if(ts == sum/2){ done = true; break; } } if(done)cout<<"Yes\n"; else cout<<"No\n"; } return 0; }
#include<iostream> #include<string> #include<vector> #include<utility> #include<algorithm> #include<map> #include<set> #include<cstdlib> #include<cmath> #include<numeric>//fill #include<iomanip> #include<functional>//https://cpprefjp.github.io/reference/functional/function.html #include<cstdlib>//https://cpprefjp.github.io/reference/cstdlib.html #include<queue> #include<deque> #include<cassert> #include<stack> #include <iterator> // std::back_inserter //#include<atcoder/all> using namespace std; //using namespace atcoder; const double PI = acos(-1); using ll = long long; using P = pair<ll,ll>; #define rep(i,n)for(ll i=0;i<(n);i++) #define repp(x,arr) for(auto& x:arr) #define repp2(x,y,arr) for(auto& [x,y]:arr) #define all(a) (a.begin()),(a.end()) const ll MOD = 1e9 + 7; const ll inf = (ll)1e18+6; // デフォルトは整数部も含めた桁数指定 //cout <<setprecision(); ll myPow(ll x, ll n, ll m) { if (n == 0) return 1; if (n % 2 == 0) return myPow(x * x % m, n / 2, m); else return x * myPow(x, n - 1, m) % m; } double dl[4] = { 0,0,0.1,0.1 }; double dr[4] = { 0,-0.1,0,-0.1 }; int main() { ios::sync_with_stdio(false); int N; cin >> N; vector<pair<double, double>>s(N), t(N); map<pair<double, double>,bool>m; rep(i, N) { cin >> t[i].first >> t[i].second; } rep(i, N) { cin >>s[i].first >> s[i].second; m[s[i]] = true; } if (N == 1) { cout << "Yes"; return 0; } double a, b,a2,b2; a = s[0].first, b = s[0].second; a2 = s[1].first, b2 = s[1].second; double p1; p1 = atan((b2 - b) / (a2 - a)); bool ans = false; //cout << "指標は" << a << " " << b << endl; rep(i, N) { double q, r,c, d; c = t[i].first, d = t[i].second; for (int j = 0; j < N; j++) { if(j==i)continue; double c2, d2,p,p2; c2 = t[j].first; d2 = t[j].second; c2 -= c; d2 -= d; p = p1-atan(d2 / c2); p2 = p + PI; { double A1, B1, x, y, x2, y2; A1 = t[j].first - c; B1 = t[j].second - d; x = A1 * cos(p) - B1 * sin(p); y = A1 * sin(p) + B1 * cos(p); x2 = A1 * cos(p2) - B1 * sin(p2); y2 = A1 * sin(p2) + B1 * cos(p2); x += a; y += b; x = round(x); y = round(y); x2 += a; y2 += b; x2 = round(x2); y2 = round(y2); if (x==a2&&y==b2) { p = p; } else if (x2 == a2 && y2 == b2) { p = p2; } else { continue; } } rep(k, N) { double A1, B1,x,y,x2,y2; A1 = t[k].first - c; B1 = t[k].second - d; x = A1 * cos(p) - B1 * sin(p); y = A1 * sin(p) + B1 * cos(p); //x2 = A1 * cos(p2) - B1 * sin(p2); y2 = A1 * sin(p2) + B1 * cos(p2); //cout << x << " " << y << endl; //cout << x2 << " " << y2 << endl; x += a; y+= b; x = round(x); y = round(y); if (m[{x,y}] == false) { //cout << "break"<<endl; break; } if (k == N - 1)ans = true; } } } if (ans)cout << "Yes"; else cout << "No"; }
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(ll i=0;i<(ll)n;i++) #define dump(x) cerr << "Line " << __LINE__ << ": " << #x << " = " << (x) << "\n"; #define spa << " " << #define fi first #define se second #define ALL(a) (a).begin(),(a).end() #define ALLR(a) (a).rbegin(),(a).rend() using ld = long double; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<ld, ld>; template<typename T> using V = vector<T>; template<typename T> using P = pair<T, T>; template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); } template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); } template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){os << "(" << v.first << ", " << v.second << ")"; return os;} template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; } template<class T> ostream& operator<<(ostream& os, const vector<vector<T>> &v){ for(auto &e : v){os << e << "\n";} return os;} struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; template <class T> void UNIQUE(vector<T> &x) {sort(ALL(x));x.erase(unique(ALL(x)), x.end());} template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } void fail() { cout << -1 << '\n'; exit(0); } inline int popcount(const int x) { return __builtin_popcount(x); } inline int popcount(const ll x) { return __builtin_popcountll(x); } template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++) {cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<"\n";}}; template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0]; for(ll i=1;i<n;i++)cerr spa v[i]; cerr<<"\n";}; const ll INF = (1ll<<62); // const ld EPS = 1e-10; // const ld PI = acos(-1.0); const ll mod = (int)1e9 + 7; //const ll mod = 998244353; ll graph_bfs(V<V<ll>> &G, ll s){ // sは始点のリスト const int N = G.size(); vector<int> dist(N, -1); queue<int> qu; // initialization qu.push(s); dist[s] = 0; while(!qu.empty()){ int now = qu.front();qu.pop(); for(auto next: G[now]){ if(dist[next] != -1) continue; dist[next] = dist[now] + 1; qu.push(next); } } ll res = 0; REP(i, N) if(dist[i] >= 0) res++; return res; } int main(){ ll N; cin >> N; V<string> S(N); REP(i, N) cin >> S[i]; V<V<ll>> G(N); REP(i, N){ REP(j, N){ if(S[i][j] == '1'){ G[j].push_back(i); } } } ld res = 0; REP(i, N){ res += (ld)1.0/(graph_bfs(G, i)); } cout << res << endl; return 0; }
#pragma GCC optimize("O2,unroll-loops") #pragma GCC target("avx,avx2,sse,sse2,ssse3,sse4.1,sse4.2,popcnt") #include<bits/extc++.h> #define all(x) begin(x), end(x) using namespace std; using ll = long long; const int maxn = 1<<11, mod = 1e9 + 7; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); vector<int> g[maxn]; int vis[maxn]; int dfs(int v) { vis[v] =1; int res = 1; for(auto i : g[v]) if(!vis[i]) res += dfs(i); return res; } signed main() { cin.tie(0)->sync_with_stdio(0); int n; char c; cin >> n; for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) { cin >> c; if(c == '1') g[j].push_back(i); } long double ans = 0; for(int i = 1; i <= n; i++) { fill(all(vis), 0); ans += 1./dfs(i); } cout << fixed << setprecision(15) << ans << endl; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define ar array int main(){ ios::sync_with_stdio(0); cin.tie(0); ll n; cin>> n; for(int i=1; ; ++i){ if(stoll(to_string(i)+to_string(i))>n){ cout<<i-1<<endl; break; } } return 0; }
#include <bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define all(nums) nums.begin(), nums.end() #define allr(nums) nums.rbegin(), nums.rend() #define len(a) int((a).size()) typedef long long int ll; typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>ordered_set ; typedef vector<vector<int>> graph; const ll inf = INT32_MAX; const ll minf = INT32_MIN; template<class T>T cal(T n) {return (n*1ll*(n+1))/2;} template<class T>T mx(T begin, T end){return max_element(begin, end);} template<class T>T mn(T begin, T end){return min_element(begin, end);} template<class T>void getUnique(vector<T>& nums){sort(nums.begin(), nums.end()); nums.erase(unique(nums.begin(), nums.end()), nums.end());} template<class T>void print(vector<T>nums){for(T i:nums)cout<<i<<" ";cout<<"\n";} template<class T>void read(vector<T>&nums){for(T& i:nums)cin>>i;} signed main () { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); ll test = 1; // cin >> test; while (test--) { int n ; cin >> n ; vector<int>nums(n) ; read(nums) ; sort(all(nums)) ; bool flag = true ; for (int i=1; i<=n; ++i) { if (i != nums[i-1]) { flag = false ; break ; } } cout << (flag ? "Yes" : "No") << "\n" ; } return 0; }
#include<bits/stdc++.h> #define ll long long int #define pii pair<int,int> #define pll pair<ll,ll> #define vpii vector< pii > #define vpll vector< pll > #define mpii map<int,int> #define mpll map<ll,ll> #define MOD 1000000007 #define all(v) v.begin(),v.end() #define s(v) v.size() #define test ll t;cin>>t;while(t--) #define vec vector<ll> #define read0(v,n) for(int i=0;i<n;i++)cin>>v[i]; #define read1(v,n) for(int i=1;i<=n;i++)cin>>v[i]; #define trav(a,x) for (auto& a: x) #define fast ios_base::sync_with_stdio(false);cin.tie(NULL); #define cut(x) {cout<<x;return 0;} #define FOR(i,a,b) for(int i=a;i<=b;i++) #define FORB(i,a,b) for(int i=a;i>=b;i--) #define mp make_pair #define pb push_back #define eb emplace_back #define f first #define sc second #define lb lower_bound #define ub upper_bound #define nl '\n' #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #define oset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> ll gcd(ll a, ll b) { if (b==0)return a; return gcd(b, a % b); } ll lcm(ll a,ll b) { return (a*b)/gcd(a,b); } ll pow(ll a, ll b) { ll ans=1; while(b) { if(b&1) ans=(ans*a)%MOD; b/=2; a=(a*a)%MOD; } return ans; } const int N=2005; ll a[N][N],row[N][N],col[N][N],dia[N][N]; char g[N][N]; int main() { fast ll n,m; cin>>n>>m; FOR(i,1,n) { string s; cin>>s; FOR(j,1,m) { g[i][j]=s[j-1]; } } FOR(i,1,n) { FOR(j,1,m) { if(i==1 and j==1){a[i][j]=0;row[i][j]=1;col[i][j]=1;dia[i][j]=1;continue;} if(g[i][j]=='#') { row[i][j]=0;col[i][j]=0;row[i][j]=0; a[i][j]=0; } else { ll x=0,y=0,z=0; if(i-1>=1)x=col[i-1][j]; if(i-1>=1 and j-1>=1)y=dia[i-1][j-1]; if(j-1>=1)z=row[i][j-1]; a[i][j]=x+y+z; row[i][j]=a[i][j]+(j-1>=1?row[i][j-1]:0); col[i][j]=a[i][j]+(i-1>=1?col[i-1][j]:0); dia[i][j]=a[i][j]+(j-1>=1 and i-1>=1?dia[i-1][j-1]:0); row[i][j]%=MOD; col[i][j]%=MOD; dia[i][j]%=MOD; a[i][j]%=MOD; } } } // FOR(i,1,n)FOR(j,1,m)cout<<dp[i][j]<<(j==m?nl:' '); cout<<a[n][m]; }
//g++ -std=gnu++14 a.cpp #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <iostream> #include <istream> #include <iterator> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #include <tuple> #include <iomanip> #include <random> #include <math.h> #include <stdio.h> using namespace std; #define ll long long #define rep(i, n) for(ll i = 0; i < (n); i++) #define P pair<ll,ll> ll MOD = 1e9 + 7; int INF = 1 << 30; ll INFL = 1LL << 60; ll MODP = 998244353; ll lmax(ll x,ll y){ if(x < y) return y; else return x; } ll lmin(ll x, ll y){ if(x > y)return y; else return x; } void add(vector<string> &s,vector<vector<ll>> &v, ll a, ll b,vector<vector<ll>> &tate,vector<vector<ll>> &yoko,vector<vector<ll>> &naname){ ll h = s.size(),w = s[0].size(),x = a, y = b; if(s[x-1][y-1] == '#')return; if(x+1 <= h){ if(s[x+1-1][y-1] != '#'){ v[x+1][y] += tate[x][y]; tate[x+1][y] += 2*tate[x][y]; yoko[x+1][y] += tate[x][y]; naname[x+1][y] += tate[x][y]; v[x+1][y] %= MOD; tate[x+1][y] %= MOD; yoko[x+1][y] %= MOD; naname[x+1][y] %= MOD; } } if(y+1 <= w){ if(s[x-1][y+1-1] != '#'){ v[x][y+1] += yoko[x][y]; tate[x][y+1] += yoko[x][y]; yoko[x][y+1] += 2*yoko[x][y]; naname[x][y+1] += yoko[x][y]; v[x][y+1] %= MOD; tate[x][y+1] %= MOD; yoko[x][y+1] %= MOD; naname[x][y+1] %= MOD; } } if(x+1 <= h && y+1 <= w){ if(s[x+1-1][y+1-1] != '#'){ v[x+1][y+1] += naname[x][y]; tate[x+1][y+1] += naname[x][y]; yoko[x+1][y+1] += naname[x][y]; naname[x+1][y+1] += 2*naname[x][y]; v[x+1][y+1] %= MOD; tate[x+1][y+1] %= MOD; yoko[x+1][y+1] %= MOD; naname[x+1][y+1] %= MOD; } } } int main(){ ll H,W; cin >> H >> W; vector<string> S(H); rep(i,H) cin >> S[i]; vector<vector<ll>> ans(H+1,vector<ll>(W+1,0)); vector<vector<ll>> tate(H+1,vector<ll>(W+1,0)),yoko(H+1,vector<ll>(W+1,0)),naname(H+1,vector<ll>(W+1,0)); ans[1][1] = 1,yoko[1][1] = 1,tate[1][1] = 1,naname[1][1] = 1; for(int i = 1;i <= H;i++){ ll s = i,t = 1; while(s > 0 && t <= W){ add(S,ans,s,t,tate,yoko,naname); s--; t++; } } for(int i = 2;i <= W;i++){ ll s = H, t = i; while(s > 0 && t <= W){ add(S,ans,s,t,tate,yoko,naname); s--; t++; } } cout << ans[H][W] << endl; return 0; }
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cmath> #include <vector> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <queue> #include <ctime> #include <cassert> #include <complex> #include <string> #include <cstring> #include <chrono> #include <random> #include <bitset> using namespace std; #define speed ios_base::sync_with_stdio(false),cout.tie(0),cin.tie(0) #define fre freopen("in.txt","r",stdin),freopen("out.txt","w",stdout) #define N 2*100005 #define M 2002 #define nd second #define st first #define endl "\n" #define pii pair<ll,ll> #define pb push_back #define mp make_pair #define inf 1e9+7 #define mid (start+end)/2 #define sp " " typedef long long int ll; string s; void solve(){ cin>>s; for (int i = 1; i < 3; ++i) { if(s[i]!=s[i-1]){ cout<<"Lost"; return; } } cout<<"Won"; } int main() { speed; // fre; int TT=1; //cin>>TT; while(TT--)solve(); return 0; }
using namespace std; #include <bits/stdc++.h> typedef long long ll; map<int64_t, int> prime_factor(int64_t n) { map<int64_t, int> ret; for (int64_t i = 2; i * i <= n; i++) { while (n % i == 0) { ret[i]++; n /= i; } } if (n != 1) ret[n] = 1; return ret; } int main() { char a, b, c; cin >> a >> b >> c; if (a == b && a == c) { cout << "Won" << endl; } else { cout << "Lost" << endl; } return 0; }
#include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <bitset> #include <complex> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> #include <cassert> #include <functional> typedef long long ll; using namespace std; #ifndef LOCAL #define debug(...) ; #else #define debug(...) cerr << __LINE__ << " : " << #__VA_ARGS__ << " = " << _tostr(__VA_ARGS__) << endl; template<typename T> ostream &operator<<(ostream &out, const vector<T> &v); template<typename T1, typename T2> ostream &operator<<(ostream &out, const pair<T1, T2> &p) { out << "{" << p.first << ", " << p.second << "}"; return out; } template<typename T> ostream &operator<<(ostream &out, const vector<T> &v) { out << '{'; for (const T &item : v) out << item << ", "; out << "\b\b}"; return out; } void _tostr_rec(ostringstream &oss) { oss << "\b\b \b"; } template<typename Head, typename... Tail> void _tostr_rec(ostringstream &oss, Head &&head, Tail &&...tail) { oss << head << ", "; _tostr_rec(oss, forward<Tail>(tail)...); } template<typename... T> string _tostr(T &&...args) { ostringstream oss; int size = sizeof...(args); if (size > 1) oss << "{"; _tostr_rec(oss, forward<T>(args)...); if (size > 1) oss << "}"; return oss.str(); } #endif #define mod 1000000007 //1e9+7(prime number) #define INF 1000000000 //1e9 #define LLINF 2000000000000000000LL //2e18 #define SIZE 200010 int f(int x, int N) { for (int i = 10; i >= 0; i--) { if (x >= N && (x & (1 << i))) { x -= 1 << i; } } return x; } int main() { int N; scanf("%d", &N); for (int i = 0; i < N; i++) { int a = f(i * 2 + 0, N); int b = f(i * 2 + 1, N); printf("%d %d\n", a + 1, b + 1); } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep2(i,j,n) for (int i=j; i <=(int)(n); i++) int a[100010]; int main() { int n,m,p,q; cin >> n; rep2(i,1,n)a[i]=1; if(n==1){ cout << 1 << endl; return 0; } m=n/2+1; rep2(i,1,m){ p=i+i; q=a[i]; while (p<=n) { if (a[p]==q)a[p]++; p+=i; } } rep2(i,1,n){ cout << a[i] << " "; } return 0; }
#include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #include <climits> #include <cstring> #include <cassert> using namespace std; //using namespace atcoder; #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 FOR(i, a, n) for (int i=(a); i<(n); ++i) #define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i) #define SZ(x) ((int)(x).size()) #define ALL(x) (x).begin(),(x).end() #define DUMP(x) cerr<<#x<<" = "<<(x)<<endl #define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl; template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "["; REP(i, SZ(v)) { if (i) os << ", "; os << v[i]; } return os << "]"; } template<class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << "(" << p.first << " " << p.second << ")"; } template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } using ll = long long; using ull = unsigned long long; using ld = long double; using P = pair<int, int>; using vi = vector<int>; using vll = vector<ll>; using vvi = vector<vi>; using vvll = vector<vll>; const ll MOD = 1e9 + 7; const int INF = INT_MAX / 2; const ll LINF = LLONG_MAX / 2; const ld eps = 1e-9; // edit vector<int> primes = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, }; vector<vector<ll>> dp; ll A, B; vector<int> xmask; ll rec(int idx, int mask) { if (A + idx == B + 1) { return 1; } if (dp[idx][mask] != -1) { return dp[idx][mask]; } ll ret = 0; ll x = A + idx; ret += rec(idx + 1, mask); if (mask & xmask[x - A]) { } else { int nmask = mask | xmask[x - A]; ret += rec(idx + 1, nmask); } // cerr << A + idx << " " << mask << " " << ret << endl; return dp[idx][mask] = ret; } void solve() { cin >> A >> B; // while (primes.back() > B - A + 1) { // primes.pop_back(); // } dp.resize(B - A + 1, vector<ll>(1 << (primes.size()), -1)); xmask.resize(B - A + 1); for (ll x = A; x <= B; ++x) { xmask[x - A] = 0; for (int j = 0; j < primes.size(); ++j) { if (x % primes[j] == 0) { xmask[x - A] |= (1 << j); } } } ll ans = rec(0, 0); cout << ans << endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(10); // std::ifstream in("input.txt"); // std::cin.rdbuf(in.rdbuf()); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define countof(array) (sizeof(array) / sizeof(array[0])) #define rep(i,n) for(int i = 0; i < (n); ++i) #define rrep(i,n) for(int i = (n)-1; i >= 0; --i) #define rep2(i,n) for(int i = 1; i <= (n); ++i) #define rrep2(i,n) for(int i = (n); i > 0; --i) #define srep(i,s,n) for(int i = s; i < (n); ++i) #define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i) #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() #define aall(a) (a), (a)+countof(a)//for array sorting #define raall(a) (a), (a)+countof(a), greater<>() #define show(x) cout<<#x<<" = "<<(x)<<endl; #define vfind(v, a) find(all(v), a) != v.end() #define yn(f) { if (f) puts("YES"); else puts("NO"); } #define yns(f) { if (f) puts("Yes"); else puts("No"); } #define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; } #define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<" "<<x.fi<<" : "<<x.se<<endl; } #define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); } #define argmax(v) distance((v).begin(), max_element(all(v))) #define argmin(v) distance((v).begin(), min_element(all(v))) #define vmax(v) *max_element(all(v)) #define vmin(v) *min_element(all(v)) typedef long long int ll; typedef pair<int, int> P; typedef vector<P> vpair; typedef vector<int> vint; typedef vector<ll> vll; typedef vector<double> vdouble; typedef vector<string> vstr; typedef vector<bool> vbool; typedef vector<vint> vvint; typedef vector<vll> vvll; typedef vector<vstr> vvstr; typedef vector<vbool> vvbool; const ll LINF = 2000000000000000000ll; const int INF = 1000000100; const ll MOD = 1e9+7; vll d(100005, INF); vpair edges[100005]; void dijkstra(int s) { priority_queue<P, vector<P>, greater<P>> que; d[s] = 0; que.push(P(0, s)); while (que.size()) { P p = que.top(); que.pop(); int v = p.se; if (d[v] < p.fi) continue; for (auto e : edges[v]) { if (d[e.fi] > d[v] + e.se) { d[e.fi] = d[v] + e.se; que.push(P(d[e.fi], e.fi)); } } } } int main() { int a, b, x, y; cin >> a >> b >> x >> y; --a;--b; rep(i, 100) { edges[i].emplace_back(i+100, x); edges[i+100].emplace_back(i, x); } rep(i, 99) { edges[i+1].emplace_back(i+100, x); edges[i+100].emplace_back(i+1, x); edges[i].emplace_back(i+1, y); edges[i+1].emplace_back(i, y); edges[i+100].emplace_back(i+101, y); edges[i+101].emplace_back(i+100, y); } dijkstra(a); cout << d[b+100] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < n; i++) #define rep2(i, x, n) for(int i = x; i <= n; i++) #define rep3(i, x, n) for(int i = x; i >= n; i--) #define each(e, v) for(auto &e: v) #define pb push_back #define eb emplace_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define sz(x) (int)x.size() using ll = long long; using pii = pair<int, int>; using pil = pair<int, ll>; using pli = pair<ll, int>; using pll = pair<ll, ll>; const int MOD = 1000000007; //const int MOD = 998244353; const int inf = (1<<30)-1; const ll INF = (1LL<<60)-1; template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;}; template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;}; struct io_setup{ io_setup(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout << fixed << setprecision(15); } } io_setup; int main(){ ll B, K; cin >> B >> K; if(K == 1) {cout << (B == 0? 1 : 2) << '\n'; return 0;} B = -B; vector<pll> P; P.eb(B, B+K/2+1); P.eb(-B-(K-1)/2, -B+1); P.eb(-B, -B+(K-1)/2+1); P.eb(B-(K-2)/2, B+1); sort(all(P)); ll R = -INF*2; ll ans = 0; each(e, P){ ll a = e.first, b = e.second; chmax(a, R), chmax(b, R); ans += b-a; chmax(R, b); } cout << ans << '\n'; }
#include<bits/stdc++.h> using namespace std; long long b,c,ans; int main(){ ios::sync_with_stdio(false); cin.tie(0); cin>>b>>c; if(b<0){ ans+=min((c-1)/2,-b-1); if(c>=2) ans+=min((c-2)/2,-b-1); ans+=c/2+1; ans+=(c-1)/2+1; if(b<=(c-1)/2)ans++; }else{ ans+=min(c/2+1,b); if(b>0) ans+=min((c-1)/2,b-1); if(b!=0){ ans+=(c-1)/2+1; if(c>=2) ans+=(c-2)/2; if(b<=c/2)ans++; }else{ ans+=c/2+1; if(c>=2) ans+=(c-1)/2; } } cout<<ans<<"\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int main () { int a; cin >> a; if (a < 100) cout << 1 << endl; else if (a % 100 == 0) { a /= 100; cout << a << endl; } else { a /= 100; a++; cout << a << endl; } }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; int main(){ int k; scanf("%d",&k); int ans=0; for(int a=1;a<=k;a++){ for(int b=1;b<=k/a;b++){ ans+=k/a/b; } } printf("%d\n",ans); return 0; }
//#pragma GCC optimize("O3") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define FIO ios_base::sync_with_stdio(false); cin.tie(0); #define trav(x,a) for (auto& x: a) #define sz(x) (int)(x).size() #define all(x) (x).begin(), (x).end() #define endl "\n" #define case(t) cout << "Case #" << (t) << ": " #define pii pair<int, int> #define pb push_back #define mp make_pair #define st first #define nd second using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ld; typedef cc_hash_table<int,int,hash<int>> ht; typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset; const double pi = acos(-1); const int mod = 1e9 + 7; const int inf = 1e9 + 7; const int N = 1e6 + 5; const ld eps = 1e-9; template<class T> void read(T& x) { cin >> x; } template<class X, class Y> void read(pair<X,Y>& a) { read(a.first), read(a.second); } template<class T, size_t U> void read(array<T,U>& x) { for (int i = 0; i < U; i++) read(x[i]); } template<class T> void read(vector<T>& x) { trav(y, x) read(y); } template<class T, class... O> void read(T& x, O&... y) { read(x), read(y...); } string to_string(const char& x) { return string(1,x); } string to_string(const char*& x) { return (string)x; } string to_string(const string& x) { return x; } template<class T, class U> string to_string(const pair<T,U>& x) { return to_string(x.first) + " " + to_string(x.second); } template<class T, size_t U> string to_string(const array<T,U>& x) { string ret = ""; for (int i = 0; i < U; i++) ret += (!i ? "" : " ") + to_string(x[i]); return ret; } template<class T> string to_string(const vector<T>& x) { string ret = ""; bool f = 0; trav(y, x) ret += (!f ? "" : " ") + to_string(y), f = 1; return ret; } template<class T> string to_string(const set<T>& x) { string ret = ""; bool f = 0; trav(y, x) ret += (!f ? "" : " ") + to_string(y), f = 1; return ret; } void print() { cout << endl; } template<class T> void pr(const T& x) { cout << to_string(x); } template<class T, class... O> void print(const T& x, const O&... y) { pr(x); if (sizeof...(y)) pr(" "); print(y...); } int main() { FIO ll n; read(n); ll ans = n; for (ll b = 0; (1ll << b) <= n; b++) { ll c = n % (1ll << b); ll a = n / (1ll << b); ans = min(ans, a + b + c); } print(ans); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const ll mod = 1000000007; int main() { ll n; cin >> n; ll a = 0, b = 0, c = 0; ll result = LONG_LONG_MAX; while (n > (1ll << b)) { a = n / (1ll << b); c = n % (1ll << b); result = min(result, a+b+c); b++; } if (b == 0) cout << 1 << endl; else cout << result << endl; }
//clear adj and visited vector declared globally after each test case //check for long long overflow //Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod; //Incase of close mle change language to c++17 or c++14 #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #define int long long #define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10); #define pb push_back #define mod 1000000007ll //998244353ll #define lld long double #define mii map<int, int> #define pii pair<int, int> #define ll long long #define ff first #define ss second #define all(x) (x).begin(), (x).end() #define rep(i,x,y) for(int i=x; i<y; i++) #define fill(a,b) memset(a, b, sizeof(a)) #define vi vector<int> #define setbits(x) __builtin_popcountll(x) #define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";} typedef std::numeric_limits< double > dbl; using namespace __gnu_pbds; using namespace std; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; //member functions : //1. order_of_key(k) : number of elements strictly lesser than k //2. find_by_order(k) : k-th element in the set const long long N=2000005, INF=2000000000000000000; lld pi=3.1415926535897932; int lcm(int a, int b) { int g=__gcd(a, b); return a/g*b; } int power(int a, int b, int p) { if(a==0) return 0; int res=1; a%=p; while(b>0) { if(b&1) res=(res*a)%p; b>>=1; a=(a*a)%p; } return res; } int fact[N],inv[N]; void pre() { fact[0]=1; inv[0]=1; for(int i=1;i<N;i++) fact[i]=(i*fact[i-1])%mod; for(int i=1;i<N;i++) inv[i]=power(fact[i], mod-2, mod); } int nCr(int n, int r, int p) { if(r>n) return 0; if(n==r) return 1; if (r==0) return 1; return (((fact[n]*inv[r]) % p )*inv[n-r])%p; } int32_t main() { IOS; pre(); int n, m, k; cin>>n>>m>>k; int ans=0; rep(i,max(0ll, n-m),k+1) { ans+=(nCr(n+m, m+i, mod) - nCr(n+m, m+i+1, mod) + mod)%mod; ans%=mod; } cout<<ans; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #ifdef LOCAL #include "debug.hpp" #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) #endif ll MOD = 1e9 + 7; ll kai(ll n) { if (n == 0) return 1; ll ans = 1; for (ll i = 1; i <= n; i++) { ans = (ans * i) % MOD; } return ans; } ll pow_mod(ll x, ll a) { if (a == 0) return 1; ll temp = pow_mod(x, a / 2); ll ans = (temp * temp) % MOD; if (a % 2) ans = (ans * x) % MOD; return ans; } ll inv(ll n) { return pow_mod(n, MOD - 2); } ll nCk(ll n, ll k) { ll ans = kai(n); ans = (ans * inv(kai(k))) % MOD; ans = (ans * inv(kai(n - k))) % MOD; return ans; } int main() { ios::sync_with_stdio(false); cin.tie(0); ll N, M, K; cin >> N >> M >> K; if (N > M + K) { cout << 0 << '\n'; return 0; } ll c = N - K; ll ans = nCk(N + M, N); ll temp = nCk(N + M, M + K + 1); if (c == 0) temp = 0; ans = (ans - temp + MOD) % MOD; cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> // #include <atcoder/all> // using namespace atcoder; using namespace std; using ll = long long; using ull = unsigned long long; // #define int ll // #define DEBUG 42 inline void nprint(){} template <class Head, class... Tail> inline void nprint(Head &&head, Tail &&... tail) { cout << head << endl; nprint(move(tail)...); } #ifdef DEBUG #define eprint(...) nprint(__VA_ARGS__) #else #define eprint(...) if(0==1) cout << 1 << endl; #endif #define Yes(a) cout << (a ? "Yes" : "No") << endl #define YES(a) cout << (a ? "YES" : "NO") << endl #define POSSIBLE(a) cout << (a ? "POSSIBLE" : "IMPOSSIBLE") << endl using cmp = complex<double>; using vb = vector<bool>; using vvb = vector<vb>; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; template<class T> using V = vector<T>; template<class T> using VV = vector<V<T>>; #define fi first #define se second template<class T>inline bool maxs(T& x, T y){ if(x >= y) return false; x = y; return true; } template<class T>inline bool mins(T& x, T y){ if(x <= y) return false; x = y; return true; } using pii = pair<int,int>; using pll = pair<ll,ll>; #define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i) #define REP(i,n) FOR(i,0,n) #define FORS(i,a,b) FOR(i,a,b+1) #define REPS(i,n) REP(i,n+1) #define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i) #define RREP(i,n) RFOR(i,0,n) #define RREPS(i,n) RREP(i,n+1) #define RFORS(i,a,b) RFOR(i,a,b+1) #define ALL(obj) (obj).begin(), (obj).end() #define RALL(obj) (obj).rbegin(), (obj).rend() #define PERM(c) sort(ALL(c)); for(bool cp = true;cp;cp = next_permutation(ALL(c))) #define eb(val) emplace_back(val) inline ll bitcnt(ll val) { return __builtin_popcountll(val); } const long double PI = std::acos(-1.0l); constexpr int dx[] = {1,0,-1,0}; constexpr int dy[] = {0,1,0,-1}; template<typename Tail> auto type_vector(Tail&& tail){return tail;} template<typename Head, typename... Tail> auto type_vector(Head&& head, Tail&&... tail){ head = 0; return vector<decltype(type_vector(tail...))>(head); } template<typename Tail> auto make_vector(Tail&& tail){return tail;} template<typename Head, typename... Tail> auto make_vector(Head&& head, Tail&&... tail){ return vector<decltype(type_vector(tail...))>(head, make_vector(tail...)); } template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p){ return s << "(" << p.first << ", " << p.second << ")"; } template<class T> istream& operator>>(istream &is,vector<T> &st){ for(size_t i=0;i<st.size();++i){is >> st[i];} return is; } template<class T> istream& operator>>(istream &is,vector<vector<T>> &st){ for(size_t i=0;i<st.size();++i){is >> st[i];} return is; } template<class T> ostream& operator<<(ostream &os, const vector<T> &st){ for(size_t i=0;i<st.size();++i) os << st[i] << (i!=st.size()-1?" ":""); return os; } ostream& operator<<(ostream &os, const vector<string> &st){ for(size_t i=0;i<st.size();++i) os << st[i] << (i!=st.size()-1?"\n":""); return os; } template<class T> ostream& operator<<(ostream &os, const vector<vector<T>> &st){ for(size_t i=0;i<st.size();++i) os << st[i] << (i!=st.size()-1?"\n":""); return os; } constexpr double EPS = 1e-10; constexpr ll MOD = 1E9+7; // constexpr ll MOD = 998244353; signed main(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); string s; cin >> s; int ans = 0; REP(i,9){ if(s.substr(i,4) == "ZONe") ++ans; } cout << ans << endl; }
#include <iostream> #include <vector> #include <iterator> #include <algorithm> #include <string> #include <numeric> #include <iterator> #include <climits> #include <cmath> #include <iomanip> using namespace std; template <class T> ostream &operator<<(ostream &o, const vector<T> &v) { o << "{"; for (int i = 0; i < (int)v.size(); i++) o << (i > 0 ? ", " : "") << v[i]; o << "}"; return o; } int main() { int n; cin >> n; int x[n]; for (int i = 0; i < n; i++) { int a; cin >> a; x[i] = a < 0 ? (-a) : a; } long long Manhattan = 0; for (int i = 0; i < n; i++) { Manhattan += (long long)x[i]; } long long square_sum = 0; for (int i = 0; i < n; i++) { square_sum += ((long long)x[i] * (long long)x[i]); } long double Euclid = (long double)sqrt(square_sum); int ChebyChef = 0; for (int i = 0; i < n; i++) { if (ChebyChef < x[i]) { ChebyChef = x[i]; } } cout << Manhattan << endl; cout << fixed << setprecision(10) << Euclid << endl; cout << ChebyChef << endl; return 0; }
#include "bits/stdc++.h" using namespace std; #ifdef LOCAL #include "debug.h" #define input freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #else #define debug(...) 4 #define input 4 #endif using ll = long long; const int mod = 1e9 + 7; const int N = 2e6 + 5; int dp[12][12]; //Beggar - C(n+r-1,r-1) int fac[N],invf[N]; inline int add(int x, int y) { return x + y >= mod ? x + y - mod : x + y; } inline int sub(int x, int y) { return x - y >= 0 ? x - y : x - y + mod; } inline int power(int x, int y, int res = 1) { while(y) { if(y & 1) res = 1ll * res * x % mod; x = 1ll * x * x % mod; y >>= 1; } return res; } void initcombi(int n) { for (int i = fac[0] = 1; i <= n; i++) { fac[i] = 1ll * fac[i - 1] * i % mod; } invf[n] = power(fac[n], mod - 2); for (int i = n; i; i--) { invf[i - 1] = 1ll * invf[i] * i % mod; } } inline int NCR(int n, int m) { if (n < m) return 0; return 1ll * fac[n] * invf[m] % mod * invf[n - m] % mod; } signed main() { input; cin.tie(nullptr) -> sync_with_stdio(false); ll x, y; cin >> x >> y; for(int i = 1; i <= sqrt(y); i++) { ll d = y / i; if(i + d == x) { cout << "Yes"; return 0; } } cout << "No"; }
// C++ (GCC9.2.1) AtCoder /* Ctrl+Option+N で 実行 */ #include <bits/stdc++.h> #define INF 100000000000 #define MOD 1000000007 #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(),(x).end() #define print(x) cout << (x) << endl; typedef long long ll; using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int M,H; cin>>M>>H; string ans = "No"; if(H % M == 0) ans = "Yes"; print(ans); return 0; }
#include <map> #include <stdio.h> #include <algorithm> using namespace std; typedef long long ll; int n; int o[300111]; map<ll, ll> mp; int main(void) { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &o[i]); } for (int i = 1; i <= n; i += 2) { o[i] *= -1; } ll s = 0; for (int i = 0; i <= n; i++) { s += o[i]; mp[s]++; } ll ans = 0; for (auto [k, v] : mp) { ans += v * (v - 1) / 2; } printf("%lld\n", ans); }
#include <bits/stdc++.h> //#include <atcoder/modint> //using namespace atcoder; //#pragma GCC optimize("Ofast") using namespace std; #define reps(i,s,n) for(int i = s; i < n; i++) #define rep(i,n) reps(i,0,n) #define Rreps(i,n,e) for(int i = n - 1; i >= e; --i) #define Rrep(i,n) Rreps(i,n,0) #define ALL(a) a.begin(), a.end() using ll = long long; using vec = vector<ll>; using mat = vector<vec>; ll N,M,H,W,Q,K,A,B; string S; using P = pair<ll, ll>; using tp = tuple<ll, ll, ll>; const ll INF = (1LL<<61); template<class T> bool chmin(T &a, const T b){ if(a > b) {a = b; return true;} else return false; } template<class T> bool chmax(T &a, const T b){ if(a < b) {a = b; return true;} else return false; } template<class T> void my_printv(std::vector<T> v,bool endline = true){ if(!v.empty()){ for(std::size_t i{}; i<v.size()-1; ++i) std::cout<<v[i]<<" "; std::cout<<v.back(); } if(endline) std::cout<<std::endl; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cin>>N; vec a(N); ll sum{}, res{}; unordered_map<ll, ll> num; num[0] = 1; rep(i, N){ cin>>a[i]; sum += (i&1 ? a[i] : -a[i]); res += num[sum]; num[sum] += 1; } cout<<res<<endl; }
#include <bits/stdc++.h> using namespace std; const int N=2e6+50; int n,m; int a[N],b[N]; int mex; void add(int i){ b[a[i]]++; // 变大根本没意义啊 // if(a[i]==mex){ // mex=a[i]+1; // TODO tle了 // while(b[mex]){ // mex++; // } // } } void del(int i){ b[a[i]]--; if(b[a[i]]==0 && a[i]<mex){ mex=a[i]; } } int main(){ scanf("%d%d",&n,&m); for(int i=1;i<=n;i++){ scanf("%d",&a[i]); } for(int i=1;i<=m;i++){ add(i); } for(int i=0;i<=n;i++){ if(b[i]==0){ mex=i; break; } } for(int i=m+1;i<=n;i++){ add(i); del(i-m); } printf("%d\n",mex); return 0; }
#include <bits/stdc++.h> #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define ll long long #define ld long double #define lb lower_bound #define ub upper_bound #define pb push_back #define mkpr make_pair #define fi(i,a,b) for (ll i=a;i<b;i++) #define vll vector<ll> #define vch vector<char> #define vst vector<string> #define vpll vector<pll> #define vii vector<int> #define vvl vector<vector<ll>> #define all(v) v.begin(),v.end() #define rev(v) reverse(v.begin(),v.end()) #define srt(v) sort(v.begin(),v.end()) #define rsrt(v) sort(v.rbegin(), v.rend()) #define mxe(v) *max_element(v.begin(),v.end()) #define pii pair<int, int> #define pll pair<ll, ll> #define ff first #define ss second #define mll map<ll, ll> #define gcd(a, b) __gcd(a, b) #define lcm(a, b) ((a)*1ll * (b)) / gcd(a, b) #define nl "\n" #define sp " " #define sz(x) (int)x.size() using namespace std; double PI = (acos(-1)); ll md = 1000000007; //ll md = 998244353; ll pw(ll a, ll b){ll c=1,m=a;while (b){if (b&1)c=(c*m);m=(m*m);b/=2;}return c;} ll pwmd(ll a, ll b){ll c = 1, m = a;while (b){if (b & 1)c = ((c * m)) % md;m = (m * m) % md;b /= 2;}return c;} ll modinv(ll n){return pwmd(n, md - 2);} ll nc2(ll n){return (1ll * n * (n - 1)) / 2;} bool prime(ll a){for(int i=2;i*i<=a;i++){if(a%i==0)return false;}return true;} ll ceel(ll a,ll b){if(a%b==0) return a/b;else return a/b+1;} #define MAX_SIZE 1000005 void Sieve(vector<int> &primes){bool IsPrime[MAX_SIZE];memset(IsPrime, true, sizeof(IsPrime)); for (int p = 2; p * p < MAX_SIZE; p++){if (IsPrime[p] == true){ for (int i = p * p; i < MAX_SIZE; i += p)IsPrime[i] = false;}} for (int p = 2; p < MAX_SIZE; p++)if (IsPrime[p])primes.push_back(p);} //vector<char> sml={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'}; //vector<char> cap={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'}; void solve(){ ll n,m; cin>>n>>m; ll l[n]; fi(i,0,n)cin>>l[i]; map<ll,ll>mp; set<ll>s; fi(i,0,n+1)s.insert(i); fi(i,0,m){ if(mp[l[i]]==0)s.erase(l[i]); mp[l[i]]++; } auto itr=s.begin(); ll mx=*itr; fi(i,m,n){ if(mp[l[i-m]]==1)s.insert(l[i-m]); mp[l[i-m]]--; if(mp[l[i]]==0)s.erase(l[i]); mp[l[i]]++; auto z=s.begin(); mx=min(mx,*z); } cout<<mx; } int main(){ //vector<int> primes; //Sieve(primes); fast ll tests=1; //cin>>tests; while(tests--){ solve(); } return 0; }
#include<bits/stdc++.h> #define ll long long using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll n,m,k,ans=0; cin>>n>>m; vector<vector<ll>> a(m,vector<ll>(2)); vector<ll> c(n+1,0); for(ll i=0;i<m;i++) cin>>a[i][0]>>a[i][1]; cin>>k; vector<vector<ll>> b(k,vector<ll>(2)); for(ll i=0;i<k;i++) cin>>b[i][0]>>b[i][1]; for(ll i=0;i<(1LL<<k);i++) { ll x=0; for(ll j=0;j<k;j++) { if((1LL<<j)&i) c[b[j][1]]=1; else c[b[j][0]]=1; } for(ll j=0;j<m;j++) { if(c[a[j][0]]&&c[a[j][1]]) x++; } for(ll j=0;j<=n;j++) c[j]=0; ans=max(ans,x); } cout<<ans; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--) #define all(x) (x).begin(), (x).end() #define sz(x) int(x.size()) using namespace std; using ll = long long; const int INF = 1e9; const ll LINF = 1e18; template <class T> void get_unique(vector<T>& x) { x.erase(unique(x.begin(), x.end()), x.end()); } template <class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); } template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); } template <typename T> istream& operator>>(istream& is, vector<T>& v) { for (int i = 0; i < int(v.size()); i++) { is >> v[i]; } return is; } template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { for (int i = 0; i < int(v.size()); i++) { os << v[i]; if (i < sz(v) - 1) os << ' '; } return os; } struct UnionFind { vector<int> data; vector<map<int, int>> mp; UnionFind(int size, vector<map<int, int>> _mp) : data(size, -1), mp(_mp) { } int root(int x) { return (data[x] < 0) ? x : data[x] = root(data[x]); } bool unite(int x, int y) { x = root(x); y = root(y); if (x != y) { if (data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = x; for (auto [key, num] : mp[y]) { mp[x][key] += num; } } return x != y; } bool find(int x, int y) { return root(x) == root(y); } int size(int x) { return -data[root(x)]; } }; int main() { int n, q; cin >> n >> q; vector<map<int, int>> mp(n); rep(i, n) { int c; cin >> c; mp[i][c] = 1; } UnionFind uf(n, mp); while (q--) { int t; cin >> t; if (t == 1) { int a, b; cin >> a >> b; a--, b--; uf.unite(a, b); } if (t == 2) { int x, y; cin >> x >> y; x--; cout << uf.mp[uf.root(x)][y] << '\n'; } } }
#include <bits/stdc++.h> #include <vector> #include <string> #include <algorithm> using namespace std; vector<string> split(const string &s, char delim) { vector<string> elems; string item; for (char ch: s) { if (ch == delim) { if (!item.empty()) { elems.push_back(item); } item.clear(); } else { item += ch; } } if (!item.empty()) { elems.push_back(item); } return elems; } string to_str_with_zero(int i, int w) { ostringstream sout; sout << std::setfill('0') << std::setw(w) << i; string s = sout.str(); return s; } int letter_to_int(char c) { return tolower(c) - 'a'; } int compare_array(vector<int> a1, vector<int>a2) { int n1 = a1.size(); int n2 = a2.size(); if (n1 != n2) { return n1 - n2; } for (int i=0; i<n1; i++) { if (a1.at(i) != a2.at(i)) { return a1.at(i) - a2.at(i); } } return 0; } int gcd(int a, int b) { if(a % b == 0) { return b; } return gcd(b, a % b); } char int_to_char(int a) { if (a == -1) { return 'z'; } else { return 'a' + a; } } long nCr(int n, int r) { long ans = 1; for (int i = n; i > n - r; --i) { ans = ans*i; } for (int i = 1 ; i < r + 1; ++i) { ans = ans / i; } return ans; } long modinv(long a, long m) { long b = m, u = 1, v = 0; while (b) { long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } int divide_count(int a, int divider) { int r = 0; while(a % divider == 0) { a /= divider; r++; } return r; } bool is_prime(int a) { int i = 2; while(i * i <= a) { if(a % i == 0) { return false; } i++; } return true; } vector<vector<int>> all_comb(int n, int k) { vector<vector<int>> combs(nCr(n, k), vector<int>(k)); for(int i=0; i<k; i++) { combs[0][i] = i; combs[1][i] = i; } for(long i=1; i<nCr(n, k); i++) { int p = 1; while(combs[i][k - p] == n - p) { p++; if(p > k) { break; } } combs[i][k - p]++; int q = combs[i][k - p]; for(int j=1; j<p; j++) { combs[i][k - p + j] = q + j; } if(i < nCr(n, k) - 1) { for(int j=0; j<k; j++) { combs[i + 1][j] = combs[i][j]; } } } return combs; } struct UnionFind { vector<int> parent; UnionFind(int n) : parent(n) { for(int i=0; i<n; i++) { parent[i] = i; } } int root(int x) { if (parent[x] == x) { return x; } return parent[x] = root(parent[x]); } void unite(int x, int y) { int rx = root(x); int ry = root(y); if(rx == ry) return; parent[rx] = ry; } bool same(int x, int y) { int rx = root(x); int ry = root(y); return rx == ry; } }; template <typename TYPE> void co(TYPE a) { cout << a << endl; } template <typename TYPE> void co_2(TYPE a, TYPE b) { cout << a << ' ' << b << endl; } template <typename TYPE> void co_l(vector<TYPE> as) { int n = as.size(); for(int i=0; i<n; i++) { cout << as[i] << endl; } } template <typename TYPE> void co_s(vector<TYPE> as) { int n = as.size(); for(int i=0; i<n; i++) { if(i > 0) { cout << ' '; } cout << as[i]; } cout << endl; } int main() { std::cout << std::setprecision(9); long mod = 1000000007; int n; cin >> n; if(n % 2 == 0) { co("White"); } else { co("Black"); } }
#include<bits/stdc++.h> #define db double #define reg register #define LL long long #define pb push_back #define lb lower_bound #define ub upper_bound #define ull unsigned long long #define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;++i) #define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;--i) #define erep(i,a) for(int i=head[a];i;i=e[i].nxt) using namespace std; bool Handsome; inline void Mi(int &x,int y){if(x>y && (x=y));} inline void Mx(int &x,int y){if(x<y && (x=y));} const int M=2e5+5; int n,a[M],b[M],c[M<<1],d[M],ct; vector<int> ga[M<<1],gb[M<<1]; struct BIT{ int t[M]; void add(int x){ for(;x;x-=x&-x)++t[x]; } int ask(int x){ int res=0; for(;x<=n;x+=x&-x)res+=t[x]; return res; } }bit; bool Most; int main(){ // printf("%.2lfMB\n",(&Most-&Handsome)/1024.0/1024.0); scanf("%d",&n); rep(i,1,n)scanf("%d",&a[i]),c[++ct]=(a[i]+=i); rep(i,1,n)scanf("%d",&b[i]),c[++ct]=(b[i]+=i); sort(c+1,c+ct+1);ct=unique(c+1,c+ct+1)-c-1; rep(i,1,n)ga[lb(c+1,c+ct+1,a[i])-c].pb(i); rep(i,1,n)gb[lb(c+1,c+ct+1,b[i])-c].pb(i); rep(i,1,ct){ sort(ga[i].begin(),ga[i].end()); sort(gb[i].begin(),gb[i].end()); if(ga[i].size()!=gb[i].size())return puts("-1"),0; rep(j,0,ga[i].size()-1){ int x=ga[i][j],y=gb[i][j]; d[y]=x; } } LL ans=0; rep(i,1,n)ans+=bit.ask(d[i]),bit.add(d[i]); printf("%lld\n",ans); return 0; }
#include <iostream> using namespace std; int hantei(long long n); int main(){ long long t, n; cin >> t; for (int i = 0; i < t; i++){ cin >> n; if (hantei(n) == -1) cout << "Odd" << endl; else if (hantei(n) == 0) cout << "Same" << endl; else if (hantei(n) == 1) cout << "Even" << endl; } return 0; } int hantei(long long n){ if (n % 2 == 1) return -1; else if (n % 4 == 0) return 1; else return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long int main(){ ll N; scanf("%lld",&N); vector<ll> x(N); ll man = 0; ll you = 0; ll che = 0; for(ll i = 0; i < N; i++) { scanf("%lld",&x.at(i)); man += abs(x.at(i)); you += pow(x.at(i),2); if(che < abs(x.at(i))) che = abs(x.at(i)); } printf("%lld\n%.10f\n%lld\n",man,sqrt(you),che); return 0; }
#include <bits/stdc++.h> #define all(x) x.begin(),x.end() #define setval(arr,v) memset(arr,v,sizeof(arr)); #define int long long int #define mod 1000000007 #define v vector #define umap unordered_map #define pb push_back #define pf push_front #define pii pair<int,int> #define fi first #define se second #define INF 1000000000000000 using namespace std; void solve() { int x,y; cin>>x>>y; if(x == y) cout<<x; else { for (int i = 0; i < 3; ++i) { if(x != i && y != i) cout<<i; } } } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; // cin>>t; while(t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using Graph = vector<vector<int>>; const int inf = 1 << 30; const ll infll = 1LL << 60; const int mod = 1000000007; const int mod9 = 998244353; int main(){ int x, y; cin >> x >> y; if((x + y)%3 == 0){ cout << 0 << endl; } else if((x + y)%3 == 1){ cout << 2 << endl; } else{ cout << 1 << endl; } }
#include <bits/stdc++.h> using namespace std; using namespace std::chrono; typedef long long int ll; using ii= pair<ll,ll>; #define fr(i,a,b) for(ll i=a;i<b;i++) #define all(o) (o).begin(),(o).end() #define F first #define S second #define MP make_pair #define PB push_back #define ld long double #define eps 0.00000000001 #define mod 1000000007 class prioritize{ public: bool operator() (ii &p1,ii &p2){ return p1.F<p2.F; } }; auto start_time= high_resolution_clock::now(); void time() { #ifndef ONLINE_JUDGE auto stop_time= high_resolution_clock::now(); auto duration= duration_cast<milliseconds>(stop_time-start_time); cout<<"run time: "<<duration.count()<<" ms"<<"\n"; #endif return; } void ojudge() { #ifndef ONLINE_JUDGE freopen("input1.txt","r", stdin); freopen("output1.txt","w",stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); return; } int main() { ojudge(); ll n; cin>>n; vector<pair<ll,string>> v(n); fr(i,0,n){ cin>>v[i].S>>v[i].F; } sort(all(v)); cout<<v[n-2].S<<"\n"; time(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i,n) for(ll i=0;i<ll(n);i++) #define REPD(i,n) for(ll i=n-1;i>=0;i--) #define FOR(i,a,b) for(ll i=a;i<=ll(b);i++) #define FORD(i,a,b) for(ll i=a;i>=ll(b);i--) const ll INF = 1000000000000; //10^12:∞ const ll MOD = 1000000007; //10^9+7:合同式の法 void swap(ll &a, ll &b) { ll temp = a; a = b; b = temp; } int main(){ ll N; cin >> N; vector<ll> P(N); for(ll &p : P) { cin >> p; } vector<ll> ans; ll target = 1; ll cur = 0; for(ll i = 1; i < N; i++) { if(P.at(i) == target) { for(ll j = i; j >= target; j--) { swap(P.at(j), P.at(j - 1)); ans.push_back(j); } for(ll j = target - 1; j < i; j++) { if(P.at(j) != j + 1) { cout << -1 << endl; return 0; } } target = i + 1; } } // targetがNでない→すべてのswapを使っていない if(target != N) { cout << -1 << endl; return 0; } for(const ll &elm : ans) { cout << elm << endl; } return 0; }
#include <iostream> using namespace std; typedef long long ll; const int MOD = 998244353; struct Modint { ll val; Modint (ll _val = 0) : val(_val % MOD) {} Modint operator+ (Modint other) const { return Modint(val + other.val); } void operator+= (Modint other) { val += other.val; val %= MOD; } Modint operator- () const { return Modint(MOD - val); } Modint operator- (Modint other) const { return Modint(val + MOD - other.val); } void operator-= (Modint other) { val += MOD - other.val; val %= MOD; } Modint operator* (Modint other) const { return Modint(val * other.val); } void operator*= (Modint other) { val *= other.val; val %= MOD; } bool operator== (Modint other) const { return val == other.val; } bool operator!= (Modint other) const { return val != other.val; } }; Modint exp (Modint a, int k) { if (k == 0) { return Modint(1); } else if (k % 2 == 0) { Modint half = exp(a, k / 2); return half * half; } else { return a * exp(a, k - 1); } } Modint inv (Modint a) { return exp(a, MOD - 2); } ostream& operator<< (ostream& out, Modint p) { out << p.val; return out; } int main () { int n, m; cin >> n >> m; Modint ans = Modint(n) * exp(Modint(m), n); Modint im = inv(Modint(m)); for (int j = 1; j <= m; j++) { Modint emj (1); // (m - j) ^ (v - 1) Modint emnv (0); if (n - 2 >= 0) { emnv = exp(Modint(m), n - 2); } for (int v = 1; v < n; v++) { ans -= Modint(n - v) * emj * emnv; emj *= Modint(m - j); emnv *= im; } } cout << ans << endl; }
//g++ 7.4.0 #include <iostream> #include <bits/stdc++.h> using namespace std; typedef long long ll; #define MOD 998244353 int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll N,M; cin>>N>>M; string s[N]; ll ans = 1; for(ll i=0;i<N;++i) cin>>s[i]; for(ll j=0;j<M;++j) { ll i = 0; ll jj = j; ll tot_R = 0; ll tot_B = 0; while(i >= 0 && jj >= 0 && i < N && jj < M) { //cout<<i<<" "<<jj<<endl; if(s[i][jj] == 'R') tot_R++; else if(s[i][jj] == 'B') tot_B++; --jj; ++i; } //cout<<"----------"<<endl; if(tot_R != 0 && tot_B != 0) { cout<<0<<endl; return(0); } if(!tot_R && !tot_B) ans *= 2LL; ans %= MOD; } for(ll i=1;i<N;++i) { ll ii = i; ll j = M - 1; ll tot_R = 0; ll tot_B = 0; while(j >= 0 && ii >= 0 && j < M && ii < N) { if(s[ii][j] == 'R') tot_R++; else if(s[ii][j] == 'B') tot_B++; j--; ii++; } if(tot_R != 0 && tot_B != 0) { cout<<0<<endl; return(0); } if(!tot_R && !tot_B) ans *= 2LL; ans %= MOD; } cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; void solve() { int n; string s; cin >> n >> s; int ans = 0; for (int i = 0; i < n; ++i) { int c1 = 0, c2 = 0; for (int j = i; j < n; ++j) { if (s[j] == 'A') c1++; else if (s[j] == 'T') c1--; else if (s[j] == 'C') c2++; else c2--; if (c1 == 0 && c2 == 0) ans++; } } cout << ans << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(0); int tt = 1; // cin >> tt; for (int i = 1; i <= tt; ++i) { solve(); } return 0; }
#include <bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> #define in(x) freopen(x, "r", stdin) #define out(x) freopen(x, "w", stdout) //#pragma GCC optimize("Ofast") //#pragma GCC optimize("unroll-loops") //#pragma GCC optimize("-O3") #define F first #define S second #define pb push_back #define N +100500 //#define M ll(998244353) #define M ll(1e9 + 7) #define sz(x) (int)x.size() #define re return #define oo ll(1e18) #define el '\n' #define pii pair <int, int> #define all(x) (x).begin(), (x).end() #define arr_all(x, n) (x + 1), (x + 1 + n) #define vi vector <int> #define last(x) (x).back() using namespace std; //using namespace __gnu_pbds; //typedef tree <int, null_type, less_equal <int> , rb_tree_tag, tree_order_statistics_node_update> ordered_set; typedef long long ll; typedef long double ld; string s; int n, i, c[300], mp[4], j, ans; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout << setprecision(6); cout << fixed; // in("sequence.in"); // out("sequence.out"); // in("D:/cpp/2/output.txt"); // out("output.txt"); c['A'] = 0; c['T'] = 1; c['G'] = 2; c['C'] = 3; cin >> n >> s; for (i = 0; i < n; i++) { mp[0] = mp[1] = mp[2] = mp[3] = 0; for (j = i; j < n; j++) { mp[c[s[j]]]++; if (mp[0] == mp[1] && mp[2] == mp[3]) ans++; } } cout << ans; }
#include<bits/stdc++.h> using namespace std; //#include <atcoder/lazysegtree> //using namespace atcoder; //using mint = modint998244353; //using mint = modint1000000007; #pragma region template using ll = long long; using PII = pair<int, int>; using PLL = pair<ll, ll>; template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; #define overload4(_1,_2,_3,_4,name,...) name #define overload3(_1,_2,_3,name,...) name #define rep1(n) for(ll i=0;i<n;++i) #define rep2(i,n) for(ll i=0;i<n;++i) #define rep3(i,a,b) for(ll i=a;i<b;++i) #define rep4(i,a,b,c) for(ll i=a;i<b;i+=c) #define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__) #define rrep1(n) for(ll i=n;i--;) #define rrep2(i,n) for(ll i=n;i--;) #define rrep3(i,a,b) for(ll i=b;i-->(a);) #define rrep(...) overload3(__VA_ARGS__,rrep3,rrep2,rrep1)(__VA_ARGS__) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) ((int)(x).size()) #define pb push_back #define eb emplace_back #define fi first #define se second #define debug(var) do{std::cerr << #var << " : ";view(var);}while(0) template<typename T> void view(T e){std::cerr << e << std::endl;} template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cerr << e << " "; } std::cerr << std::endl;} template<typename T> void view(const std::vector<std::vector<T> >& vv){cerr << endl;int cnt = 0;for(const auto& v : vv){cerr << cnt << "th : "; view(v); cnt++;} cerr << endl;} std::ostream &operator<<(std::ostream &dest, __int128_t value) { std::ostream::sentry s(dest); if (s) { __uint128_t tmp = value < 0 ? -value : value; char buffer[128]; char *d = std::end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } int len = std::end(buffer) - d; if (dest.rdbuf()->sputn(d, len) != len) { dest.setstate(std::ios_base::badbit); } } return dest; } template<class T, class K>bool chmax(T &a, const K b) { if (a<b) { a=b; return 1; } return 0; } template<class T, class K>bool chmin(T &a, const K b) { if (b<a) { a=b; return 1; } return 0; } const int inf = 1001001001; const ll INF = 1001001001001001001ll; int dx[]={1,0,-1,0}; int dy[]={0,1,0,-1}; ll rddiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // -20 / 3 == -7 ll power(ll a, ll p){ll ret = 1; while(p){if(p & 1){ret = ret * a;} a = a * a; p >>= 1;} return ret;} ll modpow(ll a, ll p, ll mod){ll ret = 1; while(p){if(p & 1){ret = ret * a % mod;} a = a * a % mod; p >>= 1;} return ret;} ll rudiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // 20 / 3 == 7 #pragma endregion // const double pi = acos(-1); //const ll mod = 998244353; const ll mod = 1000000007; int dp[2001][2001]; int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); //cout << fixed << setprecision(20); int h, w; cin >> h >> w; V<string> mp(h); rep(i,h) cin >> mp[i]; rep(i,2001) rep(j,2001) dp[i][j] = -inf; dp[h - 1][w - 1] = 0; rrep(i,h){ rrep(j,w){ if(j - 1 >= 0){ if(mp[i][j] == '-') chmax(dp[i][j - 1], -dp[i][j] - 1); else chmax(dp[i][j - 1], -dp[i][j] + 1); } if(i - 1 >= 0){ if(mp[i][j] == '-') chmax(dp[i - 1][j], -dp[i][j] - 1); else chmax(dp[i - 1][j], -dp[i][j] + 1); } } } if(dp[0][0] == 0) cout << "Draw" << endl; else if(dp[0][0] > 0) cout << "Takahashi" << endl; else cout << "Aoki" << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> P; const ll mod=1e9+7; #define rep(i,n) for (int i = 0; i < (n); i++) int n,m,a[1100],b[1100]; vector <pair<int,char>> g[1100]; ll dp[1100][1100]; int main(){ cin >> n >> m; rep(i,n)rep(j,n) dp[i][j]=mod; rep(i,m){ char c; cin >> a[i] >> b[i] >> c; a[i]--;b[i]--; g[a[i]].emplace_back(b[i],c); g[b[i]].emplace_back(a[i],c); } queue<P> q; dp[0][n-1]=0; q.emplace(0,n-1); while(!q.empty()){ int a=q.front().first; int b=q.front().second; q.pop(); for(auto e:g[a])for(auto f:g[b]){ if(e.second == f.second){ if(dp[e.first][f.first]==mod){ dp[e.first][f.first]=dp[a][b]+1; q.emplace(e.first,f.first); } } } } ll ans=mod; rep(i,n)ans=min(ans,dp[i][i]*2); rep(i,m)ans=min({ans,dp[a[i]][b[i]]*2+1,dp[b[i]][a[i]]*2+1}); if(ans==mod)cout << -1 << endl; else cout << ans << endl; return 0; }
// 解き直し. // https://atcoder.jp/contests/arc105/editorial/170 // C++(GCC 9.2.1) #include <bits/stdc++.h> using namespace std; using LL = long long; using P = pair<LL, LL>; #define repex(i, a, b, c) for(int i = a; i < b; i += c) #define repx(i, a, b) repex(i, a, b, 1) #define rep(i, n) repx(i, 0, n) #define repr(i, a, b) for(int i = a; i >= b; i--) #define all(x) x.begin(), x.end() LL cW[11], bL[101010], bV[101010]; struct bridge{ LL l, v; // 長さ, 耐荷重. bool operator < (const bridge& rhs) const{ return (v != rhs.v) ? (v > rhs.v) : (l < rhs.l); } }; int main(){ // 1. 入力情報. int N, M; scanf("%d %d", &N, &M); LL maxW = 0, minV = 202020202020202020; rep(i, N){ scanf("%lld", &cW[i]); maxW = max(maxW, cW[i]); } priority_queue<bridge> pq; rep(i, M){ LL l, v; scanf("%lld %lld", &l, &v); minV = min(minV, v); pq.push({l, v}); } // 2. 橋が崩落するパターンを除外. if(maxW > minV){ puts("-1"); return 0; } // 3. 橋の耐荷重に対する必要な最小間隔を保存. int idx = 0; while(!pq.empty()){ bridge b = pq.top(); pq.pop(); // printf("b.l=%lld b.v=%lld\n", b.l, b.v); bL[idx + 1] = max(bL[idx], b.l); bV[idx + 1] = b.v; idx++; } // rep(i, M + 1) printf("l=%lld v=%lld\n", bL[i], bV[i]); // 4. ラクダの隊列を全探索. vector<int> z(N); iota(all(z), 0); LL ans = -202020202020202020; do{ // 4-1. ラクダの隊列の重量(累積和). LL cWCum[N + 1]; memset(cWCum, 0LL, sizeof(cWCum)); rep(i, N) cWCum[i + 1] = cWCum[i] + cW[z[i]]; // rep(i, N) printf("%d ", z[i]); // puts(""); // rep(i, N + 1) printf("%lld ", cWCum[i]); // puts(""); // 4-2. 制約. LL x[N][N]; memset(x, 0LL, sizeof(x)); rep(i, N){ repx(j, i + 1, N){ int at = lower_bound(bV, bV + M + 1, cWCum[j + 1] - cWCum[i]) - bV - 1; x[i][j] = max(x[i][j], bL[at]); x[j][i] = x[i][j]; } } // rep(i, N){ // repx(j, i + 1, N) printf("%lld ", x[i][j]); // puts(""); // } // 4-3. グラフの最長路の長さは? // ex. // AtCoder Beginner Contest 022 (C - Blue Bird) を ベース に 実装. // https://atcoder.jp/contests/abc022/tasks/abc022_c // -> 具体的には, Warshall–Floyd法で, // repx(k, 1, N) repx(i, 1, N) repx(j, 1, N) d[i][j] = min(d[i][j], d[i][k] + d[k][j]); // とあるものを, i = 0 に 固定するイメージで, 更新する形に変更. LL g[N][N], way = 0; memset(g, 0LL, sizeof(g)); repx(i, 1, N){ rep(j, i + 1){ g[0][i] = min(g[0][i], g[0][j] - x[i][j]); way = min(way, g[0][i]); // printf("i=%d j=%d %lld \n", i, j, x[i][j]); } } // 4-4. 最長路の長さについて, 最小値を更新. ans = max(ans, way); }while(next_permutation(all(z))); // 5. 出力. printf("%lld\n", -ans); return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define db double #define pii pair<int,int> #define pli pair<ll,int> #define pil pair<int,ll> #define pll pair<ll,ll> #define ti3 tuple<int,int,int> #define mat vector<vector<int>> const int inf = 1 << 30; const ll mod = 1e9 + 7; const ll linf = 1LL << 62; const db EPS = 1e-7; template<class T> void chmin(T& x, T y){if(x > y) x = y;} template<class T> void chmax(T& x, T y){if(x < y) x = y;} int N, K; int A[810][810]; int cnt[810][810]; int main() { cin >> N >> K; for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { cin >> A[i][j]; } } int lb = -1, ub = 1e9 + 1; while (ub - lb > 1) { int mid = (ub + lb) / 2; for (int i = 1; i <= N ; i++) { for (int j = 1; j <= N; j++) { cnt[i][j] = (A[i][j] <= mid); } } for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { cnt[i][j + 1] += cnt[i][j]; } } for (int i = 1; i <= N; i++) { for (int j = 1; j <= N; j++) { cnt[i + 1][j] += cnt[i][j]; } } bool flag = false; for (int i = K; i <= N; i++) { for (int j = K; j <= N; j++) { int aa = cnt[i][j] - cnt[i - K][j] - cnt[i][j - K] + cnt[i - K][j - K]; if (aa >= (K * K) - ((K * K) / 2)) flag = true; } } if (flag) ub = mid; else lb = mid; } cout << ub << endl; }
#include <iostream> #include <string> int main() { std::string S, sub, bs = ""; std::cin >> S; int i = 0; while (!(S.substr(i, 1).empty())) { //std::cout << "a" << std::endl; sub = S.substr(i, 1); if (sub == "6") { sub = "9"; } else if (sub == "9") { sub = "6"; } bs = sub + bs; i++; } std::cout << bs << std::endl; }
#include<bits/stdc++.h> #define N using namespace std; typedef long long ll; string s; int main(){ cin>>s; for(int i=0;i<s.size();i++){ if(s[i]=='.')break; cout<<s[i]; } return 0; }
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,a,b) for(int i=a;i>=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() //#pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; 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; } //--------------------------------------------------------------------------------------------------- /*---------------------------------------------------------------------------------------------------             ∧_∧       ∧_∧  (´<_` )  Welcome to My Coding Space!      ( ´_ゝ`) /  ⌒i @hamayanhamayan0     /   \    | |     /   / ̄ ̄ ̄ ̄/  |   __(__ニつ/  _/ .| .|____      \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ double R, X, Y; //--------------------------------------------------------------------------------------------------- void _main() { cin >> R >> X >> Y; double distance = sqrt(X * X + Y * Y); int ans = ceil(distance / R); if (ans == 1 && distance != R) ans++; cout << ans << endl; }
#include <iostream> #include <cstring> #include <algorithm> #include <vector> #include <utility> using ll = long long; //#define rep(i, n) for(int i = 0; i < (int)(n); i++) #define rep(i, n) for(ll i = 0; i < (ll)(n); i++) using namespace std; ll n; ll sum = 0; ll m; ll k; ll minV; int main() { vector<ll> v; cin >> n >> m; rep(i,m) { cin >> k; v.push_back(k); } if (m == 0) { cout << 1; return 0; } sort(v.begin(), v.end()); if(v[v.size()-1] != n) v.push_back(n+1); minV = 1000001000; if (v[0] - 1 < minV && v[0] != 1) minV = v[0] - 1; for (int i = 1; i < v.size(); i++) { if (v[i] - v[i-1] -1 < minV && (v[i] - v[i-1] -1) != 0) minV = v[i] - v[i-1] -1; } if (v[0] != 0){ if ((v[0] - 1) % minV == 0){ sum += (v[0] - 1) / minV; } else{ sum += (v[0] - 1) / minV + 1; } } if (minV == 1000001000) { cout << 0; return 0; } for (int i = 1; i < v.size(); i++) { if((v[i] - v[i-1]-1) % minV == 0){ sum += (v[i] - v[i-1] -1) / minV; } else{ sum += (v[i] - v[i-1]-1) / minV + 1; } } cout << sum; return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long const ll MOD = 1e9+7; const int MAXN = 2e5 + 7; int k; ll dp[MAXN][17]; // dp[i][j] = number of possibilities up to digit i //smaller than n, nonzero, with j distinct digits string n; map<char,int> mp; int mask = 0; int main(){ for(char c='0'; c<='9'; c++)mp[c] = c-'0'; for(char c='A'; c<='F'; c++)mp[c] = 10 + c-'A'; cin >> n >> k; for(int i=0; i < (int)n.size(); i++){ int aux = mp[n[i]];//current digit if(i > 0){ //possibilities that were smaller before for(int j=1; j<=16; j++){//just add any digit dp[i][j] = (dp[i][j] + j*dp[i-1][j])%MOD;//already j dp[i][j] = (dp[i][j] + (17-j)*dp[i-1][j-1])%MOD;//was j-1, add new } //possibilities that become smaller now for(int digit=0; digit < aux; digit++){ if( mask == (mask|(1<<digit)) ){//repeated dp[i][__builtin_popcount(mask)] = (dp[i][__builtin_popcount(mask)] + 1)%MOD; }else{ dp[i][__builtin_popcount(mask) + 1] = (dp[i][__builtin_popcount(mask) + 1] + 1)%MOD; } } } //first nonzero digit if(i > 0)dp[i][1] = (dp[i][1] + 15)%MOD; else dp[i][1] = (dp[i][1] + aux - 1)%MOD; mask |= (1<<aux); } int acc = 0; if(__builtin_popcount(mask) == k)acc = 1;//n inclusive cout<<(dp[(int)n.size()-1][k] + acc)%MOD<<endl; }
#include <iostream> #include <vector> #define rep(i,n) for(int i=0;i<(int)(n); i++) using namespace std; using ll = long long; const ll mod = 1e9+7; const int N_MAX = 2e5+1; const int K_MAX = 17; ll dp[N_MAX][K_MAX][2]; int main() { string S; cin>>S; int N = S.size(); int K; cin>>K; vector<int> nums(N); rep(i,N) nums[i]=('0'<=S[i]&&S[i]<='9')?(S[i]-'0'):(S[i]-'A'+10); vector<int> mask(N+1); vector<int> popcnt(N); rep(i,N){ mask[i+1] = mask[i]|1<<nums[i]; popcnt[i]=__builtin_popcount(mask[i+1]); } dp[0][0][0] = 1; rep(i,N)rep(j,K_MAX){ // same (dp[i+1][popcnt[i]][0]+=dp[i][j][0])%=mod; rep(d,nums[i]){ if (j==0 && d==0){ (dp[i+1][0][1]+=dp[i][0][0])%=mod; continue; } int nj = j + ((mask[i]>>d&1)?0:1); (dp[i+1][nj][1]+=dp[i][j][0])%=mod; } // lower if (j==0){ (dp[i+1][0][1]+=dp[i][0][1])%=mod; (dp[i+1][1][1]+=dp[i][0][1]*15)%=mod; }else{ (dp[i+1][j][1]+=dp[i][j][1]*j)%=mod; if (j+1<=16) (dp[i+1][j+1][1]+=dp[i][j][1]*(16-j))%=mod; } } cout<<dp[N][K][0]+dp[N][K][1]<<"\n"; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<ll,ll> ; #define rep(i,n) for(ll i=0;i<(n);i++) #define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); const ll inf=1LL<<60; ll min(ll a,ll b){return a>=b ? b:a;} ll max(ll a,ll b){return a>=b ? a:b;} ll dist[20][20]; ll k; vector<ll> G[100009]; vector<ll> C; void bfs(ll st,ll cnt){ vector<ll> cost(100009,inf); queue<ll> q; cost[st]=0; q.push(st); while (!q.empty()){ ll x=q.front();q.pop(); for (ll i:G[x]){ if (cost[i]>cost[x]+1){ cost[i]=cost[x]+1; q.push(i); } } } rep(i,k){ dist[cnt][i]=cost[C[i]]; } } int main(){ ll n,m; cin >> n >> m; rep(i,m){ ll a,b;cin >> a >> b; a--;b--; G[a].push_back(b); G[b].push_back(a); } cin >> k; C.resize(k); rep(i,k){ ll c;cin >> c; c--;C[i]=c; } rep(i,k){ bfs(C[i],i); } //rep(i,k) rep(j,k) cout << dist[i][j] << endl; vector<vector<ll>> dp(1<<k,vector<ll>(k,inf)); rep(i,k){ dp[1<<i][i]=1; } for (ll bit=1;bit<(1<<k);++bit){ rep(i,k){ if (bit&(1<<i)){ ll pbit=bit^(1<<i); rep(j,k){ dp[bit][i]=min(dp[bit][i],dp[pbit][j]+dist[i][j]); } } } } ll ans=inf; rep(i,k) ans=min(ans,dp[(1<<k)-1][i]); if (ans==inf) ans=-1; cout << ans << endl; }
#include <iostream> #include <iomanip> #include <string> #include <vector> #include <algorithm> #include <utility> #include <functional> #include <set> #include <map> #include <queue> #include <deque> #include <bitset> #include <math.h> #include <random> #include <chrono> #include <assert.h> using namespace std ; using ll = long long ; using ld = long double ; template<class T> using V = vector<T> ; template<class T> using VV = V<V<T>> ; using pll = pair<ll,ll> ; #define all(v) v.begin(),v.end() ll mod = 1000000007 ; long double pie = acos(-1) ; ll INF = 1e18 ; void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;} void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;} ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;} ll lcm(long long a,long long b){return a/gcd(a,b)*b ;} 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 ; } void fix_cout(){cout << fixed << setprecision(20) ;} template<class T> void chmax(T &a,T &b){if(a<b) a = b ;} template<class T> void chmin(T &a,T &b){if(a>b) a = b ;} int n,m,k ; ll calc(VV<ll> &dp,VV<int> &dis,int cur,int p){ if(~(cur>>p)&1) return INF ; if(dp[cur][p]!=-1){ // cout << cur << " " << p << " " << dp[cur][p] << endl ; return dp[cur][p] ; } ll num = INF ; for(int i=0;i<k;i++){ if((cur>>i)&1){ num = min(num,calc(dp,dis,cur-(1<<p),i)+dis[i][p]) ; } } // cout << cur << " " << p << " " << num << endl ; dp[cur][p] = num ; return num ; } int main(){ cin >> n >> m ; VV<int> g(n) ; for(int i=0;i<m;i++){ int a,b ; cin >> a >> b ; a-- ; b-- ; g[a].push_back(b) ; g[b].push_back(a) ; } auto BFS = [&](V<int> &d,int s){ queue<pair<int,int>> q ; q.emplace(0,s) ; while(!q.empty()){ int p = q.front().second ; int cost = q.front().first ; q.pop() ; if(d[p]!=-1) continue ; d[p] = cost ; for(auto i:g[p]) q.emplace(cost+1,i) ; } } ; cin >> k ; V<int> c(k) ; for(auto &i:c) cin >> i ; for(auto &i:c) i-- ; V<int> d(n,-1) ; BFS(d,c[0]) ; for(auto i:c) if(d[i]==-1){ cout << -1 << endl ; return 0 ; } // for(auto i:d) cout << i << " " ; cout << endl ; VV<int> dis(k,V<int>(k,-1)) ; for(int i=0;i<k;i++) dis[0][i] = d[c[i]] ; for(int i=1;i<k;i++){ d = V<int>(n,-1) ; BFS(d,c[i]) ; for(int j=0;j<k;j++) dis[i][j] = d[c[j]] ; } VV<ll> dp(1<<k,V<ll>(k,-1)) ; for(int i=0;i<k;i++) dp[1<<i][i] = 1 ; ll ans = INF ; for(int i=0;i<k;i++) ans = min(ans,calc(dp,dis,(1<<k)-1,i)) ; cout << ans << endl ; }
#include<bits/stdc++.h> using namespace std; #define make_it_fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define mp make_pair #define eb emplace_back #define pb push_back #define pob pop_back #define all(x) (x).begin(),(x).end() #define allr(x) (x).rbegin(),(x).rend() #define ll long long #define ld long double #define endl "\n" #define ff first #define ss second #define imn (ll)-1e18 #define imx (ll)1e18 ld pi=3.14159265358979323846; 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...) 20 #endif ll mod=1e9+7; vector<ll> seg,fac; ll power(ll a,ll b,ll m) { a%=m; if(b==1) return a; if(b==0) return 1LL; ll ret=power(a,b/2,m); ret=(ret*ret)%m; if(b&1) ret=(ret*a)%m; return ret; } ll power(ll a,ll b) { if(b==1) return a; if(b==0) return 1LL; ll ret=power(a,b/2); ret=(ret*ret); if(b&1) ret=(ret*a); return ret; } ll lcm(ll a,ll b) { return (a*b)/(__gcd(a,b)); } ll phi(ll n) // Euler-Totient Function { ll result = n; for(ll i=2;i*i<=n;i++) { if (n%i==0) { while (n%i==0) n/=i; result/=i; result*=(i-1); } } if (n > 1) { result/=n; result*=(n-1); } return result; } ll findpar(ll x,vector<ll> par) { while(x!=par[x]) { x=par[x]; } return x; } ll construct(ll a[],ll s,ll e,ll i) { if(s==e) { seg[i]=a[s]; return seg[i]; } ll mid=s+(e-s)/2; seg[i]=construct(a,s,mid,2*i+1)^construct(a,mid+1,e,2*i+2); return seg[i]; } void update(ll node,ll val,ll s,ll e,ll i) { if(s==e) { seg[i]=val; return; } ll mid=s+(e-s)/2; if(node<=mid) { update(node,val,s,mid,2*i+1); } else { update(node,val,mid+1,e,2*i+2); } seg[i]=seg[2*i+1]^seg[2*i+2]; } ll query(ll l,ll r,ll s,ll e,ll i) { if(e<l || s>r) return 0; if(s>=l && e<=r) return seg[i]; ll mid=s+(e-s)/2; return (query(l,r,s,mid,2*i+1)^query(l,r,mid+1,e,2*i+2)); } void computeFac(ll mx) { fac.resize(mx+10); fac[0]=1; for(ll i=1;i<mx+10;i++) { fac[i]=(fac[i-1]*i)%mod; } } ll ncr(ll a,ll b) { if(a<b || b<0) return 0; ll x=(fac[a-b]*fac[b])%mod; return (fac[a]*power(x,mod-2,mod))%mod; } void answer_nikaal() { ll n,i; cin>>n; ll b=0; ll ans=imx; for(i=0;i<=n;i++){ if((1LL<<i)>n) break; ans=min(ans,i+n/(1LL<<i)+n%(1LL<<i)); } cout<<ans<<endl; } int main() { make_it_fast; int TEST_CASES=1; // cin>>TEST_CASES; while(TEST_CASES--) { answer_nikaal(); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const ll mod = 1000000007; // TODO: solve without editorial int main() { ll n; cin >> n; vector<ll> a(n + 1); a[1] = 6; a[2] = 10; a[3] = 15; set<ll> s; for (int i = 2; i * a[1] <= 10000; ++i) { if (a[1] * i <= 10000) s.insert(a[1] * i); if (a[2] * i <= 10000) s.insert(a[2] * i); if (a[3] * i <= 10000) s.insert(a[3] * i); } for (int i = 4; i <= n; ++i) { a[i] = *s.begin(); s.erase(s.begin()); } cout << a[1]; for (int i = 2; i <= n; ++i) { cout << ' ' << a[i]; } cout << endl; }
#include <iostream> #include <queue> #include <string> #include <vector> using namespace std; int n, m; vector<pair<int, char>> edges[1000]; int main() { cin >> n >> m; for (int i = 0; i < n; ++i) edges[i].clear(); for (int i = 0; i < m; ++i) { int from, to; char c; cin >> from >> to >> c; --from; --to; edges[from].push_back({ to, c }); edges[to].push_back({ from, c }); }; queue<pair<int, int>> q, qq; q.push(make_pair(0, n - 1)); int d = 0; int res = -1; bool visited[1000][1000] = { 0 }; while (!q.empty()) { while (!q.empty()) { auto front = q.front(); q.pop(); int x = front.first; int y = front.second; for (auto edgeA : edges[x]) { for (auto edgeB : edges[y]) { if (edgeA.second != edgeB.second) continue; if (visited[edgeA.first][edgeB.first]) continue; visited[edgeA.first][edgeB.first] = true; if (edgeA.first == edgeB.first) { res = (res == -1 || res > 2 * (d + 1)) ? 2 * (d + 1) : res; } else if (edgeA.first == y && edgeB.first == x) { res = (res == -1 || res > 2 * d + 1) ? 2 * d + 1 : res; } else { qq.push(make_pair(edgeA.first, edgeB.first)); } } } } swap(q, qq); ++d; } cout << res << endl; return 0; }
#include<bits/stdc++.h> #define fox(i,a,b) for(int i=a;i<=b;++i) #define ll long long using namespace std; int _x, _f; char _c; inline int rd() { _x = 0, _f = 1, _c = getchar(); for (; !isdigit(_c); _c = getchar()) if (_c == '-') _f = 0; for (; isdigit(_c); _c = getchar()) _x = _x * 10 + _c - '0'; return _f ? _x : -_x; } const int N = 1010; int n, m, g = INT_MAX; struct edge { vector<int>tr[26];} e[N]; bool ud[N][N], lt[N][N]; struct nwp { int x, y, st;}; queue<nwp> q; signed main() { n = rd(), m = rd(); int x, y; char c; fox (i, 1, m) { x = rd(), y = rd(); lt[x][y] = lt[y][x] = 1; scanf("%c", &c); e[x].tr[c-'a'].push_back(y); e[y].tr[c-'a'].push_back(x); } nwp a, b; a.x = 1, a.y = n, a.st = 0; if (lt[1][n]) { puts("1"); return 0; } q.push(a); while (!q.empty()) { a = q.front(), q.pop(); if (ud[x = a.x][y = a.y]) continue; ud[x][y] = 1; b.st = a.st + 1; if (b.st * 2 > g) { printf("%d\n", g); return 0; } fox (i, 0, 25) { for (int j = 0; j < e[x].tr[i].size(); ++j){ for (int k = 0; k < e[y].tr[i].size(); ++k){ b.x = e[x].tr[i][j], b.y = e[y].tr[i][k]; if (b.x == b.y) { printf("%d\n", b.st * 2); return 0; } if (lt[b.x][b.y]) g = b.st * 2 + 1; if (ud[b.x][b.y]) continue; q.push(b); } } } } puts("-1"); return 0; }
#include <bits/stdc++.h> using namespace std; #define ALL(x) (x).begin(),(x).end() #define COUT(x) cout<<(x)<<"\n" #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define REP(i,n) for(int i=0;i<n;i++) #define YES(x) cout<<(x?"YES":"NO")<<"\n" #define Yes(x) cout<<(x?"Yes":"No")<<"\n" #define dump(x) cout<<#x<<" = "<<(x)<<"\n" #define endl "\n" using G = vector<vector<int>>; using M = map<int,int>; using P = pair<int,int>; using PQ = priority_queue<int>; using PQG = priority_queue<int,vector<int>,greater<int>>; using V = vector<int>; using ll = long long; using edge = struct { int to; int cost; }; 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 int MOD = 1e9+7; const ll LINF = 1e18; const int MX = 1500; const pair<int, int> direction[4] = { { -1, 0 }, { 1, 0 }, { 0, -1 }, { 0, 1 } }; int h,w,n,m; bool light[MX][MX]; bool wall[MX][MX]; bool ok[MX][MX]; bool visited[MX][MX]; bool memo[MX][MX]; bool f(int d, int i, int j) { if (i < 0 || j < 0 || h <= i || w <= j) return false; if (wall[i][j]) return false; if (light[i][j]) return true; if (visited[i][j]) return memo[i][j]; visited[i][j] = true; int ni = i + direction[d].first; int nj = j + direction[d].second; return memo[i][j] = f(d, ni, nj); } int main() { IOS; cin >> h >> w >> n >> m; REP(i,n) { int a,b; cin >> a >> b; a--; b--; light[a][b] = 1; } REP(i,m) { int c,d; cin >> c >> d; c--; d--; wall[c][d] = 1; } REP(d,4) { REP(i,h) REP(j,w) visited[i][j] = 0; REP(i,h) REP(j,w) if(f(d,i,j)) ok[i][j] = 1; } int ans = 0; REP(i,h) REP(j,w) ans += ok[i][j]; COUT(ans); return 0; }
#include <bits/stdc++.h> #define ll long long #define ld long double using namespace std; const int N = 2000 + 5, mod = 1e9 + 7; int n, m, a[N][N], vis_r[N][N], vis_c[N][N]; void solve(int r, int c){ int cc = c; while(cc <= m && vis_r[r][cc] == 0 && a[r][cc] != -1){ vis_r[r][cc] = 1; cc++; } cc = c - 1; while(cc && vis_r[r][cc] == 0 && a[r][cc] != -1){ vis_r[r][cc] = 1; cc--; } int rr = r; while(rr <= n && vis_c[rr][c] == 0 && a[rr][c] != -1){ vis_c[rr][c] = 1; rr++; } rr = r - 1; while(rr && vis_c[rr][c] == 0 && a[rr][c] != -1){ vis_c[rr][c] = 1; rr--; } } int main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int q, q2; cin >> n >> m >> q >> q2; while(q--){ int x, y; cin >> x >> y; a[x][y] = 1; } while(q2--){ int x, y; cin >> x >> y; a[x][y] = -1; } for(int i = 1; i <= n; i++){ for(int j = 1; j <= m; j++){ if(a[i][j] == 1) solve(i, j); } } int ans = 0; for(int i = 1; i <= n; i++){ for(int j = 1; j <= m; j++){ if(vis_r[i][j] || vis_c[i][j]) ans++; } } cout << ans; return 0; }
#include <bits/stdc++.h> //#include <atcoder/all> //using namespace atcoder; //#include <boost/multiprecision/cpp_int.hpp> //#include <boost/multiprecision/cpp_dec_float.hpp> //using namespace boost::multiprecision; using namespace std; #pragma region Macros using ll = long long; #define int ll using pii = pair<int, int>; using tiii = tuple<int, int, int>; template<class T = int> using V = vector<T>; template<class T = int> using VV = V<V<T>>; #define IOS\ ios::sync_with_stdio(false);\ cin.tie(0);\ cout.tie(0); #define FOR(i,l,r) for(int i=(l);i<int(r);++i) #define REP(i,n) FOR(i,0,n) #define REPS(i,n) FOR(i,1,n+1) #define RFOR(i,l,r) for(int i=(l);i>=int(r);--i) #define RREP(i,n) RFOR(i,n-1,0) #define RREPS(i,n) RFOR(i,n,1) #define mp make_pair #define mt make_tuple #define pb push_back #define eb emplace_back #define all(x) (x).begin(),(x).end() #define SORT(name) sort(name.begin(), name.end()) #define RSORT(name)\ SORT(name);\ reverse(all(name)); #define ZERO(p) memset(p, 0, sizeof(p)) #define MINUS(p) memset(p, -1, sizeof(p)) inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';} inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';} template <class T> inline void print(T x){ cout << x << '\n';} template<typename T1,typename T2> inline void chmin(T1 &a, T2 b){ if(a > b) a = b; } template<typename T1,typename T2> inline void chmax(T1 &a, T2 b){ if(a < b) a = b; } const ll LLINF = (1LL<<60); const int INF = (1LL<<30); const double DINF = std::numeric_limits<double>::infinity(); #pragma endregion const int MOD = 1000000007; //const int MOD = 998244353; #if 1 # define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__) #else # define DBG(fmt, ...) #endif const int MAX_N = 200010; string S1, S2, S3; const char ng[] = "UNSOLVABLE"; V<> alph_id; V<> id_alph; int alph_size = 0; int StrToNum(V<>& table, const string& s) { string ret = ""; REP(i, s.length()) { char c = '0' + table[s[i] - 'a']; if(i == 0 && c == '0') { return -1; } ret += c; } return atoll(ret.c_str()); } signed main() { IOS; cin >> S1 >> S2 >> S3; map<char, bool> pat; REP(i, S1.length()) { pat[S1[i]] = true; } REP(i, S2.length()) { pat[S2[i]] = true; } REP(i, S3.length()) { pat[S3[i]] = true; } if(pat.size() > 10) { print(ng); return 0; } alph_id.assign(30, -1); for(auto& p : pat) { alph_id[p.first - 'a'] = alph_size; id_alph.pb(p.first - 'a'); alph_size++; } V<> num; REP(i, 10) { num.pb(i); } do { V<> p(30, -1); REP(i, alph_size) { int ind = id_alph[i]; p[ind] = num[i]; } int n1 = StrToNum(p, S1); if(n1 < 0) { continue; } int n2 = StrToNum(p, S2); if(n2 < 0) { continue; } int n3 = StrToNum(p, S3); if(n3 < 0) { continue; } if(n1 + n2 == n3) { print(n1); print(n2); print(n3); return 0; } } while(next_permutation(num.begin(), num.end())); print(ng); return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long LL; int main() { ios_base::sync_with_stdio(0), cin.tie(0); string s1, s2, s3; cin >> s1 >> s2 >> s3; if(s3.size() < s1.size() || s3.size() < s2.size()){ cout << "UNSOLVABLE" << '\n'; return 0; } vector<int> v(10); for(int i=0; i<10; i++) v[i] = i; int alpha[26]; LL n1, n2, n3; bool ans = false, flag = false; do{ if(v[0] == 0) continue; memset(alpha, -1, sizeof(alpha)); int cur = 0; n1 = n2 = n3 = 0; for(int i=0; i<s1.size(); i++){ n1 *= 10; int pos = s1[i] - 'a'; if(alpha[pos] == -1){ n1 += v[cur]; alpha[pos] = cur++; } else n1 += v[alpha[pos]]; } if(flag) continue; for(int i=0; i<s2.size(); i++){ n2 *= 10; int pos = s2[i] - 'a'; if(alpha[pos] == -1){ if(cur == 10){ flag = true; break; } n2 += v[cur]; alpha[pos] = cur++; } else n2 += v[alpha[pos]]; } if(flag) continue; for(int i=0; i<s3.size(); i++){ n3 *= 10; int pos = s3[i] - 'a'; if(alpha[pos] == -1){ if(cur == 10){ flag = true; break; } n3 += v[cur]; alpha[pos] = cur++; } else n3 += v[alpha[pos]]; } if(flag) continue; if(n1 == 0 || n2 == 0 || !v[alpha[s1[0]-'a']] || !v[alpha[s2[0]-'a']] || !v[alpha[s3[0]-'a']]) continue; if(n1 + n2 == n3){ ans = true; for(int i=0; i<s1.size(); i++){ int pos = s1[i] - 'a'; cout << v[alpha[pos]]; } cout << '\n'; for(int i=0; i<s2.size(); i++){ int pos = s2[i] - 'a'; cout << v[alpha[pos]]; } cout << '\n'; for(int i=0; i<s3.size(); i++){ int pos = s3[i] - 'a'; cout << v[alpha[pos]]; } cout << '\n'; break; } }while(next_permutation(v.begin(),v.end())); if(!ans) cout << "UNSOLVABLE" << '\n'; return 0; }
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main (){ int n,k; cin >> n >> k; vector<vector<int>>T(n,vector<int>(n)); for(int i=0;i<n;i++)for(int j=0;j<n;j++){ cin >> T[i][j]; } vector<int>index; for(int i=0;i<n;i++)index.push_back(i); int ans=0; do{ int time=0; for(int i=0;i<n;i++)time+=T[index[i]][index[(i+1)%n]]; if(time==k)ans++; }while(next_permutation(index.begin()+1, index.end())); cout << ans; }
#include<bits/stdc++.h> using namespace std; #define ll long long int #define f(i,a,n) for(ll i=a;i<n;i++) #define w(x) ll _t;cin>>_t;f(x,1,_t+1) #define br cout<<"\n" #define N 10000000 ll md=1e9+7,n; ll h,w,m,k; //l,d,r,u ll x[]={0,1,0,-1}; ll y[]={1,0,-1,0}; ll mat[15][15]; bool isSafe(ll i,ll j){ return i>=0 && i<h && j>=0 && j<w; } ll sol(ll x,ll sm,ll u){ if(x==(1<<n)-1){ if(sm+mat[0][u]==k) return 1; return 0; } ll ans=0; f(i,0,n){ if(((1<<i) & x) == 0){ ans += sol(x | (1<<i) ,sm+mat[u][i] ,i); } } return ans; } int main() { ios::sync_with_stdio(false);cin.tie(0); //w(_x) { cin>>n>>k; f(i,0,n) f(j,0,n) cin>>mat[i][j]; cout<<sol(1,0,0); } return 0; }
#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> using namespace std; typedef unsigned long long ull; typedef long long ll; typedef pair<int, int> ii; typedef vector<ii> vii; typedef vector<int> vi; typedef vector<ll> vll; #define PI (2*acos(0.0)) #define eps 1e-9 #define pb push_back #define endl "\n" #define watch(x) cout << (#x) << " is " << (x) << endl; #define show(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi] << " "; cout << endl; #define showpair(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi].first << " " << v[fi].second << endl; #define ff first #define ss second #define fu cout << "lol" << endl; #define precision(n) cout << fixed << setprecision(n); #define lb lower_bound #define up upper_bound #define vscan for(i = 0;i<n;i++){cin>>in; v.pb(in);} #define all(a) a.begin(), a.end() #define min3(a,b,c) min(a,min(b,c)) #define max3(a,b,c) max(a,max(b,c)) #define mem(a,val) memset(a,val,sizeof(a)) #define loop(i,n) for(i = 0; i < n; i++) #define TC ull T; cin>>T; while(T--) #define IN(x) {scanf("%d",&x);} #define LL(x) {scanf("%lld",&x);} #define CC(x) {scanf("%c",&x);} #define pfl(x) printf("%d\n",x) #define pfll(x) printf("%lld\n",x) #define newl puts("") #define space printf(" ") #define MOD 1000000007 #define speed ios_base::sync_with_stdio(false); cin.tie(NULL); #define ar array int n; ar<int,3> arr[20]; ll dp[18][ (1<<20) ]; ll dis(int a, int b){ return llabs(arr[b][0] - arr[a][0]) + llabs(arr[b][1] - arr[a][1]) + max(0, arr[b][2] - arr[a][2]); } ll inf = (1LL<<40); ll f(int node, int mask){ if(mask == (1<<n)-1){ return dis(node,0); } ll &ret = dp[node][mask]; if(ret != -1) return ret; ret = inf; for(int i = 1; i < n; i++){ if((mask & (1<<i)) == 0){ ret = min(ret, f(i, mask | (1<<i)) + dis(node,i)); } } return ret; } void solve(){ cin>>n; for(int i = 0; i < n; i++){ cin>>arr[i][0]; cin>>arr[i][1]; cin>>arr[i][2]; } mem(dp,-1); cout << f(0, 1) << endl; } int main() { speed; solve(); return 0; }
#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("Ofast") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define deb(x) cout << #x << " is " << x << "\n" #define int long long #define MOD 1000000007LL #define PI acos(-1) template <typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>; template <typename T> using max_heap = priority_queue<T>; template <class T> using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>; template <typename... T> void read(T &...args) { ((cin >> args), ...); } template <typename... T> void write(T &&...args) { ((cout << args), ...); } template <typename T> void readContainer(T &t) { for (auto &e : t) { read(e); } } template <typename T> void writeContainer(T &t) { for (const auto &e : t) { write(e, " "); } write("\n"); } auto speedup = []() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); return nullptr; }(); void solve(int tc) { int n, s, d, x, y; read(n, s, d); bool ok = false; while (n--) { read(x, y); if (x < s && y > d) { ok = true; break; } } write((ok ? "Yes" : "No")); } signed main() { int tc = 1; // read(tc); for (int curr = 1; curr <= tc; curr++) { solve(curr); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N; float D,H; cin >> N >> D >> H; float d[N],h[N]; for (int i=0;i<N;i++){ cin >> d[i] >> h[i]; } float ka,high,max=0; for (int i=0;i<N;i++){ ka=abs(H-h[i])/abs(D-d[i]); high=H-ka*D; if (high>max){ max=high; } } if (max<0){ max=0; } cout << max << endl; return 0; }
#include <iostream> #include <vector> #include <map> #include <tuple> #define fi first #define se second #define rep(i,n) for(int i = 0; i < (n); ++i) #define rrep(i,n) for(int i = 1; i <= (n); ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) #define srep(i,s,t) for (int i = s; i < t; ++i) #define rng(a) a.begin(),a.end() #define rrng(a) a.rbegin(),a.rend() #define isin(x,l,r) ((l) <= (x) && (x) < (r)) #define pb push_back #define eb emplace_back #define sz(x) (int)(x).size() #define pcnt __builtin_popcountll #define uni(x) x.erase(unique(rng(x)),x.end()) #define snuke srand((unsigned)clock()+(unsigned)time(NULL)); #define show(x) cerr<<#x<<" = "<<x<<endl; #define PQ(T) priority_queue<T,v(T),greater<T> > #define bn(x) ((1<<x)-1) #define dup(x,y) (((x)+(y)-1)/(y)) #define newline puts("") #define v(T) vector<T> #define vv(T) v(v(T)) using namespace std; typedef long long int ll; typedef unsigned uint; typedef unsigned long long ull; typedef pair<int,int> P; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<P> vp; int getInt(){int x;scanf("%d",&x);return x;} template<typename T>istream& operator>>(istream&i,v(T)&v){rep(j,sz(v))i>>v[j];return i;} template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.fi>>v.se;} template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v){return o<<v.fi<<","<<v.se;} template<typename T>bool mins(T& x,const T&y){if(x>y){x=y;return true;}else return false;} template<typename T>bool maxs(T& x,const T&y){if(x<y){x=y;return true;}else return false;} template<typename T>ll suma(const v(T)&a){ll res(0);for(auto&&x:a)res+=x;return res;} const double eps = 1e-10; int main() { ll n; scanf("%lld", &n); ll sum = 1; for(int i = 2; i<=n; i++) { int value = i; for(int j=i-1; j>1; j--) { if(value % j == 0) { value = value / j; } } if(i == 8) value = value * 2; if(i == 16) value = value * 2; if(i == 27) value = value * 3; sum *= value; } for(int i=2; i<=n; i++) { ll x = (sum+1) % i; if(x != 1) printf("no!!! n: %lld, %d, %lld\n", n, i, x); } cout << sum + 1 << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 105; const int mod = 998244353; int n; int a[maxn]; int inv[maxn]; int f[maxn][maxn][maxn * maxn]; int binpow(int x, int y) { int ans = 1; while(y) { if (y & 1) ans = 1ll * ans * x % mod; y >>= 1; x = 1ll * x * x % mod; } return ans; } void add(int &x, int y) { x += y; if (x >= mod) x -= mod; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int sum = 0, prod = 1; for(int i = 1; i < maxn; ++i) { inv[i] = binpow(i, mod - 2); } cin >> n; for(int i = 0; i < n; ++i) cin >> a[i], sum += a[i], prod = 1ll * prod * (i + 1) % mod; if (sum % 2 == 1) { cout << 0 << endl; return 0; } f[0][0][0] = prod; for(int i = 0; i < n; ++i) { for(int j = 0; j <= i; ++j) { for(int s = 0; s < maxn * maxn; ++s) { if (f[i][j][s] == 0) continue; add(f[i + 1][j][s], f[i][j][s]); add(f[i + 1][j + 1][s + a[i]], 1ll * f[i][j][s] * (j + 1) % mod * inv[n - j] % mod); } } } int ans = 0; for(int i = 1; i <= n; ++i) { ans += f[n][i][sum / 2]; ans = (ans % mod); } cout << ans << 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; struct custom_hash { static uint64_t splitmix64(uint64_t x) { // http://x...content-available-to-author-only...i.it/splitmix64.c x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define pb push_back #define eb emplace_back #define vi vector<int> #define vvi vector<vector<int>> #define vii vector<pii> #define pii pair<int,int> #define all(a) (a).begin(),(a).end() #define ff first #define ss second #define sp(n) setprecision(n)<<fixed #define endl '\n' #define umap unordered_map<long long, vii, custom_hash> #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char* name, Arg1&& arg1){ std::cerr << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...); } // -------------------Standard Traversal Moves--------------------- // vi fx = {1 ,-1 ,0, 0}, fy = {0, 0, -1, 1}; // vi fx = {2, -2, 2, -2, 1, -1, 1, -1}, fy = {1, 1, -1, -1, 2, 2, -2, -2}; // vi fx = {1, 1, 1, -1, -1 , -1, 0, 0}, fy = {1, -1, 0, 1, -1, 0, 1, -1}; // ---------------------------------------------------------------- // #define int long long const int N = 2e5 + 5, K = 20, MOD = 1000000007, mod = 998244353; // const long long INF = LLONG_MAX/2; const int INF = INT_MAX/2; const double pi = 3.141592653589793; int n,m,x,y; int a[105][105]; void solve(){ cin>>n>>m; int sum = 0, mn = INF;; for(int i=1; i<=n; i++){ for(int j=1; j<=m; j++){ cin>>a[i][j]; mn = min(mn, a[i][j]); sum += a[i][j]; } } int ans = sum - (mn*n*m); cout<<ans<<endl; } int32_t main() { IOS; int TESTS=1; // cin>>TESTS; while(TESTS--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int h,w; cin >> h >> w; int n = h*w; vector<int> a(n); for(int i = 0;i < n;i++){ cin >> a.at(i); } sort(a.begin(),a.end()); int ans = 0; for(int i = 0;i < n;i++){ ans += a.at(i)-a.at(0); } cout << ans << endl; }
#include <bits/stdc++.h> #define int long long #define x first #define y second using namespace std; void solve() { int N; cin>>N; int a[N]; for(int i = 0; i<N; i++) cin>>a[i]; int res = INT_MAX; for(int i = 0; i<1<<(N-1); i++){ int ored = 0; int xored = 0; for(int j = 0; j<=N; j++){ if(j<N){ ored |= a[j]; } if(j==N || (i>>j) & 1){ // if we are at the end or there is a // bar at the j-th position. xored ^= ored; ored = 0; } } res = min(res,xored); } cout<<res<<endl; } signed main(){ int T=1; //cin>>T; while(T--){ solve(); } }
#include<iostream> #include<vector> using namespace std; int main(){ int N; cin >> N; int n = 0; for (int i = 0; i < N; i++){ int ai; cin >> ai; if (ai > 10){ n += ai - 10; } } cout << n << endl; }
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<double, double> pdd; typedef pair<ll, ll> pll; #define endl "\n" #define INF 0x3f3f3f3f #define eb emplace_back #define mem(a, b) memset(a , b , sizeof(a)) // const ll mod = 998244353; const ll mod = 1e9 + 7; const double eps = 1e-6; const double PI = acos(-1); const double R = 0.57721566490153286060651209; const int N = 4e5 + 10; struct Edge { int v; ll w; }; vector<Edge> g[N]; vector<ll> cnt(105), XOR(N); void dfs(int u, int fa) { for(auto e : g[u]) { int v = e.v; if(v == fa) continue ; XOR[v] = XOR[u] ^ e.w; dfs(v, u); } for(int i = 0;i < 65; i++) if(XOR[u] & (1ll << i)) cnt[i + 1]++; } void solve() { int n; cin >> n; for(int i = 1;i < n; i++) { int u, v; ll w; cin >> u >> v >> w; g[u].push_back(Edge{v, w}); g[v].push_back(Edge{u, w}); } dfs(1, 0); ll ans = 0; vector<ll> bit(100); bit[1] = 1; for(int i = 2;i < 65; i++) bit[i] = bit[i - 1] * 2 % mod; for(int i = 1;i < 65; i++) { ans = (ans + bit[i] * (n - cnt[i]) % mod * cnt[i]) % mod; } cout << (ans % mod + mod) % mod << endl; } signed main() { ios_base::sync_with_stdio(false); // cin.tie(nullptr); // cout.tie(nullptr); #ifdef FZT_ACM_LOCAL freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); signed test_index_for_debug = 1; char acm_local_for_debug = 0; do { if (acm_local_for_debug == '$') exit(0); if (test_index_for_debug > 20) throw runtime_error("Check the stdin!!!"); auto start_clock_for_debug = clock(); solve(); auto end_clock_for_debug = clock(); cout << "Test " << test_index_for_debug << " successful" << endl; cerr << "Test " << test_index_for_debug++ << " Run Time: " << double(end_clock_for_debug - start_clock_for_debug) / CLOCKS_PER_SEC << "s" << endl; cout << "--------------------------------------------------" << endl; } while (cin >> acm_local_for_debug && cin.putback(acm_local_for_debug)); #else solve(); #endif return 0; }
#include<iostream> #include<vector> #include<queue> using namespace std; int main() { const long long mod = 1e9+7; int N; cin >> N; vector<vector<long long>> edge(N), weight(N); for(int i = 1; i < N; i++) { long long u, v, w; cin >> u >> v >> w; edge[--u].push_back(--v); edge[v].push_back(u); weight[u].push_back(w); weight[v].push_back(w); } vector<long long> dist(N, -1); queue<int> que; que.push(0); dist[0] = 0; while(!que.empty()) { int now = que.front(); que.pop(); for(int i = 0; i < edge[now].size(); i++) { int next = edge[now][i]; long long sum = dist[now]^weight[now][i]; if (dist[next] == -1) { dist[next] = sum; que.push(next); } } } long long ans = 0; for(int d = 0; d < 60; d++) { vector<int> cnt(2); for(int k = 0; k < N; k++) cnt[ (dist[k] >> d) & 1 ]++; // ans += ((1ll << d) % mod) * ((cnt[0]* cnt[1]) % mod); ans += (1ll<<d)%mod*cnt[0]%mod*cnt[1]; ans %= mod; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define int long long int #define ll long long int #define ld long double #define getFaster ios_base::sync_with_stdio(false), cin.tie(nullptr) #define rep(i, init, n) for (int i = init; i < (int)n; i++) #define rev(i, n, init) for (int i = (int)n; i >= init; i--) #define MOD1 1e9 + 7 #define MOD2 998244353 #define f first #define s second #define endl '\n' #define pii pair<int, int> #define tii tuple<int, int> #define all(v) v.begin(), v.end() #define mt make_tuple #define precise(i) cout << fixed << setprecision(i) #define codejam cout << "Case #" << ii + 1 << ": "; #define impossible cout << "IMPOSSIBLE" << endl; #define error(s) throw runtime_error(s) #define prev prev1 std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count()); int myRand(int R) { int val = rng() % R; assert(val >= 0); return val; } const long double PI = atan(1.0) * 4; const int32_t INF32 = 2e9 + 7; const int64_t INF64 = 3e18; const int32_t LOG = 21; const int32_t MOD = MOD1; using namespace std; //-------------------DEBUGGING------------------------- void my_debugger(string s, int LINE_NUM) { cerr << endl; } template <typename start, typename... end> void my_debugger(string s, int LINE_NUM, start x, end... y) { if (s.back() != ',') { s += ','; cerr << "LINE(" << LINE_NUM << "): "; } int i = s.find(','); cerr << s.substr(0, i) << " = " << x; s = s.substr(i + 1); if (!s.empty()) cerr << ", "; my_debugger(s, LINE_NUM, y...); } #ifdef AJIT #define debug(...) my_debugger(#__VA_ARGS__, __LINE__, __VA_ARGS__); #else #define debug(...) ; #endif //----------------------------------------------------- int gcd(int a, int b, int& x, int& y) { if (b == 0) { x = 1; y = 0; return a; } int x1, y1; int d = gcd(b, a % b, x1, y1); x = y1; y = x1 - y1 * (a / b); return d; } bool find_any_solution(int a, int b, int c, int &x0, int &y0, int &g) { g = gcd(abs(a), abs(b), x0, y0); if (c % g) { return false; } x0 *= c / g; y0 *= c / g; if (a < 0) x0 = -x0; if (b < 0) y0 = -y0; return true; } int table[200005] = {0}; void update(int i, int delta) { while (i <= 200003) { table[i] += delta; i += (i & -i); } } int pref_sum(int i) { int sum = 0; while (i > 0) { sum += table[i]; i -= i & -i; } return sum; } int sum(int l, int r) { if (l > r) return 0; return pref_sum(r) - pref_sum(l - 1); } int32_t main() { getFaster; //files_init(); int tests = 1; //cin >> tests; rep(ii, 0, tests) { int n,m; cin>>n>>m; int obs; cin>>obs; vector<pii> vals(obs); vector<int> row(n+1,m+1),col(m+1,n+1); rep(i,0,obs) { cin>>vals[i].f>>vals[i].s; int r,c; tie(r,c)=mt(vals[i].f,vals[i].s); row[r]=min(row[r],c); col[c]=min(col[c],r); } vector<vector<int>> data(m+2); int ans=0; rep(i,1,col[1]) { if(i>n)break; int extend=row[i]-1; ans+=extend; data[1].push_back(i); data[extend+1].push_back(-i); } for(int ind=1;ind<=m;ind++) { vector<int>& temp=data[ind]; rep(i,0,temp.size()) { int val=temp[i]; if(val<0) update(-val,-1); else update(val,1); } if(pref_sum(1)==0)break; int cur=col[ind]-1; ans-=pref_sum(cur); ans+=cur; } cout<<ans<<endl; } return 0; }
#include <iostream> #include <string> #include <utility> #include <stack> #include <vector> #include <queue> #include <algorithm> #include <map> #include <climits> #include <set> #include <cmath> #include <numeric> #include <cfloat> #include <iomanip> using namespace std; long long X[200000]; long long Y[200000]; long long min_X[200000]; long long min_Y[200000]; int sqrtN = 450; struct SqrtDecomposition{ int N, K; vector <long long> data; vector <long long> bucketSum; SqrtDecomposition(int n){ N = n; K = (N + sqrtN - 1) / sqrtN; data.assign(N, 0); bucketSum.assign(K, 0); } void add(int x, int y){ data[x] += y; bucketSum[x / sqrtN] += y; } long long getSum(int x, int y){ long long ans = 0; if(y - x < sqrtN){ for(int i = x; i < y; i++){ ans += data[i]; } return ans; } for(int i = x / sqrtN + 1; i < y / sqrtN; i++){ ans += bucketSum[i]; } for(int i = x; i < (x / sqrtN + 1) * sqrtN; i++){ ans += data[i]; } for(int i = y / sqrtN * sqrtN; i < y; i++){ ans += data[i]; } return ans; } }; int main(){ int H; int W; int M; cin >> H >> W >> M; for(int i = 0; i < M; i++){ cin >> X[i] >> Y[i]; } long long ans = 0; for(int i = 0; i < H; i++){ min_Y[i] = W; } for(int i = 0; i < W; i++){ min_X[i] = H; } for(int i = 0; i < M; i++){ min_Y[X[i] - 1] = min(min_Y[X[i] - 1], Y[i] - 1); min_X[Y[i] - 1] = min(min_X[Y[i] - 1], X[i] - 1); } for(int i = 0; i < min_X[0]; i++){ ans += min_Y[i]; } SqrtDecomposition sq(H); for(int i = 0; i < min_X[0]; i++){ sq.add(i, 1); } vector <pair<long long, long long> > YX_vec; for(int i = 0; i < min_X[0]; i++){ YX_vec.push_back(make_pair(min_Y[i], i)); } sort(YX_vec.begin(), YX_vec.end()); int min_Y_vec_ind = 0; for(int i = 0; i < min_Y[0]; i++){ while(min_Y_vec_ind < min_X[0] && YX_vec[min_Y_vec_ind].first <= i){ if(YX_vec[min_Y_vec_ind].first == i){ sq.add(YX_vec[min_Y_vec_ind].second, -1); } min_Y_vec_ind ++; } ans += min_X[i] - sq.getSum(0, min_X[i]); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #include <algorithm> #include <unordered_map> #define ull unsigned long long #define int long long #define ll long long #define fr(i, n) for (int i = 0; i < n; i++) #define frf(i, j, n) for (int i = j; i <= n; i++) #define frd(i, n) for (int i = n; i >= 0; i--) #define mp(i, j) make_pair(i, j) #define pb(x) push_back(x) #define INF 1e18 using namespace std; typedef pair<int, int> pi; const int MAX = 1e6 + 1; // typedef vector<vector<ll>> matrix; const ll PRIME = 1e9 + 7; typedef pair<int,pair<int,int> > ppi; // const ll MAX = 1e6 + 1; int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int a[MAX]; int b[MAX]; vector<int>graph[MAX]; vector<bool>vis(MAX,0); // vector<bool> connected(MAX,0); pi dfs(int src) { vis[src]=1; pi temp; temp.first+=a[src]; temp.second+=b[src]; for(int i: graph[src]) { if(!vis[i]) { pi tmp2=dfs(i); temp.first+=tmp2.first; temp.second+=tmp2.second; } } return temp; } void solve() { int n,m; cin>>n>>m; // int a[n],b[n]; int sum1=0,sum2=0; fr(i,n) { cin>>a[i]; sum1+=a[i]; } // int st; bool flag=0; fr(i,n) { cin>>b[i]; sum2+=b[i]; if(a[i]!=b[i]) { flag=1; } } int u,v; while(m--) { cin>>u>>v; u--,v--; graph[u].pb(v); graph[v].pb(u); } if(sum1!=sum2) { cout<<"No\n"; return; } if(flag==0) {cout<<"Yes\n";return;} // cout<<st; fr(i,n) { if(!vis[i]) { pi temp=dfs(i); if(temp.first!=temp.second) { cout<<"No\n"; return; } } } cout<<"Yes\n"; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t; t = 1; // cin >> t; // int k=1; while (t--) { // cout << "Case " << k++ << ":\n"; solve(); } }
#include <bits/stdc++.h> typedef long long int ll; typedef long double ld; #define pb push_back #define pii pair < int , int > #define F first #define S second #define endl '\n' #define int long long #define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math") #define kill(x) return cout<<x<<'\n', 0; using namespace std; const int N=2e5+100; vector <int> g[N]; ll a[N]; ll b[N]; ll vis[N]; ll p1=0,p2=0; void dfs(ll v){ vis[v]=1; p1+=a[v]; p2+=b[v]; for (auto u : g[v]){ if (!vis[u]) dfs(u); } return ; } int32_t main(){ ll n,m; cin >> n >> m; for (int i=1;i<=n;i++) cin >> a[i]; for (int i=1;i<=n;i++) cin >> b[i]; for (int i=0;i<m;i++){ ll u,v; cin >> u >> v; g[u].pb(v); g[v].pb(u); } for (int i=1;i<=n;i++){ if (!vis[i]){ dfs(i); if (p1!=p2) kill("No"); } } kill("Yes"); }
#include <bits/stdc++.h> using namespace std; #define ll long long #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) #define P pair<int,char> #define Tp tuple<int,int,int> using Graph = vector<vector<P>>; int main(){ int N; cin >> N; vector<ll> a; ll A; rep(i,N){ cin >> A; a.push_back(A); } sort(a.begin(),a.end()); reverse(a.begin(),a.end()); ll m = 998244353; ll ans = 0; ll k = 0; ll pr = 0; ll n; rep(i,N){ n = a[i]; k = (k*2-pr+n+m)%m; ans += (n*k)%m; ans %= m; pr = n; //cout <<ans << endl; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define all(x) (x).begin(), (x).end() #define int long long #define sz(x) ((int)(x).size()) #define fill(x, value) memset(x, value, sizeof(x)) #define debug(x) cout << #x << " ------> " << x << "\n" typedef pair<int, int> PII; const int N = 3e3 + 3; int arr[N], n, mod = 1e9 + 7, dp[N][N], nxt[N][N]; int ways(int i, int cur) { if (i == n + 1) return true; int sum = 0, tot = 0, onetime = 0; if (dp[i][cur] != -1) return dp[i][cur]; if(nxt[i][cur] != -1) { onetime = 1; tot += ways(nxt[i][cur] + 1, cur + 1); tot += ways(nxt[i][cur] + 1, cur); tot %= mod; } return dp[i][cur] = onetime * tot % mod; } int powr(int a, int n, int m) { int res = 1; while (n) { if (n % 2) res = res * a % m; a = a * a % m; n /= 2; } return res; } void solve() { cin >> n; for (int i = 1; i <= n; i++) cin >> arr[i]; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) dp[i][j] = -1, nxt[i][j] = -1; } for(int i = 1; i <= n; i++){ map<int, int> mp; int pf = 0; mp[0] = 0; for(int j = 1; j <= n; j++){ pf += arr[j]; pf %= i; if(mp.count(pf)) { nxt[mp[pf] + 1][i] = j; } mp[pf] = j; } } int ans = ways(1, 1) * powr(2, mod - 2, mod) % mod; cout << ans << '\n'; } signed 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 T = 1; // cin >> T; for (int i = 1; i <= T; i++) { solve(); // cout << solve() << '\n'; } cerr << "\nTime: " << clock() << " ms"; }
#include "bits/stdc++.h" using namespace std; using ll = long long; using pii = pair <int, int>; using pll = pair <ll, ll>; #define FIO() ios_base::sync_with_stdio(0);cin.tie(NULL); #define lson (node<<1) #define rson ((node<<1)|1) const int mx = 2e5 + 9; ll t[4 * mx]; vector <int> min_row[mx]; void turn_on(int node, int l, int r, int pos) { int mid = (l + r) / 2; if (l == r) { t[node] = 1; return; } if (pos <= mid) turn_on(lson, l, mid, pos); else turn_on(rson, mid + 1, r, pos); t[node] = t[lson] + t[rson]; } ll query(int node, int l, int r, int L, int R) { int mid = (l + r) / 2; if (r < L or R < l) return 0; if (L <= l and r <= R) return t[node]; ll q1 = query(lson, l, mid, L, R); ll q2 = query(rson, mid + 1, r, L, R); return q1 + q2; } int main() { FIO(); int h, w, m; cin >> h >> w >> m; vector <int> row(h + 3, w + 1), col(w + 3, h + 1); while (m--) { int x, y; cin >> x >> y; row[x] = min(row[x], y); col[y] = min(col[y], x); } ll ans = 0; for (int i = 1; i <= w; i++) { if (i < row[1]) { ans += (col[i] - 1); min_row[col[i]].push_back(i); } else min_row[1].push_back(i); } // cout << ans << '\n'; for (int i = 1; i < col[1]; i++) { for (int idx : min_row[i]) turn_on(1, 1, w, idx); if (row[i] == 1) continue; ll cnt = query(1, 1, w, 1, row[i] - 1); ans += cnt; // cout << i << " " << cnt << " " << row[i] << '\n'; } cout << ans << '\n'; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define int ll typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pii> vpii; typedef vector<pll> vpll; #define F0R(i, a, b) for (int i=a; i<(b); i++) #define F0Rd(i,a,b) for (int i = (b)-1; i >= a; i--) #define ALL(s) (s).begin(),(s).end() #define ALLn(s,n) s,s+n #define F first #define S second #define pb push_back #define tc(t) int t; cin >> t; while(t--) #define _ ios_base::sync_with_stdio(false); cin.tie(NULL); #define D1(x) { cerr << " [" << #x << ": " << x << "]\n"; } #define D2(x) { cerr << " [" << #x << ": "; for(auto it:x) cerr << it << " "; cerr << "]\n"; } const ll M = 1e9 + 7; const ll MM = 998244353; const ll INF = 1e18; void solve() { int N, K; cin >> N >> K; int cur = 0, yen = K; vector<pii> V(N); for(int i = 0; i < N; ++i) { cin >> V[i].F >> V[i].S; } sort(ALL(V)); for(int i = 0; i < N; i++) { // D1(K); // D1(V[i].F); if(K >= V[i].F) K += V[i].S; } cout << K << '\n'; } int32_t main() { _ // tc(t) solve(); // cerr << "[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl; }
#include <bits/stdc++.h> #define N (int) 3005 #define MOD 998244353 using namespace std; int n, k; int dp[N][N]; int main () { cin >> n >> k; dp[0][0] = 1; for (int i = 1; i <= n; i ++) { for (int j = i; j >= 1; j --) { dp[i][j] = (dp[i-1][j-1] + ((j<<1) <= i ? dp[i][j<<1] : 0)) % MOD; } } cout << dp[n][k] << endl; return 0; }
#include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <queue> #include <string> #include <map> #include <set> #include <stack> #include <tuple> #include <deque> #include <array> #include <numeric> #include <bitset> #include <iomanip> #include <cassert> #include <chrono> #include <random> #include <limits> #include <iterator> #include <functional> #include <sstream> #include <fstream> #include <complex> #include <cstring> #include <unordered_map> using namespace std; using ll = long long; using P = pair<int, int>; constexpr int INF = 1001001001; constexpr int mod = 1000000007; // constexpr int mod = 998244353; template<class T> inline bool chmax(T& x, T y){ if(x < y){ x = y; return true; } return false; } template<class T> inline bool chmin(T& x, T y){ if(x > y){ x = y; return true; } return false; } struct mint { int x; mint() : x(0) {} mint(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} mint& operator+=(const mint& p){ if((x += p.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint& p){ if((x -= p.x) < 0) x += mod; return *this; } mint& operator*=(const mint& p){ x = (int)(1LL * x * p.x % mod); return *this; } mint& operator/=(const mint& p){ *this *= p.inverse(); return *this; } mint operator-() const { return mint(-x); } mint operator+(const mint& p) const { return mint(*this) += p; } mint operator-(const mint& p) const { return mint(*this) -= p; } mint operator*(const mint& p) const { return mint(*this) *= p; } mint operator/(const mint& p) const { return mint(*this) /= p; } bool operator==(const mint& p) const { return x == p.x; } bool operator!=(const mint& p) const { return x != p.x; } mint pow(int64_t n) const { mint res = 1, mul = x; while(n > 0){ if(n & 1) res *= mul; mul *= mul; n >>= 1; } return res; } mint inverse() const { return pow(mod - 2); } friend ostream& operator<<(ostream& os, const mint& p){ return os << p.x; } friend istream& operator>>(istream& is, mint& p){ int64_t val; is >> val; p = mint(val); return is; } }; template<typename T> struct Combination{ int sz; vector<T> fact_; vector<T> ifact_; vector<T> inv_; Combination(int n = 1e+7) : sz(n) { fact_.resize(sz + 1); ifact_.resize(sz + 1); inv_.resize(sz + 1); fact_[0] = ifact_[sz] = inv_[0] = 1; for(int i = 1; i <= sz; ++i) fact_[i] = fact_[i - 1] * i; ifact_[sz] /= fact_[sz]; for(int i = sz; i > 0; --i) ifact_[i - 1] = ifact_[i] * i; for(int i = 1; i <= sz; ++i) inv_[i] = ifact_[i] * fact_[i - 1]; } inline T fact(int k) const { if(k < 0 || k > sz) return 0; return fact_[k]; } inline T ifact(int k) const { if(k < 0 || k > sz) return 0; return ifact_[k]; } inline T inv(int k) const { if(k < 0 || k > sz) return 0; return inv_[k]; } T get_permutation(int n, int k){ if(n < 0 || k < 0 || n < k) return 0; return fact(n) * ifact(n - k); } T get_combination(int n, int k){ if(n < 0 || k < 0 || n < k) return 0; return fact(n) * ifact(k) * ifact(n - k); } }; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N, M, A; cin >> N >> M; ll S = 0; for(int i = 0; i < N; ++i){ cin >> A; S += A; } if(M < S){ cout << 0 << endl; return 0; } Combination<mint> C; mint ans = 1; M += N; for(int i = 1; i <= S + N; ++i) ans *= mint(M - i + 1) * C.inv(i); cout << ans << endl; }
#include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; using ll = long long; #define INF 1e9+7 #define rep(i,n) for(ll i=0;i<n;i++) #define repl(i,l,r) for(ll i=(l);i<(r);i++) #define per(i,n) for(int i=(n)-1;i>=0;i--) #define perl(i,r,l) for(int i=(r)-1;i>=(l);i--) #define pb push_back #define ins insert #define se second #define fi first #define all(x) x.begin(),x.end() using vi=vector<int>; using vl=vector<ll>; using vvi= vector<vector<int>>; using vvl= vector<vector<ll>>; using pii= pair<int,int>; using pll= pair<ll,ll>; const ll mod = INF; const int dxn[9]={-1,0,1,-1,0,1,-1,0,1}; const int dyn[9]={-1,-1,-1,0,0,0,1,1,1}; const int dxf[4]={0,1,0,-1}; const int dyf[4]={-1,0,1,0}; const int maxn = 1000; int main(){ int n,m; ll a[maxn+1],b[maxn+1]; ll dp[maxn+1][maxn+1]={0}; cin >> n>>m; rep(i,n)cin >> a[i+1]; rep(i,m)cin >> b[i+1]; rep(i,m+1)dp[0][i]=i; rep(i,n+1)dp[i][0]=i; repl(i,1,n+1){ repl(j,1,m+1){ int p=1; if(a[i]==b[j])p=0; dp[i][j]=min(min(dp[i-1][j]+1,dp[i][j-1]+1),dp[i-1][j-1]+p); } } cout << dp[n][m]<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; // #define int long long #define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i) #define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i) #define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--) #define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--) #define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i) #define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i) #define irreps(i, m, n) for (long long i = ((long long)(n)-1); i > (long long)(m); ++i) #define SORT(v, n) sort(v, v + n); #define REVERSE(v, n) reverse(v, v+n); #define vsort(v) sort(v.begin(), v.end()); #define all(v) v.begin(), v.end() #define mp(n, m) make_pair(n, m); #define cinline(n) getline(cin,n); #define replace_all(s, b, a) replace(s.begin(),s.end(), b, a); #define PI (acos(-1)) #define FILL(v, n, x) fill(v, v + n, x); #define sz(x) (long long)(x.size()) using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; using pii = pair<int, int>; using pll = pair<ll, ll>; using vs = vector<string>; using vpll = vector<pair<ll, ll>>; using vtp = vector<tuple<ll,ll,ll>>; using vb = vector<bool>; using ld = long double; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template<class t> using vc=vector<t>; template<class t> using vvc=vc<vc<t>>; const ll INF = 1e9+10; const ll MOD = 1e9+7; const ll LINF = 1e18; signed main() { cin.tie( 0 ); ios::sync_with_stdio( false ); int x,y; cin>>x>>y; if(abs(x-y)<3) cout<<"Yes"<<endl; else cout<<"No"<<endl; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef double db; typedef pair <int,int> Pii; #define reg register #define mp make_pair #define pb push_back #define Mod1(x) ((x>=P)&&(x-=P)) #define Mod2(x) ((x<0)&&(x+=P)) #define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;++i) #define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;--i) template <class T> inline void cmin(T &a,T b){ ((a>b)&&(a=b)); } template <class T> inline void cmax(T &a,T b){ ((a<b)&&(a=b)); } char IO; template <class T=int> T rd(){ T s=0; int f=0; while(!isdigit(IO=getchar())) f|=IO=='-'; do s=(s<<1)+(s<<3)+(IO^'0'); while(isdigit(IO=getchar())); return f?-s:s; } const int N=2e5+10,INF=1e9+10; int n; vector <int> G[N]; int F[N][20],D[N],E[N],L[N]; int ma=-1,id; void dfs(int u,int f) { if(D[u]>ma) ma=D[u],id=u; F[u][0]=f,E[u]=D[u]; rep(i,1,18) F[u][i]=F[F[u][i-1]][i-1]; for(int v:G[u]) if(v!=f) D[v]=D[u]+1,dfs(v,u),cmax(E[u],E[v]); L[u]=G[u][0]==f?(G[u].size()==1?0:G[u][1]):G[u][0]; sort(G[u].begin(),G[u].end(),[&](int x,int y){ return E[x]<E[y]; }); } int LCA(int x,int y){ if(D[x]<D[y]) swap(x,y); for(int del=D[x]-D[y],i=0;(1<<i)<=del;++i) if(del&(1<<i)) x=F[x][i]; if(x==y) return x; drep(i,18,0) if(F[x][i]!=F[y][i]) x=F[x][i],y=F[y][i]; return F[x][0]; } int Dis(int x,int y){ return D[x]+D[y]-2*D[LCA(x,y)]; } int lst; ll Ans=1e18,A[N],M,B[N]; void dfs2(int u,int f) { //cout<<u<<' '; if(!lst) A[lst=u]=1; else A[u]=A[lst]+Dis(lst,u),lst=u; M=A[u]; for(int v:G[u]) if(v!=f) dfs2(v,u); } void Work(int u){ lst=0; dfs(u,0),dfs2(u,0); if(M<Ans) { Ans=M; rep(i,1,n) B[i]=A[i]; } //puts(""); } int main(){ n=rd(); rep(i,2,n) { int u=rd(),v=rd(); G[u].pb(v),G[v].pb(u); } dfs(1,0),Work(id); int u=1; while(L[u]) u=L[u]; Work(u); while(L[u]) u=L[u]; Work(u); ll ans=0; rep(i,1,n) cmax(ans,B[i]); //printf("%lld\n",ans); rep(i,1,n) printf("%lld ",B[i]); }
#include<bits/stdc++.h> using namespace std; #define int long long #define ll long long const int nax = 2e5+5; vector<int> edges[nax]; vector<int> value , d , par; int cp = 1; void dfs(int u , int p = -1 , int _d = 0){ par[u] = p; d[u] = _d; for(auto x : edges[u]){ if(x != p){ dfs(x,u,_d+1); } } } void dfs1(int u , int p){ value[u] = cp++; for(auto x : edges[u]){ if(x != p){ dfs1(x,u); } } cp++; } void test(){ int n; cin >> n; for(int i = 0 ; i < n-1 ; i++){ int x, y; cin >> x >> y; x-- , y-- ; edges[x].push_back(y); edges[y].push_back(x); } value.resize(n); d.resize(n); par.resize(n); dfs(0); int st = max_element(d.begin(),d.end())-d.begin(); dfs(st); int en = max_element(d.begin(),d.end())-d.begin(); value[en] = cp++; while(par[en] != -1){ int p = par[en]; value[p] = cp++; for(auto x : edges[p]){ if(x != par[p] && x != en){ dfs1(x,p); } } en = p; } for(auto x : value) cout<<x<<" "; } int32_t main(){ ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL); int T = 1; // cin >> T; while(T--){ test(); } } // 0 0 3
#include <stdio.h> #include <stdlib.h> #include <iostream> #include <iomanip> #include <sstream> #include <fstream> #include <stdint.h> #include <string.h> #define _USE_MATH_DEFINES #include <math.h> #include <vector> #include <list> #include <set> #include <map> #include <unordered_map> #include <unordered_set> #include <queue> #include <stack> #include <deque> #include <string> #include <algorithm> #include <functional> #include <bitset> #include <functional> #include <chrono> #include <random> #define sqr(x) (x) * (x) typedef long long int i64; using namespace std; using namespace std::chrono; const i64 mod = 1'000'000'000ll + 7; //const i64 mod = 998'244'353ll; const i64 inf = 1'000'000'000'000'000'000ll / 1'000'000'000ll; const long double eps = 1e-8; i64 gcd(i64 a, i64 b) { while (b) { a %= b; swap(a, b); } return a; } int main(int argc, char* argv[]) { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed); cerr.precision(15); cerr.setf(ios::fixed); if (sizeof(i64) != sizeof(long long int)) { cerr << "i64 != long long int" << endl; } i64 R = 0; i64 n; string s; cin >> n >> s; i64 cnt = 0; stringstream ss; while (cnt < n) { ss << "110"; cnt += 3; } ss << "110"; string t = ss.str(); for (i64 l = 0; l < 3; l++) { if (t.substr(l, s.size()) != s) { continue; } const i64 m = 30'000'000'000ll - n - l; R += m / 3 + 1; } cout << R << endl; return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int n; string s; cin>>n>>s; bool ng=false; for(int i=0;i<n-1;i++){ if(i<n-2&&s[i]=='1'&&s[i+1]=='1'&&s[i+2]=='1')ng=true; if(i<n-2&&s[i]=='0'&&s[i+1]=='1'&&s[i+2]=='0')ng=true; if(i<n-1&&s[i]=='0'&&s[i+1]=='0')ng=true; } if(ng){ cout<<"0\n"; return 0; } if(s=="1"){ cout<<"20000000000\n"; return 0; }else if(s=="0"){ cout<<"10000000000\n"; return 0; } int64_t ans=1e10; for(int i=0;i<n-1;i++){ if(s[i]=='0'&&s[i+1]=='1')ans--; } cout<<ans<<'\n'; }
#include <bits/stdc++.h> using namespace std; template<class T, class U> T &ctmax(T &x, const U &y){ return x = max<T>(x, y); } template<class T, class U> T &ctmin(T &x, const U &y){ return x = min<T>(x, y); } constexpr pair<long long, long long> inv_gcd(long long a, long long b) { a = a % b; if(a < 0) a += b; if(a == 0) return {b, 0}; long long s = b, t = a; long long m0 = 0, m1 = 1; while(t){ long long u = s / t; s -= t * u; m0 -= m1 * u; auto tmp = s; s = t; t = tmp; tmp = m0; m0 = m1; m1 = tmp; } if(m0 < 0) m0 += b / s; return {s, m0}; } // (rem, mod) // Requires inv_gcd pair<long long, long long> chinese_remainder_theorem(const vector<long long> &r, const vector<long long> &m){ assert(r.size() == m.size()); int n = (int)r.size(); long long r0 = 0, m0 = 1; for(int i = 0; i < n; ++ i){ assert(1 <= m[i]); long long r1 = r[i] % m[i], m1 = m[i]; if(r1 < 0) r1 += m[i]; if(m0 < m1) swap(r0, r1), swap(m0, m1); if(m0 % m1 == 0){ if(r0 % m1 != r1) return {0, 0}; continue; } long long g, im; tie(g, im) = inv_gcd(m0, m1); long long u1 = (m1 / g); if ((r1 - r0) % g) return {0, 0}; long long x = (r1 - r0) / g % u1 * im % u1; r0 += x * m0, m0 *= u1; // -> lcm(m0, m1) if(r0 < 0) r0 += m0; } return {r0, m0}; } int main(){ cin.tie(0)->sync_with_stdio(0); cin.exceptions(ios::badbit | ios::failbit); auto __solve_tc = [&](int __tc_num){ long long x, y, p, q; cin >> x >> y >> p >> q; long long res = numeric_limits<long long>::max(); for(auto r0 = x; r0 < x + y; ++ r0){ for(auto r1 = p; r1 < p + q; ++ r1){ auto [t, lcm] = chinese_remainder_theorem({r0, r1}, {2 * x + 2 * y, p + q}); if(lcm){ ctmin(res, t); } } } if(res == numeric_limits<long long>::max()){ cout << "infinity\n"; } else{ cout << res << "\n"; } return 0; }; int __tc_cnt; cin >> __tc_cnt; for(auto __tc_num = 0; __tc_num < __tc_cnt; ++ __tc_num){ __solve_tc(__tc_num); } return 0; } /* */ //////////////////////////////////////////////////////////////////////////////////////// // // // Coded by Aeren // // // ////////////////////////////////////////////////////////////////////////////////////////
#include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> #include <functional> #include <vector> #include <map> #include <set> #include <deque> #include <string> #include <cassert> using namespace std; typedef long long llint; const int INF = 0x3f3f3f3f; const llint INFLL = 0x3f3f3f3f3f3f3f3fLL; void print() { cout << "\n"; } template <typename...T, typename X> void print(X&& x, T... args) { cout << x << " "; print(args...); } int input() { return 0; } template <typename...T, typename X> int input(X& x, T&... args) { if (!(cin >> x)) return 0; return input(args...) + 1; } llint exgcd(llint a, llint b, llint& x, llint& y) { if (b == 0) { x = 1; y = 0; return a; } llint r = exgcd(b, a%b, x, y); llint t = y; y = x - (a / b) * y; x = t; return r; } llint fast_mul(llint a, llint b, llint p){ llint res = 0; while (b) { if (b & 1) { res = (res + a) % p; } b >>= 1; a = (a + a) % p; } return (res % p + p) % p; } llint excrt(const vector<llint>& a, const vector<llint>& b) { const int n = a.size(); assert(a.size() == b.size()); llint a1 = a[0]; llint b1 = b[0]; for (int i = 1; i < n; i++) { llint a2 = a[i]; llint b2 = b[i]; llint k1,k2; llint d = exgcd(a1, a2, k1, k2); if ((b2 - b1) % d != 0) { return -1; } llint t = a2 / d; k1 = (k1 % t + t) % t; k1 = fast_mul((b2 - b1) / d, k1, t); b1 = k1 * a1 + b1; a1 = a1 / d * a2; } return b1; } llint solve(int x, int y, int p, int q) { llint res = INFLL; for (int yy = 0; yy < y; yy++) { for (int qq = 0; qq < q; qq++) { llint m1 = 2LL * x + 2LL * y; llint r1 = 1LL * x + yy; llint m2 = 1LL * p + q; llint r2 = 1LL * p + qq; llint cur = excrt({m1, m2}, {r1, r2}); if (cur == -1) { continue; } res = min(res, cur); } } if (res >= INFLL) { return -1; } return res; } int main() { int T; input(T); while (T--) { int x, y, p, q; input(x, y, p, q); llint res = solve(x, y, p, q); if (res == -1) { puts("infinity"); } else { printf("%lld\n", res); } } return 0; } /* ^^^TEST^^^ 3 5 2 7 6 1 1 3 1 999999999 1 1000000000 1 ----- 20 infinity 1000000000999999999 $$$TEST$$$ */
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; using pii = pair<int, int>; using pll = pair<ll, ll>; using vpi = vector<pii>; using vpl = vector<pll>; #define fi first #define se second #define pb push_back #define mkpr make_pair #define mktp make_tuple #define rep2(i, s, n) for (ll i = (s); i < (ll) (n); i++) #define rep(i, n) rep2(i, 0LL, n) #define repit(itr, t) for (auto itr = (t).begin(); itr != (t).end(); ++itr) #define all(c) begin(c), end(c) #define SUM(v) accumulate(all(v), 0LL) #define MIN(v) *min_element(all(v)) #define MAX(v) *max_element(all(v)) #define biti(bit, i) ( (bit >> i) & 1 ) #define _GLIBCXX_DEBUG template <class T> using pq = priority_queue<T>; template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>; const ll VLMAX = 200010; const ll MOD = 1000000007; const ll INF = LONG_MAX; int main() { ll N; cin >> N; vl v(N); cin >> v[0]; vl sm(N); vl sum(N); sum[0] = v[0]; sm[0] = max(v[0], 0LL); ll m = max(v[0], 0LL); rep (i, N - 1) { ll a; cin >> a; v[i + 1] = v[i] + a; m = max(m, v[i + 1]); sum[i + 1] = sum[i] + v[i + 1]; sm[i + 1] = sum[i] + m; } cout << MAX(sm) << endl; }
#include <iostream> #include <string> #include <algorithm> #include <set> #include <vector> #include <numeric> #include <map> #include <queue> #include <cmath> #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define FOR(i, k, n) for(int i = (k); i < (int)(n); i++) using namespace std; using ll = long long; int main() { cin.tie(0); ios_base::sync_with_stdio(0); ll n, k; cin >> n >> k; rep(i, k) { if(n % 200 == 0) { n = n / 200; }else { n = n * 1000 + 200; } } cout << n << endl; return 0; }
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (ll i = 0; i < (ll)(n); (i)++) #define per(i, n) for (ll i = n - 1; i >= 0; (i)--) #define FOR(i, a, b) for (ll i = (a); i < (b); i++) #define ROF(i, a, b) for (ll i = (b) - 1; i >= (a); i--) #define ALL(x) std::begin(x), std::end(x) #define rALL(x) std::rbegin(x), std::rend(x) #define fi first #define se second typedef long long ll; inline ll cross(ll x1, ll y1, ll x2, ll y2) { return x1 * y2 - x2 * y1; } // (x1, y1)と(x2, y2)の外積, 1->2で反時計回りなら正 inline ll dot(ll x1, ll y1, ll x2, ll y2) { return x1 * x2 + y1 * y2; } // (x1, y1)と(x2, y2)の内積 inline ll norm2(ll x, ll y) { return x * x + y * y; } // ノルム二乗 inline ll cross(pair<ll, ll> a, pair<ll, ll> b) { return a.fi * b.se - a.se * b.fi; } inline ll dot(pair<ll, ll> a, pair<ll, ll> b) { return a.fi * b.fi + a.se * b.se; } inline ll norm2(pair<ll, ll> a) { return a.fi * a.fi + a.se * a.se; } int main(){ //input, initialize ll N; cin >> N; vector<ll> a(N), b(N), c(N), d(N); //solve if(N == 1){ cout << "Yes"; return 0; } rep(i, N) cin >> a[i] >> b[i]; rep(i, N) cin >> c[i] >> d[i]; rep(i, N) { a[i] *= N; b[i] *= N; c[i] *= N; d[i] *= N; } ll c1x, c1y, c2x, c2y; c1x = c1y = c2x = c2y = 0; rep(i, N) { c1x += a[i]; c1y += b[i]; c2x += c[i]; c2y += d[i]; } c1x /= N; c1y /= N; c2x /= N; c2y /= N; rep(i, N) { a[i] -= c1x; b[i] -= c1y; c[i] -= c2x; d[i] -= c2y; } if(a[0] == 0 && b[0] == 0){ swap(a[0], a[1]); swap(b[0], b[1]); } set<pair<ll, ll>> p1, p2; // 外積, 内積の順 rep(i, N){ p1.insert(make_pair(cross(a[0], b[0], a[i], b[i]), dot(a[0], b[0], a[i], b[i]))); } rep(i, N){ p2 = {}; if(c[i] == 0 && d[i] == 0) continue; rep(j, N){ p2.insert(make_pair(cross(c[i], d[i], c[j], d[j]), dot(c[i], d[i], c[j], d[j]))); } if(p1 == p2) {cout << "Yes" << '\n'; return 0;} } //output cout << "No\n"; //debug }
#include "bits/stdc++.h" #pragma GCC optimize "trapv" #define int long long int #define For(i,a,b) for(int i=a;i<b;i++) #define pb push_back #define endl "\n" #define drink_boost ios_base::sync_with_stdio(false);cin.tie(NULL) #define all(v) v.begin(),v.end() #define TEST_CASE int t;cin>>t;while(t--) #define debug(...) cout<<#__VA_ARGS__<<" = "; print(__VA_ARGS__); using namespace std; const int MOD = 1e9 + 7; void print() { cout<<endl; } void printArray() { return; } void read() { return; } template<typename T , typename... Args> void print(T a , Args... arg) { cout << a << " " ; print(arg...); } template<typename T , typename... Args> void read(T &a , Args&... arg) { cin >> a; read(arg...); } template<typename T,typename... Args> void read(vector<T>&v , Args&... arg) { for(auto &i : v) cin>>i; read(arg...); } template<typename T,typename... Args> void printArray(vector<T>&v, Args&... arg) { for(auto i : v) cout<<i<<" "; cout<<endl; printArray(arg...); } int power(int a,int b) { int res=1; while(b) { if(b&1LL) res=res*a; b>>=1LL; a=a*a; } return res; } int modPower(int a,int b) { int res=1; while(b) { if(b&1L) res=(res%MOD*a%MOD)%MOD; b>>=1; a=(a%MOD*a%MOD)%MOD; } return res; } int gcdExtended(int a,int b,int *x,int *y){ if(a==0) { *x=0,*y=1; return b; } int x1,y1; int gcd=gcdExtended(b%a,a,&x1,&y1); *x=y1-(b/a)*x1; *y = x1; return gcd; } int modInverse(int b,int m) {int x,y; int g=gcdExtended(b,m,&x,&y); if (g != 1) return -1; return (x%m + m) % m; } int modDivide(int a,int b,int m=MOD) { a=a%m; int inv=modInverse(b,m); if(inv==-1) return -1; else return (inv*a)%m; } void runCase_() { int n; read(n); int x,y,ans = 0; while(n--) { read(x,y); int s = (y*(y+1))/2 - (x * (x - 1))/2; ans += s; } print(ans); } signed main() { drink_boost; // TEST_CASE runCase_(); return 0; } /** TEST CASES HERE **/ /* */
#include<iostream> #include<iomanip> using namespace std; int sx,sy,gx,gy; int main() { cin >> sx >> sy >> gx >> gy; double d = (gx-sx)/(double)(-gy-sy); cout << fixed << setprecision(10) << - d * sy + sx << endl; return 0; }
#include <bits/stdc++.h> using std::cin; using std::cout; using std::min; int f[102][2]; int main() { int a, b, x, y; cin >> a >> b >> x >> y; f[a][1] = x; for (int i = a + 1; i <= 100; ++i) { f[i][0] = min(f[i - 1][0] + y, f[i-1][1] + x); f[i][1] = min(f[i - 1][1] + y, f[i][0] + x); } for (int i = a - 1; i >= 1; --i) { f[i][1] = min(f[i + 1][1] + y, f[i + 1][0] + x); f[i][0] = min(f[i + 1][0] + y, f[i][1] + x); } cout << f[b][1] << '\n'; return 0; }
#include <bits/stdc++.h> int mod = 998244353; long long modinv(long long dividend, long long divisor, long long modnum){ long long b = mod, u = 1, v = 0; while (b) { long long t = divisor / b; divisor -= t * b; std::swap(divisor, b); u -= t * v; std::swap(u, v); } u %= mod; if (u < 0) u += mod; long long ans = dividend * u % mod; return ans; } int main(){ int N, K; std::cin >> N >> K; std::vector< long long > A(N); for(int i=0; i<N; i++){ std::cin >> A[i]; } std::vector< long long > calc_sigma_u(K+1, 0); std::vector< long long > calc_sigma_l(K+1); for(int i=0; i<N; i++){ long long tmp = 1; for(int j=0; j<=K; j++){ calc_sigma_u[j] = (calc_sigma_u[j] + tmp) % mod; tmp = (tmp * A[i]) % mod; } } long long tmpa = 1; calc_sigma_l[0] = 1; for(int i=1; i<=K; i++){ tmpa = (tmpa * i) % mod; calc_sigma_l[i] = tmpa; } long long Factorial = 1; long long two = 1; for(int i=1; i<=K; i++){ Factorial = (Factorial * i) % mod; long long ans = 0; for(int j=0; j<=i; j++){ long long tmp = (Factorial * calc_sigma_u[j]) % mod; tmp = (tmp * calc_sigma_u[i-j]) % mod; tmp = modinv(tmp, calc_sigma_l[j], mod); tmp = modinv(tmp, calc_sigma_l[i-j], mod); //std::cout << i<< " " << j << " " <<tmp <<std::endl; ans = (ans + tmp) % mod; } two = (two * 2) % mod; long long Subtraction = (calc_sigma_u[i] * two) % mod; if(ans < Subtraction){ ans = ans + mod - Subtraction; }else{ ans = ans - Subtraction; } std::cout << modinv(ans, 2, mod) << std::endl; } return 0; }
#include<iostream> #include<vector> using i64 = int64_t; template<i64 MOD> struct modint{ i64 val; modint():val(0){} modint(i64 v):val(v<0?(-v)%MOD:v%MOD){} operator i64(){return val;} constexpr modint &operator += (modint other){this->val+=other.val;if(this->val>=MOD)this->val-=MOD;return *this;} constexpr modint &operator -= (modint other){this->val-=other.val;if(this->val<0)this->val+=MOD;return *this;} constexpr modint &operator *= (modint other){this->val*=other.val;if(this->val>=MOD)this->val%=MOD;return *this;} constexpr modint &operator /= (modint other){this->val*=other.inverse();if(this->val>=MOD)this->val%=MOD;return *this;} constexpr modint operator + (modint other)const{return modint(val)+=other;} constexpr modint operator - (modint other)const{return modint(val)-=other;} constexpr modint operator * (modint other)const{return modint(val)*=other;} constexpr modint operator / (modint other)const{return modint(val)/=other;} template<class T>modint operator + (T other)const{return modint(val)+=(modint)other;} template<class T>modint operator - (T other)const{return modint(val)-=(modint)other;} template<class T>modint operator * (T other)const{return modint(val)*=(modint)other;} template<class T>modint operator / (T other)const{return modint(val)/=(modint)other;} template<class T> modint mpow(T _n)const{ i64 n = _n; modint res(1); modint base(val); while(n){ if(n&1)res*=base; base *= base; n >>= 1; } return res; } template<class T,class U> static modint mpow(T t,U u){return modint(t).mpow(u);} modint inverse()const{return mpow(val,MOD-2);} friend std::ostream &operator << (std::ostream& os,modint mo){return os<<mo.val;} friend std::istream &operator >> (std::istream& is,modint& mo){return is>>mo.val;} }; constexpr int MOD = 998244353; using mint = modint<MOD>; mint operator""_m(unsigned long long x){return (mint)x;} #define rep(i,n) for(int i=0;i<(int)n;++i) constexpr int64_t COM_MAX = (int64_t)1e6; signed main(){ int n,k; std::cin>>n>>k; std::vector<mint> a(n); for(auto& ai:a)std::cin>>ai; std::vector<mint> fac(k+1),inv(k+1),finv(k+1); fac[1]=inv[1]=finv[0]=finv[1]=1; for(int i=2;i<=k;++i){ fac[i]=fac[i-1]*i; inv[i]=MOD-inv[MOD%i]*(MOD/i); finv[i]=finv[i-1]*inv[i]; } std::vector<mint> ushi(k+1); rep(j,k+1)rep(i,n)ushi[j]+=(a[i]*2_m).mpow(j); std::vector<mint> tapu(k+1); rep(j,k+1)rep(i,n)tapu[j]+=a[i].mpow(j)*finv[j]; auto solve = [&](i64 x){ mint ans = 0; for(int k=0;k<=x;++k){ ans += tapu[k]*tapu[x-k]; } ans *= fac[x]; ans -= ushi[x]; ans /= 2; return ans; }; for(int x=1;x<=k;++x) std::cout<<solve(x)<<'\n'; }
#include<bits/stdc++.h> #define int long long #define rep(i,a,b) for(register int i=(a);i<=(b);i++) #define per(i,a,b) for(register int i=(a);i>=(b);i--) using namespace std; const double eps=1e-14; inline int read() { register int x=0, f=1; register char c=getchar(); while(c<'0'||c>'9') {if(c=='-') f=-1; c=getchar();} while(c>='0'&&c<='9') {x=(x<<3)+(x<<1)+c-48,c=getchar();} return x*f; } long double x,y,r; int ans; signed main() { cin>>x>>y>>r; r+=eps; rep(i,ceil(y-r),floor(y+r)) { long double dc=i-y; if(r*r-dc*dc<0) continue; long double dl=sqrt(r*r-dc*dc); long double l=x-dl, r=x+dl; int il=ceil(l-eps), ir=floor(r+eps); ans=ans+ir-il+1; //cout<<i<<" "<<l<<" "<<r<<" "<<il<<" "<<ir<<endl; } printf("%lld\n",ans); return 0; }
//#include "bits/stdc++.h" #define _USE_MATH_DEFINES #include<cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <deque> #include <algorithm> #include <functional> #include <iostream> #include <list> #include <map> #include <array> #include <unordered_map> #include<unordered_set> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> #include <iterator> #include<iomanip> #include<complex> #include<fstream> #include<assert.h> #include<stdio.h> using namespace std; #define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++) #define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--) #define all(c) begin(c),end(c) #define int ll #define SZ(x) ((int)(x).size()) #define pb push_back #define mp make_pair //typedef unsigned long long ull; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ll, int> pli; typedef pair<int, double> pid; typedef pair<double, int> pdi; typedef pair<double, double> pdd; typedef vector< vector<int> > mat; template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f; const int MOD = (int)1e9 + 7; const double EPS = 1e-9; int dec() { string S; cin >> S; string res; int si = 0; while (si < SZ(S) && S[si] != '.')res += S[si++]; if (si < SZ(S) && S[si] == '.')si++; rep(i, 0, 4) { if (si < SZ(S))res += S[si]; else res += '0'; si++; } return stoi(res); } signed main() { cin.tie(0); ios::sync_with_stdio(false); int X, Y, R; X = dec(); Y = dec(); R = dec(); int lx = X - R, rx = X + R; while (lx % 10000 != 0)lx++; while (rx % 10000 != 0)rx--; int ans = 0; for (int x = lx; x <= rx; x += 10000) { int dx = abs(x - X); int l = Y, r = Y + R + 1; while (r - l > 1) { int mid = (l + r) / 2; int dy = abs(mid - Y); if (dx*dx + dy * dy <= R * R) { l = mid; } else { r = mid; } } l -= Y; int dy = Y - l; int uy = Y + l; if (uy > 0)uy /= 10000; else { uy = (uy - 9999) / 10000; } if (dy > 0)dy = (dy + 9999) / 10000; else dy /= 10000; ans += uy - dy + 1; } cout << ans << endl; return 0; }
/* Saturday 13 March 2021 05:35:07 PM IST @uthor::astrainL3gi0N */ #include<bits/stdc++.h> using namespace std; typedef long long int ll; typedef std::vector<int> vi; typedef std::vector<ll> vll; typedef std::pair<int,int> ii; #define debg(x) std::cerr<<(#x)<<" => "<<x<<'\n'; #define debgg(x,y) std::cerr<<(#x)<<" => "<<x<<'\t'<<(#y)<<' '<<y<<'\n'; #define len(a) (int)(a).size() #define all(x) x.begin(),x.end() const int mod = 1'0000'0000'7; //const int mod = 998244353; //cout.unsetf(ios::floatfield);cout.precision(10);cout.setf(ios::fixed,ios::floatfield); bool comp (int x, int y) { return x > y; } void printarr (int arr[], int n) { for(int i = 0; i < n; ++i) std::cerr<<arr[i]<<(i<n-1?' ':'\n'); } template < typename T> void printv (T &a) { for (auto it = a.begin(); it != a.end(); ++it) std::cerr<<*it<<' '; std::cerr<<'\n'; } const int maxn = 200009; //int t[510][510]; ll ans; int arr[maxn]; void solve () { bool ok = false; int n,m,k,q; std::cin>>m>>k; ans = 0; std::cout<<(k%m == 0?"Yes":"No"); std::cout<<'\n'; } void sol () { //test } int main () { std::ios_base::sync_with_stdio(false); std::cin.tie(0); int testcases = 1; solve(); return 0; }
#include <iostream> using namespace std; int main() { int m; while(cin>>m){ int h; cin>>h; if(h%m){ cout<<"No"<<endl; } else{ cout<<"Yes"<<endl; } } }
#include<bits/stdc++.h> #pragma GCC optimize("Ofast") //#pragma GCC target("avx2") #pragma GCC optimize("unroll-loops") using namespace std; //#include<boost/multiprecision/cpp_int.hpp> //#include<boost/multiprecision/cpp_dec_float.hpp> //namespace mp=boost::multiprecision; //#define mulint mp::cpp_int //#define mulfloat mp::cpp_dec_float_100 struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init; #define INF (1<<30) #define LINF (lint)(1LL<<56) #define endl "\n" #define rep(i,n) for(lint (i)=0;(i)<(n);(i)++) #define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--) #define flc(x) __builtin_popcountll(x) #define pint pair<int,int> #define pdouble pair<double,double> #define plint pair<lint,lint> #define fi first #define se second #define all(x) x.begin(),x.end() #define vec vector<lint> #define nep(x) next_permutation(all(x)) typedef long long lint; int dx[8]={1,1,0,-1,-1,-1,0,1}; int dy[8]={0,1,1,1,0,-1,-1,-1}; const int MAX_N=3e5+5; 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;} //vector<int> bucket[MAX_N/1000]; constexpr lint MOD=1000000007; //constexpr int MOD=998244353; /*#include<atcoder/all> using namespace atcoder; typedef __int128_t llint;*/ int main(void){ int N; cin >> N; lint A[N]; rep(i,N) cin >> A[i]; sort(A,A+N); lint sum[N+1]={}; rep(i,N) sum[i+1]=sum[i]+A[i]; double ans=LINF; rep(i,N){ double use=(double)A[i]/2; use*=N; double over=(sum[N]-sum[i+1]); over-=(N-1-i)*A[i]; ans=min(ans,use+over); } cout << ans/N << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; double a[n]; for(int i=0;i<n;i++){ cin >> a[i]; } sort(a,a+n); double x = a[n / 2] / 2; double exp=0; for(int i=0;i<n;i++){ exp += a[i] - min(a[i], 2*x); } exp /= n; exp += x; cout << fixed << setprecision(10) << exp << endl; return 0; }
#include <bits/stdc++.h> using namespace std; ////////////////////////////////////////////////////////////////////////////<editor-fold desc="macros"> //#define mod 9999991 long mod=9999991; #define endl "\n" #define long long long #define all(v) (v).begin(),(v).end() #define makeset(v) (v).resize(unique((v).begin(),(v).end())-(v).begin()) #define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); #define filein freopen("input.txt", "r", stdin); #define fileout freopen("output.txt", "w", stdout); #define getline(x) getline(cin,x) #define makelower(s) transform(s.begin(),s.end(),s.begin(),::tolower) bool sortby(pair<int,int> a,pair<int,int> b){ double x=(double )a.first/a.second; double y=(double )b.first/b.second; return x<y;} long Pow(long x, long y) { if(y == 0)return 1; long res=Pow(x,y/2)%mod; res=(res*res)%mod; if(y&1)res=(res*x)%mod; return res; } #define printcase(x) cout<<"Case "<<in++<<": "<<x<<endl #define memset(a,b) memset(a,b,sizeof(a)) #define print1d(ary) cout<<"[";for(auto x:(ary)){cout<<x<<",";}cout<<"]"<<endl; #define print2d(x) for(int m = 0; m <sizeof(x)/sizeof(x[0]) ; ++m){for(int l = 0; l <sizeof(x[0])/sizeof(x[0][0]) ; ++l){cout<<x[m][l]<<" ";}cout<<endl;} #define pi acos(-1) #define esp 1e-9 ////////////////////////////////////////////////////////////////////////////</editor-fold> long t,n,m,f=0,ans,a,b,q; long tmp; struct point{ double x,y; point(){x=y=0.0;} point(double _x,double _y):x(_x),y(_y){} bool operator==(point other) const { return (fabs(x-other.x)<esp && fabs(y-other.y)<esp); } bool operator<(point other) const { if(fabs(x-other.x)>esp){ return x<other.x; } return y<other.y; } }; struct vec{ double x,y; vec(double _x, double _y) : x(_x), y(_y) {} }; struct line{ double a,b,c; line() {a=b=c=1.0;} line(double _a, double _b, double _c) : a(_a), b(_b), c(_c) {} }; double distOfPoint(point p1,point p2){ return hypot(p1.x-p2.x,p1.y-p2.y); } line pointToLine(point p1,point p2){ line l; if(fabs(p1.x-p2.x)<esp){ l.a=1.0;l.b=0.0;l.c=-p1.x; } else{ l.a=-((double)(p1.y-p2.y)/(p1.x-p2.x)); l.b=1.0; l.c=-(l.a*p1.x+p1.y); } return l; } vec toVec(point p1,point p2){ return {p2.x-p1.x,p2.y-p1.y}; } vec scale(vec v,double s){ return {v.x*s,v.y*s}; } point translate(point p,vec v){ return {p.x+v.x,p.y+v.y}; } double dot(vec v1,vec v2){ return v1.x*v2.x+v1.y*v2.y; } double norm_sq(vec v){ return v.x*v.x+v.y*v.y; } double distToLineSeg(point p1,point p2,point z,point &c){ vec p1p2=toVec(p1,p2),p1z=toVec(p1,z); double u=dot(p1p2,p1z)/norm_sq(p1p2); if(u<0){ c=p1; return distOfPoint(z,p1); } if(u>1){ c=p2; return distOfPoint(z,p2); } c=translate(p1,scale(p1p2,u)); return distOfPoint(z,c); } int main() { ///<editor-fold desc="ios"> IOS #ifdef _AD_ filein //fileout #endif ///</editor-fold> int in=1,o; long c,d,count=0; string s; cin>>n; for(int i = 1; ; ++i){ s=to_string(i)+to_string(i); m=stoll(s); if(m<=n){ count++; //cout<<m<<endl; } else{ break; } } cout<<count<<endl; }
#include <bits/stdc++.h> #define repd(i, a, b) for (ll i = (a); i < (b); i++) #define repb(i, n) for (ll i = (n)-1; i >= 0; i--) #define rep(i, n) repd(i, 0, n) using namespace std; using ll = long long; using ul = unsigned long long; using ld = long double; const ul mod = 1000000007; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n; cin >> n; ll loop = 1100000; ll ans = 0; repd(i, 1, loop) { string temp = to_string(i); temp += temp; ll num = stoll(temp); if (num <= n) { ans++; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define fr(i,n) for(int i = 0; i<n; i++) #define sz(v) (int)(v.size()) #define prin(a) cout << #a << " = " << a << endl #define prinv(v) cout << #v << " = "; for(auto it : v) cout << it << ", "; cout << endl #define all(v) (v).begin(),(v).end() typedef long long ll; #define rmin(a,b) a = min<ll>(a,b) #define rmax(a,b) a = max<ll>(a,b) #define fi first #define se second template <class T> T fp(T x, long long e) { T ans(1); for(; e > 0; e /= 2) { if(e & 1) ans = ans * x; x = x * x; } return ans; } const ll mod = round(1e9)+7; struct mb { mb(int v = 0) : val(v < 0 ? v + mod : v) {} mb(ll v){ val = (v%mod+mod)%mod; } int val; void operator += (mb o) { *this = *this + o; } void operator -= (mb o) { *this = *this - o; } void operator *= (mb o) { *this = *this * o; } mb operator * (mb o) { return (int)((long long) val * o.val % mod); } //mb operator / (mb o) { return *this * fp(o, mod - 2); } //bool operator == (mb o) { return val==o.val; } //usar soh para hashes mb operator + (mb o) { return val + o.val >= mod ? val + o.val - mod : val + o.val; } mb operator - (mb o) { return val - o.val < 0 ? val - o.val + mod : val - o.val; } }; int main(){ ios::sync_with_stdio(0); cin.tie(0); int n; set<int> st; cin >> n; fr(i,n){ int x; cin >> x; st.emplace(x); } st.emplace(0); vector<int> v(all(st)); mb ans = 1; fr(i,sz(v)-1){ ans*=v[i+1]+1-v[i]; } cout << ans.val << "\n"; }
#pragma GCC optimize("O3") #pragma GCC target("sse4") #include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; using namespace std; typedef long long ll; typedef long double ld; typedef unsigned int uint; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vi> vvi; typedef vector<vl> vvl; typedef pair<int, int> pi; typedef pair<ll, ll> pl; const int MXN = 2e5, IINF = 1e9 + 10, INF = 1e18 + IINF + 10, MOD = 1000000007; const ld PI = 4.0 * atanl(1.0), PREC = .000001; const char nl = '\n'; #define FOR(i, a, b) for (int i = a; i < (b); ++i) #define F0R(a) for (int i = 0; i < (a); ++i) #define FORd(i, a, b) for (int i = (b)-1; i >= a; --i) #define F0Rd(a) for (int i = (a)-1; ~i; --i) #define trav(a, x) for (auto& a : x) #define f first #define s second #define pb push_back #define mp make_pair #define all(x) x.begin(), x.end() #define rall(x) x.end(), x.begin() #define lb lower_bound #define ub upper_bound #define sz(x) (int)(x).size() #define ins insert int n, m, t, a[MXN]; void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); } ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); } int main() { fast(); cin >> n; F0R(n) cin >> a[i]; int ans = 0; int mx = 0; for (int i = 2; i <= 1000; ++i) { int curr = 0; for (int j = 0; j < n; ++j) { if (a[j] % i == 0) ++curr; } if (curr > mx) { mx = curr; ans = i; } } cout << ans; return 0; }
#include <bits/stdc++.h> //#include<boost/multiprecision/cpp_int.hpp> #define mod 1000000007 #define DEBUG(x) cout << '>' << #x << ':' << x << endl; #define REP(i, n) for (int i = 0; i < (n); i++) #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 T(a) ll a; cin >> a; #define TT(t) T(t); while (t--) #define pb push_back #define mp make_pair const int INF = 1 << 29; typedef long long ll; #define int long long inline int two(int n) { return 1 << n; } inline int test(int n, int b) { return (n >> b) & 1; } inline void set_bit(int &n, int b) { n |= two(b); } inline void unset_bit(int &n, int b) { n &= ~two(b); } inline int last_bit(int n) { return n & (-n); } inline int ones(int n) { int res = 0; while (n && ++res) n -= n & (-n); return res; } ll gcd(ll a, ll b) { if (a == 0 || b == 0) return 0; if (a == b) return a; if (a > b) return gcd(a - b, b); return gcd(a, b - a); } ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); } ll max(ll a, ll b) { if (a > b) return a; return b; } ll power(ll x, ll y) { ll res = 1; while (y > 0) { if (y & 1) res = res * x; y = y >> 1; x = x * x; } return res; } ll powermod(ll x, ll y) { ll res = 1; x = x % mod; while (y > 0) { if (y & 1) res = (res * x) % mod; y = y >> 1; x = (x * x) % mod; } return res; } ll mulmod(ll a, ll b) { ll res = 0; a %= mod; while (b) { if (b & 1) res = (res + a) % mod; a = (2 * a) % mod; b >>= 1; } return res; } bool isPrime(ll n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i += 6) { if ((n % i == 0) || (n % (i + 2) == 0)) return false; } return true; } long double dist(ll x1, ll y1, ll x2, ll y2) { return (long double)sqrt((long double)((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2))); } ll squaredist(ll x1, ll y1, ll x2, ll y2) { return ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); } ll nCr(ll n, ll r) { if (r == 0) return 1; return (n * nCr(n - 1, r - 1)) / r; } ll countDivisors(ll n) { ll cnt = 0; for (int i = 1; i <= sqrt(n); i++) { if (n % i == 0) { if (n / i == i) cnt++; else cnt = cnt + 2; } } return cnt; } ll modulo(ll a, ll b) { ll r = a % b; return r < 0 ? r + b : r; } void fs(int &number) { bool negative = false; register int c; number = 0; c = getchar(); if (c=='-') { negative = true; c = getchar(); } for (; (c>47 && c<58); c=getchar()) number = number *10 + c - 48; if (negative) number *= -1; } using namespace std; //using namespace boost::multiprecision; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin>>n; int ns = 0; for(int i = 1; i <= n; i++) { int m = i; bool flag = true; while(m) { flag = flag && (m%10 != 7); m/=10; } m = i; while(m) { flag = flag && (m%8 != 7); m/=8; } // ns += flag; if(flag) { ns++; } } cout<<ns; return 0; }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define ll long long #define int ll #define ld long double #define reps(i,s,n) for(int i=(s);i<(int)(n);i++) #define rep(i,n) reps(i,0,n) #define rreps(i,s,n) for(int i=(int)(s-1);i>=n;i--) #define rrep(i,n) rreps(i,n,0) #define all(v) (v).begin(),(v).end() #define mset(a,n) memset(a,n,sizeof(a)) #define eras(v,n) (v).erase(remove(all(v),n),(v).end()) #define uni(v) sort(all(v));(v).erase(unique(all(v)),(v).end()) #define bcnt(i) __builtin_popcount(i) #define fi first #define se second constexpr ll INF = 1e18; constexpr ll MOD = 1000000007; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } template<class T>T min(vector<T> &v) { return *min_element(v.begin(),v.end()); } template<class T>T max(vector<T> &v) { return *max_element(v.begin(),v.end()); } template<class T>T modpow(T a, T b, T m) { a %= m; T r = 1; while (b > 0) { if (b & 1) r = (r * a) % m; a = (a * a) % m; b >>= 1; } return r; } ll modinv(ll a,ll m=MOD) {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;} template<class T>string radixconv(T n, T k){ string s; while(n/k){ s=to_string(n%k)+s; n/=k; } s=to_string(n%k)+s; return s; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(11); cerr << fixed << setprecision(6); string s; cin >> s; int n=s.size(); string ans; if(n==1){ if(s[0]=='8')ans="Yes"; else ans="No"; }else if(n==2){ ans="No"; reps(i,10,100)if(i%8==0){ string a=to_string(i); vector<int> cnt(10,0); cnt[a[0]-'0']++; cnt[a[1]-'0']++; bool b=1; reps(j,0,10)if(count(all(s),(char)('0'+j))<cnt[j])b=0; if(b){ ans="Yes"; } } }else{ ans="No"; reps(i,100,1000)if(i%8==0){ string a=to_string(i); vector<int> cnt(10,0); cnt[a[0]-'0']++; cnt[a[1]-'0']++; cnt[a[2]-'0']++; bool b=1; reps(j,0,10)if(count(all(s),(char)('0'+j))<cnt[j])b=0; if(b){ ans="Yes"; } } } cout << ans << endl; return 0; }
//#pragma GCC optimize("Ofast") #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 << "[" << H << "]"; debug_out(T...); } #ifdef dddxxz #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif #define SZ(s) ((int)s.size()) clock_t startTime; double getCurrentTime() { return (double) (clock() - startTime) / CLOCKS_PER_SEC; } typedef long long ll; //mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); const double eps = 0.00001; const int MOD = 1e9 + 7; const int INF = 1000000101; const long long LLINF = 1223372000000000555; const int N = 1e6 + 4e4; const int M = 1234; const int LOG = 18; void solve(int TC) { int n; cin >> n; set<string> st; for (int i = 1; i <= n; i++){ string s; cin >> s; string t = s; if (*t.begin() == '!') t.erase(t.begin()); else t = "!" + t; if (st.count(t)){ cout << (*s.begin() != '!' ? s : t) << endl; return; } st.insert(s); } cout << "satisfiable"; } int main() { startTime = clock(); ios_base::sync_with_stdio(false); bool llololcal = false; #ifdef dddxxz freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); llololcal = true; #endif int TC = 1; //cin >> TC; for (int test = 1; test <= TC; test++) { debug(test); solve(test); } if (llololcal) cerr << endl << "Time: " << getCurrentTime() * 1000 << " ms" << endl; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int,int>; ll INF = 1e18; int main() { int n; cin >> n; vector<string> a; set<string> b; int count = 0; rep(i,n){ string s; cin >> s; if(s[0] == '!'){ b.insert(s); } else{ a.push_back(s); count++; } } rep(i,count){ if(b.count('!'+a[i])){ cout << a[i] << endl; return 0; } } cout << "satisfiable" << endl; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i=0; i<(n); ++i) #define sz(x) int(x.size()) #define show(x) {for(auto i:x){cout << i << " ";} cout << endl;} #define isin(x,l,r) ((l)<=(x) && (x)<(r)) using namespace std; using ll=long long; using pii=pair<int,int>; using pll=pair<ll,ll>; template<typename T>bool chmin(T&x,const T&y) {if(x>y){x=y;return true;} else return false;} template<typename T>bool chmax(T&x,const T&y) {if(x<y){x=y;return true;} else return false;} int main() { int N; cin >> N; vector<int> A(N); rep(i, N) cin >> A[i]; vector<int> B(N); rep(i, N) cin >> B[i]; if (inner_product(A.begin(), A.end(), B.begin(), 0)) puts("No"); else puts("Yes"); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main(){ long long N,ans; string yn; cin >> N; ans = 0; vector<int> A(N); vector<int> B(N); rep(i,N) cin >> A.at(i); rep(i,N) cin >> B.at(i); for(int j = 0; j < N; j++){ ans += A[j] * B[j]; } if(ans == 0) yn = "Yes"; else yn = "No"; cout << yn << endl; }
#include<bits/stdc++.h> using namespace std; #define N 2005 #define db double const db eps=1e-3,pi=3.14159265358979323846264337328451; int n,t,j,i,cnt,tot,a[N],b[N],ans,c[N],d[N]; db alp,ang,dis; struct dot{db x,y;}dt[N],R[N]; inline bool eq(db aa,db bb){ return aa<bb+eps&&bb<aa+eps; } inline bool cmp(dot aa,dot bb){ if(eq(aa.x,bb.x))return aa.y<bb.y; return aa.x<bb.x; } bool check(db alp){ int i; for(i=1;i<=n;++i){ dis=sqrt((a[i]*a[i]+b[i]*b[i])); ang=atan2(b[i],a[i])+alp; dt[i].x=cos(ang)*dis; dt[i].y=sin(ang)*dis; } sort(dt+1,dt+n+1,cmp); db x=dt[1].x-R[1].x,y=dt[1].y-R[1].y; for(i=2;i<=n;++i){ if(eq(dt[i].x-R[i].x,x)&&eq(dt[i].y-R[i].y,y))continue; else return 0; } return 1; } int main(){ cin>>n; for(i=1;i<=n;++i){ cin>>a[i]>>b[i]; } for(i=1;i<=n;++i){ cin>>c[i]>>d[i]; R[i].x=c[i];R[i].y=d[i]; } sort(R+1,R+n+1,cmp); for(i=-40;i<=40;++i){ for(j=-40;j<=40;++j){ if(check(atan2(j,i))){ return cout<<"Yes",0; } } } cout<<"No"; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, a, b) for (ll i = a; i < b; i++) #define rrep(i, a, b) for (ll i = b - 1; a <= i; i--) ll MOD = 1000000007; ll MOD2 = 998244353; ll N; vector<pair<ll, ll>> S, T; vector<vector<vector<ll>>> rotation; int main () { cin >> N; rep (i, 0, N) { ll x, y; cin >> x >> y; S.push_back(make_pair(x * N, y * N)); } rep (i, 0, N) { ll x, y; cin >> x >> y; T.push_back(make_pair(x * N, y * N)); } if (N == 1) { cout << "Yes"; return 0; } { ll x0, y0; x0 = y0 = 0; rep (i, 0, N) { x0 += S[i].first; y0 += S[i].second; } x0 /= N, y0 /= N; rep (i, 0, N) { S[i].first -= x0; S[i].second -= y0; } x0 = y0 = 0; rep (i, 0, N) { x0 += T[i].first; y0 += T[i].second; } x0 /= N, y0 /= N; rep (i, 0, N) { T[i].first -= x0; T[i].second -= y0; } } sort(T.begin(), T.end()); // cout << "S\n"; // rep (i, 0, N) cout << S[i].first << " " << S[i].second << endl; // cout << "\nT\n"; // rep (i, 0, N) cout << T[i].first << " " << T[i].second << endl; { ll k = -1, denom = 0; while (denom == 0) { k++; denom = T[k].first * T[k].first + T[k].second * T[k].second; } // cout << T[k].first << " " << T[k].second << " " << denom << endl; rep (i, 0, N) { ll denom2 = S[i].first * S[i].first + S[i].second * S[i].second; if (denom != denom2) continue; ll sin_nume, cos_nume; sin_nume = S[i].first * T[k].second - S[i].second * T[k].first; cos_nume = S[i].first * T[k].first + S[i].second * T[k].second; vector<vector<ll>> r = { {cos_nume, -sin_nume}, {sin_nume, cos_nume}, {denom} }; rotation.push_back(r); } } // for (auto r : rotation) { // cout << r[0][0] << " " << r[0][1] << " "<< r[1][0] << " "<< r[1][1] << " "<< r[2][0] << "\n"; // } for (const auto& r : rotation) { vector<pair<ll, ll>> U; bool flag = 0; rep (i, 0, N) { auto [x1, y1] = S[i]; ll x2 = x1 * r[0][0] + y1 * r[0][1]; ll y2 = x1 * r[1][0] + y1 * r[1][1]; if (x2 % r[2][0] != 0) flag = true; if (y2 % r[2][0] != 0) flag = true; if (flag) break; x2 /= r[2][0]; y2 /= r[2][0]; U.push_back(make_pair(x2, y2)); } if (flag) { // cout << "coor in not an integer\n"; continue; } sort(U.begin(), U.end()); // cout << "\nU\n"; // rep (i, 0, N) cout << U[i].first << " " << U[i].second << endl; rep (i, 0, N) { if (T[i] != U[i]) { flag = true; break; } } if (flag) { // cout << "coor dont match\n"; continue; } else { cout << "Yes"; return 0; } } cout << "No"; return 0; }
#include <bits/stdc++.h> #define REP(i, e) for(int (i) = 0; (i) < (e); ++(i)) #define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i)) #define ALL(c) (c).begin(), (c).end() #define PRINT(x) cout << (x) << "\n" using namespace std; using ll = long long; using pll = pair<ll, ll>; const long long MOD = 1000000007; long long gcd(long long a, long long b){ while (a != 0 && b != 0){ if (a >= b) a %= b; else b %= a; } return a + b; } long long lcm(long long a, long long b){ return (a / gcd(a, b)) * b; } signed main(){ ll N; cin >> N; ll L = 1; for(ll i = 2; i <= N; i++) L = lcm(L, i); PRINT(L + 1); return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define ls rt<<1 #define rs rt<<1|1 const int N=1e2+5; const int INF=0x3f3f3f3f; const int mod=1e4+7; const double eps=1e-9; const double pi=acos(-1); bool chk[N]; int cnt,p[N]; void prework(ll &ans){ chk[1]=1; for(int i=2;i<N;++i){ if(!chk[i]) p[cnt++]=i; for(int j=0;j<cnt&&i*p[j]<N;++j){ chk[i*p[j]]=1; if(i%p[j]==0) break; } } ans=1; for(int i=0;i<cnt;++i){ if(p[i]>30) break; ans*=p[i]; } ans=ans*9*8*5+1; } int main(){ ll ans; prework(ans); int n;scanf("%d",&n); printf("%lld\n",ans); return 0; }
#include <iostream> #include <cstring> using namespace std; int main (){ string s; cin >> s; char c = s.front(); s.erase(0,1); s.insert(s.end(), c); cout << s; return 0; }
#include<bits/stdc++.h> #define fox(i,a,b) for(int i=a;i<=b;++i) #define ll long long using namespace std; int _x, _f; char _c; inline int rd() { _x = 0, _f = 1, _c = getchar(); for (; !isdigit(_c); _c = getchar()) if (_c == '-') _f = 0; for (; isdigit(_c); _c = getchar()) _x = _x * 10 + _c - '0'; return _f ? _x : -_x; } char s[10]; signed main() { scanf("%s", s + 1); cout << s[2] << s[3] << s[1] << endl; return 0; }
#include<bits/stdc++.h> using namespace std; using P = pair<int64_t,int64_t>; const int MAX = (1<<19); int64_t dp[MAX]; int main(){ int N, M; cin >> N >> M; vector<vector<P>> vec(N,vector<P>(0)); for(int i=0; i<M; i++){ int X, Y, Z; cin >> X >> Y >> Z; X--; vec[X].push_back(P(Y,Z)); } dp[0] = 1; for(int i=0; i<(1<<N); i++){ int c = 0; vector<int> sum(N); for(int j=0; j<N; j++){ if(i & (1<<j)){ c++; sum[j]++; } if(j != 0){ sum[j] += sum[j-1]; } } //何を追加するか? for(int j=0; j<N; j++){ if(i & (1<<j)){ continue; } bool flag = true; for(int k=0; k<vec[c].size(); k++){ auto[y,z] = vec[c][k]; if(j < y){ z--; } if(sum[y-1] > z){ flag = false; break; } } if(flag){ dp[i|(1<<j)] += dp[i]; } } } cout << dp[(1<<N)-1] << endl; }
#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; #ifdef ENABLE_DEBUG #define dump(a) cerr<<#a<<"="<<(a)<<endl #define dumparr(a,n) cerr<<#a<<"["<<(n)<<"]="<<(a[n])<<endl #else #define dump(a) #define dumparr(a,n) #endif #define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++) #define For(i, a) FOR(i, 0, a) #define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--) #define Rev(i, a) REV(i, 0, a) #define REP(a) For(i, a) #define SIGN(a) (a==0?0:(a>0?1:-1)) typedef long long int ll; typedef unsigned long long ull; typedef unsigned int uint; typedef pair<ll, ll> pll; typedef pair<ll,pll> ppll; typedef vector<ll> vll; typedef long double ld; typedef pair<ld,ld> pdd; pll operator+(pll a,pll b){ return pll(a.first+b.first,a.second+b.second); } pll operator-(pll a,pll b){ return pll(a.first-b.first,a.second-b.second); } pll operator*(ll a,pll b){ return pll(b.first*a,b.second*a); } const ll INF=(1LL<<60); #if __cplusplus<201700L ll gcd(ll a, ll b) { a=abs(a); b=abs(b); if(a==0)return b; if(b==0)return a; if(a < b) return gcd(b, a); ll r; while ((r=a%b)) { a = b; b = r; } return b; } #endif template<class T> bool chmax(T& a,const T& b){ if(a<b){ a=b; return true; } return false; } template<class T> bool chmin(T& a,const T& b){ if(a>b){ a=b; return true; } return false; } template<class S,class T> std::ostream& operator<<(std::ostream& os,pair<S,T> a){ os << "(" << a.first << "," << a.second << ")"; return os; } template<class T> std::ostream& operator<<(std::ostream& os,vector<T> a){ os << "[ "; REP(a.size()){ os<< a[i] << " "; } os<< " ]"; return os; } int main(){ cout<<setprecision(1000); ll N,M; cin>>N>>M; vector<ll> dp(1LL<<N); vector<vector<pll>> cond(N); REP(M){ ll x,y,z; cin>>x>>y>>z; --x;--y; cond[x].push_back(pll(y,z)); } auto f=[](ll num,ll y,ll z){ ll mask=(1LL<<(y+1))-1; num&=mask; return __builtin_popcountll(num)<=z; }; dp[0]=1; For(j,(1LL<<N)){ ll n=__builtin_popcountll(j); if(n==N)continue; ll cur=1; REP(N){ if((cur&j)==0){ ll jj=(j|cur); ([&]() { FOR(cidx, n, N) { for (auto &&[y, z] : cond[cidx]) { if (!f(jj, y, z)) { return; } } } dp[jj]+=dp[j]; })(); } cur<<=1; } } dump(dp); cout<<dp[(1LL<<N)-1]<<endl; return 0; }
#include <bits/stdc++.h> #define ll long long #define map unordered_map #define set unordered_set #define l_l pair<ll, ll> #define P pair<ll, ll> #define vll vector<ll> #define mll map<ll, ll> #define mp make_pair #define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i) #define rev(i, n) for (int i = ((int)(n)-1); i >= 0; --i) #define revs(i, n) for (int i = ((int)(n)); i > 0; --i) // template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } // template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } using namespace std; const ll MOD = 1000000007LL; const ll INF = (1LL << 60LL); // template <class T> void plus_mod(T &a, const T &b) {a = (a + b) % MOD;} struct UnionFind { vector<ll> data; UnionFind(ll sz) { data.assign(sz, -1); } bool unite(ll x, ll 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); } ll find(ll k) { if (data[k] < 0) return (k); return (data[k] = find(data[k])); } ll size(ll k) { return (-data[find(k)]); } bool same(ll x, ll y) { int rx = find(x); int ry = find(y); return rx == ry; } // {1:[1,2,3], 4:[4,5]} map<ll, vll> groups() { map<ll, vll> m; rep(i, data.size()) { ll root = find(i); m[root].emplace_back(i); } return m; } map<ll, set<ll>> group_set() { map<ll, set<ll>> m; rep(i, data.size()) { ll root = find(i); m[root].insert(i); } return m; } }; mll *classes[200050]; void merge_map(mll *m1, mll *m2) { auto ite = (*m2).begin(); for (; ite != end(*m2); ite++) { ll key = (*ite).first; ll val = (*ite).second; // cout << key << ":" << val << endl; (*m1)[key] += (*m2)[key]; } } int main() { // std::cout << std::fixed << std::setprecision(10); ll N, Q; scanf("%lld %lld", &N, &Q); UnionFind uf(N); rep(s, N) { ll v; scanf("%lld", &v); v--; classes[s] = new mll(); (*classes[s])[v] = 1; } rep(i, Q) { ll type, a, b; scanf("%lld %lld %lld", &type, &a, &b); a--; b--; ll group_a = uf.find(a); if (type == 1) { if (uf.same(a, b)) continue; ll group_b = uf.find(b); uf.unite(a, b); mll *m1 = classes[group_a]; mll *m2 = classes[group_b]; mll *src; mll *dest; if (m1->size() > m2->size()) { dest = m1; src = m2; } else { dest = m2; src = m1; } merge_map(dest, src); classes[group_a] = dest; classes[group_b] = dest; } if (type == 2) { // cout << ((*classes[group_a])[b]) << endl; } } ll ans = 0; // cout << ans << endl; }
//Bismillahir Rahmanir Raheem #include<bits/stdc++.h> using namespace std; typedef pair<int,int>pii; #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; #define sf(x) scanf("%d",&x) #define sfl(x) scanf("%lld",&x) #define lli long long int #define ll64 int64_t #define pb push_back #define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define frr(i,a) for(int i=0;i<a;i++) #define frl(i,a) for(lli i=0;i<a;i++) #define fr1(i,a) for(int i=1;i<=a;i++) #define iter(x) x.begin(),x.end() #define Memset(a,x,n) for(int i=0;i<n;i++)a[i]=x; #define fi first #define si second //std::string s=std::bitset<M>(n).to_string(); //number to binary string //lower_bound returns an iterator pointing to the first element in the range [first,last) which has a value not less than ‘val’. //upper_bound returns an iterator pointing to the first element in the range [first,last) which has a value greater than ‘val’. //if mod is prime modInv(a,mod)==binExp(a,mod-2); typedef pair<lli,lli>pll; void solve() { } int main() { lli n,q; cin>>n>>q; vector<lli>a(n+1); a[0]=0; for(int i=1;i<=n;i++) { cin>>a[i]; } sort(a.begin(),a.end()); lli p=0; vector<lli>l,r,e; for(int i=0;i<=n;i++) { if(i!=n and a[i+1]!=a[i]+1) { l.pb(p+1); p+=(a[i+1]-a[i]-1); r.pb(p); e.pb(a[i]+1); } } l.pb(p+1); r.pb(1e18+10); e.pb(a[n]+1); lli s; // frr(i,l.size()) // { // cout<<l[i]<<" "<<r[i]<<" "<<e[i]<<endl; // } for(int i=0;i<q;i++) { cin>>s; lli x=lower_bound(l.begin(),l.end(),s)-l.begin(); lli y=lower_bound(r.begin(),r.end(),s)-r.begin(); if(x>y) { x--; } cout<<e[x]+(s-l[x])<<endl; } }
#include<bits/stdc++.h> #define int long long using namespace std; int n,m,obs_n; const int N=2e5+5; set<int>row[N],col[N]; int seg[4*N],a[N]; void update(int index,int data,int segindex,int l,int r) { if(l==r){ seg[segindex]=data; return ; } int mid=(l+r)/2; if(index<=mid){ update(index,data,2*segindex+1,l,mid); }else{ update(index,data,2*segindex+2,mid+1,r); } seg[segindex]=seg[2*segindex+1]+seg[2*segindex+2]; } int query(int index,int l,int r,int ql,int qr) { if(l>=ql && r<=qr) return seg[index]; if(l>qr || r<ql) return 0; int mid=(l+r)/2; int q1=query(2*index+1,l,mid,ql,qr); int q2=query(2*index+2,mid+1,r,ql,qr); return q1+q2; } void buildtree(int l,int r,int index) { if(l==r){ seg[index]=a[l]; return; } int mid=(l+r)/2; buildtree(l,mid,2*index+1); buildtree(mid+1,r,2*index+2); seg[index]=seg[2*index+1]+seg[2*index+2]; } //1- based void solve(){ cin>>n>>m>>obs_n; for(int i=0;i<obs_n;i++){ int u,v;cin>>u>>v; u--;v--; row[u].insert(v); col[v].insert(u); } int block_c=(row[0].empty()?m-1:(*row[0].begin()-1)); for(int i=0;i<=block_c;i++) a[i]=1; buildtree(0,m-1,0); int ans=block_c+1; int free_r=(col[0].empty()?n-1:(*col[0].begin()-1)); for(auto x:row[0]) update(x,0,0,0,m-1); // cout<<ans<<"\n"; for(int r=1;r<n;r++){ for(auto x:row[r]) update(x,0,0,0,m-1); if(r<=free_r){ int block_c=(row[r].empty()?m-1:(*row[r].begin()-1)); // cout<<r<<" "<<block_c<<"\n"; // cout<<query(0,0,m-1,block_c+1,m-1)<<"\n"; if(block_c+1>m-1) ans+=block_c+1; else ans+=block_c+1+query(0,0,m-1,block_c+1,m-1); }else{ ans+=query(0,0,m-1,0,m-1); } // cout<<ans<<"\n"; } cout<<ans<<"\n"; } main(){ ios_base::sync_with_stdio(false);cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif solve(); }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,n) for (long long i = 0; i < (n); ++i) #define DIV 1000000007 //10^9+7 #define INF LONG_MAX/3 #define bit(n) (1LL<<(n)) template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } int dx[4]={1,0,-1,0}; int dy[4]={0,1,0,-1}; struct segtree { vector<long long> data; long long n; segtree(long long nin){ n = pow( 2, ceil( log(nin) / log(2) ) ); long long size = 2 * n - 1; this->data.resize(size, 0); } //API for update val void update(long long idx, long long val){ update(idx, val, 0, 0, n); } long long update(long long idx, long long val, long long node_id, long long left, long long right){ //if query idx is within range return val if( !( left <= idx && idx < right ) ){ return data[node_id]; } if( left + 1 < right ) { //when node range is not 1, get update children val and update node data long long mid = (left + right) / 2 ; long long L = update(idx, val, 2 * node_id + 1, left, mid); long long R = update(idx, val, 2 * node_id + 2, mid, right); data[node_id] = L + R; } else { //when node range is 1, update node data data[node_id] = data[node_id] + val; } return data[node_id]; } //API for get value of [l, r) long long get(long long l, long long r){ return get(l, r, 0, 0, n); } /* *internaly used function *query_l: query left range *query_r: query right range *node_id: node id of *node_l: node left range *node_r: node right range */ long long get(long long query_l, long long query_r, long long node_id, long long node_l, long long node_r){ //query range is outside of node range: return INF if( query_r <= node_l || node_r <= query_l ){ return 0; } //query range is within node range: return node val if( query_l <= node_l && node_r <= query_r ){ return data[node_id]; } long long mid = (node_l + node_r) / 2; long long L = get(query_l, query_r, 2 * node_id + 1, node_l, mid); long long R = get(query_l, query_r, 2 * node_id + 2, mid, node_r); return L + R; } }; vector<ll> yvec[200005]; int main(){ ll H, W, M; cin >> H >> W >> M; vector<ll>X(M); vector<ll>Y(M); ll maxx = W; ll maxy = H; segtree ysg(H+5);; rep(i, M) cin >> Y[i] >> X[i]; rep(i, M) X[i]--; rep(i, M) Y[i]--; rep(i, M) { yvec[X[i]].push_back(Y[i]); if(Y[i] == 0) chmin(maxx, X[i]); if(X[i] == 0) chmin(maxy, Y[i]); } rep(i, W) sort(yvec[i].begin(), yvec[i].end()); set<ll> ngy; rep(i, maxy) ysg.update(i, 1); ll ans = 0; for(ll y = maxy; y < H; y++) ngy.insert(y); for(ll x = 0; x < W; x++) { ll miny = H; if(x >= maxx) miny = 0; for(ll y: yvec[x]) { chmin(miny, y); if(!ngy.count(y)) { ngy.insert(y); ysg.update(y, -1); } } //cout << "x = " << x << " uekara " << miny << " yokokara " << ysg.get(miny, H) << endl; //上からいけるやつ ans += miny; //上からいけなくて横からいけるやつ ans += ysg.get(miny, H); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define _GLIBCXX_DEBUG #define rep(i, n) for (ll i = 0; i < (n); ++i) #define rep1(i, c, n) for (ll i = c; i < (n); ++i) #define yn(ok, True, False) if (ok) { p(True) } else {p(False)}; //以下debug用 #define d(x) cout << #x << "; " << x << endl; #define p(x) cout << x << endl; #define f(x) for (long unsigned int i = 0; i < x.size(); i++) cout << #x << "[" << i << "]; " << x[i] << endl; bool ok = false; vector<int> datas; const int inf = 1001001001; const ll INF = 1LL << 60; //無限大 int main(){ ll n,k; cin >> n >> k; rep(i,k){ if (n%200 == 0){ n = n/200; }else{ n = (n*1000) + 200; } // d(n) } p(n) return 0; }
#include <iostream> int main() { long long int N; int K; std::cin >> N >> K; for (int i = 0; i < K; i++) { if (N % 200 == 0) { N /= 200; } else { N *= 1000; N += 200; } } std::cout << N << std::endl; }
#define _CRT_SECURE_NO_WARNINGS #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 18; int connect[N],f[1 << N]; int main() { int n,m;scanf("%d%d",&n,&m); for(int i = 0;i < n;++i) connect[i] |= (1 << i); for(int i = 0;i < m;++i) { int u,v;scanf("%d%d",&u,&v); --u;--v; connect[u] |= (1 << v); connect[v] |= (1 << u); } f[0] = 0; for(int i = 1;i < (1 << n);++i) { f[i] = 1e5+7; bool indp = 1; for(int j = 0;j < n;++j) if((i >> j & 1) && ((connect[j] & i) != i)) indp = 0; if(indp) f[i] = 1; for(int s = i;s;s = (s - 1) & i) f[i] = min(f[i],f[s] + f[i - s]); } printf("%d",f[(1 << n) - 1]); return 0; }
#include<iostream> #include<cstdio> #include<algorithm> #define re register #define ri register int #define For(i,a,b) for(ri i=a;i<=b;++i) #define iFor(i,a,b) for(ri i=a;i>=b;--i) #define File(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout); #define gtch() (_p1==_p2&&(_p2=(_p1=buf)+fread(buf,1,1<<22,stdin),_p1==_p2)?EOF:*_p1++) using namespace std; typedef long long ll; char buf[1<<22],*_p1=buf,*_p2=buf; inline ll fr(){ re ll r=0;re char c=gtch();ri b=0; while(!isdigit(c))b=(c=='-'),c=gtch(); while(isdigit(c))r=r*10+c-'0',c=gtch(); return b?-r:r; } inline int fc(){ re char c=gtch(); while(c==' '||c=='\n')c=gtch(); return c=='.'; } const ll MOD=1e9+7; const int MAXN=2005; const ll INF=9e17+5; int n,m; int ar[MAXN][MAXN]; int up[MAXN][MAXN],dn[MAXN][MAXN],lt[MAXN][MAXN],rt[MAXN][MAXN]; ll p2[MAXN*MAXN]; int tot; inline void input(){ n=fr(),m=fr(); For(i,1,n) For(j,1,m) ar[i][j]=fc(),tot+=ar[i][j]; p2[0]=1;For(i,1,n*m) p2[i]=p2[i-1]*2%MOD; For(i,1,n) For(j,1,m) if(ar[i][j-1]) lt[i][j]=lt[i][j-1]+1;else lt[i][j]=0; For(i,1,n) iFor(j,m,1) if(ar[i][j+1]) rt[i][j]=rt[i][j+1]+1;else rt[i][j]=0; For(i,1,n) For(j,1,m) if(ar[i-1][j]) up[i][j]=up[i-1][j]+1;else up[i][j]=0; iFor(i,n,1) For(j,1,m) if(ar[i+1][j]) dn[i][j]=dn[i+1][j]+1;else dn[i][j]=0; } signed main(){ // File("temp") input(); ll ans=0; For(i,1,n) For(j,1,m){ if(!ar[i][j]) continue; ll t=lt[i][j]+rt[i][j]+up[i][j]+dn[i][j]+1; ans+=(p2[t]-1)*p2[tot-t]%MOD; ans%=MOD; } cout<<ans; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int N; string S, T; int main() { ios_base::sync_with_stdio(0); cin >> N >> S >> T; ll ans = 0; int pneed = 0; int par = (S[0] - '0') ^ (T[0] - '0'); for (int i = 1; i < N; i++) { int ds = S[i] - '0', dt = T[i] - '0'; int nneed; if (S[i-1] == '0') nneed = pneed; else nneed = max (0, pneed - 1); while (nneed % 2 != par) nneed++; ans += nneed; pneed = nneed; par ^= (ds ^ dt); } if (par || pneed > (S[N-1] - '0')) cout << "-1\n"; else cout << ans << "\n"; }
#pragma GCC optimize(3, "Ofast", "inline") #include <bits/stdc++.h> #define start ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define ll long long #define int ll #define ls st<<1 #define rs st<<1|1 #define pii pair<int,int> #define rep(z, x, y) for(int z=x;z<=y;++z) #define repd(z, x, y) for(int z=x;z>=y;--z) #define com bool operator<(const node &b)const using namespace std; mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); const int maxn = (ll) 5e5 + 5; const int mod = 998244353; const int inf = 0x3f3f3f3f; int T = 1; char s[maxn], t[maxn]; void solve() { int n; queue<int> q; cin >> n >> (s + 1) >> (t + 1); rep(i, 1, n)if (s[i] == '1')q.push(i); int ans = 0; rep(i, 1, n) { if (s[i] != t[i]) { while (!q.empty() && q.front() <= i)q.pop(); if (q.empty()) { cout << -1; return; } s[q.front()] = '0'; ans += q.front() - i; q.pop(); } } cout << ans; } signed main() { start; while (T--) solve(); return 0; }
//#include <bits/stdc++.h> #include <iostream> #include <vector> #include <queue> #include <stack> #include <list> #include <string> #include <string.h> #include <assert.h> #include <math.h> #include <numeric> #include <cmath> #include <map> #include <unordered_map> #include <set> #include <unordered_set> #include <limits> #include <limits.h> #include <iomanip> #include <algorithm> using namespace std; #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " #define int long long #define ull unsigned long long #define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define pb push_back #define mkp make_pair #define fi first #define se second struct node { int left, right; }; void solve() { int N; cin >> N; vector<int> X(N), C(N); vector<struct node> pos(N+2), dp(N+2); for(int i = 0; i <= N+1; i++) { pos[i].left = INT_MAX; pos[i].right = INT_MIN; } unordered_set<int> st; for(int i = 0; i < N; i++) { cin >> X[i] >> C[i]; st.insert(C[i]); pos[C[i]].left = min(pos[C[i]].left, X[i]); pos[C[i]].right = max(pos[C[i]].right, X[i]); } st.insert(N+1); pos[N+1].left = pos[N+1].right = 0; pos[0].left = pos[0].right = 0; dp[0].left = dp[0].right = 0; for(int i = 1; i <= N+1; i++) { if(st.find(i) == st.end()) { pos[i].left = pos[i-1].left; pos[i].right = pos[i-1].right; dp[i].left = dp[i-1].left; dp[i].right = dp[i-1].right; continue; } dp[i].left = min(dp[i-1].left + abs(pos[i-1].left - pos[i].right) + abs(pos[i].right - pos[i].left), dp[i-1].right + abs(pos[i-1].right - pos[i].right) + abs(pos[i].right - pos[i].left)); dp[i].right = min(dp[i-1].left + abs(pos[i-1].left - pos[i].left) + abs(pos[i].right - pos[i].left), dp[i-1].right + abs(pos[i-1].right - pos[i].left) + abs(pos[i].right - pos[i].left)); //cout << imie(pos[i-1].left) imie(pos[i-1].right) << '\n'; //cout << imie(dp[i].left) imie(dp[i].right) << '\n'; } // cout << min(abs(pos[N].left) + dp[N].left, // abs(pos[N].right) + dp[N].right); cout << min(dp[N+1].left, dp[N+1].right); } int32_t main() { //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); IOS; int t = 1; //cin >> t; while(t--) { solve(); } return 0; }
#include <bits/stdc++.h> #define ll long long #define int ll #define count_one(a) __builtin_popcountll(a) #define is_power_of_2(a) (a) & (a - 1) == 0 #define exit return 0 const double eps = 1e-10; const double pi = acos(-1.0); #define endl "\n" #define flush() cout << flush #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); using namespace std; void dbg_out() { cout << endl; } template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); } #ifndef ONLINE_JUDGE #define dbg(...) \ cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__), cout << endl #else #define dbg(...) #endif ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// #define inf (int)2E5 + 1 int n; // 0 - left end // 1 - right end int dp[inf][2]; vector<int> loc[inf]; int32_t main() { IOS; cin >> n; int x, c; for (int i = 0; i < n; i++) { cin >> x >> c; loc[c].push_back(x); } for (int i = 1; i <= n; i++) { sort(loc[i].begin(), loc[i].end()); } int start; for (start = 1; start <= n; start++) { if (loc[start].size()) { break; } } int prev = start; int prevEnd = 0; int prevStart = 0; for (int i = start; i <= n; i++) { if (!loc[i].size()) { continue; } int currLen = loc[i].size(); int currStart = loc[i][0]; int currEnd = loc[i][currLen - 1]; // left end dp[i][0] = min( {dp[prev][1] + (abs(prevEnd - currEnd) + abs(currEnd - currStart)), dp[prev][0] + (abs(prevStart - currEnd) + abs(currEnd - currStart))}); // right end dp[i][1] = min({dp[prev][1] + (abs(prevEnd - currStart) + abs(currEnd - currStart)), dp[prev][0] + (abs(prevStart - currStart) + abs(currEnd - currStart))}); dbg(i); dbg(dp[i][0]); dbg(dp[i][1]); prev = i; prevEnd = loc[i][currLen - 1]; prevStart = loc[i][0]; } int prevLen = loc[prev].size(); int ans = min(dp[prev][0] + abs(prevStart), dp[prev][1] + abs(prevEnd)); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long double n; cin >> n; long double a, b, ansA = -1, ansB = -1; for (long double i = 1;; i++) { a = powl(3, i); if (a > n) break; for (long double j = 1;; j++) { b = powl(5, j); if (b > n) break; if (a + b == n) { ansA = i; ansB = j; break; } } } if (ansA == -1) { cout << -1 << endl; } else { cout << ansA << " " << ansB << endl; } }
#include <bits/stdc++.h> #include<random> using namespace std; typedef unsigned long long _ulong; typedef long long int lint; typedef pair<lint, lint> plint; typedef pair<double long, double long> pld; #define ALL(x) (x).begin(), (x).end() #define SZ(x) ((lint)(x).size()) #define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++) #define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--) #define REP(i, n) FOR(i,0,n) #define IREP(i, n) IFOR(i,0,n) #define endk '\n' 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 lint MOD = 1e9 + 7, INF = 1e18; lint dx[8] = { 0, -1, 1, 0, 1, -1, 1, -1 }, dy[8] = { 1, 0, 0, -1, -1, -1, 1, 1 }; typedef pair<long double, lint> Pa; typedef pair<lint, plint> tlint; struct edge { lint cost; lint u, v; }; lint N; int main() { cin >> N; lint cnt3 = 1; lint curr = 3; while (true) { lint _curr = 5; lint cnt5 = 1; while (true) { if (curr + _curr == N) { cout << cnt3 << " " << cnt5 << endk; return 0; } if (_curr > N/ 5) break; cnt5++; _curr *= 5; } if (curr > N / 3) break; cnt3++; curr *= 3; } cout << -1 << endk; }
#include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #include <climits> #include <cstring> #include <cassert> using namespace std; //using namespace atcoder; #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 FOR(i, a, n) for (int i=(a); i<(n); ++i) #define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i) #define SZ(x) ((int)(x).size()) #define ALL(x) (x).begin(),(x).end() #define DUMP(x) cerr<<#x<<" = "<<(x)<<endl #define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl; template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "["; REP(i, SZ(v)) { if (i) os << ", "; os << v[i]; } return os << "]"; } template<class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << "(" << p.first << " " << p.second << ")"; } template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } using ll = long long; using ull = unsigned long long; using ld = long double; using P = pair<int, int>; using vi = vector<int>; using vll = vector<ll>; using vvi = vector<vi>; using vvll = vector<vll>; const ll MOD = 1e9 + 7; const int INF = INT_MAX / 2; const ll LINF = LLONG_MAX / 2; const ld eps = 1e-9; ull rnd(void) { static ull y = 2463534242; y = y ^ (y << 13); y = y ^ (y >> 17); return y = y ^ (y << 5); } // edit ll LIM = 130; int rec(ll x, ll y) { if (x == 0 && y == 0) { return 0; } if (x == y) { return x + y; } if (x == 0) { return y; } if (y == 0) { return x; } if (x > y) { // return 1 + rec(x - y, y); if (x / y > LIM) return INF; return 1 + rec(x - y, y); } if (x < y) { if (y / x > LIM) return INF; return 1 + rec(x, y - x); } return INF; } void solver(ll x, ll y, vector<int> &O) { if (x == y) { if (x == 0) return; REP(i, x) { O.push_back(1); } REP(i, y) { O.push_back(2); } } if (x == 0) { REP(i, y) { O.push_back(2); } } if (y == 0) { REP(i, x) { O.push_back(1); } } if (x > y) { O.push_back(3); solver(x - y, y, O); } if (x < y) { O.push_back(4); solver(x, y - x, O); } } void solve() { // ll N = 100; // REP(i, N) { // cout << i << " " << rec(N, i) << endl; // } ll N; cin >> N; if (N == 1) { cout << 1 << endl; cout << 1 << endl; return; } ll y; while (true) { y = rnd() % (N - 1) + 1; ll val = rec(N, y); if (val <= LIM) { // cout << val << endl; break; } else { // cerr << y << " " << val << endl; } } vector<int> ans; solver(N, y, ans); assert(ans.size() <= LIM); reverse(ALL(ans)); cout << ans.size() << endl; for (auto e : ans) { cout << e << endl; } } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(10); // std::ifstream in("input.txt"); // std::cin.rdbuf(in.rdbuf()); solve(); return 0; }
//#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i=0; i<n; ++i) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() using ll = int64_t; using ull = uint64_t; using ld = long double; using P = pair<int, int>; using vs = vector<string>; using vi = vector<int>; using vvi = vector<vi>; template<class T> using PQ = priority_queue<T>; template<class T> using PQG = priority_queue<T, vector<T>, greater<T>>; const int INF = 0xccccccc; const ll LINF = 0xcccccccccccccccLL; template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);} template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);} template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;} template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;} #define N 90 ll fib[N]; //head int main() { ios::sync_with_stdio(false); cin.tie(0); fib[0] = 1; fib[1] = 1; for(int i = 2; i < N; i++) fib[i] = fib[i-1]+fib[i-2]; ll n; cin >> n; vi ans; int fi = 1; for(auto i = N-1; i > 0; i--) { if(fib[i] <= n) { fi = 0; ans.emplace_back(i&1?2:1); n -= fib[i++]; } else { if(fi) continue; ans.emplace_back(i&1?3:4); } } int k = ans.size(); cout << k << endl; rep(i, k) cout << ans[i] << '\n'; ll x = 0, y = 0; rep(i, k) { if(ans[i] == 1) x++; if(ans[i] == 2) y++; if(ans[i] == 3) x += y; if(ans[i] == 4) y += x; } //cerr << x << ' ' << y << endl; }
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<ctime> #include<vector> #include<queue> #include<algorithm> #include<string> #include<sstream> #include<cctype> #include<cmath> #include<iomanip> #include<map> #include<stack> #include<set> #include<functional> #define in(x) x=read() #define qr read() #define int ll #define mp make_pair using namespace std; typedef long long ll; typedef unsigned long long ull; namespace fastIO { #define BUF_SIZE 100000 bool IOerror=0; inline char nc() { static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE; if (p1==pend){ p1=buf; pend=buf+fread(buf,1,BUF_SIZE,stdin); if (pend==p1){IOerror=1;return -1;} } return *p1++; } inline bool blank(char ch){return ch==' '||ch=='\n'||ch=='\r'||ch=='\t';} inline ll read() { bool sign=0; char ch=nc();ll x=0; for (;blank(ch);ch=nc()); if (IOerror)return 0; if (ch=='-')sign=1,ch=nc(); for (;ch>='0'&&ch<='9';ch=nc())x=x*10+ch-'0'; if (sign)x=-x; return x; } #undef BUF_SIZE }; using namespace fastIO; #define mod 998244353 int fac[1000010],ifac[1000010]; int c(int x,int y){if(x<y)return 0;else return fac[x]*ifac[x-y]%mod*ifac[y]%mod;} int qpow(int n,int k) { int ans=1; while(k) { if(k&1)ans*=n,ans%=mod; n*=n,n%=mod; k>>=1; } return ans; } int n,m; int ff[5010][5010]; int f(int x,int cnt) { int ans=0; if(!x)return 1; if(x&1)return 0; if(!cnt)return 0; if(ff[x][cnt]!=-1)return ff[x][cnt]; for(int i=0;i<=min(x,n);i+=2) { ans+=c(n,i)*f((x-i)/2,cnt-1),ans%=mod; } // cout<<x<<','<<cnt<<":"<<ans<<'\n'; return ff[x][cnt]=ans; } signed main() { //freopen(".in","r",stdin); //freopen(".out","w",stdout); n=qr,m=qr; memset(ff,-1,sizeof(ff)); if(m&1)return cout<<0,0; fac[0]=1; for(int i=1;i<=n+m;i++)fac[i]=fac[i-1]*i%mod; ifac[n+m]=qpow(fac[n+m],mod-2); for(int i=n+m-1;i>=0;i--)ifac[i]=ifac[i+1]*(i+1)%mod; int cnt=0; for(int i=0;i<=30;i++) { if(m&(1<<i))cnt=i+1; } cout<<f(m,cnt); return 0; }
#include <iostream> #include <iomanip> #include <vector> #include <cmath> #include <algorithm> #include <deque> #include <set> #include <limits> #include <string> #include <map> #include <unordered_map> #include <unordered_set> #include <list> #include <numeric> #include <bitset> using namespace std; using ll = long long; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, a) for (int i = 0; i < (a); ++i) #define OUT_PREC(a, n) cout << fixed << setprecision(n) << a << endl // nが一定の時 class CombMod { private: ll n; const ll _MOD = 998244353; vector<ll> val; vector<ll> inv; public: CombMod(const ll &n0) { n = n0; val.resize(n + 1, 1); val[1] = n; inv.resize(n + 1, 1); // calculate in advance for (ll i = 2; i <= n; ++i) { inv[i] = _MOD - ((inv[_MOD % i] * (ll)(_MOD / i)) % _MOD); val[i] = (((val[i - 1] * (n + 1 - i)) % _MOD) * inv[i]) % _MOD; } } ll get(ll k) { // mCk if (k < 0) return 0; else return val[k]; } }; ll solve() { int n, m; cin >> n >> m; ll MOD = 998244353; CombMod cm(n); vector<ll> dp(m + 1, 0); dp[0] = 1; for (int j = 1; j <= (m / 2); ++j) { for (int k = 0; k <= min(j, n / 2); ++k) { dp[2 * j] = (dp[2 * j] + ((dp[j - k] * cm.get(2 * k)) % MOD)) % MOD; } } return dp[m]; } int main() { /* solve */ cout << solve() << endl; // cout << (solve() ? "Yes" : "No") << endl; system("pause"); }