code_file1
stringlengths
87
4k
code_file2
stringlengths
85
4k
#include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG #define rep(i,n) for (int i = 0; i < (int)n ;i++) #define rept(i,k,n) for(int i = (int)(k);i < (int)(n);i++) #define all(vec) vec.begin(),vec.end() #define ll int64_t int main(){ int n; cin >> n; vector<vector<int> > c(n,vector<int>(n)); vector<int> a(n),b(n); int ma = 0,mb = 0; rep(i,n){ rep(j,n){ cin >> c[i][j]; } b[i] = c[0][i]-c[0][0]; a[i] = c[i][0]-c[0][0]; mb = min(mb,b[i]); ma = min(ma,a[i]); } rep(i,n){ rep(j,n){ if(c[i][j]-c[i][0] != b[j]){ cout << "No" << endl; return 0; } } } rep(i,n){ //cout << b[i] << endl; } cout << "Yes" << endl; if(ma < mb){ rep(i,n){ cout << a[i]-ma << " "; } cout << endl; rep(i,n){ cout << b[i]+c[0][0]+ma << " "; } } else{ rep(i,n){ cout << a[i]+mb+c[0][0] << " "; } cout << endl; rep(i,n){ cout << b[i]-mb << " "; } } }
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0; i < n; i++) #define Rep(i,n) for(int i = 1; i <= n; i++) #define sz(a) int(a.size()) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define fin(a) { cout << a << endl; return 0; } #define debug(a) { cerr << #a << ": " << a << endl; } #define endl '\n' #define fi first #define se second using lint = long long; using ld = long double; using P = pair<int,int>; using Pl = pair<lint,lint>; template<class T> using V = vector<T>; template<class T> using priq = priority_queue<T>; template<class T> using priq_inv = priority_queue<T, vector<T>, greater<T>>; const int dx[] = {0,1,0,-1,1,1,-1,-1}; const int dy[] = {1,0,-1,0,1,-1,-1,1}; template<class T> T ceil(const T &a, const T &b) { return ((a)+(b)-1)/b; } template<class T> bool chmin(T &a, T b) { if(a > b) { a = b; return 1; } return 0; } template<class T> bool chmax(T &a, T b) { if(a < b) { a = b; return 1; } return 0; } template<class T> void YesorNo(T x) { printf(x ? "Yes\n" : "No\n"); } struct INF { template<class T> operator T() { return numeric_limits<T>::max() / 2; } } INF; template<class T, class U> istream& operator>>(istream &in, pair<T,U> &p) { return in >> p.first >> p.second; } template<class T, class U> ostream& operator<<(ostream &out, const pair<T,U> &p) { return out << '{' << p.first << ',' << p.second << '}'; } template<class T> istream& operator>>(istream &in, vector<T> &v) { for(auto &&e : v) in >> e; return in; } template<class T> ostream& operator<<(ostream &out, const vector<T> &v) { for(const auto &e : v) out << e << ' '; return out; } /*----------------------------------------------------------------------------------------------------*/ int main(){ int n; cin >> n; V<V<int>> c(n,V<int>(n)); cin >> c; bool ok = true; rep(i,n)rep(j,n-1) { ok &= (c[i][j+1]-c[i][j] == c[0][j+1]-c[0][j]); } rep(j,n)rep(i,n-1) { ok &= (c[i+1][j]-c[i][j] == c[i+1][0]-c[i][0]); } if(!ok) fin("No"); V<int> d(n-1); Rep(i,n-1) d[i-1] = c[0][i]-c[0][i-1]; int l = -1, r = INF; while(r-l > 1) { int mid = (l+r)/2; int now = mid; bool ok = true; rep(i,n-1) { now += d[i]; if(now < 0) ok = false; } if(ok) r = mid; else l = mid; } V<int> b(n); b[0] = r; rep(i,n-1) b[i+1] = b[i] + d[i]; V<int> a(n); rep(i,n) { a[i] = c[i][0]-b[0]; if(a[i] < 0) fin("No"); } cout << "Yes" << endl; cout << a << endl << b << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (ll i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<ll, ll>; const ll INF = 2e18; int main() { ll n; cin >> n; vector<vector<ll>> c(n, vector<ll>(n)); rep(i, n) rep(j, n) cin >> c[i][j]; bool f = 1; rep(j, n - 1) { ll t = c[0][j] - c[0][j + 1]; rep(i, n) { if (c[i][j] - c[i][j + 1] != t) { f = 0; break; } } } if (f) { cout << "Yes" << endl; vector<ll> mn(n, INF); rep(j, n) rep(i, n) mn[j] = min(mn[j], c[j][i]); rep(i, n) cout << mn[i] << ' '; cout << endl; rep(i, n) cout << c[0][i] - mn[0] << ' '; cout << endl; } else { cout << "No" << endl; } return 0; }
#include <bits/stdc++.h> #define MOD 1000000007LL using namespace std; typedef long long ll; typedef pair<int,int> P; int n; ll c[501][501]; ll lc[501][501]; ll a[501],b[501]; ll difa[501]; ll difsuma[501]; ll difb[501]; ll difsumb[501]; bool solve(){ for(int i=0;i+1<n;i++){ difa[i]=c[0][i+1]-c[0][i]; for(int j=0;j<n;j++){ if(difa[i]!=(c[j][i+1]-c[j][i])){ return false; } } } for(int i=0;i+1<n;i++){ difb[i]=c[i+1][0]-c[i][0]; for(int j=0;j<n;j++){ if(difb[i]!=(c[i+1][j]-c[i][j])){ return false; } } } for(int i=0;i<n;i++){ difsuma[i+1]=difsuma[i]+difa[i]; difsumb[i+1]=difsumb[i]+difb[i]; } ll difamin=0; ll difbmin=0; for(int i=0;i<=n;i++){ difamin=min(difamin,difsuma[i]); difbmin=min(difbmin,difsumb[i]); } if(-(difamin+difbmin)>c[0][0])return false; ll ch=c[0][0]+(difamin+difbmin); for(int i=0;i<n;i++){ a[i]=difsuma[i]-difamin+ch; b[i]=difsumb[i]-difbmin; } return true; } int main(void){ scanf("%d",&n); for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ scanf("%lld",&c[i][j]); } } if(!solve()){ printf("No\n"); return 0; } printf("Yes\n"); for(int i=0;i<n;i++){ printf("%lld%c",b[i],(i+1==n)?'\n':' '); } for(int i=0;i<n;i++){ printf("%lld%c",a[i],(i+1==n)?'\n':' '); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> pii; #define ll long long #define ar array const ll mxN=2e5; const int mod=1e9+7; const ll INF=1e18; #define what_is(x) cerr << #x << " is " << x << endl; ll a,b,n,k,q,m,x,y,h,l,r,t; ll d[mxN],c[mxN]; vector<ll> adj[mxN]; void dfs(ll u=0,ll p=-1){ for(ll v: adj[u]){ if(v==p)continue; d[v]=d[u]+1; dfs(v,u); } } void dfs2(ll u=0,ll p=-1){ for(ll v: adj[u]){ if(v==p) continue; c[v]+=c[u]; dfs2(v,u); } } void solve(){ cin>>n; vector<ar<ll,2>> edges; for(ll i=0;i<n-1;i++){ ll a,b; cin>>a>>b; --a,--b; edges.push_back({a,b}); adj[a].push_back(b); adj[b].push_back(a); } dfs(); cin>>q; while(q--){ ll t,e,x; cin>>t>>e>>x;--e; if(t==1){ if(d[edges[e][0]] < d[edges[e][1]]){ c[edges[e][1]]-=x; c[0]+=x; }else{ c[edges[e][0]]+=x; } } if(t==2){ if(d[edges[e][0]] > d[edges[e][1]]){ c[edges[e][0]]-=x; c[0]+=x; }else{ c[edges[e][1]]+=x; } } } dfs2(); for(ll i=0;i<n;i++){ cout<<c[i]<<endl; } } signed main() { #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); #endif // ios::sync_with_stdio(false); // cin.tie(0); // cout.tie(0); cout<<setprecision(12)<<fixed; // cin>>t; // while(t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { int N; cin >> N; vector<int64_t> a(N-1), b(N-1); vector<vector<int64_t>> l(N, vector<int64_t>(0)); rep(i, N-1) { cin >> a.at(i) >> b.at(i); a.at(i)--; b.at(i)--; l.at(a.at(i)).push_back(b.at(i)); l.at(b.at(i)).push_back(a.at(i)); } int Q; cin >> Q; vector<int64_t> t(Q), e(Q), x(Q); rep(i, Q) { cin >> t.at(i) >> e.at(i) >> x.at(i); e.at(i)--; } vector<int64_t> tr(N, -1), temp(N, 0), d(N, -1); int64_t dn = 0; vector<int64_t> now = {0}; while (now.size()) { vector<int64_t> next(0); rep(i, now.size()) if (d.at(now.at(i)) == -1) { d.at(now.at(i)) = dn; rep(j, l.at(now.at(i)).size()) next.push_back(l.at(now.at(i)).at(j)); } dn++; now = next; } // rep(i, N) cout << d.at(i) << endl; rep(i, Q) { int64_t Qa, Qb; Qa = a.at(e.at(i)); Qb = b.at(e.at(i)); if (t.at(i) == 2) swap(Qa, Qb); if (d.at(Qa) < d.at(Qb)) { temp.at(0) += x.at(i); temp.at(Qb) -= x.at(i); } else { temp.at(Qa) += x.at(i); } // rep(i, N) cout << temp.at(i) << endl; } now = {0}; while (now.size()) { vector<int64_t> next(0); rep(i, now.size()) if (tr.at(now.at(i)) == -1) { tr.at(now.at(i)) = temp.at(now.at(i)); rep(j, l.at(now.at(i)).size()) { next.push_back(l.at(now.at(i)).at(j)); temp.at(l.at(now.at(i)).at(j)) += temp.at(now.at(i)); } } dn++; now = next; } rep(i, N) cout << tr.at(i) << endl; }
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() #define FOR(i, a, b) for (int i = a; i <= (b); i++) #define ROF(i, a, b) for (int i = a; i >= (b); i--) #define y1 awefakhlrv using pii = pair<int, int>; using vpii = vector<pii>; using vi = vector<int>; using vvi = vector<vi>; using ll = long long; using pll = pair<ll, ll>; using vpll = vector<pll>; using vll = vector<ll>; using vvll = vector<vll>; int main() { int n, k; cin >> n >> k; vvi a(n + 1, vi(n + 1)); FOR(i, 1, n) FOR(j, 1, n) cin >> a[i][j]; int ans = 0x3f3f3f3f, nd = k * k / 2 + 1; ROF(bl, 29, 0) { int na = ans - (1 << bl); if (na < 0) continue; // cout << na << endl; vvi f(n + 1, vi(n + 1)), cnt(f); FOR(i, 1, n) FOR(j, 1, n) f[i][j] = (a[i][j] >= na); // FOR(i, 1, n) FOR(j, 1, n) // cout << f[i][j] << (j == n ? '\n' : ' '); vvi psn(n + 1, vi(n + 1)); FOR(i, 1, n) FOR(j, 1, n) psn[i][j] = psn[i][j - 1] + f[i][j]; FOR(i, 1, n) FOR(j, k, n) cnt[i][j] = psn[i][j] - psn[i][j - k]; vvi psm(n + 1, vi(n + 1)); FOR(i, 1, n) FOR(j, k, n) psm[i][j] = psm[i - 1][j] + cnt[i][j]; // FOR(i, 1, n) FOR(j, 1, n) // cout << cnt[i][j] << (j == n ? '\n' : ' '); int mx = 0x3f3f3f3f; FOR(i, k, n) FOR(j, k, n) { mx = min(psm[i][j] - psm[i - k][j], mx); } // cout << endl << mx << endl; if (mx < nd) ans = na; } cout << ans - 1 << endl; }
#include <bits/stdc++.h> using namespace std; #define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define FOR(i,m) for(int i = 0 ;i < m ;i++) #define mem(a ,b) memset(a, (b) , sizeof(a)) #define all(cont) cont.begin(),cont.end() #define mp make_pair #define pb push_back #define F first #define S second #define cn cout<<'\n' #define re return typedef pair<int,int> pi; typedef vector<int> vi; typedef long long ll; typedef long double ld; typedef unsigned long long int ull; const int mod = 1e9 +7; int a[801][801]; int p[801][801]; int n , k; bool check(int x){ memset(p , 0 , sizeof(p)); for(int i = 1 ;i <= n ;i++){ for(int j = 1 ;j <= n ;j++){ p[i][j] = (a[i][j] <= x ? 1 : 0); } } for(int i =1 ;i <= n;i++){ for(int j = 1; j <= n ;j++){ p[i][j] += p[i-1][j] + p[i][j-1] - p[i-1][j-1]; } } int max_val = 0; for(int i = k; i <= n ;i++){ for(int j = k ;j <= n ;j++){ max_val = max(max_val , p[i][j] - p[i-k][j] - p[i][j-k] + p[i-k][j-k]); } } return max_val >= (k*k + 1)/2; } void solve(){ cin >> n >> k; for(int i = 1 ;i <= n ;i++){ for(int j = 1 ; j <= n ;j++)cin>>a[i][j]; } int l = 0 , r = mod-7; while(l < r){ int mid = l + (r-l)/2; if(check(mid)){ r = mid; } else l = mid + 1; } cout<<l<<"\n"; } int32_t main(){ ios; int _t = 1; // cin >> _t; for(int i = 1 ; i <= _t ;i++){ // cout<< "Case #"<<i<<": "; solve(); } return 0; }
//#pragma GCC target("avx2") //#pragma GCC optimize("O3") //#pragma GCC optimize("unroll-loops") //#pragma warning(disable : 4996) // ////#define ATCODER //#ifdef ATCODER //#include<atcoder/all> //using namespace atcoder; //#endif #include <algorithm> #include <utility> #include <vector> #include <limits.h> #include <math.h> #include <time.h> #include <algorithm> #include <array> #include <bitset> #include <cassert> #include <complex> #include <cstdio> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> #include <cassert> #include <numeric> #include <type_traits> using namespace std; #ifdef _MSC_VER #include"stdafx.h" #include <intrin.h> #define __builtin_popcount __popcnt #define __builtin_popcountll __popcnt64 void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << (H); debug_out(T...); } #define DEBUG(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define DEBUG(...) 42 #endif #define ll long long #define REP(i, n) for (ll i = 0; i < (n); ++i) #define REPR(i, n) for (ll i = (n) - 1; i >= 0; --i) #define FOR(i, m, n) for (ll i = (m); i < (n); ++i) #define VSORT(v) sort(v.begin(), v.end()); #define VREVERSE(v) reverse(v.begin(), v.end()) #define print(x) cout << (x) << '\n' #define spa <<" "<< #define lb(v, n) lower_bound(v.begin(), v.end(), (n)) #define ub(v, n) upper_bound(v.begin(), v.end(), (n)) #define int long long //#define double long double #define all(x) (x).begin(), (x).end() #define print_space(v) REP(i, v.size()) cout << v[i] << " \n"[i==(int)v.size()-1] template <typename T1, typename T2> inline bool chmin(T1 & a, T2 b) { if (a > b) { a = b; return true; }return false; } template <typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return true; }return false; } typedef pair<int, int> pii; typedef pair<long long, long long> pll; std::random_device rd; std::mt19937 mt(rd()); constexpr ll MOD = 1e9 + 7; constexpr int MAX = 400040; const double pi = acos(-1); constexpr long double EPS = 1e-14; const int dx[4] = { 0,0,-1,1 }, dy[4] = { -1,1,0,0 }; using ld = long double; int X, Y; unordered_map<int,int> dp; int rec(int y) { if (dp.count(y))return dp[y]; if (y <= X)return X - y; int ret = abs(X - y); if (y % 2 == 0) { chmin(ret, 1+rec(y / 2)); } else { chmin(ret, 2+rec((y + 1) / 2)); chmin(ret, 2+rec((y - 1) / 2)); } return dp[y] = ret; } void solve() { cin >> X >> Y; print(rec(Y)); } signed main() { cin.tie(0); ios::sync_with_stdio(false); //int q; cin >> q; //while (q--) solve(); }
#include<bits/stdc++.h> using namespace std; using ll=long long; int main(void) { ll N, K; cin >> N >> K; for (ll i = 0; i < K; i++) { if (N % 200 == 0) { N = N /200; } else { N = N * 1000 + 200; } } cout << N << endl; }
#include <bits/stdc++.h> using namespace std; #define all(x) (x).begin(),(x).end() #define rep(i, n) for (int i = 0; i < (n); i++) #define endl "\n" typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;} template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;} struct Edge { ll b, t, k; }; ll f(ll now, ll k) { return ((now + (k - 1)) / k) * k; } void solve() { int N, M, X, Y; cin >> N >> M >> X >> Y; X--, Y--; vector<vector<Edge>> G(N); for (int i = 0; i < M; i++) { ll a, b, t, k; cin >> a >> b >> t >> k; a--, b--; G[a].push_back({b, t, k}); G[b].push_back({a, t, k}); } priority_queue<pll, vector<pll>, greater<pll>> Q; Q.push({0, X}); ll INF = 2e18; vector<ll> dist(N, INF); while(!Q.empty()) { pll p = Q.top(); Q.pop(); ll d = p.first, v = p.second; if (d >= dist[v]) continue; dist[v] = d; for(int i = 0; i < G[v].size(); i++) { ll u = G[v][i].b; ll t = G[v][i].t; ll k = G[v][i].k; ll nt = t + ((d + (k - 1)) / k) * k; if (nt < dist[u]) { Q.push({nt, u}); } } } if (dist[Y] == INF) { cout << -1 << endl; } else { cout << dist[Y] << endl; } } int main() { #ifdef LOCAL_ENV cin.exceptions(ios::failbit); #endif cin.tie(0); ios::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(16); solve(); }
#include <bits/stdc++.h> using namespace std; // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; // #define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> #define int long long int #define endl "\n" #define MOD 1000000007 #define mod 1000000007 #define M 1000000007 #define pb push_back #define take(a,b,c) for(int b=0;b<c;b++) cin>>a[b] #define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define mx 1000005 #define fiint(a,b) memset(a,b,sizeof(a)) #define bitcount __builtin_popcount #define fori(i,a,b) for(int i=a;i<b;i++) #define ford(i,a,b) for(int i=a;i>=b;i--) #define debug(x) cout<<x<<endl; #define cases(t) int t; cin>>t; while(t--) #define inf1 INT_MAX #define all(a) a.begin(),a.end() #define vec vector<int> #define pii pair<int,int> #define plii pair<int,int> #define pint pair<int,int> #define ff first #define ss second #define lb lower_bound #define ub upper_bound #define bs binary_search #define mp make_pair #define sz(x) (int)x.size() #define PI 3.14159265359 int factorial[10000001]={0}; int gcd(int a, int b){ if (b == 0) return a; return gcd(b, a % b); } int powerFunction(int x,int y){ int res = 1; int p = mod; x = x; while (y > 0){ if (y & 1) res = (res*x)%p ; y = y>>1; x = (x*x)%p ; } return res; } void factorialFunction(int maxLimit){ factorial[0]=1; for(int i=1 ; i <= maxLimit ; i++) factorial[i]=(factorial[i-1]*i)%MOD; return; } int nCr(int n, int r) { if(r < 0 || r > n){ return 0; } int temp = factorial[n]; temp *= (powerFunction(factorial[r], MOD-2)%MOD); temp %= MOD; temp *= (powerFunction(factorial[n-r], MOD-2)%MOD); temp %= MOD; return temp; } signed main() { int n,m,x,y; cin>>n>>m>>x>>y; vector<pair<int ,pii >> adj[100005]; for(int i = 0 ; i < m ;i++) { int a,b,t,k;cin>>a>>b>>t>>k; adj[a].pb(mp(b , mp(t, k) )); adj[b].pb(mp(a , mp(t , k))); } vec vis(n + 1 , 0); priority_queue<pii , vector<pii> , greater<pii> > q; vec dis( n + 1, -1); q.push(mp( 0 ,x )); dis[x] = 0; while(sz(q) != 0 ) { int s = q.top().ss; //int d = q.front().ff; q.pop(); if(s == y) break; vis[s] = 1; for(auto it : adj[s]) { if(vis[it.ff] == 1) continue; int re = ( ( dis[s] % it.ss.ss == 0) ? 0 : it.ss.ss - (dis[s] % it.ss.ss) ); re += dis[s] + it.ss.ff; if(dis[it.ff] == -1 || dis[it.ff] > re) { dis[it.ff] = re; q.push(mp(re , it.ff)); } } } cout<<dis[y]<<endl; }
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ll; typedef pair<int, int> pii; int main() { int N, K, M; cin >> N >> K >> M; M *= N; int sum = 0; for (int i = 0; i < N - 1; i++) { int a; cin >> a; sum += a; } if (M - sum > K) { cout << -1 << endl; } else { cout << max(0, M - sum) << endl; } return 0; }
#include <iostream> using namespace std; int main(void){ int n,k,m,ans,sum; ans = -1; sum = 0; cin >> n; cin >> k >> m; for(int i=1;i<n;i++){ int temp; cin >> temp; sum += temp; } for(int i=0;i<= k;i++){ if(m <= (sum + i)/n){ ans = i; break; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #include <iostream> using namespace std; #define ll long long #define ld long double #define mp make_pair #define pb push_back #define fo(i,n) for(ll i=0;i<n;i++) #define fo1(i,n) for(ll i=1;i<=n;i++) #define loop(i,a,b)for(ll i=a;i<=b;i++) #define loopr(i,a,b)for(ll i=b;i>=a;i--) #define all(x) x.begin(), x.end() #define sz(x) (ll)(x).size() #define vll vector<ll> #define vvl vector<vll> #define vpll vector<pll> #define pll pair<ll,ll> #define F first #define S second #define MOD 1000000007 ll max(ll a,ll b){if (a>b) return a; else return b;} ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);} ll lcm(ll a, ll b){return a*b/gcd(a, b);} ll fexp(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%MOD; b/=2;a=a*a%MOD;}return ans;} ll inverse(ll a, ll p){return fexp(a, p-2);} int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //freopen("input.txt","r",stdin); ll T=1; //cin >> T; ll t=0; while(t++<T){ ll a,b,c; cin>>a>>b>>c; ll ans=21-(a+b+c); cout<<ans<<endl; } return 0; }
//********************************************************************// #include <bits/stdc++.h> using namespace std; #define endl "\n" #define RANGE(i, n) for (int i = 0; i < n; ++i) #define FOR(i, a, b) for (int i = a; i < b; ++i) #define DFOR(i, a, b) for(int i = a; i > b; --i) #define DEB(x) cout << #x << ": " << x << endl #define ALL(v) v.begin(), v.end() #define SORT(v) sort(ALL(v)) #define DISPV(v) { for(auto x___: v) cout << x___ << " "; cout << endl; } #define DISPM(m) { for(auto x____: m){ cout << x____.first << ": " << x____.second << endl; } }; #define DISPMV(m) { for(auto x_____: m){ cout << x_____.first << ": " ;DISPV(x_____.second);} }; using LL = long long; using VI = vector <int>; using VL = vector <long long>; using VVI = vector<VI>; using VVL = vector <VL>; using MII = map<int, int>; using MIVI = map<int, VI>; using MLL = map<LL, LL>; int READ_INT(){int temp;cin>>temp;return temp;} // read an int LL READ_LONG(){LL temp;cin>>temp;return temp;} // read a long long string READ_STRING(){string temp;cin>>temp;return temp;} // read a string const int MOD = int(1e9) + 7; const int INF = 1e9 + 5; const double PI = acos(-1.0); //M_PI; const double EPS = 1e-9; //********************************************************************// int n; VI t; LL dp[105][100005]; LL min_time(int ind, int nxt_free_time){ if(ind==n)return nxt_free_time; if(dp[ind][nxt_free_time] != -1)return dp[ind][nxt_free_time]; LL l = min_time(ind+1, nxt_free_time+t[ind]); LL r = min(nxt_free_time, t[ind])+ min_time(ind+1, abs(nxt_free_time - t[ind])); return dp[ind][nxt_free_time] = min(l, r); } int main(){ ios::sync_with_stdio(false); //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); cin >> n; RANGE(i,n)t.push_back(READ_INT()); memset(dp, -1, sizeof(dp)); cout << min_time(0, 0) << endl; return 0; } /* complie flags -Wall -Wextra -pedantic -std=c++11 -O2 -Wshadow -Wformat=2 -Wfloat-equal -Wconversion -Wlogical-op -Wshift-overflow=2 -Wduplicated-cond -Wcast-qual -Wcast-align -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -D_FORTIFY_SOURCE=2 -fsanitize=address -fsanitize=undefined -fno-sanitize-recover -fstack-protector */
#include <bits/stdc++.h> using namespace std; #define rep(i, l, n) for (int i = (int)(l); i < (int)(n); i++) #define drep(i, l, n) for (int i = (int)(n); i > (int)(l); i--) #define INF INT_MAX #define def (200007) #define MOD (1000000007) typedef vector<int> veci; typedef vector<vector<int>> Veci; typedef vector<int64_t> vecit; typedef vector<vector<int64_t>> Vecit; typedef int64_t intt; typedef vector<vector<double>> Vecd; typedef vector<double> vecd; typedef pair<int, int> P; /*veci のときdist.resize(N) Veciのとき2回resize; dp.assign(N,-1);*/ int main(){ int n; cin>>n; vector<string> name; int at_max=0;int at_i=0;int second_max=0,second_i=0; rep(i,0,n){ string s;int t; cin>>s>>t; if(at_max<t){ second_max=at_max; at_max=t; second_i=at_i; at_i=i; }else if(second_max<t){ second_max=t; second_i=i; } name.push_back(s); } cout<<name[second_i]<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define pf push_front #define ll long long #define ld long double int main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); int n; cin >> n; vector<pair<int, int>>arr; map<int, string>kode; int cur=0; for(int i=0;i<n;++i){ string s; int x; cin >> s >> x; kode[cur]=s; arr.pb({x, cur}); cur++; } sort(arr.begin(), arr.end(), greater<pair<int, int>>()); cout << kode[arr[1].se] << '\n'; }
//#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i=0; i<n; ++i) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() using ll = int64_t; using ull = uint64_t; using ld = long double; using P = pair<int, int>; using vs = vector<string>; using vi = vector<int>; using vvi = vector<vi>; template<class T> using PQ = priority_queue<T>; template<class T> using PQG = priority_queue<T, vector<T>, greater<T>>; const int INF = 0xccccccc; const ll LINF = 0xcccccccccccccccLL; template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);} template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);} template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;} template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;} //const unsigned int mod = 1000000007; const unsigned int mod = 998244353; struct mint { unsigned int x; mint():x(0) {} mint(int64_t x_) { int64_t v = int64_t(x_ % mod); if(v < 0) v += mod; x = (unsigned int)v; } static mint row(int v) { mint v_; v_.x = v; return v_; } mint operator-() const { return row(x?mod-x:0);} 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) { uint64_t z = x; z *= a.x; x = (unsigned int)(z % 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;} friend bool operator==(const mint &a, const mint &b) {return a.x == b.x;} friend bool operator!=(const mint &a, const mint &b) {return a.x != b.x;} mint &operator++() { x++; if(x == mod) x = 0; return *this; } mint &operator--() { if(x == 0) x = mod; x--; return *this; } mint operator++(int) { mint result = *this; ++*this; return result; } mint operator--(int) { mint result = *this; --*this; return result; } mint pow(int64_t t) const { mint x_ = *this, r = 1; while(t) { if(t&1) r *= x_; x_ *= x_; t >>= 1; } return r; } //for prime mod mint inv() const { return pow(mod-2);} mint& operator/=(const mint a) { return *this *= a.inv();} mint operator/(const mint a) {return mint(*this) /= a;} }; istream& operator>>(istream& is, mint& a) { return is >> a.x;} ostream& operator<<(ostream& os, const mint& a) { return os << a.x;} string to_string(mint a) { return to_string(a.x); } //head int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; if(n == 1) { cout << m << endl; return 0; } mint ans, _ = mint(m).inv(); vector<mint> _r(m+1), r(m, mint(1)); for(int j = 1; j < m+1; j++) _r[j] = (-_*j).inv(); for(int i = 1; i < n; i++) { for(int j = 1; j < m+1; j++) { r[j-1] *= -_*j+1; ans += (r[j-1]-1)*_r[j]; } } cout << mint(m).pow(n)*n - ans*mint(m).pow(n-2) << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int, int> pii; const int MOD = 998244353; int quick_pow(int a,int x) { int ret = 1; while(x) { if (x & 1) { ret = 1LL * ret * a % MOD; } x >>= 1; a = 1LL * a * a % MOD; } return ret; } int N, M; int q[5010][5010]; int main() { scanf("%d%d",&N,&M); for (int i=0;i<=M;i++) { for (int j=0;j<=N;j++) { q[i][j] = quick_pow(i, j); } } LL ans = 1LL * q[M][N] * N % MOD; for (int i=1;i<=M;i++) { for (int len=2;len<=N;len++) { LL pos = N - len + 1; LL in = q[M - i][len - 2]; LL out = q[M][N - len]; ans = (ans + MOD - pos * in % MOD * out % MOD) % MOD; } } printf("%lld\n",ans); }
#include <bits/stdc++.h> #include <cassert> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using P = pair<int, int>; struct Edge { ll to; ll weight; Edge(ll t, ll w) : to(t), weight(w) {} }; using Graph = vector<vector<Edge>>; // using Graph = vector<vector<int>>; const long long INF = 1LL << 60; const int INT_INF = 1000000000; int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; // int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {-1, 0, 1, 1, -1, 1, 0, -1}; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); string S; cin >> S; reverse(S.begin(), S.end()); for (auto &it : S) { if (it == '6') it = '9'; else if (it == '9') it = '6'; } cout << S << endl; return 0; }
#include<bits/stdc++.h> #define int long long #define REP(i,a,n) for(int i=a;i<(n);i++) #define REP_sz(i,s) for(int i=0;i<s.size();i++) #define gcd(a,b) __gcd(a,b) #define RE return #define FILL(a,b) memset(a,b,sizeof(a)) #define SO(a) sort(all(a)) #define all(a) a.begin(),a.end() #define pb push_back #define sz(a) (int)a.size() #define V vector #define ld long double #define viit(a) vector<int>::iterator a #define IT iterator #define SET setprecision #define FOR(i,a,n) for(int i=a;i<=(n);i++) #define ER1(a) a.erase(a.begin()) #define ER0(a) a.erase(a.end()) #define pii pair<int,int> #define pause system("PAUSE") #define cls system("CLS") #define mod1 1000000007 #define mod2 998244353 #define infmod 9223372036854775783 #define tc int t;cin>>t;while(t--)solve(); #define over(x) {cout<<x<<endl;return;} #define intsz(x) (int)sz(to_string(x)) using namespace std; signed main() { ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); string s; int d[]={0,1,0,0,0,0,9,0,8,6}; cin>>s; REP_sz(i,s){ s[i]='0'+d[s[i]-'0']; } reverse(s.begin(),s.end()); cout<<s<<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; ll A[2005]; ll gcd(ll a, ll b) { if (a < b) swap(a, b); ll c = a % b; if (c == 0) return b; return gcd(b, c); } int main() { cin.tie(0); ios::sync_with_stdio(false); ll N; cin >> N; REP(i, N) { cin >> A[i]; } ll mn = INF; REP(i, N) { mn = std::min(mn, A[i]); } std::unordered_map<ll, ll> mp; REP(i, N) { ll n = 1; while (n * n <= A[i] && n <= mn) { if (A[i] % n == 0) { { auto it = mp.find(n); if (it == mp.end()) { mp[n] = A[i]; } else { it->second = gcd(it->second, A[i]); } } ll x = A[i] / n; if (x <= mn) { auto it = mp.find(x); if (it == mp.end()) { mp[x] = A[i]; } else { it->second = gcd(it->second, A[i]); } } } n++; } } ll ans = 0; for (auto &p : mp) { if (p.first == p.second) ans++; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define Pint pair<int,int> #define Pll pair<ll,ll> #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 #define eb emplace_back template<class T>void chmax(T &a,T b){if(a<b)a=b;} template<class T>void chmin(T &a,T b){if(a>b)a=b;} 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); } ll gcd(ll a,ll b){ if(b==0)return a; return gcd(b,a%b); } ll lcm(ll a,ll b){ return a/gcd(a,b)*b; } 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; } ll modpow(ll a,ll b){ if(b==0)return 1; if(b%2)return modpow(a,b-1)*a%mod; ll memo=modpow(a,b/2); return memo*memo%mod; } vector<ll>kaijo,invkaijo; void init_fact(int n){ kaijo.resize(n+1); invkaijo.resize(n+1); kaijo[0]=1; for(ll i=1;i<=n;i++){ kaijo[i]=kaijo[i-1]*i; kaijo[i]%=mod; } rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2); } 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 comb(int a,int b){ if(a<b)return 0; if(a<0||b<0)return 0; return kaijo[a]*invkaijo[a-b]%mod*invkaijo[b]%mod; } ll inv(ll x){ x=modpow(x,mod-2); return x; } void solve(){ int n; string s[110]; cin>>n; rep(i,n)cin>>s[i]; int d[110][110]; rep(i,n){ rep(j,n){ if(s[i][j]=='1')d[i][j]=1; else if(i==j)d[i][j]=0; else d[i][j]=INF; } } rep(k,n){ rep(i,n){ rep(j,n){ chmin(d[i][j],d[i][k]+d[k][j]); } } } double ans=0; rep(i,n){ int c=0; rep(j,n){ if(d[j][i]<INF)c++; } ans+=1.0/c; } printf("%.12lf\n",ans); } int main(){ //int t;cin>>t;while(t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #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 MOD 1000000007 int main() { int n; cin >> n; vector<string> s(n); rep(i, n) { cin >> s[i]; } ll b = 1, f = 1; rep(i, n) { if (s[i] == "AND") { f = b + 2 * f; } else { b = 2 * b + f; } } cout << b << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define vll vector<ll> #define pll pair<ll,ll> #define forA(i,a,n,x) for(ll i=a;i<n;i+=x) #define forD(i,a,n,x) for(ll i=n-1;i>=a;i-=x) #define ranit(it,n) for(auto it:n) #define testCases ll t;cin>>t;while(t--) #define mp make_pair #define pb push_back #define F first #define S second #define mod 1000000007 #define init(a,x) memset(a,x,sizeof(a)) string s[61]; ll dp[102][2]; ll solve(ll n, bool val) { if(n==0)return 1; if(dp[n][val]!=-1)return dp[n][val]; if(s[n-1]=="OR") { if(val)return dp[n][val]= solve(n-1,false)+ 2*solve(n-1,true); else return dp[n][val]= solve(n-1,false); } else { if(val)return dp[n][val]= solve(n-1,true); else return dp[n][val]= 2*solve(n-1,false)+solve(n-1,true); } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n; cin>>n; init(dp,-1); forA(i,0,n,1)cin>>s[i]; cout<<solve(n,true); return 0; }
#include<bits/stdc++.h> #define ll long long int #define pb push_back #define po pop_back #define mp make_pair #define fi first #define se second #define hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define MOD 1000000007 using namespace std; bool comp(ll a,ll b){if(a>b)return true;else return false;} int isP(ll n){if(n==1)return 0;if(n==2 || n==3)return 1;for(ll i=2;i<=sqrt(n);i++){if(n%i==0)return 0;}return 1;} ll power(ll a,ll b){if(b==0)return 1;if(b==1) return a;ll t=power(a,b/2);if(b%2==1) return t*t*a;else return t*t;} ll powMOD(ll x,ll y){if(y==0)return 1;if(y==1)return x;ll t=powMOD(x,y/2);if(y%2==1)return t*t%MOD*x%MOD;else return t*t%MOD;} int main() { /*//----Hello World----//*/ //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); hello; ll t; // cin>>t; t=1; while(t--){ ll a,b,c; cin>>a>>b>>c; bool foo=1; if(c==0){ if(a<=b) foo=0; } else{ if(a<b) foo=0; } if(foo) cout<<"Takahashi\n"; else cout<<"Aoki\n"; } /*//----Hello World----//*/ return 0; }
#include "bits/stdc++.h" using namespace std; #include "string" #define int long long #define pi pair <int, int> #define ff first #define ss second #define boost ios::sync_with_stdio(false);cin.tie(nullptr) #define endl '\n' #define vi vector<int> int32_t main() { boost; int n, m, t; cin >> n >> m >> t; int cur = n; int pre = 0; string ans = "Yes"; for(int i = 0, x, y; i < m; i++) { cin >> x >> y; cur -= (x - pre); if(cur <= 0) { ans = "No"; break; } cur = min(n, cur + y - x); pre = y; } cur -=(t - pre); if(cur <= 0) ans = "No"; cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; #define Mod(x) (x>=P&&(x-=P)) #define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;++i) #define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;--i) #define erep(i,a) for(int i=hd[a];i;i=nxt[i]) typedef long long ll; inline void Max(int &x,int y){(x<y)&&(x=y);} inline void Min(int &x,int y){(x>y)&&(x=y);} bool let; char IO; inline int rd(int res=0){ bool f=0; while(IO=getchar(),IO<48||IO>57) f|=IO=='-'; do res=(res<<1)+(res<<3)+(IO^48); while(IO=getchar(),isdigit(IO)); return f?-res:res; } const int M=1005; struct node{ int w,v; bool operator <(const node &_)const{ return w<_.w; } }p[M]; int s[M],t[M]; priority_queue<int>que; bool vio; int main(){ cerr<<(&vio-&let)/1024.0/1024<<endl; int n=rd(),m=rd(),q=rd(); rep(i,1,n)p[i].w=rd(),p[i].v=rd(); rep(i,1,m)s[i]=rd(); sort(p+1,p+n+1); while(q--){ int l=rd(),r=rd(),tot=0; rep(i,1,l-1)t[++tot]=s[i]; rep(i,r+1,m)t[++tot]=s[i]; sort(t+1,t+tot+1); int ans=0,pos=1; while(!que.empty())que.pop(); rep(i,1,tot){ while(pos<=n&&p[pos].w<=t[i]) que.push(p[pos++].v); if(!que.empty()) ans+=que.top(),que.pop(); } printf("%d\n",ans); } }
#include <bits/stdc++.h> //#include<boost/multiprecision/cpp_int.hpp> //#include<boost/multiprecision/cpp_dec_float.hpp> //#include <atcoder/all> using namespace std; #define rep(i, a) for (int i = (int)0; i < (int)a; ++i) #define rrep(i, a) for (int i = (int)a; i > -1; --i) #define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i) #define RREP(i, a, b) for (int i = (int)a; i > b; --i) #define repl(i, a) for (ll i = (ll)0; i < (ll)a; ++i) #define pb push_back #define eb emplace_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define popcount __builtin_popcount #define popcountll __builtin_popcountll #define fi first #define se second using ll = long long; constexpr ll mod = 1e9 + 7; constexpr ll mod_998244353 = 998244353; constexpr ll INF = 1LL << 60; #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") // using lll=boost::multiprecision::cpp_int; // using // Double=boost::multiprecision::number<boost::multiprecision::cpp_dec_float<128>>;//仮数部が1024桁 template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } ll mypow(ll x, ll n, const ll &p = -1) { // x^nをmodで割った余り if (p != -1) { x = (x % p + p) % p; } ll ret = 1; while (n > 0) { if (n & 1) { if (p != -1) ret = (ret * x) % p; else ret *= x; } if (p != -1) x = (x * x) % p; else x *= x; n >>= 1; } return ret; } struct myrand{ random_device seed; mt19937 mt; myrand():mt(seed()){} int operator()(int a,int b){//[a,b) uniform_int_distribution<int>dist(a,b-1); return dist(mt); } }; //using namespace atcoder; //------------------------ //------------------------ //------------------------ //------------------------ //------------------------ void solve() { ll a,b,c,d; cin>>a>>b>>c>>d; if(c*d-b>0){ ll ans=(a+c*d-b-1)/(c*d-b); cout<<ans; }else{ cout<<-1; } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); solve(); return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <cstdio> #include <cstring> #include <cstdlib> #include <ctime> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <vector> #define setIO(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout) #define closefile fclose(stdin), fclose(stdout) #define m_p make_pair #define sz(x) (int)x.size() #define see(x) cerr << x << " " #define seeln(x) cerr << x << endl #define out(x) cerr << #x << " = " << x << " " #define outln(x) cerr << #x << " = " << x << endl #define outarr(x, l, r) {cerr<< #x"[" << l << " ~ " << r << "] = "; for (int _i = l; _i <= r; ++_i) cerr << x[_i] << " "; cerr << endl;} using namespace std; typedef long long ll; typedef pair <int, int> pii; #define gc() getchar() //#define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++) char buf[1 << 21], *p1 = buf, *p2 = buf; template <class T> void read(T &x) { x = 0; int c = gc(); int flag = 0; while (c < '0' || c > '9') flag |= (c == '-'), c = gc(); while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) +(c ^ 48), c = gc(); if (flag) x = -x; } template <class T> T _max(T a, T b){return b < a ? a : b;} template <class T> T _min(T a, T b){return a < b ? a : b;} template <class T> bool checkmax(T &a, T b){return a < b ? a = b, 1 : 0;} template <class T> bool checkmin(T &a, T b){return b < a ? a = b, 1 : 0;} const int mod = 998244353, N = (1 << 20) + 1; int fac[200005], ifac[200005], inv[200005]; #define Mul(a,b) (ll)(a) * (b) % mod #define mul(a,b) (a) = (ll)(a) * (b) % mod int Add(int x, int y) {x += y; return x >= mod ? x - mod : x;} int Sub(int x, int y) {x -= y; return x < 0 ? x + mod : x;} void add(int &a, int b) {a += b; if (a >= mod) a -= mod;} void sub(int &a, int b) {a -= b; if (a < 0) a += mod;} int qpow(int a, int b) { int ans = 1; while (b) { if (b & 1) mul(ans, a); mul(a, a); b >>= 1; } return ans; } int binom(int x, int y){return x < y ? 0 : Mul(fac[x], Mul(ifac[y], ifac[x - y]));} int n, m, k; void init() { read(n); read(m); read(k); } int calc(int lim, int l) { return Sub(qpow(lim, l), qpow(lim - 1, l)); } int calc2(int lim, int l) { return qpow(lim, l); } void solve() { if (n == 1 || m == 1) { printf("%d\n", qpow(k, m * n)); return; } int ans = 0; for (int i = 1; i <= k; ++i) { add(ans, Mul(calc(i, n), calc2(k - i + 1, m))); } printf("%d\n", ans); } int main() { init(); solve(); return 0; }
#include <cstdio> #include <algorithm> using namespace std; #define INF 998244353 long long Pow (long long a, long long b) { a %= INF; long long ans = 1; while (b > 0) { if (b & 1) { ans *= a; ans %= INF; } a *= a; a %= INF; b >>= 1; } return ans; } int main () { int n, m, k; scanf ("%d %d %d", &n, &m, &k); if (n == 1 && m == 1) { printf ("%d", k); return 0; } else if (n == 1) { printf ("%lld", Pow (k, m)); return 0; } else if (m == 1) { printf ("%lld", Pow (k, n)); return 0; } long long ans = 0; for (int i = 1; i <= k; i ++) { ans += Pow (i, n) * ((Pow (k - i + 1, m) - Pow (k - i, m)) % INF) % INF; ans %= INF; ans += INF; ans %= INF; } printf ("%lld", ans); }
#include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <utility> #define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++) #define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--) #define rep(i, n) FOR(i,0,n) #define irep(i, n) IFOR(i,0,n) template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } using ll = long long; using namespace std; int main() { char s, t; cin >> s; cin >> t; if (s == 'Y') { cout << (char)toupper(t) << endl; } else { cout << t << endl; } return 0; }
#include<iostream> #include<cstring> #include<cstdio> #include<climits> #include<algorithm> #include<queue> #include<vector> #define pii pair<int,int> #define mp make_pair #define pb push_back #define fi first #define se second using namespace std; inline int read(){ int f=1,ans=0; char c=getchar(); while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();} while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();} return f*ans; } const int MAXN=1e5+11; int f[MAXN],N,Ma[28]; char S[MAXN]; int main(){ //freopen("10.in","r",stdin); N=read(); scanf("%s",S+1); memset(Ma,127/3,sizeof(Ma)); memset(f,127/3,sizeof(f)); Ma[S[1]-'a']=0; for(int i=1;i<=N;i++){ for(int j=0;j<27;j++) if(j!=S[i]-'a') f[i]=min(f[i],Ma[j]+1); Ma[S[i+1]-'a']=min(Ma[S[i+1]-'a'],f[i]); } if(f[N]<=N) printf("%d\n",f[N]); else printf("-1\n"); return 0; }
#include <iostream> #include <vector> #include<string> #include <set> #include <cstdlib> #include <map> #include <cmath> #include <algorithm> #include <math.h> #include <iomanip> #include <ctype.h> using namespace std; int main() { int H; int W; int X; int Y; cin >> H >> W >> X >> Y; X--; Y--; vector<std::string>S(H); int result = 1; for(int i = 0;i<H;i++){ cin >> S[i]; } for(int i = Y + 1;i<W && S[X][i] != '#';i++){ result++; } for(int i = Y - 1;i>=0 && S[X][i] != '#';i--){ result++; } for(int i = X + 1;i<H && S[i][Y] != '#';i++){ result++; } for(int i = X - 1;i>=0 && S[i][Y] != '#';i--){ result++; } cout << result << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, a, b) for (int i = a; i < b; i++) #define repvec(i, v) for (int i = 0; i < v.size(); i++) #define vecall(v) (v).begin(), (v).end() #define input(t, ...) \ t __VA_ARGS__; \ in(__VA_ARGS__) #define invec(t, v, n) \ vector<t> v(n); \ for (int index = 0; index < n; index++) cin >> v[index]; using namespace std; using ll = long long; using ld = long double; using pii = pair<int, int>; using vi = vector<int>; inline void in(void) { return; } template <typename First, typename... Rest> void in(First& first, Rest&... rest) { cin >> first; in(rest...); return; } inline void out(void) { return; } template <typename First, typename... Rest> void out(First first, Rest... rest) { cout << " " << first; out(rest...); return; } const double Pi = acos(-1); int main() { input(int, h, w, x, y); x--; y--; int ans = 1; vector<vector<int>> mapp(h, vector<int>(w, 0)); rep(i, 0, h) { rep(j, 0, w) { input(char, s); if (s == '#') mapp[i][j] = 1; } } rep(i, 1, 100){ if(x - i < 0) break; else if(mapp[x - i][y] == 0) ans++; else break; } rep(i, 1, 100){ if(x + i >= h) break; else if(mapp[x + i][y] == 0) ans++; else break; } rep(i, 1, 100){ if(y - i < 0) break; else if(mapp[x][y - i] == 0) ans++; else break; } rep(i, 1, 100){ if(y + i >= w) break; else if(mapp[x][y + i] == 0) ans++; else break; } out(ans); }
#include <bits/stdc++.h> using namespace std; int main(){ int N = 0; vector<double> UFO(2); cin >> N; for (double &x : UFO){ cin >> x; } vector<vector<double>> buildings (N, vector<double> (2)); for (vector<double> &d : buildings){ for (double &f : d){ cin >> f; } } double e = 0; double y = 0; for (int i = 0; i < N; i++){ //y = 10 - 10e, y = 5 - 3e //10e - 3e = 10 - 5 e = (UFO.at(1) - buildings.at(i).at(1)) / (UFO.at(0) - buildings.at(i).at(0)); y = max(y, UFO.at(1) - UFO.at(0) * e); } cout << setprecision(16) << y << endl; }
#pragma GCC target("avx2") #pragma GCC optimize ("O3") #pragma GCC optimize ("unroll-loops") #include<bits/stdc++.h> #define int ll #define f first #define sz(a) ((int)(a).size()) #define s second #define all(v) v.begin(),v.end() #define pii pair<int,int> #define vpii vector<pii> #define eb emplace_back #define pb push_back #define fo(i,n) for(int i=0;i<n;i++) #define Fo(i,k,n) for(int i=k;i<n;i++) #define vi vector<int> using namespace std; using ll = long long; using lld = long double; const int oo = 1e13 ; const ll MOD = 1000000007; const int N = 18; int x[N] , y[N] , z[N]; int dp[1LL << N][N]; int DIS[N][N]; int n; int dis(int from , int to){ return abs(x[to] - x[from]) + abs(y[to] - y[from]) + max(0LL, z[to] - z[from]); } int get_dis(int from , int to){ return DIS[from][to]; } int fun(int mask , int src){ if(__builtin_popcountll(mask) == n) return dis(src , 0); if(dp[mask][src]!= -1) return dp[mask][src]; int ans = oo; for(int i = 1 ; i < n ; i++){ if((mask >> i) & 1) continue; ans = min(ans , dis(src , i) + fun(mask | (1 << i) , i)); } return dp[mask][src] = ans; } signed main(){ #ifndef ONLINE_JUDGE //freopen("in.txt" , "r" , stdin); #endif ios_base::sync_with_stdio(0);cin.tie(0); memset(dp , -1 , sizeof dp); cin >> n; fo(i , n) cin >> x[i] >> y[i] >> z[i]; fo(i , n) fo(j , n) if(i!=j) DIS[i][j] = oo; else DIS[i][j] = 0; cout << fun(1 , 0) << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; //#define ONLINE_JUDGE #define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); #define rep(z, x, y) for(int z=x;z<=y;++z) #define repe(z, x, y) for(int z=x;z<y;++z) #define repd(z, x, y) for(int z=x;z>=y;--z) #define repde(z, x, y) for(int z=x;z>y;--z) #define int long long typedef long long ll; typedef pair<int, int> PII; const int INF = 0x3f3f3f3f; const double eps = 1e-9; const int mod = 1e9 + 7; const int N = 65; string op[N]; void solve() { int n; cin >> n; vector<int> p; p.push_back(-1); rep(i, 1, n) { cin >> op[i]; if(op[i] == "AND") p.push_back(i); } p.push_back(n + 1); int ans = 0; repd(i, p.size() - 1, 1) { int a = ((int)pow(2ll, p[i] - p[i - 1] - 1) - 1); int b = (int)pow(2ll, p[i - 1] + 1); ans += a * b; } cout << ans << endl; } signed main() { #ifndef ONLINE_JUDGE freopen("IO/in.txt", "r", stdin); freopen("IO/out.txt", "w", stdout); #endif IOS; int t; solve(); }
#include <iostream> // cin cout #include <string> // string int main() { int n; std::cin >> n; unsigned long long res = 1; for (int i = 0; i < n; i++) { std::string x; std::cin >> x; if (x == "OR") { res += 1ULL << (i+1); } } std::cout << res; }
#include <bits/stdc++.h> #define ALL(a) a.begin(), a.end() #define ALLR(a) a.rbegin(), a.rend() #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define FORD(i, a, b) for (int i = (a); i > (b); i--) #define REP(i, n) for (int i = 0; i < (n); i++) #define REPR(i, n) for (int i = (n)-1; i >= 0; i--) #define SI(a) (int)a.size() using namespace std; using ll = long long; template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } ll llceil(ll a, ll b) { return (a + b - 1) / b; } ll shift(ll a) { return 1LL << a; } const int INF = shift(30); const ll LINF = shift(60); int main() { int n; cin >> n; vector<int> a(n); REP(i, n) cin >> a[i]; ll ans = 0; const int max_a = 200; vector<int> m(max_a * 2 + 1); REP(i, n) { FOR(j, -max_a, max_a + 1) { ll num = m[j + max_a]; ll dif = a[i] - j; ans += dif * dif * num; } m[max_a + a[i]]++; } cout << ans << endl; }
#include<bits/stdc++.h> #define int long long using namespace std; typedef long long ll; const int inf=0x3f3f3f3f; const ll INF=0x3f3f3f3f3f3f3f3f; const ll mod=1e9+7; const int N=300010; int n,ans,a[N],vis[N]; void init(){ memset(a,0,sizeof(a)); memset(vis,0,sizeof(vis)); n=ans=0; } void solve(){ init(); cin>>n; for(int i=1;i<=n;i++){ cin>>a[i]; ans+=vis[a[i]+200]; for(int j=0;j<=400;j++){ vis[j]+=(j-200-a[i])*(j-200-a[i]); } } cout<<ans<<endl; } signed main(){ ios::sync_with_stdio(false); cout.tie(NULL); int t; t=1; //cin>>t; while(t--){ solve(); } return 0;//完结撒花 }
#include <bits/stdc++.h> const long long INF = 1e9; const long long MOD = 1e9 + 7; //const long long MOD = 998244353; const long long LINF = 1e18; using namespace std; #define YES(n) cout << ((n) ? "YES" : "NO" ) << endl #define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl #define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE" ) << endl #define Possible(n) cout << ((n) ? "Possible" : "Impossible" ) << endl #define dump(x) cout << #x << " = " << (x) << endl #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) for(int i=0;i<(n);++i) #define REPR(i,n) for(int i=n;i>=0;i--) #define COUT(x) cout<<(x)<<endl #define SCOUT(x) cout<<(x)<<" " #define VECCOUT(x) for(auto&youso_: (x) )cout<<right<<setw(10)<<youso_<<" ";cout<<endl #define ENDL cout<<endl #define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__) #define LCIN(...) long long __VA_ARGS__;CINT(__VA_ARGS__) #define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__) #define VECCIN(x) for(auto&youso_: (x) )cin>>youso_ #define mp make_pair #define PQ priority_queue<long long> #define PQG priority_queue<long long,V,greater<long long>> typedef long long ll; typedef vector<long long> vl; typedef vector<long long> vi; typedef vector<bool> vb; typedef vector<char> vc; typedef vector<vl> vvl; typedef vector<vi> vvi; typedef vector<vb> vvb; typedef vector<vc> vvc; typedef pair<long long, long long> pll; #define COUT(x) cout<<(x)<<endl void CINT(){} template <class Head,class... Tail> void CINT(Head&& head,Tail&&... tail){ cin>>head; CINT(move(tail)...); } template<class T> void mod(T &x) { x %= MOD; x += MOD; x %= MOD; } ll GCD(ll a, ll b) { if(b == 0) return a; else return GCD(b, a%b); } struct COMB{ vl fact, fact_inv, inv; void init_nCk(long long SIZE) { fact.resize(SIZE + 5); fact_inv.resize(SIZE + 5); inv.resize(SIZE + 5); fact.at(0) = fact.at(1) = fact_inv.at(0) = fact_inv.at(1) = inv.at(1) = 1; for(long long i = 2; i < SIZE + 5; i++) { fact.at(i) = fact.at(i - 1)*i%MOD; inv.at(i) = MOD - inv.at(MOD%i)*(MOD/i)%MOD; fact_inv.at(i) = fact_inv.at(i - 1)*inv.at(i)%MOD; } } long long nCk (long long n, long long k) { assert(!(n < k)); assert(!(n < 0 || k < 0)); return fact.at(n)*(fact_inv.at(k)*fact_inv.at(n - k)%MOD)%MOD; } }; ll extGCD(ll a, ll b, ll &x, ll &y) { if(b == 0) { x = 1; y = 0; return a; } ll d = extGCD(b, a%b, y, x); y -= a/b*x; return d; } void Main() { LCIN(N); LCIN(H); if(H%N == 0) { cout << "Yes" << endl; } else { cout << "No" << endl; } } int main() { cout << fixed << setprecision(15); Main(); return 0; }
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_string(const string& s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(bool b) { return (b ? "true" : "false"); } string to_string(vector<bool> v) { bool first = true; string res = "{"; for (int i = 0; i < static_cast<int>(v.size()); i++) { if (!first) { res += ", "; } first = false; res += to_string(v[i]); } res += "}"; return res; } template <size_t N> string to_string(bitset<N> v) { string res = ""; for (size_t i = 0; i < N; i++) { res += static_cast<char>('0' + v[i]); } return res; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")"; } template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")"; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif #define fi first #define se second #define pb push_back #define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k)) #define forn(i,a,b) for(int i = a; i < b; i++) #define forr(i,a,b) for(int i = a; i >= b; i--) #define all(x) (x).begin(), (x).end() typedef long long ll; typedef long double ld; typedef pair<int,int> ii; typedef vector<int> vi; typedef vector<ii> vii; const ll mod = 1e9+7; int sum(int a, int b){return (a+b) % mod;} int sub(int a, int b){return (a + mod - b) % mod;} int mul(int a, int b){return (1ll * a * b) % mod;} int power(int a,int b){ int res = 1; while(b){ if(b&1)res = mul(res,a); b >>= 1; a = mul(a,a); } return res; } const int maxn = 100+10; const ll oo = (ll)1e18; ll X,memo[maxn][maxn][maxn],K; int A[maxn],N; ll dp(int pos,int cnt,int sum){ if(pos >= N){ if(cnt == 0 && sum == 0)return 0; return -oo; } ll &res = memo[pos][cnt][sum]; if(res != -1)return res; res = dp(pos+1,cnt,sum); if(cnt){ int sum2 = sum-(A[pos]%K); if(sum2 < 0)sum2 += K; res = max(res,A[pos]+dp(pos+1,cnt-1,sum2)); } return res; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> N >> X; forn(i,0,N)cin >> A[i]; ll res = X; forn(k,1,N+1){ forn(i,0,N+1)forn(j,0,N+1)forn(l,0,maxn)memo[i][j][l] = -1; K = k; ll sum = dp(0,k,X%K); //debug(k,sum); if(sum > 0){ res = min(res,(X-sum)/K); } } cout << res << '\n'; return 0; } /* __builtin_mul_overflow(x,y,&x) -fsplit-stack */
#include<bits/stdc++.h> using namespace std; int main(){ long long n; cin >> n; long long a = 3; long long b = 5; int ai = 1; int bi = 1; while(a <= n){ while(a+b <= n){ if(a+b == n){ goto answer; } if((n-a)%5 != 0){ break; } b *= 5; bi++; } b = 5; bi = 1; a *= 3; ai++; } ai = -1; answer: if(ai == -1) cout << -1 << endl; else cout << ai << ' ' << bi << endl; }
#include<bits/stdc++.h> using namespace std; #define rep(i, a, n) for(int i=(a); i<(n); ++i) #define per(i, a, n) for(int i=(a); i>(n); --i) #define pb emplace_back #define mp make_pair #define clr(a, b) memset(a, b, sizeof(a)) #define all(x) (x).begin(),(x).end() #define lowbit(x) (x & -x) #define fi first #define se second #define lson o<<1 #define rson o<<1|1 #define gmid l[o]+r[o]>>1 using LL = long long; using ULL = unsigned long long; using pii = pair<int,int>; using PLL = pair<LL, LL>; using UI = unsigned int; const int mod = 1e9 + 7; const int inf = 0x3f3f3f3f; const double EPS = 1e-7; const double PI = acos(-1.0); const int N = 1e5 + 10; int n; double a[N]; double cal(double x){ double ret = 0.0; rep(i, 0, n){ ret += (x + a[i] - min(a[i], 2.0*x)); } return ret / n; } int main(){ scanf("%d", &n); rep(i, 0, n) scanf("%lf", a+i); double low = 0.0, top = 1e10, m1, m2, a1, a2, ans = 1e20; while(top - low > EPS){ m1 = low + (top - low) / 3.0; m2 = top - (top - low) / 3.0; a1 = cal(m1); a2 = cal(m2); if(a1 >= a2){ ans = min(ans, a2); low = m1 + EPS; } else { ans = min(ans, a1); top = m2 - EPS; } } printf("%.10f\n", ans); return 0; }
#include <stdio.h> #include <algorithm> #include <vector> #include <queue> using namespace std; struct V { int d,t,k; }; struct PQ { int p; long long int t; bool operator < (const PQ x) const { return t>x.t; } }; vector<V> v[100010]; priority_queue<PQ> pq; int visit[100010]; int main() { int n,m,x,y; int chk=0; scanf("%d%d%d%d",&n,&m,&x,&y); for(int i=1;i<=m;i++) { int a,b,c,d; scanf("%d%d%d%d",&a,&b,&c,&d); v[a].push_back({b,c,d}); v[b].push_back({a,c,d}); } pq.push({x,0}); while(!pq.empty()) { auto now=pq.top(); pq.pop(); if(visit[now.p]==1) continue; visit[now.p]=1; if(now.p==y) { printf("%lld",now.t); chk=1; break; } for(auto it : v[now.p]) { if(visit[it.d]==1) continue; if(now.t%it.k==0) pq.push({it.d,(long long int)(now.t+it.t)}); else pq.push({it.d,(long long int)((now.t/it.k+1)*it.k+it.t)}); } } if(chk==0) printf("-1"); return 0; }
// Artur Kraska, II UWr #include <bits/stdc++.h> #define forr(i, n) for(int i=0; i<n; i++) #define FOREACH(iter, coll) for(auto iter = coll.begin(); iter != coll.end(); ++iter) #define FOREACHR(iter, coll) for(auto iter = coll.rbegin(); iter != coll.rend(); ++iter) #define lbound(P,R,PRED) ({typeof(P) X=P,RRR=(R), PPP = P; while(PPP<RRR) {X = (PPP+(RRR-PPP)/2); if(PRED) RRR = X; else PPP = X+1;} PPP;}) #define testy() int _tests; scanf("%d", &_tests); FOR(_test, 1, _tests) #define CLEAR(tab) memset(tab, 0, sizeof(tab)) #define CONTAIN(el, coll) (coll.find(el) != coll.end()) #define FOR(i, a, b) for(int i=a; i<=b; i++) #define FORD(i, a, b) for(int i=a; i>=b; i--) #define MP make_pair #define PB push_back #define ff first #define ss second #define deb(X) X; #define M 1000000007 #define INF 1000000007LL using namespace std; int n, m, a, x, y; priority_queue <pair<long long, int>> pq; struct droga { int cel; int odjazd; int czas; }; droga d; struct miasto { bool byl; vector <droga> l; }; miasto tab[1000007]; int main() { scanf("%d %d %d %d", &n, &m, &x, &y); forr(i, m) { scanf("%d %d %d %d", &a, &d.cel, &d.czas, &d.odjazd); tab[a].l.PB(d); swap(a, d.cel); tab[a].l.PB(d); } pq.push(MP(0, x)); while(!pq.empty()) { int nr = pq.top().ss; long long czas = -pq.top().ff; pq.pop(); if(tab[nr].byl) continue; // cout << "analizuje " << nr << endl; tab[nr].byl = 1; if(nr == y) { printf("%lld\n", czas); return 0; } for(auto p : tab[nr].l) { int nr2 = p.cel; long long odj = czas % p.odjazd; if(odj == 0) odj = czas; else odj = czas + p.odjazd - odj; // cout << " z " << nr << " moze jchac do " << nr2 << ", odjazd o " << odj << ", przyjazd o " << odj + p.czas << endl; if(!tab[nr2].byl) pq.push(MP(-(odj + p.czas), nr2)); } } printf("-1\n"); return 0; }
#include <bits/stdc++.h> #define fir first #define sec second #define PB push_back #define MP make_pair #define all(a) (a).begin(), (a).end() #define sz(a) (a).size() using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define rep1(i, n) for (int i = 1; i < (int)(n); ++i) #define foreach(itr, c) for (__typeof((c).begin()) itr = (c).begin(); itr != (c).end(); ++itr) template <class T> void chkmax(T& x, T y) { x = (x > y ? x : y); } template <class T> void chkmin(T& x, T y) { x = (x < y ? x : y); } typedef long long LL; typedef pair <int, int> pii; typedef vector <int> vi; const int N = 3e5 + 5; int n, a[N * 2]; struct Fenwick { LL d[N]; void init(){ rep1(i, n + 1) d[i] = 0; } void modify(int x, int val){ while (x <= n){ d[x] += val; x += x & -x; } } LL query(int x){ int ret = 0; while (x){ ret += d[x]; x -= x & -x; } return ret; } } fenw; int main(){ scanf("%d", &n); rep(i, n) scanf("%d", &a[i]), a[i]++; LL cur = 0; rep(i, n){ cur += i - fenw.query(a[i] - 1); fenw.modify(a[i], 1); } printf("%lld\n", cur); rep(i, n - 1){ a[i + n] = a[i]; fenw.modify(a[i], -1); cur -= a[i] - 1; cur += n - a[i]; printf("%lld\n", cur); } return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ull unsigned long long #define ll long long #define endl '\n' #define line cout<<"--------------------------"<<endl #define dd(x) cout<<#x<<" = "<<x<<' ' #define pb push_back #define mp make_pair #define mod 1000000007 #define fast ios_base::sync_with_stdio(false); cin.tie(NULL) #define filein freopen("input.txt","r",stdin) #define fileout freopen("output.txt","w",stdout) using namespace std; using namespace __gnu_pbds; template <typename T> using os=tree < T, null_type ,less<T>, rb_tree_tag,tree_order_statistics_node_update >; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const ll mx=300009; ll big[mx],small[mx]; int main() { ll n; cin>>n; vector<ll>v(n); for(ll i=0;i<n;i++) cin>>v[i]; os<ll>s; ll ans=0; for(ll i=n-1;i>=0;i--) { ll a=v[i]; ll sm=s.order_of_key(a); ans+=sm; s.insert(a); } for(ll i=0;i<n;i++) { cout<<ans<<endl; ans+=n-v[i]-1-v[i]; } }
//g++ t.cpp -o t && t < p.txt //d>p.txt&&t<p.txt&&t2<p.txt #include <iostream> // プログラムの耳と口 #include <vector> // 超有能配列秘書 #include <algorithm> // みんな大好きソートと二分探索 #include <queue> // きゅーちゃん、だいすき #include <string> // to_string #include <functional> // 関数を変数に入れる子 #include <set> // 値の取得・挿入・削除を高速に #include <map> // setの妹 これまた優秀 #include <random> // 乱択さん #include <ctime> // へびになりたい #include <bitset> // へびになった シャー #include <cassert> // #include <atcoder/all> // using namespace atcoder; // コンパイル重い // g++ t.cpp -o t -I . #define DB cerr<<"D"<<endl using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6; using P=pair<ll,ll>; const ll M = 1000000007; ll mod_pow(ll x, ll a) { ll an = 1; while(a > 0) { if (a&1) an = an * x % M; x = x * x % M; a >>= 1;} return an;} ll mod_pow(ll x, ll a, ll m) { ll an = 1; while(a > 0) { if (a&1) an = an * x % m; x = x * x % m; a >>= 1;} return an;} void add(ll& x, ll y) {x+=y; x%=M;}; void mul(ll& x, ll y) {x*=y; x%=M;}; template<typename T, typename U> void chmax(T& x, U y) {if (x<y) x=y;}; template<typename T, typename U> void chmin(T& x, U y) {if (x>y) x=y;} bool vaild(int x, int y, int hh, int ww){return 0<=x&&x<hh&&0<=y&&y<ww;} ll gcd(ll a, ll b) {if (b==0) return a; else return gcd(b, a%b);} int keta(ll a) {int res=0; while(a>0) res+=a%10, a/=10; return res;} const int up[]={1,-1,0,0}, lf[]={0,0,1,-1}; int main() { const int mx = 200000; ll n,w; cin>>n>>w; ll dp[mx]={}; for(int i=0;i<n;i++) { ll s,t,p; cin>>s>>t>>p; dp[s]+=p; if (t<mx) dp[t]-=p; } for(int i=1;i<mx;i++) { dp[i]+=dp[i-1]; } bool ok = true; for(int i=0;i<mx;i++) { ok &= dp[i] <= w; } if (ok) cout<<"Yes"<<endl; else cout<<"No"<<endl; } // ・配列の大きさok? ・priority_queueはgreater? ・debug消した? // ・落ち着いて。提出まで4分待ってね……WJ……1/10……2/10…… // Thank you for making problems and running the contest
#include<bits/stdc++.h> using namespace std; int main() { int n,s,d,i,a,b,p=0; cin >>n>>s>>d; for(i=0;i<n;i++) { cin >>a>>b; if(a<s && b>d) { ++p; } } if(p) cout <<"Yes"<<endl; else cout <<"No"<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define inf 1000000000 int n,k; vector<vector<int> > edges(100); int main(){ cin >> n >> k; for(int i=1; i<=n; i++){ for(int j=1; j<=n; j++){ edges[i].pb(0); } } for(int i=1; i<=n; i++){ for(int j=1; j<=n; j++){ cin >> edges[i][j]; edges[j][i]=edges[i][j]; } } int a[n+1]; for(int i=1;i<n+1; i++) a[i] = i; int cnt=0; do{ ll sum=0; for(int i=2; i<n+1; i++){ sum+=edges[a[i-1]][a[i]]; } sum+=edges[a[n]][a[1]]; if(sum == k) cnt++; }while(next_permutation(a+2, a+n+1)); cout << cnt; return 0; }
//g++ -std=gnu++14 a.cpp #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <iostream> #include <istream> #include <iterator> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #include <tuple> #include <iomanip> #include <random> #include <math.h> #include <stdio.h> using namespace std; #define ll long long #define rep(i, n) for(ll i = 0; i < (n); i++) ll MOD = 1e9 + 7; int INF = 1 << 30; ll INFL = 1LL << 60; ll MODP = 998244353; ll lmax(ll x,ll y){ if(x < y) return y; else return x; } ll lmin(ll x, ll y){ if(x > y)return y; else return x; } ll gcd(ll x,ll y){ while(y > 0){ if(x < y) swap(x,y); return gcd(y,x%y); } return x; } int main(){ ll n,k; cin >> n >> k; vector<vector<ll>> dist(n,vector<ll>(n)); rep(i,n)rep(j,n){ ll a; cin >> a; dist[i][j] = a; } vector<ll> array(n); vector<vector<ll>> how; rep(i,n)array[i] = i+1; do{ vector<ll> res(n); for(int i=0; i<n; i++){ res[i] = array[i]; } how.push_back(res); }while(next_permutation(array.begin(),array.end())); ll ans = 0; for(auto x : how){ if(x[0] != 1)continue; ll sum = 0; ll d = x.size(); for(int i = 0;i < d - 1;i++){ sum += dist[x[i]-1][x[i+1]-1]; } sum += dist[x[d-1]-1][0]; if(sum == k)ans++; } cout << ans <<endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int64_t N; string S, X; cin >> N >> S >> X; vector<vector<int64_t>> memo(N, vector<int64_t>(7, -1)); function<bool(int64_t, int64_t)> f = [&](int64_t i, int64_t j) { //ターンiをj(mod 7)で迎えた場合にTの勝ちであるかどうか if (i == N) { return (j == 0); } if (memo[i][j] != -1) { return bool(memo[i][j]); } bool l = f(i + 1, j * 10 % 7); bool r = f(i + 1, (j * 10 + S[i] - '0') % 7); bool m = (X[i] == 'T' ? l || r : l && r); return bool(memo[i][j] = m); }; cout << (f(0, 0) ? "Takahashi" : "Aoki") << endl; }
#include <bits/stdc++.h> using namespace std; // rep #define rep(i,n) for(decltype(n) i = 0; i < (n) ; ++i) #define orep(i,n) for(decltype(n) i = 1; i <= (n); ++i) // one rep #define drep(i,n) for(decltype(n) i = (n)-1; i >= static_cast<decltype(i)>(0); --i) // down rep #define srep(i,s,t) for(decltype(t) i = (s); i < (t); ++i) // set rep // func #define rng(x) (x).begin(),(x).end() // range #define rrng(a) (a).rbegin(),(a).rend() // reverse range #define isin(x,l,r) ((l) <= (x) && (x) < (r)) #define ru(x,y) (((x)+(y)-1)/(y)) // round up #define sz(x) int((x).size()) // size // replace #define fi first #define se second #define eb emplace_back #define fcout cout << fixed << setprecision(15) #define LL_MIN std::numeric_limits<long long>::min() #define LL_MAX std::numeric_limits<long long>::max() // type using ll = long long; using P = pair<int,int>; using vi = vector<int>; using vvi = vector<vi>; using vp = vector<P>; using vvp = vector<vp>; using vl = vector<ll>; using rpq = priority_queue<int,vi,less<int>>; // 大きい順 using pq = priority_queue<int,vi,greater<int>>;// 小さい順 const int INF = 1001001001; const ll LINF = 1010010011001001001; template<typename T> void Yes(T flag) { cout << (flag ? "Yes" : "No") << endl; } int main() { int n;cin >> n; string s,t; cin >> s >> t; vector<set<int>> dp(n,set<int>()); dp.at(n-1).insert(0); drep(i,n) { if(i==0) continue; if(t.at(i) == 'A') { rep(j,7) { int tr = (10 * j + (s.at(i)-'0')%7) % 7 >= 0 ? (10 * j + (s.at(i)-'0')%7) % 7 : (10 * j + (s.at(i)-'0')%7) % 7 + 7; int sr = j * 10 % 7; if(dp.at(i).find(tr) != dp.at(i).end() and dp.at(i).find(sr) != dp.at(i).end()) dp.at(i-1).insert(j); } } else { for(auto r: dp.at(i)) { int tr = (r-(s.at(i)-'0')%7)*5 % 7 >= 0 ? (r-(s.at(i)-'0')%7)*5 % 7 : (r-(s.at(i)-'0')%7)*5 % 7 + 7; int sr = r * 5 % 7; dp.at(i-1).insert(sr); dp.at(i-1).insert(tr); } } if(dp.at(i-1).empty()) { cout << "Aoki" << endl; return 0; } } if(t.at(0) == 'T') { if(dp.at(0).find((s.at(0) - '0') % 7) != dp.at(0).end() or dp.at(0).find(0) != dp.at(0).end()) cout << "Takahashi" << endl; else cout << "Aoki" << endl; } else { if(dp.at(0).find((s.at(0) -'0') % 7) == dp.at(0).end() or dp.at(0).find(0) == dp.at(0).end()) cout << "Aoki" << endl; else cout << "Takahashi" << endl; } return 0; }
#include <iostream> using namespace std; int main() { int x, y; cin >> x >> y; if (x + y >= 15) { if (y >= 8) cout << "1"; else if (y >= 3) cout << "2"; else cout << "3"; } else if (x + y >= 10) { if (y >= 3) cout << "2"; else cout << "3"; } else if (x + y >= 3) { cout << "3"; } else cout << "4"; }
#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; template <typename T> using orderedd_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // // find_by_order(k) returns iterator to kth element starting from 0; // order_of_key(k) returns count of elements strictly smaller than k; typedef long long ll; typedef vector<ll> VL; typedef vector<int> VI; typedef pair<ll,ll> PLL; typedef pair<int,int> PII; #define pb push_back #define F first #define S second #define SZ(a) int((a).size()) #define ALL(a) a.begin(),a.end() #define fr(i,x,y) for(int i=x;i<y;i++) #define frr(i,x,y) for(int i=x-1;i>=y;i--) #define inf 1e18+1 const long double PI = acos(-1.0L); #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); const int mod=1000000007; //const int mod=998244353; ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;} ll power(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;}a=a*a;b>>=1;}return ans;} ll powerm(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;ans%=mod;}a=a*a;a%=mod;b>>=1;}return ans%mod;} VL dx={1,0,-1,0}; VL dy={0,1,0,-1}; // string to integer stoi() // string to long long stoll() // string.substr(position,length); // integer to string to_string(); void solve() { ll a,b; cin>>a>>b; a+=b; if(a>=15&&b>=8) { cout<<"1\n"; } else if(a>=10&&b>=3) { cout<<"2\n"; } else if(a>=3) { cout<<"3\n"; } else { cout<<"4\n"; } return; } int main() { IOS; ll t=1,pp; // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("error.txt", "w", stderr); // freopen("output.txt", "w", stdout); // #endif // cin>>t; pp=t; while(t--) { //cout<<"Case #"<<pp-t<<": "; solve(); } 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 * BE CAREFUL REGARDING THE DEFAULT VALUES IN segement trees etc * BE very careful in int vs long long vs unsigned long long */ /* recursion - matrix exponential */ // BITMASK: // 1)When some constrall is of the order of 15-20, think of bitmask DP. // 2)When some constrall is around 40, try out meet in the middle // 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algorithmQ
#include <time.h> #include <iomanip> #include <iostream> #include <map> #include <algorithm> #include <queue> #include <set> #include <vector> #include <iomanip> #include <bitset> using namespace std; #define pi pair<int ,int> int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); srand (time(NULL)); int test = 1; //cin >> test; while (test--) { int n; cin >> n; map <long long , int> mp1, mp2; vector <int> a(n+1); vector <long long> preSum(n+1); long long res = 0; for (int i = 1 ; i <= n ; i++) { cin >> a[i]; if (i % 2 == 1) { preSum[i] = preSum[i-1] + a[i]; } else { preSum[i] = preSum[i-1] - a[i]; } if (preSum[i] == 0) { res++; res += mp1[0]; } else { if (i % 2 == 1) { res += mp1[preSum[i]]; } else { res += mp2[-preSum[i]]; } } mp1[preSum[i]]++; mp2[-preSum[i]]++; } cout <<res; } }
#include<bits/stdc++.h> #define ll long long #define fori(i,j,n) for(ll i=(ll)j;i<(ll)n;++i) #define forr(i,a,b) for(ll i=(ll)(a);i>=(ll)(b);--i) #define all(x) x.begin(), x.end() #define mp(i, j) make_pair(i, j) #define pb(i) push_back(i) #define pii pair<int,int> #define vi vector<ll> #define vb vector<bool> #define vii vector<vector<ll> > using namespace std; const int mod=998244353; const int maxn=INT_MAX; template<class T> T gcd(T a,T b){ while(a!=0){ T tmp=a; a=b%a; b=tmp;} return b;} vb sieve(int n){ vb prime(n+1, true); for(int i=2;i*i<=n;i++){ if(prime[i]){ for(int j=i*i;j<=n;j+=i) prime[j]=false; }} return prime;} vi noOfDivisors(int n){ vi div(n+1, 0); div[1]=1; fori(i, 2, n+1) div[i]=2; fori(i, 2, n+1){for(int j=2*i;j<=n;j+=i) div[j]++;} return div;} vi divisors(ll n){vi div;for(ll i=1;i*i<=n;i++){ if(n%i==0) { div.pb(i); if(n/i!=i) div.pb(n/i); }} return div;} 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 addmod(ll a, ll b){ return (a%mod + b%mod)%mod;} ll mulmod(ll a, ll b){ return (a%mod * b%mod)%mod;} ll powmod(ll a, ll b){ll ans=1;while(b!=0){ans=mulmod(ans, a);b--;}return ans%mod;} int main(){ #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif cin.tie(0); ios_base::sync_with_stdio(false); int t=1; cin>>t; while(t--){ int n; cin>>n; int a[n]; fori(i, 0, n) cin>>a[i]; vector<pii> ans; int cur=0; fori(i, 0, n*n){ int flag=0; fori(j, 0, n-1){ if(cur%2==0 && j%2==0 && a[j]>a[j+1]) { swap(a[j], a[j+1]); ans.pb(mp(j+1, j+2)); flag=1; cur=1-cur; //break; } else if(cur%2==1 && j%2==1 && a[j]>a[j+1]) { swap(a[j], a[j+1]); ans.pb(mp(j+1, j+2)); flag=1; cur=1-cur; //break; } } if(flag==0){ int flag2=0; fori(k, 0, n-1){ if(a[k]>a[k+1]) flag2=1; } if(flag2==0) break; if(cur%2==0) { swap(a[0], a[1]); ans.pb(mp(1, 2)); cur=1-cur; } else { swap(a[1], a[2]); ans.pb(mp(2,3)); cur=1-cur; } } //cout<<ans[ans.size()-1].first<<" "; } cout<<ans.size()<<'\n'; //if(ans.size()!=0) cout<<'\n'; fori(i, 0, ans.size()){ cout<<ans[i].first; cout<<" "; } cout<<'\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define ff first #define ss second #define rsz resize #define ins insert #define mp make_pair #define pf push_front #define pb push_back #define eb emplace_back #define ft front() #define bk back() #define sz(x) (int)(x).size() #define all(x) begin(x), end(x) #define rep(i,a,b) for (int i = (a); i < (b); ++i) #ifndef ONLINE_JUDGE #define deb(x) cerr<< #x <<" "; __print(x); cerr<<endl; #else #define deb(x) #endif const ll mod = 1e9+7; // 998244353; const ll inf = 1e18; const ld pie = acos((ld)-1); ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;} ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;} ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;} int dx[] = {1, -1, 0, 0}; int dy[] = {0, 0, 1, -1}; void __print(int x) {cerr<<x;} void __print(char x) {cerr<<x;} void __print(string x) {cerr<<x;} void __print(float x) {cerr<<x;} void __print(double x) {cerr<<x;} void __print(bool x) {cerr<<x;} void __print(ll x) {cerr<<x;} template<class T, class U> void __print(pair<T,U> p) {cerr<<"{"<<p.ff<<", "<<p.ss<<"}";} template<class T> void __print(vector<T> arr) { cerr<<"[ "; for(auto x:arr) { __print(x);cerr<<" "; } cerr<<"]"; } template<class T> void __print(set<T> st) { cerr<<"{ "; for(auto x:st) { __print(x); cerr<<" "; } cerr<<"}";} template<class T, class U> void __print(vector<pair<T,U>> arr) { cerr<<"[ "; for(auto x:arr) {__print(x);cerr<<", ";}cerr<<"]";} template<class T, class U> void __print(unordered_map<T,U> arr) { cerr<<"{ "; for(auto x:arr) {__print(x);cerr<<", ";}cerr<<"}";} template<class T, class U> void __print(map<T,U> arr) { cerr<<"{ "; for(auto x:arr) {__print(x);cerr<<", ";}cerr<<"}";} template<typename... T> void read(T&... args) { ((cin>>args),...);} template<typename... T> void write(T&&... args){((cout<<args<<" "),...);cout<<'\n';} int N,M; int main(){ scanf("%d%d", &N, &M); vector<vector<int>> arr(N, vector<int>(M, 0)); rep(i, 0, N) { string s; cin>>s; for(int j = 0; j < M; ++j) { if(s[j] == '+') { arr[i][j] = 1; } else { arr[i][j] = -1; } } } //X -> score of 1st player //y -> score of 2nd player //first player tries to maximise the X - Y -> max //second player tries to minimise the X - Y -> min vector<vector<int>> dp(N, vector<int>(M, 0)); //decreasing order of evaluation for(int i = N - 1; i >= 0; --i) { for(int j = M - 1; j >= 0; --j) { if(i == N - 1 && j == M - 1) { continue; } if((i + j)%2 == 0) { // first player dp[i][j] = INT_MIN; if(i + 1 < N) { dp[i][j] = max(dp[i][j], arr[i + 1][j] + dp[i + 1][j]); } if(j + 1 < M) { dp[i][j] = max(dp[i][j], arr[i][j + 1] + dp[i][j + 1]); } } else { //second player dp[i][j] = INT_MAX; if(i + 1 < N) { dp[i][j] = min(dp[i][j], dp[i + 1][j] - arr[i + 1][j]); } if(j + 1 < M) { dp[i][j] = min(dp[i][j], dp[i][j + 1] - arr[i][j + 1]); } } } } // for(int i = 0; i < N; ++i) { // for(int j = 0; j < M; ++j) { // printf("%d ",dp[i][j]); // }printf("\n"); // } if(dp[0][0] > 0) { puts("Takahashi"); } else if(dp[0][0] < 0) { puts("Aoki"); } else { puts("Draw"); } return 0; /*STUFF TO LOOK: 1. Check the constraints 2. Corner cases(n==0||n==1) 3. Variables in loops 4. Make sure two ints aren’t multiplied to get a long long 5. Don't use scanf or printf while using ios_base 6. using the local variable of the same name when global variable was required to be used */ }
#include<bits/stdc++.h> using namespace std; const int N=2005; char a[N][N]; int dp[N][N]; int n,m; map<char,int>mp; int main(){ mp['+']=1;mp['-']=-1; cin>>n>>m; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++)cin>>a[i][j]; dp[n][m]=0; for(int i=n;i>=1;i--) for(int j=m;j>=1;j--){ if(i==n&&j==m)continue; int flag=((i+j)%2==0); if(flag){ dp[i][j]=-N*N; if(i+1<=n)dp[i][j]=max(dp[i][j],dp[i+1][j]+mp[a[i+1][j]]); if(j+1<=m)dp[i][j]=max(dp[i][j],dp[i][j+1]+mp[a[i][j+1]]); }else{ dp[i][j]=N*N; if(i+1<=n)dp[i][j]=min(dp[i][j],dp[i+1][j]-mp[a[i+1][j]]); if(j+1<=m)dp[i][j]=min(dp[i][j],dp[i][j+1]-mp[a[i][j+1]]); } } if(dp[1][1]>0)puts("Takahashi"); else if(dp[1][1]<0)puts("Aoki"); else puts("Draw"); return 0; }
#include<bits/stdc++.h> using namespace std; int main() { int64_t n,x,z; double y=0; x=0; cin>>n; vector<int64_t> a(n); for(int i=0;i<n;i++) { cin>>a.at(i); if(a.at(i)<0) a.at(i)*=-1; x+=a.at(i); y+=(a.at(i)*a.at(i)); } y=sqrt(y); sort(a.begin(),a.end()); z=a.at(n-1); cout<<x<<endl; cout<<fixed<<setprecision(10); cout<<y<<endl; cout<<z<<endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef double db; typedef pair <int, int> pin; const int N = 45; const int S = (1 << 20) + 5; const ll inf = 1LL << 60; int n; ll m, a[N]; vector <ll> sa, sb; template <typename T> inline void read(T &X) { char ch = 0; T op = 1; for (X = 0; ch > '9' || ch < '0'; ch = getchar()) if (ch == '-') op = -1; for (; ch >= '0' && ch <= '9'; ch = getchar()) X = (X * 10) + ch - '0'; X *= op; } int main() { #ifndef ONLINE_JUDGE freopen("sample.in", "r", stdin); #endif read(n), read(m); for (int i = 1; i <= n; i++) read(a[i]); int l = n / 2, r = n - l; for (int s = 0; s < (1 << l); ++s) { ll now = 0; for (int i = 0; i < l; i++) if (s & (1 << i)) now += a[i + 1]; sa.push_back(now); } for (int s = 0; s < (1 << r); ++s) { ll now = 0; for (int i = 0; i < r; i++) if (s & (1 << i)) now += a[l + i + 1]; sb.push_back(now); } sort(sb.begin(), sb.end()); // for (int i = 0; i < sa.size(); i++) // printf("%lld%c", sa[i], " \n"[i == sa.size() - 1]); // for (int i = 0; i < sb.size(); i++) // printf("%lld%c", sb[i], " \n"[i == sb.size() - 1]); ll ans = m; for (int i = 0; i < sa.size(); i++) { ll ta = sa[i]; if (ta > m) continue; if (ta == m) { ans = 0; break; } int tb = upper_bound(sb.begin(), sb.end(), m - ta) - sb.begin() - 1; ll tmpb; if (tb < 0) tmpb = 0; else tmpb = sb[tb]; if (tmpb + ta <= m) ans = min(ans, m - tmpb - ta); } printf("%lld\n", m - ans); return 0; }
// #pragma GCC optimize(2) #include <algorithm> #include <iostream> #include <sstream> #include <cstring> #include <cstdio> #include <random> #include <cctype> #include <bitset> #include <string> #include <vector> #include <queue> #include <cmath> #include <stack> #include <set> #include <map> #define IO \ ios::sync_with_stdio(false); \ // cout.tie(0); #define lson(x) (x << 1) #define rson(x) (x << 1 | 1) using namespace std; // int dis[8][2] = {0, 1, 1, 0, 0, -1, -1, 0, 1, -1, 1, 1, -1, 1, -1, -1}; typedef unsigned long long ULL; typedef long long LL; typedef pair<int, int> P; const int maxn = 1e2 + 10; const int maxm = 1e7 + 10; const LL INF = 0x3f3f3f3f3f3f3f3f; const int inf = 0x3f3f3f3f; const LL mod = 998244353; const double eps = 1e-8; const double pi = acos(-1); // int dis[4][2] = {1, 0, 0, -1, 0, 1, -1, 0}; // int m[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; double dp[maxn][maxn][maxn]; int main() { #ifdef WXY freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); #endif IO; int a, b, c; cin >> a >> b >> c; dp[a][b][c] = 1; for (int i = a; i <= 99; i++) { for (int j = b; j <= 99; j++) { for (int k = c; k <= 99; k++) { dp[i + 1][j][k] += dp[i][j][k] * (i) / (i + j + k); dp[i][j + 1][k] += dp[i][j][k] * (j) / (i + j + k); dp[i][j][k + 1] += dp[i][j][k] * (k) / (i + j + k); } } } double ans = 0; for (int i = 0; i <= 99; i++) for (int j = 0; j <= 99; j++) { ans += (dp[100][i][j] + dp[i][100][j] + dp[i][j][100]) * max(0, i + j + 100 - a - b - c); } printf("%.10lf", ans); return 0; }
#include <bits/stdc++.h> using namespace std; void DBG() { cerr << endl; } template<class Head, class... Tail> void DBG(Head H, Tail... T) { cerr << ' ' << H; DBG(T...); } #define dbg(...) cerr << "(" << (#__VA_ARGS__) << "):", DBG(__VA_ARGS__) using ll = long long; using ld = long double; #define sqr(a) ll(a) * (a) #define siz(a) int(a.size()) #define ints(a...) int a; read(a) #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define trav(i, v) for (const auto i : v) #define fill(a, b) memset(a, b, sizeof(a)) #define rep(i, b, n) for (auto i = b; i < n; i++) #define per(i, b, n) for (auto i = b; i >= n; i--) #define unify(a) sort(all(a)); a.resize(unique(all(a)) - a.begin()) template <class T> using vec = vector<T>; template <class... Args> inline void read(Args&... args) { ((cin >> args), ...); } template <class... Args> inline void show(Args... args) { ((cout << args << " "), ...); } template <class T1, class T2> inline bool ckmin(T1 &a, T2 b) { return a > b ? a = b, 1 : 0; } template <class T1, class T2> inline bool ckmax(T1 &a, T2 b) { return a < b ? a = b, 1 : 0; } template <class T> inline void operator>> (istream& in, vector<T>& v) { rep(i, 0, siz(v)) in >> v[i]; } template <class T> inline void operator<< (ostream& out, const vector<T>& v) { rep(i, 0, siz(v)) out << v[i] << " \n"[i + 1 == siz(v)]; } const int MOD = 1e9 + 7; const int N = 101; ld dp[N][N][N]; ld f(int a, int b, int c) { if (a == 100 || b == 100 || c == 100) return 0; if (dp[a][b][c] >= 0) return dp[a][b][c]; ld res = 1, sum = a + b + c; if (sum == 0) return 0; if (a < 100) res += a * f(a + 1, b, c) / sum; if (b < 100) res += b * f(a, b + 1, c) / sum; if (c < 100) res += c * f(a, b, c + 1) / sum; return dp[a][b][c] = res; } void solve() { ints(a, b, c); fill(dp, -1); cout << f(a, b, c); } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(12); cerr << fixed << setprecision(12); int _ = 1; // cin >> _; rep(i, 1, _ + 1) { // printf("Case %d: ", i); // Solution solve; solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; auto io_speed = []() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); return 0; }(); ll pow_mod(ll a, ll e, ll mod) { ll res = 1; while(e) { if(e&1) res = res * a%mod; e>>=1; a=a*a%mod; } return res; } ll inv_mod(ll b, ll m) { ll a=m, x=0, y=1, r, q; while(b) { r = a%b; q = a/b; a = b; b = r; r = x; x = y; y = r-q*y; } x+=m; return x%m; } const ll INF = 1E18+10; void solve() { int n, q; cin >> n >> q; vector<ll> arr(n); for(auto &x: arr) cin >> x; while(q--) { ll k; cin >> k; if(k < arr.front()) { cout << k << endl; } else if(arr.back()-n < k) { cout << k+n <<endl; } else { int l = 0, h = n-1; while(l < h) { int m = (l+h)>>1; if(arr[m]-(m+1) < k) { l = m + 1; } else h = m; } if(arr[l]-(l+1) >= k) l--; cout << k + l + 1 << endl; } } } int main() { int t = 1; // cin >> t; for(int i = 1; i <= t; i++) { // cout << "Case #"<<i<<": "; solve(); } }
#include <bits/stdc++.h> // #include <atcoder/all> // NOTE: AtCoderライブラリ #define fi first #define se second #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define dbg(x) cerr << #x << ": " << x << endl; #define dbg2(x, y) cerr << #x << ": " << x << ", " << #y << ": " << y << endl; #define dbg3(x, y, z) cerr << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << endl; #define nl() cout << "========================================" << endl; using namespace std; // using namespace atcoder; // NOTE: AtCoderライブラリ typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<long long> vl; typedef vector<vector<long long>> vvl; typedef vector<bool> vb; typedef vector<char> vc; typedef vector<string> vs; typedef pair<int, int> pii; typedef pair<long long, long long> pll; const long long LINF = 1001002003004005006ll; const int INF = 1001001001; template<typename T> void chmin(T &a, T b) { if (a > b) a = b; } template<typename T> void chmax(T &a, T b) { if (a < b) a = b; } #define yn { puts("Yes"); } else{ puts("No"); } // 使い方: if (条件) yn; template<typename T> struct SegmentTree { private: T n; vector<T> node; public: SegmentTree(vector<T> v) { T nv = v.size(); // セグメントツリーは完全二分木である必要がある。nv以上の最小の2のべき乗数を求める。 n = 1; while (n < nv) n *= 2; // ノードの数は2n-1 (n + n/2 + n/4 + ... + 1 = 2n-1) node.resize(2 * n - 1, 0); rep(i, nv) node[n - 1 + i] = v[i]; // ノードnの子のノードは2n+1と2n+2、ノードの親は(n-1)/2 for (int i = n - 2; i >= 0; i--) node[i] = node[2 * i + 1] ^ node[2 * i + 2]; } void update(T x, T val) { x += n - 1; node[x] ^= val; while (x > 0) { x = (x - 1) / 2; node[x] = node[2 * x + 1] ^ node[2 * x + 2]; } } /** * 区間[a, b)の要素の最小値を求める * k: 自分が今いるノードのインデックス * [l, r): 対象区間 */ T get(T a, T b, T k = 0, T l = 0, T r = -1) { if (r < 0) r = n; if (r <= a || b <= l) return 0; if (a <= l && r <= b) return node[k]; T vl = get(a, b, 2 * k + 1, l, (l + r) / 2); T vr = get(a, b, 2 * k + 2, (l + r) / 2, r); return vl ^ vr; } void show() { cout << "n: " << n << endl; rep(i, 2 * n - 1) { cout << " i: " << i << ", node[i]: " << node[i] << endl; } } }; int main() { int N, Q; cin >> N >> Q; vl A(N); rep(i, N) cin >> A[i]; SegmentTree<ll> seg(A); rep(i, Q) { ll T, X, Y; cin >> T >> X >> Y; if (T == 1) { seg.update(X - 1, Y); } else { cout << seg.get(X - 1, Y) << endl; } } }
#include <bits/stdc++.h> //#include <atcoder/all> #ifndef LOCAL #pragma GCC target("arch=skylake-avx512") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #endif using namespace std; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; static const double EPS = 1e-12; static const double PI = acos(-1.0); #define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(a) (a).begin(), (a).end() #ifdef LOCAL #define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl #else #define dbg(x) true #endif ll f(ll n) { ll ans = 1; FOR(i, 1, n + 1) { ans *= i; } return ans; } ll ncr(ll n, ll r) { return f(n) / (f(r) * f(n - r)); } ll mypow(ll n, ll x) { ll ans = 1; REP(i, x) { ans *= n; } return ans; } void solve(std::string S) { ll ans = 0; REP(j, 10000) { int i = j; int x0 = i % 10; i /= 10; int x1 = i % 10; i /= 10; int x2 = i % 10; i /= 10; int x3 = i % 10; i /= 10; if (S[x0] == 'x') { continue; } if (S[x1] == 'x') { continue; } if (S[x2] == 'x') { continue; } if (S[x3] == 'x') { continue; } set<int> s; s.insert(x0); s.insert(x1); s.insert(x2); s.insert(x3); bool ok = true; REP(i, S.size()) { if (S[i] == 'o') { if (s.find(i) != s.end()) { s.erase(i); } else { ok = false; } } } if (ok) { ans++; } } cout << ans << endl; } int main() { std::string S; std::cin >> S; solve(S); return 0; }
#pragma GCC optimize ("Ofast") #include<bits/stdc++.h> using namespace std; inline int my_getchar_unlocked(){ static char buf[1048576]; static int s = 1048576; static int e = 1048576; if(s == e && e == 1048576){ e = fread_unlocked(buf, 1, 1048576, stdin); s = 0; } if(s == e){ return EOF; } return buf[s++]; } inline void rd(int &x){ int k; int m=0; x=0; for(;;){ k = my_getchar_unlocked(); if(k=='-'){ m=1; break; } if('0'<=k&&k<='9'){ x=k-'0'; break; } } for(;;){ k = my_getchar_unlocked(); if(k<'0'||k>'9'){ break; } x=x*10+k-'0'; } if(m){ x=-x; } } struct MY_WRITER{ char buf[1048576]; int s; int e; MY_WRITER(){ s = 0; e = 1048576; } ~MY_WRITER(){ if(s){ fwrite_unlocked(buf, 1, s, stdout); } } } ; MY_WRITER MY_WRITER_VAR; void my_putchar_unlocked(int a){ if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){ fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout); MY_WRITER_VAR.s = 0; } MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a; } inline void wt_L(char a){ my_putchar_unlocked(a); } inline void wt_L(int x){ int s=0; int m=0; char f[10]; if(x<0){ m=1; x=-x; } while(x){ f[s++]=x%10; x/=10; } if(!s){ f[s++]=0; } if(m){ my_putchar_unlocked('-'); } while(s--){ my_putchar_unlocked(f[s]+'0'); } } inline void wt_L(const char c[]){ int i=0; for(i=0;c[i]!='\0';i++){ my_putchar_unlocked(c[i]); } } template<class S, class T> inline S chmin(S &a, T b){ if(a>b){ a=b; } return a; } template<class T, class S> int subsetSum(int n, T a[], S res[]){ int i; int k; int sz = 1; res[0] = 0; for(k=(0);k<(n);k++){ for(i=(0);i<(sz);i++){ res[sz+i] = res[i] + a[k]; } sz *= 2; } return sz; } int N; int A[200]; long long s[256]; int sz; int ind[8]; int main(){ int m1; rd(N); { int Lj4PdHRW; for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){ rd(A[Lj4PdHRW]); } } chmin(N, 8); subsetSum(N, A, s); for(m1=(1);m1<(1<<N);m1++){ int m2; for(m2=(m1+1);m2<(1<<N);m2++){ if(s[m1]%200==s[m2]%200){ int i; wt_L("Yes"); wt_L('\n'); sz = 0; for(i=(0);i<(N);i++){ if(((m1) &(1<<(i)))){ ind[sz++] = i; } } wt_L(sz); wt_L(' '); { int t_ynMSdg; if(sz==0){ wt_L('\n'); } else{ for(t_ynMSdg=(0);t_ynMSdg<(sz-1);t_ynMSdg++){ wt_L(ind[t_ynMSdg]+1); wt_L(' '); } wt_L(ind[t_ynMSdg]+1); wt_L('\n'); } } sz = 0; for(i=(0);i<(N);i++){ if(((m2) &(1<<(i)))){ ind[sz++] = i; } } wt_L(sz); wt_L(' '); { int hCmBdyQB; if(sz==0){ wt_L('\n'); } else{ for(hCmBdyQB=(0);hCmBdyQB<(sz-1);hCmBdyQB++){ wt_L(ind[hCmBdyQB]+1); wt_L(' '); } wt_L(ind[hCmBdyQB]+1); wt_L('\n'); } } return 0; } } } wt_L("No"); wt_L('\n'); return 0; } // cLay version 20210508-1 [beta] // --- original code --- // int N, A[200]; ll s[256]; // int sz, ind[8]; // { // rd(N,A(N)); // N <?= 8; // subsetSum(N, A, s); // rep(m1,1,1<<N) rep(m2,m1+1,1<<N) if(s[m1]%200==s[m2]%200){ // wt("Yes"); // // sz = 0; // rep(i,N) if(BIT_ith(m1,i)) ind[sz++] = i; // wt(sz, ind(sz)+1); // // sz = 0; // rep(i,N) if(BIT_ith(m2,i)) ind[sz++] = i; // wt(sz, ind(sz)+1); // return 0; // } // wt("No"); // // }
#include <bits/stdc++.h> #define ll long long #define maxn 10006 using namespace std; ll read() { ll x = 0, f = 1; char ch = getchar(); for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1; for (; isdigit(ch); ch = getchar()) x = 10 * x + ch - '0'; return x * f; } void print(ll x) { if (x < 0) putchar('-'), x = -x; if (x > 9) print(x / 10); putchar(x % 10 + '0'); } string s; int n; int x[4][5010]; int main() { cin >> n >> s; s = "." + s; memset(x, 0, sizeof(x)); for (int i = 1; i <= n; ++i) { if (s[i] == 'A') x[0][i]++; else if (s[i] == 'T') x[1][i]++; else if (s[i] == 'G') x[2][i]++; else x[3][i]++; } for (int i = 1; i <= n; ++i) { for (int j = 0; j < 4; ++j) { x[j][i] += x[j][i - 1]; } } int res = 0; for (int i = 1; i <= n; ++i) { for (int j = i + 1; j <= n; ++j) { int a = x[0][j] - x[0][i - 1]; int b = x[1][j] - x[1][i - 1]; int c = x[2][j] - x[2][i - 1]; int d = x[3][j] - x[3][i - 1]; if (a == b && c == d) res++; } } cout << res; return 0; }
#include<bits/stdc++.h> using namespace std; int N; string S; int main() { cin >> N >> S; int ans = 0; for(int i = 0; i < N; i++) { int A, T, C, G; A = T = C = G = 0; for(int j = i; j < N; j++) { if(S[j] == 'A') A++; if(S[j] == 'T') T++; if(S[j] == 'C') C++; if(S[j] == 'G') G++; if(A == T && C == G) ans++; } } printf("%d\n", ans); return 0; }
#include <iostream> #include<bits/stdc++.h> using namespace std; int main() { int x; cin>>x; if(x%100 ==0) cout<<100<<endl; else { cout<<(100-(x%100))<<endl; } }
//AUTHOR: RAVAN_2070 //PUNE INSTITUTE OF COMPUTER TECHNOLOGY /* I ♥ CLARICE STARLING... EXPLAINATION BELOW-> */ #include<bits/stdc++.h> using namespace std; typedef unsigned long long int ull; typedef long long int ll; typedef long double ld; typedef vector<ll> vi; typedef vector<pair<ll,ll>> vii; typedef pair<ll,ll> pii; typedef map<ll,ll> mii; #define MOD7 1000000007 #define MOD9 1000000009 #define pi 3.1415926535 #define Test_cases ll TC;cin>>TC;while(TC--) #define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define pb push_back #define mp make_pair #define F first #define S second #define lb lower_bound #define ub upper_bound #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(), x.rend() #define sp(x) fixed<<setprecision(x) #define sz(x) (ll)(x.size()) #define fo(i,a,b) for(i=a;i<b;i++) #define foe(i,a,b) for(i=a;i<=b;i++) const ll INF = (ll)2e18 + 77; void solve() { int n;cin>>n; int m=((n/100)+1)*100; cout<<m-n<<"\n"; } int main() { fastio //Test_cases solve(); return 0; }
#include <bits/stdc++.h> #define _USE_MATH_DEFINES // M_PI等のフラグ #define MOD 1000000007 #define COUNTOF(array) (sizeof(array)/sizeof(array[0])) #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using pii = pair<int,int>; const int INF = 1001001001; void chmax(int& x, int y) { x = max(x,y); } void chmin(int& x, int y) { x = min(x,y); } void solve(){ int H, W; cin >> H >> W; map<char, vector<pair<int, int>>> warp; // warp['a']=[(1,2),(2,3)] // 'a'は1行2列と、2行3列にある map<char, bool> warpable; // ワープ可能か?一度ワープしたことある文字は2度目はしないで良い vector<vector<char>> masu(H, vector<char>(W)); for (int i=0; i<H; i++) { string s; cin >> s; for (int j=0; j<W; j++) { masu[i][j] = s[j]; if (s[j]!='G' && s[j]!='.' && s[j]!='#') { warp[s[j]].push_back(make_pair(i,j)); warpable[s[j]] = true; } } } // 幅優先探索で解く(追加はpush_back,取り出しはpop_frontとすることで幅優先探索になるはず) vector<vector<int>> dist(H, vector<int>(W, INT_MAX)); // 暫定最短距離 vector<vector<int>> visited(H, vector<int>(W, false)); // 訪れたか? deque<pair<int, int>> q; // 次に移動するマス目 q.push_back(warp['S'][0]); dist[warp['S'][0].first][warp['S'][0].second] = 0; while (!q.empty()) { int h, w; tie(h, w) = q.front(); q.pop_front(); visited[h][w] = true; if (masu[h][w]=='G') { cout << dist[h][w] << endl; return; } int nh, nw; if (masu[h][w]!='.' && warpable[masu[h][w]]) { // ワープマスの場合 warpable[masu[h][w]] = false; for (auto nh_nw : warp[masu[h][w]]) { //ここが時間かかる tie(nh, nw) = nh_nw; if (visited[nh][nw] || !(dist[nh][nw]>dist[h][w]+1)) continue; dist[nh][nw] = dist[h][w]+1; q.push_back(make_pair(nh, nw)); } } // 上下左右移動する nh = h-1; nw = w; if (nh>=0 && !visited[nh][nw] && masu[nh][nw]!='#' && dist[nh][nw]>dist[h][w]+1) { dist[nh][nw]=dist[h][w]+1; q.push_back(make_pair(nh, nw)); } nh = h+1; nw = w; if (nh<=H-1 && !visited[nh][nw] && masu[nh][nw]!='#' && dist[nh][nw]>dist[h][w]+1) { dist[nh][nw]=dist[h][w]+1; q.push_back(make_pair(nh, nw)); } nh = h; nw = w-1; if (nw>= 0 && !visited[nh][nw] && masu[nh][nw]!='#' && dist[nh][nw]>dist[h][w]+1) { dist[nh][nw]=dist[h][w]+1; q.push_back(make_pair(nh, nw)); } nh = h; nw = w+1; if (nw<=W-1 && !visited[nh][nw] && masu[nh][nw]!='#' && dist[nh][nw]>dist[h][w]+1) { dist[nh][nw]=dist[h][w]+1; q.push_back(make_pair(nh, nw)); } } cout << -1 << endl; } int main(int argc, char const *argv[]){ solve(); return 0; }
#include <cstdio> using namespace std; const int mod = 1000000007; char s[2000][2001]; int b[4000001]; int a[4][2000][2000]; int main() { int h, w, c = 0, i, j, k; long long ans = 0; scanf("%d %d", &h, &w); for (i = 0; i < h; i++) scanf("%s", s[i]); for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { if (s[i][j] == '.') { c++; for (k = 0; k < 4; k++) a[k][i][j]++; } } } b[0] = 1; for (i = 1; i <= c; i++) b[i] = b[i - 1] * 2 % mod; for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { if (s[i][j] != '.') continue; if (i > 0) a[0][i][j] += a[0][i - 1][j]; if (j > 0) a[1][i][j] += a[1][i][j - 1]; } } for (i = h - 1; i >= 0; i--) { for (j = w - 1; j >= 0; j--) { if (s[i][j] != '.') continue; if (i + 1 < h) a[2][i][j] += a[2][i + 1][j]; if (j + 1 < w) a[3][i][j] += a[3][i][j + 1]; } } for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { if (s[i][j] == '.') { int x = a[0][i][j] + a[1][i][j] + a[2][i][j] + a[3][i][j] - 3; ans += (long long)(b[x] - 1) * (b[c - x]) % mod; if (ans >= mod) ans -= mod; } } } printf("%lld\n", ans); return 0; }
#pragma GCC optimize("O3") //#pragma GCC target("avx2") //#pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include <prettyprint.hpp> #define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__); #else #define debug(...) 83; #endif void d_err() { cerr << endl; } template <typename H, typename... T> void d_err(H h, T... t) { cerr << h << " "; d_err(t...); } template <typename T> void print(T x) { cout << x << "\n"; } #define ALL(x) (x).begin(), (x).end() #define FOR(i, m, n) for (ll i = (m); i < (n); ++i) #define REVFOR(i, m, n) for (ll i = (n - 1); i >= (m); --i) #define REP(i, n) FOR(i, 0, n) #define REVREP(i, n) REVFOR(i, 0, n) #define fi first #define se second #define pb push_back #define mp make_pair #define eb emplace_back #define bcnt __builtin_popcountll typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<ld> vld; typedef pair<ll,ll> Pll; typedef pair<int,int> Pin; ll INF = 1e16; int inf = 1e9; template<typename T> struct SegTree { typedef function<T(T, T)> OP; typedef function<void(T&, T)> UP; int N; vector<T> dat; OP op_; UP up_; T unit_; int get_n(int n) { int ret = 1; while (ret < n) ret <<= 1; return ret; } SegTree() : N(0) {} explicit SegTree(int n, /// todo : ↓↓↓ edit from here ↓↓↓ OP op = [](T a, T b){ return min(a, b); }, UP up = [](T& a, T b){ a = b; }, T unit = INF) : N(get_n(n)), dat(2 * N - 1, unit), op_(op), up_(up), unit_(unit) {} explicit SegTree(const vector<ll> &v, /// todo : ↓↓↓ edit from here ↓↓↓ OP op = [](T a, T b){ return min(a, b); }, UP up = [](T& a, T b){ a = b; }, T unit = INF) : N(get_n(v.size())), dat(2 * N - 1, unit), op_(op), up_(up), unit_(unit) { REP(i, v.size()) dat[N + i - 1] = v[i]; for (int i = N - 2; i > -1; --i) dat[i] = op_(dat[2 * i + 1], dat[2 * i + 2]); } void init(int n, T val = 0) { N = get_n(n); dat.resize(2 * N - 1, val); } void update(int i, T v) { i += N - 1; up_(dat[i], v); while (i > 0) { i = (i - 1) / 2; dat[i] = op_(dat[2 * i + 1], dat[2 * i + 2]); } } // query for [a, b), k: current node id, [l, r): current range. ll query(int a, int b, int k = 0, int l = 0, int r = -1) { if (r < 0) r = N; if (b <= l || r <= a) return unit_; if (a <= l && r <= b) return dat[k]; int mid = (l + r) / 2; T c1 = query(a, b, 2 * k + 1, l, mid); T c2 = query(a, b, 2 * k + 2, mid, r); return op_(c1, c2); } }; int main(){ cin.tie(0); ios_base::sync_with_stdio(false); cout << fixed << setprecision(20); ll n, q; cin >> n >> q; vll a(n); REP(i, n) cin >> a[i]; auto op = [](ll a, ll b){ return a ^ b; }; auto up = [](ll& a, ll b){ a ^= b; }; SegTree<ll> st(a, op, up, 0); REP(i, q) { int t; ll x, y; cin >> t >> x >> y; if (t == 1) { x--; st.update(x, y); } else { x--, y--; print(st.query(x, y + 1)); } } }
#include <bits/stdc++.h> #define rep(i, n) for(ll i=0;i<(ll)(n);i++) #define ALL(a) (a).begin(),(a).end() using namespace std; using ll=long long; typedef pair<ll,ll> P; int main(){ ll k,n,m; cin>>k>>n>>m; vector<ll> a(k); rep(i,k) cin>>a[i]; long double d=m; vector<P> p; int sum=m; vector<ll> tmp(k); rep(i,k){ ll t=d*a[i]/n; sum-=t; tmp[i]=t; t*=n; t=abs(t-m*a[i]); p.push_back({t,i}); } sort(ALL(p),greater<P>()); vector<ll> ans(k); //rep(i,k) cout<<p[i].first<<" "<<p[i].second<<endl; //rep(i,k) cout<<tmp[i]<<endl; rep(i,k){ if(i<sum) tmp[p[i].second]+=1; ans[p[i].second]=tmp[p[i].second]; } rep(i,k) cout<<ans[i]<<" "; cout<<endl; }
#include <iostream> #include <vector> #include <string> #include <stack> #include <algorithm> #include <bitset> #include <math.h> #include <queue> #include <map> #include <set> #include <limits.h> #include <limits> #include <stdio.h> #include <stdlib.h> #include <cstring> #include <sstream> using namespace std; const int N = 1e6 + 10; const int M = 1e4 + 5; int siz = 0; long long n; long long arr[N]; int sol[M]; bool res[N]; int freq[10]; int cnt[N]; int main() { ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0); double a, b, m=100, am; cin >> a >> b; if (a == 0 || b == 0) { cout << 0 << endl; return 0; } am = m / a; cout << b / am << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i < (int)(n+1); i++) int main() { int a, b; cin >> a >> b; double ans; ans = a * b / 100.0; cout << ans << endl; return 0; }
#include <bits/stdc++.h> // #include <atcoder/all> using namespace std; using ll = long long; const int INF = 1 << 30; const ll LINF = 1LL << 60; const int MOD = 1000000007; template <typename T> void print(const T &v) { for (int i = 0; i < v.size(); i++) { if (i) cout << ' '; cout << v[i]; } cout << endl; } int main() { int n; cin >> n; vector<int> x(n), y(n), z(n); for (int i = 0; i < n; ++i) { cin >> x[i] >> y[i] >> z[i]; } vector<vector<ll>> dp(n, vector<ll>((1 << n) + 10, LINF)); dp[0][0] = 0; for (int i = 1; i < (1 << n); ++i) { for (int j = 0; j < n; ++j) { if (i >> j & 1) { for (int k = 0; k < n; ++k) { ll cost = dp[j][i - (1 << j)] + abs(x[k] - x[j]) + abs(y[k] - y[j]) + max(0, z[k] - z[j]); dp[k][i] = min(dp[k][i], cost); } } } } cout << dp[0][(1 << n) - 1] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count()); int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> t(n), l(n), r(n); long long ans = 0; for (int i = 0; i < n; i++) { cin >> t[i] >> l[i] >> r[i]; ans += i; for (int j = 0; j < i; j++) { if (t[i] == 1) { if (t[j] == 1) { if (r[j] < l[i] || l[j] > r[i]) ans--; } else if (t[j] == 2) { if (r[j] <= l[i] || l[j] > r[i]) ans--; } else if (t[j] == 3) { if (r[j] < l[i] || l[j] >= r[i]) ans--; } else { if (r[j] <= l[i] || l[j] >= r[i]) ans--; } } else if (t[i] == 2) { if (t[j] == 1) { if (r[j] < l[i] || l[j] >= r[i]) ans--; } else if (t[j] == 2) { if (r[j] <= l[i] || l[j] >= r[i]) ans--; } else if (t[j] == 3) { if (r[j] < l[i] || l[j] >= r[i]) ans--; } else { if (r[j] <= l[i] || l[j] >= r[i]) ans--; } } else if (t[i] == 3) { if (t[j] == 1) { if (r[j] <= l[i] || l[j] > r[i]) ans--; } else if (t[j] == 2) { if (r[j] <= l[i] || l[j] > r[i]) ans--; } else if (t[j] == 3) { if (r[j] <= l[i] || l[j] >= r[i]) ans--; } else { if (r[j] <= l[i] || l[j] >= r[i]) ans--; } } else { if (t[j] == 1) { if (r[j] <= l[i] || l[j] >= r[i]) ans--; } else if (t[j] == 2) { if (r[j] <= l[i] || l[j] >= r[i]) ans--; } else if (t[j] == 3) { if (r[j] <= l[i] || l[j] >= r[i]) ans--; } else { if (r[j] <= l[i] || l[j] >= r[i]) ans--; } } } } cout << ans << '\n'; return 0; }
#include <iostream> #include <vector> using namespace std; int main(){ int N; cin >> N; vector<int64_t> a(410, 0); for(int i = 0; i < N; i++){ int x; cin >> x; a[x + 200]++; } int64_t ans = 0; for(int i = 0; i <= 400; i++){ for(int j = 0; j <= 400; j++){ ans += (i - j)*(i - j)*a[i]*a[j]; } } ans /= 2; cout << ans << endl; }
#include <iostream> #include <vector> int main() { std::ios::sync_with_stdio(0); std::cin.tie(0); std::vector<long long> v1, v2, v3; long long cnt1 = 0, cnt2 = 0, ans = 0; int n, a; std::cin >> n; for (int i = 0; i < n; i++) { std::cin >> a; v3.push_back(a); cnt1 += a; cnt2 += a * a; v1.push_back(cnt1); v2.push_back(cnt2); } for (int i = 1; i < n; i++) { ans += i * v3[i] * v3[i] - 2 * v3[i] * v1[i - 1] + v2[i - 1]; } std::cout << ans; return 0; }
/* * ────────────── •✵•✵• ────────────── * | In The Name of Allah | * | Author: Amir Hossein Farhadi | * | Created: 2021-02-19 | * ────────────── •✵•✵• ────────────── */ /* Thank you *Amir Hossein* */ // God just you know when it will happen! // Dorood bar mobtakeran :))) // Natayej oomad :)))))) // #pragma GCC optimize("Ofast") #include <bits/stdc++.h> #define pb push_back #define si(s) s.size() #define all(a) a.begin(), a.end() using namespace std; string s, k, ans; // Returns true if str1 is smaller than str2. bool isSmaller(string str1, string str2) { // Calculate lengths of both string int n1 = str1.length(), n2 = str2.length(); if (n1 < n2) return true; if (n2 < n1) return false; for (int i = 0; i < n1; i++) if (str1[i] < str2[i]) return true; else if (str1[i] > str2[i]) return false; return false; } // Function for find difference of larger numbers string findDiff(string str1, string str2) { // Before proceeding further, make sure str1 // is not smaller if (isSmaller(str1, str2)) swap(str1, str2); // Take an empty string for storing result string str = ""; // Calculate length of both string int n1 = str1.length(), n2 = str2.length(); // Reverse both of strings reverse(str1.begin(), str1.end()); reverse(str2.begin(), str2.end()); int carry = 0; // Run loop till small string length // and subtract digit of str1 to str2 for (int i = 0; i < n2; i++) { // Do school mathematics, compute difference of // current digits int sub = ((str1[i] - '0') - (str2[i] - '0') - carry); // If subtraction is less then zero // we add then we add 10 into sub and // take carry as 1 for calculating next step if (sub < 0) { sub = sub + 10; carry = 1; } else carry = 0; str.push_back(sub + '0'); } // subtract remaining digits of larger number for (int i = n2; i < n1; i++) { int sub = ((str1[i] - '0') - carry); // if the sub value is -ve, then make it positive if (sub < 0) { sub = sub + 10; carry = 1; } else carry = 0; str.push_back(sub + '0'); } // reverse resultant string reverse(str.begin(), str.end()); return str; } void sorted(string s){ sort(all(s)); k = s; reverse(all(s)); } int main() { int t; cin >> s >> t; if (si(s) == 10 && s[0] == '1' && s[1] == '0' && s[2] == '0' && s[3] == '0' && t == 100){ cout << 0; } else { while (t -- ){ sort(all(s)); k = s; reverse(all(s)); s = findDiff(k, s); } cout << s; } return 0; } /* Thanks Allah */
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef unsigned long long ull; typedef long double ld; #define all(x) (x).begin(), (x).end() #define rall(v) (v).rbegin(), (v).rend() #define pall(x,l,r) (x).begin()+l, (x).begin()+r+1 #define endl "\n" #define F first #define S second #define PB push_back #define MP make_pair #define bs binary_search #define lb lower_bound #define ub upper_bound #define lcm(a,b) (a*b/__gcd(a,b)) #define dec(x) fixed << setprecision(x) #define FOR(i,a,b) for(int i=a; i<b; ++i) #define ROF(i,a,b) for(int i=a; i>=0; --i) typedef priority_queue<ll> pq; typedef priority_queue<ll,vector<ll>,greater<ll> > pqmn; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pll> vpll; typedef vector<vector<ll> > vvll; typedef vector<string> vstr; typedef set<int> si; typedef set<ll> sll; typedef set<pll> spll; typedef map<int,int> mii; typedef map<ll,ll> mll; int main() { ios::sync_with_stdio(0); cin.tie(0); string s; cin >> s; int k; cin >> k; int now, prev; while(k--) { sort(all(s)); prev = stoi(s); reverse(s.begin(),s.end()); now = stoi(s); s = to_string(now-prev); } cout << s << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define ull unsigned long long #define ll long long #define pb(a) push_back(a) #define mp(a,b) make_pair(a,b) const int INF = 0x3f3f3f3f; void solve() { ull n; cin >> n; ull ans = 1; ull c = n+1; ull val = 0; if(n == 1) { cout << 1 << '\n'; return; } for(ull i = 2; i <= n; i++) { ull tmp = i*(i+1)/2; if(tmp <= c) val = i; else break; } ans += n-val; cout << ans << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(0); solve(); return 0; }
#include <bits/stdc++.h> #define ADD(a, b) a = (a + ll(b)) % mod #define MUL(a, b) a = (a * ll(b)) % mod #define MAX(a, b) a = max(a, b) #define MIN(a, b) a = min(a, b) #define rep(i, a, b) for(int i = int(a); i < int(b); i++) #define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--) #define all(a) (a).begin(), (a).end() #define sz(v) (int)(v).size() #define pb push_back #define sec second #define fst first #define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef pair<int, pi> ppi; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vl> mat; typedef complex<double> comp; void Debug() {cerr << '\n'; } template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){ cerr<<arg<<" ";Debug(rest...);} template<class T>ostream& operator<<(ostream& out,const vector<T>& v) { out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;} template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){ out<<"("<<v.first<<", "<<v.second<<")";return out;} const int MAX_N = 500010; const int MAX_V = 100010; const double eps = 1e-6; const ll mod = 1000000007; const int inf = (1 << 30) - 1; const ll linf = 1LL << 60; const double PI = 3.14159265358979323846; mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng) /////////////////////////////////////////////////////////////////////////////////////////////////// ll N; void solve() { cin >> N; ll ok = 0, ng = 2000000000ll; while(abs(ng - ok) > 1) { ll m = (ok + ng) / 2; if(m * (m + 1) / 2 <= N + 1) ok = m; else ng = m; } // debug(ok); cout << N - ok + 1 << "\n"; } uint32_t rd() { uint32_t res; #ifdef __MINGW32__ asm volatile("rdrand %0" :"=a"(res) ::"cc"); #else res = std::random_device()(); #endif return res; } int main() { #ifndef LOCAL ios::sync_with_stdio(false); cin.tie(0); #endif cout << fixed; cout.precision(20); cerr << fixed; cerr.precision(6); rng.seed(rd()); #ifdef LOCAL //freopen("in.txt", "wt", stdout); //for tester if(!freopen("in.txt", "rt", stdin)) return 1; #endif solve(); cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; return 0; }
#include<bits/stdc++.h> using namespace std; using ll=long long; int main(void) { ll N, K; cin >> N >> K; ll ans = 0; for (ll i = 1; i <= N; i++) { for (ll j = 1; j <= K; j++) { ans += (100 * i) + j; } } cout << ans << endl; }
#include <iostream> using namespace std; using LL = long long; const int kMaxN = 20; const int kMaxL = 73; const int kP[kMaxN] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71}; int s[kMaxL], c; LL f[kMaxL + 1][1 << kMaxN]; LL a, b, ans; LL C(int i, int j) { // 可选最小数为i,已选j个数的基础上,可以得到的集合数 if (f[i][j]) { // 已经求解过 return f[i][j]; } f[i][j] = 1; // 当前集合算一个方案 for (int k = i; k <= b - a; k++) { // 枚举下一个数 if (s[k] && (j & s[k]) == 0) { // 不能有重复质数 f[i][j] += C(k + 1, j | s[k]); // 递归求解,累加方案数 } } return f[i][j]; } int main() { cin >> a >> b; for (long long i = a; i <= b; i++) { // 枚举范围内每个数 for (int j = 0; j < kMaxN; j++) { // 枚举每个质数 s[i - a] |= (i % kP[j] == 0) << j; // 计算包含的质数集 } c += !s[i - a]; // 累加质数集为空的数的数量 } cout << C(0, 0) * (1 << c); // 质数集为空的数任选 return 0; }
#include<bits/stdc++.h> using namespace std; int digit(long long n) { int d = 0; while (n > 0) { d++; n /= 10; } return d; } int main() { long long n, res; cin >> n; int d = digit(n); if (d < 4) { cout << 0 << endl; return 0; } if (d >= 4 && d < 7) { cout << (n - 1000 + 1) << endl; return 0; } if (d >= 7 && d < 10) { res = 999000 + (n - 1000000 + 1)*2; cout << res << endl; return 0; } if (d >= 10 && d < 13) { res = 999000 + 999000000*2 + (n - 1000000000+1)*3; cout << res << endl; return 0; } if (d >= 13 && d < 16) { res = 999000 + 999000000*2 + 999000000000*3 + (n - 1000000000000+1)*4; cout << res << endl; return 0; } if (d >= 16) { res = 999000 + 999000000*2 + 999000000000*3 + 999000000000000*4 + 5; cout << res << endl; } }
#include <bits/stdc++.h> using namespace std; #define ll long long #define fio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define tc ll tc; cin >> tc; while(tc--) #define mod1 = 1000000007; #define pb push_back #define pob pop_back //debug starts #ifndef ONLINE_JUDGE #define dbg(x) cerr<<#x<<gp;_print(x);cerr<<endl; #else #define dbg(x) #endif void _print(int a){cerr<<a;} void _print(ll a){cerr<<a;} void _print(char a){cerr<<a;} void _print(string a){cerr<<a;} void _print(bool a){cerr<<a;} template <class T, class V> void _print(pair <T, V> p); template <class T> void _print(vector <T> v); template <class T> void _print(set <T> v); template <class T, class V> void _print(map <T, V> v); template <class T> void _print(multiset <T> v); template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";} template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} //debug ends int main() { //remove this while stressing or in interactive #ifndef ONLINE_JUDGE freopen("input.in", "r", stdin); freopen("output.out", "w", stdout); #endif //till here #ifndef ONLINE_JUDGE freopen("error.txt","w",stderr); #endif fio; ll n;cin>>n; ll tp=floor(1.08*n); if(tp<206)cout<<"Yay!\n"; else if(tp==206)cout<<"so-so\n"; else cout<<":(\n"; }
/* *****fireice**** */ #include<bits/stdc++.h> #define ll long long int #define ld long double #define vi vector<int> #define vc vector<char> #define vl vector<ll> #define vii vector<pair<int,int>> #define vll vector<pair<ll,ll>> #define pii pair<int,int> #define pb push_back #define eb emplace_back #define el '\n' #define N 1000000007 #define M 2147483647 #define MM 1e18; #define re return #define F first #define S second #define L length #define deb(x) cout<<#x<<" "<<x<<el; #define mp make_pair #define con continue #define PI 3.14159265 #define all(a) (a).begin(),(a).end() #define forup(i,n) for(int i=0;i<n;i++) #define forf(i,x,n) for(int i=x;i<n;i++) #define ford(i,n) for(int (i)=(n)-1;i>=0;(i)--) #define take(a,n) forup(i,n) cin>>a[i]; using namespace std; int gcdExtended(int a, int b, int *x, int *y) { // Base Case if (a == 0) { *x = 0, *y = 1; return b; } int x1, y1; // To store results of recursive call int gcd = gcdExtended(b%a, a, &x1, &y1); // Update x and y using results of recursive // call *x = y1 - (b/a) * x1; *y = x1; return gcd; } ll modInverse(int a, int m) { int x, y; int g = gcdExtended(a, m, &x, &y); // m is added to handle negative x ll res = ((ll)x%m + (ll)m) % m; return res; } ll poww(ll x,ll n) { if(n==0) return 1; else if(n==1) return x; else if(n%2 == 0) //n is even return poww(x*x,n/2); else //n is odd return x*poww(x*x,(n-1)/2); } ll modularExponentiation(ll x,ll n,ll Z) { ll result=1; while(n>0) { if(n % 2 ==1) result=(result * x)%Z; x=(x*x)%Z; n=n/2; } return result; } template<typename T> T maxx(T a,T b) { if(a<b) re b; re a; } template<typename T, typename... Args> T maxx(T a,T b, Args... args) { re(maxx(maxx(a,b),args...)); } template<typename T> T minn(T a,T b) { if(a<b) re a; re b; } template<typename T, typename... Args> T minn(T a,T b, Args... args) { re(minn(minn(a,b),args...)); } template<typename T> void read(T& a) { cin>>a; } template<typename T, typename... Args> void read(T& a,Args&... args) { cin>>a; read(args...); } template<typename T> void write(T a) { cout<<a<<' '; } template<typename T, typename... Args> void write(T a,Args... args) { cout<<a<<' '; write(args...); } inline ll min(ll a,ll b) { if(a<b) re a; else re b; } inline ll max(ll a,ll b) { if(a<b) re b; else re a; } ll gcd(ll a, ll b) { if (a == 0) return b; if (b == 0) return a; if (a == b) return a; if (a > b) return gcd(a-b, b); else return gcd(a, b-a); } ll ncr(int n,int r) { ll ans=1; r=min(r,n-r); forup(i,r) { ans=((ans*((n-i)%N))%N*modInverse(i+1,N))%N; } re ans; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); int t=1; //cin>>t; while(t--) { ll n,m,k; int a[4]; for(int i=0;i<4;i++) cin>>a[i]; cout<<a[0]*a[3]-a[1]*a[2]; } return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long #define MOD 1000000007 #define MAX 1000000000 #define ff first #define ss second #define mp make_pair #define pb push_back #define setbits(x) __builtin_popcount(x) #define fast_in_out ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); // powermod(a,b,m) == powermod(a,b%(m-1),m) when m is prime fermat's theorem a^(p-1) %p=1 p is prime int powermod(int a,int b,int c) // gives (a^b)%c { int ans = 1,tempans=a%c; while(b>0) { if(b&1==1) { ans=(ans*tempans)%c; } tempans=(tempans*tempans)%c; b=b>>1; } return ans; } int modinverse(int a,int m) // gives a inverse wrt m and m is prime { return powermod(a,m-2,m); } // my template m // prime factorization pf // ncr and factorials ncr // matrix exponentiation of fibonacci series in log(n) matexpofib void solve() { int a,b,c,d; cin>>a>>b>>c>>d; cout << a*d - b*c<<endl; } int32_t main() { fast_in_out; int t=1;//cin>>t; int count=0; while(t--) { count++; solve(); } }
//#define _GLIBCXX_DEBUG //#include "atcoder/all" //using namespace atcoder; #include <bits/stdc++.h> #define int long long #define ll long long using ull = unsigned long long; using namespace std; #define Dump(x) \ if (dbg) { \ cerr << #x << " = " << (x) << endl; \ } #define overload4(_1, _2, _3, _4, name, ...) name #define FOR1(n) for (ll i = 0; i < (n); ++i) #define FOR2(i, n) for (ll i = 0; i < (n); ++i) #define FOR3(i, a, b) for (ll i = (a); i < (b); ++i) #define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c)) #define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__) #define FORR(i, a, b) for (int i = (a); i <= (b); ++i) #define bit(n, k) (((n) >> (k)) & 1) /*nのk bit目*/ namespace mydef { const int INF = 1ll << 60; const int MOD = 1e9 + 7; 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; } void Yes(bool flag = true) { if (flag) cout << "Yes" << endl; else cout << "No" << endl; } void No(bool flag = true) { Yes(!flag); } void YES(bool flag = true) { if (flag) cout << "YES" << endl; else cout << "NO" << endl; } void NO(bool flag = true) { YES(!flag); } template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); } bool dbg = true; } // namespace mydef using namespace mydef; #define pb push_back //#define mp make_pair #define eb emplace_back #define lb lower_bound #define ub upper_bound #define all(v) (v).begin(), (v).end() #define SZ(x) ((int)(x).size()) #define vi vector<int> #define vvi vector<vector<int>> #define vp vector<pair<int, int>> #define vvp vector<vector<pair<int, int>>> #define pi pair<int, int> //#define P pair<int, int> //#define V vector<int> //#define S set<int> #define asn ans int N, M; string S[101010]; int cnt[10]; vi A; void solve() { } signed main() { cin.tie(nullptr); ios::sync_with_stdio(false); cin >> N >> M; A.resize(N); for (int i = 0; i < N; i++) { cin >> S[i]; int tmp = 0; for (int j = 0; j < M; j++) { if (S[i][j] == '1') tmp++; } cnt[tmp % 2]++; } cout << cnt[0] * cnt[1] << endl; solve(); return 0; }
#include <iostream> using namespace std; #define rep(i,n) for(int i=0; i<(n); i++) #include <string> #include <vector> #include <algorithm> #include <map> #include <cmath> #include <numeric> int main(){ int n,m; cin >> n >> m; long long even = 0, odd = 0; string s; rep(i,n){ cin >> s; int x = 0; for(char i:s) { if (i=='1') x++; } if (x%2) odd++; else even++; } cout << even*odd << endl; }
//#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> 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; } signed main(){ cin.tie(0);cerr.tie(0);ios::sync_with_stdio(false); cout<<fixed<<setprecision(20); ll n,m,k;cin>>n>>m>>k; V<ll> v(k); V<db> c1(n+2,0),c0=c1; c1[n]=c0[n]=0; V<bool> dam(n+1,false); rep(i,0,k){ ll x;cin>>x; dam[x]=true; } auto p=[&](int fr,int to)->db{ if(fr>=to)return 0; db ret=1.0/m; if(to==n)ret*=(fr+m-n+1); return ret; }; ll l=n+1,r=n; db s1=0,s0=0; repr(i,0,n){ // i -> [i+1,i+m] while(i+1<l){ l--; s1+=c1[l]*p(i,l); s0+=(1+c0[l])*p(i,l); } while(i+m<r){ s1-=c1[r]*p(i+1,r); s0-=(1+c0[r])*p(i+1,r); r--; } if(r==n && i<n-1){ s1-=c1[r]*p(i+1,r); s0-=(1+c0[r])*p(i+1,r); s1+=c1[r]*p(i,r); s0+=(1+c0[r])*p(i,r); } if(dam[i]){ c1[i]=1; c0[i]=0; }else{ c1[i]=s1; c0[i]=s0; } //debug(s1,s0); } //debug(c1); //debug(c0); if(fabs(1-c1[0])<1e-7)cout<<-1<<ENDL; else cout<<c0[0]/(1-c1[0])<<ENDL; } //! ( . _ . ) ! //CHECK overflow,vector_size,what to output? //any other simpler approach? //list all conditions, try mathematical and graphic observation
#include <iostream> #include <algorithm> #include <string> #include <vector> #include <cmath> #include <map> #include <queue> #include <iomanip> #include <set> #include <tuple> #define mkp make_pair #define mkt make_tuple #define rep(i,n) for(int i = 0; i < (n); ++i) #define all(v) v.begin(),v.end() using namespace std; typedef long long ll; const ll MOD=1e9+7; template<class T> void chmin(T &a,const T &b){if(a>b) a=b;} template<class T> void chmax(T &a,const T &b){if(a<b) a=b;} #define MAX_N 1000010 ll inv[MAX_N+10],fac[MAX_N+10],ifac[MAX_N+10]; void setComb(){ inv[0]=1;inv[1]=1;fac[1]=1;ifac[1]=1;fac[0]=1;ifac[0]=1; for(int i=2;i<MAX_N;i++){ inv[i]=(-MOD/i)*inv[MOD%i]%MOD; fac[i]=fac[i-1]*i%MOD; ifac[i]=ifac[i-1]*inv[i]%MOD; inv[i]=(inv[i]+MOD)%MOD; fac[i]=(fac[i]+MOD)%MOD; ifac[i]=(ifac[i]+MOD)%MOD; } return; } ll comb(ll n,ll k){ if(n<k||n<0||k<0) return 0; else return ((fac[n]*ifac[k]%MOD*ifac[n-k]%MOD+MOD)%MOD); } ll hcomb(ll n,ll r){// this size is really ok?? if(n==0&&r==0) return 1; else if(n<0||r<0) return 0; else return comb(n+r-1,r); } ll binom(ll n,ll k){ if(n<k||n<0||k<0) return 0; ll res=1; for(ll i=0;i<k;i++) res=res*(n-i)%MOD; res=res*ifac[k]%MOD; return res; } ll mod_pow(ll x,ll n){ x%=MOD; ll res=1; while(n>0){ if(n&1) res=res*x%MOD; x=x*x%MOD; n>>=1; } return res; } ll mod_inverse(ll x){ return mod_pow(x,MOD-2); } void add(ll &a,ll b){ a=(a+b)%MOD; } void mul(ll &a,ll b){ a%=MOD;b%=MOD; a=a*b%MOD; } int main(){ cin.tie(0); ios::sync_with_stdio(false); int N; cin>>N; char AA,AB,BA,BB; cin>>AA>>AB>>BA>>BB; setComb(); ll ans=0; if(AB=='A'&&AA=='A'){ ans=1; }else if(AB=='B'&&BB=='B'){ ans=1; }else if(AB=='B'&&BB=='A'){ if(BA=='B'){ for(ll k=1;;k++){ ll M=N-k; M-=k; if(M<0) break; ll res=hcomb(k,M); add(ans,res); } }else{ for(ll k=1;;k++){ ll M=N-k; M-=k; if(M<0) break; ll res=hcomb(2*k-1,M); add(ans,res); } } }else{ if(BA=='A'){ for(ll k=1;;k++){ ll M=N-k; M-=k; if(M<0) break; ll res=hcomb(k,M); add(ans,res); } }else{ for(ll k=1;;k++){ ll M=N-k; M-=k; if(M<0) break; ll res=hcomb(2*k-1,M); add(ans,res); } } } cout<<ans<<endl; return 0; }
#include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <algorithm> #define ll long long #define maxn 1000010 inline ll read() { ll x=0; char c=getchar(),f=1; for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1; for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0'; return x*f; } inline void write(ll x) { static int buf[20],len; len=0; if(x<0)x=-x,putchar('-'); for(;x;x/=10)buf[len++]=x%10; if(!len)putchar('0'); else while(len)putchar(buf[--len]+'0'); } inline void writeln(ll x){write(x); putchar('\n');} inline void writesp(ll x){write(x); putchar(' ');} int p[maxn],mn[maxn],mu[maxn]; int l,r,tot; void euler(int n) { tot=0; mn[1]=0; mu[1]=1; for(int i=2;i<=n;i++){ if(!mn[i])p[++tot]=i,mn[i]=tot,mu[i]=-1; for(int j=1;j<=mn[i]&&i*p[j]<=n;j++) mn[i*p[j]]=j,mu[i*p[j]]=(j==mn[i]?0:-mu[i]); } // for(int i=1;i<=n;i++) // printf("%d %d %d\n",i,p[mn[i]],mu[i]); } ll solve(int n,int m) { ll ans=(ll)n*m; for(int i=1;i<=n&&i<=m;i++) ans-=(ll)mu[i]*(n/i)*(m/i); for(int i=2;i<=n&&i<=m;i++) ans-=(n/i)+(m/i)-1; // printf("%d %d : %lld\n",n,m,ans); return ans; } int main() { l=read(); r=read(); euler(r); writeln(solve(r,r)-2*solve(l-1,r)+solve(l-1,l-1)); return 0; }
#pragma GCC optimize("O3") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> // find_by_order(k): It returns to an iterator to the kth element (counting from zero) in the set // order_of_key(k) : It returns to the number of items that are strictly smaller than our item k #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define pb push_back #define f first #define s second #define F(i,a,b) for(i=a;i<b;i++) #define nl "\n" #define sp " " #define all(c) (c).begin(),(c).end() #define rev(i,b,a) for(int i=b;i>=a;i--) #define iota cout<<-1<<nl #define cty cout<<"YES"<<nl #define ctn cout<<"NO"<<nl #define lmax LLONG_MAX #define lmin LLONG_MIN #define sz(v) (v).size() #define deci(n) fixed<<setprecision(n) #define c(x) cout<<(x) #define csp(x) cout<<(x)<<" " #define c1(x) cout<<(x)<<nl #define c2(x,y) cout<<(x)<<" "<<(y)<<nl #define c3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<nl #define c4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<nl #define c5(a,b,c,d,e) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<nl #define c6(a,b,c,d,e,f) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<" "<<(f)<<nl typedef long double ld; typedef long long ll; typedef vector<ll> vll; typedef pair<ll,ll> pll; typedef vector<pll> vpll; const int mod=998244353; const int mod1=1000000007; const double pi=3.14159265358979323846264338327950288419716939937510582097494459230; // priority_queue<t> 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 cdiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up ll fdiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // divide a by b rounded down ll pct(ll x) { return __builtin_popcount(x); } // # of bits set ll poww(ll a, ll b) { ll res=1; while(b) { if(b&1) res=(res*a); a=(a*a); b>>=1; } return res; } ll modI(ll a, ll m=mod) { ll m0=m,y=0,x=1; if(m==1) return 0; while(a>1) { ll q=a/m; ll t=m; m=a%m; a=t; t=y; y=x-q*y; x=t; } if(x<0) x+=m0; return x;} ll powm(ll a, ll b,ll m=mod) {ll res=1; while(b) { if(b&1) res=(res*a)%m; a=(a*a)%m; b>>=1; } return res;} //*******************************************************************************************************************************************// ll pr[1000001]={0}; void go(){ ll i,j; for(i=2;i<=1000000;i++) { if(pr[i]) continue; pr[i]=i; for(j=i*i;j<=1000000;j+=i) pr[j]=i; } } void iamzeus() { ll i,j,x=0,y,ans=0,n,m,d,cnt=0,z,c=2,k; ll l,r,mult,bits; cin>>l>>r; vll v; for(i=max(l,2);i<=r;i++) { v.clear(); d=i; while(d>1) { j=pr[d]; v.pb(j); while(d%j==0)d/=j; } ll sum = 0; for (int msk=1; msk<(1ll<<v.size()); ++msk) { mult = 1, bits = 0; for ( z=0; z<(int)v.size(); ++z) if (msk & (1<<z)) { ++bits; mult *= v[z]; } ll cur = (r / mult)-(i/mult)+(i%mult==0); if (bits % 2 == 1) sum += cur; else sum -= cur; } // c1(sum); mult=i; sum-=(r / mult)-(i/mult)+(i%mult==0); //c1(sum); ans+=sum*2; } c1(ans); }; int main() {fast; int t; t=1; go(); //cin >>t; while(t--) iamzeus(); }
#include <bits/stdc++.h> #include <fstream> using namespace std; typedef long long int64; typedef vector<int> vec; typedef vector<int64> vec64; // string __fname = ""; // ifstream in (__fname + ".in"); // ofstream out (__fname + ".out"); // #define cin in // #define cout out #define ss cout << " "; #define nn cout << "\n"; #define ct(x) cout << x; #define cts(x) cout << x << " "; #define ctn(x) cout << x << "\n"; #define db(x) cout << "> " << #x << ": " << x << "\n"; #define qr queries(); void solve(int); void YN(bool b){if (b){ctn("YES");}else{ctn ("NO");}}; void yn(bool b){if (b){ctn("Yes");}else{ctn ("No");}}; void queries(){int n;cin >> n;for (int i = 1; i <= n; i++) solve(i);} int64 ceildiv(int64 a, int64 b) {return a / b + !!(a % b);} // // // // // // // // // // // // // // // // // // // // // // /* TEMPLATE - VANILLA */ // // // // // // // // // // // // // // // // // // // // // // const int maxn = 200200; const int64 mod = 1000000007; const double pi = 3.14159265359; const int ddx[] = {-1, -1, 0, 1, 1, 1, 0, -1}; const int ddy[] = {0, 1, 1, 1, 0, -1, -1, -1}; const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, 1, 0, -1}; void solve(int id){ return; } int main(){ ios_base::sync_with_stdio(0);cin.tie(0); vector <int> a (3); for (int i = 0; i < 3; i++) cin >> a[i]; sort(a.begin(), a.end()); if (a[2] - a[1] == a[1] - a[0]) { ctn("Yes"); } else{ ctn("No") } return 0; }
#include<bits/stdc++.h> using namespace std; #define fix_precision(i) cout << fixed << setprecision(i) #define rp(i,n) for (int i = 0; i < n; i++) const long long mod = 1e9 + 7; template<typename T, typename U, typename V> V modPower(T a, U b, V c){ //a^b mod cを返す //帰り値の型はcと同じ V x = 1;//桁数がcと同じor超えることを考えて for (U i = 0; i < b; i++){ x = (x*a)%c; } return x; } int main(void){ vector<int> a(3); cin >> a[0] >> a[1] >> a[2]; sort(a.begin(), a.end()); if (a[1] - a[0] == a[2] - a[1]){ cout << "Yes" << endl; }else{ cout << "No" << endl; } return 0; }
#include <bits/stdc++.h> // #include <atcoder/all> // using namespace atcoder; #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 repr(i, n) for (ll i = n; i >= 0; i--) #define pb push_back #define COUT(x) cout << (x) << "\n" #define COUTF(x) cout << setprecision(15) << (x) << "\n" #define ENDL cout << "\n" #define DF(x) x.erase(x.begin()) #define ALL(x) x.begin(), x.end() #define SORT(x) sort(ALL(x)) #define RSORT(x) sort(x.rbegin(), x.rend()) #define REVERSE(x) reverse(ALL(x)) #define MAX(x) *max_element(ALL(x)) #define MAXI(x) max_element(ALL(x)) - x.begin() #define SUM(x) accumulate(ALL(x), 0ll) #define COUNT(x, y) count(ALL(x), y); #define ANS cout << ans << "\n" #define YES cout << "YES\n"; #define NO cout << "NO\n"; #define Yes cout << "Yes\n"; #define No cout << "No\n"; #define init() \ cin.tie(0); \ ios::sync_with_stdio(false) #define debug(x) cerr << "[debug] " << #x << ": " << x << endl; #define debugV(v) \ cerr << "[debugV] " << #v << ":"; \ rep(z, v.size()) cerr << " " << v[z]; \ cerr << endl; using namespace std; using ll = long long; using ld = long double; using vll = vector<ll>; using vvll = vector<vector<ll>>; using mll = map<ll, ll>; using qll = queue<ll>; using P = pair<ll, ll>; using vp = vector<P>; using vs = vector<string>; template <typename T> inline istream& operator>>(istream& i, vector<T>& v) { rep(j, v.size()) i >> v[j]; return i; } template <typename T1, typename T2> inline istream& operator>>(istream& i, pair<T1, T2>& v) { return i >> v.first >> v.second; } constexpr ll INF = 0x3f3f3f3f3f3f3f3f; constexpr ld PI = 3.141592653589793238462643383279; ll get_digit(ll x) { return to_string(x).size(); } ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } template <class T> void chmax(T& a, const T& b) { if (a < b) a = b; } template <class T> void chmin(T& a, const T& b) { if (b < a) a = b; } signed main() { init(); ll N; cin >> N; ll sum = 0; P l = {-INF, 0}, r = {INF, 0}; bool f = false; ll v = 0; rep(i, N) { ll a, t; cin >> a >> t; if (t == 1) { sum += a; l.second += a; r.second += a; } if (t == 2 and l.first < a - sum) { if (r.first < a - sum) { f = true; v = a; // r.first = a - sum + 1; } l.first = a - sum; l.second = a; } if (t == 3 and a - sum < r.first) { if (a - sum < l.first) { f = true; v = a; // r.first = a - sum + 1; } // l.first = a - sum - 1; r.first = a - sum; r.second = a; } if (f) { if (t == 1) v += a; if (t == 2) chmax(v, a); if (t == 3) chmin(v, a); } } ll Q; cin >> Q; rep(i, Q) { ll x; cin >> x; if (f) { COUT(v); continue; } if (l.first != -INF and x <= l.first) { COUT(l.second); continue; } if (r.first != INF and r.first <= x) { COUT(r.second); continue; } COUT(x + sum); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int INF = (1<<30)-1; const ll LINF = (1LL<<60)-1; #define rep(i, n) for (int i = 0; i < n; i++) #define sz(a) (int)(a.size()) template<class T> bool chmax(T &a, T b) {if (a < b) {a = b;return true;}else return false;} template<class T> bool chmin(T &a, T b) {if (a > b) {a = b;return true;}else return false;} ll func(ll y, vector<ll>& a, vector<ll>& t, int n) { rep(i, n) { if (t[i] == 1) y += a[i]; else if (t[i] == 2) { if (y <= a[i]) { y = a[i]; } } else if (t[i] == 3) { if (y >= a[i]) { y = a[i]; } } } return y; } //コーナーケースに気をつけろ! int main() { int n; cin >> n; vector<ll> a(n), t(n); rep(i, n) cin >> a[i] >> t[i]; int q; cin >> q; vector<ll> x(q); rep(i, q) cin >> x[i]; ll l = -INF, r = INF; ll b, c; ll ok = l, ng = INF; while (ok+1 < ng) { ll x = (ok + ng) / 2; ll y = x; bool flag = false; rep(i, n) { if (t[i] == 1) y += a[i]; else if (t[i] == 2) { if (y <= a[i]) { flag = true; y = a[i]; } } else if (t[i] == 3) { if (y >= a[i]) { y = a[i]; } } } if (flag) ok = x; else ng = x; } l = ok; ng = -INF, ok = INF; while (ng+1 < ok) { ll x = (ok + ng) / 2; ll y = x; bool flag = false; rep(i, n) { if (t[i] == 1) y += a[i]; else if (t[i] == 2) { if (y <= a[i]) { y = a[i]; } } else if (t[i] == 3) { if (y >= a[i]) { flag = true; y = a[i]; } } } if (flag) ok = x; else ng = x; } r = ok; bool check1 = false, check2 = false, check3 = false; ll ans1, ans2, ans3; rep(i, q) { if (x[i] <= l) { if (check1) cout << ans1 << endl; else { check1 = true; ans1 = func(x[i], a, t, n); cout << ans1 << endl; } } else if (r <= x[i]) { if (check3) cout << ans3 << endl; else { check3 = true; ans3 = func(x[i], a, t, n); cout << ans3 << endl; } } else { if (check2) cout << x[i] + ans2 << endl; else { check2 = true; ans2 = func(x[i], a, t, n) - x[i]; cout << x[i] + ans2 << endl; } } } return 0; } //小数点精度 //cout << fixed << std::setprecision(15) << y << endl;
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ld; typedef vector<bool> vb; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef set<int> si; typedef map<int,int> mii; typedef map<ll,ll> mll; typedef vector<pii> vii; typedef vector<pll> vll; #define fi first #define se second #define pi 3.141592653589793 #define mod 998244353 #define pb push_back #define mp make_pair #define all(v) v.begin(),v.end() #define pqmax priority_queue<int> #define pqmin priority_queue<int,vi,greater<int>> #define fio ios_base::sync_with_stdio(0), cin.tie(NULL) #define tc int tt;cin>>tt;for(int ti=1;ti<=tt;ti++) #define case_g "Case #"<<ti<<": " #define RED "\033[31m" #define GREEN "\033[32m" #define RESET "\033[0m" #define sleep for (int i = 1, a;i < 100000000;i++, a = a * a) typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> ranked_pairset; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ranked_set; typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ranked_map; ll modpow(ll a, ll b) { ll p = 1; while (b > 0) { if (b & 1) p = p * a % mod; a = a * a % mod; b >>= 1; } return p; } ll modinv(ll a) { ll m = mod, y = 0, x = 1; while (a > 1) { ll q = a / m, t = m; m = a % m; a = t; t = y; y = x - q * y; x = t; } return x < 0 ? x + mod : x; } int main() { fio; ll n, m; cin >> n >> m; ll dp[n][m]; for (int i = 0;i < m;i++) dp[0][i] = 1; vl s(n), minv(m + 1), mpm1j(m, 1); s[0] = m; mpm1j[0] = 0; ll mpmi = 1; for (int j = 1;j <= m;j++) minv[j] = modinv(j); for (int i = 1;i < n;i++) { mpmi = mpmi * m % mod; for (int j = 0;j < m;j++) { mpm1j[m - 1 - j] = mpm1j[m - 1 - j] * (m - 1 - j) % mod; dp[i][j] = (s[i - 1] + (mpmi * j + mpm1j[m - 1 - j]) % mod * minv[j + 1]) % mod; } for (int j = 0;j < m;j++) s[i] = (s[i] + dp[i][j]) % mod; } cout << s[n - 1] << '\n'; }
#include <bits/stdc++.h> using namespace std; #define rep(i,a,b) for(int i = (a); i < (b); i++) #define drep(i,b,a) for(int i = (b)-1; i >= (a); i--) #define bit(n) (1LL << (n)) #define sz(x) ((int)(x).size()) #define all(x) (x).begin(),(x).end() #define SORT(v) sort(v.begin(),v.end()); #define RSORT(v) sort(v.rbegin(),v.rend()); #define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ); typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<double> vd; typedef vector<bool> vb; typedef vector<char> vc; typedef vector<vi> vvi; typedef vector<vl> vvl; typedef vector<vd> vvd; typedef vector<vb> vvb; typedef vector<vc> vvc; const int inf = 1 << 30; const ll infl = 1LL << 60; const double PI = acos(-1.0); template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template<class T> inline bool odd(T x) { return x & 1; } template<class T> inline bool even(T x) { return !(x & 1); } template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill( (T*)array, (T*)(array+N), val ); } template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) { return s << '<' << P.first << ", " << P.second << '>'; } template<class T> ostream& operator << (ostream &s, vector<T> P) { for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; } template<class T> ostream& operator << (ostream &s, vector<vector<T> > P) { for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << endl; } s << P[i]; } return s; } template<class T> ostream& operator << (ostream &s, set<T> P) { for(auto it : P) { s << "<" << it << "> "; } return s << endl; } template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) { for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s; } //---------------------------------------------------------------------------------------------- int main() { int n; ll mx; cin >> n >> mx; vector<ll> a(n); rep(i,0,n) cin >> a[i]; vector<ll> pre,pos; rep(i,0,n/2) pre.push_back(a[i]); rep(i,n/2,n) pos.push_back(a[i]); vector<ll> v1,v2; rep(S,0,bit(sz(pre))) { bitset<25> bs(S); ll tmp = 0; rep(i,0,sz(pre)) if(bs[i]) tmp += pre[i]; if(tmp > mx) continue; v1.push_back(tmp); } rep(S,0,bit(sz(pos))) { bitset<25> bs(S); ll tmp = 0; rep(i,0,sz(pos)) if(bs[i]) tmp += pos[i]; if(tmp > mx) continue; v2.push_back(tmp); } SORT(v2); ll res = 0; for(auto x : v1) { auto it = upper_bound(all(v2), mx-x); if(it == v2.begin()) continue; it--; chmax(res, x + *it); } cout << res << endl; return 0; }
/*      />  フ      |  _  _|      /`ミ _x 彡      /      |     /  ヽ   ?  / ̄|   | | |  | ( ̄ヽ__ヽ_)_)  \二つ */ #pragma GCC optimize("Ofast","inline","-ffast-math") #pragma GCC target("avx,sse2,sse3,sse4,mmx") #include<bits/stdc++.h> #define int long long #define pb push_back #define pf push_front #define F first #define S second #define SS stringstream #define sqr(x) ((x)*(x)) #define m0(x) memset(x,0,sizeof(x)) #define m1(x) memset(x,63,sizeof(x)) #define CC(x) cout << (x) << endl #define AL(x) x.begin(),x.end() #define pw(x) (1ull<<(x)) #define NMSL cout << "NMSL" << endl; #define debug(x) cout << #x << ": " << x << endl; #define debug2(x, y) cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl; #define debug3(x, y, z) cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl; #define debug4(a, b, c, d) cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl; #define fio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define in128 __int128_t using namespace std; const int N = 2e6+10; const int INF = numeric_limits<int>::max() / 4; const double EPS = 1e-3; const long double PI = 3.14159265358979323846; const int mod = 998244353 ; int fac[N],inv[N]; int n,m; int ppow(int a,int b=mod-2) { int ans=1%mod; a%=mod; while(b) { if(b&1) ans=ans*a%mod; a=a*a%mod; b>>=1; } return ans; } void init() { fac[0]=1; for(int i=1; i<N; ++i) fac[i]=fac[i-1]*i%mod; inv[N-1]=ppow(fac[N-1]); for(int i=N-2; i>=0; --i) inv[i]=(i+1)*inv[i+1]%mod; } int C(int n,int m) { if(m<0||m>n)return 0; return fac[n]*inv[m]%mod*inv[n-m]%mod; } signed main() { fio init(); cin>>n>>m; int ans=0; for(int i=1; i<=m; ++i) { int x=i,sum=1; vector<int>temp; for(int j=2; j*j<=x; ++j) { int cnt=0; while(x%j==0) { x/=j; cnt++; } if(cnt) temp.push_back(cnt); } if(x>1)temp.push_back(1); for(int b : temp) sum=sum*C(n+b-1,b)%mod; ans=(ans+sum)%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=998244353; #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); int N; cin>>N; vector<ll> kai(N+1,1); int weigt[N]; int sum=0; rep(i,N) cin>>weigt[i],sum+=weigt[i]; rep(i,N) kai[i+1]=(kai[i]*(i+1))%Q; if(sum%2==1){ cout<<"0\n"; return 0; } ll dp[N+1][sum+1]; memset(dp,0,sizeof(dp)); dp[0][0]=1; for(int i =0;i < N;i++){ for(int j=sum/2;j>=weigt[i];j--){ for(int k=N-1;k>=0;k--) dp[k+1][j]=(dp[k+1][j]+dp[k][j-weigt[i]])%Q; } } ll ans=0; for(int i = 0;i < N;i++){ ans=(ans+(dp[i][sum/2]*((kai[i]*kai[N-i])%Q))%Q)%Q; } cout<<(ans)%Q<<endl; }
#include<bits/stdc++.h> #define ls(p) p<<1 #define rs(p) p<<1|1 #define de(x) cout<<#x<<" = "<<x<<endl; #define rep(i,a,b) for(int i = (a);i<=(b);++i) #define endl '\n' #define PI acos(-1.0) using namespace std; typedef long long ll; typedef pair<int,int> pii; const int maxn = 1e5+10; const int INF = 1e9+10; int main(){ ll x = 1; x = x*5*7*11*13*15*16*17*18*19*23*29; ++x; cout<<x<<endl; } /* 10 acesxd */
#include<bits/stdc++.h> using namespace std; long long gcd(long long int a, long long int b) { if (b == 0) return a; return gcd(b, a % b); } long long lcm(int a, int b) { return (a / gcd(a, b)) * b; } int main(){ long long int n; cin>>n; long long ans = 1; for(long long int i=2;i<=n;i++){ ans = lcm(ans,i); } cout<<ans+1<<endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < (n); ++i) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() using ll = long long; const long long INF = 1LL << 60; const int SINF = 1LL << 30; const ll mod = 1000000000+7; const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const double pi = 3.14159265358979323846; pair<double, double> rotate(double x, double y, double d) { double rx = x * cos(d) - y*sin(d); double ry = x * sin(d) + y*cos(d); return make_pair(rx, ry); } int main() { int n; cin >> n; double x0, y0, xn2, yn2; cin >> x0 >> y0 >> xn2 >> yn2; double xm = (x0+xn2)/2; double ym = (y0+yn2)/2; pair<double, double> ans = rotate(x0-xm, y0-ym, 2*pi/n); printf("%.20f %.20f\n", ans.first + xm, ans.second + ym); }
#include <iostream> #include <cstdio> #include <cmath> #include <ctime> #include <cstdlib> #include <cassert> #include <vector> #include <list> #include <stack> #include <queue> #include <deque> #include <map> #include <set> #include <bitset> #include <string> #include <algorithm> #include <utility> #include <complex> #define rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++) #define reps(x, s) for(llint (x) = 0; (x) < (llint)(s).size()-1; (x)++) #define chmin(x, y) (x) = min((x), (y)) #define chmax(x, y) (x) = max((x), (y)) #define all(x) (x).begin(),(x).end() #define outl(x) cout << x << endl #define SP << " " << #define inf 1e18 using namespace std; typedef long long llint; typedef long long ll; typedef pair<llint, llint> P; string X, Y, R; ll get(string s) { ll p = -1; rep(i, 0, (int)s.size()-1){ if(s[i] == '.'){ p = i; break; } } if(p == -1) s += '.', p = (int)s.size()-1; ll l = s.size(); rep(i, 1, 4-(l-1 - p)) s += '0'; ll ret = 0; rep(i, 0, (int)s.size()-1){ if(s[i] == '.') continue; ret *= 10; ret += s[i]-'0'; } return ret; } bool check(ll sx, ll sy, ll tx, ll ty, ll r) { //outl(sx SP sy SP tx SP ty SP r); //cout << ((sx-tx)*(sx-tx) + (sy-ty)*(sy-ty) <= r*r) << endl; return (sx-tx)*(sx-tx) + (sy-ty)*(sy-ty) <= r*r; } int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> X >> Y >> R; ll x = get(X), y = get(Y), r = get(R); //cout << x << " " << y << " " << r << endl; ll s = (x-r)/10000 - 5, t = (x+r)/10000 + 5, ans = 0; rep(i, s, t){ if(!check(i*10000, y, x, y, r)) continue; ll uy = (y + 10000000000 + 9999) / 10000 * 10000 - 10000000000; ll dy = (y + 10000000000) / 10000 * 10000 - 10000000000; if(uy == dy && abs(y) % 10000 == 0) ans--; ll ub = r / 10000 + 5, lb = 0, mid; while(ub-lb>1){ mid = (ub+lb)/2; if(check(i*10000, uy+(mid-1)*10000, x, y, r)) lb = mid; else ub = mid; } //cout << lb << endl; ans += lb; ub = r / 10000 + 5, lb = 0, mid; while(ub-lb>1){ mid = (ub+lb)/2; if(check(i*10000, dy-(mid-1)*10000, x, y, r)) lb = mid; else ub = mid; } ans += lb; //cout << i << " " << ans << endl; } cout << ans << endl; return 0; }
#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include<bits/stdc++.h> // #include<atcoder/all> #define rep(i, n) for(long long i = 0;i < (n);i++) using namespace std; // using namespace atcoder; using ll = long long; using Pii = pair<int, int>; const ll MOD = 1000000007; const ll MOD3 = 998244353; const ll INFl = 10000000000000000; const int INFi = 1000000000; const double EPS = 0.0000001; // using mint = modint1000000007; int main() { int n; cin >> n; vector<double> a(n); rep(i, n) cin >> a[i]; sort(a.begin(), a.end()); double x = 0; int idx = n / 2; x = a[idx] / 2.0; double ans = 0; rep(i, n) { ans += a[i]; } ans += x * n; rep(i, n) { if(2 * x > a[i]) { ans -=a[i]; } else ans -= 2 * x; } // cout << ans / (double)n << endl; printf("%10lf\n", ans / (double)n); }
#include<bits/stdc++.h> #define int ll #define sz(x) int((x).size()) #define all(x) (x).begin(),(x).end() using namespace std; using ll = long long; using pi = pair<int,int>; const int inf = 0x3f3f3f3f3f3f3f3f; const int minf = 0xc0c0c0c0c0c0c0c0; double A[100100]; double ssum[100100]; signed main() { ios::sync_with_stdio(0); cin.tie(0); cout<<fixed<<setprecision(10); int n; cin>>n; for (int i=1; i<=n; i++) cin>>A[i]; sort(A+1, A+n+1); ssum[n+1] = 0; for (int i=n; i>=1; i--) { ssum[i] = ssum[i+1] + A[i]; } double lo = 0, hi = A[n]; for (int tt=50; tt; tt--) { double le = (lo + lo + hi) / 3; double ri = (lo + hi + hi) / 3; int x = lower_bound(A+1, A+n+1, le+le) - A; int big = n - x + 1; int small = n - big; double fle = (small - big) * le + ssum[x]; x = lower_bound(A+1, A+n+1, ri+ri) - A; big = n - x + 1; small = n - big; double fri = (small - big) * ri + ssum[x]; if (fle > fri) lo = le; else hi = ri; } int x = lower_bound(A+1, A+n+1, lo+lo) - A; int big = n - x + 1; int small = n - big; double res = (small - big) * lo + ssum[x]; cout<<res/n<<'\n'; return 0; }
#include <bits/stdc++.h> using namespace std; #define INF 0x3f3f3f3f #define endl '\n' #define ll long long #define mp make_pair typedef pair<int, int> ii; int solution(vector<int> dp, const int& level, const int& k, const vector<ii>& options, const vector<vector<int>>& cond){ if(level == k) return 0; int opt1 = options[level].first; int opt2 = options[level].second; int inc1 = 0, inc2 = 0; vector<int> dp2 = dp; if(dp[opt1] == 0){ dp[opt1] = 1; for(int dish: cond[opt1]){ if(dp[dish] == 1) ++inc1; } } if(dp2[opt2] == 0){ dp2[opt2] = 1; for(int dish: cond[opt2]){ if(dp2[dish] == 1) ++inc2; } } return max(solution(dp, level+1, k, options, cond) + inc1, solution(dp2, level+1, k, options, cond) + inc2); } int main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << setprecision(2) << fixed; int n, m; cin >> n >> m; vector<vector<int>> cond(n+1); while(m--){ int a, b; cin >> a >> b; cond[a].push_back(b); cond[b].push_back(a); } int k, copy; cin >> k; copy = k; vector<ii> options; while(copy--){ int c, d; cin >> c >> d; options.push_back(mp(c, d)); } vector<int> dp(n+1, 0); dp[0] = -1; cout << solution(dp, 0, k, options, cond); return 0; }
#include <iostream> using namespace std; struct choice { int a = 0; int b = 0; }; int count(bool *D, int N, struct choice *C, int M) { int ans = 0; for (int i = 0; i < M; i++) { int a = C[i].a; int b = C[i].b; if (D[a] && D[b]) { ans++; } } return ans; } int main() { int N, M, K, ans; cin >> N; cin >> M; struct choice C[M]; // conditions for (int i = 0; i < M; i++) { cin >> C[i].a; cin >> C[i].b; } cin >> K; struct choice V[K]; // votes for (int i = 0; i < K; i++) { cin >> V[i].a; cin >> V[i].b; } ans = 0; for (int n = 0; n < (1 << K); n++) { bool D[N + 1] = {}; // dishes for (int k = 0; k < K; k++) { int v = n & (1 << k); // mask int i = v ? V[k].a : V[k].b; D[i] = 1; } int sum = count(D, N + 1, C, M); if (ans < sum) { ans = sum; } } cout << ans; return 0; }
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") #include <bits/stdc++.h> using namespace std; #define pb push_back #define eb emplace_back #define mk make_pair #define fi first #define se second #define mset(a,b) memset(a, b, sizeof(a)) #define dbg(x) cout << "[" << #x << "]: " << x << endl; #define forn(i,n) for(int i=0; i < n;i++) #define forab(i,a,b) for(int i = a; i <= b; i++) #define forba(i,b,a) for(int i = b; i >= a; i--) #define each(val, v) for(auto val : v) #define abs(u) (u >= 0 ? u : -u) using ll = long long; using pii = pair<int,int>; using pll = pair<ll,ll>; using vi = vector<int>; using vl = vector<ll>; const int MAXN = 2e3 + 5; const int INF = 0x3f3f3f3f; const int MOD = 998244353; int uf[MAXN]; int sz[MAXN]; int add(int a, int b){ a += b; if( a >= MOD) a -= MOD; if(a < 0) a += MOD; return a; } int mul(int a, int b){ int ret = (1LL * a * b)%MOD; return ret; } int pw(int a, int n){ int ret = 1; while(n > 0){ if(n&1 == 1){ ret = mul(ret, a); } a = mul(a,a); n = n>> 1; } return ret; } int inv(int a){ return pw(a,MOD-2); } int divide(int a, int b){ return mul(a, inv(b)); } int fat[MAXN]; int invfat[MAXN]; void pre_fat(int n){ fat[0] = 1; fat[1] = 1; invfat[0] = 1; invfat[0] = 1; for(int i = 2; i <= n; i++){ fat[i] = mul(fat[i-1], i); invfat[i] = divide(invfat[i-1], i); } } int find(int x){ if(uf[x] == x) return x; return uf[x] = find(uf[x] ); } int uni(int a, int b){ int aa = find(a), bb = find(b); if(aa == bb) return 0; if(sz[aa] > sz[bb]) swap(aa,bb); sz[bb] += sz[aa]; uf[aa] = bb; return 1; } int lin(int i){ return i; } int shift = 55; int col(int i){ return i + shift; } int M[MAXN][MAXN]; void solve(){ pre_fat(100); int ans = 1; int n; int k; cin >> n; cin >> k; for(int i = 0; i < MAXN; i++){ uf[i] = i; sz[i] = 1; } forn(i,n){ forn(j,n){ cin >> M[i][j]; } } forn(i1, n){ for(int i2 = i1 + 1; i2 < n; i2++){ bool certo =true; forn(j,n){ if( M[i1][j]+ M[i2][j] > k ){ certo = false; } } if(certo){ uni( lin(i1) , lin(i2)); } } } forn(i1, n){ for(int i2 = i1 + 1; i2 < n; i2++){ bool certo =true; forn(j,n){ if( M[j][i1]+ M[j][i2] > k ){ certo = false; } } if(certo){ uni( col(i1) , col(i2)); } } } set<int> ja_foi; forn(i,n){ int i_li = find( lin(i) ); int i_col = find( col(i) ); if( ja_foi.find(i_li) == ja_foi.end() ){ ans = mul( ans, fat[ sz[i_li] ] ); } if(ja_foi.find(i_col) == ja_foi.end()){ ans = mul(ans, fat[ sz[i_col] ] ); } ja_foi.insert(i_li); ja_foi.insert(i_col); } cout << ans << '\n'; } int main(){ ios::sync_with_stdio(false); cin.tie(NULL); int t = 1; //cin >> t; while(t--){ solve(); } return 0; }
/*================================================================ * * 创 建 者: badcw * 创建日期: 2020/11/15 8:40 下午 * ================================================================*/ #include <bits/stdc++.h> #define VI vector<int> #define ll long long using namespace std; namespace IO { template<class T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf("%d", &x); } void _R(ll &x) { scanf("%lld", &x); } void _R(double &x) { scanf("%lf", &x); } void _R(char &x) { x = getchar(); } void _R(char *x) { scanf("%s", x); } void R() {} template<class T, class... U> void R(T &head, U &... tail) {_R(head),R(tail...);} template<class T> void _W(const T &x) { cout << x; } void _W(const int &x) { printf("%d", x); } void _W(const ll &x) { printf("%lld", x); } void _W(const double &x) { printf("%.16f", x); } void _W(const char &x) { putchar(x); } void _W(const char *x) { printf("%s", x); } template<class T, class U> void _W(const pair<T, U> &x) {_W(x.first),putchar(' '),_W(x.second);} template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); } void W() {} template<class T, class... U> void W(const T &head, const U &... tail) {_W(head),putchar(sizeof...(tail) ? ' ' : '\n'),W(tail...);} } using namespace IO; const int maxn = 2e5+50; const int mod = 1e9+7; ll qp(ll a, ll n) { ll res = 1; n %= mod - 1; if (n < 0) n += mod - 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } ll qp(ll a, ll n, int mod) { ll res = 1; n %= mod - 1; if (n < 0) n += mod - 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } map<int, int> mp[maxn]; int pre[maxn]; int F(int x) { return x == pre[x] ? x : pre[x] = F(pre[x]); } int n, m; int main(int argc, char* argv[]) { // freopen("data.in", "r", stdin); // freopen("data.out", "w", stdout); // clock_t StartTime = clock(); R(n, m); for (int i = 1; i <= n; ++i) { int x; R(x); mp[i][x] = 1; pre[i] = i; } while (m--) { int op, x, y; R(op, x, y); if (op == 1) { int u = F(x), v = F(y); if (u == v) continue; if (mp[u].size() < mp[v].size()) swap(u, v); pre[v] = u; for (auto i : mp[v]) mp[u][i.first] += i.second; mp[v].clear(); } else { int u = F(x); if (mp[u].count(y)) W(mp[u][y]); else W(0); } } // cout << "Total time: " << (clock() - StartTime) * 1000 / CLOCKS_PER_SEC << "ms" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long int; typedef vector<ll> vi; typedef vector<vi> vvi; typedef pair<ll,ll> ii; typedef vector<ii> vii; typedef vector<vii> vvii; #define F first #define S second ll min(ll x, ll y){ return ((x < y) ? x : y); } ll max(ll x, ll y){ return ((x > y) ? x : y); } const ll MOD = 998244353; ll modpow (ll b, ll e){ ll ans = 1; while (e){ if (e%2) ans *= b; ans %= MOD; b *= b; b %= MOD; e /= 2; } return ans; } int main(){ ll n,m,k; cin >> n >> m >> k; ll ans = 0; if (n == 1){ cout << modpow(k,m) << endl; }else if (m == 1){ cout << modpow(k,n) << endl; }else{ for (ll i = 1; k >= i; i++){ ll mins = modpow(i,n); mins -= modpow(i-1,n); mins += MOD; mins %= MOD; ll maxs = modpow(k-i+1,m); //cout << mins << " " << maxs << endl; ans += (mins*maxs); ans %= MOD; } cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; double X, Y, R; bool inside(ll x, ll y) { const int LARGE = 10000; x *= LARGE; y *= LARGE; ll XX = round(X * LARGE); ll YY = round(Y * LARGE); ll RR = round(R * LARGE); return (x - XX) * (x - XX) + (y - YY) * (y - YY) <= RR * RR; } ll counter(ll x, ll base, ll delta) { ll ok = base; ll er = base + delta; if (!inside(x, ok)) return 0; while(abs(ok - er) > 1) { ll mid = (ok + er) / 2; if (inside(x, mid)) ok = mid; else er = mid; } return abs(er - base); } int main() { cin >> X >> Y >> R; ll ans = 0; for (ll x = floor(X - R - 1); x < floor(X + R + 1); x++) { ans += counter(x, floor(Y) + 1, floor(R) + 1); ans += counter(x, floor(Y), - floor(R) - 1); } cout << ans << endl; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ld; typedef vector<bool> vb; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef set<int> si; typedef map<int,int> mii; typedef map<ll,ll> mll; typedef vector<pii> vii; typedef vector<pll> vll; #define fi first #define se second #define pi 3.141592653589793 #define mod 1000000007 #define pb push_back #define mp make_pair #define all(v) v.begin(),v.end() #define pqmax priority_queue<int> #define pqmin priority_queue<int,vi,greater<int>> #define fio ios_base::sync_with_stdio(0), cin.tie(NULL) #define tc int tt;cin>>tt;for(int ti=1;ti<=tt;ti++) #define case_g "Case #"<<ti<<": " #define RED "\033[31m" #define GREEN "\033[32m" #define RESET "\033[0m" #define sleep for (int i = 1, a;i < 100000000;i++, a = a * a) typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> ranked_pairset; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ranked_set; typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ranked_map; int main() { fio; vi c(1001); tc { int a; cin >> a; for (int i = 1;i * i <= a;i++) if (a % i == 0) { c[i]++; if (i != a/i) c[a/i]++; } } int ans = 2; for (int i = 3;i < 1001;i++) if (c[i] > c[ans]) ans = i; cout << ans << '\n'; }
#include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG #define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++) using vi = vector<int64_t>; using vvi = vector<vi>; using ll = int64_t; using P = pair<ll,ll>; ll INF = 1000000007; // ll INF = 9223372036854775807; // ll INF = 998244353; int main() { // fasten cin cin.tie(0); ios::sync_with_stdio(false); // implement ll n; cin >> n; vi a(n); rep(i,n) cin >> a.at(i); ll res = 0; ll gcd = 0; for(ll i=2; i<=1000; i++){ ll tmp = 0; rep(j,n) if(a.at(j)%i==0) tmp++; if(gcd <= tmp){ res = i; gcd = tmp; } } cout << res << endl; }
#include<bits/stdc++.h> #define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i) #define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i) #define foreach(i, n) for(auto &i:(n)) #define all(x) (x).begin(), (x).end() #define bit(x) (1ll << (x)) #define lambda(RES_TYPE, ...) (function<RES_TYPE(__VA_ARGS__)>)[&](__VA_ARGS__) -> RES_TYPE #define method(FUNC_NAME, RES_TYPE, ...) function<RES_TYPE(__VA_ARGS__)> FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__) using namespace std; using ll = long long; using pii = pair<int,int>; using pll = pair<ll,ll>; //const ll MOD = (ll)1e9+7; const ll MOD = 998244353; const int INF = (ll)1e9+7; const ll INFLL = (ll)1e18; template<class t> using vvector = vector<vector<t>>; template<class t> using vvvector = vector<vector<vector<t>>>; template<class t> using priority_queuer = priority_queue<t, vector<t>, greater<t>>; template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;} template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;} #ifdef DEBUG #define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl; #else #define debug(x) (void)0 #endif namespace templates{ ll modpow(ll x, ll b,ll mod=MOD){ ll res = 1; while(b){ if(b&1)res = res * x % mod; x = x * x % mod; b>>=1; } return res; } ll modinv(ll x){ return modpow(x, MOD-2); } bool was_output = false; template<class t> void output(t a){ if(was_output)cout << " "; cout << a; was_output = true; } void outendl(){ was_output = false; cout << endl; } template<class t> istream& operator>>(istream&is, vector<t>&x){ for(auto &i:x)is >> i; return is; } template<class t, class u> istream& operator>>(istream&is, pair<t, u>&x){ is >> x.first >> x.second; return is; } template<class t> ostream& operator<<(ostream&os, vector<t> &v){ os << "{"; for(t &i:v){ os << i << ", "; } os << "}"; return os; } template<class t = long long> t in(){ t res; cin >> res; return res; } template<class t> void out(t x){ cout << x; } template<class t> vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){ sort(line.begin(),line.end(),comp); return line; } template<class t> vector<t> reversed(vector<t> line){ reverse(line.begin(),line.end()); return line; } string reversed(string str){ reverse(str.begin(),str.end()); return str; } long long gcd(long long a,long long b){ while(b){ a %= b; swap(a,b); } return a; } long long lcm(long long a,long long b){ return a / gcd(a,b) * b; } } using namespace templates; string func(){ int n = in(); vector<string> strs(3); foreach(i,strs)i=in<string>(); string res = ""; rep(_,n)res += "1"; rep(_,n)res += "0"; res += "1"; return res; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n = in(); rep(i,n){ cout << func() << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long ll; typedef long double ld; typedef pair<ll, ll> pii; typedef tuple<ll, ll, ll> ti; //#include <boost/multiprecision/cpp_int.hpp> //namespace mp = boost::multiprecision; //using Bint = mp::cpp_int; #define REP(a,b,c) for(ll a=b;a<(c);a++) #define PER(a,b,c) for(ll a=b;a>=(c);a--) inline ll ii(){ ll x; cin >> x; return x; } inline string is(){ string x; cin >> x; return x; } inline ld id(){ ld x; cin >> x; return x; } inline void oi(ll x){ cout << x; } inline void od(ld x){ cout << fixed << setprecision(12) << x; } inline void os(string x){ cout << x; } inline void oe(){ cout << endl; } inline void oie(ll x){ oi(x); oe(); } inline void ode(ld x){ od(x); oe(); } inline void ose(string x){ os(x); oe(); } inline void maxin(ll &a, ll b){ a=max(a,b); } inline void minin(ll &a, ll b){ a=min(a,b); } int main(){ ll N=ii(); vector<ll> A; REP(i,0,N){ A.push_back(ii()); } sort(A.begin(),A.end()); vector<ll> S; ll s=0; for(ll a:A){ s+=a; S.push_back(s); } ll ret=0; REP(i,1,N){ ret+=A[i]*i-S[i-1]; } oie(ret); return 0; }
/*** author: yuji9511 ***/ #include <bits/stdc++.h> // #include <atcoder/all> // using namespace atcoder; using namespace std; using ll = long long; using lpair = pair<ll, ll>; const ll MOD = 998244353; const ll INF = 1e18; #define rep(i,m,n) for(ll i=(m);i<(n);i++) #define rrep(i,m,n) for(ll i=(m);i>=(n);i--) #define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];}; void print() {} template <class H,class... T> void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);} #define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << "\n" struct UnionFind { private: ll N; vector<ll> parent; vector<ll> num; vector<ll> diff_weight; public: UnionFind(ll n){ N = n; rep(i,0,N) parent.push_back(i); rep(i,0,N) num.push_back(1); rep(i,0,N) diff_weight.push_back(0); } ll root(ll x){ if(x == parent[x]){ return x; }else{ ll r = root(parent[x]); diff_weight[x] += diff_weight[parent[x]]; return parent[x] = r; } } void unite(ll a, ll b, ll w = 0){ w += weight(a); w -= weight(b); a = root(a); b = root(b); if(a == b) return; parent[b] = a; ll sum = num[a] + num[b]; num[a] = sum; num[b] = sum; diff_weight[b] = w; } bool same(ll a, ll b){ return root(a) == root(b);} ll sz(ll x){ return num[root(x)];} ll weight(ll x){ root(x); return diff_weight[x]; } ll diff(ll a, ll b){ return weight(b) - weight(a); } }; struct Combination{ private: ll N; public: vector<ll> fac, facinv, inv; Combination(ll n){ N = n; fac.resize(N+1); facinv.resize(N+1); inv.resize(N+1); fac[0] = fac[1] = 1; facinv[0] = facinv[1] = 1; inv[1] = 1; rep(i,2,N+1){ fac[i] = fac[i-1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; facinv[i] = facinv[i-1] * inv[i] % MOD; } } ll power(ll x, ll n, ll m = MOD){ if(n == 0) return 1LL; ll res = power(x * x % m, n/2, m); if(n % 2 == 1) (res *= x) %= m; return res; } ll nck(ll n, ll k){ if(k == 0 || n == k) return 1LL; if(n < k) return 0LL; return fac[n] * facinv[k] % MOD * facinv[n-k] % MOD; } ll npk(ll n, ll k){ if(k == 0) return 1LL; if(n < k) return 0LL; return fac[n] * facinv[n-k] % MOD; } }; void solve(){ ll N,K; cin >> N >> K; ll a[55][55]; rep(i,0,N){ rep(j,0,N){ cin >> a[i][j]; } } Combination cb(55); ll ans = 1; UnionFind uf(55); rep(i,0,N){ rep(j,i+1,N){ ll max_val = 0; rep(k,0,N){ max_val = max(max_val, a[i][k] + a[j][k]); } if(max_val <= K){ uf.unite(i, j); } } } bool check[55] = {}; rep(i,0,N){ ll r = uf.root(i); if(not check[r]){ check[r] = true; ans *= cb.fac[uf.sz(r)]; ans %= MOD; } } UnionFind uf2(55); rep(i,0,N){ rep(j,i+1,N){ ll max_val = 0; rep(k,0,N){ max_val = max(max_val, a[k][i] + a[k][j]); } if(max_val <= K){ uf2.unite(i, j); } } } bool check2[55] = {}; rep(i,0,N){ ll r = uf2.root(i); if(not check2[r]){ check2[r] = true; ans *= cb.fac[uf2.sz(r)]; ans %= MOD; } } print(ans); } int main(){ cin.tie(0); ios::sync_with_stdio(false); solve(); }
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long ll; typedef long double ld; #define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define test() int t;cin>>t;for(int test=1;test<=t;test++) #define pb push_back #define nl cout<<"\n" #define all(x) x.begin(),x.end() template<class C> void min_self( C &a, C b ){ a = min(a,b); } template<class C> void max_self( C &a, C b ){ a = max(a,b); } const ll MOD = 998244353; ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; } const int MAXN = 1e5+5; const int LOGN = 21; const ll INF = 1e14; int dx[] = {1,0,-1,0}; int dy[] = {0,1,0,-1}; template<class T1, class T2> void add( T1 &x, T2 y, ll m = MOD ) { x += y; if( x >= m ) x -= m; } template<class T1, class T2> void sub( T1 &x, T2 y, ll m = MOD ) { x -= y; if( x < 0 ) x += m; } template<class T> class Math { public: vector<T>fact,invfact; Math( int n ) { fact.resize(n); invfact.resize(n); fact[0] = invfact[0] = 1; for(int i=1;i<n;i++) { fact[i] = mod( i * fact[i-1] ); invfact[i] = modinv( fact[i] ); } } T modinv( T x, T m = MOD ) { return expo(x,m-2,m); } T expo( T base, T exp, T m = MOD ) { T res = 1; while( exp ) { if( exp&1 ) res = mod( res*base, m ); base = mod( base*base, m ); exp >>= 1; } return res; } T choose( T n, T k ) { if( k < 0 || k > n ) return 0; T ans = fact[n]; ans = mod( ans * invfact[n-k] ); ans = mod( ans * invfact[k] ); return ans; } }; class DSU { public: vector<int>rt,sz; int components; DSU( int n ) { rt.resize(n+5); sz.resize(n+5); components = n; for(int i=0;i<n;i++) { rt[i] = i; sz[i] = 1; } } int get_components() { return components; } int root( int x ) { while( x != rt[x] ) { rt[x] = rt[rt[x]]; x = rt[x]; } return x; } void connect( int x, int y ) { int r1 = root(x); int r2 = root(y); if( r1 == r2 ) return; if( sz[r1] < sz[r2] ) swap(r1,r2); sz[r1] += sz[r2]; rt[r2] = r1; components--; } }; int grid[55][55]; int main() { #ifdef gupta_samarth freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fastio(); int n,k; cin>>n>>k; Math<ll> m(102); for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { cin>>grid[i][j]; } } ll ans = 1; for(int rep=0;rep<2;rep++) { DSU d(n); for(int i=0;i<n;i++) { for(int j=0;j<i;j++) { int ok = 0; for(int ind=0;ind<n;ind++) { if( grid[i][ind] + grid[j][ind] <= k ) ok++; } if( ok == n ) d.connect(i,j); } } set<int>comps; for(int i=0;i<n;i++) comps.insert(d.root(i)); for( int x : comps ) ans = mod( ans * m.fact[d.sz[x]] ); // transpose for(int i=0;i<n;i++) { for(int j=i;j<n;j++) { swap(grid[i][j], grid[j][i]); } } } cout<<ans,nl; cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; return 0; }
#include <bits/stdc++.h> #define x first #define y second #define pb push_back #define all(v) v.begin(),v.end() #pragma gcc optimize("O3") #pragma gcc optimize("Ofast") #pragma gcc optimize("unroll-loops") using namespace std; const int INF = 1e9; const int TMX = 1 << 18; const long long llINF = 1e16; const long long mod = 1e9+7; const long long hashmod = 100003; const int MAXN = 100000; const int MAXM = 1000000; typedef long long ll; typedef long double ld; typedef pair <int,int> pi; typedef pair <ll,ll> pl; typedef vector <int> vec; typedef vector <pi> vecpi; typedef long long ll; int n,m,a[105],c[105]; int arrow[10005],ch[10005]; pi edge[10005]; vecpi v[105]; void dfs(int x) { c[x] = 1; for(pi i : v[x]) { if(!ch[abs(i.y)]) { if(i.y > 0) arrow[i.y] = 1; else arrow[-i.y] = 0; ch[abs(i.y)] = 1; } if(!c[i.x]) dfs(i.x); } } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> m; for(int i = 1;i <= m;i++) { int x,y; cin >> x >> y; edge[i] = {x,y}; } for(int i = 1;i <= n;i++) cin >> a[i]; for(int i = 1;i <= m;i++) { int x = edge[i].x, y = edge[i].y; if(a[x] < a[y]) arrow[i] = 0; else if(a[x] > a[y]) arrow[i] = 1; else v[x].pb({y,i}), v[y].pb({x,-i}); } for(int i = 1;i <= n;i++) { if(!c[i]) dfs(i); } for(int i = 1;i <= m;i++) { if(arrow[i]) cout << "->\n"; else cout << "<-\n"; } }
#include <bits/stdc++.h> using namespace std; #define ALL(x) (x).begin(),(x).end() #define ll long long const long long MOD = 998244353; const int N = 2020; int d[N][N]; int dx[] = {0, -1, 0, 1}; int dy[] = {-1, 0, 1, 0}; vector<pair<int, int> > g[N]; char a[N][N]; int n, m; void BFS01(int sx, int sy) { for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++)d[i][j] = 1e9; } d[sx][sy] = 0; deque<pair<int, int> > q; q.emplace_back(sx, sy); while (!q.empty()) { int vx, vy; tie(vx, vy) = q.front(); q.pop_front(); int c = a[vx][vy]; if (c >= 'a' && c <= 'z') { for (auto el:g[c - 'a']) { int x = el.first; int y = el.second; if (d[x][y] > d[vx][vy] + 1) { d[x][y] = d[vx][vy] + 1; q.push_back({x, y}); } } g[c - 'a'].resize(0); } for (int i = 0; i < 4; i++) { int x = vx + dx[i]; int y = vy + dy[i]; if (x >= 1 && x <= n && y >= 1 && y <= m && a[x][y] != '#' && d[x][y] > d[vx][vy] + 1) { d[x][y] = d[vx][vy] + 1; q.push_back({x, y}); } } } } void solve() { cin >> n >> m; int sx, sy; int tx, ty; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin >> a[i][j]; if (a[i][j] == 'G') sx = i, sy = j; if (a[i][j] == 'S') tx = i, ty = j; char c = a[i][j]; if (c >= 'a' && c <= 'z') g[c - 'a'].emplace_back(i, j); } } BFS01(sx, sy); if (d[tx][ty] == 1e9) cout << -1 << endl; else cout << d[tx][ty] << endl; } int main() { #ifdef QWERTY freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); srand(time(NULL)); int TC = 1; // cin >> TC; while (TC--) { // cout << TC << endl; solve(); } return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++)//rep(i,回数){処理} using namespace std; using ll = long long; using P = pair<int, int>; int main() { ll n, x, a, count=0; cin >> n >> x; vector<ll> ans(n); rep(i,n) { cin >> a; if (a != x) { ans[count] += a; count++; } } rep(i,count) cout << ans[i] << " "; return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int n,x; cin>>n>>x; int a[n]; for(int i=0;i<n;i++){ cin>>a[i]; } for(int i=0;i<n;i++){ if(a[i]!=x) cout<<a[i]<<" "; } }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define mp make_pair #define pb push_back #define fi first #define se second #define sz(x) int(x.size()) const int mod = 1e9 + 7; const int inf = 2e9 + 5; const ll linf = 9e18 + 5; const ll ll0 = 0 * 1ll; void init () { } void input () { } void solve() { int arr[3]; cin >> arr[0] >> arr[1] >> arr[2]; sort(arr, arr + 3); if (arr[2] - arr[1] == arr[1] - arr[0]) { cout << "Yes"; } else { cout << "No"; } } void output() { } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int number_of_testcases = 1; //cin >> number_of_testcases; while (number_of_testcases--) { init(); input(); solve(); output(); } return 0; }
#include<bits/stdc++.h> using namespace std; using ll=long long; using uint=unsigned int; using ull=unsigned long long; const ll LL_MAX=LLONG_MAX; class union_find{ private: vector<ll> par; vector<ll> siz; public: union_find(ll n) : par(n),siz(n,1LL){ for (ll i=0;i<n;i++) par[i]=i; } ll root(ll x){ ll i=x; queue<ll> line; while(i!=par[i]){ line.push(i); i=par[i]; } ll l=line.size(); for (ll j=0;j<l;j++){ par[line.front()]=i; line.pop(); } return i; } ll size(ll x){ return siz[root(x)]; } bool unite(ll x,ll y){ x=root(x); y=root(y); if (x==y) return false; if (size(x)<size(y)){ par[x]=y; siz[y]+=siz[x]; } else{ par[y]=x; siz[x]+=siz[y]; } return true; } bool same(ll x,ll y){ if (root(x)==root(y)) return true; else return false; } }; struct In{ template<typename T> operator T(){ T x; cin >> x; return x; } }; In in; template <typename T,typename U> void forin(T *x,U n){ for (U i=0;i<n;i++) cin >> x[i]; } template <typename T> void outl(T x){ cout << x << endl; } template < > void outl<int>(int x){ printf("%d\n",x); } template < > void outl<double>(double x){ printf("%.16lf\n",x); } template < > void outl<char>(char x){ printf("%c\n",x); } template < > void outl<string>(string x){ printf("%s\n",x.c_str()); } template < > void outl<uint>(uint x){ printf("%u\n",x); } template < > void outl<ll>(ll x){ printf("%lld\n",x); } template < > void outl<ull>(ull x){ printf("%llu\n",x); } void outl(){ printf("\n"); } template <typename T> void out(T x){ cout << x << flush; } template < > void out<int>(int x){ printf("%d",x); } template < > void out<char>(char x){ printf("%c",x); } template < > void out<double>(double x){ printf("%.16lf",x); } template < > void out<string>(string x){ printf("%s",x.c_str()); } template < > void out<uint>(uint x){ printf("%u",x); } template < > void out<ll>(ll x){ printf("%lld",x); } template < > void out<ull>(ull x){ printf("%llu",x); } void outyes(){ printf("Yes\n"); } void outno(){ printf("No\n"); } void outyn(bool x){ if (x) printf("Yes\n"); else printf("No\n"); } void outsp(){ printf(" "); } template <typename T> T gcd(T x,T y){ if (y == 0) return x; return gcd(y,x%y); } template <typename T> T lcm(T x,T y){ return x*y/gcd(x,y); } template <typename T> T npr(T x,T y){ T loop=max(x-y,y),ans=1; for (T i=loop;i<=x;i++){ ans*=i; } return ans; }//xPy template <typename T> T ncr(T x,T y){ T loop=min(x,x-y),ans=npr(x,y); for (T i=1;i<=loop;i++){ ans/=i; } return ans; }//xCy template <typename T> T fac(T x){ if (x==1) return 1; return x*fac(x-1); } void div1(ll &x) { x%=1000000007; } ll mypow(ll x,ll n){ ll ans=1; for (ll i=1;i<=n;i = i<<1){ if ((n & i)== i){//ループj回目で2進表記のときにj桁目が1かどうか判定 ans*=x; } x*=x; } return ans; } ll divpow(ll x,ll n){ ll ans=1; div1(x); for (ll i=1;i<=n;i = i<<1){ if ((n & i)== i){//ループj回目で2進表記のときにj桁目が1かどうか判定 ans*=x; div1(ans); } x*=x; div1(x); } return ans; } int main(){ int n=in,a[n],ans=0; forin(a,n); for (int i=0;i<n;i++){ ans+=max(a[i]-10,0); } outl(ans); }
#include <iostream> #include <vector> #include <string> #include <array> #include <functional> #include <algorithm> #include <stack> #include <map> #include <set> #include <climits> #include <queue> #include <bitset> #include <cassert> #include <math.h> #include <complex> #include <iomanip> #include <unordered_map> using namespace std; #define ll long long #define pb(x) push_back(x) #ifdef _OLIMPOLOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 1337 #endif void debug_out() { cout << "\n";} template<typename T1, typename... T2> void debug_out(T1 A, T2... B) { cout << " " << A; debug_out(B...); } int test = 1; #define out(x) {cout << x << "\n";return;} #define all(N) N.begin(),N.end() #define allr(N) N.rbegin(),N.rend() template<typename T1> void pr(vector<T1> V, int add = 0, int start = -1, int end = -1) { if (start < 0) start = 0; if (end < 0) end = V.size() - 1; for (int i = start; i <= end; i++) { cout << V[i] + add << ((i == end) ? "\n" : " "); } } template<typename T1> T1 chmin(T1 &x, const T1 v) { return x = min(x,v); } template<typename T1> T1 chmax(T1 &x, const T1 v) { return x = max(x,v); } #define rep(i, n) for (int i = 0; i < n; i++) #define reps(i, s, n) for (int i = s; i < n; i++) #define repr(i, n) for (int i = n-1; i >= 0; i--) #define repsr(i, s, n) for (int i = n-1; i >= s; i--) #define PI pair<int,int> template<typename T1> T1 gcd(const T1 &a, const T1 &b) { if (a == 0 || b == 0) return a + b; return gcd(b, a %b); } //-------------------------- ^ DONT TOUCH ^----------------------------------------------------------------- #define MAX 200001 #define MOD 998244353 ll C1[MAX], C2[MAX]; ll D1[MAX], D2[MAX]; bool HC[MAX]; ll n, x, c; void solve() { cin >> n; rep(i,n) { cin >> x >> c; if (!HC[c]) { C1[c] = C2[c] = x; } HC[c] = 1; chmin(C1[c], x); chmax(C2[c], x); } C1[0] = C2[0] = D1[0] = D2[0] = 0; reps(i, 1, n+1) { if (!HC[i]) { C1[i] = C1[i-1]; C2[i] = C2[i-1]; D1[i] = D1[i-1]; D2[i] = D2[i-1]; continue; } D1[i] = min(D1[i-1] + abs(C2[i] - C1[i-1]), D2[i-1] + abs(C2[i] - C2[i-1])) + abs(C1[i] - C2[i]); D2[i] = min(D1[i-1] + abs(C1[i] - C1[i-1]), D2[i-1] + abs(C1[i] - C2[i-1])) + abs(C1[i] - C2[i]); //debug(i, C1[i], C2[i], D1[i], D2[i]); } out(min(D1[n] + abs(C1[n]), D2[n] + abs(C2[n]))) } int main() { ios_base::sync_with_stdio(0);cin.tie(0); int test = 1; #ifdef _OLIMPOLOCAL cin >> test; #endif rep(testCase, test) { solve(); } return 0; }
#include<bits/stdc++.h> using namespace std; using ll = long long; #define int ll const int INF = 2e9 + 5; const int dpINF = 1e16; const int off = 1e9; void print(vector<pair<int, int>> a) { cout << "\n"; for(auto i : a) { cout << i.first << " " << i.second << "\n"; } cout << "\n"; } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<pair<int, int>> a(n); for(int i = 0; i < n; i++) { cin >> a[i].first >> a[i].second; // a[i].first += off; } sort(a.begin(), a.end(), [](pair<int, int> l, pair<int, int> r) { return l.second < r.second; }); vector<pair<int, int>> v(n+2, {INF, -INF}); v[0] = {0, 0}; v[n+1] = {0, 0}; for(int i = 0; i < n; i++) { v[a[i].second].first = min(v[a[i].second].first, a[i].first); v[a[i].second].second = max(v[a[i].second].second, a[i].first); } // print(v); // print(a); int dp[n+5][2]; for(int i = 0; i <= n+4; i++) { for(int j = 0; j < 2; j++) { dp[i][j] = dpINF; } } dp[0][0] = dp[0][1] = 0; cerr << "\n"; for(int i = 1; i <= n+1; i++) { if (v[i].first == INF) { v[i] = v[i-1]; dp[i][0] = dp[i-1][0]; dp[i][1] = dp[i-1][1]; continue; } dp[i][0] = min(dp[i][0], dp[i-1][0] + abs(v[i-1].first - v[i].second) + abs(v[i].second - v[i].first)); dp[i][0] = min(dp[i][0], dp[i-1][1] + abs(v[i-1].second - v[i].second) + abs(v[i].second - v[i].first)); dp[i][1] = min(dp[i][1], dp[i-1][0] + abs(v[i-1].first - v[i].first) + abs(v[i].second - v[i].first)); dp[i][1] = min(dp[i][1], dp[i-1][1] + abs(v[i-1].second - v[i].first) + abs(v[i].second - v[i].first)); // cout << dp[i][0] << " " << dp[i][1] << "\n"; } int ans = min(dp[n+1][0], dp[n+1][1]); cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define REP(i, n) FOR(i, 0, n) #define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i) #define ALL(obj) (obj).begin(), (obj).end() #define ALLR(obj) (obj).rbegin(), (obj).rend() #define CEIL(a, b) ((a - 1) / b + 1) void solve() { int N, C; cin >> N >> C; vector<pair<int, int>> event; REP(i, N) { int a, b, c; cin >> a >> b >> c; event.emplace_back(a - 1, c); event.emplace_back(b, -c); } sort(ALL(event)); int ans = 0, fee = 0, t = 0; for (auto [x, y] : event) { if (x != t) { ans += min(C, fee) * (x - t); t = x; } fee += y; } cout << ans << endl; } signed main() { cin.tie(nullptr)->sync_with_stdio(false); solve(); }
#include<bits/stdc++.h> using namespace std; long long used[222222]; int s[222222]; int t[222222]; int main() { long long n,w; cin>>n>>w; for(int i=0;i<n;i++) { long long p; cin>>s[i]>>t[i]>>p; used[s[i]]+=p; used[t[i]]-=p; } for(int i=0;i<=200000;i++) { used[i]+=used[i-1]; if(used[i]>w) { cout<<"No"; return 0; } } cout<<"Yes"; return 0; }
// AtCoder Beginner Contest 204 // B - #include <iostream> #include <vector> int main(int argc, char *argv[]); int main(int argc, char *argv[]) { unsigned short N; std::cin >> N; std::vector<unsigned short> nuts(N); for(unsigned short i=0; N>i; i++) std::cin >> nuts[i]; std::vector<unsigned short>::const_iterator it=nuts.cbegin(); const std::vector<unsigned short>::const_iterator end=nuts.cend(); unsigned long sum=0; while(end != it) { if(10 < *it) sum += *it-10; it++; } std::cout << sum << std::endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define pb push_back #define lb lower_bound #define ub upper_bound #define bs binary_search #define F first #define S second #define nl "\n" #define pll pair<ll, ll> #define all(v) (v).begin(), (v).end() #define decimal(n) cout << fixed << setprecision(n) #define mod 1000000007 // #define mod 998244353 #define pi 3.14159265358979323846 int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll t = 1, tc; //cin >> t; for (tc = 1; tc <= t; tc++) { ll n,i,x,s=0; cin>>n; for(i=0;i<n;i++){ cin>>x; s+=max(0ll,x-10); } cout<<s; } return 0; }
#include<iostream> #include<algorithm> #include<cstring> #include<cstdio> #include<bitset> #include<cmath> #include<ctime> #include<queue> #include<map> #include<set> #define int long long #define lowbit(x) (x&(-x)) #define mid ((l+r)>>1) #define lc (x<<1) #define rc (x<<1|1) #define fan(x) (((x-1)^1)+1) #define max Max #define min Min #define abs Abs using namespace std; inline int read() { int ans=0,f=1; char c=getchar(); while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();} while(c>='0'&&c<='9'){ans=(ans<<1)+(ans<<3)+c-'0';c=getchar();} return ans*f; } inline void write(int x) { if(x<0) putchar('-'),x=-x; if(x/10) write(x/10); putchar((char)(x%10)+'0'); } template<typename T>inline T Abs(T a){return a>0?a:-a;}; template<typename T,typename TT>inline T Min(T a,TT b){return a>b?b:a;} template<typename T,typename TT> inline T Max(T a,TT b){return a>b?a:b;} signed main() { int x=read(),y=read(); if(min(x,y)+3>max(x,y)) printf("Yes\n"); else printf("No\n"); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int a,b; cin>>a>>b; int ans =abs(a-b); if(ans<3)cout<< "Yes"<<endl; else cout<< "No"<<endl; }
#include <cstdio> using u32 = unsigned int; using u64 = unsigned long long int; /* A^{B^C} mod 10 0 1 1 2 4 8 6 2 3 9 7 1 3 4 6 4 5 5 6 6 7 9 3 1 7 8 4 2 6 8 9 1 9 */ u32 modpow(u32 a, u32 n, u32 mod){ u32 r = 1; for(; n; n>>=1){ if(n&1) r = (u64) r * a % mod; a = (u64) a * a % mod; } return r; } int main(){ int a, b, c; scanf("%d%d%d", &a, &b, &c); if(a % 10 == 0){ puts("0"); } else if(a % 10 == 1 || a % 10 == 5 || a % 10 == 6){ printf("%d\n", a % 10); } else if(a % 10 == 2 || a % 10 == 3 || a % 10 == 7 || a % 10 == 8) { u32 x = modpow(b, c, 4); printf("%u\n", modpow(a%10, x+4, 10)); } else if(a % 10 == 4 || a % 10 == 9) { u32 x = modpow(b, c, 2); printf("%u\n", modpow(a%10, x+2, 10)); } return 0; }
// 2021-02-21 21:21:33 // clang-format off #include <bits/stdc++.h> #ifdef LOCAL #include "lib/debug.hpp" #else #define debug(...) 1 #endif #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define rep(i, n) REP(i, 0, (n)) #define repc(i, n) REPC(i, 0, (n)) #define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++) #define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++) #define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--) template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; } template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } using namespace std; using ll = long long; using ld = long double; using P = pair<int, int>; // clang-format on ll pw10(ll n, ll m, ll mod) { ll res = 1; ll b = n; while (m > 0) { if (m & 1) res *= b; b *= b; res %= mod; b %= mod; m >>= 1; } return res % mod; } void answer() { ll a, b, c; cin >> a >> b >> c; if (a % 10 == 0) { cout << 0 << '\n'; return; } if (a % 10 == 1) { cout << 1 << '\n'; return; } int mod; { vector<int> id(10, -1); ll n = a % 10; int cur = 0; while (id[n] == -1) { id[n] = cur++; n *= a; n %= 10; } mod = cur; } ll d = pw10(b, c, mod); d--; d += mod; d %= mod; ll ans = a % 10; rep(i, d) { ans *= a; ans %= 10; } cout << ans << '\n'; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); answer(); return 0; }
#include <bits/stdc++.h> #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); #define loop(i,n) for(int i = 0; i < n; ++ i) #define mod 10e+7 #define pb push_back const long double PI = 3.141592653589793236L; typedef long long int ll; typedef long double ld; using namespace std; long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } int max(int x,int y) { if(x==0 && y==0) return -1; else if(x>y) return x; else if(x<=y) return y; return 0; } int min(int x,int y) { if(x==0 && y==0) return -1; else if(x>y) return y; else if(x<=y) return x; return 0; } void solve() { int n,f=0; cin>>n; string str; unordered_set<string> S; while(n--) { cin>>str; S.insert(str); } unordered_set<string>::iterator itr; for(itr=S.begin();itr!=S.end();++itr) //for(const string& str1 : S) { if(S.count('!'+*itr)) { cout<<*itr; return; } } cout<<"satisfiable"; } int main() { int T = 1; //cin >> T; while (T--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; void input(set<string>& rseStr) { int nStrSiz; cin >> nStrSiz; for (int nx = 0; nx < nStrSiz; ++nx) { string sStr; cin >> sStr; rseStr.insert(sStr); } } string isExistStr(const set<string>& cnrseStr) { for (auto sStr : cnrseStr) { if (sStr[0] == '!') { string s2ndSubStr = sStr.substr(1); if ( cnrseStr.count(s2ndSubStr) ) return s2ndSubStr; } } return "satisfiable"; } int main() { set<string> seStr; input(seStr); cout << isExistStr(seStr) << endl; return 0; }
#include <iostream> #include <bits/stdc++.h> #include<string> using namespace std; #define boost ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL); long long n,m; string s,st; long long a[200005]={0}; void get_values() { std::cin >> n >> m; n=n+m; //for(int i=0;i<n;i++) // std::cin >> a[i]; //std::cin >> s; //n=s.length(); } void solve() { long long i,j,t,ans=0,x,y; if(n>=15 && m>=8) std::cout << 1 << std::endl; else if(n>=10 && m>=3) std::cout << 2 << std::endl; else if(n>=3) std::cout << 3 << std::endl; else std::cout << 4 << std::endl; } int main() { boost; get_values(); solve(); return 0; }
#include<bits/stdc++.h> #define ll long long #define x first #define y second #define pi pair #define K 1000000007 using namespace std; ll a[2000000]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll test_case=1;//cin>>test_case; while(test_case--) { ll a,b;cin>>a>>b; cout<<fixed; cout<<setprecision(10)<<(100*(a-b))/(double)a<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define MOD int(1e9+7) #define INF int(1e9+7) #define LINF ll(1e18+7) #define PI acos(-1) #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define P pair<ll,ll> #define chmax(x,y) (x = max(x,y)) #define chmin(x,y) (x = min(x,y)) int n; ll a[310000]; const int SEG_LEN=1<<19; int seg[SEG_LEN*2]; void update(int ind, int val){ ind += SEG_LEN; seg[ind]=val; while(ind!=0){ ind/=2; seg[ind]=seg[ind*2]+seg[ind*2+1]; } return; } int getsum(int ql, int qr, int sl=0, int sr=SEG_LEN, int pos=1){ if(qr<=sl || sr<=ql) return 0; if(ql<=sl && sr<=qr) return seg[pos]; int sm=(sl+sr)/2; return getsum(ql,qr,sl,sm,pos*2)+getsum(ql,qr,sm,sr,pos*2+1); } int main(){ cin>>n; rep(i,n) cin>>a[i]; ll inv=0; rep(i,n){ update(a[i],1); inv += getsum(a[i]+1,n); } cout<<inv<<endl; rep(i,n-1){ inv=inv-a[i]+n-a[i]-1; cout<<inv<<endl; } }
#include<bits/stdc++.h> typedef unsigned long long ull; typedef long long ll; #define rep(i,l,r) for(int i=l;i<=r;i++) #define nep(i,r,l) for(int i=r;i>=l;i--) void sc(int &x){scanf("%d",&x);} void sc(int &x,int &y){scanf("%d%d",&x,&y);} void sc(int &x,int &y,int &z){scanf("%d%d%d",&x,&y,&z);} void sc(ll &x){scanf("%lld",&x);} void sc(ll &x,ll &y){scanf("%lld%lld",&x,&y);} void sc(ll &x,ll &y,ll &z){scanf("%lld%lld%lld",&x,&y,&z);} void sc(char *x){scanf("%s",x);} void sc(char *x,char *y){scanf("%s%s",x,y);} void sc(char *x,char *y,char *z){scanf("%s%s%s",x,y,z);} void out(int x){printf("%d\n",x);} void out(ll x){printf("%lld\n",x);} void out(int x,int y){printf("%d %d\n",x,y);} void out(ll x,ll y){printf("%lld %lld\n",x,y);} void out(int x,int y,int z){printf("%d %d %d\n",x,y,z);} void out(ll x,ll y,ll z){printf("%lld %lld %lld\n",x,y,z);} using namespace std; const int N=3e5+5; struct node { int x,y,id; }a[N]; int n; bool cmp1(node &x,node &y) { return x.x<y.x; } bool cmp2(node &x,node &y) { return x.y<y.y; } map<pair<int,int>,bool>vis; vector<int>v; void add(int x,int y) { if(vis[{a[x].id,a[y].id}]) return; vis[{a[x].id,a[y].id}]=vis[{a[y].id,a[x].id}]=true; v.push_back(max(abs(a[x].x-a[y].x),abs(a[x].y-a[y].y))); } int main() { //freopen("1.in","r",stdin);freopen("1.out","w",stdout); sc(n); rep(i,1,n) sc(a[i].x,a[i].y),a[i].id=i; sort(a+1,a+1+n,cmp1); add(1,n); add(1,n-1); add(2,n); sort(a+1,a+1+n,cmp2); add(1,n); add(1,n-1); add(2,n); sort(v.begin(),v.end()); reverse(v.begin(),v.end()); out(v[1]); }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const ll M=998244353; const ll MAXN=1e6+7; const ld pi=acos(-1); #define gi(n) ll n=read() #define endl '\n' #define rep(i,a,b) for(ll i=a; i<b; ++i) #define per(i,a,b) for(ll i=b-1; i>=a; --i) typedef vector<ll> V; typedef vector<V> VV; typedef set<ll> S; typedef pair<ll,ll> pl; typedef vector<pl> Vp; typedef map<ll,ll> ml; #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() #define pb push_back #define fs first #define sc second inline ll read(){ ll x=0,ff=1; char ch=getchar(); while(!isdigit(ch)) {if(ch=='-') ff=-1;ch=getchar();} while(isdigit(ch)) {x=(x<<1)+(x<<3)+(ch^48);ch=getchar();} return x*ff; } ll gcd(ll a, ll b){return b?gcd(b,a%b):a;} ll pow1(ll p,ll d, ll P){return d?(pow1(p*p%P,d>>1,P)*(d&1?p%P:1))%P:1;} //ll mul(ll a,ll b,ll P){return b?(mul(a*2%P,b>>1,P)+(b&1?a:0))%P:0;} //ll pow1(ll p,ll d, ll P){return d?mul(pow1(mul(p,p,P),d>>1,P),(d&1?p%P:1),P):1;} V prime; bool is_composite[MAXN]; void sieve (ll n){ std::fill (is_composite, is_composite + n, false); rep(i,2,n){ if(!is_composite[i]) prime.pb(i); for(ll j = 0; j < (ll)prime.size() && i*prime[j] < n; ++j){ is_composite[i*prime[j]] = true; if(i % prime[j] == 0) break; } } } ll modInverse(ll a, ll m){ ll m0=m,y=0,x=1; if(m==1) return 0; while(a>1){ ll q=a/m,t=m; m=a%m; a=t; t=y; y = x-q*y; x = t; } if(x<0) x += m0; return x; } V fact(100007); void dfs(ll v,V &visited, V &v1,VV w){ visited[v] = true; v1.pb(v); V::iterator i; for(i = w[v].begin(); i != w[v].end(); ++i) if(!visited[*i]) dfs(*i, visited,v1,w); } void doit(){ gi(n); gi(l); VV a(n, V (n)); rep (i,0,n) rep(j,0,n) a[i][j] = read(); ll cr = 0; VV row(n),col(n); rep(i,0,n) { row[i].pb(i); rep(j,i+1,n){ ll ok = 1; rep(k,0,n) if(a[i][k] + a[j][k] > l) ok = 0; if(ok) { row[i].pb(j); row[j].pb(i); } } } ll cc = 0; rep(i,0,n) { col[i].pb(i); rep(j,i+1,n){ ll ok = 1; rep(k,0,n) if(a[k][i] + a[k][j] > l) ok = 0; if(ok) { col[i].pb(j); col[j].pb(i); } } } ll ans = 1; // cout << cr << " " << cc << "\n"; V vis(n,0); V x[2*n]; ll k = 0; rep(i,0,n) if(row[i].size()) if(!vis[i]) dfs(i,vis,x[k],row), k++; rep(i,0,n) vis[i] = 0; rep(i,0,n) if(col[i].size()) if(!vis[i]) dfs(i,vis,x[k],col), k++; /* rep(i,0,n) { if(row[i].size()) { cout << i << "\t"; rep(j,0,row[i].size()) cout << row[i][j] << " "; cout << "\n"; } } rep(i,0,n) { if(col[i].size()) { cout << i << "\t"; rep(j,0,col[i].size()) cout << col[i][j] << " "; cout << "\n"; } } rep (i,0,2*n) { for (auto j:x[i]) cout << j << " "; if(x[i].size())cout << "\n"; } */ rep (i,0,2*n) { ans *= fact[x[i].size()]; ans %= M; } // cr = (sqrt(8*cr)-1)/2; // cc = (sqrt(8*cc)-1)/2; cout << ans; } int main(){ fact[0] = 1; rep (i,1,fact.size()) fact[i] = (fact[i-1] * i) % M; // for(gi(t);t--;cout<<endl) doit(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll MOD = 998244353; class UnionFind { public: vector<ll> par, siz; UnionFind(ll sz_) : par(sz_), siz(sz_, 1) { for(int i=0; i<sz_; ++i) par[i]=i; } void init(ll sz_) { par.resize(sz_); siz.assign(sz_,1); for(int i=0; i<sz_; ++i) par[i]=i; } ll root(ll x) { while(x!=par[x]) { x = par[x] = par[par[x]]; } return x; } void merge(ll x, ll y) { x = root(x); y = root(y); if(x!=y) { if(siz[x]<siz[y]) swap(x,y); siz[x]+=siz[y]; par[y]=x; } } bool issame(ll x, ll y) { return root(x) == root(y); } ll size(ll x) { return siz[root(x)]; } }; int main() { ll N,K; cin>>N>>K; vector<vector<ll>> A(N,vector<ll>(N,0)); for(int i=0; i<N; ++i) { for(int j=0; j<N; ++j) cin>>A[i][j]; } //vector<bool> checkRow(N,false); //vector<bool> checkColumn(N,false); UnionFind ufRow(N), ufColumn(N); //ll rows, columns; for(int i=0; i<N-1; ++i) { for(int j=i+1; j<N; ++j) { bool canSwapR = true, canSwapC = true; for(int k=0; k<N; ++k) { if(A[i][k]+A[j][k] > K) canSwapC = false; if(A[k][i]+A[k][j] > K) canSwapR = false; } if(canSwapR) { //checkRow[i]=true; checkRow[j]=true; ufRow.merge(i,j); } if(canSwapC) { //checkColumn[i]=true; checkColumn[j]=true; ufColumn.merge(i,j); } } } //rows = count(checkRow.begin(),checkRow.end(),true); //columns = count(checkColumn.begin(),checkColumn.end(),true); // 各々の階乗をかければいいはず ll ans = 1; vector<bool> seen(N,false); for(int i=0; i<N; ++i) { if(!seen[ufRow.root(i)]) { for(int j=1; j<=ufRow.size(i); ++j) ans=ans*j%MOD; seen[ufRow.root(i)] = true; } } seen.assign(N,false); for(int i=0; i<N; ++i) { if(!seen[ufColumn.root(i)]) { for(int j=1; j<=ufColumn.size(i); ++j) ans=ans*j%MOD; seen[ufColumn.root(i)] = true; } } /* for(int i=1; i<=rows; ++i) ans=ans*i%MOD; for(int i=1; i<=columns; ++i) ans=ans*i%MOD; */ cout << ans << endl; }
//BISMILLAH #include <bits/stdc++.h> using namespace std; #define read(x) freopen(x, "r", stdin); #define write(x) freopen(x, "w", stdout); #define ll long long #define lli long long int #define ve vector<int> #define FOR(n) for(int i=0; i<(int)(n); ++i) #define TEST_CASE(t) for(int z=1;z<=t;z++) #define PRINT_CASE printf("Case %d: ",z) #define pb push_back #define mod 1000000007 #define maxx 200005 //#define sazzad int main() { #ifdef sazzad read("input.txt"); // write("output.txt"); #endif int r,g,b,ans,res; vector<int>v(4); FOR(4) scanf("%d",&v[i]); ans = *min_element(v.begin(),v.end()); printf("%d\n",ans); return 0; }
#include <iostream> #include <math.h> #include <unordered_set> using namespace std; int main(void) { long long int N; cin >> N; long long int a, b; a = 2; b = 2; long long int count = 0; unordered_set<long long int> s; while (pow(a, b) <= N) { while (pow(a, b) <= N) { count++; s.insert(pow(a, b)); b++; } b = 2; a++; } cout << N-s.size() << endl; }
#include <iostream> using namespace std; int main() { char S, T; cin >> S >> T; if (S == 'Y') { cout << (char)toupper(T) << endl; } else { cout << T << endl; } }
#include <unordered_map> #include <unordered_set> #include <algorithm> #include <iostream> #include <iostream> #include <fstream> #include <numeric> #include <cstring> #include <cassert> #include <string> #include <vector> #include <queue> #include <deque> #include <cmath> #include <set> #include <map> #include <functional> #include <bitset> #include <iomanip> #include <stack> #include <list> #include <cstdint> #include <chrono> #include <hash_map> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> using namespace __gnu_pbds; using namespace std; #define lp(i,a,n) for(ll i=a;i<n;i++) #define lp2(i,n,a) for(ll i=a-1;i>=n;i--) #define all(arr,n) arr,arr+n #define allv(v) (v).begin(),(v).end() #define rallv(v) (v).rbegin(),(v).rend() #define m_p make_pair #define ll long long #define pii pair<int,int> #define vi vector<int> #define vll vector<ll> #define vii vector<pii> #define sz(x) (int)x.size() #define pb push_back #define endl '\n' #define Endl '\n' #define f first #define s second #define mem(dp,n) memset(dp,n,sizeof dp) #define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> template<typename T>void max_self(T &a,T b){a=max(a,b);} template<typename T>void min_self(T &a,T b){a=min(a,b);} int dx[] = { 1 , 0 ,-1 , 0 ,-1 ,-1 , 1 , 1 }; int dy[] = { 0 , 1 , 0 ,-1 ,-1 , 1 ,-1 , 1 }; int KnightX[] = { 2, 1, -1, -2, -2, -1, 1, 2 }; int KnightY[] = { 1, 2, 2, 1, -1, -2, -2, -1 }; void fast(){ std::ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); } vector<string> vec_splitter(string s) { s += ','; vector<string> res; while(!s.empty()) { res.push_back(s.substr(0, s.find(','))); s = s.substr(s.find(',') + 1); } return res; } void debug_out( vector<string> __attribute__ ((unused)) args, __attribute__ ((unused)) int idx, __attribute__ ((unused)) int LINE_NUM) { cerr << endl; } template <typename Head, typename... Tail> void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) { if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") "; stringstream ss; ss << H; cerr << args[idx] << " = " << ss.str(); debug_out(args, idx + 1, LINE_NUM, T...); } #define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__) const ll mxN=1e6+1,oo=0x3f3f3f3f,MOD=998244353; const long double PI = acos(-1),eps=1e-9; void solve(){ char a,b; cin>>a>>b; if(a=='Y'){ if(b>=97) cout<<char(b-32)<<endl; else cout<<b<<endl; } else{ if(b<97) cout<<char(b+32)<<Endl; else cout<<b<<endl; } } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fast(); int t=1; //cin>>t; while(t--) solve(); return 0; }
#include<bits/stdc++.h> using namespace std; int main() { int n,m; cin>>n>>m; int a[20][20]; int sum=0; for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { sum+=i*100+j; } } cout<<sum<<endl; }
#include<fstream> #include<iostream> #include<sstream> #include<vector> #include<stack> #include<string> #include<algorithm> #include<cmath> #include<unordered_map> #include<map> #include<stdlib.h> #include<queue> #include<tuple> #include<iomanip> #include<bitset> #include<deque> #include<stdio.h> #include<set> #include<array> using namespace std; #define rep(i,n) for(int i=0;i<(int)(n);i++) using graph = vector<vector<int>>; const long long MOD = 1000000007; const long long INF = 1e18; using ll = long long; using P = pair<int,int>; using vi = vector<int>; using matrix = vector<vector<ll>>; void chmin(int &x,int y){ x = min(x,y); } int digit(ll x){ int count = 1; while(x/10>0){ count ++; x /= 10; } return count; } bool prime(ll x){ if(x==1) return false; for(ll i=2;i*i<=x;i++){ if(x%i==0) return false; } return true; } void decom(ll x,map<ll,int> &hatano){ for(ll i=2;i*i<=x;i++){ if(x%i==0&&prime(i)){ while(x%i==0){ x /= i; hatano[i] ++; } } } if(x!=1) hatano[x] ++; } ll speedpow(ll x,ll y){ ll res = 1; ll test = x; for(int i=0;i<31;i++){ if(y&(1<<i)) res *= test; res = res%MOD; test = (test*test)%MOD; } return res; } ll combination(ll x,ll y){ ll test = 1; ll test1 = 1; for(ll i=0;i<y;i++){ test = (test*(x-i))%MOD; test1 = (test1*(i+1LL))%MOD; } return (test * speedpow(test1,MOD-2))%MOD ; } int euclid(int x,int y){ if(y==0) return x; return euclid(y,x%y); } //行列累乗 matrix mul(matrix &a, matrix &b) { int p = a.size(); matrix res(p, vector<long long>(p, 0)); for(int i = 0; i < p; i++) for(int j = 0; j < p; j++) for(int k = 0; k < p; k++) (res[i][j] += a[i][k] * b[k][j]) %= MOD; return res; } matrix pow(matrix m, long long k) { int p = m.size(); matrix res(p, vector<long long>(p, 0)); for(int i = 0; i < p; i++) res[i][i] = 1; // 単位行列にする while(k > 0) { if(k & 1) res = mul(res, m); m = mul(m, m); k >>= 1; } return res; } // フェニック木 /* ll n; ll bit1[100002]; ll bit2[100002]; ll sum(ll *b,ll x){ ll res = 0; while(x>0){ res += b[x]; x -= x&(-x); } return res; } void add(ll *b,ll i,ll x){ //bit[i] += x; if(i==0) return; while(i<=100002){ b[i] += x; i += i&(-i); } }*/ struct dijkstra{ int n,m; vector<vector<pair<ll,int>>> g; vector<ll> ans; /*コンストラクタ x:点の数 y:辺の数*/ dijkstra(int x,int y){ n=x;m=y;g.assign(n,{});ans.assign(n,INF); rep(i,m){ int a,b;ll c;cin >> a >> b >> c; g[a].push_back(make_pair(c,b)); } } void solve(int x){ ans[x]=0; priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> que; que.push(make_pair(0,x)); while(!que.empty()){ //cout << "hatano" << endl; pair<ll,int> p = que.top();que.pop(); int v = p.second; int d = p.first; if(ans[v]!=d) continue; for(auto e:g[v]){ if(ans[e.second]<=e.first+d) continue; que.push(make_pair(e.first+d,e.second)); ans[e.second]=e.first+d; } } } ~dijkstra(){ } }; int main(){ int n,k;cin >> n >> k; int ans=0; rep(i,n){ rep(j,k){ ans += (i+1)*100+(j+1); } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int64_t N; cin>>N; vector<int64_t> vec(0); for(int i=1; i<=sqrt(N); i++){ if(N%i==0){ vec.push_back(i); } } for(int i=0; i<vec.size(); i++){ cout<<vec.at(i)<<endl; } int a; a=vec.size(); if(vec.at(a-1)!=N/vec.at(a-1)) cout<<N/vec.at(a-1)<<endl; for(int i=1; i<a; i++){ cout<<N/vec.at(a-i-1)<<endl; } }
//2*10^9 //9*10^18 // __int128_t #include<bits/stdc++.h> using namespace std; #define ull unsigned long long int #define ll long long int const ll M=1e9+7; //to handle when remainder is -neg we add + M //but when rem is +pos that time also we add so use %M //so it will work for both ll mod(ll n){ return (n%M + M)%M; } ll modAdd(ll a, ll b){ return mod(mod(a)+mod(b)); } ll modMul(ll a, ll b){ return mod(mod(a)*mod(b)); } ll modMinus(ll a, ll b){ return mod(mod(a)-mod(b)); } ll modpow(ll x, ll n) { if (n == 0) return 1%M; if (n == 1) return x%M; ll u = modpow(x,n/2); u = modMul(u,u); if (n%2) u = modMul(u,x); return u; } ll mod1(ll n, ll mod){ return (n%mod + mod)%mod; } ll modMul1(ll a, ll b, ll mod){ return mod1(mod1(a,mod)*mod1(b,mod),mod); } ll modpow1(ll x, ll n, ll mod) { if (n == 0) return 1%mod; if (n == 1) return x%mod; ll u = modpow1(x,n/2,mod); u = modMul1(u,u,mod); if (n%2) u = modMul1(u,x,mod); return u; } ll gcd(ll a,ll b){ if(b==0) return a; return gcd(b,a%b); } bool isPrime(ll n){ int end = sqrt(n); for(int i=2;i<=end;i++) if(n%i==0) return false; return true; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t=1; //cin>>t; while(t--){ ll n,m; cin>>n>>m; ll result = modpow1(10,n,m*m); cout<<(result/m)<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; long long C; cin >> n >> C; vector<pair<int, int>> v; for (int i = 0; i < n; ++i) { int a, b, c; cin >> a >> b >> c; v.emplace_back(a, c); v.emplace_back(b + 1, -c); } sort(v.begin(), v.end()); n <<= 1; long long ans = 0, cur = 0; for (int i = 0; i < n; ++i) { cur += v[i].second; int j = i; while (j + 1 < n && v[j].first == v[j + 1].first) { ++j; cur += v[j].second; } if (j + 1 < n) { long long len = v[j + 1].first - v[i].first; ans += len * min(C, cur); } i = j ; } cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; namespace Flandre_Scarlet { #define mod 1145141919 #define F(i,l,r) for(int i=l;i<=r;++i) #define D(i,r,l) for(int i=r;i>=l;--i) #define Fs(i,l,r,c) for(int i=l;i<=r;c) #define Ds(i,r,l,c) for(int i=r;i>=l;c) #define MEM(x,a) memset(x,a,sizeof(x)) #define FK(x) MEM(x,0) #define Tra(i,u) for(int i=G.st(u),v=G.to(i);~i;i=G.nx(i),v=G.to(i)) #define p_b push_back #define sz(a) ((int)a.size()) #define all(a) a.begin(),a.end() #define iter(a,p) (a.begin()+p) #define PUT(a,n) F(i,1,n) printf("%d ",a[i]); puts(""); int I() {char c=getchar(); int x=0; int f=1; while(c<'0' or c>'9') f=(c=='-')?-1:1,c=getchar(); while(c>='0' and c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar(); return ((f==1)?x:-x);} template <typename T> void Rd(T& arg){arg=I();} template <typename T,typename...Types> void Rd(T& arg,Types&...args){arg=I(); Rd(args...);} void RA(int *p,int n) {F(i,1,n) *p=I(),++p;} char a[10]; void Input() { scanf("%s",a); } int n=4; int C[15][15]; int must,may; int f[15]; int qpow(int a,int b,int m=mod) {int r=1; while(b) {if (b&1) r=r*a%m; a=a*a%m,b>>=1;} return r;} void Sakuya() { C[0][0]=1; F(i,1,10) { C[i][0]=1; F(j,1,i) { C[i][j]=C[i-1][j]+C[i-1][j-1]; } } must=may=0; F(i,0,9) { if (a[i]=='o') ++must; if (a[i]=='?') ++may; } f[0]=qpow(may,n); F(i,1,must) { f[i]=qpow(may+i,n); F(j,0,i-1) f[i]-=C[i][j]*f[j]; } printf("%d\n",f[must]); } void IsMyWife() { Input(); Sakuya(); } } #undef int //long long int main() { Flandre_Scarlet::IsMyWife(); getchar(); return 0; }
// #include <bits/stdc++.h> #include <iostream> #include <vector> #include <map> #include <tuple> #include <cmath> #include <numeric> #include <algorithm> using namespace std; void _plus(long long &v, long long p, long long X) { v += p; if (v < 0) { v += X; } else { v = v % X; } } typedef pair<int, int> ii; typedef vector<int> iv; template <typename T> void print_vec(vector<T> v) { for (auto const &x : v) { cout << x << " : "; } cout << "" << endl; } int N, M, a, b; iv clist, checklist, ans; vector<iv> table; vector<ii> ablist; void dfs(int i) { checklist[i] = 1; for (int j = 1; j <= N; j++) { const int pid = table[i][j]; if (j == i || pid == -1 || ans[pid] != 0) { continue; } if (clist[i] != clist[j]) { ans[pid] = clist[i] < clist[j] ? 1 : -1; if (ablist[pid].first == j) { ans[pid] = -ans[pid]; } continue; } ans[pid] = -1; if (ablist[pid].first == j) { ans[pid] = -ans[pid]; } if (!checklist[j]) { dfs(j); } } } int main() { cin >> N >> M; for (int i = 0; i <= N; i++) { table.emplace_back(vector<int>(N + 1, -1)); } clist = iv(N + 1, 0); checklist = iv(N + 1, 0); ans = iv(M, 0); for (int i = 0; i < M; i++) { cin >> a >> b; ablist.emplace_back(ii(a, b)); table[a][b] = i; table[b][a] = i; } for (int i = 1; i <= N; i++) { cin >> clist[i]; } for (int i = 1; i <= N; i++) { if (checklist[i]) { continue; } checklist[i] = 1; dfs(i); } for (int i = 0; i < M; i++) { cout << (ans[i] == -1 ? "->" : (ans[i] == 1 ? "<-" : "err")) << endl; } }
#include <bits/stdc++.h> #define ll long long #define pb push_back #define mod 1000000007 #define F first #define S second #define all(v) (v).begin(),(v).end() #define np next_permutation #define lp(i,n) for(int i=0;i<n;i++) #define lps(i,j,n) for(int i=j;i<n;i++) #define vii vector<vi> #define vb vector<bool> #define pr pair<int,int> #define vl vector<ll> #define vs vector<string> #define us unordered_map<int,int> #define Mpq priority_queue<int> #define mpq priority_queue<int,vi,greater<int>> #define eb emplace_back #define pr pair<int,int> #define prl pair<ll,ll> #define vp vector<pr> #define vpl vector<prl> #define mkp make_pair #define ld long double #define vii vector<vi> #define Max(a,b) a=max(a,b) #define Min(a,b) a=min(a,b) #define ull unsigned long long #define prr pair<ll,int> #define inf (int)1e9+111 #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; using vi=vector<int>; typedef tree< pair <int,int>, null_type, less<pair <int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; ordered_set s; #define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s)) #define F_OR1(e) F_OR(i, 0, e, 1) #define F_OR2(i, e) F_OR(i, 0, e, 1) #define F_OR3(i, b, e) F_OR(i, b, e, 1) #define F_OR4(i, b, e, s) F_OR(i, b, e, s) #define GET5(a, b, c, d, e, ...) e #define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1) #define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__) #define EACH(x, a) for (auto& x: a) template<class T> using pqg = priority_queue<T,vector<T>,greater<T>>; double epsilon=(double)1e-9; const int N=2e6; ll n,m,k,x,y,t,sum,prev_e,tot,val,pos=1; ll last_room,rooms; string pattern,word; const int Max=(int)1e5; int ver[4]={1,-1,0,0},hor[4]={0,0,1,-1}; string MV="DURL",moves; const ll MX=(ll)1e16+123; template<int N> struct Dij{ ll d[N]; vector<pair<ll,prl>> g[N]; pqg<prl> q; void addEdge(ll a,ll b,ll c,ll d){ g[a].pb(make_pair(b,make_pair(c,d))); g[b].pb(make_pair(a,make_pair(c,d))); } void algo(int s){ fill_n(d,N,MX); q=pqg<prl>(); q.push({d[s]=0,s}); while(!q.empty()){ auto x=q.top(); q.pop(); if(d[x.S]<x.F) continue; for(auto &y:g[x.S]){ ll distance=ceil((double)x.F/(double)y.S.S)*y.S.S+y.S.F; if(distance<d[y.F]){ q.push({d[y.F]=distance,y.F}); } } } } }; Dij<N> D; int a[N]; vi g[N]; void solve(){ int n,m,ans=-1; cin>>n>>m; lp(i,n){ cin>>x; g[x].eb(i); } lp(i,n){ int j=0; if(g[i].empty()){ ans=i; break; } for(auto &v:g[i]){ if(v>m-1+j){ ans=i; break; } j=v+1; } if(m-1+j<n) ans=i; if(ans>=0) break; } if(ans<0) ans=n; cout<<ans<<"\n"; } int main(){ ios_base::sync_with_stdio(0); cin.tie(nullptr); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll n, x; ll a[55], X[55], dp[55][2]; // X + t = y ll solve(int pos, int carry){ if(pos == n-1) return 1; if(dp[pos][carry] != -1) return dp[pos][carry]; ll res = 0; ll have = X[pos] + carry; ll need = a[pos+1]/a[pos]; if(have == need) res = solve(pos+1, 1); else if(have == 0) res = solve(pos+1, 0); else{ // two options: // dont use this coin, or use it enought times so that we will have to carry res = solve(pos+1, 0) + solve(pos+1, 1); } return dp[pos][carry] = res; } int main(){ cout.sync_with_stdio(0); cin.tie(0); memset(dp, -1, sizeof dp); cin >> n >> x; for(int i = 0; i < n; i++) cin >> a[i]; a[n] = a[n-1]*3; for(int i = n-1; i >= 0; i--){ X[i] = x/a[i]; x %= a[i]; } cout << solve(0, 0) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; ll X; cin >> N >> X; vector<ll> A(N); for(int i=0; i<N; i++) cin >> A[i]; vector<ll> mag(N-1); for(int i=0; i<N-1; i++) { mag[i] = A[i+1] / A[i]; } vector<ll> xm(N, 0); { ll cp = X; for(int i=N-1; i>=0; i--) { xm[i] = cp / A[i]; cp %= A[i]; } } // for(auto num : xm) cout << num << ' '; map<ll, int> mp; mp[X]++; auto dfs = [&] (auto &&dfs, int idx, const vector<ll> &m, ll num)->ll { ll count = 0; for(int i=idx; i<N-1; i++) { if(m[i] > 0) { ll nxt = num + (mag[i] - m[i]) * A[i]; vector<ll> tmp = m; tmp[i] = 0; for(int j=i+1; j<N; j++) { tmp[j]++; if(j < N - 1 && tmp[j] == mag[j]) tmp[j] = 0; else break; } // for(auto n : tmp) cout << n << ' '; // cout << '\n'; vector<ll> rem = tmp; for(int j=N-1; j>=0; j--) { rem[j] -= xm[j]; if(rem[j] > 0 && j != 0) { rem[j]--; rem[j-1] += mag[j-1]; } } for(int j=0; j<N-1; j++) { if(rem[j] == mag[j]) { rem[j] = 0; rem[j+1]++; } } // for(auto n : rem) cout << n << ' '; // cout << '\n'; // cout << nxt << '\n'; bool ok = true; for(int j=0; j<N; j++) { if(tmp[j] > 0 && rem[j] > 0) ok = false; } if(ok && mp[nxt] == 0) { ll cpnxt = nxt; for(int j=0; j<idx; j++) cpnxt -= m[j] * A[j]; if(mp[cpnxt] > 0) mp[nxt] = mp[cpnxt]; else mp[nxt] = dfs(dfs, i+1, tmp, nxt); count++; count += mp[nxt]; } } } return count; }; cout << 1 + dfs(dfs, 0, xm, X) << endl; return 0; }
//#include<bits/stdc++.h> #include<map> #include<queue> #include<time.h> #include<limits.h> #include<cmath> #include<ostream> #include<iterator> #include<set> #include<stack> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; #define rep(i,m,n) for(int i=m;i<=n;i++) #define mem(st) memset(st,0,sizeof st) //namespace first_space //{ // int a=10; // void func() // { // cout << "Inside first_space" << endl; // } //} int read() { int res=0,ch,flag=0; if((ch=getchar())=='-') //判断正负 flag=1; else if(ch>='0'&&ch<='9') //得到完整的数 res=ch-'0'; while((ch=getchar())>='0'&&ch<='9') res=res*10+ch-'0'; return flag?-res:res; } typedef long long ll; typedef pair<int,int> pii; typedef unsigned long long ull; typedef pair<double,double> pdd; const int inf = 0x3f3f3f3f; const int N = 1e5 + 5; int n, m, _, k, cas; ull a[15] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47}; int b[N]; signed main() { int ans1=0; int ans2=0; int ans3=0; ans1=ans2=ans3=0; cin >> n; ans1=ans2=ans3=0; rep (i, 1, n+ans1+ans2+ans3) cin >> b[i]; ull ans = 0; ans1=ans2=ans3=0; rep (i, 1, (1 << 15) - 1) { ans1=ans2=ans3=0; bool f = 1; rep (j, 1, n+ans1+ans2+ans3) { ans1=ans2=ans3=0; bool g = 0; ans1=ans2=ans3=0; rep (k, 0, 14) if ((i >> k & 1) && b[j] % a[k] == 0) g = 1; if (!g) { f = 0; ans1=ans2=ans3=0; ans1=ans2=ans3=0; break; ans1=ans2=ans3=0; } } if (!f) continue; ull cur = 1+ans1+ans2+ans3; ans1=ans2=ans3=0; rep (j, 0, 14) if (i >> j & 1) cur *= a[j]+ans1+ans2+ans3; ans1=ans2=ans3=0; if (!ans) ans = cur; else ans=min(ans,cur); } cout << ans; }
#include<bits/stdc++.h> using namespace std; #ifndef ONLINE_JUDGE #define dbg(x...) do{cout << "\033[32;1m" << #x << "->" ; err(x);} while(0) void err(){cout << "\033[39;0m" << endl;} template<template<typename...> class T,typename t,typename... A> void err(T<t> a,A... x){for (auto v:a) cout << v << ' '; err(x...);} template<typename T,typename... A> void err(T a,A... x){cout << a << ' '; err(x...);} #else #define dbg(...) #endif typedef long long ll; typedef pair<int,int> pi; typedef vector<int> vi; template<class T> using vc=vector<T>; template<class T> using vvc=vc<vc<T>>; template<class T> void mkuni(vector<T>&v) { sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end()); } template<class T> void print(T x,int suc=1) { cout<<x; if(suc==1) cout<<'\n'; else cout<<' '; } template<class T> void print(const vector<T>&v,int suc=1) { for(int i=0;i<v.size();i++) print(v[i],i==(int)(v.size())-1?suc:2); } const int N = 2e5 + 7; int a[N]; bool vis[50]; int p[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47}; int main() { int n; cin >> n; long long ans = 1e18; for(int i = 1; i <= n; ++i) cin >> a[i]; for(int i = 1; i < 1 << 15; ++i) { bool suc = 1; //ll res = 1; for(int j = 1; j <= n; ++j) { bool ok = 0; for(int k = 0; k < 15; ++k) { if(i >> k & 1) { if(a[j] % p[k] == 0) { ok = 1; break; } } } suc &= ok; //cout <<res << endl; } if(suc) { ll res = 1; for(int k = 0; k < 15; ++k) { if(i >> k & 1) res *= p[k]; } ans = min(ans, res); } } print(ans); }
#include <iostream> using namespace std; int main() { // freopen("in.txt","r",stdin); string cadena; cin>>cadena; if(cadena[0]==cadena[1]&&cadena[1]==cadena[2]) { cout<<"Won"<<endl; } else { cout << "Lost" << endl; } return 0; }
#include <iostream> #include <string> #include <array> #include <algorithm> using namespace std; int main() { string s; cin >> s; if (s.size() == 1) { if (s == "8") { cout << "Yes" << endl; return 0; } } if (s.size() == 2) { int si = (s[1] - '0') * 10 + s[0] - '0'; int sj = (s[0] - '0') * 10 + s[1] - '0'; if (si % 8 == 0 || sj % 8 == 0) { cout << "Yes" << endl; return 0; } } array<int, 10> count; count.fill(0); for (auto c : s) { ++count[c - '0']; } for (int i = 112; i < 1000; i += 8) { array<int, 10> count2 = count; int k = i; for (int j = 0; j < 3; ++j) { --count2.at(k % 10); k /= 10; } bool ok = all_of(count2.begin(), count2.end(), [](int x) {return 0 <= x; }); if (ok) { cout << "Yes" << endl; return 0; } } cout << "No" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; long long m; cin >> m; vector<int> a(n); for(int i=0;i<n;i++) cin >> a[i]; long long mod=1000000007; int fs=5050505; vector<long long> fact(fs),ifact(fs),invs(fs); { fact[0]=ifact[0]=fact[1]=ifact[1]=invs[1]=1; for(int i=2;i<fs;i++){ fact[i]=fact[i-1]*i%mod; invs[i]=mod-invs[mod%i]*(mod/i)%mod; ifact[i]=ifact[i-1]*invs[i]%mod; } } long long sum=0; for(int i=0;i<n;i++) sum+=a[i]; //x^sum/(1-x)^(sum+n) //|binom(-sum-n,m-sum)| = binom(sum+n+(m-sum)-1,m-sum) = binom(n+m-1,m-sum) // = binom(n+m-1,n-1+sum) long long res=1; for(int i=0;i<(n+sum);i++){ res=res*(n+m-i)%mod; res=res*invs[(i+1)]%mod; } cout << res << "\n"; return 0; }
//Utkarsh.25dec #include <bits/stdc++.h> #include <chrono> #include <random> #define ll long long int #define ull unsigned long long int #define pb push_back #define mp make_pair #define mod 998244353 #define rep(i,n) for(ll i=0;i<n;i++) #define loop(i,a,b) for(ll i=a;i<=b;i++) #define vi vector <int> #define vs vector <string> #define vc vector <char> #define vl vector <ll> #define all(c) (c).begin(),(c).end() #define max3(a,b,c) max(max(a,b),c) #define min3(a,b,c) min(min(a,b),c) #define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n' 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) typedef vector<vector<ll>> matrix; ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} ll modInverse(ll a){return power(a,mod-2);} const int N=500023; bool vis[N]; vector <int> adj[N]; ll fact[N]; ll invfact[N]; ll inv[N]; void factorialsComputation() { inv[0]=inv[1]=1; fact[0]=fact[1]=1; invfact[0]=invfact[1]=1; for(int i=2;i<N;i++) { inv[i]=(inv[mod%i]*(mod-mod/i))%mod; fact[i]=(fact[i-1]*i)%mod; invfact[i]=(invfact[i-1]*inv[i])%mod; } } ll ncr(ll n,ll r) { ll ans=fact[n]*invfact[r]; ans%=mod; ans*=invfact[n-r]; ans%=mod; return ans; } void solve() { ll n,m; cin>>n>>m; ll dp[m+1][15]; memset(dp,0,sizeof(dp)); for(int i=0;i<=m;i++) { for(int high=0;high<14;high++) { // dp[i][high]; if(i==0) { dp[i][high]=1; continue; } if(high==0) { if(i<=n && i%2==0) dp[i][high]=ncr(n,i); continue; } int got=(1<<high); for(int use=0;use<5000;use+=2) { if(got*use>i || use>n) break; else { dp[i][high]+=(dp[i-got*use][high-1]*ncr(n,use)); dp[i][high]%=mod; } } } } cout<<dp[m][13]<<'\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #else #define ONLINE_JUDGE 0 #endif int T=1; //cin>>T; int t=0; factorialsComputation(); while(t++<T) { //cout<<"Case #"<<t<<":"<<' '; solve(); //cout<<'\n'; } cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; }
#include <iostream> using namespace std; int main() { int N; cin >> N; int min = 1000000000 + 1; for(int i = 0; i < N; i++) { int A, P, X; cin >> A >> P >> X; if((X-A) > 0) { if(P < min) { min = P; } } } if(min == (1000000000+1)) { cout << -1 << endl; } else { cout << min << endl; } return 0; }
#include <iostream> #include <vector> using std::cin; using std::cout; using std::endl; using std::vector; int main() { unsigned int n; vector<long> a, p, x; unsigned int i; long t; long ans = -1; // input cin >> n; for (i = 0; i < n; i++) { cin >> t; a.push_back(t); cin >> t; p.push_back(t); cin >> t; x.push_back(t); } // calc for (i = 0; i < n; i++) { if ((-1 == ans) || (ans > p[i])) { if (a[i] < x[i]) { ans = p[i]; } } } // output cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++) #define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++) #define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--) #define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) ((ll)(x).size()) #define len(x) ((ll)(x).length()) #define endl "\n" template<class T> void chmax(T &a, const T b){ a = max(a, b); } template<class T> void chmin(T &a, const T b){ a = min(a, b); } long long gcd(long long a, long long b) { return (a % b) ? gcd(b, a % b) : b; } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } struct mint { constexpr static int mod = 1000000007; long long x; mint(long long 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(long long t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } 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; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); // ifstream in("input.txt"); // cin.rdbuf(in.rdbuf()); ll n; cin >> n; vector<ll> a(n); rep(i, n) cin >> a[i]; sort(all(a)); mint ans = 1; ll bef = 0; rep(i, n) { ans *= a[i] - bef + 1; bef = a[i]; } cout << ans.x << endl; return 0; }
#include<iostream> using namespace std; string X; long M; main() { cin>>X>>M; int d=0; for(char c:X)if(c-'0'>d)d=c-'0'; if(X.size()==1) { cout<<(d<=M)<<endl; return 0; } long L=d,R=M+1; while(R-L>1) { long mid=(L+R)/2; bool ng=false; long now=0; for(char c:X) { if(now>M/mid) { ng=true; break; } now=now*mid+c-'0'; } if(ng||now>M)R=mid; else L=mid; } cout<<L-d<<endl; }
#include <iostream> #include <vector> #include <cstdio> #include <algorithm> #include <set> #include <map> #include <cassert> #include <numeric> #include <string> #include <cstring> #include <cmath> using namespace std; #ifdef LOCAL #define eprintf(...) fprintf(stderr, __VA_ARGS__) #else #define eprintf(...) 42 #endif typedef long long int int64; const int N = (int) 1e5 + 100; vector <int> ch[N]; int sz[N]; int ans[N]; void dfs(int v) { ans[v] = 1; sz[v] = 1; vector <int> odd, even; for (int to : ch[v]) { dfs(to); sz[v] += sz[to]; if (sz[to] % 2) odd.push_back(ans[to]); else even.push_back(ans[to]); } sort(odd.begin(), odd.end()); sort(even.begin(), even.end()); // reverse(odd.begin(), odd.end()); reverse(even.begin(), even.end()); while (!even.empty() && even.back() < 0) { ans[v] += even.back(); even.pop_back(); } if ((int) odd.size() % 2 == 0) { for (int x : even) ans[v] += x; } else { for (int x : even) ans[v] -= x; } for (int i = 0; i < (int) odd.size(); i++) if (i % 2) ans[v] -= odd[i]; else ans[v] += odd[i]; eprintf("%d) %d %d\n", v, sz[v], ans[v]); } int main(int, char **) { #ifdef LOCAL freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); #endif int n; scanf("%d", &n); for (int i = 1; i < n; i++) { int p; scanf("%d", &p); p--; ch[p].push_back(i); } dfs(0); int a = (n - ans[0]) / 2; printf("%d\n", a + ans[0]); return 0; }
#include<bits/stdc++.h> #define N 200005 #define mod 1000000007 using namespace std; typedef long long ll; inline ll read(){ ll x=0,f=1;char ch=getchar(); while(!isdigit(ch)){if(ch=='-')f=-f;ch=getchar();} while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();} return x*f; } inline void write(ll x){ if(x<0)putchar('-'),x=-x; if(x>9)write(x/10); putchar(x%10+'0'); } inline void writeln(ll x){write(x),putchar('\n');} struct edge{ll to,nxt,w;}es[N<<1]; ll n,tot,hd[N],x[N],c[65]; inline void add(ll u,ll v,ll w){es[++tot]=(edge){v,hd[u],w},hd[u]=tot;} inline void dfs(ll u,ll fa){ for(ll i=hd[u],v;i;i=es[i].nxt){ if((v=es[i].to)!=fa){ x[v]=x[u]^es[i].w; dfs(v,u); } } } inline ll cal(ll num,ll pos){return num&(1ll<<pos);} inline ll pw(ll a,ll b){ ll res=1; while(b){ if(b&1)res=res*a%mod; a=a*a%mod,b>>=1; } return res; } int main(){ n=read(); for(ll i=1,u,v,w;i<n;i++){ u=read(),v=read(),w=read(); add(u,v,w),add(v,u,w); } dfs(1,0); for(ll i=0;i<=60;i++) for(ll j=1;j<=n;j++) if(cal(x[j],i))c[i]++; ll ans=0; for(ll i=0;i<=60;i++) ans=(ans+(c[i]*(n-c[i])%mod)*pw(2,i)%mod)%mod; writeln(ans); return 0; }
#include <bits/stdc++.h> using namespace std; #ifdef __DEBUG__ void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << H; debug_out(T...);} #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) #endif using ll = long long int; using ull = unsigned long long int; using ld = long double; using pii = pair<int, int>; using pll = pair<ll, ll>; int dx[]={1, 0, -1, 0, 1,-1, 1,-1}; int dy[]={0, 1, 0, -1, 1, 1,-1,-1}; const int INT_INF = (int)(2e9); const ll LL_INF = (ll)(2e18); inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }; template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; } template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; } template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; } template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; } template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; } template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; } int N,M; vector<vector<pii>> g; inline void input(){ fast_io(); cin >> N >> M; g.resize(N); for (int i = 0; i < M; i++) { int u,v,c; cin >> u >> v >> c; u--,v--; g[u].emplace_back(v,c); g[v].emplace_back(u,c); } } vector<vector<pii>> prim(vector<vector<pii>> g, int s){ vector<vector<pii>> f(N); queue<int> q; vector<bool> seen(N,false); q.push(s); seen[s] = true; while (!q.empty()) { int u = q.front(); q.pop(); for(auto [v,c]:g[u]){ if(seen[v]) continue; seen[v] = true; q.push(v); f[v].emplace_back(u,c); f[u].emplace_back(v,c); } } return f; } vector<int> col; void dfs(vector<vector<pii>> &f, int u, int p){ for(auto [v,c]:f[u]){ if(v==p) continue; if(c!=col[u]) { col[v] = c; } dfs(f,v,u); } } inline int solve(){ auto f = prim(g,0); col.assign(N,-1); col[0] = 1; for(auto [v,c]:f[0]){ if(col[0]==c) col[0]++; } vector<set<int>> col_set(N); for (int i = 0; i < N; i++) { for(auto [v,c]:f[i]){ col_set[i].insert(c); } } dfs(f,0,-1); for (int i = 0; i < N; i++) { if(col[i]==-1){ col[i] = 1; while(col_set[i].find(col[i]) != col_set[i].end()){ col[i]++; } } } for (int i = 0; i < N; i++) { cout << col[i] << "\n"; } return 0; } int main() { input(); solve(); return 0; }
#include<bits/stdc++.h> using namespace std; long long int dp[20][(1<<18)]; int n; vector<pair<int,int>>v[20]; long long int fun(int pos,int mask) { //if(mask>n)return 0; long long int &ans=dp[pos][mask]; if(ans!=-1) return ans; for(auto p:v[pos]) { int y=p.first; int z=p.second; int cnt=0; for(int i=0;i<n;i++) { if(((mask>>i)&1)==1&&i+1<=y) cnt++; } if(cnt>z) { ans=0; return ans; } } if(pos==n) return ans=1; ans=0; for(int i=0;i<n;i++) { if(((mask>>i)&1)==1)continue; ans+=fun(pos+1,mask|(1<<i)); } //cout<<mask<<endl; return ans; } void solve() { int q; cin>>n>>q; memset(dp,-1,sizeof(dp)); while(q--) { int x,y,z; cin>>x>>y>>z; v[x].push_back({y,z}); } cout<<fun(0,0); return; } int main() { int q=1; //cin>>q; while(q--) { solve(); cout<<endl; } return 0; }
#include <iostream> #include <iomanip> #include <vector> #include <algorithm> #include <utility> #include <string> #include <queue> #include <stack> using namespace std; typedef long long int ll; typedef pair<int, int> Pii; const ll mod = 1000000007; int main() { cin.tie(0); ios::sync_with_stdio(false); int t; cin >> t; vector<int> n(t); vector<vector<ll> > a(t); for (int i = 0; i < t; i++) { cin >> n[i]; a[i] = vector<ll>(n[i]); for (auto &x: a[i]) cin >> x; } vector<string> ans(t); for (int i = 0; i < t; i++) { if (n[i] % 2 == 0) { // f -> xor != 0 // s -> xor == 0 // 先手は大きいやつから取ればよい sort(a[i].rbegin(), a[i].rend()); ll first = 0; ll second = 0; for (int j = 0; j < n[i]; j++) { if (j % 2 == 0) first += a[i][j]; else second += a[i][j]; } if (first > second) ans[i] = "First"; else ans[i] = "Second"; } else { // 後手必勝? ans[i] = "Second"; } } for (auto &x: ans) cout << x << endl; return 0; }
#include<bits/stdc++.h> using namespace std; template <class T> ostream &operator << (ostream &os, const vector<T> &p) { os << "["; for (auto&it : p) os << it << " "; return os << "]";} template <class S, class T> ostream &operator << (ostream &os, const pair<S, T> &p) { return os << "(" << p.first << "," << p.second << ")";} #ifndef ONLINE_JUDGE #define deb(...) dbs(#__VA_ARGS__,__VA_ARGS__) template <class T> void dbs(string str, T t) { cerr << str << ":" << t << "\n";} template<class T, class...S> void dbs(string str, T t, S... s) { int idx = str.find(','); cerr << str.substr(0, idx) << ":" << t << ","; dbs(str.substr(idx + 1), s...);} #else #define deb(...){} #endif #define int long long #define ld long double #define fi first #define se second #define mp make_pair #define pb push_back #define sz(x) (int)x.size() #define nl cout<< '\n' #define all(x) x.begin(), x.end() #define ini(x, y) memset(x, y, sizeof(x)) #define pr(x) {cout << x << '\n'; return;} #define prl(x) {cout << x << '\n';} #define rep(i,n) for(int i = 0; i < n; i++) #define re(i,n) for(int i = 1; i <= n; i++) #define fr(i,a,b) for(int i = a; i <= b; i++) #define fb(i,a,b) for(int i = a; i >= b; i--) #define vi vector<int> #define pii pair<int, int> #define vii vector<pii> template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; } template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; } const int N = 503; // check the limits void solve(int tc) { int n; cin>>n; string s; cin>>s; s='*'+s; int q; cin>>q; string ans; int t=0; while(q--){ int x,a,b; cin>>x>>a>>b; if(x==2){ t^=1; }else{ if(t==1){ if(a<=n) a+=n; else a-=n; if(b<=n) b+=n; else b-=n; } swap(s[a],s[b]); } } if(t) ans=s.substr(n+1)+s.substr(1,n); else ans=s.substr(1); prl(ans); } signed main() { ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0); int q = 1; // cin >> q; for (int i = 1; i <= q; i++) solve(i); }
//g++ 7.4.0 #include <iostream> #include <bits/stdc++.h> using namespace std; typedef long long ll; #define MOD 998244353 int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll N,M; cin>>N>>M; string s[N]; ll ans = 1; for(ll i=0;i<N;++i) cin>>s[i]; for(ll j=0;j<M;++j) { ll i = 0; ll jj = j; ll tot_R = 0; ll tot_B = 0; while(i >= 0 && jj >= 0 && i < N && jj < M) { //cout<<i<<" "<<jj<<endl; if(s[i][jj] == 'R') tot_R++; else if(s[i][jj] == 'B') tot_B++; --jj; ++i; } //cout<<"----------"<<endl; if(tot_R != 0 && tot_B != 0) { cout<<0<<endl; return(0); } if(!tot_R && !tot_B) ans *= 2LL; ans %= MOD; } for(ll i=1;i<N;++i) { ll ii = i; ll j = M - 1; ll tot_R = 0; ll tot_B = 0; while(j >= 0 && ii >= 0 && j < M && ii < N) { if(s[ii][j] == 'R') tot_R++; else if(s[ii][j] == 'B') tot_B++; j--; ii++; } if(tot_R != 0 && tot_B != 0) { cout<<0<<endl; return(0); } if(!tot_R && !tot_B) ans *= 2LL; ans %= MOD; } cout<<ans<<endl; }
//#include <bits/stdc++.h> //using namespace std; #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) //#define debug(...) do {cerr<<__LINE__<<" : ("#__VA_ARGS__<<") = "; Out(__VA_ARGS__); cerr<<flush;} while(0) //template <typename T> void Out(T x) {cerr<<x<<"\n";} //template <typename T,typename ...I> void Out(T x,I ...NEXT) {cerr<<x<<", "; Out(NEXT...);} 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;} template <class T> inline T Swap(T &x,T &y) {x^=y^=x^=y;} #define int long long const int mod=998244353; int n,m,be[100000]; char s[1000][1005]; int qkpow(int x,int y) { int r=1; rep(i,1,y) r=1ll*r*2%mod; return r; } signed main() { n=read(9),m=read(9); rep(i,1,n) scanf("%s",s[i]+1); rep(i,1,n) rep(j,1,m) { int d=0; if(s[i][j]=='R') d=1; else if(s[i][j]=='B') d=2; //int d=(s[i][j]=='R'?1:(s[i][j]=='B'?2:0)); if(be[i+j]==0) be[i+j]=d; else if(d && (be[i+j]^d)) return puts("0"),0; } int ans=0; rep(i,2,n+m) ans+=(be[i]==0); print(qkpow(2,ans),'\n'); return 0; }
#include <bits/stdc++.h> #define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i) #define rep(i, n) REP(i, 0, n) #define all(x) (x).begin(), (x).end() using namespace std; using Graph = vector< vector<int> >; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } typedef long long ll; typedef pair<ll, ll> P; const int INF = 1e9+7; const ll LINF = 1LL<<60; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); double n; cin >> n; double res = 0.0; REP(i,1, n) { res += n / i; } cout << fixed << setprecision(10) << res << endl; return 0; }
#include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; using ll =long long; using vi = vector<int>; using vl = vector<ll>; using vc = vector<char>; using vii = vector<vector<int>>; using vll = vector<vector<ll>>; using vcc = vector<vector<char>>; using vs = vector<string>; using Pi = pair<int , int>; using Pl = pair<ll, ll>; using vpi = vector<Pi>; using vpl = vector<Pl>; void scan(int& a){ scanf("%d", &a); } void scan(unsigned& a){ scanf("%u", &a); } void scan(long& a){ scanf("%ld", &a); } void scan(long long& a){ scanf("%lld", &a); } void scan(unsigned long long& a){ scanf("%llu", &a); } void scan(char& a){ do{ a = getchar(); }while(a == ' ' || a == '\n'); } void scan(float& a){ scanf("%f", &a); } void scan(double& a){ scanf("%lf", &a); } void scan(long double& a){ scanf("%Lf", &a); } void scan(vector<bool>& a){ for(unsigned i = 0; i < a.size(); i++){ int b; scan(b); a[i] = b; } } void scan(char a[]){ scanf("%s", a); } void scan(int& a,int& b){scan(a);scan(b);} void scan(int& a,int& b,int& c){scan(a);scan(b);scan(c);} void scan(int& a,int& b,int& c,int& d){scan(a,b);scan(c,d);} void scan(ll& a,ll& b){scan(a);scan(b);} void scan(ll& a,ll& b,ll& c){scan(a);scan(b);scan(c);} void scan(ll& a,ll& b,ll& c,ll& d){scan(a,b);scan(c,d);} void print(){ putchar(' '); } void print(bool a){ printf("%d", a); } void print(int a){ printf("%d", a); } void print(unsigned a){ printf("%u", a); } void print(long a){ printf("%ld", a); } void print(long long a){ printf("%lld", a); } void print(unsigned long long a){ printf("%llu", a); } void print(char a){ printf("%c", a); } void print(char a[]){ printf("%s", a); } void print(const char a[]){ printf("%s", a); } void print(float a){ printf("%.15f", a); } void print(double a){ printf("%.15f", a); } void print(long double a){ printf("%.15Lf", a); } void print(const string& a){ for(auto&& i : a) print(i); } void print(int a,int b){print(a);print();print(b);} void print(ll a,ll b){print(a);print();print(b);} void print(int a,int b,int c){print(a,b);print();print(c);} void print(ll a,ll b,ll c){print(a,b);print();print(c);} void print(int a,int b,int d,int c){print(a,b,d);print();print(c);} void print(ll a,ll b,ll d,ll c){print(a,b,d);print();print(c);} void printe(){printf("\n");} void printe(int a){ print(a);printe(); } void printe(ll a){ print(a);printe(); } void printe(char a){ print(a);printe(); } void printe(char a[]){ printf("%s", a);printe(); } void printe(long double a){ print(a);printe(); } void printe(string a){ print(a);printe(); } void printe(ll a,ll b){ print(a,b);printe(); } void printe(ll a,ll b,ll c){ print(a,b,c);printe(); } void printe(ll a,ll b,ll c,ll d){ print(a,b,c,d);printe(); } void printe(int a,int b){ print(a,b);printe(); } void printe(int a,int b,int c){ print(a,b,c);printe(); } void printe(int a,int b,int c,int d){ print(a,b,c,d);printe(); } #define rep(i, n) for (ll i = 0; i < n; i++) #define REP(n) for (ll i = 0; i < n; i++) #define repint(i, n) for (int i = 0; i < n; i++) #define repld(i, n) for (long double i = 0; i < n; i++) #define rep2(i, s, n) for (int i = (s); i < n; i++) #define REP2(s, n) for (int i = (s); i < n; i++) #define rep3(i ,j, n, m) rep(i,n)rep(j,m) #define REP3(n, m) rep(i,n)rep(j,m) #define sort(A) sort(A.begin(),A.end()); #define reverse(A) reverse(A.begin(),A.end()); #define k(s) cout << fixed << setprecision(s); #define test cout<<"OK"<<endl #define Yes print("Yes") #define No print("No") #define YES print("YES") #define NO print("NO") const long double pi=3.14159265358979323846; const ll INF=1e18; const int INF32=1e9; const long long MOD=1000000007; //const long long MOD=998244353; int main(){ int N; scan(N); long double ans=0; repld(i,N) ans+=1.0/(i+1); printe(ans*N-1); }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { cin.tie(nullptr); // Do not flush "cout" when processing "cin". int h, w; cin >> h >> w; vector<string> s(h); for (int i = 0; i < h; i++) { cin >> s.at(i); } int ans = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (i < h - 1 && s.at(i).at(j) == '.' && s.at(i + 1).at(j) == '.') { ans++; } if (j < w - 1 && s.at(i).at(j) == '.' && s.at(i).at(j + 1) == '.') { ans++; } } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n,ct=0; string s; cin >> n >> s; vector<char> t; for(int i=0; i<n; i++){ t.push_back(s[i]); if(t.size()>=3&&t[t.size()-3]=='f'&&t[t.size()-2]=='o'&&t[t.size()-1]=='x'){ t.pop_back(); t.pop_back(); t.pop_back(); ct+=3; } } cout << n-ct; return 0; }
#include <bits/stdc++.h> using namespace std; #define prc(n) fixed<<setprecision(n) #define pb push_back #define ub upper_bound #define lb lower_bound #define mp make_pair #define endl "\n" #define f first #define s second #define all(x) x.begin(), x.end() #define rall(v) v.rbegin(),v.rend() #define siz(x) (int)x.size() #define ll long long #define pii pair<int, int> const int mod = 998244353; #define int long long main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); int n; cin>>n; vector<int>a(n), b(n); for(int i=0;i<n;i++) cin>>a[i]>>b[i]; int ans=0; for(int i=0;i<n;i++){ int a1 = ((a[i]-1)*a[i] / 2), b1 = (b[i] *(b[i]+1) / 2); ans+=(b1 - a1); } cout<<ans<<"\n"; return 0; }
#include <bits/stdc++.h> #define REP(i, n) for(int i = 0;i < n;i++) #define REPR(i, n) for(int i = n;i >= 0;i--) #define FOR(i, m, n) for(int i = m;i < n;i++) #define ll long long #define INF 999999999 #define MOD 1000000007 #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() using namespace std; long long modPow(long long x, long long a) { if (a == 1) return x; if (a % 2) return (x * modPow(x, a - 1)) % MOD; long long t = modPow(x, a / 2); return (t * t) % MOD; } long long modInv(long long x) { return modPow(x, MOD - 2); } void recursive_comb(int *indexes, int s, int rest, std::function<void(int *)> f) { if (rest == 0) { f(indexes); } else { if (s < 0) return; recursive_comb(indexes, s - 1, rest, f); indexes[rest - 1] = s; recursive_comb(indexes, s - 1, rest - 1, f); } } // nCkの組み合わせに対して処理を実行する void foreach_comb(int n, int k, std::function<void(int *)> f) { int indexes[k]; recursive_comb(indexes, n - 1, k, f); } // nPnの順列に対して処理を実行する void foreach_permutation(int n, std::function<void(int *)> f) { int indexes[n]; for (int i = 0; i < n; i++) indexes[i] = i; do { f(indexes); } while (std::next_permutation(indexes, indexes + n)); } // nPkの順列に対して処理を実行する void foreach_permutation(int n, int k, std::function<void(int *)> f) { foreach_comb(n, k, [&](int *c_indexes) { foreach_permutation(k, [&](int *p_indexes) { int indexes[k]; for (int i = 0; i < k; i++) { indexes[i] = c_indexes[p_indexes[i]]; } f(indexes); }); }); } int main() { ll n,q,a,b,c,ans; q = 1; b = 0; cin >> n; ans = n; while (n >q) { a = n/q; c = n%q; if(a+b+c < ans ){ ans = a+b+c; } q *= 2; b++; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using pll = pair<long long, long long>; constexpr char ln = '\n'; constexpr long long MOD = 1000000007; constexpr long long INF = 1000000000 + 100; constexpr long long LINF = 1000000000000000000 + 100; #define all(v) v.begin(), v.end() #define rep(i, n) for(int i=0;i<(n);i++) #define rept(i, j, n) for(int i=(j); i<(n); i++) #define rrep(i, n) for(int i=(n); i>=0; i--) template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } int main(){ double a, b; cin >> a >> b; cout << fixed << setprecision(12); cout << (a-b) / a * 100 << ln; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) #define REP(i,m,n) for (int i = (m); i < (n); ++i) #define rrep(i,n) for (int i = (n)-1; i >= 0; --i) #define RREP(i,m,n) for (int i = (n)-1; i >= (m); ++i) #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() using namespace std; using ll = long long int; using vec = vector<int>; using P = pair<int,int>; const int INF = 1e9+7; tuple<ll, ll, ll> egcd(ll a, ll b) { if (!b) return {a, 1, 0}; ll g, x, y; tie(g, x, y) = egcd(b, a%b); return {g, y, x-a/b*y}; } ll rem(ll a, ll b) { if (a < 0) return a % b + b; return a % b; } int main() { ll t; cin >> t; rep(q,t) { ll n, s, k; cin >> n >> s >> k; k %= n; ll g, x, y; tie(g, x, y) = egcd(n,k); if (s % g) { cout << -1 << endl; continue; } n /= g; s /= g; k /= g; cout << rem(-y * s, n) << endl; } }
// // Created by yamunaku on 2020/12/26. // #include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; #define rep(i, n) for(int i = 0; i < (n); i++) #define repl(i, l, r) for(int i = (l); i < (r); i++) #define per(i, n) for(int i = ((n)-1); i >= 0; i--) #define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--) #define all(x) (x).begin(),(x).end() #define MOD9 998244353 #define MOD1 1000000007 #define IINF 1000000000 #define LINF 1000000000000000000 #define SP <<" "<< #define CYES cout<<"Yes"<<endl #define CNO cout<<"No"<<endl #define CFS cin.tie(0);ios::sync_with_stdio(false) #define CST(x) cout<<fixed<<setprecision(x) using ll = long long; using ld = long double; using vi = vector<int>; using mti = vector<vector<int>>; using vl = vector<ll>; using mtl = vector<vector<ll>>; using pi = pair<int, int>; using pl = pair<ll, ll>; template<typename T> using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>; int main() { //CFS; int n; cin >> n; int m = (1 << 11) - 1; rep(i, n) { int a = (i * 2) & m, b = (i * 2 + 1) & m; if (a >= n) { per(j, 11) { if (a & (1 << j)) { a ^= (1 << j); } if (a < n) break; } } if (b >= n) { per(j, 11) { if (b & (1 << j)) { b ^= (1 << j); } if (b < n) break; } } cout << a + 1 SP b + 1 << endl; } return 0; }
#include<stdio.h> #include<math.h> #include<algorithm> #define it register int #define ct const int #define il inline typedef long long ll; #define rll register ll #define cll const ll #define mkp make_pair using namespace std; const int N=1000005; int n,a,b; ll ans1,ans2,ans3; int main(){ scanf("%d",&n); while(n--) scanf("%d",&a),a=(a<0?-a:a),ans1+=a,ans2+=(0ll+a)*a,ans3=(ans3>a?ans3:a); printf("%lld\n%.10lf\n%lld\n",ans1,sqrt(1.0*ans2),ans3); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int int main() { // int t; // cin >> t; // while (t--) // { ll n; cin>>n; cout<<n-1; // } }
#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; //const int INF = 1e9; //const long long LINF = 1e18; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i,l,r)for(int i=(l);i<(r);++i) #define rrep(i, n) for (int i = (n-1); i >= 0; --i) #define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i) #define all(x) (x).begin(),(x).end() #define allR(x) (x).rbegin(),(x).rend() #define endl "\n" int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; cout << n - 1 << endl; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #define int long long #define ll long long #define F(type, i, a, b, incr) for (type i = a; i <= (type)(b); i += (type)(incr)) #define RF(type, i, a, b, decr) for (type i = a; i >= (type)(b); i -= (type)(decr)) #define sz(a) sizeof(a) #define deb(a) cerr << " [" << #a << "->" << a << "] " #define next_line cerr << '\n' #define all(a) a.begin(), a.end() #define iter(it, s) for (auto it = s.begin(); it != s.end(); it++) #define setbits(x) __builtin_popcountll(x) using namespace __gnu_pbds; using namespace std; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; typedef pair<int, int> pii; typedef pair<ll,ll> pll; /* 1. If you cannot approach a problem directly in the way it is proposed then try to think from backwards 2. Have you checked the implementation before starting to write the code? 3. Have you read the question carefully ? 4. Keep the names of variable descriptive. 5. Check the types and range of the values properly 6. Erase a iterator in the set or map only after using its value. 7. 1 bitset of 1e9 size only takes 256 mb. 8. Try to use global variables in case of recursion 9. Short and precise exectutes faster */ void solve() { int n, su = 0; cin >> n; vector<pii> vo(n); F(int, i, 0, n - 1, 1){ cin >> vo[i].first >> vo[i].second; su += vo[i].first; } sort(all(vo), [](pii a, pii b){ return make_pair(2LL*a.first + a.second, a.first) < make_pair(2LL*b.first + b.second, b.first); }); int ans = 0, sc = 0; RF(int, i, n - 1, 0, 1){ if(sc > su){ break; }else{ ans ++; sc += (vo[i].first + vo[i].second); su -= (vo[i].first); } } cout << ans << '\n'; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // freopen("Debug.txt", "w", stderr); #else #endif // cout << fixed << setprecision(10); // int _t; // cin>>_t; // while(_t --) solve(); }
# include <bits/stdc++.h> using namespace std; int main(){ int N; int count=0; cin>>N; int A[N]; int B[N]; for(int i=0;i<N;i++){ cin>>A[i]; } for(int i=0;i<N;i++){ cin>>B[i]; } int maxi=*max_element(A,A+N); int mini=*min_element(B,B+N); if(mini>maxi){ for(int k=maxi;k<=mini;k++){ count++; } } if(mini==maxi){ count++; } cout<<count; }
#include<bits/stdc++.h> using namespace std; tuple<long long, long long, long long> ext_gcd(long long a, long long b) { if (b == 0) return {a, 1, 0}; auto [gcd, y, x] = ext_gcd(b, a%b); y -= a/b * x; return {gcd, x, y}; // a*x + b*y = gcd } pair<long long,long long> crt(const vector<long long> &r, const vector<long long> &m) { /* return x that satisfies x = a mod b, for a in r, for b in m */ /* O(n log lcm(m[i]))*/ assert(r.size() == m.size()); auto mod=[&](long long a,long long k){return (a%k+k)%k;}; // a mod k for negative a long long y = 0, lcm = 1; int n = r.size(); for(int i=0; i<n; ++i) { assert(m[i] > 0); auto [g, p, q] = ext_gcd(lcm, m[i]); if(y % g != r[i] % g) return make_pair(0,0); long long s = (mod(r[i],m[i]) - y) / g * p % (m[i]/g); y = mod(y + lcm*s, lcm*(m[i]/g)); lcm *= m[i] / g; } return make_pair(y, lcm); // x = y mod lcm } void solve() { int x,y,p,q; cin >> x >> y >> p >> q; const long long INF = 2e18; long long ans = INF; for(int a=x; a<x+y; ++a) for(int b=p; b<p+q; ++b) { // t = a mod (2x+2y) // t = b mod (p+q) vector<long long> r(2),m(2); r[0] = a, r[1] = b, m[0]=2*(x+y), m[1] = p+q; auto [t,lcm] = crt(r,m); if(lcm) ans = min(ans,t); } if (ans == INF) cout << "infinity" << endl; else cout << ans << endl; } int main() { int t; cin >> t; while(t--) solve(); }
/* #pragma GCC optimize("O2") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("avx,avx2,sse,sse2,fma") //*/ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int ,int > pii; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const ll maxn = 3e6; const ll mod =1e9+7; const ld PI = acos((ld)-1); #define pb push_back #define endl '\n' #define dokme(x) cout << x , exit(0) #define migmig ios::sync_with_stdio(false),cin.tie(0),cout.tie(0) #define ms(x , y) memset(x , y , sizeof x) ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);} int n; char aa , ab , ba , bb; ll F[maxn]; ll f(int x){ if(x <= 1)return(F[x] = 1); if(F[x])return(F[x]); return( F[x] = (f(x - 1) + f(x - 2))%mod ); } int32_t main(){ migmig; cin >> n >> aa >> ab >> ba >> bb; if(n <= 3)dokme(1); if(aa == ab && ab == ba && ba == bb)dokme(1); if(ab == 'B'){ if(bb == 'B')dokme(1); if(ba == 'A')dokme(pw(2 , n - 3)); dokme(f(n - 2)); } if(aa == 'A')dokme(1); if(ba == 'B')dokme(pw(2 , n - 3)); dokme((f(n - 2))); return(0); }
#line 1 "/home/siro53/kyo-pro/compro_library/template/template.cpp" #include <bits/stdc++.h> using namespace std; template <class T> inline bool chmax(T &a, T b) { if(a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if(a > b) { a = b; return 1; } return 0; } #define DEBUG #ifdef DEBUG template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << '(' << p.first << ',' << p.second << ')'; return os; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { os << '{'; for(int i = 0; i < (int)v.size(); i++) { if(i) { os << ','; } os << v[i]; } os << '}'; return os; } void debugg() { cerr << endl; } template <class T, class... Args> void debugg(const T &x, const Args &... args) { cerr << " " << x; debugg(args...); } #define debug(...) \ cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__) #define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl #else #define debug(...) (void(0)) #define dump(x) (void(0)) #endif struct Setup { Setup() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } __Setup; using ll = long long; #define ALL(v) (v).begin(), (v).end() #define RALL(v) (v).rbegin(), (v).rend() #define FOR(i, a, b) for(int i = (a); i < int(b); i++) #define REP(i, n) FOR(i, 0, n) const int INF = 1 << 30; const ll LLINF = 1LL << 60; constexpr int MOD = 1000000007; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; //------------------------------------- #line 2 "f.cpp" ll A, B, N; vector<int> p; bool is_prime(int n) { if(n <= 1) return false; for(int i=2;i*i<=n;i++){ if(n % i == 0) return false; } return true; } void init() { for(int i=2;i<=72;i++) { if(is_prime(i)) p.push_back(i); } } int main() { init(); cin >> A >> B; N = B - A + 1; int n = p.size(); vector<vector<ll>> dp(N+1, vector<ll>(1 << n, 0)); dp[0][0] = 1; vector<int> pre_bit(N, 0); REP(i, N) { ll num = A + i; REP(j, n) if(num % p[j] == 0) pre_bit[i] |= (1 << j); } REP(i, N) { REP(S, 1 << n) { // 追加しない dp[i+1][S] += dp[i][S]; // 追加する ll num = i+A; if(S & pre_bit[i]) continue; int nS = S | pre_bit[i]; dp[i+1][nS] += dp[i][S]; } } ll ans = 0; REP(S, 1 << n) ans += dp[N][S]; cout << ans << endl; }
#include<bits/stdc++.h> #define ll long long #define ld long double #define db double #define pint pair<int,int> #define mk make_pair #define pb push_back #define eb emplace_back #define ins insert #define fi first #define se second #define Rep(x,y,z) for(int x=y;x<=z;x++) #define Red(x,y,z) for(int x=y;x>=z;x--) using namespace std; const int MAXN=2e5+5; char buf[1<<12],*pp1=buf,*pp2=buf,nc;int ny; //inline char gc() {return pp1==pp2&&(pp2=(pp1=buf)+fread(buf,1,1<<12,stdin),pp1==pp2)?EOF:*pp1++;} inline char gc(){return getchar();} inline int read(){ int x=0;ny=1;while(nc=gc(),(nc<48||nc>57)&&nc!=EOF)if(nc==45)ny=-1;if(nc<0)return nc; x=nc-48;while(nc=gc(),47<nc&&nc<58&&nc!=EOF)x=(x<<3)+(x<<1)+(nc^48);return x*ny; } int n;char s[MAXN]; int main(){ // freopen("std.in","r",stdin); // freopen("std.out","w",stdout); for(int t=read();t--;){ n=read(),scanf("%s%s%s",s+1,s+1,s+1); Rep(i,1,n)cout<<'0';Rep(i,1,n)cout<<'1';cout<<'0';puts(""); } return 0; }