code_file1
stringlengths
87
4k
code_file2
stringlengths
85
4k
#include <bits/stdc++.h> using namespace std; #define ll long long #define P pair #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)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 dp[1010][1010]; int main(){ int n,m,a[1001],b[1001]; cin>>n>>m; rep(i,n)cin>>a[i]; rep(i,m)cin>>b[i]; rep(i,n+1)rep(j,m+1)dp[i][j]=INF; dp[0][0]=0; rep(i,n+1){ rep(j,m+1){ if(j<m){ chmin(dp[i][j+1],dp[i][j]+1); } if(i<n){ chmin(dp[i+1][j],dp[i][j]+1); } if(i<n&&j<m){ if(a[i]==b[j])chmin(dp[i+1][j+1],dp[i][j]); else chmin(dp[i+1][j+1],dp[i][j]+1); } } } cout<<dp[n][m]<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; // #define ordered_set tree<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 //const long long INF=1e18; bool chmin(int& a, int b){ if(a > b){ a = b; return 1; } return 0; } 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; } int n,m; vec a(2000) , b(2000) ; int dp[2000][2000]; int find(int i , int j) { if(i >= n || j >= m) return (n - i) + (m - j) ; if(dp[i][j] != -1) return dp[i][j]; int x = find(i+1 , j) + 1; int y = find(i , j+1) + 1 ; int z = find(i+1 , j+1) + (int)(a[i] != b[j]); //int c = find(i + 1 , j + 1 ) +2; dp[i][j] = min( z , min(x,y )); //cout<<dp[i][j] <<" "<<i <<" "<<j<<endl; return dp[i][j]; } signed main() { cin>>n>>m; for(int i = 0 ; i < n ;i++) cin>>a[i]; for(int j = 0 ; j < m ;j++) cin>>b[j]; for(int i = 0 ; i < 2000 ; i++) for(int j = 0 ; j < 2000 ; j++) dp[i][j] = -1; int mi = find(0,0); // cout<<mi<<endl; cout << mi <<endl; }
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <sstream> #include <queue> #include <deque> #include <bitset> #include <iterator> #include <list> #include <stack> #include <map> #include <set> #include <functional> #include <numeric> #include <utility> #include <iomanip> #include <limits> #include <time.h> #include <math.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <assert.h> #define debug(x) cout << #x << " = " << x << endl #define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++) #define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--) using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> ii; const int MAX = 55 * 55; const int MOD = 998244353; int fat[MAX]; inline int add(int a, int b) { a += b; if (a >= MOD) a -= MOD; return a; } inline int sub(int a, int b) { a -= b; if (0 > a) a += MOD; return a; } inline int mult(int a, int b) { return (1LL * a * b) % MOD; } int f_exp(int x, int e) { if (e <= 0) return 1; if (e & 1) return mult(x, f_exp(x, e - 1)); return f_exp(mult(x, x), e / 2); } inline int inv(int x) { return f_exp(x, MOD - 2); } inline int comb(int n, int k) { if (k > n) return 0; return mult(fat[n], mult(inv(fat[n - k]), inv(fat[k]))); } void preprocess() { fat[0] = 1; fori (i, 1, MAX) { fat[i] = mult(fat[i - 1], i); } } int row_max[MAX]; int col_max[MAX]; vector<int> adj[2][MAX]; bool visited[2][MAX]; int n, k; int mat[55][55]; int bfs(int id, int start) { queue<int> q; q.push(start); visited[id][start] = true; int size = 0; while (!q.empty()) { int cur = q.front(); q.pop(); size++; for (auto &each : adj[id][cur]) { if (!visited[id][each]) { visited[id][each] = true; q.push(each); } } } return size; } void solve() { preprocess(); cin >> n >> k; fori (i, 1, n + 1) { fori (j, 1, n + 1) { cin >> mat[i][j]; row_max[i] = max(row_max[i], mat[i][j]); col_max[j] = max(col_max[j], mat[i][j]); } } fori (i, 1, n + 1) { fori (j, i + 1, n + 1) { bool row_ok = true; bool col_ok = true; fori (f, 1, n + 1) { if (mat[i][f] + mat[j][f] > k) row_ok = false; if (mat[f][i] + mat[f][j] > k) col_ok = false; } if (row_ok) { adj[0][i].push_back(j); adj[0][j].push_back(i); } if (col_ok) { adj[1][i].push_back(j); adj[1][j].push_back(i); } } } int prod[2]; prod[0] = prod[1] = 1; fori (i, 0, 2) { fori (j, 1, n + 1) { if (!visited[i][j]) { int size = bfs(i, j); prod[i] = mult(prod[i], fat[size]); } } } cout << mult(prod[0], prod[1]) << endl; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); solve(); return 0; }
// #include "pch.h" #include <iostream> #include <algorithm> #include <map> #include <set> #include <queue> #include <bitset> #include <climits> #include <string> #include <cmath> #include <bitset> #include <complex> #include <functional> #include <ctime> #include <cassert> #include <fstream> #include <stack> #include <random> typedef long long ll; typedef std::pair<int, int> Pii; typedef std::pair<long long, long long> Pll; typedef std::pair<double, double> Pdd; #define rip(i, n, s) for (int i = (s);i < (int)( n ); i++) #define all(a) a.begin(), a.end() #define MM << " " << template<typename T> using MaxHeap = std::priority_queue<T>; template<typename T> using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>; template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template<typename T> void vdeb(std::vector<T> &bb) { for (int i = 0;i < bb.size();i++) { if (i == bb.size() - 1) std::cout << bb[i]; else std::cout << bb[i] << ' '; } std::cout << '\n'; } template<typename T> void vdeb(std::vector<std::vector<T>> &bb) { for (int i = 0;i < bb.size();i++) { std::cout << i << ' '; vdeb(bb[i]); } std::cout << '\n'; } using namespace std; ll dp[110][130000]; int main() { ll n, k, m; cin >> n >> k >> m; dp[0][0] = 1; rip(i,n+1,1) { rip(j,130000, 0) { dp[i][j] = dp[i-1][j]; if(j-i >= 0) { dp[i][j] += dp[i][j-i]; dp[i][j] %= m; } if(j - i*(k+1) >= 0) { dp[i][j] -= dp[i-1][j - i*(k+1)]+m; dp[i][j] %= m; } } } rip(i, n, 0) { ll ans = 0; rip(j, 130000, 0) { ans += 1LL * dp[i][j] * dp[n-i-1][j] % m; } printf("%lld\n", (ans%m*(k+1)%m-1+m)%m); } }
#include <bits/stdc++.h> int main(){ int N; std::cin>>N; int A, B, A_max = 0; int B_min = 1000; for (int i = 0; i<N; ++i){ std::cin>>A; if(A>A_max) A_max = A; } for (int i = 0; i<N; ++i){ std::cin>>B; if(B<B_min) B_min = B; } int c = 0; for (int i = A_max; i<=B_min; i++) ++c; std::cout<<c<<std::endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define irep(i, n) for (int i = (n); i >= 0; i--) using namespace std; using ll = long long; using P = pair<int, int>; const int INF = 1 << 25; const int MOD = 1e9+7; int a[1010], b[1010]; int main() { int n; cin >> n; rep(i,n) cin >> a[i]; rep(i,n) cin >> b[i]; int ans = 0; for (int i = 1; i <= 1000; i++) { bool ok = true; rep(j,n) { if(!(a[j] <= i && i <= b[j])) ok = false; } if (ok) ans++; } cout << ans << endl; return 0; }
#include<bits/stdc++.h> // #pragma GCC2 optimize(2) #define cio ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); using namespace std; typedef long long ll; vector<ll> v; int main() { // cout<<"kdhfj"<<endl; cio; int a,b,c; cin>>a>>b>>c; if(c%2==0) { int aa=abs(a); int bb=abs(b); if(aa>bb)cout<<">"<<endl; else if(aa==bb)cout<<"="<<endl; else cout<<"<"<<endl; } else { int aa=a; int bb=b; if(aa>bb)cout<<">"<<endl; else if(aa==bb)cout<<"="<<endl; else cout<<"<"<<endl; } }
#include <bits/stdc++.h> using namespace std; main() { int N, W; scanf("%d %d", &N, &W); printf("%d", N / W); }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define sz(x) int(x.size()) #define show(x) {for(auto i: x){cout << i << " ";} cout << endl;} using namespace std; using ll = long long; using P = pair<int, int>; const int INF = 1e9; struct part { int v, l; part(int v=0, int l=0): v(v), l(l) {} }; int main() { // 全探索、重さでソート、最長路、二分探索 int N, M; cin >> N >> M; vector<int> W(N); rep(i, N) cin >> W[i]; sort(W.begin(), W.end()); vector<part> LV(M); int maxV = 0, minV = 1e9; rep(i, M) { int l, v; cin >> l >> v; maxV = max(maxV, v); minV = min(minV, v); LV[i].v = v; LV[i].l = l; } if (W[N-1] > minV) { cout << -1 << '\n'; return 0; } sort(LV.begin(), LV.end(), [&] (const part& x, const part& y) { return x.v < y.v; }); map<int, ll> mp; rep(i, M) { int key = LV[i].v; int value = LV[i].l; if (mp[key] < value) { mp[key] = value; } } int maxL = 0; for (auto &p : mp) { if (p.second > maxL) { maxL = p.second; } p.second = maxL; } mp[INF] = maxL; vector<int> pos(N); rep(i, N) pos[i] = i; ll ans = 1e16; do { vector<P> ws(N); rep(i, N) ws[i].first = W[pos[i]]; vector<vector<ll>> dist(N, vector<ll> (N)); rep(i, N) for (int j = i+1; j < N; j++) { // iからjまでの重さが十分の距離があるか int temp = 0, d = 0; for (int k = i; k <= j; k++) { temp += ws[k].first; if (k != j) d += ws[k].second; } if (temp <= minV) continue; auto it = mp.lower_bound(temp); if (it == mp.begin()) continue; it--; dist[i][j] = it -> second; } vector<ll> dp(N); rep(i, N) for (int j = i+1; j < N; j++) { dp[j] = max(dp[j], dp[i] + dist[i][j]); } ans = min(ans, dp[N-1]); } while (next_permutation(pos.begin(), pos.end())); cout << ans << '\n'; return 0; }
#include<iostream> #include<algorithm> #include<cstring> using namespace std; int n, m, c[10], dl[10], vis[10], ans = 0x3f3f3f3f, lx[10], db[10]; struct judge { int l; int v; }; judge a[100010]; bool tmp(judge x, judge y) { if (x.l != y.l) return x.l < y.l; else return x.v > y.v; } int findl(int x) { int b, e, t; b = 1, e = m, t = b + e >> 1; while (b < e) { if (a[t].v >= x) e = t-1; else b = t ; t = b + e +1>> 1; } if (a[b].v >= x) return 0; return a[b].l; } void fact() { memset(lx, 0, sizeof lx); for (int i = 1; i <= n; i++) { db[i] = db[i - 1] + c[dl[i]]; } for (int i = 2; i <= n; i++) for (int j = 1; j < i; j++) { int l = findl(db[i] - db[j - 1]); lx[i] = max(lx[i], lx[j] + l); } ans = min(ans, lx[n]); } void dfs(int i) { if (i == n + 1) { fact(); return; } for (int j = 1; j <= n; j++) { if (!vis[j]) { vis[j] = 1; dl[i] = j; dfs(i + 1); vis[j] = 0; } } } int main() { std::ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m; for (int i = 1; i <= n; i++) cin >> c[i]; for (int i = 1; i <= m; i++) cin >> a[i].l >> a[i].v; sort(a + 1, a + m + 1, tmp); for (int i = m - 1; i > 0; i--) a[i].v = min(a[i].v, a[i + 1].v); for (int i = 1; i <= n; i++) if (c[i] > a[1].v) { cout << -1; return 0; } dfs(1); cout << ans; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double vector<vector<int>> edge; vector<int> v; vector<int> d; int dfs(ll now, ll pre, ll target) { int res = 0; int ma = -1, mi = 1000000; int dma = -1, dmi = 1000000; int cnt = 0; for (int nxt : edge[now]) { if (nxt == pre) continue; cnt++; res += dfs(nxt, now, target); mi = min(mi, v[nxt]); ma = max(ma, v[nxt]); dmi = min(dmi, d[nxt]); dma = max(dma, d[nxt]); } d[now] = dmi+1; bool put = false; if (cnt == 0) { return 0; }else if (cnt == 1) { if (mi >= 2*target) { v[now] = 0; put = true; }else { v[now] = mi+1; } }else { if (ma+dmi+2 <= 2*target+1) { v[now] = mi+1; }else if (ma+1 >= 2*target+1){ v[now] = 0; put = true; }else { v[now] = ma+1; } } if (now == 0 && !put) { if (v[now] > target) put = true; } if (put) { res++; d[now] = 0; } return res; } int main() { int N, K; cin >> N >> K; edge.resize(N); v.resize(N); d.resize(N); for (int i = 0; i < N-1; i++) { int u, v; cin >> u >> v; u--;v--; edge[u].push_back(v); edge[v].push_back(u); } ll l = 0, r = N; while (r-l > 1) { ll c = (l+r)/2; fill(v.begin(), v.end(), c+1); fill(d.begin(), d.end(), N*10); ll need = dfs(0, -1, c); //cout << need << endl; if (need <= K) r = c; else l = c; } cout << r << endl; return 0; }
#include <bits/stdc++.h> #define ll long long #define pb push_back #define task "asd" #define pll pair<ll, ll> #define pii pair<pll, ll> #define fi first #define se second using namespace std; const ll mod = 1e15+7; const ll N = 2e5+5; const int base = 313; ll n, m, t, k, T, ans, siz, tong, a[N], b[N], d[N], c[N], h[N], P[N][20]; string s[N]; vector<ll> adj[N]; vector<pll> kq; ll pw(ll k, ll n) { ll total = 1; for(; n; n >>= 1) { if(n & 1)total = total * k % mod; k = k * k % mod; } return total; } void dfs(ll u, ll p) { for(int i = 1; i <= 18; i ++)P[u][i] = P[P[u][i-1]][i-1]; for(ll v : adj[u]) { if(v == p)continue; h[v] = h[u] + 1; P[v][0] = u; dfs(v, u); } } ll par(ll u, ll dist) { if(h[u] < dist)return 1; for(int i = 18; i >= 0; i --) { if((dist >> i) & 1) { u = P[u][i]; } } return u; } void bfs(ll u, ll len) { queue<ll> q; d[u] = 0; q.push(u); while(!q.empty()) { ll u = q.front(); q.pop(); if(d[u] == len)continue; for(ll v : adj[u]) { if(d[v] > d[u] + 1) { d[v] = d[u] + 1; q.push(v); } } } } bool check(ll len) { ll cnt = 0; fill_n(d, n+2, mod); for(pll x : kq) { if(d[x.se] <= len)continue; ll root = par(x.se, len); bfs(root, len); ++cnt; //cout << root <<" "<<x.se<<'\n'; if(cnt > k)return false; } return true; } void sol() { cin >> n >> k; for(int i = 1; i < n; i ++) { ll x, y; cin >> x >> y; adj[x].pb(y); adj[y].pb(x); } dfs(1, 0); for(int i = 1; i <= n; i ++)kq.pb({h[i], i}); sort(kq.rbegin(), kq.rend()); ll lf = 0, rt = n, mid; while(lf <= rt) { mid = (lf + rt) / 2; if(check(mid))rt = mid - 1; else lf = mid + 1; } cout << lf; } int main() { if(fopen(task".INP", "r")) { freopen(task".INP", "r", stdin); freopen(task".OUT", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int ntest = 1; //cin >> ntest; while(ntest -- > 0) sol(); } /* 5 1 1 2 2 3 3 4 4 5 https://codeforces.com/contest/791/problem/E */
#include <bits/stdc++.h> #define int ll #define double long double #define rbtree __gnu_pbds::tree<int,__gnu_pbds::null_type,less<int>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update> #define IOS ios_base::sync_with_stdio(false);cin.tie(0); #define pb push_back #define ALL(X) X.begin(),X.end() #define F(i,n) FF(i,0,n) #define F1(i,n) FF(i,1,n+1) #define FF(i,n,m) for(int i=(int)n;i<(int)m;++i) #ifndef LOCOL //#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector") #endif // LOCOL //#define mp make_pair using namespace std; //using namespace __gnu_pbds; template<typename T> bool remax(T& a, const T& b) {return b>a?a=b,1:0;} template<typename T> bool remin(T& a, const T& b) {return b<a?a=b,1:0;} inline ostream& operator << (ostream& os,__int128_t a){if(a==0) {return (os<<'0');}bool flag=0;if(a<0) {a=-a,flag=1;}string s;while(a){s+=a%10+'0';a/=10;}s+=flag?"-":"";reverse(ALL(s));return os<<s;} inline istream& operator >>(istream& is,__int128_t& a){string s;cin>>s;a=0;for(auto c:s) a=a*__int128_t(10)+__int128_t(c-'0');return is;} template<typename T,typename P> inline ostream& operator << (ostream& os,pair<T,P> a){os<<a.first<<" "<<a.second; return os;} template<typename T,typename P> inline istream& operator >> (istream& is,pair<T,P> &a){is>>a.first>>a.second; return is;} using ll=long long; using ull=unsigned long long; using int128= __int128_t; using uint128= __uint128_t; using pii =pair<int,int>; const int N=2E5+5; const ll M=1000000000; const ll INF_64=0x3f3f3f3f3f3f3f3f; const int INF_32=0x3f3f3f3f; const int16_t INF_16=0x3f3f; const int klog=20; const int mod=1E9+7; const double eps=1E-8; void gen(){ } void sol(){ int n;cin>>n;n*=2; vector<int> a(n); F(i,n) cin>>a[i]; vector<int> ord(n); iota(ord.begin(), ord.end(), 0); sort(ALL(ord),[&](int i,int j){return a[i]<a[j];}); vector<int> b(n); F(i,n) b[ord[i]]=(i<n/2)?1:0; string res(n, ' '); vector<int> st; F(i,n){ if(!st.empty()&&b[i]!=b[st.back()]){ res[st.back()] = '('; res[i] = ')'; st.pop_back(); } else { st.push_back(i); } } cout <<res<< '\n'; } int32_t main(){ #ifdef LOCAL //freopen(".in","r",stdin); //freopen(".out","w",stdout); #endif // LOCAL #ifndef LOCAL #endif // LOCAL IOS; int t=1; gen(); //cin>>t; FF(i,1,t+1){ //cout<<"Case #"<<i<<": "; sol(); } }
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main(){ ll t; cin>>t; while(t--){ ll x; cin>>x; if(x%2==1){ cout<<"Odd"<<'\n'; continue; } if(x>=4 && x%4==0){ cout<<"Even"<<'\n'; continue; } if(x%2==0){ cout<<"Same"<<'\n'; continue; } } }
#include<bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int, int> P; const int maxn = 500 + 10; const int M_MAX = 10 * maxn * maxn; const int mod = 1e9 + 7; const LL INF = 0x3f3f3f3f; const double eps = 1e-6; struct edge { int to, cost, next; }e[5000010]; int n, m; int h[1000010], d[1000010], len = 1; int p(int x, int y) { return (x - 1) * m + y; } void addedge(int v, int u, int cost) { e[len].to = u; e[len].cost = cost; e[len].next = h[v]; h[v] = len++; } void solve() { cin >> n >> m; for(int i = 1; i <= n; i++) { for(int j = 1; j < m; j++) { int c; cin >> c; addedge(p(i, j) , p(i, j + 1), c); addedge(p(i,j+1), p(i, j), c); } } for(int i = 1; i < n; i++) { for(int j = 1; j <= m; j++) { int c; cin >> c; addedge(p(i, j), p(i+1, j), c); } } for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { addedge(p(i, j), p(i, j) + n*m, 1); addedge(p(i,j) + n*m, p(i,j), 0); } } for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { addedge(p(i+1, j) + n*m, p(i,j) + n*m, 1); } } for(int i = 1; i <= 2 * n * m; i++) d[i] = INF; d[1] = 0; priority_queue<P> que; que.emplace(make_pair(0, 1)); while(!que.empty()) { P pe = que.top(); que.pop(); int v = pe.second; if(-d[v] != pe.first) continue; for(int i = h[v]; i; i = e[i].next) { if(d[e[i].to] > e[i].cost + d[v]) { d[e[i].to] = e[i].cost + d[v]; que.emplace(make_pair(-d[e[i].to], e[i].to)); } } } cout << d[n*m] << endl; } int main() { ios::sync_with_stdio(false); //srand(time(NULL)); //更新种子 solve(); return 0; }
#include <stdio.h> inline int read() { int b = getchar(), c = 0; int m = b == 45; if (m) b = getchar(); while (b > 47) { c = c * 10 + b - 48; b = getchar(); } return m ? - c : c; } int p[200001]; int main() { int a[400002]; int n = read(), m = read(); long s = 0; for (int i = 1; i <= n + n; i++) a[i] = read(); for (int i = 0; i < m + m; i++) p[read()] = 1; p[1] = 1; for (int i = 1; i < 200001; i++) { if (p[i]) s += a[i] - a[i + n]; } puts(s ? "No" : "Yes"); }
#include<bits/stdc++.h> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; ///Welcome to Nasif's Code #define bug printf("bug\n"); #define bug2(var) cout<<#var<<" "<<var<<endl; #define co(q) cout<<q<<endl; #define all(q) (q).begin(),(q).end() #define pi acos(-1) #define inf 1000000000000000LL #define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define MODADD(ADD_X,ADD_Y) (ADD_X+ADD_Y)%MOD #define MODSUB(SUB_X,SUB_Y) ((SUB_X-SUB_Y)+MOD)%MOD #define MODMUL(MUL_X,MUL_Y) (MUL_X*MUL_Y)%MOD #define LCM(LCM_X,LCM_Y) (LCM_X/__gcd(LCM_X,LCM_Y))*LCM_Y template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; typedef long long int ll; typedef unsigned long long int ull; const int MOD = (int)998244353; const int MAX = 1e6; int dx[]= {1,0,-1,0,1,-1,1,-1}; int dy[]= {0,1,0,-1,1,-1,-1,1}; ll dp[105][105][10050],arr[105],sum,n,fact[105]; ll recur(int pos,int cnt,int s) { if(pos==n) { if((sum-s)==s) { int cnt2=n-cnt; return (fact[cnt]*fact[cnt2])%MOD; } return 0; } ll &ret=dp[pos][cnt][s]; if(~ret) return ret; ret=0; ret+=recur(pos+1,cnt+1,s+arr[pos]); ret=(ret+recur(pos+1,cnt,s))%MOD; return ret; } int main() { FastRead //freopen("output.txt", "w", stdout); memset(dp,-1,sizeof(dp)); fact[0]=1; for(int i=1; i<=100; i++) fact[i]=(fact[i-1]*i)%MOD; cin>>n; for(int i=0; i<n; i++) { cin>>arr[i]; sum+=arr[i]; } cout<<recur(0,0,0)<<endl; return 0; }
/* In the name of *Allah* * * Thank You *Parsa* */ #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops, avx, avx2, fma") #include<iostream> #include<algorithm> #include<math.h> #include<string> #include<ios> #include<vector> #include<utility> #include<set> #include<map> #include<numeric> using namespace std; #define pb push_back #define mp make_pair #define fi first #define se second #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() typedef long long ll; typedef long double ld; const int inf_int = 1 << 30; const ll inf_longlong = 1LL << 62; const int MOD = 998244353; const int N = 100 + 5; int n, w[N]; int dp[N][N * N], fact[N]; void init() { fact[0] = 1; for (int i = 1; i < N; i++) fact[i] = 1LL * fact[i - 1] * i % MOD; } void add(int &a, int b) { a += b; if (a >= MOD) a -= MOD; } void read_input() { cin >> n; for (int i = 1; i <= n; i++) cin >> w[i]; } void solve() { dp[0][0] = 1; for (int i = 1; i <= n; i++) { for (int k = i; k; k--) { for (int j = w[i]; j < N * N; j++) { add(dp[k][j], dp[k - 1][j - w[i]]); } } } int ans = 0, sum = accumulate(w + 1, w + n + 1, 0); if (sum % 2) { cout << 0 << '\n'; return; } for (int i = 1; i < n; i++) { add(ans, 1LL * dp[i][sum / 2] * fact[i] % MOD * fact[n - i] % MOD); } cout << ans << '\n'; } void write_output() { } int main() { ios:: sync_with_stdio(false), cin.tie(0), cout.tie(0); #ifndef ONLINE_JUDGE //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); #endif init(); int test_cases = 1; //cin >> test_cases; while (test_cases--) { read_input(), solve(), write_output(); } return 0; } // Thanks *Allah*
#include<bits/stdc++.h> using namespace std; const int maxn=2020; int n,m; int fa[maxn]; int fnd(int x) { if(fa[x]==x) { return x; } return fa[x]=fnd(fa[x]); } void merge(int x,int y) { fa[fnd(x)]=fnd(y); } set<int> s1,s2; int main() { cin>>n>>m; for(int i=1;i<=n+m;i++) { fa[i]=i; } merge(1,n); merge(1,n+1); merge(1,n+m); for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { char c; cin>>c; if(c=='#') { merge(i,j+n); } } } for(int i=1;i<=n;i++) { s1.insert(fnd(i)); } for(int i=n+1;i<=n+m;i++) { s2.insert(fnd(i)); } cout<<min((int)s1.size(),(int)s2.size())-1<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; namespace IO { const int buffer_size=1e5+5; char buf[buffer_size],*S,*T; bool flag_EOF; inline char read_char() { if(S==T) T=(S=buf)+fread(buf,1,buffer_size,stdin); return S!=T?*(S++):EOF; } inline int read_int() { int flag=1; char c=read_char(); while(c<'0'||c>'9') { if(c==EOF) { flag_EOF=true; return 0; } flag=(c=='-'?-1:1); c=read_char(); } int x=0; while(c>='0'&&c<='9') { x=x*10+(c^48); c=read_char(); } return x*flag; } inline void read_string(char *s) { char x; do { x=read_char(); if(x==EOF) { flag_EOF=true; return; } }while(x<'a'||x>'z'); int len=0; while(x>='a'&&x<='z') { s[len++]=x; x=read_char(); } s[len]='\0'; } char fw[buffer_size]; int pw; inline void flush() { fwrite(fw,1,pw,stdout); pw=0; } inline void write_char(char x) { if(pw==buffer_size) flush(); fw[pw++]=x; } char st[13]; int top; inline void write_int(int x) { if(!x) { write_char('0'); return; } if(x<0) { write_char('-'); x=-x; } while(x) { st[++top]=x%10+'0'; x/=10; } while(top>0) write_char(st[top--]); } inline void write_string(const char *s) { for(int i=0;s[i];++i) write_char(s[i]); } } char s[10],t[10]; int cnt[15]; const int power[10]={1,10,100,1000,10000,100000}; inline bool check() { static int c[15]; for(int i=1;i<=9;++i) c[i]=0; int s1=0; for(int i=1;i<=5;++i) ++c[s[i]-'0']; for(int i=1;i<=9;++i) s1+=i*power[c[i]]; for(int i=1;i<=9;++i) c[i]=0; int s2=0; for(int i=1;i<=5;++i) ++c[t[i]-'0']; for(int i=1;i<=9;++i) s2+=i*power[c[i]]; return s1>s2; } int main() { int k; scanf("%d%s%s",&k,s+1,t+1); for(int i=1;i<=9;++i) cnt[i]=k; for(int i=1;i<=4;++i) { --cnt[s[i]-'0']; --cnt[t[i]-'0']; } long long cnt_win=0,cnt_all=0; for(int i=1;i<=9;++i) for(int j=1;j<=9;++j) { s[5]=i+'0',t[5]=j+'0'; if(i==j&&cnt[i]>=2) { cnt_all+=cnt[i]*(cnt[i]-1ll); if(check()) cnt_win+=cnt[i]*(cnt[i]-1ll); } else if(i!=j&&cnt[i]>=1&&cnt[j]>=1) { cnt_all+=1ll*cnt[i]*cnt[j]; if(check()) cnt_win+=1ll*cnt[i]*cnt[j]; } } printf("%.10lf\n",1.0*cnt_win/cnt_all); IO::flush(); return 0; }
#include <stdio.h> #include <string.h> #include <algorithm> int main() { int A, B, W; scanf("%d%d%d", &A, &B, &W); W *= 1000; int ansmin = 0xfffffff; int ansmax = -1; for (int n = 1; n <= 1000 * 1000; n++) { if (A * n <= W && W <= B * n) { ansmin = std::min(ansmin, n); ansmax = std::max(ansmax, n); } } if (ansmax == -1) { puts("UNSATISFIABLE"); } else { printf("%d %d\n", ansmin, ansmax); } return 0; }
//#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define rep(i, n) for (long long i = 0; i < (long long)(n); i++) #define repa(i,a,n) for (long long i = (a); i < (long long)(n); i++) #define Rrep(i,n) for (long long i = (long long)(n)-1; i >= 0; i--) #define Rrepa(i,a,n) for (long long i = (long long)(n)-1; i >= a; i--) using ll = long long; class Prints { class __Prints { public: __Prints(const char* sep, const char* term) : sep(sep), term(term) {} template <class... Args> void operator()(const Args&... args) const { print(args...); } template <typename T> void pvec(const T& vec, size_t sz) const { for (size_t i = 0; i < sz; i++) std::cout << vec[i] << (i == sz - 1 ? term : sep); } template <typename T> void pmat(const T& mat, size_t h, size_t w) { for (size_t i = 0; i < h; i++) for (size_t j = 0; j < w; j++) std::cout << mat[i][j] << (j == w - 1 ? term : sep); } private: const char *sep, *term; void print() const { std::cout << term; } void print_rest() const { std::cout << term; } template <class T, class... Tail> void print(const T& head, const Tail&... tail) const { std::cout << head, print_rest(tail...); } template <class T, class... Tail> void print_rest(const T& head, const Tail&... tail) const { std::cout << sep << head, print_rest(tail...); } }; public: Prints() {} __Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); } }; Prints print; //一次元配列はprint().pvec(vec,要素数); //二次元配列はprint().pmat(vec,要素数1,要素数2); int main() { string S; cin >> S; string flg = "Yes"; rep(i,S.size()){ if (i % 2 == 0){ if (S[i] < 'a' or 'z' < S[i]){ flg = "No"; } } else{ if (S[i] < 'A' or 'Z' < S[i]){ flg = "No"; } } //print()(i,flg); } cout << flg << endl; }
#include<bits/stdc++.h> #define int long long #define ll long long #define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define fs first #define sd second #define rept(x,n) for(int i=x;i<n;i++) #define rrept(n,x) for(int i=n-1;i>=x;i--) #define all(v) v.begin(),v.end() #define mpit map<int,int>::iterator #define stit set<int,int>::iterator #define quit queue<int,int>::iterator #define maxt(a,b,c) max(a,max(b,c)) #define mint(a,b,c) min(a,min(b,c)) #define rsort(v) sort(v.rbegin(),v.rend()) #define pb push_back #define prnt(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" "; using namespace std; void solve() { string s; cin>>s; for(ll i = 0;i<s.length();i+=2) { if(s[i]>='a'&&s[i]<='z') continue; else { cout<<"No\n"; return; } } for(ll i = 1;i<s.length();i+=2) { if(s[i]>='A'&&s[i]<='Z') continue; else { cout<<"No\n"; return; } } cout<<"Yes\n"; } signed main() { speed; int t=1; //cin>>t; while(t--) { solve(); } return 0; }
#include <bits/stdc++.h> #define fr first #define se second #define ll long long #define pb push_back using namespace std; const ll INF = 1e16 + 1; const ll N = 2e3 + 5; const ll mod = 1e9 + 7; const long double eps = 1E-7; ll n, m, cnt; int main() { string s; cin >> s; for ( int i=0; i<s.size(); i+=2 ){ if ( s[i] >= 'A' and s[i] <= 'Z' ){ cout << "No"; return 0; } } for ( int i=1; i<s.size(); i+=2 ){ if ( s[i] >= 'a' and s[i] <= 'z' ){ cout << "No"; return 0; } } cout << "Yes"; }
#ifdef LOGX #define _GLIBCXX_DEBUG #endif #include <bits/stdc++.h> using namespace std; //#include <atcoder/all> //using namespace atcoder; /*---------macro---------*/ #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 unless(x) if(!(x)) #define until(x) while(!(x)) #define ALL(a) a.begin(),a.end() #define RALL(a) a.rbegin(),a.rend() #define mybit(i,j) (((i)>>(j))&1) /*---------type/const---------*/ const int big=1000000007; //const int big=998244353; const double EPS=1e-8; //適宜変える typedef long long ll; typedef unsigned long long ull; typedef std::string::const_iterator state; //構文解析 const int dx[4]={1,0,-1,0}; const int dy[4]={0,1,0,-1}; const char newl='\n'; struct{ constexpr operator int(){return -int(1e9)-10;} constexpr operator ll(){return -ll(1e18)-10;} }neginf; struct{ constexpr operator int(){return int(1e9)+10;} constexpr operator ll(){return ll(1e18)+10;} constexpr auto operator -(){return neginf;} }inf; /*---------debug---------*/ #ifdef LOGX #include <template/debug.hpp> #else #define dbg(...) ; #define dbgnewl ; #define prt(x) ; #define _prt(x) ; #endif /*---------function---------*/ template<typename T> T max(const std::vector<T> &a){T ans=a[0];for(T elem:a){ans=max(ans,elem);}return ans;} template<typename T> T min(const std::vector<T> &a){T ans=a[0];for(T elem:a){ans=min(ans,elem);}return ans;} template<typename T,typename U> bool chmin(T &a,const U b){if(a>b){a=b;return true;}return false;} template<typename T,typename U> bool chmax(T &a,const U b){if(a<b){a=b;return true;}return false;} bool valid(int i,int j,int h,int w){return (i>=0 && j>=0 && i<h && j<w);} template<class T,class U>T expm(T x,U y,const ll mod=big){T res=1;while(y){if(y&1)(res*=x)%=mod;(x*=x)%=mod;y>>=1;}return res;} template<class T,class U>T exp(T x,U y){T res=1;while(y){if(y&1)res*=x;x*=x;y>>=1;}return res;} int main(){ //std::ios::sync_with_stdio(false); //std::cin.tie(nullptr); std::cout.precision(10); /*------------------------------------*/ ll n,k;cin >> n >> k; vector<vector<ll>> a(n,vector<ll>(n)); rep(i,n)rep(j,n)cin >> a[i][j]; ll ng=-1; ll ok=inf; //中央値をok以下にできる while(abs(ng-ok)>1){ ll x=(ng+ok)/2; vector<vector<ll>> sum(n+1,vector<ll>(n+1)); rep(i,n)rep(j,n){ sum[i+1][j+1]=(a[i][j]<=x ? -1:1); } dbg(x,sum); rep(i,n)rep(j,n+1)sum[i+1][j]+=sum[i][j]; rep(i,n+1)rep(j,n)sum[i][j+1]+=sum[i][j]; bool can=false; rep(i,n-k+1)rep(j,n-k+1){ if(sum[i+k][j+k]+sum[i][j]-sum[i+k][j]-sum[i][j+k]<=0)can=true; } (can ? ok:ng)=x; } cout << ok << newl; }
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<vector> typedef long long ll; typedef std::vector<int> P; typedef unsigned un; ll read() { ll x=0,f=1;char c=getchar(); while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();} while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar(); return f*x; } using std::min; using std::max; template<typename T>bool umin(T& a,T t){if(a>t)return a=t,1;return 0;} template<typename T>bool umax(T& a,T t){if(a<t)return a=t,1;return 0;} const int MAXN = 111; int a[MAXN],b[MAXN]; char s[MAXN]; int main() { int n=read(); scanf("%s",s+1); for(int i=1;i<=n+1;++i)a[i]=read(); for(int k=10000;k;--k) { bool fail=0; for(int i=1;i<=k&&!fail;++i) { b[1]=(a[1]/k+(i<=a[1]%k)); for(int j=2;j<=n+1;++j) { b[j]=(a[j]/k+(i<=a[j]%k)); if(s[j-1]=='>')fail|=b[j-1]<=b[j]; else fail|=b[j-1]>=b[j]; } } if(!fail) { printf("%d\n",k); for(int i=1;i<=k;puts(""),++i) for(int j=1;j<=n+1;++j)printf("%d ",a[j]/k+(i<=a[j]%k)); return 0; } } puts("0"); return 0; }
#include <stdio.h> #define mod 998244353 typedef long long ll; int main(void) { ll i, j, k, n; scanf("%lld%lld", &n, &k); ll dp[n + 1][n + 1]; for(i = 0; i <= n; ++i) dp[i][0] = 0, dp[i][i] = 1; for(i = 2; i <= n; ++i) for(j = i - 1; j; --j) { dp[i][j] = dp[i - 1][j - 1]; if(j * 2 <= i) dp[i][j] += dp[i][j * 2]; dp[i][j] %= mod; } printf("%lld", dp[n][k]); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<long long> vll; typedef vector<pair<int,int>> vpi; #define FOR(i,a,b) for (int i = (a); i < (b); ++i) #define F0R(i,a) FOR(i,0,a) #define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i) #define R0F(i,a) ROF(i,0,a) #define trav(a,x) for (auto& a: x) #define pb push_back #define rsz resize #define all(x) begin(x), end(x) #define pi pair<int, int> #define mp make_pair #define F first #define S second ll MOD = 1e9+7; ll mod_exp(ll a, ll b) { ll r = 1; while (b) { if (b&1) r = (r*a)%MOD; a = (a*a)%MOD; b >>= 1; } return r; } ll inv(ll a) { return mod_exp(a, MOD-2); } struct mat { int n, m; vector<vll> a; mat(int n, int m) { this->n = n; this->m = m; a.rsz(n, vll(m, 0)); } mat(vector<vll> a) { this->a = a; n = a.size(); m = a[0].size(); } mat operator* (const mat& other) { mat ans(n, other.m); F0R(i, n) F0R(j, other.m) F0R(k, m) ans.a[i][j] = (ans.a[i][j]+a[i][k]*other.a[k][j])%MOD; return ans; } vll* operator[](int i) { return &a[i]; } }; mat identity(int n) { mat ans(n, n); F0R(i, n) ans.a[i][i]=1; return ans; } mat exp(mat a, ll pow) { mat res = identity(a.n); while (pow) { if (pow&1) res = res*a; a = a*a; pow >>= 1; } return res; } int n, m, k, x, y; ll half = inv(2); vll a; vector<vi> adj; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m >> k; a.rsz(n); F0R(i, n) cin >> a[i]; adj.rsz(n); F0R(i, m) { cin >> x >> y; adj[x-1].pb(y-1); adj[y-1].pb(x-1); } mat mt(n, n); F0R(i, n) { ll s = inv(2*m); mt.a[i][i]=((2*m-adj[i].size())*s)%MOD; for (int nb : adj[i]) { mt.a[nb][i] = (s)%MOD; } } // cout << inv(2) << ' ' << inv(4) << '\n'; // F0R(i, n) {F0R(j, n) cout << mt.a[i][j] << ' '; cout << '\n';} mt = exp(mt, k); mat nodes(1, n); F0R(i, n) nodes.a[0][i]=a[i]; nodes = nodes*mt; F0R(i, n) cout << nodes.a[0][i] << '\n'; }
#include <bits/stdc++.h> using namespace std; int N, a[505]; void solve() { cin >> N; for (int i = 1; i <= N; i++) cin >> a[i]; vector<int> ans; for (int stp = 1; stp <= N * N; stp++) { bool flg = 1; for (int i = 2; i <= N && flg; i++) flg &= a[i - 1] < a[i]; if (flg) break; int cur = (stp & 1) ? 1 : 2; for (int i = cur; i < N; i += 2) if (a[i] > a[i + 1]) cur = i; swap(a[cur], a[cur + 1]); ans.push_back(cur); } printf("%lu\n", ans.size()); for (int i : ans) printf("%d ", i); putchar('\n'); } int main () { #ifndef ONLINE_JUDGE freopen("cpp.in", "r", stdin); #endif int T; cin >> T; while (T--) solve(); return 0; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <tuple> #include <vector> #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; } void solve() { int N; cin >> N; vector<int> P(N); rep(i, N) cin >> P[i]; rep(i, N) P[i]--; vector<int> output; int parity = 0; auto operate = [&](int pos) -> void { output.push_back(pos); swap(P[pos], P[pos + 1]); parity ^= 1; }; for (int k = N - 1; k > 0; k--) { int now = find(all(P), k) - P.begin(); while (1) { if (now == k && (now == N - 1 || P[now] + 1 == P[now + 1])) break; if (now % 2 == parity) { operate(now); now++; } else { if (now - 1 >= 0) { // operate twice operate(now - 1); now--; operate(now + 1); } else { // corner case if (k != 1) { operate(now + 1); } else { // manual operation operate(1); operate(0); operate(1); operate(0); operate(1); break; } } } } } cout << output.size() << "\n"; rep(i, output.size()) cout << output[i] + 1 << "\n"; } int main() { cin.tie(0); ios::sync_with_stdio(false); int T; cin >> T; rep(i, T) solve(); return 0; }
#include <bits/stdc++.h> #define fi first #define se second #define ll long long #define ld long double #define pb push_back #define pf push_front #define pll pair<ll,ll> #define ppl pair<pll,ll> #define plp pair<ll,pll> #define pi 3.14159265358979323846264338327950 const ll MOD=1e9+7; using namespace std; ll n,m,q,x[55]; ll w[55],val[55]; ll POWER(ll base,ll expo) { ll ret=1; while(expo) { if(expo&1)ret=ret*base; expo>>=1; base=base*base; } return ret; } bool cmp(const pll &a, const pll &b) { if(a.fi == b.fi)return (a.se < b.se); return a.fi > b.fi; } ll fun(vector<ll>& v) { ll y = v.size(); ll ans = 0; vector<ll> used(n+1,0); for(ll i=0;i<y;i++){ ll mx_v = 0,in = -1; for(ll j=1;j<=n;j++){ if(!used[j] && w[j] <= v[i] && val[j] > mx_v){ mx_v = val[j]; in = j; } } if(in != -1){ ans += mx_v; used[in] = 1; } } return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll test_cases=1; //cin>>test_cases; while(test_cases--) { //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); cin>>n>>m>>q; for(ll i=1;i<=n;i++) cin>>w[i]>>val[i]; for(ll i=1;i<=m;i++)cin>>x[i]; while(q --){ ll l,r; cin>>l>>r; vector<ll> v; for(ll i=1;i<l;i++) v.pb(x[i]); for(ll i=r+1;i<=m;i++) v.pb(x[i]); sort(v.begin(),v.end()); cout<<fun(v)<<endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; // template {{{ #define range(i, l, r) for (int i = (int)(l); i < (int)(r); (i) += 1) #define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); (i) -= 1) #define whole(f, x, ...) ([&](decltype((x)) container) { return (f)( begin(container), end(container), ## __VA_ARGS__); })(x) #define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x) #define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl using i32 = int; using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; constexpr i32 mod = 1e9 + 7; // constexpr i32 mod = 998244353; constexpr i32 inf = 1001001001; constexpr i64 infll = 1001001001001001001ll; constexpr i32 dx[] = {0, -1, 1, 0, -1, 1, -1, 1}; constexpr i32 dy[] = {-1, 0, 0, 1, -1, -1, 1, 1}; struct IoSetup { IoSetup(i32 x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup; template <typename T = i64> T input() { T x; cin >> x; return x; } template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != (int)v.size() ? " " : ""); } return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; } template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; } template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; } template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); } template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); } template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); } // }}} void solve() { int n, m, q; cin >> n >> m >> q; vector< pair<int, int> > vs(n); vector< int > xs(m); range(i, 0, n) { cin >> vs[i].second >> vs[i].first; } rwhole(sort, vs); cin >> xs; while (q--) { int l = input() - 1, r = input(); vector< int > ss; range(i, 0, l) ss.emplace_back(xs[i]); range(i, r, m) ss.emplace_back(xs[i]); whole(sort, ss); i64 ans = 0; range(i, 0, n) { range(j, 0, ss.size()) { if (ss[j] >= vs[i].second) { ans += vs[i].first; ss[j] = -1; break; } } } cout << ans << endl; } } signed main() { solve(); }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n, m; cin >> n >> m; vector<vector<int>> g(n); vector<int> vis(n, -1); vector<bool> dfn(n, false); vector<int> sz(n, 0); vector<vector<int>> adj(n, vector<int>(n)); long long res = 0; for (int i = 0; i < m; i++) { int u, v; cin >> u >> v; --u, --v; g[u].push_back(v); g[v].push_back(u); adj[u][v] = adj[v][u] = 1; } vector<int> p; function<void(int)> dfs1 = [&](int now) { dfn[now] = true; for (auto to : g[now]) { if (!dfn[to]) { p.push_back(to); dfs1(to); } } }; function<long long(int)> dfs2 = [&](int dep) -> long long { if (dep == p.size()) { return 1; } vector<bool> can(3, true); for (auto to : g[p[dep]]) { if (vis[to] != -1) { can[vis[to]] = false; } } if (!can[0] && !can[1] && !can[2]) return 0; long long ret = 0; if (!dep) { vis[p[dep]] = 0; ret += 3LL * dfs2(dep + 1); vis[p[dep]] = -1; } else { for (int c = 0; c < 3; c++) { if (can[c]) { vis[p[dep]] = c; ret += dfs2(dep + 1); vis[p[dep]] = -1; } } } return ret; }; for (int i = 0; i < n; i++) { if (!dfn[i]) { p.clear(); p.push_back(i); dfs1(i); auto tmp = dfs2(0); if (tmp) { if (res) res *= tmp; else res += tmp; } } } cout << res; return 0; }
// #pragma GCC optimize(2) // #pragma GCC optimize(3) // #pragma GCC optimize("Ofast") #include<iostream> #include<cmath> #include<vector> #include<algorithm> #include<utility> using namespace std; #define _rep(i, x, y) for(int i = (int)x; i < (int)y; ++i) #define _dep(i,x,y) for(int i = (int)x; i > (int)y; i--) #define PII pair<int,int> #define eb emplace_back #define pb push_back #define fi first #define se second #define PQ priority_queue #define lb lower_bound #define ub upper_bound #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() typedef long long ll; typedef unsigned long long ull; typedef vector<int> VI; typedef vector<VI> VII; typedef vector<ll> VL; typedef vector<vector<ll>> VLL; constexpr int mod = 1e9 + 7; constexpr int KINF = 0x3f3f3f3f; constexpr int INF = 0x7f7f7f7f; constexpr double eps = 1e-7; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); int n, m; cin >> n >> m; VII g(n); _rep(i, 0, m){ int u, v; cin >> u >> v; g[--u].eb(--v); g[v].eb(u); } vector<int> be;//在同一个连通块的点 VI vis(n), col(n); auto find = [&](auto&& self, int x) -> void{ be.eb(x); vis[x] = 1; for(int& v : g[x]) if(!vis[v]) self(self, v); }; int res = 0; auto dfs = [&](auto&& self, int id) -> void{ if(id == (int)be.size()){ res++; return; } int u = be[id]; _rep(i, 1, 4){ bool ok = true; for(int& v : g[u]) if(col[v] == i) ok = false; if(!ok) continue;// 当前节点不能染成颜色i col[u] = i; self(self, id + 1); col[u] = 0; } }; ll ans = 1; _rep(i, 0, n){ if(!vis[i]){ be.clear(); find(find, i);// 求出连通块 dfs(dfs, 0); ans *= res; res = 0; } } cout << ans << endl; return 0; } // 小心左移运算符导致的int溢出 // dp记得处理非法状态 // resize并不会初始化数组 // 全局函数一定要记得inline // 带空格字符串不能直接cin,要用getline // 最好用用"\n"代替endl
#include <bits/stdc++.h> // #include <atcoder/all> #define rep(i,n) for(int i = 0; i < (n); ++i) #define srep(i,s,t) for(int i = s; i < t; ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) using namespace std; // using namespace atcoder; typedef long long int ll; typedef pair<int,int> P; #define yn {puts("Yes");}else{puts("No");} #define MAX_N 200005 int main() { int x, y, z; cin >> x >> y >> z; int ans = 0; srep(i,1,1001001){ if(i*x < y*z) ans = i; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define ll long long #define mod 1e9 + 7 using namespace std; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll x, y, z; cin >> x >> y >> z; if (ceil(((long double)(y * z) / (long double)x)) == floor(((long double)(y * z) / (long double)x))) { cout << floor(((long double)(y * z) / (long double)x)) - 1; } else { cout << floor(((long double)(y * z) / (long double)x)); } return 0; }
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx") #pragma GCC optimize("O3") #include <bits/stdc++.h> #include <sys/time.h> using namespace std; #define NUM_CAN 20 struct state { int x; int y; int score; string path; set<int> used; }; bool operator< (const state &state1, const state &state2){ return state1.score < state2.score; }; int main() { struct timeval tmp_time; gettimeofday(&tmp_time, NULL); long long program_init_time = tmp_time.tv_sec*1000000+tmp_time.tv_usec; long long fin_time, current_time; fin_time = program_init_time + 1700000; int si, sj, count; cin >> si >> sj; vector<vector<int>> tiling(50,vector<int>(50)), grids(50,vector<int>(50)); for (int i = 0; i < 50; i++) { for (int j = 0; j < 50; j++) cin >> tiling.at(i).at(j); } for (int i = 0; i < 50; i++) { for (int j = 0; j < 50; j++) cin >> grids.at(i).at(j); } vector<int> dx{1,-1,0,0}, dy{0,0,1,-1}; string dir = "DURL"; queue<state> que; priority_queue<state> next_que, rest, blank; state now_state; int best_score; string best_path; now_state.x = si, now_state.y = sj; now_state.score = grids.at(si).at(sj); now_state.path = ""; now_state.used.insert(tiling.at(si).at(sj)); best_score = now_state.score; best_path = now_state.path; que.push(now_state); count = 0; while (!que.empty()) { while (!que.empty()) { count++; now_state = que.front(); que.pop(); for (int i = 0; i < 4; i++) { if (now_state.x+dx.at(i) < 0 || now_state.x+dx.at(i) >= 50 || now_state.y+dy.at(i) < 0 || now_state.y+dy.at(i) >= 50) continue; if (now_state.used.count(tiling.at(now_state.x+dx.at(i)).at(now_state.y+dy.at(i)))) continue; now_state.score += grids.at(now_state.x+dx.at(i)).at(now_state.y+dy.at(i)); now_state.path += dir.at(i); now_state.used.insert(tiling.at(now_state.x+dx.at(i)).at(now_state.y+dy.at(i))); now_state.x += dx.at(i), now_state.y += dy.at(i); if (best_score < now_state.score) { best_score = now_state.score; best_path = now_state.path; } next_que.push(now_state); now_state.x -= dx.at(i), now_state.y -= dy.at(i); now_state.score -= grids.at(now_state.x+dx.at(i)).at(now_state.y+dy.at(i)); now_state.path.pop_back(); now_state.used.erase(tiling.at(now_state.x+dx.at(i)).at(now_state.y+dy.at(i))); } if (count % 100 == 0) { gettimeofday(&tmp_time, NULL); current_time = tmp_time.tv_sec*1000000 + tmp_time.tv_usec; if (current_time > fin_time) break; } } if (count % 100 == 0) { if (current_time > fin_time) break; } for (int i = 0; i < NUM_CAN; i++) { if (next_que.empty()) break; que.push(next_que.top()); next_que.pop(); } while (!next_que.empty()) { rest.push(next_que.top()); next_que.pop(); } while (que.size() < NUM_CAN && !rest.empty()) { que.push(rest.top()); rest.pop(); } // next_que = blank; } cout << best_path << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0; i < (int)n; i++) using P = pair<int,int>; constexpr int N = 50; constexpr int Node = 500; int sx, sy, m = 0; double start; int t[50][50]; int p[50][50]; constexpr char dir[4] = {'R','D','L','U'}; constexpr int dx[4] = {0,1,0,-1}; constexpr int dy[4] = {1,0,-1,0}; // 状態の設定 struct State { int score, px, py; vector<char> record; vector<bool> use; State() { score = 0; use.assign(m,false); } }; bool operator< (const State& s, const State &t){return s.score < t.score;} bool operator> (const State& s, const State &t){return s.score > t.score;} int main(){ // 入力と初期設定 start = (double)clock(); cin >> sx >> sy; rep(i,N) rep(j,N) { cin >> t[i][j]; m = max(m,t[i][j]); } m++; rep(i,N) rep(j,N) cin >> p[i][j]; // とりあえずビームサーチ State best; vector<State> beam_search; State is; is.px = sx; is.py = sy; is.use[t[sx][sy]] = true; is.score += p[sx][sy]; beam_search.push_back(is); while(true) { if(((double)clock() - start) / CLOCKS_PER_SEC > 1.9) break; priority_queue<State,vector<State>,greater<State>> que; for(State st : beam_search) { int x = st.px, y = st.py; rep(i,4) { State ns = st; int nx = x + dx[i], ny = y + dy[i]; if(nx < 0 or nx >= N or ny < 0 or ny >= N or ns.use[t[nx][ny]]) continue; ns.use[t[nx][ny]] = true; ns.px = nx; ns.py = ny; ns.score += p[nx][ny]; ns.record.push_back(i); if(que.size() < Node) que.push(ns); else if(ns.score > que.top().score) {que.pop(); que.push(ns);} } } beam_search.clear(); while(que.size()) { beam_search.push_back(que.top()); que.pop(); } if(beam_search.size() and beam_search.back().score > best.score) best = beam_search.back(); } for(auto x : best.record) cout << dir[x]; cout << endl; return 0; }
//Don't act like a loser. //This code is written by huayucaiji //You can only use the code for studying or finding mistakes //Or,you'll be punished by Sakyamuni!!! #include<bits/stdc++.h> #define int long long using namespace std; int read() { char ch=getchar(); int f=1,x=0; while(ch<'0'||ch>'9') { if(ch=='-') f=-1; ch=getchar(); } while(ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); } return f*x; } const int MAXN=205,MOD=200; int n,cnt; int a[MAXN],route[MAXN][MAXN]; vector<int> v[MAXN]; void out(int x) { int sz=v[x].size(); cout<<sz<<" "; for(int i=0;i<sz;i++) { cout<<v[x][i]<<" "; } puts(""); return ; } signed main() { //freopen(".in","r",stdin); //freopen(".out","w",stdout); cin>>n; for(int i=1;i<=n;i++) { a[i]=read()%MOD; } for(int i=1;i<=n;i++) { for(int j=0;j<MOD;j++) { if(!route[i][j]&&j!=0) { continue; } if(route[i+1][j]) { puts("yes"); out(route[i+1][j]); out(route[i][j]); return 0; } else { route[i+1][j]=route[i][j]; } } for(int j=0;j<MOD;j++) { if(!route[i][j]&&j!=0) { continue; } if(route[i+1][(j+a[i])%MOD]) { puts("yes"); out(route[i+1][(j+a[i])%MOD]); v[route[i][j]].push_back(i); out(route[i][j]); return 0; } v[++cnt]=v[route[i][j]]; v[cnt].push_back(i); route[i+1][(j+a[i])%MOD]=cnt; } } puts("NO"); //fclose(stdin); //fclose(stdout); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int n, a[205]; vector<int> c[205], b; void dfs(int x, int sum) { if (c[sum].size() && b != c[sum]) { cout << "Yes\n"; cout << b.size() << ' '; for (int i : b) cout << i << ' '; cout << "\n"; cout << c[sum].size() << ' '; for (int i : c[sum]) cout << i << ' '; cout << "\n"; exit(0); } else if (b.size()) c[sum] = b; if (x == n + 1) return; dfs(x + 1, sum); b.push_back(x), dfs(x + 1, (sum + a[x]) % 200), b.pop_back(); } void solve() { cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; dfs(1, 0); cout << "No\n"; } int main() { ios::sync_with_stdio(false), cin.tie(nullptr); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define ull unsigned long long #define loops(i, s, n) for (ll i = s; i < (ll)n; i++) #define loop(i, n) loops(i, 0, n) #define ALL(a) a.begin(), a.end() #define pub push_back #define pob pop_back #define mp make_pair #define dump(x) cerr << #x << " = " << (x) << endl; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef vector<int> vi; typedef vector<double> vd; typedef vector<string> vs; typedef vector<ll> vl; // for dp // 第一引数と第二引数を比較し、第一引数(a)をより大きい/小さい値に上書き template <typename T> inline bool chmin(T &a, const T &b) { bool compare = a > b; if (a > b) a = b; return compare; } template <typename T> inline bool chmax(T &a, const T &b) { bool compare = a < b; if (a < b) a = b; return compare; } #define in_v(type, name, cnt) \ vector<type> name(cnt); \ loop(i, cnt) cin >> name[i]; #define sort_v(v) std::sort(v.begin(), v.end()) #define unique_v(v) v.erase(std::unique(v.begin(), v.end()), v.end()) //必ずソート後に実行 #define set_fix(x) ((std::cerr << std::fixed << std::setprecision(x)), (std::cout << std::fixed << std::setprecision(x))) //cout for vector template <class T> ostream &operator<<(ostream &o, const vector<T> &v) { o << "{"; for (int i = 0; i < (int)v.size(); i++) o << (i > 0 ? ", " : "") << v[i]; o << "}"; return o; } // gcd ll gcd(ll a, ll b) { if (b == 0) return a; else return gcd(b, a % b); } ll lcm(ll a, ll b) { return a * b / gcd(a, b); } //prime numbers bool IsPrime(ll num) { if (num < 2) return false; else if (num == 2) return true; else if (num % 2 == 0) return false; double sqrtNum = sqrt(num); for (ll i = 3; i <= sqrtNum; i += (ll)2) { if (num % i == 0) { return false; } } return true; } vector<ll> Eratosthenes(ll N) { int arr[N]; vector<ll> res; for (int i = 0; i < N; i++) { arr[i] = 1; } for (int i = 2; i < sqrt(N); i++) { if (arr[i]) { for (int j = 0; i * (j + 2) < N; j++) { arr[i * (j + 2)] = 0; } } } for (int i = 2; i < N; i++) { if (arr[i]) { res.push_back(i); } } return res; } //digit number int GetDigit(ll num, ll radix) { unsigned digit = 0; while (num != 0) { num /= radix; digit++; } return digit; } int digsum(ll n) { ll res = 0; while (n > 0) { res += n % (ll)10; n /= (ll)10; } return res; } int main() { int n; cin >> n; vector<ll> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } sort(ALL(a)); dump(a); dump(n / 2); dump(a[n / 2]); ld x = n % 2 == 0 ? (double)(a[n / 2 - 1] + a[n / 2]) / (double)4 : a[n / 2] / (double)2; // cout << "x: " << x << endl; ld res = 0; for (int i = 0; i < n; i++) { // cout << "res: " << res << endl; // cout << "min((double)2 * x, (ld)a[i]): " << min((double)2 * x, (ld)a[i]) << endl; // cout << "a[i]: " << a[i] << endl; res += x + (double)a[i] - min((double)2 * x, (ld)a[i]); } set_fix(20) << (double)res / (double)n << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define FOR(var, begin, end) for (int var = (begin); var <= (end); var++) #define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--) #define REP(var, length) FOR(var, 0, length - 1) #define RREP(var, length) RFOR(var, length - 1, 0) #define EACH(value, var) for (auto value : var) #define SORT(var) sort(var.begin(), var.end()) #define REVERSE(var) reverse(var.begin(), var.end()) #define RSORT(var) SORT(var); REVERSE(var) #define OPTIMIZE_STDIO ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed #define endl '\n' const int INF = 1e9; const int MOD = 1e9 + 7; const ll LINF = 1e18; using P = pair<int, int>; void solve(istream& cin, ostream& cout) { int n; cin >> n; vector<P> coo; REP(i, n) { int x, y; cin >> x >> y; coo.emplace_back(x, y); } int ans = 0; REP(i, n - 2) { REP(j, n - 1) { REP(k, n) { if (i >= j) continue; if (j >= k) continue; int x1 = coo[i].first, y1 = coo[i].second; int x2 = coo[j].first, y2 = coo[j].second; int x3 = coo[k].first, y3 = coo[k].second; if ((x1 == x2 && x2 == x3) || (y1 == y2 && y2 == y3)) ans++; else if (x1 == x2 || y1 == y2) continue; else if ((float(y3 - y2) / float(y2 - y1)) == (float(x3 - x2) / float(x2 - x1))) ans++; } } } if (ans >= 1) { cout << "Yes" << endl; } else { cout << "No" << endl; } } #ifndef TEST int main() { OPTIMIZE_STDIO; solve(cin, cout); return 0; } #endif
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<long long> VL; typedef vector<vector<long long>> VVL; typedef pair<int,int> Pair; typedef tuple<int,int,int> tpl; #define ALL(a) (a).begin(),(a).end() #define SORT(c) sort((c).begin(),(c).end()) #define REVERSE(c) reverse((c).begin(),(c).end()) #define EXIST(m,v) (m).find((v)) != (m).end() #define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin() #define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin() #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i) #define RREP(i,n) RFOR(i,n,0) #define en "\n" constexpr double EPS = 1e-9; constexpr double PI = 3.1415926535897932; constexpr int INF = 2147483647; constexpr long long LINF = 1LL<<60; constexpr long long MOD = 1000000007; // 998244353; template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;} template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;} void Main(){ int N; cin >> N; VVI edge(400400); REP(i,N){ int a,b; cin >> a >> b; a--; b--; edge[a].push_back(b); edge[b].push_back(a); } int ans = 0; vector<bool> vis(400400,false); REP(i,400400){ if(vis[i]) continue; stack<Pair> s({Pair(i,0)}); int nv = 0, ne = 0; while(!s.empty()){ auto [v,ptr] = s.top(); s.pop(); if(!vis[v]){ vis[v] = true; nv++; } for(int j=ptr; j<(int)edge[v].size(); j++){ ne++; if(vis[edge[v][j]]) continue; s.emplace(v,j+1); s.emplace(edge[v][j],0); break; } } ne /= 2; if(nv == ne+1) ans += nv-1; else ans += nv; } cout << ans << en; return; } int main(void){ cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15); int t=1; //cin>>t; REP(_,t) Main(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); constexpr int N = 400000; int n; cin >> n; vector<int> a(n), b(n); vector<vector<int>> g(N); vector<int> cnt(N); vector<bool> used(n), visited(N); for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; --a[i], --b[i]; g[a[i]].push_back(i); g[b[i]].push_back(i); cnt[a[i]]++, cnt[b[i]]++; } queue<int> q; int ans = 0; for (int i = 0; i < N; i++) { if (cnt[i] == 1 && !visited[i]) { for (int x : g[i]) { if (!used[x]) { used[x] = true; cnt[a[x] ^ b[x] ^ i]--; } } ans += 1; cnt[i] -= 1; visited[i] = true; q.push(i); } } while (!q.empty()) { int x = q.front(); q.pop(); for (int i : g[x]) { int to = a[i] ^ b[i] ^ x; if (cnt[to] == 1 && !visited[to]) { for (int u : g[to]) { if (!used[u]) { used[u] = true; cnt[a[u] ^ b[u] ^ to]--; } } ans += 1; cnt[to] -= 1; visited[to] = true; q.push(to); } } } for (int i = 0; i < N; i++) { ans += !visited[i] && cnt[i] > 0; } cout << ans << '\n'; return 0; }
#include "bits/stdc++.h" using namespace std; #ifdef LOCAL #include "debug.h" #define input freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #else #define debug(...) 4 #define input 4 #endif using ll = long long; //const int mod = 998244353; const int mod = 1e9 + 7; const int N = 2e5 + 5; struct DSU { int par[N]; int sz[N]; int find(int x) { return x == par[x] ? x : par[x] = find(par[x]); } //path compression(logn) void merge(int a, int b) { a = find(a); b = find(b); if(a == b) return; if(sz[a] < sz[b]) swap(a, b); sz[a] += sz[b]; par[b] = a; } void init(int n) { for(int i = 0; i <= n; i++) par[i] = i, sz[i] = 1; } }; DSU d; vector<int> g[N]; vector<int> dist[N]; int a[N]; void bfs(vector<int> &dist, int src) { queue<int> q; q.push(src); dist[src] = 0; while(q.size()) { int at = q.front(); q.pop(); for(int j : g[at]) { if(dist[j] == -1) { dist[j] = dist[at] + 1; q.push(j); } } } } int dp[1 << 18][18]; int k; int solve(int mask, int last) { if(mask == (1 << k) - 1) { return 0; } if(~dp[mask][last]) return dp[mask][last]; int ans = 1e9; for(int j = 0; j < k; j++) { if(mask & (1 << j)) continue; ans = min(ans, dist[last][a[j]] + solve(mask ^ (1 << j), j)); } return dp[mask][last] = ans; } signed main() { input; cin.tie(nullptr) -> sync_with_stdio(false); int t = 1; // cin >> t; while(t--) { int n, m; cin >> n >> m; d.init(n + 1); for(int i = 0; i < m; i++) { int x, y; cin >> x >> y; g[x].push_back(y); g[y].push_back(x); d.merge(x, y); } cin >> k; set<int> s; for(int i = 0; i < k; i++) { cin >> a[i]; s.insert(d.find(a[i])); } if(s.size() > 1) { cout << "-1\n"; return 0; } for(int i = 0; i < k; i++) { vector<int> temp(n + 1, -1); bfs(temp, a[i]); dist[i] = temp; } int ans = 1e9; for(int i = 0; i < k; i++) { memset(dp, -1, sizeof dp); ans = min(ans, solve(1 << i, i)); } cout << ans + 1; } }
#include <bits/stdc++.h> #define rep(a,n) for (ll a = 0; a < (n); ++a) using namespace std; //using namespace atcoder; using ll = long long; typedef pair<ll,ll> P; typedef pair<ll,P> PP; typedef vector<vector<int> > Graph; 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 ll INF = 1e18+7; #define debug(v) cout<<#v<<": ",prt(v); template <typename A,typename B> inline void prt(pair<A,B> p){cout<<"("<<p.first<<", "<<p.second<<")\n";} template <typename A,typename B,typename C> inline void prt(tuple<A,B,C> p){cout<<"("<<get<0>(p)<<", "<<get<1>(p)<<", "<<get<2>(p)<<")\n";} inline void prt(bool p){if(p)cout<<"True"<<'\n';else cout<<"False"<<'\n';} template <typename T> inline void prt(vector<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';} template<typename T> inline void prt(vector<vector<T> >& vv){ for(const auto& v : vv){ prt(v); } } template <typename T> inline void prt(deque<T> v){cout<<'{';for(ll i=0;i<v.size();i++){cout<<v[i];if(i<v.size()-1)cout<<", ";}cout<<'}'<<'\n';} template <typename A,typename B> inline void prt(map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';} template <typename A,typename B> inline void prt(unordered_map<A,B> v){cout<<'{';ll c=0;for(auto &p: v){cout<<p.first<<":"<<p.second;c++;if(c!=v.size())cout<<", ";}cout<<'}'<<'\n';} template <typename T> inline void prt(set<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';} template <typename T> inline void prt(multiset<T> v){cout<<'{';for(auto i=v.begin();i!=v.end();i++){cout<<*i;if(i!=--v.end())cout<<", ";}cout<<'}'<<'\n';} /* 方針 */ ll n,m; vector<ll>a,b; ll k; vector<ll>c; Graph g; vector<ll>dist; ll kyori[20][20]; int main(){ cin >> n >> m; a.resize(m); b.resize(m); g.resize(n); rep(i,m){ cin>>a[i]>>b[i]; a[i]--;b[i]--; g[a[i]].push_back(b[i]); g[b[i]].push_back(a[i]); } cin >> k; c.resize(k); rep(i,k){ cin>>c[i]; c[i]--; } ll start,goal; rep(i,20)rep(j,20)kyori[i][j]=INF; rep(i,k){ vector<ll>dist(n,INF); queue<ll>que; que.push(c[i]); dist[c[i]]=0; while(!que.empty()){ auto v = que.front();que.pop(); for(auto x:g[v]){ if(dist[x]!=INF)continue; dist[x]=dist[v]+1; que.push(x); } } ll M = 0; rep(j,k){ if(dist[c[j]]==INF){ cout << -1 << endl; return 0; } kyori[i][j]=dist[c[j]]; if(chmax(M,kyori[i][j])&&i==0){ goal = j; } if(chmax(M,kyori[i][j])&&i==goal){ start = j; } } } //bitDP ll ans = INF; rep(test,12){ ll i = (start+test)%k; vector<vector<ll> >dp(((1<<k)+1),vector<ll>(k+1,INF)); dp[(1<<i)][i]=1; rep(S,(1<<k)){ rep(v,k){ rep(u,k){ if (S != 0 && !(S & (1 << u))) continue; // u を含まない場合を除く if ((S & (1 << v)) == 0) { if (v != u) chmin(dp[S | (1 << v)][v], dp[S][u] + kyori[u][v]); } } } } rep(j,k){ chmin(ans,dp[(1<<k)-1][j]); } } /* rep(test,5){ ll i = (goal+test*2)%k; vector<vector<ll> >dp(((1<<k)+1),vector<ll>(k+1,INF)); dp[(1<<i)][i]=1; rep(S,(1<<k)){ rep(v,k){ rep(u,k){ if (S != 0 && !(S & (1 << u))) continue; // u を含まない場合を除く if ((S & (1 << v)) == 0) { if (v != u) chmin(dp[S | (1 << v)][v], dp[S][u] + kyori[u][v]); } } } } rep(j,k){ chmin(ans,dp[(1<<k)-1][j]); } } */ cout << ans << endl; return 0; }
#include "bits/stdc++.h" #define MOD 1000000007 #define rep(i, n) for(ll i=0; i < (n); i++) #define rrep(i, n) for(ll i=(n)-1; i >=0; i--) #define ALL(v) v.begin(),v.end() #define rALL(v) v.rbegin(),v.rend() #define FOR(i, j, k) for(ll i=j;i<k;i++) #define debug_print(var) cerr << #var << "=" << var <<endl; #define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" " #define fi first #define se second using namespace std; typedef long long int ll; typedef vector<ll> llvec; typedef vector<double> dvec; typedef pair<ll, ll> P; typedef long double ld; struct edge{ll x, c;}; /************************************** ** A main function starts from here ** ***************************************/ int main(){ ll N, M; cin >> N >> M; vector<P> v(1e3+1, {0, 0}); rep(i, N){ ll a; cin >> a; v[a].fi++; } rep(i, M){ ll a; cin >> a; v[a].se++; } rep(i, 1e3){ if((v[i+1].fi xor v[i+1].se) == 1){ cout << i + 1 << " "; } } return 0; }
#include<bits/stdc++.h> #include<stdio.h> #include<queue> #define ll long long #define ull unsigned long long #define ln "\n" using namespace std; #define dbg(x) cout<<#x<<" = "<<x<<" " #define rep(i,s,n) for(ll i = (s);i<(n);++i) void solve(){ ll n; cin>>n; vector<ll>cnt(n+1,0); for(int i=0;i<n;i++) { cnt[i+1]++; } for(int i=0;i<n;i++) { ll x; cin>>x; cnt[x]--; } string ans="Yes"; for(int i=0;i<n;i++) { if(cnt[i+1]!=0) { ans="No"; break; } } cout<<ans<<ln; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int test=1; // cin>>test; while(test--) solve(); return 0; }
#include<bits/stdc++.h> using namespace std; #define FastIO ios_base::sync_with_stdio(false); cin.tie(0); #define ll long long #define ull unsigned long long #define pb push_back #define All(x) (x).begin(),(x).end() #define mp make_pair #define nl "\n" typedef pair<int,int>ii; typedef vector<int>vi; typedef vector<ii>vii; typedef vector<vi>vvi; typedef vector<long long>vl; typedef vector <vl>vvl; template<class T> void print(T& a) { for(auto x:a) cout<<x<<" "; cout<<"\n"; } int main() { FastIO int a[3]; for(int &x:a)cin>>x; sort(a,a+3); cout<<a[1]+a[2]<<nl; return 0; }
#include <bits/stdc++.h> #include <math.h> #define rep(i, n) for(int i = 0; i < (n); i++) #define rrep(i, n) for(int i = (n-1); i >= 0; i--) using namespace std; typedef long long ll; const int MOD = 1000000007; //const int MOD = 998244353; const ll INF = 1LL<<60; const int IINF = 1000000000; 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(){ ios::sync_with_stdio(false); cin.tie(nullptr); ll X, Y, A, B; cin >> X >> Y >> A >> B; Y--; ll ans = 0; rep(i,100){ ll str = X; ll i_count = 0; rep(j,i){ if ((Y+(A-1)) / A <= str){ i_count = j; break; } str *= A; i_count = j+1; } //cout << i_count << endl; if(Y <= str) continue; ll remain = Y - str; ll count = remain/B; /*cout << i << endl; cout << str << endl; cout << count << endl; */ ans = max(ans, (ll)(count+i_count)); } cout << ans << endl; }
/*{{{*/ #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<algorithm> #include<string> #include<iostream> #include<sstream> #include<set> #include<map> #include<queue> #include<bitset> #include<vector> #include<limits.h> #include<assert.h> #define SZ(X) ((int)(X).size()) #define ALL(X) (X).begin(), (X).end() #define REP(I, N) for (int I = 0; I < (N); ++I) #define REPP(I, A, B) for (int I = (A); I < (B); ++I) #define FOR(I, A, B) for (int I = (A); I <= (B); ++I) #define FORS(I, S) for (int I = 0; S[I]; ++I) #define RS(X) scanf("%s", (X)) #define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end())))) #define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin()) #define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++) #define MP make_pair #define PB emplace_back #define MS0(X) memset((X), 0, sizeof((X))) #define MS1(X) memset((X), -1, sizeof((X))) #define LEN(X) strlen(X) #define F first #define S second using namespace std; typedef long long LL; typedef unsigned long long ULL; typedef long double LD; typedef pair<int,int> PII; typedef vector<int> VI; typedef vector<LL> VL; typedef vector<PII> VPII; typedef pair<LL,LL> PLL; typedef vector<PLL> VPLL; template<class T> void _R(T &x) { cin >> x; } void _R(int &x) { scanf("%d", &x); } void _R(int64_t &x) { scanf("%lld", &x); } void _R(double &x) { scanf("%lf", &x); } void _R(char &x) { scanf(" %c", &x); } 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 int64_t &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.F); putchar(' '); _W(x.S);} 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...); } #ifdef HOME #define DEBUG(...) {printf("[DEBUG] ");W(__VA_ARGS__);} #else #define DEBUG(...) #endif int MOD = 1e9+7; void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;} /*}}}*/ const int SIZE = 1<<20; LL N; void solve() { if(N&1)W("Odd"); else if(N%4==0)W("Even"); else W("Same"); } void input() { R(N); } int main(){ CASET { input(); solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; int x[200005], c[200005]; vector<int> v[200005]; int main(){ int n; scanf("%d", &n); for(int i=1;i<=n;i++){ scanf("%d%d", &x[i], &c[i]); v[c[i]].emplace_back(x[i]); } int la1 = 0, la2 = 0; long long res1 = 0, res2 = 0; for(int i=1;i<=n;i++){ if(v[i].empty()) continue; sort(v[i].begin(), v[i].end()); int l = v[i][0], r = v[i].back(); long long ans1 = 1e18, ans2 = 1e18; ans1 = min(ans1, abs(la1-r)*1ll+abs(r-l)+res1); ans1 = min(ans1, abs(la2-r)*1ll+abs(r-l)+res2); ans2 = min(ans2, abs(la1-l)*1ll+abs(l-r)+res1); ans2 = min(ans2, abs(la2-l)*1ll+abs(l-r)+res2); la1 = l, la2 = r; res1 = ans1, res2 = ans2; } printf("%lld\n", min(res1+abs(la1), res2+abs(la2))); }
#include <bits/stdc++.h> using namespace std; // #include <atcoder/all> // using namespace atcoder; // using mint = modint1000000007; // using mint2 = modint998244353; typedef int64_t Int; #define all(x) (x).begin(), (x).end() const double EPS = 1e-10; const Int INF = 1e18; const int inf = 1e9; const Int mod = 1e9+7; //const Int mod = 998244353; typedef struct { int64_t to, weight; } edge; Int dx[] = {0, 1, 0, -1, -1, 1, -1, 1}; Int dy[] = {1, 0, -1, 0, -1, -1, 1, 1}; template<class T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) { is >> e; } return is; } bool print_space_enable = false; void print() { std::cout << '\n'; print_space_enable = false; } template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { if (print_space_enable) std::cout << " "; std::cout << fixed << setprecision(15) << head; print_space_enable = true; print(std::forward<Tail>(tail)...); } template<typename T> void print(vector<T> v) { for (size_t i = 0; i < v.size(); i++) { if (i > 0) std::cout << " "; std::cout << v[i]; } std::cout << '\n'; } template<class T> vector<T> make_vec(size_t n, T val) { return vector<T>(n, val); } template<class... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); } bool is_overflow(Int a, Int b) { return a > INF / b; } void solve() { Int n; cin >> n; print((n - 1) / 100 + 1); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); solve(); //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++) int main() { string s; cin>>s; cout<<s[1]<<s[2]<<s[0]<<endl; }
#include<string> #define _CRT_SECURE_NO_WARNINGS #include<iostream> using namespace std; enum { A_one = 4, A_two = 12, A_three = 24, A_four = 24 }; int main(){ string input; cin >> input; int len = input.size(); int exist = 0; int notSure = 0; int notExist = 0; int res = 0; if (len != 10) { cout << res; return 0; } for (int i = 0; i < len; i++) { if (input[i] == 'o') exist++; else if (input[i] == '?') notSure++; else notExist++; } if (exist > 4) { cout << res; return 0; } else if (exist == 4) { res = A_four; cout << res; return 0; } else if (exist == 3) { if (notSure < 1) { res = 3 * A_two; cout << res; return 0; } else { res = 3 * A_two + notSure * A_three; cout << res; return 0; } } else if (exist == 2) { if (notSure == 0) { res = 14; cout << res; return 0; } else if (notSure == 1) { res = 14 + 3 * A_two; cout << res; return 0; } else { res = 14 + notSure * 3 * A_two + notSure * (notSure - 1) / 2 * A_three; cout << res; return 0; } } else if (exist == 1) { if (notSure == 0) { res = 1; cout << res; return 0; } else if (notSure == 1) { res = 1 + 14; cout << res; return 0; } else if (notSure == 2) { res = 1 + 2 * 14 + 3 * A_two; cout << res; return 0; } else { res = 1 + notSure * 14 + notSure * (notSure - 1) / 2 * 3 * A_two + notSure * (notSure - 1) * (notSure - 2) / 6 * A_three; cout << res; return 0; } } //exist == 0; else { if (notSure == 0) { cout << res; return 0; } else if (notSure == 1) { res = 1; cout << res; return 0; } else if (notSure == 2) { res = 2 + 14; cout << res; return 0; } else if (notSure == 3) { res = 3 + 3 * 14 + 3 * A_two; cout << res; return 0; } else { res = notSure + notSure * (notSure - 1) / 2 * 14 + notSure * (notSure - 1) * (notSure - 2) / 6 * 3 * A_two + notSure * (notSure - 1) * (notSure - 2) * (notSure - 3) / 24 * A_four; cout << res; return 0; } } }
#include<bits/stdc++.h> #define int long long #define endl '\n' using namespace std; int32_t main() { ios::sync_with_stdio(false); cin.tie(0); string s; cin >> s; set<int> avail, not_avail, unsure; for (int i = 0; i < 10; i++) { if (s[i] == 'o') avail.insert(i); else if (s[i] == 'x') not_avail.insert(i); else unsure.insert(i); } int ans = 0; for (int i = 0; i < 10; i++) { if (not_avail.count(i)) continue; for (int j = 0; j < 10; j++) { if (not_avail.count(j)) continue; for (int k = 0; k < 10; k++) { if (not_avail.count(k)) continue; for (int l = 0; l < 10; l++) { if (not_avail.count(l)) continue; set<int> temp; if (avail.count(i)) temp.insert(i); if (avail.count(j)) temp.insert(j); if (avail.count(k)) temp.insert(k); if (avail.count(l)) temp.insert(l); if (temp.size() == avail.size()) ans++; } } } } cout << ans << endl; return 0; }
#pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") using namespace std; #include "bits/stdc++.h" #define el "\n" typedef long long ll; const int MM = 2e3+1, MOD = 1e9+7; int R, C, dir[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; pair<int, int> st, ed; vector<pair<int, int>> tele[26]; char gr[MM][MM]; bool vis[MM][MM], used[26]; queue<pair<pair<int, int>, int>> q; int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(0); cin >> R >> C; for(int i = 1; i <= R; i++) { for(int j = 1; j <= C; j++) { cin >> gr[i][j]; if(gr[i][j] == 'S') { st = {i, j}; } else if(gr[i][j] == 'G') { ed = {i, j}; } else if(gr[i][j] != '.' && gr[i][j] != '#') { tele[gr[i][j] - 'a'].push_back({i, j}); } } } q.push({st, 0}); vis[st.first][st.second] = true; while(!q.empty()) { int x = q.front().first.first, y = q.front().first.second, d = q.front().second; q.pop(); if(x == ed.first && y == ed.second) { cout << d << el; return 0; } for(int i = 0; i < 4; i++) { int nx = x + dir[i][0], ny = y + dir[i][1]; if(nx >= 1 && nx <= R && ny >= 1 && ny <= C && vis[nx][ny] == false && gr[nx][ny] != '#') { vis[nx][ny] = true; q.push({{nx, ny}, d + 1}); } } if(gr[x][y] != 'S' && gr[x][y] != 'G' && gr[x][y] != '.' && gr[x][y] != '#') { if(used[gr[x][y] - 'a'] == true) continue; used[gr[x][y] - 'a'] = true; for(pair<int, int> t : tele[gr[x][y] - 'a']) { if(t.first == x && t.second == y) continue; if(vis[t.first][t.second] == false) { vis[t.first][t.second] = true; q.push({{t.first, t.second}, d + 1}); } } } } cout << -1 <<el; } // initialize
#include<cstdio> using namespace std; const int N=2010,M=1000000007; int h,w,dp[N][N],s[N][N],z[N][N],x[N][N]; char c[N][N]; int main(){ scanf("%d%d",&h,&w); for(int i=0;i<h;++i)scanf("%s",c[i]); dp[0][0]=1; for(int i=0;i<h;++i)for(int j=0;j<w;++j){ if(i||j)dp[i][j]=((long long)s[i][j]+z[i][j]+x[i][j])%M; if(i<h-1&&c[i+1][j]=='.')s[i+1][j]=(s[i][j]+dp[i][j])%M; if(j<w-1&&c[i][j+1]=='.')z[i][j+1]=(z[i][j]+dp[i][j])%M; if(i<h-1&&j<w-1&&c[i+1][j+1]=='.')x[i+1][j+1]=(x[i][j]+dp[i][j])%M; } printf("%d",dp[h-1][w-1]); return 0; }
#include <bits/stdc++.h> /*#include <iostream> #include <algorithm> #include <math.h> #include <iomanip> #include <string> #include <vector> #include <set> #include <sstream>*/ #define ll long long #define fop(i,m,n) for(int i=m; i<n; i++) #define fastIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0) #define X first #define Y second #define pb push_back #define mp make_pair #define all(v) v.begin(),v.end() using namespace std; const long long MOD = 1e9+7; const long long N = 1e9+5; const long long Nlog = 17; const long long Hash = 257; const double PI = 2.0*acos(0.0);//<cmath> //const double PI = 3.141592653; const double E = 2.718281828; struct Seg{ int l, r, m; int val; Seg* ch[2]; Seg(int inl, int inr) : l(inl), r(inr), m((l+r)>>1){ if(r-l == 1) val = 0; else{ ch[0] = new Seg(l, m); ch[1] = new Seg(m, r); pull(); } } void pull(){ val = ch[0]->val + ch[1]->val; } void set(int p, int v){ if(r-l == 1) val = v; else{ if(p < m) ch[0]->set(p, v); else ch[1]->set(p, v); pull(); } } int query(int a, int b){ if(r <= a || b <= l) return 0; if(a <= l && r <= b) return val; return ch[0]->query(a, b) + ch[1]->query(a, b); } }; void solve(){ int n; cin >> n; ll a[n], b[n]; fop(i,0,n){ cin >> a[i]; a[i] += i; } fop(i,0,n){ cin >> b[i]; b[i] += i; } map<ll, deque<int> > m; fop(i,0,n){ m[a[i]].pb(i); } int p[n]; fop(i,0,n){ if(m[b[i]].empty()){ cout << "-1\n"; return; } p[i] = m[b[i]].front(); m[b[i]].pop_front(); } //fop(i,0,n) cout << p[i] << ' '; //cout << '\n'; ll ans = 0; Seg tree(0, n); fop(i,0,n){ ans += tree.query(p[i], n); tree.set(p[i], 1); } cout << ans << '\n'; } int main() { fastIO; int t=1; //cin >> t; while(t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) #define Pr pair<ll,ll> #define Tp tuple<ll,ll,ll> using Graph = vector<vector<int>>; ll mod = 998244353; //segment tree //1-indexed all class segtree { public: ll n; vector<ll> A; segtree(ll k){ n = 1; while(n<k){ n *= 2; } A=vector<ll>(2*n,0); } //a[i]にxを加算する void add(ll i,ll x){ int index = n-1+i; A[index] += x; while(index>1){ index /= 2; A[index] = A[2*index]+A[2*index+1]; } } //a[i]をにする void replace(ll i,ll x){ int index = n-1+i; A[index] = x; while(index>1){ index /= 2; A[index] = A[2*index]+A[2*index+1]; } } //a[i]+a[i+1]+…+a[j]を求める ll sum(ll i,ll j){ return rangesum(i,j,1,1,n); } // a,b求める区間 k区間番号 c,d区間の始終点(k=1,c=1,d=nで入力する) ll rangesum(ll a,ll b,ll k,ll c,ll d){ //単位元の設定 ll el = 0; if(d<a||b<c){ return el; } else if(a<=c&&d<=b){ return A[k]; } else{ //2区間に分割して演算を行う ll p = rangesum(a,b,k*2,c,(c+d)/2)+rangesum(a,b,k*2+1,(c+d)/2+1,d); return p; } } }; int main() { ll N; cin >> N; ll a[N],b[N]; set<Pr> num; num.insert(make_pair(2e18,0LL)); rep(i,N){ cin >> a[i]; num.insert(make_pair(a[i]+i,i)); } vector<Pr> perm; rep(i,N){ cin >> b[i]; ll k = b[i]+i; auto itr = num.lower_bound(make_pair(k,-1)); auto p = *itr; ll s = p.first; if(s!=k){ cout << -1 << endl; return 0; } ll j = p.second; perm.push_back(make_pair(i+1,j+1)); num.erase(itr); } ll ans = 0; //main関数内で segtree seq(N+1); //などと宣言し seq.replace(i,x); //のように使う 1-indexed 注意!!!!!! sort(perm.begin(),perm.end()); reverse(perm.begin(),perm.end()); for(auto q:perm){ ll j = q.second; //cout << j << endl; ans += seq.sum(1,j); seq.add(j,1); } cout << ans << endl; }
#include <algorithm> #include <array> #include <cassert> #include <chrono> #include <cmath> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <vector> using namespace std; using ll = long long; #define rep(i, a, b) for (int i = a; i < (b); ++i) #define sz(x) (int)(x).size() #define ms(arr, v) memset(arr, v, sizeof(arr)) #define f first #define s second #define pb push_back // clang-format off template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; } template<typename T_vector>void output_vector(const T_vector &v, bool add_one = false, int start = -1, int end = -1) {if (start < 0) start = 0; if (end < 0) end = int(v.size()); for (int i = start; i < end; i++) cout << v[i] + (add_one ? 1 : 0) << (i < end - 1 ? ' ' : '\n');} template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; } template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << "(" << v.first << ":" << v.second << ")" << ","; os << "}"; return os; } auto random_address = [] {char *p = new char; delete p;return uint64_t(p);}; const uint64_t SEED = chrono::steady_clock::now().time_since_epoch().count() * (random_address() | 1); mt19937_64 rng(SEED); // clang-format on void solve() { } vector<int> to_int(int x) { vector<int> a; while (x) { int s = x % 10; a.push_back(s); x /= 10; } return a; } int g1(vector<int> x) { int ans = 0; sort(x.rbegin(), x.rend()); // 314 int z = 1; for (int i = sz(x) - 1; i >= 0; --i) { ans += z * x[i]; z *= 10; } return ans; } int g2(vector<int> x) { int ans = 0; sort(x.begin(), x.end()); // 314 int z = 1; for (int i = sz(x) - 1; i >= 0; --i) { ans += z * x[i]; z *= 10; } return ans; } int main() { ios::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; int x = n; vector<int> ans; for (int i = 0; i < k; i++) { auto d = to_int(x); int t = g1(d) - g2(d); x = t; ans.push_back(t); } if (k == 0) cout << n; else { cout << ans[sz(ans) - 1]; } // int tests; // cin >> tests; // while (tests-- > 0) // solve(); }
#include <bits/stdc++.h> #define speedup \ ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr), \ cout.precision(12) using namespace std; #ifndef ONLINE_JUDGE #define eprintf(...) fprintf(stderr,__VA_ARGS__), fflush(stderr) #else #define eprintf(...) void(0) #endif using ll = long long; using str = string; using vi = vector<int>; #define pb push_back #define all(x) (x).begin(),(x).end() #define sz(x) int((x).size()) ll nxt(ll N) { vi d; while(N) { d.pb(N%10); N/=10; } sort(all(d)); ll a=0,b=0,p=1; for(const auto& it:d) { a=a*10+it; b=it*p+b; p*=10; } return b-a; } int main() { speedup; ll N,k; cin>>N>>k; while(k--&&N>0) { N=nxt(N); } cout<<N<<'\n'; }
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> P; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define repto(i, n) for(int i = 0; i <= (n); i++) #define all(c) (c).begin(), (c).end() #define uniq(c) c.erase(unique(all(c)), (c).end()) #define _1 first #define _2 second #define pb push_back #define mp make_pair #define INF 1145141919 #define MOD 1000000007 #define DEBUG(x) cout << #x << ": " << x << endl; template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); } ll mod_pow(ll x, ll n) { if (n == 0) return 1; ll res = mod_pow(x * x % MOD, n / 2); if (n & 1) res = res * x % MOD; return res; } int main() { cin.tie(0); ios::sync_with_stdio(false); int H, W; cin >> H >> W; vector<string> S(H); int K = 0; rep (i, H) { cin >> S[i]; rep (j, W) { if (S[i][j] == '.') K++; } } vector<vector<int>> a(H, vector<int>(W, 0)); vector<vector<int>> b(H, vector<int>(W, 0)); rep (i, H) { int cnt = 0; rep(j, W) { if (S[i][j] == '.') { cnt++; if (j == W-1) { a[i][j] = cnt; } else { if (S[i][j+1] == '#') { a[i][j] = cnt; cnt = 0; } } } } } rep (i, H) { int cnt = 0; for (int j = W-1; j >= 0; j--) { if (a[i][j] > 0) { cnt = a[i][j]; } if (S[i][j] == '.') a[i][j] = cnt; } } // rep (i, H) { // rep (j, W) { // cout << a[i][j]; // } // cout << endl; // } rep (j, W) { int cnt = 0; rep(i, H) { if (S[i][j] == '.') { cnt++; if (i == H-1) { b[i][j] = cnt; } else { if (S[i+1][j] == '#') { b[i][j] = cnt; cnt = 0; } } } } } rep (j, W) { int cnt = 0; for (int i = H-1; i >= 0; i--) { if (b[i][j] > 0) { cnt = b[i][j]; } if (S[i][j] == '.') b[i][j] = cnt; } } ll ans = 0; rep(i, H) { rep (j, W) { if (S[i][j] == '.') { int m = a[i][j]+b[i][j]-1; ans += (((mod_pow(2, (ll)(m))-1)*mod_pow(2, (ll)(K-m)))%MOD); ans %= MOD; } // cout << ans << endl; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; // using mint = long double; // using mint = modint998244353; // using mint = modint1000000007; typedef long long ll; typedef pair<ll, ll> P; typedef pair<P, ll> T; typedef pair<ll, vector<ll>> Pd; const ll INF = 2e18; const ll fact_table = 1200008; priority_queue<ll> pql; priority_queue<P> pqp; // big priority queue // priority_queue <ll, vector<ll>, greater<ll> > pqls; priority_queue<P, vector<P>, greater<P>> pqps; // small priority queue // top pop ll dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}; ll dy[8] = {0, 1, 0, -1, -1, 1, 1, -1}; //↓,→,↑,← /* #define endl "\n" #ifdef ENJAPMA #undef endl #endif */ #define p(x) cout << x << endl; #define el cout << endl; #define pe(x) cout << x << " "; #define ps(x) cout << fixed << setprecision(25) << x << endl; #define pu(x) cout << (x); #define pb push_back #define lb lower_bound #define ub upper_bound #define pc(x) cout << x << ","; #define rep(i, n) for (ll i = 0; i < (n); i++) #define rep2(i, a, b) for (ll i = a; i <= (b); i++) #define rep3(i, a, b) for (ll i = a; i >= (b); i--) #define all(c) begin(c), end(c) typedef vector<ll> vec; typedef vector<vector<ll>> mat; // vec v(n) -> 長さnのベクトルを宣言 // mat dp(h, vec(w)) -> h * w の行列を宣言 const ll mod = 998244353ll; // const ll mod = 1000000007ll; ll mypow(ll a, ll b, ll m = mod) { ll x = 1; while (b) { while (!(b & 1)) { (a *= a) %= m; b >>= 1; } (x *= a) %= m; b--; } return x; } vec rv(ll read) { vec res(read); for (int i = 0; i < read; i++) { cin >> res[i]; } return res; } /* ll fact[fact_table + 5], rfact[fact_table + 5]; void c3_init() { fact[0] = rfact[0] = 1; for (ll i = 1; i <= fact_table; i++) { fact[i] = (fact[i - 1] * i) % mod; } rfact[fact_table] = mypow(fact[fact_table], mod - 2, mod); for (ll i = fact_table; i >= 1; i--) { rfact[i - 1] = rfact[i] * i; rfact[i - 1] %= mod; } return; } ll c3(ll n, ll r) { return (((fact[n] * rfact[r]) % mod) * rfact[n - r]) % mod; } */ bool icpc = false; bool multicase = false; ll n, k; ll dist = 0, cnt = 0; vec G[500005]; P dfs(int v, int p) { // first : 一番近い黒までの距離 // second : 一番遠い白までの距離 ll black = INF, white = 0; for (auto nv : G[v]) { if (nv == p) continue; auto [b, w] = dfs(nv, v); black = min(black, b); white = max(white, w); } if (white + black <= dist) { white = -1; } if (white == dist) { cnt++; white = -1, black = 0; } if (p == -1 && white >= 0) { cnt++; } black++; white++; return P(black, white); } int calc(ll mid) { dist = mid; cnt = 0; P res = dfs(1, -1); return cnt; } bool solve() { cin >> n >> k; rep(i, n - 1) { int a, b; cin >> a >> b; G[a].pb(b); G[b].pb(a); } ll ok = n, ng = -1; while (abs(ok - ng) > 1) { ll mid = (ok + ng) / 2; if (calc(mid) <= k) { ok = mid; } else { ng = mid; } } p(ok); return true; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); if (icpc) { while (solve()) ; return 0; } ll q, testcase = 1; if (multicase) { cin >> q; } else { q = 1; } while (q--) { solve(); testcase++; } // solve(); return 0; }
#include <iostream> #include <algorithm> #include <iomanip> #include <vector> #include <queue> #include <set> #include <map> #include <tuple> #include <cmath> #include <numeric> #include <functional> #include <cassert> #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; int pow10(int x){ int ans = 1; while(x--) ans *= 10; return ans; } ll tri(ll x){ return x*(x-1); } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int k; string s, t; cin >> k >> s >> t; auto calc = [&](string s_, int x){ vector<int> c(10); c[x]++; for(int i = 0; i < 4; i++) c[s_[i]-'0']++; int ans = 0; for(int i = 1; i <= 9; i++){ ans += i*pow10(c[i]); } return ans; }; double ans = 0.0; for(int i = 1; i <= 9; i++){ for(int j = 1; j <= 9; j++){ vector<ll> rem(10, k); for(int l = 0; l < 4; l++) rem[s[l]-'0']--; for(int l = 0; l < 4; l++) rem[t[l]-'0']--; rem[i]--; rem[j]--; bool ok = true; for(int l = 1; l <= 9; l++){ if(rem[l] < 0) ok = false; } if(ok){ rem[i]++; rem[j]++; double p; if(i == j){ p = (double)(tri(rem[i]))/(double)(tri(9*k-8)); }else{ p = (double)(rem[i]*rem[j])/(double)(tri(9*k-8)); } if(calc(s, i) > calc(t, j)) ans += p; // if(true) ans += p; } } } cout << ans << endl; }
#include <bits/stdc++.h> #define be(v) (v).begin(),(v).end() #define pb(q) push_back(q) #define rep(i, n) for(int i=0;i<n;i++) #define all(i, v) for(auto& i : v) typedef long long ll; using namespace std; const ll mod=1000000007, INF=(1LL<<60); #define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl; bool solve(vector<ll> v1, vector<ll> v2){ vector<ll> v(6, 0); for(ll i=1;i<=9;i++){ v[v1[i]] += i; v[v2[i]] -= i; } ll sum = 0; ll d = 1; rep(i, 6){ sum += v[i] * d; d *= 10; } if(sum > 0) return true; return false; } int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); ll k; cin >> k; ll cnt = k * 9 - 8; ll sum = (cnt - 1) * cnt; ll win = 0; string s, t; cin >> s >> t; vector<ll> num(10, k), n1(10, 0), n2(10, 0); rep(i, 4){ num[s[i] - '0']--; n1[s[i] - '0']++; num[t[i] - '0']--; n2[t[i] - '0']++; } for(ll i=1;i<=9;i++){ for(ll j=1;j<=9;j++){ if(num[i] == 0) continue; ll cnt1 = num[i]; num[i]--; if(num[j] == 0){ num[i]++; continue; } ll cnt2 = num[j]; n1[i]++; n2[j]++; if(solve(n1, n2)) win += cnt1 * cnt2; n1[i]--; n2[j]--; num[i]++; } } doublecout((double)win / (double)sum); return 0; }
#include <bits/stdc++.h> using namespace std; mt19937 rng(time(0)); long long randint(long long a, long long b){ uniform_int_distribution<long long> dist(a, b); return dist(rng); } const int swapXY[] = {0, 2, 1, 4, 3}; long long findScore(long long a, long long b){ long long A = a; long long B = b; long long score = 0; while(b){ score += a/b; long long c = b; long long d = a%b; a = c; b = d; } score += a; assert(a == __gcd(A, B)); return score; } vector<int> ans; void findScore2(long long a, long long b){ long long A = a; long long B = b; long long score = 0; while(a && b){ //printf("%lld %lld\n", a, b); while(a >= b && b > 0){ a -= b; score ++; ans.push_back(3); } while(b >= a && a > 0){ b -= a; score ++; ans.push_back(4); } } while(a){ //printf("%lld %lld\n", a, b); a --; score ++; ans.push_back(1); } while(b){ //printf("%lld %lld\n", a, b); b --; score ++; ans.push_back(2); } reverse(ans.begin(), ans.end()); assert(score == findScore(A, B)); } long double phi = (sqrt(5.0L)+1)/2; int main(){ long long N; scanf("%lld", &N); long long bestScore = 1LL << 60; long long bestI = rint(N*phi); while(findScore(N, bestI) > 130){ bestI ++; } findScore2(N, bestI); long long x = 0; long long y = 0; int K = (int)ans.size(); for(int i = 0; i < K; i ++){ if(ans[i] == 1){ x ++; }else if(ans[i] == 2){ y ++; }else if(ans[i] == 3){ x += y; }else if(ans[i] == 4){ y += x; }else{ assert(ans[i] <= 4 && ans[i] >= 1); } } //printf("x=%lld y=%lld\n", x, y); assert(x == N); printf("%d\n", K); for(int i: ans){ printf("%d\n", i); } return 0; }
#include <iostream> #include <algorithm> #include <map> #include <set> #include <queue> #include <stack> #include <numeric> #include <bitset> #include <cmath> static const int MOD = 1000000007; using ll = long long; using u32 = unsigned; using u64 = unsigned long long; using namespace std; template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208; template <class T, class U> vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); } template<class... Ts, class U> auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); } template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); } template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); } int main() { int n; cin >> n; for (int i = 0; i < n; ++i) { cout << (i*2+1)%n+1 << " " << (i*2)%n+1 << "\n"; } return 0; }
#include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; using namespace std; #define M 998244353 #define pi 3.14159265358979323846 #define ll long long #define lld long double // Pair #define pii pair<int, int> #define pll pair<ll, ll> // Vector #define vl vector<ll > #define vi vector<int> #define vpi vector<pii> #define vpl vector<pll> #define pb push_back #define mp make_pair // Search #define lb lower_bound #define ub upper_bound #define mina *min_element #define mama *max_element #define bsrch binary_search //////// #define F first #define S second #define cel(x,a) ((x + a - 1) / a) #define all(v) v.begin(), v.end() #define allrev(v) v.rbegin(), v.rend() #define lcm(m, n) ((m / __gcd(m, n))*n) #define deb(...) cerr << "(" << #__VA_ARGS__ << "):", dbg(__VA_ARGS__) #define ms(arr, v) memset(arr, v, sizeof(arr)) #define ps(x,y) fixed << setprecision(y) << x #define _X_ ios_base::sync_with_stdio(false); cin.tie(NULL) //pbds #define ordered tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> // Input / Output #define scn(str) scanf("%s", str) #define pri(str) printf("%s\n", str) const int N = 5e5 + 4; inline void dbg() { cerr << endl; } template <typename T, typename... V> inline void dbg(T t, V... v) {cerr << ' ' << t; dbg(v...);} /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ll binpow(ll a,ll b,ll p){ if(b==0)return 1; ll t=binpow(a,b/2,p); if(b%2)return (((a*t)%p)*t)%p; else return ((t*t)%p); } void solve() { int h,w; cin >> h >> w; string s[h]; for(int i = 0; i<h; i++)cin >> s[i]; bool val[h+w-1] = {0}; for(int i = 0; i<h; i++) { for(int j = 0; j<w; j++) { if(s[i][j]=='R') { val[i+j] = 1; } } } bool val2[h+w-1] = {0}; for(int i = 0; i<h; i++) { for(int j = 0; j<w; j++) { if(s[i][j]=='B') { val2[i+j] = 1; } } } int cnt = 0; for(int i = 0; i<h+w-1; i++) { if(val[i] && val2[i]) { cout << "0\n"; return; }else if(!val[i] && !val2[i])cnt++; } ll ans = binpow(2,cnt,M); cout << ans << "\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); // clock_t time_req = clock(); int t = 1; //cin>> t; while (t--) { solve(); } // time_req = clock() - time_req; // cout << (float)time_req / CLOCKS_PER_SEC; return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int, int> #define pll pair<ll, ll> #define vi vector<int> #define vll vector<ll> #define vpii vector<pair<int,int>> #define vpll vector<pair<ll,ll>> #define fr(i,k,n) for (int i = k; i < n; ++i) #define fri(i,k,n) for (int i = k; i >= n; --i) #define pb push_back #define mp make_pair #define all(arr) arr.begin(),arr.end() #define ff first #define ss second const double pi=3.1415926535897932384626433832795; const int inf=1e9; const ll inf2=1e18; const int mod=998244353; void boost(){ ios_base::sync_with_stdio(false); cin.tie(NULL); } void solve(){ int h,w; cin>>h>>w; string s[h]; fr(i,0,h){ cin>>s[i]; } vi adj[h-1+w]; fr(i,0,h){ fr(j,0,w){ if(s[i][j]=='.'){ continue; } else if(s[i][j]=='R'){ adj[i+j].pb(1); } else{ adj[i+j].pb(2); } } } ll ans=1; for(int i=0;i<=(h-1+w-1);i++){ int v=0; for(auto x: adj[i]){ v|=x; } // cout<<i<<endl; if(v==3){ cout<<0<<endl; return; } else if(v==0){ ans=(ans*2LL)%mod; } } cout<<ans<<endl; return; } int main() { boost(); int tc=1; //cin>>tc; while(tc--) solve(); return 0; }
// header {{{ // header {{{ using namespace std; #include <bits/stdc++.h> #define CPP_STR(x) CPP_STR_I(x) #define CPP_CAT(x, y) CPP_CAT_I(x, y) #define CPP_STR_I(args...) #args #define CPP_CAT_I(x, y) x##y #define ASSERT(expr...) assert((expr)) using i8 = int8_t; using u8 = uint8_t; using i16 = int16_t; using u16 = uint16_t; using i32 = int32_t; using u32 = uint32_t; using i64 = int64_t; using u64 = uint64_t; using f32 = float; using f64 = double; // }}} constexpr i64 INF = 1'010'000'000'000'000'017LL; constexpr i64 MOD = 1'000'000'007LL; constexpr f64 EPS = 1e-12; constexpr f64 PI = 3.14159265358979323846; #define M5 100007 #define M9 1000000000 // util {{{ #define FOR(i, start, end) for (i64 i = (start), CPP_CAT(i, xxxx_end) = (end); i < CPP_CAT(i, xxxx_end); ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(f, c, ...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ##__VA_ARGS__); })(c)) #define ll long long int #define VI vector<int> template <typename C> i64 SIZE(const C &c) { return static_cast<i64>(c.size()); } template <typename T, size_t N> i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); } template <typename T, typename U, typename Comp = less<>> bool chmax(T &xmax, const U &x, Comp comp = {}) { if (comp(xmax, x)) { xmax = x; return true; } return false; } template <typename T, typename U, typename Comp = less<>> bool chmin(T &xmin, const U &x, Comp comp = {}) { if (comp(x, xmin)) { xmin = x; return true; } return false; } // }}} // init {{{ struct ProconInit { static constexpr int IOS_PREC = 15; static constexpr bool AUTOFLUSH = false; ProconInit() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(IOS_PREC); if (AUTOFLUSH) cout << unitbuf; } } PROCON_INIT; // }}} //-------------------------------------------------------------------- bool isOK(int mid, double key) { } int binary_search(double key) { int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1 int right = 2000000000; /* どんな二分探索でもここの書き方を変えずにできる! */ while (right - left > 1) { int mid = left + (right - left) / 2; if (isOK(mid, key)) right = mid; else left = mid; } /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */ return right; } bool isKaibun(string st) { bool ans = true; int n = st.length(); REP(i, n / 2) { if (st[i] != st[n - i - 1]) { return false; } } return true; } int toInt(char a) { return a - '0'; } int gcd(int a, int b) { if (a % b == 0) { return (b); } else { return (gcd(b, a % b)); } } int lcm(int a, int b) { return a * b / gcd(a, b); } void solve() { int N; cin >> N; vector<ll> l(N), r(N); REP(i, N) { int t; cin >> t; ll a, b; cin >> a >> b; l[i] = a * 10LL; r[i] = b * 10LL; switch (t) { case 1: break; case 2: r[i]--; break; case 3: l[i]++; break; case 4: l[i]++; r[i]--; break; default: break; } } ll count = 0; REP(i, N - 1) { FOR(j, i + 1, N) { if (l[i] > r[i] || l[j] > r[j]) continue; if (l[i] <= r[j] && l[j] <= r[i]) { count++; } } } cout << count << endl; } signed main() { solve(); return 0; }
#include<bits/stdc++.h> #define maxn 1000005 #define inf 0x3f3f3f3f #define mod 1000000007 #define mst(a,x) memset(a,x,sizeof(a)) #define up(l,r,i) for(LL i=l;i<=r;i++) #define down(l,r,i) for(LL i=l;i>=r;i--) #define in(l,r,a) for(LL i=l;i<=r;i++)cin>>a[i] #define out(l,r,a) for(LL i=l;i<=r;i++)cout<<a[i]<<" " #define injz(n,m,a) for(LL i=1;i<=n;i++)for(LL j=1;j<=m;j++)cin>>a[i][j] #define hh cout<<endl #define pb push_back #define cf LL T;cin>>T;while(T--) #define cfout(x) cout<<(x?"YES":"NO")<<endl #define cs cout<<"qaq"<<endl typedef long long LL; typedef double db; using namespace std; int main() { ios::sync_with_stdio(false); //freopen("bwxnQAQin.txt","r",stdin); //freopen("bwxnQAQout.txt","w",stdout); LL r,x,y; cin>>r>>x>>y; double qaq=sqrt(x*x+y*y); LL qwq=ceil(qaq/r); if(qwq==1&&qwq*r!=qaq)qwq++; cout<<qwq; return 0; }
#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstring> #include <deque> #include <forward_list> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> PII; typedef pair<int, ll> PIL; typedef pair<ll, int> PLI; typedef pair<ll, ll> PLL; typedef bitset<16> BS; struct edge { int to, cost, id; }; const double PI = 3.14159265358979323846; const double PI2 = PI * 2.0; const double EPS = 1E-09; const ll MOD = 1E+09 + 7; // =998244353; const ll INFL = 1E18; const int INFI = 1E09; const int MAX_N = 1E+05; ll dx[4] = { -1, 1, 0, 0 }, dy[4] = { 0, 0, -1, 1 }; ll A, B, C; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> A >> B >> C; string ans = ""; if (A >= 0 && B >= 0) { } else if (A < 0 && B < 0) { if (C % 2 == 0) { A = abs(A); B = abs(B); } } else { if (C % 2 == 0) { A = abs(A); B = abs(B); } } if (A > B) ans = ">"; else if (A < B) ans = "<"; else ans = "="; /* for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { cout << "i = " << i << ", j = " << j << ", dp = " << dp[i][j] << "\n"; } } */ cout << ans << "\n"; return 0; }
#include<bits/stdc++.h> #define int long long #define ll long long #define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define fs first #define sd second #define rept(x,n) for(int i=x;i<n;i++) #define rrept(n,x) for(int i=n-1;i>=x;i--) #define all(v) v.begin(),v.end() #define mpit map<int,int>::iterator #define stit set<int,int>::iterator #define quit queue<int,int>::iterator #define maxt(a,b,c) max(a,max(b,c)) #define mint(a,b,c) min(a,min(b,c)) #define rsort(v) sort(v.rbegin(),v.rend()) #define pb push_back #define printarr(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" ";cout<<"\n"; #define printvec(v) for(int i = 0;i<v.size();i++)cout<<v[i]<<" ";cout<<"\n"; using namespace std; ll power(ll a,ll b){ll res = 1;while(b){if(b&1)res*=a;a*=a;b/=2;}return res;} ll powerwithmod(ll a,ll b,ll mod){ll res = 1;while(b){if(b&1)res*=a;res%=mod;a*=a;a%=mod;b/=2;}return res;} void sieve(vector<ll>&prime,ll n){ll candidate[n+1]={0};candidate[0]=1;candidate[1]=1;candidate[2]=0; for(ll i = 4;i<=n;i+=2)candidate[i]=1;for(ll i = 3;i*i<=n;i+=2){if(candidate[i]==0){ for(ll j = i*i;j<=n;j+=i){candidate[j] = 1;}}}for(ll i = 2;i<=n;i++){if(candidate[i]==0)prime.pb(i);}} /*-------------------------------------------------------------------------------------------------------*/ void solve() { ll a,b,c; cin>>a>>b>>c; if(a>=0&&b>=0) { if(a>b) cout<<">"; else if(a<b) cout<<"<"; else cout<<"="; return; } else if(a<0&&b<0) { if(a>b) cout<<">"; else if(a<b) cout<<"<"; else cout<<"="; return; } else if(a<0) { if(c&1) { cout<<"<"; } else { if(abs(a)>b) cout<<">"; else if(abs(a)<b) cout<<"<"; else cout<<"="; } return; } else if(b<0) { if(c&1) { cout<<">"; } else { if(abs(b)>a) cout<<"<"; else if(abs(b)<a) cout<<">"; else cout<<"="; } return; } } signed main() { speed; int t=1; //cin>>t; while(t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; long long f(int x) { if (x < 0) return 0LL; return 1LL * x * (x + 1) / 2 % MOD; } int main() { int t; scanf("%d", &t); while (t--) { int n, a, b; scanf("%d%d%d", &n, &a, &b); long long c = 1LL * (n - a + 1) * (n - b + 1) % MOD; printf("%lld\n", (4LL * f(n - a - b + 1) * c % MOD - 4LL * f(n - a - b + 1) * f(n - a - b + 1) % MOD + MOD) % MOD); } }
/* Clearink */ #include <cstdio> inline void wint ( int x ) { if ( 9 < x ) wint ( x / 10 ); putchar ( x % 10 ^ '0' ); } const int MAXN = 100; int N, K, M, f[MAXN + 1][MAXN * ( MAXN / 2 + 1 ) * ( MAXN >> 1 ) / 2 + 5]; inline void addeq ( int& a, const int b ) { ( a += b ) < M ? 0 : a -= M; } inline void initDP () { f[0][0] = 1; int sbound = K * ( N / 2 + 1 ) * ( N >> 1 ) >> 1; for ( int i = 0; i < N; ++ i ) { for ( int j = 0, cur; j <= sbound; ++ j ) { if ( !( cur = f[i][j] ) ) continue; for ( int k = 0, s = j; k <= K && s <= sbound; ++ k, s += i + 1 ) { addeq ( f[i + 1][s], cur ); } } } } inline int solve ( const int x ) { // k[x-1]+2k[x-2]+...+(x-1)k[1] = k[x+1]+2k[x+2]+...+(n-x)k[n]. int sbound = x - 1 < N - x ? x - 1 : N - x, ret = 0; sbound = K * sbound * ( sbound + 1 ) >> 1; for ( int s = 0; s <= sbound; ++ s ) { addeq ( ret, 1ll * f[x - 1][s] * f[N - x][s] % M ); } return ( ret * ( K + 1ll ) % M + M - 1 ) % M; } int main () { scanf ( "%d %d %d", &N, &K, &M ); initDP (); for ( int i = 1; i <= N; ++ i ) { wint ( solve ( i ) ); putchar ( '\n' ); } return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #pragma GCC optimize ("Ofast,unroll-loops") // #pragma GCC target ("avx,avx2,fma") using namespace std; using namespace __gnu_pbds; typedef int ll; typedef long double ld; typedef pair <ll, ll> pll; #ifdef SINA #define dbg(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f (const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...); } #define dbg2(x, j, n) cout<< #x << " : "; output((j), (n), x, 1); #else #define dbg(...) 0 #define dbg2(x, j, n) 0 #endif #define SZ(x) ((ll)((x).size())) #define File(s, t) freopen(s ".txt", "r", stdin); freopen(t ".txt", "w", stdout); #define input(j, n, a) for (int _i = (j); _i < (n)+(j); _i++) cin>> a[_i]; #define output(j, n, a, t) for (int _i = (j); _i < (n)+(j); _i++) cout<< a[_i] << (((t) && _i != (n)+(j)-1)? ' ' : '\n'); #define kill(x) return cout<< x << endl, 0 #define cl const ll #define fr first #define sc second #define lc (v << 1) #define rc (lc | 1) #define mid ((l + r) >> 1) #define All(x) (x).begin(), (x).end() cl inf = sizeof(ll) == 4 ? (1e9 + 10) : (3e18), mod = 1e9 + 7, MOD = 998244353; template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) { return out << '(' << a.first << ", " << a.second << ')'; } template <class A> ostream& operator << (ostream& out, const vector<A> &a) { if(!a.size())return cout<<"[]";cout<< '[' << a[0]; for (int i = 0; ++i < (int)(a.size());) cout<< ", " << a[i];cout<< ']'; } template <class T, typename _t = less <T> > using Tree = tree <T, null_type, _t, rb_tree_tag, tree_order_statistics_node_update>; cl N = 2e5 + 7; ll par [N], a [N], b [N], p [N]; vector <ll> comp [N]; ll root (ll v) { return par[v] = (par[v] == v ? v : root(par[v])); } inline void unite (ll v, ll u) { par[root(u)] = root(v); } int main () { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); iota(par, par + N, 0); ll n, ans = 0; cin>> n; input(1, n, a); input(1, n, b); input(1, n, p); for (ll i = 1; i <= n; i++) { if (i == p[i]) continue; if (b[p[i]] >= a[i]) kill(-1); unite(i, p[i]); } ans = n; for (ll i = 1; i <= n; i++) { if (par[i] == i) ans--; comp[root(i)].push_back(i); } cout<< ans << '\n'; for (ll i = 1; i <= n; i++) if (SZ(comp[i]) > 1) { sort(All(comp[i]), [&](ll x, ll y) { return a[x] > a[y]; }); ll hvy = comp[i][0]; while (p[hvy] ^ hvy) { cout<< hvy << ' ' << p[hvy] << '\n'; swap(p[hvy], p[p[hvy]]); } } cerr<< "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; return 0; } /* */
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i = 0; i < (n); ++i) #define repA(i, a, n) for(int i = a; i <= (n); ++i) #define repD(i, a, n) for(int i = a; i >= (n); --i) #define trav(a, x) for(auto& a : x) #define all(x) x.begin(), x.end() #define sz(x) (int)(x).size() #define fill(a) memset(a, 0, sizeof (a)) #define fst first #define snd second #define mp make_pair #define pb push_back typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; int main() { cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit); int n; cin >> n; vi a(n), b(n), p(n), h(n); bool possible = true; rep(i,n) cin >> a[i]; rep(i,n) cin >> b[i]; rep(i,n) cin >> p[i]; rep(i,n) p[i]--; rep(i,n) h[p[i]] = i; rep(i,n){ if(i != p[i] && a[i] <= b[p[i]]) possible = false; } if(possible == false){ cout << -1 << endl; return 0; } vector <pii> bb; rep(i,n) bb.pb(mp(b[i],i)); vector <pii> ans; sort(all(bb)); reverse(all(bb)); rep(i,n){ int bi = bb[i].snd; //bi is bag int bw = bb[i].fst; int hb = h[bi]; //hb is holder of bag if(bi == hb) continue; //Already holds bag ans.pb(mp(bi,h[bi])); swap(h[bi], h[p[bi]]); //Bags swap owners swap(p[bi], p[hb]); //Owners swap bags } cout << sz(ans) << endl; rep(i,sz(ans)){ cout << ans[i].fst + 1 << " " << ans[i].snd + 1 << '\n'; } return 0; }
#include <algorithm> #include <array> #include <cassert> #include <iostream> #include <vector> #include <string> using namespace std; void solve() { string x; cin >> x; int ans = x[0] - '0'; ans = x.size() * 10; cout << ans << endl; } int main() { int a, b, c, d; cin >> a >> b >> c >> d; vector<int> v; v.push_back(a); v.push_back(b); v.push_back(c); v.push_back(d); sort(v.begin(), v.end()); cout << v[0] << endl; }
#include <bits/stdc++.h> using namespace std; template <class A, class B> bool cmin(A& a, B b) { return a > b && (a = b, true); } template <class A, class B> bool cmax(A& a, B b) { return a < b && (a = b, true); } signed main() { cin.tie(nullptr)->sync_with_stdio(false); int N = 4; vector<int> A(N); for (int i = 0; i < N; i++) cin >> A.at(i); cout << *min_element(A.begin(), A.end()) << '\n'; }
#include<iostream> #include<cstdio> #include<map> #include<bitset> #include<algorithm> #include<cmath> #include<cstring> #include<queue> #include<stack> #include<ctime> using namespace std; #define M 500005 #define N 1000005 #define MP make_pair #define debug() cerr<<"Why So Serious?"<<endl typedef long long ll; typedef unsigned long long ull; typedef double db; template<class T>void Rd(T &x){ x=0;static char c; while(c=getchar(),c<48); do x=(x<<1)+(x<<3)+(c^48); while(c=getchar(),c>47); } int n; char str1[M],str2[M]; int tot1,tot2; int A[M],B[M]; int main(){ Rd(n); scanf("%s%s",str1,str2); for(int i=0;i<n;++i){ if(str1[i]=='1')A[++tot1]=i; if(str2[i]=='1')B[++tot2]=i; } if(tot1!=tot2){ puts("-1"); return 0; } int ans=0; for(int i=1;i<=tot1;i++)if(A[i]!=B[i]){ int j=i+1; bool f=A[i]<B[i]; for(;j<=tot1&&(A[j]<B[j])==f;++j); if(f){ ans+=abs(B[i]-A[i]); for(i++;i<j;++i){ ans+=B[i]-max(B[i-1]+1,A[i]); } i--; }else { j--; ans+=abs(B[j]-A[j]); for(int k=j-1;k>=i;--k){ ans+=min(A[k],B[k+1]-1)-B[k]; } i=j; } } printf("%d\n",ans); return 0; }
#include <bits/stdc++.h> //#include <atcoder/all> using namespace std; #define rep(i,n) for(ll i=0; i<n; i++) #define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++) #define rrep(i,n) for(ll i=n-1; i>=0; i--) #define fi first #define se second #define pcnt __builtin_popcountll typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int,int> Pii; typedef pair<ll,ll> Pll; typedef pair<ll,Pll> PlP; template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; } template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; } template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";} template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);} string zero_padding(int val, int nf){ ostringstream sout;sout << setfill('0') << setw(nf) << val; return sout.str();}; const ld eps = 1e-10; ull mo = 1000000007; ld PI=asin(1)*2; //using namespace atcoder; ll Scnt[2]; ll Tcnt[2]; string S,T; ll N; // ll dfs(ll id){ // } int main(){ cin >> N >> S >> T; rep(i,N){ Scnt[S[i] - '0']++; Tcnt[T[i] - '0']++; } set<ll> S_st, T_st; rep(i,N){ if(S[i] == '0'){ S_st.insert(i); } if(T[i] == '0'){ T_st.insert(i); } } if(!(Scnt[0] == Tcnt[0] && Scnt[1] == Tcnt[1])) drop(-1); ll ans = 0; rep(i,N){ if(S[i] == T[i]) continue; if(S[i] == '1'){ auto itr = S_st.lower_bound(i+1); ll next = *itr; S_st.erase(itr); ans++; S[next] = '1'; }else if(T[i] == '1'){ auto itr = T_st.lower_bound(i+1); ll next = *itr; T_st.erase(itr); ans++; T[next] = '1'; } } cout << ans << endl; }
#include<cstdio> #define F(i,l,r) for(int i=l,i##_end=r;i<i##_end;++i) using namespace std; template<typename T>void read(T &x) { bool neg=false; unsigned char c=getchar(); for(;(c^48)>9;c=getchar())if(c=='-')neg=true; for(x=0;(c^48)<10;c=getchar())x=(x<<3)+(x<<1)+(c^48); if(neg)x=-x; } int n; double ans; int main() { read(n); F(i,1,n)ans+=(double)n/i; printf("%0.9lf\n",ans); return 0; }
#include<bits/stdc++.h> using namespace std; // ---------- Debugger #define TRACE string to_string(string s) { return '"' + s + '"'; } string to_string(char c) { return '\'' + string(1, c) + '\''; } string to_string(char * s) { return to_string((string) s); } string to_string(const char * s) { return to_string((string) s); } string to_string(bool b) { return (b ? "true" : "false"); } template < typename A > string to_string(A v); template < typename A, typename B > string to_string(pair < A, B > p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template < typename C > struct rge { C b, e; }; template < typename C > rge<C> range(C i, C j) { return rge<C>{i, j}; } template < typename C > string to_string(rge<C> v) { bool first = true; string res = "["; for(auto it = v.b; it != v.e; it++) { if (!first) { res += ", "; } first = false; res += to_string(*it); } res += "]"; return res; } template < typename A > string to_string(A v) { return to_string(range(v.begin(), v.end())); } #ifdef TRACE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template < typename Head > void __f(const string names, Head arg1) { cerr << names << " : " << to_string(arg1) << endl; } template < typename Head, typename...Tail > void __f(const string names, Head arg1, Tail...args) { int b = 0, comma = names.size(); for(int i=0;i<names.size();i++) { if(names[i] == ',' && b == 0) { comma = i; break; } if(names[i] == '(' || names[i] == '{' || names[i] == '[' || names[i] == '<') b++; else if(names[i] == ')' || names[i] == '}' || names[i] == ']' || names[i] == '>') b--; } // size_t comma = names.find(', '); cerr << names.substr(0, comma) << " : " << to_string(arg1) << " | "; __f(names.substr(comma + 1), args...); } #else #define trace(...) #endif // ---------- Debugger #define LL long long #define FI ios_base::sync_with_stdio(false); cin.tie(NULL); #define PREC cout << setprecision(10) << fixed; const int MOD = (int)1e9 + 7; const int INF = (int)1e9 + 9; const int MX = (int)1e5 + 5; int main() { PREC; int n; cin >> n; double curr = 0; for(int x=n-1;x>=1;x--) { curr = n * 1.0/(n - x) + curr; } cout << curr << endl; return 0; }
#include <algorithm> #include <array> #include <cassert> #include <chrono> #include <cmath> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <vector> #include <stack> using namespace std; #define enviar {ios_base::sync_with_stdio(false);} #define aiuda {cin.tie(NULL); cout.tie(NULL);} #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) #define exacto(v) cout << setprecision(v) << fixed; #define ll int #define lld long double #define eb emplace_back #define em emplace #define ef emplace_front #define f first #define s second #define big greater<ll>() #define bpc(x) __builtin_popcount(x) #define bpc2(x) __builtin_clz(x) #define bpc3(x) __builtin_ctz(x) #define DIE(args...) {print(args); return;} #define lb lower_bound #define ub upper_bound #define ar(v) array<int,v> #define all(v) v.begin(), v.end() #define sz(x) (int)(x).size() #define meminf(v) memset(v, 0x3f , sizeof(v)) #define mem(v,x) memset(v , x , sizeof v); #define ai(a, n) for (int ele = 0; ele < n; ele++) cin >> a[ele]; #define ao(a, n) {for (int ele = 0; ele < (n); ele++) { if (ele) cout << " "; cout << a[ele]; } cout << '\n';} #define readgraph(list, edges) for (int i = 0; i < edges; i++) {int n1, n2; cin >> n1 >> n2; n1--; n2--; list[n1].eb(n2); list[n2].eb(n1);} template <typename T> struct combinator { T t_; combinator(T&& t) : t_(std::forward<T>(t)) {} template <typename... Args> auto operator () (Args&&... args) const { return t_(*this, std::forward<Args>(args)...); } }; template<class T> bool umin(T& a, const T& b) { return b<a?a=b, 1:0; } template<class T> bool umax(T& a, const T& b) { return a<b?a=b, 1:0; } string to_string(bool b) {return b?"true":"false"; } string to_string(char c) { return string(1, c);} string to_string(const char* s) { return string(s); } string to_string(string s) { return s; } template<class T> string to_string(T v) { bool f=1; string res; EACH(x, v) { if(!f) res+=' '; f=0; res+=to_string(x); } return res; } template<class A> void write(A x) { cout << to_string(x); } void print() { write("\n"); } template<class H, class... T> void print(const H& h, const T&... t) { write(h); if(sizeof...(t)) write(' '); print(t...); } typedef vector<int> vi; typedef vector<ll> vll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<pair<ll, ll>> vpll; typedef vector<pair<int, int>> vpii; typedef map<ll, ll> mll; typedef priority_queue<ll, std::vector<ll>, std::greater<ll>> priomin; typedef priority_queue<int> priomx; const ll mod = 998244353; //const ll mod = 1e9 + 7; const ll maxsize =2e5 + 5; //const ll inf = 0x3f3f3f3f3f3f3f3f ; // size, caracter //int a[maxsize]; void solve() { int n ; cin >> n; vector<double> a(n), b(n); FOR(i , n) { cin >> a[i]; //a[i]/=2; } sort(all(a)); partial_sum(all(a), b.begin()); double ans = 1e18; //ao(b , n); FOR(i, n) { double temp = b[n-1] - b[i] - (n - 1 - i)*a[i]; umin(ans , a[i]/2 + temp/n ); } cout << setprecision(6) << fixed; print(ans); } int main(){ enviar aiuda int tc = 1; //cin >> tc; while(tc--) solve(); return 0; }
// Parasparopagraho Jīvānām #pragma GCC optimize ("O3") #pragma GCC target ("sse4") #include <bits/stdc++.h> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> #include <ext/rope> using namespace __gnu_pbds ; using namespace __gnu_cxx ; using namespace std ; typedef long long ll ; typedef long double ldb ; typedef pair<int, int> pii ; typedef pair<int, ll> pil ; typedef pair<ll,ll> pll ; typedef vector<int> vi ; typedef vector<ll> vll ; typedef vector<pii> vpi ; typedef vector<pll> vpl ; typedef vector<bool> vb ; typedef vector<pair<ll,int> > vpli ; typedef vector<int,pil> edges ; typedef vector<vi> matrix ; typedef priority_queue<int> pqu ; template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update> ; #define rep(i,a,b) for (int i = (a); i <= (b); i++) #define per(i,b,a) for (int i = (b); i >= (a); i--) #define mp make_pair #define eb emplace_back #define pb push_back #define pob pop_back #define fi first #define se second #define ins insert #define bk back #define con continue #define lbd lower_bound #define ubd upper_bound #define sz(x) (int)x.size() #define all(x) begin(x), end(x) #define pr cout << // I don't like this but my laptop's 'O' key is not functioning well /* Careful when using long long __builtin_clz(int x) {} //: the number of zeros at the beginning of the number __builtin_ctz(int x) {} //: the number of zeros at the end of the number __builtin_popcount(int x) {} //: the number of ones in the number __builtin_parity(int x) {} //: the parity (even or odd) of the number of ones */ const int mod1 = 1000000007 ; const int mod2 = 998244353 ; const ll infl = 4e18 ; const int infi = 2e9 ; const int maxn = 1e6 + 5 ; const int block = 500 ; const int logn = 60 ; const int alpha = 27 ; const ldb pi = acos(-1) ; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) ; int rng_lr(int a, int b) { int ret ; ret = uniform_int_distribution<int>(a, b)(rng) ; return ret ; // For shuffling use shuffle(all, rng) ; } ll modpow(ll a, ll b, int MOD) { ll res = 1 ; while(b) { if(b&1) { res = res*a ; res %= MOD ; } a *= a ; a %= MOD ; b >>= 1 ; } return res%MOD ; } void upmin(int &a, int b) { if(a < b) { a = b ; } } void relax(int &a, int b) { if(a > b) { a = b ; } } ll add(ll a, ll b, int MOD) { a += b ; if(a >= MOD) { a -= MOD ; } return a ; } ll sub(ll a, ll b, int MOD) { a -= b ; if(a < 0) { a += MOD ; } return a ; } ll mul(ll a, ll b, int MOD) { b %= MOD ; a *= b ; a %= MOD ; return a ; } ll inverse(ll a, ll MOD) { a = modpow(a, MOD - 2, MOD) ; return a ; } ll lcm(ll a, ll b) { ll ret ; ll g = __gcd(a, b) ; ret = a/g ; ret = ret*b ; return ret ; } int icast(char ch) { return int(ch-'a') ; } void hyn(int a, int b) { if(a == b) cout << "YES\n" ; else cout << "NO\n" ; } void pyd(int a, int b) { if(a == b) cout << "First\n" ; else cout << "Second\n" ; } // Check constraints + overflows + types in typedef int main() { ios::sync_with_stdio(false) ; cin.tie(NULL) ; int n ; cin >> n ; vi a(n) ; rep(i,0,n-1) { cin >> a[i] ; } vector<ldb> b(n) ; rep(i,0,n-1) { b[i] = ((ldb)a[i])/((ldb)2) ; } sort(all(b)) ; ldb x = b[(n-1)/2] ; //pr x << "\n" ; ldb ev = ldb(0) ; rep(i,0,n-1) { ldb loss = x + (ldb)a[i] - min((ldb)a[i], ((ldb)2)*x) ; // pr loss << "\n" ; ldb contri = ((ldb)loss)/((ldb)n) ; ev = ev + contri ; } pr fixed << " " << setprecision(10) ; pr ev << "\n" ; return 0 ; }
#include<bits/stdc++.h> using namespace std; #define il inline #define ri register int #define ll long long #define ui unsigned int il ll read(){ bool f=true;ll x=0; register char ch=getchar(); while(ch<'0'||ch>'9') {if(ch=='-') f=false;ch=getchar();} while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=getchar(); if(f) return x; return ~(--x); } il int read(char *s){ int len=0; register char ch=getchar(); while(ch==' '||ch=='\n') ch=getchar(); while(ch!=' '&&ch!='\n'&&ch!=EOF) s[++len]=ch,ch=getchar(); return len; } il void write(const ll &x){if(x>9) write(x/10);putchar(x%10+'0');} il void print(const ll &x) {x<0?putchar('-'),write(~(x-1)):write(x);putchar('\n');} il ll max(const ll &a,const ll &b){return a>b?a:b;} il ll min(const ll &a,const ll &b){return a<b?a:b;} const ll mod=998244353; int n; const int MAXN=2e5+7; ll a[MAXN],ans,sum; int main(){ n=read(); for(ri i=1;i<=n;++i) a[i]=read(); sort(a+1,a+n+1); for(ri i=1;i<=n;++i){ ans=(ans+a[i]*sum)%mod; ans=(ans+a[i]*a[i])%mod; sum=(sum*2+a[i])%mod; } print(ans); return 0; }
// #define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; using ll = long long; // int64_t using ull = unsigned long long; using pii = pair<int,int>; using pll = pair<ll,ll>; #define REP(i,m,n) for(int i = m; i <= (n); ++i) #define rep(i,n) for(int i = 0; i < (n); ++i) #define rrep(i,n) for(int i = 1; i <= (n); ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) const int INF = 1e9+7; //10oku7 ll mod_pow(ll x , ll y , ll m){ if (y == 0) return 1; if (y == 1) return x % m; ll rep = mod_pow(x, y/2, m) * mod_pow(x, y/2, m); if (y % 2 == 1 ) rep *= (x % m); rep %= m; return rep; } ll circ(ll x , ll y){ ll res = mod_pow(x , y ,4); if (res == 0 ) res = 4; return res; } int main() { ll A,B,C; cin >> A >> B >> C; A %= 10; ll ans = mod_pow( A , circ(B,C) ,10); // cout << circ (B,C) << endl; // cout << mod_pow(A,B, 10) << endl; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define ls o<<1 #define rs o<<1|1 #define fi first #define se second typedef long long ll; typedef pair<int,int> pii; const int maxn=2e5+10; const int mod=1e9+7; const int inf=0x3f3f3f3f; const ll INF=0x3f3f3f3f3f3f3f3f; void solve(){ int a,b; scanf("%d%d",&a,&b); double ans=a/100.0*b; printf("%lf\n",ans); } int main(){ clock_t t1=clock(); #ifndef ONLINE_JUDGE freopen("in.in", "r", stdin); freopen("out.out","w",stdout); #endif // int T;scanf("%d",&T);while(T--) solve(); end: cerr<<"Time used "<<clock()-t1<<" ms"<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int a,b; cin >> a >> b; cout << (b / (100.0)) * a << endl; return 0; }
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; #pragma GCC optimize ("-O3") #define int long long #define ld long double #define endl "\n" #define rep(i,begin,end) for (__typeof(end) i=begin-(begin>end); i!=(end)-(begin>end); i+=1-2*(begin>end)) #define umap unordered_map #define pq priority_queue #define pb push_back #define mp make_pair #define fs first #define sec second #define lb lower_bound #define ub upper_bound #define mii map<int,int> #define pii pair<int,int> #define vc vector #define vi vc<int> #define vvi vc<vi> #define all(v) v.begin(),v.end() #define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower); #define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper); #define gcd(a,b) __gcd((a),(b)) #define lcm(a,b) ((a)*(b))/gcd((a),(b)) #define remax(a,b) a = max(a,b) #define remin(a,b) a = min(a,b) #define w(t) int t; cin>>t; rep(tc,0,t) #define clr(a,x) memset(a,x,sizeof a) #define chkbit(x,i) ((x)&(1LL<<(i))) #define setbit(x,i) ((x)|(1LL<<(i))) #define setbits(x) __builtin_popcountll(x) #define zerobits(x) __builtin_ctzll(x) #define ps(x,y) fixed<<setprecision(y)<<x #define print(a, n) rep(i,0,n) cout<<a[i]<<" "; cout<<endl; #define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n"; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; const int mod = 1e9+7; const int mod2 = 998244353; const int N = 2e6; const int inf = 1e18; const ld PI = 3.141592653589793; //===================================================== template<typename... T> void in(T&... args) {((cin>>args), ...);} template<typename... T> void out(T&&... args) {((cout<<args<<" "), ...);} template<typename... T> void outln(T&&... args) {((cout<<args<<" "), ...); cout<<endl;} int nxt(){int x;cin>>x;return x;} int add(int a,int b,int mod){int res=(a+b)%mod;return (res<0)?res+mod:res;} int mul(int a,int b,int mod){int res=(a*1LL*b)%mod;return (res<0)?res+mod:res;} int range(int x,int y,int z) {return (x >= y && x <= z);} struct customCompare { bool operator () (int x, int y) { return x>y; } }; //===================================================== int ModExp(int x, int y, int m){ int res = 1; while (y > 0) { if (y & 1) res = (res*x) % m; y = y>>1; x = (x*x) % m; } return res; } int calc(int n) { if (n <= 1) return 1; int x = 1, y = 1; for (int i = 2; i <= n; i++) { int tmp = (x+y)%mod; x = y; y = tmp; } return y; } void solve() { int n = nxt(); char aa, ab, ba, bb; cin >> aa >> ab >> ba >> bb; int ans; if (n <= 2) ans = 1; else if (ab == 'A' && aa == 'A') ans = 1; else if (ab == 'B' && bb == 'B') ans = 1; else if (ab == 'A' && aa == 'B' && ba == 'A') ans = calc(n-2); else if (ab == 'B' && bb == 'A' && ba == 'B') ans = calc(n-2); else ans = ModExp(2, n-3, mod); cout << ans << endl; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); solve(); return 0; }
#include<bits/stdc++.h> #define ll long long using namespace std; ll xorr[1200020]; ll a[300005]; int query(int at, int L, int R, int l, int r){ if(L>r || R<l)return 0; if(l<=L and r>=R)return xorr[at]; int mid = (L+R)/2; return query(at*2,L,mid,l,r)^query(at*2+1,mid+1,R,l,r); } void update(int at, int L, int R, int pos, ll u ){ if(L>pos || R<pos)return ; if(L==R){ xorr[at]^=u; return ; } int mid = (L+R)/2; update(at*2,L,mid,pos,u); update(at*2+1,mid+1,R,pos,u); xorr[at] = xorr[at*2]^xorr[at*2+1]; } ll build(int at , int L, int R){ if(L==R){ xorr[at]=a[L]; return xorr[at]; } int mid = (L+R)/2; ll u = build(at*2,L,mid); ll v = build(at*2+1,mid+1,R); xorr[at] = u^v; return xorr[at]; } int main(){ ios::sync_with_stdio(false); cin.tie(0); int n,q; cin>>n>>q; for(int i=1;i<=n;i++){ cin>>a[i]; } build(1,1,n); for(int i=0;i<q;i++){ int type ; cin>>type; if(type==1){ int x,y; cin>>x>>y; update(1,1,n,x,y); } else{ int L,R; cin>>L>>R; cout<<query(1,1,n,L,R)<<"\n"; } } }
using namespace std; #include<bits/stdc++.h> void testcases() { int n,time,pow; cin>>n>>time>>pow; int f=0; while(n>0) { int temp1,temp2; cin>>temp1>>temp2; if(temp1<time && temp2>pow) f=1; n-=1; } cout<<((f==1)?"Yes":"No")<<endl; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); /*int t; cin>>t; while(t--)*/ testcases(); }
#include <bits/stdc++.h> #include <math.h> using namespace std; using ll = long long; using vll = vector<ll>; using vvll = vector<vll>; using vpl = vector<pair<ll, ll>>; using pll = pair<ll, ll>; #define rep(i, k, n) for(ll i = k; i < n; i++) #define pb push_back #define mp make_pair int main(){ ll t; cin >> t; vll ans(0); rep(i, 0, t){ ll l, r; cin >> l >> r; if(r-2*l+2<=0 || r-2*l+1<=0){ ans.pb(0); continue; } ans.pb((r-2*l+2)*(r-2*l+1)/2); } rep(i, 0, ans.size()){ cout << ans[i] << endl; } }
//#pragma GCC optimize(2) #include<bits/stdc++.h> using namespace std; const int N=101000; const int inf=1e9+7; inline long long read(void) { char ch=getchar();long long sum=0;bool f=0; while((ch<'0'||ch>'9')&&ch!='-')ch=getchar(); if(ch=='-'){f=1;ch=getchar();} while(ch>='0'&&ch<='9'){sum=sum*10+ch-'0';ch=getchar();} if(f)sum=-sum;return sum; } int n; string st; int opt[N]; long long DP[N][2]; int main() { n=read(); for(int i=1;i<=n;i++) { cin>>st; if(st[0]=='O')opt[i]=1; else opt[i]=2; } DP[0][1]=DP[0][0]=1; for(int i=1;i<=n;i++){ if(opt[i]==1){ DP[i][0]+=DP[i-1][0]; DP[i][1]+=(DP[i-1][0]+DP[i-1][1]*2); } else { DP[i][0]+=DP[i-1][0]*2+DP[i-1][1]; DP[i][1]+=DP[i-1][1]; } } cout<<DP[n][1];return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ll n; cin >> n; string s; ll t = 1; ll f = 1; for(ll i = 0;i < n;i++){ cin >> s; if(s == "AND"){ f = f*2+t; } else { t = t*2+f; } } cout << t << endl; }
#include "bits/stdc++.h" using namespace std; #define REP(i, n) for(ll i = 0;i < n;i++) #define ll long long #define MOD 1000000007LL //#define MOD 998244353LL #define chmax(a,b) if (a<b)a=b; #define doublecout(a) cout<<setprecision(16)<<a<<endl; using vi = vector<ll>; // intの1次元の型に vi という別名をつける using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける using vvvi = vector<vvi>; // intの2次元の型に vvi という別名をつける const ll llMAX=9223372036854775807LL; const ll llMIN=-9223372036854775808LL; void myprint1D(vi &data) { REP(i,data.size()) cout<<data[i]<<" "; cout<<endl; } //配列を[y][x]で表示 void myprint2D_T(vvi &data) { REP(i,data.size()) myprint1D(data[i]); } //配列を[x][y]で表示 void myprint2D(vvi &data) { ll l1=data.size(); ll l2=data[0].size(); REP(j,l2){ REP(i,l1) cout<<data[i][j]<<" "; cout<<endl; } } //print(a,b...)って使い方 void print1(ll a){cout<<a<<endl;} void print2(ll a,ll b){cout<<a<<" "<<b<<endl;} void print3(ll a,ll b,ll c){cout<<a<<" "<<b<<" "<<c<<endl;} void print4(ll a,ll b,ll c,ll d){cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;} void print5(ll a,ll b,ll c,ll d,ll e){cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<endl;} ll n,x; int main(){ ll ans=llMAX; cin >> n >> x; vi a(n),b(n); REP(i,n) cin>>a[i]; for(ll maini=1;maini<=n;maini++){ vvi data(100, vi(maini,-1)); // N * M の2次元配列 N-1個つかって余りがMのやつを保存 for(ll iii=0;iii<n;iii++){ ll ta=a[iii]; for(ll i=iii-1;i>=0;i--){ for(ll j=0;j<maini;j++){ if (data[i][j]==-1)continue; chmax(data[i+1][(j+ta)%maini],data[i][j]+ta) } } chmax(data[0][ta%maini],ta) } ll ax=x%maini; ll syokiti=data[maini-1][ax]; if (syokiti==-1)continue; ans=min((x-syokiti)/maini,ans); } cout<<ans<<endl; return 0; } /* 10 22000 10 20 30 40 50 60 70 80 90 100 */
#include <bits/stdc++.h> using namespace std; int _ = (cout << fixed << setprecision(9), cin.tie(0), ios::sync_with_stdio(0)); using Int = long long; enum { ROW, COL }; int main() { int H, W; cin >> H >> W; vector<string> S(H); for (auto &s : S) cin >> s; vector<int> rows(H), cols(W); vector<vector<int>> rows_floor(H), cols_floor(W); for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (S[i][j] == '#') { rows_floor[i].push_back(j); cols_floor[j].push_back(i); } } } int nrow = H, ncol = W; auto rec = [&](auto&& rec, int type, int idx) -> void { if (type == ROW) { if (rows[idx]) return; rows[idx] = 1; nrow--; for (auto t : rows_floor[idx]) rec(rec, COL, t); } else { if (cols[idx]) return; cols[idx] = 1; ncol--; for (auto t : cols_floor[idx]) rec(rec, ROW, t); } }; rec(rec, ROW, 0); rec(rec, ROW, H - 1); rec(rec, COL, 0); rec(rec, COL, W - 1); int ans = 0; for (int i = 0; i < H; i++) { if (!rows[i] && !rows_floor[i].empty()) { ans++; rec(rec, ROW, i); } } for (int i = 0; i < W; i++) { if (!cols[i] && !cols_floor[i].empty()) { ans++; rec(rec, COL, i); } } ans += min(nrow, ncol); cout << ans << '\n'; return 0; }
#include<bits/stdc++.h> using namespace std; int in(){ int x; scanf("%d",&x); return x; } char janken(char c1,char c2){ if(c1>c2)swap(c1,c2); if(c1==c2)return c1; if(c1=='P' && c2=='R')return 'P'; if(c1=='P' && c2=='S')return 'S'; if(c1=='R' && c2=='S')return 'R'; } int main(){ int n=in(),k=in(); string s; cin>>s; vector<int>v; int p=1; for(int i=0;i<=k;i++){ v.push_back(p/n); p%=n; if(i<k)p*=2; } reverse(v.begin(),v.end()); while(v.size() && v.back()==0)v.pop_back(); int vs=v.size(); string amari; for(int i=0;i<p;i++)amari.push_back(s[i]); for(int i=0;i<vs-1;i++){ s+=s; if(v[i])amari=s+amari; string new_s,new_amari; for(int i=0;i<s.size()-1;i+=2)new_s.push_back(janken(s[i],s[i+1])); for(int i=0;i<(int)amari.size()-1;i+=2)new_amari.push_back(janken(amari[i],amari[i+1])); s=new_s; amari=new_amari; } if(vs)s=s+amari; else s=amari; int ss=s.size(); vector<char>ans(ss*2); for(int i=0;i<ss;i++)ans[ss+i]=s[i]; for(int i=ss-1;i;i--)ans[i]=janken(ans[i*2],ans[i*2+1]); cout<<ans[1]<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define pii pair<ll,ll> #define rep(i,st,en) for(ll i=st;i<en;i++) #define repdown(i,st,en) for(ll i=st;en<i;i--) #define vll vector<ll> #define vd vector<double> #define vb vector<bool> #define vii vector<pii> #define vp vector<pii> #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define eb emplace_back #define PI 3.14159265358979323846 #define ans(A) cout<<A<<endl; #define ANS(A) cout<<A; #define yes cout<<"Yes"<<endl; #define no cout<<"No"<<endl; #define resz(A,N) A.resize(N); #define vsortup(v) sort(all(v)) //1,2,3,4,5 #define vsortdown(v) sort(rall(v)) //5,4,3,2,1 vll enm_div(ll n); //約数リスト出力 int main() { ll T; cin >> T; vll cs; resz(cs,T); ll odc=0,evc=0; rep(i,0,T) cin >> cs[i]; // vll divlst = enm_div(cs[i]); // rep(j,0,divlst.size()){ // if (divlst[i]%2==0)//偶数 // evc++; // else // odc++; // } rep(i,0,T){ if (cs[i]%4==0){ ans("Even") } else{ if (cs[i]%2==0){ ans("Same"); } else{ ans("Odd") } } } return 0; } vll enm_div(ll n) { vll prms; for (ll i = 1; i*i <= n; i++) if (n%i==0){ prms.push_back(i); if (i != n/i) prms.push_back(n/i); } if (prms.size()==0) resz(prms,1); vsortup(prms); return prms; }
#include <bits/stdc++.h> #define DEBUG(C) cerr << #C << " = " << C << endl; using namespace std; const int MOD = 1e9 + 7; void solve() { const int MAX = 2e5 + 10; int N; long long W; cin >> N >> W; vector<long long> v(MAX); for (int i = 0; i < N; ++i) { int s, t; long long p; cin >> s >> t >> p; v[s] += p; v[t] -= p; } for (int i = 0; i < MAX - 1; ++i) { v[i + 1] += v[i]; } const auto ma = *max_element(begin(v), end(v)); puts(ma <= W ? "Yes" : "No"); } int main(void) { #ifndef ONLINE_JUDGE const auto in_stream = freopen("../in.txt", "r", stdin); if (in_stream == nullptr) { cerr << "ERROR!" << endl; return 1; } #endif solve(); #ifndef ONLINE_JUDGE fclose(in_stream); #endif }
#pragma GCC optimize("Ofast") #include <iostream> #include <stdio.h> #include <string> #include <vector> #include <algorithm> #include <cstdlib> #include <cmath> #include <iomanip> #include <cctype> #include <sstream> #include <stack> #include <deque> #include <queue> #include <list> #include <set> #include <map> #include <unordered_map> using namespace std; using ll = long long; using P = pair<ll, ll>; using Po = pair<double, double>; template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; #define REP(i,n) for(ll i=0;i<ll(n);i++) #define REPD(i,n) for(ll i=n-1;i>=0;i--) #define FOR(i,a,b) for(ll i=ll(a);i<=ll(b);i++) #define FORD(i,a,b) for(ll i=ll(a);i>=ll(b);i--) #define PB push_back #define MP make_pair #define SZ(x) ll(x.size()) #define ALL(x) x.begin(),x.end() #define NIL -1 #define INF 1ll<<63-1 //#define MOD 1000000007 #define PI 3.14159265358979323846 #define endl "\n" #define EPS 1e-9 #define YES cout << "YES" << endl #define NO cout << "NO" << endl #define Yes cout << "Yes" << endl #define No cout << "No" << endl template <class T, class U> bool chmin(T& t, const U& u) { if (t > u) { t = u; return true; } else return false; } template <class T, class U> bool chmax(T& t, const U& u) { if (t < u) { t = u; return true; } else return false; } bool YN(bool b) { if (b) { Yes; return true; } else { No; return false; } } ll modpow(ll a, ll n, ll mod) { ll res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } template <unsigned int MOD> struct ModInt { using uint = unsigned int; using ull = unsigned long long; using M = ModInt; uint v; ModInt(ll _v = 0) { set_norm(_v % MOD + MOD); } M& set_norm(uint _v) { //[0, MOD * 2)->[0, MOD) v = (_v < MOD) ? _v : _v - MOD; return *this; } explicit operator bool() const { return v != 0; } M operator+(const M& a) const { return M().set_norm(v + a.v); } M operator-(const M& a) const { return M().set_norm(v + MOD - a.v); } M operator*(const M& a) const { return M().set_norm(ull(v) * a.v % MOD); } M operator/(const M& a) const { return *this * a.inv(); } M& operator+=(const M& a) { return *this = *this + a; } M& operator-=(const M& a) { return *this = *this - a; } M& operator*=(const M& a) { return *this = *this * a; } M& operator/=(const M& a) { return *this = *this / a; } M operator-() const { return M() - *this; } M& operator++(int) { return *this = *this + 1; } M& operator--(int) { return *this = *this - 1; } M pow(ll n) const { if (n < 0) return inv().pow(-n); M x = *this, res = 1; while (n) { if (n & 1) res *= x; x *= x; n >>= 1; } return res; } M inv() const { ll a = v, b = MOD, p = 1, q = 0, t; while (b != 0) { t = a / b; swap(a -= t * b, b); swap(p -= t * q, q); } return M(p); } bool operator==(const M& a) const { return v == a.v; } bool operator!=(const M& a) const { return v != a.v; } friend ostream& operator<<(ostream& os, const M& a) { return os << a.v; } static uint get_mod() { return MOD; } }; using Mint = ModInt<998244353>; signed main() { cout << fixed << setprecision(15); ll n, w; cin >> n >> w; V<ll> a(200100,0); REP(i, n) { ll s, t, p; cin >> s >> t >> p; a[s] += p; a[t] -= p; } REP(i, 200010) { a[i+1] += a[i]; if (a[i] > w) { No; return 0; } } Yes; return 0; }
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL string to_string(string s) { return '"' + s + '"'; } string to_string(const char* s) { return to_string(string(s)); } string to_string(bool b) { return to_string(int(b)); } string to_string(vector<bool>::reference b) { return to_string(int(b)); } string to_string(char b) { return "'" + string(1, b) + "'"; } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A> string to_string(A v) { string res = "{"; for (const auto& x : v) res += (res == "{" ? "" : ", ") + to_string(x); return res + "}"; } void debug() { cerr << endl; } template <typename Head, typename... Tail> void debug(Head H, Tail... T) { cerr << " " << to_string(H); debug(T...); } #define db(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__) #else #define db(...) 42 #endif typedef long long ll; typedef long double ld; const int MOD = 1000000007; struct Mint { int val; Mint() { val = 0; } Mint(ll x) { val = (-MOD <= x && x < MOD) ? x : x % MOD; if (val < 0) val += MOD; } template <typename U> explicit operator U() const { return (U)val; } friend bool operator==(const Mint& a, const Mint& b) { return a.val == b.val; } friend bool operator!=(const Mint& a, const Mint& b) { return !(a == b); } friend bool operator<(const Mint& a, const Mint& b) { return a.val < b.val; } Mint& operator+=(const Mint& m) { if ((val += m.val) >= MOD) val -= MOD; return *this; } Mint& operator-=(const Mint& m) { if ((val -= m.val) < 0) val += MOD; return *this; } Mint& operator*=(const Mint& m) { val = (ll)val * m.val % MOD; return *this; } friend Mint modex(Mint a, ll p) { assert(p >= 0); Mint ans = 1; for (; p; p >>= 1, a *= a) if (p & 1) ans *= a; return ans; } Mint& operator/=(const Mint& m) { return *this *= modex(m, MOD - 2); } Mint& operator++() { return *this += 1; } Mint& operator--() { return *this -= 1; } Mint operator++(int) { Mint result(*this); *this += 1; return result; } Mint operator--(int) { Mint result(*this); *this -= 1; return result; } Mint operator-() const { return Mint(-val); } friend Mint operator+(Mint a, const Mint& b) { return a += b; } friend Mint operator-(Mint a, const Mint& b) { return a -= b; } friend Mint operator*(Mint a, const Mint& b) { return a *= b; } friend Mint operator/(Mint a, const Mint& b) { return a /= b; } friend ostream& operator<<(ostream& os, const Mint& x) { return os << x.val; } friend string to_string(const Mint& b) { return to_string(b.val); } }; int main() { int n; scanf("%d", &n); vector<int> A(n); for (int i = 0; i < n; ++i) scanf("%d", &A[i]); sort(A.begin(), A.end()); int pre = 0; Mint ans = 1; for (int i = 0; i < n; ++i) { ans *= A[i] - pre + 1; pre = A[i]; } printf("%d\n", ans.val); }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; int a[100010]; int main() { int n; ll m,ans; cin >> n; rep(i,n) cin >> a[i]; if (n==1){ cout << a[0]+1 << endl; return 0; } sort(a, a+n); //a[0:n] を値が小さい順にソート ans=a[0]+1; m=1000000007; rep(i,n-1){ ans*=(a[i+1]-a[i]+1); ans%=m; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define For(i,n) for(int i = 0; i < n; i++) #define For1(i,n) for(int i = 1; i < n; i++) #define Forn(i,n) for(int i = n-1; i >=0 ; i--) #define FOR(i,f,n) for(int i = f; i < n; i++) #define FORN(i,n,f) for(int i = n; i >= f; i--) #define Forit(it,v) for(auto it = v.begin(); it != v.end(); it++) #define pb push_back #define mp make_pair #define x first #define y second #define sz size() #define dbg(a) For(i,a.sz){cout<<a[i]<<' ';}cout<<'\n'; #define Sort(a) sort(a.begin(), a.end()); #define Rev(a) reverse(a.begin(), a.end()); typedef long long int ll; typedef pair<ll, ll> pl; typedef pair<int,int> pi; typedef vector<ll> vll; typedef vector<int> vi; typedef vector<pl> vpl; typedef vector<pi> vpi; typedef vector<vll> vvll; const int mod = 1e9+7; const int NF = 0x3f3f3f3f; const ll INF = 0x3f3f3f3f3f3f3f3f; ll gcd(ll a, ll b){ while( a!=0 and b!=0 ) { if( a >= b ) a = a%b; else if( b > a ) b = b%a; } if( a >= b ) return a; else return b; } //FastExpo ll fast_pow(ll base, ll p){ ll a =1; while(p>0){ if(p%2==0){ p /=2; base *=base; } else{ p --; a = a * 1LL * base; } a %= mod; base %=mod; } return a; } ll t,n,m,k,idx,ct1,ct0; void solve() { cin>>n; vll a(n,0); map<ll, ll> ct; ll tmp = 0, res = 0; // vll T; For(i,n){ cin>>a[i]; if(i%2){tmp+=a[i];} else{tmp -= a[i];} if(tmp == 0){res++;} ll tm = ct[tmp]; if(tm>=1 && i!=0){ res+=tm; } ct[tmp]++; } // dbg(T); cout<<res<<'\n'; } int main() { ios::sync_with_stdio(0); cin.tie(0); // cin >> t; // k = t; t = 1; while (t--) { // cout<<"Case #"<<k-t<<": "; solve(); } }
#include <bits/stdc++.h> using namespace std; // #define LOCAL // 提出時はコメントアウト #define DEBUG_ typedef long long ll; const double EPS = 1e-9; const ll INF = ((1LL<<62)-(1LL<<31)); typedef vector<ll> vecl; typedef pair<ll, ll> pairl; template<typename T> using uset = unordered_set<T>; template<typename T, typename U> using mapv = map<T,vector<U>>; template<typename T, typename U> using umap = unordered_map<T,U>; #define ALL(v) v.begin(), v.end() #define REP(i, x, n) for(int i = x; i < n; i++) #define rep(i, n) REP(i, 0, n) #define sz(x) (ll)x.size() ll llceil(ll a,ll b) { return (a+b-1)/b; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> vector<vector<T>> genarr(ll n, ll m, T init) { return vector<vector<T>>(n,vector<T>(m,init)); } ///// DEBUG #define DUMPOUT cerr #define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++) template<typename T>istream&operator>>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;} template<typename T,typename U>ostream&operator<<(ostream&os,pair<T,U>&pair_var){os<<"("<<pair_var.first<<", "<<pair_var.second<<")";return os;} template<typename T>ostream&operator<<(ostream&os,const vector<T>&vec){os<<"{";for(int i=0;i<vec.size();i++){os<<vec[i]<<(i+1==vec.size()?"":", ");} os<<"}";return os;} template<typename T,typename U>ostream&operator<<(ostream&os,map<T,U>&map_var){os<<"{";repi(itr,map_var){os<<*itr;itr++;if(itr!=map_var.end())os<<", ";itr--;} os<<"}";return os;} template<typename T>ostream&operator<<(ostream&os,set<T>&set_var){os<<"{";repi(itr,set_var){os<<*itr;itr++;if(itr!=set_var.end())os<<", ";itr--;} os<<"}";return os;} void dump_func(){DUMPOUT<<endl;} template<class Head,class...Tail>void dump_func(Head&&head,Tail&&...tail){DUMPOUT<<head;if(sizeof...(Tail)>0){DUMPOUT<<", ";} dump_func(std::move(tail)...);} #ifndef LOCAL #undef DEBUG_ #endif #ifdef DEBUG_ #define DEB #define dump(...) \ DUMPOUT << " " << string(#__VA_ARGS__) << ": " \ << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" \ << endl \ << " ", \ dump_func(__VA_ARGS__) #else #define DEB if (false) #define dump(...) #endif ////////// #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") int main() { #ifdef LOCAL ifstream in("../../Atcoder/input.txt"); cin.rdbuf(in.rdbuf()); #endif ll N; cin>>N; vector<pairl> A(N); vecl B(N), P(N); vecl holder(N); // holder[i]: 荷物iを持ってる人 rep(i,N) cin>>A[i].first, A[i].second = i; rep(i,N) cin>>B[i]; rep(i,N) cin>>P[i], holder[--P[i]] = i; // P[i]: 人iが持ってる荷物 sort(ALL(A)); rep(i,N) { auto [a,j] = A[i]; ll item = P[j]; if (item != j && a <= B[item]) { cout << -1 << endl; return 0; } } vector<pairl> ans; rep(i,N) { auto [a,ii] = A[i]; // 人: ii ll p = holder[ii]; // 荷物iiをもつ人: p if (ii == p) continue; swap(holder[ii], holder[P[ii]]); swap(P[ii],P[p]); ans.emplace_back(ii, p); } cout << sz(ans) << endl; rep(i,sz(ans)) { auto [x,y] = ans[i]; cout << ++x << " " << ++y << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll, ll> pii; #define f(i,a,b) for(ll i=a;i<b;i++) #define fo(i,a,b) for(ll i = a; i<=b;i+=1) #define rf(i,a,b) for(ll i=a;i>=b;i--) #define vll vector<ll> #define sz(a) ll(a.size()) #define all(v) v.begin(),v.end() #define pb push_back #define pf push_front #define MAXN 100010 #define MOD 1000000007 #define mod 998244353 #define deb(x) cout << '>' << #x << ':' << x << endl; #define debug(x) cout << '>' << #x << ':' << x << " "; #define nl '\n' #define INF 1000000000000000000 #define IO \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define int long long int void solve(){ int n, a, b; cin >> n >> a >> b; cout << n - a + b << nl; return ; } main() { IO; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int T = 1; // cin >> T; fo(c, 1, T){ solve(); // cout<<"Case #"<<c<<": "; } return 0; }
#include<bits/stdc++.h> using namespace std; int a[3]; signed main(){ cin>>a[0]>>a[1]>>a[2]; sort(a,a+3); cout<<a[2]+a[1]<<endl; return 0; }
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author aajisaka */ #include<bits/stdc++.h> using namespace std; 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 SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr) #define rep(i,n) for(int i=0; i<(int)(n); i++) #define all(v) v.begin(), v.end() 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 ull = unsigned long long; using P = pair<ll, ll>; constexpr long double PI = 3.14159265358979323846264338327950288L; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); class FCoprimePresent { public: void solve(istream& cin, ostream& cout) { SPEED; ll a, b; cin >> a >> b; vector<int> prime = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71}; int t = 1<<20; vector<ll> dp(t); dp[0] = 1; for(ll i=a; i<=b; i++) { int now = 0; rep(j, 20) { if (i%prime[j] == 0) { now += (1<<j); } } auto dp2 = dp; rep(j, t) { if ((j&now)==0) { dp2[j|now] += dp[j]; } } swap(dp, dp2); } ll ret = 0; rep(i, t) { ret += dp[i]; } cout << ret << endl; } }; signed main() { FCoprimePresent solver; std::istream& in(std::cin); std::ostream& out(std::cout); solver.solve(in, out); return 0; }
#include<iostream> using namespace std; int main() { int a, b; cin >> a >> b; cout << (a+b)/2 << " " << (a-b)/2 << endl; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int,int>; void solve() { int n; string s, t; cin >> n >> s >> t; queue<int> one; rep(i, n) { if (s[i] == '1') one.push(i); } ll ans = 0; // int だと桁が足りない // e.g. s = 0...01...1 (0が250000, 1が250000), t = 1...10...0 (1が250000, 0が250000) // のとき答えは 250000^2 > 2^31 rep(i, n) { if (s[i] == t[i]) continue; while (!one.empty() && i >= one.front()) { one.pop(); } if (!one.empty()) { int j = one.front(); one.pop(); ans += j - i; s[j] = '0'; } else { puts("-1"); return; } } cout << ans << endl; } int main() { solve(); return 0; }
#include <bits/stdc++.h> #define ll long long #define ve vector<ll> #define w(t) ll t; cin >> t; while(t--) using namespace std; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); int a, b, c; cin >> a >> b >> c; if (a == b) cout << c; else if (a == c) cout << b; else if (c == b) cout << a; else cout << 0; return 0; }
#include <bits/stdc++.h> using namespace std; using namespace std::chrono; #define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr) //:/ #define pb push_back #define mp make_pair #define nt _ll128 #define ld long double long double PI =3.14159265; using ll = long long; const ll modo=1e9+7; const ll ms=1e5+5; const ll inf=1e17; ll dis[100][100]; int main() { idfc; int n,k; cin>>n>>k; vector<int> vv; int i;int j; for(i=2;i<=n;i++)vv.pb(i); for(i=1;i<=n;i++) { for(j=1;j<=n;j++)cin>>dis[i][j]; } int ans=0; int tot=0; do{ // cout<<"sdsd"<<endl; ans=0; int pr=1; for(i=0;i<n-1;i++) { ans+=(dis[pr][vv[i]]); pr=vv[i]; } ans+=dis[pr][1]; if(ans==k)tot++; } while(next_permutation(vv.begin(),vv.end())); cout<<tot; return 0; }
//clear adj and visited vector declared globally after each test case //check for long long overflow //while adding and subs check if mod becomes -ve //while using an integer directly in a builtin function add ll //Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod; //Dont keep array name as size or any other key word //ctrl+end - to break infinite loop in sublime text #include <bits/stdc++.h> #include <algorithm> #include <cmath> using namespace std; #define Fio \ ios_base::sync_with_stdio(false); \ cin.tie(nullptr); \ cout.tie(nullptr) #define ll long long int #define fo(i, a, b) for (long long int i = a; i <= b; i++) #define w(t) \ int t; \ cin >> t; \ while (t--) #define all(v) v.begin(),v.end() #define vi vector<int> #define vl vector<long long int> #define vvi vector<vector<int>> #define vvl vector<vector<long long int>> #define mii map<int, int> #define umii unordered_map<int, int> #define mll map<ll,ll> #define umll unordered_map<ll,ll> #define newl cout<<"\n" #define pb push_back #define mp make_pair #define fi first #define se second const ll inf = 1e9+7; const ll mod = 1e9+7; #define MAX 300005 void call_priyanshu(){ Fio; #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt", "w", stdout); //freopen("error.txt","w",stderr); #endif } ll mini(ll a,ll b){ if(a>=b)return b; return a; } ll maxi(ll a,ll b){ if(a>=b)return a; return b; } bool cmp(pair<ll,string> a,pair<ll,string> b){ return a.fi>b.fi; } void solve(){ //write your code here ll n; cin>>n; vector<pair<ll,string>>A; fo(i,1,n){ string s; ll h; cin>>s>>h; A.pb(mp(h,s)); } sort(all(A),cmp); cout<<A[1].se; } int main(){ call_priyanshu(); // w(t){ solve(); // } return 0; }
#include <bits/stdc++.h> // #include "icld.cpp" using namespace std; using ll = long long int; using pii = pair<int,int>; using vi = vector<int>; using vll = vector<ll>; using vvi = vector<vector<int>>; using ss = string; const int dx[4] = {1,0,-1,0}; const int dy[4] = {0,1,0,-1}; //#define pi 3.14159265358979 #define ss string #define db double #define rep(i,s,n) for(int i=(s);i<(int)(n);i++) #define all(v) v.begin(),v.end() #define ci(x) cin >> (x) #define cii(x) int (x);cin >> (x) #define cci(x,y) int (x),(y);cin >> (x) >>(y) #define co(x) cout << (x) << endl int main(){ cci(h,w); vvi v(h+1,vi(w+1,0)); rep(i,0,h){ rep(j,0,w){ char c;ci(c); if(c=='.')v[i][j]=1; } } int ans=0; rep(i,0,h){ rep(j,0,w){ ans+=(v[i][j+1]&v[i][j])+(v[i+1][j]&v[i][j]); } } co(ans); }
#include <bits/stdc++.h> using namespace std; #define mp(a,b) make_pair(a,b) #define ff first #define setp(a) setprecision(a)<<fixed #define ss second #define fori(v) for(ll i=0; i<v; i++) #define forj(v) for(ll j=0; j<v; j++) #define fork(v) for(ll k=0; k<v; k++) #define forl(v) for(ll l=0; l<v; l++) #define fort(v) for(ll t=0; t<v; t++) #define forz(v) for(ll z=0; z<v; z++) #define forx(v) for(ll x=0; x<v; x++) #define fory(v) for(ll y=0; y<v; y++) #define ll long long #define double long double #define MAX 2000010 #define pb(a) push_back(a) const ll INF = 0x3f3f3f3f; const ll inf = INF; ll modulo = pow(10,9)+7; struct Segtree{ // !!! 1 based indexing !!! struct node{ ll l , r, val, tagval; bool tag; node(){} node(ll l, ll r) : l(l), r(r){} void integrate(){ val += tagval; } node operator+(node other){ node toret = node(l, other.r); toret.val = min(val, other.val); return toret; } void operator+=(node& other){ // merge 2 tag (existing tag, new tag) values // merge other's "tagval" to our "tagval" only !!!! otherwise need modification tagval += other.tagval; } void operator*=(node& other){ // merge node value to query value // merge other's "val" to our "val" only !!!! otherwise need modification val = min(val, other.val); } }; node* lazy = new node[MAX]; void init(ll num, ll l , ll r){ if(l==r){ lazy[num] = node ( l, r); lazy[num].val = (l + 1); // initialize values if needed return; } init((num<<1), l, (l+r)/2), init((num<<1)|1, (l+r)/2+1, r); lazy[num] = lazy[num<<1] + lazy[(num<<1)|1]; } void pull(ll num){ lazy[num] = lazy[num<<1] + lazy[(num<<1)|1]; } void push(ll num){ lazy[num].integrate(); lazy[num].tag = 0; if(lazy[num].l != lazy[num].r){ lazy[(num<<1)].tag = lazy[(num<<1)|1].tag = 1; lazy[(num<<1)] += lazy[num], lazy[(num<<1)|1]+=lazy[num]; } lazy[num].tagval = 0; } void upd(ll num, node& b){ if(lazy[num].tag) push(num); if(lazy[num].l > b.r || lazy[num].r < b.l) return; if(lazy[num].l >= b.l && lazy[num].r<=b.r){ lazy[num] += b; push(num); return; } upd(num<<1, b), upd((num<<1)|1, b); pull(num); } void que(ll num, node& b){ if(lazy[num].l > b.r || lazy[num].r < b.l) return ; if(lazy[num].tag) push(num); if(lazy[num].l >= b.l && lazy[num].r<=b.r){ b *= lazy[num]; return; } que(num<<1, b) , que((num<<1)|1, b); } ~Segtree(){ delete[] lazy; } }; bool J(pair<ll,ll>& a, pair<ll,ll>& b){ return a > b; } void deal(){ Segtree lz; ll n; cin>>n; lz.init(1, 0, n-1); vector<pair<ll,ll> > arr; fori(2*n){ ll ed; cin>>ed; arr.pb(mp(ed, i)); } sort(arr.begin(), arr.end(), J); ll s = 0; fori(2*n){ ll id = arr[i].ss; if(id >= n){ id = id - n ; } else{ id = n-1 - id; } Segtree::node que(id, n-1); que.val = inf; lz.que(1, que); if(que.val >= 1){ s+=arr[i].ff; Segtree::node upd(id, n-1); upd.tagval = -1; lz.upd(1, upd); } } cout<<s; } int main(){ cin.tie(0); ios_base::sync_with_stdio(0); deal(); }
#include<bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL); int n,x; string s; cin>>n>>x; cin.ignore(); getline(cin,s); for(int i=0;i<n;i++){ if(x==0){ if(s[i]=='o'){ x=x+1; } } else{ if(s[i]=='o'){ x=x+1; } else{ x=x-1; } } } cout<<x; return 0; }
#include <bits/stdc++.h> using namespace std; #define all(x) x.begin(), x.end() #define sz(x) (int) x.size() #define endl '\n' typedef long long ll; typedef unsigned long long ull; typedef pair <int, int> ii; typedef pair <int, ii> iii; int main(){ int n, x; string s; cin >> n >> x; cin >> s; for(auto i : s){ if(i == 'o') x++; else if(x) x--; } cout << x << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const double TIME_LIMIT = 1.8; const int N = 50; double PROB_REAL = 0.1; vector<int> di = {1, -1, 0, 0}; vector<int> dj = {0, 0, 1, -1}; vector<char> vc = {'D', 'U', 'R', 'L'}; map<char, pair<int, int>> mp; int si0, sj0, si1, sj1; vector<vector<ll>> t, p; ld final_score; //状態 struct STATE { // 既に訪れたかどうか vector<vector<int>> visited = vector<vector<int>>(N, vector<int>(N, 0)); // タイルの番号とそれに対応する点のベクター(要素は1か2) map<int, vector<pair<int, int>>> mp_tile; // 道のり deque<char> paths; }; // 状態の初期化 void init (STATE& state) { cin >> si0 >> sj0; t = vector<vector<ll>>(N, vector<ll>(N)); p = vector<vector<ll>>(N, vector<ll>(N)); for (int i=0;i<N;i++) { for (int j=0;j<N;j++) { cin >> t[i][j]; state.mp_tile[t[i][j]].push_back(make_pair(i, j)); } } for (int i=0;i<N;i++) { for (int j=0;j<N;j++) { cin >> p[i][j]; } } for (int i=0;i<4;i++) { mp[vc[i]] = make_pair(di[i], dj[i]); } int now_i = si0; int now_j = sj0; for (auto p : state.mp_tile[t[now_i][now_j]]) { state.visited[p.first][p.second] = 1; } double start_time = static_cast<double>(clock())/CLOCKS_PER_SEC; // 開始時刻 while (true) { // 時間の許す限り回す double now_time = static_cast<double>(clock())/CLOCKS_PER_SEC; // 現在時刻 double time_diff = now_time-start_time; if (time_diff > TIME_LIMIT) break; bool changed = false; int c = uniform_int_distribution<int>(0, 3)(rng); int next_i = now_i+di[c]; int next_j = now_j+dj[c]; if (0 <= next_i && next_i < N && 0 <= next_j && next_j < N) { if (state.visited[next_i][next_j] == 0) { changed = true; state.paths.push_back(vc[c]); for (auto p : state.mp_tile[t[next_i][next_j]]) { state.visited[p.first][p.second] = 1; } now_i = next_i; now_j = next_j; } } if (!changed) { double rand_real = uniform_real_distribution<double>(0.0, 1.0)(rng); if (!state.paths.empty() && rand_real < PROB_REAL) { char rem_c = state.paths.back(); state.paths.pop_back(); for (auto p : state.mp_tile[t[now_i][now_j]]) { state.visited[p.first][p.second] = 0; } now_i -= mp[rem_c].first; now_j -= mp[rem_c].second; } } } } // 状態遷移 void modify (STATE& state) { } // 状態のスコア計算 ld calc_score (STATE& state) { } // 山登り法 void mountain() { STATE state; init(state); while (!state.paths.empty()) { cout << state.paths.front(); state.paths.pop_front(); } cout << "\n"; } int main() { ios::sync_with_stdio(0); cin.tie(0); mountain(); return 0; }
#include <bits/stdc++.h> //#include <atcoder/all> using namespace std; //using namespace atcoder; using ll=int; using ld=long double; using pll=pair<ll, ll>; //using mint = modint1000000007; #define rep(i,n) for (ll i=0; i<n; ++i) #define all(c) begin(c),end(c) #define PI acos(-1) #define oo 2e18 template<typename T1, typename T2> bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;} template<typename T1, typename T2> bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;} //priority_queue<ll, vector<ll>, greater<ll>> Q; /* 01234でタイルの方向管理? */ #define TIMEOVER_M 25000 #define TIMEOVER 1950000 ll T[50][50]; bool B[50][50]; ll P[50][50]; ll D[50][50]; char *ans; char *W; ll score=0; ll high=0; ll dx[]={0, 1, 0, -1}; ll dy[]={-1, 0, 1, 0}; char dc[]={'U', 'R', 'D', 'L'}; bool all_fin; bool fin; clock_t start; clock_t start_m; ll loop; void steped(ll y, ll x, bool b){ ll d=D[y][x]; if (d){ --d; ll ny=y+dy[d]; ll nx=x+dx[d]; B[ny][nx]=b; } B[y][x] = b; } // 行き止まりになったら、その時点でのstringを出力 void dfs(ll y, ll x, ll c){// {y, x, 歩数} bool used[4]={}; rep(i, 4){ clock_t now = clock(); if(now-start_m>TIMEOVER_M) fin=true; if(now-start>TIMEOVER) all_fin=true; ll r=now%4; while(used[r]) (r+=1)%=4; used[r]=true; ll ny=y+dy[r]; ll nx=x+dx[r]; // cout << "time:" << now-start << endl; if(ny<0 || nx<0 || ny>49 || nx>49 || B[ny][nx] || fin || all_fin){ if(chmax(high, score)){ if(ans) free(ans); ans=strdup(W); } } else{ //反映 score+=P[ny][nx]; W[c]=dc[r]; steped(ny, nx, true); dfs(ny, nx, c+1); //復元 score-=P[ny][nx]; W[c]='\0'; steped(ny, nx, false); } } } int main(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); W=(char*)calloc(2000, 1); start = clock(); ll si, sj; cin >> si >> sj; rep(i, 50) rep(j, 50) cin >> T[i][j]; rep(i, 50) rep(j, 50) cin >> P[i][j]; // タイルの方向D rep(i, 50) rep(j, 50){ rep(k, 4){ ll ny=i+dy[k]; ll nx=j+dx[k]; if(ny<0 || nx<0 || ny>49 || nx>49) continue; if(T[i][j]==T[ny][nx]) D[i][j]=k+1; } } while(!all_fin){ loop++; fin=false; start_m = clock(); score = P[si][sj]; chmax(high, score); rep(y, 50) rep(x, 50) B[y][x]=false; rep(i, 2000) W[i]='\0'; steped(si, sj, true); dfs(si, sj, 0); } // cout << high << " " << loop << endl; printf("%s\n", ans); }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; struct fast_ios { fast_ios(){ cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); }; } fast_ios_; const int INF = (int)1e9; const ll INFL = (ll)1e18; const int MOD = 1e9 + 7; const double EPS = 1e-10; int dx[]={0, 0, -1, 1}; int dy[]={1, -1, 0, 0}; 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; } long double solve(long double x1,long double y1,long double x2,long double y2) { long double ans; ans = sqrt(pow(x1, 2) - 2 * x1 * x2 + pow(x2, 2) + (pow(y1, 2) - 2 * y1 * y2 + pow(y2, 2))); return ans; } int main() { long double r, x, y, a,ans; int b; cin >> r >> x >> y; a = solve(0, 0, x, y); if (a == r) cout << 1 << endl; else if (a <= r + r) cout << 2 << endl; else { ans = (a / r); b = ceil(ans); cout << b << endl; } return 0; }
#include<bits/stdc++.h> #include<stdlib.h> #include<algorithm> #include<cmath> #include<map> #include<set> #include<deque> #include<vector> #include<string> #include<cstring> using namespace std; #define FAST ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); #define ll long long int main(){ long double r,x,y; cin>>r>>x>>y; long double m=x*x+y*y; long double x1=m/2; long double x0; do{ x0=x1; x1=(x0+m/x0)/2; }while(fabs(x0-x1)>=0.000000001); long double k=x1/r; x1=ceil(k); if(k<1) x1++; cout<<x1<<endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pii = pair<int,int>; using pll = pair<ll,ll>; using pld = pair<ld,ld>; using vi = vector<int>; using vll = vector<ll>; using vld = vector<ld>; #define rep(j, m) for (int j = 0; j < (int)(m); j++) #define rep2(i, l, n) for (int i = l; i < (int)(n); i++) #define all(v) v.begin(), v.end() const ld PI=3.1415926535897932; int main() { ll N,K; cin >> N >> K; K = abs(K); ll x = 2 + K,y = 2; ll ans = 0; rep(i,2*N - 1 - K) { ll a,b; if (x <= N) {a = x - 1;} else {a = 2*N + 1 - x;} if (y <= N) {b = y - 1;} else {b = 2*N + 1 - y;} ans += a*b; x++; y++; } cout << ans << endl; }
#include <bitset> #include <cassert> #include <iostream> #include <iomanip> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <unordered_map> #include <unordered_set> #include <valarray> // alias, using declaration using llint = long long; using ldouble = long double; template <class T = llint> using vector = std::vector<T>; template <class T = llint> using deque = std::deque<T>; template <class T = llint> using list = std::list<T>; template <class T = llint, class U = llint> using map = std::map<T, U>; template <class T = llint, class U = llint> using mmap = std::multimap<T, U>; template <class T = llint> using set = std::set<T>; template <class T = llint> using mset = std::multiset<T>; template <class T = llint, class U = llint> using umap = std::unordered_map<T, U>; template <class T = llint, class U = llint> using ummap = std::unordered_multimap<T, U>; template <class T = llint> using uset = std::unordered_set<T>; template <class T = llint> using umset = std::unordered_multiset<T>; template <class T = llint, class U = T> using pair = std::pair<T, U>; template <class T = llint> using varray = std::valarray<T>; template <class T = llint, class... U> using pqueue = std::priority_queue<T, U...>; using std::array; using std::bitset; using std::string; using std::tuple; // constant constexpr llint INF = 0x3FFFFFFFFFFFFFFF; constexpr llint INVALID = 0x8000000000000000; namespace io { // in template <class... T, size_t... S> auto in(std::index_sequence<S...>) {tuple<T...> t; (..., (std::cin >> std::get<S>(t))); return t;} template <class... T, size_t... S> auto in(std::index_sequence<S...>, size_t n) {tuple<vector<T>...> t{vector<T>(n)...}; for (size_t i = 0; i < n; i++) (..., (std::cin >> std::get<S>(t)[i])); return t;} template <size_t N, class T = llint, class... U> auto in() {static_assert(N >= 1); if constexpr (N > 1) return in<N - 1, T, T, U...>(); else return in<T, U...>(std::index_sequence_for<T, U...>());} template <size_t N, class T = llint, class... U> auto in(size_t n) {static_assert(N >= 1); if constexpr (N > 1) return in<N - 1, T, T, U...>(n); else return in<T, U...>(std::index_sequence_for<T, U...>(), n);} template <size_t N, class T = llint> auto in(size_t n, size_t m) {static_assert(N == 1); vector<vector<T>> v(n, vector<T>(m)); for (auto&& vi : v) for (auto&& vij : vi) std::cin >> vij; return std::make_tuple(v);} // out template <class T, class... U> void out(const T& a, const U&... b) {std::cout << a << (sizeof...(b) ? " " : "\n"); if constexpr (sizeof...(b)) out(b...);} template <class T, class U = const char*> void out(const vector<T>& a, U d = " ") {for (auto&& b : a) std::cout << b << (&b != &a.back() ? d : "\n");} } int main() { // input auto [t, N] = io::in<2>(); // solve auto tax = [&](llint A) { return (100 + t) * A / 100; }; llint l = 0, h = 100000000000000000; while (h - l > 1) { llint m = (h + l) / 2; (tax(m) - m < N ? l : h) = m; } llint result = tax(l) + N - (tax(l) - l); // output io::out(result); }
/** * Dont raise your voice, improve your argument. * --Desmond Tutu */ #include <bits/stdc++.h> using namespace std; const bool ready = [](){ ios_base::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(12); return true; }(); using ld=long double; const ld PI = acos(-1); using ll= long long; #define int ll #define all(v) (v).begin(), (v).end() #define fori(n) for(int i=0; i<int(n); i++) #define cini(i) int i; cin>>i; #define cins(s) string s; cin>>s; #define cind(d) ld d; cin>>d; #define cinai(a,n) vi a(n); fori(n) { cin>>a[i]; } #define cinas(s,n) vs s(n); fori(n) { cin>>s[i]; } #define cinad(a,n) vd a(n); fori(n) { cin>>a[i]; } using pii= pair<int, int>; using pdd= pair<ld, ld>; using vd= vector<ld>; using vb= vector<bool>; using vi= vector<int>; using vvi= vector<vi>; using vs= vector<string>; #define endl "\n" /* We can buy the n+1 and split it to 1 and n * Then there is 1 to n avail and * 2 to n-1 needed. * Buy the n and split into 2 and n-2. * Buy the n-1 * Avail 1..n-2 * Needed 3..n-3 * Buy the n-2 ans split into 3 and n-5... * * So we can buy one for two until * i + sum(1..i)>n **/ void solve() { cini(n); int cnt=0; int sum=0; int ans=n; for(int i=1; ; i++) { sum+=i; if(n+1-sum>i) ans--; else break; } cout<<ans<<endl; } signed main() { solve(); } // FIRST THINK, THEN CODE // DO NOT JUMP BETWEEN PROBLEMS
#include <bits/stdc++.h> using namespace std; using ll = long long; const int MAX_N = 101; int n; ll x, a[MAX_N]; ll dp[MAX_N][MAX_N][MAX_N]; ll go(int k) { memset(dp,-1,sizeof(dp)); dp[0][0][0]=0; for(int i=0;i<n;++i)for(int j=0;j<=i;++j)for(int m=0;m<k;++m)if(dp[i][j][m]!=-1){ dp[i+1][j][m]=max(dp[i+1][j][m], dp[i][j][m]); if(j+1<=k)dp[i+1][j+1][(m+a[i])%k]=max(dp[i+1][j+1][(m+a[i])%k], dp[i][j][m]+a[i]); } return dp[n][k][x%k]; } void solve() { ll ans = 2e18; for(int k=1;k<=n;++k){ ll res=go(k); if(res != -1) ans=min(ans, (x-res)/k); } cout<<ans<<'\n'; } int main() { cin >> n >> x; for(int i=0;i<n;++i)cin>>a[i]; solve(); return 0; }
#include <iostream> #include <algorithm> #include <vector> #include <string> #include <utility> #include <set> #include <map> #include <cmath> #include <queue> #include <cstdio> #include <limits> #define rep(i,n) for(int i = 0; i < n; ++i) #define rep1(i,n) for(int i = 1; i <= n; ++i) using namespace std; template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; } template<class T> inline int sz(T &a) { return a.size(); } using ll = long long; using ld = long double; using pi = pair<int,int>; using pl = pair<ll,ll>; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; const int inf = numeric_limits<int>::max(); const ll infll = numeric_limits<ll>::max(); int main() { int n; cin >> n; vi x(n),y(n); rep(i,n) cin >> x[i] >> y[i]; int res = 0; rep(i,n) { rep(j,n) { if(i >= j) continue; int dx = abs(x[i] - x[j]), dy = abs(y[i] - y[j]); if(dy <= dx) res++; } } cout << res << "\n"; return 0; }
#include <bits/stdc++.h> #define int long long using namespace std; using vec_int = vector<int>; using P = pair<int,int>; using T = tuple<int,int,int>; using ll = long long; #define rep(i, n) for(int i = 0; i < (int)(n); i++) signed main() { int A, B; cin>>A>>B; vec_int primes = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71}; int diff = B-A+1; vector<vec_int> DP(diff+1, vec_int((1<<20), 0)); DP.at(0).at(0) = 1; for(int i=0;i<diff;i++){ int num = A+i; int state = 0; for(int j=0;j<20;j++){ if(num%primes.at(j)==0)state+=(1<<j); } for(int j=0;j<(1<<20);j++){ DP.at(i+1).at(j) += DP.at(i).at(j); if((j&state)==0){ DP.at(i+1).at(j+state) += DP.at(i).at(j); } } } int result = 0; for(int j=0;j<(1<<20);j++){ result += DP.at(diff).at(j); } cout<<result<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; long long INF = 1LL<<60; using ll = long long; using vll = vector<ll>; using mll = map<ll, ll>; #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,a,b) for(int i=a;i>=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } int main(){ ll N2; cin >> N2; string S, S0, S1; cin >> S; S0 = S.substr(0, N2); S1 = S.substr(N2, N2*2); ll Q; cin >> Q; rep(q, 0, Q){ ll T; cin >> T; ll A, B; cin >> A >> B; if(T == 1){ A--; B--; if(A < N2 && B < N2) swap(S0.at(A), S0.at(B)); else if(A < N2) swap(S0.at(A), S1.at(B - N2)); else if(B < N2) swap(S1.at(A - N2), S0.at(B)); else swap(S1.at(A - N2), S1.at(B - N2)); } else if(T == 2){ swap(S0, S1); } } cout << S0 << S1 << endl; return 0; }
#include <bits/stdc++.h> #include <cassert> #define rep(i, N) for (int i = 0; i < (N); ++i) #define rep2(i, a, b) for (ll i = a; i <= b; ++i) #define rep3(i, a, b) for (ll i = a; i >= b; --i) #define pb push_back #define eb emplace_back #define fi first #define se second #define all(c) begin(c), end(c) #define ok() puts(ok ? "Yes" : "No"); template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } using namespace std; using ll = long long; using vi = vector<int>; using vll = vector<ll>; using ii = pair<int, int>; using vvi = vector<vi>; using vii = vector<ii>; using gt = greater<int>; using minq = priority_queue<int, vector<int>, gt>; using P = pair<ll, ll>; template <class T> void takeUnique(vector<T> &v) { auto last = std::unique(v.begin(), v.end()); v.erase(last, v.end()); } const ll LINF = 1e18L + 1; const int INF = 1e9 + 1; int dx[] = {0, 1, 0, -1}; int dy[] = {1, 0, -1, 0}; int dxx[] = {0, 1, 1, 1, 0, -1, -1, -1}; int dyy[] = {1, 1, 0, -1, -1, -1, 0, 1}; // clang++ -std=c++11 -stdlib=libc++ int a[5]; int main() { int ans = INF; rep(i, 4) { int b; cin >> b; chmin(ans, b); } cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define vi vector<int> #define mod 1e9+7 #define ff first #define ss second #define ins insert #define endl "\n" #define pie_op ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define tc int t;cin>>t;while(t--) #define pb push_back #define input(n) int arr[n];for(int i1=0;i1<n;i1++)cin>>arr[i1] int main() { pie_op; ll n, ans = INT_MAX; cin >> n; for(int i = 0; i <= 60; i++){ ll b = i; ll a = n / (1LL << b); ll c = n - a * (1LL << b); ans = min(ans, a + b + c); } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; using llong = long long; using ldbl = long double; using lpair = pair<llong, llong>; #define ALL(x) x.begin(), x.end() constexpr llong mod = 1e9+7; constexpr llong inf = mod * mod; int main() { llong N; cin >> N; llong ans = inf; for (llong b = 0; b <= 60; b++) { llong a = N / (1ll << b); llong c = N % (1ll << b); ans = min(ans, a + b + c); } cout << ans << endl; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vi; typedef pair<ll,ll> pi; typedef vector<pi> vp; typedef set<ll> si; typedef map<string, ll> msi; #define REP(i,a,b) \ for(ll i=ll(a);i<=ll(b);i++) #define DEP(i,a,b) \ for(ll i=ll(a);i>=ll(b);i--) #define TR(c, it) \ for (auto it = (c).begin(); it != (c).end(); it++) #define mp make_pair #define pb push_back #define F first #define S second ll mod = 1e9+7; vector<ll> c(100001); vector<ll> adj[100001]; vector<bool> visited(100001,false); vector<ll> color(100001,0); vector<ll> ans; void dfs(ll v){ visited[v]=true; if(color[c[v]]==0)ans.push_back(v); color[c[v]]++; for(auto x:adj[v]){ if(visited[x]==false){ dfs(x); } } color[c[v]]--; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int T; T=1; while(T--) { ll n,i,j,k,l,m; cin>>n; REP(i,1,n)cin>>c[i]; REP(i,1,n-1){ cin>>j>>k; adj[j].pb(k); adj[k].pb(j); } dfs(1); sort(ans.begin(),ans.end()); for(auto x: ans)cout<<x<<endl; } return 0; }
#include<bits/stdc++.h> using namespace std; #define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) #define mod 1000000007 #define endl "\n" #define test ll txtc; cin>>txtc; while(txtc--) typedef long long int ll; typedef long double ld; int main() { FIO; //test { string s; cin>>s; ll n=(ll)s.length(); vector<vector<ll>>dp(n,vector<ll>(26,0)); dp[0][s[0]-'a']++; for(ll i=1;i<n;i++){ dp[i][s[i]-'a']++; for(ll j=0;j<26;j++){ dp[i][j]+=dp[i-1][j]; } } ll ans=0,last=n,op=-1; for(ll i=n-2;i>=1;i--){ ll ch=s[i]-'a'; if(s[i]==s[i-1]){ if(op!=ch){ ans+=(n-last); } //cout<<ans<<endl; ans-=(dp[last-1][ch]-dp[i][ch]); //cout<<ans<<endl; ans+=(last-i-1); //cout<<ans<<endl; op=ch; last=i; } } cout<<ans<<endl; } return 0; }
#include <iostream> #include <vector> #include <queue> #include <set> #include <map> #include <algorithm> #include <cstring> #define fi first #define se second #define mp make_pair #define all(x) x.begin(), x.end() #define For(it, x, y) for(int it = x; it < y; it ++) #define ios ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0) #define bug(str, x) cerr << "# " << str << " : " << x << '\n' #define here(x) cerr << "here " << x << '\n' using namespace std; typedef long long ll; typedef pair<int, int> pii; const int maxn = 2e5 + 10; const int maxa = 2e5; const int inf = 1e9; int a[maxn]; bool visited[maxn]; vector<int> G[maxn]; void dfs(int v){ visited[v] = true; for(int u : G[v]){ if(!visited[u]){ dfs(u); } } } int main(){ ios; int n; cin >> n; For(i, 0, n){ cin >> a[i]; } For(i, 0, n / 2){ G[a[i]].push_back(a[n - 1 - i]); G[a[n - 1 - i]].push_back(a[i]); } int cnt = 0; For(i, 1, maxa + 1){ if(!visited[i]){ dfs(i); cnt ++; } } cout << maxa - cnt; }
#include <bits/stdc++.h> using namespace std; #define int long long #define sz(x) (int)(x.size()) #define all(x) (x).begin(), (x).end() const int N = 2e5 + 4; vector<int> adj[N]; bool vis[N]; int sz = 0; void dfs(int u) { if (vis[u]) return; ++sz; vis[u] = true; for (auto &v : adj[u]) { dfs(v); } } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; int a[n]; for (int i = 0; i < n; ++i) { cin >> a[i]; } for (int i = 0; i < (n + 1) / 2; ++i) { if (a[i] != a[n - i - 1]) { adj[a[i]].emplace_back(a[n - i - 1]); adj[a[n - i - 1]].emplace_back(a[i]); } } int ans = 0; for (int i = 1; i < N; ++i) { if (!vis[i]) { sz = 0; dfs(i); ans += (sz - 1); } } cout << ans; return 0; }
//設定言語check #include <bits/stdc++.h> #include <iostream> #include <string> #include <limits.h> #include <algorithm> #include <iomanip> #include <math.h> #include <queue> #define REP(i,n) for((i)=0;(i)<(int)(n);(i)++) using namespace std; int main(){ long long int N, L, K, ans = 0, flag = 0 ; int i, j, k, cas, num ; cin >> N ; long long int A[N+2], B[N+2] ; REP(i,N){ cin >> A[i] >> B[i] ; } REP(i,N){ REP(j,i){ REP(k,j){ L = (A[i]-A[k]) * (B[i]-B[j]) ; K = (A[i]-A[j]) * (B[i]-B[k]) ; if(L == K){ cout << "Yes" << endl ; return 0 ; } } } } cout << "No" << endl ; return 0 ; }
#include<iostream> #include<string> #include<vector> #include<set> #include<map> #include<unordered_set> #include<unordered_map> #include<stack> #include<queue> #include<deque> #include<algorithm> #include<cmath> #include<functional> #include<bitset> #include<iomanip> #define _GLIBCXX_DEBUG #define fi first #define se second #define pb push_back #define all(x) begin(x), end(x) #define rep(i,n) for(int i=0;i<n;++i) #define rep2(i,l,r) for(int i=l;i<=r;++i) #define rep3(i,l,r) for(int i=l;i>=r;--i) #define pii pair<int,int> #define pll pair<ll,ll> using namespace std; using ll = long long; using ld = long double; using ull = unsigned long long; template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; const long long mod=1000000007; const double PI = acos(-1); int main(){ int n; cin >> n; V<pii> vp(n); for(int i=0;i<n;++i){ cin >> vp[i].fi >> vp[i].se; } bool ans = false; for(int i=0;i<n-2;++i){ for(int j=i+1;j<n-1;++j){ for(int k=j+1;k<n;++k){ if((vp[k].fi-vp[i].fi)*(vp[j].se-vp[i].se) == (vp[j].fi-vp[i].fi)*(vp[k].se-vp[i].se)) ans = true; } } } if(ans) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int a,b,c,d; cin >> a >> b >> c >> d; int tot=a+b+c+d; int ok=0; if(tot-a==a)ok=1; if(tot-b==b)ok=1; if(tot-c==c)ok=1; if(tot-d==d)ok=1; if(tot-a-b==a+b)ok=1; if(tot-a-c==a+c)ok=1; if(tot-a-d==a+d)ok=1; if(tot-b-c==c+b)ok=1; if(tot-b-d==d+b)ok=1; if(tot-d-c==c+d)ok=1; if(ok)cout << "Yes" << endl; else cout << "No" << endl; return 0; }
#include<bits/stdc++.h> #include <math.h> using namespace std; using ll = long long; const double pi=acos(-1.0); #define rep(i, n) for (int i = 0; i < (int)(n); i++) int max(int a,int b){if(a>b){return a;}return b;} int min(int a,int b){if(a<b){return a;}return b;} int main(void){ long long int a,n,v,t,s,d; cin>>v>>t>>s>>d; if(v*t<=d&&d<=v*s){cout<<"No"<<endl; return 0;} cout<<"Yes"<<endl; }
#include <vector> #include <algorithm> #include <iostream> #include <string> #include <map> #include <unordered_map> #include <set> #include <queue> #include <unordered_set> using namespace std; #define pii pair<int,int> #define pll pair<long long, long long> int main(){ int ncases; cin >> ncases; for(int z = 0; z < ncases; z++){ long long l, r; long long ret = 0; cin >> l >> r; long long maxx = (r - 2 * l + 1); if(maxx > 0){ ret = maxx * (maxx + 1) / 2; } cout << ret << endl; } }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0; (i) < n ; i++) using namespace std; using ll = long long; ll result(ll a, ll b){ ll v = b - 2 * a + 1; ll u = v * (v + 1)/2; return u; } int main(){ int T; cin >> T; ll outc[T]; rep(i,T){ ll l, r ; cin >> l >> r; if (r >= 2 * l){ ll c = result(l,r); outc[i] = c; } else { outc[i] = 0; } } rep(i,T){ cout << outc[i] << endl; } return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)(n);i++) #define chmin(x,y) x = min((x),(y)) #define chmax(x,y) x = max((x),(y)) #define popcount(x) __builtin_popcount(x) using namespace std; using ll = long long ; using P = pair<int,int> ; using pll = pair<long long,long long>; const int INF = 1e9; const long long LINF = 1e17; const int MOD = 1000000007; //const int MOD = 998244353; const double PI = 3.14159265358979323846; int main(){ int n; cin >> n; vector<ll> a(2*n); rep(i,2*n) cin >> a[i]; vector<int> id(2*n); iota(id.begin(),id.end(),0); sort(id.begin(),id.end(),[&](int l,int r){ return a[l] < a[r]; }); vector<int> revid(2*n); rep(i,2*n) revid[id[i]] = i; stack<int> st; string ans = ""; rep(i,2*n){ int t = revid[i] < n ? 0 : 1; if(st.empty()){ ans += "("; st.push(t); }else{ if(st.top() == 1-t){ ans += ')'; st.pop(); }else{ ans += '('; st.push(t); } } } cout << ans << endl; return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <cstdio> #include <cstring> #include <ctime> #include <iostream> #include <list> #include <map> #include <memory> #include <queue> #include <random> #include <set> #include <string> #include <vector> typedef long long ll; typedef unsigned long long ull; typedef long double LD; typedef std::pair<int, int> pii; const int INF = 2147483647; const int INF2 = 0x3f3f3f3f; const ll INF64 = (ll)1e18; const double INFD = 1e30; const double EPS = 1e-9; const double PI = std::acos(-1); const int MOD = 998244353; template <typename T> inline T read() { T X = 0, w = 0; char ch = 0; while (!isdigit(ch)) { w |= ch == '-'; ch = getchar(); } while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar(); return w ? -X : X; } const int MAXN = 400005; const int MAXV = (1 << 17) + 5; int n, m, k; int dr[4] = {0, 1, 0, -1}; int dc[4] = {-1, 0, 1, 0}; int dr2[8] = {1, 1, 1, -1, -1, -1, 0, 0}; int dc2[8] = {1, 0, -1, 1, 0, -1, 1, -1}; int CASE = 1; int A[MAXN]; int B[MAXN]; pii st[MAXN]; char ans[MAXN]; int top; int main() { #ifdef LOCALLL freopen("in", "r", stdin); freopen("out", "w", stdout); #endif scanf("%d", &n); n *= 2; for (int i = 1; i <= n; i++) { A[i] = read<int>(); B[i] = A[i]; } std::sort(B + 1, B + n + 1); int L = B[n / 2], R = B[n / 2 + 1]; int smalleq = 0; for (int i = 1; i <= n / 2; i++) { if (B[i] == L) smalleq++; } for (int i = 1; i <= n; i++) { bool small = A[i] < L || (A[i] == L && smalleq > 0); if (A[i] == L && smalleq > 0) smalleq--; if (top != 0 && st[top].first != small) { ans[i] = ')'; ans[st[top].second] = '('; top--; } else { st[++top] = {small, i}; } } for (int i = 1; i <= n; i++) { printf("%c", ans[i]); } printf("\n"); return 0; }
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <cmath> #define MOD(x) ((x) >= mod ? (x) - mod : (x)) using namespace std; const int maxn = 500010, inf = 1e9 + 233, mod = 1e9 + 7; int n; int fib[maxn]; char s[233][233]; int main() { scanf("%d", &n); for (int i = 1; i <= 4; i++) cin >> s[i]; if (s[1][0] == 'A' && s[2][0] == 'A') return puts("1"), 0; if (s[4][0] == 'B' && s[2][0] == 'B') return puts("1"), 0; if (s[1][0] == 'B' && s[2][0] == 'A' && s[3][0] == 'A') { fib[0] = 1; fib[1] = 1; for (int i = 2; i <= n - 2; i++) fib[i] = MOD(fib[i - 1] + fib[i - 2]); printf("%d\n", fib[n - 2]); return 0; } if (s[4][0] == 'A' && s[2][0] == 'B' && s[3][0] == 'B') { fib[0] = 1; fib[1] = 1; for (int i = 2; i <= n - 2; i++) fib[i] = MOD(fib[i - 1] + fib[i - 2]); printf("%d\n", fib[n - 2]); return 0; } int ans = 1; for (int i = 1; i <= n - 3; i ++) ans = MOD(ans + ans); printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn=1005; const int mod=1e9+7; int n; char c[2][2]; ll dp[maxn][2]; int main() { scanf("%d",&n); for(int i=0;i<2;i++) for(int j=0;j<2;j++) { char ch; do ch=getchar(); while(!isalpha(ch)); c[i][j]=ch; } if(n<=3) return printf("1\n"),0; if(c[0][1]=='A') { if(c[0][0]=='A') return printf("1\n"),0; // c[0][0]=='B' if(c[1][0]=='A') // AAAAABAAAB { dp[1][0]=dp[1][1]=1; for(int i=2;i<=n-3;i++) dp[i][0]=(dp[i-1][0]+dp[i-1][1])%mod,dp[i][1]=dp[i-1][0]; printf("%lld\n",(dp[n-3][0]+dp[n-3][1])%mod); } else // c[1][0]=='B' ABABAABBBAABBB { ll ans=1; for(int i=1;i<=n-3;i++) ans=ans*2%mod; printf("%lld\n",ans); } } else { if(c[1][1]=='B') return printf("1\n"),0; if(c[1][0]=='B') { dp[1][0]=dp[1][1]=1; for(int i=2;i<=n-3;i++) dp[i][0]=(dp[i-1][0]+dp[i-1][1])%mod,dp[i][1]=dp[i-1][0]; printf("%lld\n",(dp[n-3][0]+dp[n-3][1])%mod); } else { ll ans=1; for(int i=1;i<=n-3;i++) ans=ans*2%mod; printf("%lld\n",ans); } } return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long int const int mod = (int)1e9 + 7; template<class T> auto vec(int r, int c, T v){ return vector<vector<T>>(r, vector<T>(c, v)); } template<class T> auto vec(int o1, int o2, int o3, T v){ return vector<vector<vector<T>>>(o1, vector<vector<T>>(o2, vector<T>(o3, v))); } int power(int x, int n, int m){ x %= m; int ans = 1; while(n > 0){ if( n & 1 ) ( ans *= x ) %= m; ( x = x * x ) %= m; n >>= 1; } return ans; } #define lb(x, y) (lower_bound(x.begin(), x.end(), y) - x.begin()) #define ub(x, y) (upper_bound(x.begin(), x.end(), y) - x.begin()) #define dbg(x) cerr << "[" #x << " => " << x << "] "; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; int cur = 1, b = 0; int res = LLONG_MAX; while(cur <= n) { int a = n / cur; int c = n - a * cur; res = min(res, a + b + c); cur *= 2; b++; } cout << res << "\n"; return 0; }
/* このコード、と~おれ! Be accepted! ∧_∧  (。・ω・。)つ━☆・*。 ⊂   ノ    ・゜+.  しーJ   °。+ *´¨)          .· ´¸.·*´¨) ¸.·*¨)           (¸.·´ (¸.·'* ☆ */ #include <cstdio> #include <algorithm> #include <string> #include <cmath> #include <cstring> #include <vector> #include <numeric> #include <iostream> #include <random> #include <map> #include <unordered_map> #include <queue> #include <regex> #include <functional> #include <complex> #include <list> #include <cassert> #include <iomanip> #include <set> #include <stack> #include <bitset> #include <array> #include <chrono> //#pragma GCC target("arch=skylake-avx512") #pragma GCC target("avx2") //#pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC target("sse4") #pragma GCC optimize("unroll-loops") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define repeat(i, n, m) for(int i = n; i < (m); ++i) #define rep(i, n) for(int i = 0; i < (n); ++i) #define printynl(a) printf(a ? "yes\n" : "no\n") #define printyn(a) printf(a ? "Yes\n" : "No\n") #define printYN(a) printf(a ? "YES\n" : "NO\n") #define printim(a) printf(a ? "possible\n" : "imposible\n") #define printdb(a) printf("%.50lf\n", a) #define printLdb(a) printf("%.50Lf\n", a) #define printdbd(a) printf("%.16lf\n", a) #define prints(s) printf("%s\n", s.c_str()) #define all(x) (x).begin(), (x).end() #define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI) #define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L) #define Please return #define AC 0 #define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) using ll = long long; using ull = unsigned long long; constexpr int INF = 1073741823; constexpr int MINF = -1073741823; constexpr ll LINF = ll(4661686018427387903); constexpr ll MOD = 1e9 + 7; constexpr ll mod = 998244353; constexpr long double eps = 1e-6; const long double PI = acosl(-1.0L); using namespace std; void scans(string& str) { char c; str = ""; scanf("%c", &c); if (c == '\n')scanf("%c", &c); while (c != '\n' && c != -1 && c != ' ') { str += c; scanf("%c", &c); } } void scanc(char& str) { char c; scanf("%c", &c); if (c == -1)return; while (c == '\n') { scanf("%c", &c); } str = c; } double acot(double x) { return PI / 2 - atan(x); } ll LSB(ll n) { return (n & (-n)); } template<typename T> inline T chmin(T& a, const T& b) { if (a > b)a = b; return a; } template<typename T> inline T chmax(T& a, const T& b) { if (a < b)a = b; return a; } //cpp_int #if __has_include(<boost/multiprecision/cpp_int.hpp>) #include <boost/multiprecision/cpp_int.hpp> #include <boost/multiprecision/cpp_dec_float.hpp> using namespace boost::multiprecision; #else using cpp_int = ll; #endif //atcoder library #if __has_include(<atcoder/all>) #include <atcoder/all> //using namespace atcoder; #endif /* random_device seed_gen; mt19937 engine(seed_gen()); uniform_int_distribution dist(1, 100); */ /*----------------------------------------------------------------------------------*/ int main() { int n; scanf("%d", &n); n = min(n, 8); vector<int> a(n); rep(i, n) { scanf("%d", &a[i]); a[i] %= 200; } vector<vector<int>> b(200); rep(i, (1 << n)) { int cur = 0; vector<int> c; rep(j, n) { if (i & (1 << j)) { cur += a[j]; cur %= 200; c.push_back(j); } } if(b[cur].empty()) b[cur] = c; else { printf("yEs\n%d ", (int)c.size()); for (const auto& aa : c)printf("%d\n", aa + 1); printf("%d\n", (int)b[cur].size()); for (const auto& aa : b[cur])printf("%d\n", aa + 1); return 0; } } puts("nO"); Please AC; }
#define taskname "test" #include <bits/stdc++.h> using namespace std; #define sz(x) (int)x.size() #define fi first #define se second typedef long long lli; typedef pair<int, int> pii; string s; void read_input() { cin >> s; } void solve() { cout << s[1] << s[2] << s[0] << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); read_input(); solve(); }
// 299143BT #include<bits/stdc++.h> #define ll int64_t #define MOD 1000000007 #define pi 3.1415926535 #define fi first #define se second #define vll vector<ll> #define vpll vector<pair <ll,ll> > #define vvll vector< vll > #define str string #define umap unordered_map #define uset unordered_set #define rep(i,n) for(ll i=0;i<n;i++) #define repA(i,s,n) for(ll i=s;i<=n;i++) #define repD(i,s,n) for(ll i=s;i>=n;i--) #define pb push_back #define mp make_pair #define lb lower_bound #define ub upper_bound #define elif else if #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define ALL(v) v.begin(),v.end() #define sortA(v) sort(ALL(v)) #define sortD(v) sort(ALL(v),greater <ll> ()) #define print(v) for(auto itr:v) cout<<itr<<" "; #define sz size() #define nl cout<<"\n"; using namespace std; ll factorial(ll n){return (n==1||n==0)?1:n*factorial(n-1);} ll power(ll x,ll y){ll res=1;while(y>0){if(y&1)res=res*x;y=y>>1;x=x*x;}return res;} ll powerMod(ll x,ll y,ll m){if(y==0)return 1;ll p=powerMod(x,y/2,m)%m;p=(p*p)%m;return (y%2==0)?p:(x*p)%m;} ll modInverse(ll a,ll m){return powerMod(a,m-2,m);} ll gcd(ll a,ll b){if(a==0){return b;}else if(b==0){return a;}else{if(a>b){return gcd(a%b,b);}else{return gcd(b%a,a);}}} void pre(){ } void solve(){ str s; cin>>s; repA(i,1,s.sz-1) cout<<s[i]; cout<<s[0]; } int main(){ fast ll t=1; //cin>>t; pre(); while(t--){ solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; long long c; cin >> n >> c; vector<array<int, 2>> events; for (int i = 0; i < n; ++i) { int l, r, w; cin >> l >> r >> w; events.push_back({l, w}); events.push_back({r + 1, -w}); } sort(events.begin(), events.end()); int prv = 0; long long ans = 0, sum = 0; for (auto [x, y] : events) { ans += (x - prv) * min(sum, c); sum += y; prv = x; } cout << ans << "\n"; }
#include <algorithm> #include <iostream> #include <cstdio> #define ll long long #define MOD 1000000007 using namespace std; int main() { int t; ll n, a, b; cin >> t; while(t--) { cin >> n >> a >> b; if(a+b > n) { cout << 0 << endl; continue; } ll ans = 0; ans = (n-a-b+1)*(n-a-b+2)%MOD*((2*(n-a+1)*(n-b+1)%MOD-(n-a-b+1)*(n-a-b+2)%MOD+MOD)%MOD)%MOD; cout << ans << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long #define rep(i,n) for(int i=0;i<n;i++) int N; signed main() { cin >> N; rep(i, N) cout << (2 * i + 1) % N + 1 << " " << (2 * i + 2) % N + 1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; void chmin(int64_t& a, int64_t b){ a = min(a, b); } int main(){ int T; // cin >> T; T=1; typedef pair<int64_t, int64_t> P; while(T--){ int64_t X,Y; cin >>X>>Y; int64_t cost[6] = {0}; cost[2] = 1; cost[3] = 0; cost[5] = 0; int64_t ans = 1e18; priority_queue<P, vector<P>, greater<P>> que; map<int64_t, int64_t> memo; auto insert = [&](int64_t v, int64_t n){ if(v < ans && (!memo.count(n) || v < memo[n])){ que.emplace(v, n); memo[n] = v; } }; int64_t D=1; que.emplace(0, Y); while(que.size()){ auto p = que.top(); que.pop(); int64_t v = p.first, n = p.second; if(v >= ans) break; if(n <= 2e18/D) chmin(ans, v+abs(n-X)*D); for(int d : {2}){ int r = n%d; int64_t v2 = v + r*D + cost[d]; insert(v2, n/d); v2 = v + (d-r)*D + cost[d]; insert(v2, n/d+1); } } cout <<ans<< endl; } return 0; }
#include <bits/stdc++.h> #define pii pair<int, int> #define ld long double #define ll long long using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); string s; cin >> s; int n = s.length(); int cnt[300]; memset(cnt, 0, sizeof(cnt)); int lastIdx = n; char lastChar = '-'; ll ans = 0; for (int i = n - 1; i >= 0; i--) { if (i != n - 1 && s[i] == s[i + 1]) { cnt[s[i]]--; if (lastChar == s[i]) ans += lastIdx - i - 2 - cnt[s[i]]; else ans += n - i - 2 - cnt[s[i]]; lastIdx = i; lastChar = s[i]; memset(cnt, 0, sizeof(cnt)); } else { cnt[s[i]]++; } } cout << ans << "\n"; }
//jai baba loknath #include<bits/stdc++.h> // Program showing a policy-based data structure. #include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/tree_policy.hpp> #include <functional> // for less using namespace std; using namespace __gnu_pbds; typedef long long int ll; // GNU link : https://goo.gl/WVDL6g typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; #define READ freopen("in.txt", "r", stdin); #define WRITE freopen("out.txt", "w", stdout); #define optimize ios::sync_with_stdio(0);cin.tie(0); #define RESET(a, b) memset(a, b, sizeof(a)) #define gcd(a, b) __gcd(a, b) #define MX 200005 #define MOD 1000000007 #define inf ll(1e18) #define PI acos(-1.0) #define eps 1e-9 #define Yes cout<<"Yes"<<endl; #define YES cout<<"YES"<<endl; #define No cout<<"No"<<endl; #define NO cout<<"NO"<<endl; inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); } inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; } inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; } inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; } inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p & 1LL) r = modMul(r, b); b = modMul(b, b); p >>= 1LL; } return r; } inline ll modInverse(ll a) { return modPow(a, MOD-2); } inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); } inline ll mod(ll a, ll m){ if(a<0) return ((a%m)+m)%m; else if(a<m) return a; else return (a%m); } ll LCM(ll a, ll b) { return (a / __gcd(a, b)) * b; } //for vector of pair /*bool cmp(pair<int,int>a, pair<int,int>b) { if(a.first==b.first) return a.second<b.second; else return a.first<b.first; }*/ //for priority queue of pair class cmp { public: bool operator()(pair<ll,ll> A, pair<ll,ll> B) { if(A.first==B.first) return A.second>B.second; else return A.first<B.first; } }; ll sum[27][MX]; int main(void) { optimize RESET(sum,0); ll t,n,m,k,x,y; vector<ll> v,v1,v2; vector< pair<ll,ll> > p,p1,p2; set<ll> st; map<ll,ll> mp; priority_queue<ll> pq; priority_queue< ll,vector<ll>,greater<ll> > lpq; priority_queue< pair<ll,ll> > phpq; priority_queue< pair<ll,ll>,vector<pair<ll,ll>>,cmp > phpqcmp; priority_queue< pair<ll,ll>,vector< pair<ll,ll> >,greater< pair<ll,ll> > > plpq; string s; //cin>>t; //while(t--)//for(ll tc=1;tc<=t;tc++) { cin>>s; for(char j='a';j<='z';j++) { for(ll i=0;i<s.size();i++) { if(i==0) { if(s[i]==j) sum[j-'a'][i]=1; else sum[j-'a'][i]=0; } else if(s[i]==j) sum[j-'a'][i]=sum[j-'a'][i-1]+1; else sum[j-'a'][i]=sum[j-'a'][i-1]; } } /*for(char j='a';j<='z';j++) { for(ll i=0;i<s.size();i++) { cout<<sum[j-'a'][i]<<" "; } cout<<endl; }*/ ll pos=s.size()-1,ans=0; char str='0'; for(ll i=s.size()-1;i>0;i--) { if(s[i]==s[i-1]) { x=sum[s[i]-'a'][pos]-sum[s[i]-'a'][i]; ans+=(pos-i)-x; if(str!='0' && s[i]!=str) ans+=(s.size()-1-pos); str=s[i]; for(ll j=i-1;j>=0;j--) { if(s[j]==s[j+1]) i--; else break; } pos=i-1; } } cout<<ans<<endl; } return 0; }
/* * author: vongkh * created: Sun Jan 17 2021 */ #include <stdio.h> #include <cstdlib> #include <map> int64_t x, y; std::map<int64_t, int64_t> memo; int64_t get_operation_num(int64_t z){ //get the number of operation need to transform z back to x //each stop we have three choices : increment, decrement, divide by 2 //Observation: divide by 2 and +/- later is more efficient if(memo.find(z) != memo.end()) return memo[z]; if(z == 1) return std::abs(z - x); int64_t ans = std::abs(z - x); if(z%2){ //if z is odd we can only do +/- ans = std::min(ans, get_operation_num(z-1)+1); ans = std::min(ans, get_operation_num(z+1) + 1); }else{ //if z is even, it is optimal to try to /2 ans = std::min(ans, get_operation_num(z/2) + 1); } return memo[z] = ans; } int main(){ scanf("%lld %lld", &x, &y); //we solve this problem by thinking inversely //how to get x from y int64_t ans = get_operation_num(y); printf("%lld \n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; const ll MOD = 1e9+7; const ll INF = 1e18; #define rep(i,m,n) for(ll i = (m); i <= (n); i++) #define zep(i,m,n) for(ll i = (m); i < (n); i++) #define rrep(i,m,n) for(ll i = (m); i >= (n); i--) #define print(x) cout << (x) << endl; #define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl; int main(){ cin.tie(0); ios::sync_with_stdio(false); ll n, m; cin >> n >> m; ll a[m + 2]; rep(i, 1, m)cin >> a[i]; sort(a + 1, a + m + 1); a[0] = 0; a[m + 1] = n + 1; ll mn = INF; rep(i, 0, m){ if(a[i + 1] - a[i] - 1 > 0){ mn = min(mn, a[i + 1] - a[i] - 1); } } ll ans = 0; rep(i, 0, m){ //print(mn) //print(a[i + 1] - a[i] - 1) ans += (a[i + 1] - a[i] - 1 + mn - 1) / mn; } print(ans) return 0; }
#include<bits/stdc++.h> using namespace std; const int N = 1e5+10; int a[N]; int main() { int n; cin>>n; int maxn1=0,st1=0; int maxn2=0,st2=0; for(int i=1;i<=(1<<n);i++) { cin>>a[i]; if(i<=(1<<(n-1))) { if(a[i]>maxn1) { st1=i; maxn1=a[i]; } } else { if(a[i]>maxn2) { maxn2=max(maxn2,a[i]); st2=i; } } } if(maxn1<=maxn2) { cout<<st1<<endl; } else { cout<<st2<<endl; } }
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<(n);++i) #include <vector> int main() { int N; cin>>N; vector<int>vec(pow(2,N)); for(int i=0;i<pow(2,N);++i){ cin>>vec.at(i); } map<int,int>mp; for(int i=0;i<pow(2,N);++i){ mp[vec[i]]=i+1; } while(vec.size()>2){ vector<int>vec2; for(int i=0; i<vec.size();i+=2){ vec2.push_back(max(vec[i],vec[i+1])); } swap(vec,vec2); } int ans = min(vec[0],vec[1]); cout<< mp[ans]<<endl; 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() { double n; cin >> n; double x0, y0, xn, yn; cin >> x0 >> y0 >> xn >> yn; double vx = xn - x0; double vy = yn - y0; double theta = -(90 - (double)180 / n) * M_PI / 180; // cout << sqrt(vx * vx + vy * vy) << endl; // cout << cos(theta) << endl; // cout << cos(theta) - sin(theta) << endl; // cout << vx << " " << vy << endl; double ansx = cos(theta) * (vx * cos(theta) - vy * sin(theta)) + x0; double ansy = cos(theta) * (vx * sin(theta) + vy * cos(theta)) + y0; // double ansx = 1 / sqrt(vx * vx + vy * vy) * (vx * cos(theta) - vy * sin(theta)) + x0; // double ansy = 1 / sqrt(vx * vx + vy * vy) * (vx * sin(theta) + vy * cos(theta)) + y0; // double ansx = sqrt(vx * vx + vy * vy) * cos(theta) * (vx * cos(theta) - vy * sin(theta)) + x0; // double ansy = sqrt(vx * vx + vy * vy) * cos(theta) * (vx * sin(theta) + vy * cos(theta)) + y0; cout << fixed << setprecision(11) << ansx << " " << ansy << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define drep(i,n) for(int i = (n-1); i >= 0; i--) #define all(v) (v).begin(),(v).end() #define maxs(x,y) (x = max(x,y)) #define mins(x,y) (x = min(x,y)) template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } template <class T> T lcm(T a, T b) { return a/gcd(a,b)*b; } typedef pair<int, int> P; typedef long long ll; const int INF = 1001001001; const ll LINF = 1001002003004005006ll; const ll MOD = 1e9+7; int solve(int x, int y) { if (x == 0 && y == 0) return 0; if (x+y == 0) return 1; if (x-y == 0) return 1; if (abs(x)+abs(y) <= 3) return 1; if ((x+y)%2 == 0) return 2; if (abs(x)+abs(y) <= 6) return 2; if (abs(x+y) <=3) return 2; if (abs(x-y) <=3) return 2; else return 3; } int main() { int x1,y1,x2,y2; cin >> x1 >> y1 >> x2 >> y2; cout << solve(x2-x1, y2-y1) << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int lucas(int a, int b){ int comb = 1; for(;;){ int a3 = a % 3; a /= 3; int b3 = b % 3; b /= 3; if(a3 < b3){ comb = 0; break; } else if(a3 == 2 && b3 == 1) comb *= 2; if(a == 0 && b == 0) break; } return comb % 3; } int main(){ int N; cin >> N; string s; cin >> s; int ans = 0; for(int i = 0;i < N;i++){ char c = s.at(i); int plus = 0; if(c == 'R') plus = 1; else if(c == 'B') plus = 2; int comb = lucas(N - 1, i); plus *= comb; ans += plus; } if(N % 2 == 0) ans = (ans * 2) % 3; else ans %= 3; if(ans % 3 == 0) cout << "W" << endl; else if(ans % 3 == 1) cout << "R" << endl; else cout << "B" << endl; }
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author tatsumack */ #include <iostream> #include <fstream> #include <bits/stdc++.h> #define int long long #define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i) #define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i) #define REV(i, a, b) for (int i = (a); i >= (b); --i) #define CLR(a, b) memset((a), (b), sizeof(a)) #define DUMP(x) cout << #x << " = " << (x) << endl; #define INF 1001001001001001001ll #define fcout cout << fixed << setprecision(12) using namespace std; struct Comb { vector<vector<long long>> com; long long p; Comb(long long _p) : p(_p) { init(p); } void init(long long p) { // 動的計画法で前処理 com.assign(p, vector<long long>(p)); com[0][0] = 1; for (int i = 1; i < p; i++) { com[i][0] = 1; for (int j = i; j > 0; j--) { com[i][j] = (com[i - 1][j - 1] + com[i - 1][j]) % p; } } } long long nCk(long long n, long long k) { long long ret = 1; while (n > 0) { // 下から一桁ずつ計算する int ni = n % p; int ki = k % p; ret *= com[ni][ki]; ret %= p; n /= p; k /= p; } return ret; } }; class CTricolorPyramid { public: void solve(std::istream& cin, std::ostream& cout) { int N; cin >> N; vector<int> C(N); REP(i, N) { char c; cin >> c; if (c == 'B') C[i] = 0; if (c == 'W') C[i] = 1; if (c == 'R') C[i] = 2; } Comb cb(3); int res = 0; REP(i, N) { res += cb.nCk(N - 1, i) * C[i]; res %= 3; } if ((N - 1) % 2 == 1) { res *= -1; } res %= 3; if (res < 0) res += 3; char ans; switch (res) { case 0: ans = 'B'; break; case 1: ans = 'W'; break; case 2: ans = 'R'; break; } cout << ans << endl; } }; signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); std::istream& in(std::cin); std::ostream& out(std::cout); CTricolorPyramid solver; solver.solve(in, out); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < int(n); i++) using ll = long long; using P = pair<int, int>; template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } int main() { cin.tie(0); ios_base::sync_with_stdio(false); int n, m; cin >> n >> m; vector<int> a(m), b(m); vector<char> c(m); rep(i, m) { cin >> a[i] >> b[i] >> c[i]; a[i]--, b[i]--; } vector<vector<int>> g(n * n); auto to_one = [&](int x, int y) { return x * n + y; }; auto to_two = [&](int x) { P res = {x / n, x % n}; return res; }; rep(i, m) { rep(j, m) { if(c[i] != c[j]) continue; g[to_one(a[i], a[j])].push_back(to_one(b[i], b[j])); g[to_one(a[i], b[j])].push_back(to_one(b[i], a[j])); g[to_one(b[i], a[j])].push_back(to_one(a[i], b[j])); g[to_one(b[i], b[j])].push_back(to_one(a[i], a[j])); } } const int INF = 1e9; vector<int> dist(n * n, INF); queue<int> que; rep(i, n) { que.push(to_one(i, i)); dist[to_one(i, i)] = 0; } rep(i, m) { que.push(to_one(a[i], b[i])); chmin(dist[to_one(a[i], b[i])], 1); que.push(to_one(b[i], a[i])); chmin(dist[to_one(b[i], a[i])], 1); } while(!que.empty()) { int now = que.front(); que.pop(); for (auto nv : g[now]) { int cost = dist[now] + 2; if(dist[nv] != INF) continue; dist[nv] = cost; que.push(nv); } } int ans = min(dist[to_one(0, n - 1)], dist[to_one(n - 1, 0)]); cout << (ans == INF ? -1 : ans) << endl; return 0; }
#include "bits/stdc++.h" using namespace std; #define ll long long #define pb push_back #define all(_obj) _obj.begin(),_obj.end() #define F first #define S second #define pll pair<ll, ll> #define vll vector<ll> ll n,m,a,b,c,k,temp,x,y,INF=1e18,s; const int N=1e5+11,mod=1e9+7; ll max(ll a,ll b) {return ((a>b)?a:b);} ll min(ll a,ll b) {return ((a>b)?b:a);} vll read(int n) {vll v(n);for (int i = 0; i < v.size(); i++)cin>>v[i];return v;} mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); ll gcd(ll a, ll b, ll& x, ll& y) { //ax+by=gcd; //modular inverse =take gcd with m then (x%m+m)%m; if (b == 0) { x = 1; y = 0; return a; } ll x1, y1; ll d = gcd(b, a % b, x1, y1); x = y1; y = x1 - y1 * (a / b); return d; } void sol(void) { cin>>n>>s>>k; ll rem=n-s; ll g1=gcd(n,rem,x,y); ll g2=gcd(g1,k,x,y); k/=g2; n/=g2; rem/=g2; if(gcd(k,n,x,y)!=1) cout<<-1<<'\n'; else cout<<(((x%n+n)%n)*rem)%n<<'\n'; return ; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL),cout.tie(NULL); int test=1; cin>>test; while(test--) sol(); }
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <stack> #include <queue> #include <cmath> #include <tuple> #include <cstdio> #include <bitset> #include <sstream> #include <iterator> #include <numeric> #include <map> #include <cstring> #include <set> #include <functional> #include <iomanip> using namespace std; #define DEBUG_ //!!$BDs=P;~$K%3%a%s%H%"%&%H(B!! #ifdef DEBUG_ #define dump(x) cerr << #x << " = " << (x) << endl; #else #define dump(x) ; #endif #define equals(a,b) (fabs((a)-(b)) < EPS) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define SZ(x) ((int)(x).size()) #define pb push_back #define eb emplace_back //#define int long long typedef long long LL; typedef vector<int> VI; typedef vector<LL> VL; typedef vector<VI> VVI; typedef vector<VL> VVL; typedef vector<string> VS; typedef pair<int, int> PII; typedef pair<LL, LL> PLL; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; } template <typename T> std::string printVector(const std::vector<T> &data) { std::stringstream ss; std::ostream_iterator<T> out_it(ss, ", "); ss << "["; std::copy(data.begin(), data.end() - 1, out_it); ss << data.back() << "]"; return ss.str(); } template <typename T> void print_array(const T &ary, int size){ REP(i,size){ cout << ary[i] << " "; } cout << endl; } const int mod = 1e9+7; const LL LINF = 1001002003004005006ll; const int INF = 1001001001; const double EPS = (1e-10); const long double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899; int dx[] = {0,0,-1,1}; int dy[] = {-1,1,0,0}; signed main(int argc, char const *argv[]) { cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(12); int N,M; cin >> N >> M; vector<vector<PII>> yz(N); REP(i,M){ int x,y,z; cin >> x >> y >> z; x--; yz[x].eb(y,z); } vector<vector<LL>> dp(N+1,VL(1 << N)); dp[0][0] = 1; REP(i,N){ REP(mask,(1 << N)){ REP(j,N){ if((mask >> j) & 1) continue; dp[i+1][mask | (1 << j)] += dp[i][mask]; } } // check REP(mask, (1 << N)){ bool ok = true; for(auto p : yz[i]){ int y,z; tie(y,z) = p; int cnt = 0; REP(a,y){ if((mask >> a) & 1) cnt++; } if(cnt > z) ok = false; } if(!ok){ dp[i+1][mask] = 0; } } } //REP(i,N+1){ // dump(i) // REP(mask, (1 << N)){ // cout << mask << " " << dp[i][mask] << endl; // } //} LL ans = 0; REP(mask, (1 << N)){ ans += dp[N][mask]; } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; const int maxn=2e5+5; typedef long long ll; const int mod=1e9+7; ll dp[1<<18][18]; int x[105],y[105],z[105]; int sum[20]; int main(){ int n,m; scanf("%d%d",&n,&m); for(int i=1;i<=m;i++){ scanf("%d%d%d",&x[i],&y[i],&z[i]); } for(int i=0;i<n;i++) dp[1<<i][i]=1; for(int s=1;s<(1<<n);s++){ bool flag=0; for(int j=0;j<n;j++){ sum[j+1]=sum[j]+((s&(1<<j))>0); } for(int id=1;id<=m;id++){ if(sum[n]==x[id]){ if(sum[y[id]]>z[id]){ flag=1;break; } } } if(flag){ for(int j=0;j<n;j++) if(s&(1<<j)) dp[s][j]=0; continue; } for(int j=0;j<n;j++){ if(s&(1<<j)){ int s1=s^(1<<j); for(int k=0;k<n;k++){ if(s1&(1<<k)){ dp[s][j]+=dp[s1][k]; } } } } } ll ans=0; for(int j=0;j<n;j++){ ans+=dp[(1<<n)-1][j]; } cout<<ans<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define all(s) s.begin(), s.end() #define pb push_back #define ii pair<int, int> #define x first #define y second #define bit(x, y) ((x >> y) & 1) long long C(int n, int k) { long long res = 1; for (int i = 0; i < k; i++) { res *= (n - i); res /= (i + 1); } return res; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int l; cin >> l; cout << C(l - 1, 11) << '\n'; return 0; }
#include<iostream> #include<bits/stdc++.h> using namespace std; #define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); #define pb push_back #define mp make_pair #define fi first #define se second #define merge(a,b) a##b #define mkstr(a) #a #define flush fflush(stdout); #define debug(x,y) cout<<#x<<" "<<y<<endl; typedef long long ll; typedef long double ld; typedef unsigned long long ull; const long long mod=1e9+7; const long long inf=1e18; /************************************TEMPLATE**********************************/ ll modpower(ll x,ll y) { ll res=1; x=x%mod; if(x==0) return 0; while(y>0) { if(y&1) res=(res*x)%mod; y=y>>1; x=(x*x)%mod; } return res; } /*************************************CODE*************************************/ int main() { fastIO ll test_case=1; // cin>>test_case; while(test_case--) { int x; cin>>x; if(x<0) { x=0; } cout<<x<<endl; } return 0; }
#include<bits/stdc++.h> #define ll long long using namespace std; int main() { ll n,x; cin>>n>>x; x=x*100; ll a[n+1],b[n+1]; ll tol=0; ll ans=-1; for(ll i=0;i<n;i++) { cin>>a[i]>>b[i]; tol+=(a[i]*b[i]); if(tol>x&&ans==-1) { ans=i+1; } } cout<<ans; return 0; }
// 200b.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。 // #include <iostream> #include <vector> #include <iomanip> using namespace std; void solve(){ double d, h; int n; cin >> n >> d >> h; vector<double> sx(n); vector<double> sy(n); for (size_t i = 0; i < n; i++) { cin >> sx[i] >> sy[i]; } double ans = -10000; for (size_t i = 0; i < n; i++) { double y = h - sy[i]; double x = d - sx[i]; double a = y / x; double b = h - (d * a); ans = max(b, ans); } if (ans < 0)ans = 0; cout << std::fixed << std::setprecision(15) << ans << endl; } int main() { solve(); return 0; } // プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー // プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー // 作業を開始するためのヒント: // 1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します // 2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します // 3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します // 4. エラー一覧ウィンドウを使用してエラーを表示します // 5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します // 6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int,int>; using pll = pair<ll,ll>; #define RST(i,n) memset(i,n,sizeof i) #define SZ(a) (int)a.size() #define ALL(a) a.begin(),a.end() #define X first #define Y second #define eb emplace_back #ifdef cold66 #define debug(...) do{\ fprintf(stderr,"LINE %d: (%s) = ",__LINE__,#__VA_ARGS__);\ _do(__VA_ARGS__);\ }while(0) template<typename T>void _do(T &&_x){cerr<<_x<<endl;} template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);} template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";} template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb) { _s<<"{"; for(It _it=_ita;_it!=_itb;_it++) { _s<<(_it==_ita?"":",")<<*_it; } _s<<"}"; return _s; } template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));} template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));} template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));} template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;} #define IOS() #else #define debug(...) #define pary(...) #define endl '\n' #define IOS() ios_base::sync_with_stdio(0);cin.tie(0); #endif // cold66 //} template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; } template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; } const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2; const ll MOD=1000000007; const ll INF=0x3f3f3f3f; int a[5]; int main(){ IOS(); int sum = 0; for (int i=0;i<4;++i) { cin >> a[i]; sum += a[i]; } bool ok = false; for (int i=0;i<4;++i) { if (sum - a[i] == a[i]) ok = true; for (int j=i+1;j<4;++j) { int cur = a[i] + a[j]; if (cur == sum - cur) ok = true; } } cout << (ok ?"Yes":"No") << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long int A, B, C, D; cin >>A >> B >>C >> D; string ans ="No"; for (int a=0; a<2; a++){ for (int b =0; b<2; b++){ for (int c =0; c<2; c++){ for(int d =0; d<2; d++){ if(2*(A*a+B*b+C*c+D*d) == A + B + C+ D){ ans ="Yes"; } } } } } cout << ans << endl; }
#include <iostream> #include <cstring> #include <vector> #include <algorithm> #include <queue> #include <set> #define endl '\n' using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; const ll INF=1e10+1; vector<int> graph[2001]; bool visit[2001]; void dfs(int root) { if(visit[root]) return; visit[root]=1; for(auto node : graph[root]) { dfs(node); } } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); //freopen("input.txt","r",stdin); int n,m; cin>>n>>m; for(int i=0;i<m;i++) { int a,b; cin>>a>>b; graph[a].push_back(b); } int ans=0; for(int i=1;i<=n;i++) { memset(visit,0,sizeof(visit)); dfs(i); for(int j=1;j<=n;j++) { if(visit[j]) ans++; } } cout<<ans; return 0; }
#include <bits/stdc++.h> #define rep(i, a, n) for(int i = a; i < (n); i++) using namespace std; using ll = long long; using P = pair<int, int>; const int INF = 1001001001; const ll LINF = 1001002003004005006ll; const int mod = 1000000007; //const int mod = 998244353; int main() { int n, m; cin >> n >> m; vector<int> a(n); rep(i, 0, n) cin >> a[i]; int now = 0; set<int> st, stt; rep(i, 0, 1500005) stt.insert(i); vector<int> mp(1500005); int mn = INF; rep(i, 0, n - m + 1){ while(now < i + m){ if(mp[a[now]] == 0) stt.erase(a[now]); if(mp[a[now]] == 0) st.insert(a[now]); mp[a[now]]++; now++; } auto it = stt.begin(); mn = min(mn, (int)*it); mp[a[i]]--; if(mp[a[i]] == 0){ stt.insert(a[i]); st.erase(a[i]); } } cout << mn << endl; return 0; }
#include<bits/stdc++.h> #define rep(i,a,b) for(ll i=(a);i<=(b);i++) #define per(i,a,b) for(ll i=(a);i>=(b);i--) #define next Cry_For_theMoon typedef unsigned long long ll; using namespace std; const ll MAXN=103,INF=2e18; ll f[MAXN][MAXN][MAXN]; ll n,a[MAXN],sum; ll x,ans=INF; ll calc(ll k){ ll m=(k-(x-sum)%k)%k; //排除的数之和模k为m if(k==n){ if(m)return INF; return (x-sum)/k; } rep(i,0,n){ rep(j,0,k){ f[0][i][j]=INF; } } f[0][0][0]=0; rep(i,1,n){ rep(j,0,n){ rep(l,0,k){ f[i][0][l]=INF; } } f[i][0][0]=0; rep(j,1,n-k){ rep(l,0,k-1){ f[i][j][l]=min(f[i-1][j][l],f[i-1][j-1][(l-a[i]%k+k)%k]+a[i]); } } } if(f[n][n-k][m]>1e9)return INF; return (x-sum+f[n][n-k][m])/k; } int main(){ cin>>n>>x; rep(i,1,n)cin>>a[i],sum+=a[i]; rep(i,1,n){ ans=min(ans,calc(i)); } cout<<ans; return 0; }
/*Jai Shree Ram*/ // Never Give Up #include<bits/stdc++.h> #include<unordered_map> using namespace std; #define ff first #define ss second #define int long long #define pb push_back #define mp make_pair #define pii pair<int,int> #define vi vector<int> #define mii map<int,int> #define umii unordered_map<int,int> #define pqb priority_queue<int> #define pqs priority_queue<int,vi,greater<int> > #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define inf 1000000000000000001 #define ps(x,y) fixed<<setprecision(y)<<x #define mk(arr,n,type) type *arr=new type[n]; #define w(x) int x; cin>>x; while(x--) #define F(i,s,e,j) for(int i=s;i<=e;i+=j) #define mt19937 rng(chrono::steady_clock::now().tjhe_since_epoch().count()); //shuffle(arr,arr+n,rng) void c_p_c() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int a[100]; int dp[100][101][100]; int minim_time(int idx,int n,int s,int k,int left,int x) { if(left==0) { if((x-s)%k!=0) return inf; else return (x-s)/k; } if(idx==n) return inf; if(dp[idx][left][s]!=-1) return dp[idx][left][s]; int op1 = minim_time(idx+1,n,(s+a[idx])%k,k,left-1,x); if(op1!=inf+1) op1-=(s+a[idx])/k; int op2 = minim_time(idx+1,n,s,k,left,x); return dp[idx][left][s] = min(op1,op2); } int32_t main() { c_p_c(); int n,x; cin>>n>>x; for(int i=0;i<n;i++) cin>>a[i]; int ans = inf; for(int k=1;k<=n;k++) { memset(dp,-1,sizeof(dp)); ans = min(ans,minim_time(0,n,0,k,k,x)); } cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; int main() { int x,y,z; int ans; cin >> x >> y >> z; // ans/z < y/x // ans < z*y/x ans = (y*z)/x; if( (ans*1000/z)==(y*1000/x) ) ans--; cout << ans << endl; };
#include <bits/stdc++.h> using namespace std; #define INIT std::ios::sync_with_stdio(false);std::cin.tie(0); #define VAR(type, ...)type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__); // __VA_ARGS__可変引数マクロ template<typename T> void MACRO_VAR_Scan(T& t) { std::cin >> t; } template<typename First, typename...Rest>void MACRO_VAR_Scan(First& first, Rest& ...rest) { std::cin >> first; MACRO_VAR_Scan(rest...); } #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i; #define MAT(type, c, m, n) std::vector<std::vector<type>> c(m, std::vector<type>(n));for(auto& R:c)for(auto& w:R)std::cin>>w; template<typename T>void MACRO_OUT(const T t) { std::cout << t; } template<typename First, typename...Rest>void MACRO_OUT(const First first, const Rest...rest) { std::cout << first << " "; MACRO_OUT(rest...); } #define OUT(...) MACRO_OUT(__VA_ARGS__); #define FOUT(n, dist) std::cout<<std::fixed<<std::setprecision(n)<<(dist); // std::fixed 浮動小数点の書式 / setprecision 浮動小数点数を出力する精度を設定する。 #define SP std::cout<<" "; #define BR std::cout<<"\n"; #define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' '); #define ENDL std::cout<<std::endl; #define FLUSH std::cout<<std::flush; #define ALL(a) (a).begin(),(a).end() #define FOR(w, a, n) for(int w=(a);w<(n);++w) #define REP(w, n) for(int w=0;w<int(n);++w) #define IN(a, x, b) (a<=x && x<b) template<class T> inline T CHMAX(T & a, const T b) { return a = (a < b) ? b : a; } template<class T> inline T CHMIN(T& a, const T b) { return a = (a > b) ? b : a; } template<class T> using V = std::vector<T>; template<class T> using VV = V<V<T>>; using ll = long long; using ull = unsigned long long; using ld = long double; using PAIR = std::pair<int, int>; using PAIRLL = std::pair<ll, ll>; constexpr int INFINT = (1 << 30) - 1; // 1.07x10^ 9 constexpr int INFINT_LIM = (1LL << 31) - 1; // 2.15x10^ 9 constexpr ll INFLL = 1LL << 60; // 1.15x10^18 constexpr ll INFLL_LIM = (1LL << 62) - 1 + (1LL << 62); // 9.22x10^18 constexpr double eps = 1e-7; constexpr int MOD = 1000000007; constexpr double PI = 3.141592653589793238462643383279; template<class T, size_t N> void FILL(T(&a)[N], const T & val) { for (auto& x : a) x = val; } // int a[5] = {1,2,3,4,5}; FILL(a,10); template<class ARY, size_t N, size_t M, class T> void FILL(ARY(&a)[N][M], const T & val) { for (auto& b : a) FILL(b, val); } // 2次元配列でもそのまま使える template<class T> void FILL(std::vector<T> & a, const T & val) { for (auto& x : a) x = val; } // 使い方 vector<int> a(3); FILL(a,10); template<class ARY, class T> void FILL(std::vector<std::vector<ARY>> & a, const T & val) { for (auto& b : a) FILL(b, val); } // 2次元配列でもそのまま使える int main() { INIT; VAR(int,x,y,z) ld ans = (ld)y / (ld)x * (ld)z; if(int(ans) == ans) OUT(ans -1) else OUT(int(ans)) return 0; }
#include<iostream> #include<vector> #include<set> #include<queue> #include<map> #include<algorithm> #include<cstring> #include<string> #include<cassert> #include<cmath> #include<climits> #include<iomanip> #include<stack> #include<unordered_map> #include<bitset> #include<limits> #include<complex> #include<array> #include<numeric> #include<functional> #include<random> using namespace std; #define ll long long #define ull unsigned long long #define rep(i,m,n) for(ll (i)=(ll)(m);i<(ll)(n);i++) #define REP(i,n) rep(i,0,n) #define all(hoge) (hoge).begin(),(hoge).end() #define llsize(c) ((ll)c.size()) typedef pair<ll, ll> P; constexpr long double m_pi = 3.1415926535897932L; constexpr ll MOD = 1000000007; constexpr ll INF = 1LL << 61; constexpr long double EPS = 1e-10; template<typename T> using vector2 = vector<vector<T>>; template<typename T> using vector3 = vector<vector2<T>>; typedef vector<ll> Array; typedef vector<Array> Matrix; string operator*(const string& s, int k) { if (k == 0) return ""; string p = (s + s) * (k / 2); if (k % 2 == 1) p += s; return p; } 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; } struct Edge {//グラフ int to; ll w; ll k; Edge(int _to, ll _w, ll _k) { to = _to; w = _w; k = _k; } }; typedef vector<Edge> Edges; typedef vector<Edges> Graph; void add_edge(Graph& G, int from, int to, ll w, ll k) {//最大フロー求める Ford-fulkerson G[from].push_back(Edge(to, w, k)); } Array Dijkstra(Graph& g, ll s) {//O(|E|log|V|) Array ret(g.size(), INF); ret[s] = 0; priority_queue<P, vector<P>, greater<P>> q; q.push({ ret[s], s }); while (!q.empty()) { auto [d, v] = q.top(); q.pop(); if (ret[v] < d)continue; for (auto e : g[v]) { ll nret = ret[v] + e.w + (e.k - (ret[v]%e.k)) % e.k; if (chmin(ret[e.to], nret)){ q.push({ ret[e.to], e.to }); } } } return ret; } int main() { ios::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0); int N, M; cin >> N >> M; int S, G; cin >> S >> G; S--, G--; Graph g(N); for(int i = 0; i < M; i++){ int a, b; ll t, k; cin >> a >> b >> t >> k; a--, b--; add_edge(g, a, b, t, k); add_edge(g, b, a, t, k); } auto v = Dijkstra(g, S); if(v[G] == INF){ cout << -1 << endl; } else{ cout << v[G] << endl; } return 0; }
#include<cstdio> #define F(i,l,r) for(int i=l,i##_end=r;i<i##_end;++i) using namespace std; const int N=2e5+5; template<typename T>void read(T &x) { bool neg=false; unsigned char c=getchar(); for(;(c^48)>9;c=getchar())if(c=='-')neg=true; for(x=0;(c^48)<10;c=getchar())x=(x<<3)+(x<<1)+(c^48); if(neg)x=-x; } int n,f[N][8],b=1; char s[N],x[N]; int main() { read(n);scanf("%s%s",s,x); F(i,0,n/2)s[i]^=s[n-1-i]^=s[i]^=s[n-1-i]; F(i,0,n/2)x[i]^=x[n-1-i]^=x[i]^=x[n-1-i]; f[0][0]=1; F(i,0,n) { int t=(s[i]-'0')*b%7; if(x[i]=='A')F(j,0,7)f[i+1][j]=f[i][j]&&f[i][(j+t)%7]; else F(j,0,7)f[i+1][j]=f[i][j]||f[i][(j+t)%7]; b=b*10%7; } puts(f[n][0]?"Takahashi":"Aoki"); return 0; }
// Author:- Pratik Kinger // Birla Institute of Technology #include <bits/stdc++.h> #define ll long long #define pb push_back #define mp make_pair #define pii pair<ll, ll> #define vi vector<ll> #define vii vector<pii> #define mi map<ll, ll> #define mii map<pii, ll> #define f(i, a, b) for (ll i = (ll)a; i < (ll)b; i++) #define rf(i, a, b) for (ll i = (ll)a; i >= (ll)b; i--) #define FIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define all(a) (a).begin(), (a).end() #define fi first #define si second #define sz(x) (ll) x.size() #define endl '\n' #define mod 1000000007 #define mset(m, v) memset(m, v, sizeof(m)) using namespace std; const ll MOD = 1000000000 + 7; //------------------------------CODE--HERE-------------------------- //----------global--variables------------------- //------------end------------------------------- void solve() { int n; cin>>n; if(n == 1) cout<<0<<endl; else { cout<<n-1<<endl; } } //------------------------------ int main() { //FAST INPUT OUTPUT FIO; //INPUT OUTPUT #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t; t = 1; while (t--) { solve(); } return 0; }
#include<bits/stdc++.h> using namespace std; #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL) int main() { fastio; int n; cin>>n; cout<<n-1<<"\n"; 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 */ const int MAXN = 1e5 + 1, K = 20; long long st[MAXN][K + 1]; int Log[MAXN + 1]; void initialize() { Log[1] = 0; for (int i = 2; i <= MAXN; i++) Log[i] = Log[i / 2] + 1; } void preprocess(int N, vector<int> &array) { for (int i = 0; i < N; i++) st[i][0] = array[i]; for (int j = 1; j <= K; j++) for (int i = 0; i + (1 << j) <= N; i++) st[i][j] = min(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]); } int Min(int L, int R) { int j = Log[R - L + 1]; return min(st[L][j], st[R - (1 << j) + 1][j]); } void solve() { int n; cin >> n; vector<int> arr(n); for(int &x: arr) cin >> x; initialize(); preprocess(n, arr); vector<int> ans(n + 1 , 0); F(int, i, 0, n - 1, 1){ int l = 0, r = i; while(l <= r){ int mid = (l + r) >> 1; int cons = Min(mid, i); if(cons == arr[i]){ r = mid - 1LL; }else{ l = mid + 1LL; } } int go_l = r + 1LL; l = i, r = n - 1LL; while(l <= r){ int mid = (l + r) >> 1; int cons = Min(i, mid); if(cons == arr[i]){ l = mid + 1LL; }else{ r = mid - 1LL; } } int go_r = l - 1LL; ans[go_r - go_l + 1LL] = max(ans[go_r - go_l + 1LL], arr[i]); } int ac = 0; F(int, l, 1, n, 1){ ac = max(ac, ans[l] * l); } cout << ac; } 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; using ll = long long; const int MAX_N = 1e4+2; int n; ll a[MAX_N]; void solve() { ll ans = 0; for(int i=0;i<n;++i){ ll mi = 1e6; for(int j=i;j<n;++j){ mi=min(mi, a[j]); ans=max(ans,1LL*(j-i+1)*mi); } } cout<<ans<<'\n'; } int main() { cin >> n; for(int i=0;i<n;++i)cin >> a[i]; solve(); return 0; }
#include <bits/stdc++.h> using namespace std; //begin of def #define fastio ios_base::sync_with_stdio(false);cin.tie(0) #define endl '\n' using lli = long long int; using ulli = unsigned long long int; using Ld = long double; using pii = pair<int, int>; using pll = pair<lli, lli>; using pld = pair<Ld, Ld>; #define X first #define Y second #define rep(I, S, E) for(int I = (S); I < (E); I++) #define repq(I, S, E) for(int I = (S); I <= (E); I++) #define pb push_back #define epb emplace_back #define ALL(X) X.begin(), X.end() //end of def vector<lli> v; int main(){ fastio; vector<lli> p; lli test = 1; repq(i, 2, 50){ bool f = true; rep(j, 2, i){ if(i % j == 0){ f = false; break; } } if(f){ p.pb(i); test *= i; } } v.resize(p.size()); int n; cin >> n; rep(i, 0, n){ int k; cin >> k; rep(j, 0, p.size()){ if(k % p[j] == 0) v[j] |= (1LL << i); } } lli mn = 4e18; rep(t, 1, 1LL << p.size()){ lli x = 0, mul = 1; rep(j, 0, p.size()){ if(t & (1LL << j)){ x |= v[j]; mul *= p[j]; } } if(x == (1LL << n) - 1){ mn = min(mn, mul); } } cout << mn; return 0; }
#include <bits/stdc++.h> using namespace std; unsigned long long p[] = {0, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47}, n, a[55]; unsigned long long ans = 614889782588491410LL; void dfs(unsigned long long x, unsigned long long y){ if(x > 15){ unsigned long long ret = 0; for(unsigned long long i = 1; i <= n; i++) ret += __gcd(1LL * a[i], y) > 1; if(ret == n) ans = min(ans, y); return; } y *= p[x], dfs(x + 1, y), y /= p[x], dfs(x + 1, y); } int main(){ cin >> n; for(unsigned long long i = 1; i <= n; i++) cin >> a[i]; dfs(1, 1LL); cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define lg long long int #define loop(i, s, e) for (lg i = s; i <= e; i++) #define iloop(i, s, e) for (lg i = e; i >= s; i--) #define pb push_back #define mp make_pair #define mod 1000000007 using namespace std; lg min(lg a, lg b) { return a < b ? a : b; } lg max(lg a, lg b) { return a > b ? a : b; } lg lcm(lg a, lg b) { return (a * b) / __gcd(a, b); } lg ans = 0; lg n, m; bool sortfn(vector<lg> &a, vector<lg> &b) { return a[0] > b[0]; } lg sol(vector<string> &grid, vector<vector<lg>> &dp, lg i, lg j) { if (i == n - 1 && j == m - 1) return 1; else if (dp[i][j] != -1) return dp[i][j]; else { lg total = 0; for (lg in = i + 1; i < n; i++) { if (grid[in][j] == '#') break; total += sol(grid, dp, in, j); total %= mod; } for (lg jn = j + 1; j < m; j++) { if (grid[i][jn] == '#') break; total += sol(grid, dp, i, jn); total %= mod; } for (lg k = 1; k < min(n - i, m - j); k++) { if (grid[i + k][j + k] == '#') break; total += sol(grid, dp, i + k, j + k); total %= mod; } dp[i][j] = total % mod; return dp[i][j]; } } vector<lg> nums(11, 0); bool possible(lg n) { string s = to_string(n); vector<lg> local(11, 0); for (lg i = 0; i < s.length(); i++) { if(s[i] - 48 == 0) return false; local[s[i] - 48]++; } local[0]+=max(3-s.length(),0); for (lg i = 0; i < 10; i++) { if (local[i] > nums[i]) return false; } return true; } int main() { string s; cin >> s; lg l = s.length(); for (lg i = 0; i < l; i++) { nums[s[i] - 48]++; } nums[0]+=max(3-s.length(),0); bool poss = false; for (lg i = 0; i < 1000; i += 8) { if (possible(i)) { poss = true; break; } } if (poss) cout << "Yes" << endl; else cout << "No" << endl; }
#include <bits/stdc++.h> using namespace std; string s; int f[10]; int main() { ios::sync_with_stdio(0); cin >> s; memset(f, 0, sizeof(f)); for(int i = 0; i < s.size(); i++) f[s[i] - '0']++; if(s.size() == 2) { int d1 = (s[0] - '0') * 10 + (s[1] - '0'); int d2 = (s[1] - '0') * 10 + (s[0] - '0'); if(d1 % 8 == 0 || d2 % 8 == 0) cout << "Yes" << endl; else cout << "No" << endl; return 0; } if(s.size() == 1) { if(s == "8") cout << "Yes" << endl; else cout << "No" << endl; return 0; } for(int i = 112; i < 1000; i += 8) { int d1 = i / 100; int d2 = i / 10 % 10; int d3 = i % 10; int t[10]; for(int i = 0; i <= 9; i++) t[i] = f[i]; if(t[d1] > 0) t[d1]--; else continue; if(t[d2] > 0) t[d2]--; else continue; if(t[d3] <= 0) continue; cout << "Yes" << endl; return 0; } cout << "No" << endl; return 0; }
// Problem : C - Collinearity // Contest : AtCoder - AtCoder Beginner Contest 181 // URL : https://atcoder.jp/contests/abc181/tasks/abc181_c // Memory Limit : 1024 MB // Time Limit : 2000 ms // Powered by CP Editor (https://github.com/cpeditor/cpeditor) //#pragma GCC optimize("Ofast") //#pragma GCC optimize ("unroll-loops") //#pragma GCC target("avx,avx2,fma") #include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define eb emplace_back #define pb push_back #define size(s) (int)s.size() #define int long long #define INF 1000000000000000000 #define vi vector<int> #define vs vector<string> #define vv vector<vector<int>> #define pii pair<int,int> #define m_p(x,y) make_pair(x,y) #define vp vector<pair<int,int>> #define setbits(x) __builtin_popcountll(x) #define f first #define se second #define inc(v,n,x) v.assign(n,x) #define incd(v,n) v.resize(n) #define iniz(n) memset(n,0,sizeof(n)) #define inin(n) memset(n,-1,sizeof(n)) #define inimi(n) memset(n,0xc0,sizeof(n)) #define inima(n) memset(n,0x3f,sizeof(n)) #define all(v) (v).begin(),(v).end() using namespace std; template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; } template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; } template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; } double pi=acos(-1.0); int md=1e9+7; int dx1[]={0,0,-1,1}; int dy1[]={1,-1,0,0}; const int N=3e5+5; template<class T> T abst(T a) {return a<0?-a:a;} void solve() { int n;cin>>n; vp v(n);cin>>v; bool b=false; //x1 (y2 - y3) + x2 (y3 - y1) + x3 (y1 - y2) =0 for(int i=0;i<n;i++) { for(int j=i+1;j<n;j++) { for(int k=j+1;k<n;k++) { if(v[i].f*(v[j].se-v[k].se)+v[j].f*(v[k].se-v[i].se)+v[k].f*(v[i].se-v[j].se)==0) b=true; } } } if(b) cout<<"Yes"; else cout<<"No"; } int32_t main(){ ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL); int t=1; //cin>>t; for(int i=1;i<=t;i++) { solve(); } return 0; }
#include <algorithm> #include <iostream> #include <map> #include <memory> #include <string> #include <vector> #include "float.h" #define rep(inc, bgn, end) for (int inc = bgn; inc < end; ++inc) #define repe(inc, bgn, end) for (int inc = bgn; inc <= end; ++inc) #define INT_MAX 1000000000 using ll = long long; using namespace std; // int main() { int N; cin >> N; struct Point { int x; int y; }; vector<Point> points(N); rep(idx, 0, N) { cin >> points[idx].x >> points[idx].y; } rep(fstIdx, 0, N) { Point fstVal = points[fstIdx]; rep(scdIdx, fstIdx + 1, N) { Point scdVal = points[scdIdx]; rep(thdIdx, scdIdx + 1, N) { Point thdVal = points[thdIdx]; auto level1 = fstVal.x == scdVal.x ? FLT_MAX : (fstVal.y - scdVal.y) / (float)(fstVal.x - scdVal.x); auto level2 = fstVal.x == thdVal.x ? FLT_MAX : (fstVal.y - thdVal.y) / (float)(fstVal.x - thdVal.x); if (level1 == level2) { cout << "Yes" << endl; return 0; } } } } cout << "No" << endl; return 0; }
#include<bits/stdc++.h> using namespace std; int main() { int n; double d,h; cin>>n>>d>>h; double x[n]; double y[n]; for(int i=0;i<n;i++) { cin>>x[i]>>y[i]; } double ymin=INT_MAX; for(int i=0;i<n;i++) { bool nope=false; double yc; for(int j=0;j<n;j++) { yc=((h-y[i])/(d-x[i]))*(x[j]-x[i]) + y[i]; if(yc-y[j] < 0){ nope=true; break; } } if(!nope) { yc=y[i]-((h-y[i])/(d-x[i]))*(x[i]); if(ymin>yc) ymin=yc; } } if(ymin<0) ymin=0.0; cout<<ymin<<endl; }
#include<bits/stdc++.h> #define pb push_back #define endl ("\n") #define mp make_pair #define lb lower_bound #define int long long #define up upper_bound #define M 1000000007LL #define yy cout<<"Yes"<<endl; #define nn cout<<"No"<<endl; #define rep(i, a, n) for (int i = a; i < n; i++) #define mod 1000000007 using namespace std; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; t = 1; // cin >> t; while (t--) { int n, du, hu; cin >> n >> du >> hu; int d[n], h[n]; double ans = M; rep(i, 0, n) { cin >> d[i] >> h[i]; ans = min(ans, (hu - h[i]) / (du - d[i] + 0.0)); } cout << (max(0.0, hu - ans * du)); } return 0; }
#include <bits/stdc++.h> using namespace std; #define for0(i, n) for (int i = 0; i < (int)(n); i++) #define for1(i, n) for (int i = 1; i <= (int)(n); i++) #define forc(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i) #define forr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i) #define forr1(i, n) for (int i = (int)(n); i >= 1; --i) #define deb(x) cout << #x << "=" << x << endl #define ff first #define ss second #define pb push_back #define mp make_pair #define all(x) x.begin(), x.end() #define sortall(x) sort(all(x)) #define tr(x) for(auto it = x.begin(); it != x.end(); it++) #define fast ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #define printclock cerr<< "Time : "<< 1000*(ld) clock()/(ld)CLOCKS_PER_SEC<< "ms\n"; #define READ(f) freopen(f, "r", stdin) #define WRITE(f) freopen(f, "w", stdout) #define inf 1e18 #define mod 1e9 + 7 void dk_98() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } long long lpf[1000001], mobius[1000001]; void least_prime_factor() { for (long long i = 2; i <= 1000000; i++) if (!lpf[i]) for (long long j = i; j <= 1000000; j += i) if (!lpf[j]) lpf[j] = i; } void Mobius() { for (long long i = 1; i <= 1000000; i++) { if (i == 1) mobius[i] = 1; else { if (lpf[i / lpf[i]] == lpf[i]) mobius[i] = 0; else mobius[i] = -1 * mobius[i / lpf[i]]; } } } long long gcd_pairs(long long a[], long long n) { long long maxi = 0; long long fre[1000001] = { 0 }; for (long long i = 0; i < n; i++) { fre[a[i]]++; maxi = max(a[i], maxi); } least_prime_factor(); Mobius(); long long ans = 0; for (long long i = 1; i <= maxi; i++) { if (!mobius[i]) continue; long long temp = 0; for (long long j = i; j <= maxi; j += i) temp += fre[j]; ans += temp * (temp - 1) / 2 * mobius[i]; } return ans; } void solve() { long long l, r; cin >> l >> r; long long a[r - l + 1]; for (long long i = l; i <= r; i++) a[i - l] = i; long long val = gcd_pairs(a, r - l + 1); val *= 2; long long n = r - l + 1; long long total = n * n - n; total -= val; for (long long i = l; i <= r; i++) { if (i == 1) continue; long long what = r / i; total -= (what - 1) * 2; } cout << total << '\n'; } int main() { fast; dk_98(); int t = 1; //cin >> t; while (t--) { solve(); } }
#include<iostream> #include<string> #include<vector> #include<stack> #include<queue> #include<set> #include<map> #include<algorithm> #include<numeric> #include<cmath> #include<iomanip> #include<regex> using namespace std; #define int long long const int mod=1e9+7; bool pri[1000001],squf[1000001],even[1000001]; signed main(){ int l,r; cin>>l>>r; for(int i=2;i<=r;i++) pri[i]=squf[i]=even[i]=1; for(int i=2;i<=r;i++){ if(!pri[i]) continue; for(int j=i;j<=r;j+=i){ if(j!=i) pri[j]=0; even[j]=!even[j]; } for(int j=i*i;j<=r;j+=i*i) squf[j]=0; } int ans1=0,ans2=0; for(int g=2;g<=r;g++){ if(!squf[g]) continue; int a=r/g-(l-1)/g; a=a*(a-1)/2; if(even[g]) ans1-=a; else ans1+=a; } for(int g=max(2ll,l);g<=r;g++) ans2+=r/g-1; cout<<(ans1-ans2)*2<<endl; }
#include "bits/stdc++.h" using namespace std; int main() { string s; cin >> s; int ans = 0; const std::string find_word("ZONe"); std::string::size_type pos = s.find(find_word); while (pos != std::string::npos) { ans++; // std::cout << pos << std::endl; pos = s.find(find_word, pos + find_word.length()); } cout << ans << endl; }
#include<bits/stdc++.h> using namespace std; #define endl '\n' typedef long long int ll; #define sim template < class c #define ris return * this #define dor > debug & operator << #define eni(x) sim > typename \ enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...); struct debug { #ifdef LOCAL ~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for(auto it = d.b;it != d.e;++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } #else sim dor(const c&) { ris; } #endif }; #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " ll binom(ll n, ll k){ if(k == 0)return 1; vector<bool> down(12, false); ll up = 1; for(ll i = n;i > k;i--){ up *= i; for(ll j = 2;j <= 11;j++){ if(!down[j] && up % j == 0){ up /= j; down[j] = true; } } } for(ll i = 2;i <= 11;i++){ if(down[i])continue; up /= i; } return up; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); ll n;cin >> n; cout << binom(n - 1, n - 12) << endl; }
#include <bits/stdc++.h> #define int long long using namespace std; const int mod = 10; const int MAX=1e6+10; const int INF=0x3f3f3f3f; int fastPow(int a,int n){ int base=a; int res=1; while(n){ if(n&1){ res=(base*res)%4; } base=(base*base)%4; n=n>>1; } return res; } int a2[10]={0,2,4,8,6}; int a3[10]={0,3,9,7,1}; int a7[10]={0,7,9,3,1}; int a8[10]={0,8,4,2,6}; void solve() { int a,b,c; cin>>a>>b>>c; a=a%10; if(a==0||a==1||a==5||a==6){ cout<<a; return; } if(a==2||a==3||a==7||a==8){ int yu=fastPow(b,c); if(yu==0)yu=4; if(a==2){ cout<<a2[yu]; } if(a==3){ cout<<a3[yu]; } if(a==7){ cout<<a7[yu]; } if(a==8){ cout<<a8[yu]; } } if(a==4||a==9){ if(a==4){ if(b%2==0){ cout<<6; }else{ cout<<4; } } if(a==9){ if(b%2==0){ cout<<1; }else{ cout<<9; } } } } signed main() { //ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); int _ = 1; //cin >> _; while (_--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { unsigned long a,b,c,n,l,m,result; cin >> a >> b >> c ; n = ((a*(a + 1)/2%998244353))%998244353; l = ((b*(b + 1)/2%998244353))%998244353; m = ((c*(c + 1)/2%998244353))%998244353; result = ((n*l%998244353)*m)%998244353; cout << result << endl; }