code_file1
stringlengths
87
4k
code_file2
stringlengths
85
4k
#include <iostream> #include <vector> #include <algorithm> std::vector<std::vector<int>> children, list; std::vector<int> in, out, depth; int timer; void dfs(const int u) { in[u] = timer++; list[depth[u]].push_back(in[u]); for (const int v : children[u]) { depth[v] = depth[u] + 1; dfs(v); } out[u] = timer++; } int main() { int N; std::cin >> N; children = list = std::vector<std::vector<int>>(N); in = out = depth = std::vector<int>(N); for (int i = 1; i < N; ++i) { int p; std::cin >> p; children[p - 1].push_back(i); } dfs(0); int Q; std::cin >> Q; while (Q--) { int u, d; std::cin >> u >> d; u -= 1; const auto& v = list[d]; std::cout << std::lower_bound(v.cbegin(), v.cend(), out[u]) - std::lower_bound(v.cbegin(), v.cend(), in[u]) << '\n'; } return 0; }
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; #define all(v) v.begin(), v.end() #define pb push_back #define sz(x) (int)(x).size() const int N = 3e5 + 5; void solve() { int n, m; scanf("%d%d", &n, &m); vector<vi> g(n); vi cur, col(n, 0), vis(n, 0); for(int i = 0; i < m; ++i) { int u, v; scanf("%d%d", &u, &v); g[--u].pb(--v); g[v].pb(u); } auto check = [&](int u, int c) { for(auto v : g[u]){ if(col[v] == c) return 0; } return 1; }; function<void(int)> make = [&](int u) { cur.pb(u); vis[u] = 1; for(int v : g[u]) if(!vis[v]) make(v); }; function<int(int, int)> dfs = [&](int u, int c) -> int { if(u == sz(cur) - 1) { return 1; } int ret = 0; for(int i = 1; i <= 3; ++i) { if(check(cur[u + 1], i)) { col[cur[u + 1]] = i; ret += dfs(u + 1, i); col[cur[u + 1]] = 0; } } return ret; }; ll ans = 1; for(int i = 0; i < n; ++i) { if(!vis[i]) { cur.clear(); make(i); col[cur[0]] = 1; ans *= 3ll * dfs(0, 1); } } printf("%lld", ans); } int main() { int t = 1; // scanf("%d",&t); while(t--) solve(), puts(""); }
#include <bits/stdc++.h> #pragma GCC target ("sse4.2") using namespace std; bool home = 1; typedef long long ll; ///#define int ll typedef long double ld; typedef unsigned long long ull; signed realMain(); mt19937 rng_home(0); mt19937 rng_oj((long long) (new char)); int rng() { if (home) { return rng_home(); } else{ return rng_oj(); } } ull rng_ull() { return (ull) rng() * rng() ^ ((ull) rng() * rng()); } int rng_range(int l, int r) { return l + abs(rng()) % (r - l + 1); } signed main() { #ifdef ONLINE_JUDGE home = 0; #endif if (home) { freopen ("tony_stark", "r", stdin); } else { ios::sync_with_stdio(0); cin.tie(0); } realMain(); } const int N = 100 + 7; const int K = 10000 + 7; int n, a[N], b[K][N]; bool ok(int k) { for (int j = 1; j <= n; j++) { for (int i = 1; i <= k; i++) { b[i][j] = a[j] / k; } for (int i = 1; i <= a[j] % k; i++) { b[i][j]++; } } for (int i = 1; i <= k; i++) { for (int j = 1; j < n; j++) { if (b[i][j] == b[i][j + 1]) return 0; if ((b[i][j] > b[i][j + 1]) != (a[j] > a[j + 1])) { return 0; } } } return 1; } signed realMain() { cin >> n; n++; string do_not_need; cin >> do_not_need; for (int i = 1; i <= n; i++) { cin >> a[i]; } int l = 1, r = 10000, ret = 0; while (l <= r) { int m = (l + r) / 2; if (ok(m)) { ret = m; l = m + 1; } else { r = m - 1; } } ok(ret); cout << ret << "\n"; for (int i = 1; i <= ret; i++) { for (int j = 1; j <= n; j++) { cout << b[i][j] << " "; } cout << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll N; ll A[200]; ll memo[210][210]; ll f(int k, int a) { if (k == N) { if (a == 0)return 1; return 0; } if (memo[k][a] != -1)return memo[k][a]; return memo[k][a] = min(100LL, f(k + 1, a) + f(k + 1, (a - A[k] + 400) % 200)); } int main() { cin >> N; bool fff = 1; for (int i = 0; i < N; i++) { cin >> A[i]; A[i] %= 200; if (A[i] > 0)fff = 0; } if (fff) { puts("Yes"); puts("1 1"); puts("1 2"); return 0; } for (int i = 0; i < 210; i++)for (int j = 0; j < 210; j++)memo[i][j] = -1; for (int i = 199; i > 0; i--) { if (f(0, i) >= 2) { vector<int> B, C; int b = i, c = i; for (int j = 0; j < N; j++) { if (f(j + 1, b) && f(j + 1, (c - A[j] + 400) % 200)) { C.push_back(j); c = (c - A[j] + 400) % 200; } else if (f(j + 1, (b - A[j] + 400) % 200) && f(j + 1, c)) { B.push_back(j); b = (b - A[j] + 400) % 200; } else if (f(j + 1, (b - A[j] + 400) % 200) && f(j + 1, (c - A[j] + 400) % 200)) { C.push_back(j); c = (c - A[j] + 400) % 200; B.push_back(j); b = (b - A[j] + 400) % 200; } else { } } puts("Yes"); cout << B.size(); for (auto x : B) { cout << " " << x + 1; } cout << endl; cout << C.size(); for (auto x : C) { cout << " " << x + 1; } cout << endl; return 0; } } puts("No"); }
#include <iostream> #include <algorithm> #include <map> #include <set> #include <queue> #include <bitset> #include <climits> #include <string> #include <cmath> #include <bitset> #include <complex> #include <functional> #include <ctime> #include <cassert> #include <fstream> #include <stack> #include <random> #include <iomanip> #include <fstream> using namespace std; typedef long long ll; typedef long double dd; #define i_7 (ll)(1E9+7) //#define i_7 998244353 #define i_5 i_7-2 ll mod(ll a){ ll c=a%i_7; if(c>=0)return c; return c+i_7; } typedef pair<ll,ll> l_l; ll inf=(ll)1E18; #define rep(i,l,r) for(ll i=l;i<=r;i++) #define pb push_back ll max(ll a,ll b){if(a<b)return b;else return a;} ll min(ll a,ll b){if(a>b)return b;else return a;} dd EPS=1E-9; #define endl "\n" #define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int main(){fastio ll n,m;cin>>n>>m; ll a[n]; vector<ll> v[n]; rep(i,0,n-1)v[i].pb(-1); rep(i,0,n-1){ cin>>a[i]; v[a[i]].pb(i); } rep(i,0,n-1)v[i].pb(n); rep(i,0,n-1){ rep(j,0,(ll)v[i].size()-2){ ll a=v[i][j]; ll b=v[i][j+1]; if(b-a>m){ cout<<i<<endl; return 0; } } } cout<<n<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; template<typename T> inline void read(T &x){ x=0;bool dp=false;char ch=getchar(); while(!isdigit(ch)){dp|=ch=='-';ch=getchar();} while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();} x=dp?-x:x; return ; } template<typename T> inline void write(T x){ if(x<0) putchar('-'),x=-x; if(x>9) write(x/10); putchar(x%10^48); return ; } const int N=2e5+5,INF=1e9+7; #define ll long long int n,m; int main(){ read(n),read(m); if(m==0){ for(int i=1;i<=n;i++) printf("%d %d\n",i*2-1,i*2); return 0; } if(m<0 || m>n-2){ puts("-1"); return 0; } printf("1 %d\n",1<<25);int tot=2; for(int i=2;i<=m+2;i++,tot++) printf("%d %d\n",i*2-1,i*2); for(;tot<=n;tot++)printf("%d %d\n",(1<<25)+tot*2-1,(1<<25)+tot*2); }
#include <bits/stdc++.h> using namespace std; // modint 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() const { 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 istream& operator >> (istream& is, Fp<MOD>& x) noexcept { is >> x.val; x.val %= MOD; if (x.val < 0) x.val += MOD; return is; } friend constexpr ostream& operator << (ostream& os, const Fp<MOD>& x) noexcept { return os << x.val; } friend constexpr Fp<MOD> modpow(const Fp<MOD>& r, long long n) noexcept { if (n == 0) return 1; if (n < 0) return modpow(modinv(r), -n); auto t = modpow(r, n / 2); t = t * t; if (n & 1) t = t * r; return t; } friend constexpr Fp<MOD> modinv(const Fp<MOD>& 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); } return Fp<MOD>(u); } }; const int MOD = 1000000007; using mint = Fp<MOD>; int main() { long long N, M; cin >> N >> M; long long S = 0; vector<int> A(N); for (int i = 0; i < N; ++i) cin >> A[i], S += A[i]; mint res = 1; for (long long r = 0; r < N+S; ++r) { res *= N + M - r; res /= N + S - r; } cout << res << endl; }
using namespace std; #include <cstdio> #include <cstring> #include <algorithm> #define N 101 #define ll long long #define mo 998244353 int n,K; int a[N][N]; int dsu[N]; int getdsu(int x){return dsu[x]==x?x:dsu[x]=getdsu(dsu[x]);} ll fac[N]; ll work(){ for (int i=1;i<=n;++i) dsu[i]=i; for (int i=1;i<=n;++i) for (int j=i+1;j<=n;++j){ int x=getdsu(i),y=getdsu(j); if (x==y) continue; bool bz=1; for (int k=1;k<=n && bz;++k) if (a[i][k]+a[j][k]>K) bz=0; if (bz) dsu[x]=y; } static int cnt[N]; memset(cnt,0,sizeof cnt); for (int i=1;i<=n;++i) cnt[getdsu(i)]++; ll res=1; for (int i=1;i<=n;++i) if (dsu[i]==i) res*=fac[cnt[i]]; for (int i=1;i<=n;++i) for (int j=i+1;j<=n;++j) swap(a[i][j],a[j][i]); return res; } int main(){ scanf("%d%d",&n,&K); fac[0]=1; for (int i=1;i<=n;++i) fac[i]=fac[i-1]*i%mo; for (int i=1;i<=n;++i) for (int j=1;j<=n;++j) scanf("%d",&a[i][j]); ll ans1=work(); ll ans2=work(); printf("%lld\n",ans1*ans2%mo); return 0; }
#include<bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; int hist[n]; for (int i = 0; i < n; i++) cin >> hist[i]; stack<int> s; int max_area = 0; int tp; int area_with_top; int i = 0; while (i < n) { if (s.empty() || hist[s.top()] <= hist[i]) s.push(i++); else { tp = s.top(); s.pop(); area_with_top = hist[tp] * (s.empty() ? i : i - s.top() - 1); if (max_area < area_with_top) max_area = area_with_top; } } while (s.empty() == false) { tp = s.top(); s.pop(); area_with_top = hist[tp] * (s.empty() ? i : i - s.top() - 1); if (max_area < area_with_top) max_area = area_with_top; } cout << max_area << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
#include "bits/stdc++.h" using namespace std; #define int long long #define eb emplace_back #define mp make_pair typedef pair<int,int> pii; #define f first #define s second #define min(a,b) ((a<b)?a:b) bool debug=false; //const int mod=1000000007; char arr[400005],s; string mm="BWR"; #define op(a,b) ((a==b)?a:(3-a-b)) char solve(vector<char>&v){ if(debug){ cout<<"TRYING: "; for(char x:v){ cout<<(int)x; }cout<<'\n'; } vector<char> vv,v2; if(v.size()<=3){ vv=v; //pure brute force... while(vv.size()>1){ for(int i=0;i+1<vv.size();i++)vv[i]=op(vv[i],vv[i+1]); vv.pop_back(); } return vv[0]; }else{ int diff=( (v.size()-1)%3 )+1; for(int i=0;i<diff;i++){ v2.clear(); for(int j=i;j<v.size();j+=3)v2.push_back(v[j]); vv.push_back(solve(v2)); } return solve(vv); } } int32_t main(){ ios_base::sync_with_stdio(false);cin.tie(0); int n; cin>>n; vector<char> vv; for(int i=0;i<n;i++){ cin>>s; if(s=='B')arr[i]=0; else if(s=='W')arr[i]=1; else arr[i]=2; vv.push_back(arr[i]); } cout<<mm[solve(vv)]; return 0; } /* BW R WR B BR W BB B WW W RR R bw bw R bw wr W bw br B bw bb W bw ww B wr wr B wr br wr ww wr rr br bw br wr br br br bb br rr bb bw bb br bb bb ww bw ww wr ww ww rr wr rr br rr rr */
#include<bits/stdc++.h> using namespace std; #define ints(...) int __VA_ARGS__; vin(__VA_ARGS__) #define dbls(...) double __VA_ARGS__; vin(__VA_ARGS__) #define ulls(...) unsigned long long __VA_ARGS__; vin(__VA_ARGS__) #define strs(...) string __VA_ARGS__; vin(__VA_ARGS__) #define vifin(x, y) vi x(y); fin(x, y) #define vvis(x, y, z, p)vvi x(y, vi(z, p)) #define deb cout << "<deb> DEB" << endl #define debi(x) cout << "<deb> " << #x << " == " << x << endl #define rep(x, y) for(int x = 0; x < y; x++) #define reps(x, y, z) for(int x = y; x < z; x++) #define rev(x, y) for(int x = y; x >= 0; x--) #define revs(x, y, z) for(int x = y; x >= z; x--) #define syz(x) (int)x.size() #define ptg(x, y) (sqrt((x*x)+(y*y))) #define all(x) x.begin(), x.end() #define will(x) do{cout << x << endl; return 0;}while(0) using ll = long long; using ull = unsigned long long; using str = string; using vi = vector<int>; using vc = vector<char>; using vs = vector<str>; using vvi = vector<vector<int>>; using vvc = vector<vector<char>>; using pi = pair<int, int>; template<class T> using v = vector<T>; template<class T> using pq = priority_queue<T>; void vin(){return;} template<class T>void fin(T& __x,int __y){rep(i, __y){cin >>__x[i];};} void lout(){cout<<"=============================================="<<endl;} template<class T>void fout(T& __x){cout<<"<deb> ";for(auto __y:__x){cout<< __y<<' ';}cout<<endl;} template<class T>void fout(T& __x,int __y){cout<<"<deb> ";rep(i,__y)cout <<__x[i]<<' ';cout<<endl;} template<class T>void ffout(T __x){lout();for(auto __y:__x){for(auto __z:__y){cout<<__z<<' ';}cout<<endl;}} template<class T>void ffout(T __x,int __y,int __z){lout();rep(i,__y){rep(j,__z)cout<<__x[i][j]<<' ';cout<<endl;}lout();} template<class C,class ...T>inline void vin(C& __f,T&... __x){cin >> __f;vin(__x...);} template<class T>inline void chmax(T &a,const T &b){if(a<b)a=b;} template<class T>inline void chmin(T &a,const T &b){if(b<a)a=b;} constexpr ull LINF = 4500000000000000000; constexpr int INF = 2000000000; constexpr int four = 10007 ; constexpr int five = 100007 ; constexpr int six = 1000007 ; constexpr int seven = 10000007 ; constexpr int eight = 100000007 ; constexpr int nine = 1000000007; signed main() { ints(a, b, c, d); int sum = -INF; reps(i, a, b+1) { reps(j, c, d+1) { chmax(sum, i-j); } } cout << sum << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i,a,b) for(long long i=(long long)(a);i<(long long)(b);i++) #define ALL(a) (a).begin(),(a).end() typedef long long ll; typedef pair<ll,ll> P; ll a,b,c; int main(){ cin>>a>>b>>c; a%=10; b%=20; c%=4; if(c==0)c=4; ll d=(ll)pow(b,c)%4; if(d==0)d=4; ll an=(ll)pow(a,d)%10; cout<<an<<endl; }
#include<iostream> #include<cstdio> #include<string> #include<algorithm> #include<cmath> #include<vector> #include<stack> #include<queue> #include<map> #include<set> #include<cstring> using namespace std; typedef long long ll; ll a[200100]; void solve(int T) { int n; cin>>n; for(int i=1;i<=n;i++) { cin>>a[i]; } sort(a+1,a+n+1); ll sum=0; for(ll i=1;i<=n;i++) { //cout<<(a[i]*-1ll*(ll)(n-i)+a[i]*(ll)(i-1))<<endl; sum+=(a[i]*-1ll*(ll)(n-i)+a[i]*(ll)(i-1)); } cout<<sum; } //#define ONLINE_JUDGE; signed main() { #ifndef ONLINE_JUDGE freopen("lotato.in","r",stdin); freopen("lotato.out","w",stdout); #endif int t=1; //scanf("%d",&t); for(int i=1;i<=t;i++) { solve(i); } return 0; }
#include <bits/stdc++.h> #define rep(i, f, n) for (ll i = (f); i < (ll)(n); i++) #define repe(i, f, n) for (ll i = (f); i <= (ll)(n); i++) using namespace std; using ll = long long; using pint = pair<int, int>; int main() { int n; cin >> n; ll a, b, ans = 0; rep(i, 0, n) { cin >> a >> b; ll num = (b - a) + 1; ans += num * (a + (a + num - 1)) / 2; } cout << ans << endl; return 0; }
/*Author Sanjay shukla verdict Ac */ #include<iostream> #include<string.h> // #define endl ("\n") #define pi (3.141592653589) // #define int long long #define float double #define pb push_back #define mp make_pair #define ff first #define ss second #define all(c) cc.begin(), c.end() #define rrep(i, n) for(int i=n-1;i>=0;i--) #define rep(i,n) for(int i=0;i<n;i++) #define fast ios_base::sync_with_stdio(false), cin.tie(nullptr); using namespace std; // long long moduloMultiplication(long long a, // long long b, // long long mod) // { // long long res = 0; // Initialize result // // Update a if it is more than // // or equal to mod // a %= mod; // while (b) // { // // If b is odd, add a with result // if (b & 1) // res = (res + a) % mod; // // Here we assume that doing 2*a // // doesn't cause overflow // a = (2 * a) % mod; // b >>= 1; // b = b / 2 // } // return res; // } int32_t main(){ fast string s; cin>>s; int occurrences = 0; std::string::size_type pos = 0; std::string target = "ZONe"; while ((pos = s.find(target, pos )) != std::string::npos) { ++ occurrences; pos += target.length(); } std::cout << occurrences << std::endl; return 0; }
#include<bits/stdc++.h> using namespace std; int main() { string s; cin>>s; int p=0; for(int i=0;i<9;i++) { if(s[i]=='Z'&&s[i+1]=='O'&&s[i+2]=='N'&&s[i+3]=='e') p++; } cout<<p; return 0; }
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "/debug.h" #else #define db(...) #endif #define all(v) v.begin(), v.end() #define pb push_back using ll = long long; const int NAX = 2e5 + 5, MOD = 1000000007; void solveCase(int64_t A, int64_t B, int64_t W) { // TODO: edit here W *= 1000; vector<set<pair<int, int>>> toadd(W + A + B + 1), torem(W + A + B + 1); set<pair<int, int>> curr; curr.insert({0, 0}); torem[1].insert({0, 0}); for (size_t i = 0; i <= W; i++) { for (auto &x : toadd[i]) curr.insert(x); for (auto &x : torem[i]) curr.erase(x); db(i, curr, toadd[i], torem[i]); if (curr.size()) { auto mini = (curr.begin())->first; auto maxi = (curr.rbegin())->first; toadd[i + A].insert({mini + 1, i}); torem[i + B + 1].insert({mini + 1, i}); toadd[i + A].insert({maxi + 1, i}); torem[i + B + 1].insert({maxi + 1, i}); } } if (curr.size()) { auto mini = (curr.begin())->first; auto maxi = (curr.rbegin())->first; cout << mini << ' ' << maxi << '\n'; } else cout << "UNSATISFIABLE\n"; } // generated by oj-template v4.7.2 (https://github.com/online-judge-tools/template-generator) int main() { #ifndef LOCAL std::ios::sync_with_stdio(false); std::cin.tie(nullptr); #endif constexpr char endl = '\n'; int64_t A, B, W; cin >> A >> B >> W; solveCase(A, B, W); return 0; }
#include <bits/stdc++.h> #define mem(arr, val) memset(arr, val, sizeof(arr)) #define all(v) v.begin(), v.end() #define endl '\n' #define decision (yes ? "YES" : "NO") using namespace std; typedef pair<int, int> pii; typedef pair<long long, long long> pll; typedef pair<long long, int> pli; typedef pair<int, long long> pil; // const double PI = acos(-1.0); // const double E = exp(1.0); const double EPS = 1e-9; const int INF = (int)2e9; const int MOD = (int)1e9 + 7; const int N = (int)1e5; int main() { #ifdef MY_LOCAL freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(nullptr); int a, b, w; cin >> a >> b >> w; w *= 1000; int mini, maxi; mini = (w + b - 1) / b; maxi = w / a; if (mini > maxi) { cout << "UNSATISFIABLE" << endl; return 0; } cout << mini << " " << maxi << endl; return 0; }
#include<ctime> #include<cmath> #include<cstdio> #include<cctype> #include<algorithm> #define ll long long using namespace std; const double k=(sqrt(5)-1)/2; const double t=k; ll read(){ char c; ll x=0,f=1; while(!isdigit(c=getchar())) f-=2*(c=='-'); while(isdigit(c)){ x=x*10+f*(c-48); c=getchar(); } return x; } ll n,x,y,cnt,ans[1000]; void solve(){ if(n==1){ puts("1"); puts("1"); return; } ans[1]=3; for(ll i=max(0ll,(ll)(k*n-1000000));i<=min(n,(ll)(k*n+1000000));++i){ x=i; cnt=1; y=n-x; while(x>=1&&y>=1){ if(cnt>130) break; if(x>y){ ans[++cnt]=3; x-=y; } else{ ans[++cnt]=4; y-=x; } } while(x){ if(cnt>130) break; --x; ans[++cnt]=1; } while(y){ if(cnt>130) break; --y; ans[++cnt]=2; } if(cnt<=130) break; } printf("%lld\n",cnt); for(ll i=cnt;i;--i) printf("%lld\n",ans[i]); } int main(){ #ifndef ONLINE_JUDGE freopen("C.in","r",stdin); freopen("C.out","w",stdout); #endif clock_t t1=clock(); //-------- n=read(); solve(); //-------- fprintf(stderr,"%0.3lfs",1.0*(clock()-t1)/CLOCKS_PER_SEC); return 0; }
#include <bits/stdc++.h> #define REP(x, a) for(int x=0; x<a; x++) #define sz(x) (int) (x).size() using namespace std; int _; void solve() { string s; cin >> s; int n = sz(s); if (s > "atcoder") { cout << 0 << '\n'; return; } int pos = -1; REP(i, n) { if (s[i] != 'a') { pos = i; break; } } if (pos == -1) { cout << -1 << '\n'; return; } if (s[pos] > 't') cout << pos - 1 << '\n'; else cout << pos << '\n'; } int main(void) { ios_base::sync_with_stdio(false); cin.tie(0); for (cin >> _; _; --_) solve(); return 0; }
// Guess Who's Back #include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define endl '\n' #define D(x) cerr << #x << " = " << (x) << '\n' #define sz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() typedef long long ll; const int N = 2e5 + 5; int n; int arr[N]; int par[N]; int fs(int x) { return x == par[x] ? x : par[x] = fs(par[x]); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); for(int i = 0; i < N; i++) { par[i] = i; } cin >> n; for(int i = 0; i < n; i++) { cin >> arr[i]; } int ans = 0; for(int i = 0; i < n / 2; i++) { int j = n - 1 - i; int x = fs(arr[i]), y = fs(arr[j]); if(x != y) { ans++; par[x] = y; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; // #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> #define FS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define ll long long int #define ld long double #define pb push_back #define bp __builtin_popcount #define sz size() #define ff first #define ss second #define vll vector<ll> #define vbool vector<bool> #define vpll vector<pair<ll,ll>> #define pll pair<ll,ll> #define vllv vector<vector<ll>> #define setpri(x) cout<<setprecision(x)<<fixed; #define all(v) v.begin(),v.end() #define allr(v) v.rbegin(),v.rend() #define yesr {cout<<"YES"<<endl;return;} #define nor {cout<<"NO"<<endl;return;} // getline (std::cin,name); ll MOD=1e9+7; ll ceil1(ll n,ll x){return (n-1)/x+(n>0);} ll gcd(ll a,ll b){return __gcd(a,b);} ll lcm(ll a,ll b){return (max(a,b)/gcd(a,b))*min(a,b);} ll pow1(ll n,ll m ,ll mod=MOD ); ll pow2(ll n,ll k); ll modinv(ll n,ll mod=MOD){ return pow1(n,mod-2,mod);} bool func(pair<ll,ll> &a,pair<ll,ll> &b ){ if(a.ff != b.ff)return a.ff < b.ff; return a.ss > b.ss; } ll const N=(ll)3e5+11; ll const LG=(ll)log2(N)+1; void solve() { ll i,j,k,l,n,m,x,y,z,r; cin>>n; map<string,ll> mp; set<string> st; for(i=0;i<n;i++){ string t; cin>>t; if(st.find(t)==st.end()){ if(t[0]=='!'){ mp[t.substr(1)]++; } else{ mp[t]++; } } st.insert(t); } for(auto x:mp){ if(x.ss>1){ cout<<x.ff<<endl; return; } } cout<<"satisfiable\n"; return; } int main(){ FS; ll i,j,k,n,m,x,y,z,q; q=1; // cin>>q; for(ll tc=1;tc<=q;tc++){ // cout<<"Case #"<<tc<<": "; solve(); } return 0; } ll pow1(ll n,ll m,ll mod){ if(m==0)return 1; if(m%2==0)return pow1((n*n)%mod,m/2,mod); return (pow1((n*n)%mod,m/2,mod)*n)%mod; } ll pow2(ll n,ll k){ ll ans=1; while(k>0){ if(k%2==1)ans=ans*n; n=n*n; k/=2; } return ans; }
#include<bits/stdc++.h> #include<string> using namespace std; #define ll long long int #define ld long double #define pb push_back #define all(v) v.begin(),v.end() #define sz(x) ((int)(x).size()) #define deb(x) cout<< #x << '=' << x <<endl #define MOD 1000000007 const int N = 2e6 + 5; ll n , m , k; ll fact[N]; ll mod_pow(ll a , ll n , ll mod){ if(n == 0){ return 1; } ll res = mod_pow((a*a)%mod , n/2 , mod); if(n % 2){ res = (res*a)%mod; } return res; } ll mod_inv(ll x , ll mod){ return mod_pow(x , mod - 2 , mod); } ll nCr(ll n , ll r , ll mod){ return ((fact[n]*mod_inv(fact[r] , mod) % mod)* (mod_inv(fact[n - r] , mod) % mod))%mod; } void factorial(ll mod){ fact[0] = 1; for(int i = 1; i < N; i++){ fact[i] = (i*fact[i - 1]); fact[i] %= mod; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); factorial(MOD); cin>>n>>m>>k; if(m + k < n){ cout<<"0\n"; return 0; } ll ans = nCr(n + m , n , MOD) - nCr(n + m , n - k - 1 , MOD); if(ans < 0){ ans += MOD; } ans %= MOD; cout<<ans; return 0; }
/*Jai Shree Ram*/ // Never Give Up /*自分を信じない人にとっては、一生懸命働くことは無意味です*/ #include<bits/stdc++.h> #include<unordered_map> 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 umii unordered_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 mod 1000000007 #define inf 1e18 #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 F(i,s,e,j) for(int i=s;i<=e;i+=j) #define mt19937 rng(chrono::steady_clock::now().tjhe_since_epoch().count()); //shuffle(arr,arr+n,rng) /*---------------------------------------------------------------------------------------------------------------------------*/ int gcd(int a, int b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);} int expo(int a, int b,int m) {int res = 1; while (b > 0) {if (b & 1)res = (res * a) % m; a = (a * a) % m; b = b >> 1;} return res;} void extendgcd(int a, int b, int*v) {if (b == 0) {v[0] = 1; v[1] = 0; v[2] = a; return ;} extendgcd(b, a % b, v); int x = v[1]; v[1] = v[0] - v[1] * (a / b); v[0] = x; return;} //pass an arry of size1 3 int mminv(int a, int b) {int arr[3]; extendgcd(a, b, arr); return arr[0];} //for non prime b int mminvprime(int a, int b) {return expo(a, b - 2, b);} void swap(int &x, int &y) {int temp = x; x = y; y = temp;} int combination(int n, int r, int m, int*fact, int *ifact) {int val1 = fact[n]; int val2 = ifact[n - r]; int val3 = ifact[r]; return (((val1 * val2) % m) * val3) % m;} void google(int t) {cout << "Case #" << t << ": ";} vi sieve(int n) {int*arr = new int[n + 1](); vi vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;} int mod_add(int a, int b, int m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} int mod_mul(int a, int b, int m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;} int mod_sub(int a, int b, int m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} int mod_div(int a, int b, int m) {a = a % m; b = b % m; return (mod_mul(a, mminvprime(b, m), m) + m) % m;} //only for prime m int phin(int n) {int number = n; if (n % 2 == 0) {number /= 2; while (n % 2 == 0) n /= 2;} for (int i = 3; i <= sqrt(n); i += 2) {if (n % i == 0) {while (n % i == 0)n /= i; number = (number / i * (i - 1));}} if (n > 1)number = (number / n * (n - 1)) ; return number;} //O(sqrt(N)) /*--------------------------------------------------------------------------------------------------------------------------*/ void c_p_c() { 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); #endif } const int MAXN = 2000000; int fact[MAXN+1]; int inv_fact[MAXN+1]; void pre_compute() { fact[0] = 1; for(int i=1;i<=MAXN;i++) fact[i] = mod_mul(i,fact[i-1],mod); inv_fact[0] = 1; for(int i=1;i<=MAXN;i++) inv_fact[i] = mod_mul(mminv(i,mod),inv_fact[i-1],mod); } int combination(int i,int j) { int ans = fact[i]; ans = mod_mul(ans,inv_fact[j],mod); ans = mod_mul(ans,inv_fact[i-j],mod); return ans; } int32_t main() { c_p_c(); pre_compute(); int n,m,k; cin>>n>>m>>k; if(n>m+k) cout<<0<<endl; else { int ans = (combination(m+n,m)-combination(n+m,n-k-1)+mod)%mod; cout<<ans<<"\n"; } }
#pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <iostream> #include <string> #include <cstdlib> #include <cmath> #include <vector> #include <unordered_map> #include <map> #include <set> #include <algorithm> #include <queue> #include <stack> #include <functional> #include <bitset> #include <assert.h> #include <unordered_map> #include <fstream> #include <ctime> #include <complex> 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-10; 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){ for(auto itr = a.begin(); itr != a.end(); itr++){ cout << *itr << " "; } cout << "\n"; } template<typename T1,typename T2> inline void print2(T1 a, T2 b){ cout << "debug: " << a << " " << b << "\n"; } template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){ cout << "debug: " << 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; const int M = 127500; int dp[101][M+1]; int sdp[101][M+2]; int main(){ int N,K,mod; cin >> N >> K >> mod; dp[0][0] = 1; rep(j,K+1) sdp[0][j] = 1; for(int i=1; i<=N; i++){ rep(j,M+1){ dp[i][j] += sdp[j%i][j]; dp[i][j] %= mod; sdp[j%i][j] = 0; } rep(j,M+1){ (sdp[j%(i+1)][j] += dp[i][j]) %= mod; (sdp[j%(i+1)][min(M+1,j+((K+1)*(i+1)))] += mod - dp[i][j]) %= mod; } rep(j,i+1){ for(int k=j; k+i+1<=M; k+=i+1){ (sdp[j][k+(i+1)] += sdp[j][k]) %= mod; } } } for(int x=1; x<=N; x++){ ll ans = mod-1; for(int i=0; i<=M; i++){ ans += (ll)dp[x-1][i] * dp[N-x][i] % mod * (K+1) % mod; ans %= mod; } cout << ans << "\n"; } }
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cmath> #include <cstdint> #include <cstdio> #include <cstring> #include <deque> #include <fstream> #include <functional> #include <iostream> #include <limits> #include <map> #include <numeric> #include <queue> #include <set> #include <vector> using namespace std; using ll = long long; #define fst first #define snd second /* clang-format off */ template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; }; template <class T> struct _vec<T, 0> { using type = T; }; template <class T, size_t D> using vec = typename _vec<T, D>::type; template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); } template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); } template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; } template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; } /* clang-format on */ const int MAX = 505000 + 10; int main() { #ifdef DEBUG ifstream ifs("in.txt"); cin.rdbuf(ifs.rdbuf()); #endif int N, K, M; while (cin >> N >> K >> M) { auto dp = make_v(N + 1, MAX, 0); auto sum = make_v(MAX, 0); dp[0][0] = 1; for (int n = 1; n <= N; n++) { for (int w = 0; w < MAX; w++) { sum[w] = (dp[n - 1][w] + (w - n >= 0 ? sum[w - n] : 0)) % M; } for (int w = 0; w < MAX; w++) { dp[n][w] = (sum[w] - (w - n * (K + 1) >= 0 ? sum[w - n * (K + 1)] : 0) + M) % M; } } for (int x = 1; x <= N; x++) { int res = 0; for (int w = 0; w < MAX; w++) { res = (res + 1ll * dp[x - 1][w] * dp[N - x][w] % M) % M; } res = (1ll * res * (K + 1)) % M; res = (res - 1 + M) % M; cout << res << endl; } } return 0; }
#include<bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; using namespace std; // typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; #define ll long long #define scn(n) scanf("%d",&n) #define lscn(n) scanf("%lld",&n) #define lpri(n) printf("%lld",n) #define pri(n) printf("%d",n) #define pln() printf("\n") #define priln(n) printf("%d\n",n) #define lpriln(n) printf("%lld\n",n) #define rep(i,init,n) for(int i=init;i<n;i++) #define pb push_back #define mp make_pair #define F first #define S second #define gcd __gcd #define inf INT_MAX #define ninf INT_MIN #define inf INT_MAX #define linf LLONG_MAX #define lninf LLONG_MIN const int mod = 1e9 + 7; const int N = 1e6 + 4; int solve() { int n, m; scn(n); scn(m); map<int, int> ma; rep(i, 0, n) { int val; scn(val); ma[val]++; } rep(i, 0, m) { int val; scn(val); ma[val]++; } for(auto it: ma) if(it.S == 1) printf("%d ", it.F); return 0; } int main() { int t = 1; //scn(t); while(t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; #define rep(i, n) for(int i = 0; i < (n); ++i) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define io ios::sync_with_stdio(false); cin.tie(0) int main() { io; int n, k; cin >> n >> k; vector<int> a(n); vector<int> cnt(n, 0); rep(i, n) { cin >> a[i]; cnt[a[i]]++; } int res = 0; rep(i, k) { rep(j, n) { if (cnt[j] == 0) { res += j; break; } cnt[j]--; } } cout << res << endl; return 0; }
#include <iostream> #include <cmath> using namespace std; void solve(double a,double b,double W){ int min=ceil(W/b),max=floor(W/a); if((b*min-W)<=(b-a)*min&&(a*max-W)<=(b-a)*max){ cout<<min<<" "<<max; }else{ cout<<"UNSATISFIABLE"; } } int main(){ double a,b,w; cin>>a>>b>>w; double W=1000*w; solve(a,b,W); return 0; }
#include<iostream> #include<utility> #include<algorithm> #include<set> #include<vector> #include<cmath> #define forn(i, x, n) for(int i = x; i < n; i++) using namespace std; typedef long long ll; const int mod = 1e9 + 7; const bool DEBUG = 0; void solve(){ int a, b, w; cin>>a>>b>>w; w *= 1000; int mn = ceil(w * 1.0 / b); int mx = w / a; if(mx < mn || mn == 0) cout<< "UNSATISFIABLE"; else cout<< mn << ' ' << mx; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; //cin>>t; //while(t--) cout<<solve()<<'\n'; while(t--) solve(), cout<<'\n'; }
#include <bits/stdc++.h> using namespace std; int main() { int n, x, y, count, Flag; cin >> n; count = 0; for (int i = 1; i <= n; i++) { Flag = 0; x = i; y = i; for (int j = 0; j < 10; j++) { if ((x%10)==7 || (y%8)==7) Flag = 1; x = x / 10; y = y / 8; } if(Flag == 0) count++; } cout << count << endl; }
#include <bits/stdc++.h> using namespace std; int main() { string S; cin>>S; int ans=0; for(int i=0;i<S.size();i++){ if(S.at(i)=='Z' && i<9){ if(S.at(i+1)=='O'){ if(S.at(i+2)=='N'){ if(S.at(i+3)=='e'){ ans++; }else{ continue; } }else{ continue; } }else{ continue; } }else{ continue; } } cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; const vector<int> XS = { 0, 0, 1, 1 }; const vector<int> YS = { 0, 1, 0, 1 }; const char BLACK = '#'; int count(int i, int j, vector<string> &s) { int count = 0; for (int k = 0; k < int(XS.size()); k++) { if (BLACK == s[i + XS[k]][j + YS[k]]) { count++; } } return count; } int main(void) { int h, w; cin >> h >> w; vector<string> s(h); for (int i = 0; i < h; i++) { cin >> s[i]; } int ans = 0; for (int i = 0; i < h - 1; i++) { for (int j = 0; j < w - 1; j++) { if (1 == (1 & count(i, j, s))) { ans++; } } } cout << ans << endl; return 0; }
#define _GLIBCXX_DEBUG #include<bits/stdc++.h> using namespace std; typedef long long ll; using Graph = vector<vector<ll>>; #define REP(i,n) for(ll i=0;i<ll(n);i++) #define REPD(i,n) for(ll i=n-1;i>=0;i--) #define FOR(i,a,b) for(ll i=a;i<ll(b);i++) #define FORD(i,a,b) for(ll i=a;i>=b;i--) #define ALL(x) x.begin(),x.end() #define SIZE(x) ll(x.size()) #define INF 1000000000000 //10^12 #define MOD 1000000007 //10^9+7:合同式の法 int main(){ ll n,k; cin >> n >> k; vector<ll> vec; REP(i,n){ REP(j,k){ ll tmp = 100*(i+1); tmp += j+1; vec.push_back(tmp); } } /* REP(i,vec.size()){ cout << vec[i] << endl; }*/ cout << accumulate(vec.begin(),vec.end(),0) << endl; return 0; }
#include <bits/stdc++.h> #include <math.h> #include <chrono> using namespace std; #pragma GCC optimize("-O3") #define endl "\n" #define mp make_pair #define st first #define nd second #define pii pair<int, int> #define pb push_back #define _upgrade ios_base::sync_with_stdio(0), cout.setf(ios::fixed), cout.precision(10), cin.tie(0), cout.tie(0); #define REP(i, n) for (int i = 0; i < (n); ++i) #define FWD(i, a, b) for (int i = (a); i < (b); ++i) #define rep(i, n) for (int i = 0; i < (n); ++i) #define fwd(i, a, b) for (int i = (a); i < (b); ++i) #define all(c) (c).begin(), (c).end() #define sz(X) (int)((X).size()) #define what(x) cerr << #x << " is " << x << endl; ostream &operator<<(ostream &out, string str) { for (char c : str) out << c; return out; } template <class L, class R> ostream &operator<<(ostream &out, pair<L, R> p) { return out << "(" << p.st << ", " << p.nd << ")"; } template <class T> auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) { out << '{'; for (auto it = a.begin(); it != a.end(); it = next(it)) out << (it != a.begin() ? ", " : "") << *it; return out << '}'; } void dump() { cerr << "\n"; } template <class T, class... Ts> void dump(T a, Ts... x) { cerr << a << ", "; dump(x...); } #define debug(...) cerr << "[" #__VA_ARGS__ "]: ", dump(__VA_ARGS__) const int MAXM = 1e8 + 99; const int silnia = 40320; int n, m; int V[10]; int maks[MAXM + 22]; int get(vector<int> &X, int x, int y) { int s = 0; for (int i = x; i <= y; i++) s += V[X[i]]; return maks[min(s, MAXM)]; } int solve(vector<int> X) { vector<int> dp(10); for (int i = n - 1; i >= 0; i--) for (int j = i + 1; j < n; j++) dp[i] = max(dp[j] + get(X, i, j), dp[i]); // debug(X, dp); return dp[0]; } int32_t main() { _upgrade; cin >> n >> m; rep(i, n) cin >> V[i]; rep(i, m) { int l, v; cin >> l >> v; maks[v + 1] = max(l, maks[v + 1]); } rep(i, MAXM + 10) maks[i + 1] = max(maks[i], maks[i + 1]); vector<int> perm; rep(i, n) perm.push_back(i); rep(i, n) if (maks[V[i]] > 0) { // debug(i, V[i], maks[V[i]]); cout << -1 << endl; exit(0); } int res = 1e9; do { res = min(res, solve(perm)); // debug(perm); } while (next_permutation(all(perm))); cout << res << endl; }
#include <iostream> #include <algorithm> #include <cstring> #include <vector> #include <bits/stdc++.h> #include <stdio.h> using namespace std; const int M = 1e5+5; int n,m; int w[10]; int sums[M],mw[M]; int main(){ cin >> n >> m; int maxw = 0; for(int i = 0;i < n;i++){ cin >> w[i]; maxw = max(maxw,w[i]); } int minv = 0x3f3f3f3f; for(int i = 0;i < 1<<n;i++){ int x = 0; for(int j = 0;j < n;j++) if(i >> j & 1)x+=w[j]; sums[i] = x; } for(int i = 0;i < m;i++){ int a,b; cin >> a >> b; minv = min(minv,b); for(int s = 0;s < 1 << n;s++) if(sums[s] > b) mw[s] = max(mw[s],a); } if(maxw > minv){ cout << "-1"<<endl; return 0; } int ans = 0x3f3f3f3f; vector<int>perm(n); iota(perm.begin(),perm.end(),0); do{ vector<int>pos(n); for(int i = 0;i < n;i++){ int x = 0; for(int j = i;j >= 0;j--){ x|=1 << perm[j]; pos[i] = max(pos[i],pos[j]+mw[x]); } } ans = min(ans,pos[n-1]); }while(next_permutation(perm.begin(),perm.end())); cout << ans << endl; return 0; }
#include<iostream> using namespace std; int main() { string s, c; cin >> s >> c; int a = 0, b = 0; for (int i = 0; i < s.length(); i++) { a += s[i] - '0'; } for (int i = 0; i < c.length(); i++) { b += c[i] - '0'; } if (a > b) { cout << a; } else { cout << b; } }
#include <bits/stdc++.h> using namespace std; int sum(int n){ int a = n/100; int b = (n-a*100)/10; int c = (n-a*100-b*10); return a+b+c; } int main() { int a, b; cin >> a >> b; int asum = sum(a); int bsum = sum(b); cout << max(asum, bsum) << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define e(v) sort(v.begin(), v.end()) #define rev(v) reverse(v.begin(), v.end()) #define out(s) cout << s << endl typedef long long ll; using Graph = vector<vector<int>>; const int MOD = 1000000007; int main(){ int n; cin >> n; vector<int> x(n), y(n); rep(i,n){ cin >> x.at(i) >> y.at(i); } int num = 0; for (int i = 0; i < n - 1;i++){ for (int j = i + 1; j < n;j++){ float t = (float)(y.at(j) - y.at(i)) / (float)(x.at(j) - x.at(i)); if (t >= -1 && t <= 1) { num++; } } } out(num); }
#include <bits/stdc++.h> using namespace std; struct node { int x, y; } a[1010]; int n, ans; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d%d", &a[i].x, &a[i].y); for (int i = 1; i <= n; i++) for (int j = i + 1; j <= n; j++) if (i != j && a[i].x != a[j].x) if ((double)(a[i].y - a[j].y) / (double)(a[i].x - a[j].x) <= 1.0 && (double)(a[i].y - a[j].y) / (double)(a[i].x - a[j].x) >= -1.0) ans++; printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)n;i++) using namespace std; using ll = long long; using ld = long double; int main() { int N; ll ans=10000000; cin >> N; vector<ll>A(N), B(N); rep(i, N) { cin >> A[i] >> B[i]; ans = min(ans, A[i] + B[i]); } sort(A.begin(), A.end());sort(B.begin(), B.end()); if (A[0] + B[0] != ans) { ans = min(ans, max(A[0], B[0])); } else { ans = min(ans, max(A[0], B[1])); ans = min(ans, max(A[1], B[0])); } cout << ans<< endl; }
#include<bits/stdc++.h> using namespace std; namespace Sakurajima_Mai{ #define ms(a) memset(a,0,sizeof(a)) #define repi(i,a,b) for(int i=a,bbb=b;i<=bbb;++i)//attention reg int or reg ll ? #define repd(i,a,b) for(int i=a,bbb=b;i>=bbb;--i) #define reps(s) for(int i=head[s],v=e[i].to;i;i=e[i].nxt,v=e[i].to) #define ce(i,r) i==r?'\n':' ' #define pb push_back #define all(x) x.begin(),x.end() #define gmn(a,b) a=min(a,b) #define gmx(a,b) a=max(a,b) #define fi first #define se second typedef long long ll; typedef unsigned long long ull; typedef double db; const int infi=1e9;//infi较大,注意涉及inf相加时爆int const ll infl=4e18; inline ll ceil_div(ll a,ll b){ return (a+b-1)/b; } inline ll pos_mod(ll a,ll b){ return (a%b+b)%b; } //std::mt19937 rnd(time(0));//std::mt19937_64 rnd(time(0)); } using namespace Sakurajima_Mai; namespace Fast_Read{ inline int qi(){ 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; } inline ll ql(){ ll f=0;int 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; } inline db qd(){ char c=getchar();int flag=1;double ans=0; while((!(c>='0'&&c<='9'))&&c!='-') c=getchar(); if(c=='-') flag=-1,c=getchar(); while(c>='0'&&c<='9') ans=ans*10+(c^48),c=getchar(); if(c=='.'){c=getchar();for(int Bit=10;c>='0'&&c<='9';Bit=(Bit<<3)+(Bit<<1)) ans+=(double)(c^48)*1.0/Bit,c=getchar();} return ans*flag; } } namespace Read{ #define si(a) scanf("%d",&a) #define sl(a) scanf("%lld",&a) #define sd(a) scanf("%lf",&a) #define ss(a) scanf("%s",a) #define rai(x,a,b) repi(i,a,b) x[i]=qi() #define ral(x,a,b) repi(i,a,b) x[i]=ql() } namespace Out{ #define pi(x) printf("%d",x) #define pl(x) printf("%lld",x) #define ps(x) printf("%s",x) #define pc(x) printf("%c",x) #define pe() puts("") } namespace DeBug{ #define MARK false #define DB if(MARK) #define pr(x) cout<<#x<<": "<<x<<endl #define pra(x,a,b) cout<<#x<<": "<<endl; \ repi(i,a,b) cout<<x[i]<<" "; \ puts(""); #define FR(a) freopen(a,"r",stdin) #define FO(a) freopen(a,"w",stdout) } using namespace Fast_Read; using namespace Read; using namespace Out; using namespace DeBug; typedef long double ld;//%Lf const db pi=acos(-1.0); const db eps=1e-8; inline int sgn(db x){ return fabs(x)<eps?0:(x<0?-1:1); } struct Point{ #define Vec Point db x,y; Point(){} Point(db _x,db _y){x=_x,y=_y;} void input(){sd(x),sd(y);} bool operator ==(Point b)const{return sgn(x-b.x)==0&&sgn(y-b.y)==0;} Point operator +(const Point &b)const{return Point(x+b.x,y+b.y);} Point operator -(const Point &b)const{return Point(x-b.x,y-b.y);} Point operator /(const db b)const{return Point(x/b,y/b);} Point operator *(const db b)const{return Point(x*b,y*b);} db operator ^(const Point &b)const{return x*b.y-y*b.x;}//叉乘 db operator *(const Point &b)const{return x*b.x+y*b.y;}//点乘 Point transXY(Point b,db B){//绕点b 逆时针 旋转角度B(弧度制)后的坐标 db tx=x-b.x,ty=y-b.y; return Point(tx*cos(B)-ty*sin(B)+b.x,tx*sin(B)+ty*cos(B)+b.y); } db dis(Point p){ return sqrt((x-p.x)*(x-p.x)+(y-p.y)*(y-p.y)); }//hypot(x-p.x,y-p.y) }; int main() { int n=qi(); int x0=qi(),y0=qi(),xn2=qi(),yn2=qi(); Point center=Point(1.0*(x0+xn2)/2,1.0*(y0+yn2)/2); db arc=2*pi/n; Point res=Point(1.0*x0,1.0*y0); res=res.transXY(center,arc); printf("%.10lf %.10lf\n",res.x,res.y); return 0; }
#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 int MX = 125001; ll MOD; #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 dp[111][125001]; int main(void){ int n,m,i,j,k; ll ans = 0ll; dp[0][0] = 1ll; scanf("%d%d%lld",&n,&m,&MOD); for(i=0; i<n; ++i){ for(j=0; j<MX; ++j){ if(!dp[i][j]){ continue; } for(k=0; k<=m; ++k){ if(j+(i+1)*k>=MX){ break; } add_mod(dp[i+1][j+(i+1)*k],dp[i][j]); } } } for(i=1; i<=n; ++i){ ans = 0ll; for(j=0; j<MX; ++j){ add_mod(ans,dp[n-i][j]*dp[i-1][j]%MOD); } mul_mod(ans,(m+1)); add_mod(ans,MOD-1); printf("%lld\n",ans); } return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back double dp[101][101][101]; double f(int a,int b,int c){ if(dp[a][b][c]) return dp[a][b][c]; if(a==100||b==100||c==100) return 0; double s=0; s+=(f(a+1,b,c)+1)*a/(a+b+c); s+=(f(a,b+1,c)+1)*b/(a+b+c); s+=(f(a,b,c+1)+1)*c/(a+b+c); dp[a][b][c]=s; return s; } int main(){ string s; int a,b,c,d; cin>>a>>b>>c; cout<<fixed<<setprecision (12); cout<<f(a,b,c);}
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<(int)(n);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;} using ll = long long; int a,b; int main () { cin.tie(0); ios::sync_with_stdio(false); cin >> a >> b; cout << (a+b)/2 << " " << (a-b)/2 << endl; }
/* * @Author: kabbo * @Date: 2020-06-24 08:40:07 * @Last Modified by: kabbo * @Last Modified time: 2020-06-24 08:49:58 */ #include<bits/stdc++.h> using namespace std; #define pii pair<long long,long long> #define endl '\n' #define ull unsigned long long #define ll int64_t #define ar array // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0200r0.html 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)); } const int mod = 1e9 + 7; using u64 = uint64_t; using u128 = __uint128_t; #define sc1(x) scanf("%lld",&(x)); mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); /*Well, probably you won't understand anything, because you didn't try to understand anything in your life, you expect all hard work to be done for you by someone else. Let's start*/ void solve() { ll a,b; cin>>a>>b; cout<<(b%a?"No":"Yes")<<endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); // int t; // cin>>t; // for (int i(1); i <= t; ++i) { // printf("Case %d:\n", i); solve(); //} return 0; }
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL_ void debug_out() {cerr << endl;} template<typename Head,typename... Tail> void debug_out(Head H,Tail... T){cerr << ' ' << H; debug_out(T...);} #define debug(...) cerr << 'L' << __LINE__ << " [" << #__VA_ARGS__ << "]:",debug_out(__VA_ARGS__) #define dump(x) cerr << 'L' << __LINE__ << " " << #x << " = " << (x) << endl; #else #define debug(...) (void(0)) #define dump(x) (void(0)) #endif #define rep(i,n) for (int i = 0; i < (int)(n); i ++) #define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i) using ll = long long; using PL = pair<ll,ll>; using P = pair<int,int>; constexpr int INF = 1000000000; constexpr long long HINF = 1000000000000000; constexpr long long MOD = 1000000007;// = 998244353; constexpr double EPS = 1e-4; constexpr double PI = 3.14159265358979; int N; ll A[60]; map<PL,ll> mp; ll dfs(int d,ll val,ll ret) { if (d == N - 1){ return ret; } PL key = PL{d,val}; if (mp.count(key)) return mp[key]; ll k; if (d > 0) k = val/(A[d]/A[d-1]); else k = val/A[d]; ll p = k%(A[d+1]/A[d]); if (p == 0) { ll ans = dfs(d+1,k,ret); return mp[key] = ans; } else { ll ans = 0; ans += dfs(d+1,k - p,ret); ans += dfs(d+1,k - p + A[d+1]/A[d],ret); return mp[key] = ans; } } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); ll X; cin >> N >> X; rep(i,N) cin >> A[i]; ll ans = dfs(0,X,1); cout << ans << '\n'; return 0; }
#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++) int main(){ int x, y; cin >> x >> y; int diff = abs(x-y); if (diff < 3) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> pll; #define F(type, i, a, b, incr) for (type i = a; i <= (type)(b); i += (type)(incr)) #define pb push_back #define ppb pop_back #define ff first #define ss second #define iter(it, s) for (auto it = s.begin(); it != s.end(); it++) #define fillc(a,b) memset(a,b,sizeof(a)) #define MOD 1000000007 #define INF 1e17 void solve() { ll x,y; cin>>x>>y; set<ll> s; s.insert(0); s.insert(1); s.insert(2); if(x==y) { cout<<x<<endl; } else { s.erase(x); s.erase(y); cout<<*s.begin()<<endl; } } int main() { //freopen("input.txt","r",stdin);freopen("output.txt","w",stdout); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); solve(); }
#include<iostream> #include<bits/stdc++.h> #include<string> #include<algorithm> #define ll long long #define pb push_back #define pob pop_back #define mp make_pair #define lb lower_bound #define ub upper_bound #define loop(i,n) for(i=0;i<n;i++) #define loop1(i,n) for(i=1;i<=n;i++) #define Loop(i,n,x) for(i=0;i<n;i+=x) #define Loop1(i,n,x) for(i=1;i<=n;i+=x) #define all(a) a.begin(),a.end() #define allr(a) a.rbegin(),a.rend() #define mem(name,val) memset(name,val,sizeof(name)) const long long MOD=(ll)1000000007; ll fact[100005]; using namespace std; int main() { ll n,k; cin>>n>>k; while(k--) { if(n%200) { n=n*1000+200; } else n/=200; } cout<<n<<endl; }
#include <bits/stdc++.h> typedef long double ld; #define int long long #define gcd __gcd #define endl "\n" #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define mod2 998244353 #define maxe *max_element #define mine *min_element #define inf 1e18 #define pb push_back #define all(x) x.begin(), x.end() #define f first #define s second #define lb lower_bound #define ub upper_bound #define ins insert #define sz(x) (int)(x).size() #define mk make_pair #define deci(x, y) fixed<<setprecision(y)<<x #define w(t) int t; cin>>t; while(t--) #define nitin ios_base::sync_with_stdio(false); cin.tie(nullptr) #define PI 3.141592653589793238 #define mem0(x) memset(x,0,sizeof x) #define mem1(x) memset(x,-1,sizeof x) using namespace std; template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.f << ", " << p.second << ')'; } template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; } void dbg_out() { cerr << endl; } template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); } #ifdef NITIN #define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__) #else #define dbg(...) #endif void solve() { int n,k; cin>>n>>k; map<int,int>f; for(int i=1;i<=n;i++){ f[i]=i-1; } for(int i=n+1;i<=2*n;i++){ f[i]=2*n-i+1; } int cnt=0; for(int i=1;i<=2*n;i++){ cnt+=f[k+i]*f[i]; } cout<<cnt<<endl; } int32_t main() { nitin; solve(); }
#include <bits/stdc++.h> using namespace std; long long pattern(long long x, long long N){ if(x > 1 && x < N+1){ return x - 1; } if(x > N && x < 2*N+1){ return 2*N - x + 1; } } int main() { long long N, K, ans; ans = 0; cin >> N >> K; for (long long Q=2; Q<2*N+1; Q++){ if(K + Q < 2){ continue; } if(K + Q > 2*N+1){ break; } else{ ans += pattern(K + Q, N) * pattern(Q, N); } } cout << ans; }
#include <bits/stdc++.h> using namespace std; using Graph = vector<vector<long long>>; const long long INF = 1LL <<59; const long long Mo=1000000007; vector<long long> seen; long long dfs(const Graph &G, int v, long long cnt) { seen[v] = cnt; //判定だけならcntをboolに // v から行ける各頂点 next_v について for (auto next_v : G[v]) { if (seen[next_v]>=0) continue; // next_v が探索済だったらスルー dfs(G, next_v, cnt); // 再帰的に探索 } //cout<<grp<<" "<<cnt<<endl; return 0; } long long gcn(long long x,long long y){ if(x%y==0){ return y; } else{ return gcn(y,x%y); } } long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } int main(void){ long long tmp,idx,cur,prev; long long flg; long long i,j,l; long long n,m,k; long double res,tmp1,tmp2; cin>>n>>m>>k; long long a[k]; long double dp[n+1][2]={}; long double mm=1.0/(long double)m; //cout<<mm; for(i=0;i<k;i++){ cin>>a[i]; } sort(a,a+k); tmp=1; for(i=1;i<k;i++){ if(a[i]-a[i-1]==1){ tmp++; if(tmp==m){ cout<<-1<<endl; return 0; } } else{ tmp=1; } } tmp1=0; tmp2=0; for(i=n-1;i>=0;i--){ flg=0; tmp1+=dp[i+1][0]; tmp2+=dp[i+1][1]; if(i+m+1<=n){ tmp1-=dp[i+m+1][0]; tmp2-=dp[i+m+1][1]; } for(j=0;j<k;j++){ if(i==a[j]){ flg=1; break; } } if(flg==1){ dp[i][1]=1; continue; } dp[i][0]=tmp1/m+1.0; dp[i][1]=tmp2/m; } //cout<<dp[0][0]<<" "<<dp[1][0]<<" "<<dp[2][0]<<endl; if(dp[0][1]==1){ res=-1; } else{ res=dp[0][0]/(1.0-dp[0][1]); } //cout<<res<<endl; cout<<setprecision(15)<<res<<endl; //cout<<res<<endl; return 0; } /* Graph G(n); seen.assign(n,-1); for(i=0; i<m; i++) { cin>>tmp1>>tmp2; tmp1--; tmp2--; G[tmp1].push_back(tmp2); G[tmp2].push_back(tmp1); } */
#include <bits/stdc++.h> #define LL long long #define ull unsigned long long #define F(i, j, k) for(int i = j; i <= k; i++) #define DF(i, j, k) for(int i = j; i >= k; i--) using namespace std; template <typename T> inline void read(T &n) { T w = 1; n = 0; char ch = getchar(); while (!isdigit(ch) && ch != EOF) { if (ch == '-') w = -1; ch = getchar(); } while (isdigit(ch) && ch != EOF) { n = (n << 3) + (n << 1) + (ch & 15); ch = getchar(); } n *= w; } template <typename T> inline void write(T x) { T l = 0; ull y = 0; if (!x) { putchar(48); return; } if (x<0) { putchar('-'); x = -x; } while (x) { y = y * 10 + x % 10; x /= 10; l++; } while (l) { putchar(y % 10 + 48); y /= 10; l--; } } template <typename T> inline void writes(T x) { write(x); putchar(' '); } template <typename T> inline void writeln(T x) { write(x); puts(""); } template <typename T> inline void checkmax(T &a,T b) { a = a > b ? a : b; } template <typename T> inline void checkmin(T &a,T b) { a = a < b ? a : b; } const int N = 2e5 + 10; int p[N], wei[N]; struct wzy { long double x, c; wzy (long double X = 0,long double C = 0) { x = X; c = C; } } f[N], g[N]; wzy operator +(const wzy x,const wzy y) { return wzy{x.x + y.x, x.c + y.c}; } wzy operator -(const wzy x,const wzy y) { return wzy{x.x - y.x, x.c - y.c}; } wzy operator *(const double x, const wzy y) { return wzy{x * y.x, x * y.c}; } int main() { //freopen(".in", "r", stdin); //freopen(".out", "w", stdout); int n, k, m; read(n); read(m); read(k); F(i, 1, k) { read(p[i]); wei[p[i]] = 1; } F(i, n, n + m - 1) f[i].x = 1; DF(i, n + m - 1, n) g[i] = g[i + 1] + f[i]; long double changshu1 = m; long double changshu2 = 1 / changshu1; DF(i, n - 1, 0) { f[i] = changshu2 * (g[i + 1] - g[i + m + 1]); f[i].c -= 1.0; if (wei[i]) f[i].x = f[i].c = 0; g[i] = g[i + 1] + f[i]; } if (f[0].x == 0) puts("-1"); else cout << fixed << setprecision(4) << -f[0].c / f[0].x << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0;i<n;i++) using ll = long long; const ll INF = 1e9; int n,q; vector<ll> a,t,x; void solve() { ll s = 0, l = -INF, r = INF; REP(i,n) { if (t[i] == 1) { // + s += a[i]; l += a[i]; r += a[i]; } else if (t[i] == 2) { // max l = max(l,a[i]); r = max(r,a[i]); } else { // min l = min(l,a[i]); r = min(r,a[i]); } } REP(i,q) { ll ans = x[i]+s; if (ans < l) ans = l; if (r < ans) ans = r; cout << ans << endl; } return; } int main() { cin >> n; a.resize(n); t.resize(n); REP(i,n) cin >> a[i] >> t[i]; cin >> q; x.resize(q); REP(i,q) cin >> x[i]; solve(); return 0; }
#include <bits/stdc++.h> #define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #define ll long long int #define pii pair<int,int> #define pll pair<long long int,long long int> #define pci pair<char,int #define mii map<int,int> #define mll map<long long int,long long int> #define mci map<char,int> #define umii unordered_map<int,int> #define umll unordered_map<long long int,long long int> #define umci unordered_map<char,int> #define F first #define S second #define pb push_back #define endl '\n' #define mod 998244353 using namespace std; bool isPrime(ll n) { // Corner cases if (n <= 1) return false; if (n <= 3) return true; // This is checked so that we can skip // middle five numbers in below loop if (n % 2 == 0 || n % 3 == 0) return false; for (ll i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } ll power(ll x,ll n) {ll x1=0; ll result=1; while(n>0) { if(n % 2 ==1) result=(result * x); // if(result>=1000000001) return 0; x=(x*x); // if(x>=1000000001) return 0; n=n/2; } return result; } ll countDivisors(ll n) { ll cnt = 0; for (ll i = 1; i <= sqrt(n); i++) { if (n % i == 0) { if (n / i == i) cnt++; else cnt = cnt + 2; } } return cnt; } int main(){ IOS; ll t;t=1; while(t--){ ll n;cin>>n; while(n%2==0){ n=n/2; } cout<<2*(countDivisors(n)); } return 0; }
#include<bits/stdc++.h> using namespace std; int main() { // your code goes here // int t; // cin>>t; // while(t--) // { // } unsigned long long int x,y,a,b,count=0; cin>>x>>y>>a>>b; while(1) { if(x*(a-1)>b) { break; } if(y<=x*a) break; x=x*a; count++; } if(x<y) count+=(y-x-1)/b; cout<<count<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int a,b,c,d; cin>>a>>b; cin>>c>>d; cout << b-c << endl; }
#include <iostream> #include <vector> #include <algorithm> #include <map> #include <numeric> #include <string> #include <cstdio> #include <cstring> #include <queue> #include <stack> #include <set> #include <cmath> #include <bitset> #include <iomanip> #include <unordered_set> #include <unordered_map> using namespace std; using ll = long long; using ull = unsigned long long; #define all(x) (x).begin(),(x).end() #define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i)) #define pb push_back #define mp make_pair #define fi first #define se second #define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) #define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl constexpr int INF = 1e9+7; constexpr ll INFL = 9*1e18; constexpr int dx[4] = { 1, 0, -1, 0 }; constexpr int dy[4] = { 0, 1, 0, -1 }; // constexpr int dx[8] = {1, 1, 0,-1,-1,-1, 0, 1}; // constexpr int dy[8] = {0, 1, 1, 1, 0,-1,-1,-1}; int inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数 ull inline power(ull a,ull b){ull res = 1;rep(i,b)res *= a;return res;} template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和 template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数 template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数 template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template<typename T>inline void print(T&& x){cout<<setprecision(32)<<x<<endl;} string to_oct(int n){string s;while(n){s = to_string(n%8) + s;n /= 8;}return s;} int main(){ int n;cin>>n; string s;cin>>s; int q;cin>>q; bool reversed = false; rep(i,q){ int t;cin>>t; int a,b;cin>>a>>b;a--;b--; if(reversed){ a = (a + n) % (2*n); b = (b + n) % (2*n); } if(t == 1){ swap(s[a],s[b]); }else{ reversed = !reversed; } } if(reversed){ string t1 = s.substr(0,n); string t2 = s.substr(n,2*n); s = t2 + t1; } print(s); return 0; }
#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); } std::string s; int main(void){ int n,i,m,t,a,b,q; bool flag = false; std::cin >> n; std::cin >> s; std::cin >> q; m = s.l_ength(); for(i=0; i<q; ++i){ std::cin >> t >> a >> b; --t; --a; --b; if(t){ flag = (!flag); }else{ a += (flag?n:0); a %= m; b += (flag?n:0); b %= m; std::swap(s[a],s[b]); } } for(i=0; i<m; ++i){ std::cout << s[(flag?((i+n)%m):i)]; } std::cout << std::endl; return 0; }
#include<bits/stdc++.h> using namespace std; long long mod = 1e9 + 7; long long k , n , m , a [100005]; vector < long long > v; bool ck ( long double x ) { v . clear (); long double mm = m , nn = n; long long mnsum = 0 , mxsum = 0; for ( int i = 0 ; i < k ; i ++ ) { long long mn = ceil ( ( mm * a [i] - x ) / nn ) , mx = ( mm * a [i] + x ) / nn; mnsum += mn , mxsum += mx; } for ( int i = 0 ; i < k ; i ++ ) { if ( mnsum <= mm && mm <= mxsum ) { long long mn = ceil ( ( m * a [i] - x ) / nn ) , mx = ( m * a [i] + x ) / nn; mnsum -= mn , mxsum -= mx; long long vmn = mm - mxsum , vmx = mm - mnsum; if ( mx < vmn || vmx < mn ) return 0; if ( mn <= vmn && vmn <= mx ) { v . push_back ( vmn ); mm -= vmn; continue; } if ( mn <= vmx && vmx <= mx ) { v . push_back ( vmx ); mm -= vmx; continue; } if ( vmn <= mn && mn <= vmx ) { v . push_back ( mn ); mm -= mn; continue; } if ( vmn <= mx && mx <= vmx ) { v . push_back ( mx ); mm -= mx; continue; } } else return 0; } return 1; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); //freopen(".in","r",stdin); //freopen(".out","w",stdout); cin >> k >> n >> m; for ( int i = 0 ; i < k ; i ++ ) cin >> a [i]; long long l = 0 , r = 1e13 , mid; while ( l < r ) { mid = ( l + r ) / 2; if ( ck ( mid ) ) r = mid; else l = mid + 1; } ck ( l ); for ( int i = 0 ; i < v . size () ; i ++ ) cout << v [i] << ' '; }
#include "bits/stdc++.h" using namespace std; using ll = long long; using vll = vector<ll>; using vvll = vector<vector<ll>>; using vvvll = vector<vector<vector<ll>>>; using vvvvll = vector<vector<vector<vector<ll>>>>; using pl4 = pair<ll,ll>; using str = string; using vpl4 = vector<pair<ll,ll>>; #define sz size() #define be begin() #define en end() #define fi first #define se second #define pb push_back #define mp make_pair #define llin(x) ll (x);cin >>(x); #define stin(x) str (x);cin >>(x); #define vllin(x,n) vll (x)(n);FOR(i,0,n-1){cin >>(x)[i];} #define vllin2(a,b,n) vll (a)(n);vll (b)(n);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i];} #define vllin3(a,b,c,n) vll (a)(n);vll (b)(n);vll (c)(n);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i]>>(c)[i];} #define vlling(x,n) (x).assign(n,0);FOR(i,0,n-1){cin >>(x)[i];} #define vlling2(a,b,n) (a).assign(n,0);(b).assign(n,0);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i];} #define vlling3(a,b,c,n) (a).assign(n,0);(b).assign(n,0);(c).assign(n,0);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i]>>(c)[i];} #define vpl4in(x,n) vpl4 (x)((n),mp(0,0));FOR(i,0,n-1){cin >>x[i].fi>>x[i].se;} #define FOR(i,a,b) for(ll i = a ; i <= b ; i++) #define rFOR(i,b,a) for(ll i = a; i >= b ; i--) #define SORT(x) sort(x.be, x.en) #define rSORT(x) sort(x.rbegin(), x.rend()) #define say(x) cout<<(x); #define sal(x) cout<<(x)<<endl; #define says(x) cout<<(x)<<(' '); #define sas cout<<(' '); #define sayR(x) cout<<fixed<<setprecision(10)<<(x); #define salR(x) cout<<fixed<<setprecision(10)<<(x)<<endl; #define yn(a) cout <<((a)?"yes":"no")<<endl; #define Yn(a) cout <<((a)?"Yes":"No")<<endl; #define YN(a) cout <<((a)?"YES":"NO")<<endl; #define Imp(a) cout <<((a)?"Possible":"Impossible")<<endl; #define IMP(a) cout <<((a)?"POSSIBLE":"IMPOSSIBLE")<<endl; #define pow(a,b) ll(pow(a,b)) ll MOD=1000000007; ll INF=100000000000001; vector<ll> value; // ノードの値を持つ配列 ll N; // 葉の数 void update(ll i, ll x) { // i 番目の葉の値を x に変える i += N - 1; // i 番目の葉のノード番号 value[i] = x; while (i > 0) { i = (i - 1) / 2; // ノード i の親ノードの番号に変える value[i] = min(value[i * 2 + 1], value[i * 2 + 2]); // 左右の子の min を計算しなおす } } ll query(ll a, ll b, ll k, ll l, ll r) { // [a, b) の区間に対するクエリについて // ノード k (区間 [l, r) 担当)が答える if (r <= a || b <= l) return INF; // 区間が被らない場合は INF を返す if (a <= l && r <= b) return value[k]; // ノード k の担当範囲がクエリ区間 [a, b) // に完全に含まれる else { ll c1 = query(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子に値を聞く ll c2 = query(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子に値を聞く return min(c1, c2); // 左右の子の値の min を取る } } ll n; vvll d(200001,vll(2,0)); vvll e(200001,vll(2,0)); vvll a(200001,vll(2,0)); vvll c(200001,vll(0)); long long mi(long long a) { ll m=MOD; long long b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } signed main(){ llin(r1); llin(c1); llin(r2); llin(c2); ll x=abs(r1-r2); ll y=abs(c1-c2); if(x==0&&y==0){ sal(0); return 0; } if(x-y==0||x+y<=3){ sal(1); return 0; } if((x-y)%2==0||abs(x-y)<=3){ sal(2); return 0; } sal(3); }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define all(x) (x).begin(),(x).end() template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;} template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;} int dx[4]={0,1,0,-1}, dy[4]={1,0,-1,0}; long double eps = 1e-9; long double pi = acos(-1); signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); ll k,n,m; cin>>k>>n>>m; ll a[k]; for(int i=0;i<k;i++)cin>>a[i]; array<ll,2> ans[k]={}; ll sum = 0; array<ll,2> dif[k]={}; for(int i=0;i<k;i++){ ans[i][0] = m*a[i]/n; ans[i][1]=i; sum += ans[i][0]; dif[i][1]=i; dif[i][0] = abs(n*(ans[i][0]+1LL)-m*a[i]) - abs(n*ans[i][0]-m*a[i]); } ll rem = m - sum; sort(dif,dif+k); ll ret[k]={}; for(int i=0;i<rem;i++){ ret[dif[i][1]]++; } for(int i=0;i<k;i++)ret[ans[i][1]]+=ans[i][0]; for(int i=0;i<k;i++){ cout << ret[i] << " "; } cout << endl; }
#include <cstdio> #include <algorithm> #include <cstring> #include <cmath> #include <iostream> #define ll long long using namespace std; int k;ll n,m,a[100010],ans[100010],l[100010],r[100010],le,ri; bool check(ll x) { le=0,ri=0; for(int i=1;i<=k;i++) { r[i]=(x+a[i])/n; if(a[i]<=x) l[i]=0; else l[i]=((a[i]-x)%n==0)?(a[i]-x)/n:(a[i]-x)/n+1; le+=l[i],ri+=r[i]; if(r[i]<l[i]) return false; } if(le>m||ri<m) return false; for(int i=1;i<=k;i++) { if(r[i]-l[i]+le<=m) ans[i]=r[i],le+=r[i]-l[i]; else ans[i]=l[i]+m-le,le=m; } return true; } int main() { scanf("%d %lld %lld",&k,&n,&m); for(int i=1;i<=k;i++) scanf("%lld",&a[i]); for(int i=1;i<=k;i++) a[i]*=m; ll l=0,r=1e18; while(l<=r) { ll mid=l+r>>1; if(check(mid)) r=mid-1; else l=mid+1; } for(int i=1;i<=k;i++) printf("%lld ",ans[i]); }
//Never stop trying #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #include <bits/stdc++.h> using namespace std; #define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0) typedef string str; typedef long long ll; #define int ll typedef double db; typedef long double ld; typedef pair<int, int> pi; #define fi first #define se second typedef vector<int> vi; typedef vector<pi> vpi; typedef vector<str> vs; typedef vector<ld> vd; #define pb push_back #define sz(x) (int)x.size() #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) #define endl "\n" #define FOR(i,a,b) for (int i = (a); i < (b); ++i) #define F0R(i,a) FOR(i,0,a) #define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i) #define R0F(i,a) ROF(i,0,a) const int MOD = 1e9 + 7; //998244353 const ll INF = 1e18; const int MX = 2e5 + 10; const int nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0}; //right left down up template<class T> using V = vector<T>; template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); } // divide a by b rounded up constexpr int log2(int x) { return 31 - __builtin_clz(x); } // floor(log2(x)) #define dbg(x) cerr << " - " << #x << " : " << x << endl; #define dbgs(x,y) cerr << " - " << #x << " : " << x << " / " << #y << " : " << y << endl; #define dbgv(v) cerr << " - " << #v << " : " << endl << "[ "; for(auto it : v) cerr << it << ' '; cerr << ']' << endl; void IO() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int power[4000009]; int32_t main() { boost; IO(); power[0]=1; FOR(i,1,4000009) power[i]=(power[i-1]*2)%MOD; int N,M; cin>>N>>M; char g[N][M]; int a[N][M],b[N][M],c[N][M],d[N][M]; int K=0; FOR(i,0,N) FOR(j,0,M){ cin>>g[i][j]; if(g[i][j]=='.') K++; } //L FOR(i,0,N) FOR(j,0,M){ if(g[i][j]=='#'){ a[i][j]=0; continue; } a[i][j]=1; if(j) a[i][j]+=a[i][j-1]; } //R FOR(i,0,N) ROF(j,0,M){ if(g[i][j]=='#'){ b[i][j]=0; continue; } b[i][j]=1; if(j+1<M) b[i][j]+=b[i][j+1]; } //U FOR(j,0,M) FOR(i,0,N){ if(g[i][j]=='#'){ c[i][j]=0; continue; } c[i][j]=1; if(i) c[i][j]+=c[i-1][j]; } FOR(j,0,M) ROF(i,0,N){ if(g[i][j]=='#'){ d[i][j]=0; continue; } d[i][j]=1; if(i+1<N) d[i][j]+=d[i+1][j]; } /*FOR(i,0,N){ FOR(j,0,M) cout << d[i][j] << ' '; cout << endl; }*/ int ans=0; FOR(i,0,N) FOR(j,0,M)if(g[i][j]=='.'){ int y=a[i][j]+b[i][j]+c[i][j]+d[i][j]-3; //cout << y << endl; int x=power[y]-1; x%=MOD; //cout << x << endl; x*=power[K-(y)]; x%=MOD; ans+=x; ans%=MOD; } cout << ans << endl; return 0; } /* Careful!!! .Array bounds .Infinite loops .Uninitialized variables / empty containers .Order of input Some insights: .Binary search .Graph representation .Write brute force code .Change your approach */
#include <bits/stdc++.h> using namespace std; using ll = long long; const int mod = 1000000007; struct mint { ll x; // typedef long long ll; mint(ll x=0):x((x%mod+mod)%mod){} mint operator-() const { return mint(-x);} mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;} mint operator+(const mint a) const { return mint(*this) += a;} mint operator-(const mint a) const { return mint(*this) -= a;} mint operator*(const mint a) const { return mint(*this) *= a;} mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod-2);} mint& operator/=(const mint a) { return *this *= a.inv();} mint operator/(const mint a) const { return mint(*this) /= a;} }; istream& operator>>(istream& is, const mint& a) { return is >> a.x;} ostream& operator<<(ostream& os, const mint& a) { return os << a.x;} char c[2005][2005]; int a[2005][2005]; int b[2005][2005]; int d[2005][2005]; int main(){ int h, w; cin >> h >> w; for(int i = 0; i < h; i++){ for(int j = 0; j < w; j++){ cin >> c[i][j]; } } for(int i = 0; i < h; i++){ int now = 0; for(int j = 0; j < w; j++){ if(c[i][j]=='.'){ now++; a[i][j] = now; } if(c[i][j]=='#'){ now = 0; a[i][j] = 0; } } } for(int i = 0; i < h; i++){ int now = 0; for(int j = w-1; j>=0; j--){ if(a[i][j]==0)now = 0; if(a[i][j]>0){ now = max(now,a[i][j]); a[i][j] = now; } } } for(int i = 0; i < w; i++){ int now = 0; for(int j = 0; j < h; j++){ if(c[j][i]=='.'){ now++; b[j][i] = now; } if(c[j][i]=='#'){ now = 0; b[j][i] = 0; } } } for(int i = 0; i < w; i++){ int now = 0; for(int j = h-1; j>=0; j--){ if(b[j][i]==0)now = 0; if(b[j][i]>0){ now = max(now,b[j][i]); b[j][i] = now; } } } for(int i = 0; i < h; i++){ for(int j = 0; j < w; j++){ if(c[i][j]=='.')d[i][j] = a[i][j] + b[i][j] -1; } } ll sum = 0; for(int i = 0; i < h; i++){ for(int j = 0; j < w; j++){ if(c[i][j]=='.')sum ++; } } mint ans = 0; for(int i = 0; i < h; i++){ for(int j = 0; j < w; j++){ if(c[i][j]=='.') { mint now = 1; now *= mint(2).pow(d[i][j])-1; now *= mint(2).pow(sum-d[i][j]); ans += now; } } } cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define INF 1000000007 #define MOD 998244353 #define LINF (1LL << 62) #define PI 3.14159265358979 typedef long long i64; typedef pair<i64,i64> P; inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; } 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; } mt19937_64 rnd(time(NULL)); struct UnionFind { vector<int> par, depth, sz; UnionFind(int n) : par(n+1), depth(n+1), sz(n+1){ for(int i = 0; i <= n; i++){ par[i] = i; depth[i] = 0; sz[i] = 1; } } 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; sz[x] += sz[y]; sz[y] = sz[x]; if(depth[x] < depth[y]){ par[x] = y; } else{ par[y] = x; if(depth[x] == depth[y]) depth[x]++; } } bool same(int x, int y){ return find(x) == find(y); } int size(int x){ return sz[find(x)]; } }; i64 n, x[101], y[101]; void solve(){ cin >> n; for(int i = 0; i < n; i++){ cin >> x[i] >> y[i]; x[i] += 100; y[i] += 100; } double l = 0, r = 200; for(int i = 0; i < 100; i++){ double c = (l+r)/2; UnionFind uf(n+2); for(int j = 0; j < n; j++){ if(y[j] < c) uf.unite(j,n); if(200-y[j] < c) uf.unite(j,n+1); for(int k = 0; k < n; k++){ if(pow(pow(x[j]-x[k],2)+pow(y[j]-y[k],2),0.5) < c){ uf.unite(j,k); } } } bool ok = 1; for(int i = 0; i < n; i++){ if(uf.same(i,n) && uf.same(i,n+1)) ok = 0; } if(uf.size(0) == n+2 || !ok) r = c; else l = c; } printf("%.10f\n", r/2); } int main(){ std::cin.tie(0); std::ios::sync_with_stdio(false); int t = 1; //cin >> t; while(t--){ solve(); } return 0; }
//#include <atcoder/all> #include <bits/stdc++.h> #include <cassert> #include <numeric> using namespace std; //using namespace atcoder; typedef long long LONG; const int MOD = 1000000007; int gcd(int x, int y) { if (x % y == 0) { return y; } else { return gcd(y, x % y); //x%y==0でないときはユーグリットの互除法を使って再帰的に関数を呼び出す。 } } LONG pow2(long long x, long long n) { long long ret = 1; while (n > 0) { if (n & 1) ret = ret * x % MOD; // n の最下位bitが 1 ならば x^(2^i) をかける x = x * x % MOD; n >>= 1; // n を1bit 左にずらす } return (int)ret; } void printVector(const vector<int>& vec) { for (int value : vec) { cout << value << " "; } cout << endl; } LONG t(LONG N,LONG i) { return N - abs(i); } int count(vector<int>&a, int s) { int result = 0; for (int i = 0; i < a.size(); i++) { if (a[i] == s) { result++; } } return result; } LONG kaizyo(int N) { LONG result = 1; LONG mod = 998244353; for (LONG i = 2; i <= N; i++) { result *= i; result = result % mod; } return result; } class Point { public: int x; int y; }; LONG stock[3500][3500]; LONG test(int N, int task) { LONG mod = 998244353; if (N < task)return 0; if (N < 0)return 0; if (task == 0) { if (N == 0) { return 1; } else { return 0; } } if (stock[N][task] > 0)return stock[N][task]; stock[N][task] =( test(N - 1, task - 1) + test(N, task * 2)) % mod; return stock[N][task]%mod ; } class DP { public: DP() { } DP(int a, int b) { other = a; path = b; } int other; int path; }; void dp(vector<vector<DP>>& list, vector<int> &able, int pos,int limit) { for (int i = 0; i < list[pos].size(); i++) { if (list[pos][i].path <= limit) { if (able[list[pos][i].other] == 0) { able[list[pos][i].other] = 1; dp(list, able, list[pos][i].other, limit); } } } } int main() { LONG N; cin >> N; vector<Point>P(N); for (int i = 0; i < N; i++) { cin >>P[i].x>>P[i].y; } vector<vector<DP>>d(N+2, vector<DP>(0)); for (int i = 0; i < N; i++) { for (int j = 0; j < i; j++) { int r = (P[i].x - P[j].x)*(P[i].x - P[j].x) + (P[i].y - P[j].y)*(P[i].y - P[j].y); if (r < 40000) { d[i+2].push_back(DP(j+2, r)); d[j+2].push_back(DP(i+2, r)); } } } for (int i = 0; i < N; i++) { d[i+2].push_back(DP(0, (100-P[i].y)* (100 - P[i].y))); d[0].push_back(DP(i+2, (100 - P[i].y)*(100-P[i].y))); } for (int i = 0; i < N; i++) { d[i + 2].push_back(DP(1, (-100 - P[i].y)* (-100 - P[i].y))); d[1].push_back(DP(i + 2, (-100 - P[i].y)* (-100 - P[i].y))); } d[0].push_back(DP(1, 40000)); d[1].push_back(DP(0, 40000)); int max = 40000; int min = 0; int mid = (max) / 2; while (max - min > 1) { bool frag = false; vector<int> able(N + 2, 0 );//未到達は0、到達は1 able[0] = 1; dp(d, able, 0, mid); if (able[1] == 1) { max = mid; mid = (max + min) / 2; }else{ min = mid; mid = (max + min) / 2; } // cout << max<<"\t" << min << "\t" << mid << "\n"; } cout << std::fixed << std::setprecision(15) << sqrt(mid+1)/2.0; return 0; }
#include <bits/stdc++.h> #define int long long #define debug(x) cerr << #x << ": " << x << '\n' using namespace std; const long long INF = 1e18; const long long MOD = 998244353; void solve() { int n, x; cin >> n >> x; string s; cin >> s; int now = x; for (int i = 0; i < n; i++) { if (s[i] == 'o') now += 1; else now = max((int)0, now - 1); } cout << now << endl; } signed main() { solve(); return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i=0;i<(n);i++) using namespace std; using ll = long long; int main(){ int a,b; cin >> a >> b; int ans=2*a+100-b; cout<<ans<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; int main() { long long int n; cin>>n; long long int arr[n],ans=0,temp=0; for(int i=0;i<n;i++) cin>>arr[i]; sort(arr,arr+n); for(int i=0;i<n;i++) { ans+=arr[i]*i-temp; temp+=arr[i]; } cout<<ans<<endl; }
#include <iostream> #include <vector> using namespace std; int main() { int N; cin >> N; vector<int> p(N); for(int i=0; i<N; i++) cin >> p[i]; vector<bool> ans(210000, true); int cur = 0; for (int i = 0; i < N; i++) { ans[p[i]] = false; for (; cur <= 210000; cur++) { if (ans[cur]) { cout << cur << endl; break; } } } return 0; }
#include<bits/stdc++.h> using namespace std; int n,m; long long sam; int main() { cin>>n>>m; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) { sam+=i*100+j; } cout<<sam; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int32_t main() { //freopen("input.txt", "r", stdin); IOS; int a; cin >> a; int b; cin >> b; for(int i = -100 ; i <= 100 ; i++) { for(int j = -100 ; j <= 100 ; j++) { if(i+j == a && i-j == b) { cout << i << ' ' << j << '\n'; return 0; } } } return 0; }
#include<iostream> #include<cstdio> #include<algorithm> #include<queue> using namespace std; const int R=2e5 + 5; const int N=1e5 + 3; const int M = 2e3 + 3; const int INF=0x3f3f3f3f; struct edge{ int v,w,next; }e[R*2]; int dis[N],head[2*N],cnt=0; int a[M][M]; struct node{ int u,d; bool operator <(const node&rhs) const{ return d>rhs.d; } }; inline void addedge(int u,int v,int w){ e[++cnt].v=v; e[cnt].w=w; e[cnt].next=head[u]; head[u]=cnt; } int n,m,s; inline void Dij(){ for(int i=1;i<=n;i++) dis[i]=INF; dis[s]=0; priority_queue<node> Q; Q.push((node){s,0}); while(!Q.empty()){ node fr=Q.top();Q.pop(); int u=fr.u,d=fr.d; if(d!=dis[u]) continue; for(int i=head[u];i;i=e[i].next){ int v=e[i].v,w=e[i].w; if(dis[u]+w<dis[v]){ dis[v]=dis[u]+w; Q.push((node){v,dis[v]}); } } } } int main(){ cin>>n>>m; for(int i=1;i<=m;i++){ int x,y,z; cin>>x>>y>>z; if(!a[x][y]) a[x][y] = z; a[x][y] = min(a[x][y], z); addedge(x,y,z); } for(int i = 1; i <= n; ++i) { s = i; Dij(); int ans = -1; for(int j = 1; j <= n; ++j) if(dis[j] != INF && a[j][i]) { if(ans == -1) ans = dis[j] + a[j][i]; ans = min(ans, dis[j] + a[j][i]); } cout << ans << endl; } return 0; }
#include <iostream> #include <vector> #include <array> #include <list> #include <queue> #include <stack> #include <set> #include <map> #include <unordered_map> #include <unordered_set> #include <utility> #include <string> #include <sstream> #include <algorithm> #include <random> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <cmath> #include <cassert> #include <climits> #include <bitset> #include <functional> #include <iomanip> #include <random> #define FOR_LT(i, beg, end) for (decltype(end) i = beg; i < end; i++) #define FOR_LE(i, beg, end) for (decltype(end) i = beg; i <= end; i++) #define FOR_DW(i, beg, end) for (decltype(beg) i = beg; end <= i; i--) #define REP(n) for (decltype(n) repeat_index = 0; repeat_index < n; repeat_index++) using namespace std; template<typename T, size_t S> T minval(const T(&vals)[S]) { T val = numeric_limits<T>::max(); FOR_LT(i, 0, S) { val = min(val, vals[i]); } return val; } template<typename T, size_t S> T maxval(const T(&vals)[S]) { T val = numeric_limits<T>::min(); FOR_LT(i, 0, S) { val = max(val, vals[i]); } return val; } struct E { int i; int c; }; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout << fixed << setprecision(20); int n, m; cin >> n >> m; vector<vector<E>> es(n + 1); REP(m) { int a, b, c; cin >> a >> b >> c; es[a].push_back({ b, c }); } vector<int64_t> cs(n + 1); FOR_LE(i, 1, n) { FOR_LE(j, 1, n) { cs[j] = INT64_MAX; } using S = std::pair<int, int>; auto cmp = [](const S& lhs, const S& rhs) { return lhs.second > rhs.second; }; priority_queue<S, vector<S>, decltype(cmp)> s(cmp); s.push({i, 0}); cs[i] = 0; bool has_goal = false; while (!s.empty()) { S c = s.top(); s.pop(); if (c.first == i && c.second != 0) { cout << c.second << endl; has_goal = true; break; } if (cs[c.first] < c.second) continue; cs[c.first] = c.second; for (auto& e : es[c.first]) { //cout << e.i << " " << c.second + e.c << endl; s.push({ e.i, c.second + e.c }); } } if (!has_goal) { cout << -1 << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(),(x).end() typedef long long ll; typedef pair<ll, ll> P; const int mod = 1000000007; //出力は (ans % mod + mod) % mod (負の剰余を正にする) const int inf = 1e9; const long long INF = 1LL << 60; int main() { int n; cin >> n; int a[n]; int lim = 0; rep(i,n){ cin >> a[i]; lim = max(lim,a[i]); } int cnt = 0; int ans = 0; for(int i = 2; i <= lim; i++){ int tmp_cnt = 0; for(int j = 0; j < n; j++){ if(a[j] % i == 0) tmp_cnt++; } if(cnt < tmp_cnt){ cnt = tmp_cnt; ans = i; } } cout << ans << endl; }
//#pragma GCC optimize ("O2") //#pragma GCC optimize ("Ofast") // IN THE NAME OF GOD #include <bits/stdc++.h> using namespace std; typedef pair <int, int> pii; template <typename Head> inline void dout(Head in) { cerr << in << '\n'; } int main() { ios::sync_with_stdio(false), cin.tie(NULL); int t; cin >> t; while (t--) { long long n; cin >> n; if (n % 2 == 0) { if (n % 4 == 0) { cout << "Even\n"; } else { cout << "Same\n"; } } else { cout << "Odd\n"; } } return 0; }
#include <iostream> #include <vector> #include <string> #include <array> #include <functional> #include <algorithm> #include <stack> #include <map> #include <set> #include <climits> #include <queue> #include <bitset> #include <cassert> #include <math.h> #include <complex> #include <iomanip> #include <unordered_map> using namespace std; #define ll long long #define pb(x) push_back(x) #ifdef _OLIMPOLOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 1337 #endif void debug_out() { cout << "\n";} template<typename T1, typename... T2> void debug_out(T1 A, T2... B) { cout << " " << A; debug_out(B...); } int test = 1; #define out(x) {cout << x << "\n";return;} #define all(N) N.begin(),N.end() #define allr(N) N.rbegin(),N.rend() template<typename T1> void print(vector<T1> V, int add = 0, int start = -1, int end = -1) { if (start < 0) start = 0; if (end < 0) end = V.size() - 1; for (int i = start; i <= end; i++) { cout << V[i] + add << ((i == end) ? "\n" : " "); } } template<typename T1> T1 chmin(T1 &x, const T1 v) { return x = min(x,v); } template<typename T1> T1 chmax(T1 &x, const T1 v) { return x = max(x,v); } #define rep(i, n) for (int i = 0; i < n; i++) #define reps(i, s, n) for (int i = s; i < n; i++) #define repr(i, n) for (int i = n; i >= 0; i--) #define repsr(i, s, n) for (int i = n-1; i >= s; i--) //-------------------------- ^ DONT TOUCH ^----------------------------------------------------------------- #define MAX 1001 #define MOD 1000000007ll ll n, m, q, x, y; void solve() { cin >> n >> x; vector<int> N; rep(i,n) { cin >> y; if (x != y) N.push_back(y); } print(N); } int main() { ios_base::sync_with_stdio(0);cin.tie(0); int test = 1; #ifdef _OLIMPOLOCAL cin >> test; #endif rep(testCase, test) { #ifdef _OLIMPOLOCAL cout << "------------------ TESTCASE: " << testCase << " -------------\n"; #endif solve(); } return 0; }
#include<bits/stdc++.h> using namespace std; using ll = long long; using P = pair<ll,ll> ; #define rep(i,n) for(ll i=0;i<(n);i++) ll min(ll a,ll b){return a>=b ? b:a;} ll max(ll a,ll b){return a>=b ? a:b;} int main(){ ll n; cin >> n; vector<P> X(n); vector<P> Y(n); rep(i,n){ ll x,y; cin >> x >> y; X[i].first=x; X[i].second=i; Y[i].first=y; Y[i].second=i; } sort(X.begin(),X.end()); sort(Y.begin(),Y.end()); vector<ll> M(3,0); vector<ll> S(3); for (ll i=1;i>=0;i--){ for (ll j=n-2;j<n;++j){ if (M[0]<=abs(X[i].first-X[j].first)){ copy(M.begin(),M.end(),S.begin()); M[0]=abs(X[i].first-X[j].first); M[1]=X[i].second; M[2]=X[j].second; }else if (S[0]<=abs(X[i].first-X[j].first)){ S[0]=abs(X[i].first-X[j].first); S[1]=X[i].second; S[2]=X[j].second; } if (M[0]<=abs(Y[i].first-Y[j].first)){ if (M[1]==Y[i].second && M[2]==Y[j].second) continue; copy(M.begin(),M.end(),S.begin()); M[0]=abs(Y[i].first-Y[j].first); M[1]=Y[i].second; M[2]=Y[j].second; }else if (S[0]<abs(Y[i].first-Y[j].first)){ S[0]=abs(Y[i].first-Y[j].first); S[1]=Y[i].second; S[2]=Y[j].second; } } } cout << S[0] << endl; }
#include <iostream> #include <bits/stdc++.h> using namespace std; set<int> stepped; int t[50][50]; int p[50][50]; int s=0; int i,j; char randstep() { vector<char> ds; if (i>0 && !stepped.count(t[i-1][j])) ds.push_back('U'); if (i<49 && !stepped.count(t[i+1][j])) ds.push_back('D'); if (j>0 && !stepped.count(t[i][j-1])) ds.push_back('L'); if (j<49 && !stepped.count(t[i][j+1])) ds.push_back('R'); if (ds.empty()) return '#'; char w=ds[rand()%ds.size()]; if (w=='U') i--; if (w=='D') i++; if (w=='L') j--; if (w=='R') j++; s+=p[i][j]; stepped.insert(t[i][j]); return w; } int main() { ios_base::sync_with_stdio(false), cin.tie(nullptr); int si,sj;cin>>si>>sj; for (int x=0;x<50;x++){ for (int y=0;y<50;y++){ cin >> t[x][y]; } } for (int x=0;x<50;x++){ for (int y=0;y<50;y++){ cin >> p[x][y]; } } int ntries=20; srand(42); vector<char> bestrun; vector<char> attempts[ntries]; int satts[ntries]; int best=0; set<int> cache={t[si][sj]}; while (randstep()!='#'){ for (int k=0;k<ntries;k++){ s=0; i=si; j=sj; attempts[k].clear(); stepped=cache; char c=randstep(); while (c!='#'){ attempts[k].push_back(c); c=randstep(); } satts[k]=s; } long tot[4]; for (int k=0;k<4;k++) tot[k]=0; for (int k=0;k<ntries;k++){ if (attempts[k][0]=='U') tot[0]+=satts[k]; if (attempts[k][0]=='D') tot[1]+=satts[k]; if (attempts[k][0]=='L') tot[2]+=satts[k]; if (attempts[k][0]=='R') tot[3]+=satts[k]; } int bd=0; for (int k=1;k<4;k++){ if (tot[k]>tot[bd]) bd=k; } if (bd==0){ si--; cache.insert(t[si][sj]); bestrun.push_back('U'); } if (bd==1){ si++; cache.insert(t[si][sj]); bestrun.push_back('D'); } if (bd==2){ sj--; cache.insert(t[si][sj]); bestrun.push_back('L'); } if (bd==3){ sj++; cache.insert(t[si][sj]); bestrun.push_back('R'); } i=si; j=sj; stepped=cache; } for (int k=0;k<bestrun.size();k++){ cout << bestrun[k]; } cout << endl; //cout << s << endl; return 0; }
#include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //#define SOME_TESTCASE //#define MOD 998244353LL #if 1 //テンプレ折り畳み//テンプレ折り畳み//テンプレ折り畳み #ifdef _DEBUG #define debug() if(true) #define dout cout #define dvout(v) __vout(v) #define dvvout(v) __vvout(v) #else #define debug() if (false) #define dout if(false)cout #define dvout(v) if(false)__vout(v) #define dvvout(v) if(false)__vvout(v) #endif typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> P; #define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)//rep #define repll(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; ++i)//rep #define repi(i, n1, n) for(int i=n1, i##_len=(n); i<i##_len; ++i)//rep #define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)//自然数rep #define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i) #define rreps(i, n) for(int i=((int)(n)); i>0; --i) #define dxout(x) dout<<#x<<":"<<x<<_s//変数デバッグ出力 #define dxoutln(x) dout<<#x<<":"<<x<<_n #define _Yes {cout<<"Yes"<<endl; return;}//出力 #define _No {cout<<"No"<<endl;return;} #define _ans {cout<<ans<<endl;return;} #define _endout(s) {cout<<(s)<<endl;return;} #define vecvec(v, n, m) vector<vector<int>> v(n, vector<int>(m)); typedef vector<int> vi; typedef vector<char> vc; typedef vector<ll> vll; typedef vector<vi> vvi; typedef vector<vll> vvll; typedef vector<vc> vvc; #define vin(v) for (auto &i : (v)) cin >> i; //配列入力 #define vvin(v) for(auto&i:(v))for(auto&j:i)cin>>j; #define __vout(v) {for(auto&i:(v)){cout<<i<<' ';}cout<<"\n";} #define __vvout(v) {for(auto&i:(v)){for(auto&j:i){cout<<j<<'\t';}cout<<"\n";}cout<<"\n";} #define INF (INT_MAX/3) #define INFLL (LLONG_MAX/3) #ifndef MOD #define MOD ((ll)(1e9+7))//mod用定数 (ll)(1e9+7) #endif #define mod(n) ( ((ll)n) % MOD) #define modp(n, p) ( ((ll)n) % (ll)(p)) #define modx(A,B) mod(mod(A)*mod(B)) 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 next asdnext #define prev asdprev #define y0 y3487465 #define y1 y8687969 #define j0 j1347829 #define j1 j234892 #define SZ(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define _n "\n" #define _n2 "\n\n" #define _t "\t" #define _s " " #define _output dout<<"output:"; #define _here dout<<"here"<<_n; void test(); #endif //テンプレ折り畳み // LLONG_MAX 9.2*1e18 9223372036854775807LL = (2^63)-1 // INT_MAX 2.1*1e9 2147483647 = (2^31)-1 // O(1e8) 1.2sec vvi visited(52, vi(52,1)); vvi t(52, vi(52, -1)); int p[52][52]={}; ll score=0; int x,y; int arrow[4][2]={{1,0},{-1,0},{0,1},{0,-1}};//D,U,R,L enum{ D=0, U=1, R=2, L=3 }; void visit(int x, int y){ visited[x][y]=1; score+=p[x][y]; if(t[x-1][y] == t[x][y])visited[x-1][y]=1; else if(t[x+1][y] == t[x][y])visited[x+1][y]=1; else if(t[x][y-1] == t[x][y])visited[x][y-1]=1; else if(t[x][y+1] == t[x][y])visited[x][y+1]=1; } bool visitable(int v){ return !visited[ (x+arrow[v][0]) ][ (y+arrow[v][1]) ]; } bool move(int v){ if(!visitable(v)) return false; visit( (x+=arrow[v][0]) , (y+=arrow[v][1]) ); if(v==0)cout<<'D'; if(v==1)cout<<'U'; if(v==2)cout<<'R'; if(v==3)cout<<'L'; return true; } //solve//solve//solve//solve//solve//solve//solve//solve void solve(){ cin>>x>>y; x++;y++; reps(i,50){ reps(j,50){ int c; cin>>c; t[i][j]=c; } } reps(i,50){ reps(j,50){ int c; cin>>c; p[i][j]=c; } } reps(i,50){ reps(j,50){ visited[i][j]=0; } } visit(x,y); while(1){ bool flag=0; rep(i,4){ flag|=move(i); if(flag)break; } if(!flag)break; } cout<<_n; dout<<"score"<<score; } int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << std::fixed << std::setprecision(20); #ifdef SOME_TESTCASE int t = 0; cin >> t; rep(i, t) solve(); #else solve(); #endif return 0; } void test(){ }
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ll; int main() { ll N; cin >> N; ll cnt=N; for (int i=0;i<70;i++) { if (N<pow(2,i)) { break; } else { ll a=N/pow(2,i); ll c=a*pow(2,i); ll b=N-c; if ((a+i+b)<cnt) { cnt=a+i+b; } } } cout << cnt << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long x,a,bb,cc; int count=0, arr[65], b[65], kaam=0; long long c[65]; cin>>x; for(int i=0; x!=0; i++) { arr[i]=x%2; x=x/2; count++; if(arr[i]==1) b[kaam++]=i; } if(kaam!=1) { for(int i=0; i<kaam-1;i++) { cc=bb=a=0; for(int j=0; j<=i; j++) { cc+=pow(2, b[j]); } bb=b[i+1]; for(int j=i+1; j<kaam; j++) { a+=pow(2, b[j]-b[i+1]); } c[i]=cc+bb+a; } sort(c, c+kaam-1); } else { c[0]=1+b[0]; } cout<<c[0]; return 0; }
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; int main(){ int a, b, c; cin >> a >> b >> c; cout << 21 - a - b - c << endl; return 0; }
#include <iostream> #include <vector> using namespace std; using llint = long long; #define rep(i,n) for(int i=0;i<(n);++i); int main() { llint a,b,c; cin >> a >> b >> c; cout << (7-a) + (7-b) + (7-c) << endl; return 0; }
#include <bits/stdc++.h> typedef long double ld; #define int unsigned long long #define gcd __gcd #define endl "\n" #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define mod2 998244353 #define maxe *max_element #define mine *min_element #define inf 1e18 #define pb push_back #define all(x) x.begin(), x.end() #define f first #define s second #define lb lower_bound #define ub upper_bound #define ins insert #define sz(x) (int)(x).size() #define mk make_pair #define deci(x, y) fixed<<setprecision(y)<<x #define w(t) int t; cin>>t; while(t--) #define nitin ios_base::sync_with_stdio(false); cin.tie(nullptr) #define PI 3.141592653589793238 #define mem0(x) memset(x,0,sizeof x) #define mem1(x) memset(x,-1,sizeof x) using namespace std; template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.f << ", " << p.second << ')'; } template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; } void dbg_out() { cerr << endl; } template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); } #ifdef NITIN #define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__) #else #define dbg(...) #endif void solve() { int n; cin>>n; int x=3; int a=1,b=1; while(x<inf){ int y=5; b=1; while(y<inf){ if(x+y==n){ cout<<a<<" "<<b<<endl; exit(0); } y*=5; b++; } x*=3; a++; } cout<<-1<<endl; } int32_t main() { nitin; solve(); }
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <numeric> #include <cmath> #include <iomanip> #include <cstdio> #include <set> #include <map> #include <list> #include <cstdlib> #include <queue> #include <stack> #include <bitset> using namespace std; #define MOD 1000000007 #define PI 3.1415926535897932 #define rep(i, n) for (int i = 0; i < n; i++) #define repe(i, j, n) for (int i = j; i < n; i++) #define repi(i, n) for (int i = 0; i <= n; i++) #define repie(i, j, n) for (int i = j; i <= n; i++) #define all(x) x.begin(), x.end() #define println() cout << endl #define P pair<int, int> #define fi first #define se second typedef long long ll; long long modinv(long long a, long long m) { long long b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } ll gcd(ll a, ll b) { if(a%b) { return gcd(b, a%b); } else { return b; } } void solve1() { int n; cin >> n; vector<ll> a(n); rep(i, n) { cin >> a[i]; } ll ans; if(n > 1) { ans = gcd(a[0], a[1]); for(ll i = 2; i < n; i++) { ans = gcd(ans, a[i]); } } else { ans = a[0]; } cout << ans << endl; } int main() { solve1(); }
#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 all(c) begin(c), end(c) #define ok() puts(ok ? "Yes" : "No"); 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 ii = pair<int, int>; using vvi = vector<vi>; using vii = vector<ii>; using gt = greater<int>; using minq = priority_queue<int, vector<int>, gt>; using P = pair<ll, ll>; template <class T> void takeUnique(vector<T> &v) { auto last = std::unique(v.begin(), v.end()); v.erase(last, v.end()); } const ll LINF = 1e18L + 1; const int INF = 1e9 + 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}; // clang++ -std=c++11 -stdlib=libc++ int main() { int v, t, s, d; cin >> v >> t >> s >> d; bool ok = false; if (d < t * v || d > s * v) ok = true; ok(); return 0; }
#include<bits/stdc++.h> #define ll long long #define mod 1000000007 using namespace std; int 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); #endif ll v, a, b, d; cin >> v >> a >> b >> d; a *= v , b *= v; if (a <= d && d <= b) cout << "No\n"; else cout << "Yes\n"; return 0; }
//g++ -std=c++14 test.cpp -o test.out #include <string.h> #include <stdlib.h> #include <math.h> #include <cassert> #include <algorithm> #include <functional> #include <iostream> #include <iomanip> #include <vector> #include <queue> #include <stack> #include <map> #include <unordered_map> #include <utility> #include <limits.h> #include <bitset> #include <set> using namespace std; #define LL long long int const LL INF = (1LL<<60); const int INF_INT = 2147483647-1e6-1; const LL mod = 1000000007ll; const int mod_int = 1000000007; //引用元 //http://drken1215.hatenablog.com/entry/2019/03/03/224600 //union くっつける //find どのグループか調べる struct UnionFind { vector<LL> parent; UnionFind(LL n) : parent(n, -1) { } void init(LL n) { parent.assign(n, -1); } //xの属している木の根っこを返す LL root(LL x) { if (parent[x] < 0) return x; else return parent[x] = root(parent[x]);//経路圧縮 } LL size(LL x) {return -parent[root(x)];}//xの属する木の要素数を求める bool is_same_tree(LL x,LL y) {return root(x)==root(y);} bool merge(LL x,LL y) { x = root(x); y = root(y); if (x == y) return false; if (parent[x] > parent[y]) swap(x, y);//xの親の方がyの親より小さくなるようにする parent[x] += parent[y];//経路の長さを加算 parent[y] = x;//yの親をxとする return true; } }; LL N,M; LL U[200000],V[200000],C[200000]; LL ans[200001]; vector<vector<pair<LL,LL>>> adj; void rec(LL now_node=1,LL prev_node=-1){ for(auto next:adj[now_node]){ LL next_node = next.first; LL edge_num = next.second; if(next_node!=prev_node){ if(ans[now_node]==edge_num){ if(ans[now_node]==1) ans[next_node] = 2; else ans[next_node] = 1; }else{ ans[next_node] = edge_num; } rec(next_node,now_node); } } } void solve(){ UnionFind uf(N+1); //i->jの辺が存在して、それの番号がcならadj[i]はpair(j,c)を含む adj = vector<vector<pair<LL,LL>>>(N+1); for(int i=0;i<M;i++){ if(!uf.is_same_tree(U[i],V[i])){ uf.merge(U[i],V[i]); adj[U[i]].push_back(pair<LL,LL>(V[i],C[i])); adj[V[i]].push_back(pair<LL,LL>(U[i],C[i])); } } ans[1] = 1; rec(); } int main(){ cin >> N >> M; for(int i=0;i<M;i++){ LL u,v,c; cin >> u >> v >> c; U[i] = u; V[i] = v; C[i] = c; } solve(); for(int i=1;i<=N;i++) cout << ans[i] << endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,n) for (long long i = 0; i < (n); ++i) #define DIV 1000000007 //10^9+7 #define INF LONG_MAX/3 #define bit(n) (1LL<<(n)) template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } int dx[4]={1,0,-1,0}; int dy[4]={0,1,0,-1}; // pos, label vector<pair<ll, ll> > to[100005]; ll ans[100005]; ll N, M; void dfs(ll cur, ll pare, bool done) { if(ans[cur] != -1) return; if(done) { ans[cur] = pare + 1; if(ans[cur] > N) { ans[cur] = pare -1; } } else { ans[cur] = pare; } for(auto next: to[cur]) { dfs(next.first, next.second, next.second == ans[cur]); } } set<ll> root[100005]; int main(){ cin >> N >> M; rep(i, M) { ll u, v, c; cin >> u >> v >> c; u--;v--; root[u].insert(c); root[v].insert(c); to[u].push_back(make_pair(v, c)); to[v].push_back(make_pair(u, c)); } rep(i, N) ans[i] = -1; dfs(0, 1, false); rep(i, N) cout << ans[i] << endl;; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<int> a(n), b(n), d(n); rep(i, n) cin >> a[i]; rep(i, n) cin >> b[i]; rep(i, n) d[i] = b[i] - a[i]; // d>0なら[],B選択が有利 vector<int> even(n / 2), odd(n / 2); rep(i, n / 2) even[i] = d[i * 2]; rep(i, n / 2) odd[i] = d[i * 2 + 1]; sort(even.begin(), even.end(), greater<int>()); sort(odd.begin(), odd.end(), greater<int>()); int64_t ans = 0; rep(i, n / 2) { int t = even[i] + odd[i]; if (t > 0) ans += t; } rep(i, n) ans += a[i]; cout << ans << '\n'; 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; using P = pair<int,int>; bool chtr(vector<vector<ll>> a){ ll n=a.at(0).size(); rep(i,n-1){ rep(j,n-1){ if((a.at(i+1).at(j+1)-a.at(i).at(j+1))!=(a.at(i+1).at(j)-a.at(i).at(j))){ return true; } } } return false; } ll minh(vector<ll> a){ sort(a.begin(),a.end()); return a.at(0); } int main(){ ll n; cin>>n; vector<vector<ll>> a(n,vector<ll>(n)); vector<ll> b(n),c(n); b.at(0)=0; rep(i,n){ rep(j,n){ cin>>a.at(i).at(j); } } if(chtr(a)){ cout<<"No"<<endl; }else{ cout<<"Yes"<<endl; rep(i,n-1){ b.at(i+1)=a.at(i+1).at(0)-a.at(0).at(0); } ll adjust=abs(minh(b)); rep(i,n){ b.at(i)+=adjust; c.at(i)=a.at(0).at(i)-b.at(0); } rep(i,n){ cout<<b.at(i)<<" "; } cout<<endl; rep(i,n){ cout<<c.at(i)<<" "; } cout<<endl; } }
#include<ctime> #include<cstdio> #include<cctype> #define ll long long using namespace std; const ll N=2e5+7; ll read(){ char c; ll x=0,f=1; while(!isdigit(c=getchar())) f-=2*(c=='-'); while(isdigit(c)){ x=x*10+f*(c-48); c=getchar(); } return x; } ll n,w,s,t,m,p,f,a[N]; int main(){ #ifndef ONLINE_JUDGE freopen("D.in","r",stdin); freopen("D.out","w",stdout); #endif clock_t t1=clock(); //-------- n=read(); w=read(); for(ll i=1;i<=n;++i){ s=read(); t=read(); p=read(); a[s]+=p; a[t]-=p; if(m<t) m=t; } for(ll i=0;i<=m;++i) a[i]+=a[i-1]; for(ll i=0;i<=m;++i){ if(a[i]>w) f=1; } if(f) puts("No"); else puts("Yes"); //-------- fprintf(stderr,"%0.3lfs",1.0*(clock()-t1)/CLOCKS_PER_SEC); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(){ ll N, T; cin >> N >> T; vector<ll> A(N); for(auto &x: A) cin >> x; vector<ll> q; for(int bit = 0; bit < (1<<(N-N/2)); ++bit){ ll sum = 0; for(int i = 0; i < N-N/2; ++i){ if(bit&(1LL<<i)) sum += A[i+N/2]; } q.push_back(sum); } sort(q.begin(), q.end()); q.push_back(1LL<<60); ll res = 0; for(int bit = 0; bit < (1<<(N/2)); ++bit){ ll sum = 0; for(int i = 0; i < N/2; ++i){ if(bit&(1LL<<i)) sum += A[i]; } if(sum > T) continue; auto it = upper_bound(q.begin(), q.end(), T - sum) - q.begin(); it--; res = max(res, sum + q[it]); } cout << res << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define u unsigned #define ull unsigned long long #define ld long double #define pb push_back #define fasterInOut ios::sync_with_stdio(false); cin.tie(0); #define pi acos(-1) #define f(i,a,b) for(int i=(a);i<=(b);i++) #define fr(i,a,b) for(int i=(a);i>=(b);i--) #define MAX 1000000 void function(int x); int main() { #ifndef ONLINE_JUDGE freopen("C:/Users/ASUS/Desktop/inout/input.txt", "r", stdin); freopen("C:/Users/ASUS/Desktop/inout/output.txt", "w", stdout); #endif int a,b,c; cin>>a>>b>>c; if(a==b) cout<<c<<endl; else if(b==c) cout<<a<<endl; else if(a==c) cout<<b<<endl; else if(a==b && b==c) cout<<a<<endl; else cout<<"0"<<endl; return 0; }
#include<iostream> #include<algorithm> #include<stdio.h> #include<string.h> #include<memory.h> #include<vector> #include<math.h> using namespace std; int main() { int a,b,c; cin>>a>>b>>c; if(a==b) cout<<c; else if(a==c) cout<<b; else if(b==c) cout<<a; else cout<<0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { string s; cin>>s; ll i,j; ll f=0; ll n=s.size(); for(i=0;i<n;i+=2) { if(s[i]>='a'&&s[i]<='z') { } else { f=1; } } if(!f) { for(i=1;i<n;i+=2) { if(s[i]>='A'&&s[i]<='Z') { } else { f=1; } } } if(!f) { cout<<"Yes"<<endl; } else { cout<<"No"<<endl; } }
/* 2020-12-25 */ #include <bits/stdc++.h> #define all(s) (s).begin(),(s).end() #define rall(s) (s).rbegin(),(s).rend() #define uni(s) (s).erase(unique(all(s)),(s).end()) using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> ii; const int INF = (int)(1e9) + 10; bool check(int x,int base){ while (x){ if (x % base == 7) return false; x /= base; } return true; } int main(){ ios::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); int N; cin >> N; int ans = 0; for (int i = 1; i <= N; i++) if (check(i,10) && check(i,8)) ans++; cout << ans; return 0; }
#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 fr(i,e) for(int i=0;i<n;i++) #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()) int main() { fast_cin(); ll t; t=1; for(int it=1;it<=t;it++) { ll min=INT32_MAX; for(int i=0;i<4;i++) { ll a; cin>>a; if(a<min) min=a; } cout<<min<<endl; } return 0; }
#include<bits/stdc++.h> using namespace std; signed main(){ int a,b,c; scanf("%d%d%d",&a,&b,&c); if(c&1){ if(a<0&&b>0){ return 0&puts("<"); } if(a>0&&b<0){ return 0&puts(">"); } if(a==b){ return 0&puts("="); } if(a<b){ puts("<"); } if(a>b){ puts(">"); } } else{ a=abs(a),b=abs(b); if(a==b){ return 0&puts("="); } if(a<b){ puts("<"); } if(a>b){ puts(">"); } } return 0; }
#include <algorithm> #include <iostream> #include <iterator> #include <sstream> #include <utility> #include <cstdarg> #include <cassert> #include <climits> #include <cstdlib> #include <cstring> #include <cstdio> #include <cctype> #include <vector> #include <stack> #include <queue> #include <cmath> #include <set> #include <map> #define File #define tab char(9) #define line char(10) #define space char(32) #define hell int(998244353) #define mod int(1000000007) #define MOD(x, y) (((x) % (y) + (y)) % (y)) #define input_array(arr) for(auto &_: arr) cin >> _ #define Saitama ios_base::sync_with_stdio(false); cin.tie(NULL) #define rep(var, start, end) for(int var = start; var < end; var++) #define output_array(arr) for(auto &_: arr) cout << _ << space; cout << line #ifndef bug #define debug(x) cerr << '[' << #x << " = " << x << ']' << line #define debug2(x, y) cerr << '[' << #x << " = " << x << ']' << space \ << '[' << #y << " = " << y << ']' << line #define debug3(x, y, z) cerr << '[' << #x << " = " << x << ']' << space \ << '[' << #y << " = " << y << ']' << space \ << '[' << #z << " = " << z << ']' << line #define debug4(x, y, z, _) cerr << '[' << #x << " = " << x << ']' << space \ << '[' << #y << " = " << y << ']' << space \ << '[' << #z << " = " << z << ']' << space \ << '[' << #_ << " = " << _ << ']' << line #define bug #endif typedef long long ll; // use %lld typedef long double ld; // use %lf using namespace std; vector<ll> prime_factors(ll num) { vector<ll> ans; // 1 is not included in the implementation while(num % 2){ ans.push_back(2); num /= 2; } for(int i = 3; i * i <= num; i += 2){ while(num % i == 0){ ans.push_back(i); num /= i; } } // if the number was prime (greater than 2) if(num > 2) ans.push_back(num); return ans; } const ld pi = 3.14159265358979323846; void tests() { int rows, cols; cin >> rows >> cols; vector<int> arr(rows * cols); input_array(arr); int minimum = *min_element(arr.begin(), arr.end()); ll ans = 0; rep(i, 0, rows * cols){ ans += arr[i] - minimum; } cout << ans << line; } int32_t main() { Saitama; #ifndef File freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t = 1; // cin >> t; while(t--){ tests(); } return 0; }
/*NEVER GIVE UP*/ /*First try brute force and check if it is in the range of time complexity*/ /*Then try to solve the problem in mathematical form*/ /*Then try to imagine how the final ans will look like*/ /*Write on paper if still not able to get*/ /*Try to think diff. algorithms and data structures that could solve the problem*/ #include <bits/stdc++.h> using namespace std; int main() {long long r=0,c=0,s=0,min=1000; cin>>r>>c; long long a[r][c]; for(long long i=0;i<r;i++) { for(long long j=0;j<c;j++) { cin>>a[i][j]; if(a[i][j]<min) min=a[i][j]; } } for(long long i=0;i<r;i++) { for(long long j=0;j<c;j++) s+=(a[i][j]-min); } cout<<s; }
// Standard I/O #include <iostream> #include <sstream> #include <cstdio> // Standard Library #include <cstdlib> #include <cstring> #include <ctime> #include <cmath> // Template Class #include <complex> #include <string> #include <vector> #include <list> #include <set> #include <map> #include <queue> #include <stack> // Container Control #include <algorithm> using namespace std; #define rep( i, n ) for( int i = 0; i < n; ++i ) #define irep( i, n ) for( int i = n-1; i >= 0; --i ) #define reep( i, s, n ) for ( int i = s; i < n; ++i ) #define ireep( i, n, s ) for ( int i = n-1; i >= s; --i ) #define foreach(itr, x) for( typeof(x.begin()) itr = x.begin(); itr != x.end(); ++itr) #define mp make_pair #define mt make_tuple #define pb push_back #define eb emplace_back #define all( v ) v.begin(), v.end() #define fs first #define sc second #define vc vector // for visualizer.html double SCALE = 1.0; double OFFSET_X = 0.0; double OFFSET_Y = 0.0; #define LINE(x,y,a,b) cerr << "line(" << SCALE*(x) + OFFSET_X << "," \ << SCALE*(y) + OFFSET_Y << "," \ << SCALE*(a) + OFFSET_X << "," \ << SCALE*(b) + OFFSET_Y << ")" << endl; #define CIRCLE(x,y,r) cerr << "circle(" << SCALE*(x) + OFFSET_X << "," \ << SCALE*(y) + OFFSET_Y << "," \ << SCALE*(r) << ")" << endl; typedef long long ll; typedef complex<double> Point; typedef pair<int, int> pii; typedef pair<int, pii> ipii; typedef vector<int> vi; typedef vector<double> vd; typedef vector< vector<int> > vii; typedef vector< vector<double> > vdd; typedef vector<int>::iterator vi_itr; const int IINF = 1 << 28; const int MOD = 1e9+7; const double INF = 1e30; const double EPS = 1e-10; const double PI = acos(-1.0); // Direction : L U R D const int dx[] = { -1, 0, 1, 0}; const int dy[] = { 0, -1, 0, 1 }; int n, m; int a[128], b[128]; int k; int c[20], d[20]; int count ( int s[20] ) { int cnt = 0; int dish[128] = {}; rep(i, k) { if ( s[i] == 0 ) ++dish[c[i]]; else ++dish[d[i]]; } rep(i, m) { if ( dish[a[i]] >= 1 && dish[b[i]] >= 1 ) ++cnt; } return cnt; } int solve ( int s[20], int depth = 0 ) { if ( depth == k ) { return count(s); } int ans = 0; rep(i, 2) { s[depth] = i; ans = max(ans, solve(s, depth+1)); } return ans; } int main() { cin >> n >> m; rep(i, m) cin >> a[i] >> b[i]; cin >> k; rep(i, k) cin >> c[i] >> d[i]; int s[20] = {}; int ans = solve(s); cout << ans << endl; }
#include <bits/stdc++.h> #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define rep(i,n) for(int i=0;i<(int)(n);i++) #define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++) #define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++) #define codefor int test;scanf("%d",&test);while(test--) #define INT(...) int __VA_ARGS__;in(__VA_ARGS__) #define LL(...) ll __VA_ARGS__;in(__VA_ARGS__) #define yes(ans) if(ans)printf("yes\n");else printf("no\n") #define Yes(ans) if(ans)printf("Yes\n");else printf("No\n") #define YES(ans) if(ans)printf("YES\n");else printf("NO\n") #define vector1d(type,name,...) vector<type>name(__VA_ARGS__) #define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__)) #define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__))) #define umap unordered_map #define uset unordered_set using namespace std; using ll = long long; const int MOD=1000000007; const int MOD2=998244353; const int INF=1<<30; const ll INF2=(ll)1<<60; //入力系 void scan(int& a){scanf("%d",&a);} void scan(long long& a){scanf("%lld",&a);} template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);} template<class T> void scan(T& a){cin>>a;} template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);} void in(){} template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);} //出力系 void print(const int& a){printf("%d",a);} void print(const long long& a){printf("%lld",a);} void print(const double& a){printf("%.15lf",a);} template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);} template<class T> void print(const T& a){cout<<a;} template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}} void out(){putchar('\n');} template<class T> void out(const T& t){print(t);putchar('\n');} template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);} //デバッグ系 template<class T> void dprint(const T& a){cerr<<a;} template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}} void debug(){cerr<<endl;} template<class T> void debug(const T& t){dprint(t);cerr<<endl;} template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);} ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; } ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; } ll modinv(ll a, ll m) {ll b = m, u = 1, v = 0;while (b) {ll t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;} ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;} template<class T> void chmax(T &a,const T b){if(b>a)a=b;} template<class T> void chmin(T &a,const T b){if(b<a)a=b;} int main(){ INT(n,m); vector<int> a(n); vector<int> minv(n,INF); in(a); vector<vector<int>> graph(n); int from,to,x,ans=-INF; rep(i,m){ in(from,to); graph[from-1].push_back(to-1); } rep(i,n){ rep(j,graph[i].size()){ chmin(minv[graph[i][j]],a[i]); chmin(minv[graph[i][j]],minv[i]); } } rep(i,n)if(minv[i]!=INF)chmax(ans,a[i]-minv[i]); out(ans); }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; typedef unsigned long long ull; #define pi 3.14159265358979323846264338327950 #define ll long long #define ld long double #define boost ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) (int)((x).size()) #define mem1(a) memset(a, -1, sizeof(a)) #define mem0(a) memset(a, 0, sizeof(a)) ////debug template----------------------------- #ifndef ONLINE_JUDGE #define what(x...) \ cerr << "[" << #x << "] = ["; \ _print(x) #else #define what(x...) #endif //---- void __print(int x) { cerr << x; } void __print(ll x) { cerr << x; } void __print(ull x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(ld x) { cerr << x; } void __print(char x) { cerr << '\'' << x << '\''; } void __print(const char *x) { cerr << '\"' << x << '\"'; } void __print(const string &x) { cerr << '\"' << x << '\"'; } void __print(bool x) { cerr << (x ? "true" : "false"); } template <typename T, typename V> void __print(const pair<T, V> &x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; } template <typename T> void __print(const T &x) { int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; } void _print() { cerr << "]\n"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); } /////--------Debug template End-----------> ////Deepak Prajapati-----------------------------------------------> const ll mxN = 1e5 + 10; const ld eps = 1e-6; const ll mod = 1e9 + 7; const ll inf = 1e18; // vector<pair<int, int>> moves = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; // vector<vector<int>> g; // vector<bool> vis; void solve(int tc) { vector<int> a(3); for (auto &&i : a) { cin >> i; } sort(all(a)); cout << a[1] + a[2] << "\n"; } int main() { boost; cout << setprecision(10) << fixed; int tc = 1; // cal(); // sieve(); // cin >> tc; for (int i = 1; i <= tc; i++) { // cout << "Case #" << i << ": "; solve(i); } #ifndef ONLINE_JUDGE cerr << "Time: " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << " ms\n"; #endif return 0; }
#include <iostream> #include <vector> #include <queue> #include <stack> #include <map> #include <algorithm> #include <bitset> #include <string> #include <cstdio> #include <cmath> #include <climits> #include <fstream> #include <chrono> using namespace std; const long long INF = LLONG_MAX; const long long MOD = 1000000007; typedef pair<int, int> pii; typedef pair<long long, long long> pll; // input int sx, sy; vector<vector<int>> tile(50, vector<int>(50)), point(50, vector<int>(50)); // UP,0 // DOWN,1 // LEFT,2 // RIGHT,3 const int dx[] = {0, 0, -1, 1}; const int dy[] = {-1, 1, 0, 0}; char output(int move) { switch (move) { case 0: return 'U'; case 1: return 'D'; case 2: return 'L'; case 3: return 'R'; default: return 'U'; } } void change(int& x, int& y, const int& move) { x += dx[move]; y += dy[move]; } int move_point(const int& now_x, const int& now_y, const int& move, const vector<char>& visited) { int next_x = now_x + dx[move]; int next_y = now_y + dy[move]; if (next_x < 0 || 50 <= next_x) return 0; if (next_y < 0 || 50 <= next_y) return 0; if (visited[tile[next_y][next_x]] == 'o') return 0; if (tile[next_y][next_x] == tile[now_y][now_x]) return 0; return point[next_y][next_x]; } int main(void) { // input cin >> sy >> sx; for (int y = 0; y < 50; y++) { for (int x = 0; x < 50; x++) { cin >> tile[y][x]; } } for (int y = 0; y < 50; y++) { for (int x = 0; x < 50; x++) { cin >> point[y][x]; } } vector<char> visited(tile[49][49] + 1, 'x'); string ans; auto start = chrono::system_clock::now(); auto now = chrono::system_clock::now(); int now_x = sx, now_y = sy; do { visited[tile[now_y][now_x]] = 'o'; int max_point = 0; int move; for (int i = 0; i < 4; ++i) { if (move_point(now_x, now_y, i, visited) > 0) { int point = 0; switch (i) { case 0: point = now_y - 1; break; case 1: point = 50 - now_y; break; case 2: point = now_x - 1; break; case 3: point = 50 - now_x; break; } if (max_point < point) { max_point = point; move = i; } } } // move if (max_point == 0) { break; } else { change(now_x, now_y, move); ans += output(move); } now = chrono::system_clock::now(); } while (chrono::duration_cast<chrono::milliseconds>(now - start).count() < 1900); cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int n, a[N]; bool solve() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } if (n % 2) return false; map<int, int> freq; for (int i = 1; i <= n; i++) { freq[a[i]]++; } for (auto [x, f] : freq) { if (f % 2) return true; } return false; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while (t--) { cout << (solve() ? "First" : "Second") << '\n'; } return 0; }
#pragma GCC optimize("Ofast") #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/tree_policy.hpp> #include <functional> // for less using namespace std; #define int long long #define pb push_back #define mp make_pair #define st(arr,a) memset(arr,a,sizeof arr) #define nl cout<<'\n' #define bitcount(x) __builtin_popcountll(x) const int MOD = 1000000007ll; #define forn(i,a,b) for(int i=a;i<=b;i++) #define rfor(i,a,b) for(int i=a;i>=b;i--) #define all(x) x.begin() , x.end() #define pi pair<int,int> #define X first #define Y second #define sz(A) (int)A.size() #define N 1014159 #define vi vector<int> #define v vector #define die exit(0) #define alln(arr) arr+1 , arr+1+n using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset; // order_of_key (k) : Number of items strictly smaller than k . // find_by_order(k) : K-th element in a set (counting from zero). #define in input_int() #define ins input_string() bool sb(int a,int i){return (a&(1LL<<i))>0;} int p2(int a){return (1LL<<a);} int input_int(){int a;cin>>a;return a;} string input_string(){string s;cin>>s;return s;} int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; int ceil(int a,int b){return (a+b-1)/b;} int ct,visited[N],ans; vi adj[N]; int n,m,k,a,b,c,d,x,y,arr[N]; void clr() { forn(i,0,n+10)adj[i].clear(),visited[i]=0,arr[i]=0; } string s; void solve() { cin>>n; map<int,int>m; forn(i,1,n) { m[in]++; } int ans=0; for(auto i : m) { ans+=(n-i.Y)*i.Y; } cout<<ans/2; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; //cin>>t; forn(i,1,t) { //cout<<"Case #"<<i<<": "; solve(); nl; } return 0; } // clang++ c.cpp ; ./a.out < a.txt ;
#include <bits/stdc++.h> using namespace std; const double pi=3.141592653589793; const int64_t inf=1L<<60; //const int64_t mod=1000000007; const int64_t mod=998244353; int main(){ int N,M; cin>>N>>M; map<int,set<int>> black; set<int> move; move.insert(N); for(int i=0; i<M; i++){ int x,y; cin>>x>>y; black[x].insert(y); } set<int> pushlist; set<int> poplist; for(auto m : black){ auto ylist=m.second; for(int y : ylist){ if(move.count(y)){ if(!move.count(y+1)&&!move.count(y-1)){ //隣がいけないならダメ poplist.insert(y); } } else{ if(move.count(y+1)||move.count(y-1)){ //隣がいけるならok pushlist.insert(y); } } } for(int i : poplist){ move.erase(i); poplist.erase(i); } for(int i : pushlist){ move.insert(i); pushlist.erase(i); } } cout<<move.size()<<endl; }
#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) int s,n; pair<int,int>a[200005]; map<int,queue<int> >ma; map<int,bool>h; int vis[200005],ans; vector<int>G[200005]; void dfs(int n){ if(vis[n]==2)return; ans+=vis[n]; for(auto i:G[n])dfs(i); vis[n]=2; } int main(){ n=read,s=read; a[0]=make_pair(0,n); for(int i=1;i<=s;++i) a[i].first=read,a[i].second=read; sort(a+1,a+s+1); for(int i=s;~i;--i) if(h[a[i].second]){ queue<int>&w=ma[a[i].second]; while(w.size()&&a[w.front()].first>a[i].first)G[i].push_back(w.front()),w.pop(); ma[a[i].second-1].push(i); ma[a[i].second+1].push(i); }else{ h[a[i].second]=1;vis[i]=1; queue<int>&w=ma[a[i].second]; while(w.size()&&a[w.front()].first>a[i].first)G[i].push_back(w.front()),w.pop(); ma[a[i].second-1].push(i); ma[a[i].second+1].push(i); } dfs(0);cout<<ans; return 0; }
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; #pragma GCC optimize ("-O3") #define int long long #define ld long double #define endl "\n" #define rep(i,begin,end) for (__typeof(end) i=begin-(begin>end); i!=(end)-(begin>end); i+=1-2*(begin>end)) #define umap unordered_map #define pq priority_queue #define pb push_back #define mp make_pair #define fs first #define sec second #define lb lower_bound #define ub upper_bound #define mii map<int,int> #define pii pair<int,int> #define vc vector #define vi vc<int> #define vvi vc<vi> #define all(v) v.begin(),v.end() #define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower); #define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper); #define gcd(a,b) __gcd((a),(b)) #define lcm(a,b) ((a)*(b))/gcd((a),(b)) #define remax(a,b) a = max(a,b) #define remin(a,b) a = min(a,b) #define w(t) int t; cin>>t; rep(tc,0,t) #define clr(a,x) memset(a,x,sizeof a) #define chkbit(x,i) ((x)&(1LL<<(i))) #define setbit(x,i) ((x)|(1LL<<(i))) #define setbits(x) __builtin_popcountll(x) #define zerobits(x) __builtin_ctzll(x) #define ps(x,y) fixed<<setprecision(y)<<x #define print(a, n) rep(i,0,n) cout<<a[i]<<" "; cout<<endl; #define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n"; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; const int mod = 1e9+7; const int mod2 = 998244353; const int N = 3e5; const int inf = 1e18; const ld PI = 3.141592653589793; //===================================================== template<typename... T> void in(T&... args) {((cin>>args), ...);} template<typename... T> void out(T&&... args) {((cout<<args<<" "), ...);} template<typename... T> void outln(T&&... args) {((cout<<args<<" "), ...); cout<<endl;} int nxt(){int x;cin>>x;return x;} int add(int a,int b,int mod){int res=(a+b)%mod;return (res<0)?res+mod:res;} int mul(int a,int b,int mod){int res=(a*1LL*b)%mod;return (res<0)?res+mod:res;} int range(int x,int y,int z) {return (x >= y && x <= z);} //===================================================== void solve(){ int n = nxt(); vector<int> c(1001); rep (i, 0, n) { int x = nxt(); for (int i = 1; i*i <= x; i++){ if (x % i == 0){ c[i]++; if (i*i != x) c[x/i]++; } } } int ans = 0; rep (i, 2, 1001){ if (c[i] >= c[ans]) ans = i; } cout << ans << endl; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); solve(); return 0; }
#include <bits/stdc++.h> #include <string> #include <vector> #include <iostream> #include <algorithm> #include <cmath> #include <climits> #include <set> #include <map> #include <utility> #include <stack> #include <numeric> #include <utility> #include <complex> #include <chrono> using namespace std; using namespace std::chrono; typedef long long int lli; typedef long double ld; typedef vector<lli> vl; typedef vector<ld> vd; typedef map<lli,lli> ml; typedef unordered_map<lli,lli> uml; typedef pair<lli,lli> pl; typedef set<lli> sl; typedef vector<pl> vp; typedef queue<lli> ql; typedef priority_queue<lli> pql; typedef list<lli> ll; typedef vector<ll> graph; # define pb push_back # define mp make_pair # define f first # define sec second # define itr iterator # define MOD 1000000007 # define INF 1000000000000000 # define all(x) x.begin(), x.end() # define rall(a) a.begin(), a.end(), greater<lli>() # define ins insert # define ms(a,x) memset(a, x, sizeof(a)) # define rep(i,n) for(i=0;i<n;i++) # define wrep(i,a,b) for(i=a;i<b;i++) # define M 1500001; /* void knapsack(lli n, lli m, vl va, vl vb){ lli i, w; lli k[n+1][m+1]; k[n][m] = -1; for(i=0;i<=n;i++){ for(w=0;w<=m;w++){ if(i==0 || w==0){ k[i][w]=0; } else if(va[i-1]<=w){ k[i][w] = max(k[i-1][w], k[i-1][w-va[i-1]]+ vb[i-1]); } else{ k[i][w] = k[i-1][w]; } } } cout<<k[n][m]<<endl; } bool comp(pl a, pl b){ return a.f<b.f; } bool comp(lli a, lli b){ return abs(a)<abs(b); } lli cmb(lli n, lli r){ if(n==r){ return 1; } lli i, pdt = 1; r = max(r,n-r); for(i=1;i<=n-r;i++){ pdt *= (r+i); pdt /= i; } return pdt; } lli per(lli n, lli r){ lli i; lli pdt = 1; for(i=1;i<=r;i++){ pdt *= n-r+i; } return pdt; } // Binomial coeff Table // Combination Table lli dp[2001][2001]; void foo(){ dp[0][0] = 1; lli i, j; for (i = 1; i < 1001; i++) { dp[i][0] = 1; for (j = 1; j <= i; j++) { dp[i][j] = (dp[i-1][j] + dp[i-1][j-1]) % MOD; } } } //cout << fixed << setprecision(9) << t << endl; //sieve Table int sv[M]; vl prm; void sieve(){ lli i, j; for(i=2;i<M;i++){ if(sv[i]!=0){ continue; } sv[i] = -1; prm.pb(i); for(j=2;j*i<M;j++){ sv[i*j] = 1; } } return; } lli fexpo(lli a, lli b){ if(a==1) return 1; if(b==0) return 1; if(b==1) return a%MOD; lli ans = fexpo(a,b/2)%MOD; if(b%2==0) return (ans*ans)%MOD; else return (((a*ans)%MOD)*ans)%MOD; } lli fact[M]; lli inv_fact[M]; void foo(){ lli i; fact[0] = 1; for(i=1;i<M;i++){ fact[i] = (i*fact[i-1])%MOD; } inv_fact[M-1] = fexpo(fact[M-1],MOD-2); for(i=M-2;i>=0;i--){ inv_fact[i] = ((i+1)*inv_fact[i+1])%MOD; } } lli cmb(lli n, lli r){ return (((fact[n]*inv_fact[r])%MOD)*(inv_fact[n-r]))%MOD; } void bezout(lli a, lli b, lli &x, lli &y){ if(a==0){ x = 0; y = 1; return; } lli x1, y1; bezout(b%a,a,x1,y1); x = y1 - (b/a)*x1; y = x1; return; } */ void solve(){ lli n, i, m=0, q=0, mx=-INF, mn=INF, k=0, j=0, c=0, d=0, t = 0, sm = 0, pdt = 1; cin >> n; //lli v[n]; if(n%2==0){ cout<<"White"<<endl; } else{ cout<<"Black"<<endl; } return; } int main() { //ios_base::sync_with_stdio(false); //cin.tie(NULL); int t; //freopen("input.txt", "rt", stdin); //freopen("output.txt", "wt", stdout); //cin >> t; t = 1; while(t--){ solve(); } return 0; }
#include <iostream> #include <string> #include <algorithm> #include <functional> #include <vector> #include <stack> #include <queue> #include <set> #include <map> #include <cstdio> #include <cmath> #include <tuple> #include <random> #define rep(i, n) for(i = 0; i < n; i++) #define int long long using namespace std; const int mod = 998244353; int n; int w[100]; int fact[101]; int dp[101][101][5101]; signed main() { int i, j, k; cin >> n; rep(i, n) cin >> w[i]; fact[0] = 1; for (i = 1; i <= n; i++) { fact[i] = fact[i - 1] * i % mod; } int sumW = 0; rep(i, n) sumW += w[i]; if (sumW % 2 == 1) { cout << 0 << endl; return 0; } dp[0][0][0] = 1; rep(i, n) { for (j = 0; j <= i; j++) { rep(k, 5001) { dp[i + 1][j][k] += dp[i][j][k]; dp[i + 1][j][k] %= mod; dp[i + 1][j + 1][k + w[i]] += dp[i][j][k]; dp[i + 1][j + 1][k + w[i]] %= mod; } } } int ans = 0; for (i = 1; i < n; i++) { int res = dp[n][i][sumW / 2]; ans += res * fact[i] % mod * fact[n - i] % mod; ans %= mod; } cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define fast ios_base::sync_with_stdio(false);cin.tie(NULL) #define endl "\n" #define pb push_back #define mod 1000000007 #define MAXN 100000 int dx[]={1,-1,0,0}; int dy[]={0,0,1,-1}; int dx8[]={1,-1,0,0,1,1,-1,-1}; int dy8[]={0,0,1,-1,1,-1,1,-1}; int spf[MAXN]; void sieve() { int i, j; for (i = 0; i < MAXN; i++) spf[i] = i; for (i = 4; i < MAXN; i += 2) spf[i] = 2; for (i = 3; i * i < MAXN; i++) { if (spf[i] == i) { for (j = i * i; j < MAXN; j += i) { if (spf[j] == j) spf[j] = i; } } } } ll binexp(ll a, ll b, ll m) { a %= m; ll res = 1; while (b > 0) { if (b & 1) res = res * a % m; a = a * a % m; b >>= 1; } return res; } ll modinvfermat(ll a, ll m) { return binexp(a, m - 2, m); } void task(bool flag) { if (flag) cout << "YES\n"; else cout << "NO\n"; } ll lcm(ll a, ll b) { return ((1LL * a * b) / (__gcd(a, b))); } bool sortbysec(const pair<int,int> &a, const pair<int,int> &b) { return (a.second < b.second); } bool sortbyme(const pair<int,int> &a, const pair<int,int> &b){ return (a.first+a.second > b.first+b.second); } long double sq(long double n){ long double l=0,r=n; long double mid=l+(r-l)/2; while(r-l>=0.0000001){ mid=l+(r-l)/2; if(mid*mid<n){ l=mid; } else{ r=mid; } } // cout<<mid<<endl; return mid; } void solve(){ ll n; cin>>n; string s; cin>>s; ll ans=0; unordered_map<ll,ll> m; ll sum=0; vector<ll> a(n,0); for(ll i=0;i<n;i++) { if(s[i]=='G')a[i]=1e6; else if(s[i]=='C')a[i]=-1e6; else if(s[i]=='T')a[i]=1; else if(s[i]=='A') a[i]=-1; } for(ll i=0;i<n;i++) { sum+=a[i]; if(sum==0)ans++; if(m[sum])ans+=m[sum]; m[sum]++; } cout<<ans<<endl; return; } int main() { #ifndef ONLINE_JUDGE // for getting input from input.txt freopen("input.txt", "r", stdin); // for writing output to output.txt freopen("output.txt", "w", stdout); #endif fast; ll t; t=1; // cin>>t; while(t--){ solve(); } #ifndef ONLINE_JUDGE cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n"; #endif return 0; }
#include <cstdio> #include <iostream> #include <cstring> #include <queue> using namespace std; # define rep(i,a,b) for(int i=(a); i<=(b); ++i) # define drep(i,a,b) for(int i=(a); i>=(b); --i) typedef long long int_; inline int readint(){ int a = 0; char c = getchar(), f = 1; for(; c<'0'||c>'9'; c=getchar()) if(c == '-') f = -f; for(; '0'<=c&&c<='9'; c=getchar()) a = (a<<3)+(a<<1)+(c^48); return a*f; } inline void writeint(int_ x){ if(x > 9) writeint(x/10); putchar((x-x/10*10)^48); } const int MaxN = 100005; const int Mod = 1e9+7; int a[MaxN], f[MaxN]; int main(){ int n = readint(); f[0] = 1, f[1] = 2; rep(i,2,n) f[i] = (f[i-1]+f[i-2])%Mod; a[1] = readint(); int ans = 1ll*a[1]*f[n-1]%Mod; rep(i,2,n){ a[i] = readint(); int t = 1ll*f[max(i-3,0)]*f[max(n-i-1,0)]%Mod; // '-' t = (1ll*f[i-2]*f[n-i]%Mod+Mod-t)%Mod; // + ans = (ans+1ll*t*a[i])%Mod; } printf("%d\n",ans); return 0; }
#include<bits/stdc++.h> typedef long long int ll; typedef long double ld; typedef std::vector<ll> vi; typedef std::vector<std::vector<ll> > vv; typedef std::vector<std::pair<ll,ll> > pii; #define mod 1000000007 #define IO ios_base::sync_with_stdio(false);cin.tie(NULL); #define fo(i,a,b) for(i=a;i<b;i++) #define forr(i,a,b) for(i=a;i>=b;i--) #define mp make_pair #define pb(x) push_back(x) #define fi first #define se second #define print(vec,a,b) for(ll i=a;i<b;i++) cout<<vec[i]<<" ";cout<<endl; #define all(a) a.begin(),a.end() #define input(vec,a,b) for(ll i = a;i<b;i++) cin>>vec[i]; #define ms(a,val) memset(a,val,sizeof(a)) using namespace std; const int N = 2e5+ 5; ll expo_pow(ll x, ll y) { if (y == 0) return 1; y = y % (mod - 1); x %= mod; if (y == 0) y = mod - 1; ll res = 1; while (y) { if (y & 1) res = (res * x) % mod; x = (x * x) % mod; y >>= 1; } return res; } ll modInverse(ll a, ll m = mod) { return expo_pow(a, m - 2); } void solve(){ ll i,j,n,m,k; cin>>n; vi a(n,0); input(a,0,n); map<ll, vector<ll> > M; i = 1; bool done = false; while( i < 202) { if( n < 10 && i == (1LL<<n)) break; vi temp; ll sum = 0; fo(j,0,min(n,16LL)) { if((1LL<<j)&i) { sum+=a[j]; temp.pb(j+1); } } sum = sum%200; if(M.find(sum) != M.end()) { done = true; cout<<"Yes"<<endl; cout<<M[sum].size()<<" "; for(auto it : M[sum]) cout<<it<<" "; cout<<endl; //sort(all(temp)); cout<<temp.size()<<" "; for(auto it : temp) cout<<it<<" "; cout<<endl; return ; } else { //sort(all(temp)); M[sum] = temp; } i++; } cout<<"No"<<endl; } int main() { IO; ll t=1,i; //cin>>t; while(t--) { solve(); } return 0; }
#include <bits/stdc++.h> #include <iostream> #include <queue> #include <stack> #include <vector> #include <string> #include <set> #include <map> #include <random> #define rep(i,n) for (int i = 0; i < (n); ++i) #define repp(i,n,m) for (int i = m; i < (n); ++i) #define repl(i,n) for (long long i = 0; i < (n); ++i) #define reppl(i,n,m) for (long long i = m; i < (n); ++i) //#define int long long using namespace std; //#include <atcoder/all> //using namespace atcoder; using ll = long long; using ld = long double; using P = pair<int, int>; using PI = pair<pair<int,int>,int>; using PL = pair<long long, long long>; using PLL = pair<pair<long long, long long>, long long>; using Pxy = pair<long double, long double>; using Tiib = tuple<int, int, bool>; using vvl = vector<vector<ll>>; const int INF = 1001001007; const int modd = 1000000007; const long long modl = 1000000007LL; const long long mod = 998244353LL; const ll inf = 1e18; template <typename AT> void printvec(vector<AT> &ar){ rep(i,ar.size()-1) cout << ar[i] << " "; cout << ar[ar.size()-1] << endl; } template <typename Q> void printvvec(vector<vector<Q>> &ar){ rep(i,ar.size()){ rep(j,ar[0].size()-1) cout << ar[i][j] << " "; cout << ar[i][ar[0].size()-1] << endl; } } template <typename S> bool range(S a, S b, S x){ return (a <= x && x < b); } void yes(){ cout << "Yes" << endl; } void no (){ cout << "No" << endl; } ll cel (ll a, ll b){ if (a % b == 0) return a / b; else return a / b + 1; } ll gcds(ll a, ll b){ ll c = a % b; while (c != 0){ a = b; b = c; c = a % b; } return b; } int main(){ int n; cin >> n; ll lcm = 1LL; repp(i,n+1,2){ ll a = i; ll g = gcds(lcm,a); lcm = lcm / g * a; } cout << lcm + 1LL << endl; }
#include<bits/stdc++.h> using namespace std; using Graph=vector<vector<int>>; void dfs(int v,vector<bool> &flag,Graph &g){ if(!flag[v]){return;} flag[v]=false; for(auto &nx : g[v]){dfs(nx,flag,g);} } int main(){ int n,res=0; cin >> n; vector<int> a(n); vector<bool> flag(200005,false); Graph g(200005); for(auto &nx : a){ cin >> nx; if(!flag[nx]){flag[nx]=true;res++;} } int p=0,q=n-1; while(p<q){ g[a[p]].push_back(a[q]); g[a[q]].push_back(a[p]); p++;q--; } for(int i=1;i<=200000;i++){ if(flag[i]){ res--; dfs(i,flag,g); } } cout << res; }
#include "bits/stdc++.h" using namespace std; using li = long long; const char newl = '\n'; template <class T> vector<vector<T>> vv(const unsigned int n, const unsigned int m, const T x) { return vector<vector<T>>(n, vector<T>(m, x)); } template <class T> vector<vector<vector<T>>> vvv(const unsigned int n, const unsigned int m, const unsigned int k, const T x) { return vector<vector<vector<T>>>(n, vv(m, k, x)); } template <class T> bool contains(const set<T>& s, const T& v) { return s.find(v) != s.end(); } template <class T> bool contains(const unordered_set<T>& s, const T& v) { return s.find(v) != s.end(); } template <class K, class V> bool contains_key(const map<K, V>& m, const K& v) { return m.find(v) != m.end(); } int main() { cin.tie(0); ios::sync_with_stdio(false); li n; cin >> n; string t; cin >> t; li ans; const string pattern = "110"; const li rep = 1e10; if (n >= 3) { ans = 0; for (int start = 0; start < 3; ++start) { bool ok = true; for (int i = 0; i < n; ++i) { ok &= t[i] == pattern[(start + i) % 3]; } if (ok) { ans = (rep * 3 - start - n + 3) / 3; break; } } } else if (n == 2) { if (t == "00") { ans = 0; } else if (t == "11") { ans = rep; } else if (t == "10") { ans = rep; } else { // 01 ans = rep - 1; } } else { if (t == "1") { ans = 2 * rep; } else { ans = rep; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll MOD = 1000000007; #define mod(x) (x % MOD + MOD) % MOD const int dx[4] = {+1, 0, -1, 0}; const int dy[4] = {0, -1, 0, +1}; int main() { cin.tie(0); ios_base::sync_with_stdio(false); int n, x; string s; cin >> n >> x >> s; int ans = x; for (char c : s) { if (c == 'x') { ans = max(ans - 1, 0); } else { ans++; } } cout << ans << endl; }
#include <cstdio> #include <iostream> #include <cassert> #include <string> #include <algorithm> #include <cstring> #include <utility> #include <vector> #include <stack> #include <queue> #include <map> #include <set> #include <cmath> #include <deque> #include <unordered_map> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define IOS ios_base::sync_with_stdio(0); cin.tie(0) using namespace std; using namespace __gnu_pbds; typedef long long LL; typedef pair<int, int> pii; typedef pair<LL, LL> pll; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> order_set; const int MAXN = 234567; char S[MAXN], T[123] = "110"; int main() { int N; scanf("%d", &N); scanf("%s", S); LL ans = 0; for (int i = 0; i < 3; i++) { bool OK = true; for (int j = 0; j < N; j++) { if (S[j] != T[(i + j) % 3]) { OK = false; break; } } if (OK) { LL sum = (LL)1e10; LL need = (i + N - 1) / 3 + 1; ans += (sum - need + 1); } } printf("%lld\n", ans); return 0; } /* stuff you should look for * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * WRITE STUFF DOWN by Benq; */
#include <bits/stdc++.h> using namespace std; int a, b, ans; int check(int a, int b) { if (a+b >= 15 && b >= 8) return 1; if (a+b >= 10 && b >= 3) return 2; if (a+b >= 3) return 3; return 4; } int main() { //freopen("isc.inp", "r", stdin); //freopen("isc.out", "w", stdout); scanf("%d%d", &a, &b); ans = check(a, b); printf("%d", ans); return 0; }
#include <iostream> int main() { unsigned int N; std::cin >> N; int cnt = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < N; ++j) { if (i+j == N) cnt++; } } std::cout << cnt; return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; cout<<n-1<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; int a[65]; int main(){ int n; cin>>n; for(int i=0;i<n;i++){ string s; cin>>s; if(s == "AND") a[i] = 1; else a[i] = 0; } ll t = 1,f = 1; for(int i=0;i<n;i++){ if(a[i] == 1) { t = t; f = (ll)f*2+t; } else{ t = (ll)t*2+f; f = f; } } cout<<t<<endl; 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 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 = 10000000000000000; const int intINF = 1000000000; const ll mod = 1000000007; const ll MOD = 998244353; const ld pi = 3.141592653589793238; 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); } 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 res = 1; while (y) { if (y % 2) { res *= x; res %= mod; } x = x * x % mod; y /= 2; } return res; } ll nCk(ll n, ll k) { ll a = 1, b = 1; for (int h = n - k + 1; h <= n; h++) { a *= h; a %= mod; } for (int h = 1; h <= k; h++) { b *= h; b %= mod; } return a * modpow(b, mod - 2) % mod; } //printf("%.10f\n", n); typedef pair <ll, ll> P; ll dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 }; struct edge { ll to, cost; }; struct status { ll cost; ll x; ll y; bool operator<(const status& rhs) const { return cost < rhs.cost; }; bool operator>(const status& rhs) const { return cost > rhs.cost; }; }; signed main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); //cout << fixed << setprecision(15); ll n; cin >> n; vector<string> v(n); rep(i, n) { cin >> v[i]; } vector<ll> t(n + 2), f(n + 2); t[n] = 1; for (int i = n - 1; i >= 0; i--) { if (v[i] == "AND") { t[i] = t[i + 1] + f[i + 1]; f[i] = 2 * f[i + 1]; } else { t[i] = 2 * t[i + 1]; f[i] = t[i + 1] + f[i + 1]; } } cout << t[0] + f[0] << endl; return 0; }
#include <iostream> #include <map> #include <set> #include <cmath> #include <queue> #include <vector> #include <string> #include <algorithm> #include <functional> using namespace std; long long N; long long fib[1 << 18]; void init() { fib[0] = 1; fib[1] = 1; for (int i = 2; i <= 90; i++) fib[i] = fib[i - 1] + fib[i - 2]; } int main() { cin >> N; init(); long long idx = -1, rem = -1; for (int i = 1; i <= 89; i++) { if (fib[i] > N) { idx = i - 1; rem = N - fib[i - 1]; break; } } string S = ""; for (int i = 1; i <= idx; i++) { if (i % 2 == 1) S = "3" + S; if (i % 2 == 0) S = "4" + S; } if (S[0] == '4') S = "1" + S; else S = "2" + S; for (int i = 89; i >= 1; i--) { if (rem < fib[i]) continue; rem -= fib[i]; int cnt = 0; for (int j = (int)S.size() - 1; j >= 0; j--) { if (S[j] == '3' || S[j] == '4') cnt++; if (cnt == i + 1) { string T1 = S.substr(0, j + 1); string T2 = S.substr(j + 1, S.size() - (j + 1)); string U = ""; if (S[j] == '3') U = T1 + "1" + T2; if (S[j] == '4') U = T1 + "2" + T2; S = U; break; } } } cout << S.size() << endl; for (int i = 0; i < S.size(); i++) cout << S[i] << endl; return 0; }
#include<bits/stdc++.h> #define N 5000005 using namespace std; int read() { int x=0,f=1;char c=getchar(); while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();} while('0'<=c&&c<='9'){x=x*10+c-'0';c=getchar();} return x*f; } int n,a[N],b[N],ans; bool tag[2005]; int main() { n = read(); for(int i=1; i<=n; ++i)a[i] = read(); for(int i=1; i<=n; ++i) { for(int j=1; j<=sqrt(a[i]); ++j) { if(a[i]%j == 0)b[++b[0]] = j,b[++b[0]] = a[i]/j; } } sort(b+1,b+b[0]+1); b[0] = unique(b+1,b+b[0]+1)-b-1; for(int i=1; i<=b[0]; ++i) { int x = b[i],now = 0,id,suc; memset(tag,0,sizeof(tag)); for(int j=1; j<=n; ++j)if(a[j]%x == 0){suc = now = a[j];id = j+1;tag[j] = 1;break;} for(int j=id; j<=n; ++j) { if(a[j]%x == 0)now = __gcd(now,a[j]),tag[j] = 1; } if(now == x)suc = 1; else suc = 0; for(int j=1; j<=n; ++j)if(now > a[j])suc = 0; ans += suc; } cout << ans; }
//https://atcoder.jp/contests/abc187/tasks/abc187_d //D - Choose Me #include <bits/stdc++.h> using namespace std; //如果提交到OJ,不要定义 __LOCAL //#define __LOCAL typedef long long ll; const int MAXN=2e5+4; ll vote[MAXN]; int main() { #ifndef __LOCAL //这部分代码需要提交到OJ,本地调试不使用 ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); #endif int n; cin>>n; ll avote=0; for (int i=1; i<=n; i++) { ll a,b; cin>>a>>b; avote += -a;//记录a的票数 vote[i] = 2*a+b; } sort(vote+1, vote+n+1, greater<ll>()); //遍历求解 int ans=0; for (int i=1; i<=n; i++) { avote += vote[i]; if (avote>0) { ans=i; break; } } cout<<ans<<"\n"; #ifdef __LOCAL //这部分代码不需要提交到OJ,本地调试使用 system("pause"); #endif return 0; }
#include <iostream> #include <bits/stdc++.h> #include <bitset> #define ll long long int #define pi pair<int, int> #define pll pair<ll, ll> #define pb push_back #define vi vector<int> #define vl vector<ll> #define vll vector<vl> #define vpi vector<pi> #define vpll vector<pll> #define vb vector<bool> #define vii vector<vi> #define ALL(v) v.begin(), v.end() #define st string #define si(n) cin >> n #define dout(n) cout << n << "\n" #define mod 1000000007 #define f(i, a, b) for (int i = a; i < b; i++) #define fd(i, a, b) for (int i = a; i >= b; i--) using namespace std; bool yes = false; st s1, s2; ll max(ll a, ll b, ll c) { return max(a, max(b, c)); } struct comp { bool operator()(const pi &a, const pi &b) { if (a.first == b.first) return a.second < b.second; return a.first < b.first; } }; bool check_pal(st &s) { int i = 0, j = s.length() - 1; while (i < j) { if (s[i] != s[j]) return false; i++, j--; } return true; } void swap(char &a, char &b) { char ch = a; a = b; b = ch; return; } int dfs(vii &g, vi &vis, vi &co, int pos) { int mn = co[pos]; vis[pos] = 1; f(i, 0, g[pos].size()) { if (!vis[g[pos][i]]) mn = min(dfs(g, vis, co, g[pos][i]), mn); } return mn; } void seive(int n, vector<bool> &isprime) { isprime[0] = true; isprime[1] = true; f(i, 2, n + 1) { if (!isprime[i]) { for (int j = 2; (j * i) < n + 1; j++) isprime[j * i] = true; } } } int findfact( int n , int&a , int &b){ for( int i =2 ;i<n ; i++){ if( n%i == 0 && i!=n/i) { a=i; b = n/i ; return 0; } } return -1; } ll ignoref(vi & v, int mx , int fmx , vi & con, int idx){ ll op=0; int n = v.size(); int prev = idx == 0? v[1]:v[0]; if( fmx==1){ f(i,1,n){ if( v[i]!=mx){ op+= abs(v[i]-prev); //cout<<op<<" "; prev = v[i]; } } } else { int index; int mxcon=INT_MIN; f(i,0,n){ if(v[i]==mx){ if( mxcon <con[i]){ index =i; mxcon = con[i]; } } } f(i,1,n){ if( i!= index){ op+= abs(v[i]-prev)*1ll; // cout<<op<<" "<<v[i]<<" "<<prev<<" \n"; prev = v[i]; } } } return op; } int main() { int n; cin>>n; vi v; f(i,0,n){ int a; cin>>a; v.pb(a); } vector<pair<ll,ll>>pssum(n); ll msf=0,mx=0; f(i,0,n){ msf+=v[i]; mx = max(mx,msf); pssum[i].first = mx; pssum[i].second = msf; } ll ans = 0; msf =0; f(i,0,n){ ans = max(msf+pssum[i].first, ans); msf+=pssum[i].second; } ans = max(msf,ans); cout<<ans<<"\n"; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; #define int long long #define sim template <class c #define ris return *this #define dor > debug& operator<< #define eni(x) \ sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<( \ c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c> {i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { #ifndef LOCAL ~debug() { cerr << endl; } eni( != ) cerr << boolalpha << i; ris; } eni( == ) ris << range(begin(i), end(i)); } sim, class b dor(pair<b, c> d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } #else sim dor(const c&) { ris; } #endif } ; #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " template <typename T> using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template <class T> bool umin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template <class T> bool umax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } #define ll long long #define ld long double #define pb push_back #define mp make_pair #define in insert #define fi first #define se second #define lb lower_bound #define ub upper_bound #define sz(v) (int)(v.size()) #define all(x) x.begin(), x.end() #define allr(x) x.rbegin(), x.rend() #define mem(a, s) memset(a, s, sizeof(a)) #define rep(i, a, b) for (int i = a; i <= b; ++i) #define repr(i, a, b) for (int i = a; i >= b; --i) #define MAX 8000000000000000064LL #define MIN -8000000000000000064LL typedef vector<int> vi; typedef stack<int> sti; typedef queue<int> qi; typedef pair<int, int> pii; typedef set<int> si; typedef map<int, int> mii; typedef vector<pii> vpi; typedef priority_queue<int> pqmax; typedef priority_queue<int, vector<int>, greater<int>> pqmin; const int mod = 1e9 + 7; const int inf = 1e18; const int d4x[4] = { -1, 0, 1, 0}, d4y[4] = {0, 1, 0, -1}; const int d8x[8] = { -1, -1, 0, 1, 1, 1, 0, -1}, d8y[8] = {0, 1, 1, 1, 0, -1, -1, -1}; void solve(); int32_t main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout.precision(20); int t = 1; // cin >> t; rep(i, 1, t) { // cout << "Case #" << i << ": "; solve(); } return 0; } void solve() { int n; cin >> n; vector<pii> v; rep(i, 0, n - 1) { int x, y; cin >> x >> y; v.pb(mp(x, y)); } int count = 0; bool flag = 0; rep(i, 0, n - 1) { rep(j, i + 1, n - 1) { rep(k, j + 1, n - 1) { if ((v[j].se - v[i].se) * (v[k].fi - v[j].fi) == (v[k].se - v[j].se) * (v[j].fi - v[i].fi)) { flag = 1; break; } } } } (flag == 0) ? cout << "No\n" : cout << "Yes\n"; }
#include <bits/stdc++.h> using namespace std; int main() { typedef long long ll; ll n; cin >> n; vector<ll> x; vector<ll> y; bool isYes = false; for(int i=0; i<n; i++){ ll a, b; cin >> a >> b; x.push_back(a); y.push_back(b); } for(int i=0; i<n-2; i++){ for(int j=i+1; j<n-1; j++){ for(int k=j+1; k<n; k++){ // cout << i << "," << j << "," << k <<"." << endl; ll dx1 = x[i] - x[j]; ll dx2 = x[i] - x[k]; ll dy1 = y[i] - y[j]; ll dy2 = y[i] - y[k]; if(dx2*dy1 == dx1*dy2){ cout << "Yes" << endl; return 0; } } } } cout << "No" << endl; return 0; }
#define LOCAL #define _USE_MATH_DEFINES #include <array> #include <cassert> #include <cstdio> #include <cstring> #include <iostream> #include <iomanip> #include <string> #include <sstream> #include <vector> #include <queue> #include <stack> #include <list> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <algorithm> #include <complex> #include <cmath> #include <numeric> #include <bitset> #include <functional> #include <random> #include <ctime> using namespace std; template <typename A, typename B> ostream& operator <<(ostream& out, const pair<A, B>& a) { out << "(" << a.first << "," << a.second << ")"; return out; } template <typename T, size_t N> ostream& operator <<(ostream& out, const array<T, N>& a) { out << "["; bool first = true; for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]"; return out; } template <typename T> ostream& operator <<(ostream& out, const vector<T>& a) { out << "["; bool first = true; for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]"; return out; } template <typename T, class Cmp> ostream& operator <<(ostream& out, const set<T, Cmp>& a) { out << "{"; bool first = true; for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}"; return out; } template <typename U, typename T, class Cmp> ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) { out << "{"; bool first = true; for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}"; return out; } #ifdef LOCAL #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) #else #define trace(...) 42 #endif 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...); } typedef long long int64; typedef pair<int, int> ii; #define SZ(x) (int)((x).size()) const int INF = 1 << 29; const int MOD = 1e9 + 7; mt19937 mrand(random_device{}()); int rnd(int x) { return mrand() % x; } struct fast_ios { fast_ios() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); }; } fast_ios_; int main() { int n, m; cin >> n >> m; vector<int> a(n + 2), b(n + 2); a[0] = 0; a[n + 1] = m + 1; for (int i = 1; i <= n; ++i) cin >> a[i]; map<int, int> mi, mx; for (int i = 0; i <= n + 1; ++i) { int x = a[i] - i; if (mi.find(x) == mi.end()) { mi[x] = i; } else { mi[x] = min(mi[x], i); } if (mx.find(x) == mx.end()) { mx[x] = i; } else { mx[x] = max(mx[x], i); } } // trace(mi, mx); vector<int> left(n + 2, INF), right(n + 2, -INF); bool found = false; for (int i = 1; i <= n; ++i) { cin >> b[i]; int x = b[i] - i; if (mi.find(x) == mi.end()) { found = true; continue; } int L = mi[x], R = mx[x]; if (i >= L && i <= R) continue; if (i < L) { left[L] = min(left[L], i); } else { right[R] = max(right[R], i); } } if (found) { cout << -1 << '\n'; return 0; } int64 ret = 0; for (int i = 0; i <= n + 1; ++i) { // trace(i, left[i], right[i]); ret += max(0, i - left[i]); ret += max(0, right[i] - i); } cout << ret << '\n'; return 0; }
#include <bits/stdc++.h> using Int = long long; // clang-format off #define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++) #define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__) #define ALL(v) std::begin(v), std::end(v) struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io; #ifndef dump #define dump(...) #endif // clang-format on struct in { template <class T> operator T() { T t; std::cin >> t; return t; } }; void out() { std::cout << "\n"; } template <class Head, class... Tail> void out(Head&& h, Tail&&... t) { std::cout << h << (sizeof...(Tail) == 0 ? "" : " "), out(std::forward<Tail>(t)...); } /** * author: knshnb * created: Sun Oct 18 22:11:15 JST 2020 **/ template <class T> bool chmin(T& a, const T& b) { return a > b ? a = b, true : false; } template <class T> bool chmax(T& a, const T& b) { return a < b ? a = b, true : false; } /// @docs src/Helper/BinarySearch.md template <class F> long long binary_search(long long ok, long long ng, F check) { while (std::abs(ok - ng) > 1) { long long mid = (ok + ng) / 2; (check(mid) ? ok : ng) = mid; } return ok; } void no() { out(-1); exit(0); } signed main() { Int n = in(), L = in(); std::vector<Int> a(n), b(n); REP(i, n) a[i] = in(); REP(i, n) b[i] = in(); std::vector<Int> xs = {0}; for (Int x : a) xs.push_back(x); xs.push_back(L + 1); std::vector<Int> vec(n); REP(i, n) { if (a[i] > b[i]) { Int idx = binary_search(0, i + 1, [&](Int mid) { return xs[mid] + i + 1 - mid <= b[i]; }); if (xs[idx] + i + 1 - idx != b[i]) no(); vec[i] = idx; } else if (a[i] < b[i]) { Int idx = binary_search(n + 1, i + 1, [&](Int mid) { return xs[mid] - (mid - (i + 1)) >= b[i]; }); if (xs[idx] - (idx - (i + 1)) != b[i]) no(); vec[i] = idx; } else { vec[i] = i + 1; } } dump(vec); REP(i, n - 1) { if (vec[i] > vec[i + 1]) no(); } std::vector<Int> pma(n + 2), nma(n + 2); REP(i, n) { Int dif = vec[i] - (i + 1); if (dif > 0) chmax(pma[vec[i]], dif); if (dif < 0) chmax(nma[vec[i]], -dif); } out(std::accumulate(ALL(pma), 0LL) + std::accumulate(ALL(nma), 0LL)); }
#pragma GCC optimize ("O2") #pragma GCC target ("avx2") //#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 const int MAX = 10010; class shuturyoku_unko { public: char C[MAX * 6]; constexpr shuturyoku_unko() : C() { rep(i, MAX) { int X = i; rep(j, 5) { C[i * 6 + 4 - j] = '0' + X % 10; X /= 10; } C[i * 6 + 5] = ' '; } } }; constexpr shuturyoku_unko f; char T[800], *ci = T, c, *di; int N, A[110], B[110]; bool furagu[10001]; inline void keisan(int s) { di = T; rep(i, N + 1) { int tmp = A[i] + (B[i] > s); int tmp2; if (tmp >= 1000) { if (tmp >= 10000) tmp2 = 6; else tmp2 = 5; } else { if (tmp >= 100) tmp2 = 4; else if (tmp >= 10) tmp2 = 3; else tmp2 = 2; } memcpy(di, f.C + tmp * 6 + 6 - tmp2, tmp2); di += tmp2; } } int main() { cin.tie(0); ios::sync_with_stdio(false); fread(T, 800, 1, stdin); while ((c = *ci++) >= '0') N = N * 10 + c - '0'; ci += N + 1; rep(i, N + 1) { while ((c = *ci++) >= '0') A[i] = A[i] * 10 + c - '0'; } int saishou = 1e9; rep(i, N) if (saishou > abs(A[i] - A[i + 1])) saishou = abs(A[i] - A[i + 1]); rep(i, N + 1) { B[i] = A[i] % saishou; A[i] = A[i] / saishou; furagu[B[i]] = 1; } printf("%d\n", saishou); keisan(0); rep(s, saishou) { if (furagu[s]) keisan(s); fwrite(T, 1, di - T, stdout); } Would you please return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using P = pair<ll,ll>; #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) #define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++) #define ALL(obj) (obj).begin(), (obj).end() #define rALL(obj) (obj).rbegin(), (obj).rend() const ll INF = 1LL<<60;//1152921504606846976 const int mod = 1000000007; int main(){ ios::sync_with_stdio(false); cin.tie(0); ll n; cin>>n; string s;cin>>s; vector<ll> a(n+1);rep(i,n+1)cin>>a[i]; ll ans = INF; rep(i,n)ans = min(ans, abs(a[i+1]-a[i])); vector<vector<ll>> b(ans, vector<ll>(n+1,0)); rep(i,n+1){ ll idx = 0; while(a[i]){ b[idx][i]++; a[i]--; idx++; idx%=ans; } } cout<<ans<<endl; rep(i,ans){ rep(j,n+1){ cout<<b[i][j]<<" "; } cout<<endl; } return 0; }
#include <iostream> #include <algorithm> #include <vector> #include <string> #include <assert.h> typedef long long ll; #define rep(i,n) for(int i=0;i<n;i++) using namespace std; template <class T> void input(T& a){ cin>>a; } int main(){ int N; input(N); ll ans=0; vector <int>A(N); vector <int>B(200); rep(i,N)cin>>A[i]; rep(i,N){ A[i] = A[i]%200; } rep(i,N){ B[A[i]]++; } rep(i,200){ ans += (ll)B[i]*(B[i]-1)/2; } cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; const int N=100005; int n,a[N]; double m,p,s,t; int main() { scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]),p+=a[i]; sort(a+1,a+n+1); m=p; for(int i=1;i<=n;i++) { p-=a[i]; double s=p,t=a[i]/2.0; s+=t*(i*2-n); m=min(m,s); } printf("%.9lf\n",m/n); return 0; }
#include <cstdio> #include <cstring> using namespace std; typedef long long ll; #define ci const int inline int max(ci &x, ci &y) {return x > y ? x : y;} inline int min(ci &x, ci &y) {return x < y ? x : y;} inline void swap(int &x, int &y) {x ^= y ^= x ^= y;} inline void chmax(int &x, ci &y) { if(x < y) x = y; } inline void chmin(int &x, ci &y) { if(x > y) x = y; } #define rei register int #define rep(i, l, r) for(rei i = l, i##end = r; i <= i##end; ++ i) #define per(i, r, l) for(rei i = r, i##end = l; i >= i##end; -- i) char inputbuf[1 << 23], *p1 = inputbuf, *p2 = inputbuf; #define getchar() (p1 == p2 && (p2 = (p1 = inputbuf) + fread(inputbuf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++) inline int read() { int res = 0; char ch = getchar(); bool f = true; for(; ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = false; for(; ch >= '0' && ch <= '9'; ch = getchar()) res = res * 10 + (ch ^ 48); return f ? res : -res; } const int N = 305; int a, b, c; signed main() { a = read(); b = read(); c = read(); if(b < a) swap(a, b); if(c < a) swap(c, a); printf("%d\n", b + c); return 0; }
#include <bits/stdc++.h> using namespace std; #define N 805 #define MAX_A 1000000000 #define rep(i, n) for(int i = 0; i < n; ++i) int main(void) { int n, k, lim; int a[N][N]; int s[N][N]; rep(i, N) { s[i][0] = 0; s[0][i] = 0; } int ng = -1; int ok = MAX_A; int mid; bool ext; cin >> n >> k; lim = ((k*k) / 2) + 1; rep(i, n) { rep(j, n)cin >> a[i][j]; } while ((ng + 1) < ok) { mid = (ng + ok) / 2; rep(i, n) { rep(j, n) { s[i + 1][j + 1] = s[i + 1][j] + s[i][j + 1] - s[i][j]; if (a[i][j] > mid)s[i + 1][j + 1]++; } } ext = false; rep(i, n - k + 1) { rep(j, n - k + 1) { if ((s[i + k][j + k] + s[i][j] - s[i][j + k] - s[i + k][j]) < lim)ext = true; } } if (ext)ok = mid; else ng = mid; } cout << ok << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define endl "\n" #define ll long long #define F first #define S second #define pb push_back #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() #define read(v) for(auto &it:v) cin>>it; #define deb(x) cout << ">" << #x << '=' << x << endl; #define rep(i, n) for (ll i = 0; i < (n); i++) #define inf LLONG_MAX const ll N = 2e5 + 5; ll MOD = (ll)(1e9 + 7); vector<pair<int,int> > adj[N]; vector<int> vis(N); vector<int> value(N); int n,k; void dfs(int node,int val){ value[node]=((val>n)?1:val); vis[node]=true; for(auto it:adj[node]){ if(!vis[it.F]){ if(it.S==value[node]) dfs(it.F,value[node]+1); else dfs(it.F,it.S); } } } void solve() { cin>>n>>k; for(int i=0;i<=n;i++){ adj[i].clear(); vis[i]=false; } while(k--){ int u,v,z; cin>>u>>v>>z; adj[u].pb({v,z}); adj[v].pb({u,z}); } dfs(1,1); for(int i=1;i<=n;i++){ cout<<value[i]<<endl; } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t = 1; //cin >> t; while (t--) solve(); cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; return 0; }
#include <iostream> #include <vector> #include <algorithm> #include <string> #include <numeric> #include <utility> #include <tuple> #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__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false) template<typename T> void PPPPP(T t) { cerr << t; } template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); } #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, T b) { if (a > b) {a = b; return true; } return false; } template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; } template<typename T> void print(T a) { cout << a << '\n'; } template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(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; } }; using edge = tuple<int, int>; #include <set> int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, m; cin, n, m; UnionFind uf(n); vector<vector<edge>> tree(n); rep(i, 0, m) { int a, b, c; cin, a, b, c; a--; b--; if (!uf.Same(a, b)) { uf.Union(a, b); tree[a].emplace_back(b, c); tree[b].emplace_back(a, c); } } auto get_color = [&](int cur) { if (cur == 1) { return 2; } else { return 1; } }; vector<int> vertex(n, -1); auto rec = [&](auto &f, int cur, int prev) -> void { for (auto [nxt, color] : tree[cur]) { if (nxt == prev) continue; if (vertex[cur] == color) { vertex[nxt] = get_color(color); } else { vertex[nxt] = color; } f(f, nxt, cur); } }; rec(rec, 0, -1); set<int> s; rep(i, 0, n) { s.insert(i + 1); } for (auto [nxt, color] : tree[0]) { s.erase(color); } vertex[0] = *s.begin(); rep(i, 0, n) { print(vertex[i]); } return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; const int INF = 1001001001; const int mod = 1000000007; // rotation 90 degrees vvi rot(vvi orginal,int h,int w){ vvi v(w,vi(h)); for(int i = 0;i < h;i++){ for(int j = 0; j < w;j++){ v.at(w-j-1).at(i) = orginal.at(i).at(j); } } return v; } int main(){ int h,w,n,m; cin >> h >> w >> n >> m; vvi mas(h,vi(w,0)); vvi received(h,vi(w,0)); rep(i,n){ int a,b; cin >> a >> b; a--;b--; mas.at(a).at(b) = 1; } rep(i,m){ int c,d; cin >> c >> d; c--;d--; mas.at(c).at(d) = 2; } rep(i,4){ rep(j,h){ bool f = false; rep(k,w){ if(mas.at(j).at(k) == 2){ f = false; continue; } if(mas.at(j).at(k) == 1){ f = true; received.at(j).at(k) = 1; continue; } if(f) received.at(j).at(k) = 1; } } // cout << "h:" << h << endl; // cout << "w:" << w << endl; mas = rot(mas,h,w); received = rot(received,h,w); swap(h,w); } ll ans = 0; rep(i,h)rep(j,w) if (received.at(i).at(j)) ans++; cout << ans << endl; }
#include <iostream> using namespace std; int main() { int a,b,c,d; cin>>a>>b>>c>>d; cout<<a*d-b*c<<endl; return 0; }
#include <iostream> #include <cstdio> #include <vector> #include <unordered_set> using namespace std; class Solution{ public: double solve(int N, int M, int K, const vector<int>& A){ unordered_set<int> Aset(A.begin(), A.end()); vector<double> a(N + M, 0.0), b(N + M, 1.0); double asum = 0.0, bsum = M; for(int i = N - 1; i >= 0; i --){ if(Aset.count(i)) a[i] = 1.0, b[i] = 0.0; else a[i] = asum / M, b[i] = bsum / M + 1.0; asum -= a[i + M], asum += a[i]; bsum -= b[i + M], bsum += b[i]; } if(abs(a[0] - 1) < 1e-8) return -1; return - b[0] / (a[0] - 1.0) - 1.0; } }; int main() { int N, M, K; cin >> N >> M >> K; vector<int> A(K); for(int i = 0; i < K; i ++) cin >> A[i]; double res = Solution().solve(N, M, K, A); if(res < 0) cout << -1 << endl; else printf("%.4lf", res); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> p_ll; template<class T> void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; } #define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++) #define all(vec) vec.begin(), vec.end() #define rep(i,N) repr(i,0,N) #define per(i,N) for (ll i=(ll)N-1; i>=0; i--) const ll MOD = pow(10,9)+7; const ll LLINF = pow(2,61)-1; const ll INF = pow(2,30)-1; vector<ll> fac; void c_fac(ll x=pow(10,7)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; } ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { ll d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; } ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; } ll modpow(ll x, ll p) { ll result = 1, now = 1, pm = x; while (now<=p) { if (p&now) { result = result * pm % MOD; } now*=2; pm = pm*pm % MOD; } return result; } ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); } ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } int main() { ll N, M, K; cin >> N >> M >> K; ll A[K]; rep(i,K) cin >> A[i]; double dp[N+1][2] = {}; rep(i,K) dp[A[i]][1] = 1; double rsum[N+1][2] = {}; per(i,N) { if (dp[i][1]!=1) { dp[i][0] = (i+1+M>N?rsum[i+1][0]:rsum[i+1][0]-rsum[i+1+M][0])/M + 1; dp[i][1] = (i+1+M>N?rsum[i+1][1]:rsum[i+1][1]-rsum[i+1+M][1])/M; } rsum[i][0] = rsum[i+1][0] + dp[i][0]; rsum[i][1] = rsum[i+1][1] + dp[i][1]; } // rep(i,N+1) debug(dp[i],dp[i]+2); // rep(i,N+1) debug(rsum[i],rsum[i]+2); double result = dp[0][1]==1 ? -1 : dp[0][0]/(1-dp[0][1]); cout << setprecision(10) << result << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0; i < n; i++) #define Rep(i,n) for(int i = 1; i <= n; i++) #define sz(a) int(a.size()) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define fin(a) { cout << a << endl; return 0; } #define debug(a) { cerr << #a << ": " << a << endl; } #define endl '\n' #define fi first #define se second using lint = long long; using ld = long double; using P = pair<int,int>; using Pl = pair<lint,lint>; template<class T> using V = vector<T>; template<class T> using priq = priority_queue<T>; template<class T> using priq_inv = priority_queue<T, vector<T>, greater<T>>; const int dx[] = {0,1,0,-1,1,1,-1,-1}; const int dy[] = {1,0,-1,0,1,-1,-1,1}; template<class T> T ceil(const T &a, const T &b) { return ((a)+(b)-1)/b; } 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; } template<class T> void YesorNo(T x) { printf(x ? "Yes\n" : "No\n"); } struct INF { template<class T> operator T() { return numeric_limits<T>::max() / 2; } } INF; template<class T, class U> istream& operator>>(istream &in, pair<T,U> &p) { return in >> p.first >> p.second; } template<class T, class U> ostream& operator<<(ostream &out, const pair<T,U> &p) { return out << '{' << p.first << ',' << p.second << '}'; } template<class T> istream& operator>>(istream &in, vector<T> &v) { for(auto &&e : v) in >> e; return in; } template<class T> ostream& operator<<(ostream &out, const vector<T> &v) { for(const auto &e : v) out << e << ' '; return out; } /*----------------------------------------------------------------------------------------------------*/ struct UnionFind { // UnionFindTree vector<int> d; int group; UnionFind(int n): d(n,-1), group(n) {} int find(int x) { if(d[x] < 0) return x; return d[x] = find(d[x]); } bool unite(int x, int y) { x = find(x); y = find(y); if(x == y) return false; if(-d[x] < -d[y]) swap(x,y); group--; d[x] += d[y]; d[y] = x; return true; } bool same(int x, int y) { return find(x) == find(y); } int size(int x) { return -d[find(x)]; } }; long long Modpow(long long a, int n, long long mod){ if(n == 0) return 1; if(n%2 == 0){ long long res = Modpow(a, n/2, mod); return res * res % mod; } return a * Modpow(a, n-1, mod) % mod; } int main(){ int n; cin >> n; UnionFind uf(n); rep(i,n) { int a; cin >> a; a--; uf.unite(i,a); } cout << Modpow(2,uf.group,998244353)-1 << endl; }
#include<bits/stdc++.h> int main(){ using namespace std; unsigned long N; cin >> N; string S; cin >> S; if(S[0] != S.back())return 0 & puts("1"); for(unsigned long i{1}; i < N; ++i)if(S[0] != S[i - 1] && S[i] != S.back())return 0 & puts("2"); puts("-1"); return 0; }
//Let's join Kaede Takagaki Fan Club !! #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; #define int long long typedef long long ll; typedef pair<int,int> P; typedef pair<int,P> P1; typedef pair<P,P> P2; #define pu push #define pb push_back #define eb emplace_back #define mp make_pair #define eps 1e-7 #define INF 1000000000 #define a first #define b second #define fi first #define sc second #define rng(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define rep(i,x) for(int i=0;i<x;i++) #define repn(i,x) for(int i=1;i<=x;i++) #define SORT(x) sort(x.begin(),x.end()) #define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end()) #define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) #define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) #define all(x) x.begin(),x.end() #define si(x) (int)(x.size()) #ifdef LOCAL #define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl #else #define dmp(x) void(0) #endif template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b;return true;}else return false;} template<class t,class u> bool chmin(t&a,u b){if(b<a){a=b;return true;}else return false;} template<class t> using vc=vector<t>; template<class t,class u> ostream& operator<<(ostream& os,const pair<t,u>& p){ return os<<"{"<<p.fi<<","<<p.sc<<"}"; } template<class t> ostream& operator<<(ostream& os,const vc<t>& v){ os<<"{"; for(auto e:v)os<<e<<","; return os<<"}"; } template<class T> void g(T &a){ cin >> a; } template<class T> void o(const T &a,bool space=false){ cout << a << (space?' ':'\n'); } //ios::sync_with_stdio(false); const ll mod = 1000000007;//998244353 mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count()); template<class T> void add(T&a,T b){ a+=b; if(a >= mod) a-=mod; } ll modpow(ll x,ll n){ ll res=1; while(n>0){ if(n&1) res=res*x%mod; x=x*x%mod; n>>=1; } return res; } int n,m,w[100005]; P pp[100005]; int mx[100005]; int dist[8]; void solve(){ cin>>n>>m; rep(i,n)cin>>w[i]; rep(i,m)cin>>pp[i].b>>pp[i].a; sort(pp, pp+m); rep(i, m){ if(!i) mx[i] = pp[i].b; else mx[i] = max(mx[i-1], pp[i].b); } vc<int>p(n); rep(i,n)p[i]=i; ll ans = 1e18; do{ rep(i, n){ dist[i] = INF; } dist[n-1] = 0; vc<P>edge[8]; rep(i, n){ int W = 0; rng(j, i, n){ W += w[p[j]]; int v = lower_bound(pp, pp+m, mp(W, (ll)-INF)) - pp; v--; if(v == -1) v = 0; else v = mx[v]; edge[j].pb(mp(i, -v)); } } rep(m, n*n+5){ rep(i, n){ for(auto a:edge[i]){ if(dist[a.a] > dist[i] + a.b){ dist[a.a] = dist[i] + a.b; if(m >= n*n) goto bad; } } } } chmin(ans, -dist[0]); bad:; }while(next_permutation(all(p))); if(ans > 5e17) ans = -1; cout<<ans<<endl; } signed main(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20); int t; t = 1; //cin >> t; while(t--) solve(); }
#include<bits/stdc++.h> using namespace std; typedef long long LL; const int N=8,M=100000,INF=(1<<30)-1; int n,m,a[N+9]; struct thing{ int l,v; thing(int L=0,int V=0){l=L;v=V;} }b[M+9]; bool cmp(const thing &a,const thing &b){return a.v<b.v;} void into(){ scanf("%d%d",&n,&m); for (int i=1;i<=n;++i) scanf("%d",&a[i]); for (int i=1;i<=m;++i) scanf("%d%d",&b[i].l,&b[i].v); } int mx[M+9]; void Get_mx(){ sort(b+1,b+m+1,cmp); mx[0]=0; for (int i=1;i<=m;++i) mx[i]=max(mx[i-1],b[i].l); } int p[N+9],vis[N+9]; int dp[N+9],ans; void Get_dp(){ dp[0]=0; for (int i=1;i<=n;++i){ dp[i]=dp[i-1]; int sum=p[i]; for (int j=i-1;j>=1;--j){ sum+=p[j]; dp[i]=max(dp[i],dp[j]+mx[lower_bound(b+1,b+m+1,thing(0,sum),cmp)-b-1]); } } ans=min(ans,dp[n]); } void Dfs_ans(int k){ if (k>n){ Get_dp(); return; } for (int i=1;i<=n;++i) if (!vis[i]){ p[k]=a[i]; vis[i]=1; Dfs_ans(k+1); vis[i]=0; } } void Get_ans(){ ans=INF; int mx=a[1]; for (int i=2;i<=n;++i) mx=max(mx,a[i]); int mn=b[1].v; for (int i=2;i<=m;++i) mn=min(mn,b[i].v); if (mx>mn) return; Dfs_ans(1); } void work(){ Get_mx(); Get_ans(); } void outo(){ printf("%d\n",ans==INF?-1:ans); } int main(){ into(); work(); outo(); return 0; }
#include<bits/stdc++.h> #define N 200005 #define re register #define ll long long #define P 998244353 using namespace std; int n,m,K,q,u; inline void Rd(int &res){ re char c;res=0;bool f=0; while(c=getchar(),c<48)(c=='-')&&(f=1); do res=(res<<3)+(res<<1)+(c^48); while(c=getchar(),c>47); f&&(res=-res); } int f[25][5005]; int fac[N],fac1[N]; inline int C(int n,int m){ if(n<m)return 0; return 1ll*fac[n]*fac1[m]%P*fac1[n-m]%P; } int Pow(int x,int k){ int res=1; while(k){ if(k&1)res=1ll*res*x%P; x=1ll*x*x%P; k>>=1; } return res; } int main(){ Rd(n),Rd(m); fac[0]=1;for(re int i=1;i<N;i++)fac[i]=1ll*i*fac[i-1]%P; fac1[N-1]=Pow(fac[N-1],P-2);for(re int i=N-2;i>=0;i--)fac1[i]=1ll*(i+1)*fac1[i+1]%P; int t=1,cnt=0; while((t<<1)<=m)t<<=1,cnt++; f[cnt+2][0]=1; for(re int i=cnt+1;i>=0;i--){ int res=(1<<i); for(re int j=0;j<=n&&res*j<=m;j+=2){ for(re int k=0;k+res*j<=m;k++)if(f[i+1][k]){ f[i][res*j+k]=(f[i][res*j+k]+1ll*f[i+1][k]*C(n,j))%P; } } } printf("%d\n",f[0][m]); return 0; }
#include <iostream> #include <iomanip> #include <cstdio> #include <vector> #include <bitset> #include <string> #include <cstring> #include <map> #include <set> #include <stack> #include <queue> #include <deque> #include <utility> #include <algorithm> #include <random> #include <cmath> #include <cassert> #include <climits> #include <ctime> #include <chrono> /* #pragma GCC optimize("Ofast") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,tune=native") */ #ifdef LOCAL #define dbg(x) cout << #x << " : " << x << endl; #else #define dbg(x) #endif #define int long long #define pb push_back #define ppb pop_back() #define mp make_pair #define fi(a, b) for (int i = a; i < b; i++) #define fj(a, b) for (int j = a; j < b; j++) #define fk(a, b) for (int k = a; k < b; k++) #define fi1(a, b) for (int i = a - 1; i >= b; i--) #define fj1(a, b) for (int j = a - 1; j >= b; j--) #define fk1(a, b) for (int k = a - 1; k >= b; k--) #define fx(x, a) for (auto& x : a) #define rep(i, a, b) for (int i = a; i < b; ++i) #define rep1(i, a, b) for (int i = a - 1; i >= b; --i) #define siz(x) (int)x.size() #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() #define left leftkekmda #define right rightkekmda using namespace std; template<typename T1, typename T2>inline void mine(T1 &x, const T2 &y) { if (y < x) x = y; } template<typename T1, typename T2>inline void maxe(T1 &x, const T2 &y) { if (x < y) x = y; } template<typename T> ostream& operator << (ostream &os, const vector<T> &b) { for (auto &k : b) os << k << ' '; return os; } template<typename T> istream& operator >> (istream &is, vector<T> &b) { for (auto &k : b) is >> k; return is; } typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef char ch; typedef string str; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<pii> vpii; typedef vector<vpii> vvpii; typedef vector<ch> vch; typedef vector<vch> vvch; typedef vector<str> vs; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int N = 21; int a[N]; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; fi(0, n) cin >> a[i]; int ans = 1ll << 31; for (int mask = 1; mask < (1 << n); mask += 2) { int curb = 0; int curx = 0; for (int i = 0; i < n; ++i) { if ((mask >> i) & 1) { curx ^= curb; curb = 0; } curb |= a[i]; } curx ^= curb; mine(ans, curx); } cout << ans << '\n'; }
/* * @Author: Luisvacson * @LastEditors: Luisvacson * @Descriptions: None * @Date: 2021-05-01 20:05:46 * @LastEditTime: 2021-05-01 20:18:58 * @FilePath: \C++\Practice\B.cpp */ #include <bits/stdc++.h> using namespace std; #define MAXN 1005 int n, d1, h1; int d[MAXN], h[MAXN]; signed main() { scanf("%d%d%d", &n, &d1, &h1); register int i; double ans = -1; for (i = 1; i <= n; ++i) { scanf("%d%d", &d[i], &h[i]); int d2 = d[i], h2 = h[i]; // printf("%d %d\n%d %d\n%d %d\n", h1, h2, d1, d2, h2 - h1, d2 - d1); double k = (double)((h2 - h1) * 1.0 / (d2 - d1)); // printf("%.10lf\n", k); double b = h1 - k * d1; b = max(b, 0.0); ans = max(ans, b); } printf("%.10lf\n", ans); return 0; }
#include <vector> #include <list> #include <map> #include <set> #include <climits> #include <deque> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <ctime> #include <queue> #define rep(i,a,b) for(int i=(a);i<(b);i++) #define per(i,a,b) for(int i=(a);i>(b);i--) #define pb push_back #define ff first #define ss second #define endl '\n' #define mp make_pair #define pb push_back #define gap " " #define vi vector<int> #define ii pair<int,int> #define vii vector<ii> #define ldb long double //memset(dp,-1,sizeof(dp)) sets value to -1 of everything in dp //vector < vector<int > > vec(n,vector<int>(m,0)) here n are rows(top to down ) and m columns all with m vectors initialised with values 0 //ARRAY OF VECTORS --> vector<int> ar[size] and to pass it in a function we use foo(vector<int>(&ar)[size]) //Number of digits in N =floor(log10(N)) + 1; typedef long long ll; using namespace std; int solve(){ ldb n,D,H; cin>>n>>D>>H; ldb r=INT_MIN; rep(i,0,n) { ldb d,h; cin>>d>>h; r=max(r,(D*h-d*H)/(D-d)); } if(r<0) { cout<<0.0<<endl; return 0; } cout<<r<<endl; return 0; } int main(){ #ifndef ONLINE_JUDGE freopen("input1.txt","r",stdin); freopen("output1.txt","w",stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); int t=1; while(t--){ solve(); } return 0; }
#include<iostream> #include<vector> using namespace std; const int N = 2e5; int n; int a[N],c[N]; int main(){ cin>>n; string b; cin>>b; int minn = 1e9; for(int i=1;i<=n+1;i++) cin>>a[i], minn=min(minn,a[i]); b = " " + b; int k = -1; for(int i=10000;i>=1;i--){ int now = a[1] / i; int nxt; bool fl = true; for(int j=1;j <= n; j++){ nxt = a[j + 1] / i; if((b[j]=='<' and now >= nxt)||(b[j]=='>' and now <= nxt)){ fl = false; break; } now = nxt; } if(fl){ for(int j=1;j <= n; j++){ now = a[j] / i; nxt = a[j + 1] / i; if(b[j]=='<'){ if(a[j]%i>a[j+1]%i and nxt-now<=1) fl = false; } else{ if(a[j]%i<a[j+1]%i and now-nxt<=1) fl = false; } } if(!fl) continue; k = i; break; } } cout<<k<<'\n'; for(int i=1;i<=n+1;i++) c[i] = a[i]%k; for(int i=1;i<=k;i++){ for(int j=1;j<=n+1;j++){ if(c[j]){cout<<a[j]/k+1<<' '; c[j]--;} else cout<<a[j]/k<<' '; } puts(""); } return 0; }
#include <bits/stdc++.h> using namespace std; #ifdef __DEBUG__ void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << H; debug_out(T...);} #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) #endif using ll = long long int; inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }; template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; } template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; } template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; } ll N,X; vector<ll> A; vector<ll> coff_max; vector<ll> coff_x; inline void input(){ fast_io(); cin >> N >> X; A = fetch_vec<ll>(N); } void kuriagari(vector<ll> &y){ int n = y.size(); for (int i = 0; i < n-1; i++) { if(y[i]==coff_max[i]){ y[i] = 0; y[i+1]++; } } } int tlesolve(){ coff_x.assign(N,0); coff_max.assign(N,0); // vector<ll> coff_max.assin(N,0); coff_max[N-1] = 100; for (int i = 0; i < N-1; i++) { coff_max[i] = A[i+1]/A[i]; } for (int i = N-1; i >= 0; i--) { coff_x[i] = X/A[i]; X %= A[i]; } vector<vector<ll>> ys; ys.push_back(coff_x); for (int i = 0; i < N; i++) { vector<vector<ll>> tmp = ys; for(auto y:ys){ if(y[i]!=0 && i!=N-1){ vector<ll> ny = y; ny[i] = 0; ny[i+1]++; kuriagari(ny); tmp.push_back(ny); } } ys = tmp; } cout << ys.size() << endl; debug(coff_x); debug(coff_max); sort(ys.begin(),ys.end()); debug(ys); return 0; } int solve(){ coff_x.assign(N,0); coff_max.assign(N,0); // vector<ll> coff_max.assin(N,0); for (int i = 0; i < N-1; i++) { coff_max[i] = A[i+1]/A[i]; } ll Y = X; for (int i = N-1; i >= 0; i--) { coff_x[i] = X/A[i]; Y %= A[i]; } coff_max[N-1] = coff_x[N-1]+2; debug(coff_x); debug(coff_max); vector<map<ll,ll>> dp(N+1); dp[N][X] = 1; for (int i = N-1; i >= 0; i--) { for(auto [d,c]:dp[i+1]){ // for (int x = -coff_max[i]+1; x < coff_max[i]; x++) // { // if(abs(d-x*A[i]) < A[i]) dp[i][d-x*A[i]] += c; // } if(d > 0){ ll x = d/A[i]; if(x < coff_max[i]){ dp[i][d-x*A[i]] += c; } if(x+1 < coff_max[i]){ dp[i][d-(x+1)*A[i]] += c; } } else if(d < 0){ ll x = abs(d)/A[i]; if(abs(x) < coff_max[i]){ dp[i][d+x*A[i]] += c; } if(abs(x+1) < coff_max[i]){ dp[i][d+(x+1)*A[i]] += c; } } else{ dp[i][d] += c; } } } debug(dp); cout << dp[0][0] << endl; return 0; } int main() { input(); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int,int> pi; #define F first #define S second #define PB push_back #define MP make_pair #define fo(i,n) for(int i=0;i<n;i++) #define fos(i,n) for(ll i=0,i<n;i++) #define loop(i,a,b) for (int i = a; i < b; i++) #define loops(i,a,b) for (ll i = a; i < b; i++) void solve(){ string s; cin>>s; reverse(s.begin(),s.end()); loop(i,0,s.size()){ if(s[i]=='6'){ s[i]='9'; }else if(s[i]=='9'){ s[i]='6'; } } cout<<s<<"\n"; } int main() { ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); solve(); return 0; }
#include<bits/stdc++.h> using namespace std; int main() { long long n,m,a,b,c,d,e,f,g,h,p,q,r,fr,sc,tr,sz=0,tz,i,j,k,mx=LLONG_MIN,mn=LLONG_MAX; long long x=0,y=0,cnt=0,res=0,ans=0,sum=0; long long flg=0,flag=1,na=0,as=1; vector<long long>u,v,w; vector< pair<long long,long long> >vct; vector<string>vst; set<long long>st,nt,tt; map<long long,long long>mp,nq,qr; string str,ttr,ntr; //scanf("%lld",&n); cin>>str; sz=str.size(); char ch; reverse(str.begin(),str.end()); for(i=0;i<sz;i++) { ch=str[i]; if(ch=='6')ch='9'; else if(ch=='9')ch='6'; cout<<ch; } cout<<endl; return 0; }
#include <iostream> #include <vector> #include <algorithm> using namespace std; vector<long long> enum_divisors(long long N) { vector<long long> res; for (long long i = 1; i * i <= N; ++i) { if (N % i == 0) { res.push_back(i); // 重複しないならば i の相方である N/i も push if (N/i != i) res.push_back(N/i); } } return res; } int main() { long long S, P; cin >> S >> P; const auto &res = enum_divisors(P); for (int i = 0; i < res.size(); ++i) { long long N = res[i]; long long M = P / N; if(N + M == S) { cout << "Yes" << endl; return 0; } } cout << "No" << endl; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define pll pair<ll,ll> #define ff first #define ss second #define pb push_back #define endl "\n" const ll maxn =6e5+10; const ll mod=1e9+7; const ll base=1e18; ll cnt[maxn]; ll f[maxn]; ll get_duong(ll a,ll b) { if (b<0) return 0; ll kc=b/2; ll ans=0; if (a<=kc) { ans=ans+2*a+1; } else { ans=ans+kc+1; ll cl=b-kc*2; if (cl>=1) { ans=ans+kc+1; } else { ans=ans+kc; } } return ans; } ll get_am(ll a,ll b) { if (b<=0) return 0; ll kc=b/2; ll ans=2*kc; if (b%2==0) ans--; return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); if (fopen("t.inp","r")) { freopen("test.inp","r",stdin); freopen("test.out","w",stdout); } ll a, b; cin>> a>> b; if (a==0) { ll ans=get_am(a,b)+1; cout <<ans<<endl; } else if (a>0) { ll ans=get_duong(a,b)+get_am(a,b-1); cout <<ans<<endl; } else { ll ans=get_am(a,b)+get_duong(-a,b-1); cout <<ans<<endl; } }
#include <bits/stdc++.h> using namespace std; // 総数を1000000007(素数)で割った余り const long long mod = 1e9 + 7; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; #define ull unsigned long long #define ld long double #define vi vector<int> #define vll vector<ll> #define vc vector<char> #define vs vector<string> #define vpii vector<pii> #define vpll vector<pll> #define Graph vector<vector<int>> #define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++) #define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++) #define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--) #define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--) #define sz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define SORT(v, n) sort(v, v + n); #define VSORT(v) sort(v.begin(), v.end()); #define RSORT(x) sort(rall(x)); #define pb push_back #define mp make_pair #define INF (1e9) #define PI (acos(-1)) #define EPS (1e-7) ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; } ull lcm(ull a, ull b) { return a / gcd(a, b) * b; } const string YES = "Yes"; const string NO = "No"; int main() { long long A; scanf("%lld", &A); long long B; scanf("%lld", &B); long long C; scanf("%lld", &C); long long D; scanf("%lld", &D); ll sum = A + B + C + D; ll ab = A + B; ll ac = A + C; ll ad = A + D; ll bc = B + C; ll bd = B + D; ll cd = C + D; if ((2 * ab == sum) || (2 * ac == sum) || (2 * ad == sum) || (2 * A == sum) || (2 * B == sum) || (2 * C == sum) || (2 * D == sum)) { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0; }
/* in the name of Anton */ /* Compete against Yourself. Author - Aryan (@aryanc403) Atcoder library - https://atcoder.github.io/ac-library/production/document_en/ */ #ifdef ARYANC403 #include <header.h> #else #pragma GCC optimize ("Ofast") #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx") #pragma GCC optimize ("-ffloat-store") #include<bits/stdc++.h> #define dbg(args...) 42; #endif using namespace std; #define fo(i,n) for(i=0;i<(n);++i) #define repA(i,j,n) for(i=(j);i<=(n);++i) #define repD(i,j,n) for(i=(j);i>=(n);--i) #define all(x) begin(x), end(x) #define sz(x) ((lli)(x).size()) #define pb push_back #define mp make_pair #define X first #define Y second #define endl "\n" typedef long long int lli; typedef long double mytype; typedef pair<lli,lli> ii; typedef vector<ii> vii; typedef vector<lli> vi; const auto start_time = std::chrono::high_resolution_clock::now(); void aryanc403() { #ifdef ARYANC403 auto end_time = std::chrono::high_resolution_clock::now(); std::chrono::duration<double> diff = end_time-start_time; cerr<<"Time Taken : "<<diff.count()<<"\n"; #endif } const lli INF = 0xFFFFFFFFFFFFFFFL; lli seed; mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count()); inline lli rnd(lli l=0,lli r=INF) {return uniform_int_distribution<lli>(l,r)(rng);} class CMP {public: bool operator()(ii a , ii b) //For min priority_queue . { return ! ( a.X < b.X || ( a.X==b.X && a.Y <= b.Y )); }}; void add( map<lli,lli> &m, lli x,lli cnt=1) { auto jt=m.find(x); if(jt==m.end()) m.insert({x,cnt}); else jt->Y+=cnt; } void del( map<lli,lli> &m, lli x,lli cnt=1) { auto jt=m.find(x); if(jt->Y<=cnt) m.erase(jt); else jt->Y-=cnt; } bool cmp(const ii &a,const ii &b) { return a.X<b.X||(a.X==b.X&&a.Y<b.Y); } const lli mod = 1000000007L; // const lli maxN = 1000000007L; lli T,n,i,j,k,in,cnt,l,r,u,v,x,y; lli m; string s; vi a; //priority_queue < ii , vector < ii > , CMP > pq;// min priority_queue . int main(void) { ios_base::sync_with_stdio(false);cin.tie(NULL); // freopen("txt.in", "r", stdin); // freopen("txt.out", "w", stdout); // cout<<std::fixed<<std::setprecision(35); // cin>>T;while(T--) { n=4; a.clear();a.reserve(n); fo(i,n) { cin>>in; a.pb(in); } for(lli msk=1;msk<(1LL<<n);++msk){ lli sum=0; fo(i,n){ if(msk&(1LL<<i)) sum+=a[i]; else sum-=a[i]; } if(sum==0){ cout<<"Yes"<<endl; return 0; } } cout<<"No"<<endl; } aryanc403(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int sz = 2e5+5; typedef pair <int,int> pii; #define x first #define y second int csub[sz], dp[sz]; vector <int> g[sz]; void dfs(int u) { csub[u] = dp[u] = 1; vector <pii> od, ev; for(int v : g[u]) { dfs(v); csub[u] += csub[v]; if(csub[v] & 1) od.emplace_back(csub[v] - 2 * dp[v], v); else ev.emplace_back(csub[v] - 2 * dp[v], v); } sort(od.begin(), od.end(), greater<pii>()); sort(ev.begin(), ev.end(), greater<pii>()); int ei = 0, oi = 0; for(; ei<ev.size(); ei++) { auto v = ev[ei].y; if(csub[v] - dp[v] > dp[v]) dp[u] += dp[v]; else break; } for(; oi<od.size(); oi++) { auto v = od[oi].y; if(oi & 1) dp[u] += csub[v] - dp[v]; else dp[u] += dp[v]; } for(; ei<ev.size(); ei++) { auto v = ev[ei].y; if(oi & 1) dp[u] += csub[v] - dp[v]; else dp[u] += dp[v]; } } int main() { int n; cin >> n; for(int i=2; i<=n; i++) { int j; scanf("%d", &j); g[j].push_back(i); } dfs(1); cout << dp[1]; }
#include<algorithm> #include<iostream> #include<cmath> #include<vector> using namespace std; int N; int X[200][3],Ans[200][4]; int G2[10000][10000]; vector<vector<int>>G(10001); vector<vector<int>>X_vec; int scoring(vector<vector<int>>&ans){ double ref=0; for(int i=0;i<N;++i){ if(ans[i][0]<=X[i][0] && X[i][0]<ans[i][2] && ans[i][1]<=X[i][1] && X[i][1]<ans[i][3]){ int S=(ans[i][2]-ans[i][0])*(ans[i][3]-ans[i][1]); ref+=1.0-powf(1.0-(double)min(X[i][2],S)/(double)max(X[i][2],S),2); } } ref/=(double)N; return (int)(1000000000*ref); } bool overlap(int id,int a,int b,int c,int d){ for(int i=0;i<N;++i)if(i!=id){ int x1=Ans[i][0]; int y1=Ans[i][1]; int x2=Ans[i][2]; int y2=Ans[i][3]; if(max(a,x1)<min(x2,c) && max(b,y1)<min(y2,d)){ //cout<<"over "<<a<<" "<<x2<<" "<<b<<" "<<y2<<" "<<c<<" "<<x1<<" "<<d<<" "<<y1<<endl; return true; } } return false; } void greedy(){ int a,b,c,d,id; //面積でソート //{id,x,y,r} sort(X_vec.rbegin(),X_vec.rend(),[](const vector<int>&a,const vector<int>&b){return a[3]<b[3];}); //初期解の生成 for(int n=0;n<N;++n){ id=X_vec[n][0]; a=X_vec[n][1]; b=X_vec[n][2]; c=a+1; d=b+1; //答えを記録 Ans[id][0]=a; Ans[id][1]=b; Ans[id][2]=c; Ans[id][3]=d; } //どこまで広げられるか見ていく for(int n=0;n<N;++n){ id=X_vec[n][0]; a=Ans[id][0]; b=Ans[id][1]; c=Ans[id][2]; d=Ans[id][3]; //右斜め上方向に伸ばす int c1=c; int b1=b; while(!overlap(id,a,b1,c1,d) && c1<10000 && b1>0){ --b1; ++c1; } //cout<<"1: "<<b<<" "<<b1<<" "<<c<<" "<<c1<<endl; //右斜め下方向に伸ばす int c2=c; int d1=d; while(!overlap(id,a,b,c2,d1) && c1<10000 && d1<10000){ ++c1; ++d1; } if(c!=c1)--c1; if(d!=d1)--d1; //cout<<"2: "<<c<<" "<<c2<<" "<<d<<" "<<d1<<endl; //左斜め上方向に伸ばす int a1=a; int b2=b; while(!overlap(id,a1,b2,c,d) && a1>0 && b2>0){ --a1; --b2; } if(a!=a1)++a1; if(b!=b2)++b2; //cout<<"3: "<<a<<" "<<a1<<" "<<b<<" "<<b2<<endl; //左斜め下方向に伸ばす int a2=a; int d2=d; while(!overlap(id,a2,b,c,d2) && a2>0 && d2<10000){ --a2; ++d2; } if(a!=a2)++a2; if(d!=d2)--d2; //cout<<"4: "<<a<<" "<<a2<<" "<<d<<" "<<d2<<endl; //cout<<a1<<" "<<a2<<" "<<b1<<" "<<b2<<" "<<c1<<" "<<c2<<" "<<d1<<" "<<d2<<endl; a=max(a1,a2); b=max(b1,b2); c=min(c1,c2); d=min(d1,d2); //答えを記録 Ans[id][0]=a; Ans[id][1]=b; Ans[id][2]=c; Ans[id][3]=d; } } int main(){ //入力 cin>>N; int x,y,r; for(int i=0;i<N;++i){ cin>>X[i][0]>>X[i][1]>>X[i][2]; X_vec.push_back({i,X[i][0],X[i][1],X[i][2]}); G[X[i][0]].push_back(X[i][1]); G2[X[i][0]][X[i][1]]=1; } for(int i=0;i<N;++i)sort(G[i].begin(),G[i].end()); //アイディア //希望する点の座標を隣接リストで保持する //for debug //for(int i=0;i<n;++i)cout<<X_vec[i][3]<<endl; greedy(); //出力 for(int i=0;i<N;++i)cout<<Ans[i][0]<<" "<<Ans[i][1]<<" "<<Ans[i][2]<<" "<<Ans[i][3]<<endl; }
#include<bits/stdc++.h> #define haiyaku ios::sync_with_stdio(false), cin.tie(NULL); #define PB push_back #define F first #define S second #define mp make_pair #define all(x) x.begin(), x.end() #define int long long //#define double long double const int MINI = -2147483647; const int MAXI = 2147483647; const long long MAXLL = 9223372036854775807ll / 4; const long long MINLL = -9223372036854775807ll / 4; using namespace std; using pii = pair<int, int>; using pll = pair<long long, long long>; bitset<50001> dp; signed main () { ios::sync_with_stdio(false), cin.tie(NULL); int N; cin >> N; vector<int> t(N); for(int &X : t) cin >> X; dp[0] = true; int sum = accumulate(all(t), 0ll); for(int V : t) { for(int i = sum / 2; i >= V; i--) if (dp[i - V]) dp[i] = true; } for(int i = sum / 2; i >= 0; i--) { if (dp[i]) { cout << sum - i << '\n'; return 0; } } return 0; }
#include<bits/stdc++.h> typedef long long ll; #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define endl "\n" #define pb push_back #define lsb(x) ((x) & (-x)) #define PI acos(-1) #define line cout << endl; #define getbit(n, i) (((n) & (1LL << (i))) != 0) #define resetbit(n, i) ((n) & (~(1LL << (i)))) #define setbit(n, i) ((n) | (1LL << (i))) #define togglebit(n, i) ((n) ^ (1LL << (i))) const ll mod = (ll) 1e9+7; using namespace std; int32_t main() { IOS #ifdef gm freopen("int.txt", "r", stdin); #endif int n; cin >> n; int sum = 0; bitset<100005 >dp; dp[0] =1; for(int i= 0;i<n;i++) { int f; cin >> f; sum += f; dp |= dp << f; } int res= sum; for(int i=0;i< sum+1 ;i++) { if(dp[i]) res = min(res, max(i, sum - i)); } cout << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long int; void tc(){ int n; cin >> n; string s; cin >> s; int ans = 0; for (int i=0; i<n; i++){ int a = 0, t = 0, c = 0, g = 0; for (int j=i; j<n; j++){ if (s[j] == 'A') a++; if (s[j] == 'T') t++; if (s[j] == 'G') g++; if (s[j] == 'C') c++; if (a == t and g == c) ans++; } } cout << ans << endl; } int main(){ int t = 1; while(t--) tc(); return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for(int i = 0; i < n; i++) #define FOR(i, m, n) for(int i = m; i < n; i++) #define ALL(x) (x).begin(),(x).end() #define SIZE(x) ((ll)(x).size()) #define MAX(x) *max_element(ALL(x)) #define MIN(x) *min_element(ALL(x)) #define INF 1e9 typedef long long ll; typedef long double ld; int main(){ ll n; string s; cin>>n>>s; vector<vector<ll>> v(n+1,vector<ll> (4)); vector<char> w={'A','T','C','G'}; REP(i,n){ REP(j,4)if(s[i]==w[j])v[i+1][j]++; } ll cnt=0; FOR(i,1,n+1){ REP(j,4){ v[i][j]+=v[i-1][j]; } } REP(i,n){ FOR(j,i+1,n+1){ ll a=v[j][0]-v[i][0], t=v[j][1]-v[i][1], c=v[j][2]-v[i][2], g=v[j][3]-v[i][3]; if(a==t&&c==g)cnt++; } } cout<< cnt <<endl; return 0; }
/* “The only way that we can live is if we grow. The only way we can grow is if we change. The only way we can change is if we learn. The only way we can learn is if we are exposed. And the only way that we are exposed is if we throw ourselves into the open.” *************************************** ************************ ********************************** */ #include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/tree_policy.hpp> #include <functional> // for less using namespace __gnu_pbds; typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> data_set; #define fbo find_by_order #define ook order_of_key //---------------------mishra ka idea------------------ #define int long long #define double long double #define pb push_back #define pf push_front #define pii pair<int,int> #define vi vector<int> #define vii vector<pii> #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() #define x first #define y second #define endl '\n' #define sz(x) (int)(x).size() #define ull unsigned long long //------------------------mishra ka idea------------------- //-------------------------alsi hu mai----------------------- #define fo(i,l,u) for(i=l;i<u;i++) #define rfo(i,l,u) for(i=l;i>=u;i--) #define allfo(s) for(auto it=(s).begin();it!=(s).end();it++) #define _init(b) memset(b,-1,sizeof(b)) #define _init0(b) memset(b,0,sizeof(b)) #define MOD 1000000007 #define hell 998244353 #define output(x) cout << (x ? "YES" : "NO")<<endl; #define Output(x) cout << (x ? "Yes" : "No")<<endl; //-------------------------alsi hu mai----------------------- //--------------------het se uthaya--------------------- #define MOD2 (998244353) #define MOD3 (1000000009) #define PI acos(-1) #define eps (1e-8) #define INF (1e18) template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";} template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;} template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;} template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;} ifstream cinn("in.txt");ofstream coutt("out.txt"); int poww(const int &a,int b,const int &m=MOD){if(b==0)return 1;int x=poww(a,b/2,m);x=x*x%m;if(b&1)x=x*a%m;return x;} //--------------------het se uthaya------------------------------------------------------------------- int gcd(int a, int b) {if(a>b)swap(a,b) ; if (a == 0) return b; return gcd(b % a, a); } int rint(int l , int r){return rand()%(r-l+1) + l ;} //---------------------------aab code dekho bahut template dekh liya--------------------------------- signed main() { //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); int i,j,x,t,n; cin>>n; string s; cin>>s; //int n = s.length(); int pref[n+1] , pref1[n+1]; pref[0]=0; pref1[0]=0; int c1 = 0 , c2 = 0; fo(i,0,n){ if(s[i]=='A'){ c1++; } if(s[i]=='T'){ c1--; } if(s[i]=='G'){ c2++; } if(s[i]=='C'){ c2--; } pref[i+1]=c1; pref1[i+1]=c2; } int ans = 0; fo(i,1,n+1){ // cout<<pref[i]<<" "<<pref1[i]<<"<<<"<<endl; fo(j,i+1,n+1){ // cout<<pref[j]-pref[i-1]<<" "<<pref1[j]-pref1[i-1]<<endl; if((pref[j]-pref[i-1]==0 )&& (pref1[j]-pref1[i-1]==0))ans++; } } cout<<ans<<endl; return 0; } //----------------abc tez kar liya iska matlab ye nahi tum legend ho kya pata hagdo aage ------------------
using namespace std; #define visual #ifdef visual #include <iostream> #include <fstream> #include <vector> #include <queue> #include <algorithm> #include <set> #include <map> #include <assert.h> #include <functional> #include <math.h> #include <string> #include <ctime> #endif #ifndef visual #include <bits/stdc++.h> #endif typedef long long ll; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); map<pair<int, int>, int> m; int x = 0; int y = 0; int n; string s; cin >> n >> s; ll ans = 0; m[{0, 0}] = 1; for (char c : s) { if (c == 'C') x--; if (c == 'G') x++; if (c == 'A') y--; if (c == 'T') y++; ans += m[{x, y}]; m[{x, y}]++; } cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define rrep(i, n) for(int i = 1; i <= (int)(n); i++) #define drep(i, n) for(int i = (n)-1; i >= 0; i--) #define ALL(x) (x).begin(), (x).end() #define dup(x,y) (((x)+(y)-1)/(y)) #define srep(i,s,t) for (int i = s; i < t; ++i) using namespace std; typedef long long ll; typedef pair<int, int> P; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; const ll LINF = 1001002003004005006ll; const int INF = 1001001001; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const int mod = 1000000007; // const int mod = 998244353; string s; int n; int ans = INF; bool is3(string t) { int now = 0; rep(i, t.size()) now += t[i] - '0'; return now%3 == 0; } void func(string t, int i) { if (i == n) { if (is3(t)) ans = min(ans, n - (int)t.size()); return; } func(t+s[i], i+1); func(t, i+1); } int main() { cin >> s; n = s.size(); string t = ""; func(t, 0); if (ans >= n) ans =-1; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define P pair<ll,ll> #define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I) #define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I) #define TO(x,t,f) ((x)?(t):(f)) #define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9 #define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v x is sorted #define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v x is sorted #define NUM(x,v) (POSU(x,v)-POSL(x,v)) //x is sorted #define REV(x) (reverse(x.begin(),x.end())) //reverse ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);} ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*b);} #define NEXTP(x) next_permutation(x.begin(),x.end()) const ll INF=ll(1e16)+ll(7); const ll MOD=1000000007LL; #define out(a) cout<<fixed<<setprecision((a)) //tie(a,b,c) = make_tuple(10,9,87); #define pop_(a) __builtin_popcount((a)) ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;} int main(){ ll N; cin >> N; vector<ll> X(N),Y(N),Z(N); FOR(i,0,N) cin >> X[i] >> Y[i] >> Z[i]; ll dp[1LL<<N][N]; FOR(i,0,(1<<N))FOR(j,0,N){ dp[i][j] = INF; } dp[0][0] = 0; FOR(s,0,(1<<N)){ FOR(j,0,N){//now FOR(k,0,N){//to ll c = abs(X[j]-X[k])+abs(Y[j]-Y[k])+max(0LL,Z[k]-Z[j]); dp[s|(1<<k)][k] = min( dp[s|(1<<k)][k] , dp[s][j]+c ); } } } cout << dp[(1<<N)-1][0] << endl; }
#include<bits/stdc++.h> using namespace std; #define ll long long // Reused : hackerearth.com/submission/48716644/ const int N = 5e5+5; int t, n, m; int arr[N], bit[N] = {}; void update(int i, int val) { for( ; i <= m; i += (i&-i) ) { bit[i] += val; } } int get(int i) { int res = 0; for( ; i; i -= (i&-i) ) { res += bit[i]; } return res; } void clear() { memset(bit, 0, sizeof(bit)); } int main() { t=1; while(t--) { scanf("%d", &n); m = 0; for( int i = 0; i < n; i++ ) { scanf("%d", &arr[i]); ++arr[i]; m = max(m, arr[i]); } clear(); ll tot = 0; int rem[N], add[N]; for( int i = n-1; i >= 0; i-- ) { rem[i] = get(arr[i]-1); add[i] = n-i-1-get(arr[i]); tot += 1LL*rem[i]; update(arr[i], 1); } clear(); ll res = tot; cout<<tot<<endl; for( int i = 0; i < n-1; i++ ) { int r = get(arr[i]-1); int a = i-get(arr[i]); tot += 1LL*(a-r+add[i]-rem[i]); cout<<tot<<endl; res ^= tot; // cout<<add[i]<<" "<<rem[i]<<" "<<tot<<endl;; update(arr[i], 1); } } return 0; }
#pragma GCC optimize("O2") #include <bits/stdc++.h> namespace IN { #define BUF_SIZE 1 << 17 static char buf[BUF_SIZE], *fs = buf, *ft = buf; inline int nc() { return fs == ft && (ft = (fs = buf) + fread(buf, 1, BUF_SIZE, stdin), fs == ft) ? EOF : *fs++; } template <typename T> inline int rn(T &x) { x = 0; int f = 0; char ch = nc(); while (ch < '0' || ch > '9') { if (ch == '-') f = 1; ch = nc(); if (ch == EOF) return EOF; } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - 48; ch = nc(); } x = f ? -x : x; return 0; } template <typename T> inline int read(T &x) { return rn(x); } template <typename T, typename... Args> inline int read(T &x, Args &...args) { rn(x); return read(args...); } #undef BUF_SIZE } // namespace IN using namespace IN; using namespace std; #define SIZE 300010 #define HINF 0x3f3f3f3f #define LL long long #define PLL pair<LL, LL> #define PII pair<int, int> #define MP make_pair #define FI first #define SE second #define PB push_back #define ALL(A) A.begin(), A.end() #define LOWBIT(x) (x & (-x)) #define BPQ(type, name) priority_queue<type> name #define SPQ(type, name) priority_queue<type, vector<type>, greater<type>> name #define REP(i, n) for (LL i = 0; i < (LL)n; ++i) #define REP1(i, n) for (LL i = 1; i <= (LL)n; ++i) #define REP_R(i, a, b) for (LL i = (LL)a; i < (LL)b; ++i) #define REP_RR(i, a, b) for (LL i = (LL)a; i >= (LL)b; --i) #define SETVAL(array, val) memset(array, val, sizeof(array)) // Graph typedef struct { LL w; } E_elem; #define GRAPH(name, vertex_sz, edge_sz) \ struct { \ int VERTEX, NEXT; \ E_elem ELEM; \ } name##_E[edge_sz]; \ int name##_H[vertex_sz]; \ int name##_EDGE_NUM = 0 #define ADD_EDGE(name, u, v, elem) \ do { \ name##_E[++name##_EDGE_NUM].VERTEX = v; \ name##_E[name##_EDGE_NUM].ELEM = elem; \ name##_E[name##_EDGE_NUM].NEXT = name##_H[u]; \ name##_H[u] = name##_EDGE_NUM; \ } while (0) #define FE_V(name, v) for (int name##_EN = name##_H[v]; name##_EN; name##_EN = name##_E[name##_EN].NEXT) #define CURR_EN(name) name##_EN #define REV_EN(name) (name##_EN ^ 1) #define CURR_V(name) name##_E[name##_EN].VERTEX #define CURR_ELEM(name) name##_E[name##_EN].ELEM // Debug #define DISP(arr, n) \ REP(i, n) printf("%d ", arr[i]); \ cout << endl; #define DISP1(arr, n) \ REP1(i, n) printf("%d ", arr[i]); \ cout << endl; #define DISP_TD(arr, n, m) \ REP(i, n) { \ REP(j, m) printf("%d ", arr[n][m]); \ printf("\n"); \ } #define DISP_TD1(arr, n, m) \ REP1(i, n) { \ REP1(j, m) printf("%d ", arr[n][m]); \ printf("\n"); \ } LL n; LL a[SIZE]; LL b[SIZE]; LL c[SIZE]; LL get(LL x, LL *arr) { LL ans = 0; for (; x; x -= LOWBIT(x)) ans += arr[x]; return ans; } void add(LL x, LL y, LL *arr) { for (; x <= n; x += LOWBIT(x)) arr[x] += y; } int main() { read(n); REP(i, n) read(a[i]), a[i] += 1; LL ans = 0; vector<LL> v; REP_RR(i, n - 1, 0) { add(a[i], 1, b); LL x = get(a[i] - 1, b); ans += x; v.PB(x); } vector<LL> v1; REP(i, n) { add(a[i], 1, c); LL x = get(a[i] - 1, c); v1.PB(x); } REP(i, n) { cout << ans << endl; ans += n - 1 - 2 * v[n - i - 1] - 2 * v1[i]; } return 0; }
#include<bits/stdc++.h> // #include<iostream> // #include<algorithm> // #include<vector> // #include<set> // #include<queue> // #include<map> using namespace std; #define ll long long #define ld long double #define For(n) for(ll i=0;i<n;i++) #define Forr(a,b) for(ll i=a;i<b;i++) #define sortt(x) sort(x.begin(),x.end()) #define rsortt(x) sort(x.rbegin(),x.rend()) #define condsortt(x) sort(x.begin(),x.end(),sortBy) #define MOD 1000000007 #define en "\n" #define F first #define S second #define input(x,n) for(ll i=0;i<n;i++) cin>>x[i] #define v(A,n) vector<ll> A(n) #define vi(x) vector<ll> x #define pb(x) push_back(x) #define MP make_pair #define PI 3.14159265 void print(vector<ll> vec) { for(auto itr:vec) cout<<itr<<" "; cout<<en; } void solve() { ll n; cin>>n; v(A,n); input(A,n); vector<ll> vec[n+1]; For(n) { ll a;cin>>a; vec[a].pb(i); } v(mp,n); For(n) { ll a;cin>>a; mp[a-1]++; } ll ans = 0; map<ll,ll> kk; For(n) { ll ch = A[i]; if(kk.find(ch)!=kk.end()) { ans+=kk[ch]; continue; } int zz=0; for(auto j:vec[ch]) { zz+=mp[j]; } ans+=zz; kk[ch]=zz; } cout<<ans<<en; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll t=1; // cin>>t; for(ll i=1;i<=t;i++) { // cout<<"Case #"<<i<<": "; solve(); } return 0; }
#include<bits/stdc++.h> #define ll long long #define pb push_back #define mod 1000000007 #define pdd pair<double,double> #define pii pair<ll,ll> #define fi first #define sec second #define MAXN 1000000000000000005 #define N 300005 #define lgn 20 using namespace std; #define TRACE #ifdef TRACE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char* name, Arg1&& arg1){ cout << name << " : " << arg1 << std::endl; //use cerr if u want to display at the bottom } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...); } #else #define trace(...) #endif int main() { ios::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif //Type Your Code Here ll n; pair<ll,pii> apx[100000]; cin>>n; for(ll i=0;i<n;i++) { ll a,p,x; cin>>a>>p>>x; apx[i] = {p,{a,x}}; } sort(apx,apx+n); ll ans = -1; for(ll i=0;i<n;i++) { ll a,p,x; a = apx[i].sec.fi; p = apx[i].fi; x = apx[i].sec.sec; if(a<x) { ans = p; break; } } cout<<ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define IOS ios::sync_with_stdio(false); cin.tie(0); #define FOR(i,s,n) for(int i = (s); i < (n); i++) #define REP(i,n) FOR(i,0,n) #define RREP(i,n) for(int i = (n); i >= 0; i--) #define ALL(n) (n).begin(), (n).end() #define RALL(n) (n).rbegin(), (n).rend() #define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n'; #define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n'; #define OUT(n) cout << (n) << '\n'; using ll = long long; using ull = unsigned long long; using pii = pair<int,int>; using pll = pair<ll,ll>; constexpr int MOD = 1000000007; int mod(const ll &x){ return x > 0 ? x % MOD : (x % MOD + MOD) % MOD; } int modm(const ll &x,const ll &m){ return (x % MOD) * (m % MOD) % MOD; } int modpow(ll x, ll p) { int ret = 1; while(p > 0) { if (p & 1) ret = modm(ret,x); x = modm(x,x); p >>= 1; } return ret; } // x * modinv(d) int modd(ll x,ll d) { return modm(x,modpow(d,MOD-2)); } int main(void) { IOS int n, p; cin >> n >> p; OUT(modm(p-1,modpow(p-2,n-1))) return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; static const ll MOD = 1e9 + 7; // 繰り返し自乗法(x^nをmで割った余り) O(logn) ll power(ll x, ll n, ll m) { ll res = 1; if (n > 0) { res = power(x, n / 2, m); if (n % 2 == 0) res = (res * res) % m; else res = ((res * res % m) * x) % m; } return res; } int main() { ll n, p; cin >> n >> p; if (n == 1) { cout << p - 1 << '\n'; return 0; } cout << power(p - 2, n - 1, MOD) * (p - 1) % MOD << '\n'; }
// “Alhamdulillah for Everything” #include<bits/stdc++.h> using namespace std; #define pai acos(-1) #define ff first #define ss second #define ll long long #define pb push_back #define mp make_pair #define pll pair<ll,ll> #define sz(a) (ll)a.size() #define endl "\n" #define gcd(a, b) __gcd(a, b) #define lcm(a, b) ((a*b)/gcd(a,b)) #define all(vec) vec.begin(),vec.end() #define ms(a, b) memset(a,b,sizeof(a)) #define rep(i,n) for(int i= 0; i < int(n); i++) #define rep1(i,n) for(int i= 1; i <= n; i++) #define TEST_CASE(t) for(int zz=1;zz<=t;zz++) #define PRINT_CASE printf("Case %d: ",zz) #define fii freopen("input.txt","r",stdin); #define foo freopen("output.txt","w",stdout); #define boom ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL); const ll M = 1e9+7; const ll mxn = 1e5+7; const ll inf = 1e18; int main() { ll i,j,k,a,b,c,d,n,m,t,x,y,z,u,v; cin>>n; ll ans=0; for(i=1;((i*(i+1))/2)<=n;i++) { a=n; a-=(i*(i+1))/2; if(a%i==0) { ans+=1; } } ans<<=1; cout<<ans<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define LL long long #define pb push_back LL n; LL F[91]; vector<int> seq; vector<int> ans; int main() { cin>>n; F[1]=F[2]=1; for(int i=3;i<=90;i++) F[i]=F[i-1]+F[i-2]; for(int i=90;i>=1;i--) if(n>=F[i]) n-=F[i],seq.pb(1); else if(seq.size()) seq.pb(0); reverse(seq.begin(),seq.end()); seq.pop_back(); reverse(seq.begin(),seq.end()); int P=seq.size()&1; ans.pb(1+P); for(int i=0;i<seq.size();i++) { P=1-P; ans.pb(3+P); if(seq[i]) ans.pb(1+P); } cout<<ans.size()<<'\n'; for(int i=0;i<ans.size();i++) cout<<ans[i]<<'\n'; return 0; }
#include <bits/stdc++.h> //#include <atcoder/modint> //#include <atcoder/math> //#include <boost/multiprecision/cpp_int.hpp> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> #pragma GCC optimize("O3") #define REP(i, n) for(int i = 0; i < n; i++) #define REPP(i, n) for(int i = 1; i <= n; i++) #define ALL(obj) (obj).begin(), (obj).end() #define EPS (1e-9) #define INF (1e17) #define PI (acos(-1)) //const double PI = acos(-1); //const double EPS = 1e-15; //long long INF=(long long)1E17; #define i_7 (long long)(1e9+7) //#define i_7 998'244'353 long mod(long a){ long long c = a % i_7; if(c >= 0) return c; return c + i_7; } long long po(long a, long b){ if(b == 0) return 1; long long z = po(a , b / 2); z = mod(z * z); if(b % 2 != 0) z = mod(a * z); return z; } bool prime_(int n){ if(n == 1){ return false; }else if(n == 2){ return true; }else{ for(int i = 2; i <= std::sqrt(n); i++) if(n % i == 0) return false; return true; } } long long gcd_(long long a, long long b){ if(a < b) std::swap(a,b); if(a % b == 0) return b; else return gcd_(b, a % b); } long long lcm_(long long x, long long y){ return (x / gcd_(x,y)) * y; } using namespace std; //using namespace atcoder; //using mint = modint1000000007; //using mint = modint998244353; //using namespace boost::multiprecision; //using namespace __gnu_pbds; vector<int> a; vector<vector<int>> G; vector<int> dp; const int limit = -(1e9 + 100); int dfs(int v){ if(dp[v] != limit) return dp[v]; int res = limit; for(int nv: G[v]){ res = max(res, a[nv]); res = max(res, dfs(nv)); } return dp[v] = res; } int main(){ //using namespace std; int n, m; cin>>n>>m; a.resize(n); REP(i, n) cin>>a[i]; G.resize(n); int x[m], y[m]; REP(i, m){ cin>>x[i]>>y[i]; x[i]--; y[i]--; } REP(i, m) G[x[i]].push_back(y[i]); dp.resize(n, limit); int ans = limit; for(int i = n - 1; i >= 0; i--){ int temp = dfs(i) - a[i]; ans = max(ans, temp); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 2e5+2; int nums1[N]; int nums[N]; //进入i的最小值 bool vis[N]; int n,m,x,y; int main() { cin>>n>>m; for(int i=1;i<=n;i++){ cin>>nums1[i]; nums[i] = 1e9; } vector<pair<int,int>> vp; for(int i=0;i<m;i++){ cin>>x>>y; vp.emplace_back(make_pair(x,y)); } sort(vp.begin(),vp.end()); for(int i=0;i<m;i++){ int st = vp[i].first; int end = vp[i].second; nums[end] = min(nums[end],min(nums[st],nums1[st])); vis[end] = 1; //cout<<st<<" "<<end<<" "<<nums[end]<<endl; } int res = -1e9; for(int i=1;i<=n;i++){ //cout<<i<<" "<<nums1[i]-nums[i]<<" "<<vis[i]<<endl; if(vis[i]) { res = max(res,nums1[i]-nums[i]); } } cout<<res<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; const ll MOD = 1e9+7; const ll INF = 1e18; #define rep(i,m,n) for(ll i = (m); i <= (n); i++) #define zep(i,m,n) for(ll i = (m); i < (n); i++) #define rrep(i,m,n) for(ll i = (m); i >= (n); i--) #define print(x) cout << (x) << endl; #define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl; ll n, l, a[100008], b[100008]; int main(){ cin.tie(0); ios::sync_with_stdio(false); cin >> n >> l; rep(i, 1, n)cin >> a[i]; rep(i, 1, n)cin >> b[i]; a[0] = 0; b[0] = 0; a[n + 1] = l + 1; b[n + 1] = l + 1; n += 2; vector<ll> f; zep(i, 0, n)if(a[i] == b[i])f.push_back(i); ll m = f.size(); ll ans = 0; zep(i, 0, m - 1){ ll B = f[i]; bool flag = false; rep(j, f[i] + 1, f[i + 1] - 1){ if(b[j] < a[j]){ if(flag){print(-1) return 0;} B = j; }else{ flag = true; } } map<ll, ll> L; L[b[f[i]] - f[i]] = f[i]; rep(j, f[i] + 1, B){ if(L.find(b[j] - j) == L.end()){ print(-1) return 0; }else{ ans += j - L[b[j] - j]; L[b[j] - j] = j; } L[a[j] - j] = j; } //print(ans) map<ll, ll> R; R[b[f[i + 1]] - f[i + 1]] = f[i + 1]; rrep(j, f[i + 1] - 1, B + 1){ if(R.find(b[j] - j) == R.end()){ print(-1) return 0; }else{ ans += R[b[j] - j] - j; R[b[j] - j] = j; } R[a[j] - j] = j; } //print(ans) } print(ans) return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; typedef vector<ll> vl; typedef vector<bool> vb; typedef vector<string> vs; typedef vector<char> vc; typedef queue<ll> ql; typedef deque<ll> dql; typedef priority_queue<ll> pql; typedef set<ll> sl; typedef pair<ll, ll> pl; typedef vector<vl> vvl; typedef vector<pl> vpl; #define rep(i, n) for(ll i = 0; i < ll(n); i++) #define rep2(i, k, n) for(ll i = ll(k); i <= ll(n); i++) #define rep3(i, n, k) for(ll i = ll(n); i >= ll(k); i--) #define all(v) (v).begin(), (v).end() ll mod(ll a, ll b) {if(b == 0) return 0; return (a % b + b) % b;} bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;} bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;} const ll INF = 1LL << 60; const ll MOD = 1e9 + 7; //const ll MOD = 998244353; const ll MAX = 1e5; const char newl = '\n'; ll n, l; bool t=1; vl a(MAX+2), b(MAX+2), d(MAX+2); ll go_right(ll L, ll r) { ll cnt = 0; rep2(l, L, r-1) { if(a[l] == b[l]) continue; ll from=l, to=r; while(to-from>1) { ll m = (from + to)/2; if(b[l] <= a[m] - m + l) to = m; else from = m; } if(b[l] != a[to] - to + l) {t=0; return 0;} rep2(i, l, to-1) a[i] = a[to] - to + i; cnt += to - l; } return cnt; } ll go_left(ll l, ll R) { ll cnt = 0; rep3(r, R, l+1) { if(a[r] == b[r]) continue; ll from=l, to=r; while(to-from>1) { ll m = (from + to)/2; if(b[r] >= a[m] - m + r) from = m; else to = m; } if(b[r] != a[from] - from + r) {t=0; return 0;} rep3(i, r, from+1) a[i] = a[from] - from + i; cnt += r - from; } return cnt; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> l; a[0] = 0; a[n+1] = l+1; b[0] = 0; b[n+1] = l+1; rep2(i, 1, n) cin >> a[i]; rep2(i, 1, n) cin >> b[i]; rep(i, n+2) d[i] = b[i] - a[i]; rep2(i, 1, n-1) if(d[i] > 0 && d[i+1] < 0) {cout << -1 << newl; return 0;} ll ans=0; for(ll r=0; r<=n+1;) { if(d[r]==0) r++; ll l=r; if(d[r]>0) { while(d[r]>0) r++; ans += go_right(l, r); } if(d[r]<0) { while(d[r]<0) r++; ans += go_left(l-1, r-1); } if(!t) { cout << -1 << newl; return 0; } } cout << ans << newl; return 0; }
#include <bits/stdc++.h> #include <chrono> using namespace std; using namespace chrono; typedef long long int ll; typedef vector<int> vii; typedef vector<ll> vll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; #define pb push_back #define odd(x) ((x)&1) #define even(x) (!odd(x)) #define all(v) (v).begin(),(v).end() #define rep(i,n) for(auto i=0;i<n;++i) #define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define TEST_CASE int tc;cin>>tc;while(tc--) #define Clock high_resolution_clock::now() 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;} #ifdef LOCAL #define cerr cout #else #endif #define TRACE #ifdef TRACE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char* name, Arg1&& arg1){ cerr << name << " : " << arg1 << std::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 void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif // #define TIME /******************************************************************************************************************************/ const ll inf = 2e18; const ll mod = 998244353; const ll N = 1e5+3; int main() { auto start_time = Clock; FASTIO ll n,mxx=0; cin >> n; vll v(n), mx(n); rep(i,n) { cin >> v[i]; chmax(mxx, v[i]); mx[i] = mxx; } ll sum = 0; rep(i,n) { v[i] += (i?v[i-1]:0); sum += v[i]; cout << (sum+(i+1)*mx[i]) << "\n"; } auto end_time = Clock; #ifndef TIME return 0; #endif cout << "\nTime elapsed: " << (double)duration_cast<milliseconds>(end_time-start_time).count() << "ms"; return 0; }
#include <bits/stdc++.h> #include <climits> using namespace std; template<class T> using V = vector<T>; template<class T> using VV = V<V<T>>; using ld = long double; #define ll long long using ull = unsigned ll; using PLL = pair<ll, ll>; using VLL = V<ll>; using VB = V<bool>; using VVB = VV<bool>; using VVLL = VV<ll>; using Gr = VVLL; using MLL = map<ll, ll>; #define UMLL unordered_map<ll, ll, custom_hash> #define fast ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr); #define R & #define CR const R #define FORI(i, a, b) for(ll i = a, max##i = b; i < max##i; ++i) #define FOR(i, n) FORI(i, 0, n) #define RFORI(i, a, b) for(ll i = a, min##i = b; i >= min##i; --i) #define RFOR(i, n) RFORI(i, n, 0) #define FORA(i, a) for(auto i : a) #define FORAR(i, a) for(auto R i : a) #define FORACR(i, a) for(auto CR i : a) #define ALL(obj) begin(obj), end(obj) #define Count(q) while(q--) #define OK cerr << "OK\n"; #define mp make_pair #define pb push_back //#define DEBUG template<class T> T sqr(T x) { return x * x; } void YES(bool g, ostream R os, bool upper = true) { if(g) if(upper) os << "YES"; else os << "Yes"; else if(upper) os << "NO"; else os << "No"; os << "\n"; } template<class T> void show(T CR t, ostream R os = cerr) { FORACR(i, t) os << i << " "; os << "\n"; } template<class T> void show2d(T CR t, ostream R os = cerr) { FORACR(i, t) show(i, os); os << "\n"; } constexpr ll MOD = 1e9 + 7; //998244353; constexpr ll len = 'z' - 'a' + 1; constexpr ll INF = 1e15, MINF = -INF; constexpr ld PI = atanl(1.0L) * 4; constexpr ld eps = 1e-9, EPS = 1e-9; struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator() (uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; //arr void init() {} void solve(istream R is, ostream R os) { ll n; is >> n; string s; is >> s; char t = s[0]; bool g = 1; FORA(i, s) g &= i == t; if(g) { os << "-1\n"; return; } if(s.front() != s.back()) { os << "1\n"; return; } g = 0; FOR(i, n - 1) if(t != s[i] && t != s[i + 1]) { g = 1; } if(g) os << "2\n"; else os << "-1\n"; } void tester(istream R is, ostream R os) { auto seed = time(nullptr); //cerr << "seed: " << seed << "\n"; srand(seed); fast init(); ll q = 1; //is >> q; os << setprecision(999); Count(q) solve(is, os); } int main() { //ifstream in("input.txt"); //ofstream out("output.txt"); tester(cin, cout); }
#include<bits/stdc++.h> using namespace std; #define int long long inline int read(){ int x = 0, m = 1; char ch = getchar(); while(!isdigit(ch)){ if(ch == '-') m = -1; ch = getchar(); } while(isdigit(ch)){ x = x * 10 + ch - 48; ch = getchar(); } return x * m; } inline void write(int x){ if(x < 0){ putchar('-'); write(-x); return; } if(x >= 10) write(x / 10); putchar(x % 10 + '0'); } signed main(){ int k = read(), x = 0; for(int i = 1; i <= k; i++){ for(int j = 1; j <= k / i; j++){ x = x + k / (i * j); } } write(x); }
#include <bits/stdc++.h> using namespace std; int main() { string a,b; cin >> a; for( int i = a.size()-1 ; i >= 0 ; i--){ if (a.at(i) == '6'){ a.at(i) = '9'; } else if (a.at(i) == '9'){ a.at(i) = '6'; } b += a.at(i); } cout << b << endl; }
#include<bits/stdc++.h> // #define maxn 100010 // #define mod 998244353 using namespace std; int read() { int s=0,w=1; char ch=getchar(); while(ch<'0'||ch>'9') {if(ch=='-') w=-1;ch=getchar();} while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48),ch=getchar(); return s*w; } // int n; // int A,B; // int a[maxn] // int ksm(int x,int y) // { // int r=1; // while(y) // { // if(y&1) r=1ll*r*x%mod; // y>>=1,x=1ll*x*x%mod; // } // return r; // } signed main() { int V=read(),T=read(),S=read(),D=read(); if(T*V<=D&&D<=S*V) cout<<"No\n"; else cout<<"Yes\n"; return 0; }
#include<iostream> #include<string> #include<vector> #include<set> #include<iomanip> #include<algorithm> #include<cmath> #include<bitset> #include<queue> #include<stack> #include<utility> #include<cstdlib> #include<cstdio> #include<map> using namespace std; typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vector<int>> vvi; typedef vector<vector<ll>> vvl; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<pii> vpii; typedef vector<pll> vpll; struct Edge{ int to, cost; Edge(int t, int c) : to(t), cost(c) { } }; using Graph = vector<vector<Edge>>; #define FOR(i, a, b) for(int i=(a); i<(b); ++i) #define REP(i, n) FOR(i, 0, n) #define NREP(i, n) FOR(i, 1, n+1) template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } struct UnionFind { vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 vector<int> siz; // 素集合のサイズを表す配列(1 で初期化) UnionFind(int N) : par(N), siz(N, 1) { //最初は全てが根であるとして初期化 for(int i = 0; i < N; i++) par[i] = i; } int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根} if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(int x, int y) { // xとyの木を併合 int rx = root(x); //xの根をrx int ry = root(y); //yの根をry if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま // merge technique(データ構造をマージするテク.小を大にくっつける) if(siz[rx] < siz[ry]) swap(rx,ry); siz[rx] += siz[ry]; par[ry] = rx; //xとyの根が同じでない(=同じ木にない)時:yの根ryをxの根rxにつける return; } bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す int rx = root(x); int ry = root(y); return rx == ry; } int size(int x){ //素集合のサイズ return siz[root(x)]; } }; int uf_num(UnionFind uf, int N){ int res=0; REP(i,N) if(uf.root(i)==i) res++; return res; } const int INF=2e9+1; //for some test case (near inf) const ll INFLL=1e18; const ll MOD=1e9+7; ll MODpow(ll x, ll n, ll mod){ ll res=1; while(n>0){ if(n&1) res=res*x%mod; x=x*x%mod; n >>= 1; } return res; } ll MODcomb(ll n, ll r, ll mod, vl fact){ ll res=1; if(n>=r){ res=fact[n]%mod; res=res*MODpow(fact[r], mod-2, mod)%mod; res=res*MODpow(fact[n-r], mod-2, mod)%mod; } return res; } 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/gcd(a,b)*b; } int main(void){ int v,t,s,d; cin >> v >> t >> s >>d; if(v*t<=d && d<=v*s) cout << "No" << endl; else cout << "Yes" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll MOD = 1000000007; const ll INF = 1001001001001001; const int inf = 1001001001; using P = pair<ll, ll>; int main() { ll A, B; cin >> A >> B; ll C = B-A; for (ll i = C; i >= 1; i--) { ll D = B/i; if (i*(D-1)>= A) { cout << i << endl; return 0; } } }
#pragma GCC optimize ("O3") #pragma GCC target ("sse4") #include<stdio.h> #include<iostream> #include<vector> #include<algorithm> #include<string> #include<string.h> #ifdef LOCAL #define eprintf(...) fprintf(stderr, __VA_ARGS__) #else #define NDEBUG #define eprintf(...) do {} while (0) #endif #include<cassert> using namespace std; typedef long long LL; typedef vector<int> VI; #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i) #define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i) template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; } template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; } #define rprintf(fmt, begin, end) do { const auto end_rp = (end); auto it_rp = (begin); for (bool sp_rp=0; it_rp!=end_rp; ++it_rp) { if (sp_rp) putchar(' '); else sp_rp = true; printf(fmt, *it_rp); } putchar('\n'); } while(0) void MAIN() { LL A, B; scanf("%lld%lld", &A, &B); LL ans = 1; for (LL i=1; i<=B; i++) { LL d = B/i - (A-1)/i; if (d >= 2) ans = i; } printf("%lld\n", ans); } int main() { int TC = 1; // scanf("%d", &TC); REP (tc, TC) MAIN(); return 0; }
#include <iostream> #include <string> #include <vector> #include <array> #include <stack> #include <queue> #include <deque> #include <algorithm> #include <set> #include <map> #include <unordered_map> #include <bitset> #include <cmath> #include <functional> #include <cassert> #include <iomanip> #include <numeric> #include <memory> #include <random> #define VV(a, b, c, d) vector<vector<d>>(a, vector<d>(b, c)) #define VVV(a, b, c, d, e) vector<vector<vector<e>>>(a, VV(b, c, d, e)); #define all(obj) (obj).begin(), (obj).end() typedef long long ll; typedef long double ld; typedef std::vector<ll> v1; typedef std::vector<v1> v2; typedef std::vector<v2> v3; using namespace std; long long floor_sum(long long n,long long m,long long a,long long b){ long long res=0; if(a>=m){ res+=n*(n-1)/2*(a/m); a%=m; } if(b>=m){ res+=n*(b/m); b%=m; } long long y_max=(a*(n-1)+b)/m; if(y_max==0) return res; return res+y_max+floor_sum(y_max,a,m,(a*(n-1)+b)-m*y_max); } void solve(){ ll x, y, p, q; scanf("%lld %lld %lld %lld", &x, &y, &p, &q); ll l = 0, r = 1000000000; if(floor_sum(r, p+q, 2*(x+y), x+y+q-1) == floor_sum(r, p+q, 2*(x+y), x)){ std::cout << "infinity" << '\n'; return; } while(r-l>1){ ll mid = (l+r)/2; if(floor_sum(mid, p+q, 2*(x+y), x+y+q-1) == floor_sum(mid, p+q, 2*(x+y), x)) l = mid; else r = mid; } ll distsum = 2*(r-1)*(x+y) + x; if(distsum % (p+q) >= p) printf("%lld\n", distsum); else printf("%lld\n", distsum + (p - distsum % (p+q))); } int main(){ int t; scanf("%d\n", &t); for(int i=0;i<t;i++) solve(); }
#include <bits/stdc++.h> using namespace std; /* * * * * * * * * * */ typedef long long ll; typedef long double ld; typedef pair<int, int> pii; /* * * * * * * * * * */ /* * * * I love Ylva Eriksson * * */ const ll mod = 1e9 + 7; ll add(ll a, ll b) { return a + b > mod ? a + b - mod : a + b; } ll mult(ll a, ll b) { return a * b % mod; } ll powmod(ll b, ll e) { if (e == 0) return 1; ll u = powmod(b, e / 2); u = mult(u, u); if (e & 1) u = mult(u, b); return u; } const int maxn = 1010; ll f[maxn]; int main(){ ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); f[1] = f[0] = 1; for (int i = 2; i < maxn; ++i) f[i] = add(f[i - 1], f[i - 2]); int n, op[2][2]; cin >> n; char ci; cin >> ci; op[0][0] = ci - 'A'; cin >> ci; op[0][1] = ci - 'A'; cin >> ci; op[1][0] = ci - 'A'; cin >> ci; op[1][1] = ci - 'A'; if (n <= 3) { cout << 1 << endl; return 0; } if (op[0][1]) { //ABB if (op[1][1]) cout << 1 << endl; else cout << (op[1][0] == 0 ? powmod(2, n - 3) : f[n - 2]) << endl; } else { //AAB if(!op[0][0]) cout << 1 << endl; else cout << (op[1][0] ? powmod(2, n - 3) : f[n - 2]) << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vll = vector<ll>; using vb = vector<bool>; using vvi = vector<vi>; using vvll = vector<vll>; using vvb = vector<vb>; using pll = pair<ll,ll>; int main(){ int n; vll x(n),y(n); ll s,d; cin >> n >> s >> d; for (int i = 0; i < n; i++) { cin >> x[i] >> y[i]; } string ans = "No"; for (int i = 0; i < n; i++) { if (x[i] < s && y[i] > d) { ans = "Yes"; } } cout << ans << endl; }
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG using namespace std; typedef long long ll; #define INF 1e9 #define rep(i, n) for(int i = 0; i < n; i++) #define repr(i, n) for(int i = n; i >= 0; i--) #define FOR(i, m, n) for(int i = m; i < n; i++) #define all(x) (x).begin(),(x).end() int main() { ll N,S,D; cin >> N >> S >> D; bool ans = false; rep(i, N) { ll X,Y; cin >> X >> Y; if (X < S) if (Y > D) ans = true; } if (ans) cout << "Yes" << endl; else cout << "No" << endl; }
#include <bits/stdc++.h> using namespace std; int main(){ long long A, B; scanf("%lld %lld", &A, &B); int primes[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71}; vector <long long> dp(1 << 20, 0); dp[0] = 1; for(long long x = A; x <= B; x++){ int mask = 0; for(int i = 0; i < 20; i++) if(x % primes[i] == 0)mask |= 1 << i; for(int i = (1 << 20) - 1; i >= 0; i--) if((i & mask) == 0)dp[i | mask] += dp[i]; } printf("%lld\n", accumulate(dp.begin(), dp.end(), 0LL)); return 0; }
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") #pragma GCC option("arch=native","tune=native","no-zero-upper") #pragma GCC target("avx2") #include <bits/stdc++.h> using namespace std; #define INF 2147483647 #define infL (1LL<<60) #define inf (1<<30) #define inf9 (1000000000) #define MOD 1000000007//998244353//1000000007 #define EPS 1e-9 #define Gr 9.8 #define PI acos(-1) #define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++) #define REQ(i,n) for(int (i)=1;(i)<=(int)(n);(i)++) #define lch (rt<<1) #define rch (rt<<1|1) #define readmp(n) for(int i=0,u,v;i<n;i++) {scanf("%d%d",&u,&v); mp[u].push_back(v); mp[v].push_back(u);} typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef long double ld; typedef unsigned int uint; typedef unsigned long long ull; typedef ll ValType; template<typename T> void maxtt(T& t1, T t2) { t1=max(t1,t2); } template<typename T> void mintt(T& t1, T t2) { t1=min(t1,t2); } #define MAX (135) bool debug = 0; int n,m,k; int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0}; string direc="RDLU"; const ll MOD2 = (ll)MOD * (ll)MOD; ll ln, lk, lm; void etp(bool f = 0) { puts(f ?"YES" : "NO"); exit(0); } void addmod(int &x, int y, int mod = MOD){ x+=y; if (x>=mod) x-=mod; if(x<0) x+=mod; assert(x>=0 && x<mod); } void et(int x=-1) { printf("%d\n", x); exit(0); } ll fastPow(ll x, ll y, int mod=MOD) { ll ans = 1; while(y>0) { if(y&1) ans = (x * ans)%mod; x = x*x%mod; y>>=1; } return ans; } ll gcd1(ll x, ll y) { return y?gcd1(y,x%y):x; } int cnt[100]; int ps[20]={2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71}; ll dp[1<<20]; void fmain(int tid) { scanf("%lld%lld",&ln,&lm); int N=lm-ln+1; for(ll i=ln;i<=lm;i++) { REP(j,20) if(i%ps[j]==0) { cnt[i-ln+1] |= 1<<j; } } dp[0]=1; int fe=0; REQ(i,N) { if (cnt[i]==0) { fe++; continue; } for(int j=(1<<20)-1; j>=0; j--) if ((j&cnt[i])==cnt[i]) { int sm=j-cnt[i]; dp[j]+=dp[sm]; } } ll ans=0; REP(j, 1<<20) { ans += dp[j]; } ans *= 1LL<<fe; printf("%lld\n", ans); } int main() { int t=1; // init(); // scanf("%d", &t); REQ(i,t) { fmain(i); } return 0; }