code_file1
stringlengths
87
4k
code_file2
stringlengths
82
4k
#include <iostream> #include <string> #include <algorithm> #include <vector> using namespace std; int main() { int A, B; cin >> A >> B; int limit = A * 2 + 100; cout << limit - B; return 0; }
#include <bits/stdc++.h> using namespace std; int main () { int a; int b; int c; cin >> a >> b >> c; int sum; sum = (7 - a) + (7 - b) + (7 - c); cout << sum; }
#include<bits/stdc++.h> using namespace std; // @author: sharad_sharma #define ll long long #define ld long double #define mod 1000000007 #define inf 1e18 #define pb push_back #define all(n) n.begin(),n.end() #define loop(i,a,b) for(int i=(a);i<=(b);i++) #define logarr(arr) for(int z=(0);z<(arr.size());z++) cout<<(arr[z])<<" ";cout<<endl; #define deb(x) cout << #x << " = " << x << endl #define debu(x, y) cout << "( " << #x << ", " << #y << " ) = ( " << x << ", " << y << " )" << endl mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define int long long void file_i_o() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int N = 25; vector<vector<int>> adj(N); vector<int> visited(N, 0); vector<int> col(N, 0); vector<int> level(N, 0); // i want to search exhaustively int dfs(int i, int p) { //if(visited[i]) return 1; level[i] = level[p] + 1; visited[i] = 1; int ret = 1; for(auto u: adj[i]) { //if(u == p) continue; // this is not enough if their level is same then it must return 0 if(level[u] != 0 && level[u] != level[i] + 1) { if(col[u] == col[i]) { // this should not be allowed return 0; } continue; } int tem = 0; for(int c=1; c<4; c++) { if(col[i] == c) continue; col[u] = c; tem += dfs(u, i); col[u] = 0; } ret *= tem; } return ret; } int32_t main(int32_t argc, char const *argv[]) { clock_t begin = clock(); file_i_o(); // Write your code here.... int n, m; cin >> n >> m; for(int i=0; i<m; i++) { int x, y; cin >> x >> y; x--; y--; adj[x].pb(y); adj[y].pb(x); } int ans = 1LL; for(int i=0; i<n; i++) { if(visited[i]) continue; // let's say we colour Red on i so, it's edges is either blue or green col[i] = 1; // let's say Red is 1 level[i] = 0; int dd = dfs(i, i); ans = ans*3LL*dd; } cout << ans << "\n"; #ifndef ONLINE_JUDGE clock_t end = clock(); cout<<"\n\nExecuted In: "<<double(end - begin) / CLOCKS_PER_SEC*1000<<" ms"; #endif return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long const ll MAX =1000000000000000000; ll mod= 1000000000; long double pi=3.141592653589793238; void pls() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); #endif } ll n,m,k; vector<pair<ll,ll>> p,temp; ll recursion(int i,vector<int> &visi){ if(i==k) { ll tot=0; for(i=0;i<p.size();i++){ if(visi[p[i].first] && visi[p[i].second]) tot++; } return tot; } visi[temp[i].first]+=1; ll val=recursion(i+1,visi); visi[temp[i].first]-=1; visi[temp[i].second]+=1; ll val1=recursion(i+1,visi); visi[temp[i].second]-=1; return max(val,val1); } void solve() { cin>>n>>m; for(int i=0;i<m;i++){ ll x,y; cin>>x>>y; p.push_back({x,y}); } cin>>k; for(int i=0;i<k;i++){ ll x,y; cin>>x>>y; temp.push_back({x,y}); } vector<int> visi(n+1,0); cout<<recursion(0,visi)<<endl; } int main(){pls(); solve(); return 0;} /* Mostly wrong answer form base case or overflow or runtime Debug--> check overflow---> check varible name---> check logic implementation----> check logic */
#include<bits/stdc++.h> #define Imposter ios_base::sync_with_stdio(false);cin.tie(NULL); #define pb push_back #define ll long long int #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #pragma GCC optimize("O3") using namespace __gnu_pbds; #define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind) using namespace std; #define f(n) for(ll i=0;i<n;i++) #define rep(i,a,b) for(ll i=a;i<b;i++) #define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1] #define endl "\n" #define vll vector<ll> #define vlll vector<vll> #define all(x) x.begin(),x.end() ll power(ll x, ll y, ll p) { ll res = 1; x = x % p; while(y > 0) { if(y & 1) res = (res*x) % p; y = y>>1; x = (x*x) % p; } return res; } inline void solve() { ll n,x; cin>>n>>x; string s; cin>>s; f(s.length()) { if(s[i]=='o') x++; else if(x>0) x--; } cout<<x<<endl; } int main() { Imposter int t=1; //cin>>t; while(t--) { solve(); } return 0; }
#include <bits/stdc++.h> //#include <boost/multiprecision/cpp_int.hpp> //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> #pragma GCC optimize("O3") #define REP(i,n) for(int i=0;i<n;i++) #define REPP(i,n) for(int i=1;i<=n;i++) #define ALL(obj) (obj).begin(), (obj).end() #define EPS (1e-9) #define INF (1e17) #define PI (acos(-1)) //const double PI = acos(-1); //const double EPS = 1e-15; //long long INF=(long long)1E17; #define i_7 (long long)(1e9+7) //#define i_7 998'244'353 long mod(long a){ long long c=a%i_7; if(c>=0)return c; return c+i_7; } long long po(long a, long b){ if(b==0){ return 1; } long long z = po(a,b/2); z = mod(z*z); if(b%2!=0){ z = mod(a*z); } return z; } bool prime_(int n){ if(n==1){ return false; }else if(n==2){ return true; }else{ for(int i=2;i<=std::sqrt(n);i++){ if(n%i==0){ return false; } } return true; } } long long gcd_(long long a, long long b){ if(a<b){ std::swap(a,b); } if(a%b==0){ return b; }else{ return gcd_(b,a%b); } } long long lcm_(long long x, long long y){ return (x/gcd_(x,y))*y; } //using namespace std; //using namespace boost::multiprecision; //using namespace __gnu_pbds; int main(){ using namespace std; int n,k,m; cin>>n>>k>>m; int a[n-1]; int s = 0; REP(i,n-1){ cin>>a[i]; s += a[i]; } int r = n*m - s; if(r > k){ cout<<-1<<endl; return 0; } r = max(0, r); cout<<r<<endl; return 0; }
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cmath> #include <vector> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <queue> #include <ctime> #include <cassert> #include <complex> #include <string> #include <cstring> #include <chrono> #include <random> #include <bitset> #include <fstream> using namespace std; #define int long long #define ii pair <int, int> #define app push_back #define all(a) a.begin(), a.end() #define bp __builtin_popcountll #define ll long long #define mp make_pair #define x first #define y second #define Time (double)clock()/CLOCKS_PER_SEC #define debug(x) std::cerr << #x << ": " << x << '\n'; #define FOR(i, n) for (int i = 0; i < n; ++i) #define FORN(i, n) for (int i = 1; i <= n; ++i) #define pb push_back #define trav(a, x) for (auto& a : x) using vi = vector<int>; template <typename T> std::istream& operator >>(std::istream& input, std::vector<T>& data) { for (T& x : data) input >> x; return input; } template <typename T> std::ostream& operator <<(std::ostream& output, const pair <T, T> & data) { output << "(" << data.x << "," << data.y << ")"; return output; } template <typename T> std::ostream& operator <<(std::ostream& output, const std::vector<T>& data) { for (const T& x : data) output << x << " "; return output; } ll div_up(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up ll div_down(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // divide a by b rounded down ll math_mod(ll a, ll b) { return a - b * div_down(a, b); } #define tcT template<class T #define tcTU tcT, class U tcT> using V = vector<T>; tcT> void re(V<T>& x) { trav(a, x) cin >> a; } tcT> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } // set a = min(a,b) tcT> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } ll gcd(ll a, ll b) { while (b) { tie(a, b) = mp(b, a % b); } return a; } signed main() { #ifdef LOCAL #else #define endl '\n' ios_base::sync_with_stdio(0); cin.tie(0); #endif int n; cin >> n; vi a(2 * n); cin >> a; vi sign(2 * n); V <ii> ord; FOR (i, 2 * n) { ord.app(mp(a[i], i)); } sort(all(ord)); FOR (i, n) { sign[ord[i].y] = -1; } FOR (i, n) { sign[ord[i + n].y] = 1; } string ans; vi S; trav (e, sign) { if (S.empty() || S.back() == e) { ans += '('; S.app(e); } else { ans += ')'; S.pop_back(); } } assert(S.empty()); cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #pragma optimize("-O3") #define int long long int #define f first #define s second #define pb push_back #define endl '\n' const int N=4e5+5; bool bl[N]; int arr[N]; vector<char>ans; main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin>>n; vector<pair<int, int>>vec; for(int i=0; i<2*n; i++){ int x; cin>>x; vec.pb({x, i}); } sort(vec.begin(), vec.end()); for(int i=0; i<n; i++){ bl[vec[i].s]=1; } stack<int>st; ans.resize(2*n); for(int i=0; i<2*n; i++){ if(!st.empty() && (bl[i]^bl[st.top()])==1){ ans[i]=')'; ans[st.top()]='('; st.pop(); } else{ st.push(i); } } for(auto u:ans){ cout<<u; } return 0; }
/* -*- coding: utf-8 -*- * * f.cc: F - Construct a Palindrome */ #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<iostream> #include<string> #include<vector> #include<map> #include<set> #include<stack> #include<list> #include<queue> #include<deque> #include<algorithm> #include<numeric> #include<utility> #include<complex> #include<functional> using namespace std; /* constant */ const int MAX_N = 1000; const int INF = 1 << 30; /* typedef */ typedef vector<int> vi; typedef pair<int,int> pii; /* global variables */ vi nbrs[MAX_N][26]; int ds[MAX_N][MAX_N]; /* subroutines */ /* main */ int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < m; i++) { int u, v; char s[4]; scanf("%d%d%s", &u, &v, s); u--, v--; int ci = s[0] - 'a'; nbrs[u][ci].push_back(v); if (u != v) nbrs[v][ci].push_back(u); } memset(ds, -1, sizeof(ds)); ds[0][n - 1] = 0; queue<pii> q; q.push(pii(0, n - 1)); int mind = INF; while (! q.empty()) { pii u = q.front(); q.pop(); int u0 = u.first, u1 = u.second; int vd = ds[u0][u1] + 1; for (int c = 0; c < 26; c++) { vi &nbr0 = nbrs[u0][c], &nbr1 = nbrs[u1][c]; if (! nbr0.empty() && ! nbr1.empty()) for (vi::iterator vit0 = nbr0.begin(); vit0 != nbr0.end(); vit0++) for (vi::iterator vit1 = nbr1.begin(); vit1 != nbr1.end(); vit1++) { int v0 = *vit0, v1 = *vit1; if (v0 == v1) mind = min(mind, vd * 2); else if (v0 == u1 && v1 == u0) mind = min(mind, vd * 2 - 1); else { if (v0 > v1) swap(v0, v1); if (ds[v0][v1] < 0) { ds[v0][v1] = vd; q.push(pii(v0, v1)); } } } } } printf("%d\n", (mind >= INF) ? -1 : mind); return 0; }
#include <bits/stdc++.h> using namespace std; // using mint = long double; // using mint = modint998244353; // using mint = modint1000000007; typedef long long ll; typedef pair<ll, ll> P; typedef pair<P, ll> T; typedef pair<ll, vector<ll>> Pd; const ll INF = 2e18; const ll fact_table = 1200008; priority_queue<ll> pql; priority_queue<P> pqp; // big priority queue // priority_queue <ll, vector<ll>, greater<ll> > pqls; priority_queue<P, vector<P>, greater<P>> pqps; // small priority queue // top pop ll dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}; ll dy[8] = {0, 1, 0, -1, -1, 1, 1, -1}; //↓,→,↑,← /* #define endl "\n" #ifdef ENJAPMA #undef endl #endif */ #define p(x) cout << x << endl; #define el cout << endl; #define pe(x) cout << x << " "; #define ps(x) cout << fixed << setprecision(25) << x << endl; #define pu(x) cout << (x); #define pb push_back #define lb lower_bound #define ub upper_bound #define pc(x) cout << x << ","; #define rep(i, n) for (ll i = 0; i < (n); i++) #define rep2(i, a, b) for (ll i = a; i <= (b); i++) #define rep3(i, a, b) for (ll i = a; i >= (b); i--) #define all(c) begin(c), end(c) typedef vector<ll> vec; typedef vector<vector<ll>> mat; // vec v(n) -> 長さnのベクトルを宣言 // mat dp(h, vec(w)) -> h * w の行列を宣言 const ll mod = 998244353ll; // const ll mod = 1000000007ll; ll mypow(ll a, ll b, ll m = mod) { ll x = 1; while (b) { while (!(b & 1)) { (a *= a) %= m; b >>= 1; } (x *= a) %= m; b--; } return x; } vec rv(ll read) { vec res(read); for (int i = 0; i < read; i++) { cin >> res[i]; } return res; } /* ll fact[fact_table + 5], rfact[fact_table + 5]; void c3_init() { fact[0] = rfact[0] = 1; for (ll i = 1; i <= fact_table; i++) { fact[i] = (fact[i - 1] * i) % mod; } rfact[fact_table] = mypow(fact[fact_table], mod - 2, mod); for (ll i = fact_table; i >= 1; i--) { rfact[i - 1] = rfact[i] * i; rfact[i - 1] %= mod; } return; } ll c3(ll n, ll r) { return (((fact[n] * rfact[r]) % mod) * rfact[n - r]) % mod; } */ bool icpc = false; bool multicase = false; ll n, m; vector<P> G[500005]; ll cost[1005][1005]; bool solve() { cin >> n >> m; rep(i, m) { ll a, b; char c; cin >> a >> b >> c; G[a].pb(P(b, c - 'a')); G[b].pb(P(a, c - 'a')); } queue<P> q; rep2(i, 1, n) { rep2(j, 1, n) { cost[i][j] = INF; } } q.push(P(1, n)); cost[1][n] = 0; while (q.size()) { auto [vx, vy] = q.front(); q.pop(); for (auto [nvx, cx] : G[vx]) { for (auto [nvy, cy] : G[vy]) { if (cx != cy) continue; if (cost[nvx][nvy] != INF) continue; q.push(P(nvx, nvy)); cost[nvx][nvy] = cost[vx][vy] + 1; } } } ll ans = INF; for (int i = 1; i <= n; i++) { ans = min(ans, 2 * cost[i][i]); } for (int i = 1; i <= n; i++) { for (auto [nv, c] : G[i]) { int a = i, b = nv; ans = min(ans, cost[a][b] + cost[b][a]); } } if (ans == INF) ans = -1; p(ans); return true; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); if (icpc) { while (solve()) ; return 0; } ll q, testcase = 1; if (multicase) { cin >> q; } else { q = 1; } while (q--) { solve(); testcase++; } // solve(); return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("Ofast","unroll-loops") #define ll long long #define ft first #define sec second #define pb push_back #define pi pair<ll,ll> using namespace std; int n; vector<pi> G[200005]; ll dp[200005][60][2],ans; const int mod=1e9+7; void dfs(int now,int fa) { for(int i=0; i<60; i++) dp[now][i][0]=1; for(pi v:G[now]) if(v.ft!=fa) { dfs(v.ft,now); for(int i=0; i<60; i++) { int k=((v.sec&(1LL<<i))!=0); dp[now][i][0]+=dp[v.ft][i][k]; dp[now][i][1]+=dp[v.ft][i][1^k]; } } } void sol(int now,int fa) { ll cnt[60][2]={0}; for(pi v:G[now]) if(v.ft!=fa) { sol(v.ft,now); for(int i=0; i<60; i++) { int k=((v.sec&(1LL<<i))!=0); ll add=(1LL<<i)%mod; ans=(ans+dp[v.ft][i][1^k]*add%mod)%mod; ans=(ans+add*cnt[i][0]%mod*dp[v.ft][i][1^k]%mod)%mod; ans=(ans+add*cnt[i][1]%mod*dp[v.ft][i][k]%mod)%mod; cnt[i][0]+=dp[v.ft][i][k]; cnt[i][1]+=dp[v.ft][i][1^k]; } } //if(now==3) cout << ans <<'\n'; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for(ll i=1,a,b,c; i<n; i++) { cin >> a >> b >> c; G[a].pb({b,c}); G[b].pb({a,c}); } dfs(1,1); sol(1,1); cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define nl '\n' //----------------------------------- DEBUG ----------------------------------- #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__) << "] " // debug & operator << (debug & dd, P p) { dd << "(" << p.x << ", " << p.y << ")"; return dd; } //----------------------------------- END DEBUG -------------------------------- /* (2, 3) (4, 6) 2 < x < 3 x = 2.5 = 5 [3, 2] */ void run_cases() { int N; cin >> N; vector<vector<int64_t>> ranges(N); for(int i = 0; i < N; i++) { int64_t t, l, r; cin >> t >> l >> r; l *= 100; r *= 100; switch(t) { case 2: r--; break; case 3: l++; break; case 4: l++, r--; break; } ranges[i] = {l, r}; } int ans = 0; auto intersect = [&](vector<int64_t> &a, vector<int64_t> &b) -> bool { vector<int64_t> common = {max(a[0], b[0]), min(a[1], b[1])}; return common[0] <= common[1]; }; for(int i = 0; i < N; i++) { for(int j = i + 1; j < N; j++) { ans += intersect(ranges[i], ranges[j]); } } cout << ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(nullptr); int tests = 1; // cin >> tests; for(int test = 1;test <= tests;test++) { run_cases(); } }
#pragma GCC optimize("Ofast") #define _USE_MATH_DEFINES #include "bits/stdc++.h" using namespace std; using u8 = uint8_t; using u16 = uint16_t; using u32 = uint32_t; using u64 = uint64_t; using i8 = int8_t; using i16 = int16_t; using i32 = int32_t; using i64 = int64_t; using vi = vector<int>; constexpr char newl = '\n'; constexpr double eps = 1e-10; #define FOR(i,a,b) for (int i = (a); i < (b); i++) #define F0R(i,b) FOR(i,0,b) #define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--) #define RF0(i,b) RFO(i,0,b) #define fi first #define se second #define show(x) cout << #x << " = " << x << '\n'; #define rng(a) a.begin(),a.end() #define rrng(a) a.rbegin(),a.rend() #define sz(x) (int)(x).size() #define YesNo {cout<<"Yes";}else{cout<<"No";} #define YESNO {cout<<"YES";}else{cout<<"NO";} #define v(T) vector<T> template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; } template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; } template<class T> bool lcmp(const pair<T, T>& l, const pair<T, T>& r) { return l.first < r.first; } template<class T> istream& operator>>(istream& i, v(T)& v) { F0R(j, sz(v)) i >> v[j]; return i; } template<class A, class B> istream& operator>>(istream& i, pair<A, B>& p) { return i >> p.first >> p.second; } template<class A, class B, class C> istream& operator>>(istream& i, tuple<A, B, C>& t) { return i >> get<0>(t) >> get<1>(t) >> get<2>(t); } template<class T> ostream& operator<<(ostream& o, const vector<T>& v) { F0R(i, v.size()) { o << v[i] << ' '; } o << newl; return o; } template<class T1, class T2> ostream& operator<<(ostream& o, const map<T1, T2>& m) { for (auto& p : m) { o << p.first << ": " << p.second << newl; } o << newl; return o; } #if 1 // INSERT ABOVE HERE signed main() { cin.tie(0); ios_base::sync_with_stdio(false); int H, W; cin >> H >> W; v(string) ss(H); cin >> ss; int re = 0; F0R(r, H) { F0R(c, W) { if (ss[r][c] == '#') continue; if (r < H - 1 && ss[r + 1][c] == '.') re++; if (c < W - 1 && ss[r][c + 1] == '.') re++; } } cout << re; } #endif
#include <bits/stdc++.h> #define endl '\n' #define fi first #define se second #define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k)) #define forn(i,n) for (int i = 0; i < (n); i++) #define forr(i,a,b) for (int i = a; i <= b; i++) #define all(v) v.begin(), v.end() #define pb(x) push_back(x) using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ii> vii; const int MX = 55, mod = 998244353; int n, k, p[MX]; ll fac[MX], cn[MX], a[MX][MX], res = 1; int parent (int a) { return a == p[a] ? a : p[a] = parent(p[a]); } void join (int a, int b) { p[parent(a)] = parent(b); } void solve () { iota(p, p + MX, 0); forn (y, n) forn (x, y) { int cn = 0; forn (i, n) if (a[i][x] + a[i][y] <= k) cn++; if (cn == n) join(x, y); } memset(cn, 0, sizeof(cn)); forn (i, n) cn[parent(i)]++; forn (i, n) (res *= fac[cn[i]]) %= mod; } int main () { ios_base::sync_with_stdio(0); cin.tie(0); fac[0] = 1; for (int i = 1; i < MX; i++) { fac[i] = i * fac[i - 1] % mod; } cin >> n >> k; forn (i, n) forn (j, n) cin >> a[i][j]; solve(); forn (i, n) forn (j, i) swap(a[i][j], a[j][i]); solve(); cout << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define fr(i,n) for(int i = 0; i<n; i++) #define sz(v) (int)(v.size()) #define prin(a) cout << #a << " = " << a << endl #define prinv(v) cout << #v << " = "; for(auto it : v) cout << it << ", "; cout << endl #define all(v) (v).begin(),(v).end() typedef long long ll; #define rmin(a,b) a = min<ll>(a,b) #define rmax(a,b) a = max<ll>(a,b) #define fi first #define se second const int N = 25; vector<int> g[N]; int ne, nv; int ja_comp[N]; int cor[N]; vector<int> vno; int ant[N]; void dfscnt(int no,int from){ if(ja_comp[no]) return; ant[no] = from; ja_comp[no] = 1; vno.push_back(no); nv++; ne+=sz(g[no]); for(auto &it : g[no]) dfscnt(it,no); } /* void dfs(int no){ if(vis[no]) return; vis[no] = 1; na++; fr(c,3){ int bad = 0; for(auto &it : g[no]){ if(vis[it] and cor[it]==c){ bad = 1; break; } } if(bad) continue; if(na==nv){ ways++; } else{ } } na--; vis[no] = 0; } */ int main(){ ios::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; fr(mm,m){ int a, b; cin >> a >> b; a--,b--; g[a].push_back(b); g[b].push_back(a); } ll ans = 1; int ctc[3][2] = {{1,2},{0,2},{0,1}}; fr(noo,n){ if(!ja_comp[noo]){ nv = 0, ne = 0; vno.clear(); dfscnt(noo,-1); //prin(noo); //prin(nv); //prinv(vno); /* if(2*nv-2==ne){ ll cur = 3; fr(i,nv-1) cur*=2; ans*=cur; } else{ na = 0; dfs(i); ans*=ways; } */ ll cur = 0; fr(c1,3){ cor[vno[0]] = c1; fr(mask,1<<(nv-1)){ //prin(mask); fr(i,nv-1){ int cc = cor[ant[vno[i+1]]]; if(mask&(1<<i)){ cor[vno[i+1]] = ctc[cc][0]; } else{ cor[vno[i+1]] = ctc[cc][1]; } } int ok = 1; for(auto &no : vno){ for(auto &it : g[no]){ if(cor[it]==cor[no]){ ok = 0; goto sai; } } } sai: if(ok) cur++; } } ans*=cur; } } cout << ans << "\n"; }
#include <bits/stdc++.h> using namespace std; /* VERIFICAR: - Corner cases - Estouro de variavel - Acesso indevido de memoria MODULO NEGATIVO int modulo(int x,int N){ return (x % N + N) %N; } */ #define _ ios_base::sync_with_stdio(0);cin.tie(0); #define endl '\n' #define f first #define s second #define pb push_back typedef long long ll; typedef pair<int, int> ii; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; struct info { bool c1; bool c2; bool c3; }; int n; vector<vector<int> > g; vector<int> cores; ll cont = 0; vector<int> analisado; vector<info> opt; void solve(int at1) { if(at1 == analisado.size()) { cont++; return; } int at = analisado[at1]; bool cor1 = opt[at].c1; bool cor2 = opt[at].c2; bool cor3 = opt[at].c3; if(!cor1) { cores[at] = 0; vector<info> old = opt; for(int viz : g[at]) { opt[viz].c1 = true; } solve(at1+1); opt = old; cores[at] = -1; } if(!cor2) { cores[at] = 1; vector<info> old = opt; for(int viz : g[at]) { opt[viz].c2 = true; } solve(at1+1); opt = old; cores[at] = -1; } if(!cor3) { cores[at] = 2; vector<info> old = opt; for(int viz : g[at]) { opt[viz].c3 = true; } solve(at1+1); opt = old; cores[at] = -1; } } vector<bool> vis; void dfs(int at, int pai) { if(vis[at]) { return; } vis[at] = true; for(int viz: g[at]) { if(viz != pai) { dfs(viz, at); } } } int main() {_ int m; cin >> n >> m; g.resize(n); int a, b; for(int I=0; I<m; I++) { cin >> a >> b; a--; b--; g[a].pb(b); g[b].pb(a); } vector<bool> visAq(n, false); vector<vector<int> > componentes; for(int I=0; I<n; I++) { if(!visAq[I]) { vis.clear(); vis.resize(n); dfs(I, -1); vector<int> componente; for(int J=0; J<n; J++) { if(vis[J]) { visAq[J] = true; componente.pb(J); } } componentes.pb(componente); } } ll resp = 1; cores.resize(n, -1); opt.resize(n); for(vector<int> v : componentes) { if(v.size() == 1) { resp*=3; } else { cont = 0; analisado = v; solve(0); resp*=cont; } if(resp == 0) { break; } } cout << resp << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vl = vector<ll>; using vvl = vector<vl>; using pl = pair<ll, ll>; const ll INF = ll(1e18); const ll mod = ll(998244353); const double pi = acos(-1); #define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i)) #define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i)) #define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i)) #define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i)) #define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i)) #define rnfor(i,a,b) for(ll (i) = (b) - 1; (i) >= (a); --(i)) #define pf(x) cout << (x) << endl #define all(x) (x).begin(),(x).end() #define yes pf("Yes") #define no pf("No") template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } const int dx[8]={1,0,-1,0,1,1,-1,-1}; const int dy[8]={0,1,0,-1,1,-1,1,-1}; int multipf(vector<string>& s){ cout << s[0]; rep1(i, s.size() - 1)cout << " " << s[i]; cout << endl; return 0; } int multipf(vector<ll>& n){ cout << n[0]; rep1(i, n.size() - 1)cout << " " << n[i]; cout << endl; return 0; } ll gcd(ll a,ll b){ if(a < b)swap(a, b); if(b == 0) return a; return gcd(b,a%b); } ll lcm(ll a,ll b){ ll g = gcd(a,b); return a / g * b; } ll factorial(ll n){ ll ans = 1; rep1(i, n){ ans *= i; ans %= mod; } return ans; } ll power(ll a, ll b){ ll ans = 1; while(b) { if(b & 1LL) ans = ans * a % mod; ans %= mod; a = a * a; a %= mod; b >>= 1; } return ans % mod; } string solve(string s){ string t = ""; rep0(i, s.size()){ if(s[i] == s[i + 1]){ t.push_back(s[i]); }else if(s[i] + s[i + 1] == 163){ t.push_back('S'); }else if(s[i] + s[i + 1] == 165){ t.push_back('R'); }else t.push_back('P'); ++i; } s = t; return s; } //modの値の確認をすること int main(){ ll n,k; string s; cin >> n >> k >> s; rep0(i, k)s = solve(s + s); pf(s[0]); return 0; }
#include <map> #include <queue> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define int long long #define mp make_pair const int mod = 998244353; int read () { int x = 0, f = 1; char ch = getchar (); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar (); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar (); } return x * f; } void write (int x) { if (x < 0) x = -x, putchar ('-'); if (x >= 10) write (x / 10); putchar (x % 10 + '0'); } int quickmod (int x, int y) { int Ans = 1; while (y) { if (y & 1) Ans = (Ans * x) % mod; x = (x * x) % mod; y >>= 1; } return Ans; } int a[200005], b[200005], sum[200005]; int fac[200005], inv[200005]; signed main () { // freopen (".in", "r", stdin); // freopen (".out", "w", stdout); fac[0] = 1; for (int i = 1; i <= 200000; i++) fac[i] = (fac[i-1] * i) % mod; for (int i = 0; i <= 200000; i++) inv[i] = quickmod (fac[i], mod - 2); int n = read (), m = read (), k = read (); if (n == 1 && m == 1) return printf ("%lld", k) & 0; if (n == 1) return printf ("%lld", quickmod (k, m)) & 0; if (m == 1) return printf ("%lld", quickmod (k, n)) & 0; for (int i = 1; i <= k; i++) { a[i] = quickmod (i, n); }//所有行最大值不超过 i 时方案总数 for (int i = 1; i <= k; i++) { b[i] = quickmod (k - i + 1, m); }//所有列最小值不小于 i 时方案总数 for (int i = k; i >= 1; i--) { a[i] = (a[i] - a[i-1] + mod) % mod; } for (int i = 1; i <= k; i++) { b[i] = (b[i] - b[i+1] + mod) % mod; } // for (int i = 1; i <= k; i++) printf ("[%lld %lld]\n", a[i], b[i]); for (int i = 1; i <= k; i++) sum[i] = (sum[i-1] + a[i]) % mod; // printf ("\n"); int Ans = 0; for (int i = 1; i <= k; i++) { Ans = (Ans + (b[i] * sum[i])) % mod; // for (int j = 1; j <= i; j++) { // Ans = (Ans + (b[i] * a[j])) % mod; // } } printf ("%lld", Ans); return 0; } /* */
#include <algorithm> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <map> #include <memory> #include <queue> #include <deque> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> #include <cassert> #include <iostream> #include <stdio.h> #include <time.h> using namespace std; typedef long long ll; #define sz size() #define pb push_back #define mp make_pair #define fi first #define se second #define all(c) (c).begin(), (c).end() #define rep(i,a,b) for(ll i=(a);i<(b);++i) #define per(i,a,b) for(ll i=b-1LL;i>=(a);--i) #define clr(a, b) memset((a), (b) ,sizeof(a)) #define ctos(c) string(1,c) #define MOD 1000000007 int main(){ ll n; cin>>n; map<string,ll> ma; rep(i,0,n){ string s; cin>>s; string s1; if(s[0]=='!'){ rep(j,1,s.sz){ s1 += ctos(s[j]); } ma[s1] |= 2; } else{ ma[s] |= 1; } } map<string,ll>::iterator itr = ma.begin(); while(itr!=ma.end()){ string a = (*itr).fi; ll b = (*itr).se; if(b==3){ cout << a << endl; return 0; } itr++; } cout << "satisfiable" << endl; return 0; }
#include <bits/stdc++.h> int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int64_t n; std::cin >> n; for (int64_t a = 1, p = 3; p <= n; ++a, p *= 3) { for (int64_t b = 1, q = 5; q <= n; ++b, q *= 5) { if (p + q == n) { std::cout << a << " " << b << "\n"; return 0; } } } std::cout << -1 << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 5, INF = 1e17 + 5; long long n, m, a, b, c, d, dist[N]; bool vis[N]; struct Edge{ long long b, c, d; }; vector<Edge> graph[N]; long double findtime(long long t, long long wait, Edge e){ return wait + e.c + ((e.d / (long double)(t + 1 + wait))); } long long findwait(long long t, Edge e){ long long l = 0, r = INF, m1, m2; long double m1ans, m2ans; while(r - l > 2){ m1 = l + (r - l) / 3; m2 = r - (r - l) / 3; m1ans = findtime(t, m1, e); m2ans = findtime(t, m2, e); if(m1ans <= m2ans) r = m2; else l = m1; } vector<pair<long double, long long>> v; for(long long i = l; i <= r; i++){ v.push_back({findtime(t, i, e), i}); } sort(v.begin(), v.end()); return v.front().second; } void dijkstra(){ for(int i = 1; i <= n; i++) dist[i] = INF; priority_queue<pair<long long, long long>> pq; dist[1] = 0; pq.push({0, 1}); long long v; while(!pq.empty()){ v = pq.top().second, pq.pop(); if(!vis[v]){ vis[v] = true; for(auto e : graph[v]){ if(!vis[e.b]){ long long waitt = findwait(dist[v], e); long long edget = findtime(dist[v], waitt, e); if(dist[v] + edget < dist[e.b]){ dist[e.b] = dist[v] + edget; pq.push({-dist[e.b], e.b}); } } } } } } int main(){ ios_base::sync_with_stdio(false);cin.tie(NULL); cin >> n >> m; for(int i = 0; i < m; i++){ cin >> a >> b >> c >> d; graph[a].push_back({b, c, d}); graph[b].push_back({a, c, d}); } dijkstra(); cout << (dist[n] == INF ? -1 : dist[n]); }
//================code===================// //#define TLE #ifdef TLE #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #endif #include <bits/stdc++.h> #include <unordered_map> #include <unordered_set> #include <random> #include <ctime> #include <random> #include <chrono> //#include <stdint.h> #define ci(t) cin>>t #define co(t) cout<<t #define LL long long #define ld long double #define fa(i,a,b) for(LL i=(a);i<(LL)(b);++i) #define fd(i,a,b) for(LL i=(a);i>(LL)(b);--i) #define setp pair<int,ld> #define setl pair<LL,LL> #define micro 0.000000000001 using namespace std; LL gcd(LL a, LL b) { if (!(a && b)) return max(a, b); return a % b ? gcd(b, a % b) : b; } #ifdef OHSOLUTION #define ce(t) cerr<<t #define AT cerr << "\n=================ANS=================\n" #define AE cerr << "\n=====================================\n" #define DB(a) cerr << __LINE__ << ": " << #a << " = " << (a) << endl; #define __builtin_popcount __popcnt #define __builtin_popcountll __popcnt64 #define LLL LL #else #define AT #define AE #define ce(t) #define LLL __int128 #endif pair <int, int> vu[9] = { {0,1},{1,0},{0,-1} ,{-1,0},{-1,0},{-1,-1}, {0,-1} , {1,-1},{-1,-1} }; //RDLU EWSN template<typename T, typename U> void ckmax(T& a, U b) { a = a < b ? b : a; } template<typename T, typename U> void ckmin(T& a, U b) { a = a > b ? b : a; } struct gcmp { bool operator()(LL a, LL b) { return a < b; } bool operator()(setl& a, setl& b) { return a.second < b.second; } }; struct lcmp { bool operator()(LL a, LL b) { return a > b; } bool operator()(setl& a, setl& b) { return a.second > b.second; } }; const int max_v = 1e5+ 7; const int max_k = 5e2 + 7; const int bsz = (1ll << 10) + 7; const int INF = 1e9 + 7; const LL LNF = (LL)5e18 + 7ll; LL mod = 998244353;//1e9 + 7; template<typename T, typename U> void MOD(T& a, U b) { a += b; if (a >= mod) a -= mod; }; struct node { int nxt; int c, d; }; vector<node> adj[max_v]; int main() { #ifdef OHSOLUTION freopen("input.txt", "r", stdin); #endif ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int v, e; ci(v >> e); fa(i, 0, e) { int a, b, c, d; ci(a >> b >> c >> d); --a, --b; adj[a].push_back({ b,c,d }); adj[b].push_back({ a,c,d }); } vector<LL> dist(v, LNF); vector<bool> vist(v, 0); dist[0] = 0; priority_queue<setl, vector<setl>, lcmp> pq; pq.push({0,0}); while (pq.size()) { setl u; do { u = pq.top(); pq.pop(); } while (pq.size() && vist[u.first]); if (vist[u.first]) break; vist[u.first] = 1; for (auto& v : adj[u.first]) { LL base = dist[u.first]+1; LL l = 0; LL r = 1e9 + 7; if (base > v.d) { if (dist[v.nxt] > dist[u.first] + l + v.c + v.d / (dist[u.first] + l + 1)) { dist[v.nxt] = dist[u.first] + l + v.c + v.d / (dist[u.first] + l + 1); pq.push({ v.nxt,dist[v.nxt] }); } } else { while (l < r) { LL mid = l + r >> 1; if ((mid + base) * (mid + base) >= v.d) r = mid; else l = mid + 1; } if (dist[v.nxt] > dist[u.first] + l + v.c + v.d / (dist[u.first] + l + 1)) { dist[v.nxt] = dist[u.first] + l + v.c + v.d / (dist[u.first] + l + 1); pq.push({ v.nxt,dist[v.nxt] }); } ++l; if (dist[v.nxt] > dist[u.first] + l + v.c + v.d / (dist[u.first] + l + 1)) { dist[v.nxt] = dist[u.first] + l + v.c + v.d / (dist[u.first] + l + 1); pq.push({ v.nxt,dist[v.nxt] }); } if (l > 1) { l -= 2; if (dist[v.nxt] > dist[u.first] + l + v.c + v.d / (dist[u.first] + l + 1)) { dist[v.nxt] = dist[u.first] + l + v.c + v.d / (dist[u.first] + l + 1); pq.push({ v.nxt,dist[v.nxt] }); } } } } } dist[v - 1] == LNF ? co(-1) : co(dist[v - 1]); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using Graph = vector<vector<int>>; #define rep(i,n) for(int i=0;i<(int)(n);i++) #define inf 1001001001 #define mod 1000000007 #define mod2 998244353 #define pi acos(-1) #define all(v) v.begin(),v.end() #define vi vector<int> #define vl vector<ll> int dx[4] = {0,-1,0,1}; int dy[4] = {-1,0,1,0}; ll gcd(ll a,ll b){ if(b>a) swap(a,b); if(b==0) return a; return gcd(b,a%b); } ll lcm(ll a,ll b){ ll g=gcd(a,b); return a/g*b; } ll rep_jijo(ll n,ll x){ if(x==0) return 1; if(x%2==0){ ll t=rep_jijo(n,x/2); return t*t%mod; } return n*rep_jijo(n,x-1)%mod; } int n, q; Graph G; vi depth; vl val; void DepthDFS(int now, int d) { depth[now] = d; for(int next: G[now]) { if(depth[next] == -1) { DepthDFS(next, d + 1); } } } void SumDFS(int now, ll weight) { weight += val[now]; val[now] = weight; for(int next: G[now]) { if(depth[next] > depth[now]) { SumDFS(next, weight); } } } int main() { cin >> n; vi A(n - 1); vi B(n - 1); G.resize(n); depth.resize(n, -1); val.resize(n, 0); rep(i, n - 1) { cin >> A[i] >> B[i]; A[i]--; B[i]--; G[A[i]].push_back(B[i]); G[B[i]].push_back(A[i]); } DepthDFS(0, 0); cin >> q; rep(i, q) { int t, e, x; cin >> t >> e >> x; e--; int a = A[e]; int b = B[e]; if(t == 2) swap(a, b); if(depth[a] > depth[b]) { val[a] += x; } else { val[0] += x; val[b] -= x; } } SumDFS(0, 0); rep(i, n) cout << val[i] << endl; }
#include "bits/stdc++.h" //#include "atcoder/all" using namespace std; //using namespace atcoder; //using mint = modint1000000007; //const int mod = 1000000007; //using mint = modint998244353; //const int mod = 998244353; #define endl "\n" int N; long long Ans[200005]; vector<int>to[200005]; class Tree { public: Tree(int V, int root) : V(V), root(root) { T.resize(V); for (int i = 0; i < MAXLOGV; i++) parent[i].resize(V); depth.resize(V); } // uとvをつなぐ // lcaを求めることが主目的なので無向グラフとしている void unite(int u, int v) { T[u].push_back(v); T[v].push_back(u); } // initする // コンストラクタだけじゃなくてこれも呼ばないとlcaが求められないぞ void init() { dfs(root, -1, 0); for (int k = 0; k + 1 < MAXLOGV; k++) { for (int v = 0; v < V; v++) { if (parent[k][v] < 0) parent[k + 1][v] = -1; else parent[k + 1][v] = parent[k][parent[k][v]]; } } } // uとvのlcaを求める int lca(int u, int v) const { if (depth[u] > depth[v]) swap(u, v); for (int k = 0; k < MAXLOGV; k++) { if ((depth[v] - depth[u]) >> k & 1) { v = parent[k][v]; } } if (u == v) return u; for (int k = MAXLOGV - 1; k >= 0; k--) { if (parent[k][u] != parent[k][v]) { u = parent[k][u]; v = parent[k][v]; } } return parent[0][u]; } // uとvの距離を求める // edgeを定義しないといけない時はこれじゃダメ int dist(int u, int v) const { int p = lca(u, v); return (depth[u] - depth[p]) + (depth[v] - depth[p]); } void dfs(int v, int p, int d) { parent[0][v] = p; depth[v] = d; for (int next : T[v]) { if (next != p) dfs(next, v, d + 1); } } static const int MAXLOGV = 25; // グラフの隣接リスト表現 vector<vector<int> > T; // 頂点の数 int V; // 根ノードの番号 int root; // 親ノード vector<int> parent[MAXLOGV]; // 根からの深さ vector<int> depth; }; void dfs(int v, int p = -1) { if (-1 != p) { Ans[v] +=Ans[p]; } for (int i = 0; i < to[v].size(); ++i) { if (p == to[v][i]) { continue; } dfs(to[v][i], v); } return; } int main() { cin >> N; vector<int>A(N); vector<int>B(N); Tree tree(N, 0); for (int i = 0; i < N - 1; ++i) { cin >> A[i] >> B[i]; A[i]--; B[i]--; to[A[i]].push_back(B[i]); to[B[i]].push_back(A[i]); tree.unite(A[i], B[i]); } tree.init(); int Q; cin >> Q; for (int i = 0; i < Q; ++i) { int t, e, x; cin >> t >> e >> x; e--; if (1 == t) { if (tree.depth[B[e]] < tree.depth[A[e]]) { Ans[A[e]] += x; } else { Ans[B[e]] -= x; Ans[0] += x; } } else { if (tree.depth[A[e]] < tree.depth[B[e]]) { Ans[B[e]] += x; } else { Ans[A[e]] -= x; Ans[0] += x; } } } dfs(0); for (int i = 0; i < N; ++i) { cout << Ans[i] << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define INF 100000000 ; #define rep(i,n) for(int i=0;i< (int)(n);i++) typedef vector<vector<int>> Vi; typedef vector<vector<char>> Vc; typedef pair<int,int> P; typedef long long ll; int main(){ int M ,H; cin >> M >> H; if(H%M==0){ cout << "Yes"; }else{ cout << "No"; } }
#include <iostream> #include<string> #include<vector> #include<algorithm> #include<cmath> #include<numeric> #include<functional> #include <iomanip> #include<map> #include<queue> using namespace std; typedef long long ll; #define REP(i, n) for(ll i = 0; i < n; i++) #define REPR(i, n) for(ll i = n; i >= 0; i--) #define FOR(i, m, n) for(ll i = m; i < n; i++) #define INF 2e9 #define ALL(v) v.begin(), v.end() #define DESC std::greater<int>() //sort 3rd arg int main() { int x, y; cin >> x >> y; if (x > y) { swap(x, y); } if (x + 3 > y) { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0; }
#include<algorithm> #include<array> #include<bitset> #include<cassert> #include<climits> #include<cmath> #include<cstring> #include<deque> #include<functional> #include<iostream> #include<iomanip> #include<map> #include<numeric> #include<optional> #include<queue> #include<set> #include<stack> #include<string> #include<tuple> #include<unordered_map> #include<unordered_set> #include<vector> #pragma GCC optimize("Ofast") namespace gengar { using namespace std; #define int long long #define itn int #define uint unsigned long long #define ld long double #define vt(tp) vector<tp> #define vvt(tp) vector<vector<tp>> #define vvt2(nm,tp,h,w,n) vector<vector<tp>>nm((h),vector<tp>(w,n)) #define P pair<int,int> #define hmap unordered_map #define hset unordered_set #define all(x) x.begin(),x.end() #define nsort(x) sort(all(x)) #define rsort(x) nsort(x);reverse(all(x)) #define unq(v) v.erase(unique(all(v)),v.end()) #define l_b(c,x) distance(c.begin(),lower_bound(all(c),(x))) #define u_b(c,x) distance(c.begin(),upper_bound(all(c),(x))) #define fi first #define se second #define mp make_pair #define pb push_back #define eb emplace_back #define spc ' ' #define pass #define _overload3(_1,_2,_3,name,...) name #define _rep(i,n) repi(i,0,n) #define repi(i,a,b) for(int i=(a),__SIZE##_=(b);i<__SIZE##_;i++) #define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__) #define _daolrevo3(_1,_2,_3,name,...) name #define _per(i,n) peri(i,n,0) #define peri(i,a,b) for(int i=(a),__SIZE##_=(b);i>=__SIZE##_;i--) #define per(...) _daolrevo3(__VA_ARGS__,peri,_per,)(__VA_ARGS__) #define Bit(n) (1LL<<(n)) #define myceil(a,b) ((a)+((b)-1))/(b) #define scale(n) cout<<fixed<<setprecision(n) using i64=int64_t; using u64=uint64_t; template<class T>using PQ=priority_queue<T,vt(T),greater<T>>; void in(){} template<class Car,class...Cdr> void in(Car&&car,Cdr&&...cdr){cin>>car;in(forward<Cdr>(cdr)...);} template<class T>void drop(T x){cout<<(x)<<endl;exit(0);} void dYes(){puts("Yes");exit(0);} void dNo(){puts("No");exit(0);} int gcd(int a,int b){return b?gcd(b,a%b):a;} int lcm(int a,int b){return a/gcd(a,b)*b;} int fact(int n,int m){int f=n;for(int i=n-1;i>=1;i--){f*=i;f%=m;}return f;} template<class T>int chmin(T&a,const T&b){if(b<a){a=b;return 1;}return 0;} template<class T>int chmax(T&a,const T&b){if(a<b){a=b;return 1;}return 0;} const int inf=Bit(60); const double pi=acos(-1); const int mod=1000000007;//998244353 }; using namespace gengar; int rui[100010],rui2[100010]; int32_t main() { ios::sync_with_stdio(false); cin.tie(0); int n,m;in(n,m); vector<int>h(n),w(m); rep(i,n)cin>>h[i]; rep(i,m)cin>>w[i]; sort(all(h)); for(int i=0;i<n-1;i+=2)rui[i/2+1]=rui[i/2]+h[i+1]-h[i]; for(int i=n-2;i>0;i-=2)rui2[i/2]=rui2[i/2+1]+h[i+1]-h[i]; int ans=inf; for(auto p:w) { int x=l_b(h,p); if(x%2)x--; chmin(ans,rui[x/2]+rui2[x/2]+abs(h[x]-p)); } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> #define int long long #define pb push_back #define pf push_front #define pipii pair<int,pair<int,int>> #define pii pair<int,int> #define mod 1000000007 #define ss second #define vi vector<int> #define vvi vector<vector<int>> #define vpii vector<pair<int,int>> #define ff first #define all(v) v.begin(),v.end() #define allr(v) v.rbegin(),v.rend(); #define ld long double #define inf (int)1e9+7 #define sp fixed<<setprecision(12) using namespace std; // #include<ext/pb_ds/assoc_container.hpp> // #include<ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; // typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; #define db(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << '\n'; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } int dx[]={0,0,-1,1}; int dy[]={-1,1,0,0}; char charr[]={'L','R','U','D'}; void solve(int tc){ //cout<<"Case #"<<tc<<": "; int n; cin>>n; int a[n]; for(int i=0;i<n;i++){ cin>>a[i]; } int ans=INT_MAX; for(int i=0;i<(1ll<<n);i++){ vector<int> v; int orr=0; for(int j=0;j<n;j++){ if((1ll<<j)&i){ orr|=a[j]; v.pb(orr); orr=0; }else{ orr|=a[j]; } } if(orr>0){ v.pb(orr); } int xorr=0; for(int x:v){ xorr^=x; } ans=min(ans,xorr); } cout<<ans; } int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif //double pi=3.14159265358979323846; //precompute(); int t=1; //cin>>t; int tc=1; while(t--){ solve(tc); tc++; } return 0; }//Ardhendu Reja , JGEC /* int powmod(int x,int n,int p) { int result=1; while(n>0) { if(n % 2 ==1) result=(result * x)%p; x=(x*x)%p; n=n/2; } return result; } int modmul(int a,int b) { return ((a % mod) * (b % mod)) % mod; } */
//Never stop trying #include "bits/stdc++.h" using namespace std; #define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0) typedef long long ll; #define int ll typedef string str; typedef long double ld; typedef pair<int, int> pi; #define fi first #define se second typedef vector<int> vi; typedef vector<pi> vpi; #define pb push_back #define eb emplace_back #define sz(x) (int)x.size() #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) #define endl "\n" #define FOR(i,a,b) for (int i = (a); i < (b); ++i) #define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i) const int MOD = 1e9 + 7; //998244353 const ll INF = 1e18; const int MX = 2e5 + 10; const int nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0}; //right left down up template<class T> using V = vector<T>; template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); } // divide a by b rounded up //constexpr int log2(int x) { return 31 - __builtin_clz(x); } // floor(log2(x)) mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); //mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count()); ll random(ll a, ll b){ return a + rng() % (b - a + 1); } #ifndef LOCAL #define cerr if(false) cerr #endif #define dbg(x) cerr << #x << " : " << x << endl; #define dbgs(x,y) cerr << #x << " : " << x << " / " << #y << " : " << y << endl; #define dbgv(v) cerr << #v << " : " << "[ "; for(auto it : v) cerr << it << ' '; cerr << ']' << endl; #define here() cerr << "here" << endl; void IO() { #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } /////////////////////////ONLY CLEAN CODES ALLOWED///////////////////////// int32_t main() { boost; IO(); int N; cin>>N; vi a(N); FOR(i,0,N) cin>>a[i]; int ans=INF; FOR(m,0,(1<<N)){ if( !((m>>(N-1))&1) ) continue; int cur=0; vi vec; FOR(i,0,N){ cur|=a[i]; if((m>>i)&1){ vec.pb(cur); cur=0; } } int v=0; for(auto x: vec) v^=x; ckmin(ans,v); } cout << ans << endl; return 0; } //Change your approach
#include<bits/stdc++.h> using namespace std; #define dd double #define ll long long int #define light ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define pb push_back #define mkp make_pair #define pi pair<ll,ll> #define pii pair<ll,pi> #define fi first #define sc second ll INF=2*1e9+5; ll mod=998244353; ll ans=INF,n; void calc(vector<ll>&a , ll i,ll ro){ if(i==n-1){ ans = min(ans,ro); return; } ll rox=a[i+1]; for (ll j = i+1; j <n ; ++j){ calc(a,j,ro^rox); if(j<n-1) rox |= a[j+1]; } } void solve(){ cin>>n; vector<ll>a(n); for(auto &ele:a){ cin>>ele; } ans=INF; ll i,rox=a[0]; for(i=0;i<n;i++){ calc(a,i,rox); if(i<n-1) rox |= a[i+1]; } cout<<ans<<"\n"; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif light; ll t; //cin>>t; t=1; while(t--){ solve(); } }
/* BABA JAGAAAAAA */ #include<bits/stdc++.h> #define pb push_back #define un unordered_map #define us unordered_set #define ll long long #define PI 3.1415926535897932384626 #define fast ios:: sync_with_stdio(false);cin.tie(NULL) #define l long using namespace std; const int mod= 1e9+7; const int inf=1e9+3; int main() { fast; int x; cin>>x; if(x>=0) cout<<x<<"\n"; else cout<<0<<"\n"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int mod = 1e9+7; #define all(x) (x).begin(),(x).end() #define fr first #define sc second #define nl '\n' void solve(){ int x;cin>>x; cout<<max(x,0); } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t=1; //cin>>t; while(t--){ solve(); } return 0; }
#include <iostream> #include <string> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; int main() { string S; cin >> S; cout << S.substr(1) << S.substr(0, 1) << endl; return 0; }
// Jai Shree Ram #include<bits/stdc++.h> typedef long long int ll; #define pb push_back #define max2(a,b) (a>b)?a:b #define mi2(a,b) (a<=b)?a:b #define fori(i,n) for(ll i=0;i<(ll)n;i++) #define ford(i,n) for(ll i=n;i>=0;i--) #define pll pair<ll,ll> #define mod 1000000007 #define ff first #define ss second using namespace std; #define MAXI 1e9 #define MAX_LIMIT 500001 void solve() { string s; cin>>s; ll cn=0; for(int i=1;i<=3;i++) { if(cn==3) { break; } cout<<s[i%3]; cn++; } cout<<"\n"; } int main() { ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); ll T; T=1; //cin>>T; fori(_,T) { solve(); } }
#include <bits/stdc++.h> #define all(vec) vec.begin(), vec.end() #define pb push_back #define eb emplace_back #define fi first #define se second using namespace std; using ll = long long; using P = pair<ll, ll>; template <class T> using V = vector<T>; template <class T> inline void chmin(T &a, const T &b) { a = min(a, b); } template <class T> inline void chmax(T &a, const T &b) { a = max(a, b); } template <class T> inline bool kbit(const T &x, const int &k) { return ((x >> k) & 1LL); } inline int popcount(const int &n) { return __builtin_popcount(n); } inline ll popcountll(const ll &n) { return __builtin_popcountll(n); } inline ll mask(const ll &k) { return (1LL << k) - 1LL; } template <class T> void zip(V<T> &v) { sort(all(v)); v.erase(unique(all(v)), v.end()); } template <class T> int lwb(V<T> &v, const T &x) { return lower_bound(all(v), x) - v.begin(); } template <class T> int upb(V<T> &v, const T &x) { return upper_bound(all(v), x) - v.begin(); } void dump() { cerr << '\n'; } template <class Head, class... Tail> void dump(Head &&head, Tail &&...tail) { cerr << head << (sizeof...(Tail) == 0 ? " " : ", "); dump(std::move(tail)...); } template <class T> void print(const vector<T> &v) { for (int i = 0; i < v.size(); i++) cout << v[i] << (i + 1 == v.size() ? '\n' : ' '); } template <class T> void read(vector<T> &v) { for (int i = 0; i < v.size(); i++) cin >> v[i]; } constexpr char sp = ' ', newl = '\n'; constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; constexpr ll INF = (1LL << 60) - 1LL; constexpr ll MOD = 998244353LL; //////////////////////////////////////////////INSERT ABOVE HERE int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; string s; cin >> s; V<int> c(n + 1, -1); for (int i = 0; i <= n; i++) { bool f = false; if (i == 0 && s[0] == '<') { f = true; } else if (i == n && s[n - 1] == '>') { f = true; } else if (0 < i && i < n && s[i - 1] == '>' && s[i] == '<') { f = true; } if (!f) continue; c[i] = 0; for (int j = i - 1; j >= 0; j--) { if (s[j] == '<') break; chmax(c[j], c[j + 1] + 1); } for (int j = i + 1; j <= n; j++) { chmax(c[j], c[j - 1] + 1); if (s[j] == '>') break; } } V<int> a(n + 1); read(a); int k = 1 << 30; for (int i = 0; i <= n; i++) { if (c[i] > 0) chmin(k, a[i] / c[i]); } for (int i = 0; i < n; i++) { chmin(k, abs(a[i + 1] - a[i])); } cout << k << newl; for (int i = 0; i < k; i++) { for (int j = 0; j <= n; j++) { if (i < a[j] % k) { cout << (a[j] / k) + 1; } else { cout << (a[j] / k); } if (j < n) cout << " "; } cout << newl; } }
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() using ll = long long; constexpr int INF = 0x3f3f3f3f; constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL; constexpr double EPS = 1e-8; constexpr int MOD = 1000000007; // constexpr int MOD = 998244353; constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1}; constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1}; template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; } template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; } struct IOSetup { IOSetup() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << fixed << setprecision(20); } } iosetup; int main() { int n; string s; cin >> n >> s; vector<int> a(n + 1); REP(i, n + 1) cin >> a[i]; int k = INF; REP(i, n) chmin(k, abs(a[i + 1] - a[i])); cout << k << '\n'; REP(i, k) REP(j, n + 1) cout << (a[j] + i) / k << " \n"[j == n]; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using uint = unsigned int; using ull = unsigned long long; using pii = pair<int, int>; /* [💭] [💡] [🎈] */ ll fibo[88]; bitset<88> f; int main() { cin.tie(nullptr), cout.tie(nullptr), ios::sync_with_stdio(false); #ifdef _SHIFTPSH freopen("_run/in.txt", "r", stdin), freopen("_run/out.txt", "w", stdout); #endif ll n; cin >> n; ll tn = n; fibo[0] = fibo[1] = 1; for (int i = 2; i <= 87; i++) fibo[i] = fibo[i - 1] + fibo[i - 2]; vector<int> v; while (n) { int i = upper_bound(fibo, fibo + 88, n) - fibo - 1; v.emplace_back(i); n -= fibo[i]; } int m = v[0]; for (int i = 1; i < v.size(); i++) f[m - v[i]] = true; vector<int> ops; ops.emplace_back(1), ops.emplace_back(2); ll x = 0, y = 0; x++; y++; for (int i = 1; i < m; i++) { if (i & 1) { x += y; ops.emplace_back(3); } else { y += x; ops.emplace_back(4); } if (f[i + 1]) { if (i & 1) { x++; ops.emplace_back(1); } else { y++; ops.emplace_back(2); } } } cout << ops.size() << '\n'; for (int o:ops) { if (x == tn) { cout << o << '\n'; } else { cout << ((o - 1) ^ 1) + 1 << '\n'; } } return 0; }
#include <bits/stdc++.h> #define pb push_back #define mp make_pair #define st first #define nd second #define pii pair<int,int> #define piii pair<int,pii> #define sp " " #define nl "\n" #define all(x) x.begin(),x.end() #define fastio() ios_base::sync_with_stdio(0);cin.tie(0); #define ll long long using namespace std; const int N = 2e5+5; const ll INF = 1e18+5; const int mod = 1e9+7; int n; string s; map<int,int> m; signed main(){ #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif fastio() cin >> s; n=s.size(); for(int i=0;i<n;i++){ m[s[i]-'0']++; } if(n==1){ cout << (s[0]=='8'||s[0]=='0'?"Yes\n":"No\n"); return 0; } if(n==2){ if(((s[0]-'0')*10+s[1]-'0')%8==0||((s[1]-'0')*10+s[0]-'0')%8==0) cout << "Yes\n"; else cout << "No\n"; return 0; } for(int i=104;i<1000;i+=8){ int a=i/100; int b=i/10-a*10; int c=i%10; // cout << a << b << c << nl; if(a==b&&a==c){ if(m[a]>=3){ cout << "Yes"; return 0; } } else if(a==b){ if(m[a]>=2&&m[c]>=1){ cout << "Yes"; return 0; } } else if(a==c){ if(m[a]>=2&&m[b]>=1){ cout << "Yes"; return 0; } } else if(b==c){ if(m[b]>=2&&m[a]>=1){ cout << "Yes"; return 0; } } else{ if(m[a]>=1&&m[b]>=1&&m[c]>=1){ cout << "Yes"; return 0; } } } cout << (m[0]>=3?"Yes\n":"No\n"); }
#include<bits/stdc++.h> using namespace std; void solution() { int h, w; cin >> h >> w; long long output = 1; int values[h + w][3] = {}; for(int i = 0; i < h; i++) { string s; cin >> s; for(int j = 0; j < w; j++) { if(s[j] == '.') {values[i + j][0]++;} else if(s[j] == 'R') {values[i + j][1]++;} else {values[i + j][2]++;} } } for(int i = 0; i < h + w; i++) { if(values[i][0] && values[i][1] == 0 && values[i][2] == 0) {output *= 2;} else if(values[i][1] && values[i][2]) {output *= 0;} output %= 998244353; } cout << output << endl; return; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int count, counter = 0; count = 1; while(counter++ < count) {solution();} return 0; }
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #include <iostream> #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double db; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template <typename T> using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define pll pair<ll,ll> #define pb push_back #define eb emplace_back #define mp make_pair #define ub(v,val) upper_bound(v.begin(),v.end(),val) #define np(str) next_permutation(str.begin(),str.end()) #define lb(v,val) lower_bound(v.begin(),v.end(),val) #define sortv(vec) sort(vec.begin(),vec.end()) #define rev(p) reverse(p.begin(),p.end()); #define v vector #define len length() #define repc(i,s,e) for(ll i=s;i<e;i++) #define fi first #define se second #define mset(a,val) memset(a,val,sizeof(a)); #define mt make_tuple #define repr(i,n) for(i=n-1;i>=0;i--) #define rep(i,n) for(i=0;i<n;i++) #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define at(s,pos) *(s.find_by_order(pos)) #define set_ind(s,val) s.order_of_key(val) long long int M = 1e9 + 7 ; long long int inf = 9 * 1e18; const double PI = acos(-1); //CLOCK ll begtime = clock(); #define time() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //CLOCK ENDED ll n, m; // modular exponentiation ll binpow(ll val, ll deg) { if (deg < 0) return 0; if (!deg) return 1 % M; if (deg & 1) return binpow(val, deg - 1) * val % M; ll res = binpow(val, deg >> 1); return (res * res) % M; } //binomial ll modinv(ll n) { return binpow(n, M - 2); } ll dp[3005][3005], ways[3005][3005]; int main() { // your code goes here IOS; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll i, j, t, k, x, y, z, N; //dp[i][j] denotes ith index tak aur j groups //ways[i][j] sum%i==j mset(dp, 0); mset(ways, 0); dp[0][0] = 1; ll sum = 0; ways[1][0] = 1; cin >> n; ll a[n]; rep(i, n) cin >> a[i]; rep(i, n) { sum += a[i]; repr(j, n) { ll rem = sum % (j + 1); (dp[i + 1][j + 1] += ways[j + 1][rem]) %= M; (ways[j + 2][sum % (j + 2)] += dp[i + 1][j + 1]) %= M; } } // rep(i, n + 1) { // rep(j, n + 1) { // debug(i, j, dp[i][j]); // } // } ll ans = 0; for (i = 1; i <= n; i++) (ans += dp[n][i]) %= M; cout << ans; return 0; }
#include <iostream> #include <string.h> #include <algorithm> #include <iomanip> #include <cmath> #include <map> using namespace std; #include <vector> #include <queue> #include <numeric> #define MM (1000000000 + 7) typedef unsigned long long ull; vector<vector<int>> A[200000 + 1]; ull ans; ull N; ull a, b, c; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int i, j, k; ans = -1; cin >> N; for (i = 0; i < 63; i++) { a = N >> i; b = i; c = N - (N >> i) * (1ULL << i); ans = min(ans, a + b + c); } cout << ans << '\n'; return 0; }
/**Bismillahir Rahmanir Rahim.**/ /* Md.Fagun Molla 18ICTCSE006 BSMRSTU(SHIICT) */ #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; using ll=long long; using db=double; ///***************************************************** CONSTANTS ******************************************************/// int const N=1e6+3; ll MOD=1e9+7,fact[N]; const long long inf=(long long)1e18; const long double PI=3.14159265358979; ///************************************************ CONTAINER DEFINITIONS ***********************************************/// typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int,int> pii; typedef pair<ll, ll> pll; typedef vector<pii> vii; typedef vector<pll> vll; ///************************************************ SHORT FORM KEYWORDS *************************************************/// #define PB push_back #define F first #define S second #define MP make_pair #define I insert #define lb lower_bound #define ub upper_bound #define endl '\n' ///************************************************ SHORT FORM FUNCTIONS ************************************************/// #define loop(a,b) for(ll i=a;i<b;i++) #define loopr(a,b) for(ll i=a-1;i>=b;i--) #define mem(a,b) memset(a, b, sizeof(a) ) #define gcd(a,b) __gcd(a,b) #define lcm(a,b) (a*(b/gcd(a,b))) #define sa(v) sort(v.begin(),v.end()) #define sd(v) sort(v.begin(),v.end(),greater<>()) #define rev(s) reverse(s.begin(),s.end()) #define stll(x) stoll(x, nullptr, 10); #define yes cout<<"YES"<<endl; #define no cout<<"NO"<<endl; #define mx(a) *max_element(all(a)) #define mn(a) *min_element(all(a)) #define all(a) a.begin(),a.end() #define mxa(a,N) *max_element(a,a+N) #define mna(a,N) *min_element(a,a+N) #define print(a) {for(auto x:a)cout<<x<<" ";cout<<endl;} #define io() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); ///************************************************ SOLUTION STARTS HERE ************************************************/// ///======================================================================================================================/// void solve(){ int n; cin>>n; int aa[n],bb[n]; for(int i=0; i<n; i++) cin>>aa[i]; for(int i=0; i<n; i++) cin>>bb[i]; bool f=true; int c=0; for(int i=1; i<=1000; i++) { f=true; for(int j=0; j<n; j++) { if(aa[j]<=i && bb[j]>=i) continue; else { f=false; break; } } if(f) { c++; } } cout<<c<<endl; } int main() { io(); int T=1;//cin>>T; while(T--) solve(); return 0; } /**************************************************ALHAMDULILLAH************************************************/
#include<bits/stdc++.h> using namespace std; const int N=2e5+5; inline int read() { int x=0,f=1; char c=getchar(); while(c<'0' || c>'9') { if(c=='-') f=-1; c=getchar(); } while(c>='0' && c<='9') { x=x*10+c-'0'; c=getchar(); } return x*f; } int n; char s1[N],s2[N],s3[N]; int main() { int T=read(); while(T--) { n=read(); scanf("%s",s1+1); scanf("%s",s2+1); scanf("%s",s3+1); for(int i=1;i<=n;i++) printf("0"); for(int i=1;i<=n;i++) printf("1"); printf("0\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; #define faster ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define pi acos(-1.0) #define nl '\n' /**-------Library-------*/ #define mem(a,b) memset(a,b,sizeof(a)) #define all(a) a.begin(),a.end() #define Sort(x) sort(x.begin(),x.end()) #define Reverse(x) reverse(x.begin(),x.end()) #define SortA(ar,s) sort(ar,ar+s) #define SortD(ar,s) sort(ar,ar+s,greater<int>()) #define maxa(A,n) *max_element(A,A+n) #define minall(A,n) *min_element(A,A+n) #define gcd(a,b) __gcd(a,b) #define lcm(a,b) (a*(b/gcd(a,b))) #define sq(x) (x)*(x) #define fr0(i, n) for(int i=0; i<n; i++) #define fr1(i, n) for(int i=1; i<=n; i++ #define min3(a,b,c) min(a,min(b,c)) #define min4(a,b,c,d) min(a,min(b,min(c,d))) #define max3(a,b,c) max(a,max(b,c)) #define max4(a,b,c,d) max(a,max(b,max(c,d))) #define ABS(x) ((x)<0?-(x):(x)) #define pb(x) push_back(x) #define mod 1000000007 #define precision(x) cout<<fixed<<setprecision(x) #define end cout<<nl #define yes cout<<"YES"<<nl #define no cout<<"NO"<<nl /**----------Graph Moves----------*/ const int fx[] = {+1,-1,+0,+0}; // 4 X directions const int fy[] = {+0,+0,+1,-1}; // 4 Y directions const int fx8[] = {+0,+0,+1,-1,-1,+1,-1,+1}; // King X Moves const int fy8[] = {-1,+1,+0,+0,+1,+1,-1,-1}; // King Y Moves const int kx[] = {-2, -2, -1, -1, 1, 1, 2, 2}; // Knight X Moves const int ky[] = {-1, 1, -2, 2, -2, 2, -1, 1}; // Knight Y Moves /**------- Char Chk----------*/ bool isLow(char ch){if(ch>='a' && ch<='z') return true;return false;} bool isUpp(char ch){if(ch>='A' && ch<='Z') return true;return false;} bool isDig(char ch){if(ch>='0' && ch<='9') return true;return false;} /**----data type----*/ typedef long long int ll; typedef unsigned long long int llu; int main() { int t; cin>>t; while(t--) { ll n; cin>>n; if(n&1) cout<<"Odd"<<nl; else if((n/2)&1) cout<<"Same"<<nl; else cout<<"Even"<<nl; } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define forin(in ,n) for(ll i=0; i<n; i++) cin>>in[i] #define forout(out) for(ll i=0; i<(ll)out.size(); i++) cout<<out[i]<<endl #define rep(i, n) for (ll i = 0; i < n; ++i) #define rep_up(i, a, n) for (ll i = a; i < n; ++i) #define rep_down(i, a, n) for (ll i = a; i >= n; --i) #define P pair<ll, ll> #define all(v) v.begin(), v.end() #define fi first #define se second #define vvvll vector<vector<vector<ll>>> #define vvll vector<vector<ll>> #define vll vector<ll> #define pqll priority_queue<ll> #define pqllg priority_queue<ll, vector<ll>, greater<ll>> constexpr ll INF = (1ll << 60); //constexpr ll mod = 1000000007; //constexpr ll mod = 998244353; constexpr ll mod = 3; 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; } template <typename T> void pt(T val) { cout << val << "\n"; } template <typename T> void pt_vll(vector<T> &v) { ll vs = v.size(); rep(i, vs) { cout << v[i]; if (i == vs - 1) cout << "\n"; else cout << " "; } } ll mypow(ll a, ll n) { ll ret = 1; if(n==0) return 1; if(a==0) return 0; rep(i, n) { if (ret > (ll)(1e18 + 10) / a) return -1; ret *= a; } return ret; } long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } long long modinv(long long a, long long m) { long long b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } const int MAX = 510000; long long th[MAX], tw[MAX]; // テーブルを作る前処理 void COMinit() { th[1]=0; tw[1]=0; for (ll i = 2; i < MAX; i++){ if(i%3==2) tw[i]=1; if(i%3==0){ ll x=i; while(x%3==0){ th[i]++; x/=3; } if(x%3==2) tw[i]=1; } tw[i]+=tw[i-1]; th[i]+=th[i-1]; } } // 二項係数計算 long long COM(ll n, ll k){ if(th[n]>th[k]+th[n-k]) return 0; if((tw[n]-tw[k]-tw[n-k])%2==0) return 1; return 2; } int main() { ll n,m,k,sum=0,ans=0; string s; cin>>n>>s; COMinit(); vll a(n); rep(i,n){ if(s[i]=='W') a[i]=0; if(s[i]=='B') a[i]=1; if(s[i]=='R') a[i]=2; a[i]*=COM(n-1,i); } rep(i,n){ sum+=a[i]; sum%=mod; } if(n%2==0) sum=(3-sum)%3; if(sum%3==0) cout<<"W"<<endl; if(sum%3==1) cout<<"B"<<endl; if(sum%3==2) cout<<"R"<<endl; }
#include <bits/stdc++.h> using namespace std; typedef long long LL; const int INF = 0x3f3f3f3f; const LL mod = 1e9 + 7; const int N = 2005; char s[N][N]; int f[N][N]; int cal(char c) { return c == '+' ? 1 : -1; } int main() { int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> s[i] + 1; } for (int i = n; i >= 1; i--) { for (int j = m; j >= 1; j--) { if (i < n && j < m) f[i][j] = max(cal(s[i][j + 1]) - f[i][j + 1], cal(s[i + 1][j]) - f[i + 1][j]); else if (i < n) { f[i][j] = cal(s[i + 1][j]) - f[i + 1][j]; } else if (j < m) { f[i][j] = cal(s[i][j + 1]) - f[i][j + 1]; } else { f[i][j] = 0; } } } if (f[1][1] == 0) puts("Draw"); else if (f[1][1] > 0) puts("Takahashi"); else puts("Aoki"); return 0; }
#include <bits/stdc++.h> int main(){ int N; std::cin >> N; std::vector< int > T(N); int sum = 0; for(int i=0; i<N; i++){ std::cin >> T[i]; sum += T[i]; } std::map< int, bool > mp; mp[0] = 1; for(int i=0; i<N; i++){ std::vector< int > tmp; for(auto itr = mp.begin(); itr != mp.end(); itr++){ tmp.push_back(itr->first + T[i]); } for(int j=0; j<tmp.size(); j++){ mp[tmp[j]] = 1; } } int ans = 0; for(auto itr = mp.begin(); itr != mp.end(); itr++){ if(abs(sum / 2 - ans) > abs(sum / 2 - itr->first)){ ans = itr->first; } } std::cout << std::max(sum - ans, ans) << std::endl; return 0; }
#include <cstdio> #include <cstring> #include <cmath> #include <utility> #include <iostream> #include <functional> #include <bitset> #include <algorithm> #include <vector> #include <forward_list> #include <set> #include <map> #include <queue> #include <deque> #include <stack> #include <tuple> #include <numeric> #include <cassert> using namespace std; using ll = long long; using P = pair<ll, ll>; const ll MOD = 1e9 + 7; const ll INF = (1ll << 60); 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; } int main(void) { ll n; cin >> n; vector<ll> t(n); ll s = 0; for (int i = 0; i < n; i++) { cin >> t[i]; s += t[i]; } vector<vector<bool>> dp(n + 5, vector<bool>(100010, false)); dp[0][0] = true; for (int i = 1; i <= n; i++) { dp[i][0] = true; for (int j = 0; j < 100005; j++) { dp[i][j] = dp[i - 1][j] | dp[i][j]; if (j - t[i - 1] < 0) { continue; } dp[i][j] = dp[i - 1][j - t[i - 1]] | dp[i][j]; } } ll ans = INF; for (ll i = 0; i < 100005; i++) { if (dp[n][i]) { chmin(ans, max(s - i, i)); } } // for (int i = 1; i <= n; i++) // { // for (int j = 0; j < 26; j++) // { // cout << dp[i][j] << " "; // } // cout << endl; // } cout << ans << endl; }
#include <iostream> #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double db; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template <typename T> using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define pll pair<ll,ll> #define pb push_back #define eb emplace_back #define mp make_pair #define ub(v,val) upper_bound(v.begin(),v.end(),val) #define np(str) next_permutation(str.begin(),str.end()) #define lb(v,val) lower_bound(v.begin(),v.end(),val) #define sortv(vec) sort(vec.begin(),vec.end()) #define rev(p) reverse(p.begin(),p.end()); #define v vector #define pi 3.14159265358979323846264338327950288419716939937510 #define len length() #define repc(i,s,e) for(ll i=s;i<e;i++) #define fi first #define se second #define mset(a,val) memset(a,val,sizeof(a)); #define mt make_tuple #define repr(i,n) for(i=n-1;i>=0;i--) #define rep(i,n) for(i=0;i<n;i++) #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define at(s,pos) *(s.find_by_order(pos)) #define set_ind(s,val) s.order_of_key(val) long long int M = 1e9 + 7 ; long long int inf = 9 * 1e18; //CLOCK ll begtime = clock(); #define time() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //CLOCK ENDED ll n, m; // modular exponentiation ll binpow(ll val, ll deg) { if (deg < 0) return 0; if (!deg) return 1 % M; if (deg & 1) return binpow(val, deg - 1) * val % M; ll res = binpow(val, deg >> 1); return (res * res) % M; } //binomial ll modinv(ll n) { return binpow(n, M - 2); } int main() { // your code goes here IOS; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll i, j, t, k, x, y, z, N; cin >> n >> m; ll a[n]; rep(i, n) { cin >> a[i]; } ll cnt[n] = {0}; set<ll> s; rep(i, n + 1) { s.insert(i); } rep(i, m) { s.erase(a[i]); cnt[a[i]]++; } ll mn = *s.begin(); for (i = m; i < n; i++) { cnt[a[i - m]]--; if (cnt[a[i - m]] == 0) s.insert(a[i - m]); s.erase(a[i]); cnt[a[i]]++; mn = min(mn, *s.begin()); } cout << mn; return 0; }
#include<bits/stdc++.h> using namespace std; int a[2000001],sum[2000001],b[2000001]; int n,m,answ=99999999; void add(int x,int v) { while(x<=n+1) { a[x]+=v; x+=x&-x; } } int find(int x) { int ans=0; while(x) { ans+=a[x]; x-=x&-x; } return ans; } int query() { int l=1,r=n+2,mid,ans=n+1; while(l<=r) { mid=(l+r)>>1; if(find(mid)==mid)l=mid+1; else r=mid-1,ans=mid; } return ans; } signed main() { cin>>n>>m; for(int i=1;i<=n;i++) { cin>>b[i]; b[i]++; sum[b[i]]++; if(sum[b[i]]==1)add(b[i],1); if(i-m>=1){sum[b[i-m]]--;if(!sum[b[i-m]])add(b[i-m],-1);} if(i-m+1>=1)answ=min(answ,query()); } cout<<answ-1; }
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define int long long int32_t main() { int n,k; cin>>n>>k; vector<pair<int,int>> v; for(int i=0;i<n;i++) { int a,b; cin>>a>>b; v.push_back({a,b}); } sort(v.begin(),v.end()); int p=0,av=k; for(int i=0;i<n;i++) { int dis=v[i].F-p; if(dis<=av) { av=av-dis; p=v[i].F; av+=v[i].S; } else { p=p+av; av=0; break; } } if(av>0) { p=p+av; } cout<<p; return 0; }
#include <cstdio> #include <climits> #include <cstdlib> #include <cmath> #include <iostream> #include <iomanip> #include <string> #include <vector> #include <algorithm> #include <numeric> #include <utility> #include <queue> #include <deque> #include <stack> #include <map> #include <unordered_map> #include <unordered_set> #include <list> #include <set> #include <bitset> #include <iterator> #define endl '\n' #define fi first #define se second #define pb push_back #define MOD 1000000007 #define len(vc) int(vc.size()) #define fore(x,vc) for(auto &x: vc) #define all(vc) vc.begin(), vc.end() #define allr(vc) vc.rbegin(), vc.rend() #define forr(i,a,b) for(int i = a;i <= b;++i) #define forn(i,n) for(int i = 0; i < int(n);++i) #define gauss(n) (((n) * ((n) + 1)) / 2) #ifdef LOCAL #include "debugger.h" #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) #endif using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int N; int64_t cash; cin >> N >> cash; vector<pair<int64_t,int>> A(N); for(auto &[x,y]: A) cin >> x >> y; sort(all(A)); int64_t ans = 0; for(auto &[x,y]: A) { int64_t dis = x - ans; debug(ans,cash,dis); if(dis <= cash) { ans += dis; cash -= dis; cash += y; } else { cout << ans + cash << endl; return 0; } } cout << ans + cash << endl; return 0; }
#include <iostream> #include <vector> #include <map> #include <bitset> #include <algorithm> #define ll long long #define MODD 998244353 using namespace std; char C[5222][5222]; ll modpow(ll x, ll y) { ll xs = x; ll answer = 1; while(y) { if (y&1) { answer = (answer * xs) % MODD; } y >>= 1; xs = (xs * xs) % MODD; } return answer; } ll dp[5555][5555]; ll Solve(int H,int W) { ll threeinv = modpow(3, MODD-2); ll two_threeinv = (2*threeinv)%MODD; for(int i=H+1;i>=1;i--) for(int j=W+1;j>=1;j--) { if (i>H || j>W) { dp[i][j]=0; continue; } if (i==H && j==W) { dp[i][j]=1; continue; } ll& ret=dp[i][j]; if (C[i][j]=='X') { ret= (dp[i+1][j]+dp[i][j+1])%MODD; } if (C[i][j]=='D') { ret= dp[i+1][j]; } if (C[i][j]=='R') { ret= dp[i][j+1]; } if (C[i][j]=='?') { ret=two_threeinv*(dp[i+1][j]+dp[i][j+1])%MODD; } ret%=MODD; } return dp[1][1]; } int main() { int H,W,K; cin>>H>>W>>K; for(int i=1;i<=H;i++) for(int j=1;j<=W;j++) C[i][j]='?'; int ct=H*W; for(int i=1;i<=K;i++) { int x,y; cin>>x>>y; cin>>C[x][y]; ct--; } for(int i=0;i<=H+1;i++) for(int j=0;j<=W+1;j++) dp[i][j]=-1; ll ans = Solve(H,W); for(int i=1;i<=ct;i++) ans=(ans*3)%MODD; cout << ans << endl; }
#include <bits/stdc++.h> #define lc (o<<1) #define rc ((o<<1)|1) using namespace std; #define DebugP(x) cout << "Line" << __LINE__ << " " << #x << "=" << x << endl typedef long long LL; typedef complex<double> Comp; const int maxn = 100 + 5; const int inf = 0x3f3f3f3f; const int modu = 1e9 + 7; bool g[maxn][maxn]; LL a[maxn]; struct Matrix { LL a[maxn][maxn]; int n, m; Matrix(int n=0, int m=0): n(n), m(m) { memset(a, 0, sizeof(a)); } Matrix operator*(const Matrix &op) { Matrix res(n, op.m); for (int i = 0; i < res.n; ++i) for (int j = 0; j < res.m; ++j) for (int k = 0; k < m; ++k) res.a[i][j] = (res.a[i][j] + a[i][k]*op.a[k][j]) % modu; return res; } }x, trans; int n, m, k; int deg[maxn]; LL qpow(int a, int n) { LL b = a; LL res = 1; while (n) { if (n&1) res = res*b%modu; b = b*b % modu; n >>= 1; } return res; } int main() { // freopen("input.txt", "r", stdin); ios::sync_with_stdio(0); cin.tie(0); memset(g, 0, sizeof(g)); cin >> n >> m >> k; x.n = n; x.m = 1; for (int i = 0; i < n; ++i) cin >> x.a[i][0]; memset(deg, 0, sizeof(deg)); for (int i = 0; i < m; ++i) { int u, v; cin >> u >> v; u--; v--; g[u][v] = g[v][u] = true; deg[u]++; deg[v]++; } LL invm = qpow(2*m, modu-2); for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) if (g[i][j]) trans.a[i][j] = invm; for (int i = 0; i < n; ++i) trans.a[i][i] = ((1 - invm*deg[i])%modu+modu)%modu; trans.n = trans.m = n; Matrix ans(n, n); for (int i = 0; i < n; ++i) ans.a[i][i] = 1; while (k) { if (k&1) ans = ans*trans; trans = trans*trans; k >>= 1; } x = ans*x; for (int i = 0; i < n; ++i) cout << x.a[i][0] << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for(int i = 0; i < n; i++) #define REPR(i, n) for(int i = n - 1; i >= 0; i--) #define FOR(i, m, n) for(int i = m; i <= n; i++) #define FORR(i, m, n) for(int i = m; i >= n; i--) #define SORT(v, n) sort(v, v+n); #define VSORT(v) sort(v.begin(), v.end()); #define VSORTR(v) sort(v.rbegin(), v.rend()); #define ALL(v) (v).begin(),(v).end() using ll = long long; using vll = vector<ll>; using vvll = vector<vector<ll>>; using P = pair<ll, ll>; template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } const ll MOD = 1e9 + 7; const ll INF = 1e18; int main(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(10); ll n; cin >> n; vll a(n); REP(i, n) { cin >> a[i]; } VSORT(a); ll res = a[0] + 1; REP(i, n - 1) { res *= (a[i + 1] - a[i] + 1); res %= MOD; } cout << res << endl; return 0; }
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cmath> #include <vector> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <queue> #include <ctime> #include <cassert> #include <complex> #include <string> #include <cstring> #include <chrono> #include <random> #include <bitset> using namespace std; #ifdef LOCAL #define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr); #else #define eprintf(...) 42 #endif using ll = long long; using ld = long double; using uint = unsigned int; using ull = unsigned long long; template<typename T> using pair2 = pair<T, T>; using pii = pair<int, int>; using pli = pair<ll, int>; using pll = pair<ll, ll>; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll myRand(ll B) { return (ull)rng() % B; } #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define fi first #define se second clock_t startTime; double getCurrentTime() { return (double)(clock() - startTime) / CLOCKS_PER_SEC; } const ll MOD = (ll)1e9 + 7; ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; } ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; } ll mult(ll x, ll y) { return (x * y) % MOD; } ll bin_pow(ll x, ll p) { if (p == 0) return 1; if (p & 1) return mult(x, bin_pow(x, p - 1)); return bin_pow(mult(x, x), p / 2); } ll rev(ll x) { return bin_pow(x, MOD - 2); } const int N = 100100; int n; int a[N]; int main() { startTime = clock(); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", &a[i]); a[n++] = 0; sort(a, a + n); ll ans = 1; for (int i = 1; i < n; i++) ans = mult(ans, a[i] - a[i - 1] + 1); printf("%lld\n", ans); return 0; }
#pragma GCC optimize("O3") #include<bits/stdc++.h> using namespace std; using ll=long long; using P=pair<ll,ll>; template<class T> using V=vector<T>; #define fi first #define se second #define all(v) (v).begin(),(v).end() const ll inf=(1e18); //const ll mod=998244353; const ll mod=1000000007; ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;} ll LCM(ll c,ll d){return c/GCD(c,d)*d;} struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init; 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<class T>void debag(const vector<T> &a){cerr<<"debag :";for(auto v:a)cerr<<v<<" ";cerr<<"\n";} template<class T>void print(const vector<T> &a){for(auto v:a)cout<<v<<" ";cout<<"\n";} int main(){ ll n; cin>>n; V<ll> a(n),sum(n+1,0); ll v=0; for(int i=0;i<n;i++){ cin>>a[i]; a[i]*=2; v+=a[i]; } sort(all(a)); for(int i=0;i<n;i++){ sum[i+1]+=sum[i]+a[i]; } ll ans=inf; for(int i=0;i<n;i++){ ll id=lower_bound(all(a),a[i])-a.begin(); ll res=(sum[n]-sum[id])-(n-id)*a[i]+n*(a[i]/2); chmin(ans,res); } cout<<double(ans)/double(2*n)<<"\n"; }
#include<bits/stdc++.h> using namespace std; #define sz(x) (int)(x).size() #define int long long int #define loop(i,a,b) for(int i=a;i<b;i++) #define scan(arr,n) for (int i = 0; i < n; ++i) cin >> arr[i] #define vi vector<int> #define si set<int> #define pii pair <int, int> #define sii set<pii> #define vii vector<pii> #define mii map <int, int> #define pb push_back #define ff first #define ss second #define all(aa) aa.begin(), aa.end() #define rall(a) a.rbegin() , a.rend() #define read(a,b) int a,b; cin>>a>>b #define readt(a,b,c) int a,b,c; cin>>a>>b>>c #define readf(a,b,c,d) int a,b,c,d; cin>>a>>b>>c>>d; #define print(v) for(auto x:v) cout<<x<<" ";cout<<endl #define printPair(res) for(pair<int,int>& p:res) cout<<p.first<<" "<<p.second<<endl; #define faster ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) const int N=2E6+5; multiset<int> mn[N]; void solve(int test) { int n;cin>>n; cout<<fixed<<setprecision(6); double val=0.0; for(int i=1;i<n;i++) { val+= (n*1.0/i *1.0); } cout<<val; } int32_t main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif faster; //fact(mod); int t=1; // cin>>t; for(int test=1;test<=t;test++) { solve(test); } }
#include <iostream> #include <cstring> #include <cstdio> #include <cmath> using namespace std; const long double pai = acos(-1); struct vect{ long double x, y; vect(double _x = 0, double _y = 0) { x = _x, y = _y; } vect operator* (double k) { return vect{x * k, y * k}; } vect operator+ (vect A) { return vect(x + A.x, y + A.y); } vect operator- (vect A) { return vect(x - A.x, y - A.y); } double operator* (vect A) { return x * A.x + y * A.y; } double operator/ (vect A) { return x * A.y - y * A.x; } bool operator== (vect A) { return x == A.x && y == A.y; } vect rotate(double a){ return vect { x * cos(a) - y * sin(a), x * sin(a) + y * cos(a)}; } }; int n; vect v0, vn, vo, vx; int main(){ cin >> n >> v0.x >> v0.y >> vn.x >> vn.y; vo = (v0 - vn) * 0.5 + vn; // fprintf(stderr, "%.8lf %.8lf\n", vo.x, vo.y); v0 = v0 - vo; vn = vn - vo; // fprintf(stderr, "%.8lf %.8lf %.8lf %.8lf", v0.x, v0.y, vn.x, vn.y); vx = v0.rotate(2.0 * pai / n); vx = vx + vo; // printf("%.8lf %.8lf", vx.x, vx.y); cout.setf(ios::showpoint); cout.precision(11); cout << vx.x << " " << vx.y; }
#include<bits/stdc++.h> using namespace std; #pragma region atcoder //#include <atcoder/convolution> //using namespace atcoder; //using mint = modint998244353; //using mint = modint1000000007; #pragma endregion #pragma region macros using ll = long long; using PII = pair<int, int>; using PLL = pair<ll, ll>; template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; #define overload4(_1,_2,_3,_4,name,...) name #define overload3(_1,_2,_3,name,...) name #define rep1(n) for(ll i=0;i<n;++i) #define rep2(i,n) for(ll i=0;i<n;++i) #define rep3(i,a,b) for(ll i=a;i<b;++i) #define rep4(i,a,b,c) for(ll i=a;i<b;i+=c) #define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__) #define rrep1(n) for(ll i=n;i--;) #define rrep2(i,n) for(ll i=n;i--;) #define rrep3(i,a,b) for(ll i=b;i-->(a);) #define rrep(...) overload3(__VA_ARGS__,rrep3,rrep2,rrep1)(__VA_ARGS__) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) ((int)(x).size()) #define pb push_back #define eb emplace_back #define lb lower_bound #define ub upper_bound #define fi first #define se second #pragma endregion #pragma region debug for var, v, vv #define debug(var) do{std::cerr << #var << " : ";view(var);}while(0) template<typename T> void view(T e){std::cerr << e << std::endl;} template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cerr << e << " "; } std::cerr << std::endl;} template<typename T> void view(const std::vector<std::vector<T> >& vv){cerr << endl;int cnt = 0;for(const auto& v : vv){cerr << cnt << "th : "; view(v); cnt++;} cerr << endl;} #pragma endregion #pragma region int128 std::ostream &operator<<(std::ostream &dest, __int128_t value) { std::ostream::sentry s(dest); if (s) { __uint128_t tmp = value < 0 ? -value : value; char buffer[128]; char *d = std::end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } int len = std::end(buffer) - d; if (dest.rdbuf()->sputn(d, len) != len) { dest.setstate(std::ios_base::badbit); } } return dest; } #pragma endregion const ll mod = 1000000007; const int inf = 1001001001; const ll INF = 1001001001001001001ll; int dx[]={1,0,-1,0}; int dy[]={0,1,0,-1}; template<class T, class K>bool chmax(T &a, const K b) { if (a<b) { a=b; return 1; } return 0; } template<class T, class K>bool chmin(T &a, const K b) { if (b<a) { a=b; return 1; } return 0; } ll rudiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // 20 / 3 == 7 ll rddiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // -20 / 3 == -7 ll power(ll a, ll p){ll ret = 1; while(p){if(p & 1){ret = ret * a;} a = a * a; p >>= 1;} return ret;} ll modpow(ll a, ll p, ll m){ll ret = 1; while(p){if(p & 1){ret = ret * a % m;} a = a * a % m; p >>= 1;} return ret;} /*---------------------------------------------------------------------------------------------------------------------------------*/ const double pi = acos(-1); int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); int n; cin >> n; double a, b, c, d; cin >> a >> b >> c >> d; double cx = (a + c) / 2.0, cy = (b + d) / 2.0; double dx = a - cx, dy = b - cy; double theta = 2*pi/n; cout << cx + cos(theta)*dx - sin(theta)*dy << " " << cy + sin(theta)*dx + cos(theta)*dy << endl; } /* * review you code when you get WA (typo? index?) * int overflow, array bounds * special cases (n=1?) */
#include<iostream> #include<algorithm> #include<vector> #include<string> #include<cmath> #include<iomanip> #include<map> #include<stack> #include<queue> using namespace std; using P = pair<int,int>; using ll = long long; const long double EPS = 1e-10; int main(){ ll N; ll ans = 0; cin >> N; if(N <= 999){ cout << ans << endl; } else if(N <= 999999){ cout << 1 * (N-999) << endl; } else if(N <= 999999999LL){ ans = 999000LL; cout << ans + 2 * (N-999999LL) << endl; } else if(N <= 999999999999LL){ ans = 999000LL; ans += 2 * (999000000LL); cout << ans + 3 * (N-999999999LL) << endl; } else if(N <= 999999999999999LL){ ans = 999000LL; ans += 2 * (999000000LL); ans += 3 * (999000000000LL); cout << ans + 4 * (N-999999999999LL) << endl; } else{ ans = 999000LL; ans += 2 * (999000000LL); ans += 3 * (999000000000LL); ans += 4 * (999000000000000LL); cout << ans + 5 << endl; } }
#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++) #define PI 3.14159265359 const long long INF = 1LL << 60; long long MOD = 1000000007; long long gcd(long long a, long long b) { return b ? gcd(b, a%b) : a; } long long lcm (int a, int b){return (long long) a*b /gcd(a,b);} double radian(double degree){return degree * PI /180.0;} double degree(double radian){return radian * 180.0/PI;} int main(){ string S; cin >>S; int ans = 0; rep(i,S.length()){ if (S.substr(i, 4) == "ZONe") ans++; } cout << ans << endl; }
#include <iostream> using namespace std; int main() { int T, A, C; cin>>T>>A>>C; if((T >= 0 && A <= 100) && (C == 0 || C == 1)) { C == 0 ? (T > A ? cout<<"Takahashi" : cout<<"Aoki") : (A > T ? cout<<"Aoki" : cout<<"Takahashi") ; } return 0; }
/* Hardwork allways pays off */ //You never know how close to the solution you are ,so keep practicing #include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/tree_policy.hpp> #include <functional> // for less #include <iostream> using namespace __gnu_pbds; using namespace std; #define int long long #define ld long double #define pb push_back #define lb lower_bound #define ub upper_bound #define pii pair<int,int> #define endl '\n' #define REP(i,n) for(int i=1;i<=n;i++) #define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower) #define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper) #define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define all(x) (x).begin(), (x).end() #define mod1 998244353 #define mod 1000000007 #define pie 3.141592653589793238 #define printv(x) for(i=0;i<x.size();i++) cout<<x[i]<<" "; #define printA(x,n) for(i=0;i<n;i++) cout<<x[i]<<" "; #define F first #define S second #define vi vector<int> typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; void make_unique(vector<int> vec) { sort(all(vec)); vec.resize(unique(all(vec)) - vec.begin()); } bool isPowerOfTwo(int n) { if(n==0) return false; return (ceil(log2(n)) == floor(log2(n))); } int cceil(int x, int y){ return (x+y-1)/y; } struct Cmp { bool operater(const pair<int,int> &a,const pair<int,int> &b) { return (a.second)<(b.second); } }; bool cmp(const pair<int,int> &a,const pair<int,int> &b) { return (a.second)<(b.second); } signed main() { ios; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif // cout.precision(1); // cout<<fixed; int t=1; // init(); // cin>>t; while(t--) { int n,x,i,j,flag=0,count=0; int a,b,c; cin>>a>>b>>c; if(a==0&&b==0&&c==1) cout<<"Takahashi"<<endl; else if(c==0) { // a--; while(a!=0&&b!=0) { if(i%2==0) {a--; i++; } else {b--; i++; } } if(a>0) cout<<"Takahashi"<<endl; else cout<<"Aoki"<<endl; } else { // b--; while(a!=0&&b!=0) { if(i%2==0) {b--; i++; } else {a--; i++; } } if(a>0) cout<<"Takahashi"<<endl; else cout<<"Aoki"<<endl; } } return 0; }
//Never stop trying #include "bits/stdc++.h" using namespace std; #define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0) typedef long long ll; #define int ll typedef string str; typedef long double ld; typedef pair<int, int> pi; #define fi first #define se second typedef vector<int> vi; typedef vector<pi> vpi; #define pb push_back #define eb emplace_back #define sz(x) (int)x.size() #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) #define endl "\n" #define FOR(i,a,b) for (int i = (a); i < (b); ++i) #define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i) const int MOD = 1e9 + 7; //998244353 const ll INF = 1e18; const int MX = 2e5 + 10; const int nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0}; //right left down up template<class T> using V = vector<T>; template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); } // divide a by b rounded up //constexpr int log2(int x) { return 31 - __builtin_clz(x); } // floor(log2(x)) mt19937 rng(chrono::system_clock::now().time_since_epoch().count()); //mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count()); ll random(ll a, ll b){ return a + rng() % (b - a + 1); } #ifndef LOCAL #define cerr if(false) cerr #endif #define dbg(x) cerr << #x << " : " << x << endl; #define dbgs(x,y) cerr << #x << " : " << x << " / " << #y << " : " << y << endl; #define dbgv(v) cerr << #v << " : " << "[ "; for(auto it : v) cerr << it << ' '; cerr << ']' << endl; #define here() cerr << "here" << endl; void IO() { #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } /////////////////////////ONLY CLEAN CODES ALLOWED///////////////////////// int32_t main() { boost; IO(); int N; cin>>N; vector<pair<int,str>>vec(N); FOR(i,0,N){ cin>>vec[i].se>>vec[i].fi; } sort(rall(vec)); cout << vec[1].se << endl; return 0; } //Change your approach
#include<bits/stdc++.h> typedef long long ll; #define V(a) vector<a> #define P(a,b) pair<a,b> #define A(a) set<a> #define F first #define S second #define mp make_pair #define pb push_back #define in insert #define bp __builtin_popcount #define ppb pop_back #define FOR(a,b,c) for(ll(a) = b; a < c; a++) #define FORN(a,b,c) for(ll(a) = b; a <= c; a++) #define FOREV(a,b,c) for(ll(a)=b; a > c; a--) #define FOREVN(a,b,c) for(ll(a)=b; a >= c; a--) #define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); using namespace std; bool cprime(int x) { if (x == 1) return false; if (x <= 3) return true; if (x % 2 == 0 || x % 3 == 0) return false; for (int i = 5; i <= sqrt(x); i += 6) if (x % i == 0 || x % (i + 2) == 0) return false; return true; } bool cpalin(string s) { int n = s.length(), l; if (n == 1) return true; if (n % 2 == 0) l = n / 2 - 1; else l = (n - 1) / 2 - 1; for (int i = 0; i <= l; i++) if (s[i] != s[n - i - 1]) return false; return true; } void sieveOfEratosthenes(int n) { bool arr[n + 1]; FOR(i, 0, n + 1) arr[i] = true; for (int i = 2; i * i <= n; i++) { if (arr[i] == true) { for (int j = i * i ; j <= n; j += i) { if (arr[j] == true) arr[j] = false; } } } } ll ndivs(ll n) { int N = 1000; bool arr[N]; FOR(i, 0, N) arr[i] = true; for (int i = 2; i * i <= N; i++) { if (arr[i] == true) { for (int j = i * i ; j <= N; j += i) { if (arr[j] == true) arr[j] = false; } } } ll p = 1; FOR(i, 2, N) { if (arr[i] == true && n % i == 0) { ll m = 0; ll cp = n; while (cp % i == 0) { cp /= i; m++; } p *= (m + 1); } } return p; } bool compare( ll a, ll b) // false return swap { return a > b; } ll power( ll a, ll b) { ll p = 1; while (b > 0) { if (b & 1) p *= a; a *= a; b >>= 1; } return p; } string dtobin(ll n) { string s; while (n) { s = to_string((n % 2)) + s; n /= 2; } return s; } ll bintod(string s) { ll n = 0; FOR(i, 0, s.length()) if (s[i] == '0') continue; else n += pow(2, (s.length() - 1 - i)); return n; } ll sdigs(ll n) { int s = 0; while (n) { s += n % 10; n /= 10; } return s; } ll fact(ll p) { int x = 1; FORN(i, 1, p) x *= i; return x; } ll ncr(ll n , ll r) { ll ans = (fact(n) ) / (fact(r) * fact(n - r)); return ans; } int main() { #ifndef ONLINE_JUDGE freopen("Input.txt", "r", stdin); freopen("Output.txt", "w", stdout); #endif int n; cin >> n; V(P(int, string)) v; FOR(i, 0, n) { int x; string s; cin >> s >> x; v.pb(mp(x, s)); } sort(v.begin(), v.end()); cout << v[n - 2].S; return 0; }
#include <bits/stdc++.h> #define rep(i,a,b) for(int i=(a); i<(b); i++) using namespace std; using ll = long long; using vi = vector<int>; using vv = vector<vi>; const int INF = 1001001001; int main(){ int n; cin >> n; vi a(n), b(n); int bmin = INF; rep(i,0,n){ cin >> b[i]; bmin = min(bmin, b[i]); } a[0] = b[0]; rep(j,1,n){ cin >> a[j]; rep(i,1,n){ int c; cin >> c; if(b[0]+c != a[j] + b[i]){ cout << "No" << endl; return 0; } } } cout << "Yes" << endl; rep(i,0,n)cout<<a[i]-(b[0]-bmin)<<(i==n-1?'\n':' '); rep(i,0,n)cout<<b[i]-bmin<<(i==n-1?'\n':' '); return 0; }
#pragma GCC optimize("Ofast") #pragma GCC optimization ("unroll-loops") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define pb push_back const long double Pi = 3.141592653; const ll mod=1e9+7; long long INF = 1000000000000000000; bool cmp(pair<int,int>a,pair<int,int>b) { return (a.first<b.first) || (a.first==b.first && a.second>b.second); } int main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int t=1;//cin>>t; while(t--) { int n;cin>>n; ll a[n][n],sum=0,sum1=0; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { cin>>a[i][j]; sum+=a[i][j]; if(i==j) sum1+=a[i][j]; } } if(sum%n) cout<<"No"; else { ll h=sum/n; if(h!=sum1) cout<<"No"; else { ll pref[n]={0},mi=1e18; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { pref[i]+=a[i][j]; } mi=min(mi,pref[i]); } bool ok=true;sum=0; vector <int>a1(n),b(n); for(int i=0;i<n;i++) { ll g=pref[i]-mi; if(g%n || g<0) ok=false; else { a1[i]=g/n; sum+=a1[i]; } } ll suff[n]={0}; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { suff[i]+=a[j][i]; } } for(int i=0;i<n;i++) { ll g=suff[i]-sum; if(g%n || g<0) ok=false; else { b[i]=g/n; } } if(ok) { cout<<"Yes"<<endl; for(int i=0;i<n;i++) cout<<a1[i]<<" "; cout<<endl; for(int i=0;i<n;i++) cout<<b[i]<<" "; } else cout<<"No"; } } } }
// Atcoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。 // #define _USE_MATH_DEFINES #include<math.h> #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<bitset> #include<stack> #include<memory> #include <sstream> using namespace std; typedef long long ll; #define rad_to_deg(rad) (((rad)/2/M_PI)*360) #define EPS (1e-7) //#define INF (1e9) #define PI (acos(-1)) #define rep(i,n) for(int i=0;i<n;i++) #define show(s) cout<<s<<endl #define chmin(x,y) x=min(x,y) #define chmax(x,y) x=max(x,y) //#define LINF (1e18) #define MOD (1e9+7) #define rrep(i,n) for(int i=n-1;i>=0;--i) #define reps(i,N)for(int i =1;i<=N;++i) #define all(x) (x).begin(),(x).end() //#define int long long const int INF = 1e9; const ll LINF = 1e18; //typedef pair < ll, ll> P; //元がintの分けたものを返す p[0]は1桁目 vector<int> divnum(ll num) { int dig; vector<int>p; while (num) { dig = num % 10; p.push_back(dig); num /= 10; } return p; } //桁数を返す int digiter(ll num) { int dig; vector<int>p; while (num) { dig = num % 10; p.push_back(dig); num /= 10; } return p.size(); } //元がstringの分けたものを返す d[0]は一桁目 vector<int> convertstring(string s) { vector<int> d; ll n = s.size(); reverse(s.begin(), s.end()); rep(i, n) { d.push_back(s[i] - '0'); } return d; } /*long double は%Lf*/ //queue古い順,stack新しい //bool operator<(const Info &another) const {return x > another.x;}//struct(構造体)内の比較演算子のオバーロード int N,K; int A[805][805]; ll Dcnt[805][805]; void CSum2D(int H,int W) { rep(i, H)rep(j, W) { if (i > 0)Dcnt[i][j] += Dcnt[i - 1][j]; if (j > 0)Dcnt[i][j] += Dcnt[i][j - 1]; if (i > 0 && j > 0)Dcnt[i][j] -= Dcnt[i - 1][j - 1]; } } int32_t main() { cin >> N >> K; rep(i, N)rep(j, N)cin >> A[i][j]; int ul = INF, bl = -1; while (ul - bl > 1) { int mid = (ul + bl) >> 1; rep(i, N) { rep(j, N) { if (A[i][j] <= mid)Dcnt[i][j] = 1; else Dcnt[i][j] = 0; } } CSum2D(N, N); int thres = K*K-K * K / 2; rep(i, N)rep(j, N) { if (i + K - 1 >= N || j + K - 1 >= N)continue; ll sum = Dcnt[i + K - 1][j + K - 1]; if (i > 0)sum -= Dcnt[i - 1][j+K-1]; if (j > 0)sum -= Dcnt[i+K-1][j - 1]; if (i > 0 && j > 0)sum += Dcnt[i - 1][j - 1]; if (sum >= thres) { ul = mid; break; } } if(ul!=mid)bl = mid; } cout << ul << endl; }
/* Author: Nguyen Tan Bao Status: Idea: */ #include <bits/stdc++.h> #define FI first #define SE second #define EPS 1e-9 #define ALL(a) a.begin(),a.end() #define SZ(a) int((a).size()) #define MS(s, n) memset(s, n, sizeof(s)) #define FOR(i,a,b) for (int i = (a); i <= (b); i++) #define FORE(i,a,b) for (int i = (a); i >= (b); i--) #define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++) //__builtin_ffs(x) return 1 + index of least significant 1-bit of x //__builtin_clz(x) return number of leading zeros of x //__builtin_ctz(x) return number of trailing zeros of x using namespace std; using ll = long long; using ld = double; typedef pair<int, int> II; typedef pair<II, int> III; typedef complex<ld> cd; typedef vector<cd> vcd; const ll MODBASE = 1000000007LL; const int MAXN = 110; const int MAXM = 1000; const int MAXK = 16; const int MAXQ = 200010; int main() { ios::sync_with_stdio(0); cin.tie(nullptr); char ch, ch2; cin >> ch >> ch2; if (ch == 'Y') cout << char(ch2 - 32); else cout << ch2; return 0; }
#include <iostream> #include <cstdio> using namespace std; const int N = 1e5 + 100; int n, m; int cnt[2]; char s[30]; int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%s", s + 1); int tmp = 0; for (int j = 1; j <= m; j++) { if (s[j] == '1') tmp++; } tmp &= 1; cnt[tmp]++; } cout << cnt[0] * 1ll * cnt[1] << endl; }
#include <bits/stdc++.h> using namespace std; #define eps 1e-9 #define INF 2000000000 // 2e9 #define LLINF 2000000000000000000ll // 2e18 (llmax:9e18) #define all(x) (x).begin(), (x).end() #define sq(x) ((x) * (x)) #define rep(i, x) for (int i = 0; i < (int)(x); i++) #define drep(i, x) for (int i = ((int)(x)-1); i >= 0; i--) #define popcount __builtin_popcount #define next __next #define prev __prev #ifndef LOCAL #define dmp(...) ; #else #define dmp(...) \ cerr << "[ " << #__VA_ARGS__ << " ] : " << dump_str(__VA_ARGS__) << endl #endif // ---------------- Utility ------------------ template <class T> bool chmin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } template <class T> bool chmax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } template <class T> using MaxHeap = priority_queue<T>; template <class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>; template <class T> vector<T> vect(int len, T elem) { return vector<T>(len, elem); } // ----------------- Input ------------------- template <class T, class U> istream &operator>>(istream &is, pair<T, U> &p) { return is >> p.first >> p.second; } template <class T> istream &operator>>(istream &is, vector<T> &vec) { for (int i = 0; i < vec.size(); i++) is >> vec[i]; return is; } // ----------------- Output ------------------ template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << p.first << ',' << p.second; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &e : v) os << e << " "; return os; } template <class T> ostream &operator<<(ostream &os, const deque<T> &d) { for (const T &e : d) os << e << " "; return os; } template <class T> ostream &operator<<(ostream &os, const set<T> &s) { os << "{ "; for (const T &e : s) os << e << " "; return os << "}"; } template <class T, class U> ostream &operator<<(ostream &os, const map<T, U> &m) { os << "{ "; for (const auto &[key, val] : m) os << "( " << key << " -> " << val << " ) "; return os << "}"; } template <class TupleTy, size_t... I> void dump_tuple(ostream &os, const TupleTy t, std::index_sequence<I...>) { (..., (os << (I == 0 ? "" : ",") << std::get<I>(t))); } template <class... Args> ostream &operator<<(ostream &os, const tuple<Args...> &t) { os << "("; dump_tuple(os, t, std::make_index_sequence<sizeof...(Args)>()); return os << ")"; } void dump_str_rec(ostringstream &) {} template <class Head, class... Tail> void dump_str_rec(ostringstream &oss, Head &&head, Tail &&... tail) { oss << ", " << head; dump_str_rec(oss, forward<Tail>(tail)...); } template <class T, class... U> string dump_str(T &&arg, U &&... args) { ostringstream oss; oss << arg; dump_str_rec(oss, forward<U>(args)...); return oss.str(); } // --------------- Fast I/O ------------------ void fastio() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20); } // ------------ End of template -------------- #define endl "\n" using ll = long long; using pii = pair<int, int>; void solve() { string s; cin >> s; for (int i = 0; i < s.size(); i++) { if (s[i] == '.') break; cout << s[i]; } cout << endl; return; } int main() { fastio(); solve(); // int t; cin >> t; while(t--)solve(); // int t; cin >> t; // for(int i=1;i<=t;i++){ // cout << "Case #" << i << ": "; // solve(); // } 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, k; cin >> n >> k; vector<int> a(n); for (auto& el : a) cin >> el; sort(all(a)); vector<int> bx(k); int prev = -1; int pos = 0; for (auto el : a) { if (el != prev) { pos = 0; } prev = el; if (pos == k) { continue; } if (pos == 0 && el > bx[pos]) { break; } if (el == bx[pos]) { ++bx[pos++]; } } cout << accumulate(all(bx), 0ll); } 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; }
/* Stay motivated and keep working hard */ #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 int long long #define pb push_back #define cntbit __builtin_popcount #define fr first #define mem(arr, val) memset(arr, val, sizeof(arr)) #define sc second #define sz(v) ((int)(v).size()) #define mp make_pair #define all(a) a.begin(),a.end() #define rep(i,a,n) for(int i=a;i<n;i++) #define repd(i,a,p) for(int i=a-1;i>=p;i--) #define md 998244353 #define vi vector<int> #define vp vector<pair<int,int> > #define ml map<int,int> #define MPI 3.1415926536 #define in insert #define endl "\n" #define ub upper_bound #define lb lower_bound #define gcd __gcd #define setval(a,b) memset(a,b,sizeof(a)) #define lwr lower_bound #define pii pair<int,int> #define upr upper_bound #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> //CANDIDATE MASTER TOH BNKE RHUNGA //dsu is pel concept //KMP is pel concept int k,n,t,i,j=0,m; const int N=1e6+5; int md2; inline void add(int &a, int b) { a += b; if (a >= md) a -= md; } inline void sub(int &a, int b) { a -= b; if (a < 0) a += md; } inline int mul(int a, int b) { return (int) ((long long) a * b % md); } inline int power(int a, long long b) { int res = 1; while (b > 0) { if (b & 1) { res = mul(res, a); } a = mul(a, a); b >>= 1; } return res; } inline int inv(int a) { a %= md; if (a < 0) a += md; int b = md, u = 0, v = 1; while (a) { int t = b / a; b -= t * a; swap(a, b); u -= t * v; swap(u, v); } if (u < 0) u += md; return u; } void extgcd(int a,int b, int& x,int& y) { if(b != 0){ extgcd(b, a % b, y, x); y -= (a / b) * x; }else{ x = 1; y = 0; } } signed main() { ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); cin>>n>>k; vi v(n); multiset <int> st; for(int i=0;i<n;i++) { cin>>v[i]; st.insert(v[i]); } int ans=0; while(k) { for(i=0;i<=n;i++) { auto it=st.find(i); if(it==st.end()) break; st.erase(it); } ans+=i; k--; } cout<<ans<<endl; }
#include <iostream> #include <cmath> int main(void){ int N,K,M,l,i; double SUM = 0.0; double j,k; int *A; std::cin >> N >> K >> M; A = new int[N-2]; i = 0; while(std::cin>>l){ A[i] = l; i++; SUM = SUM + l; } j = M * N - SUM; if (j < 0){ j = 0; } if(j > K){ j = -1; } std::cout << std::ceil(j); return 0; }
#include<iostream> #include<stdio.h> #include<stdlib.h> #include<iostream> #include<math.h> using namespace std; int main() { long double a, b, r, u, l; unsigned long long c = 0; long n, m; cin >> a >> b >> r; r += 1E-14; n = ceil((a - r)); m = floor(a + r); for (long i = n; i <= m ; i++) { u = sqrt((r * r) - (i - a)*(i - a)); u = floor(b + u); l = sqrt((r * r) - (i - a) * (i - a)); l = ceil(b - l); c += u - l + 1; } cout << c; return 0; }
#include <bits/stdc++.h> #define int long long #define double long double using namespace std; const int MOD = 1000000007; const int INF = 1000000000000000000; using Graph = vector<vector<int>>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) signed main(){ string S; cin >> S; for( int i = 0; i < 15; i++ ){ int N = S.size(); bool fg = 1; for( int i = 0; i < N/2; i++ ){ if( S[i] != S[N-1-i] ){ fg = 0; break; } } if( fg ){ cout << "Yes" << endl; return 0; } S = "0" + S; } cout << "No" << endl; }
#include <bits/stdc++.h> using namespace std; using Int = long long; const char newl = '\n'; template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;} template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);} template<typename T=int> vector<T> read(size_t n){ vector<T> ts(n); for(size_t i=0;i<n;i++) cin>>ts[i]; return ts; } struct UnionFind{ int num; vector<int> rs,ps; UnionFind(int n):num(n),rs(n,1),ps(n,0){ iota(ps.begin(),ps.end(),0); } int find(int x){ return (x==ps[x]?x:ps[x]=find(ps[x])); } bool same(int x,int y){ return find(x)==find(y); } void unite(int x,int y){ x=find(x);y=find(y); if(x==y) return; if(rs[x]<rs[y]) swap(x,y); rs[x]+=rs[y]; ps[y]=x; num--; } int size(int x){ return rs[find(x)]; } int count() const{ return num; } }; template<typename T, T MOD = 1000000007> struct Mint{ static constexpr T mod = MOD; T v; Mint():v(0){} Mint(signed v):v(v){} Mint(long long t){v=t%MOD;if(v<0) v+=MOD;} Mint pow(long long k){ Mint res(1),tmp(v); while(k){ if(k&1) res*=tmp; tmp*=tmp; k>>=1; } return res; } static Mint add_identity(){return Mint(0);} static Mint mul_identity(){return Mint(1);} Mint inv(){return pow(MOD-2);} Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;} Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;} Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;} Mint& operator/=(Mint a){return (*this)*=a.inv();} Mint operator+(Mint a) const{return Mint(v)+=a;} Mint operator-(Mint a) const{return Mint(v)-=a;} Mint operator*(Mint a) const{return Mint(v)*=a;} Mint operator/(Mint a) const{return Mint(v)/=a;} Mint operator-() const{return v?Mint(MOD-v):Mint(v);} bool operator==(const Mint a)const{return v==a.v;} bool operator!=(const Mint a)const{return v!=a.v;} bool operator <(const Mint a)const{return v <a.v;} static Mint comb(long long n,int k){ Mint num(1),dom(1); for(int i=0;i<k;i++){ num*=Mint(n-i); dom*=Mint(i+1); } return num/dom; } }; template<typename T, T MOD> constexpr T Mint<T, MOD>::mod; template<typename T, T MOD> ostream& operator<<(ostream &os,Mint<T, MOD> m){os<<m.v;return os;} //INSERT ABOVE HERE signed main(){ cin.tie(0); ios::sync_with_stdio(0); int n; cin>>n; auto fs=read(n); UnionFind uf(n); for(int i=0;i<n;i++){ fs[i]--; uf.unite(i,fs[i]); } using M = Mint<int, 998244353>; cout<<M(2).pow(uf.count())-M(1)<<newl; return 0; }
#include <iostream> #include <deque> #include <unordered_map> #include <unordered_set> #include <vector> #include <memory> #include <limits> #include <queue> #include <algorithm> using namespace std; using ull = unsigned long long; using ui = unsigned int; int res; void bs(const vector<int>& nums, int idx, int prexor) { int size = nums.size(); if(idx == size) { // todo res = min(res, prexor); return; } int now_or = 0; for(int i = idx; i < size; i++) { now_or |= nums[i]; bs(nums, i + 1, prexor ^ now_or); } } void func() { int N; cin >> N; vector<int> nums; for(int i = 0; i < N; i++) { int v; cin >> v; nums.push_back(v); } res = INT32_MAX; bs(nums, 0, 0); cout << res << endl; } int main() { func(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<vector<vector<long double> > > vvvld; typedef vector<vector<long double> > vvld; typedef vector<vector<vector<int> > > vvvi; typedef vector<vector<int> > vvi; typedef long double ld; #define rep(i,n) for (int i = 0; i< (int)(n); i++) int main(){ int n; cin>>n; vector<ll> a(n); vector<bitset<30>> bi; for(int i =0; i<n; i++){ cin>>a.at(i); bitset<30> bb(a.at(i)); bi.push_back(bb); } ll lans =1e18; for(int i =0; i<(1<<n-1); i++){ bitset<20> b(i); queue<bitset<30>> q; vector<bitset<30>> bt = bi; for(int j =0; j<n-1; j++){ if(b.test(j)){ q.push(bt.at(j)); } else{ bt.at(j+1) = bt.at(j+1)|bt.at(j); } } q.push(bt.at(n-1)); bitset<30> ans; ans = q.front();q.pop(); while(!q.empty()){ bitset<30> tmp = q.front();q.pop(); ans = ans^tmp; } ll ltmp = 0; ll two = 1; for(int i =0; i<30; i++){ if(ans.test(i)) ltmp += two; two*=2; } lans = min(ltmp,lans); } cout<<lans<<endl; }
#include <bits/stdc++.h> using namespace std; int main() { double x, y, z; scanf("%lf%lf%lf", &x, &y, &z); printf("%d", (int)max(0.0,ceil(z*(y/x))-1)); }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef double db; #define inf ll(1e18) int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int T; T=1; while(T--){ int x,y,z; cin>>x>>y>>z; int answer=0; for(int i=1; i<=1000000; i++){ int var=x*i; int temp=y*z; if(var<temp){ answer=max(answer,i); } } cout<<answer; } return 0; }
//ABHISHEK AGRAWAL,BIT mesra// //Newbie......You have to be odd to be no. ONE :)// //Authhor: Abhishekagrawal //Date: 20/02/2021 //Time: 17:30:13 #include<bits/stdc++.h> using namespace std; #define ll long long int #define ld long double #define fl float #define vll vector<ll> #define pii pair<int,int> #define vpll vector<pair<ll,ll>> #define pb push_back #define f first #define s second #define mll map<ll,ll> #define mp make_pair #define sp(n) fixed<<setprecision(n) #define mod (ll)1000000007 #define sortv(v) sort(v.begin(),v.end()) #define INF (ll)(1e15) #define loop(i,n) for(int i=0;i<n;i++) #define loop1(i,n) for(int i=1;i<=n;i++) #define rloop(n,i) for(int i=n-1;i>=0;i--) #define sorta(a) sort(a,a+n,greater<ll>()) #define countone(n) __builtin_popcount(n) #define numoftrailzero(n) __builtin_ctz(n) #define maxpowoftwo(n) __builtin_clz(n) #define leastindexwithone(n) __builtin_ffs(n) #define what_is(x) cerr << #x << " is " << x << endl; #define pfv(v) cout<<v.size()<<"\n";loop(i,v.size()) cout<<v[i]<<" ";cout<<"\n"; #define pv(v) loop(i,v.size()) cout<<v[i]<<" "; #define all(v) v.begin(),v.end() #define mset(dp,val) memset(dp,val,sizeof(dp)) ll test,n;ll sum,ans; // #ifdef TESTING // #define DEBUG fprintf(stderr, "====TESTING====\n") // #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl // #define debug(...) fprintf(stderr, __VA_ARGS__) // #else // #define DEBUG // #define VALUE(x) // #define debug(...) // #endif void the_happiest_place_on_earth() { ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #ifdef ENABLE_FILE_IO freopen("out.txt", "r", stdin); freopen("out1.txt", "w", stdout); #endif } // bool comp(const pair<ll,ll> &a, const pair<ll,ll> &b){ // if(a.s+2*a.f==b.s+2*b.f) return a.f>b.f; // return (a.s+2*a.f>b.s+2*b.f); // } const int N=200040;ll a[N],b[N],c[N],par[N],Size[N],present[N],color[N]; ll power(ll a,ll b,ll M){a%=M;ll res=1;while(b>0){if(b%2 ==1){res=(res*a)%M;}a=(a*a)%M;b/=2;} return res;} void testcase(){ ll m; cin>>n>>m;ll k;cin>>k; ll mo=998244353; if(n==1){ cout<<power(k,m,mo); return; } if(m==1){ cout<<power(k,n,998244353); return; } ans=0; loop1(i,k){ ll n1=power(i,n,mo); ll n2=power(i-1,n,mo); n1=((n1-n2)%mo+mo)%mo; n2=power(k-i+1,m,mo); n1=(n1*n2)%mo; (ans+=n1)%=mo; } cout<<ans<<"\n"; return; } int main(){ the_happiest_place_on_earth(); // Today's thought: Push yourself,because no one else is going to do it for you. // Things are not always #000000 and #FFFFFF // START OF PROGRAM LOGIC // g++ -o a BB.cpp -DENABLE_FILE_IO;./a // g++ -std=c++17 -Wshadow -Wall -g -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -o a file_name.cpp;./a test=1;int t=0; // cin>>test; while(test--){ //cout<<"Case #"<<++t<<": "; testcase(); } cerr << "Time : " << 1000 *((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; // //END OF PROGRAM LOGIC return 0; } /* stuff you should look for * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * WRITE STUFF DOWN * DON'T GET STUCK ON ONE APPROACH */
#include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <complex> #include <deque> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; const ll MOD = 998244353; ll mod_pow(ll x, ll n) { ll res = 1; while (n > 0) { if (n & 1) res = res * x % MOD; x = x * x % MOD; n >>= 1; } return res; } int main() { int n, m, k; cin >> n >> m >> k; if (n == 1 && m == 1) { cout << k << endl; return 0; } if (n == 1) { swap(n, m); } ll sumP = 0; ll ans = 0; for (int limit = 1; limit <= k; limit++) { ll p = (mod_pow(limit, n) - sumP + MOD) % MOD; sumP += p; sumP %= MOD; if (m == 1) { ans += p; ans %= MOD; } else { ans += p * mod_pow(k - limit + 1, m); ans %= MOD; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = a; i < (b); ++i) #define rrep(i, a, b) for (int i = a; i >= (b); --i) #define all(x) x.begin(), x.end() #define sz(x) (int)(x).size() typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; template <typename T> void update_max(T& a, T b) { if (b > a) a = b; } template <typename T> void update_min(T& a, T b) { if (b < a) a = b; } struct Tree { typedef int T; static constexpr T unit = 0; T f(T a, T b) { return a ^ b; } // (any associative fn ) vector<T> s; int n; Tree(int n = 0, T def = unit) : s(2 * n, def), n(n) {} void update(int pos, T val) { for (s[pos += n] = val; pos /= 2;) s[pos] = f(s[pos * 2], s[pos * 2 + 1]); } T query(int b, int e) { // query [ b , e) T ra = unit, rb = unit; for (b += n, e += n; b < e; b /= 2, e /= 2) { if (b % 2) ra = f(ra, s[b++]); if (e % 2) rb = f(s[--e], rb); } return f(ra, rb); } }; int main() { #ifdef LOCAL_PROJECT freopen("input.txt", "r", stdin); #endif ios::sync_with_stdio(false); cin.tie(0); int n, q, a; cin >> n >> q; Tree tree(n); rep(i, 0, n) { cin >> a; tree.update(i, a); } int t, x, y; rep(i, 0, q) { cin >> t >> x >> y; if (t == 1) { tree.update(x - 1, tree.s[x - 1 + tree.n] ^ y); } else { cout << tree.query(x - 1, y) << endl; } } return 0; }
#ifdef _DEBUG #include "../../../library/src/debug_template.cpp" #define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__) #else #define DMP(...) ((void)0) #endif #include <cassert> #include <cstdio> #include <cmath> #include <iostream> #include <iomanip> #include <string> #include <vector> #include <set> #include <map> #include <unordered_map> #include <queue> #include <numeric> #include <algorithm> #include <bitset> #include <functional> #include <array> using namespace std; using lint = long long; constexpr int MOD = 1000000007, INF = 1010101010; constexpr lint LINF = 1LL << 60; struct init { init() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } init_; template<class T> class FenwickTree { private: int n; vector<T> bit; public: explicit FenwickTree(int sz, T &&x = T(0)) : n(sz), bit(n + 1) { for (int i = 0; i < n; i++) add(i, x); } T sum(int k) const { T res = 0; for (k--; k >= 0; k = (k & (k + 1)) - 1) res ^= bit[k]; return res; } T sum(int l, int r) const { return sum(r) ^ sum(l); } void add(int k, const T &x) { for (; k < n; k |= k + 1) bit[k] ^= x; } void set(int k, const T &x) { add(k, x - sum(k, k + 1)); } }; int main() { int N, Q; cin >> N >> Q; vector<int> A(N); for (int i = 0; i < N; i++) cin >> A[i]; vector<array<int, 3>> TXY(Q); for (int i = 0; i < Q; i++) cin >> TXY[i][0] >> TXY[i][1] >> TXY[i][2]; FenwickTree<int> ft(N); for (int i = 0; i < N; i++) { ft.set(i, A[i]); } for (int i = 0; i < Q; i++) { auto[t, x, y] = TXY[i]; t--, x--; if (t) { cout << ft.sum(x, y) << '\n'; } else { ft.add(x, y); } } return 0; }
#include <iostream> #include <vector> using namespace std; #define FOR(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 unsigned long long ull; typedef long double ld; int main() { int n; cin >> n; vector<int> cnt(2000001, 0); int pi; int x = 0; REP(i, n) { cin >> pi; cnt[pi]++; while (cnt[x] > 0) { x++; } cout << x << endl; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; void solve() { string t; cin >> t; int n = t.size(); string s = "atcoder", p = t; sort(p.rbegin(), p.rend()); if (p <= s) { cout << -1 << endl; return; } if (t > s) { cout << 0 << endl; return; } int m = n; for (int i = n - 1; i >= 0; i--) { for (int j = min(6, i - 1); j >= 0; j--) { swap(t[i], t[j]); if (s < t) { m = min(m, i - j); } swap(t[i], t[j]); } } cout << m << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { solve(); } return 0; }
#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <cassert> #include <algorithm> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> #define repi(i,a,b) for(ll i=(a);i<(b);++i) #define rep(i,a) repi(i,0,a) #define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i) #define repd(i,a) repdi(i,a,0) #define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it ) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define endl '\n' #define debug(x) std::cerr << #x << " = " << (x) << endl; using ll = long long; using P = std::pair<ll, ll>; constexpr ll INF = 1ll<<60; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template<class S, class T> std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a ) { std::cout << '(' << a.first << ", " << a.second << ')'; return out; } template<class T> std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a ) { std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; } const ll mod = 998244353; struct mint { ll x; // typedef long long ll; mint(ll x=0):x((x%mod+mod)%mod){} mint operator-() const { return mint(-x);} mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;} mint operator+(const mint a) const { return mint(*this) += a;} mint operator-(const mint a) const { return mint(*this) -= a;} mint operator*(const mint a) const { return mint(*this) *= a;} mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod-2);} mint& operator/=(const mint a) { return *this *= a.inv();} mint operator/(const mint a) const { return mint(*this) /= a;} }; std::istream& operator>>(std::istream& is, mint& a) { return is >> a.x;} std::ostream& operator<<(std::ostream& os, const mint& a) { return os << a.x;} struct combination { std::vector<mint> fact, ifact; combination(int n):fact(n+1),ifact(n+1) { assert(n < mod); fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i; ifact[n] = fact[n].inv(); for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i; } mint operator()(int n, int k) { if (k < 0 || k > n) return 0; return fact[n]*ifact[k]*ifact[n-k]; } }; ll N, M; mint mp[5010]; int main() { std::cin >> N >> M; mp[0] = 1; rep( i, N ) mp[i+1] = mp[i]*M; mint ans = mint(N)*mint(M).pow(N); repi( x, 1, M+1 ) { mint dp = 1; repi( w, 1, N ) { ans -= dp*mp[N-(w+1)]*(N-w); dp *= M-x; } } std::cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; // common mod numbers const int MOD1=1000000007; const int MOD2 = 998244353; // loop definitions #define for0(i, n) for (int i = 0; i < (int)(n); ++i) // 0 based indexing #define for1(i, n) for (int i = 1; i <= (int)(n); ++i) // 1 based indexing #define forc(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i) // closed interver from l to r r inclusive #define forr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i) // reverse 0 based. #define forr1(i, n) for (int i = (int)(n); i >= 1; --i) // reverse 1 based //short hand for usual tokens #define pb push_back #define fi first #define se second //shorthand for commonly used types typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> ii; typedef vector<ii> vii; typedef long long ll; typedef vector<ll> vll; typedef vector<vll> vvll; typedef double ld; //PRE-DEFINED FUNCIONS // modular inverse int modInverse(int a, int m) { for (int x = 1;x<m;x++) if (((a%m) * (x%m)) % m == 1) return x; return -1; } int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } //USER-DEFINED FUNCTIONS int main() { ios::sync_with_stdio(0); cin.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif //fixing precision cout.precision(10); cout << fixed; //start here int a,b,c; cin>>a>>b>>c; cout<<a+b+c - min(min(a,b), c)<<endl; return 0; }
#include <iostream> #include <iostream> #include <vector> #include <string> #include <algorithm> #include <set> #include <queue> #include <map> using namespace std; typedef long long int ll; typedef pair <int,int> pii; typedef pair<ll,ll> pll; /*bool compare_function(const pair<int, int> a, const pair<int, int> b) { return a.first < b.first; }*/ // use case //sort(V.begin(), V.end(), compare_function); /*struct compare { bool operator ()(const pair<int, int> &a, const pair<int, int> &b) { if (a.second-a.first==b.second-b.first) { return a.first>b.first; } return a.second-a.first < b.second-b.first;} }; priority_queue <pair<int,int>, vector <pair<int,int>>, compare> Q;*/ void print(set <ll> X) { for (ll i:X) { cout<<i<<" "; } cout<<endl; return; } ll solve(vector <ll> &A, ll t) { int k=(int)A.size(); ll s=0; for (int i=0;i<k;i++) {s+=A[i];} if (s<=t) {return s;} set <ll> X; X.insert(0LL); for (int i=0;i<k/2;i++) { set <ll> Y; ll m=*X.rbegin(); if (m==t) {return t;} for (ll x:X) { if (A[i]+x<=t) { Y.insert(A[i]+x); if (A[i]+x>m) {m=A[i]+x;} } } for (ll y:Y) {X.insert(y);} } set <ll> Z; Z.insert(0LL); for (int i=k/2;i<k;i++) { set <ll> Y; ll m=*X.rbegin(); if (m==t) {return t;} for (ll x:Z) { if (A[i]+x<=t) { Y.insert(A[i]+x); if (A[i]+x>m) {m=A[i]+x;} } } for (ll y:Y) {Z.insert(y);} } ll ats=*X.rbegin(); ll z=*Z.rbegin(); //print(X); //print(Z); ats=max(ats,z); for (ll x:X) { auto it=Z.upper_bound(t-x); if (it!=Z.begin()) { it--;z=*it; if (x+z<=t) {ats=max(ats,x+z);} } z=*it; while (it!=Z.end() && z+x<=t) {ats=max(ats,x+z);it++;if (it!=Z.end()) {z=*it;}} } return ats; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; ll t; cin>>n>>t; vector <ll> A; for (int i=0;i<n;i++) { ll a; cin>>a; if (a<=t) {A.push_back(a);}} sort(A.begin(),A.end(),greater<ll>()); ll ats=solve(A,t); cout<<ats<<endl; return 0; }
/** * author: said_v15 **/ #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset; typedef long long ll; #define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) #define forn for(int i=0;i<n;i++) #define pb push_back #define sc second #define f first #define kek cout<<"\n"; #define fla cout<<endl; #define debug(x) cout << #x << " is " << x << '\n'; #define rep(i,a,b) for(int i=a;i<b;i++) #define all(v) ((v).begin()), ((v).end()) #define int ll const ll MOD = (ll) 1e9 + 7; const ll MOD1 = 998244353; const int MAXN = 1000010; const int INF = 1e9; const ll LL_INF=1e18; const double pi=3.1415926535; int divide(int a, int b) { return (a+b-1)/b; } int32_t main() { #if defined(_DEBUG) freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fast; // cout << fixed << setprecision(12) << ans; // string al = "abcdefghijklmnopqrstuvwxyz"; int questions=1; // cin>>questions; while(questions--) { int n,t; cin>>n>>t; vector<int> v(n); forn cin>>v[i]; int to=n/2; int sz=n-to; vector<int> sum; for(int i=0;i<(1<<to);i++) { int add=0; for(int j=0;j<to;j++) if(i&(1<<j)) add+=v[j]; sum.push_back(add); } sort(all(sum)); int ans=0; for(int i=0;i<(1<<sz);i++) { int add=0; for(int j=to;j<n;j++) if(i&(1<<(j-to))) add+=v[j]; int ost=t-add; int near=upper_bound(all(sum),ost)-sum.begin(); near--; if(near==-1) continue; ans=max(ans, add+sum[near]); } cout<<ans; } // !!! LOOK AT NUMBER OF QUESTIONS IN A PROBLEM !!! (cin>>questions) // cout <<"Runtime is: "<<clock() * 1.0 / CLOCKS_PER_SEC <<endl; return 0; }
#include <iostream> #include <algorithm> #include <cstring> #include <cstdio> #define int long long #define mid (l+r>>1) using namespace std; int read(){ int x = 1,a = 0;char ch = getchar(); while (ch < '0'||ch > '9'){if (ch == '-') x = -1;ch = getchar();} while (ch >= '0'&&ch <= '9'){a = a*10+ch-'0';ch = getchar();} return x*a; } const int maxn = 505,mod = 998244353; int n,m; char s[maxn][maxn]; int dp[maxn][maxn][5],a[maxn][maxn]; signed main(){ n = read(),m = read(); for (int i = 1;i <= n;i++) scanf ("%s",s[i]+1); for (int i = 1;i <= n;i++) for (int j = 1;j <= m;j++){ if (s[i][j] == 'R') a[i][j] = 0; else if (s[i][j] == 'B') a[i][j] = 1; else a[i][j] = 2; } // for (int i = 1;i <= n;i++){ for (int j = 1;j <= m;j++) cout<<a[i][j]<<" "; // cout<<endl;} for (int i = 1;i <= n;i++){ for (int j = m;j >= 1;j--){ dp[i][j][a[i][j]] = 1; if (i > 1&&j < m) dp[i][j][0] |= dp[i-1][j+1][0],dp[i][j][1] |= dp[i-1][j+1][1]; } } int res = 0; for (int i = 1;i <= n;i++){ if (!dp[i][1][0]&&!dp[i][1][1]) res++; if (dp[i][1][0]&&dp[i][1][1]){ printf("0\n"); return 0; } } for (int i = 2;i <= m;i++){ // cout<<dp[n][i][0]<<" "<<dp[n][i][1]<<endl; if (!dp[n][i][0]&&!dp[n][i][1]) res++; if (dp[n][i][1]&&dp[n][i][0]){ printf("0\n"); return 0; } } int ans = 1; // cout<<res<<endl; for (int i = 1;i <= res;i++) ans = 1ll*2*ans % mod; printf("%lld\n",ans); 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 CL(A,I) (memset(A,I,sizeof(A))) #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() const string rps = "RSPRSP"; bool le(char a, char b) { if(a==b) return 1; for(ll i=0; i < (ll)rps.size(); i+=2) { if(rps[i]==a && rps[i+1]==b) return 1; if(rps[i]==b && rps[i+1]==a) return 0; } } ll n,k; string s; const ll N = 107; ll pw[N]; char DP[N][N]; char dp(ll k, ll pref) { char &ret = DP[k][pref]; if(~ret) return ret; if(k==0) return ret = s[pref]; char l = dp(k-1, pref); char r = dp(k-1, (pref+pw[k-1])%n); if(le(l,r)) return ret=l; else return ret=r; } int main(void) { ios_base::sync_with_stdio(false); CL(DP,-1); cin >> n >> k >> s; pw[0] = 1; FOR(i,1,N) pw[i]=(pw[i-1]*2)%n; cout << dp(k, 0) << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for(int i = 0; i < n; i++) using namespace std; typedef long long ll; const int INF = 1 << 30; const ll LLINF = 1LL << 62; int mod = 1000000007; ll COM[250][250]; void COMinit(){ COM[1][0] = COM[1][1] = 1; for(int i = 2; i < 250; i++){ for(int j = 0; j <= i; j++){ if(j == 0 || j == i) COM[i][j] = 1; else COM[i][j] = COM[i-1][j-1] + COM[i-1][j]; } } } int main(void){ ios::sync_with_stdio(false); cin.tie(nullptr); ll L; cin >> L; COMinit(); L -= 12; cout << COM[L+11][11] << endl; return 0; }
#include<bits/stdc++.h> #define ss second #define ff first #define Mem(x,val) memset(x,val,sizeof x) #define pb push_back #define all(v) v.begin(),v.end() #define unik(v) v.erase(unique(v.begin(),v.end()),v.end()) #define cerr(x) cerr << __LINE__ << " th Line : " << #x << " = " << x << "\n" #define debug(a,b) cerr << #a<<" = "<<a<<" | "<<#b<<" = "<<b<<'\n' #define endl '\n' #define SZ(a) ((int)a.size()) using namespace std; using ll = long long; typedef pair<int, int> pi; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll; const int nax = 300000+10; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int l; cin >> l; ll ans = 1; for(int i=1; i<12; i++){ ans *= l - i; ans /= i; } cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long int ll; // template {{{ 0 // using {{{ 1 using ll = long long int; using pii = pair<int,int>; using pll = pair<ll,ll>; using vi = vector<int>; using vl = vector<ll>; using vii = vector<pii>; using vll = vector<pll>; // }}} 1 // definition {{{ 1 // scaning {{{ 2 #define Scd(x) scanf("%d", &x) #define Scd2(x,y) scanf("%d%d", &x, &y) #define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z) #define Scll(x) scanf("%lld", &x) #define Scll2(x,y) scanf("%lld%lld", &x, &y) #define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z) #define Scc(c) scanf("%c", &c); #define Scs(s) scanf("%s", s); #define Scstr(s) scanf("%s", &s); // }}} 2 // constants {{{ 2 #define EPS (1e-7) #define INF (2e9) #define PI (acos(-1)) // }}} 2 // systems {{{ 2 #define Repe(x,y,z) for(ll x = z; x < y; x++) #define Rep(x,y) Repe(x,y,0) #define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--) #define RRep(x,y) RRepe(x,y,0) // }}} 2 // output {{{ 2 #define YesNo(a) (a)?printf("Yes\n"):printf("No\n") #define YESNO(a) (a)?printf("YES\n"):printf("NO\n") // }}} 2 // }}} 1 // input {{{ 1 // }}} 1 // }}} 0 int N,K; ll f( int k ){ return max( 0, k - 1 - 2 * max( 0, k - N - 1 ) ); } int main() { Scd2(N,K); K = abs(K); ll ans = 0; Repe(ab,2*N+1,2){ int cd = ab-K; if( 2 <= cd && cd <= 2*N ) ans += f(ab) * f(cd); } printf ("%lld\n", ans); return 0; }
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; #pragma GCC optimize ("-O3") #define int long long #define ld long double #define endl "\n" #define rep(i,begin,end) for (__typeof(end) i=begin-(begin>end); i!=(end)-(begin>end); i+=1-2*(begin>end)) #define umap unordered_map #define pq priority_queue #define pb push_back #define mp make_pair #define fs first #define sec second #define lb lower_bound #define ub upper_bound #define mii map<int,int> #define pii pair<int,int> #define vc vector #define vi vc<int> #define vvi vc<vi> #define all(v) v.begin(),v.end() #define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower); #define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper); #define gcd(a,b) __gcd((a),(b)) #define lcm(a,b) ((a)*(b))/gcd((a),(b)) #define remax(a,b) a = max(a,b) #define remin(a,b) a = min(a,b) #define w(t) int t; cin>>t; rep(tc,0,t) #define clr(a,x) memset(a,x,sizeof a) #define chkbit(x,i) ((x)&(1LL<<(i))) #define setbit(x,i) ((x)|(1LL<<(i))) #define setbits(x) __builtin_popcountll(x) #define zerobits(x) __builtin_ctzll(x) #define ps(x,y) fixed<<setprecision(y)<<x #define print(a, n) rep(i,0,n) cout<<a[i]<<" "; cout<<endl; #define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n"; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; const int mod = 1e9+7; const int mod2 = 998244353; const int N = 2e5; const int inf = 1e18; const ld PI = 3.141592653589793; //===================================================== template<typename... T> void in(T&... args) {((cin>>args), ...);} template<typename... T> void out(T&&... args) {((cout<<args<<" "), ...);} template<typename... T> void outln(T&&... args) {((cout<<args<<" "), ...); cout<<endl;} int nxt(){int x;cin>>x;return x;} int add(int a,int b,int mod){int res=(a+b)%mod;return (res<0)?res+mod:res;} int mul(int a,int b,int mod){int res=(a*1LL*b)%mod;return (res<0)?res+mod:res;} int range(int x,int y,int z) {return (x >= y && x <= z);} struct customCompare { bool operator () (int x, int y) { return x>y; } }; //===================================================== int calc(int x){ return ((x*(x+1))/2)%mod2; } void solve() { int n, k; in(n, k); int ans = 0; for(int i = 2; i <= 2*n; i++){ int j = i - k; if (j >= 2 && j <= 2*n){ ans += min(i-1, 2*n-(i-1)) * min(j-1, 2*n-(j-1)); } } cout << ans << endl; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); solve(); // int t; cin >> t; // for (int tc = 1; tc <= t; tc++) { // cout << "Case #" << tc << ": "; // solve(); // } // printclock; return 0; }
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL) #define int long long #define pb push_back #define vi vector #define mod 1000000007 #define all(v) v.begin(),v.end() #define maxv(a) *max_element(all(a)) #define minv(a) *min_element(all(a)) #define sumv(a) accumulate(all(a),0) //#define endl '\n' void solve() { int n,m; cin>>n>>m; if(m%n==0)cout<<"Yes"<<endl; else cout<<"No"<<endl; } signed main() { fastio; int t=1; // cin>>t; while(t--) { solve(); } }
#define LOCAL_DBG #ifdef LOCAL_DBG #define _GLIBCXX_DEBUG #endif #include <bits/stdc++.h> using namespace std; template<typename K, typename V> using umap = unordered_map<K, V>; template<typename T> using pque = priority_queue<T>; template<typename T> using revpque = priority_queue<T, vector<T>, greater<T>>; using ll = long long; using ld = long double; using str = string; using pll = pair<ll, ll>; using pii = pair<int, int>; using vll = vector<ll>; using vi = vector<int>; using vs = vector<str>; using umapll = umap<ll, ll>; #define _rep(i, n) _repi(i, 0, n) #define _repi(i, l, r) for (ll i = ll(l); i < ll(r); i++) #define _get_rep(_1, _2, _3, NAME, ...) NAME #define rep(...) _get_rep(__VA_ARGS__, _repi, _rep) (__VA_ARGS__) #define _rrep(i, n) for (ll i = ll(n) - 1; 0 <= i; i--) #define _rrepi(i, l, r) for (ll i = ll(r) - 1; l <= i; i--) #define _get_rrep(_1, _2, _3, NAME, ...) NAME #define rrep(...) _get_rrep(__VA_ARGS__, _rrepi, _rrep) (__VA_ARGS__) #define each(...) for (auto __VA_ARGS__) #define all(x) x.begin(), x.end() #define mkpair make_pair #define is_in(x, l, r) ((l) <= (x) && (x) < (r)) #define in(t, ...) t __VA_ARGS__; isin(cin, __VA_ARGS__) #define inv(t, v, n) vector<t> v(n); isin(cin, v) #define inv2(t, v, h, w) vector<vector<t>> v(h, vector<t>(w)); isin(cin, v) #define invv(t, va, vb, n) vector<t> va(n), vb(n); rep (i, n) { isin(cin, va[i], vb[i]); } #define invvv(t, va, vb, vc, n) vector<t> va(n), vb(n), vc(n); rep (i, n) { isin(cin, va[i], vb[i], vc[i]); } #define inln(s) str s; getline(cin, s) #define print(...) osout(cout, __VA_ARGS__) #ifdef LOCAL_DBG #define dbg(...) osout(cerr, __VA_ARGS__) #else #define dbg(...) #endif const ll inf = numeric_limits<ll>::max() / 2; template<typename T> bool chmax(T &x, const T &y) { if (x < y) { x = y; return 1; } return 0; } template<typename T> bool chmin(T &x, const T &y) { if (x > y) { x = y; return 1; } return 0; } template<typename T> void sort(vector<T> &v) { sort(all(v)); } template<typename T> void rsort(vector<T> &v) { sort(all(v), greater<T>()); } template<typename T> void dec(vector<T> &v) { rep (i, v.size()) v[i]--; } template<typename T> istream& operator >>(istream &is, vector<T> &v) { rep (i, v.size()) { cin >> v[i]; } return is; } template<typename T1, typename T2> ostream& operator <<(ostream &os, pair<T1, T2> p) { if (&os == &cout) { os << p.first << ' ' << p.second; } if (&os == &cerr) { os << '(' << p.first << ", " << p.second << ')'; } return os; } template<typename T> ostream& operator <<(ostream &os, vector<T> v) { if (&os == &cout) { rep(i, v.size() - 1) { os << v[i] << ' '; } os << v[v.size() - 1]; } if (&os == &cerr) { os << '['; rep(i, v.size() - 1) { os << v[i] << ", "; } os << v[v.size() - 1] << ']'; } return os; } void isin(__attribute__((unused)) istream &_) {} template<class S, class... T> void isin(istream &is, S &s, T&... t) { is >> s; isin(is, t...); } void osout(ostream& os) { os << '\n'; } template<class S, class... T> void osout(ostream &os, S s, T... t) { os << s; if (sizeof...(t)) os << ' '; osout(os, t...); } namespace config { int precision; void update(); } void solve(); int main() { config::update(); cin.tie(0); ios::sync_with_stdio(false); if (config::precision) { cout << fixed << setprecision(15); cerr << fixed << setprecision(15); } solve(); #ifdef LOCAL_DBG dbg("time:", 1000 * clock() / CLOCKS_PER_SEC, "[ms]"); #endif } void config::update() { precision = 0; } void solve() { in(ll,n); invv(ll,a,b,n); ll ans=inf; rep(i,n)rep(j,n) { if(i==j) chmin(ans, a[i]+b[j]); else chmin(ans, max(a[i],b[j])); } print(ans); }
#include<bits/stdc++.h> long long n,v; int main() { scanf("%lld",&n); v=sqrt(2*(n+1))-1; while((v+1)*(v+2)/2<=n+1) v++; printf("%lld",n-v+1); }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.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>; #ifndef aa #define trace(...) #define endl '\n' #endif #define pb push_back #define ub upper_bound #define lb lower_bound #define fi first #define se second #define int long long typedef long long ll; typedef long double ld; #define pii pair<int,int> #define pll pair<ll,ll> #define sz(x) ((long long)x.size()) #define fr(a,b,c) for(int a=b; a<=c; a++) #define frev(a,b,c) for(int a=c; a>=b; a--) #define rep(a,b,c) for(int a=b; a<c; a++) #define trav(a,x) for(auto &a:x) #define all(con) con.begin(),con.end() #define done(x) {cout << x << endl;return;} #define mini(x,y) x=min(x,y) #define maxi(x,y) x=max(x,y) const ll infl = 0x3f3f3f3f3f3f3f3fLL; const int infi = 0x3f3f3f3f; mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count()); const int mod = 998244353; //const int mod = 1e9 + 7; typedef vector<int> vi; typedef vector<string> vs; typedef vector<vector<int>> vvi; typedef vector<pair<int, int>> vpii; typedef map<int, int> mii; typedef set<int> si; typedef set<pair<int,int>> spii; typedef queue<int> qi; uniform_int_distribution<int> rng(1,1e9); //DEBUG FUNCTIONS START #define cerr cout void __print(int 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 deb(x...) cerr << "[" << #x << "] = "; _print(x) #define deb(x...) _print(x) #else #define deb(x...) #endif // DEBUG FUNCTIONS END const int N = 2e5+5; void solve(){ int n; cin>>n; int l=0, r = 2e9, ans=0; while(l<=r){ int x = (l+r)/2; if((x+2)*(x+3) > 2*(n+1)) ans = x, r = x-1; else l = x + 1; } cout << n - ans; } signed main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << fixed << setprecision(15); int t = 1; //cin >> t; while (t--) solve(); return 0; } int powm(int a, int b){ int res = 1; while (b) { if (b & 1) res = (res*a) % mod; a = (a * a) % mod; b >>= 1; } return res; } int divide(int a, int b) { return (a % mod) * powm(b % mod, mod - 2) % mod; } void norm(int &a) { while (a >= mod) a -= mod; while (a < 0) a += mod; }
//高知能系Vtuberの高井茅乃です。 //Twitter: https://twitter.com/takaichino //YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw #include <bits/stdc++.h> using namespace std; typedef long long ll; #define INF INT_MAX #define LLINF LLONG_MAX #define REP(i,n) for(int i=0;i<n;i++) #define REP1(i,n) for(int i=1;i<=n;i++) #define MODA 1000000007 #define MODB 998244353 template <typename T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { for (T& x: vec) { is >> x; } return is; } int main() { ll ans = 0; ll tmp = 0; //int n; cin >> n; string s; cin >> s; REP(i, s.size()){ if(s[i] == '.') break; else cout << s[i]; } cout << endl; }
//Sumonto Chatterjee #include<bits/stdc++.h> using namespace std; #define ll long long int #define f1(a,b) for(ll i=a;i<=b;i++) #define f2(a,b) for(ll j=a;j<=b;j++) #define f3(a,b) for(ll k=a;k<=b;k++) #define fr(a,b) for(ll r=a;r>=b;r--) #define all(a) a.begin(),a.end() #define pb push_back #define vll vector<long long int> #define LL (ll) #define mod 1000000007 #define line '\n' // vector<bool> isprime(2e5+5, true); // void sieve(ll n) // { // isprime[0]=isprime[1]=false; // for (ll i = 2; i * i <= n; i++) // if (isprime[i]) // for (ll j = i * i; j <= n; j += i) // isprime[j] = false; // } // ll expo(ll a, ll b, ll m) // { // a %= m; // long long res = 1; // while (b > 0) // { // if (b & 1) // res = res * a % m; // a = a * a % m; // b >>= 1; // } // return res; // } // /*segment tree*/ // ll tree[4*200005]; // /*initally, v=1, l=0, r=n-1, pos in 0 based index*/ // void update(ll v, ll pos, ll val, ll l, ll r) // { // if(l==r) // tree[v]=val; // else // { // ll mid=(l+r)/2; // if(pos<=mid) // update(2*v, pos, val, l, mid); // else // update(2*v+1, pos, val, mid+1, r); // tree[v]=tree[2*v]+tree[2*v+1]; // } // } // l,r are array segment bounds, x,y are query bounds.....all are in 0 based index // ll query(ll v, ll l, ll r, ll x, ll y) // { // if(x>y) // return 0; // if(l==x && r==y) // return tree[v]; // ll mid=(l+r)/2; // return query(2*v, l, mid, x, min(y, mid))+query(2*v+1, mid+1, r, max(x, mid+1), y); // } // void range_update(ll v, ll x, ll y, ll val, ll l, ll r) // { // if(x>y) return; // if(l==x && y==r) // tree[v]+=val; // else // { // ll mid=(l+r)/2; // range_update(2*v,x, min(mid, y), val, l, mid); // range_update(2*v+1, max(x, mid+1), y, val, mid+1, r); // } // } // ll range_query(ll v, ll l, ll r, ll pos) // { // if(l==r) // return tree[v]; // ll mid=(l+r)/2; // if(pos<=mid) // return tree[v]+range_query(2*v, l, mid, pos); // else // return tree[v]+range_query(2*v+1, mid+1, r, pos); // } void solve() { ll n; cin>>n; if(n==0) { cout<<"Yes"<<line; return; } while(n%10==0) { n/=10; } ll val=0, temp=n; while(temp) { val = val*10 + (temp%10); temp/=10; } if(n==val) cout<<"Yes"<<line; else cout<<"No"<<line; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif //ll t; cin>>t; while(t--) solve(); }
#include <bits/stdc++.h> #define ALL(v) v.begin(), v.end() #define MAX 510000 #define rrep(i, n) for(ll i = 0; i < (ll)(n); i++) #define rep(i, n) for(ll i = 1; i <= (ll)(n); i++) #define dcout cout<<fixed<<setprecision(15); #define mp make_pair #define pb push_back using namespace std; typedef long long int ll; typedef pair<ll, ll> P; constexpr int MOD = 1e9 + 7; constexpr ll inf = 1LL << 60; template< typename S, typename T > inline void chmax(S &a, const T &b) { if(a < b) a = b; } template< typename S, typename T > inline void chmin(S &a, const T &b) { if(a > b) a = b; } ll gcd(ll x, ll y) { if (x == 0) return y; return gcd(y%x, x);} ll lcm(ll x, ll y) { return x * y / gcd(x, y); } ll modpow(ll a, ll n, ll p) { if(n==0) return (ll)1; if (n == 1) return a % p; if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p; ll t = modpow(a, n / 2, p); return (t * t) % p;} ll modinv(ll a, ll m) { if(m==0)return (ll)1; ll b = m, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u;} ll fac[MAX], finv[MAX], inv[MAX]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int 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 com(ll n,ll m){ if(n<m || n<=0 ||m<0){ return 0; } if( m==0 || n==m){ return 1; } ll k=1; for(ll i=1;i<=m;i++){ k*=(n-i+1); k%=MOD; k*=modinv(i,MOD); k%=MOD; } return k;} ll rad(ll u, ll p){ ll cnt=0; while(u%p==0){ u/=p; cnt++; } return cnt;} //////////////////////////////////////////////////////////////////// int main() { ios::sync_with_stdio(false); ll tt; cin>>tt; ll num[550]; ll dis[550]; for(int i=0;i<=501;i++){ num[i]=i; } for(int i=0;i<=500;i++){ dis[i]=i; } rep(qq,tt){ ll cnt=0; ll n; cin>>n; vector<ll> v; rep(i,n){ ll t; cin>>t; v.pb(t); } if(n==1){cout<<0<<endl; continue;} if(n==2){ if(v[0]==1){cout<<0<<endl;} else{ cout<<1<<endl; cout<<1<<endl; } continue; } for(ll i=0;i<n;i++){ num[i+1]=v[i]; dis[v[i]]=i+1; } vector<ll> ans; ll fin=0; for(ll i=1;i<=n;i++){ if(num[i]==i && i!=n-2)continue; if(i==n-2){ while(fin==0){ cnt++; if(cnt%2==n%2){ ll u=num[n-2]; dis[num[n-1]]=n-2; dis[num[n-2]]=n-1; num[n-2]=num[n-1]; num[n-1]=u; ans.pb(n-2); } else{ ll u=num[n-1]; dis[num[n-1]]=n; dis[num[n]]=n-1; num[n-1]=num[n]; num[n]=u; ans.pb(n-1); } if(dis[n-2]==n-2 && dis[n-1]==n-1 && dis[n]==n){fin=1;} } } if(fin==1)break; while(num[i]!=i){ cnt++; if(cnt%2==dis[i]%2){ if(cnt%2==n%2){ ll u=num[n-2]; dis[num[n-1]]=n-2; dis[num[n-2]]=n-1; num[n-2]=num[n-1]; num[n-1]=u; ans.pb(n-2); } else{ ll u=num[n-1]; dis[num[n-1]]=n; dis[num[n]]=n-1; num[n-1]=num[n]; num[n]=u; ans.pb(n-1); } } else{ ll u=num[dis[i]]; num[dis[i]]=num[dis[i]-1]; num[dis[i]-1]=u; dis[i]--; dis[num[dis[i]+1]]++; ans.pb(dis[i]); } } } cout<<cnt<<endl; for(int i=1;i<ans.size();i++){ cout<<ans[i-1]<<" "; } cout<<ans[cnt-1]<<endl; } return 0; }
#pragma GCC optimize("O3") #include<bits/stdc++.h> using namespace std; using ll=long long; using P=pair<ll,ll>; template<class T> using V=vector<T>; #define fi first #define se second #define all(v) (v).begin(),(v).end() const ll inf=(1e18); //const ll mod=998244353; const ll mod=1000000007; ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;} ll LCM(ll c,ll d){return c/GCD(c,d)*d;} struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init; 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<class T>void debag(const vector<T> &a){cerr<<"debag :";for(auto v:a)cerr<<v<<" ";cerr<<"\n";} template<class T>void print(const vector<T> &a){for(auto v:a)cout<<v<<" ";cout<<"\n";} //#include <unistd.h> void solve(){ int n; cin>>n; V<int> a(n); for(int i=0;i<n;i++){ cin>>a[i]; a[i]--; } int t=0; V<int> ans; V<bool> ok(n,false); while(1){ bool ok=true; for(int j=0;j<n;j++){ if(a[j]<j){ ok=false; if(j%2==t){ if(t==0){ swap(a[0],a[1]); ans.emplace_back(1); }else{ swap(a[1],a[2]); ans.emplace_back(2); } t^=1; } while(a[j]<j){ swap(a[j-1],a[j]); ans.emplace_back(j); j--; t^=1; } break; } } if(ok)break; } // print(a); cout<<ans.size()<<"\n"; print(ans); } int main(){ int t; cin>>t; while(t--)solve(); }
#include <cstdio> #define rep(i,_l,_r) for(signed i=(_l),_end=(_r);i<=_end;++i) #define fep(i,_l,_r) for(signed i=(_l),_end=(_r);i>=_end;--i) #define erep(i,u) for(signed i=head[u],v=to[i];i;i=nxt[i],v=to[i]) #define efep(i,u) for(signed i=Head[u],v=to[i];i;i=nxt[i],v=to[i]) #define print(x,y) write(x),putchar(y) template <class T> inline T read(const T sample) { T x=0; int f=1; char s; while((s=getchar())>'9'||s<'0') if(s=='-') f=-1; while(s>='0'&&s<='9') x=(x<<1)+(x<<3)+(s^48),s=getchar(); return x*f; } template <class T> inline void write(const T x) { if(x<0) return (void) (putchar('-'),write(-x)); if(x>9) write(x/10); putchar(x%10^48); } template <class T> inline T Max(const T x,const T y) {if(x>y) return x; return y;} template <class T> inline T Min(const T x,const T y) {if(x<y) return x; return y;} template <class T> inline T fab(const T x) {return x>0?x:-x;} template <class T> inline T gcd(const T x,const T y) {return y?gcd(y,x%y):x;} template <class T> inline T lcm(const T x,const T y) {return x/gcd(x,y)*y;} int n,a[100]; long long ret=(1ll<<31); int main() { n=read(9); rep(i,1,n) a[i]=read(9); rep(s,0,(1<<n-1)-1) { int tmp=0,ans=0; rep(i,1,n-1) if((s>>i-1)&1) tmp|=a[i],ans^=tmp,tmp=0; else tmp|=a[i]; tmp|=a[n],ans^=tmp; if(ret>ans) ret=ans; } print(ret,'\n'); return 0; }
#include<bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; // #define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> using namespace std; #define ll long long int #define pll pair<ll,ll> #define vll vector<ll> #define pi 3.141592653589793238 #define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define precise(x) fixed<<setprecision(x) #define mod 1000000007 #define mod2 998244353 #define endl "\n" ll ans = 1e18; vll a(50); ll n; void recur(ll ind,ll cur,ll net,ll part) { if(ind >= n) { if(part == 0) return; net ^= cur; ans = min(ans,net); return; } // take recur(ind+1,cur | a[ind],net,part); // break recur(ind+1,a[ind],net ^ cur,part+1); } void solve() { cin >> n; for(ll i=0;i<n;i++) cin >> a[i]; recur(0,0,0,0); cout << ans; }int main() { FAST; ll q; q=1; // cin>>q; while(q--) solve(); return 0; }
#include<bits/stdc++.h> using namespace std; int main() { int a,b,c,d; cin>>a>>b>>c>>d; cout<<max(a,b)-min(c,d); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int A,B,C,d; cin>>A>>B>>C; d=A*A+B*B; if (d<C*C) cout<<"Yes"; else cout<<"No"; }
#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; // please, read the question correctly (do you need set or multiset)??? const int N=3010; //check the limits, dummy ll a[N]; int n, m; ll mod = 1e9+7; int mem[N][N], mem1[N][N], lst[N][N]; ll dp(int x, int y){ if(x==n)return 1; if(x>n)return 0; if(mem[x][y]!=-1)return mem[x][y]; ll res = 0; int tmp = mem1[x][y]; if(tmp==n){ res = 1; } else{ res = dp(tmp, y+1)+dp(tmp, y); res %= mod; } // cout<<x<<" "<<y<<" "<<tmp<<" "<<res<<endl; // for(int i=x; i<n; ++i){ // tmp += a[i]; // tmp %= y; // if(tmp==0){ // res += dp(i+1, y+1)+dp(i+1, y); // res %= mod; // break; // } // } mem[x][y] = res; return res; } int main(){ scanf("%d",&n); for(int i=0; i<n; ++i){ scanf("%lld",a+i); } for(int i=1; i<=n; ++i){ for(int j=0; j<n; ++j){ lst[i][j] = n+1; } lst[i][0] = n; } ll sm = 0; for(int i=n-1; i>=0; --i){ sm += a[i]; for(int j=1; j<=n; ++j){ mem1[i][j] = lst[j][(sm%j)]; } for(int j=1; j<=n; ++j){ lst[j][sm%j] = i; } } memset(mem, -1, sizeof mem); ll ans = dp(0,1); cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; //#define FOR_CODEFORCES //#define MOD 998244353LL #if 1 //テンプレ折り畳み//テンプレ折り畳み//テンプレ折り畳み #ifdef _DEBUG #define debug() if(true) #define dout cout #define dvout(v) __vout(v) #define dvvout(v) __vvout(v) #else #define debug() if (false) #define dout if (false)cout #define dvout(v) if(false)__vout(v) #define dvvout(v) if(false)__vvout(v) #endif typedef long long ll; typedef unsigned long long ull; #define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)//rep #define repll(i, n) for(ll i=0, i##_len=(n); i<i##_len; ++i)//rep #define repi(i, n1, n) for(int i=n1, i##_len=(n); i<i##_len; ++i)//rep #define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)//自然数rep #define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i) #define rreps(i, n) for(int i=((int)(n)); i>0; --i) #define _Yes {cout<<"Yes"<<endl; return;}//出力 #define _No {cout<<"No"<<endl;return;} #define _ans {cout<<ans<<endl;return;} #define _endout(s) {cout<<(s)<<endl;return;} #define vec(v, n) vector<int> v(n, 0);//配列 #define vecll(v, n) vector<ll> v(n, 0); #define vecvec(v, n, m) vector<vector<int>> v(n, vector<int>(m)); typedef vector<int> vi; typedef vector<char> vc; typedef vector<ll> vll; typedef vector<vi> vvi; typedef vector<vll> vvll; #define vin(v) for (auto &i : (v)) cin >> i; //配列入力 #define vvin(v) for(auto&i:(v))for(auto&j:i)cin>>j; #define __vout(v) for(auto&i:(v)){cout<<i<<' ';}cout<<"\n"; #define __vvout(v) for(auto&i:(v)){for(auto&j:i){cout<<j<<' ';}cout<<"\n";}cout<<"\n"; #ifndef MOD #define MOD 1000000007LL//mod用定数 (ll)(1e9+7) #endif #define mod(n) ( ((ll)n) % MOD) #define modp(n, p) ( ((ll)n) % (ll)(p)) #define modx(A,B) mod(mod(A)*mod(B)) template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } #define next asdnext #define prev asdprev #define y0 y3487465 #define y1 y8687969 #define j0 j1347829 #define j1 j234892 #define SZ(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define _n "\n" #define _n2 "\n\n" #define _t "\t" void test(); #endif //テンプレ折り畳み // LLONG_MAX 9.2*1e18 9223372036854775807LL = (2^63)-1 // INT_MAX 2.1*1e9 2147483647 = (2^31)-1 // O(1e8) 1.2sec struct ARROW{ ll a=1,b=0,c=0,d=1,k1=0,k2=0; }; void Main() { int N; cin>>N; vll X(N); vll Y(N); rep(i,N){ cin>>X[i]>>Y[i]; } int M; cin>>M; vector<ARROW> ar(M+1); reps(i,M){ int t; cin>>t; ll p; if(t==3 || t==4)cin>>p; switch (t) { case 1: ar[i].a=(ar[i-1].c); ar[i].b=(ar[i-1].d); ar[i].k1=(ar[i-1].k2); ar[i].c=-(ar[i-1].a); ar[i].d=-(ar[i-1].b); ar[i].k2=-(ar[i-1].k1); break; case 2: ar[i].a=-(ar[i-1].c); ar[i].b=-(ar[i-1].d); ar[i].k1=-(ar[i-1].k2); ar[i].c=(ar[i-1].a); ar[i].d=(ar[i-1].b); ar[i].k2=(ar[i-1].k1); break; case 3: ar[i].a=-(ar[i-1].a); ar[i].b=-(ar[i-1].b); ar[i].k1=p*2LL - (ar[i-1].k1); ar[i].c=(ar[i-1].c); ar[i].d=(ar[i-1].d); ar[i].k2=(ar[i-1].k2); break; case 4: ar[i].a=(ar[i-1].a); ar[i].b=(ar[i-1].b); ar[i].k1=(ar[i-1].k1); ar[i].c=-(ar[i-1].c); ar[i].d=-(ar[i-1].d); ar[i].k2=p*2LL - (ar[i-1].k2); break; } } int Q; cin>>Q; rep(i,Q){ int A,B; cin>>A>>B; A;B--; ll x=(ar[A].a)*X[B] + (ar[A].b)*Y[B] + (ar[A].k1); ll y=(ar[A].c)*X[B] + (ar[A].d)*Y[B] + (ar[A].k2); dout<<"output "; cout<<x<<" "<<y<<_n; } } void test(){ } int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << std::fixed << std::setprecision(20); #ifdef FOR_CODEFORCES int t = 0; cin >> t; rep(i, t) Main(); #else Main(); #endif return 0; }
#include <stdlib.h> #include <stdio.h> #include <iostream> #include <string> #include <algorithm> #include <vector> #include <sstream> using namespace std; typedef long long int lli; int N1, N2, N3,N4; vector<string> split(const string& s, char delim) { vector<string> elems; stringstream ss(s); string item; while (getline(ss, item, delim)) { if (!item.empty()) { elems.push_back(item); } } return elems; } int main() { string str; cin >> str; vector<string> ss = split(str, '.'); cout << ss[0] << endl; return 0; }
#include <iostream> using namespace std; #define int long long int int32_t main() { string x; cin>>x; string ans=""; for(int i=0;i<x.length();i++) { if(x[i]=='.') { break; } else { ans+=x[i]; } } cout<<ans<<endl; }
#pragma GCC optimize("Ofast") #include<bits/stdc++.h> using namespace std; #define ll long long #define eb emplace_back #define mp make_pair #define pb push_back #define watch(x) cout << (#x) << " = " << (x) << endl; #define w(x) int x; cin >> x; while(x--) #define all(x) (x.begin(), x.end()) #define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr); #define vi vector<int> #define lcm(x, y) (x/__gcd(x, y))*y #define sayHi cout << "Say Hi!!!!!!!!!!!!!!!!!!!!!!!!!\n"; #define rep(i,k,n) for(int i=k; i<n; i++) #define REPR(i,k,n) for (int (i) = (k); (i) >= (n); (i)--) #define sumAll(a) (accumulate ((a).begin(), (a).end(), 0ll)) #define mine(a) (*min_element((a).begin(), (a).end())) #define maxe(a) (*max_element((a).begin(), (a).end())) #define mini(a) (min_element((a).begin(), (a).end()) - (a).begin()) #define maxi(a) (max_element((a).begin(), (a).end()) - (a).begin()) #define lowb(a, x) (lower_bound((a).begin(), (a).end(), (x)) - (a).begin()) #define uppb(a, x) (upper_bound((a).begin(), (a).end(), (x)) - (a).begin()) #define mem0(a) (memset(a, 0, sizeof(a))) #define mem1(a) (memset(a, -1, sizeof(a))) const int MAXN = (int)((1e5) + 100); const long long MOD = 1e9 + 7; bool isPrime(ll n){if(n<2)return false;for(ll i=2;i*i<=n; i++){if(n%i==0)return false;}return true;} int countDigit(ll n){int count=0;while(n!=0){n/=10;++count;}return count;} void removeCharFromString(string &str,const char &ch){str.erase(remove(str.begin(),str.end(),ch),str.end());} void showTime() {cerr<<"\nExecution time: "<<(float)clock()/CLOCKS_PER_SEC<<" secs\n";} long long binExp(long long base,long long pow){ long long result=1; while(pow){ if(pow%2){result*=base;} base*=base; pow/=2; } return result; } long long binExpMod(long long base,long long pow,long long M){ long long result=1; while(pow){ if(pow%2){result=(result*base)%M;} base=(base*base)%M; pow/=2; } return result; } bool sortBySecAsc(const pair<ll,ll> &a, const pair<ll,ll> &b){ return (a.second < b.second); } bool sortBySecDes(const pair<ll,ll> &a, const pair<ll,ll> &b){ return (a.second > b.second); } /*#ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif*/ /*-----------------------------------------------------------------------------------------------------------------*/ int main() { fastIO map<int, string> m; w(t) { int x; string s; cin >> s >> x; m[x] = s; } // for(auto i:m) { // cout << i.first << " " << i.second << "\n"; // } auto it = m.end(); it--; it--; cout << it->second; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ll long long #define int ll #define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define ld long double #define ull unsigned long long #define endl "\n" #define fo(i,a,b) for(int i = a; i<=b ; i++) #define rfo(i,a,b) for(int i = a; i>=b ; i--) #define vii vector<int> #define vll vector<ll> #define pq priority_queue #define uom unordered_map #define all(v) v.begin(),v.end() #define mp make_pair #define pb push_back #define pob pop_back #define ff first #define ss second #define pii pair<int,int> #define mii map<int,int> #define vvii vector<vii> #define mod 1000000007 #define MIN -1e9 #define pi 3.1415926535897932384626433832795 using namespace std; using namespace __gnu_pbds; template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; void INPUT() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } /* ---------------------------------------------------------------- -> Check For Overflows -> Out of Bounds -> Initialisations of global arrays and variables -> Read the Question and the sample test cases carefully -> Its not Always Complex, Try to simplify -> write it down and try to solve -> Have Faith in urself and in ur approach -> If it seems totally out of reach, switch to next :) -> And Come Back later, if possible .. ----------------------------------------------------------------*/ bool cmp(pair<int, int>& a, pair<int, int>& b) { return a.ff < b.ff; } void solve() { int n,w; cin >> n>>w; // int a[n]; // fo(i,0,n-1) // cin>>a[i]; //sort(a,a+n); cout<<n/w<<endl; } signed main() { FIO INPUT(); int t; t = 1; // cin >> t; fo(i, 0, t - 1) { solve(); } return 0; }
#include <bits/stdc++.h> #define ll long long #define F first #define S second #define FF first.first #define FS first.second #define pb push_back using namespace std; ll l, r, ans, dp[(1<<20)], a[73], A[]={2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71}; int main(){ cin>>l>>r; for (ll i=l; i<=r; i++){ for (int j=0; j<20; j++){ if(i%A[j]==0)a[i-l]^=(1<<j); } } dp[0]=1; for (int i=0; i<r-l+1; i++){ for (int j=0; j<(1<<20); j++){ if((j|a[i])==(j^a[i])){ dp[j|a[i]]+=dp[j]; } } } for (int i=0; i<(1<<20); i++){ ans+=dp[i]; } cout<<ans; } /* 20: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, */
#include <bits/stdc++.h> #define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i) #define reps(i, n) for(int i=1, i##_len=(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 ALL(v) (v).begin(), (v).end() using namespace std; using ll = long long; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } void Yes(bool a) { cout << (a?"Yes":"No") << endl; } void YES(bool a) { cout << (a?"YES":"NO") << endl; } int MOD = 1e9+7; int INF = 1000; int N; int diff(vector<vector<char>> &genome, string s, int h, int w, int dir) { int res = 0; if (dir == 0) { rep(i, s.size()) { if (genome[h][(w+i)%N] != s[i] && genome[h][(w+i)%N] != '.') res++; } } else { rep(i, s.size()) { if (genome[(h+i)%N][w] != s[i] && genome[(h+i)%N][w] != '.') res++; } } return res; } pair<int, int> find(vector<vector<char>> &genome, string s, int dir) { int h=-1, w=-1; rep(i, N) rep(j, N) { bool flag = true; if (dir == 0) { rep(pos, s.size()) { if (genome[i][(j+pos)%N] != s[pos]) flag = false; } } else { rep(pos, s.size()) { if (genome[(i+pos)%N][j] != s[pos]) flag = false; } } if (flag) { h = i; w = j; break; } } return {h, w}; } int main(int argc, char **argv) { int M; cin >> N >> M; vector<vector<char>> genome(N, vector<char>(N, '.')); vector<string> s(M); rep(i, M) cin >> s[i]; // sort(ALL(s), [](const string &a, const string &b) { // return a.size() < b.size(); // }); mt19937 r; shuffle(ALL(s), r); rep(i, s[0].size()) genome[0][i] = s[0][i]; rep(i, M) { int mindiff = INF; int h, w, dir; rep(j, N) rep(k, N) { if (chmin(mindiff, diff(genome, s[i], j, k, 0))) { h = j; w = k; dir = 0; } if (chmin(mindiff, diff(genome, s[i], j, k, 1))) { h = j; w = k; dir = 1; } } if (mindiff < s[i].size()-1) { if (dir == 0) { rep(pos, s[i].size()) { genome[h][(w+pos)%N] = s[i][pos]; } } else { rep(pos, s[i].size()) { genome[(h+pos)%N][w] = s[i][pos]; } } } } vector<vector<bool>> flag(N, vector<bool>(N, false)); rep(i, M) { rep(j, N) rep(k, N) { if (diff(genome, s[i], j, k, 0) == 0) { rep(pos, s[i].size()) { flag[j][(k+pos)%N] = true; } } if (diff(genome, s[i], j, k, 1) == 0) { rep(pos, s[i].size()) { flag[(j+pos)%N][k] = true; } } } } rep(h, N) rep(w, N) { if (!flag[h][w]) genome[h][w] = '.'; } rep(h, N) { rep(w, N) { printf("%c", genome[h][w]); } printf("\n"); } }
#pragma region shig_templates #include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int, int> pairI2; typedef pair<LL, LL> pairLL2; typedef vector<int> VI; typedef vector<LL> VLL; typedef vector<VI> VVI; typedef vector<VVI> VVVI; typedef vector<string> VS; #define shig_for(i, a, b) for(int i = (a); i < (b); ++i) #define shig_rep(i, n) shig_for(i, 0, n) #define shig_forB(bit,a,b) for(int bit = (a); bit < (1<<(b)); ++bit) #define shig_repB(bit,n) shig_forB(bit,0,n) #define CINI(a) int (a); cin >> (a) #define CINLL(a) LL (a); cin >> (a) #define CINI2(a, b) int a, b; cin >> (a) >> (b) #define CINLL2(a, b) LL a, b; cin >> (a) >> (b) #define tmp int temp = 0 #define str string s template<class T> void COUT(T&& t){ cout << t << endl; } template<class T,class... Ts> void COUT(T&& t,Ts&&... ts){ cout << t << " "; COUT(ts...); } void CIN() {} template<class T,class... Ts> void CIN(T&& t,Ts&&... ts){ cin >> t; CIN(ts...); } #pragma endregion int main(){ int V, T, S, D; CIN(V, T, S, D); if(!(D >= T*V && D <= S*V)){ COUT("Yes"); }else{ COUT("No"); } //for(string& s : S) cin >> s; //cout << "Atcoder " << N << endl; //cout << fixed << setprecision(10) << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long add(long long a, long long b) { long long res = a + b; if (res >= mod) res -= mod; return res; } long long sub(long long a, long long b) { long long res = a - b + mod; if (res >= mod) res -= mod; return res; } long long mul(long long a, long long b) { return (((a % mod) * (b % mod)) % mod); } long long potolok(long long a, long long b){ return (a + b - 1) / b; } long long gcd(long long x, long long y){ if(y == 0){ return x; } if(x == 0){ return y; } if(x > y){ return gcd(y, x % y); } else{ return gcd(x, y % x); } } long long bin_pow(long long base, long long power, long long m){ if(power == 1){ return base; } if(power % 2 == 0){ long long t = bin_pow(base, power / 2, m); return t * t % m; } else{ return bin_pow(base, power - 1, m) * base % m; } } struct segtree{ int razmer; vector<long long> tree; void Init(vector<long long> &v){ int n = (int)v.size(); razmer = 1; while(razmer < n) razmer *= 2; tree.assign(2 * razmer - 1, 0); } void build(vector<long long> &v, int x, int lx, int rx){ if(rx - lx == 1){ if(lx < (int)v.size()){ tree[x] = v[lx]; } }else{ int m = (lx + rx) / 2; build(v, 2 * x + 1, lx, m); build(v, 2 * x + 2, m, rx); tree[x] = min(tree[2 * x + 1], tree[2 * x + 2]); } } void build(vector<long long> &v){ build(v, 0, 0, razmer); } void cet(int i, int v, int x, int lx, int rx){ if(rx - lx == 1){ tree[x] = v; return; }else{ int m = (lx + rx) / 2; if(i < m){ cet(i, v, 2 * x + 1, lx, m); }else{ cet(i, v, 2 * x + 2, m, rx); } tree[x] = min(tree[2 * x + 1], tree[2 * x + 2]); } } void cet(int i, int v){ cet(i, v, 0, 0, razmer); } long long mn(int l, int r, int x, int lx, int rx){ if(lx >= r || l >= rx){ return mod; } if(lx >= l && rx <= r){ return tree[x]; } else if(min(rx, r) - max(lx, l) >= 0){ int m = (lx + rx) / 2; long long s1 = mn(l, r, 2 * x + 1, lx, m); long long s2 = mn(l, r, 2 * x + 2, m, rx); return min(s1, s2); } } long long mn(int l, int r){ return mn(l, r, 0, 0, razmer); } }; void solve(){ //std::freopen("stupid_rmq.in", "r", stdin); //std::freopen("stupid_rmq.out", "w", stdout); //ios_base::sync_with_stdio(false); //cin.tie(NULL); int V, T, S, D; cin >> V >> T >> S >> D; if(D >= V * T && D <= V * S){ cout << "No" << endl; }else{ cout << "Yes" << endl; } } int main(){ int t; t = 1; //cin >> t; while(t--){ solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define int long long #define pow abcdef_pow #define sqr(x) ((x)*(x)) int pow(int a, int b, int mod) { if (b == 0) return 1; int t = pow(a, b / 2, mod); t = (t * t) % mod; if (b % 2) return (t * a) % mod; return t; } signed main() { // freopen("in" , "r", stdin ); cin.tie(0)->sync_with_stdio(0); int n, m; cin >> n >> m; int ans = ((pow(10, n, sqr(m)) - pow(10, n, m) + sqr(m) * sqr(m)) % sqr(m)) / m; cout << ans << endl; }
#include <bits/stdc++.h> #define isNum(a) (a >= '0' && a <= '9') #define SP putchar(' ') #define EL putchar('\n') #define File(a) freopen(a ".in", "r", stdin), freopen(a ".out", "w", stdout) template <typename T> void read(T &); template <typename T> void write(const T &); typedef unsigned uint; typedef long long ll; typedef unsigned long long ull; typedef std::pair<int, int> pii; const int iinf = 2147483647; const ll llinf = 9223372036854775807ll; ll pow(ll a, ll b, ll m); int main() { ll n, m; read(n), read(m); write(pow(10, n, m * m) / m % m), EL; return 0; } ll pow(ll a, ll b, ll m) { ll ans = 1, now = a; while (b) { if (b & 1) { ans = ans * now % m; } now = now * now % m; b >>= 1; } return ans; } template <typename T> inline void read(T &Re) { T k = 0; char ch = getchar(); int flag = 1; while (!isNum(ch)) { if (ch == '-') { flag = -1; } ch = getchar(); } while (isNum(ch)) { k = (k << 1) + (k << 3) + ch - '0'; ch = getchar(); } Re = flag * k; } template <typename T> inline void write(const T &Wr) { if (Wr < 0) { putchar('-'); write(-Wr); } else { if (Wr < 10) { putchar(Wr + '0'); } else { write(Wr / 10); putchar((Wr % 10) + '0'); } } }
#ifdef _DEBUG #include "../../../library/src/debug_template.cpp" #define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__) #else #define DMP(...) ((void)0) #endif #include <cassert> #include <cstdio> #include <cmath> #include <iostream> #include <iomanip> #include <string> #include <vector> #include <set> #include <map> #include <unordered_map> #include <queue> #include <numeric> #include <algorithm> #include <bitset> #include <functional> using namespace std; using lint = long long; constexpr int MOD = 1000000007, INF = 1010101010; constexpr lint LINF = 1LL << 60; struct init { init() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } init_; int main() { lint N, C; cin >> N >> C; struct dta { int a, b, c; dta(int a = 0, int b = 0, int c = 0) {} bool operator<(dta &r) const { return a < r.a; } bool operator>(dta &r) const { return b > r.b; } }; vector<dta> abc(N); for (int i = 0; i < N; i++) cin >> abc[i].a >> abc[i].b >> abc[i].c; sort(abc.begin(), abc.end()); //abc.emplace_back(INF, 0, 0); lint ans = 0, sum = 0; lint now = 0; priority_queue<dta, vector<dta>, greater<>> pq; for (int i = 0; i < N; i++) { ans += min(sum, C) * (abc[i].a - now); now = abc[i].a; pq.emplace(abc[i]); sum += abc[i].c; while (!pq.empty() && ((i == N - 1) || abc[i + 1].a > pq.top().b)) { ans += min(sum, C) * (pq.top().b - now + 1); now = pq.top().b + 1; sum -= pq.top().c; pq.pop(); } DMP(sum); } cout << ans << '\n'; return 0; }
#include<bits/stdc++.h> using namespace std; int sx, sy; int t[50][50], p[50][50]; vector<int> c(2510, 0); int score = 0, sum = 0; string ans = "", s = ""; const int dx[4] = {0, 1, 0, -1}; const int dy[4] = {1, 0, -1, 0}; const char mo[4] = {'R', 'D', 'L', 'U'}; void dfs(int x, int y) { if(clock() > 1980000) { if(sum > score) { ans = s; } return; } bool f = true; if(clock() <= 1000000){ for(int i = 0; i < 4; ++i) { int nx = x+dx[i], ny = y+dy[i]; if(nx < 0 || nx >= 50 || ny < 0 || ny >= 50) continue; if(c[t[nx][ny]]) continue; f = false; s.push_back(mo[i]); c[t[nx][ny]] = 1; sum += p[nx][ny]; dfs(nx, ny); s.pop_back(); c[t[nx][ny]] = 0; sum -= p[nx][ny]; } } else { for(int i = 3; i >= 0; --i) { int nx = x+dx[i], ny = y+dy[i]; if(nx < 0 || nx >= 50 || ny < 0 || ny >= 50) continue; if(c[t[nx][ny]]) continue; f = false; s.push_back(mo[i]); c[t[nx][ny]] = 1; sum += p[nx][ny]; dfs(nx, ny); s.pop_back(); c[t[nx][ny]] = 0; sum -= p[nx][ny]; } } if(f) { if(sum > score) { ans = s; score = sum; } } } int main() { cin >> sx >> sy; for(int i = 0; i < 50; ++i) { for(int j = 0; j < 50; ++j) scanf("%d", &t[i][j]); } for(int i = 0; i < 50; ++i) { for(int j = 0; j < 50; ++j) scanf("%d", &p[i][j]); } c[t[sx][sy]] = 1; dfs(sx, sy); cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; #define rep(i,b) for(ll i=0;i<b;i++) #define rrep(i,a,b) for(ll i=a;i>=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() ///#pragma GCC target("avx2") ///#pragma GCC optimize("O3") ///#pragma GCC optimize("unroll-loops") ll input(){ ll n; cin >> n; return n; }///input関数 ll combination(ll n,ll r){ if (r == 0 || r == n) return (1); else if (r == 1) return (n); return (combination(n-1,r-1) + combination(n-1,r)); }///nCr ll facctorialMethod(ll k){ ll sum = 1; for (ll i = 1; i <= k; ++i) { sum *= i; } return sum; }///階乗 void num_change(ll &a, ll &b){ swap(a,b); } void top3(ll &no1,ll &no2,ll cha){ if (cha>no2&&cha!=no1)num_change(cha,no2); if (no2>no1)num_change(no1,no2); } /* int main() { ll n = input(); vector<ll>num; vector<ll>cnt; rep(i,n){ ll a = input(); bool flag = true; rep(j,num.size()){ if(num.at(j) == a){ cnt.at(j)++; flag = false; } } if (flag){ num.push_back(a); cnt.push_back(1); } } sort(all(cnt)); reverse(all(cnt)); ll ans = n * (n-1)/2; fore(i,cnt){ if(i > 1){ ans -= (i*(i-1)/2); } if (i==1){ break; } } cout << ans << endl; }*/ int main(){ ll a = input(); if (a == 191){ cout << "so-so"; }else if (a <191){ cout << "Yay!"; }else{ cout << ":("; } }
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; const int maxn = 5050,mod = 998244353; int n,m,fac[maxn],ifac[maxn],f[2][maxn]; int read(){ int x = 0; char c = getchar(); while(c < '0' || c > '9') c = getchar(); while(c >= '0' && c <= '9') x = x * 10 + (c ^ 48),c = getchar(); return x; } inline int add(int x,int y){ if(x + y < mod) return x + y; else return x + y - mod; } int qpow(int x,int k){ int d = 1; while(k){ if(k & 1) d = 1ll * d * x % mod; x = 1ll * x * x % mod,k >>= 1; } return d; } void init(int n){ fac[0] = 1; for(int i = 1; i <= n; i ++) fac[i] = 1ll * fac[i - 1] * i % mod; ifac[n] = qpow(fac[n],mod - 2); for(int i = n - 1; i >= 0; i --) ifac[i] = 1ll * ifac[i + 1] * (i + 1) % mod; } int main(){ n = read(),m = read(); init(n); int cur = 0; f[cur][0] = 1; for(int k = 1; k <= m; k <<= 1){ cur ^= 1; for(int i = 0; i <= m; i ++){ f[cur][i] = 0; for(int j = 0; j <= n && j * k <= i; j += 2){ f[cur][i] = add(f[cur][i],1ll * f[cur ^ 1][i - j * k] * fac[n] % mod * ifac[j] % mod * ifac[n - j] % mod); // cout << k << ' ' << i << ' ' << f[cur][i] << endl; } } } printf("%d\n",f[cur][m]); return 0; }
#include <bits/stdc++.h> using namespace std; using ll=long long; using vin=vector<int>; using vll=vector<long long>; using vvin=vector<vector<int>>; using vvll=vector<vector<long long>>; using vstr=vector<string>; using vvstr=vector<vector<string>>; using vch=vector<char>; using vvch=vector<vector<char>>; using vbo=vector<bool>; using vvbo=vector<vector<bool>>; using vpii=vector<pair<int,int>>; using pqsin=priority_queue<int,vector<int>,greater<int>>; #define mp make_pair #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rep2(i,s,n) for(int i=(s);i<(int)(n);i++) #define all(v) v.begin(),v.end() #define decp(n) cout<<fixed<<setprecision((int)n) const ll inf=1e9+7; const ll INF=1e18; const ll mod=99824453; vin dx={-1,0,1,0}; vin dy={0,1,0,-1}; ll modpow(ll a,ll n,ll m=inf){ ll res=1; while(n){ if(n&1)res=res*a%m; a=a*a%m; n>>=1; } return res; } int main(){ ll h,w;cin>>h>>w; vstr s(h);rep(i,h)cin>>s[i]; vvin up(h,vin(w)),down(h,vin(w)),right(h,vin(w)),left(h,vin(w)); int tmp=-1;ll k=h*w; rep(i,h){ tmp=-1; rep(j,w){ left[i][j]=tmp; if(s[i][j]=='#'){ tmp=j; k--; } } tmp=w; for(int j=w-1;j>=0;j--){ right[i][j]=tmp; if(s[i][j]=='#')tmp=j; } } rep(j,w){ tmp=-1; rep(i,h){ up[i][j]=tmp; if(s[i][j]=='#')tmp=i; } tmp=h; for(int i=h-1;i>=0;i--){ down[i][j]=tmp; if(s[i][j]=='#')tmp=i; } } ll all=modpow((ll)2,k),light,can; ll ans=(ll)0; rep(i,h)rep(j,w){ if(s[i][j]=='.'){ light=(down[i][j]-up[i][j]-(ll)1)+(right[i][j]-left[i][j]-(ll)1)-(ll)1; can=all-modpow((ll)2,k-light); if(can<0)can+=inf; ans+=can;ans%=inf; } } cout<<ans<<endl; }
#include<bits/stdc++.h> using namespace std; #define FOR(i, a, b) for(int i = (a); i < (b); ++i) #define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i) #define REP(i, N) FOR(i, 0, N) #define RREP(i, N) RFOR(i, N, 0) #define FILL(A,value) memset(A,value,sizeof(A)) #define endl '\n' #define ALL(V) V.begin(), V.end() #define SZ(V) (int)V.size() #define watch(x) cout << (#x) << " is " << (x) << endl #define pb push_back #define mp make_pair #define Pi 3.14159265358979 #define A first #define B second typedef long long ll; typedef unsigned long long ull; typedef vector <int> vi; typedef vector<ll> vl; typedef pair <int, int> pi; typedef pair <ll, int> pl; typedef pair <ll, ll> pll; typedef pair <double, double> pd; //change these according to prob constraints const int INF = 0x3f3f3f3f; const int MAX = 100005; const int MAX1 = 1005; const int MAX2 = 105; const int LEN = 105; const int BASE = 1000000000; const double EPS = 1e-7; const int MOD = 1000000007; //g++ -std=c++11 your_file.cpp -o your_program ll mypow(ll a, ll b){ ll ans=1; while(b){ if(b&1) ans=(ans*a)%MOD; b/=2; a=(a*a)%MOD; } return ans; } int main(void){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ifstream in(""); ofstream out(""); clock_t begin = clock(); int n; cin >> n; int arr[n]; REP(i, n){ cin >> arr[i]; } ll ret = 1e18; REP(i, 1 << (n - 1)){ int curr = arr[0], res = 0; REP(j, n - 1){ if ((i >> j) & 1){ res ^= curr; curr = arr[j + 1]; } else{ curr |= arr[j + 1]; } } res ^= curr; ret = min(ret, (ll)res); } cout << ret << endl; clock_t end = clock(); double esecs = double(end - begin) / CLOCKS_PER_SEC; //cout << esecs << " seconds" << endl; return 0; }
#include <algorithm> #include <iostream> int main() { int a,b,c,d; std::cin >> a; std::cin >> b; std::cin >> c; std::cin >> d; std::cout << b-c << std::endl; return 0; }
#include <bits/stdc++.h> #define fi first #define se second #define is_in(x,l,r) ((l) <= (x) && (x) < (r)) #define sz(x) (int)(x).size() #define rng(a) a.begin(),a.end() #define rngr(a) a.rbegin(),a.rend() #define uni(x) x.erase(unique(rng(x)),x.end()) #define rep(i,n) for(int i=0; i<(n); i++) #define rep2(i,x,n) for(int i=x; i<(n); i++) #define ALL(c) (c).begin(), (c).end() #define ALLR(c) (c).rbegin(), (c).rend() #define pb push_back #define eb emplace_back using namespace std; const long long INF = 1LL<<60; // 仮想的な無限大の値; const int inf = 1<<30; const double pi = acos(-1); using ll = long long; using P = pair<int, int>; #define vi vector<int> #define vvi vector<vi> #define vll vector<ll> #define vs vector<string> #define vp vector<P> #define vvp vector<vp> ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } ll lcm(ll a, ll b){return a * b / gcd(a, b);} template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using CP = complex<double>; double dot( const CP &z, const CP &w ){ return (z.real()*w.real() + z.imag()*w.imag()); } double cross( const CP &z, const CP &w ){ return (z.real()*w.imag() - z.imag()*w.real()); } // #include <atcoder/all> // using namespace atcoder; // using mint = modint1000000007; // const ll mod = 1000000007; #define dame { puts("-1"); return;} #define yn {puts("Yes");}else{puts("No");} int main() { int a, b, c, d; cin >> a >> b >> c >> d; int ans = max({a-c, a-d, b-c, b-d}); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define repi(i, a, n) for (int i = a; i < (int)(n); ++i) #define rep(i, n) repi(i, 0, n) #define all(v) begin(v), end(v) using ll = long long; int main() { // freopen("1.txt", "rb", stdin); ios_base::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vector<int> F(N + 1); F[1] = 1; for (int i = 2; i <= N; ++i) { int mx = 1; for (int j = 1; 1LL * j * j <= i; ++j) { if (i % j == 0) { mx = max(mx, F[j]); mx = max(mx, F[i / j]); } } F[i] = mx + 1; } for (int i = 1; i <= N; ++i) { cout << F[i] << ' '; } cout << '\n'; return 0; }
#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include<bits/stdc++.h> // using namespace std; #if __has_include(<atcoder/all>) #include<atcoder/all> // using namespace atcoder; #endif #define int long long #pragma region header #pragma region alias using lint = long long; using ll = long long; using P = std::pair<int,int>; template<class T> using prique = std::priority_queue<T,std::vector<T>,std::greater<T>>; #pragma endregion #pragma region macros #define rep(i, n) for(int i = 0;i<(int)(n);i++) #define REP(i, m, n) for(int i = (m);i<(int)(n);i++) #define drep(i, n) for(int i = (n)-1;i>=0;i--) #define DREP(i, m, n) for(int i = (m)-1;i>=(int)(n);i--) #define all(v) (v).begin(),(v).end() #define reall(v) (v).rbegin(),(v).rend() template<class T, class U> bool chmax(T& a,const U b) { if(a < b) { a = b; return true; } return false; } template<class T, class U> bool chmin(T& a,const U b) { if(a>b) { a = b; return true; } return false; } std::map<int,int> prime_div(int n) { std::map<int,int> mp; if(~n&1) while(~n&1) n>>=1,mp[2]++; for(int i = 3;i<=std::sqrt(n);i+=2) { if(n%i==0) { while(n%i==0) { n/=i; mp[i]++; } } } if(n!=1) mp[n]++; return mp; } #pragma endregion #pragma region constant constexpr long long inf = 1LL << 61; constexpr int dx[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0}; constexpr int dy[9] = {0, 1, 0, -1, 1, -1, 1, -1, 0}; constexpr long long mod = 1e9+7; constexpr long long MOD = 998244353; #pragma endregion #pragma region inout template<class T> std::ostream& operator<<(std::ostream& stream, const std::vector<T>& v) { for(int i = 0; i < (int)(v.size()); i++) { stream << v[i]; if(i != (int)(v.size()) - 1) stream << ' '; } return stream; } template<typename Itr> inline void print(const Itr& begin, const Itr& end, bool endline = true, const char* BEGIN = "{", const char* mid = ", ", const char* END = "}") { if(begin == end) return; std::cout << BEGIN << *begin; for(Itr itr = begin+1; itr < end; itr++) std::cout << mid << *itr; std::cout << END; if(endline) std::endl(std::cout); return; } template<class T> std::istream& operator>>(std::istream& stream, std::vector<T>& v) { for(T& p:v) stream >> p; return stream; } template<typename Itr> inline void input(Itr begin, Itr end) { for(Itr& itr = begin; itr < end; itr++) std::cin >> *itr; return; } template<class T, class U> std::ostream& operator<<(std::ostream& stream, const std::pair<T,U>& pair) { return stream << pair.first << ' ' << pair.second; } template<class T, class U> inline void print(const std::pair<T,U>& pair,const bool endline = true, const char* begin = "(", const char* mid = ", ", const char* end = ")") { std::cout << begin << pair.first << mid << pair.second << end; if(endline) std::endl(std::cout); else std::cout << ' '; return; } template<class T, class U> std::istream& operator>>(std::istream& stream, std::pair<T,U>& pair) { return stream >> pair.first >> pair.second; } template<class T, class U> inline void input(std::pair<T,U>& pair, const bool first = true, const bool second = true) { if(first) std::cin >> pair.first; if(second) std::cin >> pair.second; } #pragma endregion #pragma region DEBUG #ifdef _DEBUG #define debug(x) {do{std::cout << #x << ": ";view(x);}while(0);} #else #define debug(x) #endif template<class T> inline void view(const T& x) { std::cout << x << std::endl; } template<class T> inline void view(const std::vector<T>& v) { print(all(v)); } #pragma endregion #pragma endregion signed main() { int n; std::cin >> n; std::vector<int> v(n+1); REP(i, 1, n+1) { v[i]++; for(int j = i*2;j<=n;j+=i) chmax(v[j],v[i]); } REP(i, 1, n+1) std::cout << v[i] << " \n"[i==n]; return 0; }
#include <cstdio> struct t_Edge { int next; int to; int c; }; t_Edge edge[400010]; int N, M, a, b, w; int father[200010]; int head[200010], num_edge; int vis[200010], ans[200010]; void add(int from, int to, int c) { edge[++num_edge].next = head[from]; edge[num_edge].to = to; edge[num_edge].c = c; head[from] = num_edge; } int find(int x) { if(father[x]!=x) father[x] = find(father[x]); return father[x]; } void DFS(int u) { for(int i=head[u];i;i=edge[i].next) { int v = edge[i].to; if(vis[v]) continue; vis[v] = 1; if(ans[u]==edge[i].c) { if(edge[i].c==1) ans[v] = 2; else ans[v] = 1; } else ans[v] = edge[i].c; DFS(v); } } int main() { scanf("%d%d", &N, &M); for(int i=1;i<=N;i++) father[i] = i; for(int i=1;i<=M;i++) { scanf("%d%d%d", &a, &b, &w); int r1 = find(a), r2 = find(b); if(r1==r2) continue; father[r2] = r1; add(a, b, w); add(b, a, w); } vis[1] = ans[1] = 1; DFS(1); for(int i=1;i<=N;i++) printf("%d\n", ans[i]); return 0; }
#include <bits/stdc++.h> #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #define ll long long #define ALL(a) (a).begin(),(a).end() #define rep(i,n) for(int i=0;i<(n);i++) #define rrep(i,n) for(int i=n-1;i>=0;i--) #define Pii pair<int,int> #define Pll pair<long long,long long> #define fout(num) cout << fixed << setprecision(20) << (num) << endl template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;} //vector<vector<ll>> dp(n,vector<ll>(n)) //2-dim:vector<vector<Type>> vv(n, vector<Type>(m, d)); //3-dim:vector<vector<vector<Type>>> vvv(n, vector<vector<Type>>(m, vector<Type>(l, d))); using namespace std; struct Unionfind{ vector<int> data; Unionfind(int size):data(size, -1) {} bool unite(int x, int y){ x=root(x); y=root(y); if(x!=y){ if(data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = x; } return x!=y; } bool same(int x, int y){ return root(x) == root(y); } int root(int x){ return (data[x] < 0) ? x : data[x]=root(data[x]); } int size(int x){ return -data[root(x)]; } }; signed main(){ std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); int n,m; cin >> n >> m; vector<int> col(n,-1); vector<vector<Pii>> G(n); Unionfind uni(n); vector<int> use(n+1,1); rep(i,m){ int u,v,c; cin >> u >> v >> c; u--; v--; if(!uni.same(u,v)){ if(u==0||v==0){ use[c]=0; } uni.unite(u,v); G[u].push_back({v,c}); G[v].push_back({u,c}); } } queue<int> q; q.push(0); while(!q.empty()){ int fr=q.front(); q.pop(); for(auto u:G[fr]){ if(col[u.first]==-1&&u.first!=0){ if(col[fr]==u.second){ if(u.second==n) col[u.first] = u.second-1; else col[u.first] = u.second+1; }else col[u.first]=u.second; q.push(u.first); } } } for(int i=1;i<=n;i++){ if(use[i]){ col[0]=i; break; } } rep(i,n){ cout << col[i] << endl; } return 0; } // g++ main.cpp -o main.out && ./main.out
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define sz(a) (int)a.size() #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(),v.rend() #define int long long const int N = 1e5+10; struct node{ int t; int k; }; map<int,node> mp; bool vis[N]; vector<pair<int,pair<int,int>>> adj[N]; int dist[N]; void solve() { int n,m,x,y; cin >> n >> m >> x >> y; for(int i= 0;i < m;i++) { int a,b,c,d; cin >> a >> b >> c >> d; adj[a].pb({b,{c,d}}); adj[b].pb({a,{c,d}}); } for(int i = 0;i <=n;i++) dist[i]=1e17; dist[x] = 0; priority_queue<pair<int,int>> q; q.push({0,x}); while(!q.empty()) { int u = q.top().second; q.pop(); if(vis[u])continue; vis[u] = true; for(auto x : adj[u]) { int v = x.first; int t = x.second.first; int k=x.second.second; int new_dist = ((dist[u] + k-1) / k) * k + t; if(dist[v] > new_dist){ dist[v] = new_dist; q.push({-dist[v], v}); } } } cout << (dist[y]==1e17?-1:dist[y]); } int32_t main() { ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); int t = 1; //cin >> t; while(t--) { solve(); } }
#include<iostream> #include<map> #include<set> using namespace std; map<char,int> mp; string a[3]; long long p[3],k; set<char> s; char c[10]; bool b[10],en; void dfs(int t) { if(en) return; if(t==k) { if(mp[a[0][0]]&&mp[a[1][0]]&&mp[a[2][0]]) { for(int i=0;i<3;++i) { p[i]=0; for(int j=0;j<a[i].size();++j) p[i]=p[i]*10+mp[a[i][j]]; } if(p[0]+p[1]==p[2]) { en=1; cout<<p[0]<<endl<<p[1]<<endl<<p[2]<<endl; } } return; } for(int i=0;i<10;++i) { if(!b[i]) b[i]=1,mp[c[t]]=i,dfs(t+1),b[i]=0; } } int main() { cin>>a[0]>>a[1]>>a[2]; for(int i=0;i<3;++i) for(int j=0;j<a[i].size();++j) s.insert(a[i][j]); k=s.size(); if(k>10) { cout<<"UNSOLVABLE\n"; return 0; } for(int i=0;i<k;++i) c[i]=*s.begin(),s.erase(s.begin()); dfs(0); if(!en) cout<<"UNSOLVABLE\n"; return 0; }
#pragma GCC optimize ("O2") #pragma GCC target ("avx2") //#include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; #include<cstdio> #include<cstring> using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please int to[400001], ne[400001], he[200001]; int Q[200001], pl[200001], dl[200001]; const int CM = 1 << 17, CL = 12; char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct; const ll ma0 = 1157442765409226768; const ll ma1 = 1085102592571150095; const ll ma2 = 71777214294589695; const ll ma3 = 281470681808895; const ll ma4 = 4294967295; inline int getint() { if (ci - owa > 0) { memcpy(cn, owa, CL); ci -= CM; fread(cn + CL, 1, CM, stdin); } ll tmp = *(ll*)ci; int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0); tmp = tmp << dig & ma1; tmp = tmp * 10 + (tmp >> 8) & ma2; tmp = tmp * 100 + (tmp >> 16) & ma3; tmp = tmp * 10000 + (tmp >> 32) & ma4; ci += 72 - dig >> 3; return tmp; } int main() { //cin.tie(0); //ios::sync_with_stdio(false); int N = getint(), K = getint(); int k = 1; rep(i, N - 1) { int u = getint(), v = getint(); to[k] = v; ne[k] = he[u]; he[u] = k++; to[k] = u; ne[k] = he[v]; he[v] = k++; } int q = 0, p = 0; Q[q++] = 1; while (p < N) { int u = Q[p++]; int tmp = 0; int ind = he[u]; he[u] = 0; while (ind) { int v = to[ind]; tmp = ne[ind]; if (he[v] > 0) { Q[q++] = v; ne[ind] = he[u]; he[u] = -ind; } ind = tmp; } } int are = 1000000, pd0 = are; int L = 0, R = (N + K - 1) / K; while (L + 1 < R) { int wj = (L + R) / 2; int num = 0; for (int i = N - 1; i >= 0; i--) { int po = pd0 - 1; int dd = pd0; int u = Q[i]; for (int ind = -he[u]; ind; ind = -ne[ind]) { int v = to[ind]; if (po < pl[v]) po = pl[v]; if (dd < dl[v]) dd = dl[v]; } if (po >= dd) dd = 0; if (dd >= pd0 + wj) { num++; po = pd0 + wj; dd = 0; } pl[u] = po - 1; dl[u] = dd + 1; } int are = num + (dl[1] > pd0); if (are > K) L = wj; else R = wj; pd0 += are; } printf("%d", R); Would you please return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; const int MAXN = 2e5 + 10; const int MAXM = 2e5 + 10; const ll INF = 1e18; struct edge { int u,v; int next; }e[MAXM * 2]; int first[MAXN], n, k; int idx; void add(int a, int b) { e[idx].u = a; e[idx].v = b; e[idx].next = first[a]; first[a] = idx++; } void init() { fill(first, first + n + 1, -1); idx = 0; } ll f[MAXN], g[MAXN]; int point[MAXN]; int cnt; void dfs(int u, int fa, int mid) { f[u] = -INF; g[u] = INF; for (int i = first[u]; i != -1; i = e[i].next) { int v = e[i].v; if (v == fa) continue; dfs(v, u, mid); f[u] = max(f[u], f[v] + 1); g[u] = min(g[u], g[v] + 1); } if (f[u] + g[u] <= mid) f[u] = -INF; if (g[u] > mid) f[u] = max(f[u], 0ll); if (f[u] == mid) f[u] = -INF, g[u] = 0, ++cnt; } int check(int mid) { cnt = 0; dfs(1, -1, mid); if (f[1] >= 0) cnt++; //cout << "cnt:" << cnt << endl; return cnt <= k; } int main() { scanf("%d%d", &n, &k); init(); for (int i = 1; i < n; i++) { int u, v; scanf("%d%d", &u, &v); add(u, v); add(v, u); } int left = 0, right = n; int ans = n; while (left < right) { int mid = (left + right) >> 1; //cout << "mid:" << mid << endl; if (check(mid)) { ans = mid; right = mid; } else { left = mid + 1; } } printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int N, Q; cin >> N; vector<char> S(N), S2(N); for(int i=0; i<N; i++){ cin >> S.at(i); } for(int i=0; i<N; i++){ cin >> S2.at(i); } cin >> Q; vector<int> T(Q), A(Q), B(Q); for(int i=0; i<Q; i++){ cin >> T.at(i); cin >> A.at(i); cin >> B.at(i); } for(int i=0; i<Q; i++){ if(T.at(i) == 1){ if(A.at(i)<=N && B.at(i)<=N){ swap(S.at(A.at(i)-1), S.at(B.at(i)-1)); } else if(A.at(i)>N && B.at(i)<=N){ swap(S2.at(A.at(i)-N-1), S.at(B.at(i)-1)); } else if(A.at(i)<=N && B.at(i)>N){ swap(S.at(A.at(i)-1), S2.at(B.at(i)-N-1)); } else{ swap(S2.at(A.at(i)-N-1), S2.at(B.at(i)-N-1)); } } else{ swap(S,S2); } } for(int i=0; i<N; i++){ cout << S.at(i); } for(int i=0; i<N; i++){ cout << S2.at(i); } }
#include <bits/stdc++.h> using namespace std; int main() { int N,Q; string S,s,t; cin >> N >> S >> Q; s=S.substr(0,N); t=S.substr(N); //cout << s << t << endl; bool x=true; for (int i=0; i<Q; i++) { int T,A,B; cin >> T >> A >> B; A--;B--; if (T==1) { if (B<N) { if (x) swap(s[A],s[B]); else swap(t[A],t[B]); } else if (A>=N) { A-=N,B-=N; if (x) swap(t[A],t[B]); else swap(s[A],s[B]); } else { B-=N; if (x) swap(s[A],t[B]); else swap(t[A],s[B]); } } else { if (x) x=false; else x=true; } //cout << s << t << endl; } if (x) cout << s << t << endl; else cout << t << s << endl; }
#include<bits/stdc++.h> #define int long long using namespace std; int const MOD=998244353,N=233333; int n,f[N],vis[N],cnt; inline int find(int x){ return x==f[x]?x:f[x]=find(f[x]); } inline int qpow(int x,int y){ return !y?1:qpow(x,y-1)*x%MOD; } signed main(){ ios::sync_with_stdio(0); cin>>n; for(int i=1;i<=n;i++)f[i]=i; for(int i=1;i<=n;i++){ int x;cin>>x; int fx=find(x),fy=find(i); if(fx!=fy)f[fx]=fy; } for(int i=1;i<=n;i++)vis[find(i)]=1; for(int i=1;i<=n;i++)cnt+=vis[i]; cout<<((qpow(2,cnt)+MOD-1)%MOD); }
#pragma GCC optimize ("O3") #include <bits/stdc++.h> typedef long long ll; using namespace std; const int N = 2e5 + 5; const int mod = 998244353; int n, a[N], vis[N]; int main() { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> n; for(int i = 1;i <= n;i++) cin >> a[i]; int ans = 1; for(int i = 1;i <= n;i++) { int x = i; while(vis[x] == 0) vis[x] = 1, x = a[x]; if(vis[x] == 1) ans = (ans + ans) % mod; x = i; while(vis[x] == 1) vis[x] = 2, x = a[x]; } ans = (ans + mod - 1) % mod; cout << ans; return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; using std::cout; using std::cin; using std::endl; using ll=long long; using ld=long double; ll I=1167167167167167167; ll Q=1e9+7; #define rep(i,a) for (ll i=0;i<a;i++) template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>; template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();} template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();} template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;} template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;} template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());} template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});} template<class T> void print_tate(vector<T> &v) {rep(i,v.size()) cout<<v[i]<<"\n";} void yneos(bool a){if(a) cout<<"Yes"<<"\n"; else cout<<"No"<<"\n";} //おちこんだりもしたけれど、私はげんきです。 int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll N; cin>>N; vector<ll> fib={1,1}; int k=1; while(fib[k]+fib[k-1]<=N){ fib.push_back(fib[k]+fib[k-1]); k++; } int M=fib.size(); vector<int> c(M); for(int i=M-1;i>0;i--){ while(N>=fib[i]){ c[i]++; N-=fib[i]; } } vector<ll> ans; for(int i=1;i<M;i++){ int a=1,b=4; if((M-i)%2==1){ a=2; b=3; } rep(j,c[M-i]) ans.push_back(a); ans.push_back(b); } cout<<ans.size()<<"\n"; rep(i,ans.size()){ cout<<ans[i]<<"\n"; } /*ll X=0,Y=0; rep(i,ans.size()){ if(ans[i]==1) X++; if(ans[i]==2) Y++; if(ans[i]==3) X+=Y; if(ans[i]==4) Y+=X; cout<<X<<" "<<Y<<endl; }*/ }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i,n) for (int i = 0; i < (int)(n) ; i++) vector<ll> to_base3(ll n) { if(n==0) return vector<ll>{0}; vector<ll> ret; while(n>0) { ret.push_back(n%3); n/=3; } return ret; } ll subcom(ll a, ll b) { if(a==0) { if(b==0) return 1; return 0; } if(a==1) { if(b==2) return 0; return 1; } else { if(b==0 || b==2) return 1; return 2; } } ll com(ll a, ll b) { // Lucasの定理 if(a<b) return 0; ll ret=1; auto v=to_base3(a); auto w=to_base3(b); for(int i=0; i<(int)min(v.size(), w.size()); i++) { ret *= subcom(v[i], w[i]); ret %= 3; } return ret; } int main() { ll n; cin>>n; vector<ll> bottom(n); rep(i, n) { char t; cin>>t; if(t=='R') bottom[i]=0; else if(t=='B') bottom[i]=1; else bottom[i]=2; } ll ans=0; for(int i=0; i<=n-1; i++) { ans = (ans+bottom[i]*com(n-1, i))%3; } if((n-1)%2==1) ans = (3-ans)%3; if(ans==0) cout << 'R' << endl; else if(ans==1) cout << 'B' << endl; else cout << 'W' << endl; }
//In the name of God #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pll; const ll maxn = 1e10; const ll mod = 1e9 + 7; const ll inf = 1e18; #define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define file_io freopen("input.txt", "r+", stdin);freopen("output.txt", "w+", stdout); #define pb push_back #define Mp make_pair #define F first #define S second #define Sz(x) ll((x).size()) #define all(x) (x).begin(), (x).end() ll n, vis[3]; string s; int main(){ fast_io; cin >> n >> s; if(s == "1"){ cout << maxn * 2; return 0; } if(s == "0"){ cout << maxn; return 0; } if(s == "11"){ cout << maxn; return 0; } ll x = -1; for(ll i = 0; i < n; i++){ if(s[i] == '0'){ x = i; } } if(x == -1){ cout << 0; return 0; } for(ll i = 0; i < n; i++){ if((s[i] == '0') != (x % 3 == i % 3)){ cout << 0; return 0; } } cout << maxn - (n + (2 - x % 3) + ((x - n) % 3 + 4) % 3) / 3 + 1; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++) #define all(v) v.begin(), v.end() #define sz(v) v.size() #define INF 100000000000000 //10^14 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; } struct edge { ll to; }; vector<vector<edge>> graph; vector<ll> par(1000000); vector<ll> rnk(1000000); void init(ll n){ rep(i, n){ par.at(i) = i; rnk.at(i) = 0; } } ll root(ll x){ if(par.at(x) == x){ return x; } else{ par.at(x) = root(par.at(x)); return par.at(x); } } bool same(ll x, ll y){ if(root(x) == root(y)){ return true; } else{ return false; } } void unite(ll x, ll y){ x = root(x); y = root(y); if(x == y){ return; } if(rnk.at(x) < rnk.at(y)){ par.at(x) = y; } else{ par.at(y) = x; if(rnk.at(x) == rnk.at(y)){ rnk.at(x)++; } } } int main() { ll N, M; cin >> N >> M; graph.resize(N); init(N); vector<ll> a(N); rep(i, N) cin >> a.at(i); vector<ll> b(N); rep(i, N) cin >> b.at(i); rep(i, M){ ll c, d; cin >> c >> d; c--; d--; graph.at(c).push_back({d}); graph.at(d).push_back({c}); unite(c, d); } map<ll, ll> s; map<ll, ll> g; rep(i, N){ s[root(i)] += a.at(i); g[root(i)] += b.at(i); } rep(i, N){ if(s.at(root(i)) != g.at(root(i))){ cout << "No" << endl; return 0; } } cout << "Yes" << endl; }
#include<iostream> using namespace std; int main() { int n; cin>>n; cout<<n-1; return 0; }
#include <iostream> using namespace std; unsigned long long div_cnt[2][12] = {0}; int main() { int L; cin >> L; div_cnt[1][0] = 1; for (int i = 1; i < L; i++) { for (int j = 0; j < 12; j++) { div_cnt[0][j] = div_cnt[1][j]; } for (int j = 1; j < 12; j++) { div_cnt[1][j] = div_cnt[0][j-1]+div_cnt[0][j]; } } cout << div_cnt[1][11] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ long long A,B; cin >> A >> B; vector<long long> V(200001,0); for(long long i=A;i<=B;i++){ V[1]++; V[i]++; for(long long j=2;j*j<=i;j++){ if(i%j==0){ V[j]++; if(i/j!=j) V[i/j]++; } } } for(int i=200000;;i--){ if(V[i]>=2){ cout << i << endl; return 0; } } return 0; }
#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 main() { int a, b; cin >> a >> b; int ans = 1; for (int i = 1; i <= b; i++) { for (int j = 2; j * j <= i; j++) { if (i % j == 0) { int k = (a + j - 1) / j * j; if (k <= b && k + j <= b) { ans = max(ans, j); } } if (i % j == 0) { int k = (a + (i / j) - 1) / (i / j) * (i / j); if (k <= b && k + i / j <= b) { ans = max(ans, (i / j)); } } } } cout << ans << endl; }
#include <iostream> #include <iomanip> #include <vector> #include <map> #include <algorithm> #include <string> #include <numeric> #include <cmath> #include <math.h> #define cPI 3.14159265358979323846 using namespace std; vector<int64_t> ans; void func( ) { int64_t N; cin >> N; if (N % 2 == 0) cout << "White\n"; else cout << "Black\n"; } int main() { // while (1) func(); return 0; }
#include<iostream> using namespace std; int main() {int n; cin>>n; if(n%2==0)cout<<"White"; if(n%2==1)cout<<"Black"; }
// Problem: D - KAIBUNsyo // Contest: AtCoder - AtCoder Beginner Contest 206(Sponsored by Panasonic) // URL: https://atcoder.jp/contests/abc206/tasks/abc206_d // Memory Limit: 1024 MB // Time Limit: 2000 ms // // Powered by CP Editor (https://cpeditor.org) // krishrawat #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #include <bits/stdc++.h> using namespace std; #define pb insert #define eb emplace_back #define ff first #define ss second #define all(a) a.begin(), a.end() #define show(x) cerr << #x << " is " << x << "\n" #define show2(x, y) cerr << #x << " " << #y << " " << x << " " << y << "\n" typedef long long int ll; typedef long double ld; typedef vector<ll> vl; typedef pair<ll, ll> pp; typedef vector<pp> vp; typedef map<ll, ll> ii; typedef set<ll> sl; typedef multiset<ll> msl; typedef set<pair<ll, ll>> sp; const ll MOD = 1e9 + 7; const ll N = 2e5 + 1; ll mod_mul(ll x, ll y) { return ((x % MOD) * (y % MOD)) % MOD; } ll mod_add(ll x, ll y) { return ((x % MOD) + (y % MOD)) % MOD; } ll par[N]; ll sz[N]; ll find_par(ll x) { if (par[x] == x) return x; return par[x] = find_par(par[x]); } void join(ll x, ll y) { x = find_par(x); y = find_par(y); if (x != y) { if (sz[y] > sz[x]) swap(x, y); sz[x] += sz[y]; par[y] = x; } } // main code void solve() { ll n; cin >> n; vl v(n); for (auto &i : v) { cin >> i; par[i] = i; sz[i] = 1; } ll i = 0, j = n - 1; ll ans = 0; while (i < j) { ll a = v[i]; ll b = v[j]; a = find_par(a); b = find_par(b); if (a != b) { ans++; join(a, b); } i++; j--; } cout << ans << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll t; t = 1; // cin >> t; while (t--) solve(); return 0; }
#include <bits/stdc++.h> #define int long long #define f(i,a,n) for (int i = a; i < n; ++i) #define fr(i,a,n) for(int i=a;i>=n;i--) #define ff first #define ss second #define pb push_back #define mp make_pair #define all(x) x.begin(), x.end() #define sortall(x) sort(all(x)) #define fastio ios_base::sync_with_stdio(false), cin.tie(NULL); #define w1 solve(); #define MOD (int)(1e9 + 7) #define prq priority_queue #define gcd __gcd #define sz(x) (int)x.size() #define w(t) int t; cin>>t; f(i,1,t+1) {solve(i);} using namespace std; #ifdef Avash_Local_Machine #include "debug.h" #else #define debug(x...) #endif typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pii> vpi; typedef vector<string> vs; typedef vector<char> vc; typedef vector<bool> vb; const int INF = (int)(1e17); const double PI = 3.141592653589793; int dx[4] = { -1, 0, 1, 0}; int dy[4] = {0, 1, 0, -1}; string path = "URDL"; // #define SIZE (int)(10000) // vector<int> adj[SIZE]; // vector<pii> adj[SIZE]; // vector<int> vis(SIZE, 0); int dp[801][801]; int arr[801][801]; void solve(int tc = 1) { int n, k; cin >> n >> k; f(i, 0, n) f(j, 0, n) cin >> arr[i][j]; int l = 0, r = 1e9; int ans = -1; while (l <= r) { int mid = (l + r) / 2; f(i, 0, n) f(j, 0, n) { if (arr[i][j] <= mid) dp[i][j] = 1; else dp[i][j] = 0; } f(i, 0, n) f(j, 0, n) { if (i > 0) dp[i][j] += dp[i - 1][j]; if (j > 0) dp[i][j] += dp[i][j - 1]; if (i > 0 and j > 0) dp[i][j] -= dp[i - 1][j - 1]; } bool ok = false; f(i, k - 1, n) { f(j, k - 1, n) { int sum = dp[i][j]; if (i >= k)sum -= dp[i - k][j]; if (j >= k)sum -= dp[i][j - k]; if (i >= k and j >= k)sum += dp[i - k][j - k]; int x = (k * k) / 2; if (k & 1) x++; if (sum >= x) { ok = true; break; } } if (ok == true) break; } if (ok) { r = mid - 1; ans = mid; } else l = mid + 1; } cout << ans << "\n"; } int32_t main() { fastio clock_t begin = clock(); w1 clock_t end = clock(); #ifdef Avash_Local_Machine cerr << "Executed In: " << double(end - begin) / CLOCKS_PER_SEC * 1000 << " ms\n"; #endif return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define debug(x) cerr << #x << ": " << x << '\n' #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define reps(i, n, m) for (int i = (int)(n); i < (int)(m); i++) #define ALL(obj) (obj).begin(), (obj).end() #define rALL(obj) (obj).rbegin(), (obj).rend() using ll = long long; using ld = long double; using intp = pair<int, int>; using intmap = map<int, int>; using intset = set<int>; using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; constexpr int MOD = 998244353; constexpr int INF = 1 << 30; constexpr ll LINF = 1LL << 62; inline int mod(ll a, int m = MOD) { return (a % m + m) % m; } inline bool bit(ll b, ll i) { return b & (1 << i); } inline ll ceiv(ll a, ll b) { return (a + b - 1) / b; } template<class T> bool chmin(T &a, T b) {if(a > b){a = b; return 1;} return 0;} template<class T> bool chmax(T &a, T b) {if(a < b){a = b; return 1;} return 0;} signed main() { int x; cin >> x; cout << (x < 0 ? 0 : x) << endl; }
#include <iostream> using namespace std; int main() { int x; cin >> x; if (x >= 0) { cout << x << endl; } else { cout << 0 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll, ll> pll; #define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i)) #define REP(i, n) FOR(i,n,0) #define OF64 std::setprecision(40) const ll MOD = 1000000007; const ll INF = (ll) 1e15; bool solve(vector<ll> &A) { ll N = A.size(); vector<ll> ans; REP(i, N * N) { bool sorted = true; REP(j, N - 1) { if (A[j] > A[j + 1]) { sorted = false; break; } } if (sorted) break; bool update = false; REP(j, N) { if (i % 2 != j % 2) continue; if (j + 1 >= N) break; if (A[j] > A[j + 1]) { update = true; swap(A[j], A[j + 1]); ans.push_back(j); break; } } if (!update) { for (ll j = N - 2; j >= 0; --j) { if (j % 2 == i % 2) { swap(A[j], A[j + 1]); ans.push_back(j); break; } } } #if false REP(j, N) { cout << A[j] << " "; } cout << endl; #endif } cout << ans.size() << endl; REP(i, ans.size()) { cout << ans[i] + 1 << " "; } cout << endl; { bool sorted = true; REP(j, N - 1) { if (A[j] > A[j + 1]) { sorted = false; break; } } return sorted; } } int main() { cin.tie(0); ios::sync_with_stdio(false); #if true ll Q; cin >> Q; REP(_, Q) { ll N; cin >> N; vector<ll> A(N); REP(i, N) { cin >> A[i]; } if (!solve(A)) { assert(false); } } #else vector<ll> A; ll N = 8; REP(i, N) { A.push_back(i + 1); } do { vector<ll> v; REP(i, N) { v.push_back(A[i]); } if (!solve(v)) { assert(false); } } while (next_permutation(A.begin(), A.end())); #endif return 0; }
#include <bits/stdc++.h> using namespace std; #define sim template < class c #define ris return * this #define dor > debug & operator << #define eni(x) sim > typename \ enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { #ifdef LOCAL ~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } #else sim dor(const c&) { ris; } #endif }; #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " #define x first #define y second int main() { int n; cin >> n; vector<pair<int, int>> v(n); for (int i = 0; i < n; ++i) { cin >> v[i].first >> v[i].second; } for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { if (i == j) continue; for (int k = 0; k < n; ++k) { if (k == j) continue; if (k == i) continue; if ((v[j].x - v[i].x) * (v[k].y - v[i].y) == (v[j].y - v[i].y) * (v[k].x - v[i].x)) { cout << "Yes\n"; return 0; } } } } cout << "No\n"; }
#include<bits/stdc++.h> #define LL long long using namespace std; LL A=-1e16,B=1e16,C,a; int n,q,t; int main(){ scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%lld%d",&a,&t); if(t==1){ A+=a; B+=a; C+=a; } else if(t==2){ A=max(A,a); B=max(B,a); } else { A=min(A,a); B=min(B,a); } } scanf("%d",&q); while(q--){ scanf("%lld",&a); printf("%lld\n",min(B,max(A,a+C))); } return 0; }
//@formatter:off #include<bits/stdc++.h> #define overload4(_1,_2,_3,_4,name,...) name #define rep1(i,n) for (ll i = 0; i < ll(n); ++i) #define rep2(i,s,n) for (ll i = ll(s); i < ll(n); ++i) #define rep3(i,s,n,d) for(ll i = ll(s); i < ll(n); i+=d) #define rep(...) overload4(__VA_ARGS__,rep3,rep2,rep1)(__VA_ARGS__) #define rrep1(i,n) for (ll i = ll(n)-1; i >= 0; i--) #define rrep2(i,n,t) for (ll i = ll(n)-1; i >= (ll)t; i--) #define rrep3(i,n,t,d) for (ll i = ll(n)-1; i >= (ll)t; i-=d) #define rrep(...) overload4(__VA_ARGS__,rrep3,rrep2,rrep1)(__VA_ARGS__) #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define popcount(x) __builtin_popcount(x) #define pb push_back #define eb emplace_back #ifdef __LOCAL #define debug(...) { cout << #__VA_ARGS__; cout << ": "; print(__VA_ARGS__); cout << flush; } #else #define debug(...) void(0) #endif #define INT(...) int __VA_ARGS__;scan(__VA_ARGS__) #define LL(...) ll __VA_ARGS__;scan(__VA_ARGS__) #define STR(...) string __VA_ARGS__;scan(__VA_ARGS__) #define CHR(...) char __VA_ARGS__;scan(__VA_ARGS__) #define DBL(...) double __VA_ARGS__;scan(__VA_ARGS__) #define LD(...) ld __VA_ARGS__;scan(__VA_ARGS__) using namespace std; using ll = long long; using ld = long double; using P = pair<int,int>; using LP = pair<ll,ll>; using vi = vector<int>; using vvi = vector<vector<int>>; using vl = vector<ll>; using vvl = vector<vector<ll>>; using vd = vector<double>; using vvd = vector<vector<double>>; using vs = vector<string>; using vc = vector<char>; using vvc = vector<vector<char>>; using vb = vector<bool>; using vvb = vector<vector<bool>>; using vp = vector<P>; using vvp = vector<vector<P>>; template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; } template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; } template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; } template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?"":","); return os<<']'; } template<class T> void vecout(const vector<T> &v,char div='\n') { rep(i,v.size()) cout<<v[i]<<(i==int(v.size()-1)?'\n':div);} template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;} template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;} void scan(){} template <class Head, class... Tail> void scan(Head& head, Tail&... tail){ cin >> head; scan(tail...); } template<class T> void print(const T& t){ cout << t << '\n'; } template <class Head, class... Tail> void print(const Head& head, const Tail&... tail){ cout<<head<<' '; print(tail...); } template<class... T> void fin(const T&... a) { print(a...); exit(0); } const string yes[] = {"no","yes"}; const string Yes[] = {"No","Yes"}; const string YES[] = {"NO","YES"}; const int inf = 1001001001; const ll linf = 1001001001001001001; //@formatter:on ll dp[2][1 << 21]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); LL(a, b); ll d = b - a + 1; vi p; rep(i, 2, d + 1) { bool ok = true; rep(j, 2, i) if (i % j == 0) ok = false; if (ok) p.pb(i); } int sz = p.size(); dp[0][0] = 1; debug(p); rep(i, d) { ll now = a + i; int bit = 0; rep(k, sz) { if (now % p[k]) continue; bit |= 1 << k; } rep(j, 1 << sz) { if (dp[0][j] == 0) continue; dp[1][j] += dp[0][j]; if ((bit & j) == 0) dp[1][bit | j] += dp[0][j]; dp[0][j] = 0; } swap(dp[0], dp[1]); } ll ans = 0; rep(i, 1 << sz) ans += dp[0][i]; print(ans); }
#include<bits/stdc++.h> using namespace std; #define arep(i,x,n) for(int i=int(x);i<(int)(n);i++) #define rep(i,n) for(ll i = 0;i < (ll)n;++i) #define rrep(i,n) for(int i=int(n-1);i>=0;i--) #define fs first #define sc second #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define coy cout<<"Yes"<<endl #define con cout<<"No"<<endl #define pi 3.141592653589793 #define eps 0.00000001 #define INF 1e9+7 #define LINF (ll)1e18+10 using ll = long long; using P = pair<ll,ll>; using fP = pair<double, double>; using PPI = pair<P, int>; using PIP = pair<int, P>; using Ps = pair<int, string>; using vi = vector<int>; using vl = vector<ll>; using vc = vector<char>; using vd = vector<double>; using vs = vector<string>; using vp = vector<P>; using vb = vector<bool>; using vvi = vector<vector<int>>; using vvl = vector<vector<ll>>; using vvd = vector<vector<double>>; using vvc = vector<vector<char>>; using vvp = vector<vector<P>>; using vvb = vector<vector<bool>>; 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 ll mod=998244353; const ll mod = 1e9 + 7; const ll MAX = 100; template <typename T> T abs(T a) { if (a < 0)return -a; else return a; }//2020/09/30 stdlib has abs(long) abs(long long) error ////////////////////////////////////// int main(){ int n,m; cin>>n>>m; vvi e(n); rep(i,m){ int a,b; cin>>a>>b; --a,--b; e[a].push_back(b); } vi ans(n); rep(i,n){ queue<int>q; q.push(i); vi used(n); used[i]=1; while(q.size()){ int now=q.front();q.pop(); for(int to : e[now]){ if(used[to])continue; q.push(to); ans[i]++; used[to]=1; } } } int sum=0; rep(i,n)sum+=ans[i]; cout<<sum+n<<endl; return 0; }
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define pb push_back #define inf 1e18 // 1000000007 , 998244353 // cout<<"? "<<endl for interactive #define MOD 998244353 #define mp make_pair #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define clr(x,y,z) (x).clear(),(x).resize((y),(z)) typedef long long int lli; typedef vector<lli> vli; typedef vector<int> vi; typedef tuple<int, int, long long int>tup; typedef unsigned long long ull; typedef long double ld; typedef pair<lli, lli> pll; typedef pair<int, int> pii; #define csb(x) __builtin_popcount(x) #define clz(x) __builtin_clz(x) #define ctz(x) __builtin_ctz(x) #define clin(x,n,m) x>=n*m||x<0||(x%m==0 && j==2) || (x%m==m-1 && j==3) #define cgrid(x,y,n,m) x>=n||y>=m||x<=0||y<=0 #define PI 3.1415926535897932384626 // #define deb(x) cout << #x << " = " << x << endl; #define deb(...) logger(#__VA_ARGS__, __VA_ARGS__) #define show(x) {for( auto i : x) cout << i << '\t'; cout << endl;} #define show2(x,l1,l2) {for( int i=0;i<l1;i++){for(int j=0;j<l2;j++) cout << x[i][j] << '\t'; cout << endl;}} #define rep(i,st,ed) for(int i=(st);i<(ed);i++) #define rrep(i,ed,st) for(int i=ed;i>=st;i--) #define ff first #define ss second #define minheap(type) priority_queue<type,vector<type>,greater<type>> #define sze(x) (int)x.size() #define rgenerate mt19937 rgen(chrono::high_resolution_clock::now().time_since_epoch().count()) #define indexed_set tree<lli,null_type,less<lli>,rb_tree_tag,tree_order_statistics_node_update> #define yes cout<<"YES\n" #define no cout<<"NO\n" template <typename T> void ckmin(T &a, const T &b) { a = min(a, b); } template <typename T> void ckmax(T &a, const T &b) { a = max(a, b); } template<typename ...Args>void logger(string vars, Args&&... values) {cout << vars << " = "; string delim = ""; (..., (cout << delim << values, delim = ", ")); cout << "\n";} long long gcd(ull a, ull b) { return b == 0 ? a : gcd(b, a % b); } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } void sieve(vector<int>&spf) {int n = spf.size(); rep(i, 2, n) {if (!spf[i]) {/*prime.pb(i);*/ for (int j = i; j < n; j += i) spf[j] = i; }}} lli power(lli x, lli y, long long int m = MOD) { lli ans = 1; x %= m; while (y) {if (y & 1)ans = (x * ans) % m; x = (x * x) % m; y >>= 1;} return ans;} lli ncr(vli&fact, int n, int r) {return (n >= r) ? ((fact[n] * ((power(fact[r], MOD - 2) * power(fact[n - r], MOD - 2) ) % MOD)) % MOD) : 0;} int add(int x, int y) {x += y; while (x >= MOD) x -= MOD; while (x < 0) x += MOD; return x;} int mul(int x, int y) {return (x * 1ll * y) % MOD;} int divide(int x, int y) {return mul(x, power(y, MOD - 2));} // int dx[] = {1, -1, 0, 0}; // int dy[] = {0, 0, 1, -1}; // int dl[] = {m, -m, 1, -1}; vector<vi>adj; vector<bool>visited; int sz=0; void dfs(int c){ visited[c]=true; sz++; for(int i=0;i<adj[c].size();i++){ int nxt =adj[c][i]; if(visited[nxt])continue; dfs(nxt); } } void solve() { int n,m; cin>>n>>m; adj.resize(n); visited.assign(n,false); rep(i,0,m){ int f,t; cin>>f>>t; f--,t--; adj[f].pb(t); } int ans=0; rep(i,0,n){ sz=0; dfs(i),ans+=sz; rep(j,0,n)visited[j]=false; } cout<<ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int z = 1; // cin >> z; while (z--) { solve(); } return 0; }
#include <cstdio> #include <algorithm> using namespace std; typedef long long ll; const int Maxn=100000; int n; int a[Maxn+5],b[Maxn+5]; int c[Maxn+5],d[Maxn+5]; bool cmp(int p,int q){ return p>q; } int main(){ scanf("%d",&n); ll ans=0; for(int i=1;i<=n;i++){ scanf("%d",&a[i]); ans+=a[i]; } for(int i=1;i<=n;i++){ scanf("%d",&b[i]); } for(int i=1;i<=n;i++){ if(i&1){ c[(i+1)>>1]=b[i]-a[i]; } else{ d[i>>1]=b[i]-a[i]; } } sort(c+1,c+1+(n>>1),cmp); sort(d+1,d+1+(n>>1),cmp); for(int i=1;i<=(n>>1);i++){ if(c[i]+d[i]>0){ ans+=c[i]+d[i]; } } printf("%lld\n",ans); return 0; }
#include<stdio.h> #include<stdlib.h> #include<string.h> #define rep(i,N) for(int i=0;i<(int)N;i++) #define Swap(a,b) (a+=b,b=a-b,a-=b) static inline void PUT(char c) { static char buf[1<<15],*ptr=buf; if(ptr==buf+strlen(buf)||c==0){fwrite(buf,1,ptr-buf,stdout),ptr=buf;}*ptr++=c; } static inline int IN(void) { int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();} while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x; } static inline void OUT(long a) { if(a<0)PUT('-'),a=-a; int d[40],i=0;do{d[i++]=a%10;}while(a/=10); while(i--){PUT(d[i]+48);}PUT('\n'); } static inline void AscRadix32(int *a,const int sz,const int minus) { int x,shift=0,elem[0400],temp[sz]; while(shift<040) { int bucket[0400]={0}; rep(i,sz){x=(a[i]>>shift)&0377;bucket[x]++;temp[i]=a[i];} elem[0]=0;rep(i,0377)elem[i+1]=elem[i]+bucket[i]; rep(i,sz){x=(temp[i]>>shift)&0377;a[elem[x]]=temp[i];elem[x]++;} shift+=010; } rep(i,minus>>1)Swap(a[sz-minus+i],a[sz-1-i]); rep(i,(sz-minus)>>1)Swap(a[i],a[sz-minus-1-i]); rep(i,sz>>1)Swap(a[i],a[sz-1-i]); } int main() { int N=IN(),A[N],B[N],m1=0,m2=0,p1[N/2],p2[N/2];long score=0; rep(i,N){A[i]=IN(),score+=A[i];}rep(i,N){B[i]=IN();} rep(i,N)if(i&1){p1[i/2]=B[i]-A[i];if(B[i]-A[i]<0)m1++;}else{p2[i/2]=B[i]-A[i];if(B[i]-A[i]<0)m2++;} AscRadix32(p1,N/2,m1);AscRadix32(p2,N/2,m2); rep(i,N>>1)if(p1[(N>>1)-1-i]+p2[(N>>1)-1-i]>0)score+=p1[(N>>1)-1-i]+p2[(N>>1)-1-i]; return OUT(score),0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; #define FOR(i, n) for(int (i)=0; (i)<(n); (i)++) #define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++) #define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--) template<class T, class U> void umin(T& x, const U& y){ x = min(x, (T)y);} template<class T, class U> void umax(T& x, const U& y){ x = max(x, (T)y);} template<class T, class U> void init(vector<T> &v, U x, size_t n) { v=vector<T>(n, (T)x); } template<class T, class U, typename... W> void init(vector<T> &v, U x, size_t n, W... m) { v=vector<T>(n); for(auto& a : v) init(a, x, m...); } const ll MOD = 1e9 + 7; int main(int argc, char** argv) { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << fixed << setprecision(15); if (argc == 2 && atoi(argv[1]) == 123456789) freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin); int h, w; cin >> h >> w; vector<string> s(h); FOR(i, h) cin >> s[i]; vector<vector<ll>> dp, a, b, c; init(dp, 0, h, w); init(a, 0, h, w); init(b, 0, h, w); init(c, 0, h, w); dp[0][0] = a[0][0] = b[0][0] = c[0][0] = 1; FOR(i, h){ FOR(j, w){ if (i == 0 && j == 0) continue; if (s[i][j] == '#') continue; if (i) a[i][j] = a[i-1][j]; if (j) b[i][j] = b[i][j-1]; if (i && j) c[i][j] = c[i-1][j-1]; dp[i][j] = a[i][j] + b[i][j] + c[i][j]; dp[i][j] %= MOD; a[i][j] += dp[i][j]; a[i][j] %= MOD; b[i][j] += dp[i][j]; b[i][j] %= MOD; c[i][j] += dp[i][j]; c[i][j] %= MOD; } } cout << dp[h-1][w-1] << endl; if (argc == 2 && atoi(argv[1]) == 123456789) cout << clock()*1.0/CLOCKS_PER_SEC << " sec\n"; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long int ll; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t=1; while(t--){ ll n,x,ans=0; cin >> n >> x; vector<ll> arr(n,0); for(int i=0;i<n;i++){ cin >> arr[i]; } vector<map<ll,ll>> dp(n,map<ll,ll> ()); ll factor= x/arr[n-1]; dp[n-1][factor*arr[n-1]-x]=1; if(abs((factor+1)*arr[n-1]-x) < arr[n-1]) dp[n-1][(factor+1)*arr[n-1]-x]=1; for(int i=n-2;i>=0;i--){ for(auto j: dp[i+1]){ ll diff= j.first; factor=diff/arr[i]; dp[i][diff-factor*arr[i]]+=j.second; if(diff<0){ if(abs(factor-1) < arr[i+1]/arr[i] && abs(diff-(factor-1)*arr[i]) < arr[i]){ dp[i][diff-(factor-1)*arr[i]]+=j.second; } } else{ if(factor+1 < arr[i+1]/arr[i] && abs(diff-(factor+1)*arr[i]) < arr[i]){ dp[i][diff-(factor+1)*arr[i]]+=j.second; } } } // if(dp[i].size() > 2){ // cout << "Error" << endl; // break; // } } cout << dp[0][0] << endl; } return 0; }
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <cmath> #include <cstring> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> //#define ENVIRONMENT_LINKED_ACL #ifdef ENVIRONMENT_LINKED_ACL #include <atcoder/convolution> #include <atcoder/lazysegtree> #include <atcoder/segtree.hpp> #endif //#define ENVIRONMENT_LINKED_BOOST #ifdef ENVIRONMENT_LINKED_BOOST #include <boost/multiprecision/cpp_dec_float.hpp> #include <boost/multiprecision/cpp_int.hpp> #endif using namespace std; using uint = unsigned int; using ll = long long; using ull = unsigned long long; #define REP(i, a, b) for (ll i = a; i < b; ++i) #define REPREV(i, a, b) for (ll i = a; i > b; --i) const int _ = []() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(10); return 0; }(); template <typename value_t> void resize(value_t& v, const value_t& val) { v = val; } template <typename vec_t, typename value_t, typename... arg_t> void resize(std::vector<vec_t>& v, const value_t& val, int size, arg_t... arg) { v.resize(size); for (auto& c : v) resize(c, val, arg...); } template <typename A, typename B> void chmin(A& a, const B& b) { a = min(a, static_cast<A>(b)); }; template <typename A, typename B> void chmax(A& a, const B& b) { a = max(a, static_cast<A>(b)); }; template <typename T> T modpow(T r, T n, T mod) { T ans = 1; T tmp = r % mod; while (n > 0) { if ((n & 1) > 0) { ans = ans * tmp % mod; } tmp = tmp * tmp % mod; n >>= 1; } return ans; } int main() { ll N, P; cin >> N >> P; constexpr ll mod = 1e9 + 7; ll ans = (P - 1) * modpow<ll>(P - 2, N - 1, mod) % mod; cout << ans << endl; 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; }
#include <iostream> #include <vector> #include <set> #include <cmath> #include <algorithm> #include <string> #include <utility> #include <map> #include <queue> #include <stack> #include <iomanip> #include <sstream> #include <cstring> #define MP make_pair #define PB push_back #define SZ size() #define B begin() #define E end() #define ll long long #define REP(i,a,n) for(ll i=a; i<n; ++i) #define RED(i,n,a) for(ll i=n; i>=a; --i) #define m9 1000000007 #define endl "\n" #define F first #define S second #define ld long double #define eps 0.00000000001 #define MAX 1000000007 #define vll vector <ll> #define pll pair <ll,ll> using namespace std; ll gcd(ll a, ll b){ if(a%b==0){ return b; } else{ return gcd(b, a%b); } } ll powc(ll a, ll b){ if(b<0){ return 0; } ll md=b; ll res=1; while(b>0){ if(b&1){ res*=a; } a*=a; //res%=MAX, a%=MAX; b>>=1; } return res; } ///target expert int main(){ //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); ios_base::sync_with_stdio(false); cin.tie(NULL); double x1, y1, x2, y2; cin>>x1>>y1>>x2>>y2; cout<<fixed<<setprecision(20)<<(y1*x2+y2*x1)/(y1+y2); }
#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], mx[N], c[N]; void solve() { cin >> n; mx[0] = 0; for (i = 1; i <= n; i++) { cin >> a[i]; mx[i] = max(mx[i - 1], a[i]); } c[0] = 0; for (i = 1; i <= n; i++) { cin >> b[i]; c[i] = max(c[i - 1], b[i] * mx[i]); cout << c[i] << 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; }
//Codeforcesで128bit整数を使いたいとき //→__int128_tを使う&GNU C++17 (64)で提出する //インクルードなど #include <iostream> // cout, endl, cin #include <string> // string, to_string, stoi #include <vector> // vector #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <utility> // pair, make_pair #include <tuple> // tuple, make_tuple #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include <map> // map #include <queue> // queue, priority_queue #include <set> // set #include <stack> // stack #include <deque> // deque #include <unordered_map> // unordered_map #include <unordered_set> // unordered_set #include <bitset> // bitset #include <cctype> // isupper, islower, isdigit, toupper, tolower using namespace std; typedef long long ll; //イテレーション #define REP(i,n) for(ll i=0;i<ll(n);i++) #define REPD(i,n) for(ll i=n-1;i>=0;i--) #define FOR(i,a,b) for(ll i=a;i<=ll(b);i++) #define FORD(i,a,b) for(ll i=a;i>=ll(b);i--) #define FORA(i,I) for(const auto& i:I) //x:コンテナ #define ALL(x) x.begin(),x.end() #define SIZE(x) ll(x.size()) //定数 #define INF32 2147483647 //2.147483647×10^{9}:32bit整数のinf #define INF64 9223372036854775807 //9.223372036854775807×10^{18}:64bit整数のinf #define MOD 1000000007 //問題による //略記 #define F first #define S second //出力(空白区切りで昇順に) #define coutALL(x) for(auto i=x.begin();i!=--x.end();i++)cout<<*i<<" ";cout<<*--x.end()<<endl; #define coutall(x) {for(int i=0;i<sizeof(x)/sizeof(x[0]);i++){cout<<x[i]<<"|";};};cout<<endl; //aをbで割る時の繰上げ,繰り下げ ll myceil(ll a,ll b){return (a+(b-1))/b;} ll myfloor(ll a,ll b){return a/b;} bool xOR(bool x,bool y){ return ((x&&(!y))||((!x)&&y)); } signed main(){ ll v,t,s,d;cin>>v>>t>>s>>d; if(v*t<=d&&v*s>=d){cout<<"No";}else{cout<<"Yes";}; }
#include <cstdio> int V, T, S, D; int main() { scanf("%d %d %d %d", &V, &T, &S, &D); if(V*T<=D and D<=V*S) printf("No"); else printf("Yes"); }
#include <bits/stdc++.h> using namespace std; typedef signed long long ll; #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define FORR2(x,y,arr) for(auto& [x,y]:arr) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;} template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;} //------------------------------------------------------- int H,W; string S[2020]; int dp[2020][2020]; void solve() { int i,j,k,l,r,x,y; string s; cin>>H>>W; FOR(y,H) cin>>S[y]; for(y=H-1;y>=0;y--) { for(x=W-1;x>=0;x--) { if(x==W-1&&y==H-1) continue; if((x+y)%2==0) { dp[y][x]=-10000; if(y+1<H) dp[y][x]=max(dp[y][x],dp[y+1][x]+(S[y+1][x]=='+'?1:-1)); if(x+1<W) dp[y][x]=max(dp[y][x],dp[y][x+1]+(S[y][x+1]=='+'?1:-1)); } else { dp[y][x]=10000; if(y+1<H) dp[y][x]=min(dp[y][x],dp[y+1][x]+(S[y+1][x]=='+'?-1:1)); if(x+1<W) dp[y][x]=min(dp[y][x],dp[y][x+1]+(S[y][x+1]=='+'?-1:1)); } } } if(dp[0][0]>0) { cout<<"Takahashi"<<endl; } else if(dp[0][0]==0) { cout<<"Draw"<<endl; } else cout<<"Aoki"<<endl; } int main(int argc,char** argv){ string s;int i; if(argc==1) ios::sync_with_stdio(false), cin.tie(0); FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin); cout.tie(0); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define endl "\n" #define ll long long #define ld long double #define ul unsigned long #define rep(i,n) for (ll i = 0;i<(n);++i) #define all(v) v.begin(),v.end() 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;} vector<long long> divisor(long long n){vector<long long> res;long long i = 1;while (i*i<=n){if(n%i==0){res.push_back(i);}i++;}if(res.size()==0)return res;for(long long i = res.size()-1-(res.back()*res.back()==n);i>=0;--i){res.push_back(n/res[i]);}return res;} long long safe_mod(long long x,long long m){x%=m;if(x<0){x+=m;}return x;} long long modpow(long long x,long long n,long long mod){long long ans=1;while(n>0){if(n&1){ans*=x;ans%=mod;}n>>=1;x*=x;x%=mod;}return ans;} long long intpow(long long x,long long n){long long ans=1;while(n>0){if(n&1){ans*=x;}n>>=1;x*=x;}return ans;} //template<typename T>T intpow(T x,T n){T ans=1;while(n>0){if(n&1){ans*=x;}n>>=1;x*=x;}return ans;} vector<pair<long long,long long>> factor_lst(long long n){vector<pair<long long,long long>> factor_lst;long long d=2;while(d*d<=n){if(n%d==0){long long num=0;while(n%d==0){num+=1;n/=d;}factor_lst.push_back({d,num});}d+=1;}if(n!=1){factor_lst.push_back({n,1});}return factor_lst;} #define Uniq(a) sort(all(a));a.erase(unique(all(a)),end(a)) int msb(int x){return x==0 ? -1:32-__builtin_clz(x);}//1-indexed int lsb(int x){return x==0 ? 32:__builtin_ctz(x)+1;}//1-indexed int popcnt(int x){return __builtin_popcount(x);} int popcnt(long long x){return __builtin_popcount(x);} bool ingrid(int i,int j,int H,int W){ return 0<=i&&i<H&&0<=j&&j<W; } const int dx[]={1,0,-1,0}; const int dy[]={0,1,0,-1}; template<typename T> void print(vector<T> &v){for(int i=0;i<v.size();++i){if(i)cout<<" ";cout<<v[i];}cout<<endl;} template<typename T> void print(T* v,int size){for(int i=0;i<size;++i){if(i)cout<<" ";cout<<v[i];}cout<<endl;} template<typename T,typename S>void print(pair<T,S>&p){cout<<p.first<<" "<<p.second<<endl;} const ll LINF=4*1e18; const ll MINF=5*1e15; const int INF=1e9+5; const ld PI=acosl(-1); const ld DINF=INF; void Main(); int main(){cout<<fixed<<setprecision(15);Main();} void Main(){ int L,R;cin>>L>>R; vector<ll> table(1000001); ll ans=0; for(ll g=1000000;g>=2;--g){ table[g]=(ll)(R/g-(L-1)/g)*(R/g-(L-1)/g); for(ll h=2*g;h<=1000000;h+=g){ table[g]-=table[h]; } ans+=table[g]; } for(ll x=L;x<=R;++x){ ans-=(R/x-(L-1)/x)*2-1; } if(L==1)ans+=2*R-1; cout<<ans<<endl; }
#include<bits/stdc++.h> #define f(i,n) for(long long int i = 0 ; i < n; i++) #define F first #define S second #define vll vector<ll> #define vvll vector<vector<ll>> #define all(s) s.begin(), s.end() #define u_s unordered_set #define u_m unordered_map #define ll long long int #define pb push_back #define pll pair<ll,ll> #define parr(arr) for(auto x: arr)cout<<x<<" ";cout<<endl #define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0) #define testcase ll tt; cin>>tt; while(tt--) using namespace std; vector<vvll> dp; ll helper(vvll &v, ll i, ll j, ll took){ if(i == (ll)v.size() || took == 31) return 0; if(dp[i][j][took]!=-1) return dp[i][j][took]; ll rem = (~took) & 31; ll ans = 0; if(j == 2){ ll cnt = 0; ans = INT_MAX; while(rem){ if(rem&1) ans = min(ans,v[i][cnt]); rem >>= 1; cnt++; } return dp[i][j][took] = max(ans, helper(v,i+1,j,took)); } for(ll s = rem; s ; s=(s-1)&rem){ ll cnt = 0; ll mini = INT_MAX; ll tmp = s; while(tmp){ if(tmp&1) mini = min(mini, v[i][cnt]); cnt++; tmp>>=1; } ans = max(ans, min(mini,helper(v, i+1, j+1, took|s))); } ans = max(ans, helper(v, i+1, j, took)); return dp[i][j][took] = ans; } int main() { fast; ll n; cin>>n; vvll v(n, vll(5)); for(auto &x: v) for(auto &i: x) cin>>i; dp.resize(n, vvll(3, vll(32,-1))); cout<<helper(v, 0, 0, 0); return 0; }
#pragma region templates //#pragma GCC optimize("Ofast") //#pragma GCC optimize("unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using db = double; using ld = long double; template <typename T> using V = vector<T>; template <typename T> using VV = vector<vector<T>>; template <typename T> using PQ = priority_queue<T>; #define fs first #define sc second #define pb push_back #define mp make_pair #define mt make_tuple #define eb emplace_back #define lb(c, x) distance((c).begin(), lower_bound(all(c), (x))) #define ub(c, x) distance((c).begin(), upper_bound(all(c), (x))) #define all(v) (v).begin(), (v).end() #define siz(v) (ll)(v).size() #define rep(i, a, n) for(ll i = a; i < (ll)(n); ++i) #define repr(i, a, n) for(ll i = n - 1; (ll)a <= i; --i) #define ENDL '\n' typedef pair<int, int> Pi; typedef pair<ll, ll> PL; constexpr ll mod = 1000000007; // 998244353; constexpr ll INF = 1000000099; constexpr ll LINF = (ll)(1e18 + 99); const ld PI = acos((ld)-1); constexpr ll dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1}; template <typename T, typename U> inline bool chmin(T& t, const U& u) { if(t > u) { t = u; return 1; } return 0; } template <typename T, typename U> inline bool chmax(T& t, const U& u) { if(t < u) { t = u; return 1; } return 0; } template <typename T> inline T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } inline void Yes() { cout << "Yes" << ENDL; } inline void No() { cout << "No" << ENDL; } inline void YES() { cout << "YES" << ENDL; } inline void NO() { cout << "NO" << ENDL; } template <typename T, typename Y> inline T mpow(T a, Y n) { T res = 1; for(; n; n >>= 1) { if(n & 1) res = res * a; a = a * a; } return res; } template <typename T> vector<T> finddivisor(T x) { //整数xの約数(xを含む) vector<T> divisor; for(T i = 1; (i * i) <= x; i++) { if(x % i == 0) { divisor.push_back(i); if(i * i != x) { divisor.push_back(x / i); } } } sort(divisor.begin(), divisor.end()); return divisor; } template <typename T> V<T> prefix_sum(const V<T>& v) { int n = v.size(); V<T> ret(n + 1); rep(i, 0, n) ret[i + 1] = ret[i] + v[i]; return ret; } template <typename T> T rand(T l, T r) { static random_device rd; static mt19937 g(rd()); return uniform_int_distribution<T>(l, r)(g); } template <typename T> istream& operator>>(istream& is, vector<T>& vec) { for(auto&& x : vec) is >> x; return is; } template <typename T, typename Y> ostream& operator<<(ostream& os, const pair<T, Y>& p) { return os << "{" << p.fs << "," << p.sc << "}"; } template <typename T> ostream& operator<<(ostream& os, const V<T>& v) { os << "{"; for(auto e : v) os << e << ","; return os << "}"; } template <typename... Args> void debug(Args&... args) { for(auto const& x : {args...}) { cerr << x << ' '; } cerr << ENDL; } #pragma endregion templates signed main() { cin.tie(0); cerr.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); ll n; cin >> n; VV<ll> v(n, V<ll>(5)); cin >> v; ll ok = 0, ng = INF, md; while(abs(ok - ng) > 1) { md = (ok + ng) / 2; V<ll> a(n), dp(1 << 5, 0); rep(i, 0, n) { ll bit = 0; rep(j, 0, 5) { bit *= 2; if(v[i][j] >= md) bit++; } a[i] = bit; dp[bit]++; } repr(bit, 0, (1 << 5)) { rep(d, 0, 5) if(bit & (1 << d)) { dp[bit ^ (1 << d)] += dp[bit]; } } rep(i, 0, n) { rep(j, i + 1, n) { ll now = (a[i] | a[j]), need = 0; rep(k, 0, 5) if(!(now & (1 << k))) need += (1 << k); if(dp[need]) { ok = md; goto f; } } } ng = md; f:; } cout << ok << ENDL; } //(・_・)(・_・)(・_・)(・_・) //CHECK overflow,what to output? //any other simpler approach?
#include <bits/stdc++.h> using namespace std; using ll=long long; #define P pair<int,int> #define fi first #define se second #define rep(i,n) for(int i=0;i<n;i++) #define all(v) v.begin(),v.end() #define pb push_back template<class T,class U> inline bool chmax(T &a,U b){ if(a<b){ a=b; return true; } return false; } template<class T,class U> inline bool chmin(T &a,U b){ if(a>b){ a=b; return true; } return false; } constexpr int INF=1000000000; constexpr ll llINF=1000000000000000000; constexpr int mod=1000000007; constexpr double eps=1e-8; const double pi=acos(-1); int dx[]={0,1,0,-1},dy[]={1,0,-1,0}; int Random(int mi,int ma){ random_device rnd; mt19937 mt(rnd());//32bit //[mi,ma] uniform_int_distribution<int>engine(mi,ma); return engine(mt); } /* vector<vector<ll>>C,sC; void init_comb(int n,int m){ C.resize(n+1,vector<ll>(m+1,0)); sC.resize(n+1,vector<ll>(m+1,0)); C[0][0]=1; for(int i=1;i<=n;i++){ C[i][0]=1; for(int j=1;j<=m;j++){ C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod; } } rep(i,n+1){ rep(j,m){ sC[i][j+1]=(sC[i][j]+C[i][j])%mod; } } }*/ ll gcd(ll a,ll b){ while(a%b){ a%=b; swap(a,b); } return b; } ll lcm(ll a,ll b){ return a/gcd(a,b)*b; } bool prime(int a){ if(a==1)return false; for(int i=2;i*i<=a;i++){ if(a%i==0)return false; } return true; } vector<int>primes; void init_prime(int n){ primes.push_back(2); for(int i=3;i<=n;i+=2){ bool f=true; for(int j:primes){ if(j*j>i)break; if(i%j==0){ f=false; break; } } if(f)primes.push_back(i); } } ll modpow(ll a,ll b){ ll res=1; while(b){ if(b&1){ res*=a; res%=mod; } a*=a; a%=mod; b>>=1; } return res; } vector<ll>inv,fact,factinv; void init_fact(int n){ inv.resize(n+1); fact.resize(n+1); factinv.resize(n+1); inv[0]=0; inv[1]=1; fact[0]=1; factinv[0]=1; for(ll i=1;i<=n;i++){ if(i>=2)inv[i]=mod-((mod/i)*inv[mod%i]%mod); fact[i]=(fact[i-1]*i)%mod; factinv[i]=factinv[i-1]*inv[i]%mod; } } ll _inv(ll a,ll m=mod){ //gcd(a,m) must be 1 ll b=m,u=1,v=0; while(b){ ll t=a/b; a-=t*b;swap(a,b); u-=t*v;swap(u,v); } u%=m; if(u<0)u+=m; return u; } ll comb(int a,int b){ if(a<b)return 0; if(a<0)return 0; return fact[a]*factinv[a-b]%mod*factinv[b]%mod; } ll multicomb(int a,int b){ return comb(a+b-1,b); } int n,c[100010],cnt[100010]; vector<int>g[100010]; vector<int>ans; void dfs(int x,int p=-1){ cnt[c[x]]++; if(cnt[c[x]]==1)ans.pb(x); for(int i:g[x]){ if(i!=p){ dfs(i,x); } } cnt[c[x]]--; } int main(){ cin.tie(0);ios::sync_with_stdio(false); cin>>n; rep(i,n)cin>>c[i]; rep(i,n-1){ int a,b; cin>>a>>b; a--,b--; g[a].pb(b); g[b].pb(a); } dfs(0); sort(all(ans)); for(int i:ans)cout<<i+1<<endl; return 0; }
#include "bits/stdc++.h" using namespace std; #define FAST ios_base::sync_with_stdio(false); cin.tie(0); #define pb push_back #define eb emplace_back #define ins insert #define f first #define s second #define cbr cerr<<"hi\n" #define mmst(x, v) memset((x), v, sizeof ((x))) #define siz(x) ll(x.size()) #define all(x) (x).begin(), (x).end() #define lbd(x,y) (lower_bound(all(x),y)-x.begin()) #define ubd(x,y) (upper_bound(all(x),y)-x.begin()) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); inline long long rand(long long x, long long y) { return rng() % (y+1-x) + x; } //inclusive string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); } using ll=long long; using ld=long double; #define FOR(i,s,e) for(ll i=s;i<=ll(e);++i) #define DEC(i,s,e) for(ll i=s;i>=ll(e);--i) using pi=pair<ll,ll>; using spi=pair<ll,pi>; using dpi=pair<pi,pi>; long long LLINF = 1e18; int INF = 1e9+1e6; #define MAXN (200006) ll n, m, mod=998244353, dp[20][MAXN], f[MAXN], inv[MAXN]; ll qexp(ll x,ll e){ ll sum=1; for(;e;e>>=1,x*=x,x%=mod) if(e&1) sum*=x, sum%=mod; return sum; } ll C(ll n,ll k) { return n < k ? 0ll : f[n] * inv[k] % mod * inv[n-k] % mod; } vector<int> d[MAXN]; int main() { f[0]=1; FOR(i,1,MAXN-1) f[i]=f[i-1]*i%mod; inv[MAXN-1] = qexp(f[MAXN-1], mod-2); DEC(i,MAXN-2,0) inv[i]=inv[i+1]*(i+1)%mod; FAST cin>>n>>m; FOR(j,1,m) { for(ll k=2;k*k<=j;++k) if(j%k==0) { d[j].eb(k); if(j/k!=k) d[j].eb(j/k); } } FOR(i,1,m) dp[1][i] = 1; FOR(i,2,min(n, 19ll)) { FOR(j,1,m) { for(auto k:d[j]) { dp[i][j] += dp[i-1][k]; if(dp[i][j] >= mod) dp[i][j] -= mod; } if(j != 1 && i == 2) { dp[i][j] += dp[i-1][1]; if(dp[i][j] >= mod) dp[i][j] -= mod; } } } ll ans = 0; FOR(i,1,min(n,19ll)) FOR(j,1,m) { ans += dp[i][j] * C(n-1, i-1) % mod; if(ans >= mod) ans -= mod; } cout<<ans<<'\n'; }
#include <bits/stdc++.h> #define SIZE 1005 using namespace std; typedef long long int ll; typedef pair <int,int> P; int main() { int n; scanf("%d",&n); int t=1; while(t<n) t<<=1; for(int i=0;i<n;i++) { int a=i*2; int b=i*2+1; for(int j=11;j>=0;j--) { if(a>=n&&(a>>j&1)) a^=1<<j; if(b>=n&&(b>>j&1)) b^=1<<j; } printf("%d %d\n",a+1,b+1); } }
#include <bits/stdc++.h> #define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); typedef long long ll; typedef long double ld; #define pb push_back #define mp make_pair #define ff first #define ss second #define pii pair<ll,ll> #define inf 1000000000000000000 #define bpc(x) __builtin_popcountll(x) #define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++) #define autoitr(x,it) for(auto it = x.rbegin(); it != x.rend(); it++) #define rep(n) for(ll i = 0; i < n; i++) #define repi(i,n) for(ll i = 0; i < n; i++) #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> using namespace std; mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count()); const ll N = 20; long long GCD(long long a, long long b) { return (b == 0) ? a : GCD(b, a % b); } inline long long LCM(long long a, long long b) { return a / GCD(a, b) * b; } inline long long normalize(long long x, long long mod) { x %= mod; if (x < 0) x += mod; return x; } struct GCD_type { long long x, y, d; }; GCD_type ex_GCD(long long a, long long b) { if (b == 0) return {1, 0, a}; GCD_type pom = ex_GCD(b, a % b); return {pom.y, pom.x - a / b * pom.y, pom.d}; } ll testCases; ll fun(ll t, ll a[], ll n[]) { ll lcm, ans; for(ll i=1;i<=t;i++) normalize(a[i], n[i]); ans = a[1]; lcm = n[1]; for(ll i = 2; i <= t; i++) { auto pom = ex_GCD(lcm, n[i]); ll x1 = pom.x; ll d = pom.d; if((a[i] - ans) % d != 0) return LLONG_MAX; ans = normalize(ans + x1 * (a[i] - ans) / d % (n[i] / d) * lcm, lcm * n[i] / d); lcm = LCM(lcm, n[i]); // you can save time by replacing above lcm * n[i] /d by lcm = lcm * n[i] / d } return ans; } int main() { FAST/**/ ll t; cin>>t; while(t--) { ll x,y,p,q; cin>>x>>y>>p>>q; ll ans = LLONG_MAX; for(ll r1=p;r1<=p+q-1;r1++) for(ll r2=x;r2<=x+y-1;r2++) { ll r[3], m[3]; r[1] = r1, m[1] = p+q; r[2] = r2, m[2] = 2*(x+y); ll temp = __gcd(m[1], m[2]); if(abs(r1-r2)%temp != 0) continue; ans = min(ans, fun(2, r, m)); } if(ans != LLONG_MAX) cout<<ans<<'\n'; else cout<<"infinity\n"; } return 0; }
#include <bits/stdc++.h> #define int long double using namespace std; int n; int ans; signed main(){ cin>>n; for(int i=2;i<=n;i++){ ans+=n*1.0/(n-i+1); } cout<<fixed<<setprecision(10)<<ans<<endl; return 0; }
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <sstream> #include <queue> #include <deque> #include <bitset> #include <iterator> #include <list> #include <stack> #include <map> #include <set> #include <functional> #include <numeric> #include <utility> #include <limits> #include <time.h> #include <math.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <assert.h> #include <unordered_map> #include <unordered_set> #include <bits/stdc++.h> using namespace std; using rr = long long; using O = pair<int, int>; #define rep(dsfgt, polkmnjh) for (int dsfgt = 0; dsfgt < (polkmnjh); dsfgt++) int main() { rr polkmnjh, satybnh = 0, dfgv = 1; cin >> polkmnjh; while (1) { string hikaku = to_string(dfgv) + to_string(dfgv); if (stoll(hikaku) <= polkmnjh) { satybnh++; dfgv++; } else { break; } } cout << satybnh << endl; 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() 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; const ll d = 16; ll dp[220000][2][17]; ll to_num(char c) { ll x = c - '0'; if (0<=x && x<10) return x; ll y = c - 'A'; return 10 + y; } ll bitcnt(ll bit) { ll res = 0; rep(i,d) if ((bit>>i)&1) res++; return res; } void addmodp(ll &x, ll y) {x = (x + y) % mod;} int main() { string str; cin >> str; ll N = str.size(); ll K; cin >> K; vector<ll> S(N); rep(i,N) S[i] = to_num(str[i]); ll bit = 1<<S[0]; dp[0][0][1] = 1LL; dp[0][1][1] = S[0] - 1; for (ll i=1; i<N; i++) { ll from = bitcnt(bit); bit |= 1<<S[i]; ll now = bitcnt(bit); dp[i][0][now] = 1; for (ll j=1; j<=d; j++) { addmodp(dp[i][1][j], dp[i-1][1][j] * j % mod); addmodp(dp[i][1][j], dp[i-1][1][j-1] * (d-j+1) % mod); } rep(j,S[i]) { if ((bit>>j)&1) addmodp(dp[i][1][from],1LL); else addmodp(dp[i][1][from+1],1LL); } addmodp(dp[i][1][1],15); } ll ans = 0LL; rep(i,2) addmodp(ans,dp[N-1][i][K]); Cout(ans); }
#include<bits/stdc++.h> using namespace std; const int N = 2e5 + 7; typedef long long ll; const ll mod = 1e9 + 7; string s; int k, a[N], n; int work(int x) { int ans = 0; while (x) { if (x & 1) ans++; x = x / 2; } return ans; } ll dp[N][20]; ll dfs(int p, int stat, int limit) { int cnt = work(stat); // cout << p << " " << cnt << " " << stat << endl; if (cnt > k) return 0; if (p == n) { if (cnt == k) return 1; return 0; } if (!limit && dp[p][cnt] != -1) return dp[p][cnt]; int maxn = 15; if (limit) { maxn = a[p]; } ll ans = 0; for (int i = 0; i <= maxn; i++) { ans += dfs(p + 1, stat | (1 << i), limit && i == maxn); ans = ans % mod; } if (!limit) dp[p][cnt] = ans; return ans; } void solve() { ll ans = 0; memset(dp, -1, sizeof(dp)); for (int i = 0; i < n; i++) { int maxn = 15; if (i == 0) { maxn = a[0]; } // cout << "Maxn " << maxn << endl; for (int j = 1; j <= maxn; j++) { ans += dfs(i + 1, (1 << j), i == 0 && j == maxn); ans = ans % mod; } } cout << ans << endl; } int main() { cin >> s >> k; n = s.length(); for (int i = 0; i < s.length(); i++) { if (s[i] >= '0' && s[i] <= '9') { a[i] = s[i] - '0'; } else { a[i] = s[i] - 'A' + 10; } } solve(); }
#include<bits/stdc++.h> using namespace std; #define Set(a,b) memset(a,b,sizeof(a)) template<class T>inline void init(T&x){ x=0;char ch=getchar();bool f=0; for(;ch>'9'||ch<'0';ch=getchar()) if(ch=='-') f=1; for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+(ch-48); if(f) x=-x; return; } typedef long long ll; typedef double db; const int mod=998244353,G=3,phi=998244352; int n; const int N=5e5+10; char s[N],t[N]; int main(){ init(n); scanf("%s",s+1); scanf("%s",t+1); int h1=1,h2=1; int cnt=0; bool fl=0; while(h1<=n||h2<=n) { while(h1<=n&&s[h1]!='0') ++h1; while(h2<=n&&t[h2]!='0') ++h2; if(h1<=n&&h2<=n) { if(h1!=h2) ++cnt; ++h1,++h2; }else if(h1>n&&h2>n); else {fl=1;break;} } if(fl) puts("-1"); else printf("%d\n",cnt); return 0; }
#include <bits/stdc++.h> using namespace std; #define closeSync ios::sync_with_stdio(false);cin.tie(0);cout.tie(0) const int MAXN = 300005; typedef long long ll; typedef pair<int,int> pii; const int INF = 0x3f3f3f3f; vector<int> v[2]; inline void solve() { int n; cin >> n; string S,T; cin >> S >> T; S = " " + S,T = " " + T; for (int i=1;i<=n;i++) if (S[i] == '0') v[0].push_back(i); for (int i=1;i<=n;i++) if (T[i] == '0') v[1].push_back(i); if (v[0].size() != v[1].size()) cout << "-1\n"; else { int ed = v[0].size() - 1; int cnt = 0; for (int i=0;i<=ed;i++) if (v[0][i] != v[1][i]) cnt++; cout << cnt << "\n"; } return ; } int main() {closeSync; solve(); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; // -------------------------------------------------------- template <class T> bool chmax(T& a, const T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T& a, const T b) { if (b < a) { a = b; return 1; } return 0; } #define FOR(i, l, r) for (int i = (l); i < (r); ++i) #define RFOR(i, l, r) for (int i = (r)-1; (l) <= i; --i) #define REP(i, n) FOR(i, 0, n) #define RREP(i, n) RFOR(i, 0, n) #define ALL(c) (c).begin(), (c).end() #define RALL(c) (c).rbegin(), (c).rend() #define SORT(c) sort(ALL(c)) #define RSORT(c) sort(RALL(c)) #define MIN(c) *min_element(ALL(c)) #define MAX(c) *max_element(ALL(c)) #define SUM(c) accumulate(ALL(c), 0) #define SUMLL(c) accumulate(ALL(c), 0LL) #define SZ(c) ((int)(c).size()) #define CIN(c) cin >> (c) #define COUT(c) cout << (c) << '\n' #define debug(x) cerr << #x << " = " << (x) << '\n'; using P = pair<ll, ll>; using VP = vector<P>; using VVP = vector<VP>; using VS = vector<string>; using VI = vector<int>; using VVI = vector<VI>; using VLL = vector<ll>; using VVLL = vector<VLL>; using VB = vector<bool>; using VVB = vector<VB>; using VD = vector<double>; using VVD = vector<VD>; static const double EPS = 1e-10; static const double PI = acos(-1.0); static const ll MOD = 1000000007; // static const ll MOD = 998244353; static const int INF = (1 << 30) - 1; // 1073741824 - 1 // static const ll INF = (1LL << 60) - 1; // 4611686018427387904 - 1 const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } int main() { cin.tie(0); ios::sync_with_stdio(false); int n, w; cin >> n >> w; COUT(n / w); }
#include <bits/stdc++.h> using namespace std; int main() { int64_t N, K; cin >> N >> K; if(K < 0) K = -K; int64_t X, Y; int64_t countx, county; int64_t count = 0; for(int i = 2 * N - K - 1; i > 0; i--) { X = 2 * N - (2 * N - K - 1 - i); Y = X - K; if(N < X - 1) countx = X - 1 - (2 * (X - 1) - 2 * N); else countx = X - 1; if(N < Y - 1) county = Y - 1 - (2 * (Y - 1) - 2 * N); else county = Y - 1; count += countx * county; } cout << count << endl; }
#include<bits/stdc++.h> using namespace std; #define fast {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);} typedef long long int ll; typedef string S; #define M 1e18 #define AS 250005 #define sp cout<<' ' #define nw cout<<endl #define rt return #define __ template<typename T, typename... Types> void in() {rt;} __ void in(T &a, Types&... b){cin>>(a); in(b...);} void o() {rt;} __ void o(T a, Types... b){cout<<(a);sp; o(b...);} #define fr(i,a,n) for(ll i=a;i<=n;i++) #define frm(i,a,n) for(ll i=n;i>=a;i--) #define P pair<ll,ll> #define vc vector<ll> #define pb push_back #define MP map<ll,ll> bool sortin(const pair<ll,ll> &e,const pair<ll,ll> &f){return (e.first<f.first);} bool POT(ll x){return x && (!(x&(x-1)));} ll i,j,k,l,m,n,p,q,r,a,b,c,x,y,z,ts,mn=1e18,mod=1e9+7; ll ar[AS],br[AS],xr[AS],tem[AS]; int main() { fast; in(n); fr(i,0,n-1)in(ar[i]); partial_sum(ar,ar+n,br); fr(i,0,n-1) { m=max(m,c+x); c+=br[i]; x=max(x,br[i]); m=max(m,c); } o(m); }
#include<bits/stdc++.h> using namespace std; #define rep(i, a, b) for(int i = (a); i < (b); ++i) #define trav(a, x) for(auto& a : x) #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define sz(x) ((int)(x).size()) #define endl '\n' typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef vector<int> vi; typedef vector<ll> vll; const ll mod = 1000000007; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // head int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vll psum(n); for(int i = 0; i < n; i++) { ll x; cin >> x; if(i > 0) psum[i] = x + psum[i - 1]; else psum[i] = x; } ll a = 0; ll curr = 0; ll pospref = 0; for(int i = 0; i < n; i++) { pospref = max(pospref, psum[i]); if(curr + pospref > a) a = curr + pospref; curr += psum[i]; } cout << a << endl; return 0; }
#pragma GCC target("avx2") #pragma GCC optimize("03") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; using ld = long double; using ll = long long; using ull = unsigned long long; #define endl "\n" #define FOR(i,a,b) for(int i=(a);i<=(b);i++) #define rep(i,n) for(int i=0;i<(n);i++) #define PII pair<int, int> #define PLL pair<ll, ll> #define ALL(x) (x).begin(), (x).end() #define QUERY int num_query;cin>>num_query; while(num_query--) int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; constexpr int INF=1<<30; constexpr ll LINF=1LL<<60; constexpr ll mod=1e9+7; void flush() {cout<<flush;} template<class T>vector<T> vec(int len, T elem) { return vector<T>(len, elem); } // auto dp = vec(52, vec(103, vec(103, INF))); template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; } template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; } template<class T>inline int popcount(T a) {return __builtin_popcountll(a);} template<class T>inline T emod(T a, T p) { return (a%p + p) % p;} template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa) { os << '(' << pa.first << ',' << pa.second << ')'; return os; } template <typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp) { os << '{'; for (auto v : mp) os << v.first << "=>" << v.second << ','; os << '}'; return os; } template <typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp) { os << '{'; for (auto v : mp) os << v.first << "=>" << v.second << ','; os << '}'; return os; } 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) {os << '\n'; for (auto v : vec) os << v << ' '; os << '\n'; return os;} template <typename T> ostream &operator<<(ostream &os, const deque<T> &vec) { os << "deq["; for (auto v : vec) os << v << ','; os << ']'; return os; } template <typename T> ostream &operator<<(ostream &os, const set<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; } template <typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; } template <typename T> ostream &operator<<(ostream &os, const multiset<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; } template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec) { os << '{'; for (auto v : vec) os << v << ','; os << '}'; return os; } struct MyIO { MyIO(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } IO_OI; #ifdef LOCAL void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...); } #define debug(...) \ cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl #else #define debug(...) (void(0)) #define dump(x) (void(0)) #endif //------------------- int main() { int a,b;cin>>a>>b; cout << (a+b)/2 << " " << (a-b)/2 << endl; }
#include <bits/stdc++.h> #define rep(i, n) for(int i = 0; i < (n); i++) using namespace std; using ll = long long; using P = pair<int, int>; int main() { int a, b; cin >> a >> b; int x = (a + b) / 2; int y = (a - b) / 2; cout << x << " " << y << endl; return 0; }
#include<bits/stdc++.h> using namespace std; int a, b, c, d, minim, maxim; int main(){ cin >> a >> b >> c >> d; minim = min(min(min(a , b), c), d); maxim = max(max(max(a , b), c), d); if((minim + maxim == a + b + c + d - minim - maxim) || (maxim == a + b + c + d - maxim)) cout << "Yes"; else cout << "No"; return 0; }
/** * Author: Daniel * Created Time: 2021-02-25 22:16:47 **/ #include <bits/stdc++.h> using namespace std; #define F first #define S second #define ER erase #define IS insert #define PI acos(-1) #define PB pop_back #define EB emplace_back #define lowbit(x) (x & -x) #define SZ(x) ((int)x.size()) #define MP(x, y) make_pair(x, y) #define ALL(x) x.begin(), x.end() #define RALL(x) x.rbegin(), x.rend() #define SOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<fixed<<setprecision(10) typedef long long LL; typedef vector<LL> VL; typedef vector<int> VI; typedef pair<int, int> PII; typedef unsigned long long ULL; template <typename A> using VE = vector<A>; template <typename A> using USET = unordered_set<A>; template <typename A> using HEAP = priority_queue<A>; template <typename A, typename B> using PA = pair<A, B>; template <typename A, typename B> using UMAP = unordered_map<A, B>; template <typename A> using RHEAP = priority_queue<A, vector<A>, greater<A> >; /////////////////////////////////////////////////////////////////////////// //////////////////// DO NOT TOUCH BEFORE THIS LINE //////////////////////// /////////////////////////////////////////////////////////////////////////// // check the limitation!!! const int N = 100010, M = 1010; int a[4]; // read the question carefully!!! int main() { SOS; int tot = 0; for (int i = 0; i < 4; i ++ ) { cin >> a[i]; tot += a[i]; } sort(a, a + 4); do { int t = tot; int sum = 0; for (int i = 0; i < 4; i ++ ) { sum += a[i]; tot -= a[i]; if (sum == tot) { cout << "Yes\n"; return 0; } } tot = t; } while (next_permutation(a, a + 4)); cout << "No\n"; return 0; } // GOOD LUCK!!!
#define ll long long #define dd long double #define pub push_back #define pob pop_back #define puf push_front #define pof pop_front #define mp make_pair #define mt make_tuple #define fo(i , n) for(ll i = 0 ; i < n ; i++) #define tll tuple<ll ,ll , ll > #define pll pair<int ,int> #include<bits/stdc++.h> /*#include<iomanip> #include<cmath> #include<cstdio> #include<utility> #include<iostream> #include<vector> #include<string> #include<algorithm> #include<map> #include<queue> #include<set> #include<stack> #include<bitset>*/ dd pi = acos(-1) ; ll z = 1000000007 ; ll inf = 10000; ll p1 = 37 ; ll p2 = 53 ; ll mod1 = 202976689 ; ll mod2 = 203034253 ; ll fact[100] ; ll gdp(ll a , ll b){return (a - (a%b)) ;} ll ld(ll a , ll b){if(a < 0) return -1*gdp(abs(a) , b) ; if(a%b == 0) return a ; return (a + (b - a%b)) ;} // least number >=a divisible by b ll gd(ll a , ll b){if(a < 0) return(-1 * ld(abs(a) , b)) ; return (a - (a%b)) ;} // greatest number <= a divisible by b ll gcd(ll a , ll b){ if(b > a) return gcd(b , a) ; if(b == 0) return a ; return gcd(b , a%b) ;} ll e_gcd(ll a , ll b , ll &x , ll &y){ if(b > a) return e_gcd(b , a , y , x) ; if(b == 0){x = 1 ; y = 0 ; return a ;} ll x1 , y1 ; e_gcd(b , a%b , x1 , y1) ; x = y1 ; y = (x1 - ((a/b) * y1)) ; return e_gcd(b , a%b , x1 , y1) ;} ll power(ll a ,ll b , ll p){if(b == 0) return 1 ; ll c = power(a , b/2 , p) ; if(b%2 == 0) return ((c*c)%p) ; else return ((((c*c)%p)*a)%p) ;} ll inverse(ll a ,ll n){return power(a , n-2 , n) ;} ll max(ll a , ll b){if(a > b) return a ; return b ;} ll min(ll a , ll b){if(a < b) return a ; return b ;} ll left(ll i){return ((2*i)+1) ;} ll right(ll i){return ((2*i) + 2) ;} ll ncr(ll n , ll r){if(n < r|| (n < 0) || (r < 0)) return 0 ; return ((((fact[n] * inverse(fact[r] , z)) % z) * inverse(fact[n-r] , z)) % z);} void swap(ll&a , ll&b){ll c = a ; a = b ; b = c ; return ;} //ios_base::sync_with_stdio(0); //cin.tie(0); cout.tie(0); using namespace std ; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> // ordered_set s ; s.order_of_key(val) no. of elements strictly less than val // s.find_by_order(i) itertor to ith element (0 indexed) //__builtin_popcount(n) -> returns number of set bits in n ll seed; mt19937 rnd(seed=chrono::steady_clock::now().time_since_epoch().count()); // include bits void solve() { ll n ; cin >> n ; ll arr[n+1] , ans = 1 ; arr[0] = 0 ; fo(i , n) { cin >> arr[i+1] ; } sort(arr , arr+n+1) ; for(ll i = 1 ; i <= n ; i++) { ans *= (arr[i] - arr[i-1] + 1) ; ans %= z ; } cout << ans << '\n' ; return ; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); /*#ifndef ONLINE_JUDGE freopen("inputf.txt" , "r" , stdin) ; freopen("outputf.txt" , "w" , stdout) ; freopen("error.txt" , "w" , stderr) ; #endif*/ ll t ; //cin >> t ; t = 1 ; //cout << arr[12] << ' ' << arr[32] << endl ; while(t--) { solve() ; } // cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN = 1e5 + 5; const ll mod = 1e9 + 7; int n; ll a[MAXN]; int main() { scanf("%d", &n); for(int i = 1; i <= n; i++) scanf("%lld", &a[i]); sort(a + 1, a + 1 + n); ll ans = 1; for(int i = 1; i <= n; i++) ans = ans *(a[i] - a[i - 1] + 1) % mod; printf("%lld", ans); return 0; }
#include <iostream> #include <vector> #include <algorithm> #include <set> #include <stdio.h> #include <cmath> #include <iomanip> using namespace std; int main(){ int n; cin >> n; vector<long long> a(n), b(n), c(n); for(int i = 0;i < n;i++) cin >> a[i]; for(int i = 0;i < n;i++) cin >> b[i]; for(int i = 0;i < n;i++){ cin >> c[i]; c[i]--; } long long bas[100001] = {0}; for(int i = 0;i < n;i++) bas[a[i]]++; long long cnt = 0; for(int i = 0;i < n;i++) cnt += bas[b[c[i]]]; cout << cnt << endl; }
// jay swaminarayan // // UTSAV VASOYA // #include <iostream> #include<algorithm> #include<map> #include<vector> #include<set> #include<cmath> #include<string.h> using namespace std; #define int long long #define pi (3.141592653589) #define float double #define pb push_back #define mp make_pair #define ff first #define ss second #define all(c) c.begin(), c.end() #define min3(a, b, c) min(c, min(a, b)) #define min4(a, b, c, d) min(d, min(c, min(a, b))) #define rrep(i, n) for(int i=n-1;i>=0;i--) #define rep(i,n) for(int i=0;i<n;i++) // All func int fastpower(long a,long b,int n=1000000007){ long res=1; while(b>0){ if((b&1)!=0){ res = (res%n * a%n)%n ;} a = (a%n * a%n)%n; b=b>>1;} return res;} int checkPrime(int n) { bool prime[n+1]; memset(prime, true, sizeof(prime)); for(int p=2; p*p<=n; p++) { if (prime[p] == true) { for (int i=p*p; i<=n; i += p) prime[i] = false; } } int cprime=0; for(int p=2; p<=n; p++) if(prime[p]) cprime++; return cprime;} int gcd(int a, int b){ int c = a % b; while(c != 0) { a = b; b = c; c = a % b; } return b;} #define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); int32_t main(){ fast // just chill chill just chill int n; cin >> n; int a[n],b[n],c[n]; rep(i,n) cin >>a[i]; rep(i,n) cin >> b[i]; rep(i,n) cin >> c[i]; map<int,int>mp1; map<int,int>mp2; vector<int>v; rep(i,n){ mp1[a[i]]++; mp2[b[i]]++; v.push_back(b[i]); } int ans=0; for(int i=0; i<n; i++){ int m = b[c[i]-1]; int p = mp1[m]; int count = p; ans+=count; // mp1[m]=0; // mp2[m]=0; } cout << ans; return 0; }
#include<bits/stdc++.h> using namespace std; typedef unsigned long long int ull; typedef long long int ll; typedef pair<ll,ll> pll; typedef long double D; //typedef complex<D> P; #define F first #define S second const ll MOD=1000000007; //const ll MOD=998244353; template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;} template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;} template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;} template<typename T>ostream & operator << (ostream &o,const vector<T> &A){int i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;} template<typename T,typename U>T & chmax(T &a,const U &b){if(a<b){a=b;} return a;} template<typename T,typename U>T & chmin(T &a,const U &b){if(b<a){a=b;} return a;} int main(){ cin.tie(0); ios::sync_with_stdio(false); ll H,W; cin>>H>>W; vector<vector<ll>> A(H,vector<ll>(W)); cin>>A; ll mi=1e9; for(auto &I:A){for(auto &J:I){chmin(mi,J);}} ll sum=0; for(auto &I:A){for(auto &J:I){sum+=J-mi;}} cout<<sum<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; // #include <atcoder/all> // using namespace atcoder; using ll =long long; typedef pair<int,int> P; #define SORT(a) sort((a).begin(),(a).end()) #define REV(a) reverse((a).begin(),(a).end()) #define For(i, a, b) for(int i = (a) ; i < (b) ; ++i) #define rep(i, n) For(i, 0, n) #define debug(x) cerr << #x << " = " << (x) << endl; template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } void coY() {cout <<"Yes"<<endl;} void coN(){cout <<"No"<<endl;} const int dy[] = {0,0,1,-1}; const int dx[] = {1,-1,0,0}; const ll mod = 1e9+7; const ll MOD = 998244353; const double PI=3.14159265358979323846; const int INF = 1001001001; //Write From this Line // now += mint(2).pow(s) - 1; こんな感じで、2のs乗を求められrう // auto mod int // https://youtu.be/L8grWxBlIZ4?t=9858 // https://youtu.be/ERZuLAxZffQ?t=4807 : optimize // https://youtu.be/8uowVvQ_-Mo?t=1329 : division struct mint { ll x; // typedef long long ll; mint(ll x=0):x((x%mod+mod)%mod){} mint operator-() const { return mint(-x);} mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { mint res(*this); return res+=a; } mint operator-(const mint a) const { mint res(*this); return res-=a; } mint operator*(const mint a) const { mint res(*this); return res*=a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod-2); } mint& operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res/=a; } }; istream& operator>>(istream& is, const mint& a) { return is >> a.x;} ostream& operator<<(ostream& os, const mint& a) { return os << a.x;} int main() { int n, m; cin >> n >> m; vector<int> a(n); rep(i,n) cin >> a[i]; ll sum = 0; rep(i,n){ sum += a[i]; } mint ans = 1; for(ll i = 0; i < sum+n; i++){ ans *= (m+n-i); ans /= (i+1); } cout << ans << endl; }