code_file1
stringlengths
87
4k
code_file2
stringlengths
82
4k
#include <bits/stdc++.h> // clang-format off using namespace std; using ll=long long; using ull=unsigned long long; using pll=pair<ll,ll>; const ll INF=4e18; void print0(){}; template<typename H,typename... T> void print0(H h,T... t){cout<<h;print0(t...);} void print(){print0("\n");}; template<typename H,typename... T>void print(H h,T... t){print0(h);if(sizeof...(T)>0)print0(" ");print(t...);} void perr0(){}; template<typename H,typename... T> void perr0(H h,T... t){cerr<<h;perr0(t...);} void perr(){perr0("\n");}; template<typename H,typename... T>void perr(H h,T... t){perr0(h);if(sizeof...(T)>0)perr0(" ");perr(t...);} void ioinit() { cout << fixed << setprecision(15); cerr<<fixed<<setprecision(6); ios_base::sync_with_stdio(0); cin.tie(0); } // clang-format on const ll MODULO = 1000000007LL; ll mod_minus(ll x, ll modval) { ll v = x % modval; if (v < 0) { v += modval; } return v; } ll mod(ll x) { return mod_minus(x, MODULO); } ll n; vector<ll> a; ll memo[100005][2]; bool recdone[100005][2]; ll rec(ll i, ll cur) { if (i <= 1) { return 1; } if (recdone[i][cur]) return memo[i][cur]; recdone[i][cur] = true; ll ans = 0; if (cur == 0) { ans = rec(i - 1, 1); } else { ans = rec(i - 1, 1) + rec(i - 1, 0); } return memo[i][cur] = mod(ans); } int main() { ioinit(); cin >> n; a.resize(n); for (ll i = 0; i < n; i++) { cin >> a[i]; } if (n == 2) { print(a[0] + a[0]); return 0; } if (n == 1) { print(a[0]); return 0; } ll ans = 0; for (ll i = 0; i < n; i++) { ll j = i - 1; ll plus = 0; if (i == 0) { plus = mod(rec(n - 1, 0) + rec(n - 1, 1)); } else if (i == 1) { plus = mod(rec(n - 2, 0) + rec(n - 2, 1)); } else if (i == n - 1) { plus = mod(rec(n - 2, 0) + rec(n - 2, 1)); } else { plus = mod(mod(rec(n - j - 2, 0) + rec(n - j - 2, 1)) * mod(rec(j, 0) + rec(j, 1))); } ll minus = 0; if (i == 0) { minus = 0; } else { minus = mod(rec(n - 2 - j, 1) * rec(j, 1)); } //print(i, plus, minus); ans = mod(ans + plus * a[i] - minus * a[i]); } print(ans); }
#include <cstdio> #include <algorithm> using namespace std; const int maxn = 1e5 + 5; const int mod = 1e9 + 7; int a[maxn]; int main() { long long *f = new long long[maxn]; f++; int n; scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d", a + i); } f[-1] = 1; f[0] = 1; f[1] = 2; f[2] = 3; for (int i = 3; i <= n; ++i) { f[i] = f[i - 1] + f[i - 2]; f[i] %= mod; } long long ans = 0; for (int i = 1; i <= n; ++i) { if (i == 1) { ans += f[n - 1] * a[1]; } else { ans += ((f[i - 2] * f[n - i] - f[i - 3] * f[n - i - 1]) % mod) * a[i]; } ans %= mod; } if (ans < 0) { ans += mod; } printf("%lld\n", ans); f--; delete[] f; return 0; }
#include<bits/stdc++.h> using namespace std; const int MOD = 1000000007; long bimod(int x, int exp){ long res = 1, mul = x; for(long i = exp; i > 0; i >>= 1){ if(i & 1) res = (res * mul) % MOD; mul = (x * x) % MOD; } return res; } int main(){ int n, a[100000], i; cin >> n; long sum = 0, ans; for(i = 0; i < n; i++){ cin >> a[i]; sum = (sum + a[i]) % MOD; } long bmd = bimod(2, n-1); long a_n[100000] = {1, 1,}, s_n_2 = 1; for(i = 2; i < n ; i++){ a_n[i] = s_n_2 % MOD, s_n_2 = (s_n_2 + a_n[i-1]) % MOD; } ans = sum; long afp, afm, af; for(i = 1; i < n; i++){ af = (a_n[i] * a_n[n-i]) % MOD; afp = (sum * a_n[n-i]) % MOD; afm = (a[n-i] * af * 2) % MOD; ans = (ans + afp - afm + MOD) % MOD; } cout << ans << endl; return 0; }
//#define _GLIBCXX_DEBUG #include<bits/stdc++.h> using namespace std; #define endl '\n' #define lfs cout<<fixed<<setprecision(10) #define ALL(a) (a).begin(),(a).end() #define ALLR(a) (a).rbegin(),(a).rend() #define spa << " " << #define fi first #define se second #define MP make_pair #define MT make_tuple #define PB push_back #define EB emplace_back #define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++) #define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--) using ll = long long; using ld = long double; const ll MOD1 = 1e9+7; const ll MOD9 = 998244353; const ll INF = 1e18; using P = pair<ll, ll>; template<typename T1, typename T2>bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;} template<typename T1, typename T2>bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;} ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});} void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;} void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;} void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;} template<typename T1,typename T2>void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;} template<typename T>void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++){cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}}; void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++){for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}}; template<typename T>void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;}; template<typename T>vector<vector<T>>vec(ll x, ll y, T w){vector<vector<T>>v(x,vector<T>(y,w));return v;} ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;} vector<ll>dx={1,-1,0,0,1,1,-1,-1};vector<ll>dy={0,0,1,-1,1,-1,1,-1}; 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 T1, typename T2>ostream &operator<<(ostream &os, const pair<T1, T2>&p){return os << p.first << " " << p.second;} template<typename T>ostream &operator<<(ostream &os, const vector<T> &v){for(auto &z:v)os << z << " ";cout<<"|"; return os;} //mt19937 mt(chrono::steady_clock::now().time_since_epoch().count()); int popcount(ll x){return __builtin_popcountll(x);}; int poplow(ll x){return __builtin_ctzll(x);}; int pophigh(ll x){return 63 - __builtin_clzll(x);}; int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); ll res=0,buf=0; bool judge = true; ll n;cin>>n; vector<ll>a(n),b(n); rep(i,0,n){ cin>>a[i]; res+=a[i]; } rep(i,0,n){ cin>>b[i]; b[i]=b[i]-a[i]; } vector<vector<ll>>v(2); rep(i,0,n){ v[i&1].PB(b[i]); } sort(ALLR(v[0])); sort(ALLR(v[1])); rep(i,0,v[0].size()){ if(v[0][i]+v[1][i]>0)res+=v[0][i]+v[1][i]; } cout<<res<<endl; return 0; }
// Problem: C - ABC Tournament // Contest: AtCoder - AtCoder Beginner Contest 188 // URL: https://atcoder.jp/contests/abc188/tasks/abc188_c // Memory Limit: 1024 MB // Time Limit: 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) #include <iostream> #include <cmath> #define pii pair<int,int> using namespace std; pair<int, int> arr[65546]; int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); int n, a = -1 , b = -1, pa = -1 , pb = -1; cin >> n; n = pow(2, n); for (int i = 0; i < n; ++i) cin >> arr[i].second, arr[i].first = i+1; for (int i = 0, j = n-1; i < j; ++i, --j) { if (arr[i].second > a) { a = arr[i].second, pa = arr[i].first; } if (arr[j].second > b) { b = arr[j].second, pb = arr[j].first; } } if (a > b) cout << pb; else cout << pa; }
#include <bits/stdc++.h> using namespace std; #define all(x) x.begin(), x.end() #define int long long #define endl '\n' /* ifstream in("test.txt"); #define cin in */ void solve(){ int n; cin >> n; n = 1 << n; vector<int> a(n); for(int i = 0; i < n; i++) cin >> a[i]; if(*max_element(a.begin(), a.begin()+n/2) < *max_element(a.begin()+n/2, a.end())) cout << max_element(a.begin(), a.begin()+n/2)-a.begin()+1; else cout << max_element(a.begin()+n/2, a.end())-a.begin()+1; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int t = 1; //cin >> t; while(t--){ solve(); } return 0; }
#include <bits/stdc++.h> #define ll long long #define db long double #define x first #define y second #define mp make_pair #define pb push_back #define all(a) a.begin(), a.end() using namespace std; void solve() { int n; cin >> n; string s1, s2, s3; cin >> s1 >> s2 >> s3; if (s1.back() == s2.back() && s2.back() == s3.back()) { char c = s1.back(); char x = '1' + '0' - c; for (int i = 0; i < 2 * n; ++i) { cout << x; } cout << c << "\n"; return; } int cnt0 = 0, cnt1 = 0; char c = '0'; vector<string> strs = {s1, s2, s3}; for (int i = 0; i < 3; ++i) { if (strs[i].back() == '0') { ++cnt0; } else { ++cnt1; } } if (cnt1 > cnt0) { c = '1'; } char x = '0' + '1' - c; for (int i = 0; i < n; ++i) { cout << c; } for (int i = 0; i < n; ++i) { cout << x; } cout << c << "\n"; } int main(){ #ifdef LOCAL freopen("A_input.txt", "r", stdin); //freopen("A_output.txt", "w", stdout); #endif ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; for (int i = 0; i < t; ++i) { solve(); } }
#include <bits/stdc++.h> using namespace std; struct UnionFind { vector<int> par; vector<int> siz; UnionFind(int N) : par(N),siz(N) { for (int i=0; i<N; i++) { par[i]=i,siz[i]=1; } } int root(int x) { if (par[x]==x) return x; return par[x]=root(par[x]); } void unite(int x, int y) { int rx=root(x); int ry=root(y); if (rx==ry) return; par[rx]=ry; siz[ry]+=siz[rx]; } bool same(int x,int y) { int rx=root(x); int ry=root(y); return rx==ry; } int size (int x) { return siz[root(x)]; } }; int main() { int N,M; cin >> N >> M; vector<vector<pair<int,int>>> G(N); UnionFind tree(N); int A[N]; memset(A,0,sizeof(A)); for (int i=0; i<M; i++) { int u,v,c; cin >> u >> v >> c; if (tree.same(u-1,v-1)) continue; tree.unite(u-1,v-1); G[u-1].push_back({v-1,c}); G[v-1].push_back({u-1,c}); } queue<tuple<int,int,int>> q; for (int i=0; i<N; i++) { if (G[i].size()==1) { q.push(make_tuple(i,G[i][0].first,G[i][0].second));//position,position,distance A[i]=1; break; } } while (!q.empty()) { tuple<int,int,int> p=q.front(); q.pop(); int a=get<0>(p),b=get<1>(p),d=get<2>(p); if (d==A[a]) { if (d==1) A[b]=2; else A[b]=1; } else A[b]=d; for (auto x:G[b]) { int a=x.first; if (A[a]==0) { q.push(make_tuple(b,x.first,x.second)); } } } for (int i=0; i<N; i++) cout << A[i] << endl; }
#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; using ll = long long; using ld = long double; using ordered_set = tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>; void fastio() { cin.tie(nullptr); cin.sync_with_stdio(false); } const ll MOD = 1e9+7; const ll INF = 1e18; const ll N = 2e5+1; #define S second #define F first #define vt vector #define rep(i, st, en) for(ll i = (st); i < (en); ++i) #define repr(i, en, st) for(ll i = (en); i >= (st); --i) int main() { fastio(); ll n; cin >> n; vt<ll> a(n); rep(i, 0, n) { cin >> a[i]; } vt<vt<ll>> dp(n+1, vt<ll>(n+1, 0)); /** * dp[i][j]: * i: which bag is being filled [1...n] * j: currently starting the bag at which index ? * Answer: * dp[1][1] */ vt<ll> ps(n+1); ps[0] = 0; rep(i, 1, n+1) { ps[i] = ps[i-1] + a[i-1]; } vt<vt<ll>> mult(n+1, vt<ll>(n+1, -1)); // stores index for the next multiple rep(i, 1, n+1) { vt<ll> modu(i, -1); ll sum = 0; repr(j, n, 1) { sum += a[j-1]; sum %= i; // if (i == 2) { // cerr << j << " << j \t" << modu[sum] << " << modu \t" << sum << " sum \n"; // } if (modu[sum] != -1) { mult[i][j] = modu[sum]; } modu[sum] = j; } } // rep(i, 1, n+1) { // cerr << "i: " << i << ": \n"; // rep(j, 1, n+1) { // cerr << mult[i][j] << "\t"; // } // cerr << "\n"; // } repr(j, n, 1) { //cerr << "j = " << j << "\n"; rep(i, 1, n+1) { if (mult[i][j] != -1) { dp[i][j] = (dp[i][j] + dp[i][mult[i][j]] + (i+1 <= n ? dp[i+1][mult[i][j]] : 0)) % MOD; } else { if ((ps[n]-ps[j-1]) % i == 0) { dp[i][j] = 1; } } //cerr << dp[i][j] << " " << mult[i][j] << "\n"; } } cout << dp[1][1] << "\n"; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll MOD = 1000000007; int main(){ int n; cin>>n; vector<ll> lista(n+1); for(int i = 1; i<=n; i++){ cin>>lista[i]; } vector<vector<ll> > dp(n+1, vector<ll>(n+1, 0)); for(int i = 1; i<=n; i++){ dp[i][1] = 1; } for(int i = 2; i<=n; i++){ vector<ll> resto(i, 0); ll sum = 0; for(int j = 1; j<=n; j++){ sum = (sum + lista[j])%i; dp[j][i] = (dp[j][i] + resto[sum%i])%MOD; resto[sum%i] = (resto[sum%i] + dp[j][i-1])%MOD; } } ll res = 0; for(int i = 1; i<=n; i++){ res = (res + dp[n][i])%MOD; } cout<<res<<"\n"; return 0; }
#include<cstdio> #include<iostream> using namespace std; int n,t[2010]; int l[2010],r[2010]; int cnt=0; int main() { scanf("%d",&n); for (int i=1;i<=n;i++) { scanf("%d%d%d",&t[i],&l[i],&r[i]); l[i]*=2,r[i]*=2; if (t[i]==2) r[i]--; else if (t[i]==3) l[i]++; else if (t[i]==4) l[i]++,r[i]--; } for (int i=1;i<n;i++) for (int j=i+1;j<=n;j++) { if (r[i]<l[j]||r[j]<l[i]) continue; cnt++; } printf("%d\n",cnt); }
#include <iostream> #include <cstdio> #include <algorithm> #include <vector> #include <utility> #include <string> #include <fstream> #include <map> #include <set> #include <queue> #include <memory.h> using namespace std; typedef vector<int> VI; typedef pair<int, int> PI; typedef vector<PI> VPI; #define FOR(i,a,n) for (int i = (a); i < (n); ++i) #define FORE(i,a,n) for (int i = (a); i <= (n); ++i) #define FORD(i,a,b) for (int i = (a); i >= (b); --i) #define REP(i,n) FOR(i,0,n) #define REPE(i,n) FORE(i,0,n) #define LL long long #define FIR(n) REP(i,n) #define FJR(n) REP(j,n) #define ALL(v) v.begin(), v.end() #define FI FIR(n) #define FJ FJR(n) #define FR(i,a) FOR(i,a,n) #define REPN(i) REP(i,n) #define GI(n) scanf("%d", &n) #define GI2(n,m) scanf("%d %d", &n, &m) int a[2020], b[2020]; int main() { #ifdef LOCALF freopen("input.txt", "rt", stdin); #endif ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; int t, s, f; FI{ cin >> t >> s >> f; s *= 2; f *= 2; if (t >= 3) ++s; if (t % 2 == 0) --f; a[i] = s; b[i] = f; } int res = 0; FI FOR(j, i + 1, n) if ((a[i] <= a[j] && a[j] <= b[i]) || (a[j] <= a[i] && a[i] <= b[j])) ++res; cout << res << endl; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define rep(i,n) for(i=0;i<n;i++) #define pb push_back #define mp make_pair #define ff first #define ss second #define debug cout<<"debug"<<endl; ll Pow(ll x,ll y){return y==0?:x*pow(x,y-1);} int main() { ///"In the name of Allah,most gracious and most merciful"/// ll i,j,x,y,z,count=0,sum=0,n,m; cin>>n; x=Pow(2,n); vector<ll>a(x); vector<pair<ll,ll> >v,v1,v2; for(ll i=0;i<x;i++) { cin>>a[i]; v.pb(mp(a[i],i+1)); } if(n==1){ if(v[0].ff>v[1].ff) { cout<<v[1].ss<<endl; } else { cout<<v[0].ss<<endl; } } else { while(1){ if(sum==0){ for(ll i=0;i<v.size();i+=2) { if(v[i].ff>v[i+1].ff) v1.pb(mp(v[i].ff,v[i].ss)); else v1.pb(mp(v[i+1].ff,v[i+1].ss)); } sum=1; } else if(count==0) { for(ll i=0;i<v1.size();i+=2) { if(v1[i].ff>v1[i+1].ff) v2.pb(mp(v1[i].ff,v1[i].ss)); else v2.pb(mp(v1[i+1].ff,v1[i+1].ss)); } count=1; v1.clear(); } else if(count==1) { for(ll i=0;i<v2.size();i+=2) { if(v2[i].ff>v2[i+1].ff) v1.pb(mp(v2[i].ff,v2[i].ss)); else v1.pb(mp(v2[i+1].ff,v2[i+1].ss)); } count=0; v2.clear(); } if(v1.size()==2 || v2.size()==2) break; } if(v1.size()==2) { if(v1[0].ff>v1[1].ff) { cout<<v1[1].ss<<endl; } else { cout<<v1[0].ss<<endl; } } else if(v2.size()==2) { if(v2[0].ff>v2[1].ff) { cout<<v2[1].ss<<endl; } else { cout<<v2[0].ss<<endl; } } } return 0; }
#include <bits/stdc++.h> using namespace std;using ll=long long;using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;using vb=vector<bool>;using vvb=vector<vb>;using vvl=vector<vl>;using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;using vpl=vector<PL>; #define all(v)(v).begin(),(v).end() #define rall(v)(v).rbegin(),(v).rend() // cin and cout of a vector template<class T>class iterable{static false_type c(string v);template<class U>static auto c(U v)->decltype(all(v),true_type());static false_type c(...);public:const static bool value=decltype(c(declval<T>()))::value;}; template<class T,enable_if_t<iterable<T>::value,int> =0>ostream&operator<<(ostream&o,const T&v){for(auto&&i:v)o<<i<<' ';return o;} template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}template<class T>vector<T>&operator<<(vector<T>&v,const T&t){v.push_back(t);return v;} // for loop #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) #define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define revv(i, a, b) for (int i = (int)(b-1); i >= (int)(a); i--) #define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--) #define rev1(i, n) for(int i = (int)(n); i > 0; i--) // #define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++) // #define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--) // #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) // #define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++) // Yes/no #define cho(n,a,b) cout<< ((n)?a:b)<<endl; void YES(int n){cho(n,"YES","NO");}void Yes(int n){cho(n,"Yes","No");}void Poss(int n){cho(n,"Possible","Impossible");} #define pb push_back #define rsortv(v) sort((v).rbegin(), (v).rend()) #define sortv(v) sort((v).begin(), (v).end()) // max/min template<class T, class U>bool chmax(T&a,const U&b){bool x=a<b;x?a=b:b;return x;}template<class T, class U>bool chmin(T&a,const U&b){bool x=a>b;x?a=b:b;return x;} template<class T, class U>auto max(const T&a,const U&b){return a<b?b:a;}template<class T, class U>auto min(const T&a,const U&b){return a<b?a:b;} //======================================== //======================================== //======================================== template<class T>auto minv(const T&a){return *min_element(all(a));} template<class T>auto smod(T a, T b){a %= b; if (a < 0); a+= b; return a;} template<class T>auto maxv(const T&a){return *max_element(all(a));} template<class T>auto sumv(const T&a){ll sum = 0; for(auto x: a) sum+= x; return sum;} template<class T>void pr(const T&a){cout << a << endl;} template<class T>void pr_precise(const T&a){cout.precision(10); cout << fixed << a << endl;} int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // ll M = 1000000007; ll M = 998244353; int main() { int cases = 1; // cin >> cases; rep(CASE, cases){ int p; cin >> p; int n = (1<< (p-1)); vl A(n); vl B(n); cin >> A; cin >> B; ll a = maxv(A); ll b = maxv(B); if (a < b) pr(1 + std::distance(A.begin(), std::max_element(A.begin(), A.end()))); else pr(1 + n+ std::distance(B.begin(), std::max_element(B.begin(), B.end()))); // pr(min(a,b)); // pr(A); // pr(B); // pr(C); } return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int a,b,c; cin >> a >> b >> c; if(a==b){ cout << c << endl; } else if(b == c){ cout << a <<endl; } else if(c == a){ cout << b << endl; } else{ cout << 0 << endl; } return 0; }
///Bismillahir Rahmanir Rahim /* Author: Tanzin Ahammad */ #include<bits/stdc++.h> #define u64 uint64_t #define ll long long #define endl "\n" #define PI acos(-1) #define fi first #define si second #define pb push_back #define set0(arr) memset(arr, 0, sizeof(arr)) #define setinf(arr) memset(arr, 126, sizeof(arr)) #define gcd(a,b) __gcd(a,b) #define lcm(a,b) (a*b)/gcd(a,b) #define all(x) (x).begin(),(x).end() #define sz(v) ((ll)(v).size()) #define mem(a,b) memset(a, b, sizeof(a)) #define uniq(v) (v).erase(unique(all(v)),(v).end()) #define mchk(mask,pos) (mask & (1ll<<pos)) #define mset(mask,pos) (mask bitor (1ll<<pos)) #define munset(mask,pos) (mask ^ (1ll<<pos)) #define print_case cout<<"Case "<<cs<<": " #define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) using namespace std; using pll = pair<ll, ll> ; using vl = vector<ll> ; using vpll = vector<pll> ; using mll = map<ll, ll> ; using mcl = map<char, ll> ; using msl = map<string,ll> ; using sl = set<ll> ; using sc = set<char> ; const int N = 1e6+5; const int mod = (int) 1e9 + 7; ll arr[N]; ll sumd(ll a,ll b){return (((a%mod)+(b%mod))%mod);} ll muld(ll a,ll b){return (((a%mod)*(b%mod))%mod);} ll subd(ll a,ll b){return (((a%mod)-(b%mod)+mod)%mod);} int main() { IOS; ll tc,n,x,i,j; string s1,s2,s3; cin>>s1>>s2>>s3; sc st; if(s1==s3) { cout<<"UNSOLVABLE"; return 0; } for(i=0;i<sz(s1);i++) { st.insert(s1[i]); } for(i=0;i<sz(s2);i++) { st.insert(s2[i]); } for(i=0;i<sz(s3);i++) { st.insert(s3[i]); } if(sz(st)>10) { cout<<"UNSOLVABLE"; } else { vector<char> vt; for(auto pr:st) { vt.pb(pr); } string num="0123456789"; ll f=0,n1,n2,n3; do { map<char,ll>mp; for(i=0;i<sz(vt);i++) { mp[vt[i]]=(num[i]-'0'); } n1=0,n2=0,n3=0; ll f1=0; for(i=0;i<sz(s1)&&f1==0;i++) { if(i==0&&mp[s1[i]]==0) { f1=1; break; } n1=n1*10+mp[s1[i]]; } for(i=0;i<sz(s2)&&f1==0;i++) { if(i==0&&mp[s2[i]]==0) { f1=1; break; } n2=n2*10+mp[s2[i]]; } for(i=0;i<sz(s3)&&f1==0;i++) { if(i==0&&mp[s3[i]]==0) { f1=1; break; } n3=n3*10+mp[s3[i]]; } if(f1==0&&n1+n2==n3) { f=1;break; } }while(next_permutation(num.begin(),num.end())); if(f==1) { cout<<n1<<endl<<n2<<endl<<n3; } else cout<<"UNSOLVABLE"; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long ll; typedef long double ld; typedef pair<int,int> pii; typedef pair<ll,ll> pll; #define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define test() int t;cin>>t;for(int test=1;test<=t;test++) #define pb push_back #define nl cout<<"\n" #define F first #define S second #define all(x) x.begin(),x.end() template<class C> void min_self( C &a, C b ){ a = min(a,b); } template<class C> void max_self( C &a, C b ){ a = max(a,b); } const ll MOD = 1000000007; ll mod( ll n, ll m=MOD ){ n%=m;if(n<0)n+=m;return n; } const int MAXN = 1e5+5; const int LOGN = 21; const ll INF = 1e14; int dx[] = {1,0,-1,0}; int dy[] = {0,1,0,-1}; template<class T1, class T2> void add( T1 &x, T2 y, ll m = MOD ) { x += y; if( x >= m ) x -= m; } template<class T1, class T2> void sub( T1 &x, T2 y, ll m = MOD ) { x -= y; if( x < 0 ) x += m; } template<class T> class Math { public: vector<T>fact,invfact; Math( int n ) { fact.resize(n); invfact.resize(n); fact[0] = invfact[0] = 1; for(int i=1;i<n;i++) { fact[i] = mod( i * fact[i-1] ); invfact[i] = modinv( fact[i] ); } } T modinv( T x, T m = MOD ) { return expo(x,m-2,m); } T expo( T base, T exp, T m = MOD ) { T res = 1; while( exp ) { if( exp&1 ) res = mod( res*base, m ); base = mod( base*base, m ); exp >>= 1; } return res; } T choose( T n, T k ) { if( k < 0 || k > n ) return 0; T ans = fact[n]; ans = mod( ans * invfact[n-k] ); ans = mod( ans * invfact[k] ); return ans; } }; int main() { #ifdef gupta_samarth freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fastio(); int n,p; cin>>n>>p; if( p == 2 ) { if( n == 1 ) cout<<1,nl; else cout<<0,nl; return 0; } Math<ll> m(2005); ll ans = p-1; ans = mod( ans * m.expo(p-2,n-1) ); cout<<ans,nl; cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int m, h; cin >> m >> h; if (h % m == 0) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; vector<long long> A, B; int main() { long long int n; cin >> n; long long A = 3ll; while (true) { if (n <= A) break; long long m = n - A; while (m % 5 == 0) { m /= 5; } if (m == 1) { int cnt = 0; m = A; while (m % 3 == 0) { m /= 3; cnt++; } int cnt2 = 0; m = n - A; while (m % 5 == 0) { m /= 5; cnt2++; } if (cnt >= 1 && cnt2 >= 1) { cout << cnt << " " << cnt2 << "\n"; return 0; } } long long B = A * 3ll; if (B < A) break; A = B; } cout << "-1\n"; }
#include <iostream> // cout, endl, cin #include <cmath> //sqrt pow #include <string> // string, to_string, stoi #include <vector> // vector #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <utility> // pair, make_pair #include <tuple> // tuple, make_tuple #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include <map> // map #include <queue> // queue, priority_queue #include <set> // set #include <stack> // stack #include <deque> // dequef #include <unordered_map> // unordered_map #include <unordered_set> // unordered_set #include <bitset> // bitset #include <cctype> // isupper, islower, isdigit, toupper, tolower #include <climits> #define rep(i, n) for (int i = 0; i < n; i++) using ll = long long; using ld = long double; #define vi vector<int> #define vvi vector<vi> #define vl vector<ll> #define pii pair<int, int> #define pll pair<ll, ll> #define all(a) (a).begin(), (a).end() #define mod 1000000007 using namespace std; int main(){ int n; cin >> n; vector<vl> dp(n + 1, vl(2)); dp[0][0] = dp[0][1] = 1; rep(i, n){ string s; cin >> s; if(s == "OR"){ dp[i + 1][1] = dp[i][0] + dp[i][1] * 2; dp[i + 1][0] = dp[i][0]; }else{ dp[i + 1][1] = dp[i][1]; dp[i + 1][0] = dp[i][0] * 2 + dp[i][1]; } } cout << dp[n][1] << endl; }
#include <bits/stdc++.h> using namespace std; #define lli long long int #define pb push_back #define endl ("\n") #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define vi vector<lli> #define ff first #define ss second #define rep(i, a, b) for (int i = a; i < b; i++) #define repr(i, a, b) for (int i = a; i > b; i--) int main() { fast lli t, n; t = 1; // cin>>t; while (t--) { cin>>n; n = pow(2, n); lli a[n], mx1 = 0, mx2 = 0, p, q; rep (i, 0, n) cin>>a[i]; rep (i, 0, n/2) { if (a[i] > mx1) { mx1 = a[i]; p = i; } } rep (i, n/2, n) { if (a[i] > mx2) { mx2 = a[i]; q = i; } } if (mx1 > mx2) cout<<q + 1; else cout<<p + 1; } 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 ll long long using pss = pair<string, string>; using pll = pair<ll, ll>; using pls = pair<ll,string>; typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; #define endl '\n'; #define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); const long long mod = 1 * 1e18 + 7; int main() { IO; ll i=0, j=0, m=0, n=0, k=0, t=0; cin>>t; while(t--) { cin>>n; string s[3]; for(i=0;i<3;i++) cin>>s[i]; string ans=""; ans.push_back('1'); for(i=0;i<n;i++) ans.push_back('0'); for(i=0;i<n;i++) ans.push_back('1'); cout<<ans<<endl; } return 0; }
#include<bits/stdc++.h> //#include<atcoder/all> using namespace std; //using namespace atcoder; using ll = long long; using Graph = vector<vector<int>>; using P = pair<int, int>; #define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i)) #define rrep(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i)) #define all(x) (x).begin(),(x).end() #define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w) constexpr ll INF = 1LL << 30; constexpr ll mod = 100000; //(ll)1e9 + 7; constexpr double PI = 3.1415926535897932; template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } map<char, int>mp; string s[3]; bool rec(vector<int>v,int index=0) { if (index == mp.size()) { ll N[3] = { 0 }; rep(i, 0, 2) { rep(j, 0, s[i].size()) { if (j == 0 && v[mp[s[i][j]]] == 0)return false; N[i] *= 10; N[i] += v[mp[s[i][j]]]; } } N[2] = N[0] + N[1]; ll n = N[2]; rrep(i, 0, s[2].size()) { if (v[mp[s[2][i]]] != (n % 10))return false; n /= 10; } if (n != 0)return false; rep(i, 0, 3)cout << N[i] << "\n"; return true; } vector<bool>ok(10, true); rep(i, 0, v.size())if (v[i] > -1)ok[v[i]] = false; rep(i, 0, 10) { if (!ok[i])continue; v[index] = i; if (rec(v, index + 1))return true; v[index] = -1; } return false; } int main() { init(); set<char>st; int index = 0; rep(i, 0, 3)cin >> s[i]; rep(i, 0, 3)rep(j, 0, s[i].size())st.insert(s[i][j]); for (auto s : st) { mp[s] = index; index++; } if (st.size() > 10) { cout << "UNSOLVABLE" << "\n"; return 0; } vector<int>v(mp.size(), -1); if(!rec(v)) { cout << "UNSOLVABLE" << "\n"; return 0; } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define MOD 1000000007 vector<string> s(3), ss(3); vector<bool> word(26, false), yet(10, false); vector<int> n(26); void dfs(int x) { if(x == 26) { ss[0] = ss[1] = ss[2] = ""; for(int i = 0; i < 3; i++) { for(int j = 0; j < s[i].size(); j++) { ss[i] += n[s[i][j] - 'a'] + '0'; } } if(ss[0][0] == '0' || ss[1][0] == '0' || ss[2][0] == '0') return; if(stoll(ss[0]) + stoll(ss[1]) == stoll(ss[2])) { cout << ss[0] << endl << ss[1] << endl << ss[2] << endl; exit(0); } return; } if(!word[x]){dfs(x+1);return;} for(int i = 0; i < 10; i++) { if(yet[i]) continue; n[x] = i; yet[i] = true; dfs(x + 1); yet[i] = false; } } int main() { cin >> s[0] >> s[1] >> s[2]; for(int i = 0; i < 3; i++) { for(int j = 0; j < s[i].size(); j++) { word[s[i][j] - 'a'] = true; } } for(int i = 0; i < 26; i++) { if(word[i]) { dfs(i); break; } } puts("UNSOLVABLE"); return 0; }
// Problem: F - GCD or MIN // Contest: AtCoder - AtCoder Beginner Contest 191 // URL: https://atcoder.jp/contests/abc191/tasks/abc191_f // Memory Limit: 1024 MB // Time Limit: 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; typedef long long ll; #define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define mp make_pair #define pb push_back #define ff first #define ss second #define vi vector<int> #define vll vector<ll> #define all(x) (x).begin() , (x).end() mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); #define rnd(x, y) uniform_int_distribution<ll>(x, y)(rng) void dbg(){ cerr << endl; } template<typename Head , typename... Tail> void dbg(Head h , Tail... t){ cerr << h << " "; dbg(t...); } #ifdef EMBI_DEBUG #define debug(...) cerr << "(" << #__VA_ARGS__ << "): ", dbg(__VA_ARGS__) #else #define debug(...) #endif const int max_n = 1e5 + 9; const int mod = 1e9 + 7; const int inf = 1e9; typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; ll power(ll a , ll b) { ll prod = 1; while(b) { if(b&1) prod = (prod*a)%mod; a = (a*a)%mod; b >>= 1; } return prod; } void solve(){ int n; cin >> n; int a[n]; for(int i = 0 ; i < n ; i++){ cin >> a[i]; } sort(a , a+n); map<int , int> m; for(int i = 0 ; i < n ; i++){ for(ll j = 1 ; j*j <= a[i] ; j++){ if(a[i] % j == 0){ m[j] = __gcd(m[j] , a[i]); m[a[i]/j] = __gcd(m[a[i]/j] , a[i]); } } } int ans = 0; for(auto it : m){ if(it.ff == it.ss && it.ff <= a[0])ans++; } cout << ans << "\n"; } signed main(){ int t = 1; // cin >> t; for(int i = 1 ; i <= t ; i++){ solve(); } }
#include <cstdio> #include <cmath> #include <iostream> #include <set> #include <algorithm> #include <vector> #include <map> #include <cassert> #include <string> #include <cstring> #include <queue> using namespace std; #define rep(i,a,b) for(int i = a; i < b; i++) #define S(x) scanf("%d",&x) #define S2(x,y) scanf("%d%d",&x,&y) #define P(x) printf("%d\n",x) #define all(v) v.begin(),v.end() #define FF first #define SS second #define pb push_back #define mp make_pair typedef long long int LL; typedef pair<int, int > pii; typedef vector<int > vi; map<int, vi > M; map<int, vi >::iterator it; int gcd(int a, int b) { if(b == 0) return a; return gcd(b, a % b); } int main() { int n; S(n); int mn = 1000000000; rep(i,1,n+1) { int x; S(x); mn = min(mn, x); for(int j = 1; j * j <= x; j++) if(x % j == 0) { M[j].pb(x); if(j * j != x) M[x / j].pb(x); } } int ans = 0; for(it = M.begin(); it != M.end(); it++) { if(it->FF > mn) break; int g = 0; rep(i,0,it->SS.size()) { g = gcd(it->SS[i], g); } ans += g == it->FF; } P(ans); return 0; }
#include<fstream> #include<iostream> #include<sstream> #include<vector> #include<stack> #include<string> #include<algorithm> #include<cmath> #include<unordered_map> #include<map> #include<queue> #include<tuple> #include<iomanip> #include<bitset> #include<stdio.h> #include<set> #include<array> using namespace std; #define rep(i,n) for(int i=0;i<(int)(n);i++) using graph = vector<vector<int>>; const long long MOD = 1000000007; const long long INF = 1e18; using ll = long long; using P = pair<int,int>; using matrix = vector<vector<ll>>; void chmin(int &x,int y){ x = min(x,y); } int digit(ll x){ int count = 1; while(x/10>0){ count ++; x /= 10; } return count; } bool prime(ll x){ if(x==1) return false; for(ll i=2;i*i<=x;i++){ if(x%i==0) return false; } return true; } void decom(ll x,map<ll,int> &hatano){ for(ll i=2;i*i<=x;i++){ if(x%i==0&&prime(i)){ while(x%i==0){ x /= i; hatano[i] ++; } } } if(x!=1) hatano[x] ++; } ll speedpow(ll x,ll y){ ll res = 1; ll test = x; for(int i=0;i<31;i++){ if(y&(1<<i)) res *= test; res = res%MOD; test = (test*test)%MOD; } return res; } ll combination(ll x,ll y){ ll test = 1; ll test1 = 1; for(ll i=0;i<y;i++){ test = (test*(x-i))%MOD; test1 = (test1*(i+1LL))%MOD; } return (test * speedpow(test1,MOD-2))%MOD ; } int euclid(int x,int y){ if(y==0) return x; return euclid(y,x%y); } //行列累乗 matrix mul(matrix &a, matrix &b) { int p = a.size(); matrix res(p, vector<long long>(p, 0)); for(int i = 0; i < p; i++) for(int j = 0; j < p; j++) for(int k = 0; k < p; k++) (res[i][j] += a[i][k] * b[k][j]) %= MOD; return res; } matrix pow(matrix m, long long k) { int p = m.size(); matrix res(p, vector<long long>(p, 0)); for(int i = 0; i < p; i++) res[i][i] = 1; // 単位行列にする while(k > 0) { if(k & 1) res = mul(res, m); m = mul(m, m); k >>= 1; } return res; } int main(){ int n,m,q;cin >> n >> m >> q; int v[n],w[n]; vector<P> hatano; int x[m]; vector<P> konishi; int l[q],r[q]; rep(i,n){ cin >> w[i] >> v[i]; hatano.push_back(make_pair(v[i],w[i])); } sort(hatano.rbegin(),hatano.rend()); rep(i,m){ cin >> x[i]; konishi.push_back(make_pair(x[i],i)); } sort(konishi.begin(),konishi.end()); vector<int> ans; rep(i,q){ cin >> l[i] >> r[i]; l[i] --;r[i] --; } rep(i,q){ int test=0; vector<bool> check(m,true); for(int s=l[i];s<=r[i];s++) check[s] = false; rep(j,n){ rep(k,m){ if(konishi[k].first>=hatano[j].second&&check[konishi[k].second]){ test += hatano[j].first; check[konishi[k].second] = false; // cout << hatano[j].first << endl; break; } } } ans.push_back(test); // cout << endl; } for(auto e:ans) cout << e << endl; }
#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; #define DEBUG #ifdef DEBUG inline void debug_print() { cerr << endl; } template <typename T1, typename... T2> void debug_print(const T1 a, const T2 &... b) { cerr << a << ' '; debug_print(b...); } #define debug(...) cerr << __LINE__ << ": [" << #__VA_ARGS__ << "] = " , debug_print(__VA_ARGS__); #else #define debug(...) true #endif inline void print() { cout << '\n'; } template <typename T1, typename... T2> void print(const T1 a, const T2 &... b) { cout << a << ' '; print(b...); } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto e : v) os << e << ' '; return os; } template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { for (auto e : v) os << e << ' '; return os; } template <typename T> ostream &operator<<(ostream &os, const multiset<T> &v) { for (auto e : v) os << e << ' '; return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp) { for (auto e : mp) os << e << ' '; return os; } template <typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } else return false; } template <typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } else return false; } //-------------------------- Libraries --------------------------// //---------------------------- Solve ----------------------------// void solve() { int N, M, Q; cin >> N >> M >> Q; vector<pair<int, int>> vw(N); for (int i = 0; i < N; i++) { int w, v; cin >> w >> v; vw[i] = {v, w}; } sort(vw.rbegin(), vw.rend()); vector<int> x(M); for (int i = 0; i < M; i++) cin >> x[i]; while (Q--) { int L, R; cin >> L >> R; L--; R--; multiset<int> se; for (int i = 0; i < M; i++) { if (L <= i && i <= R) continue; se.insert(x[i]); } int ans = 0; for (auto [v, w] : vw) { auto it = se.lower_bound(w); if (it != se.end()) { ans += v; se.erase(se.find(*it)); } } cout << ans << '\n'; } } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(20); int t = 1; //cin >> t; while (t--) solve(); return 0; }
#include<iostream> #include<unordered_set> #include<vector> #include<map> using namespace std; int main() { char x,y; cin>>x>>y; if(x == y) cout<<x<<"\n"; else if((x == '0' && y == '1') || (x == '1' && y == '0')) cout<<"2\n"; else if((x == '0' && y == '2') || (x == '2' && y == '0')) cout<<"1\n"; else cout<<"0\n"; return 0; } /* */
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll, ll> pll; typedef vector<ll> vll; typedef vector<vector<ll>> vvll; typedef vector<pll> vpll; typedef vector<vpll> vvpll; typedef vector<bool> vbl; typedef vector<vector<bool>> vvbl; void INX(){} template<typename Head, typename... Tail> void INX(Head&& head, Tail&&... tail) { cin >> head; INX(forward<Tail>(tail)...); } void OUTX(){} template<typename Head, typename... Tail> void OUTX(Head&& head, Tail&&... tail) { cout << head << endl; OUTX(forward<Tail>(tail)...); } void OUTX2(){cout << endl;} template<typename Head, typename... Tail> void OUTX2(Head&& head, Tail&&... tail) { cout << head << ' '; OUTX2(forward<Tail>(tail)...); } #define ADD emplace_back #define MP make_pair #define __LONG_LONG_MIN__ (-__LONG_LONG_MAX__ - 1) //#define MOD 1000000007 // 10^9 + 7 //setprecision(10) int main() { ll M, H; INX(M, H); OUTX((H % M == 0 ? "Yes" : "No")); return 0; }
#include <bits/stdc++.h> #define FOR(i, begin, end) for(int i=(begin);i<(end);i++) #define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--) #define rep(i, n) FOR(i,0,n) #define irep(i, n) IFOR(i,0,n) #define all(v) begin(v), end(v) using namespace std; using ll = long long; using ull = unsigned long long; using P = pair<int, int>; using PLL = pair<ll, ll>; using VI = vector<int>; using VLL = vector<ll>; using VB = vector<bool>; using VP = vector<P>; using Graph2 = vector<vector<int>>; using PQ = priority_queue<int>; template<typename T>istream& operator>>(istream&s,vector<T>&v){for(auto &i: v)s>>i;return s;} 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; } bool second_compare(P a,P b){if(a.second!=b.second){return a.second<b.second;} else return true;} int main() { int n; cin >> n; VI ans(n); ans[0] = 2*3; ans[1] = 2*5; ans[2] = 3*5; int idx = 3; for (int i = 16; ; i++) { if (idx >= n) break; // 倍数なら追加 if (i % (2*3) == 0 || i % (2*5) == 0 || i % (3*5) == 0) { ans[idx] = i; idx++; } } for (auto e: ans) { cout << e << ' '; } cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; long long n, sum; int main() { cin >> n; for (long long i=1000, ert=0; ; i*=1000, ert++) { sum+=(min(n, i-1)-i/1000+1)*ert; if (n<i) { cout << sum << "\n"; return 0; } } return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int inf=0x3f3f3f3f; const ll INF=0x3f3f3f3f3f3f3f; const double pi=3.1415926535897932384626; inline ll read(){ ll x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9'){ if(ch=='-') f=-1; ch=getchar(); } while(ch>='0'&&ch<='9'){ x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); } return x*f; } ll n; ll gcd(ll a,ll b){ if(!b) return a; return gcd(b,a%b); } int main(){ n=read(); ll ans=1; for(ll i=2;i<=n;++i) ans=ans*i/gcd(ans,i); printf("%lld\n",ans+1); return 0; }
/* AtCoder Regular Contest 109 https://atcoder.jp/contests/arc109/tasks/arc109_a By 242 */ /*     ∧__∧ ☆・*。・゜+.・*。    (´・ω・) ☆・*。    /ヽ○==○ _____ _____ ・゜+.・*。   /  || |100%||AC| ☆・*。・*。   し' ̄(_)) ̄(_)) ̄(_)) ̄ */ /* fstream fcout; fcout.open("out.txt",ios::out); */ #include <bits/stdc++.h> using namespace std; #define Please return #define AC 0; #define rep(i,n) for(ll i=0;i<n;i++) #define FOR(i,a,b) for(ll i=a;i<b;i++) #define ALL(x) (x.begin(),x.end()) #define ff first #define ss second struct Ios { Ios() { ios_base::sync_with_stdio(0);cin.tie(0); } }__ios; using ll = long long; using pii = pair<int,int>; using pll = pair<ll,ll>; void HI(int x){cout<<"HI "<<x<<'\n';}; //code start from here int main() { ll N; cin>>N; cout<<2329089562801<<'\n'; }
#include <bits/stdc++.h> //#include <atcoder/all> using namespace std; #define rep(i,x,y) for(ll i=(x);i<(y);i++) #define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--) #define all(x) (x).begin(),(x).end() #define itrout(x) for(int i=0;i<x.size();i++) {cout << x[i] << (i==x.size()-1 ? "\n" : " ");} #ifdef LOCAL #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl #define debugbit(x, n) cerr << #x << " = " << bitset<n>(x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl #define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl #define dassert(...) assert(__VA_ARGS__) #else #define debug(x) #define debugbit(x, n) #define itrdebug(x) #define dassert(...) #endif //#define int long long //using mint = atcoder::modint; typedef long long ll; const ll MOD = 1e9 + 7; const long double EPS = 1e-8; void solve(long long A, long long B){ ll X = (A + B) / 2, Y = (A - B) / 2; cout << X << " " << Y << endl; } signed main(){ // ios_base::sync_with_stdio(false); // cin.tie(NULL); long long A; scanf("%lld",&A); long long B; scanf("%lld",&B); solve(A, B); return 0; }
//#include <atcoder/all> #include <bits/stdc++.h> //using namespace atcoder; using namespace std; typedef long long ll; #define MOD (long long)(1e9+7) #define INF (1LL<<60) #define rep(i,n) for(ll i = 0; i < (n); i++) #define rep1(i,n) for(ll i = 1; i <= (n); i++) template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } // 最大公約数 ll gcd(ll a, ll b) { if(b == 0) return a; return gcd(b, a % b); } // mod m におけるa の逆元 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; } // 素因数分解 vector<pair<ll, ll>> prim; void pf(ll n) { ll s = sqrt(n); ll r = 0; for(ll i = 2; i <= s; i++) { if((n % i) == 0) { r = 0; do { r++; n = n / i; } while((n % i) == 0); prim.push_back({i, r}); } } if(n > s) { prim.push_back({n, 1}); } } void solve() { ll N,W; cin >> N>>W; bool ok = true; // ll N, K; cin >> N >> K; // ll x, y, z; cin >> x >> y >> z; // ll a, b, c; cin >> a >> b >> c; // string s; cin >> s; vector<ll> s(N),t(N),p(N); rep(i, N) cin >> s[i]>>t[i]>>p[i]; vector<ll> im(200200,0); rep(i,N){ im[s[i]]+=p[i]; im[t[i]]-=p[i]; } ll su=0; rep(i,200000){ su+=im[i]; if(su>W)ok=false; } cout << (ok?"Yes":"No") << endl; } int main(void) { // ll t; cin >> t; rep(i, t) solve(); }
#include <bits/stdc++.h> #define MOD 1000000007 #define all(v) v.begin(),v.end() #define ninpo ios_base::sync_with_stdio(false);cin.tie(NULL); #define dbg(x) cout<<#x<<" = "<<(x)<<endl; #define sz(cntainer) (int)cntainer.size() #define tc int t;cin>>t;for(int i=0;i<t;++i) #define ll long long #define pii pair<int,int> using namespace std; /**/ void solve() { ll n; cin>>n; map<int,ll> ct; for (int i = 0; i < n; i++){ int a; cin>>a; ct[a]++; } ll ans= (n*(n-1))/2; for(auto i: ct)ans-=((i.second*(i.second-1))/2); cout<<ans; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ninpo; // tc solve(); }
#include<bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define ff first #define ss second #define pb push_back #define mp make_pair #define PI 3.1415926535897932384626 #define mod 1000000007 #define mod1 998244353 #define ms(arr, v) memset(arr, v, sizeof(arr)) #define fo1(i,a,b) for(int i=a;i<=b;i++) #define deb(x) cout<<x<<"\n"; #define deB(x,y) cout<<x<<" "<<y<<"\n"; #define Deb(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n" #define YES cout<<"YES\n"; #define Yes cout<<"Yes\n"; #define NO cout<<"NO\n"; #define No cout<<"No\n"; #define all(v) (v).begin(),(v).end() #define mk(arr,n,type) type *arr=new type[n]; /*-------------------------------------------------------------------------------------------*/ ll gcd(ll a, ll b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);} ll expo(ll a, ll b, ll m) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % m; a = (a * a) % m; b = b >> 1;} return res;} ll mminvprime(ll a, ll b) {return expo(a, b - 2, b);} ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;} ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} ll mod_div(ll a, ll b, ll m) {a = a % m; b = b % m; return (mod_mul(a, mminvprime(b, m), m) + m) % m;} //only for prime m /*--------------------------------------------------------------------------------------------*/ int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n; cin >> n; mk(arr, n, ll); map<ll, ll> m; for (ll i = 0; i < n; i++) { cin >> arr[i]; m[arr[i]]++; } ll cnt = 0; ll total = n; for (auto i : m) { ll x = i.ss; ll temp = (total - x); cnt += (temp * x); total -= x; } cout << cnt << endl; return 0; }
#include <iostream> #include <iomanip> #include <string> #include <vector> #include <algorithm> #include <utility> #include <functional> #include <set> #include <map> #include <queue> #include <deque> #include <bitset> #include <math.h> #include <random> #include <chrono> using namespace std ; using ll = long long ; using ld = long double ; template<class T> using V = vector<T> ; template<class T> using VV = V<V<T>> ; using pll = pair<ll,ll> ; #define all(v) v.begin(),v.end() ll mod = 998244353 ; long double pie = acos(-1) ; ll INF = 1000000000000 ; void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;} //void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;} ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;} ll lcm(long long a,long long b){return a/gcd(a,b)*b ;} void fix_cout(){cout << fixed << setprecision(20) ;} template<class T> void chmax(T &a,T &b){if(a<b) a = b ;} template<class T> void chmin(T &a,T &b){if(a>b) a = b ;} int main(){ int n,k ; cin >> n >> k ; if(n<k){ cout << 0 << endl ; return 0 ; } VV<ll> dp(n+1,V<ll>(2*n+1,0)) ; dp[0][0] = 1 ; for(int i=1;i<=n;i++){ for(int j=i*2;j>=0;j--){ ll sub = 0 ; if(j*2<=2*n) sub += dp[i][j*2] ; if(j>=2) sub += dp[i-1][j-2] ; dp[i][j] = sub%mod ; } } ll ans = dp[n][k] ; if(k>=2) ans = (ans-dp[n-1][k-2]+mod)%mod ; cout << ans << endl ; }
#include "bits/stdc++.h" using namespace std; void solution() { int n, k; cin >> n >> k; vector<vector<int>> f(n + 1, vector<int> (n + 1, -1)); auto dp = [&](auto &&self, int N, int K) -> int { if (K == 0) return N == 0; if (N <= K) return N == K; if (f[N][K] != -1) return f[N][K]; return f[N][K] = (self(self, N - 1, K - 1) + self(self, N, K * 2)) % 998244353; }; cout << dp(dp, n, k); } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); int tc = 1; #ifdef DEBUG freopen("input.txt", "r", stdin); #endif // cin >> tc; while (tc --) { solution(); cout << "\n"; } }
#include <bits/stdc++.h> #define FOR(i, begin, end) for(int i=(begin);i<(end);i++) #define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--) #define rep(i, n) FOR(i,0,n) #define irep(i, n) IFOR(i,0,n) #define all(v) begin(v), end(v) using namespace std; using ll = long long; using ull = unsigned long long; using P = pair<int, int>; using PLL = pair<ll, ll>; using VI = vector<int>; using VLL = vector<ll>; using VB = vector<bool>; using VP = vector<P>; using Graph2 = vector<vector<int>>; using PQ = priority_queue<int>; template<typename T>istream& operator>>(istream&s,vector<T>&v){for(auto &i: v)s>>i;return s;} 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; } bool second_compare(P a,P b){if(a.second!=b.second){return a.second<b.second;} else return true;} int main() { int n; cin >> n; double x0, y0, xn, yn; cin >> x0 >> y0 >> xn >> yn; double Ox = (x0 + xn) / 2.0; double Oy = (y0 + yn) / 2.0; x0 -= Ox; y0 -= Oy; xn -= Ox; yn -= Oy; double r = sqrt(x0*x0 + y0*y0); double theta = atan2(y0, x0); double t = M_PI*2.0 / (double)n + theta; printf("%.10f %.10f\n", r*cos(t)+Ox, r*sin(t)+Oy); return 0; }
#include<bits/stdc++.h> using namespace std; #define file freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout); #define fo(i, strt, end) for(i=strt;strt<end?i<end:i>end;strt<end?i+=1:i-=1) #define deb(var) cout << #var << " = " << var << endl; #define deba(i, arr, n) fo(i,0, n){cout << arr[i] << " ";} #define all(arr) arr.begin(), arr.end() #define rall(arr) arr.rbegin(), arr.rend() #define autoDeb(arr) for(auto var:arr) cout<<var<<" "; #define sa(arr,n) for(int var = 0; var < n; var++) cin >> arr[var]; #define yes cout << "YES\n" #define no cout << "NO\n" typedef long long ll; typedef vector<int> vi; typedef pair<int,int> pii; typedef map<int,int> mii; /*************************************/ int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); // file; ll n; cin>>n; ll arr[n]; for(auto &i:arr) cin>>i; // autoDeb(arr);cout<<endl; ll sum=0; // int cs[n]; // int css[n]; // for(int i=0;i<n;i++){ // sum+=arr[i]; // cs[i]=sum; // } // sum=0; // for(int i=0;i<n;i++){ // sum+=cs[i]; // css[i]=sum; // } ll mx=-1; ll CS=0; ll CSS=0; for(int i=0;i<n;i++){ mx=max(mx,arr[i]); CS+=arr[i]; CSS+=CS; cout<<fixed<<mx*(i+1)+CSS<<endl; } // sum=accumulate(arr,arr+n,sum); // cout<<sum<<endl; return 0; }
#pragma GCC optimize("O3") #pragma GCC target("avx") #include <cstdio> #include <functional> #include <queue> #include <tuple> using namespace std; int main() { int R, C; scanf("%d%d", &R, &C); int A[250000], B[250000]; int dist[500000], seen[500000] = {0}, cost, pt, to_hide = R * C; priority_queue<pair<int, int>, vector<pair<int, int>>,greater<pair<int, int>>>queue; for(int i = 0; i < R * C; ++i) if(i % C != C - 1) scanf("%d", &A[i]); for(int i = 0; i < (R - 1) * C; ++i) scanf("%d", &B[i]); for(int i = 1; i < to_hide + to_hide; ++i) dist[i] = 10000000; queue.emplace(pair<int, int>(0, 0)); while(!queue.empty()) { tie(cost, pt) = queue.top(); if(pt == to_hide - 1)break; queue.pop(); seen[pt] = true; if(pt < to_hide) { if(!seen[pt + 1] && pt % C != C - 1) { if(cost + A[pt] < dist[pt + 1]) { dist[pt + 1] = cost + A[pt]; queue.emplace(pair<int, int>(dist[pt + 1], pt + 1)); } } if(!seen[pt - 1] && pt % C != 0) { if(cost + A[pt - 1] < dist[pt - 1]) { dist[pt - 1] = cost + A[pt - 1]; queue.emplace(pair<int, int>(dist[pt - 1], pt - 1)); } } if(!seen[pt + C] && pt < to_hide - C) { if(cost + B[pt] < dist[pt + C]) { dist[pt + C] = cost + B[pt]; queue.emplace(pair<int, int>(dist[pt + C], pt + C)); } } if(!seen[pt + to_hide] && cost + 1 < dist[pt + to_hide]) { dist[pt + to_hide] = cost + 1; queue.emplace(pair<int, int>(dist[pt + to_hide], pt + to_hide)); } } else { if(to_hide < pt - C && !seen[pt - C] && cost + 1 < dist[pt - C]) { dist[pt - C] = cost + 1; queue.emplace(pair<int, int>(cost + 1, pt - C)); } if(!seen[pt - to_hide] && cost < dist[pt - to_hide]) { dist[pt - to_hide] = cost; queue.emplace(pair<int, int>(cost, pt - to_hide)); } } } printf("%d\n", dist[to_hide - 1]); }
// #include "pch.h" #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> typedef long long ll; typedef std::pair<int, int> Pii; typedef std::pair<long long, long long> Pll; typedef std::pair<double, double> Pdd; #define rip(i, n, ss) for (int i = (ss);i < (int)( n ); i++) #define all(a) a.begin(), a.end() #define MM << " " << template<typename T> using MaxHeap = std::priority_queue<T>; template<typename T> using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>; template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } # ifndef ONLINE_JUDGE template<typename T> void vdeb(std::vector<T> &bb) { for (int i = 0;i < bb.size();i++) { if (i == bb.size() - 1) std::cout << bb[i]; else std::cout << bb[i] << ' '; } std::cout << '\n'; } template<typename T> void vdeb(std::vector<std::vector<T>> &bb) { for (int i = 0;i < bb.size();i++) { std::cout << i << ' '; vdeb(bb[i]); } std::cout << '\n'; } # endif class UnionFind { int _n; int _size; std::vector<int> par_size; public: UnionFind() :_n(0), _size(0){} UnionFind(int n) : _n(n), _size(0), par_size(n, -1) {} int unite(int a, int b) { assert(0 <= a && a < _n); assert(0 <= b && b < _n); a = root(a), b = root(b); if(a == b) return a; _size--; if(-par_size[a] < -par_size[b]) { par_size[b] += par_size[a]; return par_size[a] = b; } else { par_size[a] += par_size[b]; return par_size[b] = a; } } int root(int a) { assert(0 <= a && a < _n); if(par_size[a] < 0) return a; return par_size[a] = root(par_size[a]); } bool same(int a, int b) { assert(0 <= a && a < _n); assert(0 <= b && b < _n); return root(a) == root(b); } int size(int a) { assert(0 <= a && a< _n); return -par_size[root(a)]; } int size() {return _size;} std::vector<std::vector<int>> groups() { std::vector<int> leader_buf(_n), group_size(_n); for (int i = 0; i < _n; i++) { leader_buf[i] = root(i); group_size[leader_buf[i]]++; } std::vector<std::vector<int>> result(_n); for (int i = 0; i < _n; i++) { result[i].reserve(group_size[i]); } for (int i = 0; i < _n; i++) { result[leader_buf[i]].push_back(i); } result.erase( std::remove_if(result.begin(), result.end(), [&](const std::vector<int>& v) { return v.empty(); }), result.end()); return result; } }; using namespace std; int main() { int n, m; cin >> n >> m; vector<ll> a(n); rip(i,n,0) cin >> a[i]; vector<ll> b(n); UnionFind uf(n); rip(i,n,0) cin >> b[i]; rip(i,m,0) { int x, y; cin >> x >> y; --x;--y; uf.unite(x, y); uf.unite(y, x); } auto da = uf.groups(); rip(i, da.size(), 0) { ll aa = 0, bb = 0; rip(j,da[i].size(), 0) { aa += a[da[i][j]]; bb += b[da[i][j]]; } if(aa != bb) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ss second #define ff first #define all(a) a.begin(), a.end() #define All(a) a.rbegin(), a.rend() #define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.precision(10), cout << fixed template <typename T> T binpow(T base, T exp) { T result = 1; while (exp > 0) { if (exp & 1) result = (result * base); base = (base * base); exp >>= 1; } return result; } int main() { ios; #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif ll n; cin >> n; ll counter = 0; map<ll, bool> mp; for (ll i = 2; i * i <= n; ++i) { ll x = i; for (ll j = 2;; ++j) { x *= i; if (x > n) break; if (mp.find(x) == mp.end()) { counter++; mp[x] = 1; } } } cout << n - counter << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n,num; cin >> n; if(n>=100000) num=100000; else num=n; set<long long> Set; long long tmp,ans=0; for(int i=2;i<num;i++){ for(int j=2;j<34;j++){ tmp = pow(i,j); if(tmp>n) break; Set.insert(tmp); } } cout << (n-Set.size()) << endl; }
#include<bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); int i,n,t,x; bool flag; cin >> t; while(t--) { cin >> n; map<int,bool>mp; for(i=0;i<n;i++) { cin >> x; mp[x] ^= 1; } if(n & 1) { cout << "Second\n"; continue; } flag=1; for(auto it : mp) { if(it.second) { cout << "First\n"; flag=0; break; } } if(flag)cout << "Second\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; // エラトステネスのふるい vector<int> primes; void sieve(int n) { set<int> primes_set; for (int i{2}; i <= n; ++i) primes_set.insert(i); for (int i{2}; i <= n; ++i) { if (primes_set.find(i) != primes_set.end()) { for (int j{i * 2}; j <= n; j += i) { primes_set.erase(j); } } } for (const auto &p : primes_set) primes.push_back(p); } int main() { sieve(50); int N; cin >> N; vector<int> X(N); for (int i{}; i < N; ++i) cin >> X[i]; ll ans{numeric_limits<ll>::max()}; int len = primes.size(); for (int i{1}; i < (1 << len); ++i) { set<int> Y; for (int j{}; j < len; ++j) { if (i & (1 << j)) { Y.insert(primes[j]); } } bool succeed{true}; for (const auto &x : X) { bool coprime{}; for (const auto &y : Y) { if (x % y == 0) { coprime = true; break; } } if (!coprime) { succeed = false; break; } } if (succeed) { ll mul{1}; for (const auto &y : Y) { mul *= y; } ans = min(ans, mul); } } cout << ans << endl; return 0; }
//DUEL #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #define x first #define y second #define pii pair<int,int> #define pb push_back #define eb emplace_back #pragma GCC optimize("unroll-loops") #define shandom_ruffle(a, b) shuffle(a, b, rng) #define vi vector<int> #define vl vector<ll> #define popcnt __builtin_popcount #define popcntll __builtin_popcountll #define all(a) begin(a),end(a) using namespace std; using namespace __gnu_pbds; using ll=long long; using ull=unsigned long long; using ld=long double; int MOD=1000000007; int MOD2=998244353; vector<int> bases; const ll LLINF=1ll<<60; const char en='\n'; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void yes() {cout<<"YES"<<en; exit(0);} void no() {cout<<"NO"<<en; exit(0);} inline int rund() {int x576363482791fuweh=rng();return abs(x576363482791fuweh)%RAND_MAX;} template<class T> void prVec(vector<T> w,bool fl=false) { cout<<w.size()<<en; for (int i=0;i<int(w.size())-1;++i) cout<<w[i]<<' '; if (w.size()) cout<<w[w.size()-1]<<en; if (fl) cout<<flush; } void M998() { swap(MOD,MOD2); } ll raand() { ll a=rund(); a*=RAND_MAX; a+=rund(); return a; } #define rand raand ll raaand() { return raand()*(MOD-7)+raand(); } template<class T> vi compress(vector<T>&v) { set<T> s; for (auto a: v) s.insert(a); vector<T> o(all(s)); vi nv; for (int i=0;i<(int)v.size();++i) nv.pb(lower_bound(all(o),v[i])-o.begin()); return nv; } string to_upper(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A'; return a; } string to_lower(string a) { for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A'; return a; } ll sti(string a,int base=10) { ll k=0; for (int i=0;i<(int)a.size();++i) { k*=base; k+=a[i]-'0'; } return k; } template<class T> void eras(vector<T>& a,T b) { a.erase(find(a.begin(),a.end(),b)); } string its(ll k,int base=10) { if (k==0) return "0"; string a; while (k) { a.push_back((k%base)+'0'); k/=base; } reverse(a.begin(),a.end()); return a; } ll min(ll a,int b) { if (a<b) return a; return b; } ll min(int a,ll b) { if (a<b) return a; return b; } ll max(ll a,int b) { if (a>b) return a; return b; } ll max(int a,ll b) { if (a>b) return a; return b; } ll gcd(ll a,ll b) { if (b==0) return a; return gcd(b,a%b); } ll lcm(ll a,ll b) { return a/gcd(a,b)*b; } template<class T,class K> pair<T,K> mp(T a,K b) { return make_pair(a,b); } inline int mult(ll a,ll b) { return (a*b)%MOD; } inline int pot(int n,int k) { if (k==0) return 1; ll a=pot(n,k/2); a=mult(a,a); if (k%2) return mult(a,n); else return a; } int divide(int a,int b) { return mult(a,pot(b,MOD-2)); } inline int sub(int a,int b) { if (a-b>=0) return a-b; return a-b+MOD; } inline int add(int a,int b) { if (a+b>=MOD) return a+b-MOD; return a+b; } bool prime(ll a) { if (a==1) return 0; for (int i=2;i<=round(sqrt(a));++i) { if (a%i==0) return 0; } return 1; } int dx[]={0,1,0,-1}; int dy[]={1,0,-1,0}; const int N=400010; int m,n,ed,s; bool bio[N]; vi ch[N]; void dfs(int i) { ed+=ch[i].size(); ++s; bio[i]=1; for (auto a: ch[i]) if (!bio[a]) dfs(a); } int main() { ios_base::sync_with_stdio(false); cin.tie(0); for (int i=0;i<10;++i) bases.push_back(rand()%(MOD-13893829*2)+13893829); cin>>n; for (int i=0;i<n;++i) { int a,b; cin>>a>>b; ch[a].pb(b); ch[b].pb(a); } int an=400000; for (int i=1;i<=400000;++i) if (!bio[i]) { --an; ed=0; s=0; dfs(i); if (ed>=s*2) ++an; } cout<<an<<en; }
#include<bits/stdc++.h> using namespace std; #define ff first #define ss second #define int long long #define pb push_back #define pii pair<int,int> #define vi vector<int> #define mii map<int,int> #define pqb priority_queue<int> #define pqs priority_queue<int,vi,greater<int> > #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define inf 1e18 #define ps(x,y) cout<<setprecision(y)<<x #define mk(arr,n,type) type *arr=new type[n]; #define w(x) int x; cin>>x; while(x--) #define pw(b,p) pow(b,p) + 0.1 #define endl "\n" mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void __print(int32_t 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 void fastIO() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int power(int a,int b,int md) { int ans=1; while(b) { if(b&1) ans*=a; ans%=md; a*=a; a%=md; b>>=1; } return ans; } int find(map<int,int> &mp,int x) { //debug("T",x); if(!mp.count(x)) return x; if(mp[x]==x) return x; return mp[x]=find(mp,mp[x]); } void solve() { int n; cin>>n; map<int,int> mp; for(int i=0;i<n;i++) { int x,y; cin>>x>>y; //debug(mp); //debug(i); if(!mp.count(x)&&!mp.count(y)) mp[min(x,y)]=max(x,y); else if(!mp.count(x)) mp[x]=find(mp,y); else if(!mp.count(y)) mp[y]=find(mp,x); else { // debug("J",mp); int px=find(mp,x),py=find(mp,y); if(!mp.count(px)) { mp[px]=py; } else if(!mp.count(py)) { mp[py]=px; } } // debug(mp); } mp.erase(0); cout<<mp.size(); } int32_t main() { fastIO(); //w(t) { solve(); cout<<endl; } return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using P = pair<int, int>; int main() { ll n; cin >> n; vector<ll> x(n), y(n); rep(i, n) cin >> x[i] >> y[i]; int m; cin >> m; vector<ll> sousa11(m + 1), sousa12(m + 1), sousa21(m + 1), sousa22(m + 1); vector<ll> addx(m + 1), addy(m + 1); sousa11[0] = 1, sousa12[0] = 0; sousa21[0] = 0, sousa22[0] = 1; rep(i, m) { int op; cin >> op; int op11, op12; int op21, op22; if (op == 1) { op11 = 0, op12 = 1; op21 = -1, op22 = 0; } else if (op == 2) { op11 = 0, op12 = -1; op21 = 1, op22 = 0; } else if (op == 3) { op11 = -1, op12 = 0; op21 = 0, op22 = 1; int p; cin >> p; addx[i + 1] = 2 * p; } else if (op == 4) { op11 = 1, op12 = 0; op21 = 0, op22 = -1; int p; cin >> p; addy[i + 1] = 2 * p; } sousa11[i + 1] = op11 * sousa11[i] + op12 * sousa21[i]; sousa12[i + 1] = op11 * sousa12[i] + op12 * sousa22[i]; sousa21[i + 1] = op21 * sousa11[i] + op22 * sousa21[i]; sousa22[i + 1] = op21 * sousa12[i] + op22 * sousa22[i]; addx[i + 1] += op11 * addx[i] + op12 * addy[i]; addy[i + 1] += op21 * addx[i] + op22 * addy[i]; } int q; cin >> q; rep(i, q) { int a, b; cin >> a >> b; b--; ll ansx = sousa11[a] * x[b] + sousa12[a] * y[b] + addx[a]; ll ansy = sousa21[a] * x[b] + sousa22[a] * y[b] + addy[a]; cout << ansx << " " << ansy << endl; } }
#include<bits/stdc++.h> using namespace std; namespace mymtx{ array<array<int64_t,3>,3> mult(array<array<int64_t,3>,3> a, array<array<int64_t,3>,3> b){ array<array<int64_t,3>,3> ret{{ {0,0,0}, {0,0,0}, {0,0,0} }}; for(int64_t i=0;i<3;i++){ for(int64_t j=0;j<3;j++){ for(int64_t k=0;k<3;k++){ ret[i][j] += a[i][k]*b[k][j]; } } } return ret; } array<int64_t,3> mult(array<array<int64_t,3>,3> a, array<int64_t,3> b){ array<int64_t,3> ret{0,0,0}; for(int64_t i=0;i<3;i++){ for(int64_t k=0;k<3;k++){ ret[i] += a[i][k]*b[k]; } } return ret; } } int main(){ cin.tie(0); ios::sync_with_stdio(false); int64_t n; cin >> n; vector<array<int64_t,3>> x(n); for(int64_t i=0;i<n;i++){ cin >> x[i][0] >> x[i][1]; x[i][2] = 1; } int64_t m; cin >> m; vector<array<array<int64_t,3>,3>> mtx(m+1); mtx[0] = {{ {1,0,0}, {0,1,0}, {0,0,1} }}; for(int64_t i=1;i<=m;i++){ int64_t op[2]={0,0}; cin >> op[0]; if(op[0]==1){ array<array<int64_t,3>,3> tmp{{ {0,1,0}, {-1,0,0}, {0,0,1} }}; mtx[i] = mymtx::mult( tmp ,mtx[i-1]); }else if(op[0]==2){ array<array<int64_t,3>,3> tmp{{ {0,-1,0}, {1,0,0}, {0,0,1} }}; mtx[i] = mymtx::mult( tmp ,mtx[i-1]); }else if(op[0]==3){ cin >> op[1]; array<array<int64_t,3>,3> tmp{{ {-1,0,2*op[1]}, {0,1,0}, {0,0,1} }}; mtx[i] = mymtx::mult( tmp ,mtx[i-1]); }else if(op[0]==4){ cin >> op[1]; array<array<int64_t,3>,3> tmp{{ {1,0,0}, {0,-1,2*op[1]}, {0,0,1} }}; mtx[i] = mymtx::mult( tmp ,mtx[i-1]); } } int64_t q; cin >> q; array<int64_t,3> ans{0,0,0}; for(int64_t i=0,a,b;i<q;i++){ cin >> a >> b; ans = mymtx::mult(mtx[a],x[b-1]); cout << ans[0] << " " << ans[1] << "\n"; } return 0; }
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> ii; #define pb push_back #define T ll testx; cin>>testx; while(testx--) #define print(name) for(auto t:name){cout<<t<<" ";}cout<<endl; #define printii(name) for(auto t:name){cout<<t.first<<" "<<t.second<<endl;} #define mod 1000000007 #define modx 998244353 #define inf 2000000000000000000 #define mem(name,val) memset(name,val,sizeof(name)) #define f(n) for(ll i=0;i<n;i++) #define rep(i,a,n) for(ll i=a;i<n;i++) #define endl "\n" #define popcount(x) __builtin_popcountll(x) #define precise cout<<fixed<<setprecision(15) const long double pi = acos(-1); ll gcd(ll a,ll b){if(b==0){return a;}return gcd(b,a%b);} 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 int n,x,a,b;cin>>n; string s;cin>>s; string s1=s.substr(0,n); string t=s.substr(n); int q;cin>>q; ll ok=1; while(q--) { cin>>x>>a>>b; if(x==1){ a--;b--; if(ok==1){ if(a<=n-1&&b<=n-1) { swap(s1[a],s1[b]); } else if(a<=n-1&&b>n-1) { b-=n;swap(s1[a],t[b]); } else { a-=n;b-=n;swap(t[a],t[b]); } } else { if(a<=n-1&&b<=n-1) { swap(t[a],t[b]); } else if(a<=n-1&&b>n-1) { b-=n;swap(t[a],s1[b]); } else { a-=n;b-=n;swap(s1[a],s1[b]); } } } else { ok=1-ok; } } if(ok){cout<<s1<<t;}else{cout<<t<<s1;} }
#include<bits/stdc++.h> using namespace std; #define pb push_back typedef long long ll; const int maxn=2e5+4; vector <int>e[maxn]; int dep[maxn]; ll bt[maxn]; struct node{ int u,v; }ee[maxn]; void dfs(int u,int pa){ dep[u]=dep[pa]+1; for(auto v:e[u]){ if(v!=pa)dfs(v,u); } } void dfs2(int u,int pa){ for(auto v:e[u]){ if(v!=pa){ bt[v]+=bt[u]; dfs2(v,u); } } } void f(int u,int v,int x){ if(dep[u]>dep[v]){ bt[u]+=x; } else{ bt[1]+=x; bt[v]-=x; } } int main(){ int n; scanf("%d",&n); for(int i=1;i<n;i++){ int u,v; scanf("%d%d",&u,&v); ee[i].u=u;ee[i].v=v; e[u].pb(v); e[v].pb(u); } dfs(1,0); int q; scanf("%d",&q); for(int i=1;i<=q;i++){ int t,id,x; scanf("%d%d%d",&t,&id,&x); int u=ee[id].u,v=ee[id].v; if(t==2)swap(u,v); f(u,v,x); } dfs2(1,0); for(int i=1;i<=n;i++) printf("%lld\n",bt[i]); return 0; }
#include <bits/stdc++.h> #define mp make_pair #define fi first #define se second #define pb push_back #define eb emplace_back #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define forn(i, n) for (int i = 0; i < (int)(n); ++i) #define for1(i, n) for (int i = 1; i <= (int)(n); ++i) #define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i) #define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i) #define rep(i, l, r) for (int i = (l); i <= (r); i++) #define per(i, r, l) for (int i = (r); i >= (l); i--) #define ms(x, y) memset(x, y, sizeof(x)) #define SZ(x) int(x.size()) #define ok cerr<<"ok"<<endl #define db(x) cerr<<(#x)<<'='<<(x)<<endl using namespace std; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<pii> vpi; typedef vector<vi> vvi; typedef long long i64; typedef vector<i64> vi64; typedef vector<vi64> vvi64; typedef pair<i64, i64> pi64; typedef double ld; template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; } template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; } //1.integer overflow (1e5 * 1e5) (2e9 + 2e9) //2.runtime error //3.boundary condition int n,x; string s; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed; #ifdef LOCAL_DEFINE freopen("input.txt", "r", stdin); #endif cin>>n>>x; cin>>s; forn(i, n){ if(s[i]=='o') ++x; else{ --x; if(x<0) x=0; } } cout<<x<<endl; #ifdef LOCAL_DEFINE cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; #endif return 0; }
#include <iostream> #include <string> using namespace std; int main() { int n, x; string s; cin >> n >> x >> s; for(int i = 0; i < n; ++i) { if(s[i] == 'o') x++; else { if(x > 0) x--; } } cout << x << endl; }
#include <bits/stdc++.h> using ull = unsigned long long int; using ll = long long; using ld = long double; using pii = std::pair<int,int>; using pll = std::pair<ll, ll>; using vi = std::vector<int> ; using vvi = std::vector<vi> ; using vll = std::vector<ll>; using vvll = std::vector<vll>; using vd = std::vector<double> ; using vvd = std::vector<vd> ; using qi = std::queue<int> ; using vpii = std::vector<std::pair<int, int> >; using vpll = std::vector<pll>; using namespace std; #define rep(i,j) for(int (i)=0;(i)<(j);(i)++) #define drep(i,j) for(int (i)=(j);(i) >= 0;(i)--) template<class T1, class T2> inline void chmin(T1 &a, T2 b){if(a > b) a = b;} template<class T1, class T2> inline void chmax(T1 &a, T2 b){if(a < b) a = b;} template<class T> inline void pri(T a){cout << a << endl;} template<class Z> using vec = vector<Z>; template<class T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>; inline void IN(void){ return; } template <typename First, typename... Rest> void IN(First& first, Rest&... rest){ cin >> first; IN(rest...); return; } inline void OUT(void){ cout << endl; return; } template <typename First, typename... Rest> void OUT(First first, Rest... rest){ cout << first << " " ; OUT(rest...); return; } const int max_n = 3 * (1e5) + 1; const int max_m = 83 * (1e5) + 1; const ll INF = 8000000000000000000; int n,m,k; ll N; int h,w; string S; int a,b,c; vi v; int ans; double x,y,z; vector<int> G[1010101]; int score[1010101]; pair<long,long> Extended_Euclid(ll a, ll b) { if(b == 0)return {1,0}; pair<long,long> e = Extended_Euclid(b,a%b); return {e.second,e.first - a/b * e.second}; } long long int get_mod(ll a, ll mod) { return (a%mod + mod)%mod; } pair<long long int, long long int> calc(long long int b1, long long int mod1, long long int b2, long long int mod2) { pair<long long int,long long int> e = Extended_Euclid(mod1,mod2); long long int d = e.first * mod1 + e.second * mod2; if( (b1-b2)%d != 0)return {-1,0}; long long int lcm = mod1 * mod2 / d; long long tmp = (b2 - b1)/d * e.first % (mod2/d); long long x = get_mod(b1 + mod1 * tmp, lcm); return {x,lcm}; } pair<long long int, long long int> CRT(vector<long long int> &b, vector<long long int> &mod) { pair<long long int,long long int> ans = {0,1}; int N = b.size(); for(int i=0;i<N;i++) { ans = calc(ans.first,b[i],ans.second, mod[i]); } return ans; } void solve() { ll X,Y,P,Q; IN(X,Y,P,Q); ll ans = INF; for(ll t1 = X;t1 < X+Y; t1++)for(ll t2 = P;t2 < P+Q;t2++) { auto e = calc(t1,2*(X+Y),t2,P+Q) ; if(e.first > 0)chmin(ans,e.first); } if(ans == INF) { cout << "infinity" << endl; return ; } cout << ans << endl; } signed main (int argc, char* argv[]) { cin.tie(0); ios::sync_with_stdio(false); int cases=1; IN(cases); while(cases--)solve(); //pri(ans); //for(auto c : ans){cout << c << endl;} //cout << fixed << setprecision(15) << ans << endl; return 0; }
#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=2e9;//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; ll exgcd(ll a,ll b,ll &x,ll &y) { if(!a&&!b) return -1; if(!b){ x=1,y=0; return a; } ll d=exgcd(b,a%b,y,x); y-=a/b*x; return d; } ll solve(ll a,ll b,ll c) { if(!c) return 0; ll g=__gcd(a,b); if(c%g) return -1; ll x,y; exgcd(a,b,x,y); x*=(c/g),y*=(c/g); return pos_mod(x,b/g); } int main() { int T=qi(); while(T--) { ll x=ql(),y=ql(),p=ql(),q=ql(); ll ans=infl; for(ll i=p;i<=p+q-1;++i){ ll res=solve(2*(x+y),p+q,i-x); if(res==-1) continue; gmn(ans,res*2*(x+y)+x); } for(ll i=x;i<=x+y-1;++i){ ll res=solve(p+q,2*(x+y),i-p); if(res==-1) continue; gmn(ans,res*(p+q)+p); } if(ans==infl) puts("infinity"); else pl(ans),pe(); } return 0; }
#include<bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; // #define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> using namespace std; #define ll long long int #define pll pair<ll,ll> #define vll vector<ll> #define pi 3.141592653589793238 #define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define precise(x) fixed<<setprecision(x) #define mod 1000000007 #define mod2 998244353 #define endl "\n" void solve() { string s; cin>>s; cout<<s[1]<<s[2]<<s[0]; return; } int main() { FAST; ll q; q=1; // cin>>q; while(q--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long int #define pb emplace_back #define mp make_pair #define fi first #define se second #define all(v) v.begin(),v.end() #define run ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0); #define mod 1000000007 #define decimal(n,k) cout<<fixed<<setprecision(k)<<n<<endl #define LL_MAX LLONG_MAX #define yes cout<<"YES"<<endl #define no cout<<"NO"<<endl #define maxa(v) *max_element(v, v + v.size()) #define mina(v) *min_element(v, v + v.size()) int exp(int x,int y){int res=1;x=x%mod;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;} int modinv(int x){return exp(x,mod-2);} int add(int a,int b){a%=mod,b%=mod;a=((a+b)%mod+mod)%mod;return a;} int sub(int a,int b){a%=mod,b%=mod;a=((a-b)%mod+mod)%mod;return a;} int mul(int a,int b){a%=mod,b%=mod;a=((a*b)%mod+mod)%mod;return a;} int gcd(int a, int b){if (b == 0)return a; return gcd(b, a % b);} int Log2n( int n){ return (n > 1) ? 1 + Log2n(n / 2) : 0;} int fac[100009];int ncr_mod(int n,int k){int ans=fac[n];ans*=modinv(fac[k]);ans%=mod;ans*=modinv(fac[n-k]);ans%=mod;return ans;} vector<int>v_prime;void Sieve(int n){bool prime[n + 1];memset(prime,true,sizeof(prime));for (int p = 2; p*p <=n;p++){if(prime[p] ==true) {for(int i = p*p; i<= n; i += p)prime[i]=false;}}for(int p = 2;p<= n;p++)if (prime[p])v_prime.pb(p);} vector<int>v_factor;void factors(int n){ for (int i=1; i<=sqrt(n); i++) {if (n%i == 0) {if (n/i == i) v_factor.pb(i);else { v_factor.pb(i),v_factor.pb(n/i);};} } sort(all(v_factor)); } void out(vector<int>&a){for(int i=0;i<a.size();i++) cout<<a[i]<<" "; cout<<endl;} // s.top().second; signed main() { run; /* open for mod factorial fac[0]=1; for(int i=1;i<100009;i++) { fac[i]=fac[i-1]*i; fac[i]%=mod; } */ /* for sieve open this and use v_prime int pp=pow(10,6)+100000; Sieve(pp); */ // USE v_factor For calculating factors int t=1; //cin>>t; while(t--) { // vector< pair <int,int> > vp; // map<int,int>mp; // x.second-->frequency // set<int>st; int n,i,x,y,ok=0,sum=0,ans=0,j,k,cnt=0,m,c=0; int h[100009]={0}; //cin>>n; string s; cin>>s; // vector<int>a(n,0),v; cout<<s[1]<<s[2]<<s[0]<<endl; } }
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cctype> typedef long long ll; template<typename T> inline void read(T &x) { x = 0; char c = getchar(); bool flag = false; while (!isdigit(c)) { if (c == '-') flag = true ;c = getchar(); } while (isdigit(c)) x = x * 10 + (c ^ 48), c = getchar(); if (flag) x = -x; } using namespace std; ll n, m, mm; ll P; inline ll quickpow(ll x, ll k) { ll res = 1; while (k) { if (k & 1) res = res * x % P; x = x * x % P; k >>= 1; } return res; } int main() { read(n), read(m); mm = 1ll * m * m; P = mm; ll ans = quickpow(10, n) / m; printf("%lld\n", ans); return 0; }
#include <iostream> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); int a, b, c; cin >> a >> b; if (a == b) { c = b; } else { c = 3 - a - b; } cout << c << endl; return 0; }
#include<stdio.h> #include<stdlib.h> #include<bits/stdc++.h> //Do DEBUG OR NOT #define DEBUG #ifdef DEBUG #define debug(var) do{std::cout << #var << " : ";view(var);}while(0) template<typename T> void view(T e){std::cout << e << std::endl;} template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;} template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } } #else #define debug(...) true #endif #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; typedef long long ll; //prototype declaration ll pow_mod(ll n, ll k, ll m);//繰り返し二乗法 return val:(n^k)%m ll gcd(ll a, ll b);//最大公約数 2引数 ll ngcd(vector<ll> a); ll lcm(ll a, ll b);//最小公倍数 2引数 ll nlcm(vector<ll> numbers); bool isPrime(ll x);//素数判定 ll digsum(ll n);//桁和 vector<ll> enum_div(ll n);//約数全列挙 ll stringcount(string s, char c);//特定文字カウント ll pow_ten(ll n){ ll x=1; for(ll i=0;i<n;i++){ x*=10; } return x; } //__________________________main__________________________ int main(){ ll N; cin>>N; ll i=0; ll times=1000; for(i=0;i<5;i++){ if(N/times==0) break; times*=1000; } //debug(i); ll ans=0; if(i>0){ for(ll j=1;j<i;j++){ ans+=(pow_ten((j+1)*3)-pow_ten(j*3))*j; //debug(ans); } ans+=(N-pow_ten(i*3)+1)*i; } //debug(pow_ten(10)); cout<<ans<<endl; return 0; } //__________________________functions_____________Ctrl+K,Ctrl+0 //繰り返し二乗法関数 ll pow_mod(ll n, ll k, ll m){//r:(n^k)%m ll r=1; for(;k>0;k=k>>1){ if(k&1) r=(r*n)%m; n = (n*n) % m; } return r; } //最大公約数 2引数 ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; } //最大公約数 n引数 ll ngcd(vector<ll> a){ ll res; res = a[0]; for(int i = 1; i < a.size() && res != 1; i++) { res = gcd(a[i], res); } return res; } //最小公倍数 2引数 ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } //最小公倍数 n引数 ll nlcm(vector<ll> numbers) { ll res; res = numbers[0]; for (int i = 1; i < numbers.size(); i++) { res = lcm(res, numbers[i]); } return res; } //素数判定 bool isPrime(ll x){ ll i; if(x < 2)return 0; else if(x == 2) return 1; if(x%2 == 0) return 0; for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0; return 1; } //桁和 ll digsum(ll n) { ll res = 0; while(n > 0) { res += n%10; n /= 10; } return res; } //約数全列挙 vector<ll> enum_div(ll n){ vector<ll> ret; for(int i = 1 ; i*i <= n ; ++i){ if(n%i == 0){ ret.push_back(i); if(i != 1 && i*i != n){ ret.push_back(n/i); } } } return ret; } //特定文字カウント ll stringcount(string s, char c) { return count(s.cbegin(), s.cend(), c); }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using pii = pair<int, int>; int n; vector<int> a, b; vector<vector<int>> e; vector<int> depth; vector<ll> ans; void dfs_depth(int v, int d) { depth[v] = d; for (auto nv : e[v]) { if (depth[nv] != -1) continue; dfs_depth(nv, d + 1); } } void dfs_ans(int v, ll tot) { tot += ans[v]; ans[v] = tot; for (auto nv : e[v]) { if (depth[v] > depth[nv]) continue; dfs_ans(nv, tot); } } int main() { cin >> n; a.resize(n - 1); b.resize(n - 1); e.resize(n); rep(i, n - 1) { cin >> a[i] >> b[i]; a[i]--; b[i]--; e[a[i]].push_back(b[i]); e[b[i]].push_back(a[i]); } depth.assign(n, -1); dfs_depth(0, 0); ans.resize(n); int q; cin >> q; rep(i, q) { int t, e, x; cin >> t >> e >> x; e--; int ok, ng; if (t == 1) { //b[e]を通らない ok = a[e]; ng = b[e]; } else { //a[e]を通らない ok = b[e]; ng = a[e]; } if (depth[ok] < depth[ng]) { //根に足す ans[0] += x; ans[ng] -= x; } else { //部分木に足す ans[ok] += x; } } dfs_ans(0, 0); rep(i, n) cout << ans[i] << endl; return 0; }
// Knapsack DP is harder than FFT. #include<bits/stdc++.h> using namespace std; typedef int64_t ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; #define ff first #define ss second #define pb emplace_back #define FOR(i,n) for(int i=0;i<(n);++i) #define FOO(i,a,b) for(int i=(a);i<=int(b);++i) #define OOF(i,a,b) for(int i=(a);i>=int(b);--i) #define AI(x) (x).begin(),(x).end() template<class I>bool chmax(I&a,I b){return a<b?(a=b,true):false;} template<class I>bool chmin(I&a,I b){return b<a?(a=b,true):false;} template<class V>void lisan(V&v){sort(AI(v));v.erase(unique(AI(v)),v.end());} template<class V,class T>int lspos(const V&v,T x){return lower_bound(AI(v),x)-v.begin();} template<class...T>void RI(T&...t){(...,(cin>>t));} template<class...T>void PL(T...t){int c=sizeof...(T);if(!c){cout<<'\n';return;}(...,(cout<<t<<(--c?' ':'\n')));} constexpr inline ll cdiv(ll x,ll m){return x/m+(x%m?(x<0)^(m>0):0);} constexpr inline ll mpow(ll x,ll e,ll m){ll r=1;for(x%=m;e;e/=2,x=x*x%m)if(e&1)r=r*x%m;return r;} #ifdef OWO #define safe cerr<<"\033[1;32m"<<__PRETTY_FUNCTION__<<" - "<<__LINE__<<" JIZZ\033[0m\n" #define debug(args...) SDF(#args, args) #define OIU(args...) ostream& operator<<(ostream&O,args) #define LKJ(S,B,E,F) template<class...T>OIU(S<T...>s){O<<B;int c=0;for(auto i:s)O<<(c++?", ":"")<<F;return O<<E;} LKJ(vector,'[',']',i)LKJ(deque,'[',']',i)LKJ(set,'{','}',i)LKJ(multiset,'{','}',i)LKJ(unordered_set,'{','}',i)LKJ(map,'{','}',i.ff<<':'<<i.ss)LKJ(unordered_map,'{','}',i.ff<<':'<<i.ss) template<class...T>OIU(pair<T...>p){return O<<'('<<p.ff<<','<<p.ss<<')';} template<class T,size_t N>OIU(array<T,N>a){return O<<vector<T>(AI(a));} template<class...T>OIU(tuple<T...>t){return O<<'(',apply([&O](T...s){int c=0;(...,(O<<(c++?", ":"")<<s));},t),O<<')';} template<class...T>void SDF(const char* s,T...a){int c=sizeof...(T);if(!c){cerr<<"\033[1;32mvoid\033[0m\n";return;}(cerr<<"\033[1;32m("<<s<<") = (",...,(cerr<<a<<(--c?", ":")\033[0m\n")));} #else #pragma GCC optimize("Ofast") #define safe ((void)0) #define debug(...) ((void)0) #endif constexpr ll inf = 1e9, INF = 4e18; const int N = 2e5 + 225, M = 1e9 + 7; int t, n, a[N]; int32_t main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); string s; cin >> s; n = s.size(); map<char, int> mp; ll ans = 0; OOF(i,n - 1, 0){ mp[s[i]]++; if(i >= n - 2){ continue; } if(s[i] == s[i+1] and s[i+1] != s[i+2]){ ans += (n - (i + 2)) - (mp[s[i]] - 2); FOO(c,'a','z') mp[c] = 0; mp[s[i]] = n - i; } } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using uint = unsigned int; using ull = unsigned long long; using pii = pair<int, int>; /* [💭] [💡] [🎈] */ int n; int a[501], reva[501]; int swap_op(int i) { iter_swap(reva + a[i], reva + a[i + 1]); iter_swap(a + i, a + i + 1); return i; } void solve() { vector<int> ops; bool o = true; for (int i = n; i >= 1; i--) { if (a[i] == i) continue; while ((reva[i] & 1) != o) { // temp swap ops.emplace_back(swap_op(2 - o)); o = !o; } while (a[i] != i) { ops.emplace_back(swap_op(reva[i])); o = !o; } if (ops.size() > n * n) break; } cout << ops.size() << '\n'; for (int x : ops) cout << x << ' '; cout << '\n'; } int main() { cin.tie(nullptr), cout.tie(nullptr), ios::sync_with_stdio(false); #ifdef _SHIFTPSH freopen("_run/in.txt", "r", stdin), freopen("_run/out.txt", "w", stdout); #endif int t; cin >> t; while (t--) { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; reva[a[i]] = i; } solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; template<class C>constexpr int sz(const C&c){return int(c.size());} using ll=long long;using ld=long double;constexpr const char nl='\n',sp=' '; int main() { // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); // freopen("err.txt", "w", stderr); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int N; string S; cin >> N >> S; string cur; for (char c : S) { cur.push_back(c); if (sz(cur) >= 3 && cur.substr(sz(cur) - 3) == "fox") { cur.pop_back(); cur.pop_back(); cur.pop_back(); } } cout << sz(cur) << nl; return 0; }
#include <bits/stdc++.h> // #include<iomanip> using namespace std; #define int long long int typedef pair<int, int> pii; #define f(i,a,b) for(int i=a;i<b;i++) #define fo(i,a,b) for(int i = a; i<=b;i+=1) // #define Vector vector #define rf(i,a,b) for(int i=a;i>=b;i--) #define vll vector<int> #define sz(a) int(a.size()) #define all(v) v.begin(), v.end() #define pb push_back #define pf push_front #define MAXN 100010 #define MOD 1000000007 #define mod 998244353 #define deb(x) cout << '>' << #x << ':' << x << endl; #define debug(x) cout << '>' << #x << ':' << x << " "; #define nl '\n' #define MS(x,y) fill_n(*x, sizeof x / sizeof **x, y); #define mem(x,y) memset(x,y,sizeof(x)); #define INF 1000000000000000000 #define IO \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); void solve(){ int n; cin >> n; string s; cin >> s; stack<char> stk; char prev = '*', prevprev = '*'; for(int i = 0; i < n; i++){ if(stk.empty()){ stk.push(s[i]); } else { if(s[i] == 'x' and stk.size() >= 2){ prev = stk.top(); stk.pop(); prevprev = stk.top(); stk.pop(); if(prev == 'o' and prevprev == 'f'){ } else { stk.push(prevprev); stk.push(prev); stk.push(s[i]); } } else { stk.push(s[i]); } } } cout << stk.size() << nl; return ; } main() { IO; int T = 1; // cin >> T; for(int c=1; c <= T; c++){ solve(); // cout<<"Case #"<<c<<": "; } return 0; }
#pragma GCC optimize("Ofast") #define _USE_MATH_DEFINES #include "bits/stdc++.h" using namespace std; using ll = int64_t; using db = double; using ld = long double; using vi = vector<int>; using vl = vector<ll>; using vvi = vector<vector<int>>; using pii = pair<int, int>; using pll = pair<ll, ll>; using vpii = vector<pii>; using vpll = vector<pll>; constexpr char newl = '\n'; constexpr double eps = 1e-10; #define FOR(i,a,b) for (int i = (a); i < (b); i++) #define F0R(i,b) FOR(i,0,b) #define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--) #define RF0(i,b) RFO(i,0,b) #define show(x) cout << #x << " = " << x << '\n'; #define rng(a) a.begin(),a.end() #define rrng(a) a.rbegin(),a.rend() #define sz(x) (int)(x).size() #define YesNo {cout<<"Yes";}else{cout<<"No";} #define YESNO {cout<<"YES";}else{cout<<"NO";} #define v(T) vector<T> #define vv(T) vector<vector<T>> template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; } template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; } template<class T> bool lcmp(const pair<T, T>& l, const pair<T, T>& r) { return l.first < r.first; } template<class T> istream& operator>>(istream& i, v(T)& v) { F0R(j, sz(v)) i >> v[j]; return i; } template<class A, class B> istream& operator>>(istream& i, pair<A, B>& p) { return i >> p.first >> p.second; } template<class A, class B, class C> istream& operator>>(istream& i, tuple<A, B, C>& t) { return i >> get<0>(t) >> get<1>(t) >> get<2>(t); } template<class T> ostream& operator<<(ostream& o, const pair<T, T>& v) { o << "(" << v.first << "," << v.second << ")"; return o; } template<class T> ostream& operator<<(ostream& o, const vector<T>& v) { F0R(i, v.size()) { o << v[i] << ' '; } o << newl; return o; } template<class T> ostream& operator<<(ostream& o, const set<T>& v) { for (auto e : v) { o << e << ' '; } o << newl; return o; } template<class T1, class T2> ostream& operator<<(ostream& o, const map<T1, T2>& m) { for (auto& p : m) { o << p.first << ": " << p.second << newl; } o << newl; return o; } #if 1 /* グループにできない、相性の悪い頂点ペアが複数ある (相性が悪い=辺がない) 相性の悪いペアが別のグループになるようにグループ分けしたときの、 最小のグループ数を求めよ。 1<=N<=18 2^18 = 262,144 */ // INSERT ABOVE HERE signed main() { cin.tie(0); ios_base::sync_with_stdio(false); int N, M; cin >> N >> M; vv(bool) as(N, v(bool)(N, true)); F0R(i, M) { int a, b; cin >> a >> b; a--; b--; as[a][b] = as[b][a] = false; } vi dp(1 << N, N); dp[0] = 0; F0R(b, 1 << N) { F0R(i, N) { if ((b >> i) & 1) { int b2 = b ^ (1 << i); if (dp[b2] == 0) { dp[b] = 1; break; } if (dp[b2] == 1) { bool ok = true; F0R(j, N) { if ((b2 >> j) & 1 && as[i][j]) { ok = false; break; } } if (ok) { dp[b] = 1; break; } dp[b] = 2; } } } if (dp[b] > 2) { int ib = ~b; for (auto c = 0; c < b; c = (c + 1 + ib) & b) { auto c2 = c ^ b; chmin(dp[b], dp[c] + dp[c2]); } } } //cout << dp; cout << dp[(1 << N) - 1] << newl; } #endif
#include <bits/stdc++.h> #ifdef _DEBUG_ #define debug(x) cerr<<#x<<" : "<<x<<" " #define cout_n cerr<<endl #else #define debug(x) #define cout_n #endif using namespace std; const int MAXN=1e5+100; vector<int>G[MAXN]; void add(int u,int v){ G[u].push_back(v);G[v].push_back(u); } int n,m,k; int c2v[20],v2c[MAXN]; int f[20][20]; bool vis[MAXN]; void bfs(int u){ memset(vis,false,sizeof(vis)); vis[u]=true; queue<int>q;q.push(u); int d=0; while(!q.empty()){ int sz=q.size(); ++d; while(sz--){ int nowu=q.front();q.pop(); // debug(nowu); for(auto v:G[nowu]){ if(!vis[v]){ q.push(v); vis[v]=true; if(v2c[v]){ // debug(v); // debug(c2v[u]);debug(c2v[v]);cout_n; f[v2c[u]][v2c[v]]=d; } } } } } // cout_n; } int dp[(1<<19)][20]; const int INF=0x3f3f3f3f; int get1idx(int idx){ return 1<<(idx-1); } int work(){ int condmax=(1<<k)-1; memset(dp,INF,sizeof(dp)); for(int i=1;i<=k;++i){ dp[get1idx(i)][i]=0; } for(int i=1;i<=condmax;++i){ for(int x=1;x<=k;++x){ // debug(x);debug(get1idx(x));cout_n; if(!(i&(get1idx(x)))){ continue; } int cond=(i&(~get1idx(x))); for(int y=1;y<=k;++y){ if(!(cond&(get1idx(y)))){ continue; } debug(i);debug(c2v[x]);debug(c2v[y]);debug(cond);cout_n; debug(dp[i][x]);debug(dp[cond][y]);debug(f[y][x]);cout_n; dp[i][x]=min(dp[i][x],dp[cond][y]+f[y][x]); debug(dp[i][x]);cout_n;cout_n; } } } int res=INF; for(int i=1;i<=k;++i){ res=min(res,dp[condmax][i]); } return res==INF?-1:res+1; } int main(){ ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #ifdef _DEBUG_ freopen("E.in","r",stdin); freopen("E.out","w",stdout); #endif cin>>n>>m; debug(n);debug(m);cout_n; for(int i=1;i<=m;++i){ int u,v;cin>>u>>v; add(u,v); } cin>>k; for(int i=1;i<=k;++i){ cin>>c2v[i];v2c[c2v[i]]=i; } // for(int i=1;i<=n;++i){ // debug(i);debug(v2c[i]);cout_n; // } memset(f,INF,sizeof(f)); for(int u=1;u<=n;++u){ if(v2c[u]){ bfs(u); } } for(int i=1;i<=k;++i){ for(int j=1;j<=k;++j){ debug(i);debug(j);debug(f[i][j]);cout_n; } } cout<<work()<<'\n'; return 0; }
#include <bits/stdc++.h> using namespace std; #define endl "\n" int main() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); long long int n; cin>>n; long long int a[n],b[n],c[n],i; for(i=0;i<n;++i) cin>>a[i]; for(i=0;i<n;++i) cin>>b[i]; for(i=0;i<n;++i) cin>>c[i]; sort(a,a+n); long long int ans=0; for(i=0;i<n;++i) { if(binary_search(a,a+n,b[c[i]-1])) ans+=upper_bound(a,a+n,b[c[i]-1])-lower_bound(a,a+n,b[c[i]-1]); } cout<<ans; return 0; }
#include <cstdio> #include <algorithm> #define N 200007 int n; long long a[N]; long long max[N]; long long sum[N]; int main() { scanf("%d", &n); for(int i = 1; i <= n; i++) { scanf("%lld", &a[i]); max[i] = std::max(max[i - 1], a[i]); sum[i] = sum[i - 1] + a[i]; } long long tmp = 0; for(int i = 1; i <= n; i++) { tmp += sum[i]; printf("%lld\n", tmp + i * max[i]); } return 0; }
#include<bits/stdc++.h> using namespace std; long long n,u_i[200005],sub,v_i[200005],d[200005],m,t,node,e,x,u,p[200005],val[200005],dp[200005]; vector<long long> v[200005]; queue<long long> q; int main() { scanf("%lld",&n); for(int i=1;i<n;i++) { scanf("%lld%lld",&u_i[i],&v_i[i]); v[u_i[i]].push_back(v_i[i]); v[v_i[i]].push_back(u_i[i]); } memset(d,-1,sizeof d); q.push(1); d[1]=0; while(!q.empty()) { u=q.front(); q.pop(); for(int i=0;i<v[u].size();i++) { if(d[v[u][i]]==-1) { d[v[u][i]]=0; p[v[u][i]]=u; q.push(v[u][i]); } } } scanf("%lld",&m); while(m--) { scanf("%lld%lld%lld",&t,&e,&x); if(u_i[e]==p[v_i[e]]) { node=u_i[e]; sub=v_i[e]; }else { node=v_i[e]; sub=u_i[e]; } if(t==1&&u_i[e]==p[v_i[e]]||t==2&&v_i[e]==p[u_i[e]]) { dp[1]+=x; dp[sub]-=x; //printf("up\n"); }else { //printf("down\n"); dp[sub]+=x; } } memset(d,-1,sizeof d); d[1]=0; q.push(1); while(!q.empty()) { u=q.front(); q.pop(); for(int i=0;i<v[u].size();i++) { if(d[v[u][i]]==-1) { d[v[u][i]]=0; dp[v[u][i]]+=dp[u]; q.push(v[u][i]); } } } for(int i=1;i<=n;i++) { printf("%lld\n",dp[i]); } }
#include <bits/stdc++.h> #define ll long long int using namespace std; vector<int> graph[400001]; void dfs(int k, bool visited[], int par, bool &cond, int &si) { if (visited[k]) { return; } si++; visited[k] = true; for (auto i : graph[k]) { if (i != par && visited[i] == true) { cond = true; } else { dfs(i, visited, k, cond, si); } } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; pair<int, int> a[t]; for (int i = 0; i < t; i++) { int a1, b; cin >> a1 >> b; graph[a1].push_back(b); graph[b].push_back(a1); a[i] = {a1, b}; } bool visited[400001]; memset(visited, false, sizeof(visited)); int ans = 0; for (auto i : a) { if (!visited[i.first]) { int si = 0; bool cond = false; dfs(i.first, visited, -1, cond, si); // cout << cond << " " << i.first << " " << si << endl; if (cond) { ans += si; } else { ans += si - 1; } } if (!visited[i.second]) { int si = 0; bool cond = false; dfs(i.second, visited, -1, cond, si); // cout << cond << " " << i.second << " " << si << endl; if (cond) { ans += si; } else { ans += si - 1; } } } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; /**templates**/ typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef vector<ll> vl; #define si(x) scanf("%d",&x) #define sl(x) scanf("%lld",&x) #define sull(x) scanf("%llu",&x) #define sf(x) scanf("%lf",&x) #define ss(x) scanf(" %s",x) #define sc(x) scanf(" %c",&x) #define pi acos(-1.0) #define pb push_back #define aa first #define bb second #define sz(x) (ll)(x).size() #define cas printf("Case %lld: ",++t) #define casline printf("Case %lld:\n",++t) //#define cas cout<<"Case "<<++t<<": " //#define casline cout<<"Case "<<++t<<":"<<endl; #define distance(x1,y1,x2,y2)((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)) #define endl "\n" #define bug cout<<"bugggggggggggg "<<endl; #define fast ios_base::sync_with_stdio(0);cin.tie(nullptr); ///no printf/scanf #define clean fflush(stdout) const ll mod = 1000000007; const ll inf = 1LL<<62; const ll mx = 100005; const double eps = 1e-10; ll dx[10]={1,0,-1,0}; ll dy[10]={0,-1,0,1}; ///ll dx[] = {1,-1,0,0,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1,1,-1}; /// 8 Direction ///ll dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1}; /// Knight Direction ll power(ll a,ll b) { if(b==0)return 1; ll x=power(a,b/2); x=x*x; if(b%2)x=x*a; return x; } ll bigmod(ll a,ll b) { if(b==0)return 1; ll x=bigmod(a,b/2)%mod; x=(x*x)%mod; if(b%2)x=(x*a)%mod; return x; } ll Set(ll N,ll pos){return N=N | (1LL<<pos);} ll reset(ll N,ll pos){return N= N & ~(1LL<<pos);} bool check(ll N,ll pos){return (bool)(N & (1LL<<pos));} /** ...ENDING OF TEMPLATE... */ ll arr[3*mx]; ll tree[4*3*mx]; void build(ll at,ll L,ll R) { if(L==R) { tree[at]=arr[L]; return; } ll mid=(L+R)/2; build(2*at,L,mid); build(2*at+1,mid+1,R); tree[at]=tree[2*at]^tree[2*at+1]; } void update(ll at,ll L,ll R,ll id,ll val) { if(R<id||L>id)return; if(L==R&&id==R) { tree[at]^=val; return; } ll mid=(L+R)/2; update(2*at,L,mid,id,val); update(2*at+1,mid+1,R,id,val); tree[at]=tree[2*at]^tree[2*at+1]; } ll query(ll at,ll L,ll R,ll l,ll r) { if(l>R||r<L)return 0; if(l<=L&&r>=R)return tree[at]; ll mid=(L+R)/2; ll a=query(2*at,L,mid,l,r); ll b=query(2*at+1,mid+1,R,l,r); // cout<<a+b<<endl; return a^b; } int main() { // freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); // fast; ///no printf/scanf /** Use "long double"(%Lf) instead of double for precision safety*/ ll tst,a,b,c,k,n,m,res=1,ans=0,t=0; sl(n),sl(m); for(ll i=1;i<=n;i++) { sl(arr[i]); } build(1,1,n); while(m--) { sl(c),sl(a),sl(b); if(c==1) { update(1,1,n,a,b); } else { res=query(1,1,n,a,b); printf("%lld\n",res); } } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define f first #define s second const int N = 3e5+5; ll n , m , q , a[N] , BIT[N]; void update(int idx , ll val) { a[idx] = val; for(idx; idx<=n; idx = (idx + (idx&-idx))) { BIT[idx] ^= val; } } ll query(int idx) { ll res = 0; for(idx; idx; idx = (idx - (idx&-idx))) { res ^= BIT[idx]; } return res; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> q; for(int i=1; i<=n; i++) { cin >> a[i]; update(i , a[i]); } while(q--) { ll t , l , r; cin >> t >> l >> r; if (t==1) { update(l , r); } else { cout << (query(r)^query(l-1)) << '\n'; } } return 0; }
#include<iostream> #include<vector> #include<string> #include<algorithm> #include<map> #include<cmath> #include<queue> #include<stack> #include<deque> #include<list> #include<bitset> #include<sstream> using namespace std; using ll = long long; const ll MOD = 1e9+7; const ll INF = 1e18; #define REP(i, n) for(int i = 0; i < n; i++) #define endl "\n" using Graph = vector<vector<int>>; int main(){ double a,b; cin>>a>>b; printf("%.10lf\n",a*b/100); }
#pragma region head #include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vll = vector<ll>; using pi = pair<int, int>; using pll = pair<ll, ll>; template <class T> using vv = vector<vector<T>>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--) #define rrepi(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define bit(n) (1LL << (n)) template <class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; } const int INF = 1002003004; const ll LINF = 1002003004005006007ll; struct preprocess { preprocess() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); } } ____; #pragma endregion head #pragma region library #pragma endregion library int main() { int n; cin >> n; vi a(n), b(n); rep(i, n) cin >> a[i] >> b[i]; ll now = accumulate(all(a), 0ll); vll diff(n); rep(i, n) { diff[i] = a[i] * 2ll + b[i]; } sort(rall(diff)); int ans = 0; int idx = 0; while (idx < n && now >= 0) { now -= diff[idx++]; ans++; } cout << ans << '\n'; }
#include <bits/stdc++.h> #define f first #define s second using namespace std; using ll = long long; using ii = pair<int, int>; using pl = pair<ll, ll>; constexpr int MX = 5005, MOD = 998244353; pl DP[MX][2]; int main() { if (fopen("in", "r")) freopen("in", "r", stdin), freopen("out", "w", stdout); cin.tie(0)->sync_with_stdio(0); int N, M; cin >> N >> M; ll ans = 0; for (int i = 1; i <= M; ++i) { DP[0][0] = pl(0, M-1), DP[0][1] = pl(1, 1); for (int j = 0; j < N-1; ++j) { DP[j+1][0] = pl((M-1)*DP[j][0].f+(i-1)*DP[j][1].f, (M-1)*DP[j][0].s+(i-1)*DP[j][1].s); DP[j+1][1] = pl(DP[j][0].f+DP[j][0].s+(M-i+1)*DP[j][1].f, DP[j][0].s+(M-i+1)*DP[j][1].s); DP[j+1][0].f %= MOD, DP[j+1][0].s %= MOD; DP[j+1][1].f %= MOD, DP[j+1][1].s %= MOD; } (ans += DP[N-1][0].f+DP[N-1][1].f) %= MOD; } cout << ans; }
#include <bits/stdc++.h> #define task "F" #define all(v) (v).begin(), (v).end() #define rep(i, l, r) for (int i = (l); i <= (r); ++i) #define Rep(i, r, l) for (int i = (r); i >= (l); --i) #define DB(X) { cerr << #X << " = " << (X) << '\n'; } #define DB1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; } #define DB2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; } #define DB3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; } #define PR(A, l, r) { cerr << '\n'; rep(_, l, r) DB1(A, _); cerr << '\n';} #define SZ(x) ((int)(x).size()) #define pb push_back #define eb emplace_back #define pf push_front #define F first #define S second #define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a)); #define next ___next #define prev ___prev #define y1 ___y1 #define left ___left #define right ___right #define y0 ___y0 #define div ___div #define j0 ___j0 #define jn ___jn using ll = long long; using ld = long double; using ull = unsigned long long; using namespace std; typedef pair<int, int> ii; typedef pair<ii, int> iii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<ll> vl; int n, T, a[41]; int main() { #ifdef HynDuf freopen(task".in", "r", stdin); //freopen(task".out", "w", stdout); #else ios_base::sync_with_stdio(false); cin.tie(nullptr); #endif cin >> n >> T; rep(i, 0, n - 1) cin >> a[i]; vl vec; int nn = n / 2; rep(x, 0, (1 << nn) - 1) { ll sum = 0; rep(i, 0, nn - 1) if (x >> i & 1) sum += a[i]; vec.eb(sum); } sort(all(vec)); int nn1 = n - nn, ans = 0; rep(x, 0, (1 << nn1) - 1) { ll sum = 0; rep(i, 0, nn1 - 1) if (x >> i & 1) sum += a[nn + i]; auto it = upper_bound(all(vec), T - sum); if (it != vec.begin()) { it--; ans = max(1ll * ans, *it + sum); } } cout << ans; return 0; }
#include<iostream> using namespace std; #include<vector> using ll = long long; using vi = vector<int>; ll C(int n, int k) { int f1 = n, f2 = 1; ll ret = 1; if (k>n/2) { ret = C(n,n-k); } else { for (int i=0;i<k;i++) { ret *= f1; ret /= f2; f1--; f2++; } } return ret; } int main() { int A,B,i; ll K; cin>>A>>B>>K; string ans = ""; int a=0,b=0; for (i=1;i<=A+B;i++) { if (a<A) { ll c = C(A-a+B-b-1, A-a-1); if (c<K) { ans += 'b'; b++; K -= c; } else { ans += 'a'; a++; } } else { ans += 'b'; } } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> #define eb emplace_back using namespace std; template<class T> using vc = vector<T>; template<class T> using vv = vector<vector<T>>; template<class T> using PQ = priority_queue<T, vc<T>, greater<T>>; using ll = long long; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; using tiii = tuple<int, int, int>; using tlll = tuple<ll, ll, ll>; using vi = vc<int>; using vl = vc<ll>; using vs = vc<string>; const ld PI = 3.141592653589793; const ll LINF = 1001001001001001001LL; const int INF = 1001001001; constexpr int MOD = 1e9 + 7; //constexpr int MOD = 998244353; struct mint { long long x; mint(long long x = 0) noexcept : x((x % MOD + MOD) % MOD) {} // basis mint operator-() const { return mint(-x); } mint& operator+=(const mint a) noexcept { if ((x += a.x) >= MOD) x -= MOD; return *this; } mint& operator-=(const mint a) noexcept { if ((x += MOD - a.x) >= MOD) x -= MOD; return *this; } mint& operator*=(const mint a) noexcept { (x *= a.x) %= MOD; return *this; } mint operator+(const mint a) const noexcept { return mint(*this) += a; } mint operator-(const mint a) const noexcept { return mint(*this) -= a; } mint operator*(const mint a) const noexcept { return mint(*this) *= a; } mint mpow(long long t) const noexcept { if (!t) return 1; mint a = mpow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime MOD mint inv() const noexcept { return mpow(MOD - 2); } mint& operator/=(const mint a) noexcept { return *this *= a.inv(); } mint operator/(const mint a) const noexcept { return mint(*this) /= a; } // comparison bool operator==(const mint& a) const noexcept { return this->x == a.x; } bool operator!=(const mint& a) const noexcept { return this->x != a.x; } // I/O stream friend istream& operator>>(istream& is, mint& a) noexcept { return is >> a.x; } friend ostream& operator<<(ostream& os, const mint& a) noexcept { return os << a.x; } }; // additional mint mpow(const long long& a, long long n) noexcept { return mint(a).mpow(n); } mint mpow(const mint& a, long long n) noexcept { return a.mpow(n); } int main() { ll N, P; cin >> N >> P; mint ans = (mint)(P - 1) * mpow(P - 2, N - 1); cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main(){ cout << fixed << setprecision(15); int K; string S, T; cin >> K; cin >> S; cin >> T; map<int,int> card,tkh,aok; for(int i=1; i<=9; i++){ card[i] = K; tkh[i] = 0; aok[i] = 0; } for(int i=0; i<4; i++){ int a = S.at(i)-'0'; tkh[a] += 1; card[a] -= 1; a = T.at(i)-'0'; aok[a] += 1; card[a] -= 1; } double ans=0; for(int i=1; i<=9; i++){ int anst=0; if( card[i] > 0 ){ if( tkh[i] < K ){ card[i] -= 1; tkh[i] += 1; for(int j=1; j<=9; j++){ anst += j*pow(10,tkh[j]); } for(int l=1; l<=9; l++){ int ansa=0; if( card[l] > 0 ){ if( aok[l] < K ){ aok[l] += 1; for(int m=1; m<=9; m++){ ansa += m*pow(10,aok[m]); } if( anst > ansa ){ ans += (double(card[i]+1)/double(9*K-8))*(double(card[l])/double(9*K-9)); } aok[l] -= 1; } } } card[i] += 1; tkh[i] -= 1; } } } cout << ans << endl; }
#include<bits/stdc++.h> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> #define deb(x) cout<<#x<<" "<<x<<endl; #define print(arr,n) for(int i=0;i<n;++i) { cout<<arr[i]<<" "; } cout<<endl; #define ub(x,el) upper_bound(x.begin(),x.end(),el) - x.begin() #define lb(x,el) lower_bound(x.begin(),x.end(),el) - x.begin(); #define bs(x,el) binary_search(x.begin(),x.end(),el) #define MOD 1000000007 #define finish return 0 #define all(x) x.begin(),x.end() using namespace std; //using namespace __gnu_pbds; typedef long long int ll; //typedef tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; template<int D, typename T> struct Vec : public vector<Vec<D - 1, T>> { static_assert(D >= 1, "Vector dimension must be greater than zero!"); template<typename... Args> Vec(int n = 0, Args... args) : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) { }}; template<typename T> struct Vec<1, T> : public vector<T> { Vec(int n = 0, T val = T()) : vector<T>(n, val) { } }; inline ll mod(const ll& x) { return (x%MOD + MOD)%MOD; } ll gcd(ll a, ll b, ll &x, ll &y){if(a == 0){x = 0, y = 1; return b;} ll x1, y1; ll d = gcd(b%a, a, x1, y1); x = y1 - (b/a) * x1; y = x1; return d;} ll power(ll x,ll y, ll p) { ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res*x) % p; y = y>>1; x = (x*x) % p; } return res; } ll power(ll x,ll y) { ll res = 1; while (y > 0) { if (y & 1) res = (res*x); y = y>>1; x = (x*x); } return res; } ll mod(ll num, ll den){ return mod(mod(num) * power(den,MOD-2,MOD)); } vector<ll> primes(ll n) { vector<ll> p; vector<bool> v(n+1,true); for(ll i=2;i*i<=n;++i) { if(v[i]) { for(ll j=i*i;j<=n;j+=i) v[j] = false; } } for(ll i=2;i<=n;++i) if(v[i]) p.push_back(i); return p; } vector<ll> lpf(ll n){ vector<ll> v(n+1); for(ll i=1;i<=n;++i) v[i] = i; for(ll i=2;i*i<=n;++i) { if(v[i] == i) { for(ll j=i*i;j<=n;j+=i) { v[j] = i; } } } return v; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); //ll case_no = 1; ll k; cin>>k; string s,t; cin>>s>>t; unordered_map<ll,ll> mp; for(ll i=0;i<4;++i) { mp[s[i]-'0']++; mp[t[i]-'0']++; } ll total = 0; ll count = 0; for(ll i=1;i<=9;++i) { for(ll j=1;j<=9;++j) { ll s1,s2; s1 = s2 = 0; vector<ll> mp1(10),mp2(10); for(ll z=0;z<4;++z) { mp1[s[z]-'0']++; mp2[t[z]-'0']++; } ll val1 = mp1[i] + mp2[i]; ll val2 = mp2[j] + mp1[j]; mp1[i]++; mp2[j]++; bool flag = true; for(ll z=1;z<10;++z) { s1 += (power(10,mp1[z])*z); s2 += (power(10,mp2[z])*z); } for(ll z=0;z<10;++z) { if((mp1[z] + mp2[z]) > k) { flag = false; break; } } if(!flag) continue; if(i!=j) { ll v1 = k-val1; ll v2 = k-val2; if(s1 > s2) count += (v1*v2); total += (v1*v2); } else { ll v = k-val1; total += (v*(v-1)); if(s1 > s2) count += (v*(v-1)); } } } double ans = count; ans /= total; // deb(count); //deb(total); cout.precision(10); cout<<ans<<endl; }
//2021. by ljz //email [email protected] //if you find any bug in my code //please tell me #include<bits/stdc++.h> //#include<ext/pb_ds/tree_policy.hpp> //#include<ext/pb_ds/assoc_container.hpp> using namespace std; //using namespace __gnu_pbds; //using namespace __gnu_cxx; #define res register int #define LL long long #define inf 0x3f3f3f3f #define INF 0x3f3f3f3f3f3f3f #define unl __int128 #define eps 5.6e-8 #define RG register #define db double #define pc(x) __builtin_popcount(x) #define ctz(x) __builtin_ctz(x) //#define pc(x) __builtin_popcountll(x) typedef pair<int,int> Pair; #define mp make_pair #define fi first #define se second #define pi acos(-1.0) #define pb push_back #define ull unsigned LL #define lowbit(x) (x&-x) #define gc getchar #define kcz 1000000007 //template <class T>using Tree=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; // inline char gc() { // static char buf[100000],*p1,*p2; // return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++; // } inline int read() { res s=0,ch=gc(); while(ch<'0'||ch>'9')ch=gc(); while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc(); return s; } // char sr[1<<21],z[20]; // int C=-1,Z=0; // inline void Ot(){fwrite(sr,1,C+1,stdout),C=-1;} // inline void print(res x){ // if(C>1<<20)Ot();if(x<0)sr[++C]='-',x=-x; // while(z[++Z]=x%10+48,x/=10); // while(sr[++C]=z[Z],--Z); // } //inline int read() { // res s=0,ch=gc(),w=1; // while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();} // while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc(); // return s*w; //} //inline LL Read() { // RG LL s=0; // res ch=gc(); // while(ch<'0'||ch>'9')ch=gc(); // while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc(); // return s; //} //inline LL Read() { // RG LL s=0; // res ch=gc(),w=1; // while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();} // while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc(); // return s*w; //} //inline void write(RG unl x){ // if(x>10)write(x/10); // putchar(int(x%10)+'0'); //} inline void swap(res &x,res &y) { x^=y^=x^=y; } inline void add(res &x,const res &y){ x+=y,x>=kcz?x-=kcz:(x<0?x+=kcz:1); } inline int Add(const res &x,const res &y){ return x+y>=kcz?x+y-kcz:(x+y<0?x+y+kcz:x+y); } inline int mul(const res &x,const res &y){ return int(1LL*x*y%kcz); } inline int mul(const res &x,const res &y,const res &d){ return int(1LL*x*y/d%kcz); } inline int qpow(res x,res y){ if(y<=0)return 1; res ret=1; while(y){ if(y&1)ret=mul(ret,x); x=mul(x,x),y>>=1; } return ret; } //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //clock_t start=clock(); //inline void ck(){ // if(1.0*(clock()-start)/CLOCKS_PER_SEC>0.1)exit(0); //} const int N=1e5+10; namespace MAIN{ int n,a[N]; LL sum[N]; inline void MAIN(){ n=read(); for(res i=1;i<=n;i++)a[i]=read(); sort(a+1,a+n+1); for(res i=1;i<=n;i++)sum[i]=sum[i-1]+a[i]; RG LL ans=INF; // printf("%.10f\n",(3.0-2.0*2/n)*1.0*a[2]/2.0-1.0*sum[2]/n); for(res m=0;m<=n;m++){ ans=min(ans,sum[n]*2+1LL*n*a[m]-2LL*a[m]*(n-m)-2LL*sum[m]); } // printf("%lld\n",ans/2); printf("%.10Lf\n",(long double)ans/(2.0*n)); } } int main(){ // srand(19260817); // freopen("tracing.in","r",stdin); // freopen("tracing.out","w",stdout); MAIN::MAIN(); // Ot(); return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; using ll = long long; using ld = long double; template <typename T> using orderedSet = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template <typename T> using orderedMultiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>; const ld pi = 4.0 * atan(1.0); #define xlr8 \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); \ cout.precision(10); \ cout << fixed //76149 template <int D, typename T> struct Vec : public vector<Vec<D - 1, T>> { static_assert(D >= 1, "Vector dimension must be greater than zero!"); template <typename... Args> Vec(int n = 0, Args... args) : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) { } }; template <typename T> struct Vec<1, T> : public vector<T> { Vec(int n = 0, T val = T()) : vector<T>(n, val) { } }; int main() { xlr8; int testCases = 1; // cin >> testCases; while (testCases--) { int n; cin>>n; vector<int> a(n); for(int i = 0 ; i < n ; i++) cin>>a[i]; nth_element(a.begin() , a.begin() + n/2 , a.end()); nth_element(a.begin() , a.begin() + n/2 - 1, a.end()); double md = (n%2 ? a[n/2] : (a[n/2 - 1] + a[n/2])/2)/2.0; double ans = 0; for(int i = 0 ; i < n ; i++) ans += (a[i] + md - min((double)a[i] , 2*md)); ans/=n; cout<<ans<<"\n"; } }
#include <bits/stdc++.h> using namespace std; int main() { int V, T, S, D; cin >> V >> T >> S >> D; if (V*T <= D and D <= V*S) { cout << "No" << endl; } else { cout << "Yes" << endl; } return 0; }
#include<bits/stdc++.h> #define ll long long int using namespace std; #define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL) #define mp make_pair #define fi first #define se second #define pb push_back #define endl "\n" #define maxpq priority_queue<ll> #define minpq priority_queue<ll, vector<ll>, greater<ll> > #define vi vector<ll> #define pii pair<ll, ll> #define vii vector<pii> #define for0(i, n) for (int i = 0; i < n; i++) #define for1(i, n) for (int i = 1; i <= n; i++) #define loop(i,a,b) for (int i = a; i < b; i++) #define bloop(i,a,b) for (int i = a ; i>=b;i--) #define MOD 1000000007 #define INT_MAXI 1000000000000000000 #define INT_MINI -9000000000000000000 ll max(ll a, ll b) {if (a > b) return a; else return b;} ll min(ll a, ll b) {if (a < b) return a; else return b;} const int dx[4] = { -1, 1, 0, 0}; const int dy[4] = {0, 0, -1, 1}; int XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 }; int YY[] = { -1, 0, 1, -1, 1, -1, 0, 1 }; char arr[1005][1005]; int main() { fio; ll t,n,i,j,k,x,l,r,b,h,y,m,a,c,d; cin>>a>>b>>c>>d; double val=d*1.0/a; if(val>=b&&val<=c) { cout<<"No"; } else cout<<"Yes"; }
#include <stdio.h> typedef long long ll; int num[105][105], max = -1, vis[20], k, n, m; struct node { int x1, x2; } a[20], b[105]; void dfs(int now) { if (now >= k) { int sum = 0; //for (int i = 0; i < 17; i ++) printf("%d ", vis[i]);printf("\n"); for (int i = 0; i < m; i ++) if (vis[b[i].x1] && vis[b[i].x2]) //printf("sum : %d + num[%d][%d] (%d)\n", sum, b[i].x1, b[i].x2, num[b[i].x1][b[i].x2]); sum ++; if (sum > max) max = sum; //printf("%d..sum : %d\n", now, sum); return; } int px1 = a[now].x1, px2 = a[now].x2; vis[px1] ++; //printf("%d pick : %d\n", now, px1); dfs(now + 1); vis[px1] --; vis[px2] ++; //printf("%d pick : %d\n", now, px2); dfs(now + 1); vis[px2] --; } int main() { int cnt = 0; scanf("%d %d", &n, &m); while (cnt < m) { scanf("%d %d", &b[cnt].x1, &b[cnt].x2); //num[b[cnt].x1][b[cnt].x2] ++; cnt ++; } int ind = 0; scanf("%d", &k); while (ind < k) { scanf("%d %d", &a[ind].x1, &a[ind].x2); ind ++; } dfs(0); //dfs(1); printf("%d\n", max); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long int; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { double n; double x2, y2, ans = 0; cin >> n >> x2 >> y2; for (ll i = 0; i < n; i++) { double x1, y1; cin >> x1 >> y1; double y3 = ((y2 - y1) / (x2 - x1)) * (0 - x1) + y1; if (y3 > ans) { ans = y3; } } cout << fixed << setprecision(9) << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define forn(i,x,n) for(int i = x;i <= n;++i) #define forr(i,x,n) for(int i = n;i >= x;--i) #define Angel_Dust ios::sync_with_stdio(0);cin.tie(0) const int N = 2e5+7; int x[N],y[N]; map<int,vector<int>> E; int main() { int n,m;scanf("%d%d",&n,&m); forn(i,1,m) { int x,y;scanf("%d%d",&x,&y); E[x].push_back(y); } set<int> st; st.insert(n); for(auto& _ : E) { vector<int> nxt; for(auto& v : _.second) if(st.count(v - 1) || st.count(v + 1)) nxt.push_back(v); for(auto& v : _.second) st.erase(v); for(auto& v : nxt) st.insert(v); } printf("%d\n",(int)st.size()); return 0; }
#include <bits/stdc++.h> using namespace std; #define lli long long int #define REP(i,s,n) for(int i=s;i<n;i++) #define NUM 2520 #define INF (1LL<<50) #define DEBUG 0 #define mp(a,b) make_pair(a,b) #define SORT(V) sort(V.begin(),V.end()) #define PI (3.141592653589794) #define TO_STRING(VariableName) # VariableName #define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl; #define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl; #define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl; #define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl; 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; } map<lli,vector<lli>> G; void func(long long N, long long M, std::vector<long long> X, std::vector<long long> Y){ REP(i,0,M){ G[X[i]].push_back(Y[i]); } set<lli> nowS; nowS.insert(N); for(auto &e:G){ set<lli> eraseS; set<lli> nextPushS; vector<lli> &nowV = e.second; for(auto now:nowV){ if(nowS.find(now-1) != nowS.end()){ nextPushS.insert(now); } if(nowS.find(now+1) != nowS.end()){ nextPushS.insert(now); } if(nowS.find(now) != nowS.end()){ eraseS.insert(now); } } for(auto e:eraseS){ nowS.erase(e); } for(auto e:nextPushS){ nowS.insert(e); } } cout<<nowS.size()<<endl; } int main(){ // cout << fixed << setprecision(5); long long N; scanf("%lld",&N); long long M; scanf("%lld",&M); std::vector<long long> X(M); std::vector<long long> Y(M); for(int i = 0 ; i < M ; i++){ scanf("%lld",&X[i]); scanf("%lld",&Y[i]); } func(N, M, std::move(X), std::move(Y)); return 0; }
#include<bits/stdc++.h> #define x first #define y second #define pb push_back #define eb emplace_back #define all(a) (a).begin(),(a).end() #define SZ(a) (int)(a).size() #define FOR(i, a, b) for(int i=(a); i<=(b); ++i) #define iFOR(i, a, b) for(int i=(a); i>=(b); --i) #define make_unique(a) sort(all((a))), (a).resize(unique(all((a)))-(a).begin()) using namespace std; typedef pair<int,int> PII; typedef long long LL; typedef unsigned long long UL; // ULLONG_MAX, %llu typedef unsigned int UI; //UINT_MAX %u typedef double DD; typedef long double LD; typedef pair<LL,LL> PLL; typedef pair<DD,DD> PDD; typedef vector<int> VI; typedef vector<LL> VL; int mod; void adding(int &a, int b){ if((a+=b) >= mod) a -= mod; } int add(int a, int b){ if((a+=b) >= mod) return a - mod; return a; } int mul(int a, int b){ return a * 1ll * b % mod; } const int N = 101; int dp[N][130000]; int sum[N][130000]; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n, K; cin >> n >> K >> mod; int Max = 129999; dp[0][0] = sum[0][0] = 1; FOR(i, 1, n){ dp[i][0] = sum[i][0] = 1; FOR(j, 1, Max){ sum[i-1][j] = dp[i-1][j]; if(j >= i) adding(sum[i-1][j],sum[i-1][j-i]); } FOR(j, 1, Max){ dp[i][j] = sum[i-1][j]; if(j >= (K+1)*i) adding(dp[i][j], mod-sum[i-1][j-(K+1)*i]); } } FOR(x, 1, n){ // try all mean int ans = K; FOR(i, 1, Max) adding(ans, mul( mul(dp[x-1][i], dp[n-x][i]), K+1)); cout << ans << endl; } return 0; } /* * * * * * * * * * * */
// .------------------------------------------------------------. // | K U S A Y A R O U | // | | // | ---|---|--- ___ ____ _\_ ___ | // | _______ |_|_| / |___| | / | // | |_______| |_|_| \ |___| | / | // | |_______| | _____ | | \ | // | _____|_____ __|__ | / | \ | __\ | // | | | | | / \ | | // | | __|__ \| |/ | | // | | // |------------------------------------------------------------| // | .------------. | // | | KerakTelor | | // | |------------| | // | | 2020-07-21 | | // | '------------' | // '------------------------------------------------------------' #include <bits/stdc++.h> #define DEBUG(...) // #pragma GCC optimize("O2,unroll-loops") // #pragma GCC target("tune=native") #define fi first #define se second using namespace std; using ll = long long; using ld = long double; template<class T> using vec = vector<T>; template<class T> using v2d = vector<vector<T>>; template<class T> using prq = priority_queue<T>; template<class T> using rpq = priority_queue<T, vector<T>, greater<T>>; int main() { const int MOD = 1e9 + 7; int y, x; scanf("%d %d", &y, &x); v2d<int> g(y, vec<int>(x)); for(auto& i : g) { getchar(); for(auto& j : i) { j = getchar() == '#'; } } v2d<int> ps(y, vec<int>(x)); vec<int> ysum(x), xsum(y), dsum(x + y); ps[0][0] = 1; xsum[0] = 1; ysum[0] = 1; dsum[x] = 1; for(int i = 0; i < y; ++i) { for(int j = 0; j < x; ++j) { if(!i && !j) { continue; } int d = i - j + x; if(!g[i][j]) { ps[i][j] = (ps[i][j] + ysum[j]) % MOD; ps[i][j] = (ps[i][j] + xsum[i]) % MOD; ps[i][j] = (ps[i][j] + dsum[d]) % MOD; ysum[j] = (ysum[j] + ps[i][j]) % MOD; xsum[i] = (xsum[i] + ps[i][j]) % MOD; dsum[d] = (dsum[d] + ps[i][j]) % MOD; } else { ps[i][j] = 0; ysum[j] = 0; xsum[i] = 0; dsum[d] = 0; } } } printf("%d\n", ps[y - 1][x - 1]); }
#pragma GCC optimize("Ofast") #include <limits.h> #include <iostream> #include <algorithm> #include <vector> #include <set> #include <unordered_set> #include <map> #include <cmath> #include <iomanip> #include <string> #include <deque> #include <assert.h> #include <random> #include <ctime> #include <unordered_map> #include <complex> #include <chrono> #define pnode node* using namespace std; typedef long long ll; typedef long double ld; const ll mod = 998244353; ll n, k; ll pw(ll a, ll p) { if (p == 0) { return 1; } ll b = pw(a, p / 2); if (p % 2 == 0) { return (b * b) % mod; } else { return (((b * b) % mod) * a) % mod; } } ll rev(ll a) { return pw(a, mod - 2); } vector < ll > smpw; vector < ll > pwsm; vector < vector < ll > > c; vector < ll > a; void solve(){ cin >> n >> k; a.resize(n); smpw.resize(k + 1); pwsm.resize(k + 1); c.resize(k + 1, vector < ll > (k + 1)); for (ll i = 0; i < n; ++i) { cin >> a[i]; } for (ll i = 0; i <= k; ++i) { ll cursm = 0; ll curpw = 0; for (ll j = 0; j < n; ++j) { cursm += a[j]; } cursm = pw(cursm, i); cursm %= mod; for (ll j = 0; j < n; ++j) { curpw += pw(a[j], i); } curpw %= mod; smpw[i] = cursm; pwsm[i] = curpw; } for (ll i = 0; i <= k; ++i){ for (ll j = 0; j <= k; ++j) { if (i < j) { c[i][j] = 0; continue; } if (i == 0 || j == 0) { c[i][j] = 1; continue; } c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod; } } // cerr << k << " " << k - 1 << " " << c[k][k - 1] << "\n\n"; for (ll p = 1; p <= k; ++p) { ll ans = 0; for (ll i = 0; i <= p; ++i) { // c[p][i]; // i, p - i ll add = (pwsm[i] * pwsm[p - i]) % mod; add = (add - pwsm[p] + mod) % mod; add = (add * c[p][i]) % mod; ans += add; ans %= mod; } cout << (ans * rev(2)) % mod << "\n"; } } signed main(){ ll t = 1; ios_base::sync_with_stdio(0); srand(time(0)); cin.tie(0); cout.tie(0); cout << fixed; cout << setprecision(20); #ifdef DEBUG freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #else #endif while(t--){ solve(); } }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define P pair<int, int> #define fi first #define se second #define rep(i, n) for (int i = 0; i < n; i++) #define all(v) v.begin(), v.end() #define pb push_back template <class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true; } return false; } template <class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true; } return false; } constexpr int INF = 1000000000; constexpr ll llINF = 1000000000000000000; constexpr int mod = 998244353; constexpr double eps = 1e-10; const double pi = acos(-1); int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; int Random(int mi, int ma) { random_device rnd; mt19937 mt(rnd()); // 32bit //[mi,ma] uniform_int_distribution<int> engine(mi, ma); return engine(mt); } /* vector<vector<ll>>C,sC; void init_comb(int n,int m){ C.resize(n+1,vector<ll>(m+1,0)); sC.resize(n+1,vector<ll>(m+1,0)); C[0][0]=1; for(int i=1;i<=n;i++){ C[i][0]=1; for(int j=1;j<=m;j++){ C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod; } } rep(i,n+1){ rep(j,m){ sC[i][j+1]=(sC[i][j]+C[i][j])%mod; } } }*/ bool prime(int a) { if (a == 1) return false; for (int i = 2; i * i <= a; i++) { if (a % i == 0) return false; } return true; } vector<int> primes; void init_prime(int n) { primes.push_back(2); for (int i = 3; i <= n; i += 2) { bool f = true; for (int j : primes) { if (j * j > i) break; if (i % j == 0) { f = false; break; } } if (f) primes.push_back(i); } } ll modpow(ll a, ll b) { ll res = 1; while (b) { if (b & 1) { res *= a; res %= mod; } a *= a; a %= mod; b >>= 1; } return res; } vector<ll> inv, fact, factinv; void init_fact(int n) { inv.resize(n + 1); fact.resize(n + 1); factinv.resize(n + 1); inv[0] = 0; inv[1] = 1; fact[0] = 1; factinv[0] = 1; for (ll i = 1; i <= n; i++) { if (i >= 2) inv[i] = mod - ((mod / i) * inv[mod % i] % mod); fact[i] = (fact[i - 1] * i) % mod; factinv[i] = factinv[i - 1] * inv[i] % mod; } } ll _inv(ll a, ll m = mod) { // gcd(a,m) must be 1 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 comb(int a, int b) { if (a < b) return 0; if (a < 0) return 0; return fact[a] * factinv[a - b] % mod * factinv[b] % mod; } ll multicomb(int a, int b) { return comb(a + b - 1, b); } void solve() { int n, a[200010]; cin >> n; ll ma = 0, sum = 0, cur = 0; rep(i, n) { cin >> a[i]; sum += a[i]; chmax(ma, a[i]); cur += sum; cout << ma * (i + 1) + cur << endl; } } int main() { cin.tie(0); ios::sync_with_stdio(false); // int t;cin >> t;while (t--) solve(); return 0; }
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<=b;i++) #define pre(i,a,b) for(int i=a;i>=b;i--) #define N 1000005 using namespace std; int n,a[N]; double calc(double x){ double sum=0; rep(i,1,n)sum+=(a[i]-min(1.00*a[i],x*2))/(1.00*n); return sum+x; } int main(){ scanf("%d",&n); rep(i,1,n)scanf("%d",&a[i]); sort(a+1,a+n+1); if(n==1)printf("%.10lf\n",a[1]/2.00); else printf("%.10lf\n",min(calc(a[n/2]/2.00),calc(a[n/2+1]/2.00))); return 0; }
#include <bits/stdc++.h> #include <time.h> #define rep(i, n) for(int i=0;i<(int)(n);i++) #define ALL(a) (a).begin(),(a).end() using namespace std; using ll=long long; typedef pair<int,int> P; const int INF=1e9; bool LOCAL_TEST = false; int h[30][30],v[30][30],u[30][30]; double priority[30][30]; vector<string> paths; vector<int> dis,a(1000); vector<double> e(1000),dis_ave; map<int,char> mp; map<char,int> mov; inline void InitRand(){ srand((unsigned int)time(NULL)); } void move(int si,int sj,int ti,int tj,string& path){ int y=si,x=sj; while(y!=ti||x!=tj){ if(y==ti){ rep(i,abs(tj-x)) path+=mp[1]; break; } else if(x==tj){ rep(i,abs(ti-y)) path+=mp[0]; break; } if(LOCAL_TEST){ }else{ int next; if(u[y+mov[mp[0]]][x]==INF&&u[y][x+mov[mp[1]]]==INF) next=rand()%2; else if(u[y+mov[mp[0]]][x]==INF) next=0; else if(u[y][x+mov[mp[1]]]==INF) next=1; else{ if(u[y+mov[mp[0]]][x]<=u[y][x+mov[mp[1]]]) next=0; else next=1; } path+=mp[next]; if(next==0){ if(y<ti) y++; else y--; }else{ if(x<tj) x++; else x--; } } } if(LOCAL_TEST){ y=si,x=sj; int d=0; rep(i,path.size()){ if(path[i]=='U') d+=v[y-1][x],y--; if(path[i]=='D') d+=v[y][x],y++; if(path[i]=='L') d+=h[y][x-1],x--; if(path[i]=='R') d+=h[y][x],x++; } dis.push_back(d); } } void draw_cost(int si,int sj,int ti,int tj,int a,string path){ int y=si,x=sj; u[y][x]=min(u[y][x],a); rep(i,path.size()){ if(path[i]=='U') y--; if(path[i]=='D') y++; if(path[i]=='L') x--; if(path[i]=='R') x++; u[y][x]=min(u[y][x],a); } } void read_s_t_a_e(int k){ int si,sj,ti,tj; cin>>si>>sj>>ti>>tj>>a[k]>>e[k]; string path; if(si<=ti) mp[0]='D'; else mp[0]='U'; if(sj<=tj) mp[1]='R'; else mp[1]='L'; move(si,sj,ti,tj,path); paths.push_back(path); dis_ave.push_back((double)dis[k]/(abs(ti-si)+abs(tj-sj))); } void read_s_t(){ int si,sj,ti,tj,a; cin>>si>>sj>>ti>>tj; string path; if(si<=ti) mp[0]='D'; else mp[0]='U'; if(sj<=tj) mp[1]='R'; else mp[1]='L'; move(si,sj,ti,tj,path); cout<<path<<endl; flush(cout); cin>>a; a/=(int)path.size(); draw_cost(si,sj,ti,tj,a,path); } int main(){ rep(i,30) fill(priority[i],priority[i]+30,-1); mov['U']=-1; mov['D']=1; mov['L']=-1; mov['R']=1; if(LOCAL_TEST){ rep(i,30) rep(j,29) cin>>h[i][j]; rep(i,29) rep(j,30) cin>>v[i][j]; }else{ rep(i,30) fill(u[i],u[i]+30,INF); } rep(k,1000){ if(LOCAL_TEST) read_s_t_a_e(k); else read_s_t(); } if(LOCAL_TEST){ ofstream output("out.txt"); rep(k,1000) output<<paths[k]<<'\n'; rep(k,1000) cout<<k<<" "<<dis[k]<<" " <<(double)a[k]/dis[k]<<" "<<dis[k]*e[k]<<" "<<dis_ave[k]<<endl; } }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define REP(i, st, n) for (int i = (st); i < (n); ++i) #define rrep(i, n) for (int i > (n)-1; i >= 0; ++i) #define RREP(i, st, n) for (int i = (st); i > (n); ++i) using namespace std; using ll = int64_t; using P = pair<ll, ll>; template <class T> using V = vector<T>; template <class T> class Matrix { public: int h, w; V<V<T>> data; Matrix(int h_, int w_ = 0, T v = 0) { h = h_; w = (w != 0) ? w_ : h; data.resize(h); rep(i, h) data[i].resize(w, v); } Matrix(const V<V<T>>& data_) : h(data_.size()), w(data_[0].size), data(data_) {} Matrix(initializer_list<initializer_list<T>> list) { data.resize(list.size()); int cnt = 0; for (auto row : list) data[cnt++] = V<T>(row); h = data.size(), w = data[0].size(); } Matrix(const Matrix& a) : h(a.h), w(a.w), data(a.data) {} Matrix& operator=(const Matrix& a) { h = a.h, w = a.w, data = a.data; return *this; } V<T>& operator[](int n) { return data[n]; } Matrix& operator*=(Matrix& a) { V<V<T>> res(h, V<T>(a.w)); rep(i, h) rep(j, a.w) { rep(k, w) res[i][j] += data[i][k] * a[k][j]; } swap(data, res); w = a.w; return *this; } Matrix operator*(Matrix& a) { return Matrix(*this) *= a; } Matrix& operator+=(Matrix& a) { rep(i, h) rep(j, w) data[i][j] += a[i][j]; return *this; } string str() { ostringstream oss; rep(i, h) { rep(j, w) oss << data[i][j] << " "; if (i != h - 1) oss << "\n"; } return oss.str(); } }; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, m; cin >> n; V<P> xy(n); rep(i, n) cin >> xy[i].first >> xy[i].second; V<Matrix<ll>> ops; Matrix<ll> now = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}; ops.push_back(now); Matrix<ll> clk = {{0, 1, 0}, {-1, 0, 0}, {0, 0, 1}}; Matrix<ll> clw = {{0, -1, 0}, {1, 0, 0}, {0, 0, 1}}; Matrix<ll> f3 = {{-1, 0, 2}, {0, 1, 0}, {0, 0, 1}}; Matrix<ll> f4 = {{1, 0, 0}, {0, -1, 2}, {0, 0, 1}}; cin >> m; rep(i, m) { int op; ll p; cin >> op; if (op > 2) cin >> p; if (op == 1) { now = clk * now; } else if (op == 2) { now = clw * now; } else if (op == 3) { f3[0][2] = 2 * p; now = f3 * now; } else if (op == 4) { f4[1][2] = 2 * p; now = f4 * now; } ops.emplace_back(now); } int Q; cin >> Q; rep(i, Q) { int a, b; cin >> a >> b; b--; Matrix<ll> pos = {{xy[b].first}, {xy[b].second}, {1}}; auto ans = ops[a] * pos; ll x = ans[0][0], y = ans[1][0]; cout << x << " " << y << "\n"; } }
//#include <atcoder/maxflow.hpp> #include <memory> #include <iostream> #include <map> #include <list> #include <set> #include <algorithm> #include <vector> #include <sstream> #include <string> #include <functional> #include <queue> #include <deque> #include <stack> #include <limits> #include <unordered_map> #include <unordered_set> #include <cmath> #include <fstream> #include <iterator> #include <random> #include <chrono> #include <complex> #include <thread> #define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i) #define set_map_includes(set, elt) (set.find((elt)) != set.end()) #define readint(i) int i; cin >> i #define readll(i) ll i; cin >> i #define readdouble(i) double i; cin >> i #define readstring(s) string s; cin >> s typedef long long ll; using namespace std; //using namespace atcoder; ll modd = 1000 * 1000 * 1000 + 7; int main() { ios_base::sync_with_stdio(false); cout.precision(17); mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int> rand_gen(0, modd); // rand_gen(rng) gets the rand no auto start = chrono::steady_clock::now(); // readint(test_cases); int test_cases = 1; forr(t, 1, test_cases) { readint(x); cout << (x>=0 ? x : 0) << endl; } // auto stop = chrono::steady_clock::now(); // auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start); // cout << "Duration: " << duration.count() << endl; 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 = 2e5; const ld eps = 1e-9; const char newl = '\n'; ll modpow(ll n) { if(n==0) return 1; else if(n%2==0) return modpow(n/2)*modpow(n/2)%MOD; else return 2*modpow(n-1)%MOD; } int main() { ios::sync_with_stdio(false); cin.tie(0); ll n; char caa, cab, cba, cbb; cin >> n >> caa >> cab >> cba >> cbb; if(n==2) cout << 1; else if((caa=='A' && cab=='A') || (cab=='B' && cbb=='B')) { cout << 1; } else if((cab=='B' && cba=='A' && cbb=='A') || (caa=='B' && cab=='A' && cba=='B')) { cout << modpow(n-3); } else if((cab=='B' && cba=='B' && cbb=='A') || (caa=='B' && cab=='A' && cba=='A')) { vvl bc(n-1, vl(n-1)); rep(i, n-1) { bc[i][0] = 1; bc[i][i] = 1; } rep(i, n-1) rep2(j, 1, i-1) bc[i][j] = (bc[i-1][j-1] + bc[i-1][j]) % MOD; ll ans = 0; rep(k, n/2) (ans += bc[n-2-k][k]) %= MOD; cout << ans; } else return -1; cout << newl; return 0; }
#include <bits/stdc++.h> using namespace std; #define endl "\n" #define int long long int max(int a,int b) { if(a>b) return a; return b; } int min(int a,int b) { if(a<b) return a; return b; } signed main() { ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); string s; cin>>s; map<int,int> mp; int x=0; for(auto i:s){ mp[(i-'0')%3]++; x+=(i-'0'); } x%=3; int ans=s.size(); if(x==1) { if(mp[1]>=1) ans=min(ans,1); if(mp[2]>=2) ans=min(ans,2); } else if(x==2) { if(mp[1]>=2) ans=min(ans,2); if(mp[2]>=1) ans=min(ans,1); } else ans=0; if(ans==s.size()) ans=-1; cout<<ans; }
//#include "bits/stdc++.h" #define _USE_MATH_DEFINES #include <iostream> #include <sstream> #include <iomanip> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <algorithm> #include <numeric> #include <functional> #include <utility> #include <tuple> #include <vector> #include <string> #include <list> #include <set> #include <unordered_set> #include <map> #include <unordered_map> #include <queue> #include <deque> #include <stack> #include <iterator> #include <bitset> #include <complex> #include <limits> #include <random> #include<fstream> #include<array> using namespace std; #define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++) #define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--) #define all(c) begin(c),end(c) #define int ll #define SZ(x) ((int)(x).size()) #define pb push_back #define mp make_pair typedef unsigned long long ull; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ll, int> pli; typedef pair<double, double> pdd; typedef vector< vector<int> > mat; template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; } const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f; const int MOD = (int)1e9 + 7; const double EPS = 1e-9; signed main() { cin.tie(0); ios::sync_with_stdio(false); int T; cin >> T; while (T--) { int N, A, B; cin >> N >> A >> B; int a = (N - A + 1)*(N - A + 1); int b = (N - B + 1)*(N - B + 1); a %= MOD; b %= MOD; int ans = a * b; ans %= MOD; int x = max(0LL, N - A - B + 1); x = x * (x + 1) / 2; x %= MOD; x *= 2; x %= MOD; int y = (N - A + 1)*(N - B + 1); y = (y - x + MOD) % MOD; y = y * y; y %= MOD; ans = (ans - y + MOD) % MOD; cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int64_t a1,b1,c1,C,n,day; int64_t fee=0,feeall=0; vector<pair<int, int>> event; cin>>n>>C; for(int64_t i=0;i<2*n;i+=2){ cin>>a1>>b1>>c1; event.push_back(make_pair(a1,c1)); event.push_back(make_pair(b1+1,-1*c1)); } sort(event.begin(),event.end()); day=event[0].first; fee=event[0].second; // cout<<event[0].first<<" "<<event[0].second<<endl; for(int i=1;i<2*n;i++){ day=event[i].first-event[i-1].first; if(fee<C){ feeall+=fee*day; }else{ feeall+=C*day; } fee+=event[i].second; // cout<<event[i].first<<" "<<event[i].second<<" "<<feeall<<endl; } cout<<feeall<<endl; }
// UpS0lver #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update using namespace __gnu_pbds; using namespace std; #define sz(a) int((a).size()) #define pb push_back #define mp make_pair #define all(c) (c).begin(), (c).end() #define tr(c, i) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++) #define present(c, x) ((c).find(x) != (c).end()) #define cpresent(c, x) (find(all(c), x) != (c).end()) #define minei(x) min_element(x.begin(), x.end()) - (x).begin() #define maxei(x) max_element(x.begin(), x.end()) - (x).begin() #define LSOne(S) (S & (-S)) #define uns(v) sort((v).begin(), (v).end()), v.erase(unique(v.begin(), v.end()), v.end()) #define acusum(x) accumulate(x.begin(), x.end(), 0) #define acumul(x) accumulate(x.begin(), x.end(), 1, multiplies<int>()); #define bits(x) __builtin_popcount(x) #define inf 1000000000 #define MAXN 1000007 #define MOD 1000000007 #define debug(x) cerr << (#x) << " = " << (x) << '\n'; const double pi = acos(-1.0); const double eps = 1e-11; template <class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>; typedef long long ll; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; void add(int &a, int b) { a += b; if (a >= MOD) a -= MOD; } void pv(vector<ll> v) { if (v.empty()) return; cout << v[0]; for (int i = 1; i < sz(v); i++) { cout << " " << v[i]; } cout << '\n'; } ll gtSum(ll n) { return n * (n + 1) / 2; } void _run_test() { int a, b; vector<ll> res; cin >> a >> b; ll cur = 1; if (a == b) { while (a--) { res.pb(cur); res.pb(-1 * cur); cur++; } } else if (a > b) { for (int i = 0; i < b - 1; i++) { res.pb(cur); res.pb(-1 * cur); cur++; } res.pb(-1 * (gtSum(a) - gtSum(b - 1))); for (int i = b - 1; i < a; i++) { res.pb(cur++); } } else { for (int i = 0; i < a - 1; i++) { res.pb(cur); res.pb(-1 * cur); cur++; } res.pb((gtSum(b) - gtSum(a - 1))); for (int i = a - 1; i < b; i++) { res.pb(-1 * cur); cur++; } } pv(res); } int main() { std::ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; while (t--) { _run_test(); } return 0; }
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <ctime> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> P; #define rep(i, n) for (int i = 0; i < (n); ++i) #define replr(i, l, r) for (int i = (l); i < (r); ++i) const int mod = 1e9 + 7; int main() { int a, b; cin >> a >> b; int aa = 1, bb = -1; if (a < b) swap(a, b), swap(aa, bb); vector<int> A(a); A[0] = 1; rep(i, a - 1) { A[i + 1] = A[i] + 1; } int sum = 0; replr(i, b - 1, a) sum += A[i]; rep(i, a) { if (i < b - 1) cout << bb * A[i] << " "; cout << aa * A[i] << " "; } cout << bb * sum << endl; return 0; }
#include<bits/stdc++.h> #define ld double long #define ll long long #define ull unsigned long long #define all(A) A.begin(), A.end() #define pb push_back #define fri(start , end , step) for(int i = start; i < end ; i = i + step) #define frj(start , end , step) for(int j = start; j < end ; j = j + step) #define fast ios_base::sync_with_stdio(0); cin.tie(0) #define debug(x) cerr<<#x<<": "<<x<<endl; using namespace std; void pv(vector<ll>& vec ){ fri(0 , vec.size() , 1) cout << vec[i] << " "; cout << "\n"; } multiset<string> A; mt19937 rng(time(0)); char ans[20][20]; string ss = "ABCDEFGH"; pair<int , multiset<string>> check(multiset<string> tec , int i1 , int j1){ int cof = 0; fri(0 , 20 , 1){ string s; frj(i , i + 12 , 1){ if(ans[i1][j % 20] != '0' ) s += ans[i1][j % 20]; else break; int c = tec.count(s) ; if(c) { cof += c; tec.erase(s); } } } fri(0 , 20 , 1){ string s; frj(i , i + 12 , 1){ if(ans[j % 20][j1] != '0' ) s += ans[j % 20][j1]; else break; int c = tec.count(s) ; if(c) { cof += c; tec.erase(s); } } } return {cof , tec}; } bool vis[20][20]; // signed main(){ fast; int n , m; cin >> n >> m; map<char , int > M; fri(0 , 20 , 1){ frj(0 , 20 , 1){ ans[i][j] = '0'; } } fri(0 , m , 1 ){ string s; cin >> s; for(char x : s) M[x] ++; A.insert(s); } queue<pair<int , int>> q; q.push({0 , 0 }); while(!q.empty()){ int i = q.front().first ; int j = q.front().second; //debug(i); //debug(j); vis[i][j] = 1; q.pop(); multiset<string> good; int mx = -1; char best; for(char x : ss){ ans[i][j] = x; pair<int , multiset<string>> f = check(A, i , j); int ls= mx; mx = max(mx , f.first); if(ls != mx) { good= f.second; best = x; } } if(mx == 0){ int y = rng() % 8; best = ss[y]; } ans[i][j] = best; /*for(int i1 = 0; i1 < 20 ; i1 ++){ for(int j1 = 0; j1 < 20 ; j1 ++){ cout << ans[i1][j1]; } cout << endl; } cout << endl; cout << i << " " << j << endl;*/ A = good; if(i < 19 && vis[i+ 1][j] == 0) { q.push({i + 1 , j } ); vis[i + 1][j ] = 1; } if(j < 19 && vis[i][j+ 1] == 0) { q.push({i , j + 1 } ); vis[i][j + 1] = 1; } } fri(0 , 20 , 1){ frj(0 , 20 , 1) cout << ans[i][j] ; cout << "\n"; } return 0; }
#pragma GCC optimize("Ofast") #define _GLIBCXX_DEBUG #include <bits/stdc++.h> #include <sys/time.h> using namespace std; class XorShift128 { private: uint32_t x, y, z, w; public: XorShift128() : x(123456789), y(362436069), z(521288629), w(88675123) { } uint32_t rnd() { uint32_t t = x ^ (x << 11); x = y; y = z; z = w; return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); } uint32_t rnd(const int n) { return rnd() % n; } uint32_t rnd(const int l, const int r) { // [l, r] return rnd() % (r - l + 1) + l; } }; long long get_time() { struct timeval tv; gettimeofday(&tv, NULL); long long result = tv.tv_sec * 1000LL + tv.tv_usec / 1000LL; return result; } XorShift128 xor_shift_128; long long start; const int NIL = -1; const int dh[2] = {0, 1}; const int dw[2] = {1, 0}; class Solver { int N, M; vector<string> strs; vector<vector<int>> datas; vector<vector<int>> ans; public: Solver(); void run(); private: int compute_score() const; void output_answer() const; }; Solver::Solver() { cin >> N >> M; strs.resize(M); for(int i = 0; i < M; ++i) { cin >> strs[i]; } datas.resize(M); for(int i = 0; i < M; ++i) { for(int j = 0; j < strs[i].size(); ++j) { int x = strs[i][j] - 'A'; datas[i].emplace_back(x); } } ans.resize(N); for(int hi = 0; hi < N; ++hi) { for(int wi = 0; wi < N; ++wi) { ans[hi].emplace_back(xor_shift_128.rnd(8)); } } } void Solver::run() { cerr << compute_score() << endl; output_answer(); } int Solver::compute_score() const { int cnt = 0; for(const vector<int>& data : datas) { for(int i = 0; i < 2; ++i) { for(int hi = 0; hi < N; ++hi) { for(int wi = 0; wi < N; ++wi) { bool match = true; for(int j = 0; j < data.size(); ++j) { int h = (hi + j * dh[i]) % N; int w = (wi + j * dw[i]) % N; if(ans[h][w] != data[j]) { match = false; break; } } if(match) { ++cnt; goto SEARCH_END; } } } } SEARCH_END: cnt; } if(cnt < M) { return round(1e8 * cnt / M); } else { int dots = 0; for(int hi = 0; hi < N; ++hi) { for(int wi = 0; wi < N; ++wi) { dots += ans[hi][wi] == -1; } } return round(1e8 * 2 * N * N / (2 * N * N - dots)); } } void Solver::output_answer() const { for(int hi = 0; hi < N; ++hi) { for(int wi = 0; wi < N; ++wi) { if(ans[hi][wi] == NIL) { cout << '.'; } else { cout << char(int('A') + ans[hi][wi]); } } cout << endl; } } int main() { Solver solver; solver.run(); }
//{{{ #include<algorithm> #include<cmath> #include<deque> #include<fstream> #include<iomanip> #include<iostream> #include<map> #include<numeric> #include<queue> #include<random> #include<set> #include<sstream> #include<sys/time.h> #include<unordered_map> #include<unordered_set> #include<vector> using ll = long long; enum : int { M = (int)1e9 + 7 }; enum : ll { MLL = (ll)1e18L + 9 }; using namespace std; #ifdef LOCAL #include"rprint2.hpp" #else #define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ } FUNC(printde) FUNC(printdbe) FUNC(printdwe) FUNC(printdu) FUNC(printe) FUNC(printe0); #endif template <template <class T, class = std::allocator<T>> class V, class E> istream& operator >> (istream& in, V<E>& v){ for(auto& e : v){ in >> e; } return in; } //}}} int main(){ cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; set<int> st; for(int i = 0; i < n; i++){ int a; cin >> a; st.insert(a); } while(st.size() > 1){ int x = *st.begin(); int X = *st.rbegin(); st.erase(X); int X2 = X % x; st.insert(X2 ? X2 : x); } cout << *st.begin() << '\n'; }
#include <cstdio> #include <cstdlib> #include <cmath> #include <climits> #include <cfloat> #include <map> #include <utility> #include <set> #include <iostream> #include <memory> #include <string> #include <vector> #include <algorithm> #include <functional> #include <sstream> #include <complex> #include <stack> #include <queue> #include <cstring> #include <assert.h> #include <sys/time.h> #include <fstream> #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define rep(i,n) FOR(i,0,n) #define REP(i,n) FOR(i,0,n) #define each(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i) #define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i) #define exist(s,e) ((s).find(e)!=(s).end()) #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; #define deb(x) cerr << #x << " = " << (x) << " , "; #define debl cerr << " (L" << __LINE__ << ")"<< endl; #define sz(s) (int)((s).size()) #define clr(a) memset((a),0,sizeof(a)) #define nclr(a) memset((a),-1,sizeof(a)) #define pb push_back #define INRANGE(x,s,e) ((s)<=(x) && (x)<(e)) #define MP(x,y) make_pair((x),(y)) double pi=3.14159265358979323846; using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<string> vs; template<typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& z){ os << "[ "; REP(i,z.size())os << z[i] << ", " ; return ( os << "]" << endl); } template<typename T> std::ostream& operator<<(std::ostream& os, const set<T>& z){ os << "set( "; EACH(p,z)os << (*p) << ", " ; return ( os << ")" << endl); } template<typename T,typename U> std::ostream& operator<<(std::ostream& os, const map<T,U>& z){ os << "{ "; EACH(p,z)os << (p->first) << ": " << (p->second) << ", " ; return ( os << "}" << endl); } template<typename T,typename U> std::ostream& operator<<(std::ostream& os, const pair<T,U>& z){ return ( os << "(" << z.first << ", " << z.second << ",)" ); } double get_time(){ struct timeval tv; gettimeofday(&tv, NULL); return tv.tv_sec + tv.tv_usec*1e-6; } typedef unsigned int uint32_t; struct RND{ uint32_t x; uint32_t y; uint32_t z; uint32_t w; RND(){ x=123456789; y=362436069; z=521288629; w=88675123; } void init(int seed){ x=123456789; y=362436069; z=521288629; w=seed+100; REP(i,10)get(); } uint32_t get(){ uint32_t t; t=x^(x<<11); x=y;y=z;z=w; w=(w^(w>>19))^(t^(t>>8)); return w; } }; RND rnd; ll gcd(ll a, ll b){ if(b==0)return a; return gcd(b,a%b); } void _main(istream &inp){ ll N; ll ret = 0; inp >> N; rep(j,N){ ll a; inp >> a; ret = gcd(ret,a); //deb(a);deb(ret);debl; } cout << ret << endl; } int main(){ if(0){ ifstream ifs("test.txt"); _main(ifs); } else{ _main(cin); } return 0; }
#include <bits/stdc++.h> #define endl '\n' #define ll long long #define ull unsigned long long #define PI 3.14159265359 #define rep(i, init, max) for (int i = (init); i < (int)(max); i++) #define eqrep(i, init, max) for (int i = (init); i <= (int)(max); i++) #define veccin(name) rep(i, 0, name.size()) cin >> name[i] #define vecsort(name) sort(name.begin(), name.end()) #define vecsortg(name) sort(name.begin(), name.end(), greater<int>()) #define debug(...) fprintf(stderr, __VA_ARGS__) using namespace std; template <typename T> T re() { T a; cin >> a; return a; } #pragma GCC diagnostic ignored "-Wunused-value" template <class T, class... Ts> void print(const T& a, const Ts&... b) { cout << a; (cout << ... << (cout << ' ', b)); cout << endl; } int main() { vector<int> in(3); veccin(in); vecsortg(in); print(in[0] + in[1]); return 0; }
#include<bits/stdc++.h> using namespace std; int main() { int a,b,c; cin>>a>>b>>c; if(a>=b && b>=c){ cout<<a+b<<endl; } else if(a>=b && b<=c){ cout<<a+c<<endl; }else if(a<=b && a>=c){ cout<<a+b<<endl; } else { cout<<b+c<<endl; } }
/*---XXX---XXX---XXX---XXX---XXX---XXX---XXX---XXX---XXX---XXX---XXX---XXX---XXX---XXX---XXX---XXX---XXX---XXX---*/ #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; #define rep(a, b) for(int a = 0; a < (b); ++a) #define rep1(a, b, c) for(int a = (b); a < (c); ++a) #define rrep(a, b, c) for(int a = (b); a > c; --a) #define each(a, b) for(auto& a : b) #define sz(x) (int)(x).size() #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(), (a).rend() #define lb lower_bound #define ub upper_bound #define pb push_back #define eb emplace_back #define mp make_pair #define fi first #define se second #define dbg(x) cout << #x << " = " << x << endl; #define vt vector #define pii pair<int, int> #define pll pair<ll, ll> #define bitcnt(x) __builtin_popcount(x) #define fbo(x) find_by_order(x) #define ook(x) order_of_key(x) template <typename T> using oset = 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; } using ll = long long; using ld = long double; using str = string; const int inf = (int)1e9 + 5; const ll infl = (ll)1e18 + 5; const int mod = 1e9 + 7; const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1}; const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1}; /*---XXX---XXX---XXX---XXX---XXX---XXX---XXX---XXX---XXX---XXX---XXX---XXX---XXX---XXX---XXX---XXX---XXX---XXX---*/ struct UnionFindTree{ vt<int> parent; vt<int> siz; UnionFindTree(int n){ parent.resize(n); siz.resize(n, 1); rep(i, n) parent[i] = i; } int root(int x){ return (x==parent[x]?x:parent[x]=root(parent[x])); } void unite(int x, int y){ x = root(x); y = root(y); if(x==y) return; if(siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; parent[x] = y; } bool same(int x, int y){ return(root(x) == root(y)); } }; const int N = 100; int n; int x[N], y[N]; bool go(double m){ UnionFindTree uft(n+2); rep(i, n){ if(abs(100 - y[i]) <= 2*m) uft.unite(i, n); if(abs(100 + y[i]) <= 2*m) uft.unite(i, n+1); rep1(j, i+1, n){ double d = sqrt(pow(x[i]-x[j], 2) + pow(y[i]-y[j], 2)); if(d <= 2*m) uft.unite(i, j); } } return !(uft.same(n, n+1)); } void solve(){ cin >> n; rep(i, n) cin >> x[i] >> y[i]; double l = 0, r = 100, m; while(r - l > 1e-6){ m = (l+r)/2; if(go(m)) l = m; else r = m; } cout << fixed << setprecision(6) << l << '\n'; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); solve(); }
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <cmath> using namespace std; const int maxn = 100 + 5; const int modu = 1e9 + 7; const double eps = 1e-5; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; typedef long long LL; int n; int nails[maxn][2]; bool g[205][205], vis[205]; bool dfs(int x) { vis[x] = true; if (x == n+1) return true; for (int i = 0; i <= n+1; ++i) { if (!vis[i] && g[x][i]) if (dfs(i)) return true; } return false; } double dist2(int i, int j) { double x = nails[i][0] - nails[j][0]; double y = nails[i][1] - nails[j][1]; return x*x + y*y; } bool check(double radius) { memset(vis, 0, sizeof(vis)); memset(g, 0, sizeof(g)); for (int i = 0; i < n; ++i) { for (int j = i+1; j < n; ++j) { if (radius*radius*4 > dist2(i, j)) g[i][j] = g[j][i] = true; } if (nails[i][1] < radius*2) g[i][n] = g[n][i] = true; if (200 - nails[i][1] < radius*2) g[i][n+1] = g[n+1][i] = true; } return !dfs(n); } double bs(double l, double r) { while (r-l >= eps) { double mid = (l+r) / 2; if (check(mid)) l = mid; else r = mid; } // for (int i = 0; i <= 200; ++i) { // for (int j = 0; j <= 200; ++j) // printf("%d", g[i][j]); // printf("\n"); // } return l; } int main() { // freopen("my.txt", "w", stdout); cin >> n; for (int i = 0; i < n; ++i) { scanf("%d%d", &nails[i][0], &nails[i][1]); nails[i][0] += 100; nails[i][1] += 100; } cout << bs(0, 100) << endl; return 0; }
#include <bits/stdc++.h> #include <math.h> using namespace std; using ll = long long; using vll = vector<ll>; using vpl = vector<pair<ll, ll>>; using pll = pair<ll, ll>; #define rep(i, k, n) for(ll i = k; i < n; i++) #define pb push_back #define mp make_pair ll n, m, s; //頂点の数, 辺の数, スタート地点 vll A(3010); //辺の始点 vll B(3010); //辺の終点 vll C(3010); //辺のコスト vll dist(3010); //最短距離 vector<vpl> G(3010, vpl(0)); //隣接する頂点とコストをセットにした記憶したもの priority_queue<pll, vpl, greater<pll>> Q; int main(){ cin >> n >> m; rep(i, 1, m+1){ cin >> A[i] >> B[i] >> C[i]; G[A[i]].pb(mp(C[i], B[i])); } rep(i, 1, n+1){ //距離の初期化 rep(j, 0, 3010){ dist[j] = 1000000007; } //帰ってくる場所の追加 rep(j, 1, n+1){ rep(k, 0, G[j].size()){ if(G[j][k].second == i){ G[j].pb(mp(G[j][k].first, 3000)); } } } //優先度付きキューに(距離, 頂点番号)の組を入れる Q.push(mp(0, i)); dist[i] = 0; while(!Q.empty()){ ll pos = Q.top().second; Q.pop(); rep(j, 0, G[pos].size()){ ll to = G[pos][j].second; ll cost = G[pos][j].first; //posを経由してtoに行く距離がdist[to]より短ければ //dist[to]を更新してキューに入れる if(dist[to] > dist[pos] + cost){ dist[to] = dist[pos] + cost; Q.push(mp(dist[to], to)); } } } //帰ってくる場所の削除 rep(j, 1, n+1){ ll rec = 0; rep(k, 0, G[j].size()){ if(G[j][k].second == 3000){ rec++; } } rep(k, 0, rec){ G[j].pop_back(); } } // cout << i << " : "; // rep(j, 0, 3010){ // if(dist[j] != 1000000007){ // cout << "{" << j << ", " << dist[j] << "}"; // } // } if(dist[3000] != 1000000007){ cout << dist[3000] << endl; } else{ cout << -1 << endl; } } // rep(i, 1, n+1){ // cout << i << " : "; // rep(j, 0, G[i].size()){ // printf(" {%lld, %lld},", G[i][j].second, G[i][j].first); // } // cout << endl; // } }
#include <iostream> #include <stdlib.h> #include <stdio.h> #include <algorithm> #include <math.h> #include <vector> #include <map> #include <queue> #include <limits.h> #include <stack> using namespace std; typedef long long ll; const int maxn = 110; int H, W, A, B, ans = 0; void solve(int s, int bit, int a, int b) { if(s==H*W) { ans++; return ; } if(bit&(1<<s)) return solve(s+1, bit, a, b); if(a) { if(s%W!=W-1 && !(bit&(1<<(s+1)))) solve(s+1, bit|(1<<s)|(1<<(s+1)), a-1, b); if(s+W<H*W) solve(s+1, bit|(1<<s)|(1<<(s+W)), a-1, b); } if(b) solve(s+1, bit|(1<<s), a, b-1); } int main() { //freopen("/Users/zhangkanqi/Desktop/11.txt", "r", stdin); cin >> H >> W >> A >> B; solve(0, 0, A, B); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int r,c; cin>>r>>c; vector<vector<char>>vec(r,vector<char>(c)); for(int i=0;i<r;i++) { string s; cin>>s; for(int j=0;j<c;j++) vec[i][j]=s[j]; } int ans=0; for(int i=0;i<r;i++){ for(int j=0;j<c;j++){ if(vec[i][j]=='.' && j+1<c && vec[i][j+1]=='.') ans+=1; if(vec[i][j]=='.' && i+1<r && vec[i+1][j]=='.') ans+=1; } } cout<<ans<<endl; }
#include "iostream" #include "algorithm" #include "cstring" #include "cstdio" #include "cmath" #include "vector" #include "map" #include "set" #include "queue" #include "string" #include "unordered_map" #include "assert.h" using namespace std; #define MAXN 200006 //#define int long long #define rep( i , a , b ) for (int i = (a), i##end = (b); i <= i##end; ++i) #define per( i , a , b ) for (int i = (a), i##end = (b); i >= i##end; --i) #define pii pair<int,int> #define fi first #define se second #define mp make_pair #define pb push_back #define eb emplace_back #define vi vector<int> #define all( x ) (x).begin() , (x).end() #define mem( a ) memset( a , 0 , sizeof a ) typedef long long ll; #define P 998244353 int n; char ch[MAXN]; int A[MAXN]; map<int,int> M; void solve( ) { cin >> n;scanf("%s",ch + 1); int res = 0; M[0] ++; rep( i , 1 , n ) { if( ch[i] == 'A' ) A[i] = A[i - 1] + 10000; if( ch[i] == 'T' ) A[i] = A[i - 1] - 10000; if( ch[i] == 'G' ) A[i] = A[i - 1] + 1; if( ch[i] == 'C' ) A[i] = A[i - 1] - 1; res += M[A[i]]; M[A[i]] ++; } cout << res << endl; } signed main( ) { // freopen("input","r",stdin); // freopen("fuckout","w",stdout); // int T;cin >> T;while( T-- ) solve(); solve( ); }
#include <bits/stdc++.h> using namespace std; int main(){ long n; cin >> n; set<long> ans; for(long d=1;d*d<=n;d++){ if(n%d==0){ ans.insert(d); ans.insert(n/d); } } for(auto x:ans)cout << x << endl; }
#pragma GCC optimize("O3") #pragma GCC target("sse4") #include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using pi = pair<int, int>; using vpi = vector<pair<int, int>>; using pl = pair<ll, ll>; using vl = vector<ll>; #define all(v) (v).begin(), (v).end() #define ar array #define PB push_back #define sz(x) (int)(x).size() template <typename T> using pqg = priority_queue<T, vector<T>, greater<T>>; template <typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } template <typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream &operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; } void dbg_out() { cerr << endl; } template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); } #ifdef LOCAL #define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__) #else #define dbg(...) #endif 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); } }; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int INF = 1e9; const ll LINF = 1e18; const int MOD = 1e9 + 7; //998244353 void solve() { ll n; cin >> n; ll l = 1, r = 1e6, ans = 0; while(l<=r){ ll m = l+(r-l)/2; if (m*(m+1)/2>=n){ ans = m; r = m-1; }else l = m+1; } cout << ans << "\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); int testcase=1; //cin >> testcase; while (testcase--) { solve(); } }
//g++ 7.4.0 #include <iostream> #include <bits/stdc++.h> using namespace std; typedef long long ll; #define MAXN 100005 ll C[MAXN]; ll D[MAXN]; vector<pair<ll,ll>> adj[MAXN]; ll dis[MAXN]; ll getDis(ll t, ll c, ll d) { return(t + c + d/(t + 1LL)); } void dijkstra(ll source) { set<pair<ll,ll>> s; s.insert({dis[source], source}); while(!s.empty()) { pair<ll,ll> p = *s.begin(); s.erase(p); ll u = p.second; //cout<<u<<endl; for(auto it: adj[u]) { ll v = it.first; ll index = it.second; ll c = C[index]; ll d = D[index]; ll wait = max(0LL, (ll)sqrt(d) - dis[u]); ll ans = LLONG_MAX; for(ll i=0;i<=3;++i) { ll w = max(0LL, wait + i); ans = min(ans, getDis(w + dis[u], c, d)); w = max(0LL, wait - i); ans = min(ans, getDis(w + dis[u], c, d)); } //cout<<u<<" "<<v<<" "<<ans<<endl; if(dis[v] > ans) { s.erase({dis[v], v}); dis[v] = ans; s.insert({dis[v], v}); } } } } //Shit Man: There can be multiple edges as well int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll N,M; cin>>N>>M; for(ll i=1;i<=N;++i) dis[i] = LLONG_MAX; for(ll i=0;i<M;++i) { ll u,v; cin>>u>>v; adj[u].push_back({v, i}); adj[v].push_back({u, i}); cin>>C[i]; cin>>D[i]; } dis[1] = 0; dijkstra(1); if(dis[N] == LLONG_MAX) cout<<-1<<endl; else cout<<dis[N]<<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(1e18)+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;} #define num_l(a,v) POSL(a,v) //v未満の要素数 #define num_eql(a,v) POSU(a,v) //v以下の要素数 #define num_h(a,v) (a.size() - POSU(a,v)) //vより大きい要素数 #define num_eqh(a,v) (a.size() - POSL(a,v)) //v以上の要素数 // static_cast< long long ll > int main(){ int N,M; cin >> N >> M; vector<ll> G[N+1]; vector<ll> A(M),B(M),C(M),D(M); FOR(i,0,M){ cin >> A[i] >> B[i] >> C[i] >> D[i]; G[A[i]].push_back(i); G[B[i]].push_back(i); } priority_queue<P, vector<P>, greater<P> > Q; //小さいものから出る Q.push({0,1});//{Time,vart} vector<int> did(N+1,0); vector<ll> T(N+1,INF); T[1] = 0; while(Q.size()){ int u = Q.top().second; Q.pop(); if(did[u])continue; did[u] = true; FOR(ind,0,G[u].size()){ int v = B[G[u][ind]]; if(v==u) v = A[G[u][ind]]; if(did[v])continue; if(u==v)continue; ll t = sqrt(D[G[u][ind]]); ll at = INF; FOR(j,max(t-100,T[u]),max(t+100,T[u])+1){//出る時刻 at = min(at, j + D[G[u][ind]]/(j+1) + C[G[u][ind]]); } //cout << at << " atat" << endl; if(T[v] > at){ T[v] = at; Q.push({at,v}); } } } if(T[N] == INF)T[N] = -1; cout << T[N] << endl; //FOR(i,0,N+1) cout << T[i] << " "; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < n; i++) #define rep2(i, x, n) for(int i = x; i <= n; i++) #define rep3(i, x, n) for(int i = x; i >= n; i--) #define each(e, v) for(auto &e: v) #define pb push_back #define eb emplace_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define sz(x) (int)x.size() using ll = long long; using pii = pair<int, int>; using pil = pair<int, ll>; using pli = pair<ll, int>; using pll = pair<ll, ll>; const int MOD = 1000000007; //const int MOD = 998244353; const int inf = (1<<30)-1; const ll INF = (1LL<<60)-1; template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;}; template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;}; struct io_setup{ io_setup(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout << fixed << setprecision(15); } } io_setup; int main(){ int N; cin >> N; vector<ll> A(2*N); rep(i, 2*N) cin >> A[i]; vector<ll> B(2*N); rep(i, N){ B[2*i] = A[N-1-i], B[2*i+1] = A[N+i]; } priority_queue<ll, vector<ll>, greater<ll>> que; ll S = accumulate(all(A), 0LL); rep(i, N){ que.emplace(B[2*i]), que.emplace(B[2*i+1]); S -= que.top(); que.pop(); } cout << S << '\n'; }
#include<bits/stdc++.h> using namespace std; typedef long long ll;typedef double db; typedef pair<int, int> pii;typedef pair<ll, ll> pll; typedef pair<int,ll> pil;typedef pair<ll,int> pli; #define Fi first #define Se second #define _Out(a) cerr<<#a<<" = "<<(a)<<endl const int INF = 0x3f3f3f3f, MAXN = 1e6 + 50; const ll LINF = 0x3f3f3f3f3f3f3f3f, MOD = 998244353; const db Pi = acos(-1), EPS = 1e-6; void test(){cerr << "\n";}template<typename T,typename...Args>void test(T x,Args...args){cerr<<x<<" ";test(args...);} inline ll qpow(ll a, ll b){return b?((b&1)?a*qpow(a*a%MOD,b>>1)%MOD:qpow(a*a%MOD,b>>1))%MOD:1;} inline ll qpow(ll a, ll b,ll c){return b?((b&1)?a*qpow(a*a%c,b>>1,c)%c:qpow(a*a%c,b>>1,c)) %c:1;} inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} inline ll cede(ll a,ll b){if(b<0)return cede(-a,-b);if(a<0)return a/b;return (a+b-1)/b;} inline ll flde(ll a,ll b){if(b<0)return flde(-a,-b);if(a<0)return (a-b+1)/b;return a/b;} inline int sign(db x){return x<-EPS ? -1:x>EPS;} inline int dbcmp(db l,db r){return sign(l - r);} namespace Fast_IO{ //orz laofu const int MAXL((1 << 18) + 1);int iof, iotp; char ioif[MAXL], *ioiS, *ioiT, ioof[MAXL],*iooS=ioof,*iooT=ioof+MAXL-1,ioc,iost[55]; char Getchar(){ if (ioiS == ioiT){ ioiS=ioif;ioiT=ioiS+fread(ioif,1,MAXL,stdin);return (ioiS == ioiT ? EOF : *ioiS++); }else return (*ioiS++); } void Write(){fwrite(ioof,1,iooS-ioof,stdout);iooS=ioof;} void Putchar(char x){*iooS++ = x;if (iooS == iooT)Write();} inline int read(){ int x=0;for(iof=1,ioc=Getchar();(ioc<'0'||ioc>'9')&&ioc!=EOF;)iof=ioc=='-'?-1:1,ioc=Getchar(); if(ioc==EOF)Write(),exit(0); for(x=0;ioc<='9'&&ioc>='0';ioc=Getchar())x=(x<<3)+(x<<1)+(ioc^48);return x*iof; } inline long long read_ll(){ long long x=0;for(iof=1,ioc=Getchar();(ioc<'0'||ioc>'9')&&ioc!=EOF;)iof=ioc=='-'?-1:1,ioc=Getchar(); if(ioc==EOF)Write(),exit(0); for(x=0;ioc<='9'&&ioc>='0';ioc=Getchar())x=(x<<3)+(x<<1)+(ioc^48);return x*iof; } void Getstr(char *s, int &l){ for(ioc=Getchar();ioc==' '||ioc=='\n'||ioc=='\t';)ioc=Getchar(); if(ioc==EOF)Write(),exit(0); for(l=0;!(ioc==' '||ioc=='\n'||ioc=='\t'||ioc==EOF);ioc=Getchar())s[l++]=ioc;s[l] = 0; } template <class Int>void Print(Int x, char ch = '\0'){ if(!x)Putchar('0');if(x<0)Putchar('-'),x=-x;while(x)iost[++iotp]=x%10+'0',x/=10; while(iotp)Putchar(iost[iotp--]);if (ch)Putchar(ch); } void Putstr(const char *s){for(int i=0,n=strlen(s);i<n;++i)Putchar(s[i]);} } // namespace Fast_IO using namespace Fast_IO; ll fac[MAXN],invfac[MAXN]; void init() { fac[0]=1;for(int i=1;i<MAXN;i++)fac[i]=fac[i-1]*i%MOD; invfac[MAXN-1]=qpow(fac[MAXN-1],MOD-2); for(int i=MAXN-2;i>=0;i--)invfac[i]=invfac[i+1]*(i+1)%MOD; } inline ll C(int n,int m) { if(m<0||m>n)return 0; return fac[n]*invfac[m]%MOD*invfac[n-m]%MOD; } ll tot[333]; void work() { int n=read(),k=read(); for(int i=1;i<=n;i++) { ll x=read(); ll now=1; for(int j=0;j<=k;j++) { tot[j]=(tot[j]+now)%MOD; now=now*x%MOD; } } ll mi2=1; for(int i=1;i<=k;i++) { mi2=mi2*2%MOD; ll ans=0; for(int j=0;j<=i;j++) { ans=(ans+tot[j]*tot[i-j]%MOD*C(i,j)%MOD)%MOD; } ans=(ans-tot[i]*mi2%MOD+MOD)*qpow(2,MOD-2)%MOD; printf("%lld\n",ans); } } int main() { init(); //std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); //int T=read();for(int cas=1;cas<=T;cas++) //int T;scanf("%d",&T);for(int i=1;i<=T;i++) work(); // Write(); } /** 2 5 3 6 3 1 2 4 5 */
// // main.cpp // #include <algorithm> #include <array> #include <assert.h> #include <complex> #include <iomanip> #include <iostream> #include <limits> #include <inttypes.h> #include <map> #include <math.h> #include <memory> #include <memory> #include <queue> #include <random> #include <set> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <vector> // #include <atcoder/dsu> // using namespace atcoder; // using mint = modint1000000007; // using mint = modint998244353; // using mint = modint; using namespace std; using ll = int64_t; using ull = uint64_t; [[maybe_unused]] constexpr ll LL_MAX = numeric_limits<ll>::max(); [[maybe_unused]] constexpr ll LL_MIN = numeric_limits<ll>::min(); [[maybe_unused]] constexpr ull ULL_MAX = numeric_limits<ull>::max(); #define rep(i, a, b) for (ll i = (a); i < (b); i++) #define rrep(i, a, b) for (ll i = (a)-1; i >= (b); i--) template<typename T> void chmin(T& x, T y) { x = min(x, y); } template<typename T> void chmax(T& x, T y) { x = max(x, y); } ll csum(ll x, ll y) { if (x > 0 && y > 0 && x > LL_MAX - y) { return LL_MAX; } if (x < 0 && y < 0 && x < LL_MIN - y) { return LL_MIN; } return x + y; } ll readi() { ll ret; scanf("%" PRId64 "", &ret); return ret; } vector<ll> readvi(ll n) { vector<ll> ret(n); rep(i, 0, n) { ret[i] = readi(); } return ret; } double readf() { double ret; scanf("%lf", &ret); return ret; } string reads() { string s; cin >> s; return s; } void writei(ll x) { printf("%" PRId64 "\n", x); } void writevi(const vector<ll>& xs) { rep(i,0,xs.size()) { if (i < xs.size() - 1) { printf("%" PRId64 " ", xs[i]); } else { printf("%" PRId64 "\n", xs[i]); } } } void writes(const string& s) { cout << s.c_str() << endl; } template<typename T> vector<T> make_vec_nd(T init, ll size) { return vector<T>(size, init); } template<typename T, typename... Args> auto make_vec_nd(T init, ll size, Args... rest) { auto inner = make_vec_nd(init, rest...); return vector<decltype(inner)>(size, inner); } struct P { ll x; ll y; }; int main() { ll N = readi(); ll M = readi(); vector<ll> hs = readvi(N); vector<ll> ws = readvi(M); sort(hs.begin(), hs.end()); sort(ws.begin(), ws.end()); struct HW { bool isH; ll idx; ll height; bool operator<(const HW& rhs) const { return height < rhs.height || (height == rhs.height && isH < rhs.isH); } }; vector<HW> hws; rep(i,0,N) { hws.push_back({true, i, hs[i]}); } rep(i,0,M) { hws.push_back({false, i, ws[i]}); } sort(hws.begin(), hws.end()); vector<ll> leftCnt(M); ll cnt = 0; for (HW& hw : hws) { if (hw.isH) { cnt++; } else { leftCnt[hw.idx] = cnt; } } auto makePairs = [N, &hs]() { vector<ll> leftPairs(N+1); rep(n,1,N+1) { if (n%2 == 0) { leftPairs[n] = leftPairs[n-1] + abs(hs[n-1] - hs[n-2]); } else { leftPairs[n] = leftPairs[n-1]; } } return leftPairs; }; vector<ll> leftPairs = makePairs(); reverse(hs.begin(), hs.end()); vector<ll> rightPairs = makePairs(); reverse(hs.begin(), hs.end()); // writevi(leftPairs); // writevi(rightPairs); ll ans = LL_MAX; rep(i,0,M) { ll ansLoc = 0; if (leftCnt[i] % 2 == 1) { ansLoc += leftPairs[leftCnt[i]]; ansLoc += ws[i] - hs[leftCnt[i]-1]; ansLoc += rightPairs[N-leftCnt[i]]; } else { ansLoc += leftPairs[leftCnt[i]]; ansLoc += hs[leftCnt[i]] - ws[i]; ansLoc += rightPairs[N-leftCnt[i]-1]; } chmin(ans, ansLoc); } writei(ans); }
#pragma GCC optimize("O3") #pragma GCC target("avx2") #include <algorithm> #include <iostream> #include <vector> #include <array> using namespace std; #define f(x,y,z) for(int x=y;x<=z;++x) vector<int> v[200001]; array<int, 200001> jr, dkt, tdk, at, uj; int n, k, a, b, l, r, m, hit; void jrk(int x) { for(int &i:v[x]) if(i != at[x]) { at[i] = x, jr[i] = jr[x]+1, jrk(i); } } bool cek(int &x) { // cerr << x; fill(dkt.begin(), dkt.end(), 0x3f3f3f3f); fill(tdk.begin(), tdk.end(), 0); hit = 0; f(i,1,n) { int &z = uj[i]; // cerr << ' ' << z; if(dkt[z]+tdk[z] <= x) { tdk[z] = -1; } else if(tdk[z] == x || (z == 1 && tdk[z] >= 0)) { ++hit, tdk[z] = -1, dkt[z] = 0; } tdk[at[z]] = max(tdk[at[z]], tdk[z]+1); dkt[at[z]] = min(dkt[at[z]], dkt[z]+1); } // cerr << '\n'; return hit <= k; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin >> n >> k; f(i,2,n) { cin >> a >> b; v[a].push_back(b); v[b].push_back(a); } jrk(1); f(i,1,n) uj[i] = i; sort(uj.begin()+1, uj.begin()+n+1, [](int &i, int &j){ return jr[i] > jr[j]; }); l = 1, r = n-1; while(l <= r) { m = (l+r)>>1; cek(m) ? r = m-1 : l = m+1; } cout << l << '\n'; }
#include <bits/stdc++.h> using namespace std; inline long long read(){ long long s = 0, w = 1; char ch = getchar(); while (ch < '0' || ch > '9'){ if (ch == '-') w = -1; ch = getchar(); } while (ch >= '0' && ch <= '9'){ s = s * 10 + ch - '0'; ch = getchar(); } return s * w; } int main(){ int a = read(), b = read(), c = read(); bool f = c; while(1){ if(!f){ if (a == 0){ puts("Aoki"); return 0; } a--; } else{ if (b == 0){ puts("Takahashi"); return 0; } b--; } f ^= 1; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using VI = vector<int>; using VL = vector<ll>; using VS = vector<string>; template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>; #define FOR(i,a,n) for(int i=(a);i<(n);++i) #define eFOR(i,a,n) for(int i=(a);i<=(n);++i) #define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i) #define erFOR(i,a,n) for(int i=(n);i>=(a);--i) #define SORT(a) sort(a.begin(),a.end()) #define rSORT(a) sort(a.rbegin(),a.rend()) #define fSORT(a,f) sort(a.begin(),a.end(),f) #define all(a) a.begin(),a.end() #define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x)) #define tp(a,i) get<i>(a) #define line cout << "-----------------------------\n" #define stop system("pause") constexpr ll INF = 1000000000; constexpr ll LLINF = 1LL << 60; constexpr ll mod = 1000000007; constexpr ll MOD = 998244353; constexpr ld eps = 1e-10; constexpr ld pi = 3.1415926535897932; template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; } template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; } inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; } template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& a : v)is >> a; return is; } template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; } template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); } template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); } template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); } template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); } template<class T>inline void print(const T& a) { cout << a << "\n"; } template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); } template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); } template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); } inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; } template<class T>inline T sum(const vector<T>& a, int l, int r) { return a[r] - (l == 0 ? 0 : a[l - 1]); } int main() { init(); int n, m; cin >> n >> m; VI w(n); cin >> w; SORT(w); vector<pair<int, int>> lv(m); cin >> lv; fSORT(lv, [](auto x, auto y) { if (x.second == y.second)return x.first < y.first; return x.second < y.second;}); if (lv[0].second < w.back()) { print(-1); return 0; } FOR(i, 1, m)chmax(lv[i].first, lv[i - 1].first); int ans = INF; do { VI s(n); FOR(i, 0, n)s[i] = w[i] + (i == 0 ? 0 : s[i - 1]); VI dp(n); FOR(i, 0, n)FOR(j, i + 1, n) { int ok = m, ng = -1; while (ok - ng > 1) { int mid = ok + ng >> 1; if (sum(s, i, j) <= lv[mid].second)ok = mid; else ng = mid; } int d = (ok == 0 ? 0 : lv[ok - 1].first); chmax(dp[j], dp[i] + d); } chmin(ans, dp[n - 1]); } while (next_permutation(all(w))); print(ans); return 0; }
#include<bits/stdc++.h> #define pb push_back #define mk make_pair #define ll long long #define ss second #define ff first #define mod 1000000007 #define w(x) ll x; cin>>x; while(x--) #define ps(x,y) fixed<<setprecision(y)<<x; #define fo(i, j, k, in) for (ll i=j ; i<k ; i+=in) #define re(i, j) fo(i, 0, j, 1) #define pi acos(-1) #define all(cont) cont.begin(), cont.end() #define countbit(x) __builtin_popcount(x) #define mod 1000000007 #define de(n) ll n;cin>>n; #define def(a,n) ll n;cin>>n;ll a[n];re(i,n){cin>>a[i];} #define defi(a,n,k) ll n;cin>>n; ll k;cin>>k;ll a[n];re(i,n){cin>>a[i];} #define deb(x) cout<<#x<<"="<<x<<endl; #define tr(it,a) for(auto it=a.begin();it!=a.end();it++) #define nl cout<<endl; using namespace std; //18-1326D1 1208B 845C 912B 1009B 1350C 20C 1333C 1234D 1327C 1305B 1304B (or in matrix) 1216-C(26) 21 void cp() { ios :: 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 main() { //cp(); //w(x) { de(a); de(b); de(c); ll m=998244353; ll ans=1; if(a%2==0) { ans=((ans%m)*(a/2)%m)%m; ans=((ans%m)*(a+1)%m)%m; } else { ans=((ans%m)*((a+1)/2)%m)%m; ans=((ans%m)*(a)%m)%m; } if(b%2==0) { ans=((ans%m)*(b/2)%m)%m; ans=((ans%m)*(b+1)%m)%m; } else { ans=((ans%m)*((b+1)/2)%m)%m; ans=((ans%m)*(b)%m)%m; } if(c%2==0) { ans=((ans%m)*(c/2)%m)%m; ans=((ans%m)*(c+1)%m)%m; } else { ans=((ans%m)*((c+1)/2)%m)%m; ans=((ans%m)*(c)%m)%m; } cout<<ans; } }
#include <bits/stdc++.h> using namespace std; #define endl "\n" #define pb push_back #define fo(i, start, end) for (ll i = start; i < end; i++) #define rep(i, start, end, step) for (ll i = start; i < end; i += step) #define print(x) cout << #x << " is " << x << endl #define all(arg) arg.begin(), arg.end() #define sz(arg) (int)arg.size() using ll = long long; using vi = vector<int>; using vll = vector<long long>; void solve() { int n, m; cin >> n >> m; int a; vector<vi> mp(n); fo(i, 0, n) mp[i].push_back(-1); fo(i, 0, n) { cin >> a; mp[a].push_back(i); } fo(i, 0, n) mp[i].push_back(n); fo(i, 0, n) { fo(j, 1, (ll)mp[i].size()) { if (mp[i][j] - mp[i][j - 1] > m) { cout << i << endl; return; } } } cout << n << endl; } int main() { #ifndef DEBUG ios::sync_with_stdio(false); cin.tie(nullptr); #endif solve(); return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main(){ string s; cin>>s; string ss=""; ll x=s.length(); for(ll i=(x-1);i>=0;i--){ ss+=s[i]; } for(ll i=0;i<(ll)ss.length();i++){ if(ss[i]=='6'){ss[i]='9'; continue;} if(ss[i]=='9')ss[i]='6'; } cout<<ss; }
#include<bits/stdc++.h> #define icantcode ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); using namespace std; bool can = 1; string s; int main(){ icantcode cin>>s; int l = s.length(); for(int i=0;i<l;i++){ if(i%2 == 0){ if(s[i]>='A' && s[i]<='Z'){ can = 0; break; } } else{ if(s[i]>='a' && s[i]<='z'){ can = 0; break; } } } if(can) cout<<"Yes"; else cout<<"No"; return 0; }
#include <iostream> #include <vector> #include <cassert> using namespace std; #include <iostream> #include <cassert> template<long long mod> class modint{ private: using T = long long; T a; public: constexpr modint(const long long x = 0) noexcept : a((x%mod+mod)%mod) {} constexpr T& value() noexcept { return a; } constexpr const T& value() const noexcept { return a; } constexpr modint operator-() const noexcept { return modint(0) -= *this; } constexpr modint operator+(const modint& rhs) const noexcept { return modint(*this) += rhs; } constexpr modint operator-(const modint& rhs) const noexcept { return modint(*this) -= rhs; } constexpr modint operator*(const modint& rhs) const noexcept { return modint(*this) *= rhs; } constexpr modint operator/(const modint& rhs) const noexcept { return modint(*this) /= rhs; } constexpr modint& operator+=(const modint& rhs) noexcept { a += rhs.a; if(a >= mod) a -= mod; return *this; } constexpr modint &operator-=(const modint& rhs) noexcept { if(a < rhs.a) a += mod; a -= rhs.a; return *this; } constexpr modint& operator*=(const modint& rhs) noexcept { a = a*rhs.a%mod; return *this; } constexpr modint& operator/=(const modint& rhs) noexcept { return *this *= rhs.inv(); } constexpr bool operator==(const modint& rhs) const noexcept { return a == rhs.a; } constexpr bool operator!=(const modint& rhs) const noexcept { return not (*this == rhs); } constexpr modint pow(long long k) const noexcept { modint ret(1); modint x = k > 0 ? *this : this->inv(); k = abs(k); while(k > 0){ if(k&1) ret *= x; x *= x; k >>= 1; } return ret; } constexpr modint inv() const noexcept { return pow(mod-2); } friend std::ostream& operator<<(std::ostream &os, const modint &X) noexcept { return os << X.a; } friend std::istream& operator>>(std::istream &is, modint &X) noexcept { is >> X.a; X.a %= mod; if(X.a < 0) X.a += mod; return is; } }; template<typename T> struct Combination { private: int sz; vector<T> F, F_; public: Combination(int sz) : sz(sz), F(sz+1), F_(sz+1) { F[0] = 1; for(int i = 0; i < sz; ++i) F[i+1] = F[i]*(i+1); F_.back() = (T)1/F.back(); for(int i = sz-1; i >= 0; --i) F_[i] = F_[i+1]*(i+1); } T C(int n, int k){ assert(n <= sz); if(n < 0 or k > n) return (T)0; return F[n]*F_[k]*F_[n-k]; } T P(int n, int k){ assert(n <= sz); if(n < 0 or k > n) return (T)0; return F[n]*F_[n-k]; } }; int main(){ using mint = modint<998244353>; int n, m; cin >> n >> m; vector<vector<int>> D(m+1); for(int i = 2; i <= m; ++i){ if(D[i].size()) continue; for(int j = 1; j*i <= m; ++j){ int k = i*j, c = 0; while(k%i == 0){ ++c; k /= i; } D[j*i].emplace_back(c); } } Combination<mint> comb(n+100); mint ans = 0; for(int i = 1; i <= m; ++i){ mint t = 1; for(auto e : D[i]){ t *= comb.C(n+e-1,n-1); } ans += t; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG #define rep(i, from, to) for (ll i = from; i < (to); ++i) #define mp(x,y) make_pair(x,y) #define all(x) (x).begin(),(x).end() #define sz(x) (int)(x).size() #define pb push_back using ll = long long; using ld=long double; using vin=vector<int>; using vvin=vector<vin>; using vll=vector<ll>; using vvll=vector<vll>; using vst=vector<string>; using P = pair<ll,ll>; const int inf=1e9+7; const ll INF=9e18; const long double PI = acos(-1.0); template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;} template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;} template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; } template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; } const int dx[4] = { 1, 0, -1, 0 }; const int dy[4] = { 0, 1, 0, -1 }; int main(){//cout<<fixed<<setprecision(20); int a,b; cin>>a>>b; cout<<(a+b)/2<<" "<<(a-b)/2<<endl; }
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define Mp make_pair #define pb push_back using ll = long long; using db = double; using pii = pair<int, int>; using vi = vector<int>; mt19937 mrand(time(0)); ll get(ll r) { return ((ll)mrand() * mrand() % r + r) % r; } ll get(ll l, ll r) { return get(r - l + 1) + l; } int n, a[300], f[300], id[300], x[300], y[300], cnt[300]; bool valid(int l, int len) { for (int i = 1; i <= n / 2; ++i) { if (x[i] != -1 && y[i] != -1) { if (x[i] >= l + 2 * len) continue; if (y[i] < l) continue; if (x[i] >= (l + len)) return false; if (x[i] < l) return false; if (((y[i] - x[i]) != len)) return false; } else if (x[i] == -1) { if (y[i] >= (l + 2 * len)) continue; if (y[i] < l) continue; if (y[i] < l + len) return false; if (a[y[i] - len]) return false; } else if (y[i] == -1) { if (x[i] < l) continue; if (x[i] >= l + 2 * len) continue; if (x[i] >= l + len) return false; if (a[x[i] + len]) return false; } } return true; } signed main() { scanf("%d", &n); for(int i = 1; i <= n; i++) { scanf("%d %d", &x[i], &y[i]); if(x[i] != -1 && y[i] != -1 && x[i] >= y[i]) return puts("No"), 0; ~x[i] ? a[x[i]] = 1, cnt[x[i]]++, id[x[i]] = i : 0; ~y[i] ? a[y[i]] = 1, cnt[y[i]]++, id[y[i]] = i : 0; } n <<= 1, f[0] = 1; for(int i = 1; i <= n; i++) if(cnt[i] > 1) return puts("No"), 0; for(int i = 0; i <= n; i++) if(f[i]) for(int j = 1; i + 2 * j <= n; j++) f[i + 2 * j] |= valid(i + 1, j); puts(f[n] ? "Yes" : "No"); fprintf(stderr, "time=%.4f\n", (db)clock()/CLOCKS_PER_SEC); return 0; }
#include<bits/stdc++.h> #define int long long #define all(x) begin(x), end(x) #define SZ(x) ((int)(x).size()) #define EB emplace_back #define PB push_back #define PP pop_back #define MP make_pair #define F first #define S second #define de(x) if(x && x == MODE) #define MODE 0 using namespace std; typedef pair<int, int> pii; const int INF = 1e18; const int maxn = 1e5 + 7; vector<int> G[maxn]; int A[maxn], B[maxn]; int C[maxn]; int target[maxn] = {}; bool v[maxn] = {}; int d[20][20] = {}; int dp[1<<20][20] = {}; int32_t main() { int i,j; int N, M; cin >> N >> M; for (int i=1; i<=M; i++) scanf("%lld %lld", &A[i], &B[i]); for (int i=1; i<=M; i++) { G[A[i]].PB(B[i]); G[B[i]].PB(A[i]); } int K; cin >> K; memset(target, -1, sizeof(target)); for (int i=0; i<K; i++) { scanf("%lld", &C[i]); target[C[i]] = i; } for (int i=0; i<K; i++) { memset(v, 0, sizeof(v)); queue<int> que; que.push(C[i]); v[C[i]] = 1; int step = 1; while (!que.empty()) { int goal = que.size(); while (goal--) { int x = que.front(); que.pop(); for (auto y : G[x]) { if (v[y]) continue; v[y] = 1; que.push(y); if (target[y] != -1) { d[i][target[y]] = step; } } } step++; } } de(1) { for (int i=0; i<K; i++) { for (int j=0; j<K; j++) { printf("d(%lld, %lld) = %lld\n", i, j, d[i][j]); } } } for (int i=0; i<(1<<K); i++) { for (int j=0; j<K; j++) dp[i][j] = INF; } for (int i=0; i<K; i++) dp[1<<i][i] = 1; for (int i=0; i<(1<<K); i++) { for (int j=0; j<K; j++) { if (i&(1<<j)) { for (int k=0; k<K; k++) { if (j == k || !d[j][k]) continue; dp[i][j] = min(dp[i][j], dp[i^(1<<j)][k] + d[k][j]); de(1) printf("dp[%lld][%lld] = %lld\n", i, j, dp[i][j]); } } } } int ans = INF; for (int i=0; i<K; i++) ans = min(ans, dp[(1<<K)-1][i]); if (ans == INF) printf("-1\n"); else printf("%lld\n", ans); return 0; } // // ___ ___ __________ __________ // /////\ \/\ ______\/\\\\\\\\\\\ Code by ~Ice Tea~ of // //// \ \ \ \ \_____/\ \\\\_____/ New Empire of CHSH ... // //// \ \ \ \ \ \ \\\\\\\\\\\ // ////__ \ \ \ \ \ \ \\\\_____/ // ///////\ \ \ \ \ \______\ \\\\_______ ________ // ////____/ \ \__\ \___ ___\ \\\\\\\\\\\ _\ ___ \_ // /__/ \/__/\/__/\ \__/\ \\\\_____//\ .\_/\_ \ // \ \ \ \ \\\\\\\\\\\\ \_\/_\ \ // ... with the AC Power of \ \ \ \ \\\\_____/ \ _____ \ // The Great Tsundere Doggy. \ \ \ \ \\\\ \ \ \ \ \ \ // \ \__\ \ \\\\\\\\\\ \__\ \ \__\ // \/__/ \/________/\/__/ \/__/ //
/* Another source code by: _ _ _ _ _ _____ _ | \ | (_) | (_) / ____| | | | \| |_| |_ _ _ __ | | __ _ __ | |_ | . ` | | __| | '_ \| | |_ | '_ \| __| | |\ | | |_| | | | | |__| | |_) | |_ |_| \_|_|\__|_|_| |_|\_____| .__/ \__| | | |_| */ #include<bits/stdc++.h> #include <vector> using namespace std; #define vi vector<int> #define pb push_back #define p push #define sll stack<long long> #define qll queue<long long> #define vll vector<long long> #define st string #define vvll vector<vll> #define vstr vector <string> #define vp vector <pair<ll,ll>> #define fori(n) for(ll i=0;i<n;i++) #define forj(n) for(int j=0;j<n;j++) #define fork(n) for(int k=0;k<n;k++) #define fori1(n) for(int i=1;i<n;i++) #define f(i,a,b) for(int i=a;i<=b;i++) #define s(v) sort(v.begin(),v.end()) #define sr(v) sort(v.rbegin(),v.rend()) #define ll long long #define MOD 1000000007 #define pi 3.14159265358979323 #include <math.h> #define yn(n) if(n)cout<<"yes\n";else cout<<"no\n"; #define Yn(n) if(n)cout<<"Yes\n";else cout<<"No\n"; #define YN(n) if(n)cout<<"YES\n";else cout<<"NO\n"; #define mp make_pair #define ff first #define ss second ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);} ll lcm(ll a, ll b){return a*b/gcd(a, b);} ll modify(ll n){ll res = n;res%=MOD;res+=MOD;res%=MOD;return res;} ll md(ll n){if(n>0)return n;else return -n;} ll mv(vll v){ll m=v[0];fori(v.size()){m=max(v[i],m);}return m;} vll read(ll n){vll v(n);fori(n)cin>>v[i];return v;} void out(vll v){fori(v.size()){cout<<v[i]<<" ";}cout<<"\n";} void solve(){ ll n,m,k,x; cin>>n>>m>>k; cout<<21-n-k-m; } int main(){ #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif int t; t=1; //cin >> t; while(t--){ solve(); } cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; }
/* code by:- __ | \ _______ ______ ______ ____ ______ ____ __ __ __ ______ \▓▓_______ / \| \| \ \| \ \| \ | \ | \| \| \ \ | ▓▓▓▓▓▓▓ \▓▓▓▓▓▓\ ▓▓▓▓▓▓\▓▓▓▓\ ▓▓▓▓▓▓\▓▓▓▓\ ▓▓ | ▓▓ \▓▓ \▓▓▓▓▓▓\ ▓▓ ▓▓▓▓▓▓▓\ \▓▓ \ / ▓▓ ▓▓ | ▓▓ | ▓▓ ▓▓ | ▓▓ | ▓▓ ▓▓ | ▓▓ | \/ ▓▓ ▓▓ ▓▓ | ▓▓ _\▓▓▓▓▓▓\ ▓▓▓▓▓▓▓ ▓▓ | ▓▓ | ▓▓ ▓▓ | ▓▓ | ▓▓ ▓▓__/ ▓▓ | ▓▓ ▓▓▓▓▓▓▓ ▓▓ ▓▓ | ▓▓ | ▓▓\▓▓ ▓▓ ▓▓ | ▓▓ | ▓▓ ▓▓ | ▓▓ | ▓▓\▓▓ ▓▓ | ▓▓\▓▓ ▓▓ ▓▓ ▓▓ | ▓▓ \▓▓▓▓▓▓▓ \▓▓▓▓▓▓▓\▓▓ \▓▓ \▓▓\▓▓ \▓▓ \▓▓_\▓▓▓▓▓▓▓ __ | ▓▓ \▓▓▓▓▓▓▓\▓▓\▓▓ \▓▓ | \__| ▓▓ | \__/ ▓▓ \▓▓ ▓▓ \▓▓ ▓▓ \▓▓▓▓▓▓ \▓▓▓▓▓▓ */ #include <bits/stdc++.h> using namespace std; #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define rep(i, x, y) for (__typeof(x) i = x; i < y; i++) #define repr(i, x, y) for (__typeof(x) i = x; i > y; i --) #define all(x) (x).begin(),(x).end() // #define Sort(x) sort(all((x))) // #define rSort(x) sort((x).rbegin(),(x).rend()) // #define X first // #define Y second #define sep ' ' #define SZ(x) ll(x.size()) #define MAX(a,b) ((a)>(b)?(a):(b)) #define MIN(a,b) ((a)<(b)?(a):(b)) #define pb push_back #define pf push_front #define mp make_pair typedef long long ll; typedef long double ld; typedef pair<ll, ll> pll; typedef pair<double, double> pdd; typedef vector<ll> vll; #define first X #define second Y const ll N = 1e17 + 10; const ll M = 1e9 + 7; void solve() { ll n,x; cin>>n>>x; ll a[n]; vector<ll>v; rep(i,0,n) { cin>>a[i]; if(a[i]!=x) { v.pb(a[i]); } } rep(i,0,SZ(v)) { cout<<v[i]<<sep; } } int main() { int t=1; while(t--) { solve(); } // solve(); }
//インクルードなど #include <iostream> // cout, endl, cin #include <string> // string, to_string, stoi #include <vector> // vector #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <utility> // pair, make_pair #include <tuple> // tuple, make_tuple #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include <map> // map #include <queue> // queue, priority_queue #include <set> // set #include <stack> // stack #include <deque> // deque #include <unordered_map> // unordered_map #include <unordered_set> // unordered_set #include <bitset> // bitset #include <cctype> // isupper, islower, isdigit, toupper, tolower #include <iomanip> using namespace std; typedef long long ll; //イテレーション #define REP(i,n) for(ll i=0;i<ll(n);i++) #define REPD(i,n) for(ll i=n-1;i>=0;i--) #define FOR(i,a,b) for(ll i=a;i<=ll(b);i++) #define FORD(i,a,b) for(ll i=a;i>=ll(b);i--) #define FORA(i,I) for(const auto& i:I) //x:コンテナ #define ALL(x) x.begin(),x.end() #define SIZE(x) ll(x.size()) //定数 #define INF32 2147483647 //2.147483647×10^{9}:32bit整数のinf #define INF64 9223372036854775807 //9.223372036854775807×10^{18}:64bit整数のinf #define MOD 1000000007 //問題による //略記 #define F first #define S second //出力(空白区切りで昇順に) #define coutALL(x) for(auto i=x.begin();i!=--x.end();i++)cout<<*i<<" ";cout<<*--x.end()<<endl; #define coutall(x) {for(int i=0;i<sizeof(x)/sizeof(x[0]);i++){cout<<x[i]<<"|";};};cout<<endl; //aをbで割る時の繰上げ,繰り下げ ll myceil(ll a,ll b){return (a+(b-1))/b;} ll myfloor(ll a,ll b){return a/b;} signed main(){ ll n;cin>>n; vector<ll> a(n); REP(i,n){cin>>a[i];}; sort(ALL(a)); bool ok=true; REP(i,n){if(a[i]!=i+1){ok=false;};}; cout<<(ok?"Yes":"No"); }
#include <bits/stdc++.h> #include <cmath> using namespace std; #define int long long #define pb push_back #define mkp make_pair #define ms(a) memset(a, 0, sizeof(a)); #define all(a) a.begin(), a.end() #define endl '\n' #define boost \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define mod 1000000007 #define inf 1e18 #define deb(x) cout << #x << " " << x << endl; #define deb2(x, y) cout << #x << " " << x << " " << #y << " " << y << endl; #define deb3(x, y, z) cout << #x << " " << x << " " << #y << " " << y << " " << #z << " " << z << endl; void solve() { int x; cin >> x; cout << 100 - (x % 100); } signed main() { //boost //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); int t = 1; // cin >> t; while (t--) solve(); return 0; }
// ********************************************************************************* // * MURTAZA MUSTAFA KHUMUSI * // * NIT-DGP,CSE - 2019-2023 * // ********************************************************************************* #include <bits/stdc++.h> using namespace std; typedef long long ll; #define MOD 1000000007; #define loop(i, a, n) for (int i = a; i < n; i++) #define loop1(i, b, n) for (int i = b; i <= n; i++) #define loopit(a) for (auto it = a.begin(); it != a.end(); it++) #define ms(a, b) memset(a, b, sizeof(a)) #define pb(a) push_back(a) #define MP make_pair #define pi pair<int, int> #define ff first #define ss second #define bloop(i, a, b) for (int i = a; i > b; i--) #define bloop1(i, a, b) for (int i = a; i >= b; i--) #define PQ priority_queue<int> pq; #define vi vector<int> #define si set<int> #define MPQ priority_queue<pi, vector<int>, greater<pi>> mpq; #define io \ ios_base::sync_with_stdio(0); \ cin.tie(NULL); const int maxm = 300005; // ll m = 1e9 + 7; ll m = 998244353; vector<vi> adj; vi h; vi sz; vi in; ll add(ll a, ll b, ll mod = m) { return ((a % mod) + (b % mod)) % mod; } ll mul(ll a, ll b, ll mod = m) { return ((a % mod) * (b % mod)) % mod; } ll sub(ll a, ll b, ll mod = m) { return ((a % mod) - (b % mod) + mod) % mod; } ll modmul(ll a, ll b, ll mod = m) { ll ans = 0; a = a % mod; while (b) { if (b & 1) ans = add(ans, a, mod); a = mul(a, 2, mod); b >>= 1; } return ans; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll fe(ll base, ll exp, ll mod = m) { ll ans = 1; while (exp) { if (exp & 1) ans = mul(ans, base, mod); base = mul(base, base, mod); exp >>= 1; } return ans; } void dfs_h_sz(int cur, int par) { h[cur] = h[par] + 1; sz[cur]++; for (const auto &v : adj[cur]) { if (v == par) continue; dfs_h_sz(v, cur); sz[cur] += sz[v]; } } void buildGraph(int n, int m) { adj = vector<vi>(n + 1); h = vector<int>(n + 1); sz = vector<int>(n + 1); in = vector<int>(n + 1); loop(i, 0, m) { int a, b; cin >> a >> b; adj[a].pb(b); adj[b].pb(a); } dfs_h_sz(1, 0); } struct cmp { bool operator()(const pi &a, const pi &b) { return a.ff < b.ff; } }; ll modin(ll a) { return fe(a, m - 2); } ll sum(ll a) { return mul(mul(a, a + 1), modin(2)); } void solve() { int n,k; ll sum = 0; cin>>n>>k; int a = abs(k); int arr[maxm] ={0}; // int arr[maxm] = {0}; loop1(i,1,2*n){ if(i<=n) arr[i] = i-1; else arr[i] = 2*n-i+1; } loop1(i,2,2*n){ if(2<=i+k && i+k<=2*n) sum += 1LL*arr[i]*arr[i+k]; } cout<<sum<<"\n"; } int main() { io; // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int test; // cin >> test; test = 1; while (test--) { solve(); } return 0; }
#include<bits/stdc++.h> #define HohleFeuerwerke using namespace std #pragma GCC optimize(3,"Ofast","-funroll-loops","-fdelete-null-pointer-checks") #pragma GCC target("ssse3","sse3","sse2","sse","avx2","avx") #define int long long HohleFeuerwerke; inline int read(){ int s=0,f=1;char c=getchar(); for(;!isdigit(c);c=getchar()) if(c=='-') f=-1; for(;isdigit(c);c=getchar()) s=s*10+c-'0'; return s*f; } inline void write(int x){ if(x<0) putchar('-'),x=-x; if(x>=10) write(x/10); putchar('0'+x%10); } int n,k,ans; inline int calc(int x,int n){ if(x<=n+1&&x>=2) return x-1; else return 2*n-x+1; } signed main() { int T=1; while(T--){ n=read(),k=read(),ans=0; if(k<0) k=-k; for(int s=2;s<=2*n-k;s++) ans+=calc(s,n)*calc(s+k,n)/*,cout<<s<<" "<<s+k<<" "<<calc(s,n)<<" "<<calc(s+k,n)<<endl*/; write(ans);puts(""); } }
#include<iostream> using namespace std; template<long long Mod>struct modInt { long long x; constexpr modInt()noexcept:x(){} template<typename T> constexpr modInt(T v=0)noexcept:x(v%Mod){if(x<0)x+=Mod;} constexpr long long getval()const noexcept{return x;} constexpr modInt operator-()const noexcept{return x?Mod-x:0;} constexpr modInt operator+(const modInt&r)const noexcept{return modInt(*this)+=r;} constexpr modInt operator-(const modInt&r)const noexcept{return modInt(*this)-=r;} constexpr modInt operator*(const modInt&r)const noexcept{return modInt(*this)*=r;} constexpr modInt operator/(const modInt&r)const noexcept{return modInt(*this)/=r;} constexpr modInt&operator+=(const modInt&r)noexcept{x+=r.x;if(x>=Mod)x-=Mod;return*this;} constexpr modInt&operator-=(const modInt&r)noexcept{x-=r.x;if(x<0)x+=Mod;return*this;} constexpr modInt&operator*=(const modInt&r)noexcept{x=x*r.x%Mod;return*this;} constexpr modInt&operator/=(const modInt&r)noexcept{x=x*r.inv();return*this;} constexpr modInt powm(long long n)noexcept { if(n<0)return powm(-n).inv(); modInt x=*this,r=1; for(;n;x*=x,n>>=1)if(n&1)r*=x; return r; } constexpr modInt inv()const noexcept { long long a=x,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 modInt(u); } constexpr bool operator==(const modInt&r){return this->x==r.x;} constexpr bool operator!=(const modInt&r){return this->x!=r.x;} friend ostream&operator<<(ostream&os,const modInt<Mod>&a){return os<<a.x;} friend istream&operator>>(istream&is,modInt<Mod>&a){long long v;is>>v;a=modInt<Mod>(v);return is;} }; const long long mod=1000000007; using mint=modInt<mod>; main() { int n;mint p;cin>>n>>p; cout<<(p-1)*(p-2).powm(n-1)<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define PI 3.14159265 #define double long double #define DB #ifdef DB #define el cerr << "\n"; #define db(...) cerr << " [" << #__VA_ARGS__ << " : " << __VA_ARGS__ << "] "; #else #define el #define db(...) #endif // DB #define ll long long int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); int L, R; cin >> L >> R; vector<ll> dp(R + 1); ll res = 0; int x; for (int i = R; i >= 2; --i) { // db(i); x = (R / i) - ((L - 1) / i); dp[i] = 1LL * x * x; // db(dp[i]); for (int j = i + i; j <= R; j += i) { dp[i] -= dp[j]; // db(j) db(dp[j]) db(dp[i]); } res += dp[i]; // db(i) db(dp[i]) db(x) db(res) el; } for (int i = max(2, L); i <= R; ++i) { x = (R / i) - ((L - 1) / i); res -= x * 2 - 1; } cout << res; return 0; }
#include <bits/stdc++.h> #define int long long #define double long double using namespace std; const int MOD = 1000000007; using Graph = vector<vector<int>>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) signed main(){ int N, M; cin >> N >> M; vector<int> A(N); rep(i, N) cin >> A[i]; vector<int> fg(N+1, -1); rep(i, M) fg[A[i]] = i; //現時点での最小 priority_queue<int, vector<int>, greater<int>> pq; rep(i, N+1){ if( fg[i] == -1 ) pq.push(i); } int ans = pq.top(); for( int i = M; i < N; i++ ){ fg[A[i]] = i; if( pq.top() == A[i] ) pq.pop(); if( fg[A[i-M]] == i-M ) pq.push(A[i-M]); ans = min(ans, pq.top()); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; const int L = 1.5 * 1e6 + 2; int n, m, a[L], pos[L], dis[L]; bool vis[L]; int main() { scanf("%d %d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); a[i]++, vis[a[i]] = true; dis[a[i]] = max(dis[a[i]], i-pos[a[i]]); pos[a[i]] = i; } for (int i = 1; i < L; i++) { dis[i] = max(dis[i], n-pos[a[i]]+1); if (dis[i] > m || !vis[i]) { printf("%d", i-1); return 0; } } printf("%d", L-1); return 0; }
/* Author : MatsuTaku Date : 06/13/21 Certificate: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDF9T447OEo8XSQ6O1AznN5tKC8mzvYc4Zs3+oOKfMqgLXfOwQnpfcoxKs4MAP1eICBD13PkcIezJ9IlV6nKQZKs1BQmvjSXJ+zKK8YCKvAueNPuNO0Bim43IBaNHNFWcMvcmUvHgRb6hUSO0V8I7OsjiFo20KDBj3gAznu9tir0Q== CompetitiveProgrammingCertification:[email protected] */ #include <bits/stdc++.h> using namespace std; #include <x86intrin.h> #define REP(i, l, r) for (int i = (l), i##_less = (r); i < i##_less; i++) #define rep(i, n) REP(i, 0, n) #define RREP(i, l, r) for (int i = (r)-1, i##_least = (l); i >= i##_least; i--) #define rrep(i, n) RREP(i, 0, n) #define chmax(dst, x) dst = max(dst, (x)) #define chmin(dst, x) dst = min(dst, (x)) using lint = long long int; using ulint = unsigned long long int; template<typename T> using vvec = vector<vector<T>>; template<typename T> vvec<T> make_vvec(int n, int m, T v) { return vvec<T>(n, vector<T>(m, v)); } class Solver { public: Solver(); void solve(); }; Solver::Solver() {} void Solver::solve() { int a,b; cin>>a>>b; cout << (double)a/100*b << endl; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(10); Solver solver; int t = 1; // cin>>t; while (t--) { solver.solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; using lli = long long int; #define ip(a) lli a; cin >> a #define ipfl(a) double a; cin >> a #define ipstr(a) string a; cin >> a #define op(a) cout << a #define opspc(a) cout << a << "\n" #define FOR0(i, n) for(lli i = 0; i < n; i++) #define FORa(i, a, n) for(lli i = a; i <= n; i++) #define pb push_back #define mem(a, b) memset(a, b, sizeof(a)) #define all(arr) arr.begin(), arr.end() #define vi vector<lli> #define pwr(a, b) (lli)(pow(a*1.0, b*1.0)) vi primearr(0); lli fact(lli n); bool sortbysec(const pair<int,int> &a, const pair<int,int> &b) { return (a.second < b.second); } void genPrime(lli n) { bool prime[n + 1]; memset(prime, true, sizeof(prime)); for (lli p = 2; p * p <= n; p++) { if (prime[p] == true) { for (lli i = p * p; i <= n; i += p) { prime[i] = false; } } } for (lli p = 2; p <= n; p++) { if (prime[p]) { primearr.pb(p); } } } lli lcm(lli a, lli b) { return a * b / __gcd(a, b); } lli nCr(lli n, lli r) { return fact(n) / (fact(r) * fact(n - r)); } // Returns factorial of n lli fact(lli n) { lli res = 1; for (lli i = 2; i <= n; i++) res = res * i; return res; } void solve() { ip(n); string st[n]; int v[n]; int maxe = INT_MIN; int cnt = 0; for (int i = 0; i < n; ++i) { cin >> st[i]; cin >> v[i]; } if(n == 2) { if(v[0] < v[1]) { cout << st[0] << "\n"; return; } else { cout << st[1] << "\n"; return; } } // for (int i = 0; i < n; ++i) // { // cout << st[i] << " " << v[i] << "\n"; // } for (int i = 0; i < n; ++i) { cnt = 0; for(int j = 0; j < n; j++) { if(v[i] >= v[j]) { cnt++; } } if(cnt == n - 1) { cout << st[i] << "\n"; return; } } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // lli t; // cin >> t; // while(t--) // { solve(); // } }
#include <bits/stdc++.h> #define clr(x) memset(x,0,sizeof(x)) #define For(i,a,b) for (int i=(a);i<=(b);i++) #define Fod(i,b,a) for (int i=(b);i>=(a);i--) #define fi first #define se second #define kill _z_kill #define y0 _z_y0 #define y1 _z_y1 #define x0 _z_x0 #define x1 _z_x1 #define pb(x) push_back(x) #define mp(x,y) make_pair(x,y) using namespace std; typedef long long LL; typedef unsigned long long ull; typedef unsigned uint; typedef long double LD; typedef vector <int> vi; typedef pair <int,int> pii; void enable_comma(){} string tostring(char c){ string s=""; s+=c; return s; } string tostring(string s){ return "\""+s+"\""; } string tostring(const char *c){ return tostring((string)c); } string tostring(long long x){ if (x<0) return "-"+tostring(-x); if (x>9) return tostring(x/10)+tostring(char('0'+x%10)); else return tostring(char('0'+x)); } string tostring(int x){ return tostring((long long)x); } string tostring(unsigned long long x){ if (x>9) return tostring((long long)(x/10))+tostring(char('0'+x%10)); else return tostring(char('0'+x)); } string tostring(unsigned x){ return tostring((long long)x); } string tostring(double x){ static char res[114]; sprintf(res,"%lf",x); string s=tostring(res); return s.substr(1,(int)s.size()-2); } string tostring(long double x){ return tostring((double)x); } template <class A,class B> string tostring(pair <A,B> p){ return "("+tostring(p.fi)+","+tostring(p.se)+")"; } template <class T> string tostring(T v){ string res=""; for (auto p : v) res+=(res.size()?",":"{")+tostring(p); return res.size()?res+"}":"{}"; } template <class A> string tostring(A* a,int L,int R){ return tostring(vector <A>(a+L,a+R+1)); }; string tostrings(){ return ""; } template <typename Head,typename... Tail> string tostrings(Head H,Tail... T){ return tostring(H)+" "+tostrings(T...); } #define User_Time ((double)clock()/CLOCKS_PER_SEC) #ifdef zzd #define outval(x) cerr<<#x" = "<<tostring(x)<<endl #define outvals(...) cerr<<"["<<#__VA_ARGS__<<"]: "<<\ tostrings(__VA_ARGS__)<<endl #define outtag(x) cerr<<"--------------"#x"---------------"<<endl #define outsign(x) cerr<<"<"#x">"<<endl #define outarr(a,L,R) cerr<<#a"["<<(L)<<".."<<(R)<<"] = "<<\ tostring(a,L,R)<<endl #else #define outval(x) enable_comma() #define outvals(...) enable_comma() #define outtag(x) enable_comma() #define outsign(x) enable_comma() #define outarr(a,L,R) enable_comma() #endif #ifdef ONLINE_JUDGE #ifdef assert #undef assert #endif #define assert(x) (!(x)?\ cout<<"Assertion failed!"<<endl<<\ "function: "<<__FUNCTION__<<endl<<\ "line: "<<__LINE__<<endl<<\ "expression: "<<#x<<endl,exit(3),0:1) #endif LL read(){ LL x=0,f=0; char ch=getchar(); while (!isdigit(ch)) f=ch=='-',ch=getchar(); while (isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar(); return f?-x:x; } template <class T> void ckmax(T &x,const T y){ if (x<y) x=y; } template <class T> void ckmin(T &x,const T y){ if (x>y) x=y; } //int Pow(int x,int y){ // int ans=1; // for (;y;y>>=1,x=(LL)x*x%mod) // if (y&1) // ans=(LL)ans*x%mod; // return ans; //} //void Add(int &x,int y){ // if ((x+=y)>=mod) // x-=mod; //} //void Del(int &x,int y){ // if ((x-=y)<0) // x+=mod; //} //int Add(int x){ // return x>=mod?x-mod:x; //} //int Del(int x){ // return x<0?x+mod:x; //} //int md(LL x){ // return (x%mod+mod)%mod; //} int main(){ int n=read(); string s; cin>>s; int ans=0; For(i,0,n-1){ int c0=0,c1=0; For(j,i,n-1){ if (s[j]=='A') c0--; else if (s[j]=='T') c0++; else if (s[j]=='G') c1--; else if (s[j]=='C') c1++; if (!c0&&!c1) ans++; } } cout<<ans<<endl; return 0; }
// Problem: B - DNA Sequence // Contest: AtCoder - AtCoder Regular Contest 104 // URL: https://atcoder.jp/contests/arc104/tasks/arc104_b // Memory Limit: 1024 MB // Time Limit: 2000 ms // // Powered by CP Editor (https://cpeditor.org) #include<iostream> #define t(x) (tot[j][(x)]-tot[i-1][(x)]) using namespace std; int main(){ int n; cin>>n; string s; cin>>s; s=" "+s; int tot[n+1][200]; for(int i=0;i<=200;++i) tot[0][i]=0; for(int i=1;i<=n;++i){ for(int j=0;j<=200;++j) tot[i][j]=tot[i-1][j]; ++tot[i][s[i]]; } int tt=0; for(int i=1;i<=n;++i) for(int j=i+1;j<=n;++j) if(t('A')==t('T')&&t('C')==t('G')) ++tt; cout<<tt; }
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; char win(char a, char b) { if (a == b) return a; if ((a ^ b) == ('R' ^ 'S')) return 'R'; if ((a ^ b) == ('R' ^ 'P')) return 'P'; return 'S'; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; string s; cin >> s; vector<char> v; for (int i = 0; i < n; i++) { v.push_back(s[i]); } for (int i = 0; i < k; i++) { vector<char> u; if (v.size() % 2 == 0) { for (int j = 0; j < v.size(); j += 2) { u.push_back(win(v[j], v[j + 1])); } } else { for (int j = 0; j < 2*v.size(); j += 2) { u.push_back(win(v[j%v.size()], v[(j + 1)%v.size()])); } } v = u; } cout << v[0] << endl; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const ll maxn=2e5+10; const ll m1=1e18+7; const ll mod=1e18+7; const ll INF64 = ll(1e18); #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") ll t[4*maxn]; void build(ll a[], ll v, ll tl, ll tr) { if (tl == tr) { t[v] = a[tl]; } else { ll tm = (tl + tr) / 2; build(a, v*2, tl, tm); build(a, v*2+1, tm+1, tr); t[v] = t[v*2] + t[v*2+1]; } } ll sum(ll v, ll tl, ll tr, ll l, ll r) { if (l > r) return 0; if (l == tl && r == tr) { return t[v]; } ll tm = (tl + tr) / 2; return sum(v*2, tl, tm, l, min(r, tm)) + sum(v*2+1, tm+1, tr, max(l, tm+1), r); } void update(ll v, ll tl, ll tr, ll pos, ll new_val) { if (tl == tr) { t[v] = new_val; } else { ll tm = (tl + tr) / 2; if (pos <= tm) update(v*2, tl, tm, pos, new_val); else update(v*2+1, tm+1, tr, pos, new_val); t[v] = t[v*2] + t[v*2+1]; } } bool compare(pair<ll,ll> p1,pair<ll,ll> p2) { if(p1.second==p2.second) { return(p1.first<p2.first); } else return(p1.second<p2.second); } int main() { #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); //long long tt = clock(); #endif ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0); //Line Sweep ll n,m,n2,i; cin>>n>>m>>n2; vector<pair<ll,ll>> v; ll x_l=INT_MAX,y_l=INT_MAX; for(i=0;i<n2;++i) { ll x,y; cin>>x>>y; if(x==1) { x_l=min(x_l,y); } if(y==1) { y_l=min(y_l,x); } v.push_back(make_pair(x,y)); } for(i=1;i<=m;++i) { v.push_back(make_pair(0,i)); v.push_back(make_pair(n+1,i)); } if(x_l!=INT_MAX) { for(i=x_l+1;i<=m;++i) { v.push_back(make_pair(1,i)); } } if(y_l!=INT_MAX) { for(i=y_l+1;i<=n;++i) { v.push_back(make_pair(i,1)); } } sort(v.begin(),v.end(),compare); ll active[maxn]; memset(active,0,sizeof(active)); build(active,1,0,maxn-1); ll ans=0; /*for(i=0;i<v.size();++i) { cout<<v[i].first<<" "<<v[i].second<<"\n"; }*/ for(i=0;i<v.size()-1;++i) { active[v[i].first]=1; update(1,0,maxn-1,v[i].first,1); if(v[i].second!=v[i+1].second) { continue; } if(v[i].first==v[i+1].first) continue; ll diff=v[i+1].first-v[i].first-1; if(v[i].first==0) { ans+=diff; } else { ans+=diff-(v[i].first+1<=v[i+1].first-1?sum(1,0,maxn-1,v[i].first+1,v[i+1].first-1):0); } } cout<<ans; return(0); }
#include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <string> #include <queue> #include <stack> #include <set> #include <map> #include <iomanip> #include <utility> #include <tuple> #include <functional> #include <bitset> #include <cassert> #include <complex> #include <stdio.h> #include <time.h> #include <numeric> #include <random> #include <unordered_map> #include <unordered_set> #define all(a) a.begin(),a.end() #define rep(i, n) for (ll i = 0; i < (n); i++) #define pb push_back #define debug(x) cerr << __LINE__ << ' ' << #x << ':' << (x) << '\n' #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; typedef long double ld; typedef pair<ll, ll> P; typedef complex<ld> com; template<class T> using prique = priority_queue<T, vector<T>, greater<T>>; constexpr int inf = 1000000010; constexpr ll INF = 1000000000000000010; constexpr int mod1e9 = 1000000007; constexpr int mod998 = 998244353; constexpr ld eps = 1e-12; constexpr ld pi = 3.141592653589793238; constexpr ll ten(int n) { return n ? 10 * ten(n - 1) : 1; }; int dx[] = { 1,0,-1,0,1,1,-1,-1 }; int dy[] = { 0,1,0,-1,1,-1,1,-1 }; void fail() { cout << "-1\n"; exit(0); } void no() { cout << "No\n"; exit(0); } template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; } template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; } template<class T> istream &operator >> (istream &s, vector<T> &v) { for (auto &e : v) s >> e; return s; } template<class T> ostream &operator << (ostream &s, const vector<T> &v) { for (auto &e : v) s << e << ' '; return s; } struct fastio { fastio() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); cerr << fixed << setprecision(20); } }fastio_; int main() { ll n, t; cin >> n >> t; vector<ll> a(n); cin >> a; int m = n / 2; vector<ll> x(1 << m); vector<ll> y(1 << (n - m)); rep(i, 1 << m) { rep(j, m) { if (i >> j & 1) { x[i] += a[j]; } } } rep(i, 1 << (n - m)) { rep(j, n - m) { if (i >> j & 1) { y[i] += a[j + m]; } } } y.pb(-INF); sort(all(x)); sort(all(y)); ll ans = 0; for (ll v : x) { ll rem = t - v; auto itr = upper_bound(all(y), rem); itr--; ll s = v + (*itr); chmax(ans, s); } cout << ans << '\n'; }
#include <bits/stdc++.h> using namespace std; #define int long long template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } int n, t; int a[100]; set<int> zen, kou; void dfs(int i, int ma, int now, int b){ if(i >= ma){ if(b == 0){ zen.insert(now); }else{ kou.insert(now); } return; } dfs(i+1, ma, now, b); dfs(i+1, ma, now+a[i], b); } signed main(){ cin >> n >> t; for(int i = 0;i < n;i++){ cin >> a[i]; } dfs(0, n/2, 0, 0); dfs(n/2, n, 0, 1); int ans = 0; for(auto e = zen.begin(); e != zen.end();e++){ int x = *e; if(x > t) continue; auto hoge = kou.upper_bound(t-x); hoge--; ans = max(ans, x+*hoge); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll lim = 1000000000000000000ll; vector <ll> seq; const int Maxn = 90; bool op[Maxn]; vector <int> res; int main() { seq.push_back(1); seq.push_back(1); while (seq.back() <= lim) { ll nw = seq.back() + seq[int(seq.size()) - 2]; seq.push_back(nw); } ll n; scanf("%lld", &n); while (n > 0) { int ind = upper_bound(seq.begin(), seq.end(), n) - seq.begin() - 1; n -= seq[ind]; op[Maxn - 1 - ind] = true; } int p = 0; while (!op[p]) p++; while (p < Maxn) { if (p % 2 == 0) { res.push_back(4); if (op[p]) res.push_back(2); } else { res.push_back(3); if (op[p]) res.push_back(1); } p++; } printf("%d\n", int(res.size())); for (int i = 0; i < res.size(); i++) printf("%d\n", res[i]); return 0; }
#include <iostream> #include <cassert> #include <vector> #include <algorithm> using namespace std; int main(){ long long n; cin >> n; long long x = 0, y = 0; vector<int> Q; auto q = [&](int i){ if(i == 0){ x += 1; } if(i == 1){ y += 1; } if(i == 2){ x += y; } if(i == 3){ y += x; } Q.emplace_back(i); }; vector<long long> F(2,0); F[1] = 1; for(int i = 2; i < 130; ++i){ long long t = F[i-1] + F[i-2]; if(t > n) break; F.emplace_back(t); } vector<int> A; long long n_ = n; for(int i = F.size()-1; i >= 0; --i){ if(F[i] <= n_){ A.emplace_back(i); n_ -= F[i]; } } q(0); int p = 3, j = A[0]-1; for(auto a : A){ if(a == A[0]) continue; while(j > a){ q(p); p ^= 1; --j; } q(p&1); } if(y == n){ swap(x,y); for(auto& q : Q) q ^= 1; } cout << Q.size() << endl; for(auto e : Q){ cout << e+1 << '\n'; } cerr << x << " " << y << endl; assert(x == n); }
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long ll; typedef int Int; typedef pair<Int, Int> pii; typedef pair<Int, double> pid; typedef pair<double, double> pdd; typedef pair<Int, pii> pip; typedef pair<pii, Int> ppi; typedef pair<double, Int> pdp; typedef vector<Int> veci; typedef vector<double> vecd; typedef vector<int> veci; typedef vector<ll> vecll; typedef vector<double> vecd; typedef vector<pii> vecpii; typedef vector<ppi> vecppi; typedef vector<veci> mati; typedef vector<vecll> matll; typedef vector<vecd> matd; #define PB(x) push_back(x) #define EB(x) emplace_back(x) #define ALL(x) x.begin(),x.end() #define SZ(x) (x).size() #define CLR(x) memset(x,0,sizeof x) #define pdebug() printf("%d\n",__LINE__) #define REP(i, a, b) for(int i = (a);i <= (b);i++) #define FORO(i, n) REP(i,0,(int)n-1) #define FORI(i, n) REP(i,1,(int)n) #define FORIT(i, t) for(auto i = t.begin();i != t.end();i++) #define eps 1e-6 #define sqr(x) ((x)*(x)) #define dist(_a, _b) sqrt(sqr(_a.A-_b.A)+sqr(_a.B-_b.B)) #define norm(_a) sqrt(sqr(_a.A)+sqr(_a.B)) #define DEBUG 1 #if DEBUG #define DUMP(a) do { std::cout << #a " = " << (a) << ", "; } while(false) #define DUMPLN(a) do { std::cout << #a " = " << (a) << std::endl; } while(false) #else #define DUMP(a) #define DUMPLN(a) #endif template<typename T, typename U> inline void getMin(T &a, U b) { if (a > b) a = b; } template<typename T, typename U> inline void getMax(T &a, U b) { if (a < b) a = b; } template<typename T> vector<T> getVector(const int n) { return vector<T>(n); } template<typename T> vector<T> getVector(const int n, const T a) { return vector<T>(n, a); } template<typename T> vector<T> getEmptyVector() { return vector<T>(); } template<typename T> void appendAll(vector<T> &a, vector<T> b) { a.insert(a.end(), b.begin(), b.end()); } template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; }; // #define X first // #define Y second const int dx[4] = {1, -1, 0, 0}; const int dy[4] = {0, 0, 1, -1}; const ll MOD = 1000000007; const int MAXN = 1 << 17; const int inf = 1 << 27; const ll llinf = 1LL << 50; const int NIL = -inf; int popcount(int x) { return __builtin_popcount(x); } void solve() { int N, A, B; cin >> N >> A >> B; cout << N - A + B << endl; } int main() { ios::sync_with_stdio(false); cin.tie(0); int tc = 1; // cin >> tc; while(tc--) { solve(); } return 0; }
#include<bits/stdc++.h> using namespace std; using ll = long long int; #define pb push_back #define mp make_pair #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); typedef pair<ll,ll> pii; typedef vector<pii> vii; typedef vector <ll> vi; #define MAX 100003 bool comp(pii a,pii b) { return a.second < b.second; } int main() { // freopen("inputfile.txt","r",stdin);; int x,a,b;cin>>x>>a>>b; cout<<(x-a)+b<<endl; return 0; }
/*Lucky_Glass*/ #include <set> #include <vector> #include <cstdio> #include <cstring> #include <algorithm> typedef long long llong; #define con(typ) const typ & const int N = 1e5 + 10; const llong INF = 0x3f3f3f3f3f3f3f3fll; int n; std::set<llong> exi[3]; std::vector<llong> ele[3]; llong aAbs(con(llong) k) { return k < 0 ? -k : k; } llong nextTo(std::set<llong> &se, con(llong) val) { auto s = se.lower_bound(val); llong ret = INF; if ( s != se.end() ) ret = std::min(ret, aAbs(val - *s));; if ( s != se.begin() ) ret = std::min(ret, aAbs(val - *(--s))); return ret; } int main() { scanf("%d", &n), n *= 2; for ( int i = 1, k; i <= n; ++i ) { char typ[10] = ""; llong val; scanf("%lld%s", &val, typ); if ( typ[0] == 'R' ) k = 0; else if ( typ[0] == 'G' ) k = 1; else k = 2; exi[k].insert(val), ele[k].push_back(val); } int sp[3] = {-1, -1, -1}; for ( int i = 0; i < 3; ++i ) if ( ele[i].size() & 1 ) { if ( ~sp[0] ) sp[1] = i; else sp[0] = i; } else { sp[2] = i; } if ( sp[0] == -1 ) { printf("0\n"); return 0; } llong ans = INF; for ( llong i : ele[sp[0]] ) ans = std::min(ans, nextTo(exi[sp[1]], i)); std::pair<llong, int> mna[2], mnb[2]; mna[0].first = mnb[0].first = mna[1].first = mnb[1].first = INF; for ( int i = 0; i < (int)ele[sp[2]].size(); ++i ) { llong val = nextTo(exi[sp[0]], ele[sp[2]][i]); if ( val < mna[0].first ) mna[1] = mna[0], mna[0] = std::make_pair(val, i); else if ( val < mna[1].first ) mna[1] = std::make_pair(val, i); val = nextTo(exi[sp[1]], ele[sp[2]][i]); if ( val < mnb[0].first ) mnb[1] = mnb[0], mnb[0] = std::make_pair(val, i); else if ( val < mnb[1].first ) mnb[1] = std::make_pair(val, i); } if ( mna[0].second != mnb[0].second ) { ans = std::min(ans, mna[0].first + mnb[0].first); } else { ans = std::min(ans, mna[0].first + mnb[1].first); ans = std::min(ans, mna[1].first + mnb[0].first); } printf("%lld\n", ans); return 0; }
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> #define ll long long #define int ll #define pb push_back #define INF 1e18 #define MOD 1000000007 #define mp make_pair const double PI=3.141592653589793238462643383279502884197169399375105820974944; #define REP(i,n) for (int i = 0; i < n; i++) #define FOR(i,a,b) for (int i = a; i < b; i++) #define REPD(i,n) for (int i = n-1; i >= 0; i--) #define FORD(i,a,b) for (int i = a; i >= b; i--) #define remax(a,b) a = max(a,b) #define remin(a,b) a = min(a,b) #define umap unordered_map #define pii pair<int,int> #define F first #define S second #define mii map<int,int> #define vi vector<int> #define vvi vector<vi> #define itr :: iterator it #define all(v) v.begin(),v.end() #define WL(t) while(t--) #define gcd(a,b) __gcd((a),(b)) #define lcm(a,b) ((a)*(b))/gcd((a),(b)) #define out(x) cout << #x << " is " << x <<"\n" #define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); using namespace std; int util(vi A, vi B) { int a = 0, b = 0; int result = INF; while (a < A.size() && b < B.size()) { if (abs(A[a] - B[b]) < result) result = abs(A[a] - B[b]); if (A[a] < B[b]) a++; else b++; } return result; } void solve() { int n, a; char c; cin>>n; vi r, g, b; REP(i, 2*n) { cin>>a>>c; if(c=='R') { r.pb(a); } else if(c=='G') { g.pb(a); } else { b.pb(a); } } sort(all(r)); sort(all(g)); sort(all(b)); if(r.size()%2==0&&g.size()%2==0&&b.size()%2==0) { cout<<"0"; } else if(r.size()%2==0) { int x=util(r, g); int y=util(r, b); int z=util(g, b); cout<<min(z, x+y); } else if(g.size()%2==0) { int x=util(g, r); int y=util(g, b); int z=util(r, b); cout<<min(z, x+y); } else { int x=util(b, r); int y=util(b, g); int z=util(r, g); cout<<min(z, x+y); } } signed main() { FastIO int t=1; //cin>>t; WL(t){ solve(); if(t!=0) cout<<"\n"; } return 0; }
//https://atcoder.jp/contests/abc182/tasks/abc182_c //C - To 3 #include <bits/stdc++.h> using namespace std; int main() { long long n; cin>>n; //特判 if (0==n%3) { cout<<"0\n"; return 0; } else if (n<=2) { cout<<"-1\n"; return 0; } //转换为数字 int cnt[3]={};//每个数字个数 int tot=0;//每个位数总和 vector<int> v; while (n) { int p=n%10;//取个位 n/=10; tot+=p; v.push_back(p); cnt[p%3]++; } n = v.size(); if (1==tot%3) { if (n>1 && cnt[1]>=1) { cout<<"1\n"; } else if (n>2 && cnt[2]>=2) { cout<<"2\n"; } else { cout<<"-1\n"; } } else if (2==tot%3) { if (n>1 && cnt[2]>=1) { cout<<"1\n"; } else if (n>2 && cnt[1]>=2) { cout<<"2\n"; } else { cout<<"-1\n"; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main () { string s; cin >> s; int right = s.length()-1; while (s[right] == '0') { right--; } for (int left = 0; right >= 0; ++left) { if (s[left] != s[right]) { cout << "No"; return 0; } --right; } cout << "Yes"; return 0; } //je kotinnnnnnnnnnnnnnnn
#include <bits/stdc++.h> using namespace std; int main() { int t; scanf("%d", &t); while (t--) { int l, r; scanf("%d%d", &l, &r); printf("%lld\n", r < l << 1 ? 0 : 1ll * (r - (l << 1) + 1) * (r - (l << 1) + 2) >> 1); } return 0; }
#include <bits/stdc++.h> #define repp(i, l, r) for (long long i = (l); i < (r); i++) #define rep(i, n) for (long long i = 0; i < (n); ++i) #define per(i, n) for (long long i = (n); i >= 0; --i) #define all(v) v.begin(), v.end() const int INF = 1 << 30; const long long LINF = 1LL << 60; const long long int MOD = 1000000007; using namespace std; using ll = long long; using P = pair<int, int>; using PLI = pair<long long, int>; template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } //ミョ(-ω- ?) int main() { cin.tie(nullptr); ios::sync_with_stdio(false); ll n; cin >> n; vector<pair<long double, long double>> a(n); rep(i, n) { cin >> a[i].first >> a[i].second; } for (ll i = 0; i < n; i++) { for (ll j = i + 1; j < n; j++) { for (ll k = j + 1; k < n; k++) { ll x1 = (a[i].first - a[j].first); ll x2 = (a[j].first - a[k].first); ll y1 = (a[i].second - a[j].second); ll y2 = (a[j].second - a[k].second); if(x2 * y1 == x1 * y2){ cout << "Yes\n"; cerr << i << j << k << "\n"; return 0; } } } } cout << "No\n"; return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define mem0(a) memset(a,0,sizeof(a)) #define mem1(a) memset(a,-1,sizeof(a)) #define memf(a) memset(a,false,sizeof(a)) #define all(v) (v).begin(),(v).end() #define lb lower_bound #define ub upper_bound #define pll pair<ll,ll> #define mll map<ll,ll> #define endl "\n" #define pb push_back #define mp make_pair #define F first #define S second #define DEC(x) fixed<<setprecision(x) #define FAST ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL); #define gcd(a,b) __gcd((a),(b)) #define lcm(a,b) ((a)*(b))/__gcd((a),(b)) const int M=1000000007; const int MM=998244353; const long double PI = acos(-1); const long long INF=2e18; template<typename T,typename T1>void amax(T &a,T1 b){if(b>a)a=b;} template<typename T,typename T1>void amin(T &a,T1 b){if(b<a)a=b;} ll power( ll b, ll e) { if(e==0) return 1; if(e&1) return b*power(b*b,e/2); return power(b*b,e/2); } ll power(ll b,ll e,ll m) { if(e==0) return 1; if(e&1) return b*power(b*b%m,e/2,m)%m; return power(b*b%m,e/2,m); } ll modinv(ll a,ll m) { return power(a,m-2,m); } // #define _NCR_ int TLE_TERROR() { ll n,ans=0; cin>>n; ll a[n],b[n]; for(ll i=0;i<n;i++) cin>>a[i]; for(ll i=0;i<n;i++) cin>>b[i]; for(ll i=0;i<n;i++) { ans+=(a[i]*b[i]); } if(ans==0) cout<<"Yes"<<endl; else cout<<"No"<<endl; return 0; } int main() { FAST // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); ll int TESTS=1; // cin>>TESTS; #ifdef _NCR_ initialvalues(); #endif while(TESTS--) TLE_TERROR(); return 0; }
#include <bits/stdc++.h> using namespace std; bool isCollinear(int x1, int y1, int x2,int y2, int x3, int y3) { int result = x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2); return result==0; } int main() { int t; cin>>t; vector<pair<int, int>> points; while(t--) { int a , b; cin>>a>>b; points.push_back({a,b}); } int n = points.size(); bool ok = false; for(int i = 0 ; i < n ; i++) { pair<int, int> p1 = points[i]; for(int j = i+1 ; j < n ; j++) { pair<int, int> p2 = points[j]; for(int k = j+1; k < n ; k++) { pair<int, int> p3 = points[k]; if(isCollinear(p1.first, p1.second, p2.first, p2.second, p3.first, p3.second) == true) { ok =true; break; } } if(ok) break; } if(ok ) break; } if(ok) cout<<"Yes\n"; else cout<<"No\n"; }
#include<bits/stdc++.h> using namespace std; long long int MOD = 1000000007; void mult(vector<vector<long long int>> &a, vector<vector<long long int>> &b, int n) { vector<vector<long long int>> c(n, vector<long long int>(n, 0)); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { for (int k = 0; k < n; k++) { c[i][j] += a[i][k] * b[k][j]; c[i][j] %= MOD; } } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { a[i][j] = c[i][j]; } } } void bin_mat(vector<vector<long long int>> &m, long long int e, int n, vector<vector<long long int>> &temp) { if (e == 0) return; if (e == 1) return; bin_mat(m, e / 2, n, temp); mult(m, m, n); if (e % 2) mult(m, temp, n); } long long int bin_pow(long long int b, long long int e) { if (e == 0) return 1; long long int temp = bin_pow(b, e / 2); temp = temp * temp % MOD; if (e % 2) return temp * b % MOD; return temp; } void solve() { int n,m,k; cin >> n >> m >> k; vector<long long int> num(n); for (int i = 0; i < n; i++) { cin >> num[i]; } vector<vector<int>> graph(n); for (int i = 0; i < m; i++) { int a,b; cin >> a >> b; a--; b--; graph[a].push_back(b); graph[b].push_back(a); } vector<vector<long long int>> mat(n, vector<long long int>(n, 0)); for (int i = 0; i < n; i++) { int cnt = m - graph[i].size(); mat[i][i] += 2 * cnt % MOD; for (auto j: graph[i]) { mat[i][i]++; mat[i][j]++; } } vector<vector<long long int>> temp = mat; bin_mat(mat, k, n, temp); if (k > 0) { vector<long long int> ans(n, 0); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { ans[i] += mat[i][j] * num[j] % MOD; ans[i] %= MOD; } } long long int val = bin_pow(2 * m, k); val = bin_pow(val, MOD - 2); for (int i = 0; i < n; i++) { cout << ans[i] * val % MOD << '\n'; } } else { for (int i = 0; i < n; i++) cout << num[i] % MOD << '\n'; } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> pi; typedef vector <ll> vi; typedef vector <pi> vpi; typedef pair<pi,ll> pii; typedef set <ll> si; typedef long double ld; #define f first #define s second #define FOR(i,s,e) for(ll i=s;i<=ll(e);++i) #define DEC(i,s,e) for(ll i=s;i>=ll(e);--i) #define pb push_back #define all(x) (x).begin(), (x).end() #define lbd(x, y) lower_bound(all(x), y) #define ubd(x, y) upper_bound(all(x), y) #define aFOR(i,x) for (auto i: x) #define mem(x,i) memset(x,i,sizeof x) #define fast ios_base::sync_with_stdio(false),cin.tie(0) #define maxn 101 #define MOD 1000000007 #define int ll int N,M,K,A[maxn]; //~ int dp[maxn][maxn * 10]; //~ vi adj[maxn]; ll qexp(ll x, ll y) { ll res = 1; while (y > 0){ if (y & 1){ res = res*x; res %= MOD; } y = y>>1; x = x*x; x %= MOD; } return res; } int modinv(int A,int B){ A %= MOD; B = qexp(B,MOD-2); A *= B; A %= MOD; return A; } //~ int dpf(int i,int j){ //~ if (j == 0) return A[i]; //~ if (dp[i][j] != -1) return dp[i][j]; //~ dp[i][j] = 0; //~ aFOR(k,adj[i]){ //~ dp[i][j] += modinv((dpf(i,j-1) + dpf(k,j-1)) % MOD, 2); //~ } //~ dp[i][j] += (dpf(i,j-1) * (M - adj[i].size())) % MOD; //~ dp[i][j] = modinv(dp[i][j], M); //~ return dp[i][j]; //~ } struct Matrix{ ll a[101][101]; Matrix(){ FOR(i,1,N) FOR(j,1,N) a[i][j] = 0; } Matrix operator *(Matrix other){ Matrix product = Matrix(); FOR(i,1,N) FOR(j,1,N) FOR(k,1,N){ product.a[i][k] += (a[i][j] * other.a[j][k]) % MOD; product.a[i][k] %= MOD; } return product; } }; Matrix mat_exp(Matrix mat, int k){ Matrix ans = Matrix(); FOR(i,1,N) ans.a[i][i] = 1; while (k > 0){ if (k % 2 == 1){ ans = ans * mat; } mat = mat * mat; k /= 2; } return ans; } int32_t main(){ fast; cin >> N >> M >> K; FOR(i,1,N) cin >> A[i]; Matrix mat = Matrix(); FOR(i,1,M){ int x,y; cin >> x >> y; //~ adj[x].pb(y); adj[y].pb(x); mat.a[x][y] = mat.a[y][x] = 1; mat.a[x][x]++; mat.a[y][y]++; } FOR(i,1,N){ mat.a[i][i] = (2 * M - mat.a[i][i]) % MOD; mat.a[i][i] = (mat.a[i][i] + MOD) % MOD; } Matrix res = mat_exp(mat, K); //~ cout << K << '\n'; //~ FOR(i,1,N){ //~ FOR(j,1,N) cout << res.a[i][j] << ' '; //~ cout << '\n'; //~ } //~ return 0; int k = qexp((2 * M) % MOD, K); FOR(i,1,N){ int ans = 0; FOR(j,1,N){ ans += (res.a[i][j] * A[j]) % MOD; ans %= MOD; } cout << modinv(ans, k) << '\n'; } //~ mem(dp,-1); //~ FOR(i,1,N){ //~ cout << dpf(i,K) << '\n'; //~ } }
#include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; int X, Y, Z; int main(void) { cin >> X >> Y >> Z; int ans = 0; for (int i = 0; i <= 1000000; i++) { if (Y*Z > i*X) { ans = i; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; /* ループ処理 0からnまで*/ #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { double X, Y, Z; cin >> X >> Y >> Z; double a = Y / X; double b = a * Z; cout << int(ceil(b - 1)) << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define BE(x) x.begin(), x.end() int main() { ll s, p; cin >> s >> p; for (ll i = 1; i*i <= p; i++) { if (p % i > 0) continue; ll n = i, m = p / i; if (n + m == s) { cout << "Yes" << endl; return 0; } } cout << "No" << endl; }
#include <bits/stdc++.h> #define ll long long int using namespace std; const int N = 2e5 + 5; int main() { ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); int n; cin >> n; string str; cin >> str; string s = ""; char ch[3] = {'1','1','0'}; if(str.size() ==1) { ll ans = 1e10; if(str[0] == '0') { cout << ans << "\n"; } else cout << 2*ans << "\n"; return 0; } for(int i=0;i<2*n;i++) { s += ch[i%3]; } ll cnt = 0; int j =0; ll add = 0; ll fst = 0; for(int i=0;i<2*n;i++) { //cout << i << " " << j << '\n'; if(str[j] == s[i]) { j++; if(j == n) { fst = i-n+1; cnt = 1; break; } } else { j = 0; if(str[j] == s[i]) j++; } } if(cnt == 0) { cout << 0 << '\n'; } else { ll curr = 0; ll low = 1; ll high = 3e10; ll best = 1; ll lim = 3e10; fst++; //ll v = fst + 3*(1e10 - 1); //v += str.size() - 1; //cout << v << "\n"; while(low <= high) { ll mid = (low + high)/2; ll val = fst + 3*mid; ll r = val + str.size() - 1; if(r > lim) { high = mid-1; } else { best = mid; low = mid+1; } } cout << best+1; } }
#include<bits/stdc++.h> using namespace std; #define int long long const int maxn=2e5+5; struct edge{ int u,to,nxt; }e[2*maxn]; int head[maxn],cnt; int x,y; void add(int x,int y){ e[++cnt].to=y; e[cnt].u=x; e[cnt].nxt=head[x]; head[x]=cnt; } int c[maxn],n,m,p,dep[maxn]; void dfs(int u,int fa){ dep[u]=dep[fa]+1; for(int i=head[u];i;i=e[i].nxt){ int v=e[i].to; if(v==fa)continue; dfs(v,u); } } void dfs2(int u,int fa,int res){ res+=c[u]; c[u]=res; for(int i=head[u];i;i=e[i].nxt){ int v=e[i].to; if(v==fa)continue; dfs2(v,u,res); } } signed main(){ cin>>n; for(int i=1;i<n;i++){ cin>>x>>y; add(x,y); add(y,x); } dfs(1,0); int q; cin>>q; for(int i=1;i<=q;i++){ int t; cin>>t>>x>>y; int u=e[2*x-1].u,v=e[2*x-1].to; if(t==2){ swap(u,v); } // cerr<<u<<' '<<v<<endl; if(dep[u]>dep[v]){ c[u]+=y; } else{ p+=y; c[v]-=y; } } dfs2(1,0,p); for(int i=1;i<=n;i++){ cout<<c[i]<<endl; } }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; // -------------------------------------------------------- template<class T> bool chmax(T& a, const T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> bool chmin(T& a, const T b) { if (b < a) { a = b; return 1; } return 0; } #define FOR(i,l,r) for (ll i = (l); i < (r); ++i) #define RFOR(i,l,r) for (ll i = (r)-1; (l) <= i; --i) #define REP(i,n) FOR(i,0,n) #define RREP(i,n) RFOR(i,0,n) #define ALL(c) (c).begin(), (c).end() #define RALL(c) (c).rbegin(), (c).rend() #define SORT(c) sort(ALL(c)) #define RSORT(c) sort(RALL(c)) #define MIN(c) *min_element(ALL(c)) #define MAX(c) *max_element(ALL(c)) #define SUMLL(c) accumulate(ALL(c), 0LL) #define COUNT(c,v) count(ALL(c),(v)) #define SZ(c) ((ll)(c).size()) #define BIT(b,i) (((b)>>(i)) & 1) #define PCNT(b) __builtin_popcountll(b) #define CLZ(b) __builtin_clzll(b) #define BITLEN(b) (64LL - CLZ(b)) #define CIN(c) cin >> (c) #define COUT(c) cout << (c) << '\n' #define debug(x) cerr << "l." << __LINE__ << " : " << #x << " = " << (x) << '\n' ll llceil(ll a, ll b) { return (a + b - 1) / b; } string toupper(const string& S) { string T(S); REP(i,SZ(T)) T[i] = toupper(T[i]); return T; } string tolower(const string& S) { string T(S); REP(i,SZ(T)) T[i] = tolower(T[i]); return T; } using P = pair<ll,ll>; using VP = vector<P>; using VVP = vector<VP>; using VS = vector<string>; using VVS = vector<VS>; using VLL = vector<ll>; using VVLL = vector<VLL>; using VVVLL = vector<VVLL>; using VB = vector<bool>; using VVB = vector<VB>; using VVVB = vector<VVB>; using VD = vector<double>; using VVD = vector<VD>; using VVVD = vector<VVD>; using VLD = vector<ld>; using VVLD = vector<VLD>; using VVVLD = vector<VVLD>; static const double EPS = 1e-10; static const double PI = acos(-1.0); static const ll MOD = 1000000007; // static const ll MOD = 998244353; static const ll INF = (1LL << 62) - 1; // 4611686018427387904 - 1 // -------------------------------------------------------- // #include <atcoder/all> // using namespace atcoder; int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15); ll N; cin >> N; VLL C(N); REP(i,N) cin >> C[i]; VVLL G(N); REP(_,N-1) { ll A, B; cin >> A >> B; A--; B--; G[A].push_back(B); G[B].push_back(A); } ll L = 1e5; VLL cnt(L+1,0); VLL ans = {1}; auto rec = [&](auto self, ll u, ll p) -> void { if (cnt[C[u]] == 0) ans.push_back(u+1); cnt[C[u]]++; for (ll v : G[u]) if (v != p) { self(self, v, u); } cnt[C[u]]--; }; cnt[C[0]]++; for (ll v : G[0]) { rec(rec, v, 0); } SORT(ans); for (ll a : ans) COUT(a); return 0; }
#include <iostream> #include <algorithm> #include <vector> using namespace std; int main(){ vector<int> a(3); cin >> a[0] >> a[1] >> a[2]; sort(a.begin(), a.end()); if (a[2] - a[1] == a[1] - a[0]) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define endl '\n'; #define mp make_pair #define pii pair<int,int> #define vi vector<int> #define mi 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 all(x) x.begin(), x.end() #define clr(x) memset(x, 0, sizeof(x)) #define sortall(x) sort(all(x)) #define ps(x,y) fixed<<setprecision(y)<<x #define deb(x) cout << #x << "=" << x << endl #define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl #define tr(it, a) for(auto it = a.begin(); it != a.end(); it++) #define fo(i, n) for(int i=0; i<n; i++) 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;} void test_case(int test_num) { vi a(3); fo(i,3) { cin >> a[i]; } sortall(a); if(a[0] - a[1] == a[1] - a[2]) { cout << "Yes" << endl; } else { cout << "No" << endl; } return; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int _; _ = 1; //cin >> _; for(int t = 1; t <= _; t++) { test_case(t); } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) #define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++) #define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--) #define all(a) (a.begin()),(a.end()) #define rall(a) (a.rbegin()),(a.rend()) #define fi first #define se second #define pb push_back #define eb emplace_back using ll = long long; using vll = vector<ll>; using vi = vector<int>; using vvi = vector<vector<int>>; using P = pair<int, int>; /*** mod int ***/ // auto mod int // https://youtu.be/L8grWxBlIZ4?t=9858 // https://youtu.be/ERZuLAxZffQ?t=4807 : optimize // https://youtu.be/8uowVvQ_-Mo?t=1329 : division const int mod = 1000000007; // const int mod = 998244353; struct mint { ll x; // typedef long long ll; mint(ll x=0):x((x%mod+mod)%mod){} mint operator-() const { return mint(-x);} mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;} mint operator+(const mint a) const { return mint(*this) += a;} mint operator-(const mint a) const { return mint(*this) -= a;} mint operator*(const mint a) const { return mint(*this) *= a;} mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod-2);} mint& operator/=(const mint a) { return *this *= a.inv();} mint operator/(const mint a) const { return mint(*this) /= a;} }; istream& operator>>(istream& is, mint& a) { return is >> a.x;} ostream& operator<<(ostream& os, const mint& a) { return os << a.x;} /*** mod int ここまで ***/ // combination mod prime // https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619 struct combination { vector<mint> fact, ifact; combination(int n):fact(n+1),ifact(n+1) { assert(n < mod); fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i; ifact[n] = fact[n].inv(); for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i; } mint operator()(int n, int k) { if (k < 0 || k > n) return 0; return fact[n]*ifact[k]*ifact[n-k]; } } comb(1000005); void Solve(){ int n, a, b; cin >> n >> a >> b; if(a+b>n) { cout << 0 << endl; return; } mint x = (mint)(n-(a+b)+2) * (mint)(n-(a+b)+1)/2; mint y = (mint)(n-a+1) * (mint)(n-b+1) - (mint)x * 2; mint ans = (mint)(n-a+1) * (mint)(n-a+1) * (mint)(n-b+1) * (mint)(n-b+1) - y * y; cout << ans << endl; } void Main(){ int t; cin >> t; while(t--) Solve(); return; } int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(15); Main(); return 0; }
#include <bits/stdc++.h> #define lli long long int using namespace std; #define mod 1000000007 #define MOD 1000000037 #define mod1 998244353 #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define INF 2147483607 #define common cout << "Case #" << w+1 << ": " int main() { int te; cin >> te; for(int w=0;w<te;w++) { int n,a,b; cin >> n >> a >> b; if(n-a-b+1<=0) cout << "0" << endl; else { int ans=(n+1-a); ans=(ans*1LL*(n+1-b))%mod; ans=(ans*1LL*(n+1-a-b))%mod; ans=(ans*1LL*(n+2-a-b))%mod; ans=(ans*1LL*2)%mod; int ans1=(n+1-a-b)*1LL*(n+1-a-b)%mod; int ans2=(n+2-a-b)*1LL*(n+2-a-b)%mod; ans1=(ans1*1LL*ans2)%mod; ans=(ans*1LL-ans1)%mod; ans=(ans*1LL+mod)%mod; cout << ans << endl; } } }
#include <bits/stdc++.h> #define Fast cin.tie(0), ios::sync_with_stdio(0) #define All(x) x.begin(), x.end() #define louisfghbvc int t; cin >> t; for(int tt = 0; tt < t; ++tt) #define sz(x) (int)(x).size() #define sort_unique(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end())); using namespace std; typedef long long LL; typedef pair<LL, LL> ii; typedef vector<LL> vi; template<typename T> istream& operator>>(istream &is, vector<T> &v) { for(auto &it : v) is >> it; return is; } template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep = ""; for(const auto &x : v) os << sep << x, sep = ", "; return os << '}'; } template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } void dbg_out() { cerr << " end.\n"; } template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); } const int N = 5e2+5; const int INF = 0x3f3f3f3f; /** Read problem statement carefully **/ int dp[N][N]; LL A[N][N], B[N][N]; int r, c; void solve(int x){ memset(dp, 0x3f, sizeof dp); cin >> r >> c; for(int i = 1; i <= r; ++i) for(int j= 1; j < c; ++j) cin >> A[i][j]; for(int i = 1; i < r; ++i) for(int j = 1; j <= c; ++j) cin >> B[i][j]; dp[1][1] = 0; priority_queue<ii, vector<ii>, greater<ii>> pq; pq.push({0, 0}); while(sz(pq)){ auto [cost, idx] = pq.top(); pq.pop(); int x = idx/c, y = idx%c; x++, y++; if(cost > dp[x][y]) continue; dp[x][y] = cost; if(y < c){ if(dp[x][y+1] > dp[x][y] + A[x][y]){ dp[x][y+1] = dp[x][y] + A[x][y]; pq.push({dp[x][y+1], (x-1) * c + y}); } } if(y > 1){ if(dp[x][y-1] > dp[x][y] + A[x][y-1]){ dp[x][y-1] = dp[x][y] + A[x][y-1]; pq.push({dp[x][y-1], (x-1) * c + y - 2}); } } if(x < r){ if(dp[x+1][y] > dp[x][y] + B[x][y]){ dp[x+1][y] = dp[x][y] + B[x][y]; pq.push({dp[x+1][y], x * c + y - 1}); } } for(int i = 1; i < r && x - i > 0; ++i){ int ga = 1 + i; if(dp[x][y] + ga < dp[x-i][y]){ dp[x-i][y] = dp[x][y] + ga; pq.push({dp[x-i][y], (x - i - 1) * c + y-1}); } } } cout << dp[r][c] << "\n"; } int main() { // Fast; // louisfghbvc solve(1); return 0; } /** Enjoy the problem. **/
//...Bismillahir Rahmanir Rahim. . . #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; // typedefs... typedef double db; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<ll, ll> pll; typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update>pref_trie; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset; // constants... const double PI = acos(-1); const ll mod = 998244353; // 1000000007; const int MXS = 2e5+5; const ll MXI = 1e9+5; const ll MXL = 1e18+5; const ll INF = 1e9+5; const ll INFLL = 1e18+5; const ll EPS = 1e-9; // defines... #define MP make_pair #define PB push_back #define fi first #define se second #define sz(x) (int)x.size() #define all(x) begin(x), end(x) #define si(a) scanf("%d", &a) #define sii(a, b) scanf("%d%d", &a, &b) #define ordered_set tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> #define boost_ ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0); #define iter_(i,n) for (int i = 0; i < int(n); i++) #define for_n(i, n) for (int i = 1; i <= int(n); i++) #define print_array(a) for(int i=0;i<n;i++) cout<<a[i]<<" "; #define rev(i,n) for(int i=n;i>=0;i--) #define itr ::iterator #define s_sort(s) sort(s.begin(),s.end()) #define n_sort(a, n) sort(a,a+n) #define precise_impact cout<<setprecision(10)<<fixed; #define endl "\n" // functions... ll gcd(ll a, ll b){ while (b){ a %= b; swap(a, b);} return a;} ll lcm(ll a, ll b){ return (a/gcd(a, b)*b);} ll ncr(ll a, ll b){ ll x = max(a-b, b), ans=1; for(ll K=a, L=1; K>=x+1; K--, L++){ ans = ans * K; ans /= L;} return ans;} ll bigmod(ll a,ll b){ if(b==0){ return 1;} ll tm=bigmod(a,b/2); tm=(tm*tm)%mod; if(b%2==1) tm=(tm*a)%mod; return tm;} ll egcd(ll a,ll b,ll &x,ll &y){ if(a==0){ x=0; y=1; return b;} ll x1,y1; ll d=egcd(b%a,a,x1,y1); x=y1-(b/a)*x1; y=x1; return d;} ll modpow(ll a,ll p) {ll ans=1;while(p){if(p%2)ans=(ans*a)%mod;a=(a*a)%mod;p/=2;} return ans;} ll inverse_mod(ll n) {return modpow(n,mod-2);} //ll ncr_mod(ll n,ll r) {return (((fact[n]*inverse_mod(fact[r]))%mod)*inverse_mod(fact[n-r]))%mod;} int main() { boost_; ll n,k; vector<pair<ll,ll> > v; cin>>n>>k; for(int i=0;i<n;i++) { ll num,x; cin>>num>>x; v.PB({num,x}); } sort(all(v)); ll pos=0; for(int i=0;i<n;i++) { if(pos+k<v[i].fi) {cout<<pos+k<<endl;return 0;} k=k-(v[i].fi-pos)+v[i].se; pos=v[i].fi; } cout<<pos+k<<endl; }
//Created By:Hardik Kapoor #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; //template begins #define int long long int #define ios ios_base::sync_with_stdio(false);cin.tie(NULL); #define itt vector<int>:: iterator #define pb push_back #define mp make_pair #define max3(a,b,c) max(max((a),(b)),(c)) #define max4(a,b,c,d) max(max((a),(b)),max((c),(d))) #define min3(a,b,c) min(min((a),(b)),(c)) #define min4(a,b,c,d) min(min((a),(b)),min((c),(d))) #define lb lower_bound #define ub upper_bound #define all(v) v.begin(),v.end() #define db long double #define itp vector<pair<int,int> >:: iterator #define ff first #define ss second #define endl "\n" typedef pair<int,int> pii; template<typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; /* find_by_order() - Returns an iterator to the k-th largest element (counting from zero) order_of_key() - The number of items in a set that are strictly smaller than our item Rest same as set */ const int inf=1000000000000000000; const long double pi = 3.14159265358979323846264338; const long long mod = 1000000007; // const long long mod = 998244353; int pow(int x, unsigned int y, int p){ int res=1; x=x%p; if (x==0) return 0; while (y > 0) { if (y & 1) res = (res*x) % p; y = y>>1; x = (x*x) % p; } return res; } int _pow(int a, int b){ if(!b) return 1; int temp = _pow(a, b / 2); temp = (temp * temp); if(b % 2) return (a * temp); return temp; } int invmod(int a,int m){ return pow(a,m-2,m); } int cl(int a,int x){ if(a%x==0) return a/x; else return a/x+1; } //template ends signed main(){ ios #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int Tests=1; while(Tests--) { 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 cout<<0<<endl; } }
#include <bits/stdc++.h> using namespace std; int main () { int a, b, c; cin >> a >> b >> c; if (a == b) { cout << c << endl; } else if (a == c) { cout << b << endl; } else if (b == c) { cout << a << endl; } else { cout << 0 << endl; } }
#include<bits/stdc++.h> #include<iostream> #include<cstdio> #include<algorithm> #include<queue> #include<vector> #include<cstring> #include<map> #include<set> #include<cstdlib> #include<bitset> using namespace std; #define FAST ios::sync_with_stdio(false), cin.tie(0), cout.tie(0) typedef long long ll; #define N 200005 ll p=1e9+7; ll n,m,f[N][17][17]={0},v[22]={0},sm; char a[N]; int main() { ll i,j,k,a1,a2,an=0; scanf("%s",a+1); n=strlen(a+1); for(ll i=1;i<=n;i++) if(a[i]>='0'&&a[i]<='9') a[i]-='0'; else a[i]-='A'-10; scanf("%lld",&m); for(ll i=0;i<=m;i++) f[0][i][i]=1; for(ll i=1;i<=n;i++) for(ll j=1;j<=m;j++) for(ll k=j;k<=m;k++) f[i][j][k]=((ll)f[i-1][j][k-1]*(17ll-k)+(ll)f[i-1][j][k]*k)%p; for(ll i=1;i<=n;i++) an=(an+15ll*f[i-1][1][m])%p; // for(ll i=1;i<=n;i++) // { // for(ll j=1;j<=m;j++) // for(ll k=j;k<=m;k++)printf("%lld\n",f[i][j][1]); // } for(ll i=1;i<=n;i++) { for(ll j=a[i]+1;j<=15;j++) an=(an-f[n-i][sm+(!v[j])][m]+p)%p; //printf("%lld\n",an); sm+=!v[a[i]]; v[a[i]]=1; } printf("%lld",an); }
//#pragma GCC optimize(2) #include<cstdio> #include<iostream> #include<string> #include<cstring> #include<map> #include<cmath> #include<cctype> #include<vector> #include<set> #include<queue> #include<algorithm> #include<sstream> #include<ctime> #include<cstdlib> #define X first #define Y second #define L (u<<1) #define R (u<<1|1) #define pb push_back #define mk make_pair #define Mid (tr[u].l+tr[u].r>>1) #define Len(u) (tr[u].r-tr[u].l+1) #define random(a,b) ((a)+rand()%((b)-(a)+1)) #define db puts("---") using namespace std; //void rd_cre() { freopen("d://dp//data.txt","w",stdout); srand(time(NULL)); } //void rd_ac() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//AC.txt","w",stdout); } //void rd_wa() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//WA.txt","w",stdout); } typedef long long LL; typedef unsigned long long ULL; typedef pair<int,int> PII; const int N=200010,mod=1e9+7,INF=0x3f3f3f3f; const double eps=1e-6; int n,k; int a[N]; char s[N]; int f[N][20][2]; int dfs(int pos,int state,int flag,int lead) { int cnt=__builtin_popcount(state); if(cnt>k) return 0; if(pos==n+1) return cnt==k&&lead; if(flag&&lead&&f[pos][cnt][lead]!=-1) return f[pos][cnt][lead]; int x=flag? 15:a[pos]; int ans=0; for(int i=0;i<=x;i++) (ans+=dfs(pos+1,(!lead&&i==0)? state:state|(1<<i),flag||i<x,lead||i!=0))%=mod; f[pos][cnt][lead]=ans; return ans; } int main() { // ios::sync_with_stdio(false); // cin.tie(0); scanf("%s%d",s+1,&k); n=strlen(s+1); for(int i=1;i<=n;i++) if(s[i]>='A'&&s[i]<='Z') a[i]=s[i]-'A'+10; else a[i]=s[i]-'0'; memset(f,-1,sizeof(f)); printf("%d",dfs(1,0,0,0)); return 0; } /* */
#include <iostream> #include <vector> #include <queue> using namespace std; using ll = long long; using ull = unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) template<class T> using nega_queue = priority_queue<T,vector<T>,greater<T>>; ll waittime(ll D){ ll l=0, r=40000; while(r-l > 1){ ll m = (l+r)/2; if(m*m+m <= D) l=m; else r=m; } return l; } struct Edge{ int to; ll c,d,w; }; const ll INF = 1001001001001001001; int N,M; vector<vector<Edge>> E; int main(){ cin >> N >> M; E.resize(N); rep(i,M){ int a,b,c,d; cin >> a >> b >> c >> d; a--; b--; E[a].push_back({ b,c,d,waittime(d) }); E[b].push_back({ a,c,d,waittime(d) }); } vector<ll> D(N,INF); nega_queue<pair<ll,int>> Q; D[0] = 0; Q.push({0ll,0}); while(Q.size()){ int p = Q.top().second; ll d = Q.top().first; Q.pop(); if(D[p] != d) continue; for(auto e : E[p]){ ll t = max(d,e.w); ll nxd = t + e.c + e.d / (t+1); if(D[e.to] <= nxd) continue; D[e.to] = nxd; Q.push({nxd,e.to}); } } if(D[N-1] == INF) cout << "-1\n"; else cout << D[N-1] << "\n"; return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ ios::sync_with_stdio(false); cin.tie(nullptr); } } ios_do_not_sync_inst;
#include<iostream> #include<string> #include<cstdio> #include<vector> #include<cmath> #include<algorithm> #include<functional> #include<iomanip> #include<queue> #include<ciso646> #include<random> #include<map> #include<set> #include<bitset> #include<stack> #include<unordered_map> #include<utility> #include<cassert> #include<complex> #include<numeric> #include<array> #define rep(i,n) for(int i=0;i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define Rep(i,sta,n) for(int i=sta;i<n;i++) #define rep1(i,n) for(int i=1;i<=n;i++) #define per1(i,n) for(int i=n;i>=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) #define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n"); #define all(v) (v).begin(),(v).end() #define all_rev(v) (v).rbegin(),(v).rend() #define debug(x) cout << #x << ": " << x << '\n'; #define degreeToRadian(deg) (((deg)/360)*2*M_PI) #define radianTodegree(rad) (((rad)/2/M_PI)*360) template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; using ll = long long; using P = pair<int,int>; using PL = pair<ll, ll>; const ll INF = 1LL<<60; const int MOD = 1e9 + 7; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; int main() { //cin.tie(0);ios::sync_with_stdio(false); //cout << fixed << setprecision(15); int n; cin >> n; vector<P> a; vector<P> b; rep (i, n) { int t, tt; cin >> t >> tt; a.push_back({t,i}); b.push_back({tt,i}); } sort(all(a)); sort(all(b)); if (a[0].second != b[0].second) { cout << max(a[0].first, b[0].first) << endl; } else { int t = a[0].first + b[0].first; int tt = max(a[1].first, b[0].first); int ttt = max(a[0].first, b[1].first); t = min(t, tt); t = min(t, ttt); cout << t << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long #define deb(x) cout << #x << "=" << x << endl //------------------------------------------------------------ void solve(){ int n; cin >> n; int A[n]; for (auto &it: A) cin >> it; int P[n+1] = {0}, PP[n+1] = {0}; int emax = A[0]; for (int i=0; i<n; ++i){ P[i+1] = P[i] + A[i]; } for (int i=0; i<n; ++i){ PP[i+1] = PP[i] + P[i+1]; } // for (auto m: PP) cout << m << ' '; for (int i=1; i<=n; ++i){ emax = max(emax, A[i-1]); int ans = i*emax + PP[i]; cout << ans << '\n'; } } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; // cin >> t; while (t--){ solve(); } } // ------------------------------------------------------------
// //#ifdef ONLINE_JUDGE //#pragma GCC optimize("Ofast") //#pragma GCC optimize("O2") //#pragma GCC optimize("O3") //#pragma GCC optimize("unroll-loops") ////// //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx") //#endif #include <bits/stdc++.h> #include <utility> #define all(x) (x).begin(), (x).end() #define allp(x) (x)->begin(), (x)->end() #define pb push_back using namespace std; void dout() { cerr << endl; } typedef long long ll; typedef long double ld; template <typename Head, typename... Tail> void dout(Head H, Tail... T) { cerr << H << ' '; dout(T...); } //using ll = long long; //#ifdef __int128 //using hll = __int128; //#endif //using pii = pair<ll, ll>; //using ld = long double; template <typename T> void do_uniq(vector<T> &vec){ sort(all(vec)); vec.resize(unique(all(vec)) - vec.begin()); } #ifndef ONLINE_JUDGE clock_t timestamp_start = clock(); void time_calc() { cerr << (ld)(clock() - timestamp_start) / CLOCKS_PER_SEC << endl; } #endif #ifdef _getchar_nolock #else # define _getchar_nolock getchar_unlocked #endif #define integer ll integer mod = 1e9 + 7; integer ml(integer a, integer b) { return (a * 1ll * b) % mod; } integer add(integer a, integer b) { return (a + b) % mod; } integer sub(integer a, integer b) { return add(a, mod - b); } integer sq(integer a) { return ml(a, a); } integer b_p(integer b, integer p) { if (p == 0) return 1; if (p & 1) return ml(b, b_p(b, p - 1)); return sq(b_p(b, p >> 1)); } int gcd(int x, int y){ return y == 0 ? x : gcd(y, x % y); } #define solvsh //#define multi #ifdef solvsh //#define int ll const int MAXN = 5e3 + 32; void solve() { int n; cin >> n; vector<int> v; for (int i = 0; i < n; ++i) { int curr; cin >> curr; v.push_back(curr); } ll mmx = 0; ll pref = 0; ll add = 0; for (int i = 0; i < n; ++i) { mmx = max(mmx, 0ll + v[i]); ll answr = (i + 1) * mmx; pref += v[i]; add += pref; answr += add; cout << answr << "\n"; } } #else #endif void multisolve() { #ifndef ONLINE_JUDGE freopen("../input.in", "r", stdin); #endif int t; cin >> t; int i = 1; while (t--) { // cout << "Case #" << i << ": "; solve(); // i++; } } #ifndef ONLINE_JUDGE void gen() { #ifndef ONLINE_JUDGE freopen("../input.in", "w", stdout); #endif } #endif #define int int int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); cout << fixed << setprecision(20); cerr << fixed << setprecision(20); #ifdef multi // gen(); multisolve(); // checkk(); #else solve(); #endif // time_calc(); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pll; #define all(x) (x).begin(),(x).end() #define X first #define Y second #define sep ' ' #define endl '\n' #define debug(x) cerr << #x << ": " << x << endl; const ll MAXN = 1e6 + 10; const ll INF = 8e18; const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9; int n; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; set<int> st; for (int i = 1; i <= n; i++) { int x; cin >> x; st.insert(x); } ll ans = 1, prv = 0; while (!st.empty()) { int x = *st.begin(); ans = ans * (x - prv + 1) % MOD; st.erase(st.begin()); prv = x; } cout << ans << endl; return 0; }
#include<bits/stdc++.h> #define LL long long using namespace std; const int mod=1000000007,inv2=(mod+1)/2; int n,a[100010]; LL ans=1; inline int read() { int x=0;bool w=0;char ch=0; while(!isdigit(ch)){w|=ch=='-';ch=getchar();} while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();} return w?-x:x; } LL ksm(LL B,LL K,LL A=1) { for(;K;K>>=1,B=B*B%mod) if(K&1)A=A*B%mod; return A; } int main() { n=read(); for(int i=1;i<=n;i++) a[i]=read(); sort(a+1,a+1+n); n=unique(a+1,a+1+n)-a-1; for(int i=1;i<=n;i++) ans=ans*(1+a[i]-a[i-1])%mod; printf("%lld\n",ans); return 0; }
#include<bits/stdc++.h> typedef long long ll; typedef long double ld; using namespace std; mt19937_64 mrand(chrono::steady_clock::now().time_since_epoch().count()); //mt19937_64 mrand(42); #define ii for(int i=1;i<=n;++i) #define ji for(int j=1;j<=n;++j) #define jj for(int j=1;j<=m;++j) #define ij for(int i=1;i<=m;++i) #define sz(x) ((ll)x.size()) #define all(x) x.begin(),x.end() #define al(x) x+1,x+1+n #define asd cout<<"ok"<<endl; #define asdd cout<<"okok"<<endl; #define vi vector<int> #define vvi vector<vector<int>> #define vl vector<ll> #define vii vector<pair<int,int>> #define pr(v) for(auto i:v) cout<<i<<" ";cout<<endl; #define prt(a, l, r) for(auto i=l;i<=r;++i) cout<<a[i]<<" ";cout<<endl; #define pc(x) __builtin_popcount(x) #define pb push_back #define PS string qqwwee;cin>>qqwwee; const int maxn = 105; int x[maxn], y[maxn]; int main() { int n; cin >> n; ii cin >> x[i] >> y[i]; int ok = 0; for(int i=1;i<=n;++i) { for(int j=i+1;j<=n;++j) { for(int k=j+1;k<=n;++k) { // (y[i] - y[k]) / (x[i] - x[k]) = (y[j] - y[k]) / (x[j] - x[k]) if((y[i] - y[k]) * (x[j] - x[k]) == (y[j] - y[k]) * (x[i] - x[k])) { ok = 1; break; } } } } if(ok) cout << "Yes"; else cout << "No"; }
#include <map> #include <set> #include <list> #include <cmath> #include <queue> #include <stack> #include <bitset> #include <vector> #include <cstdio> #include <string> #include <cassert> #include <climits> #include <sstream> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define PB push_back #define MP make_pair #define SZ(v) ((int)(v).size()) #define abs(x) ((x) > 0 ? (x) : -(x)) #define FOREACH(e,x) for(__typeof(x.begin()) e=x.begin();e!=x.end();++e) typedef long long LL; double my_sqrt(double d) {return sqrt(max(d, 0.0));} double my_acos(double d) {return acos(d<-1?-1:d>1?1:d);} #define sqr(v) ((v)*(v)) const int MAXN = 105; const double eps = 1E-6; int n; int sig(double d) { return (d>eps) - (d<-eps); } struct Point { double x, y; Point(double x, double y) : x(x), y(y) {} Point() {} Point operator - (const Point & p) const { return Point(x-p.x, y-p.y); } Point operator + (const Point & p) const { return Point(x+p.x, y+p.y); } Point operator * (double d) const { return Point(x*d, y*d); } /*double operator * (const Point &b) const { return x * b.y - y * b.x; }*/ bool operator == (const Point & p) const { return sig(x-p.x)==0 && sig(y-p.y)==0; } bool operator < (const Point & p) const { return sig(x-p.x)!=0 ? x<p.x : sig(y-p.y)<0; } Point resize(double d) { d /= my_sqrt(sqr(x)+sqr(y)); return Point(x*d, y*d); } Point left90() { return Point(-y, x); } Point rotate(double radian) { //逆时针转 double c = cos(radian), s = sin(radian); return Point(x*c-y*s, y*c+x*s); } double mod() { return my_sqrt(sqr(x)+sqr(y)); } void output() { printf("x = %.2f, y = %.2f\n", x, y); } }; double cross(const Point & o, const Point & a, const Point & b) { return (a.x-o.x)*(b.y-o.y) - (b.x-o.x)*(a.y-o.y); } double dot(Point o, Point a, Point b) { return (a.x-o.x)*(b.x-o.x) + (a.y-o.y)*(b.y-o.y); } int main() { cin >> n; vector<Point> p(n); for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; p[i] = Point(x, y); } for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { for (int k = j + 1; k < n; k++) { // cout << i << j << k << " " << cross(p[i], p[j], p[k]) << endl; if (sig(cross(p[i], p[j], p[k])) == 0) { cout << "Yes" << endl; return 0; } } } } cout << "No" << endl; return 0; }
// // main.cpp // test // // Created by wyzwyz on 2021/5/13. // #include<cstdio> #include<cctype> #include<map> #define maxn 505505 template<class T> inline T read(){ T r=0,f=0; char c; while(!isdigit(c=getchar()))f|=(c=='-'); while(isdigit(c))r=(r<<1)+(r<<3)+(c^48),c=getchar(); return f?-r:r; } template<class T> inline T min(T a,T b){ return a<b?a:b; } int n,a[maxn]; long long sum[2][maxn]; std::map<long long,int> cnt; int main(){ n=read<int>(); for(int i=1;i<=n;i++) a[i]=read<int>(); sum[1][1]=a[1]; cnt[-a[1]]=1; for(int i=2;i<=n;i++){ if(i&1){ sum[0][i]=sum[0][i-1]; sum[1][i]=sum[1][i-2]+a[i]; } else { sum[1][i]=sum[1][i-1]; sum[0][i]=sum[0][i-2]+a[i]; } cnt[sum[0][i]-sum[1][i]]++; } long long ans=cnt[0]; for(int i=1;i<n;i++){ cnt[sum[0][i]-sum[1][i]]--; ans+=cnt[sum[0][i]-sum[1][i]]; } printf("%lld\n",ans); return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define pll pair<ll,ll> #define ff first #define ss second #define pb push_back #define endl "\n" const ll maxn =7e5+100; const ll mod=1e9+7 ; const ll base=2e18; ll n; vector<pll> adj[maxn]; ll dp[(1ll<<18)]; 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.ans","w",stdout); } ll m; cin>> n>> m ; dp[0]=1; while (m--) { ll x, y, z; cin>>x>> y>> z; adj[x].pb(make_pair(y-1,z)); } for (int i=1;i<(1ll<<n);i++) { vector<ll> vt; for (int j=0;j<n;j++) { if (i&(1ll<<j)) { dp[i]+=dp[i^(1ll<<j)]; vt.pb(j); } } ll x=__builtin_popcount(i); for (auto p:adj[x]) { ll y=p.ff; ll z=p.ss; auto h=upper_bound(vt.begin(),vt.end(),y)-vt.begin(); if (h>z) dp[i]=0; } } cout <<dp[(1ll<<n)-1]; }
#include<bits/stdc++.h> using namespace std; int main(){ int a,b; cin>>a>>b; if(b%a==0){ cout<<"Yes"<<endl; } else{ cout<<"No"<<endl; } return 0; }
#pragma GCC optimize("O3") #pragma GCC target("sse4") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpii; #define FOR(i, a, b) for (int i = a; i <= (b); i++) #define F0R(i, a) for (int i = 0; i < (a); i++) #define FORd(i, a, b) for (int i = (b); i >= a; i--) #define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--) #define trav(a, x) for (auto &a : x) #define sz(x) (int)(x).size() #define mp make_pair #define pb push_back #define eb emplace_back #define f first #define s second #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() #define ins insert mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int MOD = 1000000007; const char nl = '\n'; const int MX = 150001; //check the limits, dummy void solve(int t) { } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int M,H; cin>>M>>H; cout << (H%M?"No\n":"Yes\n"); } // read the question correctly (ll vs int) // template by bqi343
// Problem: // B - Reversible Cards // // // Contest: AtCoder - AtCoder Regular Contest 111 // URL: https://atcoder.jp/contests/arc111/tasks/arc111_b // Memory Limit: 1024 MB // Time Limit: 2000 ms // // Powered by CP Editor (https://cpeditor.org) #define _CRT_SECURE_NO_WARNINGS #include <bits/stdc++.h> using namespace std; typedef long long ll; #define forn(i,x,n) for(int i = x;i <= n;++i) const int N = 4e5+7,M = 2 * N; vector<int> E[N]; int st[N],in_stk[N],cir; void dfs(int u,int fa) { in_stk[u] = 1; st[u] = 1; for(auto& v : E[u]) { if(v == fa) continue; if(in_stk[v]) cir = 1; if(st[v]) continue; dfs(v,u); } in_stk[u] = 0; } int main() { int n;scanf("%d",&n); set<int> col; forn(i,1,n) { int u,v;scanf("%d%d",&u,&v); E[u].push_back(v);E[v].push_back(u); col.insert(u);col.insert(v); } int res = col.size(); // cout << res << endl; for(auto& i : col) if(!st[i]) { cir = 0; dfs(i,-1); if(!cir) --res; } printf("%d",res); return 0; }
#include <bits/stdc++.h> using namespace std; template <typename T> using vec = vector<T>; template <typename T> using vvec = vec<vec<T>>; template <typename T> using lqueue = priority_queue<T, vector<T>, greater<T>>; template <typename T> using gqueue = priority_queue<T, vector<T>, less<T>>; constexpr int max_v = 400000; array<vec<int>, max_v + 1> g; array<bool, max_v + 1> vis; int main() { int n; cin >> n; for (int i = 0; i < n; ++i) { int a, b; cin >> a >> b; g[a].push_back(b); g[b].push_back(a); } int ans = 0; for (int i = 0; i <= max_v; ++i) { if (vis[i]) continue; vis[i] = true; int sum = 0, cnt = 0; queue<int> que; que.push(i); while (!que.empty()) { int c = que.front(); que.pop(); sum += g[c].size(); ++cnt; for (auto v : g[c]) { if (vis[v]) continue; vis[v] = true; que.push(v); } } sum /= 2; if (cnt <= sum) { ans += cnt; } else { ans += cnt - 1; } } cout << ans << endl; }
#include<bits/stdc++.h> #define ll long long int #define mk make_pair #define pb push_back #define INF (ll)1e18 #define pii pair<ll,ll> #define mod 1000000007 //998244353 #define f(i,a,b) for(ll i=a;i<b;i++) #define fb(i,a,b) for(ll i=a;i>b;i--) #define ff first #define ss second #define srt(v) if(!v.empty())sort(v.begin(),v.end()) #define rev(v) if(!v.empty())reverse(v.begin(),v.end()) #define PI 3.141592653589793238 #define pqr priority_queue<ll,vector<ll>,greater<ll>()> using namespace std; ll pow_mod(ll a,ll b) { ll res=1; while(b!=0) { if(b&1) { res=(res*a)%mod; } a=(a*a)%mod; b/=2; } return res; } void solve() { long double x,y,r; cin>>x>>y>>r; r=nextafter(r,INFINITY); ll ans=0; // cout<<rr<<endl; // cout<<ceil(-5.5)<<endl; ll low=(ll)ceil(x-r); ll high=(ll)floor(x+r); // cout<<low<<" "<<high<<endl; for(ll i=low;i<=high;i++){ long double x_cor=i; long double y_cor=sqrt(r*r-(x-x_cor)*(x-x_cor)); long double up=y_cor+y+1e-14; long double down=y-y_cor-1e-14; // cout<<up<<" "<<down<<endl; ll u=(floor)(up); ll d=(ceil)(down); ans+=(u-d+1); //ans+=(2*lim_y+1); } cout<<ans<<endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); //Start from Here. ll t; t=1; // cin>>t; while(t--) solve(); //Good Bye! return 0; }
#include <bits/stdc++.h> #define REP(i,n) for(ll i=0;i<(ll)(n);i++) #define REPD(i,n) for(ll i=n-1;i>=0;i--) #define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++) #define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--) #define ALL(x) (x).begin(),(x).end() #define RALL(x) (x).rbegin(),(x).rend() #define SIZE(x) ((ll)(x).size()) #define MAX(x) *max_element(ALL(x)) #define MIN(x) *min_element(ALL(x)) using namespace std; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } typedef long long ll; const int INF = 1000000000; bool ok(ll x, ll y, ll r){ return x*x + y*y <= r*r; } ll solver(ll x, ll y, ll r, ll lim){ int L = 0, R = 1; ll res = 0; for(int i = int(1e9)+50000; i >= lim; i-=10000){ while(ok(x-L*10000,i-y,r)) --L; while(ok(R*10000-x,i-y,r)) ++R; res += R - L - 1; } return res; } ll in(){ double x; cin >> x; x *= 10000; return round(x); } int main() { ll x = in(); ll y = in(); ll r = in(); x %= 10000; y %= 10000; ll ans = solver(x, y, r, 10000); ans += solver(x, -y, r, 0); cout << ans << endl; return 0; }