code_file1
stringlengths
87
4k
code_file2
stringlengths
82
4k
#include <bits/stdc++.h> using namespace std; #define ll long long #define MOD 1000000007 #define FOR(i, a, b) for (ll i=a; i<(b); i++) #define FORD(i, a, b) for (int i=a-1; i>=(b); i--) void solve () { ll ans = 0; ll n; cin >> n; vector<ll> a(n); FOR(i, 0, n) cin >> a[i]; FOR(i, 0, n) { ll tmp; cin >> tmp; a[i] *= tmp; ans += a[i]; } if(ans==0) cout << "Yes\n"; else cout << "No\n"; } int main () { ios::sync_with_stdio(false); cin.tie(0); solve(); return 0; } //$ sudo g++ -o name name.cpp //$ ./name
#include <bits/stdc++.h> #define int long long int #define pb push_back #define vvi vector<vector<int>> #define Pii pair<int,int> #define SS second #define F first const int mod = 998244353; #define ld long double #define sp fixed<<setprecision(9) const int inf =1e18+7; using namespace std; #define db(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << '\n'; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } // int a[1000000],fenw[1000000]; // int query(int k){ // int s=0; // while(k>=1){ // s+=fenw[k]; // k-=(k&-k); // } // return s; // } // void update(int k,int x,int n){ // while(k<=n){ // fenw[k]+=x; // k+=(k&-k); // } // } int powmod(int x, int n, int md){ int ans=1; while(n){ if(n&1) ans=(ans*x)%md; n/=2; x=(x*x)%md; } return ans; } int merge(int arr[],int temp[],int left,int mid,int right){ int i,j,k; int inv_count=0; i=left,j=mid,k=left; while(i<mid and j<=right){ if(arr[i]<=arr[j]){ temp[k++]=arr[i++]; }else{ temp[k++]=arr[j++]; inv_count+=mid-i; } } while(i<mid){ temp[k++]=arr[i++]; } while(j<=right){ temp[k++]=arr[j++]; } for(i=left;i<=right;i++){ arr[i]=temp[i]; } return inv_count; } int merge_sort(int arr[],int temp[],int left,int right){ int mid,inv_count=0; if(right>left){ mid=(left+right)/2; inv_count+=merge_sort(arr,temp,left,mid); inv_count+=merge_sort(arr,temp,mid+1,right); inv_count+=merge(arr,temp,left,mid+1,right); } return inv_count; } void solve(int test){ int n; cin>>n; int a[n]; int b[n]; vector<vector<int>> v1,v2; for(int i=0;i<n;i++){ cin>>a[i]; a[i]+=i; v1.pb({a[i],i}); } for(int i=0;i<n;i++){ cin>>b[i]; b[i]+=i; v2.pb({b[i],i}); } sort(v1.begin(),v1.end()); sort(v2.begin(),v2.end()); int v[n],temp[n]; for(int i=0;i<n;i++){ if(v1[i][0]!=v2[i][0]){ cout<<-1; return; } v[v1[i][1]]=v2[i][1]; } cout<<merge_sort(v,temp,0,n-1); } 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 //double pi=3.14159265358979323846; //sieve(); //precompute(); int t=1; //cin>>t; int test=1; while(t--){ solve(test); test++; } return 0; }//Ardhendu Reja , JGEC
#include<bits/stdc++.h> #define LL long long #define pb push_back #define pii pair<int,int> using namespace std; const int mn=3006; int n,a[mn]; int main() { scanf("%d",&n); a[1]=6,a[2]=10,a[3]=15;a[0]=3; for(int i=1;i<=10000;++i) { if(i==6||i==10||i==15) continue; if(i%6==0||i%10==0||i%15==0) a[++a[0]]=i; } for(int i=1;i<=n;++i) cout<<a[i]<<" "; }
#include <bits/stdc++.h> #define REP(i, nn ) for(int i = 0 ; i < (int) nn; i++) #define REPS(i, ss, nn ) for(int i = ss ; i < (int) nn; i++) #define REV(i, ss, nn ) for(int i = ss ; i >= nn; i--) #define deb(x) std::cout << #x << " " << x << endl; #define debl(x) std::cout << #x << " " << x << " "; #define all(x) x.begin(), x.end() using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; namespace std{ template<class Fun> class y_combinator_result{ Fun fun_; public: template<class T> explicit y_combinator_result(T &&fun) : fun_(std::forward<T>(fun)){} template<class ...Args> decltype(auto) operator()(Args&&...args){ return fun_(std::ref(*this), std::forward<Args>(args)...); } }; template<class Fun> decltype(auto) y_combinator(Fun && fun){ return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun)); } }; template<typename T> bool umax(T& a, T b){ bool ret = a < b; if(ret) a = b; return ret; } template<typename T> bool umin(T& a, T b){ bool ret = a > b; if(ret) a = b; return ret; } struct edge{ int to; ll cost; int from; edge(){ edge(0,0);} edge(int to_, ll cost_) : to(to_), cost(cost_){} edge(int to_, int from_, ll cost_) : to(to_), cost(cost_), from(from_){} }; template<typename... T> void read(T& ... a){ ((cin >> a),...); } template<typename... T> void write(T... a){ ((cout << a),...); } template<typename T> vector<T> read_array(int sz){ vector<T> ret(sz); for(auto & x : ret) cin >> x; return ret; } void solve(){ int n; read(n); int mxN = 10000; vector<int> v; for(int k = 1; k <= mxN; k++){ int c = 0; if ( k % 2 == 0) c++; if( k % 3 == 0) c++; if (k % 5 == 0) c++; if(c >= 2) v.push_back(k); } if(n == 3){ vector<int> ans = {6, 10, 15}; for(int i = 0 ; i < n ; i++) write(ans[i], " "); return; } // deb(v.size()); for(int i = 0 ; i < n ; i++) write(v[i], " "); } int main() { //making data IO Fast std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); /****************************/ int T = 1; // cin >> T; while(T--) solve(); return 0; }
#include<iostream> #include<algorithm> using namespace std; bool mysolve(int arr[4]){ int sum = 0; for(int i = 0 ; i< 4 ; i++){ sum+=arr[i]; } int flag = 0; for(int i = 0 ; i< 4; i++){ if(arr[i]==(sum-arr[i])) {flag=1;break;} } for(int i = 0 ; i< 4; i++){ for(int j = i + 1 ; j <4 ; j++){ if((arr[i]+arr[j])==(sum-arr[i]-arr[j])) {flag=1;break;}} } for(int i = 0 ; i< 4; i++){ for(int j = i + 1 ; j <4 ; j++){ for(int k = j +1 ; k < 4; k++){ if((arr[i]+arr[j]+arr[k])==(sum-arr[i]-arr[j]-arr[k])) {flag=1;break;}}} } if(flag){ return true; } else return false; } bool editoral(int arr[4]){ if((arr[0]+arr[3] == arr[2]+arr[1])||(arr[0]+arr[1]+arr[2]==arr[3])) return true; else return false; } int main() { int arr[4]; cin>>arr[0]>>arr[1]>>arr[2]>>arr[3]; sort(arr,arr+4); //bool answer = mysolve(arr); bool answer = editoral(arr); answer?cout<<"Yes"<<endl:cout<<"No"<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int a,b,c,d; cin>>a>>b>>c>>d; if(a==b+c+d)return puts("Yes"),0; if(b==a+c+d)return puts("Yes"),0; if(c==b+a+d)return puts("Yes"),0; if(d==b+c+a)return puts("Yes"),0; if(b+a==c+d)return puts("Yes"),0; if(a+c==b+d)return puts("Yes"),0; if(b+c==a+d)return puts("Yes"),0; puts("No"); return 0; }
// https://atcoder.jp/contests/abc191/tasks/abc191_e #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define repr(i, n) for (int i = n - 1; i >= 0; i--) #define ALL(x) x.begin(), x.end() using str = string; using ll = long long; using vi = vector<int>; using vvi = vector<vector<int>>; using vll = vector<ll>; using vvl = vector<vector<ll>>; using pii = pair<int, int>; using pll = pair<ll, ll>; struct Graph { struct Edge { int from, to, cost; }; int n; int INF; vector<vector<Edge>> adj_list; Graph(int _n) { n = _n; INF = 1e9; adj_list.resize(n, vector<Edge>(0)); } void add(int from, int to, int cost) { adj_list[from].push_back({from, to, cost}); } int dijkstra(int start) { int ans = INF; vector<int> dist(n, INF); dist[start] = 0; priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq; pq.push({dist[start], start}); while (not pq.empty()) { int cur = pq.top().second; pq.pop(); for (Edge e : adj_list[cur]) { if (dist[e.to] > dist[cur] + e.cost) { dist[e.to] = dist[cur] + e.cost; pq.push({dist[e.to], e.to}); } if (e.to == start) { ans = min(ans, dist[cur] + e.cost); } } } return ans == INF ? -1 : ans; } }; int main() { int n, m; cin >> n >> m; Graph g(n); rep(i, m) { int a, b, c; cin >> a >> b >> c; a--; b--; g.add(a, b, c); } rep(i, n) { cout << g.dijkstra(i) << endl; } }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using std::cin; using std::cout; using std::vector; const int N = 200005; vector<int> to[N]; int dep[N]; int in[N]; int out[N]; int k; vector<int> ls[N]; void dfs(int v, int d) { in[v] = k++; dep[v] = d; for (int u : to[v]) dfs(u, d + 1); out[v] = k; } int main() { int n; cin >> n; rep(i, n - 1) { int p; cin >> p; to[p - 1].push_back(i + 1); } dfs(0, 0); rep(i, n) ls[dep[i]].push_back(in[i]); rep(i, n) sort(ls[i].begin(), ls[i].end()); int q; cin >> q; auto f = [&](int d, int r) { return lower_bound(ls[d].begin(), ls[d].end(), r) - ls[d].begin(); }; rep(qi, q) { int u, d; cin >> u >> d; --u; int ans = f(d, out[u]) - f(d, in[u]); cout << ans << '\n'; } return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; vector<tuple<long long,long long,long long>> a(n); for(int i=0;i<n;i++){ cin>>get<0>(a[i])>>get<1>(a[i])>>get<2>(a[i]); get<2>(a[i])=max(0ll,get<2>(a[i])-get<0>(a[i])); if(get<2>(a[i])==0) get<0>(a[i])=10*10*10*10*10*10*10*10*10+1; } sort(a.begin(),a.end()); if(get<0>(a[0])==10*10*10*10*10*10*10*10*10+1) cout<<-1<<endl; else{ long long ans=10*10*10*10*10*10*10*10*10+1; int w=0; while(get<0>(a[w])<10*10*10*10*10*10*10*10*10+1){ ans=min(ans,get<1>(a[w])); w++; } cout<<ans<<endl; } }
#include<bits/stdc++.h> using namespace std; int main() { long long n, a, b, x, mn = 10000000000, pre = 0, d = 0; cin>>n; while(n--){ cin>>a>>b>>x; d = d + a - pre; x = x - d; if(x > 0) mn = min(mn, b); pre = a; } if(mn == 10000000000) cout<<-1<<endl; else cout<<mn<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; #ifndef ONLINE_JUDGE #define LOCAL #endif typedef long long ll; typedef long double ld; typedef pair<ll,ll> pll; typedef vector<ll> vi; typedef vector<pll> vpll; const long infl=0x3f3f3f3f3f3f3f3fLL; const int infi=0x3f3f3f3f; #define endl '\n' #define pb push_back #define all(a) (a).begin(),(a).end() #define F first #define S second #define rs(v,n) v.resize(n) #define hell 1000000007 //#define hell 998244353 #define peak 9e18 #define pii acos(-1) #define clr(a,x) memset(a,x,sizeof(a)) auto clk=clock(); mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count()); #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template<typename T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; namespace Ops{ template<class y,class z> ll expo(ll b,y e,z m){ll a=1;b%=m;while(e!=0){if((e&1)==1){a=a*b;a=a%m;}b=b*b;b%=m;e>>=1;}return a%m;} template<class y> ll power(ll b,y e){ll a=1;while(e!=0){if((e&1)==1){a=a*b;}b=b*b;e>>=1;}return a;} template<class x,class z> ll inv(x b,z m){return expo(b,m-2,m);} template<class x,class y> x invGeneral(x a,y b){if(a==0)return b==1?0:-1;x m=invGeneral(b%a,a);return m==-1?-1:((1-(ll)b*m)/a+b)%b;} template<class x,class y> x min(x a,y b){x c;if(a<=b)c=a;else c=b;return c;} template<class x,class y> x max(x a,y b){x c;if(a>=b)c=a;else c=b;return c;} ll mul(ll x,ll y,ll m){x%=m;y%=m;if(x==0)return 0;if(x%2==0)return (mul(x/2,y,m)*2)%m;return ((mul(x/2,y,m)*2)%m+y)%m;} } using namespace Ops; namespace InOp{ template<class x>istream &operator>>(istream &in,vector<x> &v) {for(auto& i:v)in>>i;return in;} template<class x,class y> ostream &operator<<(ostream &out,pair<x,y> &p) {out<<"("<<p.F<<","<<p.S<<")";return out;} template<class x> ostream &operator<<(ostream &out,vector<x> &v) {out<<"Size : "<<v.size()<<endl;for(auto i:v)out<<i<<" ";out<<endl;return out;} } using namespace InOp; namespace Debug{ #ifdef LOCAL #define deb(...) printall(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void printall(const char* name, Arg1&& arg1){cerr<<name<<" : "<<arg1<<endl;} template <typename Arg1, typename... Args> void printall(const char* names,Arg1&& arg1,Args&&... args){const char* comma=strchr(names,',');cerr.write(names,comma-names)<<" : " <<arg1<<" | ";printall(comma+1,args...);} #else #define deb(...) void(0) #endif } using namespace Debug; namespace Bits{ template<class x> constexpr int onbits(x a){return __builtin_popcount(a);} constexpr int bits(long long x){return 64-__builtin_clzll(x);}//take care of 0 constexpr int bits(int x){return 32-__builtin_clz(x);}//take care of 0 constexpr int traz(int a){return __builtin_ctz(a);} constexpr int traz(long long a){return __builtin_ctzll(a);} } using namespace Bits; namespace YesNo{ //#define CAPITAL void yes(){ #ifdef CAPITAL cout<<"YES"<<"\n"; #else cout<<"Yes"<<"\n"; #endif } void no(){ #ifdef CAPITAL cout<<"NO"<<"\n"; #else cout<<"No"<<"\n"; #endif } } using namespace YesNo; void maester(); int main() { ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); srand(chrono::high_resolution_clock::now().time_since_epoch().count()); cout<<fixed<<setprecision(6); cerr<<fixed<<setprecision(6); ll test=1; //cin>>test; for(ll tt=1;tt<=test;tt++) { //cout<<"Case #"<<tt<<": "; maester(); } #ifdef LOCAL cerr<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl; #endif return 0; } #define N 1000005 void maester() { ll i,j,k,l,r,m,n,x,y; cin>>n; vi v(n); cin>>v; map<ll,ll> ma; ll ans=0; for(i=0;i<n;i++) { ans+=ma[v[i]%200]; ma[v[i]%200]++; } cout<<ans<<endl; }
// Write CPP code here #include <bits/stdc++.h> using namespace std; // function to Count pairs in an array whose // absolute difference is divisible by k void countPair(long int arr[], long int n, long int k) { // long intialize the count long int cnt = 0; // making every element of arr in // range 0 to k - 1 for (long int i = 0; i < n; i++) { arr[i] = (arr[i]) % k; } // create an array hash[] long int hash[k] = { 0 }; // store to count of element of arr // in hash[] for (long int i = 0; i < n; i++) { hash[arr[i]]++; } // count the pair whose absolute // difference is divisible by k for (long int i = 0; i < k; i++) { cnt += (hash[i] * (hash[i] - 1)) / 2; } // prlong int the value of count cout << cnt << endl; } // Driver Code int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif long int n; long int arr[1000000]; cin >> n; for (long int i = 0; i < n; i++) { cin >> arr[i]; } long int k = 200; // calculate the size of array //long int n = sizeof(arr) / sizeof(arr[0]); countPair(arr, n, k); return 0; }
#include<bits/stdc++.h> using namespace std; const int N = 1e6 + 5, M = 1e3 + 5; #define int long long #define double long double #define fio ios_base::sync_with_stdio(false);cin.tie(NULL); char s[1111]; void solve() { cin>>s+1; for(int i=1;i<=strlen(s+1);i++){ if(i&1) { if(s[i]>='A'&&s[i]<='Z') { cout<<"No"<<endl; return; } } else{ if(s[i]>='a'&&s[i]<='z') { cout<<"No"<<endl; return; } } } cout<<"Yes"<<endl; } signed main() { fio; solve(); return 0; }
#include<bits/stdc++.h> #define inf 1e18 #define endl "\n" #define loop(i,x,y) for(int i = x; i < y ; i++ ) #define in(n) int n; cin>>n; #define inarr(arr,n) int arr[n]; for(int i = 0; i < n ; i++){cin>>arr[i];} #define maploop(x) for(auto itr = x.begin(); itr != x.end();itr++) #define int long long using namespace std; const int N = 10001; int mod = 1000000007; void Main() { string s; cin >> s; loop(i, 0, s.size()) { if (i % 2 == 1) { if (s[i] >= 'A' && s[i] <= 'Z') { continue; } else { cout << "No" << endl; return; } } else { if (s[i] >= 'a' && s[i] <= 'z') { continue; } else { cout << "No" << endl; return; } } } cout << "Yes" << endl; } int32_t main() { srand(time(0)); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; //cin >> t; while (t--) { Main(); } }
//~ author : Sumit Prajapati #include <bits/stdc++.h> using namespace std; #define ull unsigned long long #define ll long long #define int long long #define pii pair<int, int> #define pll pair<ll, ll> #define pb push_back #define mk make_pair #define ff first #define ss second #define all(a) a.begin(),a.end() #define trav(x,v) for(auto &x:v) #define rep(i,n) for(int i=0;i<n;i++) #define repe(i,n) for(int i=1;i<=n;i++) #define read(a,n) rep(i,n)cin>>a[i] #define reade(a,n) repe(i,n)cin>>a[i] #define FOR(i,a,b) for(int i=a;i<=b;i++) #define printar(a,s,e) FOR(i,s,e)cout<<a[i]<<" ";cout<<'\n' #define curtime chrono::high_resolution_clock::now() #define timedif(start,end) chrono::duration_cast<chrono::nanoseconds>(end - start).count() auto time0 = curtime; const int MD=1e9+7; const int MDL=998244353; const int INF=1e9; const int MX=1e5+5; void solve(){ int a,b,c,d; cin>>a>>b>>c>>d; rep(k,MX){ int cyan=a+k*b; int red=d*k*c; if(cyan<=red){ cout<<k<<"\n"; return; } } cout<<"-1\n"; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); time0 = curtime; srand(time(NULL)); int t=1; // cin>>t; repe(tt,t){ // cout<<"Case #"<<tt<<": "; solve(); } // cerr<<"Execution Time: "<<timedif(time0,curtime)*1e-9<<" sec\n"; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #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; } ll solve(long long X, long long Y){ static map<ll,ll> cache; if(cache.count(Y)){ return cache[Y]; } if(X>=Y){ return X-Y; } ll ret=abs(X-Y); if(Y%2){ chmin(ret,solve(X,(Y+1)/2)+2); chmin(ret,solve(X,(Y-1)/2)+2); }else{ chmin(ret,solve(X,Y/2)+1); } return cache[Y]=ret; } int main(){ cout<<setprecision(1000); long long X; scanf("%lld",&X); long long Y; scanf("%lld",&Y); cout<<solve(X, Y)<<endl;; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0; i < (int)n; i++) using ll = long long; const int INF = 1e9; int main(){ int n, k; cin >> n >> k; vector<vector<int>> g(n); rep(i,n-1) { int u, v; cin >> u >> v; u--; v--; g[u].push_back(v); g[v].push_back(u); } int l = -1, r = n, m; vector<int> dp(n), yet(n), done(n); auto dfs = [&](auto&& self, int u, int p) -> void { dp[u] = 0; yet[u] = 0; done[u] = INF; for(auto x : g[u]) { if(x == p) continue; self(self,x,u); dp[u] += dp[x]; done[u] = min(done[u],done[x]+1); } if(done[u] <= m) yet[u] = -1; for(auto x : g[u]) { if(x == p) continue; if(yet[x]+1+done[u] > m) yet[u] = max(yet[u],yet[x]+1); } if(yet[u] == m) { dp[u]++; done[u] = 0; yet[u] = -1; } }; while(r - l > 1) { m = (l + r) / 2; dfs(dfs,0,-1); if(yet[0] != -1) dp[0]++; (dp[0] <= k ? r : l) = m; } cout << r << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define mp make_pair #define fr first #define sc second template<class T> T T_INF(){ return 1000000000000000000; } template<> int T_INF<int>(){ return 1000000000; } struct Tree{ int n; vector<vector<pair<int,int>>> G; Tree(int n_){ init(n_); } Tree(){} void init(int n_){ n=n_; G=vector<vector<pair<int,int>>>(n); } void add_edge(int u,int v,int i=0){ G[u].push_back(mp(v,i)); } }; struct rooted_tree{ Tree* Tr; int root; vector<pair<int,int>> par; vector<int> dep; vector<int> vs; //pre-orderにvertexを並べたもの vector<int> pre_order; //頂点iがpre-orderで何番目か rooted_tree(Tree* Tr_,int r=0):Tr(Tr_),root(r),par(Tr->n),dep(Tr->n),vs(Tr->n),pre_order(Tr->n,-1){ dfs(mp(r,-1),-1,0,0); } rooted_tree(){} int dfs(pair<int,int> e, int p,int d,int k){ if(pre_order[e.fr]!=-1)return k; par[e.fr]=mp(p,e.sc); dep[e.fr]=d; vs[k]=e.fr; pre_order[e.fr]=k++; for(auto ed: Tr->G[e.fr])k=dfs(ed,e.fr,d+1,k); return k; } }; template<class T> vector<T> dist_on_tree(const Tree &Tr, int s){ vector<T> dist(Tr.n,-1); queue<int> que; dist[s]=0; que.push(s); while(!que.empty()){ int v=que.front(); que.pop(); for(auto ed: Tr.G[v]){ if(dist[ed.fr]!=-1)continue; dist[ed.fr]=dist[v]+1; que.push(ed.fr); } } return dist; } int main(){ int n,k; scanf("%d%d",&n,&k); Tree Tr(n); for(int i=0;i<n-1;i++){ int u,v; scanf("%d%d",&u,&v); u--; v--; Tr.add_edge(u,v); Tr.add_edge(v,u); } rooted_tree rt(&Tr); vector<pair<int,int>> vs; for(int i=0;i<Tr.n;i++)vs.push_back(mp(rt.dep[i],i)); sort(vs.begin(),vs.end(),greater<pair<int,int>>()); int l=0,r=n-1; while(l<r){ int m=(l+r)/2; bool ok=false; if(m<=800){ static int d[200010]; fill(d,d+n,-1); int cnt=0; for(auto p: vs){ int v=p.sc; bool used=false; pair<int,int> loc(v,0); do{ if(d[loc.fr]>=loc.sc){ used=true; break; } loc.fr=rt.par[loc.fr].fr; loc.sc++; }while(loc.fr!=-1&&loc.sc<=m); if(!used){ for(int i=0;i<m&&v!=-1;i++)v=rt.par[v].fr; if(v==-1)v=0; cnt++; if(cnt>k)break; loc=mp(v,0); do{ d[loc.fr]=m-loc.sc; loc.fr=rt.par[loc.fr].fr; loc.sc++; }while(loc.fr!=-1&&loc.sc<=m); } } ok=cnt<=k; } else { static bool used[200010]; fill(used,used+n,false); int cnt=0; for(auto p: vs){ int v=p.sc; if(!used[v]){ for(int i=0;i<m&&v!=-1;i++)v=rt.par[v].fr; if(v==-1)v=0; cnt++; if(cnt>k)break; auto d=dist_on_tree<int>(Tr,v); for(int i=0;i<n;i++)if(d[i]<=m)used[i]=true; } } ok=cnt<=k; } if(ok)r=m; else l=m+1; } cout<<l<<endl; }
#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #define ll long long #define rep(i, n) for(ll i = 0; i < n; ++i) #define rep2(i, a, b) for(ll i = a; i <= b; ++i) #define rep3(i, a, b) for(ll i = a; i >= b; --i) #define eb emplace_back #define pb push_back #define all(c) (c).begin(), (c).end() #define vi vector<int> #define N 100100 #define MOD 1000000007 //998244353 #define pii pair<int,int> #define pll pair<ll,ll> int main() { ll n; vector<ll>a; vector<ll>b; ll x, y, z; ll l[N]; ll r[N]; bool v; ll s, ans; cin >> n >> x; a.pb(0); rep(i, n) { cin >> y; a.pb(y); } a.pb(x + 1); b.pb(0); rep(i, n) { cin >> y; b.pb(y); } b.pb(x + 1); x = 0; n += 2; rep(i, n) { l[i] = -1; r[i] = -1; } rep(i, n) { while (true) { if (x >= i) { if (a[x] + (i - x) < b[i])x++; else break; } else { if (a[x + 1] + (i - x - 1) > b[i])break; else x++; } } if (a[x] + (i - x) != b[i]) { cout << -1 << endl; return 0; } if (l[x] == -1)l[x] = i; r[x] = i; } ans = 0; rep(i,n) { if (l[i] >= 0) { if (l[i] < i) { ans += (i - l[i]); } if (r[i] > i) { ans += (r[i] - i); } } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define FASTIO using namespace std; using ll = long long; using Vi = std::vector<int>; using Vl = std::vector<ll>; using Pii = std::pair<int, int>; using Pll = std::pair<ll, ll>; constexpr int I_INF = std::numeric_limits<int>::max(); constexpr ll L_INF = std::numeric_limits<ll>::max(); template <typename T1, typename T2> inline bool chmin(T1& a, const T2& b) { if (a > b) { a = b; return true; } return false; } template <typename T1, typename T2> inline bool chmax(T1& a, const T2& b) { if (a < b) { a = b; return true; } return false; } class Prints { private: class __Prints { public: __Prints(const char* sep, const char* term) : sep(sep), term(term) {} template <class... Args> void operator()(const Args&... args) const { print(args...); } template <typename T> void pvec(const T& vec, size_t sz) const { for (size_t i = 0; i < sz; i++) std::cout << vec[i] << (i == sz - 1 ? term : sep); } template <typename T> void pmat(const T& mat, size_t h, size_t w) { for (size_t i = 0; i < h; i++) for (size_t j = 0; j < w; j++) std::cout << mat[i][j] << (j == w - 1 ? term : sep); } private: const char *sep, *term; void print() const { std::cout << term; } void print_rest() const { std::cout << term; } template <class T, class... Tail> void print(const T& head, const Tail&... tail) const { std::cout << head, print_rest(tail...); } template <class T, class... Tail> void print_rest(const T& head, const Tail&... tail) const { std::cout << sep << head, print_rest(tail...); } }; public: Prints() {} __Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); } }; Prints prints; //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% void solve() { ll N, L; cin >> N >> L; Vl A(N + 2), B(N + 2); for (ll i = 1; i <= N; i++) { cin >> A[i]; A[i] -= i; } for (ll i = 1; i <= N; i++) { cin >> B[i]; B[i] -= i; } A[N + 1] = B[N + 1] = (L + 1) - (N + 1); Vl pos = B; pos.erase(unique(pos.begin(), pos.end()), pos.end()); ll ans = 0; for (auto p : pos) { int idxl_a = lower_bound(A.begin(), A.end(), p) - A.begin(); int idxr_a = upper_bound(A.begin(), A.end(), p) - A.begin(); int idxl_b = lower_bound(B.begin(), B.end(), p) - B.begin(); int idxr_b = upper_bound(B.begin(), B.end(), p) - B.begin(); if (idxr_a - idxl_a == 0) { prints()(-1); return; } ans += max(idxr_b - idxr_a, 0) + max(idxl_a - idxl_b, 0); } prints()(ans); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% int main() { #ifdef FASTIO std::cin.tie(nullptr), std::cout.tie(nullptr); std::ios::sync_with_stdio(false); #endif #ifdef FILEINPUT std::ifstream ifs("./in_out/input.txt"); std::cin.rdbuf(ifs.rdbuf()); #endif #ifdef FILEOUTPUT std::ofstream ofs("./in_out/output.txt"); std::cout.rdbuf(ofs.rdbuf()); #endif std::cout << std::setprecision(18) << std::fixed; solve(); std::cout << std::flush; return 0; }
/* author: Maksim1744 created: 10.04.2021 15:15:03 */ #include "bits/stdc++.h" using namespace std; #define ll long long #define ld long double #define mp make_pair #define pb push_back #define eb emplace_back #define sum(a) ( accumulate ((a).begin(), (a).end(), 0ll)) #define mine(a) (*min_element((a).begin(), (a).end())) #define maxe(a) (*max_element((a).begin(), (a).end())) #define mini(a) ( min_element((a).begin(), (a).end()) - (a).begin()) #define maxi(a) ( max_element((a).begin(), (a).end()) - (a).begin()) #define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin()) #define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin()) template<typename T> vector<T>& operator-- (vector<T>& v){for (auto& i : v) --i; return v;} template<typename T> vector<T>& operator++ (vector<T>& v){for (auto& i : v) ++i; return v;} template<typename T> istream& operator>>(istream& is, vector<T>& v){for (auto& i : v) is >> i; return is;} template<typename T> ostream& operator<<(ostream& os, vector<T>& v){for (auto& i : v) os << i << ' '; return os;} template<typename T, typename U> pair<T,U>& operator-- (pair<T, U> &p){--p.first; --p.second; return p;} template<typename T, typename U> pair<T,U>& operator++ (pair<T, U> &p){++p.first; ++p.second; return p;} template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& p){is >> p.first >> p.second; return is;} template<typename T, typename U> ostream& operator<<(ostream& os, pair<T, U>& p){os << p.first << ' ' << p.second; return os;} template<typename T, typename U> pair<T,U> operator-(pair<T,U> a, pair<T,U> b){return mp(a.first-b.first, a.second-b.second);} template<typename T, typename U> pair<T,U> operator+(pair<T,U> a, pair<T,U> b){return mp(a.first+b.first, a.second+b.second);} template<typename T, typename U> void umin(T& a, U b){if (a > b) a = b;} template<typename T, typename U> void umax(T& a, U b){if (a < b) a = b;} #ifdef HOME #define SHOW_COLORS #include "C:/C++ libs/print.cpp" #else #define show(...) 42 #define mclock 42 #define shows 42 #define debug if (false) #endif int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; vector<int> v(n * 2); cin >> v; vector<int> a(n), b(n); for (int i = 0; i < n; ++i) { a[i] = v[n - 1 - i]; b[i] = v[n + i]; } set<pair<int, int>> cur; ll ans = 0; reverse(a.begin(), a.end()); reverse(b.begin(), b.end()); for (int i = 0; i < n; ++i) { cur.emplace(a[i], i); cur.emplace(b[i], i + n); ans += cur.rbegin()->first; cur.erase(--cur.end()); } cout << ans << '\n'; return 0; }
#line 1 "main.cpp" /** * @title Template */ #include <iostream> #include <algorithm> #include <utility> #include <numeric> #include <vector> #include <array> #include <cassert> #line 2 "/Users/kodamankod/Desktop/cpp_programming/Library/other/chmin_chmax.cpp" template <class T, class U> constexpr bool chmin(T &lhs, const U &rhs) { if (lhs > rhs) { lhs = rhs; return true; } return false; } template <class T, class U> constexpr bool chmax(T &lhs, const U &rhs) { if (lhs < rhs) { lhs = rhs; return true; } return false; } /** * @title Chmin/Chmax */ #line 2 "/Users/kodamankod/Desktop/cpp_programming/Library/other/range.cpp" #line 4 "/Users/kodamankod/Desktop/cpp_programming/Library/other/range.cpp" class range { public: class iterator { private: int64_t M_position; public: constexpr iterator(int64_t position) noexcept: M_position(position) { } constexpr void operator ++ () noexcept { ++M_position; } constexpr bool operator != (iterator other) const noexcept { return M_position != other.M_position; } constexpr int64_t operator * () const noexcept { return M_position; } }; class reverse_iterator { private: int64_t M_position; public: constexpr reverse_iterator(int64_t position) noexcept: M_position(position) { } constexpr void operator ++ () noexcept { --M_position; } constexpr bool operator != (reverse_iterator other) const noexcept { return M_position != other.M_position; } constexpr int64_t operator * () const noexcept { return M_position; } }; private: const iterator M_first, M_last; public: constexpr range(int64_t first, int64_t last) noexcept: M_first(first), M_last(std::max(first, last)) { } constexpr iterator begin() const noexcept { return M_first; } constexpr iterator end() const noexcept { return M_last; } constexpr reverse_iterator rbegin() const noexcept { return reverse_iterator(*M_last - 1); } constexpr reverse_iterator rend() const noexcept { return reverse_iterator(*M_first - 1); } }; /** * @title Range */ #line 16 "main.cpp" using i32 = std::int32_t; using i64 = std::int64_t; using u32 = std::uint32_t; using u64 = std::uint64_t; using isize = std::ptrdiff_t; using usize = std::size_t; constexpr i32 inf32 = (i32(1) << 30) - 1; constexpr i64 inf64 = (i64(1) << 62) - 1; int main() { isize N, M; std::cin >> N >> M; if (M < 0) { std::cout << "-1\n"; return 0; } if (N == 1) { if (M == 0) { std::cout << "1 2\n"; } else { std::cout << "-1\n"; } return 0; } if (M >= N - 1) { std::cout << "-1\n"; return 0; } std::vector<std::pair<i32, i32>> ans; ans.emplace_back(1, 1000000); for (auto i: range(0, M + 1)) { ans.emplace_back(2 * i + 2, 2 * i + 3); } for (auto i: range(0, N - M - 2)) { ans.emplace_back(1000000 + 2 * i + 1, 1000000 + 2 * i + 2); } for (auto [x, y]: ans) { std::cout << x << ' ' << y << '\n'; } return 0; }
#include <iostream> #include <vector> #include <queue> #include <stack> #include <map> #include <algorithm> #include <bitset> #include <string> #include <cstdio> #include <cmath> #include <climits> #include <fstream> using namespace std; const long long INF = LLONG_MAX; const long long MOD = 1000000007; typedef pair<int, int> pii; typedef pair<long long, long long> pll; ostream& operator<<(ostream& os, vector<vector<char>> v) { for (int y = 0; y < v.size(); y++) { for (int x = 0; x < v[y].size(); x++) { os << v[y][x]; } os << endl; } return os; } class UnionFind { private: vector<int> parent; public: UnionFind(int N) { parent.resize(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; } }; long long comb2(long long n) { return n * (n-1) / 2; } int main(void) { int n; cin >> n; vector<pll> a(n); vector<long long> sum(n+1, 0); for (int i = 0; i < n; ++i) { cin >> a[i].first; a[i].first %= 200; a[i].second = i + 1; } sort(a.begin(), a.end()); for (int i = 0; i < n; ++i) { sum[i+1] = sum[i] + a[i].first; } vector<vector<pii>> v(200); for (int left = 0; left < n; ++left) { for (int right = left + 1; right <= n; ++right) { long long s = sum[right] - sum[left]; long long mod = s % 200; v[mod].emplace_back(left, right); } } for (int mod = 0; mod < 200; ++mod) { if (v[mod].size() > 1) { cout << "Yes" << endl; for (int i = 0; i < 2; ++i) { cout << v[mod][i].second - v[mod][i].first; vector<int> index; for (int j = v[mod][i].first; j < v[mod][i].second; ++j) { index.push_back(a[j].second); } sort(index.begin(), index.end()); for (int i : index) { cout << ' ' << i; } cout << endl; } return 0; } } cout << "No" << endl; }
#include <bits/stdc++.h> #include <cmath> #include <unordered_set> using namespace std; using ll = long long; using vi = vector<int>; const int MOD = 1000000007; int main() { int n; cin >> n; vector<ll> A(n); for(int i = 0; i < n; i++){ ll a; cin >> a; A.at(i) = a; } sort(A.begin(), A.end()); reverse(A.begin(), A.end()); ll ans = 1; for(int i = 0; i < n-1; i++){ ans *= A.at(i) - A.at(i+1) + 1; ans %= MOD; } ans *= A.at(n-1) + 1; ans %= MOD; cout << ans << endl; }
#include<bits/stdc++.h> #define ll long long using namespace std; //memset(dp, 0, sizeof(dp)); void work(int T) { int n; cin >> n; vector<int> a(n); for(int i = 0; i < n; i++) { string s; cin >> s; if(s == "AND") { a[i] = 1; } else { a[i] = 0; } } vector<vector<ll>> dp(n + 1, vector<ll>(2)); dp[0][0] = dp[0][1] = 1; for(int i = 1; i <= n; i++) { if(a[i - 1]) { dp[i][0] = dp[i - 1][0] + dp[i - 1][1] + dp[i - 1][0]; dp[i][1] = dp[i - 1][1]; } else { dp[i][0] = dp[i - 1][0]; dp[i][1] = dp[i - 1][1] + dp[i - 1][0] + dp[i - 1][1]; } } cout << dp[n][1] << endl; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.precision(10); cout << fixed; // int t; // for(cin >> t; t > 0; t--) { // work(t); // } work(0); return 0; };
#include<bits/stdc++.h> #define rep(a,b,c) for(register int a=(b);a<=(c);++a) #define dow(a,b,c) for(register int a=(b);a>=(c);--a) using namespace std; const int MaxN=1000000+5; int lef[MaxN],rig[MaxN]; bool usd[MaxN]; int main() { register int n; scanf("%d",&n); register int pos,typ; rep(i,1,n) { scanf("%d%d",&pos,&typ); if(!usd[typ]) { usd[typ]=true; lef[typ]=rig[typ]=pos; continue; } lef[typ]=min(lef[typ],pos); rig[typ]=max(rig[typ],pos); } usd[n+1]=true; register long long dpB=0,dpE=0,_dpB=0,_dpE=0,Answer; register int Last=0; rep(i,1,n+1) { if(!usd[typ=i]) continue; _dpB=dpB,_dpE=dpE; dpB=(rig[typ]-lef[typ])+min(_dpB+abs(rig[typ]-lef[Last]),_dpE+abs(rig[typ]-rig[Last])); dpE=(rig[typ]-lef[typ])+min(_dpB+abs(lef[typ]-lef[Last]),_dpE+abs(lef[typ]-rig[Last])); Last=typ; } printf("%lld\n",Answer=min(dpB,dpE)); 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=INF; const ll inf=INF*INF; const ll mod=MOD; const ll MAX=100010; signed main(){ ll n;cin>>n; double d,h;cin>>d>>h; double ans=0; rep(i,n){ double a,b;cin>>a>>b; ans=max(ans,h-(h-b)*d/(d-a)); } cout<<fixed<<setprecision(10)<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) #define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++) #define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--) #define all(a) (a.begin()),(a.end()) #define rall(a) (a.rbegin()),(a.rend()) #define fi first #define se second #define pb push_back #define eb emplace_back using ll = long long; using vll = vector<ll>; using vi = vector<int>; using vvi = vector<vector<int>>; using P = pair<int, int>; using LD = long double; template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } void yes(bool ok = true){ cout << (ok ? "yes" : "no") << endl; } void Yes(bool ok = true){ cout << (ok ? "Yes" : "No") << endl; } void YES(bool ok = true){ cout << (ok ? "YES" : "NO") << endl; } LD memo[105][105][105]; LD dfs(int a, int b, int c){ if(memo[a][b][c] != 0) return memo[a][b][c]; if(a == 100 || b == 100 || c == 100) return memo[a][b][c] = 0; LD sum = a + b + c; return memo[a][b][c] = a * (dfs(a+1, b, c)+1) / sum + b * (dfs(a, b+1, c)+1) / sum + c * (dfs(a, b, c+1)+1) / sum; } void Main(){ int a, b, c; cin >> a >> b >> c; cout << dfs(a, b, c) << endl; return; } int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(15); Main(); return 0; }
#include <bits/stdc++.h> using namespace std; //begin of def #define fastio ios_base::sync_with_stdio(false);cin.tie(0) #define endl '\n' using lli = long long int; using ulli = unsigned long long int; using Ld = long double; using pii = pair<int, int>; using pll = pair<lli, lli>; using pld = pair<Ld, Ld>; #define X first #define Y second #define rep(I, S, E) for(int I = (S); I < (E); I++) #define repq(I, S, E) for(int I = (S); I <= (E); I++) #define pb push_back #define epb emplace_back #define ALL(P) P.begin(), P.end() //end of def const lli MOD = 1e9 + 7; int main(){ fastio; int n; cin >> n; vector<lli> v(n); rep(i, 0, n) cin >> v[i]; v.pb(0); sort(ALL(v)); v.erase(unique(ALL(v)), v.end()); n = v.size(); lli res = 1; rep(i, 1, n){ res = (res * (v[i] - v[i - 1] + 1)) % MOD; } cout << res; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long int #define rep(i, n) for(int i = 0; i < (int) n; i++) #define repd(i, n) for(int i = (int) (n - 1); i >= 0; i--) #define FOR(i, a, b) for(int i = a; i <= (int) b; i++) #define FORD(i, a, b) for(int i = a; i >= (int) b; i--) template <typename T> void load(int n, vector<T> &v) { rep(i, n) { T a; cin >> a; v.push_back(a); } } signed main() { int k; cin >> k; /* * AとBのペアを考えれば,Cは floor(k/AB) 個の候補が存在する. * よって以下のコードを書くことができる. */ /* int count = 0; for (int a = 1; a <= k; a++) { for (int b = 1; b <= k; b++) { count += floor((double) k / ((double) a * (double) b)); } } cout << count << endl; */ /* * これで正解は出るが,計算量はO(N^2)であるから,間に合わない. * ここから改良する.まず,a * b > kの時点で組み合わせは無いので答えにはなり得ない. * よって,以下のコードを得る */ int count = 0; for (int a = 1; a <= k; a++) { for (int b = 1; a * b <= k; b++) { count += floor((double) k / ((double) a * (double) b)); } } cout << count << endl; /* * この計算量について考えてみよう. * aが1からkまで動くとき,bは1からk / aまで動く. * よって,計算量は, Sum(a=1->k)[k / a] = k * Sum(a=1->k)[1 / a] を考えることにより, * O(klog(k))である.よって十分高速に動作する. * ※ 1 + 1/2 + 1/3 + ... 1/n < log(n) は面積評価することにより証明できる. */ }
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <vector> // Acknowledgement: Special thanks to kyomukyomupurin, who developed this // template. template <class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '(' << p.first << ", " << p.second << ')'; } template <class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { int n = 0; for (auto e : vec) os << (n++ ? ", " : "{") << e; return os << (n ? "}" : "{}"); } template <class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { int n = 0; for (auto e : st) os << (n++ ? ", " : "{") << e; return os << (n ? "}" : "{}"); } template <class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { int n = 0; for (auto e : mp) os << (n++ ? ", " : "{") << e; return os << (n ? "}" : "{}"); } template <class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { for (T& e : vec) is >> e; return is; } #ifdef LOCAL #define debug(...) \ std::cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__) #else #define debug(...) #endif void debug_out() { std::cerr << '\n'; } template <class Head, class... Tail> void debug_out(Head&& head, Tail&&... tail) { std::cerr << head; if (sizeof...(Tail) != 0) std::cerr << ", "; debug_out(std::forward<Tail>(tail)...); } using namespace std; using int64 = long long; int main() { string s; cin >> s; vector<int> v(10); int sz = s.size(); for (int i = 0; i < sz; i++) { int idx = s[i] - '0'; v[idx]++; } debug(v); if (sz == 1) { if (s == "8") cout << "Yes" << endl; else cout << "No" << endl; return 0; } vector<string> vs = {"16", "61", "24", "42", "32", "23", "48", "84", "56", "65", "64", "46", "72", "27", "88", "96", "69"}; if (sz == 2) { for (auto a : vs) { if (a == s) { cout << "Yes" << endl; return 0; } } cout << "No" << endl; return 0; } for (int i = 104; i < 1000; i += 8) { bool break_flag = false; vector<int> v_tmp = v; string tmp = to_string(i); debug(tmp); for (int j = 0; j < 3; j++) { if (v_tmp[tmp[j] - '0'] <= 0) { break_flag = true; break; } v_tmp[tmp[j] - '0']--; } debug(v_tmp); if (!break_flag) { cout << "Yes" << endl; return 0; } } cout << "No" << endl; return 0; }
#include<bits/stdc++.h> #define ll long long int #define ld long double #define pb push_back #define pf push_front #define ppb pop_back #define ppf pop_front #define sz size() #define pi acos(-1.0) #define maxe *max_element #define mine *min_element #define F first #define S second #define C continue #define G goto done #define mem(a,b) memset(a,b,sizeof(a)) #define all(a) (a).begin(),(a).end() #define gcd(a,b) __gcd(a,b) #define lcm(a,b) ((a)*((b)/gcd(a,b))) #define point(a) fixed<<setprecision(a) #define get(a) for(auto &x:a) cin>>x #define print(a) for(auto x:a) cout<<x<<" "; cout<<endl #define see(x) cout<<#x<<" = "<<x<<endl #define uniq(a) sort(all(a)); (a).erase(unique((a).begin(),(a).end()),(a).end()) #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define tc int test; cin>>test; while(test--) using namespace std; int main() { string s; cin>>s; if(s.sz==1) { if(s=="8") cout<<"Yes"; else cout<<"No"; return 0; } set<ll>two, three; for(ll i=10;i<=99;i++) if(i%8==0) two.insert(i); for(ll i=100;i<=999;i++) if(i%8==0) three.insert(i); if(s.sz==2) { for(auto i:two) { string k=s; reverse(all(k)); ll a,b; a=stoi(s); b=stoi(k); if(a%8==0 || b%8==0) { cout<<"Yes"; return 0; } } cout<<"No"; return 0; } //for(auto i:three) cout<<i<<" "; cout<<endl; for(auto i:three) { string now=to_string(i); string k=s; ll f=0; //see(now); for(ll i=0;i<now.sz;i++) { for(ll j=0;j<k.sz;j++) { if(now[i]==k[j]) { //cout<<k<<" "; k[j]='X'; f++; break; //cout<<k<<endl<<endl; } } } if(f==3) { cout<<"Yes"; return 0; } } cout<<"No"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; int main() { // ios::sync_with_stdio(false); // cin.tie(NULL); ll i,j,k,l,m,n,t; char s,c; cin >> s; cin >> c; if(s == 'Y') cout << (char)toupper(c) << '\n'; else cout << c << '\n'; }
#include<bits/stdc++.h> using namespace std; typedef unsigned long long ll; #define fi first #define se second #define endl '\n' #define sf(n) scanf("%d",&n); #define pf(n) printf("%d\n",n); #define fast_io ios_base::sync_with_stdio(0); cin.tie(0) int main() { fast_io; char v1,v2,v3; cin >> v1 >> v2 >> v3; if(v1==v2 && v2==v3){ cout << "Won" << endl; } else{ cout << "Lost" << endl; } return 0; }
#include<bits/stdc++.h> #define rep(i, n) for (int i = 0, length = n; i < length; i++) #define fi first #define se second #define lb lower_bound #define ub upper_bound #define ep emplace #define epb emplace_back #define scll static_cast<long long> #define sz(x) static_cast<int>((x).size()) #define pfll(x) printf("%lld\n", x) #define ci(x) cin >> x #define ci2(x, y) cin >> x >> y #define ci3(x, y, z) cin >> x >> y >> z #define ci4(w, x, y, z) cin >> w >> x >> y >> z #define co(x) cout << x << endl #define co2(x, y) cout << x << " " << y << endl #define co3(x, y, z) cout << x << " " << y << " " << z << endl using namespace std; typedef long long ll; typedef pair<int, int> P; typedef priority_queue<int> PQ; typedef priority_queue<int, vector<int>, greater<int>> PQG; typedef priority_queue<P> PQP; typedef priority_queue<P, vector<P>, greater<P>> PQPG; const int MAX_N = 2e5, MOD = 1e9 + 7, INF = 1e9; int n, a[100], b[100], c[100], d[100]; int sq(int x, int y) { return x * x + y * y; } bool comp(const P& p1, const P& p2) { if (p1.fi >= 0 && p2.fi < 0) return true; if (p1.fi < 0 && p2.fi >= 0) return false; if (p1.fi == 0 && p2.fi == 0) { if (p1.se > 0 && p2.se < 0) return true; if (p1.se < 0 && p2.se > 0) return false; return abs(p1.se) < abs(p2.se); } if (p2.fi * p1.se == p1.fi * p2.se) return sq(p1.fi, p1.se) < sq(p2.fi, p2.se); return p2.fi * p1.se < p1.fi * p2.se; } bool judge(vector<P> &x, vector<P> &y) { rep(i, n) { bool tmp = true; rep(j, n) if (sq(x[j].fi, x[j].se) != sq(y[(j + i) % n].fi, y[(j + i) % n].se) || sq(x[(j + 1) % n].fi - x[j].fi, x[(j + 1) % n].se - x[j].se) != sq(y[(j + i + 1) % n].fi - y[(j + i) % n].fi, y[(j + i + 1) % n].se - y[(j + i) % n].se)) { tmp = false; break; } if (tmp) return true; } return false; } int main() { ci(n); rep(i, n) ci2(a[i], b[i]); rep(i, n) ci2(c[i], d[i]); if (n < 2) { co("Yes"); return 0; } vector<P> u[n], v[n]; rep(i, n) { rep(j, n) { if (j == i) continue; u[i].epb(a[j] - a[i], b[j] - b[i]); v[i].epb(c[j] - c[i], d[j] - d[i]); } sort(u[i].begin(), u[i].end(), comp); sort(v[i].begin(), v[i].end(), comp); } bool ans = false; rep(i, n) rep(j, n) ans |= judge(u[i], v[j]); if (n == 3 && sq(u[0][0].fi, u[0][0].se) != sq(u[0][1].fi, u[0][1].se) && sq(u[1][0].fi, u[1][0].se) != sq(u[1][1].fi, u[1][1].se) && sq(u[2][0].fi, u[2][0].se) != sq(u[2][1].fi, u[2][1].se)) { rep(i, 3) rep(j, 3) rep(k, 2) { if (sq(u[i][0].fi, u[i][0].se) != sq(v[i][k].fi, v[i][k].se)) continue; int t = (i + 1) % 2; if (u[i][0].fi * u[t][0].se - u[i][0].se * u[t][0].fi != v[i][k].fi * v[t][k].se - v[i][k].se * v[t][k].fi) { co("No"); return 0; } } } if (ans) co("Yes"); else co("No"); return 0; }
#include<bits/stdc++.h> using namespace std; #define LL long long void solve() { int n, ans = 0; cin >> n; vector<array<int, 2>> v(n), w(n); for (int i=0;i<n;++i) { cin >> v[i][0] >> v[i][1]; } for (int i=0;i<n;++i) { cin >> w[i][0] >> w[i][1]; } if (n == 1) { cout << "Yes\n"; return; } auto dist = [](array<int, 2> a, array<int, 2> b) { LL x = a[0] - b[0], y = a[1] - b[1]; return x * x + y * y; }; for (int i=0;i<n;++i) { for (int j=0;j<n;++j) if (j != i) { // v[0] maps to w[i] // v[1] maps to w[j] LL r1 = dist(v[0], v[1]), r2 = dist(w[i], w[j]); if (r1 != r2) continue; // cout << i << " " << j << " match\n"; LL av = v[1][0] - v[0][0], bv = v[1][1] - v[0][1], aw = w[j][0] - w[i][0], bw = w[j][1] - w[i][1]; vector<array<LL, 2>> vv, ww; for (auto p : v) { p[0] -= v[0][0]; p[1] -= v[0][1]; vv.push_back({av * p[0] + bv * p[1], av * p[1] - bv * p[0]}); } for (auto p : w) { p[0] -= w[i][0]; p[1] -= w[i][1]; ww.push_back({aw * p[0] + bw * p[1], aw * p[1] - bw * p[0]}); } sort(vv.begin(), vv.end()); sort(ww.begin(), ww.end()); if (vv == ww) { cout << "Yes\n"; return; } // for (auto p : vv) cout << p[0] << "," << p[1] << " "; cout << '\n'; // for (auto p : ww) cout << p[0] << "," << p[1] << " "; cout << '\n'; } } cout << "No\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define FI freopen("../in", "r", stdin) #define FO freopen("../out", "w", stdout) #define X first #define Y second 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 EDBUG #define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__) #else #define dbg(...) #endif typedef long long ll; typedef pair<int, int> ii; void solve() { int n; cin >> n; int ans = 0; while (n --) { int x; cin >> x; ans += max(0, x - 10); } cout << ans; } int main() { ios::sync_with_stdio(false); #ifndef EDBUG cin.tie(nullptr); #endif #ifdef QUICKRUN FI; // FO; #endif solve(); return 0; }
#include <iostream> #include <algorithm> #include <bits/stdc++.h> #define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define ll long long #define mm(arr) memset(arr, 0, sizeof(arr)) #define scanArray(a,n) for(int i = 0; i < n; i++){cin >> a[i];} #define pb push_back #define PI 3.141592653589793 #define MOD 1000000007 #include <cctype> #include <cstring> #include <cstdio> using namespace std; int main() { int a,b,c; char d; string e,f; cin >>a; if (a>=0){ cout <<a; } else cout <<0; return 0; }
/** I can do this all day **/ #pragma GCC optimize("O2") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> pii; typedef pair<ll,ll> pll; #define all(x) (x).begin(),(x).end() #define F first #define S second #define Mp make_pair #define SZ(x) (int)x.size() #define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define file_io freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout); const int N = 1e6 + 10; const ll mod = 1e9 + 7; const ll mod2 = 998244353; const ll inf = 8e18; const int LOG = 22; ll pw(ll a , ll b, ll M) { return (!b ? 1 : (b & 1 ? (a * pw(a * a % M, b / 2, M)) % M : pw(a * a % M, b / 2, M))); } int n, A[N]; int main() { scanf("%d", &n); A[1] = 6; A[2] = 10; A[3] = 15; int ptr = 16; for(int i = 4; i <= n; i ++) { int ok = 0; while(!ok) { ok = 1; for(int j = 1; j < i; j ++) { if(__gcd(ptr, A[j]) == 1) { ok = 0; break; } } if(!ok) { ptr ++; } } A[i] = ptr; ptr ++; } for(int i = 1; i <= n; i ++) { printf("%d ", A[i]); } return 0; } /** test corner cases(n = 1?) watch for overflow or minus indices **/
#include<bits/stdc++.h> using namespace std; #define ll long long int #define ull unsigned long long int /**********************************************/ bool rec(set<char> s, map<char, vector<pair<int, int>>>& mp, vector<string>& num) { if (mp.empty()) { for (int i = 0; i < 3; i++) { if (num[i][0] == '0') return false; } ll a = stoll(num[0]); ll b = stoll(num[1]); ll c = stoll(num[2]); if (a + b == c) { cout << a << endl; cout << b << endl; cout << c << endl; return true; } else { return false; } } char currentChar = mp.begin()->first; auto v = mp.begin()->second; mp.erase(currentChar); vector<char> v1; for (auto& x : s) v1.push_back(x); for (auto& x : v1) { s.erase(x); for (auto& p : v) { int stringIndex = p.first; int charIndex = p.second; num[stringIndex][charIndex] = x; } if (rec(s, mp, num)) return true; s.insert(x); } mp[currentChar] = v; return false; } void solve(vector<string>& v) { if (v[2].size() < v[0].size() || v[2].size() < v[1].size()) { cout << "UNSOLVABLE" << endl; return; } map<char, vector<pair<int, int>>> mp; for (int i = 0; i < 3; i++) { for (int j = 0; j < v[i].size(); j++) { mp[v[i][j]].push_back({i, j}); } } if (mp.size() > 10) { cout << "UNSOLVABLE" << endl; return; } vector<string> num(3); for (int i = 0; i < 3; i++) { num[i] = ""; for (int j = 0; j < v[i].size(); j++) { num[i] += 'x'; } } set<char> s; for (char i = '0'; i <= '9'; i++) s.insert(i); if (!rec(s, mp, num)) { cout << "UNSOLVABLE" << endl; } } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); ll t = 1; // cin >> t; while (t--) { vector<string> v(3); for (int i = 0; i < 3; i++) { cin >> v[i]; } solve(v); } }
#include<iostream> #include<iomanip> #include<bitset> #include<algorithm> #include<string> #include<vector> #include<cstdio> #include<cmath> #include<queue> #include<map> #include<set> using namespace std; using ll=long long; int main(){ int N; string S; cin >> N >> S; N++; vector<int> A(N); for(int &x: A)cin >> x; int dmi = 1000000; for(int i = 1; i < N; i++){ int d = abs(A[i] - A[i - 1]); dmi = min (dmi, d); } cout << dmi << endl; for(int i = 0; i < dmi; i++){ vector<int> B(N, 0); for(int j = 0; j < N; j++){ B[j] = A[j] / dmi; if(dmi - i <= A[j] % dmi)B[j]++; } for(int j = 0; j < N; j++){ if(j < N - 1){ cout << B[j] << " "; continue; } cout << B[j] << endl; } } return 0; }
/* * author :Sadik Hassan(_sad_) * */ #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization ("unroll-loops") #include "bits/stdc++.h" using namespace std; using ll = long long; using ld = long double; #define nl "\n" #define pb push_back #define fi first #define se second #define MP make_pair #define PI (acos(-1.0)) #define rep1(i,n) for(int i=1;i<=n;i++) #define rep(i,n) for(int i=0;i<n;i++) #define urep(i,n) for(int i=n-1;i>=0;i--) #define urep1(i,n) for(int i=n;i>=1;i--) #define SZ(s) (int)s.size() #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define w(t) int t;cin>>t;while(t--) #define _SAD() ios::sync_with_stdio(0),cin.tie(0),cout.tie(0),cout<<fixed<<setprecision(2); typedef vector<int> vi; typedef vector<ll> vii; typedef set<int> si; typedef set<ll> sii; /*---------------------------------------------------------------------*/ const int N = (int)1e6; const int MOD =(int)1e9+7; const ll INF = (ll)1e18+5; int main() { _SAD() int n,l;cin>>n>>l; cout<<n/l<<nl; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #pragma GCC optimize("Ofast") #define watch(x) cout<<(#x)<<"="<<(x)<<'\n' #define mset(d,val) memset(d,val,sizeof(d)) #define setp(x) cout<<fixed<<setprecision(x) #define forn(i,a,b) for(int i=(a);i<(b);i++) #define fore(i,a,b) for(int i=(a);i<=(b);i++) #define pb push_back #define F first #define S second #define pqueue priority_queue #define fbo find_by_order #define ook order_of_key typedef long long ll; typedef pair<ll,ll> ii; typedef vector<ll> vi; typedef vector<ii> vii; typedef long double ld; template<typename T> using pbds = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; void amin(ll &a, ll b){ a=min(a,b); } void amax(ll &a, ll b){ a=max(a,b); } void YES(){cout<<"YES\n";} void NO(){cout<<"NO\n";} void SD(int t=0){ cout<<"PASSED "<<t<<endl; } const ll INF = ll(1e18); const int MOD = 998244353; const bool DEBUG = 0; const int MAXN = 100005; int main() { ios_base::sync_with_stdio(0); cin.tie(0); ll b,c; cin>>b>>c; vii v; v.pb({b,b-c/2}); //subtract only v.pb({-b,-b-(c-1)/2}); //flip then subtract v.pb({-b,-(b-(c-1)/2)}); //subtract then flip v.pb({b,(b+(c-2)/2)}); //flip, subtract, flip forn(i,0,v.size()) if(v[i].F>v[i].S) swap(v[i].F,v[i].S); sort(v.begin(), v.end()); ll ans=0,l=v[0].F,r=v[0].S; //for(ii tmp: v) cout<<tmp.F<<" "<<tmp.S<<'\n'; forn(i,1,v.size()) { if(v[i].F>r) { ans+=r-l+1; l=v[i].F, r=v[i].S; } else { r=max(r,v[i].S); } } ans+=r-l+1; cout<<ans<<'\n'; return 0; }
#include <bits/stdc++.h> // include every standard library #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 vector<int> vi; typedef vector<ll> vl; typedef vector<vi> vvi; typedef vector<vl> vvl; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef long double ld; typedef vector<bool> vb; typedef vector<vb> vvb; typedef vector<pll> vpll; typedef vector<pii> vpii; #define oset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> #define in() freopen("test.txt","r",stdin) #define out() freopen("output.txt","w",stdout) #define vt vector #define pb push_back #define eb emplace_back #define pob pop_back #define mk make_pair #define fi first #define se second #define nl "\n" #define MOD 1000000007 #define all(v) v.begin(),v.end() #define s(v) v.size() #define test ll t;cin>>t;while(t--) #define read0(v,n) for(int i=0;i<n;i++)cin>>v[i]; #define read1(v,n) for(int i=1;i<=n;i++)cin>>v[i]; #define trav(a,x) for (auto& a: x) #define fast ios_base::sync_with_stdio(false);cin.tie(NULL); #define cut(x) {cout<<x;return 0;} #define print(x) {cout<<x<<nl;} #define FOR(i,a,b) for(int i=a;i<b;++i) #define FORB(i,a,b) for(int i=a;i>=b;--i) #define err1(a) {cout<<#a<<' '<<a<<nl;} #define err2(a,b) {cout<<#a<<' '<<a<<' '<<#b<<' '<<b<<nl;} #define mem(a,b) memset(a,b,sizeof(a)) #define maxn 100000 #define dis(ar,n) {for(int i=0;i<(n);++i) cout << ar[i] << " "; cout << nl;} ll gcd(ll a, ll b){if (b==0)return a;return gcd(b, a % b);} ll lcm(ll a,ll b){return (a*b)/gcd(a,b);} ll bpow(ll a, ll b){ll ans=1;while(b){if(b&1)ans=(ans*a)%MOD;b/=2;a=(a*a)%MOD;}return ans;} vt<pair<int,int>> dir = {{1,0},{-1,0},{0,1},{0,-1}}; int main(){ fast ld a,b; cin >> a >> b; cout << a*(b/100.0) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; mt19937 rand_mt(42); const int N = 20; class Genome{ public: Genome(const vector<string>& S): sequences(S){ // auto dna = init_random(); auto dna = init_bf(); for(int i=0; i<N; i++){ dna_w[i] = dna[i]; for(int j=0; j<N; j++){ dna_h[j] += dna[i][j]; } } for(int i=0; i<N; i++){ dna_w[i] += dna_w[i]; dna_h[i] += dna_h[i]; } } array<string, N> init_random(){ auto dna = array<string, N>(); for(int i=0; i<N; i++){ for(int j=0; j<N; j++){ dna[i] += 'A' + rand_mt() % 8; } } return dna; } array<string, N> init_bf(){ auto dna = array<string, N>(); int i = 0; for(auto s : sequences){ for(int i=0; i<N; i++){ if(N - dna[i].size() < s.size()) continue; dna[i] += s; break; } } return dna; } int evaluate(){ const auto M = sequences.size(); int c = 0; for(auto s : sequences){ bool hasSeq = false; for(auto dw : dna_w){ if(dw.find(s) != string::npos){ hasSeq = true; break;} } if (hasSeq){ c++; continue;} for(auto dw : dna_h){ if(dw.find(s) != string::npos){ hasSeq = true; break;} } if (hasSeq){ c++; continue;} } int d = 0; auto dna = getDNA(); for(auto s : dna){ d += count(s.begin(), s.end(), '.'); } if(c < M){ return int(1e+8 * (c / (double) M)); }else{ return int(1e+8 * ((2 * N * N) / (double) (2 * N * N - d))); } } array<string, N> getDNA(){ auto dna = array<string, N>(); for(int i=0; i<N; i++){ dna[i] = dna_w[i].substr(0, 20); } return dna; } void print(){ auto dna = getDNA(); for(int i=0; i<N; i++){ cout << dna[i] << endl; } } public: array<string, N> dna_w; array<string, N> dna_h; const vector<string> sequences; }; int main() { int M; cin >> M >> M; vector<string> S(M, ""); for(int i=0; i<M; i++) cin >> S[i]; sort(S.begin(), S.end(), [](const string& s1, const string& s2){return s1.size() > s2.size();}); auto genome = Genome(S); genome.print(); // cerr << "score = "<< genome.evaluate() << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define R cin>> #define ll long long #define ln cout<<endl #define in(a) insert(a) #define pb(a) push_back(a) #define pd(a) printf("%.10f\n",a) #define mem(a) memset(a,0,sizeof(a)) #define all(c) (c).begin(),(c).end() #define iter(c) __typeof((c).begin()) #define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--) #define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++) #define rep(i,n) REP(i,0,n) #define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++) ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;} template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);} template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;} const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1}; typedef pair<ll,ll> P; vector<string> C(vector<string> s) { ll n=s.size(); rep(i,n)REP(j,i+1,n) swap(s[i][j],s[j][i]); return s; } ll n,m; string s[1000]; ll calc(vector<string> t) { ll cnt=0; rep(k,m) { ll f=0; rep(l,2) { rep(i,n) { rep(j,n) { if(t[i].substr(0,s[k].size())==s[k]) f=1; rotate(t[i].begin(),t[i].begin()+1,t[i].end()); } } t=C(t); } cnt+=f; } return cnt; } vector<string> ans; ll MM; void solve(vector<string> t) { ll d=calc(t); if(MM<d) { MM=d; ans=t; } rep(k,5) { random_shuffle(all(t)); rep(i,n) rotate(t[i].begin(),t[i].begin()+rand()%n,t[i].end()); ll d=calc(t); if(MM<d) { MM=d; ans=t; } } } void Main() { srand((unsigned)time(NULL)); cin >> n >> m; rep(i,m) R s[i]; vector<string> v[15]; rep(i,m) v[s[i].size()].pb(s[i]); rep(e,30) { vector<string> t(n); rrep(i,15) { random_shuffle(all(v[i])); rep(j,v[i].size()) { ll M=MAX,x=0; string rr; rep(k,n) { rep(l,t[k].size()+1) { string r1=t[k].substr(l); if(r1.size()<=v[i][j].size()) { string r2=v[i][j].substr(0,r1.size()); if(r1==r2) { ll d=t[k].size()+v[i][j].size()-r1.size(); if(d<=n&&M>d) { M=d; x=k; rr=t[k]+v[i][j].substr(r1.size()); } } } } } if(rand()%9==0) M=MAX; if(M!=MAX) t[x]=rr; } } rep(i,n) { while(t[i].size()<n) { //t[i]+='.'; t[i]+=(char)(rand()%8+'A'); } } solve(t); } rep(i,n) pr(ans[i]); } int main(){Main();return 0;}
#include <iostream> using namespace std; int main(void) { unsigned long long n, n1, m; cin >> n; n1 = n + 1; // n+1本目の残り長さ m = 1; // 最初に切る木の長さ = n+1本目の木で賄えた本数 - 1 while(true) if (n1 >= m) {//次の長さの木を賄えたら n1 -= m; //n+1本目の木を切る m++; //次に賄う木の長さ+1増加 = n+1本目の木で賄えた本数 + 1 } else break; cout << n + 2 - m << endl; return 0; }
#include <bits/stdc++.h> // #include <atcoder/all> #define rep(i,n) for(int i = 0; i < (n); ++i) #define srep(i,s,t) for(int i = s; i < t; ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) using namespace std; // using namespace atcoder; typedef long long int ll; typedef pair<int,int> P; #define yn {puts("Yes");}else{puts("No");} #define MAX_N 200005 int main() { ll n; cin >> n; ll l = 1, r = 2002002002; while(l+1<r){ ll m = (l+r) /2; if(m*(m+1)/2 <= n+1) l = m; else r = m; } ll ans = n+1 - l; cout << ans << endl; return 0; }
#include<iostream> #include<cstdio> #include<map> #include<bitset> #include<algorithm> #include<cmath> #include<cstring> #include<queue> #include<stack> #include<ctime> using namespace std; #define M 200005 #define N 1000005 #define MP make_pair #define debug() cerr<<"Why So Serious?"<<endl typedef long long ll; typedef unsigned long long ull; typedef double db; template<class T>void Rd(T &x){ x=0;static char c; while(c=getchar(),c<48); do x=(x<<1)+(x<<3)+(c^48); while(c=getchar(),c>47); } int n; int Id1[M],Id2[M]; int A[M],B[M]; bool cmp1(int a,int b){ return (A[a]==A[b])?a<b:A[a]<A[b]; } bool cmp2(int a,int b){ return (B[a]==B[b])?a<b:B[a]<B[b]; } int P[M]; int Sum[M]; void Add(int x){ for(;x>0;x-=x&-x)Sum[x]++; } int Query(int x){ int res=0; for(;x<=n;x+=x&-x)res+=Sum[x]; return res; } int main(){ Rd(n); for(int i=1;i<=n;++i)Id1[i]=Id2[i]=i; for(int i=1;i<=n;++i)Rd(A[i]),A[i]+=i; for(int i=1;i<=n;++i)Rd(B[i]),B[i]+=i; sort(Id1+1,Id1+n+1,cmp1); sort(Id2+1,Id2+n+1,cmp2); ll ans=0; for(int i=1;i<=n;++i){ if(A[Id1[i]]!=B[Id2[i]]){ puts("-1"); return 0; } P[Id1[i]]=Id2[i]; } for(int i=1;i<=n;++i){ ans+=Query(P[i]); Add(P[i]); } printf("%lld\n",ans); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n,m,a[2200000],mex,nums[2200000]; vector<int> v; cin >> n >> m; for(int i=0; i<n; i++) { cin >> a[i]; if(i<m) v.push_back(a[i]); } sort(v.begin(),v.end()); int now=0; bool ok=true; for(int i=0; i<m; i++){ if(v[i] == now) now++; if(v[i] > now && ok) { mex = now; ok=false; } nums[v[i]]++; } if(ok) mex = now; for(int i=0; i<n-m; i++){ nums[a[i]]--; nums[a[i+m]]++; if(a[i] < mex && nums[a[i]]==0) mex = a[i]; } cout << mex; }
#include <bits/stdc++.h> using namespace std; #define stp(var, init, end) for (auto var = init; var < end; ++var) #define stpe(var, init, end) for (auto var = init; var <= end; ++var) #define stpi(iter, array) for (auto iter = array.begin(); iter != array.end(); ++iter) #define ll long long int main(void) { int a, b, c; cin >> a >> b >> c; cout << max(max(a + b, b + c), c + a); return 0; }
#include<bits/stdc++.h> using namespace std; int a,b,c; int main() { cin>>a>>b>>c; if(a==b)cout<<c; else if(b==c)cout<<a; else if(a==c)cout<<b; else cout<<0; return 0; }
#include<bits/stdc++.h> #define ll long long int #define mk make_pair #define pb push_back #define INF (ll)1e18 #define pii pair<ll,ll> #define mod 998244353 #define f(i,a,b) for(ll i=a;i<b;i++) #define fb(i,a,b) for(ll i=a;i>b;i--) #define ff first #define ss second #define srt(v) if(!v.empty())sort(v.begin(),v.end()) #define rev(v) if(!v.empty())reverse(v.begin(),v.end()) #define PI 3.141592653589793238 #define pqr priority_queue<ll,vector<ll>,greater<ll>()> using namespace std; ll pow_mod(ll a,ll b) { ll res=1; while(b!=0) { if(b&1) { res=(res*a)%mod; } a=(a*a)%mod; b/=2; } return res; } ll inv_mod(ll x){ return pow_mod(x,mod-2); } const ll N=(ll)3e5; ll inv[N]; ll fac[N]; void init(){ fac[0]=1; for(ll i=1;i<N;i++) fac[i]=(i*fac[i-1])%mod; for(ll i=0;i<N;i++) inv[i]=inv_mod(fac[i]); } ll ncr(ll n,ll r){ if(n<r) return 0; if(n==r||r==0) return 1LL; ll x=fac[n]; ll y=inv[n-r]; ll z=inv[r]; return ((x*y)%mod*z)%mod; } ll n; void solve(ll test_case) { string s; cin>>s; s.pb(s[0]); s.erase(0,1); cout<<s<<endl; } int main() { // init(); //factorial calculations //Start from Here. ll t; t=1; ll q; // cin>>t>>n>>q; for(ll i=1;i<=t;i++) solve(i); //Good Bye! return 0; }
#include <iostream> #include <iomanip> #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 <cmath> #include <valarray> #include <cstdlib> #include <array> #include <random> #include <stdio.h> #include <stdlib.h> using namespace std; #define rep(i,a,n) for(int i=(a);i<(n);i++) #define ll long long #define sort(A) sort(A.begin(), A.end()) #define zisyo(v) next_permutation(begin(v),end(v)) #define check(i) cout<<"*"<<i<<endl #define vec(a) vector<a> #define vvec(a) vector<vector<a>> #define keta(a) setprecision(a) //最小公倍数はこれ→ (a*b / gcd(a,b)) //最大公約数 int gcd(int x, int y) { int m = min(x, y); for (int d = m; d > 0; d--) { if (x % d == 0 && y % d == 0) { return d; } } } //各桁の和 ll ketawa(ll n) { ll sum = 0; while (n > 0) { sum += n % 10; n /= 10; } return sum; } //回文判定 bool KIBN(string s) { rep(i, 0, s.size() / 2) { if (s[i] != s[s.size() - 1 - i])return false; } return true; } //素数判定 bool IsPrime(int num) { if (num < 2) return false; else if (num == 2) return true; else if (num % 2 == 0) return false; double sqrtNum = sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) { return false; } } return true; } int main(void) { char a, b, c; cin >> a >> b >> c; cout << b << c << a << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; // #pragma GCC optimize("O2") typedef long long int ll; typedef long double ld; typedef map <ll,ll> mm; typedef vector <ll> mv; typedef pair <ll,ll> mp; typedef set <ll> ms; typedef multiset <ll> mms; typedef queue <ll> mq; typedef deque <ll> mdq; typedef stack <ll> mst; typedef priority_queue <ll> mpq; typedef priority_queue <ll, vector<ll>, greater<ll> > mmh; typedef complex<double> cd; #define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> #define ordered_multiset tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> #define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define flush cout.flush(); #define all(v) v.begin(),v.end() #define deb(x) cout << #x << " " << x << endl; #define ff first #define ss second #define pb(v) push_back(v) #define lb(v) lower_bound(v) #define ub(v) upper_bound(v) #define cn continue #define forl(i,n) for(ll i=0;i<n;i++) #define forlr(i,n) for(ll i=n-1;i>=0;i--) #define rev(s) reverse(s.begin(),s.end()) void swap(ll &a,ll &b) { ll tmp=a; a=b; b=tmp; } ll atoistring(string s) { stringstream lol(s); ll x; lol>>x; return x; } void pv(mv v) { forl(i,v.size()) cout<<v[i]<<" "; cout<<"\n"; } void pa(ll *v, ll size) { forl(i,size) cout<<v[i]<<" "; cout<<"\n"; } void removeDups(mv &v) { sort(all(v)); mv::iterator it = unique(v.begin(), v.end()); v.resize(distance(v.begin(), it)); } inline ld kthRoot(ld n, ll k) { return pow(k, (1.0 / k) * (log(n) / log(k))); } ll power(ll x, ll y, ll p) { ll res=1; x=x%p; while(y>0) { if(y&1) res = (res*x)%p; y=y>>1; x=(x*x)%p; } return res; } void checkmod(ll &x, ll mod) { if(x>=mod) x%=mod; } ll mod = 1e9 + 7; ll arr[102]; unordered_map < ll , ll > facs; vector < mp > ans; void hashIt(ll x) { ll v = sqrt(x); for(ll i=2;i<=v;i++) { if(x % i == 0) { facs[i] ++ ; while(x % i == 0) x /= i; } } if(x > 1) facs[x] ++ ; } void thisIsMain() { facs.clear(); ans.clear(); ll n; cin>>n; forl(i,n) cin>>arr[i]; forl(i,n) hashIt(arr[i]); for(auto v : facs) ans.push_back({v.ss, v.ff}); sort(all(ans)); // forl(i,ans.size()) cout<<ans[i].ff<<" "<<ans[i].ss<<"\n"; cout<<ans.back().ss<<"\n"; } int main(void) { fastio ll t = 1; // cin>>t; while(t--) thisIsMain(); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) using ll = long long; using P = pair<int,int>; int main() { int n; cin >> n; vector<int> a(n); int ma=0; rep(i,n){ cin>>a[i]; ma = max(a[i],ma); } int ans=0; int index; for (int i = 2; i <= ma; i++) { /* code */ int sum=0; for (int j = 0; j < n; j++) { if(a[j]%i ==0) sum++; } if(ans<=sum) { ans = sum; index = i; } } cout<<index<<endl; return 0; }
#include <iostream> #include <cstdio> #include <vector> #include <algorithm> #include <set> using namespace std; const int N = 500005; char s[N], e[N]; vector<int> v[2]; vector<int> df; int t[N]; int n; int lowbit(int x){ return x & -x; } void add(int x, int w){ while(x <= n){ t[x] += w; x += lowbit(x); } } int query(int x){ int res = 0; while(x){ res += t[x]; x -= lowbit(x); } return res; } int main(){ scanf("%d", &n); scanf("%s", s); scanf("%s", e); bool flag = 1; int ans = 0; for(int i = 1; i <= n; i++){ if(s[i - 1] == '0') add(i, 1); if(s[i - 1] != e[i - 1]){ v[s[i - 1] - '0'].push_back(i); df.push_back(i); } } df.push_back(n + 1); if(v[0].size() != v[1].size()) printf("-1\n"); else{ int l = df[0], mt = 0; for(int i = 0; i < df.size(); i++){ if(s[df[i] - 1] == '0') mt--; else mt++; // cout << mt << endl; if(mt == 0){ ans += query(df[i]) - query(l - 1); l = df[i + 1]; } } printf("%d\n", ans); } return 0; }
// #pragma GCC optimize("Ofast,unroll-loops") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") #include <bits/stdc++.h> #define ll long long int #define vi vector<int> #define vvi vector<vector<int>> #define vll vector<long long> #define vs vector<string> #define vc vector<char> #define vb vector<bool> #define forn(i, s, n) for(ll i=(ll)s; i<(ll)(n); i++) #define all(c) c.begin(),c.end() #define pb push_back #define pll pair<long long int, long long int> #define pii pair<int, int> #define lld long double #define F first #define S second #define PI 3.141592653589793238 #define prec(n) fixed<<setprecision(n) #define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr) #define itsval(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); itval(_it, args); } using namespace std; // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; void itval(istream_iterator<string> it) {} template<typename T, typename... Args> void itval(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; itval(++it, args...); } const ll MOD = 1e9 + 7; template <typename T> inline void print(T x) {cout << x << "\n";} template <typename T> inline void printvec(T x) {for (auto a : x)cout << a << ' '; cout << '\n';} // ----------------------------------------------------------------------- struct custom { bool operator()(const pair<pll, ll> &p1, const pair<pll, ll> &p2)const { if (p1.S == p2.S) { return p1.F.F > p2.F.F; } return p1.S < p2.S; } }; // Calculate a^b % MOD ------------------------------------------------- ll get_pow(ll a, ll b, ll M = MOD) { ll res = 1; while (b) { if (b & 1) res = (res * a) % M; a = (a * a) % M; b >>= 1; } return res; } // --------------------------------------------------------------------- const ll N = 2e5 + 5, inf = 2e18; void solve() { ll N, P; cin >> N >> P; ll ans = (P - 1); ans = ans * get_pow(P - 2, N - 1) % MOD; cout << ans << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int test = 1; clock_t z = clock(); //cin >> test; forn(tes, 0, test) { solve(); } debug("Total Time:%.4f\n", (double)(clock() - z) / CLOCKS_PER_SEC); return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll MOD = 1000000007; int main(){ int n; cin>>n; vector<ll> lista(n+1); for(int i = 1; i<=n; i++){ cin>>lista[i]; } vector<vector<ll> > dp(n+1, vector<ll>(n+1, 0)); for(int i = 1; i<=n; i++){ dp[i][1] = 1; } for(int i = 2; i<=n; i++){ vector<ll> resto(i, 0); ll sum = 0; for(int j = 1; j<=n; j++){ sum = (sum + lista[j])%i; dp[j][i] = (dp[j][i] + resto[sum%i])%MOD; resto[sum%i] = (resto[sum%i] + dp[j][i-1])%MOD; } } ll res = 0; for(int i = 1; i<=n; i++){ res = (res + dp[n][i])%MOD; } cout<<res<<"\n"; return 0; }
#include <bits/stdc++.h> using ll=long long; using ld=long double; #define rep(i,n) for(int i=0;i<n;i++) using namespace std; ll p=998244353; vector<ll> a(200100); vector<ll> b(200100); ll powk(ll k,ll n){ ll ans=1,m=k; while(n){ if(n%2) ans=ans*m%p; m=m*m%p; n/=2; } return ans; } void comb1(){ a[0]=1; for(ll i=1;i<200100;i++) a[i]=a[i-1]*i%p; rep(i,200100) b[i]=powk(a[i],p-2); return; } ll comb(int n,int k){ ll ans=a[n]*b[n-k]%p*b[k]%p; return ans; } int main(){ comb1(); ll n,m; cin >> n >> m; ll ans=1; for(int i=2;i<=m;i++){ int j=i,x=2; ll y=1; while(x*x<=i){ int k=0; while(j%x==0){ j/=x; k++; } y*=comb(n+k-1,k); y%=p; x++; } if(1<j) y=y*n%p; ans=(ans+y)%p; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main(void) { char c1, c2, c3; cin >> c1 >> c2 >> c3; if ((c1 == c2) && (c2 == c3)) cout << "Won" << endl; else cout << "Lost" << endl; return 0; }
// 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); ll a,b,c,d; cin>>a>>b>>c>>d; print(b-c) return 0; }
/** * 問題順: D * 問題名: Base n * 実行時間制限: 2 sec * メモリ制限: 1024 MB * 配点: 400点 * URL: https://atcoder.jp/contests/abc192/tasks/abc192_d * 最終結果: WA * 問題分類: 数学, 数え上げ * アルゴリズム: 二分探索 */ #include<iostream> using namespace std; using ll = long long; string X; ll M; bool isOK(ll d) { ll x=0,tM=M; int i; int Mlen=0; while(tM>0) { Mlen++; tM/=d; } if (Mlen<X.size()) return false; for (i=0;i<X.size() && x<=M;i++) { x *= d; x += (X[i]-'0'); } return x<=M; } int main() { int i; cin>>X>>M; int maxD=0; for (i=0;i<X.size();i++) { maxD = max(maxD, (int)(X[i]-'0')); } ll ans=0; ll ok = maxD+1, ng=1e18; ng++; if (X.size()>1) { if (isOK(ok)) { while (abs(ok - ng) > 1) { ll mid = (ok + ng) / 2; if (isOK(mid)) ok = mid; else ng = mid; } ans = ok-maxD; } } else { ans = isOK(ok) ? 1 : 0; } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> typedef long long ll; using namespace std; int sum_digit(int n){ int res = 0; while(n){ res += n%10; n /= 10; } return res; } int main() { ios::sync_with_stdio(0); cin.tie(0); int a, b; cin >> a >> b; int x = sum_digit(a); int y = sum_digit(b); cout << (x > y ? x : y) ; cout << endl; return 0; }
#include <bits/stdc++.h> #ifdef _DEBUG #include "_DEBUG.hpp" #endif #define int long long using namespace std; using P = pair<int, int>; const int inf = 2e18; const int mod = 1e9 + 7; template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; } 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 <class T, class V> typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) { t = v; } template <class T, class V> typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v) { for (auto &e : t) fill(e, v); } bool kaibun(string s) { bool ok = true; for (int i = 0; i < s.size() / 2; i++) { if (s[i] != s[(int)s.size() - 1 - i]) ok = false; } return ok; } signed main() { string s; cin >> s; bool ok = false; for (int i = 0; i < 99; i++) { string t = s; for (int j = 0; j < i; j++) { t.insert(0, "0"); } if (kaibun(t)) { ok = true; break; } } cout << (ok ? "Yes" : "No") << endl; return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; while(n!=0&&n%10==0){ n/=10; } int k=0; int o=n; while(o!=0){ k*=10; k+=(o%10); o/=10; } if(k==n){ cout << "Yes" << endl; }else{ cout << "No" << endl; } return(0); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #ifdef APURBA #include "DEBUG_TEMPLATE.h" #define HERE cout<<"here - "<<__LINE__<<"\n"; #define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); } #else #define HERE #define debug(args...) #endif const int N = 1e5 +5; const ll mod = 1e9+7; typedef pair<int,int> pii; bool issub(int i, int j , string &s1, string &s2) { if(j==s2.size()) { return 1; } if(i==s1.size() || j==s2.size()) { return 0; } if(s1[i]== s2[j]) { return issub(i+1, j+1 , s1, s2); } else{ return issub(i+1 , j , s1, s2); } } void TEST_CASES(int cas) { int n; string s1,s2,s3; cin>>n>>s1>>s2>>s3; s1+=s1; s2+=s2; s3+=s3; debug(s1,s2,s3); string ans; for(int i=0;i<n;i++) { ans+="0"; } for(int i=0;i<n;i++) { ans+="1"; } ans+="0"; debug(ans); if(issub(0,0,s1,ans) && issub(0,0,s2,ans)&&issub(0,0,s3,ans)) { cout<<ans<<"\n"; return; } ans.pop_back(); ans+="1"; debug(ans); if(issub(0,0,s1,ans) && issub(0,0,s2,ans)&&issub(0,0,s3,ans)) { cout<<ans<<"\n"; return; } ans.clear(); for(int i=0;i<n;i++) { ans+="1"; } for(int i=0;i<n;i++) { ans+="0"; } ans+="0"; debug(ans); if(issub(0,0,s1,ans) && issub(0,0,s2,ans)&&issub(0,0,s3,ans)) { cout<<ans<<"\n"; return; } ans.pop_back(); ans+="1"; debug(ans); if(issub(0,0,s1,ans) && issub(0,0,s2,ans)&&issub(0,0,s3,ans)) { cout<<ans<<"\n"; return; } } /* */ int32_t main() { #ifndef APURBA ios_base::sync_with_stdio(false); cin.tie(nullptr); #endif //freopen("input.txt","r",stdin); //freopen("out1.txt","w",stdout); int t=1,cas=0; cin>>t; while(t--) { TEST_CASES(++cas); } return 0; }
#include<bits/stdc++.h> const int N=1e5+100; using namespace std; int n; void run(){ cin>>n; string a,b,c; cin>>a>>b>>c; for(int i=1;i<=n;i++)cout<<0; for(int i=1;i<=n;i++)cout<<1; cout<<0<<endl; } int main(){ int T;cin>>T; while(T--) run(); }
#include <bits/stdc++.h> #define ar array #define ll long long #define endl '\n' using namespace std; const int MAX_N = 1e5 + 1; const ll MOD = 1e9 + 7; const ll INF = 1e9; int MAX = INT_MAX; long long LMAX = LONG_LONG_MAX; vector<vector<int>> a; bool check[2000]; void dfs(int c) { if(check[c]) return; check[c] = true; for(auto it:a[c]) { dfs(it); } } void solve() { int n, m; cin >> n >> m; a.resize(n); for(int i=0; i<m; i++) { int x,y; cin >> x >> y; a[x-1].push_back(y-1); } int ans=0; for(int i=0; i<n; i++) { for(int j=0; j<n; j++) check[j] = false; dfs(i); for(int j=0; j<n; j++) if(check[j]) ans++; } cout << ans << endl; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tc = 1; // cin >> tc; while(tc--) { // cout << "Case #" << t << ": "; solve(); } }
#include <bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; vector<tuple<int,int,int>> a; int b[4][2] = {{0,0},{0,-1},{1,0},{1,-1}}; for(int i = 0; i< n;i++){ int type; cin >> type; int inp1,inp2; cin >> inp1 >> inp2; a.push_back(make_tuple(type,inp1,inp2)); } int cnt = 0; for(int i = 0;i < n;i++){ for(int j = i + 1;j < n;j++){ if(get<2>(a.at(i)) < get<1>(a.at(j)) || get<2>(a.at(j)) < get<1>(a.at(i)) || (get<2>(a.at(i)) == get<1>(a.at(j)) && (get<0>(a.at(i)) == 2 || get<0>(a.at(i)) == 4 || get<0>(a.at(j)) == 3 || get<0>(a.at(j)) == 4)) || (get<2>(a.at(j)) == get<1>(a.at(i)) && (get<0>(a.at(i)) == 3 || get<0>(a.at(i)) == 4 || get<0>(a.at(j)) == 2 || get<0>(a.at(j)) == 4)) ){ continue; } cnt++; } } cout << cnt; }
#include <bits/stdc++.h> using namespace std; //#pragma GCC optimize("O3") #define DIM 200009 #define INF ((long long)1e18+9ll) #define pairll pair<long long,long long> #define fi first #define se second #define ld long double #define amen exit(0) #define endl '\n' #define MODULO 998244353 #define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0) long long i,j,k,l,n,m; string a,b; int main() { fast; int nt; cin>>nt; while(nt--){ a="atcoder"; cin>>b; if(a<b)cout<<0<<endl; else{ long long res=INF; long long pos=-1; for(int i=0;i<b.size();i++){ if(b[i]!='a'){ pos=i+1; break; } } if(pos==-1)cout<<-1<<endl; else{ if(b[pos-1]>'t')cout<<pos-2<<endl; else cout<<pos-1<<endl; } } } amen; }
#define _CRT_SECURE_NO_WARNINGS #include<iostream> #include<sstream> #include<cstdio> #include<cstdlib> #include<cstring> #include<climits> #include<cmath> #include<string> #include<vector> #include<set> #include<map> #include<queue> #include<numeric> #include<functional> #include<algorithm> #include<bitset> #include<tuple> #include<unordered_set> #include<unordered_map> #include<random> #include<array> #include<cassert> using namespace std; #define INF ((1<<30)-1) #define rep(i,n) for(int i=0;i<(int)(n);i++) #define all(v) v.begin(),v.end() int main() { ios::sync_with_stdio(0); cin.tie(0); int T; cin >> T; rep(_, T) { string s; cin >> s; string t = s; sort(all(t)); reverse(all(t)); if (t <= "atcoder") { cout << -1 << endl; continue; } int ans = INF; int cur = 0; rep(i, 7) { int idx = -1; for (int j = i; j <= s.size(); j++) { if ("atcoder"[i] < s[j]) { ans = min(ans, cur + j - i); } else if ("atcoder"[i] == s[j] && idx == -1) { idx = j; } } if (idx == -1)break; cur += idx - i; for (int j = idx - 1; j >= i; j--) { s[j + 1] = s[j]; } s[i] = "atcoder"[i]; } if (s.size() > 7 && s.substr(0, 7) == "atcoder")ans = min(ans, cur); cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define pb push_back #define int long long template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<vi> vvi; const int inf = 1e9; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; signed main() { double a,b; cin >> a >> b; if(a==b){ cout << a << endl; }else { cout << 3-a-b << endl; } return 0; }
#include <bits/stdc++.h> #define x first #define y second using namespace std; typedef pair<int, int> PII; typedef pair<double, double> PDD; typedef long long LL; typedef unsigned long long ULL; int main() { int a, b; cin >> a >> b; cout << 1.0 * (a - b) / a * 100 << endl; return 0; }
#include "bits/stdc++.h" #define REP(i,num) for(ll i=0;i<(num);++i) #define FOR(i,c,num) for(ll (i)=(c);(i)<(num);++(i)) #define LOOP(i) while(i--) #define ALL(c) c.begin(),c.end() #define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl; #define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;} using namespace std; using ll = long long; using vll = vector<ll>; using vvll = vector<vector<ll>>; constexpr ll atcoder_mod = 1e9+7; template<typename T=ll> T in(){ T x; cin >> x; return (x); } template<typename T=ll,typename C=vector<T>> C vecin(int N){ C x(N);REP(i,N){ x[i]=in<T>(); }return x; } void vout(){ cout << endl; } template<typename Head,typename... Tail> void vout(Head&& h,Tail&&... t){ cout << ' ' << h;vout(forward<Tail>(t)...); } void out(){ cout << endl; } template<typename Head,typename... Tail> void out(Head&& h,Tail&&... t){ cout << h;vout(forward<Tail>(t)...); } template<typename T> bool chmax(T& a,T b){ if(a<b){ a=b;return true; }return false; } template<typename T> bool chmin(T& a,T b){ if(a>b){ a=b;return true; }return false; } class Data{ public: ll X,Y,Z; }; int main(){ cin.tie(0); ios::sync_with_stdio(false); cout<<fixed<<setprecision(10); auto N=in(); vector<Data> D(N); REP(i,N){ D[i].X=in(); D[i].Y=in(); D[i].Z=in(); } ll L = 1ll<<N; vvll dp(L,vll(N,1ll<<60)); dp[0][0] = 0; REP(i,L){ REP(j,N){ REP(k,N){ ll to = i | (1ll<<k); ll C = abs(D[j].X-D[k].X)+abs(D[j].Y-D[k].Y)+max(0ll,D[k].Z-D[j].Z); chmin(dp[to][k],dp[i][j]+C); } } } out(dp[L-1][0]); return 0; }
#include <bits/stdc++.h> using namespace std; #define M_PI 3.14159265358979323846 #define MOD 1000000007 typedef long long ll; typedef vector<int> vint; typedef vector<vint> vvint; typedef vector<ll> vll; typedef vector<vll> vvll; typedef pair<int, int> ipair; typedef pair<ll, ll> llpair; /* Author: Koushik Sahu Created: 03 April 2021 Sat 22:14:58 */ const int nxM = 105; int h, w, x, y; string s[nxM]; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); cin>>h>>w>>x>>y; for(int i=0; i<h; i++) cin>>s[i]; x--, y--; int ans = 1; for(int i=x+1; i<h; i++){ if(s[i][y]=='.') ans++; else break; } for(int i=x-1; i>=0; i--){ if(s[i][y]=='.') ans++; else break; } for(int i=y+1; i<w; i++){ if(s[x][i]=='.') ans++; else break; } for(int i=y-1; i>=0; i--){ if(s[x][i]=='.') ans++; else break; } cout<<ans<<"\n"; return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int n,k,m; cin>>n>>k>>m; vector<int> v(n-1); int l=0; for(int i=0;i<n-1;i++){ cin>>v[i]; l+=v[i]-m; } l-=m; if(l>=0) cout<<0<<endl; else if(-1*l<=k) cout<<-1*l<<endl; else cout<<-1<<endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n, k, m; scanf("%d%d%d", &n, &k, &m); int sum = 0; for (int i = 0; i < n-1; i++) { int x; scanf("%d", &x); sum += x; } for (int i = 0; i <= k; i++) { if ((sum + i) / n >= m) { return !printf("%d\n", i); } } printf("-1\n"); }
#include <bits/stdc++.h> using namespace std; int main(){ int x; cin>>x; for(int i= 1; i<=1001; i++){ if(i*100 > x){ cout<<i*100-x; break; } } return 0; }
#include<bits/stdc++.h> using namespace std; # define ll long long # define read read1<ll>() # define Type template<typename T> Type T read1(){ T t=0; char k; bool vis=0; do (k=getchar())=='-'&&(vis=1);while('0'>k||k>'9'); while('0'<=k&&k<='9')t=(t<<3)+(t<<1)+(k^'0'),k=getchar(); return vis?-t:t; } # define fre(k) freopen(k".in","r",stdin);freopen(k".out","w",stdout) ll n; int main(){ n=read;ll v=9e18,x=0; for(ll i=0;i<62;++i) if((n>>i)+i+(n&(1ll<<i)-1)<v) v=(n>>i)+i+(n&(1ll<<i)-1),x=i; cout<<v; return 0; }
#include <bits/stdc++.h> long long c[61][61]; using namespace std; int main(){ c[0][0]=1; for(int i=1;i<=60;i++){ c[i][0]=1; for(int j=1;j<=i;j++){ c[i][j]=c[i-1][j-1]+c[i-1][j]; } } int a,b; long long k; cin>>a>>b>>k; int n=a+b; for(int i=1;i<=n;i++){ if(c[n-i][b]>=k){ cout<<'a'; a--; } else{ cout<<'b'; k-=c[n-i][b]; b--; } } return 0; }
#include <algorithm> #include <iostream> #include <numeric> #include <string> #include <tuple> #include <utility> #include <vector> #define rep(i, a, b) for (int i = int(a); i < int(b); i++) using namespace std; using ll = long long int; using P = pair<ll, ll>; // clang-format off #ifdef _DEBUG_ #define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; debug_print(__VA_ARGS__); } while(false) template<typename T, typename... Ts> void debug_print(const T &t, const Ts &...ts) { cerr << t; ((cerr << ", " << ts), ...); cerr << endl; } #else #define dump(...) do{ } while(false) #endif template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); } template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); } template<typename T> bool chmin(T &a, const T& b) { if (a > b) {a = b; return true; } return false; } template<typename T> bool chmax(T &a, const T& b) { if (a < b) {a = b; return true; } return false; } template<typename T, typename... Ts> void print(const T& t, const Ts&... ts) { cout << t; ((cout << ' ' << ts), ...); cout << '\n'; } template<typename... Ts> void input(Ts&... ts) { (cin >> ... >> ts); } template<typename T> istream &operator,(istream &in, T &t) { return in >> t; } // clang-format on int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int a, b; ll k; input(a, b, k); auto comb = make_v(100, 100, 0LL); auto nCr = [&](auto &f, int n, int r) -> ll { if (r == 0 || n == r) { return 1; } if (comb[n][r] > 0) return comb[n][r]; return comb[n][r] = f(f, n - 1, r) + f(f, n - 1, r - 1); }; string ans = ""; int n = a + b; rep(i, 0, n) { if (a > 0) { ll cnt = nCr(nCr, a + b - 1, b); dump(k, cnt, a, b); if (k > cnt) { k -= cnt; ans += 'b'; b--; } else { ans += 'a'; a--; } } else { ans += 'b'; k--; b--; } } print(ans); return 0; }
#include <iostream> #include <map> #include <vector> #include <set> #include <stack> #include <bitset> #include <queue> #include <algorithm> #include <iomanip> #include <unordered_map> #include <unordered_set> #include <cmath> #include <cassert> #include <random> using namespace std; void solve(); int main() { #ifdef DEBUG freopen("input.txt", "r", stdin); #endif srand(time(0)); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); return 0; } #define int long long const int N = 101, A = 2e5 + 100, INF = 1e18; int n, ans; string f, s; void solve() { cin >> n >> f >> s; vector < int > a, b; for (int i = s.size() - 1; i >= 0; i--) { if (s[i] == '1') a.push_back(i); } for (int i = 0; i < f.size(); i++) { if (f[i] == '0') continue; if (a.empty() || a.back() > i) b.push_back(i); else { ans += i - a.back(); a.pop_back(); } } if (b.size() % 2 == 1 || !a.empty()) { cout << -1; return; } for (int i = 0; i < b.size(); i += 2) { ans += b[i + 1] - b[i]; } cout << ans; }
#include <bits/stdc++.h> #ifndef ONLINE_JUDGE #define _GLIBCXX_DEBUG #endif using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = s; i < (int)(n); i++) #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define vec vector #define rip return 0 typedef long long ll; typedef pair<ll,ll> P; ll max(ll x,ll y){ if(x>y)return x; else return y; } ll min(ll x,ll y){ if(x<y)return x; else return y; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cout<<fixed<<setprecision(12); /*-------------------------------------------*/ ll r,x,y; cin>>r>>x>>y; double eu=sqrt(x*x+y*y); ll ans=eu/r; if(r*ans==eu)cout<<ans<<endl; else if(eu>2*r) cout<<ans+1<<endl; else cout<<2<<endl; }
#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> #include <unordered_set> using namespace std; // #pragma GCC optimize("O3") // #pragma GCC optimize("unroll-loops") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") // #pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl") using ll = long long; 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; } int sx, sy, gx, gy; ll score; inline void query(){ cin >> sx >> sy >> gx >> gy; } string get_str(){ string res = ""; while(sx < gx) { res += 'D'; ++sx; } while(sx > gx) { res += 'U'; --sx; } while(sy < gy) { res += 'R'; ++sy; } while(sy > gy) { res += 'L'; --sy; } return res; } inline void output(string s){ cout << s << endl; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); for(int i = 0; i < 1000; ++i){ query(); output(get_str()); cin >> score; } return 0; }
//#include <atcoder/all> //using namespace atcoder; #include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i, n) for(int i=0; i<n; i++) #define REPR(i, n) for(int i=n-1; i>=0; i--) #define FOR(i, m, n) for(int i=m; i<n; i++) #define ALL(v) v.begin(), v.end() #define bit(n) (1LL<<(n)) #define FIX(d) fixed << setprecision(d) using P = pair<int, int>; using LP = pair<ll, ll>; using vvi = vector<vector<int>>; using vvl = vector<vector<ll>>; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const int INF = 1e9; const ll LINF = (1LL<<60); int di[] = {-1, 1, 0, 0}; int dj[] = {0, 0, -1, 1}; const int H = 30, W = 30; struct edge { int to; int cost; edge(int _to, int _cost){ to = _to; cost = _cost; } }; using Graph = vector<vector<edge>>; // 経路復元用 vector<ll> dijkstra(int s, const Graph &G, vector<int> &prev) { int n = G.size(); priority_queue<P, vector<P>, greater<P>> que; vector<ll> d(n, INF); prev.resize(n, -1); d[s] = 0; que.emplace(0, s); while (!que.empty()){ P p = que.top(); que.pop(); int v = p.second; if (d[v] < p.first) continue; for(auto nv: G[v]){ if (d[nv.to] > d[v] + nv.cost){ d[nv.to] = d[v] + nv.cost; prev[nv.to] = v; que.emplace(d[nv.to], nv.to); } } } return d; } string get_path(const vector<int> &prev, int t) { vector<int> path; for (int cur = t; cur != -1; cur = prev[cur]) { path.push_back(cur); } reverse(path.begin(), path.end()); string pathString = ""; REP(i,path.size()-1){ if(path[i]-path[i+1]==1) pathString.push_back('L'); else if(path[i]-path[i+1]==-1) pathString.push_back('R'); else if(path[i]-path[i+1]==W) pathString.push_back('U'); else pathString.push_back('D'); } return pathString; } void init(Graph &G){ REP(i,H) REP(j,W){ int cur = i*W+j; REP(k,4){ int ni = i+di[k]; int nj = j+dj[k]; if(ni<0 || ni>=H || nj<0 || nj>=H) continue; int next = ni*W+nj; G[cur].push_back(edge(next, 1000)); G[next].push_back(edge(cur, 1000)); } } } int main() { Graph G(H*W); init(G); REP(q,1000){ int si, sj, ti, tj; cin >> si >> sj >> ti >> tj; int sp = si*W+sj; int tp = ti*W+tj; vector<int> prev; auto dist = dijkstra(sp, G, prev); string path = get_path(prev, tp); cout << path << endl; int score; cin >> score; int score_per = score / path.size(); int cur = tp; while(cur!=sp){ int next = prev[cur]; for(auto &eg: G[cur]){ if(eg.to!=next) continue; //chmax(eg.cost, score_per); eg.cost = score_per; } for(auto &eg: G[next]){ if(eg.to!=cur) continue; //chmax(eg.cost, score_per); eg.cost = score_per; } cur = next; } } return 0; }
#include <bits/stdc++.h> typedef long long int ll; using namespace std; #define P 998244353 #define rep(i,n) for(i=0;i<n;++i) #define re(i,a,n) for(i=a;i<=n;++i) #define repr(i,a,n) for(i=a;i>=n;--i) #define pb push_back #define mp make_pair #define fi first #define se second ll binpow(ll x, ll y, ll p) { ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res*x) % p; y = y>>1; x = (x*x) % p; } return res; } ll modInverse(ll n, ll p) { return binpow(n, p-2, p); } /*const ll MAXN=4e6+1; ll spf[MAXN]; void sieve() { spf[1] = 1; ll i,j; for (i=2; i<MAXN; i++) spf[i] = i; for (i=4; i<MAXN; i+=2) spf[i] = 2; for (i=3; i*i<MAXN; i++) { if (spf[i] == i) { for (j=i*i; j<MAXN; j+=i) if (spf[j]==j) spf[j] = i; } } } */ int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll m,n,i,f=0,j,ans=0,k,x,r,l,t,y,h,w; cin >> h >> w >> n >> m ; set<ll> s; ll a[h][w]; ll used[h][w]; rep(i,h) { rep(j,w){ a[i][j]=0; used[i][j]=0;} } vector<vector<ll>> row(h),col(w),rowb(h),colb(w); rep(i,n) { cin >> x >> y ; x--; y--; a[x][y]=1; } rep(i,m) { cin >> x>> y ; x--; y--; a[x][y]=-1; } rep(i,h) { f=0; rep(j,w) { if(a[i][j]==1) { f=1; } else if(a[i][j]==-1) f=-1; if(f==1) used[i][j]=1; } } rep(i,h) { f=0; rep(j,w) { if(a[i][w-j-1]==1) { f=1; } else if(a[i][w-j-1]==-1) f=-1; if(f==1) used[i][w-j-1]=1; } } rep(j,w) { f=0; rep(i,h) { if(a[h-i-1][j]==1) { f=1; } else if(a[h-i-1][j]==-1) f=-1; if(f==1) used[h-i-1][j]=1; } } rep(j,w) { f=0; rep(i,h) { if(a[i][j]==1) { f=1; } else if(a[i][j]==-1) f=-1; if(f==1) used[i][j]=1; } } rep(i,h) { rep(j,w) { if(used[i][j]==1) { //cout << i << " " << j << endl ; ans++; } } } cout << ans ; return 0; }
#include <bits/stdc++.h> using namespace std; #define ALL(c) (c).begin(),(c).end() #define PB push_back #define IN(x,c) (find(c.begin(),c.end(),x) != (c).end()) #define REP(i,n) for (int i=0;i<(int)(n);i++) #define FOR(i,a,b) for (int i=(a);i<=(b);i++) #define INIT(a,v) memset(a,v,sizeof(a)) #define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end())))) template<class A, class B> A cvt(B x) { stringstream ss; ss<<x; A y; ss>>y; return y; } #define SPC << " " << #define DEBUG(x) cerr << #x << " = "; cerr << x << endl; #define DEBUG_ITER(x) cerr << #x << " = "; for (auto _ : x) cerr << _ << ' '; cerr << endl; typedef pair<int,int> PII; typedef long long int64; typedef vector<int> VI; typedef vector<PII> VII; typedef vector<double> VD; #define MOD 1000000007 /* Matrix operations */ typedef int64 Element; typedef vector<Element> Row; typedef vector<Row> Matrix; Matrix zeros(int h, int w) { return Matrix(h, Row(w)); } Matrix identity(int n) { Matrix c = zeros(n,n); REP (i,n) c[i][i]=1; return c; } Matrix transpose(const Matrix &a) { int h=a[0].size(), w=a.size(); Matrix t = zeros(h, w); REP (i,h) REP (j,w) t[i][j]=a[j][i]; return t; } Matrix operator+(const Matrix &a, const Matrix &b) { int h=a.size(), w=a[0].size(); assert(a.size()==b.size() && a[0].size()==b[0].size()); Matrix c = zeros(h,w); REP (i,h) REP (j,w) { c[i][j]=a[i][j]+b[i][j]; c[i][j]%=MOD; } return c; } Matrix operator+(const Matrix &a, Element k) { int h=a.size(), w=a[0].size(); Matrix c = a; REP (i,h) REP (j,w) { c[i][j]+=k; c[i][j]%=MOD; } return c; } Matrix operator*(Element k, const Matrix &a) { int h=a.size(), w=a[0].size(); Matrix c = a; REP (i,h) REP (j,w) { c[i][j]*=k; c[i][j]%=MOD; } return c; } Matrix operator*(const Matrix &a, const Matrix &b) { int h=a.size(), w=b[0].size(); assert(a[0].size()==b.size()); Matrix c = zeros(h,w); REP (i,h) REP (j,w) { REP (k,a[0].size()) { c[i][j]+=a[i][k]*b[k][j]; c[i][j]%=MOD; } } return c; } Matrix operator+(Element k, const Matrix &a) { return a+k; } Matrix operator*(const Matrix &a, Element k) { return k*a; } Matrix operator-(const Matrix &a, const Matrix &b) { return a+(-1)*b; } Matrix mat_pow(const Matrix &a, int k) { assert(a.size()==a[0].size()); if (k==0) return identity(a.size()); if (k%2==0) { Matrix c=mat_pow(a,k/2); return c*c; } else { Matrix c=mat_pow(a,k-1); return c*a; } } void mat_print(const Matrix &a) { REP (i,a.size()) { REP (j,a[i].size()) { if (j!=0) cout << " "; cout << a[i][j]; } cout << endl; } } int modPow(int a, int k, int m) { if (k==0) return 1; else if (k%2==0) { int64 b=modPow(a,k/2,m); return (b*b)%m; } else { int64 b=modPow(a,k-1,m); return (a*b)%m; } } int n,m,k; int a[100]; int deg[100]; vector<int> adj[100]; int main() { //freopen("test.in","r",stdin); cin >> n >> m >> k; REP (i,n) cin >> a[i]; Matrix A = zeros(n,n); REP (i,m) { int x,y; cin >> x >> y; x--; y--; adj[x].PB(y); adj[y].PB(x); deg[x]++; deg[y]++; } int64 inv_2m=modPow(2*m,MOD-2,MOD); int64 inv_m=modPow(m,MOD-2,MOD); REP (i,n) { for (int j : adj[i]) { A[i][j]=inv_2m; //1.0/(2*m); A[i][i]=(A[i][i]+inv_2m)%MOD; //+=1.0/(2*m); } A[i][i]=(A[i][i]+(m-deg[i])*inv_m)%MOD; } Matrix v = zeros(n,1); REP (i,n) v[i][0]=a[i]; Matrix Ak = mat_pow(A,k); Matrix vk = Ak*v; REP (i,n) { cout << vk[i][0] << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; #define _GLIBCXX_DEBUG //gccで配列[]を使った時にバグを検出してくれる 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; } int main(void){ int n; cin >> n; vector<int> a(n); int64_t cnt = 0; for(int i = 0; i < n; i++){ cin >> a.at(i); } for(int i = 0; i < n; i++){ int x = 0; if(a.at(i) > 10){ x = a.at(i) - 10; } cnt += x; } cout << cnt << endl; }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define eb emplace_back #define mk make_pair #define fi first #define se second #define mset(a, b) memset(a, b, sizeof(a)) using ll = long long; using pii = pair<int, int>; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template<class Ty> Ty randint(Ty a, Ty b) { return uniform_int_distribution<Ty>(a, b)(rng); } template<class T> void DBG(T&& x) { cerr << x << " "; } template<class T, class...Args> void DBG(T&& x, Args&&... args) { DBG(x); DBG(args...); } #define DBG(...) { cerr << "[" << #__VA_ARGS__ << "]: "; DBG(__VA_ARGS__); cerr << endl; } template<class num> inline void rd(num& x) { cin >> x; } template <class Ty, class... Args> inline void rd(Ty& x, Args&... args) { rd(x); rd(args...); } template<class num> inline void print(num&& x) { cout << x; } template <class Ty, class... Args> inline void print(Ty&& x, Args&&... args) { print(x); print(' '); print(args...); } #define print(...) print(__VA_ARGS__), print('\n') inline void run_test(int test_number) { int n, x; rd(n, x); for (int i = 0; i < n; i++) { int y; rd(y); if (y != x) cout << y << " "; } cout << "\n"; } int main() { //#ifndef LOCAL_PC // freopen("FILE.in", "r", stdin); //#endif ios::sync_with_stdio(false); cin.tie(nullptr); int n_tests = 1; for (int i = 1; i <= n_tests; i++) run_test(i); }
#include <iostream> using namespace std; int main() { long long n; cin >> n; long long ans[n]; ans[0] = 1; for(int i=1;i<n;i++) { ans[i] = ans[i-1] * (n-i) / i; } /*for(int i=0;i<n;i++) { cout << ans[i] << " "; } cout << endl;*/ cout << ans[11] << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using Graph=vector<vector<int>>; const long long INF = 1ll << 60; std::vector<std::vector<long long>> comb(int n, int r) { std::vector<std::vector<long long>> v(n + 1,std::vector<long long>(n + 1, 0)); for (int i = 0; i < v.size(); i++) { v[i][0] = 1; v[i][i] = 1; } for (int j = 1; j < v.size(); j++) { for (int k = 1; k < j; k++) { v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]); } } return v; } int main(){ ll l; cin>>l; vector<vector<ll>> ans=comb(l,12); cout<<ans[l-1][11]<<endl; return 0; }
//g++ -std=gnu++14 a.cpp // ./compile_run.sh #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 revrep(i, n) for(ll i = (n)-1; i >=0; i--) #define P pair<ll,ll> #define pb push_back ll MOD = 1e9 + 7; int INF = 1 << 30; ll INFL = 1LL << 60; ll MODP = 998244353; //const ll M = MOD; template<typename __T__> int len(vector<__T__> x){ return int(x.size()); } template<typename __T__> void vecout(vector<__T__> x){ rep(i, len(x)) cout << x[i] << " "; cout << endl; } 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; } ll gen(ll x,ll y){ if(y == 0)return 1; if(y == 1)return x%MOD; if(y%2 == 1){ return ((x%MOD)*gen(x,y-1)%MOD)%MOD; }else{ ll res = gen(x,y/2)%MOD; return ((res%MOD)*(res%MOD))%MOD; } } ll Factorial(ll x,ll y){ //xのy乗 if(y == 1) return x; if(y == 0) return 1; if(y%2 == 0){ ll res = Factorial(x,y/2); return res*res; }else{ return x*Factorial(x,y-1); } } ll gcd(ll x, ll y){ if(x < y) swap(x,y); if(y == 0) return x; return gcd(y,x%y); } ll lcm(ll x,ll y){ ll s = gcd(x,y); x /= s; y /= s; return x*y*s; } ll maxn = 1005; vector<vector<ll>> to(maxn*(maxn-1)/2); vector<vector<ll>> id(maxn,vector<ll>(maxn,0)); ll toid (ll i,ll j){ //iとjの試合に対応する頂点番号を返す関数 if(i > j)swap(i,j); return id[i][j]; } int len(string s, string t){ int dp[s.size()][t.size()]; rep(i,s.size()) rep(j,t.size()) dp[i][j] = 0; ll res = 0; rep(i,s.size()){ rep(j,t.size()) { if(s[i] == t[j]){ if(i < 1 || j < 1){ dp[i][j] = 1; }else{ dp[i][j] = dp[i-1][j-1] + 1; } } res = lmax(res,dp[i][j]); } } return res; } int main(){ string s; cin >> s; string ans = ""; ans += s[1]; ans += s[2]; ans += s[0]; cout << ans << endl; return 0; }
#include<bits/stdc++.h> #include <iostream> #include <string> #include <cmath> #include <algorithm> #include <stdlib.h> #include <vector> #include <set> #include <cassert> #include <numeric> using namespace std; #define rep(i,n) for(int i = 0; i < (int)n; i++) using ll = long long; #define ALL(a) (a).begin(),(a).end() int main() { ll N,n,ans=0,sum; string s; vector<ll> L; cin >> s; n = s.size(); s = s + s[0]; s.erase(0,1); cout << s; }
#include <bits/stdc++.h> using namespace std; long long n; vector<long long> v(2, 1); vector<int> solve(); int main() { for (int i = 2;; ++i) { if (v[i - 2] + v[i - 1] >= 1e18) break; v.push_back(v[i - 2] + v[i - 1]); } cin >> n; auto res = solve(); cout << res.size() << endl; for (auto p : res) cout << p << endl; return 0; } vector<int> solve() { vector<int> res; long long rem = n; for (int i = 86; i; --i) { long long now = rem / v[i]; while (now--) res.push_back(1 + (i & 1)); rem %= v[i]; res.push_back(4 - (i & 1)); } long long x = 0, y = 0; for (auto p : res) { if (p == 1) ++x; else if (p == 2) ++y; else if (p == 3) x += y; else y += x; } assert(x == n); assert(res.size() <= 130); return res; }
#include <bits/stdc++.h> using namespace std; long long X; vector<long long> fibo = {0,1}; vector<int> ans = {1}; bitset<100> bs; int main() { scanf("%lld", &X); while (fibo[fibo.size()-2] + fibo[fibo.size()-1] <= X) fibo.push_back(fibo[fibo.size()-2] + fibo[fibo.size()-1]); int K = fibo.size(); X -= fibo.back(); while (X) { while (fibo.back() > X) fibo.pop_back(); bs[fibo.size()] = true; X -= fibo.back(); } for (int i = 1; i < K-1; ++i) { ans.push_back(3+i%2); if (bs[K-i]) ans.push_back(1+i%2); } printf("%d\n", ans.size()); if (K % 2 == 0) { for (int x: ans) printf("%d\n", x); } else { for (int x: ans) { if (x <= 2) printf("%d\n", 3-x); else printf("%d\n", 7-x); } } return 0; }
#include <bits/stdc++.h> #define mp make_pair #define mt make_tuple #define fi first #define se second #define pb push_back #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define forn(i, n) for (int i = 0; i < (int)(n); ++i) #define for1(i, n) for (int i = 1; i <= (int)(n); ++i) #define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i) #define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i) using namespace std; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pii> vpi; typedef vector<vi> vvi; typedef long long i64; typedef vector<i64> vi64; typedef vector<vi64> vvi64; typedef pair<i64, i64> pi64; typedef double ld; template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; } template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.precision(10); cout << fixed; #ifdef LOCAL_DEFINE freopen("input.txt", "rt", stdin); #endif vi a(4); forn(i, 4) cin >> a[i]; bool ok = false; forn(mask, 1 << 4) { int s = 0; forn(i, 4) (s += a[i] * ((mask >> i) & 1 ? 1 : -1)); ok |= s == 0; } cout << (ok ? "Yes" : "No") << '\n'; #ifdef LOCAL_DEFINE cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; #endif return 0; }
#include <iostream> #include <vector> using namespace std; int main(){ vector<int> v(4); int sum = 0; for(int i=0;i<4;i++){ cin >> v[i]; sum += v[i]; } for(int i=1;i<16;i++){ int tsum = 0; for(int j=0;j<4;j++){ if(i & (1<<j)){ tsum += v[j]; } } if(tsum == sum - tsum){ cout << "Yes" << endl; return 0; } } cout << "No" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using PII = pair<ll, ll>; #define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(x) x.begin(), x.end() #define POPCOUNT(x) __builtin_popcount(x) template <typename T> void chmin(T &a, const T &b) { a = min(a, b); } template <typename T> void chmax(T &a, const T &b) { a = max(a, b); } const ll INF = 1LL << 60; struct FastIO { FastIO() { cin.tie(0); ios::sync_with_stdio(0); } } fastiofastio; const ll MOD = 1e9 + 7; int main() { int N; cin >> N; REP(i, N) { cout << (i * 2) % N + 1 << " " << (i * 2 + 1) % N + 1 << endl; } }
#include<bits/stdc++.h> #include<iostream> #include<cstdio> #include<algorithm> #include<queue> #include<vector> #include<cstring> #include<map> #include<set> #include<cstdlib> #include<bitset> using namespace std; #define FAST ios::sync_with_stdio(false), cin.tie(0), cout.tie(0) typedef long long ll; ll siz[200005],par[200005]; ll mod=998244353; ll find(ll x) { if(x==par[x]) return x; else return par[x]=find(par[x]); } void unite(ll x,ll y) { x=find(x);y=find(y); if(x==y) return; if(siz[x]<=siz[y]) { siz[y]+=siz[x]; par[x]=y; } else { siz[x]+=siz[y]; par[y]=x; } } ll go[200005]={0}; int main(void) { ll n; scanf("%lld",&n); for(ll i=1;i<=n;i++) siz[i]=1,par[i]=i; for(ll i=1;i<=n;i++) { ll u; scanf("%lld",&u); unite(i,u); } for(ll i=1;i<=n;i++) { go[find(i)]=1; // printf("%lld %lld\n",i,find(i)); } ll ans=0; for(ll i=1;i<=n;i++) ans+=go[i]; ll an=1; for(ll i=0;i<ans;i++) { an=an*2%998244353; } an=an-1; an=an%mod+mod; an=an%mod; cout<<an; }
#include <bits/stdc++.h> int main(){ int N; std::cin >> N; long A[N]; long ans; long hoge; ans =0; hoge=0; //std::cout <<"A: "; for (int i=0;i<N;i++){ std::cin >> A[i]; // std::cout <<A[i] <<" "; } //std::cout <<std::endl; std::sort(A,A+N); //std::cout << ans << std::endl; for (int i=N-1;i>=0;i--){ //std::cout << i << " "<< A[i] <<" "<<hoge ; if (i==N-1){ hoge =0; } else{hoge = 2*hoge+A[i+1];} hoge = hoge%998244353; ans +=(A[i]*(A[i]+(int)hoge)); ans = ans%998244353; //std::cout << " "<<hoge<<" "<<ans<<std::endl; } std::cout << ans%998244353 << std::endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(v) (v).begin(), (v).end() using ll = long long; constexpr int INF = 1e9; constexpr long long LINF = 1e18; constexpr long long MOD = 1e9 + 7; /* 実行時MODint : template <int& MOD = 1000000007> static int MOD; cin >> MOD; */ template <int MOD = 1000000007> struct Mint { int x; constexpr Mint() : x(0) {} constexpr Mint(long long t) : x(t >= 0 ? (t % MOD) : (MOD - (-t) % MOD) % MOD) {} Mint pow(int n) { Mint res(1), t(x); while (n > 0) { if (n & 1) res *= t; t *= t; n >>= 1; } return res; } Mint inv() const { int a = x, b = MOD, u = 1, v = 0, t; while (b > 0) { t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } return Mint(u); } Mint &operator+=(Mint a) { x += a.x; if (x >= MOD) x -= MOD; return *this; } Mint &operator-=(Mint a) { x += MOD - a.x; if (x >= MOD) x -= MOD; return *this; } Mint &operator*=(Mint a) { x = int(1LL * x * a.x % MOD); return *this; } Mint &operator/=(Mint a) { return (*this) *= a.inv(); } Mint operator+(Mint a) const { return Mint(x) += a; } Mint operator-(Mint a) const { return Mint(x) -= a; } Mint operator*(Mint a) const { return Mint(x) *= a; } Mint operator/(Mint a) const { return Mint(x) /= a; } Mint operator-() const { return Mint(-x); } bool operator==(const Mint a) { return x == a.x; } bool operator!=(const Mint a) { return x != a.x; } bool operator<(const Mint a) { return x < a.x; } friend ostream &operator<<(ostream &os, const Mint &a) { return os << a.x; } friend istream &operator>>(istream &is, Mint &a) { int t; is >> t; a = Mint<MOD>(t); return (is); } }; signed main() { int n; cin >> n; char caa, cab, cba, cbb; cin >> caa >> cab >> cba >> cbb; if (n <= 3) { cout << 1 << endl; return 0; } if ((cab == 'A' && caa == 'A') || (cab == 'B' && cbb == 'B')) { cout << 1 << endl; return 0; } if ((cab == 'A' && caa == 'B' && cba == 'A') || (cab == 'B' && cbb == 'A' && cba == 'B')) { Mint<> dp[n][2]; dp[0][0] = 1; rep(i, n - 1) { dp[i + 1][0] += dp[i][1]; dp[i + 1][1] += (dp[i][0] + dp[i][1]); } cout << dp[n - 1][1] << endl; return 0; } cout << Mint<>(2).pow(n - 3) << endl; return 0; }
#include<cstdio> #include<cctype> #include<algorithm> #include<cstring> #include<cmath> // Standard iostream objects -*- C++ -*- // Copyright (C) 1997-2014 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the // terms of the GNU General Public License as published by the // Free Software Foundation; either version 3, or (at your option) // any later version. // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // Under Section 7 of GPL version 3, you are granted additional // permissions described in the GCC Runtime Library Exception, version // 3.1, as published by the Free Software Foundation. // You should have received a copy of the GNU General Public License and // a copy of the GCC Runtime Library Exception along with this program; // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see // <http://www.gnu.org/licenses/>. /** @file include/iostream * This is a Standard C++ Library header. */ // // ISO C++ 14882: 27.3 Standard iostream objects // #ifndef _GLIBCXX_IOSTREAM #define _GLIBCXX_IOSTREAM 1 #pragma GCC system_header #include <bits/c++config.h> #include <ostream> #include <istream> namespace std _GLIBCXX_VISIBILITY(default) { _GLIBCXX_BEGIN_NAMESPACE_VERSION /** * @name Standard Stream Objects * * The &lt;iostream&gt; header declares the eight <em>standard stream * objects</em>. For other declarations, see * http://gcc.gnu.org/onlinedocs/libstdc++/manual/io.html * and the @link iosfwd I/O forward declarations @endlink * * They are required by default to cooperate with the global C * library's @c FILE streams, and to be available during program * startup and termination. For more information, see the section of the * manual linked to above. */ //@{ extern istream cin; /// Linked to standard input extern ostream cout; /// Linked to standard output extern ostream cerr; /// Linked to standard error (unbuffered) extern ostream clog; /// Linked to standard error (buffered) #ifdef _GLIBCXX_USE_WCHAR_T extern wistream wcin; /// Linked to standard input extern wostream wcout; /// Linked to standard output extern wostream wcerr; /// Linked to standard error (unbuffered) extern wostream wclog; /// Linked to standard error (buffered) #endif //@} // For construction of filebuffers for cout, cin, cerr, clog et. al. static ios_base::Init __ioinit; _GLIBCXX_END_NAMESPACE_VERSION } // namespace #endif /* _GLIBCXX_IOSTREAM */ #define R register using namespace std; using namespace std; typedef long long ll; const int N =111111; int n, a[N],p[]={0, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 0, 0}; ll ans; void dfs(int k,ll b) { if(!p[k]) { int i=1; for(i=1;i<=n;i++) if(__gcd(b,(ll)a[i])==1) break; if(i==n+1) { if(!ans) ans=b; else ans=min(ans,b); } } else dfs(k+1,b),dfs(k+1,b*p[k]); } int main() { cin>>n; for(int i=1;i<=n;i++) cin>>a[i]; dfs(1,1); cout<<ans; return 0; }
//Bismillahir Rahmanir Raheem #include<bits/stdc++.h> using namespace std; typedef pair<int,int>pii; #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 //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’. typedef pair<lli,lli>pll; bool isp[102]; const lli mx=50ll; vector<lli>prime; void sieve() { memset(isp,1,sizeof(isp)); isp[0]=isp[1]=0; for(int i=4;i<=mx;i+=2) { isp[i]=0; } for(int i=3;i*i<=mx;i+=2) { if(isp[i]) { for(int j=i*i;j<=mx;j+=i) { isp[j]=0; } } } for(lli i=2;i<=mx;i++) { if(isp[i]) { prime.pb(i); //cout<<i<<" "; } } //cout<<endl; } void solve() { sieve(); lli n; lli ans=-1; //cout<<"ans = "<<ans<<endl; cin>>n; lli a[n]; frr(i,n) { cin>>a[i]; } for(int i=0;i<(1<<15);i++) { lli res=1ll; bool ok=true; //cout<<"i = "<<i<<endl; for(int j=0;j<15;j++) { if((i&(1<<j))) { //cout<<prime[j]<<" "; res*=prime[j]; } } //cout<<endl; for(int j=0;j<n;j++) { if(__gcd(a[j],res)==1) { ok=false; } } if(ok) { //cout<<"res = "<<res<<endl; if(ans==-1) { ans=res; } else ans=min(ans,res); } } cout<<ans<<endl; } int main() { int t; t=1; while(t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; #define sz(x) (ll)x.size() #define m1(x) memset(x, 1, sizeof(x)) #define m0(x) memset(x, 0, sizeof(x)) #define inf(x) memset(x, 0x3f, sizeof(x)) #define flout cout << fixed << setprecision(12) #define MOD 1000000007 int main() { int n, m; cin >> n >> m; int a[m], b[m]; for (int i = 0; i < m; i ++) { cin >> a[i] >> b[i]; a[i]--; b[i]--; } int k; cin >> k; int c[k], d[k]; for (int i = 0; i < k; i ++) { cin >> c[i] >> d[i]; c[i]--; d[i]--; } bool cur[n]; int ans = 0; for (int i = 0; i < (1 << k); i ++) { m0(cur); for (int j = 0; j < k; j ++) { if ((1 << j) & i) { cur[d[j]] = true; } else { cur[c[j]] = true; } } int counter = 0; for (int i = 0; i < m; i ++) { if (cur[a[i]] && cur[b[i]]) { counter ++; } } ans = max(ans, counter); } cout << ans << endl; }
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <climits> #include <cmath> #include <complex> #include <cstring> #include <deque> #include <functional> #include <iostream> #include <iomanip> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <unordered_map> #include <unordered_set> #include <vector> #include <cstdint> using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int,int> pii; #define MP make_pair #define PB push_back #define inf 1000000007 #define rep(i,n) for(int i = 0; i < (int)(n); ++i) #define all(x) (x).begin(),(x).end() template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ std::fill( (T*)array, (T*)(array+N), val ); } 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; } #define int long long signed main(){ int n,k; cin >> n >> k; vector<int> a(n); rep(i,n) cin >> a[i]; sort(all(a)); vector<int>c(n+1); c[0] = k; rep(i,n){ if(c[a[i]]>0){ c[a[i]]--; c[a[i]+1]++; } } ll sm = 0; rep(i,n+1){ sm += c[i]*(ll)i; } cout << sm << endl; return 0; }
#include<bits/stdc++.h> //#pragma GCC optimize("O2") //#pragma GCC optimize ("unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define mp make_pair #define pb push_back #define pll pair<LL,LL> #define pii pair<int,int> #define y second #define x first #define LL long long #define ULL unsigned long long #define sqr(x) ((x)*(x)) #define pi acos(-1) #define pdd pair<double,double> #define MEM(x) memset(x,0,sizeof(x)) #define MEMS(x) memset(x,-1,sizeof(x)) using namespace std; int dp[2][3005][3005]; int mod=998244353; int DP(int op,int x,int y){ if(y>x)return 0; if(op==0&&y==x)return 1; if(x==0&&y==0)return 1; if(y<=0)return 0; if(x<0)return 0; if(dp[op][x][y]!=-1)return dp[op][x][y]; if(op==0){ if(y==0)return 0; dp[0][x][y]=DP(1,x,y); } if(op==1){ dp[1][x][y]=(DP(0,x,y*2)+DP(1,x-1,y-1))%mod; } // printf("%d %d %d %d\n",op,x,y,dp[op][x][y]); return dp[op][x][y]; } void solve(){ int n,k; scanf("%d %d",&n,&k); MEMS(dp); printf("%lld\n",DP(0,n,k)); } int main(){ int t=1; while(t--){ solve(); } } /* 11 4 12 1 1 1 1 AABB .AB. CCDD .CD. EEFF .EF. GGHH .GH. IIJJ .IJ. KKLL 12 0 0 0 -13 3 -13 3 -10 10 -10 10 10 -1 10 -1 13 -4 13 -4 10 -10 10 -10 0 */
#include <cstdio> #include <string> #include <iostream> #include <cmath> #include <algorithm> #include <vector> #include <set> #include <unordered_set> #include <map> #include <unordered_map> #include <tuple> #define max(l,r) ((l)>(r)?(l):(r)) #define min(l,r) ((l)<(r)?(l):(r)) #define rep(i,s,l) for(int i=(int)s;i<(int)l;++i) using namespace std; typedef long long ll; typedef unsigned long long ull; template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } const long long INF = 1LL<<60; const long long MOD = 1000000007; int main() { int n,k; cin >> n >> k; ll ans = 0LL; rep(i,1,n+1) { rep(j,1,k+1) { ans += i*100+j; } } cout << ans << endl; }
#include <bits/stdc++.h> //#define DEBUG #define REP(i, nn ) for(int i = 0 ; i < (int) nn; i++) #define deb(x) std::cout << #x << " " << x << endl; #define debl(x) std::cout << #x << " " << x << " "; using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; template<typename... T> void read(T& ... a){ ((cin >> a),...); } template<typename... T> void write(T... a){ ((cout << a << "\n"),...); } template<typename... T> void write_space(T... a){ ((cout << a << " "),...); } const string s = "110"; const int sz = s.size(); constexpr ll L = 3e10; void solve(){ ll n ; cin >>n; string t; cin >> t; if( n == 1){ if(t[0] == '1'){ cout << 2 * L / 3 << endl; }else{ cout << L / 3 << endl; } return; } bool match; int start = -1; for(start = 0 ; start < sz; start++){ match = true; for(int i = 0 ; i < (int) t.size(); i++){ int j = (i + start) % sz; if( t[i] != s[j]){ match = false; break; } } if(match) break; } if(match == false){ cout << 0 << endl; }else{ assert(start >= 0); ll end = L - n; // debl(start) deb(end) ll ans = end / 3; if(end % 3 >= start){ ans++; } cout << ans << endl; } } int main() { //making data IO Fast std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); /****************************/ solve(); return 0; }
#include <iostream> #include <vector> #include <climits> #include <algorithm> #include <cmath> #include <map> #include <set> #include <string> #include <bitset> #include <utility> #include <numeric> #include <queue> #include <stack> #include <functional> #include <iomanip> using ll = long long; using namespace std; constexpr int MOD = 1e9 + 7; constexpr ll MOD_LL = ll(1e9 + 7); constexpr int INF = (1 << 30); //constexpr ll INF = (1LL << 60); int main(void) { ll n; string t; cin >> n >> t; ll ans = 0LL; if( n == 1 ) { if( t == "1" ) { ans = 2LL * 1e10; } else { ans = 1e10; } } else if( n == 2 && t == "11" ) { ans = 1e10; } else { bool f = true; int num_zero = 0; for(int i = 0; i < n; ++i) { if( i < n - 1 ) { string tmp = t.substr(i, 2); if( tmp == "00" ) { f = false; break; } } if( t[i] == '0' ) num_zero++; } for(int i = 0; i < n - 2; ++i) { string tmp = t.substr(i, 3); if( tmp == "111" || tmp == "010" ) { f = false; break; } } if( f ) { if( t.back() == '0' ) { ans = 1e10 - num_zero + 1; } else { ans = 1e10 - num_zero; } } } cout << ans << endl; return 0; }
/* Author: QAQAutoMaton Lang: C++ Code: B.cpp Mail: lk@qaq-am.com Blog: https://www.qaq-am.com/ */ #include<bits/stdc++.h> #define debug(qaq...) fprintf(stderr,qaq) #define DEBUG printf("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__) #define Debug debug("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__) #define all(x) x.begin(),x.end() #define x first #define y second #define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end()) using namespace std; typedef unsigned uint; typedef long long ll; typedef unsigned long long ull; typedef complex<double> cp; typedef pair<int,int> pii; int inf; const double eps=1e-8; const double pi=acos(-1.0); template<class T,class T2>int chkmin(T &a,T2 b){return a>b?a=b,1:0;} template<class T,class T2>int chkmax(T &a,T2 b){return a<b?a=b,1:0;} template<class T>T sqr(T a){return a*a;} template<class T,class T2>T mmin(T a,T2 b){return a<b?a:b;} template<class T,class T2>T mmax(T a,T2 b){return a>b?a:b;} template<class T>T aabs(T a){return a<0?-a:a;} template<class T>int dcmp(T a,T b){return a>b;} template<int *a>int cmp_a(int x,int y){return a[x]<a[y];} template<class T>bool sort2(T &a,T &b){return a>b?swap(a,b),1:0;} #define min mmin #define max mmax #define abs aabs struct __INIT__{ __INIT__(){ fill((unsigned char*)&inf,(unsigned char*)&inf+sizeof(inf),0x3f); } }__INIT___; namespace io { const int SIZE = (1 << 21) + 1; char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr; // getchar #define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++) // print the remaining part inline void flush () { fwrite (obuf, 1, oS - obuf, stdout); oS = obuf; } // putchar inline void putc (char x) { *oS ++ = x; if (oS == oT) flush (); } template<typename A> inline bool read (A &x) { for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;else if(c==EOF)return 0; for (x = 0; c <= '9' && c >= '0'; c = gc()) x = x * 10 + (c & 15); x *= f; return 1; } inline bool read (char &x) { while((x=gc())==' '||x=='\n' || x=='\r'); return x!=EOF; } inline bool read(char *x){ while((*x=gc())=='\n' || *x==' '||*x=='\r'); if(*x==EOF)return 0; while(!(*x=='\n'||*x==' '||*x=='\r'||*x==EOF))*(++x)=gc(); *x=0; return 1; } template<typename A,typename ...B> inline bool read(A &x,B &...y){ return read(x)&&read(y...); } template<typename A> inline bool write (A x) { if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x; while (x) qu[++ qr] = x % 10 + '0', x /= 10; while (qr) putc (qu[qr --]); return 0; } inline bool write (char x) { putc(x); return 0; } inline bool write(const char *x){ while(*x){putc(*x);++x;} return 0; } inline bool write(char *x){ while(*x){putc(*x);++x;} return 0; } template<typename A,typename ...B> inline bool write(A x,B ...y){ return write(x)||write(y...); } //no need to call flush at the end manually! struct Flusher_ {~Flusher_(){flush();}}io_flusher_; } using io :: read; using io :: putc; using io :: write; int fpm(int a,int b,int p){ a%=p; int c=1; for(;b;b>>=1,a=a*a%p)if(b&1)c=c*a%p; return c; } int xfpm(int a,int b){ if(a==1||(a<4 && b==1))return fpm(a,b,4); else return fpm(a,b,4)+4; } signed main(){ #ifdef QAQAutoMaton freopen("B.in","r",stdin); freopen("B.out","w",stdout); #endif int a,b,c; read(a,b,c); a%=10; /*for(int i=1;i<10;++i){ write(i,i*i%10,i*i*i%10,i*i*i*i%10,i*i*i*i*i%10,'\n'); }*/ write(fpm(a,xfpm(b,c),10),'\n'); return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long int ll; ll quickpow(ll a,ll b,ll mod) { ll res=1; while(b) { if(b&1) { res=res*a%mod; } b=b/2; a=a*a%mod; } return res%mod; } int aa[10][10]; int main() { aa[0][0]=1;aa[0][1]=1; aa[1][0]=4;aa[1][1]=2;aa[1][2]=4;aa[1][3]=8;aa[1][4]=6; aa[2][0]=4;aa[2][1]=3;aa[2][2]=9;aa[2][3]=7;aa[2][4]=1; aa[3][0]=2;aa[3][1]=4;aa[3][2]=6; aa[4][0]=1;aa[4][1]=5; aa[5][0]=1;aa[5][1]=6; aa[6][0]=4;aa[6][1]=7;aa[6][2]=9;aa[6][3]=3;aa[6][4]=1; aa[7][0]=4;aa[7][1]=8;aa[7][2]=4;aa[7][3]=2;aa[7][4]=6; aa[8][0]=2;aa[8][1]=9;aa[8][2]=1; ll x,y,z; cin>>x>>y>>z; int t1=z%10; int t2=y%10; int t3=x%10; if(t3==0){printf("0\n");return 0;} ll t4= quickpow(y,z,aa[t3-1][0]); //printf("%d %d\n",t3-1,t4); //printf("%d %d\n",aa[t3-1][t4],aa[1][0]); if(t4==0){t4=aa[t3-1][0];} int ans=aa[t3-1][t4]; printf("%d",ans); return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long int #define mp(a,b) make_pair(a,b) #define vi vector<int> #define mii map<int,int> #define mpi map<pair<int,int>,int> #define vp vector<pair<int,int> > #define pb(a) push_back(a) #define fr(i,n) for(i=0;i<n;i++) #define rep(i,a,n) for(i=a;i<n;i++) #define F first #define S second #define endl "\n" #define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define mod 1000000007 #define dom 998244353 #define pi 3.14159265 #define sl(a) (int)a.length() #define sz(a) (int)a.size() #define all(a) a.begin(),a.end() #define pii pair<int,int> #define mini 2000000000000000000 #define time_taken 1.0 * clock() / CLOCKS_PER_SEC //mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count()); //primes for hashing 937, 1013 template<typename T, typename U> static inline void amin(T &x, U y) { if (y < x) x = y; } template<typename T, typename U> static inline void amax(T &x, U y) { if (x < y) x = y; } void shikhar7s(int cas) { int x,y; cin>>x>>y; if(!x) cout<<y<<endl; else if(x>0) { if(y<3) cout<<y+1<<endl; else cout<<y+min(2*x,y)-1<<endl; } else { if(y<3) cout<<y+1<<endl; else cout<<y+min(1-2*x,y)-1<<endl; } } signed main() { fast; //freopen("input.txt", "rt", stdin); //freopen("output.txt", "wt", stdout); int t=1; //cin>>t; int cas=1; while(cas<=t) { shikhar7s(cas); cas++; } return 0; }
#include <bits/stdc++.h> using namespace std; int _ = (cout << fixed << setprecision(9), cin.tie(0), ios::sync_with_stdio(0)); using Int = long long; int main() { Int B, C; cin >> B >> C; vector<pair<Int, Int>> sec; sec.emplace_back(B - C/2, B); sec.emplace_back(-B - (C-1)/2, -B); sec.emplace_back(-B, -B + (C-1)/2); sec.emplace_back(B, B + (C-2)/2); Int ans = 0, rmax = LLONG_MIN; sort(begin(sec), end(sec)); for (auto [l, r] : sec) { l = max(l, rmax + 1); ans += r - l + 1; rmax = max(rmax, r); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main (){ int a[2][2]; for(int i = 0 ; i<2;i++){ for(int j = 0 ; j<2;j++){ cin >> a[i][j];; } } cout << (a[0][0]*a[1][1])-(a[0][1]*a[1][0]); }
#include<bits/stdc++.h> using namespace std; using ll = long long; #define _overload3(_1,_2,_3,name,...) name #define _rep(i,n) repi(i,0,n) #define repi(i,a,b) for(int i=int(a);i<int(b);++i) #define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__) #define ALL(x) (x).begin(),(x).end() template<class T>bool umax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;} template<class T>bool umin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;} #ifdef LOCAL void _debug_out() { cerr << endl; } template <typename Head, typename... Tail> void _debug_out(Head H, Tail... T) { cerr << " " << to_string(H); _debug_out(T...); } #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", _debug_out(__VA_ARGS__) #define eprintf(...) fprintf(stderr, __VA_ARGS__) #else #define debug(...) 42 #define eprintf(...) 42 #endif int main() { int a,b,c,d; cin >> a >> b >> c >> d; cout << a*d-b*c<<endl; }
#include <bits/stdc++.h> using namespace std; #define int long long int #define endl "\n" #define aashish_999 ios_base::sync_with_stdio(false);cin.tie(NULL) void solve() { //read the question properly string s; cin >> s; string f, r; f = r = ""; bool flag = false; int cnt = 0; for (auto i : s) { if (i == 'R') flag = !flag, ++cnt; else if (flag) r += i; else f += i; } string final; if (cnt % 2 == 0) reverse(r.begin(), r.end()), final = r + f; else reverse(f.begin(), f.end()), final = f + r; string ans = ""; for (int i = 0; i < final.length(); i++) { if (ans.empty()) { ans += final[i]; continue; } if (ans.back() == final[i]) { ans.pop_back(); } else ans.push_back(final[i]); } cout << ans; } int32_t main() { aashish_999; int testcases = 1; //cin >> testcases; while (testcases--) { solve(); } }
#define _USE_MATH_DEFINES #include <iostream> #include <cstring> #include <regex> #include <cmath> #include <algorithm> #include <vector> #include <list> #include <map> #include <unordered_set> #include <queue> #include <unordered_map> #include <set> #include <cassert> #include <climits> #pragma GCC optimize("O3") using namespace std; using ll = long long; using ull = unsigned long long; #define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i) #define repd(i, n) for(ll i = (n) - 1ll; 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 foreach(i, itr) for(auto& i : (itr)) #define asort(arr, size) std::sort(arr, arr + size) #define dsort(arr, size) std::sort(arr, arr + size, [](auto a, auto b) { return a > b; }) #define cauto const auto& #define bit(n) (1LL << (n)) //////////////////////////////////// // ここから下に任意のコードを書く // //////////////////////////////////// int main() { string S; cin >> S; deque<char> T; bool R = false; rep(i, S.size()) { if (S[i] == 'R') { R = !R; } else if (T.empty()) { T.push_back(S[i]); } else if (R) { if (T.front() == S[i]) { T.pop_front(); } else { T.push_front(S[i]); } } else { if (T.back() == S[i]) { T.pop_back(); } else { T.push_back(S[i]); } } } if (R) { for_each(T.rbegin(), T.rend(), [](char c) { cout << c; }); } else { for (char c : T) { cout << c; } } cout << endl; return 0; } //ll abi[5000][5]; //ll dp[5000][3][5]; // //ll getPower(int index) { // ll res = INT_MAX; // rep(i, 3) { // ll mx = 0; // rep(j, 5) { // mx = max(mx, dp[index][i][j]); // } // res = min(res, mx); // } // return res; //} // //int main() //{ // int N; // cin >> N; // rep(i, N) cin >> abi[i][0] >> abi[i][1] >> abi[i][2] >> abi[i][3] >> abi[i][4]; // // dp[0][0][0] = abi[0][0]; // dp[0][0][1] = abi[0][1]; // dp[0][0][2] = abi[0][2]; // dp[0][0][3] = abi[0][3]; // dp[0][0][4] = abi[0][4]; // FOR(i, 1, N) { // int index = -1; // rep(j, 3) { // rep(k, 5) { // dp[i][j][k] = dp[i - 1][j][k]; // } // } // ll res = INT_MAX; // rep(j, 3) { // ll mx = 0; // rep(k, 5) { // mx = max(mx, dp[i][j][k]); // } // res = min(res, mx); // } // } // // return 0; //}
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pll = pair<ll,ll>; using pld = pair<ld,ld>; using vll = vector<ll>; using vld = vector<ld>; using vstr = vector<string>; #define _GLIBCXX_DEBUG #define rep(j, m) for (ll j = 0; j < (ll)(m); j++) #define rep2(i, l, n) for (ll i = l; i < (ll)(n); i++) #define all(v) v.begin(), v.end() const ld PI = 3.1415926535897932; const ll MOD = 1000000007; const ll MOD2 = 998244353; vll dx = {-1,0,1,0}; vll dy = {0,-1,0,1}; vll Dx = {-1,-1,-1,0,0,1,1,1}; vll Dy = {-1,0,1,-1,1,-1,0,1}; const ll INF = 1000000000000000; int main() { ll N; cin >> N; vector<pll> X(N); vector<pll> Y(N); rep(i,N) { cin >> X[i].first >> Y[i].first; X[i].second = i; Y[i].second = i; } sort(all(X)); sort(all(Y)); ll x1 = X[N - 1].first - X[0].first; ll y1 = Y[N - 1].first - Y[0].first; ll x21 = X[N - 2].first - X[0].first; ll y21 = Y[N - 2].first - Y[0].first; ll x22 = X[N - 1].first - X[1].first; ll y22 = Y[N - 1].first - Y[1].first; if (x1 > y1) { if ((X[N - 1].second == Y[N - 1].second && X[0].second == Y[0].second)|| (X[N - 1].second == Y[0].second && X[0].second == Y[N - 1].second)) { cout << max(max(x21,x22),max(y21,y22)) << endl; } else { cout << max(x21,max(x22,y1)) << endl; } } else { if ((X[N - 1].second == Y[N - 1].second && X[0].second == Y[0].second)|| (X[N - 1].second == Y[0].second && X[0].second == Y[N - 1].second)) { cout << max(max(x21,x22),max(y21,y22)) << endl; } else { cout << max(x1,max(y21,y22)) << endl; } } }
#include <bits/stdc++.h> using namespace std; #define il inline #define re register #define rep(i, s, e) for (re int i = s; i <= e; ++i) #define drep(i, s, e) for (re int i = s; i >= e; --i) #define file(a) freopen(#a".in", "r", stdin), freopen(#a".out", "w", stdout) const int mod = 998244353; const int inv2 = (mod + 1) >> 1; const int N = 200010; il int read() { int x = 0; bool f = true; char c = getchar(); while (!isdigit(c)) {if (c == '-') f = false; c = getchar();} while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); return f ? x : -x; } il int inc(int a, int b) { return (a += b) >= mod ? a - mod : a; } il int dec(int a, int b) { return (a -= b) < 0 ? a + mod : a; } il int mul(int a, int b) { return 1ll * a * b % mod; } int inv[N]; il void init(int w) { inv[1] = 1; rep(i, 2, w) inv[i] = mod - mul(mod / i, inv[mod % i]); } int n, m, f[N]; int tot, p[N], minv[N]; bool isnp[N]; il void filt() { f[1] = 1; rep(i, 2, m) { if (!isnp[i]) p[++tot] = i, f[i] = n, minv[i] = 1; for (re int j = 1; j <= tot && i * p[j] <= m; ++j) { isnp[i * p[j]] = true; if (i % p[j]) f[i * p[j]] = mul(f[i], n), minv[i * p[j]] = 1; else { f[i * p[j]] = mul(f[i], mul(n + minv[i], inv[minv[i] + 1])), minv[i * p[j]] = minv[i] + 1; break; } } } } int main() { n = read(), m = read(), init(200000); filt(); int ans = 0; rep(i, 1, m) ans = inc(ans, f[i]); printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) #define Pr pair<ll,ll> #define Tp tuple<ll,ll,ll> using Graph = vector<vector<int>>; ll mod = 1000000007; int main() { ll N; cin >> N; vector<char> col = {'R','G','B'}; vector<vector<ll>> cute(3); rep(i,2*N){ ll a; char c; cin >> a >> c; rep(j,3){ if(c==col[j]) cute[j].push_back(a); } } bool even[3]; rep(i,3){ cute[i].push_back(2e18); cute[i].push_back(-2e18); sort(cute[i].begin(),cute[i].end()); if(cute[i].size()%2==0) even[i] = true; else even[i] = false; } if(even[0]&&even[1]&&even[2]){ cout << 0 << endl; return 0; } ll md[3]; rep(i,3) md[i] = 2e18; rep(i,3){ rep(j,3){ if(i<=j) continue; int k = 3-i-j; int M = cute[i].size()-2; for(int l=1;l<=M;l++){ ll c = cute[i][l]; int s = lower_bound(cute[j].begin(),cute[j].end(),c)-cute[j].begin(); md[k] = min({md[k],abs(c-cute[j][s]),abs(c-cute[j][s-1])}); } } } ll ans = 2e18; rep(i,3){ if(even[i]) ans = min(ans,md[i]); //cout << md[i] << endl; rep(j,3){ if(i<=j) continue; if(!even[i]&&!even[j]) ans = min(ans,md[i]+md[j]); } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.h" #else #define deb(...) #endif #define endl "\n" #define pb push_back #define int long long #define ll long long #define pii pair<int,int> #define F first #define S second #define all(c) c.begin(),c.end() #define read(v) for(auto &it:v) cin>>it; const int inf = 1e18; const int N = 2e5 + 5; const int mod = 1000000007; vector <int> adj[4]; int solve(vector <int> &B, vector <int> &C) { int ans = inf; if (B.empty() || C.empty()) { return ans; } for (auto it : B) { // find best match for this in C? auto x = lower_bound(all(C), it); if (x == C.end()) { ans = min(ans, abs(it - *C.rbegin())); } else { if (x == C.begin()) { ans = min(ans, abs(it - *C.begin())); } else { ans = min(ans, abs(it - *x)); x--; ans = min(ans, abs(it - *x)); } } } for (auto it : C) { // find best match for this in C? auto x = lower_bound(all(B), it); if (x == B.end()) { ans = min(ans, abs(it - *B.rbegin())); } else { if (x == B.begin()) { ans = min(ans, abs(it - *B.begin())); } else { ans = min(ans, abs(it - *x)); x--; ans = min(ans, abs(it - *x)); } } } return ans; } void test_case() { int n; cin >> n; for (int i = 0; i < 2 * n; i++) { int a; char b; cin >> a >> b; if (b == 'R') { adj[1].pb(a); } else if (b == 'G') { adj[2].pb(a); } else { adj[3].pb(a); } } sort(all(adj[1])); sort(all(adj[2])); sort(all(adj[3])); int r = adj[1].size(), g = adj[2].size(), b = adj[3].size(); int cnt = 0, who = -1; for ( int val : {r, g, b}) { if (val % 2 == 1) { cnt++; } else { if (val == r) { who = 1; } else if (val == g) { who = 2; } else { who = 3; } } } if (cnt == 0) { cout << 0 << endl; return; } if (cnt == 1 || cnt == 3) { assert(false); } vector <int> A = adj[who]; set <int> st = {1, 2, 3}; st.erase(who); vector <int> B = adj[*st.begin()]; vector <int> C = adj[*st.rbegin()]; cout << min(solve(B, C), solve(A, C) + solve(A, B)) << endl; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; while (t--)test_case(); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i,n) for (int i = 0; i < n; i++) #define all(n) n.begin(), n.end() int main () { ll n; cin >> n; vector<ll> a(n); vector<ll> b(n); vector<ll> c(n); rep(i,n) cin >> a.at(i); rep(i,n) cin >> b.at(i); ll maxv = a.at(0); c.at(0) = a.at(0) * b.at(0); for (int i = 1; i < n; i++) { maxv = max(maxv, a.at(i)); c.at(i) = max(c[i - 1], maxv * b.at(i)); } for (auto i : c) { cout << i << endl; } }
#include <iostream> #include <fstream> #include <string> using namespace std; int main() { int N; cin>>N; int a[N]; int b[N]; for(int i=0;i<N;i++){ cin>>a[i]; if(i>0){ if (a[i]<a[i-1]){ a[i]=a[i-1]; } } } for(int i=0;i<N;i++){ cin>>b[i]; } long long int before=0; for(int i=0;i<N;i++){ long long int out=a[i]*b[i]; if(out<before){ out=before; }else{ before=out; } cout<<out<<endl; } return 0; }
/** * Made by: Diego Briaares * At: 07.03.2021 18:28:23 **/ #include <bits/stdc++.h> using namespace std; void optimize() { ios_base::sync_with_stdio(0); cin.tie(0); } void test_case() { int n; cin >> n; string s1, s2, s3; cin >> s1 >> s2 >> s3; s1 += s1; s2 += s2; s3 += s3; vector<string> cand; string a, b; for (int i = 0; i < n; i++) a.push_back('0'); for (int i = 0; i < n; i++) b.push_back('1'); string c = a + b + "0"; cout << c << "\n"; } int main () { optimize(); int t; cin >> t; while (t--) { test_case(); } }
#include <algorithm> #include <iostream> #include <cstring> #include <cstdio> #define pb push_back #define mp make_pair #define fir first #define sec second const int N = 1e6 + 5; using namespace std; int cas, n; char s[3][N], T[N]; template < typename T > inline T read() { T x = 0, w = 1; char c = getchar(); while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); } while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x * w; } bool check() { bool flag = 1; int pos = 1; for(int op = 0; op < 3; op++) { pos = 1; for(int i = 1; i <= 4 * n; i++) if(pos <= 2 * n + 1 && T[pos] == s[op][i > 2 * n ? i - 2 * n : i]) pos++; flag &= pos > 2 * n; } return flag; } int main() { #ifndef ONLINE_JUDGE freopen("cpp.in", "r", stdin); #endif cas = read <int> (); while(cas--) { n = read <int> (), scanf("%s", s[0] + 1), scanf("%s", s[1] + 1), scanf("%s", s[2] + 1); for(int i = 1; i <= n; i++) T[i] = '1', T[n + i] = '0'; T[2 * n + 1] = '1'; if(check()) { for(int i = 1; i <= 2 * n + 1; i++) printf("%c", T[i]); puts(""); continue; } for(int i = 1; i <= n; i++) T[i] = '1', T[n + i] = '0'; T[2 * n + 1] = '0'; if(check()) { for(int i = 1; i <= 2 * n + 1; i++) printf("%c", T[i]); puts(""); continue; } for(int i = 1; i <= n; i++) T[i] = '0', T[n + i] = '1'; T[2 * n + 1] = '0'; if(check()) { for(int i = 1; i <= 2 * n + 1; i++) printf("%c", T[i]); puts(""); continue; } for(int i = 1; i <= n; i++) T[i] = '0', T[n + i] = 1; T[2 * n + 1] = '1'; if(check()) { for(int i = 1; i <= 2 * n + 1; i++) printf("%c", T[i]); puts(""); continue; } T[1] = '0'; for(int i = 1; i <= n; i++) T[i + 1] = '1', T[n + i + 1] = '0'; if(check()) { for(int i = 1; i <= 2 * n + 1; i++) printf("%c", T[i]); puts(""); continue; } T[1] = '1'; for(int i = 1; i <= n; i++) T[i + 1] = '1', T[n + i + 1] = '0'; if(check()) { for(int i = 1; i <= 2 * n + 1; i++) printf("%c", T[i]); puts(""); continue; } T[1] = '1'; for(int i = 1; i <= n; i++) T[i + 1] = '0', T[n + i + 1] = '1'; if(check()) { for(int i = 1; i <= 2 * n + 1; i++) printf("%c", T[i]); puts(""); continue; } T[1] = '0'; for(int i = 1; i <= n; i++) T[i + 1] = '0', T[n + i + 1] = '1'; if(check()) { for(int i = 1; i <= 2 * n + 1; i++) printf("%c", T[i]); puts(""); continue; } } return 0; }
#include <bits/stdc++.h> using namespace std; const int N=205; int n,ma[N],tmp[N]; bool ok=1,can[N][N],f,dp[N]; int main() { scanf("%d",&n); for(int i=1,ai,bi;i<=n;i++){ scanf("%d%d",&ai,&bi); if(ai>0 && ma[ai]) ok=0; if(bi>0 && ma[bi]) ok=0; if(ai>0 && bi>0) ma[ai]=bi,ma[bi]=ai; else if(ai>0) ma[ai]=-1; else if(bi>0) ma[bi]=-2; // cout<<i<<" "<<ok<<endl; } if(!ok){ printf("No\n"); return 0; } n<<=1; // for(int l=1;l<=n;l++) // cout<<ma[l]<<" "; // cout<<endl; for(int l=1;l<=n;l++) for(int r=l;r<=n;r++){ if((r-l+1)%2) continue;f=1; int k=(r-l+1)/2; for(int i=l;i+k<=r;i++){ if(ma[i]>0 && ma[i]!=i+k) f=0; if(ma[i+k]>0 && ma[i+k]!=i) f=0; if(ma[i] && ma[i+k] && ma[i]!=i+k) f=0; if(ma[i]==-2 || ma[i+k]==-1) f=0; } can[l][r]=f; } // cout<<can[1][2]<<endl; dp[0]=1; for(int i=1;i<=n;i++) { for(int j=0;j<i;j++) if(dp[j] && can[j+1][i]) dp[i]=1; // cout<<dp[i]<<" "; } // cout<<endl; if(dp[n]) printf("Yes\n"); else printf("No\n"); return 0; }
// author: xay5421 // created: Sat May 29 20:25:20 2021 #ifdef xay5421 #define D(...) fprintf(stderr,__VA_ARGS__) #else #define D(...) ((void)0) //#define NDEBUG #endif #include<bits/stdc++.h> #define SZ(x) ((int)(x).size()) #define rep(i,a,b) for(int i=(a);i<=(b);++i) using namespace std; const int N=505; int T,n,a[N]; bool ok(){ rep(i,1,n)if(a[i]!=i)return 0; return 1; } int main(){ #ifdef xay5421 freopen("a.in","r",stdin); #endif scanf("%d",&T); rep(_,1,T){ D("_=%d\n",_); scanf("%d",&n); rep(i,1,n)scanf("%d",&a[i]); vector<int>ans; while(1){ if(ok())break; bool flg=0; for(int i=(n-1)&1?n-1:n-2;i>=1;i-=2){ if(a[i]>a[i+1]){ swap(a[i],a[i+1]),ans.push_back(i); flg=1; break; } } if(flg==0){ swap(a[1],a[2]),ans.push_back(1); } if(ok())break; flg=0; for(int i=2;i<n;i+=2){ if(a[i]>a[i+1]){ swap(a[i],a[i+1]),ans.push_back(i); flg=1; break; } } if(flg==0){ swap(a[2],a[3]),ans.push_back(2); } } printf("%d\n",SZ(ans)); for(int x:ans)printf("%d ",x); puts(""); } return 0; }
/* Piyush Sharma*/ #include <bits/stdc++.h> typedef long long ll; using namespace std; int main() { ll testcase = 1; // ll testcase; // cin >> testcase; while (testcase > 0) { double n, D, H; cin >> n >> D >> H; double maxVal = INT_MIN; double backup = 0 * 1.0000; while ( n > 0 ) { double d, h; cin >> d >> h; double res = double((h*1.0) - ((d*1.0)*(((H-h)*1.0)/(D-d)))); if ( res >= maxVal ) { maxVal = res; } n--; } if ( maxVal <= 0 ) { cout << setprecision(16) << backup; } else { cout << setprecision(16) << maxVal; } testcase--; } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,t,n) for(int64_t i=t;i<n;i++) #define Sort(a) sort(a.begin(),a.end()) #define rSort(a,n,m) sort(a.begin()+n-1,a.begin()+m) #define Reverse(a) reverse(a.begin(),a.end()) #define rReverse(a,n,m) reverse(a.begin()+n-1,a.begin()+m) #define MOD 1000000007 #define sign(i) -1*pow(-1,i) #define vi(A,N,i) vector<int64_t> A(N,i) #define vs(A,N,i) vector<string> A(N,i) #define vb(A,N,i) vector<bool> A(N,i) #define INF ((1LL<<62)-(1LL<<31)) //((a+b+c)-max(a,max(b,c))-min(a,min(b,c))) /*template <class T> }*/ //cout << fixed << setprecision(桁数); int64_t def_str(string x,string y){ int64_t def=0; rep(i,0,(int64_t)x.size()){ if(x[i]!=y[i]){ def++; } } return def; } int main() { //int64_t a,b,c,d,e,f,g,h,hi,ans=0,now_ans=0,mlt_ans=1; double a,b,c,d,e,f,ans=0,now_ans=0,mlt_ans=1; string x,y,z; char s,t,u; bool frag=false,frag1=false,frag2=false; vector<int64_t> A{},B{},C{},D{}; vector<string> Cg{},Dg{}; vector<char> E{},F{}; vector<bool> G(26,false); cin>>a>>b>>c; //cin>>x; //cin>>s>>t;//////////////////////// rep(i,0,a){ cin>>d>>e; f=-(b*(c-e)/(b-d))+c; ans=max(ans,f); } cout << fixed << setprecision(20); cout<<ans; }
#include <iostream> // cout, endl, cin #include <string> // string, to_string, stoi #include <vector> // vector #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <utility> // pair, make_pair #include <tuple> // tuple, make_tuple #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include <map> // map #include <queue> // queue, priority_queue #include <set> // set #include <stack> // stack #include <deque> // deque #include <unordered_map> // unordered_map #include <unordered_set> // unordered_set #include <bitset> // bitset #include <cctype> // isupper, islower, isdigit, toupper, tolower #include <stdexcept> #include<math.h> #include<iomanip> using namespace std; using Graph=vector<vector<int>>; using ll=long long ; #define rep(i,n) for(int i=0;i<(n);i++) #define f first #define sc second const int mod=1'000'000'007; // UnionFind // coding: https://youtu.be/TdR816rqc3s?t=726 // comment: https://youtu.be/TdR816rqc3s?t=6822 struct UnionFind { vector<int> d; UnionFind(int n=0): d(n,-1) {} int find(int x) { if (d[x] < 0) return x; return d[x] = find(d[x]); } bool unite(int x, int y) { x = find(x); y = find(y); if (x == y) return false; if (d[x] > d[y]) swap(x,y); d[x] += d[y]; d[y] = x; return true; } bool same(int x, int y) { return find(x) == find(y);} int size(int x) { return -d[find(x)];} }; int fact(int n){ if(n==0){ return 1; }else{ return n*fact(n-1); } } bool is_prime(int x){ if(x<=1) return false; for(int i=2;i*i<x;i++){ if(x%i==0) return false;} return true;} template<class T>void chmin(T& a,T b){ if(a>b){ a=b; } } template<class T>void chmax(T& a,T b){ if(a<b){ a=b; } } int gcd(int x, int y) { if(x % y == 0) { return y; } else { return gcd(y, x % y); } } ll f(ll x,ll c,ll d){ return x-x/c-x/d+x/(c/(gcd(c,d))*d); } string to_oct(int n){ string s; while(n){ s = std::to_string(n%8) + s; n /= 8; } return s; } using namespace std; int main(){ int a,b,c; cin>>a>>b>>c; if(a*a+b*b<c*c){ cout << "Yes" << endl; }else{ cout << "No" << endl; } }
#include <bits/stdc++.h> #define int long long #define INT_MAX INT64_MAX #define INT_MIN INT64_MIN #define PI 3.14159265358979323846 #define CLK clock_t clk = clock();//Start of main #define OCLK cerr << "Time (in ms): " << (double)(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';//End of main #define MOD 1000000007 /* DEFINE cout */ #define pln cout << "===============================\n" #define on cout<<"\n" #define os cout<<" " #define o2(a,b) cout<<a<<" "<<b #define o(a) cout << a #define bitcount __builtin_popcountll /* DEFINE cout */ #define endl "\n" #define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);//fastio using namespace std; struct hash_pair { // use pair as key in unordered_map<pair<int,int>,int,hash_pair>; template <class T1, class T2> size_t operator()(const pair<T1, T2>& p) const { auto hash1 = hash<T1>{}(p.first); auto hash2 = hash<T2>{}(p.second); return hash1 ^ hash2; } }; bool prime[10000001]; int P=MOD-2; int factorial[10000001]={0}; int powerFunction(int x,int y){ int res = 1; int p = MOD; x = x % p; while (y > 0){ if (y & 1) res = (res*x) % p; y = y>>1; x = (x*x) % p; } return res; } void sieveFunction(int maxLimit){ memset(prime, true, sizeof(prime)); prime[0] = prime[1]=false; for(int i=2; maxLimit >= i ; i++){ if(prime[i]){ for(int j=2*i ; maxLimit >= j ; j+=i) prime[j]=false; } } } void factorialFunction(int maxLimit){ factorial[0]=1; for(int i=1 ; i <= maxLimit ; i++) factorial[i]=(factorial[i-1]*i)%MOD; return; } int gcd(int a, int b){ if (b == 0) return a; return gcd(b, a % b); } signed main(){ int n, m, t; cin >> n >> m >> t; int a[m], b[m]; int batt = n; int tm = 0; bool fg = true; for(int i=0; m>i; i++){ cin >> a[i] >> b[i]; int reach = a[i] - tm; // cout << batt << endl; if(batt > reach){ batt -= reach; }else{ fg = false; } int stay = b[i]-a[i]; batt += stay; batt = min(n, batt); tm = b[i]; } // cout << batt << endl; int rem = t - b[m-1]; if(batt <= rem){ fg = false; } if(fg){ cout << "Yes\n"; }else{ cout << "No\n"; } }
#include <stdio.h> typedef long long ll; int main(void) { ll i, j, k, n, a, b, c = 2, s, t, now; bool ans = true; scanf("%lld%lld", &n, &k); if(k > n * n * n / 2) ans = false, k = n * n * n - k + 1; s = n + n + 1; while(s - c > 1) { t = (s + c) / 2; now = t * (t - 1) * (t - 2) / 6; if(t > n + 2) now -= (t - n) * (t - n - 1) * (t - n - 2) * 3 / 6; if(now < k) c = t; else s = t; } t = c; k -= t * (t - 1) * (t - 2) / 6; if(t > n + 2) k += (t - n) * (t - n - 1) * (t - n - 2) * 3 / 6; c++; now = 0; for(i = 1; ; ++i) { if(c - i > n) t = 2 * n - c + i + 1; else t = c - i - 1; if(now + t >= k) { a = i, k -= now; break; } now += t; } for(i = 1; k; ++i) if(a + i + n >= c) --k; b = i - 1; if(ans) printf("%lld %lld %lld", a, b, c - a - b); else printf("%lld %lld %lld", n - a + 1, n - b + 1, n - c + a + b + 1); return 0; }
//ABC 200 E - Patisserie ABC 2 //https://atcoder.jp/contests/abc200/tasks/abc200_e #include <bits/stdc++.h> using namespace std; long long dp[4][3000005] = {}; int main() { int n; long long k; cin >> n >> k; //已选了几个数,其数字和是多少 dp[0][0] = 1; for(int i = 0; i < 3; i++) { // 推送给、贡献给父问题 for(int j = 0; j <= i * n; j++) { dp[i + 1][j + 1] += dp[i][j]; //区间统一修:差分 dp[i + 1][j + n + 1] -= dp[i][j]; } for(int j = 1; j <= (i + 1) * n; j++) //差分+前缀和 dp[i + 1][j] += dp[i + 1][j - 1]; //才是最后的值 } int x; for(int i = 3; i <= 3 * n; i++) if(k <= dp[3][i]) { x = i; break; } else k -= dp[3][i]; //为何要减去? for(int i = 1; i <= n; i++) { int jmi = max(1, x - i - n); int jma = min(n, x - i - 1); if(jmi > jma) continue; if(k > (jma - jmi + 1)) { k -= (jma - jmi + 1); continue; } int y = jmi + k - 1; int z = x - i - y; cout << i << ' ' << y << ' ' << z << '\n'; return 0; } }
#include<bits/stdc++.h> using namespace std; const int M = 100005; #define ll long long int ll N = 1e9 + 7; ll Z = 998244353; #define all(x) (x).begin(), (x).end() #define deb(x) cerr << #x << " = " << x <<"\n"; #define rep(i, begin, end) for (__typeof(end) i = (begin) — ((begin) > (end)); i != (end) — ((begin) > (end)); i += 1 — 2 * ((begin) > (end))) ll power(ll x, unsigned int y, int p) { ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res*x) % p; y = y>>1; x = (x*x) % p; } return res; } ll modinv(ll x, int p){ return (power(x, p-2, p)); } bool compare(const pair<int, int> &p1, const pair<int, int> &p2){ return (p1.first < p2.first); // Ascending Order // return (p1.first > p2.first); // Descending Order } // min({args}), max({args}) void precompute(){ } int main(){ #ifdef SARTHAK freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("error.txt", "w", stderr); auto start = chrono::high_resolution_clock::now(); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t=1; //cin>>t; precompute(); while(t--){ int n; cin>>n; cout<<(n-1)/100 + 1<<"\n"; } #ifdef SARTHAK auto end = chrono::high_resolution_clock::now(); double time_taken = chrono::duration_cast<chrono::nanoseconds>(end - start).count(); time_taken *= 1e-9; cout << "\nTime taken by program is : " << fixed << time_taken << setprecision(9); cout << " sec" << endl; #endif return 0; }
#include<bits/stdc++.h> using namespace std; void century(int year) { if(year<=0) return; else if(year % 100 == 0) { cout<<(year/100); } else cout<<(year /100) +1; } int main() { int N; cin>>N; // year// century(N); return 0; }
#include <algorithm> #include <array> #include <cassert> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> using namespace std; using ll = long long; const int MAX_H = 2e5; const int MAX_W = 2e5; // From https://cp-algorithms.com/data_structures/fenwick.html struct FenwickTree { vector<int> bit; // binary indexed tree int n; FenwickTree(int n) { this->n = n; bit.assign(n, 0); } FenwickTree(vector<int> a) : FenwickTree(a.size()) { for (size_t i = 0; i < a.size(); i++) add(i, a[i]); } int sum(int r) { int ret = 0; for (; r >= 0; r = (r & (r + 1)) - 1) ret += bit[r]; return ret; } int sum(int l, int r) { return sum(r) - sum(l - 1); } void add(int idx, int delta) { for (; idx < n; idx = idx | (idx + 1)) bit[idx] += delta; } void set(int idx, int val) { int curr = sum(idx, idx); if (curr == 1) add(idx, -1); add(idx, val); } }; vector<int> byRow[MAX_H + 1], byCol[MAX_W + 1]; int main() { int h, w, m; scanf("%d %d %d", &h, &w, &m); for (int i = 0; i < m; i++) { int x, y; scanf("%d %d", &x, &y); byRow[x].push_back(y); byCol[y].push_back(x); } for (int i = 1; i <= h; i++) { byRow[i].push_back(w + 1); sort(byRow[i].begin(), byRow[i].end()); } for (int i = 1; i <= w; i++) { byCol[i].push_back(h + 1); sort(byCol[i].begin(), byCol[i].end()); } ll ans = 0; // Go right, then down for (int i = 1; i < byRow[1].front(); i++) { assert(byCol[i].front() > 1); ans += byCol[i].front() - 1; } FenwickTree blockedColumns(w + 1); // Go down, then right for (int i = 1; i < byCol[1].front(); i++) { assert(!byRow[i].empty()); assert(byRow[i].front() > 1); // Add cells that in columns you can't reach by going right first ans += max(0, byRow[i].front() - byRow[1].front()); // Add cells that are blocked from above ans += blockedColumns.sum(1, byRow[i].front() - 1); for (int blockedColumn : byRow[i]) { if (blockedColumn < byRow[1].front()) blockedColumns.set(blockedColumn, 1); } } printf("%lld\n", ans); 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 FOR(i,m,n) for(ll i=ll(m); i<ll(n); i++) #define ALL(obj) (obj).begin(),(obj).end() #define VI vector<int> #define VP vector<pair<ll,ll>> #define VPP vector<pair<int,pair<int,int>>> #define VLL vector<long long> #define VVI vector<vector<int>> #define VVLL vector<vector<long long>> #define VC vector<char> #define VS vector<string> #define VVC vector<vector<char>> #define VB vector<bool> #define VVB vector<vector<bool>> #define fore(i,a) for(auto &i:a) typedef pair <int, int> P; template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>; template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } const ll INF = (1 << 30) - 1; const ll INFL = 1LL << 60; const ll mod = 1000000007; VLL tate[200005]; VLL yoko[200005]; VLL cnt[200005]; struct Segment_tree { using T = ll; ll n; vector<T> data; const T out = 0LL; inline T vmerge(T l, T r) { return l + r; } Segment_tree(ll n) :n(n) { data.assign(2 * n, out); } void update(ll p, T x) { // set value at position p for (data[p += n] = x; p > 1; p >>= 1) { data[p >> 1] = vmerge(data[p], data[p ^ 1]); } } T query(ll l, ll r) { // sum on interval [l, r) T resl = out, resr = out; for (l += n, r += n; l < r; l >>= 1, r >>= 1) { if (l & 1) resl = vmerge(data[l++], resl); if (r & 1) resr = vmerge(resr, data[--r]); } return vmerge(resl, resr); } }; int main() { ll h, w, m; cin >> h >> w >> m; vector<pair<ll, ll>> v(m); REP(i, m) { cin >> v[i].first >> v[i].second; v[i].first--; v[i].second--; tate[v[i].first].push_back(v[i].second); yoko[v[i].second].push_back(v[i].first); } REP(i, 200005) { sort(ALL(tate[i])); sort(ALL(yoko[i])); } ll x; if (tate[0].size() == 0)x = w; else x = tate[0][0]; ll ans = 0; REP(i, x) { if (yoko[i].size() == 0) { ans += h; cnt[h].push_back(i); } else { ans += yoko[i][0]; cnt[yoko[i][0]].push_back(i); } //cerr << " "<<ans << endl; } FOR(i, x, w) { cnt[0].push_back(i); } Segment_tree rsq(200005); cerr << ans << endl; ll y; if (yoko[0].size() == 0)y = h; else y = yoko[0][0]; cerr << y << endl; FOR(i, 0, y) { if (tate[i].size() == 0) { ans += rsq.query(0, w); } else { ans += rsq.query(0, tate[i][0]); } for (ll j : cnt[i]) { //cerr << i << ' ' << j << endl; rsq.update(j, 1); } } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; #define int long long int #define rep(i,a,b) for(int i=a;i<b;i++) void abcd(){ int n,k; string s; cin >> s; n=0; rep(i,0,9){ if(s[i]=='Z' && s[i+1]=='O' && s[i+2]=='N' && s[i+3]=='e'){ n++; } } cout << n; } int32_t main(){ int t=1; // scanf("%lld",&t); while(t--){ abcd(); } return 0; }
#include<bits/stdc++.h> using namespace std; int main() {string s; cin>>s; int ans=0; string a="ZONe"; for(int i=0;i<9;i++) {string x=s.substr(i,4); if(x==a) {ans++;}} cout<<ans; return 0;}
#include <bits/stdc++.h> using namespace std; #define rep(i,x,n) for(int i=x;i<(int)n;++i) #define sp(p) cout<<setprecision(16)<<fixed<<p<<endl; #define ceiling(a,b) ((a+b-1)/b) #define out(a) cout<<a<<endl; #define vout(v) rep(i,0,v.size())cout<<v[i]<<(i==v.size()-1?"\n":" "); #define vvout(vv) rep(j,0,vv.size()){vout(vv[j])} #define mout(m) for(auto&e:m)cout<<e.first<<": "<<e.second<<endl; #define _CHK_ 1 #define chk(a) if(_CHK_){cout<<#a<<": ";out(a)} #define vchk(v) if(_CHK_){cout<<#v<<": ";vout(v)} #define vvchk(vv) if(_CHK_){cout<<#vv<<": "<<endl;vvout(vv)} #define mchk(m) if(_CHK_){cout<<#m<<": "<<endl;mout(m)} template<int MOD> struct Fp { long long val; constexpr Fp(long long v = 0) noexcept : val(v % MOD) { if (val < 0) val += MOD; } constexpr int getmod() { return MOD; } constexpr Fp operator - () const noexcept { return val ? MOD - val : 0; } constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; } constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; } constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; } constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; } constexpr Fp& operator += (const Fp& r) noexcept { val += r.val; if (val >= MOD) val -= MOD; return *this; } constexpr Fp& operator -= (const Fp& r) noexcept { val -= r.val; if (val < 0) val += MOD; return *this; } constexpr Fp& operator *= (const Fp& r) noexcept { val = val * r.val % MOD; return *this; } constexpr Fp& operator /= (const Fp& r) noexcept { long long a = r.val, b = MOD, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } val = val * u % MOD; if (val < 0) val += MOD; return *this; } constexpr bool operator == (const Fp& r) const noexcept { return this->val == r.val; } constexpr bool operator != (const Fp& r) const noexcept { return this->val != r.val; } friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept { return os << x.val; } // friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept { // if (n == 0) return 1; // auto t = modpow(a, n / 2); // t = t * t; // if (n & 1) t = t * a; // return t; // } }; const long long MOD = 1000000007; using mint = Fp<MOD>; mint modpow(const mint &a, int64_t n){ if(n==0)return 1; mint t=modpow(a,n/2); t=t*t; if(n&1)t=t*a; return t; } int main(){ int64_t H,W; cin>>H>>W; vector<vector<char>> S(H, vector<char>(W)); for (int64_t i = 0; i < H; i++) { for (int64_t j = 0; j < W; j++) { cin>>S[i][j]; } } // vvchk(S) vector<vector<int64_t>> dp(H, vector<int64_t>(W, 0)); vector<vector<int64_t>> x(H, vector<int64_t>(W, 0)); vector<vector<int64_t>> y(H, vector<int64_t>(W, 0)); vector<vector<int64_t>> z(H, vector<int64_t>(W, 0)); dp[0][0]=1; for (int64_t i = 0; i < H; i++) { for (int64_t j = 0; j < W; j++) { if(i==0&&j==0)continue; if(j-1>=0&&S[i][j-1]=='.'&&S[i][j]=='.') x[i][j]=x[i][j-1]+dp[i][j-1]; if(i-1>=0&&S[i-1][j]=='.'&&S[i][j]=='.') y[i][j]=y[i-1][j]+dp[i-1][j]; if(j-1>=0&&i-1>=0&&S[i-1][j-1]=='.'&&S[i][j]=='.') z[i][j]=z[i-1][j-1]+dp[i-1][j-1]; dp[i][j]=x[i][j]+y[i][j]+z[i][j]; dp[i][j]%=MOD; } } // vvchk(x) // vvchk(y) // vvchk(z) // vvchk(dp) out(dp[H-1][W-1]) return 0; }
#include<bits/stdc++.h> #include<iostream> #include<string> #include<cmath> #include<cstdio> #include<cctype> #include<cstring> #include<iomanip> #include<cstdlib> #include<ctime> #include<set> #include<map> #include<utility> #include<queue> #include<vector> #include<stack> #include<sstream> #include<algorithm> /************************************************/ #define rep(i,n) for(int i=0;i<n;i++) #define m_p make_pair #define pb push_back #define fr first #define se second #define forn(i,a,n) for(int i=a;i<n;i++) #define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++) #define pii pair<int,int> #define vi vector<int> #define ll long long #define sz(s) s.size() #define all(s) s.begin(),s.end() #define zero(x) memset(x,0,sizeof(x)) #define vii vector<pair<int,int> > #define mpis map<int,string> #define mpii map<int,int> #define mpsi map<string,int> #define re return #define mod 1000000007 /************************************************/ using namespace std; long long get(){ char c=getchar(); long long x=0LL; while(c<'0'||c>'9') c=getchar(); while(c>='0'&&c<='9'){ x*=10LL; x+=(c-'0'); c=getchar(); } return x; } string i_t_s(int x){ string t=""; while(x){ t+=x%10+'0'; x/=10; } reverse(all(t)); re t; } int s_t_i(string t){ int x=0; rep(i,sz(t)){ x=x*10+(t[i]-'0'); } re x; } bool vis[8]; int n; ll t[8][8]; ll k; int ans; void dfs(int x,int cnt,ll sum){ if(cnt==n&&x==0&&sum==k){ ans++; re; } if(vis[x]) re; vis[x]=true; rep(i,n){ if(sum+t[x][i]>k) continue; dfs(i,cnt+1,sum+t[x][i]); } vis[x]=false; } int main(){ ios::sync_with_stdio(0); cin>>n>>k; rep(i,n) rep(j,n) cin>>t[i][j]; dfs(0,0,0); cout<<ans; re 0; }
// clang-format off #pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<ll, ll>; using G = vector<vector<ll>>; #define G(i, j) i, vector<ll>(j) #define Gv(i, j, k) i, vector<ll>(j, k) #define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i) #define rep1(i,n) for(ll i=1, i##_len=(n); i<=i##_len; ++i) #define rrep(i,n) for(ll i=n-1; i>=0; --i) #define rrep1(i,n) for(ll i=n; i>0; --i) #define all(x) (x).begin(),(x).end() #define SORT(x) sort(all(x)) #define SORT_DESC(x) sort((x).rbegin(),(x).rend()) #define pb push_back #define mp make_pair #define coutl cout<<fixed<<setprecision(10) #define ANS(ans) cout<<ans<<endl #define END(ans) ANS(ans); return const ll LINF = (1LL << 62) - 1; const int INF = (1 << 30) - 1; template<class T>inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;} template<class T>inline bool chmin(T &a, const T &b){if (b<a){a=b;return 1;}return 0;} // clang-format on void solve(std::string S) { ll count = 0; ll len = S.length(); for (ll i = 0; i < len; ++count) { ll ret = S.find("ZONe", i); if (ret == string::npos) break; i = ret + 1; } ANS(count); } // clang-format off int main() { std::string S; std::cin >> S; solve(S); return 0; }
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define pb push_back #define mp make_pair #define rep(i,n) for (int i = 0;i < n;i++) typedef long long ll; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif string s; int p1 = 0; int p2 = 1; int p3 = 2; int p4 = 3; int count = 0; cin >> s; while (p4 < s.size()) { if (s[p1] == 'Z' && s[p2] == 'O' && s[p3] == 'N' && s[p4] == 'e') { count++; } p1++; p2++; p3++; p4++; } cout << count; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int H, W; cin >> H >> W; int count=0; char S[H][W]; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { cin >> S[i][j]; } } for (int i = 1; i < H-1; i++) { for (int j = 1; j < W-1; j++) { if (S[i][j] == '.') { if (S[i-1][j-1]=='#' && S[i-1][j]=='#' && S[i][j-1]=='#') { count ++; } if (S[i+1][j-1]=='#' && S[i+1][j]=='#' && S[i][j-1]=='#') { count ++; } if (S[i-1][j+1]=='#' && S[i-1][j]=='#' && S[i][j+1]=='#') { count ++; } if (S[i+1][j+1]=='#' && S[i+1][j]=='#' && S[i][j+1]=='#') { count ++; } } } } cout << 4 + 2*count << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i) #define rep(i, n) drep(i, 0, n - 1) #define P pair<ll, ll> #define all(a) (a).begin(), (a).end() int main(){ ll H, W; cin >> H >> W; vector<string> S(H); rep(i, H) cin >> S.at(i); ll ans = 0; ll dh[4] = {0, 1, 0, 1}; ll dw[4] = {0, 0, 1, 1}; rep(h, H-1){ rep(w, W-1){ ll count = 0; rep(i, 4){ ll nh = h + dh[i]; ll nw = w + dw[i]; if(S[nh][nw] == '#') count++; } if(count == 1 || count == 3) ans++; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main(){ long long n; cin >> n; long long tsum = 0; while(n--){ long long a, b; cin >> a >> b; long long sum1 = ((a-1) * a) / 2; long long sum2 = ( b * (b+1)) / 2; long long sum = sum2 - sum1; tsum = tsum + sum; } cout << tsum << endl; return 0; }
#include <iostream> #include <fstream> #include <cstdio> #include <string> #include <stack> #include <queue> #include <random> #include <deque> #include <cassert> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <numeric> #include <sstream> #include <iomanip> #include <algorithm> #include <vector> #include <list> #include <forward_list> #include <array> #include <cstring> #include <cmath> #include <tuple> #include <complex> #include <bitset> #include <climits> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<double, double>; using pld = pair<ld, ld>; int main() { ios::sync_with_stdio(0); cin.tie(0); ll N, K; cin >> N >> K; ll res = 0; for (ll cur_sum = 2 - min(0ll, K); cur_sum <= 2 * N - max(0ll, K); ++cur_sum) { res += (abs(cur_sum - 2 * max(1ll, cur_sum - N)) + 1) * (abs(cur_sum + K - 2 * max(1ll, cur_sum + K - N)) + 1); } cout << res; }
#include<cstdio> using namespace std; int n,k,calc[200]; int dp[200][200]; char s[200]; inline int dfs(int cur,int p) { if(p==0) { if(s[cur]=='R') return 1; else if(s[cur]=='P') return 2; else if(s[cur]=='S') return 3; } if(dp[cur][p]) return dp[cur][p]; int l=dfs(cur,p-1); int r=dfs((cur+calc[p-1])%n,p-1); int ans; if(l==r) ans=l; else { if(l==1) { if(r==2) ans=2; else ans=1; } else if(l==2) { if(r==1) ans=2; else ans=3; } else if(l==3) { if(r==1) ans=1; else ans=3; } } dp[cur][p]=ans; return ans; } inline void prework() { scanf("%d%d",&n,&k); scanf("%s",s); calc[0]=1; for(int i=1; i<=k; i++) calc[i]=calc[i-1]*2%n; int op=dfs(0,k); if(op==1) puts("R"); else if(op==2) puts("P"); else puts("S"); } int main() { prework(); return 0; }
#include <bits/stdc++.h> using namespace std; char battle(char l_hand, char r_hand) { if ((l_hand == 'R' && r_hand == 'S') || (l_hand == 'P' && r_hand == 'R') || (l_hand == 'S' && r_hand == 'P')) { return l_hand; } if ((r_hand == 'R' && l_hand == 'S') || (r_hand == 'P' && l_hand == 'R') || (r_hand == 'S' && l_hand == 'P')) { return r_hand; } return l_hand; } int main() { int N, K; string S; cin >> N >> K >> S; for (int k = 0; k < K; k++) { string T = S + S; S = ""; for (int i = 0; i < N * 2; i += 2) { S += battle(T.at(i), T.at(i + 1)); } } cout << S.at(0) << endl; }
#include <bits/stdc++.h> //#include <atcoder/all> #define rep(i, n) for (int i=0; i < (n); i++) using namespace std; //using namespace atcoder; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; typedef pair<int, int> P; const int INF = 1 << 30; const ll LINF = 1LL << 61; const int NIL = -1; const int MAX = 10000; const int MOD = 1000000007; const double pi = 3.141592653589; bool is_seven_in_ten(int x){ while(x!=0){ if(x % 10 == 7) return true; else{ x /= 10; } } return false; } bool is_seven_in_eight(int x){ while(x!=0){ if(x % 8 == 7){ return true; } else{ x /= 8; } } return false; } int main() { int n; cin >> n; int ten = 0, eight = 0, ten_eight = 0; for(int i=1;i<=n;i++){ if(is_seven_in_eight(i) && is_seven_in_ten(i)){ ten_eight++; } if(is_seven_in_ten(i)){ ten++; } if(is_seven_in_eight(i)){ eight++; } } cout << n - ten - eight + ten_eight << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define tcase int _; cin >> _; while(_--) //#define int long long const int MOD = 1e9+7; const int MAX = 1e6; const int INF = 2e9; void solve() { int n; cin >> n; int a1=0, a2=0; vector<int> v(n, 1); for(int i=1; i<=n; i++) { int ok=1; int x = i; while(x) { if(x%10 == 7) ok=0; x /= 10; } if(!ok) v[i-1] = 0; } for(int i=1; i<=n; i++) { int ok=1; for(int j=0; j<30; j+=3) { if(((7<<j) & i) == (7<<j)) { ok=0; break; } } if(!ok) v[i-1] = 0; } int ans=0; for(int x : v) ans += x; cout << ans << endl; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); solve(); return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef long double ld; #define F first #define S second const int MOD = 1e9 + 7;//XXX const int C = 26;//XXX void add(int &x, int y){ x += y; while (x >= MOD) x -= MOD; while (x < 0) x += MOD; } int fix(int x){ while (x >= MOD) x -= MOD; while (x < 0) x += MOD; return x; } int pw(int a, int b){ int ret = 1; while (b){ if (b & 1) ret = 1ll*ret*a%MOD; b >>= 1; a = 1ll*a*a%MOD; } return ret; } const int MAXN = 1e6 + 10; map<ll,ll> mp; ll go(ll X, ll Y) { if(Y <= X) { return X - Y; } if(mp.count(Y)) return mp[Y]; if(Y % 2 == 0) { return mp[Y] = min(go(X, Y/2)+1, Y - X); } return mp[Y] = min(go(X, Y+1), go(X, Y-1)) + 1; } void solve() { ll X, Y; cin >> X >> Y; cout << go(X, Y) << "\n"; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); //cout << fixed << setprecision(6); int te = 1; //cin >> te; for (int w = 1; w <= te; w++){ //cout << "Case #" << w << ": "; solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using ii = pair<int,int>; const int MAX = 1e6+10; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int l,r; cin >> l >> r; ll res = 0; for(int i=2;i<=r;i++){ int t = i; int fail = 0; int factors = 0; if( t%4 == 0){ continue; } if( t%2 == 0){ factors ++; t/=2; } for(int d =3;d*d<=t;d+=2){ if( t%d ) continue; factors ++; if( t%(d*d) == 0 ){ fail = 1; break; } t/=d; } if( t > 1) factors ++; if( fail ) continue; int sign = -1; if( factors%2 ) sign = 1; ll sumand = r/i - (l-1)/i; sumand = sumand*sumand*sign; res += sumand; } for(int i=max(2,l);i<=r;i++){ res -= 2*(r/i) - 1; } cout << res << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; #define repp(i, a, b) for(int i = a; i <= b; i++) #define rep(i, a, b) for(int i = a; i < b; i++) #define rrep(i, b, a) for(int i = b; i >= a; i--) #define pb emplace_back #define ff first #define ss second #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() #define LB lower_bound #define UB upper_bound #define MP make_pair #define in_edges(M) repp(I, 1, M){int A, B; cin >> A >> B; v[A].pb(B), v[B].pb(A);} #define endl "\n" const ll MOD = 1e9 + 7; const ll INF = 1e18 + 1; ll power(ll x,ll y){ll res = 1; x%=MOD;while(y>0){if(y&1)res=(res*x)%MOD;y=y>>1,x=(x*x)%MOD;}return res;} void pre(); void solve(); void post(); map<ull, bool> m; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; pre(); repp(tst, 1, t){ solve(); post(); } } /*--------------------------------------------------------------------------------------------------------------------*/ void pre(){ ull a = 3, b = 5; while(a < INF){ b = 5; while(b < INF){ m[a + b] = 1; if(b * 5 < b) break; b *= 5; } if(a * 3 < a) break; a *= 3; } } void solve(){ ull n; cin >> n; ull a = 3, b = 5; ll x = 1, y = 1; while(a < INF){ b = 5; y = 1; while(b < INF){ if(a + b == n){ cout << x << " " << y; return; } m[a + b] = 1; if(b * 5 < b) break; b *= 5; y++; } if(a * 3 < a) break; a *= 3; x++; } cout << -1; } void post(){}
#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <cassert> #include <algorithm> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> #define repi(i,a,b) for(ll i=(a);i<(b);++i) #define rep(i,a) repi(i,0,a) #define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i) #define repd(i,a) repdi(i,a,0) #define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it ) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define endl '\n' #define debug(x) std::cerr << #x << " = " << (x) << endl; using ll = long long; using P = std::pair<ll, ll>; constexpr ll INF = 1ll<<60; 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 S, class T> std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a ) { std::cout << '(' << a.first << ", " << a.second << ')'; return out; } template<class T> std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a ) { std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; } const ll mod = 998244353; struct mint { ll x; // typedef long long ll; mint(ll x=0):x((x%mod+mod)%mod){} mint operator-() const { return mint(-x);} mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;} mint operator+(const mint a) const { return mint(*this) += a;} mint operator-(const mint a) const { return mint(*this) -= a;} mint operator*(const mint a) const { return mint(*this) *= a;} mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod-2);} mint& operator/=(const mint a) { return *this *= a.inv();} mint operator/(const mint a) const { return mint(*this) /= a;} }; std::istream& operator>>(std::istream& is, mint& a) { return is >> a.x;} std::ostream& operator<<(std::ostream& os, const mint& a) { return os << a.x;} struct combination { std::vector<mint> fact, ifact; combination(int n):fact(n+1),ifact(n+1) { assert(n < mod); fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i; ifact[n] = fact[n].inv(); for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i; } mint operator()(int n, int k) { if (k < 0 || k > n) return 0; return fact[n]*ifact[k]*ifact[n-k]; } }; ll N, M; mint mp[5010]; int main() { std::cin >> N >> M; mp[0] = 1; rep( i, N ) mp[i+1] = mp[i]*M; mint ans = mint(N)*mint(M).pow(N); repi( x, 1, M+1 ) { mint dp = 1; repi( w, 1, N ) { ans -= dp*mp[N-(w+1)]*(N-w); dp *= M-x; } } std::cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define FOR(i,s,t) for(int i=(s),_t=(t); i<=_t; ++i) #define DOR(i,s,t) for(int i=(s),_t=(t); i>=_t; --i) #define EOR(i,x) for(int i=Head[x]; ~i; i=Nxt[i]) typedef double db; typedef long long ll; typedef unsigned long long ull; namespace Eddd { char sc() { return getchar(); static const int LEN=100000; static char Buf[LEN],*OP=Buf,*ED=Buf; if(OP==ED) ED=(OP=Buf)+fread(Buf,1,LEN,stdin); return *OP++; } template<class T> void rd(T &x) { static int c,f;x=f=0; while(c=sc(),c<48) if(c=='-') f=1; do x=(x<<3)+(x<<1)+(c^48); while(c=sc(),c>47);if(f) x=-x; } template<class T> void pt(T x) { if(x<0) putchar('-'),x=-x; else if(!x) putchar('0'); static int Stk[30],tp=0; for(; x; x/=10) Stk[tp++]=x%10; while(tp) putchar(Stk[--tp]^48); } template<class T> void ptk(const T &x) { pt(x);putchar(' '); } template<class T> void ptn(const T &x) { pt(x);putchar('\n'); } template<class T> bool chkmi(T &x,const T &y) { return x>y?x=y,true:false; } template<class T> bool chkmx(T &x,const T &y) { return x<y?x=y,true:false; } template<class T> T gcd(const T &x,const T &y) { return y?gcd(y,x%y):x; } } using namespace Eddd; int main() { int n,x; rd(n);rd(x); while(n--) { int a; rd(a); if(a!=x) ptk(a); } putchar('\n'); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N, X; cin >> N >> X; vector<int> A; for (int i = 0; i < N; i++) { int n; cin >> n; if (n != X) { A.push_back(n); } } bool first = true; for (int apple : A) { if (first) { first = false; } else { cout << " "; } cout << apple; } cout << endl; }
#include <stdio.h> int f; long long n, k; long long l, m, r; long long x, y, z; long long r1(long long a) { long long b = a * (a + 1) * (a + 2) / 6; if (a > n) { b -= (a - n) * (a - n + 1) * (a - n + 2) / 2; } return b; } long long r2(long long a) { long long b; if (x <= n) { b = x * (x + 1) / 2; b -= (x - a) * (x - a + 1) / 2; return b; } else { if (x - n < a) { b = n * (n + 1) / 2; b -= (n - a) * (n - a + 1) / 2; b += (x - n) * (a - (x - n) - 1); } else { b = (a + 2 * n - x - 1) * (a + 2 * n - x) / 2; b -= (2 * n - x - 1) * (2 * n - x) / 2; } } return b; } int main() { scanf("%lld%lld", &n, &k); if (2 * k == n * n * n + 1) { printf("%lld %lld %lld\n", (n + 1) / 2, (n + 1) / 2, (n + 1) / 2); return 0; } if (2 * k > n * n * n + 1) { k = n * n * n + 1 - k; f = 1; } r = n + (n - 1) / 2; while (r - l - 1) { m = (l + r) / 2; if (r1(m) < k)l = m; else r = m; } x = r; if (r > n)r = n; l = 0; k -= r1(x - 1); while (r - l - 1) { m = (l + r) / 2; if (r2(m) < k)l = m; else r = m; } y = r; z = k - r2(l); if (n < x && y <= x - n) { z += x - n - y + 1; } if (f)printf("%lld %lld %lld\n", n + 1 - y, n + 1 - z, n + 1 - (x - y - z + 2)); else printf("%lld %lld %lld\n", y, z, x - y - z + 2); }
#include<bits/stdc++.h> typedef long long ll; using namespace std; ll seq[4000005]; int main(){ ll n,k; cin>>n>>k; for(int i=n;i<=n*2-1;i++)seq[i]=i+1-n; for(int i=n*2;i<=n*3-2;i++)seq[i]=n*3-1-i; ll cnt=0,sum=0,S=3; int l=3*n-2,r=4*n-3; for(int I=1;I<=3*n-2;I++){ cnt-=seq[r+1]; cnt+=seq[l]; if(sum+cnt>=k)break; else sum+=cnt; l--; r--; S++; } int p; for(p=1;p<=r-l+1;p++){ if(sum+seq[p+l-1]>=k)break; else sum+=seq[p+l-1]; } for(int i=1;i<=n;i++){ if(p+i>=S-n && p+i<S)sum++; if(sum==k){ cout<<p<<' '<<i<<' '<<S-p-i<<endl; break; } } return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #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; } const long long MOD = 1000000007; long long modpow(long long a,unsigned long long b){ long long base=a,ans=(1LL); while(b){ if(b&1){ ans=ans*base%MOD; } base=base*base%MOD; b>>=1; } return ans; } long long invpow(long long a){ return modpow(a,MOD-2); } class UF{ vector<long> par,rank,size_uf; long _chunk_size; public: UF(long size):_chunk_size(size){ for (long i = 0; i < size; i++) { par.push_back(i); rank.push_back(0); size_uf.push_back(1); } } long find(long x){ if(par[x]==x)return x; return par[x]=find(par[x]); } void unite(long x,long y){ x=find(x); y=find(y); if(x==y)return; --_chunk_size; if(rank[x]<rank[y]){ par[x]=y; size_uf[y]+=size_uf[x]; } else{ par[y]=x; size_uf[x]+=size_uf[y]; if(rank[x]==rank[y])rank[x]++; } } bool same(long x,long y){ return find(x)==find(y); } long operator [](long x){ return this->find(x); } long size(long x){ x=find(x); return size_uf[x]; } long chunk_size(){ return this->_chunk_size; } }; void solve(long long H, long long W, std::vector<std::string> S){ ll K=0; UF uft(H*W),ufy(H*W); For(i,H){ For(j,W){ if(S[i][j]=='.'){ ++K; if(i<H-1&&S[i+1][j]=='.'){ uft.unite(W*i+j,W*(i+1)+j); } if(j<W-1&&S[i][j+1]=='.'){ ufy.unite(W*i+j,W*i+j+1); } } } } ll all = modpow(2,K)*K%MOD; ll diff=0; For(i,H){ For(j,W){ if(S[i][j]=='.'){ ll cnt=uft.size(W*i+j)+ufy.size(W*i+j)-1; diff=(diff+modpow(2,K-cnt))%MOD; } } } cout<<(MOD+all-diff)%MOD<<endl; } int main(){ cout<<setprecision(1000); long long H; scanf("%lld",&H); long long W; scanf("%lld",&W); std::vector<std::string> S(H); for(int i = 0 ; i < H ; i++){ std::cin >> S[i]; } solve(H, W, std::move(S)); return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; constexpr ll mod = 1e9 + 7; ll modpow(ll a, ll b) { ll r = 1; while (b) { if (b & 1) r = r * a % mod; a = a * a % mod; b >>= 1; } return r; } int main() { // ios::sync_with_stdio(false); // cin.tie(nullptr); ll n, w, h, ans = 0, cnt = 0; cin >> h >> w; string s[h]; ll tate[h][w] = {}, yoko[h][w] = {}; rep(i, h) cin >> s[i]; rep(i, h) rep(j, w) if (s[i][j] == '.') cnt++; if (cnt == h * w) { ll t = h + w - 1; ans = (modpow(2, t) - 1) * modpow(2, h * w - t); ans %= mod; ans *= h * w; ans %= mod; cout << ans << endl; return 0; } ans = 0; rep(i, h) rep(j, w) { if (s[i][j] == '#') continue; ll now = 1; for (int k = i - 1; k >= 0; --k) if (s[k][j] == '.') now++; else break; for (int k = i + 1; k < h; ++k) if (s[k][j] == '.') now++; else break; for (int k = j - 1; k >= 0; --k) if (s[i][k] == '.') now++; else break; for (int k = j + 1; k < w; ++k) if (s[i][k] == '.') now++; else break; ll add = (modpow(2, now) - 1) * modpow(2, cnt - now) % mod; (ans += add) %= mod; } cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define w(x) int x;cin>>x;while(x--) #define ll long long int #define ld long double #define pb push_back #define fast ios_base::sync_with_stdio(false);cin.tie(NULL) #define vi vector<int> #define inf 1e18 #define mod 998244353 void solve() { ll no; cin>>no; ll k=5; vector<ll>v5; vector<ll>v3; while(k<=inf){ v5.pb(k); k=k*5; } k=3; while(k<=inf){ v3.pb(k); k=k*3; } int n=v3.size(); int m=v5.size(); for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ if(v3[i]+v5[j]==no){ cout<<i+1<<" "<<j+1<<"\n"; return; } } } cout<<"-1\n"; } int main() { /*#ifndef ONLINE_JUDGE freopen("input.txt", "r",stdin); freopen("output.text", "w",stdout); #endif*/ fast; /*ll t; cin>>t; while(t--)*/ solve(); return 0; }
#include <iostream> #include <climits> #include <list> #include <queue> #include <stack> #include <set> #include <functional> #include <algorithm> #include <string> #include <map> #include <unordered_map> #include <unordered_set> #include <iomanip> #include <cmath> #include <random> #include <bitset> #include <cstdio> #include <numeric> #include <cassert> #include <ctime> using namespace std; #define PB push_back #define MP make_pair #define YES cout << "YES" << endl #define Yes cout << "Yes" << endl #define NO cout << "NO" << endl #define No cout << "No" << endl #define INF (1 << 28) #define LLINF (1LL << 60) #define MOD 998244353 //#define MOD 1000000007 #define rep(i, n) for (int i = 0; i < n; i++) #define llrep(i, n) for (ll i = 0; i < n; i++) using ll = long long; typedef pair<ll, ll> P; int main() { int n; cin>>n; if(floor(1.08*n)<206){ cout << "Yay!" << endl; } else if(floor(1.08*n)==206){ cout << "so-so" << endl; } else{ cout << ":(" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; vector<int> G[25]; int a[25], c[25]; vector<int> tmp; void dfs1(int u) { a[u] = 1; tmp.push_back(u); for (int v : G[u]) { if (!a[v]) dfs1(v); } } long long dfs2(int i) { int u = tmp[i]; bool vis[3] = {false, false, false}; for (int v : G[u]) { if (~c[v]) vis[c[v]] = true; } long long res = 0; for (int j = 0; j < 3; ++j) { if (!vis[j]) { c[u] = j; if (i == (int)tmp.size() - 1) ++res; else res += dfs2(i + 1); c[u] = -1; } } return res; } int main() { int n, m; scanf("%d %d", &n, &m); memset(c, -1, sizeof(c)); for (int i = 1; i <= m; ++i) { int u, v; scanf("%d %d", &u, &v); G[u].push_back(v); G[v].push_back(u); } long long res = 1; for (int i = 1; i <= n; ++i) { if (!a[i]) { tmp.clear(); dfs1(i); res *= dfs2(0); } } printf("%lld\n", res); return 0; }
#include <iostream> #include <string> #include <vector> #include <set> #include <map> #include <queue> #include <stack> #include <algorithm> #include <math.h> #include <cassert> #define rep(i,n) for(int i = 0; i < n; ++i ) using namespace std; using ll = long long; int v[20][2]; int main() { int n,m; cin >> n >> m; vector<int> a(m),b(m); rep(i,m) cin >> a[i] >> b[i], --a[i], --b[i]; int k; cin >> k; rep(i,k) cin >> v[i][0] >> v[i][1], --v[i][0], --v[i][1]; int ans = 0; rep(x,1<<k){ vector<bool> t(n); rep(i,k) t[v[i][x>>i&1]] = true; int res = 0; rep(i,m) if(t[a[i]]&&t[b[i]]) ++res; ans = max(ans,res); } cout << ans << endl; }
#include<bits/stdc++.h> #define pb emplace_back #define pf first #define ps second #define all(x) x.begin(),x.end() #define allr(x) x.rbegin(),x.rend() #define Endl '\n' #define codejam cout<<"Case #"<<t<<": "; #define pl pair<ll,ll> #define mod 1000000007 #define INF 1000000001 #define forn(i,n) for(ll i=0;i<n;i++) #define MAX 200002 #define fast ios_base::sync_with_stdio(false);cin.tie(NULL); using namespace std; typedef long long int ll; ll gcd(ll a,ll b) { if(b==0) return a; return gcd(b,a%b); } //////////////////////////////////// JAI SHREE RAM ///////////////////////////////////// void JAISHREERAM() { ll n,i,j,ans=0; string a; cin>>a; n=a.size(); i=0; while(i<n && a[i]=='0') i++; j=n-1; while(j>=0 && a[j]=='0') j--; while(i<j) { if(a[i]!=a[j]) return void(cout<<"No"); i++,j--; } cout<<"Yes"; } int main() { fast; int T=1; // cin>>T; for(int t=1;t<=T;t++) { // codejam JAISHREERAM(); } return 0; }
#pragma GCC optimize("Ofast") #include<bits/stdc++.h> using namespace std; #define ll long long #define eb emplace_back #define mp make_pair #define pb push_back #define watch(x) cout << (#x) << " = " << (x) << endl; #define w(x) int x; cin >> x; while(x--) #define all(x) (x.begin(), x.end()) #define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr); #define vi vector<int> #define lcm(x, y) (x/__gcd(x, y))*y #define sayHi cout << "Say Hi!!!!!!!!!!!!!!!!!!!!!!!!!\n"; #define rep(i,k,n) for(int i=k; i<n; i++) #define REPR(i,k,n) for (int (i) = (k); (i) >= (n); (i)--) #define sumAll(a) (accumulate ((a).begin(), (a).end(), 0ll)) #define mine(a) (*min_element((a).begin(), (a).end())) #define maxe(a) (*max_element((a).begin(), (a).end())) #define mini(a) (min_element((a).begin(), (a).end()) - (a).begin()) #define maxi(a) (max_element((a).begin(), (a).end()) - (a).begin()) #define lowb(a, x) (lower_bound((a).begin(), (a).end(), (x)) - (a).begin()) #define uppb(a, x) (upper_bound((a).begin(), (a).end(), (x)) - (a).begin()) #define mem0(a) (memset(a, 0, sizeof(a))) #define mem1(a) (memset(a, -1, sizeof(a))) const int MAXN = (int)((1e5) + 100); const long long MOD = 1e9 + 7; bool isPrime(ll n){if(n<2)return false;for(ll i=2;i*i<=n; i++){if(n%i==0)return false;}return true;} int countDigit(ll n){int count=0;while(n!=0){n/=10;++count;}return count;} void removeCharFromString(string &str,const char &ch){str.erase(remove(str.begin(),str.end(),ch),str.end());} void showTime() {cerr<<"\nExecution time: "<<(float)clock()/CLOCKS_PER_SEC<<" secs\n";} long long binExp(long long base,long long pow){ long long result=1; while(pow){ if(pow%2){result*=base;} base*=base; pow/=2; } return result; } long long binExpMod(long long base,long long pow,long long M){ long long result=1; while(pow){ if(pow%2){result=(result*base)%M;} base=(base*base)%M; pow/=2; } return result; } bool sortBySecAsc(const pair<ll,ll> &a, const pair<ll,ll> &b){ return (a.second < b.second); } bool sortBySecDes(const pair<ll,ll> &a, const pair<ll,ll> &b){ return (a.second > b.second); } /*#ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif*/ /*-----------------------------------------------------------------------------------------------------------------*/ int main() { fastIO ll n; cin >> n; if(n==0) { cout << "Yes"; return 0; } while(n%10 == 0) { n/=10; } string s, temp2; s = temp2 = to_string(n); reverse(s.begin(), s.end()); if(temp2 == s) { cout << "Yes"; }else { cout << "No"; } return 0; }
#include <cstdio> #include <cstring> #include <string> #include <iostream> #include <algorithm> #define M 100001 int n, m, pthn, ans[M], head[M]; struct Edge { int nxt, to, w; }pth[M << 2]; void add(int from, int to, int w) { pth[++pthn].to = to, pth[pthn].nxt = head[from]; pth[pthn].w = w, head[from] = pthn; } void dfs(int u, int now, int last) { if (now == -1 && last == -1) ans[u] = 1; else if (now == last) ans[u] = now + 1; else if (now != last) ans[u] = now; if (ans[u] > n) ans[u] = 1; for (int i = head[u]; i; i = pth[i].nxt) { int v = pth[i].to; if (ans[v]) continue; dfs(v, pth[i].w, ans[u]); } } int main() { scanf("%d %d", &n, &m); for (int i = 1, u, v, w; i <= m; ++i) { scanf("%d %d %d", &u, &v, &w); add(u, v, w), add(v, u, w); } dfs(1, -1, -1); for (int i = 1; i <= n; ++i) printf("%d\n", ans[i]); return 0; }
#include<bits/stdc++.h> #define io ios_base::sync_with_stdio(0); #define tie cin.tie(NULL); #define Inf (1LL<<62) #define inf (1<<30) #define ll long long #define pr pair<int,int> #define pb push_back #define fr0(i,n) for(i=0;i<n;i++) #define fr1(i,n) for(i=1;i<=n;i++) #define no cout<<"No\n"; #define yes cout<<"Yes\n"; #define mp make_pair #define nl cout<<"\n"; #define mem(ara,val) memset(ara,val,sizeof(ara)) #define case(cs,n) printf("Case #%d: %lld\n",cs,n) const int mx=2e5; const ll mod=100000007; using namespace std; vector<ll>a(500,Inf),b(500,Inf); ll c[500][500]; bool mat(int n) { int i,j; fr0(i,n) b[0]=min(c[i][0],b[0]); fr0(i,n) a[i]=c[i][0]-b[0]; fr1(j,n-1) { b[j]=c[0][j]-a[0]; fr1(i,n-1) { if(c[i][j]-a[i]!=b[j]) return 0; } } return 1; } int main() { io tie int n,i,j; cin>>n; fr0(i,n) fr0(j,n) cin>>c[i][j]; if(mat(n)) { yes fr0(i,n) cout<<a[i]<<' '; nl fr0(i,n) cout<<b[i]<<' '; nl } else no }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<int> vll; typedef pair<int, int> pii; #define F first #define S second #define PB push_back #define MP make_pair #define ALL(v) v.begin(), v.end() #define rALL(v) v.rbegin(), v.rend() #define INF 1000000007LL #define MOD 998244353LL const int LIM = 2e5 + 5; void solve() { int n; cin >> n; vi v(n); for(auto& i : v) cin >> i; sort(ALL(v)); reverse(ALL(v)); ll ways = 1; for(int i = 1; i < n; i++) { ll p = v[i - 1] - v[i] + 1; ways = ways * p % INF; } ways = ways * (v[n - 1] + 1) % INF; cout << ways << '\n'; } int 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; int MOD = 998244353; int N=3141, M=2718; long comblist[6000]; long result[6000]; long fastpow(long a, int p){ long ans = 1; while(p>0){ if (p%2==1) ans = ans * a % MOD; p >>= 1; a = a * a % MOD; } return ans; } long fastinv(long a){ return fastpow(a, MOD - 2); } void preparecomb(){ comblist[0] = 1; for (int i = 1; i <= N ; i++) { comblist[i] = comblist[i - 1] * (N - i + 1) % MOD * fastinv(i) % MOD; } } void print(auto x){ cout << x << endl; } long solve2(){ //result[i] == f(2i) result[0] = 1; result[1] = comblist[2]; int i = 2; while(2*i<=M){ for (int j = i>>1;j>=0&&2*(i-2*j)<=N; j--){ result[i] += result[j] * comblist[2*(i-2*j)] % MOD; result[j] %= MOD;} i++; } return result[M / 2] % MOD; } int main2() { cin >> N >> M; if (N == 1 || M % 2 == 1) { print(0); return 0; } if (N==2){ print(1); return 0; } preparecomb(); print(solve2()); return 0; } int main(){ while(true){ main2(); break; } }
#include <bits/stdc++.h> #define ld long double #define ll long long #define pb push_back #define mp make_pair #define ff first #define ss second #define no cout<<"NO\n"; #define yes cout<<"YES\n"; #define nl cout<<"\n"; #define sp <<" "<< #define ull unsigned long long #define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL)); #define MOD 1000000007 #define INF LONG_LONG_MAX #define MINF LONG_LONG_MIN using namespace std; bool pr(int n){ if (n <= 1) return 0; for (ll i=2;i*i<=n;i++) if (n%i == 0) return 0; return 1; } int main() { FAST ll a,b;cin>>a>>b; if(a+b>=15 && b>=8){ cout<<1<<endl; } else if(a+b>=10 &&b>=3) { cout<<2<<endl; } else if((a+b)>=3){ cout<<3<<endl; } else{ cout<<4<<endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int N, L; cin >> N >> L; if(N == L){ cout << N << endl; }else if(N != 0 && L != 0){ cout << 0 << endl; }else if(N != 1 && L != 1){ cout << 1 << endl; }else{ cout << 2 << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; #define fi(a,b) for(int i=a;i<b;i++) #define fj(a,b) for(int j=a;j<b;j++) #define ff first #define ss second #define ll long long #define ld long double #define ull unsigned long long #define bp(x) __builtin_popcount(x) #define pr(x) for(auto it: x) cout<<it<<" "; cout<<endl; #define getMax(x) max_element(x.begin(),x.end()) #define getMin(x) min_element(x.begin(),x.end()) #define endl "\n" typedef vector<int> vi; typedef vector< pair<int, int> > vii; typedef vector<long long> vl; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector< pair<ll, ll> > vll; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // auto dist = uniform_int_distribution<int>(l, r); // int dx[] = {1, 0, -1, 0}; // int dy[] = {0, 1, 0, -1}; // int dx[] = { -1, 0, 1, 1, 1, 0, -1, -1}; // int dy[] = { -1, -1, -1, 0, 1, 1, 1, 0}; vector<vi>adj; vl depth, in, out, ans; vector<vi> cache; int tym = 0; void dfs(int u = 0, int pre = -1, int dep = 0) { depth[u] = dep; in[u] = tym++; cache[dep].push_back(in[u]); for (auto v : adj[u]) { if (v == pre) continue; dfs(v, u, dep + 1); } out[u] = tym++; } bool isAnc(int u, int v) { return (in[u] <= in[v] and out[u] >= out[v]); } void omae_wa_mou_shindeiru(int tc) { int n; cin >> n; depth.assign(n, 0); adj.assign(n, vi({})); in.assign(n, 0); out.assign(n, 0); cache.assign(n + 5, vi({})); fi(1, n) { int v; cin >> v; v--; adj[i].push_back(v); adj[v].push_back(i); } dfs(); int q; cin >> q; ans.assign(q, 0); fi(0, q) { ll u, d; cin >> u >> d; u--, d; cout << lower_bound(cache[d].begin(), cache[d].end(), out[u]) - lower_bound(cache[d].begin(), cache[d].end(), in[u]) << endl; } } int main() { ios::sync_with_stdio(0); cin.tie(0); int tc = 1; // cin >> tc; fi(1, tc + 1) { omae_wa_mou_shindeiru(i); } }
#include <bits/stdc++.h> #define fi first #define se second #define rep(i,s,n) for (int i = (s); i < (n); ++i) #define rrep(i,n,g) for (int i = (n)-1; i >= (g); --i) #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define len(x) (int)(x).size() #define dup(x,y) (((x)+(y)-1)/(y)) #define pb push_back #define eb emplace_back #define Field(T) vector<vector<T>> #define pq(T) priority_queue<T,vector<T>,greater<T>> using namespace std; using ll = long long; using P = pair<int,int>; struct ArbitraryModInt { int x; ArbitraryModInt() : x(0) {} ArbitraryModInt(int64_t y) : x(y >= 0 ? y % get_mod() : (get_mod() - (-y) % get_mod()) % get_mod()) {} static int &get_mod() { static int mod = 0; return mod; } static void set_mod(int md) { get_mod() = md; } ArbitraryModInt &operator+=(const ArbitraryModInt &p) { if((x += p.x) >= get_mod()) x -= get_mod(); return *this; } ArbitraryModInt &operator-=(const ArbitraryModInt &p) { if((x += get_mod() - p.x) >= get_mod()) x -= get_mod(); return *this; } ArbitraryModInt &operator*=(const ArbitraryModInt &p) { unsigned long long a = (unsigned long long) x * p.x; unsigned xh = (unsigned) (a >> 32), xl = (unsigned) a, d, m; asm("divl %4; \n\t" : "=a" (d), "=d" (m) : "d" (xh), "a" (xl), "r" (get_mod())); x = m; return *this; } ArbitraryModInt &operator/=(const ArbitraryModInt &p) { *this *= p.inv(); return *this; } ArbitraryModInt operator-() const { return ArbitraryModInt(-x); } ArbitraryModInt operator+(const ArbitraryModInt &p) const { return ArbitraryModInt(*this) += p; } ArbitraryModInt operator-(const ArbitraryModInt &p) const { return ArbitraryModInt(*this) -= p; } ArbitraryModInt operator*(const ArbitraryModInt &p) const { return ArbitraryModInt(*this) *= p; } ArbitraryModInt operator/(const ArbitraryModInt &p) const { return ArbitraryModInt(*this) /= p; } bool operator==(const ArbitraryModInt &p) const { return x == p.x; } bool operator!=(const ArbitraryModInt &p) const { return x != p.x; } ArbitraryModInt inv() const { int a = x, b = get_mod(), u = 1, v = 0, t; while(b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return ArbitraryModInt(u); } ArbitraryModInt pow(int64_t n) const { ArbitraryModInt ret(1), mul(x); while(n > 0) { if(n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } friend ostream &operator<<(ostream &os, const ArbitraryModInt &p) { return os << p.x; } friend istream &operator>>(istream &is, ArbitraryModInt &a) { int64_t t; is >> t; a = ArbitraryModInt(t); return (is); } }; using mint = ArbitraryModInt; void mul(vector<mint> &dp, int d) { int MAX = len(dp)-1; rrep(i,MAX+1,d) { dp[i] -= dp[i - d]; } } void div(vector<mint> &dp, int d) { int MAX = len(dp); rep(i,d,MAX+1) { dp[i] += dp[i - d]; } } int main() { int n, k, m; cin >> n >> k >> m; mint::set_mod(m); vector<mint> dp(n*n*k+1, 0); vector<vector<mint>> vals(n+1, vector<mint>(n*n*k+1)); dp[0] = mint(1); vals[0][0] = dp[0]; rep(i,1,n) { div(dp, i); mul(dp, i*(k+1)); rep(j,0,n*n*k) { vals[i][j] = dp[j]; } } rep(i,0,n) { mint ans = 0; rep(j,0,n*n*k+1) { ans += vals[i][j] * vals[n-i-1][j]; } cout << ans*(k+1)-1 << endl; } return 0; }
#include<bits/stdc++.h> #define ll long long using namespace std; int main(){ int n,s,d; cin>>n>>s>>d; int sec[n]; int pow[n]; for(int i=0;i<n;i++){ cin>>sec[i]; cin>>pow[i]; } int count=0; for(int i=0;i<n;i++){ if(sec[i]<s and pow[i]>d){ count++; } } if(count>0){ cout<<"Yes"<<endl; } else{ cout<<"No"<<endl; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; //イテレーション #define REP(i,n) for(ll i=0;i<ll(n);i++) #define REPD(i,n) for(ll i=n-1;i>=0;i--) #define FOR(i,a,b) for(ll i=a;i<=ll(b);i++) #define FORD(i,a,b) for(ll i=a;i>=ll(b);i--) #define FORA(i,I) for(const auto& i:I) //x:コンテナ #define ALL(x) x.begin(),x.end() #define SIZE(x) ll(x.size()) //定数 #define INF32 2147483647 //2.147483647×10^{9}:32bit整数のinf #define INF64 9223372036854775807 //9.223372036854775807×10^{18}:64bit整数のinf //#define MOD 1000000007 //問題による //略記 #define F first #define S second //出力(空白区切りで昇順に) #define coutALL(x) for(auto i=x.begin();i!=--x.end();i++)cout<<*i<<" ";cout<<*--x.end()<<endl; const string YES = "Yes"; const string NO = "No"; void solve(long long N, long long S, long long D, std::vector<long long> X, std::vector<long long> Y){ REP(i, N) { if (X[i] < S && Y[i] > D) { cout << YES << endl; return; } } cout << NO << endl; } signed main(){ //小数の桁数の出力指定 cout<<fixed<<setprecision(10); //入力の高速化用のコード ios::sync_with_stdio(false); cin.tie(nullptr); long long N; scanf("%lld",&N); long long S; scanf("%lld",&S); long long D; scanf("%lld",&D); std::vector<long long> X(N); std::vector<long long> Y(N); for(ll i = 0 ; i < N ; i++){ scanf("%lld",&X[i]); scanf("%lld",&Y[i]); } solve(N, S, D, std::move(X), std::move(Y)); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int>A(N),B(N),C(N); vector<int>cnt(N+1); for(int i = 0; i < N; i++) { cin >> A[i]; } for(int i = 0; i < N; i++) { cin >> B[i]; } for(int i = 0; i < N; i++) { cin >> C[i]; C[i] = B[C[i]-1]; cnt[C[i]]++; } long long ans = 0; for(int i = 0; i < N; i++) { ans += cnt[A[i]]; } cout << ans << endl; }
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <stack> #include <queue> #include <cmath> #include <tuple> #include <cstdio> #include <bitset> #include <sstream> #include <iterator> #include <numeric> #include <map> #include <cstring> #include <set> #include <functional> #include <iomanip> using namespace std; #define DEBUG_ //!!$BDs=P;~$K%3%a%s%H%"%&%H(B!! #ifdef DEBUG_ #define dump(x) cerr << #x << " = " << (x) << endl; #else #define dump(x) ; #endif #define equals(a,b) (fabs((a)-(b)) < EPS) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define SZ(x) ((int)(x).size()) #define pb push_back #define eb emplace_back //#define int long long typedef long long LL; typedef vector<int> VI; typedef vector<LL> VL; typedef vector<VI> VVI; typedef vector<VL> VVL; typedef vector<string> VS; typedef pair<int, int> PII; typedef pair<LL, LL> PLL; 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 <typename T> std::string printVector(const std::vector<T> &data) { std::stringstream ss; std::ostream_iterator<T> out_it(ss, ", "); ss << "["; std::copy(data.begin(), data.end() - 1, out_it); ss << data.back() << "]"; return ss.str(); } template <typename T> void print_array(const T &ary, int size){ REP(i,size){ cout << ary[i] << " "; } cout << endl; } const int mod = 1e9+7; const LL LINF = 1001002003004005006ll; const int INF = 1001001001; const double EPS = (1e-10); const long double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899; int dx[] = {0,0,-1,1}; int dy[] = {-1,1,0,0}; signed main(int argc, char const *argv[]) { cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(12); int N; cin >> N; VI A(N),B(N); REP(i,N) cin >> A[i]; REP(i,N) cin >> B[i]; int amax = -1, bmin = INF; REP(i,N){ chmax(amax, A[i]); chmin(bmin, B[i]); } cout << max(0, bmin-amax+1) << endl; }
#include<bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ll long long int #define pb push_back #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define all(v) v.begin(),v.end() typedef tree<pair<ll, ll>, null_type, less< pair<ll,ll>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; const ll mod=(1e+9)+7; const ll MAX = 5e5+9; const ll INF = 1e9; ll power(ll a,ll b,ll m = mod) {ll res = 1;while(b>0){if(b&1)res = (res*a)%m;b = b>>1;a = (a*a)%m;}return res;} bool prime[10000]; void sieve(ll n) { memset(prime, true, sizeof(prime)); for(ll i = 2; i*i <= n; i++){ if(prime[i]){ for(ll p = i*i; p <= n; p += i) prime[p] = false; } } ll cnt = 0; for(ll i = 1; i <= n; i++){ if(prime[i]){ cnt++; } } } void factors(ll n){ for(ll i = 1; i*i <= n; i++){ if(n%i == 0){ cout<<i<<" "; if(n/i != i){ cout<<n/i<<" "; } } } cout<<"\n"; } vector <ll> G[MAX]; bool vis[MAX]; void dfs(ll v){ if(vis[v] == true) return; vis[v] = true; for(ll i = 0; i < G[v].size(); i++){ dfs(G[v][i]); } } int main() { fastio; ll t = 1; // cin>>t; while(t--) { ll a,b; cin >> a >> b; cout << a*b*1.0/100<<"\n"; } } //ordered set is a policy based data structure with 2 extra funcs st.order_of_key(x) (no of elements which are strictly //smaller than x) //find_by_order(x) returns the iterator corresponding to the xth position {1 based index} both functions take log(n) time
#include <iostream> #include <iomanip> #include <fstream> #include <set> #include <map> #include <stack> #include <queue> #include <vector> #include <algorithm> #include <cmath> #include <complex> #include <chrono> using namespace std; int main(int argc, const char * argv[]) { ios::sync_with_stdio(false); cin.tie(0); int N; cin >> N; double x0, y0, xop, yop; cin >> x0 >> y0 >> xop >> yop; double cx = (x0 + xop) / 2., cy = (y0 + yop) / 2.; double vx = x0 - cx, vy = y0 - cy; double x1 = cx + cos(2. * M_PI / N) * vx - sin(2. * M_PI / N) * vy; double y1 = cy + sin(2. * M_PI / N) * vx + cos(2. * M_PI / N) * vy; printf("%.10f %.10f\n", x1, y1); return 0; }
// #define _GLIBCXX_DEBUG // for STL debug (optional) #include <iostream> #include <iomanip> #include <cstdio> #include <string> #include <cstring> #include <deque> #include <list> #include <queue> #include <stack> #include <vector> #include <utility> #include <algorithm> #include <map> #include <set> #include <complex> #include <cmath> #include <limits> #include <cfloat> #include <climits> #include <ctime> #include <cassert> #include <numeric> #include <fstream> #include <functional> #include <bitset> using namespace std; using ll = long long int; using int64 = long long int; template<typename T> void chmax(T &a, T b) {a = max(a, b);} template<typename T> void chmin(T &a, T b) {a = min(a, b);} template<typename T> void chadd(T &a, T b) {a = a + b;} int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; const int INF = 1LL << 29; const ll LONGINF = 1LL << 60; const ll MOD = 1000000007LL; int main() { int N; cin >> N; N <<= 1; vector<int> A(N); for(auto &e : A) cin >> e; vector< pair<int, int> > pairs; for(int i=0; i<N; i++) { pairs.emplace_back(A[i], i); } sort(pairs.rbegin(), pairs.rend()); vector<int> isBig(N); for(int i=0; i<N; i++) { int idx = pairs[i].second; isBig[idx] = (i < N/2); } stack<int> stk; string s = ""; for(int i=0; i<N; i++) { if(stk.empty() or stk.top() == isBig[i]) { s += "("; stk.push(isBig[i]); } else { s += ")"; stk.pop(); } } cout << s << endl; return 0; }
//#include <bits/stdc++.h> #include <iostream> #include <iomanip> #include <math.h> #include <cmath> #include <algorithm> #include <climits> #include <functional> #include <cstring> #include <string> #include <cstdlib> #include <ctime> #include <cstdio> #include <vector> #include <stack> #include <queue> #include <deque> #include <map> #include <set> #include <bitset> #include <complex> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> #define itn int #define nit int #define ll long long #define ms multiset #define F(i,a,b) for(register int i=a,i##end=b;i<=i##end;++i) #define UF(i,a,b) for(register int i=a,i##end=b;i>=i##end;--i) #define re register #define ri re int #define il inline #define pii pair<int,int> #define cp complex<double> //#pra gma G CC opti mize(3) using namespace std; using std::bitset; //using namespace __gnu_pbds; const double Pi=acos(-1); namespace fastIO { template<class T> inline void read(T &x) { x=0; bool fu=0; char ch=0; while(ch>'9'||ch<'0') { ch=getchar(); if(ch=='-')fu=1; } while(ch<='9'&&ch>='0') x=(x*10-48+ch),ch=getchar(); if(fu)x=-x; } inline int read() { int x=0; bool fu=0; char ch=0; while(ch>'9'||ch<'0') { ch=getchar(); if(ch=='-')fu=1; } while(ch<='9'&&ch>='0') x=(x*10-48+ch),ch=getchar(); return fu?-x:x; } template<class T,class... Args> inline void read(T& t,Args&... args) { read(t); read(args...); } char _n_u_m_[40]; template<class T> inline void write(T x ) { if(x==0){ putchar('0'); return; } T tmp = x > 0 ? x : -x ; if( x < 0 ) putchar('-') ; register int cnt = 0 ; while( tmp > 0 ) { _n_u_m_[ cnt ++ ] = tmp % 10 + '0' ; tmp /= 10 ; } while( cnt > 0 ) putchar(_n_u_m_[ -- cnt ]) ; } template<class T> inline void write(T x ,char ch) { write(x); putchar(ch); } } using namespace fastIO; pii s[400002]; ll n; int orz; int a[400002]; char ans[400002]; bool tp[400002]; int main() { cin>>n;n<<=1; F(i,1,n)read(a[i]); F(i,1,n)s[i]=make_pair(a[i],i); sort(s+1,s+n+1); F(i,1,n/2)tp[s[i].second]=1; F(i,1,n){ if(tp[i]==1){ if(orz<=0){ --orz; ans[i]='('; }else{ --orz; ans[i]=')'; } }else{ if(orz>=0){ ++orz; ans[i]='('; }else{ ++orz; ans[i]=')'; } } } F(i,1,n)putchar(ans[i]); return 0; }
//Geekio_op #include<bits/stdc++.h> using namespace std; int main(){ vector<int>v(3); for(int i=0;i<3;i++){ cin >> v[i]; } sort(v.begin(),v.end()); for(int i=0;i<3-1;i++){ if((abs(v[i]-v[i+1]))==(abs(v[i+1]-v[i+2]))){ cout << "Yes"; return 0; } } cout << "No"; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)(n);i++) using namespace std; typedef long long ll; int main() { ll a, b, c, d; cin >> a >> b >> c >> d; ll x, y; if (a >= b) { x = a; } else { x = b; } if (c >= d) { y = d; } else { y = c; } cout << x - y << endl; }
#include <bits/stdc++.h> using namespace std; /*^ debug */ template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_string(const string& s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(bool b) { return (b ? "true" : "false"); } string to_string(vector<bool> v) { bool first = true; string res = "{"; for (int i = 0; i < static_cast<int>(v.size()); i++) { if (!first) { res += ", "; } first = false; res += to_string(v[i]); } res += "}"; return res; } template <size_t N> string to_string(bitset<N> v) { string res = ""; for (size_t i = 0; i < N; i++) { res += static_cast<char>('0' + v[i]); } return res; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")"; } template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")"; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif /* debug $*/ /*^ generic definitions */ template<typename F> struct _RecurFun : F { _RecurFun(F&& f) : F(forward<F>(f)) {} template<typename... Args> decltype(auto) operator()(Args&&... args) const { return F::operator()(*this, forward<Args>(args)...); } }; template<typename F> decltype(auto) RecurFun(F&& f) { return _RecurFun<F> { forward<F>(f) }; } template<typename D, typename R> vector<R> maps(const vector<D> &&d, function<R(D)> f) { vector<R> r(d.size()); for (int i = 0; i < (int) d.size(); ++i) r[i] = f(d[i]); return r; } /* generic definitions $*/ int main() { ios::sync_with_stdio(false); int N; { cin >> N; } vector<int> C(N); { for (int i = 0; i < N; ++i) cin >> C[i]; } vector<vector<int>> G(N); { for (int i = 0; i + 1 < N; ++i) { int u, v; { cin >> u >> v; --u, --v; } G[u].push_back(v); G[v].push_back(u); } } vector<int> res; set<int> bag; function<void(int, int)> dfs = [&](int u, int fa) { for (int v : G[u]) if (v != fa) { bool flag = false; if (!bag.count(C[v])) flag = true, bag.insert(C[v]), res.push_back(v); dfs(v, u); if (flag) bag.erase(C[v]); } }; res.push_back(0); bag.insert(C[0]); dfs(0, -1); sort(res.begin(), res.end()); for (int u : res) cout << u+1 << "\n"; }
#include<bits/stdc++.h> using namespace std; #pragma GCC optimization("Ofast") #pragma GCC optimization("unroll-loops") #pragma GCC target ("avx2,avx,fma") typedef long long int ll; //#define int long long int typedef long double db; typedef pair <int,int> ii ; typedef vector < int > vi ; typedef vector < ii > vii ; #define rep(i,n) for(int i = 0 ; i < n ; i++) #define repu(i,a,b) for(int i = a ; i <= b ; i++) #define repd(i,b,a) for(int i = b ; i >= a ; i--) #define pb push_back #define fi first #define se second #define all(p) p.begin(),p.end() #define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define Endl endl inline ll poww(ll a,ll b){ll r=1LL;while(b>0){if(b&1)r=r*a;b/=2;a=a*a;}return (int)r;} template <class T>inline void sary(T st, T nd){while(st<nd)cin>>*st++;/*sf("%d", st++);*/} int mod=998244353; inline ll mul(ll a, ll b){return ((a%mod)*(b%mod))%mod;} inline ll add(ll a, ll b){return ((a%mod)+(b%mod))%mod;} inline ll sub(ll a, ll b){return ((a%mod)-(b%mod)+mod)%mod;} inline ll divi(ll a, ll b) { return (500000004*(a%mod))%mod; } const int N= 5002; int sum(int n) { int s=0; while(n) { s+=n%10; n/=10; } return s; } void solve() { int a, b; cin>>a>>b; cout<<max(sum(a),sum(b)); } int32_t main() { IOS int t=1; //cin>>t; #ifndef ONLINE_JUDGE clock_t clk = clock(); #endif while(t--) solve(); #ifndef ONLINE_JUDGE cerr << "\nTime (in ms): " << double(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n'; #endif }
///********************** Bismillahir Rahmanir Rahim *****************/// #include<bits/stdc++.h> using namespace std; ///*********************** Template Start Here ***********************/// ///************************ C o n t a i n e r ************************/// typedef long long ll; typedef unsigned long long ull; typedef vector<ll> vl; typedef vector<int> vi; typedef vector<char> vc; typedef vector<string> vs; typedef vector<int>::iterator vit; typedef set<int> si; typedef set<string> ss; typedef set<int>::iterator sit; typedef map<int, int> mii; typedef map<string, int> msi; typedef map<int, string> mis; typedef map<string, string> mss; typedef pair<ll, ll> pll; typedef pair<int,int> pii; typedef pair<double, double> pdd; typedef double dl; ///**************************** M a r c o ****************************/// #define f first #define s second #define endl '\n' #define sp <<" "<< #define pb push_back #define MP make_pair #define MOD 1000000007 #define sqr(a) ((a) * (a)) #define sz(x) (int)x.size() #define mid(l,r) ((l+r)/2) #define fora(a) for(auto u:a) #define gcd(a,b) __gcd(a,b) #define lcm(a,b) (a*(b/gcd(a,b))) #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() #define mem(a,b) memset(a, b, sizeof(a)) #define test int tc; cin>>tc; while(tc--) #define forn(i,n) for(auto i=0; i<n; i++) #define rforn(i,n) for(auto i=n-1; i>=0; i--) #define printv(a) {for(auto u:a) cout<<u<<" "; cout<<endl;} #define printm(a) {for(auto u:a) cout<<u.f sp u.s<<endl;} #define abid() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define ssd(a,b,c) set_symmetric_difference(all(a), all(b), c.begin()); #define fori(a,b,c) {for(a = c.begin(); a!=b; a++) cout<< *a<< " "; cout<<endl;} #define fraction(a) cout.unsetf(ios::floatfield); cout.precision(a); cout.setf(ios::fixed,ios::floatfield); #define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout); ///**************************** C o n s t ****************************/// const double PI = acos(-1); const double eps = 1e-9; const int inf = 2000000000; const ll infLL = 9000000000000000000; ///************************ Template End Here ************************/// int main() { abid(); int x,y,z; cin>>x>>y>>z; cout<<(y*z-1)/x<<endl; 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; int main() { int n, m; cin >> n >> m; vint a(m), b(m); rep(i, m) cin >> a[i] >> b[i]; int k; cin >> k; vint c(k), d(k); rep(i, k) cin >> c[i] >> d[i]; rep(i, m) { --a[i]; --b[i]; } rep(i, k) { --c[i]; --d[i]; } int ans = 0; rep(i, 1<<k) { vbool sara(m, false); rep(j, k) { if ((i>>j)&1) sara[d[j]] = true; else sara[c[j]] = true; } int t = 0; rep(j, m) if (sara[a[j]] && sara[b[j]]) t++; ans = max(ans, t); } cout << ans << endl; return 0; }
//================code===================// //#define TLE #ifdef TLE #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #endif #include <bits/stdc++.h> #include <unordered_map> #include <unordered_set> #include <random> #include <ctime> #define ci(t) cin>>t #define co(t) cout<<t #define LL long long #define ld double #define fa(i,a,b) for(LL i=(a);i<(LL)(b);++i) #define fd(i,a,b) for(LL i=(a);i>(LL)(b);--i) #define setp tuple<LL,LL,LL> #define setl pair<LL,LL> #define micro 0.000001 using namespace std; LL gcd(LL a, LL b) { return a % b ? gcd(b, a % b) : b; } #ifdef OHSOLUTION #define ce(t) cerr<<t #define AT cerr << "\n=================ANS=================\n" #define AE cerr << "\n=====================================\n" #define DB(a) cerr << __LINE__ << ": " << #a << " = " << (a) << endl; #define __builtin_popcount __popcnt #define __builtin_popcountll __popcnt64 #else #define AT #define AE #define ce(t) #endif pair <int, int> vu[9] = { {0,-1},{1,0},{0,1} ,{-1,0},{0,0},{1,1}, {-1,1} , {1,-1},{-1,-1} }; //RDLU EWSN template<typename T, typename U> void ckmax(T& a, U b) { a = a < b ? b : a; } template<typename T, typename U> void ckmin(T& a, U b) { a = a > b ? b : a; } struct gcmp { bool operator()(LL a, LL b) { return a < b; } bool operator()(setl& a, setl& b) { return a.second < b.second; } }; struct lcmp { bool operator()(LL a, LL b) { return a > b; } bool operator()(setl& a, setl& b) { return a.second > b.second; } }; const int max_v = 1e5+ 7; const int max_k = 1e1 + 7; const int INF = 1e9 + 7; const LL LNF = (LL)5e18 + 7ll; LL mod = 998244353; template<typename T, typename U> void MOD(T& a, U b) { a += b; if (a >= mod) a -= mod; } int main() { #ifdef OHSOLUTION freopen("input.txt", "r", stdin); #endif ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; ci(n); vector<int> vi(n); fa(i, 0, n) ci(vi[i]); vector<int> prime; vector<int> sp(57); fa(i, 2, 57) { if (!sp[i]) prime.push_back(i); for (auto& x : prime) { if (i * x >= 57) break; sp[i * x] = x; if (i % x == 0) break; } } vector<int> tar; LL ans = LNF; auto check = [&](LL x) { fa(i, 0, n) { if (gcd(x, vi[i]) == 1) return false; } return true; }; fa(i, 0, 1 << 15) { tar.clear(); LL tmp = 1; fa(j, 0, 15) if (i & (1 << j)) tar.push_back(prime[j]),tmp*=prime[j]; if(check(tmp)) ckmin(ans,tmp); } co(ans); return 0; }
#include<bits/stdc++.h> using ll = int_fast64_t; using P = std::pair<ll,ll>; using PP = std::pair<ll,P>; #define REP(i,b,e) for(int i=b; i<e; i++) #define PRINT(vec) {printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");} #define fi first #define se second const int MOD = 1e9+7; int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1}; int main(){ ll n; scanf("%ld", &n); std::set<ll> st; REP(i, 2, 100000){ ll x = i; REP(j, 2, 40){ x *= i; if(x>n) break; st.insert(x); } } printf("%ld\n", n - st.size()); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> p_ll; template<class T> void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; } #define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++) #define all(vec) vec.begin(), vec.end() #define rep(i,N) repr(i,0,N) #define per(i,N) for (ll i=(ll)N-1; i>=0; i--) #define popcount __builtin_popcount const ll LLINF = pow(2,61)-1; const ll INF = pow(2,30)-1; ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); } ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } int main() { ll N; cin >> N; ll a[N]; rep(i,N) cin >> a[i]; ll b[N]; rep(i,N) cin >> b[i]; ll result[N] = {}, ma = 0; rep(i,N) { ma = max(ma, a[i]); if (i==0) result[i] = ma*b[i]; else result[i] = max(result[i-1], ma*b[i]); } debug(result,result+N); return 0; }
#include <vector> #include <list> #include <map> #include <set> #include <queue> #include <deque> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <ctime> #include <unordered_map> using namespace std; #define x first #define y second #define all(v) v.begin(), v.end() #define compress(v) (sort(all(v)), v.erase(unique(all(v)), v.end())) typedef long long ll; typedef pair<int, int> p; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<ll> x(n), y(n); for (auto &a : x) cin >> a; for (auto &a : y) cin >> a; ll mx = -1, value = -1; for (int i = 0; i < n; i++) { mx = max(mx, x[i]); value = max(value, mx*y[i]); cout << value << '\n'; } }
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int maxn=1e5+10; const int maxm=3e5+10; int head[maxn],w[maxm],dis[20][maxn],nt[maxm],to[maxm],tot; int cnt[maxn],d[maxn],vis[maxn];int n,m,c[maxn]; void add(int x,int y,int z) { to[++tot]=y;w[tot]=z;nt[tot]=head[x];head[x]=tot; } bool spfa(int p) { for(int i=1;i<=n;i++) dis[p][i]=1e9; memset(vis,0,sizeof vis); queue<int> q; while(q.size()) q.pop(); dis[p][c[p]]=0;vis[c[p]]=true;q.push(c[p]); while(q.size()){ int x=q.front();q.pop();vis[x]=false; for(int i=head[x];i;i=nt[i]){ int y=to[i],z=w[i]; //cout<<dis[y]<<" "<<dis[x]+z<<endl; if(dis[p][y]>dis[p][x]+z){ dis[p][y]=dis[p][x]+z; if(!vis[y]) q.push(y),vis[y]=true; } } } return true; } int dp[1<<18][20]; int main() { scanf("%d%d",&n,&m); for(int i=1;i<=m;i++){ int t1,t2;scanf("%d%d",&t1,&t2); add(t1,t2,1);add(t2,t1,1); } int k;scanf("%d",&k); for(int i=0;i<k;i++) scanf("%d",&c[i]),spfa(i); int ans=1e9;memset(dp,0x3f,sizeof dp); for(int i=0;i<k;i++) dp[1<<i][i]=1; for(int s=1;s<(1<<k);s++){ for(int i=0;i<k;i++){ if(s&(1<<i)){ ; }else continue; for(int j=0;j<k;j++){ if(i==j) continue; if(s&(1<<j));else continue; dp[s][j]=min(dp[s][j],dp[s^(1<<j)][i]+dis[i][c[j]]); } } } for(int i=0;i<k;i++) ans=min(ans,dp[(1<<k)-1][i]); if(ans==1e9) cout<<"-1"<<endl; else cout<<ans<<endl; }
#include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <iostream> #include <cassert> #include <cmath> #include <string> #include <queue> #include <set> #include <map> #include <cstdlib> using namespace std; #define mp make_pair #define pb push_back #define fi first #define se second #define li long long #define pii pair<int, int> #define vi vector<int> #define li long long #define forn(i, n) for (int i = 0; i < (int)n; i++) #define fore(i, b, e) for (int i = (int)b; i <= (int)e; i++) const int MAXK = 17; const int MAXN = 1e5+5; const int INF = 1e9; vi edges[MAXN]; int dp[(1 << MAXK)][MAXK]; int d[MAXK][MAXN]; void upd(int& x, int y) { x = min(x, y); } int main() { int n, m; scanf("%d%d", &n, &m); forn(i, m) { int x, y; scanf("%d%d", &x, &y); edges[x].pb(y); edges[y].pb(x); } int k; scanf("%d", &k); vi chosen(k); forn(i, k) { scanf("%d", &chosen[i]); } forn(i, k) { queue<int> q; q.push(chosen[i]); fore(v, 1, n) { d[i][v] = INF; } d[i][chosen[i]] = 0; while(!q.empty()) { int v = q.front(); q.pop(); for (int u : edges[v]) { if (d[i][u] == INF) { d[i][u] = d[i][v] + 1; q.push(u); } } } } /*forn(i, k) { fore(j, 1, n) { printf("d[%d][%d] = %d\n", i, j, d[i][j]); } }*/ forn(mask, (1 << k)) forn(last, k) dp[mask][last] = INF; forn(j, k) { dp[(1 << j)][j] = 1; } forn(mask, (1 << k)) { forn(last, k) { if (dp[mask][last] == INF) { continue; } forn(next, k) { if (!(mask & (1 << next)) && d[last][chosen[next]] != INF) { upd(dp[mask | (1 << next)][next], dp[mask][last] + d[last][chosen[next]]); } } } } int ans = INF; forn(last, k) { ans = min(ans, dp[(1 << k) - 1][last]); } if (ans == INF) { ans = -1; } printf("%d", ans); }
#include<bits/stdc++.h> using namespace std; int main() { int N; string S; cin >> N >> S; vector<vector<int>> a(N+1,vector<int>(N+1,0)); vector<vector<int>> t(N+1,vector<int>(N+1,0)); vector<vector<int>> c(N+1,vector<int>(N+1,0)); vector<vector<int>> g(N+1,vector<int>(N+1,0)); for (int i=0;i<N;i++) { if (S[i]=='A'){ a[0][i+1]=a[0][i]+1; t[0][i+1]=t[0][i]; g[0][i+1]=g[0][i]; c[0][i+1]=c[0][i]; } if (S[i]=='T'){ a[0][i+1]=a[0][i]; t[0][i+1]=t[0][i]+1; g[0][i+1]=g[0][i]; c[0][i+1]=c[0][i]; } if (S[i]=='C'){ a[0][i+1]=a[0][i]; t[0][i+1]=t[0][i]; g[0][i+1]=g[0][i]; c[0][i+1]=c[0][i]+1; } if (S[i]=='G'){ a[0][i+1]=a[0][i]; t[0][i+1]=t[0][i]; g[0][i+1]=g[0][i]+1; c[0][i+1]=c[0][i]; } } for (int i=1;i<N+1;i++) { for (int j=0;j<=i;j++) { a[j][i]=a[0][i]-a[0][j]; t[j][i]=t[0][i]-t[0][j]; c[j][i]=c[0][i]-c[0][j]; g[j][i]=g[0][i]-g[0][j]; } } int ans=0; for (int i=1;i<N+1;i++) { for (int j=0;j<i;j++) { if (a[j][i]==t[j][i] && c[j][i]==g[j][i]){ ans++; } } } cout << ans << endl; }
#include <bits/stdc++.h> #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; using ll = long long; using P = pair<int, ll>; int main() { int n; cin >> n; // vector<int> a(n); map<int,int> m; rep(i,n){ int a; cin >> a; m[a]++; } // sort(m.begin(), m.end()); ll sum = 0; for(auto x : m){ n -= x.second; sum += (ll)n * x.second; } cout << sum << endl; return 0; }
#include<bits/stdc++.h> typedef long long int ll; using namespace std; #define sz 1600008 #define mod 998244353 #define f first #define s second ll arr[sz+10],brr[sz+10]; ll num=1; long long binpow(long long a, long long b) { a %= mod; long long res = 1; while (b > 0) { if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1; } return res; } int main() { int t=1; //scanf("%d",&t); for(int cs=1;cs<=t;cs++) { ll n,m,k; scanf("%lld %lld %lld",&n,&m,&k); for(ll i=1;i<=k;i++) { arr[i]=binpow(i,n); brr[i]=binpow(i,m); } ll ans=0; ll last,fast; if(n==1 || m==1) { for(ll i=1;i<=k;i++) { last=(arr[i]-arr[i-1]+mod)%mod; ll a=k-i+1; fast=(brr[a]-brr[a-1]+mod)%mod; last=(last*fast)%mod; ans=(ans+last)%mod; } printf("%lld\n",ans); return 0; } for(ll i=1;i<=k;i++) { last=(arr[i]-arr[i-1]+mod)%mod; ll a=k-i+1; fast=(brr[a]+mod)%mod; last=(last*fast)%mod; ans=(ans+last)%mod; } printf("%lld\n",ans); } return 0; }
#include <bits/stdc++.h> using namespace std; #pragma optimize("-O3") #define int long long int #define f first #define s second #define pb push_back #define endl '\n' const int MOD=998244353; const int N=2e5+5; int num[N]; int num2[N]; int ex[N]; int ex2[N]; int add(int x, int y) { return (x + y) % MOD; } int sub(int x, int y){ return add(x, MOD - y); } int mul(int x, int y) { return (x * 1ll * y) % MOD; } int binpow(int x, int y) { int z = 1; while(y > 0) { if(y % 2 == 1) z = mul(z, x); x = mul(x, x); y /= 2; } return z; } int inv(int x) { return binpow(x, MOD - 2); } main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, m, k; cin>>n>>m>>k; num[1]=1; ex[1]=1; for(int i=2; i<=k; i++){ num[i]=sub(binpow(i, n), ex[i-1]); ex[i]=add(ex[i-1], num[i]); } num2[k]=1; ex2[k]=1; for(int i=k-1; i>=1; i--){ num2[i]=sub(binpow(k-i+1, m), ex2[i+1]); ex2[i]=add(ex2[i+1], num2[i]); } if(n==1 && m==1){ cout<<k; return 0; } if(n==1){ int ans=0; for(int i=1; i<=k; i++){ ans=add(ans, num2[i]); } cout<<ans; return 0; } if(m==1){ int ans=0; for(int i=1; i<=k; i++){ ans=add(ans, num[i]); } cout<<ans; return 0; } int ans=0; for(int i=1; i<=k; i++){ ans=add(ans, mul(num[i], binpow(k-i+1, m))); } cout<<ans; return 0; }