code_file1
stringlengths
87
4k
code_file2
stringlengths
85
4k
#include <bits/stdc++.h> using namespace std; int main() { int64_t n, m, k = 0, ans = 0; cin >> n >> m; vector<int64_t> a(m + 1, 0); map<int64_t, int> s; for (auto i = 0; i < m; i++) cin >> a[i]; a.push_back(n + 1); sort(a.begin(), a.end()); for (auto i = 0; i < (int)a.size() - 1; i++) if (a[i + 1] != a[i]) s[a[i + 1] - a[i] - 1]++; for (auto& elm : s) { if (elm.first == 0) continue; if (k == 0) k = elm.first, ans += elm.second; else ans += (elm.first / k + ((elm.first % k) ? 1 : 0)) * elm.second; } cout << ans << endl; return 0; }
#include<bits/stdc++.h> #define int long long using namespace std; const int mod=1000000007; int p(int A,int B){ if(!B)return 1; if(B&1)return p(A,B-1)*A%mod; int C=p(A,B/2); return C*C%mod; } signed main(){ int H,W,cnt=0,ans=0; cin>>H>>W; vector<string> A(H); for(string &S:A)cin>>S; vector<vector<int>> B(H+1,vector<int>(W+1,-mod)); for(int i=0;i<H;i++) for(int j=0;j<W;j++) if(A[i][j]=='.')B[i][j]=1,cnt++; vector<vector<int>> C=B; for(int i=0;i<H;i++) for(int j=0;j<W;j++){ B[i][j+1]+=max(B[i][j],0LL); C[i+1][j]+=max(C[i][j],0LL); } vector<vector<int>> D(H,vector<int>(W,-1)); for(int i=H-1;i>=0;i--) for(int j=W-1;j>=0;j--){ if(B[i][j]>=0 && B[i][j+1]>=0)B[i][j]=B[i][j+1]; if(C[i][j]>=0 && C[i+1][j]>=0)C[i][j]=C[i+1][j]; if(B[i][j]>=0)D[i][j]+=B[i][j]; if(C[i][j]>=0)D[i][j]+=C[i][j]; } for(int i=0;i<H;i++) for(int j=0;j<W;j++) if(D[i][j]>0)ans=(ans+p(2,cnt-D[i][j])*((p(2,D[i][j])-1+mod)%mod)%mod)%mod; cout<<ans<<endl; }
#include<iostream> using namespace std; int main(void){ int a,b,x,y; int ans; cin >> a >> b >> x >> y; ans = 0; if(a < b){ if(x*2 < y){ ans = (b - a + 1) * x + (b - a) * x; } else{ ans = (b - a) * y + x; } } else if(a > b){ if(x*2 < y){ ans = (a - b - 1) * x + (a - b) * x; } else{ ans = (a - b - 1) * y + x; } } else{ ans = x; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll, ll> pll; #define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i)) #define REP(i, n) FOR(i,n,0) #define OF64 std::setprecision(10) const ll MOD = 1000000007; const ll INF = (ll) 1e15; struct Vertex { vector<pll> edge; }; int main() { cin.tie(0); ios::sync_with_stdio(false); ll A, B, X, Y; cin >> A >> B >> X >> Y; vector<Vertex> V(300); ll x = 100; REP(i, x) { V[i].edge.push_back(pll(i + x, X)); V[i + x].edge.push_back(pll(i, X)); } REP(i, x - 1) { V[i + 1].edge.push_back(pll(i + x, X)); V[i + x].edge.push_back(pll(i + 1, X)); V[i].edge.push_back(pll(i + 1, Y)); V[i + 1].edge.push_back(pll(i, Y)); V[i + x].edge.push_back(pll(i + x + 1, Y)); V[i + x + 1].edge.push_back(pll(i + x, Y)); } A--; B = B - 1 + x; vector<ll> d(3 * x, INF); d[A] = 0; priority_queue<pll, vector<pll>, function<bool(pll, pll)>> q([](pll a, pll b) { return a.second > b.second; }); q.push(pll(A, 0)); while (!q.empty()) { pll t = q.top(); q.pop(); if (d[t.first] < t.second) continue; REP(i, V[t.first].edge.size()) { pll y = V[t.first].edge[i]; ll nxt = y.first; ll cost = y.second + t.second; if (d[nxt] <= cost) continue; d[nxt] = cost; q.push(pll(nxt, cost)); } } cout << d[B] << endl; 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; vector<int> solve(vector<int> P) { int N = P.size(); for (auto &p : P) p--; vector<int> ans; int pos = 0; auto op = [&](int n) { assert(ans.size() % 2 == n % 2); ans.push_back(n); swap(P[n], P[n + 1]); if (pos == n) pos++; else if (pos == n + 1) pos--; }; for (int t = N - 1; t >= 3; t--) { pos = find(begin(P), end(P), t) - begin(P); if (pos == t) { continue; } while (pos != t && pos % 2 != ans.size() % 2) { if (ans.size() % 2 == 0) { if (pos == 1) { op(2); } else { op(0); } } else { if (t >= 4 && pos == 2) { op(3); } else { op(1); } } } while (pos != t) { op(pos); } } while (!is_sorted(begin(P), end(P))) { op(ans.size() % 2); } for (auto &a : ans) a++; return ans; } int main() { int T; cin >> T; while (T--) { int N; cin >> N; vector<int> P(N); for (auto &p : P) cin >> p; auto ans = solve(P); cout << ans.size() << '\n'; for (auto a : ans) cout << a << ' '; cout << '\n'; } return 0; }
#include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> #include<iostream> #include<vector> using namespace std; const int N=4e5+5; int s[N],t,n; struct node { int x,id; inline bool operator < (const node &a) const {return x!=a.x?x<a.x:id<a.id;} }a[N]; bool tp[N]; int main() { scanf("%d",&n); for(int i=1,x ; i<=2*n ; ++i) scanf("%d",&x),a[i].x=x,a[i].id=i; sort(a+1,a+2*n+1); for(int i=n+1 ; i<=2*n ; ++i) tp[a[i].id]=1; for(int i=1 ; i<=2*n ; ++i) { if(!t) printf("("),s[++t]=i; else if(tp[s[t]]!=tp[i]) printf(")"),--t; else printf("("),s[++t]=i; } return 0; }
#include <iostream> #include <stdio.h> #include <string.h> #include <algorithm> #include <cmath> using namespace std; long long a[105][105], k, b[105]; int n, m; string st; int main() { for (int i = 1; i <= 60; i++) {a[0][i] = 1; a[i][0] = 1;} for (int i = 1; i <= 60; i++) for (int j = 1; j <= i; j++) { a[i][j] = a[i - 1][j] + a[i - 1][j - 1]; // cout << a[i][j] << endl; } cin >> n >> m; cin >> k; int i = m, cntm = m; long long cnt = k; while (cntm) { if (a[i][cntm] > cnt) { b[n + m - i + 1] = 1; cnt -= a[i - 1][cntm]; i = cntm - 2; cntm--; //cout <<i << 'c'; } else if (a[i][cntm] == cnt) { int x = n + m - i + 1; // cout << cntm << ' ' << cnt << ' ' << i; for (int j = x; j <= x + cntm - 1; j++) b[j] = 1; for (int j = 1; j <= n + m; j++) if (b[j]) cout <<'b'; else cout << 'a'; cout << endl; return 0; } i++; } for (int j = 1; j <= n + m; j++) if (b[j]) cout <<'b'; else cout << 'a'; cout << endl; return 0; }
#include "bits/stdc++.h" using namespace std; long long ncr(long long a,long long b) { long long m=1; for(int i=a;i>b;i--) { m*=i; m/=a-i+1; } return m; } int main() { ios::sync_with_stdio(false); cin.tie(0); long long a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, m = 0, n = 0, p = 0, q = 0, mod = 1000000007, pi = 3.1415926535; string s1, s2; char moji; cin >> a >> b >> c; d=a+b; c--; for(int i=0;i<d;i++) { if(ncr(a+b-1,max(a-1,b))<=c) { c-=ncr(a+b-1,max(a-1,b)); cout << 'b'; b--; } else { if(a) { cout << 'a'; a--; } else { cout << 'b'; b--; } } } cout << endl; return 0; }
//To debug : g++ -g file.cpp -o code //to flush output : fflush(stdout) or cout.flush() //cout<<setprecision(p)<<fixed<<var //use 1LL<<i to for 64 bit shifting , (ll)2 because by default 2 is ll //take care of precedence rule of operators //do not forget to change the sizes of arrays and value of contants and other things after debugging #include<bits/stdc++.h> using namespace std; #define ll long long #define rep(i,a,n) for(i=a;i<n;++i) #define irep(i,n,a) for(i=n;i>a;--i) #define mod 1000000007 #define pb push_back #define big 9223372036854775807 #define big1 LONG_MAX #define big2 ll_MAX #define big3 1000000000 #define sma1 LONG_MIN #define sma2 ll_MIN #define sma3 -1000000000 #define mp make_pair #define dub double #define ivec vector<ll> #define lvec vector<long long> #define cvec vector<char> #define svec vector<string> #define mt make_tuple #define MOD 998244353 #define ld long double #define pi acos(-1.0) #define SZ(x) (ll)(x.size()) //comment the below if not required /* #define ss second.second #define ff first.first #define f first #define s second #define sf second.first #define fs first.second */ #define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) //cout<<"Case #"<<c<<": "<<ans<<"\n" ; ld x,y,r; ll xc,yc,rc,ans; ll read() { ld x; cin>>x; return llround(x * 10000); } ll solve(ll X) { ll l,r,m,L1=LLONG_MIN,val,R1=LLONG_MIN; l = yc , r = yc+rc ; while(l<=r) { m = (l+r)/2; val = (m-yc)*(m-yc)+(X-xc)*(X-xc); if(val<=(rc*rc)) { R1 = m; l = m+1; } else r = m-1; } r = yc , l = yc-rc; while(l<=r) { m = (l+r)/2; val = (m-yc)*(m-yc)+(X-xc)*(X-xc); if(val<=(rc*rc)) { L1 = m; r = m-1; } else l = m+1; } if(L1<=R1 && L1!=LLONG_MIN && R1!=LLONG_MIN) return (floor(((ld)R1)/1e4)-ceil(((ld)L1)/1e4)+1); else return 0; } int main() { IOS; xc = read(); yc = read(); rc = read(); ll i; i = floor(((xc+rc)/1e4))*1e4; for(;i>=(xc-rc);i-=1e4) { ans+=solve(i); } cout<<ans; return 0; }
#include<bits/stdc++.h> #define pb push_back #define ll long long #define ld long double #define lld long double using namespace std; clock_t time_p=clock(); void Time() { time_p=clock()-time_p; cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n"; } const int INF = 1e9 + 7; lld pi=3.1415926535897932; const long long INF64 = 9e18; const long long mod = 998244353; void solve() { ld x, y, r; cin >> x >> y >> r; r = nextafter(r, INFINITY); ll ans = 0; for(ll i = floor(x - r); i <= ceil(x + r); ++i) { ld left = r * r - (x - i) * (x - i); if(left >= 0) { ld range = sqrt(left); ld low = y - range, high = y + range; low = ceil(low); high = floor(high); ans += (high - low + 1); } } cout << ans << endl; } int main() { ios_base :: sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); cout.precision(35); int t; solve(); Time(); return 0; }
//#pragma GCC optimize(2) #include <bits/stdc++.h> #define IO (ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)) #define inf 0x3f3f3f3f #define ll long long #define pii pair<int, int> #define vs vector<int> #define pk push_back #define vss vector<vector<int> > #define sz(x) (int)(x).size() #define mk(a, b) make_pair(a, b) #define rep(a, b, c) for(register int a = b; a <= c; ++ a) #define per(a, b, c) for(register int a = b; a >= c; -- a) using namespace std; template<class T> inline void read(T &x) { x = 0; T f = 1; char c = getchar(); while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9') x = (x << 3) + (x << 1) + (c ^ 48), c = getchar(); x *= f; } template<class T> inline void print(T x){ if(x < 0) x = ~x + 1, putchar('-'); if(x > 9) print(x / 10); putchar(x % 10 + '0'); } int main() { int n; cin >> n; n = n * 1.08; if(n < 206) puts("Yay!"); else if(n == 206) puts("so-so"); else puts(":("); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; bool flag = true; for (int i = 0; 2*i <= s.length(); i++) { if (s[2*i] >= 65 && s[2*i] <= 90) { flag = false; } } for (int i = 0; 2*i+1 <= s.length(); i++) { if (s[2*i+1] >= 97 && s[2*i+1] <= 122) { flag = false; } } if (flag) { cout <<"Yes" << endl; } else { cout << "No" << endl; } return 0; }
/* Be patient, things will be at their rightful place. Everything happens for a reason. It was meant to happen this way, accept it. And now decide what you can do about it. */ #include<bits/stdc++.h> #define ll long long #define ld long double #define pb push_back #define ip pair<ll,ll> #define vii vector<ll> #define vpp vector<ip> #define vdd vector<ld> #define vb vector<bool> #define pi pair<ll,ip> #define sc(x) scanf("%lli",&x) #define hu 200010 #define pq priotity_queue<ll> #define pqs priority_queue<ll,vii,greater<ll>> #define ppq priority_queue<ip,vpp,greater<ip>> #define INF INT_MAX #define ff first #define ss second #define fo(i,k,n) for(ll i=k;i<n;i++) using namespace std; const ll M = 1000000000+7; //Grid Movement ll dx[] = {-1, 0, 1, 0}; ll dy[] = {0, -1, 0, 1}; ld Pi= acos(-1); ll lcm(ll a,ll b) { return (a*b)/(__gcd(a,b)); } ll mex(ll x, ll y) { ll res = 1; x = x % M; if (x == 0) return 0; while (y > 0) { if (y & 1) res = (res*x) % M; y = y>>1; x = (x*x) % M; } return res; } bool comp(ll comp1,ll comp2) { return comp1>comp2; } void yes() { printf("Yes\n"); } void no() { printf("No\n"); } ll inv(ll a, ll m) { ll m0 = m; ll y = 0, x = 1; if (m == 1) return 0; while (a > 1) { int q = a / m; int t = m; m = a % m, a = t; t = y; y = x - q * y; x = t; } if (x < 0) x += m0; return x; } void sieve(ll n) { vii primes(n+1); vb is_prime(n+1); is_prime.resize(n+1); primes.resize(n+1); is_prime[0] = is_prime[1] = false; for(int i = 2; i<=n; i++) { if(is_prime[i]) { primes.pb(i); for (int j = i*i; j<=n; j+=i) is_prime[j] = false; } } } ll n,m; bool vis[hu]={0}; vii v; vii vec[hu]; void dfs(ll i) { v.pb(i); vis[i] = 1; for(auto it:vec[i]) { if(!vis[it]) dfs(it); } } void solve() { sc(n); sc(m); ll a[n],b[n]; ll s1=0,s2=0; fo(i,0,n) { sc(a[i]); } fo(i,0,n) { sc(b[i]); } fo(i,0,m) { ll x,y; sc(x); sc(y); vec[x].pb(y); vec[y].pb(x); } fo(i,1,n+1) { v.clear(); if(!vis[i]) { dfs(i); } ll s1 = 0;s2=0; for(auto it:v) { s1+=a[it-1]; s2+=b[it-1]; } if(s1!=s2) { no(); return; } } yes(); } int main() { // ios_base::sync_with_stdio(0); cin.tie(0); ll t=1; // sc(t); while(t--) solve(); }
#include<bits/stdc++.h> using namespace std; const int maxH = 16; const int maxW = 16; int config[maxH][maxW]; int h,w,a,b; long long find_ans(int r,int c,int rem) { if(rem==0){ return 1; } if(c == w) return 0; long long ans = 0; int i1=-1; for(int i=r;i<h;i++) { if(config[i][c] == 0) { i1 = i; break; } } if(i1 == -1) return find_ans(0,c+1,rem); if(i1+1<h && config[i1+1][c] == 0){ ans += find_ans(i1+2,c,rem-1); } if(c != w-1) { config[i1][c+1] = 1; ans += find_ans(i1+1,c,rem-1); config[i1][c+1] = 0; } ans += find_ans(i1+1,c,rem); return ans; } int main() { cin>>h>>w>>a>>b; cout<<find_ans(0,0,a)<<endl; return 0; }
#include<iostream> #include<math.h> #include<stdlib.h> #include<string> #include<limits.h> #include<utility> #include<vector> //#include<bits/stdc++.h> #include<tuple> #include<queue> #include<map> #include<algorithm> //#include <bits/stdc++.h> #define rep(i,n) for(ll i=0;i<n;i++) #define ALL(A) A.begin(),A.end() using namespace std; typedef long long ll; typedef pair<ll, ll> P; const int MAX = 510000; const int MOD = 1000000007; long long fac[MAX], finv[MAX], inv[MAX]; // �e�[�u�������O���� void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // �񍀌W���v�Z long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } int main() { ll n,p; cin>>n>>p; vector<ll> a(0); ll n1=n-1; while(n1>0){ a.push_back(n1%2); n1/=2; } ll tmp=a.size(); //rep(i,tmp)cout<<a[i]<<" "; //cout<<endl; ll ans=p-1; ll mod=1e9+7; ll x=p-2; rep(i,tmp){ if(a[i]==1){ ans*=x; } ans%=mod; x*=x; x%=mod; } cout<<ans<<endl; }
#include <bits/stdc++.h> using ll = long long int; ll mod_pow(ll n, ll r, ll mod) { ll ans = 1; ll pow = n; while (r > 0) { if (r & 1) { ans = (ans * pow) % mod; } pow = (pow * pow) % mod; r >>= 1; } return ans; } int main() { ll MOD = 1e9 + 7; ll N, P; std::cin >> N >> P; ll ans = (P - 1) * mod_pow(P - 2, N - 1, MOD) % MOD; std::cout << ans << std::endl; }
#include <bits/stdc++.h> using namespace std; //TEMPLATE #define len(a) (ll) a.size() #define ms(a, x) memset(a, x, sizeof a) #define bitcount(n) __builtin_popcountll(n) #define FR ios_base::sync_with_stdio(false);cin.tie(NULL) #define cin1(a) cin >> a #define cin2(a, b) cin >> a >> b #define cin3(a, b, c) cin >> a >> b >> c #define cin4(a, b, c, d) cin >> a >> b >> c >> d #define cots(a) cout << a << " " #define cot1(a) cout << a << "\n" #define cot2(a, b) cout << a << " " << b << "\n" #define cot3(a, b, c) cout << a << " " << b << " " << c << "\n" #define cot4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << "\n" #define cotcase(cs) cout << "Case " << cs << ": " #define yes cout << "Yes\n" #define no cout << "No\n" #define line cout << "\n" #define reversed(s) reverse(s.begin(), s.end()) #define asort(s) sort(s.begin(), s.end()) #define dsort(s) sort(s.rbegin(), s.rend()) #define all(s) s.begin(), s.end() #define uniq(s) s.resize(distance(s.begin(),unique(s.begin(), s.end()))) #define found(s, x) (s.find(x) != s.end()) #define for0(i, n) for (i = 0; i < n; i++) #define for1(i, n) for (i = 1; i <= n; i++) #define fora(i, a, b) for (i = a; i <= b; i++) #define forb(i, b, a) for (i = b; i >= a; i--) #define ll long long #define pb push_back #define mp make_pair #define ld long double #define pii pair <ll, ll> #define piii pair <ll, pii> #define F first #define S second #define pi acos(-1.0) #define bug(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << '\n' void err(istringstream *iss) {} template<typename T, typename... Args> void err(istringstream *iss, const T a, const Args... args) { string _name; *iss >> _name; if (_name.back()==',') _name.pop_back(); cerr << _name << " = " << fixed << setprecision(5) << a << "; ", err(iss, args...); } const ll INF = LLONG_MAX; const ll SZ = 1e10; const ll mod = 1e9+7; string s, s1, s2; ll n, k, ans = 0; void add() { s += "110"; } int main() { FR; ll cs = 0, tc = 1, x, y, z, i, j, g, p, q, sum = 0, c = 0, t = 0; // ll a, b, d; // string s, s1, s2; cin2(n, s1); while(len(s) <= n) { add(); } for1(i, 3) add(); fora(i, 0, 2) { s2.clear(); for(j = i, c = 1; c <= len(s1); j++, c++) { s2.pb(s[j]); } if(s1 == s2) { p = (j / 3) + (j%3 != 0); ans += (SZ - p + 1); } } cot1(ans); return 0; }
#include<iostream> #include<string> #include<cstdio> #include<vector> #include<cmath> #include<algorithm> #include<functional> #include<iomanip> #include<queue> #include<ciso646> #include<random> #include<map> #include<set> #include<bitset> #include<stack> #include<unordered_map> #include<utility> #include<cassert> #include<complex> #include<numeric> #include<array> #define rep(i,n) for(int i=0;i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define Rep(i,sta,n) for(int i=sta;i<n;i++) #define rep1(i,n) for(int i=1;i<=n;i++) #define per1(i,n) for(int i=n;i>=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) #define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n"); #define all(v) (v).begin(),(v).end() #define all_rev(v) (v).rbegin(),(v).rend() #define debug(x) cout << #x << ": " << x << '\n'; #define degreeToRadian(deg) (((deg)/360)*2*M_PI) #define radianTodegree(rad) (((rad)/2/M_PI)*360) template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; using ll = long long; using P = pair<int,int>; using PL = pair<ll, ll>; const ll INF = 1LL<<60; const int MOD = 1e9 + 7; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; int main() { //cin.tie(0);ios::sync_with_stdio(false); //cout << fixed << setprecision(15); string S; cin >> S; vector<string> A; for (int i = 8; to_string(i).size() < 4; i+=8) { if (to_string(i).size() == 3) A.push_back(to_string(i)); } map<int, int> mp; if (S.size() > 2) { for (auto v : S) mp[v - '0']++; for (auto a : A) { bool ok = true; map<int, int> mp2 = mp; for (auto ch : a) { if (mp2[ch - '0'] > 0) mp2[ch - '0']--; else ok = false; } if (ok) { cout << "Yes" << endl; return 0; } } } else { string S_rev = S; reverse(all(S_rev)); if (stoll(S) % 8 == 0 || stoll(S_rev) % 8 == 0) { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0; } cout << "No" << endl; return 0; }
#include <bits/stdc++.h> #ifndef aly_local #include <ext/rope> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace __gnu_cxx; template<typename T> #define oset(T) tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update> void __funxc(); #endif using namespace std; #define sim template < class c #define ris return * this #define dor > debug & operator << #define eni(x) sim > typename \ enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { #ifdef aly_local ~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } #else sim dor(const c&) { ris; } #endif }; #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " struct __time{ #ifdef aly_local chrono::time_point<chrono::high_resolution_clock> start,end; __time(){ start = chrono::high_resolution_clock::now(); } ~__time(){ end = chrono::high_resolution_clock::now(); chrono::duration<double,milli> duration = end-start; cerr << "clock: " << duration.count() << " ms." << endl; } #endif }; #define logit cerr << "i'm here" << endl; #define invec(x) for(auto & __a : x) cin >> __a #define outvec(x) for(auto & __a : x){cout << __a << " ";} cout << "\n" #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define allp(x) x->begin(),x->end() #define si(x) (int)x.size() #define fastio ios_base::sync_with_stdio(false);cin.tie(0) #define ll int64_t #define ld long double typedef pair<ll,ll> pll; typedef pair<int,int> pii; typedef tuple<ll,ll,ll> triplet; #ifndef aly_local #pragma GCC optimize("Ofast") #pragma GCC optimize("-funroll-loops") #endif template<typename T,typename Y> inline void mint(T & x,Y y){ x = min<T>(x,y);} template<typename T,typename Y> inline void maxt(T & x,Y y){ x = max<T>(x,y);} inline void local_input(){ #ifdef aly_local freopen("in.txt","r",stdin); #endif } constexpr int mod = (int) 998244353; constexpr int maxn = (int) 10000; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// auto solve() -> decltype(auto) { int a,b; cin >> a >> b; for(int value = b;;value--){ int range_multiples = (b/value) - ((a-1)/value); if(range_multiples >= 2){ return void(cout << value << "\n"); } } assert(false); } int32_t main(void){ __time __x; fastio;local_input(); uint32_t tcs = 1; // cin >> tcs; for(uint32_t i = 1;i <= tcs;i++) solve(); }
#include <bits/stdc++.h> using namespace std; #define ll long long #define FOR(i, a, b) for (ll i = (a); i < (b); ++i) #define ROF(i, a, b) for (ll i = (b)-1; i >= (a); --i) #define rep(a) for (ll i = 0; i < a; ++i) #define fio \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define iio \ ios_base::sync_with_stdio(0); #define tc \ ll tc; \ cin >> tc; \ rep(tc) #define vi vector<int> #define vl vector<ll> #define nl "\n" #define gp " " #define pb push_back #define pob pop_back #define vin(a, n) \ vector<int> a(n); \ rep(n) cin >> a[i]; #define vln(a, n) \ vector<ll> a(n); \ rep(n) cin >> a[i]; #define min3(a, b, c) min(min(a, b), c); #define min4(a, b, c, d) min(min(a, b), min(c, d)); #define max3(a, b, c) max(max(a, b), c); #define max4(a, b, c, d) max(max(a, b), max(c, d)); #define ff first #define ss second #define mod1 = 1000000007; #define i1(a) ll a;cin>>a; #define i2(a,b) ll a,b;cin>>a>>b; #define i3(a,b,c) ll a,b;cin>>a>>b>>c; #define i4(a,b,c,d) ll a,b;cin>>a>>b>>c>>d; #define i5(a,b,c,d,e) ll a,b;cin>>a>>b>>c>>d>>e; void solve() { } int main() { #ifndef ONLINE_JUDGE freopen("input.in", "r", stdin); freopen("output.out", "w", stdout); #endif fio; i2(n,q); vln(a,n); vln(quer,q); sort(a.begin(), a.end()); vector<ll> b(n); b[0]=a[0]-1; FOR(i,1,n){ b[i]=a[i]-i-1; } rep(q){ if (quer[i]>b[n-1]){ cout<<quer[i]+n<<nl; }else{ ll j=lower_bound(b.begin(),b.end(),quer[i])-b.begin(); cout<<a[j]-(b[j]-quer[i])-1<<nl; } } }
#include<bits/stdc++.h> using namespace std; #define mp make_pair #define mt make_tuple #define fi first #define se second #define pb push_back #define ll long long #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define rep(i,n) for(i=0;i<n;i++) #define forn(i, n) for (ll i = 0; i < (ll)(n); ++i) #define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i) #define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i) #define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i) #define fora(it,x) for(auto it:x) #define PI 3.14159265 #define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define endl "\n" typedef pair<ll, ll> pii; typedef vector<ll> 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 long 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; } const ll N=18; ll g[20][20]; ll dp[1<<N],dp1[1<<N],power[N]; vector<ll> arr[20]; ll fun1(vector<ll> &nodes){ if(nodes.size()==0) return(0); ll flag=1; for(auto u:nodes){ for(auto v:nodes){ if(u+1==v+1) continue; if(g[u+1][v+1]==0){ flag=0; break; } } if(flag==0) break; } //for(auto x:nodes) cout<<x+1<<" "; //cout<<flag; //cout<<endl; return(flag); } void fun2(ll num,ll n){ vector<ll> nodes; forn(i,n){ if((num&(1<<i))!=0) nodes.pb(i); } dp1[num]=fun1(nodes); } void fun(ll n,ll num){ for(ll i=num;i>0;i=((i-1)&num)){ ll num2=i; ll num1=num2^num; if(dp1[num2]==0) continue; else dp[num]=min(dp1[num2]+dp[num1],dp[num]); } } int main(){ sync ll n,m; cin>>n>>m; power[0]=1; for1(i,n) power[i]=2*power[i-1]; forn(i,m){ ll u,v; cin>>u>>v; g[u][v]=1; g[v][u]=1; } forn(i,1<<n){ ll c=0,num=0,p=1; forn(j,n){ if((i&(1<<j))!=0){ num=num+p; c++; } p*=2; } dp[num]=c; arr[c].pb(num); fun2(i,n); } dp[0]=0; forn(i,n+1){ for(auto x:arr[i]){ fun(n,x); } } //forn(i,1<<n) cout<<dp[i]<<" "; cout<<dp[(1<<n)-1]; }
#define _USE_MATH_DEFINES #include <algorithm> #include <cmath> #include <complex> #include <iostream> #include <map> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> #include <queue> #define INF 1010101010 #define INFLL 1010101010101010101 using namespace std; int mod = 1000000007; int main() { int n; long long t; cin >> n >> t; vector<long long> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<long long> b; int n2 = n / 2; int n3 = n - n2; for (int i = 0; i < (1 << n2); i++) { long long sum = 0; for (int j = 0; j < n2; j++) { if (((i >> j) & 1) == 1) { sum += a[j]; } } if (sum <= t) { b.emplace_back(sum); } } sort(b.begin(), b.end()); long long ans = 0; for (int i = 0; i < (1 << n3); i++) { long long sum = 0; for (int j = n / 2; j < n; j++) { if (((i >> (j - n / 2)) & 1) == 1) { sum += a[j]; } } if (sum > t) continue; int u = upper_bound(b.begin(), b.end(), t - sum) - b.begin(); u--; ans = max(ans, b[u] + sum); } cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll n; int k; string s; int main(){ cin>>s>>k; for(int i=0;i<k;i++){ ll a,b,ant; ant=1; a=0; b=0; string st; sort(s.begin(),s.end()); st=s; reverse(st.begin(),st.end()); for(int i=s.size()-1;i>=0;i--){ a+=(s[i]-'0')*ant; ant*=10; } ant=1; for(int i=st.size()-1;i>=0;i--){ b+=(st[i]-'0')*ant; ant*=10; } b-=a; if(b==0){ cout<<0; return 0; } stringstream ss; ss<<b; ss>>s; } cout<<s; }
#include <bits/stdc++.h> using namespace std; using ll = long long; ll n, k; ll g1(ll x){ if(x == 0) return 0; string S = to_string(x); vector<int> V; for(char s : S){ int i = s-'0'; V.push_back(i); } sort(V.begin(), V.end(), greater<int>()); string R = ""; for(int v : V) R += to_string(v); ll res = stoi(R); return res; } ll g2(ll x){ if(x == 0) return 0; string S = to_string(x); vector<int> V; for(char s : S){ int i = s-'0'; if(i > 0) V.push_back(i); } sort(V.begin(), V.end()); string R = ""; for(int v : V) R += to_string(v); ll res = stoi(R); return res; } ll solve(int i, ll x){ if(i == k) return x; ll calc = g1(x) - g2(x); return solve(i+1, calc); } int main(){ cin >> n >> k; cout << solve(0, n) << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i,i1,n) for(int i=(int)(i1);i<(int)(n);i++) #define ll long long #define vi vector<int> #define vll vector<long long> using graph = vector<vector<int>>; int main() { string s; cin>>s; int count=0; rep(i,0,9){ if(s.at(i)=='Z'&&s.at(i+1)=='O'&&s.at(i+2)=='N'&&s.at(i+3)=='e'){ count++; } } cout<<count; }
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define V vector #define pb push_back #define eb emplace_back #define lb lower_bound #define ub upper_bound #define mp make_pair #define rep(i, n) for (int i = 0; i < (n); i++) #define all(v) v.begin(), v.end() #define allr(v) v.rbegin(), v.rend() #define sz(x) int(x.size()) #define pcnt __builtin_popcountll 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> void print(T a) {cout << a << ' ';} template <typename T> void printe(T a) {cout << a << endl;} template <typename T> void printv(T a) {rep(i, sz(a))print(a[i]); cout<<endl;} template <typename T> void printp(pair<T, T> a) {print(a.first); cout<<a.second<<endl;} template <typename A, size_t N, typename T> void Fill (A (&array)[N], const T & val) {fill ((T*)array, (T*)(array+N), val);} template <typename T> using vc = vector<T>; template <typename T> using vv = vc<vc<T>>; template <typename T> using vvv = vc<vv<T>>; using ll = long long; using P = pair<int, int>; using Pl = pair<ll, ll>; using vi = vc<int>; using vvi = vv<int>; using vl = vc<ll>; using vvl = vv<ll>; vi di = {-1, 1, 0, 0, -1, -1, 1, 1}; vi dj = { 0, 0, -1, 1, -1, 1, -1, 1}; int main () { int n; cin >> n; int m = 5; vvi a(n, vi(m)); rep(i, n) rep(j, m) cin >> a[i][j]; vi MX(m, 0); rep(i, n) rep(j, m) chmax(MX[j], a[i][j]); int ans = 0; rep(i, n) { rep(j, i) { vi mx(m); // i,jさんの最大値 rep(k, 5) mx[k] = max(a[i][k], a[j][k]); int mn = 2e9, im = -1; rep(k, 5) if (chmin(mn, mx[k])) im = k; mx[im] = MX[im]; int res = 2e9; rep(k, 5) chmin(res, mx[k]); chmax(ans, res); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } #define M 1502 int a[M][M]; int b[M][M] = {}; signed main(){ int h, w; cin >> h >> w; int n, m; cin >> n >> m; for(int i = 0;i < n;i++){ int y, x; cin >> y >> x; y--; x--; a[y][x] = 1; } for(int i = 0;i < m;i++){ int y, x; cin >> y >> x; y--; x--; a[y][x] = -1; } for(int i = 0;i < h;i++){ int now = 0; for(int j = 0;j < w;j++){ if(a[i][j] == 1){ now = 1; }else if(a[i][j] == -1){ now = 0; } b[i][j] += now; } } for(int i = 0;i < h;i++){ int now = 0; for(int j = w-1;j >= 0;j--){ if(a[i][j] == 1){ now = 1; }else if(a[i][j] == -1){ now = 0; } b[i][j] += now; } } for(int j = 0;j < w;j++){ int now = 0; for(int i = 0;i < h;i++){ if(a[i][j] == 1){ now = 1; }else if(a[i][j] == -1){ now = 0; } b[i][j] += now; } } for(int j = 0;j < w;j++){ int now = 0; for(int i = h-1;i >= 0;i--){ if(a[i][j] == 1){ now = 1; }else if(a[i][j] == -1){ now = 0; } b[i][j] += now; } } int ans = 0; for(int i = 0;i < h;i++){ for(int j = 0;j < w;j++){ ans += min(b[i][j], 1ll); } } cout << ans << endl; return 0; }
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <iomanip> #include <queue> #include <stack> #include <cstdlib> #include <map> #include <iomanip> #include <set> #include <functional> #include <stdio.h> #include <ctype.h> #include <random> #include <string.h> #include <unordered_map> #include <cstdio> #include <climits> using namespace std; #define all(vec) vec.begin(),vec.end() typedef long long ll; ll gcd(ll x, ll y) { if (y == 0)return x; return gcd(y, x%y); } ll lcm(ll x, ll y) { return x / gcd(x, y)*y; } ll kai(ll x, ll y, ll m) { ll res = 1; for (ll i = x - y + 1; i <= x; i++) { res *= i; res %= m; } return res; } ll mod_pow(ll x, ll y, ll m) { ll res = 1; while (y > 0) { if (y & 1) { res = res * x % m; } x = x * x % m; y >>= 1; } return res; } ll comb(ll x, ll y, ll m) { if (y > x)return 0; return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m; } int h, w, n, m, a[500010], b[500010], c[100010], d[100010]; bool bl[1510][1510][4]; int dx[4] = { 0,0,1,-1 }, dy[4] = { 1,-1,0,0 }; signed main() { std::random_device rnd; std::mt19937_64 mt(rnd()); cin >> h >> w >> n >> m; for (int i = 0; i < n; i++)cin >> a[i] >> b[i]; for (int i = 0; i < m; i++)cin >> c[i] >> d[i]; for (int i = 0; i < m; i++)for (int j = 0; j < 4; j++)bl[c[i]][d[i]][j] = true; queue<pair<pair<int, int>, int>> que; for (int i = 0; i < n; i++) { for (int j = 0; j < 4; j++)que.push(make_pair(make_pair(a[i], b[i]), j)), bl[a[i]][b[i]][j] = true; } while (!que.empty()) { int x = que.front().first.first, y = que.front().first.second, k = que.front().second; que.pop(); int tx = x + dx[k], ty = y + dy[k]; if (tx < 1 || h < tx || ty < 1 || w < ty || bl[tx][ty][k])continue; bl[tx][ty][k] = true; que.push(make_pair(make_pair(tx, ty), k)); } int ans = 0; for (int i = 1; i <= h; i++)for (int j = 1; j <= w; j++)if (bl[i][j][0] || bl[i][j][1] || bl[i][j][2] || bl[i][j][3])ans++; cout << ans - m << endl; }
#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; } template <std::ostream& os = std::cout> class Prints { private: class __Prints { public: __Prints(const char* sep, const char* term) : sep(sep), term(term) {} template <class... Args> auto operator()(const Args&... args) const -> decltype((os << ... << std::declval<Args>()), void()) { print(args...); } template <typename T> auto pvec(const T& vec, size_t sz) const -> decltype(os << std::declval<decltype(std::declval<T>()[0])>(), void()) { for (size_t i = 0; i < sz; i++) os << vec[i] << (i == sz - 1 ? term : sep); } template <typename T> auto pmat(const T& mat, size_t h, size_t w) -> decltype(os << std::declval<decltype(std::declval<T>()[0][0])>(), void()) { for (size_t i = 0; i < h; i++) for (size_t j = 0; j < w; j++) os << mat[i][j] << (j == w - 1 ? term : sep); } private: const char *sep, *term; void print() const { os << term; } void print_rest() const { os << term; } template <class T, class... Tail> void print(const T& head, const Tail&... tail) const { os << head, print_rest(tail...); } template <class T, class... Tail> void print_rest(const T& head, const Tail&... tail) const { os << sep << head, print_rest(tail...); } }; public: Prints() {} __Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); } }; Prints<> prints; Prints<std::cerr> prints_err; //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% using Graph = std::vector<std::vector<int>>; void solve() { int N; cin >> N; Graph g(N); vector<Pii> edges(N - 1); for (ll i = 0; i < N - 1; i++) { int a, b; cin >> a >> b; --a, --b; g[a].emplace_back(b); g[b].emplace_back(a); edges[i] = {a, b}; } Vi ls(N), rs(N); { int idx = 0; auto dfs = [&](auto&& self, int u, int p) -> void { ls[u] = idx++; for (auto v : g[u]) { if (v != p) self(self, v, u); } rs[u] = idx; }; dfs(dfs, 0, -1); } Vl imos(N + 1); int Q; cin >> Q; while (Q--) { ll t, e, x; cin >> t >> e >> x; --e; auto [a, b] = edges[e]; if (t == 2) swap(a, b); if (ls[a] < ls[b]) { imos[0] += x; imos[N] -= x; imos[ls[b]] -= x; imos[rs[b]] += x; } else { imos[ls[a]] += x; imos[rs[a]] -= x; } } for (ll i = 0; i < N; i++) { imos[i + 1] += imos[i]; } for (ll i = 0; i < N; i++) { prints()(imos[ls[i]]); } } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 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; }
#include <bits/stdc++.h> // clang-format off using namespace std; using ll = long long; using ull = unsigned long long; using pll = pair<ll,ll>; const ll INF = 4e18; void print0() {} template<typename Head,typename... Tail> void print0(Head head,Tail... tail){cout<<fixed<<setprecision(15)<<head;print0(tail...);} void print() { print0("\n"); } template<typename Head,typename... Tail>void print(Head head,Tail... tail){print0(head);if(sizeof...(Tail)>0)print0(" ");print(tail...);} // clang-format on vector<pll> val; vector<vector<ll>> memo(2, vector<ll>(200005, -INF)); ll rec(ll isright, ll i) { if (i == val.size()) { return (isright ? abs(val[i - 1].second) : abs(val[i - 1].first)); } if (memo[isright][i] != -INF) return memo[isright][i]; ll cur = 0; if (i > 0) { cur = (isright ? val[i - 1].second : val[i - 1].first); } return memo[isright][i] = min( abs(cur - val[i].second) + abs(val[i].second - val[i].first) + rec(0, i + 1), abs(cur - val[i].first) + abs(val[i].first - val[i].second) + rec(1, i + 1)); } int main() { ll n; cin >> n; vector<vector<ll>> bkt(n + 1); for (ll i = 0; i < n; i++) { ll x, c; cin >> x >> c; bkt[c].push_back(x); } for(ll i = 0; i <= n; i++) { if(bkt[i].size()==0)continue; ll mx=-INF; ll mn=INF; for(auto e: bkt[i]){ mx=max(mx,e); mn=min(mn,e); } val.push_back({mn,mx}); } print(rec(0, 0)); }
#include<bits/stdc++.h> using namespace std; using ll = long long; const int N = 70 * 70 ; int dp[N][N]; const string s = "atcoder"; int main() { cout.precision(15); ll n; ll ans1 = 0, ans2 = 0, ans3 = 0, x; cin >> n; for(int i=0;i<n;i++)cin >> x, ans1+=abs(x),ans2+=abs(x)*abs(x), ans3 = max(ans3, abs(x)); cout << fixed << ans1 << ' ' << sqrt(1.0*ans2)<< ' ' << ans3 << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; const ll MOD = 1e9+7; const ll INF = 1e18; #define rep(i,m,n) for(ll i = (m); i <= (n); i++) #define zep(i,m,n) for(ll i = (m); i < (n); i++) #define rrep(i,m,n) for(ll i = (m); i >= (n); i--) #define print(x) cout << (x) << endl; #define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl; int main(){ cin.tie(0); ios::sync_with_stdio(false); ll n; cin >> n; ll x[n]; zep(i, 0, n)cin >> x[i]; ll a = 0; zep(i, 0, n)a += abs(x[i]); print(a) ll b = 0; zep(i, 0, n)b += x[i] * x[i]; cout << fixed << setprecision(20) << sqrt(b) << endl; ll c = 0; zep(i, 0, n)c = max(c, abs(x[i])); print(c) return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using db = long double; // or double, if TL is tight using str = string; // yay python! using pi = pair<int,int>; using pl = pair<ll,ll>; using pd = pair<db,db>; using vi = vector<int>; using vb = vector<bool>; using vl = vector<ll>; using vd = vector<db>; using vs = vector<str>; using vpi = vector<pi>; using vpl = vector<pl>; using vpd = vector<pd>; #define tcT template<class T #define tcTU tcT, class U // ^ lol this makes everything look weird but I'll try it tcT> using V = vector<T>; tcT, size_t SZ> using AR = array<T,SZ>; tcT> using PR = pair<T,T>; // pairs #define mp make_pair #define f first #define s second // vectors // oops size(x), rbegin(x), rend(x) need C++17 #define sz(x) int((x).size()) #define bg(x) begin(x) #define all(x) bg(x), end(x) #define rall(x) x.rbegin(), x.rend() #define sor(x) sort(all(x)) #define rsz resize #define ins insert #define ft front() #define bk back() #define pb push_back #define eb emplace_back #define pf push_front #define lb lower_bound #define ub upper_bound tcT> int lwb(V<T>& a, const T& b) { return int(lb(all(a),b)-bg(a)); } // loops #define FOR(i,a,b) for (int i = (a); i < (b); ++i) #define F0R(i,a) FOR(i,0,a) #define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i) #define R0F(i,a) ROF(i,0,a) #define trav(a,x) for (auto& a: x) const int MOD = 1e9+7; // 998244353; const int MX = 2e5+5; const ll INF = 1e18; // not too close to LLONG_MAX const db PI = acos((db)-1); const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1}; // for every grid problem!! mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); template<class T> using pqg = priority_queue<T,vector<T>,greater<T>>; // bitwise ops // also see https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html constexpr int pct(int x) { return __builtin_popcount(x); } // # of bits set constexpr int bits(int x) { // assert(x >= 0); // make C++11 compatible until USACO updates ... return x == 0 ? 0 : 31-__builtin_clz(x); } // floor(log2(x)) constexpr int p2(int x) { return 1<<x; } constexpr int msk2(int x) { return p2(x)-1; } ll cdiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up ll fdiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // divide a by b rounded down tcT> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } // set a = min(a,b) tcT> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } tcTU> T fstTrue(T lo, T hi, U f) { hi ++; assert(lo <= hi); // assuming f is increasing while (lo < hi) { // find first index such that f is true T mid = lo+(hi-lo)/2; f(mid) ? hi = mid : lo = mid+1; } return lo; } tcTU> T lstTrue(T lo, T hi, U f) { lo --; assert(lo <= hi); // assuming f is decreasing while (lo < hi) { // find first index such that f is true T mid = lo+(hi-lo+1)/2; f(mid) ? lo = mid : hi = mid-1; } return lo; } tcT> void remDup(vector<T>& v) { // sort and remove duplicates sort(all(v)); v.erase(unique(all(v)),end(v)); } tcTU> void erase(T& t, const U& u) { // don't erase auto it = t.find(u); assert(it != end(t)); t.erase(it); } // element that doesn't exist from (multi)set void solve() { int a,b; cin>>a>>b; int sum_a=0, sum_b=0; while(a) { sum_a += a%10; a /= 10; } while(b) { sum_b += b%10; b /= 10; } cout<<max(sum_a,sum_b); } int main() { cin.tie(0)->sync_with_stdio(0); int ct=1; // cin>>ct; while(ct--) { solve(); } }
#include <bits/stdc++.h> using namespace std; const long long INF = 1e18; const double pi = 3.1415926535897932384626433832795028841971693993751058209749445923; #define FOR(i, a, b) for(ll i = a; i < b; ++i) #define beg begin() #define ll long long #define vll vector <ll> #define pb push_back #define mkp make_pair #define vb vector <bool> void solve_it(){ double n; cin>>n; double x0, y0, x, y; cin>>x0>>y0>>x>>y; x = (x + x0) / 2; y = (y + y0) / 2; x0 -= x; y0 -= y; double theta = (360 / n) * (pi / 180); cout<<x0 * cos(theta) - y0 * sin(theta) + x<<" "; cout<<x0 * sin(theta) + y0 * cos(theta) + y; } int main(){ ios::sync_with_stdio(0); cin.tie(0); solve_it(); return 0; }
#include<bits/stdc++.h> using namespace std; #define INF 1234567890 #define ll long long int N; string s; int main() { ios::sync_with_stdio(0); cin.tie(0); cin.exceptions(ios::badbit | ios::failbit); cin >> N >> s; if (s[0] != s.back()) { cout << "1\n"; return 0; } for(int i=1; i<N; i++) if (s[i-1] != s[0] && s[i] != s[0]) { cout << "2\n"; return 0; } cout << "-1\n"; return 0; }
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<vector> #include<cmath> #include<algorithm> #include<map> #include<queue> #include<deque> #include<iomanip> #include<tuple> #include<cassert> #include<set> #include<complex> #include<numeric> #include<functional> #include<unordered_map> #include<unordered_set> using namespace std; typedef long long int LL; typedef pair<int,int> P; typedef pair<LL,LL> LP; const int INF=1<<30; const LL MAX=1e9+7; void array_show(int *array,int array_n,char middle=' '){ for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n')); } void array_show(LL *array,int array_n,char middle=' '){ for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n')); } void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){ if(vec_n==-1)vec_n=vec_s.size(); for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n')); } void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){ if(vec_n==-1)vec_n=vec_s.size(); for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n')); } template<typename T> ostream& operator<<(ostream& os,const vector<T>& v1){ int n=v1.size(); for(int i=0;i<n;i++){ if(i)os<<" "; os<<v1[i]; } return os; } template<typename T1,typename T2> ostream& operator<<(ostream& os,const pair<T1,T2>& p){ os<<p.first<<" "<<p.second; return os; } template<typename T> istream& operator>>(istream& is,vector<T>& v1){ int n=v1.size(); for(int i=0;i<n;i++)is>>v1[i]; return is; } template<typename T1,typename T2> istream& operator>>(istream& is,pair<T1,T2>& p){ is>>p.first>>p.second; return is; } namespace sol{ void solve(){ const int N=26; int n,m; int i,j,k; int a,b,c; string sa; cin>>n; cin>>sa; vector<int> dp(N,INF); for(i=0;i<N;i++){ if(sa[0]-'a'==i)continue; dp[i]=0; } for(i=0;i<n;i++){ a=sa[i]-'a'; b=dp[a]+1; if(i==n-1)break; c=sa[i+1]-'a'; for(j=0;j<N;j++){ if(j==c)continue; dp[j]=min(dp[j],b); } } if(b>=INF)b=-1; cout<<b<<endl; } } int main(){ cin.tie(0); ios::sync_with_stdio(false); sol::solve(); }
#include<iostream> #include<set> #include<vector> using namespace std; typedef long long li; #define rep(i,n) for(int i=0;i<(n);i++) #define df 0 template<class T> void print(const T& t){ cout << t << "\n"; } template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); } // Container コンテナ型, map以外 template< template<class ...> class Ctn,class T> std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){ auto itr=v.begin(); while(itr!=v.end()){ if(itr!=v.begin())cout << " "; cout << *(itr++); } return os; }; // pair 型 template<class S,class T> std::ostream& operator<<(std::ostream& os, const pair<T,S>& p){ cout << "(" << p.first << "," << p.second << ")"; return os; } struct node{ int v; li w; node(int vv=0,li ww=1){v=vv; w=ww;} }; struct graph{ int n; int m; int weighted,origin,directed; li ma; vector<vector<node>> adj; vector<li> col,w; graph(int nn,int mm,int d_flag=0,int w_flag=0,int ori=1){ ma=0; n=nn; m=mm; weighted=w_flag; directed=d_flag; origin=ori; if(df){ print(origin,"-origin"); if(weighted) print("weighted"); if(directed) print("directed"); } adj.resize(n); rep(i,m){ int a,b; li w=1; cin >>a >>b; a-=origin; b-=origin; if(weighted) cin >>w; adj[a].push_back({b,w}); if(not directed) adj[b].push_back({a,w}); ma=max(ma,w); } } void add(int a,int b,li w=1){ adj[a].push_back({b,w}); if(not directed) adj[b].push_back({a,w}); ma=max(ma,w); } li dijkstra(int a,int b); li dijkstra(int b=-1){ if(b==-1) b=n-1; return dijkstra(0,b); }; }; std::ostream& operator<<(std::ostream& os,const node& n){ printf("%d[%ld]",n.v,n.w); return os; }; std::ostream& operator<<(std::ostream& os,const graph& g){ if(g.weighted){ rep(i,g.n){ printf("%d :",i+g.origin); for(auto p:g.adj[i]){ printf(" %d[%d]",p.v+g.origin,p.w); } print(""); } }else{ rep(i,g.n){ printf("%d :",i+g.origin); for(auto p:g.adj[i]){ printf(" %d",p.v+g.origin); } print(""); } } return os; }; li graph::dijkstra(int a,int b){ set<pair<li,int>> que; que.insert({a,0}); vector<li> seen(n,ma*n+1); while(!que.empty()){ auto p=*que.begin(); que.erase(que.begin()); li d=p.first,v=p.second; if(df)print(v); if(v==b) return d; for(auto x:adj[v]){ int u=x.v; li d0=x.w; if(d+d0<seen[u]){ que.erase({seen[u],u}); seen[u]=d+d0; que.insert({seen[u],u}); } } if(df)print("que",que); } return ma*n+1; } int main(){ int r,c; cin >>r >>c; graph g(r*c*2,0,1,1,0); rep(i,r)rep(j,c-1){ li a; cin >>a; g.add(i*c+j,i*c+j+1,a); g.add(i*c+j+1,i*c+j,a); } rep(i,r-1)rep(j,c){ li b; cin >>b; g.add(i*c+j,(i+1)*c+j,b); } rep(i,r)rep(j,c){ g.add(i*c+j,r*c+i*c+j,1); g.add(r*c+i*c+j,i*c+j,0); } rep(i,r-1) rep(j,c){ g.add(r*c+(i+1)*c+j,r*c+i*c+j,1); } if(df)print(g); print(g.dijkstra(r*c-1)); }
#include<iostream> #include<string> #include<vector> #include<stack> #include<queue> #include<set> #include<map> #include<algorithm> #include<cstring> using namespace std; int n, m; int a[510][510]; int b[510][510]; long long dist[510][510]; priority_queue<pair<long long, pair<int, int>>, vector<pair<long long, pair<int, int>>>, greater<pair<long long, pair<int, int>>>> pq; bool in_range(int x, int y) { return x >= 1 && x <= n && y >= 1 && y <= m; } int main() { int i, j; int x, y; long long d; int nx, ny; long long nd; cin >> n >> m; for (i = 1; i <= n; i++) { for (j = 1; j < m; j++) { cin >> a[i][j]; } } for (i = 1; i < n; i++) { for (j = 1; j <= m; j++) { cin >> b[i][j]; } } memset(dist, 110, sizeof(dist)); dist[1][1] = 0; pq.push(make_pair(0, make_pair(1, 1))); while (!pq.empty()) { x = pq.top().second.first; y = pq.top().second.second; d = pq.top().first; pq.pop(); if (dist[x][y] != d) continue; nx = x + 1; ny = y; if (in_range(nx, ny)) { nd = d + b[x][y]; if (dist[nx][ny] > nd) { dist[nx][ny] = nd; pq.push(make_pair(nd, make_pair(nx, ny))); } } nx = x; ny = y - 1; if (in_range(nx, ny)) { nd = d + a[x][y - 1]; if (dist[nx][ny] > nd) { dist[nx][ny] = nd; pq.push(make_pair(nd, make_pair(nx, ny))); } } nx = x; ny = y + 1; if (in_range(nx, ny)) { nd = d + a[x][y]; if (dist[nx][ny] > nd) { dist[nx][ny] = nd; pq.push(make_pair(nd, make_pair(nx, ny))); } } for (i = 1; i < x; i++) { nx = i; ny = y; nd = d + x - i + 1; if (dist[nx][ny] > nd) { dist[nx][ny] = nd; pq.push(make_pair(nd, make_pair(nx, ny))); } } } cout << dist[n][m]; }
#include<bits/stdc++.h> #define int long long using namespace std; inline int read() { int x=0,flag=1; char ch=getchar(); while(ch<'0'||ch>'9') { if(ch=='-') flag=0; ch=getchar(); } while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+ch-'0'; ch=getchar(); } return (flag?x:~(x-1)); } int n,x,v,p; signed main() { n=read(); x=read()*100; for(int i=1;i<=n;i++) { v=read(); p=read(); x-=v*p; if(x<0) { cout<<i; return 0; } } cout<<-1; return 0; }
#include <iostream> using namespace std; int main() { int n, x; cin >> n >> x; int vsum = 0; x *= 100; for (int i = 0; i < n; ++i) { int v, p; cin >> v >> p; vsum += v * p; if (x < vsum) { cout << i + 1 << endl; break; } } if (vsum <= x) cout << -1 << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; vector<ll> fac; ll p=1e9+7; ll power(ll a, ll x) { ll ans=1; while(x) { if(x&1) { ans=(ans*a)%p; } x=x>>1; a=(a*a)%p; } return ans; } void pre(int n) { ll x=1; fac.push_back(x); for(ll i=1; i<=n; i++) { x=(x*i)%p; fac.push_back(x); } return; } bool win(vector<int> &a, vector<int> &b) { ll asum=0, bsum=0; for(ll i=1; i<10; i++) { asum+=i*power(10, a[i]); bsum+=i*power(10, b[i]); } return asum>bsum; } ll count(int &me, int &you, vector<int> original) { ll ans; ans=original[me]; original[me]--; ans=ans*original[you]; return ans; } void solve() { ll k; string s, t; cin>>k>>s>>t; vector<int> a(10), b(10), original(10); for(int i=0; i<4; i++) { a[s[i]-'0']++; b[t[i]-'0']++; } for(int i=1; i<10; i++) { original[i]=k-a[i]-b[i]; } ll good=0, total=(9*k-8)*(9*k-9); for(int me=1; me<10; me++) { for(int you=1; you<10; you++) { a[me]++; b[you]++; if(a[me]+b[me]<=k && a[you]+b[you]<=k && win(a, b)) { good+=count(me, you, original); } a[me]--; b[you]--; } } double ans=(double)good/(double)total; cout<<ans<<endl; return; } int main() { #ifdef bipinpathak (void)!freopen("input.txt", "r", stdin); (void)!freopen("output.txt", "w", stdout); #endif ios::sync_with_stdio(false); cin.tie(NULL); int t = 1; while(t--) { solve(); } return 0; }
#include<iostream> #include<cmath> long long func(double a,double b){ long long hb,lb; if (b>=0||b<0&&((long long)b)-b==0) hb=(long long) b;else hb=(long long) b-1; if (a<=0||a>0&&((long long)a)-a==0) lb=(long long) a;else lb=(long long) a+1; return hb-lb+1; } using namespace std; int main(){ long double x,y,r; cin>>x>>y>>r; r+=1e-14; long long ans=0; long long lb=ceil(x-r); long long rb=floor(x+r); for (long long i=lb;i<=rb;i++){ long double hbb=y+sqrt(r*r-(x-i)*(x-i)); long double lbb=y-sqrt(r*r-(x-i)*(x-i)); ans=ans+floor(hbb)-ceil(lbb)+1; // cout<<lbb<<' '<<hbb<<' '<<ans<<endl; } cout<<ans; }
#include <bits/stdc++.h> using namespace std; # define deb_v(x) cerr << #x << " = ("; \ for (auto item: x) cerr << a[i] << " "; \ cerr << ")\n"; # define deb(x) cerr << #x << " = " << x << "\n"; void solve(int t) { } int main() { int x; scanf("%d", &x); if (x >= 0) { printf("%d\n", x); } else { printf("0\n"); } }
#define DEBUG 0 #include <bits/stdc++.h> #define all(v) (v).begin(), (v).end() #define pb push_back #define rep(i,n) for(int i=0; i<(n); i++) #define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--) #define REP(i, begin, end) for(int i = int(begin); i < int(end); i++) using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; template<class T>using numr=std::numeric_limits<T>; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } const int INF = 1e9; const ll LLINF = 1e16; const int mod = 1000000007; const int mod2 = 998244353; void debug_impl() { std::cerr << std::endl; } template <typename Head, typename... Tail> void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); } #if DEBUG #define debug(...)\ do {\ std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\ debug_impl(__VA_ARGS__);\ std::cerr << std::noboolalpha;\ } while (false) #else #define debug(...) {} #endif template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr> std::istream& operator>> (std::istream& is, Container& v) { for (auto & x : v) { is >> x; } return is; } template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr > std::ostream& operator<< (std::ostream& os, Container const& v) { os << "{"; for (auto it = v.begin(); it != v.end(); it++) {os << (it != v.begin() ? "," : "") << *it;} return os << "}"; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); int x; cin >> x; if(x>=0) cout << x << endl; else cout << 0 << endl; }
#pragma GCC optimize ("O2") #pragma GCC target ("avx") //#include<bits/stdc++.h> #include<iostream> #include<cstring> //#include<atcoder/all> //using namespace atcoder; using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please char cn[1200010]; char* ci = cn, * di = cn; const ll ma0 = 1157442765409226768; const ll ma1 = 1085102592571150095; const ll ma2 = 71777214294589695; const ll ma3 = 281470681808895; const ll ma4 = 4294967295; inline int getint() { ll tmp = *(ll*)ci; int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0); tmp = tmp << dig & ma1; tmp = tmp * 10 + (tmp >> 8) & ma2; tmp = tmp * 100 + (tmp >> 16) & ma3; tmp = tmp * 10000 + (tmp >> 32) & ma4; ci += 72 - dig >> 3; return tmp; } int main() { cin.tie(0); ios::sync_with_stdio(false); fread(cn, 1, 1200010, stdin); int T = getint(); rep(t, T) { int N = getint(); rep(i, N)* di++ = '0'; rep(i, N)* di++ = '1'; *di++ = '0'; *di++ = '\n'; ci += 6 * N + 3; } fwrite(cn, 1, di - cn, stdout); Would you please return 0; }
//雪花飄飄北風嘯嘯 //天地一片蒼茫 #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/rope> using namespace std; using namespace __gnu_pbds; using namespace __gnu_cxx; #define ll long long #define ii pair<ll,ll> #define iii pair<ii,ll> #define fi first #define se second #define endl '\n' #define debug(x) cout << #x << " is " << x << endl #define pub push_back #define pob pop_back #define puf push_front #define pof pop_front #define lb lower_bound #define up upper_bound #define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--)) #define all(x) (x).begin(),(x).end() #define sz(x) (int)(x).size() #define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> //change less to less_equal for non distinct pbds, but erase will bug mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); int n,m,a,b; string grid[105]; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin.exceptions(ios::badbit | ios::failbit); cin>>n>>m>>a>>b; rep(x,0,n) cin>>grid[x]; a--,b--; int ans=-3; int c; c=b; while (c<m) if (grid[a][c]=='.') ans++,c++; else break; c=b; while (0<=c) if (grid[a][c]=='.') ans++,c--; else break; c=a; while (c<n) if (grid[c][b]=='.') ans++,c++; else break; c=a; while (0<=c) if (grid[c][b]=='.') ans++,c--; else break; cout<<ans<<endl; }
#include <algorithm> // #include <atcoder/all> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <tuple> #include <unordered_map> #include <vector> /* cd $dir && g++ -std=c++17 -Wall -Wextra -O2 -DATCODERDEBUG -I/mnt/d/MyProjects/atcoder/lib/ac-library $fileName && echo 'compilation ok!' && ./a.out */ using namespace std; #define REP(i, n) for (ll i = 0; i < ll(n); i++) #define FOR(i, a, b) for (ll i = a; i <= ll(b); i++) #define ALL(x) x.begin(), x.end() #define dame(a) \ { \ cout << a << endl; \ return 0; \ } typedef long long ll; class dstream : public ostream {}; template <typename T> dstream &operator<<(dstream &os, T v) { #ifdef ATCODERDEBUG cout << "\033[1;31m" << v << "\033[0m"; #endif return os; } ostream &endd(std::ostream &out) { #ifdef ATCODERDEBUG out << std::endl; #endif return out; } dstream dout; template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "[ "; for (auto const &x : v) { os << x; if (&x != &v.back()) { os << " : "; } } os << " ]" << endl; return os; } template <typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { os << "[" << endl; for (auto const &x : v) { os << " "; os << x; } os << "]" << endl; return os; } template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &v) { os << "[ " << v.first << " " << v.second << " ]" << endl; return os; } template <typename T, typename U, typename Comp = less<>> bool chmax(T &xmax, const U &x, Comp comp = {}) { if (comp(xmax, x)) { xmax = x; return true; } return false; } template <typename T, typename U, typename Comp = less<>> bool chmin(T &xmin, const U &x, Comp comp = {}) { if (comp(x, xmin)) { xmin = x; return true; } return false; } ll op(ll a, ll b) { return min(a, b); } ll e() { return 1e17; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll N, x, c; cin >> N; vector<vector<ll>> c2xs(N, vector<ll>()); REP(i, N) { cin >> x; cin >> c; c2xs[c - 1].emplace_back(x); } REP(i, N) { sort(c2xs[i].begin(), c2xs[i].end()); } ll left = 0; ll right = 0; ll left_v = 0; ll right_v = 0; REP(c, N) { ll siz = c2xs[c].size(); if (siz == 0) continue; ll minX = c2xs[c][0]; ll maxX = c2xs[c][siz - 1]; ll n_right_v = min(left_v + abs(left - minX), right_v + abs(right - minX)) + (maxX - minX); ll n_left_v = min(right_v + abs(right - maxX), left_v + abs(left - maxX)) + (maxX - minX); right_v = n_right_v; left_v = n_left_v; right = maxX; left = minX; dout << left << " " << left_v << " " << right << " " << right_v << endd; } ll ans = 1e17; chmin(ans, left_v + abs(left)); chmin(ans, right_v + abs(right)); cout << ans << endl; // cout << std::fixed << std::setprecision(15) << sqrt(ans) << endl; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0; i<n; i++) #define reps(i,s,n) for(int i=s; i<n; i++) #define per(i,n) for(int i=n-1; i>=0; i--) #define pers(i,n,s) for(int i=n-1; i>=s; i--) #define all(v) v.begin(),v.end() #define fi first #define se second #define pb push_back #define si(v) int(v.size()) #define lb(v,n) lower_bound(all(v),n) #define lbi(v,n) lower_bound(all(v),n) - v.begin() #define ub(v,n) upper_bound(all(v),n) #define ubi(v,n) upper_bound(all(v),n) - v.begin() #define mod 1000000007 #define infi 1010000000 #define infl 1100000000000000000 #define outve(v) for(auto i : v) cout << i << " ";cout << endl #define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;} #define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];} #define IN(n,m,v) rep(i,n) rep(j,m){cin >> v[i][j];} #define cyes cout << "Yes" << endl #define cno cout << "No" << endl #define cYES cout << "YES" << endl #define cNO cout << "NO" << endl #define csp << " " << #define outset(n) cout << fixed << setprecision(n); using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; using vi = vector<int>; using vvi = vector<vector<int>>; using vd = vector<double>; using vvd = vector<vector<double>>; using vl = vector<ll>; using vvl = vector<vector<ll>>; using vs = vector<string>; using pii = pair<int,int>; using pll = pair<ll,ll>; template<typename T> using ve = vector<T>; template<typename T> using pq2 = priority_queue<T>; template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>; template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;} template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;} int compress(vi& x1, vi& x2){ int n = si(x1); vi a; rep(i,n){ a.pb(x1[i]); a.pb(x2[i]); } sort(all(a)); a.erase(unique(all(a)),a.end()); rep(i,n){ x1[i] = lbi(a,x1[i]); x2[i] = lbi(a,x2[i]); } return si(a); } template <typename T> class BIT { ve<T> node; int n; T find(int m){ T s = 0; while (m > 0) { s += node[m]; m -= (m & (-m)); } return s; } public: BIT(int _n) : n(_n){ node.assign(n+1,0); } T sum(int a, int b){ T s_a = find(a); T s_b = find(b+1); return s_b - s_a; } void update(int m, T x){ m++; while (m <= n) { node[m] += x; m += (m & (-m)); } } }; void solve(){ int N; cin >> N; vi A(N),B(N); in(N,A); in(N,B); ll sum = 0; rep(i,N) sum += A[i]-B[i]; if(sum != 0){ cout << -1 << endl; return; } rep(i,N) A[i] += i, B[i] += i; int m = compress(A,B); ve<set<int>> C(m+1); rep(i,N) C[A[i]].insert(i); BIT<ll> bi(N+10); ll ans = 0; rep(i,N){ if(si(C[B[i]]) == 0){ cout << -1 << endl; return; } int a = *C[B[i]].begin(); C[B[i]].erase(a); //cout << a csp i csp bi.sum(0,a+1) << endl; ans += (ll)abs(a+bi.sum(0,a+1)-i); bi.update(0,1); bi.update(a+1,-1); } cout << ans << endl; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); solve(); return 0; }
#include <iostream> #include <algorithm> #include <string> #include <string.h> #include <stdlib.h> #include <math.h> #include <cmath> #include <vector> #include <queue> #include <stack> #include <cmath> #include <map> #include <iomanip> #include <set> #include <ctime> #include <tuple> #include <bitset> #include <assert.h> #include <deque> #include <functional> #include <numeric> using namespace std; typedef long long ll; #define fi first #define se second #define debugA cerr << "AAAAA" << endl #define debug_ cerr << "-------------" << endl #define debug(x) cerr << #x << ": " << x << endl #define debug_vec(v) \ cout << #v << endl; \ for (int i = 0; i < v.size(); i++) \ { \ cout << v[i] << " "; \ } \ cout << endl; #define debug_vec2(v) \ cout << #v << endl; \ for (int i = 0; i < v.size(); i++) \ { \ for (int j = 0; j < v[i].size(); j++) \ { \ cout << v[i][j] << " "; \ } \ cout << endl; \ } template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } template <typename T> void quit(T a) { cout << a << endl; exit(0); } using Graph = vector<vector<int> >; using P = pair<int, int>; using P1 = pair<int, pair<int, int> >; // クラスカル法とかで、{cost, {from, // to}}的に使う。 const ll LINF = 10010020030040056ll; const int INF = 1001001001; const double pi = acos(-1); int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); ll MOD = 998244353; ll a,b,c; cin >> a >> b >> c; ll tmp1 = (a *(a+1)) / 2; ll tmp2 = (b * (b+1)) / 2; ll tmp3 = (c * (c+1)) / 2; tmp1 %=MOD; tmp2 %=MOD; tmp3 %=MOD; ll ans = ((tmp1 * tmp2) % MOD) * tmp3 % MOD; ans = (ans + MOD) % MOD; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double int main() { ll A, B, C; cin >> A >> B >> C; ll mod = 998244353; ll inv2 = (mod+1)/2; ll X = A*(A+1)%mod*inv2%mod; ll Y = B*(B+1)%mod*inv2%mod; ll Z = C*(C+1)%mod*inv2%mod; ll ans = X*Y%mod*Z%mod; cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define MAXN 5005 #define lowbit(x) (x&-x) #define reg register #define mkpr make_pair #define fir first #define sec second typedef long long LL; typedef unsigned long long uLL; const int INF=0x3f3f3f3f; const int mo=998244353; const LL jzm=2333; const int iv2=499122177; const double Pi=acos(-1.0); typedef pair<int,int> pii; const double PI=acos(-1.0); template<typename _T> _T Fabs(_T x){return x<0?-x:x;} template<typename _T> void read(_T &x){ _T f=1;x=0;char s=getchar(); while(s>'9'||s<'0'){if(s=='-')f=-1;s=getchar();} while('0'<=s&&s<='9'){x=(x<<3)+(x<<1)+(s^48);s=getchar();} x*=f; } template<typename _T> void print(_T x){if(x<0){x=(~x)+1;putchar('-');}if(x>9)print(x/10);putchar(x%10+'0');} int n,m,fac[MAXN],inv[MAXN],f[MAXN],g[15][MAXN]; int add(int x,int y){return x+y<mo?x+y:x+y-mo;} void init(){ fac[0]=fac[1]=f[1]=inv[0]=inv[1]=1; for(int i=2;i<=5000;i++){ fac[i]=1ll*i*fac[i-1]%mo; f[i]=1ll*(mo-mo/i)*f[mo%i]%mo; inv[i]=1ll*f[i]*inv[i-1]%mo; } } int C(int x,int y){ if(x<y||x<0||y<0)return 0; return 1ll*fac[x]*inv[y]%mo*inv[x-y]%mo; } signed main(){ read(n);read(m);init();g[0][0]=1; for(int i=1;i<=13;i++){ for(int j=0;j<=n&&1ll*j*(1<<i-1)<=m;j+=2) for(int k=m;k>=1ll*j*(1<<i-1);k--) g[i][k]=add(1ll*C(n,j)*g[i-1][k-1ll*j*(1<<i-1)]%mo,g[i][k]); //for(int j=0;j<=m;j++)printf("g%d %d:%d\n",i,j,g[i][j]); } printf("%d\n",g[13][m]); return 0; } /* */
#include <bits/stdc++.h> using namespace std; const int maxn=210; int n; unsigned long long C[maxn][maxn]; int main() // C(n-1,11) { cin>>n;n--; for(int i=0;i<=n;i++) C[i][0]=1; for(int i=1;i<=n;i++) for(int j=1;j<=12;j++) C[i][j]=C[i-1][j]+C[i-1][j-1]; cout<<C[n][11]; return 0; }
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ll long long #define pb push_back #define INF 9223372036854775807ll #define endl '\n' #define pii pair<ll int,ll int> #define vi vector<ll int> #define all(a) (a).begin(),(a).end() #define F first #define S second #define sz(x) (ll int)x.size() #define hell 1000000007 #define rep(i,a,b) for(ll int i=a;i<b;i++) #define lbnd lower_bound #define ubnd upper_bound #define bs binary_search #define mp make_pair #define lower(u) transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase; #define upper(u) transform(u.begin(), u.end(), u.begin(), ::toupper); #define time cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; using namespace std; using namespace __gnu_pbds; #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> #define N 100005 void solve() { ll n,m; cin>>n>>m; if(m==0) { rep(i,1,n+1) { cout<<2*i<<" "<<2*i+1<<endl; } return; } if(m<0||m>n-2) { cout<<-1<<endl; } else { ll rem=n-m-1; ll l=1,r=1e9; rep(i,0,rem) { cout<<l<<" "<<r<<endl; l++; r--; } ll pre=rem+1; rep(i,0,m+1) { cout<<pre<<" "<<pre+1<<endl; pre+=2; } } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); int TESTS=1; // cin>>TESTS; while(TESTS--) { solve(); } time return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> P; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const int INF = (1<<30)-1; const int MOD = 1e9+7; const ll LINF = (1ll<<62)-1; #define REP(i,n) for(int i=0;i<(n);++i) #define COUT(x) cout<<(x)<<"\n" #define COUT16(x) cout << fixed << setprecision(16) << (x) << "\n"; int main(){ //input cin.tie(nullptr); ll n,a;cin >> n; unordered_map<int,ll>mp; REP(i,n){ cin >> a; mp[a]++; } //map ll ans = n*(n-1)/2; for(auto &p:mp){ ans -= (p.second-1)*p.second/2; } //output COUT(ans); }
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=18,M=205; long long dp[(1<<N)+5]; int n,m,x[M],y[M],z[M]; vector<pair<int,int> >g[N+5]; int main(){ cin>>n>>m; for(int i=1;i<=m;++i) cin>>x[i]>>y[i]>>z[i],g[x[i]].push_back(make_pair(y[i],z[i])); for(int i=0;i<=n;++i) sort(g[i].begin(),g[i].end()); dp[0]=1; for(int S=0;S<(1<<n);++S){ const int bitc=__builtin_popcount(S); for(int j=0;j<n;++j) if(!(S>>j&1)){ vector<int> v; for(int k=0;k<n;++k) if((S|(1<<j))>>k&1) v.push_back(k+1); sort(v.begin(),v.end(),greater<int>()); int cnt=0,f=1; for(auto e:g[bitc+1]){ while(!v.empty()&&v.back()<=e.first) v.pop_back(),++cnt; f&=(cnt<=e.second); } if(f) dp[S|(1<<j)]+=dp[S]; } } cout<<dp[(1<<n)-1]<<'\n'; return 0; }
#include <bits/stdc++.h> const long long INF = 1e9; const long long MOD = 1e9 + 7; //const long long MOD = 998244353; const long long LINF = 1e18; using namespace std; #define YES(n) cout << ((n) ? "YES" : "NO" ) << endl #define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl #define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE" ) << endl #define Possible(n) cout << ((n) ? "Possible" : "Impossible" ) << endl #define dump(x) cout << #x << " = " << (x) << endl #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) for(int i=0;i<(n);++i) #define REPR(i,n) for(int i=n;i>=0;i--) #define COUT(x) cout<<(x)<<endl #define SCOUT(x) cout<<(x)<<" " #define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl #define ENDL cout<<endl #define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__) #define LCIN(...) long long __VA_ARGS__;CINT(__VA_ARGS__) #define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__) #define VECCIN(x) for(auto&youso_: (x) )cin>>youso_ #define mp make_pair #define PQ priority_queue<long long> #define PQG priority_queue<long long,V,greater<long long>> typedef long long ll; typedef vector<long long> vl; typedef vector<long long> vi; typedef vector<bool> vb; typedef vector<char> vc; typedef vector<vl> vvl; typedef vector<vi> vvi; typedef vector<vb> vvb; typedef vector<vc> vvc; typedef pair<long long, long long> pll; #define COUT(x) cout<<(x)<<endl void CINT(){} template <class Head,class... Tail> void CINT(Head&& head,Tail&&... tail){ cin>>head; CINT(move(tail)...); } template<class T> void mod(T &x) { x %= MOD; x += MOD; x %= MOD; } ll solve(ll x, vl &a) { ll ans = 0; return ans; } void Main() { CIN(N, T); vl A(N); VECCIN(A); vl B, C, D, E; for(ll i = 0; i < N; i++) { if(i%2) { B.push_back(A.at(i)); } else { C.push_back(A.at(i)); } } D.push_back(0); for(ll i = 0; i < N/2; i++) { for(ll j = 0; j < (ll)pow(2,i); j++) { D.push_back(D.at(j) + B.at(i)); } } sort(D.begin(),D.end()); // VECCOUT(D); E.push_back(0); for(ll i = 0; i < N - N/2; i++) { for(ll j = 0; j < (ll)pow(2,i); j++) { E.push_back(E.at(j) + C.at(i)); } } // VECCOUT(E); ll ans = 0; for(ll i = 0; i < E.size(); i++) { // ans = max(ans, solve(E.at(i), D)); if(E.at(i) > T) continue; ans = max(ans, *(upper_bound(D.begin(), D.end(), T - E.at(i)) - 1) + E.at(i)); // cout << ans << endl; } cout << ans << endl; } int main() { cout << fixed << setprecision(15); Main(); return 0; }
#include <bits/stdc++.h> #include <vector> #include <fstream> #include <string> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define ll unsigned long long int main() { //入力 int n; cin >> n; //処理 if (n % 2 == 0) cout << "White" << endl; else cout << "Black" << endl; //出力 // cout << ans << endl; return 0; }
#include <iostream> using namespace std; int main() { int n; cin >> n; if (n%2 == 0) { cout << "White" << endl; } else { cout << "Black" << endl; } }
#include<iostream> #include<string> #include<algorithm> #include<vector> #include<set> #include<map> #include <functional> #include <iomanip> #include<cmath> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; using ll = long long; int GetDigit(ll num) { int a = 0; while (num) { num /= 10; a++; } return a; } ll Get_keta_num(ll num) { ll z = 0; while (num) { z += num % 10; num /= 10; } return z; } void print(set<int> s) { for (set<int>::iterator it = s.begin(); it != s.end(); it++) { cout << *it << " "; } cout << endl; } ll count_num_2(ll num) { ll data = 0; while (true) { ll m = num % 1000; ll k = num % 100; if ((m % 8) == 0) { data += 3; num /= 8; continue; } else if ((k % 4) == 0) { data += 2; num /= 4; continue; } else if ((k % 2) == 0) { data++; num /= 2; continue; } break; } return data; } ll facctorialMethod(int k) { ll sum = 1; for (int i = 1; i <= k; ++i) { sum *= i; } return sum; } //" " ll Get_num_in_string(string s) { int n = s.length(), z; ll sur = 0; for (int i = 0; i < n; i++) { z = int(s[i] - '0'); if (z < 10) { sur *= 10; sur += z; } } return sur; } ll ll_pow(int num, int zyousuu) { ll ans = 1; for (int i = 0; i < zyousuu; i++) { ans *= num; } return ans; } string substrBack(std::string str, size_t pos, size_t len) { const size_t strLen = str.length(); return str.substr(strLen - pos, len); } ll ll_gcd(ll x, ll y) { if (x < y) { ll a = x; x = y; y = a; } while (y > 0) { ll r = x % y; x = y; y = r; } return x; } int main() { ll a, b, c; cin >> a >> b >> c; ll a_num = (a + 1) * a / 2; a_num %= 998244353; ll c_num = (c + 1) * c / 2; ll b_num = (b + 1) * b / 2; c_num %= 998244353; b_num %= 998244353; a_num = (a_num * b_num) % 998244353; a_num= (a_num * c_num) % 998244353; cout << a_num << endl; return 0; }
#include <iostream> #include <cstdio> #include <string> #include <algorithm> #include <utility> #include <cmath> #include <vector> #include <stack> #include <queue> #include <deque> #include <set> #include <unordered_set> #include <map> #include <tuple> #include <numeric> #include <functional> using namespace std; typedef long long ll; typedef vector<ll> vl; typedef vector<vector<ll>> vvl; typedef pair<ll, ll> P; #define rep(i, n) for(ll i = 0; i < n; i++) #define exrep(i, a, b) for(ll i = a; i <= b; i++) #define out(x) cout << x << endl #define exout(x) printf("%.5f\n", x) #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define pb push_back #define re0 return 0 const ll mod = 1000000007; const ll INF = 1e16; int main() { ll n; double D, H; cin >> n >> D >> H; double ans = 0.0; rep(i, n) { double d, h; cin >> d >> h; double k = (H - h) / (D - d); chmax(ans, h - k * d); } exout(ans); re0; }
#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++) #define per(i, n) for (int i = n - 1; i >= 0; i--) #define per1(i, n) for (int i = n; i >= 1; i--) using namespace std; typedef long long int ll; template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; /*--------------------------------------------------*/ /*--------------------------------------------------*/ ll f(ll n) { return n * (n + 1) / 2; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int T; cin >> T; rep(i, T) { int L, R; cin >> L >> R; if (2 * L <= R) { cout << f(R - 2 * L + 1) << "\n"; } else { cout << 0 << "\n"; } } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long lint; #define rep(i,n) for(lint (i)=0;(i)<(n);(i)++) #define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++) #define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--) #define INF (1ll<<60) #define all(x) (x).begin(),(x).end() const lint MOD =1000000007; const lint MAX = 1000000; using Graph =vector<vector<lint>>; typedef pair<lint,lint> P; typedef map<lint,lint> M; #define chmax(x,y) x=max(x,y) #define chmin(x,y) x=min(x,y) lint fac[MAX], finv[MAX], inv[MAX]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (lint i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } long long COM(lint n, lint k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } lint primary(lint num) { if (num < 2) return 0; else if (num == 2) return 1; else if (num % 2 == 0) return 0; double sqrtNum = sqrt(num); for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) { return 0; } } return 1; } long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } lint lcm(lint a,lint b){ return a/__gcd(a,b)*b; } lint gcd(lint a,lint b){ return __gcd(a,b); } int main(){ lint x,y,a,b; cin>>x>>y>>a>>b; --y; lint ans=0; lint c=x; while(c<b/a){ c*=a; if(c>y)break; ans++; } lint add=max(0LL,(y-c)/b); ans+=add; cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; #define fi first #define se second #define rep(i, n) for (ll i = 0; i < (n); ++i) #define rep0(i, n) for (ll i = 0; i <= (n); ++i) #define rep1(i, n) for (ll i = 1; i <= (n); ++i) #define rrep1(i, n) for (ll i = (n); i > 0; --i) #define rrep0(i, n) for (ll i = (n); i >= 0; --i) #define srep(i, s, t) for (ll i = s; i < t; ++i) #define srep1(i, s, t) for (ll i = s; i <= t; ++i) #define rng(a) a.begin(), a.end() #define rrng(a) a.rbegin(), a.rend() #define isin(x, l, r) ((l) <= (x) && (x) < (r)) #define pb push_back #define eb emplace_back #define sz(x) (int)(x).size() #define pcnt __builtin_popcountll #define uni(x) x.erase(unique(rng(x)), x.end()) #define snuke srand((unsigned)clock() + (unsigned)time(NULL)); #define show(x) cerr << #x << " = " << x << endl; #define PQ(T) priority_queue<T, v(T), greater<T>> #define bn(x) ((1 << x) - 1) #define dup(x, y) (((x) + (y)-1) / (y)) #define newline puts("") #define v(T) vector<T> #define vv(T) v(v(T)) typedef unsigned uint; typedef unsigned long long ull; typedef pair<int, int> P; typedef tuple<int, int, int> T; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<P> vp; typedef vector<T> vt; constexpr ll MAX = 200002; int main() { ll n; cin >> n; vl a(MAX, 0); ll b = 0, maxb = 0, sum = 0, ans = 0; rep1(i, n) cin >> a[i]; rep1(i, n) { b += a[i]; maxb = max(maxb, b); ans = max(ans, sum + maxb); sum += b; } cout << ans << endl; return 0; }
#include<stdio.h> #include<iostream> #include<string.h> #include<algorithm> #include<queue> #include<stack> #include<math.h> #include<map> typedef long long int ll; using namespace std; #define maxn 0x3f3f3f3f #define INF 0x3f3f3f3f3f3f3f3f const int mm=2e5+100; ll d[mm],num[mm]; int main() { ll n,m,i,j,t,a,b,c,p,k,kk; cin>>n; for(i=1;i<=n;i++) scanf("%lld",&d[i]); for(i=1;i<=n;i++) { num[i]=num[i-1]+d[i]; } ll ans=0; p=0; ll sum=0; for(i=1;i<=n;i++) { ans+=num[i]; if(ans>=sum) { sum=ans; p=i; } } if(p==0) { printf("0\n"); } else { ll sum1=sum; ll o=0; o=max(o,sum); if(p!=1) { for(i=p;i>=1;i--) { if(d[i]>=0) { sum1-=d[i]; } else sum1-=d[i]; o=max(o,sum1); } o=max(o,sum1); } sum1=sum; // cout<<sum1<<endl; if(p!=n) { for(i=1;i<=p;i++) { if(d[i]<=0) { sum1+=d[i]; } else sum1+=d[i]; o=max(o,sum1); //cout<<sum1<<endl; } o=max(o,sum1); } cout<<o<<endl; } }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)(n);i++) #define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++) #define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--) #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++) #define setp(n) fixed << setprecision(n) template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } #define ll long long #define vll vector<ll> #define vi vector<int> #define pll pair<ll,ll> #define pi pair<int,int> #define all(a) (a.begin()),(a.end()) #define rall(a) (a.rbegin()),(a.rend()) #define fi first #define se second #define pb push_back #define ins insert #define debug(a) cerr<<(a)<<endl #define dbrep(a,n) rep(_i,n) cerr<<(a[_i])<<" "; cerr<<endl #define dbrep2(a,n,m) rep(_i,n){rep(_j,m) cerr<<(a[_i][_j])<<" "; cerr<<endl;} using namespace std; template<class A, class B> ostream &operator<<(ostream &os, const pair<A,B> &p){return os<<"("<<p.fi<<","<<p.se<<")";} template<class A, class B> istream &operator>>(istream &is, pair<A,B> &p){return is>>p.fi>>p.se;} //------------------------------------------------- //--ModInt //------------------------------------------------- const uint_fast64_t MOD = 998244353; class mint { private: using Value = uint_fast64_t; Value n; public: mint():n(0){} mint(int_fast64_t _n):n(_n<0 ? MOD-(-_n)%MOD : _n%MOD){} mint(const mint &m):n(m.n){} friend ostream& operator<<(ostream &os, const mint &a){ return os << a.n; } friend istream& operator>>(istream &is, mint &a){ Value temp; is>>temp; a = mint(temp); return is; } mint& operator+=(const mint &m){n+=m.n; n=(n<MOD)?n:n-MOD; return *this;} mint& operator-=(const mint &m){n+=MOD-m.n; n=(n<MOD)?n:n-MOD; return *this;} mint& operator*=(const mint &m){n=n*m.n%MOD; return *this;} mint& operator/=(const mint &m){return *this*=m.inv();} mint& operator++(){return *this+=1;} mint& operator--(){return *this-=1;} mint operator+(const mint &m) const {return mint(*this)+=m;} mint operator-(const mint &m) const {return mint(*this)-=m;} mint operator*(const mint &m) const {return mint(*this)*=m;} mint operator/(const mint &m) const {return mint(*this)/=m;} mint operator++(int){mint t(*this); *this+=1; return t;} mint operator--(int){mint t(*this); *this-=1; return t;} bool operator==(const mint &m) const {return n==m.n;} bool operator!=(const mint &m) const {return n!=m.n;} mint operator-() const {return mint(MOD-n);} mint pow(Value b) const { mint ret(1), m(*this); while(b){ if (b & 1) ret*=m; m*=m; b>>=1; } return ret; } mint inv() const {return pow(MOD-2);} }; //------------------------------------------------- int main(void) { int N,M; cin>>N>>M; mint ans = mint(M).pow(N)*N; mint M_inv = mint(M).inv(); mint A = mint(M).pow(N-2); FOR(t,1,M){ mint X = mint(M-t)*M_inv; mint D = (mint(1)-X).inv(); ans -= A*D*(D*(X.pow(N)-1)+N); } cout<<ans<<"\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { // your code goes here long long t,n; cin>>t>>n; cout<<(long long)ceil(100*n/(long double)t)+n-1<<endl; return 0; }
//#include <atcoder/maxflow.hpp> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> #include <iostream> #include <map> #include <list> #include <set> #include <algorithm> #include <vector> #include <string> #include <functional> #include <queue> #include <deque> #include <stack> #include <unordered_map> #include <unordered_set> #include <cmath> #include <iterator> #include <random> #include <chrono> #include <complex> #include <bitset> #include <fstream> #define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i) #define set_map_includes(set, elt) (set.find((elt)) != set.end()) #define readint(i) int i; cin >> i #define readll(i) ll i; cin >> i #define readdouble(i) double i; cin >> i #define readstring(s) string s; cin >> s typedef long long ll; //using namespace __gnu_pbds; //using namespace atcoder; using namespace std; const ll modd = (1000LL * 1000LL * 1000LL + 7LL); //const ll modd = 998244353; int main(int argc, char *argv[]) { mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int> rand_gen(0, modd); // rand_gen(rng) gets the rand no ios_base::sync_with_stdio(false); cin.tie(0); cout.precision(12); // readint(test_cases); int test_cases = 1; forr(t, 1, test_cases) { readint(n); vector<ll> a; forr(i,0,n) { readll(aa); a.push_back(2*aa); } sort(a.begin(), a.end()); vector<ll> summ; summ.push_back(0); for(auto x : a) { summ.push_back(summ.back() + x); } ll minval = modd*modd; forr(i,0,n) { ll val = (ll)(i+1)*a[i]/2 + (summ.back() - summ[i+1]) - (ll)(n-i-1)*a[i]/2; minval = min(minval, val); } cout << (double)minval/static_cast<double>(2*n) << endl; } return 0; }
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <numeric> #include <queue> using namespace std; typedef long long ll; int main(){ ll X,Y,A,B; cin >> X >> Y >> A >> B; ll ans = 0; while(X<Y/A && X*A<=X+B){ X *= A; ans++; } ans += (Y-1-X)/B; cout << ans << endl; }
#include <bits/stdc++.h> typedef long long LL; using namespace std; LL n; int main (){ cin>>n; LL m=2*n+2, x=sqrt(n); while(x*(x+1)>m) x--; while(x*(x+1)<=m) x++; n -= x-1; printf("%lld\n",n+1); }
#include<bits/stdc++.h> using namespace std; #define f(i,a,b) for(register int i=a;i<=b;++i) #define ll long long inline ll read(){ll x;scanf("%lld",&x);return x;} ll Abs(ll x){if(x<0)return -x;return x;} int main() { ll n=read(); __int128 L=0,R=n+1; while(L<R){ __int128 Mid=(L+R+1)>>1; if((__int128)(1+Mid)*Mid/2<=n+1) L=Mid; else R=Mid-1; } cout<<n-(ll)L+1; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ //2位を出力して、O(n)で2位の順番を探しだす int n; cin >> n; int n_sub=1; for(int i=0;i<n;i++){ n_sub*=2; } vector<int> a(n_sub/2); vector<int> a_sub(n_sub/2); vector<int> b(n_sub/2); vector<int> b_sub(n_sub/2); for(int i=0;i<n_sub;i++){ if(i<(n_sub/2)){ cin >> a_sub[i]; a[i] = a_sub[i]; }else{ cin >> b_sub[i-(n_sub/2)]; b[i-(n_sub/2)] = b_sub[i-(n_sub/2)]; } } sort(a_sub.begin(),a_sub.end()); sort(b_sub.begin(),b_sub.end()); int max_a = a_sub[(n_sub/2)-1]; int max_b = b_sub[(n_sub/2)-1]; int max_c = min(max_a,max_b); for(int i=0;i<n_sub/2;i++){ if(a[i]==max_c){ cout << i+1 << endl; return 0; } } for(int i=0;i<n_sub/2;i++){ if(b[i]==max_c){ cout << (n_sub/2)+i+1 << endl; return 0; } } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; ll pow(ll a, ll b) { for (int i = 1; i <= b; i++) { a *= a; if (i = b) return a; } } int main() { ll n; cin >> n; ll max_1 = 0, max_2 = 0; ll p = 0, q = 0; ll k = pow(2, n - 1); vector<ll> a(k * 2); for (int i = 0; i < 2 * k; i++) { cin >> a[i]; } for (int i = 0; i < k; i++) { if(max_1<=a[i]){ max_1 = max(max_1, a[i]); p=i; } } for (int i = k; i < k * 2; i++) { if(max_2<=a[i]){ max_2 = max(max_2, a[i]); q=i; } } if (min(max_1, max_2) == max_1) cout << p + 1 << endl; else cout << q + 1 << endl; }
#include <iostream> #include <vector> #include <array> #include <set> using namespace std; int main(){ int n; cin>> n; vector<array<int,5> > A(n); for(auto& a: A) for(int &i :a) cin>> i; //for(auto& a: A) for(int &i :a) cout <<i<<" "; int left=0, right = 1e9+1; auto check = [&](int x)-> bool{ set<int> s; for(auto& a: A){ int bit = 0; for(int& i :a){ bit <<=1; bit |= i>=x; } s.insert(bit); } for(int x: s) for(int y: s) for(int z: s){ if((x|y|z)==31) return 1; } return 0; }; while(left+1<right){ int cen = (left + right) / 2; if(check(cen)){ left = cen; }else{ right = cen; } } cout << left << endl; return 0; }
#include<stdio.h> #include<string.h> #include<stdlib.h> #include<math.h> #include<time.h> #include<algorithm> using namespace std; const int N=50005; int n; int w[N][5],ans; int mn[N][1<<5],a[N]; inline bool check(int val) { for(int i=1 ; i<=n ; ++i) a[i]=0; for(int i=1 ; i<=n ; ++i) for(int j=0 ; j<5 ; ++j) if(w[i][j]>=val) a[i]|=1<<j; for(int i=1 ; i<=n ; ++i) { for(int S=0 ; S<32 ; ++S) mn[i][S]=mn[i-1][S]; for(int S=0 ; S<32 ; ++S) mn[i][S|a[i]]=min(mn[i-1][S]+1,mn[i][S|a[i]]); } return mn[n][31]<=3; } int main() { int l=0,r=1000000000; scanf("%d",&n); for(int i=1 ; i<=n ; ++i) for(int j=0 ; j<5 ; ++j) scanf("%d",&w[i][j]); mn[0][0]=0; for(int i=1 ; i<32 ; ++i) mn[0][i]=4; while(l<=r) { int mid=(l+r)>>1; if(check(mid)) ans=mid,l=mid+1; else r=mid-1; } printf("%d",ans); return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define lop(n) for(ll i=0;i<n;i++) #define loop(a,b) for(ll i=a;i<b;i++) #define sortt(x) sort(x.begin(),x.end()) #define MOD 1000000007 #define en "\n" #define F first #define S second #define inputlist for(ll i=0;i<n;i++) cin>>A[i] #define pb(x) push_back(x) #define MP make_pair #define PI 3.14159265 void solve() { ll n; cin>>n; map<ll,ll> mp; for(ll i=0;i<n;i++) { ll a;cin>>a;mp[a]++; } vector<ll> vec; for(auto itr:mp) vec.pb(itr.F); ll ans = 1; n=vec.size(); for(ll i=n-1;i>0;i--) { ans = (ans + ((vec[i]-vec[i-1])*ans)%MOD )%MOD; } ans = (ans + (vec[0]*ans)%MOD )%MOD; cout<<ans; } //536870912 int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); //cin>>s; //call(); // fac[0] = 1; // for (int i = 1; i <= 200005; i++) // fac[i] = (fac[i - 1] * i) % MOD; ll t=1; // cin>>t; for(ll i=1;i<=t;i++) { // cout<<"Case #"<<i<<": "; solve(); } 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; ll n,a[114514],ans=1; int main() { read(n);F(i,1,n)read(a[i]);sort(a+1,a+n+1); F(i,1,n)ans=ans*(a[i]-a[i-1]+1)%1000000007; write(ans); return 0; }
#pragma GCC target ("avx2") // #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #include <iostream> #include <array> #include <algorithm> #include <vector> #include <bitset> #include <set> #include <unordered_set> #include <cmath> #include <complex> #include <deque> #include <iterator> #include <numeric> #include <map> #include <unordered_map> #include <queue> #include <stack> #include <string> #include <tuple> #include <utility> #include <limits> #include <iomanip> #include <functional> #include <cassert> // #include <atcoder/all> using namespace std; using ll=long long; template<class T> using V = vector<T>; template<class T, class U> using P = pair<T, U>; using vll = V<ll>; using vii = V<int>; using vvll = V<vll>; using vvii = V< V<int> >; using PII = P<int, int>; using PLL = P<ll, ll>; #define RevREP(i,n,a) for(ll i=n;i>a;i--) // (a,n] #define REP(i,a,n) for(ll i=a;i<n;i++) // [a,n) #define rep(i, n) REP(i,0,n) #define ALL(v) v.begin(),v.end() #define eb emplace_back #define pb push_back #define sz(v) int(v.size()) 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; } template< class A, class B > ostream& operator <<(ostream& out, const P<A, B> &p) { return out << '(' << p.first << ", " << p.second << ')'; } template< class A > ostream& operator <<(ostream& out, const V<A> &v) { out << '['; for (int i=0;i<int(v.size());i++) { if (i) out << ", "; out << v[i]; } return out << ']'; } const long long MOD = 1000000007; const long long HIGHINF = (long long)1e18; const int INF = (int)1e9; int main() { cin.tie(0); ios::sync_with_stdio(false); int n, m; cin >> n >> m; vii a(n), b(m); set<int> aset, bset; rep(i, n) { cin >> a[i]; aset.insert(a[i]); } rep(i, m) { cin >> b[i]; bset.insert(b[i]); } vii ans; rep(i, n) { if (bset.find(a[i]) == bset.end()) ans.eb(a[i]); } rep(i, m) { if (aset.find(b[i]) == aset.end()) ans.eb(b[i]); } sort(ALL(ans)); rep(i, sz(ans)) { if (i) cout << ' '; cout << ans[i]; } cout << '\n'; return 0; }
#include <stdio.h> #include <stdlib.h> #include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <string> #include <vector> using namespace std; using ll = long long int; using ull = unsigned long long int; 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; } bool a[1001]; bool b[1001]; int main() { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { int t; cin >> t; a[t] = true; } for (int i = 0; i < m; i++) { int t; cin >> t; b[t] = true; } for (int i = 1; i < 1001; i++) { if (a[i] ^ b[i]) { cout << i << " "; } } cout << endl; }
#include<bits/stdc++.h> using namespace std; typedef unsigned long long ull; inline ull Hash(const string& s){ ull ans=0; for(auto c : s) ans=ans*26+c-'a'; return ans; } string s; int N; set<ull> s1,s2; inline void work(){ for(int i=1;i<=N;i++){ cin>>s; set<ull> &t1=(s[0]=='!'?s1:s2); set<ull> &t2=(s[0]!='!'?s1:s2); reverse(s.begin(),s.end()); if( *s.rbegin()=='!' ) s.pop_back(); ull val=Hash(s); if( t1.find(val)!=t1.end() ){ reverse(s.begin(),s.end()); cout<<s<<endl; return ; } else t2.insert(val); } cout<<"satisfiable"<<endl; } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>N; work(); return 0; }
#include<bits/stdc++.h> using namespace std; struct{template<class T>constexpr operator T(){return numeric_limits<T>::max();}constexpr auto operator-();}inf; struct{template<class T>constexpr operator T(){return numeric_limits<T>::lowest();}constexpr auto operator-();}negative_inf; constexpr auto decltype(inf)::operator-(){return negative_inf;} constexpr auto decltype(negative_inf)::operator-(){return inf;} #define swap(a,b) {a^=b;b^=a;a^=b;} #define rep(i,n) for(long long i = 0; i < n; i++) #define reps(i,s,n) for(long long i = (s); i < n; i++) #define repr(i,n) for(long long i = (n - 1); i >= 0; i--) #define LOOP for(long long i = 0;;i++) #define PB push_back #define ALL(v) v.begin(),v.end() #define DOUBLE fixed << setprecision(15) typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<long long> vll; typedef vector<double> vd; typedef vector<char> vc; typedef vector<bool> vb; typedef vector<string> vs; typedef vector<vi> vvi; typedef vector<vll> vvll; typedef vector<vvll> vvvll; typedef vector<vd> vvd; typedef vector<vc> vvc; typedef vector<vb> vvb; typedef pair<ll,ll> P; typedef vector<P> vP; #define F first #define S second #define SPC << " " ll gcd(ll x,ll y){if(x<=0||y<=0)return 0;if(y>x){swap(x,y);}return x%y==0?y:gcd(y,x%y);} ll lcm(ll x,ll y){return x*y/gcd(x,y);} ll factrial(int x){return x<=1?1:x*factrial(x-1);} ll nPr(ll n,ll r){ll a=1;rep(i,n-r)a*=(n-i);return a;} ll nCr(ll n,ll r){ll a=1;rep(i,r){a*=(n-i);a/=(i+1);}return a;} vP factor(ll n){vP r;if(n<=1)return{};ll m=pow(n,0.5)+1;reps(i,2,m){if(n%i==0){ll c=0; while(n%i==0){c++;n/=i;}r.PB({i,c});}if(n<=1)break;}if(n>1)r.PB({n,1});return r;} int main(){ string s; cin >> s; string o; rep(i,s.length()){ if(s[i]=='6') s[i] = '9'; else if(s[i]=='9') s[i] = '6'; } repr(i,s.length()){ cout << s[i]; } cout << endl; }
#include<bits/stdc++.h> using namespace std; typedef long long LL; const int mod = 998244353; const int N = 3000 + 10; LL dp[N][N]; LL f(LL n, LL k) { if(n < k) return 0; if(n == k) return 1; if(!n) return 0; if(!k) return 0; if(dp[n][k] != -1) return dp[n][k]; return dp[n][k] = (f(n - 1, k - 1) + f(n, 2 * k)) % mod; } void solve() { memset(dp, -1, sizeof dp); LL n, k; scanf("%lld%lld", &n, &k); printf("%lld\n", f(n, k)); } int main() { // freopen("in.txt", "r", stdin); solve(); return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; const ll INF=0x3f3f3f3f3f3f3f3f; const int maxn=3e3+5,mod=998244353; int n,k; ll dp[maxn][maxn]; int main(){ scanf("%d%d",&n,&k); dp[0][0]=1; // dp[i][j] for(int i=1;i<=n;i++){ for(int j=i;j>=1;j--){ dp[i][j]=(dp[i-1][j-1]+(2*j<=i?dp[i][2*j]:0))%mod; // cout<<i<<" "<<j<<" "<<dp[i][j]<<endl; } } // for(int i=1;i<=k;i++){ // for(int j=n;j>=1;j--){ // dp[i][j]=(dp[i-1][j-1]+dp[i][2*j])%mod; // cout<<i<<" "<<j<<" "<<dp[i][j]<<endl; // } // } printf("%lld\n",dp[n][k]); return 0; }
#include<bits/stdc++.h> using namespace std; #define MAXN 100005 #define lowbit(x) (x&-x) #define reg register #define mkpr make_pair #define fir first #define sec second typedef long long LL; typedef unsigned long long uLL; const int INF=0x3f3f3f3f; const int mo=998244353; const LL jzm=2333; const int iv2=499122177; const double Pi=acos(-1.0); typedef pair<int,int> pii; const double PI=acos(-1.0); template<typename _T> _T Fabs(_T x){return x<0?-x:x;} template<typename _T> void read(_T &x){ _T f=1;x=0;char s=getchar(); while(s>'9'||s<'0'){if(s=='-')f=-1;s=getchar();} while('0'<=s&&s<='9'){x=(x<<3)+(x<<1)+(s^48);s=getchar();} x*=f; } template<typename _T> void print(_T x){if(x<0){x=(~x)+1;putchar('-');}if(x>9)print(x/10);putchar(x%10+'0');} int k,cnt1[15],cnt2[15],pow10[10]={1,10,100,1000,10000,100000}; char str1[15],str2[15];LL sum1,sum2; void sakura(LL num){ int tmp1=0,tmp2=0; for(int i=1;i<=9;i++)tmp1+=i*pow10[cnt1[i]],tmp2+=i*pow10[cnt2[i]]; sum1+=num;if(tmp1>tmp2)sum2+=num;return ; } signed main(){ read(k);scanf("\n%s\n%s",str1+1,str2+1); if(k==1){puts("0");return 0;} for(int i=1;i<5;i++)cnt1[str1[i]-'0']++,cnt2[str2[i]-'0']++; for(int i=1;i<10;i++) for(int j=1;j<10;j++){ LL tmp=k-cnt1[i]-cnt2[i];cnt1[i]++; tmp*=1ll*(k-cnt1[j]-cnt2[j]);cnt2[j]++; //printf("%d %d:%d\n",i,j,tmp); if(cnt1[i]<=k&&cnt2[j]<=k)sakura(tmp); cnt1[i]--;cnt2[j]--; } printf("%.5f\n",1.0*sum2/sum1); return 0; }
#include <bits/stdc++.h> using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define FORR2(x,y,arr) for(auto& [x,y]:arr) #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) //------------------------------------------------------- int T,N; string S,A="atcoder"; void solve() { int i,j,k,l,r,x,y; string s; A+='a'-1; cin>>T; while(T--) { cin>>S; int ret=1010101; FOR(i,8) { string T=S; int sum=0; x=0; for(j=0;j<T.size();j++) { if(x<i) { if(T[j]==A[x]) { sum+=j-x; rotate(T.begin()+x,T.begin()+j,T.begin()+j+1); x++; } } else if(i==x) { if(T[j]>A[x]) { sum+=j-x; rotate(T.begin()+x,T.begin()+j,T.begin()+j+1); x=100; break; } } } if(x==100) ret=min(ret,sum); } if(ret==1010101) ret=-1; cout<<ret<<endl; } } int main(int argc,char** argv){ string s;int i; if(argc==1) ios::sync_with_stdio(false), cin.tie(0); FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin); cout.tie(0); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") typedef long long int ll; typedef long double ld; #define MOD 1000000007 #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL) #define endl '\n' #define pb push_back #define conts continue #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(), a.rend() #define no cout << "NO" << endl #define yes cout << "YES" << endl #define ff first #define ss second #define ceil2(x,y) (x+y-1) / y #ifndef ONLINE_JUDGE #define debug(x) cout << #x <<" = "; print(x); cout << endl; #else #define debug(x) #endif bool iseven(ll n) {if ((n & 1) == 0) return true; return false;} void print(ll t) {cout << t;} void print(int t) {cout << t;} void print(string t) {cout << t;} void print(char t) {cout << t;} void print(double t) {cout << t;} void print(ld t) {cout << t;} template <class T, class V> void print(pair <T, V> p); template <class T> void print(vector <T> v); template <class T> void print(set <T> v); template <class T, class V> void print(map <T, V> v); template <class T> void print(multiset <T> v); template <class T, class V> void print(pair <T, V> p) {cout << "{"; print(p.ff); cout << ","; print(p.ss); cout << "}";} template <class T> void print(vector <T> v) {cout << "[ "; for (T i : v) {print(i); cout << " ";} cout << "]";} template <class T> void print(set <T> v) {cout << "[ "; for (T i : v) {print(i); cout << " ";} cout << "]";} template <class T> void print(multiset <T> v) {cout << "[ "; for (T i : v) {print(i); cout << " ";} cout << "]";} template <class T, class V> void print(map <T, V> v) {cout << "[ "; for (auto i : v) {print(i); cout << " ";} cout << "]";} void solve() { ll n; cin >> n; ll ans = floor(1.08*n); if(ans < 206){ cout << "Yay!" << endl; } else if(ans == 206){ cout << "so-so" << endl; } else{ cout << ":(" << endl; } } signed main() { #ifndef ONLINE_JUDGE freopen("D:/Competitive Programming/input.txt", "r", stdin); freopen("D:/Competitive Programming/output.txt", "w", stdout); #endif fastio; solve(); return 0; }
#include <algorithm> #include <iostream> #include <list> #include <numeric> #include <random> #include <vector> #include <map> #include <set> #include <iterator> #include <ostream> #include <sstream> #include <iomanip> #include <stdio.h> #include <queue> #include <cstdio> using namespace std; #define rep(i, n) for(int i = 0; i < n; ++i) typedef long long ll; template<class T> string toString(T n){ostringstream ost;ost<<n;ost.flush();return ost.str();} int toInt(string s){int r=0;istringstream sin(s);sin>>r;return r;} long long toInt64(string s){long long r=0;istringstream sin(s);sin>>r;return r;} string res; string s; int main() { ios::sync_with_stdio(); cin.tie(0); cin>>s; string res; res = ""; for(int i = 0; i < (int)s.size(); ++i){ if(s[i] == '.'){cout<<res<<endl; return 0;} res += s[i]; } cout<<res<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; using ll = long long; #define rep(i,f,n) for(ll i=(f); (i) < (n); i++) #define repe(i,f,n) for(ll i=(f); (i) <= (n); i++) #define repc(i,f,n) for(char i=(f); (i) <= (n); i++) //#define PI 3.14159265358979323846264338327950L #define debug(x) cout<<#x<<" :: "<<x<<"\n"; #define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n"; #define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n"; #define Pl pair<ll, ll> #define OUT(x) cout << x << endl; return 0; #define ALL(x) (x).begin(),(x).end() #define UNIQUE(x) (x).erase(unique(all(x)),(x).end()) //printf("%.10f\n") //cout << fixed << setprecision(10); template<class T> inline bool chmax(T& a, T b){if (a < b) { a = b; return true; } return false;} template<class T> inline bool chmaxe(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;} const ll MOD = 1000000007ll; const ll INF = 1e+18; const int iINF = 1e9; const double EPS = 1e-8; //const double PI = acos(-1.0); struct sh { ll D; ll C; ll S; }; int main() { ll N; cin >> N; N *= 1.08; if(N ==206)cout << "so-so" << endl; else if(N > 206) cout << ":(" << endl; else cout << "Yay!" << endl; }
#include <bits/stdc++.h> using namespace std; #define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define MOD 1000000007 #define MOD1 998244353 #define INF 1e18 #define nline "\n" #define pb push_back #define ppb pop_back #define mp make_pair #define ff first #define ss second #define PI 3.141592653589793238462 #define set_bits __builtin_popcountll #define sz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() const int maxn=2e5+10; typedef long long ll; typedef unsigned long long ull; typedef long double lld; ll gcd(ll a, ll b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);} ll expo(ll a, ll b, ll mod) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;} ll mminvprime(ll a, ll b) {return expo(a, b - 2, b);} bool revsort(ll a, ll b) {return a > b;} void swap(int &x, int &y) {int temp = x; x = y; y = temp;} ll combination(ll n, ll r, ll m, ll *fact, ll *ifact) {ll val1 = fact[n]; ll val2 = ifact[n - r]; ll val3 = ifact[r]; return (((val1 * val2) % m) * val3) % m;} void google(int t) {cout << "Case #" << t << ": ";} vector<ll> sieve(int n) {int*arr = new int[n + 1](); vector<ll> vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;} ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;} ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} ll mod_div(ll a, ll b, ll m) {a = a % m; b = b % m; return (mod_mul(a, mminvprime(b, m), m) + m) % m;} //only for prime m ll phin(ll n) {ll number = n; if (n % 2 == 0) {number /= 2; while (n % 2 == 0) n /= 2;} for (ll i = 3; i <= sqrt(n); i += 2) {if (n % i == 0) {while (n % i == 0)n /= i; number = (number / i * (i - 1));}} if (n > 1)number = (number / n * (n - 1)) ; return number;} bool isPrime(ll n) { if (n <= 1) return false; if (n <= 3) return true; if (n%2 == 0 || n%3 == 0) return false; for (ll i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0) return false; return true; } ll nextPrime(ll N) { if (N <= 1) return 2; ll prime = N; bool found = false; while (!found) { prime++; if (isPrime(prime)) found = true; } return prime; } bool palin(string s,ll i,ll j){ if(i>j) return false; while(i<j){ if(s[i]!=s[j]) return false; i++; j--; } return true; } bool isperfect(lld x){ if(x>=0){ ll s=sqrt(x); return (s*s==x); } return false; } string correct(string s,ll k){ string res; ll n=s.size(); for(ll i=0;i<k;i++){ res+=s[i%n]; } return res; } int main() { #ifndef ONLINE_JUDGE // for getting input from input.txt freopen("input1.txt", "r", stdin); // for writing output to output.txt freopen("output1.txt", "w" , stdout); #endif fastio(); ll n; cin>>n; ll r=n*1.08; if(r==206) cout<<"so-so"<<'\n'; else if(r<206) cout<<"Yay!"<<'\n'; else cout<<":("<<'\n'; return 0; }
#include<iostream> #include<vector> using namespace std; int main() { int m, n; char a; cin >> m; cin >> n; for (int i = 0; i < m; i++) { cin >> a; if (a == 'o') { n++; } else { n--; if (n < 0)n++; } } cout << n << endl; return 0; }
#include <bits/stdc++.h> using ll = long long; #define rep(i, n) for (int i = 0; i < n; ++i) using namespace std; int main() { ll x,n; cin>>n>>x; string mozi; cin >> mozi; rep(i,n){ if (mozi.compare(i,1, "x") == 0) { if (x > 0) { x--; } } else{ x++; } } cout<<x; return 0; }
#include<bits/stdc++.h> #define ll long long #define f(i,a,b) for(int i=a;i<=b;++i) using namespace std; ll a,b,kq; int main() { ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); cin>>a>>b; f(i,1,a){ f(j,1,b){ kq+=i*100+j; } } cout<<kq; }
#include <bits/stdc++.h> //#include <boost/multiprecision/cpp_int.hpp> //namespace mp = boost::multiprecision; //#include "atcoder/all" using namespace std; const double PI = 3.14159265358979323846; typedef long long ll; const double EPS = 1e-9; #define rep(i, n) for (int i = 0; i < (n); ++i) typedef pair<ll, ll> P; const ll INF = 10e17; #define cmin(x, y) x = min(x, y) #define cmax(x, y) x = max(x, y) #define ret() return 0; double equal(double a, double b) { return fabs(a - b) < DBL_EPSILON; } std::istream &operator>>(std::istream &in, set<int> &o) { int a; in >> a; o.insert(a); return in; } std::istream &operator>>(std::istream &in, queue<int> &o) { ll a; in >> a; o.push(a); return in; } bool contain(set<int> &s, int a) { return s.find(a) != s.end(); } typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK; int main() { int n; cin >> n; vector<ll> v(n); rep(i, n) cin >> v[i]; ll g = v[0]; for(ll l : v) g = __gcd(g, l); cout << g << endl; }
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; typedef long long ll; const int inf=0x3f3f3f3f; const int N=2e3+5; const int mod=1e9+7; ll read() { ll c=getchar(),Nig=1,x=0; while(!isdigit(c)&&c!='-')c=getchar(); if(c=='-')Nig=-1,c=getchar(); while(isdigit(c))x=((x<<1)+(x<<3))+(c^'0'),c=getchar(); return Nig*x; } ll gcd(ll a,ll b)//最大公约数 { return b==0?a:gcd(b,a%b); } ll lcm(ll a,ll b)//最小公倍数 { return a*b/gcd(a,b); } ll quick_pow(ll x, ll n)//快速幂 { ll ans=x,dayult=1; dayult%=mod; while(n) { if(n&1) { dayult=dayult*ans%mod; n--; } ans=ans*ans%mod; n>>=1; } return dayult; } ll extra_gcd(ll a,ll b,ll &x,ll &y)//扩展欧几里得(递归)-求逆元 { if(!b) { x=1; y=0; return a; } ll exgcd=extra_gcd(b,a%b,y,x); y-=a/b*x; return exgcd; } ll n,m,c; bool f[N][N]; ll dp[N][N]; ll x; ll y[N]; ll z[N]; ll g[N]; int main() { n=read(); m=read(); for(ll i=1;i<=n;i++) { string sz; cin>>sz; for(ll j=0;j<m;j++) if(sz[j]=='.') { f[i][j+1]=1; } } dp[1][1]=1; for(ll i=1;i<=n;i++) { x=0; for(ll j=1;j<=m;j++) { z[j]=g[j]; } for(ll j=1;j<=m;j++) { if(i==1&&i==j) { x=1; y[1]=1; g[2]=1; continue; } if(f[i][j]) { dp[i][j]=(y[j]+x+z[j])%mod; g[j+1]=(z[j]+dp[i][j])%mod; y[j]=(y[j]+dp[i][j])%mod; x=(x+dp[i][j])%mod; } else { dp[i][j]=0; x=y[j]=g[j+1]=0; } } } printf("%lld\n",dp[n][m]); return 0; }
#include <bits/stdc++.h> using namespace std; #define X ios_base::sync_with_stdio(false); cin.tie(NULL); #define FIXED_FLOAT(x) std::fixed <<std::setprecision(2)<<(x) void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif // long long p = 1e9+7; typedef long long ll; typedef pair<ll,ll> pl; typedef vector<int> VI; typedef vector<pair<ll,ll>> VP; typedef vector<ll> VL; typedef vector<VL> VVL; typedef vector<bool> VB; // typedef pair<ll, ll> PL; typedef unordered_map<ll, ll> UMP; #define FOR(i,b,init) for(i=init;i<b;i++) #define IFOR(i,b,init) for(i=b;i>=init;i--) #define pb push_back #define fi first #define se second #define mp make_pair // typedef unordered_set<ll>; /////GLOABLS VARS ll MOD = 1e9+7; ll MOD1 = 998244353; ll gmx = 1e6+7; VL fact(gmx, 1); //////FUNCTIONS ll powp(ll val, ll deg) { // debug(val, deg); if (!deg) return 1; if (deg & 1) return (powp(val, deg - 1) * val) % MOD; ll res = powp(val, deg >> 1); // debug(res); return (res * res) % MOD; } ll mx=1e5+7; vector<VL> adj; // vector<set<ll>> al(mx); VL vis; // ll c=1; // set<ll> dfs(ll r){ // if(adj[r].size()==0){al[r].insert(r);} // for(auto nb: adj[r]){ // set<ll> leaves = dfs(nb); // for(auto leaf: leaves){ // al[r].insert(leaf); // } // } // return al[r]; // } bool dfs(ll r, ll parent){ // debug() // if(igno[r]==1){return;} // debug(r,parent); if(vis[r]==1){return true;} if(vis[r]==2){return false;} vis[r]=1; for(auto k: adj[r]){ if(dfs(k, r)){vis[r]=2;return true;} } vis[r]=2; return false; } //SPF // VL spf(mx,1); // FOR(i,mx,1){ // spf[i]=i; // } // // VL all_primes; // FOR(i,mx,2){ // if(spf[i]==i){ // // all_primes.pb(i); // for(j=i*i;j<mx;j+=i){ // spf[j]=min(i, spf[j]); // } // } // } //It is not easy but it can be fun, if you think!!! ll gcd(ll a, ll b){ // debug(a,b); if(a>b){swap(a,b);} if(a==0){return b;} return gcd(a, b%a); } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) // #endif // ll tc,ori; // cin>>tc; // while(tc--){ string s; // cin>>s; ll n,k,m,o,x,r,y,i,a,b,j; cin>>n>>m; cout<<n/m; // VL l(n); // } }
#include<bits/stdc++.h> using namespace std; template<typename T>inline T read(){ T f=0,x=0;char c=getchar(); while(!isdigit(c)) f=c=='-',c=getchar(); while(isdigit(c)) x=x*10+c-48,c=getchar(); return f?-x:x; } namespace run{ const int N=2e6+5,lim=309,mod=998244353,inv2=(mod+1)/2; inline int add(int x,int y){return x+y>=mod?x-mod+y:x+y;} inline int sub(int x,int y){return x>=y?x-y:x+mod-y;} inline int qpow(int x,int y){ int ret=1; while(y){ if(y&1) ret=1LL*x*ret%mod; x=1LL*x*x%mod,y>>=1; } return ret; } int C[lim][lim]; inline void pre(int K){ C[0][0]=1; for(int i=1;i<=K;i++){ C[i][0]=1; for(int j=1;j<=i;j++) C[i][j]=add(C[i-1][j],C[i-1][j-1]); } } int n,a[N],K,sum[lim],pw[lim],ex[lim]; int main(){ n=read<int>(),K=read<int>(),pre(K); for(int i=1;i<=n;i++) a[i]=read<int>(); for(int i=1;i<=n;i++){ pw[0]=1; for(int k=1;k<=K;k++) pw[k]=1LL*pw[k-1]*a[i]%mod; for(int k=0;k<=K;k++) sum[k]=add(sum[k],pw[k]); pw[0]=1; for(int k=1;k<=K;k++) pw[k]=1LL*pw[k-1]*2%mod*a[i]%mod; for(int k=0;k<=K;k++) ex[k]=add(ex[k],pw[k]); } for(int k=1;k<=K;k++){ int ans=0; for(int j=0;j<=k;j++) ans=(1LL*C[k][j]*sum[k-j]%mod*sum[j]+ans)%mod; ans=sub(ans,ex[k]),ans=1LL*ans*inv2%mod; printf("%d\n",ans); } return 0; } } int main(){ #ifdef my freopen(".in","r",stdin); freopen(".out","w",stdout); #endif return run::main(); }
#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<int MOD=1000000007> struct modint{ /*static modint inv[2005]; static void init(){ for(int i=0;i<2005;i++)inv[i]=modpow(modint(i),MOD-2); }*/ ull val; modint(ull x){ val=x%MOD; } modint(){} friend modint modpow(modint x,ull k){ modint ret(1ULL); while(k>0){ if(k&1ULL)ret*=x; x*=x; k>>=1; } return ret; } modint& operator +=(const modint& rhs){ this->val+=rhs.val; if(this->val>=MOD)this->val-=MOD; return *this; } friend modint operator+(modint lhs, const modint& rhs){ lhs+=rhs; return lhs; } modint& operator -=(const modint& rhs){ this->val+=MOD-rhs.val; if(this->val>=MOD)this->val-=MOD; return *this; } friend modint operator-(modint lhs, const modint& rhs){ lhs-=rhs; return lhs; } modint& operator *=(const modint& rhs){ this->val*=rhs.val; this->val%=MOD; return *this; } friend modint operator*(modint lhs, const modint& rhs){ lhs*=rhs; return lhs; } modint& operator /=(const modint& rhs){ (*this)*=modpow(rhs,MOD-2); //(*this)*=inv[rhs.val]; return *this; } friend modint operator/(modint lhs, const modint& rhs){ lhs/=rhs; return lhs; } }; //template<int MOD> //modint<MOD> modint<MOD>::inv[2005]; const int MOD=998244353; typedef modint<MOD> mi; int n,k; mi a[200010]; mi s[200010]; mi fac[302]; mi ret_[200010]; int main(){ scanf("%d%d",&n,&k); for(int i=0;i<n;i++){ int x; scanf("%d",&x); a[i]=x; } fac[0]=1; for(int i=1;i<=k;i++)fac[i]=fac[i-1]*i; for(int j=0;j<n;j++){ mi p=1,q=1; for(int i=0;i<=k;i++){ s[i]+=p; p*=a[j]; ret_[i]+=q; q*=2*a[j]; } } for(int i=0;i<=k;i++){ s[i]/=fac[i]; } for(int i=1;i<=k;i++){ mi ret=0; for(int j=0;j<=i;j++){ ret+=s[j]*s[i-j]; } ret*=fac[i]; ret-=ret_[i]; ret/=2; printf("%d\n",(int)(ret.val)); } }
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <cmath> using namespace std; int main(){ int a; int b; cin >> a >> b; int tmp = (2 * (a) + 100); cout << tmp - b << endl; return 0; }
#include <algorithm> #include <array> #include <cstdio> #include <iostream> #include <queue> #include <string> #include <vector> using namespace std; #define int long long #define ll long long #define INF 1LL << 33 #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define SHOW(p) \ if (test) \ cout << #p " : " << p << endl; bool test = true; //bool test = false; int B, C, n, ans; signed main() { cin >> B >> C; n = C / 2; if (C == 1) { if (B == 0) { ans = 1; } else { ans = 2; } } else if (C == 2) { if (B == 0) { ans = 2; } else { ans = 3; } } else if (B == 0) { if (C % 2 == 0) { ans = 2 * n; } else { ans = 2 * n + 1; } } else if (B > 0) { if (C % 2 == 0) { if (B - n > 0) { // |X| <= B ans = 2 * n + 1; } else { // |X| <= B ans = 2 * B + 1; } // |X| > B ans += 2 * n - 2; } else { if (B - n > 0) { // |X| <= B ans = 2 * n + 2; } else { // |X| <= B ans = 2 * B + 1; } // |X| > B ans += 2 * n - 1; } } else { if (C % 2 == 0) { // |X| <= B if (B + n >= 0) { ans = -2 * B + 1; } else { ans = 2 * n + 1; } // |X| > B ans += 2 * n - 1; } else { // |X| <= B if (B + n >= 0) { ans = -2 * B + 1; } else { ans = 2 * n; } ans += 2 * n; } } cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long int #define tc ll t;cin>>t;while(t--) #define PI 2*acos(0) #define mset(pq) memset(pq, 0, sizeof(pq)); ll M=1e9+7; int sum_digit(int x) { int sum=0; while(x>0){ sum+=x%10; x/=10; } return sum; } int reverse_num(int n){ int tmp=n, ans=0, r; while(tmp>0){ r=tmp%10; ans=ans*10+r; tmp/=10; } return ans; } ll factorial(ll n){ ll i, ans=1; for(i=n; i>1; i--){ans*=i;} return ans; } ll gcd(ll num1, ll num2) { ll a,b,r; a=num1; b=num2; r=a%b; while(r>0){ a=b; b=r; r=a%b; } return b; } ll lcm(ll num1, ll num2) { return (num1*num2)/gcd(num1, num2); } void solve() { int n, m, a, b, c, d, x, y, z, p; cin >> a >> b; x = sum_digit(a); y = sum_digit(b); cout << max(x, y); } int main() { //tc solve(); return 0; } /* */ // reverse(s.begin(), s.end()); // reversing a string // getline( cin, s); /* vector <int> arr; for(i=0; i<n; i++) arr.push_back(i); */
#include <bits/stdc++.h> #define rep(i,N) for(int i=0; i<(N); i++) using namespace std; int main() { int64_t N; cin >> N; vector<int64_t> a(0); for(int64_t i=1; i*i<=N; i++){ if(i*i == N){ a.push_back(i); continue; } if(N%i == 0){ a.push_back(i); a.push_back(N/i); } } sort(a.begin(),a.end()); int64_t n=a.size(); rep(i,n) cout << a[i] << endl; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; const ll MOD = 998244353; #define rep(i,a,b) for(ll i=a;i<b;++i) #define pii pair<ll,ll> ll ar[8]; ll pow(ll a,ll b) { return ar[b]; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); ar[0] = 1; rep(i,1,8) ar[i] = ar[i-1]*10; ll k; cin>>k; string s,t; cin>>s>>t; ll a[9]={0},b[9]={0},a1=0,b1=0; rep(i,0,s.size()-1) a[s[i]-'1']++; rep(i,0,t.size()-1) b[t[i]-'1']++; rep(i,0,9) a1+=(i+1)*(ll)pow(10,a[i]); rep(i,0,9) b1+=(i+1)*(ll)pow(10,b[i]); ll num=0,d=0; rep(i,0,9) { rep(j,0,9) { ll r1 = k-a[i]-b[i],r2 = k-b[j]-a[j]; if(!r1 || !r2) continue; (i!=j)?d+=(r1*r2):d+=((r1*(r1-1))); ll t1 = -1*(i+1)*(ll)pow(10,a[i]); t1 += (i+1)*(ll)pow(10,a[i]+1); ll t2 = -1*(j+1)*(ll)pow(10,b[j]); t2 += (j+1)*(ll)pow(10,b[j]+1); if(a1+t1>b1+t2) (i!=j)?num+=(r1*r2):num+=((r1*(r1-1))); } } printf("%0.12f\n",(double)num/d); }
#include <bits/stdc++.h> using namespace std; #define IOS ios::sync_with_stdio(false) #define rep(i, n) for(ll i=0; i<(ll)n; i++) #define ALL(obj) begin(obj), end(obj) typedef long long ll; vector<vector<int> > G(22); vector<int> color(22, -1), ts; vector<bool> vis(22, 0); int n, m, a, b; void dfs(int now){ ts.push_back(now); vis[now]=1; for(int i: G[now]){ if(vis[i]) continue; dfs(i); } } ll DFS(int i){ if(i==ts.size()) return 1; ll res=0; rep(j, 3){ bool f=1; for(int x:G[ts[i]]){ if(color[x]==j){ f=0; break; } } if(!f) continue; color[ts[i]]=j; res+=DFS(i+1); color[ts[i]]=-1; } return res; } int main() { IOS; cin>>n>>m; rep(i, m){ cin>>a>>b; a--; b--; G[a].push_back(b); G[b].push_back(a); } ll ans=1; rep(i, n){ if(vis[i]) continue; dfs(i); fill(ALL(color), -1); ans*=DFS(0); ts.clear(); } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); long long int i=1; long long int ans=0; bool flag=false; long long int N; cin >> N; while(flag==false){ string str1 = to_string(i); string str2 = to_string(i); string str = str1+str2; long long int num = (long long int)stol(str); if(num<=N){ ans++; i++; }else{ flag = true; } } cout << ans; }
#include<bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define ppb pop_back #define pf push_front #define ppf pop_front #define all(x) (x).begin(), (x).end() #define uniq(v) (v).erase(unique(all(v)), (v).end()) #define sz(x) (int)((x).size()) #define ff first #define ss second #define rep(i, a, b) for(int i = a; i <= b; i++) #define mem1(a) memset(a, -1, sizeof(a)) #define mem0(a) memset(a, 0, sizeof(a)) #define endl "\n" typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pii> vpii; const long long INF = 1e18; const int32_t M = 1e9 + 7; const int32_t MM = 998244353; int binpow(int a, int b) { int res = 1; while (b > 0) { if (b & 1) { res = a * res; } a = a * a; b >>= 1; } return res; } void fast_io() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } vi num; void precompute() { for (int i = 1; i <= 6; i++) { int low = binpow(10, i - 1); int high = binpow(10, i) - 1; for (int j = low; j <= high; j++) { int tmp = j * binpow(10, i) + j; num.pb(tmp); } } } void solve() { int n; cin >> n; auto it = upper_bound(all(num), n); int ind = it - num.begin(); cout << ind << endl; } signed main() { fast_io(); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t = 1; // cin >> t; precompute(); while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define tolowercase(s) transform(s.begin(),s.end(),s.begin(),::tolower); #define touppercase(s) transform(s.begin(),s.end(),s.begin(),::toupper); #define lsb(x) (x&(-x)) #define MOD 1000000007 #define ll long long typedef pair<ll, ll> ii; typedef vector<ll> vi; typedef vector<bool> vb; typedef vector<vi> vvi; typedef vector<ii> vii; typedef vector<vii> vvii; #define pq priority_queue #define ff first #define ss second #define pb push_back #define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl; #define file_read(x,y) freopen(x, "r", stdin); \ freopen(y, "w", stdout); int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll x,y; cin>>x>>y; if(min(x,y)+3>max(x,y)) cout<<"Yes\n"; else cout<<"No\n"; }
#include "bits/stdc++.h" using namespace std; int main(){ int A, B; cin>>A>>B; if(A<B&&A+3>B||B<A&&B+3>A) cout<<"Yes"<<endl; else cout<<"No"<<endl; }
#include<bits/stdc++.h> using namespace std; #define F first #define S second #define int long long #define pb push_back #define mp make_pair #define pii pair<int,int> #define vec vector<int> #define mii map<int,int> #define pqb priority_queue<int> #define no_of_test(zzz) int zzz; cin>>zzz; while(zzz--) #define p(c) cout<<c<<'\n'; #define f(i,a,b) for(int i=a;i<b;i++) const int mod = 1e9 + 7; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //no_of_test(zzz) { int x,y; cin>>x>>y; int k=abs(x-y); if(k<3) cout<<"Yes"<<'\n'; else { cout<<"No"<<'\n'; } } return 0; } //cout<<"###"<<'\n'; //cout<<"."<<'\n'; //cout<<"****"<<'\n'; /* NO YES NO YES NO YES */
#include<bits/stdc++.h> using namespace std; #pragma GCC optimize(2) typedef long long ll; const int N=1e6+5; const int inf=0x3f3f3f3f; ll gcd(ll a,ll b)//最大公约数 { return b==0?a:gcd(b,a%b); } ll lcm(ll a,ll b)//最小公倍数 { return a*b/gcd(a,b); } ll quick_pow(ll x, ll n)//快速幂 { ll num=x,ansult=1; while(n) { if(n%2) ansult*=num; num*=num; n/=2; } return ansult; } ll extra_gcd(ll a,ll b,ll &x,ll &y)//扩展欧几里得(递归)-求逆元 { if(!b) { x=1; y=0; return a; } ll exgcd=extra_gcd(b,a%b,y,x); y-=a/b*x; return exgcd; } int flag(int a) { ; } ll read() { ll c=getchar(),Nig=1,x=0; while(!isdigit(c)&&c!='-')c=getchar(); if(c=='-')Nig=-1,c=getchar(); while(isdigit(c))x=((x<<1)+(x<<3))+(c^'0'),c=getchar(); return Nig*x; } void out(int a) { if(a > 9) { out(a/10); } putchar(a%10 + '0'); } ll num[105],n; void visit() { for(int i=1;i<=n;i++) { cout<<num[i]<<" "; } cout<<endl; } void Del(int x) { for(ll i=x;i<n;i++) { num[i]=num[i+1]; } n--; } int main() { ll x,y; x=read(); y=read(); if(abs(x-y)<3) { printf("Yes\n"); } else { printf("No\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; #define vi vector<int> #define fo(a,b,c) for(int a=b;a<c;a++) #define int long long int #define ff first #define ss second #define pb push_back #define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); const int mod = 1e9 + 7; const int cmod = 998244353; const int N = 3e5 + 5; const int inf = 1e18 + 2; int power(int a,int b) { if(b==0) return 1; else if(b%2==0) { int c=power(a,b/2); return (c*c)%mod; } else return ((a%mod)*(power(a,b-1)%mod))%mod; } void solve(int Case) { vi v(3); fo(i,0,3) cin>>v[i]; sort(v.begin(),v.end()); if(v[1]-v[0]==v[2]-v[1]) { cout<<"Yes"; goto a; } sort(v.begin(),v.end(),greater<int>()); if(v[1]-v[0]==v[2]-v[1]) { cout<<"Yes"; goto a; } cout<<"No"; a:; } int32_t main() { fastio int testcase = 1; //cin >> testcase; int Case = 1; while(testcase --) { solve(Case); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main(){ int a, b, c; cin >> a >> b >> c; if(a > b) swap(a, b); if(a > c) swap(a, c); if(b > c) swap(b, c); if(b - a == c - b) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; for (auto it = s.rbegin(); it != s.rend(); ++it) { char c = *it; if (c == '6' || c == '9') { c ^= '6' ^ '9'; } cout << c; } cout << endl; }
#include<bits/stdc++.h> using namespace std; #define ll long long int #define ld long double #define mem(a,val) memset(a,(val),sizeof((a))) #define FAST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define decimal(n) cout << fixed ; cout << setprecision((n)); #define mp make_pair #define eb emplace_back #define f first #define s second #define all(v) v.begin(), v.end() #define endl "\n" #define lcm(m,n) (m)*((n)/__gcd((m),(n))) #define rep(i,n) for(ll (i)=0;(i)<(n);(i)++) #define rep1(i,n) for(ll (i)=1;(i)<(n);(i)++) #define repa(i,n,a) for(ll (i)=(a);(i)<(n);(i)++) #define repr(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--) #define pll pair<ll,ll> #define pii pair<int, int> #define mll map<ll,ll> #define vll vector<ll> #define sz(x) (ll)x.size() #define ub upper_bound #define lb lower_bound #define pcnt(x) __builtin_popcountll(x) const long long N=10; const long long NN=1e18; const int32_t M=1e9+7; const int32_t MM=998244353; template<typename T,typename T1>T maxn(T &a,T1 b){if(b>a)a=b;return a;} template<typename T,typename T1>T minn(T &a,T1 b){if(b<a)a=b;return a;} inline long long int mul(long long int a,long long int b){return (a*1LL*b)%M;} inline long long int add(long long int a,long long int b){return (a+b)%M;} inline long long int sub(long long int a,long long int b){return ((a%M-b%M)+M)%M;} inline ll mod(long long int x,long long int p = M) {return (x < 0?(x%p)+p:x%p);} long long int power(long long int b,long long int e,long long int m) { if(e==0LL) return 1LL; if(e&1LL) return ((b%m)*(power((b*b)%m,e/2,m)))%m; return power((b*b)%m,e/2,m); } long long int modInverse(long long int A,long long int m) { return power(A,m-2,m); } long long int fac[N+1],invfac[N+1]; void init() { fac[0]=1; invfac[0]=1; for(long long int i=1;i<N+1;i++) { fac[i]=mul(fac[i-1],i); } for(long long int i=1;i<N+1;i++)invfac[i]=mul(invfac[i-1],modInverse(i,M)); } long long int nCr(long long int n, long long int r) { if(n<r)return 0LL; if (r==0)return 1LL; return mul(mul(fac[n],invfac[r]),invfac[n-r]); } void solve() { //code begins from here// init(); string s; cin>>s; ll o=0,x=0,q=0; rep(i,sz(s)) { if(s[i]=='x')x++; else if(s[i]=='o')o++; else q++; } ll ans=0; if(o==4) { ans=fac[4]; } else if(o==3) { ans=q*fac[4]+3*(24/2); } else if(o==2) { ans=((q*(q-1))/2)*24+q*3*(12)+2*(4)+(6); } else if(o==1) { ans=1+q*(2*(fac[4]/fac[3])+(fac[4]/4))+nCr(q,2)*3*(fac[4]/fac[2])+nCr(q,3)*fac[4]; } else if(o==0) { if(q)ans=pow(q,4); } cout<<ans; } signed main() { FAST //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); int testcase=1; //cin>>testcase; while(testcase--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long LL; #define IOS ios::sync_with_stdio(false); cin.tie(0);cout.tie(0) const int P = 1e9 + 7; const double PI = acos(-1.0); const int INF = 0x3f3f3f3f; const int N = 3e6 + 10; int main() { IOS; int n; string str; vector<int> v; cin >> str >> n; for(auto x : str) if(x >= '0' && x <= '9') v.push_back((int)(x - '0')); else v.push_back((int)(10 + x - 'A')); vector<vector<int> > f(str.size() + 1, vector<int>(18, 0)); int state = 0; for(int i = 0; i < (int)str.size(); ++ i) { for(int j = 1; j <= 16; ++ j) { f[i + 1][j] = (f[i + 1][j] + (LL)f[i][j] * j % P) % P; f[i + 1][j + 1] = (f[i + 1][j + 1] + (LL)f[i][j] * (16 - j) % P) % P; } f[i + 1][1] = (f[i + 1][1] + (LL)f[i][0] * 15 % P) % P; f[i + 1][0] = (f[i + 1][0] + f[i][0]) % P; for(int j = 0; j < v[i]; ++ j) { int nstate = state; if(i || j) nstate |= (1 << j); f[i + 1][__builtin_popcount(nstate)] += 1; } state |= (1 << v[i]); } int res = f[str.size()][n] + (__builtin_popcount(state) == n); cout << res << endl; return 0; }
#include <cstdio> #include <iostream> using namespace std; typedef long long LL; const int mod = 1e9 + 7; const int L = 2e5 + 100; const int K = 16 + 4; char lmt[L]; int lp; long long f[L][K]; bool has[L]; int cnt; int n, k; int main() { char in = getchar(); while((in < '0' || in > '9') && (in < 'A' || in > 'F')) in = getchar(); while((in >= '0' && in <= '9') || (in >= 'A' && in <= 'F')) { lmt[++lp] = (in < 'A') ? (in - '0') : (in - 'A' + 10); in = getchar(); } scanf("%d", &k); f[1][1] = max(0, lmt[1] - 1); for(int i = 2; i <= lp; ++i) f[i][1] = 15; for(int i = 1; i <= lp; ++i) { if(!has[lmt[i]]) ++cnt; has[lmt[i]] = true; for(int j = 01; j <= 16; ++j) { f[i + 1][j] += f[i][j] * j; f[i + 1][j] %= mod; f[i + 1][j + 1] += f[i][j] * (16 - j); f[i + 1][j + 1] %= mod; } for(int k = 0; k < lmt[i + 1]; ++k) { f[i + 1][cnt] += has[k]; f[i + 1][cnt] %= mod; f[i + 1][cnt + 1] += !has[k]; f[i + 1][cnt + 1] %= mod; } } cout << (f[lp][k] + (cnt == k)) % mod; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int x, cnt = 0; bool flag = false; for (int i = 1; i <= n; i++) { flag = false; x = i; while (x) { if (x % 10 == 7) { flag = true; break; } else { x /= 10; } } if (flag) continue; x = i; while (x) { if (x % 8 == 7) { flag = true; break; } else { x /= 8; } } if (flag) continue; cnt++; } cout << cnt << endl; }
#include <iostream> using namespace std; int h8(int x){ int x0,x1,x2,x3,x4,x5; x5=x/32768; x4=(x-x5*32768)/4096; x3=(x-x5*32768-x4*4096)/512; x2=(x-x5*32768-x4*4096-x3*512)/64; x1=(x-x5*32768-x4*4096-x3*512-x2*64)/8; x0=x-x5*32768-x4*4096-x3*512-x2*64-x1*8; return x0+x1*10+x2*100+x3*1000+x4*10000+x5*100000; } bool h(int x){ string str=to_string(x); for(int i=0;i<str.length();i++){ if(str[i]=='7') return true; } return false; } int main(){ int n,cnt=0; cin>>n; for(int i=1;i<=n;i++){ if(h(i)==false&&h(h8(i))==false) cnt++; } cout<<cnt<<endl; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(0); int N,S,D; cin >> N >> S >> D; rep(i,N){ int X,Y; cin >> X >> Y; if(X < S && Y > D){ cout << "Yes" << endl; return 0; } } cout << "No" << endl; }
#include<bits/stdc++.h> using namespace std; #define fr(i,t) for(i=0;i<t;i++) #define fr1(i,r,t) for(i=r;i<t;i++) typedef long long int lli; typedef unsigned long long int ulli; #define inf LONG_MAX #define ff first #define ss second double pie=3.14159265358979323846; #define dbug(x) cout<<#x<<"="<<x<<endl #define dbug2(x,y) lli M=1e9+7; // lli M=998244353; #define gg cout<<"Case #"<<i+1<<": " #define exact(x) cout<<fixed<<setprecision(8)<<x<<endl #define ceil(x,y) (x+y-1)/y #define all(x) (x).begin(),(x).end() int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); lli T,n,i,j,k=0,m,j1,co=0,check,mi,l,sum; lli ans=0; // cin>>T; // fr(i,T) // { lli x,y; cin>>n>>x>>y; lli a[n],b[n]; fr(j,n) cin>>a[j]>>b[j]; co=0; fr(j,n) { if(a[j]<x&&b[j]>y) co=1; } if(co==0) cout<<"No"<<endl; else cout<<"Yes"<<endl; // } }
#include <bits/stdc++.h> using namespace std; const int N = 2005; int n, m, fa[N], ans1, ans2, siz[N]; char a[N][N]; int find_(int x) { return x == fa[x] ? x : fa[x] = find_(fa[x]); } int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n + m; i++) fa[i] = i, siz[i] = 1; for (int i = 1; i <= n; i++) scanf("%s", a[i] + 1); a[1][1] = a[n][1] = a[1][m] = a[n][m] = '#'; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) if (a[i][j] == '#') { int x = find_(i), y = find_(j + n); if (x^y) fa[x] = y, siz[y] += siz[x]; } for (int i = 1; i <= n + m; i++) if (find_(i) == i) ans1 += (i <= n)|(siz[i] >= 2), ans2 += (i > n)|(siz[i] >= 2); printf("%d\n", min(ans1, ans2) - 1); }
#include <bits/stdc++.h> #define _overload3(_1,_2,_3,name,...)name #define _rep(i,n)repi(i,0,n) #define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i) #define MSVC_UNKO(x)x #define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__)) #define all(c)c.begin(),c.end() #define write(x)cout<<(x)<<'\n' using namespace std; using ll = long long; template<class T>using vv = vector<vector<T>>; template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); } constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60; struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa; int main() { int N, M; cin >> N >> M; vector<int> X(M), Y(M), Z(M); rep(i, M) cin >> X[i] >> Y[i] >> Z[i]; vv<int> cond(N); rep(i, M) { cond[X[i] - 1].push_back(i); } vector<int> xsort(M); iota(xsort.begin(), xsort.end(), 0); sort(xsort.begin(), xsort.end(), [&](int l, int r) { return X[l] < X[r]; }); vv<ll> dp = vvec(N + 1, 1 << N, 0LL); dp[0][0] = 1; rep(i, N) { rep(bit, 1 << N) { rep(j, N) { if (bit >> j & 1) continue; int nbit = bit | 1 << j; bool ok = true; for (int ci : cond[i]) { int y = nbit & ((1 << Y[ci]) - 1); int z = __builtin_popcount(y); if (z > Z[ci]) { ok = false; break; } } if (ok) { dp[i + 1][nbit] += dp[i][bit]; } } } } write(dp[N][(1 << N) - 1]); }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; ll gcd(ll a, ll b){return b? gcd(b, a % b): a;} ll quickpow(ll a, ll b){ll res = 1; while(b){if (b & 1) res = res * a; a = a * a; b >>= 1;} return res;} // head const int N = 2e5 + 5, mod = 998244353; int n, m; int dp[20][N], c[N][20]; int main(void){ ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m; c[0][0] = 1; for (int i = 1; i <= n; i++) { c[i][0] = 1; for (int j = 1; j <= 20; j++) { c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod; } } for (int i = 1; i <= m; i++) dp[1][i] = 1; for (int i = 1; i <= 18; i++) { for (int j = 1; j <= m; j++) { for (int k = j + j; k <= m; k += j) { dp[i + 1][k] += dp[i][j]; dp[i + 1][k] %= mod; } } } int ans = 0; for (int i = 1; i <= 19; i++) { int cnt = 0; for (int j = 1; j <= m; j++) { cnt += dp[i][j]; cnt %= mod; } ans += 1ll * cnt * c[n - 1][i - 1] % mod; ans %= mod; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define endl '\n' #define sz(v) (int)v.size() #define all(v) v.begin(), v.end() void dbg_out() { cerr << "\b\b]\n"; } template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T){ cerr << H << ", "; dbg_out(T...);} #define watch(...) cerr << "[" << #__VA_ARGS__ << "]: [", dbg_out(__VA_ARGS__) const int N = 4e5 + 5; const int mod = 998244353; vector <ll> fac(N+2), reFac(N+2); ll power(ll a, ll b){ ll res = 1; while(b){ if(b & 1){ (res *= a) %= mod; } (a *= a) %= mod; b >>= 1; } return res; } void calc() { fac[0] = 1; for (int i = 1; i <= N; ++i) fac[i] = (fac[i-1] * i) % mod; reFac[N] = power(fac[N], mod-2); for (int i = N; i > 0; --i){ reFac[i-1] = (reFac[i] * i) % mod; } } ll modMul(ll a, ll b) { if (a >= mod) a %= mod; if (b >= mod) b %= mod; return (a * b) % mod; } ll nCr(ll a, ll b) { //nCr => C(n, r) if (a < 0 or b < 0 or a < b) return 0LL; return modMul(fac[a], modMul(reFac[b], reFac[a - b])); } vector <int> factor(N); //factor[i] => smallest prime factor of i void linear_seive() { vector <int> primes; for (int i = 2; i < N; ++i) { if (factor[i] == 0) { factor[i] = i; primes.push_back(i); } for (int j = 0; j < sz(primes) and primes[j] <= factor[i] and primes[j] * i < N; ++j) { factor[i * primes[j]] = primes[j]; } } } map <int, int> factorize(int n) { map <int, int> cnts; while (n > 1) { cnts[factor[n]]++; n /= factor[n]; } return cnts; }; int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); calc(); linear_seive(); int n, m; cin >> n >> m; ll ans = 0; for (int i = 1; i <= m; ++i) { map <int, int> cnts = factorize(i); ll tot = 1; for (auto j: cnts) { tot *= nCr(j.second + n - 1, n-1); tot %= mod; } ans += tot; ans %= mod; } cout << ans; return 0; } /* * Put the values of A[n-1] => {1...m}, for each value of A[n-1], calculate the number of sequences. * How to calculate them? * Use Binomial Coeff / Stars and Bars. * Since we have fixed the A[n-1] element, we have remained n-1 elements. * A[n-1] as: for each 'i', 1 <= i <= m, calculate the prime factorization of 'i' suppose: p^a * q^b. then, using stars and bars: nCr(a+n-1, n-1) * nCr(b+n-1, n-1). So answer is: 1 <= i <= m, summation(nCr(cnts(p) + n-1, n-1)), p => prime factor of 'i', cnts(p) => occurence of 'p' in 'i' */
#include<iostream> using namespace std; int main(){ int n,a,b; cin>>n>>a>>b; cout<<n-a+b<<endl; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--) #define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++) #define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--) #define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++) #define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++) #define ALL(x) x.begin(), x.end() using ll = long long; using namespace std; int main(){ int n, a, b; cin >> n >> a >> b; n -= a; n += b; cout << n << endl; return 0; }
#include <cstdio> #include <cstring> #include <cmath> #include <utility> #include <iostream> #include <functional> #include <bitset> #include <algorithm> #include <vector> #include <forward_list> #include <set> #include <map> #include <queue> #include <deque> #include <stack> #include <tuple> #include <numeric> #include <cassert> using namespace std; using ll = long long; using P = pair<ll, ll>; const ll MOD = 1e9 + 7; const ll INF = (1ll << 60); template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } ll n; void dfs(vector<bool> used, map<char, int> m, ll d) { if (d == n) { return; } for (int i = 0; i < 10; i++) { } } int main(void) { vector<string> s(3); cin >> s[0] >> s[1] >> s[2]; set<char> se; map<char, int> m; for (int i = 0; i < 3; i++) { for (int j = 0; j < s[i].size(); j++) { se.insert(s[i][j]); m[s[i][j]] = -1; } } n = se.size(); if (n > 10) { cout << "UNSOLVABLE" << endl; return 0; } vector<ll> v(10); for (int i = 0; i < 10; i++) { v[i] = i; } do { ll k = 0; for (auto &&i : m) { i.second = v[k]; k++; } // for (auto &&i : m) // { // cout << i.first << " " << i.second << endl; // } vector<ll> x(3, 0); bool flag = true; for (int i = 0; i < 3; i++) { ll ten = 1ll; for (int j = s[i].size() - 1; j >= 0; j--) { if (j == 0) { if (m[s[i][j]] == 0) { flag = false; break; } } x[i] += ten * m[s[i][j]]; ten *= 10ll; } } if (x[0] + x[1] != x[2]) { flag = false; } if (flag) { for (int i = 0; i < 3; i++) { cout << x[i] << endl; } return 0; } } while (next_permutation(v.begin(), v.end())); cout << "UNSOLVABLE" << endl; }
#include <bits/stdc++.h> using namespace std; int A,B,W; int main(){ cin>>A>>B>>W; int m=1e9,M=0; for(int n=1;n<=1000000;n++){ if(A*n<=1000*W && 1000*W<=B*n){ m=min(m,n); M=max(M,n); } } if(M==0) cout<<"UNSATISFIABLE"; else cout<<m<<" "<<M; }
#include <bits/stdc++.h> #ifdef LILY #include "Debug.h" #else #define var(...) (0) #define dbg(...) (0) #endif using int32 = int; using int64 = long long; using namespace std; class Solution { #define int int32 #define sfor(i, n) for (int i = 1; i <= (n); ++i) #define tfor(i, n) for (int i = 0; i < (n); ++i) #define INF 0x3f3f3f3f #define EPS 1e-5 double a, b; int res = 1; void reals() { int dist = b - a; for (res = dist; res > 1; res--) { double left = a / res, right = b / res; if ([&]() { int cnt = 0; for (int j = ceil(left); j <= right; j++) if (++cnt == 2) return true; return false; }()) { return; } } } public: Solution() { cin >> a >> b; reals(); cout << res << endl; } #undef int #undef tfor #undef sfor }; int32 main() { #ifdef LILY while (1) #endif Solution(); return 0; }
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (a % b == 0) { return b; } else { return gcd(b, a % b); } } int main(void) { int A, B, ans = 1; cin >> A >> B; for (int i = 1; i <= B; i++) { if (floor(B / i) - floor((A - 1) / i) >= 2) { ans = i; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; const ll MOD = 998244353; const ll INF = 1e18; #define rep(i,m,n) for(ll i = (m); i <= (n); i++) #define zep(i,m,n) for(ll i = (m); i < (n); i++) #define rrep(i,m,n) for(ll i = (m); i >= (n); i--) #define print(x) cout << (x) << endl; #define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl; ll n, w[101], ex[101], sm, dp[2][100 * 101][101]; int main(){ cin.tie(0); ios::sync_with_stdio(false); cin >> n; zep(i, 0, n)cin >> w[i]; ex[0] = 1; rep(i, 1, n)ex[i] = i * ex[i - 1] % MOD; zep(i, 0, n)sm += w[i]; if(sm % 2 == 1){print(0) return 0;} dp[0][0][0] = 1; zep(i, 0, n){ memset(dp[(i + 1) % 2], 0, sizeof(dp[(i + 1) % 2])); rep(j, 0, sm / 2){ rep(k, 0, i){ dp[(i + 1) % 2][j][k] += dp[i % 2][j][k]; dp[(i + 1) % 2][j][k] %= MOD; dp[(i + 1) % 2][j + w[i]][k + 1] += dp[i % 2][j][k]; dp[(i + 1) % 2][j + w[i]][k + 1] %= MOD; } } } ll ans = 0; zep(k, 1, n){ ans += dp[n % 2][sm / 2][k] * (ex[k] * ex[n - k] % MOD) % MOD; ans %= MOD; } print(ans) return 0; }
#include<bits/stdc++.h> using namespace std; const long long int MOD = 998244353; void solve() { int n; cin >> n; vector<int> a(n); long long int sum = 0; for (int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } if (sum % 2) { cout << 0; return; } vector<long long int> f(n + 1, 1); vector<vector<long long int>> dp(sum + 1, vector<long long int>(n + 1, 0)); dp[0][0] = 1; for (int i = 1; i <= n; i++) f[i] = f[i - 1] * i % MOD; for (int i = 0; i < n; i++) { for (int j = n; j > 0; j--) { for (int k = sum; k >= a[i]; k--) { dp[k][j] += dp[k - a[i]][j - 1]; dp[k][j] %= MOD; } } } long long int ans = 0; for (int i = 0; i <= n; i++) { ans += dp[sum / 2][i] * f[i] % MOD * f[n - i] % MOD; ans %= MOD; } cout << ans; } int main() { ios::sync_with_stdio(false); cin.tie(0); int t = 1; // cin >> t; while (t--) { solve(); } }
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; int main() { int n; cin >> n; vector<int> a(n),b(n); rep(i, n)cin >> a[i]; sort(a.begin(), a.end()); rep(i, n)b[i] = i + 1; rep(i, n) { if (a[i] != b[i]) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; return 0; }
#include<bits/stdc++.h> using namespace std; const int INF = INT_MAX; const int MOD = 1e9 + 7; //const int ULTRA = 1e14; const int PROMAX = 1e6 + 5; const int PRO = 1e5 + 5; #define ll long long #define int ll #define all(x) x.begin(), x.end() #define lla(x) x.rbegin(), x.rend() #define pb push_back #define ThinkTwice ios_base::sync_with_stdio(false); cin.tie(NULL); int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1}; int dy[] = { 0, 1, 0, -1, -1, 1, 1, -1}; char dir[] = {'U','R','D','L'}; inline int powmod(int a, int b, int mod) {int res=1; while(b>0) {if(b&1) res=(res*a)%mod; a=(a*a)%mod; b>>=1; } return res;} inline int power(int a, int b) {int res=1; while(b>0) {if(b&1) res*=a; a*=a; b>>=1;} return res; } //__________________________________________________________________ void solve() { char a, b, c; cin>>a>>b>>c; if(a == b && b == c) cout<<"Won\n"; else cout<<"Lost\n"; } signed main() { ThinkTwice int t; t = 1; // cin>>t; for(int i = 1; i<=t; i++) { // cout<<"Case "<<i<<": "; solve(); } } //__________________________________________________________________ /* Sample Input: Sample Output: */
// Created by Priyanshu #include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; using namespace std; #define M 1000000007 #define pi 3.14159265358979323846 #define ll long long #define lld long double // Pair #define pii pair<int, int> #define pll pair<ll, ll> // Vector #define vl vector<ll > #define vi vector<int> #define vpi vector<pii> #define vpl vector<pll> #define pb push_back #define mp make_pair // Search #define lb lower_bound #define ub upper_bound #define mina *min_element #define mama *max_element #define bsrch binary_search //////// #define F first #define S second #define cel(x,a) (((x) + (a) - 1) / (a)) #define all(v) v.begin(), v.end() #define countofbits(n) __builtin_popcountll(n) #define lcm(m, n) (((m) / __gcd((m), (n)))*(n)) #define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> #define deb(...) cout << "(" << #__VA_ARGS__ << "):", dbg(__VA_ARGS__) #define ms(arr, v) memset(arr, v, sizeof(arr)) #define pf(x,y) setfill('x')<<setw(y) #define ps(x,y) fixed << setprecision(y) << x #define _X_ ios_base::sync_with_stdio(false); cin.tie(NULL) /////////////////////////////// int II; long long I_O; char CC, SS[20]; const int N = 1e5 + 4; /////////////////////////////// // Input / Output #define scn(str) scanf("%s", str) #define pri(str) printf("%s\n", str) #define inp(a, n) for(int Ele=0; Ele<(n); Ele++)a[Ele]=read() #define inp1(a, n) for(int Ele=1; Ele<=(n); Ele++)a[Ele]=read() inline ll read() { II = 1, I_O = 0; while (!isdigit(CC = getchar())) if (CC == '-') II = -1; while (isdigit(CC)) I_O = I_O * 10 + CC - '0', CC = getchar(); return I_O * II;} inline void wonl() { putchar('\n');} inline void wws() { } inline void dbg() { cout << endl; } inline void ww(ll k) { if (k < 0) putchar('-'), k *= -1; II = 0; while (k)SS[++II] = k % 10, k /= 10; if (!II) SS[++II] = 0; while (II)putchar(SS[II--] + '0');} inline void ww(pll p) { ww(p.F), putchar(' '), ww(p.S); } // bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {return (a.S < b.S);} // struct compare { // bool operator()(const pair<int, int>& value, const int& key) {return (value.F < key);} // bool operator()(const int& key, const pair<int, int>& value) {return (key < value.F);} // }; template <typename T, typename... V> inline void wonl(T t, V... v) {ww(t); if (sizeof...(v))putchar(' '); wonl(v...);} template <typename T, typename... V> inline void wws(T t, V... v) {ww(t); putchar(' '); wws(v...);} template <typename T, typename... V> inline void dbg(T t, V... v) {cout << ' ' << t; dbg(v...);} // always type cast before using v.size() //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void solve() { int ar[3]; inp(ar, 3); sort(ar, ar + 3); wonl(ar[1] + ar[2]); } int main() { // _X_; // clock_t time_req = clock(); solve(); // time_req = clock() - time_req; // cout << (float)time_req / CLOCKS_PER_SEC; return 0; }
#include <bits/stdc++.h> #include <math.h> using namespace std; int main() { int a, b, c, Max1, Max2; cin >> a >> b >> c; Max1 = max(a+b, b+c); Max2 = max(c+a, Max1); cout << Max2 << endl; }
#include <bits/stdc++.h> using namespace std; #ifdef Dhiraj #include "D:/dhiraj/Programming/debug.h" #else #define d(...) 11 #define cerr if(0) cerr #endif #define ll long long int #define endl '\n' template <typename T, typename U> inline istream& operator >> (istream& in, pair<T, U>& p) { in >> p.first >> p.second; return in; } template <typename T> inline istream& operator >> (istream& in, vector<T>& v) { for(T& x : v) in >> x; return in; } const ll INF = 1e10; const ll N = 1e5 + 1; const ll K = 17 + 1; ll n, m, k; vector<ll> g[N]; ll c[K]; ll dis[K][N]; ll dp[1ll << K][K]; void bfs(ll id) { vector<bool> vis(n + 1, 0); vis[c[id]] = true; for(ll i = 0; i <= n; i++) { dis[id][i] = INF; } queue<ll> q; q.push(c[id]); dis[id][c[id]] = 0; while(!q.empty()) { ll u = q.front(); q.pop(); for(ll v : g[u]) { if(!vis[v]) { vis[v] = true; dis[id][v] = dis[id][u] + 1; q.push(v); } } } } ll f(ll mask, ll u) { if(mask == (1ll << (k + 1)) - 2) return 0; ll &ans = dp[mask][u]; if(ans != -1) return ans; ans = INF; for(ll v = 1; v <= k; v++) { if((mask & (1ll << v)) == 0) { ans = min(ans, dis[u][c[v]] + f(mask | (1ll << v), v)); } } return ans; } void solve(int &tc) { cin >> n >> m; for(ll i = 0; i <= n; i++) { g[i].clear(); } for(ll i = 0; i < m; i++) { ll x, y; cin >> x >> y; g[x].push_back(y); g[y].push_back(x); } cin >> k; for(ll i = 1; i <= k; i++) { cin >> c[i]; bfs(i); } memset(dp, -1, sizeof(dp)); ll ans = INF; for(ll i = 1; i <= k; i++) { ans = min(ans, 1 + f(1ll << i, i)); } if(ans == INF) ans = -1; cout << ans << endl; } int main() { #ifdef Dhiraj freopen("D:/dhiraj/Programming/i1.txt", "r", stdin); freopen("D:/dhiraj/Programming/o1.txt", "w", stdout); freopen("D:/dhiraj/Programming/e1.txt", "w", stderr); #endif ios::sync_with_stdio(false); cin.tie(0); int tc = 1; for(int i = 1; i <= tc; i++) { cerr << "Case #" << i << "\n"; solve(i); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; #define FOR(i, n) for(int (i)=0; (i)<(n); (i)++) #define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++) #define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--) template<class T, class U> void umin(T& x, const U& y){ x = min(x, (T)y);} template<class T, class U> void umax(T& x, const U& y){ x = max(x, (T)y);} template<class T, class U> void init(vector<T> &v, U x, size_t n) { v=vector<T>(n, (T)x); } template<class T, class U, typename... W> void init(vector<T> &v, U x, size_t n, W... m) { v=vector<T>(n); for(auto& a : v) init(a, x, m...); } int n, m, k; vector<vector<int>> edges; vector<int> c; vector<int> vis; vector<int> d; int main(int argc, char** argv) { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15); if (argc == 2 && atoi(argv[1]) == 123456789) freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin); cin >> n >> m; edges.resize(n+1); FOR(i, m){ int u, v; cin >> u >> v; edges[u].push_back(v); edges[v].push_back(u); } cin >> k; c.resize(k); FOR(i, k) cin >> c[i]; vector<vector<int>> dist(k, vector<int>(k)); for (int i = 0; i < k; i++){ vector<int> d(n+1, -1); d[c[i]] = 0; queue<int> Q; Q.push(c[i]); while (!Q.empty()){ int v = Q.front(); Q.pop(); for (int w : edges[v]){ if (d[w] == -1){ d[w] = d[v] + 1; Q.push(w); } } } for (int j = 0; j < k; j++){ dist[i][j] = d[c[j]]; } } int K = 1<<k; const int inf = 1e9; vector<vector<int>> dp; init(dp, inf, K, k); FOR(i, k) dp[1<<i][i] = 0; FOR(mask, K){ FOR(i, k){ if ((mask & (1<<i))){ int mask2 = mask ^ (1<<i); FOR(j, k){ if ((mask2 & (1<<j)) && dist[j][i] != -1){ umin(dp[mask][i], dp[mask2][j] + dist[j][i]); } } } } } int sol = inf; FOR(i, k) umin(sol, dp[K-1][i]); cout << (sol < inf ? sol+1 : -1) << endl; if (argc == 2 && atoi(argv[1]) == 123456789) cout << clock()*1.0/CLOCKS_PER_SEC << " sec\n"; return 0; }
#include <bits/stdc++.h> #define forn(i,n) for(int i=0;i<(int)n;i++) #define forx(i,x,n) for(int i=x;i<(int)n;i++) #define ce(e,i,n) cout<<e<<" \n"[i==(int)n-1]; using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; const int N=5e2+2; //int a[N][N],vis[N][N],dr[4]={1,0,-1,0},dc[4]={0,1,0,-1},n,m; int main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); // = 0 - [i] {} '\n' p _ ? ^ int n,q,t; ll mn=-1e15,mx=1e15,s=0,x,a; cin>>n; forn(i,n){ cin>>a>>t; if(t==1)mn+=a,mx+=a,s+=a; else if(t==2)mn=max(mn,a),mx=max(mx,a); else mn=min(mn,a),mx=min(mx,a); } cin>>q; forn(i,q)cin>>x,cout<<min(mx,max(mn,x+s))<<'\n'; }
#include<bits/stdc++.h> using namespace std; using ll=long long; int main(){ int n;cin>>n; vector<ll>ae(n+1,0),be(n+1,0),b(n+1); int tmp; for(int i=0;i<n;i++){ cin>>tmp; ae.at(tmp)++; } for(int i=1;i<=n;i++){ cin>>b.at(i); be.at(b.at(i))=1; } ll ans=0; for(int i=0;i<n;i++){ cin>>tmp; ans+=ae.at(b.at(tmp))*be.at(b.at(tmp)); } cout<<ans<<endl; }
#include <bits/stdc++.h> #define int long long // #define m 1000000007 // #define piii pair<pair<int,int>> #define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; void solve(){ int n; cin>>n; int a[n],b[n]; for(int i=0;i<n;i++){ cin>>a[i]; } for(int i=0;i<n;i++){ cin>>b[i]; } int mx1=a[0]*b[0],mx=0; for(int i=0;i<n;i++){ if(a[i]>mx) mx=a[i]; if(b[i]*mx>mx1) {mx1=b[i]*mx; cout<<mx1<<"\n";} else cout<<mx1<<"\n"; } } int32_t main(){ fast // int t; // cin>>t; // while(t--){ solve(); // cout<<"\n"; // } return 0; }
#include <iostream> #include <vector> using namespace std; int main() { int M; cin >> M; vector<int> vec(M); for (int i = 0; i < M; i++) { cin >> vec.at(i); // cout << vec.at(i) << endl; } vector<int> prime({2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47}); uint64_t answer = -1; for (uint16_t i = 0; i <= 0b0111111111111111; i++) // uint16_t i = 0b0111111111111111; { bool c1 = true; // 全ての入力 for (size_t j = 0; j < vec.size(); j++) { // 全ての素数 int c2 = false; for (size_t k = 0; k < 15; k++) { if (i & 0b1 << k) { // 一つでも割り切れる if (vec[j] % prime[k] == 0) { c2 = true; break; } } } // cout << c2 << endl; if (!c2) { // 一つも割り切れない c1 = false; break; } } // 全ての入力に置いて何かしら割り切れる if (c1) { uint64_t kouho = 1; for (size_t k = 0; k < 15; k++) { if (i & 1 << k) { kouho *= prime[k]; } } if (kouho < answer) answer = kouho; } // kouho *= prime[j]; // bool tmp = true; // for (size_t j = 0; j < prime.size(); j++) // { // if(prime[j]%kouho) // } // if (tmp) } cout << answer; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define MAX 1000000001 #define MOD 1000000007 #define rep(i, n) for (int i = 0; i < n; ++i) void solve(void) { vector<int> v(3); rep(i, 3) cin >> v[i]; map<int, int> mp; rep(i, 3) mp[v[i]]++; bool f = false; for (auto i : mp) { if (i.second >= 2) f = true; if (i.second >= 3) { cout << i.first << endl; return; } } if (f) for (auto i : mp) { if (i.second < 2) { cout << i.first << endl; return; } } else cout << 0 << endl; } int main(void) { solve(); }
#include<bits/stdc++.h> using namespace std; #define ll long long int #define mod 1000000007 #define pb emplace_back #define desend(x) greater<x>() #define srt(v) sort(v.begin(),v.end()) #define all(x) x.begin(),x.end() #define rvs(x) reverse(x.begin(),x.end()) #define Input(x) for(auto &n:x) cin>>n; #define Output(x) for(auto &n:x) cout<<n<<" ";cout<<"\n"; ll power(ll x,ll y){//for (x^y)%mod Iterative ll ans=1; while(y>0){ ans%=mod; if(y&1)ans*=x; x=x*x%mod; y>>=1; } return ans%mod; } ll fact(ll n){ ll ans=1; for(ll i=1;i<=n;i++){ ans*=i; ans%=mod; } return ans; } void solve(){ ll a,b,c; cin>>a>>b>>c; map<ll,ll> ma; ma[a]++; ma[b]++; ma[c]++; if(ma.size()==3)cout<<0; else { if(ma.size()==1)cout<<a; else { for(auto it:ma)if(it.second==1)cout<<it.first; } } } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); solve(); }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0; i<(n); ++i) #define rrep(i,n) for(int i=1; i<=(n); ++i) #define drep(i,n) for(int i=(n)-1; i>=0; --i) #define srep(i,s,t) for (int i = s; i < t; ++i) #define pb push_back #define eb emplace_back #define sz(x) (int)(x).size() #define fi first #define se second #define v(T) vector<T> #define imposs {cout<<"-1\n";return 0;} #define LL_MAX LLONG_MAX #define LL_MIN LLONG_MIN typedef unsigned int uint; typedef long long int ll; typedef vector<int> vi; typedef vector<ll> vll; typedef pair<int,int> pii; typedef vector<pii> vpii; typedef set<int> si; typedef multiset<int> msi; template<typename T>string join(const v(T)&v) {stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);} template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v) {if(sz(v))o<<join(v);return o;} int main(){ cin.tie(0); ios::sync_with_stdio(false); string S; cin >> S; ll ans = 0; char n = '0'; rep(i, sz(S)) { if (S[i] != n) { if (n != '0') ans++; if (i < sz(S)-1 && S[i] == S[i+1]) { if (n != '0') ans += (sz(S) - 1 - i); n = S[i]; } } } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; #define FOR(i, n) for(int (i)=0; (i)<(n); (i)++) #define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++) #define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--) template<class T, class U> void umin(T& x, const U& y){ x = min(x, (T)y);} template<class T, class U> void umax(T& x, const U& y){ x = max(x, (T)y);} template<class T, class U> void init(vector<T> &v, U x, size_t n) { v=vector<T>(n, (T)x); } template<class T, class U, typename... W> void init(vector<T> &v, U x, size_t n, W... m) { v=vector<T>(n); for(auto& a : v) init(a, x, m...); } int main(int argc, char** argv) { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15); if (argc == 2 && atoi(argv[1]) == 123456789) freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin); const ll MOD = 1e9+7; int n; cin >> n; vector<int> v(n); FOR(i, n) cin >> v[i]; v.push_back(0); sort(v.begin(), v.end()); ll sol = 1; for(int i = 1; i<v.size(); i++) if (v[i] != v[i-1]) sol = sol * (v[i] - v[i-1] + 1) % MOD; cout << sol << endl; if (argc == 2 && atoi(argv[1]) == 123456789) cout << clock()*1.0/CLOCKS_PER_SEC << " sec\n"; return 0; }
#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 MOD = 1000000007; /* 実行時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, p; cin >> n >> p; cout << Mint<>(p - 1) * Mint<>(p - 2).pow(n - 1) << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i < (int)(n); i++) #define ll long long #define int long long #define length size() const int MOD = 1000000007; const int MAX = 510000; const int inf = 400000000000000; template<typename T> string join(vector<T> &vec ,const string &sp){ int si = vec.length; if(si==0){ return ""; }else{ stringstream ss; rep(i,si-1){ ss << vec[i] << sp; } ss << vec[si - 1]; return ss.str(); } } bool isPrime(int n){ //cout << n << endl; if(n == 1) return false; else if(n%2 == 0&&n!=2) return false; bool f = true; for(int i=3;i<=sqrt(n);i+=2){ if(n%i==0){ f = false; break; } } return f; } map<int,int> pf(int n){ map<int,int> mp; if(n==1){ mp[1] = 1; return mp; }else{ int p = 2; while(n!=1){ if(n%p==0){ if(mp.find(p)==mp.end()){ mp[p] = 1; }else{ mp[p]++; } n /= p; }else{ (p==2)?p++:p+=2; } } return mp; } } int ctoi(const char c){ switch(c){ case '0': return 0; case '1': return 1; case '2': return 2; case '3': return 3; case '4': return 4; case '5': return 5; case '6': return 6; case '7': return 7; case '8': return 8; case '9': return 9; default : return -1; } } struct UnionFind{ vector<int> par; vector<int> siz; int w; UnionFind(int n) : par(n),siz(n){ for(int i=0;i<n;i++){par[i]=i;siz[i]=1;} w = n; } int root(int x){ while(par[x]!=x){ x = par[x] = par[par[x]]; } return x; } void merge(int x,int y){ x = root(x); y = root(y); if(siz[x]>siz[y]) swap(x,y); if(x!=y){ siz[y] += siz[x]; par[x] = y; w-=1; } } int size(int n){ return siz[n]; } int wid(){ return w; } }; vector<int> rev(vector<int> vec){ rep(i,vec.size()){ vec[i] = (vec[i]==1)?0:1; } return vec; } vector<long long> divisor(long long n) { vector<long long> ret; for (long long i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(ret.begin(), ret.end()); // 昇順に並べる return ret; } ll merge_cnt(vector<int> &a) { int n = a.size(); if (n <= 1) { return 0; } ll cnt = 0; vector<int> b(a.begin(), a.begin()+n/2); vector<int> c(a.begin()+n/2, a.end()); cnt += merge_cnt(b); cnt += merge_cnt(c); int ai = 0, bi = 0, ci = 0; // merge の処理 while (ai < n) { if ( bi < b.size() && (ci == c.size() || b[bi] <= c[ci]) ) { a[ai++] = b[bi++]; } else { cnt += n / 2 - bi; a[ai++] = c[ci++]; } } return cnt; } signed main(void){ int h,w; cin >> h >> w; vector<vector<int>> vec(h+2,vector<int>(w+2,0)); rep(i,h){ rep(j,w){ char t; cin >> t; if(t=='#'){ vec[i+1][j+1] = 1; } } } int ans = 0; rep(i,h+1){ rep(j,w+1){ if(vec[i][j]+vec[i][j+1]+vec[i+1][j]+vec[i+1][j+1]==1||vec[i][j]+vec[i][j+1]+vec[i+1][j]+vec[i+1][j+1]==3) ans++; } } cout << ans << endl; }
#include "bits/stdc++.h" //#include "atcoder/all" using namespace std; //using namespace atcoder; //using mint = modint1000000007; //const int mod = 1000000007; //using mint = modint998244353; //const int mod = 998244353; //const int INF = 1e9; //const long long LINF = 1e18; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i,l,r)for(int i=(l);i<(r);++i) #define rrep(i, n) for (int i = (n-1); i >= 0; --i) #define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i) #define all(x) (x).begin(),(x).end() #define allR(x) (x).rbegin(),(x).rend() #define endl "\n" int main() { ios::sync_with_stdio(false); cin.tie(nullptr); string s1, s2, s3; cin >> s1 >> s2 >> s3; vector<char>cv; rep(i, s1.size()) { cv.push_back(s1[i]); } rep(i, s2.size()) { cv.push_back(s2[i]); } rep(i, s3.size()) { cv.push_back(s3[i]); } sort(cv.begin(), cv.end()); cv.erase(unique(cv.begin(), cv.end()), cv.end()); if (cv.size() > 10) { cout << "UNSOLVABLE " << endl; return 0; } vector<int> v; rep(i, 10) { v.push_back(i); } map<char, int>mp; do { int count = 0; rep(i, cv.size()) { mp[cv[i]] = v[i]; } long long n1 = 0; long long n2 = 0; long long n3 = 0; if (0 == mp[s1[0]]) { continue; } if (0 == mp[s2[0]]) { continue; } if (0 == mp[s3[0]]) { continue; } rep(i, s1.size()) { n1 *= 10; n1 += mp[s1[i]]; } rep(i, s2.size()) { n2 *= 10; n2 += mp[s2[i]]; } rep(i, s3.size()) { n3 *= 10; n3 += mp[s3[i]]; } if (n1 + n2 == n3) { cout << n1 << endl; cout << n2 << endl; cout << n3 << endl; return 0; } } while (next_permutation(v.begin(), v.end())); cout << "UNSOLVABLE " << endl; return 0; }
// ----- In the name of ALLAH, the Most Gracious, the Most Merciful ----- #include<bits/stdc++.h> using namespace std; #define sim template < class c #define ris return * this #define dor > debug & operator << #define eni(x) sim > typename \ enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { #ifdef LOCAL ~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } #else sim dor(const c&) { ris; } #endif }; #define deb(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " #define memo(dp,val) memset(dp,val,sizeof(dp)) #define NINJA ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define all(a) a.begin(),a.end() #define fo(i,n) for(int i=0;i<n;i++) #define Fo(i,k,n) for(int i=k;i<n;i++) #define for1(i,n) for(int i=1;i<=n;i++) #define dloop(i,n) for(int i=n-1;i>=0;i--) #define iii tuple<int,int,int> #define vi vector<int> #define ii pair<int,int> #define vii vector<ii> #define int long long #define ld long double #define pb push_back #define endl "\n" #define setbits __builtin_popcountll #define mp map<int,int> #define F first #define S second #define sz(v) (int)v.size() #define mod 1000000007 #define inf (int)1e18 int n; int dp[205][12]; int solve(int sz, int c){ if(c==11) return 1; if(sz==n || c>11) return 0; int&ans = dp[sz][c]; if(ans!=-1) return ans; ans = 0; for(int i=sz+1;i<n;i++){ ans += solve(i,c+1); } return ans; } int32_t main(){ NINJA; memset(dp,-1,sizeof(dp)); cin >> n; cout << solve(0,0); return 0; }
#include <iostream> using namespace std; int main() { int h, m; cin >> m >> h; cout << (h % m == 0 ? "Yes\n" : "No\n"); return 0; }
#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 FOR(i, m, n) for(int i = m; i <= n; i++) #define FORR(i, m, n) for(int i = m; i >= n; i--) #define SORT(v, n) sort(v, v+n); #define VSORT(v) sort(v.begin(), v.end()); #define VSORTR(v) sort(v.rbegin(), v.rend()); #define ALL(v) (v).begin(),(v).end() using ll = long long; using vll = vector<ll>; using vvll = vector<vector<ll>>; using P = pair<ll, ll>; template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } const ll MOD = 1e9 + 7; const ll INF = 1e18; int main(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(10); ll a, b; cin >> a >> b; if (b % a == 0) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define mod 1000000007 #define int long long #define big 998244353 #define ff first #define se second #define pb push_back #define pii pair<int,int> #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define PSET(x,y) fixed<<setprecision(y)<<x #define mp make_pair #define pi 3.141592653589 int power(int x,int y){ int r=1,z=x; while(y){ if(y & 1)r*=z; z*=z;y=y>>1;} return r;} int powerm(int x,int y,int p){ int r=1; while(y){ if(y & 1)r=(r*x)%p; y=y>>1; x=(x*x)%p;} return r%p;} int modinv(int x,int m){ return powerm(x,m-2,m);} int logarithm(int a,int b){ int x=0; while(a>1){ x++; a/=b;} return x;} vector<int> ad[200005]; int vis[200005]; vector<int> gr; void dfs(int x){ vis[x]=1; gr.pb(x); for(auto p:ad[x]) if(!vis[p]) dfs(p); } int32_t main(){ fast; int n,m; cin>>n>>m; vector<int> a(n),b(n); for(int i=0;i<n;i++) cin>>a[i]; for(int i=0;i<n;i++) cin>>b[i]; for(int i=1;i<=m;i++){ int u,v; cin>>u>>v; ad[u].pb(v); ad[v].pb(u); } for(int i=1;i<=n;i++){ gr.clear(); if(!vis[i]) dfs(i); int sum1,sum2; sum1=sum2=0; for(auto p:gr){ sum2+=b[p-1]; sum1+=a[p-1]; } if(sum1!=sum2){ cout<<"No"; return 0; } } cout<<"Yes"; return 0; }
///Bismillahir Rahmanir Rahim #include "bits/stdc++.h" #define ll long long #define int ll #define fi first #define si second #define mp make_pair #define pb push_back #define pi pair<int,int> #define node(a,b,c) mp(mp(a,b),c) #define clr(x) memset(x,0,sizeof(x)); #define f(i,l,r) for(int i=l;i<=r;i++) #define rf(i,r,l) for(int i=r;i>=l;i--) #define done(i) cout<<"done = "<<i<<endl; #define show(x,y) cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl; #define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; const ll inf=1e18; const int mod=1e9+7; const int M=200005; int a[M],b[M],par[M],asum[M],bsum[M],sz[M],ok[M]; int fnd(int x) { if(par[x]==x)return x; return par[x]=fnd(par[x]); } void tie(int x,int y) { int fx=fnd(x); int fy=fnd(y); if(fx==fy)return ; par[fx]=fy; } main() { fast int n,m; cin>>n>>m; f(i,1,n)cin>>a[i],par[i]=i; f(i,1,n)cin>>b[i]; f(i,1,m) { int u,v; cin>>u>>v; tie(u,v); } f(i,1,n) { int p=fnd(i); asum[p]+=a[i]; bsum[p]+=b[i]; } f(i,1,n) { if(asum[i]!=bsum[i]) { cout<<"No\n";return 0; } } cout<<"Yes\n"; return 0; }
#include <bits/stdc++.h> using namespace std; const int MAX_N = 200000; typedef long long ll; const ll MOD = 998244353; int n, k; ll A[MAX_N]; ll S[301]; ll inv[301]; ll func(ll t) { ll ans = 1; ll pow = MOD - 2; while (pow > 0) { if (pow&1) ans = ans * t % MOD; t = t * t % MOD; pow >>= 1; } return ans; } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> k; for (int j = 0; j <= k; j++) { S[j] = 0; if (j > 0) inv[j] = func(j); } for (int i = 0; i < n; i++) { cin >> A[i]; ll tmp = 1ll; S[0] += tmp; for (int j = 1; j <= k; j++) { tmp = tmp * A[i] % MOD; S[j] += tmp; if (S[j] >= MOD) S[j] -= MOD; } } for (int x = 1; x <= k; x++) { ll ans = 0; ll comb = 1ll; for (int i = 0; i * 2 + 1 <= x; i++) { if (i > 0) comb = comb * (x - i + 1) % MOD * inv[i] % MOD; ll tmp = S[i] * S[x - i] % MOD + MOD - S[x]; if (tmp >= MOD) tmp -= MOD; ans = ans + (comb * tmp % MOD); if (ans >= MOD) ans -= MOD; } if (x % 2 == 0) { comb = comb * (x / 2 + 1) % MOD * inv[x / 2] % MOD; ll tmp = (S[x / 2] * S[x / 2] % MOD + MOD - S[x]) * inv[2] % MOD; ans = ans + (comb * tmp % MOD); if (ans >= MOD) ans -= MOD; } cout << ans << "\n"; } }
#include <bits/stdc++.h> #define endl '\n' #define fi first #define se second #define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k)) #define forn(i,n) for (int i = 0; i < (n); i++) #define forr(i,a,b) for (int i = a; i <= b; i++) #define all(v) v.begin(), v.end() #define pb(x) push_back(x) using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll, int> ii; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ii> vii; const int MX = 200005, mod = 998244353; const ll inv2 = (mod + 1) / 2; int n, k; ll res[MX], s[MX], comb[705][705], a[MX]; int main () { ios_base::sync_with_stdio(0); cin.tie(0); forn (i, 705) { comb[i][0] = 1; for (int j = 1; j <= i; j++) comb[i][j] = (comb[i - 1][j] + comb[i - 1][j - 1]) % mod; } cin >> n >> k; forn (i, n) cin >> a[i]; forn (i, n) { ll x = 1; forn (j, k + 1) { (s[j] += x) %= mod; (x *= a[i]) %= mod; } } forn (i, k + 1) forn (j, k + 1) { (res[i + j] += comb[i + j][i] * s[i] % mod * s[j] % mod) %= mod; (res[i + j] -= comb[i + j][i] * s[i + j]) %= mod; } for (int i = 1; i <= k; i++) { (res[i] *= inv2) %= mod; cout << MOD(res[i], mod) << endl; } return 0; }
/* * Created By: 'Present_Sir' * Created On: Thursday 27 May 2021 10:33:10 AM */ #include<bits/stdc++.h> #define int long long using namespace std; const int Mod = 998244353; template <int mod> struct ModInt { int x; ModInt() : x(0) {} ModInt(long long x_) { if ((x = x_ % mod + mod) >= mod) x -= mod; } ModInt& operator+=(ModInt rhs) { if ((x += rhs.x) >= mod) x -= mod; return *this; } ModInt& operator-=(ModInt rhs) { if ((x -= rhs.x) < 0) x += mod; return *this; } ModInt& operator*=(ModInt rhs) { x = (unsigned long long)x * rhs.x % mod; return *this; } ModInt& operator/=(ModInt rhs) { x = (unsigned long long)x * rhs.inv().x % mod; return *this; } ModInt operator-() const { return -x < 0 ? mod - x : -x; } ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; } ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; } ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; } ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; } bool operator==(ModInt rhs) const { return x == rhs.x; } bool operator!=(ModInt rhs) const { return x != rhs.x; } ModInt inv() const { return pow(*this, mod - 2); } friend ostream& operator<<(ostream& s, ModInt<mod> a){ s << a.x; return s; } friend istream& operator>>(istream& s, ModInt<mod>& a){ s >> a.x; return s; } }; using mint = ModInt<Mod>; // ... // ... // ... // ... int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; vector < string > s(n); for(auto &x: s) cin >> x; mint ans = 1; for(int i=0; i<n+m-1; ++i){ int a=0, b=0, cnt=0; int nx = 0; for(int j=i; j>=0; --j){ int ny = j; if(nx>=0 and ny>=0 and nx<n and ny<m){ if(s[nx][ny] == 'R')++a; if(s[nx][ny]=='B')++b; if(s[nx][ny]=='.')++cnt; } ++nx; } //cerr << a << " " << b << "\n"; if(a>0 and b>0){ cout << 0 << "\n"; return 0; }else if(a == 0 and b == 0){ ans *= 2; } } cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0; i<(n); i++) #define sz(x) int(x.size()) using namespace std; typedef long long ll; typedef pair<int,int> P; int main(){ int h,w; cin >> h >> w; vector<string> s(h); rep(i,h) cin >> s[i]; vector<bool> flag_R(h+w-1); vector<bool> flag_B(h+w-1); rep(i,h)rep(j,w){ if(s[i][j] == 'R') flag_R[i+j] = true; if(s[i][j] == 'B') flag_B[i+j] = true; } ll ans = 1; rep(i,h+w-1){ if(flag_R[i] && flag_B[i]){ ans = 0; } if(!flag_R[i] && !flag_B[i]){ ans *= 2; ans %= 998244353; } } cout << ans << endl; return 0; }
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author */ #include <iostream> #include <fstream> #include <bits/stdc++.h> using namespace std; #define ll long long inline int inint(istream& in) {int x; in >> x; return x;} inline ll inll(istream& in) {ll x; in >> x; return x;} inline string instr(istream& in) {string x; in >> x; return x;} #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i) #define REV(i, a, b) for (int i = (a); i >= (b); --i) #define CLR(a, b) memset((a), (b), sizeof(a)) #define DUMP(x) cout << #x << " = " << (x) << endl; #define INF 1001001001001001001ll #define fcout cout << fixed << setprecision(12) class ARockPaperScissors { public: void solve(std::istream& in, std::ostream& out) { int x = inint(in); int y = inint(in); if(x == y){ out << x << endl; return; } if(x + y == 1){ out << 2 << endl; return; } if(x + y == 2){ out << 1 << endl; return; } if(x + y == 3){ out << 0 << endl; return; } } }; int main() { ARockPaperScissors solver; std::istream& in(std::cin); std::ostream& out(std::cout); solver.solve(in, out); return 0; }
#include <bits/stdc++.h> using namespace std; #define deb(k) cerr << #k << ": " << k << "\n"; #define size(a) (int)a.size() #define fastcin cin.tie(0)->sync_with_stdio(0); #define st first #define nd second #define pb push_back #define mk make_pair #define int long long typedef long double ldbl; typedef double dbl; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef map<int, int> mii; typedef vector<int> vint; #define MAX 300100 #define MAXLG 20 const int inf = 0x3f3f3f3f; const ll mod = 998244353; const ll linf = 0x3f3f3f3f3f3f3f3f; const int N = 300100; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //knapstack ll fat[MAX+100]; ll ifat[MAX+100]; 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 init(){ fat[0] = 1; for(ll i=1;i<=MAX;i++){ fat[i] = (fat[i-1]*i)%mod; } ifat[MAX] = power(fat[MAX], mod-2, mod); for(ll i=MAX-1;i>=0;i--) ifat[i] = (ifat[i+1]*(i+1))%mod; } ll choose(int x, int y){ if(y < 0 || y > x || x < 0) return 0; return fat[x]*(ifat[y]*ifat[x-y]%mod)%mod; } int n, m; int dp[5010][20]; int vis[5010][20]; int sol(int x, int y){ if(y == 17){ if(x) return 0; return 1; } if(vis[x][y]) return dp[x][y]; vis[x][y] = 1; int &c = dp[x][y]; for(int i=0;i<=n;i+=2){ if( (1<<y)*i > x) break; c = (c + sol(x - (1<<y)*i, y+1)*choose(n, i)%mod)%mod; } return c; } void solve(){ init(); cin>>n>>m; cout<<sol(m, 0)<<"\n"; // Have you read the problem again? // Maybe you understood the wrong problem } int32_t main(){ fastcin; int t_ = 1; //cin>>t_; while(t_--) solve(); return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0; i<(int)(n); i++) using namespace std; using LL = long long; using P = pair<int,int>; const LL INF = 1e18; int main(){ int N, M; cin >> N >> M; vector<LL> H(N), W(M); rep(i,N) cin >> H[i]; rep(i,M) cin >> W[i]; sort(H.begin(),H.end()); vector<int> sum_left((N+1)/2), sum_right((N+1)/2); rep(i,(N-1)/2){ sum_left[i+1] = sum_left[i] + (H[2*i+1] - H[2*i]); sum_right[i+1] = sum_right[i] + (H[2*i+2] - H[2*i+1]); } LL ans = INF; rep(i,M){ int num = lower_bound(H.begin(),H.end(),W[i])-H.begin(); LL right = sum_right[(N-1)/2] - sum_right[num/2]; LL res = sum_left[num/2] + right; if(num % 2 == 0) res += H[num] - W[i]; else res += W[i] - H[num-1]; ans = min(ans, res); } cout << ans << endl; return 0; }
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #include<bits/stdc++.h> #define itn int #define ll long long #define pir pair<ll,ll> #define yes {puts("Yes");} #define no {puts("No");} using namespace std; ll read(){ ll a=0,b=1;char c=getchar(); while(c>'9'||c<'0'){if(c=='-')b=-1;c=getchar();} while(c>='0'&&c<='9')a=a*10+c-48,c=getchar(); return a*b; } int n,m; struct edge{ int v,nx; ll c,d; }e[200005]; int cnt,hd[100005]; ll dis[100005]; bool vis[100005]; struct node{ int i; ll w; }; bool operator<(node a,node b){ return a.w>b.w; } ll clac(ll t,ll c,ll d){ if(!d)return c; ll sq=sqrt(d+2),ans=c+d/(t+1); for(ll st=t;st<=t+3;st++){ ans=min(ans,d/(st+1)+st-t+c); } if(t+1<sq){ for(ll st=t;st<=t+30;st++){ ans=min(ans,d/(st+1)+st-t+c); } for(ll st=max(t,sq-30);st<=sq+5;st++){ ans=min(ans,d/(st+1)+st-t+c); } } return ans; } void dij(){ memset(dis,0x3f,sizeof dis); dis[1]=0; priority_queue<node>q; q.push(node{1,0}); while(!q.empty()){ node t=q.top();q.pop(); if(vis[t.i])continue; vis[t.i]=1; for(int i=hd[t.i];i;i=e[i].nx){ int v=e[i].v; ll w=clac(dis[t.i],e[i].c,e[i].d); if(dis[v]>dis[t.i]+w){ dis[v]=dis[t.i]+w; q.push(node{v,dis[v]}); } } } } int main(){ n=read(),m=read(); while(m--){ int a=read(),b=read(),c=read(),d=read(); e[++cnt]=edge{b,hd[a],c,d},hd[a]=cnt; e[++cnt]=edge{a,hd[b],c,d},hd[b]=cnt; } dij(); if(dis[n]>1e18)cout<<-1; else cout<<dis[n]<<'\n'; return 0; }
#include <bits/stdc++.h> using namespace std; //#define int long long typedef long long ll; typedef unsigned long long ul; typedef unsigned int ui; const ll mod = 1000000007; // const ll mod = 998244353; const ll INF = mod * mod; const int INF_N = 1e+9; typedef pair<int, int> P; #define rep(i,n) for(int i=0;i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define Rep(i,sta,n) for(int i=sta;i<n;i++) #define rep1(i,n) for(int i=1;i<=n;i++) #define per1(i,n) for(int i=n;i>=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) #define all(v) (v).begin(),(v).end() typedef pair<ll, ll> LP; typedef long double ld; typedef pair<ld, ld> LDP; const ld eps = 1e-12; const ld pi = acos(-1.0); //typedef vector<vector<ll>> mat; typedef vector<int> vec; //繰り返し二乗法 ll mod_pow(ll a, ll n, ll m) { ll res = 1; while (n) { if (n & 1)res = res * a%m; a = a * a%m; n >>= 1; } return res; } struct modint { ll n; modint() :n(0) { ; } modint(ll m) :n(m) { if (n >= mod)n %= mod; else if (n < 0)n = (n%mod + mod) % mod; } operator int() { return n; } }; bool operator==(modint a, modint b) { return a.n == b.n; } modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; } modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; } modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; } modint operator+(modint a, modint b) { return a += b; } modint operator-(modint a, modint b) { return a -= b; } modint operator*(modint a, modint b) { return a *= b; } modint operator^(modint a, int n) { if (n == 0)return modint(1); modint res = (a*a) ^ (n / 2); if (n % 2)res = res * a; return res; } //逆元(Eucledean algorithm) ll inv(ll a, ll p) { return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p); } modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); } const int max_n = 1 << 18; modint fact[max_n], factinv[max_n]; void init_f() { fact[0] = modint(1); for (int i = 0; i < max_n - 1; i++) { fact[i + 1] = fact[i] * modint(i + 1); } factinv[max_n - 1] = modint(1) / fact[max_n - 1]; for (int i = max_n - 2; i >= 0; i--) { factinv[i] = factinv[i + 1] * modint(i + 1); } } modint comb(int a, int b) { if (a < 0 || b < 0 || a < b)return 0; return fact[a] * factinv[b] * factinv[a - b]; } using mP = pair<modint, modint>; int dx[4] = { 0,1,0,-1 }; int dy[4] = { 1,0,-1,0 }; void solve() { int n, w; cin >> n >> w; cout << n/w << endl; } signed main() { ios::sync_with_stdio(false); cin.tie(0); //cout << fixed << setprecision(10); //init_f(); //init(); //int t; cin >> t; rep(i, t)solve(); solve(); // stop return 0; }
/* Written By mafailure */ //In the name of God #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/tree_policy.hpp> #include <functional> // for less using namespace std; using namespace __gnu_pbds; #define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define endl "\n" #ifdef ill #define int long long #endif template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; } template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; } template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } void dbg_out() { cerr << endl; } template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); } #ifdef AATIF_DEBUG #define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__) #else #define dbg(...) #endif //#define int long long // int dx[]={-1,1,0,0}; int dy[]={0,0,1,-1}; // int dx[]={2,2,-2,-2,1,1,-1,-1}; int dy[]={1,-1,1,-1,2,-2,2,-2}; const long long mod = 1e9 + 7; const double eps=1e-9; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<string> vs; typedef vector<bool> vb; typedef pair<int, int> ii; typedef vector< pair< int, int > > vii; typedef map<int, int> mii; typedef pair<int, ii> pip; typedef pair<ii, int> ppi; #define arrinp(arr,init,final,size,type) type* arr=new type[size];for(int i=init;i<final;i++)cin>>arr[i]; #define cr2d(arr,n,m,t) t**arr=new t*[n];for(int i=0;i<n;i++)arr[i]=new t[m]; #define w(t) int t;cin>>t; while(t--) #define takeInp(n) int n;cin>>n; #define fr(i,init,final) for(int i=init;i<final;i++) #define frr(i,init,final) for(int i=init;i>=final;i--) #define Fr(i,final) for(int i=0;i<final;i++) #define Frr(i,first) for(int i=first;i>=0;i--) #define fi first #define se second #define mp make_pair #define pb push_back #define all(c) (c).begin(),(c).end() #define rall(c) (c).rbegin(),(c).rend() #define debug(x) cerr<<">value ("<<#x<<") : "<<x<<endl; #define setb __builtin_popcount #define lsone(n) (n&(-n)) #define rlsone(n) (n&(n-1)) #define clr(a,b) memset(a,b,sizeof(a)) const int inf= INT_MAX; //struct point_i{int x,y;}; struct point_i{int x,y; point_i(){ x=0; y=0;} point_i(int x_,int y_){x=(x_);y=(y_) ;} }; struct point { float x,y; point (){x=y=0.0;} point (float x_,float y_){x=(x_); y=(y_);} bool operator < (point other) const{ if(fabs(x-other.x)>eps)return x<other.x; return y<other.y; } bool operator == (point other) const { return fabs(other.x-x)<=eps&& fabs(other.y-y)<=eps; } } ; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; vi init(string s) { istringstream sin(s); int n; vi arr; while(sin>>n)arr.push_back(n); return arr; } int power(int x, int y) { if(y==0)return 1; int u=power(x,y/2); u=(u*u)%mod; if(y%2)u=(x*u)%mod; return u; } int gcd(int a,int b) { if(a<b)return gcd(b,a); return (b==0?a:(a%b?gcd(b,a%b):b)); } int gcd_e(int a,int b,int &x,int &y) { if(b==0){x=1; y=0; return a;} int x1,y1; int p=gcd_e(b,a%b,x1,y1); x=y1; y=x1-(a/b)*y1; return p; } signed main() { IOS int n,m; cin>>n>>m; vi a(n),b(m); fr(i,0,n) cin>>a[i]; fr(i,0,m) cin>>b[i]; int dp[n+1][m+1]; fr(i,0,n+1)fr(j,0,m+1)dp[i][j]=inf; dp[0][0]=0; fr(i,0,n+1) { fr(j,0,m+1) { if(dp[i][j]==inf) continue; if(mp(i,j)==mp(n,m))continue; if(i!=n)dp[i+1][j]=min(dp[i+1][j],dp[i][j]+1); if(j!=m)dp[i][j+1]=min(dp[i][j+1],dp[i][j]+1); if(i!=n&&j!=m)dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j]+2), dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j]+(a[i]!=b[j])); } } cout<<dp[n][m]<<endl; }
// Template #include <iostream> #include <vector> #include <algorithm> #include <numeric> #include <iomanip> #include <tuple> #include <utility> #include <queue> #include <set> #include <map> #include <array> #include <cassert> #include <cmath> #define rep_override(x, y, z, name, ...) name #define rep2(i, n) for (int i = 0; i < (int)(n); ++i) #define rep3(i, l, r) for (int i = (int)(l); i < (int)(r); ++i) #define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__) #define all(x) (x).begin(), (x).end() using namespace std; using ll = long long; constexpr int inf = 1001001001; constexpr ll infll = 3003003003003003003LL; template <typename T> inline bool chmin(T &x, const T &y) { if (x > y) { x = y; return true; } return false; } template <typename T> inline bool chmax(T &x, const T &y) { if (x < y) { x = y; return true; } return false; } template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &element : vec) is >> element; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { for (int i = 0, vec_len = (int)vec.size(); i < vec_len; ++i) { os << vec[i] << (i + 1 == vec_len ? "" : " "); } return os; } struct IOSET { IOSET() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } ioset; // Main int main() { int n; cin >> n; vector<int> a(n); cin >> a; constexpr int mx = 200001; vector<vector<int>> g(mx); rep(i, n) { if (a[i] != a[n - 1 - i]) { g[a[i]].push_back(a[n - 1 - i]); } } int ans = 0; vector<int> checked(mx, 0); rep(i, mx) { if (g[i].empty()) continue; if (checked[i]) continue; queue<int> q; q.push(i); int sz = 0; checked[i] = 1; ++sz; while (!q.empty()) { int j = q.front(); q.pop(); for (int k : g[j]) { if (!checked[k]) { checked[k] = 1; ++sz; q.push(k); } } } ans += sz - 1; } cout << ans << '\n'; }
#include <bits/stdc++.h> #define SZ(x) (int)x.size() #define ll long long #define pb push_back using namespace std; const int N = 200005; int n; int a[N], f[N]; int find(int x) { return x == f[x] ? x : f[x] = find(f[x]); } int main() { cin >> n; int ans = 0; for(int i = 0; i < n; ++i) { cin >> a[i]; } for(int i = 0; i < N; ++i) f[i] = i; for(int i = 0; i < n / 2; ++i) { int u = find(a[i]), v = find(a[n - 1 - i]); if (u != v) { f[u] = v; ans++; } } cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long ll inf = -1e12; int main(){ ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; string str; cin >> n >> str; if(str[0] != str[n-1]){ cout << 1; return 0; } for(int i=1; i<=n-3; i++){ if(str[i] != str[0] && str[i+1] != str[0]){ cout << 2; return 0; } } cout << -1; return 0; }
#include<bits/stdc++.h> using namespace std ; #define Next( i, x ) for( int i = head[x]; i; i = e[i].next ) #define rep( i, s, t ) for( int i = (s); i <= (t); ++ i ) #define drep( i, s, t ) for( int i = (t); i >= (s); -- i ) #define mp make_pair #define pi pair<int, int> #define pb push_back #define vi vector<int> int gi() { char cc = getchar() ; int cn = 0, flus = 1 ; while( cc < '0' || cc > '9' ) { if( cc == '-' ) flus = - flus ; cc = getchar() ; } while( cc >= '0' && cc <= '9' ) cn = cn * 10 + cc - '0', cc = getchar() ; return cn * flus ; } const int N = 1e5 + 5 ; int n ; char s[N] ; signed main() { n = gi() ; cin >> s + 1 ; n = strlen(s + 1) ; if(s[1] != s[n]) { puts("1") ; exit(0) ; } for(int i = 2; i < n; ++ i) { if(s[i] != s[1] && s[i + 1] != s[1]) { puts("2") ; exit(0) ; } } puts("-1") ; return 0 ; }
#include <vector> #include <algorithm> #include <iostream> #include <climits> using namespace std; #define rep(i,n) for(int i=0;i<n;++i) #define fep(i,j,n) for(int i=j;i<n;++i) #define ll long long #define ay array #define vtc vector #define MN 200001 vtc<int> dag; vtc<int> v[MN]; int val[MN]; int dp[MN]; bool done[MN]; void dfs(int i){ if(done[i])return; done[i]=1; for(int j:v[i]) dfs(j); dag.push_back(i); } int main(){ int n,m; cin >>n>>m; rep(i,n) cin >>val[i]; rep(i,m){ int a,b; cin >>a>>b; a--;b--; v[a].push_back(b); } rep(i,n){ dfs(i); dp[i]=INT_MAX; } reverse(dag.begin(),dag.end()); int sol=INT_MIN; for(int c:dag){ dp[c]=min(dp[c],val[c]); for(int t:v[c]){ dp[t]=min(dp[t],dp[c]); sol=max(sol,val[t]-dp[t]); } } cout <<sol<<endl; }
/////////////////////////////////////////////////////////////////////////////////////////////////// #include <iostream> #include <vector> #include <algorithm> #include <stack> #include <queue> #include <map> #include <math.h> #include <climits> #include <set> #include <cstring> #include <unordered_map> #include <cstdlib> #include <cmath> #include <string> #include <iomanip> #include <cmath> #include <bitset> #include <stdlib.h> #include <chrono> /////////////////////////////////////////////////////////////////////////////////////////////////// #define fio ios_base::sync_with_stdio(false);cin.tie(NULL); #define ll long long int #define ull unsigned long long int #define cinll(x) ll x;cin >> x; #define cini(x) int x;cin >> x; #define cins(x) string x;cin >> x; #define vect(x) vector<ll> x #define vect1(x) vector<ll> x;x.push_back(0); #define pb(x) push_back(x) #define mp(x, y) make_pair(x, y) /////////////////////////////////////////////////////////////////////////////////////////////////// #define MAX 1e17 #define MIN -9223372036854775800 #define MOD 1000000007 #define f first #define s second /////////////////////////////////////////////////////////////////////////////////////////////////// using namespace std; using u64 = uint64_t; //Safe_hashing for minimising collisions //https://codeforces.com/blog/entry/62393 struct custom_hash { static uint64_t splitmix64(uint64_t x) { // http://xorshift.di.unimi.it/splitmix64.c x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; bool compare(pair<string,ll> a,pair<string,ll> b) { return a.s > b.s; } void findAns(map<ll,char> & mapit,ll currPin,ll & ans,vector<ll> &pin) { if(currPin == 5) { bool ok = true; for(ll i = 0;i <= 9;i++) { if(mapit[i] == 'o') { bool search = false; for(ll j = 1;j <= 4;j++) { if(pin[j] == i) search = true; } if(search == false) { ok = search; break; } } } if(ok) { ans++; } return; } for(ll i = 0;i <= 9;i++) { if(mapit[i] == 'o' || mapit[i] == '?') { pin[currPin] = i; findAns(mapit,currPin+1,ans,pin); pin[currPin] = 0; } } } void solve() { map<ll,char> mapit; for(ll i=0;i<10;i++) { char ch; cin>>ch; mapit[i] = ch; } ll ans = 0; vector<ll> pin(5,0); findAns(mapit,1,ans,pin); cout<<ans; return; } int main(){ // fio; // cinll(t); /////////////////////////////////////////// #ifndef ONLINE_JUDGE freopen("input.txt" , "r", stdin); freopen("output.txt", "w" , stdout); #endif /////////////////////////////////////////// // cinll(t); // for(ll i=1;i<=t;i++) { solve(); // } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string N; cin >> N; string n; reverse_copy(N.begin(), N.end(), back_inserter(n)); int count = 0; for (int i = 0; i < N.size(); i++) { if (N.at(i) == '0') { count++; } } int f = 0; for(int i = 0; i < count + 1; i++){ if(N == n){ f = 1; break; } N = "0" + N; n = n + "0"; } if(f == 1) cout << "Yes" << endl; else cout << "No" << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define int long long #define index(i, n) for(ll i = 0; i < n; i++) #define loop(i, a, b) for(ll i = a;i<b;i++) long long binpow(long long a, long long b) { long long res = 1; while (b > 0) { if (b & 1) res = res * a; a = a * a; b >>= 1; } return res; } bool is_pelin(int n) { vector<int>arr; while(n){ arr.push_back(n%10); n /= 10; } n = arr.size(); for(int i = 0;i<n/2;i++){ if(arr[i] != arr[n - 1 - i])return false; } return true; } int count_zero(int n){ int temp = 0; int cnt = 0; while(n){ temp = n&10; if(temp != 0)break; n/=10; cnt++; } return cnt; } bool is_rem(int n){ vector<int>arr; while(n){ arr.push_back(n%10); n /= 10; } int check = 0; index(i, arr.size()) { if(arr[i] != 0){ check = i; break; } } int ans = 0; int j = 0; loop(i, check, arr.size()){ ans += binpow(10, j) * arr[i]; j++; } if(is_pelin(ans))return true; return false; } signed main(){ ios::sync_with_stdio(0); cin.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); # endif int n; cin >> n; if(is_pelin(n)){ cout << "Yes"; } else{ if(is_rem(n)){ cout << "Yes"; } else{ cout << "No"; } } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(long long i=0;i<(long long)(n);i++) #define REP(i,k,n) for(long long i=k;i<(long long)(n);i++) #define all(a) a.begin(),a.end() #define pb emplace_back #define eb emplace_back #define lb(v,k) (lower_bound(all(v),k)-v.begin()) #define ub(v,k) (upper_bound(all(v),k)-v.begin()) #define fi first #define se second #define pi M_PI #define PQ(T) priority_queue<T> #define SPQ(T) priority_queue<T,vector<T>,greater<T>> #define dame(a) {out(a);return 0;} #define decimal cout<<fixed<<setprecision(15); #define dupli(a) {sort(all(a));a.erase(unique(all(a)),a.end());} typedef long long ll; typedef pair<ll,ll> P; typedef tuple<ll,ll,ll> PP; typedef tuple<ll,ll,ll,ll> PPP; typedef multiset<ll> S; using vi=vector<ll>; using vvi=vector<vi>; using vvvi=vector<vvi>; using vvvvi=vector<vvvi>; using vp=vector<P>; using vvp=vector<vp>; using vb=vector<bool>; using vvb=vector<vb>; const ll inf=1001001001001001001; const ll INF=1001001001; const ll mod=1000000007; const double eps=1e-10; template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;} template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;} template<class T> void out(T a){cout<<a<<'\n';} template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';} template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';} template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);} template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';} template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);} template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);} template<class T> void yesno(T b){if(b)out("yes");else out("no");} template<class T> void YesNo(T b){if(b)out("Yes");else out("No");} template<class T> void YESNO(T b){if(b)out("YES");else out("NO");} template<class T> void noyes(T b){if(b)out("no");else out("yes");} template<class T> void NoYes(T b){if(b)out("No");else out("Yes");} template<class T> void NOYES(T b){if(b)out("NO");else out("YES");} void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);} ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);} ll modpow(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;} int main(){ ll t;cin>>t; rep(tt,t){ ll n;cin>>n; vi v(n); rep(i,n)cin>>v[i]; if(n%2)out("Second"); else{ sort(all(v)); ll a=0,b=0; rep(i,n){ if(i%2)a+=v[i]; else b+=v[i]; } if(a==b)out("Second"); else out("First"); } } }
#include <bits/stdc++.h> using namespace std; struct UnionFind { vector<int> par; vector<int> sz; vector<int> es; UnionFind(int n = 1) { init(n); } void init(int n = 1) { par.resize(n); sz.resize(n); es.resize(n); for (int i = 0; i < n; ++i) { par[i] = i; sz[i] = 1; } } int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); } bool same(int x, int y) { return root(x) == root(y); } void unite(int x, int y) { x = root(x); y = root(y); es[x]++; if (x == y) return; if (sz[x] > sz[y]) swap(x, y); par[x] = y; sz[y] += sz[x]; es[y] += es[x]; return; } int size(int x) { return sz[root(x)]; } int esize(int x) { return es[root(x)]; } }; const int MAXA = 200005; int main() { long long N; cin >> N; vector<long long> A(N); for (int i = 0; i < N; i++) { cin >> A.at(i); } UnionFind uf(MAXA); for (int l = 0, r = N - 1; l < r; l++, r--) { if (A.at(l) == A.at(r)) continue; uf.unite(A.at(l), A.at(r)); } long long ans = 0; for (int i = 0; i < MAXA; i++) { if (i != uf.root(i)) continue; const int sz = uf.size(i); ans += sz - 1; } cout << ans << endl; }
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define N 200005 #define ll long long #define mod 998244353 int n, k; int A[N], S[305]; int C[305][305]; int main() { scanf("%d%d", &n, &k); for (int i = 0; i <= k; i++) { C[i][0] = 1; for (int j = 1; j <= i; j++) C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod; } for (int i = 1; i <= n; i++) { scanf("%d", &A[i]); int now = 1; for (int x = 0; x <= k; x++) { S[x] = (S[x] + now) % mod; now = (ll)now * A[i] % mod; } } int now = 1; for (int i = 1; i <= k; i++) { now = (now << 1) % mod; int ans = 0; for (int j = 0; j <= i; j++) ans = (ans + (ll)C[i][j] * S[j] % mod * S[i - j]) % mod; //printf("%d\n", ans); ans = (ans - (ll)now * S[i] % mod + mod) % mod; ans = ans * 499122177ll % mod; if (ans < 0) ans += mod; printf("%d\n", ans); } }
#include <bits/stdc++.h> #include <cassert> typedef long long int ll; using namespace std; // #include <atcoder/all> // using namespace atcoder; // @@ !! LIM() int main(/* int argc, char *argv[] */) { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << setprecision(20); ll N, X; cin >> N >> X; vector<ll> A(N); for (ll i = 0; i < N; i++) cin >> A[i]; map<ll, ll> mp; auto func = [&](auto rF, ll x, ll i) -> ll { while (i < N && x % A[i] == 0) i++; if (i == N) return 1; ll& ret = mp[x]; if (ret == 0) { ll y = x % A[i]; ret = rF(rF, x - y, i + 1) + rF(rF, x + (A[i] - y), i + 1); } return ret; }; cout << func(func, X, 1) << endl; return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> #define ll long long #define mod 1000000007 // templates #define all(v) v.begin(), v.end() #define F first #define S second #define sz(x) (int)x.size() #define po(x, y) fixed << setprecision(y) << x #define ss(s) scanf(" %[^\n]%*c", s) #define sc(n) scanf("%d", &n) #define sl(n) scanf("%lld", &n) #define ps(s) printf("%s\n", s) #define pr(n) printf("%d\n", n) #define pl(n) printf("%lld\n", n) #define prs(n) printf("%d ", n) #define pls(n) printf("%lld ", n) using namespace std; const ll inf = (ll)1e15 + 10; const int N = (int)1e6 + 10; void solve() { int n; cin >> n; vector<pair<int, string>> a; for (int i = 0; i < n; i++) { int d; string s; cin >> s >> d; a.push_back({d, s}); } sort(all(a)); cout << a[n - 2].S << endl; } int main() { // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif int t = 1; // sc(t); while (t--) { solve(); } // cerr << (float)clock() / CLOCKS_PER_SEC * 1000 << " ms" << endl; return 0; }
#include<bits/stdc++.h> #define int long long using namespace std; int T,L,R; signed main(){ cin>>T; while(T--){ cin>>L>>R; if(R>=2*L)printf("%lld\n",(R-2*L+2)*(R-2*L+1)/2); else printf("0\n"); } return 0; } /* */
#include <bits/stdc++.h> #define ll long long #define V vector<long long> #define VV vector<vector<long long>> #define VVV vector<vector<vector<long long>>> #define P pair<ll,ll> #define rep(i,n) for(ll (i)=0;(i)<(n);++(i)) using namespace std; long long mod=1e9+7; struct mint{ long long x; mint(long long 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(long long t)const{ if(!t)return 1; mint a=pow(t>>1); a*=a; if(t&1)a*=*this; return a; } mint inv()const{return pow(mod-2);} mint& operator/=(const mint a){return *this*=a.inv();} mint operator/(const mint a)const{return mint(*this)/=a;} }; istream& operator>>(istream& is,mint& a){return is>>a.x;} ostream& operator<<(ostream& os,const mint& a){return os<<a.x;} int main() { ll n,m; cin>>n>>m; mod=m*m; cout<<(mint(10).pow(n).x/m+m)%m<<endl; }
#include <bits/stdc++.h> using namespace std; const long long MOD = 5; long long ksm(long long a,long long n,long long mod) { if(n==1)return a%mod; if(n==0)return 1; long long ans=ksm(a,n>>1,mod); ans=ans*ans%mod; if(n&1)ans=ans*a%mod; return ans; } void solve(long long N, long long M){ printf("%lld\n",ksm(10,N,M*M)/M); } // Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) int main(){ long long N; scanf("%lld",&N); long long M; scanf("%lld",&M); solve(N, M); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define P pair<ll,ll> #define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I) #define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I) #define TO(x,t,f) ((x)?(t):(f)) #define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9 #define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v x is sorted #define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v x is sorted #define NUM(x,v) (POSU(x,v)-POSL(x,v)) //x is sorted #define REV(x) (reverse(x.begin(),x.end())) //reverse ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);} ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*b);} #define NEXTP(x) next_permutation(x.begin(),x.end()) const ll INF=ll(1e16)+ll(7); const ll MOD=1000000007LL; #define out(a) cout<<fixed<<setprecision((a)) //tie(a,b,c) = make_tuple(10,9,87); #define pop_(a) __builtin_popcount((a)) ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;} template <typename T> class Seg_Tree{ public: // 0-index vector<T> dat; T initial,M; int n; T unite(T a,T b){// return max(a,b); } Seg_Tree(int n0_=1,T initial_=1,T M_=1){ initsize(n0_,initial_,M_); } void initsize(int n0,T initial_,T M_){ M = M_; initial = initial_; int k=1; while(1){ if(n0<=k){ n=k; dat.resize(2*n-1); for(int i=0;i<2*n-1;i++)dat[i]=initial; break; } k*=2; } } //i banme wo x nisuru void update(int i,T x){ i += n-1; dat[i] = x; while(i>0){ i = (i-1) / 2; dat[i] = unite(dat[i*2+1],dat[i*2+2]); } } //[a,b) T query0(int a,int b,int k,int l,int r){ if(r<=a || b<=l)return initial; if(a<=l && r<=b)return dat[k]; else{ T vl = query0(a,b,k*2+1,l,(l+r)/2); T vr = query0(a,b,k*2+2,(l+r)/2,r); return unite(vl,vr); } } //return [a,b) T query(int a,int b){ return query0(a,b,0,0,n); } }; int main() { ll ans = 0 , N; cin >> N; vector<ll> A(N),B(N); FOR(i,0,N){ cin >> A[i]; } B[0] = A[0]; FOR(i,1,N) { B[i] = B[i-1] + A[i]; } Seg_Tree<ll> sg(N,0,MOD); FOR(i,0,N){ sg.update(i,B[i]); } ll x = 0; FOR(i,0,N){ ans = max(ans,x+sg.query(0,i+1)); x += B[i]; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<long> vec(N); long max_distance = 0,now=0; long diff = 0,max_idx = 0; for(int i = 0;i<N;i++){ cin >> vec.at(i); diff += vec.at(i); now += diff; if(now >= max_distance){ max_distance = now; max_idx = i; } } long true_max = max_distance; if(max_idx != N-1){ for(int i = 0;i<max_idx+1;i++){ max_distance += vec.at(i); true_max = max(true_max,max_distance); } } else{ max_distance -= diff; for(int i = 0;i<max_idx;i++){ max_distance += vec.at(i); true_max = max(true_max,max_distance); } } cout << true_max << endl;; }
#include <iostream> #include <algorithm> #include <string> #include <cmath> #include <vector> #include <iomanip> #include <random> #include <climits> #include <set> #include <map> using namespace std; /* */ int main() { int n; cin >> n; int i = 1; int sum = 0; while (1) { sum += i; if (sum >= n) { cout << i << endl; break; } i++; } return 0; }
#pragma GCC optimize(2) #include<bits/stdc++.h> #define mp make_pair #define pb push_back #define ff first #define ss second using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pii> vii; ll n; int main() { cin>>n; n*=2LL; int ans=0; for(ll i=1LL;i*i<=n;i++) { if(n%i==0LL) { ll j=n/i; if((i%2LL)==(j%2LL)) continue; ans+=2; } } cout<<ans<<endl; return 0; }
#include"bits/stdc++.h" using namespace std; using ll=long long; template<class T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;} template<class T,class Size=typename vector<T>::size_type>inline auto vector_2d(Size h,Size w,T v){return vector<vector<T>>(h,vector<T>(w,v));} template<class RandomAccessIterator,class Pair=typename iterator_traits<RandomAccessIterator>::value_type>inline void sort_pairs_by_second(RandomAccessIterator first,RandomAccessIterator last){sort(first,last,[](const Pair&p1,const Pair&p2){return p1.second<p2.second||(p1.second==p2.second&&p1.first<p2.first);});} int main() { ll n=in(); map<ll,ll>cnt; for(ll i=0;i<n;++i){ ++cnt[in()]; } while(cnt.size()!=1){ cnt[cnt.rbegin()->first-cnt.begin()->first]+=cnt.rbegin()->second; //cnt.erase(cnt.rbegin()); cnt.erase(prev(cnt.end())); } cout<<cnt.begin()->first<<endl; }
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <functional> #include <cmath> #include <map> #define rep(i,n) for (int i=0;i<n;i++) #define DENOM 1000000007 using namespace std; using ll = long long; int main(){ string s ; cin >> s ; size_t n = s.size() ; size_t j ; for (j=0;j<n;++j) { if (s[j] == '.') break ; } cout << s.substr(0, j) << endl ; return 0 ; }
#include <cmath> #include<iostream> #include<vector> #include<algorithm> #include<functional> #include<queue> #include<set> #include<map> #include<bitset> #include<iomanip> #include<stack> #include<set> #include<string> #include<deque> using namespace std; typedef long long ll; typedef pair<ll, ll> P; ll mod = 1000000007; ll mod2 = 998244353; ll a[300005]; int main() { ll n; cin >> n; map<ll, ll>mp; for (int i = 0; i < n; i++) { cin >> a[i]; mp[a[i]]++; } ll ans = 0; for (int i = 0; i < n; i++) { mp[a[i]]--; ll cnt = n; cnt -= (i + 1); ans += (cnt - mp[a[i]]); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define int long long #define pb push_back #define vi vector<int> #define all(a) a.begin(), a.end() using namespace std; void solve() { int n; cin>>n; vi a(n); int ans=(n*(n-1))/2; for(int i=0;i<n;i++){ cin>>a[i]; } sort(all(a)); int cnt=1,val; for(int i=1;i<n;i++){ if(a[i]==a[i-1]){ cnt++; } else{ val=(cnt*(cnt-1))/2; ans=ans-val; cnt=1; } } if(cnt){ val=(cnt*(cnt-1))/2; ans=ans-val; } cout<<ans; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); }
#include<bits/stdc++.h> #define int long long using namespace std; signed main(){ string S; cin>>S; int ans=0; for(int i=0;i+3<S.size();i++)ans+=S.substr(i,4)=="ZONe"; cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = (int)(a); (i) < (int)(b); (i)++) #define rrep(i, a, b) for (int i = (int)(b) - 1; (i) >= (int)(a); (i)--) #define all(v) v.begin(), v.end() typedef long long ll; template <class T> using V = vector<T>; template <class T> using VV = vector<V<T>>; /* 提出時これをコメントアウトする */ #define LOCAL true #ifdef LOCAL #define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl #else #define dbg(x) true #endif int main() { ios::sync_with_stdio(false); cin.tie(nullptr); constexpr char endl = '\n'; string s; cin >> s; int ans = 0; rep(i,0,s.size() - 3) { if (s.substr(i,4) == "ZONe") ans++; } cout << ans << endl; 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>; using Graph = vector<vector<int>>; 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; } int main() { int a,b,c; cin >> a >> b >>c; if(c== 0){ cout << "=" << endl; return 0; } int R,L; if(c %2 == 0){ L = a; R = b; if(L<0)L = -L; if(R<0)R = -R; } else{ L = a; R = b; } if(L > R){ cout << ">" << endl; return 0; } if(L ==R){ cout << "=" << endl; return 0; } if(L < R){ cout << "<" << endl; return 0; } return 0; }
// ** Sumonta Saha Mridul ** SWE - SUST /* * ###### ## ## ## ## ####### ## ## ######## ### ! ## ## ## ## ### ### ## ## ### ## ## ## ## ? ## ## ## #### #### ## ## #### ## ## ## ## * ###### ## ## ## ### ## ## ## ## ## ## ## ## ## ! ## ## ## ## ## ## ## ## #### ## ######### ? ## ## ## ## ## ## ## ## ## ### ## ## ## * ###### ####### ## ## ####### ## ## ## ## ## */ #include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define pb push_back #define pii pair<int, int> #define pll pair<long, long> #define mp(a, b) make_pair(a, b) #define vi vector<int> #define vll vector<ll> #define vii vector<pii> #define Mi map<int, int> #define mii map<pii, int> #define all(a) (a).begin(), (a).end() #define f first #define se second #define lb lower_bound #define ub upper_bound #define sz(x) (int)x.size() #define endl '\n' #define Y cout << "YES\n" #define No cout << "NO\n" #define F(i, s, e) for (ll i = s; i < e; ++i) #define rep(i, a, b) for (int i = a; i < b; i++) #define rem(i, a, b) for (int i = a; i > b; i--) #define P(str) cout << str << endl #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) #define mod 1000000007 #define INF numeric_limits<ll>::max(); #define NINF numeric_limits<ll>::min(); const int N = int(1e5 + 3); ll power(ll base, ll powr) { ll res = 1; while (powr) { if (powr % 2 == 0) base *= base, powr /= 2; else res *= base, powr--; } return res; } int main() { fast; ll a, b, c; cin >> a >> b >> c; if (c % 2 == 0) a = abs(a), b = abs(b); if (a < b) cout << "<" << endl; else if (a > b) cout << ">" << endl; else cout << "=" << endl; }
#include<bits/stdc++.h> using namespace std; // Macros //#define int long long int #define lli long long int #define ulli unsigned long long int #define mods 1000000007 #define pb push_back #define ppb pop_back #define mp make_pair #define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) #define forLoop(i, a, b) for(int i=a; i<b; i++) #define endl "\n" #define all(x) (x).begin(),(x).end() #define mem0(a) memset(a,0,sizeof(a)) // Pre defined Variables as a constant const long long INF = 1e18; const int32_t M = 1e9 + 7; const int32_t MM = 998244353; // Functions int www(int x, int y) { if (x == 0) return 0; return ((x % y == 0) ? x / y : x / y + 1); } void for_cop() { lli s; cin >> s; lli tmp = 1; lli ans = 0; while (1) { lli tmp2 = stoll(to_string(tmp) + to_string(tmp)); tmp++; if (tmp2 > s) break; ans++; } cout << ans << endl; } // Main Code int32_t main() { fio; int t = 1; //cin >> t; while (t--) for_cop(); return 0; } // Ends Here
#include <bits/stdc++.h> using namespace std; const int N = 105; int n; char s[N][N]; vector<int> edges[N]; int cnt[N]; void bfs(int u) { queue<int> q; vector<bool> vis(n); q.push(u); vis[u] = true; while (q.size()) { int u = q.front(); q.pop(); for (int v: edges[u]) { if (vis[v]) continue; vis[v] = true; q.push(v); } } for (int u = 0; u < n; ++u) { if (vis[u]) ++cnt[u]; } } int solve() { scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%s", s[i]); for (int j = 0; j < n; ++j) { if (s[i][j] == '1') edges[i].push_back(j); } } for (int i = 0; i < n; ++i) bfs(i); double ans = 0; for (int i = 0; i < n; ++i) { ans += 1.0 / cnt[i]; } printf("%.15lf\n", ans); return 0; } int main() { int t = 1; // scanf("%d", &t); for (int tc = 0; tc < t; ++tc) { solve(); } return 0; }
#include<iostream> #include<string> #include<vector> #include<stack> #include<queue> #include<set> #include<map> #include<algorithm> #include<numeric> #include<cmath> #include<iomanip> #include<regex> using namespace std; #define int long long const int mod=1e9+7; int dp[101][100001]={}; signed main(){ int n,t[100]; cin>>n; int sum=0; for(int i=0;i<n;i++){ cin>>t[i]; sum+=t[i]; } dp[0][0]=1; for(int i=0;i<n;i++){ for(int j=0;j<=sum;j++){ dp[i+1][j]=dp[i][j]; if(j>=t[i]) dp[i+1][j]|=dp[i][j-t[i]]; } } int ans=sum; for(int i=0;i<=sum;i++) if(dp[n][i]) ans=min(ans,max(i,sum-i)); cout<<ans<<endl; }
#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto e : v) os << e << ' '; return os; } template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { for (auto e : v) os << e << ' '; return os; } template <typename T> ostream &operator<<(ostream &os, const multiset<T> &v) { for (auto e : v) os << e << ' '; return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp) { for (auto e : mp) os << e << ' '; return os; } template <typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } else return false; } template <typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } else return false; } inline bool in(int x, int y, int h, int w) { return 0 <= x && x < h && 0 <= y && y < w; } inline void print() { cout << '\n'; } template <typename T1, typename... T2> void print(const T1 a, const T2 &... b) { cout << a << ' '; print(b...); } //#define DEBUG #ifdef DEBUG inline void debug_print() { cerr << endl; } template <typename T1, typename... T2> void debug_print(const T1 a, const T2 &... b) { cerr << a << ' '; debug_print(b...); } #define debug(...) cerr << __LINE__ << ": [" << #__VA_ARGS__ << "] = " , debug_print(__VA_ARGS__); #else #define debug(...) true #endif const int INF = (1<<30)-1; const long long LINF = 1LL<<60; const double EPS = 1e-9; const int MOD = 1000000007; //const int MOD = 998244353; const int dx[8] = {-1,0,1,0,1,-1,1,-1}; const int dy[8] = {0,1,0,-1,1,-1,-1,1}; //-------------------------- Libraries --------------------------// //--------------------------- Solver ----------------------------// void solve() { int N; cin >> N; vector<int> a(N); for (int i = 0; i < N; i++) cin >> a[i]; set<int> se; se.insert(a[0]); se.insert(-a[0]); for (int i = 1; i < N; i++) { set<int> tmp; for (auto &&e : se) { tmp.insert(e+a[i]); tmp.insert(e-a[i]); } se = tmp; } int d = INF; for (auto &&e : se) chmin(d, abs(e)); int sum = 0; for (int i = 0; i < N; i++) { sum += a[i]; } int ans = (sum+d)/2; cout << ans << '\n'; } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(20); int t = 1; //cin >> t; while (t--) solve(); return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=55e4; int n,K,mo,i,j,ff[N*2],*f=ff+N,S; inline void red(int&x){x+=x>>31&mo;} inline void ins(int x){ if(x>0)for(j=-S;j<=S;++j)red(f[j]+=f[j-x]-mo); else for(j=S;j>=-S;--j)red(f[j]+=f[j-x]-mo); if(x>0)for(j=S;j>=-S;--j)red(f[j]-=f[j-x*(K+1)]); else for(j=-S;j<=S;++j)red(f[j]-=f[j-x*(K+1)]); } inline void del(int x){ for(j=S;j>=-S;--j)red(f[j]-=f[j-x]); for(j=-S;j<=S;++j)red(f[j]+=f[j-x*(K+1)]-mo); } int main(){ scanf("%d%d%d",&n,&K,&mo); for(i=1;i<=n;++i)S+=i*K;*f=1; for(i=2;i<=n;++i)ins(i-1); for(i=1;i<=n;++i){ if(i>1)ins(1-i); j=(1ll**f*(K+1)+mo-1)%mo;printf("%d\n",j); if(i<n)del(n-i); } }
#include<bits/stdc++.h> using namespace std; int n,k,p,f[2][300005]; int mod(int x){return x>=p?x-p:x;} int solve(int x) { memset(f,0,sizeof(f)); f[0][150001]=1; for(register int i=1;i<=n;++i) { if(i>x) { for(int j=1;j<=300001;j++) { f[i&1][j]=f[(i-1)&1][j]; if(j-i+x>0&&j-i+x<=300001)f[i&1][j]=mod(f[i&1][j]+f[i&1][j-i+x]); if(j-(k+1)*(i-x)>0&&j-(k+1)*(i-x)<=300001)f[i&1][j]=mod(f[i&1][j]-f[(i-1)&1][j-(k+1)*(i-x)]+p); } } else if(i<x) { for(int j=300001;j>=1;j--) { f[i&1][j]=f[(i-1)&1][j]; if(j-i+x>0&&j-i+x<=300001)f[i&1][j]=mod(f[i&1][j]+f[i&1][j-i+x]); if(j-(k+1)*(i-x)>0&&j-(k+1)*(i-x)<=300001)f[i&1][j]=mod(f[i&1][j]-f[(i-1)&1][j-(k+1)*(i-x)]+p); } } else { for(int j=1;j<=300001;j++) if(f[(i-1)&1][j])f[i&1][j]=1ll*(k+1)*f[(i-1)&1][j]%p; } } return mod(f[n&1][150001]-1+p); } int ans[105]; signed main() { //freopen("dd.out","w",stdout); scanf("%d%d%d",&n,&k,&p); for(int i=1;i<=(n+1)/2;i++)ans[i]=solve(i),cout<<ans[i]<<endl; for(int i=(n+1)/2+1;i<=n;i++)ans[i]=ans[n+1-i],cout<<ans[i]<<endl; return 0; }
#include<bits/stdc++.h> #define fo(i,a,b) for(int i=(a);i<=(b);++i) #define fd(i,a,b) for(int i=(a);i>=(b);--i) #define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0) using namespace std; typedef long long ll; const ll mod = 998244353; const int maxn = 5e3 + 5; int n, m, k; ll a[maxn][maxn], dp[maxn][maxn]; ll power(ll a, ll b) { ll ans = 1; while (b) { if (b & 1)ans = (ans * a) % mod; a = a * a % mod; b >>= 1; } return ans; } int main() { IOS; cin >> n >> m >> k; fo(i, 1, k) { int x, y; char z; cin >> x >> y >> z; a[x][y] = z; } dp[1][1] = 1; fo(i, 1, n* m - k)dp[1][1] = 3ll * dp[1][1] % mod; ll inv3 = power(3, mod - 2); fo(i, 1, n)fo(j, 1, m) { dp[i][j] %= mod; if (a[i][j] == 'X') { dp[i + 1][j] += dp[i][j]; dp[i][j + 1] += dp[i][j]; } else if (a[i][j] == 'R') { dp[i][j + 1] += dp[i][j]; } else if (a[i][j] == 'D') { dp[i + 1][j] += dp[i][j]; } else { dp[i + 1][j] += 2ll * inv3 * dp[i][j]; dp[i][j + 1] += 2ll * inv3 * dp[i][j]; } } cout << dp[n][m] << endl; return 0; } /* */
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; const int maxn = 2e5 + 50; int n,x1[maxn],x2[maxn]; long long f[2][2]; struct node{ int x,c; bool operator < (node p){ return c < p.c; } }a[maxn]; int read(){ int x = 0,f = 1; char c = getchar(); while(c < '0' || c > '9'){ if(c == '-') f = -1; c = getchar(); } while(c >= '0' && c <= '9') x = x * 10 + (c ^ 48),c = getchar(); return x * f; } inline long long dis(int x,int a,int b){ return 0ll + abs(x - a) + abs(a - b); } int main(){ n = read(); for(int i = 1; i <= n; i ++) a[i].x = read(),a[i].c = read(); sort(a + 1,a + n + 1); int cnt = 0,p = 1; while(p <= n){ cnt ++,x1[cnt] = x2[cnt] = a[p].x; while(p < n && a[p].c == a[p + 1].c) p ++,x1[cnt] = min(x1[cnt],a[p].x),x2[cnt] = max(x2[cnt],a[p].x); p ++; } cnt ++,x1[cnt] = x2[cnt] = 0; // for(int i = 1; i <= cnt; i ++) cout << i << ' ' << x1[i] << ' ' << x2[i] << endl; int cur = 0; for(int i = 1; i <= cnt; i ++){ cur ^= 1; f[cur][0] = min(f[cur ^ 1][0] + dis(x1[i - 1],x2[i],x1[i]),f[cur ^ 1][1] + dis(x2[i - 1],x2[i],x1[i])); f[cur][1] = min(f[cur ^ 1][0] + dis(x1[i - 1],x1[i],x2[i]),f[cur ^ 1][1] + dis(x2[i - 1],x1[i],x2[i])); // cout << i << ' ' << f[cur][0] << ' ' << f[cur][1] << endl; } printf("%lld\n",min(f[cur][0],f[cur][1])); return 0; }
#include<bits/stdc++.h> using namespace std; const int M=505; int n,m,lsum[M][M],rsum[M][M]; char mp[M][M]; int main() { scanf("%d%d",&n,&m); for(int i=1; i<=n; ++i) scanf("%s",mp[i]+1); for(int i=1; i<=n; ++i) for(int j=1; j<=m; ++j) { lsum[i][j]=lsum[i][j-1]+lsum[i-1][j]-lsum[i-1][j-1]; rsum[i][j]=rsum[i-1][j]+rsum[i][j-1]-rsum[i-1][j-1]; if(mp[i][j]=='.') { if(mp[i][j-1]=='.') lsum[i][j]++; if(mp[i-1][j]=='.') rsum[i][j]++; } } int q=1,x1=1,x2=n,y1=1,y2=m; while(q--) { int l=lsum[x2][y2]+lsum[x1-1][y1-1]-lsum[x1-1][y2]-lsum[x2][y1-1]; int r=rsum[x2][y2]+rsum[x1-1][y1-1]-rsum[x1-1][y2]-rsum[x2][y1-1]; for(int i=y1; i<=y2; ++i) if(mp[x1][i]=='.'&&mp[x1-1][i]=='.') --l; for(int i=x1; i<=x2; ++i) if(mp[i][y1]=='.'&&mp[i][y1-1]=='.') --r; printf("%d\n",l+r); } return 0; }
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { char X[110][110]={}; int ans =0,H,W; cin>>H>>W; for(int i=0;i<H;i++){ string S; cin>>S; for(int j=0;j<W;j++){ X[i][j]=S[j]; } } for(int i=0;i<H;i++){ for(int j=0;j<W;j++){ if(X[i][j]=='#')continue; if(X[i+1][j]=='.')ans++; if(X[i][j+1]=='.')ans++; } } cout<<ans<<endl; return 0; }