code_file1
stringlengths
87
4k
code_file2
stringlengths
82
4k
#include<bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define INF 0x3f3f3f3f #define pi M_PI typedef pair<ll, ll> llPair; typedef vector<ll> vll; typedef vector<ld> vld; typedef vector<bool> vb; typedef priority_queue<ll> pqll; ll MOD = 1000000007; /* Really doe, like really doe Really doe, like really doe */ int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); ll t; t = 1; for (ll z = 0; z < t; ++z) { ll h, w; cin >> h >> w; vector<vb> block(h, vb(w, false)); vector<vll> dp(h, vll(w, 0)); vector<vll> dig(h + 1, vll(w + 1, 0)); vector<vll> hor(h + 1, vll(w + 1, 0)); vector<vll> ver(h + 1, vll(w + 1, 0)); for (ll i = 0; i < h; ++i) { for (ll j = 0; j < w; ++j) { char c; cin >> c; if (c == '#') { block[i][j] = true; } } } dp[0][0] = 1; dig[1][1] = 1; hor[1][1] = 1; ver[1][1] = 1; for (ll i = 0; i < h; ++i) { for (ll j = 0; j < w; ++j) { if (i == 0 && j == 0)continue; else if (block[i][j]) { dp[i][j] = 0; dig[i][j] = 0; hor[i][j] = 0; ver[i][j] = 0; } else { dp[i][j] = hor[i][j + 1] + ver[i + 1][j] + dig[i][j]; dp[i][j] %= MOD; hor[i + 1][j + 1] = (hor[i][j + 1] + dp[i][j]) % MOD; dig[i + 1][j + 1] = (dig[i][j] + dp[i][j]) % MOD; ver[i + 1][j + 1] = (ver[i + 1][j] + dp[i][j]) % MOD; } } } cout << dp[h - 1][w - 1] << '\n'; } return 0; }
// time-limit: 2000 #include<bits/stdc++.h> using namespace std; #define int long long const int inf = 1e9 + 7; void solve(){ int n; cin >> n; vector<int> xi(n+1), yi(n+1); for(int i=1; i<=n; i++){ cin >> xi[i] >> yi[i]; } int m; cin >> m; typedef array<int, 3> arr; // 0:x, 1:y, 2:c vector<arr> X(m+1), Y(m+1); X[0][0] = 1; Y[0][1] = 1; X[0][1] = X[0][2] = Y[0][0] = Y[0][2] = 0; auto neg = [&](arr a){ for(int i=0; i<3; i++){ a[i] *= -1; } return a; }; for(int i=1; i<=m; i++){ int op; cin >> op; if(op == 1){ X[i] = Y[i-1]; Y[i] = neg(X[i-1]); } else if(op == 2){ X[i] = neg(Y[i-1]); Y[i] = X[i-1]; } else if(op == 3){ int p; cin >> p; X[i] = neg(X[i-1]); X[i][2] += 2 * p; Y[i] = Y[i-1]; } else{ int p; cin >> p; X[i] = X[i-1]; Y[i] = neg(Y[i-1]); Y[i][2] += 2 * p; } } int q; cin >> q; for(int i=0; i<q; i++){ int point, after; cin >> after >> point; cout << X[after][0]*xi[point] + X[after][1]*yi[point] + X[after][2] << ' '; cout << Y[after][0]*xi[point] + Y[after][1]*yi[point] + Y[after][2] << '\n'; } } signed main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int T = 1, t = 0; while(t++ < T){ //cout << "Case #" << t << ": "; solve(); } return 0; }
#include<bits/stdc++.h> typedef uint64_t u64; typedef int64_t i64; typedef long double f128; using namespace std; template<typename T> void scan(T& n){ cin>>n; } template<typename T,typename U> void scan(pair<T,U>& p){ cin>>p.first>>p.second; } void scan(){} template<typename T,class... Args> void scan(T& n,Args&... args){ scan(n); scan(args...); } template<typename T> void scanall(T start,T end){ for(;start!=end;++start){ scan(*start); } } template<typename T> void print(T n){ cout<<n; } template<typename T,typename U> void print(pair<T,U> p){ cout<<'{'<<p.first<<','<<p.second<<'}'; } void print(){} template<typename T,class... Args> void print(T n,Args... args){ print(n); print(args...); } template<typename T> void println(T n){ print(n); cout<<endl; } template<typename T,class... Args> void println(T n,Args... args){ print(n,' '); println(args...); } template<typename T> void printall(T start,T end){ if(start!=end){ print(*start); for(++start;start!=end;++start){ print(' ',*start); } } cout<<endl; } template<typename T> T chmax(T& n,T m){ return n=max(n,m); } template<typename T> T chmin(T& n,T m){ return n=min(n,m); } template<typename T,typename U> T power(T a,U n){ T res=1; while(n){ res*=(n&1)?a:1; a*=a; n>>=1; } return res; } template<typename T> struct combination{ vector<T> fact; combination(const int Max):fact(Max+1,1){ for(int i=2;i<=Max;++i){ fact[i]=fact[i-1]*(T)i; } } template<typename U> T nCk(U n,U k){ if(n<k||n<0||k<0){ return 0; } return fact[n]/fact[k]/fact[n-k]; } }; void solve(); int main(){ cout<<fixed<<setprecision(15); bool is_multitestcase=0; int T=1; if(is_multitestcase){ scan(T); } for(int i=0;i<T;++i){ solve(); } return 0; } void solve(){ f128 A,B; scan(A,B); println(A*B/100); }
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define all(x) x.begin(),x.end() #define pll pair <long long,long long> #define ss second #define ff first #define inf (ll)1e18 #define mod 1000000007 #define ld long double #define fast ios_base::sync_with_stdio(false);cin.tie(NULL); #define endl "\n" const ll N=1000001 ; int main() { fast ; ll n,m ; cin>>n>>m ; vector<ll>v(m+2) ; for(ll i=1;i<=m;i++) cin>>v[i] ; v[0]=0 ; v[m+1]=n+1 ; sort(all(v)) ; ll mn=n,ans=0; for(ll i=1;i<=m+1;i++) { if(v[i]-v[i-1]>1) { mn=min(mn,v[i]-v[i-1]-1) ; } } for(ll i=1;i<=m+1;i++) { if(v[i]-v[i-1]>1) { ans+=(v[i]-v[i-1]-1+mn-1)/mn ; } } cout<<ans<<endl ; }
#include <bits/stdc++.h> using namespace std; using ll = long long; ll solve() { ll N; cin >> N; vector<ll> P(N); for ( int i = 1; i < N; i++ ) { cin >> P[i]; P[i]--; } P[0] = -1; vector<vector<int>> G(N); // ch for ( int i = 1; i < N; i++ ) { G[P[i]].push_back(i); } vector<int> pt(N), sb(N,1); auto dfs = [&](auto self, int v) -> void { vector<vector<int>> val(2); // [even/odd] 選択したときに得るコインの差分 for ( int u : G[v] ) { self(self, u); sb[v] += sb[u]; val[sb[u]%2].push_back(pt[u]); } int s = -1; for ( int a : val[0] ) { if ( a > 0 ) s += a; } sort(val[1].rbegin(), val[1].rend()); int odd = 1; for ( int a : val[1] ) { s += a * odd; odd *= -1; } for ( int a : val[0] ) { if ( a < 0 ) s += a * odd; } pt[v] = s; }; dfs(dfs,0); ll ans = (N-pt[0])/2; return ans; } int main() { auto ans = solve(); cout << ans << "\n"; return 0; }
#include <iostream> #include <vector> using namespace std; using ll = long long; int main() { int n; cin >> n; vector<ll> vec(n); for (int i = 0; i < n; ++i) { if (i == 0) { cin >> vec[i]; } else { ll tmp; cin >> tmp; vec[i] = vec[i-1] + tmp; } } ll cur = 0; ll ans = 0; ll vmax = vec[0]; for (auto &v : vec) { vmax = max(v, vmax); ans = max(ans, cur + vmax); cur += v; } cout << ans << endl; }
// E - White Pawn #include <bits/stdc++.h> using namespace std; int main(){ int N, M; cin>>N>>M; int C = min(N, M), L = C*2 + 1; auto ixOk = [&](int y){ return 0 <= y && y < L; }; vector<pair<int,int>> D; while(M--){ int x, y; cin>>x>>y; y -= N - C; if(ixOk(y)) D.emplace_back(x, y); } sort(D.begin(), D.end()); vector<int> Y, S(L); S[C] = 1; auto update = [&](){ vector<int> A; for(int&y:Y) if((ixOk(y-1) && S[y-1]) || (ixOk(y+1) && S[y+1])) A.push_back(y); for(int&y:Y) S[y] = 0; for(int&y:A) S[y] = 1; }; int px = 0; for(auto&[x, y]:D){ if(px != x) update(), Y.clear(), px = x; Y.push_back(y); } update(); cout<< accumulate(S.begin(), S.end(), 0) <<endl; }
#include <bits/stdc++.h> #define int long long #define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); using namespace std; const int N = 2e5+5; int bit[N], row[N], col[N]; vector<int> tt[N]; void update(int pos, int val){ while(pos < N){ bit[pos] += val; pos += pos&-pos; } } int query(int pos){ int res = 0; while(pos){ res += bit[pos]; pos -= pos&-pos; } return res; } signed main(){ fastio int h,w,m; cin >> h >> w >> m; fill(row,row+N,w); fill(col,col+N,h); while(m--){ int x,y; cin >> x >> y; x--,y--; row[x] = min(row[x],y); col[y] = min(col[y],x); tt[y].push_back(x); } int ans = 0; int i; for(i = 0;i < h&&row[i];i++) ans += row[i]; int ok[h]; fill(ok,ok+h,1); for(;i < h;i++) ok[i] = 0, update(i,1); for(i = 0;i < w&&col[i];i++){ for(int j : tt[i]){ if(ok[j]) ok[j] = 0, update(j,1); } ans += query(col[i]-1); } cout << ans << "\n"; } /* * * * * * * X * * X * X * * * * */
#include <bits/stdc++.h> #define spd ios::sync_with_stdio(false),cin.tie(0) using namespace std; using ll = long long; #define N 1000005 #define MAX 1e18 vector<ll> powers; set<ll> squares; set<ll> s; void powersPrecomputation() { for (ll i = 2; i < N; i++) { squares.insert(i * i); if (squares.find(i) != squares.end()) continue; ll temp = i; while (i * i <= MAX / temp) { temp *= (i * i); s.insert(temp); } } for (auto x : s) powers.push_back(x); } ll calculateAnswer(ll L, ll R) { ll perfectSquares = floor(sqrtl(R)) - floor(sqrtl(L - 1)); ll high = (upper_bound(powers.begin(), powers.end(), R) - powers.begin()); ll low = (lower_bound(powers.begin(), powers.end(), L) - powers.begin()); perfectSquares += (high - low); return perfectSquares; } int main() { powersPrecomputation(); ll L = 1; ll R; cin >> R; cout << R - calculateAnswer(L, R) + 1 << endl; return 0; }
#include <bits/stdc++.h> using Int = long long; // clang-format off #define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++) #define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__) #define RREP_(i, a_, b_, a, b, ...) for (Int i = Int(b) - 1, low##i = (a); i >= low##i; i--) #define RREP(i, ...) RREP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__) #define ALL(v) std::begin(v), std::end(v) struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io; #ifndef dump #define dump(...) #endif // clang-format on struct in { template <class T> operator T() { T t; std::cin >> t; return t; } }; void out() { std::cout << "\n"; } template <class Head, class... Tail> void out(Head&& h, Tail&&... t) { std::cout << h << (sizeof...(Tail) == 0 ? "" : " "), out(std::forward<Tail>(t)...); } template <class T> bool chmin(T& a, const T& b) { return a > b ? a = b, true : false; } template <class T> bool chmax(T& a, const T& b) { return a < b ? a = b, true : false; } template <class T> using V = std::vector<T>; /** * author: knshnb * created: Sun Feb 28 00:29:14 JST 2021 **/ V<V<Int>> solve(Int n) { V<V<Int>> ret(1); REP(i, 1 << n) ret[0].push_back(i < (1 << (n - 1))); if (n == 1) return ret; auto sub = solve(n - 1); REP(t, 2) { for (auto& v : sub) { ret.push_back({}); for (Int x : v) ret.back().push_back(x); for (Int x : v) ret.back().push_back(t ? !x : x); } } return ret; } signed main() { Int n = in(); auto res = solve(n); out(res.size()); for (auto& v : res) { for (Int x : v) std::cout << char('A' + x); out(); } }
#include<iostream> #include<vector> using namespace std; const int BUF = 100005; const int BIT = 25; int N, M; int val[BUF]; void read() { cin >> N >> M; for (int i = 0; i < N; ++i) { string s; cin >> s; val[i] = 0; for (int j = 0; j < M; ++j) { val[i] <<= 1; val[i] += s[j] - '0'; } } } void work() { int cnt[BIT] = {}; for (int i = 0; i < N; ++i) { ++cnt[__builtin_popcount(val[i])]; } long long ans = 0; for (int i = 0; i < BIT; ++i) { for (int j = i + 1; j < BIT; ++j) { if (abs(i - j) % 2 == 1) { ans += 1LL * cnt[i] * cnt[j]; } } } cout << ans << endl; } int main() { read(); work(); return 0; }
#include<bits/stdc++.h> #define FOR(i,s,t) for(int i=s;i<=t;++i) #define REP(i,t,s) for(int i=t;i>=s;--i) #define RESET(a) memset(a,0,sizeof a) using namespace std; typedef long long ll; const ll M=3e10; char s[200005]; int n,vi[3]; int main() { scanf("%d%s",&n,s); FOR(i,0,n-1) { s[i]-='0'; if((s[i]==0)^(i%3==0)) vi[0]=1; if((s[i]==0)^(i%3==1)) vi[1]=1; if((s[i]==0)^(i%3==2)) vi[2]=1; } ll ans=0; if(!vi[2]) { ans+=(M-n)/3+1; } if(!vi[1]) { ans+=(M-n-1)/3+1; } if(!vi[0]) { ans+=(M-n-2)/3+1; } cout<<ans; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using P = pair<int,int>; template<class T> using V = vector<T>; template<typename T> using posteriority_queue = priority_queue<T,vector<T>,greater<T>>; #define rep(i,n) for (int i = 0; i < (int)(n) ; i++) #define rep2(i,a,b) for (int i = (a); i < (int)(b); i++) #define repR(i,n) for (int i = (int)(n)-1; i >= 0; i--) #define repR2(i,a,b) for (int i = (int)(b)-1; i >= (int)(a); i--) #define ENDL '\n' #define pb push_back #define SIZE(a) (int)(a.size()) #define ALL(a) a.begin(),a.end() #define RALL(a) a.rbegin(),a.rend() #define UNIQUE(a) a.erase(unique(all(a)),a.end()); #define debug(x) cout<<(#x)<<" is : "<<(x)<<endl; #define debugc(vec) {cout<<(#vec)<<" is below; -------"<<endl;for(auto elements:(vec))cout<<elements<<" ";cout<<endl<<"------------------"<<endl;} inline string rev(string s) {string t(s.rbegin(), s.rend()); return t;} template<class T> inline bool chmin(T &a, T b) { if(a>b) {a=b; return 1;} return 0;} template<class T> inline bool chmax(T &a, T b) { if(a<b) {a=b; return 1;} return 0;} const ll INF = (1LL<<30)-1; const ll INFLL = (1LL<<62)-1; const ld PI = 3.14159265358979323846L; const ll MOD = 998244353; ll modpow(ll x,ll y,ll mod) { //繰り返し二乗法 if(mod==1) return 1;//特殊処理 if(y==0) return 1; if(y==1) return x%mod; if(y%2==1) return x*modpow(x,y-1,mod)%mod; ll rt = modpow(x,y/2,mod); return rt*rt%mod; } int main() { cout << fixed << setprecision(15); cin.tie(nullptr); ios_base::sync_with_stdio(false); ll n, cnt=0; cin>>n; V<ll> edge(n), seen(n); rep(i, n) { cin>>edge[i]; edge[i]--; } rep(i, n) { if(seen[i]) continue; seen[i]=i+1; ll now = i; while(1) { ll to = edge[now]; if(seen[to]) { if(seen[to]==i+1) cnt++; break; } seen[to]=i+1; now = to; } } cout << modpow(2,cnt,MOD)-1 << endl; }
#include<bits/stdc++.h> using namespace std; vector<int>f(200009),sz(200009,0); inline int getf(int x) { if(x!=f[x]) return f[x]=getf(f[x]); else return x; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; long long ans=0; cin>>n; vector<int>a(n); for(int i=1;i<=200008;i++) f[i]=i; for(int i=0;i<n;i++) cin>>a[i]; for(int i=0;i<n/2;i++) f[getf(a[i])]=getf(a[n-i-1]); for(int i=1;i<=200008;i++) sz[getf(i)]++; for(int i=1;i<=200008;i++) if(i==getf(i)) ans+=sz[i]-1; cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define endl "\n" #define fo(i,s,e) for( i=s;i<e;i++) #define rfo(i,s,e) for(i=s;i>e;i--) #define ll long long int #define pb push_back #define pob pop_back() #define sp " " #define ff first #define ss second const ll MOD=1e9+7; const ll INF = (1LL << 60) - 1; ll power(ll x, ll y){ if (y == 0) return 1; ll temp = power(x, y / 2); if (y % 2 == 0) return temp * temp; else return (x * temp) * temp; } int main(){ int t; cin>>t; ll count1=0; vector <pair<int,int>> v; while(t--){ int x,y; cin>>x>>y; v.pb({x,y}); } for(int i=0;i<v.size()-1;i++){ for(int j=i+1;j<v.size();j++){ // cout<<(float)(v[j].ss-v[i].ss)/(v[j].ff-v[i].ff)<<" "; if((float)(v[j].ss-v[i].ss)/(v[j].ff-v[i].ff)>=-1 && (float)(v[j].ss-v[i].ss)/(v[j].ff-v[i].ff)<=1) count1++; } } cout<<count1; return 0; }
//#include<cstdio> //#include<cassert> //#include<iostream> //#include<cstring> //#include<algorithm> #include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> #define MAX ((int)2e9 + 5) #define MAXP ((int)1e5 + 5) #define MAXL ((ll)1e18 + 5) #define MAX_X ((int)2001) #define MAX_Y ((int)2001) #define pi acos(-1) #define MOD ((int)1e9 + 7) //#define MOD ((int)998244353 + 0) #define BAS ((int)1e6 + 3) //#define BAS ((int)2e5 + 3) #define N ((int)1e5 + 9) #define eps (1e-8) #define fastio ios_base::sync_with_stdio(false),cin.tie(NULL) #define logn 17 #define endl "\n" #define mpp make_pair #define BUCK 105 #define LEF (idx<<1) #define RIG ((idx<<1)|1) //#define int ll using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef unsigned long long ull; /*fast io ios_base::sync_with_stdio(false); cin.tie(NULL); */ typedef tree < int, null_type, less < int >, rb_tree_tag, tree_order_statistics_node_update > o_set; typedef tree < pair < int, int >, null_type, less < pair < int, int > >, rb_tree_tag, tree_order_statistics_node_update > o_setp; /// o_set s; /// s.order_of_key(k) : Number of items strictly smaller than k . /// *(s.find_by_order(k)) : K-th element in a set (counting from zero). typedef long double ldd; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int my_rand(int l, int r) { return uniform_int_distribution<int>(l,r) (rng); } int arr[N]; ll pre[N]; int main() { fastio; int n; cin>>n; for(int i = 1 ; i<=n ; i++){ cin>>arr[i]; arr[i] += arr[i]; } sort(arr+1,arr+n+1); for(int i = 1 ; i<=n ; i++) pre[i] = pre[i-1] + arr[i]; ll ans = MAXL; for(int i = 1 ; i<=n ; i++){ ll sum = 1LL*(i-1)*arr[i]/2 + (pre[n] - pre[i-1]) - 1LL*(n-i+1)*arr[i]/2; ans = min(ans , sum); } cout<<fixed<<setprecision(20); cout<<ans/(2.0*n)<<endl; return 0; }
#include <bits/stdc++.h> //#include <atcoder/all> using namespace std; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; static const double EPS = 1e-12; static const double PI = acos(-1.0); #define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(a) (a).begin(), (a).end() #ifdef LOCAL #define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl #else #define dbg(x) true #endif void solve(long long N) { ll x = 999'999'999'999'999; ll ans = 0; while (x > 0) { if (N > x) { ans += N - x; } x /= 1000; } cout << ans << endl; } int main() { long long N; scanf("%lld", &N); solve(N); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) // allマクロの定義 #define all(v) v.begin(), v.end() using ll = long long; int main() { ll N; cin >> N; if (1 <= N && N < pow(10, 3)) { cout << 0 << endl; return 0; }else if (pow(10, 3) <= N && N < pow(10, 6)) { cout << N-1000+1 << endl; }else if (pow(10, 6) <= N && N < pow(10, 9)) { cout << 2*(N-1000000+1) + 999000 << endl; }else if (pow(10, 9) <= N && N < pow(10, 12)) { cout << 3*(N-1000000000+1) + 2*999000000 + 999000 << endl; }else if (pow(10, 12) <= N && N < pow(10, 15)) { cout << 4*(N-1000000000000+1) + 3*999000000000 + 2*999000000 + 999000 << endl; }else if (N == pow(10, 15)) { cout << 5 + 4*999000000000000 + 3*999000000000 + 2*999000000 + 999000 << endl; } }
#include <bits/stdc++.h> using namespace std; #define reps(i,s,n) for(int i = s; i < n; i++) #define rep(i,n) reps(i,0,n) using ll = long long; using P = pair<int,int>; template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } int V, E; const int MAX_V = 2e5 + 5; using DD = int; //ll; #define INF 1e9+7 DD d[MAX_V]; struct edge {int to; DD cost; }; vector<edge> G[MAX_V]; int pprev[MAX_V]; void add_edge(int from, int to, DD dist) { G[from].push_back((edge){to, dist}); G[to].push_back((edge){from, dist}); } void dijkstra(int s){ priority_queue<P, vector<P>, greater<P> > que; fill(d, d + V, INF); fill(pprev, pprev + V, -1); d[s] = 0; que.push(P(0, s)); while(!que.empty()){ P p = que.top(); que.pop(); int v = p.second; if (d[v] < p.first)continue; for (int i = 0; i < G[v].size(); i++){ edge e = G[v][i]; if (d[e.to] > d[v] + e.cost){ d[e.to] = d[v] + e.cost; que.push(P(d[e.to], e.to)); pprev[e.to] = v; } } } } const int MAX_N = 17; //int n; int dd[MAX_N][MAX_N]; int dp[1 << MAX_N][MAX_N]; int N, M, K; int rec(int S, int v, int dep){ if (dp[S][v] >= 0) { return dp[S][v]; } if (S == (1 << K) - 1){ return dp[S][v] = 0; } int res = INF; for (int u = 0; u < K; u++) { if (!(S >> u & 1)) { res = min(res, rec(S | 1 << u, u, dep + 1) + dd[v][u]); } } return dp[S][v] = res; } int C[100005]; int main() { cin >> N >> M; V = N, E = M; rep(i, M){ int a, b; cin >> a >> b; a--; b--; add_edge(a, b, 1); } cin >> K; rep(i, K){ cin >> C[i]; C[i]--; } rep(i, K)rep(j, K){ dd[i][j] = INF; if (i > j){ int s = C[i], g = C[j]; dijkstra(s); dd[i][j] = d[g]; dd[j][i] = d[g]; //fprintf(stderr, "dd[%d][%d] = %d\n", C[i] + 1, C[j] + 1, dd[i][j]); if (d[g] == INF){ cout << -1; return 0; } } } memset(dp, -1, sizeof(dp)); int res = INF; for (int u = 0; u < K; u++) { chmin(res, rec(1 << u, u, 1)); } cout << res + 1; }
#include <bits/stdc++.h> using namespace std ; const int MAX = 18 ; int mark[MAX][MAX] ; int n , m ; int can[1 << MAX] , dp[1 << MAX] ; int main() { ios_base::sync_with_stdio(0) ; cin.tie(0) ; cin>>n>>m ; for(int i = 0 ; i < m ; ++i) { int a , b ; cin>>a>>b ; a-- , b-- ; mark[a][b] = mark[b][a] = 1 ; } can[0] = 1 ; for(int mask = 1 ; mask < (1 << n) ; ++mask) { int first = -1 ; for(int bit = 0 ; bit < n ; ++bit) { if((mask & (1 << bit))) { if(first == -1) can[mask] = can[mask ^ (1 << bit)] , first = bit ; else can[mask] &= mark[first][bit] ; } } } dp[0] = 0 ; for(int mask = 1 ; mask < (1 << n) ; ++mask) { dp[mask] = 1e9 ; for(int submask = mask ; submask ; submask = (submask - 1) & mask) { if(can[submask]) dp[mask] = min(dp[mask] , 1 + dp[mask ^ submask]) ; } } return cout<<dp[(1 << n)-1]<<"\n" , 0 ; }
#include<iostream> #include<algorithm> #include<vector> using namespace std; int gcd(int a,int b){return b?gcd(b,a%b):a;} int N; int A[2020]; bool ok(int X) { int g=0; for(int i=0;i<N;i++) { int t=gcd(g,A[i]); if(t%X==0)g=t; } return g==X; } main() { cin>>N; vector<pair<int,int> >X; int mA=1e9; for(int i=0;i<N;i++) { cin>>A[i]; mA=min(mA,A[i]); for(int j=1;j*j<=A[i];j++)if(A[i]%j==0) { X.push_back(make_pair(j,i)); if(A[i]/j>j)X.push_back(make_pair(A[i]/j,i)); } } sort(X.begin(),X.end()); int ans=0; for(int i=0;i<X.size();) { if(X[i].first>mA)break; int j=i+1; int g=A[X[i].second]; while(j<X.size()&&X[i].first==X[j].first) { g=gcd(g,A[X[j++].second]); } if(g==X[i].first)ans++; i=j; } cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<ll> a(n); for (auto &it: a) cin >> it; vector<ll> pre(n+1); ll pre_mx = 0, an = 0, pos = 0; for (int i = 0; i < n; ++i) { pre[i+1] = pre[i] + a[i]; pre_mx = max(pre_mx, pre[i+1]); an = max(an, pos+pre_mx); pos += pre[i+1]; } cout << an << '\n'; return 0; }
#include<iostream> #include<cstring> #include<cmath> #include<vector> #include<map> #include<set> #include<queue> #include<stack> #include<deque> #include <algorithm> using namespace std; #define mem(a,b) memset(a,b,sizeof a) #define PII pair<int,int> #define ll long long #define ull unsigned long long #define ft first #define sd second #define endl '\n' #define PI acos(-1.0) #define lcm(a,b) a/gcd(a,b)*b #define INF_INT 0x3f3f3f3f #define debug(a) cout<<#a<<"="<<a<<endl; #define _for(i,a,b) for( int i=(a); i<(b); ++i) #define _rep(i,a,b) for( int i=(a); i<=(b); ++i) //inline void print(__int128 x){if(x<0){putchar('-');x=-x;}if(x>9) print(x/10);putchar(x%10+'0');} int gcd(int a, int b){return b ? gcd(b, a % b) : a;} int exgcd(int a, int b, int &x, int &y){if(!b){x = 1; y = 0;return a;}int d = exgcd(b, a % b, y, x);y -= (a/b) * x;return d;} ll qmi(ll m, ll k, ll p){ll res = 1 % p, t = m;while (k){if (k&1) res = res * t % p;t = t * t % p;k >>= 1;}return res;} inline int read(){int s=0,x=1;char ch=getchar();while(ch<'0'||ch>'9') {if(ch=='-') x=-1; ch=getchar();}while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar(); }return s*x;} const int NN = 1e6+7; const int mod = 1e9+7; int N,M,k; ll C(int n, int m){ if(n<0||m<0) return 0; ll res = 1; _rep(i,1,n+m){ res = (res*i)%mod; } _rep(i,2,m){ ll ni = qmi(i,mod-2,mod); res = (res*ni) %mod; } _rep(i,2,n){ ll ni = qmi(i,mod-2,mod); res = (res*ni) %mod; } return res; } void solve() { cin >> N >> M >> k; if(N-k-M > 0) puts("0"); else{ cout << (C(N,M)-C(N-k-1,M+k+1)+mod)%mod << endl; } } int main() { //ios::sync_with_stdio(0); int T = 1; while(T--) { solve(); } return 0; }
#pragma GCC optimize("O3") #pragma GCC target("sse4") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef unsigned int uint; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpii; #define FOR(i, a, b) for (int i = a; i <= (b); i++) #define F0R(i, a) for (int i = 0; i < (a); i++) #define FORd(i, a, b) for (int i = (b); i >= a; i--) #define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--) #define trav(a, x) for (auto &a : x) #define sz(x) (int)(x).size() #define popcnt(x) __builtin_popcount(x) #define low_bo(a, x) (lower_bound(a.begin(), a.end(), x) - a.begin()) #define up_bo(a, x) (upper_bound(a.begin(), a.end(), x) - a.begin()) #define unique(a) a.resize(unique(a.begin(), a.end()) - a.begin()) #define shuffle(a) shuffle(a.begin(), a.end(), rnd) #define mp make_pair #define pb push_back #define eb emplace_back #define f first #define s second #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() #define ins insert mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int MOD = 998244353; const char nl = '\n'; const int MX = 20000; //check the limits, dummy int n, m, np; ull fac[MX]; ll c[5001]; ll rev(ll x, ll m) { return x == 1 ? 1 : (1 - rev(m % x, x) * (ll)m) / x + m; } ll choose(ll n, ll r) { if (n < r) return 0; if (r == 0) return 1; return ((fac[n] * (rev(fac[r], MOD) % MOD)) % MOD * (rev(fac[n - r], MOD) % MOD)) % MOD; } void init() { fac[0] = 1; for (int i = 1; i < MX; i++) fac[i] = (fac[i - 1] * i) % MOD; } void solve(int t) { cin >> n >> m; np = (n / 2) * 2; if (m % 2) { cout << "0\n"; return; } ll dp[5001][13]; for (int ma = 0; ma < 5001; ma++) { if (ma % 2) continue; dp[ma][0] = choose(n, ma); } for (int d = 1; d < 13; d++) { for (int ma = 0; ma < 5001; ma++) { if (ma % 2) continue; int p2 = (1 << d); int mx = min(ma / 2 / p2, n / 2); ll ret = 0; for (int i = 0; i <= mx; i++) { ret = ((dp[2 * i][0] * dp[ma - i * 2 * p2][d - 1]) % MOD + ret) % MOD; } dp[ma][d] = ret; } } int d = 0; while ((1 << d) <= m) d++; cout << dp[m][d - 2] << nl; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(20); cout << fixed; init(); int T = 1; F0R(i, T) { solve(i + 1); } } // read the question correctly (ll vs int) // template by bqi343
#include <algorithm> #include <iostream> #include <vector> #include <map> #include <cstdio> #include <string> #include <cmath> #include <queue> #include <tuple> #include <bitset> #include <cassert> #include <chrono> #include <cstring> #include <iomanip> #include <iostream> #include <random> #include <set> #include <stack> #include <time.h> #include <unordered_map> //#include <bits/stdc++.h> #define maxs(x,y) x = max(x,y) #define mins(x,y) x = min(x,y) #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,i0,n) for(int (i)=(i0);(i)<(n);(i)++) #define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--) #define SORT(x) sort(x.begin(),x.end()) #define SORTR(x) sort(x.begin(),x.end(),greater<int>()) #define fi first #define se second #define pb push_back #define eb emplace_back #define mp make_pair #define mt make_tuple using namespace std; using ll = long long; typedef std::pair<int, int> pii; typedef std::pair<int, double> pid; typedef std::vector<int> vi; typedef std::vector<pii> vii; #define PI 3.14159265358979323846264338327950L const int mod = 1000000007; struct container{ int bottom, top, id; container(int id, int bottom, int top): top(top), bottom(bottom),id(id){ } }; struct Data { int ind; ll time; Data(int ind,ll time): ind(ind),time(time){} bool operator<(const Data& a) const { return time > a.time; } }; class UnionFind{ public: int uf[200005]; unordered_map<int,unordered_map<int,int>> kids; UnionFind(vector<int>& a){ int n = a.size(); memset(uf,-1,sizeof uf); for(int i = 0; i < n; i++){ kids[i+1][a[i]] = 1; } } int parent(int i){ if (uf[i] < 0) return i; return uf[i] = parent(uf[i]); } void join(int i, int j){ int pi = parent(i); int pj = parent(j); if (pi == pj) return; if (size(pi) < size(pj)) swap(pi,pj); for(auto e: kids[pj]){ kids[pi][e.first] += e.second; } uf[pi] += uf[pj]; uf[pj] = pi; } int size(int i){ int pi = parent(i); return abs(uf[pi]); } void init(){ memset(uf,-1,sizeof uf); } }; void solve(){ int n,q; cin >> n >> q; vector<int> c(n); rep(i,n) cin >> c[i]; UnionFind uf(c); rep(i,q){ int t; cin >> t; if (t==1){ int a,b; cin >> a >> b; uf.join(a,b); } else{ int x,y; cin >> x >> y; int p = uf.parent(x); cout << uf.kids[p][y] << endl; } } } int main() { int T = 1; //cin >> T; while (T--){ solve(); cout << endl; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> p_ll; template<class T> void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; } #define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++) #define all(vec) vec.begin(), vec.end() #define rep(i,N) repr(i,0,N) #define per(i,N) for (ll i=(ll)N-1; i>=0; i--) #define popcount __builtin_popcount const ll LLINF = pow(2,61)-1; const ll INF = pow(2,30)-1; ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); } ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } ll modpow(ll x, ll p, ll m) { ll result = 1, now = 1, pm = x; while (now<=p) { if (p&now) { result = result * pm % m; } now*=2; pm = pm*pm % m; } return result; } int main() { ll A, B, C; cin >> A >> B >> C; ll bc = modpow(B,C,4); if (bc==0) bc = 4; ll abc = modpow(A,bc,10); cout << abc << endl; return 0; }
#include<bits/stdc++.h> #define ull unsigned long long #define ll long long #define F first #define S second #define pss pair<string,string> #define pcc pair<char,char> #define pll pair<ll,ll> #define pii pair<int,int> #define piii pair<int,pii> #define vi vector<int> #define vii vector<pii> #define pb push_back #define vs vector<string> #define vl vector<ll> #define vs vector<string> #define vll vector<pll> #define vss vector<pss> #define vcc vector<pcc> #define MP make_pair #define rep(i,n) for(int i=0;i<n;i++) #define REP(i,n) for(int i=n-1;i>=0;i--) #define Very_fast std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); using namespace std; const int N = 1e5+5; int mod=10; const int INF=0x3f3f3f3f; inline ll gcd(ll a,ll b){if(b==0)return a;else return gcd(b,a%b);} inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;} inline ll lowbit(ll x){return (x&-x);} inline ll kissme(ll x,ll y) { ll res=1; if(x==0)return 1; if(x==1)return y; res=kissme(x/2,y); res=res*res%mod; if(x%2==1)res=res*y%mod; return res; } ll a,b,c;vi v[20]; void init() { v[0].pb(0); v[1].pb(1); v[2].pb(2); v[2].pb(4); v[2].pb(8); v[2].pb(6); v[3].pb(3); v[3].pb(9); v[3].pb(7); v[3].pb(1); v[4].pb(4); v[4].pb(6); v[5].pb(5); v[6].pb(6); v[7].pb(7); v[7].pb(9); v[7].pb(3); v[7].pb(1); v[8].pb(8); v[8].pb(4); v[8].pb(2); v[8].pb(6); v[9].pb(9); v[9].pb(1); } signed main() { Very_fast; init(); cin>>a>>b>>c; mod=v[a%10].size(); cout<<v[a%10][(kissme(c,b)-1+mod)%mod]; return 0; }
#include <iostream> #include <cstring> using namespace std; using ll = long long; const int N = 200005, P = 1e9 + 7; char s[N]; int n, k; ll f[N][17]; int to_num(char c) { if ('0' <= c && c <= '9') return c ^ '0'; return 10 + c - 'A'; } void init() { f[0][k] = 1; for (int i = 1; i < n; ++i) for (int j = k; ~j; --j) f[i][j] = (j * f[i - 1][j] + (16 - j) * f[i - 1][j + 1]) % P; } ll dp(char s[]) { ll res = 0; int i = 0, cnt = 0; bool st[16]; memset(st, 0, sizeof st); for (int j = 1; j < n; ++j) res = (res + f[j][0] - f[j - 1][1]) % P; while (i < n) { int c = to_num(s[i]), l = n - i - 1; for (int j = 0; j < c; ++j) if (st[j]) res = (res + f[l][cnt]) % P; else if (i || j) res = (res + f[l][cnt + 1] % P); if (!st[c]) ++cnt, st[c] = true; if (++i == n && k == cnt) ++res; } return res; } int main() { scanf("%s%d", s, &k); n = strlen(s); init(); cout << dp(s) << endl; }
//abc185_a.cpp //Thu Dec 17 12:35:08 2020 #include <bits/stdc++.h> #define INTINF 2147483647 #define LLINF 9223372036854775807 #define MOD 1000000007 #define rep(i,n) for (int i=0;i<(n);++i) using namespace std; using ll=long long; typedef pair<int,int> P; int main(){ int a[4]; rep(i,4) cin >> a[i]; int ans = a[0]; rep(i,4)ans = min(ans,a[i]); cout << ans << endl; // printf("%.4f\n",ans); }
#include<iostream> #include<math.h> #include<algorithm> #include<stdint.h> #include<vector> #include<deque> #include<stack> #include<functional> #include<string> #include<cstring> #include<array> #include<fstream> #include<iomanip> #include<list> #include<set> #include<map> #include<unordered_map> #include<unordered_set> #include<bitset> #include<queue> //#include<boost/multiprecision/cpp_int.hpp> using namespace std; //using namespace boost::multiprecision; using ll = long long; using ull = unsigned long long; using uint = unsigned int; template<typename A, typename B> using P = pair<A, B>; #define REP(i,a,b) for(ll i = a; i < b; ++i) #define PRI(s) std::cout << s << endl #define PRIF(v, n) printf("%."#n"f\n", (double)v) template<typename A, typename B>void mins(A& a, const B& b) { a = min(a, (A)b); }; template<typename A, typename B>void maxs(A & a, const B & b) { a = max(a, (A)b); }; int main() { ll a, b, c, d; cin >> a >> b >> c >> d; PRI(min(min(min(a, b), c), d)); return 0; }
# include <bits/stdc++.h> #include <cmath> using namespace std; typedef long long ll; typedef long double ld; typedef pair <int, int> pii; typedef pair <pii, int> ppi; typedef pair <int, pii> pip; typedef pair <pii, pii> ppp; typedef pair <ll, ll> pll; # define A first # define B second # define endl '\n' # define sep ' ' # define all(x) x.begin(), x.end() # define kill(x) return cout << x << endl, 0 # define SZ(x) int(x.size()) # define lc id << 1 # define rc id << 1 | 1 ll power(ll a, ll b, ll md) { return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md)); } const int xn = 1e5 + 10; const int xm = - 20 + 10; const int sq = 320; const int inf = 1e9 + 10; const ll INF = 1e18 + 10; const int mod = 1e9 + 7;//998244353; const int base = 257; int n, a[xn], b[xn]; int main(){ ios::sync_with_stdio(0);cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif cin >> n; int d = 0; int ans = inf; for(int i = 0; i < n; i++){ cin >> a[i]; } for(int i = 0; i < n; i++){ cin >> b[i]; } sort(a, a + n); sort(b, b + n); if(b[0] >= a[n - 1]){ ans = b[0] - a[n - 1] + 1; }else{ ans = 0; } cout << ans; }
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~= *$* WRITER:kakitamasziru/OxOmisosiru *$* ~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/ #ifdef LOCAL_JUDGE #define _GLIBCXX_DEBUG #endif #include <fstream> #include <stdio.h> #include <iostream> // cout, endl, cin #include <string> // string, to_string, stoi #include <vector> // vector #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <utility> // pair, make_pair #include <tuple> // tuple, make_tuple #include <cstdint> // int64_t, int*_t #include <iomanip> //setprecision #include <map> // map #include <unordered_map> //unordered_map #include <queue> // queue, priority_queue #include <set> // set,multiset #include <stack> // stack #include <deque> // deque #include <math.h>//pow,,, #include <cmath>//abs,,, #include <bitset> // bitset #include <numeric> //accumulate,,, #include <sstream> #include <random> #include <initializer_list> #define endl "\n"; using namespace std; const long long INF = 4000000000000000001; const int inf = 1001001001; const long long MOD = 3; //const long long MAXIMUM = INFINITY; //Solve N^M. This, mod_pow use Iterative Square Method. long long mod_pow(long long N, long long M, long long mod) { if (M == 0) return 1; long long res = mod_pow((N * N) % mod, M / 2,mod); //When end-of-a bit is 1, times simple N. if (M & 1) res = (res * N) % mod; return res %= mod; } long long gcd(long long a, long long b) { if (b == 0) return a; else return gcd(b, a % b); } long long lcm(long long a, long long b) { return a / gcd(a, b) * b ; } long long get_mod(long long res){ if(res < 0) res += MOD; return res % MOD; } int main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); /*FILE* in = freopen("answer.txt", "w", stdout); ifstream ifs("in.txt"); // 巨大ケースは in.txt に書いてifsで標準入力*/ int N;cin >> N; vector<int> A(N),B(N); for(int i = 0;i<N;i++) cin >> A.at(i); for(int i = 0;i<N;i++) cin >> B.at(i); sort(A.begin(),A.end()); reverse(A.begin(),A.end()); int ans = 0; for(int i = A.front();i<=1001;i++){ for(int j = 0;j<N;j++){ if(B.at(j) < i){ goto NG; } } ans++; NG:; } cout << ans << endl; }
#include <cstdio> #include <string> #include <vector> #include <algorithm> #include <memory.h> #include <cmath> #include <map> #include <set> #include <queue> #include <stack> #include <ctime> #include <iostream> #include <functional> #include <complex> #include <stdlib.h> #include <fstream> #include <random> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<double, double> pdd; typedef pair<pii, int> p3i; typedef vector<int> vi; typedef vector<pii> vii; typedef vector<p3i> v3i; typedef vector<vii> vvii; typedef vector<p3i> vp3i; typedef long double ld; typedef vector<ld> vld; #define pb push_back #define mp make_pair #define REP(i, n) for (int (i) = 0; (i) < (n); (i)++) #define REPD(i, n) for (int (i) = (n) - 1; (i) >= 0; (i)--) #define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++) #define FORD(i,a, b) for (int (i) = (a); (i) >= (b); (i)--) #define sz(v) (int)(v).size() #define all(v) (v).begin(), (v).end() #define rv(v) reverse(all(v)) #define CL(v, val) memset((v), (val), sizeof((v))) #define SORT(a) sort(all(a)) #define un(v) SORT(v), (v).resize(unique(all(v)) - (v).begin()) #define eps 1.0e-9 #define X first #define Y second #define bit(n) (1 << (n)) #define bit64(n) (ll(1) << (n)) #define sqr(x) ((x) * (x)) #define sq5(x) ((x) * (x) * (x) * (x) * (x)) #define N 400005 ll t[N * 4]; void push(int v) { if (t[v]) { t[v * 2] += t[v]; t[v * 2 + 1] += t[v]; t[v] = 0; } } void upd(int v, int tl, int tr, int l, int r, ll val) { if (l > r) { return; } if (tl == l && tr == r) { t[v] += val; return; } push(v); int tm = (tl + tr) / 2; upd(v * 2, tl, tm, l, min(tm, r), val); upd(v * 2 + 1, tm + 1, tr, max(tm + 1, l), r, val); } ll get(int v, int tl, int tr, int pos) { if (tl == tr) { return t[v]; } push(v); int tm = (tl + tr) / 2; if (pos <= tm) { return get(v * 2, tl, tm, pos); } else { return get(v * 2 + 1, tm + 1, tr, pos); } } vector<vi>g; int tIn[N], tOut[N]; int tt = 0; void dfs(int v, int p = -1) { tIn[v] = tt++; REP(i, sz(g[v])) { int u = g[v][i]; if (u != p) { dfs(u, v); } } tOut[v] = tt++; } bool inner(int a, int b) { return tIn[b] <= tIn[a] && tOut[a] <= tOut[b]; } int main(void) { int n; scanf("%d", &n); g.resize(n); CL(tIn, -1); CL(tOut, -1); vii edges; REP(i, n - 1) { int x, y; scanf("%d%d", &x, &y); x--, y--; g[x].pb(y); g[y].pb(x); edges.pb(mp(x, y)); } dfs(0); int q; scanf("%d", &q); REP(i, q) { int type, e; ll x; scanf("%d%d%lld", &type, &e, &x); e--; if (type == 1) { if (inner(edges[e].X, edges[e].Y)) { upd(1, 0, n * 2 - 1, tIn[edges[e].X], tOut[edges[e].X], x); } else { upd(1, 0, n * 2 - 1, 0, n * 2 - 1, x); upd(1, 0, n * 2 - 1, tIn[edges[e].Y], tOut[edges[e].Y], -x); } } else { if (inner(edges[e].Y, edges[e].X)) { upd(1, 0, n * 2 - 1, tIn[edges[e].Y], tOut[edges[e].Y], x); } else { upd(1, 0, n * 2 - 1, 0, n * 2 - 1, x); upd(1, 0, n * 2 - 1, tIn[edges[e].X], tOut[edges[e].X], -x); } } } REP(i, n) { printf("%lld\n", get(1, 0, n * 2 - 1, tIn[i])); } }
#include<bits/stdc++.h> #define ll long long #define ld long double #define pb push_back #define mp make_pair #define fi first #define se second #define REP(i,j) for(int i=0;i<j;i++) #define REPA(i,j) for(int i=1;i<=j;i++) #define FORN(i,j,k) for(int i=j;i<k;i++) #define vi vector<int> #define vvi vector<vi > #define pii pair<int,int> #define vpii vector<pii > #define all(a) a.begin(),a.end() using namespace std; const int INF=1<<30; //const ll INF=1ll<<60; const ll MOD=1e9+7; inline void read(int &x){ // short neg=1; x=0; char c=getchar(); /*while(c<'0'||c>'9'){ if(c=='-')neg=-1; c=getchar(); }*/ while(c>='0'&&c<='9'){ x=(x<<3)+(x<<1)+(c^48),c=getchar(); } // x*=neg; } ll quick_mod(ll A,ll B){//A^B ll ret=1; A%=MOD; while(B) { if(B&1)ret=ret*A%MOD; B>>=1; A=A*A%MOD; } return ret; } int n; string s; int q; int t,a,b; bool flag=0; int main(void){ cin>>n>>s; cin>>q; REP(ii,q){ cin>>t>>a>>b; a--; b--; if(t==1){ if(flag){ if(a>=n)a-=n; else a+=n; if(b>=n)b-=n; else b+=n; } swap(s[a],s[b]); } else{ flag=!flag; } } if(flag)cout<<s.substr(n,n)<<s.substr(0,n); else cout<<s; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int a,b,c; cin>>a>>b>>c; cout<<max((a+b),max((b+c),(c+a))); return 0; }
#include <iostream> #include<bits/stdc++.h> using namespace std; #define ll long long int int main() { double sx,sy,gx,gy,i,j; double ans = 0.0; std::cin >> sx>>sy>>gx>>gy; ans = ((gx-sx)*sy)/(gy+sy); ans += sx; cout << fixed << setprecision(12) << ans <<endl; return 0; }
#include <iostream> #include <string> #include <algorithm> #include <iostream> #include <string> #include <algorithm> #include <vector> #include <iomanip> #include <cmath> #include <stdio.h> #include <queue> #include <deque> #include <cstdio> #include <set> #include <map> #include <bitset> #include <stack> #include <cctype> using namespace std; int a[5][3030]; int a1[5][5] = {}; int i1[5]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[0][i] >> a[1][i] >> a[2][i] >> a[3][i] >> a[4][i]; for (int j = 0; j < 5; j++) { if (a1[j][j] < a[j][i]) { for (int k = 0; k < 5; k++) { a1[k][j] = a[k][i]; } i1[j] = i; } } } int ans = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { for (int k = 0; k < 5; k++) { if (i1[k] == i || i1[k] == j)continue; int na = max({ a[0][i],a[0][j],a1[0][k] }); for (int l = 1; l < 5; l++) { int nb= max({ a[l][i],a[l][j],a1[l][k] }); na = min(na, nb); } ans = max(ans, na); } } } cout << ans << endl; }
#include <bits/stdc++.h> #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; typedef long long ll; #define REP(i,n) for(ll i=0; i<ll(n); i++) #define FOR(i,m,n) for(ll i=ll(m); i<ll(n); i++) #define ALL(obj) (obj).begin(),(obj).end() #define VI vector<int> #define VP vector<pair<ll,ll>> #define VPP vector<pair<int,pair<int,int>>> #define VLL vector<long long> #define VVI vector<vector<int>> #define VVLL vector<vector<long long>> #define VC vector<char> #define VS vector<string> #define VVC vector<vector<char>> #define VB vector<bool> #define VVB vector<vector<bool>> #define fore(i,a) for(auto &i:a) typedef pair <int, int> P; template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>; template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } const int INF = (1 << 30) - 1; const ll INFL = 1LL << 60; //const ll mod = 1e9 + 7; const ll mod = 998244353; int main() { int n; cin >> n; int ok = INF; int ng = 0; VVI a(n,VI(5)); REP(i, n)REP(j, 5)cin >> a[i][j]; while (ok - ng > 1) { bool ok3 = false; int mid = (ok + ng) / 2; VVB k(n, VB(5, false)); bool check[5]; REP(i, 5)check[i] = false; REP(i, n) { REP(j, 5) { if (a[i][j] >= mid) { k[i][j] = true; check[j] = true; } } } REP(i, n) { if (ok3)break; REP(j, i) { bool ok2[5]; int cnt = 0; REP(l, 5)ok2[l] = false; REP(l, 5) { if (k[i][l] || k[j][l]) { ok2[l] = true; cnt++; } } if (cnt == 5) { ok3 = true; break; } else if (cnt == 4) { REP(l, 5) { if (!ok2[l] && check[l]) { ok3 = true; break; } } } } } if (ok3) { ng = mid; } else { ok = mid; } } cout << ng << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> PP; #define MOD 1000000007 //#define MOD 998244353 #define INF 2305843009213693951 //#define INF 810114514 #define PI 3.141592653589 #define setdouble setprecision #define REP(i,n) for(ll i=0;i<(n);++i) #define OREP(i,n) for(ll i=1;i<=(n);++i) #define RREP(i,n) for(ll i=(n)-1;i>=0;--i) #define all1(i) begin(i),end(i) #define GOODBYE do { cout << "-1" << endl; return 0; } while (false) #define MM <<" "<< #define Endl endl #define debug true #define debug2 false std::vector<long long> divisor_enum(long long N){ /* Copyright (c) 2021 0214sh7 https://github.com/0214sh7/library/ */ std::vector<long long> R; if(N<=0)return R; long long s=0; for(long long i=1;i*i<=N;i++){ if(N%i==0){ R.push_back(i); if(i*i!=N)s++; } } for(long long i = s-1;i>=0;i--){ R.push_back(N/R[i]); } return R; } int main(void){ ll A,B; cin >> A >> B; vector<ll> C(214514,0); for(int i=A;i<=B;i++){ vector<ll> Y = divisor_enum(i); REP(j,Y.size()){ C[Y[j]]++; } } ll Ans = 1; REP(i,C.size()){ if(C[i]>=2){ Ans=max(Ans,i); } } cout << Ans << endl; return 0; }
//c #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; long long gcd(long long a, long long b) { if (a < b) { long long t = a; a = b; b = t; } if (b == 0) { return a; } long long r = a % b; while (r != 0) { a = b; b = r; r = a % b; } return b; } int main() { int a, b; cin >> a >> b; /*long long mx = 0; for (int i = a; i <= b; i++) { for (int j = i + 1; j <= b; j++) { mx = max(mx, gcd(i, j)); } } cout << mx << endl;*/ vector<vector<int>> t(b + 1); for (int i = 1; i <= b; i++) { for (int j = i; j <= b; j += i) { t[j].emplace_back(i); } } vector<int> ans; for (int i = a; i <= b; i++) { for (int j = 0; j < t[i].size(); j++) { ans.emplace_back(t[i][j]); } } sort(ans.rbegin(), ans.rend()); for (int i = 0; i < ans.size() - 1; i++) { if (ans[i] == ans[i + 1]) { cout << ans[i] << endl; return 0; } } return 0; }
#include <bits/stdc++.h> #define DeltaCube23 ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define pb push_back #define mp make_pair #define minimum(a) *min_element(a.begin(), a.end()) #define maximum(a) *max_element(a.begin(), a.end()) #define MOD 998244353 #define forf(i,a,b) for(int i = (a); i < (b); i++) #define forr(i,a,b) for(int i = (a); i >= (b); i--) typedef long long int lli; lli binpow(lli a,lli b,lli m){lli res=1;for(b%=m-1,a%=m;b>0;b>>=1,a=a*a%m)if(b&1)res=res*a%m;return res;} lli gcd(lli a, lli b) {return b? gcd(b, a%b) : a;} //#define int lli //CAREFUL using namespace std; const int mx=1e6+5; int main() { DeltaCube23 int t=1; //cin>>t; while(t--) { string s; cin>>s; deque<char> dq; int n = s.length(); int turn = 0; forf(i,0,n) { if(s[i] == 'R') turn = 1-turn; else if(turn == 0) dq.push_back(s[i]); else dq.push_front(s[i]); } string ns; while(!dq.empty()) { char temp = dq.front(); dq.pop_front(); ns += temp; } if(turn == 1) reverse(ns.begin(), ns.end()); n = ns.length(); vector<char> ans; ans.pb('R'); int len = 1; char prev = ans[len - 1]; forf(i,0,n) { if(ns[i] == prev) { ans.pop_back(); len--; prev = ans[len - 1]; } else { ans.pb(ns[i]); prev = ns[i]; len++; } } n = (int)ans.size(); forf(i,1,n) { cout<<ans[i]; } } return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define all(x) x.begin(), x.end() const int mod = 1000000007; const int N = 2e5 + 7; int vis[N] = {0}; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t = 1; while (t--) { int n; cin >> n; int a[n]; vector<int> ans; int ma = 0; int pos = 0; for (int i = 0; i < n; ++i) { cin >> a[i]; } // for (int i = 0; i < n; ++i) // { // if (a[i] != 0) // { // vis[a[i]] = 1; // ans.push_back(0); // } // else // { // pos = i; // break; // } // } int g = 0; for (int i = 0; i < n; ++i) { vis[a[i]] = 1; for (int j = g; j < i + 2; ++j) { if (!vis[j]) { ans.push_back(j); g = j; break; } } } for (int i : ans) cout << i << "\n"; } } /* 10 10 3 3 3 6 8 1 6 10 10 10 4 1 1 2 3 10 5 */
#include<bits/stdc++.h> #include<ext/pb_ds/tree_policy.hpp> #include<ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; ///--->>> CONTAINERS <<<---/// using i64 = int64_t; using ll = long long; using ld = long double; using vi = vector<ll>; using vvi = vector<vector< ll > >; using vpi = vector<pair<ll,ll> >; using pi = pair<ll,ll>; using st = set<ll>; using stk = stack<ll>; using kiwi = queue<ll>; using pkiwi = priority_queue<ll>; using mp = map<ll,ll>; using ump = unordered_map<ll,ll>; ///--->>> TEMPLATES <<<---/// template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update >; ///--->>> MACROS<<<---/// const ll mx = 3e5+123; #define MOD 998244353 #define mod 1000000007 #define isb(z) __builtin_popcount(z) #define lisb(z) __builtin_popcountll(z) #define iclz(z) __builtin_clz(z) #define lclz(z) __builtin_clzll(z) #define ictz(z) __builtin_ctz(z) #define lctz(z) __builtin_ctzll(z) #define REP(i,n) for (ll i=1;i<=n;++i) #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ///--->>>OPTIMIZE<<<---/// #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") ///--->>> DEBUGGER<<<---/// #define dbg(args...) do {cerr<<#args<<" : "; diraf(args); } while(0) void diraf () { cerr << endl;} template < typename T, typename ... hello>void diraf( T arg, const hello &... rest) {cerr<<arg<< ' ';diraf(rest...);} ///--->>> RANDOMIZER<<<---/// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); /* usage - just do rng() */ int main(int argc, char* argv[]){ fastio; cin.exceptions(cin.failbit); ///freopen("input.txt","r",stdin); ///freopen("output.txt","w",stdout); ///cout<<fixed<<setprecision(20); ll n; cin>>n; vi a(n); ll sum = 0, maxPref = 0, update = 0, prefSum = 0;///, maxPref = 0; for(ll i=0;i<n;++i){ cin>>a[i]; sum +=a[i]; update = max(update, sum); maxPref = max(maxPref, prefSum + update); prefSum +=sum; /// dbg(sum, maxPref, prefSum, update); } cout<<maxPref<<endl; return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> #include <iomanip> using namespace std; template <typename T> ostream& operator<<(ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i < (int)vec.size(); ++i) { os << vec[i] << (i + 1 == (int)vec.size() ? "" : ", "); } os << "}"; return os; } template <typename T, typename U> ostream& operator<<(ostream& os, pair<T, U>& pair_var) { os << "(" << pair_var.first << ", " << pair_var.second << ")"; return os; } template <typename T, typename U> ostream& operator<<(ostream& os, map<T, U>& map_var) { os << "{"; for (auto itr = map_var.begin(); itr != map_var.end(); itr++) { os << "(" << itr->first << ", " << itr->second << ")"; itr++; if (itr != map_var.end()) os << ", "; itr--; } os << "}"; return os; } template <typename T> ostream& operator<<(ostream& os, set<T>& set_var) { os << "{"; for (auto itr = set_var.begin(); itr != set_var.end(); itr++) { os << *itr; ++itr; if (itr != set_var.end()) os << ", "; itr--; } os << "}"; return os; } void dump_func() { cerr << "\n"; } template <class Head, class... Tail> void dump_func(Head&& head, Tail&&... tail) { cerr << head; if (sizeof...(Tail) == 0) { cerr << " "; } else { cerr << ", "; } dump_func(std::move(tail)...); } #define dump(...) cerr << "[" << to_string(__LINE__) << "]" \ << " " << string(#__VA_ARGS__) << " = ", \ dump_func(__VA_ARGS__) using ll = long long; using ld = long double; using VI = vector<int>; using VL = vector<double>; using VVI = vector<VI>; using VVL = vector<VL>; using PI = pair<int, int>; using PL = pair<ll, ll>; using VPI = vector<PI>; using VPL = vector<PL>; using VS = vector<string>; #define ln '\n' #define REP(t, n) for (int t = 0; t < (n); ++t) #define FOR(t, a, b) for (int t = (a); t <= (b); ++t) #define FORR(t, a, b) for (int t = (a); t >= (b); --t) #define ALL(c) (c).begin(), (c).end() #define CAUTO const auto& int main() { cin.tie(0); ios::sync_with_stdio(false); ll n; cin>>n; vector<ll> a(n+1),wa(n+1),maxFromzero(n+1); FOR(i,1,n){ cin>>a[i]; } FOR(i,1,n){ wa[i] = wa[i-1] + a[i]; } FOR(i,1,n){ maxFromzero[i] = max(maxFromzero[i-1],wa[i]); } ll ans=0,x=0; FOR(i,1,n){ x+=wa[i-1]; ans=max(ans,x+maxFromzero[i]); } // cout<<wa<<ln<<maxFromzero<<ln; cout<<ans<<ln; return 0; }
#include<deque> #include<queue> #include<vector> #include<algorithm> #include<iostream> #include<set> #include<cmath> #include<tuple> #include<string> #include<chrono> #include<functional> #include<iterator> #include<random> #include<unordered_set> #include<array> #include<map> #include<iomanip> #include<assert.h> #include<list> #include<bitset> #include<stack> #include<memory> #include<numeric> #include <utility> using namespace std; typedef long long int llint; typedef long double lldo; #define mp make_pair #define mt make_tuple #define pub push_back #define puf push_front #define pob pop_back #define pof pop_front #define fir first #define sec second #define res resize #define ins insert #define era erase #define REP(i, n) for(int i = 0;i < (n);i++) /*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/ const llint mod=1000000007; const llint inf=2.19e15+1; const long double pai=3.141592653589793238462643383279502884197; const long double eps=1e-10; template <class T,class U>bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;} template <class T,class U>bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;} llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);} llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;} template<class T> void SO(T& ve){sort(ve.begin(),ve.end());} template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());} template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();} template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();} int main(void){ int i,j,n;cin>>n; llint ans=0; vector<int>sco(n); for(i=0;i<n;i++){llint A;cin>>A;ans+=A;sco[i]=-A;} for(i=0;i<n;i++){llint B;cin>>B;sco[i]+=B;} vector<llint>gu(n/2); vector<llint>ki(n/2); for(i=0;i<n/2;i++){ gu[i]=sco[i+i]; ki[i]=sco[i+i+1]; } SO(gu);SO(ki); for(i=n/2-1;i>=0;i--){ if(gu[i]+ki[i]>0){ans+=gu[i]+ki[i];} else{break;} } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> #define debug(...) fprintf(stderr, __VA_ARGS__) #define RI register int typedef long long LL; #define int LL #define FILEIO(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout); using namespace std; namespace IO { char buf[1000000], *p1 = buf, *p2 = buf; inline char gc() { if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin); return p1 == p2 ? EOF : *(p1++); } template <class T> inline void read(T &n) { n = 0; RI ch = gc(), f; while ((ch < '0' || ch > '9') && ch != '-') ch = gc(); f = (ch == '-' ? ch = gc(), -1 : 1); while (ch >= '0' && ch <= '9') n = n * 10 + (ch ^ 48), ch = gc(); n *= f; } char Of[105], *O1 = Of, *O2 = Of; template <class T> inline void print(T n, char ch = '\n') { if (n < 0) putchar('-'), n = -n; if (n == 0) putchar('0'); while (n) *(O1++) = (n % 10) ^ 48, n /= 10; while (O1 != O2) putchar(*(--O1)); putchar(ch); } } using IO :: read; using IO :: print; int const MAXN = 1e5 + 5; int a[MAXN], b[MAXN]; priority_queue <int> q1, q2; signed main() { #ifdef LOCAL FILEIO("a"); #endif int n; read(n); for (RI i = 1; i <= n; ++i) read(a[i]); for (RI i = 1; i <= n; ++i) read(b[i]); LL ans = 0; for (RI i = 1; i <= n; ++i) { ans += a[i]; if (i & 1) q1.push(b[i] - a[i]); else q2.push(b[i] - a[i]); } while (!q1.empty() && !q2.empty() && q1.top() + q2.top() > 0) { ans += q1.top() + q2.top(); q1.pop(), q2.pop(); } print(ans); return 0; } // created by Daniel yuan /* ________ / \ / / \ \ / / \ \ \ / \ ______ / \________/ */
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 1e5 + 5; ll rd(){ ll x = 0; int f =1; char ch = getchar(); while(ch < '0' || ch > '9') { if(ch == '-') f = -1; ch = getchar(); } while(ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } int main(){ ll s = rd(); ll p = rd(); for(int i = 1;(ll)i * i <= p;i++){ if(p % i) continue; ll j = p / i; if(i + j == s) { puts("Yes"); return 0; } } puts("No"); }
#pragma GCC optimize ("Ofast") #include<bits/stdc++.h> using namespace std; inline int my_getchar_unlocked(){ static char buf[1048576]; static int s = 1048576; static int e = 1048576; if(s == e && e == 1048576){ e = fread_unlocked(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_unlocked(); if(k=='-'){ m=1; break; } if('0'<=k&&k<='9'){ x=k-'0'; break; } } for(;;){ k = my_getchar_unlocked(); 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_unlocked(buf, 1, s, stdout); } } } ; MY_WRITER MY_WRITER_VAR; void my_putchar_unlocked(int a){ if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){ fwrite_unlocked(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_unlocked(a); } inline void wt_L(const char c[]){ int i=0; for(i=0;c[i]!='\0';i++){ my_putchar_unlocked(c[i]); } } int main(){ int A; rd(A); int B; rd(B); int C; rd(C); if(A>B||(A==B&&C==1)){ wt_L("Takahashi"); wt_L('\n'); } else{ wt_L("Aoki"); wt_L('\n'); } return 0; } // cLay version 20210103-1 [bug fixed 1] // --- original code --- // { // int @A, @B, @C; // wt(if[A>B||(A==B&&C==1), "Takahashi", "Aoki"]); // }
#include <bits/stdc++.h> using namespace std; #define repr(i, a, b) for (int i = a; i < b; i++) #define rep(i, n) for (int i = 0; i < n; i++) typedef long long ll; typedef pair<ll,ll> P; #define mod 1000000007 ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;} ll lcm(ll x,ll y) {return x/gcd(x,y)*y;} int main(){ ll n; cin >> n; string s; cin >> s; vector<ll> a(n+1); rep(i,n+1) cin >> a[i]; ll num=10005; rep(i,n){ num=min(num,abs(a[i]-a[i+1])); } cout << num << endl; for(ll i=0;i<num;i++){ for(ll j=0;j<n+1;j++){ if(j) cout << " "; ll ans=a[j]/num; ll amari=a[j]%num; if(amari==0){ cout << ans; continue; } if(i+amari>=num){ cout << ans+1; }else{ cout << ans; } } cout << endl; } return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; #define mp(a,b) make_pair(a,b) #define ff first #define setp(a) setprecision(a)<<fixed #define ss second #define fori(v) for(ll i=0; i<v; i++) #define forj(v) for(ll j=0; j<v; j++) #define fork(v) for(ll k=0; k<v; k++) #define forl(v) for(ll l=0; l<v; l++) #define fort(v) for(ll t=0; t<v; t++) #define forz(v) for(ll z=0; z<v; z++) #define forx(v) for(ll x=0; x<v; x++) #define fory(v) for(ll y=0; y<v; y++) #define ll long long #define double long double #define MAX (int) (3*pow(10,5) + 10) #define pb(a) push_back(a) using namespace __gnu_pbds; const ll INF = 0x3f3f3f3f; const ll inf = pow(10,18); ll modulo = pow(10,9)+7; void deal(){ ll n; cin>>n; { string s; cin>>s; } n++; vector<ll> arr(n,0); fori(n){ cin>>arr[i]; } ll mn = inf; for(ll i = 1; i<n; i++){ ll dif = arr[i] - arr[i-1]; if(dif < 0){ dif = -dif; } mn = min(mn, dif); } vector<vector<ll> > val(mn, vector<ll>(n)); fori(mn){ forj(n){ ll vl = arr[j] / mn; ll extra = arr[j] % mn; val[i][j] = vl; if(i<extra){ ++val[i][j]; } } } cout<<mn<<'\n'; fori(mn){ forj(n){ cout<<val[i][j]<<' '; } cout<<'\n'; } } int main(){ cin.tie(0); ios_base::sync_with_stdio(0); deal(); }
#include <iostream> #include <vector> #include <string> #include <array> #include <functional> #include <algorithm> #include <stack> #include <map> #include <set> #include <climits> #include <queue> #include <bitset> #include <cassert> #include <math.h> #include <complex> #include <iomanip> #include <unordered_map> using namespace std; #define ll long long #define pb(x) push_back(x) template<typename T1> void dbg_pr(vector<T1> V, int add = 0, int start = -1, int end = -1) { cout << "{"; if (start < 0) start = 0; if (end < 0) end = V.size() - 1; for (int i = start; i <= end; i++) { cout << V[i] + add << ((i == end) ? "}" : " "); } } void dbg_pr(string V) {cout << "\"" << V << "\"";} template<typename T1> void dbg_pr(T1 V) {cout << V;} template<typename T1, typename T2> void dbg_pr(map<T1, T2> M) { cout << "{"; for(const auto m : M) { dbg_pr(m.first); cout << ":"; dbg_pr(m.second); cout << ","; } cout << "}"; } #ifdef _OLIMPOLOCAL #define dbg(...) cerr << "\033[1;36m[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define dbg(...) 1337 #endif void debug_out() { cout << "\033[0m\n";} template<typename T1, typename... T2> void debug_out(T1 A, T2... B) { cout << " "; dbg_pr(A); debug_out(B...); } int test = 1; #define out(x) {cout << x << "\n";return;} #define all(N) N.begin(),N.end() #define allr(N) N.rbegin(),N.rend() void setupFastCin() {ios::sync_with_stdio(false);cin.tie(0);} template<typename T1> T1 chmin(T1 &x, const T1 v) { return x = min(x,v); } template<typename T1> T1 chmax(T1 &x, const T1 v) { return x = max(x,v); } template<typename T1> void pr(vector<T1> V, int add = 0, int start = -1, int end = -1) { if (start < 0) start = 0; if (end < 0) end = V.size() - 1; for (int i = start; i <= end; i++) { cout << V[i] + add << ((i == end) ? "\n" : " "); } } #define rep(i, n) for (int i = 0; i < n; i++) #define reps(i, s, n) for (int i = s; i < n; i++) #define repr(i, n) for (int i = n-1; i >= 0; i--) #define repsr(i, s, n) for (int i = n-1; i >= s; i--) #define PI pair<int,int> #define PLL pair<ll, ll> template<typename T1> T1 gcd(const T1 &a, const T1 &b) { if (a == 0 || b == 0) return a + b; return gcd(b, a %b); } //-------------------------- ^ DONT TOUCH ^----------------------------------------------------------------- #define MAX 1000000 #define MAXP 21 //#define MOD 998244353ll #define MOD 1000000007ll long long power(long long x, long long n) { long long p = x; long long s = 1; while (n > 0) { if (n & 1) s = (s * p) % MOD; p = (p * p) % MOD; n /= 2; } return s; } int n; ll x; ll C[2][100005]; ll D[2][100005]; void solve() { cin >> n; C[0][0] = 1; cin >> D[0][0]; D[1][0] = C[1][0] = 0; reps(i, 1, n) { cin >> x; C[0][i] = C[0][i-1] + C[1][i-1]; C[1][i] = C[0][i-1]; C[0][i] %= MOD; C[1][i] %= MOD; D[0][i] = D[0][i-1] + D[1][i-1] + (C[0][i] * x) % MOD; D[1][i] = D[0][i-1] - (C[1][i] * x) % MOD; D[0][i] %= MOD; D[1][i] %= MOD; dbg(D[0][i], D[1][i]); } out((D[0][n-1] + D[1][n-1] + MOD + MOD + MOD) % MOD) } int main() { setupFastCin(); int T = 1; #ifdef _OLIMPOLOCAL cin >> T; #endif reps(t, 1, T + 1){ solve(); } return 0; }
#include <vector> #include <array> #include <stack> #include <queue> #include <list> #include <bitset> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <algorithm> #include <numeric> #include <iostream> #include <iomanip> #include <string> #include <chrono> #include <random> #include <cmath> #include <cassert> #include <climits> #include <cstring> #include <cstdlib> #include <functional> #include <sstream> using namespace std; int main(int argc, char** argv) { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(12); int n; cin >> n; vector<int> A(n); for (int i = 0; i < n; ++i) { cin >> A[i]; } vector<long long> dp(2, 0); vector<long long> cnts(2, 0); auto ndp = dp; auto ncnts = cnts; cnts[1] = 1; const long long MOD = 1000000007; for (auto x : A) { fill(ndp.begin(), ndp.end(), 0); fill(ncnts.begin(), ncnts.end(), 0); { ncnts[0] = (cnts[0] + cnts[1]) % MOD; ndp[0] = (dp[0] + cnts[0] * 1LL * x % MOD) % MOD; (ndp[0] += (dp[1] + cnts[1] * 1LL * x % MOD) % MOD) %= MOD; } { ncnts[1] = cnts[0]; ndp[1] = (dp[0] - cnts[0] * 1LL * x % MOD + MOD) % MOD; } swap(ndp, dp); swap(ncnts, cnts); } long long res = 0; res += dp[0]; res += dp[1]; res %= MOD; cout << res << '\n'; return 0; }
// 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); } template <typename T> struct SegmentTree { using F = function<T(T, T)>; const T e; const F f; size_t sz; vector<T> tree; SegmentTree(size_t n, const F &f, const T &e = 0) : f(f), e(e) { sz = 1; while(sz < n) sz <<= 1; tree.assign(2*sz, e); } void set(typename vector<T>::iterator begin, typename vector<T>::iterator end) { copy(begin, end, tree.begin() + sz); for(size_t k=sz-1; k>0; k--) tree[k] = f(tree[2*k+0], tree[2*k+1]); } void update(size_t k, const T &x) { k += sz; tree[k] = x; while(k >>= 1) tree[k] = f(tree[2*k+0], tree[2*k+1]); } T query(size_t a, size_t b) const { b = min(b, sz); a = max((size_t)0, a); T l = e, r = e; for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) { if(a & 1) l = f(l, tree[a++]); if(b & 1) r = f(tree[--b], r); } return f(l, r); } T operator[](const size_t k) const { return tree[sz + k]; } }; int main(void) { constexpr ll MOD = 0 ? 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; vector<ll> a(n), b(n), c(n); for(auto &e: a) cin >> e; for(auto &e: b) cin >> e; map<ll,vector<ll>> m; for(ll i=0; i<n; i++) m[a[i]+i].push_back(i); map<ll,ll> idx; for(ll i=0; i<n; i++) { ll x = b[i]+i; auto &v = m[x]; ll y = idx[x]++; if(y == v.size()) { cout << -1 << endl; return 0; } c[i] = v[y]; } ll r = 0; SegmentTree<ll> st(n, [&](ll a, ll b){return a + b;}, 0); for(ll i=0; i<n; i++) { r += i - st.query(0, c[i]); st.update(c[i], st[c[i]]+1); } cout << r << endl; } return 0; }
#include <bits/stdc++.h> #define rep(i,a,b) for(int i=(a);i<=(b);++i) #define ll long long using namespace std; inline int read(){ int 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; } const int N=2e5+5; struct node{int v,id;}a[N],b[N]; bool cmp(node x,node y){return x.v==y.v?x.id<y.id:x.v<y.v;} int n,A[N],t[N]; void I(int pos){for(int i=pos;i<=n;i+=i&-i)++t[i];} int Q(int pos){int res=0;for(int i=pos;i;i-=i&-i)res+=t[i];return res;} ll ans; int main(){ n=read(); rep(i,1,n)a[i]={read()+i,i}; rep(i,1,n)b[i]={read()+i,i}; sort(a+1,a+n+1,cmp);sort(b+1,b+n+1,cmp); rep(i,1,n){ if(a[i].v!=b[i].v)return puts("-1"),0; A[a[i].id]=b[i].id; } for(int i=n;i;i--){ I(A[i]);ans+=Q(A[i]-1); } printf("%lld\n",ans); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; int ret = 4; if (a+b >= 15 && b >= 8) ret = 1; else if (a+b >= 10 && b >= 3) ret = 2; else if (a+b >= 3) ret = 3; cout << ret << '\n'; return 0; }
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> #include <queue> #include <vector> #include <cstring> #include <functional> #include <map> #define LL long long #define lson(rt) (rt << 1) #define rson(rt) (rt << 1 | 1) using namespace std; const int N = 1e6 + 10; map<LL, LL> memo; LL x, y; LL fun (LL y) { if(x >= y) return abs(x - y); if(memo.find(y) != memo.end()) return memo[y]; if(y & 1) { return memo[y] = min(abs(x - y), min(fun(y + 1) + 1, fun(y - 1) + 1)); } else { return memo[y] = min(abs(x - y), fun(y / 2) + 1LL); } } void solve() { cin >> x >> y; cout << fun(y) << endl; } int main () { // ios::sync_with_stdio(false); // cin.tie(0); cout.tie(0); solve(); return 0; }
//In the name of Allah :) #include <bits/stdc++.h> using namespace std; string to_string(char c) { return string(1,c); } string to_string(bool b) { return b ? "true" : "false"; } string to_string(const char* s) { return (string)s; } string to_string(string s) { return s; } template<class A> string to_string(complex<A> c) { stringstream ss; ss << c; return ss.str(); } string to_string(vector<bool> v) { string res = "{"; for(int i = 0; i < (int)v.size(); i++) res += char('0'+v[i]); res += "}"; return res; } template<size_t SZ> string to_string(bitset<SZ> b) { string res = ""; for(size_t i = 0; i < SZ; i++) res += char('0'+b[i]); return res; } template<class A, class B> string to_string(pair<A,B> p); template<class T> string to_string(T v) { // containers with begin(), end() bool fst = 1; string res = "{"; for (const auto& x: v) { if (!fst) res += ", "; fst = 0; res += to_string(x); } res += "}"; return res; } template<class A, class B> string to_string(pair<A,B> p) { return "("+to_string(p.first)+", "+to_string(p.second)+")"; } void DBG() { cerr << "]" << endl; } template<class H, class... T> void DBG(H h, T... t) { cerr << to_string(h); if (sizeof...(t)) cerr << ", "; DBG(t...); } #ifdef LOCAL // compile with -DLOCAL #define wis(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "] : [", DBG(__VA_ARGS__) #else #define wis(...) 0 #endif typedef long long ll; #define all(x) (x).begin(), (x).end() const vector<pair<int ,int>> moves = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; const int MAXN = 1510; char grid[MAXN][MAXN]; bitset <MAXN> mark[4][MAXN]; int h, w, n, m; void dfs(int x, int y, int dir){ if(mark[dir][x][y]){ return; } wis(x, y); mark[dir][x][y] = 1; grid[x][y] = 'r'; x = x + moves[dir].first; y = y + moves[dir].second; if(x >= 0 && y >= 0 && x < h && y < w && grid[x][y] != 'm'){ dfs(x, y, dir); } } int main(){ ios::sync_with_stdio(0); cin >> h >> w >> n >> m; vector<pair<int, int>> a(n); for(int i = 0; i < n; i++){ int x, y; cin >> x >> y; x--, y--; a[i] = {x, y}; } for(int i = 0; i < m; i++){ int x, y; cin >> x >> y; x--, y--; grid[x][y] = 'm'; } for(auto [x, y] : a){ dfs(x, y, 0); dfs(x, y, 1); dfs(x, y, 2); dfs(x, y, 3); } int ans = 0; for(int i = 0; i < h; i++){ for(int j = 0; j < w; j++){ ans += grid[i][j] == 'r'; } } cout << ans << '\n'; }
#include<bits/stdc++.h> #define HAS_TEST_CASE 0 namespace rG{ typedef long long ll; const int N=2e3; int a[N+10][N+10]; int n,m; bool can[N+10][N+10]; void main(){ int T1,T2; scanf("%d%d%d%d",&n,&m,&T1,&T2); for(int i=1;i<=T1;i++){ int x,y;scanf("%d%d",&x,&y); a[x][y]=1; } for(int i=1;i<=T2;i++){ int x,y;scanf("%d%d",&x,&y); a[x][y]=2; } for(int i=1;i<=n;i++){ bool now=0; for(int j=1;j<=m;j++){ if(a[i][j]==1)can[i][j]|=1,now=1; if(a[i][j]==2)now=0; if(a[i][j]==0)can[i][j]|=now; } now=0; for(int j=m;j>=1;j--){ if(a[i][j]==1)can[i][j]|=1,now=1; if(a[i][j]==2)now=0; if(a[i][j]==0)can[i][j]|=now; } } for(int j=1;j<=m;j++){ bool now=0; for(int i=1;i<=n;i++){ if(a[i][j]==1)can[i][j]|=1,now=1; if(a[i][j]==2)now=0; if(a[i][j]==0)can[i][j]|=now; } now=0; for(int i=n;i>=1;i--){ if(a[i][j]==1)can[i][j]|=1,now=1; if(a[i][j]==2)now=0; if(a[i][j]==0)can[i][j]|=now; } } int ans=0; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) ans+=can[i][j]; printf("%d\n",ans); } } // namespace rG int main(){ #if defined(LOCAL)&&HAS_TEST_CASE freopen("tmp.out","w",stdout); #endif #if HAS_TEST_CASE int T;scanf("%d",&T); while(T--)rG::main(); #else rG::main(); #endif return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define MOD int(1e9+7) #define INF int(1e9+7) #define LINF ll(1e18+7) #define PI acos(-1) #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define P pair<ll,ll> #define chmax(x,y) (x = max(x,y)) #define chmin(x,y) (x = min(x,y)) ll a[210000]; int main(){ int n; cin>>n; rep(i,n) cin>>a[i]; ll base=0; ll befo=0; ll MAX=0; rep(i,n){ base+=befo+a[i]; befo+=a[i]; chmax(MAX,a[i]); cout<<base+MAX*(i+1)<<endl; } }
#include <bits/stdc++.h> #define ll long long using namespace std; typedef pair<int, int> P; typedef pair<ll, ll> LP; //定数 //円周率 const double pi = 3.141592653589793238462643383279; //天井 const int INF = 1000000000; // = 10^9 const ll LINF = 100000000000000000; // = 10^17 //ABC文字列 const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZABC"; const string abc = "abcdefghijklmnopqrstuvwxyzabc"; //よくあるmodくん const ll MOD = 1000000007; // = 10^9 + 7 //前処理テーブルの大きさ指定 const int MAX = 1200000; // = 10^6 + 2*(10^5) //ちなみに、1024MBで持てる最大長の配列は10^8程度 //データ構造 //隣接リスト用構造体(有向グラフ向け) struct edge { ll to; // E.toでその辺の終点へアクセスできる。 ll cost; // e.costでその辺の重みにアクセスできる。 }; //Union_Find木 struct UnionFind { vector<int> UF; // UF.at(i) : iの親の番号 vector<int> SIZE; // SIZE.at(root(i)) : iと連結されてる要素の数 UnionFind(int N) : UF(N), SIZE(N, 1) { // 最初は全てが根であるとして初期化 for(int i = 0; i < N; i++) { UF.at(i) = i; } } int root(int x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根} if (UF.at(x) == x) { return x; } return UF.at(x) = root(UF.at(x)); } void unite(int x, int y) { // xとyの木を併合 int rx = root(x); // xの根をrx int ry = root(y); // yの根をry if (rx == ry) { return; // xとyの根が同じ(=同じ木にある)時はそのまま } // xとyの根が同じでない(=同じ木にない)時:小さい方の根を大きい方の根につける。 if (SIZE.at(rx) < SIZE.at(ry)) { UF.at(rx) = ry; SIZE.at(ry) += SIZE.at(rx); SIZE.at(rx) = 0; } else { UF.at(ry) = rx; SIZE.at(rx) += SIZE.at(ry); SIZE.at(ry) = 0; } } bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す。 int rx = root(x); int ry = root(y); return rx == ry; } int size(int x) { // xと連結されてる要素の数を返す。 return SIZE.at(root(x)); } }; //関数 (計算量) //ctoi (O(1)) int ctoi(char c){ if (c == '0') return 0; if (c == '1') return 1; if (c == '2') return 2; if (c == '3') return 3; if (c == '4') return 4; if (c == '5') return 5; if (c == '6') return 6; if (c == '7') return 7; if (c == '8') return 8; if (c == '9') return 9; return -1; } //to_char (O(1)) char to_char(int i){ if (i == 0) return '0'; if (i == 1) return '1'; if (i == 2) return '2'; if (i == 3) return '3'; if (i == 4) return '4'; if (i == 5) return '5'; if (i == 6) return '6'; if (i == 7) return '7'; if (i == 8) return '8'; if (i == 9) return '9'; return ' '; } //メイン処理 int main() { cout << fixed << setprecision(16); //精度向上 //ここまでテンプレ int A, B; cin >> A >> B; cout << 2 * A + 100 - B << endl; }
#include<bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; #define rep(i, n) for(int i = 0; i < n; i++) const int mod = 1000000007; int main() { int n; cin >> n; ll x1,x2,x3,x4,y1,y2,y3,y4; x1 = x2 = y1 = y2 = -1e9-1; x3 = x4 = y3 = y4 = 1e9+1; int x11,x22,x33,x44,y11,y22,y33,y44; rep(i,n){ ll x,y; cin >> x >> y; if(x>=x1){ x2 = x1; x22 = x11; x1 = x; x11 = i; } else if(x>=x2){ x2 = x; x22 = i; } if(x<=x4){ x3 = x4; x33 = x44; x4 = x; x44 = i; } else if(x<=x3){ x3 = x; x33 = i; } if(y>=y1){ y2 = y1; y22 = y11; y1 = y; y11 = i; } else if(y>=y2){ y2 = y; y22 = i; } if(y<=y4){ y3 = y4; y33 = y44; y4 = y; y44 = i; } else if(y<=y3){ y3 = y; y33 = i; } } vector<ll> ans; if(x11 == y11 && x33 == y33){ ans.push_back(max(x1-x3,y1-y3)); } else{ ans.push_back(x1-x3); ans.push_back(y1-y3); } if(x11 == y11 && x44 == y44){ ans.push_back(max(x1-x4,y1-y4)); } else{ ans.push_back(x1-x4); ans.push_back(y1-y4); } if(x22 == y22 && x33 == y33){ ans.push_back(max(x2-x3,y2-y3)); } else{ ans.push_back(x2-x3); ans.push_back(y2-y3); } if(x22 == y22 && x44 == y44){ ans.push_back(max(x2-x4,y2-y4)); } else{ ans.push_back(x2-x4); ans.push_back(y2-y4); } sort(ans.rbegin(),ans.rend()); cout << ans[1] << endl; return 0; }
//Don't act like a loser. //This code is written by huayucaiji //You can only use the code for studying or finding mistakes //Or,you'll be punished by Sakyamuni!!! #include<bits/stdc++.h> #define int long long using namespace std; int read() { char ch=getchar(); int f=1,x=0; while(ch<'0'||ch>'9') { if(ch=='-') f=-1; ch=getchar(); } while(ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); } return f*x; } const int MAXN=2e5+10; int n; priority_queue<int> q; struct point { int x,y,id; }p[MAXN]; map<pair<int,int>,bool> mp; int dist(point a,point b) { return max(abs(a.x-b.x),abs(a.y-b.y)); } bool cmpx(point a,point b) { if(a.x!=b.x) return a.x<b.x; return a.y<b.y; } bool cmpy(point a,point b) { if(a.y!=b.y) return a.y<b.y; return a.x<b.x; } pair<int,int> mk(int a,int b) { return make_pair(max(a,b),min(a,b)); } void get(point a,point b) { if(!mp[mk(a.id,b.id)]) { mp[mk(a.id,b.id)]=1; q.push(dist(a,b)); } } signed main() { //freopen(".in","r",stdin); //freopen(".out","w",stdout); cin>>n; for(int i=1;i<=n;i++) { p[i].x=read();p[i].y=read(); p[i].id=i; } sort(p+1,p+n+1,cmpx); get(p[1],p[n]); get(p[1],p[n-1]); get(p[2],p[n]); sort(p+1,p+n+1,cmpy); get(p[1],p[n]); get(p[1],p[n-1]); get(p[2],p[n]); q.pop(); cout<<q.top()<<endl; //fclose(stdin); //fclose(stdout); return 0; }
/** * Author : Tanbin_Hasan * Created : 22.02.2021 **/ #include <bits/stdc++.h> using namespace std ; int main(void) { ios::sync_with_stdio(false) ; cin.tie(0) ; int n ; cin >> n ; long long ans = 0 ; for (int i = 1 ; i < n + 1 ; ++i) { for (int j = 1 ; j < n + 1 ; ++j) { if (i * j > n) { break ; } for (int k = 1 ; k < n + 1 ; ++k) { if (i * j * k > n) { break ; } ++ans ; } } } cout << ans ; return 0 ; }
#include<bits/stdc++.h> using namespace std; const int N=2e5+100; #define ll long long char str[N]; int n, b[N], c[N], sum[N], cnt; ll ans; int main() { scanf("%s",str+1), n=strlen(str+1); for(int i=1;i<=n;++i) { if(i != 1 && str[i] == str[i-1]) ++b[cnt]; else c[++cnt]=str[i]-'a', b[cnt]=1; } for(int i=1;i<=cnt;++i) sum[i]=b[i]+sum[i-1]; for(int i=cnt;i>=1;--i) { if(b[i] == 1) continue; for(int j=i+1, r=0;j<=cnt;++j) { if(c[j] == c[i] && b[j] >= 2) { ans += sum[j-1]-sum[i]-r; break; } if(b[j] >= 2 && c[j] != c[i]) { ans += n-r-sum[i]; break; } if(b[j] == 1 && c[j] == c[i]) ++r; if(j == cnt) ans += n-sum[i]-r; } } cout<<ans<<endl; return 0; }
#pragma GCC optimize ("Ofast") #include<bits/stdc++.h> using namespace std; void*wmem; char memarr[96000000]; template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){ static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] ); (*arr)=(T*)(*mem); (*mem)=((*arr)+x); } template<class T> inline void walloc1d(T **arr, int x1, int x2, void **mem = &wmem){ walloc1d(arr, x2-x1, mem); (*arr) -= x1; } inline int my_getchar_unlocked(){ static char buf[1048576]; static int s = 1048576; static int e = 1048576; if(s == e && e == 1048576){ e = fread_unlocked(buf, 1, 1048576, stdin); s = 0; } if(s == e){ return EOF; } return buf[s++]; } inline void rd(char &c){ int i; for(;;){ i = my_getchar_unlocked(); if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){ break; } } c = i; } inline int rd(char c[]){ int i; int sz = 0; for(;;){ i = my_getchar_unlocked(); if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){ break; } } c[sz++] = i; for(;;){ i = my_getchar_unlocked(); if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){ break; } c[sz++] = i; } c[sz]='\0'; return sz; } struct MY_WRITER{ char buf[1048576]; int s; int e; MY_WRITER(){ s = 0; e = 1048576; } ~MY_WRITER(){ if(s){ fwrite_unlocked(buf, 1, s, stdout); } } } ; MY_WRITER MY_WRITER_VAR; void my_putchar_unlocked(int a){ if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){ fwrite_unlocked(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_unlocked(a); } inline void wt_L(const char c[]){ int i=0; for(i=0;c[i]!='\0';i++){ my_putchar_unlocked(c[i]); } } template<class S, class T> inline S moddw_L(S a, const T b){ a %= b; if(a < 0){ a += b; } return a; } template<class T> void arrRot(int k, int N, T A[], T B[] = NULL, void *mem = wmem){ int i; int fg = 0; (k = moddw_L(k,N)); if(B==NULL){ walloc1d(&B, N, &mem); fg = 1; } for(i=(k);i<(N);i++){ B[i-k] = A[i]; } for(i=(0);i<(k);i++){ B[N-k+i] = A[i]; } if(fg){ for(i=(0);i<(N);i++){ A[i] = B[i]; } } } char S[6]; int main(){ wmem = memarr; rd(S); arrRot(1, 3, S); wt_L(S); wt_L('\n'); return 0; } // cLay version 20210327-1 [beta] // --- original code --- // char S[6]; // { // rd(S); // arrRot(1, 3, S); // wt(S); // }
#include<cstdio> #define p() *p3++='\n' #define P() *p3++=' ' #define N 1010 using namespace std; static char obuf[1<<23],*p3=obuf; template<typename T> inline void read(T&x) { T s=0,w=1;char ch=getchar(); while(ch<'0'||ch>'9') {if(ch=='-')w=-1;ch=getchar();} while(ch>='0'&&ch<='9') {s=(s<<1)+(s<<3)+(ch^48),ch=getchar();} x=w*s; } template<typename T> inline void write(T x) { if(x<0) x=~x+1,*p3++='-'; if(x>9) write(x/10); *p3++=x%10+'0'; } int n,m,a[N],b[N],tong[N]; int main() { read(n),read(m); for(int i=1; i<=n; ++i) { read(a[i]); tong[a[i]]++; } for(int i=1; i<=m; ++i) { read(b[i]); tong[b[i]]++; } for(int i=1; i<=N; ++i) { if(tong[i]==1) write(i),P(); } fwrite(obuf,p3-obuf,1,stdout); return 0; }
#include <iostream> #include <vector> #include <algorithm> #include <iomanip> using namespace std; int ans = 0; int n, k; long t[8][8]; void saiki(int count, int go, long dist, int now) { if (count == n-1) { if (dist + t[now][0] == k) { ans++; } } else { for (int i = 1; i < n; i++) { if (((1 << i) & go) == 0) { saiki(count + 1, (go | (1 << i)), dist + t[now][i], i); } } } } int main() { int go = 0; cin >> n >> k; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> t[i][j]; } } saiki(0, 0, 0, 0); cout << ans; }
#include<bits/stdc++.h> using namespace std; #define endl "\n" #define int long long #define mod 1000000007 #define all(v) (v).begin(),(v).end() #define rall(v) (v).rbegin(),(v).rend() #define trace(x) cerr<<#x<<" : "<<x<<endl; int cnt = 0; bool vis[2002]; void dfs(int idx, vector<int> v[]) { vis[idx] = true; for(auto it:v[idx]) { if(!vis[it]) { dfs(it, v); cnt++; } } } void solve() { int n, m; cin >> n >> m; vector<int> v[n]; for (int i = 0; i < m;i++) { int x, y; cin >> x >> y; x--; y--; v[x].push_back(y); } int ans = 0; for (int i = 0; i < n;i++) { cnt = 0; memset(vis, false, sizeof(vis)); dfs(i, v); ans += cnt; } cout << ans + n; } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t=1; //cin>>t; for(int i=0;i<t;i++) solve(); return 0; }
#include <cstdio> #include <algorithm> using namespace std; using ll = long long int; const ll MOD=1e9+7; const int MAXN=1e3+5; ll factorial[MAXN]; int N; char cAA,cAB,cBA,cBB; ll fast_power(ll base,ll exp){ if (exp==0) return 1ll; auto temp=fast_power(base,exp/2); if (exp%2) return temp*temp%MOD*base%MOD; else return temp*temp%MOD; } ll inv(ll a){ return fast_power(a,MOD-2);} ll C(int n,int m){ auto nominator=factorial[n],denom=factorial[m]*factorial[n-m]%MOD; return nominator*inv(denom)%MOD; } int main(){ scanf("%d\n",&N); scanf("%c\n%c\n%c\n%c",&cAA,&cAB,&cBA,&cBB); // factorial[0]=1ll; // for(int i=1;i<=N;i++) factorial[i]=factorial[i-1]*i%MOD; ll len=max(0,N-3); if (cAB!=cBA&&((cAB=='A'&&cAA=='B')||(cAB=='B'&&cBB=='A'))){ printf("%lld\n",fast_power(2ll,len)); }else if ((cAB=='A'&&cAA=='B')||(cAB=='B'&&cBB=='A')){ ll A=1,B=0; for(int i=0;i<N-2;i++){ ll tA=B,tB=(A+B)%MOD; A=tA,B=tB; } printf("%lld\n",(A+B)%MOD); }else puts("1"); return 0; }
#include <bits/stdc++.h> #include <map> #include <iostream> using namespace std; typedef long long ll; typedef long double ld; #define BIG 200005 ll M = 1000000000+7; ll mpow(ll x, ll n){ ll ans = 1; while(n != 0){ if(n&1) ans = ans*x % M; x = x*x % M; n = n >> 1; } return ans; } int main() { int N; cin >> N; vector<int> c; // A=0, B=1 for(int i=0;i<4;i++){ char cc; cin >> cc; c.push_back(cc - 'A'); } if(N<=3){ printf("%d\n", 1); return 0; } // ab = Aにする if(c[1]==1){ for(int i=0;i<4;i++){ c[i] = 1 - c[i]; } swap(c[0], c[3]); } ll ans; if(c[0]==0){ ans = 1; }else{ // aa = B if(c[2]==1){ // 2^(N-3) ans = mpow(2ll, ll(N-3)); }else{ ll pre = 0; ll p = 1; for(int i=0;i<N-2;i++){ ll current = (p + pre) % M; pre = p; p = current; } ans = p; } } printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i,a,n) for (int i=(a); i<(n); i++) #define rep2(i,a,n) for (int i=(a); i<=(n); i++) using ll = long long; using dl = double long; using P = pair<int,int>; using Graph = vector<vector<int>>; int main() { vector<int> l(3); rep(i,0,3) cin >> l[i]; sort(l.begin(),l.end()); cout << l[1]+l[2] << endl; }
#include<iostream> using namespace std; int main(){ int A[4]; for(int i = 0; i < 4; i++){ cin >> A[i]; } cout << A[0] * A[3] - A[1] * A[2] << endl; }
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~= *$* WRITER:kakitamasziru/OxOmisosiru *$* ~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/ #ifdef LOCAL_JUDGE #define _GLIBCXX_DEBUG #endif #include <stdio.h> #include <iostream> // cout, endl, cin #include <string> // string, to_string, stoi #include <vector> // vector #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <utility> // pair, make_pair #include <tuple> // tuple, make_tuple #include <cstdint> // int64_t, int*_t #include <iomanip> //setprecision #include <map> // map #include <queue> // queue, priority_queue #include <set> // set,multiset #include <stack> // stack #include <deque> // deque #include <math.h>//pow,,, #include <cmath>//abs,,, #include <bitset> // bitset #include <numeric> //accumulate,,, #include <time.h> //clock #define endl "\n"; using namespace std; using PLL = pair<long long,long long>; typedef tuple<int,int,int> TUP; using P = pair<int,int>; const long long INF = 3000000000000000001; const int inf = 1001001001; long long MOD = 1000000007; //Solve N^M. This, mod_pow use Iterative Square Method. long long mod_pow(long long N, long long M, long long mod) { if (M == 0) return 1; long long res = mod_pow((N * N) % mod, M / 2,mod); //When end-of-a bit is 1, times simple N. if (M & 1) res = (res * N) % mod; return res %= mod; } long long gcd(long long a, long long b) { if (b == 0) return a; else return gcd(b, a % b); } long long lcm(long long a, long long b) { return a / gcd(a, b) * b ; } long long get_mod(long long res){ if(res < 0) res += MOD; return res % MOD; } int main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); int H,W;cin >> H >> W; vector<vector<int>> ban(H,vector<int>(W)); int mini = inf; int ans = 0; for(int i = 0;i<H;i++) for(int j = 0;j<W;j++) cin >> ban.at(i).at(j), mini = min(mini,ban.at(i).at(j)); for(int i = 0;i<H;i++) for(int j = 0;j<W;j++) ans += ban.at(i).at(j)-mini; cout << ans << endl; }
#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; typedef long long int ll; constexpr int kN = 73; bitset<kN> bs[kN]; int n; ll ans; unordered_map<__int128, ll> ma; void solve(bitset<kN> cur) { int id = cur._Find_first(); __int128 val = 0; for (int i = n - 1; i >= id; i--) if (cur[i]) val |= __int128(1) << (n - 1 - i); if (ma.find(val) != ma.end()) { ans += ma[val]; return ; } ll cur_ans = ans; ans++; for (int i = id; i < n; i = cur._Find_next(i)) solve(cur & bs[i]); ma[val] = ans - cur_ans; return ; } int main() { ll a, b; scanf("%lld%lld", &a, &b); n = b - a + 1; for (ll i = a; i <= b; i++) for (ll j = i + 1; j <= b; j++) if (__gcd(i, j) == 1) bs[i - a][j - a] = true; bitset<kN> cur; for (int i = 0; i < n; i++) cur[i] = true; solve(cur); printf("%lld\n", ans); }
#include <bits/stdc++.h> #define fo(i,a,b) for(int i=a;i<=b;++i) #define fod(i,a,b) for(int i=a;i>=b;--i) using namespace std; typedef long long LL; const int N=500500; int read(int &n) { bool q=0;n=0;char ch=' '; for(;ch!='-'&&(ch<'0'||ch>'9');ch=getchar()); if(ch=='-')ch=getchar(),q=1; for(;ch>='0'&&ch<='9';ch=getchar())n=(n<<3)+(n<<1)+ch-48; return q?n=-n:n; } int n,m; int a[N],a0[N]; int Ans[N]; int JS(int q,int w,int i,int j) { return abs(q-i)+abs(w-j); } int main() { int q,w,_; read(_); while(_--) { read(n); fo(i,1,n)read(a[i]),a0[i]=a[i]; Ans[0]=0; fo(I,1,n) { int nw; fo(i,1,n)if(a[i]==I){nw=i;break;} if(nw==I)continue; if(((nw-1)&1)==(Ans[0]&1)) { fod(i,n-1,1)if((i&1)!=(Ans[0]&1)){q=i;break;} if(q==nw) { Ans[++Ans[0]]=q,swap(a[q],a[q+1]); Ans[++Ans[0]]=q-1,swap(a[q],a[q-1]); ++nw; fod(i,nw-1,I)Ans[++Ans[0]]=i,swap(a[i],a[i+1]); }else if(q<I) { fo(i,1,n)if((i&1)!=(Ans[0]&1)){q=i;break;} Ans[++Ans[0]]=q,swap(a[q],a[q+1]); fod(i,nw-1,I)Ans[++Ans[0]]=i,swap(a[i],a[i+1]); if(q%2!=Ans[0]%2) { Ans[++Ans[0]]=q,swap(a[q],a[q+1]); }else{ Ans[++Ans[0]]=q+3,swap(a[q+3],a[q+4]); Ans[++Ans[0]]=q,swap(a[q],a[q+1]); Ans[++Ans[0]]=q+3,swap(a[q+3],a[q+4]); } } else{ Ans[++Ans[0]]=q,swap(a[q],a[q+1]); fod(i,nw-1,I)Ans[++Ans[0]]=i,swap(a[i],a[i+1]); } }else{ fod(i,nw-1,I)Ans[++Ans[0]]=i,swap(a[i],a[i+1]); } } // fo(i,1,Ans[0]) // { // q=Ans[i]; // if(Ans[i]%2 !=(i&1))printf("dfwefwefe\n"); // swap(a0[q],a0[q+1]); // } // fo(i,1,n-1)if(a0[i]>a0[i+1])printf("wefverbrtbrtbrterth\n"); printf("%d\n",Ans[0]); fo(i,1,Ans[0])printf("%d ",Ans[i]);printf("\n"); } return 0; }
#include <bits/stdc++.h> #define f first #define s second #define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i) #define pb push_back #define all(s) begin(s), end(s) #define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define sz(s) int(s.size()) #define ENDL '\n' #define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__)) #define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__))) using namespace std; template<class t> using vc=vector<t>; template<class t> using vvc=vc<vc<t>>; typedef long long lli; typedef pair<int,int> ii; typedef vector<int> vi; #define deb(x) cout << #x": " << (x) << endl; lli gcd(lli a, lli b){return (b?gcd(b,a%b):a);} lli lcm(lli a, lli b){ if(!a || !b) return 0; return a * b / gcd(a, b); } int popcount(lli x) { return __builtin_popcountll(x); } // mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // int rnd(int n){return uniform_int_distribution<int>(0, n-1)(rng);} lli poww(lli a, lli b, lli mod){ lli res =1; while(b){ if(b&1) res = (res * a)%mod; a = (a*a)%mod; b/=2; } return res; } vvc<int> graph(int n, int m, bool dir=1){ vv(int,v,n+1,0); fore(i,0,m){ int a,b; cin>>a>>b; v[a].pb(b); if(dir)v[b].pb(a); } return v; } template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2; // ---- コーディングはここから! ('-')7 void solve(){ int n; cin>>n; vc<lli>v(n),x(n),y(n); fore(i,0,n)cin>>x[i]; fore(i,0,n)cin>>y[i]; v[0]=x[0]; fore(i,1,n)v[i]=max(x[i],v[i-1]); v[0]*=y[0]; fore(i,1,n)v[i]=max(v[i-1],v[i]*y[i]); fore(i,0,n)cout<<v[i]<<ENDL; // cout<<ENDL; } int main(){_ //int t; cin>>t; while(t--) solve(); }
#include<iostream> #include<vector> #include<map> #include<stack> #include<stdlib.h> #include<math.h> #include<string> #include<string.h> #include<set> #include<algorithm> #define Doura() ios_base::sync_with_stdio(false),cin.tie(NULL), cout.tie(NULL) #define ll long long using namespace std; int main() { Doura(); int h,w,i,j,m=1000; cin>>h>>w; int a[h][w]; for(i=0;i<h;i++) { for(j=0;j<w;j++) { cin>>a[i][j]; m=min(m,a[i][j]); } } int cnt=0; for(i=0;i<h;i++) { for(j=0;j<w;j++) { cnt+=a[i][j]-m; } } cout<<cnt<<endl; }
// #define _GLIBCXX_DEBUG #include <bits/stdc++.h> // #include <atcoder/all> // g++ main.cpp -std=c++17 -I . using namespace std; // using namespace atcoder; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(v) (v).begin(), (v).end() template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;} template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;} using ll=long long; const int inf = INT_MAX / 2; const ll INF = 1LL << 60; const int MOD = 1000000007; // const int MOD = 998244353; // cout << fixed << setprecision(15) << ans << endl; // using mint = modint1000000007; //////////////////////////////////////////////////////////////////////////////////////////// bool cmp0(const tuple<ll, ll, int> &a, const tuple<ll, ll, int> &b) { return get<0>(a) < get<0>(b); } bool cmp1(const tuple<ll, ll, int> &a, const tuple<ll, ll, int> &b) { return get<1>(a) < get<1>(b); } int main() { int n;cin>>n; vector<tuple<ll, ll, int>> xy; rep(i, n) { ll x, y;cin>>x>>y; xy.push_back(make_tuple(x, y, i)); } vector<tuple<ll, ll, int>> v0 = xy; sort(all(v0), cmp0); vector<tuple<ll, ll, int>> v1 = xy; sort(all(v1), cmp1); vector<int> ind; if(get<0>(v0[n-1]) - get<0>(v0[0]) > get<1>(v1[n-1]) - get<1>(v1[0])) { ind.push_back(get<2>(v0[0])); ind.push_back(get<2>(v0[n-1])); } else { ind.push_back(get<2>(v1[0])); ind.push_back(get<2>(v1[n-1])); } // cout << ind[0] << endl; // cout << ind[1] << endl; ll ans = -INF; rep(i, 2) { vector<tuple<ll, ll, int>> temp = xy; temp.erase(temp.begin() + ind[i]); vector<tuple<ll, ll, int>> v0 = temp; sort(all(v0), cmp0); vector<tuple<ll, ll, int>> v1 = temp; sort(all(v1), cmp1); chmax(ans, max(get<0>(v0[n-2]) - get<0>(v0[0]), get<1>(v1[n-2]) - get<1>(v1[0]))); } cout << ans << endl; }
#include <iostream> #include <algorithm> #include <vector> #include <string> #include <queue> #include <cmath> using namespace std; //-------------------------------------------------------// #define fast() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define MOD 1000000007 #define INF 1e18 #define endl '\n' #define pb push_back #define mp make_pair #define PI 3.141592653589793238462 #define sz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define rep(iter, from, to, increment) for(iter = (from); iter<(to); iter+=(increment)) typedef long long ll; typedef unsigned long long ull; typedef long double lld; bool revsort(ll a, ll b) {return a>b;} void swap(int &x, int &y) {int temp = x; x = y; y = temp;} vector<ll> sieve(ll n){ int* arr = new int[n+1](); vector<ll> vect; for(int i = 2;i<=n; i++) if(arr[i]==0){ vect.push_back(i); for(int j = 2*i;j<=n;j+=i) arr[j] = 1;}return vect;} void solveA(){ float N; cin>>N; N *= 1.08; int out = N; if( out > 206) cout<<":("<<endl; else { if (out == 206) cout<<"so-so"<<endl; else cout<<"Yay!"<<endl; } } void solveB(){ ll n; cin>>n; ll out = round(sqrt(2*n)); cout<<out<<endl; } int main(){ fast() //int T; // cin>>T; // while(T--) solveB(); }
#include<bits/stdc++.h> using namespace std; int main() { int n; cin>>n; n*=2; int res = sqrt(n); while(res*(res+1)<n){ res++; } cout<<res<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; int a[n][2]; for(int i=0;i<n;i++) cin >> a[i][0] >> a[i][1]; int count=0; for(int i=0;i<n-1;i++){ for(int j=i+1;j<n;j++){ if(abs(a[i][1]-a[j][1])<=abs(a[i][0]-a[j][0])) count++; } } cout << count << endl; }
#include <iostream> #include<bits/stdc++.h> using namespace std; #define ull signed long long int #define lli long long int #define ll long long #define all(v) v.begin(), v.end() #define allr(v) v.rbegin(),v.rend() //reverse #define vl vector<lli> #define fro(i,a,b) for(int i=a;i<b;i++) #define mii unordered_map<ll,ll> #define pb push_back double pi = 2*acos(0.0); const int INF = 1e9 + 7; //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; } return res; } void func(vector<lli>v,lli k,lli n,lli &ans,lli h1,lli h2,lli cnt,vector<vector<bool>>&dp){ if(n<0) return; if(h1>=k&&h2>=k){ ans=min(ans,cnt); return; } if(dp[h1][h2]==true) return; func(v,k,n-1,ans,h1+v[n],h2,cnt+1,dp); dp[h1+v[n]][h2]=true; func(v,k,n-1,ans,h1,h2+v[n],cnt+1,dp); dp[h1][h2+v[n]]=true; func(v,k,n-1,ans,h1,h2,cnt,dp); dp[h1][h2]=true; } void WetPitch() { lli n; cin>>n; double x[n];double y[n]; fro(i,0,n){ cin>>x[i]>>y[i]; } lli ans=0; for(int i=0;i<n;i++){ for(int j=i+1;j<n;j++){ if((y[j]-y[i])/(x[j]-x[i])>=-1&&(y[j]-y[i])/(x[j]-x[i])<=1) ans++; } } cout<<ans<<endl; } signed main() { ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0); lli tst; tst=1; //cin>>tst;int p=1; while(tst--) { WetPitch(); } return 0; }
// ダイクストラ法 非負距離のみ // O((N+M)log M) // https://www.youtube.com/watch?v=iEfDi7wagfE&feature=youtu.be #include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<(n);i++) typedef long long ll; #define REP(i,n) for(ll i=0;i<(ll)(n);i++) #define REPD(i,n) for(ll i=n-1;i>=0;i--) #define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++) #define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--) //定数 #define INF (1LL << 60)/2 //10^9:極めて大きい値,∞ //略記 #define PB push_back //vectorヘの挿入 #define MP make_pair //pairのコンストラクタ #define F first //pairの一つ目の要素 #define S second //pairの二つ目の要素 //////////////////////////////////////////////// struct Edge { long long to; // 繋がる所 long long cost; // 区間距離(コスト) Edge(long long to=0, long long cost=0): to(to), cost(cost) {} }; using Graph = vector<vector<Edge>>; using P = pair<long, int>; /* dijkstra(G,s,dis) 入力:グラフ G, 開始点 s, 距離を格納する(結果) dis 計算量:O(|E|log|V|) 副作用:dis が書き換えられる (disがINFなら到達不可) */ void dijkstra(const Graph &G, int s, vector<long long> &dis) { int N = G.size(); dis.resize(N, INF); priority_queue<P, vector<P>, greater<P>> pq; // 「仮の最短距離, 頂点」が小さい順に並ぶ dis[s] = 0; pq.emplace(dis[s], s); while (!pq.empty()) { P p = pq.top(); pq.pop(); int v = p.second; if (dis[v] < p.first) { // 最短距離で無ければ無視 continue; } for (auto &e : G[v]) { if (dis[e.to] > dis[v] + e.cost) { // 最短距離候補なら priority_queue に追加 dis[e.to] = dis[v] + e.cost; pq.emplace(dis[e.to], e.to); } } } } int main(){ int N, M; cin >> N >> M; Graph g0(N),g1(N); vector<long long> dis0, dis1, same(N, INF); rep(i, M){ int a, b, c; cin >> a >> b >> c; a--;b--; g0[a].emplace_back(b, c); g1[b].emplace_back(a, c); if(a==b) same[a]=min(same[a], (ll)c); } rep(i, N){ dis0.clear(); dis1.clear(); dijkstra(g0, i, dis0); dijkstra(g1, i, dis1); ll dist=same[i]; rep(j,N){ if(j==i) continue; dist=min(dist, dis0[j]+dis1[j]); } if(dist>=INF) cout << "-1" << endl; else cout << dist << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define dbg(...) dbs(#__VA_ARGS__, __VA_ARGS__) template <class T> void dbs(string str, T t) { cerr << str << " : " << t << "\n"; } template <class T, class... S> void dbs(string str, T t, S... s) { int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...); } template <class S, class T> ostream &operator<<(ostream &os, const pair<S, T> &p) { return os << "(" << p.first << ", " << p.second << ")"; } template <class T> void debug(T a, T b) { cerr << "["; for (T i = a; i != b; ++i) { if (i != a) cerr << ", "; cerr << *i; } cerr << "]\n"; } const int N = 100100; int root[N]; int getRoot(int n) { if (root[n] != n) { root[n] = getRoot(root[n]); } return root[n]; } vector<pair<int, int>> adj[N]; int val[N]; bool visited[N]; int n, m; void dfs(int u, int edgeVal) { val[u] = edgeVal; visited[u] = true; set<int> childVals; for (const auto& e : adj[u]) { if (visited[e.first]) { continue; } if (e.second == edgeVal) { dfs(e.first, edgeVal % n + 1); } else { dfs(e.first, e.second); } childVals.insert(val[e.first]); } if (val[u] == -1) { val[u] = 1; while (childVals.count(val[u])) { ++val[u]; } } } int main() { #ifdef LOCAL freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m; for (int i = 0; i < m; ++i) { int u, v, w; cin >> u >> v >> w; --u, --v; adj[u].emplace_back(v, w); adj[v].emplace_back(u, w); } dfs(0, -1); for (int i = 0; i < n; ++i) { cout << val[i] << "\n"; } return 0; }
#include<bits/stdc++.h> using namespace std; int main() { int n,m,k; scanf("%d%d%d",&n,&m,&k); k=k*1000; int r,l; if(k%m==0) r=k/m; else r=k/m+1; l=k/n; if(r>l)puts("UNSATISFIABLE"); else printf("%d %d",r,l); return 0; }
/// In the name of ALLAH /// I'm THEOVE46 #include<bits/stdc++.h> using namespace std; #define gap " " #define nn "\n" #define pi 2*acos(0.0) #define db double #define ft float #define ll long long int #define ull unsigned long long int #define pf printf #define sf scanf #define ff first #define ss second #define sfi(n) sf("%d",&n) #define sfi2(n, m) sf("%d%d",&n,&m) #define sfl(n) sf("%lld",&n) #define sfl2(n, m) sf("%lld%lld",&n,&m) #define sff(n) sf("%f",&n) #define sfd(n) sf("%lf",&n) #define pfi(n) pf("%d",n) #define pfl(n) pf("%lld",n) #define pff(n) pf("%f",f) #define pfd(n) pf("%lf",f) #define bfi cin.ignore() #define bfs cin.get() #define bfc getchar() #define gl(s) getline(cin, s) #define loop(a,n) for(i=a; i<n; i++) #define mloop(i,a,n) for(i=a; i<n; i++) #define rloop(i,a,n) for(i=a; i>=n; i--) #define tloop(test) for(ll tl=1; tl<=test; tl++) #define case1(z) cout<<"Case "<<z<<": " #define case2(z) printf("Case %d: ",z) #define vi vector<int> #define vl vector<ll> #define vld(vc,rw) vector<vector<ll> >vc(rw) #define pii pair<int,int> #define pll pair<ll,ll> #define pis pair<int,string> #define psi pair<string,int> #define mls map <ll,string> #define msl map <string,ll> #define mll map <ll,ll> #define mp make_pair #define pb push_back #define itr vector<int> :: iterator #define atl(i, v) for(auto i: v) #define sz(s) s.size() #define sl(s) s.length() #define Sort(s) sort(s.begin(), s.end()) #define SortR(s) sort(s.rbegin(), s.rend()) #define all(x) x.begin(),x.end() #define rall(x) x.end(), x.begin() #define MEM(ar,val) memset(ar, (val), sizeof(ar)) #define IN(A,B,C) assert(B<=A && A<=C) #define MOD 1000000007 #define EPS 1e-9 #define Max 1e9 #define Min -1e9 #define bug1 " **1** " #define bug2 " ****2**** " #define artri(b,h) 0.5*b*h #define artrap(b1,b2,h) (b1+b2)/2*h #define arcrl(r) pi*r*r #define vlsyl(r,h) pi*r*r*h #define vlcone(r,h) pi*r*r*(h/3) #define vlsph(r) (4/3)*pi*r*r*r #define flush fflush(stdout) #define pcn(dg,val) fixed << setprecision(dg) << val #define ggl pf("Case #%lld: ", tl) #define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0) #define showsort(n, a) for(int i=0; i<n; i++) cout << a[i] << gap; cout << endl; inline string IntToString(ll a) {char x[100]; sprintf(x,"%lld",a); string s=x; return s;} inline ll StringToInt(string a) {char x[100]; ll res; strcpy(x, a.c_str()); sscanf(x,"%lld",&res); return res;} ///THEOVE46 int main() { FastIO; bool bl = true; ll a, b, w, mn, mx, x, y, s; sf("%lld%lld%lld", &a, &b, &w); w*=1000; mn = w/b; if(w%b!=0) { x = w%b; s = w - (a*mn); if(s<a) {bl = false; //cout << bug1 << endl; } mn++; } mx = w/a; if(w%a!=0) { x = w%a; s = (b-a)*mx; if(s<x) {bl = false; //cout << bug2 << x << " " << mx << " " << s << endl; } } if(bl) cout << mn << " " << mx << nn; else cout << "UNSATISFIABLE" << endl; return 0; } /// check for integer overflow, array bounds /// check for n=1 /// - - - The Ove 46
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; using vvi = vector<vector<int>>; using ll = long long; using vl = vector<long long>; using vvl = vector<vector<long long>>; int main(){ int n; cin >> n; vl a(n),m(n,0),ans(n,0),sum(n,0),sum2(n,0); ll tmpmax = 0; for(int ix=0;ix<n;ix++){ cin >> a[ix]; tmpmax = max(a[ix],tmpmax); if(ix == 0) {m[ix] = a[ix]; sum[ix] = a[ix]; sum2[ix] = 0;} else {m[ix] = max(a[ix],m[ix-1]); sum[ix] = sum[ix-1] + a[ix]; sum2[ix] = sum2[ix-1] + sum[ix-1];} } /* for(auto x : sum) cout << x << endl; cout << endl; for(auto x : sum2) cout << x << endl; cout << endl; */ for(int ix=0;ix<n;ix++){ if(ix == 0) ans[ix] = sum[ix] + m[ix]; else{ ans[ix] = sum[ix] + (ix+1)*m[ix] + sum2[ix]; } } for(auto x : ans) cout << x << endl; }
#include <bits/stdc++.h> using namespace std; int main(){ int n{}; cin>>n; vector <long long int> a(n+1),sum(n+1); for (int i{1};i<=n;i++){ cin>>a.at(i); sum.at(i) = sum.at(i-1) + a.at(i); } long long int max{a.at(0)},sum1{}; for (int i{1};i<=n;i++){ if (max < a.at(i)){ sum1 += (i-1)*(a.at(i) - max); max = a.at(i); } sum1 += max + sum.at(i); cout<<sum1<<endl; } return 0; }
// includes #include <bits/stdc++.h> using namespace std; // macros #define pb emplace_back #define mk make_pair #define FOR(i, a, b) for(int i=(a);i<(b);++i) #define rep(i, n) FOR(i, 0, n) #define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--) #define irep(itr, st) for(auto itr = (st).begin(); itr != (st).end(); ++itr) #define irrep(itr, st) for(auto itr = (st).rbegin(); itr != (st).rend(); ++itr) #define whole(x) (x).begin(),(x).end() #define sz(x) ((int)(x).size()) #define bit(n) (1LL<<(n)) #define F first #define S second // functions template <typename T> void unique(T& c){c.erase(std::unique(c.begin(), c.end()), c.end());} template <class T>bool chmax(T &a, const T &b){if(a < b){a = b; return 1;} return 0;} template <class T>bool chmin(T &a, const T &b){if(a > b){a = b; return 1;} return 0;} template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;} template <typename T> ostream &operator<<(ostream &os, const vector<T>& vec){for(int i = 0; i < vec.size(); i++){ os << vec[i]; if(i + 1 != vec.size())os << " ";} return os;} template <typename T> ostream &operator<<(ostream &os, const set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;} template <typename T> ostream &operator<<(ostream &os, const unordered_set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;} template <typename T> ostream &operator<<(ostream &os, const multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;} template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;} template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p){os << "(" << p.first << ", " << p.second << ")"; return os;} template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if(++titr != mp.end())os << " "; } return os;} template <typename T1, typename T2> ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if(++titr != mp.end())os << " "; } return os;} // types using ll = long long int; using P = pair<int, int>; // constants const int inf = 1e9; const ll linf = 1LL << 60; const double EPS = 1e-10; const int mod = 1000000007; const int dx[4] = {-1, 0, 1, 0}; const int dy[4] = {0, -1, 0, 1}; // io struct fast_io{ fast_io(){ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(20);} } fast_io_; int s(int x){ int res = 0; rep(i, 4){ res += x % 10; x /= 10; } return res; } int main(int argc, char const* argv[]) { int a, b; cin >> a >> b; cout << max(s(a), s(b)) << endl; return 0; }
#include<bits/stdc++.h> #define int long long #define for0(i, n) for(int i = 0; i < (n); i++) #define for1(i, n) for(int i = 1; i <= (n);i++) #define mp make_pair #define puts(x) cout << (x) << "\n" using namespace std; int input() { int t; cin >> t; return t; } int n, x[300], y[300], R[300], xe[300], ye[300]; bool fb(int i, int j) { if (x[i] + xe[i] <= x[j])return 1; if (x[j] + xe[j] <= x[i])return 1; if (y[i] + ye[i] <= y[j])return 1; if (y[j] + ye[j] <= y[i])return 1; return 0; } bool fball(int i) { if (x[i] + xe[i] > 10000 || y[i] + ye[i] > 10000)return 0; for0(j, n) if (i != j && !fb(i, j))return 0; return 1; } signed main() { cin >> n; for0(i, n) { cin >> x[i] >> y[i] >> R[i]; xe[i] = 1; ye[i] = 1; } for0(i, n) { int l = 1, r = (int)sqrt(R[i]) + 1; while (r - l > 1) { int mid = (l + r) / 2; xe[i] = mid; ye[i] = mid; if (fball(i))l = mid; else r = mid; } xe[i] = l; ye[i] = l; } for0(valsq, 3000)for0(i, n) if (xe[i] * ye[i] < R[i]) { if (x[i] + xe[i] < 10000) { xe[i]++; if (fball(i))continue; xe[i]--; } if (y[i] + ye[i] < 10000) { ye[i]++; if (fball(i))continue; ye[i]--; } } for0(valsq, 3000)for0(i, n) if (xe[i] * ye[i] < R[i]) { if (y[i] > 0) { y[i]--; ye[i]++; if (fball(i))continue; y[i]++; ye[i]--; } if (x[i] > 0) { x[i]--; xe[i]++; if (fball(i))continue; x[i]++; xe[i]--; } } for0(i, n)cout << x[i] << ' ' << y[i] << ' ' << x[i] + xe[i] << ' ' << y[i] + ye[i] << endl; }
#include <iostream> #include <iomanip> using namespace std; int main() { int a,b,c; cin >> a >> b >> c; int n = 101; double e[n][n][n]; for(int i = 0; i < n; ++i){ for(int j = 0; j < n; ++j){ e[i][j][100] = 0; e[100][i][j] = 0; e[j][100][i] = 0; } } for(int i = n-2; i >= a; --i){ for(int j = n-2; j >= b; --j){ for(int k = n-2; k >= c; --k){ e[i][j][k] = ((double)i*(e[i+1][j][k]) + (double)j*(e[i][j+1][k]) + (double)k*(e[i][j][k+1]))/(double)(i+j+k) + 1; } } } cout << fixed << setprecision(9) << e[a][b][c] <<endl; }
#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; } //---------------------------------------------------------------------------------------------- double dpd[101][101]; double dpt[101][101][101]; int main() { vector<int> v(3); rep(i,0,3) cin >> v[i]; SORT(v); if(v[1] == 0) cout << 100-v[2] << endl; else if(v[0] == 0) { int a = v[1], b = v[2]; for(int i = 99; i >= a; --i) { for(int j = 99; j >= b; --j) { dpd[i][j] += (double)i/(double)(i+j) * (dpd[i+1][j] + 1); dpd[i][j] += (double)j/(double)(i+j) * (dpd[i][j+1] + 1); } } cout << fixed << setprecision(10) << dpd[a][b] << endl; } else { int a = v[0], b = v[1], c = v[2]; for(int i = 99; i >= a; --i) { for(int j = 99; j >= b; --j) { for(int k = 99; k >= c; --k) { dpt[i][j][k] += (double)i/(double)(i+j+k) * (dpt[i+1][j][k] + 1); dpt[i][j][k] += (double)j/(double)(i+j+k) * (dpt[i][j+1][k] + 1); dpt[i][j][k] += (double)k/(double)(i+j+k) * (dpt[i][j][k+1] + 1); } } } cout << fixed << setprecision(10) << dpt[a][b][c] << endl; } return 0; }
// atcoder/arc113/C/main.cpp // author: @___Johniel // github: https://github.com/johniel/ #include <bits/stdc++.h> #define each(i, c) for (auto& i : c) #define unless(cond) if (!(cond)) using namespace std; template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; } template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; } template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; } template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; } template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; } template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; } template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); } template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); } using lli = long long int; using ull = unsigned long long; using point = complex<double>; using str = string; template<typename T> using vec = vector<T>; constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1}); constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1}); constexpr lli mod = 1e9 + 7; int main(int argc, char *argv[]) { ios_base::sync_with_stdio(0); cin.tie(0); cout.setf(ios_base::fixed); cout.precision(15); str s; while (cin >> s) { lli x = 0; map<char, int> m; for (int i = s.size() - 3; 0 <= i; --i) { ++m[s[i+2]]; if (s[i] == s[i + 1] && s[i + 1] != s[i + 2]) { x += s.size() - (i+2) - m[s[i]]; m.clear(); m[s[i]] = s.size() - (i+2); } } cout << x << endl; } return 0; }
#define LOCAL #ifdef LOCAL #define _GLIBCXX_DEBUG #endif #include <bits/stdc++.h> using namespace std; #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 LINF = 1001002003004005006ll; constexpr int INF = 1002003004; 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); } }; int main() { ios::sync_with_stdio(false); cin.tie(0); vi v(4); rep(i, 0, 4) cin >> v[i]; sort(All(v)); cout << v[0] << endl; return 0; };
#include<bits/stdc++.h> #define int long long int #define debug(x) cout << '>' << #x << ':' << x << endl; #define loop(i,n) for(int i=0;i<(int)(n);i++) #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define fastm_fast ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL) #define pb push_back #define mp make_pair #define ff first #define ss second using namespace std; const int mod = 1e9 + 7; const int MAX = 2e5+5; typedef pair<int, int> pii; typedef vector<int> vi ; typedef vector<string> vs; typedef vector<pii> vpi; typedef vector<vi> vvi; typedef map<int,int> mapii ; void sujho(){ int a ,b ,c; cin >> a >> b >> c ; if( a==b ) cout << c ; else if(a == c) cout << b ; else if(b == c) cout << a ; else cout << 0; } int32_t main() { fastm_fast; // int test;cin >> test; // for(int i = 1; i <= test; i++) { //cout << "Case #"<< test << ":"; sujho(); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; const int maxn=1e6+5; int main() { int a,b,c,d; cin>>a>>b>>c>>d; cout<<b-c<<endl; return 0; }
#include<bits/stdc++.h> using namespace std ; #define int long long #define pb push_back #define all(v) v.begin(),v.end() #define sz(a) (int)a.size() #define F first #define S second #define INF 2000000000000000000 #define popcount(x) __builtin_popcountll(x) #define pll pair<int,int> #define pii pair<int,int> #define ld long double #define bug(x) cerr<<"#x"<<" is "<<x<<endl; const int M = 1000000007; const int MM = 998244353; const long double PI = acos(-1); template<typename T, typename U> static inline void amin(T &x, U y){ if(y<x) x=y; } template<typename T, typename U> static inline void amax(T &x, U y){ if(x<y) x=y; } template<typename T, typename U> ostream& operator<<(ostream &os, const pair<T, U> &p) { return os<<'('<<p.F<< ","<<p.S<<')'; } int tError() { int l,r; cin>>l>>r; if(l==0 && r==0) return cout<<1<<endl,0; else if((l==r)or(r-2*l+1<=0)) return cout<<0<<endl,0; int ans=(r-2*l)+1; int anss=(ans*(ans+1))/2; cout<<anss<<endl; return 0; } signed main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif int TESTS=1; cin>>TESTS; while(TESTS--) tError(); // cerr << "Time taken: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; return 0; }
#include<iostream> #include<bits/stdc++.h> using namespace std; int main() { int n, a[1000], b[1000]; cin>>n; for (int j = 0; j < n; j++) cin>>a[j]>>b[j]; int min = a[0], mini = 0; for (int i = 1; i < n; i++) { if(a[i]<min) { min = a[i]; mini = i; } } b[mini] = a[mini]+b[mini]; int mi = b[0], mii = 0; for (int k = 1; k < n; k++) { if(b[k]<mi) { mi = b[k]; mii = k; } } if(mini==mii)cout<<b[mii]; else printf("%d", max(a[mini], b[mii])); return 0; }
#include <bits/stdc++.h> using namespace std; #define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); const long long INF=1e9+7; int main(){ IOS; long long n; cin>>n; long long i=1; while(i*(i+1)<2*n){ i++; } cout<<i<<endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); } ll lcm(ll a, ll b) { return ((a * b) / gcd(a, b)); } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); ld n; cin >> n; cout << ceil(-0.5 + pow(1 + 8 * n, 0.5) * 0.5); return 0; }
#include <bits/stdc++.h> using namespace std; vector<int> ans; int bitmask[18]; int bits[20]; int dp[2000000]; bool chMap[2000000]; bool check(int state){ for (int i=0;i<18;++i) if ((bits[i]&state) && (bitmask[i]&state)!=state) return false; return true; } int solve(int n){ chMap[0]=true; for (int state=1;state<bits[n];++state) chMap[state]=check(state); dp[0]=0; for (int state=1;state<bits[n];++state){ dp[state]=INT_MAX; //if (state%1000==0) cout<<"1000!\n"; for (int sub=state;sub!=0;sub=(sub-1)&state) if (chMap[sub]) dp[state]=min(dp[state],dp[state^sub]+1); } return dp[bits[n]-1]; } int main(){ int n,m; scanf("%d%d",&n,&m); for (int i=0;i<20;++i) bits[i]=1<<i; for (int i=0;i<m;++i){ int u,v; scanf("%d%d",&u,&v); u--; v--; bitmask[u]|=bits[v]; bitmask[v]|=bits[u]; } for (int i=0;i<n;++i){ bitmask[i]|=bits[i]; } printf("%d",solve(n)); }
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <cstdio> #include <cstring> #include <cmath> using namespace std; using ll = long long; int main() { int n; ll x; cin >> n >> x; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } ll r = 1LL << 60; for (int k = 1; k <= n; k++) { int dp[101][100]; for (int j = 0; j <= k; j++) { for (int b = 0; b < k; b++) { dp[j][b] = -(1 << 30); } } dp[0][0] = 0; for (int i = 0; i < n; i++) { for (int j = min(i + 1, k); j > 0; j--) { for (int b = 0; b < k; b++) { int t = (b - a[i]) % k; if (t < 0) t += k; dp[j][b] = max(dp[j][b], dp[j - 1][t] + a[i]); } } } int t = dp[k][x % k]; if (t < 0) continue; r = min(r, (x - t) / k); } cout << r << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < n; i++) #define rep2(i, x, n) for(int i = x; i <= n; i++) #define rep3(i, x, n) for(int i = x; i >= n; i--) #define each(e, v) for(auto &e: v) #define pb push_back #define eb emplace_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define sz(x) (int)x.size() using ll = long long; using pii = pair<int, int>; using pil = pair<int, ll>; using pli = pair<ll, int>; using pll = pair<ll, ll>; const int MOD = 1000000007; //const int MOD = 998244353; const int inf = (1<<30)-1; const ll INF = (1LL<<60)-1; template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;}; template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;}; struct io_setup{ io_setup(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout << fixed << setprecision(15); } } io_setup; int main(){ int N, M; cin >> N >> M; vector<int> A(N); rep(i, N) cin >> A[i]; vector<int> v(N+1, 0); rep(i, M) v[A[i]]++; vector<bool> ok(N+1, false); rep(i, N+1){ if(v[i] == 0) ok[i] = true; } rep(i, N-M){ int l = A[i], r = A[M+i]; v[r]++, v[l]--; if(v[l] == 0) ok[l] = true; } rep(i, N+1){ if(ok[i]) {cout << i << '\n'; return 0;} } }
#include<bits/stdc++.h> using namespace std; // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/detail/standard_policies.hpp> // using namespace __gnu_pbds; #pragma GCC optimize("O3") #ifdef LOCAL #include "/Users/lbjlc/Desktop/coding/debug_utils.h" #else #define print(...) ; #define printn(...) ; #define printg(...) ; #define fprint(...) ; #define fprintn(...) ; #endif #define rep(i, a, b) for(auto i = (a); i < (b); i++) #define rrep(i, a, b) for(auto i = (a); i > (b); i--) #define all(v) (v).begin(), (v).end() #define pb push_back // #define mp make_pair #define fi first #define se second #define maxi(x, y) x = max(x, y) #define mini(x, y) x = min(x, y) // long long fact(long long n) { if(!n) return 1; return n*fact(n-1); } // #define endl '\n' mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int get_random() { static uniform_int_distribution<int> dist(0, 1e9 + 6); return dist(rng); } #define solve_testcase int T;cin>>T;for(int t=1;t<=T;t++){solve(t);} typedef unsigned long long ull; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<double, double> pdd; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<vvi> vvvi; typedef vector<pii> vpii; typedef vector<pll> vpll; typedef vector<pdd> vpdd; typedef vector<long long> vll; #define bd(type,op,val) bind(op<type>(), std::placeholders::_1, val) template<class T> void make_unique(T & v) { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); } int geti() { int x; cin >> x; return x; } long long getll() { long long x; cin >> x; return x; } double getd() { double x; cin >> x; return x; } // pair<int, int> a(geti(), geti()) does not work // pair<int, int> a({geti(), geti()}) works, since it uses initializer. const int MAXN = 3e5 + 100; void solve(int tt) { // cout<<"Case #"<<tt<<": "; } ll cal(int n, int tot) { if(n+n<tot) return 0; if(n<tot) return n-(tot-n)+1; return tot-1; } int main(int argc, char * argv[]) { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); // solve_testcase; int n,k; cin>>n>>k; k=abs(k); long long res=0; rep(i,2,2*n+1) { res+=cal(n,i)*cal(n,i+k); } cout<<res<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { string s; cin>>s;int c1=0,c2=0,n=s.length(); for(int i=0;i<n;i++) { if(i%2==0) { if(s[i]>=97&&s[i]<=122) { ++c1; } } if(i%2==1) { if(s[i]>=65&&s[i]<=90) { ++c2; } } } if(c1+c2==n) { cout<<"Yes"; } else { cout<<"No"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { #ifndef ONLINE_JUDGE // for getting input from input.txt freopen("input.txt", "r", stdin); // for writing output to output.txt freopen("output.txt", "w", stdout); #endif int N; cin >> N; int tax = N * 1.08; if (tax < 206) { cout << "Yay!" << endl; } else if (tax == 206) { cout << "so-so" << endl; } else { cout << ":(" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll mod =1000000007; #define rep(i,n) for(ll i=0; i<n; i++) int main(){ double a,b; cin>>a>>b; cout<<fixed<<setprecision(10); cout<<(1-b/a)*100<<endl; }
#include <bits/stdc++.h> using namespace std; int main(){ int n, w; cin >> n >> w; cout << n/w << endl; return 0; }
#include<iostream> #include<string> using namespace std; int main(){ int n; string s; cin >> n >> s; int ans = 0; for(int l = 2; l <= n; l = l + 2){ int anum = 0, tnum = 0, cnum = 0, gnum =0; string t = s.substr(0, l); for(int i = 0, size = t.size(); i < size; ++i){ switch (t[i]){ case 'A': ++anum; break; case 'T': ++tnum; break; case 'C': ++cnum; break; case 'G': ++gnum; break; default: break; } } if((anum == tnum)&&(cnum == gnum))++ans; for(int i = 1; i + l <= n; ++i){ switch (s[i-1]){ case 'A': --anum; break; case 'T': --tnum; break; case 'C': --cnum; break; case 'G': --gnum; break; default: break; } switch (s[i + l -1]){ case 'A': ++anum; break; case 'T': ++tnum; break; case 'C': ++cnum; break; case 'G': ++gnum; break; default: break; } if((anum == tnum)&&(cnum == gnum))++ans; } } cout << ans; fflush(stdout); return 0; }
/* "An anomaly, I'm Muhammad Ali Cause I know one day I'm gonna be the" - Greatest, Eminem */ #pragma GCC optimize ("O3") #pragma GCC target ("sse4") #include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef long long int ll; #define ff first #define Shazam ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define ss second #define all(c) c.begin(),c.end() #define endl "\n" #define test() int t; cin>>t; while(t--) #define fl(i,a,b) for(int i = a ; i <b ;i++) #define get(a) fl(i,0,a.size()) cin>>a[i]; #define pra(a) fl(i,0,a.size()) cout<<a[i]<<" "; cout<<endl; #define pr(a,n) fl(i,0,n) cout<<a[i]<<" "; cout<<endl; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; const ll INF = 2e18; const int inf = 2e9; const int mod1 = 1e9 + 7; int main(){ Shazam; ll n, x; cin >> n >> x; string s; cin >> s; for(char c : s){ x = max(0LL, x + ((c=='x')?-1:1)); } cout << x << endl; return 0; }
#pragma GCC optimize("O2") #include <bits/stdc++.h> using namespace std; #define FASTIO ios_base::sync_with_stdio(false), cin.tie(0) //#define MULTI_TEST //#define GOOGLE #ifdef LOCAL #include "debugger.h" #else #define db(...) #endif #define ll long long #define v32 vector<int> #define v64 vector<ll> #define s32 set<int> #define s64 set<ll> #define p32 pair<int, int> #define p64 pair<ll, ll> #define sz(v) (ll)(v).size() #define fi first #define se second #define ln '\n' const ll MOD = 1e9 + 7; inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); } inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); } void solve(int tc) { int n; string s; cin >> n >> s; map<char, int> id; id['A'] = 0; id['C'] = 1; id['G'] = 2; id['T'] = 3; int ans = 0; for (int i = 0; i < n; i++) { v32 cnt(4, 0); for (int j = i; j < n; j++) { cnt[id[s[j]]]++; if (cnt[0] == cnt[3] && cnt[1] == cnt[2]) ans++; } } cout << ans << ln; return; } int main() { #ifndef LOCAL FASTIO; #endif int t = 1; #ifdef LOCAL clock_t start, stop; start = clock(); #endif #ifdef MULTI_TEST cin >> t; #endif for (int tc = 1; tc < t + 1; tc++) { #ifdef GOOGLE cout << "Case #" << tc << ": "; #endif solve(tc); } #ifdef LOCAL stop = clock(); cerr << "Time :" << fixed << setprecision(5) << double(stop - start) / double(CLOCKS_PER_SEC) << "s" << ln; #endif return 0; }
/* Author: rafa45 Date: 28 Sep 2020 */ #include<bits/stdc++.h> #define ll long long #define endl "\n" #define mod 1000000007 using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int i=0, j=0, n=0; int c1=0, c2=0, cnt=0; string s, sub; cin >> n >> s; for(i=0; i<n-1; i++){ c1=0; c2=0; for(j=i; j<n; j++){ if(s[j]=='A') c1++; else if(s[j]=='T') c1--; else if(s[j]=='C') c2++; else c2--; if(c1==0 && c2==0) cnt++; } } cout << cnt << endl; return 0; }
#include <iostream> #include <set> #include <vector> using namespace std; int main(void) { int n; cin >> n; long a; long sum = 0; long sum1 = 0; for (long i = 0; i < n; i++) { cin >> a; sum += a; sum1 += a * a; } cout << n * sum1 - sum * sum << endl; return 0; }
#include<bits/stdc++.h> #include<iostream> #include<cstdio> #include<algorithm> #include<queue> #include<vector> #include<cstring> #include<map> #include<set> #include<cstdlib> #include<bitset> using namespace std; #define FAST ios::sync_with_stdio(false), cin.tie(0), cout.tie(0) typedef long long ll; ll a[402]={0}; int main(void) { ll n; scanf("%lld",&n); for(ll i=0;i<n;i++) { ll v; scanf("%lld",&v); a[v+200]++; } ll ans=0; for(ll i=-200;i<=200;i++) { for(ll j=i+1;j<=200;j++) { ans+=(i-j)*(i-j)*a[i+200]*a[j+200]; } } printf("%lld\n",ans); }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define ull unsigned long long #define loops(i, s, n) for (ll i = s; i < (ll)n; i++) #define loop(i, n) loops(i, 0, n) #define ALL(a) a.begin(), a.end() #define pub push_back #define pob pop_back #define mp make_pair #define dump(x) cerr << #x << " = " << (x) << endl; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef vector<int> vi; typedef vector<double> vd; typedef vector<string> vs; typedef vector<ll> vl; // for dp // 第一引数と第二引数を比較し、第一引数(a)をより大きい/小さい値に上書き template <typename T> inline bool chmin(T &a, const T &b) { bool compare = a > b; if (a > b) a = b; return compare; } template <typename T> inline bool chmax(T &a, const T &b) { bool compare = a < b; if (a < b) a = b; return compare; } #define in_v(type, name, cnt) \ vector<type> name(cnt); \ loop(i, cnt) cin >> name[i]; #define sort_v(v) std::sort(v.begin(), v.end()) #define unique_v(v) v.erase(std::unique(v.begin(), v.end()), v.end()) //必ずソート後に実行 #define set_fix(x) ((std::cerr << std::fixed << std::setprecision(x)), (std::cout << std::fixed << std::setprecision(x))) //cout for vector template <class T> ostream &operator<<(ostream &o, const vector<T> &v) { o << "{"; for (int i = 0; i < (int)v.size(); i++) o << (i > 0 ? ", " : "") << v[i]; o << "}"; return o; } // gcd ll gcd(ll a, ll b) { if (b == 0) return a; else return gcd(b, a % b); } ll lcm(ll a, ll b) { return a * b / gcd(a, b); } //prime numbers bool IsPrime(ll num) { if (num < 2) return false; else if (num == 2) return true; else if (num % 2 == 0) return false; double sqrtNum = sqrt(num); for (ll i = 3; i <= sqrtNum; i += (ll)2) { if (num % i == 0) { return false; } } return true; } vector<ll> Eratosthenes(ll N) { int arr[N]; vector<ll> res; for (int i = 0; i < N; i++) { arr[i] = 1; } for (int i = 2; i < sqrt(N); i++) { if (arr[i]) { for (int j = 0; i * (j + 2) < N; j++) { arr[i * (j + 2)] = 0; } } } for (int i = 2; i < N; i++) { if (arr[i]) { res.push_back(i); } } return res; } //digit number int GetDigit(ll num, ll radix) { unsigned digit = 0; while (num != 0) { num /= radix; digit++; } return digit; } int digsum(ll n) { ll res = 0; while (n > 0) { res += n % (ll)10; n /= (ll)10; } return res; } int main() { int n; cin >> n; vector<ll> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<ll> a_sum(n); ll sum = 0; sort(ALL(a), greater<ll>()); for (int i = 0; i < n; i++) { sum += a[i]; a_sum[i] = sum; } ll res = 0; for (int i = 0; i < n; i++) { res -= (i+1) * a[i] - a_sum[i]; } cout << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; template<class T,class U> using P = pair<T,U>; template<class T> using vec = vector<T>; template<class T> using vvec = vector<vec<T>>; #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) ll M = 998244353; vector<ll> fac(300001); //n!(mod M) vector<ll> ifac(300001); //k!^{M-2} (mod M) //a,bの範囲的にこれだけ配列を用意していけば十分 ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため,随時mod計算 ll ans = 1; while(n != 0){ if(n&1) ans = ans*x % M; x = x*x % M; n = n >> 1; } return ans; } ll comb(ll a, ll b){ //aCbをmod計算 if(a == 0 && b == 0)return 1; if(a < b || a < 0)return 0; ll tmp = ifac[a-b]* ifac[b] % M; return tmp * fac[a] % M; } int main(){ fac[0] = 1; ifac[0] = 1; for(ll i = 0; i<300000; i++){ fac[i+1] = fac[i]*(i+1) % M; // n!(mod M) ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用 } int n; cin >> n; vec<ll> a(n); rep(i, n) cin >> a[i]; sort(a.begin(), a.end()); ll ans = 0; ll tmp = 0; for(int i = n-1; i>=0; i--) { tmp *= 2; tmp %= M; if (i < n-1) tmp += M - a[i+1], tmp %= M; tmp += a[i]; tmp %= M; // cout << i << " " << a[i] * tmp << endl; ans += a[i] * tmp; ans %= M; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i,n) for (int i=0;i<(int)(n);i++) template <typename T> bool chmax(T &a, const T& b) {if (a < b) {a = b; return true;}return false;} template <typename T> bool chmin(T &a, const T& b) {if (a > b) {a = b; return true;}return false;} const int MOD = 1000000007; ll x = 10000000000; int main(){ int a,b,c,d; cin >> a >> b; cin >> c >> d; cout << b-c << endl; }
#include <bits/stdc++.h> using namespace std; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int a, b; cin >> a >> b; int c = a * 2 + 100; int d = c - b; cout << d; }
// ██████  ██  ██ ██████  ██ ██  ██  ██████  // ██       ██  ██ ██   ██ ██ ██  ██  ██    ██  // ██  ███ ██  ██ ██████  ██ █████   ██  ██  // ██  ██ ██  ██ ██   ██ ██ ██  ██  ██  ██  //  ██████   ██████  ██  ██ ██ ██  ██  ██████   #include <bits/stdc++.h> typedef long long ll; using namespace std; #define repr(i,a,b) for(int i=a;i<b;i++) #define rep(i,n) for(int i=0;i<n;i++) #define invrepr(i,a,b) for(int i=b-1;i>=a;i--) #define invrep(i,n) invrepr(i,0,n) #define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr) #define P pair<int,int> const ll MOD=1e9+7; const int MAX=1e5+10; const int INF=1e9; const double PI=acos(-1); int main() { vector<int> a(3); rep(i,3) cin >> a[i]; sort(a.begin(),a.end()); if (a[2]-a[1]==a[1]-a[0]) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { int a[3]; cin >> a[0] >> a[1] >> a[2]; sort(a, a + 3); if (2 * a[1] == a[0] + a[2]) cout << "Yes"; else cout << "No"; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() using namespace std; using ll = long long; const int INF = 1000000000; const int MOD = 1000000007; const ll llINF = 1000000000000000000; void solve() { vector<int> a(3); rep(i, 3) cin >> a[i]; sort(all(a)); if (a[2] - a[1] == a[1] - a[0]) cout << "Yes" << endl; else cout << "No" << endl; } int main() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(15); solve(); return 0; }
#include<bits/stdc++.h> #include<math.h> #define str string #define sz size() #define bgn begin() #define ll long long int #define li long int #define con continue #define rt return 0 #define fr first #define sec second #define pf push_front #define pb push_back #define vb vct.begin() #define ve vct.end() #define vs vct.size() #define db dq.begin() #define de dq.end() #define ds dq.size() #define ib it.begin() #define ie it.end() #define itf it->first #define its it->second #define lb lst.begin() #define le lst.end() #define mb mp.begin() #define me mp.end() #define stb st.begin() #define ste st.end() #define sb s.begin() #define se s.end() #define NL printf("\n") #define yes printf("YES\n") #define no printf("NO\n") #define forone for(i=1;i<=n;i++) #define forzero for(i=0;i<n;i++) #define sortone sort(ara+1,ara+n+1) #define sortzero sort(ara,ara+n) #define get(ara) forone cin>>ara[i] #define tc ll tc;scanf("%lld",&tc);while(tc--) using namespace std; int main( ) { //tc { ll i,j,k,y,n,x,m,a,b,ans=0,sum=0,cnt=0; ll c,mx=0,mn=INT_MAX,mod=1e9+7; str s,z,taj="No"; cin>>n>>k; x=abs(n-k); if(x<=2) taj="Yes"; cout<<taj; NL; } return 0; }
#include <bits/stdc++.h> #ifdef LILY #include "./Debug.h" #else #define var(...) (0) #define dbg(...) (0) #endif using int32 = int; using int64 = long long; using namespace std; class Solution { #define int int64 #define sfor(i, n) for (int i = 1; i <= (n); ++i) #define tfor(i, n) for (int i = 0; i < (n); ++i) int n, m, l, r, res; vector<int> x; using p = pair<int, int>; vector<p> t; void SHURU() { cin >> l >> r; --l, --r; res = 0; } void SHUCHU() { cout << res << endl; } void CHULI() { vector<int> cases; for (int i = 0; i < m; ++i) { if (i < l || i > r) cases.push_back(x[i]); } if (cases.size() == 0) return; sort(cases.begin(), cases.end()); for (auto i : t) { auto j = lower_bound(cases.begin(), cases.end(), i.first); if (j == cases.end()) continue; cases.erase(j); res += i.second; if (cases.size() == 0) return; } } public: Solution() { int q, s, y; cin >> n >> m >> q; tfor(i, n) { cin >> s >> y; t.emplace_back(s, y); } tfor(i, m) { cin >> s; x.push_back(s); } sort(t.begin(), t.end(), [](p a, p b) { return a.second > b.second; }); while (q--) { SHURU(); CHULI(); SHUCHU(); } } #undef int #undef tfor #undef sfor }; int32 main() #ifndef LILY { Solution(); } #endif
// Problem: B - Reversible Cards // Contest: AtCoder - AtCoder Regular Contest 111 // URL: https://atcoder.jp/contests/arc111/tasks/arc111_b // Memory Limit: 1024 MB // Time Limit: 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; struct splitmix64_hash { static uint64_t splitmix64(uint64_t x) { // http://xorshift.di.unimi.it/splitmix64.c x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = std::chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; template <typename K, typename V, typename Hash = splitmix64_hash> using hash_map = __gnu_pbds::gp_hash_table<K, V, Hash>; template <typename K, typename Hash = splitmix64_hash> using hash_set = hash_map<K, __gnu_pbds::null_type, Hash>; #define FOR(i,a,b) for(int i = (a); i <= (b); ++i) #define FORD(i,a,b) for(int i = (a); i >= (b); --i) #define RI(i,n) FOR(i,1,(n)) #define REP(i,n) FOR(i,0,(n)-1) #define mini(a,b) a=min(a,b) #define maxi(a,b) a=max(a,b) #define pb push_back #define st first #define nd second #define sz(w) (int) w.size() typedef vector<int> vi; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<pii, int> para; const ll inf = 1e18 + 7; const ll maxN = 1e6 + 5; const ll MOD = 1e9 + 7; bool cycle, has[maxN], visited[maxN]; vi graph[maxN]; int DFS(int x, int prv) { int ile = 1; visited[x] = true; for (auto v: graph[x]) { // cout << x << " " << prv << ": " << v << endl; if (!visited[v]) { ile += DFS(v, x); } else { if (v != prv) { cycle = true; } } } return ile; } // sprawdz MODULO! int main() { mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; int mx = 0; REP(i, n) { int a, b; cin >> a >> b; graph[a].pb(b); graph[b].pb(a); mx = max(mx, max(a, b)); has[a] = true; has[b] = true; } int ans = 0; RI(i, mx) { if (!has[i]) continue; if (!visited[i]) { int ile = DFS(i, -1); // cout << ile << " " << cycle << endl; ans += ile - !cycle; cycle = false; } } cout << ans; return 0; }
#include<iostream> #include<string> #include<cstring> #include<algorithm> #include<vector> #include<iomanip> #include<math.h> #include<complex> #include<queue> #include<deque> #include<stack> #include<map> #include<set> #include<bitset> #include<functional> #include<assert.h> #include<numeric> using namespace std; #define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i ) #define rep(i,n) REP(i,0,n) using ll = long long; const int inf=1e9+7; const ll longinf=1LL<<60 ; const ll mod=1e9+7 ; #define PI 3.141592653589793 //#include <atcoder/all> //using namespace atcoder; //using Mint = modint; struct UnionFind{ vector<int> par,siz; UnionFind(int N): par(N), siz(N){ rep(i, N){ par[i] = i; siz[i] = 1; } } int root(int x){ if(par[x]==x) return x; else return root(par[x]); } void unite(int x, int y){ x=root(x); y=root(y); if(x==y) return; if(siz[x] < siz[y]) swap(x, y); par[y] = x; siz[x] += siz[y]; } bool same(int x, int y){ return root(x)==root(y); } int size(int x){ return siz[root(x)]; } }; int main(){ int h, w; cin >> h >> w; string s[h]; UnionFind uf(2020); rep(i, h){ cin >> s[i]; } uf.unite(0, w-1); uf.unite(w, h+w-1); rep(i, h){ set<int> yoko; rep(j, w){ if((i==0 || i==h-1) && s[i][j]=='#'){ uf.unite(0, j); //cout << 0 << " " << j << endl; } if(s[i][j]=='#') yoko.insert(j); } auto itr = yoko.begin(); for(auto k: yoko){ uf.unite(*itr, k); //cout << *itr << " " << k << endl; } yoko.clear(); } rep(j, w){ set<int> tate; rep(i, h){ if((j==0 || j==w-1) && s[i][j]=='#'){ uf.unite(w, w+i); //cout << w << " " << w+i << endl; } if(s[i][j]=='#') tate.insert(w+i); } auto itr = tate.begin(); for(auto k: tate){ uf.unite(*itr, k); //cout << *itr << " " << k << endl; } tate.clear(); } set<int> ansa, ansb; rep(i, w){ ansa.insert(uf.root(i)); } for(int i=w; i<=h+w-1; i++){ ansb.insert(uf.root(i)); } cout << min(ansa.size()-1, ansb.size()-1) << endl; }
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<long long> VL; typedef vector<vector<long long>> VVL; typedef pair<int,int> Pair; typedef tuple<int,int,int> tpl; #define ALL(a) (a).begin(),(a).end() #define SORT(c) sort((c).begin(),(c).end()) #define REVERSE(c) reverse((c).begin(),(c).end()) #define EXIST(m,v) (m).find((v)) != (m).end() #define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin() #define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin() #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i) #define RREP(i,n) RFOR(i,n,0) #define en "\n" constexpr double EPS = 1e-9; constexpr double PI = 3.1415926535897932; constexpr int INF = 2147483647; constexpr long long LINF = 1LL<<60; constexpr long long MOD = 1000000007; // 998244353; 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;} void Main(){ int N; double D,H; cin >> N >> D >> H; VI d(N),h(N); REP(i,N) cin >> d[i] >> h[i]; double ng = 0, ok = 1000; REP(_,50){ double b = (ok+ng)/2; double a = (H-b)/D; bool flag = true; REP(i,N){ if(a*d[i]+b < h[i]){ flag = false; break; } } if(flag) ok = b; else ng = b; } cout << ok << en; return; } int main(void){ cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15); int t=1; //cin>>t; while(t--) Main(); 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, int> 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, k, a[800][800]; int comp(int x) { int sum[n + 1][n + 1]; rep(i, n + 1) sum[0][i] = 0; rep(i, n + 1) sum[i][0] = 0; rep(i, n) rep(j, n) sum[i + 1][j + 1] = sum[i][j + 1] + (a[i][j] >= x); rep(i, n - k + 1) { int tmp = 0; rep(j, k) tmp += sum[i + k][j] - sum[i][j]; rep(j, n - k + 1) { tmp += sum[i + k][j + k] - sum[i][j + k] - sum[i + k][j] + sum[i][j]; if (tmp < k * k / 2 + 1) return false; } } return true; } int main() { ci2(n, k); rep(i, n) rep(j, n) ci(a[i][j]); int l = 0, r = 1e9 + 1; while (r - l > 1) { int mid = (l + r) / 2; ((comp(mid)) ? l : r) = mid; } co(l); return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0;i<n;i++) const int INF = 1e9; int n,k; int a[805][805], s[805][805]; int binary_search(int key) { auto check = [&](int mid) { REP(i,n) REP(j,n) s[i+1][j+1] = a[i][j] > mid ? 1 : 0; REP(i,n+1) REP(j,n) s[i][j+1] += s[i][j]; REP(i,n) REP(j,n+1) s[i+1][j] += s[i][j]; REP(i,n-k+1) REP(j,n-k+1) { int now = s[i+k][j+k]; now -= s[i][j+k]; now -= s[i+k][j]; now += s[i][j]; if (now < key) return true; } return false; }; int ok = INF; int ng = -1; while(abs(ok-ng) > 1) { int mid = (ok+ng)/2; check(mid) ? ok = mid : ng = mid; } return ok; } int main() { cin >> n >> k; REP(i,n) REP(j,n) cin >> a[i][j]; int med = k * k / 2 + 1; cout << binary_search(med) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N; long long count[200] = {}; cin >> N; for (int i = 0; i < N; i++) { int A; cin >> A; count[A % 200]++; } long long result = 0; for (int i = 0; i < 200; i++) { result += (count[i] - 1) * count[i] / 2; } cout << result << endl; }
#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<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update> */ typedef long long ll; typedef long double ld; typedef unsigned long long ull; #define rep(i,a,b) for(ll i=a;i<=b;++i) #define rrep(i,a,b) for(ll i=a;i>=b;--i) #define FOR(i,n) for(ll i=0;i<n;i++) #define pb push_back #define mp make_pair #define PI 3.14159265358979323846 #define fi first #define se second #define all(x) x.begin(),x.end() #define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); const ll INF = 1e18+7; const ll mod = 1e9+7; const ll MAXN = 1e4+10; ll poww(ll a, ll b) { if(b<0) return 0LL; ll ans = 1; while (b) { if (b & 1)ans = ans * a; a = a * a; b >>= 1; } return ans; } ll binpow(ll a, ll b, ll m) { if (b < 0) return 0LL; if (a <= 0)return 0LL; a %= m; ll ans = 1LL; while (b) { if (b & 1)ans = ans * a % m; a = a * a % m; b >>= 1; } return ans; } ll modinv(ll n) { return binpow(n, mod - 2, mod); } void solve() { ll n; cin>>n; ll a[n]; FOR(i,n) cin>>a[i]; map<ll,ll> mt; ll ans = 0; for(ll i=0; i<n; i++) { ans += mt[a[i]%200]; mt[a[i]%200]++; } cout<<ans; } int main() { IOS; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif //ll no_of_test_cases; cin>>no_of_test_cases; ll no_of_test_cases = 1; //cout<<setprecision(15); for(ll i=1; i<=no_of_test_cases; i++) { solve(); } return 0; }
#include <iostream> #include <vector> #include <algorithm> #include <set> #include <queue> #include <stack> using namespace std; typedef long long ll; const ll mod = 1000 * 1000 * 1000 + 7; vector<ll> v; ll res = 0; struct edge { int u, v; ll w; edge() {} edge(int _u, int _v, ll _w) : u(_u), v(_v), w(_w) {} }; struct node { vector<edge> edges; }; struct graph { vector<node> nodes; int n; graph(int _n) : n(_n) { nodes.resize(n); } void add_edge(int u, int v, ll w) { nodes[u].edges.emplace_back(u, v, w); nodes[v].edges.emplace_back(v, u, w); } void dfs1(int cur, int prev, ll W) { v[cur] = W; for (edge& e : nodes[cur].edges) if (e.v != prev) { dfs1(e.v, cur, W ^ e.w); } } void dfs2(int cur, int prev, int cnt, ll W, bool inv = false) { ll cont = ((inv ? n - cnt : cnt) * (W % mod)) % mod; res = (res + cont) % mod; for (edge& e : nodes[cur].edges) { if (e.v == prev) { continue; } bool b = (e.w & W) != 0; dfs2(e.v, cur, cnt, W, inv ^ b); } } }; int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); int n; cin >> n; graph g(n); v.resize(n); for (int i = 1; i < n; i++) { int u, v; ll w; cin >> u >> v >> w; g.add_edge(--u, --v, w); } g.dfs1(0, -1, 0); for (int i = 0; i <= 60; i++) { int cnt = 0; ll W = 1ll << i; for (int j = 0; j < n; j++) if (v[j] & W) { cnt++; } g.dfs2(0, -1, cnt, W); } cout << (res * 500000004) % mod << '\n'; cin.ignore(2); return 0; }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define eb emplace_back #define x first #define y second #define FOR(i, m, n) for (ll i(m); i < n; i++) #define DWN(i, m, n) for (ll i(m); i >= n; i--) #define REP(i, n) FOR(i, 0, n) #define DW(i, n) DWN(i, n, 0) #define F(n) REP(i, n) #define FF(n) REP(j, n) #define D(n) DW(i, n) #define DD(n) DW(j, n) using ll = long long; using ld = long double; using pll = pair<ll, ll>; using tll = tuple<ll, ll, ll>; using vll = vector<ll>; using vpll = vector<pll>; using vtll = vector<tll>; using gr = vector<vll>; using wgr = vector<vpll>; void add_edge(gr&g,ll x, ll y){ g[x].pb(y);g[y].pb(x); } void add_edge(wgr&g,ll x, ll y, ll z){ g[x].eb(y,z);g[y].eb(x,z); } template<typename T,typename U> ostream& operator<<(ostream& os, const pair<T,U>& p) { cerr << ' ' << p.x << ',' << p.y; return os; } template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { for(auto x: v) os << ' ' << x; return os; } template <typename T> ostream& operator<<(ostream& os, const set<T>& v) { for(auto x: v) os << ' ' << x; return os; } template<typename T,typename U> ostream& operator<<(ostream& os, const map<T,U>& v) { for(auto x: v) os << ' ' << x; return os; } struct d_ { template<typename T> d_& operator,(const T& x) { cerr << ' ' << x; return *this;} } d_t; #define dbg(args ...) { d_t,"|",__LINE__,"|",":",args,"\n"; } #define deb(X ...) dbg(#X, "=", X); #define EPS (1e-10) #define INF (1LL<<61) #define YES(x) cout << (x ? "YES" : "NO") << endl; #define CL(A,I) (memset(A,I,sizeof(A))) #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() struct E { ll x,y,w; }; const ll MOD = 1e9+7; ll mod(ll a, ll b=MOD) { return ((a%b)+b)%b; } ll extended_euclid(ll a,ll b,ll &x,ll &y) { if (a == 0) { x = 0; y = 1; return b;} ll x1, y1; ll d = extended_euclid(b%a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return d; } ll mod_inverse(ll a, ll n=MOD) { ll x, y; ll d = extended_euclid(a, n, x, y); if (d > 1) return -1; return mod(x,n); } struct Mt { ll x = 0; Mt(){} Mt(ll y):x(mod(y)){} bool operator==(Mt &y){return x==y.x;} Mt operator+(Mt y){return mod(x+y.x);} Mt operator-(){return mod(-x);} Mt operator-(Mt y){return mod(x-y.x);} Mt operator*(Mt y){return mod(x*y.x);} Mt operator/(Mt y){return mod(x*mod_inverse(y.x));} Mt operator+=(Mt y){return x=(*this+y).x;} Mt operator-=(Mt y){return x=(*this-y).x;} Mt operator*=(Mt y){return x=(*this*y).x;} Mt operator/=(Mt y){return x=(*this/y).x;} }; ostream& operator<<(ostream& os, const Mt&m){ os << m.x; return os; } ll cnt[67]; void dfs(ll u, wgr &g, ll p=-1, ll on=0) { F(60) cnt[i]+=(on&(1ll<<i))?1:0; for(auto [v,w]: g[u]) if(v!=p) dfs(v,g,u, on^w); } int main(void) { ios_base::sync_with_stdio(false); ll n; cin >> n; wgr g(n); F(n-1) { ll u,v,w; cin >> u >> v >> w; u--; v--; add_edge(g, u,v,w); } dfs(0,g); ll ret = 0; F(60) { ll cur = cnt[i]; ret = mod(ret + mod(1ll<<i) * mod((cur) * (n-cur))); } cout << ret << endl; return 0; }
#include <bits/stdc++.h> #define rep(i,a,b) for(long long int i=a;i<b;i++) typedef long long int lli; using namespace std; void solve(){ lli n; cin>>n; if(n%2 != 0){ cout<<"Odd\n"; } else{ n=n/2; if(n%2 != 0){ cout<<"Same\n"; } else{ cout<<"Even\n"; } } } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin>>t; while(t--){ solve(); } return 0; }
#include <iostream> #include <string> using namespace std; int main() { string S; cin >> S; auto ans = "Yes"; for (size_t i = 0; i < S.length(); i++) { if (i % 2 == 0 && !islower(S[i])) ans = "No"; else if (i % 2 == 1 && islower(S[i])) ans = "No"; } cout << ans << endl; }
#pragma GCC optimize("O3") #pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math,inline") #pragma GCC target("sse4") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define mod 1000000007 #define pi 3.1415926535898 #define eps 1e-9 #define fast ios::sync_with_stdio(0); cin.tie(0);cout.tie(0) #define vt vector #define ar array #define fs first #define sc second #define pb push_back #define sp printf(" ") #define nl '\n' #define all(a) a.begin(),a.end() #define unique(c) (c).resize(unique(all(c)) - (c).begin()) #define sz(x) (int)(x).size() #define revsort(x) sort(all(x));reverse(all(x)) #define REP(i,start,end) for (int i = start; i <=end; i++) #define RREP(i,end,start) for (int i=end; i>=start ;i--) #define EACH(x, a) for (auto& x: a) typedef long long LL; typedef long double LD; typedef unsigned long long ULL; typedef pair<int, int> pii; typedef pair<LL, LL> pll; typedef pair<double, double> pdd; typedef vector<int> vi; typedef vector<LL> vll; typedef vector<double> vd; typedef vector<vector<LL> > matrix; typedef vector<vector<int> > graph; template<class A> void read(vt<A>& v); template<class A, size_t S> void read(ar<A, S>& a); template<class T> void read(T& x) { cin >> x; } void read(double& d) { string t; read(t); d=stod(t); } void read(long double& d) { string t; read(t); d=stold(t); } template<class H, class... T> void read(H& h, T&... t) { read(h); read(t...); } template<class A> void read(vt<A>& x) { EACH(a, x) read(a); } template<class A, size_t S> void read(array<A, S>& x) { EACH(a, x) read(a); } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int getRand(int l, int r) { uniform_int_distribution<int> uid(l, r); return uid(rng); } struct custom_hash { static uint64_t splitmix64(uint64_t x) { // http://xorshift.di.unimi.it/splitmix64.c x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; int add (LL var1, LL var2) { return ( (var1 % mod) + (var2 % mod) + mod) % mod; } int mul (LL var1, LL var2) { return (var1*var2) % mod; } int powm (LL x, LL y) { int ans = 1; while (y) { if (y & 1) { ans = mul(ans, x); } x = mul(x, x); y /= 2; } return ans; } int inv(LL x) { return powm(x, mod-2); } LL INF=1e9; void solve() { int n; read(n); vi a(n); read(a); int x = *min_element(all(a)); map <int, int> mp; REP (i, 0, n-1) { for (LL j = 1; j*j <= a[i]; j++) { if (a[i]%j) continue; mp[j] = __gcd(a[i], mp[j]); mp[a[i]/j] = __gcd(a[i], mp[a[i]/j]); } } int ans = 0; for (auto px : mp) { if (px.fs > x) break; if (px.fs == px.sc) ans++; } cout << ans << nl; } int main() { fast; solve(); }
#include <iostream> #include <bits/stdc++.h> using namespace std; #define mod 1000000007 #define pb(x) push_back(x); #define mp(x, y) make_pair(x, y) #define mem(dp, a) memset(dp, a, sizeof dp); #define all(a) a.begin(), a.end() #define sall(a) sort(all(a)) #define X first #define Y second typedef long long int ll; typedef pair<ll, ll> pp; #define debug(x) cout << #x << " :: " << x << "\n"; #define debug2(x, y) cout << #x << " :: " << x << "\t" << #y << " :: " << y << "\n"; #define debug3(x, y, z) cout << #x << " :: " << x << "\t" << #y << " :: " << y << "\t" << #z << " :: " << z << "\n"; #define boost \ ios_base::sync_with_stdio(false); \ 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 ordered_set tree<pp, null_type, less<pp>, rb_tree_tag, tree_order_statistics_node_update> ll power(ll b, ll exp) { ll res = 1; while (exp > 0) { if (exp % 2) { res = 1LL * res * b % mod; } b = 1LL * b * b % mod; exp /= 2; } return res; } int main() { boost; ll n; cin >> n; ll a[n], g = 0; for (ll i = 0; i < n; i++) cin >> a[i]; ll mn = *min_element(a, a+n); unordered_map<ll, ll> ma; ll ans = 1; for (ll i = 0; i < n; i++) { ll num = a[i]; for (ll j = 1; ((j*j) <= num)&&(j<mn); j++) { if ((num%j)==0) { ma[j] = __gcd(ma[j], a[i]); if( ((num/j)!=j)&&((num/j)<mn) ) ma[num / j] = __gcd(ma[num / j], a[i]); } } } for(auto it:ma) { ans += (it.first == it.second); } cout << ans; return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int a =0 , b=0 , c =0 , d=0; cin >> a>> b >> c >> d; cout << (a*d) - (b*c) <<endl; return 0;}
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);++i) #define repA(i,k,n) for(int i=k;i<=(n);++i) #define repD(i,k,n) for(int i=k;i>=(n);--i) #define endl '\n' #define print(b) for(auto a:b) cout<<a<<' '; #define printN(b) for(auto a:b) cout<<a<<endl; #define fin freopen("C:\\Users\\Nazmul Rahul\\Desktop\\in.txt", "r++", stdin) #define fout freopen("C:\\Users\\Nazmul Rahul\\Desktop\\out.txt", "w++", stdout) #define fastio ios::sync_with_stdio(false) #define max(a,b) ((a)>(b)?(a):(b)) #define min(a,b) ((a)<(b)?(a):(b)) #define pb push_back #define pob pop_back #define ll long long int using namespace std; int main() { #ifndef ONLINE_JUDGE fin; fout; #endif int ara[2][2]; for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) cin >> ara[i][j]; } cout << ((ara[0][0]*ara[1][1]) - (ara[0][1]*ara[1][0])); cout << endl; return 0; }
#include <bits/stdc++.h> #define mk make_pair #define fs first #define sc second using namespace std; typedef long long ll; typedef long double ld; int main(){ ll n; while(cin>>n){ ll ans=0, tmp1 = 3, tmp2 = 1, ans1 = -1, ans2 = -1; for(ll i = 1; tmp1<=n; tmp1*=3, ++i){ tmp2 = 5; for(ll j = 1; tmp2<=n-tmp1; ++j, tmp2*=5){ if(tmp2+tmp1==n){ ans1 = i; ans2 = j; break; } } if(ans1!=-1){ break; } } if(ans1==-1){ printf("-1\n"); } else{ printf("%lld %lld\n",ans1, ans2); } } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(){ ll N; cin >> N; for(ll i = 1; i <= 37; i++){ for(ll j = 1; j <= 37; j++){ if(powl(3,i)+powl(5,j)==N){cout<<i<<" "<<j<<endl;return 0;}; if(powl(5,i)+powl(3,j)==N==N){cout<<j<<" "<<i<<endl;return 0;}; } } cout << "-1" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define rep(i, n) for (ll i = 0; i < n; ++i) #define P pair<ll, ll> #define Graph vector<vector<ll>> #define fi first #define se second #define vvvll vector<vector<vector<ll>>> #define vvll vector<vector<ll>> #define vll vector<ll> constexpr ll INF = (1ll << 60); constexpr ll mod = 1000000007; constexpr double pi = 3.14159265358979323846; template <typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; } int main(){ ll n,m,t,a[1001],b[1001],x,k=0,time=0; cin>>n>>m>>t; rep(i,m){ cin>>a[i]>>b[i]; } x=n; rep(i,m){ x-=a[i]-time; if(x<=0){ k=1; break; } x+=b[i]-a[i]; if(x>n) x=n; time=b[i]; } x-=t-time; if(x<=0) k=1; if(k==1) cout<<"No"<<endl; else cout<<"Yes"<<endl; }
/* -------------------- | LOSER | | ~NOOBOSS~ | -------------------- */ #include <bits/stdc++.h> using namespace std; #define mxx LLONG_MAX #define mnn LLONG_MIN #define Y() cout<< "YES" <<endl #define N() cout << "NO"<<endl #define endl "\n" #define Ceil(x,y) ((x+y-1)/y) #define sz(s) (int)s.size() #define angle(x) double(x * acos(-1) / 180.0) #define max_3(a,b,c) max(a, max(b,c)) #define min_3(a,b,c) min(a, min(b,c)) #define gcd(a,b) __gcd(a,b) #define lcm(a,b) (a*b)/gcd(a,b) #define loser return 0 #define ll long long #define PI acos(-1) #define mem(a,v) memset(a,v,sizeof(a)) #define all(v) v.begin(),v.end() #define SORT(v) sort(v.begin(),v.end()) #define SRV(v) sort(v.rbegin(),v.rend()) #define REV(v) reverse(v.begin(),v.end()) #define B begin() #define E end() #define V vector #define F first #define S second #define PSB push_back #define MP make_pair #define flash cout.flush() #define InTheNameOfGod ios::sync_with_stdio(0);cin.tie(0); cout.tie(0); constexpr ll MOD = 998244353; constexpr ll mod = 1e9 + 7; int dx[] = {0,0,1,-1}; int dy[] = {1,-1,0,0}; /*-----*/ #define bug1(a) cerr<<a<<endl; #define bug2(a,b) cerr<<a<<" "<<b<<endl; #define bug3(a,b,c) cerr<<a<<" "<<b<<" "<<c<<endl; /*----*/ const ll N=3e5+5; vector<ll> adj[N]; ll power(ll n,ll p){if(p==0) return 1;if(p==1)return n;if(p%2)return power(n,p-1)*n;else{ll x=power(n,p/2);return x*x;}} ll modpow(ll a,ll b,ll m){ll ans=1;while(b){if(b&1)ans=(ans*a)%m;b/=2;a=(a*a)%m;}return ans;} ll nsum(ll num){return (num*(num+1))/2;} void edge (ll u,ll v) {adj[u].PSB(v) ;adj[v].PSB(u);} /*------------------START---------------------*/ /*-----*/ void solve(){ ll n,m,t,mah; cin>>mah>>m>>t; n=mah; ll pre=0; while(m--){ ll x,y; cin>>x>>y; mah-=(x-pre); if(mah<=0){ cout<<"No"<<endl; return; } pre=y; mah+=(y-x); mah=min(mah,n); } // bug1(mah); mah-=(t-pre); //bug1(mah); if(mah<=0){ cout<<"No"<<endl; return; } cout<<"Yes"<<endl; //cout << fixed << setprecision(10); } /*-----*/ int main(){ InTheNameOfGod ll Test=1; //cin>>Test; while(Test--){ solve(); } loser; } /////// C O D I N G I S L I F E ///////
#include <bits/stdc++.h> #define rep(i,n) for(ll i=0;i<n;++i) #define rrep(i, n) for(ll i=n-1;i>=0;--i) #define rep1(i, n) for(ll i=1; i<=n; ++i) #define repitr(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++) #define ALL(a) (a).begin(),(a).end() template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}} template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}} using namespace std; using ll = long long; using ull = unsigned long long; using pll = pair<ll, ll>; const ll MOD = 1e9 + 7; const ll LINF = 1LL << 60; const int INF = 1e9 + 7; const double PI = 3.1415926535897932384626433; int main(){ ll n; cin >> n; if(n % 2)cout << "Black"; else cout << "White"; }
#include <cstdio> using namespace std; int n; int main(){ scanf("%d",&n); if(n%2){ printf("Black\n"); }else{ printf("White\n"); } return 0; }
#include <iostream> #include <vector> #include <string> #include <regex> using namespace std; int main() { int N; cin >> N; string S; cin >> S; int Q; cin >> Q; string pre = S.substr(0, N); string post = S.substr(N); for (int i = 0; i < Q; ++i) { int t, a, b; cin >> t >> a >> b; if (t == 1) { a--; b--; if (b < N) { swap(pre[a], pre[b]); } else if (N <= a) { swap(post[a - N], post[b - N]); } else { swap(pre[a], post[b - N]); } } else { swap(pre, post); } } cout << pre << post << endl; }
#include <bits/stdc++.h> using namespace std; const int M=18; const int INF=0x3f3f3f3f; int x[M],y[M],z[M]; int d[M][M]; inline int dis(int i,int j) { return abs(x[i]-x[j])+abs(y[i]-y[j])+max(0,z[j]-z[i]); } int dp[1<<M][M]; int main() { int n; cin>>n; for(int i=0;i<n;i++) { cin>>x[i]>>y[i]>>z[i]; } for(int i=0;i<n;i++) for(int j=0;j<n;j++) d[i][j]=dis(i,j); for(int k=0;k<n;k++) for(int i=0;i<n;i++) for(int j=0;j<n;j++) d[i][j]=min(d[i][j],d[i][k]+d[k][j]); memset(dp,INF,sizeof(dp)); int mask=1<<n; dp[1][0]=0; for(int s=1;s<mask-1;s++) { for(int j=0;j<n;j++) { if(dp[s][j]==INF) continue; for(int k=0;k<n;k++) { if(s&(1<<k)) continue; dp[s^(1<<k)][k]=min(dp[s^(1<<k)][k],dp[s][j]+d[j][k]); } } } int ans=INF; for(int i=1;i<n;i++) { ans=min(ans,dp[mask-1][i]+d[i][0]); } printf("%d\n",ans); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++) #define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--) #define All(v) v.begin(), v.end() #define rAll(v) v.rbegin(), v.rend() template<class in_chmax> void chmax(in_chmax &x, in_chmax y) {x = max(x,y);} template<class in_chmin> void chmin(in_chmin &x, in_chmin y) {x = min(x,y);} void Yes() {cout << "Yes" << endl; exit(0);} void No() {cout << "No" << endl; exit(0);} template<class in_Cout> void Cout(in_Cout x) {cout << x << endl; exit(0);} template<class in_vec_cout> void vec_cout(vector<in_vec_cout> vec) { for (in_vec_cout res : vec) {cout << res << " ";} cout << endl; } const ll inf = 1e18; const ll mod = 1e9 + 7; int main() { ll N, M; cin >> N >> M; vector<ll> cnt(2); rep(i,N) { string S; cin >> S; ll v = 0; rep(j,M) if (S[j]-'0') v++; cnt[v%2]++; } ll ans = 1; rep(i,2) ans *= cnt[i]; Cout(ans); }
#include <iostream> #include <string> using namespace std; typedef long long ll; string s[100010]; ll cnt[1<<20] = {}; int main(){ int i,j,n,m; cin >> n >> m; ll od = 0,ev = 0; for(i=0;i<n;i++){ cin >> s[i]; int cnt = 0; for(j=0;j<m;j++) cnt += s[i][j] - '0'; if(cnt&1) od++; else ev++; } cout << od*ev << endl; }
// author: xay5421 // created: Sun Jun 13 00:10:43 2021 #ifdef xay5421 #define D(...) fprintf(stderr,__VA_ARGS__) #else #define D(...) ((void)0) //#define NDEBUG #endif #include<bits/stdc++.h> #define rep(i,a,b) for(int i=(a);i<=(b);++i) #define per(i,a,b) for(int i=(a);i>=(b);--i) using namespace std; typedef long long LL; LL n,f[90],dp[90][2],opt[90][2],dx[90],dy[90]; void sol0(int pos){ opt[pos][0]=1; per(i,pos-1,1){ opt[i][0]=opt[i+1][0]+(~i&1?opt[i+1][1]:0); opt[i][1]=opt[i+1][1]+(i&1?opt[i+1][0]:0); } LL rem=n-dp[pos][0]; rep(i,1,pos-1){ if(i&1){ while(opt[i][1]&&rem>=opt[i][1]){ ++dy[i]; rem-=opt[i][1]; } while(opt[i][0]&&rem>=opt[i][0]){ ++dx[i]; rem-=opt[i][0]; } }else{ while(opt[i][0]&&rem>=opt[i][0]){ ++dx[i]; rem-=opt[i][0]; } while(opt[i][1]&&rem>=opt[i][1]){ ++dy[i]; rem-=opt[i][1]; } } } D("rem=%lld\n",rem); dx[pos]+=rem; vector<int>ans; ans.push_back(1); ans.push_back(2); rep(i,1,pos){ if(i>1){ if(i&1)ans.push_back(4); else ans.push_back(3); } rep(_,1,dx[i])ans.push_back(1); rep(_,1,dy[i])ans.push_back(2); } cout<<ans.size()<<endl; for(int x:ans)printf("%d\n",x); } int main(){ f[0]=f[1]=1; rep(i,2,89)f[i]=f[i-1]+f[i-2]; scanf("%lld",&n); dp[1][0]=dp[1][1]=1; rep(i,2,89){ dp[i][0]=dp[i-1][0]+(~i&1?dp[i-1][1]:0); dp[i][1]=dp[i-1][1]+(i&1?dp[i-1][0]:0); } per(i,89,1){ if(dp[i][0]<=n){ sol0(i); return 0; } /*else{ sol1(i); }*/ } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; vector<int> ans; bool gcd(ll a, ll b, int c) { if (c < 0) return false; if (a == 0) { if (b > c) return false; for (int i = 0; i < b; ++i) { ans.push_back(2); } return true; } if (b == 0) { if (a > c) return false; for (int i = 0; i < a; ++i) { ans.push_back(1); } return true; } if (a > b) { if (gcd(a - b, b, c - 1)) { ans.push_back(3); return true; } return false; } if (gcd(a, b - a, c - 1)) { ans.push_back(4); return true; } return false; } int main() { ios::sync_with_stdio(false); cin.tie(0); ll n; cin >> n; std::mt19937_64 gen{0}; for (;;) { ll b = gen() % n; if (gcd(n, b, 130)) { break; } else if (gcd(b, n, 130)) { break; } } cout << ans.size() << endl; for (auto v: ans) { cout << v << endl; } }
#include<bits/stdc++.h> using namespace std; typedef unsigned long long ull; inline ull Hash(const string& s){ ull ans=0; for(auto c : s) ans=ans*26+c-'a'; return ans; } string s; int N; set<ull> s1,s2; inline void work(){ for(int i=1;i<=N;i++){ cin>>s; set<ull> &t1=(s[0]=='!'?s1:s2); set<ull> &t2=(s[0]!='!'?s1:s2); reverse(s.begin(),s.end()); if( *s.rbegin()=='!' ) s.pop_back(); ull val=Hash(s); if( t1.find(val)!=t1.end() ){ reverse(s.begin(),s.end()); cout<<s<<endl; return ; } else t2.insert(val); } cout<<"satisfiable"<<endl; } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>N; work(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; //const ll INF = numeric_limits<ll>::max() / 4; //const int INF = numeric_limits<int>::max() / 4; int main() { // ll N; string S; cin >> S; vector<int> A(10,-1); // -1:x, 0:? 1:o for(int i = 0; i < 10; i++){ if(S[i] == 'o') A[i] = 1; if(S[i] == '?') A[i] = 0; } int c = 0; bool f = true; vector<int> B(10,0); for(int i = 0; i < 10000; i++){ f = true; fill(B.begin(),B.end(),0); int n = i; for(int j = 0; j < 4; j++){ B[n % 10]++; n /= 10; } for(int j = 0; j < 10; j++){ if(A[j] == 1){ if(B[j] == 0) f = false; }else if(A[j] == -1){ if(B[j] > 0) f = false; } } if(f) c++; } cout << c << endl; return(0); }
#include <bits/stdc++.h> #include <numeric> using namespace std; #define int long long #define FOR(i, size) for (int i = 0; i < size; i++) #define all(x) x.begin(), x.end() #define endl "\n" #define MOD 1000000007 #define deb(...) logger(#__VA_ARGS__, __VA_ARGS__) template <typename... Args> void logger(string vars, Args &&...values) { cout << vars << " = "; string delim = ""; (..., (cout << delim << values, delim = ", ")); } template <typename T> void print_list(vector<T> collection, bool newline = true) { for (const auto &item : collection) { cout << item << " "; } if (newline) cout << endl; } #define ONE_TESTCASE 1 int n, m, timer; void Solve() { cin >> n; vector<pair<double, double>> v; FOR(i, n) { int t; cin >> t; double a, b; cin >> a >> b; if (t == 2) { b -= 0.1; } else if (t == 3) { a += 0.1; } else if (t == 4) { a += 0.1; b -= 0.1; } v.push_back({a, b}); } int cnt = 0; for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { if ((v[i].second >= v[j].first and v[i].first <= v[j].first) or (v[j].second >= v[i].first and v[i].first >= v[j].first)) cnt++; } } cout << cnt; } int32_t main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #if ONE_TESTCASE int test = 1; #else int test; cin >> test; #endif for (int t = 1; t <= test; t++) { Solve(); cout << endl; } }
#include<bits/stdc++.h> #define ll long long using namespace std; const int inf=1e9+7; const ll INF=1e18+7; int n,t; long double a[2001],b[2001]; bool intersect(int i,int j){ if(a[i]<=b[j]&&b[i]>=a[j]) return 1; return 0; } int main(){ cin>>n; for(int i=0;i<n;i++){ cin>>t>>a[i]>>b[i]; if(t>2) a[i]+=0.5; if(t%2==0) b[i]-=0.5; } int ans=0; for(int i=0;i<n-1;i++) for(int j=i+1;j<n;j++) if(intersect(i,j)) ans++; cout<<ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define mp make_pair #define pb push_back #define ll long long int #define sd(x) scanf("%lld",&x) #define sdi(x) scanf("%d",&x) #define sdc(c) scanf("%c",&c) #define inf 1000000000000000000ll #define pll pair<ll,ll> #define pii pair<int,int> #define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define bits(x) __builtin_popcountll(x) #define ld long double #define test() ll test; cin>>test; while(test--) #define fi first #define se second #define all(x) x.begin(),x.end() void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif clock_t time_p = clock(); void time_taken() { time_p = clock() - time_p; cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n"; } inline ll GCD(ll x, ll y) { if(x<y) swap(x,y); if(x==0) return y; if(y==0) return x; return GCD(x%y,y); } ll phi(ll n) { ll result = n; for (ll i = 2; i * i <= n; i++) { if(n % i == 0) { while(n % i == 0) n /= i; result -= result / i; } } if(n > 1) result -= result / n; return result; } ll power(ll x, ll n, ll mod) { ll res = 1; x %= mod; while(n) { if(n&1) { res = ((res*x)%mod+mod)%mod; } x = ((x*x)%mod+mod)%mod; n>>=1; } return res; } const int MOD = 1e9+7; inline ll add(ll x, ll y, ll MOD) { x %= MOD; y %= MOD; ll ans = (x+y)%MOD; return ans; } inline ll mul(ll x,ll y, ll MOD) { x %= MOD; y %= MOD; ll ans = ((x*y)%MOD+MOD)%MOD; return ans; } int main() { fastio; ll N, X; cin>>N>>X; ll ans = 0; ll V,P; int indx = -1; for(int i=1;i<=N;i++) { cin>>V>>P; ans += V*P; if(ans>X*100 && indx == -1) { indx = i; } } cout<<indx<<endl; time_taken(); }
#include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <sstream> #include <cstring> #include <string> #include <queue> #include <cstdio> #include <stack> #include <set> #include <map> #include <list> #include <iomanip> #include <utility> #include <tuple> #include <functional> #include <bitset> #include <cassert> #include <complex> #include <stdio.h> #include <time.h> #include <numeric> #include <unordered_map> #include <unordered_set> # define ll int64_t # define rep(i,n) for(ll i=0;i<n;i++) # define rrep(i,n) for(ll i=1;i<=n;i++) # define ALL(x) (x).begin(), (x).end() # define SZ(x) ((int)(x).size()) # define pb push_back # define mod 1000000007 # define PI 3.141592653589793 # define vec vector #define dump(x) cerr<<#x<<"="<<x<<endl using namespace std; const ll MAX = 510000; const ll MOD = 1000000007; ll fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < MAX; i++){ fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 ll COM(ll n, ll k){ if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } ll modpow(ll a,ll n) { ll res=1; while(n>0){ if(n&1) res=res*a%mod; a = a*a%mod; n >>= 1; } return res; } ll factorial(ll n){ ll x=1; rrep(i,n) x*=i; return x; } ll gcd(ll m,ll n){ if(n==0) return m; return gcd(n,m%n); } const long long INF = 1LL << 60; template<class T> void chmax(T& a,T b){ if(a<b){ a=b; } } template<class T> void chmin(T& a,T b){ if(a>b){ a=b; } } using Interval = pair<ll,ll>; bool cmp(const Interval &a,const Interval &b){ return a.second<b.second; } int main(){ cin.tie(0); ios::sync_with_stdio(false); ll n,m,b,fut=0; cin>>n>>m>>b; ll maxi=n; rep(i,m){ ll st,fi; cin>>st>>fi; n -= st-fut; if(n <= 0){ cout<<"No"<<endl; return 0; } if(n + fi-st > maxi) n = maxi; else n += fi-st; fut = fi; } n -= b-fut; if(n <= 0) cout<<"No"<<endl; else cout<<"Yes"<<endl; return 0; }
//#include<bits/stdc++.h> #include<iostream> #include<algorithm> #include<vector> #include<cmath> #include<numeric> // __GCD() #include<stack> #include<string.h> #include<math.h> #include<set> using namespace std; #define ll long long #define all(v) v.begin(),v.end() int main(){ ll r; double x,y; cin>>r>>x>>y; double a=sqrt(x*x+y*y); ll b=a; if(a-b==0){ if(b%r==0){ cout<<b/r<<endl; } else{ if(b<r) cout<<2<<endl; else cout<<b/r+1<<endl; } } else{ if(b<r) cout<<2<<endl; else cout<<b/r+1<<endl; } return 0; }
#include <bits/stdc++.h> int main() { int a, b; std::cin >> a >> b; for (int i = b - a; i > 0; i--) { int l = a / i * i; if (l < a) l += i; int r = b / i * i; if (r + i <= b) r += i; if (l < r) { std::cout << i << '\n'; break; } } }
#include <algorithm> #include <cmath> #include <cstdio> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> using namespace std; typedef long long ll; #define MOD 1000000007 int main() { int n; cin >> n; vector<ll> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } ll ans = 2e18; for (int bit = 0; bit < (1 << n); ++bit) { vector<ll> v; ll sum = 0; for (int i = 0; i < n; ++i) { if (bit >> i & 1) { v.push_back(sum); sum = a[i]; } else { sum |= a[i]; } } v.push_back(sum); ll res = 0; for (int i = 0; i < v.size(); ++i) { res ^= v[i]; } ans = min(ans, res); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using i8 = int8_t; using i16 = int16_t; using i32 = int32_t; using i64 = int64_t; using isize = ptrdiff_t; using u8 = uint8_t; using u16 = uint16_t; using u32 = uint32_t; using u64 = uint64_t; using usize = size_t; using f32 = float_t; using f64 = double_t; i32 n; vector<i64> a; i64 ans = 1e18; void solve(i32 p, i64 Or, i64 Xor) { if (p == n) { ans = min(Xor ^ Or, ans); return; } Or |= a[p]; solve(p + 1, Or, Xor); solve(p + 1, 0, Xor ^ Or); } auto main() -> i32 { ios::sync_with_stdio(false), cin.tie(nullptr); cin >> n; a.resize(n); for (auto& x : a) { cin >> x; } solve(0, 0, 0); cout << ans; cout << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define ls n << 1 #define rs n << 1 | 1 #define PB push_back #define MP make_pair #define LD double #define int long long #define LL long long #define pii pair<int, int> #define fi first #define se second const int N = 1e5; const int M = 300; const int mod = 1e9 + 7; const LL inf = 1e18; // inline char nc() { // static char buf[1000000], *p1 = buf, *p2 = buf; // return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin), p1 == p2) ? EOF : *p1++; // } // #define getchar nc inline int read() { int s = 0; register bool neg = 0; register char c = getchar(); for (; c < '0' || c > '9'; c = getchar()) neg |= (c == '-'); for (; c >= '0' && c <= '9'; s = s * 10 + (c ^ 48), c = getchar()) ; s = (neg ? -s : s); return s; } int a, b, h[2]; char s[N + 10][21]; signed main() { // freopen("in1.in", "r", stdin); // freopen("out.out", "w", stdout); a = read(); b = read(); int ans=0; for (int i = 1; i <= a; i++) { scanf("%s", s[i] + 1); int val=0; for (int j = 1; j <= b; j++) val ^= (s[i][j]=='1'); h[val]++; } printf("%lld", h[0]*h[1]); return 0; }
#include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <queue> #include <string> #include <map> #include <set> #include <stack> #include <tuple> #include <deque> #include <array> #include <numeric> #include <bitset> #include <iomanip> #include <cassert> #include <chrono> #include <random> #include <limits> #include <iterator> #include <functional> #include <sstream> #include <fstream> #include <complex> #include <cstring> #include <unordered_map> #include <unordered_set> using namespace std; using ll = long long; constexpr int INF = 1001001001; constexpr int mod = 1000000007; // constexpr int mod = 998244353; template<class T> inline bool chmax(T& x, T y){ if(x < y){ x = y; return true; } return false; } template<class T> inline bool chmin(T& x, T y){ if(x > y){ x = y; return true; } return false; } ll cnt[10000000]; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int N, M; cin >> N >> M; vector<string> s(N); for(int i = 0; i < N; ++i){ cin >> s[i]; cnt[stoi(s[i], nullptr, 2)] += 1; } ll ans = 0; ll odd = 0, even = 0; for(int mask = 0; mask < 1 << M; ++mask){ int popcnt = __builtin_popcount(mask); if(popcnt % 2 == 0){ even += cnt[mask]; } else{ odd += cnt[mask]; } } ans += odd * even; cout << ans << endl; return 0; }
#include"bits/stdc++.h" using namespace std; #define ll long long #define ul unsigned long long #define ui unsigned int #define ri register int #define pb push_back #define mp make_pair char p[30]={'0','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'}; inline ll rd(){ ll x=0,flag=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-') flag=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+(ch^48);ch=getchar();} return x*flag; } /* int wl,x,y,head[]; struct node{ int nxt,to; }star[]; inline void add(int from,int to){ wl++; star[wl].to=to; star[wl].nxt=head[from]; head[from]=wl; }*/ inline int lowbit(int x){return x & ( - x ) ;} ll n; map<ll,int>vis; int main() { n=rd(); ll lim=sqrt(n),ans=0; for(ll i=2;i<=lim;++i){ ll tmp=i; for(ri j=2;;++j){ tmp*=i;//cout<<i<<" "<<tmp<<endl; if(tmp>n) break; if(vis.find(tmp)==vis.end()) vis[tmp]=1,ans++; } } cout<<n-ans; return 0; }
#include <iostream> #define int long long using namespace std; const int N = 100000 + 7; int pd[N], prime[N]; int cnt; inline void diprime() { pd[0] = pd[1] = 1; for(int i=2; i<=N-7; i++) { if(!pd[i]) prime[++cnt]=i; for(int j=1; j<=cnt; j++) { if(prime[j] * i > N-7) break; pd[prime[j] * i] = 1; if(i%prime[j] == 0) break; } } return ; } int n, ans; bool nmsl[100007]; inline void doit(int x) { int now = x; for(int i=2; (now*=x)<=n; i++) { // now *= x; // if(pd[i]) continue; if(now <= 100000) nmsl[now] = 1; // cout << x << ' ' << i << ' ' << now << ' ' << nmsl[now] << '\n'; ans++; } return ; } signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); // diprime(); cin >> n; for(int i=2; i*i<=n; i++) { if(nmsl[i]) continue; doit(i); } cout << n - ans << '\n'; }
#include <iostream> #include <algorithm> #include <unordered_set> #include <set> #include <vector> #include <queue> #include <map> #include <numeric> #include <math.h> #include <complex> using namespace std; #define rep(i, n) for (long long int i = 0; i < (long long int)(n); i++) #define irep(i, n) for (long long int i = 1; i <= (long long int)(n); i++) #define drep(i, n, diff) for (long long int i = 0; i < (long long int)(n); i += diff) #define mod 1000000007 #define INF 100100100100100101 #define ld(val) printf("%s : %lld\n", #val, val); #define sd(val) printf("%s : %s\n", #val, val.c_str()); typedef long long int ll; typedef pair<ll, ll> P; typedef pair<P, P> PP; typedef tuple<ll, ll, ll> TP; vector<ll> to[200005]; vector<ll> lst[200005]; ll d[200005]; ll in[200005]; ll out[200005]; ll cnt; void dfs(ll n, ll cd) { in[n] = cnt; cnt++; lst[cd].push_back(in[n]); for(auto v: to[n]) { dfs(v, cd+1); } out[n] = cnt; } int main() { ll n; cin >> n; rep(i, n-1) { ll x; cin >> x; to[x-1].push_back(i+1); } dfs(0, 0); ll q; cin >> q; rep(i, q) { ll u, d; cin >> u >> d; --u; ll l = lower_bound(lst[d].begin(), lst[d].end(), out[u]) - lst[d].begin(); ll r = lower_bound(lst[d].begin(), lst[d].end(), in[u]) - lst[d].begin(); printf("%lld\n", l-r); } return 0; }
#include <bits/stdc++.h> #define int long long using namespace std; const int MOD=1e9+7; typedef pair<pair<int,int>,pair<int,int>> pii; const int N = 200005; int n,q,root=1,dis[N]; vector<int> G[N]; vector<pii> Ques; int L[N],R[N],TIME=0; int calc_QUAI(int x){ return x/sqrt(n); } bool cmp(pii a, pii b){ if(calc_QUAI(a.first.first)!=calc_QUAI(b.first.first)) return calc_QUAI(a.first.first)<calc_QUAI(b.first.first); return a.first.second<b.first.second; } void dfs(int now,int dep){ L[now]=TIME++; dis[L[now]]=dep; for(int next:G[now]) dfs(next,dep+1); R[now]=TIME-1; } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin >> n; for(int i=1;i<n;++i){ int p; cin >> p; G[p].push_back(i+1); } dfs(root,0); cin >> q; Ques.resize(q); for(int i=0;i<q;++i){ int u,d; cin >> u >> d; Ques[i]={{L[u],R[u]},{d,i}}; } sort(Ques.begin(),Ques.end(),cmp); int LL=0,RR=0; vector<int> COUNT; COUNT.resize(n); vector<int> ans; ans.resize(q); COUNT[dis[L[0]]]++; for(int i=0;i<q;++i){ while(RR<Ques[i].first.second){ ++RR; COUNT[dis[RR]]++; } while(RR>Ques[i].first.second){ COUNT[dis[RR]]--; --RR; } while(LL<Ques[i].first.first){ COUNT[dis[LL]]--; ++LL; } while(LL>Ques[i].first.first){ --LL; COUNT[dis[LL]]++; } ans[Ques[i].second.second]=COUNT[Ques[i].second.first]; } for(int i=0;i<q;++i) cout << ans[i] << '\n'; return 0; }
// @Date : 2021-06-05 19:00:19 // @Author : raj lath ([email protected]) // @Link : link // @Version : 1.0.0 #include <bits/stdc++.h> using namespace std; #define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define ll long long #define MOD 1000000007 #define mod 9982444353 #define rep(i, n) for(int i = 0; i < (n); ++i) #define trav(a, x) for(auto& a : x) #define all(x) x.begin(), x.end() #define sz(x) (int)(x).size() void solve() { } int main() { FIO; ll a, b, c; cin >> a >> b >> c; int answer = 0; if (a == b) answer = c; else if (a == c) answer = b; else if (b == c) answer = a; cout<<answer<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int A,B,C; cin>>A>>B>>C; if(C==0){ A=A-1; if(A<B){ cout<<"Aoki"<<endl; } else{ cout<<"Takahashi"<<endl; } } else{ B=B-1; if(B<A){ cout<<"Takahashi"<<endl; } else{ cout<<"Aoki"<<endl; } } }
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll h, w, a, b; ll count(vector<ll> mas, ll aed, ll bed, ll now){ /* cout << now << endl; for(int i=0;i<w*h;i++) cout << mas[i] << " "; cout << endl; */ if(aed<0 || bed<0) return 0; if(now == h*w) return 1; if(mas[now]!=0) return count(mas, aed, bed, now+1); mas[now]=1; ll c = count(mas, aed, bed-1, now+1); if((now+1)%w!=0 && mas[now+1]==0){ mas[now+1] = 1; c += count(mas, aed-1, bed, now+1); mas[now+1] = 0; } if((now+w)<w*h){ mas[now+w] = 1; c += count(mas, aed-1, bed, now+1); mas[now+w] = 0; } return c; } int main(){ cin >> h >> w >> a >> b; vector<ll> A(w*h, 0); cout << count(A, a, b, 0) << endl; return 0; }
#include <bits/stdc++.h> #define LL long long #define db double #define mp make_pair #define x first #define y second #define vi vector<int> #define SZ(a) (int)((a).size()) using namespace std; const int N = 1e5 + 10; int k, n, m, id[N]; LL a[N], b[N], c[N]; int cmp(int x, int y) { return abs(c[x] - a[x]) < abs(c[y] - a[y]); } void quit() { for(int i = 1; i <= k; i++) printf("%lld ", b[i] / n); printf("\n"); exit(0); } int main() { scanf("%d%d%d", &k, &n, &m); int L = 0, R = 0; for(int i = 1; i <= k; i++) { scanf("%lld", &a[i]); a[i] *= m; LL l = a[i] / n * n, r = (a[i] / n + 1) * n; if(abs(l - a[i]) > abs(r - a[i])) swap(l, r); L += l / n, R += l / n; b[i] = l; c[i] = r; id[i] = i; } sort(id + 1, id + k + 1, cmp); if(L <= m && m <= R) quit(); for(int i = 1; i <= k; i++) { int x = id[i]; if(m < L) { if(c[x] > b[x]) continue; b[x] = c[x], L--; } else { if(c[x] < b[x]) continue; b[x] = c[x], R++; } if(L <= m && m <= R) quit(); } return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long int #define ld long double #define MOD 1000000007 #define endl "\n" #define pb push_back #define mp make_pair #define ff first #define ss second #define all(var) (var).begin(), (var).end() #define sz(x) (int)x.size() #define MAXX 9000000000000000000 #define pii pair<int,int> #define vi vector<int> #define vvi vector<vector<int> > #define vpi vector<pair<int,int> > #define vvpi vector<vector<pair<int,int> > > int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int n,s,d,fl=0; cin >> n >> s >> d; while(n--) { int x,y; cin >> x >> y; if(x < s && y > d) { cout << "Yes"; return 0; } } cout << "No\n"; return 0; }
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <cstdint> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <memory> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <valarray> #include <vector> #if __has_include(<string_view>) #include <string_view> #endif #if __has_include(<optional>) #include <optional> #endif #if __has_include(<any>) #include <any> #endif #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; //---------------------------------------------------------- template <class T, class U> istream& operator>>(istream& is, pair<T, U>& pair) { is >> pair.first >> pair.second; return is; } template <class T> istream& operator>>(istream& is, vector<T>& collection) { for (auto& item : collection) is >> item; return is; } template <class T> istream& operator>>(istream& is, valarray<T>& collection) { for (auto& item : collection) is >> item; return is; } template <class T> T peak_and_pop(std::queue<T>& q) { assert(!q.empty()); T t = move(q.front()); q.pop(); return t; } template <class T> T peak_and_pop(std::priority_queue<T>& q) { assert(!q.empty()); T t = move(q.top()); q.pop(); return t; } template <class T> T peak_and_pop(std::stack<T>& q) { assert(!q.empty()); T t = move(q.top()); q.pop(); return t; } //---------------------------------------------------------- void solution() { int n,x; cin >> n >> x; string s; cin >> s; assert(s.length() == n); int score = x; for(char c : s){ score = max(0, score + (c == 'o' ? 1 : -1)); } cout << score << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(10); solution(); return 0; }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; using LL = long long; using VI = vector<int>; using VVI = vector<VI>; using VLL = vector<LL>; using VVLL = vector<VLL>; using VS = vector<string>; using PII = pair<int,int>; using PLL = pair<LL,LL>; using VPI = vector<PII>; using VPL = vector<PLL>; using VB = vector<bool>; using VVB = vector<VB>; #define REP(i,m,n) for(LL i=(m);i<(n);i++) #define RREP(i,m,n) for(int i=(m);i>=(n);i--) int main(){ LL n,k,ans=0; cin >> n >> k; REP(ab,2,2*n+1){ LL cd = ab - k; if(2<=cd && cd<=2*n){ LL count_ab = min(ab-1, 2*n-ab+1); LL count_cd = min(cd-1, 2*n-cd+1); ans += count_ab * count_cd; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll,ll> PP; #define MOD 1000000007 //#define MOD 998244353 #define INF 2305843009213693951 //#define INF 810114514 #define PI 3.141592653589 #define setdouble setprecision #define REP(i,n) for(ll i=0;i<(n);++i) #define OREP(i,n) for(ll i=1;i<=(n);++i) #define RREP(i,n) for(ll i=(n)-1;i>=0;--i) #define all1(i) begin(i),end(i) #define GOODBYE do { cout << "-1" << endl; return 0; } while (false) #define MM <<" "<< #define Endl endl #define debug true #define debug2 false ll R,C; class Dijkstra{ /* Copyright (c) 2021 0214sh7 https://github.com/0214sh7/library/ */ private: typedef std::pair<long long,int> P; std::vector<std::vector<P>> G; int V; //long long INF = (1LL<<61); std::priority_queue<P,std::vector<P>,std::greater<P>> que; public: void init(int N,std::vector<std::pair<std::pair<int,int>,long long>> edge){ //頂点数を決定する V=N; //辺集合を扱いやすい形式に変換する G.resize(V); for(int i=0;i<edge.size();i++){ int from=edge[i].first.first,to=edge[i].first.second; long long cost=edge[i].second; G[from].push_back({cost,to}); } } Dijkstra(int N,std::vector<std::pair<std::pair<int,int>,long long>> edge){ init(N,edge); } std::vector<long long> solve(int s){ std::vector<long long> d; //INFで初期化する for(int i=0;i<V;i++){ d.push_back(INF); } d[s]=0; que.push({0,s}); //queは{cost,to}をコストが小さい順に出す while(!que.empty()){ P p = que.top(); que.pop(); int v=p.second; if(d[v]<p.first)continue; for(int i=0;i<G[v].size();i++){ P e = G[v][i]; if(d[e.second]>d[v]+e.first){ d[e.second] = d[v]+e.first; que.push({d[e.second],e.second}); } } //新造 for(ll i=1;v-i*C>=0;i++){ if(d[v-i*C]>d[v]+1+i){ d[v-i*C] = d[v]+1+i; que.push({d[v-i*C],v-i*C}); } } } return d; } }; int main(void){ vector<vector<ll>> A,B; cin >> R >> C; A.resize(R); B.resize(R-1); REP(i,R){ REP(j,C-1){ ll a; cin >> a; A[i].push_back(a); } } REP(i,R-1){ REP(j,C){ ll b; cin >> b; B[i].push_back(b); } } vector<pair<pair<int,int>,long long>> E; REP(i,R){ REP(j,C-1){ E.push_back({ {i*C+j,i*C+j+1},A[i][j]}); E.push_back({ {i*C+j+1,i*C+j},A[i][j]}); } } REP(j,C){ REP(i,R-1){ E.push_back({ {i*C+j,(i+1)*C+j},B[i][j]}); } } Dijkstra dijkstra(R*C,E); vector<ll> D = dijkstra.solve(0); /* REP(i,R*C){ cout << D[i] << " "; if((i+1)%C==0)cout << endl; }*/ cout << D[R*C-1] << endl; return 0; }
#include <iostream> #include <string> constexpr int MAX = 30; long long dp[MAX + 1][MAX + 1]; std::string find_kth(int A, int B, long long K) { if (A == 0) { return std::string(B, 'b'); } if (B == 0) { return std::string(A, 'a'); } if (K <= dp[A - 1][B]) { return std::string("a") + find_kth(A - 1, B, K); } else { return std::string("b") + find_kth(A, B - 1, K - dp[A - 1][B]); } } int main() { int A, B; long long K; std::cin >> A >> B >> K; dp[0][0] = 1; for (int i = 0; i <= A; ++i) { for (int j = 0; j <= B; ++j) { if (i > 0) { dp[i][j] += dp[i - 1][j]; } if (j > 0) { dp[i][j] += dp[i][j - 1]; } } } std::cout << find_kth(A, B, K) << '\n'; return 0; }
#include <iostream> #include <algorithm> #include <string> // nCr static long long Combination(int n, int r) { if (n < r) return 0; if ((r * 2) > n) r = n - r; long long ans = 1; for (int up = 1, down = n; up <= r; up++, down--) { ans = ans * down / up; } return ans; } using namespace std; int main(void) { int A, B; cin >> A >> B; long long K; cin >> K; int AB = A + B; int leftA = A; int pos = 0; string ans = ""; long long anspos = 0; while (pos < AB) { if (leftA <= 0) { ans += 'b'; pos++; continue; } long long low = Combination(AB - pos -1, leftA - 1); long long hi = Combination(AB - pos -1, leftA); if (anspos + low < K) { anspos += low; ans += 'b'; } else { ans += 'a'; leftA--; } pos++; } cout << ans << endl; return 0; }
#pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target("avx,avx2,sse,sse2") #pragma comment(linker, "/stack:200000000") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define int long long #define pb push_back #define pf push_front #define eb emplace_back #define mp make_pair #define all(v) (v).begin(),(v).end() #define rall(v) (v).rbegin(),(v).rend() #define f first #define s second #define sz(x) (int)x.size() #define endl "\n" #define forn(i,n) for(int i=0;i<n;++i) #define fore(i,l,r) for(int i=int(l);i<=int(r);++i) #define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++) #define fill(a,value) memset(a,value,sizeof(a)); #define gcd(a,b) __gcd((a),(b)) #define watch1(x) cout<<(x)<<endl #define watch2(x,y) cout<<(x)<<" "<<(y)<<endl #define watch3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl #define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count()); 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 tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset; const int INF = 9e18; const int mod = 998244353; const int N = 2e5 + 5; int i, n, a[N], b[N], p[N], vis[N]; void solve() { cin >> n; vpii w, ans; for (i = 1; i <= n; i++) { cin >> a[i]; w.pb({a[i], i}); } for (i = 1; i <= n; i++) { cin >> b[i]; } map<int, int> have, mp; for (i = 1; i <= n; i++) { cin >> p[i]; have[p[i]] = i; mp[i] = p[i]; } for (i = 1; i <= n; i++) { if (i != p[i] && a[i] <= b[p[i]]) { cout << -1 << endl; return; } } int cnt = 0; for (i = 1; i <= n; i++) { if (!vis[i]) { int v = i; cnt++; while (!vis[v]) { vis[v] = 1; v = p[v]; } } } cout << n - cnt << endl; sort(all(w)); for (i = 1; i <= n; i++) { if (mp[w[i - 1].s] == w[i - 1].s) { continue; } int give = mp[w[i - 1].s], get = have[w[i - 1].s]; ans.pb({w[i - 1].s, get}); have[give] = get; mp[get] = give; } assert(sz(ans) == n - cnt); for (auto &i : ans) { cout << i.f << " " << i.s << endl; } } signed main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fastio; int t; //cin >> t; t = 1; while (t--) { solve(); } return 0; }
/* the vast starry sky, bright for those who chase the light. */ #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; #define mk make_pair const int inf=(int)1e9; const ll INF=(ll)5e18; const int MOD=998244353; int _abs(int x){return x<0 ? -x : x;} int add(int x,int y){x+=y; return x>=MOD ? x-MOD : x;} int sub(int x,int y){x-=y; return x<0 ? x+MOD : x;} #define mul(x,y) (ll)(x)*(y)%MOD void Add(int &x,int y){x+=y; if(x>=MOD) x-=MOD;} void Sub(int &x,int y){x-=y; if(x<0) x+=MOD;} void Mul(int &x,int y){x=mul(x,y);} int qpow(int x,int y){int ret=1; while(y){if(y&1) ret=mul(ret,x); x=mul(x,x); y>>=1;} return ret;} void checkmin(int &x,int y){if(x>y) x=y;} void checkmax(int &x,int y){if(x<y) x=y;} void checkmin(ll &x,ll y){if(x>y) x=y;} void checkmax(ll &x,ll y){if(x<y) x=y;} #define out(x) cerr<<#x<<'='<<x<<' ' #define outln(x) cerr<<#x<<'='<<x<<endl #define sz(x) (int)(x).size() inline int read(){ int x=0,f=1; char c=getchar(); while(c>'9'||c<'0'){if(c=='-') f=-1; c=getchar();} while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar(); return x*f; } const int N=500005; int n,a[N],b[N],p[N],id[N],pos[N]; bool cmp(int x,int y){return a[x]<a[y];} vector<pii> ans; int main() { n=read(); for(int i=1;i<=n;i++) a[i]=read(); for(int i=1;i<=n;i++) b[i]=read(); for(int i=1;i<=n;i++) p[i]=read(),pos[p[i]]=i; for(int i=1;i<=n;i++) if(i!=p[i]&&a[i]<=b[p[i]]){puts("-1"); return 0;} for(int i=1;i<=n;i++) id[i]=i; sort(id+1,id+n+1,cmp); for(int i=1;i<=n;i++){ int u=id[i]; if(u==p[u]) continue; int from=pos[u]; ans.push_back(mk(from,u)); pos[p[u]]=from; swap(p[from],p[u]); } printf("%d\n",sz(ans)); for(auto &u : ans) printf("%d %d\n",u.first,u.second); return 0; }
#include <bits/stdc++.h> using namespace std; string rev(string a){//aのAとBを反転させたやつを返す for(auto &p:a)p^='A'^'B'; return a; } int main(){ int n;cin>>n; vector<vector<string>> s(n+1);//s[i]:n=iの時の答え for(int i=0;i<n;i++){ for(string p:s[i]){ s[i+1].push_back(p+p); s[i+1].push_back(p+rev(p)); } s[i+1].push_back(string(1<<i,'A')+string(1<<i,'B')); } cout<<s[n].size()<<endl; for(string p:s[n])cout<<p<<endl; }
//#include <atcoder/math> #include <bits/stdc++.h> using namespace std; //using namespace atcoder; #define INF_LL 100000000000000000LL #define INF 2000000000 #define MOD 998244353 #define ll long long #define all(x) x.begin(), x.end() #define REP(i, a, b) for(int i = a; i < b; i++) #define rep(i, n) REP(i, 0, n) // typedef float double; // typedef priority_queue prique; typedef pair<ll, ll> P; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<P> vp; typedef vector<ll> vl; typedef vector<vi> matrix; int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; int sign[2] = {1, -1}; 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(a > b) { a = b; return 1; } return 0; } ll modpow(ll a, ll b, ll m) { if(b == 0) return 1; ll t = modpow(a, b / 2, m); if(b & 1) { return (t * t % m) * a % m; } else { return t * t % m; } } struct edge { int to; ll cost; edge(int t, ll c) { to = t, cost = c; } }; typedef vector<vector<edge>> graph; // using mint = modint998244353; char inv(char c){ if(c == 'A') return 'B'; return 'A'; } vector<string> solve(int n){ if(n == 1){ return {"AB"}; } vector<string> t = solve(n - 1); vector<string> res(t.size() * 2 + 1); rep(i, t.size()){ rep(j, t[i].size()){ res[i * 2] += t[i][j]; res[i * 2] += t[i][j]; res[i * 2 + 1] += t[i][j]; res[i * 2 + 1] += inv(t[i][j]); } } rep(i, t.size() * 2 + 2){ int cnt = 0; rep(j, res.size() - 1){ if(res[j][i] == 'A') cnt++; } if(cnt != t.size()){ res[res.size()-1]+='A'; }else{ res[res.size()-1]+='B'; } } return res; } int main() { ll n; cin >> n; vector<string> ans = solve(n); int k = ans.size(); vector<vector<int>> c(ans[0].size(), vector<int>(ans[0].size())); cout << k << endl; rep(i, k){ string res = ans[i]; cout << res << endl; rep(i, res.size()) REP(j, i + 1, res.size()) {if(res[i] == res[j])c[i][j]++;} } // int t = c[0][1]; // rep(i, n) REP(j, i + 1, n) { // if(c[i][j] != t){ // cout << i << " " << j << " " << c[i][j] << endl; // } // } return 0; }
#include<cstdio> #include<iostream> using namespace std; int n; int x[101],y[101]; //int t[1001]; int t; int maxn,minn=9999; int main() { scanf("%d",&n); for(int a=1;a<=n;a++) scanf("%d",&t),maxn=max(maxn,t); for(int a=1;a<=n;a++) scanf("%d",&t),minn=min(minn,t); /*for(int a=1;a<=n;a++) { t[x[a]]--; t[y[a]]++; } for(int a=1;a<=1000;a++) { //printf("t[%d]:%d\n",a,t[a]); t[a]+=t[a-1]; if(t[a]==-n) { printf("%d",a); return 0; } } printf("0"); */ printf("%d",(minn-maxn+1>=0)?(minn-maxn+1):0); return 0; }
#include <bits/stdc++.h> #define maxn 100086 using namespace std; int a, b; int main(){ scanf("%d%d", &a, &b); if(a > b){ int sum = 0; for(int i = 1;i <= a;i++) sum += i, printf("%d ", i); for(int i = 1;i < b;i++) sum -= i, printf("%d ", -i); printf("%d", -sum); }else{ int sum = 0; for(int i = 1;i <= b;i++) sum += i, printf("%d ", -i); for(int i = 1;i < a;i++) sum -= i, printf("%d ", i); printf("%d", sum); } }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++) #define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--) #define all(v) v.begin(), v.end() void chmax(ll &x, ll y) {x = max(x,y);} void chmin(ll &x, ll y) {x = min(x,y);} void Yes() {cout << "Yes" << endl; exit(0);} void No() {cout << "No" << endl; exit(0);} template<class in_Cout> void Cout(in_Cout x) {cout << x << endl; exit(0);} template<class in_vec_cout> void vec_cout(vector<in_vec_cout> vec) { for (in_vec_cout res : vec) {cout << res << " ";} cout << endl; } const ll inf = 1e18; const ll mod = 1e9 + 7; using matrix = vector<vector<ll>>; ll powmodp(ll x, ll n) { if (n==0) return 1; if (n%2) return x * powmodp(x,n-1) % mod; ll res = powmodp(x,n/2); return res * res % mod; } ll inv(ll x) {return powmodp(x,mod-2);} ll N, M, K; vector<ll> A, G[110]; ll p, half; matrix E(ll n) { matrix res(n,vector<ll>(n)); rep(i,n) res[i][i] = 1; return res; } void addmodp(ll &x, ll y) {x = (x + y) % mod;} matrix prodmatrix(matrix x, matrix y) { ll H = x.size(), W = y[0].size(), sz = y.size(); matrix res(H,vector<ll>(W)); rep(i,H) rep(j,W) rep(k,sz) { addmodp(res[i][j], x[i][k] * y[k][j] % mod); } return res; } vector<ll> prodmatrix(matrix x, vector<ll> y) { matrix z(y.size(),vector<ll>(1)); rep(i,y.size()) z[i][0] = y[i]; matrix tmp = prodmatrix(x,z); vector<ll> res(tmp.size()); rep(i,tmp.size()) res[i] = tmp[i][0]; return res; } vector<ll> prodmatrix(vector<ll> x, matrix y) { matrix z(1,vector<ll>(x.size())); rep(i,x.size()) z[0][i] = x[i]; matrix tmp = prodmatrix(z,y); vector<ll> res(tmp[0].size()); rep(i,tmp[0].size()) res[i] = tmp[0][i]; return res; } matrix powmodp(matrix x, ll n) { if (n==0) return E(x.size()); if (n%2) return prodmatrix(x,powmodp(x,n-1)); matrix res = powmodp(x,n/2); return prodmatrix(res,res); } void init() { cin >> N >> M >> K; A.resize(N); rep(i,N) cin >> A[i]; rep(i,M) { ll x, y; cin >> x >> y; x--; y--; G[x].push_back(y); G[y].push_back(x); } p = inv(M); half = inv(2); } int main() { init(); matrix mat(N,vector<ll>(N)); rep(i,N) { ll cnt = G[i].size(); for (ll j : G[i]) mat[i][j] = p * half % mod; ll q = cnt * p % mod; q = q * half % mod; mat[i][i] = (1 + mod - q) % mod; } matrix F = powmodp(mat,K); vector<ll> res = prodmatrix(F,A); for (ll ans : res) cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define int long long namespace math{ const int MOD = 1e9+7; const int MN = 10'100; int fact[MN], inv_fact[MN]; int power(int a, int n) { int res = 1; for (;n; n >>= 1, a = (a * a) % MOD) if (n & 1) res = (res * a) % MOD; return res; } int inv(int a) { return inv_fact[a]*fact[a-1]%MOD; } void init_fact() { fact[0]=1; for (int i=1;i<MN;++i) fact[i] = fact[i-1]*i%MOD; inv_fact[MN-1] = power(fact[MN-1], MOD - 2); for (int i=MN-1; i>0;--i) inv_fact[i-1]=inv_fact[i]*i%MOD; } struct mint { int n; mint(int n): n(n){} mint(): n(0){} mint operator+(mint o){return (n + o.n) % MOD;} mint operator-(mint o){return (n - o.n % MOD + MOD) % MOD;} mint operator*(mint o){return (n * o.n) % MOD;} mint operator/(mint o){return o.n >= MN ? n * power(o.n, MOD - 2) % MOD : n * inv(o.n) % MOD;} }; }; using namespace math; using mat = vector<vector<mint>>; int n, m, k; vector<int> g[100]; mat M; mat operator*(mat A, mat B) { mat ret(A.size(), vector<mint>(B[0].size())); for (int i = 0; i < A.size(); ++i) { for (int j = 0; j < B[0].size(); ++j) { for (int k = 0; k < B.size(); ++k) ret[i][j] = ret[i][j] + A[i][k] * B[k][j]; } } return ret; } mat power(mat A, int n) { mat ret(A.size(), vector<mint>(A.size())); for (int i = 0; i < A.size(); ++i) ret[i][i] = 1; for (; n; A = A * A, n >>= 1) { if (n & 1) ret = ret * A; } return ret; } signed main() { cin.tie(0)->sync_with_stdio(false); cin>>n>>m>>k; M.resize(n, vector<mint>(n)); mat A(1, vector<mint>(n)); for (int i = 0; i< n;++i) cin>>A[0][i].n; for (int i = 0; i<m;++i) { int u, v; cin>>u>>v; --u, --v; g[u].push_back(v); g[v].push_back(u); } init_fact(); for (int i = 0; i < n;++i) { M[i][i] = mint(1) - mint(g[i].size()) / m / 2; for (int it: g[i]) { M[it][i] = mint(1) / m / 2; } } mat Ans = A * power(M, k); for (int i = 0; i<n;++i) cout << Ans[0][i].n << '\n'; return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <numeric> #include <vector> int main(void){ int a, b, c, d; std::cin >> a >> b >> c >> d; std::cout << a * d - b * c << std::endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int A, B; cin >> A >> B; cout << (2 * A + 100) - B << endl; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using ull = unsigned long long; using P = pair<int, int>; const int INF = 1e9; const int MOD = 1000000007; const int dx[] = {-1,0,1,0}; const int dy[] = {0,-1,0,1}; //const int dx[] = {-1,-1,-1, 0, 0, 1, 1, 1}; const int dy[] = {-1, 0, 1,-1, 1,-1, 0, 1}; #define PI 3.14159265358979323846264338327950L //cout << fixed << setprecision(10) << Min << endl << Max << endl; int main() { ll N; cin >> N; if (N < 8) { cout << "-1" << endl; return 0; } ll ans5 = 0, ans3 = 0; ll tmp = 1; while (1) { tmp = tmp * 5; ll tmp2 = N - tmp; if (tmp2 < 3) { cout << "-1" << endl; return 0; } ans5++; ans3 = 0; while (tmp2 % 3 == 0) { tmp2 /= 3; ans3++; } if (tmp2 > 1) continue; else break; } cout << ans3 << " " << ans5 << endl; }
#include <bits/stdc++.h> using namespace std; int main() { // int t {0}; // cin >> t; // while (t--) // { int l {0}; cin >> l; // long long int ans = C((long long int) l - 1, (long long int) 11); // cout << ans << endl; vector < vector <long long int> > C (l, vector <long long int> (12)); C[0][0] = 1; for (int i = 1; i < 12; i++) { C[1][i] = 0; } for (int i = 1; i < l; i++) { C[i][0] = 1; for (int j = 1; j < 12; j++) { C[i][j] = C[i - 1][j] + C[i - 1][j - 1]; } } long long int ans = C[l - 1][11]; cout << ans << endl; // } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define fr(i,j,k) for(int i=j;i<k;i++) #define f(n) fr(i,0,n) #define f1(n) fr(i,1,n+1) #define pb push_back #define F first #define S second #define all(x) x.begin(), x.end() const int mod = 998244353; const int maxn = 400005; ll fac[55]; int d[55]; int v[55][55]; int fi(int x) { return d[x] < 0 ? x : d[x] = fi(d[x]); } void merge(int x,int y) { x = fi(x); y = fi(y); if (x == y) return; d[x] += d[y]; d[y] = x; } void go() { int n, tar; cin >> n >> tar; fac[0] = 1; f1(50) { fac[i] = fac[i - 1] * i % mod; } f1(n) { fr(j,1,n+1) { cin >> v[i][j]; } } memset(d, -1, sizeof(d)); fr(j,1,n+1) { fr(k,1,n+1) { int f = 0; fr(i,1,n+1) { if (v[i][j] + v[i][k] > tar) { f = 1; break; } } if (!f) { merge(j,k); } } } ll ans = 1; f1(n) { if (d[i] < 0) { ans *= fac[-d[i]]; ans %= mod; } } memset(d, -1, sizeof(d)); //f1(n) { fr(j,1,n+1) { fr(k,1,n+1) { int f = 0; fr(i,1,n+1) { if (v[j][i] + v[k][i] > tar) { f = 1; break; } } if (!f) { merge(j,k); } } } //} f1(n) { if (d[i] < 0) { ans *= fac[-d[i]]; ans %= mod; } } cout << ans << '\n'; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int c = 0; int t; if (!c) { t = 1; } else { cin >> t; } while (t--) { go(); } }
//un_coder #include<bits/stdc++.h> typedef long long ll; #define all(a) a.begin(),a.end() #define MOD 1000000007 #define inf 1e18 using namespace std; void solve(); int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("error.txt", "w", stderr); freopen("output.txt", "w", stdout); #endif ll t=1; //cin>>t; while(t--) { solve(); //cout<<"\n"; } cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl; return 0; } void solve() { int n,q; cin>>n>>q; vector<ll> a(n),low(n); for(auto &it:a) cin>>it; for(int i=0; i<n; i++) low[i]=a[i]-(i+1); for(int i=0; i<q; i++) { ll k; cin>>k; int idx=lower_bound(all(low),k)-low.begin(); if(idx==n) cout<<a[n-1]+(k-low[n-1])<<"\n"; else cout<<a[idx]-(low[idx]-k+1)<<"\n"; } }
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define ordered_set tree<ll, null_type , less<ll> , rb_tree_tag , tree_order_statistics_node_update> #define int long long int #define ull unsigned long long #define pb push_back #define inf 1e18 #define mk make_pair #define ld long double #define mod 1000000007 #define fi first #define se second #define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define test int t; cin>>t; while(t--) #define setbits __builtin_popcount #define endl '\n' #define LOCAL #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 imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " #define maxn 200001 vector<vector<pair<int,int>>>v(maxn); vector<int>pre(maxn); void dfs(int x,int p,int w) { int val=w; if(p!=0) { val=val^pre[p]; } pre[x]=val; for(auto itr:v[x]) { if(itr.fi!=p) { dfs(itr.fi,x,itr.se); } } } int32_t main() { fastIO; int n; cin>>n; int x,y,val,val1,ans=0; for(int i=0;i<n-1;i++) { cin>>x>>y>>val; v[x].pb({y,val}); v[y].pb({x,val}); } dfs(1,0,0); vector<vector<int>>suf(n+1,vector<int>(61)); for(int i=n;i>=1;i--) { for(int j=0;j<=60;j++) { val1=(int)1<<j; if(val1&pre[i]) { suf[i][j]++; } } if(i<n) { for(int j=0;j<=60;j++) { suf[i][j]+=suf[i+1][j]; } } } for(int i=1;i<n;i++) { for(int j=0;j<=60;j++) { x=n-suf[i+1][j]-i-1; int val1=(int)1<<j; if(val1&pre[i]) { x++; val=val1%mod; val=(x*val)%mod; ans=(ans+val)%mod; } else{ val=val1%mod; val=(suf[i+1][j]*val)%mod; ans=(ans+val)%mod; } } } cout<<ans<<endl; }
#include<bits/stdc++.h> #define FORz(i,t,n) for(int i=t;i<=n;i++) #define FORf(i,n,t) for(int i=n;i>=t;i--) #define SCC(x) scanf("%d",&x) #define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0) typedef long long ll; using namespace std; const int N=1e5+5; const ll MOD=1e9+7; // inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}return x*f;} //ll pow1(ll a,ll b){ll r=1;while(b){if(b&1)r=r*a;a=a*a;b>>=1;}return r;} ll pow2(ll a,ll b,ll mod){ll r=1;while(b){if(b&1)r=r*a%mod;a=a*a%mod;b>>=1;}return r%mod;} //ll gcd(ll a,ll b){ll m=a%b;while(m){a=b;b=m;m=a%b;}return b;} void exgcd(ll a, ll b, ll &d, ll &x, ll &y){if(!b) { d = a; x = 1; y = 0;}else { exgcd(b, a % b, d, y, x); y -= x * (a / b); }} ll inv(ll a){ll d, x, y;exgcd(a, MOD, d, x, y);return d == 1 ? (x + MOD) % MOD : -1;}struct node{ll mat[105][105];};node mul(node x,node y,int n,ll mod){node tmp;for(int i=0;i<n;i++)for(int j=0;j<n;j++){tmp.mat[i][j]=0;for(int k=0;k<n;k++)tmp.mat[i][j]+=(x.mat[i][k]*y.mat[k][j])%mod;tmp.mat[i][j]%=mod;}return tmp;} // node matpow(node x,node y,ll num,int n,ll mod){while(num){if(num&1){y=mul(x,y,n,mod);}x=mul(x,x,n,mod);num=num>>1;}return y;} //for(ll i=2;i<N-1;i++){if(!a[i]) b[++cnt]=i;for(ll j=1;j<=cnt&&i*b[j]<N;j++){a[i*b[j]]=1;if(i%b[j]==0) break;}} //int find(int x){return a[x]==x?x:a[x]=find(a[x]);} //void merge(int x,int y){a[find(y)]=a[find(x)];} ll n,q,t,a,b,z; string s,j; int main() { int n; cin>>n>>s>>q; j=s.substr(n,n)+s.substr(0,n); while(q--){ cin>>t>>a>>b; a--,b--; if(t==1){ char x=s[(a+z*n)%(2*n)]; s[(a+z*n)%(2*n)]=s[(b+z*n)%(2*n)]; s[(b+z*n)%(2*n)]=x; x=j[(a+!z*n)%(2*n)]; j[(a+!z*n)%(2*n)]=j[(b+!z*n)%(2*n)]; j[(b+!z*n)%(2*n)]=x; } else{ z=!z; } } z?cout<<j:cout<<s; }
#include <bits/stdc++.h> using namespace std; #pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define REP(i, n) for (int i = 1; i <= (int)(n); i++) #define repi(i, s, n) for (int i = (s); i < (int)(n); i++) #define all(x) (x).begin(), (x).end() #define uniqueV(x) \ sort(x.begin(), x.end()); \ x.erase(unique(x.begin(), x.end()), x.end()); #define debug(x) cerr << #x << ": " << x << '\n' #define debug2(x, y) \ cerr << "(" << #x << ", " << #y << ") = " \ << "(" << x << ", " << y << ")" << '\n' typedef long long int ll; typedef pair<int, int> P; const long long INF = 3e18 + 12; const int inf = 1e9; // ---------------------------------------------- int main() { ios::sync_with_stdio(false); cin.tie(0); int a, b, w; cin >> a >> b >> w; w *= 1000; int ans_min = inf; int ans_max = 0; bool flag = false; repi(i, 1, 1e6 + 1) { if (a * i <= w && w <= b * i) { ans_min = min(ans_min, i); ans_max = max(ans_max, i); flag = true; } } if (flag) { cout << ans_min << " " << ans_max << endl; } else { cout << "UNSATISFIABLE" << endl; } return 0; }
#include <bits/stdc++.h> #define pb push_back #define eb emplace_back #define all(v) (v).begin(), (v).end() typedef int64_t ll; typedef uint64_t ull; using namespace std; void one_case() { int n; cin >> n; vector<ll> a(n), b(n); for (auto& el : a) cin >> el; for (auto& el : b) cin >> el; ll A = a[0], B = 0; vector<ll> S; S.pb(a[0] * b[0]); for (int i = 1 ; i < n; ++i) { A = max(A, a[i]); S.pb(max(S[i - 1], b[i] * A)); } for (auto& el : S) { cout << el << "\n"; } } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int t = 1; // cin >> t; for (int i = 0; i < t; ++i) { one_case(); } return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) #define rrep(i,n) for(int i = 1; i <= (n); ++i) using namespace std; typedef long long ll; typedef pair<int,int>P; const int INF = 1001001001; int main() { ll n; cin >> n; ll x = 1000; ll ans = 0; while(n+1 >= x){ ans += n-(x-1); x *= 1000; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> //#include <atcoder/all> using namespace std; // using namespace atcoder; struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); } } fast; typedef long long ll; typedef pair<ll, ll> P; long long mod = 1000000007; #define REP(i, n) for (long long i = 0; i < (n); i++) #define rep(i, a, n) for (long long i = a; i < (n); i++) long long modpow(long long m, long long n, long long modvalue) { if (n == 0) return 1; if (n % 2 == 0) { long long t = modpow(m, n / 2, modvalue); return t * t % modvalue; } else { return modpow(m, n - 1, modvalue) * m % modvalue; } } long long pow(long long m, long long n) { if (n == 0) return 1; if (n % 2 == 0) { long long t = pow(m, n / 2); return t * t; } else { return pow(m, n - 1) * m; } } bool bitcheck(ll x, ll y) { return (x >> y) & 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); } // long long mod = 998244353; long long moddiv(long long a, long long b, ll modvalue) { return (a * modpow(b, mod - 2, modvalue)) % modvalue; } const ll INF = 1LL << 60; void print_binary(long long a) { for (int i = 31; i >= 0; i--) { cout << (a >> i & 1); } cout << endl; } ll nCkmod(ll n, ll k, ll modvalue) { ll numera = 1; for (int i = n; i > n - k; i--) { numera *= i; numera %= modvalue; } ll denomi = 1; REP(i, k) { denomi *= (i + 1); denomi %= modvalue; } return moddiv(numera, denomi, modvalue); } map<ll, ll> cnt; void primeFactors(long long n) { while (n % 2 == 0) { cnt[2]++; n = n / 2; } for (int i = 3; i <= sqrt(n); i = i + 2) { while (n % i == 0) { cnt[i]++; n = n / i; } } if (n > 2) { cnt[n]++; } } // using mint = modint1000000007; struct UnionFind { vector<int> parent, size; UnionFind(int n) { parent.resize(n, -1); size.resize(n, 1); } void unite(int x, int y) { if (same(x, y)) { return; } x = root(x); y = root(y); if (size[x] <= size[y]) { swap(x, y); } parent[y] = x; size[x] += size[y]; } bool same(int x, int y) { return (root(x) == root(y)); } int root(int x) { while (parent[x] != -1) { x = parent[x]; } return x; } int getsize(int x) { return size[root(x)]; } }; vector<vector<ll>> adj; bool warfloyd(vector<vector<ll>> graph) { adj = graph; for (int k = 0; k < graph.size(); k++) { for (int i = 0; i < graph.size(); i++) { for (int j = 0; j < graph.size(); j++) { adj[i][j] = min(adj[i][j], adj[i][k] + adj[k][j]); } } } REP(i, graph.size()) { if (adj[i][i] != 0) { return true; } } return false; } #define DEBUG(x) cerr << #x << ": " << x << endl int main() { ll n; cin >> n; if (n < 1000) { cout << 0 << endl; } else if (n < 1000000) { cout << n - 1000 + 1 << endl; } else if (n < 1000000000) { cout << 1000000 - 1000 + 2 * (n - 1000000 + 1) << endl; } else if (n < 1000000000000) { cout << 1000000 - 1000 + 2 * (1000000000 - 1000000) + 3 * (n - 1000000000 + 1) << endl; } else if (n < 1000000000000000) { cout << 1000000 - 1000 + 2 * (1000000000 - 1000000) + 3 * (1000000000000 - 1000000000) + 4 * (n - 1000000000000 + 1) << endl; } else { cout << 1000000 - 1000 + 2 * (1000000000 - 1000000) + 3 * (1000000000000 - 1000000000) + 4 * (n - 1000000000000 + 1) + 1 << endl; } }
/* * @Author: FuTianyu * @Date: 2021-01-30 20:04:16 * @Last Modified by: FuTianyu * @Last Modified time: 2021-01-30 20:10:50 */ #include<bits/stdc++.h> using namespace std; #define FOR(i,a,b) for(int i=a;i<=b;i++) #define REP(i,a,b) for(int i=a;i>=b;i--) inline int read(){ int sum=0,ff=1; char ch=getchar(); while(!isdigit(ch)){ if(ch=='-') ff=-1; ch=getchar(); } while(isdigit(ch)) sum=sum*10+(ch^48),ch=getchar(); return sum*ff; } inline void write(int x){ if(x==0){ putchar('0'); return ; } char F[200]; int tmp=x>0?x:-x,cnt=0; if(x<0) putchar('-'); while(tmp>0) F[cnt++]=tmp%10+'0',tmp/=10; while(cnt>0) putchar(F[--cnt]); } int main(){ int a=read(),b=read(),c=read(); int sum=0; if(c==0){ while(1){ if(a==0){ cout<<"Aoki"; return 0; } if(b==0){ cout<<"Takahashi"; return 0; } sum++; sum%=2; if(sum==1) a--; else b--; } } if(c==1){ while(1){ if(b==0){ cout<<"Takahashi"; return 0; } if(a==0){ cout<<"Aoki"; return 0; } sum++; sum%=2; if(sum==0) a--; else b--; } } return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define endl '\n' #define maxn 300010 const int MOD = 1000000007; int ar[maxn], tree[4 * maxn]; int doit(int a, int b) { return a ^ b; } void build(int start, int end, int index = 1) { if (start == end) { tree[index] = ar[start]; return; } int mid = start + end >> 1; build(start, mid, 2 * index); build(mid + 1, end, 2 * index + 1); tree[index] = doit(tree[2 * index], tree[2 * index + 1]); } int queryTree(int start, int end, int l, int r, int index = 1) { if (r < start or l > end) return 0; if (l <= start and r >= end) return tree[index]; int mid = start + end >> 1; return doit(queryTree(start, mid, l, r, 2 * index), queryTree(mid + 1, end, l, r, 2 * index + 1)); } void update(int start, int end, int x, int val, int index) { if (x < start or x > end) return; if (start == end) { tree[index] ^= val; return; } int mid = start + end >> 1; update(start, mid, x, val, 2 * index); update(mid + 1, end, x, val, 2 * index + 1); tree[index] = doit(tree[2 * index], tree[2 * index + 1]); } void solve() { int n, q; cin >> n >> q; for (int i = 0; i < n; ++i) { cin >> ar[i]; } build(0, n - 1); for (int i = 0; i < q; ++i) { int t, x, y; cin >> t >> x >> y; if (t == 1) { update(0, n - 1, x - 1, y, 1); } else { cout << queryTree(0, n - 1, x - 1, y - 1, 1) << endl; } } } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int t = 1; // cin >> t; while (t--) solve(); return 0; }
#include<bits/stdc++.h> using namespace std; typedef double db; const int N = 1e5 + 5; int n, m, k; db ans = 0; db a[N]; db b[N]; bool vis[N]; int main() { cin >> n >> m >> k; for (int i = 1; i <= k; ++i) { int t; cin >> t; vis[n-t] = 1; } db ans1 = 0, ans2 = 0; for (int i = 1; i <= n; ++i) { if (vis[i]) { a[i] = 1, b[i] = 0; } else { a[i] = ans1 / m; b[i] = ans2 / m + 1; } ans1 += a[i], ans2 += b[i]; if (i >= m) { ans1 -= a[i - m]; ans2 -= b[i - m]; } } if (abs(a[n] - 1.0) < 1e-6)puts("-1"); else printf("%.4lf\n", b[n] / (1.0 - a[n])); }
#include <bits/stdc++.h> using ll = long long; using namespace std; #define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++) #define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++) #define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--) #define rreps(i, n) for (int i = ((int)(n)); i > 0; i--) #define repi(i, x) \ for (auto i = (x).begin(), i##_fin = (x).end(); i != i##_fin; i++) #define all(x) (x).begin(), (x).end() #define F first #define S second #define mp make_pair #define mt make_tuple #define pb push_back #define eb emplace_back typedef vector<int> Vi; typedef vector<Vi> VVi; typedef pair<int, int> Pi; typedef vector<Pi> VPi; typedef vector<long long> V; typedef vector<V> VV; typedef vector<VPi> VVPi; typedef pair<long long, long long> P; typedef vector<P> VP; 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 chmin(pair<T, T>& a, pair<T, T> b) { if (max(a.F, a.S) > max(b.F, b.S)) { a = b; return 1; } return 0; } 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) { #ifdef LOCAL os << "{"; #endif rep(i, v.size()) { if (i) os << " "; os << v[i]; } #ifdef LOCAL os << "}"; #endif return os; } template <class T, class U> istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; } template <class T> istream& operator>>(istream& is, vector<T>& v) { rep(i, v.size()) { is >> v[i]; } return is; } const long long INFLL = 1LL << 60; const int INF = 1 << 30; const double PI = acos(-1); #ifdef LOCAL #define dbg(x) cerr << #x << ": " << (x) << '\n' #define say(x) cerr << (x) << '\n' #else #define dbg(x) #define say(x) #endif void init_main() { cin.tie(nullptr); ios::sync_with_stdio(false); #ifdef LOCAL if (freopen("in.txt", "r", stdin) == NULL) { cerr << "no inputfile found" << '\n'; } if (freopen("out.txt", "w", stdout) == NULL) { cerr << "no outputfile found" << '\n'; } if (freopen("err.txt", "w", stderr) == NULL) { cerr << "no errputfile found" << '\n'; } #endif } string solve(bool a) { return ((a) ? "Yes" : "No"); } int main() { init_main(); int n; int ans = INF; cin >> n; Vi t(n); cin >> t; int sum = 0; rep(i, n) { sum += t[i]; } VVi dp(n + 1, Vi(sum / 2 + 5, 0)); dp[0][0] = 1; rep(i, n) { rep(j, sum / 2 + 2) { if (dp[i][j]) { dp[i + 1][j] = 1; if (j + t[i] < sum / 2 + 1) { dp[i + 1][j + t[i]] = 1; } } } } dbg(dp); rep(i, sum / 2 + 3) { if (dp[n][i]) chmin(ans, max(i, sum - i)); } cout << ans << endl; } /* n^2 -> nT dp[at][flag]->(a,b) */