code_file1
stringlengths
87
4k
code_file2
stringlengths
85
4k
#include <bits/stdc++.h> using namespace std; int main() { int n; double x, y; complex<double> a, b; cin >> n; cin >> x >> y; a = {x, y}; cin >> x >> y; b = {x, y}; auto m = (a + b) / 2.0; auto res = m + (a - m) * polar(1.0, M_PI * 2.0 / n); cout << setprecision(9) << res.real() << " " << res.imag() << endl; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define mit map<int,int>::iterator #define sit set<int>::iterator #define itrm(g,x) for(mit g=x.begin();g!=x.end();g++) #define itrs(g,x) for(sit g=x.begin();g!=x.end();g++) #define ltype int #define rep(i,j,k) for(ltype(i)=(j);(i)<=(k);(i)++) #define rap(i,j,k) for(ltype(i)=(j);(i)<(k);(i)++) #define per(i,j,k) for(ltype(i)=(j);(i)>=(k);(i)--) #define pii pair<int,int> #define fi first #define se second #define mpr make_pair #define pb push_back #define fastio ios::sync_with_stdio(false) #define check(x) if(x>=mod) x-=mod const int inf=0x3f3f3f3f,mod=1000000007; const double pi=3.1415926535897932,eps=1e-6; void chmax(int &x,int y){if(x < y) x = y;} void chmin(int &x,int y){if(x > y) x = y;} int qpow(int x,int y){ int ret = 1; while(y) { if(y & 1) ret = (ll)ret * x % mod; x = (ll)x * x % mod; y >>= 1; } return ret; } int n,m,a,b,ans; char s[1005][1005]; int main() { scanf("%d%d%d%d",&n,&m,&a,&b); rep(i,1,n) scanf("%s",s[i]+1); int P = a; while(P > 1 && s[P - 1][b] == '.') ans++,P--; P = b; while(P > 1 && s[a][P - 1] == '.') ans++,P--; P = a; while(P < n && s[P + 1][b] == '.') ans++,P++; P = b; while(P < m && s[a][P + 1] == '.') ans++,P++; printf("%d\n",ans+1); return 0; }
/* #pragma GCC optimize(2) #pragma GCC optimize(3,"Ofast","inline") */ #include<bits/stdc++.h> #define ALL(x) (x).begin(),(x).end() #define ll long long #define db double #define ull unsigned long long #define pii_ pair<int,int> #define mp_ make_pair #define pb push_back #define fi first #define se second #define rep(i,a,b) for(int i=(a);i<=(b);i++) #define per(i,a,b) for(int i=(a);i>=(b);i--) #define show1(a) cout<<#a<<" = "<<a<<endl #define show2(a,b) cout<<#a<<" = "<<a<<"; "<<#b<<" = "<<b<<endl using namespace std; const ll INF = 1LL<<60; const int inf = 1<<30; const int maxn = 2e5+5; inline void fastio() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);} int a[maxn],b[maxn],c[maxn]; int main() { fastio(); int n,k; cin >> n >> k; vector<pii_> g; rep(i,1,n){ cin >> a[i] >> b[i] >> c[i]; g.pb(mp_(a[i],c[i])); g.pb(mp_(b[i]+1,-c[i])); } sort(ALL(g)); ll ans = 0,tot = 0; rep(i,0,2*n-1){ int now = g[i].fi; tot += g[i].se; int pos = i; while(pos+1<2*n && g[pos+1].fi==now){ tot += g[++pos].se; } if(pos == 2*n-1) break; ans += 1LL*min(1LL*k,tot)*(g[pos+1].fi-now); i = pos; } cout << ans << endl; return 0; }
#include <cctype> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <ios> #include <iostream> #include <iterator> #include <string_view> #include <utility> #include <vector> #include <string> #include <algorithm> #include <queue> #include <climits> #include <cmath> #include <sstream> #include <iomanip> #include <map> #include <stack> #include <regex> #include <set> #include <bitset> #include <list> const int64_t infl = 1LL << 60; const int64_t cc = pow(10, 9) + 7; bool sort_pair(std::pair<int64_t, char> origin, std::pair<int64_t, int64_t> another) { return origin.first < another.first; } bool sort_pair2(std::pair<int64_t, char> origin, std::pair<int64_t, int64_t> another) { return origin.second < another.second; } 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; } int main() { int64_t q,k,h,w,m,n,c; std::cin>> n; std::cin>> c; std::vector< std::pair< int64_t, int64_t > > list; for( int i = 0; i < n; i++ ) { std::cin>> q; std::cin>> k; std::cin>> h; list.push_back( std::make_pair( q, h ) ); list.push_back( std::make_pair( k + 1, -h ) ); } std::sort( list.begin(), list.end(), sort_pair ); q = 0; k = 1; m = 0; for( int i = 0; i < list.size(); i++ ) { if( k != list[i].first ) { q += std::min( c, m ) * ( list[i].first - k ); k = list[i].first; } m += list[i].second; } std::cout<< q <<"\n"; }
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,a,b) for(int i=a;i>=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() //#pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } //--------------------------------------------------------------------------------------------------- template<int MOD> struct ModInt { static const int Mod = MOD; unsigned x; ModInt() : x(0) { } ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; } ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; } int get() const { return (int)x; } ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; } ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; } ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; } ModInt &operator/=(ModInt that) { return *this *= that.inverse(); } ModInt operator+(ModInt that) const { return ModInt(*this) += that; } ModInt operator-(ModInt that) const { return ModInt(*this) -= that; } ModInt operator*(ModInt that) const { return ModInt(*this) *= that; } ModInt operator/(ModInt that) const { return ModInt(*this) /= that; } ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); } return ModInt(u); } bool operator==(ModInt that) const { return x == that.x; } bool operator!=(ModInt that) const { return x != that.x; } ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; } }; template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a) { st << a.get(); return st; }; template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) { ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; } typedef ModInt<1000000007> mint; /*---------------------------------------------------------------------------------------------------             ∧_∧       ∧_∧  (´<_` )  Welcome to My Coding Space!      ( ´_ゝ`) /  ⌒i @hamayanhamayan0     /   \    | |     /   / ̄ ̄ ̄ ̄/  |   __(__ニつ/  _/ .| .|____      \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ int N; ll A[3010]; mint dp[3010][3010]; // dp[i][k] := i番目まででk組作った mint tot[3010][3010]; // tot[k][mo] := k組作っていてこれまでの総和を(k+1)で割った余りがmoである //--------------------------------------------------------------------------------------------------- void _main() { cin >> N; rep(i, 0, N) cin >> A[i]; dp[0][0] = 1; tot[0][0] = 1; ll sum = 0; rep(i, 0, N) { sum += A[i]; rep(k, 1, N + 1) dp[i + 1][k] = tot[k - 1][sum % k]; rep(k, 1, N + 1) tot[k][sum % (k + 1)] += dp[i + 1][k]; } mint ans = 0; rep(k, 1, N + 1) ans += dp[N][k]; cout << ans << endl; }
#include<bits/stdc++.h> #define rep(i, n) for(int i = 0;i < (n);i++) using namespace std; const int INF = 10000000; using ll = long long; int main() { int n, m, q; cin >> n >> m >> q; vector<int> x(m); vector<pair<int, int>> vw(n); rep(i, n) cin >> vw[i].second >> vw[i].first; rep(i, m) cin >> x[i]; sort(vw.begin(), vw.end(), greater<pair<int, int>>()); rep(i, q) { int l, r; cin >> l >> r; ll ans = 0; vector<pair<int, int>> vwtemp; for(auto j : vw) vwtemp.push_back(j); vector<int> temp; for(int j = 0;j < l - 1;j++) temp.push_back(x[j]); for(int j = r;j < m;j++) temp.push_back(x[j]); sort(temp.begin(), temp.end()); for(int j : temp){ rep(k, n) { if(j >= vwtemp[k].second){ ans += vwtemp[k].first; vwtemp[k].second = INF; break; } } } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> #define int long long #define x first #define y second using namespace std; void solve(){ int n; string s,t; cin>>n>>s>>t; vector <int> aw {0,1,1,1,1,1,1},tw {1,0,0,0,0,0,0}; for (int i=n-1; i>=0; i--){ vector <int> temp {0,0,0,0,0,0,0}; if (t[i]=='A'){ for (int j=0; j<7; j++){ if (!aw[j]) continue; for (int k=0; k<7; k++){ if ((10*k)%7==j||(10*k+s[i]-'0')%7==j) temp[k]=1; } } aw=temp; for (int j=0; j<7; j++) tw[j]=aw[j]^1; } else { for (int j=0; j<7; j++){ if (!tw[j]) continue; for (int k=0; k<7; k++){ if ((10*k)%7==j||(10*k+s[i]-'0')%7==j) temp[k]=1; } } tw=temp; for (int j=0; j<7; j++) aw[j]=tw[j]^1; } } if (aw[0]) cout<<"Aoki"; else cout<<"Takahashi"; } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); int t=1; //cin>>t; while (t--) solve(); }
#include <cstdio> using namespace std; const int max_n = 200000; char s[max_n+1], op[max_n+1]; bool wn[7] = {}, nwn[7]; int main() { int n, cur = 1; bool sl1, sl2; scanf("%d%s%s", &n, s, op); wn[0] = true; for (int i = n - 1; i >= 0; i--) { for (int j = 0; j < 7; j++) nwn[j] = wn[j]; if (op[i] == 'A') { for (int j = 0; j < 7; j++) if (!wn[(j+cur*(s[i]-'0'))%7]) nwn[j] = false; } else { for (int j = 0; j < 7; j++) if (wn[(j+cur*(s[i]-'0'))%7]) nwn[j] = true; } sl1 = true, sl2 = false; for (int j = 0; j < 7; j++) { wn[j] = nwn[j]; sl1 &= wn[j], sl2 |= wn[j]; } if (sl1) { puts("Takahashi"); return 0; } else if (!sl2) { puts("Aoki"); return 0; } cur = (cur * 10) % 7; } if (wn[0]) puts("Takahashi"); else puts("Aoki"); return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int(i)=0;i<(n);i++) #define MAX_N 200001 int par[MAX_N]; //親 int rnk[MAX_N]; //木の深さ int siz[MAX_N]; //木のサイズ typedef long long ll; //n要素で初期化 void init(){ REP(i,MAX_N){ par[i]=i; rnk[i]=0; siz[i]=1; } } //木の根を求める int find(int x){ if(par[x]==x){ return x; }else{ return par[x]=find(par[x]); } } //xとyの属する集合を併合 void unite(int x,int y){ x=find(x); y=find(y); if(x==y) return; if(rnk[x]<rnk[y]){ par[x]=y; siz[y]+=siz[x]; }else{ par[y]=x; siz[x]+=siz[y]; if(rnk[x]==rnk[y]) rnk[x]++; } } //xとyが同じ集合に属するか否か bool same(int x, int y){ return find(x)==find(y); } //連結成分の個数 int union_num(int n){ int rtn=0; REP(i,n) if(i==find(i)) rtn++; return rtn; } int main(){ int n;cin>>n; int ans=0; vector<int> x(n,0); set<int> se; init(); REP(i,n){ cin>>x.at(i); se.insert(x.at(i)); } REP(i,n) unite(x.at(i),x.at(n-i-1)); for(auto p:se) if(p==find(p)) ans+=siz[p]-1; //REP(i,n) if(x.at(i)==find(x.at(i))) ans+=siz[x.at(i)]-1; //for(auto p:se) cout<<p<<" "<<find(p)<<" "<<siz[p]<<endl; cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; inline int read(){ int f=1,r=0;char c=getchar(); while(!isdigit(c))f^=c=='-',c=getchar(); while(isdigit(c))r=(r<<1)+(r<<3)+(c^48),c=getchar(); return f?r:-r; } int main(){ cout<<max(read(),0); return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define _GLIBCXX_DEBUG using namespace std; using ll = long long; using P = pair<int,int>; const int Max_W = 1000000, INF = 1e9; int dpmin[Max_W+1], dpmax[Max_W+1]; int main(){ int a, b, w; cin >> a >> b >> w; w *= 1000; fill(dpmin, dpmin+w+1, INF); fill(dpmax, dpmax+w+1, -INF); for (int i = a; i <= b; i++){ dpmin[0] = 0; dpmax[0] = 0; for (int j = 0; j <= w; j++){ if (j - i >= 0) { dpmin[j] = min(dpmin[j-i] + 1, dpmin[j]); dpmax[j] = max(dpmax[j-i] + 1, dpmax[j]); } } } if (dpmin[w] == INF || dpmax[w] == -INF) { cout << "UNSATISFIABLE" << endl; return 0; } cout << dpmin[w] << " " << dpmax[w] << endl; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (int)(n); i++) using namespace std; using LL = long long; using P = pair<int,int>; const long double INF = 2e12; const long double eps = 1e-12; int N, M, K; vector<int> A; long double solve(long double ans){ vector<long double> dp(N + 1), sum(N + 1); rep(i,N){ int n = N - 1 - i; if(A[n]) dp[n] = ans; else dp[n] = (sum[i] - sum[max(0, i - M)]) / M + 1; sum[i+1] = sum[i] + dp[n]; } return dp[0]; } long double binary_search(long double left, long double right){ if(right - left < eps * left) return left; long double ans = sqrt(left * right); long double res = solve(ans); if(ans > res) right = ans; else left = ans; return binary_search(left, right); } int main(){ cin >> N >> M >> K; A = vector<int>(N + 1); rep(i,K){ int a; cin >> a; A[a] = 1; } int num = 0; rep(i,N+1){ if(A[i]) num++; else num = 0; if(num >= M){ cout << -1 << endl; return 0; } } cout << setprecision(20) << binary_search(1, INF) << endl; return 0; }
//------------------------------------- //| -<{ Besme llahe Rahmane Rahim }>- | //------------------------------------- #include <bits/stdc++.h> #define pb push_back #define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); #define sz(x) (int)(x).size() #define all(c) (c).begin(),(c).end() using namespace std; //#include ".dbg.h" typedef long long ll; const int N = 300005; ll n, cnt = 1, ans; int a[N]; void solve(){ ans = n * (n-1) / 2; sort(a, a + n); for(ll i = 1; i < n; i++) { if(a[i] == a[i-1]) cnt++; if(a[i] != a[i-1] || i == n-1) { ans -= (cnt * (cnt - 1) / 2); cnt = 1; } } } int main(){ cin >> n; for(int i = 0; i < n; i++) cin >> a[i]; solve(); cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,a,n) for (int i=a;i<n;i++)//iをaからn #define per(i,n,a) for (int i=a-1;i>=n;i--)//iをnからa #define db(x) cout << #x << " = " << x << endl #define db2(x, y) cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"; //デバッグ用 #define all(x) (x).begin(), (x).end() #define INF 1000000000000 //10^12:∞ #define MOD 1000000007 //10^9+7:合同式の法 #define pb push_back #define F first #define S second typedef long long ll; //sort(all(a)); ソート //sort(all(a),greater<int>()); 逆順ソート //a.erase(unique(all(a)), a.end()); ソート後に重複を削除 //cout<< std::fixed << std::setprecision(15)<<0.000001<<endl; 小数点以下を表示させる //vector<vector<int>> data(3, vector<int>(4)); int型の2次元配列(3×4要素の)の宣言 int main() { ll n; cin>>n; vector<ll> a(n+1); ll ans=0; rep(i,0,n){ cin>>a.at(i); } a.at(n)=MOD; sort(all(a)); ll last=0; rep(i,0,n-1){ if(a.at(i)!=a.at(i+1)){ //cout<<i<<" "<<a.at(i)<<" "<<i+1<<" "<<a.at(i+1)<<endl; last=i+1; }else{ } ans+=last; } cout<<ans; return 0; }
#include <bits/stdc++.h> using namespace std; std::vector<std::string> split(std::string str, char del) { int first = 0; int last = str.find_first_of(del); std::vector<std::string> result; while (first < str.size()) { std::string subStr(str, first, last - first); result.push_back(subStr); first = last + 1; last = str.find_first_of(del, first); if (last == std::string::npos) { last = str.size(); } } return result; } unsigned GetDigit(unsigned num) { unsigned digit = 0; while (num != 0) { num /= 10; digit++; } return digit; } long long int poww(int x, int y) { long long int res = 1; for (int i = 0; i < y; i++) { res *= x; } return res; } int main() { long long int N; cin >> N; long long int cnt = 0; // for (int i = 1; i <= N; i++) // { // int d = GetDigit(i); // // cout << i << ": " << d << endl; // if (d % 2 != 0) // { // continue; // } // auto a = poww(10, d/2); // if (i % a == i/ a) { // cnt++; // } // } // cout << cnt << endl; for (int i= 1; i < 10e+6; i++) { auto d = GetDigit(i); auto n = poww(10,d)* i + i; if (n <= N) cnt++; else break; } cout << cnt << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long int32_t main() { string s; cin>>s; int ans; int n=s.length(); if(n&1) ans=pow(10,n/2)-1; else { int x = stoi(s.substr(0,n/2)); int y = stoi(s.substr(n/2,n/2)); if(x<=y) ans=x; else ans=x-1; } cout<<ans; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i = 0; i < (n); ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) #define srep(i,s,t) for (int i = s; i < t; ++i) using namespace std; typedef long long int ll; typedef pair<int,int> P; #define yn {puts("Yes");}else{puts("No");} struct edge{ ll to, cost; }; #define MAX_N 200005 int nn = MAX_N; // 複数回根付き木を作成する場合は適宜変える. vector<edge> pre_G[MAX_N]; vector<edge> G[MAX_N]; int par_[MAX_N]; ll par_cost[MAX_N]; int flag_netsukigi[MAX_N]; void make_netsukigi(int r){ rep(i,nn){ G[i].clear(); par_[i] = 0; flag_netsukigi[i] = 0; } queue<int> que; que.push(r); flag_netsukigi[r] = 1; par_[r] = -1; while(que.size() > 0){ int x = que.front(); que.pop(); flag_netsukigi[x] = 1; rep(i,pre_G[x].size()){ if(flag_netsukigi[pre_G[x][i].to] == 0){ par_[pre_G[x][i].to] = x; par_cost[pre_G[x][i].to] = pre_G[x][i].cost; G[x].push_back(pre_G[x][i]); que.push(pre_G[x][i].to); } } } } ll dp[MAX_N][64][2]; ll ans; const ll MOD = 1000000007; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; nn = n; rep(i,n-1){ ll from, to, cost; cin >> from >> to >> cost; from--; to--; // 0-indexにするため. edge e1, e2; e1.to = to; e2.to = from; e1.cost = cost; e2.cost = cost; pre_G[from].push_back(e1); pre_G[to].push_back(e2); } make_netsukigi(0); int sons[n] = {}; queue<int> que; rep(i,n){ sons[i] = G[i].size(); if(G[i].size() == 0){ que.push(i); } rep(j,60) dp[i][j][0] = 1; } while(que.size()){ int x = que.front(); que.pop(); if(x == 0) continue; int px = par_[x]; ll cost = par_cost[x]; bitset<64> bi(cost); rep(i,60) if(bi[i]) swap(dp[x][i][0],dp[x][i][1]); rep(i,60){ ans += (1LL<<i) % MOD * dp[px][i][0] % MOD * dp[x][i][1] % MOD; ans += (1LL<<i) % MOD * dp[px][i][1] % MOD * dp[x][i][0] % MOD; ans %= MOD; } rep(i,60){ rep(j,2){ dp[px][i][j] += dp[x][i][j]; } } sons[px]--; if(sons[px]==0) que.push(px); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; #define pb push_back #define eb emplace_back #define mp make_pair #define fi first #define se second #define rep(i, n) rep2(i, 0, n) #define rep2(i, m, n) for (int i = m; i < (n); i++) #define per(i, b) per2(i, 0, b) #define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--) #define ALL(c) (c).begin(), (c).end() #define SZ(x) ((int)(x).size()) constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); } template <class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; } template <class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; } template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << "(" << p.first << "," << p.second << ")"; return os; } template <class T> ostream& operator<<(ostream& os, const vector<T>& v) { os << "{"; rep(i, v.size()) { if (i) os << ","; os << v[i]; } os << "}"; return os; } #ifdef LOCAL void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...); } #define debug(...) \ cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl #else #define debug(...) (void(0)) #define dump(x) (void(0)) #endif int main() { int N; cin >> N; V<int> A(N), B(N); int sz = N * 2; V<int> tp(sz), com(sz, -1); bool ng = false; rep(i, N) { cin >> A[i] >> B[i]; if (A[i] != -1) { --A[i]; if (tp[A[i]]) ng = true; tp[A[i]] = i + 1; } if (B[i] != -1) { --B[i]; if (tp[B[i]]) ng = true; tp[B[i]] = -(i + 1); } if (A[i] != -1 && B[i] != -1) { com[A[i]] = B[i]; com[B[i]] = A[i]; } } if (ng) { puts("No"); return 0; } V<bool> dp(sz + 1); dp[0] = true; rep(i, sz) { if (!dp[i]) continue; for (int j = i + 1; j < sz; ++j) { int w = j - i + 1; if (w & 1) continue; w /= 2; bool ok = true; V<bool> exist(N); rep(k, w) { int p = i + k, q = i + k + w; if (com[p] != -1 && !(i <= com[p] && com[p] <= j)) { ok = false; } if (com[q] != -1 && !(i <= com[q] && com[q] <= j)) { ok = false; } bool same = true; if (tp[p] != 0 && tp[q] != 0) { if (tp[p] < 0 || tp[p] + tp[q] != 0) { ok = false; } else same = true; } if (tp[p] < 0 || tp[q] > 0) { ok = false; } else { if (tp[p] != 0) { int v = tp[p] - 1; if (exist[v]) { ok = false; } exist[v] = true; } if (!same && tp[q] != 0) { int v = -tp[q] - 1; if (exist[v]) { ok = false; } exist[v] = true; } } } if (ok) { dp[j + 1] = true; } } } puts(dp[sz] ? "Yes" : "No"); return 0; }
#include <iostream> #include <vector> #include <algorithm> #include <cmath> using namespace std; const int RANGEMAX = 10000; struct record{ int id; int x; int y; int r; bool operator<(const record &other) const { return this->r < other.r; } bool operator>(const record &other) const { return this->r > other.r; } }; int input(vector<int> &x, vector<int> &y, vector<int> &r){ int n; cin >> n; x = vector<int>(n); y = vector<int>(n); r = vector<int>(n); for(int i = 0; i < n; i++) cin >> x[i] >> y[i] >> r[i]; return n; } void output(int n, const vector<int> &a, const vector<int> &b, const vector<int> &c, const vector<int> &d){ for(int i = 0; i < n; i++){ cout << a[i] << " " << b[i] << " " << c[i] << " " << d[i] << endl; } } // 入出力 AC Score: 823090 void solve001(int n, vector<int> x, vector<int> y, vector<int> r){ vector<vector<bool>> isused(RANGEMAX, vector<bool>(RANGEMAX, false)); vector<int> a(n, -1), b(n, -1), c(n, -1), d(n, -1); vector<record> data(n); for(int i = 0; i < n; i++){ data[i] = {i, x[i], y[i], r[i]}; } sort(data.begin(), data.end(), greater<record>()); for(int curind = 0; curind < n; curind++){ int id = data[curind].id; int oneSideLen = (int)sqrt(r[id]);// 1辺の長さ for(int i = x[id]; i < min(x[id]+oneSideLen, RANGEMAX); i++){ for(int j = y[id]; j < min(y[id]+oneSideLen, RANGEMAX); j++){ if(isused[i][j] && i > x[id] && j > y[id]){ a[id] = x[id]; b[id] = y[id]; c[id] = i-1; d[id] = j-1; goto EndMakeRectLoop; }else if(isused[i][j] && (i == x[id] && j == y[id])){ goto EndMakeRectLoop; } } } EndMakeRectLoop: if(a[id] != -1){ for(int i = a[id]; i < c[id]; i++){ for(int j = b[id]; j < d[id]; j++) isused[i][j] = true; } } } for(int curind = 0; curind < n; curind++){ if(a[curind] != -1) continue; for(int i = 0; i < RANGEMAX; i++){ for(int j = 0; j < RANGEMAX; j++){ if(!isused[i][j]){ isused[i][j] = true; a[curind] = i; b[curind] = j; c[curind] = i+1; d[curind] = j+1; goto EndMakeRectLoop2; } } } EndMakeRectLoop2: ; } output(n, a, b, c, d); } int main(){ int n; vector<int> x, y, r; n = input(x, y, r); solve001(n, x, y, r); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define REP(i, n) for(int i=0; i<(n); ++i) #define FOR(i, a, b) for(int i=(a); i<(b); ++i) #define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i) #define DEBUG(x) cout<<#x<<": "<<(x)<<'\n' #define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n' #define ALL(a) (a).begin(), (a).end() template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;} template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;} // constexpr ll MOD=1000000007ll; constexpr ll MOD=998244353ll; #define FIX(a) ((a)%MOD+MOD)%MOD const double EPS=1e-11; #define EQ0(x) (abs((x))<EPS) #define EQ(a, b) (abs((a)-(b))<EPS) int n, x[252], y[252], r[252]; int main(){ ios::sync_with_stdio(false); cin.tie(0); // cout<<setprecision(10)<<fixed; cin>>n; REP(i, n){ cin>>x[i]>>y[i]>>r[i]; } REP(i, n){ cout<<i*(10000/n)<<' '<<0<<' '<<(i+1)*(10000/n)<<' '<<10000<<'\n'; } return 0; }
#include<map> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #define N 600006 #define LL long long #define int long long using namespace std; int n,m; int a[N]; map<int,int>mp; LL ans; inline int qr() { char a=0;int w=1,x=0; while(a<'0'||a>'9'){if(a=='-')w=-1;a=getchar();} while(a<='9'&&a>='0'){x=(x<<3)+(x<<1)+(a^48);a=getchar();} return x*w; } signed main() { n=qr(); for(register int i=1;i<=n;i++) mp[a[i]=qr()]++; sort(a+1,a+n+1); for(register int i=1;i<=n;i++) { for(register int j=-205;j<=a[i];j++) ans+=(a[i]-j)*(a[i]-j)*mp[j]; } // for(register int i=-200;i<=200;i++) // for(register int j=i;j<=200;j++) // if(mp[i]&&mp[j]) // ans+=(LL)(j-i)*(j-i)*mp[i]*mp[j]; cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long using vec_int = vector<int>; using P = pair<int,int>; using T = tuple<int,int,int>; using ll = long long; #define rep(i, n) for(int i = 0; i < (int)(n); i++) int charToInt(char c){ char zero_num = '0'; return (int)c - (int)zero_num; } signed main(){ int N; cin>>N; vec_int A(N); rep(i,N)cin>>A.at(i); int ans = (int)pow(10,18); for(int i=0;i<(1<<(N-1));i++){ int temp = A.at(0); int temp_ans = 0; int a = 1; for(int j=1;j<N;j++){ if((i/a)%2==1){ temp_ans = temp_ans^temp; temp = A.at(j); }else{ temp = (temp | A.at(j)); } a *= 2; } temp_ans = temp_ans^temp; ans = min(temp_ans, ans); } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> // #include <boost/multiprecision/cpp_int.hpp> #define rep(i,a,b) for(ll i=a;i<b;i++) #define rrep(i,b,a) for(int i=b;i>=a;i--) #define fori(a) for(auto i : a ) #define all(a) begin(a), end(a) #define set(a,b) memset(a,b,sizeof(a)) #define sz(a) a.size() double pi=acos(-1); #define ll long long #define ull unsigned long long #define pb push_back #define PF push_front //deque // #define mp make_pair #define pq priority_queue const ll mod=1000000007; #define f first #define s second #define pii pair< ll, ll > #define vi vector<int> #define vpii vector<pii> #define debug(v) for(auto i:v) cout<<i<<" "; #define tc int t; cin >> t; while(t--) // using namespace boost::multiprecision; using namespace std; void optimizeIO(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } const int N=1000005; ll fact[N],invfact[N]; ll power(ll x,ll y){ if(y<=0) return 1LL; ll z=power(x,y/2); if(y%2) return (((z*z)%mod)*x)%mod; return (z*z)%mod; } void pre(){ fact[0]=invfact[0]=invfact[1]=fact[1]=1; rep(i,2,N) fact[i]=(i*fact[i-1])%mod; rep(i,2,N) invfact[i]=(invfact[i-1]*power(i,mod-2))%mod; } ll nCr(ll n,ll k){ return (((fact[n]*invfact[n-k])%mod)*invfact[k])%mod; } const int N1=1e6+1; vector<int> isprime(N1,1),prime; void seive(){ rep(i,2,sqrt(N1)+1){ if(isprime[i]){ for(int j=i*i;j<N1;j+=i) isprime[j]=0; prime.pb(i); } } rep(i,sqrt(N1)+1,N1) if(isprime[i]) prime.pb(i); } struct dsu { vector<int> par, rank; dsu(int n): par(n+1), rank(n+1) { for (int i = 0; i <= n; i++) { par[i] = i; rank[i]= 1; } } int root(int a) { if (a == par[a]) return a; return par[a] = root(par[a]); } void merge(int a, int b) { a = root(a); b = root(b); if (a == b) return; if (rank[a] > rank[b]) swap(a, b); par[b] = a; } set<int> parent(int n){ set<int> s; for(int i=1;i<=n;i++){ s.insert(root(i)); } return s; } }; void solve(){ int n; cin>>n; double x0,y0,xn2,yn2; cin>>x0>>y0>>xn2>>yn2; cout<<fixed<<setprecision(18); double theta= ((n-2.0))/(2.0*n); theta*=acos(-1); // cout<<theta<<endl; double v1=xn2-x0,v2=yn2-y0,v3,v4; v3=(v1+v2*tan(theta))*cos(theta)*cos(theta); v4=(-v1*tan(theta)+v2)*cos(theta)*cos(theta); // v3=(v3*v3)/(v1*v1),v4=(v4*v4)/(v2*v2); // cout<<v1<<" "<<v2<<endl; cout<<x0+v3<<" "<<y0+v4<<endl; } int main(){ optimizeIO(); int r=1; {solve();} }
#include <iostream> #include <stdio.h> #include <algorithm> #include <map> #include <cmath> #include <cstring> #include <stack> #include <queue> using namespace std; typedef long long LL; const LL LINF = 0x3f3f3f3f3f3f3f3f; const int INF = 0x3f3f3f3f; const double Pi = acos(-1.0); double N, a, b, c, d, e, f, A1, A2, A3, len; int main() { cin >> N >> a >> b >> c >> d; e = (a+c)/2.0; f = (b+d)/2.0; if (a != c) { A1 = atan((b-d)/(a-c)); } else { A1 = Pi / 2; } A2 = 2 * Pi / N; A3 = A1 + A2; len = sqrt((a-c)*(a-c) + (b-d)*(b-d)) / 2; if (a > c || (a == c && b > d)) A3 -= Pi; e -= len * cos(A3); f -= len * sin(A3); printf("%lf %lf", e, f); return 0; }
#include <vector> #include <list> #include <map> #include <set> #include <queue> #include <deque> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <ctime> #include <unordered_map> #include <unordered_set> using namespace std; #define x first #define y second #define all(v) v.begin(), v.end() #define compress(v) (sort(all(v)), v.erase(unique(all(v)), v.end())) typedef long long ll; typedef pair<ll, ll> p; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); ll X, Y; cin >> X >> Y; unordered_set<ll> visited; queue<p> q; q.push({ Y,0 }); ll ans = (ll)1e18; visited.insert(Y); while (!q.empty()) { p cur = q.front(); q.pop(); ll y = cur.x, cnt = cur.y; if (cnt >= ans) continue; if (y == X) { ans = min(ans, cnt); continue; } ans = min(ans, cnt + abs(y - X)); if (y < X) continue; if (y % 2 == 0) { if (visited.find(y / 2) == visited.end()) { q.push({ y / 2,cnt + 1 }); visited.insert(y / 2); } } else { if (visited.find(y + 1) == visited.end()) { q.push({ y + 1,cnt + 1 }); visited.insert(y + 1); } if (visited.find(y - 1) == visited.end()) { q.push({ y - 1,cnt + 1 }); visited.insert(y - 1); } } } cout << ans; }
#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; signed main(){ ll X, Y; cin >> X >> Y; if (Y <= X) { cout << X - Y << endl; return 0; } unordered_map<ll, ll> memo; auto dfs = [&](auto&& self, ll current) -> ll { if (memo.find(current) != memo.end()) return memo[current]; ll minCost = abs(current - X); if (X < current) { for (const int add : {1, -1}) { ll costDiff = 0, next = current; while (next % 2 != 0) { next += add; costDiff++; } next /= 2; costDiff++; assert(next < current); minCost = min(minCost, self(self, next) + costDiff); } } return memo[current] = minCost; }; cout << dfs(dfs, Y) << endl; }
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <numeric> #include <cmath> #include <iomanip> #include <cstdio> #include <set> #include <map> #include <unordered_map> #include <unordered_set> #include <list> #include <cstdlib> #include <queue> #include <stack> #include <bitset> using namespace std; #define MOD 1000000007 #define PI 3.1415926535897932 #define INF 1e9 #define rep(i, n) for (int i = 0; i < n; i++) #define repe(i, j, n) for (int i = j; i < n; i++) #define repi(i, n) for (int i = 0; i <= n; i++) #define repie(i, j, n) for (int i = j; i <= n; i++) #define all(x) x.begin(), x.end() #define println() cout << endl #define P pair<int, int> #define fi first #define se second typedef long long ll; using Graph = vector<vector<ll>>; long long modinv(long long a, long long m) { long long b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } ll dp[2000][2000]; ll nCr(ll n, ll r) { if(n==r) return dp[n][r] = 1; if(r==0) return dp[n][r] = 1; if(r==1) return dp[n][r] = n%MOD; if(dp[n][r]) return dp[n][r]%MOD; return dp[n][r] = nCr(n-1,r)%MOD + nCr(n-1,r-1)%MOD; } ll H(ll n, ll r) { return nCr(n+r-1, r)%MOD; } int prime[10000000]; bool is_prime[100000000 + 1]; int sieve(int n) { int pcnt = 0; for(int i = 0; i <= n; i++) { is_prime[i] = true; } is_prime[0] = is_prime[1] = false; for(int i = 2; i <= n; i++) { if(is_prime[i]) { prime[pcnt++] = i; for(int j = 2*i; j <= n; j += i) { is_prime[j] = false; } } } return pcnt; } struct UnionFind { //自身が親であれば、その集合に属する頂点数に-1を掛けたもの //そうでなければ親のid vector<ll> r; UnionFind(ll N) { r = vector<ll>(N, -1); } ll root(ll x) { if (r[x] < 0) return x; return r[x] = root(r[x]); } bool unite(ll x, ll y) { x = root(x); y = root(y); if (x == y) return false; if (r[x] > r[y]) swap(x, y); r[x] += r[y]; r[y] = x; return true; } ll size(ll x) { return -r[root(x)]; } bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す ll rx = root(x); ll ry = root(y); return rx == ry; } }; void solve1() { ll n; cin >> n; vector<ll> a(n), b(n); rep(i, n) { cin >> a[i] >> b[i]; } ll ans = 1e18; rep(i, n) { ans = min(ans, a[i]+b[i]); } for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { if(i != j) ans = min(ans, max(a[i],b[j])); } } cout << ans << endl; } int main() { solve1(); }
//#pragma GCC optimize ("O3") //#pragma GCC target ("sse4") //#pragma GCC optimize("Ofast") //#pragma GCC optimize("Ofast,unroll-loops") //#pragma GCC target("avx,avx2,fma") #include <algorithm> #include <array> #include <cassert> #include <chrono> #include <cmath> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <vector> using namespace std; #define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> //using namespace __gnu_pbds; #define int long long #define ll int #define all(a) a.begin(),a.end() #define rev(a) a.rbegin(),a.rend() //typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; //less_equal for multiset #define ar array #define pb push_back #define fi(a,b) for(int i=a;i<(b);i++) #define fj(a,b) for(int j=a;j<(b);j++) #define fk(a,b) for(int k=a;k<(b);k++) const double pi=acosl(-1); void solve() { int n; cin>>n; vector<pair<int,int>> a(n); int ans=1e15; fi(0,n){ cin>>a[i].first>>a[i].second; } fi(0,n) { fj(0,n) { if(i==j) { ans=min(ans,a[i].first+a[j].second); } else { ans=min(ans,max(a[i].first,a[j].second)); } } } cout<<ans<<'\n'; } signed main() { FAST; int tt=1; //cin>>tt; while(tt--) { solve(); } } //int dx[] = {+1,-1,+0,+0,-1,-1,+1,+1}; // Eight Directions //int dy[] = {+0,+0,+1,-1,+1,-1,-1,+1}; // Eight Directions //int dx[]= {-2,-2,-1,1,-1,1,2,2}; // Knight moves //int dy[]= {1,-1,-2,-2,2,2,-1,1}; // Knight moves // For (a^b)%mod, where b is large, replace b by b%(mod-1). // a+b = (a|b)+(a&b) // a+b = 2*(a&b)+(a^b)
#include<ctime> #include<cmath> #include<cstdio> #include<cctype> #include<algorithm> #define ll long long using namespace std; const double k=(sqrt(5)-1)/2; const double t=k; ll read(){ char c; ll x=0,f=1; while(!isdigit(c=getchar())) f-=2*(c=='-'); while(isdigit(c)){ x=x*10+f*(c-48); c=getchar(); } return x; } ll n,x,y,cnt,ans[1000]; void solve(){ if(n==1){ puts("1"); puts("1"); return; } ans[1]=3; for(ll i=max(0ll,(ll)(k*n-1000000));i<=min(n,(ll)(k*n+1000000));++i){ x=i; cnt=1; y=n-x; while(x>=1&&y>=1){ if(cnt>130) break; if(x>y){ ans[++cnt]=3; x-=y; } else{ ans[++cnt]=4; y-=x; } } while(x){ if(cnt>130) break; --x; ans[++cnt]=1; } while(y){ if(cnt>130) break; --y; ans[++cnt]=2; } if(cnt<=130) break; } printf("%lld\n",cnt); for(ll i=cnt;i;--i) printf("%lld\n",ans[i]); } int main(){ #ifndef ONLINE_JUDGE freopen("C.in","r",stdin); freopen("C.out","w",stdout); #endif clock_t t1=clock(); //-------- n=read(); solve(); //-------- fprintf(stderr,"%0.3lfs",1.0*(clock()-t1)/CLOCKS_PER_SEC); return 0; }
#include <cmath> #include <cstdio> #include <stack> using namespace std; int main() { long long N; scanf("%lld", &N); stack<int> ans; long long x, y; x = N; __float128 phi = (1 + sqrtf128((__float128)5)) / 2; y = (long long)(x / phi) + 1; for (; x != 0 || y != 0;) { if (y == 0) { ans.push(1); x--; } else if (x == 0) { ans.push(2); x--; } else if (x > y) { if ((y - 1) * phi > x) { ans.push(2); y--; } else { ans.push(3); x -= y; } } else { if ((x - 1) * phi > y) { ans.push(1); x--; } else { ans.push(4); y -= x; } } } printf("%lu\n", ans.size()); x = 0; y = 0; for (; !ans.empty();) { printf("%d\n", ans.top()); if (ans.top() == 1) x++; if (ans.top() == 2) y++; if (ans.top() == 3) x += y; if (ans.top() == 4) y += x; ans.pop(); } fprintf(stderr, "%lld\n", x); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> P; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const int INF = (1<<30)-1; const int MOD = 1e9+7; const ll LINF = (1ll<<62)-1; #define REP(i,n) for(int i=0;i<(n);++i) #define COUT(x) cout<<(x)<<"\n" #define COUT16(x) cout << fixed << setprecision(16) << (x) << "\n"; int main(){ int n;cin >> n; if(floor(n*1.08)<206)COUT("Yay!"); else if(floor(n*1.08)==206)COUT("so-so"); else COUT(":("); }
/* これを入れて実行 g++ code.cpp ./a.out */ #include <iostream> #include <cstdio> #include <stdio.h> #include <vector> #include <string> #include <cstring> #include <queue> #include <deque> #include <stack> #include <algorithm> #include <utility> #include <set> #include <map> #include <unordered_map> #include <unordered_set> #include <cmath> #include <math.h> #include <tuple> #include <iomanip> #include <bitset> #include <functional> #include <cassert> #include <random> #define all(x) (x).begin(),(x).end() #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; typedef long long ll; typedef long double ld; int dy4[4] = {-1, 0, +1, 0}; int dx4[4] = {0, +1, 0, -1}; int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1}; const long long INF = 1LL << 61; const ll MOD = 1e9 + 7; bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){ return f.second > s.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 / gcd(a, b) * b; } ll conbinationMemo[201][12]; void cmemoInit(){ rep(i, 201){ rep(j, 12){ conbinationMemo[i][j] = -1; } } } ll nCr(ll n, ll r){ if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r]; if(r == 0 || r == n){ return 1; } else if(r == 1){ return n; } return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1)); } ll nPr(ll n, ll r){ r = n - r; ll ret = 1; for (ll i = n; i >= r + 1; i--) ret *= i; return ret; } //-----------------------ここから----------- ll n; vector<string> s; vector<set<ll>> parents; int main(void){ cin >> n; s.resize(n); vector<string> rs(n, string(n, '0')); rep(i, n) cin >> s[i]; rep(i, n){ rep(j, n){ if(s[i][j] == '1'){ rs[j][i] = '1'; } } } parents.resize(n); rep(i, n){ queue<ll> q; vector<ll> visited(n, 0); visited[i] = 1; q.push(i); parents[i].insert(i); while(!q.empty()){ ll now = q.front(); q.pop(); rep(j, n){ if(visited[j]) continue; if(rs[now][j] == '1'){ parents[i].insert(j); visited[j] = 1; q.push(j); } } } } ld ans = 0; rep(i, n){ ans += 1.0 / (ld)parents[i].size(); } cout << fixed << setprecision(10) << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define int long long signed main(){ cin.tie(nullptr)->sync_with_stdio(false); int t,n; cin >> t >> n; vector<int>arr; set<int>s; set<int>mods; int cur = 100+t; while(true){ if(s.find(cur/100-1)==s.end()&&cur!=100+t){ arr.push_back(cur/100-1); } if(cur%100==t&&cur!=100+t)break; s.insert(cur/100); cur+=100+t; } int repeat = (cur-100-t)/100; n--; for(int i = 0; i<arr.size(); i++){ if(n%arr.size()==i){ //cout << i << "\n"; //cout << arr[i] << "\n"; cout << repeat*(n/arr.size())+arr[i] << "\n"; return 0; } } return 0; }
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < n; ++i) #define REPR(i, n) for (int i = n - 1; i >= 0; --i) #define FOR(i, a, b) for (int i = a; i < b; ++i) #define FORR(i, a, b) for (int i = b - 1; i >= a; --i) #define SORT(v) sort(v.begin(), v.end()) #define SORTR(v) sort(v.rbegin(), v.rend()) #define REV(v) reverse(v.begin(), v.end()) #define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr) #define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin()) #define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin()) #define SZ(v) (int)v.size() using namespace std; using ll = long long; using P = pair<int, int>; class Main { int H, W; vector<string> S; void input() { cin >> H >> W; S.resize(H); REP(i, H) { cin >> S[i]; } } void output() { int res = 0; REP(i, H) { REP(j, W) { if (S[i][j] == '#') continue; if (i < H - 1) { if (S[i + 1][j] == '.') ++res; } if (j < W - 1) { if (S[i][j + 1] == '.') ++res; } } } cout << res << endl; } public: Main() { input(); output(); } }; int main() { cin.tie(0); ios::sync_with_stdio(false); Main(); return 0; }
#ifdef __GNUC__ #pragma GCC diagnostic ignored "-Wunused-result" #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #endif #include <algorithm> #include <cmath> #include <cstring> #include <cctype> #include <iostream> #include <sstream> #include <numeric> #include <map> #include <set> #include <queue> #include <vector> using namespace std; typedef long long LL; typedef long double LD; typedef pair<LL, LL> II; typedef pair<LL, II> III; typedef priority_queue<III, vector<III>, greater<>> Queue; static const LL INF = 1LL << 60; void solve(long long N, long long M, std::vector<long long>& w, std::vector<long long>& l, std::vector<long long>& v) { LL max_w = *max_element(w.begin(), w.end()); LL min_allow = *min_element(v.begin(), v.end()); if (max_w > min_allow) { cout << -1 << endl; return; } // if (min_allow >= accumulate(w.begin(), w.end(), 0LL)) { // cout << 0 << endl; // return; // } vector<II> vv; for (int i = 0; i < M; ++i) { vv.emplace_back(II(l[i], v[i])); } sort(vv.begin(), vv.end()); map<LL, LL> m; m[0] = 0; LL mn = INF; for (LL i = M - 1; i >= 0; --i) { if (vv[i].second < mn) { mn = vv[i].second; m[mn] = vv[i].first; } } sort(w.rbegin(), w.rend()); vector<int> seq(N); iota(seq.begin(), seq.end(), 0); LL ans = INF; do { vector<vector<LL>> dist(N, vector<LL>(N)); vector<LL> pos(N); for (LL i = 1; i < N; ++i) { LL tot_w = w[seq[i]]; for (LL j = i - 1; j >= 0; --j) { tot_w += w[seq[j]]; auto x = m.lower_bound(tot_w); if (x == m.end()) --x; if (tot_w <= x->first) --x; dist[i][j] = dist[j][i] = -x->second; } } // Bellman-Ford vector<LL> costs(N); costs[0] = 0; for (int k = 0; k < N; ++k) { bool changed = false; for (int i = 0; i < N; ++i) { for (int j = i + 1; j < N; ++j) { LL cost = costs[i] + dist[i][j]; if (costs[j] > cost) { changed = true; costs[j] = cost; } } } if (!changed) break; } ans = min(ans, -costs[N - 1]); } while (next_permutation(seq.begin() + 1, seq.end())); cout << ans << endl; } int main() { long long N, M; std::cin >> N >> M; std::vector<long long> w(N), l(M), v(M); for (int i = 0; i < N; i++) { std::cin >> w[i]; } for (int i = 0; i < M; i++) { std::cin >> l[i] >> v[i]; } solve(N, M, w, l, v); return 0; }
#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 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; // Editorial AC int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(15); ll N, M; cin >> N >> M; VLL w(N); REP(i,N) cin >> w[i]; VLL l(M),v(M); REP(i,M) cin >> l[i] >> v[i]; if (MAX(w) > MIN(v)) { COUT(-1); return 0; } VLL X(1<<N); REP(S,1<<N) if (PCNT(S) >= 2) { ll W = 0; REP(i,N) if (BIT(S,i)) W += w[i]; REP(i,M) if (v[i] < W) chmax(X[S], l[i]); } ll ans = INF; VLL A(N); iota(ALL(A),0); VLL dp(N); do { fill(ALL(dp), 0); REP(s,N-1) { ll u1 = A[s]; ll S = (1<<u1); FOR(t,s+1,N) { ll u2 = A[t]; S |= (1<<u2); chmax(dp[t], dp[s] + X[S]); } } chmin(ans, dp[N-1]); } while (next_permutation(ALL(A))); assert(ans != INF); COUT(ans); return 0; }
#include "bits/stdc++.h" using namespace std; int main() { string s; cin >>s; reverse(s.begin(),s.end()); for(const auto c:s) { if(c=='6') { cout<<"9"; } else if(c=='9') { cout<<"6"; }else{ cout<<c; } } }
#include <bits/stdc++.h> using namespace std; #define SZ(x) (int)(x).size() #define REP(i,n) for(int i=0;i<(n);i++) #define FOR(i,a,b) for(int i=(a);i<(b);i++) #define REPR(i,n) for(int i=(n)-1;i>=0;i--) #define ALL(s) (s).begin(), (s).end() #define so(V) sort(ALL(V)) #define rev(V) reverse(ALL(V)) #define uni(v) v.erase( unique(ALL(v)) , v.end()); typedef long long unsigned int llu; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<bool> vb; typedef vector<vi> vvi; const double EPS = 1e-9; const int MOD = 1e9 + 7; const int INF = (1 << 29); const ll LINF = 1e18; const double PI = acos(-1); template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template<typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T& t, const V& v) { t = v; } template<typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T& t, const V& v) { for (auto& e : t) fill_v(e, v); } template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template<class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return 1; } return 0; } int main() { cin.tie(0); ios::sync_with_stdio(false); string S; cin >> S; map<char, char> M; M['0'] = '0'; M['1'] = '1'; M['6'] = '9'; M['8'] = '8'; M['9'] = '6'; REPR(i, SZ(S)) { cout << M[S[i]]; } cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define endl "\n" #define IOS \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define int long long #define ld long double #define ff first #define ss second #define BS binary_search #define all(c) (c).begin(), (c).end() #define sz(x) (int)(x).size() #define get(a, t) get<a>(t) typedef long long LL; typedef pair<int, int> pii; typedef pair<LL, LL> pll; typedef pair<string, string> pss; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<pii> vii; typedef vector<LL> vl; typedef vector<vl> vvl; double EPS = 1e-9; double PI = acos(-1); int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1}; int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1}; #ifdef TESTING #define DEBUG fprintf(stderr, "====TESTING====\n") #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl #define debug(...) fprintf(stderr, __VA_ARGS__) #else #define VALUE(x) #define debug(...) #endif #define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a)) #define FORN(a, b, c) for (int(a) = (b); (a) <= (c); ++(a)) #define FORD(a, b, c) for (int(a) = (b); (a) >= (c); --(a)) #define FORSQ(a, b, c) for (int(a) = (b); (a) * (a) <= (c); ++(a)) #define FORC(a, b, c) for (char(a) = (b); (a) <= (c); ++(a)) #define FOREACH(a, b) for (auto &(a) : (b)) #define REP(i, n) FOR(i, 0, n) #define REPN(i, n) FORN(i, 1, n) #define MAX(a, b) a = max(a, b) #define MIN(a, b) a = min(a, b) #define SQR(x) ((LL)(x) * (x)) #define RESET(a, b) memset(a, b, sizeof(a)) #define mp make_pair #define pb push_back #define ALL(v) v.begin(), v.end() #define ALLA(arr, sz) arr, arr + sz #define SIZE(v) (int)v.size() #define SORT(v) sort(ALL(v)) #define REVERSE(v) reverse(ALL(v)) #define SORTA(arr, sz) sort(ALLA(arr, sz)) #define REVERSEA(arr, sz) reverse(ALLA(arr, sz)) #define PERMUTE next_permutation const int INF = 1e18; const int N = 100005; int mod = 1e9 + 7; void solve() { string s; cin >> s; if (s[1] == s[0] && s[1] == s[2]) { cout << "Won" << endl; } else { cout << "Lost" << endl; } } int32_t main() { IOS; //int t;cin >> t; int t = 1; for (int tc = 1; tc <= t; tc++) { //cout<<"Case #"<<tc<<": "; solve(); } return 0; }
#include<bits/stdc++.h> #define ls(p) p<<1 #define rs(p) p<<1|1 #define de(x) cout<<#x<<" = "<<x<<endl; #define rep(i,a,b) for(int i = (a);i<=(b);++i) #define endl '\n' #define PI acos(-1.0) #define pb push_back using namespace std; void debug(){freopen("data.in","r",stdin);freopen("data.out","w",stdout);} typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; const int maxn = 1e5+10; int main(){ //debug(); int v,t,s,d; cin>>v>>t>>s>>d; if(d < t * v || d > v * s) cout<<"Yes\n"; else cout<<"No\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ long long N; cin >> N; vector<long long> A(N); for(int i = 0; i < N;i++){ long long a = 0; cin >> a; A.at(i) = a; } sort(A.begin(), A.end()); reverse(A.begin(),A.end()); long long ans =0; for(int i = 0; i < N ;i++){ ans += A.at(i)*((N-1)-2*i); } cout << ans <<endl; }
///Bismillahir Rahmanir Rahim #include<bits/stdc++.h> using namespace std; #define FAST ios_base::sync_with_stdio(false);cin.tie(NULL) #define int long long #define pb push_back #define pp pop_back #define mp make_pair #define pi 2*acos(0.0) #define scan(i) scanf("%lld",&i) #define scann(i,j) scanf("%lld%lld",&i,&j) #define print(i) printf("%lld\n",i) #define printt(i,j) printf("%lld %lld\n",i,j) #define loop(i,n) for(int i = 0 ; i <n ; i++) #define loopp(i,n) for(int i = 1 ; i <n ; i++) #define rep(i,n) for(int i=n-1;i>=0;i--) #define rev(v) reverse(v.begin(),v.end()) #define reset(a,b) memset(a,b,sizeof(a)) #define vect vector<int> #define vec_it vector<int>::reverse_iterator vi #define sorta(v) sort(v.begin(),v.end()) #define sortd(v) sort(v.begin(),v.end(),greater<>()) #define sorted(v) is_sorted(v.begin(),v.end()) #define mapp map<int,int> #define rmap map<int,int,greater<>>m #define pairr pair<int,int> #define sett set<int> #define rset set<int,greater<>>s #define set_it set<int>::reverse_iterator si #define map_it map<int,int> :: reverse_iterator mi #define digit(n) floor(log10(n)+1) #define yes cout<<"Yes"<<endl #define no cout<<"No"<<endl #define ff first #define ss second #define mx INT_MAX #define lmx LLONG_MAX #define mn INT_MIN #define lmn LLONG_MIN #define inf 0x3f3f3f3f #define inff 10e18 #define GCD __gcd(a,b) #define LCM (a/GCD)*b template <typename T> T gcd(T a,T b){return (b==0)?a:gcd(b,a%b);} template <typename T> T lcm(T a,T b) {return a*(b/gcd(a,b));} int modulo (int a, int b) { return a >= 0 ? a % b : ( b - abs ( a%b ) ) % b; } void solve() { // freopen ("(input).txt" , "r", stdin) ; string st,stt; int low=0,high=0; int l,r; char ch; int n,k,t,x,y,z,d=0,cnt=0,temp=0,sum=0,f=0,flag=0; cin>>n ; vect v(n) ,a ; sett s ; mapp m,mm ; pairr p ; loop(i,n) cin>>v[i]; sorta(v); int dp[n+1]; dp[0]=0; for(int i=1;i<n;i++) { dp[i]=(v[i]-v[i-1])*i+dp[i-1]; sum+=dp[i]; } cout<<sum<<endl; } main() { int t; // cin>>t; // while(t--) solve(); }
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N=2e5+5; int res=INT_MIN,a[N],mark[N],m,n; vector<int> adj[N]; void dfs(int u){ for(int v: adj[u]){ if(mark[v]==INT_MIN)dfs(v); mark[u]=max(mark[u],mark[v]); res = max(res,mark[u]-a[u]); } mark[u]=max(a[u],mark[u]); } int main() { scanf("%d%d",&n,&m); for(int i=1;i<=n;++i){ scanf("%d",&a[i]); mark[i]=INT_MIN; } while(m--){ int u,v; scanf("%d%d",&u,&v); adj[u].push_back(v); } for(int i=1;i<=n;++i)if(mark[i]==INT_MIN){ dfs(i); } cout << res; }
#include <bits/stdc++.h> #define speedup ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr),cout.precision(12) using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_map; #define sbc __builtin_popcount #define pb push_back #define pbk pop_back #define em emplace #define emb emplace_back #define ff first #define ss second #define ll long long const ll mod = 1e9 + 7; template<typename T> void smax(T& a, T b) { if(a<b) a=b; } template<typename T> void smin(T& a, T b) { if(a>b) a=b; } template<typename T> T pw(T a,T b) { T p=1,one=1; while(b) { if(b&one) p=p*a; a=a*a; b >>=1; } return p; } template<typename T> T pwm(T a,T b,T md=mod) { T p=1,one=1; while(b) { if(b&one) p=p*a%md; a=a*a%md; b >>=1; } return p; } template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &it:v) is >> it; return is; } template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &it) { os << it.first << ' ' << it.second; return os; } template <typename T> ostream &operator<<(ostream &os, const array<T, 2> &v) { for (auto &it : v) os << it << ' '; return os; } template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &it : v) os << it << ' '; return os; } #ifndef ONLINE_JUDGE class Timer { chrono::high_resolution_clock::time_point start_t, end_t; public: Timer() { start_t=chrono::high_resolution_clock::now(); } ~Timer() { end_t = chrono::high_resolution_clock::now(); auto duration = chrono::duration_cast<chrono::milliseconds>(end_t-start_t); cerr<<"\nRunTime: "<<duration.count()<<"ms"<<'\n'; } }; void debug() { cerr << '\n'; } template<typename T, typename... Args> void debug(T print, Args... args) { cerr << ' ' << print; debug(args...); } #define deb(...) cerr << "[" << #__VA_ARGS__ << "]" << " --> ", debug(__VA_ARGS__) #else #define deb(...) void(0) #endif void solve() { int n,m; cin>>n>>m; vector<vector<int>> g(n); int a[n],mx[n]; for(int i=0;i<n;++i) { cin>>a[i]; mx[i]=-1; } for(int i=0,x,y;i<m;++i) { cin>>x>>y, --x, --y; g[y].pb(x); } for(int i=0;i<n;++i) deb(a[i]),deb(g[i]); int ans=INT_MIN; for(int i=n-1;~i;--i) { int val=a[i]; if(~mx[i]) { smax(val,mx[i]); smax(ans,mx[i]-a[i]); } for(const auto& j:g[i]) smax(mx[j], val); } cout<<ans<<'\n'; } int main() { speedup; //int t; cin >> t; while (t--) solve(); } /**Vim * * * * * * * * */
#include <bits/stdc++.h> #define rep(i, n) for(int i = 0; i < (n); i++) #define rep2(i, x, n) for(int i = x; i < (n); i++) using namespace std; using ll = long long; int main() { int N; string S; cin >> N >> S; int ans = 0; for(int i = 0; i < N - 1; i++) { int a = 0, t = 0, g = 0, c = 0; switch(S[i]) { case 'A': a++; break; case 'T': t++; break; case 'G': g++; break; case 'C': c++; break; } for(int j = i + 1; j < N; j++) { switch(S[j]) { case 'A': a++; break; case 'T': t++; break; case 'G': g++; break; case 'C': c++; break; } if(a == t && g == c) ans++; } } cout << ans << endl; return 0; }
#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <cassert> #include <algorithm> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> #define repi(i,a,b) for(ll i=(a);i<(b);++i) #define rep(i,a) repi(i,0,a) #define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i) #define repd(i,a) repdi(i,a,0) #define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it ) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define endl '\n' #define debug(x) std::cerr << #x << " = " << (x) << endl; using ll = long long; using P = std::pair<ll, ll>; constexpr ll INF = 1ll<<60; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template<class S, class T> std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a ) { std::cout << '(' << a.first << ", " << a.second << ')'; return out; } template<class T> std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a ) { std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; } const ll mod = 1000000007; struct mint { ll x; // typedef long long ll; mint(ll x=0):x((x%mod+mod)%mod){} mint operator-() const { return mint(-x);} mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;} mint operator+(const mint a) const { return mint(*this) += a;} mint operator-(const mint a) const { return mint(*this) -= a;} mint operator*(const mint a) const { return mint(*this) *= a;} mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod-2);} mint& operator/=(const mint a) { return *this *= a.inv();} mint operator/(const mint a) const { return mint(*this) /= a;} }; std::istream& operator>>(std::istream& is, mint& a) { return is >> a.x;} std::ostream& operator<<(std::ostream& os, const mint& a) { return os << a.x;} struct combination { std::vector<mint> fact, ifact; combination(int n):fact(n+1),ifact(n+1) { assert(n < mod); fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i; ifact[n] = fact[n].inv(); for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i; } mint operator()(int n, int k) { if (k < 0 || k > n) return 0; return fact[n]*ifact[k]*ifact[n-k]; } }; std::string n; ll K; ll dig( char ch ) { if( ch >= '0' && ch <= '9' ) return ch-'0'; else return ch-'A'+10; } combination comb( 200010 ); mint inc[20][200010], po[20][200010]; int main() { std::cin >> n >> K; ll N = n.size(); rep( i, 20 ) { po[i][0] = 1; rep( j, N+5 ) po[i][j+1] = po[i][j]*i; } rep( a, K+1 ) rep( b, N+1 ) { /*mint sign = 1; repi( k, K-a, 16-a+1 ) { inc[a][b] += sign*comb(b,k)*comb(16-a,k)*po[16][b-k]; sign *= -1; }*/ repi( k, a, K+1 ) { inc[a][b] += comb(K-a, k-a)*po[k][b]*((K-k)&1 ? -1 : 1); } inc[a][b] *= comb(16-a, K-a); } ll bit = 0; mint ans = 0; rep( i, N ) { ll x = dig(n[i]); ll k = __builtin_popcountll(bit&((1ll<<x)-1)); ll l = __builtin_popcountll(bit); bit |= 1ll<<x; if( !i ) { --x; if( bit&1 ) --k; } ans += inc[l][N-i-1]*k; ans += inc[l+1][N-i-1]*(x-k); if( i ) ans += inc[1][i-1]*15; } if( __builtin_popcountll(bit) == K ) ans += 1; std::cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define repx(i, x, n) for (ll i = (ll)(x); i < (ll)(n); i++) #define repr(i, n) for (ll i = ((ll)(n)-1); i >= 0; i--) #define reprx(i, x, n) for (ll i = ((ll)(n)-1); i >= (ll)(x); i--) #define all(x) (x).begin(),(x).end() #define sz(x) ((ll)(x).size()) #define submit(x) {cout<<x<<endl; return 0;} #define X first #define Y second template<class T> using V = vector<T>; template<class T> using VV = V<V<T>>; template<class T>bool chmax(T &a,T b) {if (a<b) {a=b; return 1;} return 0;} template<class T>bool chmin(T &a,T b) {if (b<a) {a=b; return 1;} return 0;} template<class T>long long ip(T a, T b) {bitset<60> s(b); long long val=1; for(int i=0;i<60;i++){if(s.test(i))val*=a; a*=a;} return val;} using ll = long long; using P = pair<ll, ll>; const ll INF = 1LL << 60; const double PI = 3.1415926535897932; ll n; VV<ll> par; bool solve(ll mid) { set<ll> s; rep(i,n) { ll tmp = 0; rep(j,5) { if (par[i][j] >= mid) tmp += (1<<j); } s.insert(tmp); } for (auto x : s) for (auto y : s) for (auto z : s) { if ((x | y | z) == 31) return true; } return false; } int main() { cin>>n; par.assign(n,V<ll>(5)); rep(i,n) rep(j,5) cin>>par[i][j]; ll right = 1000000001; ll left = 0; ll mid = (right + left) / 2; while (right - left > 1) { if (solve(mid)) left = mid; else right = mid; mid = (right + left) / 2; } submit(left) }
#include <bits/stdc++.h> #include <math.h> using namespace std; typedef long long ll; typedef unsigned long long ull; # define M_PI 3.14159265358979323846 const int M=1e9+7; long long mod(long long x){ return ((x%M + M)%M); } long long add(long long a, long long b){ return mod(mod(a)+mod(b)); } long long mul(long long a, long long b){ return mod(mod(a)*mod(b)); } ll modPow(ll a, ll b){ if(b==0) return 1LL; if(b==1) return a%M; ll res=1; while(b){ if(b%2==1) res=mul(res,a); a=mul(a,a); b=b/2; } return res; } void solve (){ ll n; cin>>n; n=2*n; ll ans=0; for(ll i=1;i*i<=n;i++){ if(n%i==0){ ll f1=i; ll f2=n/i; if((f2+1-f1)%2==0) ans++; if(n/i != i){ ll f1=n/i; ll f2=i; if((f2+1-f1)%2==0) ans++; } } } cout<<ans; } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout<<fixed; cout<<setprecision(10); // freopen("timber_input.txt", "r", stdin); // freopen("timber_output.txt", "w", stdout); int t=1; // cin>>t; for(int i=1;i<=t;i++){ // cout<<"Case #"<<i<<": "; solve(); } return 0; }
#include <iostream> #include <vector> #include <algorithm> #include <iomanip> #include <cmath> #include <set> #include <map> #include <stack> #include <queue> #define ll long long #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define P pair<ll, ll> using namespace std; int main(){ int n; cin >> n; vector<vector<P> > v(n + 1); vector<P> v2(n + 1, P(1e18, -1e18)); rep(i, n){ ll x, c; cin >> x >> c; v2[c].first = min(v2[c].first, x); v2[c].second = max(v2[c].second, x); } rep(i, n){ if(v2[i + 1].first == 1e18) continue; v[i + 1].push_back(P(v2[i + 1].first, 1e18)); v[i + 1].push_back(P(v2[i + 1].second, 1e18)); } v[0].push_back(P(0, 0)); for(int i = 0; i < n; i++){ // cout << i << endl; if(v[i + 1].size() == 0){ v[i + 1] = v[i]; continue; } for(auto& now: v[i]){ ll nowx = now.first, nowv = now.second; ll l = v[i + 1][0].first, r = v[i + 1][v[i + 1].size() - 1].first; for(auto& next: v[i + 1]){ ll nextx = next.first; ll nextv = nowv; if(nowx < l){ nextv += r - nowx + r - nextx; } else if(nowx > r){ nextv += nowx - l + nextx - l; } else{ nextv += r - l; if(nextx < nowx){ nextv += abs(r - nowx) + abs(l - nextx); } else{ nextv += abs(l - nowx) + abs(r - nextx); } } next.second = min(next.second, nextv); } } // cout << "------" << i+1 << "-------" << endl; // for(auto& e: v[i+1]){ // cout << e.first << " , " << e.second << endl; // } } ll ans = 1e18; for(auto& e: v[n]){ ans = min(ans, e.second + abs(e.first)); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<pair <int, int>, null_type,less<pair <int, int>>, rb_tree_tag,tree_order_statistics_node_update> const int MAXN = 3e5 + 20, MAXM = 16e4 + 5, MOD = 1e9 + 7, SQ = 450; const long long INF = 1e9 + 10; int l[MAXN], r[MAXN]; long long dp[MAXN][2]; void solve() { int n; cin >> n; for (int i = 1; i <= n; i++) { l[i] = INF; r[i] = -INF; } vector <int> id; l[0] = 0; r[0] = 0; l[n + 1] = 0; r[n + 1] = 0; id.push_back(0); id.push_back(n + 1); for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; l[y] = min(x, l[y]); r[y] = max(x, r[y]); id.push_back(y); } sort(id.begin(), id.end()); id.resize(unique(id.begin(), id.end()) - id.begin()); int t = id.size(); dp[0][0] = 0; dp[0][1] = 0; for (int i = 1; i < id.size(); i++) { dp[i][0] = dp[i - 1][1] + abs(r[id[i - 1]] - r[id[i]]) + abs(r[id[i]] - l[id[i]]); dp[i][0] = min(dp[i - 1][0] + abs(l[id[i - 1]] - r[id[i]]) + abs(r[id[i]] - l[id[i]]), dp[i][0]); dp[i][1] = dp[i - 1][1] + abs(r[id[i - 1]] - l[id[i]]) + abs(r[id[i]] - l[id[i]]); dp[i][1] = min(dp[i - 1][0] + abs(l[id[i - 1]] - l[id[i]]) + abs(r[id[i]] - l[id[i]]), dp[i][1]); } cout << min(dp[t - 1][0], dp[t - 1][1]) << endl; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int q = 1; // cin >> q; while (q--) { solve(); } }
#define _USE_MATH_DEFINES #include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <ctime> #include <complex> #include <deque> #include <functional> #include <iostream> #include <list> #include <map> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> #include <queue> #define INF 1010101010LL #define INFLL 1010101010101010101LL using namespace std; //const int mod = 1000000007; //const int mod = 998244353; class BIT { public: BIT(int n) : a(n) {} void add(int p, long long num) { while (p < a.size()) { a[p] += num; p |= p + 1; } } /* i から j までの和 [i, j] */ long long sum(int i, int j) { long long s = 0, t = 0; i--; while (i >= 0) { s += a[i]; i = (i & (i + 1)) - 1; } while (j >= 0) { t += a[j]; j = (j & (j + 1)) - 1; } return t - s; } private: vector<long long> a; }; vector<int> compress_num, compressed_num; int find_comp(int x) { return lower_bound(compress_num.begin(), compress_num.end(), x) - compress_num.begin(); } int main() { int n, m, q; cin >> n >> m >> q; vector<long long> t(q), x(q), y(q); for (int i = 0; i < q; i++) { cin >> t[i] >> x[i] >> y[i]; x[i]--; } for (int i = 0; i < q; i++) { compress_num.emplace_back(y[i]); } compress_num.emplace_back(0); sort(compress_num.begin(), compress_num.end()); compress_num.erase(unique(compress_num.begin(), compress_num.end()), compress_num.end()); /*for (int i = 0; i < compress_num.size(); i++) { compressed_num[i] = lower_bound(compress_num.begin(), compress_num.end(), compress_num[i]) - compress_num.begin(); }*/ long long sum = 0; vector<int> a(n), b(m); BIT bita(q+10), bitb(q + 10); BIT numa(q+10), numb(q + 10); numa.add(0, n); numb.add(0, m); for (int i = 0; i < q; i++) { if (t[i] == 1) { sum -= bitb.sum(find_comp(a[x[i]]), q+5) + a[x[i]] * numb.sum(0, find_comp(a[x[i]]) - 1); bita.add(find_comp(a[x[i]]), -a[x[i]]); numa.add(find_comp(a[x[i]]), -1); a[x[i]] = y[i]; numa.add(find_comp(a[x[i]]), 1); bita.add(find_comp(a[x[i]]), a[x[i]]); sum += bitb.sum(find_comp(a[x[i]]), q+5) + y[i] * numb.sum(0, find_comp(a[x[i]]) - 1); cout << sum << endl; } else { sum -= bita.sum(find_comp(b[x[i]]), q + 5) + b[x[i]] * numa.sum(0, find_comp(b[x[i]]) - 1); bitb.add(find_comp(b[x[i]]), -b[x[i]]); numb.add(find_comp(b[x[i]]), -1); b[x[i]] = y[i]; numb.add(find_comp(b[x[i]]), 1); bitb.add(find_comp(b[x[i]]), b[x[i]]); sum += bita.sum(find_comp(b[x[i]]), q + 5) + y[i] * numa.sum(0, find_comp(b[x[i]]) - 1); cout << sum << endl; } /*for (int j = 0; j < n; j++) { cout << a[j] << " "; } cout << endl; for (int j = 0; j < m; j++) { cout << b[j] << " "; } cout << endl;*/ } return 0; }
#include<bits/stdc++.h> #define rep(i, n) for (int i = 0, length = n; i < length; i++) #define fi first #define se second #define lb lower_bound #define ub upper_bound #define ep emplace #define epb emplace_back #define scll static_cast<long long> #define sz(x) static_cast<int>((x).size()) #define pfll(x) printf("%lld\n", x) #define ci(x) cin >> x #define ci2(x, y) cin >> x >> y #define ci3(x, y, z) cin >> x >> y >> z #define ci4(w, x, y, z) cin >> w >> x >> y >> z #define co(x) cout << x << endl #define co2(x, y) cout << x << " " << y << endl #define co3(x, y, z) cout << x << " " << y << " " << z << endl using namespace std; typedef long long ll; typedef pair<int, ll> P; typedef priority_queue<int> PQ; typedef priority_queue<int, vector<int>, greater<int>> PQG; typedef priority_queue<P> PQP; typedef priority_queue<P, vector<P>, greater<P>> PQPG; const int MAX_N = 2e5, MOD = 1e9 + 7, INF = 1e9; int n, m, q, t[MAX_N], x[MAX_N], y[MAX_N], memo[MAX_N][2]; map<int, int> ma; vector<ll> ans; P bit[MAX_N + 2][2]; P sum(int i, int j) { P s = P(0, 0); while (i > 0) { s.fi += bit[i][j].fi; s.se += bit[i][j].se; i -= i & -i; } return s; } void add(int i, int j, int x, int y) { while (i <= q + 1) { bit[i][j].fi += x; bit[i][j].se += y; i += i & -i; } } int main() { ci3(n, m, q); rep(i, q) { ci3(t[i], x[i], y[i]); ma.ep(y[i], 0); } ma.ep(0, 0); int cnt = 0; for (auto &i: ma) i.se = ++cnt; ans.epb(0); rep(i, n) add(1, 0, 1, 0); rep(i, m) add(1, 1, 1, 0); rep(i, q) { int old_y = memo[x[i] - 1][t[i] - 1]; add(ma[y[i]], t[i] - 1, 1, y[i]); add(ma[old_y], t[i] - 1, -1, -old_y); P p1 = sum(ma[y[i]] - t[i] % 2, t[i] % 2); P p2 = sum(ma[old_y] - t[i] % 2, t[i] % 2); ll tmp = ans.back(); tmp += scll(p1.fi) * y[i] - scll(p2.fi) * old_y; tmp += p2.se - p1.se; ans.epb(tmp); memo[x[i] - 1][t[i] - 1] = y[i]; } rep(i, q) co(ans[i + 1]); return 0; }
#include<iostream> using namespace std; int main() { int n, m; cin >> n >> m; cout << n / m; }
//#include <atcoder/all> //using namespace atcoder; #include <bits/stdc++.h> using namespace std; typedef long long ll; #define REP(i, n) for(int i=0; i<n; i++) #define REPR(i, n) for(int i=n-1; i>=0; i--) #define FOR(i, m, n) for(int i=m; i<n; i++) #define ALL(v) v.begin(), v.end() #define bit(n) (1LL<<(n)) #define FIX(d) fixed << setprecision(d) using P = pair<int, int>; using vvi = vector<vector<int>>; using vvl = vector<vector<ll>>; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const int INF = 2e9; const ll LINF = (1LL<<60); int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n,w; cin >> n >> w; cout << n/w << endl; return 0; }
#include <iostream> #include <algorithm> using namespace std; long long md = 1000000007; long long fp(long long n, long long k) { long long s = 1; while (k) { if (k & 1) s = (s * n) % md; k /= 2; n = (n * n) % md; } return s; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; int s = n; for (int i = 0; i < n; i++) { int a; cin >> a; s += a; } int p = n + m; long long ns = 1, rs = 1; for (int i = 0; i < s; i++) { ns = (ns * (p - i)) % md; rs = (rs * (i + 1)) % md; } rs = fp(rs, md - 2); cout << (ns * rs) % md << '\n'; 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;} template<typename T>void rearrange(vector<ll>&ord, vector<T>&v){ auto tmp = v; for(int i=0;i<tmp.size();i++)v[i] = tmp[ord[i]]; } template<typename Head, typename... Tail>void rearrange(vector<ll>&ord,Head&& head, Tail&&... tail){ rearrange(ord, head); rearrange(ord, tail...); } //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; vector<ll>a(4); rep(i,0,4)cin>>a[i]; cout<<*min_element(ALL(a))<<endl; return 0; }
#include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <algorithm> using namespace std; #define N 110 #define sq(_) ((_) * (_)) #define eps 1e-7 bool equ(double x , double y) { return fabs(x - y) < eps; } int n; double x[2][N] , y[2][N]; double gx , gy; bool vis[N]; int main() { cin >> n; for(int t = 0 ; t <= 1 ; t++) { gx = gy = 0; for(int i = 1 ; i <= n ; i++) { cin >> x[t][i] >> y[t][i]; gx += x[t][i] , gy += y[t][i]; // x[t][i] *= n , y[t][i] *= n; } gx /= n * 1.0 , gy /= n * 1.0; for(int i = 1 ; i <= n ; i++) x[t][i] -= gx , y[t][i] -= gy; } /* for(int t = 0 ; t <= 1 ; t++) for(int i = 1 ; i <= n ; i++) { cout << x[t][i] << '\t' << y[t][i] << endl; }*/ for(int i = 1 ; i <= n ; i++) { if(x[0][i] != 0 || y[0][i] != 0) { swap(x[0][i] , x[0][1]); swap(y[0][i] , y[0][1]); } } for(int i = 1 ; i <= n ; i++) { // if(sq(x[1][1]) + sq(y[1][1]) != sq(x[0][i]) + sq(y[0][i])) continue; double angle = atan2(y[1][i] , x[1][i]) - atan2(y[0][1] , x[0][1]); memset(vis , 0 , sizeof(vis)); vis[i] = true; for(int j = 1 ; j <= n ; j++) { double tx , ty; tx = x[0][j] * cos(angle) - y[0][j] * sin(angle); ty = x[0][j] * sin(angle) + y[0][j] * cos(angle); for(int k = 1 ; k <= n ; k++) if(equ(tx , x[1][k]) && equ(ty , y[1][k])) vis[k] = true; } bool flag = true; for(int j = 1 ; j <= n ; j++) if(vis[j] == 0) { flag = false; break; } if(flag) { puts("Yes"); return 0; } } puts("No"); return 0; }
// ----- In the name of ALLAH, the Most Gracious, the Most Merciful ----- #include<bits/stdc++.h> using namespace std; #define sim template < class c #define ris return * this #define dor > debug & operator << #define eni(x) sim > typename \ enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { #ifdef LOCAL ~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } #else sim dor(const c&) { ris; } #endif }; #define deb(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " #define int long long #define endl "\n" #define mod 1000000007 #define inf (int)1e18 const int mxn = 65; int dp[mxn][2]; string a[mxn]; int n; int solve(int i, bool prev){ if(i>=n){ return prev; } int &ans=dp[i][prev]; if(ans!=-1) return ans; ans = 0; if(a[i]=="AND"){ ans += solve(i+1,prev&true) + solve(i+1,prev&false); }else{ ans += solve(i+1,prev|true) + solve(i+1,prev|false); } return ans; } int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); memset(dp,-1,sizeof(dp)); cin >> n; for(int i=0;i<n;i++){ cin >> a[i]; } debug() << range(a,a+n); cout << solve(0,0) + solve(0,1) << endl; debug() << deb(solve(0,0)); debug() << deb(solve(0,1)); return 0; }
#include <bits/stdc++.h> #define ff first #define ss second #define endl '\n' using namespace std; const long long INF = (long long) 1e18; const int mod = (int) 998244353; const int MAXN = (int) 3e5+5; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pii; typedef pair<ll,ll> pll; ll n, k; int gr[55][55]; int fact[MAXN]; int p1[MAXN], p2[MAXN]; int sz1[MAXN], sz2[MAXN]; int find_set(int *p, int a){ if(p[a] == a) return a; return p[a] = find_set(p, p[a]); } void merge(int a, int b, int *p){ a = find_set(p, a); b = find_set(p, b); if(a != b){ p[b] = a; if(p == p1) sz1[a] += sz1[b]; else sz2[a] += sz2[b]; } } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr);cout.tie(nullptr); #ifdef Local freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/int.txt","r",stdin); freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/out.txt","w",stdout); #endif fact[0] = 1; for(int i = 1; i <= 50; i++) fact[i] = 1LL * fact[i - 1] * i % mod; cin>>n>>k; for(int i = 0; i < n; i++){ p1[i] = i; sz1[i] = 1; p2[i] = i; sz2[i] = 1; for(int j = 0; j < n; j++) cin>>gr[i][j]; } int ans = 1; for(int i = 0; i < n; i++){ for(int j = i + 1; j < n; j++){ bool tru = 1; for(int l = 0; l < n; l++){ if(gr[i][l] + gr[j][l] > k){ tru = 0; break; } } if(tru) merge(i, j, p1); } } for(int i = 0; i < n; i++){ if(p1[i] == i){ ans = 1LL * ans * fact[sz1[i]] % mod; } } for(int i = 0; i < n; i++){ for(int j = i + 1; j < n; j++){ bool tru = 1; for(int l = 0; l < n; l++){ if(gr[l][i] + gr[l][j] > k){ tru = 0; break; } } if(tru) merge(i, j, p2); } } for(int i = 0; i < n; i++){ if(p2[i] == i){ ans = 1LL * ans * fact[sz2[i]] % mod; } } cout<<ans<<endl; #ifdef Local cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds "; #endif }
#include <iostream> #include <cstdio> #include <vector> #include <map> #include <queue> #include <cstring> #include <algorithm> using namespace std; //#define int long long int n,m,a[1500010],f[1500010]; signed main() { memset(f,0,sizeof(f)); scanf("%d%d",&n,&m); for(int i = 1; i <= n; i++) { scanf("%d",&a[i]); } for(int i = 1; i <= m; i++) { f[a[i]]++; } int ans; for(int i = 0; ; i++) { if(f[i] == 0) { ans = i; break; } } for(int i = 2; i+m-1 <= n; i++) { if(a[i-1] < ans && a[i+m-1] != a[i-1] && f[a[i-1]] == 1) { ans = a[i-1]; } f[a[i-1]]--; f[a[i+m-1]]++; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define clog(x) std::clog << (#x) << " is " << (x) << '\n'; using LL = long long; int main() { //freopen("in", "r", stdin); std::cin.tie(nullptr)->sync_with_stdio(false); LL n; std::cin >> n; std::vector<LL> F{1, 1}; while (F.back() <= n) F.emplace_back(F[F.size() - 2] + F[F.size() - 1]); F.pop_back(); int s = F.size(), now = s - 1; std::vector<int> a(s), ans; while (now >= 0 && n) { if (F[now] <= n) { // 不会超过两次的 n -= F[now]; ++a[s - 1 - now]; } --now; } for (int i = 0; i < s; ++i) { if ((i & 1) == (s & 1)) { if (a[i]) ans.emplace_back(2); ans.emplace_back(4); } else { if (a[i]) ans.emplace_back(1); ans.emplace_back(3); } } std::cout << ans.size() << '\n'; for (auto x : ans) std::cout << x << '\n'; return 0; }
/// #include <bits/stdc++.h> using namespace std; #define fo(i,a,b) for(int i=a;i<b;i++) #define fodec(i,a,b) for(int i=a;i>b;i--) #define sz(v) int(v.size()) #define len(s) s.length() #define ll long long int #define vi vector<int> #define vll vector<ll> #define vb vector<bool> #define vvi vector<vector<int>> #define vvb vector<vector<bool>> #define vvll vector<vector<ll>> #define pb push_back #define pii pair<int,int> #define fi first #define se second #define mp make_pair #define piii pair<int,pair<int,int>> #define all(x) x.begin(),x.end() #define bit_cnt(x) __builtin_popcount(x) #define fastio ios_base:: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) #define fileio freopen("input.txt","r",stdin); freopen("output.txt","w",stdout) #define inf 1e9 const int MOD = 1e9+7; int n; vvi adj; vi cc; vi ans; unordered_map<int,bool> uu; void solve(int s,int par){ bool f=false; if(!uu[cc[s]]){ f=true; ans.pb(s); uu[cc[s]]=true; } for(auto&x:adj[s]){ if(x==par) continue; solve(x,s); } if(f) uu[cc[s]]=false; } int main(){ cin>>n; cc.assign(n,-1); fo(i,0,n) cin>>cc[i]; adj.assign(n,vector<int>()); fo(i,0,n-1){ int x,y; cin>>x>>y; x--; y--; adj[x].pb(y); adj[y].pb(x); } ans.clear(); uu.clear(); solve(0,-1); sort(all(ans)); for(auto&it:ans) cout<<it+1<<endl; }
#include <bits/stdc++.h> using namespace std; // template {{{ #define range(i, l, r) for (int i = (int)(l); i < (int)(r); (i) += 1) #define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); (i) -= 1) #define whole(f, x, ...) ([&](decltype((x)) container) { return (f)( begin(container), end(container), ## __VA_ARGS__); })(x) #define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x) #define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl using i32 = int; using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; constexpr i32 mod = 1e9 + 7; // constexpr i32 mod = 998244353; constexpr i32 inf = 1001001001; constexpr i64 infll = 1001001001001001001ll; constexpr i32 dx[] = {0, -1, 1, 0, -1, 1, -1, 1}; constexpr i32 dy[] = {-1, 0, 0, 1, -1, -1, 1, 1}; struct IoSetup { IoSetup(i32 x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup; template <typename T = i64> T input() { T x; cin >> x; return x; } template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != (int)v.size() ? " " : ""); } return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; } template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; } template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; } template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); } template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); } template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); } // }}} void solve() { 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; } } signed main() { solve(); }
#include <iostream> #include <vector> #include <algorithm> using namespace std; #define int long long int lst[3][11]; int nlst[10]; bool check(void) { int num[3] = {0}; for (int i = 0; i < 3; i++) { if (nlst[lst[i][0]] == 0) return false; for (int j = 0; j < lst[i][10]; j++) { num[i] *= 10; num[i] += nlst[lst[i][j]]; } } return (num[0] + num[1] == num[2]); } signed main(void) { string s; bool b; char clst[10]; int cp = 0; for (int i = 0; i < 3; i++) { cin >> s; for (int j = s.size() - 1; j >= 0; j--) { lst[i][10] = s.size(); b = true; // アルファベットを数字に変換 for (int k = 0; k < cp; k++) { if (clst[k] == s[j]) { lst[i][j] = k; b = false; break; } } if (b) { if (cp >= 10) { // 11文字以上使われてる cout << "UNSOLVABLE" << endl; return 0; } clst[cp] = s[j]; lst[i][j] = cp; cp++; } } } vector<int> seed = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; sort(seed.begin(), seed.end()); do { for (int i = 0; i < 10; i++) nlst[i] = seed[i]; b = check(); if (b) break; } while (next_permutation(seed.begin(), seed.end())); if (b) { for (int i = 0; i < 3; i++) { for (int j = 0; j < lst[i][10]; j++) cout << nlst[lst[i][j]]; cout << endl; } } else cout << "UNSOLVABLE" << endl; }
#include "bits/stdc++.h" using namespace std; #include "string" #define int long long #define pi pair<int, int> #define ff first #define ss second #define boost ios::sync_with_stdio(false);cin.tie(nullptr) #define endl '\n' #define vi vector<int> int32_t main() { boost; int n; cin >> n; string s; cin >> s; int q; cin >> q; int f = 0; while(q--) { int t, a, b; cin >> t >> a >> b; a--, b--; if(t == 1) { if(f) { if(a < n) a += n; else a -= n; if(b < n) b += n; else b -=n; } swap(s[a], s[b]); } else f ^= 1; } if(f) s = s.substr(n) + s.substr(0, n); cout << s << endl; }
#include <iostream> #include <string> #include <vector> using namespace std; bool s_first = true;//true_s1,false_s2 void swap_char(vector<char>&,vector<char>&,int,int,int); int main(){ int n; cin >> n; string s; cin >> s; vector<char> s1(n); vector<char> s2(n); for(int i = 0;i < n;i++){ s1[i] = s[i]; } for(int i = 0;i < n;i++){ s2[i] = s[i+n]; } int q; cin >> q; for(int i = 0;i < q;i++){ int t,a,b; cin >> t >> a >> b; a--; b--; if(t == 1){ if(s_first){ swap_char(s1,s2,a,b,n); }else{ swap_char(s2,s1,a,b,n); } } if(t == 2){ s_first = !s_first; } } if(s_first){ for(auto i:s1){ cout << i; } for(auto i:s2){ cout << i; } cout << endl; }else{ for(auto i:s2){ cout << i; } for(auto i:s1){ cout << i; } cout << endl; } return 0; } void swap_char(vector<char>& s1,vector<char>& s2,int a,int b,int n){ if(a >= n){ if(b >= n){ swap(s2[a-n],s2[b-n]); }else{ swap(s2[a-n],s1[b]); } }else{ if(b >= n){ swap(s1[a],s2[b-n]); }else{ swap(s1[a],s1[b]); } } return; }
#include <bits/stdc++.h> #define endl "\n"; #define pii pair<int,int>; using namespace std; typedef long long ll; const ll BIG=1000000007; const double PI=3.141592653589793238; ll binpow(ll a,ll b,ll m) { ll res=1; while(b>0){ if(b&1){res=(res*a)%m;} b>>=1;a=(a*a)%m; } return res; } template <typename T,typename Q> T max(T a,Q b) { if(a<b) return b; return a; } template <typename T,typename Q> T min(T a,Q b) { if(a>b) return b; return a; } void solve() { int a,b; cin>>a>>b; cout<<(a+b)/2<<" "<<(a-b)/2; } int main() { int t;t=1; while(t--) { solve(); } return 0; }
#include<bits/stdc++.h> #define For(i,x,y) for (register int i=(x);i<=(y);i++) #define FOR(i,x,y) for (register int i=(x);i<(y);i++) #define Dow(i,x,y) for (register int i=(x);i>=(y);i--) #define Debug(v) for (auto i:v) printf("%lld ",i);puts("") #define mp make_pair #define fi first #define se second #define pb push_back #define ep emplace_back #define siz(x) ((int)(x).size()) #define all(x) (x).begin(),(x).end() #define fil(a,b) memset((a),(b),sizeof(a)) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> pa; typedef pair<ll,ll> PA; typedef vector<int> poly; inline ll read(){ ll x=0,f=1;char c=getchar(); while ((c<'0'||c>'9')&&(c!='-')) c=getchar(); if (c=='-') f=-1,c=getchar(); while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar(); return x*f; } int main(){ int a=read(),b=read(),x=(a+b)/2,y=a-x; printf("%d %d\n",x,y); }
//Many 110 #include<bits/stdc++.h> using namespace std; using ll = long long; #define int long long #define rep(i,x,y) for(ll i=x;i<y;i++) #define rrep(i,x,y) for(ll i=x-1;i>=y;i--) #define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i] #define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i] #define lcm(a,b) (a/__gcd(a, b)*b) #define range(a) (a).begin(),(a).end() #define nnn "\n" #define spa " " using P = pair<ll,ll>; using graph = vector<vector<ll>>; const int inf = 2147483647;//2*10^9 const ll INF = 9223372036854775807;//9*10^18 //cout<<fixed<<setprecision(15)<<x<<nnn; signed main (){ int n;string t;cin>>n>>t; int ans=0; string s; rep(i,0,n/3+2){ s.push_back('0'); s.push_back('1'); s.push_back('1'); } bool flag=false; rep(i,0,3)rep(j,0,n){ if(t[j]!=s[i+j])break; if(j==n-1)flag=true; } if(flag){ if(n==1){ if(t[0]=='1')ans=2*1e10; else ans=1e10; }else if(n==2){ if(t[0]=='0')ans=1e10-1; else ans=1e10; }else{ if(t[0]=='0')ans=(3e10-2-n)/3+1; else if(t[1]=='0')ans=(3e10-1-n)/3+1; else ans=(3e10-n)/3+1; } } cout<<ans<<nnn; return 0; }
#include <iostream> #include <string> #include <vector> #include <set> #include <map> #include <queue> #include <algorithm> #include <cmath> #include <cstdio> using namespace std; typedef unsigned long long ull; typedef long long ll; ll N, ans; string Tstr; ll check_valid(ll offset, const char* T) { ll i; ll m; const char* valid = "110"; m = 0; for (i = offset; i < N; i++) { if (T[i] != valid[m]) { return -1; } m++; if (m == 3) m = 0; } //cout << "passed" << endl; ll n = (N - offset) / 3; ll left = (N - offset) % 3; if (left > 0) n++; if (offset == 0) { return n - 1; } else { return n; } } int main() { N = 1E10; cin >> N; cin >> Tstr; if (N == 1) { if (Tstr.at(0) == '1') { ans = 2 * 1E10; } else { ans = 1E10; } cout << ans << endl; return 0; } if (N == 2) { auto check = Tstr.substr(0, 2); if (check == "11" || check == "10") { ans = 1E10; } else if (check=="01"){ ans = 1E10-1; } else { ans = 0; } cout << ans << endl; return 0; } string head = Tstr.substr(0, 3); ll offset = 0; if (head == "110") { if (N == 3) { ans = 1E10; cout << ans << endl; return 0; } offset = 0; } else if (head == "101"){ if (N == 3) { ans = 1E10-1; cout << ans << endl; return 0; } offset = 2; } else if (head == "011") { if (N == 3) { ans = 1E10 - 1; cout << ans << endl; return 0; } offset = 1; } else { ans = 0; cout << ans << endl; return 0; } // cout << "offset=" << offset << " T=" << Tstr << endl; ll ret= check_valid(offset, Tstr.c_str()); if (ret == -1) { ans = 0; } else { ans = 1E10 - ret; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL_ void debug_out() {cerr << endl;} template<typename Head,typename... Tail> void debug_out(Head H,Tail... T){cerr << ' ' << H; debug_out(T...);} #define debug(...) cerr << 'L' << __LINE__ << " [" << #__VA_ARGS__ << "]:",debug_out(__VA_ARGS__) #define dump(x) cerr << 'L' << __LINE__ << " " << #x << " = " << (x) << endl; #else #define debug(...) (void(0)) #define dump(x) (void(0)) #endif #define rep(i,n) for (int i = 0; i < (int)(n); i ++) #define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i) using ll = long long; using PL = pair<ll,ll>; using P = pair<int,int>; constexpr int INF = 1000000000; constexpr long long HINF = 1000000000000000; constexpr long long MOD = 1000000007;// = 998244353; constexpr double EPS = 1e-4; constexpr double PI = 3.14159265358979; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int H,W; cin >> H >> W; vector<string> S(H); rep(i,H) cin >> S[i]; int ans = 0; rep(i,H) { rep(j,W) { if (S[i][j] == '#') continue; if (i + 1 < H && S[i+1][j] == '.') ++ans; if (j + 1 < W && S[i][j+1] == '.') ++ans; } } cout << ans << '\n'; return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long int #define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define pii pair<int,int> #define F first #define S second #define pb push_back const int mod1=998244353,mod2=(int)1e9+7; int power(int n,int k,int mod){int ans=1; n=n%mod;while(k>0){if(k&1)ans=(ans*n)%mod;n=(n*n)%mod;k>>=1;}return (ans+mod)%mod;}//negative nos & 0^0 struct triplet{int a,b,c;};bool operator < (const triplet &t1,const triplet &t2){if(t1.a<t2.a)return true;if(t1.a==t2.a && t1.b <t2.b)return true;if(t1.a==t2.a && t1.b ==t2.b && t1.c<t2.c)return true;return false;} // memset(dp, -1, sizeof dp); void problemSolver() { int n,k,ans=0; cin>>n>>k; for(int y=2;y<=2*n;y++) { int x=k+y; if(x<=1 || x>2*n) continue; int ans1=(2*n-x+1),ans2=(2*n-y+1); if(x<=n) ans1=x-1; if(y<=n) ans2=y-1; ans+=ans1*ans2; } cout<<ans; } int32_t main() { fio; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int testcases=1; // cin>>testcases; while(testcases--) problemSolver(); }
#include <bits/stdc++.h> using namespace std; #define rep(i,a,n) for (int i=a;i<n;i++)//iをaからn #define per(i,n,a) for (int i=a-1;i>=n;i--)//iをnからa #define db(x) cout << #x << " = " << x << endl//デバッグ用 #define db2(x, y) cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"; //デバッグ用 #define all(x) (x).begin(), (x).end() #define INF32 2147483647 //2.147483647×10^{9}:32bit整数のinf #define INF64 9223372036854775807 //9.223372036854775807×10^{18}:64bit整数のinf #define MOD 1000000007 //10^9+7:合同式の法 #define pb push_back #define F first #define S second typedef long long ll; //sort(all(a)); ソート //sort(all(a),greater<int>()); 逆順ソート //a.erase(unique(all(a)), a.end()); ソート後に重複を削除 //cout<< std::fixed << std::setprecision(15)<<0.000001<<endl; 小数点以下を表示させる //vector<vector<int>> data(3, vector<int>(4)); int型の2次元配列(3×4要素の)の宣言 int main() { ll n; cin>>n; n-=3; cout<<"6 10 15 "; ll i=16; while(n){ i++; bool is2,is3,is5; is2=i%2==0; is3=i%3==0; is5=i%5==0; if((is2&&is3)||(is2&&is5)||(is5&&is3)){ cout<<i<<" "; n--; if(n==0)break; } } }
#include<bits/stdc++.h> typedef int LL; typedef double dl; #define opt operator #define pb push_back #define pii std::pair<LL,LL> const LL maxn=1e6+9,mod=998244353,inf=0x3f3f3f3f; LL Read(){ LL x(0),f(1); char c=getchar(); while(c<'0' || c>'9'){ if(c=='-') f=-1; c=getchar(); } while(c>='0' && c<='9'){ x=(x<<3ll)+(x<<1ll)+c-'0'; c=getchar(); }return x*f; } void Chkmin(LL &x,LL y){ if(y<x) x=y; } void Chkmax(LL &x,LL y){ if(y>x) x=y; } LL add(LL x,LL y){ return x+=y,x>=mod?x-mod:x; } LL dec(LL x,LL y){ return x-=y,x<0?x+mod:x; } LL mul(LL x,LL y){ return 1ll*x*y%mod; } LL Pow(LL base,LL b){ LL ret(1); while(b){ if(b&1) ret=mul(ret,base); base=mul(base,base); b>>=1; }return ret; } LL n; int main(){ n=Read(); printf("%d\n",(1<<n)-1); for(LL i=1;i<(1<<n);++i){ for(LL j=0;j<(1<<n);++j){ if(__builtin_popcount(i&j)&1){ printf("B"); }else{ printf("A"); } }puts(""); } return 0; }
/** * author : Nikh1l * created: 27.02.2021 17:29:54 **/ #include<bits/stdc++.h> using namespace std; using ll = int64_t; void Learner() { double a, b, ans = 0; cin >> a >> b; cout << setprecision(10) << (a - b)*100/a; } int32_t main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); Learner(); }
#include<bits/stdc++.h> #define ll long long using namespace std; const int N = 2e5 + 10, oo = 1e9 + 10, MOD = 1e9 + 7; ll s, p; main() { ios::sync_with_stdio(0); cin.tie(0); cin >> s >> p; for(ll i = 1; i * i <= p; i++) { if(p % i == 0) { if(p / i + i == s) { cout << "Yes\n"; return 0; } } } cout << "No\n"; }
#include <bits/stdc++.h> using namespace std; using ll = long long; ll gcd(ll a, ll b){return b ? gcd(b,a%b):a;} int main(){ ll n; cin >> n; ll ans = 2; for(ll i=3; i<=n; ++i){ ans *= i /gcd(ans,i); } cout << ans+1 << endl; }
#include<bits/stdc++.h> #include<string.h> #include<vector> #include<set> #include<map> #include<stack> #include<queue> #define endl "\n" #define ll long long #define int long long #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cin.exceptions(cin.failbit);cout.tie(NULL); using namespace std; bool isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i += 6) { if ((n % i == 0) || (n % (i + 2) == 0)) return false; } return true; } const int N = 2e5 + 5; const int MOD = 1e9 + 7; int fact[N], invfact[N]; int pow(int a, int b, int m) { int ans=1; while(b) { if(b&1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans; } int modinv(int k) { return pow(k, MOD-2, MOD); } void precompute() { fact[0]=fact[1]=1; for(int i=2;i<N;i++) { fact[i]=fact[i-1]*i; fact[i]%=MOD; } invfact[N-1]=modinv(fact[N-1]); for(int i=N-2;i>=0;i--) { invfact[i]=invfact[i+1]*(i+1); invfact[i]%=MOD; } } int nCr(int x, int y) { if(y>x) return 0; int num=fact[x]; num*=invfact[y]; num%=MOD; num*=invfact[x-y]; num%=MOD; return num; } int32_t main() { int t; t=1; while(t--) { int n; cin >> n; int x=1; for(int i=2;i<=n;i++) { x=((x*i)/__gcd(x,i)); //cout << x << endl; } //for(int i=2;i<=n;i++) //cout << (x+1)%i << endl; cout << x+1; } }
#include<bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define lld long double #define pii pair<int,int> #define pll pair<ll,ll> #define pb push_back #define f first #define s second #define mk make_pair /*----------------------DEBUGGER---------------------------*/ #ifndef ONLINE_JUDGE #define debug(x) cerr << #x <<" "; _print(x); cerr << endl; #else #define debug(x) #endif void _print(ll t) {cerr << t;} void _print(int t) {cerr << t;} void _print(string t) {cerr << t;} void _print(char t) {cerr << t;} void _print(lld t) {cerr << t;} void _print(double t) {cerr << t;} void _print(ull t) {cerr << t;} template <class T, class V> void _print(pair <T, V> p); template <class T> void _print(vector <T> v); template <class T> void _print(set <T> v); template <class T, class V> void _print(map <T, V> v); template <class T> void _print(multiset <T> v); template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.f); cerr << ","; _print(p.s); cerr << "}";} template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} /*----------------------DEBUGGER---------------------------*/ int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("error.txt", "w", stderr); #endif int tt = 1; //cin >> tt; while (tt--) { int n; cin >> n; ll ans = 108 * n; ans /= 100; if (ans < 206) cout << "Yay!"; else if (ans == 206) cout << "so-so"; else cout << ":("; }//while }//main
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <math.h> #include <queue> #include <numeric> #include <iomanip> #include <map> #include <set> using namespace std; using ll = long long; template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; #define pb push_back #define mp make_pair #define fi first #define se second #define For(i,a,b) for(ll i=(a);i<(ll)(b);i++) #define rFor(i,a,b) for(ll i=(a);i>=(ll)(b);i--) #define co(a) cout<<a<<endl #define ce(a) cerr<<a<<endl #define Sort(a) sort((a).begin(),(a).end()) #define Rev(a) reverse((a).begin(),(a).end()) #define Unique(a) (a).erase(unique((a).begin(), (a).end()),(a).end()) #define cfs(a) cout<<fixed<<setprecision(a) constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); } template <class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; } template <class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; } template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << "(" << p.first << "," << p.second << ")"; return os; } template <class T> ostream& operator<<(ostream& os, const vector<T>& v) { os << "{"; For(i, 0, v.size()) { if (i) os << ","; os << v[i]; } os << "}"; return os; } #define LOCAL #ifdef LOCAL void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...); } #define debug(...) \ cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl #else #define debug(...) (void(0)) #define dump(x) (void(0)) #endif constexpr ll INF = TEN(18); int main() { ll N; cin >> N; N = N * 1.08 / 1; if (206 > N) { co("Yay!"); } else if (206 == N) { co("so-so"); } else { co(":("); } }
#pragma region Template // clang-format off #include <bits/stdc++.h> using namespace std; // #include <atcoder/all> // using namespace atcoder; #define rep(i, m, n) for (int i = m; i < (int)(n); i++) #define repe(i, m, n) for (int i = m; i <= (int)(n); i++) #define all(x) (x).begin(),(x).end() #define yesno {cout<<"Yes"<<endl;}else{cout<<"No"<<endl;} using ll = long long; using vi = vector<int>; using vvi = vector<vector<int>>; using vs = vector<string>; using pii = pair<int,int>; 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; } #pragma endregion Template // clang-format on int main() { int k; cin >> k; string T, A; cin >> T >> A; vector<ll> c(10, k), t(10), a(10); rep(i, 0, 4) { t[T[i] - '0']++; a[A[i] - '0']++; c[T[i] - '0']--; c[A[i] - '0']--; } ll twin = 0, awin = 0; repe(i, 1, 9) repe(j, 1, 9) { auto tt = t, aa = a; tt[i]++; aa[j]++; ll tsum = 0, asum = 0, n = 0; if (i == j) { n = c[i] * (c[i] - 1); } else { n = c[i] * c[j]; } repe(k, 1, 9) { tsum += k * (ll)pow(10, tt[k]); asum += k * (ll)pow(10, aa[k]); } if (tsum > asum) twin += n; else awin += n; } double ans = (double)twin / (twin + awin); printf("%.10f\n", ans); }
#include <iostream> #include <algorithm> #include <map> #include <set> #include <queue> #include <stack> #include <numeric> #include <bitset> #include <cmath> static const int MOD = 1000000007; using ll = long long; using u32 = unsigned; using u64 = unsigned long long; using namespace std; template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208; int main() { int n, m, k; cin >> n >> m >> k; vector<int> bad(n+1); vector<int> aa; for (int i = 0; i < k; ++i) { int x; cin >> x; bad[x]++; aa.emplace_back(x); } for (int i = 0; i+m <= k; ++i) { if(aa[i+m-1]-aa[i] == m-1) return puts("-1"), 0; } vector<array<double, 2>> ans(n), S(n+1); for (int i = n-1; i >= 0; --i) { if(bad[i]){ ans[i][1] = 1; }else { for (int j = 0; j < 2; ++j) { ans[i][j] = (S[i+1][j]-S[min(n, i+1+m)][j])/m; } ans[i][0]++; } for (int j = 0; j < 2; ++j) { S[i][j] = S[i+1][j]+ans[i][j]; } } printf("%.10lf\n", ans[0][0]/(1-ans[0][1])); return 0; }
#include <stdio.h> #include <iostream> #include <vector> #include <algorithm> //#define LOCAL using namespace std; typedef long long ll; const int mx=100+10; const int SIZE=50; ll prime[mx], ptot; bool isp[mx]; ll x[mx]; ll ans; ll n; vector<ll>vec[mx]; void fj(ll v){ ll cpy=v; for(ll i=2;i*i<=v;i++){ if(v%i==0){ vec[cpy].push_back(i); while(v%i==0)v/=i; } } if(v!=1)vec[cpy].push_back(v); } void getPrime(){ isp[1]=1; for(ll i=2;i<=SIZE;i++){ if(isp[i]==0){ prime[++ptot]=i; } for(ll j=1;j<=ptot;j++){ if(i*prime[j]>SIZE)break; isp[i*prime[j]]=1; if(i%prime[j]==0)break; } } } bool vis[mx]; void dfs(ll c, ll v){//c<=ptot; if(v>=ans) return; if(c==ptot+1){ for(ll i=1;i<=n;i++){ bool ok=false; for(ll j=0;j<vec[x[i]].size();j++){ ll value=vec[x[i]][j]; if(vis[value]){ ok=true; break; } } if(!ok) return; } ans=v; return; } vis[prime[c]]=true; dfs(c+1, v*prime[c]); vis[prime[c]]=false; dfs(c+1, v); } void solve(){ getPrime(); for(ll i=1;i<=SIZE;i++)fj(i); cin>>n; for(ll i=1;i<=n;i++){ cin>>x[i]; } n=unique(x+1, x+1+n)-x-1; ans=1e18+10; dfs(1, 1); cout<<ans<<endl; } int main(){ #ifdef LOCAL FILE *fp=freopen("1", "r", stdin); #endif solve(); #ifdef LOCAL fclose(fp); #endif return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long long unsigned int ull; typedef pair<ll, ll> llpair; typedef std::numeric_limits<double> dbl; #if defined(_USE_MATH_DEFINES) && !defined(_MATH_DEFINES_DEFINED) #define _MATH_DEFINES_DEFINED #define M_E 2.71828182845904523536 #define M_LOG2E 1.44269504088896340736 #define M_LOG10E 0.434294481903251827651 #define M_LN2 0.693147180559945309417 #define M_LN10 2.30258509299404568402 #define M_PI 3.14159265358979323846 #define M_PI_2 1.57079632679489661923 #define M_PI_4 0.785398163397448309616 #define M_1_PI 0.318309886183790671538 #define M_2_PI 0.636619772367581343076 #define M_2_SQRTPI 1.12837916709551257390 #define M_SQRT2 1.41421356237309504880 #define M_SQRT1_2 0.707106781186547524401 #endif void prepareIO() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.precision(dbl::max_digits10); } const ll MOD = 1e9 + 7; const ll N = 3e3 + 1; int main() { #ifndef ONLINE_JUDGE freopen("../input.txt", "r", stdin); freopen("../output.txt", "w", stdout); #endif prepareIO(); ll n; cin >> n; vector<ll> a(n + 1), psum(n + 1, 0); for (ll i = 1; i <= n; i++) { cin >> a[i]; psum[i] = psum[i - 1] + a[i]; } vector<vector<ll>> dp(n + 1, vector<ll>(n + 1, 0)); vector<vector<ll>> sum(n + 1, vector<ll>(n + 1, 0)); sum[1][0] = 1; for (ll i = 1; i <= n; i++) { for (ll j = 1; j <= i; j++) { dp[i][j] = sum[j][psum[i] % j]; } for (ll k = 1; k <= n; k++) { sum[k][psum[i] % k] = ((sum[k][psum[i] % k]) % MOD + (dp[i][k - 1]) % MOD) % MOD; } } ll ans = 0; for (ll j = 1; j <= n; j++) { ans = ((ans % MOD) + (dp[n][j] % MOD) % MOD); } cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define boost ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define mp make_pair #define pb push_back #define fp first #define sp second typedef long long int ll; typedef pair<ll,ll> pp; #define check(x, i) ((x>>i)&1LL) #define set(x,i) (x|(1LL<<i)) #define unset(x,i) (x&~(1LL<<i)) #define INF LONG_MAX #define MAX_N 20 #define MAX 200005 #define mod 1000000007 #define REP(i,n) for(i=0;i<n;i++) #define FOR(i,a,b) for(i=a;i<=b;i++) #define RFOR(i,a,b) for(i=a;i>=b;i--) #define len(i,s) for(i=0;s[i];i++) #define T() ll t;cin>>t;while(t--) #pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target("avx,avx2,sse,sse2") ll gcd (ll a, ll b){return (a?gcd(b%a,a):b);} ll pow1(ll a,ll b,ll MOD){ll ans=1;while(b!=0){if(b&1)ans=(ans*a)%MOD;a=(a*a)%MOD;b=b/2;}return ans;} ll modInverse(ll a,ll p){return pow1(a,p-2,p);} int main() { boost #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll n; cin>>n; ll i,j; ll arr[n-1]; REP(i,n-1) { arr[i]=i+2; } ll ans = arr[0]; for (int i = 1; i < n-1; i++) ans = (((arr[i] * ans)) / (gcd(arr[i], ans))); cout<<ans+1<<"\n"; }
#include <bits/stdc++.h> #define ll long long #define ui unsigned int #define forn(i, n) for (int i = 0; i < int(n); i++) using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); ll N, M; cin >> N; int d = 0; M = N; while (M > 0) { d++; M /= 10; } if (d == 1) { cout << 0 << endl; return 0; } if (d % 2 != 0) { M = 0; for (int i = 0; i < d; i++) { M = 10 * M + 9; } } else { M = N; } vector<ll> c; while (M > 0) { c.push_back(M % 10); M /= 10; } reverse(c.begin(), c.end()); ll R = 0; for (ui i = 0; i < c.size() / 2; i++) R = 10 * R + c[i]; ll ans = R; for (ui i = 0; i < c.size() / 2; i++) R = 10 * R + c[i]; // cout << R << " " << N << endl; cout << ans - (R > N ? 1 : 0) << endl; }
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<vector> #include<cmath> #include<algorithm> #include<map> #include<queue> #include<deque> #include<iomanip> #include<tuple> #include<cassert> #include<set> #include<complex> #include<numeric> #include<functional> #include<unordered_map> #include<unordered_set> using namespace std; typedef long long int LL; typedef pair<int,int> P; typedef pair<LL,LL> LP; const int INF=1<<30; const LL MAX=1e9+7; void array_show(int *array,int array_n,char middle=' '){ for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n')); } void array_show(LL *array,int array_n,char middle=' '){ for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n')); } void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){ if(vec_n==-1)vec_n=vec_s.size(); for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n')); } void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){ if(vec_n==-1)vec_n=vec_s.size(); for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n')); } template<typename T> ostream& operator<<(ostream& os,const vector<T>& v1){ int n=v1.size(); for(int i=0;i<n;i++){ if(i)os<<" "; os<<v1[i]; } return os; } template<typename T1,typename T2> ostream& operator<<(ostream& os,const pair<T1,T2>& p){ os<<p.first<<" "<<p.second; return os; } template<typename T> istream& operator>>(istream& is,vector<T>& v1){ int n=v1.size(); for(int i=0;i<n;i++)is>>v1[i]; return is; } namespace sol{ int n,m; const int N=5,M=3; int t[3333][N]; bool check(int q){ vector<vector<char>> dp(1<<N,vector<char>(M+10)); dp[0][0]=1; int i,j,k; int a,b; for(i=0;i<n;i++){ a=0; for(j=0;j<N;j++){ if(t[i][j]>=q)a^=1<<j; } for(j=0;j<(1<<N);j++){ for(k=M-1;k>=0;k--){ if(dp[j][k])dp[j|a][k+1]=1; } } } return dp[(1<<N)-1][M]; } void solve(){ int i,j,k; int a,b,c; int z[3]={0,INF}; cin>>n; for(i=0;i<n;i++){ for(j=0;j<N;j++){ cin>>t[i][j]; } } while(z[1]-z[0]>1){ z[2]=(z[0]+z[1])/2; if(check(z[2]))z[0]=z[2]; else z[1]=z[2]; } cout<<z[0]<<endl; } } int main(){ sol::solve(); }
#include <bits/stdc++.h> #define rep(i, a, n) for(int i = a; i < n; i++) using namespace std; using ll = long long; using P = pair<int, int>; const ll INF = 3e18; inline ll mod(ll a, ll m) { return (a%m+m)%m;} // EXTGCD a*x + b*y = extGCD ll extGCD(ll a, ll b, ll &x, ll &y){ if(b == 0) { x = 1; y = 0; return a;} ll d = extGCD(b, a%b, y, x); y -= a/b*x; return d; } // Chinese Remainder Theorem // x ≡ r (mod m) pair<ll, ll> ChineseRem(ll b1, ll m1, ll b2, ll m2){ ll p, q; ll d = extGCD(m1, m2, p, q); // p is inv of m1/d (mod m2/d) if((b2 - b1)%d != 0) return make_pair(0, -1); // no answer ll m = m1*(m2/d); // lcm(m1, m2) ll tmp = (b2 - b1)/d*p%(m2/d); ll r = mod(b1 + m1*tmp, m); return make_pair(r, m); } void solve(){ ll x, y, p, q; cin >> x >> y >> p >> q; ll a = (x + y)*2, b = p + q; ll ans = INF; rep(i, 0, y){ rep(j, 0, q){ pair<ll, ll> P = ChineseRem(x+i, a, p+j, b); if(P.first != 0) ans = min(ans, P.first); } } if(ans == INF) cout << "infinity" << endl; else cout << ans << endl; return; } int main() { int t; cin >> t; while(t--) solve(); return 0; }
#include <bits/stdc++.h> #define int long long #define mod 998244353 using namespace std; const int O = 3e5 + 5; int tree[O * 4], lazy[O * 4]; void Push(int id, int l, int r){ int &x = lazy[id]; int mid = (l + r) / 2; if (x == 0) return; tree[id << 1] += x; lazy[id << 1] += x; tree[id << 1 | 1] += x; lazy[id << 1 | 1] += x; x = 0; } void Update(int id, int l, int r, int u, int v, int val){ if (l > v || r < u) return; Push(id, l, r); if (u <= l && r <= v){ tree[id] += val; lazy[id] += val; return; } int mid = (l + r) / 2; Update(id << 1, l, mid, u, v, val); Update(id << 1 | 1, mid + 1, r, u, v, val); tree[id] = tree[id << 1] + tree[id << 1 | 1]; } int Get(int id, int l, int r, int u, int v){ Push(id, l, r); if (l > v || r < u) return 0; if (u <= l && r <= v) return tree[id]; int mid = (l + r) / 2; return Get(id << 1, l, mid, u, v) + Get(id << 1 | 1, mid + 1, r, u, v); } main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; vector <int> a(n + 1), b(n + 1); for (int i = 1; i <= n; ++ i) cin >> a[i], a[i] += i; for (int i = 1; i <= n; ++ i) cin >> b[i], b[i] += i; vector <int> val; for (int i = 1; i <= n; ++ i) val.push_back(b[i]); sort(val.begin(), val.end()); val.resize(distance(val.begin(), (unique(val.begin(), val.end())))); vector <vector <int>> g; g.resize((int)val.size() + 1); for (int i = 1; i <= n; ++ i){ int id = upper_bound(val.begin(), val.end(), a[i]) - val.begin() - 1; if (val[id] != a[i]) return cout << -1, 0; g[id].push_back(i); } int h = val.size(); for (int i = 0; i < h; ++ i) reverse(g[i].begin(), g[i].end()); int ans = 0; for (int i = 1; i <= n; ++ i){ int id = upper_bound(val.begin(), val.end(), b[i]) - val.begin() - 1; int x = g[id].back(); ans += (x + Get(1, 1, n, x, x) - i); Update(1, 1, n, 1, x, 1); g[id].pop_back(); } cout << ans; }
#include <bits/stdc++.h> #define sz(c) int(c.size()) #define rep(i, a, b) for (int i = a; i < (b); ++i) #define per(i, a, b) for (int i = (b)-1; i >= (a); --i) using namespace std; using ll = long long; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #ifdef LOCAL #include <local/debug.h> #else #define debug(...) (void)0 #endif int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); int N; cin >> N; vector<int> A(N); rep(i, 0, N) cin >> A[i]; vector<int> B(N); rep(i, 0, N) cin >> B[i]; set<pair<int, int>> s; ordered_set<int> ord; rep(i, 0, N) { s.insert({A[i] + i, i + 1}); ord.insert(i + 1); } ll res = 0; rep(i, 0, N) { int val = B[i] + i; auto it = s.lower_bound({val, 0}); if (it == s.end() || it->first != val) { if (it != s.end()) assert(it->first > val); res = -1; break; } int pos = it->second; ll order = ord.order_of_key(pos); res += order; debug(val, pos, order); s.erase(it); ord.erase(pos); } cout << res << '\n'; }
#include<bits/stdc++.h> using namespace std; bool cmp(char c1, char c2) { if (c1 == c2) return 1; if (c1 == 'R' && c2 == 'S') return 1; if (c1 == 'P' && c2 == 'R') return 1; if (c1 == 'S' && c2 == 'P') return 1; return 0; } int main() { int n, k; string s; cin >> n >> k >> s; for (int i = 1; i <= k; i++) { s += s; string t; for (int j = 0; j < n * 2; j += 2) if (cmp(s[j], s[j+1])) t.push_back(s[j]); else t.push_back(s[j+1]); s = t; } cout << s[0] << endl; }
#line 2 "header.hpp" //%snippet.set('header')% //%snippet.fold()% #ifndef HEADER_H #define HEADER_H // template version 2.0 #include <bits/stdc++.h> using namespace std; // varibable settings template <class T> constexpr T inf = numeric_limits<T>::max() / 2.1; #define _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i) #define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__) #define _rrep(i, n) rrepi(i, 0, n) #define rrepi(i, a, b) for (ll i = (ll)((b)-1); i >= (ll)(a); --i) #define r_rep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__) #define each(i, a) for (auto &&i : a) #define all(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) #define pb(a) push_back(a) #define mp(a, b) make_pair(a, b) #define mt(...) make_tuple(__VA_ARGS__) #define ub upper_bound #define lb lower_bound #define lpos(A, x) (lower_bound(all(A), x) - A.begin()) #define upos(A, x) (upper_bound(all(A), x) - A.begin()) template <class T, class U> inline void chmax(T &a, const U &b) { if ((a) < (b)) (a) = (b); } template <class T, class U> inline void chmin(T &a, const U &b) { if ((a) > (b)) (a) = (b); } template <typename X, typename T> auto make_table(X x, T a) { return vector<T>(x, a); } template <typename X, typename Y, typename Z, typename... Zs> auto make_table(X x, Y y, Z z, Zs... zs) { auto cont = make_table(y, z, zs...); return vector<decltype(cont)>(x, cont); } template <class T> T cdiv(T a, T b){ assert(a >= 0 && b > 0); return (a+b-1)/b; } #define is_in(x, a, b) ((a) <= (x) && (x) < (b)) #define uni(x) sort(all(x)); x.erase(unique(all(x)), x.end()) #define slice(l, r) substr(l, r - l) typedef long long ll; typedef long double ld; template <typename T> using PQ = priority_queue<T, vector<T>, greater<T>>; void check_input() { assert(cin.eof() == 0); int tmp; cin >> tmp; assert(cin.eof() == 1); } #if defined(PCM) || defined(LOCAL) #else #define dump(...) ; #define dump_1d(...) ; #define dump_2d(...) ; #define cerrendl ; #endif #endif /* HEADER_H */ //%snippet.end()% #line 2 "solve.cpp" template<class T=ll> using vec = vector<T>; struct Fast { Fast() { std::cin.tie(0); ios::sync_with_stdio(false); } } fast; using vi = vector<int>; using vvi = vector<vi>; using pii = pair<int, int>; using iii = tuple<int, int, int>; int solve() { ll n;cin>>n; vec<ll> d(n); rep(i, n){ string s;cin>>s; d[i] = (s == "AND" ? 1 : 0); } auto dp0 = make_table(n+1, 0LL); auto dp1 = make_table(n+1, 0LL); dp0[0] = 1; dp1[0] = 1; rep(i, 0, n){ if (d[i] == 1){ dp0[i+1] += dp1[i]; // x[i] = 0 dp1[i+1] += dp1[i]; // x[i] = 1 dp0[i+1] += dp0[i]; // x[i] = 0 dp0[i+1] += dp0[i]; // x[i] = 1 } else{ dp1[i+1] += dp1[i]; // x[i] = 0 dp1[i+1] += dp1[i]; // x[i] = 1 dp0[i+1] += dp0[i]; // x[i] = 0 dp1[i+1] += dp0[i]; // x[i] = 1 } } cout << dp1[n] << endl; return 0; } signed main(){/*{{{*/ solve(); #if defined(PCM) || defined(LOCAL) check_input(); #endif return 0; }/*}}}*/
#include<bits/stdc++.h> using namespace std; using Long = long long; using Double = long double; using pii = pair<int,int>; using pll = pair<Long,Long>; using vi = vector<int>; using vl = vector<Long>; using vs = vector<string>; using vii = vector<pii>; using vll = vector<pll>; #define ff first #define ss second #define pb push_back #define pf push_front #define fore( i, from, to ) for( int i = from; i < to; ++i ) #define forn( i, n ) fore(i, 0, n ) #define fori( i, from, to ) for( int i = to - 1; i >= from; --i ) #define forin( i, n ) fori(i, 0, n ) #define forit( it, cnt ) for( auto &it : cnt ) #define endl '\n' #define db(x) cout << "[ " << #x << " = " << x << " ]" << endl #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define sz(v) (int) v.size() #define PI acos(-1.0) #define INF 2e9 #define MOD 1e9 + 7 #define EPS 1e-6 #define fast ios::sync_with_stdio(false); cin.tie(nullptr) int main(){ fast; int n; cin >> n; vector<int> v(n); forn(i, n) cin >> v[i]; int mx = 0; int ans = 1; fore( i, 2, 1001 ){ int cnt = 0; forn( j, n){ if( v[j] % i == 0 ) cnt++; } if( mx < cnt ){ ans = i; mx = cnt; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N; vector<int> A(100); cin >> N; for (size_t i = 0; i < N; i++) { cin >> A[i]; } int maxcount = 0, count, ans; for (size_t i = 2; i <= 1000; i++) { count = 0; for (size_t j = 0; j < N; j++) { if (A[j] % i == 0) { count++; } } if (count >= maxcount) { maxcount = count; ans = i; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define rep(i,n) for(int i=0;i<(int)(n);i++) #define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++) #define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++) #define codefor int test;scanf("%d",&test);while(test--) #define INT(...) int __VA_ARGS__;in(__VA_ARGS__) #define LL(...) ll __VA_ARGS__;in(__VA_ARGS__) #define yes(ans) if(ans)printf("yes\n");else printf("no\n") #define Yes(ans) if(ans)printf("Yes\n");else printf("No\n") #define YES(ans) if(ans)printf("YES\n");else printf("NO\n") #define vector1d(type,name,...) vector<type>name(__VA_ARGS__) #define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__)) #define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__))) #define umap unordered_map #define uset unordered_set using namespace std; using ll = long long; const int MOD=1000000007; const int MOD2=998244353; const int INF=1<<30; const ll INF2=(ll)1<<60; //入力系 void scan(int& a){scanf("%d",&a);} void scan(long long& a){scanf("%lld",&a);} template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);} template<class T> void scan(T& a){cin>>a;} template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);} void in(){} template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);} //出力系 void print(const int& a){printf("%d",a);} void print(const long long& a){printf("%lld",a);} void print(const double& a){printf("%.15lf",a);} template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);} template<class T> void print(const T& a){cout<<a;} template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}} void out(){putchar('\n');} template<class T> void out(const T& t){print(t);putchar('\n');} template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);} //デバッグ系 template<class T> void dprint(const T& a){cerr<<a;} template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}} void debug(){cerr<<endl;} template<class T> void debug(const T& t){dprint(t);cerr<<endl;} template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);} ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; } ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; } ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;} template<class T> void chmax(T &a,const T b){if(b>a)a=b;} template<class T> void chmin(T &a,const T b){if(b<a)a=b;} int main(){ codefor{ LL(l,r); ll ans=0,n=r-2*l+1; if(n>=0){ ans=n*n; ans-=n*(n-1)/2; } out(ans); } }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < n; ++i) using ll = long long; using P = pair<int, int>; int main() { ll T; cin >> T; rep(i, T) { ll L, R; cin >> L >> R; if (R - L < L) { cout << 0 << endl; continue; } ll a = (R - 2 * L + 1); ll b = (R - 2 * L + 2); if (a % 2 == 0) a /= 2; else b /= 2; ll ans = a * b; cout << ans << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; template <class T> inline bool chmax(T &a, T b) { if(a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if(a > b) { a = b; return 1; } return 0; } #define DEBUG #ifdef DEBUG template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << '(' << p.first << ',' << p.second << ')'; return os; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { os << '{'; for(int i = 0; i < (int)v.size(); i++) { if(i) { os << ','; } os << v[i]; } os << '}'; return os; } void debugg() { cerr << endl; } template <class T, class... Args> void debugg(const T &x, const Args &... args) { cerr << " " << x; debugg(args...); } #define debug(...) \ cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__) #define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl #else #define debug(...) (void(0)) #define dump(x) (void(0)) #endif struct Setup { Setup() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } __Setup; using ll = long long; #define ALL(v) (v).begin(), (v).end() #define RALL(v) (v).rbegin(), (v).rend() #define repl(i, a, b) for(int i = a; i < int(b); i++) #define rep(i, n) repl(i, 0, n) const int INF = 1 << 30; const ll LLINF = 1LL << 60; constexpr int MOD = 1000000007; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; //------------------------------------- int main() { int N; cin >> N; vector<vector<int>> G(N); rep(i, N) { string s; cin >> s; rep(j, N) if(s[j] == '1') G[j].push_back(i); } double ans = 0; rep(i, N) { vector<bool> seen(N, false); auto dfs = [&](auto dfs, int v) -> void { if(seen[v]) return; seen[v] = true; for(int u : G[v]) dfs(dfs, u); }; dfs(dfs, i); ans += 1.0 / (double)(count(ALL(seen), true)); } cout << ans << endl; }
/* このコード、と~おれ! Be accepted! ∧_∧  (。・ω・。)つ━☆・*。 ⊂   ノ    ・゜+.  しーJ   °。+ *´¨)          .· ´¸.·*´¨) ¸.·*¨)           (¸.·´ (¸.·'* ☆ */ #include <cstdio> #include <algorithm> #include <string> #include <cmath> #include <cstring> #include <vector> #include <numeric> #include <iostream> #include <random> #include <map> #include <unordered_map> #include <queue> #include <regex> #include <functional> #include <complex> #include <list> #include <cassert> #include <iomanip> #include <set> #include <stack> #include <bitset> #include <array> #include <chrono> //#pragma GCC target("arch=skylake-avx512") //#pragma GCC target("avx2") //#pragma GCC optimize("O3") //#pragma GCC optimize("Ofast") //#pragma GCC target("sse4") //#pragma GCC optimize("unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define repeat(i, n, m) for(int i = n; i < (m); ++i) #define rep(i, n) for(int i = 0; i < (n); ++i) #define printynl(a) printf(a ? "yes\n" : "no\n") #define printyn(a) printf(a ? "Yes\n" : "No\n") #define printYN(a) printf(a ? "YES\n" : "NO\n") #define printim(a) printf(a ? "possible\n" : "imposible\n") #define printdb(a) printf("%.50lf\n", a) #define printLdb(a) printf("%.50Lf\n", a) #define printdbd(a) printf("%.16lf\n", a) #define prints(s) printf("%s\n", s.c_str()) #define all(x) (x).begin(), (x).end() #define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI) #define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L) #define Please return #define AC 0 #define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) using ll = long long; using ull = unsigned long long; constexpr int INF = 1073741823; constexpr int MINF = -1073741823; constexpr ll LINF = ll(4661686018427387903); constexpr ll MOD = 1e9 + 7; constexpr ll mod = 998244353; constexpr long double eps = 1e-6; const long double PI = acosl(-1.0L); using namespace std; void scans(string& str) { char c; str = ""; scanf("%c", &c); if (c == '\n')scanf("%c", &c); while (c != '\n' && c != -1 && c != ' ') { str += c; scanf("%c", &c); } } void scanc(char& str) { char c; scanf("%c", &c); if (c == -1)return; while (c == '\n') { scanf("%c", &c); } str = c; } double acot(double x) { return PI / 2 - atan(x); } ll LSB(ll n) { return (n & (-n)); } template<typename T> inline T chmin(T& a, const T& b) { if (a > b)a = b; return a; } template<typename T> inline T chmax(T& a, const T& b) { if (a < b)a = b; return a; } //cpp_int #if __has_include(<boost/multiprecision/cpp_int.hpp>) #include <boost/multiprecision/cpp_int.hpp> #include <boost/multiprecision/cpp_dec_float.hpp> using namespace boost::multiprecision; #else using cpp_int = ll; #endif //atcoder library #if __has_include(<atcoder/all>) #include <atcoder/all> //using namespace atcoder; #endif /* random_device seed_gen; mt19937 engine(seed_gen()); uniform_int_distribution dist(1, 100); */ /*----------------------------------------------------------------------------------*/ int main() { int n, q; scanf("%d%d", &n, &q); vector<ll> a(n); rep(i, n)scanf("%lld", &a[i]); while (q--) { ll k; scanf("%lld", &k); ll ng = 0, ok = (ll)2e18; while (abs(ng - ok) > 1) { ll mid = (ng + ok) / 2; ll idx = distance(a.begin(), upper_bound(all(a), mid)); if (mid - idx >= k)ok = mid; else ng = mid; } printf("%lld\n", ok); } Please AC; }
#include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<string> #include<vector> #include<stack> #include<bitset> #include<cstdlib> #include<cmath> #include<set> #include<list> #include<deque> #include<map> #include<queue> using namespace std; typedef long long ll; ll n,k; ll a[100]; void YPO() { ll len=0,i; while(n) { a[len]=n%10; n/=10; len++; } sort(a,&a[len]); ll x1=0,x2=0; for(i=0;i<len;i++) { x1*=10; x1+=a[i]; } for(i=len-1;i>=0;i--) { x2*=10; x2+=a[i]; } n=x2-x1; } int main() { ll i,j; scanf("%lld%lld",&n,&k); for(i=0;i<k;i++) { YPO(); } printf("%lld\n",n); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n,x; cin>>n>>x; int a[n]; for(int i=0;i<n;i++){ cin>>a[i]; if(a[i] == x) a[i] = 0; } for(int i=0;i<n;i++){ cin>>a[i]; if(a[i] != 0) cout<<a[i]<<" "; } }
#include<bits/stdc++.h> using namespace std ; int main() { int n; cin>>n; int a[n],b[1001]={0}; int i; for(i=0;i<n;i++) cin>>a[i]; int j; for(i=2;i<=1000;i++) { for(j=0;j<n;j++) { if(a[j]%i==0) b[i]++; } } int max=0; for(i=2;i<=1000;i++) { if(b[i]>max) max=b[i]; } for(i=2;i<=1000;i++) { if(b[i]==max) { cout<<i; break; } } }
#include<bits/stdc++.h> #define int long long const int N=500050; using namespace std; map<int,int> a; int n,x,s[N],ans; main(){ scanf("%lld",&n),a[0]=1; for(int i=1;i<=n;i++)scanf("%lld",&x),s[i]=s[i-1]+((i&1)?-x:x),a[s[i]]++; for(int i=1;i<=n;i++)--a[s[i]],ans+=a[s[i]]; printf("%lld",ans); }
#include <bits/stdc++.h> using namespace std; using ll = long long; const int INFint = 1e9+1; const ll INFll = (ll)1e18+1; const int MOD=1e9+7; int main(){ int N,M; cin>>N>>M; vector<vector<int>> G(N,vector<int>()); for(int i(0);i<M;i++){ int a,b; cin>>a>>b; a--;b--; G[a].push_back(b); G[b].push_back(a); } int K; cin>>K; vector<int> C(K); for(int i(0);i<K;i++){ cin>>C[i]; C[i]--; } vector<vector<int>> d(K, vector<int>(N,INFint)); for(int k(0);k<K;k++){ queue<int> q; d[k][C[k]] = 0; q.push(C[k]); while(!q.empty()){ int v = q.front();q.pop(); for (int next: G[v]){ if(d[k][next] == INFint){ d[k][next] = d[k][v] + 1; q.push(next); } } } } int ans(INFint); vector<vector<int>> dp(1<<K,vector<int>(K,INFint)); for(int i(0);i<K;i++) dp[1<<i][i] = 0; for(int i(1);i<(1<<K);i++){ for(int j(0);j<K;j++){ if(i&(1<<j)){ // iのなかにjが入っている時のみ考える(jが通過していないパターンは矛盾しているのであり得ない) for(int k(0);k<K;k++){ dp[i][j] = min(dp[i][j], dp[i-(1<<j)][k]+ d[k][C[j]]); //集めるdpでkからjにくるパターンを考えている } } } } for(int i(0);i<K;i++) ans = min(ans, dp[(1<<K)-1][i]); if(ans == INFint) cout << -1 << endl; else cout << ans+1 << endl; return 0; }
#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; signed main(){ int N, M; cin >> N >> M; vector<int> A(M), B(M); rep(i,0,M) cin >> A[i] >> B[i]; int K; cin >> K; vector<int> C(K); rep(i,0,K) cin >> C[i]; vector<vector<int>> edges(N+1); rep(i,0,M) { edges[A[i]].emplace_back(B[i]); edges[B[i]].emplace_back(A[i]); } vector<vector<int>> distances(K, vector<int>(K, INT_MAX)); rep(i,0,K) { vector<int> distances_(N+1, INT_MAX); priority_queue<pair<int, int>, vector<pair<int,int>>, greater<>> q; q.push({0, C[i]}); distances_[C[i]] = 0; while (!q.empty()) { auto [cost, current] = q.top(); q.pop(); for (const auto& next : edges[current]) { if (distances_[next] > cost + 1) { distances_[next] = cost + 1; q.push({distances_[next], next}); } } } rep(j,0,K) { if (distances_[C[j]] == INT_MAX) { cout << -1 << endl; return 0; } distances[i][j] = distances_[C[j]]; } } vector<vector<int>> dp(1 << K, vector<int>(K, INT_MAX)); rep(i,0,K) dp[1<<i][i] = 1; rep(i,1,1<<K) rep(j,0,K) { if(dp[i][j] == INT_MAX) continue; rep(k,0,K) { dp[i | 1<<k][k] = min(dp[i | 1<<k][k], dp[i][j] + distances[j][k]); } } cout << *min_element(all(dp[(1<<K) - 1])) << endl; return 0; }
#include<iostream> #include<vector> using namespace std; using ll = long long; int main() { int n; ll x; cin >> n >> x; vector<int> A(n); for (auto& Ai : A) cin >> Ai; ll ans = (ll)2e18; for (int base = 1; base <= n; base++) { vector<vector<int>> T(base + 1, vector<int>(base, -(int)2e9)); T[0][(base-(x%base))%base] = 0; for (auto ind : A) { for (int i = base - 1; i >= 0; i--) { for (int j = 0; j < base; j++) { if (T[i][j] + ind > T[i + 1][(j + ind) % base]) { T[i + 1][(j + ind) % base] = T[i][j] + ind; } } } } if (T[base][0] < 0) continue; ans = min(ans, (x - T[base][0]) / base); } cout << ans << '\n'; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; #define REP(i, n) for(ll i = 0LL; i < (ll)(n); i++) #define REPR(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--) #define FOR(i, n, m) for(ll i = (ll)n; i < (ll)(m); i++) #define ALL(x) (x).begin(),(x).end() #define MOD 1000000007 #define INF (1LL << 62) #define PI (acos(-1)) #define PRINT(x) std::cout << x << endl ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;} ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll countDigit(ll n) { return floor(log10(n) + 1); } typedef pair <ll,ll> P; static const ll dx[8] = {0,1,0,-1, 1, -1, 1, -1}, dy[8] = {1,0,-1,0,1,1,-1,-1}; template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { for (int i = 0; i < (int)v.size(); ++i) os << v[i] << " "; return os; } template <typename T1, typename T2> ostream& operator<<(ostream& os, const map<T1, T2>& m) { for (auto p : m) os << "<" << p.first << ", " << p.second << "> "; return os; } int main() { ll N, K; cin >> N >> K; vector<vector<ll>> mat(N, vector<ll>(N, 0)); REP(i, N) { REP(j, N){ cin >> mat[i][j]; } } vector<ll> indices(N-1); iota(indices.begin(), indices.end(), 1); ll cnt = 0; do { ll sum = mat[0][indices[0]]; REP(i, N-2) { sum += mat[indices[i]][indices[i+1]]; } sum += mat[indices[N-2]][0]; if (K == sum) cnt++; } while (std::next_permutation(indices.begin(), indices.end())); cout << cnt << endl; return 0; }
#include<bits/stdc++.h> #define show(x) cerr << #x << " = " << x << '\n'; using namespace std; #define int long long #pragma GCC optimize(2) int n, q; vector<int> a; void solve() { cin >> n >> q; for(int i = 1; i <= n; i ++) { int t; cin >> t; a.push_back(t); } for(int i = 1; i <= q; i ++) { int m; cin >> m; int l = 0, r = 2e18; while(l < r) { int mid = l + r >> 1; int p = upper_bound(a.begin(), a.end(), mid) - a.begin() - 1; int x = mid - p; if(x <= m) { l = mid + 1; } else { r = mid; } } cout << l << '\n'; } } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); solve(); }
/*NEVER GIVE UP*/ /*First try brute force and check if it is in the range of time complexity*/ /*Then try to solve the problem in mathematical form*/ /*Then try to imagine how the final ans will look like*/ /*Write on paper if still not able to get*/ /*Try to think diff. algorithms and data structures that could solve the problem*/ #include <bits/stdc++.h> using namespace std; long long power(long long x, long long y, long long p) { long long res = 1; // Initialize result x = x % p; // Update x if it is more than or // equal to p if (x == 0) return 0; // In case x is divisible by p; while (y > 0) { // If y is odd, multiply x with result if (y & 1) res = (res*x) % p; // y must be even now y = y>>1; // y = y/2 x = (x*x) % p; } return res; } int main() {long long n=0,q=0,d=0,k=0; cin>>n>>q; long long a[n];vector<long long> dp(n); for(long long j=0;j<n;j++) cin>>a[j]; sort(a,a+n); dp[0]=a[0]-1; for(long long j=1;j<n;j++) { dp[j]=dp[j-1]+(a[j]-a[j-1]-1); } for(long long j=0;j<q;j++) { cin>>k; d=lower_bound(dp.begin(),dp.end(),k)-dp.begin(); if(d==n) cout<<a[n-1]+(k-dp[n-1])<<endl; else if(d==0) cout<<k<<endl; else { cout<<a[d]-dp[d]+k-1<<endl; } } }
// UTF−8 #include<bits/stdc++.h> using namespace std; using ll = long long int; using lc = complex<double>; /* #include<atcoder/all> */ /* using namespace atcoder; */ template<class T>bool chmax(T &a, const T &b) { return (a<b ? (a=b,1) : 0); } template<class T>bool chmin(T &a, const T &b) { return (a>b ? (a=b,1) : 0); } int main(void) { constexpr ll MOD = 1 ? 1e9+7 : 998244353; const double PI = acos(-1); constexpr double eps = 1e-10; cout << fixed << setprecision(32); cin.tie(0); ios::sync_with_stdio(false); if(1) { ll n; cin >> n; lc p0, p1; { double x0, y0, x1, y1; cin >> x0 >> y0 >> x1 >> y1; p0 = lc(x0, y0); p1 = lc(x1, y1); } lc c = (p0 + p1) / 2.0; lc res = (p0 - c) * lc(cos(2 * PI / n), sin(2 * PI / n)) + c; cout << real(res) << ' ' << imag(res) << endl; } return 0; }
#include <iostream> #include <string> #include <vector> #include <queue> #include <algorithm> #include <cmath> #include <complex> using namespace std; using ll = long long; using C = complex<double>; C inC() { double x, y; cin >> x >> y; return C(x, y); } int main() { int n; cin >> n; C s = inC(); C t = inC(); C o = (s+t)/2.0; double pi = acos(-1); double rad = 2 * pi / n; C r(cos(rad), sin(rad)); C ans = o + (s - o) * r; printf("%.10f %.10f\n", ans.real(), ans.imag()); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define scan(a,n) for(long long int index=0;index<n;index++) cin>>a[index]; #define print(a,n) for(long long int index=0;index<n;index++) cout<<a[index]<<" ";cout<<endl; #define mod 1000000007 #define pb push_back #define mp make_pair #define ss second #define ff first #define vli vector<long long int> #define vlli vector<pair<long long int,long long int>> #define vsi vector<string> #define all(n) n.begin(),n.end() #define forn(i,a,b) for(i=a;i<b;i++) ll mul(ll x,ll y){ return (x*y)%mod;} ll power(ll x, ll y) {ll res = 1; x %= mod; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;} ll mod_inv(ll x) {return power(x, mod - 2);} ll fact(ll n) {ll res = 1; for (ll i = 2; i <= n; i++) res = mul(res , i); return res; } ll nCr(ll n, ll r) { return mul(fact(n),mod_inv(mul(fact(r),fact(n - r))));} int main() { fast; #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif ll t=1; // cin>>t; while(t--){ ll a,b,c,d; cin>>a>>b>>c>>d; cout<<max(a,b)-min(c,d)<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int a, b, c, d, maks=-1e9+7; cin >> a >> b >> c >> d; for(int i=a;i<=b;++i){ for(int j=c;j<=d;++j){ maks=max(maks, i-j); } } cout << maks << '\n'; } /* stuff you should look for * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * WRITE STUFF DOWN */
#include <bits/stdc++.h> using namespace std; typedef long long ll; struct Edge{ int v,c,d; inline ll arrive(ll t){ return t+c+ll(d)/(t+1); } inline ll tmin(ll t0){ return arrive(max(t0,ll(round(sqrt(d)))-1)); } }; int main(){ int n,m; cin>>n>>m; vector<vector<Edge>> adj(n); for(int i=0;i<m;i++){ int a,b,c,d; cin>>a>>b>>c>>d; a--; b--; adj[a].push_back({b,c,d}); adj[b].push_back({a,c,d}); } priority_queue<pair<ll,int>> pq; vector<ll> dist(n,-1); pq.push({0,0}); while(!pq.empty()){ int u=pq.top().second; ll t0=-pq.top().first; pq.pop(); if(dist[u]!=-1)continue; dist[u]=t0; for(auto &e:adj[u]) if(dist[e.v]==-1) pq.push({-e.tmin(t0),e.v}); } cout<<dist[n-1]<<endl; }
//wtrl,everybody hangbeat me #include<bits/stdc++.h> /*#include<iostream> #include<string> #include<cmath> #include<cstdio> #include<cctype> #include<cstring> #include<iomanip> #include<cstdlib> #include<ctime> #include<set> #include<map> #include<utility> #include<queue> #include<vector> #include<stack> #include<sstream> #include<algorithm>*/ using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef vector<pii> vii; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<vi> vvi; typedef pair<ll,ll> pll; /*=====================================================================*/ #define pb push_back #define rep(i,n) for(int i=0;i<(int)(n);i++) #define all(s) (s).begin(),(s).end() #define repd(i,n) for(int i=n-1;i>=0;i--) #define forn(i,p,n) for(int i=p;i<=n;i++) #define ford(i,p,n) for(int i=n;i>=p;i--) #define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();++i) #define INF 1e9 #define PI acos(-1) /*=====================================================================*/ string int_to_string(ll n) { string s=""; while(n) { ll now=n%10; s+=now+'0'; n/=10; } reverse(s.begin(),s.end()); return s; } ll string_to_int(string s) { ll n=0; rep(i,s.size()) { n*=10; n+=s[i]-'0'; } return n; } /*======================================================================*/ const int dx[]={-1,0,1,0}; const int dy[]={0,-1,0,1}; const int month[2][12]={{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31}}; struct node { ll to; ll c; ll d; }; vector<node> v[100010]; ll dist[100010]; bool use[100010]; inline ll calc(ll down,ll up) { ll res=max(down,(ll)sqrt((ll)up)); while(up/(res+1)>up/(res+2)) { res++; } return res-down+up/(res+1); } void dijkstra(ll now) { priority_queue<pll> pq; pq.push(pll((ll)0,(ll)now)); dist[now]=(ll)0; while(!pq.empty()) { pll now=pq.top(); pq.pop(); ll nd=now.second; if(use[nd]==1) { continue; } use[nd]=1; rep(i,v[nd].size()) { ll cost=v[nd][i].c+calc(dist[nd],v[nd][i].d); //cout<<cnt<<endl; if(dist[nd]+cost>=dist[v[nd][i].to]) { continue; } dist[v[nd][i].to]=cost+dist[nd]; pq.push(pll(-dist[v[nd][i].to],(ll)v[nd][i].to)); } } } void solve() { int n,m; cin>>n>>m; rep(i,m) { ll a,b,c,d; scanf("%lld%lld%lld%lld",&a,&b,&c,&d); v[a].pb({b,c,d}); v[b].pb({a,c,d}); } forn(i,1,n) { dist[i]=1e18; } dijkstra(1); printf("%lld",dist[n]==1e18?-1:dist[n]); } /*======================================================================*/ int main() { // std::ios::sync_with_stdio(false); /* freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); */ /*====================================================================*/ int t=1; //cin>>t; while(t--) { solve(); } return 0; } /* 注意数组越界,vector长度为0的时候循环会RE 注意输入顺序 注意循环时int*int爆ll 注意答案存爆ll */
//#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 a, b, c, d; cin >> a >> b >> c >> d; cout << (b -c) << "\n"; } int main(void) { // ll t; cin >> t; rep(i, t) solve(); }
// execute g++ main.cpp -std=c++14 -I C:\Users\naoya\Desktop\code\Atcoder #include<bits/stdc++.h> //#include<atcoder/all> typedef long long ll; typedef long double ld; using namespace std; //using namespace atcoder; using Pii = pair<int, int>; using Pll = pair<ll, ll>; //ordered_set 重複不可 #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // use set_function + find_by_order(select itr-num) #define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i) #define ALL(x) (x).begin(),(x).end() #define pb push_back ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;} ll lcm(ll a,ll b){return a/gcd(a,b)*b;} 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;} char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}; char Alpha[26] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'}; int dx[4] = {-1, 1, 0, 0}; int dy[4] = {0, 0, 1, -1}; //cout << std::fixed << std::setprecision(15) << y << endl; //小数表示 ll rtime(ll now, ll cost, ll dcost){ auto f = [&](double t) { return (double)t + (double)cost + ((double)dcost/(double)(t+1)); }; ll st = now; double left = now, right = 5e17; int cnt = 100; while (cnt--) { if(abs(right - left) < 0.5) break; double c1 = ((double)left * 2 + (double)right) / 3; double c2 = ((double)left + (double)right * 2) / 3; // もしf(c2)のほうが良い(小さい)なら、駄目な方lowを更新する if (f(c1) > f(c2)) left = c1; else right = c2; } auto f2 = [&](ll t) { return t + cost + (dcost/(t+1)); }; ll k = (ll)right; ll kk = max((ll)left, k+1); ll kkk = max(st, k-1); return min({f2(k), f2(kk), f2(kkk)}); } /////////////////////////////////////////////////////////////// struct edge{ll to, cost, dcost;}; class Dijkstra{ public: vector<vector<edge>> G; vector<ll> d; Dijkstra(int n){ G = vector<vector<edge> >(n); d = vector<ll>(n, 2e18); } void add_edge(ll from, ll to, ll cost, ll dcost){ edge e = {to, cost, dcost}; G[from].pb(e); } void dijkstra(ll s){ priority_queue<Pll, vector<Pll>, greater<Pll> > que; d[s] = 0; que.push(Pll(0, s)); while(!que.empty()){ Pll p = que.top(); que.pop(); ll v = p.second; if(d[v] < p.first) continue; for(int i = 0; i < G[v].size(); i++){ //二部探索でどこまで待つか考える edge e = G[v][i]; ll cc = rtime(min(d[v], p.first), e.cost, e.dcost); if(d[e.to] > cc){ d[e.to] = cc; que.push(Pll(d[e.to], e.to)); } } } } }; int main(){ int n, m; cin >> n >> m; Dijkstra dijk(n); REP(i,0,m){ ll a, b, c, d; cin >> a >> b >> c >> d; a--; b--; dijk.add_edge(a,b,c,d); dijk.add_edge(b,a,c,d); } dijk.dijkstra(0); if(dijk.d[n-1] == 2e18){ cout << -1 << endl; return 0; } cout << dijk.d[n-1] << endl; }
#include <bits/stdc++.h> #define LL long long #define rep(i,n) for(int i=0;i<n;++i) #define repn(i,n) for(int i=1;i<=n;++i) using namespace std; int qmi(int a, int k, int p) // 快速幂模板 { int res = 1 % p; while (k) { if (k & 1) res = (LL)res * a % p; a = (LL)a * a % p; k >>= 1; } return res; } int C(int a, int b, int p) // 通过定理求组合数C(a, b) { if (a < b) return 0; LL x = 1, y = 1; // x是分子,y是分母 for (int i = a, j = 1; j <= b; i --, j ++ ) { x = (LL)x * i % p; y = (LL) y * j % p; } return x * (LL)qmi(y, p - 2, p) % p; } int lucas(LL a, LL b, int p) { if (a < p && b < p) return C(a, b, p); return (LL)C(a % p, b % p, p) * lucas(a / p, b / p, p) % p; } const int N = 1e6+10; int b[N]; int main() { int n; cin>>n; string s; cin>>s; for(int i=0;i<n;i++) b[i] = lucas(n-1,i,3); //for(int i=0;i<n;i++) cout<<b[i]<<' '; //B 0 W 1 R 2 if(n&1) { int ans = 0; for(int i=0;i<=n;i++) { if(s[i]=='W') ans += 1 * b[i]; if(s[i]=='R') ans += 2 * b[i]; } ans %= 3; if(ans==2) cout<<"R"<<endl; else if(ans==1) cout<<"W"<<endl; else cout<<"B"<<endl; }else{ int ans = 0; for(int i=0;i<n;i++) { if(s[i]=='W') ans -= 1 * b[i]; if(s[i]=='R') ans -= 2 * b[i]; } ans %= 3; ans +=3 ; if(ans==2) cout<<"R"<<endl; else if(ans==1) cout<<"W"<<endl; else cout<<"B"<<endl; } }
#include<iostream> #include<unordered_map> #include<cstring> using namespace std; const int N = 400010; typedef long long ll; int m, q; ll n; int pow10(ll n) { ll res = 1%q; int i = -1; while(n >> ++i); --i; while(~i) { int j = n >> i & 1; res = (res * res) % q; if(j) res = (res * 10) % q; --i; } return res; } int main() { cin >> n >> m; q = m * m; printf("%d", pow10(n) / m % m); }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using P = pair<int, int>; int main() { int n, m, q; cin >> n >> m >> q; vector<P> wv(n); rep(i, n) { int w, v; cin >> w >> v; wv[i] = {v, -w}; } sort(wv.begin(), wv.end(), greater<>()); vector<ll> x(m); rep(i, m) cin >> x[i]; rep(i, q) { int l, r; cin >> l >> r; l--, r--; multiset<ll> s; rep(j, m) { if (j >= l && j <= r) continue; s.insert(x[j]); } ll res = 0; rep(j, n) { auto it = s.lower_bound(-wv[j].second); if (it == s.end()) continue; res += wv[j].first; s.erase(it); } cout << res << endl; } }
#include <bits/stdc++.h> #define MOD 1000000007LL using namespace std; typedef long long ll; typedef pair<int,int> P; class segtree{ public: static const int N=1<<18; ll dp[1<<19]; segtree(){ memset(dp,0,sizeof(dp)); } void update(int k,ll v){ k+=N-1; dp[k]+=v; while(k>0){ k=(k-1)/2; dp[k]=dp[k*2+1]+dp[k*2+2]; } } ll query(int a,int b,int k=0,int l=0,int r=N){ if(b<=l || r<=a)return 0; if(a<=l && r<=b)return dp[k]; int mid=(l+r)/2; ll vl=query(a,b,k*2+1,l,mid); ll vr=query(a,b,k*2+2,mid,r); return vl+vr; } }; segtree sumx,cntx; segtree sumy,cnty; int n,m,q; ll sum; ll a[200005]; ll b[200005]; int t[200005],x[200005]; ll y[200005]; vector<ll> yi; int main(void){ scanf("%d%d%d",&n,&m,&q); cntx.update(0,n); cnty.update(0,m); yi.push_back(0); for(int i=0;i<q;i++){ scanf("%d%d%lld",&t[i],&x[i],&y[i]); x[i]--; yi.push_back(y[i]); } sort(yi.begin(),yi.end()); yi.erase(unique(yi.begin(),yi.end()),yi.end()); for(int i=0;i<q;i++){ int pos=lower_bound(yi.begin(),yi.end(),y[i])-yi.begin(); if(t[i]==1){ ll val_mi=sumy.query(a[x[i]],yi.size()+1); ll cnt_mi=cnty.query(0,a[x[i]]); sum-=cnt_mi*yi[a[x[i]]]+val_mi; sumx.update(a[x[i]],-yi[a[x[i]]]); cntx.update(a[x[i]],-1); a[x[i]]=pos; sumx.update(a[x[i]],yi[a[x[i]]]); cntx.update(a[x[i]],1); val_mi=sumy.query(a[x[i]],yi.size()+1); cnt_mi=cnty.query(0,a[x[i]]); sum+=cnt_mi*yi[a[x[i]]]+val_mi; //printf("%lld %lld\n",val_mi,cnt_mi); }else{ ll val_mi=sumx.query(b[x[i]],yi.size()+1); ll cnt_mi=cntx.query(0,b[x[i]]); sum-=cnt_mi*yi[b[x[i]]]+val_mi; sumy.update(b[x[i]],-yi[b[x[i]]]); cnty.update(b[x[i]],-1); b[x[i]]=pos; sumy.update(b[x[i]],yi[b[x[i]]]); cnty.update(b[x[i]],1); val_mi=sumx.query(b[x[i]],yi.size()+1); cnt_mi=cntx.query(0,b[x[i]]); sum+=cnt_mi*yi[b[x[i]]]+val_mi; } printf("%lld\n",sum); } return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5+5; typedef long long LL; int n,m,q,a[maxn],b[maxn]; LL ans; struct Seg { LL sum[maxn<<5]; int root,ch[maxn<<5][2],cnt[maxn<<5],tot; void upd(int &u,int l,int r,int p,int v) { if(!u)u = ++tot; cnt[u]+=v,sum[u] += v*p; if(l == r)return ; int mid = l+r>>1; p<=mid?upd(ch[u][0],l,mid,p,v):upd(ch[u][1],mid+1,r,p,v); } int Cnt(int u,int l,int r,int x,int y){ if(!u||l>y||r<x)return 0; if(l>=x&&r<=y)return cnt[u]; int mid = l+r>>1; return Cnt(ch[u][0],l,mid,x,y)+Cnt(ch[u][1],mid+1,r,x,y); } LL Sum(int u,int l,int r,int x,int y){ if(!u||l>y||r<x)return 0; if(l>=x&&r<=y)return sum[u]; int mid = l+r>>1; return Sum(ch[u][0],l,mid,x,y)+Sum(ch[u][1],mid+1,r,x,y); } }t1,t2; int main() { scanf("%d %d %d",&n,&m,&q); for(int i=1;i<=n;++i)t1.upd(t1.root,0,1e8,0,1); for(int i=1;i<=m; ++i)t2.upd(t2.root,0,1e8,0,1); while(q--) { int ty,x,y,les; scanf("%d %d %d",&ty,&x,&y); if(ty == 1){ les = t2.Cnt(t2.root,0,1e8,0,a[x]); ans -= t2.Sum(t2.root,0,1e8,a[x]+1,1e8)+1ll*les*a[x]; t1.upd(t1.root,0,1e8,a[x],-1),a[x] = y,t1.upd(t1.root,0,1e8,a[x],1); les = t2.Cnt(t2.root,0,1e8,0,a[x]); ans += t2.Sum(t2.root,0,1e8,a[x]+1,1e8)+1ll*les*a[x]; } if(ty == 2){ les = t1.Cnt(t1.root,0,1e8,0,b[x]); ans -= t1.Sum(t1.root,0,1e8,b[x]+1,1e8)+1ll*les*b[x]; t2.upd(t2.root,0,1e8,b[x],-1),b[x] = y,t2.upd(t2.root,0,1e8,b[x],1); les = t1.Cnt(t1.root,0,1e8,0,b[x]); ans += t1.Sum(t1.root,0,1e8,b[x]+1,1e8)+1ll*les*b[x]; } printf("%lld\n",ans); } return 0; }
/* हरे कृष्ण हरे कृष्ण कृष्ण कृष्ण हरे हरे हरे राम हरे राम राम राम हरे हरे */ #include<bits/stdc++.h> using namespace std; #define pb emplace_back #define pob pop_back typedef long long int lli; #define test lli t; cin>>t; while(t--) #define ff first #define ss second #define F(n) for(lli i=0;i<n;i++) #define pf pop_front #define lb lower_bound #define ub upper_bound #define setbits(x) __builtin_popcountll(x) #define zerobits(x) __builtin_ctzll(x) #define bs binary_search #define all(x) x.begin(),x.end() #define nl "\n" #define loop(i,s,n) for(lli i=s;i<n;i++) #define pp(a) for(auto x : a) cout<<x<<" "; cout<<nl; #define mem(arr,x) memset(arr,x,sizeof(arr)) #define mod 1000000007 #define inf 1e18 #define tt(n) cin>>n; lli a[n]; loop(i,0,n) cin>>a[i]; #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define ps(x,y) fixed<<setprecision(y)<<x lli solve(lli n) { lli r,i; while(n!=0) { r=n%10; if(r==7) return -1; n/=10; } return 0; } lli decToOctal(lli n) { lli octalNum[100]; lli i = 0,f=0; while (n != 0) { octalNum[i] = n % 8; n = n / 8; i++; } for (lli j = i - 1; j >= 0; j--) { if(octalNum[j]==7) { f=1; break; } } if(f) return -1; else return 0; } int main() { fast; lli n,i,j,c,x=0; cin>>n; lli a[n],s=0; loop(i,0,n) cin>>a[i]; sort(a,a+n); loop(i,0,n) { s+=(i*a[i])-((n-1-i)*a[i]); } cout<<s; return 0; }
/* “The only way that we can live is if we grow. The only way we can grow is if we change. The only way we can change is if we learn. The only way we can learn is if we are exposed. And the only way that we are exposed is if we throw ourselves into the open.” *************************************** ************************ ********************************** */ #include <bits/stdc++.h> using namespace std; //---------------------mishra ka idea------------------ #define int long long #define double long double #define pb push_back #define pf push_front #define pii pair<int,int> #define vi vector<int> #define vii vector<pii> #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() #define x first #define y second #define endl '\n' #define sz(x) (int)(x).size() #define ull unsigned long long //------------------------mishra ka idea------------------- //-------------------------alsi hu mai----------------------- #define fo(i,l,u) for(i=l;i<u;i++) #define rfo(i,l,u) for(i=l;i>=u;i--) #define allfo(s) for(auto it=(s).begin();it!=(s).end();it++) #define _init(b) memset(b,-1,sizeof(b)) #define _init0(b) memset(b,0,sizeof(b)) #define MOD 1000000007 #define hell 998244353 #define output(x) cout << (x ? "YES" : "NO")<<endl; #define Output(x) cout << (x ? "Yes" : "No")<<endl; //-------------------------alsi hu mai----------------------- //--------------------het se uthaya--------------------- #define MOD2 (998244353) #define MOD3 (1000000009) #define PI acos(-1) #define eps (1e-8) #define INF (1e18) template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";} template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;} template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;} template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;} ifstream cinn("in.txt");ofstream coutt("out.txt"); int poww(const int &a,int b,const int &m=MOD){if(b==0)return 1;int x=poww(a,b/2,m);x=x*x%m;if(b&1)x=x*a%m;return x;} //--------------------het se uthaya------------------------------------------------------------------- int gcd(int a, int b) {if(a>b)swap(a,b) ; if (a == 0) return b; return gcd(b % a, a); } int rint(int l , int r){return rand()%(r-l+1) + l ;} //---------------------------aab code dekho bahut template dekh liya--------------------------------- bool poss(int a , int b){ return (a<b && a>-b); } signed main() { // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); int i,j,x,n,k; cin>>n>>k; map<int,int> mp; mp[k]=1; vi v; fo(i,0,n){ cin>>x; v.pb(x); } v.pb(INF); reverse(all(v)); int a , b , c; fo(i,1,n){ map<int,int> np; for(auto aa : mp){ // cout<<">>"<<aa.x<<","<<aa.y<<"<< "; a = aa.x/v[i]; if(poss(aa.x-a*v[i],v[i]) && poss(a,v[i-1]/v[i]))np[aa.x-a*v[i]]+=aa.y; if(poss(aa.x-(a+1)*v[i],v[i]) && poss(a+1,v[i-1]/v[i]) )np[aa.x-(a+1)*v[i]]+=aa.y; if(poss(aa.x-(a-1)*v[i],v[i]) && poss(a-1,v[i-1]/v[i]))np[aa.x-(a-1)*v[i]]+=aa.y; } //cout<<endl; swap(np,mp); } int ans=0; for(auto aa : mp){ //cout<<">>"<<aa.x<<","<<aa.y<<"<< "; ans+=aa.y; } cout<<ans<<endl; return 0; }
// Problem: F - Valid payments // Contest: AtCoder - AtCoder Beginner Contest 182 // URL: https://atcoder.jp/contests/abc182/tasks/abc182_f // Memory Limit: 1024 MB // Time Limit: 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) #include <bits/stdc++.h> #define ll long long int #define ii int #define du double #define jmp "\n" #define vl vector<ll> #define vvl vector<vl> #define pb push_back #define printv(v) \ for (auto x : v) \ cout << x << " "; \ cout << jmp; #define vi vector<int> #define vb vector<bool> #define ump unordered_map #define SORT(v) sort(v.begin(), v.end()) #define REV(x) reverse(x.begin(), x.end()) #define all(x) x.begin(), x.end() #define SET(x, a) memset(x, a, sizeof(x)) #define si(x) (ll) x.size() #define ff first #define ss second #define I(a) \ for (auto &x : a) \ cin >> x; #define iin insert #define deb(x) cout << "test " << #x << "=" << x << jmp #define deb2(x, y) cout << "test " << #x << "=" << x << "," << #y << "=" << y << jmp using namespace std; const ll nax = 1e5 + 5; vl a; ll n, k; map<pair<ll, ll>, ll> dp; ll r(ll x, ll i) { if (i == n - 1) return (x % a[i] == 0); if (dp.count({i, x})) return dp[{i, x}]; if (x % a[i + 1]) return dp[{i, x}] = r(x - (x % a[i + 1]), i + 1) + r(x + a[i + 1] - (x % a[i + 1]), i + 1); else return dp[{i, x}] = r(x, i + 1); } void solve() { // ll n, k; cin >> n >> k; a = vl(n); I(a); cout << r(k, 0); } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll t = 1; // cin >> t; while (t--) solve(); return 0; }
#define _DEBUG #include "bits/stdc++.h" #define CHOOSE(a) CHOOSE2 a #define CHOOSE2(a0,a1,a2,a3,a4,x,...) x #define debug_1(x1) cout<<#x1<<": "<<x1<<endl #define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl #define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl #define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl #define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl #ifdef _DEBUG #define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__) #else #define debug(...) #endif #define rep(index,num) for(int index=0;index<(int)num;index++) #define rep1(index,num) for(int index=1;index<=(int)num;index++) #define brep(index,num) for(int index=(int)num-1;index>=0;index--) #define brep1(index,num) for(int index=(int)num;index>0;index--) #define scan(argument) cin>>argument #define prin(argument) cout<<argument<<endl #define kaigyo cout<<endl #define eps 1e-7 #define mp(a1,a2) make_pair(a1,a2) #define ALL(a) (a).begin(),(a).end() #define rALL(a) (a).rbegin(),(a).rend() #define puba(a) emplace_back((a)) typedef long long ll; typedef long double ld; using namespace std; typedef pair<ll,ll> pll; typedef pair<int,int> pint; typedef vector<int> vint; typedef vector<ll> vll; typedef vector<pint> vpint; typedef vector<pll> vpll; template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } ll INFl=(ll)1e+18+1; int INF=1e+9+1; int main(){ ll N,M,A[200001]; scan(N>>M); if(M==0){ prin(1); return 0; } else if(M==N){ prin(0); return 0; } rep(i,M){ scan(A[i]); } sort(A,A+M); vll sa; if(A[0]!=1) sa.puba(A[0]-1); rep(i,M-1){ // debug(i,A[i]); if(A[i+1]-A[i]>=2){ sa.puba(A[i+1]-A[i]-1); } } //debug(A[M-1]); if(A[M-1]!=N) sa.puba(N-A[M-1]); sort(ALL(sa)); ll K=sa[0]; //debug(K); ll ans=0; for(const auto& s:sa){ // debug(s); ans+=s/K+(s%K!=0); } prin(ans); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int count = 0; int X; double A = 1.0000/3.000; X = pow(N,A)+0.00001; int Y,Z; for(int i = 0; i < X ;i++){ Y = sqrt(N/(i+1)); //cout << Y << endl; for(int j = i; j < Y ;j++){ Z = N/(i+1)/(j+1); //cout << i << "F" << j << "F"<< Z << endl; for(int k = j;k < Z ; k++){ //cout << i+1 << " " << j+1 << " " << k+1 << endl; if(i!=j && j!=k && k!=i)count +=6; else if(i==j && j==k)count++; else count +=3; } } } cout<< count << endl; }
#include <bits/stdc++.h> #define pb push_back #define ss second #define ff first #define all(x) x.begin(), x.end() #define INF 3000000000000001 // 3e15 #define ll_max 9000000000000000000 #define PI 3.14159265358979323846L #define fill(a, n, x) for(int i = 0; i < n; i++) a[i] = x; #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); typedef long long int ll; typedef long double ld; typedef pair<ll,ll> pll; const ll mod = 1000000007; const ll N = 100100; const ll M = log2(N) + 1; struct point { ll x, y; }; template<typename T> T fast_exp(T x,T n) { if(n == 0) return 1; T ans = 1; if(n % 2 == 0) { ans = fast_exp(x, n / 2); ans = ans * ans % mod; } else ans = fast_exp(x, n - 1) * x % mod; return ans; } struct node { int vertex; bool mx; bool mn; node(int v, bool a, bool b) { vertex = v; mx = a; mn = b; } }; struct cmp { bool operator () (pair<ll, node> a, pair<ll, node> b) { if(a.ff < b.ff) return 1; return 0; } }; ll fact[N], infact[N]; void work() { fact[0] = fact[1] = infact[0] = infact[1] = 1; for(ll i = 2; i < N; i++) { fact[i] = fact[i - 1] * i % mod; infact[i] = fast_exp(fact[i], mod - 2); } } ll ncr(ll n, ll r) { return fact[n] * infact[n - r] % mod * infact[r] % mod; } int main() { fast; int _ = 1; //cin >> _; work(); int test = 0; while(_--) { test++; ll n, m, q, x = 0, y = 0, ans = 0, k = 0; cin >> n; x = 0, y = 0; ll a[n + 1], b[n + 1]; a[0] = 0; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 1; i <= n; i++) cin >> b[i]; for(int i = 1; i <= n; i++) { a[i] = max(a[i - 1], a[i]); ans = max(a[i] * b[i], ans); cout << ans << "\n"; } } return 0; }
//Author: AnandRaj doubleux #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int,int> pii; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<pii> vpii; typedef pair<ll,ll> pll; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<pll> vpll; #define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define test() int t;cin>>t;while(t--) #define all(v) v.begin(),v.end() #define prinp(p) cout<<p.first<<" "<<p.second<<endl #define prinv(V) for(auto v:V) cout<<v<<" ";cout<<endl #define take(V,f,n) for(int in=f;in<f+n;in++) cin>>V[in] #define what(x) cerr<<#x<<" = "<<x<<endl #define KStest() int t,t1;cin>>t;t1=t;while(t--) #define KScout cout<<"Case #"<<t1-t<<": " mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int MOD = 1e9+7,MAX = 1e6+5; const ll INF = 1e18+5; int main() { int n; cin>>n; vi A(n),B(n); take(A,0,n); take(B,0,n); int maxA = 0; ll maxAB = 0; for(int i=0;i<n;i++) { maxA = max(maxA,A[i]); maxAB = max(maxAB,(ll)B[i]*maxA); cout<<maxAB<<endl; } }
/** * @author Macesuted ([email protected]) * @copyright Copyright (c) 2021 */ #include <bits/stdc++.h> using namespace std; #define int long long #define maxn 3005 #define mod 1000000007 int a[maxn], f[maxn][maxn], cnt[maxn]; void work(void) { int n; cin >> n; for (register int i = 1; i <= n; i++) cin >> a[i]; for (register int j = n; j; j--) { memset(cnt, 0, sizeof(cnt)); cnt[0] = 1; for (register int i = n, tat = 0; i; i--) { tat = (tat + a[i]) % j; f[i][j] = cnt[tat]; cnt[tat] = (cnt[tat] + f[i][j + 1]) % mod; } } cout << f[1][1] << endl; return; } signed main() { ios::sync_with_stdio(false); int _ = 1; // cin >> _; while (_--) work(); return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); #define int long long #define ld long double using namespace __gnu_pbds; using namespace std; using ll = long long; template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; void DBG() { cerr << "]" << endl; } template<class H, class... T> void DBG(H h, T... t) { cerr << h; if (sizeof...(t)) cerr << ", "; DBG(t...); } #ifndef ONLINE_JUDGE #define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__) #else #define dbg(...) 0 #endif const int N = 3e3 + 5; const int mod = 1e9 + 7; const int INF = 1e18; const double eps = 1e-5; const double PI = acos(-1); mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); struct mi { int v; explicit operator int() const { return v; } mi() { v = 0; } mi(ll _v):v(_v%mod) { v += (v<0)*mod; } }; mi& operator+=(mi& a, mi b) { if ((a.v += b.v) >= mod) a.v -= mod; return a; } mi& operator-=(mi& a, mi b) { if ((a.v -= b.v) < 0) a.v += mod; return a; } mi operator+(mi a, mi b) { return a += b; } mi operator-(mi a, mi b) { return a -= b; } mi operator*(mi a, mi b) { return mi((ll)a.v*b.v); } mi& operator*=(mi& a, mi b) { return a = a*b; } mi pow(mi a, ll p) { assert(p >= 0); // asserts are important! return p==0?1:pow(a*a,p/2)*(p&1?a:1); } mi inv(mi a) { assert(a.v != 0); return pow(a,mod-2); } mi operator/(mi a, mi b) { return a*inv(b); } mi dp[N][N]; int prv[N][N]; int s[N], ind[N]; void solve(int tc){ int n; cin >> n; vector<mi> a(n+1), pref(n+1); for(int i=1; i<=n; i++) cin >> a[i].v; memset(dp, 0, sizeof dp); dp[0][0] = 1; for(int k=1; k<=n; k++){ for(int i=1; i<=n; i++){ s[i] = (s[i-1] + a[i].v)%k; } for(int i=0; i<k; i++){ ind[i] = -1; } for(int i=0; i<=n; i++){ prv[k][i] = ind[s[i]]; ind[s[i]] = i; } } for(int i=1; i<=n; i++){ for(int j=1; j<=n; j++){ if(prv[j][i] != -1){ dp[i][j] = dp[prv[j][i]][j-1] + dp[prv[j][i]][j]; } // cout << prv[i][j] << ' '; } // cout << endl; } mi ans = 0; for(int j=1; j<=n; j++) ans += dp[n][j]; cout << ans.v << '\n'; } int32_t main(){ fast; int tc = 1; // cin >> tc; for(int tt=1; tt<=tc; tt++){ solve(tt); } return 0; }
// C - Bowls and Dishes #include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (ll i=0; i < n; i++) // 0 ~ n-1 template<class T> inline bool chmax(T& a, T& b) { if (a < b) { int tmp=a; a=b; b=tmp; return 1; } return 0; } template<class T> inline bool chmin(T& a, T& b) { if (a > b) { int tmp=a; a=b; b=tmp; return 1; } return 0; } const ll mod=1000000000+7; int main(){ int n,m; cin>>n>>m; vector<int>a(m),b(m); rep(i,m){ cin>>a[i]>>b[i]; } int k; cin>>k; vector<int>c(k),d(k); rep(i,k){ cin>>c[i]>>d[i]; } int ans=0; for(int bit=0;bit<(1<<k);bit++){ // 0:put d, 1:put c vector<int>dishes(n); int cnt=0; for(int i=0;i<k;i++){ // k people if(bit&(1<<i)){ dishes[c[i]-1]++; }else{ dishes[d[i]-1]++; } } for(int i=0;i<m;i++){ if(dishes[a[i]-1]>=1&&dishes[b[i]-1]>=1){ cnt++; } } ans=max(ans,cnt); } cout<<ans<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define pi acos(-1.0) #define endl "\n" #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) typedef long long ll; typedef unsigned long long ull; bool sortbysecc(const pair<int,int> &a, const pair<int,int> &b){ return (a.second < b.second); } ll plates[200], ans; void solve(ll a[], ll b[], ll c[], ll d[], ll i, ll n, ll k){ if(i==k){ ll cnt=0; for(ll j=0;j<n;j++){ if(plates[a[j]]&&plates[b[j]]){ cnt++; } } ans=max(cnt, ans); return; } plates[c[i]]++; solve(a, b, c, d, i+1, n, k); plates[c[i]]--; plates[d[i]]++; solve(a ,b, c, d, i+1, n, k); plates[d[i]]--; } int main() { fastio; ll tc, n, m, k, i, j, f, caseno=1; cin>>n>>m; ll a[m], b[m]; for(i=0;i<m;i++){ cin>>a[i]>>b[i]; } cin>>k; ll c[k], d[k]; for(i=0;i<k;i++){ cin>>c[i]>>d[i]; } ans=0; solve(a, b, c, d, 0, m, k); cout<<ans; }
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) int n; int dp[18][(1<<18)]; int cost[18][18]; int solve(int i,int mask) { if(mask==0) return cost[i][0]; if(dp[i][mask]!=-1) return dp[i][mask]; int ans=INT_MAX; for(int j=1;j<n;j++) { if(mask&(1<<j)) { ans=min(ans,cost[i][j]+solve(j,mask^(1<<j))); } } return dp[i][mask]=ans; } int32_t main() { fast; cin>>n; memset(dp,-1,sizeof(dp)); vector<vector<int>>v(n,vector<int>(3)); for(int i=0;i<n;i++) { for(int j=0;j<3;j++) { cin>>v[i][j]; } } for(int i=0;i<n;i++) { for(int j=i+1;j<n;j++) { cost[i][j]=abs(v[j][0]-v[i][0])+abs(v[j][1]-v[i][1])+max(0,v[j][2]-v[i][2]); cost[j][i]=abs(v[i][0]-v[j][0])+abs(v[i][1]-v[j][1])+max(0,v[i][2]-v[j][2]); } } for(int i=0;i<n;i++) { cost[i][i]=0; } cout<<solve(0,(((1<<n)-1)^1))<<endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; // -------------------------------------------------------- template<class T> bool chmax(T& a, const T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> bool chmin(T& a, const T b) { if (b < a) { a = b; return 1; } return 0; } #define FOR(i,l,r) for (int i = (l); i < (r); ++i) #define REP(i,n) FOR(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 SUM(c) accumulate(ALL(c), 0) #define SUMLL(c) accumulate(ALL(c), 0LL) #define SZ(c) ((int)(c).size()) #define debug(x) cerr << #x << " = " << (x) << '\n'; using P = pair<int,int>; using VP = vector<P>; using VVP = vector<VP>; using VS = vector<string>; using VI = vector<int>; using VVI = vector<VI>; using VLL = vector<ll>; using VVLL = vector<VLL>; using VB = vector<bool>; using VVB = vector<VB>; using VD = vector<double>; using VVD = vector<VD>; 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 int INF = 1 << 30; // 1073741824 // static const ll INF = 1LL << 62; // 4611686018427387904 // -------------------------------------------------------- // #include <atcoder/all> // using namespace atcoder; static const int MAX_N = 17; VVI dp((1 << MAX_N), VI(MAX_N, INF)); struct city { int X, Y, Z; }; int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(10); int N; cin >> N; vector<city> C(N); REP(i, N) { int X, Y, Z; cin >> X >> Y >> Z; C[i] = city{X, Y, Z}; } VVI G(N, VI(N, INF)); REP(i, N-1) FOR(j,i+1,N) { city a = C[i]; city b = C[j]; G[i][j] = abs(b.X - a.X) + abs(b.Y - a.Y) + max(0, b.Z - a.Z); G[j][i] = abs(a.X - b.X) + abs(a.Y - b.Y) + max(0, a.Z - b.Z); } dp[0][0] = 0; FOR(S, 1, (1 << N)) { FOR(u, 0, N) { if (!(S & (1 << u))) continue; int T = S - (1 << u); FOR(v, 0, N) { if (G[v][u] == INF) continue; dp[S][u] = min(dp[S][u], dp[T][v] + G[v][u]); } } } int ans = dp[(1 << N) - 1][0]; cout << ans << '\n'; return 0; }
#include <iostream> #include <cstdio> #include <string> #include <algorithm> #include <utility> #include <cmath> #include <vector> #include <stack> #include <queue> #include <deque> #include <set> #include <map> #include <tuple> #include <numeric> #include <functional> using namespace std; typedef long long ll; typedef vector<ll> vl; typedef vector<vector<ll>> vvl; typedef pair<ll, ll> P; #define rep(i, n) for(ll i = 0; i < n; i++) #define exrep(i, a, b) for(ll i = a; i <= b; i++) #define out(x) cout << x << endl #define exout(x) printf("%.10f\n", x) #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define pb push_back #define re0 return 0 const ll mod = 1000000007; const ll INF = 1e16; // a^n (mod.MOD)を求める。計算量はO(logn) ll modpow(ll a, ll n, ll MOD = mod) { if(n == 0) { return 1; } if(n%2 == 1) { return (a * modpow(a, n-1, MOD)) % MOD; } return (modpow(a, n/2, MOD) * modpow(a, n/2, MOD)) % MOD; } // nCrをO(r)で求める。 ll Comb(ll n, ll r) { if(n < r) { return 0; } if(r > n-r) { return Comb(n, n-r); } ll Mul = 1, Div = 1; rep(i, r) { Mul *= (n-i); Div *= (i+1); Mul %= mod; Div %= mod; } return Mul * modpow(Div, mod - 2) % mod; } int main() { ll n, m; cin >> n >> m; ll s = 0; rep(i, n) { ll a; cin >> a; s += a; } out(Comb(n+m, n+s)); re0; }
/* Written By mafailure */ #define ill //In the name of God #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/tree_policy.hpp> #include <functional> // for less using namespace std; using namespace __gnu_pbds; #define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define endl "\n" #ifdef ill #define int long long #endif template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; } template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; } template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } void dbg_out() { cerr << endl; } template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); } #ifdef AATIF_DEBUG #define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__) #else #define dbg(...) #endif //#define int long long // int dx[]={-1,1,0,0}; int dy[]={0,0,1,-1}; // int dx[]={2,2,-2,-2,1,1,-1,-1}; int dy[]={1,-1,1,-1,2,-2,2,-2}; const long long mod = 1e9 + 7; const double eps=1e-9; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<string> vs; typedef vector<bool> vb; typedef pair<int, int> ii; typedef vector< pair< int, int > > vii; typedef map<int, int> mii; typedef pair<int, ii> pip; typedef pair<ii, int> ppi; #define arrinp(arr,init,final,size,type) type* arr=new type[size];for(int i=init;i<final;i++)cin>>arr[i]; #define cr2d(arr,n,m,t) t**arr=new t*[n];for(int i=0;i<n;i++)arr[i]=new t[m]; #define w(t) int t;cin>>t; while(t--) #define takeInp(n) int n;cin>>n; #define fr(i,init,final) for(int i=init;i<final;i++) #define frr(i,init,final) for(int i=init;i>=final;i--) #define Fr(i,final) for(int i=0;i<final;i++) #define Frr(i,first) for(int i=first;i>=0;i--) #define fi first #define se second #define mp make_pair #define pb push_back #define all(c) (c).begin(),(c).end() #define rall(c) (c).rbegin(),(c).rend() #define debug(x) cerr<<">value ("<<#x<<") : "<<x<<endl; #define setb __builtin_popcount #define lsone(n) (n&(-n)) #define rlsone(n) (n&(n-1)) #define clr(a,b) memset(a,b,sizeof(a)) const int inf= INT_MAX; //struct point_i{int x,y;}; struct point_i{int x,y; point_i(){ x=0; y=0;} point_i(int x_,int y_){x=(x_);y=(y_) ;} }; struct point { float x,y; point (){x=y=0.0;} point (float x_,float y_){x=(x_); y=(y_);} bool operator < (point other) const{ if(fabs(x-other.x)>eps)return x<other.x; return y<other.y; } bool operator == (point other) const { return fabs(other.x-x)<=eps&& fabs(other.y-y)<=eps; } } ; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; vi init(string s) { istringstream sin(s); int n; vi arr; while(sin>>n)arr.push_back(n); return arr; } int power(int x, int y) { if(y==0)return 1; int u=power(x,y/2); u=(u*u)%mod; if(y%2)u=(x*u)%mod; return u; } int gcd(int a,int b) { if(a<b)return gcd(b,a); return (b==0?a:(a%b?gcd(b,a%b):b)); } int gcd_e(int a,int b,int &x,int &y) { if(b==0){x=1; y=0; return a;} int x1,y1; int p=gcd_e(b,a%b,x1,y1); x=y1; y=x1-(a/b)*y1; return p; } int mul(int a,int b) { return (a*b)%mod; } int inv(int n) { return power(n,mod-2); } signed main() { IOS int n; cin>>n; int m; cin>>m; vi a(n); fr(i,0,n) cin>>a[i]; int sum=accumulate(all(a),n); int num=1; int den=1; m+=n; fr(i,0,sum) { num=mul(num,m-i); den=mul(den,sum-i); } cout<<mul(num,inv(den))<<endl; //fr(i,0,n) sum+=a[i]; }
#include<iostream> #include<stdio.h> #include<string> #include<vector> #include<map> #include<tuple> #include<algorithm> #include<cmath> #include<limits> #include<set> #include<deque> #include<queue> #include<stack> using namespace std; #define int long long int #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define dup(x,y) (((x)+(y)-1)/(y)) int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } int lcm(int a, int b) { return a / gcd(a, b) * b; } 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; } typedef pair<int, int>P; const int MOD = 1e9 + 7; //const int MOD = 998244353; const int INF = 1e18; const long double PI = (acos(-1)); signed main() { string S; cin >> S; if (S.size() == 1) { if (S[0] == '8')cout << "Yes"; else cout << "No"; return 0; } if (S.size() <= 2) { int a = '1' + S[0] - 1; int b = '1' + S[1] - 1; int c = 10 * a + b; int d = 10 * b + a; if (c % 8 == 0 || d % 8 == 0) { cout << "Yes"; } else cout << "No"; return 0; } map<int, int>m; for (auto i : S)m[i]++; for (int i = 1; i <= 9; i++) { for (int j = 1; j <= 9; j++) { for (int k = 1; k <= 9; k++) { char ci = '1' + i - 1; char cj = '1' + j - 1; char ck = '1' + k - 1; m[ci]--; m[cj]--; m[ck]--; if (m[ci] < 0 || m[cj] < 0 || m[ck] < 0) { m[ci]++; m[cj]++ + m[ck]++; continue; } int num = i * 100 + j * 10 + k; if (num % 8 == 0) { cout << "Yes"; return 0; } m[ci]++; m[cj]++ + m[ck]++; } } } cout << "No"; }
#include <iostream> #include <string> #include <algorithm> #include <map> using namespace std; int naive(int N, string S, string T) { map<string, int> M; M[S] = 0; for (int d=0; d<100; d++) { for (auto it: M) { string s = it.first; int n = it.second; if (n==d) { for (int i=1; i<N; i++) if (s[i]=='1') { string s2 = s; s2[i] = '0'; s2[i-1] = s2[i-1]^1; if (M.count(s2)==0) M[s2] = n+1; } } } } if (M.count(T)==0) return -1; return M[T]; } long long solve(int N, string S, string T) { long long ans = 0; int p1 = 0; for (int i=0; i<N; i++) { if (S[i]=='0' && T[i]=='1') { p1 = max(p1, i+1); while (p1<N && S[p1]=='0') p1++; if (p1>=N) return -1; S[p1] = '0'; S[i] = '1'; ans += p1-i; } else if (S[i]=='1' && T[i]=='0') { p1 = max(p1, i+1); while (p1<N && S[p1]=='0') p1++; if (p1>=N) return -1; S[i] = '0'; S[p1] = '0'; ans += p1-i; } } return ans; } int main() { //while (true) //{ // int N = 8; // string S; // for (int i=0; i<N; i++) // S += "01"[rand()%2]; // string T; // for (int i=0; i<N; i++) // T += "01"[rand()%2]; // int a1 = solve(N, S, T); // int a2 = naive(N, S, T); // //cout<<a1<<" "<<a2<<endl; // if (a1!=a2) // { // cout<<N<<endl; // cout<<S<<endl; // cout<<T<<endl; // cout<<a1<<" "<<a2<<endl; // return 0; // } //} int N; cin>>N; string S; cin>>S; string T; cin>>T; cout<<solve(N, S, T)<<endl; }
#pragma region header #include <bits/stdc++.h> using namespace std; #define rep(i,n)for(int i=0;i<(n);i++) #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define pb push_back #define int ll #define each(i, a) for (auto &&i : (a)) using ll = long long; using ld = long double; using vi = vector<int>; using vvi = vector<vi>; using vs = vector<string>; using vvs = vector<vs>; using vd = vector<ld>; using vvd = vector<vd>; using vb = vector<bool>; using vvb = vector<vb>; using P = pair<int, int>; using vp = vector<P>; using int128 = __int128_t;//cin coutはできない int gcd(int a,int b){return b?gcd(b,a%b):a;} int lcm(int a,int b){return a / gcd(a, b) * b;}; int dx[4]={1,0,-1,0}; int dy[4]={0,1,0,-1}; template <class T> void CVEC(const T &v) { int c = v.size() - 1; for (int i = 0; i < c; i++) cout << v[i] << ' '; if (c > -1) cout << v[c]; cout << '\n'; } #pragma endregion header vvi es; vi a, b; vi depth, dp; void DepthDFS(int v, int d){ depth[v] = d; for(auto nv : es[v]){ if(depth[nv] == -1) DepthDFS(nv, d+1); } } void ImosDFS(int v, int now){ now += dp[v]; dp[v] = now; for(auto nv : es[v]){ if(depth[nv] > depth[v]){ ImosDFS(nv, now); } } } signed main(){ int n; cin >> n; es.resize(n); a.resize(n-1); b.resize(n-1); depth.assign(n, -1); dp.assign(n,0); rep(i,n-1){ cin >> a[i] >> b[i]; a[i]--, b[i]--; es[a[i]].push_back(b[i]); es[b[i]].push_back(a[i]); } DepthDFS(0,0); int q; cin >> q; rep(i,q){ int t, e, x; cin >> t >> e >> x; e--; int va, vb; if(t == 1){ va = a[e]; vb = b[e]; }else{ va = b[e]; vb = a[e]; } if(depth[va] < depth[vb]){ //根に足す dp[0] += x; //通らない方を引く dp[vb] -= x; }else{ //部分木に足す dp[va] += x; } } ImosDFS(0,0); rep(i,n){ cout << dp[i] << endl; } }
#include<bits/stdc++.h> #define F(i,l,r) for(register int i=l;i<=r;i++) #define D(i,r,l) for(register int i=r;i>=l;i--) #define ll long long #define mem(a,b) memset(a,b,sizeof(a)) #define p_b push_back #define m_p make_pair #define il inline #define fi first #define se second const int INF=0x7f7f7f7f,N=2e5+5; using namespace std; template<typename T> void rd(T &num) { char ch=getchar(); num=0; int k=1; while((ch>'9'||ch<'0')&&ch!='-') ch=getchar(); if(ch=='-') k=-1,ch=getchar(); while(ch<='9'&&ch>='0') num=num*10+ch-'0',ch=getchar(); num*=k; } int n,T; int u[N],v[N]; int op,e;ll x; vector<int> mp[N]; int L[N],R[N],dep[N]; int cnt; void dfs(int p,int fa) { dep[p]=dep[fa]+1; L[p]=++cnt; F(i,0,(int)mp[p].size()-1) { int to=mp[p][i]; if(to!=fa) dfs(to,p); } R[p]=cnt; } ll ans[N<<2],tag[N<<2]; il int ls(int p) {return p<<1;} il int rs(int p) {return p<<1|1;} il void push_up(int p) {ans[p]=ans[ls(p)]+ans[rs(p)];} il void f(int p,int l,int r,ll k) { ans[p]+=(r-l+1)*k; tag[p]+=k; } il void push_down(int p,int l,int r) { if(tag[p]) { int mid=(l+r)>>1; f(ls(p),l,mid,tag[p]); f(rs(p),mid+1,r,tag[p]); tag[p]=0; } } il void upd(int p,int l,int r,int nl,int nr,ll k) { if(nl<=l&&nr>=r) { f(p,l,r,k); return ; } push_down(p,l,r); int mid=(l+r)>>1; if(nl<=mid) upd(ls(p),l,mid,nl,nr,k); if(nr>mid) upd(rs(p),mid+1,r,nl,nr,k); push_up(p); } il ll query(int p,int l,int r,int ql,int qr) { ll res=0; if(ql<=l&&qr>=r) return ans[p]; push_down(p,l,r); int mid=(l+r)>>1; if(ql<=mid) res+=query(ls(p),l,mid,ql,qr); if(qr>mid) res+=query(rs(p),mid+1,r,ql,qr); return res; } int main() { rd(n); F(i,1,n-1) { rd(u[i]),rd(v[i]); mp[u[i]].p_b(v[i]),mp[v[i]].p_b(u[i]); } dfs(1,0); // F(i,1,n) { // printf("dep:%d st_l:%d st_r:%d\n",dep[i],L[i],R[i]); // } rd(T); while(T--) { rd(op),rd(e),rd(x); int st=u[e],nd=v[e]; if(op==2) swap(st,nd); if(dep[st]>dep[nd]) upd(1,1,n,L[st],R[st],x); else upd(1,1,n,L[1],R[1],x),upd(1,1,n,L[nd],R[nd],-x); } F(i,1,n) printf("%lld\n",query(1,1,n,L[i],L[i])); return 0; }
//#pragma GCC optimize ("O3") //#pragma GCC target ("sse4") //#pragma GCC optimize("Ofast") //#pragma GCC optimize("Ofast,unroll-loops") //#pragma GCC target("avx,avx2,fma") #include <algorithm> #include <array> #include <cassert> //#include <chrono> #include <cmath> //#include <cstring> //#include <functional> //#include <iomanip> #include <iostream> #include <map> //#include <numeric> //#include <queue> //#include <random> #include <set> #include <vector> using namespace std; #define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> //using namespace __gnu_pbds; #define int long long #define ll int #define all(a) a.begin(),a.end() #define rev(a) a.rbegin(),a.rend() //typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; //less_equal for multiset #define ar array #define pb push_back #define fi(a,b) for(int i=a;i<(b);i++) #define fj(a,b) for(int j=a;j<(b);j++) #define fk(a,b) for(int k=a;k<(b);k++) const double pi=acosl(-1); void solve() { int n,k; cin>>n>>k; vector<pair<int,int>> a(n); vector<int> c(n); fi(0,n) { cin>>a[i].first>>a[i].second>>c[i]; } vector<pair<int,int>> temp; fi(0,n) { temp.pb({a[i].first,(i+1)}); temp.pb({a[i].second+1,-(i+1)}); } sort(all(temp)); int m=temp.size(); // int i=0; // int count=0; int ans=0; multiset<int> s; int index=abs(temp[0].second)-1; int cost=c[index]; s.insert(index); int i=1; // for(auto x:temp) // { // cout<<x.first<<' '; // } // cout<<'\n'; // for(auto x:temp) // { // cout<<x.second<<' '; // } // cout<<'\n'; while(i<m) { // cout<<i<<' '<<cost<<'\n'; index=abs(temp[i].second)-1; if(temp[i].second<0) { int diff=temp[i].first-temp[i-1].first; ans+=diff*min(k,cost); int here=temp[i].first; int prev=i; while(i<n&&temp[i].first==here&&temp[i].second<0) { cost-=c[abs(temp[i].second)-1]; i++; } if(i==prev) { cost-=c[abs(temp[i].second)-1]; i++; } } else { int diff=temp[i].first-temp[i-1].first; ans+=diff*min(k,cost); cost+=c[index]; i++; } } cout<<ans<<'\n'; } signed main() { FAST; int tt=1; //cin>>tt; while(tt--) { solve(); } } //int dx[] = {+1,-1,+0,+0,-1,-1,+1,+1}; // Eight Directions //int dy[] = {+0,+0,+1,-1,+1,-1,-1,+1}; // Eight Directions //int dx[]= {-2,-2,-1,1,-1,1,2,2}; // Knight moves //int dy[]= {1,-1,-2,-2,2,2,-1,1}; // Knight moves // For (a^b)%mod, where b is large, replace b by b%(mod-1)..{because we solve this by introducing log ..do same for general cases} // a+b = (a|b)+(a&b) // a+b = 2*(a&b)+(a^b)
#include <bits/stdc++.h> using namespace std; int main(){ int64_t N, X; cin >> N >> X; string S; cin >> S; int64_t ans = X; for(int i=0;i<N;i++){ if(S.at(i)=='x' && ans>0){ ans--; }else if(S.at(i) == 'o'){ ans++; } } cout << ans << endl; return 0; }
#include <cmath> #include <cstdio> #include <cstring> #include <algorithm> #include <iostream> #include <queue> #define REP(i, n) for(int i = 0; i < (int)(n); ++i) using namespace std; typedef long long ll; double xs[200000+10]; double ys[200000+10]; bool g[105][105]; int visited[105]; int counter; int main(void) { int n; scanf("%d", &n); REP(i, n) { scanf("%lf%lf", &xs[i], &ys[i]); } int start = n; int goal = n+1; double left = 0; double right = 100; REP(iTry, 100) { double mid = (left + right) / 2; REP(i, n) { g[i][i] = true; g[i][start] = g[start][i] = (ys[i] + 100) <= 2*mid; g[i][goal] = g[goal][i] = (100 - ys[i]) <= 2*mid; REP(j, i) { g[i][j] = g[j][i] = sqrt((xs[i]-xs[j])*(xs[i]-xs[j]) + (ys[i]-ys[j])*(ys[i]-ys[j])) <= 2*mid; } } ++counter; queue<int> q; q.push(start); visited[start] = counter; while(!q.empty()){ int cur = q.front(); q.pop(); REP(i, n+2) { if(g[cur][i] && visited[i] != counter) { q.push(i); visited[i] = counter; } } } if(visited[goal] == counter) { right = mid; } else { left = mid; } } printf("%.10f\n", left); return 0; }
/****************************************** By Lord Sanskar Bhargava******************************/ #include<bits/stdc++.h> #include <algorithm> #include <array> #include <cassert> #include <chrono> #include <cmath> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <vector> using namespace std; typedef long long ll; typedef long double ld; typedef complex<ld> cd; typedef pair<int, int> pi; typedef pair<ll,ll> pl; typedef pair<ld,ld> pd; typedef vector<int> vi; typedef vector<ld> vd; typedef vector<ll> vl; typedef vector<pi> vpi; typedef vector<pl> vpl; typedef vector<cd> vcd; #define fastio ios::sync_with_stdio(0);cin.tie(0); #define mp make_pair #define pb push_back #define ep emplace_back #define all(v) (v).begin(),(v).end() #define dll(v) (v).rbegin(),(v).rend() #define set1(x) __builtin_popcount(x) #define gcd(a,b) __gcd(a,b) #define rep(i,a,b) for(ll i=a;i<b;i++) #define bk(i,a,b) for(ll i=a;i>=b;i--) #define ff first #define ss second #define sz(x) ((ll) (x).size()) #define mid(l,r) (l+(r-l)/2) #define inf 1e18 const int mod = 1000000007; template <typename T> T gcd(T a, T b){if(a%b) return gcd(b,a%b);return b;} template <typename T> T lcm(T a, T b){return (a*(b/gcd(a,b)));} template<typename T_vector> void output_vector(const T_vector &v, bool add_one = false, int start = -1, int end = -1) { if (start < 0) start = 0; if (end < 0) end = int(v.size()); for (int i = start; i < end; i++) cout << v[i] + (add_one ? 1 : 0) << (i < end - 1 ? ' ' : '\n'); } unsigned mod_pow(unsigned a, unsigned b, unsigned mod) { unsigned result = 1; while (b > 0) { if (b & 1) result = unsigned(uint64_t(result) * a % mod); a = unsigned(uint64_t(a) * a % mod); b >>= 1; } return result; } ll read(){ ll i; cin>>i; return i; } vl readvl(ll n,ll off=0){ vl v(n); rep(i,0,n)v[i]=read()+off; return v; } string readString(){ string s; cin>>s; return s; } template<class T> T sq(const T& t){ return t*t; } void run_test() { double n; double k=1.08; ll c=206; cin>>n; if((ll)(n*k)<c){ cout<<"Yay!"<<endl;return; } if((ll)(n*k)==c){ cout<<"so-so"<<endl;return; } if((ll)(n*k)>c){ cout<<":("<<endl;return; } } int main(int argc, char const *argv[]) { clock_t begin = clock(); fastio; int tt=1; // cin>>tt; while(tt--) { run_test(); } #ifndef ONLINE_JUDGE clock_t end = clock(); cout<<"\n\nExecuted In: "<<double(end - begin) / CLOCKS_PER_SEC*1000<<" ms"; #endif return 0; }
#include<bits/stdc++.h> #define Fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define Freed freopen ("0in.txt","r",stdin); #define Fout freopen ("0out.txt","w",stdout); #define ll long long int #define pb push_back #define mp make_pair #define pi acos(-1.0) #define Mod 1000000007 #define limit 200008 using namespace std; ll mn[limit],mx[limit]; vector<ll> g[limit]; void dfs(ll u) { ll cost = min(mn[u],mx[u]); for(auto v:g[u]) { if(mn[v]>cost) { mn[v] = cost; //cout <<u<<" "<<v<<' '<<mn[v]<<" "<<mx[v]<<endl; dfs(v); } } } void solve(ll tc) { ll i,j,n,m,k; cin >> n >> m; for(i=0; i<limit; i++) { mn[i] = 1e18; } for(i=0; i<n; i++) cin >> mx[i]; for(i=0; i<m; i++) { ll u, v; cin >> u >> v; u--; v--; g[u].pb(v); } for(i=0; i<n; i++) { dfs(i); } ll ans = -1e18; for(i=0; i<n; i++) { ans = max(ans,mx[i]-mn[i]); //cout <<i<<" "<<mn[i]<<' '<<mx[i]<<" "<<ans<<endl; } cout <<ans<<endl; return ; } int main() { // Fast // Freed // Fout ll tc,tt=1; // cin >> tt; for(tc=1; tc<=tt; tc++) solve(tc); return 0; }
// Author :: <Hitesh_Saini> #include<bits/stdc++.h> #define __speed() ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); #define dbg(x) cout << "[" << __LINE__ << ": "<< #x << " = " << x << " ]\n"; #define tt int t; for (cin>>t; t--; ) #define f0(i, n) for (i = 0; i < (int)(n); i++) #define f1(i, n) for (i = 1; i<= (int)(n); i++) #define cmax(x, y) x = max(x, y); #define cmin(x, y) x = min(x, y); #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define sz(x) (int)(x.size()) #define EB emplace_back #define PB push_back #define endl "\n" #define S second #define F first using namespace std; using mii = map<int, int>; using pii = pair<int, int>; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; const int mod = 1e9+7, mxN = 2e5+5; template<typename... T> void print(T... args) { ((cout << args << " "), ...); cout << endl; } template<typename T1, typename T2> istream& operator>>(istream& in, pair<T1,T2> &a) { in>>a.F>>a.S; return in; } template<typename T1, typename T2> ostream& operator<<(ostream& out, pair<T1,T2> a) { out<<a.F<<" "<<a.S; return out; } template<typename T> istream& operator>>(istream& in, vector<T> &a) { for (auto&x:a)in>>x; return in; } template<typename T> ostream& operator<<(ostream& out, vector<T> a) { for (auto&x:a)out << x << ' '; return out; } vi C(mxN, INT_MAX); vi adj[mxN]; void solve() { int n, m, i, u, v; cin >> n >> m; vi A(n); cin >> A; vector<pii> B(n); f0(i, n) B[i].F = A[i], B[i].S = i; sort(all(B)); f0(i, m) { cin >> u >> v; --u, --v; adj[u].EB(v); } vi vis(n); f0(i, n) { queue<int> q; q.push(B[i].S); while(sz(q)) { int cr = q.front(); vis[cr] = 1; q.pop(); if (cr^B[i].S) cmin(C[cr], A[B[i].S]); for (int x: adj[cr]) if (!vis[x]) q.push(x); } vis[B[i].S] = 0; } int ans = INT_MIN; f0(i, n) if(C[i]!=INT_MAX) cmax(ans, A[i]-C[i]); // print(C[0], C[1], C[2]); print(ans); } signed main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif __speed() solve(); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; #define REP(NAME, NUM) for (int NAME = 0; NAME < int(NUM); ++NAME) #define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME) #define ALL(NAME) (NAME).begin(), (NAME).end() #define cMOD 1000000007ULL #define cINF ((1ll<<62)-1) #define cINFINT ((1<<30)-1) const ld pi = acosl(-1.0); template <typename T> void chmin(T& a, T b){ if(a > b) a = b; } template <typename T> void chmax(T& a, T b){ if(a < b) a = b; } ll n,m; ll in(ll y) { return -m-2 <= y-n && y-n <= m+2; } ll c(ll y) { return y - n + m+2; } int main() { cin.tie( 0 ); ios::sync_with_stdio( false ); // ---------------------------------------------------------------- cin>>n>>m; vector<pair<ll,ll>> p( m ); REP(i,m) cin>>p[i].first>>p[i].second; sort(ALL(p)); map<ll, vector<ll>> xy; REP(i,m) { if(xy.count(p[i].first)<=0) xy[p[i].first] = vector<ll>(0); xy[p[i].first].emplace_back(p[i].second); } vector<bool> dp(2*m+5,false); map<ll, bool> update; dp[c(n)] = true; for( auto i = xy.begin(); i != xy.end() ; ++i ) { //cout << i->first << ": "; REP( i, dp.size() ) cout << dp[i] << " "; cout << endl; //ll x = i->first; vector<ll>& ylist = i->second; update.clear(); REP(j,ylist.size()) { ll y = ylist[j]; for(ll d=0;d<=1;d=((d==0)?-1:d+2)) { if(!(in(y)&&in(y+d))) continue; if(d==0) update[y] = false; else if(dp[c(y+d)]) update[y] = true; } } for( auto j = update.begin(); j != update.end() ; ++j ) { //cout << i->first << ": " << j->first << " " << j->second << endl; dp[c(j->first)] = j->second; } } ll ans = 0; REP(i,dp.size()) if(dp[i] == true) ++ans; cout << ans << endl; // ---------------------------------------------------------------- return 0; }
#include <bits/stdc++.h> #define fast ios::sync_with_stdio(0), cin.tie(nullptr) #define all(v) v.begin(), v.end() #define compress(v) sort(all(v)), v.erase(unique(all(v)), v.end()) #define fi first #define se second #define cat(a, b) a##b using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const ll S = 200000 + 10, MOD = (ll)1e9 + 7; pii arr[S]; bool chk[S * 2]; int main() { fast; int n, m; cin >> n >> m; for (int i = 0; i < m; i++) cin >> arr[i].fi >> arr[i].se; sort(arr, arr + m); chk[m + 1] = 1; vector<vector<pii>> v{ {arr[0]} }; for (int i = 1; i < m; i++) { if (arr[i - 1].fi != arr[i].fi) v.push_back({}); v.back().push_back(arr[i]); } queue<int> pos, impos; for (auto i : v) { for (pii j : i) { if (abs(j.se - n) > m or j.fi == 0) continue; int idx = j.se - n + m + 1; if (chk[idx - 1] or chk[idx + 1]) { if (!chk[idx]) pos.push(idx); } else { if (chk[idx]) impos.push(idx); } } while (!pos.empty()) { chk[pos.front()] = true; pos.pop(); } while (!impos.empty()) { chk[impos.front()] = false; impos.pop(); } } int ans = 0; for (int i = 1; i <= 2 * m + 1; i++) ans += chk[i]; cout << ans; return 0; }
#include <iostream> #include <vector> using namespace std; void check(bool& Akaried, vector<vector<int>>& Map, int i, int j) { switch (Map[i][j]) { case 1: break; case -1: if (Akaried) Map[i][j] = 1; break; case 2: Akaried = true; break; case 3: Akaried = false; break; } return; } int main() { int H, W, N, M; cin >> H >> W >> N >> M; vector<vector<int>> Map(H, vector<int>(W, -1)); for (int i = 0; i < N; i++) { int a, b; cin >> a >> b; a--, b--; Map[a][b] = 2; } for (int i = 0; i < M; i++) { int c, d; cin >> c >> d; c--, d--; Map[c][d] = 3; } for (int i = 0; i < H; i++) { bool Akaried = false; for (int j = 0; j < W; j++) { check(Akaried, Map, i, j); } for (int j = W - 1; j >= 0; j--) { check(Akaried, Map, i, j); } } for (int j = 0; j < W; j++) { bool Akaried = false; for (int i = 0; i < H; i++) { check(Akaried, Map, i, j); } for (int i = H - 1; i >= 0; i--) { check(Akaried, Map, i, j); } } int ans = 0; for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) ans += (Map[i][j] == 1 || Map[i][j] == 2); cout << ans << endl; }
#include <bits/stdc++.h> //#include <atcoder/all> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; //using namespace atcoder; using ll = long long; using P = pair<int, int>; int main() { int H, W, N, M; cin >> H >> W >> N >> M; vector<vector<int>> dp(H + 2, vector<int>(W + 2)); rep(i, N) { int a, b; cin >> a >> b; dp[a][b] = 2; } rep(i, M) { int a, b; cin >> a >> b; dp[a][b] = -1; } bool judge = false; for (int h = 1; h <= H; h++) { judge = false; for (int w = 1; w <= W; w++) { if (dp[h][w] < 0){ judge = false; } else if (dp[h][w] > 1) { judge = true; } else if (judge) { dp[h][w] = 1; } } judge = false; for (int w = W; w > 0; w--) { if (dp[h][w] < 0){ judge = false; } else if (dp[h][w] > 1) { judge = true; } else if (judge) { dp[h][w] = 1; } } } for (int w = 1; w <= W; w++) { judge = false; for(int h = 1; h <= H; h++){ if (dp[h][w] < 0){ judge = false; } else if (dp[h][w] > 1) { judge = true; } else if (judge) { dp[h][w] = 1; } } judge = false; for(int h = H;h > 0; h--){ if (dp[h][w] < 0){ judge = false; } else if (dp[h][w] > 1) { judge = true; } else if (judge) { dp[h][w] = 1; } } } int ans = 0; for (int h = 1; h <= H; h++) { for (int w = 1; w <= W; w++) { if (dp[h][w] > 0) ans++; } } cout << ans << endl; return 0; }
#include<bits/stdc++.h> #define ll long long int #define mk make_pair #define pb push_back #define INF (ll)1e18 #define pii pair<ll,ll> #define mod 998244353 #define ff first #define ss second #define srt(v) if(!v.empty())sort(v.begin(),v.end()) #define rev(v) if(!v.empty())reverse(v.begin(),v.end()) #define PI 3.141592653589793238 #define pqr priority_queue<ll,vector<ll>,greater<ll>()> using namespace std; ll pow_mod(ll a,ll b) { ll res=1; while(b!=0) { if(b&1) { res=(res*a)%mod; } a=(a*a)%mod; b/=2; } return res; } ll inv_mod(ll x){ return pow_mod(x,mod-2); } const ll N=(ll)3e5; ll inv[N]; ll fac[N]; ll ncr(ll n,ll r){ if(n<r) return 0; if(n==r||r==0) return 1LL; ll x=fac[n]; ll y=inv[n-r]; ll z=inv[r]; return ((x*y)%mod*z)%mod; } void solve() { ll n; cin>>n; ll a[n]; for(ll i=0;i<n;i++) cin>>a[i]; ll ans[n]; ll sum[n]; ll mx[n]={0}; for(ll i=0;i<n;i++){ if(i==0) sum[i]=a[i]; else sum[i]=sum[i-1]+a[i]; if(i!=0) mx[i]=mx[i-1]; mx[i]=max(mx[i],a[i]); } ll res=0; for(ll i=0;i<n;i++){ res+=sum[i]; ans[i]=res+mx[i]*(i+1); } for(ll i=0;i<n;i++) cout<<ans[i]<<"\n"; cout<<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(); fac[0]=1; for(ll i=1;i<N;i++) fac[i]=(i*fac[i-1])%mod; for(ll i=0;i<N;i++) inv[i]=inv_mod(fac[i]); //Good Bye! return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define int ll const int N = (int) 2e5 + 7; int n, a[N], b[N], aib[N]; map<int, vector<int>> pos; map<int, int> cur; void add(int i, int x) { while (i <= n) { aib[i] += x; i += i & (-i); } } int get(int i) { int sol = 0; while (i) { sol += aib[i]; i -= i & (-i); } return sol; } signed main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= n; i++) cin >> b[i]; vector<int> foo, bar; for (int i = 1; i <= n; i++) { a[i] += i; b[i] += i; foo.push_back(a[i]); bar.push_back(b[i]); } sort(foo.begin(), foo.end()); sort(bar.begin(), bar.end()); if (foo != bar) { cout << "-1\n"; return 0; } for (int i = 1; i <= n; i++) { pos[b[i]].push_back(i); } int sol = 0; for (int i = 1; i <= n; i++) { int j = pos[a[i]][cur[a[i]]++]; assert(j + get(j) >= 1); sol += j + get(j) - 1; add(j, -1); } cout << sol << "\n"; return 0; }
// Problem: D - Base n // Contest: AtCoder - AtCoder Beginner Contest 192 // URL: https://atcoder.jp/contests/abc192/tasks/abc192_d // Memory Limit: 1024 MB // Time Limit: 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) // Disclaimer: Don't copy my template, it may lead to plagiarism. /* Author: Soumy Jain Handle: soumy_jain || soumyjain "Beautiful flowers too, eventually wither and fall. That's the fate of all living beings." "I hate perfection. To be perfect is to be unable to improve any furthur." - Mayuri Kurotsuchi | Bleach "I smile to show the pressure of heroes and to trick the fear inside of me." "Gravel may be gravel, but me? I'm the gravel that shatters diamonds." "If you were to write a story with me in the lead role, it would certainly be...a TRAGEDY." - Kaneki Ken | Tokyo Ghoul */ /******************************************************************************/ // clang-format off #include <bits/stdc++.h> #define ll long long #define ull unsigned long long #define SPEEDHACK ios_base::sync_with_stdio(false);cin.tie(NULL); #define Tc ll tc; cin>>tc; while(tc--) #define Qu ll qu; cin>>qu; while(qu--) #define ff first #define ss second #define sz(v) (ll)(v).size() #define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout); #define MOD 1000000007 // 998244353 using namespace std; /******************************************************************************/ void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(ll x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(ull 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 // clang-format on /***********************************MAIN***************************************/ // Are you ready to face the wrath of test cases? Good luck noob Soumy! int main() { SPEEDHACK // file string s; cin >> s; ll m; cin >> m; ll d = 0; for (ll i = 0; i < sz(s); i++) { d = max(d, (ll)s[i] - 48); } if (sz(s) == 1) { if (s[0] - 48 > m) cout << 0; else cout << 1; return 0; } ll c = 0; if (sz(s) == 2 || sz(s) == 3 || sz(s) == 4) { for (ll i = pow(m / (s.front() * 1.0 - 48), 1.0 / (sz(s) - 1)); i > d; i--) { ll k = 0, b = 1; for (ll j = sz(s) - 1; j >= 0; j--, b *= i) { k += (s[j] - 48) * b; } if (k <= m) { c = i; break; } } cout << c - d; return 0; } for (ll i = d + 1; i <= pow(m, 1.0 / (sz(s) - 1)); i++) { ll k = 0, b = 1; for (ll j = sz(s) - 1; j >= 0; j--, b *= i) { k += (s[j] - 48) * b; } if (k > m) break; c++; } cout << c; return 0; }
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.h" #else #define dump(...) #endif #define endl '\n' //#define int long long #define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define REP(i, x) for (int i = 0; i < (int)(x); i++) #define REPS(i, x) for (int i = 1; i <= (int)(x); i++) #define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--) #define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--) #define INF 2147483647 #define LLINF 9223372036854775807LL #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define BIT(n) (1LL << (n)) #define TOUPPER(s) transform(s.begin(), s.end(), s.begin(), ::toupper) #define TOLOWER(s) transform(s.begin(), s.end(), s.begin(), ::tolower) #define FILLZERO(s, n) \ do { \ ostringstream os; \ os << setw(n) << setfill('0') << s; \ s = os.str(); \ } while (0); #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) // sortしてからつかうこと using ll = long long; using vi = vector<int>; using vvi = vector<vector<int>>; using pi = pair<int, int>; template <typename T> using Pq = priority_queue<T>; template <typename T> using pQ = priority_queue<T, vector<T>, greater<T>>; template <typename T> vector<T> make_vec(size_t a, T n) { return vector<T>(a, n); } template <typename T, typename... Ts> auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <typename T> bool isProductOverflow(T a, T b) { return (a > numeric_limits<T>::max() / b); } template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } __attribute__((constructor)) void ioInit() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); cout << std::fixed << std::setprecision(10); } constexpr ll MOD = 1e9 + 7; // constexpr ll MOD = 998244353; int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}; int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1}; ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z; string S, T; ll ans = 0; long long intpow(long long a, long long n) { if (n == 0) return 1; else if (n & 1) return intpow(a * a, n / 2) * a; else return intpow(a * a, n / 2); } string f(ll x, ll n) { string res; while (x > 0) { if (x == 1 and n == 1) { break; } res.push_back(char(min(10LL, x % n) + '0')); x /= n; } reverse(ALL(res)); return res; } bool comp(string &x, string &y) { if (x.size() > y.size()) { return 1; } else if (x.size() < y.size()) { return 0; } else { return x >= y; } } signed main() { cin >> S >> M; dump(S); string tmp = S; sort(RALL(tmp)); ll n = tmp[0] - '0'; ll ok = n + 1; ll ng = M + 10; tmp = f(M, ok); if (!comp(tmp, S)) { cout << 0 << endl; return 0; } tmp = f(M, ng); if (comp(tmp, S)) { if (S.size() == 1) { cout << 1 << endl; return 0; } cout << M - n << endl; return 0; } while (abs(ok - ng) > 1) { ll mid = (ok + ng) / 2; auto T = f(M, mid); if (comp(T, S)) { ok = mid; } else { ng = mid; } } cout << ok - n << endl; }
#include<cstdio> #include<cstring> #include<queue> #include<cmath> #include<algorithm> using namespace std; typedef int int_; #define int long long #define maxn 400010 const int inf=1e9+7; queue<int> q; inline int read(){ int ret=0,ff=1; char ch=getchar(); while(ch<'0'||ch>'9'){ if(ch=='-') ff=-ff; ch=getchar(); } while(ch>='0'&&ch<='9'){ ret=ret*10+ch-'0'; ch=getchar(); } return ret*ff; } struct Edge{ int u,v,w,next; }E[maxn<<1]; int ecnt=0,head[maxn]; int in[maxn]; void addedge(int u,int v){ ++in[v]; E[++ecnt].u=u; E[ecnt].v=v; E[ecnt].next=head[u]; head[u]=ecnt; } void Addedge(int u,int v){ addedge(u,v); addedge(v,u); } int gcd(int a,int b){ return b?gcd(b,a%b):a; } int ksm(int a,int b,int p){ int ret=1; while(b){ if(b&1) ret=ret*a%p; a=a*a%p; b>>=1; } return ret%p; } bool cmp(int x,int y){ return x>y; } int a[10010]; int G2(int x){ int cnt=0; while(x){ a[++cnt]=x%10; x/=10; } sort(a+1,a+1+cnt); int ret=0; for(int i=1;i<=cnt;++i) ret=ret*10+a[i]; return ret; } int G1(int x){ int cnt=0; while(x){ a[++cnt]=x%10; x/=10; } sort(a+1,a+1+cnt,cmp); int ret=0; for(int i=1;i<=cnt;++i) ret=ret*10+a[i]; return ret; } int F(int x){ return G1(x)-G2(x); } char X[10010]; bool ck(int Mid,int len,int m){ int sum=0,tmp=1; for(int j = len; j;--j){ sum+=tmp*(X[j]-'0'); tmp*=Mid; } return sum>m; } int dp[2][110][110][110]; int_ main(){ int n=read(),x=read(); for(int i=1;i<=n;++i) a[i]=read(); memset(dp, -1, sizeof dp); for(int i=1;i<=n;i++) dp[0][i][0][0] = 0; for(int i=0;i<n;i++){ int qwq=i&1; for(int j =1;j<=n;j++){ for(int qaq =0;qaq<=i;qaq++){ for(int res=0;res<j;res++){ if(dp[qwq][j][qaq][res]==-1) continue; dp[qwq^1][j][qaq+1][(res+a[i+1])%j]=max(dp[qwq^1][j][qaq+1][(res+a[i+1])%j],dp[qwq][j][qaq][res]+a[i+1]); dp[qwq^1][j][qaq][res]=max(dp[qwq^1][j][qaq][res], dp[qwq][j][qaq][res]); } } } } int qwq=n&1,ans=x; for(int qaq=1;qaq<=n;qaq++){ if(dp[qwq][qaq][qaq][x%qaq]>0&&x>=dp[qwq][qaq][qaq][x%qaq])ans=min(ans,(x-dp[qwq][qaq][qaq][x%qaq])/qaq); } printf("%lld",ans); return 0; } /* 1 6 3 */ /* 111111111111111111111111111111111111111111111111111111111111 1000000000000000000 100000000000000000000000000000000000000000000000000000000000 1000000000000000000 2 1000000000000000000 */
#pragma GCC optimize ("Ofast") #include<bits/stdc++.h> using namespace std; inline int my_getchar(){ static char buf[1048576]; static int s = 1048576; static int e = 1048576; if(s == e && e == 1048576){ e = fread(buf, 1, 1048576, stdin); s = 0; } if(s == e){ return EOF; } return buf[s++]; } inline void rd(int &x){ int k; int m=0; x=0; for(;;){ k = my_getchar(); if(k=='-'){ m=1; break; } if('0'<=k&&k<='9'){ x=k-'0'; break; } } for(;;){ k = my_getchar(); if(k<'0'||k>'9'){ break; } x=x*10+k-'0'; } if(m){ x=-x; } } inline void rd(long long &x){ int k; int m=0; x=0; for(;;){ k = my_getchar(); if(k=='-'){ m=1; break; } if('0'<=k&&k<='9'){ x=k-'0'; break; } } for(;;){ k = my_getchar(); if(k<'0'||k>'9'){ break; } x=x*10+k-'0'; } if(m){ x=-x; } } struct MY_WRITER{ char buf[1048576]; int s; int e; MY_WRITER(){ s = 0; e = 1048576; } ~MY_WRITER(){ if(s){ fwrite(buf, 1, s, stdout); } } } ; MY_WRITER MY_WRITER_VAR; void my_putchar(int a){ if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){ fwrite(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout); MY_WRITER_VAR.s = 0; } MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a; } inline void wt_L(char a){ my_putchar(a); } inline void wt_L(long long x){ int s=0; int m=0; char f[20]; if(x<0){ m=1; x=-x; } while(x){ f[s++]=x%10; x/=10; } if(!s){ f[s++]=0; } if(m){ my_putchar('-'); } while(s--){ my_putchar(f[s]+'0'); } } template<class S, class T> inline S chmin(S &a, T b){ if(a>b){ a=b; } return a; } template<class S, class T> inline S chmax(S &a, T b){ if(a<b){ a=b; } return a; } int N; long long X; long long A[110]; long long f[110][110]; int main(){ int k; rd(N); rd(X); { int Lj4PdHRW; for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){ rd(A[Lj4PdHRW]); } } long long ans = 4611686016279904256LL; for(k=(1);k<(N+1);k++){ int i, j; for(j=(0);j<(k+1);j++){ int l; for(l=(0);l<(k+1);l++){ f[j][l] = -4611686016279904256LL; } } f[0][0] = 0; for(i=(0);i<(N);i++){ for(j=(k)-1;j>=(0);j--){ int l; for(l=(0);l<(k);l++){ if(f[j][l] < 0){ continue; } chmax(f[j+1][(l + A[i])%k], f[j][l] + A[i]); } } } if(f[k][X%k] < 0){ continue; } chmin(ans, (X-f[k][X%k])/k); } wt_L(ans); wt_L('\n'); return 0; } // cLay version 20210103-1 // --- original code --- // //no-unlocked // int N; // ll X, A[110], f[110][110]; // { // rd(N,X, A(N)); // ll ans = ll_inf; // rep(k,1,N+1){ // rep(j, k+1) // rep(l, k+1) // f[j][l] = -ll_inf; // f[0][0] = 0; // rep(i, N) // rrep(j, k) // rep(l, k) // { // if(f[j][l] < 0) continue; // f[j+1][(l + A[i])%k] >?= f[j][l] + A[i]; // } // if(f[k][X%k] < 0) // continue; // ans <?= (X-f[k][X%k])/k; // } // wt(ans); // }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; using vll = vector<ll>; using vvll = vector<vll>; using vc = vector<char>; using vcc = vector<vc>; using Pii = pair<int,int>; using ld = long double; #define rep(i,n) for(int i = 0; i<(int)n; i++) #define per(i,n) for(int i = n-1; i>=0; i--) #define mysort(V) sort(V.begin(),V.end()) #define myreverse(V) reverse(V.begin(),V.end()) #define myunique(V) V.erase( unique(V.begin(), V.end()), V.end() ); #define print(s) cout << s << endl; const ld PI = 3.14159265358979; const long long INF = 12345678909876; long long powll(long long x, long long n){ if(n == 0) return 1; else return powll(x,n-1)*x; } long long gcd(long long a, long long b){ if(a%b==0) return b; else return gcd(b,a%b); } int main(){ int N; string s,t; cin >> N >> s >> t; vector<int> A(0),B(0); for(int i = 0; i<s.size(); i++){ if(s[i]=='0'){ A.push_back(i); } } for(int j = 0; j<s.size(); j++){ if(t[j]=='0'){ B.push_back(j); } } int ans = 0; if(A.size()!=B.size()){ ans = -1; } else{ for(int i = 0; i<A.size(); i++){ if(A[i]!=B[i]){ ans++; } } } cout << ans << endl; }
#include <bits/stdc++.h> // #include <atcoder/all> using namespace std; // using namespace atcoder; #define rp(i, k, n) for (int i = k; i < n; i++) using ll = long long; using ld = long double; template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } const ll INF = 1ll << 60; const ll MOD = 1e9 + 7ll; // const ll MOD = 998244353; const double PI=3.14159265358979323846; int mygcd(int n, int m) { // 最大公約数を求めるプログラム // nとmの最大公約数を返す関数 if(m > n) { int c = n; n = m; m = c; } if(n%m == 0) return m; else return mygcd(m, n%m); } int main() { int n; cin >> n; string s, x; cin >> s >> x; vector<vector<int>> dp(200010, vector<int>(7)); // dp[i][j] ... i番目の手番でT%7=jだった場合の勝敗 // 0ならAoki, 1ならTakahashi dp[n][0] = 1; for(int i = n-1; i >= 0; i--) { int a = s[i] - '0'; rp(j, 0, 7) { int b = (j*10 + a) % 7; int c = (j*10) % 7; if(x[i] == 'A') { // aと0どちらを加えても7の倍数になる場合、1 if(dp[i+1][b] == 1 and dp[i+1][c] == 1) { dp[i][j] = 1; } } else { if(dp[i+1][b] == 1 or dp[i+1][c] == 1) { dp[i][j] = 1; } } } } if(dp[0][0] == 1) cout << "Takahashi" << endl; else cout << "Aoki" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define R cin>> #define ll long long #define ln cout<<'\n' #define in(a) insert(a) #define pb(a) push_back(a) #define pd(a) printf("%.10f\n",a) #define mem(a) memset(a,0,sizeof(a)) #define all(c) (c).begin(),(c).end() #define iter(c) __typeof((c).begin()) #define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--) #define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++) #define rep(i,n) REP(i,0,n) #define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++) ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;} template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);} template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;} const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1}; typedef pair<ll,ll> P; void Main() { ll n; R n; pr(n-1); } int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}
#include <bits/stdc++.h> using namespace std; #define N 100010 typedef long long ll; ll arr[N]; int main() { ll n, q; cin >> n >> q; for (int i = 0; i < n; i++) { cin >> arr[i]; } ll k; while (q--) { cin >> k; ll target = 1; ll left = 0, right = n - 1; while (left <= right) { ll middle = left + ((right - left) >> 1); if (arr[middle] - middle - 1 < k) { left = middle + 1; } else if (arr[middle] - middle - 1 >= k) { right = middle - 1; } } cout << k + target + right << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define loop(i,a,b) for(ll i=a;i<=b;i++) #define pb push_back #define mod 1000000007 void contest() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif } ll dmod(ll x) {return ((x + mod) % mod);} ll modular_power(ll x, ll y) {ll ans = 1; while (y) {if (y & 1)ans = dmod(ans * x); y /= 2; x = dmod(x * x);} return ans;} ll inverse(ll x) {return modular_power(dmod(x), mod - 2);} ll rotated_search(ll a[], ll l, ll h, ll key) { if (l > h)return -1; ll mid = (l + h) / 2; if (a[mid] == key)return mid; if (a[l] <= a[mid]) { if (key >= a[l] && key <= a[mid])return rotated_search(a, l, mid - 1, key); return rotated_search(a, mid + 1, h, key); } if (key >= a[mid] && key <= a[h])return rotated_search(a, mid + 1, h, key); return rotated_search(a, l, mid - 1, key); } ll knight(ll n) {return n * n * (n * n - 1) / 2 - 4 * (n - 1) * (n - 2);} 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); } }; bool comp(pair<int, int> l1, pair<int, int> l2) { if (l1.first < l2.first)return true; return false; } long long int tt(long long int l, long long int r) { long long int temp1 = ((l) * (l + 1)) / 2; long long int temp2 = ((r) * (r + 1)) / 2; return temp2 - temp1; } int main() { contest(); fast ///// CODE BELOW ////////// //unordered_map<long long ll, long long ll, custom_hash> mp; int n; cin >> n; int a[n]; for (int i = 0; i < n; i++)cin >> a[i]; long long int ans = 0; for (int i = 0; i < n; i++) { if (a[i] > 10) { ans += (a[i] - 10); } } cout << ans; } // 10 10 // ...#..A.#. // ....B...## // ...#...... // .......... // ...#.#.... // ..##..#... // .......#.. // #.......#. // ...#....#. // #......#..
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> VI; using PII = pair<int, int>; inline void quickread() { ios::sync_with_stdio(false); cin.tie(nullptr); } ll qpow(ll a, ll b, ll p) { ll ret = 1; while(b) { if(b & 1) ret = (ret * a) % p; a = (a * a) % p; b >>= 1; } return ret; } int main() { quickread(); int n, ret = 0; cin >> n; VI a(n); for(int i =0 ; i < n; i++) { cin >> a[i]; if(a[i] > 10) { ret += (a[i] - 10); } } cout << ret << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(NULL); ios_base::sync_with_stdio(false); int a, b; int x = 1^2; cin >> a >> b; if ((x^a^b) != (1^2)) cout << (x^a^b); else cout << a; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int x, y; cin >> x >> y; if ( x == y ) cout << x; else { int arr[3] = {0, 1, 2}; for ( int i = 0; i < 3; i ++ ) { if ( arr[i] != x && arr[i] != y ) { cout << arr[i]; break; } } } }
#include <bits/stdc++.h> #include <string> #include <algorithm> #include <cstdlib> #include <math.h> using namespace std; int t[200001]; int main(void){ int n; cin >> n; int at=0; for(int i=0;i<n;i++){ int s; cin >> s; t[s]++; while(t[at]){ //cout << ":" << at << endl; at++; } cout << at << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define endl "\n" #define int long long int #define mod 1000000007 #define vi vector<int> #define pint pair<int,int> #define vint vector<vector<int>> #define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); const int N = 1e6+5; int A[N], B[N], P[N], Q[N][3], D[N][3]; int mat[5005][5005]; pint edges[N]; unordered_map<int, set<int>> m; bool compare(vi a, vi b) { return a[0] < b[0]; } int lcm(int a, int b) { return (a*b)/(__gcd(a,b)); } int mypow(int a, int x) { if(a<=1 || x==1) return a; if(x==0) return 1; int temp = mypow(a,x/2); if(x%2==0) return ((temp%mod) * (temp%mod))%mod; else return (a%mod * ((temp%mod) * (temp%mod))%mod)%mod; } int count_bits(int n) { int cnt = 0; while(n) { n = n & (n-1); cnt++; }return cnt; } void bfs(int src, int n) { unordered_map<int, bool> visited; for(int i=0;i<n;i++) visited[i] = false; queue<int> q; q.push(src); visited[src] = true; while(!q.empty()) { int curr = q.front(); q.pop(); B[curr] -= min(B[curr], A[src]); //cout<<curr<<" "<<endl; for(auto neigh: m[curr]) { if(visited[neigh] == false) { //cout<<neigh<<endl; q.push(neigh); visited[neigh] = true; m[src].erase(neigh); m[neigh].erase(src); } } } } int length_of_lis(int n) { if(n<=1) return n; vector<int> res; res.push_back(A[0]); int i; for(i=1;i<n;i++) { if(A[i] > res.back()) res.push_back(A[i]); else { int index = lower_bound(res.begin(), res.end(), A[i]) - res.begin(); res[index] = A[i]; } }return res.size(); } void solve(int n) { bool table[n+1]; int i,j; for(i=0;i<=n;i++) table[i] = false; vi res; int left = 0; for(i=0;i<n;i++) { if(A[i] != left) { res.push_back(left); if(A[i] >= 0 && A[i] <= n) table[A[i]] = true; } else { table[left] = true; while(table[left] != false) left++; res.push_back(left); } } for(auto x:res) cout<<x<<endl; } int32_t main() { //code IOS; int t,n,m,a,b,x,y,i,j,z; //cin>>t; t = 1; while(t--) { cin>>n; for(i=0;i<n;i++) cin>>A[i]; solve(n); } return 0; }
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { int a, b, c; cin >> a >> b >> c; if(( a*a + b*b) < (c*c) ){ printf("Yes\n"); } else{ printf("No\n"); } }
#define LOCAL #ifdef LOCAL #define _GLIBCXX_DEBUG #endif #include <bits/stdc++.h> using namespace std; #define int long long #define rep(i,s,n) for (int i = (ll)s; i < (ll)n; i++) #define rrep(i,n,e) for (int i = (ll)n; i > (ll)e; i--) #define ll long long #define ld long double #define pb push_back #define eb emplace_back #define All(x) x.begin(), x.end() #define Range(x, i, j) x.begin() + i, x.begin() + j // #define M_PI 3.14159265358979323846 // CF #define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI)) #define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360) #define Find(set, element) set.find(element) != set.end() #define Decimal(x) cout << fixed << setprecision(10) << x << endl; // print Decimal number 10 Rank #define endl "\n" #define Case(x) printf("Case #%d: ", x); // gcj typedef pair<int, int> PI; typedef pair<ll, ll> PLL; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<vector<vector<int>>> vvvi; typedef vector<ll> vl; typedef vector<vector<ll>> vvl; typedef vector<vector<vector<ll>>> vvvl; typedef vector<PI> vpi; typedef vector<vector<PI>> vvpi; typedef vector<PLL> vpl; typedef vector<vector<PLL>> vvpl; typedef vector<char> vch; typedef vector<vector<char>> vvch; constexpr ll INF = 1001002003004005006ll; constexpr int n_max = 2e5+10; template<class T> inline bool chmax(T &a, T b) { if(a<b) { a=b; return true; } return false; }; template<class T> inline bool chmin(T &a, T b) { if(a>b) { a=b; return true; } return false; }; template<class T, class U> T POW(T x, U n) {T ret=1; while (n>0) {if (n&1) {ret*=x;} x*=x; n>>=1;} return ret;}; // debug template <typename A, typename B> string to_string(pair<A, B> p); string to_string(const string &s) {return '"' + s + '"';}; string to_string(const char c) {return to_string((string) &c);}; string to_string(bool b) {return (b ? "true" : "false");}; template <size_t N> string to_string(bitset<N> v){ string res = ""; for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]); return res; }; template <typename A> string to_string(A v) { bool first = true; string res = "{"; for(const auto &x : v) { if(!first) res += ", "; first = false; res += to_string(x); } res += "}"; return res; }; template <typename A, typename B> string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";} void debug_out() {cerr << endl;}; template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); }; void LINE_OUT() { cout << "--------------" << endl; }; #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #define LINE LINE_OUT(); #else #define debug(...) 71 #define LINE 71; #endif void print() { cout << endl; } template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { cout << head; if (sizeof...(tail) != 0) cout << " "; print(forward<Tail>(tail)...); }; template <class T> void print(vector<T> &vec) { for (auto& a : vec) { cout << a; if (&a != &vec.back()) cout << " "; } cout << endl; }; template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec); } }; signed main() { ios::sync_with_stdio(false); cin.tie(0); int a, b, c; cin >> a >> b >> c; cout << ((a*a + b*b < c*c) ? "Yes": "No") << endl; return 0; };
#include<bits/stdc++.h> using namespace std; const double eps=1e-5;//精度 int n; struct point{ int x,y; }p[110]; int fa[110]; int father(int x){ return fa[x]==x?x:fa[x]=father(fa[x]); } double dis(int x,int y){ return sqrt(pow(p[x].x-p[y].x,2)+pow(p[x].y-p[y].y,2)); } int main(){ scanf("%d",&n); for(int i=1;i<=n;i++){ cin>>p[i].x>>p[i].y; } double l=0,r=100,mid,ans=0; while(r-l>eps){ mid=(l+r)/2; for(int i=1;i<=n+2;i++) fa[i]=i; for(int i=1;i<=n;i++){//枚举所有点进行合并 for(int j=1;j<=n;j++) if(dis(i,j)<=mid*2) fa[father(j)]=father(i);//合并 if(100-p[i].y<=mid*2)fa[father(n+1)]=father(i);//连接上下边界 if(p[i].y+100<=mid*2)fa[father(n+2)]=father(i); } if(father(n+1)!=father(n+2)) ans=l=mid;//二者还没有接上,还可以大 else r=mid;//二者已经接上了,考虑更小 } printf("%.5f\n",ans); return 0; }
# include <algorithm> # include <stdio.h> # include <math.h> using namespace std; int n, k; int x[111]; int y[111]; int f[111]; struct edge { int x; int y; double l; } e[10010]; bool cmp(edge a, edge b) { return a.l < b.l; } int fi(int x) { int t = x; while (t != f[t]) { t = f[t]; } while (x != f[x]) { int T = f[x]; f[x] = t; x = T; } return t; } void ji(int x, int y) { f[fi(x)] = fi(y); } int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d%d", x + i, y + i); for (int j = 1; j < i; j++) { e[++k].x = i; e[k].y = j; e[k].l = sqrt((x[j] - x[i]) * (x[j] - x[i]) + (y[j] - y[i]) * (y[j] - y[i])); } } for (int i = 1; i <= n; i++) { e[++k].x = 0; e[k].y = i; e[k].l = 100 - y[i]; e[++k].x = n + 1; e[k].y = i; e[k].l = y[i] + 100; } e[++k].x = 0; e[k].y = n + 1; e[k].l = 200; sort(e + 1, e + 1 + k, cmp); for (int i = 0; i <= n + 1; i++) { f[i] = i; } for (int i = 1;; i++) { ji(e[i].x, e[i].y); if (fi(0) == fi(n + 1)) { printf("%.18f", e[i].l / 2); return 0; } } }
#include <iostream> #include <vector> #include <algorithm> int main() { int n, m; std::cin >> n >> m; std::vector<int> a(m); for (int i=0; i<m; ++i) { std::cin >> a[i]; } std::sort(a.begin(), a.end()); std::vector<int> s; for (int i=0; i<=m; ++i) { int j; if (i == m) { j = n+1; } else { j = a[i]; } int k; if (i == 0) { k = 0; } else { k = a[i-1]; } if (j-k-1 > 0) s.push_back(j-k-1); } if (s.size() == 0) { std::cout << 0 << std::endl; return 0; } int min = *std::min_element(s.begin(), s.end()); int ans = 0; for (auto i : s) { ans += i/min; ans += i%min != 0 ? 1 : 0; } std::cout << ans << std::endl; }
#include <iostream> #include <algorithm> #include <cstring> using namespace std; const int N = 810; int n, k, a[N][N]; bool check(int mid) { int s[N][N], d[N][N]; memset(s, 0, sizeof(s)); memset(d, 0, sizeof(d)); for(int i = 1; i <= n; i++) { for(int j = 1; j <= n; j++) { s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + (a[i][j] < mid); d[i][j] = d[i - 1][j] + d[i][j - 1] - d[i - 1][j - 1] + (a[i][j] == mid); } } for(int i = 1; i <= n - k + 1; i++) { for(int j = 1; j <= n - k + 1; j++) { int x = i + k - 1, y = j + k - 1; int t = s[x][y] - s[i - 1][y] - s[x][j - 1] + s[i - 1][j - 1]; int cnt = d[x][y] - d[i - 1][y] - d[x][j - 1] + d[i - 1][j - 1]; if(t + cnt >= k * k / 2 + k % 2) return true; } } return false; } int main() { cin >> n >> k; for(int i = 1; i <= n; i++) { for(int j = 1; j <= n; j++) { cin >> a[i][j]; } } int l = 0, r = 1e9; while(l < r) { int mid = l + r >> 1; if(check(mid)) r = mid; else l = mid + 1; } cout << l << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define mod 1000000007 int main() { ll t = 1; // cin >> t; while(t--) { ll n; cin >> n; ll c = 0 , x = 1 , c1 = 0; while(1) { // x*y + x*(x-1)/2 = ll val = n - ((x*(x-1))/2); // cout << val << endl; ll val1 = val / x; if(val1 < 0) break; if(val % x == 0 && val1 > 0) { // cout << "i " << val1 << endl; c++; } x++; } cout << 2*c+c1 << endl; } }
#include<bits/stdc++.h> #define pb push_back #define fo(i,n) for(int i=0;i<n;i++) #define ll long long #define int long long #define Mod 1000000007 #define maxn 200005 #define MAX 4294967296 // 2^32 const int M=1e9+7; #define ip pair<int,int> #define test(t) ll t;cin>>t;while(t--) using namespace std; long long power(int x,int y){ if(y==0)return 1; long long res=1; while(y>0){ if(y&1){ res=(res*x)%Mod; } x=x*x%Mod; y/=2; } return res; } ll power(ll x, ll y, ll p) { ll res = 1; // Initialize result x = x % p; // Update x if it is more than or // equal to p while (y > 0) { // If y is odd, multiply x with result if (y & 1) res = (res*x) % p; // y must be even now y = y>>1; // y = y/2 x = (x*x) % p; } return res; } long long gcd(int x,int y){ // if(y>x)swap(x,y); if(y==0)return x; return gcd(y,x%y); } // const int N=200005; // int dp[N]; // int r=1000000000000000005; int fact[250005]; // int prime[25]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97}; // set<int>st; int mul(int l,int r){ return ((l%Mod)%Mod*(r%Mod)%Mod)%Mod; } int nCr(int n,int k){ if(n<k)return 0; int ans=fact[n]%Mod; ans=mul(ans,power(fact[n-k],Mod-2)); ans=mul(ans,power(fact[k],Mod-2)); return ans; } // int n; // int v=100000000000000; // void dfs(int i,int j){ // size[i]=1; // bool is=1; // for(auto it:adj[i]){ // if(!vis[it]){ // dfs(it,i); // size[i]+=size[it]; // } // } // } bool prime(int x){ if(x<2)return false; for(int i=2;i*i<=x;i++){ if(x%i==0)return false; } return true; } void solve(){ int n; cin>>n; int ans=0; for(int i=2;i<=(i*(i+1))/2;i++){ if((n-((i*(i+1))/2))%i==0)ans++; } cout<<2*ans; return ; } signed main(){ // std::string binary = std::bitset<8>(n).to_string(); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); // memset(fact,0,sizeof(fact)); // test(t) int n; cin>>n; int ans=1; for(int i=2;(i*(i+1))/2<=n;i++){ if((n-((i*(i+1))/2))%i==0)ans++; } cout<<2*ans; }
#include<bits/stdc++.h> using namespace std; long long a,s,x,mx; int n; int main(){ cin>>n; int i; for(i=1;i<=n;i++){ cin>>x; mx=max(mx,x); a+=x; s+=a; cout<<s+i*mx<<endl; } }
#include <bits/stdc++.h> #include <bits/extc++.h> using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ld; typedef double db; typedef string str; typedef pair<int,int> pi; typedef pair<ll,ll> pl; typedef pair<db,db> pd; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<db> vd; typedef vector<str> vs; typedef vector<pi> vpi; typedef vector<pl> vpl; typedef vector<pd> vpd; typedef vector<vi> vvi; typedef set<int> si; #define vt vector #define mp make_pair #define f first #define s second #define sz(x) (int)x.size() #define all(x) begin(x), end(x) #define rall(x) (x).rbegin(), (x).rend() #define rsz resize #define ins insert #define ft front() #define bk back() #define pf push_front #define pb push_back #define eb emplace_back #define lb lower_bound #define ub upper_bound #define ts to_string #define EACH(x, a) for (auto& x: a) template<class T> void read(T &x){ cin >> x; } template<class A> void read(vt<A> &v){ EACH(x, v) read(x); } template<class H, class... T> void read(H& h, T& ...t){ read(h); read(t...); } str to_string(const char* c){ return (str)c; } str to_string(char c){ return (str)""+c; } str to_string(str s){ return s; } str to_string(bool b){ return b?"True" : "False"; } template<class A> str to_string(vt<A> v){ str s; EACH(x, v) s+= to_string(x) + " "; return s; } template<class H, class... T> str to_string(H& h, T& ...t){ str s; s+=to_string(h); s+=" "; s+=to_string(t...); return s; } void print(str s){ cout << s << "\n"; } template<class... A> void print(A ...a){ print(to_string(a...)); } int cdiv(int a, int b) { return a/b+!(a<0||a%b == 0); } str tb(int x) {str ans; int c = x; for(int i = log2(x); i >= 0; --i){if(pow(2,i) <= c){ ans += "1"; c-=pow(2,i); } else { ans += "0"; } } return ans;} bool ispr(int x){if(x <= 1){return false;} for(int i = 2; i <= sqrt(x); ++i){ if(x%i == 0){ return false; } }return true; } const int MOD = 1e9+7; // 998244353; const int MX = 2e5+5; const ll INF = 1e18; //tree<int,null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update> T; void solve(){ ll n; cin >> n; vl v(n); read(v); ll ans = 0; ll mx = 0; ll su = 0; for(int i = 0; i < n; ++i){ su+=v[i]; ans+=su; mx=max(mx,v[i]); cout << mx*(i+1)+ans << '\n'; } } int main(){ std::ios::sync_with_stdio(0); std::cin.tie(0); bool isT = 0; if(isT){ int t; cin >> t; while(t--){ solve(); } return 0; } solve(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; #define fi first #define se second #define rep(i, n) for (ll i = 0; i < (n); ++i) #define rep0(i, n) for (ll i = 0; i <= (n); ++i) #define rep1(i, n) for (ll i = 1; i <= (n); ++i) #define rrep1(i, n) for (ll i = (n); i > 0; --i) #define rrep0(i, n) for (ll i = (n); i >= 0; --i) #define srep(i, s, t) for (ll i = s; i < t; ++i) #define srep1(i, s, t) for (ll i = s; i <= t; ++i) #define rsrep1(i, s, t) for (ll i = s; i >= t; --i) #define rng(a) a.begin(), a.end() #define rrng(a) a.rbegin(), a.rend() #define isin(x, l, r) ((l) <= (x) && (x) < (r)) #define pb push_back #define eb emplace_back #define sz(x) (int)(x).size() #define pcnt __builtin_popcountll #define uni(x) x.erase(unique(rng(x)), x.end()) #define snuke srand((unsigned)clock() + (unsigned)time(NULL)); #define show(x) cerr << #x << " = " << x << endl; #define PQ(T) priority_queue<T, v(T), greater<T>> #define bn(x) ((1 << x) - 1) #define dup(x, y) (((x) + (y)-1) / (y)) #define newline puts("") #define v(T) vector<T> #define vv(T) v(v(T)) #define min(a, b) (((a) < (b)) ? (a) : (b)) #define max(a, b) (((a) > (b)) ? (a) : (b)) typedef unsigned uint; typedef unsigned long long ull; typedef pair<ll, ll> P; typedef tuple<ll, ll, ll> T; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<P> vp; typedef vector<T> vt; typedef vector<string> vs; template <typename T> istream &operator>>(istream &i, v(T) & v) { rep(j, sz(v)) i >> v[j]; return i; } #define dame \ { \ puts("-1"); \ return 0; \ } #define yn \ { \ puts("Yes"); \ } \ else { puts("No"); } constexpr ll MAX = 2000001; constexpr ll LINF = 9223372036854775807; constexpr ll mod = 1000000007; //constexpr ll mod = 998244353; int main() { ll n; cin >> n; rep(i, n) { string s; cin >> s; if ("atcoder" < s) { cout << 0 << endl; continue; } string t = s; sort(t.begin(), t.end()); reverse(t.begin(), t.end()); if ("atcoder" > t) { cout << -1 << endl; continue; } rep(i, s.size()) { if (s.at(i) != 'a') { if (s.at(i) > 't') cout << i - 1 << endl; else cout << i << endl; break; } } } return 0; }
#include<bits/stdc++.h> using namespace std; void solve() { string s; cin>>s; int n=s.size(); s="."+s; string t=".atcoder"; int res=-1; for(int i=0;i<=7;i++) { string a=s; int cur=0; for(int j=1;j<=i;j++) { bool found=false; for(int k=j;k<=n;k++) { if(a[k]==t[j]) { found=true; for(int z=k;z>j;z--) { cur++; swap(a[z],a[z-1]); } break; } } if(!found) cur=1e9; //if(i==7) cout<<j<<' '<<found<<' '; } bool have=false; if(i!=7) { for(int k=i+1;k<=n;k++) { if(a[k]>t[i+1]) { have=true; for(int z=k;z>i+1;z--) { cur++; swap(a[z],a[z-1]); } break; } } } if(cur==1e9) continue; if(have||(i==7&&n>7)) { if(res==-1||res>cur) res=cur; } } cout<<res<<'\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int t; cin>>t; while(t--) solve(); }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; // #include <atcoder/all> // using namespace atcoder; int main(){ int n, w; cin >> n >> w; int ans = n/w; cout << ans << endl; }
#include<iostream> #include<string> #include<vector> #include<stack> #include<queue> #include<set> #include<map> #include<algorithm> #include<numeric> #include<cmath> #include<iomanip> #include<regex> using namespace std; #define int long long const int mod=1e9+7; bool pri[1000001],squf[1000001],even[1000001]; signed main(){ int l,r; cin>>l>>r; for(int i=2;i<=r;i++) pri[i]=squf[i]=even[i]=1; for(int i=2;i<=r;i++){ if(!pri[i]) continue; for(int j=i;j<=r;j+=i){ if(j!=i) pri[j]=0; even[j]=!even[j]; } for(int j=i*i;j<=r;j+=i*i) squf[j]=0; } int ans1=0,ans2=0; for(int g=2;g<=r;g++){ if(!squf[g]) continue; int a=r/g-(l-1)/g; a=a*(a-1)/2; if(even[g]) ans1-=a; else ans1+=a; } for(int g=max(2ll,l);g<=r;g++) ans2+=r/g-1; cout<<(ans1-ans2)*2<<endl; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define ff first #define ss second #define all(c) (c).begin(),(c).end() #define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0) typedef long double ld; typedef pair<ll,ll> pii; const ll inf = 1e9; const ll inf64 = 1e18; const ll MOD = inf + 7; void solve() { ll n,k; cin>>n>>k; string s=std::to_string(n); ll last=n; for(ll i=1;i<=k;i++) { //cout<<last<<"\n"; string s1=std::to_string(last); sort(s1.begin(),s1.end()); string s2=s1; sort(s2.rbegin(),s2.rend()); ll g=stoi(s2); ll r=stoi(s1); last=g-r; } cout<<last; } int main() { fast; ll t=1; //cin>>t; while (t--) solve(); }
#include <iostream> #include <vector> #include <algorithm> int main() { const auto g1 = [](long a) { std::vector<long> v; while (a > 0) { v.push_back(a % 10); a /= 10; } std::sort(v.begin(), v.end(), std::greater<long>()); long ret = 0; long n = 1; for (auto it = v.rbegin(); it != v.rend(); ++it, n *= 10) { ret += *it * n; } return ret; }; const auto g2 = [](long a) { std::vector<long> v; while (a > 0) { v.push_back(a % 10); a /= 10; } std::sort(v.begin(), v.end()); long ret = 0; long n = 1; for (auto it = v.rbegin(); it != v.rend(); ++it, n *= 10) { ret += *it * n; } return ret; }; const auto f = [&g1, &g2](long a) { return g1(a) - g2(a); }; long n, k; std::cin >> n >> k; long ret = n; for (long i = 0; i < k; ++i) { ret = f(ret); } std::cout << ret << std::endl; return 0; }
#include "bits/stdc++.h" #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; #define ub upper_bound #define lb lower_bound #define isrt insert #define clr clear #define rsz resize #define ff first #define ss second #define lli long long int #define pb push_back #define pf push_front #define mkp make_pair #define pii pair<lli,lli> #define vi vector<int> #define mii map<lli,lli> #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 1e9 #define ps(x,y) fixed<<setprecision(y)<<x #define mk(arr,n,type) type *arr=new type[n]; #define w(x) int x; cin>>x; while(x--) #define all(v) v.begin(),v.end() #define endl "\n" const double PI = acos(-1); typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; lli maxm(lli a, lli b) { return (a >= b ? a : b); } lli minm(lli a, lli b) { return (a <= b ? a : b); } lli power(lli x, lli y, lli p) { lli 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; } lli nCrmodp(lli n, lli r, lli p) { if (r == 0) return 1; if (r == 1) return n; lli pro = 1, k = n; while (k > r) { pro *= k; pro %= p; --k; } k = 2; while (k <= (n - r)) { pro *= power(k, (p - 2), p); pro %= p; ++k; } return pro; } lli first_big(lli n, lli k, vector<lli> arr) { lli l, r, ans = n; l = 0; r = n - 1; while (l <= r) { lli m = l + (r - l) / 2; if (arr[m] > k) { ans = m; r = m - 1; } else l = m + 1; } return ans; } lli last_small(lli n, lli k, vector<lli> arr) { lli l, r, ans = -1; l = 0; r = n - 1; while (l <= r) { lli mid = (l + r) / 2; if (arr[mid] <= k) { ans = mid; l = mid + 1; } else r = mid - 1; } return ans; } void c_p_c() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int main() { c_p_c(); int n; cin >> n; vector<int>v(n); for (int i = 0; i < n; ++i) cin >> v[i]; int ans = v[0]; for (int i = 1; i < n; ++i) ans = __gcd(ans, v[i]); cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define fs first #define sc second #define pb push_back #define mp make_pair #define eb emplace_back #define ALL(A) A.begin(),A.end() #define RALL(A) A.rbegin(),A.rend() typedef long long ll; typedef pair<ll,ll> P; const ll mod=1000000007; const ll LINF=1LL<<60; const int INF=1<<30; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } int main(){ int n;cin>>n; ll x;cin>>x; for(int i = 1; i < n; i++) { ll y;cin>>y; x = __gcd(x,y); } cout << x << endl; return 0; }
#include<bits/stdc++.h> using namespace std; const int N=4e5+1e3+7; int C(int n,int m) { if(n<m||n<0||m<0) return 0; long long ret=1; for(int i=n;i>=n-m+1;i--) ret=ret*i; for(int i=1;i<=m;i++) ret=ret/i; return ret%3; } int Lucas(int n,int m) { if(n<3||m<3) return C(n,m); return C(n%3,m%3)*Lucas(n/3,m/3)%3; } int get(char c) { return c=='R'?0:c=='B'?1:2; } int n; char s[N]; string ans="RBW"; int main() { scanf("%d",&n); scanf("%s",s); n--; int r=0; for(int i=0;i<=n;i++) (r+=Lucas(n,i)*get(s[i]))%=3; if(n&1) r=(3-r)%3; putchar(ans[r]); }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define rep(x,y,z) for(int x=y;x<=z;x++) const int N=4e5+10; const double eps = 0.01; const ll mod = 1e9+7; const double pi = acos(-1.0) ; const ll inf = 0x3f3f3f3f3f3f3f3f; const ll DIV=100000; inline ll read() { ll x=0,f=1;char ch=getchar(); while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();} while (isdigit(ch)){x=x*10+ch-48;ch=getchar();} return x*f; } inline void pt(ll ans,ll f){ printf("%lld",ans); if(f==1) putchar(' '); else putchar('\n'); } ll n,m,k,tot; ll f[N],g[N]; string str; int main() { // scanf("%d%d", &n, &m); int q; f[1]=0,g[1]=g[0]=1; for(int i=2;i<N;i++){ int cnt=0,tmp=i; while(tmp%3==0){ tmp/=3; cnt++; } f[i]=f[i-1]+cnt; g[i]=g[i-1]*tmp%3; } n = read(); cin>>str; int len=str.length(); ll ans=0; for(int i=0;i<len;i++){ // cout<<f[i]<<":"<<g[i]<<endl; if(str[i]=='W') ans=ans+(f[n-1]-f[i]-f[n-1-i]==0)*g[n-1]*g[i]*g[n-1-i]%3; else if(str[i]=='R') ans=ans+2*(f[n-1]-f[i]-f[n-1-i]==0)*g[n-1]*g[i]*g[n-1-i]%3; // pt(ans,2); ans%=3; } // cout<<ans<<endl; if(n%2==0) ans=(-ans+3)%3; if(ans==0) putchar('B'); else if (ans == 1 ) putchar('W'); else putchar('R'); return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0;i<(n);i++) typedef long long ll; int main(){ int a,b;cin>>a>>b; vector<ll> x(a,0),y(b,0); ll ttl=0; REP(i,a){ x.at(i)=600000-i; ttl+=x.at(i); } ll ttl2=0; REP(i,b-1){ y.at(i)=i+1; ttl2+=y.at(i); } y.at(b-1)=ttl-ttl2; REP(i,a) cout<<x.at(i)<<" "; REP(i,b) cout<<-y.at(i)<<" "; cout<<endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define all(a) (a).begin(), (a).end() using ll = long long; int mod = 1000000007; const int INF = 1001001001; template<class T> void chmin(T& a, T b) {if (a > b) a = b;} template<class T> void chmax(T& a, T b) {if (a < b) a = b;} int dx[4] = {1, -1, 0, 0}; int dy[4] = {0, 0, 1, -1}; int ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}; int ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; using Graph = vector<vector<int>>; int main() { int a, b; cin >> a >> b; if (a == b) { for (int i = 1; i <= a; i++) { cout << i << " " << -i << " "; } cout << endl; return 0; } int mi = min(a, b); int mx = max(a, b); int p = mx * (mx + 1) / 2; int d = (mi - 1) * mi / 2; for (int i = 1; i < mi; i++) { cout << i << " " << -i << " "; } int x = p - d; if (a > b) { for (int i = mi; i < mx + 1; i++) { cout << i << " "; } cout << -x << endl; return 0; } else { for (int i = mi; i < mx + 1; i++) { cout << -i << " "; } cout << x << endl; } return 0; }
#include<bits/stdc++.h> #include<iostream> #include<string> #include<cmath> #include<cstdio> #include<cctype> #include<cstring> #include<iomanip> #include<cstdlib> #include<ctime> #include<set> #include<map> #include<utility> #include<queue> #include<vector> #include<stack> #include<sstream> #include<algorithm> #define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++) #define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--) #define rep(i,n)for(int i=0,_n=n;i<n;i++) #define ll long long #define pii pair<int,int> #define vi vector<int> #define vpii vector<pii> #define m_p make_pair #define re return #define pb push_back #define si set<int> #define ld long double #define X first #define Y second #define st string #define ull unsigned long long #define mod 1000000007 #define INF 1000000007 #define x1 XZVJDFADSPFOE #define y1 GASDIJSLDAEJF #define x2 DFDAJKVOHKWIW #define y2 PSFSAODSXVNMQ #define LLINF 0x3f3f3f3f3f3f3f3fLL #define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++) using namespace std; inline void read(int &x) { short negative=1; x=0; char c=getchar(); while(c<'0' || c>'9') { if(c=='-') negative=-1; c=getchar(); } while(c>='0' && c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar(); x*=negative; } ll quickpower(ll n,ll k){ ll ans=1; while(k){ if(k%2){ ans*=n; ans%=mod; } n*=n; n%=mod; k/=2; } return ans; } string int_to_string(int n) { string s=""; while(n) { int now=n%10; s+=now+'0'; n/=10; } reverse(s.begin(),s.end()); return s; } int string_to_int(string s) { int n=0; rep(i,s.size()) { n*=10; n+=s[i]-'0'; } return n; } int n; ll a[100100],b[100100]; ll sum=0; int main() { ios::sync_with_stdio(0); cin>>n; rep(i,n)cin>>a[i]; rep(i,n)cin>>b[i]; rep(i,n)sum+=a[i]*b[i]; if(sum==0)cout<<"Yes\n"; else cout<<"No\n"; return 0; }
#include <iostream> #include <bits/stdc++.h> using namespace std; int n; int a[100000], b[100000]; int result; int main() { cin >> n; for(int i=0; i<n; i++) cin >> a[i]; for(int i=0; i<n; i++) cin >> b[i]; for(int i=0; i<n; i++) result += a[i] * b[i]; cout << (result == 0 ? "Yes" : "No"); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); ll n; cin >> n; ll a; cin >> a; ll b; cin >> b; cout << n-a+b << '\n'; return 0; }
//******\\ ||udc321|| #include<iostream> #include<vector> #include<algorithm> #include<cmath> #include<iomanip> #include<queue> #include<map> #include<set> #include<fstream> #include<cstring> #include<sstream> #define ll long long #define fr(e,r,v) for(ll e=r;e<v;e++) #define bc(e,r,v) for(ll e=r;e>v;e--) #define all(n) (n.begin(),n.end()) #define tr(ctn,it) for(typeof(ctn.begin()) it=ctn.begin(); it!=ctn.end();it++) #define ft first #define sd second #define pb push_back #define lb lower_bound #define mpr make_pair #define db double using namespace std; ll mod=1000000007; /*mt19937 rng(chrono::steady_clock::now(). time_since_epoch().count());*/ int main() { ll n,a,b; cin>>n>>a>>b; cout<<n-a+b<<endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef double db; typedef pair <int, int> pin; const int N = 2005; const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0}; int n, m, f[N][N]; char s[N][N]; bool vis[N][N]; vector <pin> vec[26]; template <typename T> inline void read(T &X) { char ch = 0; T op = 1; for (X = 0; ch > '9' || ch < '0'; ch = getchar()) if (ch == '-') op = -1; for (; ch >= '0' && ch <= '9'; ch = getchar()) X = (X * 10) + ch - '0'; X *= op; } inline bool valid(int x, int y) { return x >= 1 && x <= n && y >= 1 && y <= m && s[x][y] != '#'; } queue <pin> q; inline int solve(int sx, int sy, int ex, int ey) { q.push(pin(sx, sy)); vis[sx][sy] = 1; for (; !q.empty(); ) { pin now = q.front(); q.pop(); int x = now.first, y = now.second; if (x == ex && y == ey) return f[x][y]; for (int i = 0; i < 4; i++) { int tox = x + dx[i], toy = y + dy[i]; if (valid(tox, toy) && !vis[tox][toy]) { f[tox][toy] = f[x][y] + 1; vis[tox][toy] = 1; q.push(pin(tox, toy)); } } if (s[x][y] >= 'a' && s[x][y] <= 'z') { int c = s[x][y] - 'a'; for (int i = 0; i < vec[c].size(); i++) { int tox = vec[c][i].first, toy = vec[c][i].second; if (vis[tox][toy]) continue; vis[tox][toy] = 1; f[tox][toy] = f[x][y] + 1; q.push(pin(tox, toy)); } } } return -1; } int main() { #ifndef ONLINE_JUDGE freopen("sample.in", "r", stdin); #endif read(n), read(m); for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1); int sx, sy, ex, ey; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) { if (s[i][j] == 'G') ex = i, ey = j; if (s[i][j] == 'S') sx = i, sy = j; if (s[i][j] >= 'a' && s[i][j] <= 'z') vec[s[i][j] - 'a'].push_back(pin(i, j)); } printf("%d\n", solve(sx, sy, ex, ey)); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,a,b) for(int i = (a); i < (b); i++) #define drep(i,b,a) for(int i = (b)-1; i >= (a); i--) #define bit(n) (1LL << (n)) #define sz(x) ((int)(x).size()) #define all(x) (x).begin(),(x).end() #define SORT(v) sort(v.begin(),v.end()); #define RSORT(v) sort(v.rbegin(),v.rend()); #define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ); typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<double> vd; typedef vector<bool> vb; typedef vector<char> vc; typedef vector<vi> vvi; typedef vector<vl> vvl; typedef vector<vd> vvd; typedef vector<vb> vvb; typedef vector<vc> vvc; const int inf = 1 << 30; const ll infl = 1LL << 60; const double PI = acos(-1.0); template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template<class T> inline bool odd(T x) { return x & 1; } template<class T> inline bool even(T x) { return !(x & 1); } template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill( (T*)array, (T*)(array+N), val ); } template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) { return s << '<' << P.first << ", " << P.second << '>'; } template<class T> ostream& operator << (ostream &s, vector<T> P) { for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; } template<class T> ostream& operator << (ostream &s, vector<vector<T> > P) { for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << endl; } s << P[i]; } return s; } template<class T> ostream& operator << (ostream &s, set<T> P) { for(auto it : P) { s << "<" << it << "> "; } return s << endl; } template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) { for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s; } //---------------------------------------------------------------------------------------------- using P = pair<int,int>; int dist[2020][2020]; const int di[] = {1, 0,-1, 0}; const int dj[] = {0, 1, 0,-1}; int main() { int h,w; cin >> h >> w; vector<string> g(h); rep(i,0,h) cin >> g[i]; vector<vector<P>> table(26); vector<bool> used(26); int si,sj,gi,gj; rep(i,0,h) rep(j,0,w) { char c = g[i][j]; if('a' <= c && c <= 'z') table[c-'a'].emplace_back(i,j); if(c == 'S') si = i, sj = j; if(c == 'G') gi = i, gj = j; } Fill(dist, -1); queue<P> que; dist[si][sj] = 0; que.emplace(si,sj); while(!que.empty()) { auto [ci,cj] = que.front(); que.pop(); rep(k,0,4) { int ni = ci + di[k]; int nj = cj + dj[k]; if(ni < 0 || ni >= h || nj < 0 || nj >= w) continue; if(g[ni][nj] == '#' || dist[ni][nj] != -1) continue; dist[ni][nj] = dist[ci][cj] + 1; que.emplace(ni,nj); } char c = g[ci][cj]; if('a' <= c && c <= 'z') { if(used[c-'a']) continue; for(auto [ni,nj] : table[c-'a']) { if(ni < 0 || ni >= h || nj < 0 || nj >= w) continue; if(g[ni][nj] == '#' || dist[ni][nj] != -1) continue; dist[ni][nj] = dist[ci][cj] + 1; que.emplace(ni,nj); } used[c-'a'] = true; } } cout << dist[gi][gj] << endl; return 0; }
// #pragma optimization_level 3 // #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx") #include<bits/stdc++.h> using namespace std; #define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define MOD 1000000007 #define sym(s) s = "#" + s + "#"; #define INF 1e18 #define newl cout<<"\n"; #define pb push_back #define ppb pop_back #define mp make_pair #define ff first #define ss second #define PI 3.141592653589793238462 #define set_bits __builtin_popcountll #define sz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define alll(x,n) x+1, x+n+1 #define foo(i,a,n) for(ll i = (a); i <= n; i++) #define deb1(a) cout<<a<<"\n"; #define deb2(a,b) cout<<a<<" "<<b<<"\n"; #define deb3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n"; #define deb4(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n"; #define debp(a) cout<<a.ff<<" "<<a.ss<<"\n"; #define debv(a) for(auto it: a)cout<<it<<" ";newl; #define debm(a) for(auto it: a)cout<<"{"<<it.ff<<","<<it.ss<<"}, ";newl; #define deb1d(a,n) foo(i,1,n)cout<<a[i]<<" ";newl; #define deb2d(a,n,m) foo(i,1,n){foo(j,1,m){cout<<a[i][j]<<" ";}newl;} const int N = (int)2e+5 + 8; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<ll,ll> pll; typedef vector<ll> vll; typedef vector<pll> vpll; // typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update > pbds; // find_by_order, order_of_key #ifndef ONLINE_JUDGE #define debug(x) cerr << #x <<" "; _print(x); cerr << endl; #else #define debug(x) #endif void _print(ll t) {cerr << t;} void _print(int t) {cerr << t;} void _print(string t) {cerr << t;} void _print(char t) {cerr << t;} void _print(ld t) {cerr << t;} void _print(double t) {cerr << t;} void _print(ull t) {cerr << t;} template <class T, class V> void _print(pair <T, V> p); template <class T> void _print(vector <T> v); template <class T> void _print(set <T> v); template <class T, class V> void _print(map <T, V> v); template <class T> void _print(multiset <T> v); template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";} template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} vll v; ll t; bool P(ll x){ int k=upper_bound(all(v),x)-v.begin(); return (x-k+1)>=t; } ll bsmin(ll L, ll R){ ll mid; while (L < R) { mid = L + (R - L) / 2; if (P(mid)) R = mid; else L = mid + 1; } if (!P(L)) return -1; return L; } void MAIN(ll tc) { #ifndef ONLINE_JUDGE freopen("Error.txt", "w", stderr); #endif ll n,q; cin>>n>>q; v.resize(n); for(ll &x:v)cin>>x; v.pb(0); sort(all(v)); for(int i=0;i<q;i++){ cin>>t; cout<<bsmin(1,LLONG_MAX)<<"\n"; } } int main(){ fastio(); cout<<fixed; cout<<setprecision(10); int test__cases = 1; // cin>>test__cases; for(int i = 1; i <= test__cases; i++){ MAIN(i); } }
#include<bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; #include<ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; #define forn(i,x1,n) for(int i=x1; i<n; i++) #define forit(it, m) for(decltype(m)::iterator it = m.begin(); it!=m.end(); ++it) #define ff first #define ss second #define int long long #define pb push_back #define mp make_pair #define pii pair<int,int> #define vi vector<int> #define mii map<int,int> #define pqb priority_queue<int> #define pqs priority_queue<int,vi,greater<int> > #define setbits(x1) __builtin_popcountll(x1) #define zrobits(x1) __builtin_ctzll(x1) #define mod 1000000007 // #define mod 998244353 #define inf 1e18 #define ps(x1,y) fixed<<setprecision(y)<<x1 #define mk(arr,n,type) type *arr=new type[n]; #define w(x1) int x1; cin>>x1; while(x1--) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void zeus() { 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 } int32_t main() { zeus(); int n, q; cin >> n >> q; int a[n + 1]; forn(i, 0, n) { cin >> a[i]; } a[n] = 0; sort(a, a + n + 1); int diff[n]; forn(i, 0, n) { diff[i] = a[i + 1] - a[i] - 1; } int prefixsum[n + 1]; prefixsum[0] = 0; forn(i, 0, n) { prefixsum[i + 1] = prefixsum[i] + diff[i]; } forn(i, 0, q) { int k; cin >> k; auto ind = lower_bound(prefixsum, prefixsum + n + 1, k) - prefixsum; cout << a[ind - 1] + k - prefixsum[ind - 1] << endl; } }
#include<bits/stdc++.h> using namespace std; #define ll long long #define pi pair<ll,ll> #define pd pair<ld,ld> #define pb push_back #define inf 1e16 #define en '\n' #define ld long double #define ff first #define ss second #define ull unsigned long long #define lb lower_bound #define ub upper_bound #define fr(a,b,c) for(ll a = b ; a <= c ; ++a ) #define frn(a,b,c) for(ll a = b ; a >= c ; a -- ) #define fra(a,b) for(auto a: b) #define ms(a) memset(a,0,sizeof a); #define alla(a) a,a+n #define allv(a) a.begin(),a.end() #define size(a) (ll)a.size() #define getMat(x,n,m,val) vector<vector<ll>>x(n,vector<ll>(m,val)) const ll MAXN = 1e5+5; #define pii 3.14159265358979323846 const ll mod = 998244353; ll pw(ll b, ll r, ll md=mod){ b = b%mod; r = r%mod; ll ans = 1; while(r){ if(r&1)ans = (ans*b)%md; b = (b*b)%md; r>>=1; } return ans; } ll dp[3010][6010]; ll rec(ll n, ll k){ if(k>n)return 0; if(n==0 && k==0)return 1LL; else if(n==0 || k==0)return 0LL; if(dp[n][k]!=-1)return dp[n][k]; dp[n][k]=(rec(n-1,k-1)+rec(n,2*k))%mod; return dp[n][k]; } int main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); ll t=1; // cin>>t; while(t--){ ll n,k;cin>>n>>k; fr(i,0,n)fr(j,0,2*n)dp[i][j]=-1; cout<<rec(n,k)<<en; } return 0 ; }
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") #pragma GCC optimize(3 , "Ofast" , "inline") #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") #include <iostream> #include <cstdio> #include <algorithm> #include <unordered_map> #include <vector> #include <map> #include <list> #include <queue> #include <cstring> #include <cstdlib> #include <ctime> #include <cmath> #include <stack> #include <set> #include <bitset> #include <deque> using namespace std ; #define ios ios::sync_with_stdio(false) , cin.tie(0) #define x first #define y second #define pb push_back #define ls rt << 1 #define rs rt << 1 | 1 typedef long long ll ; const double esp = 1e-6 , pi = acos(-1) ; typedef pair<int , int> PII ; const int N = 1e6 + 10 , INF = 0x3f3f3f3f , mod = 1e9 + 7; ll qmi(ll a , ll b) { ll res = 1 ; while(b) { if(b & 1) res = res * a % mod ; a = a * a % mod ; b >>= 1 ; } return res ; } int work() { int n , p ; cin >> n >> p ; ll ans = 1ll * (p - 1) * qmi(p - 2 , n - 1) % mod ; cout << ans << "\n" ; return 0 ; } int main() { // freopen("C://Users//spnooyseed//Desktop//in.txt" , "r" , stdin) ; // freopen("C://Users//spnooyseed//Desktop//out.txt" , "w" , stdout) ; work() ; return 0 ; } /* */
#include <bits/stdc++.h> #define rep(a,b,c) for(ll a = b; a < c; a++) #define rep2(a,b,c) for(ll a = c - 1; a >=b; a--) #define all(x) (x).begin(), (x).end() #define pb push_back #define x first #define y second using namespace std; using ll = long long; using tl = tuple<ll, ll, ll>; using pl = pair<ll, ll>; using pi = pair<int, int>; using ld = long double; const int MAX = 2e5 + 3; string S; map<char, int> m; ll ans; int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); cin >> S; rep2(i, 2, S.size()) { m[S[i]]++; if (S[i - 2] == S[i - 1] && S[i - 1] != S[i]) { ans += S.size() - i - m[S[i - 2]]; m.clear(); m[S[i - 2]] = S.size() - i; } } cout << ans; return 0; }
#include <bits/stdc++.h> #define MP make_pair #define PB push_back #define int long long #define st first #define nd second #define rd third #define FOR(i, a, b) for(int i =(a); i <=(b); ++i) #define RE(i, n) FOR(i, 1, n) #define FORD(i, a, b) for(int i = (a); i >= (b); --i) #define REP(i, n) for(int i = 0;i <(n); ++i) #define VAR(v, i) __typeof(i) v=(i) #define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i) #define ALL(x) (x).begin(), (x).end() #define SZ(x) ((int)(x).size()) #define __builtin_ctz __builtin_ctzll #define __builtin_clz __builtin_clzll #define __builtin_popcount __builtin_popcountll using namespace std; template<typename TH> void _dbg(const char* sdbg, TH h) { cerr<<sdbg<<"="<<h<<"\n"; } template<typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t) { while(*sdbg != ',') { cerr<<*sdbg++; } cerr<<"="<<h<<","; _dbg(sdbg+1, t...); } #ifdef LOCAL #define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__) #define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<"\n"; }} #else #define debug(...) (__VA_ARGS__) #define debugv(x) #define cerr if(0)cout #endif #define next ____next #define prev ____prev #define left ____left #define hash ____hash typedef long long ll; typedef long double LD; typedef pair<int, int> PII; typedef pair<ll, ll> PLL; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<ll> VLL; typedef vector<pair<int, int> > VPII; typedef vector<pair<ll, ll> > VPLL; template<class C> void mini(C&a4, C b4){a4=min(a4, b4); } template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); } template<class T1, class T2> ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";} template<class A, class B, class C> struct Triple { A first; B second; C third; bool operator<(const Triple& t) const { if (st != t.st) return st < t.st; if (nd != t.nd) return nd < t.nd; return rd < t.rd; } }; template<class T> void ResizeVec(T&, vector<int>) {} template<class T> void ResizeVec(vector<T>& vec, vector<int> sz) { vec.resize(sz[0]); sz.erase(sz.begin()); if (sz.empty()) { return; } for (T& v : vec) { ResizeVec(v, sz); } } typedef Triple<int, int, int> TIII; template<class A, class B, class C> ostream& operator<< (ostream &out, Triple<A, B, C> t) { return out << "(" << t.st << ", " << t.nd << ", " << t.rd << ")"; } template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; } template<class T> ostream& operator<<(ostream& out, set<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; } template<class L, class R> ostream& operator<<(ostream& out, map<L, R> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; } const int N = 111; typedef bitset<N> B; int32_t main() { ios_base::sync_with_stdio(0); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); cin.tie(0); //double beg_clock = 1.0 * clock() / CLOCKS_PER_SEC; int n; cin>>n; vector<B> dis(n + 2); RE (i, n) { string s; cin>>s; dis[i][i] = 1; RE (j, n) { if (s[j - 1] == '1') { dis[j][i] = 1; } } } LD res = 0; RE (i, n) { VI vis(n + 2); int cnt = 0; function<void(int)> Dfs = [&](int v) { vis[v] = 1; cnt++; RE (j, n) { if (dis[v][j] == 1 && !vis[j]) { Dfs(j); } } }; Dfs(i); res += 1. / cnt; } // RE (k, n) { // RE (i, n) { // RE (j, n) { // dis[i] |= dis[i][k] & dis[k][j]; // } // } // } // LD res = 0; // RE (i, n) { // res += 1. / dis[i].count(); // } cout<<res<<endl; return 0; }