code_file1
stringlengths
87
4k
code_file2
stringlengths
85
4k
#include <iostream> #include <chrono> #include <string> #include <vector> #include <algorithm> class DNA { private: char base[20][20]; public: void inputV(const int& i, const int& j, const std::string& s) { for (int k = 0; k < (int)s.size(); k++) { if (i + k < 20) base[i + k][j] = s[k]; else base[i + k - 20][j] = s[k]; } } void inputH(const int& i, const int& j, const std::string& s) { for (int k = 0; k < (int)s.size(); k++) { if (j + k < 20) base[i][j + k] = s[k]; else base[i][j + k - 20] = s[k]; } } void output() { for (int i = 0; i < 20; i++) { for (int j = 0; j < 20; j++) { std::cout << base[i][j]; } std::cout << std::endl; } } bool search(const std::string& s) { for (int i = 0; i < 20; i++) { for (int j = 0; j < 20; j++) { if (base[i][j] != s[0]) continue; else { for (int k = 0; k < (int)s.size(); k++) { if (i + k < 20) { if (base[i + k][j] != s[k]) break; } else if (base[i + k - 20][j] != s[k]) break; if (k == (int)s.size()) return true; } for (int k = 0; k < (int)s.size(); k++) { if (j + k < 20) { if(base[i][j + k] != s[k]) break; } else if (base[i][j + k - 20] != s[k]) break; if (k == (int)s.size()) return true; } } } } return false; } //constructor DNA() { for (int i = 0; i < 20; i++) { for (int j = 0; j < 20; j++) { base[i][j] = '.'; } } } }; int main() { DNA alien; int m; std::cin >> m >> m; std::vector<std::pair<int, std::string>> sequences(m, { 0, "" }); for (int i = 0; i < m; i++) { std::cin >> sequences[i].second; sequences[i].first = (int)sequences[i].second.size(); } sort(sequences.begin(), sequences.end()); int i = -1; int now = 0; while(now < 20) { int cnt = 0; while (cnt < 20) { i++; if (i >= (int)sequences.size()) break; if (sequences[i].first + now > 20) break; if (alien.search(sequences[i].second)) continue; alien.inputH(cnt, now, sequences[i].second); cnt++; } if (sequences[i].first + now > 20) break; if (i >= (int)sequences.size()) break; now += sequences[i].first; } alien.output(); return 0; }
#pragma GCC optimize("Ofast") #define _USE_MATH_DEFINES #include "bits/stdc++.h" using namespace std; using ll = int64_t; using ld = long double; using vi = vector<int>; using vl = vector<ll>; using vvi = vector<vector<int>>; using pii = pair<int, int>; using pll = pair<ll, ll>; using vpii = vector<pii>; using vpll = vector<pll>; constexpr char newl = '\n'; constexpr double eps = 1e-10; #define FOR(i,a,b) for (int i = (a); i < (b); i++) #define F0R(i,b) FOR(i,0,b) #define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--) #define RF0(i,b) RFO(i,0,b) #define show(x) cout << #x << " = " << x << '\n'; #define rng(a) a.begin(),a.end() #define rrng(a) a.rbegin(),a.rend() #define sz(x) (int)(x).size() #define YesNo {cout<<"Yes";}else{cout<<"No";} #define YESNO {cout<<"YES";}else{cout<<"NO";} #define v(T) vector<T> #define vv(T) vector<vector<T>> template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; } template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; } template<class T> bool lcmp(const pair<T, T>& l, const pair<T, T>& r) { return l.first < r.first; } template<class T> istream& operator>>(istream& i, v(T)& v) { F0R(j, sz(v)) i >> v[j]; return i; } template<class A, class B> istream& operator>>(istream& i, pair<A, B>& p) { return i >> p.first >> p.second; } template<class A, class B, class C> istream& operator>>(istream& i, tuple<A, B, C>& t) { return i >> get<0>(t) >> get<1>(t) >> get<2>(t); } template<class T> ostream& operator<<(ostream& o, const pair<T, T>& v) { o << "(" << v.first << "," << v.second << ")"; return o; } template<class T> ostream& operator<<(ostream& o, const vector<T>& v) { F0R(i, v.size()) { o << v[i] << ' '; } o << newl; return o; } template<class T> ostream& operator<<(ostream& o, const set<T>& v) { for (auto e : v) { o << e << ' '; } o << newl; return o; } template<class T1, class T2> ostream& operator<<(ostream& o, const map<T1, T2>& m) { for (auto& p : m) { o << p.first << ": " << p.second << newl; } o << newl; return o; } #if 1 template <class NUM> class BIT { public: BIT(int size) : vc(size) { } // 0 <= index < size void Add(NUM v, int index) { assert(0 <= index && index < vc.size()); index++; for (; index <= vc.size(); index += index & -index) { vc[index - 1] += v; } } // [0, r) NUM Sum(int r) { NUM s = 0; if (r < 0) return 0; if (r > vc.size()) r = vc.size(); for (; r; r -= r & -r) { s += vc[r - 1]; } return s; } // [l, r) NUM Sum(int l, int r) { return Sum(r) - Sum(l); } protected: vector<NUM> vc; private: }; // INSERT ABOVE HERE signed main() { cin.tie(0); ios_base::sync_with_stdio(false); int N; cin >> N; BIT<int> bit(N); vi as(N); ll s = 0; F0R(i, N) { cin >> as[i]; bit.Add(1, as[i]); s += bit.Sum(as[i] + 1, N); } F0R(k, N) { cout << s << newl; s -= as[k]; s += N - as[k] - 1; } } #endif
//@formatter:off #include<bits/stdc++.h> #define rep(i,n) for (int i = 0; i < int(n); ++i) #define rrep(i,n) for (int i = int(n)-1; i >= 0; i--) #define rep2(i,s,n) for (int i = int(s); i < int(n); ++i) #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define pb push_back #define eb emplace_back #define vi vector<int> #define vvi vector<vector<int>> #define vl vector<ll> #define vvl vector<vector<ll>> #define vd vector<double> #define vvd vector<vector<double>> #define vs vector<string> #define vc vector<char> #define vvc vector<vector<char>> #define vb vector<bool> #define vvb vector<vector<bool>> #define vp vector<P> #define vvp vector<vector<P>> using namespace std; using ll = long long; using P = pair<int,int>; using LP = pair<ll,ll>; template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; } template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; } template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; } template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?"":","); return os<<']'; } void Yes(bool b) { cout << (b ? "Yes" : "No") << '\n'; } void YES(bool b) { cout << (b ? "YES" : "NO") << '\n'; } template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;} template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;} const int inf = 1001001001; const ll linf = 1001001001001001001; //@formatter:on constexpr int mod = 1000000007; //constexpr int mod = 998244353; struct mint { ll x; constexpr mint(ll x = 0) : x((x % mod + mod) % mod) {} constexpr mint operator-() const { return mint(-x); } constexpr mint &operator+=(const mint &a) { if ((x += a.x) >= mod) x -= mod; return *this; } constexpr mint &operator++() { return *this += mint(1); } constexpr mint &operator-=(const mint &a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } constexpr mint &operator--() { return *this -= mint(1); } constexpr mint &operator*=(const mint &a) { (x *= a.x) %= mod; return *this; } constexpr mint operator+(const mint &a) const { mint res(*this); return res += a; } constexpr mint operator-(const mint &a) const { mint res(*this); return res -= a; } constexpr mint operator*(const mint &a) const { mint res(*this); return res *= a; } constexpr mint pow(ll t) const { mint res = mint(1), a(*this); while (t > 0) { if (t & 1) res *= a; t >>= 1; a *= a; } return res; } // for prime mod constexpr mint inv() const { return pow(mod - 2); } constexpr mint &operator/=(const mint &a) { return *this *= a.inv(); } constexpr mint operator/(const mint &a) const { mint res(*this); return res /= a; } }; ostream &operator<<(ostream &os, const mint &a) { return os << a.x; } void solve() { int n, a, b; cin >> n >> a >> b; if (a < b) swap(a, b); mint ans = mint(n - a + 1) * (n - a + 1); ans *= mint(n - b + 1) * (n - b + 1); mint m = 0; mint l = n - a + 1; m += l * (a - b + 1); int mx = min(b - 1, n - a); m += (l - 1 + l - mx) * mx; m *= m; ans -= m; cout << ans << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int t; cin >> t; rep(i, t) solve(); }
#include <bits/stdc++.h> using namespace std; #define ll long long #define fr(i,j,k) for(int i=j;i<k;i++) #define f(n) fr(i,0,n) #define f1(n) fr(i,1,n+1) #define pb push_back #define F first #define S second #define all(x) x.begin(), x.end() const int mod = 998244353; const int maxn = 400005; int dp[3005][3005]; int solve(int n, int k) { //cout << n <<' '<<k<<endl; //system("PAUSE"); if (n <= k) { return (n == k); } if (~dp[n][k]) { return dp[n][k]; } if (!k) { return 0; } return dp[n][k] = (solve(n - 1, k - 1) + solve(n, k * 2)) % mod; } void go() { int n, k; cin >> n >> k; memset(dp, -1, sizeof(dp)); cout << solve(n, k) << '\n'; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int c = 0; int t; if (!c) { t = 1; } else { cin >> t; } while (t--) { go(); } }
#include <bits/stdc++.h> using namespace std; const int inf=1e9; int n, m, k, x, y; int dist[17][100001]; int dp[17][131072]; int c[17]; int solve(int last, int mask) { if (__builtin_popcount(mask)==1) return 0; if (dp[last][mask]!=0) return dp[last][mask]; int ans=inf; for (int i=0; i<k; i++) { if (i!=last && mask&(1<<i)) { int t=solve(i, mask^(1<<last)); ans=min(ans, t+dist[last][c[i]]); } } return dp[last][mask]=ans; } int main() { cin>>n>>m; vector<int> v[n+1]; for (int i=0; i<m; i++) { cin>>x>>y; v[x].push_back(y); v[y].push_back(x); } cin>>k; for (int i=0; i<k; i++) cin>>c[i]; for (int i=0; i<k; i++) { for (int j=1; j<=n; j++) dist[i][j]=inf; queue<int> q; q.push(c[i]); dist[i][c[i]]=0; while (!q.empty()) { int temp=q.front(); q.pop(); int size=v[temp].size(); for (int j=0; j<size; j++) { if (dist[i][v[temp][j]]==inf) { q.push(v[temp][j]); dist[i][v[temp][j]]=dist[i][temp]+1; } } } } for (int i=1; i<k; i++) { if (dist[0][c[i]]==inf) { cout<<"-1\n"; return 0; } } int ans=inf; for (int i=0; i<k; i++) { ans=min(ans, solve(i, (1<<k)-1)); } cout<<ans+1<<'\n'; }
#include <bits/stdc++.h> #define LL long long #define PII pair<int,int> #define PIL pair<int,LL> #define PLI pair<LL,int> #define PIII pair<int,PII> #define PLL pair<LL,LL> #define PLII pair<LL,PII> #define VI vector<int> #define VVI vector<VI> #define VL vector<LL> #define VVL vector<VL> #define VPII vector<PII> #define FF first #define SS second #define MP make_pair #define PB push_back #define all(x) x.begin(),x.end() #define watch(x) cout<<(#x)<<" = "<<(x)<<'\n' #define mset(a,v) memset(a,v,sizeof(a)) #define setp(x) cout<<fixed<<setprecision(x) #define EPS 0.00000000001 #define PI acos(-1) #define loop(i,b,n) for(int i=b;i<n;++i) #define rev_loop(i,b,n) for(int i=b;i>=n;--i) using namespace std; const int MOD = 1e9 + 7; const LL MX = 1e5 + 100; const LL MX1 = 20; const LL INF = 1e9; VI g[MX], mem[MX1]; int k, c[MX1], d[MX1][MX1]; void dp(int i, int v) { if(v + 1 == (1 << k)) { mem[i][v] = 0; return; } int v1; mem[i][v] = INF; loop(j,0,k) { if(!(v & (1 << j))) { v1 = v | (1 << j); if(mem[j][v1] == -1) dp(j,v1); mem[i][v] = min(mem[i][v], mem[j][v1] + d[i][j]); } } } bool bfs(int s, int id) { queue<int> q; int dis[MX]; mset(dis,-1); dis[s] = 0; q.push(s); while(!q.empty()) { int u = q.front(); q.pop(); for(int v : g[u]) { if(dis[v] == -1) { dis[v] = 1 + dis[u]; q.push(v); } } } loop(i,0,k) { if(dis[c[i]] == -1) return false; d[id][i] = dis[c[i]]; } return true; } int main() { //ofstream out("output.txt"); //ifstream in("input.txt"); ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int n, m, u, v; cin>>n>>m; loop(i,0,m) { cin>>u>>v; --u; --v; g[u].PB(v); g[v].PB(u); } cin>>k; loop(i,0,k) {cin>>c[i]; --c[i]; mem[i].resize(1 << (k+1), -1);} int f = 1; loop(i,0,k) { if(!bfs(c[i], i)) {f = 0; break;} } int ans = -1; if(f) { int v; ans = INF; loop(i,0,k) { v = (1 << i); if(mem[i][v] == -1) dp(i,v); ans = min(ans, 1 + mem[i][v]); } } cout<<ans<<'\n'; return 0; }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define eb emplace_back #define unused [[maybe_unused]] #define tempT template<class T> #define ALL(obj) (obj).begin(), (obj).end() #define rALL(obj) (obj).rbegin(), (obj).rend() #define debug(x) cerr << #x << ": " << x << endl #define ans_exit(x) { cout << x << endl; exit(0); } #define ans_return(x) { cout << x << endl; return; } #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define r_rep(i, n) for (int i = (int)(n) - 1; i >= 0; i--) #define reps(i, n, m) for (ll i = (ll)(n); i < (ll)(m); i++) #define r_reps(i, n, m) for (ll i = (ll)(m) - 1; i >= (ll)(n); i--) #define debugarr(a) {cerr << #a << ":"; \ for(auto _e:a){cerr << " " <<_e;} cerr << endl;} using ll unused = long long; using ld unused = long double; using vl unused = vector<ll>; using vvl unused = vector<vl>; using vvvl unused = vector<vvl>; using lp unused = pair<ll, ll>; using lmap unused = map<int, int>; unused constexpr ll MOD = 1e9 + 7; unused constexpr ll INF = 1 << 29; unused constexpr ll LINF = 1LL << 61; unused constexpr int DX[8] = {0, 1, 0,-1, 1, 1,-1,-1}; unused constexpr int DY[8] = {1, 0,-1, 0, 1,-1, 1,-1}; unused inline bool bit(ll b, ll i) { return b & (1LL << i); } unused inline ll ceiv(ll a, ll b) { return (a + b - 1) / b; } unused inline ll mod(ll a, ll m = MOD) { return (a % m + m) % m; } unused inline void modadd(ll &a, ll b, ll m = MOD) { a = mod(a + b, m); } unused inline ll floordiv(ll a, ll b) { return a / b - (a < 0 && a % b); } unused inline ll ceildiv(ll a, ll b) { return floordiv(a + b - 1, b); } tempT unused inline bool in_range(T a, T x, T b) { return a <= x && x < b; } unused inline bool in_range(ll x, ll b) { return in_range(0LL, x, b); } tempT unused bool chmin(T &a, T b) { if(a > b) {a = b; return 1;} return 0; } tempT unused bool chmax(T &a, T b) { if(a < b) {a = b; return 1;} return 0; } int main() { ll n; cin >> n; vl ans(n + 1, 1); reps(i, 1, n + 1) { for(int j = 2 * i; j <= n; j += i) { chmax(ans[j], ans[i] + 1); } } reps(i, 1, n) { cout << ans[i] << " "; } cout << ans.back() << endl; }
#include<algorithm> #include<cstdio> #define MaxN 100500 using namespace std; int n,tn,p[MaxN],c[MaxN]; int main() { scanf("%d",&n); c[1]=1; for (int i=1;i<=n;i++){ if (!c[i])c[p[++tn]=i]=2; for (int j=1;j<=tn&&i*p[j]<=n;j++){ c[i*p[j]]=c[i]+1; if (i%p[j]==0)break; } }for (int i=1;i<=n;i++) printf("%d ",c[i]); return 0; }
#include <bits/stdc++.h> using namespace std; using Graph = vector<vector<long long>>; const long long INF = 1LL <<60; const long long Mo=1000000007; vector<long long> seen; long long dfs(const Graph &G, int v, long long cnt) { seen[v] = cnt; //判定だけならcntをboolに // v から行ける各頂点 next_v について for (auto next_v : G[v]) { if (seen[next_v]>=0) continue; // next_v が探索済だったらスルー dfs(G, next_v, cnt); // 再帰的に探索 } //cout<<grp<<" "<<cnt<<endl; return 0; } long long gcn(long long x,long long y){ if(x%y==0){ return y; } else{ return gcn(y,x%y); } } long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } int main(void){ long long res=0,tmp1,tmp2,cnt,idx,cur,prev; long long flg,fir=1; long long i,j; long long n,m,k,l; string s,t; cin>>n; cin>>s; cin>>t; /* if(n==1 && s[0]!=t[0]){ res=-1; cout<<res<<endl; return 0; } */ for(l=n-1;l>=0;l--){ if(s[l]!=t[l]){ break; } } if(s[l]=='0'){ res=-1; cout<<res<<endl; return 0; } for(i=0;i<l;i++){ if(s[i]!=t[i]){ flg=0; fir=max(fir,i+1); for(j=fir;j<=l;j++){ if(s[j]=='1'){ flg=1; s[j]='0'; res+=(j-i); fir=j+1; if(j==l){ for(k=l-1;k>fir;k--){ l=k; if(s[k]!=t[k]){ break; } } } /* if(s[l]=='0' || s[l]==t[l]){ res=-1; cout<<res<<endl; return 0; }*/ break; } } if(flg==0){ res=-1; cout<<res<<endl; return 0; } } } if(s[i]!=t[i]){ res=-1; } cout<<res<<endl; //cout<<setprecision(15)<<res<<endl; //cout<<res<<endl; return 0; } /* Graph G(n); seen.assign(n,-1); for(i=0; i<m; i++) { cin>>tmp1>>tmp2; tmp1--; tmp2--; G[tmp1].push_back(tmp2); G[tmp2].push_back(tmp1); } */
#include<bits/stdc++.h> using namespace std; int main() { int a,b,c; cin>>a>>b>>c; if(a*a+b*b<c*c) puts("Yes"); else puts("No"); }
#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include<bits/stdc++.h> using namespace std; using ll = long long; using pint = pair<ll,ll>; template<class T> ostream& operator<<(ostream& os, const vector<T> arr){ for(ll i = 0; i < (ll)arr.size(); i++)cout << arr[i] << (i == (ll)arr.size() -1 ? "" : " "); return os;} bool check(vector<ll> A, vector<ll> B, vector<vector<ll>> C) { ll N = A.size(); vector<vector<ll>> D(N, vector<ll>(N)); for(ll i = 0; i < N; i++) { for(ll j = 0; j < N; j++)D[i][j] = A[i] + B[j]; } return D == C; } int main() { ll N; cin >> N; vector<vector<ll>> C(N, vector<ll>(N)); for(ll i = 0; i < N; i++) { for(ll j = 0; j < N; j++) cin >> C[i][j]; } ll pos = 0; ll nin = 2e9;; for(ll i = 0; i < N; i++) { ll val = *min_element(C[i].begin(), C[i].end()); if(val < nin) { nin = val; pos = i; } } vector<ll> B(N), A(N); for(ll i = 0; i < N; i++)B[i] = C[pos][i] - A[pos]; for(ll i = 0; i < N; i++)A[i] = C[i][0] - B[0]; if(!check(A, B, C)) { cout << "No" << endl; return 0; } cout << "Yes" << endl; cout << A << endl; cout << B << endl; }
#include <bits/stdc++.h> #define int long long #define ri register int #define N 505 using namespace std; int n,p,q,a[N],b[N],c[N][N]; template <typename T> inline void read(T &x) { register T f=0,c=getchar(); for (; c<48||57<c; c=getchar()) if (c=='-') f=1; for (x=0; 48<=c&&c<=57; c=getchar()) x=(x<<3)+(x<<1)+(c&15); if (f) x=~(--x); } template <typename T> inline void print(T x) { if (x<0) putchar('-'),x=~(--x); if (x>9) print(x/10); putchar(x%10|48); } signed main() { read(n); for (ri i=1; i<=n; ++i) for (ri j=1; j<=n; ++j) read(c[i][j]); for (ri i=2; i<=n; ++i) a[i]=c[i][1]-c[1][1]; for (ri i=2; i<=n; ++i) for (ri j=2; j<=n; ++j) if (c[j][i]-c[1][i]!=a[j]) return puts("No"),0; for (ri i=2; i<=n; ++i) b[i]=c[1][i]-c[1][1]; for (ri i=2; i<=n; ++i) for (ri j=2; j<=n; ++j) if (c[i][j]-c[i][1]!=b[j]) return puts("No"),0; for (ri i=2; i<=n; ++i) if (a[i]<0&&p>a[i]) p=a[i]; for (ri i=2; i<=n; ++i) if (b[i]<0&&q>b[i]) q=b[i]; if (c[1][1]+p+q<0) return puts("No"),0; puts("Yes"),print(a[1]=-p),putchar(' '); for (ri i=2; i<=n; ++i) print(a[i]+a[1]),putchar(' '); puts(""),print(b[1]=c[1][1]+p),putchar(' '); for (ri i=2; i<=n; ++i) print(b[i]+b[1]),putchar(' '); return 0; }
#include <bits/stdc++.h> #define fo(a,b,c) for (a=b; a<=c; a++) #define fd(a,b,c) for (a=b; a>=c; a--) #define ll long long //#define file using namespace std; int n,i,j,k,l; ll ans,A,B,C,sum[501],sum2[501]; int main() { #ifdef file freopen("a.in","r",stdin); #endif scanf("%d",&n); fo(A,1,500) { fo(B,1,A) if (A*B<=500) { if (A!=B) ++sum[A*B]; } if (A*A<=500) ++sum2[A*A]; } fo(i,1,500) sum[i]+=sum[i-1],sum2[i]+=sum2[i-1]; fo(A,1,n) { if (A<=500) { fo(B,1,A) if (A*B<=n) { fo(C,1,B) if (A*B*C<=n) { if (A>B && B>C) ans+=6; else if (A==B && B==C) ans+=1; else ans+=3; } else break; } } else ans+=sum[n/A]*6+sum2[n/A]*3; } printf("%lld\n",ans); fclose(stdin); fclose(stdout); return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ int K; int NumberOfUnderK = 0; int Multi; int m, n, l, n1, l1; cin >> K; for (m = 1; m <= K; m++){ for (n = 1; n <= K/m; n++){ for (l = 1; l <= K/n; l++){ Multi = m * n * l; if(Multi <= K){ NumberOfUnderK++; } else{ break; } } } } cout << NumberOfUnderK << endl; }
#include<bits/stdc++.h> #define pi 3.141592653589793238 #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #define MOD 1000000007 #define INF 999999999999999999 #define pb push_back #define ff first #define ss second #define mt make_tuple #define ll long long #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); using namespace std; #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// const int N = 5e3 + 1; ll dp[80][N]; ll fac[N]; ll f[N][N]; ll power(ll x, ll y, ll p){ ll res = 1; x = x % p; while (y > 0){ if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } ll modi(ll a, ll m){ return power(a, m - 2, m); } ll nCr(ll n, ll r, ll p){ if (r == 0) return 1; if(f[n][r] != -1){ return f[n][r]; } return f[n][r] = (fac[n] * modi(fac[r], p) % p * modi(fac[n - r], p) % p) % p; } int main() { //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); fast; ll T = 1, i, j; //cin >> T; while (T--) { memset(f, -1, sizeof(f)); ll mod = 998244353; fac[0] = 1; for(i = 1; i < N; i++){ fac[i] = (i * fac[i - 1]) % mod; } ll n, m; cin >> n >> m; ll ofset = 1; dp[0][0] = 1; for(i = -1; i < 14; i++){ for(ll sum = 0; sum <= m; sum++){ for(j = 0; j <= n; j += 2){ if(sum + (1 << (i + 1)) * j > m){ continue; } dp[i + 1 + ofset][sum + (1 << (i + 1)) * j] += dp[i + ofset][sum] * nCr(n, j, mod); dp[i + 1 + ofset][sum + (1 << (i + 1)) * j] %= mod; } } } cout << dp[14][m] << endl; } return 0; }
#include<bits/stdc++.h> #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize("Ofast") using namespace std; inline int read(){ int res=0; bool zf=0; char c; while(((c=getchar())<'0'||c>'9')&&c!='-'); if(c=='-')zf=1; else res=c-'0'; while((c=getchar())>='0'&&c<='9')res=(res<<3)+(res<<1)+c-'0'; if(zf)return -res; return res; } const int maxn=2e5+5,P=998244353; int f[maxn],g[maxn]; int p[maxn],r; int v[maxn],inv[25]; signed main(){ int n=read(),m=read(),ans=1; inv[1]=1; for(register int i=2;i<=20;++i){ inv[i]=1ll*inv[P%i]*(P-P/i)%P; } for(register int i=2,t;i<=m;++i){ if(!v[i]){ f[i]=n,g[i]=1,p[++r]=i; } for(register int j=1;j<=r&&(t=i*p[j])<=m;++j){ v[t]=1; if(i%p[j]){ f[t]=1ll*f[i]*n%P,g[t]=1; } else{ f[t]=1ll*f[i]*(n+g[i])%P*inv[g[i]+1]%P,g[t]=g[i]+1; break; } } ans+=f[i]; (ans>=P)&&(ans-=P); } printf("%d\n",ans); return 0; }
#include<bits/stdc++.h> #include<bits/extc++.h> #define pii pair<int, int> #define F first #define S second using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, greater<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; #define int long long int r[200005], c[200005]; bool done[200005]; signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int h, w, m; cin>>h>>w>>m; int gone=0, both, ans=0; for(int i=1;i<=h;i++) r[i]=w+1; for(int i=1;i<=w;i++) c[i]=h+1; vector<pii> v; for(int i=0;i<m;i++){ int x, y; cin>>x>>y; v.push_back({x, y}); c[y]=min(c[y], x); r[x]=min(r[x], y); } both=(r[1]-1)*(c[1]-1); sort(v.begin(), v.end()); int prev=-1; ordered_set os; for(auto [x, y]:v){ if(x>=c[1] || y>=r[1]) continue; //vertical if(!done[y]) gone+=c[1]-1-x; //horizontal if(x!=prev){ gone+=r[1]-1-y+1; gone-=os.order_of_key(y-1); } //cout<<x<<" "<<y<<" "<<gone<<endl; os.insert(y); done[y]=true; prev=x; } //cout<<gone<<" "; both-=gone; for(int i=1;i<c[1];i++){ ans+=r[i]-1; } for(int i=1;i<r[1];i++){ ans+=c[i]-1; } cout<<ans-both<<endl; }
//Classic //g++ -std=c++11 -O2 -Wall a.cpp -o test #include<bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define vll vector<ll> #define vi vector<int> #define pi pair<int,int> #define vp vector<pi> #define pb push_back #define mp make_pair #define mt make_tuple #define F first #define S second #define For(i,a,b) for(ll i=a;i<b;i++) #define endl "\n" #define debug(x) cout<<"AA Baju Smit------> "<<#x<<" -> "<<x<<endl #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(), x.rend() #define mint map<int,int> #define mod 1000000007 #define ciN cin #define Z(s) get<0>(s) #define O(s) get<1>(s) #define T(s) get<2>(s) //////////////////////////////////////////////////////////////// void jabru() { ll n; cin >> n; ll x; cin >> x; x *= 100; int ind = -1; ll curr = 0; for (int i = 0; i < n; i++) { ll a, b; cin >> a >> b; curr += a * b; if (curr > x && ind == -1)ind = i + 1; } cout << ind << endl; } int main() { ios::sync_with_stdio(0); cin.tie(0); ll t; t = 1; //cin >> t; while (t--) { jabru(); } return 0; } //cout << ans << endl;
#include <iostream> #include <vector> #include <algorithm> int X,Y,Z = 0; int main(void){ std::cin >> X; std::cin >> Y; std::cin >> Z; if((Y*Z)%X == 0) std::cout << int((float(Y)/X)*Z-1); else std::cout << int((float(Y)/X)*Z); }
#include <iostream> using namespace std; int main() { int a,b,c;cin>>a>>b>>c; int ans = max(a+b,max(b+c,a+c)); cout<<ans<<endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define endl "\n" #define ll long long #define pb push_back #define ff first #define ss second #define all(x) x.begin(),x.end() const int mod=1e9+7; const int N=3e5+9; void solve() { int n; cin >> n; string s; cin >> s; int k; cin >> k; int c = 0; while(k--) { int t, a, b; cin >> t >> a >> b; if(t==2) {c++; continue;} if( c % 2 == 0) { swap(s[a-1],s[b-1]); continue; } if(a <= n && b > n) { a += n; b -= n; swap(s[a-1],s[b-1]); continue; } if(b <= n) { a += n; b += n; swap(s[a-1],s[b-1]); continue; } if(a > n) { a -= n; b -= n; swap(s[a-1],s[b-1]); continue; } } if(c%2==0) {cout << s << endl;return;} for(int i = n; i < 2 * n; i++) cout<<s[i]; for(int i = 0; i < n; i++) cout << s[i]; cout << endl; } int main() { IOS; int t = 1; //cin >> t; while(t--) solve(); return 0; }
// This is the start Shubham template// #include<bits/stdc++.h> using namespace std; #define endl "\n" #define int long long int #define mp(a,b) make_pair(a,b) #define ff first #define ss second #define mod 1000000007 #define deg(x) cout<<#x<<" = "<<x<<endl; #define INF LONG_LONG_MAX #define vll vector<int> #define pb push_back #define pll pair<int,int> void input(){ #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif } #define cases int t; cin>>t; while(t--) #define array(a,n) vll a(n); rep(i,0,n) cin>>a[i]; #define all(x) x.begin(),x.end() #define printall(a) rep(i,0,a.size()) cout<<a[i]<<" "; cout<<endl; #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,a,b) for(int i=a;i>=b;i--) //Hers's the end of shubham template void solve(); int lcm (int a,int b); int power(int a,int n); int lcm (int a,int b) { return a*b/(__gcd(a,b)); } int power(int a,int n ) { if(n==0) return 1; if(n%2) return (a*power((a*a)%mod,n/2))%mod; return power((a*a)%mod,n/2); } int Pow(int a,int n ) { // cout<<"HI"; if(n==0) return 1; if(n%2) return (a*power((a*a),n/2)); return a*power((a*a),n/2); } int primes[1000010]={}; void seive() { for(int i = 3;i*i<=1000000;i++) { if(!primes[i]) { for(int j = i*i;j<=1000000;j+=i) primes[i] = 1; } } primes[0] = primes[1] = 1; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); input(); int test; test = 1; while(test--) { int a,b,c; cin>>a>>b>>c; // 10 10 10 if(a*a+b*b<c*c) { cout<<"Yes\n"; } else cout<<"No\n"; } }
#include <iostream> #include <algorithm> #include <tuple> #include <vector> #include <string> #include <queue> #include <cmath> #include <set> #include <map> #include <cassert> using namespace std; using ll = long long; int main() { string s; cin >> s; int len = s.size(); map<char, int> num; vector<char> can; vector<int> res; ll ans = 0; char ko = '1'; for(int i = len-1; i >= 0; i--){ if(i-1 >= 0){ if(s[i-1] == s[i]){ if(ko == '1' || ko == s[i]){ ko = s[i]; }else{ int tmp = num[s[i]]; num.erase(begin(num), end(num)); num[s[i]] = tmp; ko = s[i]; } int tmp = num[s[i]]; num.erase(begin(num), end(num)); num[s[i]] = tmp; ans += (len-1-i)-num[s[i]]; num[s[i]]+= (len-1-i)-num[s[i]]; //cout << "num: " << num[s[i]] << endl; //cout << (len-1-i)-num[s[i]] << endl; } } num[s[i]]++; //cout << "saishuu" << num[s[i]] << endl; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #include<sstream> #include<string> #include<vector> #include <set> #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define pb push_back #define mp make_pair #define ll long long #define ff first #define ss second long long M=1000000007; using namespace std; ll fact[10000]; ll power(ll x, unsigned ll y, unsigned ll m) { if (y == 0) return 1; ll p = power(x, y / 2, m) % m; p = (p * p) % m; return (y % 2 == 0) ? p : (x * p) % m; } unsigned long long modInverse(unsigned long long n, int p) { return power(n, p - 2, p); } unsigned long long nCrModPFermat(unsigned long long n, int r, int p) { // If n<r, then nCr should return 0 if (n < r) return 0; // Base case if (r == 0) return 1; return (fact[n] * modInverse(fact[r], p) % p * modInverse(fact[n - r], p) % p) % p; } int32_t main() { IOS ll n,count=0; cin>>n; ll m=n,cnt=0; while(m>0) { m/=10; cnt++; } for(ll i=4;i<=cnt-1;i++) { count+=(((i+2)/3)-1)*(9*(pow(10,i-1))); } ll u=(n-(pow(10,cnt-1)))+1; count+=(((cnt+2)/3)-1)*(u); cout<<count<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int N; cin >> N; vector<int> A(N); vector<int> B(N); unordered_map<int, bool> mp; for(int i = 0; i < N; i++) { cin >> A[i]; } for(int i = 0; i < N; i++) { cin >> B[i]; } int res = 0; int big, small; vector<int> check; for(int i = 0; i < N; i++) { if(A[i] >= B[i]) big = A[i], small = B[i]; else big = B[i], small = A[i]; if(i == 0) { vector<int> v; for(int j = small; j <= big; j++) { v.push_back(j); } check = v; } else { vector<int> v; for(int j = small; j <= big; j++) { for(auto x: check) { if(j == x) { v.push_back(j); } } } check = v; } } cout << check.size() << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define reps(i, s, n) for (int i = s; i < n; i++) #define per(i, n) for (int i = n - 1; i >= 0; i--) #define pers(i, n, s) for (int i = n - 1; i >= s; i--) #define all(v) v.begin(), v.end() #define fi first #define se second #define pb push_back #define si(v) int(v.size()) #define lb(v, n) lower_bound(all(v), n) #define lbi(v, n) lower_bound(all(v), n) - v.begin() #define ub(v, n) upper_bound(all(v), n) #define ubi(v, n) upper_bound(all(v), n) - v.begin() #define mod 1000000007 #define infi 1010000000 #define infl 1100000000000000000 #define outve(v) \ for (auto i : v) \ cout << i << " "; \ cout << endl #define outmat(v) \ for (auto i : v) \ { \ for (auto j : i) \ cout << j << " "; \ cout << endl; \ } #define in(n, v) \ for (int i = 0; i < (n); i++) \ { \ cin >> v[i]; \ } #define IN(n, m, v) \ rep(i, n) rep(j, m) { cin >> v[i][j]; } #define cyes cout << "Yes" << endl #define cno cout << "No" << endl #define cYES cout << "YES" << endl #define cNO cout << "NO" << endl #define csp << " " << #define outset(n) cout << fixed << setprecision(n); using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; using vi = vector<int>; using vvi = vector<vector<int>>; using vd = vector<double>; using vvd = vector<vector<double>>; using vl = vector<ll>; using vvl = vector<vector<ll>>; using vs = vector<string>; using pii = pair<int, int>; using pll = pair<ll, ll>; template <typename T> using ve = vector<T>; template <typename T> using pq2 = priority_queue<T>; template <typename T> using pq1 = priority_queue<T, vector<T>, greater<T>>; template <typename T> bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <typename T> bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } void solve() { int N; cin >> N; int a[N], b[N]; rep(i, N) { cin >> a[i]; } rep(i, N) { cin >> b[i]; } int max = a[0], min = b[0]; rep(i, N) { if (a[i] > max) max = a[i]; if (b[i] < min) min = b[i]; } if (min < max) cout << 0; else cout << min - max + 1; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); solve(); return 0; }
//#define _GLIBCXX_DEBUG #include <bits/stdc++.h> #define rep(i, n) for(int i=0; i<n; ++i) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() using namespace std; using ll = int64_t; using ld = long double; using P = pair<int, int>; using vs = vector<string>; using vi = vector<int>; using vvi = vector<vi>; template<class T> using PQ = priority_queue<T>; template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >; const int INF = 0xccccccc; const ll LINF = 0xcccccccccccccccLL; template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);} template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);} template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;} template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;} struct UnionFind { vector<int> par; // 親を指すvector,-par[親]は木のサイズ UnionFind(int n):par(n, -1) {} // uniteで親を埋め込んでいく必要あり int root(int x) { // 親をたどる&データの整理 if(par[x] < 0) return x; return par[x] = root(par[x]); } bool unite(int x, int y) { // データの結合 x = root(x); y = root(y); if(x == y) return false; if(par[x] > par[y]) swap(x, y); par[x] += par[y]; par[y] = x; return true; } bool same(int x, int y) {return root(x) == root(y);} // 所属判定 int size(int x) {return -par[root(x)];} // 木のサイズ }; //head #define N 400010 int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vi cnt(N); UnionFind uft(N); rep(i, n) { int a, b; cin >> a >> b; uft.unite(a, b); cnt[a]++; } rep(i, N) if(uft.root(i) != i) cnt[uft.root(i)] += cnt[i]; int ans = 0; rep(i, N) if(uft.root(i) == i) { ans += min(uft.size(i), cnt[i]); } cout << ans << endl; }
#define NOMINMAX #define TEST_MODE true #define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #include "bits/stdc++.h" using namespace std; #define rep(i,n) for(int i=0;i<(int)(n);++i) #define rep2(i,a,b) for(int i=(a);i<(int)(b);++i) #define rrep(i,n) for(int i=(n)-1;i>=0;--i) #define rrep2(i,a,b) for(int i=(a)-1;i>=(int)b;--i) #define range(i,a,b,c) for(int i=a;c>0?i<b:i>b;i+=c) #define chmax(a,b) (a=(a)<(b)?(b):(a)) #define chmin(a,b) (a=(a)>(b)?(b):(a)) #define i1(a) cin>>a; #define i2(a,b) cin>>a>>b; #define i3(a,b,c) cin>>a;i2(b,c); #define i4(a,b,c,d) cin>>a;i3(b,c,d); #define i5(a,b,c,d) cin>>a;i4(b,c,d); #define o1(a) cout<<a<<endl; #define o2(a,b) cout<<a<<" ";p1(b); #define o3(a,b,c) cout<<a<<" ";p2(b, c); #define abp(o,a,b) o1(((o)?a:b)) #define YEP(x) abp(x,"YES","NO") #define Yep(x) abp(x,"Yes","No") #define all(a) begin(a),end(a) #define ifnot(a) if(!(a)) #define int long long #ifdef LOCAL_ENV #if TEST_MODE==true const bool test = true; #define dump(x) cerr<<#x<<" : "<<(x)<< " " #define dumpl(x) dump(x)<<endl #else const bool test = false; #define dump(x) #define dumpl(x) #endif #else const bool test = false; #define dump(x) #define dumpl(x) #endif using ll = int; using ull = unsigned int; using ld = long double; ll dx[] = { 1,0,-1,0 }; ll dy[] = { 0,1,0,-1 }; const ll inf = (ll)1 << 60; const ll undefined = inf; const ll INFL = (ll)1 << 60; ll mod_n = (ll)1e9 + 7; const double eps = 1e-10; typedef long double Real; // return -1, 0, 1 ll sgn(const Real& r) { return(r > eps) - (r < -eps); } ll sgn(const Real& a, const Real& b) { return sgn(a - b); } const ll MAX = (ll)2e5 + 5; const ll MAX2 = (ll)2e3 + 5; vector<string> split(const string& str, char sep) { vector<string> v; stringstream ss(str); string buffer; while (getline(ss, buffer, sep)) v.push_back(buffer); return v; } string join(const vector<string>& v, const string delim = 0) { string s; if (!v.empty()) { s += v[0]; for (decltype(v.size()) i = 1, c = v.size(); i < c; ++i) { if (delim != "")s += delim; s += v[i]; } }return s; } string operator*(const string& s, const ll& n) { string res = ""; rep(i, n)res += s; return res; } #define sum(a) accumulate(all(a),0ll) template<typename T>T gcd(T a, T b) { T c; while (a != 0) { c = a; a = b % a; b = c; }; return b; } #define bit_cnt(n) [](int n){int c=0;while(N){if(N&1)c++;N>>=1;}return c;}; template<typename T>void prll_vec(ostream& o, vector<T> a) { rep(i, a.size() - 1)o << a[i] << " "; o << a.back() << endl; } ll pow_n(ll x, ll n) { ll r = 1; while (n > 0) { if (n & 1)r = r * x; x = x * x; n >>= 1; }return r; } ll H, W; #define grid_ng(y,x) (y<0||y>=H||x<0||x>=W) ll div_ceil(ll a, ll b) { ll r = a / b; if (a % b != 0)r++; return r; } struct Point { ll x, y; bool operator<(const Point& r)const { if (x != r.x)return x < r.x; return y < r.y; } }; int n; class Solver { public: void solve() { int n; i1(n); vector<int> a(n), b(n); rep(i, n) i1(a[i]); rep(i, n) i1(b[i]); int sum = 0; rep(i, n) { sum += a[i] * b[i]; } Yep(sum == 0); } }; signed main() { srand((unsigned int)time(NULL)); cout << fixed << setprecision(20); auto ptr = new Solver(); ptr->solve(); delete ptr; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define f(i, a, b) for (int i = a; i < b; i++) #define pi pair<int, int> #define pb push_back #define mp make_pair #define endl '\n' #define all(v) (v).begin(), (v).end() #define FIO ios_base::sync_with_stdio(0), cin.tie(0) #define fi first #define se second signed main() { FIO; int a, b, w; cin >> a >> b >> w; w *= 1000; int umin = (w + b - 1) / b; int diff = umin * b - w; double div = (diff + 0.0) / umin; if ((b - div) < a) { cout << "UNSATISFIABLE"; return 0; } int umax = w / a; cout << umin << " " << umax; }
/** * author: shu8Cream * created: 22.02.2021 00:37:07 **/ #include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i=0; i<(n); i++) #define all(x) (x).begin(), (x).end() using ll = long long; using P = pair<int,int>; using vi = vector<int>; using vvi = vector<vi>; const int mod = 998244353; struct mint{ ll x; mint(ll x=0):x((x%mod+mod)%mod){} mint operator-() const { return mint(-x);} mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;} mint operator+(const mint a) const { return mint(*this) += a;} mint operator-(const mint a) const { return mint(*this) -= a;} mint operator*(const mint a) const { return mint(*this) *= a;} mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod-2);} mint& operator/=(const mint a) { return *this *= a.inv();} mint operator/(const mint a) const { return mint(*this) /= a;} }; istream& operator>>(istream& is, mint& a) { return is >> a.x;} ostream& operator<<(ostream& os, const mint& a) { return os << a.x;} mint upper[220000]; mint lower[220000]; mint lower2[220000]; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n,m,k; cin >> n >> m >> k; if(n>m) swap(n,m); if(n==1){ cout << mint(k).pow(m) << endl; return 0; } for(int x=1; x<=k; x++) upper[x] = mint(k-x+1).pow(m); for(int x=1; x<=k; x++) lower[x] = mint(x).pow(n); for(int x=1; x<=k; x++) lower2[x] = lower[x] - lower[x-1]; mint ans = 0; for(int x=1; x<=k; x++) ans+=lower2[x]*upper[x]; cout << ans << endl; }
#include<iostream> using namespace std; #define ll long long int int main() { ll n,a; cin>>n; ll sum=0,mx=0,ans=0,dis=0; for(ll i=0;i<n;i++){ cin>>a; sum+=a; mx=max(mx,sum); ans=max(ans,dis+mx); //First check plus the mx value cause after mx value it will decrease dis+=sum; } cout<<ans<<endl; return 0; }
#include<iostream> #include<vector> #include<algorithm> #include <sstream> #include<string> using namespace std; int main() { int n; long long a[5][2 * 100000 + 8] = { 0 },c=0,m=0; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[0][i]; c += a[0][i]; if (a[0][i] >= 0) { a[1][i] += a[1][i - 1] + a[0][i]; a[2][i] = a[2][i - 1]; } else { a[2][i] += a[2][i - 1] + a[0][i]; a[1][i] = a[1][i - 1]; } a[3][i] = a[3][i - 1] + a[1][i] + a[2][i]; if (i == 1) { a[4][1] = a[0][1]; } else { a[4][i] = max(c, a[4][i - 1]); } m = max(m, a[4][i] + a[3][i - 1]); } cout << m << endl; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; const long long INF = 1LL<<60; const double PI = acos(-1.0); /*const double PI = atan2(0.0,-1.0)*/ 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; } #define rep(i, n) for(ll i = 0; i < (ll)(n); i++) #define rep1(i,aa,n) for(ll i = aa; i <= (ll)(n); i++) #define ALL(a) (a).begin(),(a).end() #define ar_init(aa,val) rep(i,aa.size()) aa[i]=val; #define v2d(aa,val1,val2,ini) vector<vector<ll>> aa(val1,vector<ll>(val2,ini)); #define pqe priority_queue<ll> #define pqeg priority_queue<ll,vector<ll>,greater<ll>> #define lcin(...) ll __VA_ARGS__;CINT(__VA_ARGS__) #define eout(...) COU(__VA_ARGS__); #define sout(...) SCOU(__VA_ARGS__); #define scin(...) string __VA_ARGS__;CINT(__VA_ARGS__) #define lb(aa,val) lower_bound(ALL(aa),val) #define pb push_back #define mkp make_pair #define si size() void CINT(){} template <class Head,class... Tail> void CINT(Head&& head,Tail&&... tail){ cin>>head; CINT(move(tail)...); } void COU(){} template <class Head,class... Tail> void COU(Head&& head,Tail&&... tail){ cout<<head<<endl; COU(move(tail)...); } void SCOU(){} template <class Head,class... Tail> void SCOU(Head&& head,Tail&&... tail){ cout<<head<<" "; SCOU(move(tail)...); } template <class T = ll> T IN(){T x;cin>>x;return (x);} using pii = pair<ll,ll>; using v2 = vector<vector<ll>>; using v1 = vector<ll>; using v2p = vector<vector<pii>>; using v1p = vector<pii>; //ll mo=1000000007; ll mo=998244353; ll mod_pow(ll N,ll n){ if(n==0) return 1; ll pp,hh; pp=n/2; hh=n%2; int tt=mod_pow(N,n/2); if(hh==0)return tt%mo*tt%mo; else {return tt%mo*tt%mo*N%mo;} } ll pp[6000][6000]; int main(){ //cout<<fixed<<setprecision(15); lcin(n,m); rep1(i,1,m){ pp[i][0]=1; rep1(k,1,n){ pp[i][k]=pp[i][k-1]*i; pp[i][k]%=mo; } } ll res=0; rep1(i,1,m){ rep1(k,1,n){ if(k+2<=n){res+=pp[m][n-k-2]*(pp[m-i+1][k]-pp[m-i][k])%mo*max((ll)0,n-k+1-2)*(i-1)%mo*(i-1)%mo; } if(k!=n){res+=2*pp[m][max((ll)0,n-k-1)]*(pp[m-i+1][k]-pp[m-i][k])%mo*(i-1)%mo; } if(k==n){res+=pp[m-i+1][k]-pp[m-i][k]; res%=mo; } } } eout(res); }
#include<bits/stdc++.h> using namespace std; int read(){ int x=0;char ch=getchar(); while(!isdigit(ch))ch=getchar(); while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^'0'),ch=getchar(); return x; } const int N=5005,mod=998244353; typedef long long ll; ll dp[N],n,m,cm[N]; int main(){ n=read(),m=read(); cm[0]=1;for(int i=1;i<=n;i++)cm[i]=cm[i-1]*m%mod; ll ans=cm[n]*n%mod; for(int i=1;i<=m;i++)for(int j=1;j<=n;j++)dp[j]=(dp[j-1]*(i-1)%mod+cm[j-1])%mod,ans=(ans-dp[j-1]*cm[n-j]%mod)%mod; cout<<(ans+mod)%mod; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; double pi = 3.141592653589793238; const ll LL_INF_BIG = 1e18 + 7; const ll LL_INF = 1e9 + 7; const int INF = 1e9 + 7; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; template <class T> void chmin(T& a, T b) { if (a > b) a = b; return; } template <class T> void chmax(T& a, T b) { if (a < b) a = b; return; } vector<pair<ll, ll>> prime_factorize(ll N) { vector<pair<ll, ll>> res; for (ll i = 2; i * i <= N; i++) { if (N % i != 0) continue; ll exp = 0; while (N % i == 0) { exp++; N /= i; } res.push_back({i, exp}); } if (N != 1) res.push_back({N, 1}); return res; } ll mod_pow(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; } struct UnionFind { vector<int> parents, siz; UnionFind(int N) : parents(N, -1), siz(N, 1) {} int root(int x) { if (parents.at(x) == -1) return x; return parents.at(x) = root(parents.at(x)); } bool unite(int x, int y) { int rx = root(x); int ry = root(y); if (rx == ry) return false; if (siz.at(rx) > siz.at(ry)) swap(rx, ry); parents.at(rx) = ry; // Update the size only at root. siz.at(ry) += siz.at(rx); return true; } bool same(int x, int y) { int rx = root(x); int ry = root(y); return rx == ry; } // If the size is needed, we need to see it at root. int size(int x) { return siz.at(root(x)); } }; // struct Edge { // ll to; // ll weight; // Edge(ll t, ll w) : to(t), weight(w) {} // }; using Edge = pair<int, pair<int, int>>; using Graph = vector<vector<Edge>>; Graph G; vector<Edge> edge; int N, M; vector<int> A; ll answer = 0; vector<int> answers; vector<int> intervals; void input() { cin >> N >> M; A.resize(M); for (int i = 0; i < M; i++) { int a; cin >> a; // a--; A.at(i) = a; } } void solve() { if(M==0) { answer = 1; return; } sort(A.begin(), A.end()); int minInterval = INF; int firstInterval = A.at(0)-1; if (firstInterval > 0) { chmin(minInterval, firstInterval); intervals.push_back(firstInterval); } for (int i = 1; i < M; i++) { int ival = A.at(i) - A.at(i - 1) - 1; if (ival == 0) continue; chmin(minInterval, ival); intervals.push_back(ival); } int lastInterval = N - A.at(M - 1); if (lastInterval > 0) { chmin(minInterval, lastInterval); intervals.push_back(lastInterval); } int k; k = minInterval; for (int i = 0; i < intervals.size(); i++) { if (intervals.at(i) % k == 0) { answer += intervals.at(i) / k; } else { answer += intervals.at(i) / k; answer++; } } } int main() { ios::sync_with_stdio(false); cin.tie(0); input(); solve(); // cout << fixed << setprecision(3); cout << answer << "\n"; // for (auto answer : answers) cout << answer << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; template <int mod> class Modint { using mint = Modint; static_assert(mod > 0, "Modulus must be positive"); public: static constexpr int get_mod() noexcept { return mod; } constexpr Modint(long long y = 0) noexcept : x(y >= 0 ? y % mod : (y % mod + mod) % mod) {} constexpr int value() const noexcept { return x; } constexpr mint& operator+=(const mint& r) noexcept { if ((x += r.x) >= mod) x -= mod; return *this; } constexpr mint& operator-=(const mint& r) noexcept { if ((x += mod - r.x) >= mod) x -= mod; return *this; } constexpr mint& operator*=(const mint& r) noexcept { x = static_cast<int>(1LL * x * r.x % mod); return *this; } constexpr mint& operator/=(const mint& r) noexcept { *this *= r.inv(); return *this; } constexpr mint operator-() const noexcept { return mint(-x); } constexpr mint operator+(const mint& r) const noexcept { return mint(*this) += r; } constexpr mint operator-(const mint& r) const noexcept { return mint(*this) -= r; } constexpr mint operator*(const mint& r) const noexcept { return mint(*this) *= r; } constexpr mint operator/(const mint& r) const noexcept { return mint(*this) /= r; } constexpr bool operator==(const mint& r) const noexcept { return x == r.x; } constexpr bool operator!=(const mint& r) const noexcept { return x != r.x; } constexpr mint inv() const noexcept { int a = x, b = mod, u = 1, v = 0; while (b > 0) { int t = a / b; std::swap(a -= t * b, b); std::swap(u -= t * v, v); } return mint(u); } constexpr mint pow(long long n) const noexcept { mint ret(1), mul(x); while (n > 0) { if (n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } friend std::ostream& operator<<(std::ostream& os, const mint& r) { return os << r.x; } friend std::istream& operator>>(std::istream& is, mint& r) { long long t; is >> t; r = mint(t); return is; } private: int x; }; using mint = Modint<998244353>; template <typename T> class Combination { public: Combination() = default; Combination(int n) : fact(n + 1), fact_inv(n + 1) { fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i; fact_inv[n] = T(1) / fact[n]; for (int i = n; i > 0; --i) fact_inv[i - 1] = fact_inv[i] * i; } T perm(int n, int r) const { if (r < 0 || n < r) return 0; return fact[n] * fact_inv[n - r]; } T comb(int n, int r) const { if (r < 0 || n < r) return 0; return fact[n] * fact_inv[r] * fact_inv[n - r]; } private: std::vector<T> fact, fact_inv; }; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int N, K; cin >> N >> K; vector<vector<mint>> A(K + 1, vector<mint>(N, 1)); for (int i = 0; i < N; ++i) cin >> A[1][i]; for (int i = 2; i <= K; ++i) { for (int j = 0; j < N; ++j) { A[i][j] = A[i - 1][j] * A[1][j]; } } vector<mint> sum(K + 1); for (int i = 0; i <= K; ++i) { for (int j = 0; j < N; ++j) sum[i] += A[i][j]; } vector<mint> pow2(K + 1, 1); for (int i = 1; i <= K; ++i) pow2[i] = pow2[i-1] * 2; Combination<mint> comb(K + 1); for (int X = 1; X <= K; ++X) { mint ans = 0; for (int i = 0; i <= X; ++i) ans += comb.comb(X, i) * sum[i] * sum[X - i]; ans -= pow2[X] * sum[X]; ans /= 2; cout << ans << "\n"; } }
#include<algorithm> #include<iostream> #include<cstring> #include<cstdio> using std::sort; using std::cout; using std::endl; using std::max; using std::min; inline int read(){ int h=0;char c=getchar(); while(c<'0'||c>'9')c=getchar(); while(c>='0'&&c<='9')h=(h<<1)+(h<<3)+c-'0',c=getchar(); return h; } const int p=998244353; inline int add(int x,int y){return x+y>=p?x+y-p:x+y;} //long long ksm()/ const int MAXN=110; int n; int f[2][110][11111]; int nw=0,lst=1; //前i个物品,A有j个,B有i-j个,A-B为w的方案数。 int id(int x){return x+5001;} int a[MAXN]; long long jc[MAXN]; //int jcn[MAXN]; int main(){ jc[0]=1;for(int i=1;i<=100;i++)jc[i]=jc[i-1]*i%p; n=read();for(int i=1;i<=n;i++)a[i]=read(); f[0][0][id(0)]=1; for(int i=1;i<=n;i++){ std::swap(nw,lst); memset(f[nw],0,sizeof(f[nw])); for(int j=0;j<=i;j++){ for(int d=-5000;d<=5000;d++){ if(d+a[i]<=5000)f[nw][j+1][id(d+a[i])]=add(f[nw][j+1][id(d+a[i])],f[lst][j][id(d)]); if(d-a[i]>=-5000)f[nw][j][id(d-a[i])]=add(f[nw][j][id(d-a[i])],f[lst][j][id(d)]); } } } int ans=0; for(int i=0;i<=n;i++){ ans=(ans+f[nw][i][id(0)]*jc[i]%p*jc[n-i])%p; } printf("%d\n",ans); return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update #define MIN(a, b) (((a) < (b)) ? (a) : (b)) #define MAX(a, b) (((a) < (b)) ? (b) : (a)) //#pragma GCC optimize("O3") using namespace std; using namespace __gnu_pbds; 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); typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int,int> pii; typedef pair<ll,ll> pll; ll n,v[1005],suma,dp[105][20005],aux[105][20005],fact[20005],f[20005],ans; const ll mod=998244353; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>n; fact[0]=1; for(ll i=1;i<=1000;i++) fact[i]=(fact[i-1]*i)%mod; for(int i=1;i<=n;i++) { cin>>v[i]; f[v[i]]++; suma+=v[i]; } sort(v+1,v+n+1); if(suma%2==1) { cout<<0; return 0; } dp[0][0]=1; for(int i=1;i<=n;i++) { for(int j=0;j<=n;j++) for(int s=0;s<=suma;s++) aux[j][s]=dp[j][s]; for(int j=1;j<=n;j++) for(int s=v[i];s<=suma;s++) dp[j][s]=(dp[j][s]+aux[j-1][s-v[i]])%mod; } for(ll j=1;j<=n;j++) { ll k=n-j; ll val=(fact[j]*fact[k])%mod; val=(val*dp[j][suma/2])%mod; /*if(j==n/2&&n%2==0) val=(val*2LL)%mod;*/ ans=(ans+val)%mod; } cout<<ans<<'\n'; return 0; }
#include <bits/stdc++.h> using namespace std; #define f first #define s second #define pb push_back #define mp make_pair #define rep(i, a, b) for (int i = (a); i <= (b); ++i) typedef long long ll; typedef long long unsigned llu; typedef vector<int> vi; typedef pair<int, int> pi; #ifdef _DEBUG ifstream fin("..\\date.in"); #endif vi v = {112, 128, 136, 144, 152, 168, 176, 184, 192, 216, 224, 232, 248, 256, 264, 272, 288, 296, 312, 328, 336, 344, 352, 368, 376, 384, 392, 416, 424, 432, 448, 456, 464, 472, 488, 496, 512, 528, 536, 544, 552, 568, 576, 584, 592, 616, 624, 632, 648, 656, 664, 672, 688, 696, 712, 728, 736, 744, 752, 768, 776, 784, 792, 816, 824, 832, 848, 856, 864, 872, 888, 896, 912, 928, 936, 944, 952, 968, 976, 984, 992}; void solve() { string s, t; llu poz1, poz2, poz3; cin >> s; if (s.length() == 1) { if (s == "8") cout << "Yes"; else cout << "No"; return; } else if (s.length() == 2) { if (s == "16" || s == "24" || s == "32" || s == "48" || s == "56" || s == "64" || s == "72" || s == "88" || s == "96" || s == "61" || s == "42" || s == "23" || s == "84" || s == "65" || s == "46" || s == "27" || s == "69") cout << "Yes"; else cout << "No"; return; } else { for (int i : v) { t = to_string(i); poz1 = s.find(t[0]); if (poz1 == string::npos) continue; if (t[1] == t[0]) { poz2 = s.find(t[1], poz1 + 1); if (poz2 == string::npos) continue; } else { poz2 = s.find(t[1]); if (poz2 == string::npos) continue; } if (t[2] == t[1]) { poz3 = s.find(t[2], poz2 + 1); if (poz3 == string::npos) continue; } else if (t[2] == t[0]) { poz3 = s.find(t[2], poz1 + 1); if (poz3 == string::npos) continue; } else { poz3 = s.find(t[2]); if (poz3 == string::npos) continue; } cout << "Yes"; return; } cout << "No"; return; } } int main() { int t; ios::sync_with_stdio(false); cin.tie(nullptr); t = 1; while (t--) { solve(); } 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() { ll n; cin >> n; ll ans = LINF; for(ll i = 0; i < 61; i++){ if((1ll<<i) > n) continue; ll j = n/(1LL<<i); ll k = n - j*(1ll<<i); ans = min(ans, i + j + k); } cout << ans << endl; return 0; }
#include "iostream" #include "string" #include "algorithm" using namespace std; long long g1(long long n) { string s = to_string(n); sort(s.begin(), s.end(), [](int a, int b){ return a > b; }); return stoll(s); } long long g2(long long n) { string s = to_string(n); sort(s.begin(), s.end()); return stoll(s); } int main() { int k = 0; long long n = 0; cin >> n >> k; for (int i = 0; i < k; i++) { n = g1(n) - g2(n); } cout << n << endl; return 0; }
#include<bits/stdc++.h> using namespace std; int l,r; void check(int &ans,int k,long long x) { int L=1,R=r/k+100; while(L<=R) { int mid=(L+R)>>1; if(mid*k>x&&mid*k<=r) { ans=max(ans,k); return ; } if(mid*k<=x) { L=mid+1; } else { R=mid-1; } } } int solve(int x) { int ans=0; for(int i=1;i*i<=x;i++) { if(x%i==0) { check(ans,x/i,x); check(ans,i,x); } } return ans; } signed main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>l>>r; int ans=0; for(int i=l;i<r;i++) { ans=max(ans,solve(i)); } cout<<ans; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int a,b; ll k; bool sz[100]; ll c[65][65]; void init() { c[0][0]=1; for(int i=1;i<=64;i++) { for(int j=0;j<=i;j++) { if(j==0) c[i][j]=1; else if(j==i) c[i][j]=1; else c[i][j]=c[i-1][j]+c[i-1][j-1]; } } } int main() { init(); cin>>a>>b>>k; int nowa=a; for(int i=1;i<=a+b&&nowa;i++) { if(c[a+b-i][nowa-1]>=k) { sz[i]=1; nowa--; } else { sz[i]=0; k-=c[a+b-i][nowa-1]; } } for(int i=1;i<=a+b;i++) { if(sz[i]==0) cout<<'b'; else cout<<'a'; } return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for(int i = 0; i < (n); i++) #define REPS(i, n) for(int i = 1; i <= (n); i++) #define RREP(i, n) for(int i = (n)-1; i >= 0; i--) #define RREPS(i, n) for(int i = (n); i > 0; i--) #define ALL(v) v.begin(), v.end() #define RALL(v) v.rbegin(), v.rend() #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) #define mp make_pair #define mt make_tuple #define pb push_back #define YES cout << "YES" << endl #define Yes cout << "Yes" << endl #define NO cout << "NO" << endl #define No cout << "No" << endl using ll = long long; using pi = pair<int, int>; using pl = pair<ll, ll>; using vi = vector<int>; using vl = vector<ll>; using vs = vector<string>; using vb = vector<bool>; using vvi = vector<vi>; using vvl = vector<vl>; const int MOD = 1e9 + 7; //const int MOD = 998244353; const int INF = 1e9 + 7; const ll INFL = 1e18; const double PI = 3.14159265359; 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; } ll com(ll n, ll r) { if(n == 0 || r == 0) return 1; ll ret = 1; for(ll i = 1; i <= r; i++) { ret *= n-i+1; ret /= i; } return ret; } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); ll a, b, k; cin >> a >> b >> k; ll s = 0; string ans = ""; ll x = 0, y = 0; REPS(i, a+b-1) { if(x == a || y == b) break; if(k <= s+com(a+b-i, a-(x+1))) { x++; ans.pb('a'); } else { y++; s += com(a+b-i, a-(x+1)); ans.pb('b'); } } cout << ans; REP(i, a-x) cout << 'a'; REP(i, b-y) cout << 'b'; cout << endl; }
#include <bits/stdc++.h> using namespace std; using i16 = short; using u16 = unsigned short; using i32 = int; using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; using f32 = float; using f64 = double; using f80 = long double; using P = pair<int, int>; using vec = vector<int>; using mat = vector<vector<int>>; #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define all(v) v.begin(), v.end() #define endl "\n" constexpr int MOD = 1000000007; constexpr int INF = 1001001001; constexpr bool is_multiple = false; i32 digits_sum(i32 n) { i32 res = 0; while (n > 0) { res += (n % 10); n /= 10; } return res; } void solve() { i32 a, b; cin >> a >> b; cout << max(digits_sum(a), digits_sum(b)) << endl; } int main() { i32 t = 1; if (is_multiple) cin >> t; while (t--) solve(); return 0; }
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < n; i++) using namespace std; using ll = long long; int main() { int a, b; cin >> a >> b; int sum = 0, sumi = 0; rep(i,3) { sum += a % 10; a /= 10; sumi += b % 10; b /= 10; } cout << max(sum, sumi) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<vi> vvi; typedef vector<vll> vvll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<pii> vpii; typedef vector<pll> vpll; typedef vector<vpii> vvpii; typedef vector<vpll> vvpll; #define pb push_back #define mp make_pair #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define sz(x) (int)(x).size() #define fi first #define se second template<class T> bool ckmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;} template<class T> bool ckmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;} namespace debug { void __print(int x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for(auto z : x) cerr << (f++ ? "," : ""), __print(z); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if(sizeof...(v)) cerr << ", "; _print(v...);} #ifdef ljuba #define dbg(x...) cerr << "LINE(" << __LINE__ << ") -> " << "[" << #x << "] = ["; _print(x) #else #define dbg(x...) #endif } using namespace debug; const char nl = '\n'; mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); void solve() { int n; cin >> n; vi v(n); for(auto &z : v) cin >> z; map<int, ll> cnt; ll ans = 0; for(int i = 0; i < n; ++i) { ans += cnt[v[i]%200]; cnt[v[i]%200]++; } cout << ans << nl; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int testCases = 1; //cin >> testCases; while(testCases--) solve(); }
#include <bits/stdc++.h> #define ll long long #define db long double #define x first #define y second #define mp make_pair #define pb push_back #define all(a) a.begin(), a.end() using namespace std; const int mod = 1000000007; void add(int& a, int b) { a += b; if (a >= mod) a -= mod; if (a < 0) a += mod; } int mult(int a, int b) { return a * (ll)b % mod; } int bp(int a, int b) { int res = 1; while (b > 0) { if (b & 1) res = mult(res, a); a = mult(a, a); b >>= 1; } return res; } int main(){ #ifdef LOCAL freopen("A_input.txt", "r", stdin); //freopen("A_output.txt", "w", stdout); #endif ios_base::sync_with_stdio(0); cin.tie(0); int tt; cin >> tt; while (tt--) { string s1, s2, s3; int n; cin >> n >> s1 >> s2 >> s3; int c = 0; if (s1.back() == '1') c = 1; if (s2.back() == '1') c = 1; if (s3.back() == '1') c = 1; if (c == 0) { for (int i = 0; i < n; ++i) cout << '0'; for (int i = 0; i < n; ++i) cout << '1'; } else { for (int i = 0; i < n; ++i) cout << '1'; for (int i = 0; i < n; ++i) cout << '0'; } cout << c; cout << "\n"; } }
#include <bits/stdc++.h> using namespace std; #define ll long long int int main() { vector<ll>v(3); cin>>v[0]>>v[1]>>v[2]; sort(v.begin(),v.end()); if(v[0]!=v[1] and v[1]!=v[2] and v[0]!=v[2])cout<<0; else { if(v[0]==v[1])cout<<v[2]; else cout<<v[0]; } cout<<endl; }
#include<bits/stdc++.h> using namespace std; #define ll long long int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll a,b,c,d; cin>>a>>b>>c>>d; if(c*d==b) { cout<<"-1"; return 0; } ll num=c*d-b; ll ans=(a+num-1)/num; if(ans<=0) { cout<<"-1"; return 0; } cout<<ans; }
#include <bits/stdc++.h> using namespace std ; int N, ans=0; string S, T; vector<int> a, b; int main(){ cin >> N >> S >> T; bool f=true; int x=-1; for(int i=0;i<N;i++){ if(S[i]=='0')a.push_back(i); if(T[i]=='0')b.push_back(i); } if(a.size()!=b.size())puts("-1"); else{ for(int i=0;i<a.size();i++){ if(a[i]!=b[i])ans++; } cout << ans << endl; } return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define mod 1000000007 char p[1000005],q[1000005]; ll pre[1000005]={0},ans=0,pre2[1000005]={0},n; ll solve(ll le,ll ri,ll pos) { if(pos==0) return 0; if(le>=ri) return 0; if(le==ri-1) { ans+=1;return 0; } ll pos1,pos2; if(pos==1) { pos1=le,pos2=le; while(pos1<=ri) { if(p[pos1]=='1'&&q[pos1]=='0') { while(p[pos2]!='0') pos2++; if(pos1>=n||pos1<0) while(1); ans+=1; p[pos2]='1'; pos2++; } pos1++; } } else { pos1=ri,pos2=ri; while(pos1>=le) { if(p[pos1]=='1'&&q[pos1]=='0') { while(p[pos2]!='0') pos2--; if(pos1>=n||pos1<0) while(1); ans+=1; p[pos2]='1'; pos2--; } pos1--; } } return 0; } int main() { ll t,i,j,now1=0,now2=0,nowleft=0,nowway=0,zz1=0,zz2=0; cin>>n; scanf("%s",&p); scanf("%s",&q); for(i=0;i<n;i++) { if(p[i]=='0') zz1++; if(q[i]=='0') zz2++; } if(zz1!=zz2) { printf("-1"); return 0; } if(p[0]=='0') pre[0]=1; if(p[0]=='0'&&q[0]=='1') pre2[0]=1; for(i=1;i<n;i++) { pre[i]=pre[i-1]; if(p[i]=='0') pre[i]++; pre2[i]=pre2[i-1]; if(p[i]=='0'&&q[i]=='1') pre2[i]++; } for(i=0;i<n;i++) { if(p[i]=='1') now1++; if(q[i]=='1') now2++; if(now1==now2) { solve(nowleft,i,nowway); nowleft=i+1; } if(now1>now2) nowway=1; else if(now1<now2) nowway=2; } printf("%lld",ans); return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; typedef long long ll; int i, j; int func (int n){ if (n == 0) return 1; int x = func(n/2); x *= x; if (n%2 == 1) x *= 2; return x; } int main(void){ int n, num_p; vector<int> A; vector<int> tree; cin >> n; num_p = func(n); A.resize(num_p); tree.resize(num_p); rep (i, num_p){ cin >> A[i]; tree[i] = i+1; } rep (i, n-1){ rep (j, num_p/2){ if (A[j*2] > A[j*2+1]){ A[j] = A[j*2]; tree[j] = tree[j*2]; } else{ A[j] = A[j*2+1]; tree[j] = tree[j*2+1]; } } num_p /= 2; } if (A[0] < A[1]) cout << tree[0] << endl; else cout << tree[1] << endl; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ll long long #define ull unsigned long long #define ld long double #define F first #define S second #define eb emplace_back #define pb push_back #define mp make_pair #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) using namespace __gnu_pbds; using namespace std; template <typename T> using oset = tree <pair <T, T>, null_type, less <pair <T, T>>, rb_tree_tag, tree_order_statistics_node_update>; template <typename T> void ckmin(T& a, const T b) {a = min(a, b);} template <typename T> void ckmax(T& a, const T b) {a = max(a, b);} template <typename T> vector <T> sieve(T n) { vector <T> f(n+1, 1), res; for (T i = 2; i <= n; ++i) for (T j = i; j <= n; j += i) ++f[j]; for (T i = 2; i <= n; ++i) if (f[i] == 2) res.eb(i); return res; } template <typename T> T power(T a, T b) { T res = 1; while (b) { if (b & 1) res = res * a; b >>= 1; a = a * a; } return res; } template <typename T> void print(vector <T> v) { for (T i : v) cout << i << " "; cout << '\n'; } template <typename T> void print(vector <vector <T>>& v) { for (vector <T>& vv : v) { for (T& i : vv) cout << i << " "; cout << '\n'; } } template <typename T> void read(vector <T>& v) {for (T& i : v) cin >> i;} template <typename T> void read(T&& t) {cin >> t;} template <typename T, typename... Args> void read(T&& t, Args&&... args) { cin >> t; read(forward<Args>(args)...); } template <typename T> void print(T&& t) {cout << t << '\n';} template <typename T, typename... Args> void print(T&& t, Args&&... args) { cout << t << " "; print(forward<Args>(args)...); } void usaco(string name = "") { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(name.size()) { freopen((name+".in").c_str(), "r", stdin); freopen((name+".txt").c_str(), "w", stdout); } } inline void solve() { int n; cin >> n; vector <int> a(1 << n); for (int i = 0; i < (1 << n); ++i) cin >> a[i]; auto x = max_element((1 << (n-1)) + all(a)) - a.begin(); auto y = max_element(all(a) - (1 << (n-1))) - a.begin(); print(a[x] > a[y] ? y+1 : x+1); } int32_t main() { usaco(); int t = 1; while (t--) solve(); }
#include <bits/stdc++.h> #define Fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); using ll = long long ; using namespace std; using pii = pair<int,int>; #define ld long double #define bit(mask,i) ((mask>>i)&1) #define p(a) cout<<"("<<a.first<<" "<<a.second<<") "; #define row vector<ll> #define vll row #define mtx vector<row> #define oo 1e9+9 #define INF oo #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() using namespace std; const int N = 2e5 + 5; ll mod=998244353; ll dp[5000+5][5000+5]; int main() { ll tcc=1; //cin>>tcc; while(tcc--){ ll a,b,c,d; cin>>a>>b>>c>>d; ll ans=a*d-b*c; cout<<ans<<"\n"; } return 0; }
#include<bits/stdc++.h> using namespace std; using ll = long long ; int main() { int a,b,c,d; cin>>a>>b>>c>>d; cout<<min({a,b,c,d}) <<endl; }
#include<bits/stdc++.h> using namespace std; #pragma GCC optimize("O3") typedef long long ll; #define rep(i, n) for(ll i = 0; i < (n); ++i) #define repA(i, a, n) for(ll i = a; i <= (n); ++i) #define repD(i, a, n) for(ll i = a; i >= (n); --i) #define vec(i, a) for( auto i=a.begin();i != a.end(); ++i) #define all(x) x.begin(), x.end() #define sz(x) (ll)(x).size() #define fill(a) memset(a, 0, sizeof (a)) #define mp make_pair #define pb push_back #define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define in freopen("input.txt","r",stdin); #define out freopen("output.txt","w",stdout); #define sixfive in out typedef long double ld; typedef std::pair<ll, ll> pii; typedef std::vector<ll> vi; const ll MOD = 1e9 + 7; ll n_bits(ll n ) { ll x= __builtin_popcount(n) ;return x ;} ll binpow(ll a, ll b, ll m=MOD) { a%=m; ll res=1; while (b>0) { if (b&1) res=res*a%m; a=a*a%m; b>>=1; } return res; } int main() { #ifndef ONLINE_JUDGE sixfive #endif fast ll t=1; //cin>>t; while(t--) { int n,k; cin>>n>>k; int a[n]; for(int i=0;i<n;i++) { cin>>a[i]; if(a[i]!=k) cout<<a[i]<<" "; } } 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 FOR(i,a,b) for(int i=(a);i<(b);++i) #define ALL(x) (x).begin(),(x).end() const int IINF = 1e9; const LL LINF = 1e18; const LL MOD = 1e9+7; int main() { int N; cin >> N; vector<LL> A(N), T(N); REP(i, N) { cin >> A[i] >> T[i]; } int Q; cin >> Q; vector<LL> X(Q); REP(i, Q) { cin >> X[i]; } pair<LL, LL> range(-LINF, LINF); LL shift = 0; REP(i, N) { if(T[i] == 1) { shift += A[i]; range.first += A[i]; range.second += A[i]; } if(T[i] == 2) { if(range.second <= A[i]) { range = make_pair(A[i], A[i]); }else if(A[i] <= range.first) { // 何もしない }else{ range.first = A[i]; } } if(T[i] == 3) { if(A[i] <= range.first) { range = make_pair(A[i], A[i]); }else if(range.second <= A[i]) { // 何もしない }else{ range.second = A[i]; } } } REP(i, Q) { LL low = range.first; LL high = range.second; LL r = min<LL>(max<LL>(X[i] + shift, low), high); cout << r << endl; } return 0; }
#include <iostream> #include <vector> #include <string> #include <deque> #include <list> #include <tuple> #include <algorithm> #include <set> using namespace std; uint64_t modValue[200] = {UINT64_MAX}; vector<int> pathOne[200]; int searchPath[200]; vector<uint64_t> all; bool findFlg = false; bool findTwo(int path[], int pathCount){ uint64_t tempValue = 0; bool twoFlg = false; for(int count = 0; count < pathCount; count++){ uint64_t value = all[(path[count] - 1)]; tempValue += (value % 200); } tempValue = tempValue % 200; if(modValue[tempValue] == 1){ cout << "Yes" << endl; cout << pathOne[tempValue].size() << " "; for(int count = 0; count < pathOne[tempValue].size(); count++){ cout << pathOne[tempValue][count] << " "; } cout << endl; cout << pathCount << " "; for(int count = 0; count < pathCount; count++){ cout << path[count] << " "; } cout << endl; twoFlg = true; } else { modValue[tempValue] = 1; for(int count = 0; count < pathCount; count++){ pathOne[tempValue].push_back(path[count]); } } return twoFlg; } void solution(vector<uint64_t> all, int targetNum, int pathCount, int checkIndex) { if(pathCount == targetNum){ if(findTwo(searchPath, pathCount)){ findFlg = true; } return; } if(pathCount + all.size() - checkIndex == targetNum){ for(int copyIndex = checkIndex; copyIndex < all.size(); copyIndex++){ searchPath[pathCount] = copyIndex + 1; pathCount++; } if(findTwo(searchPath, pathCount)){ findFlg = true; } return; } searchPath[pathCount] = checkIndex + 1; solution(all, targetNum, pathCount + 1, checkIndex + 1); if(findFlg){ return; } solution(all, targetNum, pathCount, checkIndex + 1); } int main() { int N; cin >> N; for(int readCount = 1; readCount <= N; readCount++){ uint64_t temp; cin >> temp; all.push_back(temp % 200); } for(int current = 1; current <= N; current++){ solution(all, current, 0, 0); if(findFlg){ break; } } if(!findFlg){ cout << "No" << endl; } }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; #define MOD 1000000007LL #define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++) #define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++) #define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++) #define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++) #define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--) #define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--) #define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--) #define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--) #define iter(i, it) for(auto &(i): (it)) template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) { cout << "(" << m.first << ", " << m.second << ")"; return s; } template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) { ll c = 0; cout << "{ "; iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", "); cout << "}"; return s; } template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) { cout << "{ "; rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", "); cout << "}"; return s; } template<typename T> ostream& operator<<(ostream &s, const list<T> &v) { ll c = 0; cout << "{ "; iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", "); cout << "}"; return s; } int main(void) { ll a, b, c, d; cin >> a >> b >> c >> d; cout << b - c << endl; return 0; }
#include <bits/stdc++.h> #define pb push_back #define fst first #define snd second #define fore(i,a,b) for(int i=a,ggdem=b;i<ggdem;++i) #define SZ(x) ((int)x.size()) #define ALL(x) x.begin(),x.end() #define mset(a,v) memset((a),(v),sizeof(a)) #define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0) using namespace std; typedef long long ll; const ll MOD=998244353; ll dp[102][102][10004]; int main(){FIN; ll n; cin>>n; vector<ll> a(n); fore(i,0,n)cin>>a[i]; for(ll x=n;x>=0;x--){ for(ll y=x;y>=0;y--){ fore(z,0,10004){ ll &res=dp[x][y][z]; if(x==n){ if(z==0)res=1; else res=0; }else{ res=dp[x+1][y+1][z+a[x]]*(y+1); if(a[x]<=z){ res=(res+dp[x+1][y][z-a[x]]*(x+1-y))%MOD; }else{ res=(res+dp[x+1][x-y+1][a[x]-z]*(x+1-y))%MOD; } } } } } cout<<dp[0][0][0]<<"\n"; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #ifdef LOCAL #include "debug.hpp" #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) #endif ll MOD = 998244353; int main() { ios::sync_with_stdio(false); cin.tie(0); ll N; cin >> N; vector<ll> W(N); for (ll i = 0; i < N; i++) cin >> W[i]; ll SUM = 0; for (ll i = 0; i < N; i++) { SUM += W[i]; } if (SUM % 2) { cout << 0 << '\n'; return 0; } // i 番目までを見たとき、j個を使ってkを作る数 SUM /= 2; vector<vector<ll>> dp(N + 1, vector<ll>(SUM + 1, 0)); dp[0][0] = 1; for (ll i = 0; i < N; i++) { vector<vector<ll>> dp2 = dp; for (ll j = 0; j < N; j++) { for (ll k = 0; k < SUM + 1; k++) { ll w = k + W[i]; if (w > SUM) continue; dp2[j + 1][w] += dp[j][k]; dp2[j + 1][w] %= MOD; } } dp = dp2; } debug(dp); vector<ll> factorial(N + 1, 1); for (ll i = 1; i <= N; i++) { factorial[i] = factorial[i - 1] * i; factorial[i] %= MOD; } ll ans = 0; for (ll k = 0; k < N; k++) { ll temp = dp[k][SUM]; temp = (temp * factorial[k]) % MOD; temp = (temp * factorial[N - k]) % MOD; ans = (ans + temp) % MOD; } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pll = pair<ll, ll>; using tlll = tuple<ll, ll, ll>; //constexpr ll MOD = 1e9 + 7; constexpr ll MOD = 998244353; //constexpr ll MOD = ; ll mod(ll A, ll M) {return (A % M + M) % M;} constexpr ll INF = 1LL << 60; template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;} template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;} ll divceil(ll A, ll B) {return (A + (B - 1)) / B;} #define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false) int main() { ll x, y; cin >> x >> y; if (x == y) cout << x << endl; else cout << 3 - x - y << endl; }
#include <bits/stdc++.h> using namespace std; // Big two primes #define X 1001100011100001111ll #define mod 1000000007 #define int long long #define ll long long #define all(a) a.begin(),a.end() #define sortall(a) sort(all(a)) #define fo(i, n) for (int i = 0; i < n; i++) #define fo1(i, n) for (int i = 1; i <= n; i++) #define loop(i,a,b) for (int i = a; i < b; i++) #define nloop(i,a,b) for (int i = a ; i>=b;i--) #define tc(t) int t; cin >> t; while (t--) #define arrip(a,n) int a[n]; fo(i, n) cin >> a[i]; #define arrop(a,n) fo(i,n) cout<<a[i]<<" "; #define pb push_back #define mp make_pair #define itr(it, a) for(auto it = a.begin(); it != a.end(); it++) #define PI 3.1415926535897932384626 #define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL) #define rr return 0 #define prec(n) fixed<<setprecision(n) #define maxpq priority_queue<int> #define minpq priority_queue<int, vector<int>, greater<int> > #define inf (int)(1e18) #define ini(a, i) memset(a, i, sizeof(a)) #define vi vector<int> #define fi first #define se second #define endl "\n" #define pi pair<int, int> #define vpi vector<pi> #define sz(s) s.size() #define bits(n) __builtin_popcount(n) //const int MAXN = (int)((1e5) +` 100); //int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);} int max(int a, int b) {if (a > b) return a; else return b;} int min(int a, int b) {if (a < b) return a; else return b;} void solve() { int n, x; cin >> n >> x; arrip(a, n); fo(i, n) { if (a[i] != x) { cout << a[i] << " "; } } cout << endl; } int32_t main() { fio; #ifndef ONLINE_JUDGE freopen("bi.txt", "r", stdin); freopen("bo.txt", "w", stdout); #endif solve(); }
#include<iostream> #include<cstdio> #include<cstring> using namespace std; long long f[1000],g[1000]; long long n; int tmp[1000]; int main() { f[0]=0,f[1]=1; for(int n=2;n<=87;n++) { f[n]=f[n-1]+f[n-2]; if(f[n]>1e18)break; } for(int i=0;i<=87;i+=2)g[i>>1]=f[i]; scanf("%lld",&n); int lim=43;while(g[lim]>n)--lim; int tn=0; for(int i=lim;i>=1;i--) { while(n>=g[i])tmp[++tn]=2,n-=g[i]; tmp[++tn]=4,tmp[++tn]=3; } printf("%d\n",tn); for(int i=1;i<=tn;i++)printf("%d\n",tmp[i]); }
#include <bits/stdc++.h> #define int long long using namespace std; int f[114], n, num; bool cur_op, yes; queue <int> ans; const int inf=1e18; void init() { f[0]=1ll, f[1]=2ll; for(num=2;f[num-1]<=inf;++num) f[num]=f[num-1]+f[num-2]; --num; return ; } signed main() { cin>>n;init(); for(int i=num; i>=0; --i) { while(n>=f[i]) { n-=f[i], ans.push(cur_op+1); yes=true; } cur_op^=1; if(yes) ans.push(cur_op+3); } cout<<ans.size()<<endl; while(!ans.empty()) cout<<((ans.front()-1)^1)+1<<endl, ans.pop(); 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>; using namespace std; #define INF ((1<<30)-1) #define LLINF (1LL<<60) #define EPS (1e-10) const ll mod = 1e9 + 7; ll f1(ll n) { if (n < 0) return 0; ll res = n * (n + 1) / 2; return res % mod; } ll f2(ll n) { if (n < 0) return 0; ll res = f1(n); res %= mod; res *= res; res %= mod; return res; } void solve() { int n, a, b; cin >> n >> a >> b; ll x = ((f1(n - a - b + 1) * (n - b + 1) % mod) * (n - a + 1)) % mod; ll y = f2(n - a - b + 1) % mod; ll ans = (x*4) % mod - (y*4) % mod; cout << (ans + mod) % mod << endl; } int main() { int T; cin >> T; rep(t, T) { solve(); } }
#include<bits/stdc++.h> #define debug(a) cout<<#a<<"="<<a<<endl #define rep(i,a,b) for(ll i=a,i##end=b;i<=i##end;++i) #define drep(i,a,b) for(ll i=a,i##end=b;i>=i##end;--i) #define erep(i,a) for(ll i=hd[a],y;(y=to[i]);i=nxt[i]) typedef long long ll; using namespace std; char IO; inline ll rd() { ll res=0,f=1; while(IO=getchar(),IO<48||IO>57)if(IO=='-')f=0; do res=(res<<3)+(res<<1)+(IO^48); while(IO=getchar(),IO>=48&&IO<=57); if(f)return res; return -res; } inline void Max(ll &a,ll b) { ((a<b)&&(a=b)); } inline void Min(ll &a,ll b) { ((a>b)&&(a=b)); } bool let; const ll P=1e9+7; bool vio; int main() { // printf("%.3f",(&vio-&let)/1024.0/1024); ll T=rd(); while(T--) { ll n=rd(),a=rd(),b=rd(); if(a<b)swap(a,b); ll tot=(n-a+1)*(n-a+1)%P*(n-b+1)%P*(n-b+1)%P; if(a+b>n) { ll t=((1+n-a)*(n-a)%P+(a-b+1)*(n-a+1)%P)%P; printf("%lld\n",((tot-t*t%P)%P+P)%P); } else { ll t=((n-a-b+2+n-a)*(b-1)%P+(a-b+1)%P*(n-a+1)%P)%P; printf("%lld\n",((tot-t*t%P)%P+P)%P); } } }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vc = vector<char>; using vcc = vector<vc>; using Pii = pair<int,int>; int main(){ int n,x; cin >> n >> x; for(int i = 0; i<n; i++){ int a; cin >> a; if(a != x){ cout << a << " "; } } cout << endl; }
#include <iostream> #include <string> #include <vector> using namespace std; int main() { int n, x; cin >> n >> x; vector <char> data(n); for (int i = 0; i < n; i++){ cin >> data.at(i); } for (int i = 0; i < n; i++){ if (x == 0 and data.at(i) == 'x') continue; else{ if (data.at(i) == 'o'){ x += 1; } else x -= 1; } } cout << x << endl; }
//Codeforcesで128bit整数を使いたいとき //→__int128_tを使う&GNU C++17 (64)で提出する //インクルードなど #include<bits/stdc++.h> using namespace std; typedef long long ll; //イテレーション #define REP(i,n) for(ll i=0;i<ll(n);i++) #define REPD(i,n) for(ll i=n-1;i>=0;i--) #define FOR(i,a,b) for(ll i=a;i<=ll(b);i++) #define FORD(i,a,b) for(ll i=a;i>=ll(b);i--) #define FORA(i,I) for(const auto& i:I) //x:コンテナ #define ALL(x) x.begin(),x.end() #define SIZE(x) ll(x.size()) //定数 #define INF32 2147483647 //2.147483647×10^{9}:32bit整数のinf #define INF64 9223372036854775807 //9.223372036854775807×10^{18}:64bit整数のinf #define MOD 1000000007 //問題による //略記 #define F first #define S second //出力(空白区切りで昇順に) #define coutALL(x) for(auto i=x.begin();i!=--x.end();i++)cout<<*i<<" ";cout<<*--x.end()<<endl; //aをbで割る時の繰上げ,繰り下げ ll myceil(ll a,ll b){return (a+(b-1))/b;} ll myfloor(ll a,ll b){return a/b;} signed main(){ ll M,H; cin >> M >> H; if (H % M == 0) cout << "Yes" << "\n"; else cout << "No" << "\n"; }
#define _USE_MATH_DEFINES #include <iostream> //cin, cout #include <vector> //vector #include <algorithm> //sort,min,max,count #include <string> //string,getline, to_string #include <ios> //fixed #include <iomanip> //setprecision #include <utility> //swap, pair #include <cstdlib> //abs(int) #include <cmath> //sqrt,ceil,M_PI, pow, sin #include <sstream> //stringstream, getline #include <numeric> //gcd, accumlate #include <deque> //deque #include <random> //randam_device #include <limits> //numeric_limits using namespace std; constexpr long long int D_MOD = 1000000007; int main() { int M, H; cin >> M >> H; if (H % M == 0) { cout << "Yes" << endl; } else { cout << "No" << endl; } return 0; }
#include <iostream> #include <algorithm> #include <vector> #include <string> #include <utility> #include <set> #include <map> #include <cmath> #include <queue> #include <cstdio> #include <limits> #include <numeric> #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(); class Osa_k{ public: int max_number; vi min_factor; Osa_k(int N) : max_number(N) { Build(); } void Build() { min_factor.resize(max_number+1); iota(min_factor.begin(),min_factor.end(), 0); for(int i = 2; i <= max_number; ++i) { if(min_factor[i] < i) continue; for(int j = 1; i*j <= max_number; ++j) { min_factor[i*j] = i; } } } vvi PrimeFactor() { vvi res(max_number+1); for(int i = 2; i <= max_number; ++i) { int num = i; while(num >= 2) { int factor = min_factor[num]; res[i].push_back(factor); while(num % factor == 0) num /= factor; } } return res; } void Test() { vvi res = PrimeFactor(); for(int i = 2; i <= max_number; ++i) { cout << i << "\n"; for(auto tmp: res[i]) cout << tmp << " "; cout << "\n"; } } }; int main() { ll l,r; cin >> l >> r; Osa_k os(r+1); vvi primeFactor = os.PrimeFactor(); ll res = 0; for(int i = l; i <= r; ++i) { int n = sz(primeFactor[i]); rep1(S,(1<<n)-1){ int prod = 1; rep(j,n) { if((S>>j)&1) prod *= primeFactor[i][j]; } ll count = r/prod - (i-1)/prod; count -= r/i; if(__builtin_popcount(S) % 2 == 1) res += count; else res -= count; } } cout << res*2 << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 10; typedef long long ll; ll f[maxn], g[maxn]; ll ans; ll sqr(ll x) { return x * x;} ll calcg(int l, int r) { return sqr(r - l + 1); } ll calcf(int l, int r) { l = max(l, 2); if(l > r) return 0; return sqr(r - l + 1); } int main() { int l, r; scanf("%d%d", &l, &r); for(int i = r; i >= 2; --i) { f[i] = calcf((l + i - 1) / i, r / i); g[i] = calcg((l + i - 1) / i, r / i); for(int j = i + i; j <= r; j += i) { g[i] -= g[j]; f[i] -= g[j]; } ans += f[i]; } printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, int> pli; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; vector<vector<tuple<int, int, int>>> adj(n); while (m--) { int a, b, c, d; cin >> a >> b >> c >> d; --a, --b; adj[a].emplace_back(b, c, d); adj[b].emplace_back(a, c, d); } constexpr ll INF = 1LL << 60; vector<ll> dist(n, INF); dist[0] = 0; priority_queue<pli, vector<pli>, greater<pli>> pq; pq.push(pli(0, 0)); auto rounding = [&](ll t, int d) -> int { int ct = static_cast<int>(sqrt(d)) - t - 1; if (ct < 0) { return 0; } int diff1 = d / (t + 1) - d / (t + ct + 1) - ct; int diff2 = d / (t + 1) - d / (t + ct + 2) - ct - 1; if (diff1 < 0 && diff2 < 0) { return 0; } else { return diff1 > diff2 ? ct : ct + 1; } }; while (!pq.empty()) { auto [t, v] = pq.top(); pq.pop(); if (t != dist[v]) { continue; } for (auto [u, c, d] : adj[v]) { int extra = rounding(t, d); ll nt = t + c + extra + d / (t + extra + 1); if (nt < dist[u]) { dist[u] = nt; pq.push(pli(nt, u)); } } } cout << (dist[n - 1] == INF ? -1LL : dist[n - 1]) << "\n"; return 0; }
//Shrey Dubey #include<iostream> #include<string> #include<algorithm> #include<map> #include<unordered_map> #include<vector> #include<set> #include<list> #include<iomanip> #include<queue> #include<stack> #include <math.h> #include<climits> #include<bitset> #include<cstring> #include<numeric> #include<array> using namespace std; typedef long long ll; typedef long double ld; #define YES cout<<"YES\n" #define Yes cout<<"Yes\n" #define NO cout<<"NO\n" #define No cout<<"No\n" #define prDouble(x) cout<<fixed<<setprecision(10)<<x //to print decimal numbers #define pb push_back #define ff first #define sec second #define umap unordered_map #define mp make_pair #define KOBE ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define fo(n) for(ll i = 0; i<n; i++) #define fnd(stl, data) find(stl.begin(), stl.end(), data) #define forn(x,n) for(ll x = 0; x<n; x++) #define imax INT_MAX #define lmax LLONG_MAX #define imin INT_MIN #define lmin LLONG_MIN #define vi vector<int> #define vl vector<ll> #define vp vector<pair<ll,ll> > #define vb vector<bool> #define pr(t) cout<<t<<"\n" #define int long long #define ql queue<ll> #define qp queue<pair<ll,ll> > #define endl "\n" #define nl cout<<"\n" #define re cin >> #define pll pair<ll,ll> #define FOR(a,b) for(ll i = a; i<=b; i++) #define all(x) x.begin(),x.end() // ll dx[] = {1,0,-1,0}; // ll dy[] = {0,1,0,-1}; ll mod = 1e9 + 7; ll cl(ld a){ if(a>(ll) a){ return (ll)a+1; } else{ return (ll)a; } } ll flr(ld a){ if(a < 0.0){ return (ll) a - 1; } return (ll) a; } //code starts here ll n,m,q; vp pos; void solve(){ re n; pos.resize(n); fo(n){ re pos[i].ff; re pos[i].sec; } re m; pll x = mp(1,0); pll y = mp(1,0); vp oper(m); fo(m){ re oper[i].ff; if(oper[i].ff == 3 || oper[i].ff == 4){ re oper[i].sec; } } re q; vector<pair<pll,ll> > qry(q); fo(q){ re qry[i].ff.ff; re qry[i].ff.sec; qry[i].sec = i; } sort(qry.begin(),qry.end()); vp ans(q); bool swp = false; ll a = 0; fo(q){ ll curop = qry[i].ff.ff; ll posn = qry[i].ff.second; posn--; ll idx = qry[i].sec; // cout<<curop<<"()"<<posn<<"\n"; while(a != curop){ ll op = oper[a].ff; if(op == 1){ auto temp = x; x = y; y = temp; y.ff *= -1; y.sec *= -1; swp = !swp; }else if(op == 2){ auto temp = x; x = y; y = temp; x.ff *= -1; x.sec *= -1; swp = !swp; }else if(op == 4){ ll p = oper[a].sec; y.sec = 2*p-y.second; y.ff *= -1; }else{ ll p = oper[a].sec; x.sec = 2*p-x.sec; x.ff *= -1; } a++; } ll xp = pos[posn].ff, yp = pos[posn].sec; if(swp){ swap(xp,yp); } xp *= x.ff; xp += x.sec; yp *= y.ff; yp += y.sec; ans[idx] = mp(xp,yp); } for(auto p: ans) cout<<p.ff<<" "<<p.sec<<"\n"; } int32_t main(){ KOBE; ll t; t = 1; // re t; while(t--) solve(); } //common errors // row - n, col - m always and loop var // see the freq of numbers carefully // see if there's array overflow // use map for large inputs //problem ideas //check piegonhole wherever possible //there might be many instances of limited answers like 0,1,2 only // see suffix and prefix //don't be obsessed with binary search // try to find repeating pattern in matrices /* 1 1 2 4 1 3 3 2 4 2 5 0 1 1 1 2 1 3 1 4 1 */
#include <stdio.h> #include <algorithm> long long n; long long a[400000]; int b[400000]; int q[400000]; int e; int main() { scanf("%lld", &n); for (long long i = 0; i < 2 * n; i++) { scanf("%lld", a + i); a[i] *= 2 * n; a[i] += i; } std::sort(a, a + 2 * n); for (int i = 0; i < n; i++) { b[a[i] % (2 * n)]++; } if (b[0]) { for (int i = 0; i < 2 * n; i++) { b[i] = 1 - b[i]; } } for (int i = 0; i < 2 * n; i++) { if (e) { if (q[e - 1] == b[i]) { q[e] = b[i]; e++; printf("("); continue; } else { e--; printf(")"); continue; } } else { q[e] = b[i]; e++; printf("("); continue; } } printf("\n"); }
#include <bits/stdc++.h> using namespace std; using ll = long long; void solve() { int n; cin>>n; n*=2; vector<vector<int>> a(n, vector<int> (2)); for(int i=0; i<n; i++) { cin>>a[i][0]; a[i][1]=i; } sort(a.begin(), a.end()); for(int i=0; 2*i<n; i++) { a[a[i][1]][0]*=-1; } string ans(n, '('); int pos=0, neg=0; for(int i=0; i<n; i++) { if(a[i][0]<0) { if(pos) { ans[i]=')'; pos--; } else { neg++; } } else { if(neg) { ans[i]=')'; neg--; } else { pos++; } } } cout<<ans<<endl; return; } int main() { #ifdef bipinpathak (void)!freopen("input.txt", "r", stdin); (void)!freopen("output.txt", "w", stdout); #endif ios::sync_with_stdio(false); cin.tie(NULL); auto start=clock(); int t = 1; //cin>>t; for(int i=0; i<t; i++) { //cout<<"Case #"<<i+1<<": "; solve(); } double used= (double) (clock()-start); used=(used*1000)/CLOCKS_PER_SEC; cerr<<fixed<<setprecision(2)<<used<<" ms"<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; template<typename T> void out(T x) { cout << x << endl; exit(0); } #define watch(x) cout << (#x) << " is " << (x) << endl using ll = long long; const int maxn = 1e6 + 5; int n; int a[maxn],b[maxn],p[maxn],pinv[maxn]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>n; for (int i=1; i<=n; i++) { cin>>a[i]; } for (int i=1; i<=n; i++) { cin>>b[i]; } for (int i=1; i<=n; i++) { cin>>p[i]; pinv[p[i]]=i; } for (int i=1; i<=n; i++) { if (i==p[i]) continue; if (a[i] > b[p[i]]) continue; out(-1); } vector<pair<int,int>> ans; vector<int> ord(n); iota(ord.begin(),ord.end(),1); sort(ord.begin(),ord.end(),[&](int i, int j) { return a[i]<a[j]; }); // a[i] > b[p[i]] // a[j] > b[p[j]] // a[i] <= a[j], implies b[p[i]] < b[p[j]] for (int i: ord) { if (i==p[i]) continue; int j = pinv[i]; int tmpi = p[i]; int tmpj = p[j]; swap(p[i],p[j]); pinv[tmpj]=i; pinv[tmpi]=j; assert(i==p[i]); ans.emplace_back(i,j); } cout<<ans.size()<<endl; for (auto p: ans) cout<<p.first<<" "<<p.second<<"\n"; 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 = input(); vector< int > as(n), bs(n), ps(n); cin >> as >> bs >> ps; for (auto &p : ps) p--; vector< int > used(n, false); bool valid = true; vector< pair< int, int > > ans; for (int v = 0; v < n; v++) { if (used[v]) continue; vector< int > us; us.emplace_back(v); used[v] = true; for (int u = ps[v]; u != v; u = ps[u]) { us.emplace_back(u); used[u] = true; } if ((int)us.size() == 1) continue; int min_b = inf; int idx_b = -1; for (int i = 0; i < (int)us.size(); i++) { int u = us[i]; if (as[u] <= bs[ps[u]]) { valid = false; } if (bs[ps[u]] < min_b) { min_b = bs[ps[u]]; idx_b = i; } } int sz = us.size(); for (int i = (idx_b - 1 + sz) % sz; i != idx_b; i = (i - 1 + sz) % sz) { ans.emplace_back(us[i] + 1, us[(i + 1) % sz] + 1); } } if (not valid) { cout << -1 << endl; return; } cout << (int)ans.size() << endl; for (auto &t : ans) { cout << t.first << " " << t.second << endl; } } signed main() { solve(); }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(ll i = 0; i < (n); ++i) #define repA(i, a, n) for(ll i = a; i < (n); ++i) #define repD(i, a, n) for(ll i = a; i > (n); --i) #define trav(a, x) for(auto& a : x) #define all(x) x.begin(), x.end() #define sz(x) (long long) (x).size() #define fill(a) memset(a, 0, sizeof(a)) #define fst first #define snd second // #define mp make_pair #define pb push_back void __print(int x) {cout << x;} void __print(long x) {cout << x;} void __print(long long x) {cout << x;} void __print(unsigned x) {cout << x;} void __print(unsigned long x) {cout << x;} void __print(unsigned long long x) {cout << x;} void __print(float x) {cout << x;} void __print(double x) {cout << x;} void __print(long double x) {cout << x;} void __print(char x) {cout << '\'' << x << '\'';} void __print(const char *x) {cout << '\"' << x << '\"';} void __print(const string &x) {cout << '\"' << x << '\"';} void __print(bool x) {cout << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';} template<typename T> void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";} void _print() {cout << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define dbg(x...) cout << "[" << #x << "] = ["; _print(x) #else #define dbg(x...) #endif const long double PI = 3.141592653589793238462643383; typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<long long int> vll; typedef vector<double> vd; typedef vector<pii> vii; long long Ceil(long long a, long long b){ if(a%b==0) return a/b; else return (a/b)+1; } ll p=1000000007; // ll p = 1000000000000000000+5; float E = 0.00000000000001; ll power(ll x, ll y){ if(y==0){ return 1; } if(y%2==0){ ll q=power(x,y/2); q=q%p; return (q*q)%p; } ll q=power(x,y/2); q=q%p; return ((x%p)*((q*q)%p))%p; } bool isPowerOfTwo (long long x) { /* First x in the below expression is for the case when x is 0 */ return x && (!(x&(x-1))); } long long int gcd(long long int a, long long int b){ if (a == 0) return b; return gcd(b % a, a); } long long int mod(long long int a, long long int b) { long long int ret = a%b; return ret>=0? ret: ret+b; } int main(){ std::ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t = 1; // cin>>t; while(t--){ float a,b; cin>>a>>b; std::cout << std::fixed << std::setprecision(2); cout<<abs((b/a-1)*100); } return 0; }
#include <algorithm> #include <iostream> int main() { int A, B; std::cin >> A >> B; std::cout << 100.0 * (1.0 - 1.0 * B / A) << std::endl; return 0; }
#include <bits/stdc++.h> //#include <atcoder/all> #define rep(i,n,a) for(int i = a; i < (int)(n); i++) using namespace std; typedef long long ll; typedef unsigned long long u_ll; typedef pair<int, int> pair_; const int INF = 1001001001; const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, -1, 0, 1}; int k; template<class T> void chmin(T& a, T b){ if(a>b) a=b; } int main(){ int n, m; cin >> n >> m; vector<ll> a(n), b(m); rep(i, n, 0) cin >> a[i]; rep(i, m, 0) cin >> b[i]; vector<vector<int>> dp(n+1, vector<int>(m+1, INF)); int ans=0; if(n<m){ rep(i, n, 0) if(a[i]!=b[i]) ans++; ans+=m-n; } else{ rep(i, m, 0) if(a[i]!=b[i]) ans++; ans+=n-m; } //cout << ans << " "; dp[0][0]=0; rep(i, n+1, 0){ rep(j, m+1, 0){ if(i>0 && j>0){ if(a[i-1]==b[j-1]){ chmin(dp[i][j], dp[i-1][j-1]); } else{ chmin(dp[i][j], dp[i-1][j-1]+1); } } if(i>0) chmin(dp[i][j], dp[i-1][j]+1); if(j>0) chmin(dp[i][j], dp[i][j-1]+1); } } ans=min(ans, dp[n][m]); cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> VI; typedef vector<VI> VVI; typedef pair<ll, ll> P; #define FOR(i,a,b) for(ll i=ll(a);i<ll(b);++i) #define rep(i,n) FOR(i,0,n) #define PRINT(V) for (auto v : (V)) cout << v << " " #define ALL(n) begin(n),end(n) struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star; const ll INF = numeric_limits<ll>::max(); const char clist[4] = {'A', 'T', 'C', 'G'}; int main() { int n; cin >> n; string s; cin >> s; VI a(n+1), t(n+1), c(n+1), g(n+1); rep(i, n) { a[i+1] = a[i] + (s[i] == 'A'); t[i+1] = t[i] + (s[i] == 'T'); c[i+1] = c[i] + (s[i] == 'C'); g[i+1] = g[i] + (s[i] == 'G'); } ll ans = 0; rep(i, n) { for(int l=2; l<=n ; l = l+2) { if (i+l > n) continue; if ((a[i+l] - a[i] == t[i+l] - t[i])&&(c[i+l] - c[i] == g[i+l] - g[i])) { ++ans; } } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int(i) = 0; (i) < (n); (i)++) #define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++) #define All(v) (v).begin(), (v).end() #define pb push_back #define MP(a, b) make_pair((a), (b)) template <class T> vector<T> make_vec(size_t a, T val) { return vector<T>(a, val); } template <class... Ts> auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec(ts...))>(a, make_vec(ts...)); } using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using Graph = vector<vector<int>>; template <typename T> struct edge { int to; T cost; edge(int t, T c) : to(t), cost(c) {} }; template <typename T> using WGraph = vector<vector<edge<T>>>; const int INF = 1 << 30; const ll LINF = 1LL << 60; const int MOD = 1e9 + 7; int main() { int x; cin >> x; if(x < 0) { cout << 0 << endl; } else { cout << x << endl; } }
#include<bits/stdc++.h> using namespace std; typedef long long int ll; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); string a; cin>>a; ll n=a.size(); ll i; bool ok=true; for(i=0;i<n;i++) { if((i+1)%2!=0 && int(a[i])<=90 && int(a[i])>=65) ok=false; else if((i+1)%2==0 && int(a[i])<=120 && int(a[i])>=97) ok=false; } if(ok) cout<<"Yes"; else cout<<"No"; return 0; }
#include <iostream> #include <utility> #include <vector> using namespace std; int main() { int n; cin >> n; vector<pair<int, int>> coords; for (int i = 0; i < n; ++i) { int x, y; cin >> x >> y; coords.push_back({x, y}); } for (int i = 0; i < n; ++i) { for (int j = i + 1; j < n; ++j) { for (int k = j + 1; k < n; ++k) { if ((coords[j].first - coords[i].first) * (coords[k].second - coords[i].second) == (coords[k].first - coords[i].first) * (coords[j].second - coords[i].second)) { cout << "Yes\n"; return 0; } } } } cout << "No\n"; return 0; }
#include <bits/stdc++.h> #define REP(i,n) for(ll i=0;i<(ll)(n);i++) #define REPD(i,n) for(ll i=n-1;i>=0;i--) #define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++) #define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--) #define ALL(x) (x).begin(),(x).end() #define SIZE(x) ((ll)(x).size()) #define MAX(x) *max_element(ALL(x)) #define MIN(x) *min_element(ALL(x)) #define INF 1000000000 using namespace std; typedef long long ll; int main() { int N; cin >> N; int x[N], y[N]; REP(i, N){ cin >> x[i] >> y[i]; } bool flag = false; FOR(i, 0, N-3){ FOR(j, i+1, N-2){ FOR(k, j+1, N-1){ int resx, resy, posx, posy; resx = x[k] - x[i]; resy = y[k] - y[i]; posx = x[j] - x[i]; posy = y[j] - y[i]; //cout << i << " " << j << " " << k << endl; //cout << resx*posx + resy*posy << endl; if(resx*posy - resy*posx == 0){ flag = true; break; } } } } if(flag) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
// #include <bits/stdc++.h> #include <algorithm> #include <cmath> #include <iostream> #include <map> #include <vector> #define int long long #define all(a) a.begin(), a.end() #define vi vector<int> #define pii pair<int, int> #define fe(i, a, b) for (int i = a; i <= (b); ++i) #define fr(i, a, b) for (int i = b; i >= (a); --i) using namespace std; inline int in() { int s = 0, f = 0, ch = getchar(); while (!isdigit(ch)) f |= ch == '-', ch = getchar(); while (isdigit(ch)) s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar(); return f ? -s : s; } const int N = 1e6 + 5; const int mod = 998244353; const int inf = ~(1ULL << 63); int n, m, k; int a[N], b[N], f[N]; int c[N]; int qp(int a, int b) { int sum = 1; while (b) { if (b & 1) sum = sum * a % mod; a = a * a % mod; b >>= 1; } return sum; } int inv(int a) { return qp(a, mod - 2); } bool flag[N]; int p[N], tot; int find(int x) { return x == f[x] ? x : f[x] = find(f[x]); } struct node { int x, y; }; int toint(string s, int r) { int ans = 0; for (auto i : s) { ans = ans * r + i - 48; } return ans; } node ve[N + 1]; void work() { n = in(), m = in(); fe(i, 1, n) { a[i] = in(); } int tot = 0; fe(i, 1, m) { f[a[i]]++; } for (; f[tot]; tot++) ; int ans = tot; fe(i, 1, n - m) { f[a[i]]--; f[a[i + m]]++; if (f[a[i]] == 0 && tot > a[i]) { tot = a[i]; } ans = min(ans, tot); } cout << ans; } signed main() { #ifndef ONLINE_JUDGE freopen("1.in", "r", stdin); freopen("1.out", "w", stdout); #endif // for (int _ = in(); _; --_) work(); // system("pause"); return 0; }
#include <cstdio> #include <vector> typedef long long LL; const int Mod = 998244353; const int MN = 55; int N, K, A[MN][MN], Ans; std::vector<int> G[MN]; int c, vis[MN]; void DFS(int u) { vis[u] = 1; Ans = (LL)Ans * ++c % Mod; for (int v : G[u]) if (!vis[v]) DFS(v); } int main() { scanf("%d%d", &N, &K), Ans = 1; for (int i = 1; i <= N; ++i) for (int j = 1; j <= N; ++j) scanf("%d", &A[i][j]); for (int i = 1; i <= N; ++i) for (int j = 1; j <= N; ++j) if (i < j) { int ok = 1; for (int k = 1; k <= N; ++k) if (A[i][k] + A[j][k] > K) ok = 0; if (ok) G[i].push_back(j), G[j].push_back(i); } for (int i = 1; i <= N; ++i) if (!vis[i]) c = 0, DFS(i); for (int i = 1; i <= N; ++i) G[i].clear(), vis[i] = 0; for (int i = 1; i <= N; ++i) for (int j = 1; j <= N; ++j) if (i < j) { int ok = 1; for (int k = 1; k <= N; ++k) if (A[k][i] + A[k][j] > K) ok = 0; if (ok) G[i].push_back(j), G[j].push_back(i); } for (int i = 1; i <= N; ++i) if (!vis[i]) c = 0, DFS(i); printf("%d\n", Ans); return 0; }
#include <bits/stdc++.h> #define int long long #define pii pair<int, int> #define x1 x1228 #define y1 y1228 #define left left228 #define right right228 #define tm tm228 #define pb push_back #define eb emplace_back #define mp make_pair #define ff first #define ss second #define all(x) x.begin(), x.end() #define debug(x) cout << #x << ": " << x << endl; #define TIME (ld)clock()/CLOCKS_PER_SEC using namespace std; typedef long long ll; typedef long double ld; const int maxn = 3e5 + 7, mod = 1e9 + 7, MAXN = 1e6 + 7; const double eps = 1e-9; const ll INF = 1e18, inf = 1e15; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); int n; int a[maxn], b[maxn]; void solve() { cin >> n; for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 0; i < n; ++i) cin >> b[i]; int cur = 0; for (int i = 0; i < n; ++i) cur += a[i]; vector<int> odd, even; for (int i = 0; i < n; i += 2) odd.pb(b[i] - a[i]); for (int i = 1; i < n; i += 2) even.pb(b[i] - a[i]); sort(all(odd)); reverse(all(odd)); sort(all(even)); reverse(all(even)); int ans = cur; int c = 0; for (int i = 0; i < n / 2; ++i) { c += odd[i] + even[i]; ans = max(ans, cur + c); } cout << ans; } signed main() { #ifdef LOCAL freopen("TASK.in", "r", stdin); freopen("TASK.out", "w", stdout); #else #endif // LOCAL ios_base::sync_with_stdio(false); cin.tie(0); cout.precision(20); cout << fixed; int t = 1; for (int i = 0; i < t; ++i) { solve(); } return 0; }
#include<iostream> #include<stdio.h> #include<math.h> #include<string> #include<string.h> #include<algorithm> #include<vector> #include<set> #define ll long long const int maxn = 2e5 + 10; using namespace std; int m = 0, n, cha[maxn], l, r, qz[maxn], a[maxn], b[maxn]; int main(){ ll res = 0; scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d", &a[i]); } for (int i = 0; i < n; ++i) { scanf("%d", &b[i]); res += b[i]; } for (int i = 0; i < n; ++i) { if(i & 1) qz[i / 2] = a[i] - b[i]; else cha[i / 2] = a[i] - b[i]; } sort(qz, qz + n / 2); reverse(qz, qz + n / 2); sort(cha, cha + n / 2); reverse(cha, cha + n / 2); while (m < n / 2){ if(qz[m] + cha[m] <= 0) break; else { res += qz[m] + cha[m]; m++; } } printf("%lld\n", res); }
#include <bits/stdc++.h> using namespace std; using ll = long long; using pll = pair<long long, long long>; constexpr char ln = '\n'; constexpr long long MOD = 1000000007; constexpr long long INF = 1000000000 + 100; constexpr long long LINF = 1000000000000000000 + 100; #define all(v) v.begin(), v.end() #define rep(i, n) for(int i=0;i<(n);i++) #define rept(i, j, n) for(int i=(j); i<(n); i++) #define rrep(i, n) for(int i=(n); i>=0; i--) template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } int dx[4] = {0,1,0,1}; int dy[4] = {0,0,1,1}; int main(){ int H, W; cin >> H >> W; vector<string> g(H); rep(i, H)cin >> g[i]; int res = 0; rep(i, H-1){ rep(j, W-1){ int b = 0; rep(k, 4)if(g[i+dy[k]][j+dx[k]]=='#')b++; if(b%2==1)res++; } } cout << res << ln; }
#include <bits/stdc++.h> using namespace std; #define ALL(x) (x).begin(),(x).end() #define COUT(x) cout<<(x)<<"\n" #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define REP(i,n) for(int i=0;i<n;i++) #define YES(x) cout<<(x?"YES":"NO")<<"\n" #define Yes(x) cout<<(x?"Yes":"No")<<"\n" #define dump(x) cout<<#x<<" = "<<(x)<<"\n" #define endl "\n" using G = vector<vector<int>>; using M = map<int,int>; using P = pair<int,int>; using PQ = priority_queue<int>; using PQG = priority_queue<int,vector<int>,greater<int>>; using V = vector<int>; using ll = long long; using edge = struct { int to; int cost; }; template<class T>bool chmax(T &a,const T &b) {if(a<b){a=b; return 1;} return 0;} template<class T>bool chmin(T &a,const T &b) {if(b<a){a=b; return 1;} return 0;} const int INF = 1e9; const int MOD = 1e9+7; const ll LINF = 1e18; int main() { IOS; string a,b; cin >> a >> b; int suma=0,sumb=0; REP(i,a.size()) { suma += a[i] - '0'; } REP(i,b.size()) { sumb += b[i] - '0'; } COUT(max(suma, sumb)); return 0; }
#include <bits/stdc++.h> const long long INF = 1e9; const long long MOD = 1e9 + 7; //const long long MOD = 998244353; const long long LINF = 1e18; using namespace std; #define YES(n) cout << ((n) ? "YES" : "NO" ) << endl #define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl #define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE" ) << endl #define Possible(n) cout << ((n) ? "Possible" : "Impossible" ) << endl #define dump(x) cout << #x << " = " << (x) << endl #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) for(int i=0;i<(n);++i) #define REPR(i,n) for(int i=n;i>=0;i--) #define COUT(x) cout<<(x)<<endl #define SCOUT(x) cout<<(x)<<" " #define VECCOUT(x) for(auto&youso_: (x) )cout<<right<<setw(10)<<youso_<<" ";cout<<endl #define ENDL cout<<endl #define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__) #define LCIN(...) long long __VA_ARGS__;CINT(__VA_ARGS__) #define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__) #define VECCIN(x) for(auto&youso_: (x) )cin>>youso_ #define mp make_pair #define PQ priority_queue<long long> #define PQG priority_queue<long long,V,greater<long long>> typedef long long ll; typedef vector<long long> vl; typedef vector<long long> vi; typedef vector<bool> vb; typedef vector<char> vc; typedef vector<vl> vvl; typedef vector<vi> vvi; typedef vector<vb> vvb; typedef vector<vc> vvc; typedef pair<long long, long long> pll; #define COUT(x) cout<<(x)<<endl void CINT(){} template <class Head,class... Tail> void CINT(Head&& head,Tail&&... tail){ cin>>head; CINT(move(tail)...); } template<class T> void mod(T &x) { x %= MOD; x += MOD; x %= MOD; } ll GCD(ll a, ll b) { if(b == 0) return a; else return GCD(b, a%b); } struct COMB{ vl fact, fact_inv, inv; void init_nCk(long long SIZE) { fact.resize(SIZE + 5); fact_inv.resize(SIZE + 5); inv.resize(SIZE + 5); fact.at(0) = fact.at(1) = fact_inv.at(0) = fact_inv.at(1) = inv.at(1) = 1; for(long long i = 2; i < SIZE + 5; i++) { fact.at(i) = fact.at(i - 1)*i%MOD; inv.at(i) = MOD - inv.at(MOD%i)*(MOD/i)%MOD; fact_inv.at(i) = fact_inv.at(i - 1)*inv.at(i)%MOD; } } long long nCk (long long n, long long k) { assert(!(n < k)); assert(!(n < 0 || k < 0)); return fact.at(n)*(fact_inv.at(k)*fact_inv.at(n - k)%MOD)%MOD; } }; ll extGCD(ll a, ll b, ll &x, ll &y) { if(b == 0) { x = 1; y = 0; return a; } ll d = extGCD(b, a%b, y, x); y -= a/b*x; return d; } void Main() { LCIN(A, B, C, D); ll ans = (A + C*D - B - 1)/(C*D - B); if(C*D - B <= 0) cout << -1 << endl; else cout << ans << endl; } int main() { cout << fixed << setprecision(15); Main(); return 0; }
#include <bits/stdc++.h> #define ll long long #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); #define pll pair<ll, ll> #define plll pair<ll, pll> using namespace std; ll a, b, c, d, cnt = 0, red, cyan, beda; bool bisa = true; int main(){ fastio; cin >> a >> b >> c >> d; red = a; cyan = 0; while(red > cyan * d){ red += b; cyan += c; cnt++; if(cnt >= 1e9){bisa = false; break;} } if(bisa) cout << cnt; else cout << -1; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back #define mii map <int, int> #define mll map <ll, ll> #define pii pair <int, int> #define pll pair <ll, ll> #define vi vector <int> #define vd vector <double> #define vll vector <ll> #define fi first #define se second #define si set <int> #define sll set <ll> #define spii set <pii> #define vs vector <string> #define vpii vector <pair <int, int> > #define vpll vector <pair <long long, long long> > #define vvi vector <vector <int> > #define vvpii vector <vector <pii > > #define vb vector <bool> #define vvb vector <vb> #define mp make_pair #define vvll vector <vll> #define vsi vector <si> #define rep(i, n) for (int i = 0; i < (n); i++) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define MANX MAXN #define itn int #define dbg(x); {cout<<#x<<"="<<x<<", ";} #define in(x); { for (auto &to : x) cin>>to;} #define out(x); { for (auto &to : x) cout<<to<<" ";cout<<'\n'; } const ll INFLL = 1e18; const int MAXN = 1e6+100; const ll INF = 1e9; const int mod1 = 1e9+7; const int mod2 = 1e9+21; int add(int a,int b) { a+=b; if (a>=mod1) return a-mod1; return a; } int mult(int a,int b) { return 1ll*a*b%mod1; } int sub(int a,int b) { a-=b; if (a<0) return a+mod1; return a; } int bin_pow(int base,ll deg) { if (deg==0) return 1; int t=bin_pow(base,deg/2); if (deg&1) return 1ll*t*t%mod1*base%mod1; else return 1ll*t*t%mod1; } int C(int n,int k) { int ans=1; for (int i=n-k+1;i<=n;i++) ans=mult(ans,i); for (int i=1;i<=k;i++) ans=mult(ans,bin_pow(i,mod1-2)); return ans; } void solve() { int n,m; cin>>n>>m; vi a(n); in(a); int sum=accumulate(all(a),0); if (sum>m) { cout<<0<<'\n'; return; } m=m-sum; int k=sum+n; cout<<C(m+k,k)<<'\n'; } int main() { #ifdef Mip182 #else ios_base::sync_with_stdio(0); cin.tie(0); #endif #ifdef Mip182 freopen("a.in", "r", stdin); #endif int _t; _t=1; // cin>>_t; while (_t--) solve(); #ifdef Mip182 cout<<'\n'<<"Time : "<<(double)(clock())/CLOCKS_PER_SEC<<'\n'; #endif }
#include <bits/stdc++.h> using namespace std; template<class T> using vec = vector<T>; template<class T> using v2d = vector<vector<T>>; using ld = long double; using ll = long long; const ll M = 1e9+7; int main() { int h, w; cin>>h>>w; v2d<int> b(h, vec<int>(w, 1)); v2d<ll> r(h, vec<ll>(w, 0)); v2d<ll> vert(h, vec<ll>(w, 0)); v2d<ll> hori(h, vec<ll>(w, 0)); v2d<ll> diag(h, vec<ll>(w, 0)); r[0][0] = 1; vert[0][0] = 1; hori[0][0] = 1; diag[0][0] = 1; string s; for(int i = 0; i < h; i++) { cin>>s; for(int j = 0; j < w; j++) { s[j] == '#' && b[i][j]--; } } for(int i = 0; i < h; i++) { for(int j = 0; j < w; j++) { if (!b[i][j]) { continue; } if (i) { r[i][j] += vert[i-1][j]; } if (j) { r[i][j] += hori[i][j-1]; } if (i && j) { r[i][j] += diag[i-1][j-1]; } vert[i][j] = r[i][j]; hori[i][j] = r[i][j]; diag[i][j] = r[i][j]; if (i) { vert[i][j] += vert[i-1][j]; } if (j) { hori[i][j] += hori[i][j-1]; } if (i && j) { diag[i][j] += diag[i-1][j-1]; } r[i][j] %= M; vert[i][j] %= M; hori[i][j] %= M; diag[i][j] %= M; } } cout<<r[h-1][w-1]<<'\n'; return 0; }
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll n; cin>>n; ll i=1; ll ans=0; while(i) { if((i*(i+1))/2>=n) { ans=i; break; } i++; } cout<<ans<<endl; return 0; }
#include <iostream> #include <bits/stdc++.h> #include <fstream> using namespace std; typedef long long ll; typedef long double ld; #define fast ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int main() { fast int n, cnt = 0; cin >> n; if (n%100 == 0) n++,cnt++; while(n % 100) n++,cnt++; cout << cnt; }
//#include <atcoder/all> #include <bits/stdc++.h> //#include <windows.h> //#include <time.h> using namespace std; //using namespace atcoder; using ll = long long; #define all(A) A.begin(),A.end() using vll = vector<ll>; #define rep(i, n) for (long long i = 0; i < (long long)(n); i++) using Graph = vector<vector<tuple<ll, ll, ll>>>; int main() { ll N; cin>>N; vll A(N); rep(i,N)cin>>A[i]; sort(all(A)); ll M=N/2; double K=double(A[M])/2.0; double s=0; rep(i,N){ s+=K+A[i]-min(2*K,double(A[i])); } s/=N; cout<<setprecision(16)<<s<<endl; }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; typedef long long int lli; typedef unsigned long long int ulli; typedef long double ld; typedef vector<lli> vi; typedef vector<vi> vvi; typedef pair<lli, lli> pii; #define vec(s) vector<s> #define vvec(s) vector<vector<s>> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define Yes(x) cout << (x ? "Yes" : "No") << endl; #define YES(x) cout << (x ? "YES" : "NO") << endl; #define out(s) cout << s << endl; #define Reverse(x) reverse(all(x)); #define Sort(x) sort(all(x)); #define pb(s) push_back(s); #define sp " " #define INF 10000000000 #define LINF 9000000000000000000 #define all(s) s.begin(), s.end() void vout(vi v) { for (lli i = 0; i < v.size(); i++) cout << v.at(i) << endl; } int main() { lli n; cin >> n; vi a(n); rep(i, n) { cin >> a[i]; } lli ans = 2e9; rep(i, 1 << (n - 1)) { lli xored = 0; lli ored = 0; rep(j, n + 1) { if (j < n) { ored |= a[j]; } if (j == n || (i >> j & 1)) { xored ^= ored; ored = 0; } } ans = min(ans, xored); } out(ans); }
#include <algorithm> #include <cmath> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <set> #include <string> #include <unordered_set> #include <vector> #define REP(i, n) for(int i = 0; i < n; ++i) using namespace std; using LLONG = long long; const LLONG MOD = 1000000007; int main() { int N; cin >> N; string S, X; cin >> S >> X; reverse(S.begin(), S.end()); reverse(X.begin(), X.end()); // rem[i][j]:Tの余りがiのとき、次の桁にjを付けたときの余り int rem[7][10]; REP(i, 7) REP(j, 10) { rem[i][j] = (i * 10 + j) % 7; } // Taが勝つのは最後に余り0のときのみ vector<bool> tWin(7, false); tWin[0] = true; REP(i, N) { int s = static_cast<int>(S[i] - '0'); char x = X[i]; if (x == 'T') { vector<bool> nexWin(7, false); REP(prevR, 7) { // どちらかの手で勝てるならprevRで勝てる if (tWin[rem[prevR][0]] || tWin[rem[prevR][s]]) { nexWin[prevR] = true; } } tWin = nexWin; } else { vector<bool> nexWin(7, false); REP(prevR, 7) { // どちらかともの手で勝てるときのみprevRで勝てる // さもなくばAokiが妨害する if (tWin[rem[prevR][0]] && tWin[rem[prevR][s]]) { nexWin[prevR] = true; } } tWin = nexWin; } } cout << (tWin[0] ? "Takahashi" : "Aoki") << endl; }
#include <bits/stdc++.h> #define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;i++) #define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;i--) typedef long long ll; inline int read() { int x=0,f=1;char c=getchar(); while(c<48||c>57){if(c=='-')f=-1;c=getchar();} while(c>=48&&c<=57)x=(x<<1)+(x<<3)+(c^48),c=getchar(); return x*f; } using namespace std; const int M=2e5+5; int dp[M][10];// dp[i][j]:算到第i位时为j是否必胜 int len; string a,b; int DP(int n,int now){ if(n==len){ // printf("%d\n",now); return now==0; } if(dp[n][now]!=-1)return dp[n][now]; int num; int p=b[n]-'0'; // printf("n=%d,b=%c,p=%d\n",n,b[n],p); if(a[n]=='A'){ num=(now*10+p)%7; if(DP(n+1,num)==0)return dp[n][now]=0; num=(now*10)%7; if(DP(n+1,num)==0)return dp[n][now]=0; return dp[n][now]=1; }else { num=(now*10+p)%7; // printf("now=%d,num=%d\n",now,num); if(DP(n+1,num)==1)return dp[n][now]=1; num=(now*10)%7; if(DP(n+1,num)==1)return dp[n][now]=1; return dp[n][now]=0; } } int main() { memset(dp,-1,sizeof(dp)); len=read(); cin>>b; cin>>a; if(DP(0,0))puts("Takahashi"); else puts("Aoki"); return 0; }
#include<iostream> using namespace std; int main() { int X, Y, Z,count=0; cin >> X >> Y >> Z; while (Y * Z > X * count) { count++; } cout << count-1 << endl; cin >> X; return 0; }
#include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG #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 ll long long int main(){ int n, s, d; cin >> n >> s >> d; vector<vector<int>> M(n, vector<int>(2)); rep(i, n) cin >> M[i][0] >> M[i][1]; rep(i, n){ if (M[i][0] < s && M[i][1] > d){ cout << "Yes" << endl; return 0; } } cout << "No" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, a) for(int i=0;i<a;i++) #define repA(i,a,b) for(int i=a;i<b;i++) #define l list #define v vector #define u_m unordered_map #define itr iterator #define nm(a) numeric_limits<a>::max() typedef long long ll; const int mxN=2e5; ll n,arr[mxN],prime[15]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47}; ll best(bool choose[15],int index){ if(index==15){ for(ll i=0;i<n;i++){ bool did=0; for(ll j=0;j<15;j++){ if(choose[j]&&arr[i]%prime[j]==0){ did=1; break; } } if(did==0)return numeric_limits<ll>::max(); } ll idk=1; rep(i,15){if(choose[i])idk*=prime[i];} return idk; } choose[index]=0; ll ans=best(choose,index+1); choose[index]=1; return min(ans,best(choose,index+1)); } void solve(){ cin>>n; rep(i,n)cin>>arr[i]; bool empty[15]; memset(empty,0,sizeof(empty)); cout<<best(empty,0)<<endl; } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t=1; /*#ifnef ONLINEJUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif */ while(t--){ solve(); } return 0; }
#include <bits/stdc++.h> #define SORT(v, n) sort(v, v + n); #define VSORT(v) sort(v.begin(), v.end()); #define size_t unsigned long long #define ll long long #define rep(i, a) for (int i = 0; i < (a); i++) #define repr(i, a) for (int i = (int)(a)-1; i >= 0; i--) #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define FORR(i, a, b) for (int i = (int)(b)-1; i >= a; i--) #define ALL(a) a.begin(), a.end() using namespace std; int si() { int x; scanf("%d", &x); return x; } long long sl() { long long x; scanf("%lld", &x); return x; } string ss() { string x; cin >> x; return x; } void pi(int x) { printf("%d ", x); } void pl(long long x) { printf("%lld ", x); } void pd(double x) { printf("%.15f ", x); } void ps(const string &s) { printf("%s ", s.c_str()); } void br() { putchar('\n'); } const ll MOD = 1e9 + 7; const ll INF = 1e9 + 5; struct mint { int n; mint(int n_ = 0) : n(n_) {} }; mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; } mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; } mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; } mint &operator+=(mint &a, mint b) { return a = a + b; } mint &operator-=(mint &a, mint b) { return a = a - b; } mint &operator*=(mint &a, mint b) { return a = a * b; } typedef pair<int, int> P; string s, t, u; int a, b, result; int main() { cin >> a >> b; if (a + b >= 15 && b >= 8) result = 1; else if (a + b >= 10 && b >= 3) result = 2; else if (a + b >= 3) result = 3; else result = 4; cout << result << endl; }
#include <bits/stdc++.h> using namespace std; #define ar array #define ll long long const int MAX_N = 1e5 + 1; const ll MOD = 1e9 + 7; const ll INF = 1e9; void solve() { int n; cin>>n; vector<int> v(n); for(int i=0;i<n;i++){ cin>>v[i]; } sort(v.begin(),v.end()); for(int i=1;i<n-1;i++){ if(v[i]==v[i-1]){ cout<<"No\n"; return; } } cout<<"Yes\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tc = 1; // cin >> tc; for (int t = 1; t <= tc; t++) { // cout << "Case #" << t << ": "; solve(); } }
#include <bits/stdc++.h> using namespace std; #define rep(i,a,b) for(ll i=a;i<b;i++) #define pb push_back typedef long long ll; typedef long double ld; const ll INF = 9223372036854775807; const ll MOD = 1000000007; const long double PI = acos(-1); #define mp make_pair #define all(v) v.begin(), v.end() #define F first #define S second typedef vector<ll> vi; typedef map<int, int> mii; typedef vector<vi> vvi; //debugger void __print(int x) {cerr << x;} void __print(long x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(unsigned x) {cerr << x;} void __print(unsigned long x) {cerr << x;} void __print(unsigned long long x) {cerr << x;} void __print(float x) {cerr << x;} void __print(double x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << '\'' << x << '\'';} void __print(const char *x) {cerr << '\"' << x << '\"';} void __print(const string &x) {cerr << '\"' << x << '\"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifndef ONLINE_JUDGE #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif // debugger end //global variables //functions int main() { ios::sync_with_stdio(0); cin.tie(0); //int test; // cin>>test; // while(test--) // { // solve(); //} ll n; cin>>n; set<ll> s; rep(i,0,n) { ll temp; cin>>temp; if(temp>n) { cout<<"No"<<endl; return 0; } s.insert(temp); } if(s.size()==n) { cout<<"Yes"<<endl; } else { cout<<"No"<<endl; } return 0; }
#include <bits/stdc++.h> namespace IO{ char buf[1000000],*p1,*p2; inline char getc(){ if(p1==p2) p2=(p1=buf)+fread(buf,1,1000000,stdin); return p1==p2?EOF:*(p1++); } template<typename tp>inline void r(tp &n){ n=0;char c=getc(); while(!isdigit(c)) c=getc(); while( isdigit(c)) n=n*10+c-48,c=getc(); } template<typename tp>inline void w(tp n){ if(n/10) w(n/10); putchar(n%10+48); } }; using namespace IO; const int N=1e5+5; using namespace std; int n,L; long long a[N],b[N]; int main(){ //freopen("1.in","r",stdin); r(n),r(L); for(int i=1;i<=n;++i) r(a[i]); for(int i=1;i<=n;++i) r(b[i]); a[n+1]=L+1,b[n+1]=L+1; for(int i=n+1;i>=1;--i) a[i]=a[i]-a[i-1]-1,b[i]=b[i]-b[i-1]-1; long long ans=0,j=1,st=1; for(int i=1;i<=n+1;++i){ if(!b[i]) continue; while(!a[j]) ++j;st=j; long long cur=0; while(cur<b[i]&&j<=n+1) cur+=a[j++]; if(cur!=b[i]) {puts("-1");return 0;} ans+=max(0ll,j-1-i)+max(0ll,i-st); } w(ans); return 0; }
#include "bits/stdc++.h" #define MOD 998244353 #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;}; ll mod(ll a, ll mod){ ll res = a%mod; if(res<0)res=res + mod; return res; } 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; } ll modinv(ll a, ll mod){ ll b=mod, u=1, v=0; while(b){ ll t=a/b; a-=t*b; swap(a, b); u-=t*v; swap(u, v); } u%=mod; if(u<0)u+=mod; return u; } ll gcd(ll a, ll b){ ll r = a%b; if(r==0) return b; else return gcd(b, a%b); } bool is_prime(ll n){ ll i = 2; if(n==1)return false; if(n==2)return true; bool res = true; while(i*i <n){ if(n%i==0){ res = false; } i = i+1; } //if(i==1)res = false; if(n%i==0)res=false; return res; } /************************************** ** A main function starts from here ** ***************************************/ int main(){ ll a, b, c; cin >> a >> b >> c; ll A = mod((a+1)*a/2,MOD); ll B = mod((b+1)*b/2,MOD); ll C = mod((c+1)*c/2,MOD); cout << mod(mod(C*B, MOD)*A, MOD)<<endl; return 0; }
#include <iostream> using namespace std; int main() { int m, h; cin >> m >> h; cout << (h % m == 0 ? "Yes" : "No") << endl; return 0; }
#include<bits/stdc++.h> using namespace std; #define GODSPEED ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(15); #define f first #define s second #define newl cout<<"\n"; #define pb push_back #define mset(a,x) memset(a,x,sizeof(a)) #define debv(a) for(auto it: a)cout<<it<<" ";newl; #define deb1(a) cout<<a<<"\n"; #define deb2(a,b) cout<<a<<" "<<b<<"\n"; #define deb3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n"; #define deb4(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n"; #define uniq(a) a.resize(unique(a.begin(), a.end()) - a.begin()); #define all(a) a.begin(),a.end() typedef long long ll; typedef long double ld; typedef pair<ll, ll> pll; typedef vector<ll> vll; typedef vector<pll> vpll; const ll N = 2e6 + 5; const ll mod = 998244353; const ll INF = 0x7f7f7f7f7f7f7f7f; const int INFi = 0x7f7f7f7f; const ll LEVEL = log2(N) + 1; int m, h; void solve() { cin >> m >> h; if(h % m == 0) deb1("Yes") else deb1("No") } int main() { GODSPEED; int test = 1; //cin >> test; for (int i = 1; i <= test; i++) { solve(); } }
#include<bits/stdc++.h> using namespace std; using ll = long long; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; long double ed = 0; ll md = 0,cd = 0; for(int i = 0; i < n;++i){ ll x; cin >> x; cd = max(cd,abs(x)); md = md + abs(x); ed = ed + (long double)(x*x); } ed = sqrt(ed); cout << md << "\n"; cout << fixed << setprecision(15) << ed << "\n"; cout << cd << "\n"; }
#include<bits/stdc++.h> #define FOR(i,a,b) for(int i=(a); i<=(b); ++i) #define ROF(i,a,b) for(int i=(a); i>=(b); --i) #define pb push_back #define eb emplace_back #define SZ(a) (int)(a).size() #define all(a) (a).begin(), (a).end() #define make_unique(a) sort(all((a))), (a).erase(unique(all((a))),(a).end()) #define x first #define y second #define MP make_pair #define MT make_tuple #define debug(x) cout << #x << " = " << x << endl #define debug2(x,y) FOR(i,1,y) cout << "##"; cout << #x << " = " << x << endl using namespace std; typedef long long i64; typedef tuple<int,int,int> iii; typedef vector<int> vi; typedef pair<int,int> pii; typedef long double ld; int readInt(){ int a; scanf("%d",&a); return a; } i64 readLong(){ i64 a; scanf("%lld",&a); return a;} void readString(char *s){ scanf(" %s",s); } const int mod = 998244353; int add(int a, int b){ return ((a+=b)>=mod)?a-mod:a; } void adding(int &a, int b){ a = add(a,b); } int mul(int a, int b){ return a*1ll*b%mod; } int pw(int a, int b){ int res = a, ans = 1; for(int i=1;i<=b;i<<=1,res=mul(res,res)){ if(i&b) ans = mul(ans, res); } return ans; } int main(){ i64 n = readLong(); i64 ans = LLONG_MAX; FOR(i, 0, 59){ ans = min(ans, i+n/(1ll<<i)+(n&((1ll<<i)-1))); } printf("%lld",ans); return 0; } // 1
#ifdef _DEBUG #define _GLIBCXX_DEBUG #endif #if __has_include(<atcoder/all>) #include <atcoder/all> #endif #include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using P = pair<int, ll>; #define rep(i, a, b) for(int i = (int)(a); i <= (int)(b); i++) #define rrep(i, a, b) for(int i = (int)(a); i >= (int)(b); i--) const int MOD = 1000000007; const int MOD2 = 998244353; const ll INF = 1e18; const ld PI = acos(-1); class UnionFind { public: vector<int> par; vector<int> rnk; vector<ll> siz; vector<int> isequal; UnionFind(int N): par(N), rnk(N), siz(N), isequal(N){ for(int i = 0; i < N; i++){ par[i] = i, rnk[i] = 0, siz[i] = 1; } } //根 int find(int x){ if(par[x] ==x )return x; return par[x] = find(par[x]); } void unite(int x, int y){ int rx = find(x); int ry = find(y); if (rx == ry) return; if(rnk[rx] < rnk[ry]){ par[rx] = ry; siz[ry] += siz[rx]; siz[rx] = 0; } else{ par[ry] = rx; siz[rx] += siz[ry]; siz[ry] = 0; if(rnk[rx] == rnk[ry]){ rnk[rx]++; } } } //集合が同じか bool same(int x, int y){ return find(x) == find(y); } //集合の大きさ ll size(int x){ return siz[find(x)]; } }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N,Q; cin >> N; vector<ll> A(N),T(N); ll delta=0; rep(i,0,N-1){ cin >> A[i] >> T[i]; if(T[i]==1) delta+=A[i]; } cin >> Q; vector<int> X(Q); rep(i,0,Q-1){ cin >> X[i]; } ll mx=INF,mn=-INF; rep(i,0,N-1){ if(T[i]==1){ mx+=A[i]; mn+=A[i]; } else if(T[i]==2){ mx=max(A[i],mx); mn=max(A[i],mn); } else if(T[i]==3){ mx=min(A[i],mx); mn=min(A[i],mn); } } /*cout << delta << endl; cout << mx << ' ' << mn << endl;*/ rep(i,0,Q-1){ if(X[i]+delta>=mx){ cout << mx << endl; } else if(X[i]+delta<=mn){ cout << mn << endl; } else{ cout << X[i]+delta << endl; } } }
#pragma GCC optimize ("O2") #pragma GCC target ("avx2") //#include<bits/stdc++.h> //#include<atcoder/all> //using namespace atcoder; #include<iostream> #include<cstring> using namespace std; typedef long long ll; #define rep(i, n) for(int i = 0; i < (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define Would #define you #define please const int mod = 998244353; const int CM = 1 << 17, CL = 12; char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct; const ll ma0 = 1157442765409226768; const ll ma1 = 1085102592571150095; const ll ma2 = 71777214294589695; const ll ma3 = 281470681808895; const ll ma4 = 4294967295; inline int getint() { if (ci - owa > 0) { memcpy(cn, owa, CL); ci -= CM; fread(cn + CL, 1, CM, stdin); } int pn = 1; if (*ci == '-') { pn = -pn; ci++; } ll tmp = *(ll*)ci; if ((tmp & ma0) ^ ma0) { int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0); tmp = tmp << dig & ma1; tmp = tmp * 10 + (tmp >> 8) & ma2; tmp = tmp * 100 + (tmp >> 16) & ma3; tmp = tmp * 10000 + (tmp >> 32) & ma4; ci += (72 - dig >> 3); } else { tmp = tmp & ma1; tmp = tmp * 10 + (tmp >> 8) & ma2; tmp = tmp * 100 + (tmp >> 16) & ma3; tmp = tmp * 10000 + (tmp >> 32) & ma4; ci += 8; if ((ct = *ci++) >= '0') { tmp = tmp * 10 + ct - '0'; if (*ci++ == '0') { tmp = tmp * 10; ci++; } } } return pn * tmp; } //constexprあり16桁まで const int MAX = 10000; class shuturyoku_unko { public: char C[MAX * 5]; constexpr shuturyoku_unko() : C() { rep(i, MAX) { int X = i; rep(j, 4) { C[i * 5 + 3 - j] = '0' + X % 10; X /= 10; } C[i * 5 + 4] = '\n'; } } }; constexpr shuturyoku_unko f; const int dm = 1 << 17; char dn[dm], * di = dn, * owad = dn + dm - 20; void putint(ll A) { if (owad < di) { fwrite(dn, 1, di - dn, stdout); di = dn; } if (A < 0) { A = -A; *di++ = '-'; } int dig = 1; if (A >= 100000000) { if (A >= 1000000000000) { if (A >= 1000000000000000) dig = 4; else if (A >= 100000000000000) dig = 3; else if (A >= 10000000000000) dig = 2; memcpy(di + 8 + dig, f.C + A % 10000 * 5, 5); A /= 10000; memcpy(di + 4 + dig, f.C + A % 10000 * 5, 4); A /= 10000; memcpy(di + dig, f.C + A % 10000 * 5, 4); memcpy(di, f.C + A / 10000 * 5 + 4 - dig, dig); di += 13 + dig; } else { if (A >= 100000000000) dig = 4; else if (A >= 10000000000) dig = 3; else if (A >= 1000000000) dig = 2; memcpy(di + 4 + dig, f.C + A % 10000 * 5, 5); A /= 10000; memcpy(di + dig, f.C + A % 10000 * 5, 4); memcpy(di, f.C + A / 10000 * 5 + 4 - dig, dig); di += 9 + dig; } } else { if (A >= 10000) { if (A >= 10000000) dig = 4; else if (A >= 1000000) dig = 3; else if (A >= 100000) dig = 2; memcpy(di + dig, f.C + A % 10000 * 5, 5); memcpy(di, f.C + A / 10000 * 5 + 4 - dig, dig); di += 5 + dig; } else { if (A >= 1000) dig = 4; else if (A >= 100) dig = 3; else if (A >= 10) dig = 2; memcpy(di, f.C + A * 5 + 4 - dig, dig + 1); di += 1 + dig; } } } int main() { cin.tie(0); ios::sync_with_stdio(false); int N = getint(); ll L = -1e16, R = 1e16; ll ima = 0; rep(i, N) { int a = getint(); char t = *ci; ci += 2; if (t == '1') { ima += a; } else if (t == '2') { if (L < a - ima) L = a - ima; if (R < L) R = L; } else { if (a - ima < R) R = a - ima; if (R < L) L = R; } } int Q = getint(); rep(i, Q) { ll tmp = getint(); if (tmp > R) tmp = R; if (tmp < L) tmp = L; putint(tmp + ima); } fwrite(dn, 1, di - dn, stdout); Would you please return 0; }
#include <bits/stdc++.h> using namespace std; int main() { unsigned long long n, res = 1e18; cin >> n; for (int i = 63; i >= 0; i--) res = min(res, n / (1ll << i) + i + n % (1ll << i)); cout << res; }
#include <bits/stdc++.h> using namespace std; typedef multiset<string> mss; typedef map<int, int> mii; typedef set<string> ss; typedef vector<int> vi; int main(void){ string S; cin >> S; string T; bool isReverse = false; for(int i = 0; i < S.size(); i++) { if(S[i] == 'R') isReverse = !isReverse; else { if(isReverse) { T = S[i] + T; int l = T.size(); if(l > 1 && T[0] == T[1]) { // console.log(T.substr(0, l-2)) T = T.substr(2); } } else { T += S[i]; int l = T.size(); if(l > 1 && T[l-2] == T[l-1]) { // console.log(T.substr(0, l-2)) T = T.substr(0, l-2); } } } } auto print = [](string s, bool isReverse) { if(isReverse) { reverse(s.begin(), s.end()); for(char c: s) cout << c; } else { for(char c: s) cout << c; } }; print(T, isReverse); }
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "dump.hpp" #else #define dump(...) #define dumpv(...) #endif #define rep(i, n) for (int i = 0; i < (n); i++) #define mins(x, y) (x = min(x, y)) #define maxs(x, y) (x = max(x, y)) using ll = long long; using vi = vector<int>; using vl = vector<ll>; using vvi = vector<vi>; using vvl = vector<vl>; using P = pair<int, int>; const int MOD = 1e9 + 7; const int INF = 1001001001; const ll LINF = 1001002003004005006ll; enum queryType { SUM, MAX, MIN }; template<typename T> struct SegTree { int n; T init; // 単位元(初期値) vector<T> node; function<T(T&, T&)> calc; // 子ノード2つから親ノードのデータにする処理 SegTree(int sz, queryType qtype) : n(1) { // 初期値と処理関数の設定 switch (qtype) { case SUM: init = 0; calc = [](T& v1, T& v2) { return v1 + v2; }; break; case MAX: init = std::numeric_limits<T>::lowest(); calc = [](T& v1, T& v2) { return (v1 > v2) ? v1 : v2; }; break; case MIN: init = std::numeric_limits<T>::max(); calc = [](T& v1, T& v2) { return (v1 < v2) ? v1 : v2; }; break; } while (n < sz) n *= 2; // 最下段のノード数は2のべき乗(n) node.resize(2 * n - 1, init); // セグメント木全体で必要なノード数は2n-1個である } SegTree(vector<T>& v, queryType qtype) : SegTree(v.size(), qtype) { // 最下段に値を入れたあとに、下の段から順番に値を入れる // 値を入れるには、自分の子の2値を参照すれば良い // ノードiの親は(i-1)/2、子は(2i+1,2i+2)で見つける for (int i = 0; i < v.size(); i++) node[i + n - 1] = v[i]; for (int i = n - 2; i >= 0; i--) node[i] = calc(node[2 * i + 1], node[2 * i + 2]); } void update(int i, T v) { i += (n - 1); // 最下段のノードにアクセスする // 最下段のノードを更新したら、あとは親に上って更新していく node[i] = v; while (i > 0) { i = (i - 1) / 2; // 1つ親にする node[i] = calc(node[2 * i + 1], node[2 * i + 2]); } } // 要求区間 [a, b) 中の要素の最小値を答える // k := 自分がいるノードのインデックス、対象区間は [l, r) にあたる T query(int a, int b, int k = 0, int l = 0, int r = -1) { // 最初に呼び出されたときの対象区間は [0, n) if (r < 0) r = n; // 要求区間と対象区間が交わらない -> 適当に返す if (r <= a || b <= l) return init; // 要求区間が対象区間を完全に被覆 -> 対象区間を答えの計算に使う if (a <= l && r <= b) return node[k]; // 要求区間が対象区間の一部を被覆 -> 子について探索を行う // 左側の子を vl ・ 右側の子を vr としている // 新しい対象区間は、現在の対象区間を半分に割ったもの T vl = query(a, b, 2 * k + 1, l, (l + r) / 2); T vr = query(a, b, 2 * k + 2, (l + r) / 2, r); return calc(vl, vr); } }; void solve() { int n; cin >> n; vi a(n); rep(i, n) cin >> a[i]; vl c(n + 1); vl m(n + 1); rep(i, n) c[i + 1] += c[i] + a[i]; rep(i, n) m[i + 1] = max(m[i], c[i] + a[i]); dump(a); dump(c); dump(m); ll x = 0; ll ans = -INF; rep(i, n) { ll nx = x + m[i]; maxs(ans, nx); x += c[i + 1]; maxs(ans, x); } cout << ans << endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); // freopen("temp.1", "r", stdin); solve(); return 0; }
#include <iostream> #include <vector> #include <cmath> #include <algorithm> using namespace std; typedef long long ll; ll mod = 1000000007; int main() { ll N,cnt=0,S = 0; cin >> N; vector<ll> A(N); for(int i=0; i<N; i++){ cin >> A[i]; S += A[i]; } sort(A.begin(),A.end()); for(int i=0; i<N-1; i++){ S -= A[i]; cnt += S - (A[i] * (N-i-1)); } cout << cnt; }
//bismillahir rahmanir rahim //@uthor : mubin_akib #pragma GCC optimize ("O3") #pragma GCC target ("sse4") #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef complex<ld> cd; typedef pair <int, int> pi; typedef pair<ll, ll> pl; typedef pair<ld, ld> pd; typedef vector<int> vi; typedef vector<ld> vd; typedef vector<ll> vl; typedef vector<pi> vpi; typedef vector<pl> vpl; typedef vector<cd> vcd; #define FOR(i, a, b) for (int i = a; i < (b); i++) #define F0R(i, a) for (int i = 0; i < (a); i++) #define FORd(i,a,b) for (int i = (b) - 1; i >= a; i--) #define F0Rd(i,a) for (int i = (a) - 1; i >= 0; i--) #define REP(i, a, b) for(int i = (a); i <= (b); ++i) #define trav(a,x) for(auto& a : x) #define sz(x) (int)(x).size() #define mp make_pair #define pb push_back #define eb emplace_back #define fi first #define se second #define lb lower_bound #define ub upper_bound #define all(x) x.begin(), x.end() #define ins insert template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int mod = 1e9 + 7; const char nl = '\n'; const int N = 10005; void solve() { string n; ll k; cin >> n >> k; while(k--){ if(stoll(n) % 200 == 0){ n = to_string(stoll(n) / 200); } else{ n += "200"; } } cout << n << nl; } int main() { #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(0); cin.tie(0); solve(); // int t; // cin >> t; // while(t--){ // solve(); // } return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long #define mod 1000000007 #define endl "\n" #define scan(a) scanf("%d", &a) #define print(a) printf("%d\n", a) int modadd(int a, int b,int MOD = mod){ return((a%MOD)+(b%MOD)+MOD)%MOD; } int modsub(int a, int b,int MOD = mod){ return((a%MOD) - (b%MOD) + MOD)%MOD; } void fast (void) __attribute__ ((constructor)); void fast (void) { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); } void solve(){ int N; cin>>N; vector<vector<int>> A(N,vector<int>(5)); // vector A(N, array<int, 5>{}); for(auto &a:A) for(int &i:a) cin>>i; int ok=0,ng=1000000001; auto check = [&](int x)->bool { set<int> s; for(auto &a:A){ int bit=0; for(int &i:a){ bit <<= 1; bit |= i>=x; } s.insert(bit); } for(int x:s) for(int y:s) for(int z:s){ //if all 5 bits are set if((x|y|z)==31) return 1; } return 0; }; while(abs(ok-ng)>1){ int cen = (ok+ng)/2; (check(cen) ? ok : ng) = cen; } cout<<ok<<endl; } signed main (void) { // int t; cin>>t; // while(t--) { solve(); cout<<"\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define lli long long int #define tc int t;cin>>t;while(t--) #define all(x) x.begin(),x.end() #define f first #define s second #define pb push_back #define pi pair<int,int> #define pll pair<lli,lli> #define vi vector<int> #define vll vector<lli> #define vpi vector<pair<int,int> > #define vpll vector<pair<lli,lli> > #define vvi vector<vector<int> > #define vvll vector<vector<lli> > #define vvpi vector<vector<pair<int,int> > > #define vvpll vector<vector<pair<lli,lli> > > #define inf 1000000000 #define maxn 1005 lli mod=998244353; int main(){ fastio; lli n; cin>>n; lli sm=0; for(int i=1;i<=n;i++){ sm+=i; if(sm>=n) { cout<<i<<"\n"; break; } } return 0; }
#include<bits/stdc++.h> //#include<ext/pb_ds/assoc_container.hpp> //#include<ext/pb_ds/tree_policy.hpp> //#include <ext/pb_ds/trie_policy.hpp> //using namespace __gnu_pbds; using namespace std; #define ll long long int #define ld long double #define mod 1000000007 #define inf 1e18 #define endl "\n" #define pb push_back #define vi vector<int> #define vl vector<ll> #define vs vector<string> #define pii pair<ll,ll> #define ump unordered_map #define mp make_pair #define pq_max priority_queue<ll> #define pq_min priority_queue<ll,vi,greater<ll> > #define all(n) n.begin(),n.end() #define ff first #define ss second #define mid(l,r) (l+(r-l)/2) #define bitc(n) __builtin_popcount(n) #define loop(i,a,b) for(int i=(a);i<=(b);i++) #define looprev(i,a,b) for(int i=(a);i>=(b);i--) #define iter(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++) #define log(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); } #define logarr(arr,a,b) for(int z=(a);z<=(b);z++) cout<<(arr[z])<<" ";cout<<endl; #define M 1000000007 #define w(x) int x; cin>>x; while(x--) template <typename T> T gcd(T a, T b) {if (a % b) return gcd(b, a % b); return b;} template <typename T> T lcm(T a, T b) {return (a * (b / gcd(a, b)));} vs tokenizer(string str, char ch) {std::istringstream var((str)); vs v; string t; while (getline((var), t, (ch))) {v.pb(t);} return v;} void err(istream_iterator<string> it) {} template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cout << *it << " = " << a << endl; err(++it, args...); } //typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds; //typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update> pbtrie; void file_i_o() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } ll calc(ll k) { return k * (k + 1) / 2; } int main(int argc, char const *argv[]) { clock_t begin = clock(); file_i_o(); // Write your code here.... ll n; cin >> n; loop(i, 1, n) { if (calc(i) >= n) { cout << i << endl; break; } } #ifndef ONLINE_JUDGE clock_t end = clock(); cout << "\n\nExecuted In: " << double(end - begin) / CLOCKS_PER_SEC * 1000 << " ms"; #endif return 0; }
#include <bits/stdc++.h> using namespace std; #define repr(i, a, b) for (int i = a; i < b; i++) #define rep(i, n) for (int i = 0; i < n; i++) typedef long long ll; typedef pair<ll,ll> P; #define mod 1000000007 ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;} ll lcm(ll x,ll y) {return x/gcd(x,y)*y;} int main(){ ll n; string s,t; cin >> n >> s >> t; ll kazu_s=0,kazu_t=0; rep(i,n){ if(s[i]=='0') kazu_s++; if(t[i]=='0') kazu_t++; } if(kazu_s!=kazu_t){ cout << -1 << endl; return 0; } vector<ll> ss; vector<ll> tt; rep(i,n){ if(s[i]=='0') ss.push_back(i); if(t[i]=='0') tt.push_back(i); } ll ans=0; rep(i,ss.size()){ if(ss[i]!=tt[i]) ans++; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define f first #define s second #define sz size() #define ll long long #define all(_v) _v.begin(), _v.end() #define pii pair <int, int> #define pll pair <ll, ll> #define pvllvll pair <vector <ll>, vector <ll> > #define ld long double #define veci vector <int> #define vecll vector <ll> const int dx[4] = {1, -1, 0, 0}; const int dy[4] = {0, 0, -1, 1}; const double PI = 3.1415926535897932384626433832795; const double eps = 1e-9; const int MOD1 = 1e9 + 7; const int MOD2 = 998244353; void solve() { int a[4]; cin >> a[0] >> a[1] >> a[2] >> a[3]; int n = 4; bool ch = 0; for(int i = 0; i < n; ++i) { for(int j = 0; j < n; ++j) { if(i == j) continue; for(int k = 0; k < n; ++k) { if(i == k || j == k) continue; for(int z = 0; z < n; ++z) { if(i == z || k == z || j == z) continue; if(a[k] == a[i] + a[j] + a[z] || a[i] + a[j] == a[k] + a[z]) { ch = 1; } } } } } if(!ch) cout << "No"; else cout << "Yes"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int T = 1; ///cin >> T; while(T--) solve(), cout << '\n'; return 0; }
#define _USE_MATH_DEFINES #include<iostream> #include<vector> #include<algorithm> #include<cmath> #include<string> #include<iomanip> #include<cassert> #include<functional> typedef long long ll; int main(){ std::ios::sync_with_stdio(false); std::cin.tie(0); int n; int x; std::string s; std::cin >> n >> x >> s; for (int i = 0; i < n; i++){ if (s.at(i) == 'o'){ x += 1; } else{ x -= 1; if (x < 0){ x = 0; } } } std::cout << x << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for(int i = a; i < b; ++i) int debug = 0; const int N = 2010, inf = 1e9; int n, m, ans, dp[N][N]; vector <int> g[26][N]; main() { cin >> n >> m; rep(i, 1, n + 1) { rep(j, 1, n + 1) { if (i == j) { dp[i][j] = 0; } else { dp[i][j] = inf; } } } rep(i, 0, m) { int a, b, c; char cc; cin >> a >> b >> cc; c = cc - 'a'; if (debug) { cerr << " edge: " << a << ' ' << b << ' ' << cc << endl; } g[c][a].push_back(b); g[c][b].push_back(a); if (a != b) dp[a][b] = dp[b][a] = 1; } set <array <int, 3>> d; rep(i, 1, n + 1) rep(j, i, n + 1) { d.insert({dp[i][j], i, j}); } while (!d.empty()) { auto cur = *d.begin(); d.erase(cur); int w = cur[0], a = cur[1], b = cur[2]; if (debug) cerr << w << ' ' << a << ' ' << b << '\n'; assert(a <= b); if (w == inf) break; rep(c, 0, 26) { for (int u : g[c][a]) for (int v : g[c][b]) { int uu = u, vv = v; if (uu > vv) swap(uu, vv); if (dp[uu][vv] > w + 2) { d.erase({dp[uu][vv], uu, vv}); dp[uu][vv] = w + 2; d.insert({dp[uu][vv], uu, vv}); } } } } if (dp[1][n] == inf) { ans = -1; } else { ans = dp[1][n]; } cout << ans << '\n'; }
#include <bits/stdc++.h> using namespace std; enum { NONE, BLUB, BLOCK }; int main(int argc, char *argv[]) { cin.sync_with_stdio(false), cin.tie(nullptr); int H, W, N, M; cin >> H >> W >> N >> M; vector<vector<int>> grid(H, vector<int>(W, NONE)); for (int i = 0; i < N; i++) { int x, y; cin >> x >> y; grid[x - 1][y - 1] = BLUB; } for (int i = 0; i < M; i++) { int x, y; cin >> x >> y; grid[x - 1][y - 1] = BLOCK; } vector<vector<bool>> visited(H, vector<bool>(W, false)); for (int i = 0; i < H; i++) { int lastBlub = -1, lastBlock = -1; for (int j = 0; j < W; j++) { if (grid[i][j] == BLUB) { for (int k = lastBlock + 1; k <= j; k++) { visited[i][k] = true; } lastBlock = lastBlub = j; } if (grid[i][j] == BLOCK && lastBlub != -1) { for (int k = lastBlub + 1; k < j; k++) { visited[i][k] = true; } } if (grid[i][j] == BLOCK) { lastBlub = -1, lastBlock = j; } } if (lastBlub != -1) { for (int j = lastBlub + 1; j < W; j++) { visited[i][j] = true; } } } for (int j = 0; j < W; j++) { int lastBlub = -1, lastBlock = -1; for (int i = 0; i < H; i++) { if (grid[i][j] == BLUB) { for (int k = lastBlock + 1; k <= i; k++) { visited[k][j] = true; } lastBlub = lastBlock = i; } if (grid[i][j] == BLOCK && lastBlub != -1) { for (int k = lastBlub + 1; k < i; k++) { visited[k][j] = true; } } if (grid[i][j] == BLOCK) { lastBlub = -1, lastBlock = i; } } if (lastBlub != -1) { for (int i = lastBlub + 1; i < H; i++) { visited[i][j] = true; } } } int ans = 0; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { ans += visited[i][j]; } } cout << ans << "\n"; }
#include<bits/stdc++.h> using namespace std; const long long INF = 1000000000; typedef long long ll; #define rep(i,n) for(int i=0; i<(n); ++i) typedef pair<ll, ll> P; typedef pair<string, int> Psi; vector<int> G[2100]; ll visited[2100]; ll ct=0; void dfs(int from){ for(int j=0;j<G[from].size(); j++){ // cout<<from<<":"<<G[from][j]<<endl; if(visited[G[from][j]] !=1){ visited[from]=1; visited[G[from][j]]=1; // cout<<G[from][j]<<endl; ct++; dfs(G[from][j]); } } } int main() { cin.tie(0); ios::sync_with_stdio(false); int n,m;cin>>n>>m; for(int i=0; i<m; i++){ int from,to;cin>>from>>to; G[from].push_back(to); } ll ans =0; for(int i=1; i<=n; i++){ ct=1; for(int a=0; a<2005; a++){ visited[a]=0; } dfs(i); ans +=ct; } cout<<ans<<endl; }
#include <bits/stdc++.h> using namespace std; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int x, y; cin >> x >> y; int z = (x > y ? y - x : x - y) + 3; if (z > 0) cout << "Yes"; else cout << "No"; }
#include<bits/stdc++.h> using namespace std; #define f(t) ll t; cin>>t; while(t--) #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define vec vector<ll> #define vecpair vector<pair<ll,ll>> using ll = long long; using ld = long double; const int N = 2e5 + 5; int main(){ IOS; int x,y; cin>>x>>y; if(abs(x-y)>=3){ cout<<"No"<<endl; } else{ cout<<"Yes"<<endl; } }
#include<bits/stdc++.h> #define rep(i,n) for (int i=0; i<n; i++) #define REP(i,x,n) for (int i=x; i<n; i++) #define P pair<int,int> using namespace std; using vi = vector<int>; using vvi = vector<vi>; using ll = long long; #define T tuple<int, int, int> #define PP pair<P,P> #define ALL(a) a.begin(), a.end() int main(){ int n; cin >> n; vector<PP> inputData; rep(i,n){ int x, y, r; cin >> x >> y >> r; PP p = PP(P(r,i),P(x,y)); inputData.push_back(p); } sort(ALL(inputData)); // for (auto p : inputData){ // printf("%d %d %d %d\n", p.first.first, p.first.second, p.second.first, p.second.second); // } vector<PP> outputData(n); //広告は最低でも1の面積を持つので面積1で初期化 rep(i,n){ int index, x, y; index = inputData[i].first.second; x = inputData[i].second.first; y = inputData[i].second.second; outputData[index] = PP(P(x,y),P(x+1, y+1)); } rep(i,n){ int r, index, x, y; r = inputData[i].first.first; index = inputData[i].first.second; x = inputData[i].second.first; y = inputData[i].second.second; vector<P> divisors; //rについて約数列挙 for (int i=1; i*i<=r; i++){ if (r % i == 0){ divisors.push_back(P(i,r/i)); } } //交差検出 int m = divisors.size(); bool missFlag = true; rep(j,m){ bool jadge = true; int vertical = divisors[j].first; int heng = divisors[j].second; //広告がはみ出すならbreak; if (x + vertical > 1e4) continue; if (y + heng > 1e4) continue; rep(k,(int)outputData.size()){ if (k == index) continue; int a1 = outputData[k].first.first; int a2 = outputData[k].first.second; int b1 = outputData[k].second.first; int b2 = outputData[k].second.second; if (a1<=x && x<=b1 && a2<=y && y<=b2) jadge = false; if (a1<=x+vertical && x+vertical<=b1 && a2<=y+heng && y<=b2+heng) jadge = false; // if (x<=a1 && a1<=x+vertical && y<=a2 && a2<=y+heng) jadge = false; // if (x<=b1 && b1<=x+vertical && y<=b2 && b2<=y+heng) jadge = false; if (x<a1 && x+vertical>b1 && y>a2 && y+heng<b2) jadge = false; if (x<=b1 && b1<=x+vertical && y<=a2 && a2<=y+heng) jadge = false; if (x<=a1 && a1<=x+vertical && y<=b2 && b2<=y+heng) jadge = false; } //入れることができるなら広告を入れる. if (jadge){ missFlag = false; outputData[index] = PP(P(x,y),P(x+vertical,y+heng)); break; } } if (missFlag){ r /= 2; if (r <= 1e2){ continue; } PP p = PP(P(r,index),P(x,y)); inputData.push_back(p); n++; } } for (auto p : outputData){ printf("%d %d %d %d\n", p.first.first, p.first.second, p.second.first, p.second.second); } }
#include <bits/stdc++.h> using namespace std; #define PI 3.14159265358979323846264338327950L const int Limit = 10000; tuple<long long,long long,long long> T; int main(void) { int n; cin >> n; vector<long long> x(n), y(n), r(n); vector<long long> a(n), b(n), c(n), d(n); vector<int>X(Limit + 5, -1); vector<int>Y(Limit + 5, -1); for (int i = 0; i < n; i++) { cin>>x[i]>>y[i]>>r[i]; } for (int i = 0; i < n; i++) { a[i] = x[i]; b[i] = y[i]; c[i] = x[i]+1; d[i] = y[i]+1; } for (int i = 0; i < n; i++) { for (int j = a[i]; j <= b[i]; j++) { X[j] = i; } for (int j = c[i]; j <= d[i]; j++) { Y[j] = i; } } for (long long loop = 0; loop < 50000; loop++) { for (int i = 0; i < n; i++) { double tmp = (b[i] - a[i])*(d[i]-c[i]); // if(tmp > r[i]){ // continue; // } // //割当が大きすぎるので縮小させる // if(loop%2 ==0){ // //X軸方向だけを縮小 // if (0 <= a[i] + 1 && a[i] + 1 <= Limit && X[a[i] + 1]==i &&a[i]+1 < x[i]) { // X[a[i]] = -1; // a[i] = a[i] + 1; // } // if (0 <= c[i] - 1 && c[i] - 1 <= Limit && X[c[i] - 1]==i && c[i] - 1 > x[i]) { // X[c[i]] = -1; // c[i] = c[i] - 1; // } // }else{ // //Y軸方向だけを縮小 // if (0 <= b[i] + 1 && b[i] + 1 <= Limit && Y[b[i] + 1]==i && b[i] + 1 < y[i]) { // Y[b[i]] = -1; // b[i] = b[i] + 1; // } // if (0 <= d[i] - 1 && d[i] - 1 <= Limit && Y[d[i] - 1]==i && d[i] - 1 > y[i]) { // Y[d[i] ] = -1; // d[i] = d[i] - 1; // } // } // }else{ //割当を大きくする if (0 <= a[i] - 1 && a[i] - 1 <= Limit && X[a[i] - 1] == -1) { a[i] = a[i] - 1; X[a[i]] = i; } if (0 <= c[i] + 1 && c[i] + 1 <= Limit && X[c[i] + 1]== -1) { c[i] = c[i] + 1; X[c[i]] = i; } if (0 <= b[i] - 1 && b[i] - 1 <= Limit && Y[b[i] - 1]== -1) { b[i] = b[i] - 1; Y[b[i]] = i; } if (0 <= d[i] + 1 && d[i] + 1 <= Limit && Y[d[i] + 1]== -1) { d[i] = d[i] + 1; Y[d[i] ] = i; } } } for (int i = 0; i < n; i++) { cout << a[i] << " " << b[i] << " " << c[i] << " " << d[i] << endl; } return 0; }
// #pragma GCC optimize("Ofast,unroll-loops") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") #include <bits/stdc++.h> #define ll long long int #define vi vector<int> #define vvi vector<vector<int>> #define vll vector<long long> #define vs vector<string> #define vc vector<char> #define vb vector<bool> #define forn(i, s, n) for(ll i=(ll)s; i<(ll)(n); i++) #define all(c) c.begin(),c.end() #define pb push_back #define pll pair<long long int, long long int> #define pii pair<int, int> #define lld long double #define F first #define S second #define PI 3.141592653589793238 #define prec(n) fixed<<setprecision(n) #define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr) #define itsval(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); itval(_it, args); } using namespace std; // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; void itval(istream_iterator<string> it) {} template<typename T, typename... Args> void itval(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; itval(++it, args...); } const ll MOD = 1e9 + 7; template <typename T> inline void print(T x) {cout << x << "\n";} template <typename T> inline void printvec(T x) {for (auto a : x)cout << a << ' '; cout << '\n';} // ----------------------------------------------------------------------- struct custom { bool operator()(const pair<int, pii> &p1, const pair<int, pii> &p2)const { if (p1.F == p2.F) return p1.S.F > p2.S.F; return p1.F > p2.F; } }; // Calculate a^b % MOD ------------------------------------------------- ll get_pow(ll a, ll b, ll M = MOD) { ll res = 1; while (b) { if (b & 1) res = (res * a) % M; a = (a * a) % M; b >>= 1; } return res; } // --------------------------------------------------------------------- const ll N = 3e5 + 5, inf = 2e9; std::vector<pii> adj[N]; int a[502][502], b[502][502], ind[502][502], dist[N]; void solve() { int R, C; cin >> R >> C; forn(i, 1, R + 1) { forn(j, 1, C) { cin >> a[i][j]; } } forn(i, 1, R) { forn(j, 1, C + 1) cin >> b[i][j]; } forn(i, 1, R + 1) { forn(j, 1, C + 1) { ind[i][j] = j + C * i; dist[ind[i][j]] = inf; } } forn(i, 1, R + 1) { forn(j, 1, C + 1) { if (j < C) { adj[ind[i][j]].pb({a[i][j], ind[i][j + 1]}); } if (j > 1) { adj[ind[i][j]].pb({a[i][j - 1], ind[i][j - 1]}); } if (i < R) { adj[ind[i][j]].pb({b[i][j], ind[i + 1][j]}); } forn(k, 1, i) { adj[ind[i][j]].pb({1 + k, ind[i - k][j]}); } } } dist[ind[1][1]] = 0; set<pii>s; s.insert({0, ind[1][1]}); while (!s.empty()) { pll t = *s.begin(); s.erase(s.begin()); for (auto x : adj[t.S]) { if (dist[x.S] > x.F + t.F) { s.erase({dist[x.S], x.S}); dist[x.S] = x.F + t.F; s.insert({dist[x.S], x.S}); } } } cout << dist[ind[R][C]] << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int test = 1; clock_t z = clock(); //cin >> test; forn(tes, 0, test) { solve(); } debug("Total Time:%.4f\n", (double)(clock() - z) / CLOCKS_PER_SEC); return 0; }
// #include <atcoder/all> #include <bits/stdc++.h> #define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++) #define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--) #define rep(i, n) FOR(i, 0, n) #define ALL(x) begin(x), end(x) using namespace std; using ll = long long; constexpr ll Mod = 998244353; constexpr ll mod = 1e9 + 7; constexpr ll inf = 1LL << 60; const double PI = acos(-1); 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); } /*-------------------------------------------*/ int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int a, b; cin >> a >> b; int y = (a - b) / 2; int x = a - y; cout << x << " " << y << endl; return 0; }
#include <bits/stdc++.h> #define ll long long #define pb push_back #define pp pop_back #define mp make_pair #define bb back #define ff first #define ss second using namespace std; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int a, b; cin >> a >> b; cout << a*(a+1)/2*100*b + a*b*(b+1)/2 << '\n'; return 0; }
#include<bits/stdc++.h> using namespace std; #define ll long long #define deb(x) cout << #x << "=" << x << endl #define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl #define pb push_back #define mp make_pair #define fi first #define se second #define all(x) x.begin(), x.end() #define allr(x) x.rbegin(), x.rend() #define clr(x) memset(x, 0, sizeof(x)) #define sortall(x) sort(all(x)) #define sortallr(x) sort(allr(x)) #define PI 3.1415926535897932384626 #define mod 1000000007 typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpii; typedef vector<pll> vpl; typedef vector<vi> vvi; typedef vector<vl> vvl; void solve() { int n,k; cin>>n>>k; int sum=0; for(int i=1;i<=n;i++) for(int j=1;j<=k;j++) { int no=i*100; no+=j; sum+=no; } cout<<sum; } int main(void) { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; int main(){ double n; cin >> n; double x=0; for (double i=1;i<n;i++){ x+=n/i; } cout << fixed << setprecision(10) << x << endl; }
#include <bits/stdc++.h> #define ll long long #define pb push_back #define mod 1000000007 #define F first #define S second #define all(v) (v).begin(),(v).end() #define np next_permutation #define lp(i,n) for(int i=0;i<n;i++) #define lps(i,j,n) for(int i=j;i<n;i++) #define vii vector<vi> #define vb vector<bool> #define pr pair<int,int> #define vl vector<ll> #define vs vector<string> #define us unordered_map<int,int> #define Mpq priority_queue<int> #define mpq priority_queue<int,vi,greater<int>> #define eb emplace_back #define pr pair<int,int> #define prl pair<ll,ll> #define vp vector<pr> #define vpl vector<prl> #define mkp make_pair #define ld long double #define vii vector<vi> #define Max(a,b) a=max(a,b) #define Min(a,b) a=min(a,b) #define ull unsigned long long #define prr pair<ll,int> #define inf (int)1e9+111 #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; using vi=vector<int>; typedef tree< pair <int,int>, null_type, less<pair <int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; ordered_set s; #define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s)) #define F_OR1(e) F_OR(i, 0, e, 1) #define F_OR2(i, e) F_OR(i, 0, e, 1) #define F_OR3(i, b, e) F_OR(i, b, e, 1) #define F_OR4(i, b, e, s) F_OR(i, b, e, s) #define GET5(a, b, c, d, e, ...) e #define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1) #define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__) #define EACH(x, a) for (auto& x: a) template<class T> using pqg = priority_queue<T,vector<T>,greater<T>>; double epsilon=(double)1e-9; const int N=3e5+123; ll n,m,k,x,y,t,sum,prev_e,tot,val,pos=1; ll last_room,rooms; string pattern,word; const int Max=(int)1e5; int ver[4]={1,-1,0,0},hor[4]={0,0,1,-1}; string MV="DURL",moves; const ll MX=(ll)1e16+123; template<int N> struct Dij{ ll d[N]; vector<pair<ll,prl>> g[N]; pqg<prl> q; void addEdge(ll a,ll b,ll c,ll d){ g[a].pb(make_pair(b,make_pair(c,d))); g[b].pb(make_pair(a,make_pair(c,d))); } void algo(int s){ fill_n(d,N,MX); q=pqg<prl>(); q.push({d[s]=0,s}); while(!q.empty()){ auto x=q.top(); q.pop(); if(d[x.S]<x.F) continue; for(auto &y:g[x.S]){ ll distance=ceil((double)x.F/(double)y.S.S)*y.S.S+y.S.F; if(distance<d[y.F]){ q.push({d[y.F]=distance,y.F}); } } } } }; Dij<N> D; void solve(){ int n; double ans=0; cin>>n; lps(i,1,n){ ans+=(double)n/(double)(n-i); } cout<<setprecision(15)<<fixed; cout<<ans<<"\n"; } int main(){ ios_base::sync_with_stdio(0); cin.tie(nullptr); solve(); return 0; }
#include<bits/stdc++.h> using namespace std; #define int long long int32_t main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); int t; cin>>t; while(t--){ int n; cin>>n; map<int,int> mp; for(int i=0;i<n;i++){ int x; cin>>x; mp[x]++; } if(n&1){ cout<<"Second"<<"\n"; continue; } bool all_even = true; for(pair<const int,int> &p : mp){ if(p.second&1){ all_even = false; break; } } if(all_even){ cout<<"Second"<<"\n"; } else { cout<<"First"<<"\n"; } } return 0; }
#include <bits/stdc++.h> #define For(i, l, r) for (register int i = l, _r = r; i <= _r; ++i) #define Ford(i, l, r) for (register int i = r, _l = l; i >= _l; --i) using namespace std; typedef long long ll; #define pii pair<int, int> #define mk make_pair const int N = 1e5 + 20; const int mod = 1e9 + 7; int T, n, a[N]; ll sum, tot; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = (x << 3) + (x << 1) + ch - '0'; ch = getchar(); } return x * f; } int main() { int t = read(); while (t--) { sum = tot = 0; n = read(); For(i, 1, n) a[i] = read(); sort(a + 1, a + 1 + n); if (n & 1) { For(i, 2, n) i & 1 ? sum += a[i] : tot += a[i]; sum += a[1]; puts(sum ^ tot ? "Second" : "First"); } else { For(i, 1, n) i & 1 ? sum += a[i] : tot += a[i]; puts(sum ^ tot ? "First" : "Second"); } } return 0; }
#pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target("avx,avx2,sse,sse2") #pragma comment(linker, "/stack:200000000") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define int long long #define pb push_back #define pf push_front #define eb emplace_back #define mp make_pair #define all(v) (v).begin(),(v).end() #define rall(v) (v).rbegin(),(v).rend() #define f first #define s second #define sz(x) (int)x.size() #define endl "\n" #define forn(i,n) for(int i=0;i<n;i++) #define fore(i,l,r) for(int i=int(l);i<=int(r);i++) #define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++) #define fill(a,value) memset(a,value,sizeof(a)); #define gcd(a,b) __gcd((a),(b)) #define watch1(x) cout<<(x)<<endl #define watch2(x,y) cout<<(x)<<" "<<(y)<<endl #define watch3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl #define fastio ios::sync_with_stdio(0);cin.tie(0); #define uid(a,b) uniform_int_distribution<int>(a,b)(rng) typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<pii> vpii; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); const int INF = 9e18; const int mod = 1e9 + 7; const int N = 2e5 + 5; int i, j, n, pref[N]; vpii g[N]; void dfs(int v, int par) { for (auto &p : g[v]) { int u = p.f, w = p.s; if (u != par) { pref[u] = pref[v] ^ w; dfs(u, v); } } } void burn() { cin >> n; for (i = 1; i <= n; i++) { int u, v, w; cin >> u >> v >> w; g[u].pb({v, w}); g[v].pb({u, w}); } pref[1] = 0; dfs(1, 0); int ans = 0; for (j = 0; j < 62; j++) { int odd = 0, even = 0; for (i = 1; i <= n; i++) { if (pref[i] >> j & 1) { odd++; } else { even++; } } int pairs = (odd * even) % mod, contri = (1LL << j) % mod; ans += (pairs * contri) % mod; ans %= mod; } cout << ans << endl; } signed main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fastio; int t = 1; // cin >> t; while (t--) { burn(); } return 0; }
#include <iostream> #include <fstream> #include <algorithm> #include <vector> #include <set> #include <stack> #include <numeric> #include <chrono> #include <random> #include <bitset> #include <tuple> #include <queue> #include <map> #include <unordered_map> #include <cstring> #include <cassert> #include <climits> #include <complex> #include <math.h> using namespace std; const int N = 2e5 + 10, mod =998244353; int dp[N][2], arr[N], n; int solve(int i, bool j) { if(i == n) return 0; if(dp[i][j] != -1) return dp[i][j]; int ret = 0; if(!j) { ret = solve(i + 1, 0); if(i != n - 1) ret = (ret + 1ll * arr[i] * solve(i + 1, 1) % mod) % mod; ret = (ret + 1ll * arr[i] * arr[i] % mod) % mod; } else { ret = arr[i]; if(i != n - 1) ret = (ret + 2ll * solve(i + 1, j) % mod) % mod; } return dp[i][j] = ret; } int main() { // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tc = 1; for(int cn = 1; cn <= tc; cn++) { scanf("%d", &n); for(int i = 0; i < n; i++) scanf("%d", &arr[i]); sort(arr, arr + n); memset(dp, -1, sizeof(dp)); printf("%d\n", solve(0, 0)); } return 0; }
#include <iostream> #include <string> #include <vector> #include <random> #include <stdlib.h> #include <time.h> #include <utility> #include <algorithm> #include <unistd.h> using namespace std; int main(){ srand((unsigned)time(NULL)); time_t start = time(NULL); int si,sj,x,y,now,cnt,num=0; string ans="",A=""; cin>>si>>sj; vector<vector<int>> t(50,vector<int>(50)); vector<vector<int>> p(50,vector<int>(50)); vector<int> gone(2500); for(int i=0;i<50;i++)for(int j=0;j<50;j++)cin>>t.at(i).at(j); for(int i=0;i<50;i++)for(int j=0;j<50;j++){ cin>>p.at(i).at(j); } while(time(NULL)-start<1.9){ x=si;//初期化 y=sj; ans=""; cnt=p.at(x).at(y); fill(gone.begin(),gone.end(),0); while(1){ now=t.at(x).at(y); gone.at(now)=1; vector<pair<pair<int,char>,pair<int,int>>> tmp; if(x!=0 && gone.at(t.at(x-1).at(y))==0){ tmp.push_back({{p.at(x-1).at(y),'U'},{x-1,y}}); } if(x!=49 && gone.at(t.at(x+1).at(y))==0){ tmp.push_back({{p.at(x+1).at(y),'D',},{x+1,y}}); } if(y!=0 && gone.at(t.at(x).at(y-1))==0){ tmp.push_back({{p.at(x).at(y-1),'L'},{x,y-1}}); } if(y!=49 && gone.at(t.at(x).at(y+1))==0){ tmp.push_back({{p.at(x).at(y+1),'R'},{x,y+1}}); } if(tmp.size()==0){ if(cnt>num){ num=cnt; A=ans; } break; } int len=tmp.size(); int go; if(len==1){ go=0; }else if(len==2){ sort(tmp.begin(),tmp.end()); int q=rand()%10; if(q<2)go=0; else go=1; }else if(len==3){ sort(tmp.begin(),tmp.end()); int q=rand()%10; if(q<1)go=0; else if(q<3)go=1; else go=2; }else{ sort(tmp.begin(),tmp.end()); //最初だけありえる go=rand()%4; } if(go>=len){ sleep(2); } pair<pair<int,char>,pair<int,int>> u=tmp.at(go); x=u.second.first; y=u.second.second; ans+=u.first.second; cnt+=u.first.first; } //cout<<cnt<<endl; } cout<<A<<endl; //cerr<<time(NULL)-start<<endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define DIM 20 #define DIMMASK 270007 //#define ll long long long long a[DIM],d[DIMMASK]; bool isbit(int mask, int bit) { return (mask & (1 << (bit-1))) != 0; } int removebit(int mask, int b) { return mask & ~(1 << (b-1)); } vector< pair<int,int> > g[DIM]; int n,q,x,y,z; int main() { //freopen("input.txt","r",stdin); int n,maxmask,prevmask,currres,currcount; cin >> n >> q; for(int i=1; i<=q; i++) { cin >> x >> y >> z; g[x].push_back({y,z}); } d[0] = 1; maxmask = (1 << n) - 1; for(int m = 0; m <= maxmask; m++) { for(int last = 1; last <= n; last++) { if(!isbit(m,last)) continue; prevmask = removebit(m,last); d[m] += d[prevmask]; } //cout <<"BEFORE "<< m<<" "<<d[m]<<endl; x = __builtin_popcount(m); for(auto [y,z] : g[x]) { //cout <<"YZ="<<y<<" "<<z<<endl; int tmpmask = m & ((1<<y)-1); //cout <<"PC="<<__builtin_popcount(tmpmask)<<endl; if(__builtin_popcount(tmpmask)>z) d[m] = 0; } //cout <<"AFTER "<< m<<" "<<d[m]<<endl; } cout << d[maxmask] << endl; //for(int i=0; i<=maxmask; i++) cout << i<<" "<<d[i]<<endl; return 0; }
#include<bits/stdc++.h> #define PI 3.141592653589793238462 #define eps 1e-10 using namespace std; typedef long long ll; typedef long double db; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef pair<db,db> pdd; int x[1005],y[1005]; int main(){ string s,t;cin>>s>>t; int ns=0,nt=0; for(int i=0;i<s.length();i++){ ns+=(s[i]-'0'); nt+=(t[i]-'0'); } cout<<max(ns,nt)<<endl; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; template <class T> using idx_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; #define ll long long #define ull unsigned long long #define arr array #define vt vector #define vi vector<int> #define vvi vector<vector<int>> #define vl vector<ll> #define vvl vector<vector<ll>> #define vb vector<bool> #define vvb vector<vector<bool>> #define vc vector<char> #define vvc vector<vector<char>> #define all(v) (v).begin(), (v).end() #define pi acosl(-1) //ofstream out("debug.txt"); const int MxN = 1e5, md = 1e9 + 7; int s(int a) { int c = 0; while (a) { c += a % 10; a /= 10; } return c; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int a, b, c, d; cin >> a >> b; c = s(a), d = s(b); cout << (c >= d ? c : d) << '\n'; }
#include <bits/stdc++.h> #define int long long using namespace std; const int N = 2e5 + 101; int a[N], b[N], n; signed main() { scanf("%lld",&n); for(int i = 1;i <= n; i++) scanf("%lld",&a[i]); for(int i = 1;i <= n; i++) scanf("%lld",&b[i]); int now1 = a[1],now2 = b[1], nowmax = now1 * now2; printf("%lld\n",nowmax); for(int i = 2;i <= n; i++) { now1 = max(now1,a[i]); nowmax = max(nowmax,b[i] * now1); printf("%lld\n",nowmax); } }
//Let's join Kaede Takagaki Fan Club !! #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; //#define int long long typedef long long ll; typedef pair<int,int> P; typedef pair<int,P> P1; typedef pair<P,P> P2; #define pu push #define pb push_back #define eb emplace_back #define mp make_pair #define eps 1e-7 #define INF 1000000000 #define a first #define b second #define rng(i,a,b) for(int i=int(a);i<int(b);i++) #define rep(i,x) for(int i=0;i<x;i++) #define repn(i,x) for(int i=1;i<=x;i++) #define SORT(x) sort(x.begin(),x.end()) #define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end()) #define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) #define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) #define all(x) x.begin(),x.end() #define si(x) int(x.size()) #ifdef LOCAL #define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl #else #define dmp(x) void(0) #endif template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b;return true;}else return false;} template<class t,class u> bool chmin(t&a,u b){if(b<a){a=b;return true;}else return false;} template<class t> using vc=vector<t>; template<class t,class u> ostream& operator<<(ostream& os,const pair<t,u>& p){ return os<<"{"<<p.fi<<","<<p.sc<<"}"; } template<class t> ostream& operator<<(ostream& os,const vc<t>& v){ os<<"{"; for(auto e:v)os<<e<<","; return os<<"}"; } template<class T> void g(T &a){ cin >> a; } template<class T> void o(const T &a,bool space=false){ cout << a << (space?' ':'\n'); } //ios::sync_with_stdio(false); const ll mod = 1000000007;//998244353 //mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count()); template<class T> void add(T&a,T b){ a+=b; if(a >= mod) a-=mod; } ll modpow(ll x,ll n){ ll res=1; while(n>0){ if(n&1) res=res*x%mod; x=x*x%mod; n>>=1; } return res; } int n; ll a[200005], b[200005]; void solve(){ cin >> n; repn(i, n) cin >> a[i]; ll mx = 0; repn(i, n){ cin >> b[i]; chmax(mx, a[i]); b[i] *= mx; } repn(i, n){ chmax(b[i], b[i-1]); cout << b[i] << '\n'; } } signed main(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20); int t; t = 1; // cin >> t; while(t--) solve(); }
#define _GLIBCXX_DEBUG // #include <bits/stdc++.h> #include <iostream> #include <iomanip> #include <vector> #include <map> #include <algorithm> #include <cmath> #include <unordered_set> #include <utility> #include <tuple> using namespace std; using ll = int64_t; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) const ll INF = 1ll << 60; // 十分大きい値とする (ここでは 2^60) const ll MOD = 1000000007; const double PI = acos(-1); template<class T> void chmin(T &a, T b) { if (a > b) a = b; } template<class T> void chmax(T &a, T b) { if (a < b) a = b; } int main() { ll N; cin >> N; double x0, y0; cin >> x0 >> y0; double xn2, yn2; // x_{N/2}, y_{N/2} cin >> xn2 >> yn2; // 2点 p_{0}, p_{N/2} の距離 double dist; dist = sqrt((x0 - xn2)*(x0 - xn2) + (y0 - yn2)*(y0 - yn2)); double theta = PI*(N - 2)/N; // 正N角形の頂点の角度 double r; // 正N角形の1辺の長さ if ((N/2)%2 == 0) { double sum_cos = 0; double a = theta/2.0; rep(i, N/4) { sum_cos += 2.0*cos(a); a = theta - PI + a; } r = dist/sum_cos; } else { double sum_cos = 1.0; double a = theta/2.0; rep(i, (N-2)/4) { sum_cos += 2.0*cos(a); a = theta - PI + a; } r = dist/sum_cos; } // p_{0} から p_{N/2} へのベクトルを長さ r に規格化したもの double vx, vy; vx = r*(xn2 - x0)/dist; vy = r*(yn2 - y0)/dist; // p_{0} から p_{1} へのベクトル double wx, wy; wx = cos(theta/2.0)*vx + sin(theta/2.0)*vy; wy = -sin(theta/2.0)*vx + cos(theta/2.0)*vy; cout << fixed << setprecision(11); cout << x0 + wx << " " << y0 + wy << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define forin(in ,n) for(ll i=0; i<n; i++) cin>>in[i] #define forout(out) for(ll i=0; i<(ll)out.size(); i++) cout<<out[i]<<endl #define rep(i, n) for (ll i = 0; i < n; ++i) #define rep_up(i, a, n) for (ll i = a; i < n; ++i) #define rep_down(i, a, n) for (ll i = a; i >= n; --i) #define P pair<ll, ll> #define all(v) v.begin(), v.end() #define fi first #define se second #define vvvll vector<vector<vector<ll>>> #define vvll vector<vector<ll>> #define vll vector<ll> #define pqll priority_queue<ll> #define pqllg priority_queue<ll, vector<ll>, greater<ll>> constexpr ll INF = (1ll << 60); constexpr ll mod = 1000000007; //constexpr ll mod = 998244353; constexpr double pi = 3.14159265358979323846; template <typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <typename T> void pt(T val) { cout << val << "\n"; } template <typename T> void pt_vll(vector<T> &v) { ll vs = v.size(); rep(i, vs) { cout << v[i]; if (i == vs - 1) cout << "\n"; else cout << " "; } } ll mypow(ll a, ll n) { ll ret = 1; if(n==0) return 1; if(a==0) return 0; rep(i, n) { if (ret > (ll)(1e18 + 10) / a) return -1; ret *= a; } return ret; } long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } long long modinv(long long a, long long m) { long long b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } //自分以外の約数の和 ll enum_sum(ll n){ ll ret=0; if(n==1) return 0; for(ll i = 1 ; i*i <= n ; ++i){ if(n%i == 0){ ret+=i; if(i != 1 && i*i != n){ ret+=(n/i); } } } return ret; } int main() { ll r,c,n,m,t,k=0,cnt=INF,ans=0; string s; cin>>t; rep(bit,t){ cin>>n>>s>>s>>s; rep(i,n){ cout<<0; } rep(i,n){ cout<<1; } cout<<0<<endl; } }
/** *!! God will direct your steps !! * @Author : Ekansh Saxena (ekansh9927) * @DateTime: 19-12-2020 17:59:21 * **/ #include<bits/stdc++.h> using namespace std; #define mod 1000000007 #define all(x) x.begin(),x.end() #define F first #define S second #define pb push_back #define pf push_front #define pob pop_back #define pof pop_front #define pll pair<long long,long long> #define B begin() #define E end() #define usi unordered_set<int> #define usll unordered_set<long long> #define uslli unordered_set<long long int> #define umll unordered_map<long long,long long> #define umlli unordered_map<long long int,long long int> #define umstoll unordered_map<string,long long> #define umchtoll unordered_map<char,long long> #define vi vector<int> #define vll vector<long long> #define vlli vector<long long int> #define vpll vector<pair<long long,long long>> #define sortall(arr) sort(arr.begin(),arr.end()) #define modadd(a,b) (a%mod + b%mod)%mod #define modsub(a,b) (a%mod - b%mod)%mod #define modmul(a,b) (a%mod * b%mod)%mod #define REP(n) for(int i=0;i<n;i++) #define FOR(i,l,r,in) for(i=l;i<r;i+=in) #define FILL(n,arr) for(int i=0;i<n;i++){ll x;cin>>x;arr.pb(x);} #define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) typedef long long ll; typedef long long int lli; //___________________________________POWER____________________________________________ ll power(ll x, ll y, ll p){ ll res = 1; x = x % p; if (x == 0) return 0; while (y > 0) { if (y & 1) res = (res*x) % p; y = y>>1; x = (x*x) % p; } return res; } //_______________________________END-OF-POWER__________________________________________ void solve(){ ll n,m; cin>>n>>m; cout<<n/m<<endl; } int main(){ FIO; ll t=1; //cin>>t; while(t--){ solve(); } return 0; }
#include <math.h> #include <iostream> #include <string> #include <iomanip> #include <algorithm> #include <tuple> #include <vector> #include <cmath> #include<set> #include <sstream> #include <bitset> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(a) (a).begin(),(a).end()//配列を全部参照 using namespace std; using ll = long long int; using Graph = vector<vector<int>>; // グラフ型 //cin.tie(nullptr); /*高速で入力可能*/ //vector<vector<int>> hako(n, vector<int>(2)); //sort(hako.begin(), hako.end(), [](const vector<int>& alpha, const vector<int>& beta) {return alpha[0] < beta[0]; }); int main() { cin.tie(nullptr); ll n,h,w; ll ans = 1; cin >> h >> w; vector<vector<char>> hako(h, vector<char>(w)); vector<bool> R(h + w-1), B(h + w-1); rep(i, h)rep(j, w) cin >> hako[i][j]; rep(i, h)rep(j, w) { if (hako[i][j] == 'R') R[i + j] = true; if (hako[i][j] == 'B') B[i + j] = true; } rep(i, h + w-1) { if (R[i] && B[i]) ans = 0; if (!R[i] && !B[i]) ans = ans * 2 % 998244353; } cout << ans << endl; return 0; }
#pragma GCC optimize("O2") #include <bits/stdc++.h> #ifdef DEBUG #include "debug.hpp" #endif using namespace std; #define all(c) (c).begin(), (c).end() #define rall(c) (c).rbegin(), (c).rend() #define traverse(c, it) for(auto it = (c).begin(); it != (c).end(); ++it) #define rep(i, N) for(int i = 0; i < (N); ++i) #define rrep(i, N) for(int i = (N) - 1; i >= 0; --i) #define rep1(i, N) for(int i = 1; i <= (N); ++i) #define rep2(i, s, e) for(int i = (s); i <= (e); ++i) #define rep3(i, s, e, d) for(int i = (s); (d) >= 0 ? i <= (e) : i >= (e); i += (d)) #ifdef DEBUG #define debug(x...) { \ ++dbg::depth; \ string dbg_vals = dbg::to_string(x); \ --dbg::depth; \ dbg::fprint(__func__, __LINE__, #x, dbg_vals); \ } #define light_debug(x) { \ dbg::light = true; \ dbg::dout << __func__ << ":" << __LINE__; \ dbg::dout << " " << #x << " = " << x << endl; \ dbg::light = false; \ } #else #define debug(x...) 42 #define light_debug(x) 42 #endif using ll = long long; template<typename T> inline T& ckmin(T& a, T b) { return a = a > b ? b : a; } template<typename T> inline T& ckmax(T& a, T b) { return a = a < b ? b : a; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); #ifdef DEBUG freopen("debug", "w", stderr); #endif int N, M; cin >> N >> M; vector<vector<bool>> E(N, vector<bool>(N)); rep(_, M) { int a, b; cin >> a >> b; --a, --b; E[a][b] = E[b][a] = true; } vector<bool> ch(1 << N, true); rep(m, 1 << N) { rep(i, N) rep2(j, i + 1, N - 1) if((m & (1 << i)) && (m & (1 << j)) && !E[i][j]) ch[m] = false; } vector<int> dp(1 << N, N); dp[0] = 0; rep(m, 1 << N) { for(int i{m}; i; i = (i - 1) & m) if((i & m) == i && ch[i]) ckmin(dp[m], 1 + dp[m ^ i]); } cout << dp.back() << '\n'; #ifdef DEBUG dbg::dout << "\nExecution time: " << clock() * 1000 / CLOCKS_PER_SEC << "ms" << endl; #endif return 0; }
#include <bits/stdc++.h> using namespace std; #define vec vector #define PB push_back #define MP make_pair #define MT make_tuple #define F first #define S second using ll = long long int; // watch out for overflows in your code using pii = pair<int,int>; //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); void debug() { cout << "\n"; }; template <typename T, typename... Targs> void debug(T t, Targs... args) { cout << t << " "; debug(args...); } template <typename T1, typename T2> inline ostream& operator << (ostream& os, const pair<T1,T2>& p) { return os << "(" << p.F << ", " << p.S << ")"; } template <typename T> inline ostream& operator << (ostream& os, const vec<T>& v) { for(auto& t : v) { os << t << " "; } return os; } template <typename T> inline ostream& operator << (ostream& os, const vec<vec<T>>& m) { for(auto& v : m) { for(auto& t : v) { os << t << " "; } os << "\n"; } return os; } template <typename T> inline ostream& operator << (ostream& os, const set<T>& v) { for(auto& t : v) { os << t << " "; } return os; } template <typename K, typename V> inline ostream& operator << (ostream& os, const map<K,V>& m) { for(auto& p : m) { os << p.F << " -> " << p.S << "\n"; } return os; } const int INF = 1e9; int N, M; vec<vec<int>> adj; struct Solution { int lso(int x) { return x & (-x); } bool complete(int mask) { int m = mask; while(m) { int bit_u = lso(m); int u = __builtin_ctz(m) + 1; int new_mask = bit_u; for(int v : adj[u]) { new_mask |= (1 << (v-1)); } if((new_mask & mask) != mask) { return false; } m -= bit_u; //debug(mask, new_mask); } return true; } int S; vec<int> dp; int ans; Solution() : S((1 << N) - 1), dp(S+1, -1) { compute(); ans = dp[S]; } void compute() { dfs(S); } int dfs(int mask) { //debug("dfs_in", mask); if(mask == 0) { return 0; } int& ans = dp[mask]; if(ans != -1) { //debug("dfs_out_0", mask, ans); return ans; } if(complete(mask)) { //debug("dfs_out_1", mask, ans); ans = 1; } else { ans = INF; for(int m = mask; m > 0; m = ((m-1) & mask)) { //debug("dfs_mid", m, mask^m); if(m != 0 && (mask ^ m) != 0) { ans = min(ans, dfs(m) + dfs(mask ^ m)); } } } //debug("dfs_out_2", mask, ans); return ans; } }; //////////////////////////////////////////////////////////////////////// int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> N >> M; adj.assign(N+1, vec<int>()); for(int i = 1; i <= M; ++i) { int a, b; cin >> a >> b; adj[a].PB(b); adj[b].PB(a); } Solution sol; /* cout << sol.check_complete(0b111); cout << sol.check_complete(0b101); cout << sol.check_complete(0b100); cout << "\n"; */ cout << sol.ans << "\n"; }
#pragma GCC optimize("O2") #include <bits/stdc++.h> namespace IN { #define BUF_SIZE 1 << 17 static char buf[BUF_SIZE], *fs = buf, *ft = buf; inline int nc() { return fs == ft && (ft = (fs = buf) + fread(buf, 1, BUF_SIZE, stdin), fs == ft) ? EOF : *fs++; } template <typename T> inline int rn(T &x) { x = 0; int f = 0; char ch = nc(); while (ch < '0' || ch > '9') { if (ch == '-') f = 1; ch = nc(); if (ch == EOF) return EOF; } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - 48; ch = nc(); } x = f ? -x : x; return 0; } template <typename T> inline int read(T &x) { return rn(x); } template <typename T, typename... Args> inline int read(T &x, Args &...args) { rn(x); return read(args...); } #undef BUF_SIZE } // namespace IN namespace OUT { template <typename T> inline void print(std::string, T x) { std::cout << x << std::endl; } template <typename T, typename... Args> inline void print(std::string sep, T x, Args... args) { std::cout << x << sep; print(sep, args...); } } // namespace OUT using namespace IN; using namespace OUT; using namespace std; #define INF 0x3f3f3f3f #define LL long long #define PLL pair<LL, LL> #define PII pair<int, int> #define MP make_pair #define FI first #define SE second #define PB push_back #define ALL(A) A.begin(), A.end() #define BPQ(type, name) priority_queue<type> name #define SPQ(type, name) priority_queue<type, vector<type>, greater<type>> name #define REP(i, n) for (LL i = 0; i < (LL)n; ++i) #define REP1(i, n) for (LL i = 1; i <= (LL)n; ++i) #define REP_R(i, a, b) for (LL i = (LL)a; i < (LL)b; ++i) #define REP_RR(i, a, b) for (LL i = (LL)a; i >= (LL)b; --i) #define SETVAL(array, val) memset(array, val, sizeof(array)) // Debug #define DISP(arr, n) \ REP(i, n) cout << arr[i] << ' '; \ cout << endl; #define DISP1(arr, n) \ REP1(i, n) cout << arr[i] << ' '; \ cout << endl; #define DISP_T(arr, n, m) \ REP(i, n) { \ REP(j, m) cout << arr[i][j] << ' '; \ cout << endl; \ } #define DISP_T1(arr, n, m) \ REP1(i, n) { \ REP1(j, m) cout << arr[i][j] << ' '; \ cout << endl; \ } #define SIZE 200010 LL t[SIZE]; int n; int main() { read(n); LL tak = 0; REP(i, n) { LL a, b; read(a, b); t[i] = 2 * a + b; tak -= a; } sort(t, t + n, greater<LL>()); int p = 0; while (tak <= 0) tak += t[p++]; cout << p << endl; return 0; }
#include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; #define stp(var, init, end) for (auto var = init; var < end; ++var) #define ll long long int main(void) { int n, cou = 0; cin >> n; ll dif = 0, a, b; vector<ll> get(n); stp(i, 0, n) { cin >> a >> b; dif += a; get[i] = 2 * a + b; } sort(get.begin(), get.end(), [](ll a, ll b) { return a > b; }); for (int x = 0; dif >= 0; ++x) { dif -= get[x]; ++cou; } cout << cou; return 0; }
#include <bits/stdc++.h> using namespace std; using Int = long long; #define PUTS(x) std::cout << (x) << endl; #define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++) vector<Int> IntsIn(int n) { auto v = vector<Int>(0); for (int i = 0; i < n; i++) { Int a; cin >> a; v.push_back(a); } return v; } int main() { Int n, m; cin >> n >> m; auto a = IntsIn(n); auto b = IntsIn(n); auto g = vector<vector<Int>>(n, vector<Int>()); rep(i, m) { Int c, d; cin >> c >> d; c--; d--; g[c].push_back(d); g[d].push_back(c); } auto components = vector<set<Int>>(); auto visited = vector<bool>(n, false); rep(i, n) { auto component = set<Int>(); function<void(Int)> dfs = [&](Int index) { if (visited[index]) return; visited[index] = true; component.insert(index); for (auto nextIndex : g[index]) { dfs(nextIndex); } }; dfs(i); if (component.size() > 0) { components.push_back(component); } } for (auto s : components) { Int A = 0; Int B = 0; for (auto i : s) { A += a[i]; B += b[i]; } if (A != B) { PUTS("No"); exit(0); } } PUTS("Yes"); }
#include<bits/stdc++.h> using namespace std; using ll=long long; ll H,W; ll A[505][505]; ll B[505][505]; struct edge{ll to,cost;}; using P=pair<ll,ll>; using PP=pair<ll,P>; using PPP=pair<ll,PP>; using Graph=vector<vector<edge>>; static const ll INF=1000000000000000; ll d[2][505][505]; void dijkstra(ll sx,ll sy){ for(ll k=0;k<2;k++) for(ll i=0;i<H;i++) for(ll j=0;j<W;j++)d[k][i][j]=INF;d[0][sx][sy]=0; priority_queue<PPP,vector<PPP>,greater<PPP>>que; que.push(PPP(0,PP(0,P(sx,sy)))); while(!que.empty()){ PPP p=que.top();que.pop(); ll D=p.first;ll t=p.second.first;ll X=p.second.second.first; ll Y=p.second.second.second; if(d[t][X][Y]<D)continue; if(Y+1<W){ if(d[t][X][Y]+A[X][Y]<d[0][X][Y+1]){ d[0][X][Y+1]=d[t][X][Y]+A[X][Y]; PPP p;p.first=d[0][X][Y+1];p.second.first=0;p.second.second.first=X; p.second.second.second=Y+1;que.push(p); } } if(0<=Y-1){ if(d[t][X][Y]+A[X][Y-1]<d[0][X][Y-1]){ d[0][X][Y-1]=d[t][X][Y]+A[X][Y-1]; PPP p;p.first=d[0][X][Y-1];p.second.first=0;p.second.second.first=X; p.second.second.second=Y-1;que.push(p); } } if(X+1<H){ if(d[t][X][Y]+B[X][Y]<d[0][X+1][Y]){ d[0][X+1][Y]=d[t][X][Y]+B[X][Y]; PPP p;p.first=d[0][X+1][Y];p.second.first=0;p.second.second.first=X+1; p.second.second.second=Y;que.push(p); } } if(0<=H-1){ if(d[t][X][Y]+2-t<d[1][X-1][Y]){ d[1][X-1][Y]=d[t][X][Y]+2-t; PPP p;p.first=d[1][X-1][Y];p.second.first=1;p.second.second.first=X-1; p.second.second.second=Y;que.push(p); } } } } int main(){ cin>>H>>W;Graph G(H*W); for(ll i=0;i<H;i++) for(ll j=0;j<W-1;j++)cin>>A[i][j]; for(ll i=0;i<H-1;i++) for(ll j=0;j<W;j++)cin>>B[i][j]; dijkstra(0,0); cout<<d[0][H-1][W-1]<<endl; return 0; }
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; using lint=long long; using graph=vector<vector<int>>; void add_directed_edge(graph& G,int u,int v){ G[u].emplace_back(v); } const long long INF=1LL<<61; int main(){ int n,m; scanf("%d%d",&n,&m); vector<lint> a(n); rep(i,n) scanf("%lld",&a[i]); graph G(n); rep(i,m){ int u,v; scanf("%d%d",&u,&v); u--; v--; add_directed_edge(G,u,v); } vector<lint> dp(n,INF); rep(u,n) for(int v:G[u]) { dp[v]=min({dp[v],dp[u],a[u]}); } lint ans=-INF; rep(u,n) ans=max(ans,a[u]-dp[u]); printf("%lld\n",ans); return 0; }
#include<bits/stdc++.h> using namespace std; #define N 5005 #define mod 998244353 #define ll long long int n,m,c[N][N],f[21][N]; int main(){ for(int i=0;i<N;i++){ c[i][0]=c[i][i]=1; for(int j=1;j<i;j++)c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod; } scanf("%d%d",&n,&m); f[0][0]=1; int lst=0; for(int i=1;(1<<i)<=m;i++){ for(int j=0;(2*j<=n)&&(j*(1<<i)<=m);j++) for(int k=j*(1<<i);k<=m;k++)f[i][k]=(f[i][k]+1LL*c[n][2*j]*f[i-1][k-j*(1<<i)])%mod; lst=i; } printf("%d",f[lst][m]); }
#include <bits/stdc++.h> using namespace std; int N; int main(){ cin >> N; if (N * 108 / 100 < 206)puts("Yay!"); else if (N * 108 / 100 == 206)puts("so-so"); else puts(":("); return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define repk(i, k, n) for (int i = k; i < n; i++) using namespace std; using ll = long long; vector<pair<int, int> > prime_factorize(int N) { vector<pair<int, int> > res; for (int a = 2; a * a <= N; ++a) { if (N % a != 0) continue; int ex = 0; while (N % a == 0) { ++ex; N /= a; } res.push_back({a, ex}); } if (N != 1) res.push_back({N, 1}); return res; } vector<int> divisors(int n){ vector<int> res; for(int i=1; i*i <= n; i++){ if(n%i == 0){ res.push_back(i); if(n/i != i) res.push_back(n/i); } } sort(res.begin(), res.end()); return res; } int main (){ int k; cin >> k; int a, b, c; int ans = 0; repk(i, 1, k+1){ repk(j, 1, k+1){ if(i*j > k) break; repk(l, 1, k+1){ if(i*j*l>k) break; if(i*j*l <=k) ans++; } } } cout << ans << endl; return 0; }
#include <cstdio> const int maxn=100+10; struct E{ int to; int next; }ed[maxn*maxn*2]; int head[maxn]; int tot; void J(int a,int b){ ed[++tot].to=b; ed[tot].next=head[a]; head[a]=tot; } int en; int vis[maxn]; int ans; void Dfs(int x){ if(x==en+1){ ans++; return; } if(!head[x]){ Dfs(x+1); return; } for(int i=head[x];i;i=ed[i].next){ if(vis[ed[i].to]){ Dfs(x+1); return; } } Dfs(x+1); vis[x]=1; Dfs(x+1); vis[x]=0; } long long gcd(long long a,long long b){ return b?gcd(b,a%b):a; } int main(){ long long a,b; scanf("%lld%lld",&a,&b); en=b-a+1; for(int i=1;i<=b-a+1;i++) for(int j=1;j<=b-a+1;j++){ if(i==j) continue; if(gcd(a+i-1,a+j-1)!=1){ J(i,j); J(j,i); } } Dfs(1); int ha=0; for(int i=1;i<=b-a+1;i++) if(!head[i]) ha++; printf("%lld",1ll*ans*(1ll<<ha)); return 0; }
// //abc195_e #include<bits/stdc++.h> #define rep(i,n) for(int i=0;i<n;++i) #define reps(i,s,n) for(int i=s;i<n;++i) using namespace std; using ll = long long; using P = pair<int, int>; const int p[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71}; const int n = 20; const ll bn = 1 << n; ll dp[75][bn]; int main() { ll a,b; cin >> a >> b; dp[0][0] = 1; int idx = 0; for(ll i = a; i<= b; ++i) { ll ai = i; ll pi = 0; rep(j,n) if(ai%p[j]==0) pi |= (1<<j);//(pi+=(1<<j)と同じ) rep(s,bn) { //aiを選択しない dp[idx+1][s] += dp[idx][s]; //aiを選択する(sにaiの素因数がない場合に可能) if((s&pi) == 0) dp[idx+1][s|pi] += dp[idx][s]; } ++idx; } ll ans = 0; rep(s,bn) ans += dp[idx][s]; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int n; string s; vector<int> a; vector<vector<int>> solve(); int main() { cin >> n >> s; a.resize(n + 1); for (auto &p : a) cin >> p; auto res = solve(); cout << res.size() << endl; for (auto &v : res) for (int i = 0; i <= n; ++i) cout << v[i] << " \n"[i == n]; return 0; } vector<vector<int>> solve() { vector<int> b(n + 1, 0); for (int i = 0; i <= n; ++i) { int now = i; while (now && s[now - 1] == '>') b[now - 1] = max(b[now - 1], b[now] + 1), --now; now = i; while (now < n && s[now] == '<') b[now + 1] = max(b[now + 1], b[now] + 1), ++now; } vector<vector<int>> res; auto check = [](vector<int> &v) { for (int i = 0; i < n; ++i) { if (s[i] == '<' && v[i] >= v[i + 1]) return 0; if (s[i] == '>' && v[i] <= v[i + 1]) return 0; } return 1; }; auto f = [&](int i) { vector<vector<int>> v(i, b); vector<int> rem(n + 1, 0); bool ch = 1; for (int j = 0; j <= n; ++j) { rem[j] = a[j] - i * b[j]; if (rem[j] < 0) ch = 0; } if (!ch) return vector<vector<int>>(); for (int j = 0; j < i; ++j) for (int k = 0; k <= n; ++k) v[j][k] += rem[k] / i + (rem[k] % i > j); for (int j = 0; j < i; ++j) if (!check(v[j])) { ch = 0; break; } if (!ch) return vector<vector<int>>(); return v; }; int l = 1, r = 10001; while (r - l > 1) { int mid = (l + r) >> 1; if (f(mid).size()) l = mid; else r = mid; } return f(l); }
#include <iostream> #include <cstdio> #include <cstdlib> #include <algorithm> #include <cmath> #include <vector> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <queue> #include <ctime> #include <cassert> #include <complex> #include <string> #include <cstring> #include <chrono> #include <random> #include <bitset> #include <fstream> using namespace std; #define int long long #define ii pair <int, int> #define app push_back #define all(a) a.begin(), a.end() #define bp __builtin_popcountll #define ll long long #define mp make_pair #define x first #define y second #define Time (double)clock()/CLOCKS_PER_SEC #define debug(x) std::cerr << #x << ": " << x << '\n'; #define FOR(i, n) for (int i = 0; i < n; ++i) #define FORN(i, n) for (int i = 1; i <= n; ++i) #define pb push_back #define trav(a, x) for (auto& a : x) using vi = vector<int>; template <typename T> std::istream& operator >>(std::istream& input, std::vector<T>& data) { for (T& x : data) input >> x; return input; } template <typename T> std::ostream& operator <<(std::ostream& output, const pair <T, T> & data) { output << "(" << data.x << "," << data.y << ")"; return output; } template <typename T> std::ostream& operator <<(std::ostream& output, const std::vector<T>& data) { for (const T& x : data) output << x << " "; return output; } ll div_up(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up ll div_down(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // divide a by b rounded down ll math_mod(ll a, ll b) { return a - b * div_down(a, b); } #define tcT template<class T #define tcTU tcT, class U tcT> using V = vector<T>; tcT> void re(V<T>& x) { trav(a, x) cin >> a; } tcT> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } // set a = min(a,b) tcT> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } ll gcd(ll a, ll b) { while (b) { tie(a, b) = mp(b, a % b); } return a; } signed main() { #ifdef LOCAL #else #define endl '\n' ios_base::sync_with_stdio(0); cin.tie(0); #endif int n; cin >> n; vi a(2 * n); cin >> a; multiset <int> ms; int ans = 0; trav (e, a) ans += e; FOR (i, n) { int l = n - 1 - i; int r = n + i; ms.insert(a[l]); ms.insert(a[r]); ans -= *ms.begin(); ms.erase(ms.begin()); } cout << ans << endl; }
#include <algorithm> #include <iostream> #include <vector> #include <numeric> struct AMat { public: AMat() : m{ 0, 0, 0, 0 }, v{ 0, 0 } {} AMat(int op, int p) : m { 0, 0, 0, 0 }, v{ 0, 0 } { if (op == 1) { m[0][0] = 0; m[0][1] = 1; m[1][0] = -1; m[1][1] = 0; v[0] = 0; v[1] = 0; } else if (op == 2) { m[0][0] = 0; m[0][1] = -1; m[1][0] = 1; m[1][1] = 0; v[0] = 0; v[1] = 0; } else if (op == 3) { m[0][0] = -1; m[0][1] = 0; m[1][0] = 0; m[1][1] = 1; v[0] = 2 * static_cast<int64_t>(p); v[1] = 0; } else if (op == 4) { m[0][0] = 1; m[0][1] = 0; m[1][0] = 0; m[1][1] = -1; v[0] = 0; v[1] = 2 * static_cast<int64_t>(p); } } ~AMat() {} std::int64_t m[2][2]; std::int64_t v[2]; }; struct Vec2 { Vec2() : v{0, 0} {} ~Vec2() {} std::int64_t v[2]; }; AMat operator*(const AMat& lhs, const AMat& rhs) { AMat r; for (int i = 0; i < 2; ++i) { for (int j = 0; j < 2; ++j) { for (int k = 0; k < 2; ++k) { r.m[i][j] += lhs.m[i][k] * rhs.m[k][j]; } } } r.v[0] = lhs.m[0][0] * rhs.v[0] + lhs.m[0][1] * rhs.v[1] + lhs.v[0]; r.v[1] = lhs.m[1][0] * rhs.v[0] + lhs.m[1][1] * rhs.v[1] + lhs.v[1]; return r; } Vec2 operator*(const AMat& lhs, const Vec2& rhs) { Vec2 r; r.v[0] = lhs.m[0][0] * rhs.v[0] + lhs.m[0][1] * rhs.v[1] + lhs.v[0]; r.v[1] = lhs.m[1][0] * rhs.v[0] + lhs.m[1][1] * rhs.v[1] + lhs.v[1]; return r; } int main() { int N; std::cin >> N; std::vector<Vec2> X(N); for (int i = 0; i < N; ++i) { std::cin >> X[i].v[0] >> X[i].v[1]; } int M; std::cin >> M; std::vector<int> OP(M); std::vector<int> P(M); for (int i = 0; i < M; ++i) { std::cin >> OP[i]; if (OP[i] == 3) { std::cin >> P[i]; } else if (OP[i] == 4) { std::cin >> P[i]; } } int Q; std::cin >> Q; std::vector<int> A(Q), B(Q); for (int i = 0; i < Q; ++i) { std::cin >> A[i] >> B[i]; } std::vector<AMat> mats(M); for (int i = 0; i < M; ++i) { AMat m(OP[i], P[i]); if (i == 0) { mats[i] = m; } else { mats[i] = m * mats[i - 1]; } } for (int i = 0; i < Q; ++i) { int p = B[i] - 1; if (A[i] == 0) { std::cout << X[p].v[0] << " " << X[p].v[1] << std::endl; } else { Vec2 r = mats[A[i] - 1] * X[p]; std::cout << r.v[0] << " " << r.v[1] << std::endl; } } }
#include<iostream> #include<bits/stdc++.h> #define int long long int #define vi vector<int> #define fo(i,n) for(int i=1;i<=n;i++) #define foo(i,n) for(int i=0;i<n;i++) #define sort(v) sort(v.begin(), v.end()) #define rev(v) reverse(v.begin(), v.end()) #define uniq(v) sort(v); v.resize(unique(v.begin(), v.end())-v.begin()); #define ff first #define ss second #define pb push_back #define pii pair<int,int> #define ok ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); using namespace std; #define vp vector<pair<int,int>> #define mod 1000000007 const int huge = 1e17; 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 abbs(int a,int b){ if(a-b < 0) return b-a; return a-b; } int lowerB(vi &v, int val){ int ind=v.size(),l=0,r=v.size(),mid;while(l<=r){mid=(l+r)/2;if(v[mid]>=val){ind=mid;r=mid-1;}else l=mid+1;}return ind; } void solve(){ int n; cin>>n; vi v(n); foo(i,n) cin>>v[i]; vi pre(n); int x = 0; foo(i,n) x+=v[i], pre[i] = x; vector<vector<int>> dp(n+500,vector<int>(n+500,0)); dp[1][0] = 1; int ans = 0; for(int i=0; i<n; i++) { for(int j=n; j>=1; j--) { dp[j+1][pre[i]%(j+1)] += dp[j][pre[i]%j]; dp[j+1][pre[i]%(j+1)]%=mod; if(i==n-1) { ans+=dp[j][pre[i]%j]; ans%=mod; } } } cout<<ans; } signed main(){ ok int t; t = 1; //cin>>t; while(t--){ solve(); } }
#include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <string> #include <queue> #include <stack> #include <set> #include <map> #include <iomanip> #include <utility> #include <tuple> #include <functional> #include <bitset> #include <cassert> #include <complex> #include <stdio.h> #include <time.h> #include <numeric> #include <random> #include <unordered_set> #include <unordered_map> #define all(a) a.begin(), a.end() #define rep(i, n) for (ll i = 0; i < (n); i++) #define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--) #define range(i, a, b) for (ll i = (a); i < (b); i++) #define rrange(i, a, b) for (ll i = (b) - 1; i >= (a); i--) #define pb push_back #define debug(x) cerr << __LINE__ << ' ' << #x << ':' << (x) << '\n' #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; typedef long double ld; typedef pair<ll, ll> P; typedef complex<ld> com; template<class T> using pri_s = priority_queue<T, vector<T>, greater<T>>; template<class T> using pri_b = priority_queue<T>; constexpr int inf = 1000000010; constexpr ll INF = 1000000000000000010; constexpr int mod1e9 = 1000000007; constexpr int mod998 = 998244353; constexpr ld eps = 1e-12; constexpr ld pi = 3.141592653589793238; constexpr ll ten(int n) { return n ? 10 * ten(n - 1) : 1; }; int dx[] = { 1,0,-1,0,1,1,-1,-1 }; int dy[] = { 0,1,0,-1,1,-1,1,-1 }; void fail() { cout << "-1\n"; exit(0); } void no() { cout << "No\n"; exit(0); } template<class T> void er(T a) { cout << a << '\n'; exit(0); } template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; } template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; } template<class T> istream &operator >> (istream &s, vector<T> &v) { for (auto &e : v) s >> e; return s; } template<class T> ostream &operator << (ostream &s, const vector<T> &v) { for (auto &e : v) s << e << ' '; return s; } template<class T, class U> ostream &operator << (ostream &s, const pair<T, U> &p) { s << p.first << ' ' << p.second; return s; } struct fastio { fastio() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); cerr << fixed << setprecision(20); } }fastio_; class unionfind { vector<int> par; vector<int> sz; public: unionfind(int n) { par = vector<int>(n); for (int i = 0; i < n; i++) par[i] = i; sz = vector<int>(n, 1); } int find(int x) { if (par[x] == x) return x; else return par[x] = find(par[x]); } int size(int x) { return sz[find(x)]; } bool same(int x, int y) { return find(x) == find(y); } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (sz[x] < sz[y]) { par[x] = y; sz[y] += sz[x]; } else { par[y] = x; sz[x] += sz[y]; } } }; int main() { int h, w; cin >> h >> w; vector<vector<char>> a(h, vector<char>(w)); rep(i, h) rep(j, w) cin >> a[i][j]; unionfind uni(h + w); uni.unite(0, h); uni.unite(0, h + w - 1); uni.unite(h - 1, h); uni.unite(h - 1, h + w - 1); rep(i, h) rep(j, w) if (a[i][j] == '#') uni.unite(i, h + j); set<int> x, y; rep(i, h) x.insert(uni.find(i)); for (int i = h; i < h + w; i++) y.insert(uni.find(i)); int ans = min(x.size(), y.size()); cout << ans - 1 << '\n'; }
#include <bits/stdc++.h> #define ll long long #define fi first #define se second #define pb push_back #define me memset #define rep(a,b,c) for(int a=b;a<=c;++a) #define per(a,b,c) for(int a=b;a>=c;--a) const int N = 1e6 + 10; const int mod = 998244353; const int INF = 0x3f3f3f3f; using namespace std; typedef pair<int,int> PII; typedef pair<ll,ll> PLL; ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;} ll lcm(ll a,ll b) {return a/gcd(a,b)*b;} ll f[N],invf[N]; ll fpow(ll a,ll k){ ll res=1; while(k){ if(k&1) res=(res*a)%mod; k>>=1; a=a*a%mod; //cout<<1<<endl; } return res; } void init(int n){ f[0]=1; for(int i=1;i<=n;++i){ f[i]=f[i-1]*i%mod; } invf[n]=fpow(f[n],mod-2); for(int i=n-1;i>=0;--i){ invf[i]=invf[i+1]*(i+1)%mod; } } ll C(int n,int k){ if(k<0 || k>n) return 0; return f[n]*invf[k]%mod*invf[n-k]%mod; } ll dp[25][N]; int main(){ ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); init(2e5+10); int n,m; cin>>n>>m; rep(i,1,m) dp[1][i]=1; rep(i,1,19){ rep(j,1,m){ for(int k=2;k*j<=m;++k){ dp[i+1][k*j]+=dp[i][j]; } } } ll ans=0; rep(i,1,19){ rep(j,1,m){ ans=(ans+C(n-1,i-1)*dp[i][j]%mod)%mod; } } cout<<ans<<'\n'; return 0; }
#include <bits/stdc++.h> using namespace std; int n; double ans; bool can[105][105]; int main() { cin>>n; for (int i=1; i<=n; ++i) for (int j=1; j<=n; ++j) { char c; cin>>c; can[i][j]=c=='1'; } for (int i=1; i<=n; ++i) can[i][i]=1; for (int k=1; k<=n; ++k) for (int i=1; i<=n; ++i) for (int j=1; j<=n; ++j) can[i][j]|=can[i][k]&&can[k][j]; for (int i=1; i<=n; ++i) { int now=0; for (int j=1; j<=n; ++j) now+=can[j][i]; ans+=1.0/now; } printf("%.13lf",ans); }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; typedef vector<ll> vl; typedef vector<bool> vb; typedef vector<string> vs; typedef vector<char> vc; typedef queue<ll> ql; typedef deque<ll> dql; typedef priority_queue<ll> pql; typedef set<ll> sl; typedef pair<ll, ll> pl; typedef map<ll, ll> ml; typedef vector<vl> vvl; typedef vector<pl> vpl; #define rep(i, n) for(ll i = 0; i < ll(n); i++) #define rep2(i, k, n) for(ll i = ll(k); i <= ll(n); i++) #define rep3(i, n, k) for(ll i = ll(n); i >= ll(k); i--) #define all(v) (v).begin(), (v).end() ll mod(ll a, ll b) {return (a % b + b) % b;} ll quo(ll a, ll b) {return (a - mod(a, b)) / b;} template <typename T, typename U> bool chmin(T &a, const U b) {if(a > b) {a = b; return 1;} return 0;} template <typename T, typename U> bool chmax(T &a, const U b) {if(a < b) {a = b; return 1;} return 0;} const ll INF = 1LL << 60; const ll MOD = 1e9 + 7; //const ll MOD = 998244353; const ll MAX = 2e5; const ld eps = 1e-9; const char newl = '\n'; ll itr1, itr2, M1 = 0, M2 = 0; bool found = 0; vl e, d1, d2; vb diam; vvl G; void dfs1(ll v) { for(ll u: G[v]) { if(d1[u] == INF) { d1[u] = d1[v] + 1; dfs1(u); } } return; } void dfs2(ll v) { for(ll u: G[v]) { if(d2[u] == INF) { d2[u] = d2[v] + 1; dfs2(u); } } return; } void dfs3(ll v) { if(v == itr2) { found = 1; return; } for(ll u: G[v]) { if(found) break; if(d2[v] < d2[u]) dfs3(u); if(found) diam[u] = 1; } return; } ll dfs4(ll v, ll num) { e[v] = num; ll last = -1; for(ll u: G[v]) { if(e[u] == INF) { if(diam[u]) { last = u; continue; } num = dfs4(u, num+1); } } if(last != -1) num = dfs4(last, num+1); return num+1; } int main() { ios::sync_with_stdio(false); cin.tie(0); ll n, a, b; cin >> n; e = vl(n, INF); d1 = vl(n, INF); d2 = vl(n, INF); diam = vb(n, 0); G = vvl(n); rep(_, n-1) { cin >> a >> b; a--, b--; G[a].push_back(b); G[b].push_back(a); } d1[0] = 0; dfs1(0); rep(i, n) if(chmax(M1, d1[i])) itr1 = i; d2[itr1] = 0; dfs2(itr1); rep(i, n) if(chmax(M2, d2[i])) itr2 = i; dfs3(itr1); dfs4(itr1, 1); //cout << itr1 << " " << itr2 << newl; //rep(i, n) if(diam[i]) cout <<i << newl; rep(i, n) cout << e[i] << ' '; cout << newl; return 0; }
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> #define ll long long #define ull unsigned long long #define all(x) (x).begin(),(x).end() #define print(x) if(x)cout<<"YES\n";else cout<<"NO\n"; #define pb push_back #define F first #define S second //#define mod 1000000007 #define mod 998244353 using namespace __gnu_pbds; using namespace std; void solve() { int a, b, c; cin >> a >> b >> c; cout << 21 - a - b - c << "\n"; } int main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif fastio; int T = 1; // cin>>T; while (T--) { solve(); } }
#include <iostream> #include <vector> using namespace std; using llint = long long; #define rep(i,n) for(int i=0;i<(n);++i); int main() { llint a,b,c; cin >> a >> b >> c; cout << (7-a) + (7-b) + (7-c) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long LL; const int INF = 0x3f3f3f3f; const LL mod = 1e9 + 7; const int N = 100005; LL n, m; __int128 zh(__int128 x) { return x * (x - 1) * (x - 2) / 6; } __int128 cal(__int128 x) { __int128 res = zh(x); if (x > n) res -= 3 * zh(x - n); if (x > 2 * n) res += 3 * zh(x - 2 * n); return res; } int main() { cin >> n >> m; LL l = 3, r = n * 3; while (l < r) { LL mid = l + r >> 1; if (cal(mid) >= m) r = mid; else l = mid + 1; } m -= cal(l - 1); for (int i = 1; i <= n; i++) { int x = max(1LL, l - i - n), y = min(n, l - i - 1); int len = y - x + 1; if (len <= 0) continue; if (m > len) m -= len; else { x += m - 1; printf("%d %d %d\n", i, x, l - x - i); break; } } return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math") #pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") #pragma comment(linker, "/stack:200000000") using namespace std; using namespace __gnu_pbds; #define fastio ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL) #define pb push_back #define eb emplace_back #define ppb pop_back #define F first #define S second #define gcd __gcd #define lcm(a, b) (ull(a) / gcd(a, b) * b) #define sz(x) (int)(x).size() #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define mkp make_pair #define mkt make_tuple #define mem(x) memset(x, 0, sizeof(x)) #define deci(x) fixed << setprecision(x) #define zero(x) setw(x) << setfill('0') #define EACH(v, u) for(auto& v : u) #define lowbit(x) (x & -x) #define dbg(...) cerr << "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " typedef uint32_t uint; typedef int64_t ll; typedef uint64_t ull; typedef long double ld; #define vt vector #define Q queue #define pq priority_queue #define mset multiset #define uset unordered_set #define umap unordered_map #define ar array typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<double, double> pdd; template<class T> using PQ = priority_queue<T>; template<class T> using PQG = priority_queue<T, vt<T>, greater<T>>; template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template<class T, class U> ostream& operator<<(ostream& os, pair<T, U> p) { return os << p.F << " " << p.S; } template<class T> ostream& operator<<(ostream& os, vt<T> v) { EACH(u, v) os << u << " "; return os; } template<class T> void read(T& x) { cin >> x; } template<class T, class... U> void read(T& a, U&... b) { read(a), read(b...); } template<class T> void write(T x) { cout << x;} template<class T, class... U> void write(T a, U... b) { write(a), write(" "), write(b...), write("\n"); } string operator*(string a, int x) { string ret = a; for(int i = 1; i < x; ++i) ret += a; return ret; } string& operator*=(string& a, int x) { return a = a * x; } ull fpm(ull a, ull b, ull m) { ull ret = 1; while(b) { if(b & 1) ret = ret * ret % m; a = a * a % m; b >>= 1; } return ret; } const int INF(1e9); const ll LINF(1e17); const ld pi(3.141592653589793238); const int d4i[4] = {-1, 0, 1, 0}, d4j[4] = {0, 1, 0, -1}; const int d8i[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, d8j[8] = {-1, 0, 1, -1, 1, -1, 0, 1}; int main() { fastio; int a, b, c; cin >> a >> b; if(a == b) cout << a << "\n"; else { c = 0 ^ 1 ^ 2 ^ a ^ b; cout << c << "\n"; } return 0; }
#include<bits/stdc++.h> #define int long long using namespace std; const int mod=998244353; int n,m,ans=1; char s[508][508]; signed main() { scanf("%lld%lld",&n,&m); for(int i=1; i<=n; i++) for(int j=1; j<=m; j++) cin>>s[i][j]; for(int j=2; j<=n+m; j++) { int flag=0,ok=1,sum=1; for(int i=1; i<j; i++) { if(i>n||j-i>m) continue; if(flag!=0){ if(s[i][j-i]=='B'&&flag==1) ok=0; if(s[i][j-i]=='R'&&flag==-1) ok=0; } if(s[i][j-i]=='R'&&flag==0) flag=1; if(s[i][j-i]=='B'&&flag==0) flag=-1; if(s[i][j-i]!='.') sum=0; } if(ok==0) ans=0; else if(sum) ans=ans*2%mod; } printf("%lld\n",ans); return 0; }
#include <bits/stdc++.h> #define f(i,a,b) for( ll i = a; i < b ; i++ ) #define af(i,a,b) for( ll i = a; i >= b ; i--) #define rep(i,a,b,k) for(ll i = a; i < b ; i+= k ) #define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k) #define ff first #define ss second #define pb push_back #define mp make_pair #define sz(a) (ll) a.size() #define all(a) a.begin(), a.end() #define sor(a) sort( a.begin(), a.end() ) #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL) #define inter ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr) // policy-based //#include <ext/pb_ds/assoc_container.hpp> //#include <ext/pb_ds/tree_policy.hpp> //using namespace __gnu_pbds; using namespace std; typedef long long ll; // int or long long typedef long double ld; typedef pair<ll,ll> ii ; typedef vector<ll> vi ; typedef vector<ii> vii ; /* typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; */ const ll MAX = 1e3 + 100; const ll inf = 1e9; const ll mod = 998244353; ll c[100][100]; struct DSU{ ll p[200],sz[200]; void ini(ll n){ f(i,0,n) p[i] = i,sz[i] = 1; } ll find(ll u){ return (p[u]==u?u:p[u]=find(p[u])); } void uni(ll u,ll v){ ll x = find(u),y = find(v); if(x == y) return; p[y] = x; sz[x] += sz[y]; } }; DSU a,b; ll fac[MAX]; int main(){ fastio; fac[0] = 1; f(i,1,MAX) fac[i] = (fac[i-1]*i) % mod; ll n,k,ans = 1; cin >> n >> k; f(i,0,n) f(j,0,n) cin >> c[i][j]; a.ini(n); b.ini(n); f(x,0,n){ f(y,x+1,n){ bool go = true; f(i,0,n) if(c[i][x] + c[i][y] > k) go = false; if(go) a.uni(x,y); } } f(x,0,n){ f(y,x+1,n){ bool go = true; f(i,0,n) if(c[x][i] + c[y][i] > k) go = false; if(go) b.uni(x,y); } } f(i,0,n) if(a.find(i) == i) (ans *= fac[a.sz[i]] )%=mod; f(i,0,n) if(b.find(i) == i) (ans *= fac[b.sz[i]] )%=mod; cout << ans << endl; }
#ifdef Icry #include "debug.h" #else #include <bits/stdc++.h> #define debug(args...) #endif using namespace std; const int N = 1e5 + 10; int dp[111][N], a[111], n, sum = 0; int go(int i, int t) { if (i == n) return max(t, sum - t); int &ret = dp[i][t]; if (~ret) return ret; ret = min(go(i + 1, t + a[i]), go(i + 1, t)); return ret; } int main() { #ifdef Icry auto begin = chrono :: high_resolution_clock :: now(); #endif ios_base :: sync_with_stdio(0); cin.tie(0); cin >> n; for (int i = 0; i < n; ++i) cin >> a[i], sum += a[i]; // sort(a, a + n); // reverse(a, a + n); memset(dp, -1, sizeof dp); cout << go(0, 0) << '\n'; #ifdef Icry auto end = chrono :: high_resolution_clock :: now(); cerr << setprecision(4) << fixed; cerr << "[Execution time: " << chrono :: duration_cast <chrono :: duration <double>> (end - begin).count() << " seconds]\n"; #endif }
#include<bits/stdc++.h> using namespace std; const int N=1e6+5; int num[N]; int dp[N]; int main() { int n; cin>>n; int sum=0; for(int i=1;i<=n;i++) cin>>num[i],sum+=num[i]; if(n==1) { cout<<num[1]; return 0; } dp[0]=1; int temp=sum; sum/=2; for(int i=1;i<=n;i++) for(int j=sum;j>=num[i];j--) if(dp[j-num[i]]) dp[j]=1; for(int i=sum;i>=1;i--) if(dp[i]) { cout<<temp-i; return 0; } }
#include<bits/stdc++.h> using namespace std; int main(){ string s; cin>>s; int n=s.size(); for(int i=0;i<n;i++)s[i]-='0'; if(n<3){ if(n==1)cout<<(s[0]%8 ? "No" : "Yes")<<endl; else cout<<((s[0]*10+s[1])%8 && (s[1]*10+s[0])%8 ? "No" : "Yes")<<endl; return 0; } vector<int>x(10); int ans=0; for(int i=0;i<n;i++)x[s[i]]++; for(int i=1;i<=9;i++){ for(int j=1;j<=9;j++){ for(int k=1;k<=9;k++){ vector<int>memo=x; memo[i]--,memo[j]--,memo[k]--; if(memo[i]>=0 && memo[j]>=0 && memo[k]>=0 && (i*100+j*10+k)%8==0)ans=1; } } } cout<<(ans ? "Yes" : "No")<<endl; return 0; }
#define _DEBUG #include "bits/stdc++.h" #define CHOOSE(a) CHOOSE2 a #define CHOOSE2(a0,a1,a2,a3,a4,x,...) x #define debug_1(x1) cout<<#x1<<": "<<x1<<endl #define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl #define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl #define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl #define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl #ifdef _DEBUG #define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__) #else #define debug(...) #endif #define rep(index,num) for(int index=0;index<(int)num;index++) #define rep1(index,num) for(int index=1;index<=(int)num;index++) #define brep(index,num) for(int index=(int)num-1;index>=0;index--) #define brep1(index,num) for(int index=(int)num;index>0;index--) #define scan(argument) cin>>argument #define prin(argument) cout<<argument<<endl #define kaigyo cout<<endl #define eps 1e-7 #define mp(a1,a2) make_pair(a1,a2) #define ALL(a) (a).begin(),(a).end() #define rALL(a) (a).rbegin(),(a).rend() typedef long long ll; typedef long double ld; using namespace std; typedef pair<ll,ll> pll; typedef pair<int,int> pint; typedef vector<int> vint; typedef vector<ll> vll; typedef vector<pint> vpint; typedef vector<pll> vpll; template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } ll INFl=(ll)1e+18+1; int INF=1e+9+1; int main(){ int N,A[102]; scan(N); rep(i,N) scan(A[i]); int maxdo=0; int ans; for(int k=2;k<=1000;k++){ int cnt=0; rep(i,N) cnt+=(A[i]%k==0); if(maxdo<cnt){ maxdo=cnt; ans=k; } } prin(ans); return 0; }
#include <iostream> #include <vector> #include <algorithm> #include <cmath> #include <queue> #include <string> #include <map> #include <set> #include <stack> #include <tuple> #include <deque> #include <array> #include <numeric> #include <bitset> #include <iomanip> #include <cassert> #include <chrono> #include <random> #include <limits> #include <iterator> #include <functional> #include <sstream> #include <fstream> #include <complex> #include <cstring> #include <unordered_map> #include <unordered_set> using namespace std; // #pragma GCC optimize("O3") // #pragma GCC optimize("unroll-loops") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") // #pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl") using ll = long long; constexpr int INF = 1001001001; constexpr int mod = 1000000007; // constexpr int mod = 998244353; template<class T> inline bool chmax(T& x, T y){ if(x < y){ x = y; return true; } return false; } template<class T> inline bool chmin(T& x, T y){ if(x > y){ x = y; return true; } return false; } int sx, sy, gx, gy; ll score; inline void query(){ cin >> sx >> sy >> gx >> gy; } string get_str(){ string res = ""; while(sx < gx) { res += 'D'; ++sx; } while(sx > gx) { res += 'U'; --sx; } while(sy < gy) { res += 'R'; ++sy; } while(sy > gy) { res += 'L'; --sy; } return res; } inline void output(string s){ cout << s << endl; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); for(int i = 0; i < 1000; ++i){ query(); output(get_str()); cin >> score; } return 0; }
/* *Which of the favors of your Lord will you deny ?* */ #include <bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long #define vpnt(ans) \ for (ll i = 0; i < ans.size(); i++) \ cout << ans[i] << (i + 1 < ans.size() ? ' ' : '\n'); #define setbit(x, k) (x |= (1LL << k)) #define clearbit(x, k) (x &= ~(1LL << k)) //x er last theke k-1 tomo ghor #define checkbit(x, k) (x & (1LL << k)) #define mp make_pair #define scl(x) scanf("%lld", &x) #define sci(x) scanf("%d", &x) #define pb push_back #define pf push_front #define ppb pop_back #define ppf pop_front #define ff first #define ss second #define pii pair<int, int> #define YES printf("YES\n") #define Yes printf("Yes\n") #define yes printf("yes\n") #define NO printf("NO\n") #define No printf("No\n") #define no printf("no\n") #define nn cout << "\n"; #define INF (1 << 30) #define LL_INF (1LL << 32) #define pll pair<ll, ll> #define pp(n, p) (ll)(pow(n, p) + 0.5) #define ok ios::sync_with_stdio(false); #define fine cin.tie(nullptr); #define mod 1000000007 #define N 100005 int main() { ll n; cin>>n; vector<int>a, b; map<int,int>m; n = (1<<n); for(int i=0; i<n; i++) { ll x; cin>>x; a.pb(x); m[x] = i+1; } while(a.size()>2) { vector<int>t; for(int i=0; i<a.size(); i+=2) { t.pb(max(a[i], a[i+1])); } a = t; } int res = min(a[0], a[1]); cout<<m[res];nn; }
#include<iostream> #include<string> #include<iomanip> #include<cmath> #include<vector> #include<algorithm> #include<utility> using namespace std; // #define int long long #define int __int128 #define endl "\n" constexpr int INF = (int)1e35; constexpr long long MOD = 1'000'000'007; struct fast_io { fast_io(){ std::cin.tie(nullptr); std::ios::sync_with_stdio(false); }; } fio; std::ostream& operator << (std::ostream& os, const __int128& in) { constexpr __int32_t base = 10; bool sign = false; if(in < 0) sign = true; vector<__int32_t> num; for(__int128 i = in; i; i /= base){ num.push_back(i % base); } if(num.size() == 0) num.push_back(0); if(sign) cout<<"-"; for(__int32_t i = num.size()-1; i >= 0; i--){ cout<<num[i]; } // cout<<endl; return os; } std::istream& operator >> (std::istream& is, __int128& out) { char c; out = 0; while(is.get(c) && isspace(c)) ; if(is){ do out = out * 10 + c - '0'; while(is.get(c) && !isspace(c)); if(is) is.unget(); } return is; } void extgcd(int a, int b, int &x, int &y){ if(b == 0){ x = 1; y = 0; return ; } extgcd(b,a%b,y,x); y -= a/b * x; } int mod_inverse(int a, int m){ int x, y; extgcd(a, m, x, y); return (m + x % m ) % m; } int gcd(int a, int b) {return a%b?gcd(b, a%b):b;}; pair<int,int> liner_congruence(const vector<int>& A, const vector<int>& B, const vector<int>& M){ int x = 0, m = 1; for(int i = 0; i < A.size(); i++){ int a = A[i] * m, b = B[i] - A[i] * x, d = gcd(M[i], a); if(b % d != 0) return make_pair(0, -1); int t = b / d * mod_inverse(a / d, M[i] / d) % (M[i] / d); x = x + m * t; m *= M[i] / d; } return make_pair((x%m + m) % m, m); } signed main(){ cout<<fixed<<setprecision(10); int T; cin>>T; for(int _ = 0; _ < T; _++){ int X, Y, P, Q; int mini = INF; vector<int> A(2), B(2), M(2); cin>>X>>Y>>P>>Q; M[0] = X * 2 + Y * 2; M[1] = P + Q; for(int i = 0; i < Y; i++){ for(int j = 0; j < Q; j++){ A[0] = 1; A[1] = 1; B[0] = (X + i); B[1] = (P + j); pair<int,int> p = liner_congruence(A, B, M); if(p.first != 0) { mini = min(mini, p.first); } } } if(mini != INF)cout<<mini<<endl; else cout<<"infinity"<<endl; } return 0; }
#include <bits/stdc++.h> using namespace std; struct UnionFind { vector<int> par; vector<int> sz; UnionFind(int n=0){ if(n>0) initialize(n); } void initialize(int n){ par.resize(n); sz.assign(n, 1); for(int i=0; i<n; i++){ par[i] = i; } } int find(int x){ if(par[x] == x){ return x; }else{ return par[x] = find(par[x]); } } bool unite(int x, int y){ x = find(x), y = find(y); if(x == y) return false; if(sz[x] > sz[y]) swap(x, y); par[x] = y; sz[y] += sz[x]; return true; } bool same(int x, int y){ return find(x) == find(y); } int size(int x){ return sz[find(x)]; } }; int main(){ int N; cin >> N; vector<double> X(N), Y(N); for(int i=0; i<N; i++) cin >> X[i] >> Y[i]; using T = tuple<double, int, int>; vector<T> es; for(int i=0; i<N; i++) for(int j=0; j<i; j++) es.emplace_back(hypot(X[i]-X[j], Y[i]-Y[j]), i, j); for(int i=0; i<N; i++){ es.emplace_back(100-Y[i], i, N); es.emplace_back(Y[i]+100, i, N+1); } sort(es.begin(), es.end()); UnionFind uf(N+2); for(auto& [d, a, b] : es){ uf.unite(a, b); if(uf.same(N, N+1)){ cout << fixed << setprecision(10) << d/2 << endl; return 0; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { static int a[5]; scanf("%d%d%d%d",&a[1],&a[2],&a[3],&a[4]); sort(a+1,a+5); puts(a[1]+a[4]==a[2]+a[3] || a[4]==a[1]+a[2]+a[3] ? "Yes" : "No"); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define PI 3.14159265358979323846 #define int long long constexpr long long INF = numeric_limits<long long>::max() / 2; constexpr int MOD = 1000000007; using Graph = vector<vector<int>>; signed main() { cin.tie(nullptr); ios::sync_with_stdio(false); int a[4]; int sum=0; rep(i,4){ cin>>a[i]; sum+=a[i]; } for(int bit=0;bit<(1<<4);bit++){ int s=0; rep(i,4){ if(bit&(1<<i))s+=a[i]; } if(s*2==sum){ cout<<"Yes"<<endl; return 0; } } cout<<"No"<<endl; }
#include <bits/stdc++.h> using namespace std; int main(){ int x,b; cin >> x; if(x%100==0){ b =100; } else{ for(int i=0;i<1001;i++){ if(0<i*100-x && i*100-x < 100){ b=i*100-x; break; } } } cout << b << endl; return 0; }
#include <iostream> #include <algorithm> #include <utility> #include <vector> #include <string> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define REP(i, n) for (int i = 0; i < (n); i++) #define RREP(i, n) for (int i = (n) - 1; i >= 0; i--) #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define RFOR(i, a, b) for (int i = (a); i > (b); i--) #define ALL(a) (a).begin(), (a).end() int main() { int X; cin >> X; cout << 100 - X % 100 << endl; return 0; }
#include <iostream> #include <algorithm> #include <vector> #include <queue> #include <string> #include <cmath> #include <cassert> #define amax(a, b) a = std::max(a, b) #define amin(a, b) a = std::min(a, b) using ll = long long; using ld = long double; #define RATIO (10000ll) #define OFFSET (100000000000ll) ll toLL(std::string &s) { int n = s.size(), zeros = 0; ll ans = 0; bool foundDot = false; for (int i=0; i<n || zeros > 0; i++, zeros = std::max(0, zeros-1)) { if (i < n) { if (s[i] != '.') { ans = ans * 10 + (s[i] - '0'); } if (s[i] == '.' || (!foundDot && i == n-1)) { zeros = 5; foundDot = true; } } else { ans *= 10; } } return ans; } ll ceil(ll x) { return (x + RATIO - 1) / RATIO * RATIO; } int main() { std::string xs, ys, rs; std::cin >> xs >> ys >> rs; const ll x = toLL(xs) + OFFSET, y = toLL(ys) + OFFSET, r = toLL(rs); std::cerr << x << ' ' << y << ' ' << r << std::endl; ll ans = 0; for (ll i=ceil(x - r); i <= x + r; i += RATIO) { const ll dd = r * r - (i - x) * (i - x); ll left = y, right = y + r + 1; while (right - left > 1) { ll mid = (left + right) / 2; if ((mid - y) * (mid - y) <= dd) { left = mid; } else { right = mid; } } ll max = left; left = y - r - 1, right = y; while (right - left > 1) { ll mid = (left + right + 1) / 2; if ((mid - y) * (mid - y) <= dd) { right = mid; } else { left = mid; } } ll min = right; ans += max / RATIO - (min - 1) / RATIO; } std::cout << ans << '\n'; return 0; }
#include<bits/stdc++.h> using namespace std; int main(){ int a,b,w; cin >> a >> b >> w; int m=1e9,M=0; for(int n=1;n<=1000000;n++){ if(a*n<=1000*w && 1000*w<=b*n){ m=min(m,n); M=max(M,n); } } if(M==0)cout << "UNSATISFIABLE"; else cout << m << ' ' << M; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; class Mat { public: ll a[2][2]; ll b[2]; Mat() { a[0][0] = 1; a[0][1] = 0; a[1][0] = 0; a[1][1] = 1; b[0] = 0; b[1] = 0; } Mat(ll m, ll p) { if (m == 1) { a[0][0] = 0; a[0][1] = 1; a[1][0] = -1; a[1][1] = 0; b[0] = 0; b[1] = 0; } else if (m == 2) { a[0][0] = 0; a[0][1] = -1; a[1][0] = 1; a[1][1] = 0; b[0] = 0; b[1] = 0; } else if (m == 3) { a[0][0] = -1; a[0][1] = 0; a[1][0] = 0; a[1][1] = 1; b[0] = 2 * p; b[1] = 0; } else { a[0][0] = 1; a[0][1] = 0; a[1][0] = 0; a[1][1] = -1; b[0] = 0; b[1] = 2 * p; } } Mat mul(Mat s) { // this * s Mat ans = Mat(); ans.a[0][0] = this->a[0][0] * s.a[0][0] + this->a[0][1] * s.a[1][0]; ans.a[0][1] = this->a[0][0] * s.a[0][1] + this->a[0][1] * s.a[1][1]; ans.a[1][0] = this->a[1][0] * s.a[0][0] + this->a[1][1] * s.a[1][0]; ans.a[1][1] = this->a[1][0] * s.a[0][1] + this->a[1][1] * s.a[1][1]; ans.b[0] = this->a[0][0] * s.b[0] + this->a[0][1] * s.b[1] + this->b[0]; ans.b[1] = this->a[1][0] * s.b[0] + this->a[1][1] * s.b[1] + this->b[1]; return ans; } void print() { cout << a[0][0] << ' ' << a[0][1] << ' ' << b[0] << endl << a[1][0] << ' ' << a[1][1] << ' ' << b[1] << endl; } }; int main() { ll N; cin >> N; vector<pair<ll, ll>> P(N); for (ll i = 0; i < N; ++i) cin >> P[i].first >> P[i].second; ll M; cin >> M; //前処理 行列表現 Mat mat[M + 1]; mat[0] = Mat(); for (ll i = 0; i < M; ++i) { ll n; cin >> n; Mat tmp; if (n == 1 || n == 2) { tmp = Mat(n, 0); } else { ll p; cin >> p; tmp = Mat(n, p); } mat[i + 1] = tmp.mul(mat[i]); //mat[i+1].print(); } ll Q; cin >> Q; for (ll i = 0; i < Q; ++i) { //クエリ ll A, B; cin >> A >> B; --B; Mat q = mat[A]; ll x = P[B].first * q.a[0][0] + P[B].second * q.a[0][1] + q.b[0]; ll y = P[B].first * q.a[1][0] + P[B].second * q.a[1][1] + q.b[1]; cout << x << ' ' << y << endl; } }
// #pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; #define ll long long const ll nax = 200002; const ll p = 1e9 + 7; ll dp[nax][2]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; vector<ll> mn(n + 2, INT_MAX), mx(n + 2, INT_MIN); for (int i = 0; i < n; ++i) { ll x, c; cin >> x >> c; mn[c] = min(mn[c], x); mx[c] = max(mx[c], x); } mn[n + 1] = mx[n + 1] = 0; mn[0] = mx[0] = 0; for (int i = 1; i <= n + 1; ++i) { if (mn[i] == INT_MAX) { dp[i][0] = dp[i - 1][0]; dp[i][1] = dp[i - 1][1]; mn[i] = mn[i - 1]; mx[i] = mx[i - 1]; continue; } dp[i][0] = mx[i] - mn[i] + min(abs(mx[i] - mx[i - 1]) + dp[i - 1][1], abs(mx[i] - mn[i - 1]) + dp[i - 1][0]); dp[i][1] = mx[i] - mn[i] + min(abs(mn[i] - mx[i - 1]) + dp[i - 1][1], abs(mn[i] - mn[i - 1]) + dp[i - 1][0]); } cout << dp[n + 1][0]; }
#include<bits/stdc++.h> using namespace std; #define io cin.tie(0);ios::sync_with_stdio(false); #define debug(x) cout<<#x<<"="<<x<<endl #define lowbit(x) x&(-x) #define pii pair<int,int> #define mk make_pair #define ll long long #define lb long double #define rs p<<1|1 #define ls p<<1 const int maxn = 1e6 + 5; const int mod = 1e9 + 7; const int inf = 0x3f3f3f3f; inline ll read(){ ll p=0,f=1;char c=getchar(); while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();} while(c>='0'&&c<='9'){p=(p<<1)+(p<<3)+(c^48),c=getchar();} return f*p; } void solve(){ io; lb x, y, R; cin >> x >> y >> R; R += 1e-14; ll ans = 0; for(int i = ceil(x - R); i <= floor(x + R); i ++){ //左边界向上取整,有边界向下取整 lb t, b; t = y + sqrt(R * R - (x - i) * (x - i)); b = y - sqrt(R * R - (x - i) * (x - i)); ans += floor(t) - ceil(b) + 1; //上边界向下取整,下边界向上取整 } cout << ans << endl; } int main(){ solve(); return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #define rep(i, a, b) for (auto i = (a); i < (b); ++i) #define per(i, a, b) for (auto i = (b); i-- > (a); ) #define all(x) begin(x), end(x) #define rall(x) (x).rbegin(), (x).rend() #define sz(x) int((x).size()) #define lb(x...) lower_bound(x) #define ub(x...) upper_bound(x) template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const ll B = 10000; const ll inf = B * (2e5 + 30); ll get(string s) { auto it = find(all(s), '.'); ll res = stoi(string(begin(s), it)); res *= B; if (it != end(s)) { ++it; while (distance(it, end(s)) != 4) s.push_back('0'); res += stoi(string(it, end(s))); } return res; } bool f(ll a, ll b) { return a * a <= b; } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); string _a, _b, _r; cin >> _a >> _b >> _r; auto a = get(_a); auto b = get(_b); auto r = get(_r); ll ans = 0; for (ll x = -inf; x <= inf; x += B) { ll d = r * r - (x - a) * (x - a); if (d < 0) continue; ll l = 0, r = sqrt(d) + 100; while (r - l > 1) { ll m = l + (r - l) / 2; (f(m, d) ? l : r) = m; } assert(f(l, d) && !f(r, d)); ll L = b - l; ll R = b + l; L += inf; R += inf; assert(L > 0 && R > 0); ans += R / B - (L - 1) / B; } cout << ans; }