code_file1
stringlengths
87
4k
code_file2
stringlengths
85
4k
#include <bits/stdc++.h> using namespace std; using ll = long long; using lb = long double; #define fi first #define se second #define pb push_back ll times_cap(ll a, ll b) { if (log10(a) + log10(b) >= 17.0)return 1e17; else return a * b; } typedef pair<int64_t, int64_t> P; int main(){ ll x,y; cin>>x>>y; if(x>=y){ cout<<x-y<<endl; return 0; } map<ll,ll> dis; priority_queue<P,vector<P>,greater<P>> pq; pq.push({0,y}); ll ans=y-x; dis[x]=ans; ll A=1,D=1; while(!pq.empty()){ auto tmp=pq.top(); pq.pop(); ll v=tmp.second,cst=tmp.first; dis[x]=min(cst+abs(v-x),dis[x]); ans=min(dis[x],ans); if(cst>dis[v])continue; if(cst>ans)continue; if(v==x){ ans=min(ans,cst); continue; } if(v<=x){ ans=min(ans,cst+x-v); continue; } if(v%2==0){ if(dis[v/2]==0||dis[v/2]>dis[v]+1){ dis[v/2]=cst+1; pq.push({dis[v/2],v/2}); } /*if(dis[v+1]==0||dis[v+1]>dis[v]+1){ dis[v+1]=cst+1; pq.push({dis[v+1],v+1}); }*/ /*if(dis[v-1]==0||dis[v-1]>dis[v]+1){ dis[v-1]=cst+1; pq.push({dis[v-1],v-1}); }*/ } else{ if(dis[v+1]==0||dis[v+1]>dis[v]+1){ dis[v+1]=cst+1; pq.push({dis[v+1],v+1}); } if(dis[v-1]==0||dis[v-1]>dis[v]+1){ dis[v-1]=cst+1; pq.push({dis[v-1],v-1}); } } } cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main () { int a, b; cin >> a >> b; ll K; cin >> K; ll cmp[63][63]; for (int i = 0; i <= 60; i ++) { cmp[i][0] = cmp[i][i] = 1; for (int j = 1; j < i; j ++) { cmp[i][j] = cmp[i - 1][j] + cmp[i - 1][j - 1]; } } int s = a + b; for (int i = 0; i < s; i ++) { if (a == 0) { cout << 'b'; b --; } else if (b == 0) { cout << 'a'; a --; } else { if (K <= cmp[a + b - 1][a - 1]) { cout << 'a'; a --; } else { cout << 'b'; K -= cmp[a + b - 1][a - 1]; b --; } } } cout << endl; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #define int long long #define ll long long #define F(type, i, a, b, incr) for (type i = a; i <= (type)(b); i += (type)(incr)) #define RF(type, i, a, b, decr) for (type i = a; i >= (type)(b); i -= (type)(decr)) #define sz(a) sizeof(a) #define deb(a) cerr << " [" << #a << "->" << a << "] " #define next_line cerr << '\n' #define all(a) a.begin(), a.end() #define iter(it, s) for (auto it = s.begin(); it != s.end(); it++) #define setbits(x) __builtin_popcountll(x) using namespace __gnu_pbds; using namespace std; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; typedef pair<int, int> pii; typedef pair<ll,ll> pll; /* 1. If you cannot approach a problem directly in the way it is proposed then try to think from backwards 2. Have you checked the implementation before starting to write the code? 3. Have you read the question carefully ? 4. Keep the names of variable descriptive. 5. Check the types and range of the values properly 6. Erase a iterator in the set or map only after using its value. 7. 1 bitset of 1e9 size only takes 256 mb. 8. Try to use global variables in case of recursion 9. Short and precise exectutes faster */ void solve() { int n,s,d; cin >>n >> s >> d; F(int, i, 0, n - 1,1 ){ int x, y; cin >> x >> y; if((x < s) && (y > d)){ cout << "Yes\n"; return; } } cout <<"No\n"; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // freopen("Debug.txt", "w", stderr); #else #endif // cout << fixed << setprecision(10); // int _t; // cin>>_t; // while(_t --) solve(); }
/* -> Bismillahir Rahmanir Rahim <- */ #include <bits/stdc++.h> using namespace std; //Some Hints //Find odd and even return 1 || 0 // __builtin_parity() if x is ll use __builtin_parityll(x) #define gcd(a, b) __gcd(a, b) #define lcm(a, b) (a * (b / gcd(a, b))) // count how many 0 in a bynary number #define NumOf0(x) __builtin_popcount(x) // count how many 1 in a bynary number #define NumOf1(x) __builtin_ctz(x) #define pi acos(-1) typedef long long ll; typedef unsigned long long ull; typedef unsigned un; #define Bismilla \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) bool isPrime(int n) { if (n < 2) { return false; } if (n == 2 || n == 3) { return true; } if (n % 2 == 0) { return false; } for (ll i = 3; i * i <= n; i += 2) { if (n % i == 0) { return false; } } return true; } #define pb push_back #define vi vector<int> #define vl vector<ll> #define In insert #define mini(a, b) a = min(a, (b)) #define maxi(a, b) a = max(a, (b)) #define si(a) scanf("%d", &a) #define si2(a, b) scanf("%d %d", &a, &b) #define si3(a, b, c) scanf("%d %d %d", &a, &b, &c) #define sl(a) scanf("%lld", &a) #define sl2(a, b) scanf("%lld %lld", &a, &b) #define sl3(a, b, c) scanf("%lld %lld %lld", &a, &b, &c) #define ln "\n" #define pf printf #define endl "\n" #define pfi(a) printf("%d\n", a) #define pf2(a, b) printf("%d %d\n", a, b) // Now Start.....:) void solve() { ll n, m, k, q, l, r, x, y, z; cin >> x >> y >> z; bool ok=false; for (int i = 0; i < x; i++) { cin>>n>>m; if(n<y and m>z){ ok = true; } } cout<<((ok)?"Yes":"No")<<ln; } int main() { Bismilla; solve(); }
#include <bits/stdc++.h> #define DEBUG if(0) #define lli __int128 #define ldouble long double using namespace std; /* (2x + 2y)n + x <= t < (2x + 2y)n + x + y range = y (max 500) (p + q)n + p <= t < (p + q)(n + 1) range = q (max 500) try all combinations of mod (500^2) t - (2x + 2y)n - x == remY t - (2x + 2y)n = remY + x t = remY + x + (2x + 2y)n1 t - (p + q)n - p == remQ t - (p + q)n = remQ + p t = remQ + p + (p + q)n2 remQ + p + (p + q)n2 = remY + x + (2x + 2y)n1 (p + q)n2 - (2x + 2y)n1 = remY + x - remQ - p */ lli read() { lli x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } void print(lli x) { if (x < 0) { putchar('-'); x = -x; } if (x > 9) print(x / 10); putchar(x % 10 + '0'); } lli abslol(lli num) { return num < 0 ? -num : num; } lli gcd(lli a, lli b, lli& x, lli& y) { if (b == 0) { x = 1; y = 0; return a; } lli x1, y1; lli d = gcd(b, a % b, x1, y1); x = y1; y = x1 - y1 * (a / b); return d; } bool find_any_solution(lli a, lli b, lli c, lli &x0, lli &y0, lli &g) { g = gcd(abslol(a), abslol(b), x0, y0); if (c % g) { return false; } x0 *= c / g; y0 *= c / g; if (a < 0) x0 = -x0; if (b < 0) y0 = -y0; return true; } const lli inf = LONG_LONG_MAX; lli x, y, p, q; lli findMinSolution(lli remY, lli remQ) { // t - (2x + 2y)n - x == remY // t - (2x + 2y)n = remY + x // t = remY + x + (2x + 2y)x0 // t - (p + q)n - p == remQ // t - (p + q)n = remQ + p // t = remQ + p + (p + q)y0 // remQ + p + (p + q)y0 = remY + x + (2x + 2y)x0 // -(2x + 2y)x0 + (p + q)y0 = remY + x - remQ - p lli x0, y0, g; lli a = -(2*x + 2*y), b = p + q, c = remY + x - remQ - p; if (find_any_solution(a, b, c, x0, y0, g)) { lli t1 = remY + x + (2*x + 2*y)*x0, t2 = remQ + p + (p + q)*y0; bool isNegative = a / g < 0; // lli lo = 0, hi = 1e18; // while (lo < hi) // { // lli mid = (lo + hi + 1) >> 1; // if ((y0 + mid*(a / g)) != 0 && LONG_LONG_MAX / abslol(y0 + mid*(a / g)) < (p + q)) // hi = mid - 1; // else // lo = mid; // } // lli maxHi = lo; // lo = -1e18, hi = 0; // while (lo < hi) // { // lli mid = (lo + hi) >> 1; // if ((y0 + mid*(a / g)) != 0 && LONG_LONG_MAX / abslol(y0 + mid*(a / g)) < (p + q)) // lo = mid + 1; // else // hi = mid; // } // lli minLo = lo; lli lo = -1e18, hi = 1e18; while (lo < hi) { lli mid = (lo + hi + isNegative) >> 1; lli e = remQ + p + (p + q)*(y0 + mid*(a / g)); // DEBUG printf("\t\t%lld %lld\n", mid, e); if (isNegative) { if (e >= 0) lo = mid; else hi = mid - 1; } else { if (e >= 0) hi = mid; else lo = mid + 1; } } x0 -= lo * b / g; y0 += lo * a / g; // DEBUG printf("\t%lld %lld - %lld %lld | %lld %lld\n", remY, remQ, t1, t2, 0LL, b / g); return remQ + p + (p + q)*y0; } else return inf; } int main() { int t; scanf("%d", &t); for (int tt = 1; tt <= t; tt++) { // scanf("%lld %lld %lld %lld", &x, &y, &p, &q); x = read(); y = read(); p = read(); q = read(); lli ans = inf; for (int i = 0; i < y; i++) for (int j = 0; j < q; j++) ans = min(ans, findMinSolution(i, j)); if (ans == inf) printf("infinity\n"); else { print(ans); printf("\n"); } } return 0; }
#include<iostream> #include<utility> using namespace std; typedef long long ll; int T; ll X,Y,Q,P; ll A,B,ans; ll ext_gcd(ll p,ll q,ll& x, ll& y) { // get px+qy=gcd(p,q) if(q==0) return x=1,y=0,p; ll g=ext_gcd(q,p%q,y,x); y-=p/q*x; return g; } pair<ll,ll> crt(ll a1,ll mo1,ll a2,ll mo2) { // return (x,y) y=lcm(a1,a2),x%mo1=a1,x%mo2=a2 ll g,x,y,z; g=ext_gcd(mo1,mo2,x,y); a1=(a1%mo1+mo1)%mo1;a2=(a2%mo2+mo2)%mo2; if(a1%g != a2%g) return pair<ll,ll>(-1,0); // N/A __int128_t lcm=mo1*(mo2/g); if(lcm<mo1) return pair<ll,ll>(-2,0); // overflow __int128_t v=a1+((a2-a1)%lcm+lcm)*x%lcm*(mo1/g); return make_pair(((v%lcm)+lcm) % lcm,lcm); } int main(){ cin>>T; while(T--){ ans=1LL<<60; cin>>X>>Y>>P>>Q; for(int i=X;i<X+Y;i++){ ll tmp=crt(i,2*(X+Y),P,P+Q).first; if(tmp>=0){ if(ans>tmp) ans=tmp; } } for(int i=P;i<P+Q;i++){ ll tmp=crt(i,P+Q,X,2*(X+Y)).first; if(tmp>=0){ if(ans>tmp) ans=tmp; } } if(ans==1LL<<60) cout<<"infinity"<<endl; else cout<<ans<<endl; } }
#include <iostream> #include <vector> #include <queue> #include <map> #include <set> #include <string> #include <algorithm> #include <cmath> using namespace std; using ll = long long; using P = pair<ll, ll>; #define rep(i, n) for (ll i = 0; i < (n); i++) #define rep2(i, s, n) for (ll i = s; i < (n); i++) const ll MOD = 998244353; ll modPow(ll a, ll n){ if (n == 0) return 1; if (n == 1) return a % MOD; if (n % 2 == 1) return (a * modPow(a, n-1)) % MOD; ll t = modPow(a, n/2); return (t * t) % MOD; } int main(){ ll n; cin >> n; vector<ll> f(n); rep(i, n){ cin >> f[i]; f[i]--; } ll num = 0; vector<bool> flag(n, false); rep(i, n){ if (flag[i]) continue; multiset<ll> st; ll now = i; st.insert(now); rep(j, n){ flag[now] = true; now = f[now]; st.insert(now); if (flag[now]) break; } if (st.count(now) == 2) num++; } cout << modPow(2, num)-1 << endl;; return 0; }
#include <bits/stdc++.h> #include <cassert> #define rep(i, N) for (int i = 0; i < (N); ++i) #define rep2(i, a, b) for (ll i = a; i <= b; ++i) #define rep3(i, a, b) for (ll i = a; i >= b; --i) #define pb push_back #define eb emplace_back #define fi first #define se second #define nl '\n' #define endl '\n' #define all(c) begin(c), end(c) #define ok() puts(ok ? "Yes" : "No"); #define pcnt(x) __builtin_popcountll(x) #define df(x) ll x = in(); template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } using namespace std; using ll = long long; using vi = vector<int>; using vll = vector<ll>; using vvll = vector<vll>; using ii = pair<int, int>; using vvi = vector<vi>; using vii = vector<ii>; using vs = vector<string>; using P = pair<ll, ll>; using gt = greater<P>; using minq = priority_queue<P, vector<P>, gt>; using vP = vector<P>; inline ll in() { ll x; scanf("%lld", &x); return x; } template <class T> void takeUnique(vector<T> &v) { auto last = std::unique(v.begin(), v.end()); v.erase(last, v.end()); } template <class T> void print(const initializer_list<T> &il) { for (auto x : il) { cout << x << " "; } cout << "\n"; } inline void priv(vll a) { rep(i, (int)a.size() - 1) cout << a[i] << " "; cout << a.back() << nl; } inline void priv(vi a) { rep(i, (int)a.size() - 1) cout << a[i] << " "; cout << a.back() << nl; } const ll LINF = 8e18L + 1; const int INF = 8e9 + 1; int dx[] = {0, 1, 0, -1}; int dy[] = {1, 0, -1, 0}; int dxx[] = {0, 1, 1, 1, 0, -1, -1, -1}; int dyy[] = {1, 1, 0, -1, -1, -1, 0, 1}; // g++ -std=c++17 -stdlib=libc++ #define _GLIBCXX_DEBUG // This slows down the execution; even the time complexity, since it checks if // std funcs such as lower_bound meets prereqs int mod = 1e9 + 7; int n, p; ll f(ll nn) { if (nn == 0) return 1; ll ret = f(nn / 2); (ret *= ret) %= mod; if (nn & 1) (ret *= (p - 2)) %= mod; return ret; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout << fixed << setprecision(16); cin >> n >> p; ll ans = p - 1; ans *= f(n - 1); cout << ans % mod << nl; return 0; }
#include <iostream> #include <string> #include <algorithm> using namespace std; // string N; int main() { int x = 0; cin >> x; if (x < 0) { cout << 0; } else { cout << x; } //int k = N.length(); //const char* N_ch = N.c_str(); //int mod0 = 0; //int mod1 = 0; //int mod2 = 0; //for (int i = 0; i < k; i++) { // int num = (int)N_ch[i] - '0'; // if (num % 3 == 0)mod0++; // else if (num % 3 == 1)mod1++; // else if (num % 3 == 2)mod2++; //} //if ((mod2 < 3 && mod1 == 0 && mod0 == 0) || (mod2 == 0 && mod1 < 3 && mod0 == 0))cout << -1; //else { // if ((mod1 * 1 + mod2 * 2) % 3 == 2)cout << 2; // else if ((mod1 * 1 + mod2 * 2) % 3 == 1)cout << 1; //} }
#include <iostream> //#include <string> //#include <algorithm> using namespace std; int main() { int X; cin >> X; cout << 100 - X%100; }
#include <iostream> #include <string> #include <vector> #include <deque> #include <queue> #include <algorithm> #include <iomanip> #include <set> #include <map> #include <bitset> #include <cmath> #include <functional> using namespace std; #define REP(i,n) for(ll (i) = (0);(i) < (n);++i) #define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i) #define SHOW1d(v,n) {REP(W,n)cerr << v[W] << ' ';cerr << endl << endl;} #define SHOW2d(v,i,j) {REP(aaa,i){REP(bbb,j)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;} #define PB push_back #define EB emplace_back #define MP make_pair #define FI first #define SE second #define ALL(v) v.begin(),v.end() #define Decimal fixed<<setprecision(20) #define INF 1000000000 #define LLINF 1000000000000000000LL #define MOD 1000000007LL typedef long long ll; typedef pair<ll,ll> P; template<typename T> void show_vector(vector<T> v) { for (auto ele: v)cout << ele << " " ;cout << endl; } template<typename T> void show_vector(vector<vector<T>> v) { for (auto ele: v)show_vector(ele); } template<typename T> void show_vector(vector<vector<vector<T>>> v) { for (auto ele: v) { show_vector(ele); cout << endl; } } int main(){ cin.tie(0);cout.tie(0);ios::sync_with_stdio(false); vector<ll> fib(88); fib[0] = 0; fib[1] = 1; for (ll i = 2;i < fib.size();i++) { fib[i] = fib[i-1] + fib[i-2]; } ll n;cin >> n; vector<ll> v(2); vector<ll> ans; REP(i, fib.size() - 1) { if (n >= fib[fib.size() - 1 - i]) { n -= fib[fib.size() - 1 - i]; v[i%2]++; ans.PB(i % 2); } v[(i+1)%2] += v[i%2]; ans.PB(2 + (1 - (i % 2))); //cout << v[0] << " " << v[1] << endl; } cout << ans.size() << endl; REP(i, ans.size()) { cout << ans[i]+1 << endl; } // cout << "ans: " << v[0] << endl; return 0; }
#include <bits/stdc++.h> #include <cstdlib> #include <pthread.h> #include <sstream> #include <string> using namespace std; #define mem1(a) memset(a,-1,sizeof(a)) #define mem0(a) memset(a,0,sizeof(a)) #define ln "\n" #define ll long long int #define Mod 1000000007 #define lld long double template<typename T_vector> void output_vector(const T_vector &v, bool add_one = false, int start = -1, int end = -1) { if (start < 0) start = 0; if (end < 0) end = int(v.size()); for (int i = start; i < end; i++) cout << v[i] + (add_one ? 1 : 0) << (i < end - 1 ? ' ' : '\n'); } ll sttoll(string s) { stringstream hel(s); ll x = 0; hel >> x; return x; } string lltostr(ll x) { string s; s = to_string(x); return s; } void solve(int tc) { ll n, k; cin >> n >> k; ll b = n; while (k > 0) { if (b % 200 == 0) b /= 200; else { string t = lltostr(b); t += "200"; b = sttoll(t); } k--; } cout << b << ln; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout << setprecision(15) << fixed; ll t = 1; // cin >> t; for (ll i = 0; i < t; i++) { solve(i); } return 0; }
#include <bits/stdc++.h> #define MAX 50 #define SQRDMAX 2500 #define K 1 using namespace std; int si, sj, tiles[SQRDMAX], weights[SQRDMAX]; list<tuple<int, int>> path; bitset<SQRDMAX> visited; const int directions[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; void setTile(int i, int j) { visited.flip(i * MAX + j); for (const int* dir : directions) { int i_ = i + dir[0]; int j_ = j + dir[1]; int cell; cell = i_ * MAX + j_; if (0 <= i_ && i_ < MAX && 0 <= j_ && j_ < MAX && tiles[cell] == tiles[i * MAX + j]) { visited.flip(cell); break; } } } tuple<int, list<tuple<int, int>>> dfs(int i, int j) { priority_queue<tuple<int, int, int>> q; //get valid adj for (const int* dir : directions) { int i_ = i + dir[0]; int j_ = j + dir[1]; int cell; cell = i_ * MAX + j_; if (0 <= i_ && i_ < MAX && 0 <= j_ && j_ < MAX && tiles[cell] != tiles[i * MAX + j] && !visited.test(cell)) { q.push(make_tuple(weights[i_ * MAX + j_], i_, j_)); } } //dfs int bestPathWeight = 0; list<tuple<int, int>> bestPath; //get k best choices for (int k = 0; k < K && !q.empty(); ++k) { int weight, i_, j_; tie(weight, i_, j_) = q.top(); q.pop(); setTile(i_, j_); // cout<<visited.count()<<endl; int pathWeight; list<tuple<int, int>> path; tie(pathWeight, path) = dfs(i_, j_); setTile(i_, j_); if (weight + pathWeight > bestPathWeight) { bestPathWeight = weight + pathWeight; bestPath = path; } // cout<<visited.count()<<endl; } bestPath.push_front(make_tuple(i, j)); return make_tuple(weights[i * MAX + j] + bestPathWeight, bestPath); } int main(void) { scanf("%d%d", &si, &sj); for (int i = 0; i < SQRDMAX; ++i) scanf("%d", &tiles[i]); for (int i = 0; i < SQRDMAX; ++i) scanf("%d", &weights[i]); setTile(si, sj); int pathWeight; list<tuple<int, int>> path; tie(pathWeight, path) = dfs(si, sj); setTile(si, sj); tuple<int, int> prev = make_tuple(si, sj); string res = ""; for (const tuple<int, int>& t : path) { int i, j, i_, j_; tie(i, j) = t; tie(i_, j_) = prev; // if (abs(i - i_) > 1 || abs(j - j_) > 1 || visited.test(i * MAX + j)) // cout<<"Error"<<endl; if (i > i_) res += "D"; else if (i < i_) res += "U"; else if (j < j_) res += "L"; else if (j > j_) res += "R"; setTile(i, j); prev = t; // cout<<i<<" "<<j<<endl; } cout<<res<<endl; return 0; }
#include <bits/stdc++.h> int ri() { int n; scanf("%d", &n); return n; } int main() { int n = ri(); int a[n]; for (auto &i : a) i = ri(); int res = 2000000000; for (int i = 0; i < 1 << (n - 1); i++) { int xored = 0; int ored = 0; for (int j = 0; j <= n; j++) { if (j < n) ored |= a[j]; if (j == n || (i >> j & 1)) xored ^= ored, ored = 0; } res = std::min(res, xored); } printf("%d\n", res); return 0; }
#include"bits/stdc++.h" #define rep(i,n) for(ll i=0;i<n;++i) #define ALL(x) x.begin(),x.end() #define BACK(x) x.rbegin(),x.rend() #define MOD 1000000007 #define INF INT_MAX #define FLOAT_ANS setprecision(30) #define elif else if using namespace std; typedef long long ll; typedef unsigned long long ull; int main(void){ string s; cin>>s; rep(i,s.length()){ if(i%2){ if(s[i]>'Z'){ cout<<"No"; return 0; } } else{ if(s[i]<'a'){ cout<<"No"; return 0; } } } cout<<"Yes"; } /* */
#include <iostream> #include <iomanip> #include <string> #include <vector> #include <algorithm> #include <utility> #include <functional> #include <set> #include <map> #include <queue> #include <deque> #include <bitset> #include <math.h> #include <random> #include <chrono> #include <assert.h> #include <climits> using namespace std; #define int long long signed main() { int n; cin >> n; int sum = 0; for (int i = 1;; i++) { sum += i; if (sum >= n) { cout << i << '\n'; return 0; } } }
#include <bits/stdc++.h> #define PI 3.14159265358979323846 #define MAXINF (1e18L) #define INF (1e9L) #define EPS (1e-9) #define MOD ((ll)(1e9+7)) #define REP(i, n) for(int i=0;i<int(n);++i) #define REPA(x, v) for(auto&& x:v) #define Rep(i,sta,n) for(int i=sta;i<n;i++) #define RREP(i, n) for(int i=int(n)-1;i>=0;--i) #define ALL(v) v.begin(),v.end() #define FIND(v,x) (binary_search(ALL(v),(x))) #define SORT(v) sort(ALL(v)) #define RSORT(v) sort(v.rbegin(),v.rend()) #define DEBUG(x) cerr<<#x<<": "<<x<<endl; #define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl #define Yes(n) cout<<((n)?"Yes":"No")<<endl #define YES(n) cout<<((n)?"YES":"NO")<<endl #define pb push_back #define fi first #define se second using namespace std; template<class A>void pr(A a){cout << (a) << endl;} template<class A,class B>void pr(A a,B b){cout << a << " " ;pr(b);} template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);} template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);} template<class T> void pr_vec(vector<T> &v, char ep=' '){int n=v.size();REP(ni,n){cout<<v[ni];if(ni!=n-1)cout<<ep;}cout<<endl;}; template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;} template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;} typedef long long ll; typedef pair<int, int> pii; typedef pair<ll,ll> pll; int main(void) { int N,X; cin >> N >> X; string S; cin >> S; REP(i, N){ if(S[i] == 'o') X++; else X = max(0, X-1); } pr(X); }
#include <iostream> #include <fstream> #include <vector> #include <algorithm> #include <stack> #include <cassert> #include <map> #include <numeric> #include <cstring> #include <set> #include <ctime> #include <queue> #include <cmath> #include <iomanip> #include <iterator> #include <bitset> #include <unordered_set> using namespace std; clock_t timeStart, timeFinish; void timeBegin() { timeStart = clock(); } void timeEnd() { timeFinish = clock(); } void timeDuration() { double time_taken = double(timeFinish - timeStart) / double(CLOCKS_PER_SEC); cout << "Time taken by program is : " << fixed << time_taken << setprecision(5); cout << " sec " << endl; } class InputReader { public: InputReader() { input_file = stdin; cursor = 0; fread(buffer, SIZE, 1, input_file); } InputReader(const char *file_name) { input_file = fopen(file_name, "r"); cursor = 0; fread(buffer, SIZE, 1, input_file); } inline InputReader &operator >>(int &n) { while((buffer[cursor] < '0' || buffer[cursor] > '9') && buffer[cursor] != '-') { advance(); } int sign = 1; if (buffer[cursor] == '-') { sign = -1; advance(); } n = 0; while('0' <= buffer[cursor] && buffer[cursor] <= '9') { n = n * 10 + buffer[cursor] - '0'; advance(); } n *= sign; return *this; } inline InputReader &operator >>(long long &n) { while((buffer[cursor] < '0' || buffer[cursor] > '9') && buffer[cursor] != '-') { advance(); } int sign = 1; if (buffer[cursor] == '-') { sign = -1; advance(); } n = 0; while('0' <= buffer[cursor] && buffer[cursor] <= '9') { n = n * 10 + buffer[cursor] - '0'; advance(); } n *= sign; return *this; } private: FILE *input_file; static const int SIZE = 1 << 17; int cursor; char buffer[SIZE]; inline void advance() { ++ cursor; if(cursor == SIZE) { cursor = 0; fread(buffer, SIZE, 1, input_file); } } }; const int MAXN = 1000; const int MOD = 1000000007; int dp[1 + MAXN][2]; int main() { //timeBegin(); //ifstream cin("input.txt"); //ofstream cout("papagali.out"); int n; char aa, ab, ba, bb; cin >> n >> aa >> ab >> ba >> bb; if (n <= 3) { cout << "1\n"; return 0; } if ((ab == 'A' && aa == 'A') || (ab == 'B' && bb == 'B')) { cout << "1\n"; return 0; } if ((ab == 'A' && aa == 'B' && ba == 'B') || (ab == 'B' && bb == 'A' && ba == 'A')) { int answer = 1; for (int i = 1; i <= n - 3; i++) { answer *= 2; if (answer >= MOD) { answer -= MOD; } } cout << answer << "\n"; return 0; } dp[1][0] = dp[1][1] = 1; for (int i = 2; i <= n - 3; i++) { dp[i][0] = dp[i - 1][0] + dp[i - 1][1]; if (dp[i][0] >= MOD) { dp[i][0] -= MOD; } dp[i][1] = dp[i - 1][0]; } int answer = dp[n - 3][0] + dp[n - 3][1]; if (answer >= MOD) { answer -= MOD; } cout << answer << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int n,k,right=1000000000,left=-1; cin >> n >> k; int lim = k*k/2 + 1; bool a; vector<vector<int>> park(n,vector<int>(n)); vector<vector<int>> s(n+1,vector<int>(n+1)); for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ cin >> park.at(i).at(j); } } while(right - left > 1){ int mid = (left + right)/2; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ s.at(i+1).at(j+1) = s.at(i).at(j+1) + s.at(i+1).at(j) - s.at(i).at(j); if(park.at(i).at(j) > mid) s.at(i+1).at(j+1)++; } } a = false; for(int i=0;i<n-k+1;i++){ for(int j=0;j<n-k+1;j++){ if(s.at(i+k).at(j+k) - s.at(i).at(j+k) - s.at(i+k).at(j) + s.at(i).at(j) < lim)a = true; } } if(a) right = mid; else left = mid; //cout << left << " " << right << endl; } cout << right << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) #define ll long long #define pp pair<ll,ll> #define ld long double #define all(a) (a).begin(),(a).end() #define mk make_pair constexpr int inf=1000001000; constexpr ll INF=2e18; constexpr ll mod=1000000007; // ll MOD=998244353; constexpr ll MOD=998244353; int main() { int n; ll x; cin >> n >> x; vector<ll> a(n); vector<map<ll,ll>> dp(n+1); dp[0][x]=1; rep(i,n) cin >> a[i]; a.push_back(INF); reverse(all(a)); rep(i,n){ for (auto it=dp[i].begin();it!=dp[i].end();it++){ if (it->first>=0){ dp[i+1][(it->first)%a[i+1]]+=it->second; if ((it->first)%a[i+1]!=0 && it->first+a[i+1]<a[i]) dp[i+1][-(a[i+1]-(it->first)%a[i+1])]+=it->second; } else{ dp[i+1][-((-it->first)%a[i+1])]+=it->second; if ((-it->first)%a[i+1]!=0 && it->first-a[i+1]>-a[i]) dp[i+1][a[i+1]-((-it->first)%a[i+1])]+=it->second; } } } cout << dp[n][0] << endl; }
#include <iostream> #include<string> using namespace std; string nyu,totyu,kekka; int main() { cin >> nyu; char totyu = nyu[0]; string kekka = nyu + totyu; kekka = kekka.erase(0,1); cout <<kekka; return 0; }
#include<bits/stdc++.h> using namespace std; #define ff first #define ss second #define int long long #define pb push_back #define mp make_pair #define pii pair<int,int> #define vi vector<int> #define mii map<int,int> #define pqb priority_queue<int> #define pqs priority_queue<int,vi,greater<int> > #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define all(a) (a).begin(),(a).end() #define ps(x,y) fixed<<setprecision(y)<<x #define mk(arr,n,type) type *arr=new type[n]; #define w(x) int x; cin>>x; while(x--) #define REP(i,n) for(i=0;i<n;i++) #define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const long long M = 1e9 + 7; void c_p_c() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int mod(int x) { return (x % M + M) % M; } int add(int a, int b) { return mod(mod(a) + mod(b)); } bool isRoaring(int n) { string s = to_string(n); } void solve() { string s; cin >> s; int c = 0; int n = s.size(); int i; for (i = 0; i < n - 3; i++) { if (s[i] == 'Z' && s[i + 1] == 'O' && s[i + 2] == 'N' && s[i + 3] == 'e') c++; } cout << c << endl; } int32_t main() { c_p_c(); FIO; int tt = 1; solve(); }
#include <bits/stdc++.h> using namespace std; // Type alias using ll=long long; using ld=double; using pi=pair<int,int>; using pll=pair<ll,ll>; using pld=pair<ld,ld>; using ti3=tuple<int, int, int>; using vi=vector<int>; using vll=vector<ll>; using vld=vector<ld>; using vpi=vector<pi>; using vpll=vector<ll>; using vpld=vector<ld>; using vti3=vector<ti3>; // Constants const double EPS = 1e-9; const int inf = numeric_limits<int>::max() / 2; const ll mod = 1e9+7; // Macro #define rep(i,n) for(int i=0;i<int(n);++i) #define rrep(i,n) for(int i=int(n-1);i>=0;--i) #define 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 SHOW(a) cout << #a << " = " << a << endl #define ARR(a,n) for(int i=0;i<int(n);++i) cout << #a << "[" << i << "]" << " = " << a[i] << endl #define ALL(a) a.begin(),a.end() // Funtcions ll pow(ll base, ll i, ll mod){ ll a = 1; while(i){ if (i & 1) { a *= base; a %= mod; } base *= base; base %= mod; i >>= 1; } return a; } ll gcd(ll a, ll b){ while(b){ ll c = a % b; a = b; b = c; } return a; } ll lcm(ll a, ll b){ return a / gcd(a, b) * b; } template<typename T> bool chmin(T& a, const T& b) { if (a > b) return a = b, true; else return false; } template<typename T> bool chmax(T& a, const T& b) { if (a < b) return a = b, true; else return false; } void solve(){ int n, m, q; cin >> n >> m >> q; pi wv[55]; pi x[55]; rep(i, n) { int w, v; cin >> w >> v; wv[i] = make_pair(v, w); } rep(i, m) { int t; cin >> t; x[i] = make_pair(t, i); } sort(wv, wv + n); sort(x, x + m); rep(i, q) { int l, r; cin >> l >> r; l--; r--; bool used[55] = {}; rep(i, m) { if(l <= x[i].second && x[i].second <= r) { used[i] = true; } } int ans = 0; rrep(i, n) { int v = wv[i].second; rep(j, m) { if(x[j].first >= v && !used[j]) { ans += wv[i].first; used[j] = true; break; } } } cout << ans << endl; } } int main(){ // FastIO //ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define mp make_pair #define fr first #define sc second int n,m,q; int w[52],v[52]; int x[52]; int main(){ scanf("%d%d%d",&n,&m,&q); for(int i=0;i<n;i++){ scanf("%d%d",&w[i],&v[i]); } for(int i=0;i<m;i++)scanf("%d",&x[i]); vector<pair<int,int>> vec; for(int i=0;i<n;i++){ vec.push_back(mp(v[i],w[i])); } sort(vec.begin(),vec.end()); reverse(vec.begin(),vec.end()); for(int i=0;i<n;i++){ v[i]=vec[i].fr; w[i]=vec[i].sc; } for(;q>0;q--){ int l,r; scanf("%d%d",&l,&r); vector<int> X; for(int i=0;i<m;i++){ if(l-1<=i&&i<=r-1){} else X.push_back(x[i]); } sort(X.begin(),X.end()); bool used[52]; memset(used,false,sizeof used); int ret=0; for(int i=0;i<n;i++){ for(int j=0;j<X.size();j++){ if(!used[j]&&X[j]>=w[i]){ used[j]=true; ret+=v[i]; break; } } } cout<<ret<<endl; } }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (n); i++) using P = pair<long long,long long>; using ll = long long; int main() { ll N,W; cin >> N >> W; int p[N]; vector<tuple<int,int,int>> vec(N); rep(i,N) cin >> get<0>(vec.at(i)) >> get<1>(vec.at(i)) >> get<2>(vec.at(i)) ; sort(vec.begin(),vec.end()); vector<P> vec2(2*N); rep(i,N){ vec2.at(i).first = get<0>(vec.at(i)); vec2.at(i).second = get<2>(vec.at(i)); } rep(i,N){ vec2.at(N+i).first = get<1>(vec.at(i)); vec2.at(N+i).second = -get<2>(vec.at(i)); } sort(vec2.begin(),vec2.end()); ll now = 0; bool over = false; int time=0; int before_time=0; rep(i,2*N){ time = vec2.at(i).first; if ((before_time|=time)&&(now > W)){ over = true; } now += vec2.at(i).second; before_time = time; } if(over){ cout << "No" << endl; } else{ cout << "Yes" << endl; } }
// AtCoder template #include<bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,n) for(int i = 0; i < n; ++i) int main(){ cin.tie(0); ios::sync_with_stdio(false); int n,m; cin >> n >> m; vector<ll> h(n); rep(i,n) cin >> h[i]; vector<ll> w(m); rep(i,m) cin >> w[i]; sort(h.begin(), h.end()); sort(w.begin(), w.end()); if(n == 1){ ll ans = 1e17; rep(i,m) ans = min(ans, abs(h[0]-w[i])); cout << ans << endl; return 0; } vector<ll> ev(n/2+10,0LL), od(n/2+10,0LL); rep(i,n/2){ ev[i+1] = ev[i] + h[2*i+1] - h[2*i]; od[i+1] = od[i] + h[2*i+2] - h[2*i+1]; } ll ans = 1e17; rep(i,m){ int j = upper_bound(h.begin(), h.end(), w[i]) - h.begin(); --j; if(j >= n-1){ ans = min(ans, ev[n/2] + abs(w[i] - h[n-1])); continue; } if(j%2){ ans = min(ans, od[n/2]-od[(j+1)/2] + ev[(j+1)/2] + abs(h[j+1] - w[i])); }else{ ans = min(ans, ev[j/2] + od[n/2] - od[j/2] + abs(w[i] - h[j])); } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define all(x) (x).begin(),(x).end() #define ll long long #define vi vector<int> #define pii pair<int,int> #define F first #define S second #define pb push_back #define rep(i, a, b) for(int i = a; i < b; i++) #define repr(i, a, b) for(int i = a - 1; i >= b; i--) #define iter(m) for(auto it = m.begin(); it != m.end(); it++) #define iterr(m) for(auto it = m.rbegin(); it != m.rend(); it++) #define N 500500 #define PI 3.14159265358979323846264338327950L #define speed ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0); const ll mod = (ll)1e9 + 7; int main(){ speed; int n, h; cin >> n >> h; int matrix[n][n]; rep(i, 0, n) { rep(j, 0, n) { cin >> matrix[i][j]; } } vector<int> path; rep(i, 0, n) { path.push_back(i); } int cnt = 0; do { int sum = 0; rep(i, 0, n) { sum += matrix[path[i]][path[(i + 1) % n]]; } if(sum == h && path[0] == 0) cnt++; } while(next_permutation(all(path))); cout << cnt; return 0; }
#include<bits/stdc++.h> typedef long long ll; using namespace std; int main() { ll a,b; cin>>a>>b; if(a==b) { vector<ll>v; for(ll i=1; i<=a; i++) { v.push_back(i); v.push_back(i*-1); } ll si=v.size(); for(ll i=0; i<si-1; i++) { cout<<v[i]<<" "; } cout<<v[si-1]<<endl; } else { if(a>b) { vector<ll>v; for(ll i=1; i<=a; i++) { v.push_back(i); } for(ll i=1; i<b; i++) { v.push_back(i*-1); } ll res=(a*(a+1))/2; ll res1=(b*(b-1))/2; ll finalres=(res-res1)*-1; v.push_back(finalres); ll si=v.size(); for(ll i=0; i<si-1; i++) { cout<<v[i]<<" "; } cout<<v[si-1]<<endl; } else if(b>a) { vector<ll>v; for(ll i=1; i<=b; i++) { v.push_back(i*-1); } for(ll i=1; i<a; i++) { v.push_back(i); } ll res=(b*(b+1))/2; ll res1=(a*(a-1))/2; ll finalres=(res-res1); v.push_back(finalres); ll si=v.size(); for(ll i=0; i<si-1; i++) { cout<<v[i]<<" "; } cout<<v[si-1]<<endl; } } }
#include<bits/stdc++.h> #define FastIO ios_base::sync_with_stdio(false); cin.tie(0); #define pb push_back #define all(x) (x).begin(),(x).end() #define uniq(v) (v).erase(unique(all(v)),(v).end()) #define sz(x) (int)((x).size()) #define fr first #define sc second #define pii pair<int,int> #define ll long long using namespace std ; ll i , j , c ; ll dp[61][61] ; void solve() { ll a , b , k ; cin >> a >> b >> k ; memset(dp,0l,sizeof(dp)) ; dp[0][0] = 1 ; for(i=1;i<=61;i++){ dp[i][0] = 1 ; for(j=1;j<i;j++){ dp[i][j] = dp[i-1][j] + dp[i-1][j-1] ; } dp[i][i] = 1 ; } ll n = a+b ; while(n--){ ll value = dp[a-1+b][b] ; if(value>=k){ cout << 'a'; a-- ; }else { cout << 'b' ; b-- ; k-= value ; } } } signed main(){ FastIO ; int t=1 ; ///cin>>t ; while(t--){ solve() ; } return 0 ; }
#include<bits/stdc++.h> #include <iostream> #include <string> #include <cmath> #include <algorithm> #include <stdlib.h> #include <vector> #include <set> #include <cassert> #include <numeric> using namespace std; #define rep(i,n) for(int i = 0; i < (int)n; i++) using ll = long long; #define ALL(a) (a).begin(),(a).end() int main() { ll A,B,K,W,ans1=0,ans2=10000000,sum=0,x,y,z,ans=0; string s, s2, s3; char S1,S2,S3[11]; vector<ll> v,v1,v2; map<ll,ll> f,g; cin >> A >> B >> K; if(A==B && B==K){ cout << A; return 0; } if(A==B && A!=K){ cout << K; return 0; }if(B==K && A!=B){ cout << A; return 0; }if(A==K && B!=A){ cout << B; return 0; } cout << 0; }
#include <bits/stdc++.h> //#include <atcoder/all> using namespace std; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef vector<PII> VPII; typedef long long LL; typedef vector<LL> VL; typedef vector<VL> VVL; typedef pair<LL, LL> PLL; typedef vector<PLL> VPLL; typedef priority_queue<LL> PQ_DESC; typedef priority_queue<LL, VL, greater<LL>> PQ_ASC; typedef priority_queue<PII> PQ_DESC_PII; typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII; typedef priority_queue<VL> PQ_DESC_VL; typedef priority_queue<VL, vector<VL>, greater<VL>> PQ_ASC_VL; typedef priority_queue<PLL> PQ_DESC_PLL; typedef priority_queue<PLL, vector<PLL>, greater<PLL>> PQ_ASC_PLL; #define ALL(c) (c).begin(),(c).end() #define PB push_back #define MP make_pair #define SORT_ASC(c) sort(ALL(c)) //#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>()) #define SORT_DESC(c) sort((c).rbegin(),(c).rend()) #define REV(c) reverse((c).begin(), (c).end()) #define SIZE(a) LL((a).size()) #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(i,n) FOR(i,0,n) #define PER(i,n) ROF(i,0,n) const double EPS = 1e-10; const double PI = acos(-1.0); const LL LARGE_INT = 1e9+100; const LL INF = 2e9+100; const LL INF_LL = (LL)INF*(LL)INF; const LL MOD = 1e9+7; //debug #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; LL modpow(LL a, LL n) { LL res = 1; while (n > 0) { if (n & 1) res = res * a % MOD; a = a * a % MOD; n >>= 1; } return res; } void Main() { LL n,s,d;cin>>n>>s>>d; REP(i,n){ LL x,y;cin>>x>>y; if(x<s && y>d){ cout<<"Yes"<<endl; return; } } cout<<"No"<<endl; return; } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(15); Main(); return 0; }
#ifdef GCC_VERSION #include<bits/stdc++.h> #endif #include <iostream> #include <set> #include <vector> #include <string> #include <cmath> #include <map> #include <tuple> #include <algorithm> #include <functional> #include <deque> #include <queue> #include <cstring> #include <chrono> #include <numeric> #ifdef _DEBUG #define DEBUG_INPUT #endif #ifdef DEBUG_INPUT #include "../__common/Helper.h" #endif using ll = long long int; using ld = long double; static const ll INF = 6'000'000'000'000'000'000; // -INF for min value template<typename T> using Vec = std::vector<T>; template<typename T> using VecVec = std::vector<std::vector<T>>; #define fe(e,cont) for(auto& e : cont) // others loop types by snippets #define all(v) std::begin(v),std::end(v) // only for md-arrays template<class T> void unsafe_clear(T& val) { auto sz = sizeof(val); std::memset(&val, 0, sz); } template<class T1, class T2> bool isMemEqual(const T1& v1, const T2& v2) { static_assert(sizeof(v1) == sizeof(v2)); return std::memcmp(&v1, &v2, sizeof(v1)) == 0; } ll ipow(ll v, ll p) { ll res = 1; while (p--) { res *= v; } return res; } ll div_ceil(ll a, ll b) { ll res = a / b; if (res * b != a) res++; return res; } class Timer { // Sometimes measurement is required... using sc = std::chrono::steady_clock; sc::time_point start; public: Timer() :start(sc::now()) {} ll elapsedMs() { return std::chrono::duration_cast<std::chrono::milliseconds>(sc::now() - start).count(); } }; extern const char* INPUT_DATA; #ifdef DEBUG_INPUT static Helper helper(INPUT_DATA); #endif template<class T> T __get() { #ifdef DEBUG_INPUT return helper.get<T>(); #else T val; std::cin >> val; return val; #endif } ll get() { return __get<ll>(); } std::string gets() { return __get<std::string>(); } std::tuple<ll, ll> get2() { return { get(), get() }; } std::tuple<ll, ll, ll> get3() { return { get(), get(), get() }; } std::tuple<ll, ll, ll, ll> get4() { return { get(), get(), get(), get() }; } std::tuple<ll, ll, ll, ll, ll> get5() { return { get(), get(), get(), get(), get() }; } template<class T> void print(const T& val) { std::cout << val << " "; } template<class T, class ... Types> void print(const T& var, const Types&...var2) { print(var); print(var2...); } void endl() { std::cout << "\n"; } void onetime(); void prepare() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr); onetime(); } void task(); void tcase() { ll t = get(); while (t--) task(); } int main() { Timer timer; prepare(); //tcase(); task(); #ifdef DEBUG_INPUT while (helper.hasInput()) task(); //print("Execution time:", timer.elapsedMs()); #endif return 0; } //------------------------------------------------------------- void onetime() { } const char* INPUT_DATA = R"( 4 9 9 5 5 15 5 5 15 15 15 )"; void task() { auto [n, S, D] = get3(); bool f = false; for (ll i = 0; i < n; i += 1) { ll s = get(); ll d = get(); if (s < S && d > D) { f = true; } } print(f?"Yes":"No"); }
#include "bits/stdc++.h" using namespace std; #define mod 1000000007 #define pie 3.142857143 #define ll long long int #define fr(i,a,n) for(ll i=a;i<n;i++) #define vi vector<int> #define vlli vector<ll> #define pb push_back #define ppb pop_back #define mp make_pair #define fv(i,a) for(auto i:a) #define sz(a) int((a).size()) #define all(c) (c).begin(),(c).end() #define frv(i,c) for(auto i = c.begin(); i != c.end(); i++) vi cs(10, 0), ct(10, 0); ll comp(ll x) { ll ans = 0; if (x == 0) { fr(i, 1, 10) { ans += i * pow(10, cs[i]); } } else { fr(i, 1, 10) { ans += (i * pow(10, ct[i])); } } return ans; } void solve() { ll k; cin >> k; string s, t; cin >> s >> t; fr(i, 0, 4) { ll x = s[i] - '0'; cs[x]++; } fr(i, 0, 4) { ll x = t[i] - '0'; ct[x]++; } vlli ans1(10, 0), ans2(10, 0); ll tot = 0; fr(i, 1, 10) { tot += k - (cs[i] + ct[i]); if (cs[i] + ct[i] < k) { cs[i]++; ans1[i] = comp(0); cs[i]--; ct[i]++; ans2[i] = comp(1); ct[i]--; } // if (ct[i] < k) // { // ct[i]++; // ans2[i] = comp(1); // ct[i]--; // } } // fr(i, 1, 10) // { // cout << ans1[i] << " " << ans2[i] << endl; // } tot = tot * (tot - 1); ll sum = 0; fr(i, 1, 10) { fr(j, 1, 10) { if (ans1[i] > ans2[j]) { if (i != j) sum += ((k - (cs[i] + ct[i])) * (k - (cs[j] + ct[j]))); if (i == j) { ll x = cs[i] + ct[i]; x = k - x; sum += (x * (x - 1)); } } } } // cout << sum << " " << tot << endl; double fina = (double)sum / tot; cout << fixed << setprecision(9); cout << fina << endl; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen ("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); int t; //cin >> t; t = 1; while (t--) { solve(); } return 0; }
#include<bits/stdc++.h> // #include<atcoder/all> #define rep(i, n) for(ll i = 0; i < (ll)(n); i++) template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } #define all(x) (x).begin(),(x).end() #pragma GCC optimize("Ofast") using namespace std; // using namespace atcoder; typedef long long int ll; typedef long double ld; typedef long long lint; const ll INF=(1LL<<62); const ll LINF=(1LL<<62); const ld pi=acosl((ld)-1); const ll mod = 1000000007; // const ll mod = 1234567; const int dx[4]={0,1,0,-1}; const int dy[4]={1,0,-1,0}; const int ddx[8]={1,0,-1,-1,-1,0,1,1}; const int ddy[8]={1,1,1,0,-1,-1,-1,0}; #define endn "\n" #define TO_STRING(VariableName) # VariableName template <typename T>ostream &operator<<(ostream &out,const vector<T> &v) {rep(i,(int)v.size()-1)cout<<v[i]<<" ";cout<<v[(int)v.size()-1];return out;} template <typename T1, typename T2>ostream &operator<<(ostream &out, const map<T1, T2> &p) {out << "(" << p.first << ", " << p.second << ")";return out;} template <typename T1, typename T2>ostream &operator<<(ostream &out, const pair<T1, T2> &p){out << "(" << p.first << ", " << p.second << ")";return out;} template<class T>void debag(const T &obj){cout<<obj<<endl;} bool solve(){ ll num=1000+10; vector<ll>count(num,0); ll n,m;cin>>n>>m; rep(i,n){ ll a;cin>>a;count[a]++; } rep(i,m){ ll a;cin>>a;count[a]++; } rep(i,num){ if(count[i]==1)cout<<i<<" "; } cout<<endl; return false; } signed main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cout<<fixed<<setprecision(30); // ll T;cin>>T; // rep(i,T){ // cout<<"Case #"<<i+1<<" : ";solve(); // } solve(); }
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int MOD=1000000007; #define INF 1LL<<30 #define rep(i,n) for (int i = 0; i < (n); ++i) #define all(x) (x).begin(),(x).end() int main(){ double n,x0,y0,xn2,yn2; cin>>n>>x0>>y0>>xn2>>yn2; double cx=(x0+xn2)/2; double cy=(y0+yn2)/2; x0-=cx; y0-=cy; double PI=acos(-1); double th=2*PI/n; double x1=x0*cos(th)-y0*sin(th)+cx; double y1=x0*sin(th)+y0*cos(th)+cy; cout<<setprecision(10)<<x1<<" "<<y1<<endl; }
#include <bits/stdc++.h> using namespace std; #define For(i,n) for(ll i = 0; i < n; i++) #define For1(i,n) for(ll i = 1; i < n; i++) #define Forn(i,n) for(int i = n-1; i >=0 ; i--) #define FOR(i,f,n) for(ll i = f; i < n; i++) #define Forit(it,v) for(auto it = v.begin(); it != v.end(); it++) #define pb push_back #define mp make_pair #define x first #define y second #define sz size() #define dbg(a) For(i,a.sz){cout<<a[i]<<' ';}cout<<'\n'; #define Sort(a) sort(a.begin(), a.end()); #define Rev(a) reverse(a.begin(), a.end()); typedef long long int ll; typedef pair<ll, ll> pl; typedef pair<int,int> pi; typedef vector<ll> vll; typedef vector<int> vi; typedef vector<pl> vpl; typedef vector<vll> vvll; const long double PI = 3.1415926535; int t,m,k,n,X,s,idx,ct1,ct0; //const int N = 1e5; void solve() { cin>>n; vector<long double> a,b; For(i,2){ cin>>k>>m; a.pb(k); b.pb(m); } a.pb((a[0]+a[1]) /2); b.pb((b[0]+b[1])/2); long double vx, vy, l, ax, ay, Vx, Vy, L; vx = a[0] - a[1]; vy = b[0] - b[1]; l = pow(vx, 2.0)+pow(vy, 2.0); l = sqrt(l); vx /= l; vy /= l; // long double angle = (360/n) * PI; ax = cos((2*PI)/n); ay = sin((2*PI)/n); Vx = ax*vx - ay*vy; Vy = ay*vx + ax*vy; L = sqrt(pow(abs(a[0]-a[1]), 2.0)+pow(abs(b[0]-b[1]), 2.0)) /2; // cout<<ax<<' '<<ay<<' '<<L<<' '<<a[2]<<' '<<b[2]<<' '<<Vx*L<<' '<<Vy*L<<'\n'; cout<<setprecision(20)<<a[2]+Vx*L<<' '<<b[2]+Vy*L<<'\n'; } int main() { ios::sync_with_stdio(0); cin.tie(0); // cin >> t; t =1; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (int)(n); i++) #define REP(i,n) for (int i = 1; i < (int)(n); i++) #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define debug(var) do{cout << #var << " : "; view(var);}while(0) template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;} template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;} using namespace std; template<class T> void view(T e) {cout << e << endl;} template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;} template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}} using vint = vector<int>; using vvint = vector<vector<int>>; using ll = long long; using vll = vector<ll>; using vvll = vector<vector<ll>>; using P = pair<int,int>; const int inf = 1<<30; const ll inf_l = 1LL<<61; const int MAX = 1e5; vint dx = {1, 0, -1, 0}; vint dy = {0, 1, 0, -1}; int h, w; vector<string> field; P start, goal; int d[2005][2005]; vector<vector<P>> warp(26); int to_int(P p) { return p.first * w + p.second; } P to_cood(int x) { return P(x / w, x % w); } void solve(P p) { priority_queue<P, vector<P>, greater<P>> q; q.push(P(0, to_int(p))); while (!q.empty()) { P p = q.top(); q.pop(); int x = to_cood(p.second).second; int y = to_cood(p.second).first; if (d[y][x] < p.first) continue; d[y][x] = p.first; if ('a' <= field[y][x] && field[y][x] <= 'z') { vector<P> &w = warp[field[y][x] - 'a']; auto ptr = w.begin(); while (ptr != w.end()) { if (d[(*ptr).first][(*ptr).second] > p.first + 1) { d[(*ptr).first][(*ptr).second] = p.first + 1; q.push(P(p.first + 1, to_int(*ptr))); ptr++; } else ptr = w.erase(ptr); } } rep(i,4) { int n_x = x + dx[i]; int n_y = y + dy[i]; if (n_x >= 0 && n_x < w && n_y >= 0 && n_y < h) { if (field[n_y][n_x] == '#') continue; if (d[n_y][n_x] > p.first + 1) { d[n_y][n_x] = p.first + 1; q.push(P(p.first + 1, to_int(P(n_y, n_x)))); } } } } } int main() { cin >> h >> w; field.resize(h); rep(i,h) cin >> field[i]; rep(i,h)rep(j,w) { if (field[i][j] == 'S') start = P(i, j); if (field[i][j] == 'G') goal = P(i, j); if ('a' <= field[i][j] && field[i][j] <= 'z') { warp[field[i][j] - 'a'].push_back(P(i, j)); } } rep(i,h)rep(j,w) d[i][j] = inf; solve(start); // rep(i,h) { // rep(j,w) cout << d[i][j] << " "; // cout << endl; // } int ans = d[goal.first][goal.second]; if (ans == inf) cout << -1 << endl; else cout << ans << endl; }
#include <bits/stdc++.h> #include <math.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) using ll = long long; using vec = vector<ll>; using vec2 = vector<vector<ll>>; const ll inf = 1e18; const ll mod = 1e9 + 7; int main(){ ll h, w; cin >> h >> w; vector<vector<char>> A(h,vector<char>(w)); rep(i,h){ rep(j,w){ cin >> A[i][j]; } } //yoko ll ans = 0; for(int i = 0;i < h;i++){ for(int j = 0;j <= w-2;j++){ if(A[i][j] == '.' && A[i][j+1] == '.'){ ans++; } } } for(int i = 0;i <= h-2;i++){ for(int j = 0;j < w;j++){ if(A[i][j] == '.' && A[i+1][j] == '.'){ ans++; } } } cout << ans << endl; }
#include <bits/stdc++.h> #define ll long long #define ld long double #define endl "\n" using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n,m,t; cin >> n >> m >> t; pair<int,int> arr[m]; for (int i=0;i<=m-1;i++) { cin >> arr[i].first >> arr[i].second; } int x=n; int time=0; bool ans=false; for (int i=0;i<=m-1;i++) { int a=arr[i].first-time; x=max(x-a,0); if (x==0) { ans=true; } int b=arr[i].second-arr[i].first; x=min(n,x+b); time=arr[i].second; } x=max(0,x-(t-time)); if (x==0) { ans=true; } if (ans) { cout << "No" << endl; } else { cout << "Yes" << endl; } return 0; }
#include<iostream> using namespace std; int main() { int n, m, t; bool yee=true; cin>>n>>m>>t; int r=0; int last=0; int mx=n; while(m--) { int a,b; cin>>a>>b; int now=a-last; n-=now; if(n<=0) {yee=false;} n=min(mx,(n+b-a)); last=b; } // cout<<n<<" "<<t-last<<endl; n-=(t-last); // cout<<n<<endl; if(yee and n>0){cout<<"Yes"<<endl;} else cout<<"No"<<endl; }
#include <bits/stdc++.h> #define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++) #define rep(i,n) Rep(i,0,n) #define all(v) v.begin(),v.end() using namespace std; using ll=long long; using vi=vector<int>; #define _GLIBCXX_DEBUG const int mod=998244353; int main(){ int N;cin>>N; vector<int> f(N); rep(i,N) cin >> f[i]; rep(i,N) f[i]--; vi a(N,-1);int count=0; rep(i,N){ if(a[i]>=0) continue; a[i]=i;int x=i; while(a[f[x]]<0){ x=f[x]; a[x]=i; } if(a[f[x]]<i) continue; else count++; } ll x=2; ll ans=1; while(count>0){ if(count&1) { ans*=x; ans%=mod; } count>>=1; x=x*x;x%=mod; } ans--;ans=(ans+mod)%mod; cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define drep(i,n) for (int i = (n)-1; i >= 0; --i) #define dup(x,y) (((x)+(y)-1)/(y)) #define ALL(x) (x).begin(), (x).end() typedef long long ll; typedef pair<int, int> pii; const double EPS = 1e-10; const int INF = 1e9; const ll LINF = 1e18; const int MOD = 998244353; const double PI = acos(-1); int dx[4] = {0,1,0,-1}; int dy[4] = {1,0,-1,0}; 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; } ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;} ll lcm(ll a, ll b) { return a/gcd(a,b)*b;} ll mpow(ll x, ll p) { if (p==0) return 1; ll res=mpow(x,p/2); res=res*res%MOD; return p%2?res*x%MOD:res; } ll lpow(ll x, ll p) { if (p==0) return 1; ll res=lpow(x,p/2); res*=res; return p%2?res*x:res; } int main() { int tt; cin >> tt; while (tt--) { int n; cin >> n; vector<int> a(n); rep(i,n) cin >> a[i]; map<int, int> mp; rep(i,n) mp[a[i]]++; if (n % 2 == 0) { bool b = true; for (auto p: mp) { if (p.second % 2 == 1) { b = false; } } if (b) cout << "Second" << endl; else cout << "First" << endl; } else { cout << "Second" << endl; } } }
#include <bits/stdc++.h> #define pb push_back #define ff first #define ss second using namespace std; typedef long long ll; typedef unsigned long long ull; const ll INF = (ll)1<<62; const ll MOD = 1e9+7; const int iINF = 1<<30; const double PI = 3.14159265359; void solve(){ ll n; cin >> n; vector<ll> fib(105, 0); fib[0] = fib[1] = 1; for(int i=2;i<100;i++) fib[i] = fib[i-1]+fib[i-2]; int s = 0; for(int i=1;i<100;i+=2){ if(fib[i] > n){ s = i; break; } } s--; vector<int> ans; vector<bool> taken(105, false); ll m = n; for(int i=s;i>=1;i--){ if(m >= fib[i]){ taken[i] = true; m -= fib[i]; } } for(int i=s;i>=1;i-=2){ if(taken[i-1]) ans.pb(2); if(taken[i]) ans.pb(1); ans.pb(4); ans.pb(3); } cout << ans.size() << "\n"; for(int x : ans) cout << x << "\n"; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; //cin >> t; while(t--){ solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long int; #define int long long int #define INF 1e14 #define dd double #define MOD 1000000007 #define my_sizeof(type) ((char *)(&type+1)-(char*)(&type)) #define nl cout<<endl #define fill(a,val) memset(a,val,sizeof(a)) #define mp make_pair #define endl "\n" #define pb push_back #define ff first #define ss second #define SIZE 200005 #define all(v) v.begin(),v.end() #define s(ar,n) sort(ar,ar+n) #define rs(ar,n) sort(ar, ar+n, greater<ll>()) #define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl #define ain(a,n) for(ll i=0;i<n;i++)cin>>a[i]; #define maxa(ar,N) *max_element(ar,ar+N) #define mina(ar,N) *min_element(ar,ar+N) #define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) // find_by_order() - 0 indexing // order_of_key() - number of elements strictly smaller int exp(int a,int b) { int ans=1; for(int i =0;i<b;i++)ans*=a; return ans; } signed main() { fastio(); int tc=1; //cin>>tc; while(tc--){ int n;cin>>n; int a[n],b[n]; ain(a,n);ain(b,n); int x = maxa(a,n); int y =mina(b,n); if(x>y)cout<<0; else cout<<y-x+1; } return 0; }
#include <bits/stdc++.h> #define int long long #define rep(i,a,b) for(int i=(a);i<=(b);i++) #define pre(i,a,b) for(int i=(b);i>=(a);i--) #define ios ios::sync_with_stdio(false),cin.tie(0); #define pb push_back #define ps push #define fi first #define se second #define ps push #define Inf 0x3f3f3f3f3f3f3f3f #define eps 1e-5 typedef long long ll; const int N=3e5+5; const int M=2e5+5; const int mod=998244353; using namespace std; ll quick_power_mod(ll a,ll b,ll m)//pow(a,b)%m { a%=m; ll result = 1; while(b>0) { if(b&1) result=(result*a)%m; a=(a*a)%m; b>>=1; } return result; } //计算组合数取模 ll comp(ll a,ll b,int p)//composite num C(a,b)%p { if(a<b)return 0; if(a==b)return 1; if(b>a-b)b=a-b; ll ans=1,ca=1,cb=1; for(ll i=0;i<b;i++) { ca=(ca*(a-i))%p; cb=(cb*(b-i))%p; } ans=(ca*quick_power_mod(cb,p-2,p))%p; return ans; } ll lucas(ll n,ll m,ll p) { ll ans=1; while(n&&m&&ans) { ans=(ans*comp(n%p,m%p,p))%p;//also can be recusive n/=p; m/=p; } return ans; } ll gcd(ll a,ll b){ return b==0?a:gcd(b,a%b); } string str; signed main() { ios; int n,q; cin>>n>>str>>q; int t,a,b; int cc=0; while(q--){ cin>>t>>a>>b; if(t==1){ if(cc%2==0){ swap(str[a-1],str[b-1]); } else{ if(a<=n){ a+=n; } else{ a-=n; } if(b<=n){ b+=n; } else{ b-=n; } swap(str[a-1],str[b-1]); } } else{ cc++; // swap(str[n-1],str[2*n-1]); } } if(cc%2==0){ cout<<str<<endl; } else{ for(int i=n;i<2*n;i++){ cout<<str[i]; } for(int i=0;i<n;i++){ cout<<str[i]; } cout<<endl; } return 0 ; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define endl "\n" #define all(v) v.begin(),v.end() const int mod = 1e9 + 7; int main (){ fast_io; int n; cin >> n; string s; cin >> s; string start = s.substr(0, n); string last = s.substr(n, n); int q; cin >> q; while (q--) { int type, a, b; cin >> type >> a >> b; a--, b--; if (type == 1) { if (a < n && b < n) { swap(start[a], start[b]); } else if (a < n && b >= n) { swap(start[a], last[b - n]); } else if (a >= n && b < n) { swap(start[a - n], last[b]); } else { swap(last[a - n], last[b - n]); } } else { swap(start, last); } } cout << start << last << endl; }
/* Another source code by: _ _ _ _ _ _____ _ | \ | (_) | (_) / ____| | | | \| |_| |_ _ _ __ | | __ _ __ | |_ | . ` | | __| | '_ \| | |_ | '_ \| __| | |\ | | |_| | | | | |__| | |_) | |_ |_| \_|_|\__|_|_| |_|\_____| .__/ \__| | | |_| */ #include<bits/stdc++.h> #include <vector> using namespace std; #define vi vector<int> #define pb push_back #define p push #define sll stack<long long> #define qll queue<long long> #define vll vector<long long> #define st string #define vvll vector<vll> #define vstr vector <string> #define vp vector <pair<ll,ll>> #define fori(n) for(ll i=0;i<n;i++) #define forj(n) for(int j=0;j<n;j++) #define fork(n) for(int k=0;k<n;k++) #define fori1(n) for(int i=1;i<n;i++) #define f(i,a,b) for(int i=a;i<=b;i++) #define s(v) sort(v.begin(),v.end()) #define sr(v) sort(v.rbegin(),v.rend()) #define ll long long #define MOD 1000000007 #define pi 3.14159265358979323 #include <math.h> #define yn(n) if(n)cout<<"yes\n";else cout<<"no\n"; #define Yn(n) if(n)cout<<"Yes\n";else cout<<"No\n"; #define YN(n) if(n)cout<<"YES\n";else cout<<"NO\n"; #define mp make_pair #define ff first #define ss second ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);} ll lcm(ll a, ll b){return a*b/gcd(a, b);} ll modify(ll n){ll res = n;res%=MOD;res+=MOD;res%=MOD;return res;} ll md(ll n){if(n>0)return n;else return -n;} ll mv(vll v){ll m=v[0];fori(v.size()){m=max(v[i],m);}return m;} vll read(ll n){vll v(n);fori(n)cin>>v[i];return v;} void out(vll v){fori(v.size()){cout<<v[i]<<" ";}cout<<"\n";} void solve(){ ll n,m,k,x; vector<pair<pair<int,int>,int>> v1,v2; cin>>n; fori(n){ cin>>m>>k; v1.pb({{m,k},i}); v2.pb({{k,m},i}); } s(v1); s(v2); // fori(n){ // cout<<v1[i].first.first<<" "<<v1[i].first.second<<"\n"; // } // cout<<"\n"; // fori(n){ // cout<<v2[i].first.first<<" "<<v2[i].first.second<<"\n"; // } // cout<<"\n"; vll visited(n,0); vp temp; fori(n){ if(i==0||i==1||i==n-2||i==n-1){ if(visited[v1[i].second]==0){ temp.pb(v1[i].first); visited[v1[i].second]=1; } } } fori(n){ if(i==0||i==1||i==n-2||i==n-1){ if(visited[v2[i].second]==0){ temp.pb({v2[i].first.second,v2[i].first.first}); visited[v2[i].second]=1; } } } vll ans; fori(temp.size()){ for(int j=i+1;j<temp.size();j++){ ans.pb(max(abs(temp[i].first-temp[j].first),abs(temp[i].second-temp[j].second))); } } sr(ans); cout<<ans[1]; } int main(){ #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif int t; t=1; //cin >> t; while(t--){ solve(); } cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; }
#include <bits/stdc++.h> namespace IO{ char buf[1000000],*p1,*p2; inline char getc(){ if(p1==p2) p2=(p1=buf)+fread(buf,1,10,stdin); return p1==p2?EOF:*(p1++); } template<typename tp>inline void r(tp &n){ n=0;char c=getc(); while(!isdigit(c)) c=getc(); while( isdigit(c)) n=n*10+c-48,c=getc(); } template<typename tp>inline void w(tp n){ if(n/10) w(n/10); putchar(n%10+48); } }; using namespace IO; const int N=2e5+5,K=3e2+5,Mod=998244353; using namespace std; int n,k; int a[N],bin[K],s[N][K],c[K][K]; void Prework(){ bin[0]=1; for(int i=1;i<=k;++i) bin[i]=bin[i-1]*2ll%Mod; c[0][0]=c[1][0]=1; for(int i=1;i<=k;++i,c[i][0]=1) for(int j=1;j<=i;++j) c[i][j]=(c[i-1][j-1]+c[i-1][j])%Mod; for(int i=1;i<=n;++i) s[i][0]=1; for(int i=1;i<=n;++i) for(int j=1;j<=k;++j) s[i][j]=1ll*s[i][j-1]*a[i]%Mod; for(int i=0;i<=k;++i) for(int j=2;j<=n;++j) s[j][i]=(s[j-1][i]+s[j][i])%Mod; } int solve(int d){ int res=0; for(int i=0;i<=d;++i) res=(res+1ll*c[d][i]*s[n][i]%Mod*s[n][d-i]%Mod)%Mod; return res; } int Q(long long b,int t){ long long ret=1; for(int i=1;i<=t;i<<=1,b=b*b%Mod) if(i&t) ret=ret*b%Mod; return ret; } int main(){ r(n),r(k); for(int i=1;i<=n;++i) r(a[i]); Prework(); int inv=Q(2,Mod-2); for(int i=1;i<=k;++i){ int ans=solve(i); ans=(ans-1ll*bin[i]*s[n][i]%Mod+Mod)%Mod; w(1ll*ans*inv%Mod);putchar(10); } return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long const int MAXN = 2e1 + 5; int fa[MAXN]; int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); } void merge(int x, int y) { fa[find(y)] = find(x); } vector<int> vec; int res, col[MAXN]; int n, m, g[MAXN][MAXN]; void dfs(int k) { if (k == vec.size()) { ++res; return ; } for (int i = 1; i <= 3; ++i) { int u = vec[k]; col[u] = i; auto check = [](int x) -> bool { for (int i = 1; i <= n; ++i) if (g[x][i] && col[i] == col[x]) return false; return true; }; if (check(vec[k])) dfs(k + 1); col[u] = 0; } } bool vis[MAXN]; signed main(int argc, char *argv[]) { //ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); for (int i = 0; i < MAXN; ++i) fa[i] = i; cin >> n >> m; while (m--) { int u, v; cin >> u >> v; merge(u, v); g[u][v] = g[v][u] = 1; } int ans = 1; for (int i = 1; i <= n; ++i) { if (vis[i]) continue; vec.clear(), res= 0; for (int j = 1; j <= n; ++j) if (find(j) == i) vec.push_back(j), vis[j] = true;; dfs(0); ans *= res; } cout << ans << '\n'; system("pause"); return 0; }
#include <cstdio> int n, x, sum, a, b; int main() { scanf("%d%d", &n, &x); x *= 100; for(int i = 1; i <= n; i++){ scanf("%d%d", &a, &b); sum += a*b; if(sum > x) return printf("%d", i), 0; } puts("-1"); }
#include<bits/stdc++.h> using namespace std; int main(){ int N; int total = 0; cin >> N; for(int i = 1;total < N;i++){ total += i; if(total >= N){ cout << i << endl; break; } } }
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int MOD=1000000007; #define INF 1LL<<30 #define rep(i,n) for (int i = 0; i < (n); ++i) #define all(x) (x).begin(),(x).end() int main(){ int n; cin>>n; vector<int> t(n); int sum=0; rep(i,n){ cin>>t[i]; sum+=t[i]; } if(n==1){ cout<<t[0]<<endl; return 0; } int ans; if(sum%2==0) ans=sum/2; else ans=sum/2+1; bool dp[n+10][sum+10]; memset(dp, 0, sizeof(dp)); dp[0][0] = true; for (int i = 0; i < n; ++i) { for (int j = 0; j <= sum+10; ++j) { dp[i+1][j] |= dp[i][j]; if (j >= t[i]) dp[i+1][j] |= dp[i][j-t[i]]; } } while(1){ if(dp[n][ans]){ cout<<ans<<endl; return 0; } ans++; } }
#include <bits/stdc++.h> #include <math.h> using namespace std; using ll = long long; using vll = vector<ll>; using vvll = vector<vll>; using vpl = vector<pair<ll, ll>>; using pll = pair<ll, ll>; #define rep(i, k, n) for(ll i = k; i < n; i++) #define pb push_back #define mp make_pair //dijkstra + bitDP ll n, m, k; const ll INF = 10000000000000; vll c(21); vvll G(300000, vll(0)); vll dist(300000); vvll cost(21, vll(21)); priority_queue<pll, vpl, greater<pll>> Q; //dp[bit][v]:集合bitについて最後をvとして順序を最適化した時の最小コスト vvll dp((1<<21)+1, vll(21)); ll rec(ll bit, ll v){ //探索済みならリターン if(dp[bit][v] != -1) return dp[bit][v]; //初期化(bitがvのみ) if(bit == (1<<v)) return dp[bit][v] = 0; //答えの変数 ll res = INF; //bitからvを除いたもの ll prev_bit = bit & ~(1<<v); //vの一つ手前のuについて全探索 rep(u, 0, k){ //uがprev_bitに含まれない場合スルー if(!(prev_bit & (1<<u))) continue; //再帰的に探索 if(res > rec(prev_bit, u) + cost[u][v]){ res = rec(prev_bit, u) + cost[u][v]; } } //メモ化してリターン return dp[bit][v] = res; } int main(){ cin >> n >> m; rep(i, 0, m){ ll a, b; cin >> a >> b; G[a].pb(b); G[b].pb(a); } cin >> k; rep(i, 0, k){ cin >> c[i]; } bool flag = true; rep(i, 0, k){ //距離の初期化 rep(j, 1, n+1){ dist[j] = INF; } //優先度付きキューに(距離, 頂点番号)の組を入れる Q.push(mp(0, c[i])); dist[c[i]] = 0; while(!Q.empty()){ ll pos = Q.top().second; Q.pop(); rep(i, 0, G[pos].size()){ ll to = G[pos][i]; //posを経由してtoに行く距離がdist[to]より短ければ //dist[to]を更新してキューに入れる if(dist[to] > dist[pos] + 1){ dist[to] = dist[pos] + 1; Q.push(mp(dist[to], to)); } } } //コストの配列を作って入れる vll record(0); rep(j, 0, k){ if(dist[c[j]] == INF){ flag = false; break; } record.pb(dist[c[j]]); } cost[i] = record; } if(flag){ //dpテーブルを-1で初期化 rep(i, 0, (1<<k)){ rep(j, 0, k){ dp[i][j] = -1; } } //探索 ll res = INF; rep(v, 0, k){ if(res > rec((1<<k)-1, v)){ res = rec((1<<k)-1, v); } } cout << res+1 << endl; } else cout << -1 << endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll x,y,r,ans; ll inp(){ string s; bool f=true,neg=false; cin>>s; if(s.front()=='-'){ s.erase(s.begin()); neg=true; } for(int i=0;i<s.size();i++)if(s[i]=='.'){ while(s.size()<=i+4)s+='0'; f=false; } if(f)s+="0000"; ll res=0; for(char c:s)if(c!='.'){ res=res*10+c-'0'; } if(neg)res=-res; return res; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); x=inp();y=inp();r=inp(); ll px=x-r,lb=y+10000,rb=y-10000; while(lb%10000!=0)lb--; while(rb%10000!=0)rb++; while(px%10000!=0)px++; for(;px<=x+r;px+=10000){ while(lb-10000>=y||(y-lb+10000)*(y-lb+10000)+(x-px)*(x-px)<=r*r)lb-=10000; while(rb+10000<=y||(rb-y+10000)*(rb-y+10000)+(x-px)*(x-px)<=r*r)rb+=10000; while((y-lb)*(y-lb)+(x-px)*(x-px)>r*r&&lb<y)lb+=10000; while((rb-y)*(rb-y)+(x-px)*(x-px)>r*r&&rb>y)rb-=10000; ans+=max(0ll,(rb-lb)/10000+1); } cout<<ans<<endl; return 0; }
#include <iostream> #include <algorithm> #include <utility> #include <vector> #include <string> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define REP(i, n) for (int i = 0; i < (n); i++) #define RREP(i, n) for (int i = (n) - 1; i >= 0; i--) #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define RFOR(i, a, b) for (int i = (a); i > (b); i--) #define ALL(a) (a).begin(), (a).end() int main() { int a, b, c, d; cin >> a >> b >> c >> d; cout << a * d - b * c << endl; return 0; }
#include<bits/stdc++.h> using namespace std; int main() { int n,c,i,j,x,y,z,m,l,k=0,op=0,c1=0,sum=0,x1,y1,po=1; cin>>n>>x>>y>>z; cout<<(n*z)-(x*y); return 0; }
/*----------------------*/ /*----- Monazo1997 -----*/ /*----------------------*/ #include <bits/stdc++.h> using namespace std; //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); typedef long long ll; #define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define forr(i, a, b) for(ll i = (a); i < (ll) (b); i++) #define forn(i, n) forr(i, 0, n) #define pb push_back #define mp make_pair #define all(c) (c).begin(),(c).end() #define DBG(x) cerr << #x << " = " << (x) << endl #define DBGV(v,n) forn(i,n) cout << v[i] << " "; cout << endl #define esta(x,c) ((c).find(x) != (c).end()) #define RAYA cerr << "===============================" << endl const ll MOD = (ll)(1e9+7); // 998244353 const ll INF = (ll)(1e7+10); // (1e18+10) const int MAXN = (int)(2e5+5); int main(){ FIN; ll a, b; cin >> a >> b; ll suma = 0; forn(i,a-1) { cout << i+1 << " "; suma += i+1; } suma += INF; cout << INF << " "; forn(i,b-1) { cout << -i-1 << " "; suma -= i+1; } cout << -suma << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int a,b,sa,wa; vector<int> god; cin>>a>>b; if(a==b){ for(int i=1;i<=a;i++){ god.push_back(i); god.push_back(-1*i); } }else if(a>b){ sa=a-b; wa=0; for(int i=1;i<=sa+1;i++){ god.push_back(i); wa+=i; } god.push_back(-1*wa); for(int i=0;i<b-1;i++){ wa++; god.push_back(wa); god.push_back(-1*wa); } }else{ sa=b-a; wa=0; for(int i=1;i<=sa+1;i++){ god.push_back(-1*i); wa+=i; } god.push_back(wa); for(int i=0;i<a-1;i++){ wa++; god.push_back(wa); god.push_back(-1*wa); } } for(int i=0;i<god.size();i++){ cout<<god.at(i)<<" "; } cout<<endl; }
#include <bits/stdc++.h> using namespace std; #define fr(i,n) for(int i = 0; i<n; i++) typedef long long ll; #define rmin(a,b) a = min<ll>(a,b) //solves https://atcoder.jp/contests/abc193/tasks/abc193_e ll div(ll a, ll b, bool ceil){ ll ans = abs(a/b); bool pos = (a<0)==(b<0); if(a%b and ceil==pos) ans++; if(!pos) ans*=-1; return ans; } ll gcd_ext(ll a, ll b, ll &xo, ll &yo){ if(b==0){ xo = 1, yo = 0; return a; } ll x1, y1; ll g = gcd_ext(b,a%b,x1,y1); xo = y1; yo = x1-(a/b)*y1; return g; } /* Retorna qual o menor x positivo que satisfaz a*x + b*y = c (obviamente o y correspondente eh negativo) (ou -1 se nao existe) Util em CRT para achar menor r positivo que r = ra (mod a) r = rb (mod b) -> a*x-b*y = rb-ra r = a*x + ra */ ll qual_sol(ll a, ll b, ll c){ ll xo, yo; ll g = gcd_ext(a,b,xo,yo); if(c%g!=0) return -1; c/=g, a/=g,b/=g; xo*=c,yo*=c; ll k = div(-xo,b,b>0); return xo+k*b; } /* Return minimun r such that: r = ra (mod a) r = rb (mod b) Or -1 if no such r */ ll solve_crt(ll ra, ll a, ll rb, ll b){ ll minx = qual_sol(a,-b,rb-ra); if(minx==-1) return minx; return a*minx+ra; } int main(){ ios::sync_with_stdio(0); cin.tie(0); ll t; cin >> t; fr(tt,t){ ll X, Y, P, Q; cin >> X >> Y >> P >> Q; ll t1 = P+Q, t2 = 2*X+2*Y; ll ans = LLONG_MAX; fr(i,Q) fr(j,Y){ ll cand = solve_crt(P+i,t1,X+j,t2); if(cand!=-1) rmin(ans,cand); } if(ans<LLONG_MAX){ cout << ans << "\n"; } else{ cout << "infinity\n"; } } }
#include<iostream> #include<vector> #include<string> #include<algorithm> #include<iomanip> #include<cstdio> #include<map> #include<set> #include<cmath> using namespace std; typedef long long ll; int main(){ int n;cin>>n; ll size=pow(2,n); ll res1=0,res2=0,maxv1=0,maxv2=0; for(int i=0;i<size/2;i++){ ll tmp;cin>>tmp; if(tmp>maxv1){ maxv1=tmp; res1=i+1; } } for(int i=size/2;i<size;i++){ ll tmp;cin>>tmp; if(tmp>maxv2){ maxv2=tmp; res2=i+1; } } if(maxv1>maxv2)cout<<res2<<endl; else cout<<res1<<endl; return 0; }
#include <iostream> #include <math.h> #include <queue> #include <stack> #include <map> #include <algorithm> using namespace std; const int INF = 1 * (1 << 30); const int mINF = -1 * (1 << 30); int main() { string s; cin >> s; if (s.find(".") != string::npos) { s.erase(s.find(".")); } cout << s << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define _ 0 const int maxn=1e5+5; const int inf=0x3f3f3f3f; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); //freopen(".in","r",stdin); //freopen(".out","w",stdout); string x; cin>>x; for(int i=0;i<=x.size()-1;i++) { if(x[i]=='.') break; cout<<x[i]; } return ~~(0^_^0); }
#include <iostream> #include <vector> #include <algorithm> using namespace std; using ll = long long; using P = pair<int, int>; #define rep(i,n) for(int i = 0; i < (n); i++) int main() { int n; cin >> n; vector<int> a(n); rep(i,n) cin >> a[i]; sort(a.begin(), a.end()); ll ans = 0; rep(i,n) { ans += (ll)a[i] * i; ans -= (ll)a[i] * (n-1-i); } cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #pragma region atcoder /*#include <atcoder/all> using namespace atcoder; //using mint = modint998244353; //using mint = modint1000000007;*/ #pragma endregion #pragma region macros using ll = long long; using pii = pair<int, int>; template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; #define rep(i, n) for(int i = 0; i < n; i++) #define REP(i, a, b) for(int i = a; i < b; i++) #define rrep(i, n) for(int i = n - 1; i >= 0; i--) #define RREP(i, a, b) for(int i = b - 1; i >= a; i--) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) ((int)(x).size()) #define pb push_back #define eb emplace_back #define lb lower_bound #define ub upper_bound #define fi first #define se second #pragma endregion #pragma region debug for var, v, vv #define debug(var) do{std::cerr << #var << " : ";view(var);}while(0) template<typename T> void view(T e){std::cerr << e << std::endl;} template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cerr << e << " "; } std::cerr << std::endl;} template<typename T> void view(const std::vector<std::vector<T> >& vv){cerr << endl;int cnt = 0;for(const auto& v : vv){cerr << cnt << "th : "; view(v); cnt++;} cerr << endl;} #pragma endregion #pragma region int128 std::ostream &operator<<(std::ostream &dest, __int128_t value) { std::ostream::sentry s(dest); if (s) { __uint128_t tmp = value < 0 ? -value : value; char buffer[128]; char *d = std::end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } int len = std::end(buffer) - d; if (dest.rdbuf()->sputn(d, len) != len) { dest.setstate(std::ios_base::badbit); } } return dest; } #pragma endregion const ll mod = 1000000007; const int inf = 1001001001; const ll INF = 1001001001001001001ll; int dx[]={1,0,-1,0}; int dy[]={0,1,0,-1}; template<class T>bool chmax(T &a, const T b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T b) { if (b<=a) { a=b; return 1; } return 0; } ll rudiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // 20 / 3 == 7 ll rddiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // -20 / 3 == -7 ll power(ll a, ll p){ll ret = 1; while(p){if(p & 1){ret = ret * a;} a = a * a; p >>= 1;} return ret;} ll modpow(ll a, ll p){ll ret = 1; while(p){if(p & 1){ret = ret * a % mod;} a = a * a % mod; p >>= 1;} return ret;} /*---------------------------------------------------------------------------------------------------------------------------------*/ int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); //cout << fixed << setprecision(20); int n; cin >> n; vector<ll> a(n); for(int i = 0; i < n; i++) cin >> a[i]; sort(a.begin(), a.end()); ll ans = 0; for(int i = 0; i < n; i++){ ans += (ll)(-1) * (n - 1 - i) * a[i] + (ll)i * a[i]; } cout << ans << endl; } /* * review you code when you get WA (typo? index?) * int overflow, array bounds * special cases (n=1?) */
/* Author: Arnab Sinha ███████╗██╗ ██╗███████╗██████╗ ██╗ ██████╗ ██████╗██╗ ██╗███████╗██████╗ █████╗ █████╗ ██╔════╝██║ ██║██╔════╝██╔══██╗ ██║ ██╔═══██╗██╔════╝██║ ██╔╝██╔════╝██╔══██╗██╔══██╗██╔══██╗ ███████╗███████║█████╗ ██████╔╝ ██║ ██║ ██║██║ █████╔╝ █████╗ ██║ ██║╚██████║╚██████║ ╚════ █║██╔══██║██╔══╝ ██╔══██╗ ██║ ██║ ██║██║ ██╔═██╗ ██╔══╝ ██║ ██║ ╚═══██║ ╚═══██║ ███████║██║ ██║███████╗██║ ██║███████╗███████╗╚██████╔╝╚██████╗██║ ██╗███████╗██████╔╝ █████╔╝ █████╔╝ ╚══════╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝╚══════╝╚══════╝ ╚═════╝ ╚═════╝╚═╝ ╚═╝╚══════╝╚═════╝ ╚════╝ ╚════╝ */ #include<bits/stdc++.h> #define IOS ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define li long long int #define ld long double #define all(v) v.begin(),v.end() #define rev(a) reverse(all(a)) #define sort(a) sort(all(a)) #define pb push_back #define INF 1e18+10 #define MINF -1e18-10 #define rep(i,a,b) for(li i=a;i<b;i++) #define vli vector<li> const li MAXN = 1e5+10; const li mod = 998244353; using namespace std; li power(li a, li b, li mod) { a%=mod; li ret = 1; while(b){ if(b&1) ret*=a; a*=a;; if(ret>=mod) ret%=mod; if(a>=mod) a%=mod; b>>=1; } return ret; } template <class T> void read(T& x){ cin>>x; } template <class T, class... U> void read(T& x, U&... u){ read(x); read(u...); } template <class A> void read(vector<A>& v){ for(auto &it:v) read(it); } template <class A> void print(A x){ cout<<x; } template <class A> void printl(A x){ cout<<x<<endl; } template <class A> void print(vector<A>& v) { for(auto &it:v){ print(it); cout<<' '; } cout<<endl; } bool isprime(li n) { if (n <= 1) return false; for (li i = 2; i <= sqrt(n); i++) if (n % i == 0) return false; return true; } li lcm(li a,li b){ return (a*b)/__gcd(a,b); } void solve() { li n; cin>>n; vli a(n),b(n); rep(i,0,n){ li x,y; cin>>x>>y; a[i] = x; b[i] = y; } li ans = INF; rep(i,0,n){ rep(j,0,n){ if(i==j){ ans = min(ans, a[i] + b[j]); } else ans = min(ans, max(a[i],b[j])); } } cout<<ans<<endl; } int main() { IOS; // li t; // cin>>t; // while(t--) solve(); return 0; }
#include <iostream> #include <vector> #include <algorithm> int main(){ int N; std::cin >> N; std::vector<int> A(N), B(N); for(int i=0; i<N; ++i){ std::cin >> A.at(i) >> B.at(i); } int A_min=A.at(0), A_i=0, B_min=B.at(0), B_i=0; for(int i=0; i<N; ++i){ if(A_min>A.at(i)){ A_min = A.at(i); A_i = i; } if(B_min>B.at(i)){ B_min = B.at(i); B_i = i; } } A.erase(A.begin()+A_i); B.erase(B.begin()+B_i); int A_min2=A.at(0), B_min2=B.at(0); for(int i=0; i<N-1; ++i){ if(A_min2>A.at(i)) A_min2 = A.at(i); if(B_min2>B.at(i)) B_min2 = B.at(i); } int result; if(A_i == B_i) result = std::min(A_min+B_min, std::min(std::max(A_min,B_min2), std::max(A_min2,B_min))); else result = std::max(A_min,B_min); std::cout << result << std::endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using pll = pair<long long, long long>; constexpr char ln = '\n'; constexpr long long MOD = 1000000007; constexpr long long INF = 1000000000 + 100; constexpr long long LINF = 1000000000000000000 + 100; #define all(v) v.begin(), v.end() #define rep(i, n) for(int i=0;i<(n);i++) #define rept(i, j, n) for(int i=(j); i<(n); i++) #define rrep(i, n) for(int i=(n); i>=0; i--) 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; } int main(){ int N; cin >> N; N = pow(2, N); vector<pll> A(N); rep(i, N){ int a; cin >> a; A[i] = {i, a}; } while(true){ if(A.size()==2){ if(A[0].second > A[1].second) cout << A[1].first + 1 << ln; else cout << A[0].first + 1 << ln; return 0; } vector<pll> v; for(int i=0; i<A.size(); i+=2){ if(A[i].second > A[i+1].second)v.push_back(A[i]); else v.push_back(A[i+1]); } A = v; } }
#include <bits/stdc++.h> using namespace std; typedef long long LL; int main() { LL N, L, R; scanf("%lld",&N); L = 0, R = N + 1; while(L < R - 1) { LL mid = (L + R) / 2; //printf("%lld %lld %lld\n",L,R,mid); if (mid > 2e9) { R = mid; } else if ((mid + 1) * mid / 2 <= N + 1) { L = mid; } else { R = mid; } } printf("%lld\n",N + 1 - L); }
#include<bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; typedef pair<int, int> P; const int INF = 1e9; const ll MOD = 1000000007; int main() { string S; cin >> S; REP(i, S.size() - 1) { i += 1; if(!('A' <= S[i] && S[i] <= 'Z')) { cout << "No" << endl; return 0; } } REP(i, S.size()) { if(!('a' <= S[i] && S[i] <= 'z')) { cout << "No" << endl; return 0; } i += 1; } cout << "Yes" << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0; i<(n); i++) #define rep2(i,x,n) for(int i=x; i<(n); i++) #define pb push_back #define eb emplace_back #define sz size #define ALL(v) v.begin(),v.end() const long long INF = 1LL << 60; using namespace std; using ll = long long; using P = pair<int, int>; using LP = pair<ll, ll>; using P3 = tuple<int, int, int>; #define vi vector<int> #define vvi vector<vi> #define vll vector<ll> #define vs vector<string> 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; } ll gcd(ll a, ll b) { if (a%b == 0) { return(b); } else { return(gcd(b, a%b)); } } ll lcm(ll a, ll b) { return a * b / gcd(a, b); } int main() { ll l, n; cin >> n; l = 2; rep2(i, 2, n) l = lcm(l, i+1); cout << l+1 << endl; // rep2(i, 2, n+1) { // l *= (ll)i; // cout << l << endl; // } // cout << l+1 << endl; return 0; }
#include <algorithm> #include <iostream> #include <numeric> #include <string> #include <tuple> #include <utility> #include <vector> #define rep(i, a, b) for (int i = int(a); i < int(b); i++) using namespace std; using ll = long long int; using P = pair<ll, ll>; // clang-format off #ifdef _DEBUG_ #define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; debug_print(__VA_ARGS__); } while(false) template<typename T, typename... Ts> void debug_print(const T &t, const Ts &...ts) { cerr << t; ((cerr << ", " << ts), ...); cerr << endl; } #else #define dump(...) do{ } while(false) #endif template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); } template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); } template<typename T> bool chmin(T &a, const T& b) { if (a > b) {a = b; return true; } return false; } template<typename T> bool chmax(T &a, const T& b) { if (a < b) {a = b; return true; } return false; } template<typename T, typename... Ts> void print(const T& t, const Ts&... ts) { cout << t; ((cout << ' ' << ts), ...); cout << '\n'; } template<typename... Ts> void input(Ts&... ts) { (cin >> ... >> ts); } template<typename T> istream &operator,(istream &in, T &t) { return in >> t; } // clang-format on class UnionFind { public: vector<int> par; int N; UnionFind(int n) { par.resize(n, -1); N = n; } int Find(int n) { return par[n] < 0 ? n : par[n] = Find(par[n]); } bool Union(int x, int y) { x = Find(x); y = Find(y); if (x == y) return false; if (-par[x] > -par[y]) swap(x, y); par[y] += par[x]; par[x] = y; N--; return true; } bool Same(int x, int y) { return Find(x) == Find(y); } int size(int x) { return -par[Find(x)]; } int size() { return N; } }; int popcount(ll bits) { bits = (bits & 0x5555555555555555LL) + (bits >> 1 & 0x5555555555555555LL); bits = (bits & 0x3333333333333333LL) + (bits >> 2 & 0x3333333333333333LL); bits = (bits & 0x0f0f0f0f0f0f0f0fLL) + (bits >> 4 & 0x0f0f0f0f0f0f0f0fLL); bits = (bits & 0x00ff00ff00ff00ffLL) + (bits >> 8 & 0x00ff00ff00ff00ffLL); bits = (bits & 0x0000ffff0000ffffLL) + (bits >> 16 & 0x0000ffff0000ffffLL); return (bits & 0x00000000ffffffffLL) + (bits >> 32 & 0x00000000ffffffffLL); } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, m; input(n, m); vector<P> edge(m); vector<ll> pow2(30, 1); rep(i, 1, 30) { pow2[i] = pow2[i - 1] * 2; } rep(i, 0, m) { int a, b; input(a, b); a--; b--; edge[i] = P(a, b); } int bits = 1 << n; ll ans = 0; rep(bit, 0, bits) { vector<bool> used(n, 0); rep(i, 0, n) { if ((bit >> i) & 1) { used[i] = true; } } UnionFind uf(2 * n), uf2(n); bool ok = true; for (auto [a, b] : edge) { if (used[a] && used[b]) { ok = false; } else if (used[a] || used[b]) { continue; } else { uf.Union(a, b + n); uf.Union(a + n, b); uf2.Union(a, b); } } for (auto [a, b] : edge) { if (!used[a] && !used[b]) { if (uf.Same(a + n, b + n)) { ok = false; break; } } } if (ok) { ans += pow2[uf2.size() - popcount(bit)]; } } print(ans); return 0; }
#include <iostream> #include <algorithm> #include <vector> using namespace std; int main(void){ int n; cin >> n; vector< int > p(n+1); vector< vector< int > > p2c(n+1, vector< int >()); for(int i = 2; i <= n; i++){ cin >> p[i]; p2c[p[i]].push_back(i); } vector< int > dp(n+1, -1), dpz(n+1, -1); auto f = [&](auto f, int v)->void{ if(p2c[v].size() == 0){ dp[v] = 1; dpz[v] = 1; return; } dp[v] = 1; vector< int > vp; int pn = 0; for(int w: p2c[v]){ f(f, w); if(dp[w] < 0 && dpz[w] == 0){ dp[v] += dp[w]; }else if(dpz[w] == 0){ pn += dp[w]; }else{ vp.push_back(dp[w]); } } sort(vp.begin(), vp.end()); int vs = vp.size(); for(int i = 0; i < vs; i++) dp[v] += (i%2 == 0 ? vp[i] : -vp[i]); dp[v] += (vs%2 == 0 ? pn : -pn); dpz[v] = (1-vs%2); }; f(f, 1); cout << (n+dp[1])/2 << endl; }
#include <iostream> using namespace std; typedef long long ll; int main (void) { ll b , c; cin >> b >> c; ll la , ra , lb , rb; ll ans = 0; if (b > 0) { lb = b - c / 2; rb = b + (c - 2) / 2; la = -b - (c - 1) / 2; ra = -(b - (c - 1) / 2); if (lb > ra) ans = rb - lb + ra - la + 2; else ans = rb - la + 1; } else { lb = b - c / 2; rb = b + (c - 2) / 2; la = -b - (c - 1) / 2; ra = -(b - (c - 1) / 2); if (la > rb) ans = ra - la + rb - lb + 2; else ans = ra - lb + 1; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0;i<(n);i++) typedef long long ll; int main(){ ll b,c;cin>>b>>c; ll ans=0; bool f=true; if(b<0) f=false; b=abs(b); if(b==0){ ans=c; }else if(c>2*b){ if(f) ans=2*b+c-1; else ans=2*b+c; }else if(c>=3){ ans=2*c-1; }else{ ans=c+1; } cout<<ans<<endl; }
#include<iostream> #include<algorithm> #include<vector> using namespace std; int N_MAX = 5002; int p=998244353; short c[5002][5002]; typedef long long ll; int main() { int h,w,k,hh,ww,i,j,l,t; ll m[N_MAX]; char cc; cin >> h >> w >> k; vector<ll> res(h+w-1),b(h+w-1); for(i=0;i<h;i++) fill(c[i],c[i]+w,0); for(i=0;i<k;i++){ cin >> hh >> ww >> cc; if(cc=='R') c[hh-1][ww-1]=1; else if(cc=='D') c[hh-1][ww-1]=2; else c[hh-1][ww-1]=3; } m[0]=1; for(i=1;i<=min(h,w)+1;i++) m[i]=(m[i-1]*3)%p; res[0]=1; for(l=0;l<h+w-2;l++){ swap(res,b); fill(res.begin(),res.end(),0); t=0; for(i=0;i<=l;i++){ j=l-i; if(i>=h) break; if(j>=w) continue; if(c[i][j]==0) t++; } for(i=0;i<=l;i++){ j=l-i; if(i>=h) break; if(j>=w) continue; if(c[i][j]==1){ if(j<w-1){ res[i]+=b[i]*m[t]; res[i]%=p; } }else if(c[i][j]==2){ if(i<h-1){ res[i+1]+=b[i]*m[t]; res[i+1]%=p; } }else if(c[i][j]==3){ if(j<w-1){ res[i]+=b[i]*m[t]; res[i]%=p; } if(i<h-1){ res[i+1]+=b[i]*m[t]; res[i+1]%=p; } }else{ if(j<w-1){ res[i]+=b[i]*m[t-1]*2; res[i]%=p; } if(i<h-1){ res[i+1]+=b[i]*m[t-1]*2; res[i+1]%=p; } } } } if(c[h-1][w-1]==0){ res[h-1]*=3; res[h-1]%=p; } cout << res[h-1] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; constexpr ll MOD = 1e9+7; int solve_naive(const int n, const int s, const int k){ int cnt = 0; ll now = s; while (now % n != 0 && cnt < n){ now += k; cnt += 1; } if (cnt >= n){ return -1; } return cnt; } ll _gcd(ll a, ll b){ return (a%b) ? _gcd(b, a%b) : b; } pair<ll, ll> extgcd(ll a, ll b){ // ax+by=gcd(a, b)なるx, yを求める if(a%b==0)return {0, 1}; // a*0+b*1=b const auto [x, y] = extgcd(b, a%b); // b*x + (a-a/b*b)*y = gcd(a, b) return {y, x-a/b*y}; // a*y + b*(x+a/b*y) = gcd(a, b) } ll powmod(ll x, ll n, ll p){ // return (x ** n) mod p if (n==0)return 1; if(n==1)return x%p; const auto y = powmod(x, n/2, p); return (y*y%p)*powmod(x, n%2, p)%p; } int solve(int n, int s, int k){ // s + a * k == 0 mod n なる最小の a を求める const auto g = _gcd(k, n); if(s%g!=0){ // k, n が g の倍数なので s は g の倍数である必要がある return -1; } if(g>1){ return solve(n/g, s/g, k/g); } // k*a == 1 mod n なる a を求める const auto [a, _] = extgcd(k, n); return ((n-s)*a%n+n)%n; } int main() { int t; cin >> t; for(int ti=0; ti<t; ti++){ int n,s,k; cin >> n >> s >> k; cout << solve(n, s, k) << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned int ui; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> ii; typedef vector<ii> vii; const int INF = int (1e9) + int (1e5); const ll INFL = ll(2e18) + ll(1e10); const ui MOD = 1E9 + 7; const double EPS = 1e-9; #define FOR(i,n) for (int i=0;i<(n);++i) #define ROF(i,x) for(int i = (x) ; i >= 0 ; --i) #define MP make_pair #define all(a) (a).begin(),(a).end() #define ODD(x) ( ((x)&1)==0?0:1 ) #define SIGN(x) ( ((x) > 0) - ((x) < 0) ) #define dbg(x) cerr << #x"= " << x << endl std::mt19937_64 generator(std::chrono::system_clock::now().time_since_epoch().count()); inline ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} ll gcd(ll a, ll b) { return a ? gcd(b%a, a): b; } ll lcm(ll a, ll b) { return a / gcd(a,b) * b; } void READ(bool _local){ ios_base::sync_with_stdio(false); cin.tie(0); #ifdef _DEBUG if (_local) freopen ("in.txt", "r", stdin); #endif } int main() { READ(0); int n;cin>>n; vi a(n); FOR(i,n) cin>>a[i]; sort(all(a)); ll ret=a[0]+1; for(int i=1;i<n;++i){ ret = ret * (a[i]-a[i-1]+1) % MOD; } cout << ret; return 0; }
#include<iostream> #include<iomanip> #include<string> #include<algorithm> #include<vector> #include<utility> #include<tuple> #include<map> #include<queue> #include<stack> #include<deque> #include<bitset> #include<math.h> #include<numeric> using namespace std; using ll = int64_t; using Graph = vector<vector<int> >; const ll M = 1000000007; int main(){ ll n; cin >> n; vector<ll> a(n); for(int i=0;i<n;i++) cin >> a[i]; sort(a.begin(),a.end()); ll tmp=0; vector<ll> b(n); for(int i=0;i<n;i++){ b[i]=a[i]-tmp; tmp=a[i]; } for(int i=0;i<n;i++) b[i]++; ll ans=1; for(int i=0;i<n;i++){ ans*=b[i]; ans%=M; } cout << ans << endl; }
#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <cstdio> #include <algorithm> #include <vector> using namespace std; constexpr int MOD = 998244353; constexpr int prob = 665496236; long long dp[5001]; int pow(long long x, int n){ long long ret = 1; while (n > 0) { if (n & 1) ret *= x, ret %= MOD; x *= x, x %= MOD; n >>= 1; } return ret; } int main(){ int H, W, K; scanf("%d%d%d", &H, &W, &K); vector<vector<pair<int, char>>> X(H); for(int i = 0; i < H; ++i) X[i].reserve(W); for(int i = 0; i < K; ++i){ int x, y; char c; scanf("%d%d%c%c", &x, &y, &c, &c); --x, --y; X[x].emplace_back(y, c); } dp[0] = 1; for(int i = 0; i < H; ++i){ sort(X[i].begin(), X[i].end()); auto itr = X[i].begin(); for (int j = 0; j < W; ++j){ dp[j] %= MOD; if(itr != X[i].end() and itr->first == j){ char c = itr->second; if(c != 'D') dp[j + 1] += dp[j]; if((i != H - 1) & c == 'R') dp[j] = 0; ++itr; } else{ dp[j + 1] += dp[j] * prob; if(i != H - 1) dp[j] *= prob; } } } long long ans = dp[W - 1]; ans *= pow(3, H * W - K); printf("%d", ans % MOD); return 0; }
#include <bits/stdc++.h> #define fir first #define sec second #define PB push_back #define MP make_pair #define all(a) (a).begin(), (a).end() #define sz(a) (a).size() 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 foreach(itr, c) for (__typeof((c).begin()) itr = (c).begin(); itr != (c).end(); ++itr) template <class T> void chkmax(T& x, T y) { x = (x > y ? x : y); } template <class T> void chkmin(T& x, T y) { x = (x < y ? x : y); } typedef long long LL; typedef pair <int, int> pii; typedef vector <int> vi; const int N = 5005; const LL P = 998244353; int n, m, K; int a[N][N]; LL f[N][N]; bool vis[N][N]; LL mul1, mul2, mul3; LL _pow(LL x, LL y){ if (y < 0) return 0; LL ret = 1; for (; y; y >>= 1, x = x * x % P) if (y & 1) ret = ret * x % P; return ret; } LL dp(int r, int c){ if (r == 1 && c == 1) return 1; if (vis[r][c]) return f[r][c]; vis[r][c] = 1; LL& ret = f[r][c]; if (r > 1 && a[r - 1][c] != 1){ if (!a[r - 1][c]) ret += mul3 * dp(r - 1, c); else ret += dp(r - 1, c); ret %= P; } if (c > 1 && a[r][c - 1] != 2){ if (!a[r][c - 1]) ret += mul3 * dp(r, c - 1); else ret += dp(r, c - 1); ret %= P; } return ret; } int main(){ scanf("%d%d%d", &n, &m, &K); mul3 = _pow(3, P - 2); mul3 = mul3 * 2 % P; rep(i, K){ int x, y; char c; scanf("%d%d %c", &x, &y, &c); if (c == 'R') a[x][y] = 1; if (c == 'D') a[x][y] = 2; if (c == 'X') a[x][y] = 3; } LL ret = dp(n, m); ret = ret * _pow(3, n * m - K) % P; printf("%lld\n", ret); return 0; }
// Problem: E - Come Back Quickly // Contest: AtCoder - AtCoder Beginner Contest 191 // URL: https://atcoder.jp/contests/abc191/tasks/abc191_e // Memory Limit: 1024 MB // Time Limit: 3000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) #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)2e3 + 10; ll dist[N][N]; ll bk[N][N]; vector<pair<int, ll>> adj[N]; vector<ll> ans; void bfs(int node) { queue<pair<int, ll>> q; dist[node][node] = 0; q.push({node, 0}); while (sz(q)) { auto t = q.front(); q.pop(); for (auto child : adj[t.F]) { if (child.S + t.S < dist[node][child.F]) { dist[node][child.F] = child.S + t.S; q.push({child.F, child.S + t.S}); } } } } void solve() { int n, m; sc(n), sc(m); ll c; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { dist[i][j] = inf; bk[i][j] = inf; } } vector<array<ll, 3>> ar; for (int i = 1; i <= m; i++) { int u, v; sc(u), sc(v), sl(c); bk[u][v] = c; ar.push_back({u, v, c}); } sort(all(ar)); for (int i = 0; i < m; i++) { int u = ar[i][0], v = ar[i][1]; ll c = ar[i][2]; if (i && u == ar[i - 1][0] && v == ar[i - 1][1]) { continue; } adj[u].push_back({v, c}); } for (int i = 1; i <= n; i++) { bfs(i); } // printf("swapno\n"); for (int i = 1; i <= n; i++) { ll mn = inf; for (auto p : adj[i]) { mn = min(mn, p.S + dist[p.F][i]); } if (mn == inf) { pr(-1); } else { pl(mn); } } } 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; }
#pragma GCC optimize("Ofast", "unroll-loops") #include <bits/stdc++.h> using namespace std; template<typename T> vector<T> dijkstra(int s, vector<vector<pair<int, T>>> &G){ const int n = G.size(); vector<T> d(n, numeric_limits<T>::max()); vector<int> b(n, -1); priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> q; d[s] = 0; q.emplace(d[s], s); while (!q.empty()){ pair<T, int> p = q.top(); q.pop(); int v = p.second; if (d[v] < p.first) continue; for (auto& e : G[v]){ int u = e.first; T c = e.second; if (d[u] > d[v] + c){ d[u] = d[v] + c; b[u] = v; q.emplace(d[u], u); } } } return d; } using edge = pair<int, int>; int N, M; vector<vector<edge>> G, transG; void input(void){ cin >> N >> M; G.resize(N); transG.resize(N); for (int i = 0; i < M; ++i){ int A, B, C; cin >> A >> B >> C; --A, --B; G[A].emplace_back(B, C); transG[B].emplace_back(A, C); } } int solve(int v){ const int INF = numeric_limits<int>::max(); auto mindist = dijkstra(v, G); int ans = INF; for (edge e : transG[v]){ if (mindist[e.first] == INF) continue; ans = min(ans, e.second + mindist[e.first]); } if (ans == INF) return -1; return ans; } int main(void){ input(); for (int i = 0; i < N; ++i) cout << solve(i) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int a,b,c; int main(){ cin>>a>>b>>c; set<int> se; se.insert(a); se.insert(b); se.insert(c); if(se.size()==3)cout<<0<<endl; else{ if(a==b)cout<<c<<endl; else if(b==c)cout<<a<<endl; else cout<<b<<endl; } }
#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<<right<<setw(10)<<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 GCD(ll a, ll b) { if(b == 0) return a; else return GCD(b, a%b); } struct COMB{ vl fact, fact_inv, inv; void init_nCk(long long SIZE) { fact.resize(SIZE + 5); fact_inv.resize(SIZE + 5); inv.resize(SIZE + 5); fact.at(0) = fact.at(1) = fact_inv.at(0) = fact_inv.at(1) = inv.at(1) = 1; for(long long i = 2; i < SIZE + 5; i++) { fact.at(i) = fact.at(i - 1)*i%MOD; inv.at(i) = MOD - inv.at(MOD%i)*(MOD/i)%MOD; fact_inv.at(i) = fact_inv.at(i - 1)*inv.at(i)%MOD; } } long long nCk (long long n, long long k) { assert(!(n < k)); assert(!(n < 0 || k < 0)); return fact.at(n)*(fact_inv.at(k)*fact_inv.at(n - k)%MOD)%MOD; } }; ll extGCD(ll a, ll b, ll &x, ll &y) { if(b == 0) { x = 1; y = 0; return a; } ll d = extGCD(b, a%b, y, x); y -= a/b*x; return d; } void Main() { LCIN(X); cout << 100 - X%100 << endl; } int main() { cout << fixed << setprecision(15); Main(); return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int N; cin >> N; long long S=0,ans=0; vector<long long> A(N); for(int i=0;i<N;i++){ cin >> A[i]; S+=A[i]; } sort(A.begin(),A.end()); for(int i=0;i<N;i++){ ans+=S-(N-i)*A[i]; S-=A[i]; } cout << ans << endl; }
#include <bits/stdc++.h> #include <numeric> #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define RREP(i, n) for (int i = (int)(n) - 1 ; i >= 0; i--) #define FOR(i, a, b) for (int i = (a); i < (int)(b); i++) #define ALL(v) (v).begin(), (v).end() #define MIN(v) *min_element((v).begin(), (v).end()) #define MAX(v) *max_element((v).begin(), (v).end()) #define PF(p) (p).first #define PS(p) (p).second #define MF(p) (p)->first #define MS(p) (p)->second #define SZ(x) ((int)(x).size()) #define pb push_back #define mp make_pair #define VL vector<long long> #define VVL vector<vector<long long>> #define VB vector<bool> #define VVB vector<vector<bool>> #define VC vector<char> #define VVC vector<vector<char>> using namespace std; using ll = long long; const ll MOD = 1000000007LL; //const ll MOD = 998244353LL; int pmod(int x){int y=x%(int)MOD;return (y>=0)?y:y+(int)MOD;} ll pmod(ll x){ll y=x%MOD;return (y>=0LL)?y:y+MOD;} bool in(ll x, ll a, ll b){return (a<=x)&&(x<b);} template<class T>bool chmin(T& a, T b){if(a>b){a=b;return true;}else return false;} template<class T>bool chmax(T& a, T b){if(a<b){a=b;return true;}else return false;} int main(){ ll N; cin>>N; VL A(N); REP(i,N)cin>>A[i]; sort(ALL(A)); ll sum = 0; for(ll i=0LL;i<N;++i){ sum += (2LL*i-N+1LL) * A[i]; } cout << sum; return 0; }
#pragma GCC optimize ("O2") #pragma GCC target ("avx") //#include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; #include<iostream> #include<cstring> using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please ll A[200001], B[200001], tmp[200001]; void pakuri_sort(int N, ll A[]) { const int b = 8; rep(k, 4) { int kazu[1 << b] = {}, kazu2[1 << b] = {}; rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++; rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i]; for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i]; k++; rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++; rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i]; for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i]; } } const int CM = 400001, CL = 12; char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct; const ll ma0 = 1157442765409226768; const ll ma1 = 1085102592571150095; const ll ma2 = 71777214294589695; const ll ma3 = 281470681808895; const ll ma4 = 4294967295; inline int getint() { if (ci - owa > 0) { memcpy(cn, owa, CL); ci -= CM; fread(cn + CL, 1, CM, stdin); } ll tmp = *(ll*)ci; if ((tmp & ma0) ^ ma0) { int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0); tmp = tmp << dig & ma1; tmp = tmp * 10 + (tmp >> 8) & ma2; tmp = tmp * 100 + (tmp >> 16) & ma3; tmp = tmp * 10000 + (tmp >> 32) & ma4; ci += (72 - dig >> 3); } else { tmp = tmp & ma1; tmp = tmp * 10 + (tmp >> 8) & ma2; tmp = tmp * 100 + (tmp >> 16) & ma3; tmp = tmp * 10000 + (tmp >> 32) & ma4; ci += 8; if ((ct = *ci++) >= '0') { tmp = tmp * 10 + ct - '0'; if (*ci++ == '0') { tmp = tmp * 10; ci++; } } } return tmp; } int main() { cin.tie(0); ios::sync_with_stdio(false); int N = getint(); rep(i, N) { A[i] = ll(i) << 32 | getint(); B[i] = ll(i) << 32 | getint(); } pakuri_sort(N, A); pakuri_sort(N, B); const ll ma = (1ll << 32) - 1; rep(i, N) { auto tmp = (A[i] & ma) < (B[N - 1 - i] & ma); cn[A[i] >> 31] = tmp; cn[B[N - 1 - i] >> 31 | 1] = tmp; } int c = -1, pn = 0; rep(i, N << 1) { if (c != -1 && pn == cn[i]) { cn[c] = '('; cn[i] = ')'; c = tmp[c]; pn ^= 1; } else { pn = cn[i]; tmp[i] = c; c = i; } } fwrite(cn, 1, N << 1, stdout); Would you please return 0; }
#include<bits/stdc++.h> using namespace std; //====================== // // Template OleschY // // Die M�glichkeiten der deutschen Grammatik k�nnen // einen, wenn man sich darauf, was man ruhig, wenn // man m�chte, sollte, einl�sst, �berraschen. // - @Gedankenbalsam // //====================== //====================== // Solution Single testcase //====================== int solve() { int n; cin >> n; vector<int> bra(2 * n); vector<bool> col(2 * n, false); for(int i = 0; i < 2 * n; ++i) { cin >> bra[i]; } vector<int> id(2 * n); iota(id.begin(), id.end(), 0); sort(id.begin(), id.end(), [&](int a, int b) { return bra[a] < bra[b]; }); for(int i = 0; i < n; ++i) { col[id[i]] = true; } stack<int> stk; string sol; for(int i = 0; i < 2 * n; ++i) { if(stk.empty()) { sol += '('; stk.push(i); continue; } int pos = stk.top(); if(col[pos] == col[i]) { sol += '('; stk.push(i); } else { sol += ')'; stk.pop(); } } cout << sol << "\n"; return 0; } //====================== // Technical stuff //====================== int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); //freopen("a.out","w",stdout); // console output is better (in most cases) #else // add i/o method of specific testing system #endif int ntest = 1; //cin >> ntest; for(int test = 0; test < ntest; ++test) { solve(); } return 0; }
#include<iostream> #include<string> #include<algorithm> #include<cmath> #include<vector> #include<list> #include<stack> #include<queue> #include<map> #include<set> #include<iomanip> #include<tuple> #include<cstring> #include<bitset> #define REP(i,n) for(ll i=0;i<(ll)n;i++) #define ALL(x) (x).begin(),(x).end() #define SZ(x) ((ll)(x).size()) #define pb push_back #define eb emplace_back #define INF 1000000000 #define INFLL 1000000000000000000LL using namespace std; template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } using ll = long long; using PP = pair<ll, ll>; #define MAX_N 200000+100 class UnionFind { vector<int> par;//親 vector<int> ran;//rank public: UnionFind(int n) { par.resize(n); ran.resize(n); for (int i = 0; i < n; i++) { par[i] = i; ran[i] = 0; } } void init(int n) { par.resize(n); ran.resize(n); for (int i = 0; i < n; i++) { par[i] = i; ran[i] = 0; } } //根を求める int find(int x) { if (par[x] == x) { return x; } else return par[x] = find(par[x]);//辺の縮約を行っている } //併合 void unite(int x, int y) { x = find(x); y = find(y); if (x == y)return; if (ran[x] < ran[y]) { par[x] = y; } else { par[y] = x; if (ran[x] == ran[y])ran[x]++; } } //同じ木に属するか bool same(int x, int y) { return find(x) == find(y); } }; int N, Q, C[MAX_N], bel[MAX_N]; map<ll, ll> mp[MAX_N]; vector<ll> aff[MAX_N]; int main() { cin >> N >> Q; REP(i, N) { cin >> C[i]; C[i]--; } REP(i, N) { bel[i] = i; mp[bel[i]][C[i]] = 1; aff[i].push_back(i); } UnionFind uf(N); while (Q--) { int a, x, y; cin >> a >> x >> y; x--, y--; if (a == 1) { if (!uf.same(x, y)) { uf.unite(x, y); if (SZ(aff[bel[x]]) > SZ(aff[bel[y]])) swap(x, y); ll belx = bel[x]; for (auto&& v : aff[belx]) { aff[bel[y]].push_back(v); bel[v] = bel[y]; } aff[belx].clear(); for (auto&& m : mp[belx]) { mp[bel[y]][m.first] += m.second; } mp[belx].clear(); } } if (a == 2) { cout << mp[bel[x]][y] << endl; } } return 0; }
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <chrono> #include <cstdint> #include <cstdio> #include <cstring> #include <deque> #include <ios> #include <iostream> #include <limits> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <vector> #include <utility> using namespace std; using i64 = int64_t; using u64 = uint64_t; using i32 = int32_t; using pi64 = pair<i64, i64>; constexpr i64 MAXN = 3*100*1000LL+5LL; constexpr i64 MOD = 1000000007LL; constexpr i64 INF64 = MOD * MOD; #define vec vector #define let const #define DRi64(x) i64 x; cin >> x; #define DRS(x) string x; cin >> x; #define DRVi64(v, n) vec<i64> v(n); { for (i64 i = 0; i < n; ++i) { cin >> v[i]; }} #ifdef DEBUG #define P(x) cerr << x << "\n" #else #define P(x) #endif i64 find_(const i64 a, vec<i64>& parents) { if (parents[a] != a) { parents[a] = find_(parents[a], parents); } return parents[a]; } void union_(const i64 a, const i64 b, vec<i64>& parents, vec<i64>& sizes, vec<map<i64, i64>>& class_hists) { let i64 r_a = find_(a, parents); let i64 r_b = find_(b, parents); if (r_a == r_b) { return; } if (sizes[r_a] < sizes[r_b]) { union_(r_b, r_a, parents, sizes, class_hists); return; } sizes[r_a] += sizes[r_b]; parents[r_b] = r_a; // merge map of smaller vertex into that of larger vertex for (let auto& [cls, cnt] : class_hists[r_b]) { class_hists[r_a][cls] += cnt; } } int main() { ios_base::sync_with_stdio(false); DRi64(N); DRi64(Q); DRVi64(C, N); // Ci \in [1, N] vec<i64> class_hist(N + 1, 0); for (let i64 c : C) { ++class_hist[c]; } vec<i64> parents(N + 1); iota(parents.begin(), parents.end(), 0LL); vec<i64> sizes(N + 1, 1); vec<map<i64, i64>> class_hists(N + 1); for (i64 i = 1; i <= N; ++i) { class_hists[i][C[i - 1]] = 1; } for (; Q-->0;) { DRi64(typ); if (typ == 1) { DRi64(A); DRi64(B); union_(A, B, parents, sizes, class_hists); } else if (typ == 2) { DRi64(X); DRi64(Y); if (let i64 r_X = find_(X, parents); class_hists[r_X].count(Y)) { cout << class_hists[r_X][Y] << "\n"; } else { cout << "0\n"; } } else { abort(); } } return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long using vec_int = vector<int>; using P = pair<int,int>; using T = tuple<int,int,int>; using Q = tuple<int,int,int, int, int>; using ll = long long; #define rep(i, n) for(int i = 0; i < (int)(n); i++) int charToInt(char c){ char zero_num = '0'; return (int)c - (int)zero_num; } int solve(vector<vec_int> &DP, vector<vec_int> &mat, int state, int pos, int K){ if(DP.at(state).at(pos)>=0){ return DP.at(state).at(pos); } int temp=1; vec_int city_vec; rep(i,K){ if((state/temp)%2==1 && i!=pos){ city_vec.push_back(i); } temp*=2; } if(city_vec.size()==0){ DP.at(state).at(pos) = 1; return 1; } int next_state = state - (1<<pos); int result = INT_MAX; for(auto next_city: city_vec){ int temp = solve(DP, mat, next_state, next_city, K) + mat.at(next_city).at(pos); result = min(temp, result); } DP.at(state).at(pos) = result; return result; } signed main(){ int N, M; cin>>N>>M; vec_int A(M), B(M); rep(i,M)cin>>A.at(i)>>B.at(i); vector<vec_int> G(N+1); rep(i,M){ G.at(A.at(i)).push_back(B.at(i)); G.at(B.at(i)).push_back(A.at(i)); } int K; cin>>K; vec_int C(K); rep(i,K)cin>>C.at(i); vector<vec_int> mat(K, vec_int(K,-1)); rep(k,K){ int start = C.at(k); priority_queue<P, vector<P>, greater<P>> pq; pq.emplace(0, start); vec_int visited(N+1, -1); while(!pq.empty()){ int cost, pos; tie(cost, pos) = pq.top(); pq.pop(); if(visited.at(pos)>=0)continue; visited.at(pos) = cost; for(auto next_pos: G.at(pos)){ if(visited.at(next_pos)>=0)continue; pq.emplace(cost+1, next_pos); } } rep(i,K){ mat.at(k).at(i) = visited.at(C.at(i)); //都市kからiまでの最短コスト, -1の時には到達不能 if(visited.at(C.at(i))==-1){ cout<<-1<<endl; return 0; } } } // TSPをbitDPで解く // DP.at(i).at(j): 今までの回った年: i, 最後の都市i vector<vec_int> DP(1<<K, vec_int(K, -1)); int ans = INT_MAX; rep(i,K){ ans = min(ans, solve(DP, mat, (1<<K)-1, i, K)); } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0; i<(n); ++i) #define fixed_setprecision(n) fixed << setprecision((n)) #define execution_time(ti) printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC); #define pai 3.1415926535897932384 #define NUM_MAX 2e18 #define NUM_MIN -1e9 using namespace std; using ll = long long; using P = pair<int,int>; template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; } #define DISPLAY_CNT 10 ll h[DISPLAY_CNT] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; map<char, ll> m; ll SendMoreMoney(string S){ ll n=0; ll l=S.length()-1; for(auto s:S){ n += m[s] * pow(10, l); l--; } return n; } int main() { string s1, s2, s3; cin >> s1 >> s2 >> s3; for(auto s:s1) m[s]=0; for(auto s:s2) m[s]=0; for(auto s:s3) m[s]=0; if(m.size()>DISPLAY_CNT){ cout << "UNSOLVABLE" << endl; return 0; } do{ ll cnt=0; for(auto &itr:m){ itr.second = h[cnt]; cnt++; } if(m[s1[0]] == 0 || m[s2[0]] == 0 || m[s3[0]] == 0) continue; ll n1=SendMoreMoney(s1); ll n2=SendMoreMoney(s2); ll n3=SendMoreMoney(s3); if(n1 + n2 == n3){ cout << n1 << endl << n2 << endl << n3 << endl; return 0; } }while(next_permutation(h, h+DISPLAY_CNT)); cout << "UNSOLVABLE" << endl; return 0; }
#include <iostream> #include <sstream> #include <algorithm> #include <cmath> #include <functional> #include <vector> #include <set> #include <map> #include <queue> #include <stack> using namespace std; #define fi first #define se second #define rep(i, n) for (int i = 0; i < (n); ++i) #define rrep(i, n) for (int i = 1; i < (n); ++i) #define srep(i, s, n) for (int i = s; i < (n); ++i) #define rng(a) a.begin(), a.end() #define rrng(a) a.rbegin(), a.rend() #define pb push_back #define eb emplace_back #define sz(x) (int)(x).size() using ll = long long; using ull = unsigned long long; using P = pair<int, int>; using T3 = tuple<int, int, int>; template<typename T>void print(vector<T> a) { for (T t : a) { cout << t << " "; } cout << endl; } const ll LINF = 1LL << 60; const int INF = 1001001001; const int mod = 1e9 + 7; vector<vector<int> > g; vector<bool> visited; ll f(int i) { ll res = 0; // for (int next : g[i]) // res += g[i].size(); for (int next : g[i]) { if (!visited[next]) { visited[next] = true; res++; res += f(next); } } return res; } int main() { int n, m; cin >> n >> m; g = vector<vector<int> >(n); rep(i, n) { g[i].pb(i); } rep(i, m) { int a, b; cin >> a >> b; a--; b--; g[a].pb(b); } // rep(i, n) { print(g[i]); } ll ans = 0; rep(i, n) { visited = vector<bool>(n, false); // cout << ans << endl; ans += f(i); } cout << endl; cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define ll long long #define rgi register int using namespace std; const int M=2e3+7,modd=998244353; int n,m; bitset<M>a[M]; inline int read(){ int w=0,r=1;char c=getchar(); while(!(isdigit(c)||c=='-'))c=getchar(); if(c=='-'){r=-1;c=getchar();} while(isdigit(c)){w=(w<<3)+(w<<1)+c-'0';c=getchar();} return w*r; } int main(){ int t=1; while(t--){ n=read(),m=read(); for(int i=1;i<=m;i++){ int fr=read(),tr=read(); a[fr][tr]=1; } for(int i=1;i<=n;i++)a[i][i]=1; for(int k=1;k<=n;k++){ for(int i=1;i<=n;i++){ if(a[i][k])a[i]|=a[k]; } } int ans=0; for(int i=1;i<=n;i++)ans+=a[i].count(); printf("%d\n",ans); } return 0; } /* 3 3 1 2 2 3 3 2 */
#include <bits/stdc++.h> using namespace std; #define pb push_back #define all(x) (x).begin(),(x).end() #define SZ(x) ((int)(x).size()) #define REP(i,n) for(int _n=n, i=0;i<_n;++i) #define FOR(i,a,b) for(int64_t i=(a),_b=(b);i<=_b;++i) #define FORD(i,a,b) for(int64_t i=(a),_b=(b);i>=_b;--i) using ull = uint64_t; using ll = int64_t; using PII = pair<int, int>; using VI = vector<int>; string to_string(string s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(bool b) { return (b ? "true" : "false"); } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) const ll md = 1000000007; bool canReach(ll a, ll b, ll c, ll d) { if (a + b == c + d || a - b == c - d || abs(a - c) + abs(b - d) <= 3) { return true; } return false; } int main() { ios::sync_with_stdio(false); cin.tie(0); ll a, b, c, d; cin >> a >> b >> c >> d; if (a == c && b == d) { cout << 0 << endl; return 0; } if (canReach(a, b, c, d)) { cout << "1\n"; return 0; } if ((c + d - a + b) % 2 == 0 && (a - b + c + d) % 2 == 0) { cout << 2 << endl; return 0; } if ((a + b +c - d) % 2 == 0 && (a + b - c + d) % 2 == 0) { cout << 2 << endl; return 0; } for (ll x = c - 6; x <= c + 6; x++) { for (ll y = d - 6; y <= d + 6; y++) { if (abs(x - c) + abs(y - d) > 3) continue; if (canReach(a, b, x, y)) { cout << "2\n"; return 0; } } } cout << 3 << endl; }
#include <algorithm> #include <cstdio> #include <cmath> using std::min; long long c1, r1, c2, r2; int main(void) { scanf("%lld%lld%lld%lld", & r1, & c1, & r2, & c2); if (r1 == r2 && c1 == c2) { puts("0"); return 0; } if (llabs(r2 - r1) + llabs(c2 - c1) <= 3 || r1 + c1 == r2 + c2 || r1 - c1 == r2 - c2) { puts("1"); return 0; } if ((llabs(r2 - r1) & 1) == (llabs(c2 - c1) & 1)) { puts("2"); return 0; } else { long long deltay = llabs(c2 - c1), deltax = llabs(r2 - r1); if (min(llabs(r2 - deltay - r1), llabs(r2 + deltay - r1)) <= 3) puts("2"); else if (min(llabs(c2 - deltax - c1), llabs(c2 + deltax - c1)) <= 3) puts("2"); else puts("3"); } return 0; }
#include<iostream> #include<algorithm> #include<vector> using namespace std; typedef long long int ll; typedef pair<ll,ll> P; const int MAX = 200000; int main(){ int N,M,Q,op[MAX],p[MAX],A,B; bool rev=false; ll multX,multY,plusX,plusY,preM,preP,x,y; vector<int> q[MAX],index[MAX]; vector<P> first; P xy[MAX]; P ans[MAX]; cin>>N; for(int i=0;i<N;i++)cin>>xy[i].first>>xy[i].second; cin>>M; for(int i=0;i<M;i++){ cin>>op[i]; if(op[i]>=3)cin>>p[i]; } cin>>Q; for(int i=0;i<Q;i++){ cin>>A>>B;A--;B--; if(A<0){ ans[i]=xy[B]; }else{ q[A].push_back(B); index[A].push_back(i); } } multX=multY=1; plusX=plusY=0; for(int i=0;i<M;i++){ preM=multX; preP=plusX; if(op[i]==1){ rev=!rev; multX=multY; plusX=plusY; multY=-preM; plusY=-preP; }else if(op[i]==2){ rev=!rev; multX=-multY; plusX=-plusY; multY=preM; plusY=preP; }else if(op[i]==3){ multX*=-1; plusX*=-1; plusX+=2*p[i]; }else if(op[i]==4){ multY*=-1; plusY*=-1; plusY+=2*p[i]; } for(int j=0;j<q[i].size();j++){ if(rev){ x=xy[q[i][j]].second; y=xy[q[i][j]].first; }else{ x=xy[q[i][j]].first; y=xy[q[i][j]].second; } ans[index[i][j]]=P({plusX+multX*x,plusY+multY*y}); } } for(int i=0;i<Q;i++){ cout<<ans[i].first<<" "<<ans[i].second<<endl; } return 0; }
#include <iostream> #include <cstdio> #include <vector> #include <iomanip> #include <unordered_map> #include <unordered_set> #include <algorithm> #include <map> #include <set> #include <cmath> #include <queue> using namespace std; using VI = vector <int>; using VVI = vector <VI>; using DI = deque <int>; const int INF = 1000000000; const int UNUSED = INF+1; int solve(const VVI& adja, int f, int t) { int N = adja.size(); VI dist(N, INF); DI que; dist[f] = 0; que.push_back(f); while (!que.empty()) { int now = que.front(); que.pop_front(); for (int i = 0; i < adja[now].size(); ++i) { int nextv = adja[now][i]; if (dist[nextv] == INF) { dist[nextv] = dist[now]+1; que.push_back(nextv); } } } return dist[t]; } int solveDP(const VVI& CD, VVI& DP, int now, int st) { int &ret = DP[now][st]; int K = CD.size(); int tot = 1<<K; if (st == tot-1) { return ret = 0; } if (ret != UNUSED) { return ret; } ret = INF; for (int i = 0; i < K; ++i) { int nextv = 1<<i; if ((nextv&st) == 0 && CD[now][i] != INF) { ret = min(ret, CD[now][i] + solveDP(CD, DP, i, st|nextv)); } } // cout << "DEBUG " << now << " " << st << " " << ret << endl; return ret; } int main() { int N; int M; cin >> N >> M; VI A(M); VI B(M); VVI adja(N); for (int i = 0; i < M; ++i) { cin >> A[i] >> B[i]; --A[i]; --B[i]; adja[A[i]].push_back(B[i]); adja[B[i]].push_back(A[i]); } int K; cin >> K; VI C(K); for (int i = 0; i < K; ++i) { cin >> C[i]; --C[i]; } VVI CD(K, VI(K, INF)); for (int i = 0; i < K; ++i) { CD[i][i] = 0; for (int j = i+1; j < K; ++j) { CD[i][j] = CD[j][i] = solve(adja, C[i], C[j]); } } int tot = 1<<K; int ans = INF; VVI DP(K, VI(tot, UNUSED)); for (int i = 0; i < K; ++i) { solveDP(CD, DP, i, 1<<i); } for (int i = 0; i < K; ++i) { ans = min(ans, 1+DP[i][1<<i]); } if (ans >= INF) { cout << -1 << endl; } else { cout << ans << endl; } return 0; }
#include<iostream> #include<cctype> using namespace std; int main(void){ char a,b; cin>>a>>b; cout<<(char)(a=='Y'?toupper(b):b)<<endl; return 0; }
/** I can do this all day **/ #pragma GCC optimize("O2") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> pii; typedef pair<ll,ll> pll; #define all(x) (x).begin(),(x).end() #define F first #define S second #define Mp make_pair #define SZ(x) (int)x.size() #define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define file_io freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout); const int N = 1e6 + 10; const ll mod = 1e9 + 7; const ll mod2 = 998244353; const ll inf = 8e18; const int LOG = 22; ll pw(ll a , ll b, ll M) { return (!b ? 1 : (b & 1 ? (a * pw(a * a % M, b / 2, M)) % M : pw(a * a % M, b / 2, M))); } int main() { int x, y; cin >> x >> y; if(x == y) { cout << x << endl; } else { if(x != 0 && y != 0) cout << 0 << endl; else if(x != 1 && y != 1) cout << 1 << endl; else cout << 2 << endl; } return 0; } /** test corner cases(n = 1?) watch for overflow or minus indices **/
#include <bits/stdc++.h> using namespace std; int main(void){ string str1,str2; int i; cin >> str1; str2 = ""; for(i=0;i<str1.size();i++){ if(str1.at(str1.size()-i-1) == '6')str2 += "9"; else if(str1.at(str1.size()-i-1) == '9')str2 += "6"; else str2 += str1.at(str1.size()-i-1); } cout << str2; return 0; }
#include<bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); //freopen(".in","r",stdin); //freopen(".out","w",stdout); int n; cin >> n; int ans = n / 100; if ( n % 100 ) ans ++; cout << ans; }
#include<bits/stdc++.h> using namespace std; # define ll long long # define read read1<ll>() # define Type template<typename T> Type T read1(){ T t=0; char k; bool vis=0; do (k=getchar())=='-'&&(vis=1);while('0'>k||k>'9'); while('0'<=k&&k<='9')t=(t<<3)+(t<<1)+(k^'0'),k=getchar(); return vis?-t:t; } # define fre(k) freopen(k".in","r",stdin);freopen(k".out","w",stdout) pair<int,int>a[200005]; int s; set<int,int>se; int dis(int x,int y){return max(abs(a[x].first-a[y].first),abs(a[x].second-a[y].second));} set<pair<int,pair<int,int> > >q2; set<pair<int,int> >q,q1; int main(){ s=read; for(int i=1;i<=s;++i)a[i]=make_pair(read,read); sort(a+1,a+s+1); q.insert(make_pair(a[1].second,1)); q.insert(make_pair(a[2].second,2)); q1.insert(make_pair(-a[1].second,1)); q1.insert(make_pair(-a[2].second,2)); q2.insert(make_pair(dis(1,2),make_pair(1,2))); for(int i=3;i<=s;++i){ q2.insert(make_pair(dis(1,i),make_pair(1,i))); q2.insert(make_pair(dis(2,i),make_pair(2,i))); auto j=q.begin(); q2.insert(make_pair(dis(j->second,i),make_pair(j->second,i)));++j; q2.insert(make_pair(dis(j->second,i),make_pair(j->second,i)));j=q1.begin(); q2.insert(make_pair(dis(j->second,i),make_pair(j->second,i)));++j; q2.insert(make_pair(dis(j->second,i),make_pair(j->second,i))); q.insert(make_pair(a[i].second,i)); q1.insert(make_pair(-a[i].second,i)); q.erase(q.begin());q1.erase(q1.begin()); }auto i=q2.end();--i;--i; cout<<i->first; return 0; }
#include<bits/stdc++.h> #define dbug printf("I am here\n"); #define Fast ios_base::sync_with_stdio(false); cin.tie(0); #define vs v.size() #define ss s.size() #define sz(a) a.size() #define sot(v) sort(v.begin(),v.end()) #define all(v) (v).begin(), (v).end() #define rev(v) reverse(v.begin(),v.end()) #define revsot(v) sort(v.rbegin(),v.rend()) #define yes cout<<"YES"<<endl #define no cout<<"NO"<<endl #define ii pair<int, int> #define int long long #define ll long long #define ull unsigned long long #define pb push_back #define mpp make_pair #define Okay 0 #define pi 3.14159 const int mx = 2e6+100; const int inf = 1e18; const int mod = 1e9+7; using namespace std; void solve(){ int n; cin>>n; int res = n/100; res++; cout<<res*100 - n <<endl; } int32_t main(){ Fast; // int tst; // cin>>tst; // while(tst--) solve(); return Okay; }
#pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> #include <complex> #include <queue> #include <set> #include <unordered_set> #include <list> #include <chrono> #include <random> #include <iostream> #include <algorithm> #include <cmath> #include <string> #include <vector> #include <map> #include <unordered_map> #include <stack> #include <iomanip> #include <fstream> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> p32; typedef pair<ll,ll> p64; typedef pair<double,double> pdd; typedef vector<ll> v64; typedef vector<int> v32; typedef vector<vector<int> > vv32; typedef vector<vector<ll> > vv64; typedef vector<vector<p64> > vvp64; typedef vector<p64> vp64; typedef vector<p32> vp32; ll MOD = 998244353; double eps = 1e-12; #define forn(i,e) for(ll i = 0; i < e; i++) #define forsn(i,s,e) for(ll i = s; i < e; i++) #define rforn(i,s) for(ll i = s; i >= 0; i--) #define rforsn(i,s,e) for(ll i = s; i >= e; i--) #define ln "\n" #define dbg(x) cout<<#x<<" = "<<x<<ln #define mp make_pair #define pb push_back #define fi first #define se second #define INF 2e18 #define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) #define all(x) (x).begin(), (x).end() #define sz(x) ((ll)(x).size()) void solve(){ string s; cin>>s; for (int i = 0; i < s.size(); i++) { if(s[i]=='6'){ s[i] ='9'; } else if(s[i] == '9'){ s[i] ='6'; } } for (int i = s.size()-1; i >=0; i--) { cout<<s[i]; } } int main() { fast_cin(); // ll t; // cin >> t; // for(int it=1;it<=t;it++) { // cout << "Case #" << it+1 << ": "; solve(); // } return 0; }
#include "bits/stdc++.h" using namespace std; #define ll long long const int areTests = 0; string s; void run_test(int testcase) { cin >> s; int ans = 0; for(int pin = 0; pin < 10000; pin++) { string str = to_string(pin); while(str.size() < 4) str = "0" + str; set <int> r; for(int i = 0; i < 10; i++) { if(s[i] == 'o') r.insert(i); } int ok = 1; for(char c: str) { if(s[c - '0'] == 'x') ok = 0; else if(s[c - '0'] == 'o') { r.erase(c - '0'); } } if(ok && r.empty()) ans++; } cout << ans; } int main() { ios::sync_with_stdio(0); #ifndef LOCAL cin.tie(0); #endif cout << fixed << setprecision(10); int t = 1; if(areTests) cin >> t; for(int i = 1; i <= t; i++) { run_test(i); } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> P; #define all(v) v.begin(), v.end() const ll mod=1000000007; const string yesno(bool ans){ return (ans?"Yes":"No"); } int main() { int a,b;cin>>a>>b; int x,y; x=(a+b)/2; y=(a-b)/2; cout<<x<<" "<<y<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back int main(){ ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); int a, b, suma = 0, sumb = 0; cin >> a >> b; while(a){ suma += a % 10; a /= 10; } while(b){ sumb += b % 10; b /= 10; } cout << max(suma, sumb); return 0; }
#include <bits/stdc++.h> // #include <boost/multiprecision/cpp_int.hpp> #define rep(i,a,b) for(ll i=a;i<b;i++) #define rrep(i,b,a) for(int i=b;i>=a;i--) #define fori(a) for(auto i : a ) #define all(a) begin(a), end(a) #define set(a,b) memset(a,b,sizeof(a)) #define sz(a) a.size() double pi=acos(-1); #define ll long long #define ull unsigned long long #define pb push_back #define PF push_front //deque // #define mp make_pair #define pq priority_queue const ll mod=1000000007; #define f first #define s second #define pii pair< ll, ll > #define vi vector<int> #define vpii vector<pii> #define debug(v) for(auto i:v) cout<<i<<" "; #define tc int t; cin >> t; while(t--) // using namespace boost::multiprecision; using namespace std; void optimizeIO(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } const int N=1000005; ll fact[N],invfact[N]; ll power(ll x,ll y){ if(y<=0) return 1LL; ll z=power(x,y/2); if(y%2) return (((z*z)%mod)*x)%mod; return (z*z)%mod; } void pre(){ fact[0]=invfact[0]=invfact[1]=fact[1]=1; rep(i,2,N) fact[i]=(i*fact[i-1])%mod; rep(i,2,N) invfact[i]=(invfact[i-1]*power(i,mod-2))%mod; } ll nCr(ll n,ll k){ return (((fact[n]*invfact[n-k])%mod)*invfact[k])%mod; } const int N1=1e6+1; vector<int> isprime(N1,1),prime; void seive(){ rep(i,2,sqrt(N1)+1){ if(isprime[i]){ for(int j=i*i;j<N1;j+=i) isprime[j]=0; prime.pb(i); } } rep(i,sqrt(N1)+1,N1) if(isprime[i]) prime.pb(i); } struct dsu { vector<int> par, rank; dsu(int n): par(n+1), rank(n+1) { for (int i = 0; i <= n; i++) { par[i] = i; rank[i]= 1; } } int root(int a) { if (a == par[a]) return a; return par[a] = root(par[a]); } void merge(int a, int b) { a = root(a); b = root(b); if (a == b) return; if (rank[a] > rank[b]) swap(a, b); par[b] = a; } set<int> parent(int n){ set<int> s; for(int i=1;i<=n;i++){ s.insert(root(i)); } return s; } }; void solve(){ int n; cin>>n; int a[n],b[n]; rep(i,0,n){cin>>a[i]; b[i]=0;} rep(i,0,n) b[a[i]-1]++; int flag=0; rep(i,0,n){ if(b[i]==0 || b[i]>1) flag=1; } if(flag) cout<<"No"; else cout<<"Yes"; } int main(){ optimizeIO(); int r=1; {solve();} }
#include<bits/stdc++.h> #define int long long #define rep(i,a,b) for(register int i=(a);i<=(b);i++) #define per(i,a,b) for(register int i=(a);i>=(b);i--) using namespace std; const int N=2009,inf=0x3f3f3f3f3f3f3f3f; inline int read() { register int x=0, f=1; register char c=getchar(); while(c<'0'||c>'9') {if(c=='-') f=-1; c=getchar();} while(c>='0'&&c<='9') {x=(x<<3)+(x<<1)+c-48,c=getchar();} return x*f; } int n,m,a[N],b[N],c[N],d[N]; bool vst[N]; struct edge {int to,w;}; vector<edge>e[N]; struct node { int u,w; bool operator < (const node &b) const { return w>b.w; } }; void dijakstra(int s) { priority_queue<node>q; q.push((node){s,0}); memset(d,0x3f,sizeof(d)); d[s]=0; memset(vst,0,sizeof(vst)); while(!q.empty()) { int u=q.top().u; q.pop(); if(vst[u]) continue; vst[u]=1; for(auto ed:e[u]) if(d[ed.to]>d[u]+ed.w) d[ed.to]=d[u]+ed.w, q.push((node){ed.to,d[ed.to]}); } } signed main() { n=read(), m=read(); rep(i,1,m) a[i]=read(), b[i]=read(), c[i]=read(); rep(i,1,n) { rep(j,1,n) e[j].clear(); rep(j,1,m) { if(b[j]==i) e[a[j]].push_back((edge){n+1,c[j]}); else e[a[j]].push_back((edge){b[j],c[j]}); } dijakstra(i); printf("%lld\n",d[n+1]<inf?d[n+1]:-1ll); } return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ string S; cin >> S; char s=S.at(0); string Sback=S.substr(1); cout << Sback+s << endl; }
#include <bits/stdc++.h> #include <algorithm> using namespace std; typedef long long int ll; int main(){ string s; cin>>s; reverse(s.begin(),s.end()); for(int i=0;i<s.length();i++){ if(s[i]=='6'){ s[i]='9'; } else if(s[i]=='9'){ s[i]='6'; } } cout<<s<<endl; return 0; }
#include <bits/stdc++.h> int main(){ int N, M; std::cin >> N >> M; std::vector< std::vector< int > > AB(N); std::map< int, int > cost; for(int i=0; i<M; i++){ int a, b, c; std::cin >> a >> b >> c; a--; b--; int ab = a * N + b; auto itr = cost.find(ab); if(itr == cost.end()){ AB[a].push_back(b); cost[ab] = c; }else if(c < itr->second){ cost[ab] = c; } } for(int i=0; i<N; i++){ std::priority_queue< std::pair< int, int >, std::vector<std::pair< int, int >>, std::greater<std::pair< int, int >> > time_pos; std::pair< int, int > tmp; tmp.first = 0; tmp.second = i; time_pos.push(tmp); std::vector< int > min(N, 1e9); while(!time_pos.empty()){ tmp = time_pos.top(); time_pos.pop(); int c_pos = tmp.second; int c_time = tmp.first; if(c_time >= min[c_pos]){ continue; } if(c_time != 0){ min[c_pos] = c_time; } for(int j=0; j<AB[c_pos].size(); j++){ tmp.second = AB[c_pos][j]; tmp.first = c_time + cost[c_pos * N + AB[c_pos][j]]; if(tmp.first >= min[AB[c_pos][j]]){ continue; } time_pos.push(tmp); } } if(min[i] != 1e9){ std::cout << min[i] << std::endl; }else{ std::cout << -1 << std::endl; } } return 0; }
#include <bits/stdc++.h> #define pi 3.14159 using namespace std; typedef long long LL; const LL MOD = 1e9 + 7; const int N = 1e5 + 7, M = 1e7, OO = 0x3f3f3f3f; #define AC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin.sync_with_stdio(0); int main() { LL n,m,t,flag=1,last=0,cap; cin>>n>>m>>t; cap=n; while(m--){ LL arrive,stay; cin>>arrive>>stay; LL dis=arrive-last; n-=dis; if(n<=0){ flag=0; } n+=stay-arrive; n=min(n,cap); last=stay; } LL dis=t-last; n-=dis; if(n<=0){ flag=0; } if (flag){ cout<<"Yes"; } else{ cout<<"No"; } return 0; }
#include "bits/stdc++.h" using namespace std; using ll = long long; void Main() { double A, B, W; cin >> A >> B >> W; W *= 1000; double minimum = W / B; double maximum = W / A; bool foundMin = false; bool foundMax = false; int minInt = 1000000000; int maxInt = -1; for (int i = 1; i < 1001000; ++i) { if (minimum <= i && i <= maximum) { minInt = min(minInt, i); maxInt = max(maxInt, i); } } if (maxInt < 0) { cout << "UNSATISFIABLE" << endl; } else { cout << minInt << " " << maxInt << endl; } } int main() { std::cout << std::fixed << std::setprecision(15); Main(); return 0; }
/* Author : MatsuTaku Date : 02/18/21 */ #include <bits/stdc++.h> using namespace std; #include <x86intrin.h> #ifndef ONLINE_JUDGE #define Assert(cond) assert(cond) #else #define Assert(cond) #endif #define rep(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; i++) using lint = long long int; template<typename T> using vvec = vector<vector<T>>; template<typename T> vvec<T> make_vvec(int n, int m, T v) { return vvec<T>(n, vector<T>(m, v)); } template<typename T> void chmax(T& dst, T x) { dst = max(dst, x); } template<typename T> void chmin(T& dst, T x) { dst = min(dst, x); } class Solver { public: Solver(); void solve(); }; Solver::Solver() {} constexpr lint scale = 10000; void Solver::solve() { double _x,_y,_r; cin>>_x>>_y>>_r; lint x = (lint) round(_x*scale); lint y = (lint) round(_y*scale); lint r = (lint) round(_r*scale); lint p = (x-r)/scale * scale; lint ans = 0; while (p <= x+r) { if (p < x-r) { p += scale; continue; } lint dx = abs(x-p); lint dy = sqrt(r*r-dx*dx); // while ((dy+1)*(dy+1) + dx*dx <= r*r) dy++; while (dy*dy + dx*dx > r*r) dy--; lint by = y - dy - 1, ty = y + dy; if (by < 0) { lint add = (-by/scale+1) * scale; by += add; ty += add; } ty /= scale; by /= scale; ans += ty-by; p += scale; } cout << ans << endl; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(10); Solver solver; int t = 1; // cin>>t; while (t--) { solver.solve(); } return 0; }
#include <bits/stdc++.h> template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}} template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}} #define ll long long #define double long double #define rep(i,n) for(int i=0;i<(n);i++) #define REP(i,n) for(int i=1;i<=(n);i++) #define mod (ll)(1e9+7) #define inf (ll)(3e18+7) #define eps (double)(1e-9) #define pi (double) acos(-1) #define P pair<int,int> #define PiP pair<int,pair<int,int>> #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() using namespace std; using Graph = vector<vector<int>>; vector<ll> d, sum; void dfs1(const Graph &G, int v, int p, int D) { d[v] = D; for (auto nv : G[v]) { if (nv == p)continue; dfs1(G, nv, v, D+1); } } void dfs2(const Graph &G, int v, int p){ for (auto nv : G[v]) { if (nv == p)continue; sum[nv] += sum[v]; dfs2(G, nv, v); } } int main() { int n, q; cin >> n; Graph G(n); vector<ll> a(n-1), b(n-1); rep(i, n-1){ cin >> a[i] >> b[i]; a[i]--; b[i]--; G[a[i]].push_back(b[i]); G[b[i]].push_back(a[i]); } d.resize(n); sum.resize(n); dfs1(G, 0, -1, 0); cin >> q; rep(i, q){ ll t, e, x; cin >> t >> e >> x; e--; if(t == 1){ if(d[a[e]] < d[b[e]]){ sum[0] += x; sum[b[e]] -= x; }else{ sum[a[e]] += x; } }else{ if(d[b[e]] < d[a[e]]){ sum[0] += x; sum[a[e]] -= x; }else{ sum[b[e]] += x; } } } dfs2(G, 0, -1); rep(i, n)cout << sum[i] << endl; }
#include <bits/stdc++.h> using namespace std; vector<int> v , T; void build(int node, int l, int r) { if (l == r) { T[node] = v[l]; } else { int mid = (l + r) / 2; build(2 * node, l, mid); build(2 * node + 1, mid + 1, r); T[node] = T[2 * node] ^ T[2 * node + 1]; } } void update(int node, int start, int end, int pos, int value) { if (start == end){ T[node] = value; return; } int mid = (start + end) / 2; if (pos <= mid) { update(2 * node, start, mid, pos, value); } else update(2 * node + 1, mid + 1, end, pos, value); T[node] = T[2 * node] ^ T[2 * node + 1]; } int query(int node, int start, int end, int l, int r){ if (start > r || end < l) return 0; if (start >= l && end <= r) { return T[node]; } int mid = (start + end) / 2; int ans = query(2 * node, start, mid, l, r); int ans2 = query(2 * node + 1, mid + 1, end, l, r); return ans ^ ans2; } int main(){ int n , q; cin >> n >> q; v = vector<int>(n); for (int i = 0; i < n; i++) { cin >> v[i]; } T = vector<int>(4 * n); build(1, 0, n - 1); while (q--) { int command; cin >> command; if (command == 1) { int x , y; cin >> x >> y; --x; int ans = query(1, 0, n - 1, x, x); update(1, 0, n - 1, x, ans ^ y); } else if (command == 2) { int x, y; cin >> x >> y; --x; --y; int ans = query(1, 0, n - 1, x, y); cout << ans << endl; } else assert(false); } return 0; }
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <stack> #include <queue> #include <cmath> #include <tuple> #include <cstdio> #include <bitset> #include <sstream> #include <iterator> #include <numeric> #include <map> #include <cstring> #include <set> #include <functional> #include <iomanip> #include <cassert> using namespace std; //#define DEBUG_ //!!$BDs=P;~$K%3%a%s%H%"%&%H(B!! #ifdef DEBUG_ #define dump(x) cerr << #x << " = " << (x) << endl; #else #define dump(x) ; #endif #define equals(a,b) (fabs((a)-(b)) < EPS) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define SZ(x) ((int)(x).size()) #define pb push_back #define eb emplace_back //#define int long long typedef long long LL; typedef vector<int> VI; typedef vector<LL> VL; typedef vector<VI> VVI; typedef vector<VL> VVL; typedef vector<string> VS; typedef pair<int, int> PII; typedef pair<LL, LL> PLL; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } template <typename T> std::string printVector(const std::vector<T> &data) { std::stringstream ss; std::ostream_iterator<T> out_it(ss, ", "); ss << "["; std::copy(data.begin(), data.end() - 1, out_it); ss << data.back() << "]"; return ss.str(); } template <typename T> void print_array(const T &ary, int size){ REP(i,size){ cout << ary[i] << " "; } cout << endl; } const int mod = 1e9+7; //const int mod = 998244353; const LL LINF = 1001002003004005006ll; const int INF = 1001001001; const double EPS = (1e-10); const long double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899; int dx[] = {0,0,-1,1}; int dy[] = {-1,1,0,0}; LL N,K; bool check(LL mid, const VVL& A){ dump(mid) LL half = (K*K+1) / 2; VVL acc(N,VL(N)); REP(i,N) REP(j,N){ if(i == 0 && j == 0){ if(A[0][0] <= mid) acc[i][j] = 1; else acc[i][j] = 0; }else if(i == 0){ if(A[i][j] <= mid){ acc[i][j] = acc[i][j-1] + 1; }else{ acc[i][j] = acc[i][j-1]; } }else if(j == 0){ if(A[i][j] <= mid){ acc[i][j] = acc[i-1][j] + 1; }else{ acc[i][j] = acc[i-1][j]; } }else{ if(A[i][j] <= mid){ acc[i][j] = acc[i-1][j] + acc[i][j-1] - acc[i-1][j-1] + 1; }else{ acc[i][j] = acc[i-1][j] + acc[i][j-1] - acc[i-1][j-1]; } } } //REP(i,N){ // REP(j,N){ // cerr << acc[i][j] << " "; // } // cerr << endl; //} REP(i,N) REP(j,N){ if(i-K < -1 or j-K < -1) continue; LL tx,ty,tz; if(i-K == -1){ tx = 0; }else{ tx = acc[i-K][j]; } if(j-K == -1){ ty = 0; }else{ ty = acc[i][j-K]; } if(i-K == -1 or j-K == -1){ tz = 0; }else{ tz = acc[i-K][j-K]; } //LL cnt = acc[i][j] - acc[i-K][j] - acc[i][j-K] + acc[i-K][j-K]; LL cnt = acc[i][j] - tx - ty + tz; dump(cnt) dump(half) if(cnt >= half) { return true; } } return false; } signed main(int argc, char const *argv[]) { cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(12); //LL N,K; cin >> N >> K; vector<VL> A(N,VL(N)); REP(i,N) REP(j,N){ cin >> A[i][j]; } LL ok = INF; //LL ng = INF; LL ng = -1; while(abs(ok-ng) > 1){ LL mid = (ok + ng) / 2; if(check(mid,A)){ dump("ok") ok = mid; }else{ dump("ng") ng = mid; } } cout << ok << endl; }
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <cmath> #include <cstdio> #include <deque> #include <functional> #include <iostream> #include <iterator> #include <map> #include <queue> #include <set> #include <string> #include <sstream> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; #if __has_include(<atcoder/all>) #include <atcoder/all> using namespace atcoder; #endif #define GET_MACRO(_1, _2, _3, NAME, ...) NAME #define _rep(i, n) _rep2(i, 0, n) #define _rep2(i, a, b) for(int i = (int)(a); i < (int)(b); i++) #define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() using i64 = long long; template<class T> bool chmin(T& a, const T& b) { return (b < a) ? (a = b, true) : false; } template<class T> bool chmax(T& a, const T& b) { return (b > a) ? (a = b, true) : false; } template<typename T>istream& operator>>(istream&i,vector<T>&v){rep(j,v.size())i>>v[j];return i;} template<typename T>string join(vector<T>&v){stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);} template<typename T>ostream& operator<<(ostream&o,vector<T>&v){if(v.size())o<<join(v);return o;} template<typename T>string join(vector<vector<T>>&vv){string s="\n";rep(i,vv.size())s+=join(vv[i])+"\n";return s;} template<typename T>ostream& operator<<(ostream&o,vector<vector<T>>&vv){if(vv.size())o<<join(vv);return o;} int main() { int a, b, w; cin >> a >> b >> w; w *= 1000; auto x = w / b; if (x * b < w && w < a * (x + 1)) { return cout << "UNSATISFIABLE" << endl, 0; } int mi; if (w % b == 0) mi = x; else mi = x + 1; int y = w / a; int z = w - y * a; if (a <= z) y++; cout << mi << " " << y << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxN = 205; vector <int> v[2]; int dp[maxN][maxN][maxN][2][2]; int a[maxN]; int n; int rec(int pos = 0, int s1 = 0, int s2 = 0, bool ac1 = 0, bool ac2 = 0) { if(pos == n) return (s1 == s2 && ac1 && ac2); int &res = dp[pos][s1][s2][ac1][ac2]; if(~res) return res; res = rec(pos + 1, s1, s2, ac1, ac2); if(res) return res; // Give current pos to s1 int new_s1 = (s1 + a[pos]) % 200; res = rec(pos + 1, new_s1, s2, ac1 || 1, ac2); if(res) { v[0].push_back(pos + 1); return res; } // Give current pos to s2 int new_s2 = (s2 + a[pos]) % 200; res = rec(pos + 1, s1, new_s2, ac1, ac2 || 1); if(res) { v[1].push_back(pos + 1); return res; } return res; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; for(int i = 0; i < n; i++) { cin >> a[i]; a[i] %= 200; } memset(dp, -1, sizeof dp); int res = rec(); if(res) { sort(v[0].begin(), v[0].end()); sort(v[1].begin(), v[1].end()); cout << "Yes\n"; cout << v[0].size(); for(int &x : v[0]) { cout << ' ' << x; } cout << '\n'; cout << v[1].size(); for(int &x : v[1]) { cout << ' ' << x; } } else { cout << "No"; } }
#include <bits/stdc++.h> #define debug(x) cerr << #x << " = " << x << endl using namespace std; typedef long long LL; const int MAXN = 55; const int MOD = 1E9 + 7; LL n, x, a[MAXN], g[MAXN], lim[MAXN], dp[MAXN][2]; template <class T> void read(T& x) { x = 0; T f = 1; char ch = getchar(); while (ch < '0' || ch > '9') f = (ch == '-' ? -1 : 1), ch = getchar(); while (ch >= '0' && ch <= '9') x = x * 10 + ch - 48, ch = getchar(); x *= f; } template <class T, class... Args> void read(T& x, Args&... args) { read(x), read(args...); } template <class T> void write(T x) { if (x < 0) putchar('-'), x = -x; if (x > 9) write(x / 10); putchar(x % 10 + '0'); } signed main() { // freopen("1.in", "r", stdin); read(n, x); for (int i = 1; i <= n; i++) read(a[i]); for (int i = n; i >= 1; i--) { if (!x) break; g[i] = x / a[i], x %= a[i]; } for (int i = n - 1; i >= 1; i--) { lim[i] = a[i + 1] / a[i]; dp[i][0] = (g[i] != 0); dp[i][1] = (g[i] != lim[i] - 1); if (g[i] == 0) { dp[i][0] += dp[i + 1][0]; dp[i][1] += dp[i + 1][1] + dp[i + 1][0]; } else if (g[i] == lim[i] - 1) { dp[i][0] += dp[i + 1][0] + dp[i + 1][1]; dp[i][1] += dp[i + 1][1]; } else { dp[i][1] += dp[i + 1][1] + dp[i + 1][0]; dp[i][0] += dp[i + 1][0] + dp[i + 1][1]; } } cout << dp[1][0] + 1; return 0; }
#include<iostream> #include<vector> #include<cmath> #include<string> #include<algorithm> #include<map> #include<utility> #include<cstdio> #include<cmath> #include<bits/stdc++.h> using namespace std; using ll = long long; const long long INF = 1LL<<60; const ll di[] = {-1, 0, 1, 0}; const ll dj[] = {0, -1, 0, 1}; vector<ll> load[100005]; typedef pair<ll,ll> Pair; int main(){ ll N; unordered_set<ll> p; cin >> N; ll cnt = 0; for(ll i = 2;i*i <=N;++i){ for(ll j =i*i;j<=N;j*=i){ p.insert(j); } } /* for(ll i = 2;i*i <=N;++i){ ll ok = 1; ll ng = 34; while(ng-ok != 1){ ll wj = (ok+ng)/2; if(pow(i,wj)<=N){ ok = wj; } else{ ng = wj; } } cout << i <<" " << ok << endl; cnt+=(ok-1); } cout << N - cnt << endl; */ cout << N - p.size() << endl; return 0; }
#include <bits/stdc++.h> #define REP(i, nn ) for(int i = 0 ; i < (int) nn; i++) #define REPS(i, ss, nn ) for(int i = ss ; i < (int) nn; i++) #define REV(i, ss, nn ) for(int i = ss ; i >= nn; i--) #define deb(x) std::cout << #x << " " << x << endl; #define debl(x) std::cout << #x << " " << x << " "; #define all(x) x.begin(), x.end() using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; namespace std{ template<class Fun> class y_combinator_result{ Fun fun_; public: template<class T> explicit y_combinator_result(T &&fun) : fun_(std::forward<T>(fun)){} template<class ...Args> decltype(auto) operator()(Args&&...args){ return fun_(std::ref(*this), std::forward<Args>(args)...); } }; template<class Fun> decltype(auto) y_combinator(Fun && fun){ return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun)); } }; template<typename T> bool umax(T& a, T b){ bool ret = a < b; if(ret) a = b; return ret; } template<typename T> bool umin(T& a, T b){ bool ret = a > b; if(ret) a = b; return ret; } struct edge{ int to; ll cost; int from; edge(){ edge(0,0);} edge(int to_, ll cost_) : to(to_), cost(cost_){} edge(int to_, int from_, ll cost_) : to(to_), cost(cost_), from(from_){} }; template<typename... T> void read(T& ... a){ ((cin >> a),...); } template<typename... T> void write(T... a){ ((cout << a),...); } template<typename T> vector<T> read_array(int sz){ vector<T> ret(sz); for(auto & x : ret) cin >> x; return ret; } void solve(){ ll n; read(n); set<ll> st; for(ll k = 2; k * k <= n; k++){ ll a = k * k; while(a <= n){ st.insert(a); a *= k; } } ll ans = n - st.size(); write(ans, "\n"); } int main() { //making data IO Fast std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); /****************************/ int T = 1; // cin >> T; while(T--) solve(); return 0; }
#include <bits/stdc++.h> #define ll long long #define int long long #define arr(a) new int[a] #define db1(x) cout<<#x<<"="<<x<<'\n' #define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n' #define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n' #define dbV(arr) cout << #arr << "=[ "; \ for(auto i:arr) cout << i << " "; cout << "]\n"; #define rep(i,n) for(int i = 0; i < (n); ++i) #define repF(i,a,n) for(int i = (a); i <= (n); ++i) #define repB(i,a,n) for(int i = (a); i >= (n); --i) #define test(t) int t;cin>>t;while(t--) #define inp(a) int a;cin>>a; #define pii pair<int,int> #define pll pair<ll,ll> #define vi vector<int> #define vl vector<ll> #define umii unordered_map<int,int> #define umll unordered_map<ll,ll> #define mii map<int,int> #define mll map<ll,ll> #define seti set<int> #define setl set<ll> #define pb push_back #define F first #define S second #define MOD 1000000007 #define all(z) z.begin(),z.end() using namespace std; void printArray(int a[],int n) { rep(i,n) cout<<a[i]<<" "; cout<<"\n"; } void printVec(vi v) { int s = v.size(); rep(i,s) cout<<v[i]<<" "; cout<<"\n"; } void printBool(bool b) { if(b) cout<<"YES\n"; else cout<<"NO\n"; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t,n;cin>>t>>n; int ans = ceil((100.0*n)/(t + 0.0)) + n - 1; cout<<ans; return 0; }
#include<bits/stdc++.h> using namespace std; #define loopi(n) for(ll i=0;i<n;i++) #define loopj(n) for(ll j=0;j<n;j++) #define loopk(n) for(ll k=0;k<n;k++) #define loopnode(v) for(ll i : v) #define mod7 1000000007 #define mod9 1000000009 #define mod8 100000000 #define modl 998244353 #define pb push_back #define mp make_pair #define fst first #define scnd second typedef long long ll; typedef long double ld; typedef std::vector<ll> vecl; typedef std::vector<bool> vecb; typedef std::vector<long double> vecd; typedef std::vector<string> vecstr; typedef std::vector<char> vecch; typedef std::vector< pair<ll,ll> > vecpair; typedef unordered_map<ll,ll> umap; typedef unordered_map<long double,int> umapd; typedef unordered_map<string,ll> umapstr; typedef unordered_map<char,ll> umapc; typedef set< ll,greater<ll> > st; typedef priority_queue<ll> q_max; typedef priority_queue<ll,vector<ll>,greater<ll> > q_min; typedef map<ll,ll> mapl; int main() { ll t,N;cin>>t>>N; if((N*100)%t == 0) cout<<((N*100)/t) + N -1; else cout<<((N*100)/t) + N; return 0; }
#include<bits/stdc++.h> using namespace std; #define IOS ios::sync_with_stdio(false);cin.tie(0); #define ch(a) (int(a-'a')+1) #define mm(a) memset(a,0,sizeof(a)) #define rep(i,a,b) for(int i=(a);i<=(b);i++) #define inf 0x7FFFFFFF typedef long long ll; const int Maxx=3*1e5+10; ll a[Maxx]; int main() { int n; IOS; cin>>n; rep(i,1,n) cin>>a[i]; ll ans=1LL*(n-1)*n/2; sort(a+1,a+n+1); ll tmp=1; for(int i=1;i<=(n-1);i++) { if(a[i]==a[i+1]) { ++tmp; } else { ans-=1LL*(tmp-1)*tmp/2;tmp=1; } } ans-=1LL*(tmp-1)*tmp/2; cout<<ans<<endl; return 0; }
#pragma region Macros #include <bits/stdc++.h> #if defined(LOCAL) || defined(ONLINE_JUDGE) || defined(_DEBUG) #include <atcoder/all> #endif using namespace std; #define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i) #define REPR(i, n) for(int i=(n); i>=0; --i) #define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i) #define EACH(i, v) for(const auto& i : v) #define ALL(x) (x).begin(),(x).end() #define ALLR(x) (x).rbegin(),(x).rend() template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } template<class T>using vec = vector<T>; template<class T, class U>using umap = unordered_map<T, U>; using ll = long long; using P = pair<ll, ll>; using vl = vec<ll>; #define fi first #define se second #define el endl constexpr ll INF = numeric_limits<ll>::max()/2-1; #pragma endregion #pragma region IOMacros template<class T> istream &operator>>(istream &stream, vec<T>& o){REP(i, o.size())stream >> o[i];return stream;} template<class T> ostream &operator<<(ostream &stream, vec<T>& objs){REP(i, objs.size())stream << objs[i] << " ";stream << el;return stream;} #define I(T, ...) ;T __VA_ARGS__;__i(__VA_ARGS__); void __i() {} template<class T, class... Ts> void __i(T&& o, Ts&&... args){cin >> o;__i(forward<Ts>(args)...);} void O() {cout << el;} template<class T, class... Ts> void O(T&& o, Ts&&... args){cout << o << " ";O(forward<Ts>(args)...);} #pragma endregion void Main(); int main(){ std::cin.tie(nullptr); std::cout << std::fixed << std::setprecision(15); Main(); return 0; } // 約数列挙 //O(√N) vector<ll> enumDivisors(ll N) { vector<ll> res1, res2; for (ll i = 1; i * i <= N; ++i) { if (N % i == 0) { res1.push_back(i); if (N/i != i) res2.push_back(N/i); } } res1.reserve(res1.size()+res2.size()); copy(res2.rbegin(), res2.rend(), back_inserter(res1)); return res1; } void Main(){ I(ll, N); auto div = enumDivisors(N); EACH(v, div){ cout << v << el; } }
#include <bits/stdc++.h> #define ll long long #define X first #define Y second #define pii pair<int,int> #define ld long long double using namespace std; int const N = 18; int x[N], y[N], z[N]; int target; ll oo = 1e16; int n; ll mem[N][1<<18]; ll cal(int i, int j){ return abs(x[i] - x[j]) + abs(y[i]-y[j]) + max(0, z[j]-z[i]); } ll dp(int nd, int mask){ if((mask&target) == target){ return cal(nd, 0); } ll &ret = mem[nd][mask]; if(~ret) return ret; ret = oo; for(int i=0; i<n; i++){ if((mask & (1<<i)) == 0){ ret = min(ret, dp(i, mask | (1<<i)) + cal(nd, i)); } } return ret; } void test() { memset(mem, -1, sizeof(mem)); cin>>n; target = (1<<n) - 1; for(int i=0; i<n; i++){ cin>>x[i]>>y[i]>>z[i]; } cout<<dp(0, 1)<<'\n'; } int main() { #ifdef ONLINE_JUDGE ios::sync_with_stdio(false), cin.tie(0); #endif #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif int t = 1; // cin >> t; for (int i = 1; i <= t; i++) { test(); } }
#include "bits/stdc++.h" //#include "atcoder/all" using namespace std; //using namespace atcoder; //using mint = modint1000000007; #define endl "\n" vector<bool>B(100005); vector<bool>B2(100005); vector<int>Ans(100005); struct Edge { int to, id; Edge(int to, int id) :to(to), id(id) {} }; vector<Edge>g[100005]; vector<Edge>g2[100005]; void dfs(int v, int p = -1) { if (B[v]) { return; } B[v] = true; for (Edge e : g[v]) { if (p == e.to) { continue; } if (B[e.to]) { continue; } g2[v].emplace_back(e.to, e.id); dfs(e.to, v); } return; } void dfs2(int v, int id = -1, int p = -1) { Ans[v] = id; if (-1 != id) { B2[id] = true; } for (Edge e : g2[v]) { if (p == e.to) { continue; } if (Ans[v] != e.id) { dfs2(e.to, e.id, v); } else { dfs2(e.to, -1, v); } } return; } int main() { int N, M; cin >> N >> M; for (int n = 0; n < M; ++n) { int a, b, c; cin >> a >> b >> c; a--; b--; c--; g[a].emplace_back(b, c); g[b].emplace_back(a, c); } for (int i = 0; i < N; ++i) { B[i] = false; B2[i] = false; } dfs(0); dfs2(0); int memo = 0; for (; memo < N; ++memo) { if (!B2[memo]) { break; } } for (int n = 0; n < N; ++n) { if (-1 == Ans[n]) { Ans[n] = memo; } cout << Ans[n] + 1 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); ll n; cin >> n; if(n % 100 == 0) { cout << 100; return 0; } else { ll p = n / 100; p++; p = p * 100; cout << abs(p - n); return 0; } }
#include <iostream> #include <iomanip> #include <algorithm> #include <assert.h> #include <complex> #include <utility> #include <vector> #include <string> #include <stack> #include <queue> #include <tuple> #include <cmath> #include <bitset> #include <cctype> #include <set> #include <map> #include <unordered_map> #include <numeric> #include <functional> #include <chrono> #define _overload3(_1,_2,_3,name,...) name #define _rep(i,n) repi(i,0,n) #define repi(i,a,b) for(ll i=a;i<b;++i) #define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__) #define _rrep(i,a) rrepi(i,a,0) #define rrepi(i,a,b) for(ll i=a-1;i>=b;--i) #define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__) #define all(x) (x).begin(),(x).end() #define PRINT(V) cout << V << "\n" #define SORT(V) sort((V).begin(),(V).end()) #define RSORT(V) sort((V).rbegin(), (V).rend()) using namespace std; using ll = long long; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); } template<class itr> void cins(itr first,itr last){ for (auto i = first;i != last;i++){ cin >> (*i); } } template<class itr> void array_output(itr start,itr goal){ string ans = "",k = " "; for (auto i = start;i != goal;i++) ans += to_string(*i)+k; if (!ans.empty()) ans.pop_back(); PRINT(ans); } ll gcd(ll a, ll b) { return a ? gcd(b%a,a) : b; } const ll INF = 1e18; const ll MOD = 1000000007; const ll MOD2 = 998244353; const ll MOD3 = 1e6; const ll EPS = 1e-10; int sgn(const double a){ return (a < -EPS ? -1 : (a > EPS ? +1 : 0)); } typedef pair<int,int> pi; typedef pair<ll,ll> P; typedef tuple<ll,ll,ll> tri; typedef pair<double,double> point; typedef complex<double> Point; typedef string::const_iterator State; const ll MAX = 125000; constexpr ll nx[4] = {-1,0,1,0}; constexpr ll ny[4] = {0,1,0,-1}; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); ll x; cin >> x; PRINT((x/100+1)*100-x); }
#include <iostream> int main() { int N; std::cin>>N; int result=1e9+1; int A,P,X; for(int i=0;i<N;i++) { std::cin>>A>>P>>X; if(X-A>0)if(result>P)result=P; } if(result==1e9+1)result=-1; std::cout<<result<<std::endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int N; cin >> N; 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]; int mx = 0; int mn = 10000; for(int i = 0; i < N; i++){ mx = max (A[i], mx); mn = min(B[i], mn); } if(mx > mn){ cout << 0 << endl; } else{ cout << mn - mx + 1 << endl; } }
#include <stdio.h> #include <iostream> #include <vector> #include <queue> #include <stack> #include <algorithm> using ll = long long int; const int INF = (1<<30); const ll INFLL = (1ll<<60); const ll MOD = (ll)(1e9+7); #define l_ength size void mul_mod(ll& a, ll b){ a *= b; a %= MOD; } void add_mod(ll& a, ll b){ a = (a<MOD)?a:(a-MOD); b = (b<MOD)?b:(b-MOD); a += b; a = (a<MOD)?a:(a-MOD); } ll p[225816],q[225816],r[225816],s[225816],t[225816],u[225816],x[225816],y[225816]; int main(void){ int n,m,l,i,o,a,b; ll k; p[0] = 1ll; t[0] = 1ll; std::cin >> n; for(i=0; i<n; ++i){ std::cin >> x[i] >> y[i]; } std::cin >> m; for(i=0; i<m; ++i){ std::cin >> o; switch(o){ case 1: p[i+1] = s[i]; q[i+1] = t[i]; r[i+1] = u[i]; s[i+1] = -p[i]; t[i+1] = -q[i]; u[i+1] = -r[i]; break; case 2: p[i+1] = -s[i]; q[i+1] = -t[i]; r[i+1] = -u[i]; s[i+1] = p[i]; t[i+1] = q[i]; u[i+1] = r[i]; break; case 3: std::cin >> k; p[i+1] = -p[i]; q[i+1] = -q[i]; r[i+1] = k*2-r[i]; s[i+1] = s[i]; t[i+1] = t[i]; u[i+1] = u[i]; break; case 4: std::cin >> k; p[i+1] = p[i]; q[i+1] = q[i]; r[i+1] = r[i]; s[i+1] = -s[i]; t[i+1] = -t[i]; u[i+1] = k*2-u[i]; break; } } std::cin >> l; for(i=0; i<l; ++i){ std::cin >> a >> b; --b; std::cout << (x[b]*p[a]+y[b]*q[a]+r[a]) << " " << (x[b]*s[a]+y[b]*t[a]+u[a]) << std::endl; } return 0; }
#include <bits/stdc++.h> #define repd(i, a, b) for (ll i = (a); i < (b); i++) #define repb(i, n) for (ll i = (n)-1; i >= 0; i--) #define rep(i, n) repd(i, 0, n) using namespace std; using ll = long long; using ul = unsigned long long; using ld = long double; const ul mod = 1000000007; class number { public: ll a; ll b; ll other; ll num(ll x, ll y) { return x * a + y * b + other; } }; using p = pair<number, number>; p op2(number x, number y) { number nx, ny; nx = {-y.a, -y.b, -y.other}; ny = x; return make_pair(nx, ny); } p op1(number x, number y) { number nx, ny; nx = y; ny = {-x.a, -x.b, -x.other}; return make_pair(nx, ny); } p op3(number x, number y, ll axis) { number nx; nx = {x.a, x.b, x.other - axis}; nx = {-nx.a, -nx.b, -nx.other}; nx = {nx.a, nx.b, nx.other + axis}; return make_pair(nx, y); } p op4(number x, number y, ll axis) { number ny; ny = {y.a, y.b, y.other - axis}; ny = {-ny.a, -ny.b, -ny.other}; ny = {ny.a, ny.b, ny.other + axis}; return make_pair(x, ny); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n; cin >> n; vector<ll> x(n), y(n); rep(i, n) { cin >> x[i] >> y[i]; } ll m; cin >> m; vector<p> v(m + 1); v[0] = {{1, 0, 0}, {0, 1, 0}}; rep(i, m) { number bx = v[i].first; number by = v[i].second; ll num; cin >> num; if (num <= 2) { if (num == 1) { v[i + 1] = op1(bx, by); } else { v[i + 1] = op2(bx, by); } } else { ll axis; cin >> axis; if (num == 3) { v[i + 1] = op3(bx, by, axis); } else { v[i + 1] = op4(bx, by, axis); } } } ll q; cin >> q; vector<ll> a(q), b(q); rep(i, q) { cin >> a[i] >> b[i]; b[i]--; } rep(i, q) { number nx, ny; nx = v[a[i]].first; ny = v[a[i]].second; ll ans_x = nx.num(x[b[i]], y[b[i]]); ll ans_y = ny.num(x[b[i]], y[b[i]]); cout << ans_x << " " << ans_y << endl; } return 0; }
#include <iostream> #include <cstdio> #include <cmath> #include <ctime> #include <cstdlib> #include <cassert> #include <vector> #include <list> #include <stack> #include <queue> #include <deque> #include <map> #include <set> #include <bitset> #include <string> #include <algorithm> #include <utility> #define rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++) #define chmin(x, y) (x) = min((x), (y)) #define chmax(x, y) (x) = max((x), (y)) #define all(x) (x).begin(),(x).end() #define inf 1e18 using namespace std; typedef long long llint; typedef pair<llint, llint> P; llint h, w, n, m; llint a[1505][1505]; bool r[1505][1505]; int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> h >> w >> n >> m; llint y, x; rep(i, 1, n){ cin >> y >> x; a[x][y] = 1; } rep(i, 1, m){ cin >> y >> x; a[x][y] = -1; } rep(y, 1, h){ llint b = 0; rep(x, 1, w){ if(a[x][y]) b = a[x][y]; if(b > 0) r[x][y] = true; } b = 0; for(int x = w; x >= 1; x--){ if(a[x][y]) b = a[x][y]; if(b > 0) r[x][y] = true; } } rep(x, 1, w){ llint b = 0; rep(y, 1, h){ if(a[x][y]) b = a[x][y]; if(b > 0) r[x][y] = true; } b = 0; for(int y = h; y >= 1; y--){ if(a[x][y]) b = a[x][y]; if(b > 0) r[x][y] = true; } } llint ans = 0; rep(y, 1, h){ rep(x, 1, w){ if(r[x][y]) ans++; } } cout << ans << endl; return 0; }
#include<bits/stdc++.h> #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC optimization ("unroll-loops") using namespace std; #define TRACE #ifdef TRACE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char* name, Arg1&& arg1){ cerr << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...); } #else #define trace(...) #endif //#define int long long const int N=1505; int h,w,n,m,a[N][N],cnt[N][N]; int32_t main(){ ios_base:: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin>>n>>m>>h>>w; for(int i=1;i<=h;i++){ int r,c;cin>>r>>c; a[r][c]=1; } for(int i=1;i<=w;i++){ int r,c;cin>>r>>c; a[r][c]=-1; } for(int i=1;i<=n;i++){ for(int j=1,flg=0;j<=m;j++){ if(a[i][j]==1)flg=1; else if(a[i][j]==-1)flg=0; cnt[i][j]|=flg; } for(int j=m,flg=0;j>=1;j--){ if(a[i][j]==1)flg=1; else if(a[i][j]==-1)flg=0; cnt[i][j]|=flg; } } for(int j=1;j<=m;j++){ for(int i=1,flg=0;i<=n;i++){ if(a[i][j]==1)flg=1; else if(a[i][j]==-1)flg=0; cnt[i][j]|=flg; } for(int i=n,flg=0;i>=1;i--){ if(a[i][j]==1)flg=1; else if(a[i][j]==-1)flg=0; cnt[i][j]|=flg; } } int ans = 0; for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)ans+=cnt[i][j]; cout<<ans; }
#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>; const int MOD = 1000000007; int main() { int T; cin >> T; rep(i, T) { ll N, A, B; cin >> N >> A >> B; ll d = max(0LL, N - A - B + 1) % MOD; ll ans = 2 * d % MOD * (d + 1) % MOD * (N - A + 1) % MOD * (N - B + 1) % MOD - d * d % MOD * (d + 1) % MOD * (d + 1) % MOD; if (ans < 0) ans += MOD; cout << ans << endl; } }
// Author : Sarthak Kapoor #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; #define int ll #define rep(i,n) for(int i=0;i<n;++i) #define repa(i,a,n) for(int i=a;i<n;++i) #define repr(i,n) for(int i=n-1;i>=0;--i) #define ll long long #define pi pair<int,int> #define pii pair<pi,int> #define vi vector<int> #define pb push_back #define fi first #define sec second #define all(v) v.begin(),v.end() #define s(v) v.size() ll mod = 1000000007; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1] ll gcd(ll a,ll b){ if(b==0)return a; return gcd(b,a%b); } ll fastexp(ll x,ll a){ ll res = 1; while(a>0){ if(a&1){ res = (res*x)%mod; } a=a>>1; x=(x*x)%mod; } return res; } ll inverse(ll n){ return fastexp(n,mod-2); } template <typename T> void add(T &a, T b){ a += b; if(a >= mod)a -= mod; } template <typename T> void sub(T &a, T b){ a -= b; if(a < 0)a += mod; } template <typename T> void mul(T &a, T b){ a *= b; if(a >= mod)a %= mod; } signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int a,b; cin>>a>>b; int sign = 1; if(b > a){ sign = -1; } vi v(a+b); int sum = 0; rep(i,max(a,b)){ v[i] = sign*(i+1); sum += (i+1); } sign *= (-1); int j = 1; repa(i,max(a,b),a+b-1){ v[i] = sign*(j); sum -= j; j++; } v[a+b-1] = sign*sum; rep(i,a+b){ cout<<v[i]<<" "; } return 0; }
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; //template #define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define ALL(v) (v).begin(),(v).end() using ll=long long int; const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12; template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;} template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;} //end int main(){ int n,k; cin>>n>>k; using P=pair<ll,ll>; vector<P> ps(n); rep(i,0,n)cin>>ps[i].first>>ps[i].second; sort(ALL(ps)); vector<ll> a(n+1),b(n+1); rep(i,1,n+1){ a[i]=ps[i-1].first; b[i]=ps[i-1].second; } ll cur=k; rep(i,1,n+1){ if(cur<a[i]-a[i-1]){ cout<<cur+a[i-1]<<'\n'; return 0; } else{ cur-=a[i]-a[i-1]; cur+=b[i]; } } cout<<cur+a.back()<<'\n'; return 0; }
#include"bits/stdc++.h" using namespace std; typedef long long ll; int main(){ ll n,k; cin>>n>>k; vector<pair<ll,ll>>a(n); for(ll i=0;i<n;i++)cin>>a[i].first>>a[i].second; sort(a.begin(),a.end()); ll now=0; for(ll i=0;i<n;i++){ if(k-(a[i].first-now)<0){ cout<<now+k<<endl; return 0; } k-=(a[i].first-now); k+=a[i].second; now=a[i].first; } cout<<now+k<<endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i,a,n) for (int i=a;i<n;i++)//iをaからn #define per(i,n,a) for (int i=a-1;i>=n;i--)//iをnからa #define db(x) cout << #x << " = " << x << endl #define db2(x, y) cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"; //デバッグ用 #define all(x) (x).begin(), (x).end() #define INF 1000000000000 //10^12:∞ #define MOD 1000000007 //10^9+7:合同式の法 #define pb push_back #define F first #define S second typedef long long ll; //sort(all(a)); ソート //sort(all(a),greater<int>()); 逆順ソート //a.erase(unique(all(a)), a.end()); ソート後に重複を削除 //cout<< std::fixed << std::setprecision(15)<<0.000001<<endl; 小数点以下を表示させる //vector<vector<int>> data(3, vector<int>(4)); int型の2次元配列(3×4要素の)の宣言 int main(){ int a,b,c; cin>>a>>b>>c; int ans=a+b+c-min({a,b,c}); cout<<ans; }
#include <bits/stdc++.h> using namespace std; int main() { int arr[3]; for(int i=0;i<3;i++){ cin>>arr[i]; } sort(arr,arr+3); cout<<(arr[1]+arr[2]); return 0; }
#include<bits/stdc++.h> using namespace std; using ll = long long; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define repll(i,n) for(long long i = 0; i < (long long)(n); i++) int main(){ int t; cin >> t; rep(i, t){ string s; cin >> s; int ans = 0; if(string(s.size(), 'a') == s) ans = -1; else if(s > "atcoder") ans = 0; else{ int k; rep(j, s.size()){ if(s[j] != 'a'){ k = j; break; } } if(s[k] > 't') ans = k - 1; else ans = k; } cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define ff first #define ss second #define rsz resize #define ins insert #define mp make_pair #define pf push_front #define pb push_back #define eb emplace_back #define ft front() #define bk back() #define sz(x) (int)(x).size() #define all(x) begin(x), end(x) #define rep(i,a,b) for (int i = (a); i < (b); ++i) #ifndef ONLINE_JUDGE #define deb(x) cerr<< #x <<" "; __print(x); cerr<<endl; #else #define deb(x) #endif const ll mod = 1e9+7; // 998244353; const ll inf = 1e18; const ld pie = acos((ld)-1); 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;} int dx[] = {1, -1, 0, 0}; int dy[] = {0, 0, 1, -1}; void __print(int x) {cerr<<x;} void __print(char x) {cerr<<x;} void __print(string x) {cerr<<x;} void __print(float x) {cerr<<x;} void __print(double x) {cerr<<x;} void __print(bool x) {cerr<<x;} void __print(ll x) {cerr<<x;} template<class T, class U> void __print(pair<T,U> p) {cerr<<"{"<<p.ff<<", "<<p.ss<<"}";} template<class T> void __print(vector<T> arr) { cerr<<"[ "; for(auto x:arr) { __print(x);cerr<<" "; } cerr<<"]"; } template<class T> void __print(set<T> st) { cerr<<"{ "; for(auto x:st) { __print(x); cerr<<" "; } cerr<<"}";} template<class T, class U> void __print(vector<pair<T,U>> arr) { cerr<<"[ "; for(auto x:arr) {__print(x);cerr<<", ";}cerr<<"]";} template<class T, class U> void __print(unordered_map<T,U> arr) { cerr<<"{ "; for(auto x:arr) {__print(x);cerr<<", ";}cerr<<"}";} template<class T, class U> void __print(map<T,U> arr) { cerr<<"{ "; for(auto x:arr) {__print(x);cerr<<", ";}cerr<<"}";} template<typename... T> void read(T&... args) { ((cin>>args),...);} template<typename... T> void write(T&&... args){((cout<<args<<" "),...);cout<<'\n';} int main(){ int N; scanf("%d", &N); string s,t; cin >> s >> t; int cs0 = 0, ct0 = 0; rep(i, 0, N) { if(s[i] == '0') { cs0++; } if(t[i] == '0') { ct0++; } } if(cs0 != ct0) { puts("-1"); return 0; } int cs = 0, ct = 0; int ans = cs0; rep(i, 0, N) { if(s[i] == '0') { cs++; } if(t[i] == '0') { ct++; } if(s[i] == t[i] && t[i] == '0' && cs == ct) { ans--; } } printf("%d\n", ans); return 0; /*STUFF TO LOOK: 1. Check the constraints 2. Corner cases(n==0||n==1) 3. Variables in loops 4. Make sure two ints aren’t multiplied to get a long long 5. Don't use scanf or printf while using ios_base 6. using the local variable of the same name when global variable was required to be used */ }
#include<bits/stdc++.h> using namespace std; #define int long long signed main(){ int x; cin>>x; cout<<max(x,0ll)<<endl; }
#include<bits/stdc++.h> using namespace std; int main() { int x; cin >> x; if(x < 0) cout << "0" << endl; else cout << x << endl; }
#pragma GCC optimize("O3") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> // find_by_order(k): It returns to an iterator to the kth element (counting from zero) in the set // order_of_key(k) : It returns to the number of items that are strictly smaller than our item k #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define pb push_back #define f first #define s second #define F(i,a,b) for(i=a;i<b;i++) #define nl "\n" #define sp " " #define all(c) (c).begin(),(c).end() #define rev(i,b,a) for(int i=b;i>=a;i--) #define iota cout<<-1<<nl #define cty cout<<"YES"<<nl #define ctn cout<<"NO"<<nl #define lmax LLONG_MAX #define lmin LLONG_MIN #define sz(v) (v).size() #define deci(n) fixed<<setprecision(n) #define c(x) cout<<(x) #define csp(x) cout<<(x)<<" " #define c1(x) cout<<(x)<<nl #define c2(x,y) cout<<(x)<<" "<<(y)<<nl #define c3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<nl #define c4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<nl #define c5(a,b,c,d,e) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<nl #define c6(a,b,c,d,e,f) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<" "<<(f)<<nl typedef long double ld; typedef long long ll; typedef vector<ll> vll; typedef pair<ll,ll> pll; typedef vector<pll> vpll; const int mod=998244353; const double pi=3.14159265358979323846264338327950288419716939937510582097494459230; // priority_queue<t> ll poww(ll a, ll b) { ll res=1; while(b) { if(b&1) res=(res*a); a=(a*a); b>>=1; } return res; } ll modI(ll a, ll m=mod) { ll m0=m,y=0,x=1; if(m==1) return 0; while(a>1) { ll q=a/m; ll t=m; m=a%m; a=t; t=y; y=x-q*y; x=t; } if(x<0) x+=m0; return x;} ll powm(ll a, ll b,ll m=mod) {ll res=1; while(b) { if(b&1) res=(res*a)%m; a=(a*a)%m; b>>=1; } return res;} //*******************************************************************************************************************************************// void iamzeus() { ll i,j,x=0,y,ans=0,n,m,d,cnt=0,z,c=2,k; char a[3]; cin>>a[0]>>a[1]>>a[2]; cout<<a[1]<<a[2]<<a[0]; }; int main() {fast; int t; t=1; //cin >>t; while(t--) iamzeus(); }
#include<bits/stdc++.h> using namespace std; #define endl "\n" #define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define ll long long #define vi vector<ll> #define pb push_back #define F first #define S second #define all(v) (v).begin(),(v).end() #define pii pair<ll,ll> #define vii vector<pii> #define MOD 1000000007LL #define calc_fact(n) tgamma(n+1) signed main() { FIO; ll a,b,c,d; cin>>a>>b>>c>>d; cout<<min(min(a,b),min(c,d)); }
#include <bits/stdc++.h> using namespace std; // #include <atcoder/segtree> // using namespace atcoder; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<ll,ll> pll; typedef vector<ll> vll; typedef vector<vll> vvll; typedef vector<vvll> vvvll; typedef vector<pll> vpll; typedef vector<vpll> vvpll; typedef vector<bool> vb; typedef vector<vb> vvb; typedef vector<double> vd; typedef vector<vd> vvd; typedef priority_queue<pll, vpll, function<bool(pll,pll)> > pqpll; typedef priority_queue<ll, vll, function<bool(pll,pll)> > pqll; // struct triplet{ ll fs,sc,td; triplet(ll a,ll b,ll c): fs(a), sc(b), td(c){} }; // typedef priority_queue<triplet, vector<triplet>, function<bool(triplet, triplet)> > pqtri; // typedef vector<triplet> vtri; // typedef vector<vtri> vvtri; struct edge{ ll from,to,cost; edge(ll e_from,ll e_to,ll e_cost): from(e_from), to(e_to), cost(e_cost){} }; typedef vector<vector<edge>> Graph; #define rep(i,a,n) for(ll i = a;i < n;i++) #define rrep(i,a,n) for(ll i = n-1; i >= a;i--) #define LINF (1LL << 60) #define INF (1 << 30) #define fs first #define sc second #define EPS 1e-10 #define ALL(a) a.begin(), a.end() #define tcheck(a) if((clock() - start)/(ld)CLOCKS_PER_SEC >= a) break template<typename T> ll sz(vector<T> &pos){ return (ll)pos.size(); } template<typename T> ll sz(priority_queue<T, vector<T> > &pq) {return (ll)pq.size(); } template<typename T> ll sz(priority_queue<T, vector<T>, greater<T> > &pq) {return (ll)pq.size(); } ll sz(string &s) {return (ll)s.size(); } void chmin(ll &a, ll b) { if(a > b) a = b; } void chmax(ll &a, ll b) { if(a < b) a = b; } template<typename T> void chmin(T &a, T b) { if(a > b) a = b; } template<typename T> void chmax(T &a, T b) { if(a < b) a = b; } ll gcd(ll a,ll b){ return ((!b) ?a :gcd(b, a%b)); } ll lcm(ll a,ll b){ return a / gcd(a,b) * b; } ll dx[4] = {0,-1,1,0},dy[4] = {-1,0,0,1}; bool checkindex(ll i,ll n){ return (i < n && i >= 0); } bool endflag; void rec(ll k, vector<string> &s, vb &is_used, vll &num, vector<string> &ans, vb &temp){ if(26 <= k){ bool flag = false; vll tempnum(3,0); rep(i,0,3){ bool check = true; rep(j,0,sz(s[i])){ if(check && num[s[i][j] - 'a'] == 0){ return; } else check = false; tempnum[i] *= 10; tempnum[i] += num[s[i][j] - 'a']; } } if(tempnum[0] + tempnum[1] == tempnum[2]){ endflag = true; cout << tempnum[0] << endl; cout << tempnum[1] << endl; cout << tempnum[2] << endl; } return; } else if(!temp[k]){ rec(k+1,s,is_used,num,ans,temp); return; } if(endflag) return; rep(i,0,10){ if(!is_used[i]){ is_used[i] = true; num[k] = i; rec(k+1,s,is_used,num,ans,temp); is_used[i] = false; num[k] = -1; } } return; } int main(){ vector<string> s(3),ans(3); vb temp(26,false); ll cnt = 0; rep(i,0,3){ cin >> s[i]; rep(j,0,sz(s[i])){ if(temp[s[i][j] - 'a']) cnt++; temp[s[i][j] - 'a'] = true; } } vb is_used(10,false); vll num(26,-1); rep(i,0,3) rep(j,0,sz(s[i])) ans[i].push_back('X'); rec(0,s,is_used,num,ans,temp); if(!endflag) cout << "UNSOLVABLE" << endl; }
#include <bits/stdc++.h> using namespace std; // clang-format off // #include <atcoder/all> // using namespace atcoder; // using mint = modint1000000007; // using mint = modint998244353 using ll = int64_t; template <class T> istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v) cin >> a; return is; } template <class T> istream& operator>>(istream& is, vector<pair<T, T>>& v) { for (auto& a : v) cin >> a.first >> a.second; return is; } template <class T> istream& operator>>(istream& is, vector<tuple<T, T, T>>& v) { for (auto& a : v) { T a1, a2, a3; cin >> a1 >> a2 >> a3; a = {a1, a2, a3}; } return is; } template<typename T> istream& operator>>(istream &is, complex<T>& c) { double x, y; is >> x >> y; c.real(x); c.imag(y); return is; } template <class T> ostream& operator<<(ostream& os, vector<T>& v) { for (auto& a : v) os << a << " "; os << endl; return os; } template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } #define all(v) begin(v), end(v) #define rall(v) rbegin(v), rend(v) #define TRC1(a) cout << #a ":" << a #define TRC2(a, b) TRC1(a); cout << " "; TRC1(b) #define TRC3(a, b, c) TRC2(a, b); cout << " "; TRC1(c) #define TRC4(a, b, c, d) TRC3(a, b, c); cout << " "; TRC1(d) #define GET_NAME(_1,_2,_3,_4,NAME,...) NAME #define TRC(...) GET_NAME(__VA_ARGS__, TRC4, TRC3, TRC2, TRC1) (__VA_ARGS__) << endl using veci = vector<int>; using vecll = vector<ll>; using Pi = pair<int, int>; using Ti = tuple<int, int, int>; #define _overload3(_1,_2,_3,name,...) name #define _rep(i,n) repi(i,0,n) #define repi(i,a,b) for(int i=int(a);i<int(b);++i) #define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__) const int IINF = INT32_MAX; const ll LINF = INT64_MAX; // cout << fixed << setprecision(15); void solve(); int main() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(15); solve(); return 0; } // clang-format on void solve() { vector<string> S(3); cin >> S; set<char> heads; map<char, ll> mp; rep(i, 3) { ll co = 1; if (i == 2) co = -1; for_each(rall(S[i]), [&](char c) { mp[c] += co; co *= 10; }); heads.insert(S[i][0]); } veci d(10); iota(all(d), 0); do { int i = 0; ll tot = 0; for (auto [c, co] : mp) { if (d[i] == 0 && heads.count(c)) { tot = 1; break; } tot += co * d[i++]; } if (tot == 0) { i = 0; for (auto& [c, co] : mp) co = d[i++]; rep(j, 3) { ll x = 0; for (char c : S[j]) x = x * 10 + mp[c]; cout << x << endl; } return; } } while (next_permutation(all(d))); cout << "UNSOLVABLE" << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(i64 i=0; i<n; i++) #define all(v) v.begin(),v.end() #define pp pair<int,int> using Graph=vector<vector<int>>; using i64=int64_t; int main() { int si,sj;cin>>si>>sj; vector<vector<int>> t(50,vector<int>(50)); rep(i,50) { rep(j,50) { cin>>t[i][j]; } } vector<vector<int>> p(50,vector<int>(50)); rep(i,50) { rep(j,50) { cin>>p[i][j]; } } vector<char>ans; if(si<=48) { if(t[si][sj]!=t[si+1][sj]) { ans.push_back('D'); if(si<=47 && t[si+1][sj]!=t[si+2][sj]) { ans.push_back('D'); if(si<=46 && t[si+2][sj]!=t[si+3][sj]) { ans.push_back('D'); } } } else { ans.push_back('U'); } } else { if(sj<=48) { if(t[si][sj]!=t[si][sj+1]) { ans.push_back('R'); if(sj<=47 && t[si][sj+1]!=t[si][sj+2]) { ans.push_back('R'); } } else { ans.push_back('L'); } } else { if(t[si][sj]!=t[si][sj-1]) { ans.push_back('L'); } else { ans.push_back('U'); } } } rep(i,ans.size()) { cout << ans[i]; } }
//雪花飄飄北風嘯嘯 //天地一片蒼茫 #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 ub 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 main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin.exceptions(ios::badbit | ios::failbit); int a,b; cin>>a>>b; int ans=0; rep(x,1,a+1) rep(y,1,b+1){ ans+=x*100+y; } cout<<ans<<endl; }
#include <iostream> #include <string> #include <map> #include <set> #include <algorithm> #include <utility> #include <queue> #include <deque> #include <iomanip> #include <cmath> // 最大公約数 template<typename T> T gcd(T a, T b) { if (a < b) { return gcd(b, a); } else { const T mod = a % b; if (mod == 0) { return b; } else { return gcd(b, mod); } } } int main() { int N; std::cin >> N; double m = 0; double y = 0; double c = 0; for (int64_t i = 0; i < N; ++i) { double x; std::cin >> x; m += abs(x); y += x * x; c = std::max<double>(c, abs(x)); } y = sqrt(y); std::cout << std::setprecision(15) << m << "\n" << y << "\n" << c << std::endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() {int N;cin>>N; vector<long long>A(N),B(N); for(int i=0;i<N;i++) cin>>A.at(i); for(int i=0;i<N;i++) cin>>B.at(i); long long c=0; int d=0; for(int i=0;i<N;i++) {d=max<long long>(d,A.at(i)); c=max(c,d*B.at(i)); cout<<c<<endl;} }
// Rakib (CSE'19) #include<bits/stdc++.h> #define boost_ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) #define pb push_back #define read(i,n,a) for(i=0;i<n;++i) cin>>a[i] #define print(i,a) for(auto i:a) cout<<i<< " " ; cout<<endl ; #define dpoint(n) cout<<showpoint<<fixed<<setprecision(n) #define MOD 1000003 #define llmax LONG_LONG_MAX #define llmin LONG_LONG_MIN #define read_grid(i,j,n,m,a) for(i=0;i<n;++i) for(j=0;j<m;++j) cin >> a[i][j]; #define all(a) a.begin(),a.end() #define vl vector<ll> typedef long long ll; typedef unsigned long long ull; using namespace std; int gcd(int x,int y){ if(!y) return x; return gcd(y,x%y); } ll MX=100001; vector<ll>check(MX,1), divisor(MX,2); //vector<ll>primes,divisor; void prime(){ ll i,j; //check[1]=0; //check[2]=1; //primes.pb(2); for(i=3;i<MX;i+=2){ if(check[i]){ //primes.pb(i); divisor[i]=i; for(j=i*i;j<MX;j+=2*i) divisor[j]=i, check[j]=0; } } } void task(ll case_no){ ll n,m; cin >> n >> m; ll i,j; ll a[n][m]; ll x=llmax; for(i=0;i<n;++i){ for(j=0;j<m;++j){ cin >> a[i][j]; x=min(x,a[i][j]); } } ll ans=0; for(i=0;i<n;++i){ for(j=0;j<m;++j){ ans+=a[i][j]-x; } } cout << ans << "\n"; } int main(){ boost_; //prime(); ll t=1,i=0; //cin >> t; while(t--){ task(++i); } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long //data types used often, but you don't want to type them time by time #define ull unsigned long long #define ui unsigned int //#define ld long double #define mod 998244353 //define inf 100000000000010 #define us unsigned short #define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf //#define INF LONG_MAX #define PI 3.1415926535897932384626 #define mp make_pair #define fi first #define se second #define pb push_back #define rep(x,j,n)for(int x=j;x<n;x++) #define repr(x,n,j)for(ll x=n;x>j;x--) #define all(x) (x).begin(), (x).end() typedef vector<pair<ll,ll>> vpi; typedef vector<ll> vi; typedef vector<vi> vvi; typedef pair<ll,ll> pi; typedef long double ld; mt19937 myrand(time(0)); 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+=6) { if(n%i==0||n%(i+2)==0)return false; } return true; } ll modexp(ll a,ll b,ll m) { ll r=1; a=a%m; while(b>0) { if(b&1)r=(r*a)%m; b = b>>1; a=(a*a)%m; } return r%m; } ll builtin_popcount(ll x) { ll cnt = 0; for(ll i=60;i>=0;i--) { if((1LL<<i)&x)cnt++; } return cnt; } ll addmod(ll a,ll b) { a%=mod; b%=mod; return (a+b)%mod; } ll mulmod(ll a,ll b) { a%=mod; b%=mod; return (a*b)%mod; } ll submod(ll a,ll b) { a%=mod; b%=mod; a-=b; if(a<0)a+=mod; return a%mod; } struct CustomCompare { bool operator()(pi a,pi b) { return a.fi<b.fi; } }; /* const int mxn = 5*(1e6) +10; vi spf(mxn); void sieve() { for(ll i =0;i<mxn;i++)spf[i] = i; for(ll i=2;i<mxn;i+=2)spf[i] = 2; for(ll i = 3;i*i<mxn;i++) { if(spf[i]==i) { for(ll j = i*i;j<mxn;j+=i) { if(spf[j]==j)spf[j] = i; } } } } */ const int mxn = 2e5 +10; vi arr(mxn); int main(){ ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0); ll n,w; cin>>n>>w; rep(i,0,n) { ll l,r,p; cin>>l>>r>>p; arr[l]+=p; arr[r]-=p; } bool flag = true; ll curr = 0; rep(i,0,mxn) { curr+=arr[i]; if(curr>w)flag = false; } if(flag)cout<<"Yes\n"; else cout<<"No\n"; return 0; } /* */
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll r1, c1, r2, c2; cin >> r1 >> c1 >> r2 >> c2; if (r1 == r2 && c1 == c2) cout << 0 << endl; else if (r1 + c1 == r2 + c2 || r1 - c1 == r2 - c2 || abs(r1 - r2) + abs(c1 - c2) <= 3) cout << 1 << endl; else if (abs(r1 + c1 + r2 + c2) % 2LL == 0) cout << 2 << endl; else { if (abs(r1 - c1 - r2 + c2) <= 5 || abs(r1 + c1 - r2 - c2) <= 5) cout << 2 << endl; else cout << 3 << endl; } return 0; }
#line 1 "C.cpp" #include <bits/stdc++.h> using namespace std::literals::string_literals; using i64 = std::int_fast64_t; using std::cout; using std::cerr; using std::endl; using std::cin; template<typename T> std::vector<T> make_v(size_t a){return std::vector<T>(a);} template<typename T,typename... Ts> auto make_v(size_t a,Ts... ts){ return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); } int main() { int a, b, c, d; scanf("%d%d%d%d", &a, &b, &c, &d); int ans; if(std::abs(a + b) % 2 == std::abs(c + d) % 2) ans = 2; else ans = 3; if(a == c and b == d) ans = 0; if(a + b == c + d) ans = std::min(ans, 1); if(a - b == c - d) ans = std::min(ans, 1); for(int i = a - 2; i <= a + 2; i++) { for(int j = b - 2; j <= b + 2; j++) { if(i == c and j == d) ans = std::min(ans, 1); if(i + j == c + d) ans = std::min(ans, 2); if(i - j == c - d) ans = std::min(ans, 2); if(std::abs(i - c) + std::abs(j - d) <= 3) ans = std::min(ans, 2); } } std::vector<std::pair<int, int>> v = {{a - 3, b}, {a + 3, b}, {a, b - 3}, {a, b + 3}}; for(auto [i, j]: v) { if(i == c and j == d) ans = std::min(ans, 1); if(i + j == c + d) ans = std::min(ans, 2); if(i - j == c - d) ans = std::min(ans, 2); if(std::abs(i - c) + std::abs(j - d) <= 3) ans = std::min(ans, 2); } printf("%d\n", ans); return 0; } // 三手以下 // 2 手判断 // パリティ同じ -> 曲がって行ける // 異なる -> 四角内で動いてからななめ // 1 手判断 // もとから
#include<iostream> using namespace std; int n,T[5007],C[5007],A[5007],G[5007]; char s[5007]; int main(){ cin>>n; cin>>s+1; for(int i=1;i<=n;i++){ T[i]=T[i-1]; C[i]=C[i-1]; A[i]=A[i-1]; G[i]=G[i-1]; if(s[i]=='A')A[i]++; if(s[i]=='C')C[i]++; if(s[i]=='G')G[i]++; if(s[i]=='T')T[i]++; } int ans=0,a=0,c=0,t=0,g=0; for(int i=1;i<=n;i++){ for(int j=1;j<i;j++){ a=A[i]-A[j-1]; g=G[i]-G[j-1]; t=T[i]-T[j-1]; c=C[i]-C[j-1]; if(a==t&&c==g)ans++; } } printf("%d\n",ans); }
// Problem : B - DNA Sequence // Contest : AtCoder - AtCoder Regular Contest 104 // URL : https://atcoder.jp/contests/arc104/tasks/arc104_b // Memory Limit : 1024 MB // Time Limit : 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) // $%U%$ // Mere bas ka nahi hai // still i'm trying // apna time aayega // // .--------------. // | Try First One| // '--------------' // | .--------------. // | | | // V V | // .--------------. | // | AC. |<---. | // '--------------' | | // (True)| |(False) | | // .--------' | | | // | V | | // | .--------------. | | // | | Try Again |----' | // | '--------------' | // | | // | .--------------. | // '->| Try Next One |-------' // '--------------' // #include<bits/stdc++.h> using namespace std; typedef long long int ll; ll power(ll x,ll y,ll m){if(y==0)return 1;ll p=power(x,y/2,m)%m;p=(p*p)%m;return (y%2==0)?p:(x*p)%m;} ll nCr(ll n,ll r,ll m){if(r>n)return 0;ll a=1,b=1,i;for(i=0;i<r;i++){a=(a*n)%m;--n;}while(r){b=(b*r)%m;--r;}return (a*power(b,m-2,m))%m;} #define Test int t;cin>>t;while(t--) #define endl '\n' void solve() { int n; string s; cin >> n >> s; map<pair<int,int>,int> mp; int A,G,C,T; A = G = C = T = 0; int ans=0; mp[{0,0}]++; for(int i=0;i<n;++i) { if(s[i]=='A') A++; else if(s[i]=='G') G++; else if(s[i]=='C') C++; else T++; if(mp[{A-T,C-G}]!=0) ans+=mp[{A-T,C-G}]; mp[{A-T,C-G}]++; } cout << ans << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); //Test solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define fo(i, n) for (i = 0; i < n; i++) #define Fo(i, k, n) for (i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1) #define ll long long #define si(x) scanf("%d", &x) #define sl(x) scanf("%lld", &x) #define ss(s) scanf("%s", s) #define pi(x) printf("%d\n", x) #define pl(x) printf("%lld\n", x) #define ps(s) printf("%s\n", s) #define deb(x) cout << #x << "=" << x << endl #define deb2(x, y) cout << #x << "=" << x << ", " << #y << "=" << y << endl #define pb push_back #define mp make_pair #define F first #define S second #define all(x) x.begin(), x.end() #define clr(x) memset(x, 0, sizeof(x)) #define sortall(x) sort(all(x)) #define tr(it, a) for (auto it = a.begin(); it != a.end(); it++) #define PI 3.1415926535897932384626 #define M 1000000007 typedef pair<int, int> ii; typedef pair<ll, ll> pl; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<ii> vii; int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); srand(chrono::high_resolution_clock::now().time_since_epoch().count()); int t = 1; //cin >> t; while (t--) { string s; cin >> s; //cout << s; for (int i = 0; i < s.length() && s[i] != '.'; i++) { cout << s[i]; } } return 0; }
#include<bits/stdc++.h> using namespace std; int n; int main() { cin>>n; for(int i=1;i<=n;++i) printf("%d %d\n",(2*i)%n+1,(2*i-1)%n+1); }
#pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx") #pragma GCC target ("avx2,fma") #pragma GCC optimize ("O3") #pragma GCC optimize ("unroll-loops") #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> //#include <atcoder/all> #define F first #define S second #define int long long #define ll long long //#define int unsigned long long #define pb push_back #define rank fewfewf #define double long double using namespace std; using namespace __gnu_pbds; //using namespace atcoder; typedef tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int N = 705000; const int K = 20; const int mod = 1e9 + 7; int x, y; map<int,int> m; int solve(int z){ if (m.find(z) != m.end()) return m[z]; m[z] = abs(z - x); for (int i = -1; i <= 1; i++){ if ((z + i) % 2 == 0) m[z] = min(m[z], 1 + abs(i) + solve((z + i) / 2)); } return m[z]; } main(){ ios_base::sync_with_stdio(0); cin.tie(0); //freopen("input.txt", "r", stdin); //freopen("input.txt", "w", stdout); cin >> x >> y; cout << solve(y); }
#include <iostream> #include <string> #include <algorithm> #include <functional> #include <vector> #include <stack> #include <queue> #include <set> #include <map> #include <cstdio> #include <cmath> #include <tuple> #define int long long #define rep(i, n) for(i = 0; i < n; i++) using namespace std; const int DEPTH = 19; class SegTree { public: int val[1 << (DEPTH + 1)]; SegTree() { for (int i = 0; i < (1 << (DEPTH + 1)); i++) { val[i] = 0; } } void update(int pos, int x) { pos += (1 << DEPTH) - 1; val[pos] ^= x; while (pos > 0) { pos = (pos - 1) / 2; val[pos] = val[2 * pos + 1] ^ val[2 * pos + 2]; } } int query(int l, int r, int a = 0, int b = (1 << DEPTH), int id = 0) { if (a >= r || b <= l) return 0; if (l <= a && b <= r) return val[id]; int res1 = query(l, r, a, (a + b) / 2, id * 2 + 1); int res2 = query(l, r, (a + b) / 2, b, id * 2 + 2); return res1 ^ res2; } }; SegTree seg; int n, q; int a[300000]; int t, x, y; signed main() { int i; cin >> n >> q; rep(i, n) cin >> a[i]; rep(i, n) seg.update(i, a[i]); rep(i, q) { cin >> t >> x >> y; x--; if (t == 1) { seg.update(x, y); } else { cout << seg.query(x, y) << endl; } } return 0; }
/*************************BALIGA***************************************/ #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 lli long long int #define ulli unsigned long long int #define lld long double #define MP make_pair #define PB push_back #define MT make_tuple #define rep0(i,n) for(lli i=0;i<n;i++) #define rep1(i,n) for(lli i=1;i<=n;i++) #define rep(i,x,y) for(lli i=x;i<=y;i++) #define per1(i,n) for(lli i=n;i>0;i--) #define per0(i,n) for(lli i=n-1;i>=0;i--) #define per(i,x,y) for(lli i=x;i>=y;i--) #define ff first #define ss second #define pli pair <lli,lli> #define plli pair <pli,lli> #define vi vector<int> #define vli vector<long long int> #define vs vector<string> #define vc vector<char> #define vipair vector<pair<int,int>> #define vlipair vector<pair<lli,lli>> #define all(c) c.begin(),c.end() #define print(c) for(lli i=0;i<c.size();i++) cout<<c[i]<<' ' #define max3(a,b,c) max(max(a,b),c) #define min3(a,b,c) min(min(a,b),c) #define sz(a) a.size() #define INF64 1e18 #define INF32 1e9 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const lli mod = INF64; const lld eps = 1e-9; const lli maxn = 1000; const lli max_nodes=15; const lli alpha=26; const lli max_log=19; lli fact[maxn+3]; template <typename T> void add(T &a, T b){a += b;if(a >= mod)a -= mod;} template <typename T> void sub(T &a, T b){a -= b;if(a < 0)a += mod;} template <typename T> void mul(T &a, T b){a *= b;if(a >= mod)a %= mod;} template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; void calcfac() {fact[0]=1;fact[1]=1;rep(i,2,maxn) fact[i] = (fact[i-1]*i)%mod;} lli gcd(lli a,lli b) {if(b==0) return a; return gcd(b,a%b);} lli gcdext(lli a,lli b,lli &x,lli &y){if(a==0){x=0;y=1;return b;}lli x1,y1;lli g=gcdext(b%a,a,x1,y1);x=y1-(b/a)*x1;y=x1;return g;} lli fastexp(lli a,lli b) {a%=mod;lli res=1;while(b>0){if(b&1) res=(res*a)%mod; a=(a*a)%mod; b>>=1;}return res;} lli inverse(lli n) {return fastexp(n,mod-2);} lli ncr(lli n , lli r){if(n < r|| (n < 0) || (r < 0)) return 0 ; if(r==0) return 1; return (((fact[n] * inverse(fact[r]))%mod)*inverse(fact[n-r]))%mod;} int pct(int x) { return __builtin_popcount(x);} //number of set bits int bits(int x) { return 31-__builtin_clz(x); } // floor(log2(x)) // TRIE // int triex[max_nodes][alpha],globcount=1; // void build_triex(string s) {int i = 0, v = 0;while(i < s.size()){if(triex[v][s[i]-'a'] == -1)v = triex[v][s[i++]-'a'] = globcount++ ;else v = triex[v][s[i++]-'a'];}} // SPARSE TABLE // lli logarithm[maxn+1]; // void calclog() {logarithm[1]=0;for(lli i=2;i<=maxn;i++)logarithm[i]=logarithm[i/2]+1;} // lli sp_table[maxn][max_log+1]; // void build_sp(vli &nums) {calclog();lli n=nums.size();rep0(i,n)sp_table[i][0]=nums[i];for(lli j=1;j<=max_log;j++){for(lli i=0;i+(1<<j)<=n;i++){sp_table[i][j]=min(sp_table[i][j-1],sp_table[i+(1<<(j-1))][j-1]);}}} // lli query_sp(lli l,lli r) {lli j=logarithm[r-l+1];return min(sp_table[l][j],sp_table[r-(1<<j)+1][j]);} void solve() { lli n; cin>>n; lli ncpy = n; lli ans = 0; if(n<1000) { cout<<'0'; return; } lli digs=0; while(ncpy>0) { digs++; ncpy/=10; } lli d = 3*(digs/3); if(d == digs) d-=3; // cout<<digs<<' '<<d<<'\n'; for(int i=d;i>=3;i-=3) { // cout << n - fastexp(10,i) + 1<<'\n'; ans += n - fastexp(10,i) + 1; } cout<<ans; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int TC; TC=1; // cin>>TC; for(int t=0;t<TC;t++) solve(); cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(ll i=0;i<(ll)n;i++) #define dump(x) cerr << "Line " << __LINE__ << ": " << #x << " = " << (x) << "\n"; #define spa << " " << #define fi first #define se second #define ALL(a) (a).begin(),(a).end() #define ALLR(a) (a).rbegin(),(a).rend() using ld = long double; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<ld, ld>; template<typename T> using V = vector<T>; template<typename T> using P = pair<T, T>; template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); } template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); } template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){os << "(" << v.first << ", " << v.second << ")"; return os;} template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; } template<class T> ostream& operator<<(ostream& os, const vector<vector<T>> &v){ for(auto &e : v){os << e << "\n";} return os;} struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_; template <class T> void UNIQUE(vector<T> &x) {sort(ALL(x));x.erase(unique(ALL(x)), x.end());} template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } void fail() { cout << -1 << '\n'; exit(0); } inline int popcount(const int x) { return __builtin_popcount(x); } inline int popcount(const ll x) { return __builtin_popcountll(x); } template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++) {cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<"\n";}}; template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0]; for(ll i=1;i<n;i++)cerr spa v[i]; cerr<<"\n";}; const ll INF = (1ll<<62); // const ld EPS = 1e-10; // const ld PI = acos(-1.0); const ll mod = (int)1e9 + 7; //const ll mod = 998244353; vector<ll> get_moebius_function(ll m){ vector<ll> is_prime(m+1, 1); vector<ll> meb(m+1, -1); meb[0] = 0; meb[1] = 0; is_prime[0] = 0; is_prime[1] = 0; REP(i, m+1){ if(is_prime[i] == 0) continue; for(int j=2;j*i<=m;j++){ is_prime[i*j] = 0; } for(int j=1;j*i<=m;j++){ meb[i*j] *= -1; if(j%i == 0) meb[i*j] = 0; } } // 普通のメビウス関数の定義に戻すための処理 meb[1] = 1; // REP(i, m+1) if(i>1) meb[i] *= -1; return meb; } int main(){ ll L, R; cin >> L >> R; ll MA = 1010101; // ll MA = 30; auto meb = get_moebius_function(MA); // dump(meb) ll res = 0; for(ll i=2;i<=R;i++){ ll kosu = R/i - (L-1)/i; ll tmp = kosu * kosu * meb[i]; res += tmp; } for(ll i=L;i<=R;i++){ ll kosu = R/i - (L-1)/i; ll tmp = 2*kosu-1; res -= tmp; } if(L == 1){ res += 2*R-1; } cout << res << endl; return 0; }
#include <bits/stdc++.h> //#include <chrono> #pragma GCC optimize("Ofast") using namespace std; #define reps(i,s,n) for(int i = s; i < n; i++) #define rep(i,n) reps(i,0,n) #define Rreps(i,n,e) for(int i = n - 1; i >= e; --i) #define Rrep(i,n) Rreps(i,n,0) #define ALL(a) a.begin(), a.end() using ll = long long; using vec = vector<ll>; using mat = vector<vec>; ll N,M,H,W,Q,K,A,B; string S; using P = pair<ll, ll>; const ll INF = (1LL<<60); template<class T> bool chmin(T &a, const T &b){ if(a > b) {a = b; return true;} else return false; } template<class T> bool chmax(T &a, const T &b){ if(a < b) {a = b; return true;} else return false; } template<class T> void my_printv(std::vector<T> v,bool endline = true){ if(!v.empty()){ for(std::size_t i{}; i<v.size()-1; ++i) std::cout<<v[i]<<" "; std::cout<<v.back(); } if(endline) std::cout<<std::endl; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); cin>>N; rep(i, N){ cout<<(i*2)%N + 1 <<' '<<(i*2 + 1)%N + 1<<endl; } }
#pragma region include #include <iostream> #include <iomanip> #include <stdio.h> #include <vector> #include <algorithm> #include <cmath> #include <map> #include <set> #include <string> #include <bitset> #include <complex> #include <deque> #include <functional> #include <limits> #include <list> #include <numeric> #include <queue> #include <stack> #include <utility> #include <array> #include <random> #include <tuple> #include <unordered_map> #include <unordered_set> #include <assert.h> #include <chrono> using namespace std; typedef long long ll; #define dump(x) // // cerr << #x << " = " << (x) << " [" << __LINE__ << ":" << __FUNCTION__ << "] " << endl; // vector出力 template < typename T > ostream& operator<<(ostream& os, vector< T >& v) { os << "{"; for (int i = 0; i < (int)v.size(); i++) { os << v[i] << (i < v.size() - 1 ? ", " : ""); } os << "}"; return os; } // pair出力 template < typename T, typename U > ostream& operator<<(ostream& os, const pair< T, U >& p) { return os << "(" << p.first << ", " << p.second << ")"; } // map出力 template < typename T, typename U > ostream& operator<<(ostream& os, const map< T, U >& map_var) { os << "{"; for (auto itr = map_var.begin(); itr != map_var.end(); itr++) { os << "(" << itr->first << ", " << itr->second << ")"; itr++; if (itr != map_var.end()) os << ", "; itr--; } os << "}"; return os; } // set 出力 template < typename T > ostream& operator<<(ostream& os, const set< T >& set_var) { os << "{"; for (auto itr = set_var.begin(); itr != set_var.end(); itr++) { os << *itr; ++itr; if (itr != set_var.end()) os << ", "; itr--; } os << "}"; return os; } // multiset 出力 template < typename T > ostream& operator<<(ostream& os, const multiset< T >& set_var) { os << "{"; for (auto itr = set_var.begin(); itr != set_var.end(); itr++) { os << *itr; ++itr; if (itr != set_var.end()) os << ", "; itr--; } os << "}"; return os; } #pragma endregion ///////////////////////////////////////// int main() { string s;cin >> s; string ans; for (int i = s.size()-1; i >= 0; i--) { if (s[i] == '6') { ans.push_back('9'); } else if (s[i] == '9') { ans.push_back('6'); } else { ans.push_back(s[i]); } } cout << ans << endl; return 0; } /////////////////////////////////////////
#include <map> #include <set> #include <list> #include <cmath> #include <deque> #include <stack> #include <queue> #include <array> #include <bitset> #include <cstdio> #include <string> #include <vector> #include <random> #include <chrono> #include <utility> #include <numeric> #include <cstdlib> #include <cstring> #include <climits> #include <sstream> #include <assert.h> #include <iostream> #include <iomanip> #include <algorithm> #include <functional> #include <unordered_map> using namespace std; struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _; int main() { int n, t; cin >> n >> t; vector<int> left, right; for (int i = 0; i <= n - 1; i++) { int a; cin >> a; if (i <= n / 2) left.emplace_back(a); else right.emplace_back(a); } auto subseq = [&](const vector<int>& v) -> vector<long long> { vector<long long> res; for (int mask = 0; mask < 1 << (int)v.size(); mask++) { long long curr = 0; for (int j = 0; j < v.size(); j++) { if (mask & (1 << j)) curr += v[j]; } res.emplace_back(curr); } sort(res.begin(), res.end()); return res; }; vector<long long> ff = subseq(left); vector<long long> ss = subseq(right); long long ans = 0; for (auto i : ff) { auto it = upper_bound(ss.begin(), ss.end(), t - i); if (it == ss.begin()) continue; ans = max(ans, i + *prev(it)); } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define DEBUG #ifdef DEBUG template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << '(' << p.first << ',' << p.second << ')'; return os; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { os << '{'; for(int i = 0; i < (int)v.size(); i++) { if(i) { os << ','; } os << v[i]; } os << '}'; return os; } void debugg() { cerr << endl; } template <class T, class... Args> void debugg(const T &x, const Args &... args) { cerr << " " << x; debugg(args...); } #define debug(...) \ cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__) #define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl #else #define debug(...) (void(0)) #define dump(x) (void(0)) #endif using namespace std; typedef long long ll; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<char> vc; typedef vector<string> vs; typedef vector<bool> vb; typedef vector<double> vd; typedef pair<ll,ll> P; typedef pair<int,int> pii; typedef vector<P> vpl; typedef tuple<ll,ll,ll> tapu; #define rep(i,n) for(int i=0; i<(n); i++) #define REP(i,a,b) for(int i=(a); i<(b); i++) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() const int inf = 1<<30; const ll linf = 1LL<<62; const int MAX = 510000; ll dy[8] = {0,-1,0,1,1,-1,-1,1}; ll dx[8] = {-1,0,1,0,1,-1,1,-1}; const double pi = acos(-1); const double eps = 1e-7; template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){ if(a>b){ a = b; return true; } else return false; } template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){ if(a<b){ a = b; return true; } else return false; } template<typename T> inline void print(T &a){ int sz = a.size(); for(auto itr = a.begin(); itr != a.end(); itr++){ cout << *itr; sz--; if(sz) cout << " "; } cout << "\n"; } template<typename T1,typename T2> inline void print2(T1 a, T2 b){ cout << a << " " << b << "\n"; } template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){ cout << a << " " << b << " " << c << "\n"; } void mark() {cout << "#" << "\n";} ll pcount(ll x) {return __builtin_popcountll(x);} const int mod = 1e9 + 7; //const int mod = 998244353; int main(){ ll n,t; cin >> n >> t; vl a(n); rep(i,n) cin >> a[i]; vl ls1, ls2; int N = n/2; rep(bit,1<<N){ ll s = 0; rep(i,N) if(bit>>i & 1) s += a[i]; ls1.push_back(s); } rep(bit,1<<(n-N)){ ll s = 0; rep(i,n-N) if(bit>>i & 1) s += a[i+N]; ls2.push_back(s); } sort(rall(ls1)); sort(all(ls2)); ll ans = 0; int id = 0; int m = ls2.size(); for(auto x : ls1){ if(x > t) continue; while(id < m-1 && ls2[id+1] + x <= t) id++; if(id < m) chmax(ans, ls2[id] + x); } cout << ans << "\n"; }
/*input helloAtZoner */ #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef tree<long long,null_type,less_equal<long long>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; //order_of_key #of elements less than x // find_by_order kth element using ll=long long; using ld=long double; using pii=pair<ll,ll>; #define f first #define s second #define pb push_back #define REP(i,n) for(ll i=0;i<n;i++) #define REP1(i,n) for(int i=1;i<=n;i++) #define FILL(n,x) memset(n,x,sizeof(n)) #define ALL(_a) _a.begin(),_a.end() #define sz(x) (int)x.size() #define SORT_UNIQUE(c) (sort(c.begin(),c.end()),c.resize(distance(c.begin(),unique(c.begin(),c.end())))) const ll INF64=4e18; const int INF=0x3f3f3f3f; const ll MOD=3; const ld PI=acos(-1); const ld eps=1e-9; #define lowb(x) x&(-x) #define MNTO(x,y) x=min(x,(__typeof__(x))y) #define MXTO(x,y) x=max(x,(__typeof__(x))y) inline ll mult(ll a,ll b){ if(a>=MOD) a%=MOD; if(b>=MOD) b%=MOD; return (a*b)%MOD; } inline ll mypow(ll a,ll b){ if(b<=0) return 1; ll res=1LL; while(b){ if(b&1) res=mult(res,a); a=mult(a,a); b>>=1; } return res; } const int maxn=1e5+5; int main(){ ios::sync_with_stdio(false),cin.tie(0); string s; cin>>s; int ans=0; REP(i,sz(s)){ string x=""; REP(j,4) x.pb(s[i+j]); if(x=="ZONe"){ ++ans; } } cout<<ans; }
#include<bits/stdc++.h> using namespace std; using ll = long long; const ll mod = 1e9 + 7; int run_test(){ string s; cin >> s; int ans = 0; for(int i = 0; i <= 8; i++){ if(s[i] == 'Z' && s[i+1] == 'O' && s[i+2] == 'N' && s[i+3] =='e'){ ans++; } } cout << ans; return 0; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tt; tt = 1; while(tt--){ run_test(); } }
#include<bits/stdc++.h> #define int long long using namespace std; signed main() { int n,x; cin>>n; int l=1,r=2e9; while(r-l>1) { int m=l+r>>1; if(m*(m+1)/2<=n+1) l=m; else r=m; } cout<<n-l+1<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int K; cin >> K; ll ans = 0; for (int i = 1; i <= K; i++) { int jEnd = K / i; for (int j = i; j <= jEnd; j++) { int p = K / (i * j); if (p < j) break; if (i == j) ans += 1 + (p - i) * 3; else ans += 3 + (p - j) * 6; } } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define ff first #define ss second #define pb push_back #define mp make_pair #define deb(x) cout<< #x << " " << x << "\n"; #define MAX 9223372036854775807 #define MIN -9223372036854775807 #define setbits(n) __builtin_popcountll(n) #define mkunique(a) a.resize(unique(a.begin(),a.end())-a.begin()); const ll mod=1e9+7; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll T=clock(); ll n; cin>>n; n*=2; vector<ll> a(n), b; for(ll i=0;i<n;i++) cin>>a[i]; multiset<ll> s; ll ans=0, val=0; for(ll i=0;i<n/2;i++){ if(a[i]<a[n-i-1]) swap(a[i],a[n-i-1]); if(s.size()>0 && *s.rbegin()>a[i]){ ans+=*s.rbegin(); s.erase(--s.end()); s.insert(a[i]); s.insert(a[n-i-1]); } else{ ans+=a[i]; s.insert(a[n-i-1]); } } cout<<ans; cerr<<"\n\nTIME: "<<(long double)(clock()-T)/CLOCKS_PER_SEC<<" sec\n"; T = clock(); return 0; }
#include <bits/stdc++.h> #define N 400005 #define ll long long using namespace std; inline int read() { int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int T; int n; int a[N]; int main() { n = read(); ll ans = 0; for(int i=1;i<=2*n;i++) a[i] = read(), ans += a[i]; priority_queue<int> q; for (int i = 1 ; i <= n; i += 1) { q.push(-a[n - i + 1]); q.push(-a[n + i]); ans += q.top(); q.pop(); } cout << ans << endl; } // 1 2 3 4 5 6 7 8 //
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double class BIT{ public: int size; vector<long long> tree; BIT(int n){ size = n; tree = vector<long long>(n, 0); return; } void add(int n, long long a) { assert(n < size); int x = n; while (x < size){ tree[x] += a; x |= x+1; } return; } long long getsum(int n) { assert(n < size); int x = n+1; long long sum = 0; while (x > 0) { sum += tree[x-1]; x &= x-1; } return sum; } }; int main() { int N; cin >> N; vector<ll> A(N), B(N); for (int i = 0; i < N; i++) { cin >> A[i]; A[i] += i; } for (int i = 0; i < N; i++) { cin >> B[i]; B[i] += i; } { vector<ll> C = A, D = B; sort(C.begin(), C.end()); sort(D.begin(), D.end()); if (C != D) { cout << -1 << endl; return 0; } } map<ll, ll> mp; set<ll> st; map<ll, ll> cnt; for (int i = 0; i < N; i++) { st.insert(A[i]); cnt[A[i]]++; } ll t = 0; for (ll n : st) { mp[n] = t; t += cnt[n]; } map<ll, ll> cnt2; for (int i = 0; i < N; i++) { ll pre = A[i]; A[i] = mp[A[i]]+cnt2[A[i]]; cnt2[pre]++; } cnt2.clear(); for (int i = 0; i < N; i++) { ll pre = B[i]; B[i] = mp[B[i]]+cnt2[B[i]]; cnt2[pre]++; } { vector<ll> tmp(N); for (int i = 0; i < N; i++) { tmp[B[i]] = i; } for (int i = 0; i < N; i++) { A[i] = tmp[A[i]]; } } ll ans = 0; BIT bit(N); for (ll i = 0; i < N; i++) { ans += i - bit.getsum(A[i]); bit.add(A[i], 1); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> //#include <atcoder/modint.hpp> using namespace std; #define all(a)a.begin(),a.end() using ll=long long; const int INF = 1<<30; const ll INFll =1LL<<62; const int mod= int(1e9)+7; const int mod2=998244353; using P = pair<int,int>; using Pl= pair<ll,ll>; using ld=long double; using V=vector<int>; using Vl=vector<ll>; using Vd=vector<ld>; using VV=vector<vector<int>>; using VVl=vector<vector<ll>>; using VVd=vector<vector<ld>>; //using mint=atcoder::modint1000000007; // modint: mod 計算を int を扱うように扱える構造体 template<int MOD> struct Fp { long long val; constexpr Fp(long long v = 0) noexcept : val(v % MOD) { if (val < 0) val += MOD; } constexpr int getmod() { return MOD; } constexpr Fp operator - () const noexcept { return val ? MOD - val : 0; } constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; } constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; } constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; } constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; } constexpr Fp& operator += (const Fp& r) noexcept { val += r.val; if (val >= MOD) val -= MOD; return *this; } constexpr Fp& operator -= (const Fp& r) noexcept { val -= r.val; if (val < 0) val += MOD; return *this; } constexpr Fp& operator *= (const Fp& r) noexcept { val = val * r.val % MOD; return *this; } constexpr Fp& operator /= (const Fp& r) noexcept { long long a = r.val, b = MOD, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } val = val * u % MOD; if (val < 0) val += MOD; return *this; } constexpr bool operator == (const Fp& r) const noexcept { return this->val == r.val; } constexpr bool operator != (const Fp& r) const noexcept { return this->val != r.val; } friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept { return os << x.val; } friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept { if (n == 0) return 1; auto t = modpow(a, n / 2); t = t * t; if (n & 1) t = t * a; return t; } }; using mint = Fp<mod>; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n;cin >>n; ll m;cin >>m; ll r=m; ll x=0; for (int i = 0; i < n; ++i) { int a;cin >>a; x+=(a+1); r-=a; } x++; // cout <<x<<" "<<r<<"\n"; //((x,r))を求めたい つまり(x+r-1,x-1)を求めたい mint ans=1; for (int i = 1; i <=x-1; ++i) { // cout<<x+r-i<<" "<<i<<"\n"; ans*=(x+r-i); ans/=i; } cout <<ans<<"\n"; return 0; }
#include<bits/stdc++.h> #define x first #define y second #define all(x) (x).begin(),(x).end() #define sz(x) (int)(x).size() #define mem(x,val) memset(x,val,sizeof x) #define pii pair<int,int> #define pb emplace_back #define ar array #define int long long #define FOR(i, a, b) for(int i = a; i < b; i++) #define F0R(i, n) FOR(i, 0, n) #define FOR1(i, n) FOR(i, 1, n+1) #define wopen(x) freopen((x),"w",stdout) #define ropen(x) freopen((x),"r",stdin) using namespace std; int a, b, c; signed main(void){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> a >> b >> c; a += c; if(b >= a) cout << "Aoki\n"; else cout << "Takahashi\n"; }
#include <bits/stdc++.h> using namespace std; int main(){ int A,B,C; cin >>A>>B>>C; if(A>B){ cout <<"Takahashi"<<endl; } if(A<B){ cout <<"Aoki"<<endl; } if(A==B){ if(C==0){ cout <<"Aoki"<<endl; } if(C==1){ cout <<"Takahashi"<<endl; } } }
#include<bits/stdc++.h> #define si(a) scanf("%d",&a) #define sl(a) scanf("%lld",&a) #define sd(a) scanf("%lf",&a) #define sc(a) scanf("%c",&a) #define ss(a) scanf("%s",a) #define pi(a) printf("%d\n",a) #define pl(a) printf("%lld\n",a) #define pc(a) putchar(a) #define ms(a) memset(a,0,sizeof(a)) #define repi(i, a, b) for(int i=a;i<=b;++i) #define repd(i, a, b) for(int i=a;i>=b;--i) #define reps(s) for(int i=head[s];i;i=Next[i]) #define ll long long #define ull unsigned long long #define vi vector<int> #define pii pair<int,int> #define mii unordered_map<int,int> #define msi unordered_map<string,int> #define lowbit(x) ((x)&(-(x))) #define ce(i, r) i==r?'\n':' ' #define pb push_back #define fi first #define se second #define all(x) x.begin(),x.end() #define pr(x) cout<<#x<<": "<<x<<endl using namespace std; inline int qr() { int f = 0, fu = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-')fu = -1; c = getchar(); } while (c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + c - 48; c = getchar(); } return f * fu; } const int N = 105; int head[N], ver[N * N << 1], Next[N * N << 1], tot; int siz[N], n; bool v[N]; char a[N]; inline void add(int x, int y) { ver[++tot] = y; Next[tot] = head[x]; head[x] = tot; } void dfs(int x) { siz[x]++, v[x] = true; reps(x)if (!v[ver[i]]) dfs(ver[i]); } int main() { n = qr(); repi(i, 1, n) { ss(a + 1); repi(j, 1, n)if (a[j] == '1')add(i, j); } repi(i, 1, n) { memset(v, false, sizeof(bool) * (n + 1)); dfs(i); } double ans = 0; repi(i, 1, n)ans += 1.0 / siz[i]; printf("%.9lf", ans); return 0; }
#include "bits/stdc++.h" #define int long long #define endl '\n' using namespace std; typedef long long ll; typedef long double ld; #define db(x) cerr << #x << ": " << x << '\n'; #define read(a) int a; cin >> a; #define reads(s) string s; cin >> s; #define readb(a, b) int a, b; cin >> a >> b; #define readc(a, b, c) int a, b, c; cin >> a >> b >> c; #define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];} #define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];} #define print(a) cout << a << endl; #define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl; #define printv(v) for (int i: v) cout << i << " "; cout << endl; #define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} #define all(v) v.begin(), v.end() #define sz(v) (int)(v.size()) #define rz(v, n) v.resize((n) + 1); #define pb push_back #define fi first #define se second #define vi vector <int> #define pi pair <int, int> #define vpi vector <pi> #define vvi vector <vi> #define setprec cout << fixed << showpoint << setprecision(20); #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define FORD(i, a, b) for (int i = (a); i >= (b); i--) const ll inf = 1e18; const ll mod = 1e9 + 7; const ll N = 2e5 + 1; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int power (int a, int b = mod - 2) { int res = 1; while (b > 0) { if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1; } return res; } vi adj[101], vis; int cnt = 0; void dfs (int cur) { cnt++; vis[cur] = 1; for (int i: adj[cur]) if (!vis[i]) dfs(i); } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); read(n); FOR (i, 1, n) { reads(s); FOR (j, 1, n) if (s[j - 1] == '1') adj[j].pb(i); } ld ans = 0; FOR (i, 1, n) { vis.assign(n + 1, 0); cnt = 0; dfs(i); ans += 1/(ld)(cnt); } setprec; print(ans); }
#include <bits/stdc++.h> // #include <atcoder/all> using namespace std; // using namespace atcoder; #define DEBUG(x) cerr<<#x<<": "<<x<<endl; #define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl; #define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;} typedef long long ll; // #define int ll #define vi vector<int> #define vl vector<ll> #define vii vector< vector<int> > #define vll vector< vector<ll> > #define vs vector<string> #define pii pair<int,int> #define pis pair<int,string> #define psi pair<string,int> #define pll pair<ll,ll> template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); } template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); } template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; } #define X first #define Y second #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rep1(i,n) for(int i=1;i<=(int)(n);i++) #define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--) #define rrep1(i,n) for(int i=(int)(n);i>0;i--) #define REP(i,a,b) for(int i=a;i<b;i++) #define in(x, a, b) (a <= x && x < b) #define all(c) c.begin(),c.end() template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; } #define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end()); const ll inf = 1000000001; const ll INF = (ll)1e18 + 1; const long double pi = 3.1415926535897932384626433832795028841971L; #define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl; // int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; // int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 }; vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1}; // vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 }; #define fio() cin.tie(0); ios::sync_with_stdio(false); const ll MOD = 1000000007; // const ll MOD = 998244353; // #define mp make_pair //#define endl '\n' double distance(pii a, pii b) { return sqrt((a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second)); } signed main() { fio(); int n; cin >> n; vector<pii> yx(n); rep (i, n) cin >> yx[i].second >> yx[i].first; sort(all(yx)); double ok = 0, ng = 100; rep (_, 200) { double r = (ok + ng) / 2; bool update_flag = true; vector<bool> dp(n); while (update_flag) { update_flag = false; rep (i, n) { if (yx[i].first + 100 < 2 * r) { if (not dp[i]) { dp[i] = true; update_flag = true; } } rep (j, n) { if (dp[j]) { double dist = distance(yx[i], yx[j]); if (dist < 2 * r) { if (not dp[i]) { dp[i] = true; update_flag = true; } } } } } } bool flag = true; rep (i, n) { if (dp[i]) { if (100 - yx[i].first < 2 * r) { flag = false; } } } (flag ? ok : ng) = r; } Sp(ok); }
// SmartCoder #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update using namespace __gnu_pbds; using namespace std; #define sz(a) int((a).size()) #define pb push_back #define mp make_pair #define all(c) (c).begin(), (c).end() #define tr(c, i) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++) #define present(c, x) ((c).find(x) != (c).end()) #define cpresent(c, x) (find(all(c), x) != (c).end()) #define minei(x) min_element(x.begin(), x.end()) - (x).begin() #define maxei(x) max_element(x.begin(), x.end()) - (x).begin() #define LSOne(S) (S & (-S)) #define uns(v) sort((v).begin(), (v).end()), v.erase(unique(v.begin(), v.end()), v.end()) #define acusum(x) accumulate(x.begin(), x.end(), 0) #define acumul(x) accumulate(x.begin(), x.end(), 1, multiplies<int>()); #define bits(x) __builtin_popcount(x) #define oo INT_MAX #define inf 1000000000 #define MAXN 1000007 #define MOD 1000000007 const double pi = acos(-1.0); const double eps = 1e-11; typedef long long ll; typedef pair<int, int> ii; typedef vector<ii> vii; typedef vector<int> vi; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; void pv(vector<int> v) { if (v.empty()) return; cout << v[0]; for (int i = 1; i < sz(v); i++) { cout << " " << v[i]; } cout << endl; } int main() { std::ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int h, m; cin >> m >> h; if (h % m == 0) cout << "Yes\n"; else cout << "No\n"; return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long void solve(){ ll n,i,j; cin >> n; map<ll,ll> mp; for(i=0;i<n;i++) { ll x; cin >> x; mp[x]++; } ll ans = n*(n-1)/2; for(auto k:mp) ans -= ( (k.second-1) * k.second ) / 2; cout<< ans; } int main(){ ll n , t = 1 ,tt = 1; // cin >> tt; while(t <= tt){ solve(); t++; } }
#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 << ']'; } template<class A, class B> istream& operator >>(istream& in, P<A, B> &p) { return in >> p.first >> p.second; } template<class A> istream& operator >>(istream& in, V<A> &v) { for (int i = 0; i < int(v.size()); i++) in >> v[i]; return in; } 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; cin >> n; vll a(n); cin >> a; map<ll, ll> acnt; rep(i, n) { acnt[a[i]]++; } ll ans = 0; for (PLL ap: acnt) { ans += ap.second * (n - ap.second); } cout << ans / 2 << '\n'; return 0; }
#include<iostream> #include<string> #include<algorithm> #include<cmath> #include<ctime> #include<map> #include<vector> #include<math.h> #include<stdio.h> #include<stack> #include<queue> #include<tuple> #include<cassert> #include<set> #include<bitset> #include<functional> #include <fstream> //#include<bits/stdc++.h> #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #define rep(i, x) for(ll i = 0; i < x; i++) #define rep2(i, x) for(ll i = 1; i <= x; i++) #define rep3(i, x, y) for(ll i = x; i < y; i++) #define rep4(i, x) for(ll i = x; i >= 0; i--) #define all(a) (a).begin(),(a).end() #define puts(x) cout << (x) << "\n" using ll = long long; using ld = long double; using namespace std; const ll INF = 1000000000000000000; const int intINF = 1000000000; const ll mod = 1000000007; const ll MOD = 998244353; const ld pi = 3.141592653589793238; //const ld EPS = 1e-9; bool isprime(int p) { if (p == 1) return false; for (int i = 2; i < p; i++) { if (p % i == 0) return false; } return true; } ll gcd(ll a, ll b) { if (a < b)swap(a, b); if (a % b == 0)return b; return gcd(b, a % b); } //ax + by = cが整数解をもつための必要十分条件は c が gcd(a,b) で割り切れること。 // 返り値: a と b の最大公約数 // ax + by = gcd(a, b) を満たす (x, y) が格納される //main関数内に extGCD(a, b, x, y); でx, yに解が格納 ll extGCD(ll a, ll b, ll& x, ll& y) { if (b == 0) { x = 1; y = 0; return a; } ll d = extGCD(b, a % b, y, x); y -= a / b * x; return d; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll keta(ll n) { ll res = 0; while (n >= 1) { res += n % 10; n /= 10; } return res; } ll modpow(ll x, ll y, ll m) { ll res = 1; while (y) { if (y % 2) { res *= x; res %= m; } x = x * x % m; y /= 2; } return res; } ll kaijyo[600005]; void nCkinit(ll n, ll m) { ll cnt = 1; kaijyo[0] = 1; for (int h = 1; h <= n; h++) { cnt *= h; cnt %= m; kaijyo[h] = cnt; } } ll nCk(ll n, ll k, ll m) { /*ll a = 1, b = 1; for (int h = 1; h <= n; h++) { a *= h; a %= m; } for (int h = 1; h <= k; h++) { b *= h; b %= m; } for (int h = 1; h <= n - k; h++) { b *= h; b %= m; }*/ ll a = kaijyo[n], b = kaijyo[k] * kaijyo[n - k] % m; return a * modpow(b, m - 2, m) % m; } //printf("%.10f\n", n); typedef pair <ll, ll> P; typedef pair <ll, string> pp; ll dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 }; struct edge { ll to, cost; }; struct status { ll d; ll c; ll s; bool operator<(const status& rhs) const { return d < rhs.d; }; bool operator>(const status& rhs) const { return d > rhs.d; }; }; int main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); //cout << fixed << setprecision(15); //input ll n; string s, t; cin >> n >> s >> t; ll zero = 0; rep(i, n) { if (s[i] == '0') { zero++; } } rep(i, n) { if (t[i] == '0') { zero--; } } if (zero != 0) { cout << "-1" << endl; return 0; } ll sone = 0, tone = 0, l = -1, ans = 0; rep(i, n) { if (s[i] == '1') { sone++; } if (t[i] == '1') { tone++; } if (sone == tone) { if (sone != 0) ans += (i - l) - sone; sone = 0; tone = 0; l = i; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace::std; int main() { int N; cin >> N; string s, t; cin >> s >> t; int s0 = 0; int t0 = 0; int ans = 0; for(int i = 0; i < N; i++) { if(s[i] == '0' && t[i] == '1') { ans += 1; s0 += 1; } else if(s[i] == '1' && t[i] == '0') { t0 += 1; } else if(s0 != t0 && s[i] == '0') { ans += 1; } } if(s0 != t0) { cout << -1 << endl; return 0; } cout << ans << endl; }
#include <algorithm> #include <iostream> #include <vector> #include <set> #include <cstdio> #include <math.h> #include <string> #include <sstream> #include <map> #include <unordered_map> #include <queue> #include <stack> #include <cassert> #include <iterator> #include <cstring> #include <fstream> #include <cstdio> #include<ctime> using namespace std; typedef long long ll; const int maxl = 110; int n, k, mod, lim; ll ans; ll dp[maxl][maxl * maxl * maxl]; inline void prework() { scanf("%d%d%d", &n, &k, &mod); lim = k * n * (n - 1) / 2; } inline void add(ll& x, ll y) { x = (x + y) % mod; if (x < 0) x += mod; } inline void mainwork() { dp[0][0] = 1; for (int i = 1; i < n; i++) { for (int j = 0; j <= lim; j++) { dp[i][j] = dp[i - 1][j]; if (j >= i) add(dp[i][j], dp[i][j - i]); } for (int j = lim; j >= (k + 1) * i; j--) add(dp[i][j], -dp[i][j - (k + 1) * i]); } } inline void print() { for (int x = 1; x <= n; x++) { ans = 0; for (int i = 0; i <= lim; i++) add(ans, dp[x - 1][i] * dp[n - x][i]); ans = ans * (k + 1) % mod; ans = (ans - 1 + mod) % mod; printf("%lld\n", ans); } } int main() { int t = 1; //scanf("%d",&t); for (int i = 1; i <= t; i++) { prework(); mainwork(); print(); } return 0; }
#include <bits/stdc++.h> // #include <atcoder/all> // using namespace atcoder; #define _overload3(_1,_2,_3,name,...) name #define _rep(i,n) repi(i,0,n) #define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i) #define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__) #define gnr(i,a,b) for(ll i=ll(b)-1;i>=ll(a);i--) #define per(i,b) gnr(i,0,b) #define all(x) x.begin(),x.end() #define SZ(x) ((int)(x).size()) #define PB push_back #define MP make_pair #define V vector #define P pair<int,int> #define Pbb pair<bool,bool> #define F first #define S second template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } using ll = long long; using ld = long double; using namespace std; const int INF =1001001001; const int MAX = 2e6+1; int main() { ll R,x,y;cin>>R>>x>>y; ll z=x*x+y*y; R*=R; if(z==R){ cout<<1<<endl; return 0; } ll ans=2; while(1){ if(ans*ans>=z){ cout<<ans<<endl; return 0; } if(ans*ans*R>=z){ cout<<ans<<endl; return 0; } ans++; } }
#include <bits/stdc++.h> using namespace std; using db = double; bool win(string s, string t) { int num[2][10]; for (int i = 0; i < 2; i ++) { for (int j = 0; j < 10; j ++) { num[i][j] = 0; } } for (int i = 0; i < 5; i ++) { int kj = (int)s[i] - (int)'0'; num[0][kj] ++; } for (int j = 0; j < 5; j ++) { int kj = (int)t[j] - (int)'0'; num[1][kj] ++; } int X[2]; for (int i = 0; i < 2; i ++) { X[i] = 0; for (int j = 0; j < 10; j ++) { int pk = j; for (int k = 0; k < num[i][j]; k ++) { pk *= 10; } X[i] += pk; } } //cout << s << ' ' << t << ' ' << X[0] << ' ' << X[1] << endl; return X[0] > X[1]; } int main () { long long K; cin >> K; long long numb[10]; for (int i = 1; i < 10; i ++) { numb[i] = K; } long long k_ = K; k_ *= 9; long long bo = ((k_ - 8) * (k_ - 9)) / 2; //cout << bo << endl; string s, t; cin >> s >> t; for (int i = 0; i < 4; i ++) { int kj = (int)s[i] - (int)'0'; numb[kj] --; } for (int i = 0; i < 4; i ++) { int kj = (int)t[i] - (int)'0'; numb[kj] --; } db ans = 0; long long ansn = 0; string key = "0123456789"; for (int x = 1; x < 10; x ++) { for (int y = 1; y < 10; y ++) { s[4] = key[x]; t[4] = key[y]; if (win(s, t)) { long long si = numb[x] * numb[y]; if (x == y) { si -= numb[x]; } ansn += si; //cout << x << ' ' << y << ' ' << ansn << endl; } } } //cout << ansn << endl; ans = (db)ansn / bo; cout << setprecision(20) << ans / 2 << endl; }
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < (n); i++) using namespace std; int n, t1[10], t2[10], sum1, sum2; string a, b; double res; int main() { cin >> n >> a >> b; REP(i, 4) t1[a[i]-'0']++, t2[b[i]-'0']++; REP(i, 10) sum1 += i*pow(10, t1[i]), sum2 += i*pow(10, t2[i]); for (int i=1; i<10; i++) for (int j=1; j<10; j++) { int A = sum1+9*i*pow(10,t1[i]); int T = sum2+9*j*pow(10,t2[j]); if (A>T) res += 1.0*(n-t1[i]-t2[i])/(9*n-8)*(n-t1[j]-t2[j]-(i==j))/(9*n-9); } printf("%.10f\n", res); return 0; }
#include <array> #include <iostream> using namespace std; using arr = array<int, 10>; int func_g1(const arr& a) { int t = 0; for (int i = 9; i >= 0; i--) { for (int jj = 0; jj < a[i]; jj++) { t = t * 10 + i; } } return t; } int func_g2(const arr& a) { int t = 0; for (int i = 0; i < 10; i++) { for (int jj = 0; jj < a[i]; jj++) { t = t * 10 + i; } } return t; } int get_length(const int x) { if (x < 10) return 1; if (x < 100) return 2; if (x < 1000) return 3; if (x < 10000) return 4; if (x < 100000) return 5; if (x < 1000000) return 6; if (x < 10000000) return 7; if (x < 100000000) return 8; if (x < 1000000000) return 9; return 10; } arr decomp(const int x) { arr t{}; int tmp = x; for (int i = 0, length = get_length(x); i < length; i++) { t[tmp % 10]++; tmp /= 10; } return t; } int main() { // C int N, K; cin >> N >> K; for (int i = 0; i < K; i++) { auto A = decomp(N); auto g1 = func_g1(A); auto g2 = func_g2(A); N = g1 - g2; } cout << N << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0;i<(n);i++) int main(){ int n,s,d;cin>>n>>s>>d; string ans="No"; REP(i,n){ int x,y;cin>>x>>y; if(s>x&&d<y) ans="Yes"; //if(d<y) ans="Yes"; } cout<<ans<<endl; }
#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> using namespace std; const long long Maxn=2e5+10; const long long Maxm=Maxn<<2; const long long mod=998244353; long long a[Maxn],c[Maxn]; long long tag[Maxm],sum[Maxm]; long long p[Maxn]; long long n,ans; inline long long read() { long long s=0,w=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();} while(ch>='0' && ch<='9')s=(s<<3)+(s<<1)+(ch^48),ch=getchar(); return s*w; } inline bool cmp(long long x,long long y) { return a[x]<a[y]; } long long power(long long x,long long y) { long long ret=1ll,base=x; while(y) { if(y & 1)ret=(ret*base)%mod; base=(base*base)%mod; y>>=1; } return ret; } inline long long inv(long long x) { return power(x,mod-2); } inline void push_up(long long k) { sum[k]=(sum[k<<1]+sum[k<<1|1])%mod; } inline void upd(long long k,long long v) { tag[k]=(tag[k]*v)%mod; sum[k]=(sum[k]*v)%mod; } inline void push_down(long long k) { if(tag[k]==1ll)return; upd(k<<1,tag[k]); upd(k<<1|1,tag[k]); tag[k]=1ll; } void build(long long k,long long l,long long r) { tag[k]=1ll; if(l==r) { if(l==1)sum[k]=(a[c[l]])%mod; else sum[k]=(p[l-2]*a[c[l]])%mod; return; } long long mid=(l+r)>>1; build(k<<1,l,mid); build(k<<1|1,mid+1,r); push_up(k); } void modify(long long k,long long l,long long r,long long x,long long y,long long v) { if(x<=l && r<=y)return upd(k,v); push_down(k); long long mid=(l+r)>>1; if(x<=mid)modify(k<<1,l,mid,x,y,v); if(mid<y)modify(k<<1|1,mid+1,r,x,y,v); push_up(k); } long long query(long long k,long long l,long long r,long long x,long long y) { if(x<=l && r<=y)return sum[k]; push_down(k); long long mid=(l+r)>>1,ret=0ll; if(x<=mid)ret=query(k<<1,l,mid,x,y); if(mid<y)ret=(ret+query(k<<1|1,mid+1,r,x,y))%mod; return ret; } int main() { // freopen("in.txt","r",stdin); n=read(); for(long long i=1;i<=n;++i) a[i]=read(),c[i]=i; sort(c+1,c+1+n,cmp); p[0]=1ll; for(long long i=1;i<=n;++i) p[i]=(p[i-1]*2ll)%mod; build(1,1,n); long long tmp=inv(2ll); for(long long i=1;i<=n;++i) { ans=(ans+(query(1,1,n,i,n)*a[c[i]])%mod)%mod; if(i+2<=n)modify(1,1,n,i+2,n,tmp); } printf("%lld\n",ans); return 0; }
#include <iostream> #include <vector> #include <utility> #include<algorithm> #include <string> #include <map> #include <cmath> #include <queue> #include <random> #include <tuple> #include <set> #define ll long long #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; int main(){ ll n; cin >> n; vector<vector<ll>> a(n,vector<ll>(2)); vector<tuple<ll,ll>> x(n); vector<tuple<ll,ll>> y(n); rep(i,n){ cin >> a[i][0] >> a[i][1]; x[i] = make_tuple(a[i][0],i); y[i] = make_tuple(a[i][1],i); } sort(x.begin(),x.end()); sort(y.begin(),y.end()); vector<vector<ll>> c; c = {{get<1>(x[0]),get<1>(x[n-1])},{get<1>(x[1]),get<1>(x[n-1])},{get<1>(x[0]),get<1>(x[n-2])}}; vector<ll> ans; rep(i,3){ vector<ll> d; d = c[i]; ll m = abs(a[d[0]][0]-a[d[1]][0]); ll p = abs(a[d[0]][1]-a[d[1]][1]); if(m >= p){ ans.push_back(-m); } } c = {{get<1>(y[0]),get<1>(y[n-1])},{get<1>(y[1]),get<1>(y[n-1])},{get<1>(y[0]),get<1>(y[n-2])}}; rep(i,3){ vector<ll> d; d = c[i]; ll m = abs(a[d[0]][0]-a[d[1]][0]); ll p = abs(a[d[0]][1]-a[d[1]][1]); if(m < p){ ans.push_back(-p); } } sort(ans.begin(),ans.end()); cout << -ans[1] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) using ll = long long; ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める int main() { ll n; cin >> n; ll a,b; ll total = 0; rep(i,n){ cin >> a >> b; total += (b*(b+1)/2) - (a*(a-1))/2; } cout << total << endl; return 0; }
#pragma Ofast //#pragma GCC optimize("Ofast,no-stack-protector") #include<bits/stdc++.h> #define int long long #define float double using namespace std; signed main(){ srand(time(NULL)); ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); int a; cin>>a; string b; cin>>b; bool fail=0; int suc=-1; int three=3; for(int ii=0;ii<3;ii++){ fail=0; for(int i=ii;i<a;i++){ if(i%3==2-ii){ //cout<<i<<" "<<b[i]<<" "<<0<<endl; if(b[i]!='0'){ fail=1; break; } } else{ //cout<<i<<" "<<b[i]<<" "<<1<<endl; if(b[i]!='1'){ fail=1; break; } } } if(fail==0){ suc=ii; break; } } if(suc==-1){ cout<<0<<endl; } else if(b=="111"){ cout<<0<<endl; } else if(b=="00"||b=="000"||b=="010"||b=="100"||b=="001"){ cout<<0<<endl; } else if(a==1){ if(b=="1") cout<<20000000000<<endl; if(b=="0"){ cout<<10000000000<<endl; } } else{ a+=suc; //cout<<a<<endl; suc=(a+2)/3; cout<<10000000000-suc+1<<endl; } return 0; }